[V3,4/7] block: Add backing file loop check in change_backing_file()

Submitted by Xu Wang on July 15, 2013, 9:42 a.m.

Details

Message ID 1373881356-3294-5-git-send-email-cngesaint@gmail.com
State New
Headers show

Commit Message

Xu Wang July 15, 2013, 9:42 a.m.
Backing file loop should be checked before calling change_backing_
file(). If loop appeared, this calling should be stopped and an
error was printed.

Signed-off-by: Xu Wang <cngesaint@gmail.com>
---
 block.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/block.c b/block.c
index e9b9112..bd8240c 100644
--- a/block.c
+++ b/block.c
@@ -1967,6 +1967,13 @@  int bdrv_change_backing_file(BlockDriverState *bs,
         return -EINVAL;
     }
 
+    /* Check if loop exists in backing files chain after changed */
+    if (bdrv_backing_file_loop_check(bs->filename,
+                                     bs->drv ? bs->drv->format_name : NULL,
+                                     backing_file, backing_fmt)) {
+        return -EIO;
+    }
+
     if (drv->bdrv_change_backing_file != NULL) {
         ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt);
     } else {