* [PULL 0/4] Block layer patches
@ 2019-09-20 16:20 Kevin Wolf
2019-09-23 9:49 ` Peter Maydell
0 siblings, 1 reply; 13+ messages in thread
From: Kevin Wolf @ 2019-09-20 16:20 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, peter.maydell, qemu-devel
The following changes since commit 521db80318d6c749a6f6c5a65a68397af9e3ef16:
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-09-16' into staging (2019-09-16 15:25:55 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to d2c8c09fca9210d0f2399c8d570086a4a66bd22e:
iotests: Remove Python 2 compatibility code (2019-09-20 17:58:51 +0200)
----------------------------------------------------------------
Block layer patches:
- Fix internal snapshots with typical -blockdev setups
- iotests: Require Python 3.6 or later
----------------------------------------------------------------
Kevin Wolf (4):
block/snapshot: Restrict set of snapshot nodes
iotests: Test internal snapshots with -blockdev
iotests: Require Python 3.6 or later
iotests: Remove Python 2 compatibility code
block/snapshot.c | 26 +++--
tests/qemu-iotests/044 | 3 -
tests/qemu-iotests/163 | 3 -
tests/qemu-iotests/267 | 168 ++++++++++++++++++++++++++++
tests/qemu-iotests/267.out | 182 +++++++++++++++++++++++++++++++
tests/qemu-iotests/check | 13 ++-
tests/qemu-iotests/common.filter | 5 +-
tests/qemu-iotests/group | 1 +
tests/qemu-iotests/iotests.py | 13 +--
tests/qemu-iotests/nbd-fault-injector.py | 7 +-
10 files changed, 389 insertions(+), 32 deletions(-)
create mode 100755 tests/qemu-iotests/267
create mode 100644 tests/qemu-iotests/267.out
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PULL 0/4] Block layer patches
2019-09-20 16:20 Kevin Wolf
@ 2019-09-23 9:49 ` Peter Maydell
0 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2019-09-23 9:49 UTC (permalink / raw)
To: Kevin Wolf; +Cc: QEMU Developers, Qemu-block
On Fri, 20 Sep 2019 at 17:21, Kevin Wolf <kwolf@redhat.com> wrote:
>
> The following changes since commit 521db80318d6c749a6f6c5a65a68397af9e3ef16:
>
> Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-09-16' into staging (2019-09-16 15:25:55 +0100)
>
> are available in the Git repository at:
>
> git://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to d2c8c09fca9210d0f2399c8d570086a4a66bd22e:
>
> iotests: Remove Python 2 compatibility code (2019-09-20 17:58:51 +0200)
>
> ----------------------------------------------------------------
> Block layer patches:
>
> - Fix internal snapshots with typical -blockdev setups
> - iotests: Require Python 3.6 or later
>
> ----------------------------------------------------------------
> Kevin Wolf (4):
> block/snapshot: Restrict set of snapshot nodes
> iotests: Test internal snapshots with -blockdev
> iotests: Require Python 3.6 or later
> iotests: Remove Python 2 compatibility code
Hi. This fails 'make check' on all the non-x86 Linux hosts:
iotests 267 fails on aarch32, ppc64, s390x, aarch64.
Sample output from the aarch32 run; others are similar
but the listed snapshot size differs.
TEST iotest-qcow2: 267 [fail]
QEMU --
"/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/../../aarch64-softmmu/qemu-system-aarch64"
-nodefaults -display none
-machine virt,accel=qtest
QEMU_IMG --
"/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/../../qemu-img"
QEMU_IO --
"/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/../../qemu-io"
--cache writeback -f qcow2
QEMU_NBD --
"/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/../../qemu-nbd"
IMGFMT -- qcow2 (compat=1.1)
IMGPROTO -- file
PLATFORM -- Linux/aarch64 mustang-maydell 4.15.0-51-generic
TEST_DIR --
/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/scratch
SOCKET_SCM_HELPER --
/home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/socket_scm_helper
--- /home/peter.maydell/qemu/tests/qemu-iotests/267.out 2019-09-20
17:54:40.127012142 +0000
+++ /home/peter.maydell/qemu/build/all-a32/tests/qemu-iotests/267.out.bad
2019-09-20 18:02:11.756586745 +0000
@@ -34,7 +34,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -45,7 +45,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 636 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 684 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -70,7 +70,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 636 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 684 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -95,7 +95,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -106,7 +106,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -120,7 +120,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -135,7 +135,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -146,14 +146,14 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
Internal snapshots on overlay:
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
-1 snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+1 snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
Internal snapshots on backing file:
=== -blockdev with NBD server on the backing file ===
@@ -167,7 +167,7 @@
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK
--- snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+-- snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
(qemu) loadvm snap0
(qemu) quit
@@ -178,5 +178,5 @@
Internal snapshots on backing file:
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
-1 snap0 591 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
+1 snap0 640 KiB yyyy-mm-dd hh:mm:ss 00:00:00.000
*** done
Not run: 172 186 192 220
Failures: 267
Failed 1 of 104 iotests
thanks
-- PMM
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PULL 0/4] Block layer patches
@ 2023-03-28 12:35 Kevin Wolf
2023-03-28 19:42 ` Peter Maydell
0 siblings, 1 reply; 13+ messages in thread
From: Kevin Wolf @ 2023-03-28 12:35 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, peter.maydell, qemu-devel
The following changes since commit e3debd5e7d0ce031356024878a0a18b9d109354a:
Merge tag 'pull-request-2023-03-24' of https://gitlab.com/thuth/qemu into staging (2023-03-24 16:08:46 +0000)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to d8fbf9aa85aed64450907580a1d70583f097e9df:
block/export: Fix graph locking in blk_get_geometry() call (2023-03-27 15:16:05 +0200)
----------------------------------------------------------------
Block layer patches
- aio-posix: Fix race during epoll upgrade
- vhost-user-blk/VDUSE export: Fix a potential deadlock and an assertion
failure when the export runs in an iothread
- NBD server: Push pending frames after sending reply to fix performance
especially when used with TLS
----------------------------------------------------------------
Florian Westphal (1):
nbd/server: push pending frames after sending reply
Kevin Wolf (1):
block/export: Fix graph locking in blk_get_geometry() call
Stefan Hajnoczi (2):
block/export: only acquire AioContext once for vhost_user_server_stop()
aio-posix: fix race between epoll upgrade and aio_set_fd_handler()
include/block/block-io.h | 4 +++-
include/sysemu/block-backend-io.h | 5 ++++-
block.c | 5 +++--
block/block-backend.c | 7 +++++--
block/export/virtio-blk-handler.c | 7 ++++---
nbd/server.c | 3 +++
util/fdmon-epoll.c | 25 ++++++++++++++++++-------
util/vhost-user-server.c | 5 +----
8 files changed, 41 insertions(+), 20 deletions(-)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PULL 0/4] Block layer patches
2023-03-28 12:35 Kevin Wolf
@ 2023-03-28 19:42 ` Peter Maydell
0 siblings, 0 replies; 13+ messages in thread
From: Peter Maydell @ 2023-03-28 19:42 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, qemu-devel
On Tue, 28 Mar 2023 at 13:35, Kevin Wolf <kwolf@redhat.com> wrote:
>
> The following changes since commit e3debd5e7d0ce031356024878a0a18b9d109354a:
>
> Merge tag 'pull-request-2023-03-24' of https://gitlab.com/thuth/qemu into staging (2023-03-24 16:08:46 +0000)
>
> are available in the Git repository at:
>
> https://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to d8fbf9aa85aed64450907580a1d70583f097e9df:
>
> block/export: Fix graph locking in blk_get_geometry() call (2023-03-27 15:16:05 +0200)
>
> ----------------------------------------------------------------
> Block layer patches
>
> - aio-posix: Fix race during epoll upgrade
> - vhost-user-blk/VDUSE export: Fix a potential deadlock and an assertion
> failure when the export runs in an iothread
> - NBD server: Push pending frames after sending reply to fix performance
> especially when used with TLS
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes.
-- PMM
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PULL 0/4] Block layer patches
@ 2023-11-28 14:09 Kevin Wolf
0 siblings, 0 replies; 13+ messages in thread
From: Kevin Wolf @ 2023-11-28 14:09 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, stefanha, qemu-devel
The following changes since commit e867b01cd6658a64c16052117dbb18093a2f9772:
Merge tag 'qga-pull-2023-11-25' of https://github.com/kostyanf14/qemu into staging (2023-11-27 08:59:00 -0500)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 6e081324facf9aeece9c286774bab5af3b8d6099:
ide/via: Fix BAR4 value in legacy mode (2023-11-28 14:56:32 +0100)
----------------------------------------------------------------
Block layer patches
- ide/via: Fix BAR4 value in legacy mode
- export/vhost-user-blk: Fix consecutive drains
- vmdk: Don't corrupt desc file in vmdk_write_cid
- iotests: fix default machine type detection
----------------------------------------------------------------
Andrey Drobyshev (1):
iotests: fix default machine type detection
BALATON Zoltan (1):
ide/via: Fix BAR4 value in legacy mode
Fam Zheng (1):
vmdk: Don't corrupt desc file in vmdk_write_cid
Kevin Wolf (1):
export/vhost-user-blk: Fix consecutive drains
include/qemu/vhost-user-server.h | 1 +
block/export/vhost-user-blk-server.c | 9 +++++++--
block/vmdk.c | 28 ++++++++++++++++++--------
hw/ide/via.c | 17 ++++++++++------
util/vhost-user-server.c | 39 ++++++++++++++++++++++++++++--------
tests/qemu-iotests/testenv.py | 2 +-
tests/qemu-iotests/059 | 2 ++
tests/qemu-iotests/059.out | 4 ++++
8 files changed, 77 insertions(+), 25 deletions(-)
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PULL 0/4] Block layer patches
@ 2025-04-08 13:00 Kevin Wolf
2025-04-08 13:00 ` [PULL 1/4] qemu-img: fix division by zero in bench_cb() for zero-sized images Kevin Wolf
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Kevin Wolf @ 2025-04-08 13:00 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
The following changes since commit dfaecc04c46d298e9ee81bd0ca96d8754f1c27ed:
Merge tag 'pull-riscv-to-apply-20250407-1' of https://github.com/alistair23/qemu into staging (2025-04-07 09:18:33 -0400)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to f8222bfba3409a3ce09c191941127a8cf2c7e623:
test-bdrv-drain: Fix data races (2025-04-08 15:00:01 +0200)
----------------------------------------------------------------
Block layer patches
- scsi-disk: Apply error policy for host_status errors again
- qcow2: Fix qemu-img info crash with missing crypto header
- qemu-img bench: Fix division by zero for zero-sized images
- test-bdrv-drain: Fix data races
----------------------------------------------------------------
Denis Rastyogin (1):
qemu-img: fix division by zero in bench_cb() for zero-sized images
Kevin Wolf (2):
qcow2: Don't crash qemu-img info with missing crypto header
scsi-disk: Apply error policy for host_status errors again
Vitalii Mordan (1):
test-bdrv-drain: Fix data races
include/qemu/job.h | 3 ++
block/qcow2.c | 4 +-
hw/scsi/scsi-disk.c | 39 +++++++++-----
job.c | 6 +++
qemu-img.c | 6 ++-
tests/unit/test-bdrv-drain.c | 32 +++++++-----
tests/qemu-iotests/tests/qcow2-encryption | 75 +++++++++++++++++++++++++++
tests/qemu-iotests/tests/qcow2-encryption.out | 32 ++++++++++++
8 files changed, 167 insertions(+), 30 deletions(-)
create mode 100755 tests/qemu-iotests/tests/qcow2-encryption
create mode 100644 tests/qemu-iotests/tests/qcow2-encryption.out
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PULL 1/4] qemu-img: fix division by zero in bench_cb() for zero-sized images
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
@ 2025-04-08 13:00 ` Kevin Wolf
2025-04-08 13:00 ` [PULL 2/4] qcow2: Don't crash qemu-img info with missing crypto header Kevin Wolf
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Kevin Wolf @ 2025-04-08 13:00 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
From: Denis Rastyogin <gerben@altlinux.org>
This error was discovered by fuzzing qemu-img.
This commit fixes a division by zero error in the bench_cb() function
that occurs when using the bench command with a zero-sized image.
The issue arises because b->image_size can be zero, leading to a
division by zero in the modulo operation (b->offset %= b->image_size).
This patch adds a check for b->image_size == 0 and resets b->offset
to 0 in such cases, preventing the error.
Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
Message-ID: <20250318101933.255617-1-gerben@altlinux.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qemu-img.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/qemu-img.c b/qemu-img.c
index 89c93c1eb5..2044c22a4c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4488,7 +4488,11 @@ static void bench_cb(void *opaque, int ret)
*/
b->in_flight++;
b->offset += b->step;
- b->offset %= b->image_size;
+ if (b->image_size == 0) {
+ b->offset = 0;
+ } else {
+ b->offset %= b->image_size;
+ }
if (b->write) {
acb = blk_aio_pwritev(b->blk, offset, b->qiov, 0, bench_cb, b);
} else {
--
2.49.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PULL 2/4] qcow2: Don't crash qemu-img info with missing crypto header
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
2025-04-08 13:00 ` [PULL 1/4] qemu-img: fix division by zero in bench_cb() for zero-sized images Kevin Wolf
@ 2025-04-08 13:00 ` Kevin Wolf
2025-04-08 13:00 ` [PULL 3/4] scsi-disk: Apply error policy for host_status errors again Kevin Wolf
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Kevin Wolf @ 2025-04-08 13:00 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
qcow2_refresh_limits() assumes that s->crypto is non-NULL whenever
bs->encrypted is true. This is actually not the case: qcow2_do_open()
allows to open an image with a missing crypto header for BDRV_O_NO_IO,
and then bs->encrypted is true, but s->crypto is still NULL.
It doesn't make sense to open an invalid image, so remove the exception
for BDRV_O_NO_IO. This catches the problem early and any code that makes
the same assumption is safe now.
At the same time, in the name of defensive programming, we shouldn't
make the assumption in the first place. Let qcow2_refresh_limits() check
s->crypto rather than bs->encrypted. If s->crypto is NULL, it also can't
make any requirement on request alignment.
Finally, start a qcow2-encryption test case that only serves as a
regression test for this crash for now.
Reported-by: Leonid Reviakin <L.reviakin@fobos-nt.ru>
Reported-by: Denis Rastyogin <gerben@altlinux.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250318201143.70657-1-kwolf@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qcow2.c | 4 +-
tests/qemu-iotests/tests/qcow2-encryption | 75 +++++++++++++++++++
tests/qemu-iotests/tests/qcow2-encryption.out | 32 ++++++++
3 files changed, 109 insertions(+), 2 deletions(-)
create mode 100755 tests/qemu-iotests/tests/qcow2-encryption
create mode 100644 tests/qemu-iotests/tests/qcow2-encryption.out
diff --git a/block/qcow2.c b/block/qcow2.c
index dd6bcafbd8..7774e7f090 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1721,7 +1721,7 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
ret = -EINVAL;
goto fail;
}
- } else if (!(flags & BDRV_O_NO_IO)) {
+ } else {
error_setg(errp, "Missing CRYPTO header for crypt method %d",
s->crypt_method_header);
ret = -EINVAL;
@@ -1976,7 +1976,7 @@ static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp)
{
BDRVQcow2State *s = bs->opaque;
- if (bs->encrypted) {
+ if (s->crypto) {
/* Encryption works on a sector granularity */
bs->bl.request_alignment = qcrypto_block_get_sector_size(s->crypto);
}
diff --git a/tests/qemu-iotests/tests/qcow2-encryption b/tests/qemu-iotests/tests/qcow2-encryption
new file mode 100755
index 0000000000..95f6195ab8
--- /dev/null
+++ b/tests/qemu-iotests/tests/qcow2-encryption
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+# group: rw quick
+#
+# Test case for encryption support in qcow2
+#
+# Copyright (C) 2025 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# creator
+owner=kwolf@redhat.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+status=1 # failure is the default!
+
+_cleanup()
+{
+ _cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ../common.rc
+. ../common.filter
+
+# This tests qcow2-specific low-level functionality
+_supported_fmt qcow2
+_supported_proto file
+_require_working_luks
+
+IMG_SIZE=64M
+
+echo
+echo "=== Create an encrypted image ==="
+echo
+
+_make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $IMG_SIZE
+$PYTHON ../qcow2.py "$TEST_IMG" dump-header-exts
+_img_info
+$QEMU_IMG check \
+ --object secret,id=sec0,data=123456 \
+ --image-opts file.filename="$TEST_IMG",encrypt.key-secret=sec0 \
+ | _filter_qemu_img_check
+
+echo
+echo "=== Remove the header extension ==="
+echo
+
+$PYTHON ../qcow2.py "$TEST_IMG" del-header-ext 0x0537be77
+$PYTHON ../qcow2.py "$TEST_IMG" dump-header-exts
+_img_info
+$QEMU_IMG check \
+ --object secret,id=sec0,data=123456 \
+ --image-opts file.filename="$TEST_IMG",encrypt.key-secret=sec0 2>&1 \
+ | _filter_qemu_img_check \
+ | _filter_testdir
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/tests/qcow2-encryption.out b/tests/qemu-iotests/tests/qcow2-encryption.out
new file mode 100644
index 0000000000..9b549dc2ab
--- /dev/null
+++ b/tests/qemu-iotests/tests/qcow2-encryption.out
@@ -0,0 +1,32 @@
+QA output created by qcow2-encryption
+
+=== Create an encrypted image ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+Header extension:
+magic 0x537be77 (Crypto header)
+length 16
+data <binary>
+
+Header extension:
+magic 0x6803f857 (Feature table)
+length 384
+data <binary>
+
+image: TEST_DIR/t.IMGFMT
+file format: IMGFMT
+virtual size: 64 MiB (67108864 bytes)
+encrypted: yes
+cluster_size: 65536
+No errors were found on the image.
+
+=== Remove the header extension ===
+
+Header extension:
+magic 0x6803f857 (Feature table)
+length 384
+data <binary>
+
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Missing CRYPTO header for crypt method 2
+qemu-img: Could not open 'file.filename=TEST_DIR/t.qcow2,encrypt.key-secret=sec0': Missing CRYPTO header for crypt method 2
+*** done
--
2.49.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PULL 3/4] scsi-disk: Apply error policy for host_status errors again
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
2025-04-08 13:00 ` [PULL 1/4] qemu-img: fix division by zero in bench_cb() for zero-sized images Kevin Wolf
2025-04-08 13:00 ` [PULL 2/4] qcow2: Don't crash qemu-img info with missing crypto header Kevin Wolf
@ 2025-04-08 13:00 ` Kevin Wolf
2025-04-08 13:00 ` [PULL 4/4] test-bdrv-drain: Fix data races Kevin Wolf
2025-04-09 8:31 ` [PULL 0/4] Block layer patches Stefan Hajnoczi
4 siblings, 0 replies; 13+ messages in thread
From: Kevin Wolf @ 2025-04-08 13:00 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
Originally, all failed SG_IO requests called scsi_handle_rw_error() to
apply the configured error policy. However, commit f3126d65, which was
supposed to be a mere refactoring for scsi-disk.c, broke this and
accidentally completed the SCSI request without considering the error
policy any more if the error was signalled in the host_status field.
Apart from the commit message not describing the change as intended,
errors indicated in host_status are also obviously backend errors and
not something the guest must deal with independently of the error
policy.
This behaviour means that some recoverable errors (such as a path error
in multipath configurations) were reported to the guest anyway, which
might not expect it and might consider its disk broken.
Make sure that we apply the error policy again for host_status errors,
too. This addresses an existing FIXME comment and allows us to remove
some comments warning that callbacks weren't always called. With this
fix, they are called in all cases again.
The return value passed to the request callback doesn't have more free
values that could be used to indicate host_status errors as well as SAM
status codes and negative errno. Store the value in the host_status
field of the SCSIRequest instead and use -ENODEV as the return value (if
a path hasn't been reachable for a while, blk_aio_ioctl() will return
-ENODEV instead of just setting host_status, so just reuse it here -
it's not necessarily entirely accurate, but it's as good as any errno).
Cc: qemu-stable@nongnu.org
Fixes: f3126d65b393 ('scsi: move host_status handling into SCSI drivers')
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250407155949.44736-1-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/scsi/scsi-disk.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 8da1d5a77c..e59632e9b1 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -68,10 +68,9 @@ struct SCSIDiskClass {
SCSIDeviceClass parent_class;
/*
* Callbacks receive ret == 0 for success. Errors are represented either as
- * negative errno values, or as positive SAM status codes.
- *
- * Beware: For errors returned in host_status, the function may directly
- * complete the request and never call the callback.
+ * negative errno values, or as positive SAM status codes. For host_status
+ * errors, the function passes ret == -ENODEV and sets the host_status field
+ * of the SCSIRequest.
*/
DMAIOFunc *dma_readv;
DMAIOFunc *dma_writev;
@@ -225,11 +224,26 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int ret, bool acct_failed)
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
SCSIDiskClass *sdc = (SCSIDiskClass *) object_get_class(OBJECT(s));
SCSISense sense = SENSE_CODE(NO_SENSE);
+ int16_t host_status;
int error;
bool req_has_sense = false;
BlockErrorAction action;
int status;
+ /*
+ * host_status should only be set for SG_IO requests that came back with a
+ * host_status error in scsi_block_sgio_complete(). This error path passes
+ * -ENODEV as the return value.
+ *
+ * Reset host_status in the request because we may still want to complete
+ * the request successfully with the 'stop' or 'ignore' error policy.
+ */
+ host_status = r->req.host_status;
+ if (host_status != -1) {
+ assert(ret == -ENODEV);
+ r->req.host_status = -1;
+ }
+
if (ret < 0) {
status = scsi_sense_from_errno(-ret, &sense);
error = -ret;
@@ -289,6 +303,10 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int ret, bool acct_failed)
if (acct_failed) {
block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
+ if (host_status != -1) {
+ scsi_req_complete_failed(&r->req, host_status);
+ return true;
+ }
if (req_has_sense) {
sdc->update_sense(&r->req);
} else if (status == CHECK_CONDITION) {
@@ -409,7 +427,6 @@ done:
scsi_req_unref(&r->req);
}
-/* May not be called in all error cases, don't rely on cleanup here */
static void scsi_dma_complete(void *opaque, int ret)
{
SCSIDiskReq *r = (SCSIDiskReq *)opaque;
@@ -448,7 +465,6 @@ done:
scsi_req_unref(&r->req);
}
-/* May not be called in all error cases, don't rely on cleanup here */
static void scsi_read_complete(void *opaque, int ret)
{
SCSIDiskReq *r = (SCSIDiskReq *)opaque;
@@ -585,7 +601,6 @@ done:
scsi_req_unref(&r->req);
}
-/* May not be called in all error cases, don't rely on cleanup here */
static void scsi_write_complete(void * opaque, int ret)
{
SCSIDiskReq *r = (SCSIDiskReq *)opaque;
@@ -2846,14 +2861,10 @@ static void scsi_block_sgio_complete(void *opaque, int ret)
sg_io_hdr_t *io_hdr = &req->io_header;
if (ret == 0) {
- /* FIXME This skips calling req->cb() and any cleanup in it */
if (io_hdr->host_status != SCSI_HOST_OK) {
- scsi_req_complete_failed(&r->req, io_hdr->host_status);
- scsi_req_unref(&r->req);
- return;
- }
-
- if (io_hdr->driver_status & SG_ERR_DRIVER_TIMEOUT) {
+ r->req.host_status = io_hdr->host_status;
+ ret = -ENODEV;
+ } else if (io_hdr->driver_status & SG_ERR_DRIVER_TIMEOUT) {
ret = BUSY;
} else {
ret = io_hdr->status;
--
2.49.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PULL 4/4] test-bdrv-drain: Fix data races
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
` (2 preceding siblings ...)
2025-04-08 13:00 ` [PULL 3/4] scsi-disk: Apply error policy for host_status errors again Kevin Wolf
@ 2025-04-08 13:00 ` Kevin Wolf
2025-04-09 8:31 ` [PULL 0/4] Block layer patches Stefan Hajnoczi
4 siblings, 0 replies; 13+ messages in thread
From: Kevin Wolf @ 2025-04-08 13:00 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
From: Vitalii Mordan <mordan@ispras.ru>
This patch addresses potential data races involving access to Job fields
in the test-bdrv-drain test.
Fixes: 7253220de4 ("test-bdrv-drain: Test drain vs. block jobs")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2900
Signed-off-by: Vitalii Mordan <mordan@ispras.ru>
Message-ID: <20250402102119.3345626-1-mordan@ispras.ru>
[kwolf: Fixed up coding style and one missing atomic access]
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qemu/job.h | 3 +++
job.c | 6 ++++++
tests/unit/test-bdrv-drain.c | 32 +++++++++++++++++++-------------
3 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/include/qemu/job.h b/include/qemu/job.h
index 2b873f2576..a5a04155ea 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -545,6 +545,9 @@ bool job_is_ready(Job *job);
/* Same as job_is_ready(), but called with job lock held. */
bool job_is_ready_locked(Job *job);
+/** Returns whether the job is paused. Called with job_mutex *not* held. */
+bool job_is_paused(Job *job);
+
/**
* Request @job to pause at the next pause point. Must be paired with
* job_resume(). If the job is supposed to be resumed by user action, call
diff --git a/job.c b/job.c
index 660ce22c56..0653bc2ba6 100644
--- a/job.c
+++ b/job.c
@@ -251,6 +251,12 @@ bool job_is_cancelled_locked(Job *job)
return job->force_cancel;
}
+bool job_is_paused(Job *job)
+{
+ JOB_LOCK_GUARD();
+ return job->paused;
+}
+
bool job_is_cancelled(Job *job)
{
JOB_LOCK_GUARD();
diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c
index 7410e6f352..290cd2a70e 100644
--- a/tests/unit/test-bdrv-drain.c
+++ b/tests/unit/test-bdrv-drain.c
@@ -632,6 +632,8 @@ typedef struct TestBlockJob {
BlockDriverState *bs;
int run_ret;
int prepare_ret;
+
+ /* Accessed with atomics */
bool running;
bool should_complete;
} TestBlockJob;
@@ -667,10 +669,10 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
/* We are running the actual job code past the pause point in
* job_co_entry(). */
- s->running = true;
+ qatomic_set(&s->running, true);
job_transition_to_ready(&s->common.job);
- while (!s->should_complete) {
+ while (!qatomic_read(&s->should_complete)) {
/* Avoid job_sleep_ns() because it marks the job as !busy. We want to
* emulate some actual activity (probably some I/O) here so that drain
* has to wait for this activity to stop. */
@@ -685,7 +687,7 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
static void test_job_complete(Job *job, Error **errp)
{
TestBlockJob *s = container_of(job, TestBlockJob, common.job);
- s->should_complete = true;
+ qatomic_set(&s->should_complete, true);
}
BlockJobDriver test_job_driver = {
@@ -791,7 +793,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
/* job_co_entry() is run in the I/O thread, wait for the actual job
* code to start (we don't want to catch the job in the pause point in
* job_co_entry(). */
- while (!tjob->running) {
+ while (!qatomic_read(&tjob->running)) {
aio_poll(qemu_get_aio_context(), false);
}
}
@@ -799,7 +801,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
WITH_JOB_LOCK_GUARD() {
g_assert_cmpint(job->job.pause_count, ==, 0);
g_assert_false(job->job.paused);
- g_assert_true(tjob->running);
+ g_assert_true(qatomic_read(&tjob->running));
g_assert_true(job->job.busy); /* We're in qemu_co_sleep_ns() */
}
@@ -825,7 +827,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
*
* paused is reset in the I/O thread, wait for it
*/
- while (job->job.paused) {
+ while (job_is_paused(&job->job)) {
aio_poll(qemu_get_aio_context(), false);
}
}
@@ -858,7 +860,7 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
*
* paused is reset in the I/O thread, wait for it
*/
- while (job->job.paused) {
+ while (job_is_paused(&job->job)) {
aio_poll(qemu_get_aio_context(), false);
}
}
@@ -1411,10 +1413,12 @@ static void test_set_aio_context(void)
typedef struct TestDropBackingBlockJob {
BlockJob common;
- bool should_complete;
bool *did_complete;
BlockDriverState *detach_also;
BlockDriverState *bs;
+
+ /* Accessed with atomics */
+ bool should_complete;
} TestDropBackingBlockJob;
static int coroutine_fn test_drop_backing_job_run(Job *job, Error **errp)
@@ -1422,7 +1426,7 @@ static int coroutine_fn test_drop_backing_job_run(Job *job, Error **errp)
TestDropBackingBlockJob *s =
container_of(job, TestDropBackingBlockJob, common.job);
- while (!s->should_complete) {
+ while (!qatomic_read(&s->should_complete)) {
job_sleep_ns(job, 0);
}
@@ -1541,7 +1545,7 @@ static void test_blockjob_commit_by_drained_end(void)
job_start(&job->common.job);
- job->should_complete = true;
+ qatomic_set(&job->should_complete, true);
bdrv_drained_begin(bs_child);
g_assert(!job_has_completed);
bdrv_drained_end(bs_child);
@@ -1557,15 +1561,17 @@ static void test_blockjob_commit_by_drained_end(void)
typedef struct TestSimpleBlockJob {
BlockJob common;
- bool should_complete;
bool *did_complete;
+
+ /* Accessed with atomics */
+ bool should_complete;
} TestSimpleBlockJob;
static int coroutine_fn test_simple_job_run(Job *job, Error **errp)
{
TestSimpleBlockJob *s = container_of(job, TestSimpleBlockJob, common.job);
- while (!s->should_complete) {
+ while (!qatomic_read(&s->should_complete)) {
job_sleep_ns(job, 0);
}
@@ -1700,7 +1706,7 @@ static void test_drop_intermediate_poll(void)
job->did_complete = &job_has_completed;
job_start(&job->common.job);
- job->should_complete = true;
+ qatomic_set(&job->should_complete, true);
g_assert(!job_has_completed);
ret = bdrv_drop_intermediate(chain[1], chain[0], NULL, false);
--
2.49.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PULL 0/4] Block layer patches
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
` (3 preceding siblings ...)
2025-04-08 13:00 ` [PULL 4/4] test-bdrv-drain: Fix data races Kevin Wolf
@ 2025-04-09 8:31 ` Stefan Hajnoczi
4 siblings, 0 replies; 13+ messages in thread
From: Stefan Hajnoczi @ 2025-04-09 8:31 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, kwolf, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PULL 0/4] Block layer patches
@ 2025-04-25 17:52 Kevin Wolf
2025-04-28 17:56 ` Stefan Hajnoczi
0 siblings, 1 reply; 13+ messages in thread
From: Kevin Wolf @ 2025-04-25 17:52 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
The following changes since commit 019fbfa4bcd2d3a835c241295e22ab2b5b56129b:
Merge tag 'pull-misc-2025-04-24' of https://repo.or.cz/qemu/armbru into staging (2025-04-24 13:44:57 -0400)
are available in the Git repository at:
https://repo.or.cz/qemu/kevin.git tags/for-upstream
for you to fetch changes up to 2b689db0bedd24eda8b491cb1fcfb015dfec5a31:
qemu-img: improve queue depth validation in img_bench (2025-04-25 18:09:04 +0200)
----------------------------------------------------------------
Block layer patches
- Discard alignment fixes
- Remove unused callback .bdrv_aio_pdiscard()
- qemu-img bench: Input validation fix
----------------------------------------------------------------
Denis Rastyogin (1):
qemu-img: improve queue depth validation in img_bench
Stefan Hajnoczi (2):
file-posix: probe discard alignment on Linux block devices
block/io: skip head/tail requests on EINVAL
Sunny Zhu (1):
block: Remove unused callback function *bdrv_aio_pdiscard
include/block/block_int-common.h | 4 ---
block/file-posix.c | 67 +++++++++++++++++++++++++++++++++++++++-
block/io.c | 35 +++++++--------------
qemu-img.c | 2 +-
4 files changed, 79 insertions(+), 29 deletions(-)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PULL 0/4] Block layer patches
2025-04-25 17:52 Kevin Wolf
@ 2025-04-28 17:56 ` Stefan Hajnoczi
0 siblings, 0 replies; 13+ messages in thread
From: Stefan Hajnoczi @ 2025-04-28 17:56 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, kwolf, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-04-28 17:58 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 13:00 [PULL 0/4] Block layer patches Kevin Wolf
2025-04-08 13:00 ` [PULL 1/4] qemu-img: fix division by zero in bench_cb() for zero-sized images Kevin Wolf
2025-04-08 13:00 ` [PULL 2/4] qcow2: Don't crash qemu-img info with missing crypto header Kevin Wolf
2025-04-08 13:00 ` [PULL 3/4] scsi-disk: Apply error policy for host_status errors again Kevin Wolf
2025-04-08 13:00 ` [PULL 4/4] test-bdrv-drain: Fix data races Kevin Wolf
2025-04-09 8:31 ` [PULL 0/4] Block layer patches Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2025-04-25 17:52 Kevin Wolf
2025-04-28 17:56 ` Stefan Hajnoczi
2023-11-28 14:09 Kevin Wolf
2023-03-28 12:35 Kevin Wolf
2023-03-28 19:42 ` Peter Maydell
2019-09-20 16:20 Kevin Wolf
2019-09-23 9:49 ` Peter Maydell
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).