Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 280

kvm-83-270.el5_11.src.rpm

From b8890e9aed2157fc554fc98631f001ae3d955076 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <armbru@redhat.com>
Date: Tue, 19 Apr 2011 15:10:15 -0300
Subject: [PATCH 03/10] block: Change bdrv_eject() not to drop the image

RH-Author: Markus Armbruster <armbru@redhat.com>
Message-id: <1303225822-22611-2-git-send-email-armbru@redhat.com>
Patchwork-id: 22558
O-Subject: [PATCH RHEL5 qemu-kvm 1/8] block: Change bdrv_eject() not to drop the image
Bugzilla: 652135
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>

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 <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Manually cherry-picked from qemu commit 4be9762adb0947a353e6efef2fed354f69218bfb
---
 qemu/block.c     |    7 ++++---
 qemu/block_int.h |    1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu/block.c     |    7 ++++---
 qemu/block_int.h |    1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/qemu/block.c b/qemu/block.c
index 46f44aa..7525fb6 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -1874,7 +1874,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;
 }
@@ -1916,10 +1916,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/qemu/block_int.h b/qemu/block_int.h
index dd40c5d..bf21589 100644
--- a/qemu/block_int.h
+++ b/qemu/block_int.h
@@ -119,6 +119,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* */
-- 
1.7.5.141.g791a