diff mbox

[1/2] qcow2: free allocated cluster on fail in qcow2_write_snapshots()

Message ID 1368607419-15178-1-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia May 15, 2013, 8:43 a.m. UTC
Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 block/qcow2-snapshot.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Stefan Hajnoczi May 16, 2013, 9:32 a.m. UTC | #1
On Wed, May 15, 2013 at 04:43:38PM +0800, Wenchao Xia wrote:
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  block/qcow2-snapshot.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
> index 992a5c8..a6065a9 100644
> --- a/block/qcow2-snapshot.c
> +++ b/block/qcow2-snapshot.c
> @@ -268,6 +268,8 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
>      return 0;
>  
>  fail:
> +    /* free the new snapshot table */
> +    qcow2_free_clusters(bs, snapshots_offset, snapshots_size);
>      return ret;
>  }

snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
offset = snapshots_offset;
if (offset < 0) {
    return offset;
}
ret = bdrv_flush(bs);
if (ret < 0) {
    return ret;
}

For completeness the bdrv_flush() return ret should be change to a goto
fail so that we cover all failure cases.
Wayne Xia May 17, 2013, 4:58 a.m. UTC | #2
于 2013-5-16 17:32, Stefan Hajnoczi 写道:
> On Wed, May 15, 2013 at 04:43:38PM +0800, Wenchao Xia wrote:
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> ---
>>   block/qcow2-snapshot.c |    2 ++
>>   1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
>> index 992a5c8..a6065a9 100644
>> --- a/block/qcow2-snapshot.c
>> +++ b/block/qcow2-snapshot.c
>> @@ -268,6 +268,8 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
>>       return 0;
>>
>>   fail:
>> +    /* free the new snapshot table */
>> +    qcow2_free_clusters(bs, snapshots_offset, snapshots_size);
>>       return ret;
>>   }
>
> snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
> offset = snapshots_offset;
> if (offset < 0) {
>      return offset;
> }
> ret = bdrv_flush(bs);
> if (ret < 0) {
>      return ret;
> }
>
> For completeness the bdrv_flush() return ret should be change to a goto
> fail so that we cover all failure cases.
>
   Ok, will add those.
diff mbox

Patch

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 992a5c8..a6065a9 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -268,6 +268,8 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
     return 0;
 
 fail:
+    /* free the new snapshot table */
+    qcow2_free_clusters(bs, snapshots_offset, snapshots_size);
     return ret;
 }