Skip to content

Commit 3f93481

Browse files
PiMakerkevmw
authored andcommitted
block/io: accept NULL qiov in bdrv_pad_request
Some operations, e.g. block-stream, perform reads while discarding the results (only copy-on-read matters). In this case, they will pass NULL as the target QEMUIOVector, which will however trip bdrv_pad_request, since it wants to extend its passed vector. In particular, this is the case for the blk_co_preadv() call in stream_populate(). If there is no qiov, no operation can be done with it, but the bytes and offset still need to be updated, so the subsequent aligned read will actually be aligned and not run into an assertion failure. In particular, this can happen when the request alignment of the top node is larger than the allocated part of the bottom node, in which case padding becomes necessary. For example: > ./qemu-img create /tmp/backing.qcow2 -f qcow2 64M -o cluster_size=32768 > ./qemu-io -c "write -P42 0x0 0x1" /tmp/backing.qcow2 > ./qemu-img create /tmp/top.qcow2 -f qcow2 64M -b /tmp/backing.qcow2 -F qcow2 > ./qemu-system-x86_64 --qmp stdio \ > --blockdev qcow2,node-name=node0,file.driver=file,file.filename=/tmp/top.qcow2 \ > <<EOF > {"execute": "qmp_capabilities"} > {"execute": "blockdev-add", "arguments": { "driver": "compress", "file": "node0", "node-name": "node1" } } > {"execute": "block-stream", "arguments": { "job-id": "stream0", "device": "node1" } } > EOF Originally-by: Stefan Reiter <[email protected]> Signed-off-by: Thomas Lamprecht <[email protected]> [FE: do update bytes and offset in any case add reproducer to commit message] Signed-off-by: Fiona Ebner <[email protected]> Message-ID: <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 2c66de6 commit 3f93481

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

block/io.c

+20-13
Original file line numberDiff line numberDiff line change
@@ -1726,22 +1726,29 @@ static int bdrv_pad_request(BlockDriverState *bs,
17261726
return 0;
17271727
}
17281728

1729-
sliced_iov = qemu_iovec_slice(*qiov, *qiov_offset, *bytes,
1730-
&sliced_head, &sliced_tail,
1731-
&sliced_niov);
1732-
1733-
/* Guaranteed by bdrv_check_request32() */
1734-
assert(*bytes <= SIZE_MAX);
1735-
ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov,
1736-
sliced_head, *bytes);
1737-
if (ret < 0) {
1738-
bdrv_padding_finalize(pad);
1739-
return ret;
1729+
/*
1730+
* For prefetching in stream_populate(), no qiov is passed along, because
1731+
* only copy-on-read matters.
1732+
*/
1733+
if (qiov && *qiov) {
1734+
sliced_iov = qemu_iovec_slice(*qiov, *qiov_offset, *bytes,
1735+
&sliced_head, &sliced_tail,
1736+
&sliced_niov);
1737+
1738+
/* Guaranteed by bdrv_check_request32() */
1739+
assert(*bytes <= SIZE_MAX);
1740+
ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov,
1741+
sliced_head, *bytes);
1742+
if (ret < 0) {
1743+
bdrv_padding_finalize(pad);
1744+
return ret;
1745+
}
1746+
*qiov = &pad->local_qiov;
1747+
*qiov_offset = 0;
17401748
}
1749+
17411750
*bytes += pad->head + pad->tail;
17421751
*offset -= pad->head;
1743-
*qiov = &pad->local_qiov;
1744-
*qiov_offset = 0;
17451752
if (padded) {
17461753
*padded = true;
17471754
}

0 commit comments

Comments
 (0)