From patchwork Fri Jun 3 19:04:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 98639 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 4F326B6FAD for ; Sat, 4 Jun 2011 05:29:11 +1000 (EST) Received: from localhost ([::1]:50703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSa3P-0002wC-NS for incoming@patchwork.ozlabs.org; Fri, 03 Jun 2011 15:29:08 -0400 Received: from eggs.gnu.org ([140.186.70.92]:59373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfb-0005gr-Cp for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSZfa-0002XS-0p for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSZfZ-0002XB-AM for qemu-devel@nongnu.org; Fri, 03 Jun 2011 15:04:29 -0400 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 p53J4ScG010001 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 15:04:28 -0400 Received: from localhost (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p53J4Rvo031951; Fri, 3 Jun 2011 15:04:28 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2011 16:04:02 -0300 Message-Id: <1307127842-12102-11-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.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: kwolf@redhat.com, amit.shah@redhat.com, aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [RFC 10/10] QMP/HMP: change: Use QMP tray commands 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 commit rewrites change in terms of blockdev-tray-open, blockdev-media-insert and blockdev-tray-close. There should be no visible changes in HMP or QMP, except that the use of this command causes the BLOCK_TRAY_OPEN *and* BLOCK_TRAY_CLOSE events to emitted. Signed-off-by: Luiz Capitulino --- blockdev.c | 43 +++++++++---------------------------------- 1 files changed, 9 insertions(+), 34 deletions(-) diff --git a/blockdev.c b/blockdev.c index 36c56fd..e9edcb3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -648,23 +648,6 @@ out: return ret; } -static int eject_device(Monitor *mon, BlockDriverState *bs, int force) -{ - if (!force) { - if (!bdrv_is_removable(bs)) { - qerror_report(QERR_DEVICE_NOT_REMOVABLE, - bdrv_get_device_name(bs)); - return -1; - } - if (bdrv_is_locked(bs)) { - qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs)); - return -1; - } - } - bdrv_close(bs); - return 0; -} - static BlockDriverState *bdrv_removable_find(const char *name) { BlockDriverState *bs; @@ -819,30 +802,22 @@ int do_change_block(Monitor *mon, const char *device, const char *filename, const char *fmt) { BlockDriverState *bs; - BlockDriver *drv = NULL; - int bdrv_flags; - bs = bdrv_find(device); - if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, device); + if (tray_open(device, 1, 0) < 0) { /* XXX: should we force? */ return -1; } - if (fmt) { - drv = bdrv_find_whitelisted_format(fmt); - if (!drv) { - qerror_report(QERR_INVALID_BLOCK_FORMAT, fmt); - return -1; - } - } - if (eject_device(mon, bs, 0) < 0) { + + if (media_insert(device, filename, fmt) < 0) { 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, filename, bdrv_flags, drv) < 0) { - qerror_report(QERR_OPEN_FILE_FAILED, filename); + + if (tray_close(device) < 0) { + /* XXX: open the tray and remove the media? */ return -1; } + + bs = bdrv_find(device); /* XXX: bdrv_find() is called 4 times */ + assert(bs != NULL); return monitor_read_bdrv_key_start(mon, bs, NULL, NULL); }