qcow2: add update refcount table realization for update_refcount
PATCH v2 1/1 qcow2: add update refcount table realization for update_refcount
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
---
The v2 do following change to modify some potential issue.
+------- Here should start from "0".
|
for (k = 0; k < refcount_block_entries; k++) {
if (refcount_block[k] != cpu_to_be16(0)) {
... | |
} | |
} | +---- Using "0" is more safe.
|
+-------- This should be "k" not "++k".
---
block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)block/qcow2-refcount.c +31 -0
@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) { + goto fail; + } + + s->refcount_table[refcount_table_index] = data64; + + } + } } ret =0 ;
Signature · 1 line
1.9.3
Quoted 48 lines · Jun Li
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
The v2 do following change to modify some potential issue.
+------- Here should start from "0". | for (k = 0; k < refcount_block_entries; k++) { if (refcount_block[k] != cpu_to_be16(0)) { ... | | } | | } | +---- Using "0" is more safe. | +-------- This should be "k" not "++k". --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)block/qcow2-refcount.c +19
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret = bdrv_pwrite_sync(bs->file,
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 617
Quoted 10 lines
block/qcow2-refcount.c +9
-0+ s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64, sizeof(data64)); +if (ret <0 ) { + goto fail; + } + + s->refcount_table[refcount_table_index] = data64;
Shouldn't the in memory version be be in cpu order ? like
s->refcount_table[refcount_table_index] = 0;
Best regards
Benoît
Quoted 10 lines
block/qcow2-refcount.c +3
-0+ + } + } }ret = 0;Signature · 1 line
1.9.3
Quoted 58 lines · Benoît Canet
Quoted 56 lines · Jun Li
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
The v2 do following change to modify some potential issue.
+------- Here should start from "0". | for (k = 0; k < refcount_block_entries; k++) { if (refcount_block[k] != cpu_to_be16(0)) { ... | | } | | } | +---- Using "0" is more safe. | +-------- This should be "k" not "++k". --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)block/qcow2-refcount.c +27
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) { + goto fail; + } +
Quoted 4 lines
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 616
Quoted 1 line
block/qcow2-refcount.c +1
-0+ s->refcount_table[refcount_table_index] = data64;Shouldn't the in memory version be be in cpu order ? like
s->refcount_table[refcount_table_index] = 0;
I don't think so. See following:
(gdb) p sizeof(s->refcount_table[0])
$5 = 8
(gdb) p sizeof(s->refcount_table[1])
$6 = 8
(gdb) p sizeof(0)
$7 = 4
So I think here is right. Thank you for sharing Max's patch(qcow2: Drop REFCOUNT_SHIFT) with me. I find this patch has been reviewed, but it has not been merged. Maybe I will modify my realization after this patch merged.
Thanks again.
Jun Li
Quoted 14 lines
Best regards
Benoît
Quoted 10 lines
block/qcow2-refcount.c +3
-0+ + } + } } ret =0 ;Signature · 1 line
1.9.3
Quoted 64 lines · Jun Li
Quoted 58 lines · Benoît Canet
Quoted 56 lines · Jun Li
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
The v2 do following change to modify some potential issue.
+------- Here should start from "0". | for (k = 0; k < refcount_block_entries; k++) { if (refcount_block[k] != cpu_to_be16(0)) { ... | | } | | } | +---- Using "0" is more safe. | +-------- This should be "k" not "++k". --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)block/qcow2-refcount.c +27
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) { + goto fail; + } +Quoted 4 lines
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 616
Quoted 1 line
block/qcow2-refcount.c +1
-0+ s->refcount_table[refcount_table_index] = data64;Shouldn't the in memory version be be in cpu order ? like
s->refcount_table[refcount_table_index] = 0;
Quoted 8 lines
I don't think so. See following:
(gdb) p
sizeof(s->refcount_table[0])
$5 = 8
(gdb) psizeof(s->refcount_table[1])
$6 = 8
(gdb) p sizeof(0)
$7 = 4
There is two different thing here: endianness and type.
For the endianess you can look at qcow2_refcount_init. The endianness of this in memory table is the one of the CPU. Here data64 is big endian and this is wrong.
For the type integer promotion will take care of it. See http://www.tutorialspoint.com/cprogramming/c_type_casting.htm
assigning zero means that the compiler will silently perform a cast to int64_t.
Best regards
Benoît
Quoted 25 lines
So I think here is right. Thank you for sharing Max's
patch(qcow2: Drop REFCOUNT_SHIFT)with me. I find this patch has been reviewed, but it has not been merged. Maybe I will modify my realization after this patch merged.Thanks again.
Jun Li
Quoted 14 lines
Best regards
Benoît
Quoted 10 lines
block/qcow2-refcount.c +3
-0+ + } + } } ret =0 ;Signature · 1 line
1.9.3
Quoted 26 lines · On Mon, 1 Sep 2014 18:52:48 +0800 Jun Li <[email protected]> wrote:
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
The v2 do following change to modify some potential issue.
+------- Here should start from "0". | for (k = 0; k < refcount_block_entries; k++) { if (refcount_block[k] != cpu_to_be16(0)) { ... | | } | | } | +---- Using "0" is more safe. | +-------- This should be "k" not "++k". --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)block/qcow2-refcount.c +0
-0
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 592
Quoted 7 lines
block/qcow2-refcount.c +4
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index;
Hi,
k = 0 is also done in the for block below...
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 593
Quoted 1 line
block/qcow2-refcount.c +1
-0+int refcount_block_entries = s->cluster_size /sizeof (uint16_t );
It's better for maintainance to count elements in an array this way:
int refcount_block_entries = s->cluster_size / sizeof(refcount_block[0]);
Quoted 19 lines
block/qcow2-refcount.c +19
-0+for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) {
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 622
Quoted 10 lines
block/qcow2-refcount.c +7
-0+ goto fail; + } + + s->refcount_table[refcount_table_index] = data64; + + } + } } ret =0 ;
Cheers.
Signature · 7 lines
Gregory Kurz [email protected] [email protected] Software Engineer @ IBM/Meiosys http://www.ibm.com Tel +33 (0)562 165 496 "Anarchy is about taking complete responsibility for yourself." Alan Moore.
Thanks. I will give a new version in v3 of qcow2 shrink.
Jun Li
Quoted 95 lines · 2014-9-3 上午1:12于 "Greg Kurz" <[email protected]>写道:
Quoted 1 line · On Mon, 1 Sep 2014 18:52:48 +0800 Jun Li <[email protected]> wrote:
When every item of refcount block is NULL, free refcount block and reset
the
Quoted 7 lines
corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
The v2 do following change to modify some potential issue.
Quoted 7 lines
+------- Here should start from "0". | for (k = 0; k < refcount_block_entries; k++) { if (refcount_block[k] != cpu_to_be16(0)) { ... | | } | | } | +---- Using "0" is moresafe.
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT
Quoted 11 lines
| +-------- This should be "k" not "++k". --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)block/qcow2-refcount.c +0
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULTupdate_refcount(BlockDriverState *bs,
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT · line 587
Quoted 2 lines
block/qcow2-refcount.c +0
-0if (refcount ==0 && s->discard_passthrough[type]) { update_refcount_discard(bs, cluster_offset,
s->cluster_size);block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 592
Quoted 5 lines
block/qcow2-refcount.c +4
-0} + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) { +int k = block_index;Hi,
k = 0 is also done in the for block below...
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT · line 593
Quoted 1 line
block/qcow2-refcount.c +1
-0+ int refcount_block_entries = s->cluster_size /
sizeof(uint16_t);It's better for maintainance to count elements in an array this way:
int
refcount_block_entries=s->cluster_size/sizeof(refcount_block[0]);block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
Quoted 12 lines
block/qcow2-refcount.c +12
-0+for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block); +/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >>(
s->cluster_bits-Quoted 7 lines
block/qcow2-refcount.c +7
-0+ REFCOUNT_SHIFT); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) {block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 622
Quoted 10 lines
block/qcow2-refcount.c +7
-0+ goto fail; + } + + s->refcount_table[refcount_table_index] = data64; + + } + } } ret =0 ;Cheers.
--
Gregory Kurz [email protected]
[email protected]
Software Engineer @ IBM/Meiosys http://www.ibm.com
Tel +33 (0)562 165 496"Anarchy is about taking complete responsibility for yourself."
Alan Moore.
Am 01.09.2014 um 12:52 hat Jun Li geschrieben:
Quoted 4 lines
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>
The commit message should also describe why this is a relevant improvement for some use case. My gut feeling is that it complicates the code for a very minimal gain.
Kevin
Quoted 9 lines · Kevin Wolf
Am 01.09.2014 um 12:52 hat Jun Li geschrieben:
Quoted 4 lines
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>The commit message should also describe why this is a relevant improvement for some use case. My gut feeling is that it complicates the code for a very minimal gain.
Hi Kevin,
"Add update refcount table realization for update_refcount" is nesseary for qcow2 shrinking. I will submit v3 of "qcow2: Patch for shrinking qcow2 disk image". When check the code of update_refcount, I find it lacks of this patch.
Best Regards,
Jun Li
Am 09.09.2014 um 04:52 hat Jun Li geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 9 lines
Am 01.09.2014 um 12:52 hat Jun Li geschrieben:
Quoted 4 lines
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>The commit message should also describe why this is a relevant improvement for some use case. My gut feeling is that it complicates the code for a very minimal gain.
Quoted 5 lines
Hi Kevin,
"Add update refcount table realization for
update_refcount" is nesseary for qcow2 shrinking. I will submit v3 of "qcow2: Patch for shrinking qcow2 disk image". When check the code ofupdate_refcount, I find it lacks of this patch.
Why is it necessary? Can't you just leave the refcount blocks allocated? They shouldn't take a lot of space.
Kevin
Quoted 12 lines · Kevin Wolf
Am 09.09.2014 um 04:52 hat Jun Li geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 9 lines
Am 01.09.2014 um 12:52 hat Jun Li geschrieben:
Quoted 4 lines
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>The commit message should also describe why this is a relevant improvement for some use case. My gut feeling is that it complicates the code for a very minimal gain.
Quoted 9 lines
Quoted 5 lines
Hi Kevin,
"Add update refcount table realization for
update_refcount" is nesseary for qcow2 shrinking. I will submit v3 of "qcow2: Patch for shrinking qcow2 disk image". When check the code ofupdate_refcount, I find it lacks of this patch.Why is it necessary? Can't you just leave the refcount blocks allocated? They shouldn't take a lot of space.
For example:cluster_size: 64k
We want to shrink a disk from 2T to 1T.
one refcount block which in one cluster size can show 64k / 2B = 32k clusters. As 32k * 64k = 2G, so one refcount block will show 2G space. And (2T - 1T) / 2G = 512. So 512 refcount block will take 512 * 64k = 32M space.
So when we shrink a disk from 2T to 1T, host cluster will leak at least 32M space(refcount block leak) without this patch.
Above is just an example. For usual test case, we can not hit this host cluster leak, but when we do qcow2 shrinking, this will lead host cluster leak.
Best Regards,
Jun Li
On Mon, Sep 01, 2014 at 06:52:48PM +0800, Jun Li wrote:
How does this patch handle self-describing refcount blocks? I think they will keep the refcount block alive forever because your code will not decide to free them.
This patch should also discard the refcount block if we decide to free it (in the same way that we discard at cluster_offset).
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 591
Quoted 11 lines
block/qcow2-refcount.c +3
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) {
What is the purpose of block_index == 0?
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 601
Quoted 10 lines
block/qcow2-refcount.c +10
-0+int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block);
You can't do this, the buffer belongs to the refcount block cache. Please look at the cache get/put as well as qcow2_cache_create/destroy.
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 614
Quoted 13 lines
block/qcow2-refcount.c +13
-0+/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 ); + refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) { + goto fail; + }
Plase use write_reftable_entry().
Quoted 6 lines · Stefan Hajnoczi
On Mon, Sep 01, 2014 at 06:52:48PM +0800, Jun Li wrote:
How does this patch handle self-describing refcount blocks? I think they will keep the refcount block alive forever because your code will not decide to free them.
Sorry, I have ignored self-describing refcount blocks. :)
Quoted 16 lines
This patch should also discard the refcount block if we decide to free it (in the same way that we discard at
cluster_offset).block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 591
Quoted 11 lines
block/qcow2-refcount.c +3
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) {What is the purpose of
block_index== 0?
Here is want to reduce the probability of running the following code. Only when block_index == 0, we will run the following code to free refcount block.
Quoted 12 lines
block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 601
Quoted 11 lines
block/qcow2-refcount.c +10
-0+int k = block_index; +int refcount_block_entries = s->cluster_size /sizeof (uint16_t ); +for (k =0 ; k < refcount_block_entries; k++) { +if (refcount_block[k] !=cpu_to_be16 (0 )) { +break ; + } + } + +if (k == refcount_block_entries) { +qemu_vfree (refcount_block);
Quoted 2 lines
You can't do this, the buffer belongs to the refcount block cache. Please look at the cache get/put as well as qcow2_cache_create/destroy.
ok, thx. Should addqcow2_cache_put(bs, s->refcount_block_cache, (void**) refcount_block);
Quoted 15 lines
Quoted 4 lines
block/qcow2-refcount.c +3
-0+/* update refcount table */ +unsigned int refcount_table_index; +uint64_t data64 =cpu_to_be64 (0 );block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 614
Quoted 10 lines
block/qcow2-refcount.c +10
-0+ refcount_table_index = cluster_index >> (s->cluster_bits - +REFCOUNT_SHIFT ); + ret =bdrv_pwrite_sync (bs->file, + s->refcount_table_offset + + refcount_table_index * +sizeof (uint64_t ), + &data64,sizeof (data64)); +if (ret <0 ) { + goto fail; + }
Quoted 1 line
Plase use
write_reftable_entry().
ok, got it. I will submit a new version when I submit v3 of qcow2 shrinking.
Best Regards,
Jun Li
Quoted 9 lines · Jun Li
Quoted 6 lines · Stefan Hajnoczi
On Mon, Sep 01, 2014 at 06:52:48PM +0800, Jun Li wrote:
How does this patch handle self-describing refcount blocks? I think they will keep the refcount block alive forever because your code will not decide to free them.
Sorry, I have ignored self-describing refcount blocks. :)
For this...
Quoted 17 lines
Quoted 16 lines
This patch should also discard the refcount block if we decide to free it (in the same way that we discard at
cluster_offset).block/qcow2-refcount.c static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, · line 591
Quoted 11 lines
block/qcow2-refcount.c +3
-0@@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,if (refcount ==0 && s->discard_passthrough[type]) {update_refcount_discard (bs, cluster_offset, s->cluster_size); } + +/* When refcount block is NULL, update refcount table */ +if (block_index ==0 ) {What is the purpose of
block_index== 0?
Quoted 2 lines
Here is want to reduce the probability of running the following code. Only when
block_index== 0, we will run the following code to free refcount block.
...and this reason, I consider this approach incomplete.
The approach is unreliable because a change to refcount update ordering could change leak behavior.
Either free refcount blocks to avoid leaks in all cases, or don't bother.
Stefan
Quoted 5 lines · Jun Li
When every item of refcount block is NULL, free refcount block and reset the corresponding item of refcount table with NULL.
Signed-off-by Jun Li <address@hidden>---
By the way, test cases are definitely needed for this change. See tests/qemu-iotests/qcow2.py and the test cases in tests/qemu-iotests.
Stefan