From patchwork Wed Mar 28 20:50:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 149343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6647BB6FA2 for ; Thu, 29 Mar 2012 11:54:01 +1100 (EST) Received: from localhost ([::1]:57188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SD3cl-0002EF-9C for incoming@patchwork.ozlabs.org; Wed, 28 Mar 2012 20:53:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCzpb-0000h4-RD for qemu-devel@nongnu.org; Wed, 28 Mar 2012 16:51:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCzpZ-0000m5-On for qemu-devel@nongnu.org; Wed, 28 Mar 2012 16:50:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCzpZ-0000lp-HI for qemu-devel@nongnu.org; Wed, 28 Mar 2012 16:50:57 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2SKouNd028651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Mar 2012 16:50:56 -0400 Received: from localhost (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2SKostW009917; Wed, 28 Mar 2012 16:50:55 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 28 Mar 2012 17:50:54 -0300 Message-Id: <1332967854-29106-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1332967854-29106-1-git-send-email-lcapitulino@redhat.com> References: <1332967854-29106-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 2/2] qapi: convert device_del X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- hmp-commands.hx | 3 +-- hmp.c | 9 +++++++++ hmp.h | 1 + hw/qdev-monitor.c | 15 +++++++-------- qapi-schema.json | 20 ++++++++++++++++++++ qmp-commands.hx | 5 +---- 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index bd35a3e..a6f5a84 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -622,8 +622,7 @@ ETEXI .args_type = "id:s", .params = "device", .help = "remove device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_device_del, + .mhandler.cmd = hmp_device_del, }, STEXI diff --git a/hmp.c b/hmp.c index 9cf2d13..f3e5163 100644 --- a/hmp.c +++ b/hmp.c @@ -934,3 +934,12 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock)); } } + +void hmp_device_del(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + Error *err = NULL; + + qmp_device_del(id, &err); + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 8807853..443b812 100644 --- a/hmp.h +++ b/hmp.h @@ -60,5 +60,6 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict); void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); +void hmp_device_del(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 58fa943..761ba90 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -19,6 +19,7 @@ #include "qdev.h" #include "monitor.h" +#include "qmp-commands.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -574,26 +575,24 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) return 0; } -int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_device_del(const char *id, Error **errp) { - const char *id = qdict_get_str(qdict, "id"); DeviceState *dev; Error *local_err = NULL; int ret; dev = qdev_find_recursive(sysbus_get_default(), id); if (NULL == dev) { - qerror_report(QERR_DEVICE_NOT_FOUND, id); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, id); + return; } ret = qdev_unplug(dev, &local_err); if (error_is_set(&local_err)) { - qerror_report_err(local_err); - error_free(local_err); + error_propagate(errp, local_err); + } else if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); } - - return ret; } void qdev_machine_init(void) diff --git a/qapi-schema.json b/qapi-schema.json index 0d11d6e..ace55f3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1701,3 +1701,23 @@ # Since: 1.1 ## { 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} } + +## +# @device_del: +# +# Remove a device from a guest +# +# @id: the name of the device +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# If the device does not support unplug, BusNoHotplug +# +# Notes: When this command completes, the device may not be removed from the +# guest. Hot removal is an operation that requires guest cooperation. +# This command merely requests that the guest begin the hot removal +# process. +# +# Since: 0.14.0 +## +{ 'command': 'device_del', 'data': {'id': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index c626ba8..c878b54 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -314,10 +314,7 @@ EQMP { .name = "device_del", .args_type = "id:s", - .params = "device", - .help = "remove device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_device_del, + .mhandler.cmd_new = qmp_marshal_input_device_del, }, SQMP