Skip to contentSkip to conversation

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

PATCH Superseded QingFeng Hao 3 participants 7 messages Nov 26, 2016 – Nov 28, 2016 Block layer

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Hi all,
v2 includes changes due to review comments by Kevin Wolf(thanks to Kevin).

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 (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 v2 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
Reviewed-by on v2 1/1
#2 lore raw

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

Quoted 39 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) {
Signature · 1 line
2.8.4
#3 lore raw

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

Quoted 34 lines · Fam Zheng
Quoted 33 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);
 
Quoted 7 lines
Quoted 6 lines
block/vmdk.c +0 -0
          n_bytes = buf_len + sizeof(VmdkGrainMarker);
          iov = (struct iovec) {
Signature · 1 line
2.8.4

Thanks!

Signature · 1 line
QingFeng Hao(Robin)
#4 lore raw

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

In reply to QingFeng Hao

Hi QingFeng,

I just have a question that whether the marker->data need convert?

I've no idea, just suddenly realized this question.

Jing

Quoted 35 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) {
#5 lore raw

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

Quoted 8 lines · liujing

Hi QingFeng,

I just have a question that whether the marker->data need convert?

I've no idea, just suddenly realized this question.

nope, the data is type of char * for the compressed data stream, so no endian issue. thanks.

Quoted 40 lines

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) {
Signature · 1 line
QingFeng Hao(Robin)
#6 lore raw
In reply to QingFeng Hao

Sorry, missed Cc qemu-stable in this patch.

Quoted 29 lines · QingFeng Hao

Hi all,
v2 includes changes due to review comments by Kevin Wolf(thanks to Kevin).

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 (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
QingFeng Hao(Robin)