Patchwork [3/3] Prevent creating an image with the same filename as backing file

login
register
mail settings
Submitter Jes Sorensen
Date Dec. 16, 2010, 11:04 a.m.
Message ID <1292497454-32573-4-git-send-email-Jes.Sorensen@redhat.com>
Download mbox | patch
Permalink /patch/75737/
State New
Headers show

Comments

Jes Sorensen - Dec. 16, 2010, 11:04 a.m.
From: Jes Sorensen <Jes.Sorensen@redhat.com>

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
 block.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
Stefan Hajnoczi - Dec. 16, 2010, 11:46 a.m.
On Thu, Dec 16, 2010 at 11:04 AM,  <Jes.Sorensen@redhat.com> wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  block.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/block.c b/block.c
> index 765f9f3..027dc6a 100644
> --- a/block.c
> +++ b/block.c
> @@ -2769,6 +2769,13 @@ int bdrv_img_create(const char *filename, const char *fmt,
>     BlockDriver *drv, *proto_drv;
>     int ret = 0;
>
> +    if (!strcmp(filename, base_filename)) {
> +        error_report("Error: Trying to create a snapshot with the same "
> +                     "filename as the backing file");

Can we avoid using the word "snapshot" here?  Just "image" would make sense too.

Users could hit this if they incorrectly create an image manually.
They might not be thinking in terms of "snapshot" and that word is
already overloaded in QEMU.

Stefan
Kevin Wolf - Dec. 16, 2010, 11:48 a.m.
Am 16.12.2010 12:04, schrieb Jes.Sorensen@redhat.com:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
> 
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
>  block.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 765f9f3..027dc6a 100644
> --- a/block.c
> +++ b/block.c
> @@ -2769,6 +2769,13 @@ int bdrv_img_create(const char *filename, const char *fmt,
>      BlockDriver *drv, *proto_drv;
>      int ret = 0;
>  
> +    if (!strcmp(filename, base_filename)) {
> +        error_report("Error: Trying to create a snapshot with the same "
> +                     "filename as the backing file");
> +        ret = -1;
> +        goto out;
> +    }
> +
>      /* Find driver and parse its options */
>      drv = bdrv_find_format(fmt);
>      if (!drv) {

This doesn't catch things like qemu-img create -f qcow2
-obacking_file=foo.qcow2 foo.qcow2 though it will work if you use the
legacy -b option. I think we should keep it consistent.

Kevin

Patch

diff --git a/block.c b/block.c
index 765f9f3..027dc6a 100644
--- a/block.c
+++ b/block.c
@@ -2769,6 +2769,13 @@  int bdrv_img_create(const char *filename, const char *fmt,
     BlockDriver *drv, *proto_drv;
     int ret = 0;
 
+    if (!strcmp(filename, base_filename)) {
+        error_report("Error: Trying to create a snapshot with the same "
+                     "filename as the backing file");
+        ret = -1;
+        goto out;
+    }
+
     /* Find driver and parse its options */
     drv = bdrv_find_format(fmt);
     if (!drv) {