Skip to contentSkip to conversation

vpc: Add missing error handling in alloc_block

PATCH In review Kevin Wolf 3 participants 4 messages Nov 23, 2011 – Nov 25, 2011 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 vpc: Add missing error handling in alloc_block

---
 block/vpc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/vpc.c +4 -1
index 75d7d4a..89a5ee2 100644
@@ -362,8 +362,11 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)
 
     // Initialize the block's bitmap
     memset(bitmap, 0xff, s->bitmap_size);
-    bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
+    ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
         s->bitmap_size);
+    if (ret < 0) {
+        return ret;
+    }
 
     // Write new footer (the old one will be overwritten)
     s->free_data_block_offset += s->block_size + s->bitmap_size;
Signature · 1 line
1.7.6.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Kevin Wolf

---
 block/vpc.c |    5 ++++-

 1 files changed, 4 insertions(+), 1 deletions(-)
block/vpc.c +0 -0
index 75d7d4a..89a5ee2 100644

block/vpc.c static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num) · line 369

Quoted 9 lines
block/vpc.c +4 -1
@@ -362,8 +362,11 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)
 
     // Initialize the block's bitmap
     memset(bitmap, 0xff, s->bitmap_size);
-    bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
+    ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
         s->bitmap_size);
+    if (ret < 0) {
+        return ret;
+    }

I notice that s->pagetable[index] is left modified when the function fails. But this is a larger issue and could be addressed in a later patch which also looks at the other failure cases in this function.

Stefan

author
#2 lore raw

Am 23.11.2011 12:01, schrieb Stefan Hajnoczi:

Quoted 12 lines · Kevin Wolf
Quoted 11 lines
---
 block/vpc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/vpc.c +0 -0
index 75d7d4a..89a5ee2 100644
@@ -362,8 +362,11 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)
 
Quoted 12 lines

block/vpc.c static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num) · line 369

Quoted 8 lines
block/vpc.c +4 -1
    // Initialize the block's bitmap
    memset(bitmap, 0xff, s->bitmap_size);
-    bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
+    ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
        s->bitmap_size);
+    if (ret < 0) {
+        return ret;
+    }

I notice that s->pagetable[index] is left modified when the function fails. But this is a larger issue and could be addressed in a later patch which also looks at the other failure cases in this function.

Error handling in vpc needs some work anyway. For example, almost all places return -1 instead of the real error number. Probably even the order of operations is unsafe, didn't check that yet.

Kevin

#3 lore raw

Am 23.11.2011 12:23, schrieb Kevin Wolf:

Quoted 26 lines

Am 23.11.2011 12:01, schrieb Stefan Hajnoczi:

Quoted 12 lines · Kevin Wolf
Quoted 11 lines
---
 block/vpc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/vpc.c +0 -0
index 75d7d4a..89a5ee2 100644
@@ -362,8 +362,11 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num)
 
Quoted 12 lines

block/vpc.c static int64_t alloc_block(BlockDriverState* bs, int64_t sector_num) · line 369

Quoted 8 lines
block/vpc.c +4 -1
    // Initialize the block's bitmap
    memset(bitmap, 0xff, s->bitmap_size);
-    bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
+    ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
        s->bitmap_size);
+    if (ret < 0) {
+        return ret;
+    }

I notice that s->pagetable[index] is left modified when the function fails. But this is a larger issue and could be addressed in a later patch which also looks at the other failure cases in this function.

Quoted 3 lines

Error handling in vpc needs some work anyway. For example, almost all places return -1 instead of the real error number. Probably even the order of operations is unsafe, didn't check that yet.

As a note, as part of QEMU Test Day(s) I tested VHD images (cf. Wiki) - booting, installing software, etc. and haven't encountered any problem. Doesn't mean it's entirely safe though, obviously.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg