|
|
9ae3a8 |
From 1f5e04965db81bea1eac402110166290bfc774db Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Date: Sun, 1 Oct 2017 03:55:19 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 4/4] block/ssh: Use QemuOpts for runtime options
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Message-id: <798f4a5f4498382bd5764a5e7889595a36aab78c.1506829990.git.jcody@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 76786
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.5 1/1] block/ssh: Use QemuOpts for runtime options
|
|
|
9ae3a8 |
Bugzilla: 1461672
|
|
|
9ae3a8 |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Using QemuOpts will prevent qemu from crashing if the input options have
|
|
|
9ae3a8 |
not been validated (which is the case when they are specified on the
|
|
|
9ae3a8 |
command line or in a json: filename) and some have the wrong type.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 8a6a80896d6af03b8ee0c17cdf37219eca2588a7)
|
|
|
9ae3a8 |
Signed-off-by: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/ssh.c | 79 ++++++++++++++++++++++++++++++++++++++++++-------------------
|
|
|
9ae3a8 |
1 file changed, 55 insertions(+), 24 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/ssh.c b/block/ssh.c
|
|
|
9ae3a8 |
index b00ff7f..a9341b8 100644
|
|
|
9ae3a8 |
--- a/block/ssh.c
|
|
|
9ae3a8 |
+++ b/block/ssh.c
|
|
|
9ae3a8 |
@@ -510,36 +510,73 @@ static int authenticate(BDRVSSHState *s, const char *user, Error **errp)
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static QemuOptsList ssh_runtime_opts = {
|
|
|
9ae3a8 |
+ .name = "ssh",
|
|
|
9ae3a8 |
+ .head = QTAILQ_HEAD_INITIALIZER(ssh_runtime_opts.head),
|
|
|
9ae3a8 |
+ .desc = {
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ .name = "host",
|
|
|
9ae3a8 |
+ .type = QEMU_OPT_STRING,
|
|
|
9ae3a8 |
+ .help = "Host to connect to",
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ .name = "port",
|
|
|
9ae3a8 |
+ .type = QEMU_OPT_NUMBER,
|
|
|
9ae3a8 |
+ .help = "Port to connect to",
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ .name = "path",
|
|
|
9ae3a8 |
+ .type = QEMU_OPT_STRING,
|
|
|
9ae3a8 |
+ .help = "Path of the image on the host",
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ .name = "user",
|
|
|
9ae3a8 |
+ .type = QEMU_OPT_STRING,
|
|
|
9ae3a8 |
+ .help = "User as which to connect",
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+ {
|
|
|
9ae3a8 |
+ .name = "host_key_check",
|
|
|
9ae3a8 |
+ .type = QEMU_OPT_STRING,
|
|
|
9ae3a8 |
+ .help = "Defines how and what to check the host key against",
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+ },
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|
|
9ae3a8 |
int ssh_flags, int creat_mode, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int r, ret;
|
|
|
9ae3a8 |
+ QemuOpts *opts = NULL;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
const char *host, *user, *path, *host_key_check;
|
|
|
9ae3a8 |
int port;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (!qdict_haskey(options, "host")) {
|
|
|
9ae3a8 |
+ opts = qemu_opts_create(&ssh_runtime_opts, NULL, 0, &error_abort);
|
|
|
9ae3a8 |
+ qemu_opts_absorb_qdict(opts, options, &local_err);
|
|
|
9ae3a8 |
+ if (local_err) {
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
- error_setg(errp, "No hostname was specified");
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- host = qdict_get_str(options, "host");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (qdict_haskey(options, "port")) {
|
|
|
9ae3a8 |
- port = qdict_get_int(options, "port");
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- port = 22;
|
|
|
9ae3a8 |
+ host = qemu_opt_get(opts, "host");
|
|
|
9ae3a8 |
+ if (!host) {
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ error_setg(errp, "No hostname was specified");
|
|
|
9ae3a8 |
+ goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (!qdict_haskey(options, "path")) {
|
|
|
9ae3a8 |
+ port = qemu_opt_get_number(opts, "port", 22);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ path = qemu_opt_get(opts, "path");
|
|
|
9ae3a8 |
+ if (!path) {
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
error_setg(errp, "No path was specified");
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- path = qdict_get_str(options, "path");
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (qdict_haskey(options, "user")) {
|
|
|
9ae3a8 |
- user = qdict_get_str(options, "user");
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
+ user = qemu_opt_get(opts, "user");
|
|
|
9ae3a8 |
+ if (!user) {
|
|
|
9ae3a8 |
user = g_get_user_name();
|
|
|
9ae3a8 |
if (!user) {
|
|
|
9ae3a8 |
error_setg_errno(errp, errno, "Can't get user name");
|
|
|
9ae3a8 |
@@ -548,9 +585,8 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (qdict_haskey(options, "host_key_check")) {
|
|
|
9ae3a8 |
- host_key_check = qdict_get_str(options, "host_key_check");
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
+ host_key_check = qemu_opt_get(opts, "host_key_check");
|
|
|
9ae3a8 |
+ if (!host_key_check) {
|
|
|
9ae3a8 |
host_key_check = "yes";
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -614,21 +650,14 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ qemu_opts_del(opts);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs);
|
|
|
9ae3a8 |
if (r < 0) {
|
|
|
9ae3a8 |
sftp_error_setg(errp, s, "failed to read file attributes");
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* Delete the options we've used; any not deleted will cause the
|
|
|
9ae3a8 |
- * block layer to give an error about unused options.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
- qdict_del(options, "host");
|
|
|
9ae3a8 |
- qdict_del(options, "port");
|
|
|
9ae3a8 |
- qdict_del(options, "user");
|
|
|
9ae3a8 |
- qdict_del(options, "path");
|
|
|
9ae3a8 |
- qdict_del(options, "host_key_check");
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
err:
|
|
|
9ae3a8 |
@@ -648,6 +677,8 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
s->session = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ qemu_opts_del(opts);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|