compressed block-stream
cover compressed block-stream
It might be useful to compress images during block-stream; this way the user can merge compressed images of a backing chain and the result will remain compressed.
Anton Nefedov (4):
qcow2: reject unaligned offsets in write compressed
block: support compressed write for copy-on-read
block-stream: add compress option
iotest 030: add compressed block-stream test
Pavel Butsykin (1):
qcow2: multiple clusters write compressed
qapi/block-core.json | 4 +++ include/block/block_int.h | 4 ++- block/io.c | 30 +++++++++++++++---- block/qcow2.c | 73 +++++++++++++++++++++++++++++++++++----------- block/stream.c | 16 +++++++--- blockdev.c | 13 ++++++++- hmp.c | 2 ++ block/trace-events | 2 +- hmp-commands.hx | 4 +-- tests/qemu-iotests/030 | 69 ++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 +-- 11 files changed, 186 insertions(+), 35 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 qcow2: reject unaligned offsets in write compressed
Misaligned compressed write is not supported.
--- block/qcow2.c | 4 ++++ 1 file changed, 4 insertions(+)
block/qcow2.c +4 -0
@@ -3349,6 +3349,10 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); } +if (offset_into_cluster (s, offset)) { +return -EINVAL ; + } + buf =qemu_blockalign (bs, s->cluster_size);if (bytes != s->cluster_size) { if (bytes > s->cluster_size ||
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/5 for-2.11?] qcow2: reject unaligned offsets in write compressed
Quoted 6 lines · Anton Nefedov
Misaligned compressed write is not supported.
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 4 ++++ 1 file changed, 4 insertions(+)
Should this one be applied in 2.11?
Quoted 17 lines
block/qcow2.c +4
-0@@ -3349,6 +3349,10 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); } +if (offset_into_cluster (s, offset)) { +return -EINVAL ; + } + buf =qemu_blockalign (bs, s->cluster_size);if (bytes != s->cluster_size) { if (bytes > s->cluster_size ||
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 1/5 for-2.11?] qcow2: reject unaligned offsets in write compressed
Quoted 10 lines · Eric Blake
Quoted 6 lines · Anton Nefedov
Misaligned compressed write is not supported.
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 4 ++++ 1 file changed, 4 insertions(+)Should this one be applied in 2.11?
For the record, this one is pretty hard to trigger; backup and qemu-img convert currently use compressed write, both make sure they operate in clusters.
qemu-io is almighty though
qemu-io> write -c -P 7 512 64k
wrote 65536/65536 bytes at offset 512
64 KiB, 1 ops; 0.0187 sec (3.329 MiB/sec and 53.2566 ops/sec) qemu-io> read -P 7 512 64k
Pattern verification failed at offset 512, 65536 bytes read 65536/65536 bytes at offset 512
64 KiB, 1 ops; 0.0002 sec (248.016 MiB/sec and 3968.2540 ops/sec) qemu-io> read -P 7 0 64k
read 65536/65536 bytes at offset 0
64 KiB, 1 ops; 0.0000 sec (1.606 GiB/sec and 26315.7895 ops/sec)
/Anton
Re: [Qemu-devel] [PATCH 1/5 for-2.11?] qcow2: reject unaligned offsets in write compressed
Quoted 9 lines · Anton Nefedov
Quoted 8 lines · Eric Blake
Quoted 6 lines · Anton Nefedov
Misaligned compressed write is not supported.
Signed-off-by Anton Nefedov <[email protected]>---
block/qcow2.c| 4 ++++1 file changed, 4 insertions(+)
Quoted 8 lines
Quoted 2 lines
Should this one be applied in 2.11?
For the record, this one is pretty hard to trigger; backup and qemu-img convert currently use compressed write, both make sure they operate in clusters.
qemu-io is almighty though
Okay, then we definitely have a bug, and this patch is definitely 2.11 material, especially if you update the commit message to show the trigger case:
Quoted 14 lines
qemu-io> write -c -P 7 512 64k
wrote 65536/65536 bytes at offset 512
64 KiB, 1 ops; 0.0187 sec (3.329 MiB/sec and 53.2566 ops/sec) qemu-io> read -P 7 512 64k
Pattern verification failed at offset 512, 65536 bytes read 65536/65536 bytes at offset 512
64 KiB, 1 ops; 0.0002 sec (248.016 MiB/sec and 3968.2540 ops/sec) qemu-io> read -P 7 0 64k
read 65536/65536 bytes at offset 0
64 KiB, 1 ops; 0.0000 sec (1.606 GiB/sec and 26315.7895 ops/sec)/Anton
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Max Reitz
AppliedRe: [Qemu-devel] [PATCH 1/5] qcow2: reject unaligned offsets in write compressed
In reply to Anton NefedovQuoted 6 lines · Anton Nefedov
Misaligned compressed write is not supported.
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 4 ++++ 1 file changed, 4 insertions(+)
Thanks, applied to my block branch for 2.11:
https://github.com/XanClic/qemu/commits/block
Max
PATCH 2/5 qcow2: multiple clusters write compressed
In reply to Anton NefedovFrom: Pavel Butsykin <[email protected]>
At the moment, qcow2_co_pwritev_compressed can process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.
--- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-)
block/qcow2.c +56 -21
@@ -3325,11 +3325,9 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,return 0 ; } -/* XXX: put compressed sectors first, then all the cluster aligned -tables to avoid losing bytes in alignment */ static coroutine_fn int -qcow2_co_pwritev_compressed (BlockDriverState *bs,uint64_t offset, -uint64_t bytes,QEMUIOVector *qiov) +qcow2_co_pwritev_cluster_compressed (BlockDriverState *bs,uint64_t offset, +uint64_t bytes,QEMUIOVector *qiov) {BDRVQcow2State *s = bs->opaque;QEMUIOVector hd_qiov;
@@ -3339,25 +3337,12 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,uint8_t *buf, *out_buf;int64_t cluster_offset; -if (bytes ==0 ) { -/* align end of file to a sector boundary to ease reading with -sector based I/Os */ - cluster_offset =bdrv_getlength (bs->file->bs); -if (cluster_offset <0 ) { -return cluster_offset; - } -return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); - } - -if (offset_into_cluster (s, offset)) { -return -EINVAL ; - } +assert (bytes <= s->cluster_size); +assert (!offset_into_cluster (s, offset)); buf =qemu_blockalign (bs, s->cluster_size); -if (bytes != s->cluster_size) { -if (bytes > s->cluster_size || - offset + bytes != bs->total_sectors <<BDRV_SECTOR_BITS ) - { +if (bytes < s->cluster_size) { +if (offset + bytes != bs->total_sectors <<BDRV_SECTOR_BITS ) {qemu_vfree (buf);return -EINVAL ; }
@@ -3437,6 +3422,56 @@ fail:return ret; } +/* XXX: put compressed sectors first, then all the cluster aligned +tables to avoid losing bytes in alignment */ +static coroutine_fn int +qcow2_co_pwritev_compressed (BlockDriverState *bs,uint64_t offset, +uint64_t bytes,QEMUIOVector *qiov) +{ +BDRVQcow2State *s = bs->opaque; +QEMUIOVector hd_qiov; +uint64_t curr_off =0 ; +int ret; + +if (bytes ==0 ) { +/* align end of file to a sector boundary to ease reading with +sector based I/Os */ +int64_t cluster_offset =bdrv_getlength (bs->file->bs); +if (cluster_offset <0 ) { +return cluster_offset; + } +return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); + } + +if (offset_into_cluster (s, offset)) { +return -EINVAL ; + } + +qemu_iovec_init (&hd_qiov, qiov->niov); +do { +uint32_t chunk_size; + +qemu_iovec_reset (&hd_qiov); + chunk_size =MIN (bytes, s->cluster_size); +qemu_iovec_concat (&hd_qiov, qiov, curr_off, chunk_size); + + ret =qcow2_co_pwritev_cluster_compressed (bs, offset + curr_off, + chunk_size, &hd_qiov); +if (ret == -ENOTSUP ) { + ret =qcow2_co_pwritev (bs, offset + curr_off, chunk_size, + &hd_qiov,0 ); + } +if (ret <0 ) { +break ; + } + curr_off += chunk_size; + bytes -= chunk_size; + }while (bytes); +qemu_iovec_destroy (&hd_qiov); + +return ret; +} +static int make_completely_empty (BlockDriverState *bs) {BDRVQcow2State *s = bs->opaque;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Quoted 9 lines · Anton Nefedov
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.
Quoted 4 lines
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-)
On one hand, it might be better to do this centrally somewhere in block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this in block/io.c.
So long story short, it's OK to do this locally in qcow2, yes.
Quoted 78 lines
block/qcow2.c +32
-21@@ -3325,11 +3325,9 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,return 0 ; } -/* XXX: put compressed sectors first, then all the cluster aligned -tables to avoid losing bytes in alignment */ static coroutine_fn int -qcow2_co_pwritev_compressed (BlockDriverState *bs,uint64_t offset, -uint64_t bytes,QEMUIOVector *qiov) +qcow2_co_pwritev_cluster_compressed (BlockDriverState *bs,uint64_t offset, +uint64_t bytes,QEMUIOVector *qiov) {BDRVQcow2State *s = bs->opaque;QEMUIOVector hd_qiov;@@ -3339,25 +3337,12 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,uint8_t *buf, *out_buf;int64_t cluster_offset; -if (bytes ==0 ) { -/* align end of file to a sector boundary to ease reading with -sector based I/Os */ - cluster_offset =bdrv_getlength (bs->file->bs); -if (cluster_offset <0 ) { -return cluster_offset; - } -return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); - } - -if (offset_into_cluster (s, offset)) { -return -EINVAL ; - } +assert (bytes <= s->cluster_size); +assert (!offset_into_cluster (s, offset)); buf =qemu_blockalign (bs, s->cluster_size); -if (bytes != s->cluster_size) { -if (bytes > s->cluster_size || - offset + bytes != bs->total_sectors <<BDRV_SECTOR_BITS ) - { +if (bytes < s->cluster_size) { +if (offset + bytes != bs->total_sectors <<BDRV_SECTOR_BITS ) {qemu_vfree (buf);return -EINVAL ; }@@ -3437,6 +3422,56 @@ fail:return ret; } +/* XXX: put compressed sectors first, then all the cluster aligned +tables to avoid losing bytes in alignment */ +static coroutine_fn int +qcow2_co_pwritev_compressed (BlockDriverState *bs,uint64_t offset, +uint64_t bytes,QEMUIOVector *qiov) +{ +BDRVQcow2State *s = bs->opaque; +QEMUIOVector hd_qiov; +uint64_t curr_off =0 ; +int ret; + +if (bytes ==0 ) { +/* align end of file to a sector boundary to ease reading with +sector based I/Os */ +int64_t cluster_offset =bdrv_getlength (bs->file->bs); +if (cluster_offset <0 ) { +return cluster_offset; + } +return bdrv_truncate (bs->file, cluster_offset,PREALLOC_MODE_OFF ,NULL ); + } + +if (offset_into_cluster (s, offset)) { +return -EINVAL ; + } + +qemu_iovec_init (&hd_qiov, qiov->niov);
block/qcow2.c fail: · line 3460
Quoted 10 lines
block/qcow2.c +10
-0+ do { + uint32_t chunk_size; + + qemu_iovec_reset(&hd_qiov); + chunk_size = MIN(bytes, s->cluster_size); + qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); + + ret = qcow2_co_pwritev_cluster_compressed(bs, offset + curr_off, + chunk_size, &hd_qiov); + if (ret == -ENOTSUP) {
Why this? I mean, I can see the appeal, but then we should probably actually return -ENOTSUP somewhere (e.g. for unaligned clusters and the like) -- and we should not abort if offset_into_cluster(s, cluster) is true, but we should write the header uncompressed and compress the main bulk.
Max
Quoted 18 lines
block/qcow2.c +14
-0+ ret =qcow2_co_pwritev (bs, offset + curr_off, chunk_size, + &hd_qiov,0 ); + } +if (ret <0 ) { +break ; + } + curr_off += chunk_size; + bytes -= chunk_size; + }while (bytes); +qemu_iovec_destroy (&hd_qiov); + +return ret; +} +static int make_completely_empty (BlockDriverState *bs) {BDRVQcow2State *s = bs->opaque;
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Quoted 24 lines · Max Reitz
Quoted 9 lines · Anton Nefedov
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.Quoted 4 lines
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-)On one hand, it might be better to do this centrally somewhere in
block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this inblock/io.c.So long story short, it's OK to do this locally in qcow2, yes.
[..]
Quoted 8 lines
block/qcow2.c fail: · line 3460
Quoted 7 lines
block/qcow2.c +7
-0+qemu_iovec_reset (&hd_qiov); + chunk_size =MIN (bytes, s->cluster_size); +qemu_iovec_concat (&hd_qiov, qiov, curr_off, chunk_size); + + ret =qcow2_co_pwritev_cluster_compressed (bs, offset + curr_off, + chunk_size, &hd_qiov); +if (ret == -ENOTSUP ) {
Quoted 8 lines
Why this? I mean, I can see the appeal, but then we should probably actually return
-ENOTSUPsomewhere (e.g. for unaligned clusters and the like) -- and we should not abort ifoffset_into_cluster(s, cluster)is true, but we should write the header uncompressed and compress the main bulk.Max
Right, sorry, missed this part when porting the patch.
I think this needs to be removed (and the commit message fixed accordingly).
Returning an error, rather than silently falling back to uncompressed seems preferable to me. "Compressing writers" (backup, img convert and now stream) are aware that they have to cluster-align, and if they fail to do so that means there is an error somewhere.
If it won't return an error anymore, then the unaligned tail shouldn't either. So we can end up 'letting' the callers send small unaligned requests which will never get compressed.
/Anton
Quoted 2 lines
Quoted 2 lines
block/qcow2.c +2
-0+ ret =qcow2_co_pwritev (bs, offset + curr_off, chunk_size, + &hd_qiov,0 );
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Quoted 49 lines · Anton Nefedov
Quoted 26 lines · Max Reitz
Quoted 9 lines · Anton Nefedov
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.Quoted 5 lines
Signed-off-by Anton Nefedov <[email protected]>---
block/qcow2.c| 77
+++++++++++++++++++++++++++++++++++++++++++----------------1 file changed, 56 insertions(+), 21 deletions(-)On one hand, it might be better to do this centrally somewhere in block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this in
block/io.c.So long story short, it's OK to do this locally in qcow2, yes.
[..]
Quoted 10 lines
Quoted 9 lines
+
qemu_iovec_reset(&hd_qiov);
+chunk_size=MIN(bytes, s->cluster_size);
+qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); +
+ ret = qcow2_co_pwritev_cluster_compressed(bs, offset +curr_off,
+chunk_size,&hd_qiov);
+ if (ret ==-ENOTSUP) {Quoted 8 lines
Why this? I mean, I can see the appeal, but then we should probably actually return
-ENOTSUPsomewhere (e.g. for unaligned clusters and the like) -- and we should not abort ifoffset_into_cluster(s, cluster)is true, but we should write the header uncompressed and compress the main bulk.Max
Quoted 8 lines
Right, sorry, missed this part when porting the patch.
I think this needs to be removed (and the commit message fixed accordingly).
Returning an error, rather than silently falling back to uncompressed seems preferable to me. "Compressing writers" (backup, img convert and now stream) are aware that they have to cluster-align, and if they fail to do so that means there is an error somewhere.
OK for me.
Quoted 3 lines
If it won't return an error anymore, then the unaligned tail shouldn't either. So we can end up 'letting' the callers send small unaligned requests which will never get compressed.
Either way is fine. It just looks to me like vmdk falls back to uncompressed writes, so it's not like it would be completely new behavior...
(But I won't judge whether what vmdk does is a good idea.)
Max
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Am 15.11.2017 um 17:30 hat Max Reitz geschrieben:
Quoted 61 lines · Anton Nefedov
Quoted 49 lines · Max Reitz
Quoted 26 lines · Anton Nefedov
Quoted 9 lines
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.Quoted 5 lines
Signed-off-by Anton Nefedov <[email protected]>---
block/qcow2.c| 77
+++++++++++++++++++++++++++++++++++++++++++----------------1 file changed, 56 insertions(+), 21 deletions(-)On one hand, it might be better to do this centrally somewhere in block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this in
block/io.c.So long story short, it's OK to do this locally in qcow2, yes.
[..]
Quoted 10 lines
Quoted 9 lines
+
qemu_iovec_reset(&hd_qiov);
+chunk_size=MIN(bytes, s->cluster_size);
+qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); +
+ ret = qcow2_co_pwritev_cluster_compressed(bs, offset +curr_off,
+chunk_size,&hd_qiov);
+ if (ret ==-ENOTSUP) {Quoted 8 lines
Why this? I mean, I can see the appeal, but then we should probably actually return
-ENOTSUPsomewhere (e.g. for unaligned clusters and the like) -- and we should not abort ifoffset_into_cluster(s, cluster)is true, but we should write the header uncompressed and compress the main bulk.Max
Quoted 8 lines
Right, sorry, missed this part when porting the patch.
I think this needs to be removed (and the commit message fixed accordingly).
Returning an error, rather than silently falling back to uncompressed seems preferable to me. "Compressing writers" (backup, img convert and now stream) are aware that they have to cluster-align, and if they fail to do so that means there is an error somewhere.OK for me.
Quoted 8 lines
Quoted 3 lines
If it won't return an error anymore, then the unaligned tail shouldn't either. So we can end up 'letting' the callers send small unaligned requests which will never get compressed.
Either way is fine. It just looks to me like vmdk falls back to uncompressed writes, so it's not like it would be completely new behavior...
(But I won't judge whether what vmdk does is a good idea.)
Probably not.
If we let io.c know about the cluster-size alignment requirement for compressed writes, the usual RMW code path could kick in. Wouldn't this actually be a better solution than uncompressed writes or erroring out?
In fact, with this, we might even be very close to an option that turns every write into a compressed write, so you get images that stay compressed even while they are in use.
Kevin
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Quoted 77 lines · Kevin Wolf
Am 15.11.2017 um 17:30 hat Max Reitz geschrieben:
Quoted 61 lines · Anton Nefedov
Quoted 49 lines · Max Reitz
Quoted 26 lines · Anton Nefedov
Quoted 9 lines
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.Quoted 5 lines
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-)On one hand, it might be better to do this centrally somewhere in block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this in
block/io.c.So long story short, it's OK to do this locally in qcow2, yes.
[..]
Quoted 10 lines
Quoted 9 lines
+
qemu_iovec_reset(&hd_qiov);
+chunk_size=MIN(bytes, s->cluster_size);
+qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); +
+ ret = qcow2_co_pwritev_cluster_compressed(bs, offset +curr_off,
+chunk_size,&hd_qiov);
+ if (ret ==-ENOTSUP) {Quoted 8 lines
Why this? I mean, I can see the appeal, but then we should probably actually return
-ENOTSUPsomewhere (e.g. for unaligned clusters and the like) -- and we should not abort ifoffset_into_cluster(s, cluster)is true, but we should write the header uncompressed and compress the main bulk.Max
Quoted 8 lines
Right, sorry, missed this part when porting the patch.
I think this needs to be removed (and the commit message fixed accordingly).
Returning an error, rather than silently falling back to uncompressed seems preferable to me. "Compressing writers" (backup, img convert and now stream) are aware that they have to cluster-align, and if they fail to do so that means there is an error somewhere.OK for me.
Quoted 8 lines
Quoted 3 lines
If it won't return an error anymore, then the unaligned tail shouldn't either. So we can end up 'letting' the callers send small unaligned requests which will never get compressed.
Either way is fine. It just looks to me like vmdk falls back to uncompressed writes, so it's not like it would be completely new behavior...
(But I won't judge whether what vmdk does is a good idea.)
Probably not.
If we let
io.cknow about the cluster-size alignment requirement for compressed writes, the usual RMW code path could kick in. Wouldn't this actually be a better solution than uncompressed writes or erroring out?
Quoted 6 lines
In fact, with this, we might even be very close to an option that turns every write into a compressed write, so you get images that stay compressed even while they are in use.
Kevin
That's alignment, and indeed it would be nice to have that block limit and I think this patch does not contradict with that (now that in v2 it doesn't fall back to uncompressed but returns EINVAL). Unless we also want a max request limit so io.c does the request split?
/Anton
Re: [Qemu-devel] [PATCH 2/5] qcow2: multiple clusters write compressed
Am 23.11.2017 um 10:04 hat Anton Nefedov geschrieben:
Quoted 84 lines · Kevin Wolf
Quoted 81 lines
Am 15.11.2017 um 17:30 hat Max Reitz geschrieben:
Quoted 61 lines · Anton Nefedov
Quoted 49 lines · Max Reitz
Quoted 26 lines · Anton Nefedov
Quoted 9 lines
From: Pavel Butsykin <[email protected]>
At the moment,
qcow2_co_pwritev_compressedcan process the requests size less than or equal to one cluster. This patch added possibility to write compressed data in the QCOW2 more than one cluster. The implementation is simple, we just split large requests into separate clusters and write using existing functionality. For unaligned requests we use a workaround and do write data without compression.Quoted 5 lines
Signed-off-by Anton Nefedov <[email protected]>--- block/qcow2.c | 77 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 21 deletions(-)On one hand, it might be better to do this centrally somewhere in block/io.c. On the other, that would require more work because it would probably mean having to introduce another field in BlockLimits, and it wouldn't do much -- because qcow (v1) is, well, qcow v1... And vmdk seems to completely not care about this single cluster limitation. So for now we probably wouldn't even gain anything by doing this in
block/io.c.So long story short, it's OK to do this locally in qcow2, yes.
[..]
Quoted 10 lines
Quoted 9 lines
+
qemu_iovec_reset(&hd_qiov);
+chunk_size=MIN(bytes, s->cluster_size);
+qemu_iovec_concat(&hd_qiov, qiov, curr_off, chunk_size); +
+ ret = qcow2_co_pwritev_cluster_compressed(bs, offset +curr_off,
+chunk_size,&hd_qiov);
+ if (ret ==-ENOTSUP) {Quoted 8 lines
Why this? I mean, I can see the appeal, but then we should probably actually return
-ENOTSUPsomewhere (e.g. for unaligned clusters and the like) -- and we should not abort ifoffset_into_cluster(s, cluster)is true, but we should write the header uncompressed and compress the main bulk.Max
Quoted 8 lines
Right, sorry, missed this part when porting the patch.
I think this needs to be removed (and the commit message fixed accordingly).
Returning an error, rather than silently falling back to uncompressed seems preferable to me. "Compressing writers" (backup, img convert and now stream) are aware that they have to cluster-align, and if they fail to do so that means there is an error somewhere.OK for me.
Quoted 8 lines
Quoted 3 lines
If it won't return an error anymore, then the unaligned tail shouldn't either. So we can end up 'letting' the callers send small unaligned requests which will never get compressed.
Either way is fine. It just looks to me like vmdk falls back to uncompressed writes, so it's not like it would be completely new behavior...
(But I won't judge whether what vmdk does is a good idea.)
Probably not.
If we let
io.cknow about the cluster-size alignment requirement for compressed writes, the usual RMW code path could kick in. Wouldn't this actually be a better solution than uncompressed writes or erroring out?In fact, with this, we might even be very close to an option that turns every write into a compressed write, so you get images that stay compressed even while they are in use.
Quoted 5 lines
Quoted 1 line
Kevin
That's alignment, and indeed it would be nice to have that block limit and I think this patch does not contradict with that (now that in v2 it doesn't fall back to uncompressed but returns EINVAL).
Yes, I agree.
Quoted 1 line
Unless we also want a max request limit so
io.cdoes the request split?
I'm not sure about this one. We might want to change the qcow2 code later so that we can actually write multiple compressed clusters at once as an performance optimisation, and then we would give up the splitting in io.c again. So maybe it's not really worth it.
Kevin
PATCH 3/5 block: support compressed write for copy-on-read
In reply to Anton Nefedov--- block/io.c | 30 ++++++++++++++++++++++++------ block/trace-events | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-)
block/io.c +24 -6
@@ -953,7 +953,7 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset, } static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, -int64_t offset,unsigned int bytes,QEMUIOVector *qiov) +int64_t offset,unsigned int bytes,QEMUIOVector *qiov,int flags) {BlockDriverState *bs = child->bs;
@@ -988,12 +988,13 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,* allocating cluster in the image file. Note that this value may exceed * BDRV_REQUEST_MAX_BYTES (even when the original read did not), which * is one reason we loop rather than doing it all at once. +* Also this is crucial for compressed copy-on-read. */ bdrv_round_to_clusters (bs, offset, bytes, &cluster_offset, &cluster_bytes); skip_bytes = offset - cluster_offset;trace_bdrv_co_do_copy_on_readv (bs, offset, bytes, - cluster_offset, cluster_bytes); + cluster_offset, cluster_bytes, flags); bounce_buffer = qemu_try_blockalign(bs, MIN(MIN(max_transfer, cluster_bytes),
@@ -1041,8 +1042,13 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,/* This does not change the data on the disk, it is not * necessary to flush even in cache=writethrough mode. */ - ret =bdrv_driver_pwritev (bs, cluster_offset, pnum, - &local_qiov,0 ); +if (flags &BDRV_REQ_WRITE_COMPRESSED ) { + ret =bdrv_driver_pwritev_compressed (bs, cluster_offset, + pnum, &local_qiov); + }else { + ret =bdrv_driver_pwritev (bs, cluster_offset, pnum, + &local_qiov,0 ); + } }if (ret <0 ) {
@@ -1107,7 +1113,12 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,* potential fallback support, if we ever implement any read flags * to pass through to drivers. For now, there aren't any * passthrough flags. */ -assert (!(flags & ~(BDRV_REQ_NO_SERIALISING |BDRV_REQ_COPY_ON_READ ))); +assert (!(flags & ~(BDRV_REQ_NO_SERIALISING |BDRV_REQ_COPY_ON_READ | +BDRV_REQ_WRITE_COMPRESSED ))); + +/* write compressed only makes sense with copy on read */ +assert (!(flags &BDRV_REQ_WRITE_COMPRESSED ) || + (flags &BDRV_REQ_COPY_ON_READ ));/* Handle Copy on Read and associated serialisation */ if (flags &BDRV_REQ_COPY_ON_READ ) {
@@ -1132,7 +1143,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, }if (!ret || pnum != bytes) { - ret =bdrv_co_do_copy_on_readv (child, offset, bytes, qiov); + ret =bdrv_co_do_copy_on_readv (child, offset, bytes, qiov, flags); goto out; } }
@@ -1209,6 +1220,13 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child,return ret; } +/* write compressed only makes sense with copy on read */ +if ((flags &BDRV_REQ_WRITE_COMPRESSED ) && + !(flags &BDRV_REQ_COPY_ON_READ )) + { +return -EINVAL ; + } +bdrv_inc_in_flight (bs);/* Don't do copy-on-read if we read data before write operation */
block/trace-events +1 -1
@@ -12,7 +12,7 @@ blk_co_pwritev(void *blk, void *bs, int64_t offset, unsigned int bytes, int flag bdrv_co_preadv(void *bs, int64_t offset, int64_t nbytes, unsigned int flags) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwritev(void *bs, int64_t offset, int64_t nbytes, unsigned int flags) "bs %p offset %"PRId64" nbytes %"PRId64" flags 0x%x" bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int count, int flags) "bs %p offset %"PRId64" count %d flags 0x%x" -bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int64_t cluster_offset, int64_t cluster_bytes) "bs %p offset %"PRId64" bytes %u cluster_offset %"PRId64" cluster_bytes %"PRId64 +bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int64_t cluster_offset, int64_t cluster_bytes, int flags) "bs %p offset %"PRId64" bytes %u cluster_offset %"PRId64" cluster_bytes %"PRId64" flags 0x%x" # block/stream.c stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_allocated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d"
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 3/5] block: support compressed write for copy-on-read
Quoted 10 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- block/io.c | 30 ++++++++++++++++++++++++------ block/trace-events | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-)block/io.c +0
-0
[...]
block/io.c int coroutine_fn bdrv_co_preadv(BdrvChild *child, · line 1229
Quoted 11 lines
block/io.c +7
-0@@ -1209,6 +1220,13 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child,return ret; } +/* write compressed only makes sense with copy on read */ +if ((flags &BDRV_REQ_WRITE_COMPRESSED ) && + !(flags &BDRV_REQ_COPY_ON_READ )) + { +return -EINVAL ; + } +
I think the assertion in bdrv_aligned_preadv() should be enough, but either way:
Quoted 3 lines
block/io.c +0
-0bdrv_inc_in_flight (bs);/* Don't do copy-on-read if we read data before write operation */
Re: [Qemu-devel] [PATCH 3/5] block: support compressed write for copy-on-read
Quoted 29 lines · Max Reitz
Quoted 10 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- block/io.c | 30 ++++++++++++++++++++++++------ block/trace-events | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-)block/io.c +0
-0[...]
block/io.c int coroutine_fn bdrv_co_preadv(BdrvChild *child, · line 1229
Quoted 11 lines
block/io.c +7
-0@@ -1209,6 +1220,13 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child,return ret; } +/* write compressed only makes sense with copy on read */ +if ((flags &BDRV_REQ_WRITE_COMPRESSED ) && + !(flags &BDRV_REQ_COPY_ON_READ )) + { +return -EINVAL ; + } +I think the assertion in
bdrv_aligned_preadv()should be enough, but either way:
Quoted 2 lines
Reviewed-by Max Reitz <[email protected]>
Ok, and it will fail more loudly. Will remove.
Quoted 4 lines
Quoted 3 lines
block/io.c +0
-0bdrv_inc_in_flight (bs);/* Don't do copy-on-read if we read data before write operation */
PATCH 4/5 block-stream: add compress option
In reply to Anton Nefedov--- qapi/block-core.json | 4 ++++ include/block/block_int.h | 4 +++- block/stream.c | 16 ++++++++++++---- blockdev.c | 13 ++++++++++++- hmp.c | 2 ++ hmp-commands.hx | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-)
qapi/block-core.json +4 -0
@@ -2007,6 +2007,9 @@ # # @speed: the maximum speed, in bytes per second # +# @compress: true to compress data, if the target format supports it. +# (default: false). Since 2.12. +# # @on-error: the action to take on an error (default report). # 'stop' and 'enospc' can only be used if the block device # supports io-status (see BlockInfo). Since 1.3.
@@ -2026,6 +2029,7 @@ { 'command': 'block-stream', 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*base-node': 'str', '*backing-file': 'str', '*speed': 'int', + '*compress': 'bool', '*on-error': 'BlockdevOnError' } } ##
include/block/block_int.h +3 -1
@@ -863,6 +863,7 @@ int is_windows_drive(const char *filename);* @backing_file_str: The file name that will be written to @bs as the * the new backing file if the job completes. Ignored if @base is %NULL. * @speed: The maximum speed, in bytes per second, or 0 for unlimited. +* @compress: True to compress data. * @on_error: The action to take upon error. * @errp: Error object. *
@@ -875,7 +876,8 @@ int is_windows_drive(const char *filename);*/ void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str, -int64_t speed,BlockdevOnError on_error,Error **errp); +int64_t speed,bool compress, +BlockdevOnError on_error,Error **errp);/** * commit_start:
block/stream.c +12 -4
@@ -38,23 +38,29 @@ typedef struct StreamBlockJob {BlockdevOnError on_error;char *backing_file_str;int bs_flags; +bool compress; } StreamBlockJob; static int coroutine_fn stream_populate(BlockBackend *blk,int64_t offset,uint64_t bytes, -void *buf) +void *buf,bool compress) {struct iovec iov = { .iov_base = buf, .iov_len = bytes, };QEMUIOVector qiov; +int flags =BDRV_REQ_COPY_ON_READ ; + +if (compress) { + flags |=BDRV_REQ_WRITE_COMPRESSED ; + }assert (bytes <SIZE_MAX );qemu_iovec_init_external (&qiov, &iov,1 );/* Copy-on-read the unallocated clusters */ -return blk_co_preadv (blk, offset, qiov.size, &qiov,BDRV_REQ_COPY_ON_READ ); +return blk_co_preadv (blk, offset, qiov.size, &qiov, flags); } typedef struct {
@@ -166,7 +172,7 @@ static void coroutine_fn stream_run(void *opaque) }trace_stream_one_iteration (s, offset, n, ret);if (copy) { - ret =stream_populate (blk, offset, n, buf); + ret =stream_populate (blk, offset, n, buf, s->compress); }if (ret <0 ) { BlockErrorAction action =
@@ -227,7 +233,8 @@ static const BlockJobDriver stream_job_driver = {void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str, -int64_t speed,BlockdevOnError on_error,Error **errp) +int64_t speed,bool compress, +BlockdevOnError on_error,Error **errp) {StreamBlockJob *s;BlockDriverState *iter;
@@ -267,6 +274,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base = base; s->backing_file_str =g_strdup (backing_file_str); s->bs_flags = orig_bs_flags; + s->compress = compress; s->on_error = on_error;trace_stream_start (bs, base, s);
blockdev.c +12 -1
@@ -2968,6 +2968,7 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, bool has_base_node, const char *base_node, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, + bool has_compress, bool compress, bool has_on_error, BlockdevOnError on_error, Error **errp) {
@@ -2981,6 +2982,10 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, on_error =BLOCKDEV_ON_ERROR_REPORT ; } +if (!has_compress) { + compress = false; + } + bs =bdrv_lookup_bs (device, device, errp);if (!bs) {return ;
@@ -3034,11 +3039,17 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, goto out; } +if (compress && bs->drv->bdrv_co_pwritev_compressed ==NULL ) { +error_setg (errp,"Compression is not supported for this drive %s" , +bdrv_get_device_name (bs)); + goto out; + } +/* backing_file string overrides base bs filename */ base_name = has_backing_file ? backing_file : base_name;stream_start (has_job_id ? job_id :NULL , bs, base_bs, base_name, - has_speed ? speed :0 , on_error, &local_err); + has_speed ? speed :0 , compress, on_error, &local_err);if (local_err) {error_propagate (errp, local_err); goto out;
hmp.c +2 -0
@@ -1812,9 +1812,11 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)const char *device =qdict_get_str (qdict,"device" );const char *base =qdict_get_try_str (qdict,"base" );int64_t speed =qdict_get_try_int (qdict,"speed" ,0 ); +bool compress =qdict_get_try_bool (qdict,"compress" , false);qmp_block_stream (true, device, device, base !=NULL , base, false,NULL , false,NULL ,qdict_haskey (qdict,"speed" ), speed, +qdict_haskey (qdict,"compress" ), compress, true,BLOCKDEV_ON_ERROR_REPORT , &error);hmp_handle_error (mon, &error);
hmp-commands.hx +2 -2
@@ -75,8 +75,8 @@ ETEXI { .name = "block_stream", - .args_type = "device:B,speed:o?,base:s?", - .params = "device [speed [base]]", + .args_type = "device:B,speed:o?,base:s?,compress:o?", + .params = "device [speed [base]] [compress]", .help = "copy data from a backing file into a block device", .cmd = hmp_block_stream, },
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 4/5] block-stream: add compress option
Quoted 9 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- qapi/block-core.json | 4 ++++ include/block/block_int.h | 4 +++- block/stream.c | 16 ++++++++++++---- blockdev.c | 13 ++++++++++++- hmp.c | 2 ++ hmp-commands.hx | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-)
Looks good to me overall, two notes below.
Max
qapi/block-core.json line 2012
Quoted 11 lines
qapi/block-core.json +3
-0@@ -2007,6 +2007,9 @@ # # @speed: the maximum speed, in bytes per second # +# @compress: true to compress data, if the target format supports it. +# (default: false). Since 2.12. +#
Too many full stops (one before, one after the parentheses). Also, this makes it sound a bit like it would still be possible to specify this parameter even if the target doesn't support it (and it would just be ignored then), but that's not true.
Also, the format most parameter documentation follows for block-stream is more "@parameter: Description. Default. (Since version)".
So I'd suggest:
"true to compress data; may only be set if the target format supports it. Defaults to false if omitted. (Since 2.12)"
But I won't argue too much over the format, so the following is OK, too:
"true to compress data; may only be set if the target format supports it (default: false). (Since 2.12)"
Quoted 120 lines
qapi/block-core.json +1
-0# @on-error: the action to take on an error (default report). # 'stop' and 'enospc' can only be used if the block device # supports io-status (see BlockInfo). Since 1.3.@@ -2026,6 +2029,7 @@ { 'command': 'block-stream', 'data': { '*job-id': 'str', 'device': 'str', '*base': 'str', '*base-node': 'str', '*backing-file': 'str', '*speed': 'int', + '*compress': 'bool', '*on-error': 'BlockdevOnError' } } ##include/block/block_int.h +3
-1@@ -863,6 +863,7 @@ int is_windows_drive(const char *filename);* @backing_file_str: The file name that will be written to @bs as the * the new backing file if the job completes. Ignored if @base is %NULL. * @speed: The maximum speed, in bytes per second, or 0 for unlimited. +* @compress: True to compress data. * @on_error: The action to take upon error. * @errp: Error object. * @@ -875,7 +876,8 @@ int is_windows_drive(const char *filename);*/ void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str, -int64_t speed,BlockdevOnError on_error,Error **errp); +int64_t speed,bool compress, +BlockdevOnError on_error,Error **errp);/** * commit_start: block/stream.c +12
-4@@ -38,23 +38,29 @@ typedef struct StreamBlockJob {BlockdevOnError on_error;char *backing_file_str;int bs_flags; +bool compress; } StreamBlockJob; static int coroutine_fn stream_populate(BlockBackend *blk,int64_t offset,uint64_t bytes, -void *buf) +void *buf,bool compress) {struct iovec iov = { .iov_base = buf, .iov_len = bytes, };QEMUIOVector qiov; +int flags =BDRV_REQ_COPY_ON_READ ; + +if (compress) { + flags |=BDRV_REQ_WRITE_COMPRESSED ; + }assert (bytes <SIZE_MAX );qemu_iovec_init_external (&qiov, &iov,1 );/* Copy-on-read the unallocated clusters */ -return blk_co_preadv (blk, offset, qiov.size, &qiov,BDRV_REQ_COPY_ON_READ ); +return blk_co_preadv (blk, offset, qiov.size, &qiov, flags); } typedef struct {@@ -166,7 +172,7 @@ static void coroutine_fn stream_run(void *opaque) }trace_stream_one_iteration (s, offset, n, ret);if (copy) { - ret =stream_populate (blk, offset, n, buf); + ret =stream_populate (blk, offset, n, buf, s->compress); }if (ret <0 ) { BlockErrorAction action =@@ -227,7 +233,8 @@ static const BlockJobDriver stream_job_driver = {void stream_start (const char *job_id,BlockDriverState *bs,BlockDriverState *base,const char *backing_file_str, -int64_t speed,BlockdevOnError on_error,Error **errp) +int64_t speed,bool compress, +BlockdevOnError on_error,Error **errp) {StreamBlockJob *s;BlockDriverState *iter;@@ -267,6 +274,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base = base; s->backing_file_str =g_strdup (backing_file_str); s->bs_flags = orig_bs_flags; + s->compress = compress; s->on_error = on_error;trace_stream_start (bs, base, s);blockdev.c +5
-0@@ -2968,6 +2968,7 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, bool has_base_node, const char *base_node, bool has_backing_file, const char *backing_file, bool has_speed, int64_t speed, + bool has_compress, bool compress, bool has_on_error, BlockdevOnError on_error, Error **errp) {@@ -2981,6 +2982,10 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, on_error =BLOCKDEV_ON_ERROR_REPORT ; } +if (!has_compress) { + compress = false; + } + bs =bdrv_lookup_bs (device, device, errp);if (!bs) {return ;
blockdev.c void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, · line 3044
Quoted 6 lines
blockdev.c +3
-0@@ -3034,11 +3039,17 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, goto out; } +if (compress && bs->drv->bdrv_co_pwritev_compressed ==NULL ) { +error_setg (errp,"Compression is not supported for this drive %s" , +bdrv_get_device_name (bs));
I think just device instead of bdrv_get_device_name(bs) is better (or bdrv_get_device_or_node_name(bs) at least).
Quoted 44 lines
blockdev.c +4
-1+ goto out; + } +/* backing_file string overrides base bs filename */ base_name = has_backing_file ? backing_file : base_name;stream_start (has_job_id ? job_id :NULL , bs, base_bs, base_name, - has_speed ? speed :0 , on_error, &local_err); + has_speed ? speed :0 , compress, on_error, &local_err);if (local_err) {error_propagate (errp, local_err); goto out;hmp.c +2
-0@@ -1812,9 +1812,11 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)const char *device =qdict_get_str (qdict,"device" );const char *base =qdict_get_try_str (qdict,"base" );int64_t speed =qdict_get_try_int (qdict,"speed" ,0 ); +bool compress =qdict_get_try_bool (qdict,"compress" , false);qmp_block_stream (true, device, device, base !=NULL , base, false,NULL , false,NULL ,qdict_haskey (qdict,"speed" ), speed, +qdict_haskey (qdict,"compress" ), compress, true,BLOCKDEV_ON_ERROR_REPORT , &error);hmp_handle_error (mon, &error);hmp-commands.hx +2
-2@@ -75,8 +75,8 @@ ETEXI { .name = "block_stream", - .args_type = "device:B,speed:o?,base:s?", - .params = "device [speed [base]]", + .args_type = "device:B,speed:o?,base:s?,compress:o?", + .params = "device [speed [base]] [compress]", .help = "copy data from a backing file into a block device", .cmd = hmp_block_stream, },
Re: [Qemu-devel] [PATCH 4/5] block-stream: add compress option
Quoted 37 lines · Max Reitz
Quoted 9 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- qapi/block-core.json | 4 ++++ include/block/block_int.h | 4 +++- block/stream.c | 16 ++++++++++++---- blockdev.c | 13 ++++++++++++- hmp.c | 2 ++ hmp-commands.hx | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-)Looks good to me overall, two notes below.
Max
qapi/block-core.json line 2012
Quoted 11 lines
qapi/block-core.json +3
-0@@ -2007,6 +2007,9 @@ # # @speed: the maximum speed, in bytes per second # +# @compress: true to compress data, if the target format supports it. +# (default: false). Since 2.12. +#Too many full stops (one before, one after the parentheses). Also, this makes it sound a bit like it would still be possible to specify this parameter even if the target doesn't support it (and it would just be ignored then), but that's not true.
Also, the format most parameter documentation follows for block-stream is more "@parameter: Description. Default. (Since version)".
So I'd suggest:
Quoted 8 lines
"true to compress data; may only be set if the target format supports it. Defaults to false if omitted. (Since 2.12)"
But I won't argue too much over the format, so the following is OK, too:
"true to compress data; may only be set if the target format supports it (default: false). (Since 2.12)"
Thanks, will fix.
[..]
Quoted 11 lines
qapi/block-core.json void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, · line 3044
Quoted 7 lines
qapi/block-core.json +3
-0@@ -3034,11 +3039,17 @@ void qmp_block_stream(bool has_job_id, const char *job_id, const char *device, goto out; } + if (compress && bs->drv->bdrv_co_pwritev_compressed == NULL) { + error_setg(errp, "Compression is not supported for this drive %s", + bdrv_get_device_name(bs));I think just device instead of
bdrv_get_device_name(bs)is better (orbdrv_get_device_or_node_name(bs)at least).
device should be enough indeed, done.
/Anton
PATCH 5/5 iotest 030: add compressed block-stream test
In reply to Anton Nefedov--- tests/qemu-iotests/030 | 69 +++++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 +-- 2 files changed, 70 insertions(+), 3 deletions(-)
tests/qemu-iotests/030 +68 -1
@@ -21,7 +21,7 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_pipe, qemu_io backing_img = os.path.join(iotests.test_dir, 'backing.img') mid_img = os.path.join(iotests.test_dir, 'mid.img')
@@ -800,5 +800,72 @@ class TestSetSpeed(iotests.QMPTestCase): self.cancel_and_wait() +class TestCompressed(iotests.QMPTestCase): + supported_fmts = ['qcow2'] + cluster_size = 64 * 1024; + image_len = 1 * 1024 * 1024; + + def setUp(self): + qemu_img('create', backing_img, str(TestCompressed.image_len)) + qemu_io('-f', 'raw', '-c', 'write -P 1 0 ' + str(TestCompressed.image_len), backing_img) + qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) + + # write '4' in every 4th cluster + step=4 + for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1): + qemu_io('-c', 'write -P %d %d %d' % + (step, step * i * TestCompressed.cluster_size, + TestCompressed.cluster_size), + test_img) + + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + os.remove(test_img) + os.remove(backing_img) + + def _pattern(self, x, divs): + return divs[-1] if not x%divs[-1] else self._pattern(x, divs[:-1]) + + def test_compressed(self): + self.assert_no_active_block_jobs() + + result = self.vm.qmp('block-stream', device='drive0', compress=True) + if iotests.imgfmt not in TestCompressed.supported_fmts: + self.assert_qmp( + result, 'error/desc', + 'Compression is not supported for this drive drive0') + return + self.assert_qmp(result, 'return', {}) + + # write '2' in every 2nd cluster + step = 2 + for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1): + result = self.vm.qmp('human-monitor-command', + command_line= + 'qemu-io drive0 \"write -P %d %d %d\"' % + (step, step * i * TestCompressed.cluster_size, + TestCompressed.cluster_size)) + self.assert_qmp(result, 'return', "") + + self.wait_until_completed() + self.assert_no_active_block_jobs() + + self.vm.shutdown() + + for i in range(TestCompressed.image_len / TestCompressed.cluster_size): + outp = qemu_io('-c', 'read -P %d %d %d' % + (self._pattern(i, [1,4,2]), + i * TestCompressed.cluster_size, + TestCompressed.cluster_size), + test_img) + self.assertTrue(not 'fail' in outp) + self.assertTrue('read' in outp and 'at offset' in outp) + + self.assertTrue( + "File contains external, encrypted or compressed clusters." + in qemu_img_pipe('map', test_img)) + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'])
tests/qemu-iotests/030.out +2 -2
@@ -1,5 +1,5 @@ -....................... +........................ ---------------------------------------------------------------------- -Ran 23 tests +Ran 24 tests OK
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 5/5] iotest 030: add compressed block-stream test
Quoted 20 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- tests/qemu-iotests/030 | 69 +++++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 +-- 2 files changed, 70 insertions(+), 3 deletions(-)tests/qemu-iotests/030 +1
-1@@ -21,7 +21,7 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_pipe, qemu_io backing_img = os.path.join(iotests.test_dir, 'backing.img') mid_img = os.path.join(iotests.test_dir, 'mid.img')
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 809
Quoted 10 lines
tests/qemu-iotests/030 +7
-0@@ -800,5 +800,72 @@ class TestSetSpeed(iotests.QMPTestCase): self.cancel_and_wait() +class TestCompressed(iotests.QMPTestCase): + supported_fmts = ['qcow2'] + cluster_size = 64 * 1024; + image_len = 1 * 1024 * 1024; + + def setUp(self): + qemu_img('create', backing_img, str(TestCompressed.image_len))
First, this is missing the '-f raw', if you want to keep it in line with the next command.
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 810
Quoted 1 line
tests/qemu-iotests/030 +1
-0+ qemu_io('-f', 'raw', '-c', 'write -P 1 0 ' + str(TestCompressed.image_len), backing_img)
But why would you want this to be raw?
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 814
Quoted 4 lines
tests/qemu-iotests/030 +4
-0+ qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) + + # write '4' in every 4th cluster + step=4
I'd prefer spaces around operators. (Also in _pattern() and in the call to pattern ([1,4,2] should be [1, 4, 2]).)
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 815
Quoted 1 line
tests/qemu-iotests/030 +1
-0+ for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1):
As far as I know, range() has an actual step parameter, maybe that would be simpler -- and I don't know what the +1 is supposed to mean.
How about "for ofs in range(0, TestCompressed.image_len,
TestCompressed.cluster_size * step)"?
Would that work?
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 829
Quoted 13 lines
tests/qemu-iotests/030 +13
-0+ qemu_io('-c', 'write -P %d %d %d' % + (step, step * i * TestCompressed.cluster_size,> + TestCompressed.cluster_size), + test_img) + + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + os.remove(test_img) + os.remove(backing_img) + + def _pattern(self, x, divs): + return divs[-1] if not x%divs[-1] else self._pattern(x, divs[:-1])
I have no idea what this function does.
...OK, having looked into how it's used, I understand better. A comment would certainly be helpful, though.
Maybe also call it differently. It doesn't really return a pattern. What this function does is it returns the first integer from @divs (starting from the end, which is weird) which is a divider of @x. So maybe call it _first_divider(self, x, dividers), that would help already.
Quoted 8 lines
tests/qemu-iotests/030 +8
-0+ + def test_compressed(self): + self.assert_no_active_block_jobs() + + result = self.vm.qmp('block-stream', device='drive0', compress=True) + if iotests.imgfmt not in TestCompressed.supported_fmts: + self.assert_qmp( + result, 'error/desc',
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 847
Quoted 10 lines
tests/qemu-iotests/030 +10
-0+ 'Compression is not supported for this drive drive0') + return + self.assert_qmp(result, 'return', {}) + + # write '2' in every 2nd cluster + step = 2 + for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1): + result = self.vm.qmp('human-monitor-command', + command_line= + 'qemu-io drive0 \"write -P %d %d %d\"' %
Just " instead of \" would be enough, I think.
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 859
Quoted 12 lines
tests/qemu-iotests/030 +12
-0+ (step, step * i * TestCompressed.cluster_size, + TestCompressed.cluster_size)) + self.assert_qmp(result, 'return', "") + + self.wait_until_completed() + self.assert_no_active_block_jobs() + + self.vm.shutdown() + + for i in range(TestCompressed.image_len / TestCompressed.cluster_size): + outp = qemu_io('-c', 'read -P %d %d %d' % + (self._pattern(i, [1,4,2]),
The 4 is useless, because everything that's divisible by 4 is divisible by 2 already.
Also, I don't quite see what this should achieve exactly. You first write the backing image full of 1s, OK. Then you write 4s to every fourth cluster in the top image. Then you start streaming, and then you write 2s to ever second cluster in the top image, which overwrites all of the 4s you wrote.
Do you maybe not want to write 2 into every second cluster of the backing image in setUp() instead of 4 into the top image? (And then 4th into every fourth cluster here in test_compressed().) Then you would need [1, 2, 4] here, which makes much more sense.
Max
Quoted 25 lines
tests/qemu-iotests/030 +10
-0+ i * TestCompressed.cluster_size, + TestCompressed.cluster_size), + test_img) + self.assertTrue(not 'fail' in outp) + self.assertTrue('read' in outp and 'at offset' in outp) + + self.assertTrue( + "File contains external, encrypted or compressed clusters." + in qemu_img_pipe('map', test_img)) + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'])tests/qemu-iotests/030.out +2
-2@@ -1,5 +1,5 @@ -....................... +........................ ---------------------------------------------------------------------- -Ran 23 tests +Ran 24 tests OK
Re: [Qemu-devel] [PATCH 5/5] iotest 030: add compressed block-stream test
Quoted 35 lines · Max Reitz
Quoted 20 lines · Anton Nefedov
Signed-off-by Anton Nefedov <[email protected]>--- tests/qemu-iotests/030 | 69 +++++++++++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/030.out | 4 +-- 2 files changed, 70 insertions(+), 3 deletions(-)tests/qemu-iotests/030 +1
-1@@ -21,7 +21,7 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_pipe, qemu_io backing_img = os.path.join(iotests.test_dir, 'backing.img') mid_img = os.path.join(iotests.test_dir, 'mid.img')tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 809
Quoted 10 lines
tests/qemu-iotests/030 +7
-0@@ -800,5 +800,72 @@ class TestSetSpeed(iotests.QMPTestCase): self.cancel_and_wait() +class TestCompressed(iotests.QMPTestCase): + supported_fmts = ['qcow2'] + cluster_size = 64 * 1024; + image_len = 1 * 1024 * 1024; + + def setUp(self): + qemu_img('create', backing_img, str(TestCompressed.image_len))First, this is missing the '-f raw', if you want to keep it in line with the next command.
Quoted 4 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 810
Quoted 1 line
tests/qemu-iotests/030 +1
-0+ qemu_io('-f', 'raw', '-c', 'write -P 1 0 ' + str(TestCompressed.image_len), backing_img)But why would you want this to be raw?
Copied this from another test in this file :)
The source image format does not really matter. Will fix though.
Quoted 8 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 814
Quoted 4 lines
tests/qemu-iotests/030 +4
-0+ qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img) + + # write '4' in every 4th cluster + step=4I'd prefer spaces around operators. (Also in
_pattern()and in the call to pattern ([1,4,2] should be [1, 4, 2]).)
Quoted 9 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 815
Quoted 1 line
tests/qemu-iotests/030 +1
-0+ for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1):As far as I know,
range()has an actual step parameter, maybe that would be simpler -- and I don't know what the +1 is supposed to mean.How about "for ofs in range(0, TestCompressed.image_len,
TestCompressed.cluster_size * step)"?
Would that work?
It does, thank you.
Quoted 16 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 829
Quoted 13 lines
tests/qemu-iotests/030 +13
-0+ qemu_io('-c', 'write -P %d %d %d' % + (step, step * i * TestCompressed.cluster_size,> + TestCompressed.cluster_size), + test_img) + + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + os.remove(test_img) + os.remove(backing_img) + + def _pattern(self, x, divs): + return divs[-1] if not x%divs[-1] else self._pattern(x, divs[:-1])I have no idea what this function does.
Quoted 8 lines
...OK, having looked into how it's used, I understand better. A comment would certainly be helpful, though.
Maybe also call it differently. It doesn't really return a pattern. What this function does is it returns the first integer from @divs (starting from the end, which is weird) which is a divider of @x. So maybe call it
_first_divider(self, x, dividers), that would help already.
Yeah, I really had to comment.
Exactly, it starts from the end as I meant it to accept numbers in the order they were written. So 'first_divider' wouldn't be right. Not that important though, will rename and reorder the input.
Quoted 12 lines
Quoted 12 lines
tests/qemu-iotests/030 +12
-0+ + def test_compressed(self): + self.assert_no_active_block_jobs() + + result = self.vm.qmp('block-stream', device='drive0', compress=True) + if iotests.imgfmt not in TestCompressed.supported_fmts: + self.assert_qmp( + result, 'error/desc', + 'Compression is not supported for this drive drive0') + return + self.assert_qmp(result, 'return', {}) +
Quoted 9 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 847
Quoted 6 lines
tests/qemu-iotests/030 +6
-0+ # write '2' in every 2nd cluster + step = 2 + for i in range(TestCompressed.image_len / TestCompressed.cluster_size / step + 1): + result = self.vm.qmp('human-monitor-command', + command_line= + 'qemu-io drive0 \"write -P %d %d %d\"' %Just " instead of \" would be enough, I think.
Done.
Quoted 22 lines
tests/qemu-iotests/030 class TestSetSpeed(iotests.QMPTestCase): · line 859
Quoted 12 lines
tests/qemu-iotests/030 +12
-0+ (step, step * i * TestCompressed.cluster_size, + TestCompressed.cluster_size)) + self.assert_qmp(result, 'return', "") + + self.wait_until_completed() + self.assert_no_active_block_jobs() + + self.vm.shutdown() + + for i in range(TestCompressed.image_len / TestCompressed.cluster_size): + outp = qemu_io('-c', 'read -P %d %d %d' % + (self._pattern(i, [1,4,2]),The 4 is useless, because everything that's divisible by 4 is divisible by 2 already.
Also, I don't quite see what this should achieve exactly. You first write the backing image full of 1s, OK. Then you write 4s to every fourth cluster in the top image. Then you start streaming, and then you write 2s to ever second cluster in the top image, which overwrites all of the 4s you wrote.
Quoted 7 lines
Do you maybe not want to write 2 into every second cluster of the backing image in
setUp()instead of 4 into the top image? (And then 4th into every fourth cluster here intest_compressed().) Then you would need [1, 2, 4] here, which makes much more sense.Max
Then the top image would be empty before stream starts. Not very good as qmp-driven writes may be late and just overwrite clusters of the image fully copied from backing.
I meant the concurrent write touching both top and backing clusters. 2 and 4 were a bad choice though.
I think setUp() should write every 3 to the top (so we have unallocated cluster pairs to cover qcow2 writing several clusters compressed). And test_compressed() write every 4 with qmp.
Quoted 27 lines
Quoted 25 lines
tests/qemu-iotests/030 +10
-0+ i * TestCompressed.cluster_size, + TestCompressed.cluster_size), + test_img) + self.assertTrue(not 'fail' in outp) + self.assertTrue('read' in outp and 'at offset' in outp) + + self.assertTrue( + "File contains external, encrypted or compressed clusters." + in qemu_img_pipe('map', test_img)) + if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'])tests/qemu-iotests/030.out +2
-2@@ -1,5 +1,5 @@ -....................... +........................ ---------------------------------------------------------------------- -Ran 23 tests +Ran 24 tests OK
Quoted 3 lines · Anton Nefedov
It might be useful to compress images during block-stream; this way the user can merge compressed images of a backing chain and the result will remain compressed.
I haven't looked at the patches yet so maybe the answer is obvious, but still:
would the "compress" option be still necessary if what we have is blockdev-stream instead?
Fam
Quoted 11 lines · Fam Zheng
Quoted 3 lines · Anton Nefedov
It might be useful to compress images during block-stream; this way the user can merge compressed images of a backing chain and the result will remain compressed.
I haven't looked at the patches yet so maybe the answer is obvious, but still:
would the "compress" option be still necessary if what we have is blockdev-stream instead?Fam
Sorry, I can't see blockdev-stream available now. How that would be different? Would it imply the blocks are pulled up to the top (active) image?
Or did you mean block-commit? The option might be useful there as well, and needs to be implemented separately
/Anton