qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/3] block: Allow x-blockdev-del on a BB with a monitor-owned BDS
@ 2016-02-08 14:14 Alberto Garcia
  2016-02-08 14:14 ` [Qemu-devel] [PATCH 2/3] iotests: Update test 139 after the changes in x-blockdev-del Alberto Garcia
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Alberto Garcia @ 2016-02-08 14:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Alberto Garcia, qemu-block, Max Reitz

When x-blockdev-del is performed on a BlockBackend that has inserted
media it will only succeed if the BDS doesn't have any additional
references.

The only problem with this is that if the BDS was created separately
using blockdev-add then the backend won't be able to be destroyed
unless the BDS is ejected first. This is an unnecessary restriction.

Now that we have a list of monitor-owned BDSs we can allow
x-blockdev-del to work in this scenario if the BDS has exactly one
extra reference and that reference is from the monitor.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 blockdev.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index e1b6b0f..847058d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3966,9 +3966,16 @@ void qmp_x_blockdev_del(bool has_id, const char *id,
         }
 
         if (bs->refcnt > 1) {
-            error_setg(errp, "Block device %s is in use",
-                       bdrv_get_device_or_node_name(bs));
-            goto out;
+            /* We allow deleting a BlockBackend that has a BDS with an
+             * extra reference if that extra reference is from the
+             * monitor. */
+            bool bs_has_only_monitor_ref =
+                blk && bs->monitor_list.tqe_prev && bs->refcnt == 2;
+            if (!bs_has_only_monitor_ref) {
+                error_setg(errp, "Block device %s is in use",
+                           bdrv_get_device_or_node_name(bs));
+                goto out;
+            }
         }
     }
 
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-02-09 15:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08 14:14 [Qemu-devel] [PATCH 1/3] block: Allow x-blockdev-del on a BB with a monitor-owned BDS Alberto Garcia
2016-02-08 14:14 ` [Qemu-devel] [PATCH 2/3] iotests: Update test 139 after the changes in x-blockdev-del Alberto Garcia
2016-02-09 15:36   ` Eric Blake
2016-02-09 15:44     ` Alberto Garcia
2016-02-08 14:14 ` [Qemu-devel] [PATCH 3/3] block: Update the x-blockdev-del documentation Alberto Garcia
2016-02-09 15:38   ` Eric Blake
2016-02-09 10:32 ` [Qemu-devel] [PATCH 1/3] block: Allow x-blockdev-del on a BB with a monitor-owned BDS Kevin Wolf
2016-02-09 10:47   ` Alberto Garcia
2016-02-09 15:34 ` Eric Blake
2016-02-09 15:39   ` Alberto Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).