Patchwork [V3,6/7] block: Add backing file loop check in qcow2_change_backing_file()

login
register
mail settings
Submitter Xu Wang
Date July 15, 2013, 9:42 a.m.
Message ID <1373881356-3294-7-git-send-email-cngesaint@gmail.com>
Download mbox | patch
Permalink /patch/258971/
State New
Headers show

Comments

Xu Wang - July 15, 2013, 9:42 a.m.
Add backing file loop check before execute change backing file for
qcow2 format.

Signed-off-by: Xu Wang <cngesaint@gmail.com>
---
 block/qcow2.c | 6 ++++++
 1 file changed, 6 insertions(+)
Fam Zheng - July 18, 2013, 5:32 a.m.
On Mon, 07/15 05:42, Xu Wang wrote:
> Add backing file loop check before execute change backing file for
> qcow2 format.
> 
> Signed-off-by: Xu Wang <cngesaint@gmail.com>
> ---
>  block/qcow2.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 0eceefe..01bd7d5 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -1195,6 +1195,12 @@ fail:
>  static int qcow2_change_backing_file(BlockDriverState *bs,
>      const char *backing_file, const char *backing_fmt)
>  {
> +    /* 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;
> +    }
>      pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: "");
>      pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: "");
>  
> -- 
> 1.8.1.4
> 

I'm not sure this is needed, there's already loop check in block layer's
bdrv_change_backing_file(), which calls drv->bdrv_change_backing_file().
wouldn't this be redundant?

Thanks.

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 0eceefe..01bd7d5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1195,6 +1195,12 @@  fail:
 static int qcow2_change_backing_file(BlockDriverState *bs,
     const char *backing_file, const char *backing_fmt)
 {
+    /* 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;
+    }
     pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: "");
     pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?: "");