From patchwork Fri Jun 3 19:03:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98624 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 BAEB4B6F6B for ; Sat, 4 Jun 2011 05:08:08 +1000 (EST) Received: from localhost ([::1]:48318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZj2-0005gk-Tb for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2011 15:08:04 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfV-0005fT-JL 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 1QSZfT-0002WL-Jf for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfT-0002W3-28 for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:23 -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 p53J4M9T009978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 15:04:22 -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 p53J4L8h021173; Fri, 3 Jun 2011 15:04:21 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2011 16:03:59 -0300 Message-Id: <1307127842-12102-8-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 07/10] QMP: Introduce the blockdev-media-insert 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 inserts a new media in an already opened tray. It's only available in QMP. Please, check the command's documentation (being introduced in this commit) for a detailed description. Signed-off-by: Luiz Capitulino --- blockdev.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ blockdev.h | 1 + qmp-commands.hx | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index 943905d..14c8312 100644 --- a/blockdev.c +++ b/blockdev.c @@ -721,6 +721,58 @@ static int tray_close(const char *device) return 0; } +static int media_insert(const char *device, const char *mediafile, + const char *format) +{ + BlockDriver *drv = NULL; + BlockDriverState *bs; + int bdrv_flags; + + bs = bdrv_removable_find(device); + if (!bs) { + return -1; + } + + if (bdrv_is_locked(bs)) { + qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs)); + return -1; + } + + if (bdrv_is_inserted(bs)) { + /* FIXME: will report undefined error in QMP */ + return -1; + } + + if (!bs->tray_open) { + /* FIXME: will report undefined error in QMP */ + return 1; + } + + if (format) { + drv = bdrv_find_whitelisted_format(format); + if (!drv) { + qerror_report(QERR_INVALID_BLOCK_FORMAT, format); + return -1; + } + } + + bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR; + bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0; + if (bdrv_open(bs, mediafile, bdrv_flags, drv) < 0) { + qerror_report(QERR_OPEN_FILE_FAILED, mediafile); + return -1; + } + + return 0; +} + +int do_media_insert(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + return media_insert(qdict_get_str(qdict, "device"), + qdict_get_str(qdict, "media"), + qdict_get_try_str(qdict, "format")); +} + int do_tray_close(Monitor *mon, const QDict *qdict, QObject **ret_data) { return tray_close(qdict_get_str(qdict, "device")); diff --git a/blockdev.h b/blockdev.h index 975e91a..4dfd869 100644 --- a/blockdev.h +++ b/blockdev.h @@ -67,5 +67,6 @@ 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); +int do_media_insert(Monitor *mon, const QDict *qdict, QObject **ret_data); #endif diff --git a/qmp-commands.hx b/qmp-commands.hx index fdf9750..fe50593 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -480,6 +480,38 @@ Example: EQMP { + .name = "blockdev-media-insert", + .args_type = "device:B,media:F,format:s?", + .mhandler.cmd_new = do_media_insert, + }, + +SQMP +blockdev-media-insert +--------------------- + +Insert a new media in a removable drive. The tray must be empty and already +opened. The tray is not automatically closed (please, see blockdev-tray-open +and blockdev-tray-close commands). + +Arguments: + +- "device": device name (json-string) +- "media": media file path (json-string) +- "format": media file format (json-string, optional) + +Example: + +-> { "execute": "blockdev-media-insert", + "arguments": { "device": "ide1-cd0", + "media": "/srv/images/Fedora-12-x86_64-DVD.iso" } } +<- { "return": {} } + +Note: If the media is encrypted, the command block_passwd has to be used to + set the media's password. + +EQMP + + { .name = "migrate", .args_type = "detach:-d,blk:-b,inc:-i,uri:s", .params = "[-d] [-b] [-i] uri",