block: BLOCK_IO_DELAY event
Subsystems (2)
v2 cover block: BLOCK_IO_DELAY event
Hi,
v1: https://lists.nongnu.org/archive/html/qemu-block/2026-08/msg00701.html
I’m told there are installations where storage is very slow, and some would like the VM stack to report this proactively. To do so, we should (via QAPI events) report on extremely slow I/O requests.
We already have the latency histogram, but this is not deemed sufficient because it is not proactively reporting and would require repeated querying. Therefore, this series introduces the event still.
In contrast to v1, this version adds the delay tracking to the BlockBackend request code instead of using the existing cookies from block/accounting.c.
As explained in the v1 cover letter, in order to be able to raise a BLOCK_IO_DELAY event exactly when a request crosses the threshold, we need to keep requests in a list, which requires trivially verifiable resource management, i.e. trivially being able to see that every request that is begun being tracked (and thus put into that list) is also removed from that list once the request is done. This was not possible with the accounting cookies, so instead, as suggested by Stefan, this version adds its own tracking directly into the BB-level requests.
The downside is that accounting and delay tracking thus track different kinds of requests. If that is unacceptable, the only alternatives would be:
- To do it with cookies, which is basically impossible, as explained,
- To change the cookies to be tied to BB-level requests as well, which would (A) be an invasive code change, and (B) change the existing reporting in an incompatible way.
Personally, I found the divergence to be more acceptable than having a go at said invasive change, and having to defend the incompatible reporting change.
In addition to what v1 provides, with this threshold-level reporting, we can now also have the VM stop on exceedingly delayed requests, so the guest would not see that delay, as a last-ditch effort for guests that find extreme latencies to be catastrophic. (Which is to say Windows does that: It throws a BSOD when exceeding a certain maximum latency.)
Note patches 3 and 4 that might not really fully fit into this series; they fix a pre-existing bug around the runstate transitions between IO_ERROR and SUSPENDED. An AI review tool informed me that the transition between SUSPENDED and IO_HANG was missing in patch 5, but given that I had just copied what IO_ERROR does, I felt bad adding that transition for IO_HANG, but leaving IO_ERROR as it was.
git-backport-diff against v1 is not so useful here, I’m afraid:
Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/12:[down] 'qapi/common: Clarify what IoOperationType is for' 002/12:[0004] [FC] 'qapi/block: Add IoAccountingOperation enum' 003/12:[down] 'runstate: Allow IO_ERROR/SUSPENDED transitions' 004/12:[down] 'iotests: PC-only test for I/O errors during suspend' 005/12:[down] 'qapi/run-state: Add io-hang state' 006/12:[0017] [FC] 'qapi/block: Add BLOCK_IO_DELAY event' 007/12:[down] 'qapi/block: Add BLOCK_IO_DONE event' 008/12:[----] [--] 'block-backend: Public blk_get_attached_dev_path()' 009/12:[down] 'host-utils: Add u{add,sub}{32,64}_saturate()' 010/12:[down] 'block: Per-request delay tracker' 011/12:[down] 'block: Add delay-report-ns and delay-stop-ns props' 012/12:[down] 'iotests: Add io-delay-reporting test'
Hanna Czenczek (12):
qapi/common: Clarify what IoOperationType is for qapi/block: Add IoAccountingOperation enum
runstate: Allow IO_ERROR/SUSPENDED transitions
iotests: PC-only test for I/O errors during suspend qapi/run-state: Add io-hang state qapi/block: Add BLOCK_IO_DELAY event qapi/block: Add BLOCK_IO_DONE event
block-backend: Public blk_get_attached_dev_path()
host-utils: Add u{add,sub}{32,64}_saturate()
block: Per-request delay tracker
block: Add delay-report-ns and delay-stop-ns props
iotests: Add io-delay-reporting test
qapi/block.json | 90 +++++ qapi/common.json | 5 +- qapi/run-state.json | 7 +- include/block/block-backend-delay.h | 112 ++++++ include/hw/block/block.h | 8 +- include/qemu/host-utils.h | 62 ++++ include/system/block-backend-global-state.h | 11 + include/system/block-backend-io.h | 9 + block/block-backend-delay.c | 326 ++++++++++++++++++ block/block-backend.c | 50 ++- blockdev.c | 16 + hw/block/block.c | 7 + system/runstate.c | 27 +- block/meson.build | 1 + tests/qemu-iotests/172.out | 76 ++++ tests/qemu-iotests/tests/io-delay-reporting | 187 ++++++++++ .../qemu-iotests/tests/io-delay-reporting.out | 90 +++++ .../tests/io-error-during-suspend | 155 +++++++++ .../tests/io-error-during-suspend.out | 22 ++ 19 files changed, 1244 insertions(+), 17 deletions(-) create mode 100644 include/block/block-backend-delay.h create mode 100644 block/block-backend-delay.c create mode 100755 tests/qemu-iotests/tests/io-delay-reporting create mode 100644 tests/qemu-iotests/tests/io-delay-reporting.out create mode 100755 tests/qemu-iotests/tests/io-error-during-suspend create mode 100644 tests/qemu-iotests/tests/io-error-during-suspend.out
Signature · 1 line
2.55.0
PATCH v2 1/12 qapi/common: Clarify what IoOperationType is for
The documentation for this type is a bit sparse right now, and specifically does not explain why it is limited to read/write only; "I/O operation type" could well imply this should distinguish a much broader range of operations like flushes, discards, etc., but it does not.
Make a note why that is, which is that these types reflect the block device on-error policy settings that we have, which are rerror for read and werror for write.
--- qapi/common.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
qapi/common.json +4 -1
@@ -9,7 +9,10 @@ ## # @IoOperationType: -# An enumeration of the I/O operation types +# An enumeration of the I/O operation types, limited to the block +# device on-error policy settings we have (rerror and werror). +# For reference, the corresponding error policy values are set in +# `BlockdevOnError`. # # @read: read operation #
Signature · 1 line
2.55.0
Re: [PATCH v2 01/12] qapi/common: Clarify what IoOperationType is for
Quoted 21 lines · Hanna Czenczek
The documentation for this type is a bit sparse right now, and specifically does not explain why it is limited to read/write only; "I/O operation type" could well imply this should distinguish a much broader range of operations like flushes, discards, etc., but it does not.
Make a note why that is, which is that these types reflect the block device on-error policy settings that we have, which are rerror for read and werror for write.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/common.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)qapi/common.json +0
-0@@ -9,7 +9,10 @@
qapi/common.json line 18
Quoted 10 lines
qapi/common.json +4
-1## # @IoOperationType: -# An enumeration of the I/O operation types +# An enumeration of the I/O operation types, limited to the block +# device on-error policy settings we have (rerror and werror). +# For reference, the corresponding error policy values are set in +# `BlockdevOnError`. # # @read: read operation #
I believe I get what you mean only because I read the cover letter first.
My first attempt
I/O operation types that may have a block device on-error policy.
is still confusing, because we use "block device" both for frontends and backends. I believe "block device on-error policy" refers to the qdev properties "rerror" and "werror" certain block frontends / device models have (virtio-blk-device, scsi-hd, scsi-cd, usb-storage). Possible clarification:
These are the properties "rerror" and "werror" certain block device models have.
And then maybe
@read: read operation, corresponding to property "rerror"
@write: write operation, corresponding to property "werror"
Re: [PATCH v2 01/12] qapi/common: Clarify what IoOperationType is for
Quoted 46 lines · Markus Armbruster
Quoted 21 lines · Hanna Czenczek
The documentation for this type is a bit sparse right now, and specifically does not explain why it is limited to read/write only; "I/O operation type" could well imply this should distinguish a much broader range of operations like flushes, discards, etc., but it does not.
Make a note why that is, which is that these types reflect the block device on-error policy settings that we have, which are rerror for read and werror for write.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/common.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)qapi/common.json +0
-0@@ -9,7 +9,10 @@qapi/common.json line 18
Quoted 10 lines
qapi/common.json +4
-1## # @IoOperationType: -# An enumeration of the I/O operation types +# An enumeration of the I/O operation types, limited to the block +# device on-error policy settings we have (rerror and werror). +# For reference, the corresponding error policy values are set in +# `BlockdevOnError`. # # @read: read operation #I believe I get what you mean only because I read the cover letter first.
My first attempt
I/O operation types that may have a block device on-error policy.
is still confusing, because we use "block device" both for frontends and backends. I believe "block device on-error policy" refers to the qdev properties "rerror" and "werror" certain block frontends / device models have (virtio-blk-device, scsi-hd, scsi-cd, usb-storage). Possible clarification:
Quoted 8 lines
These are the properties "rerror" and "werror" certain block device models have.
And then maybe
@read: read operation, corresponding to property "rerror"
@write: write operation, corresponding to property "werror"
Sure, thanks!
Unless you stop me ( :) ), I’ll keep the reference in, in addition.
Hanna
PATCH v2 2/12 qapi/block: Add IoAccountingOperation enum
In reply to Hanna CzenczekThis enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
qapi/block.json +20 -0
@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting. +# +# @read: Reading data +# +# @write: Writing data +# +# @flush: Flushing data to disk +# +# @zone-append: Appending data to a zone of a zoned block device +# +# @unmap: Discarding a block of data +# +# Since: 11.2 +## +{ 'enum': 'IoAccountingOperation', + 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] }
Signature · 1 line
2.55.0
Re: [PATCH v2 02/12] qapi/block: Add IoAccountingOperation enum
Quoted 14 lines · Hanna Czenczek
This enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)qapi/block.json +0
-0
qapi/block.json line 636
Quoted 8 lines
qapi/block.json +5
-0@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting.
Can we have a link to suitable docs on block accounting?
Quoted 15 lines
qapi/block.json +15
-0+# +# @read: Reading data +# +# @write: Writing data +# +# @flush: Flushing data to disk +# +# @zone-append: Appending data to a zone of a zoned block device +# +# @unmap: Discarding a block of data +# +# Since: 11.2 +## +{ 'enum': 'IoAccountingOperation', + 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] }
Re: [PATCH v2 02/12] qapi/block: Add IoAccountingOperation enum
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Hanna Czenczek
This enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Quoted 14 lines
qapi/block.json line 636
Quoted 13 lines
qapi/block.json +5
-0@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting.Can we have a link to suitable docs on block accounting?
Which do you have in mind?
Also, I’m not sure whether these are suitable, because they are the operation types used by block accounting, but for now, accounting cookies (block/accounting.c) use their own non-QAPI enum (enum BlockAcctType).
Hanna
Quoted 15 lines
Quoted 15 lines
qapi/block.json +15
-0+# +# @read: Reading data +# +# @write: Writing data +# +# @flush: Flushing data to disk +# +# @zone-append: Appending data to a zone of a zoned block device +# +# @unmap: Discarding a block of data +# +# Since: 11.2 +## +{ 'enum': 'IoAccountingOperation', + 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] }
Re: [PATCH v2 02/12] qapi/block: Add IoAccountingOperation enum
Quoted 28 lines · Hanna Czenczek
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Hanna Czenczek
This enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)Quoted 15 lines
qapi/block.json line 636
Quoted 13 lines
qapi/block.json +5
-0@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting.Can we have a link to suitable docs on block accounting?
Quoted 1 line
Which do you have in mind?
Hey, I asked first!
Two ideas to find candidates:
1. How is IoAccountingOperation going to be used?
I can see events BLOCK_IO_DELAY and BLOCK_IO_DONE. Documentation there calls it "disk operation" in the event description and "I/O operation" in the argument description. Not a peep about "accounting". Might "tracked by block accounting" be about implementation? Or asked differently: why would the user care about block accounting here?
2. Assuming "block accounting" is actually relevant for the user: what are the QMP interfaces related to it?
Quoted 1 line
Also, I’m not sure whether these are suitable, because they are the operation types used by block accounting, but for now, accounting cookies (
block/accounting.c) use their own non-QAPI enum (enum BlockAcctType).
[...]
Re: [PATCH v2 02/12] qapi/block: Add IoAccountingOperation enum
Quoted 28 lines · Markus Armbruster
Quoted 26 lines · Hanna Czenczek
Quoted 25 lines · Markus Armbruster
Quoted 14 lines · Hanna Czenczek
This enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)qapi/block.json +0
-0qapi/block.json line 636
Quoted 8 lines
qapi/block.json +5
-0@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting.Can we have a link to suitable docs on block accounting?
Quoted 2 lines
Quoted 1 line
Which do you have in mind?
Hey, I asked first!
:)
Quoted 10 lines
Two ideas to find candidates:
1. How is IoAccountingOperation going to be used?
I can see events
BLOCK_IO_DELAYandBLOCK_IO_DONE. Documentation there calls it "disk operation" in the event description and "I/O operation" in the argument description. Not a peep about "accounting". Might "tracked by block accounting" be about implementation? Or asked differently: why would the user care about block accounting here?
Good question, the user presumably indeed won’t care. It is only going to be used for those two events, so maybe it makes most sense to merge those three patches (IoAccountingOperation, BLOCK_IO_DELAY, BLOCK_IO_DONE), so I can immediately refer to those events instead of accounting.
(The internal reasoning is that I don’t want this to deviate from the existing accounting too much, so that maybe the accounting code can later be switched to use the same request boundaries as this series introduces, and then switch its enum over to this QAPI variant. But absolutely not relevant to users, correct.)
Quoted 2 lines
2. Assuming "block accounting" is actually relevant for the user: what are the QMP interfaces related to it?
The best is probably the BlockDeviceStats keys for the different latency histograms, which could be a map of this new enum to histograms instead… But given the above, probably best to just drop this.
Hanna
Quoted 2 lines
Quoted 1 line
Also, I’m not sure whether these are suitable, because they are the operation types used by block accounting, but for now, accounting cookies (
block/accounting.c) use their own non-QAPI enum (enum BlockAcctType).[...]
Re: [PATCH v2 02/12] qapi/block: Add IoAccountingOperation enum
Quoted 40 lines · Hanna Czenczek
Quoted 29 lines · Markus Armbruster
Quoted 27 lines · Hanna Czenczek
Quoted 25 lines · Markus Armbruster
Quoted 14 lines · Hanna Czenczek
This enum gives more information than IoOperationType (which is used for the rerror/werror distinction) to identify operation types for block accounting.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)qapi/block.json +0
-0qapi/block.json line 636
Quoted 8 lines
qapi/block.json +5
-0@@ -629,3 +629,23 @@ 'command': 'str' }, 'features': [ 'unstable' ], 'allow-preconfig': true } + +## +# @IoAccountingOperation: +# +# I/O operation types as they are tracked by block accounting.Can we have a link to suitable docs on block accounting?
Quoted 3 lines
Quoted 1 line
Which do you have in mind?
Hey, I asked first!
:)
Quoted 4 lines
Two ideas to find candidates:
1. How is IoAccountingOperation going to be used?
Quoted 8 lines
Quoted 6 lines
I can see events
BLOCK_IO_DELAYandBLOCK_IO_DONE. Documentation there calls it "disk operation" in the event description and "I/O operation" in the argument description. Not a peep about "accounting". Might "tracked by block accounting" be about implementation? Or asked differently: why would the user care about block accounting here?Good question, the user presumably indeed won’t care. It is only going to be used for those two events, so maybe it makes most sense to merge those three patches (
IoAccountingOperation,BLOCK_IO_DELAY,BLOCK_IO_DONE), so I can immediately refer to those events instead of accounting.
You could also add the enum without a reference, then add references as you go. Not sure whether pointing that out in the enum's commit message would be advisable.
Quoted 6 lines
(The internal reasoning is that I don’t want this to deviate from the existing accounting too much, so that maybe the accounting code can later be switched to use the same request boundaries as this series introduces, and then switch its enum over to this QAPI variant. But absolutely not relevant to users, correct.)
Quoted 2 lines
2. Assuming "block accounting" is actually relevant for the user: what are the QMP interfaces related to it?
The best is probably the
BlockDeviceStatskeys for the different latency histograms, which could be a map of this new enum to histograms instead… But given the above, probably best to just drop this.
Makes sense to me. Thanks!
[...]
PATCH v2 3/12 runstate: Allow IO_ERROR/SUSPENDED transitions
In reply to Hanna CzenczekI/O errors can occur while the VM is suspended, and we can continue from a stop due to I/O error into suspension. Allow these transitions.
--- system/runstate.c | 2 ++ 1 file changed, 2 insertions(+)
system/runstate.c +2 -0
@@ -106,6 +106,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING }, { RUN_STATE_IO_ERROR, RUN_STATE_FINISH_MIGRATE }, { RUN_STATE_IO_ERROR, RUN_STATE_PRELAUNCH }, + { RUN_STATE_IO_ERROR, RUN_STATE_SUSPENDED }, { RUN_STATE_PAUSED, RUN_STATE_RUNNING }, { RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
@@ -173,6 +174,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_SUSPENDED, RUN_STATE_SAVE_VM }, { RUN_STATE_SUSPENDED, RUN_STATE_RESTORE_VM }, { RUN_STATE_SUSPENDED, RUN_STATE_SHUTDOWN }, + { RUN_STATE_SUSPENDED, RUN_STATE_IO_ERROR }, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
Signature · 1 line
2.55.0
PATCH v2 4/12 iotests: PC-only test for I/O errors during suspend
In reply to Hanna CzenczekUsing IDE (PIO) and writing directly to the PIIX4 PM device, we can test what happens when an I/O error occurs while the VM is suspended.
The moment we resume the request while the VM is suspended is the moment of the SUSPENDED -> IO_ERROR transition, and the moment we issue cont is the reverse IO_ERROR -> SUSPENDED transition.
--- .../tests/io-error-during-suspend | 155 ++++++++++++++++++ .../tests/io-error-during-suspend.out | 22 +++ 2 files changed, 177 insertions(+) create mode 100755 tests/qemu-iotests/tests/io-error-during-suspend create mode 100644 tests/qemu-iotests/tests/io-error-during-suspend.out
tests/qemu-iotests/tests/io-error-during-suspend new file +155 -0
@@ -0,0 +1,155 @@ +#!/usr/bin/env python3 +# group: rw +# +# Reproduce an I/O error while the guest is entering suspend +# +# Copyright (C) 2026 Red Hat, Inc. +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Creator/Owner: Hanna Czenczek <[email protected]> + +import iotests +from iotests import filter_qmp_event, log + +iotests.script_initialize() + +# PC machine type required for PIIX4 and IDE +if iotests.qemu_default_machine != 'pc': + iotests.notrun('Requires a PC machine') + +def vm_qemu_io(qvm, dev_id, cmd): + log(f'[HMP] qemu-io to {dev_id}: {cmd}') + command_line=f'qemu-io -d {dev_id} "{cmd}"' + log(qvm.qmp('human-monitor-command', command_line=command_line)) + +def await_event(qvm, match): + evt = qvm.event_wait(match, timeout=30.0) + assert evt is not None + return evt + +def find_pci(qvm, vendor, device): + """ + Return bus, slot, function of the device matching vendor and device ID. + """ + + for bus in qvm.qmp('query-pci')['return']: + for dev in bus['devices']: + if dev['id']['vendor'] == vendor and dev['id']['device'] == device: + return dev['bus'], dev['slot'], dev['function'] + + raise RuntimeError(f'PCI device {vendor:04x}:{device:04x} not found') + +def enter_s3(qvm): + """ + Enter suspend via the PIIX4 PM device + """ + + bus, slot, function = find_pci(qvm, 0x8086, 0x7113) + pci_pm_addr = 0x80000000 | (bus << 16) | (slot << 11) | (function << 8) + + # Config registers: + # - 0x40: Set the power management I/O range base + # - 0x80: Bit 0 enables that range + # I/O range: + # - +4: PM1a_CNT + # - Bits 10..=12: SLEEP_TYPE (1 for suspend, see `acpi_pm_cnt_write()`) + # - Bit 13: SLEEP_ENABLE + + arbitrary_pm_io_base = 0xb000 + log('Setting up PIIX4 PM I/O range') + # Setting the base address + qvm.qtest(f'outl 0xcf8 {pci_pm_addr + 0x40:#x}') + qvm.qtest(f'outl 0xcfc {arbitrary_pm_io_base:#x}') + # Enabling the range + qvm.qtest(f'outl 0xcf8 {pci_pm_addr + 0x80:#x}') + qvm.qtest('outb 0xcfc 0x1') + + log('Going to sleep') + pm1a_cnt = arbitrary_pm_io_base + 4 + pm1a_value = (1 << 10) | (1 << 13) + qvm.qtest(f'outw {pm1a_cnt:#x} {pm1a_value:#x}') + +def ide_issue_pio_read(qvm, lba, sectors): + """ + Issue a read request from the master device. + Does not read the data through PIO, though. + """ + + for port, val in ( + (0x1f6, 0xe0 | ((lba >> 24) & 0xf)), # 0x40 selects LBA + (0x1f2, sectors), + (0x1f3, lba & 0xff), + (0x1f4, (lba >> 8) & 0xff), + (0x1f5, (lba >> 16) & 0xff), + (0x1f7, 0x20), # WIN_READ + ): + qvm.qtest(f'outb {port:#x} {val:#x}') + +with iotests.VM() as vm: + # So we have PIIX4 + vm.add_args('-machine', 'pc') + + failing_sector = 42 + vm.add_blockdev(vm.qmp_to_opts({ + 'driver': 'raw', + 'node-name': 'test', + 'file': { + 'driver': 'blkdebug', + 'inject-error': [{'event': 'read_aio', 'iotype': 'read', + 'sector': str(failing_sector), 'once': 'on'}], + 'image': { + 'driver': 'null-co', + }, + }, + })) + + disk = 'ide-disk' + vm.add_device(f'ide-hd,id={disk},drive=test,bus=ide.0,unit=0,' + 'rerror=stop,werror=stop') + + vm.launch() + + try: + # Issue a read request from a guest device (to the failing sector), and + # have it pause before it returns + vm_qemu_io(vm, disk, 'break read_aio r0') + log('Issuing read') + ide_issue_pio_read(vm, failing_sector, 1) + vm_qemu_io(vm, disk, 'wait_break r0') + + # Read request is paused now, let's suspend the VM + log('Entering suspend') + enter_s3(vm) + log(await_event(vm, 'SUSPEND'), filters=[filter_qmp_event]) + + # Should be suspended now + log('[QMP] query-status') + log(vm.qmp('query-status')) + except Exception: + # The VM will not be able to quit without this request finished, which + # (without this block) would make the test hang instead of exit if + # something unexpected goes wrong + vm_qemu_io(vm, disk, 'resume r0') + raise + + # Resume the request, which should run into an error thanks to our blkdebug + # configuration + vm_qemu_io(vm, disk, 'resume r0') + log(await_event(vm, 'BLOCK_IO_ERROR'), filters=[filter_qmp_event]) + log(await_event(vm, 'STOP'), filters=[filter_qmp_event]) + + # Should be stopped now (not just suspended) + log('[QMP] query-status') + log(vm.qmp('query-status')) + + log('[QMP] cont') + log(vm.qmp('cont')) + + log(await_event(vm, 'RESUME'), filters=[filter_qmp_event]) + + # Should be suspended again (error was injected 'once', so should be gone) + log('[QMP] query-status') + log(vm.qmp('query-status')) + + vm.shutdown()
tests/qemu-iotests/tests/io-error-during-suspend.out new file +22 -0
@@ -0,0 +1,22 @@ +[HMP] qemu-io to ide-disk: break read_aio r0 +{"return": ""} +Issuing read +[HMP] qemu-io to ide-disk: wait_break r0 +{"return": ""} +Entering suspend +Setting up PIIX4 PM I/O range +Going to sleep +{"event": "SUSPEND", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +[QMP] query-status +{"return": {"running": false, "status": "suspended"}} +[HMP] qemu-io to ide-disk: resume r0 +{"return": ""} +{"data": {"action": "stop", "device": "", "node-name": "test", "nospace": false, "operation": "read", "qom-path": "/machine/peripheral/ide-disk", "reason": "Input/output error"}, "event": "BLOCK_IO_ERROR", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"event": "STOP", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +[QMP] query-status +{"return": {"running": false, "status": "io-error"}} +[QMP] cont +{"return": {}} +{"event": "RESUME", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +[QMP] query-status +{"return": {"running": false, "status": "suspended"}}
Signature · 1 line
2.55.0
PATCH v2 5/12 qapi/run-state: Add io-hang state
In reply to Hanna CzenczekThis state is similar to io-error, but is not entered on I/O errors but instead when a request takes longer than a user-defined time (set via the delay-stop-ns property on a block device, which is not yet available but will be added by a future patch in this series).
In contrast to other stop states, this state does not drain block devices. That is because it is entered only when a request hangs, which means that draining would be counter-productive.
--- qapi/run-state.json | 7 ++++++- system/runstate.c | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-)
qapi/run-state.json +6 -1
@@ -53,12 +53,17 @@ # @colo: guest is paused to save/restore VM state under colo # checkpoint, VM can not get into this state unless colo # capability is enabled for migration. (since 2.8) +# +# @io-hang: An I/O operation has been delayed for too long and the +# device is configured to stop the VM when that happens. In +# contrast to other paused states, the VM's block devices will not +# be drained when entering this run state. (since 11.2) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo' ] } + 'guest-panicked', 'colo', 'io-hang' ] } ## # @ShutdownCause:
system/runstate.c +18 -7
@@ -98,6 +98,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_INMIGRATE, RUN_STATE_PRELAUNCH }, { RUN_STATE_INMIGRATE, RUN_STATE_POSTMIGRATE }, { RUN_STATE_INMIGRATE, RUN_STATE_COLO }, + { RUN_STATE_INMIGRATE, RUN_STATE_IO_HANG }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_PAUSED }, { RUN_STATE_INTERNAL_ERROR, RUN_STATE_FINISH_MIGRATE },
@@ -135,6 +136,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_FINISH_MIGRATE, RUN_STATE_SUSPENDED }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_WATCHDOG }, { RUN_STATE_FINISH_MIGRATE, RUN_STATE_GUEST_PANICKED }, + { RUN_STATE_FINISH_MIGRATE, RUN_STATE_IO_HANG }, { RUN_STATE_RESTORE_VM, RUN_STATE_RUNNING }, { RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
@@ -155,6 +157,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG }, { RUN_STATE_RUNNING, RUN_STATE_GUEST_PANICKED }, { RUN_STATE_RUNNING, RUN_STATE_COLO}, + { RUN_STATE_RUNNING, RUN_STATE_IO_HANG }, { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING }, { RUN_STATE_SAVE_VM, RUN_STATE_SUSPENDED },
@@ -175,6 +178,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_SUSPENDED, RUN_STATE_RESTORE_VM }, { RUN_STATE_SUSPENDED, RUN_STATE_SHUTDOWN }, { RUN_STATE_SUSPENDED, RUN_STATE_IO_ERROR }, + { RUN_STATE_SUSPENDED, RUN_STATE_IO_HANG }, { RUN_STATE_WATCHDOG, RUN_STATE_RUNNING }, { RUN_STATE_WATCHDOG, RUN_STATE_FINISH_MIGRATE },
@@ -185,6 +189,11 @@ static const RunStateTransition runstate_transitions_def[] = { { RUN_STATE_GUEST_PANICKED, RUN_STATE_FINISH_MIGRATE }, { RUN_STATE_GUEST_PANICKED, RUN_STATE_PRELAUNCH }, + { RUN_STATE_IO_HANG, RUN_STATE_RUNNING }, + { RUN_STATE_IO_HANG, RUN_STATE_FINISH_MIGRATE }, + { RUN_STATE_IO_HANG, RUN_STATE_PRELAUNCH }, + { RUN_STATE_IO_HANG, RUN_STATE_SUSPENDED }, + { RUN_STATE__MAX, RUN_STATE__MAX }, };
@@ -445,13 +454,15 @@ static int do_vm_stop(RunState state, bool send_stop) } } -bdrv_drain_all (); -/* -* Even if vm_state_notify() return failure, -* it would be better to flush as before. -*/ - ret |=bdrv_flush_all (); -trace_vm_stop_flush_all (ret); +if (state !=RUN_STATE_IO_HANG ) { +bdrv_drain_all (); +/* +* Even if vm_state_notify() return failure, +* it would be better to flush as before. +*/ + ret |=bdrv_flush_all (); +trace_vm_stop_flush_all (ret); + }return ret; }
Signature · 1 line
2.55.0
Re: [PATCH v2 05/12] qapi/run-state: Add io-hang state
Quoted 28 lines · Hanna Czenczek
This state is similar to io-error, but is not entered on I/O errors but instead when a request takes longer than a user-defined time (set via the delay-stop-ns property on a block device, which is not yet available but will be added by a future patch in this series).
In contrast to other stop states, this state does not drain block devices. That is because it is entered only when a request hangs, which means that draining would be counter-productive.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/run-state.json | 7 ++++++- system/runstate.c | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-)qapi/run-state.json +5
-0@@ -53,12 +53,17 @@ # @colo: guest is paused to save/restore VM state under colo # checkpoint, VM can not get into this state unless colo # capability is enabled for migration. (since 2.8) +# +# @io-hang: An I/O operation has been delayed for too long and the +# device is configured to stop the VM when that happens. In +# contrast to other paused states, the VM's block devices will not +# be drained when entering this run state. (since 11.2)
qapi/run-state.json line 69
Quoted 10 lines
qapi/run-state.json +1
-1## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo' ] } + 'guest-panicked', 'colo', 'io-hang' ] } ## # @ShutdownCause:
QAPI schema
PATCH v2 6/12 qapi/block: Add BLOCK_IO_DELAY event
In reply to Hanna CzenczekThis event will be emitted when a disk operation takes longer than a pre-defined threshold (as set on the block device).
Note that the description refers to the "delay-report-ns" and "delay-stop-ns" block device properties, which are not yet available. A future commit in this series will add them.
--- qapi/block.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
qapi/block.json +37 -0
@@ -649,3 +649,40 @@ ## { 'enum': 'IoAccountingOperation', 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] } + +## +# @BLOCK_IO_DELAY: +# +# Emitted when a disk operation takes longer than the pre-defined +# threshold (as set via the "delay-report-ns" / "delay-stop-ns" +# properties on the block device). +# +# Note that delays deliberately incurred by throttling do count +# towards the operation duration. +# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Ongoing duration of the operation (in nanoseconds) +# +# @action: Action that has been taken ("report" for "delay-report-ns" +# or "stop" for "delay-stop-ns"). A "stop" action means the VM +# will be stopped with the "io-hang" `RunState`, which does not +# drain the block devices attached to the VM, because draining +# would be counterproductive in case of a hanging I/O request. +# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DELAY', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + 'action': 'BlockErrorAction', + '*offset': 'uint64', + 'bytes': 'uint64' } }
Signature · 1 line
2.55.0
Re: [PATCH v2 06/12] qapi/block: Add BLOCK_IO_DELAY event
Quoted 17 lines · Hanna Czenczek
This event will be emitted when a disk operation takes longer than a pre-defined threshold (as set on the block device).
Note that the description refers to the "delay-report-ns" and "delay-stop-ns" block device properties, which are not yet available. A future commit in this series will add them.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)qapi/block.json +0
-0
qapi/block.json line 658
Quoted 10 lines
qapi/block.json +7
-0@@ -649,3 +649,40 @@ ## { 'enum': 'IoAccountingOperation', 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] } + +## +# @BLOCK_IO_DELAY: +# +# Emitted when a disk operation takes longer than the pre-defined +# threshold (as set via the "delay-report-ns" / "delay-stop-ns" +# properties on the block device).
As in PATCH 01, "block device" could be confusing, because we use the term both for frontends and backends. I believe "delay-report-ns" and "delay-stop-ns" are the qdev properties every block device model will have [PATCH 11].
qapi/block.json line 662
Quoted 4 lines
qapi/block.json +4
-0+# +# Note that delays deliberately incurred by throttling do count +# towards the operation duration. +#
Please use the revised syntax for introductions, like you did in PATCH 01:
# @name: introduction, best to keep it brief, but you may continue it
# like this if necessary. If your text need to refer to # arguments, it's almost certainly not brief introduction # anymore.
#
# Additional text can go here for now.
I apologize for the inconvenience. We need this to eliminate certain syntactic ambiguities that plagued the doc generator. We'll need it some more for the doc inliner.
qapi/block.json line 673
Quoted 11 lines
qapi/block.json +11
-0+# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Ongoing duration of the operation (in nanoseconds) +# +# @action: Action that has been taken ("report" for "delay-report-ns" +# or "stop" for "delay-stop-ns"). A "stop" action means the VM +# will be stopped with the "io-hang" `RunState`, which does not +# drain the block devices attached to the VM, because draining +# would be counterproductive in case of a hanging I/O request.
This feels less than clear. What exactly happens? My best guess:
* When an operation takes longer than delay-report-ns, BLOCK_IO_DELAY is emitted with "action": "report" (but only once for this operation).
* When an operation takes longer than delay-stop-ns, the guest is stopped (run state becomes io-hang), and BLOCK_IO_DELAY is emitted with "action": "stop".
Say we continue the guest. Can the even be triggered again for this operation?
The three possible values are ignore, report, and stop. You cover report and stop. Can ignore happen?
We should use ``literal`` markup for literal values.
Quoted 15 lines
qapi/block.json +15
-0+# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DELAY', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + 'action': 'BlockErrorAction', + '*offset': 'uint64', + 'bytes': 'uint64' } }
Re: [PATCH v2 06/12] qapi/block: Add BLOCK_IO_DELAY event
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Hanna Czenczek
This event will be emitted when a disk operation takes longer than a pre-defined threshold (as set on the block device).
Note that the description refers to the "delay-report-ns" and "delay-stop-ns" block device properties, which are not yet available. A future commit in this series will add them.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)qapi/block.json +3
-0@@ -649,3 +649,40 @@ ## { 'enum': 'IoAccountingOperation', 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] } + +## +# @BLOCK_IO_DELAY:
Quoted 8 lines
qapi/block.json line 658
Quoted 4 lines
qapi/block.json +4
-0+# +# Emitted when a disk operation takes longer than the pre-defined +# threshold (as set via the "delay-report-ns" / "delay-stop-ns" +# properties on the block device).As in PATCH 01, "block device" could be confusing, because we use the term both for frontends and backends. I believe "delay-report-ns" and "delay-stop-ns" are the qdev properties every block device model will have [PATCH 11].
Sure. So… “block device model”, or “on -device”?
Quoted 14 lines
qapi/block.json line 662
Quoted 4 lines
qapi/block.json +4
-0+# +# Note that delays deliberately incurred by throttling do count +# towards the operation duration. +#Please use the revised syntax for introductions, like you did in PATCH 01:
# @name: introduction, best to keep it brief, but you may continue it
# like this if necessary. If your text need to refer to
# arguments, it's almost certainly not brief introduction
# anymore.
#
# Additional text can go here for now.
Quoted 3 lines
I apologize for the inconvenience. We need this to eliminate certain syntactic ambiguities that plagued the doc generator. We'll need it some more for the doc inliner.
Sure!
Quoted 16 lines
qapi/block.json line 673
Quoted 11 lines
qapi/block.json +11
-0+# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Ongoing duration of the operation (in nanoseconds) +# +# @action: Action that has been taken ("report" for "delay-report-ns" +# or "stop" for "delay-stop-ns"). A "stop" action means the VM +# will be stopped with the "io-hang" `RunState`, which does not +# drain the block devices attached to the VM, because draining +# would be counterproductive in case of a hanging I/O request.This feels less than clear. What exactly happens? My best guess:
* When an operation takes longer than delay-report-ns,
BLOCK_IO_DELAYis emitted with "action": "report" (but only once for this operation).
Quoted 6 lines
* When an operation takes longer than delay-stop-ns, the guest is stopped (run state becomes io-hang), and
BLOCK_IO_DELAYis emitted with "action": "stop".Say we continue the guest. Can the even be triggered again for this operation?
No, because latency starts when the request begins, and the event (and action) happen only when that threshold is crossed.
I can try to be more clear.
Quoted 2 lines
The three possible values are ignore, report, and stop. You cover report and stop. Can ignore happen?
No, it cannot. (Also by definition of ignore meaning to… ignore something. So an event cannot carry this.)
Quoted 1 line
We should use ``literal`` markup for literal values.
Sure.
Hanna
Quoted 15 lines
Quoted 15 lines
qapi/block.json +15
-0+# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DELAY', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + 'action': 'BlockErrorAction', + '*offset': 'uint64', + 'bytes': 'uint64' } }
Re: [PATCH v2 06/12] qapi/block: Add BLOCK_IO_DELAY event
Quoted 36 lines · Hanna Czenczek
Quoted 26 lines · Markus Armbruster
Quoted 24 lines · Hanna Czenczek
This event will be emitted when a disk operation takes longer than a pre-defined threshold (as set on the block device).
Note that the description refers to the "delay-report-ns" and "delay-stop-ns" block device properties, which are not yet available. A future commit in this series will add them.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)qapi/block.json +4
-0@@ -649,3 +649,40 @@ ## { 'enum': 'IoAccountingOperation', 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] } + +## +# @BLOCK_IO_DELAY: +#Quoted 8 lines
qapi/block.json line 658
Quoted 3 lines
qapi/block.json +3
-0+# Emitted when a disk operation takes longer than the pre-defined +# threshold (as set via the "delay-report-ns" / "delay-stop-ns" +# properties on the block device).As in PATCH 01, "block device" could be confusing, because we use the term both for frontends and backends. I believe "delay-report-ns" and "delay-stop-ns" are the qdev properties every block device model will have [PATCH 11].
Quoted 1 line
Sure. So… “block device model”, or “on -device”?
For PATCH 01, I suggested additional text that makes the meaning obvious:
These are the properties "rerror" and "werror" certain block device models have.
Here, you have something similar already. I think "on the block device model" would do. Or maybe "the block device model's ``delay-report-ns`` / ``delay-report-ns`` properties".
Quoted 38 lines
Quoted 15 lines
qapi/block.json line 662
Quoted 4 lines
qapi/block.json +4
-0+# +# Note that delays deliberately incurred by throttling do count +# towards the operation duration. +#Please use the revised syntax for introductions, like you did in PATCH 01:
# @name: introduction, best to keep it brief, but you may continue it
# like this if necessary. If your text need to refer to
# arguments, it's almost certainly not brief introduction
# anymore.
#
# Additional text can go here for now.Quoted 3 lines
I apologize for the inconvenience. We need this to eliminate certain syntactic ambiguities that plagued the doc generator. We'll need it some more for the doc inliner.
Sure!
Quoted 17 lines
qapi/block.json line 673
Quoted 11 lines
qapi/block.json +11
-0+# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Ongoing duration of the operation (in nanoseconds) +# +# @action: Action that has been taken ("report" for "delay-report-ns" +# or "stop" for "delay-stop-ns"). A "stop" action means the VM +# will be stopped with the "io-hang" `RunState`, which does not +# drain the block devices attached to the VM, because draining +# would be counterproductive in case of a hanging I/O request.This feels less than clear. What exactly happens? My best guess:
* When an operation takes longer than delay-report-ns,
BLOCK_IO_DELAYis emitted with "action": "report" (but only once for this operation).
Quoted 8 lines
Quoted 6 lines
* When an operation takes longer than delay-stop-ns, the guest is stopped (run state becomes io-hang), and
BLOCK_IO_DELAYis emitted with "action": "stop".Say we continue the guest. Can the even be triggered again for this operation?
No, because latency starts when the request begins, and the event (and action) happen only when that threshold is crossed.
So it can be triggered once for @delay-report-ns, and once for @delay-stop-ns. Correct?
In sane usage, @delay-report-ns < @delay-stop-ns. Correct?
Quoted 6 lines
I can try to be more clear.
Quoted 2 lines
The three possible values are ignore, report, and stop. You cover report and stop. Can ignore happen?
No, it cannot. (Also by definition of
ignoremeaning to… ignore something. So an event cannot carry this.)
Try mentioning this. If the text feels worse then, don't.
Quoted 21 lines
Quoted 1 line
We should use ``literal`` markup for literal values.
Sure.
Hanna
Quoted 15 lines
Quoted 15 lines
qapi/block.json +15
-0+# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DELAY', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + 'action': 'BlockErrorAction', + '*offset': 'uint64', + 'bytes': 'uint64' } }
Re: [PATCH v2 06/12] qapi/block: Add BLOCK_IO_DELAY event
Quoted 40 lines · Markus Armbruster
Quoted 34 lines · Hanna Czenczek
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Hanna Czenczek
This event will be emitted when a disk operation takes longer than a pre-defined threshold (as set on the block device).
Note that the description refers to the "delay-report-ns" and "delay-stop-ns" block device properties, which are not yet available. A future commit in this series will add them.
Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)qapi/block.json +3
-0@@ -649,3 +649,40 @@ ## { 'enum': 'IoAccountingOperation', 'data': [ 'read', 'write', 'flush', 'zone-append', 'unmap' ] } + +## +# @BLOCK_IO_DELAY:Quoted 8 lines
qapi/block.json line 658
Quoted 4 lines
qapi/block.json +4
-0+# +# Emitted when a disk operation takes longer than the pre-defined +# threshold (as set via the "delay-report-ns" / "delay-stop-ns" +# properties on the block device).As in PATCH 01, "block device" could be confusing, because we use the term both for frontends and backends. I believe "delay-report-ns" and "delay-stop-ns" are the qdev properties every block device model will have [PATCH 11].
Quoted 1 line
Sure. So… “block device model”, or “on -device”?
For PATCH 01, I suggested additional text that makes the meaning obvious:
Quoted 6 lines
These are the properties "rerror" and "werror" certain block device models have.
Here, you have something similar already. I think "on the block device model" would do. Or maybe "the block device model's ``delay-report-ns`` / ``delay-report-ns`` properties".
Great, thanks.
Quoted 39 lines
Quoted 39 lines
Quoted 14 lines
qapi/block.json line 662
Quoted 4 lines
qapi/block.json +4
-0+# +# Note that delays deliberately incurred by throttling do count +# towards the operation duration. +#Please use the revised syntax for introductions, like you did in PATCH 01:
# @name: introduction, best to keep it brief, but you may continue it
# like this if necessary. If your text need to refer to
# arguments, it's almost certainly not brief introduction
# anymore.
#
# Additional text can go here for now.Quoted 3 lines
I apologize for the inconvenience. We need this to eliminate certain syntactic ambiguities that plagued the doc generator. We'll need it some more for the doc inliner.
Sure!
Quoted 20 lines
qapi/block.json line 673
Quoted 11 lines
qapi/block.json +11
-0+# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Ongoing duration of the operation (in nanoseconds) +# +# @action: Action that has been taken ("report" for "delay-report-ns" +# or "stop" for "delay-stop-ns"). A "stop" action means the VM +# will be stopped with the "io-hang" `RunState`, which does not +# drain the block devices attached to the VM, because draining +# would be counterproductive in case of a hanging I/O request.This feels less than clear. What exactly happens? My best guess:
* When an operation takes longer than delay-report-ns,
BLOCK_IO_DELAYis emitted with "action": "report" (but only once for this operation).* When an operation takes longer than delay-stop-ns, the guest is stopped (run state becomes io-hang), and
BLOCK_IO_DELAYis emitted with "action": "stop".
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Say we continue the guest. Can the even be triggered again for this operation?
No, because latency starts when the request begins, and the event (and action) happen only when that threshold is crossed.
So it can be triggered once for @delay-report-ns, and once for @delay-stop-ns. Correct?
Yes, correct.
Quoted 1 line
In sane usage, @delay-report-ns < @delay-stop-ns. Correct?
Well, uh, I suppose. The opposite could be imagined, but if someone wants that, that might rather indicate they would really want an array of thresholds rather than a single one, so… As long as we just have a single reporting threshold, @delay-report-ns < @delay-stop-ns is the sane usage, yes.
Quoted 6 lines
Quoted 5 lines
I can try to be more clear.
Quoted 2 lines
The three possible values are ignore, report, and stop. You cover report and stop. Can ignore happen?
No, it cannot. (Also by definition of
ignoremeaning to… ignore something. So an event cannot carry this.)Try mentioning this. If the text feels worse then, don't.
Sure!
Hanna
Quoted 20 lines
Quoted 20 lines
Quoted 1 line
We should use ``literal`` markup for literal values.
Sure.
Hanna
Quoted 15 lines
Quoted 15 lines
qapi/block.json +15
-0+# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DELAY', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + 'action': 'BlockErrorAction', + '*offset': 'uint64', + 'bytes': 'uint64' } }
Re: [PATCH v2 06/12] qapi/block: Add BLOCK_IO_DELAY event
Quoted 1 line · Hanna Czenczek
On 23.10.26 08:14, Markus Armbruster wrote:
[...]
Quoted 3 lines
Quoted 1 line
In sane usage, @delay-report-ns < @delay-stop-ns. Correct?
Well, uh, I suppose. The opposite could be imagined, but if someone wants that, that might rather indicate they would really want an array of thresholds rather than a single one, so… As long as we just have a single reporting threshold,
@delay-report-ns < @delay-stop-nsis the sane usage, yes.
Three options, I think:
1. Make @delay-stop-ns < @delay-stop-ns an error.
2. Advice users that @delay-stop-ns < @delay-stop-ns probably makes no sense.
3. Nothing, because we trust users they can figure this out themselves.
Entirely up to you!
[...]
PATCH v2 7/12 qapi/block: Add BLOCK_IO_DONE event
In reply to Hanna CzenczekThis event is emitted when an operation completes, for which a BLOCK_IO_DELAY event has previously been emitted.
--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
qapi/block.json +33 -0
@@ -660,6 +660,9 @@ # Note that delays deliberately incurred by throttling do count # towards the operation duration. # +# This event will only be emitted once per request and action. When +# the operation does finish, a `BLOCK_IO_DONE` event is emitted. +# # @qom-path: path to the block device object in the QOM tree # # @operation: I/O operation
@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event. +# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if available +# +# @bytes: Request length +# +# @failed: If true, this request failed for any reason. If false, the +# request succeeded. +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DONE', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + '*offset': 'uint64', + 'bytes': 'uint64', + 'failed': 'bool' } }
Signature · 1 line
2.55.0
Re: [PATCH v2 07/12] qapi/block: Add BLOCK_IO_DONE event
Quoted 13 lines · Hanna Czenczek
This event is emitted when an operation completes, for which a
BLOCK_IO_DELAYevent has previously been emitted.Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)qapi/block.json +0
-0
qapi/block.json line 664
Quoted 5 lines
qapi/block.json +2
-0@@ -660,6 +660,9 @@ # Note that delays deliberately incurred by throttling do count # towards the operation duration. # +# This event will only be emitted once per request and action. When +# the operation does finish, a `BLOCK_IO_DONE` event is emitted.
I think the first sentence answers a question I had on the previous patch. Move it there?
Quoted 5 lines
qapi/block.json +1
-0+# # @qom-path: path to the block device object in the QOM tree # # @operation: I/O operation
qapi/block.json line 697
Quoted 9 lines
qapi/block.json +6
-0@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event.
Can we have multiple operations in flight that previously emitted BLOCK_IO_DELAY?
If yes, might a management application need to connect the BLOCK_IO_DONE back to the BLOCK_IO_DELAY?
If yes, how could it do that?
Please use the revised syntax for introductions:
##
# @BLOCK_IO_DONE: Emitted on completion for disk operations that
# previously emitted a BLOCK_IO_DELAY event.
qapi/block.json line 705
Quoted 8 lines
qapi/block.json +8
-0+# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if available
Out of curiosity: when could @offset be unavailable?
qapi/block.json line 709
Quoted 4 lines
qapi/block.json +4
-0+# +# @bytes: Request length +# +# @failed: If true, this request failed for any reason. If false, the
Suggest "for some reason".
Quoted 12 lines
qapi/block.json +12
-0+# request succeeded. +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DONE', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + '*offset': 'uint64', + 'bytes': 'uint64', + 'failed': 'bool' } }
Re: [PATCH v2 07/12] qapi/block: Add BLOCK_IO_DONE event
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Hanna Czenczek
This event is emitted when an operation completes, for which a
BLOCK_IO_DELAYevent has previously been emitted.Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
Quoted 12 lines
qapi/block.json line 664
Quoted 10 lines
qapi/block.json +2
-0@@ -660,6 +660,9 @@ # Note that delays deliberately incurred by throttling do count # towards the operation duration. # +# This event will only be emitted once per request and action. When +# the operation does finish, a `BLOCK_IO_DONE` event is emitted.I think the first sentence answers a question I had on the previous patch. Move it there?
Sure.
Quoted 17 lines
Quoted 5 lines
qapi/block.json +1
-0+# # @qom-path: path to the block device object in the QOM tree # # @operation: I/O operationqapi/block.json line 697
Quoted 9 lines
qapi/block.json +6
-0@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event.Can we have multiple operations in flight that previously emitted
BLOCK_IO_DELAY?
Quoted 4 lines
If yes, might a management application need to connect the
BLOCK_IO_DONEback to theBLOCK_IO_DELAY?If yes, how could it do that?
Well, the combination of device, operation, offset, bytes.
Do you think there should be an ID like a u64 counter per BlockBackend?
Quoted 5 lines
Please use the revised syntax for introductions:
##
# @BLOCK_IO_DONE: Emitted on completion for disk operations that
# previously emitted aBLOCK_IO_DELAYevent.
Sure.
Quoted 9 lines
qapi/block.json line 705
Quoted 8 lines
qapi/block.json +8
-0+# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if availableOut of curiosity: when could @offset be unavailable?
For flushes.
Quoted 5 lines
qapi/block.json line 709
Quoted 4 lines
qapi/block.json +4
-0+# +# @bytes: Request length +# +# @failed: If true, this request failed for any reason. If false, theSuggest "for some reason".
Sure!
Hanna
Quoted 12 lines
Quoted 12 lines
qapi/block.json +12
-0+# request succeeded. +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DONE', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + '*offset': 'uint64', + 'bytes': 'uint64', + 'failed': 'bool' } }
Re: [PATCH v2 07/12] qapi/block: Add BLOCK_IO_DONE event
Quoted 45 lines · Hanna Czenczek
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Hanna Czenczek
This event is emitted when an operation completes, for which a
BLOCK_IO_DELAYevent has previously been emitted.Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)Quoted 13 lines
qapi/block.json line 664
Quoted 10 lines
qapi/block.json +2
-0@@ -660,6 +660,9 @@ # Note that delays deliberately incurred by throttling do count # towards the operation duration. # +# This event will only be emitted once per request and action. When +# the operation does finish, a `BLOCK_IO_DONE` event is emitted.I think the first sentence answers a question I had on the previous patch. Move it there?
Sure.
Quoted 18 lines
Quoted 5 lines
qapi/block.json +1
-0+# # @qom-path: path to the block device object in the QOM tree # # @operation: I/O operationqapi/block.json line 697
Quoted 9 lines
qapi/block.json +6
-0@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event.Can we have multiple operations in flight that previously emitted
BLOCK_IO_DELAY?
Quoted 8 lines
Quoted 4 lines
If yes, might a management application need to connect the
BLOCK_IO_DONEback to theBLOCK_IO_DELAY?If yes, how could it do that?
Well, the combination of device, operation, offset, bytes.
Do you think there should be an ID like a u64 counter per BlockBackend?
I'm not overly particular on how exactly the connection can be made. If the quadruple you suggested always suffices, that's good enough for me. Documentation should point it out, though.
Can multiple operations with the same (device, operation, offset, bytes) be in flight?
Quoted 19 lines
Quoted 5 lines
Please use the revised syntax for introductions:
##
# @BLOCK_IO_DONE: Emitted on completion for disk operations that
# previously emitted aBLOCK_IO_DELAYevent.Sure.
Quoted 10 lines
qapi/block.json line 705
Quoted 8 lines
qapi/block.json +8
-0+# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if availableOut of curiosity: when could @offset be unavailable?
Quoted 1 line
For flushes.
Uh, what's @bytes then?
Quoted 23 lines
Quoted 6 lines
qapi/block.json line 709
Quoted 4 lines
qapi/block.json +4
-0+# +# @bytes: Request length +# +# @failed: If true, this request failed for any reason. If false, theSuggest "for some reason".
Sure!
Hanna
Quoted 12 lines
Quoted 12 lines
qapi/block.json +12
-0+# request succeeded. +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DONE', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + '*offset': 'uint64', + 'bytes': 'uint64', + 'failed': 'bool' } }
Re: [PATCH v2 07/12] qapi/block: Add BLOCK_IO_DONE event
Quoted 50 lines · Markus Armbruster
Quoted 48 lines · Hanna Czenczek
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Hanna Czenczek
This event is emitted when an operation completes, for which a
BLOCK_IO_DELAYevent has previously been emitted.Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)Quoted 12 lines
qapi/block.json line 664
Quoted 10 lines
qapi/block.json +2
-0@@ -660,6 +660,9 @@ # Note that delays deliberately incurred by throttling do count # towards the operation duration. # +# This event will only be emitted once per request and action. When +# the operation does finish, a `BLOCK_IO_DONE` event is emitted.I think the first sentence answers a question I had on the previous patch. Move it there?
Sure.
Quoted 17 lines
Quoted 5 lines
qapi/block.json +1
-0+# # @qom-path: path to the block device object in the QOM tree # # @operation: I/O operationqapi/block.json line 697
Quoted 9 lines
qapi/block.json +6
-0@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event.Can we have multiple operations in flight that previously emitted
BLOCK_IO_DELAY?Quoted 4 lines
If yes, might a management application need to connect the
BLOCK_IO_DONEback to theBLOCK_IO_DELAY?If yes, how could it do that?
Well, the combination of device, operation, offset, bytes.
Quoted 7 lines
Quoted 1 line
Do you think there should be an ID like a u64 counter per BlockBackend?
I'm not overly particular on how exactly the connection can be made. If the quadruple you suggested always suffices, that's good enough for me. Documentation should point it out, though.
Can multiple operations with the same (device, operation, offset, bytes) be in flight?
Technically, sure.
Adding an ID is quite ugly, I feel like, which is why I would need your input in how it would be least intrusive in QAPI.
(Caveat, at this point: I’m afraid I’ll be quite far from my notebook for around four weeks… Thank you for your help so far :))
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
Please use the revised syntax for introductions:
##
# @BLOCK_IO_DONE: Emitted on completion for disk operations that
# previously emitted aBLOCK_IO_DELAYevent.Sure.
Quoted 9 lines
qapi/block.json line 705
Quoted 8 lines
qapi/block.json +8
-0+# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if availableOut of curiosity: when could @offset be unavailable?
Quoted 2 lines
Quoted 1 line
For flushes.
Uh, what's @bytes then?
0. I found that natural. Any offset value is a valid offset, but a value of 0 for bytes sounded good to me.
I now anticipate discomfort with this, so I can make @bytes optional, too, yes.
Hanna
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
qapi/block.json line 709
Quoted 4 lines
qapi/block.json +4
-0+# +# @bytes: Request length +# +# @failed: If true, this request failed for any reason. If false, theSuggest "for some reason".
Sure!
Hanna
Quoted 12 lines
Quoted 12 lines
qapi/block.json +12
-0+# request succeeded. +# +# Since: 11.2 +## +{ 'event': 'BLOCK_IO_DONE', + 'data': { + 'qom-path': 'str', + 'operation': 'IoAccountingOperation', + 'latency-ns': 'uint64', + '*offset': 'uint64', + 'bytes': 'uint64', + 'failed': 'bool' } }
Re: [PATCH v2 07/12] qapi/block: Add BLOCK_IO_DONE event
Quoted 18 lines · Hanna Czenczek
Quoted 17 lines · Markus Armbruster
Quoted 15 lines · Hanna Czenczek
Quoted 14 lines · Markus Armbruster
Quoted 12 lines · Hanna Czenczek
This event is emitted when an operation completes, for which a
BLOCK_IO_DELAYevent has previously been emitted.Signed-off-by Hanna Czenczek <[email protected]>--- qapi/block.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)qapi/block.json +0
-0
[...]
Quoted 28 lines
Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
qapi/block.json line 697
Quoted 10 lines
qapi/block.json +6
-0@@ -686,3 +689,33 @@ 'action': 'BlockErrorAction', '*offset': 'uint64', 'bytes': 'uint64' } } + +## +# @BLOCK_IO_DONE: +# +# Emitted on completion for disk operations that previously emitted a +# `BLOCK_IO_DELAY` event.Can we have multiple operations in flight that previously emitted
BLOCK_IO_DELAY?If yes, might a management application need to connect the
BLOCK_IO_DONEback to theBLOCK_IO_DELAY?Quoted 6 lines
Quoted 1 line
If yes, how could it do that?
Well, the combination of device, operation, offset, bytes.
Do you think there should be an ID like a u64 counter per BlockBackend?
I'm not overly particular on how exactly the connection can be made. If the quadruple you suggested always suffices, that's good enough for me. Documentation should point it out, though.
Quoted 6 lines
Quoted 2 lines
Can multiple operations with the same (device, operation, offset, bytes) be in flight?
Technically, sure.
Adding an ID is quite ugly, I feel like, which is why I would need your input in how it would be least intrusive in QAPI.
First step is to get a clearer idea on what exactly management applications need here.
Quoted 1 line
(Caveat, at this point: I’m afraid I’ll be quite far from my notebook for around four weeks… Thank you for your help so far :))
No problem!
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
qapi/block.json line 705
Quoted 8 lines
qapi/block.json +8
-0+# +# @qom-path: path to the block device object in the QOM tree +# +# @operation: I/O operation +# +# @latency-ns: Full duration of the operation (in nanoseconds) +# +# @offset: Request offset in the guest disk (in bytes), if availableOut of curiosity: when could @offset be unavailable?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
For flushes.
Uh, what's @bytes then?
0. I found that natural. Any offset value is a valid offset, but a value of 0 for bytes sounded good to me.
I now anticipate discomfort with this, so I can make @bytes optional, too, yes.
How much a flush writes and where is not known here. We can use 0 for "unknown" as long as we document it. "Absent" feels like the more obvious choice to me, though. Advice, not a demand.
Same logic arguagbly applies to @offset, too.
Regardless, the special case "flush" needs to be documented.
[...]
PATCH v2 8/12 block-backend: Public blk_get_attached_dev_path()
In reply to Hanna CzenczekMake blk_get_attached_dev_path() public so we can use it in the I/O operation delay QMP event to identify the affected guest block device.
--- include/system/block-backend-io.h | 9 +++++++++ block/block-backend.c | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-)
include/system/block-backend-io.h +9 -0
@@ -41,6 +41,15 @@ bool blk_iostatus_is_enabled(const BlockBackend *blk);*/ char *blk_get_attached_dev_id (BlockBackend *blk); +/* +* Return the QOM path of the block device attached to the +* BlockBackend. +* +* The caller is responsible for releasing the value returned +* with g_free() after use. +*/ +char *blk_get_attached_dev_path (BlockBackend *blk); +BlockAIOCB *blk_aio_pwrite_zeroes (BlockBackend *blk,int64_t offset,int64_t bytes,BdrvRequestFlags flags,BlockCompletionFunc *cb,void *opaque);
block/block-backend.c +1 -5
@@ -1054,11 +1054,7 @@ char *blk_get_attached_dev_id(BlockBackend *blk)return blk_get_attached_dev_id_or_path (blk, true); } -/* -* The caller is responsible for releasing the value returned -* with g_free() after use. -*/ -static char *blk_get_attached_dev_path (BlockBackend *blk) +char *blk_get_attached_dev_path (BlockBackend *blk) {return blk_get_attached_dev_id_or_path (blk, false); }
Signature · 1 line
2.55.0
PATCH v2 9/12 host-utils: Add u{add,sub}{32,64}_saturate()
In reply to Hanna CzenczekAdd saturating addition/subtraction functions for unsigned 32 and 64 bit values.
--- include/qemu/host-utils.h | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
include/qemu/host-utils.h +62 -0
@@ -636,6 +636,36 @@ static inline int64_t sadd64_saturate(int64_t x, int64_t y)return ret; } +/** +* uadd32_saturate - 32-bit unsigned addition with saturation +* @x, @y: addends +* +* Computes @x + @y, and saturates rather than truncating the result. +*/ +static inline uint32_t uadd32_saturate (uint32_t x,uint32_t y) +{ +uint32_t ret; +if (uadd32_overflow (x, y, &ret)) { + ret =UINT32_MAX ; + } +return ret; +} + +/** +* uadd64_saturate - 64-bit unsigned addition with saturation +* @x, @y: addends +* +* Computes @x + @y, and saturates rather than truncating the result. +*/ +static inline uint64_t uadd64_saturate (uint64_t x,uint64_t y) +{ +uint64_t ret; +if (uadd64_overflow (x, y, &ret)) { + ret =UINT64_MAX ; + } +return ret; +} +/** * ssub32_saturate - 32-bit signed subtraction with saturation * @x, @y: addends
@@ -666,6 +696,38 @@ static inline int64_t ssub64_saturate(int64_t x, int64_t y)return ret; } +/** +* usub32_saturate - 32-bit unsigned subtraction with saturation +* @x: Minuend +* @y: Subtrahend +* +* Computes @x - @y, and saturates rather than truncating the result. +*/ +static inline uint32_t usub32_saturate (uint32_t x,uint32_t y) +{ +uint32_t ret; +if (usub32_overflow (x, y, &ret)) { + ret =0 ; + } +return ret; +} + +/** +* usub64_saturate - 64-bit unsigned subtraction with saturation +* @x: Minuend +* @y: Subtrahend +* +* Computes @x - @y, and saturates rather than truncating the result. +*/ +static inline uint64_t usub64_saturate (uint64_t x,uint64_t y) +{ +uint64_t ret; +if (usub64_overflow (x, y, &ret)) { + ret =0 ; + } +return ret; +} +/* * Unsigned 128x64 multiplication. * Returns true if the result got truncated to 128 bits.
Signature · 1 line
2.55.0
PATCH v2 10/12 block: Per-request delay tracker
In reply to Hanna CzenczekRegister I/O requests to BlockBackends with a per-BB timer running in the background (in the main context) that goes through the list of requests to find any that surpass a user-defined[1] threshold and then emit a QMP event calling this out, or stopping the VM altogether so the guest can be shielded of absolutely excessive delay.
One example for where stopping may be useful: Windows will cancel requests after a set timeout, but virtio-blk does not support cancelling requests (by design, I understand). So it will cancel again, and again, and then reset the whole driver (which however won’t cancel the request either), and eventually declare the driver faulty and show a BSOD. The only ways around this would be to implement request cancellation (which I think is not generally possible), or, well, pause the VM in case of absolutely excessive I/O request delay, and resume it when the request is done (BLOCK_IO_DONE event), so that Windows will not see that massive delay.
[1] Not yet user-defined in this commit, but a future commit will allow users to specify the threshold when to take action, on the guest device.
--- include/block/block-backend-delay.h | 112 +++++++ include/system/block-backend-global-state.h | 11 + block/block-backend-delay.c | 326 ++++++++++++++++++++ block/block-backend.c | 44 ++- block/meson.build | 1 + 5 files changed, 492 insertions(+), 2 deletions(-) create mode 100644 include/block/block-backend-delay.h create mode 100644 block/block-backend-delay.c
include/block/block-backend-delay.h new file +112 -0
@@ -0,0 +1,112 @@ +/* +* Copyright (c) 2026 Hanna Czenczek <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef BLOCK_BACKEND_DELAY_H +#define BLOCK_BACKEND_DELAY_H + +#include "qemu/thread.h" +#include "qemu/timer.h" +#include "qapi/qapi-types-block.h" + +/* Enumeration of I/O delay threshold types */ +enum BlockDelayThreshold { +/* Latency threshold at which to report a delay */ +BLOCK_DELAY_REPORT , +/* Latency threshold at which to auto-stop the VM */ +BLOCK_DELAY_STOP , + +/* Number of different thresholds */ +BLOCK_DELAY__MAX , +}; + +typedef struct BlockDelayTracker { +/* Timer to regularly check requests for delay */ +QEMUTimer *timer; + +/* Which clock to use */ +QEMUClockType clock_type; + +/* +* Protects access to all subsequent fields in this struct. Do not take any +* other lock while this lock is taken. +*/ +QemuMutex lock; + +/* Thresholds for generating delay report events or stopping the VM */ +uint64_t threshold_ns[BLOCK_DELAY__MAX ]; + +/* List of active requests; new requests appended at the end */ + QTAILQ_HEAD(, BlockDelayTrackerRequest) requests; +}BlockDelayTracker ; + +typedef struct BlockDelayTrackerRequest { +/* offset < 0 means no valid offset */ +int64_t offset; +/* Request length, or 0 if no valid length */ +uint64_t bytes; +/* When the request was started */ +uint64_t start_time_ns; +/* Operation type */ +IoAccountingOperation op_type; +/* +* Whether any delay threshold has been exceeded. +* If so, we need to emit BLOCK_IO_DONE when the request is done. +*/ +bool threshold_exceeded[BLOCK_DELAY__MAX ]; +/* +* Set the first time any threshold is exceeded, to cache the device name +* for BLOCK_IO_DONE. +*/ +char *device_path; + +/* Entry in the list of all running requests for this BB */ +QTAILQ_ENTRY (BlockDelayTrackerRequest) list; +}BlockDelayTrackerRequest ; + +/** +* Set up the request latency delay tracker for this BlockBackend. +* +* The caller must allocate blk->delay_tracker beforehand (because +* block-backend-delay.c cannot access BlockBackend fields directly). +*/ +void blk_delay_tracker_init (BlockBackend *blk); + +/** +* Stop and destroy the request latency delay tracker for this BlockBackend. +*/ +void blk_delay_tracker_destroy (BlockDelayTracker *bdt); + +/** +* Return the latency delay tracker object for the given BlockBackend. +* +* (Implemented in block-backend.c, where the BlockBackend definition resides.) +*/ +BlockDelayTracker *blk_delay_tracker (BlockBackend *blk); + +/** +* Begin tracking an I/O request on @blk of type @op_type over @bytes starting +* from @offset. +* +* @request is initialized by this function. +* +* Use offset=-1 for operations that have no valid offset (e.g. flush). +*/ +void blk_track_delay_begin (BlockBackend *blk, +BlockDelayTrackerRequest *request, +int64_t offset, +uint64_t bytes, +IoAccountingOperation op_type); +/** +* Finalize I/O request tracking. +* +* @ret indicates the operation's status, with 0 for success and -errno for +* errors. +*/ +void blk_track_delay_end (BlockBackend *blk, +BlockDelayTrackerRequest *request, +int ret); + +#endif
include/system/block-backend-global-state.h +11 -0
@@ -102,6 +102,17 @@ void blk_update_root_state(BlockBackend *blk);bool blk_get_detect_zeroes_from_root_state (BlockBackend *blk);int blk_get_open_flags_from_root_state (BlockBackend *blk); +/** +* Set the nanosecond threshold for per-request latency, when to consider it +* sufficient of a delay to report via BLOCK_IO_DELAY QMP event. +*/ +void blk_set_delay_report_threshold (BlockBackend *blk,uint64_t ns); +/** +* Set the nanosecond threshold for per-request latency, when to consider it +* sufficient of a delay to stop the VM. +*/ +void blk_set_delay_stop_threshold (BlockBackend *blk,uint64_t ns); +int blk_save_vmstate (BlockBackend *blk,const uint8_t *buf,int64_t pos,int size);int blk_load_vmstate (BlockBackend *blk,uint8_t *buf,int64_t pos,int size);
block/block-backend-delay.c new file +326 -0
326 lines not on this page · raw message
block/block-backend.c +42 -2
147 lines not on this page · raw message
block/meson.build +1 -0
@@ -8,6 +8,7 @@ block_ss.add(files( 'blklogwrites.c', 'blkverify.c', 'block-backend.c', + 'block-backend-delay.c', 'block-copy.c', 'commit.c', 'copy-before-write.c',
Signature · 1 line
2.55.0
PATCH v2 11/12 block: Add delay-report-ns and delay-stop-ns props
In reply to Hanna CzenczekThese device properties allow setting up I/O latency thresholds for when to report an I/O operation delay via QMP event (BLOCK_IO_DELAY) or when to stop the VM.
--- include/hw/block/block.h | 8 +++- blockdev.c | 16 ++++++++ hw/block/block.c | 7 ++++ tests/qemu-iotests/172.out | 76 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-)
include/hw/block/block.h +7 -1
@@ -36,6 +36,8 @@ typedef struct BlockConf {BlockdevOnError werror;uint32_t num_stats_intervals;uint32_t *stats_intervals; +uint64_t delay_report_ns; +uint64_t delay_stop_ns; } BlockConf;static inline unsigned int get_physical_block_exp (BlockConf *conf)
@@ -83,7 +85,11 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.account_failed, ON_OFF_AUTO_AUTO), \DEFINE_PROP_ARRAY ("stats-intervals" , _state, \ _conf.num_stats_intervals, _conf.stats_intervals, \ - qdev_prop_uint32, uint32_t) + qdev_prop_uint32, uint32_t), \ +DEFINE_PROP_UINT64 ("delay-report-ns" , _state, _conf.delay_report_ns,\ +0 ), \ +DEFINE_PROP_UINT64 ("delay-stop-ns" , _state, _conf.delay_stop_ns, \ + 0)#define DEFINE_BLOCK_PROPERTIES (_state, _conf) \ DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
blockdev.c +16 -0
@@ -496,6 +496,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,BlockdevDetectZeroesOptions detect_zeroes =BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF ;const char *throttling_group =NULL ; +uint64_t delay_report_ns, delay_stop_ns;/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */
@@ -580,6 +581,9 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, read_only =qemu_opt_get_bool (opts,BDRV_OPT_READ_ONLY , false); + delay_report_ns =qemu_opt_get_number (opts,"delay-report-ns" ,0 ); + delay_stop_ns =qemu_opt_get_number (opts,"delay-stop-ns" ,0 ); +/* init */ if ((!file || !*file) && !qdict_size (bs_opts)) {BlockBackendRootState *blk_rs;
@@ -615,6 +619,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts, } bs =blk_bs (blk); +blk_set_delay_report_threshold (blk, delay_report_ns); +blk_set_delay_stop_threshold (blk, delay_stop_ns); bs->detect_zeroes = detect_zeroes; block_acct_setup(blk_get_stats(blk), account_invalid, account_failed,
@@ -3753,6 +3759,16 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_BOOL, .help = "whether to account for failed I/O operations " "in the statistics", + },{ + .name = "delay-report-ns", + .type = QEMU_OPT_NUMBER, + .help = "threshold in ns when to report an I/O operation " + "delay via QMP event", + },{ + .name = "delay-stop-ns", + .type = QEMU_OPT_NUMBER, + .help = "threshold in ns when to pause the VM because " + "of an I/O operation delay", }, {/* end of list */ } },
hw/block/block.c +7 -0
@@ -249,6 +249,13 @@ bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,blk_set_enable_write_cache (blk, wce);blk_set_on_error (blk, rerror, werror); +if (conf->delay_report_ns) { +blk_set_delay_report_threshold (blk, conf->delay_report_ns); + } +if (conf->delay_stop_ns) { +blk_set_delay_stop_threshold (blk, conf->delay_stop_ns); + } +if (!block_acct_setup (blk_get_stats (blk), conf->account_invalid, conf->account_failed, conf->stats_intervals, conf->num_stats_intervals, errp)) {
tests/qemu-iotests/172.out +76 -0
304 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v2 12/12 iotests: Add io-delay-reporting test
In reply to Hanna CzenczekTest delay-report-ns and delay-stop-ns via HMP qemu-io (break, aio_read, resume) on a null node (with blkdebug).
--- tests/qemu-iotests/tests/io-delay-reporting | 187 ++++++++++++++++++ .../qemu-iotests/tests/io-delay-reporting.out | 90 +++++++++ 2 files changed, 277 insertions(+) create mode 100755 tests/qemu-iotests/tests/io-delay-reporting create mode 100644 tests/qemu-iotests/tests/io-delay-reporting.out
tests/qemu-iotests/tests/io-delay-reporting new file +187 -0
@@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +# group: rw +# +# Test the I/O delay QMP event. +# +# Copyright (C) 2026 Red Hat, Inc. +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Creator/Owner: Hanna Czenczek <[email protected]> + +import asyncio +import iotests +from iotests import filter_qmp_event, log + +DELAY_REPORT_MS = 5000 # ms +DELAY_STOP_MS = 10000 # ms +EPSILON_MS = 50 # ms -- small delta that can safely be added/subtracted +NS_PER_MS = 1000 * 1000 +DELAY_REPORT_NS = DELAY_REPORT_MS * NS_PER_MS +DELAY_STOP_NS = DELAY_STOP_MS * NS_PER_MS + +qtest_clock = 0 # ms + +iotests.script_initialize() + +def vm_qemu_io(qvm, virtio_blk_id, cmd): + log(f'[HMP] qemu-io to {virtio_blk_id}: {cmd}') + command_line=f'qemu-io -d {virtio_blk_id}/virtio-backend "{cmd}"' + log(qvm.qmp('human-monitor-command', command_line=command_line)) + +def advance_clock_to(qvm, clock_ms): + """ + Retain the current absolute clock time so we can step *to* a specific time + via `clock_step`. + """ + + # pylint does not like global much, but this is a test script, and not + # using global would just make this more complicated. + global qtest_clock # pylint: disable=global-statement + msecs = clock_ms - qtest_clock + log(f'[qtest] clock_step {msecs}ms to {clock_ms}ms') + qvm.qtest(f'clock_step {msecs * NS_PER_MS}') + qtest_clock += msecs + +def reset_clock(): + """ + Reset the internal qtest clock to 0; use before launching a new VM. + """ + + global qtest_clock # pylint: disable=global-statement + qtest_clock = 0 + +def await_event(qvm, match): + evt = qvm.event_wait(match, timeout=30.0) + assert evt is not None + return evt + +def assert_no_event(qvm, event_name): + try: + evt = qvm.event_wait(event_name, timeout=0.1) + assert evt is None, f'Unexpected {event_name} event: {evt}' + except asyncio.TimeoutError: + pass + log(f'(No {event_name} event)') + +def run(error): + """ + If @error is False, run both requests normally. + If it is True, inject an error into the second one. + """ + + log('') + log(f'=== Running tests with error={error} ===') + log('') + + reset_clock() + with iotests.VM() as vm: + # Cannot use null-co.latency-ns, as that uses realtime (not qtest time) + # Need to use raw to get the read_aio event working + opts = { + 'driver': 'raw', + 'node-name': 'test-node', + 'file': { + 'driver': 'blkdebug', + 'image': { + 'driver': 'null-co', + }, + }, + } + if error: + opts['file']['inject-error'] = [{ + 'event': 'read_aio', + 'iotype': 'read', + 'sector': str(4096 // 512), + 'once': 'on', + }] + vm.add_blockdev(vm.qmp_to_opts(opts)) + + vm.launch() + + log(f'[QMP] device_add id=vblk delay-report-ns={DELAY_REPORT_NS} ' + f'delay-stop-ns={DELAY_STOP_NS}') + log(vm.qmp('device_add', { + 'driver': 'virtio-blk', + 'id': 'vblk', + 'drive': 'test-node', + 'delay-report-ns': DELAY_REPORT_NS, + 'delay-stop-ns': DELAY_STOP_NS, + })) + + try: + vm_qemu_io(vm, 'vblk', 'break read_aio read_0') + vm_qemu_io(vm, 'vblk', 'aio_read 0k 4k') + vm_qemu_io(vm, 'vblk', 'wait_break read_0') + + vm_qemu_io(vm, 'vblk', 'break read_aio read_1') + vm_qemu_io(vm, 'vblk', 'aio_read 4k 4k') + vm_qemu_io(vm, 'vblk', 'wait_break read_1') + + advance_clock_to(vm, DELAY_REPORT_MS - EPSILON_MS) + + # Assert there is no event before the step + assert_no_event(vm, 'BLOCK_IO_DELAY') + + advance_clock_to(vm, DELAY_REPORT_MS) + + # But now there should be, right on time + events = [await_event(vm, 'BLOCK_IO_DELAY'), + await_event(vm, 'BLOCK_IO_DELAY')] + events.sort(key=lambda event: event['data']['offset']) + for event in events: + log(event, filters=[filter_qmp_event]) + + # Have the read_0 request finish -- advance clock to test the + # correct duration + advance_clock_to(vm, DELAY_REPORT_MS + EPSILON_MS) + vm_qemu_io(vm, 'vblk', 'resume read_0') + log(await_event(vm, 'BLOCK_IO_DONE'), filters=[filter_qmp_event]) + + # Let read_1 hang for longer to trigger a STOP + advance_clock_to(vm, DELAY_STOP_MS) + + # Read the pre-STOP notification + log(await_event(vm, 'BLOCK_IO_DELAY'), filters=[filter_qmp_event]) + + # Then the actual STOP + log(await_event(vm, 'STOP'), filters=[filter_qmp_event]) + log('[QMP] query-status') + log(vm.qmp('query-status')) + + # Have the read_1 request finish + advance_clock_to(vm, DELAY_STOP_MS + EPSILON_MS) + vm_qemu_io(vm, 'vblk', 'resume read_1') + log(await_event(vm, 'BLOCK_IO_DONE'), filters=[filter_qmp_event]) + + log('[QMP] cont') + log(vm.qmp('cont')) + log(await_event(vm, 'RESUME'), filters=[filter_qmp_event]) + log('[QMP] query-status') + log(vm.qmp('query-status')) + except Exception: + # The VM will not be able to quit without these requests finished, + # which (without this block) would make the test hang instead of + # exit if something unexpected goes wrong + vm_qemu_io(vm, 'vblk', 'resume read_0') + vm_qemu_io(vm, 'vblk', 'resume read_1') + raise + + # Test device unplug to verify that stopping the delay tracking timer + # works + log('[QMP] device_del id=vblk') + log(vm.qmp('device_del', id='vblk')) + + # system_reset forces the device unplug to happen + log('[QMP] system_reset') + log(vm.qmp('system_reset')) + + event = vm.event_wait('DEVICE_DELETED', 20.0, + {'data': {'device': 'vblk'}}) + assert event is not None + log(event, filters=[filter_qmp_event]) + + vm.shutdown() + +run(False) +run(True)
tests/qemu-iotests/tests/io-delay-reporting.out new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.55.0