From nobody Fri Oct 24 22:15:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519222987755708.9238145066978; Wed, 21 Feb 2018 06:23:07 -0800 (PST) Received: from localhost ([::1]:32907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoVIY-0008Af-TY for importer@patchew.org; Wed, 21 Feb 2018 09:23:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoUrv-0001Ta-C3 for qemu-devel@nongnu.org; Wed, 21 Feb 2018 08:55:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoUrt-00037d-Vd for qemu-devel@nongnu.org; Wed, 21 Feb 2018 08:55:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57160 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoUrn-00034M-TZ; Wed, 21 Feb 2018 08:55:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64153407A9AB; Wed, 21 Feb 2018 13:55:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-57.ams2.redhat.com [10.36.117.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8566219F132; Wed, 21 Feb 2018 13:55:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 21 Feb 2018 14:53:57 +0100 Message-Id: <20180221135404.27598-30-kwolf@redhat.com> In-Reply-To: <20180221135404.27598-1-kwolf@redhat.com> References: <20180221135404.27598-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Feb 2018 13:55:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Feb 2018 13:55:27 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 29/36] ssh: Use QAPI BlockdevOptionsSsh object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jdurgin@redhat.com, pkrempa@redhat.com, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, namei.unix@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Create a BlockdevOptionsSsh object in connect_to_ssh() and take the options from there. 'host_key_check' is still processed separately because it's not in the schema yet. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/ssh.c | 136 +++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 61 insertions(+), 75 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index b63addcf94..9a89b7f350 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -543,21 +543,6 @@ static QemuOptsList ssh_runtime_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "Port to connect to", }, - { - .name =3D "path", - .type =3D QEMU_OPT_STRING, - .help =3D "Path of the image on the host", - }, - { - .name =3D "user", - .type =3D QEMU_OPT_STRING, - .help =3D "User as which to connect", - }, - { - .name =3D "host_key_check", - .type =3D QEMU_OPT_STRING, - .help =3D "Defines how and what to check the host key against", - }, { /* end of list */ } }, }; @@ -582,23 +567,31 @@ static bool ssh_process_legacy_socket_options(QDict *= output_opts, return true; } =20 -static InetSocketAddress *ssh_config(QDict *options, Error **errp) +static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp) { - InetSocketAddress *inet =3D NULL; - QDict *addr =3D NULL; - QObject *crumpled_addr =3D NULL; - Visitor *iv =3D NULL; - Error *local_error =3D NULL; - - qdict_extract_subqdict(options, &addr, "server."); - if (!qdict_size(addr)) { - error_setg(errp, "SSH server address missing"); - goto out; + BlockdevOptionsSsh *result =3D NULL; + QemuOpts *opts =3D NULL; + Error *local_err =3D NULL; + QObject *crumpled; + const QDictEntry *e; + Visitor *v; + + /* Translate legacy options */ + opts =3D qemu_opts_create(&ssh_runtime_opts, NULL, 0, &error_abort); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto fail; } =20 - crumpled_addr =3D qdict_crumple(addr, errp); - if (!crumpled_addr) { - goto out; + if (!ssh_process_legacy_socket_options(options, opts, errp)) { + goto fail; + } + + /* Create the QAPI object */ + crumpled =3D qdict_crumple(options, errp); + if (crumpled =3D=3D NULL) { + goto fail; } =20 /* @@ -609,51 +602,50 @@ static InetSocketAddress *ssh_config(QDict *options, = Error **errp) * but when they come from -drive, they're all QString. The * visitor expects the former. */ - iv =3D qobject_input_visitor_new(crumpled_addr); - visit_type_InetSocketAddress(iv, NULL, &inet, &local_error); - if (local_error) { - error_propagate(errp, local_error); - goto out; + v =3D qobject_input_visitor_new(crumpled); + visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err); + visit_free(v); + qobject_decref(crumpled); + + if (local_err) { + error_propagate(errp, local_err); + goto fail; } =20 -out: - QDECREF(addr); - qobject_decref(crumpled_addr); - visit_free(iv); - return inet; + /* Remove the processed options from the QDict (the visitor processes + * _all_ options in the QDict) */ + while ((e =3D qdict_first(options))) { + qdict_del(options, e->key); + } + +fail: + qemu_opts_del(opts); + return result; } =20 static int connect_to_ssh(BDRVSSHState *s, QDict *options, int ssh_flags, int creat_mode, Error **errp) { + BlockdevOptionsSsh *opts; int r, ret; - QemuOpts *opts =3D NULL; - Error *local_err =3D NULL; - const char *user, *path, *host_key_check; + const char *user, *host_key_check; long port =3D 0; =20 - opts =3D qemu_opts_create(&ssh_runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(opts, options, &local_err); - if (local_err) { - ret =3D -EINVAL; - error_propagate(errp, local_err); - goto err; - } - - if (!ssh_process_legacy_socket_options(options, opts, errp)) { - ret =3D -EINVAL; - goto err; + host_key_check =3D qdict_get_try_str(options, "host_key_check"); + if (!host_key_check) { + host_key_check =3D "yes"; + } else { + qdict_del(options, "host_key_check"); } =20 - path =3D qemu_opt_get(opts, "path"); - if (!path) { - ret =3D -EINVAL; - error_setg(errp, "No path was specified"); - goto err; + opts =3D ssh_parse_options(options, errp); + if (opts =3D=3D NULL) { + return -EINVAL; } =20 - user =3D qemu_opt_get(opts, "user"); - if (!user) { + if (opts->has_user) { + user =3D opts->user; + } else { user =3D g_get_user_name(); if (!user) { error_setg_errno(errp, errno, "Can't get user name"); @@ -662,17 +654,9 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *opti= ons, } } =20 - host_key_check =3D qemu_opt_get(opts, "host_key_check"); - if (!host_key_check) { - host_key_check =3D "yes"; - } - /* Pop the config into our state object, Exit if invalid */ - s->inet =3D ssh_config(options, errp); - if (!s->inet) { - ret =3D -EINVAL; - goto err; - } + s->inet =3D opts->server; + opts->server =3D NULL; =20 if (qemu_strtol(s->inet->port, NULL, 10, &port) < 0) { error_setg(errp, "Use only numeric port value"); @@ -729,15 +713,17 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *opt= ions, =20 /* Open the remote file. */ DPRINTF("opening file %s flags=3D0x%x creat_mode=3D0%o", - path, ssh_flags, creat_mode); - s->sftp_handle =3D libssh2_sftp_open(s->sftp, path, ssh_flags, creat_m= ode); + opts->path, ssh_flags, creat_mode); + s->sftp_handle =3D libssh2_sftp_open(s->sftp, opts->path, ssh_flags, + creat_mode); if (!s->sftp_handle) { - session_error_setg(errp, s, "failed to open remote file '%s'", pat= h); + session_error_setg(errp, s, "failed to open remote file '%s'", + opts->path); ret =3D -EINVAL; goto err; } =20 - qemu_opts_del(opts); + qapi_free_BlockdevOptionsSsh(opts); =20 r =3D libssh2_sftp_fstat(s->sftp_handle, &s->attrs); if (r < 0) { @@ -764,7 +750,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *optio= ns, } s->session =3D NULL; =20 - qemu_opts_del(opts); + qapi_free_BlockdevOptionsSsh(opts); =20 return ret; } --=20 2.13.6