qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Benoît Canet" <benoit.canet@nodalink.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, jcody@redhat.com,
	"Benoît Canet" <benoit.canet@nodalink.com>,
	stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] block: commit and stream return an error when a subtree is found
Date: Mon, 15 Sep 2014 16:21:20 +0200	[thread overview]
Message-ID: <1410790880-21861-3-git-send-email-benoit.canet@nodalink.com> (raw)
In-Reply-To: <1410790880-21861-1-git-send-email-benoit.canet@nodalink.com>

In bdrv_find_backing_image when looking for the base BDS of a backing chain and
a BDS having a multiple children block driver is found return NULL and set an
error message.

This will hopefully remove any unwanted interference between stream, commit
and drivers like quorum.

CC: Jeff Cody <jcody@redhat.com>
Signed-off-by: Benoît Canet <benoit.canet@nodalink.com>
---
 block.c               | 17 +++++++++++++++--
 blockdev.c            | 18 ++++++++++++------
 include/block/block.h |  3 ++-
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index d06dd51..ea86252 100644
--- a/block.c
+++ b/block.c
@@ -4339,9 +4339,13 @@ int bdrv_is_snapshot(BlockDriverState *bs)
 /* backing_file can either be relative, or absolute, or a protocol.  If it is
  * relative, it must be relative to the chain.  So, passing in bs->filename
  * from a BDS as backing_file should not be done, as that may be relative to
- * the CWD rather than the chain. */
+ * the CWD rather than the chain.
+ * If a multiple children BDS driver is found down the backing chain path then
+ * return NULL and set an error message.
+ */
 BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
-        const char *backing_file)
+                                          const char *backing_file,
+                                          Error **errp)
 {
     char *filename_full = NULL;
     char *backing_file_full = NULL;
@@ -4362,6 +4366,15 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
 
     for (curr_bs = bs; curr_bs->backing_hd; curr_bs = curr_bs->backing_hd) {
 
+        /* If a BDS having a multiple children block driver is found then the
+         * function should fail.
+         */
+        if (curr_bs->drv && curr_bs->drv->supports_multiple_children) {
+            error_setg(errp, "multiple children block driver found down the "
+                             "backing chain");
+            break;
+        }
+
         /* If either of the filename paths is actually a protocol, then
          * compare unmodified paths; otherwise make paths relative */
         if (is_protocol || path_has_protocol(curr_bs->backing_file)) {
diff --git a/blockdev.c b/blockdev.c
index e919566..4c5c28e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1894,9 +1894,11 @@ void qmp_block_stream(const char *device,
     }
 
     if (has_base) {
-        base_bs = bdrv_find_backing_image(bs, base);
+        base_bs = bdrv_find_backing_image(bs, base, errp);
         if (base_bs == NULL) {
-            error_set(errp, QERR_BASE_NOT_FOUND, base);
+            if (!*errp) {
+                error_set(errp, QERR_BASE_NOT_FOUND, base);
+            }
             return;
         }
         base_name = base;
@@ -1965,23 +1967,27 @@ void qmp_block_commit(const char *device,
 
     if (has_top && top) {
         if (strcmp(bs->filename, top) != 0) {
-            top_bs = bdrv_find_backing_image(bs, top);
+            top_bs = bdrv_find_backing_image(bs, top, errp);
         }
     }
 
     if (top_bs == NULL) {
-        error_setg(errp, "Top image file %s not found", top ? top : "NULL");
+        if (!*errp) {
+            error_setg(errp, "Top image file %s not found", top ? top : "NULL");
+        }
         return;
     }
 
     if (has_base && base) {
-        base_bs = bdrv_find_backing_image(top_bs, base);
+        base_bs = bdrv_find_backing_image(top_bs, base, errp);
     } else {
         base_bs = bdrv_find_base(top_bs);
     }
 
     if (base_bs == NULL) {
-        error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL");
+        if (!*errp) {
+            error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL");
+        }
         return;
     }
 
diff --git a/include/block/block.h b/include/block/block.h
index 8f4ad16..65cde65 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -272,7 +272,8 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
 int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
     int nb_sectors, BdrvRequestFlags flags);
 BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
-    const char *backing_file);
+                                          const char *backing_file,
+                                          Error **errp);
 int bdrv_get_backing_file_depth(BlockDriverState *bs);
 void bdrv_refresh_filename(BlockDriverState *bs);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
-- 
2.1.0

  parent reply	other threads:[~2014-09-15 14:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15 14:21 [Qemu-devel] [PATCH 0/2] Handle interferences between multiple children drivers and stream and commit Benoît Canet
2014-09-15 14:21 ` [Qemu-devel] [PATCH 1/2] block: Introduce a BlockDriver field to flag drivers supporting multiple children Benoît Canet
2014-09-15 14:21 ` Benoît Canet [this message]
2014-09-19  4:35 ` [Qemu-devel] [PATCH 0/2] Handle interferences between multiple children drivers and stream and commit Jeff Cody
2014-09-19 14:08   ` Benoît Canet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1410790880-21861-3-git-send-email-benoit.canet@nodalink.com \
    --to=benoit.canet@nodalink.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).