]> git.ipfire.org Git - thirdparty/qemu.git/commit
block: Fix crash when loading snapshot on inactive node
authorKevin Wolf <kwolf@redhat.com>
Fri, 1 Dec 2023 14:25:18 +0000 (15:25 +0100)
committerMichael Tokarev <mjt@tls.msk.ru>
Fri, 22 Dec 2023 19:25:28 +0000 (22:25 +0300)
commitb769a8e472be68215ba6431f6e91d4bf8f537ff4
tree49e4fcbfa41ae386a63dc68da25835c4778e9dee
parentc95e38d33beb9e6a5563a951e3087ea5360ee598
block: Fix crash when loading snapshot on inactive node

bdrv_is_read_only() only checks if the node is configured to be
read-only eventually, but even if it returns false, writing to the node
may not be permitted at the moment (because it's inactive).

bdrv_is_writable() checks that the node can be written to right now, and
this is what the snapshot operations really need.

Change bdrv_can_snapshot() to use bdrv_is_writable() to fix crashes like
the following:

$ ./qemu-system-x86_64 -hda /tmp/test.qcow2 -loadvm foo -incoming defer
qemu-system-x86_64: ../block/io.c:1990: int bdrv_co_write_req_prepare(BdrvChild *, int64_t, int64_t, BdrvTrackedRequest *, int): Assertion `!(bs->open_flags & BDRV_O_INACTIVE)' failed.

The resulting error message after this patch isn't perfect yet, but at
least it doesn't crash any more:

$ ./qemu-system-x86_64 -hda /tmp/test.qcow2 -loadvm foo -incoming defer
qemu-system-x86_64: Device 'ide0-hd0' is writable but does not support snapshots

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231201142520.32255-2-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit d3007d348adaaf04ee8b099a475282034a662414)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
block/snapshot.c