From nobody Sat Feb 7 06:40:07 2026 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490879957098709.6415190656887; Thu, 30 Mar 2017 06:19:17 -0700 (PDT) Received: from localhost ([::1]:35597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctZyt-0005Vg-NY for importer@patchew.org; Thu, 30 Mar 2017 09:19:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ctZv6-0002av-1v for qemu-devel@nongnu.org; Thu, 30 Mar 2017 09:15:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ctZv4-0002Ra-Di for qemu-devel@nongnu.org; Thu, 30 Mar 2017 09:15:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ctZux-0002DN-6s; Thu, 30 Mar 2017 09:15:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB0736AAD3; Thu, 30 Mar 2017 13:15:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6379B7FB61; Thu, 30 Mar 2017 13:15:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C434511386CB; Thu, 30 Mar 2017 15:15:07 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB0736AAD3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CB0736AAD3 From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 30 Mar 2017 15:15:01 +0200 Message-Id: <1490879707-6060-5-git-send-email-armbru@redhat.com> In-Reply-To: <1490879707-6060-1-git-send-email-armbru@redhat.com> References: <1490879707-6060-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 30 Mar 2017 13:15:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 for-2.9 04/10] block: Document -drive problematic code and bugs 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, qemu-block@nongnu.org, mitake.hitoshi@lab.ntt.co.jp, jcody@redhat.com, mreitz@redhat.com, pbonzini@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" -blockdev and blockdev_add convert their arguments via QObject to BlockdevOptions for qmp_blockdev_add(), which converts them back to QObject, then to a flattened QDict. The QDict's members are typed according to the QAPI schema. -drive converts its argument via QemuOpts to a (flat) QDict. This QDict's members are all QString. Thus, the QType of a flat QDict member depends on whether it comes from -drive or -blockdev/blockdev_add, except when the QAPI type maps to QString, which is the case for 'str' and enumeration types. The block layer core extracts generic configuration from the flat QDict, and the block driver extracts driver-specific configuration. Both commonly do so by converting (parts of) the flat QDict to QemuOpts, which turns all values into strings. Not exactly elegant, but correct. However, A few places access the flat QDict directly: * Most of them access members that are always QString. Correct. * bdrv_open_inherit() accesses a boolean, carefully. Correct. * nfs_config() uses a QObject input visitor. Correct only because the visited type contains nothing but QStrings. * nbd_config() and ssh_config() use a QObject input visitor, and the visited types contain non-QStrings: InetSocketAddress members @numeric, @to, @ipv4, @ipv6. -drive works as long as you don't try to use them (they're all optional). @to is ignored anyway. Reproducer: -drive driver=3Dssh,server.host=3Dh,server.port=3D22,server.ipv4,path=3Dp -drive driver=3Dnbd,server.type=3Dinet,server.data.host=3Dh,server.data.p= ort=3D22,server.data.ipv4 both fail with "Invalid parameter type for 'data.ipv4', expected: boolean" Add suitable comments to all these places. Mark the buggy ones FIXME. "Fortunately", -drive's driver-specific options are entirely undocumented. Signed-off-by: Markus Armbruster --- block.c | 41 +++++++++++++++++++++++++++++++++++++++-- block/file-posix.c | 6 ++++++ block/nbd.c | 8 ++++++++ block/nfs.c | 7 +++++++ block/rbd.c | 6 ++++++ block/ssh.c | 8 ++++++++ 6 files changed, 74 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 6e906ec..b3ce23f 100644 --- a/block.c +++ b/block.c @@ -1157,6 +1157,12 @@ static int bdrv_open_common(BlockDriverState *bs, Bl= ockBackend *file, if (file !=3D NULL) { filename =3D blk_bs(file)->filename; } else { + /* + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when + * they come from -drive, they're all QString. + */ filename =3D qdict_get_try_str(options, "filename"); } =20 @@ -1324,6 +1330,12 @@ static int bdrv_fill_options(QDict **options, const = char *filename, BlockDriver *drv =3D NULL; Error *local_err =3D NULL; =20 + /* + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ drvname =3D qdict_get_try_str(*options, "driver"); if (drvname) { drv =3D bdrv_find_format(drvname); @@ -1358,6 +1370,7 @@ static int bdrv_fill_options(QDict **options, const c= har *filename, } =20 /* Find the right block driver */ + /* Direct use of @options members is problematic, see note above */ filename =3D qdict_get_try_str(*options, "filename"); =20 if (!drvname && protocol) { @@ -1987,6 +2000,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, qdict_extract_subqdict(parent_options, &options, bdref_key_dot); g_free(bdref_key_dot); =20 + /* + * Caution: direct use of non-string @parent_options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ reference =3D qdict_get_try_str(parent_options, bdref_key); if (reference || qdict_haskey(options, "file.filename")) { backing_filename[0] =3D '\0'; @@ -2059,6 +2078,12 @@ bdrv_open_child_bs(const char *filename, QDict *opti= ons, const char *bdref_key, qdict_extract_subqdict(options, &image_options, bdref_key_dot); g_free(bdref_key_dot); =20 + /* + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ reference =3D qdict_get_try_str(options, bdref_key); if (!filename && !reference && !qdict_size(image_options)) { if (!allow_none) { @@ -2275,8 +2300,11 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, } =20 /* Set the BDRV_O_RDWR and BDRV_O_ALLOW_RDWR flags. - * FIXME: we're parsing the QDict to avoid having to create a - * QemuOpts just for this, but neither option is optimal. */ + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ if (g_strcmp0(qdict_get_try_str(options, BDRV_OPT_READ_ONLY), "on") && !qdict_get_try_bool(options, BDRV_OPT_READ_ONLY, false)) { flags |=3D (BDRV_O_RDWR | BDRV_O_ALLOW_RDWR); @@ -2298,6 +2326,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, options =3D qdict_clone_shallow(options); =20 /* Find the right image format driver */ + /* Direct use of @options members is problematic, see note above */ drvname =3D qdict_get_try_str(options, "driver"); if (drvname) { drv =3D bdrv_find_format(drvname); @@ -2309,6 +2338,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, =20 assert(drvname || !(flags & BDRV_O_PROTOCOL)); =20 + /* Direct use of @options members is problematic, see note above */ backing =3D qdict_get_try_str(options, "backing"); if (backing && *backing =3D=3D '\0') { flags |=3D BDRV_O_NO_BACKING; @@ -2787,6 +2817,13 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, do { QString *new_obj =3D qobject_to_qstring(entry->value); const char *new =3D qstring_get_str(new_obj); + /* + * Caution: direct use of non-string bs->options members is + * problematic. When they come from -blockdev or + * blockdev_add, members are typed according to the QAPI + * schema, but when they come from -drive, they're all + * QString. + */ const char *old =3D qdict_get_try_str(reopen_state->bs->option= s, entry->key); =20 diff --git a/block/file-posix.c b/block/file-posix.c index 0841a08..738541e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2193,6 +2193,12 @@ static int hdev_open(BlockDriverState *bs, QDict *op= tions, int flags, int ret; =20 #if defined(__APPLE__) && defined(__MACH__) + /* + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ const char *filename =3D qdict_get_str(options, "filename"); char bsd_path[MAXPATHLEN] =3D ""; bool error_occurred =3D false; diff --git a/block/nbd.c b/block/nbd.c index 36ea617..11e3ba7 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -278,6 +278,14 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDic= t *options, Error **errp) goto done; } =20 + /* + * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive + * server.type=3Dinet. .to doesn't matter, it's ignored anyway. + * That's because when @options come from -blockdev or + * blockdev_add, members are typed according to the QAPI schema, + * 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_SocketAddress(iv, NULL, &saddr, &local_err); if (local_err) { diff --git a/block/nfs.c b/block/nfs.c index 3f43f6e..42407de 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -474,6 +474,13 @@ static NFSServer *nfs_config(QDict *options, Error **e= rrp) goto out; } =20 + /* + * Caution: this works only because all scalar members of + * NFSServer are QString in @crumpled_addr. The visitor expects + * @crumpled_addr to be typed according to the QAPI scherma. It + * is when @options come from -blockdev or blockdev_add. But when + * they come from -drive, they're all QString. + */ iv =3D qobject_input_visitor_new(crumpled_addr); visit_type_NFSServer(iv, NULL, &server, &local_error); if (local_error) { diff --git a/block/rbd.c b/block/rbd.c index 498322b..b9a9526 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -384,6 +384,12 @@ static int qemu_rbd_create(const char *filename, QemuO= pts *opts, Error **errp) goto exit; } =20 + /* + * Caution: direct use of non-string @options members is + * problematic. When they come from -blockdev or blockdev_add, + * members are typed according to the QAPI schema, but when they + * come from -drive, they're all QString. + */ pool =3D qdict_get_try_str(options, "pool"); conf =3D qdict_get_try_str(options, "conf"); clientname =3D qdict_get_try_str(options, "user"); diff --git a/block/ssh.c b/block/ssh.c index 278e66f..471ba8a 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -601,6 +601,14 @@ static InetSocketAddress *ssh_config(QDict *options, E= rror **errp) goto out; } =20 + /* + * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive. + * .to doesn't matter, it's ignored anyway. + * That's because when @options come from -blockdev or + * blockdev_add, members are typed according to the QAPI schema, + * 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) { --=20 2.7.4