From patchwork Wed Jan 18 17:41:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 136670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2CCAB6F68 for ; Thu, 19 Jan 2012 05:05:27 +1100 (EST) Received: from localhost ([::1]:59991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnZXK-0000hP-Rl for incoming@patchwork.ozlabs.org; Wed, 18 Jan 2012 12:43:02 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnZWY-0007M4-3Z for qemu-devel@nongnu.org; Wed, 18 Jan 2012 12:42:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RnZWQ-0000OQ-T5 for qemu-devel@nongnu.org; Wed, 18 Jan 2012 12:42:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47058) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RnZWQ-0000OF-M2 for qemu-devel@nongnu.org; Wed, 18 Jan 2012 12:42:06 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0IHg5GW022072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Jan 2012 12:42:05 -0500 Received: from localhost (ovpn-116-46.ams2.redhat.com [10.36.116.46]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0IHg3ls025138; Wed, 18 Jan 2012 12:42:05 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 18 Jan 2012 15:41:15 -0200 Message-Id: <1326908484-13389-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1326908484-13389-1-git-send-email-lcapitulino@redhat.com> References: <1326908484-13389-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 05/14] qapi: Convert eject 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 --- blockdev.c | 20 +++++--------------- blockdev.h | 1 - hmp-commands.hx | 3 +-- hmp.c | 10 ++++++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 39 insertions(+), 22 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9ee5bae..124fbe6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -683,27 +683,17 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp) bdrv_close(bs); } -int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_eject(const char *device, bool has_force, bool force, Error **errp) { BlockDriverState *bs; - int force = qdict_get_try_bool(qdict, "force", 0); - const char *filename = qdict_get_str(qdict, "device"); - Error *err = NULL; - bs = bdrv_find(filename); + bs = bdrv_find(device); if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, filename); - return -1; - } - - eject_device(bs, force, &err); - if (error_is_set(&err)) { - qerror_report_err(err); - error_free(err); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; } - return 0; + eject_device(bs, force, errp); } void qmp_block_passwd(const char *device, const char *password, Error **errp) diff --git a/blockdev.h b/blockdev.h index f1b6396..1937b28 100644 --- a/blockdev.h +++ b/blockdev.h @@ -58,7 +58,6 @@ DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi); DriveInfo *add_init_drive(const char *opts); void do_commit(Monitor *mon, const QDict *qdict); -int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_change_block(Monitor *mon, const char *device, const char *filename, const char *fmt); int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); diff --git a/hmp-commands.hx b/hmp-commands.hx index 047fba2..364623c 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -75,8 +75,7 @@ ETEXI .args_type = "force:-f,device:B", .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd = hmp_eject, }, STEXI diff --git a/hmp.c b/hmp.c index 081acab..a0752f5 100644 --- a/hmp.c +++ b/hmp.c @@ -702,3 +702,13 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict) qmp_expire_password(protocol, whenstr, &err); hmp_handle_error(mon, &err); } + +void hmp_eject(Monitor *mon, const QDict *qdict) +{ + int force = qdict_get_try_bool(qdict, "force", 0); + const char *device = qdict_get_str(qdict, "device"); + Error *err = NULL; + + qmp_eject(device, true, force, &err); + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 575f529..29dbf93 100644 --- a/hmp.h +++ b/hmp.h @@ -51,5 +51,6 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict); void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict); void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); +void hmp_eject(Monitor *mon, const QDict *qdict); #endif diff --git a/qapi-schema.json b/qapi-schema.json index dc92a79..42682eb 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1331,3 +1331,24 @@ # sure you are on the same machine as the QEMU instance. ## { 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} } + +## +# @eject: +# +# Ejects a device from a removable drive. +# +# @device: The name of the device +# +# @force: @optional If true, eject regardless of whether the drive is locked. +# If not specified, the default value is false. +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @device is not removable and @force is false, DeviceNotRemovable +# If @force is false and @device is locked, DeviceLocked +# +# Notes: Ejecting a device will no media results in success +# +# Since: 0.14.0 +## +{ 'command': 'eject', 'data': {'device': 'str', '*force': 'bool'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index d7264b2..185beba 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -84,10 +84,7 @@ EQMP { .name = "eject", .args_type = "force:-f,device:B", - .params = "[-f] device", - .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd_new = qmp_marshal_input_eject, }, SQMP