Skip to contentSkip to conversation

vmdk: Fix cylinders number during convert

PATCH In review Arthur Gautier 5 participants 9 messages Oct 22, 2014 – Oct 31, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmdk: Fix cylinders number during convert

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

---
 block/vmdk.c               |  4 +--
 tests/qemu-iotests/106     | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/106.out |  5 ++++
 tests/qemu-iotests/group   |  1 +
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100755 tests/qemu-iotests/106
 create mode 100644 tests/qemu-iotests/106.out
block/vmdk.c +2 -2
index 4ae6c75..c22a6c6 100644
@@ -1928,8 +1928,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                            parent_desc_line,
                            ext_desc_lines->str,
                            (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
-                           total_size /
-                               (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE),
+                           DIV_ROUND_UP(total_size,
+                               (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE)),
                            number_heads,
                            adapter_type);
     desc_len = strlen(desc);
tests/qemu-iotests/106 new file +67 -0

67 lines not on this page · raw message

tests/qemu-iotests/106.out new file +5 -0
new file mode 100644
index 0000000..5d2f0a3
@@ -0,0 +1,5 @@
+QA output created by 106
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1024 
+=== Check for correct number of cylinders ===
+
+*** done
tests/qemu-iotests/group +1 -0
index b230996..0c68320 100644
@@ -106,3 +106,4 @@
 103 rw auto quick
 104 rw auto
 105 rw auto quick
+106 rw auto quick
Signature · 1 line
2.1.1
#1 lore raw
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

Thanks,

/mjt

Quoted 16 lines
---
 block/vmdk.c               |  4 +--
 tests/qemu-iotests/106     | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/106.out |  5 ++++
 tests/qemu-iotests/group   |  1 +
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100755 tests/qemu-iotests/106
 create mode 100644 tests/qemu-iotests/106.out
block/vmdk.c +0 -0
index 4ae6c75..c22a6c6 100644

block/vmdk.c static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) · line 1935

Quoted 10 lines
block/vmdk.c +2 -2
@@ -1928,8 +1928,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                            parent_desc_line,
                            ext_desc_lines->str,
                            (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
-                           total_size /
-                               (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE),
+                           DIV_ROUND_UP(total_size,
+                               (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE)),
                            number_heads,
                            adapter_type);
     desc_len = strlen(desc);

[]

#2 lore raw
Quoted 12 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

Quoted 6 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

Too many questions for -trivial, copying VMDK maintainers.

#3 lore raw
Quoted 14 lines · Markus Armbruster
Quoted 12 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

Quoted 8 lines
Quoted 6 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

Too many questions for -trivial, copying VMDK maintainers.

Fam: What do you think about this change?

Stefan

#4 lore raw
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · Michael Tokarev
Quoted 3 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

This ensures the cylinders always gets the ceiling value.

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

I'd like to hear an answer to this question too, so we know why it's right and worth to have.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

I don't remember a reason why truncating (I doubt there is any), OTOH I'm not sure what is the right thing to do if the guest tries to write to the last incomplete CHS either.

Fam

#5 lore raw
Quoted 10 lines · Fam Zheng
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

I'd like to hear an answer to this question too, so we know why it's right and worth to have.

Sincerely, I didn't tried myself.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

Quoted 5 lines

I don't remember a reason why truncating (I doubt there is any), OTOH I'm not sure what is the right thing to do if the guest tries to write to the last incomplete CHS either.

Fam

Maybe we can expand the disk to the size matching cylinders * sectors * sector_size and issue a warning to the user? This way it will always be safe.

WDYT?

Signature · 2 lines
\o/ Arthur
 G  Gandi.net
#6 lore raw
Quoted 34 lines · Arthur Gautier
Quoted 10 lines · Fam Zheng
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

I'd like to hear an answer to this question too, so we know why it's right and worth to have.

Sincerely, I didn't tried myself.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

I don't remember a reason why truncating (I doubt there is any), OTOH I'm not sure what is the right thing to do if the guest tries to write to the last incomplete CHS either.

Quoted 6 lines
Quoted 1 line

Fam

Maybe we can expand the disk to the size matching cylinders * sectors * sector_size and issue a warning to the user? This way it will always be safe.

Possible, but I don't know if it's worth it. Could you explain what doesn't work now, in order to show *why* you need this change?

Thanks,
Fam

#7 lore raw
Quoted 42 lines · Fam Zheng
Quoted 34 lines · Arthur Gautier
Quoted 10 lines · Fam Zheng
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

I'd like to hear an answer to this question too, so we know why it's right and worth to have.

Sincerely, I didn't tried myself.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

I don't remember a reason why truncating (I doubt there is any), OTOH I'm not sure what is the right thing to do if the guest tries to write to the last incomplete CHS either.

Quoted 6 lines
Quoted 1 line

Fam

Maybe we can expand the disk to the size matching cylinders * sectors * sector_size and issue a warning to the user? This way it will always be safe.

Quoted 5 lines

Possible, but I don't know if it's worth it. Could you explain what doesn't work now, in order to show *why* you need this change?

Thanks,
Fam

Please take a look at the test in the patch. I have been able to generate an image with a number of cylinders of zero which I believe is wrong.

Signature · 2 lines
\o/ Arthur
 G  Gandi.net
#8 lore raw
Quoted 46 lines · Arthur Gautier
Quoted 45 lines · Fam Zheng
Quoted 34 lines · Arthur Gautier
Quoted 10 lines · Fam Zheng
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Michael Tokarev
Quoted 4 lines · Arthur Gautier

We can not rely on int cast to get a correct number of cylinders. The cylinders information was wrong in 49.9999% of cases.

This ensures the cylinders always gets the ceiling value.

Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Good thing, especially the good probability :), and also a good patch which comes with a test.

But I wonder if anything can break this way? Migration, windows guest being unable to find its partitions, something else?

I'd like to hear an answer to this question too, so we know why it's right and worth to have.

Sincerely, I didn't tried myself.

Quoted 12 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

And more. What-if our drive size in cylinders will be larger than the size in bytes? The proposed div_round_up() will increase number of cylinders, so size in CHS will be larger than size in bytes. Maybe there was a reason why originally the size in cylinders was calculated by truncating extra fractional part? What-if guest will try to access the very last CHS which is incomplete?

I don't remember a reason why truncating (I doubt there is any), OTOH I'm not sure what is the right thing to do if the guest tries to write to the last incomplete CHS either.

Quoted 6 lines
Quoted 1 line

Fam

Maybe we can expand the disk to the size matching cylinders * sectors * sector_size and issue a warning to the user? This way it will always be safe.

Possible, but I don't know if it's worth it. Could you explain what doesn't work now, in order to show *why* you need this change?

Quoted 7 lines
Quoted 2 lines

Thanks,
Fam

Please take a look at the test in the patch. I have been able to generate an image with a number of cylinders of zero which I believe is wrong.

Why do you believe it is wrong? We are also able to create images with length 0.

Do you have a real use case for this? If we "fix" this to round up the cylinders, there might be other issues for those users who actually use this field.

Do yo know how VMware handle this?

Fam