From patchwork Thu Mar 4 15:57:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 107C7B7067 for ; Fri, 5 Mar 2010 04:39:08 +1100 (EST) Received: from localhost ([127.0.0.1]:33899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnF0p-0008VM-Rc for incoming@patchwork.ozlabs.org; Thu, 04 Mar 2010 12:39:03 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnDXi-0005nW-Ut for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:55 -0500 Received: from [199.232.76.173] (port=58596 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnDXh-0005mW-Oh for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:53 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnDXT-0001Re-C9 for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:52 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:47490) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NnDXP-0001Pm-TM for qemu-devel@nongnu.org; Thu, 04 Mar 2010 11:04:36 -0500 Received: from blackfin.pond.sub.org (pD9E38041.dip.t-dialin.net [217.227.128.65]) by oxygen.pond.sub.org (Postfix) with ESMTPA id DAC732DD325 for ; Thu, 4 Mar 2010 17:04:30 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 02CD325A; Thu, 4 Mar 2010 16:57:14 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Mar 2010 16:57:11 +0100 Message-Id: <1267718231-13303-51-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1267718231-13303-1-git-send-email-armbru@redhat.com> References: <1267718231-13303-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Luiz Capitulino Subject: [Qemu-devel] [PATCH 50/50] monitor: convert do_device_add() to QObject X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Markus Armbruster --- hw/qdev.c | 42 ++++++++++++++++++++++++++++++++++-------- hw/qdev.h | 2 +- qemu-monitor.hx | 3 ++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 241f204..35e7a88 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -586,7 +586,9 @@ static BusState *qbus_find(const char *path) dev = qbus_find_dev(bus, elem); if (!dev) { qerror_report(QERR_DEVICE_NOT_FOUND, elem); - qbus_list_dev(bus); + if (!monitor_cur_is_qmp()) { + qbus_list_dev(bus); + } return NULL; } @@ -605,7 +607,9 @@ static BusState *qbus_find(const char *path) return QLIST_FIRST(&dev->child_bus); default: qerror_report(QERR_DEVICE_MULTIPLE_BUSSES, elem); - qbus_list_bus(dev); + if (!monitor_cur_is_qmp()) { + qbus_list_bus(dev); + } return NULL; } } @@ -619,7 +623,9 @@ static BusState *qbus_find(const char *path) bus = qbus_find_bus(dev, elem); if (!bus) { qerror_report(QERR_BUS_NOT_FOUND, elem); - qbus_list_bus(dev); + if (!monitor_cur_is_qmp()) { + qbus_list_bus(dev); + } return NULL; } } @@ -762,16 +768,36 @@ void do_info_qdm(Monitor *mon) } } -void do_device_add(Monitor *mon, const QDict *qdict) +/** + * do_device_add(): Add a device + * + * Argument qdict contains + * - "driver": the name of the new device's driver + * - "bus": the device's parent bus (device tree path) + * - "id": the device's ID (must be unique) + * - device properties + * + * Example: + * + * { "driver": "usb-net", "id": "eth1", "netdev": "netdev1" } + */ +int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { QemuOpts *opts; opts = qemu_opts_from_qdict(&qemu_device_opts, qdict); - if (opts) { - if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) { - qemu_opts_del(opts); - } + if (!opts) { + return -1; + } + if (!monitor_cur_is_qmp() && qdev_device_help(opts)) { + qemu_opts_del(opts); + return 0; } + if (!qdev_device_add(opts)) { + qemu_opts_del(opts); + return -1; + } + return 0; } void do_device_del(Monitor *mon, const QDict *qdict) diff --git a/hw/qdev.h b/hw/qdev.h index 0eb45b0..c86a59d 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -171,7 +171,7 @@ void qbus_free(BusState *bus); void do_info_qtree(Monitor *mon); void do_info_qdm(Monitor *mon); -void do_device_add(Monitor *mon, const QDict *qdict); +int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); void do_device_del(Monitor *mon, const QDict *qdict); /*** qdev-properties.c ***/ diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 45e5fd1..5308f36 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -573,7 +573,8 @@ ETEXI .args_type = "device:O", .params = "driver[,prop=value][,...]", .help = "add device, like -device on the command line", - .mhandler.cmd = do_device_add, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_device_add, }, STEXI