Block layer patches
The following changes since commit 56afd82bd4db9688f1c1c9d0e2ea163b8cde3283:
Merge tag 'qemu-sparc-20261101' of https://github.com/mcayland/qemu into staging (2026-11-01 08:37:48 -0800)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 6e641f2440aa637c670b7f0fe512ea3fc2611b99:
block/vmdk: add eos marker for stream optimized disks (2026-11-02 17:06:37 +0100)
----------------------------------------------------------------
Block layer patches
- mirror: do not require a root block node
- file-posix: Add 'accept-read-only-device' option
- vmdk: Fixes for converting to streamOptimized
- virtio-blk: Add support for FUA write requests
- Print simple help text when calling "-blockdev help"
- qemu-nbd: Add --all-bitmaps option
- coroutine: Fix default idle pool max size on Linux
----------------------------------------------------------------
Alberto Faria (1):
virtio-blk: Add support for FUA write requests
Christian Quante (1):
tests/qtest/fdc-test: check block accounting of non-DMA reads
Daniel P. Berrangé (1):
block: fix leak of block histogram data
Eric Blake (1):
qemu-nbd: Add --all-bitmaps option
Fiona Ebner (3):
iotests/041: add test for mirror with throttle node as source
blockdev: mirror: do not require a root block node iotests/041: add tests for mirroring below throttle node
Haoqian He (1):
iotests: cover discard passthrough during background mirror
Hector Cao (1):
util/coroutine: trim sysctl's max_map_count newline before parsing
Kevin Wolf (2):
file-posix: Add 'accept-read-only-device' option
iotests: Add loop-accept-ro-dev test
Sanne Raymaekers (3):
block/vmdk: Don't preallocate full 64k for compressed data grains block/vmdk: skip RGD for stream optimized disks block/vmdk: add eos marker for stream optimized disks
Stefan Hajnoczi (1):
qemu-pr-helper: do not free reply when multipath_process_cmd() fails
Thomas Huth (1):
block: Print simple help text when calling "-blockdev help"
Wesley Hershberger (1):
util/coroutine: Reduce default idle pool max size
qapi/block-core.json | 23 ++++- docs/tools/qemu-nbd.rst | 12 ++- include/block/block-common.h | 1 + include/hw/virtio/virtio-blk.h | 1 + block.c | 15 +++ block/accounting.c | 2 + block/file-posix.c | 23 ++++- block/vmdk.c | 121 +++++++++++++--------- blockdev.c | 20 +++- hw/block/virtio-blk.c | 37 +++++++ hw/core/machine.c | 1 + hw/virtio/virtio-qmp.c | 10 ++ qemu-nbd.c | 57 ++++++++++- scsi/qemu-pr-helper.c | 11 +- system/vl.c | 7 +- tests/qtest/fdc-test.c | 42 ++++++++ util/qemu-coroutine.c | 71 ++++++++----- tests/qemu-iotests/041 | 128 ++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- tests/qemu-iotests/tests/loop-accept-ro-dev | 88 ++++++++++++++++ tests/qemu-iotests/tests/loop-accept-ro-dev.out | 19 ++++ tests/qemu-iotests/tests/mirror-discard | 73 ++++++++++++++ tests/qemu-iotests/tests/mirror-discard.out | 5 + tests/qemu-iotests/tests/qemu-img-bitmaps | 13 +++ tests/qemu-iotests/tests/qemu-img-bitmaps.out | 12 +++ 25 files changed, 707 insertions(+), 89 deletions(-) create mode 100755 tests/qemu-iotests/tests/loop-accept-ro-dev create mode 100644 tests/qemu-iotests/tests/loop-accept-ro-dev.out create mode 100755 tests/qemu-iotests/tests/mirror-discard create mode 100644 tests/qemu-iotests/tests/mirror-discard.out
[PULL 07/17] blockdev: mirror: do not require a root block node
From: Fiona Ebner <[email protected]>
The mirror block job currently only operates on a root block node. It might be desired to use a throttle node as the root node for limiting the guest IO, without also limiting mirror operations.
There is no obvious reason why mirror should only be able to operate on a root block node.
When there is no explicit @replaces argument, implicit filters on top are skipped. Allowing mirror to operate on non-root nodes does not change that fact and keeps the behavior consistent with the documentation for @replaces.
Message-ID: <[email protected]>
--- qapi/block-core.json | 4 ++-- blockdev.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-)
qapi/block-core.json +2 -2
@@ -2250,7 +2250,7 @@ # @job-id: identifier for the newly-created block job. If omitted, # the device name will be used. (Since 2.7) # -# @device: the device name or node-name of a root node whose writes +# @device: the device name or node-name of a block node whose writes # should be mirrored. # # @target: the target of the new image. If the file exists, or if it
@@ -2573,7 +2573,7 @@ # @job-id: identifier for the newly-created block job. If omitted, # the device name will be used. (Since 2.7) # -# @device: The device name or node-name of a root node whose writes +# @device: The device name or node-name of a block node whose writes # should be mirrored. # # @target: the id or node-name of the block device to mirror to. This
blockdev.c +17 -3
@@ -2987,13 +2987,19 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)bool target_is_zero;int ret; - bs =qmp_get_root_bs (arg->device, errp); +bdrv_graph_rdlock_main_loop (); + bs =bdrv_lookup_bs (arg->device, arg->device, errp);if (!bs) { +bdrv_graph_rdunlock_main_loop (); +return ; + } +if (!bdrv_is_inserted (bs)) { +error_setg (errp,"Device has no medium" ); +bdrv_graph_rdunlock_main_loop ();return ; }/* Early check to avoid creating target */ -bdrv_graph_rdlock_main_loop ();if (bdrv_op_is_blocked (bs,BLOCK_OP_TYPE_MIRROR_SOURCE , errp)) {bdrv_graph_rdunlock_main_loop ();return ;
@@ -3150,10 +3156,18 @@ void qmp_blockdev_mirror(const char *job_id,BlockMirrorBackingMode backing_mode =MIRROR_LEAVE_BACKING_CHAIN ;int ret; - bs =qmp_get_root_bs (device, errp); +bdrv_graph_rdlock_main_loop (); + bs =bdrv_lookup_bs (device, device, errp);if (!bs) { +bdrv_graph_rdunlock_main_loop ();return ; } +if (!bdrv_is_inserted (bs)) { +error_setg (errp,"Device has no medium" ); +bdrv_graph_rdunlock_main_loop (); +return ; + } +bdrv_graph_rdunlock_main_loop (); target_bs =bdrv_lookup_bs (target, target, errp);if (!target_bs) {
Signature · 1 line
2.56.0
[PULL 06/17] iotests/041: add test for mirror with throttle node as source
In reply to Kevin WolfFrom: Fiona Ebner <[email protected]>
Mostly in preparation for commit "iotests/041: add tests for mirroring below throttle node" which adds test cases for commit "blockdev:
mirror: do not require a root block node".
Message-ID: <[email protected]>
--- tests/qemu-iotests/041 | 88 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 +- 2 files changed, 90 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +88 -0
@@ -1373,6 +1373,94 @@ class TestFilters(iotests.QMPTestCase): self.complete_and_wait('mirror') +class TestThrottle(iotests.QMPTestCase): + image_len = 3 * 1024 * 1024 + attachTargetImage = True + + def mirror_command(self, device): + self.vm.cmd('blockdev-mirror', + job_id='mirror', + device=device, + target='target', + sync='full') + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, + test_img, str(self.image_len)) + qemu_img('create', '-f', iotests.imgfmt, + target_img, str(self.image_len)) + qemu_io('-c', 'write -P 23 0 3M', test_img) + + self.vm = iotests.VM().add_device('virtio-scsi,id=vio-scsi') + self.vm.launch() + + self.vm.cmd('object-add', { + 'id': 'thrgr0', + 'qom-type': 'throttle-group', + 'limits': { + 'bps-total': 1 * 1024 + } + }) + + if self.attachTargetImage: + self.vm.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + }, + }) + + source = { + 'node-name': 'source', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': test_img + }, + } + + self.vm.cmd('blockdev-add', { + 'node-name': 'throttle', + 'driver': 'throttle', + 'throttle-group': 'thrgr0', + 'file': source, + }) + + self.vm.cmd('device_add', + driver='scsi-hd', + id='virtio', + bus='vio-scsi.0', + drive='throttle') + + def tearDown(self): + os.remove(test_img) + os.remove(target_img) + + def test_throttled(self): + self.mirror_command('throttle') + + time.sleep(1) + result = self.vm.qmp('query-block-jobs') + self.assert_qmp(result, 'return[0]/ready', False) + + self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000 * 1000}') + self.complete_and_wait('mirror') + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirroring') + +class TestThrottleDriveMirror(TestThrottle): + attachTargetImage = False + + def mirror_command(self, device): + self.vm.cmd('drive-mirror', + job_id='mirror', + device=device, + target=target_img, + sync='full', + mode='existing') if __name__ == '__main__': iotests.main(supported_fmts=['qcow2', 'qed'],
tests/qemu-iotests/041.out +2 -2
@@ -1,5 +1,5 @@ -........................................................................................................... +............................................................................................................. ---------------------------------------------------------------------- -Ran 107 tests +Ran 109 tests OK
Signature · 1 line
2.56.0
[PULL 12/17] iotests: cover discard passthrough during background mirror
In reply to Kevin WolfFrom: Haoqian He <[email protected]>
A mirror_top node without BDRV_O_UNMAP silently ignores discard requests.
Add a regression test to verify that discard requests are not ignored during background mirror.
Message-ID: <[email protected]>
--- tests/qemu-iotests/tests/mirror-discard | 73 +++++++++++++++++++++ tests/qemu-iotests/tests/mirror-discard.out | 5 ++ 2 files changed, 78 insertions(+) create mode 100755 tests/qemu-iotests/tests/mirror-discard create mode 100644 tests/qemu-iotests/tests/mirror-discard.out
tests/qemu-iotests/tests/mirror-discard new file +73 -0
@@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# group: rw auto quick +# +# Test that discard reaches the source through a blockdev-mirror filter. +# +# Copyright (C) 2026 SmartX, Inc. + +from pathlib import Path + +import iotests + + +source = Path(iotests.test_dir, 'mirror-discard-source.qcow2') +target = Path(iotests.test_dir, 'mirror-discard-target.qcow2') + + +class TestMirrorDiscard(iotests.QMPTestCase): + def setUp(self): + for path in (source, target): + self.addCleanup(path.unlink, missing_ok=True) + iotests.qemu_img_create( + '-f', iotests.imgfmt, + '-o', 'compat=1.1,cluster_size=65536', str(path), '1M') + + self.vm = iotests.VM() + # Cleanups run in reverse order: close the VM before removing images. + self.addCleanup(self.vm.shutdown) + self.vm.add_drive(str(source), opts='discard=unmap,node-name=src') + self.vm.add_blockdev( + f'driver={iotests.imgfmt},node-name=target,' + f'file.driver=file,file.filename={target}') + self.vm.launch() + + def test_background_discard(self): + self.vm.cmd('x-qemu-io', device='drive0', + command='write -q -P 0xab 0 192k') + + # Check discard works before mirror_top is inserted, then restore data. + self.vm.cmd('x-qemu-io', device='drive0', + command='discard -q 64k 64k') + self.vm.cmd('x-qemu-io', device='drive0', + command='read -q -P 0x00 64k 64k') + self.vm.cmd('x-qemu-io', device='drive0', + command='write -q -P 0xab 64k 64k') + + self.vm.cmd('blockdev-mirror', job_id='mirror', device='drive0', + target='target', sync='full', copy_mode='background') + self.wait_ready('mirror') + self.pause_job('mirror') + + # Use the backend so the request passes through mirror_top to src. + self.vm.cmd('x-qemu-io', device='drive0', + command='discard -q 64k 64k') + checks = ( + 'read -q -P 0x00 64k 64k', + 'read -q -P 0xab 0 64k', + 'read -q -P 0xab 128k 64k', + ) + for command in checks: + self.vm.cmd('x-qemu-io', device='drive0', command=command) + + self.vm.cmd('block-job-resume', device='mirror') + self.complete_and_wait('mirror', wait_ready=False) + self.vm.shutdown() + + # Check both images independently after all writes have been flushed. + for path in (source, target): + for command in checks: + iotests.qemu_io('-f', iotests.imgfmt, '-c', command, str(path)) + + +if __name__ == '__main__': + iotests.main(supported_fmts=['qcow2'], supported_protocols=['file'])
tests/qemu-iotests/tests/mirror-discard.out new file +5 -0
@@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK
Signature · 1 line
2.56.0
[PULL 11/17] virtio-blk: Add support for FUA write requests
In reply to Kevin WolfFrom: Alberto Faria <[email protected]>
Message-ID: <[email protected]>
--- include/hw/virtio/virtio-blk.h | 1 + hw/block/virtio-blk.c | 37 ++++++++++++++++++++++++++++++++++ hw/core/machine.c | 1 + hw/virtio/virtio-qmp.c | 10 +++++++++ 4 files changed, 49 insertions(+)
include/hw/virtio/virtio-blk.h +1 -0
@@ -99,6 +99,7 @@ typedef struct MultiReqBuffer {VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS ];unsigned int num_reqs;bool is_write; +bool is_fua; } MultiReqBuffer; typedef struct VirtIOBlkClass {
hw/block/virtio-blk.c +37 -0
@@ -38,6 +38,16 @@#include "hw/virtio/virtio-blk-common.h" #include "qemu/coroutine.h" +/* TODO Remove once the Linux headers have caught up */ +#ifndef VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA +#define VIRTIO_BLK_F_REQ_FLAGS 18/* Request flags supported */ +#define VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA 19/* FUA flag supported */ + +#define VIRTIO_BLK_REQ_FLAG_OUT_FUA 0 + +#define VIRTIO_BLK_OUTDHR_FLAGS (out) out.ioprio +#endif +/* Internal buffer size limit for zone report */ #define VIRTIO_BLK_MAX_ZONES_PER_BATCH 4096
@@ -219,6 +229,7 @@ static inline void submit_requests(VirtIOBlock *s, MultiReqBuffer *mrb,QEMUIOVector *qiov = &mrb->reqs[start]->qiov;int64_t sector_num = mrb->reqs[start]->sector_num;bool is_write = mrb->is_write; +bool is_fua = mrb->is_fua;BdrvRequestFlags flags =0 ;if (num_reqs >1 ) {
@@ -255,6 +266,9 @@ static inline void submit_requests(VirtIOBlock *s, MultiReqBuffer *mrb, }if (is_write) { +if (is_fua) { + flags |=BDRV_REQ_FUA ; + }blk_aio_pwritev (blk, sector_num <<BDRV_SECTOR_BITS , qiov, flags, virtio_blk_rw_complete, mrb->reqs[start]);
@@ -895,6 +909,7 @@ out:static int virtio_blk_handle_request (VirtIOBlockReq *req,MultiReqBuffer *mrb) {uint32_t type; +uint32_t flags;struct iovec *in_iov = req->elem.in_sg;struct iovec *out_iov = req->elem.out_sg;unsigned in_num = req->elem.in_num;
@@ -931,6 +946,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) &req->inhdr_undo); type =virtio_ldl_p (vdev, &req->out.type); + flags =virtio_ldl_p (vdev, &VIRTIO_BLK_OUTDHR_FLAGS (req->out));/* VIRTIO_BLK_T_OUT defines the command direction. VIRTIO_BLK_T_BARRIER * is an optional flag. Although a guest should not send this flag if
@@ -939,6 +955,9 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)case VIRTIO_BLK_T_IN : {bool is_write = type &VIRTIO_BLK_T_OUT ; +bool is_fua = is_write && +virtio_vdev_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA ) && + (flags & (1U <<VIRTIO_BLK_REQ_FLAG_OUT_FUA )); req->sector_num =virtio_ldq_p (vdev, &req->out.sector);if (is_write) {
@@ -975,6 +994,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)* changes */ if (mrb->num_reqs >0 && (mrb->num_reqs ==VIRTIO_BLK_MAX_MERGE_REQS || is_write != mrb->is_write || + is_fua != mrb->is_fua || !s->conf.request_merging)) {virtio_blk_submit_multireq (s, mrb); }
@@ -982,6 +1002,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)assert (mrb->num_reqs <VIRTIO_BLK_MAX_MERGE_REQS ); mrb->reqs[mrb->num_reqs++] = req; mrb->is_write = is_write; + mrb->is_fua = is_fua;break ; }case VIRTIO_BLK_T_FLUSH :
@@ -1363,6 +1384,10 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,/* Firstly sync all virtio-blk possible supported features */ features |= s->host_features; +if (virtio_has_feature (features,VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA )) { +virtio_add_feature (&features,VIRTIO_BLK_F_REQ_FLAGS ); + } +virtio_add_feature (&features,VIRTIO_BLK_F_SEG_MAX );virtio_add_feature (&features,VIRTIO_BLK_F_GEOMETRY );virtio_add_feature (&features,VIRTIO_BLK_F_TOPOLOGY );
@@ -1388,6 +1413,15 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,return features; } +static int virtio_blk_validate_features (VirtIODevice *vdev) +{ +if (virtio_vdev_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA ) && + !virtio_vdev_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS )) { +return -EINVAL ; + } +return 0 ; +} +static int virtio_blk_set_status (VirtIODevice *vdev,uint8_t status) {VirtIOBlock *s =VIRTIO_BLK (vdev);
@@ -2043,6 +2077,8 @@ static const Property virtio_blk_properties[] = { conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS),DEFINE_PROP_UINT32 ("max-write-zeroes-sectors" , VirtIOBlock, conf.max_write_zeroes_sectors,BDRV_REQUEST_MAX_SECTORS ), +DEFINE_PROP_BIT64 ("fua" , VirtIOBlock, host_features, + VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA, true),/* * Zero is valid, and says that the device does not support zone append, * as a ZBC or ZAC disk does not.
@@ -2066,6 +2102,7 @@ static void virtio_blk_class_init(ObjectClass *klass, const void *data) vdc->get_config = virtio_blk_update_config; vdc->set_config = virtio_blk_set_config; vdc->get_features = virtio_blk_get_features; + vdc->validate_features = virtio_blk_validate_features; vdc->set_status = virtio_blk_set_status; vdc->reset = virtio_blk_reset; vdc->save = virtio_blk_save_device;
hw/core/machine.c +1 -0
@@ -44,6 +44,7 @@ GlobalProperty hw_compat_11_1[] = { { "sysbus-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, { "pcie-root-port", "speed", "16" }, + { "virtio-blk-device", "fua", "off" }, };const size_t hw_compat_11_1_len =G_N_ELEMENTS (hw_compat_11_1);
hw/virtio/virtio-qmp.c +10 -0
@@ -33,6 +33,12 @@#include "standard-headers/linux/virtio_vsock.h" #include "standard-headers/linux/virtio_gpio.h" +/* TODO Remove once the Linux headers have caught up */ +#ifndef VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA +#define VIRTIO_BLK_F_REQ_FLAGS 18/* Request flags supported */ +#define VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA 19/* FUA flag supported */ +#endif +#define FEATURE_ENTRY (name, desc) (qmp_virtio_feature_map_t) \ { .virtio_bit = name, .feature_desc = desc }
@@ -171,6 +177,10 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = { "VIRTIO_BLK_F_SECURE_ERASE: Secure erase supported"),FEATURE_ENTRY (VIRTIO_BLK_F_ZONED , \"VIRTIO_BLK_F_ZONED: Zoned block devices" ), +FEATURE_ENTRY (VIRTIO_BLK_F_REQ_FLAGS , \ +"VIRTIO_BLK_F_REQ_FLAGS: Request flags supported" ), +FEATURE_ENTRY (VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA , \ +"VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA: FUA flag for OUT requests" ),FEATURE_ENTRY (VIRTIO_BLK_F_BARRIER , \"VIRTIO_BLK_F_BARRIER: Request barriers supported" ), FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
Signature · 1 line
2.56.0
[PULL 08/17] iotests/041: add tests for mirroring below throttle node
In reply to Kevin WolfFrom: Fiona Ebner <[email protected]>
Test mirror with a non-root node as a source. This restriction was dropped with commit "blockdev: mirror: do not require a root block node".
Message-ID: <[email protected]>
--- tests/qemu-iotests/041 | 40 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 42 insertions(+), 2 deletions(-)
tests/qemu-iotests/041 +40 -0
@@ -1434,10 +1434,19 @@ class TestThrottle(iotests.QMPTestCase): bus='vio-scsi.0', drive='throttle') + self.drive_qdev = '/machine/peripheral/virtio' + def tearDown(self): os.remove(test_img) os.remove(target_img) + def blockstats(self, device): + result = self.vm.qmp("query-blockstats") + for r in result['return']: + if r['node-name'] == device: + return r['stats'] + raise Exception(f'Device {device} not found when querying blockstats') + def test_throttled(self): self.mirror_command('throttle')
@@ -1451,6 +1460,37 @@ class TestThrottle(iotests.QMPTestCase): self.assertTrue(iotests.compare_images(test_img, target_img), 'target image does not match source after mirroring') + def test_below_throttle(self): + self.mirror_command('source') + + # The throttling above should not block the mirror from completing. + self.complete_and_wait('mirror') + self.vm.shutdown() + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirroring') + + def test_below_throttle_with_io_on_throttle(self): + self.mirror_command('source') + + reqs = 3 + req_len = 1 * 1024 + + for i in range(0, reqs): + req = f'aio_write -P 7 {i}M {req_len}' + self.vm.hmp_qemu_io(self.drive_qdev, req, qdev=True) + + self.wait_ready('mirror') + # The throttle node above should still have in-flight requests. + assert self.blockstats('throttle')['wr_bytes'] <= 1 * req_len + + self.complete_and_wait('mirror', wait_ready=False) + assert self.blockstats('throttle')['wr_bytes'] == reqs * req_len + self.vm.shutdown() + # The throttle node above is drained too when the mirror finishes, so + # the images should match. + self.assertTrue(iotests.compare_images(test_img, target_img), + 'target image does not match source after mirroring') + class TestThrottleDriveMirror(TestThrottle): attachTargetImage = False
tests/qemu-iotests/041.out +2 -2
@@ -1,5 +1,5 @@ -............................................................................................................. +................................................................................................................. ---------------------------------------------------------------------- -Ran 109 tests +Ran 113 tests OK
Signature · 1 line
2.56.0
[PULL 05/17] util/coroutine: Reduce default idle pool max size
In reply to Kevin WolfFrom: Wesley Hershberger <[email protected]>
If g_file_get_contents fails (AppArmor, etc), use a more conservative default max size for the idle coroutine pool.
This avoids any possibility of the failure described in 86a637e48104 unless the host kernel is configured with a lower-than-default vm.max_map_count.
This change is motivated by a discussion of backport risk:
https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2168803/comments/8
Message-ID: <[email protected]>
--- util/qemu-coroutine.c | 73 +++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 27 deletions(-)
util/qemu-coroutine.c +46 -27
@@ -361,42 +361,61 @@ void qemu_coroutine_dec_pool_size(unsigned int removing_pool_size) global_pool_max_size -= removing_pool_size; } -static unsigned int get_global_pool_hard_max_size (void ) -{#ifdef __linux__ - g_autofree char *contents = NULL; -int max_map_count; +/* +* include/linux/mm.h +*/ +#define DEFAULT_MAX_MAP_COUNT 65530 -/* -* Linux processes can have up to max_map_count virtual memory areas -* (VMAs). mmap(2), mprotect(2), etc fail with ENOMEM beyond this limit. We -* must limit the coroutine pool to a safe size to avoid running out of -* VMAs. -*/ -if (g_file_get_contents ("/proc/sys/vm/max_map_count" , &contents,NULL , -NULL )) { +static unsigned int get_max_map_count (void ) +{ + g_autofree char *contents = NULL; +unsigned int max_map_count =0 ; +if (g_file_get_contents ("/proc/sys/vm/max_map_count" , &contents, +NULL ,NULL )) {/* contents has trailing newline, remove it before conversion */ g_strchomp (contents); -if (qemu_strtoi (contents,NULL ,10 , &max_map_count) !=0 ) { -return UINT_MAX ; - } -/* -* This is an upper bound that avoids exceeding max_map_count. Leave a -* fixed amount for non-coroutine users like library dependencies, -* vhost-user, etc. Each coroutine takes up 2 VMAs so halve the -* remaining amount. -*/ -if (max_map_count >5000 ) { -return (max_map_count -5000 ) /2 ; - }else { -/* Disable the global pool but threads still have local pools */ -return 0 ; +if (qemu_strtoui (contents,NULL ,10 , &max_map_count) ==0 ) { +return max_map_count; } } -#endif +/* +* Read from /proc might fail due to mandatory access control (AppArmor, +* SELinux, etc). Use the kernel's default in that case. +*/ +return DEFAULT_MAX_MAP_COUNT ; +} + +/* +* Linux processes can have up to max_map_count virtual memory areas +* (VMAs). mmap(2), mprotect(2), etc fail with ENOMEM beyond this limit. We +* must limit the coroutine pool to a safe size to avoid running out of +* VMAs. +*/ +static unsigned int get_global_pool_hard_max_size (void ) +{ +unsigned int max_map_count =get_max_map_count (); + +/* +* This is an upper bound that avoids exceeding max_map_count. Leave a +* fixed amount for non-coroutine users like library dependencies, +* vhost-user, etc. Each coroutine takes up 2 VMAs so halve the +* remaining amount. +*/ +if (max_map_count >5000 ) { +return (max_map_count -5000 ) /2 ; + }else { +/* Disable the global pool but threads still have local pools */ +return 0 ; + } +} +#else +static unsigned int get_global_pool_hard_max_size (void ) +{return UINT_MAX ; } +#endif static void __attribute__((constructor))qemu_coroutine_init (void ) {
Signature · 1 line
2.56.0
[PULL 04/17] util/coroutine: trim sysctl's max_map_count newline before parsing
In reply to Kevin WolfFrom: Hector Cao <[email protected]>
Strip trailing whitespace from max_map_count before passing it to qemu_strtoi(), allowing the strict full-string parse to succeed. Otherwise, qemu_strtoi() fails to parse the string and returns -22, making the global cache pool cap size set to UINT_MAX.
Message-ID: <[email protected]>
--- util/qemu-coroutine.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
util/qemu-coroutine.c +6 -2
@@ -374,8 +374,12 @@ static unsigned int get_global_pool_hard_max_size(void)* VMAs. */ if (g_file_get_contents ("/proc/sys/vm/max_map_count" , &contents,NULL , -NULL ) && -qemu_strtoi (contents,NULL ,10 , &max_map_count) ==0 ) { +NULL )) { +/* contents has trailing newline, remove it before conversion */ +g_strchomp (contents); +if (qemu_strtoi (contents,NULL ,10 , &max_map_count) !=0 ) { +return UINT_MAX ; + }/* * This is an upper bound that avoids exceeding max_map_count. Leave a * fixed amount for non-coroutine users like library dependencies,
Signature · 1 line
2.56.0
[PULL 09/17] file-posix: Add 'accept-read-only-device' option
In reply to Kevin WolfThe host_device block driver refuses to open a block device read-write if the BLKROGET ioctl tells it that it's actually read-only. For such devices it's possible to open a read-write file descriptor, but any writes to the device would fail.
There are valid use cases for which this check gets in the way, as explained in the bug report:
However, this behavior prevents a legitimate enterprise use case:
running VMs against storage replication target LUNs in a disaster recovery configuration. Enterprise storage arrays (Dell Powermax, Pure Storage) set the SCSI Write Protect bit on replication target LUNs, causing the Linux kernel to mark them read-only via BLKROGET. The VMs on the passive DR site need to start with these LUNs attached - writes are expected to fail (the application middleware knows it's on the passive side), and after a DR role swap the LUN becomes writable and writes should succeed immediately without any VM restart.
In order to allow such use cases in which a currently read-only device is deliberately opened read-write, add a new option to the host_device driver that allows the user to skip the check.
Message-ID: <[email protected]>
--- qapi/block-core.json | 19 ++++++++++++++++++- block/file-posix.c | 23 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-)
qapi/block-core.json +18 -1
@@ -3390,6 +3390,23 @@ 'features': [ { 'name': 'dynamic-auto-read-only', 'if': 'CONFIG_POSIX' } ] } +## +# @BlockdevOptionsHostDevice: +# Driver specific block device options for the host_device +# backend. +# +# @accept-read-only-device: allow opening a read-only device as +# read-write. If this is false, opening a host device read-write +# requires on Linux that the BLKROGET ioctl considers the device +# writable. If it is true, this check is skipped. (since: 11.2, +# default: false) +# +# Since: 11.2 +## +{ 'struct': 'BlockdevOptionsHostDevice', + 'base': 'BlockdevOptionsFile', + 'data': { '*accept-read-only-device': 'bool' } } + ## # @BlockdevOptionsNull: # Driver specific block device options for the null backend.
@@ -4777,7 +4794,7 @@ 'ftps': 'BlockdevOptionsCurlFtps', 'host_cdrom': { 'type': 'BlockdevOptionsFile', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, - 'host_device': { 'type': 'BlockdevOptionsFile', + 'host_device': { 'type': 'BlockdevOptionsHostDevice', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, 'http': 'BlockdevOptionsCurlHttp', 'https': 'BlockdevOptionsCurlHttps',
block/file-posix.c +20 -3
@@ -177,6 +177,7 @@ typedef struct BDRVRawState { bool has_laio_fdsync:1; bool use_linux_io_uring:1; bool use_mpath:1; + bool accept_read_only_device:1;int page_cache_inconsistent;/* errno from fdatasync failure */ bool has_fallocate;bool needs_alignment;
@@ -513,7 +514,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) } } -static int check_hdev_writable (int fd) +static int check_hdev_writable (BlockDriverState *bs,int fd) {#if defined(BLKROGET )/* Linux block devices can be configured "read-only" using blockdev(8).
@@ -523,10 +524,19 @@ static int check_hdev_writable(int fd)* bdrv_open() is supposed to fail if the disk is read-only. Explicitly * check for read-only block devices so that Linux block devices behave * properly. +* +* Users can use the accept-read-only-device option to skip the check if +* they deliberately open a read-only block device as writable, e.g. because +* it may become read-write later. */ +BDRVRawState *s = bs->opaque;struct stat st;int readonly =0 ; +if (s->accept_read_only_device) { +return 0 ; + } +if (fstat (fd, &st)) {return -errno; }
@@ -620,6 +630,11 @@ static QemuOptsList raw_runtime_opts = { .type = QEMU_OPT_BOOL, .help = "check that page cache was dropped on live migration (default: off)" }, + { + .name = "accept-read-only-device", + .type = QEMU_OPT_BOOL, + .help = "allow opening a read-only device as read-write (default: off)" + }, {/* end of list */ } }, };
@@ -737,8 +752,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, s->fd = fd;/* Check s->open_flags rather than bdrv_flags due to auto-read-only */ + s->accept_read_only_device = +qemu_opt_get_bool (opts,"accept-read-only-device" , false);if (s->open_flags &O_RDWR ) { - ret =check_hdev_writable (s->fd); + ret =check_hdev_writable (bs, s->fd);if (ret <0 ) {error_setg_errno (errp, -ret,"The device is not writable" ); goto fail;
@@ -1116,7 +1133,7 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags, }if (fd !=-1 && (*open_flags &O_RDWR )) { - ret =check_hdev_writable (fd); + ret =check_hdev_writable (bs, fd);if (ret <0 ) {qemu_close (fd);error_setg_errno (errp, -ret,"The device is not writable" );
Signature · 1 line
2.56.0
[PULL 10/17] iotests: Add loop-accept-ro-dev test
In reply to Kevin WolfAdd a test for the accept-read-only-device option of host_device.
Message-ID: <[email protected]>
--- tests/qemu-iotests/tests/loop-accept-ro-dev | 88 +++++++++++++++++++ .../qemu-iotests/tests/loop-accept-ro-dev.out | 19 ++++ 2 files changed, 107 insertions(+) create mode 100755 tests/qemu-iotests/tests/loop-accept-ro-dev create mode 100644 tests/qemu-iotests/tests/loop-accept-ro-dev.out
tests/qemu-iotests/tests/loop-accept-ro-dev new file +88 -0
@@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# group: quick +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright Red Hat, Inc. +# +# Test the accept-read-only-device option on a loop device + +seq="$(basename $0)" +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() { + if [ -n "$loopdev" ]; then + sudo losetup --detach "$loopdev" + fi + + _cleanup_test_img +} + +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +cd .. +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -nodefaults "$@" + echo +} + +run_qemu() +{ + printf '{"execute":"qmp_capabilities"}\n{"execute":"quit"}' | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | + _filter_generated_node_ids | _filter_imgfmt | + _filter_actual_image_size | _filter_img_info | + sed -e "s#/dev/loop[0-9]\\+#LOOPDEV#g" +} + +if ! sudo -n losetup &>/dev/null; then + _notrun "sudo losetup not available" +fi + +if ! command -v blockdev >/dev/null 2>&1; then + _notrun "blockdev tool not available" +fi + +echo +echo "=== Start QEMU on a loop device after blockdev --setro ===" +echo + +_make_test_img -f $IMGFMT 1M + +loopdev=$(sudo losetup --find --show "$TEST_IMG") +if [ -z "$loopdev" ]; then + _fail +fi + +sudo blockdev --setro "$loopdev" +sudo chmod a+rw "$loopdev" + +run_qemu \ + -blockdev host_device,node-name=disk,filename="$loopdev" \ + -device virtio-blk,drive=disk + +run_qemu \ + -blockdev host_device,node-name=disk,filename="$loopdev",accept-read-only-device=off \ + -device virtio-blk,drive=disk + +run_qemu \ + -blockdev host_device,node-name=disk,filename="$loopdev",accept-read-only-device=on \ + -device virtio-blk,drive=disk + +# success, all done +echo +echo '*** done' +rm -f $seq.full +status=0
tests/qemu-iotests/tests/loop-accept-ro-dev.out new file +19 -0
@@ -0,0 +1,19 @@ +QA output created by loop-accept-ro-dev + +=== Start QEMU on a loop device after blockdev --setro === + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +Testing: -blockdev host_device,node-name=disk,filename=LOOPDEV -device virtio-blk,drive=disk +QEMU_PROG: -blockdev host_device,node-name=disk,filename=LOOPDEV: The device is not writable: Permission denied + +Testing: -blockdev host_device,node-name=disk,filename=LOOPDEV,accept-read-only-device=off -device virtio-blk,drive=disk +QEMU_PROG: -blockdev host_device,node-name=disk,filename=LOOPDEV,accept-read-only-device=off: The device is not writable: Permission denied + +Testing: -blockdev host_device,node-name=disk,filename=LOOPDEV,accept-read-only-device=on -device virtio-blk,drive=disk +QMP_VERSION +{"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} +{"return": {}} + + +*** done
Signature · 1 line
2.56.0
[PULL 13/17] block: fix leak of block histogram data
In reply to Kevin WolfFrom: Daniel P. Berrangé <[email protected]>
The block_acct_cleanup method failed to release memory associated with block histograms.
Message-ID: <[email protected]>
--- block/accounting.c | 2 ++ 1 file changed, 2 insertions(+)
block/accounting.c +2 -0
@@ -80,6 +80,8 @@ bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,void block_acct_cleanup (BlockAcctStats *stats) {BlockAcctTimedStats *s, *next; +block_latency_histograms_clear (stats); + QSLIST_FOREACH_SAFE(s, &stats->intervals, entries, next) {g_free (s); }
Signature · 1 line
2.56.0
[PULL 15/17] block/vmdk: Don't preallocate full 64k for compressed data grains
In reply to Kevin WolfFrom: Sanne Raymaekers <[email protected]>
For stream optimized disks the spec notes: "Each marker and its associated block begin on a sector or 512‐byte boundary... There are five types of markers: compressed grain markers,..." [^1]
This means that instead of pre-zeroing grains with their typical size (64K), in stream optimized disks, only the real size of the compressed grains should be written. Writing zeroes is not necessary and wasted work, though usually the zeros are immediately overwritten with the next compressed clusters and nothing is lost; near the end of the image, it could mean that the image became larger than expected.
[^1] Virtual Disk Format 5.0 Technical Note.
Message-ID: <[email protected]>
--- block/vmdk.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
block/vmdk.c +18 -9
@@ -1730,16 +1730,25 @@ get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, cluster_sector = extent->next_cluster_sector; extent->next_cluster_sector += extent->cluster_sectors; -/* First of all we write grain itself, to avoid race condition -* that may to corrupt the image. -* This problem may occur because of insufficient space on host disk -* or inappropriate VM shutdown. +/* +* Stream optimized (compressed) extents do not have to be +* pre-allocated, as compressed writes always cover the whole +* cluster, and will align on 512 byte chunks. */ - ret =get_whole_cluster (bs, extent, cluster_sector *BDRV_SECTOR_SIZE , - offset, skip_start_bytes, skip_end_bytes, - zeroed); -if (ret) { -return ret; +if (!extent->compressed) { +/* +* First of all we write grain itself, to avoid race condition +* that may to corrupt the image. +* This problem may occur because of insufficient space on host disk +* or inappropriate VM shutdown. +*/ + ret =get_whole_cluster (bs, extent, + cluster_sector *BDRV_SECTOR_SIZE , + offset, skip_start_bytes, skip_end_bytes, + zeroed); +if (ret) { +return ret; + } }if (m_data) { m_data->new_allocation = true;
Signature · 1 line
2.56.0
[PULL 16/17] block/vmdk: skip RGD for stream optimized disks
In reply to Kevin WolfFrom: Sanne Raymaekers <[email protected]>
For stream optimized disks the spec notes: "The rgdOffset should be ignored because bit 1 of the flags field is not set." Where bit 1 of the flags field indicates a redundant grain directory (RGD).[^1]
In short, stream optimized disks should have the RGD offset set to 0, and only write the main grain directory.
This patch also corrects the comments around the code writing the grain directories, and it makes the error thrown when it fails to write the backup grain directory more explicit.
[^1] Virtual Disk Format 5.0 Technical Note.
Message-ID: <[email protected]>
--- block/vmdk.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-)
block/vmdk.c +30 -16
@@ -2246,8 +2246,9 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress, }else { header.version =1 ; } - header.flags =VMDK4_FLAG_RGD |VMDK4_FLAG_NL_DETECT - | (compress ?VMDK4_FLAG_COMPRESS |VMDK4_FLAG_MARKER :0 ) + header.flags =VMDK4_FLAG_NL_DETECT + | (compress ? +VMDK4_FLAG_COMPRESS |VMDK4_FLAG_MARKER :VMDK4_FLAG_RGD ) | (zeroed_grain ?VMDK4_FLAG_ZERO_GRAIN :0 ); header.compressAlgorithm = compress ?VMDK4_COMPRESSION_DEFLATE :0 ; header.capacity = filesize /BDRV_SECTOR_SIZE ;
@@ -2262,8 +2263,16 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress, header.desc_offset =1 ; header.desc_size =20 ; - header.rgd_offset = header.desc_offset + header.desc_size; - header.gd_offset = header.rgd_offset + gd_sectors + (gt_size * gt_count); + +if (compress) { + header.rgd_offset =0 ; + header.gd_offset = header.desc_offset + header.desc_size; + }else { + header.rgd_offset = header.desc_offset + header.desc_size; + header.gd_offset = + header.rgd_offset + gd_sectors + (gt_size * gt_count); + } + header.grain_offset =ROUND_UP (header.gd_offset + gd_sectors + (gt_size * gt_count), header.granularity);
@@ -2303,21 +2312,26 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress, goto exit; } -/* write grain directory */ +/* write backup grain directory */ gd_buf_size = gd_sectors *BDRV_SECTOR_SIZE ; gd_buf =g_malloc0 (gd_buf_size); -for (i =0 , tmp =le64_to_cpu (header.rgd_offset) + gd_sectors; - i < gt_count; i++, tmp += gt_size) { - gd_buf[i] =cpu_to_le32 (tmp); - } - ret =blk_co_pwrite (blk,le64_to_cpu (header.rgd_offset) *BDRV_SECTOR_SIZE , - gd_buf_size, gd_buf,0 ); -if (ret <0 ) { -error_setg_errno (errp, -ret,"failed to write VMDK grain directory" ); - goto exit; + +if (!compress) { +for (i =0 , tmp =le64_to_cpu (header.rgd_offset) + gd_sectors; + i < gt_count; i++, tmp += gt_size) { + gd_buf[i] =cpu_to_le32 (tmp); + } + ret =blk_co_pwrite (blk, +le64_to_cpu (header.rgd_offset) *BDRV_SECTOR_SIZE , + gd_buf_size, gd_buf,0 ); +if (ret <0 ) { +error_setg_errno (errp, -ret, +"failed to write VMDK backup grain directory" ); + goto exit; + } } -/* write backup grain directory */ +/* write grain directory */ for (i =0 , tmp =le64_to_cpu (header.gd_offset) + gd_sectors; i < gt_count; i++, tmp += gt_size) { gd_buf[i] =cpu_to_le32 (tmp);
@@ -2326,7 +2340,7 @@ vmdk_init_extent(BlockBackend *blk, int64_t filesize, bool flat, bool compress, gd_buf_size, gd_buf, 0);if (ret <0 ) {error_setg_errno (errp, -ret, -"failed to write VMDK backup grain directory" ); +"failed to write VMDK grain directory" ); } ret =0 ;
Signature · 1 line
2.56.0
[PULL 02/17] block: Print simple help text when calling "-blockdev help"
In reply to Kevin WolfFrom: Thomas Huth <[email protected]>
Other command line options like "-chardev", "-netdev" or "-device" already present the user with a list of available parameters, but when running "-blockdev help", there is currently only an error message. There is already the possibility to run "-drive format=help", but it does not seem to be documented, so this is not very useful for the average user. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".
Message-ID: <[email protected]>
--- include/block/block-common.h | 1 + block.c | 15 +++++++++++++++ system/vl.c | 7 +++++-- 3 files changed, 21 insertions(+), 2 deletions(-)
include/block/block-common.h +1 -0
@@ -583,5 +583,6 @@ char *path_combine(const char *base_path, const char *filename);char *bdrv_get_full_backing_filename_from_filename (const char *backed,const char *backing,Error **errp); +void bdrv_show_help (void );#endif /* BLOCK_COMMON_H */
block.c +15 -0
@@ -524,6 +524,21 @@ bool bdrv_uses_whitelist(void)return use_bdrv_whitelist; } +static void bdrv_help_format_print (void *opaque,const char *name) +{ +if (bdrv_format_is_whitelisted (name, false)) { +printf ("%s\n" , name); + }else { +printf ("%s (read-only)\n" , name); + } +} + +void bdrv_show_help (void ) +{ +printf ("Available blockdev drivers:\n" ); +bdrv_iterate_format (bdrv_help_format_print,NULL , true); +} + typedef struct CreateCo { BlockDriver *drv; char *filename;
system/vl.c +5 -2
@@ -2975,7 +2975,10 @@ void qemu_init(int argc, char **argv) HD_OPTS);break ;case QEMU_OPTION_blockdev: - { +if (is_help_option (optarg)) { +bdrv_show_help (); +exit (EXIT_SUCCESS ); + }else {Visitor *v;BlockdevOptionsQueueEntry *bdo;
@@ -2988,8 +2991,8 @@ void qemu_init(int argc, char **argv)visit_free (v);loc_save (&bdo->loc);QSIMPLEQ_INSERT_TAIL (&bdo_queue, bdo, entry); -break ; } +break ;case QEMU_OPTION_drive:if (!qemu_opts_parse_noisily (qemu_find_opts ("drive" ), optarg, false)) {
Signature · 1 line
2.56.0
[PULL 14/17] qemu-pr-helper: do not free reply when multipath_process_cmd() fails
In reply to Kevin WolfFrom: Stefan Hajnoczi <[email protected]>
Kevin Wolf pointed out that the multipath_process_cmd() documentation only defines the value of reply on success. Don't touch it when the function returns -1.
The libmpathcmd implementation as of c78cf64a9e8e does not set *reply to NULL when its internal mpath_send_cmd() call fails, so I think Kevin's interpretation is correct.
As it stands, there is no observable bug in the QEMU code though because reply is initialized to NULL before calling multipath_process_cmd(). This patch is just a cleanup.
Message-ID: <[email protected]>
--- scsi/qemu-pr-helper.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
scsi/qemu-pr-helper.c +8 -3
@@ -559,7 +559,7 @@ static char *get_dm_name(int fd, Error **errp)static bool multipathd_cmd (int fd,const char *cmd,Error **errp) {const unsigned int timeout_ms =60000 ; -char *reply =NULL ; + g_autofree char *reply = NULL;int last_errno;int ret;
@@ -568,11 +568,16 @@ static bool multipathd_cmd(int fd, const char *cmd, Error **errp)if (reply &&strcmp (reply,"ok\n" ) !=0 ) {error_setg (errp,"mpath_process_cmd(%d, \"%s\") replied \"%s\"" , fd, cmd, reply); -free (reply);return false; } -free (reply);if (ret ==-1 ) { +/* +* It should already be NULL but the mpath_process_cmd() documentation +* only defines it when the function returns success, so don't depend +* on its value when ret == -1. +*/ + reply =NULL ; +error_setg_errno (errp, last_errno,"mpath_process_cmd(%d, \"%s\") failed" , fd, cmd);
Signature · 1 line
2.56.0
[PULL 01/17] tests/qtest/fdc-test: check block accounting of non-DMA reads
In reply to Kevin WolfFrom: Christian Quante <[email protected]>
Since commit 9c4c09d2a663 ("hw/block/fdc: account for read and write requests"), the floppy reports its reads and writes in query-blockstats. Check this for the existing non-DMA reads: send_read_no_dma_command() now compares rd_operations and rd_bytes before and after the command, one 512-byte request for every sector the test reads through the FIFO.
Without the accounting, read_no_dma_1, read_no_dma_18 and read_no_dma_19 fail with rd_operations at 0 instead of 2, 36 and 38.
Message-ID: <[email protected]>
--- tests/qtest/fdc-test.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
tests/qtest/fdc-test.c +42 -0
@@ -27,6 +27,7 @@#include "libqtest-single.h" #include "qobject/qdict.h" +#include "qobject/qlist.h" #define DRIVE_FLOPPY_BLANK \ "-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k"
@@ -177,6 +178,34 @@ static uint8_t send_read_command(uint8_t cmd)return ret; } +/* Returns a counter that query-blockstats reports for floppy0 */ +static int64_t floppy_blockstat (const char *counter) +{ +QDict *response; +QList *list; +QListEntry *entry; +QDict *stats =NULL ; +int64_t value; + + response =qtest_qmp (global_qtest,"{'execute': 'query-blockstats'}" ); +g_assert (response &&qdict_haskey (response,"return" )); + list =qdict_get_qlist (response,"return" ); + + QLIST_FOREACH_ENTRY(list, entry) { +QDict *entry_dict =qobject_to (QDict, entry->value); + +if (!g_strcmp0 (qdict_get_try_str (entry_dict,"qdev" ),"floppy0" )) { + stats =qdict_get_qdict (entry_dict,"stats" ); +break ; + } + } + +g_assert (stats); + value =qdict_get_int (stats, counter); +qobject_unref (response); +return value; +} +static uint8_t send_read_no_dma_command (int nb_sect,uint8_t expected_st0) {uint8_t drive =0 ;
@@ -193,6 +222,9 @@ static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0)uint8_t ret =0 ; +int64_t rd_ops_before =floppy_blockstat ("rd_operations" ); +int64_t rd_bytes_before =floppy_blockstat ("rd_bytes" ); +floppy_send (CMD_READ );floppy_send (head <<2 | drive);g_assert (!get_irq (FLOPPY_IRQ ));
@@ -248,6 +280,16 @@ static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0)assert_bit_set (msr,RQM );g_assert (!get_irq (FLOPPY_IRQ )); +/* +* The non-DMA loop above has read 2 * nb_sect sectors through the FIFO, +* and the controller fetches each of them from the image with a request +* of its own. +*/ + g_assert_cmpint(floppy_blockstat("rd_operations") - rd_ops_before, ==, +2 * nb_sect); + g_assert_cmpint(floppy_blockstat("rd_bytes") - rd_bytes_before, ==, +512 *2 * nb_sect); +return ret; }
Signature · 1 line
2.56.0
[PULL 17/17] block/vmdk: add eos marker for stream optimized disks
In reply to Kevin WolfFrom: Sanne Raymaekers <[email protected]>
The end of stream marker should be at the very end of a stream optimized disk. It consists of a regular marker struct with val, size and type set to 0. It is then padded with more 0s to fill out a sector. This effectively results in 512 zero bytes.[^1]
[^1] Virtual Disk Format 5.0 Technical Note.
Message-ID: <[email protected]>
--- block/vmdk.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-)
block/vmdk.c +28 -20
@@ -195,6 +195,13 @@ typedef struct VmdkGrainMarker {uint8_t data[]; }QEMU_PACKED VmdkGrainMarker; +typedef struct EosMarker { +uint64_t val; +uint32_t size; +uint32_t type; +uint8_t pad[512 -16 ]; +} QEMU_PACKED EosMarker; +enum {MARKER_END_OF_STREAM =0 ,MARKER_GRAIN_TABLE =1 ,
@@ -987,12 +994,7 @@ vmdk_open_vmdk4(BlockDriverState *bs, BdrvChild *file, int flags,VMDK4Header header;uint8_t pad[512 -4 -sizeof (VMDK4Header)]; -struct { -uint64_t val; -uint32_t size; -uint32_t type; -uint8_t pad[512 -16 ]; - } QEMU_PACKED eos_marker; +EosMarker eos_marker; }QEMU_PACKED footer; ret = bdrv_pread(file, bs->file->bs->total_sectors * 512 - 1536,
@@ -2182,23 +2184,29 @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov) {if (bytes ==0 ) { -/* The caller will write bytes 0 to signal EOF. -* When receive it, we align EOF to a sector boundary. */ +/* The caller will write bytes 0 to signal EOF. */ BDRVVmdkState *s = bs->opaque; -int i, ret; +int ret;int64_t length; + QEMU_AUTO_VFREE EosMarker *eos_marker = NULL; -for (i =0 ; i < s->num_extents; i++) { - length =bdrv_co_getlength (s->extents[i].file->bs); -if (length <0 ) { -return length; - } - length =QEMU_ALIGN_UP (length,BDRV_SECTOR_SIZE ); - ret =bdrv_co_truncate (s->extents[i].file, length, false, -PREALLOC_MODE_OFF ,0 ,NULL ); -if (ret <0 ) { -return ret; - } +/* Stream optimized disks should only contain a single extent. */ +assert (s->num_extents ==1 ); + +/* +* Stream optimized disks end with an EOS marker, +* consisting of 512 null bytes. +*/ + eos_marker =qemu_blockalign0 (bs,sizeof (EosMarker)); + length =bdrv_co_getlength (s->extents[0 ].file->bs); +if (length <0 ) { +return length; + } + length =QEMU_ALIGN_UP (length,BDRV_SECTOR_SIZE ); + ret =bdrv_co_pwrite (s->extents[0 ].file, length,sizeof (EosMarker), + eos_marker,0 ); +if (ret <0 ) { +return ret; }return 0 ; }
Signature · 1 line
2.56.0
[PULL 03/17] qemu-nbd: Add --all-bitmaps option
In reply to Kevin WolfFrom: Eric Blake <[email protected]>
When exporting bitmaps over NBD, we previously required a user to pass one '-B name' per bitmap, which they would have to use 'qemu-img info' to learn the list of names to pass. More convenient is an option to export all possible bitmaps at once, as discussed here [1].
Implementation-wise, mixing --all-bitmaps and -B is harmless (grabbing all bitmap names already requires crawling the backing chain and deduplicating, so either the -B name is already detected as a duplicate from adding the name again, or it is an invalid name that will still cause a later error about bitmap not found). I also tested that mixing -s and --all-bitmaps still works (the temporary overlay image to make -s work has no bitmaps of its own, so starting the crawl for bitmap names at the original bs is just fine).
Also, now that parallels can have bitmaps (and not just qcow2), a slight doc wording change for -B is warranted.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2026-10/msg01234.html
Message-ID: <[email protected]>
--- docs/tools/qemu-nbd.rst | 12 +++- qemu-nbd.c | 57 ++++++++++++++++++- tests/qemu-iotests/tests/qemu-img-bitmaps | 13 +++++ tests/qemu-iotests/tests/qemu-img-bitmaps.out | 12 ++++ 4 files changed, 90 insertions(+), 4 deletions(-)
docs/tools/qemu-nbd.rst +9 -3
@@ -83,9 +83,15 @@ driver options if :option:`--image-opts` is specified. .. option:: -B, --bitmap=NAME - If *filename* has a qcow2 persistent bitmap *NAME*, expose - that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata context - accessible through NBD_OPT_SET_META_CONTEXT. + If *filename* has a persistent bitmap *NAME* (possibly via a backing + chain), expose that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata + context accessible through NBD_OPT_SET_META_CONTEXT. + +.. option:: --all-bitmaps + + If *filename* has any persistent bitmaps (possibly via a backing + chain), expose one ``qemu:dirty-bitmap:NAME`` metadata context per + bitmap, accessible through NBD_OPT_SET_META_CONTEXT. .. option:: -s, --snapshot
qemu-nbd.c +56 -1
111 lines not on this page · raw message
tests/qemu-iotests/tests/qemu-img-bitmaps +13 -0
@@ -131,6 +131,19 @@ $QEMU_IMG map --output=json --image-opts \ nbd_server_stop +# Repeat with the --all-bitmaps option +nbd_server_start_unix_socket -r -f qcow2 --all-bitmaps "$TEST_IMG" +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map + +nbd_server_stop + echo echo "=== Check handling of inconsistent bitmap ===" echo
tests/qemu-iotests/tests/qemu-img-bitmaps.out +12 -0
@@ -103,6 +103,18 @@ Format specific information: === Check bitmap contents === +[{ "start": 0, "length": 3145728, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 3145728, "length": 1048576, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}, +{ "start": 4194304, "length": 6291456, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}] +[{ "start": 0, "length": 1048576, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 1048576, "length": 1048576, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}, +{ "start": 2097152, "length": 8388608, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}] +[{ "start": 0, "length": 2097152, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 2097152, "length": 1048576, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}, +{ "start": 3145728, "length": 7340032, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}] +[{ "start": 0, "length": 2097152, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, +{ "start": 2097152, "length": 1048576, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}, +{ "start": 3145728, "length": 7340032, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}] [{ "start": 0, "length": 3145728, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}, { "start": 3145728, "length": 1048576, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}, { "start": 4194304, "length": 6291456, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": OFFSET}]
Signature · 1 line
2.56.0
Richard Henderson
AppliedQuoted 15 lines · Kevin Wolf
The following changes since commit
56afd82bd4db9688f1c1c9d0e2ea163b8cde3283:Merge tag 'qemu-sparc-20261101' ofhttps://github.com/mcayland/qemu into staging (2026-11-01 08:37:48 -0800)are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to
6e641f2440aa637c670b7f0fe512ea3fc2611b99:block/vmdk: add eos marker for stream optimized disks (2026-11-02 17:06:37 +0100)
----------------------------------------------------------------
Block layer patches
Quoted 7 lines
- mirror: do not require a root block node
- file-posix: Add 'accept-read-only-device' option
- vmdk: Fixes for converting to streamOptimized
- virtio-blk: Add support for FUA write requests
- Print simple help text when calling "-blockdev help"
- qemu-nbd: Add --all-bitmaps option
- coroutine: Fix default idle pool max size on Linux
Applied, thanks.
r~