Skip to contentSkip to conversation

qemu: fix the bug reported by qemu-iotests case 055

PATCH In review QingFeng Hao 4 participants 7 messages Dec 16, 2016 – Feb 13, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

v3 cover qemu: fix the bug reported by qemu-iotests case 055

Hi all,
v3 doesn't have code change but got the reviewed-by from Fam Zheng(thanks to Fam).
v2 includes changes due to review comments by Kevin Wolf(thanks to Kevin).

v3:
* Got reviewed-by from Fam Zheng.
* Based on master's commit:
6a928d25b6: Update version for v2.8.0-rc4 release

v2:
* Add endian conversion for lba field in vmdk_write_extent.
* Based on master's commit:
00227fefd205: Update version for v2.8.0-rc1 release

v1:
* Add patch to fix the bug reported by qemu-iotests case 055. Jing Liu and I found the cause was in vmdk and the fix is in the followed patch.
Based on master's commit:
00227fefd205: Update version for v2.8.0-rc1 release

Upstream master's qemu-iotests case 055 reports the following error:
+qemu-img: Error while reading offset 0 of tests/qemu-iotests/scratch/blockdev-target.img: Invalid argument +qemu-img: Error while reading offset 0 of tests/qemu-iotests/scratch/blockdev-target.img: Invalid argument +qemu-img: Error while reading offset 0 of tests/qemu-iotests/scratch/blockdev-target.img: Invalid argument +qemu-img: Error while reading offset 0 of tests/qemu-iotests/scratch/blockdev-target.img: Invalid argument

Thanks!
QingFeng Hao

QingFeng Hao (1):
block/vmdk: Fix the endian problem of buf_len and lba

 block/vmdk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.8.4
#1 lore raw

PATCH v3 1/1 block/vmdk: Fix the endian problem of buf_len and lba

The problem was triggered by qemu-iotests case 055. It failed when it was comparing the compressed vmdk image with original test.img.

The cause is that buf_len in vmdk_write_extent wasn't converted to little-endian before it was stored to disk. But later vmdk_read_extent read it and converted it from little-endian to cpu endian. If the cpu is big-endian like s390, the problem will happen and the data length read by vmdk_read_extent will become invalid! The fix is to add the conversion in vmdk_write_extent, meanwhile, repair the endianness problem of lba field which shall also be converted to little-endian before storing to disk.

---
 block/vmdk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/vmdk.c +2 -2
index a11c27a..26e5f95 100644
@@ -1354,8 +1354,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
             goto out;
         }
 
-        data->lba = offset >> BDRV_SECTOR_BITS;
-        data->size = buf_len;
+        data->lba = cpu_to_le64(offset >> BDRV_SECTOR_BITS);
+        data->size = cpu_to_le32(buf_len);
 
         n_bytes = buf_len + sizeof(VmdkGrainMarker);
         iov = (struct iovec) {
Signature · 1 line
2.8.4
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/1] block/vmdk: Fix the endian problem of buf_len and lba

Dears,

We would like to know if this patch will be pulled

into upstream or what else we need to do for it?

Because for upstream, the qemu-iotests case 055 still failed.

Thanks.

Jing

Quoted 36 lines · QingFeng Hao

The problem was triggered by qemu-iotests case 055. It failed when it was comparing the compressed vmdk image with original test.img.

The cause is that buf_len in vmdk_write_extent wasn't converted to little-endian before it was stored to disk. But later vmdk_read_extent read it and converted it from little-endian to cpu endian. If the cpu is big-endian like s390, the problem will happen and the data length read by vmdk_read_extent will become invalid! The fix is to add the conversion in vmdk_write_extent, meanwhile, repair the endianness problem of lba field which shall also be converted to little-endian before storing to disk.

---
  block/vmdk.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
block/vmdk.c +2 -2
index a11c27a..26e5f95 100644
@@ -1354,8 +1354,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
              goto out;
          }
 
