qcow2: free allocated cluster on fail in qcow2_write_snapshots()
PATCH 1/2 qcow2: free allocated cluster on fail in qcow2_write_snapshots()
--- block/qcow2-snapshot.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
block/qcow2-snapshot.c +2 -0
@@ -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; }
Signature · 1 line
1.7.1
PATCH 2/2 qcow2: cancel the modification on fail in qcow2_snapshot_create()
--- block/qcow2-snapshot.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
block/qcow2-snapshot.c +11 -0
@@ -410,6 +410,17 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)#endif return 0 ; +restore_refcount: + ret =qcow2_update_snapshot_refcount (bs, s->l1_table_offset, + s->l1_size,-1 ); +if (ret <0 ) { +/* Nothing can be done none now, need image check later */ +error_report ("qcow2: Error in restoring refcount in snapshot" ); + } + +dealloc_cluster: +qcow2_free_clusters (bs, sn->l1_table_offset, sn->l1_size); + fail:g_free (sn->id_str);g_free (sn->name);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 2/2] qcow2: cancel the modification on fail in qcow2_snapshot_create()
Quoted 17 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- block/qcow2-snapshot.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)block/qcow2-snapshot.c +4
-0@@ -410,6 +410,17 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)#endif return 0 ; +restore_refcount: + ret =qcow2_update_snapshot_refcount (bs, s->l1_table_offset, + s->l1_size,-1 ); +if (ret <0 ) {
block/qcow2-snapshot.c int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) · line 426
Quoted 10 lines
block/qcow2-snapshot.c +7
-0+/* Nothing can be done none now, need image check later */ +error_report ("qcow2: Error in restoring refcount in snapshot" ); + } + +dealloc_cluster: +qcow2_free_clusters (bs, sn->l1_table_offset, sn->l1_size); + fail:g_free (sn->id_str);g_free (sn->name);
This patch is missing goto restore_refcount and goto dealloc_cluster.
Quoted 10 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- block/qcow2-snapshot.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)block/qcow2-snapshot.c +0
-0
block/qcow2-snapshot.c static int qcow2_write_snapshots(BlockDriverState *bs) · line 274
Quoted 7 lines
block/qcow2-snapshot.c +2
-0@@ -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.
Quoted 29 lines · Stefan Hajnoczi
Quoted 10 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- block/qcow2-snapshot.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)block/qcow2-snapshot.c +0
-0block/qcow2-snapshot.c static int qcow2_write_snapshots(BlockDriverState *bs) · line 274
Quoted 7 lines
block/qcow2-snapshot.c +2
-0@@ -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; }
Quoted 3 lines
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.
Signature · 3 lines
Best Regards Wenchao Xia