Skip to contentSkip to conversation

qemu-img: Make resize error message more general

PATCH Applied Max Reitz 3 participants 4 messages Feb 5, 2018 – Feb 23, 2018

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qemu-img: Make resize error message more general

The issue:

  $ qemu-img resize -f qcow2 foo.qcow2
  qemu-img: Expecting one image file name
  Try 'qemu-img --help' for more information

So we gave an image file name, but we omitted the length. qemu-img thinks the last argument is always the size and removes it immediately from argv (by decrementing argc), and tries to verify that it is a valid size only at a later point.

So we do not actually know whether that last argument we called "size" is indeed a size or whether the user instead forgot to specify that size but did give a file name.

Therefore, the error message should be more general.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
index 68b375f998..2753b63514 100644
@@ -3468,7 +3468,7 @@ static int img_resize(int argc, char **argv)
         }
     }
     if (optind != argc - 1) {
-        error_exit("Expecting one image file name");
+        error_exit("Expecting image file name and size");
     }
     filename = argv[optind++];
 
Signature · 1 line
2.14.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Max Reitz

The issue:

  $ qemu-img resize -f qcow2 foo.qcow2
  qemu-img: Expecting one image file name
  Try 'qemu-img --help' for more information

So we gave an image file name, but we omitted the length. qemu-img thinks the last argument is always the size and removes it immediately from argv (by decrementing argc), and tries to verify that it is a valid size only at a later point.

So we do not actually know whether that last argument we called "size" is indeed a size or whether the user instead forgot to specify that size but did give a file name.

Therefore, the error message should be more general.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +0 -0
index 68b375f998..2753b63514 100644

qemu-img.c static int img_resize(int argc, char **argv) · line 3474

Quoted 8 lines
qemu-img.c +1 -1
@@ -3468,7 +3468,7 @@ static int img_resize(int argc, char **argv)
         }
     }
     if (optind != argc - 1) {
-        error_exit("Expecting one image file name");
+        error_exit("Expecting image file name and size");
     }
     filename = argv[optind++];
 

Sounds good to me.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Max Reitz
Quoted 28 lines · Max Reitz

The issue:

   $ qemu-img resize -f qcow2 foo.qcow2
   qemu-img: Expecting one image file name
   Try 'qemu-img --help' for more information

So we gave an image file name, but we omitted the length. qemu-img thinks the last argument is always the size and removes it immediately from argv (by decrementing argc), and tries to verify that it is a valid size only at a later point.

So we do not actually know whether that last argument we called "size" is indeed a size or whether the user instead forgot to specify that size but did give a file name.

Therefore, the error message should be more general.

---
  qemu-img.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +0 -0
index 68b375f998..2753b63514 100644

qemu-img.c static int img_resize(int argc, char **argv) · line 3471

Quoted 5 lines
qemu-img.c +1 -1
@@ -3468,7 +3468,7 @@ static int img_resize(int argc, char **argv)
          }
      }
      if (optind != argc - 1) {
-        error_exit("Expecting one image file name");
+        error_exit("Expecting image file name and size");

Yes, that reads better in the context you described.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author Applied
#3 lore raw
In reply to Max Reitz
Quoted 15 lines · Max Reitz

The issue:

  $ qemu-img resize -f qcow2 foo.qcow2
  qemu-img: Expecting one image file name
  Try 'qemu-img --help' for more information

So we gave an image file name, but we omitted the length. qemu-img thinks the last argument is always the size and removes it immediately from argv (by decrementing argc), and tries to verify that it is a valid size only at a later point.

So we do not actually know whether that last argument we called "size" is indeed a size or whether the user instead forgot to specify that size but did give a file name.

Quoted 7 lines

Therefore, the error message should be more general.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to my block branch.

Max