qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Xu Wang <gesaint@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, stefanha@gmail.com,
	wdongxu@linux.vnet.ibm.com, Xu Wang <gesaint@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH V9 3/4] block: Add backing file loop check in change_backing_file()
Date: Tue, 26 Nov 2013 01:38:32 -0500	[thread overview]
Message-ID: <1385447913-19004-4-git-send-email-gesaint@linux.vnet.ibm.com> (raw)
In-Reply-To: <1385447913-19004-1-git-send-email-gesaint@linux.vnet.ibm.com>

Backing file loop should be checked before calling change_backing_
file(). If loop appeared, this calling should be stopped and an
error printed.

Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com>
---
 block.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/block.c b/block.c
index b8cea1c..87f7018 100644
--- a/block.c
+++ b/block.c
@@ -2075,6 +2075,7 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
  * Return values:
  * 0        - success
  * -EINVAL  - backing format specified, but no file
+ * -EIO     - generic I/O error (may happen for all errors)
  * -ENOSPC  - can't update the backing file because no space is left in the
  *            image file header
  * -ENOTSUP - format driver doesn't support changing the backing file
@@ -2083,6 +2084,7 @@ int bdrv_change_backing_file(BlockDriverState *bs,
     const char *backing_file, const char *backing_fmt)
 {
     BlockDriver *drv = bs->drv;
+    Error *local_err = NULL;
     int ret;
 
     /* Backing file format doesn't make sense without a backing file */
@@ -2090,6 +2092,13 @@ int bdrv_change_backing_file(BlockDriverState *bs,
         return -EINVAL;
     }
 
+    /* Check if loop exists in backing files chain after change */
+    if (!bdrv_backing_chain_okay(backing_file, NULL, bs->filename, 
+                                 &local_err)) {
+        error_report("Backing file check: %s", error_get_pretty(local_err));
+        return -EIO;
+    }
+
     if (drv->bdrv_change_backing_file != NULL) {
         ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
     } else {
-- 
1.8.1.4

  parent reply	other threads:[~2013-11-26  6:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-26  6:38 [Qemu-devel] [PATCH V9 0/4] Refine and export backing file loop check Xu Wang
2013-11-26  6:38 ` [Qemu-devel] [PATCH V9 1/4] block/qemu-img: Refine and export infinite loop checking in collect_image_info_list() Xu Wang
2013-12-19 15:23   ` Jeff Cody
2013-12-19 16:18   ` Jeff Cody
2013-11-26  6:38 ` [Qemu-devel] [PATCH V9 2/4] block: Add check infinite loop in bdrv_img_create() Xu Wang
2013-12-19 16:27   ` Jeff Cody
2013-11-26  6:38 ` Xu Wang [this message]
2013-12-19 16:13   ` [Qemu-devel] [PATCH V9 3/4] block: Add backing file loop check in change_backing_file() Jeff Cody
2013-11-26  6:38 ` [Qemu-devel] [PATCH V9 4/4] blockdev: Add infinite loop check in drive_init() Xu Wang
2013-12-19 17:25   ` Jeff Cody

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=1385447913-19004-4-git-send-email-gesaint@linux.vnet.ibm.com \
    --to=gesaint@linux.vnet.ibm.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=wdongxu@linux.vnet.ibm.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).