-        data->lba = offset >> BDRV_SECTOR_BITS;
-        data->size = buf_len;
+        data->lba = cpu_to_le64(offset >> BDRV_SECTOR_BITS);
+        data->size = cpu_to_le32(buf_len);
 
          n_bytes = buf_len + sizeof(VmdkGrainMarker);
          iov = (struct iovec) {
#3 lore raw

Re: [Qemu-devel] [PATCH v3 1/1] block/vmdk: Fix the endian problem of buf_len and lba

Quoted 7 lines · liujing

Dears,

We would like to know if this patch will be pulled

into upstream or what else we need to do for it?

Because for upstream, the qemu-iotests case 055 still failed.

Kevin, would you like to take this or should I do it?

Fam

Quoted 45 lines

Thanks.

Jing

Quoted 36 lines · QingFeng Hao

The problem was triggered by qemu-iotests case 055. It failed when it was comparing the compressed vmdk image with original test.img.

The cause is that buf_len in vmdk_write_extent wasn't converted to little-endian before it was stored to disk. But later vmdk_read_extent read it and converted it from little-endian to cpu endian. If the cpu is big-endian like s390, the problem will happen and the data length read by vmdk_read_extent will become invalid! The fix is to add the conversion in vmdk_write_extent, meanwhile, repair the endianness problem of lba field which shall also be converted to little-endian before storing to disk.

---
  block/vmdk.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
block/vmdk.c +2 -2
index a11c27a..26e5f95 100644
@@ -1354,8 +1354,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
              goto out;
          }
 
-        data->lba = offset >> BDRV_SECTOR_BITS;
-        data->size = buf_len;
+        data->lba = cpu_to_le64(offset >> BDRV_SECTOR_BITS);
+        data->size = cpu_to_le32(buf_len);
 
          n_bytes = buf_len + sizeof(VmdkGrainMarker);
          iov = (struct iovec) {
#4 lore raw

Re: [Qemu-devel] [PATCH v3 1/1] block/vmdk: Fix the endian problem of buf_len and lba

Quoted 10 lines · Fam Zheng
Quoted 7 lines · liujing

Dears,

We would like to know if this patch will be pulled

into upstream or what else we need to do for it?

Because for upstream, the qemu-iotests case 055 still failed.

Kevin, would you like to take this or should I do it?

Adding Max since he's taking care of the other VMDK fix I posted.

Fam

#5 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/1] block/vmdk: Fix the endian problem of buf_len and lba

In reply to QingFeng Hao
Quoted 12 lines · QingFeng Hao

The problem was triggered by qemu-iotests case 055. It failed when it was comparing the compressed vmdk image with original test.img.

The cause is that buf_len in vmdk_write_extent wasn't converted to little-endian before it was stored to disk. But later vmdk_read_extent read it and converted it from little-endian to cpu endian. If the cpu is big-endian like s390, the problem will happen and the data length read by vmdk_read_extent will become invalid! The fix is to add the conversion in vmdk_write_extent, meanwhile, repair the endianness problem of lba field which shall also be converted to little-endian before storing to disk.

Quoted 8 lines
---
 block/vmdk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thanks, I've applied the patch to my block tree:

https://github.com/XanClic/qemu/commits/block

Max

#6 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/1] block/vmdk: Fix the endian problem of buf_len and lba

Quoted 21 lines · Max Reitz
Quoted 12 lines · QingFeng Hao

The problem was triggered by qemu-iotests case 055. It failed when it was comparing the compressed vmdk image with original test.img.

The cause is that buf_len in vmdk_write_extent wasn't converted to little-endian before it was stored to disk. But later vmdk_read_extent read it and converted it from little-endian to cpu endian. If the cpu is big-endian like s390, the problem will happen and the data length read by vmdk_read_extent will become invalid! The fix is to add the conversion in vmdk_write_extent, meanwhile, repair the endianness problem of lba field which shall also be converted to little-endian before storing to disk.

Quoted 8 lines
---
  block/vmdk.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines

Thanks, I've applied the patch to my block tree:

https://github.com/XanClic/qemu/commits/block

Thanks Max!

Quoted 3 lines

Max

Signature · 1 line
QingFeng Hao(Robin)