Skip to contentSkip to conversation

qcow2: Avoid making the L1 table too big

PATCH Applied Max Reitz 3 participants 9 messages Jun 15, 2016 – Jul 6, 2016 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover qcow2: Avoid making the L1 table too big

See https://bugs.launchpad.net/qemu/+bug/1592590 for a bug report.

Reproducer:

$ ./qemu-img create -f qcow2 test.qcow2 1M
Formatting 'test.qcow2', fmt=qcow2 size=1048576 encryption=off
cluster_size=65536 lazy_refcounts=off refcount_bits=16
$ ./qemu-img resize test.qcow2 100000T
Image resized.
$ ./qemu-img info test.qcow2
qemu-img: Could not open 'test.qcow2': Active L1 table too large

After this series:

$ ./qemu-img resize test.qcow2 100000T
qemu-img: Error resizing image: File too large

Max Reitz (2):
qemu-img: Use strerror() for generic resize error
qcow2: Avoid making the L1 table too big

 block/qcow2-cluster.c | 2 +-
 qemu-img.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.8.3
author
#1 lore raw

PATCH 1/2 qemu-img: Use strerror() for generic resize error

Emitting the plain error number is not very helpful. Use strerror() instead.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +1 -1
index 14e2661..d5ccd9a 100644
@@ -3277,7 +3277,7 @@ static int img_resize(int argc, char **argv)
         error_report("Image is read-only");
         break;
     default:
-        error_report("Error resizing image (%d)", -ret);
+        error_report("Error resizing image: %s", strerror(-ret));
         break;
     }
 out:
Signature · 1 line
2.8.3
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qemu-img: Use strerror() for generic resize error

Quoted 13 lines · Max Reitz

Emitting the plain error number is not very helpful. Use strerror() instead.

---
 qemu-img.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-img.c +0 -0
index 14e2661..d5ccd9a 100644

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

Quoted 6 lines
qemu-img.c +1 -1
@@ -3277,7 +3277,7 @@ static int img_resize(int argc, char **argv)
         error_report("Image is read-only");
         break;
     default:
-        error_report("Error resizing image (%d)", -ret);
+        error_report("Error resizing image: %s", strerror(-ret));
         break;

I've argued in the past that we have lots of error_report() callers using strerror(), and may want to add an error_report_errno() (similar to error_setg_errno()); this just adds to the list of things that would benefit. But such a conversion would be a separate BiteSized task, and doesn't invalidate your patch.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#3 lore raw

PATCH 2/2 qcow2: Avoid making the L1 table too big

In reply to Max Reitz

We refuse to open images whose L1 table we deem "too big". Consequently, we should not produce such images ourselves.

---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2-cluster.c +1 -1
index 893ddf6..335b9b0 100644
@@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }
 
Signature · 1 line
2.8.3
Reviewed-by on v1 2/2
#4 lore raw
Quoted 8 lines · Max Reitz

We refuse to open images whose L1 table we deem "too big". Consequently, we should not produce such images ourselves.

---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
block/qcow2-cluster.c +1 -1
index 893ddf6..335b9b0 100644
@@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }
 
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
In reply to Max Reitz

Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:

Quoted 14 lines

We refuse to open images whose L1 table we deem "too big". Consequently, we should not produce such images ourselves.

---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2-cluster.c +0 -0
index 893ddf6..335b9b0 100644

block/qcow2-cluster.c int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, · line 70

Quoted 7 lines
block/qcow2-cluster.c +1 -1
@@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }

Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?

Kevin

author
#6 lore raw
Quoted 18 lines · Kevin Wolf

Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:

Quoted 17 lines

We refuse to open images whose L1 table we deem "too big". Consequently, we should not produce such images ourselves.

---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2-cluster.c +0 -0
index 893ddf6..335b9b0 100644
@@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
Quoted 6 lines

block/qcow2-cluster.c int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, · line 70

Quoted 4 lines
block/qcow2-cluster.c +1 -1
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }

Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?

Good idea, did that. I changed it directly in my block branch, or do you think a v2 mail necessary?

Max

#7 lore raw

Am 06.07.2016 um 14:47 hat Max Reitz geschrieben:

Quoted 26 lines · Kevin Wolf
Quoted 18 lines

Am 15.06.2016 um 17:36 hat Max Reitz geschrieben:

Quoted 17 lines

We refuse to open images whose L1 table we deem "too big". Consequently, we should not produce such images ourselves.

---
 block/qcow2-cluster.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/qcow2-cluster.c +0 -0
index 893ddf6..335b9b0 100644
@@ -65,7 +65,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
         }
     }
 
Quoted 6 lines

block/qcow2-cluster.c int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, · line 70

Quoted 4 lines
block/qcow2-cluster.c +1 -1
-    if (new_l1_size > INT_MAX / sizeof(uint64_t)) {
+    if (new_l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
         return -EFBIG;
     }

Maybe add a QEMU_BUILD_BUG_ON(QCOW_MAX_L1_SIZE > INT_MAX)?

Quoted 2 lines

Good idea, did that. I changed it directly in my block branch, or do you think a v2 mail necessary?

No, letting you apply it directly is what I intended.

Kevin

author Applied
#8 lore raw
In reply to Max Reitz
Quoted 18 lines · Max Reitz

See https://bugs.launchpad.net/qemu/+bug/1592590 for a bug report.

Reproducer:

$ ./qemu-img create -f qcow2 test.qcow2 1M
Formatting 'test.qcow2', fmt=qcow2 size=1048576 encryption=off
cluster_size=65536 lazy_refcounts=off refcount_bits=16
$ ./qemu-img resize test.qcow2 100000T
Image resized.
$ ./qemu-img info test.qcow2
qemu-img: Could not open 'test.qcow2': Active L1 table too large

After this series:

$ ./qemu-img resize test.qcow2 100000T
qemu-img: Error resizing image: File too large
Quoted 7 lines

Max Reitz (2):
qemu-img: Use strerror() for generic resize error
qcow2: Avoid making the L1 table too big

 block/qcow2-cluster.c | 2 +-
 qemu-img.c            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Applied to my block branch.

Max