From patchwork Fri Jun 3 19:03:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98644 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 43C9FB6FAD for ; Sat, 4 Jun 2011 05:47:37 +1000 (EST) Received: from localhost ([::1]:52102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSaLF-00075D-RC for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2011 15:47:34 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfT-0005ev-MA for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSZfR-0002Vy-LH for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfR-0002Vn-6N for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:21 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4KwZ009973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 15:04:20 -0400 Received: from localhost (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p53J4IS3032287; Fri, 3 Jun 2011 15:04:19 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2011 16:03:58 -0300 Message-Id: <1307127842-12102-7-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.23 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 06/10] QMP: Introduce the blockdev-tray-close 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 closes a removable media drive's tray. It's only available in QMP. 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 closed? Signed-off-by: Luiz Capitulino --- blockdev.c | 22 ++++++++++++++++++++++ blockdev.h | 1 + qmp-commands.hx | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index b1c705c..943905d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -704,6 +704,28 @@ static int tray_open(const char *device, int remove, int force) return 0; } +static int tray_close(const char *device) +{ + BlockDriverState *bs; + + bs = bdrv_removable_find(device); + if (!bs) { + return -1; + } + + if (bdrv_eject(bs, 0, 0) < 0) { + /* FIXME: will report undefined error in QMP */ + return -1; + } + + return 0; +} + +int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return tray_close(qdict_get_str(qdict, "device")); +} + int do_tray_open(Monitor *mon, const QDict *qdict, QObject **ret_data) { return tray_open(qdict_get_str(qdict, "device"), diff --git a/blockdev.h b/blockdev.h index 5e46aae..975e91a 100644 --- a/blockdev.h +++ b/blockdev.h @@ -66,5 +66,6 @@ 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); +int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index 58ab132..fdf9750 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -153,6 +153,29 @@ Examples: EQMP { + .name = "blockdev-tray-close", + .args_type = "device:B", + .mhandler.cmd_new = do_tray_close, + }, + +SQMP +blockdev-tray-close +------------------- + +Close a removable media drive's tray. + +Arguments: + +- device: device name (json-string) + +Example: + +-> { "execute": "blockdev-tray-close", "arguments": { "device": "ide1-cd0" } } +<- { "return": {} } + +EQMP + + { .name = "blockdev-tray-open", .args_type = "device:B,force:-f,remove:-r", .mhandler.cmd_new = do_tray_open,