From patchwork Tue Aug 3 14:44:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 60761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8E124B70A4 for ; Wed, 4 Aug 2010 00:51:07 +1000 (EST) Received: from localhost ([127.0.0.1]:54902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgIpc-0000iJ-MP for incoming@patchwork.ozlabs.org; Tue, 03 Aug 2010 10:51:04 -0400 Received: from [140.186.70.92] (port=57948 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgIjO-0006Ad-2f for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgIjM-0004HC-P7 for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9481) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgIjM-0004Gv-IH for qemu-devel@nongnu.org; Tue, 03 Aug 2010 10:44:36 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o73EiYLr024580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Aug 2010 10:44:34 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o73EiPOx019437; Tue, 3 Aug 2010 10:44:33 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 3 Aug 2010 16:44:29 +0200 Message-Id: <1280846670-27063-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1280846670-27063-1-git-send-email-kwolf@redhat.com> References: <1280846670-27063-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 5/6] block: Change bdrv_eject() not to drop the image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster bdrv_eject() gets called when a device model opens or closes the tray. If the block driver implements method bdrv_eject(), that method gets called. Drivers host_cdrom implements it, and it opens and closes the physical tray, and nothing else. When a device model opens, then closes the tray, media changes only if the user actively changes the physical media while the tray is open. This is matches how physical hardware behaves. If the block driver doesn't implement method bdrv_eject(), we do something quite different: opening the tray severs the connection to the image by calling bdrv_close(), and closing the tray does nothing. When the device model opens, then closes the tray, media is gone, unless the user actively inserts another one while the tray is open, with a suitable change command in the monitor. This isn't how physical hardware behaves. Rather inconvenient when programs "helpfully" eject media to give you a chance to change it. The way bdrv_eject() behaves here turns that chance into a must, which is not what these programs or their users expect. Change the default action not to call bdrv_close(). Instead, note the tray status in new BlockDriverState member tray_open. Use it in bdrv_is_inserted(). Arguably, the device models should keep track of tray status themselves. But this is less invasive. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block.c | 7 ++++--- block_int.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index a12be0b..da70f29 100644 --- a/block.c +++ b/block.c @@ -2517,7 +2517,7 @@ int bdrv_is_inserted(BlockDriverState *bs) if (!drv) return 0; if (!drv->bdrv_is_inserted) - return 1; + return !bs->tray_open; ret = drv->bdrv_is_inserted(bs); return ret; } @@ -2559,10 +2559,11 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag) ret = drv->bdrv_eject(bs, eject_flag); } if (ret == -ENOTSUP) { - if (eject_flag) - bdrv_close(bs); ret = 0; } + if (ret >= 0) { + bs->tray_open = eject_flag; + } return ret; } diff --git a/block_int.h b/block_int.h index 7d5e751..b863451 100644 --- a/block_int.h +++ b/block_int.h @@ -144,6 +144,7 @@ struct BlockDriverState { int open_flags; /* flags used to open the file, re-used for re-open */ int removable; /* if true, the media can be removed */ int locked; /* if true, the media cannot temporarily be ejected */ + int tray_open; /* if true, the virtual tray is open */ int encrypted; /* if true, the media is encrypted */ int valid_key; /* if true, a valid encryption key has been set */ int sg; /* if true, the device is a /dev/sg* */