Skip to contentSkip to conversation

vpc: fix return value check for blk_pwrite

PATCH Applied Paolo Bonzini 2 participants 2 messages Apr 7, 2016 – Apr 8, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vpc: fix return value check for blk_pwrite

bdrv_pwrite_sync used to return zero or negative error, while blk_pwrite returns the number of written bytes when successful. This caused VPC image creation to fail spectacularly: it wrote the first 512 bytes, and then exited immediately because of the non-zero answer from blk_pwrite. But the truly spectacular part is that it returns a positive value (the 512 that blk_pwrite returned) causing everyone to believe that it succeeded.

This fixes qemu-iotests with vpc format.

Fixes b8f45cdf7827e39f9a1e6cc446f5972cc6144237
---
 block/vpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/vpc.c +1 -1
index 8830b5b..3713ec3 100644
@@ -775,7 +775,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
     num_bat_entries = (total_sectors + block_size / 512) / (block_size / 512);
 
     ret = blk_pwrite(blk, offset, buf, HEADER_SIZE);
-    if (ret) {
+    if (ret < 0) {
         goto fail;
     }
 
Signature · 1 line
1.8.3.1
Applied
#1 lore raw

Am 07.04.2016 um 16:52 hat Paolo Bonzini geschrieben:

Quoted 11 lines

bdrv_pwrite_sync used to return zero or negative error, while blk_pwrite returns the number of written bytes when successful. This caused VPC image creation to fail spectacularly: it wrote the first 512 bytes, and then exited immediately because of the non-zero answer from blk_pwrite. But the truly spectacular part is that it returns a positive value (the 512 that blk_pwrite returned) causing everyone to believe that it succeeded.

This fixes qemu-iotests with vpc format.

Fixes b8f45cdf7827e39f9a1e6cc446f5972cc6144237

Thanks, applied to the block branch.

Kevin