* [PATCH] blockdev: Fix blockdev-snapshot-sync error reporting for no medium
@ 2024-03-06 14:28 Markus Armbruster
2024-03-18 11:47 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2024-03-06 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, hreitz, qemu-block, qemu-trivial
When external_snapshot_abort() rejects a BlockDriverState without a
medium, it creates an error like this:
error_setg(errp, "Device '%s' has no medium", device);
Trouble is @device can be null. My system formats null as "(null)",
but other systems might crash. Reproducer:
1. Create a block device without a medium
-> {"execute": "blockdev-add", "arguments": {"driver": "host_cdrom", "node-name": "blk0", "filename": "/dev/sr0"}}
<- {"return": {}}
3. Attempt to snapshot it
-> {"execute":"blockdev-snapshot-sync", "arguments": { "node-name": "blk0", "snapshot-file":"/tmp/foo.qcow2","format":"qcow2"}}
<- {"error": {"class": "GenericError", "desc": "Device '(null)' has no medium"}}
Broken when commit 0901f67ecdb made @device optional.
Use bdrv_get_device_or_node_name() instead. Now it fails as it
should:
<- {"error": {"class": "GenericError", "desc": "Device 'blk0' has no medium"}}
Fixes: 0901f67ecdb7 (qmp: Allow to take external snapshots on bs graphs node.)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
blockdev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/blockdev.c b/blockdev.c
index d8fb3399f5..057601dcf0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1395,7 +1395,8 @@ static void external_snapshot_action(TransactionAction *action,
bdrv_drained_begin(state->old_bs);
if (!bdrv_is_inserted(state->old_bs)) {
- error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
+ error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM,
+ bdrv_get_device_or_node_name(state->old_bs));
return;
}
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] blockdev: Fix blockdev-snapshot-sync error reporting for no medium
2024-03-06 14:28 [PATCH] blockdev: Fix blockdev-snapshot-sync error reporting for no medium Markus Armbruster
@ 2024-03-18 11:47 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2024-03-18 11:47 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, hreitz, qemu-block, qemu-trivial
Am 06.03.2024 um 15:28 hat Markus Armbruster geschrieben:
> When external_snapshot_abort() rejects a BlockDriverState without a
> medium, it creates an error like this:
>
> error_setg(errp, "Device '%s' has no medium", device);
>
> Trouble is @device can be null. My system formats null as "(null)",
> but other systems might crash. Reproducer:
>
> 1. Create a block device without a medium
>
> -> {"execute": "blockdev-add", "arguments": {"driver": "host_cdrom", "node-name": "blk0", "filename": "/dev/sr0"}}
> <- {"return": {}}
>
> 3. Attempt to snapshot it
>
> -> {"execute":"blockdev-snapshot-sync", "arguments": { "node-name": "blk0", "snapshot-file":"/tmp/foo.qcow2","format":"qcow2"}}
> <- {"error": {"class": "GenericError", "desc": "Device '(null)' has no medium"}}
>
> Broken when commit 0901f67ecdb made @device optional.
>
> Use bdrv_get_device_or_node_name() instead. Now it fails as it
> should:
>
> <- {"error": {"class": "GenericError", "desc": "Device 'blk0' has no medium"}}
>
> Fixes: 0901f67ecdb7 (qmp: Allow to take external snapshots on bs graphs node.)
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-18 11:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-06 14:28 [PATCH] blockdev: Fix blockdev-snapshot-sync error reporting for no medium Markus Armbruster
2024-03-18 11:47 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).