From patchwork Fri Jun 3 19:03:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98632 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 D65C6B6FB2 for ; Sat, 4 Jun 2011 05:19:11 +1000 (EST) Received: from localhost ([::1]:47691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZtk-0000Fy-Dd for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2011 15:19:08 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfW-0005fl-NX for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSZfP-0002Vc-37 for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfO-0002VL-Mh for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:18 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4Hoo024769 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 15:04:18 -0400 Received: from localhost (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4Gir021156; Fri, 3 Jun 2011 15:04:17 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2011 16:03:57 -0300 Message-Id: <1307127842-12102-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com> References: <1307127842-12102-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, amit.shah@redhat.com, aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [RFC 05/10] QMP: Introduce the blockdev-tray-open command 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 This command opens a removable media drive's tray. It's only available in QMP. The do_tray_open() function is split into two smaller functions because next commits will also use them. Please, check the command's documentation (being introduced in this commit) for a detailed description. XXX: Should we return an error if the tray is already open? Signed-off-by: Luiz Capitulino --- blockdev.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ blockdev.h | 1 + qmp-commands.hx | 27 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6e0eb83..b1c705c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -665,6 +665,52 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force) return 0; } +static BlockDriverState *bdrv_removable_find(const char *name) +{ + BlockDriverState *bs; + + bs = bdrv_find(name); + if (!bs) { + qerror_report(QERR_DEVICE_NOT_FOUND, name); + return NULL; + } + + if (!bdrv_is_removable(bs)) { + qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs)); + return NULL; + } + + return bs; +} + +static int tray_open(const char *device, int remove, int force) +{ + BlockDriverState *bs; + + bs = bdrv_removable_find(device); + if (!bs) { + return -1; + } + + if (bdrv_eject(bs, 1, force) < 0) { + /* FIXME: will report undefined error in QMP */ + return -1; + } + + if (remove) { + bdrv_close(bs); + } + + return 0; +} + +int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return tray_open(qdict_get_str(qdict, "device"), + qdict_get_try_bool(qdict, "remove", 0), + qdict_get_try_bool(qdict, "force", 0)); +} + int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data) { BlockDriverState *bs; diff --git a/blockdev.h b/blockdev.h index 3587786..5e46aae 100644 --- a/blockdev.h +++ b/blockdev.h @@ -65,5 +65,6 @@ int do_change_block(Monitor *mon, const char *device, int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data); int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); +int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index 8393f22..58ab132 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -153,6 +153,33 @@ Examples: EQMP { + .name = "blockdev-tray-open", + .args_type = "device:B,force:-f,remove:-r", + .mhandler.cmd_new = do_tray_open, + }, + +SQMP +blockdev-tray-open +------------------ + +Open a removable media drive's tray. + +Arguments: + +- device: device name (json-string) +- force: force ejection (json-bool, optional) +- remove: remove the media (json-bool, optional) + +Example: + +-> { "execute": "blockdev-tray-open", "arguments": { "device": "ide1-cd0" } } +<- { "return": {} } + +Note: The tray remains open after this command is issued + +EQMP + + { .name = "screendump", .args_type = "filename:F", .params = "filename",