aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2023-02-03 12:43:10 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-02-03 12:43:10 +0000
commit5736527050cfcc5b92521d79fe87b4883059d864 (patch)
tree8de593567c75a7596e65a0487aa82c00874a1b4f /hw
parentbf4460a8d9a86f6cfe05d7a7f470c48e3a93d8b2 (diff)
parentd570177b50c389f379f93183155a27d44856ab46 (diff)
downloadqemu-5736527050cfcc5b92521d79fe87b4883059d864.zip
qemu-5736527050cfcc5b92521d79fe87b4883059d864.tar.gz
qemu-5736527050cfcc5b92521d79fe87b4883059d864.tar.bz2
Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging
Block layer patches - qemu-img info: Show protocol-level information - Move more functions to coroutines - Make coroutine annotations ready for static analysis - qemu-img: Fix exit code for errors closing the image - qcow2 bitmaps: Fix theoretical corruption in error path - pflash: Only load non-zero parts of backend image to save memory - Code cleanup and test case improvements # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCAAvFiEE3D3rFZqa+V09dFb+fwmycsiPL9YFAmPajLURHGt3b2xmQHJl # ZGhhdC5jb20ACgkQfwmycsiPL9aLjg//bk2uodtEZ1X1y/vU3Lmcqd2wh9gv4f9L # csFFf17rrxce/m+4daVISHAzS+Zrwpgixt+vMm2dP+jQTZOg0G7/rcaRYYAYa29Y # Lepr2Qsz0V6HnNpuvUE5hrXiJXU7w5InikLlnoTnwa2H2Nr/wMlzkPX1wh4OdaBy # 5KG/sjGVsaotrIdYjI3HnTvU/eytn1IcvLwqcTP2M7u8UMNyZkALyDjbC5QxBkwh # TPVXNGCeDrD6atDOvsmBCkNM3kTmfsGoP5mYyJK5V6iARYV19Nt8tdmt094EFmHk # VBgeY9y+Q6BctcDe31961+oFqGrsLnT3J7mHDhAoaO0BM8wwWCHfCA7yasmGjCj5 # HGE7/UJ8DYwGQ9T9N8gsx8NmsfyWgIcyRQGuzld72B4FTzES9NXS1JTUFAZHrDUl # IIaL5bh8aycBKprDBTwvz07a6sDkvmxiR2G0TuS7kFev5O7+qW9dH517PWOWbsRA # 3+ICzsHCUE2GLi83KkRkBEqRW0CnNmA9qzWNdPdQ0egsEAtNqmJGaFPRLYqQ0ZwR # gbu7+eK4kUyfqpqieeFxBY53THLE4yxZ3lcg4yFoQWQfKdTCYo69qUNK5AV1hvKY # TzNAuNbOsipL06dRWy4jInbhzenbiYechyEuoqFv0PpHe1D+JrL8QA2hI/JHDwls # enNpKYXdkn4= # =Wf8w # -----END PGP SIGNATURE----- # gpg: Signature made Wed 01 Feb 2023 16:00:53 GMT # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "kwolf@redhat.com" # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * tag 'for-upstream' of https://repo.or.cz/qemu/kevin: (38 commits) qemu-img: Change info key names for protocol nodes qemu-img: Let info print block graph iotests/106, 214, 308: Read only one size line iotests: Filter child node information block/qapi: Add indentation to bdrv_node_info_dump() block/qapi: Introduce BlockGraphInfo block/qapi: Let bdrv_query_image_info() recurse qemu-img: Use BlockNodeInfo block: Split BlockNodeInfo off of ImageInfo block/vmdk: Change extent info type block/file: Add file-specific image info block: Improve empty format-specific info dump block/nbd: Add missing <qemu/bswap.h> include block: Rename bdrv_load/save_vmstate() to bdrv_co_load/save_vmstate() block: Convert bdrv_debug_event() to co_wrapper_mixed block: Convert bdrv_lock_medium() to co_wrapper block: Convert bdrv_eject() to co_wrapper block: Convert bdrv_get_info() to co_wrapper_mixed block: Convert bdrv_get_allocated_file_size() to co_wrapper block: use bdrv_co_refresh_total_sectors when possible ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/block/block.c36
-rw-r--r--hw/scsi/scsi-disk.c5
2 files changed, 40 insertions, 1 deletions
diff --git a/hw/block/block.c b/hw/block/block.c
index ddcef71f..af0710e 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -16,6 +16,40 @@
#include "qapi/qapi-types-block.h"
/*
+ * Read the non-zeroes parts of @blk into @buf
+ * Reading all of the @blk is expensive if the zeroes parts of @blk
+ * is large enough. Therefore check the block status and only write
+ * the non-zeroes block into @buf.
+ *
+ * Return 0 on success, non-zero on error.
+ */
+static int blk_pread_nonzeroes(BlockBackend *blk, hwaddr size, void *buf)
+{
+ int ret;
+ int64_t bytes, offset = 0;
+ BlockDriverState *bs = blk_bs(blk);
+
+ for (;;) {
+ bytes = MIN(size - offset, BDRV_REQUEST_MAX_SECTORS);
+ if (bytes <= 0) {
+ return 0;
+ }
+ ret = bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL);
+ if (ret < 0) {
+ return ret;
+ }
+ if (!(ret & BDRV_BLOCK_ZERO)) {
+ ret = bdrv_pread(bs->file, offset, bytes,
+ (uint8_t *) buf + offset, 0);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+ offset += bytes;
+ }
+}
+
+/*
* Read the entire contents of @blk into @buf.
* @blk's contents must be @size bytes, and @size must be at most
* BDRV_REQUEST_MAX_BYTES.
@@ -54,7 +88,7 @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
* block device and read only on demand.
*/
assert(size <= BDRV_REQUEST_MAX_BYTES);
- ret = blk_pread(blk, 0, size, buf, 0);
+ ret = blk_pread_nonzeroes(blk, size, buf);
if (ret < 0) {
error_setg_errno(errp, -ret, "can't read block backend");
return false;
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index e493c28..d4e3608 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2332,10 +2332,15 @@ static void scsi_disk_reset(DeviceState *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);
uint64_t nb_sectors;
+ AioContext *ctx;
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
+ ctx = blk_get_aio_context(s->qdev.conf.blk);
+ aio_context_acquire(ctx);
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
+ aio_context_release(ctx);
+
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
if (nb_sectors) {
nb_sectors--;