From nobody Thu Jul 17 12:21:35 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.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 1487711032880308.9685806454205; Tue, 21 Feb 2017 13:03:52 -0800 (PST) Received: from localhost ([::1]:48561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgHbB-000694-SX for importer@patchew.org; Tue, 21 Feb 2017 16:03:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgHZN-0005D2-NI for qemu-devel@nongnu.org; Tue, 21 Feb 2017 16:01:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgHZM-0006dz-Ii for qemu-devel@nongnu.org; Tue, 21 Feb 2017 16:01:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52312) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgHZJ-0006c3-7X; Tue, 21 Feb 2017 16:01:53 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A21E7E9D0; Tue, 21 Feb 2017 21:01:53 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1LL1pZt001104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 21 Feb 2017 16:01:52 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6CFB311386CE; Tue, 21 Feb 2017 22:01:48 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 21 Feb 2017 22:01:48 +0100 Message-Id: <1487710908-26356-6-git-send-email-armbru@redhat.com> In-Reply-To: <1487710908-26356-1-git-send-email-armbru@redhat.com> References: <1487710908-26356-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 21 Feb 2017 21:01:53 +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] [PATCH RFC v3 5/5] block: Crude initial implementation of -blockdev 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, pkrempa@redhat.com, qemu-block@nongnu.org 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" The new command line option -blockdev works like QMP command blockdev-add. The option argument may be given in JSON syntax, exactly as in QMP. Example usage: -blockdev '{"node-name": "foo", "driver": "raw", "file": {"driver": "fi= le", "filename": "foo.img"} }' The JSON argument doesn't exactly blend into the existing option syntax, so the traditional KEY=3DVALUE,... syntax is also supported, using dotted keys to do the nesting: -blockdev node-name=3Dfoo,driver=3Draw,file.driver=3Dfile,file.filename= =3Dfoo.img Note that calling qmp_blockdev_add() (say via qmp_marshal_block_add()) right away would crash. We need to stash the configuration for later instead. This is crudely done, and bypasses QemuOpts, even though storing configuration is what QemuOpts is for. Need to revamp option infrastructure to support QAPI types like BlockdevOptions. Signed-off-by: Markus Armbruster --- qemu-options.hx | 3 +++ vl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 9936cf3..36a38d7 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -512,6 +512,9 @@ Use @var{file} as CD-ROM image (you cannot use @option{= -hdc} and using @file{/dev/cdrom} as filename (@pxref{host_drives}). ETEXI =20 +DEF("blockdev", HAS_ARG, QEMU_OPTION_blockdev, + "-blockdev FIXME document\n", QEMU_OPTION_blockdev) + DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=3Dfile][,if=3Dtype][,bus=3Dn][,unit=3Dm][,media=3Dd][,in= dex=3Di]\n" " [,cyls=3Dc,heads=3Dh,secs=3Ds[,trans=3Dt]][,snapshot=3Don|off]= \n" diff --git a/vl.c b/vl.c index b5d0a19..37be73c 100644 --- a/vl.c +++ b/vl.c @@ -95,6 +95,9 @@ int main(int argc, char **argv) #include "migration/colo.h" #include "sysemu/kvm.h" #include "sysemu/hax.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi-visit.h" #include "qapi/qmp/qjson.h" #include "qemu/option.h" #include "qemu/config-file.h" @@ -2954,6 +2957,12 @@ int main(int argc, char **argv, char **envp) Error *main_loop_err =3D NULL; Error *err =3D NULL; bool list_data_dirs =3D false; + typedef struct BlockdevOptions_queue { + BlockdevOptions *bdo; + Location loc; + QSIMPLEQ_ENTRY(BlockdevOptions_queue) entry; + } BlockdevOptions_queue; + QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue =3D QSIMPLEQ_HEAD_INI= TIALIZER(bdo_queue); =20 module_call_init(MODULE_INIT_TRACE); =20 @@ -3095,6 +3104,37 @@ int main(int argc, char **argv, char **envp) drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optar= g, HD_OPTS); break; + case QEMU_OPTION_blockdev: + { + BlockdevOptions_queue *bdo =3D g_new(BlockdevOptions_q= ueue, 1); + bool is_json =3D optarg[0] =3D=3D '{'; + QObject *obj; + QDict *args; + Visitor *v; + + if (is_json) { + obj =3D qobject_from_json(optarg); + // TODO get error out of parser + if (!obj) { + error_report("invalid JSON"); + exit(1); + } + args =3D qobject_to_qdict(obj); + assert(args); + v =3D qobject_input_visitor_new(QOBJECT(args), tru= e); + } else { + args =3D keyval_parse(optarg, "driver", &error_fat= al); + v =3D qobject_input_visitor_new_autocast(QOBJECT(a= rgs)); + } + + visit_type_BlockdevOptions(v, NULL, &bdo->bdo, + &error_fatal); + visit_free(v); + QDECREF(args); + loc_save(&bdo->loc); + QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry); + break; + } case QEMU_OPTION_drive: if (drive_def(optarg) =3D=3D NULL) { exit(1); @@ -4407,6 +4447,16 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); } + while (!QSIMPLEQ_EMPTY(&bdo_queue)) { + BlockdevOptions_queue *bdo =3D QSIMPLEQ_FIRST(&bdo_queue); + + QSIMPLEQ_REMOVE_HEAD(&bdo_queue, entry); + loc_push_restore(&bdo->loc); + qmp_blockdev_add(bdo->bdo, &error_fatal); + loc_pop(&bdo->loc); + qapi_free_BlockdevOptions(bdo->bdo); + g_free(bdo); + } if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine_class->block_default_type, NULL)) { exit(1); --=20 2.7.4