diff mbox

[V5,5/6] block: Add backing file loop check in change_backing_file()

Message ID 1375434137-4452-6-git-send-email-gesaint@linux.vnet.ibm.com
State New
Headers show

Commit Message

Xu Wang Aug. 2, 2013, 9:02 a.m. UTC
From: Xu Wang <cngesaint@gmail.com>

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(+)

Comments

Eric Blake Aug. 2, 2013, 10:31 p.m. UTC | #1
On 08/02/2013 03:02 AM, Xu Wang wrote:
> From: Xu Wang <cngesaint@gmail.com>
> 
> Backing file loop should be checked before calling change_backing_
> file(). If loop appeared, this calling should be stopped and an

Breaking a function name across a line break is awkward.

> error was printed.

s/was //

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

>  
> +    /* Check if loop exists in backing files chain after changed */

s/changed/change/

But isn't that a bit late?  Don't you want to check that a backing loop
will not be created, prior to making the change?

> +    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 {
>
diff mbox

Patch

diff --git a/block.c b/block.c
index 8bb63c2..a14488f 100644
--- a/block.c
+++ b/block.c
@@ -1963,6 +1963,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 {