1 | The following changes since commit 91fe7a376ad46e3cc5e82d418aad22173c948a3c: | 1 | The following changes since commit 825b96dbcee23d134b691fc75618b59c5f53da32: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging (2018-06-15 11:41:44 +0100) | 3 | Merge tag 'migration-20250310-pull-request' of https://gitlab.com/farosas/qemu into staging (2025-03-11 09:32:07 +0800) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream | 7 | https://repo.or.cz/qemu/kevin.git tags/for-upstream |
8 | 8 | ||
9 | for you to fetch changes up to 6266e900b8083945cb766b45c124fb3c42932cb3: | 9 | for you to fetch changes up to a93c04f3cbe690877b3297a9df4767aa811fcd97: |
10 | 10 | ||
11 | block: Remove dead deprecation warning code (2018-06-15 14:49:44 +0200) | 11 | virtio-scsi: only expose cmd vqs via iothread-vq-mapping (2025-03-11 15:49:22 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block layer patches: | 14 | Block layer patches |
15 | 15 | ||
16 | - Fix options that work only with -drive or -blockdev, but not with | 16 | - virtio-scsi: add iothread-vq-mapping parameter |
17 | both, because of QDict type confusion | 17 | - Improve writethrough performance |
18 | - rbd: Add options 'auth-client-required' and 'key-secret' | 18 | - Fix missing zero init in bdrv_snapshot_goto() |
19 | - Remove deprecated -drive options serial/addr/cyls/heads/secs/trans | 19 | - Code cleanup and iotests fixes |
20 | - rbd, iscsi: Remove deprecated 'filename' option | ||
21 | - Fix 'qemu-img map' crash with unaligned image size | ||
22 | - Improve QMP documentation for jobs | ||
23 | 20 | ||
24 | ---------------------------------------------------------------- | 21 | ---------------------------------------------------------------- |
25 | Eric Blake (2): | 22 | Kevin Wolf (8): |
26 | qemu-img: Fix assert when mapping unaligned raw file | 23 | block: Remove unused blk_op_is_blocked() |
27 | iotests: Add test 221 to catch qemu-img map regression | 24 | block: Zero block driver state before reopening |
25 | file-posix: Support FUA writes | ||
26 | block/io: Ignore FUA with cache.no-flush=on | ||
27 | aio: Create AioPolledEvent | ||
28 | aio-posix: Factor out adjust_polling_time() | ||
29 | aio-posix: Separate AioPolledEvent per AioHandler | ||
30 | aio-posix: Adjust polling time also for new handlers | ||
28 | 31 | ||
29 | John Snow (2): | 32 | Stefan Hajnoczi (13): |
30 | jobs: fix stale wording | 33 | scsi-disk: drop unused SCSIDiskState->bh field |
31 | jobs: fix verb references in docs | 34 | dma: use current AioContext for dma_blk_io() |
35 | scsi: track per-SCSIRequest AioContext | ||
36 | scsi: introduce requests_lock | ||
37 | virtio-scsi: introduce event and ctrl virtqueue locks | ||
38 | virtio-scsi: protect events_dropped field | ||
39 | virtio-scsi: perform TMFs in appropriate AioContexts | ||
40 | virtio-blk: extract cleanup_iothread_vq_mapping() function | ||
41 | virtio-blk: tidy up iothread_vq_mapping functions | ||
42 | virtio: extract iothread-vq-mapping.h API | ||
43 | virtio-scsi: add iothread-vq-mapping parameter | ||
44 | virtio-scsi: handle ctrl virtqueue in main loop | ||
45 | virtio-scsi: only expose cmd vqs via iothread-vq-mapping | ||
32 | 46 | ||
33 | Kevin Wolf (4): | 47 | Thomas Huth (1): |
34 | block: Remove deprecated -drive geometry options | 48 | iotests: Limit qsd-migrate to working formats |
35 | block: Remove deprecated -drive option addr | ||
36 | block: Remove deprecated -drive option serial | ||
37 | block: Remove dead deprecation warning code | ||
38 | 49 | ||
39 | Markus Armbruster (17): | 50 | include/block/aio.h | 5 +- |
40 | rbd: Drop deprecated -drive parameter "filename" | 51 | include/block/raw-aio.h | 8 +- |
41 | iscsi: Drop deprecated -drive parameter "filename" | 52 | include/hw/scsi/scsi.h | 8 +- |
42 | qobject: Move block-specific qdict code to block-qdict.c | 53 | include/hw/virtio/iothread-vq-mapping.h | 45 +++ |
43 | block: Fix -blockdev for certain non-string scalars | 54 | include/hw/virtio/virtio-scsi.h | 15 +- |
44 | block: Fix -drive for certain non-string scalars | 55 | include/system/block-backend-global-state.h | 1 - |
45 | block: Clean up a misuse of qobject_to() in .bdrv_co_create_opts() | 56 | include/system/dma.h | 3 +- |
46 | block: Factor out qobject_input_visitor_new_flat_confused() | 57 | util/aio-posix.h | 1 + |
47 | block: Make remaining uses of qobject input visitor more robust | 58 | block/block-backend.c | 12 - |
48 | block-qdict: Simplify qdict_flatten_qdict() | 59 | block/file-posix.c | 26 +- |
49 | block-qdict: Tweak qdict_flatten_qdict(), qdict_flatten_qlist() | 60 | block/io.c | 4 + |
50 | block-qdict: Clean up qdict_crumple() a bit | 61 | block/io_uring.c | 13 +- |
51 | block-qdict: Simplify qdict_is_list() some | 62 | block/linux-aio.c | 24 +- |
52 | check-block-qdict: Rename qdict_flatten()'s variables for clarity | 63 | block/snapshot.c | 1 + |
53 | check-block-qdict: Cover flattening of empty lists and dictionaries | 64 | hw/block/virtio-blk.c | 132 +------- |
54 | block: Fix -blockdev / blockdev-add for empty objects and arrays | 65 | hw/ide/core.c | 3 +- |
55 | rbd: New parameter auth-client-required | 66 | hw/ide/macio.c | 3 +- |
56 | rbd: New parameter key-secret | 67 | hw/scsi/scsi-bus.c | 121 +++++-- |
57 | 68 | hw/scsi/scsi-disk.c | 24 +- | |
58 | Max Reitz (1): | 69 | hw/scsi/virtio-scsi-dataplane.c | 103 ++++-- |
59 | block: Add block-specific QDict header | 70 | hw/scsi/virtio-scsi.c | 502 ++++++++++++++++------------ |
60 | 71 | hw/virtio/iothread-vq-mapping.c | 131 ++++++++ | |
61 | qapi/block-core.json | 19 ++ | 72 | system/dma-helpers.c | 8 +- |
62 | qapi/job.json | 23 +- | 73 | util/aio-posix.c | 114 ++++--- |
63 | include/block/qdict.h | 34 +++ | 74 | util/async.c | 1 - |
64 | include/hw/block/block.h | 1 - | 75 | hw/virtio/meson.build | 1 + |
65 | include/qapi/qmp/qdict.h | 17 -- | 76 | meson.build | 4 + |
66 | include/sysemu/blockdev.h | 3 - | 77 | tests/qemu-iotests/tests/qsd-migrate | 2 +- |
67 | block.c | 1 + | 78 | 28 files changed, 803 insertions(+), 512 deletions(-) |
68 | block/block-backend.c | 1 - | 79 | create mode 100644 include/hw/virtio/iothread-vq-mapping.h |
69 | block/crypto.c | 12 +- | 80 | create mode 100644 hw/virtio/iothread-vq-mapping.c |
70 | block/gluster.c | 1 + | ||
71 | block/iscsi.c | 24 +- | ||
72 | block/nbd.c | 16 +- | ||
73 | block/nfs.c | 8 +- | ||
74 | block/parallels.c | 11 +- | ||
75 | block/qcow.c | 11 +- | ||
76 | block/qcow2.c | 11 +- | ||
77 | block/qed.c | 11 +- | ||
78 | block/quorum.c | 1 + | ||
79 | block/rbd.c | 85 +++--- | ||
80 | block/sheepdog.c | 23 +- | ||
81 | block/snapshot.c | 1 + | ||
82 | block/ssh.c | 16 +- | ||
83 | block/vdi.c | 8 +- | ||
84 | block/vhdx.c | 11 +- | ||
85 | block/vpc.c | 11 +- | ||
86 | block/vvfat.c | 1 + | ||
87 | block/vxhs.c | 1 + | ||
88 | blockdev.c | 111 +------ | ||
89 | device-hotplug.c | 4 - | ||
90 | hw/block/block.c | 27 -- | ||
91 | hw/block/nvme.c | 1 - | ||
92 | hw/block/virtio-blk.c | 1 - | ||
93 | hw/ide/qdev.c | 1 - | ||
94 | hw/scsi/scsi-disk.c | 1 - | ||
95 | hw/usb/dev-storage.c | 1 - | ||
96 | qemu-img.c | 2 +- | ||
97 | qobject/block-qdict.c | 722 +++++++++++++++++++++++++++++++++++++++++++++ | ||
98 | qobject/qdict.c | 628 --------------------------------------- | ||
99 | tests/ahci-test.c | 6 +- | ||
100 | tests/check-block-qdict.c | 690 +++++++++++++++++++++++++++++++++++++++++++ | ||
101 | tests/check-qdict.c | 641 ---------------------------------------- | ||
102 | tests/check-qobject.c | 1 + | ||
103 | tests/hd-geo-test.c | 37 +-- | ||
104 | tests/ide-test.c | 8 +- | ||
105 | tests/test-replication.c | 1 + | ||
106 | util/qemu-config.c | 1 + | ||
107 | MAINTAINERS | 2 + | ||
108 | hmp-commands.hx | 1 - | ||
109 | qemu-doc.texi | 15 - | ||
110 | qemu-options.hx | 14 +- | ||
111 | qobject/Makefile.objs | 1 + | ||
112 | tests/Makefile.include | 4 + | ||
113 | tests/qemu-iotests/221 | 60 ++++ | ||
114 | tests/qemu-iotests/221.out | 16 + | ||
115 | tests/qemu-iotests/group | 1 + | ||
116 | 55 files changed, 1692 insertions(+), 1668 deletions(-) | ||
117 | create mode 100644 include/block/qdict.h | ||
118 | create mode 100644 qobject/block-qdict.c | ||
119 | create mode 100644 tests/check-block-qdict.c | ||
120 | create mode 100755 tests/qemu-iotests/221 | ||
121 | create mode 100644 tests/qemu-iotests/221.out | ||
122 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Commit a290f085 exposed a latent bug in qemu-img map introduced | ||
4 | during the conversion of block status to be byte-based. Earlier in | ||
5 | commit 5e344dd8, the internal interface get_block_status() switched | ||
6 | to take byte-based parameters, but still called a sector-based | ||
7 | block layer function; as such, rounding was added in the lone | ||
8 | caller to obey the contract. However, commit 237d78f8 changed | ||
9 | get_block_status() to truly be byte-based, at which point rounding | ||
10 | to sector boundaries can result in calling bdrv_block_status() with | ||
11 | 'bytes == 0' (a coding error) when the boundary between data and a | ||
12 | hole falls mid-sector (true for the past-EOF implicit hole present | ||
13 | in POSIX files). Fix things by removing the rounding that is now | ||
14 | no longer necessary. | ||
15 | |||
16 | See also https://bugzilla.redhat.com/1589738 | ||
17 | |||
18 | Fixes: 237d78f8 | ||
19 | Reported-by: Dan Kenigsberg <danken@redhat.com> | ||
20 | Reported-by: Nir Soffer <nsoffer@redhat.com> | ||
21 | Reported-by: Maor Lipchuk <mlipchuk@redhat.com> | ||
22 | CC: qemu-stable@nongnu.org | ||
23 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
24 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
25 | --- | ||
26 | qemu-img.c | 2 +- | ||
27 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
28 | |||
29 | diff --git a/qemu-img.c b/qemu-img.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/qemu-img.c | ||
32 | +++ b/qemu-img.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv) | ||
34 | int64_t n; | ||
35 | |||
36 | /* Probe up to 1 GiB at a time. */ | ||
37 | - n = QEMU_ALIGN_DOWN(MIN(1 << 30, length - offset), BDRV_SECTOR_SIZE); | ||
38 | + n = MIN(1 << 30, length - offset); | ||
39 | ret = get_block_status(bs, offset, n, &next); | ||
40 | |||
41 | if (ret < 0) { | ||
42 | -- | ||
43 | 2.13.6 | ||
44 | |||
45 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Although qemu-img creates aligned files (by rounding up), it | ||
4 | must also gracefully handle files that are not sector-aligned. | ||
5 | Test that the bug fixed in the previous patch does not recur. | ||
6 | |||
7 | It's a bit annoying that we can see the (implicit) hole past | ||
8 | the end of the file on to the next sector boundary, so if we | ||
9 | ever reach the point where we report a byte-accurate size rather | ||
10 | than our current behavior of always rounding up, this test will | ||
11 | probably need a slight modification. | ||
12 | |||
13 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | --- | ||
16 | tests/qemu-iotests/221 | 60 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
17 | tests/qemu-iotests/221.out | 16 +++++++++++++ | ||
18 | tests/qemu-iotests/group | 1 + | ||
19 | 3 files changed, 77 insertions(+) | ||
20 | create mode 100755 tests/qemu-iotests/221 | ||
21 | create mode 100644 tests/qemu-iotests/221.out | ||
22 | |||
23 | diff --git a/tests/qemu-iotests/221 b/tests/qemu-iotests/221 | ||
24 | new file mode 100755 | ||
25 | index XXXXXXX..XXXXXXX | ||
26 | --- /dev/null | ||
27 | +++ b/tests/qemu-iotests/221 | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | +#!/bin/bash | ||
30 | +# | ||
31 | +# Test qemu-img vs. unaligned images | ||
32 | +# | ||
33 | +# Copyright (C) 2018 Red Hat, Inc. | ||
34 | +# | ||
35 | +# This program is free software; you can redistribute it and/or modify | ||
36 | +# it under the terms of the GNU General Public License as published by | ||
37 | +# the Free Software Foundation; either version 2 of the License, or | ||
38 | +# (at your option) any later version. | ||
39 | +# | ||
40 | +# This program is distributed in the hope that it will be useful, | ||
41 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
42 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
43 | +# GNU General Public License for more details. | ||
44 | +# | ||
45 | +# You should have received a copy of the GNU General Public License | ||
46 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
47 | +# | ||
48 | + | ||
49 | +seq="$(basename $0)" | ||
50 | +echo "QA output created by $seq" | ||
51 | + | ||
52 | +here="$PWD" | ||
53 | +status=1 # failure is the default! | ||
54 | + | ||
55 | +_cleanup() | ||
56 | +{ | ||
57 | + _cleanup_test_img | ||
58 | +} | ||
59 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
60 | + | ||
61 | +# get standard environment, filters and checks | ||
62 | +. ./common.rc | ||
63 | +. ./common.filter | ||
64 | + | ||
65 | +_supported_fmt raw | ||
66 | +_supported_proto file | ||
67 | +_supported_os Linux | ||
68 | + | ||
69 | +echo | ||
70 | +echo "=== Check mapping of unaligned raw image ===" | ||
71 | +echo | ||
72 | + | ||
73 | +_make_test_img 43009 # qemu-img create rounds size up | ||
74 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
75 | + | ||
76 | +truncate --size=43009 "$TEST_IMG" # so we resize it and check again | ||
77 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
78 | + | ||
79 | +$QEMU_IO -c 'w 43008 1' "$TEST_IMG" | _filter_qemu_io # writing also rounds up | ||
80 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
81 | + | ||
82 | +truncate --size=43009 "$TEST_IMG" # so we resize it and check again | ||
83 | +$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map | ||
84 | + | ||
85 | +# success, all done | ||
86 | +echo '*** done' | ||
87 | +rm -f $seq.full | ||
88 | +status=0 | ||
89 | diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out | ||
90 | new file mode 100644 | ||
91 | index XXXXXXX..XXXXXXX | ||
92 | --- /dev/null | ||
93 | +++ b/tests/qemu-iotests/221.out | ||
94 | @@ -XXX,XX +XXX,XX @@ | ||
95 | +QA output created by 221 | ||
96 | + | ||
97 | +=== Check mapping of unaligned raw image === | ||
98 | + | ||
99 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=43009 | ||
100 | +[{ "start": 0, "length": 43520, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
101 | +[{ "start": 0, "length": 43520, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
102 | +wrote 1/1 bytes at offset 43008 | ||
103 | +1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
104 | +[{ "start": 0, "length": 40960, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
105 | +{ "start": 40960, "length": 2049, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
106 | +{ "start": 43009, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
107 | +[{ "start": 0, "length": 40960, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
108 | +{ "start": 40960, "length": 2049, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
109 | +{ "start": 43009, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
110 | +*** done | ||
111 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/tests/qemu-iotests/group | ||
114 | +++ b/tests/qemu-iotests/group | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | 217 rw auto quick | ||
117 | 218 rw auto quick | ||
118 | 219 rw auto | ||
119 | +221 rw auto quick | ||
120 | -- | ||
121 | 2.13.6 | ||
122 | |||
123 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
2 | 1 | ||
3 | During the design for manual completion, we decided not to use the | ||
4 | "manual" property as a shorthand for both auto-dismiss and auto-finalize. | ||
5 | |||
6 | Fix the wording. | ||
7 | |||
8 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
10 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | qapi/job.json | 11 ++++++----- | ||
14 | 1 file changed, 6 insertions(+), 5 deletions(-) | ||
15 | |||
16 | diff --git a/qapi/job.json b/qapi/job.json | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/qapi/job.json | ||
19 | +++ b/qapi/job.json | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | # the last job in a transaction. | ||
22 | # | ||
23 | # @pending: The job has finished its work, but has finalization steps that it | ||
24 | -# needs to make prior to completing. These changes may require | ||
25 | -# manual intervention by the management process if manual was set | ||
26 | -# to true. These changes may still fail. | ||
27 | +# needs to make prior to completing. These changes will require | ||
28 | +# manual intervention via @job-finalize if auto-finalize was set to | ||
29 | +# false. These pending changes may still fail. | ||
30 | # | ||
31 | # @aborting: The job is in the process of being aborted, and will finish with | ||
32 | # an error. The job will afterwards report that it is @concluded. | ||
33 | # This status may not be visible to the management process. | ||
34 | # | ||
35 | -# @concluded: The job has finished all work. If manual was set to true, the job | ||
36 | -# will remain in the query list until it is dismissed. | ||
37 | +# @concluded: The job has finished all work. If auto-dismiss was set to false, | ||
38 | +# the job will remain in the query list until it is dismissed via | ||
39 | +# @job-dismiss. | ||
40 | # | ||
41 | # @null: The job is in the process of being dismantled. This state should not | ||
42 | # ever be visible externally. | ||
43 | -- | ||
44 | 2.13.6 | ||
45 | |||
46 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
2 | 1 | ||
3 | These point to the job versions now, not the blockjob versions which | ||
4 | don't really exist anymore. | ||
5 | |||
6 | Except set-speed, which does. It sticks out like a sore thumb. This | ||
7 | patch doesn't fix that, but it doesn't make it any worse, either. | ||
8 | |||
9 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
11 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | --- | ||
14 | qapi/job.json | 12 ++++++------ | ||
15 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
16 | |||
17 | diff --git a/qapi/job.json b/qapi/job.json | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/qapi/job.json | ||
20 | +++ b/qapi/job.json | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | # | ||
23 | # Represents command verbs that can be applied to a job. | ||
24 | # | ||
25 | -# @cancel: see @block-job-cancel | ||
26 | +# @cancel: see @job-cancel | ||
27 | # | ||
28 | -# @pause: see @block-job-pause | ||
29 | +# @pause: see @job-pause | ||
30 | # | ||
31 | -# @resume: see @block-job-resume | ||
32 | +# @resume: see @job-resume | ||
33 | # | ||
34 | # @set-speed: see @block-job-set-speed | ||
35 | # | ||
36 | -# @complete: see @block-job-complete | ||
37 | +# @complete: see @job-complete | ||
38 | # | ||
39 | -# @dismiss: see @block-job-dismiss | ||
40 | +# @dismiss: see @job-dismiss | ||
41 | # | ||
42 | -# @finalize: see @block-job-finalize | ||
43 | +# @finalize: see @job-finalize | ||
44 | # | ||
45 | # Since: 2.12 | ||
46 | ## | ||
47 | -- | ||
48 | 2.13.6 | ||
49 | |||
50 | diff view generated by jsdifflib |
1 | The -drive option serial was deprecated in QEMU 2.10. It's time to | 1 | Commit fc4e394b28 removed the last caller of blk_op_is_blocked(). Remove |
---|---|---|---|
2 | remove it. | 2 | the now unused function. |
3 | |||
4 | Tests need to be updated to set the serial number with -global instead | ||
5 | of using the -drive option. | ||
6 | 3 | ||
7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
8 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | 5 | Message-ID: <20250206165331.379033-1-kwolf@redhat.com> |
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | 9 | --- |
11 | include/hw/block/block.h | 1 - | 10 | include/system/block-backend-global-state.h | 1 - |
12 | include/sysemu/blockdev.h | 1 - | 11 | block/block-backend.c | 12 ------------ |
13 | block/block-backend.c | 1 - | 12 | 2 files changed, 13 deletions(-) |
14 | blockdev.c | 10 ---------- | ||
15 | hw/block/block.c | 13 ------------- | ||
16 | hw/block/nvme.c | 1 - | ||
17 | hw/block/virtio-blk.c | 1 - | ||
18 | hw/ide/qdev.c | 1 - | ||
19 | hw/scsi/scsi-disk.c | 1 - | ||
20 | hw/usb/dev-storage.c | 1 - | ||
21 | tests/ahci-test.c | 6 +++--- | ||
22 | tests/ide-test.c | 8 ++++---- | ||
23 | qemu-doc.texi | 5 ----- | ||
24 | qemu-options.hx | 6 +----- | ||
25 | 14 files changed, 8 insertions(+), 48 deletions(-) | ||
26 | 13 | ||
27 | diff --git a/include/hw/block/block.h b/include/hw/block/block.h | 14 | diff --git a/include/system/block-backend-global-state.h b/include/system/block-backend-global-state.h |
28 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/block/block.h | 16 | --- a/include/system/block-backend-global-state.h |
30 | +++ b/include/hw/block/block.h | 17 | +++ b/include/system/block-backend-global-state.h |
31 | @@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) | 18 | @@ -XXX,XX +XXX,XX @@ bool blk_supports_write_perm(BlockBackend *blk); |
32 | 19 | bool blk_is_sg(BlockBackend *blk); | |
33 | /* Configuration helpers */ | 20 | void blk_set_enable_write_cache(BlockBackend *blk, bool wce); |
34 | 21 | int blk_get_flags(BlockBackend *blk); | |
35 | -void blkconf_serial(BlockConf *conf, char **serial); | 22 | -bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp); |
36 | bool blkconf_geometry(BlockConf *conf, int *trans, | 23 | int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, |
37 | unsigned cyls_max, unsigned heads_max, unsigned secs_max, | 24 | Error **errp); |
38 | Error **errp); | 25 | void blk_add_aio_context_notifier(BlockBackend *blk, |
39 | diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/include/sysemu/blockdev.h | ||
42 | +++ b/include/sysemu/blockdev.h | ||
43 | @@ -XXX,XX +XXX,XX @@ struct DriveInfo { | ||
44 | bool is_default; /* Added by default_drive() ? */ | ||
45 | int media_cd; | ||
46 | QemuOpts *opts; | ||
47 | - char *serial; | ||
48 | QTAILQ_ENTRY(DriveInfo) next; | ||
49 | }; | ||
50 | |||
51 | diff --git a/block/block-backend.c b/block/block-backend.c | 26 | diff --git a/block/block-backend.c b/block/block-backend.c |
52 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/block/block-backend.c | 28 | --- a/block/block-backend.c |
54 | +++ b/block/block-backend.c | 29 | +++ b/block/block-backend.c |
55 | @@ -XXX,XX +XXX,XX @@ static void drive_info_del(DriveInfo *dinfo) | 30 | @@ -XXX,XX +XXX,XX @@ void *blk_blockalign(BlockBackend *blk, size_t size) |
56 | return; | 31 | return qemu_blockalign(blk ? blk_bs(blk) : NULL, size); |
57 | } | ||
58 | qemu_opts_del(dinfo->opts); | ||
59 | - g_free(dinfo->serial); | ||
60 | g_free(dinfo); | ||
61 | } | 32 | } |
62 | 33 | ||
63 | diff --git a/blockdev.c b/blockdev.c | 34 | -bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp) |
64 | index XXXXXXX..XXXXXXX 100644 | 35 | -{ |
65 | --- a/blockdev.c | 36 | - BlockDriverState *bs = blk_bs(blk); |
66 | +++ b/blockdev.c | 37 | - GLOBAL_STATE_CODE(); |
67 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = { | 38 | - GRAPH_RDLOCK_GUARD_MAINLOOP(); |
68 | .type = QEMU_OPT_STRING, | ||
69 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | ||
70 | },{ | ||
71 | - .name = "serial", | ||
72 | - .type = QEMU_OPT_STRING, | ||
73 | - .help = "disk serial number", | ||
74 | - },{ | ||
75 | .name = "file", | ||
76 | .type = QEMU_OPT_STRING, | ||
77 | .help = "file name", | ||
78 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
79 | const char *werror, *rerror; | ||
80 | bool read_only = false; | ||
81 | bool copy_on_read; | ||
82 | - const char *serial; | ||
83 | const char *filename; | ||
84 | Error *local_err = NULL; | ||
85 | int i; | ||
86 | const char *deprecated[] = { | ||
87 | - "serial" | ||
88 | }; | ||
89 | |||
90 | /* Change legacy command line options into QMP ones */ | ||
91 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
92 | goto fail; | ||
93 | } | ||
94 | |||
95 | - /* Serial number */ | ||
96 | - serial = qemu_opt_get(legacy_opts, "serial"); | ||
97 | - | 39 | - |
98 | /* no id supplied -> create one */ | 40 | - if (!bs) { |
99 | if (qemu_opts_id(all_opts) == NULL) { | 41 | - return false; |
100 | char *new_id; | 42 | - } |
101 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
102 | dinfo->type = type; | ||
103 | dinfo->bus = bus_id; | ||
104 | dinfo->unit = unit_id; | ||
105 | - dinfo->serial = g_strdup(serial); | ||
106 | |||
107 | blk_set_legacy_dinfo(blk, dinfo); | ||
108 | |||
109 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/hw/block/block.c | ||
112 | +++ b/hw/block/block.c | ||
113 | @@ -XXX,XX +XXX,XX @@ | ||
114 | #include "qapi/qapi-types-block.h" | ||
115 | #include "qemu/error-report.h" | ||
116 | |||
117 | -void blkconf_serial(BlockConf *conf, char **serial) | ||
118 | -{ | ||
119 | - DriveInfo *dinfo; | ||
120 | - | 43 | - |
121 | - if (!*serial) { | 44 | - return bdrv_op_is_blocked(bs, op, errp); |
122 | - /* try to fall back to value set with legacy -drive serial=... */ | ||
123 | - dinfo = blk_legacy_dinfo(conf->blk); | ||
124 | - if (dinfo) { | ||
125 | - *serial = g_strdup(dinfo->serial); | ||
126 | - } | ||
127 | - } | ||
128 | -} | 45 | -} |
129 | - | 46 | |
130 | void blkconf_blocksizes(BlockConf *conf) | 47 | /** |
131 | { | 48 | * Return BB's current AioContext. Note that this context may change |
132 | BlockBackend *blk = conf->blk; | ||
133 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | ||
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/hw/block/nvme.c | ||
136 | +++ b/hw/block/nvme.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | - blkconf_serial(&n->conf, &n->serial); | ||
142 | if (!n->serial) { | ||
143 | error_setg(errp, "serial property not set"); | ||
144 | return; | ||
145 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | ||
146 | index XXXXXXX..XXXXXXX 100644 | ||
147 | --- a/hw/block/virtio-blk.c | ||
148 | +++ b/hw/block/virtio-blk.c | ||
149 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | - blkconf_serial(&conf->conf, &conf->serial); | ||
154 | if (!blkconf_apply_backend_options(&conf->conf, | ||
155 | blk_is_read_only(conf->conf.blk), true, | ||
156 | errp)) { | ||
157 | diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c | ||
158 | index XXXXXXX..XXXXXXX 100644 | ||
159 | --- a/hw/ide/qdev.c | ||
160 | +++ b/hw/ide/qdev.c | ||
161 | @@ -XXX,XX +XXX,XX @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | - blkconf_serial(&dev->conf, &dev->serial); | ||
166 | if (kind != IDE_CD) { | ||
167 | if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, | ||
168 | errp)) { | ||
169 | diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c | ||
170 | index XXXXXXX..XXXXXXX 100644 | ||
171 | --- a/hw/scsi/scsi-disk.c | ||
172 | +++ b/hw/scsi/scsi-disk.c | ||
173 | @@ -XXX,XX +XXX,XX @@ static void scsi_realize(SCSIDevice *dev, Error **errp) | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | - blkconf_serial(&s->qdev.conf, &s->serial); | ||
178 | blkconf_blocksizes(&s->qdev.conf); | ||
179 | |||
180 | if (s->qdev.conf.logical_block_size > | ||
181 | diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c | ||
182 | index XXXXXXX..XXXXXXX 100644 | ||
183 | --- a/hw/usb/dev-storage.c | ||
184 | +++ b/hw/usb/dev-storage.c | ||
185 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp) | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | - blkconf_serial(&s->conf, &dev->serial); | ||
190 | blkconf_blocksizes(&s->conf); | ||
191 | if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), true, | ||
192 | errp)) { | ||
193 | diff --git a/tests/ahci-test.c b/tests/ahci-test.c | ||
194 | index XXXXXXX..XXXXXXX 100644 | ||
195 | --- a/tests/ahci-test.c | ||
196 | +++ b/tests/ahci-test.c | ||
197 | @@ -XXX,XX +XXX,XX @@ static AHCIQState *ahci_boot(const char *cli, ...) | ||
198 | s = ahci_vboot(cli, ap); | ||
199 | va_end(ap); | ||
200 | } else { | ||
201 | - cli = "-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s" | ||
202 | - ",format=%s" | ||
203 | + cli = "-drive if=none,id=drive0,file=%s,cache=writeback,format=%s" | ||
204 | " -M q35 " | ||
205 | "-device ide-hd,drive=drive0 " | ||
206 | + "-global ide-hd.serial=%s " | ||
207 | "-global ide-hd.ver=%s"; | ||
208 | - s = ahci_boot(cli, tmp_path, "testdisk", imgfmt, "version"); | ||
209 | + s = ahci_boot(cli, tmp_path, imgfmt, "testdisk", "version"); | ||
210 | } | ||
211 | |||
212 | return s; | ||
213 | diff --git a/tests/ide-test.c b/tests/ide-test.c | ||
214 | index XXXXXXX..XXXXXXX 100644 | ||
215 | --- a/tests/ide-test.c | ||
216 | +++ b/tests/ide-test.c | ||
217 | @@ -XXX,XX +XXX,XX @@ static void test_bmdma_no_busmaster(void) | ||
218 | static void test_bmdma_setup(void) | ||
219 | { | ||
220 | ide_test_start( | ||
221 | - "-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw " | ||
222 | - "-global ide-hd.ver=%s", | ||
223 | + "-drive file=%s,if=ide,cache=writeback,format=raw " | ||
224 | + "-global ide-hd.serial=%s -global ide-hd.ver=%s", | ||
225 | tmp_path, "testdisk", "version"); | ||
226 | qtest_irq_intercept_in(global_qtest, "ioapic"); | ||
227 | } | ||
228 | @@ -XXX,XX +XXX,XX @@ static void test_identify(void) | ||
229 | int ret; | ||
230 | |||
231 | ide_test_start( | ||
232 | - "-drive file=%s,if=ide,serial=%s,cache=writeback,format=raw " | ||
233 | - "-global ide-hd.ver=%s", | ||
234 | + "-drive file=%s,if=ide,cache=writeback,format=raw " | ||
235 | + "-global ide-hd.serial=%s -global ide-hd.ver=%s", | ||
236 | tmp_path, "testdisk", "version"); | ||
237 | |||
238 | dev = get_pci_device(&bmdma_bar, &ide_bar); | ||
239 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
240 | index XXXXXXX..XXXXXXX 100644 | ||
241 | --- a/qemu-doc.texi | ||
242 | +++ b/qemu-doc.texi | ||
243 | @@ -XXX,XX +XXX,XX @@ with ``-device ...,netdev=x''), or ``-nic user,smb=/some/dir'' | ||
244 | (for embedded NICs). The new syntax allows different settings to be | ||
245 | provided per NIC. | ||
246 | |||
247 | -@subsection -drive serial=... (since 2.10.0) | ||
248 | - | ||
249 | -The drive serial argument is replaced by the the serial argument | ||
250 | -that can be specified with the ``-device'' parameter. | ||
251 | - | ||
252 | @subsection -usbdevice (since 2.10.0) | ||
253 | |||
254 | The ``-usbdevice DEV'' argument is now a synonym for setting | ||
255 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
256 | index XXXXXXX..XXXXXXX 100644 | ||
257 | --- a/qemu-options.hx | ||
258 | +++ b/qemu-options.hx | ||
259 | @@ -XXX,XX +XXX,XX @@ ETEXI | ||
260 | DEF("drive", HAS_ARG, QEMU_OPTION_drive, | ||
261 | "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" | ||
262 | " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" | ||
263 | - " [,snapshot=on|off][,serial=s][,rerror=ignore|stop|report]\n" | ||
264 | + " [,snapshot=on|off][,rerror=ignore|stop|report]\n" | ||
265 | " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" | ||
266 | " [,readonly=on|off][,copy-on-read=on|off]\n" | ||
267 | " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" | ||
268 | @@ -XXX,XX +XXX,XX @@ The default mode is @option{cache=writeback}. | ||
269 | Specify which disk @var{format} will be used rather than detecting | ||
270 | the format. Can be used to specify format=raw to avoid interpreting | ||
271 | an untrusted format header. | ||
272 | -@item serial=@var{serial} | ||
273 | -This option specifies the serial number to assign to the device. This | ||
274 | -parameter is deprecated, use the corresponding parameter of @code{-device} | ||
275 | -instead. | ||
276 | @item werror=@var{action},rerror=@var{action} | ||
277 | Specify which @var{action} to take on write and read errors. Valid actions are: | ||
278 | "ignore" (ignore the error and try to continue), "stop" (pause QEMU), | ||
279 | -- | 49 | -- |
280 | 2.13.6 | 50 | 2.48.1 |
281 | 51 | ||
282 | 52 | diff view generated by jsdifflib |
1 | From: Max Reitz <mreitz@redhat.com> | 1 | Block drivers assume in their .bdrv_open() implementation that their |
---|---|---|---|
2 | state in bs->opaque has been zeroed; it is initially allocated with | ||
3 | g_malloc0() in bdrv_open_driver(). | ||
2 | 4 | ||
3 | There are numerous QDict functions that have been introduced for and are | 5 | bdrv_snapshot_goto() needs to make sure that it is zeroed again before |
4 | used only by the block layer. Move their declarations into an own | 6 | calling drv->bdrv_open() to avoid that block drivers use stale values. |
5 | header file to reflect that. | ||
6 | 7 | ||
7 | While qdict_extract_subqdict() is in fact used outside of the block | 8 | One symptom of this bug is VMDK running into a double free when the user |
8 | layer (in util/qemu-config.c), it is still a function related very | 9 | tries to apply an internal snapshot like 'qemu-img snapshot -a test |
9 | closely to how the block layer works with nested QDicts, namely by | 10 | test.vmdk'. This should be a graceful error because VMDK doesn't support |
10 | sometimes flattening them. Therefore, its declaration is put into this | 11 | internal snapshots. |
11 | header as well and util/qemu-config.c includes it with a comment stating | ||
12 | exactly which function it needs. | ||
13 | 12 | ||
14 | Suggested-by: Markus Armbruster <armbru@redhat.com> | 13 | ==25507== Invalid free() / delete / delete[] / realloc() |
15 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 14 | ==25507== at 0x484B347: realloc (vg_replace_malloc.c:1801) |
16 | Message-Id: <20180509165530.29561-7-mreitz@redhat.com> | 15 | ==25507== by 0x54B592A: g_realloc (gmem.c:171) |
17 | [Copyright note tweaked, superfluous includes dropped] | 16 | ==25507== by 0x1B221D: vmdk_add_extent (../block/vmdk.c:570) |
18 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 17 | ==25507== by 0x1B1084: vmdk_open_sparse (../block/vmdk.c:1059) |
19 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 18 | ==25507== by 0x1AF3D8: vmdk_open (../block/vmdk.c:1371) |
19 | ==25507== by 0x1A2AE0: bdrv_snapshot_goto (../block/snapshot.c:299) | ||
20 | ==25507== by 0x205C77: img_snapshot (../qemu-img.c:3500) | ||
21 | ==25507== by 0x58FA087: (below main) (libc_start_call_main.h:58) | ||
22 | ==25507== Address 0x832f3e0 is 0 bytes inside a block of size 272 free'd | ||
23 | ==25507== at 0x4846B83: free (vg_replace_malloc.c:989) | ||
24 | ==25507== by 0x54AEAC4: g_free (gmem.c:208) | ||
25 | ==25507== by 0x1AF629: vmdk_close (../block/vmdk.c:2889) | ||
26 | ==25507== by 0x1A2A9C: bdrv_snapshot_goto (../block/snapshot.c:290) | ||
27 | ==25507== by 0x205C77: img_snapshot (../qemu-img.c:3500) | ||
28 | ==25507== by 0x58FA087: (below main) (libc_start_call_main.h:58) | ||
29 | |||
30 | This error was discovered by fuzzing qemu-img. | ||
31 | |||
32 | Cc: qemu-stable@nongnu.org | ||
33 | Closes: https://gitlab.com/qemu-project/qemu/-/issues/2853 | ||
34 | Closes: https://gitlab.com/qemu-project/qemu/-/issues/2851 | ||
35 | Reported-by: Denis Rastyogin <gerben@altlinux.org> | ||
36 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
37 | Message-ID: <20250310104858.28221-1-kwolf@redhat.com> | ||
20 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 38 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
21 | --- | 39 | --- |
22 | include/block/qdict.h | 32 ++++++++++++++++++++++++++++++++ | 40 | block/snapshot.c | 1 + |
23 | include/qapi/qmp/qdict.h | 17 ----------------- | 41 | 1 file changed, 1 insertion(+) |
24 | block.c | 1 + | ||
25 | block/gluster.c | 1 + | ||
26 | block/iscsi.c | 1 + | ||
27 | block/nbd.c | 1 + | ||
28 | block/nfs.c | 1 + | ||
29 | block/parallels.c | 1 + | ||
30 | block/qcow.c | 1 + | ||
31 | block/qcow2.c | 1 + | ||
32 | block/qed.c | 1 + | ||
33 | block/quorum.c | 1 + | ||
34 | block/rbd.c | 1 + | ||
35 | block/sheepdog.c | 1 + | ||
36 | block/snapshot.c | 1 + | ||
37 | block/ssh.c | 1 + | ||
38 | block/vhdx.c | 1 + | ||
39 | block/vpc.c | 1 + | ||
40 | block/vvfat.c | 1 + | ||
41 | block/vxhs.c | 1 + | ||
42 | blockdev.c | 1 + | ||
43 | qobject/qdict.c | 1 + | ||
44 | tests/check-qdict.c | 1 + | ||
45 | tests/check-qobject.c | 1 + | ||
46 | tests/test-replication.c | 1 + | ||
47 | util/qemu-config.c | 1 + | ||
48 | 26 files changed, 56 insertions(+), 17 deletions(-) | ||
49 | create mode 100644 include/block/qdict.h | ||
50 | 42 | ||
51 | diff --git a/include/block/qdict.h b/include/block/qdict.h | ||
52 | new file mode 100644 | ||
53 | index XXXXXXX..XXXXXXX | ||
54 | --- /dev/null | ||
55 | +++ b/include/block/qdict.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
57 | +/* | ||
58 | + * Special QDict functions used by the block layer | ||
59 | + * | ||
60 | + * Copyright (c) 2013-2018 Red Hat, Inc. | ||
61 | + * | ||
62 | + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. | ||
63 | + * See the COPYING.LIB file in the top-level directory. | ||
64 | + */ | ||
65 | + | ||
66 | +#ifndef BLOCK_QDICT_H | ||
67 | +#define BLOCK_QDICT_H | ||
68 | + | ||
69 | +#include "qapi/qmp/qdict.h" | ||
70 | + | ||
71 | +void qdict_copy_default(QDict *dst, QDict *src, const char *key); | ||
72 | +void qdict_set_default_str(QDict *dst, const char *key, const char *val); | ||
73 | + | ||
74 | +void qdict_join(QDict *dest, QDict *src, bool overwrite); | ||
75 | + | ||
76 | +void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); | ||
77 | +void qdict_array_split(QDict *src, QList **dst); | ||
78 | +int qdict_array_entries(QDict *src, const char *subqdict); | ||
79 | +QObject *qdict_crumple(const QDict *src, Error **errp); | ||
80 | +void qdict_flatten(QDict *qdict); | ||
81 | + | ||
82 | +typedef struct QDictRenames { | ||
83 | + const char *from; | ||
84 | + const char *to; | ||
85 | +} QDictRenames; | ||
86 | +bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp); | ||
87 | + | ||
88 | +#endif | ||
89 | diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/include/qapi/qmp/qdict.h | ||
92 | +++ b/include/qapi/qmp/qdict.h | ||
93 | @@ -XXX,XX +XXX,XX @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key, | ||
94 | bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value); | ||
95 | const char *qdict_get_try_str(const QDict *qdict, const char *key); | ||
96 | |||
97 | -void qdict_copy_default(QDict *dst, QDict *src, const char *key); | ||
98 | -void qdict_set_default_str(QDict *dst, const char *key, const char *val); | ||
99 | - | ||
100 | QDict *qdict_clone_shallow(const QDict *src); | ||
101 | -void qdict_flatten(QDict *qdict); | ||
102 | - | ||
103 | -void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); | ||
104 | -void qdict_array_split(QDict *src, QList **dst); | ||
105 | -int qdict_array_entries(QDict *src, const char *subqdict); | ||
106 | -QObject *qdict_crumple(const QDict *src, Error **errp); | ||
107 | - | ||
108 | -void qdict_join(QDict *dest, QDict *src, bool overwrite); | ||
109 | - | ||
110 | -typedef struct QDictRenames { | ||
111 | - const char *from; | ||
112 | - const char *to; | ||
113 | -} QDictRenames; | ||
114 | -bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp); | ||
115 | |||
116 | #endif /* QDICT_H */ | ||
117 | diff --git a/block.c b/block.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/block.c | ||
120 | +++ b/block.c | ||
121 | @@ -XXX,XX +XXX,XX @@ | ||
122 | #include "block/block_int.h" | ||
123 | #include "block/blockjob.h" | ||
124 | #include "block/nbd.h" | ||
125 | +#include "block/qdict.h" | ||
126 | #include "qemu/error-report.h" | ||
127 | #include "module_block.h" | ||
128 | #include "qemu/module.h" | ||
129 | diff --git a/block/gluster.c b/block/gluster.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/block/gluster.c | ||
132 | +++ b/block/gluster.c | ||
133 | @@ -XXX,XX +XXX,XX @@ | ||
134 | #include "qemu/osdep.h" | ||
135 | #include <glusterfs/api/glfs.h> | ||
136 | #include "block/block_int.h" | ||
137 | +#include "block/qdict.h" | ||
138 | #include "qapi/error.h" | ||
139 | #include "qapi/qmp/qdict.h" | ||
140 | #include "qapi/qmp/qerror.h" | ||
141 | diff --git a/block/iscsi.c b/block/iscsi.c | ||
142 | index XXXXXXX..XXXXXXX 100644 | ||
143 | --- a/block/iscsi.c | ||
144 | +++ b/block/iscsi.c | ||
145 | @@ -XXX,XX +XXX,XX @@ | ||
146 | #include "qemu/bitops.h" | ||
147 | #include "qemu/bitmap.h" | ||
148 | #include "block/block_int.h" | ||
149 | +#include "block/qdict.h" | ||
150 | #include "scsi/constants.h" | ||
151 | #include "qemu/iov.h" | ||
152 | #include "qemu/option.h" | ||
153 | diff --git a/block/nbd.c b/block/nbd.c | ||
154 | index XXXXXXX..XXXXXXX 100644 | ||
155 | --- a/block/nbd.c | ||
156 | +++ b/block/nbd.c | ||
157 | @@ -XXX,XX +XXX,XX @@ | ||
158 | |||
159 | #include "qemu/osdep.h" | ||
160 | #include "nbd-client.h" | ||
161 | +#include "block/qdict.h" | ||
162 | #include "qapi/error.h" | ||
163 | #include "qemu/uri.h" | ||
164 | #include "block/block_int.h" | ||
165 | diff --git a/block/nfs.c b/block/nfs.c | ||
166 | index XXXXXXX..XXXXXXX 100644 | ||
167 | --- a/block/nfs.c | ||
168 | +++ b/block/nfs.c | ||
169 | @@ -XXX,XX +XXX,XX @@ | ||
170 | #include "qemu/error-report.h" | ||
171 | #include "qapi/error.h" | ||
172 | #include "block/block_int.h" | ||
173 | +#include "block/qdict.h" | ||
174 | #include "trace.h" | ||
175 | #include "qemu/iov.h" | ||
176 | #include "qemu/option.h" | ||
177 | diff --git a/block/parallels.c b/block/parallels.c | ||
178 | index XXXXXXX..XXXXXXX 100644 | ||
179 | --- a/block/parallels.c | ||
180 | +++ b/block/parallels.c | ||
181 | @@ -XXX,XX +XXX,XX @@ | ||
182 | #include "qemu/osdep.h" | ||
183 | #include "qapi/error.h" | ||
184 | #include "block/block_int.h" | ||
185 | +#include "block/qdict.h" | ||
186 | #include "sysemu/block-backend.h" | ||
187 | #include "qemu/module.h" | ||
188 | #include "qemu/option.h" | ||
189 | diff --git a/block/qcow.c b/block/qcow.c | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/block/qcow.c | ||
192 | +++ b/block/qcow.c | ||
193 | @@ -XXX,XX +XXX,XX @@ | ||
194 | #include "qapi/error.h" | ||
195 | #include "qemu/error-report.h" | ||
196 | #include "block/block_int.h" | ||
197 | +#include "block/qdict.h" | ||
198 | #include "sysemu/block-backend.h" | ||
199 | #include "qemu/module.h" | ||
200 | #include "qemu/option.h" | ||
201 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/block/qcow2.c | ||
204 | +++ b/block/qcow2.c | ||
205 | @@ -XXX,XX +XXX,XX @@ | ||
206 | |||
207 | #include "qemu/osdep.h" | ||
208 | #include "block/block_int.h" | ||
209 | +#include "block/qdict.h" | ||
210 | #include "sysemu/block-backend.h" | ||
211 | #include "qemu/module.h" | ||
212 | #include <zlib.h> | ||
213 | diff --git a/block/qed.c b/block/qed.c | ||
214 | index XXXXXXX..XXXXXXX 100644 | ||
215 | --- a/block/qed.c | ||
216 | +++ b/block/qed.c | ||
217 | @@ -XXX,XX +XXX,XX @@ | ||
218 | */ | ||
219 | |||
220 | #include "qemu/osdep.h" | ||
221 | +#include "block/qdict.h" | ||
222 | #include "qapi/error.h" | ||
223 | #include "qemu/timer.h" | ||
224 | #include "qemu/bswap.h" | ||
225 | diff --git a/block/quorum.c b/block/quorum.c | ||
226 | index XXXXXXX..XXXXXXX 100644 | ||
227 | --- a/block/quorum.c | ||
228 | +++ b/block/quorum.c | ||
229 | @@ -XXX,XX +XXX,XX @@ | ||
230 | #include "qemu/cutils.h" | ||
231 | #include "qemu/option.h" | ||
232 | #include "block/block_int.h" | ||
233 | +#include "block/qdict.h" | ||
234 | #include "qapi/error.h" | ||
235 | #include "qapi/qapi-events-block.h" | ||
236 | #include "qapi/qmp/qdict.h" | ||
237 | diff --git a/block/rbd.c b/block/rbd.c | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/block/rbd.c | ||
240 | +++ b/block/rbd.c | ||
241 | @@ -XXX,XX +XXX,XX @@ | ||
242 | #include "qemu/error-report.h" | ||
243 | #include "qemu/option.h" | ||
244 | #include "block/block_int.h" | ||
245 | +#include "block/qdict.h" | ||
246 | #include "crypto/secret.h" | ||
247 | #include "qemu/cutils.h" | ||
248 | #include "qapi/qmp/qstring.h" | ||
249 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
250 | index XXXXXXX..XXXXXXX 100644 | ||
251 | --- a/block/sheepdog.c | ||
252 | +++ b/block/sheepdog.c | ||
253 | @@ -XXX,XX +XXX,XX @@ | ||
254 | #include "qemu/option.h" | ||
255 | #include "qemu/sockets.h" | ||
256 | #include "block/block_int.h" | ||
257 | +#include "block/qdict.h" | ||
258 | #include "sysemu/block-backend.h" | ||
259 | #include "qemu/bitops.h" | ||
260 | #include "qemu/cutils.h" | ||
261 | diff --git a/block/snapshot.c b/block/snapshot.c | 43 | diff --git a/block/snapshot.c b/block/snapshot.c |
262 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
263 | --- a/block/snapshot.c | 45 | --- a/block/snapshot.c |
264 | +++ b/block/snapshot.c | 46 | +++ b/block/snapshot.c |
265 | @@ -XXX,XX +XXX,XX @@ | 47 | @@ -XXX,XX +XXX,XX @@ int bdrv_snapshot_goto(BlockDriverState *bs, |
266 | #include "qemu/osdep.h" | 48 | bdrv_graph_wrunlock(); |
267 | #include "block/snapshot.h" | 49 | |
268 | #include "block/block_int.h" | 50 | ret = bdrv_snapshot_goto(fallback_bs, snapshot_id, errp); |
269 | +#include "block/qdict.h" | 51 | + memset(bs->opaque, 0, drv->instance_size); |
270 | #include "qapi/error.h" | 52 | open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err); |
271 | #include "qapi/qmp/qdict.h" | 53 | qobject_unref(options); |
272 | #include "qapi/qmp/qerror.h" | 54 | if (open_ret < 0) { |
273 | diff --git a/block/ssh.c b/block/ssh.c | ||
274 | index XXXXXXX..XXXXXXX 100644 | ||
275 | --- a/block/ssh.c | ||
276 | +++ b/block/ssh.c | ||
277 | @@ -XXX,XX +XXX,XX @@ | ||
278 | #include <libssh2_sftp.h> | ||
279 | |||
280 | #include "block/block_int.h" | ||
281 | +#include "block/qdict.h" | ||
282 | #include "qapi/error.h" | ||
283 | #include "qemu/error-report.h" | ||
284 | #include "qemu/option.h" | ||
285 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
286 | index XXXXXXX..XXXXXXX 100644 | ||
287 | --- a/block/vhdx.c | ||
288 | +++ b/block/vhdx.c | ||
289 | @@ -XXX,XX +XXX,XX @@ | ||
290 | #include "qemu/osdep.h" | ||
291 | #include "qapi/error.h" | ||
292 | #include "block/block_int.h" | ||
293 | +#include "block/qdict.h" | ||
294 | #include "sysemu/block-backend.h" | ||
295 | #include "qemu/module.h" | ||
296 | #include "qemu/option.h" | ||
297 | diff --git a/block/vpc.c b/block/vpc.c | ||
298 | index XXXXXXX..XXXXXXX 100644 | ||
299 | --- a/block/vpc.c | ||
300 | +++ b/block/vpc.c | ||
301 | @@ -XXX,XX +XXX,XX @@ | ||
302 | #include "qemu/osdep.h" | ||
303 | #include "qapi/error.h" | ||
304 | #include "block/block_int.h" | ||
305 | +#include "block/qdict.h" | ||
306 | #include "sysemu/block-backend.h" | ||
307 | #include "qemu/module.h" | ||
308 | #include "qemu/option.h" | ||
309 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
310 | index XXXXXXX..XXXXXXX 100644 | ||
311 | --- a/block/vvfat.c | ||
312 | +++ b/block/vvfat.c | ||
313 | @@ -XXX,XX +XXX,XX @@ | ||
314 | #include <dirent.h> | ||
315 | #include "qapi/error.h" | ||
316 | #include "block/block_int.h" | ||
317 | +#include "block/qdict.h" | ||
318 | #include "qemu/module.h" | ||
319 | #include "qemu/option.h" | ||
320 | #include "qemu/bswap.h" | ||
321 | diff --git a/block/vxhs.c b/block/vxhs.c | ||
322 | index XXXXXXX..XXXXXXX 100644 | ||
323 | --- a/block/vxhs.c | ||
324 | +++ b/block/vxhs.c | ||
325 | @@ -XXX,XX +XXX,XX @@ | ||
326 | #include <qnio/qnio_api.h> | ||
327 | #include <sys/param.h> | ||
328 | #include "block/block_int.h" | ||
329 | +#include "block/qdict.h" | ||
330 | #include "qapi/qmp/qerror.h" | ||
331 | #include "qapi/qmp/qdict.h" | ||
332 | #include "qapi/qmp/qstring.h" | ||
333 | diff --git a/blockdev.c b/blockdev.c | ||
334 | index XXXXXXX..XXXXXXX 100644 | ||
335 | --- a/blockdev.c | ||
336 | +++ b/blockdev.c | ||
337 | @@ -XXX,XX +XXX,XX @@ | ||
338 | #include "sysemu/blockdev.h" | ||
339 | #include "hw/block/block.h" | ||
340 | #include "block/blockjob.h" | ||
341 | +#include "block/qdict.h" | ||
342 | #include "block/throttle-groups.h" | ||
343 | #include "monitor/monitor.h" | ||
344 | #include "qemu/error-report.h" | ||
345 | diff --git a/qobject/qdict.c b/qobject/qdict.c | ||
346 | index XXXXXXX..XXXXXXX 100644 | ||
347 | --- a/qobject/qdict.c | ||
348 | +++ b/qobject/qdict.c | ||
349 | @@ -XXX,XX +XXX,XX @@ | ||
350 | */ | ||
351 | |||
352 | #include "qemu/osdep.h" | ||
353 | +#include "block/qdict.h" | ||
354 | #include "qapi/qmp/qnum.h" | ||
355 | #include "qapi/qmp/qdict.h" | ||
356 | #include "qapi/qmp/qbool.h" | ||
357 | diff --git a/tests/check-qdict.c b/tests/check-qdict.c | ||
358 | index XXXXXXX..XXXXXXX 100644 | ||
359 | --- a/tests/check-qdict.c | ||
360 | +++ b/tests/check-qdict.c | ||
361 | @@ -XXX,XX +XXX,XX @@ | ||
362 | */ | ||
363 | |||
364 | #include "qemu/osdep.h" | ||
365 | +#include "block/qdict.h" | ||
366 | #include "qapi/qmp/qdict.h" | ||
367 | #include "qapi/qmp/qlist.h" | ||
368 | #include "qapi/qmp/qnum.h" | ||
369 | diff --git a/tests/check-qobject.c b/tests/check-qobject.c | ||
370 | index XXXXXXX..XXXXXXX 100644 | ||
371 | --- a/tests/check-qobject.c | ||
372 | +++ b/tests/check-qobject.c | ||
373 | @@ -XXX,XX +XXX,XX @@ | ||
374 | */ | ||
375 | |||
376 | #include "qemu/osdep.h" | ||
377 | +#include "block/qdict.h" | ||
378 | #include "qapi/qmp/qbool.h" | ||
379 | #include "qapi/qmp/qdict.h" | ||
380 | #include "qapi/qmp/qlist.h" | ||
381 | diff --git a/tests/test-replication.c b/tests/test-replication.c | ||
382 | index XXXXXXX..XXXXXXX 100644 | ||
383 | --- a/tests/test-replication.c | ||
384 | +++ b/tests/test-replication.c | ||
385 | @@ -XXX,XX +XXX,XX @@ | ||
386 | #include "qemu/option.h" | ||
387 | #include "replication.h" | ||
388 | #include "block/block_int.h" | ||
389 | +#include "block/qdict.h" | ||
390 | #include "sysemu/block-backend.h" | ||
391 | |||
392 | #define IMG_SIZE (64 * 1024 * 1024) | ||
393 | diff --git a/util/qemu-config.c b/util/qemu-config.c | ||
394 | index XXXXXXX..XXXXXXX 100644 | ||
395 | --- a/util/qemu-config.c | ||
396 | +++ b/util/qemu-config.c | ||
397 | @@ -XXX,XX +XXX,XX @@ | ||
398 | #include "qemu/osdep.h" | ||
399 | +#include "block/qdict.h" /* for qdict_extract_subqdict() */ | ||
400 | #include "qapi/error.h" | ||
401 | #include "qapi/qapi-commands-misc.h" | ||
402 | #include "qapi/qmp/qdict.h" | ||
403 | -- | 55 | -- |
404 | 2.13.6 | 56 | 2.48.1 |
405 | |||
406 | diff view generated by jsdifflib |
1 | We removed all options from the 'deprecated' array, so the code is dead | 1 | Until now, FUA was always emulated with a separate flush after the write |
---|---|---|---|
2 | and can be removed as well. | 2 | for file-posix. The overhead of processing a second request can reduce |
3 | performance significantly for a guest disk that has disabled the write | ||
4 | cache, especially if the host disk is already write through, too, and | ||
5 | the flush isn't actually doing anything. | ||
6 | |||
7 | Advertise support for REQ_FUA in write requests and implement it for | ||
8 | Linux AIO and io_uring using the RWF_DSYNC flag for write requests. The | ||
9 | thread pool still performs a separate fdatasync() call. This can be | ||
10 | improved later by using the pwritev2() syscall if available. | ||
11 | |||
12 | As an example, this is how fio numbers can be improved in some scenarios | ||
13 | with this patch (all using virtio-blk with cache=directsync on an nvme | ||
14 | block device for the VM, fio with ioengine=libaio,direct=1,sync=1): | ||
15 | |||
16 | | old | with FUA support | ||
17 | ------------------------------+---------------+------------------- | ||
18 | bs=4k, iodepth=1, numjobs=1 | 45.6k iops | 56.1k iops | ||
19 | bs=4k, iodepth=1, numjobs=16 | 183.3k iops | 236.0k iops | ||
20 | bs=4k, iodepth=16, numjobs=1 | 258.4k iops | 311.1k iops | ||
21 | |||
22 | However, not all scenarios are clear wins. On another slower disk I saw | ||
23 | little to no improvment. In fact, in two corner case scenarios, I even | ||
24 | observed a regression, which I however consider acceptable: | ||
25 | |||
26 | 1. On slow host disks in a write through cache mode, when the guest is | ||
27 | using virtio-blk in a separate iothread so that polling can be | ||
28 | enabled, and each completion is quickly followed up with a new | ||
29 | request (so that polling gets it), it can happen that enabling FUA | ||
30 | makes things slower - the additional very fast no-op flush we used to | ||
31 | have gave the adaptive polling algorithm a success so that it kept | ||
32 | polling. Without it, we only have the slow write request, which | ||
33 | disables polling. This is a problem in the polling algorithm that | ||
34 | will be fixed later in this series. | ||
35 | |||
36 | 2. With a high queue depth, it can be beneficial to have flush requests | ||
37 | for another reason: The optimisation in bdrv_co_flush() that flushes | ||
38 | only once per write generation acts as a synchronisation mechanism | ||
39 | that lets all requests complete at the same time. This can result in | ||
40 | better batching and if the disk is very fast (I only saw this with a | ||
41 | null_blk backend), this can make up for the overhead of the flush and | ||
42 | improve throughput. In theory, we could optionally introduce a | ||
43 | similar artificial latency in the normal completion path to achieve | ||
44 | the same kind of completion batching. This is not implemented in this | ||
45 | series. | ||
46 | |||
47 | Compatibility is not a concern for io_uring, it has supported RWF_DSYNC | ||
48 | from the start. Linux AIO started supporting it in Linux 4.13 and libaio | ||
49 | 0.3.111. The kernel is not a problem for any supported build platform, | ||
50 | so it's not necessary to add runtime checks. However, openSUSE is still | ||
51 | stuck with an older libaio version that would break the build. We must | ||
52 | detect this at build time to avoid build failures. | ||
3 | 53 | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 54 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
5 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | 55 | Message-ID: <20250307221634.71951-2-kwolf@redhat.com> |
56 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
57 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
6 | --- | 58 | --- |
7 | blockdev.c | 12 ------------ | 59 | include/block/raw-aio.h | 8 ++++++-- |
8 | 1 file changed, 12 deletions(-) | 60 | block/file-posix.c | 26 ++++++++++++++++++-------- |
9 | 61 | block/io_uring.c | 13 ++++++++----- | |
10 | diff --git a/blockdev.c b/blockdev.c | 62 | block/linux-aio.c | 24 +++++++++++++++++++++--- |
11 | index XXXXXXX..XXXXXXX 100644 | 63 | meson.build | 4 ++++ |
12 | --- a/blockdev.c | 64 | 5 files changed, 57 insertions(+), 18 deletions(-) |
13 | +++ b/blockdev.c | 65 | |
14 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | 66 | diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h |
15 | const char *filename; | 67 | index XXXXXXX..XXXXXXX 100644 |
16 | Error *local_err = NULL; | 68 | --- a/include/block/raw-aio.h |
17 | int i; | 69 | +++ b/include/block/raw-aio.h |
18 | - const char *deprecated[] = { | 70 | @@ -XXX,XX +XXX,XX @@ |
19 | - }; | 71 | #define QEMU_RAW_AIO_H |
20 | 72 | ||
21 | /* Change legacy command line options into QMP ones */ | 73 | #include "block/aio.h" |
22 | static const struct { | 74 | +#include "block/block-common.h" |
23 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | 75 | #include "qemu/iov.h" |
24 | goto fail; | 76 | |
77 | /* AIO request types */ | ||
78 | @@ -XXX,XX +XXX,XX @@ void laio_cleanup(LinuxAioState *s); | ||
79 | |||
80 | /* laio_co_submit: submit I/O requests in the thread's current AioContext. */ | ||
81 | int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov, | ||
82 | - int type, uint64_t dev_max_batch); | ||
83 | + int type, BdrvRequestFlags flags, | ||
84 | + uint64_t dev_max_batch); | ||
85 | |||
86 | bool laio_has_fdsync(int); | ||
87 | +bool laio_has_fua(void); | ||
88 | void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); | ||
89 | void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); | ||
90 | #endif | ||
91 | @@ -XXX,XX +XXX,XX @@ void luring_cleanup(LuringState *s); | ||
92 | |||
93 | /* luring_co_submit: submit I/O requests in the thread's current AioContext. */ | ||
94 | int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset, | ||
95 | - QEMUIOVector *qiov, int type); | ||
96 | + QEMUIOVector *qiov, int type, | ||
97 | + BdrvRequestFlags flags); | ||
98 | void luring_detach_aio_context(LuringState *s, AioContext *old_context); | ||
99 | void luring_attach_aio_context(LuringState *s, AioContext *new_context); | ||
100 | #endif | ||
101 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/block/file-posix.c | ||
104 | +++ b/block/file-posix.c | ||
105 | @@ -XXX,XX +XXX,XX @@ static int fd_open(BlockDriverState *bs) | ||
106 | } | ||
107 | |||
108 | static int64_t raw_getlength(BlockDriverState *bs); | ||
109 | +static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs); | ||
110 | |||
111 | typedef struct RawPosixAIOData { | ||
112 | BlockDriverState *bs; | ||
113 | @@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options, | ||
114 | #endif | ||
115 | s->needs_alignment = raw_needs_alignment(bs); | ||
116 | |||
117 | + if (!s->use_linux_aio || laio_has_fua()) { | ||
118 | + bs->supported_write_flags = BDRV_REQ_FUA; | ||
119 | + } | ||
120 | + | ||
121 | bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK; | ||
122 | if (S_ISREG(st.st_mode)) { | ||
123 | /* When extending regular files, we get zeros from the OS */ | ||
124 | @@ -XXX,XX +XXX,XX @@ static inline bool raw_check_linux_aio(BDRVRawState *s) | ||
125 | #endif | ||
126 | |||
127 | static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr, | ||
128 | - uint64_t bytes, QEMUIOVector *qiov, int type) | ||
129 | + uint64_t bytes, QEMUIOVector *qiov, int type, | ||
130 | + int flags) | ||
131 | { | ||
132 | BDRVRawState *s = bs->opaque; | ||
133 | RawPosixAIOData acb; | ||
134 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr, | ||
135 | #ifdef CONFIG_LINUX_IO_URING | ||
136 | } else if (raw_check_linux_io_uring(s)) { | ||
137 | assert(qiov->size == bytes); | ||
138 | - ret = luring_co_submit(bs, s->fd, offset, qiov, type); | ||
139 | + ret = luring_co_submit(bs, s->fd, offset, qiov, type, flags); | ||
140 | goto out; | ||
141 | #endif | ||
142 | #ifdef CONFIG_LINUX_AIO | ||
143 | } else if (raw_check_linux_aio(s)) { | ||
144 | assert(qiov->size == bytes); | ||
145 | - ret = laio_co_submit(s->fd, offset, qiov, type, | ||
146 | + ret = laio_co_submit(s->fd, offset, qiov, type, flags, | ||
147 | s->aio_max_batch); | ||
148 | goto out; | ||
149 | #endif | ||
150 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr, | ||
151 | |||
152 | assert(qiov->size == bytes); | ||
153 | ret = raw_thread_pool_submit(handle_aiocb_rw, &acb); | ||
154 | + if (ret == 0 && (flags & BDRV_REQ_FUA)) { | ||
155 | + /* TODO Use pwritev2() instead if it's available */ | ||
156 | + ret = raw_co_flush_to_disk(bs); | ||
157 | + } | ||
158 | goto out; /* Avoid the compiler err of unused label */ | ||
159 | |||
160 | out: | ||
161 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, | ||
162 | int64_t bytes, QEMUIOVector *qiov, | ||
163 | BdrvRequestFlags flags) | ||
164 | { | ||
165 | - return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ); | ||
166 | + return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ, flags); | ||
167 | } | ||
168 | |||
169 | static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offset, | ||
170 | int64_t bytes, QEMUIOVector *qiov, | ||
171 | BdrvRequestFlags flags) | ||
172 | { | ||
173 | - return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE); | ||
174 | + return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE, flags); | ||
175 | } | ||
176 | |||
177 | static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs) | ||
178 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_flush_to_disk(BlockDriverState *bs) | ||
179 | |||
180 | #ifdef CONFIG_LINUX_IO_URING | ||
181 | if (raw_check_linux_io_uring(s)) { | ||
182 | - return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); | ||
183 | + return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH, 0); | ||
25 | } | 184 | } |
26 | 185 | #endif | |
27 | - /* Other deprecated options */ | 186 | #ifdef CONFIG_LINUX_AIO |
28 | - if (!qtest_enabled()) { | 187 | if (s->has_laio_fdsync && raw_check_linux_aio(s)) { |
29 | - for (i = 0; i < ARRAY_SIZE(deprecated); i++) { | 188 | - return laio_co_submit(s->fd, 0, NULL, QEMU_AIO_FLUSH, 0); |
30 | - if (qemu_opt_get(legacy_opts, deprecated[i]) != NULL) { | 189 | + return laio_co_submit(s->fd, 0, NULL, QEMU_AIO_FLUSH, 0, 0); |
31 | - error_report("'%s' is deprecated, please use the corresponding " | 190 | } |
32 | - "option of '-device' instead", deprecated[i]); | 191 | #endif |
33 | - } | 192 | return raw_thread_pool_submit(handle_aiocb_flush, &acb); |
34 | - } | 193 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, |
35 | - } | 194 | } |
36 | - | 195 | |
37 | /* Media type */ | 196 | trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS); |
38 | value = qemu_opt_get(legacy_opts, "media"); | 197 | - return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND); |
39 | if (value) { | 198 | + return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND, 0); |
199 | } | ||
200 | #endif | ||
201 | |||
202 | diff --git a/block/io_uring.c b/block/io_uring.c | ||
203 | index XXXXXXX..XXXXXXX 100644 | ||
204 | --- a/block/io_uring.c | ||
205 | +++ b/block/io_uring.c | ||
206 | @@ -XXX,XX +XXX,XX @@ static void luring_deferred_fn(void *opaque) | ||
207 | * | ||
208 | */ | ||
209 | static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, | ||
210 | - uint64_t offset, int type) | ||
211 | + uint64_t offset, int type, BdrvRequestFlags flags) | ||
212 | { | ||
213 | int ret; | ||
214 | struct io_uring_sqe *sqes = &luringcb->sqeq; | ||
215 | + int luring_flags; | ||
216 | |||
217 | switch (type) { | ||
218 | case QEMU_AIO_WRITE: | ||
219 | - io_uring_prep_writev(sqes, fd, luringcb->qiov->iov, | ||
220 | - luringcb->qiov->niov, offset); | ||
221 | + luring_flags = (flags & BDRV_REQ_FUA) ? RWF_DSYNC : 0; | ||
222 | + io_uring_prep_writev2(sqes, fd, luringcb->qiov->iov, | ||
223 | + luringcb->qiov->niov, offset, luring_flags); | ||
224 | break; | ||
225 | case QEMU_AIO_ZONE_APPEND: | ||
226 | io_uring_prep_writev(sqes, fd, luringcb->qiov->iov, | ||
227 | @@ -XXX,XX +XXX,XX @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s, | ||
228 | } | ||
229 | |||
230 | int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset, | ||
231 | - QEMUIOVector *qiov, int type) | ||
232 | + QEMUIOVector *qiov, int type, | ||
233 | + BdrvRequestFlags flags) | ||
234 | { | ||
235 | int ret; | ||
236 | AioContext *ctx = qemu_get_current_aio_context(); | ||
237 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t offset, | ||
238 | }; | ||
239 | trace_luring_co_submit(bs, s, &luringcb, fd, offset, qiov ? qiov->size : 0, | ||
240 | type); | ||
241 | - ret = luring_do_submit(fd, &luringcb, s, offset, type); | ||
242 | + ret = luring_do_submit(fd, &luringcb, s, offset, type, flags); | ||
243 | |||
244 | if (ret < 0) { | ||
245 | return ret; | ||
246 | diff --git a/block/linux-aio.c b/block/linux-aio.c | ||
247 | index XXXXXXX..XXXXXXX 100644 | ||
248 | --- a/block/linux-aio.c | ||
249 | +++ b/block/linux-aio.c | ||
250 | @@ -XXX,XX +XXX,XX @@ static void laio_deferred_fn(void *opaque) | ||
251 | } | ||
252 | |||
253 | static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, | ||
254 | - int type, uint64_t dev_max_batch) | ||
255 | + int type, BdrvRequestFlags flags, | ||
256 | + uint64_t dev_max_batch) | ||
257 | { | ||
258 | LinuxAioState *s = laiocb->ctx; | ||
259 | struct iocb *iocbs = &laiocb->iocb; | ||
260 | QEMUIOVector *qiov = laiocb->qiov; | ||
261 | + int laio_flags; | ||
262 | |||
263 | switch (type) { | ||
264 | case QEMU_AIO_WRITE: | ||
265 | +#ifdef HAVE_IO_PREP_PWRITEV2 | ||
266 | + laio_flags = (flags & BDRV_REQ_FUA) ? RWF_DSYNC : 0; | ||
267 | + io_prep_pwritev2(iocbs, fd, qiov->iov, qiov->niov, offset, laio_flags); | ||
268 | +#else | ||
269 | + assert(flags == 0); | ||
270 | io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset); | ||
271 | +#endif | ||
272 | break; | ||
273 | case QEMU_AIO_ZONE_APPEND: | ||
274 | io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset); | ||
275 | @@ -XXX,XX +XXX,XX @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset, | ||
276 | } | ||
277 | |||
278 | int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov, | ||
279 | - int type, uint64_t dev_max_batch) | ||
280 | + int type, BdrvRequestFlags flags, | ||
281 | + uint64_t dev_max_batch) | ||
282 | { | ||
283 | int ret; | ||
284 | AioContext *ctx = qemu_get_current_aio_context(); | ||
285 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qiov, | ||
286 | .qiov = qiov, | ||
287 | }; | ||
288 | |||
289 | - ret = laio_do_submit(fd, &laiocb, offset, type, dev_max_batch); | ||
290 | + ret = laio_do_submit(fd, &laiocb, offset, type, flags, dev_max_batch); | ||
291 | if (ret < 0) { | ||
292 | return ret; | ||
293 | } | ||
294 | @@ -XXX,XX +XXX,XX @@ bool laio_has_fdsync(int fd) | ||
295 | io_destroy(ctx); | ||
296 | return (ret == -EINVAL) ? false : true; | ||
297 | } | ||
298 | + | ||
299 | +bool laio_has_fua(void) | ||
300 | +{ | ||
301 | +#ifdef HAVE_IO_PREP_PWRITEV2 | ||
302 | + return true; | ||
303 | +#else | ||
304 | + return false; | ||
305 | +#endif | ||
306 | +} | ||
307 | diff --git a/meson.build b/meson.build | ||
308 | index XXXXXXX..XXXXXXX 100644 | ||
309 | --- a/meson.build | ||
310 | +++ b/meson.build | ||
311 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('HAVE_OPTRESET', | ||
312 | cc.has_header_symbol('getopt.h', 'optreset')) | ||
313 | config_host_data.set('HAVE_IPPROTO_MPTCP', | ||
314 | cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP')) | ||
315 | +if libaio.found() | ||
316 | + config_host_data.set('HAVE_IO_PREP_PWRITEV2', | ||
317 | + cc.has_header_symbol('libaio.h', 'io_prep_pwritev2')) | ||
318 | +endif | ||
319 | |||
320 | # has_member | ||
321 | config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', | ||
40 | -- | 322 | -- |
41 | 2.13.6 | 323 | 2.48.1 |
42 | |||
43 | diff view generated by jsdifflib |
1 | The -drive option addr was deprecated in QEMU 2.10. It's time to remove | 1 | For block drivers that don't advertise FUA support, we already call |
---|---|---|---|
2 | it. | 2 | bdrv_co_flush(), which considers BDRV_O_NO_FLUSH. However, drivers that |
3 | do support FUA still see the FUA flag with BDRV_O_NO_FLUSH and get the | ||
4 | associated performance penalty that cache.no-flush=on was supposed to | ||
5 | avoid. | ||
6 | |||
7 | Clear FUA for write requests if BDRV_O_NO_FLUSH is set. | ||
3 | 8 | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
5 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | 10 | Message-ID: <20250307221634.71951-3-kwolf@redhat.com> |
6 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
7 | --- | 13 | --- |
8 | include/sysemu/blockdev.h | 1 - | 14 | block/io.c | 4 ++++ |
9 | blockdev.c | 17 +---------------- | 15 | 1 file changed, 4 insertions(+) |
10 | device-hotplug.c | 4 ---- | ||
11 | qemu-doc.texi | 5 ----- | ||
12 | qemu-options.hx | 5 +---- | ||
13 | 5 files changed, 2 insertions(+), 30 deletions(-) | ||
14 | 16 | ||
15 | diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h | 17 | diff --git a/block/io.c b/block/io.c |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/sysemu/blockdev.h | 19 | --- a/block/io.c |
18 | +++ b/include/sysemu/blockdev.h | 20 | +++ b/block/io.c |
19 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 21 | @@ -XXX,XX +XXX,XX @@ bdrv_driver_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, |
20 | } BlockInterfaceType; | 22 | return -ENOMEDIUM; |
21 | |||
22 | struct DriveInfo { | ||
23 | - const char *devaddr; | ||
24 | BlockInterfaceType type; | ||
25 | int bus; | ||
26 | int unit; | ||
27 | diff --git a/blockdev.c b/blockdev.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/blockdev.c | ||
30 | +++ b/blockdev.c | ||
31 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = { | ||
32 | .type = QEMU_OPT_STRING, | ||
33 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | ||
34 | },{ | ||
35 | - .name = "addr", | ||
36 | - .type = QEMU_OPT_STRING, | ||
37 | - .help = "pci address (virtio only)", | ||
38 | - },{ | ||
39 | .name = "serial", | ||
40 | .type = QEMU_OPT_STRING, | ||
41 | .help = "disk serial number", | ||
42 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
43 | DriveMediaType media = MEDIA_DISK; | ||
44 | BlockInterfaceType type; | ||
45 | int max_devs, bus_id, unit_id, index; | ||
46 | - const char *devaddr; | ||
47 | const char *werror, *rerror; | ||
48 | bool read_only = false; | ||
49 | bool copy_on_read; | ||
50 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
51 | Error *local_err = NULL; | ||
52 | int i; | ||
53 | const char *deprecated[] = { | ||
54 | - "serial", "addr" | ||
55 | + "serial" | ||
56 | }; | ||
57 | |||
58 | /* Change legacy command line options into QMP ones */ | ||
59 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
60 | } | 23 | } |
61 | 24 | ||
62 | /* Add virtio block device */ | 25 | + if (bs->open_flags & BDRV_O_NO_FLUSH) { |
63 | - devaddr = qemu_opt_get(legacy_opts, "addr"); | 26 | + flags &= ~BDRV_REQ_FUA; |
64 | - if (devaddr && type != IF_VIRTIO) { | 27 | + } |
65 | - error_report("addr is not supported by this bus type"); | 28 | + |
66 | - goto fail; | 29 | if ((flags & BDRV_REQ_FUA) && |
67 | - } | 30 | (~bs->supported_write_flags & BDRV_REQ_FUA)) { |
68 | - | 31 | flags &= ~BDRV_REQ_FUA; |
69 | if (type == IF_VIRTIO) { | ||
70 | QemuOpts *devopts; | ||
71 | devopts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, | ||
72 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
73 | } | ||
74 | qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id"), | ||
75 | &error_abort); | ||
76 | - if (devaddr) { | ||
77 | - qemu_opt_set(devopts, "addr", devaddr, &error_abort); | ||
78 | - } | ||
79 | } | ||
80 | |||
81 | filename = qemu_opt_get(legacy_opts, "file"); | ||
82 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
83 | dinfo->type = type; | ||
84 | dinfo->bus = bus_id; | ||
85 | dinfo->unit = unit_id; | ||
86 | - dinfo->devaddr = devaddr; | ||
87 | dinfo->serial = g_strdup(serial); | ||
88 | |||
89 | blk_set_legacy_dinfo(blk, dinfo); | ||
90 | diff --git a/device-hotplug.c b/device-hotplug.c | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/device-hotplug.c | ||
93 | +++ b/device-hotplug.c | ||
94 | @@ -XXX,XX +XXX,XX @@ void hmp_drive_add(Monitor *mon, const QDict *qdict) | ||
95 | if (!dinfo) { | ||
96 | goto err; | ||
97 | } | ||
98 | - if (dinfo->devaddr) { | ||
99 | - monitor_printf(mon, "Parameter addr not supported\n"); | ||
100 | - goto err; | ||
101 | - } | ||
102 | |||
103 | switch (dinfo->type) { | ||
104 | case IF_NONE: | ||
105 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/qemu-doc.texi | ||
108 | +++ b/qemu-doc.texi | ||
109 | @@ -XXX,XX +XXX,XX @@ provided per NIC. | ||
110 | The drive serial argument is replaced by the the serial argument | ||
111 | that can be specified with the ``-device'' parameter. | ||
112 | |||
113 | -@subsection -drive addr=... (since 2.10.0) | ||
114 | - | ||
115 | -The drive addr argument is replaced by the the addr argument | ||
116 | -that can be specified with the ``-device'' parameter. | ||
117 | - | ||
118 | @subsection -usbdevice (since 2.10.0) | ||
119 | |||
120 | The ``-usbdevice DEV'' argument is now a synonym for setting | ||
121 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
122 | index XXXXXXX..XXXXXXX 100644 | ||
123 | --- a/qemu-options.hx | ||
124 | +++ b/qemu-options.hx | ||
125 | @@ -XXX,XX +XXX,XX @@ ETEXI | ||
126 | DEF("drive", HAS_ARG, QEMU_OPTION_drive, | ||
127 | "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" | ||
128 | " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" | ||
129 | - " [,snapshot=on|off][,serial=s][,addr=A][,rerror=ignore|stop|report]\n" | ||
130 | + " [,snapshot=on|off][,serial=s][,rerror=ignore|stop|report]\n" | ||
131 | " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" | ||
132 | " [,readonly=on|off][,copy-on-read=on|off]\n" | ||
133 | " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" | ||
134 | @@ -XXX,XX +XXX,XX @@ an untrusted format header. | ||
135 | This option specifies the serial number to assign to the device. This | ||
136 | parameter is deprecated, use the corresponding parameter of @code{-device} | ||
137 | instead. | ||
138 | -@item addr=@var{addr} | ||
139 | -Specify the controller's PCI address (if=virtio only). This parameter is | ||
140 | -deprecated, use the corresponding parameter of @code{-device} instead. | ||
141 | @item werror=@var{action},rerror=@var{action} | ||
142 | Specify which @var{action} to take on write and read errors. Valid actions are: | ||
143 | "ignore" (ignore the error and try to continue), "stop" (pause QEMU), | ||
144 | -- | 32 | -- |
145 | 2.13.6 | 33 | 2.48.1 |
146 | |||
147 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | As a preparation for having multiple adaptive polling states per |
---|---|---|---|
2 | AioContext, move the 'ns' field into a separate struct. | ||
2 | 3 | ||
3 | Legacy -drive supports "password-secret" parameter that isn't | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
4 | available with -blockdev / blockdev-add. That's because we backed out | 5 | Message-ID: <20250307221634.71951-4-kwolf@redhat.com> |
5 | our first try to provide it there due to interface design doubts, in | 6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | commit 577d8c9a811, v2.9.0. | ||
7 | |||
8 | This is the second try. It brings back the parameter, except it's | ||
9 | named "key-secret" now. | ||
10 | |||
11 | Let's review our reasons for backing out the first try, as stated in | ||
12 | the commit message: | ||
13 | |||
14 | * BlockdevOptionsRbd member @password-secret isn't actually a | ||
15 | password, it's a key generated by Ceph. | ||
16 | |||
17 | Addressed by the rename. | ||
18 | |||
19 | * We're not sure where member @password-secret belongs (see the | ||
20 | previous commit). | ||
21 | |||
22 | See previous commit. | ||
23 | |||
24 | * How @password-secret interacts with settings from a configuration | ||
25 | file specified with @conf is undocumented. | ||
26 | |||
27 | Not actually true, the documentation for @conf says "Values in the | ||
28 | configuration file will be overridden by options specified via QAPI", | ||
29 | and we've tested this. | ||
30 | |||
31 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
32 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
33 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
34 | --- | 8 | --- |
35 | qapi/block-core.json | 6 ++++++ | 9 | include/block/aio.h | 6 +++++- |
36 | block/rbd.c | 41 +++++++++++++++++++++++++---------------- | 10 | util/aio-posix.c | 31 ++++++++++++++++--------------- |
37 | 2 files changed, 31 insertions(+), 16 deletions(-) | 11 | util/async.c | 3 ++- |
12 | 3 files changed, 23 insertions(+), 17 deletions(-) | ||
38 | 13 | ||
39 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 14 | diff --git a/include/block/aio.h b/include/block/aio.h |
40 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/qapi/block-core.json | 16 | --- a/include/block/aio.h |
42 | +++ b/qapi/block-core.json | 17 | +++ b/include/block/aio.h |
43 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ struct BHListSlice { |
44 | # This maps to Ceph configuration option | 19 | |
45 | # "auth_client_required". (Since 3.0) | 20 | typedef QSLIST_HEAD(, AioHandler) AioHandlerSList; |
46 | # | 21 | |
47 | +# @key-secret: ID of a QCryptoSecret object providing a key | 22 | +typedef struct AioPolledEvent { |
48 | +# for cephx authentication. | 23 | + int64_t ns; /* current polling time in nanoseconds */ |
49 | +# This maps to Ceph configuration option | 24 | +} AioPolledEvent; |
50 | +# "key". (Since 3.0) | 25 | + |
51 | +# | 26 | struct AioContext { |
52 | # @server: Monitor host address and port. This maps | 27 | GSource source; |
53 | # to the "mon_host" Ceph option. | 28 | |
54 | # | 29 | @@ -XXX,XX +XXX,XX @@ struct AioContext { |
55 | @@ -XXX,XX +XXX,XX @@ | 30 | int poll_disable_cnt; |
56 | '*snapshot': 'str', | 31 | |
57 | '*user': 'str', | 32 | /* Polling mode parameters */ |
58 | '*auth-client-required': ['RbdAuthMode'], | 33 | - int64_t poll_ns; /* current polling time in nanoseconds */ |
59 | + '*key-secret': 'str', | 34 | + AioPolledEvent poll; |
60 | '*server': ['InetSocketAddressBase'] } } | 35 | int64_t poll_max_ns; /* maximum polling time in nanoseconds */ |
61 | 36 | int64_t poll_grow; /* polling time growth factor */ | |
62 | ## | 37 | int64_t poll_shrink; /* polling time shrink factor */ |
63 | diff --git a/block/rbd.c b/block/rbd.c | 38 | diff --git a/util/aio-posix.c b/util/aio-posix.c |
64 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
65 | --- a/block/rbd.c | 40 | --- a/util/aio-posix.c |
66 | +++ b/block/rbd.c | 41 | +++ b/util/aio-posix.c |
67 | @@ -XXX,XX +XXX,XX @@ static void qemu_rbd_refresh_limits(BlockDriverState *bs, Error **errp) | 42 | @@ -XXX,XX +XXX,XX @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, |
68 | } | 43 | return false; |
69 | |||
70 | |||
71 | -static int qemu_rbd_set_auth(rados_t cluster, const char *secretid, | ||
72 | - BlockdevOptionsRbd *opts, | ||
73 | +static int qemu_rbd_set_auth(rados_t cluster, BlockdevOptionsRbd *opts, | ||
74 | Error **errp) | ||
75 | { | ||
76 | - char *acr; | ||
77 | + char *key, *acr; | ||
78 | int r; | ||
79 | GString *accu; | ||
80 | RbdAuthModeList *auth; | ||
81 | |||
82 | - if (secretid) { | ||
83 | - gchar *secret = qcrypto_secret_lookup_as_base64(secretid, | ||
84 | - errp); | ||
85 | - if (!secret) { | ||
86 | - return -1; | ||
87 | + if (opts->key_secret) { | ||
88 | + key = qcrypto_secret_lookup_as_base64(opts->key_secret, errp); | ||
89 | + if (!key) { | ||
90 | + return -EIO; | ||
91 | + } | ||
92 | + r = rados_conf_set(cluster, "key", key); | ||
93 | + g_free(key); | ||
94 | + if (r < 0) { | ||
95 | + error_setg_errno(errp, -r, "Could not set 'key'"); | ||
96 | + return r; | ||
97 | } | ||
98 | - | ||
99 | - rados_conf_set(cluster, "key", secret); | ||
100 | - g_free(secret); | ||
101 | } | 44 | } |
102 | 45 | ||
103 | if (opts->has_auth_client_required) { | 46 | - max_ns = qemu_soonest_timeout(*timeout, ctx->poll_ns); |
104 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = { | 47 | + max_ns = qemu_soonest_timeout(*timeout, ctx->poll.ns); |
105 | }, | 48 | if (max_ns && !ctx->fdmon_ops->need_wait(ctx)) { |
106 | }; | 49 | /* |
107 | 50 | * Enable poll mode. It pairs with the poll_set_started() in | |
108 | -/* FIXME Deprecate and remove keypairs or make it available in QMP. | 51 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) |
109 | - * password_secret should eventually be configurable in opts->location. Support | 52 | if (ctx->poll_max_ns) { |
110 | - * for it in .bdrv_open will make it work here as well. */ | 53 | int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start; |
111 | +/* FIXME Deprecate and remove keypairs or make it available in QMP. */ | 54 | |
112 | static int qemu_rbd_do_create(BlockdevCreateOptions *options, | 55 | - if (block_ns <= ctx->poll_ns) { |
113 | const char *keypairs, const char *password_secret, | 56 | + if (block_ns <= ctx->poll.ns) { |
114 | Error **errp) | 57 | /* This is the sweet spot, no adjustment needed */ |
115 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, | 58 | } else if (block_ns > ctx->poll_max_ns) { |
116 | Error *local_err = NULL; | 59 | /* We'd have to poll for too long, poll less */ |
117 | int r; | 60 | - int64_t old = ctx->poll_ns; |
118 | 61 | + int64_t old = ctx->poll.ns; | |
119 | + if (secretid) { | 62 | |
120 | + if (opts->key_secret) { | 63 | if (ctx->poll_shrink) { |
121 | + error_setg(errp, | 64 | - ctx->poll_ns /= ctx->poll_shrink; |
122 | + "Legacy 'password-secret' clashes with 'key-secret'"); | 65 | + ctx->poll.ns /= ctx->poll_shrink; |
123 | + return -EINVAL; | 66 | } else { |
124 | + } | 67 | - ctx->poll_ns = 0; |
125 | + opts->key_secret = g_strdup(secretid); | 68 | + ctx->poll.ns = 0; |
126 | + opts->has_key_secret = true; | 69 | } |
127 | + } | 70 | |
128 | + | 71 | - trace_poll_shrink(ctx, old, ctx->poll_ns); |
129 | mon_host = qemu_rbd_mon_host(opts, &local_err); | 72 | - } else if (ctx->poll_ns < ctx->poll_max_ns && |
130 | if (local_err) { | 73 | + trace_poll_shrink(ctx, old, ctx->poll.ns); |
131 | error_propagate(errp, local_err); | 74 | + } else if (ctx->poll.ns < ctx->poll_max_ns && |
132 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, | 75 | block_ns < ctx->poll_max_ns) { |
76 | /* There is room to grow, poll longer */ | ||
77 | - int64_t old = ctx->poll_ns; | ||
78 | + int64_t old = ctx->poll.ns; | ||
79 | int64_t grow = ctx->poll_grow; | ||
80 | |||
81 | if (grow == 0) { | ||
82 | grow = 2; | ||
83 | } | ||
84 | |||
85 | - if (ctx->poll_ns) { | ||
86 | - ctx->poll_ns *= grow; | ||
87 | + if (ctx->poll.ns) { | ||
88 | + ctx->poll.ns *= grow; | ||
89 | } else { | ||
90 | - ctx->poll_ns = 4000; /* start polling at 4 microseconds */ | ||
91 | + ctx->poll.ns = 4000; /* start polling at 4 microseconds */ | ||
92 | } | ||
93 | |||
94 | - if (ctx->poll_ns > ctx->poll_max_ns) { | ||
95 | - ctx->poll_ns = ctx->poll_max_ns; | ||
96 | + if (ctx->poll.ns > ctx->poll_max_ns) { | ||
97 | + ctx->poll.ns = ctx->poll_max_ns; | ||
98 | } | ||
99 | |||
100 | - trace_poll_grow(ctx, old, ctx->poll_ns); | ||
101 | + trace_poll_grow(ctx, old, ctx->poll.ns); | ||
133 | } | 102 | } |
134 | } | 103 | } |
135 | 104 | ||
136 | - if (qemu_rbd_set_auth(*cluster, secretid, opts, errp) < 0) { | 105 | @@ -XXX,XX +XXX,XX @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, |
137 | - r = -EIO; | 106 | /* No thread synchronization here, it doesn't matter if an incorrect value |
138 | + r = qemu_rbd_set_auth(*cluster, opts, errp); | 107 | * is used once. |
139 | + if (r < 0) { | 108 | */ |
140 | goto failed_shutdown; | 109 | + ctx->poll.ns = 0; |
141 | } | 110 | + |
142 | 111 | ctx->poll_max_ns = max_ns; | |
112 | - ctx->poll_ns = 0; | ||
113 | ctx->poll_grow = grow; | ||
114 | ctx->poll_shrink = shrink; | ||
115 | |||
116 | diff --git a/util/async.c b/util/async.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/util/async.c | ||
119 | +++ b/util/async.c | ||
120 | @@ -XXX,XX +XXX,XX @@ AioContext *aio_context_new(Error **errp) | ||
121 | qemu_rec_mutex_init(&ctx->lock); | ||
122 | timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx); | ||
123 | |||
124 | - ctx->poll_ns = 0; | ||
125 | + ctx->poll.ns = 0; | ||
126 | + | ||
127 | ctx->poll_max_ns = 0; | ||
128 | ctx->poll_grow = 0; | ||
129 | ctx->poll_shrink = 0; | ||
143 | -- | 130 | -- |
144 | 2.13.6 | 131 | 2.48.1 |
145 | |||
146 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
---|---|---|---|
2 | 2 | Message-ID: <20250307221634.71951-5-kwolf@redhat.com> | |
3 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 3 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | --- | 5 | --- |
7 | qobject/block-qdict.c | 27 +++++++++++---------------- | 6 | util/aio-posix.c | 77 ++++++++++++++++++++++++++---------------------- |
8 | 1 file changed, 11 insertions(+), 16 deletions(-) | 7 | 1 file changed, 41 insertions(+), 36 deletions(-) |
9 | 8 | ||
10 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 9 | diff --git a/util/aio-posix.c b/util/aio-posix.c |
11 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/qobject/block-qdict.c | 11 | --- a/util/aio-posix.c |
13 | +++ b/qobject/block-qdict.c | 12 | +++ b/util/aio-posix.c |
14 | @@ -XXX,XX +XXX,XX @@ static int qdict_is_list(QDict *maybe_list, Error **errp) | 13 | @@ -XXX,XX +XXX,XX @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, |
15 | 14 | return false; | |
16 | for (ent = qdict_first(maybe_list); ent != NULL; | 15 | } |
17 | ent = qdict_next(maybe_list, ent)) { | 16 | |
18 | + int is_index = !qemu_strtoi64(ent->key, NULL, 10, &val); | 17 | +static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll, |
19 | 18 | + int64_t block_ns) | |
20 | - if (qemu_strtoi64(ent->key, NULL, 10, &val) == 0) { | 19 | +{ |
21 | - if (is_list == -1) { | 20 | + if (block_ns <= poll->ns) { |
22 | - is_list = 1; | 21 | + /* This is the sweet spot, no adjustment needed */ |
23 | - } else if (!is_list) { | 22 | + } else if (block_ns > ctx->poll_max_ns) { |
24 | - error_setg(errp, | 23 | + /* We'd have to poll for too long, poll less */ |
25 | - "Cannot mix list and non-list keys"); | 24 | + int64_t old = poll->ns; |
26 | - return -1; | 25 | + |
27 | - } | 26 | + if (ctx->poll_shrink) { |
28 | + if (is_list == -1) { | 27 | + poll->ns /= ctx->poll_shrink; |
29 | + is_list = is_index; | 28 | + } else { |
29 | + poll->ns = 0; | ||
30 | + } | 30 | + } |
31 | + | 31 | + |
32 | + if (is_index != is_list) { | 32 | + trace_poll_shrink(ctx, old, poll->ns); |
33 | + error_setg(errp, "Cannot mix list and non-list keys"); | 33 | + } else if (poll->ns < ctx->poll_max_ns && |
34 | + return -1; | 34 | + block_ns < ctx->poll_max_ns) { |
35 | + /* There is room to grow, poll longer */ | ||
36 | + int64_t old = poll->ns; | ||
37 | + int64_t grow = ctx->poll_grow; | ||
38 | + | ||
39 | + if (grow == 0) { | ||
40 | + grow = 2; | ||
35 | + } | 41 | + } |
36 | + | 42 | + |
37 | + if (is_index) { | 43 | + if (poll->ns) { |
38 | len++; | 44 | + poll->ns *= grow; |
39 | if (val > max) { | 45 | + } else { |
40 | max = val; | 46 | + poll->ns = 4000; /* start polling at 4 microseconds */ |
41 | } | 47 | + } |
42 | - } else { | 48 | + |
43 | - if (is_list == -1) { | 49 | + if (poll->ns > ctx->poll_max_ns) { |
44 | - is_list = 0; | 50 | + poll->ns = ctx->poll_max_ns; |
45 | - } else if (is_list) { | 51 | + } |
46 | - error_setg(errp, | 52 | + |
47 | - "Cannot mix list and non-list keys"); | 53 | + trace_poll_grow(ctx, old, poll->ns); |
48 | - return -1; | 54 | + } |
55 | +} | ||
56 | + | ||
57 | bool aio_poll(AioContext *ctx, bool blocking) | ||
58 | { | ||
59 | AioHandlerList ready_list = QLIST_HEAD_INITIALIZER(ready_list); | ||
60 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | ||
61 | /* Adjust polling time */ | ||
62 | if (ctx->poll_max_ns) { | ||
63 | int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start; | ||
64 | - | ||
65 | - if (block_ns <= ctx->poll.ns) { | ||
66 | - /* This is the sweet spot, no adjustment needed */ | ||
67 | - } else if (block_ns > ctx->poll_max_ns) { | ||
68 | - /* We'd have to poll for too long, poll less */ | ||
69 | - int64_t old = ctx->poll.ns; | ||
70 | - | ||
71 | - if (ctx->poll_shrink) { | ||
72 | - ctx->poll.ns /= ctx->poll_shrink; | ||
73 | - } else { | ||
74 | - ctx->poll.ns = 0; | ||
49 | - } | 75 | - } |
50 | } | 76 | - |
77 | - trace_poll_shrink(ctx, old, ctx->poll.ns); | ||
78 | - } else if (ctx->poll.ns < ctx->poll_max_ns && | ||
79 | - block_ns < ctx->poll_max_ns) { | ||
80 | - /* There is room to grow, poll longer */ | ||
81 | - int64_t old = ctx->poll.ns; | ||
82 | - int64_t grow = ctx->poll_grow; | ||
83 | - | ||
84 | - if (grow == 0) { | ||
85 | - grow = 2; | ||
86 | - } | ||
87 | - | ||
88 | - if (ctx->poll.ns) { | ||
89 | - ctx->poll.ns *= grow; | ||
90 | - } else { | ||
91 | - ctx->poll.ns = 4000; /* start polling at 4 microseconds */ | ||
92 | - } | ||
93 | - | ||
94 | - if (ctx->poll.ns > ctx->poll_max_ns) { | ||
95 | - ctx->poll.ns = ctx->poll_max_ns; | ||
96 | - } | ||
97 | - | ||
98 | - trace_poll_grow(ctx, old, ctx->poll.ns); | ||
99 | - } | ||
100 | + adjust_polling_time(ctx, &ctx->poll, block_ns); | ||
51 | } | 101 | } |
52 | 102 | ||
103 | progress |= aio_bh_poll(ctx); | ||
53 | -- | 104 | -- |
54 | 2.13.6 | 105 | 2.48.1 |
55 | |||
56 | diff view generated by jsdifflib |
1 | The -drive options cyls, heads, secs and trans were deprecated in | 1 | Adaptive polling has a big problem: It doesn't consider that an event |
---|---|---|---|
2 | QEMU 2.10. It's time to remove them. | 2 | loop can wait for many different events that may have very different |
3 | typical latencies. | ||
3 | 4 | ||
4 | hd-geo-test tested both the old version with geometry options in -drive | 5 | For example, think of a guest that tends to send a new I/O request soon |
5 | and the new one with -device. Therefore the code using -drive doesn't | 6 | after the previous I/O request completes, but the storage on the host is |
6 | have to be replaced there, we just need to remove the -drive test cases. | 7 | rather slow. In this case, getting the new request from guest quickly |
7 | This in turn allows some simplification of the code. | 8 | means that polling is enabled, but the next thing is performing the I/O |
9 | request on the backend, which is slow and disables polling again for the | ||
10 | next guest request. This means that in such a scenario, polling could | ||
11 | help for every other event, but is only ever enabled when it can't | ||
12 | succeed. | ||
13 | |||
14 | In order to fix this, keep a separate AioPolledEvent for each | ||
15 | AioHandler. We will then know that the backend file descriptor always | ||
16 | has a high latency and isn't worth polling for, but we also know that | ||
17 | the guest is always fast and we should poll for it. This solves at least | ||
18 | half of the problem, we can now keep polling for those cases where it | ||
19 | makes sense and get the improved performance from it. | ||
20 | |||
21 | Since the event loop doesn't know which event will be next, we still do | ||
22 | some unnecessary polling while we're waiting for the slow disk. I made | ||
23 | some attempts to be more clever than just randomly growing and shrinking | ||
24 | the polling time, and even to let callers be explicit about when they | ||
25 | expect a new event, but so far this hasn't resulted in improved | ||
26 | performance or even caused performance regressions. For now, let's just | ||
27 | fix the part that is easy enough to fix, we can revisit the rest later. | ||
8 | 28 | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 29 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | 30 | Message-ID: <20250307221634.71951-6-kwolf@redhat.com> |
31 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
32 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | 33 | --- |
12 | include/sysemu/blockdev.h | 1 - | 34 | include/block/aio.h | 1 - |
13 | blockdev.c | 75 +---------------------------------------------- | 35 | util/aio-posix.h | 1 + |
14 | hw/block/block.c | 14 --------- | 36 | util/aio-posix.c | 26 ++++++++++++++++++++++---- |
15 | tests/hd-geo-test.c | 37 +++++------------------ | 37 | util/async.c | 2 -- |
16 | hmp-commands.hx | 1 - | 38 | 4 files changed, 23 insertions(+), 7 deletions(-) |
17 | qemu-doc.texi | 5 ---- | ||
18 | qemu-options.hx | 7 +---- | ||
19 | 7 files changed, 9 insertions(+), 131 deletions(-) | ||
20 | 39 | ||
21 | diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h | 40 | diff --git a/include/block/aio.h b/include/block/aio.h |
22 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/sysemu/blockdev.h | 42 | --- a/include/block/aio.h |
24 | +++ b/include/sysemu/blockdev.h | 43 | +++ b/include/block/aio.h |
25 | @@ -XXX,XX +XXX,XX @@ struct DriveInfo { | 44 | @@ -XXX,XX +XXX,XX @@ struct AioContext { |
26 | int auto_del; /* see blockdev_mark_auto_del() */ | 45 | int poll_disable_cnt; |
27 | bool is_default; /* Added by default_drive() ? */ | 46 | |
28 | int media_cd; | 47 | /* Polling mode parameters */ |
29 | - int cyls, heads, secs, trans; | 48 | - AioPolledEvent poll; |
30 | QemuOpts *opts; | 49 | int64_t poll_max_ns; /* maximum polling time in nanoseconds */ |
31 | char *serial; | 50 | int64_t poll_grow; /* polling time growth factor */ |
32 | QTAILQ_ENTRY(DriveInfo) next; | 51 | int64_t poll_shrink; /* polling time shrink factor */ |
33 | diff --git a/blockdev.c b/blockdev.c | 52 | diff --git a/util/aio-posix.h b/util/aio-posix.h |
34 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/blockdev.c | 54 | --- a/util/aio-posix.h |
36 | +++ b/blockdev.c | 55 | +++ b/util/aio-posix.h |
37 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = { | 56 | @@ -XXX,XX +XXX,XX @@ struct AioHandler { |
38 | .type = QEMU_OPT_STRING, | 57 | #endif |
39 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | 58 | int64_t poll_idle_timeout; /* when to stop userspace polling */ |
40 | },{ | 59 | bool poll_ready; /* has polling detected an event? */ |
41 | - .name = "cyls", | 60 | + AioPolledEvent poll; |
42 | - .type = QEMU_OPT_NUMBER, | 61 | }; |
43 | - .help = "number of cylinders (ide disk geometry)", | 62 | |
44 | - },{ | 63 | /* Add a handler to a ready list */ |
45 | - .name = "heads", | 64 | diff --git a/util/aio-posix.c b/util/aio-posix.c |
46 | - .type = QEMU_OPT_NUMBER, | 65 | index XXXXXXX..XXXXXXX 100644 |
47 | - .help = "number of heads (ide disk geometry)", | 66 | --- a/util/aio-posix.c |
48 | - },{ | 67 | +++ b/util/aio-posix.c |
49 | - .name = "secs", | 68 | @@ -XXX,XX +XXX,XX @@ static bool run_poll_handlers(AioContext *ctx, AioHandlerList *ready_list, |
50 | - .type = QEMU_OPT_NUMBER, | 69 | static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, |
51 | - .help = "number of sectors (ide disk geometry)", | 70 | int64_t *timeout) |
52 | - },{ | 71 | { |
53 | - .name = "trans", | 72 | + AioHandler *node; |
54 | - .type = QEMU_OPT_STRING, | 73 | int64_t max_ns; |
55 | - .help = "chs translation (auto, lba, none)", | 74 | |
56 | - },{ | 75 | if (QLIST_EMPTY_RCU(&ctx->poll_aio_handlers)) { |
57 | .name = "addr", | 76 | return false; |
58 | .type = QEMU_OPT_STRING, | ||
59 | .help = "pci address (virtio only)", | ||
60 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
61 | QemuOpts *legacy_opts; | ||
62 | DriveMediaType media = MEDIA_DISK; | ||
63 | BlockInterfaceType type; | ||
64 | - int cyls, heads, secs, translation; | ||
65 | int max_devs, bus_id, unit_id, index; | ||
66 | const char *devaddr; | ||
67 | const char *werror, *rerror; | ||
68 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
69 | Error *local_err = NULL; | ||
70 | int i; | ||
71 | const char *deprecated[] = { | ||
72 | - "serial", "trans", "secs", "heads", "cyls", "addr" | ||
73 | + "serial", "addr" | ||
74 | }; | ||
75 | |||
76 | /* Change legacy command line options into QMP ones */ | ||
77 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
78 | type = block_default_type; | ||
79 | } | 77 | } |
80 | 78 | ||
81 | - /* Geometry */ | 79 | - max_ns = qemu_soonest_timeout(*timeout, ctx->poll.ns); |
82 | - cyls = qemu_opt_get_number(legacy_opts, "cyls", 0); | 80 | + max_ns = 0; |
83 | - heads = qemu_opt_get_number(legacy_opts, "heads", 0); | 81 | + QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { |
84 | - secs = qemu_opt_get_number(legacy_opts, "secs", 0); | 82 | + max_ns = MAX(max_ns, node->poll.ns); |
83 | + } | ||
84 | + max_ns = qemu_soonest_timeout(*timeout, max_ns); | ||
85 | + | ||
86 | if (max_ns && !ctx->fdmon_ops->need_wait(ctx)) { | ||
87 | /* | ||
88 | * Enable poll mode. It pairs with the poll_set_started() in | ||
89 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) | ||
90 | |||
91 | /* Adjust polling time */ | ||
92 | if (ctx->poll_max_ns) { | ||
93 | + AioHandler *node; | ||
94 | int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start; | ||
95 | - adjust_polling_time(ctx, &ctx->poll, block_ns); | ||
96 | + | ||
97 | + QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { | ||
98 | + if (QLIST_IS_INSERTED(node, node_ready)) { | ||
99 | + adjust_polling_time(ctx, &node->poll, block_ns); | ||
100 | + } | ||
101 | + } | ||
102 | } | ||
103 | |||
104 | progress |= aio_bh_poll(ctx); | ||
105 | @@ -XXX,XX +XXX,XX @@ void aio_context_use_g_source(AioContext *ctx) | ||
106 | void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, | ||
107 | int64_t grow, int64_t shrink, Error **errp) | ||
108 | { | ||
109 | + AioHandler *node; | ||
110 | + | ||
111 | + qemu_lockcnt_inc(&ctx->list_lock); | ||
112 | + QLIST_FOREACH(node, &ctx->aio_handlers, node) { | ||
113 | + node->poll.ns = 0; | ||
114 | + } | ||
115 | + qemu_lockcnt_dec(&ctx->list_lock); | ||
116 | + | ||
117 | /* No thread synchronization here, it doesn't matter if an incorrect value | ||
118 | * is used once. | ||
119 | */ | ||
120 | - ctx->poll.ns = 0; | ||
85 | - | 121 | - |
86 | - if (cyls || heads || secs) { | 122 | ctx->poll_max_ns = max_ns; |
87 | - if (cyls < 1) { | 123 | ctx->poll_grow = grow; |
88 | - error_report("invalid physical cyls number"); | 124 | ctx->poll_shrink = shrink; |
89 | - goto fail; | 125 | diff --git a/util/async.c b/util/async.c |
90 | - } | 126 | index XXXXXXX..XXXXXXX 100644 |
91 | - if (heads < 1) { | 127 | --- a/util/async.c |
92 | - error_report("invalid physical heads number"); | 128 | +++ b/util/async.c |
93 | - goto fail; | 129 | @@ -XXX,XX +XXX,XX @@ AioContext *aio_context_new(Error **errp) |
94 | - } | 130 | qemu_rec_mutex_init(&ctx->lock); |
95 | - if (secs < 1) { | 131 | timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx); |
96 | - error_report("invalid physical secs number"); | 132 | |
97 | - goto fail; | 133 | - ctx->poll.ns = 0; |
98 | - } | ||
99 | - } | ||
100 | - | 134 | - |
101 | - translation = BIOS_ATA_TRANSLATION_AUTO; | 135 | ctx->poll_max_ns = 0; |
102 | - value = qemu_opt_get(legacy_opts, "trans"); | 136 | ctx->poll_grow = 0; |
103 | - if (value != NULL) { | 137 | ctx->poll_shrink = 0; |
104 | - if (!cyls) { | ||
105 | - error_report("'%s' trans must be used with cyls, heads and secs", | ||
106 | - value); | ||
107 | - goto fail; | ||
108 | - } | ||
109 | - if (!strcmp(value, "none")) { | ||
110 | - translation = BIOS_ATA_TRANSLATION_NONE; | ||
111 | - } else if (!strcmp(value, "lba")) { | ||
112 | - translation = BIOS_ATA_TRANSLATION_LBA; | ||
113 | - } else if (!strcmp(value, "large")) { | ||
114 | - translation = BIOS_ATA_TRANSLATION_LARGE; | ||
115 | - } else if (!strcmp(value, "rechs")) { | ||
116 | - translation = BIOS_ATA_TRANSLATION_RECHS; | ||
117 | - } else if (!strcmp(value, "auto")) { | ||
118 | - translation = BIOS_ATA_TRANSLATION_AUTO; | ||
119 | - } else { | ||
120 | - error_report("'%s' invalid translation type", value); | ||
121 | - goto fail; | ||
122 | - } | ||
123 | - } | ||
124 | - | ||
125 | - if (media == MEDIA_CDROM) { | ||
126 | - if (cyls || secs || heads) { | ||
127 | - error_report("CHS can't be set with media=cdrom"); | ||
128 | - goto fail; | ||
129 | - } | ||
130 | - } | ||
131 | - | ||
132 | /* Device address specified by bus/unit or index. | ||
133 | * If none was specified, try to find the first free one. */ | ||
134 | bus_id = qemu_opt_get_number(legacy_opts, "bus", 0); | ||
135 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
136 | dinfo = g_malloc0(sizeof(*dinfo)); | ||
137 | dinfo->opts = all_opts; | ||
138 | |||
139 | - dinfo->cyls = cyls; | ||
140 | - dinfo->heads = heads; | ||
141 | - dinfo->secs = secs; | ||
142 | - dinfo->trans = translation; | ||
143 | - | ||
144 | dinfo->type = type; | ||
145 | dinfo->bus = bus_id; | ||
146 | dinfo->unit = unit_id; | ||
147 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
148 | index XXXXXXX..XXXXXXX 100644 | ||
149 | --- a/hw/block/block.c | ||
150 | +++ b/hw/block/block.c | ||
151 | @@ -XXX,XX +XXX,XX @@ bool blkconf_geometry(BlockConf *conf, int *ptrans, | ||
152 | unsigned cyls_max, unsigned heads_max, unsigned secs_max, | ||
153 | Error **errp) | ||
154 | { | ||
155 | - DriveInfo *dinfo; | ||
156 | - | ||
157 | - if (!conf->cyls && !conf->heads && !conf->secs) { | ||
158 | - /* try to fall back to value set with legacy -drive cyls=... */ | ||
159 | - dinfo = blk_legacy_dinfo(conf->blk); | ||
160 | - if (dinfo) { | ||
161 | - conf->cyls = dinfo->cyls; | ||
162 | - conf->heads = dinfo->heads; | ||
163 | - conf->secs = dinfo->secs; | ||
164 | - if (ptrans) { | ||
165 | - *ptrans = dinfo->trans; | ||
166 | - } | ||
167 | - } | ||
168 | - } | ||
169 | if (!conf->cyls && !conf->heads && !conf->secs) { | ||
170 | hd_geometry_guess(conf->blk, | ||
171 | &conf->cyls, &conf->heads, &conf->secs, | ||
172 | diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c | ||
173 | index XXXXXXX..XXXXXXX 100644 | ||
174 | --- a/tests/hd-geo-test.c | ||
175 | +++ b/tests/hd-geo-test.c | ||
176 | @@ -XXX,XX +XXX,XX @@ static void setup_mbr(int img_idx, MBRcontents mbr) | ||
177 | |||
178 | static int setup_ide(int argc, char *argv[], int argv_sz, | ||
179 | int ide_idx, const char *dev, int img_idx, | ||
180 | - MBRcontents mbr, const char *opts) | ||
181 | + MBRcontents mbr) | ||
182 | { | ||
183 | char *s1, *s2, *s3; | ||
184 | |||
185 | @@ -XXX,XX +XXX,XX @@ static int setup_ide(int argc, char *argv[], int argv_sz, | ||
186 | s3 = g_strdup(",media=cdrom"); | ||
187 | } | ||
188 | argc = append_arg(argc, argv, argv_sz, | ||
189 | - g_strdup_printf("%s%s%s%s", s1, s2, s3, opts)); | ||
190 | + g_strdup_printf("%s%s%s", s1, s2, s3)); | ||
191 | g_free(s1); | ||
192 | g_free(s2); | ||
193 | g_free(s3); | ||
194 | @@ -XXX,XX +XXX,XX @@ static void test_ide_mbr(bool use_device, MBRcontents mbr) | ||
195 | for (i = 0; i < backend_last; i++) { | ||
196 | cur_ide[i] = &hd_chst[i][mbr]; | ||
197 | dev = use_device ? (is_hd(cur_ide[i]) ? "ide-hd" : "ide-cd") : NULL; | ||
198 | - argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr, ""); | ||
199 | + argc = setup_ide(argc, argv, ARGV_SIZE, i, dev, i, mbr); | ||
200 | } | ||
201 | args = g_strjoinv(" ", argv); | ||
202 | qtest_start(args); | ||
203 | @@ -XXX,XX +XXX,XX @@ static void test_ide_drive_user(const char *dev, bool trans) | ||
204 | const CHST expected_chst = { secs / (4 * 32) , 4, 32, trans }; | ||
205 | |||
206 | argc = setup_common(argv, ARGV_SIZE); | ||
207 | - opts = g_strdup_printf("%s,%s%scyls=%d,heads=%d,secs=%d", | ||
208 | - dev ?: "", | ||
209 | - trans && dev ? "bios-chs-" : "", | ||
210 | - trans ? "trans=lba," : "", | ||
211 | + opts = g_strdup_printf("%s,%scyls=%d,heads=%d,secs=%d", | ||
212 | + dev, trans ? "bios-chs-trans=lba," : "", | ||
213 | expected_chst.cyls, expected_chst.heads, | ||
214 | expected_chst.secs); | ||
215 | cur_ide[0] = &expected_chst; | ||
216 | - argc = setup_ide(argc, argv, ARGV_SIZE, | ||
217 | - 0, dev ? opts : NULL, backend_small, mbr_chs, | ||
218 | - dev ? "" : opts); | ||
219 | + argc = setup_ide(argc, argv, ARGV_SIZE, 0, opts, backend_small, mbr_chs); | ||
220 | g_free(opts); | ||
221 | args = g_strjoinv(" ", argv); | ||
222 | qtest_start(args); | ||
223 | @@ -XXX,XX +XXX,XX @@ static void test_ide_drive_user(const char *dev, bool trans) | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | - * Test case: IDE device (if=ide) with explicit CHS | ||
228 | - */ | ||
229 | -static void test_ide_drive_user_chs(void) | ||
230 | -{ | ||
231 | - test_ide_drive_user(NULL, false); | ||
232 | -} | ||
233 | - | ||
234 | -/* | ||
235 | - * Test case: IDE device (if=ide) with explicit CHS and translation | ||
236 | - */ | ||
237 | -static void test_ide_drive_user_chst(void) | ||
238 | -{ | ||
239 | - test_ide_drive_user(NULL, true); | ||
240 | -} | ||
241 | - | ||
242 | -/* | ||
243 | * Test case: IDE device (if=none) with explicit CHS | ||
244 | */ | ||
245 | static void test_ide_device_user_chs(void) | ||
246 | @@ -XXX,XX +XXX,XX @@ static void test_ide_drive_cd_0(void) | ||
247 | for (i = 0; i <= backend_empty; i++) { | ||
248 | ide_idx = backend_empty - i; | ||
249 | cur_ide[ide_idx] = &hd_chst[i][mbr_blank]; | ||
250 | - argc = setup_ide(argc, argv, ARGV_SIZE, | ||
251 | - ide_idx, NULL, i, mbr_blank, ""); | ||
252 | + argc = setup_ide(argc, argv, ARGV_SIZE, ide_idx, NULL, i, mbr_blank); | ||
253 | } | ||
254 | args = g_strjoinv(" ", argv); | ||
255 | qtest_start(args); | ||
256 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
257 | qtest_add_func("hd-geo/ide/drive/mbr/blank", test_ide_drive_mbr_blank); | ||
258 | qtest_add_func("hd-geo/ide/drive/mbr/lba", test_ide_drive_mbr_lba); | ||
259 | qtest_add_func("hd-geo/ide/drive/mbr/chs", test_ide_drive_mbr_chs); | ||
260 | - qtest_add_func("hd-geo/ide/drive/user/chs", test_ide_drive_user_chs); | ||
261 | - qtest_add_func("hd-geo/ide/drive/user/chst", test_ide_drive_user_chst); | ||
262 | qtest_add_func("hd-geo/ide/drive/cd_0", test_ide_drive_cd_0); | ||
263 | qtest_add_func("hd-geo/ide/device/mbr/blank", test_ide_device_mbr_blank); | ||
264 | qtest_add_func("hd-geo/ide/device/mbr/lba", test_ide_device_mbr_lba); | ||
265 | diff --git a/hmp-commands.hx b/hmp-commands.hx | ||
266 | index XXXXXXX..XXXXXXX 100644 | ||
267 | --- a/hmp-commands.hx | ||
268 | +++ b/hmp-commands.hx | ||
269 | @@ -XXX,XX +XXX,XX @@ ETEXI | ||
270 | .params = "[-n] [[<domain>:]<bus>:]<slot>\n" | ||
271 | "[file=file][,if=type][,bus=n]\n" | ||
272 | "[,unit=m][,media=d][,index=i]\n" | ||
273 | - "[,cyls=c,heads=h,secs=s[,trans=t]]\n" | ||
274 | "[,snapshot=on|off][,cache=on|off]\n" | ||
275 | "[,readonly=on|off][,copy-on-read=on|off]", | ||
276 | .help = "add drive to PCI storage controller", | ||
277 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
278 | index XXXXXXX..XXXXXXX 100644 | ||
279 | --- a/qemu-doc.texi | ||
280 | +++ b/qemu-doc.texi | ||
281 | @@ -XXX,XX +XXX,XX @@ with ``-device ...,netdev=x''), or ``-nic user,smb=/some/dir'' | ||
282 | (for embedded NICs). The new syntax allows different settings to be | ||
283 | provided per NIC. | ||
284 | |||
285 | -@subsection -drive cyls=...,heads=...,secs=...,trans=... (since 2.10.0) | ||
286 | - | ||
287 | -The drive geometry arguments are replaced by the the geometry arguments | ||
288 | -that can be specified with the ``-device'' parameter. | ||
289 | - | ||
290 | @subsection -drive serial=... (since 2.10.0) | ||
291 | |||
292 | The drive serial argument is replaced by the the serial argument | ||
293 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
294 | index XXXXXXX..XXXXXXX 100644 | ||
295 | --- a/qemu-options.hx | ||
296 | +++ b/qemu-options.hx | ||
297 | @@ -XXX,XX +XXX,XX @@ ETEXI | ||
298 | |||
299 | DEF("drive", HAS_ARG, QEMU_OPTION_drive, | ||
300 | "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" | ||
301 | - " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" | ||
302 | " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" | ||
303 | - " [,serial=s][,addr=A][,rerror=ignore|stop|report]\n" | ||
304 | + " [,snapshot=on|off][,serial=s][,addr=A][,rerror=ignore|stop|report]\n" | ||
305 | " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" | ||
306 | " [,readonly=on|off][,copy-on-read=on|off]\n" | ||
307 | " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" | ||
308 | @@ -XXX,XX +XXX,XX @@ This option defines where is connected the drive by using an index in the list | ||
309 | of available connectors of a given interface type. | ||
310 | @item media=@var{media} | ||
311 | This option defines the type of the media: disk or cdrom. | ||
312 | -@item cyls=@var{c},heads=@var{h},secs=@var{s}[,trans=@var{t}] | ||
313 | -Force disk physical geometry and the optional BIOS translation (trans=none or | ||
314 | -lba). These parameters are deprecated, use the corresponding parameters | ||
315 | -of @code{-device} instead. | ||
316 | @item snapshot=@var{snapshot} | ||
317 | @var{snapshot} is "on" or "off" and controls snapshot mode for the given drive | ||
318 | (see @option{-snapshot}). | ||
319 | -- | 138 | -- |
320 | 2.13.6 | 139 | 2.48.1 |
321 | |||
322 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | aio_dispatch_handler() adds handlers to ctx->poll_aio_handlers if |
---|---|---|---|
2 | polling should be enabled. If we call adjust_polling_time() for all | ||
3 | polling handlers before this, new polling handlers are still left at | ||
4 | poll->ns = 0 and polling is only actually enabled after the next event. | ||
5 | Move the adjust_polling_time() call after aio_dispatch_handler(). | ||
2 | 6 | ||
3 | The following pattern occurs in the .bdrv_co_create_opts() methods of | 7 | This fixes test-nested-aio-poll, which expects that polling becomes |
4 | parallels, qcow, qcow2, qed, vhdx and vpc: | 8 | effective the first time around. |
5 | 9 | ||
6 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | qobject_unref(qdict); | 11 | Message-ID: <20250311141912.135657-1-kwolf@redhat.com> |
8 | qdict = qobject_to(QDict, qobj); | ||
9 | if (qdict == NULL) { | ||
10 | ret = -EINVAL; | ||
11 | goto done; | ||
12 | } | ||
13 | |||
14 | v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | ||
15 | [...] | ||
16 | ret = 0; | ||
17 | done: | ||
18 | qobject_unref(qdict); | ||
19 | [...] | ||
20 | return ret; | ||
21 | |||
22 | If qobject_to() fails, we return failure without setting errp. That's | ||
23 | wrong. As far as I can tell, it cannot fail here. Clean it up | ||
24 | anyway, by removing the useless conversion. | ||
25 | |||
26 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
27 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
28 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
29 | --- | 13 | --- |
30 | block/parallels.c | 9 ++++----- | 14 | util/aio-posix.c | 28 +++++++++++++++++----------- |
31 | block/qcow.c | 9 ++++----- | 15 | 1 file changed, 17 insertions(+), 11 deletions(-) |
32 | block/qcow2.c | 9 ++++----- | ||
33 | block/qed.c | 9 ++++----- | ||
34 | block/vhdx.c | 9 ++++----- | ||
35 | block/vpc.c | 9 ++++----- | ||
36 | 6 files changed, 24 insertions(+), 30 deletions(-) | ||
37 | 16 | ||
38 | diff --git a/block/parallels.c b/block/parallels.c | 17 | diff --git a/util/aio-posix.c b/util/aio-posix.c |
39 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/block/parallels.c | 19 | --- a/util/aio-posix.c |
41 | +++ b/block/parallels.c | 20 | +++ b/util/aio-posix.c |
42 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create_opts(const char *filename, | 21 | @@ -XXX,XX +XXX,XX @@ |
43 | BlockdevCreateOptions *create_options = NULL; | 22 | /* Stop userspace polling on a handler if it isn't active for some time */ |
44 | Error *local_err = NULL; | 23 | #define POLL_IDLE_INTERVAL_NS (7 * NANOSECONDS_PER_SECOND) |
45 | BlockDriverState *bs = NULL; | 24 | |
46 | - QDict *qdict = NULL; | 25 | +static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll, |
47 | + QDict *qdict; | 26 | + int64_t block_ns); |
48 | QObject *qobj; | 27 | + |
49 | Visitor *v; | 28 | bool aio_poll_disabled(AioContext *ctx) |
50 | int ret; | 29 | { |
51 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create_opts(const char *filename, | 30 | return qatomic_read(&ctx->poll_disable_cnt); |
52 | qdict_put_str(qdict, "file", bs->node_name); | 31 | @@ -XXX,XX +XXX,XX @@ static bool aio_dispatch_handler(AioContext *ctx, AioHandler *node) |
53 | 32 | * scanning all handlers with aio_dispatch_handlers(). | |
54 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | 33 | */ |
55 | - qobject_unref(qdict); | 34 | static bool aio_dispatch_ready_handlers(AioContext *ctx, |
56 | - qdict = qobject_to(QDict, qobj); | 35 | - AioHandlerList *ready_list) |
57 | - if (qdict == NULL) { | 36 | + AioHandlerList *ready_list, |
58 | + if (!qobj) { | 37 | + int64_t block_ns) |
59 | ret = -EINVAL; | 38 | { |
60 | goto done; | 39 | bool progress = false; |
40 | AioHandler *node; | ||
41 | @@ -XXX,XX +XXX,XX @@ static bool aio_dispatch_ready_handlers(AioContext *ctx, | ||
42 | while ((node = QLIST_FIRST(ready_list))) { | ||
43 | QLIST_REMOVE(node, node_ready); | ||
44 | progress = aio_dispatch_handler(ctx, node) || progress; | ||
45 | + | ||
46 | + /* | ||
47 | + * Adjust polling time only after aio_dispatch_handler(), which can | ||
48 | + * add the handler to ctx->poll_aio_handlers. | ||
49 | + */ | ||
50 | + if (ctx->poll_max_ns && QLIST_IS_INSERTED(node, node_poll)) { | ||
51 | + adjust_polling_time(ctx, &node->poll, block_ns); | ||
52 | + } | ||
61 | } | 53 | } |
62 | 54 | ||
63 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | 55 | return progress; |
64 | + v = qobject_input_visitor_new_keyval(qobj); | 56 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) |
65 | + qobject_unref(qobj); | 57 | bool use_notify_me; |
66 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | 58 | int64_t timeout; |
67 | visit_free(v); | 59 | int64_t start = 0; |
68 | 60 | + int64_t block_ns = 0; | |
69 | diff --git a/block/qcow.c b/block/qcow.c | 61 | |
70 | index XXXXXXX..XXXXXXX 100644 | 62 | /* |
71 | --- a/block/qcow.c | 63 | * There cannot be two concurrent aio_poll calls for the same AioContext (or |
72 | +++ b/block/qcow.c | 64 | @@ -XXX,XX +XXX,XX @@ bool aio_poll(AioContext *ctx, bool blocking) |
73 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create_opts(const char *filename, | 65 | |
74 | { | 66 | aio_notify_accept(ctx); |
75 | BlockdevCreateOptions *create_options = NULL; | 67 | |
76 | BlockDriverState *bs = NULL; | 68 | - /* Adjust polling time */ |
77 | - QDict *qdict = NULL; | 69 | + /* Calculate blocked time for adaptive polling */ |
78 | + QDict *qdict; | 70 | if (ctx->poll_max_ns) { |
79 | QObject *qobj; | 71 | - AioHandler *node; |
80 | Visitor *v; | 72 | - int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start; |
81 | const char *val; | 73 | - |
82 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create_opts(const char *filename, | 74 | - QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { |
83 | qdict_put_str(qdict, "file", bs->node_name); | 75 | - if (QLIST_IS_INSERTED(node, node_ready)) { |
84 | 76 | - adjust_polling_time(ctx, &node->poll, block_ns); | |
85 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | 77 | - } |
86 | - qobject_unref(qdict); | 78 | - } |
87 | - qdict = qobject_to(QDict, qobj); | 79 | + block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start; |
88 | - if (qdict == NULL) { | ||
89 | + if (!qobj) { | ||
90 | ret = -EINVAL; | ||
91 | goto fail; | ||
92 | } | 80 | } |
93 | 81 | ||
94 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | 82 | progress |= aio_bh_poll(ctx); |
95 | + v = qobject_input_visitor_new_keyval(qobj); | 83 | - progress |= aio_dispatch_ready_handlers(ctx, &ready_list); |
96 | + qobject_unref(qobj); | 84 | + progress |= aio_dispatch_ready_handlers(ctx, &ready_list, block_ns); |
97 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | 85 | |
98 | visit_free(v); | 86 | aio_free_deleted_handlers(ctx); |
99 | |||
100 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
101 | index XXXXXXX..XXXXXXX 100644 | ||
102 | --- a/block/qcow2.c | ||
103 | +++ b/block/qcow2.c | ||
104 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt | ||
105 | Error **errp) | ||
106 | { | ||
107 | BlockdevCreateOptions *create_options = NULL; | ||
108 | - QDict *qdict = NULL; | ||
109 | + QDict *qdict; | ||
110 | QObject *qobj; | ||
111 | Visitor *v; | ||
112 | BlockDriverState *bs = NULL; | ||
113 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt | ||
114 | |||
115 | /* Now get the QAPI type BlockdevCreateOptions */ | ||
116 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
117 | - qobject_unref(qdict); | ||
118 | - qdict = qobject_to(QDict, qobj); | ||
119 | - if (qdict == NULL) { | ||
120 | + if (!qobj) { | ||
121 | ret = -EINVAL; | ||
122 | goto finish; | ||
123 | } | ||
124 | |||
125 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | ||
126 | + v = qobject_input_visitor_new_keyval(qobj); | ||
127 | + qobject_unref(qobj); | ||
128 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
129 | visit_free(v); | ||
130 | |||
131 | diff --git a/block/qed.c b/block/qed.c | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/block/qed.c | ||
134 | +++ b/block/qed.c | ||
135 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, | ||
136 | Error **errp) | ||
137 | { | ||
138 | BlockdevCreateOptions *create_options = NULL; | ||
139 | - QDict *qdict = NULL; | ||
140 | + QDict *qdict; | ||
141 | QObject *qobj; | ||
142 | Visitor *v; | ||
143 | BlockDriverState *bs = NULL; | ||
144 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, | ||
145 | qdict_put_str(qdict, "file", bs->node_name); | ||
146 | |||
147 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
148 | - qobject_unref(qdict); | ||
149 | - qdict = qobject_to(QDict, qobj); | ||
150 | - if (qdict == NULL) { | ||
151 | + if (!qobj) { | ||
152 | ret = -EINVAL; | ||
153 | goto fail; | ||
154 | } | ||
155 | |||
156 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | ||
157 | + v = qobject_input_visitor_new_keyval(qobj); | ||
158 | + qobject_unref(qobj); | ||
159 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
160 | visit_free(v); | ||
161 | |||
162 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/block/vhdx.c | ||
165 | +++ b/block/vhdx.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create_opts(const char *filename, | ||
167 | Error **errp) | ||
168 | { | ||
169 | BlockdevCreateOptions *create_options = NULL; | ||
170 | - QDict *qdict = NULL; | ||
171 | + QDict *qdict; | ||
172 | QObject *qobj; | ||
173 | Visitor *v; | ||
174 | BlockDriverState *bs = NULL; | ||
175 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create_opts(const char *filename, | ||
176 | qdict_put_str(qdict, "file", bs->node_name); | ||
177 | |||
178 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
179 | - qobject_unref(qdict); | ||
180 | - qdict = qobject_to(QDict, qobj); | ||
181 | - if (qdict == NULL) { | ||
182 | + if (!qobj) { | ||
183 | ret = -EINVAL; | ||
184 | goto fail; | ||
185 | } | ||
186 | |||
187 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | ||
188 | + v = qobject_input_visitor_new_keyval(qobj); | ||
189 | + qobject_unref(qobj); | ||
190 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
191 | visit_free(v); | ||
192 | |||
193 | diff --git a/block/vpc.c b/block/vpc.c | ||
194 | index XXXXXXX..XXXXXXX 100644 | ||
195 | --- a/block/vpc.c | ||
196 | +++ b/block/vpc.c | ||
197 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_create_opts(const char *filename, | ||
198 | QemuOpts *opts, Error **errp) | ||
199 | { | ||
200 | BlockdevCreateOptions *create_options = NULL; | ||
201 | - QDict *qdict = NULL; | ||
202 | + QDict *qdict; | ||
203 | QObject *qobj; | ||
204 | Visitor *v; | ||
205 | BlockDriverState *bs = NULL; | ||
206 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_create_opts(const char *filename, | ||
207 | qdict_put_str(qdict, "file", bs->node_name); | ||
208 | |||
209 | qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
210 | - qobject_unref(qdict); | ||
211 | - qdict = qobject_to(QDict, qobj); | ||
212 | - if (qdict == NULL) { | ||
213 | + if (!qobj) { | ||
214 | ret = -EINVAL; | ||
215 | goto fail; | ||
216 | } | ||
217 | |||
218 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | ||
219 | + v = qobject_input_visitor_new_keyval(qobj); | ||
220 | + qobject_unref(qobj); | ||
221 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
222 | visit_free(v); | ||
223 | 87 | ||
224 | -- | 88 | -- |
225 | 2.13.6 | 89 | 2.48.1 |
226 | |||
227 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Parameter "filename" is deprecated since commit 5c3ad1a6a8f, v2.10.0. | 3 | qsd-migrate is currently only working for raw, qcow2 and qed. |
4 | Time to get rid of it. | 4 | Other formats are failing, e.g. because they don't support migration. |
5 | Thus let's limit this test to the three usable formats now. | ||
5 | 6 | ||
6 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 7 | Suggested-by: Kevin Wolf <kwolf@redhat.com> |
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
9 | Message-ID: <20250224214058.205889-1-thuth@redhat.com> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | --- | 12 | --- |
10 | block/iscsi.c | 23 ++--------------------- | 13 | tests/qemu-iotests/tests/qsd-migrate | 2 +- |
11 | 1 file changed, 2 insertions(+), 21 deletions(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | 15 | ||
13 | diff --git a/block/iscsi.c b/block/iscsi.c | 16 | diff --git a/tests/qemu-iotests/tests/qsd-migrate b/tests/qemu-iotests/tests/qsd-migrate |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100755 |
15 | --- a/block/iscsi.c | 18 | --- a/tests/qemu-iotests/tests/qsd-migrate |
16 | +++ b/block/iscsi.c | 19 | +++ b/tests/qemu-iotests/tests/qsd-migrate |
17 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = { | 20 | @@ -XXX,XX +XXX,XX @@ import iotests |
18 | .name = "timeout", | 21 | |
19 | .type = QEMU_OPT_NUMBER, | 22 | from iotests import filter_qemu_io, filter_qtest |
20 | }, | 23 | |
21 | - { | 24 | -iotests.script_initialize(supported_fmts=['generic'], |
22 | - .name = "filename", | 25 | +iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'], |
23 | - .type = QEMU_OPT_STRING, | 26 | supported_protocols=['file'], |
24 | - }, | 27 | supported_platforms=['linux']) |
25 | { /* end of list */ } | ||
26 | }, | ||
27 | }; | ||
28 | @@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, | ||
29 | char *initiator_name = NULL; | ||
30 | QemuOpts *opts; | ||
31 | Error *local_err = NULL; | ||
32 | - const char *transport_name, *portal, *target, *filename; | ||
33 | + const char *transport_name, *portal, *target; | ||
34 | #if LIBISCSI_API_VERSION >= (20160603) | ||
35 | enum iscsi_transport_type transport; | ||
36 | #endif | ||
37 | int i, ret = 0, timeout = 0, lun; | ||
38 | |||
39 | - /* If we are given a filename, parse the filename, with precedence given to | ||
40 | - * filename encoded options */ | ||
41 | - filename = qdict_get_try_str(options, "filename"); | ||
42 | - if (filename) { | ||
43 | - warn_report("'filename' option specified. " | ||
44 | - "This is an unsupported option, and may be deprecated " | ||
45 | - "in the future"); | ||
46 | - iscsi_parse_filename(filename, options, &local_err); | ||
47 | - if (local_err) { | ||
48 | - ret = -EINVAL; | ||
49 | - error_propagate(errp, local_err); | ||
50 | - goto exit; | ||
51 | - } | ||
52 | - } | ||
53 | - | ||
54 | opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); | ||
55 | qemu_opts_absorb_qdict(opts, options, &local_err); | ||
56 | if (local_err) { | ||
57 | @@ -XXX,XX +XXX,XX @@ out: | ||
58 | } | ||
59 | memset(iscsilun, 0, sizeof(IscsiLun)); | ||
60 | } | ||
61 | -exit: | ||
62 | + | ||
63 | return ret; | ||
64 | } | ||
65 | 28 | ||
66 | -- | 29 | -- |
67 | 2.13.6 | 30 | 2.48.1 |
68 | |||
69 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Parameter "filename" is deprecated since commit 91589d9e5ca, v2.10.0. | 3 | Commit 71544d30a6f8 ("scsi: push request restart to SCSIDevice") removed |
4 | Time to get rid of it. | 4 | the only user of SCSIDiskState->bh. |
5 | 5 | ||
6 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
9 | Message-ID: <20250311132616.1049687-2-stefanha@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | --- | 11 | --- |
10 | block/rbd.c | 16 ---------------- | 12 | hw/scsi/scsi-disk.c | 1 - |
11 | 1 file changed, 16 deletions(-) | 13 | 1 file changed, 1 deletion(-) |
12 | 14 | ||
13 | diff --git a/block/rbd.c b/block/rbd.c | 15 | diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/rbd.c | 17 | --- a/hw/scsi/scsi-disk.c |
16 | +++ b/block/rbd.c | 18 | +++ b/hw/scsi/scsi-disk.c |
17 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | 19 | @@ -XXX,XX +XXX,XX @@ struct SCSIDiskState { |
18 | QObject *crumpled = NULL; | 20 | uint64_t max_unmap_size; |
19 | const QDictEntry *e; | 21 | uint64_t max_io_size; |
20 | Error *local_err = NULL; | 22 | uint32_t quirks; |
21 | - const char *filename; | 23 | - QEMUBH *bh; |
22 | char *keypairs, *secretid; | 24 | char *version; |
23 | int r; | 25 | char *serial; |
24 | 26 | char *vendor; | |
25 | - /* If we are given a filename, parse the filename, with precedence given to | ||
26 | - * filename encoded options */ | ||
27 | - filename = qdict_get_try_str(options, "filename"); | ||
28 | - if (filename) { | ||
29 | - warn_report("'filename' option specified. " | ||
30 | - "This is an unsupported option, and may be deprecated " | ||
31 | - "in the future"); | ||
32 | - qemu_rbd_parse_filename(filename, options, &local_err); | ||
33 | - qdict_del(options, "filename"); | ||
34 | - if (local_err) { | ||
35 | - error_propagate(errp, local_err); | ||
36 | - return -EINVAL; | ||
37 | - } | ||
38 | - } | ||
39 | - | ||
40 | keypairs = g_strdup(qdict_get_try_str(options, "=keyvalue-pairs")); | ||
41 | if (keypairs) { | ||
42 | qdict_del(options, "=keyvalue-pairs"); | ||
43 | -- | 27 | -- |
44 | 2.13.6 | 28 | 2.48.1 |
45 | 29 | ||
46 | 30 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | There's no need to restart the loop. We don't elsewhere, e.g. in | 3 | In the past a single AioContext was used for block I/O and it was |
4 | qdict_extract_subqdict(), qdict_join() and qemu_opts_absorb_qdict(). | 4 | fetched using blk_get_aio_context(). Nowadays the block layer supports |
5 | Simplify accordingly. | 5 | running I/O from any AioContext and multiple AioContexts at the same |
6 | time. Remove the dma_blk_io() AioContext argument and use the current | ||
7 | AioContext instead. | ||
6 | 8 | ||
7 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 9 | This makes calling the function easier and enables multiple IOThreads to |
10 | use dma_blk_io() concurrently for the same block device. | ||
11 | |||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 13 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
14 | Message-ID: <20250311132616.1049687-3-stefanha@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | --- | 16 | --- |
11 | qobject/block-qdict.c | 18 +++--------------- | 17 | include/system/dma.h | 3 +-- |
12 | 1 file changed, 3 insertions(+), 15 deletions(-) | 18 | hw/ide/core.c | 3 +-- |
19 | hw/ide/macio.c | 3 +-- | ||
20 | hw/scsi/scsi-disk.c | 6 ++---- | ||
21 | system/dma-helpers.c | 8 ++++---- | ||
22 | 5 files changed, 9 insertions(+), 14 deletions(-) | ||
13 | 23 | ||
14 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 24 | diff --git a/include/system/dma.h b/include/system/dma.h |
15 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/qobject/block-qdict.c | 26 | --- a/include/system/dma.h |
17 | +++ b/qobject/block-qdict.c | 27 | +++ b/include/system/dma.h |
18 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 28 | @@ -XXX,XX +XXX,XX @@ typedef BlockAIOCB *DMAIOFunc(int64_t offset, QEMUIOVector *iov, |
19 | QObject *value; | 29 | BlockCompletionFunc *cb, void *cb_opaque, |
20 | const QDictEntry *entry, *next; | 30 | void *opaque); |
21 | char *new_key; | 31 | |
22 | - bool delete; | 32 | -BlockAIOCB *dma_blk_io(AioContext *ctx, |
23 | 33 | - QEMUSGList *sg, uint64_t offset, uint32_t align, | |
24 | entry = qdict_first(qdict); | 34 | +BlockAIOCB *dma_blk_io(QEMUSGList *sg, uint64_t offset, uint32_t align, |
25 | 35 | DMAIOFunc *io_func, void *io_func_opaque, | |
26 | while (entry != NULL) { | 36 | BlockCompletionFunc *cb, void *opaque, DMADirection dir); |
27 | - | 37 | BlockAIOCB *dma_blk_read(BlockBackend *blk, |
28 | next = qdict_next(qdict, entry); | 38 | diff --git a/hw/ide/core.c b/hw/ide/core.c |
29 | value = qdict_entry_value(entry); | 39 | index XXXXXXX..XXXXXXX 100644 |
30 | new_key = NULL; | 40 | --- a/hw/ide/core.c |
31 | - delete = false; | 41 | +++ b/hw/ide/core.c |
32 | 42 | @@ -XXX,XX +XXX,XX @@ static void ide_dma_cb(void *opaque, int ret) | |
33 | if (prefix) { | 43 | BDRV_SECTOR_SIZE, ide_dma_cb, s); |
34 | new_key = g_strdup_printf("%s.%s", prefix, entry->key); | 44 | break; |
35 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 45 | case IDE_DMA_TRIM: |
36 | * itself disappears. */ | 46 | - s->bus->dma->aiocb = dma_blk_io(blk_get_aio_context(s->blk), |
37 | qdict_flatten_qdict(qobject_to(QDict, value), target, | 47 | - &s->sg, offset, BDRV_SECTOR_SIZE, |
38 | new_key ? new_key : entry->key); | 48 | + s->bus->dma->aiocb = dma_blk_io(&s->sg, offset, BDRV_SECTOR_SIZE, |
39 | - delete = true; | 49 | ide_issue_trim, s, ide_dma_cb, s, |
40 | + qdict_del(qdict, entry->key); | 50 | DMA_DIRECTION_TO_DEVICE); |
41 | } else if (qobject_type(value) == QTYPE_QLIST) { | 51 | break; |
42 | qdict_flatten_qlist(qobject_to(QList, value), target, | 52 | diff --git a/hw/ide/macio.c b/hw/ide/macio.c |
43 | new_key ? new_key : entry->key); | 53 | index XXXXXXX..XXXXXXX 100644 |
44 | - delete = true; | 54 | --- a/hw/ide/macio.c |
45 | + qdict_del(qdict, entry->key); | 55 | +++ b/hw/ide/macio.c |
46 | } else if (prefix) { | 56 | @@ -XXX,XX +XXX,XX @@ static void pmac_ide_transfer_cb(void *opaque, int ret) |
47 | /* All other objects are moved to the target unchanged. */ | 57 | pmac_ide_transfer_cb, io); |
48 | qdict_put_obj(target, new_key, qobject_ref(value)); | 58 | break; |
49 | - delete = true; | 59 | case IDE_DMA_TRIM: |
50 | - } | 60 | - s->bus->dma->aiocb = dma_blk_io(blk_get_aio_context(s->blk), &s->sg, |
51 | - | 61 | - offset, 0x1, ide_issue_trim, s, |
52 | - g_free(new_key); | 62 | + s->bus->dma->aiocb = dma_blk_io(&s->sg, offset, 0x1, ide_issue_trim, s, |
53 | - | 63 | pmac_ide_transfer_cb, io, |
54 | - if (delete) { | 64 | DMA_DIRECTION_TO_DEVICE); |
55 | qdict_del(qdict, entry->key); | 65 | break; |
56 | - | 66 | diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c |
57 | - /* Restart loop after modifying the iterated QDict */ | 67 | index XXXXXXX..XXXXXXX 100644 |
58 | - entry = qdict_first(qdict); | 68 | --- a/hw/scsi/scsi-disk.c |
59 | - continue; | 69 | +++ b/hw/scsi/scsi-disk.c |
60 | } | 70 | @@ -XXX,XX +XXX,XX @@ static void scsi_do_read(SCSIDiskReq *r, int ret) |
61 | 71 | if (r->req.sg) { | |
62 | + g_free(new_key); | 72 | dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_READ); |
63 | entry = next; | 73 | r->req.residual -= r->req.sg->size; |
64 | } | 74 | - r->req.aiocb = dma_blk_io(blk_get_aio_context(s->qdev.conf.blk), |
75 | - r->req.sg, r->sector << BDRV_SECTOR_BITS, | ||
76 | + r->req.aiocb = dma_blk_io(r->req.sg, r->sector << BDRV_SECTOR_BITS, | ||
77 | BDRV_SECTOR_SIZE, | ||
78 | sdc->dma_readv, r, scsi_dma_complete, r, | ||
79 | DMA_DIRECTION_FROM_DEVICE); | ||
80 | @@ -XXX,XX +XXX,XX @@ static void scsi_write_data(SCSIRequest *req) | ||
81 | if (r->req.sg) { | ||
82 | dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_WRITE); | ||
83 | r->req.residual -= r->req.sg->size; | ||
84 | - r->req.aiocb = dma_blk_io(blk_get_aio_context(s->qdev.conf.blk), | ||
85 | - r->req.sg, r->sector << BDRV_SECTOR_BITS, | ||
86 | + r->req.aiocb = dma_blk_io(r->req.sg, r->sector << BDRV_SECTOR_BITS, | ||
87 | BDRV_SECTOR_SIZE, | ||
88 | sdc->dma_writev, r, scsi_dma_complete, r, | ||
89 | DMA_DIRECTION_TO_DEVICE); | ||
90 | diff --git a/system/dma-helpers.c b/system/dma-helpers.c | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/system/dma-helpers.c | ||
93 | +++ b/system/dma-helpers.c | ||
94 | @@ -XXX,XX +XXX,XX @@ static const AIOCBInfo dma_aiocb_info = { | ||
95 | .cancel_async = dma_aio_cancel, | ||
96 | }; | ||
97 | |||
98 | -BlockAIOCB *dma_blk_io(AioContext *ctx, | ||
99 | +BlockAIOCB *dma_blk_io( | ||
100 | QEMUSGList *sg, uint64_t offset, uint32_t align, | ||
101 | DMAIOFunc *io_func, void *io_func_opaque, | ||
102 | BlockCompletionFunc *cb, | ||
103 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *dma_blk_io(AioContext *ctx, | ||
104 | |||
105 | dbs->acb = NULL; | ||
106 | dbs->sg = sg; | ||
107 | - dbs->ctx = ctx; | ||
108 | + dbs->ctx = qemu_get_current_aio_context(); | ||
109 | dbs->offset = offset; | ||
110 | dbs->align = align; | ||
111 | dbs->sg_cur_index = 0; | ||
112 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *dma_blk_read(BlockBackend *blk, | ||
113 | QEMUSGList *sg, uint64_t offset, uint32_t align, | ||
114 | void (*cb)(void *opaque, int ret), void *opaque) | ||
115 | { | ||
116 | - return dma_blk_io(blk_get_aio_context(blk), sg, offset, align, | ||
117 | + return dma_blk_io(sg, offset, align, | ||
118 | dma_blk_read_io_func, blk, cb, opaque, | ||
119 | DMA_DIRECTION_FROM_DEVICE); | ||
120 | } | ||
121 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *dma_blk_write(BlockBackend *blk, | ||
122 | QEMUSGList *sg, uint64_t offset, uint32_t align, | ||
123 | void (*cb)(void *opaque, int ret), void *opaque) | ||
124 | { | ||
125 | - return dma_blk_io(blk_get_aio_context(blk), sg, offset, align, | ||
126 | + return dma_blk_io(sg, offset, align, | ||
127 | dma_blk_write_io_func, blk, cb, opaque, | ||
128 | DMA_DIRECTION_TO_DEVICE); | ||
65 | } | 129 | } |
66 | -- | 130 | -- |
67 | 2.13.6 | 131 | 2.48.1 |
68 | |||
69 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Parameter auth-client-required lets you configure authentication | 3 | Until now, a SCSIDevice's I/O requests have run in a single AioContext. |
4 | methods. We tried to provide that in v2.9.0, but backed out due to | 4 | In order to support multiple IOThreads it will be necessary to move to |
5 | interface design doubts (commit 464444fcc16). | 5 | the concept of a per-SCSIRequest AioContext. |
6 | 6 | ||
7 | This commit is similar to what we backed out, but simpler: we use a | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | list of enumeration values instead of a list of objects with a member | ||
9 | of enumeration type. | ||
10 | |||
11 | Let's review our reasons for backing out the first try, as stated in | ||
12 | the commit message: | ||
13 | |||
14 | * The implementation uses deprecated rados_conf_set() key | ||
15 | "auth_supported". No biggie. | ||
16 | |||
17 | Fixed: we use "auth-client-required". | ||
18 | |||
19 | * The implementation makes -drive silently ignore invalid parameters | ||
20 | "auth" and "auth-supported.*.X" where X isn't "auth". Fixable (in | ||
21 | fact I'm going to fix similar bugs around parameter server), so | ||
22 | again no biggie. | ||
23 | |||
24 | That fix is commit 2836284db60. This commit doesn't bring the bugs | ||
25 | back. | ||
26 | |||
27 | * BlockdevOptionsRbd member @password-secret applies only to | ||
28 | authentication method cephx. Should it be a variant member of | ||
29 | RbdAuthMethod? | ||
30 | |||
31 | We've had time to ponder, and we decided to stick to the way Ceph | ||
32 | configuration works: the key configured separately, and silently | ||
33 | ignored if the authentication method doesn't use it. | ||
34 | |||
35 | * BlockdevOptionsRbd member @user could apply to both methods cephx | ||
36 | and none, but I'm not sure it's actually used with none. If it | ||
37 | isn't, should it be a variant member of RbdAuthMethod? | ||
38 | |||
39 | Likewise. | ||
40 | |||
41 | * The client offers a *set* of authentication methods, not a list. | ||
42 | Should the methods be optional members of BlockdevOptionsRbd instead | ||
43 | of members of list @auth-supported? The latter begs the question | ||
44 | what multiple entries for the same method mean. Trivial question | ||
45 | now that RbdAuthMethod contains nothing but @type, but less so when | ||
46 | RbdAuthMethod acquires other members, such the ones discussed above. | ||
47 | |||
48 | Again, we decided to stick to the way Ceph configuration works, except | ||
49 | we make auth-client-required a list of enumeration values instead of a | ||
50 | string containing keywords separated by delimiters. | ||
51 | |||
52 | * How BlockdevOptionsRbd member @auth-supported interacts with | ||
53 | settings from a configuration file specified with @conf is | ||
54 | undocumented. I suspect it's untested, too. | ||
55 | |||
56 | Not actually true, the documentation for @conf says "Values in the | ||
57 | configuration file will be overridden by options specified via QAPI", | ||
58 | and we've tested this. | ||
59 | |||
60 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
61 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
9 | Message-ID: <20250311132616.1049687-4-stefanha@redhat.com> | ||
62 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
63 | --- | 11 | --- |
64 | qapi/block-core.json | 13 +++++++++++++ | 12 | include/hw/scsi/scsi.h | 1 + |
65 | block/rbd.c | 42 ++++++++++++++++++++++++++++++++---------- | 13 | hw/scsi/scsi-bus.c | 1 + |
66 | 2 files changed, 45 insertions(+), 10 deletions(-) | 14 | hw/scsi/scsi-disk.c | 17 ++++++----------- |
15 | 3 files changed, 8 insertions(+), 11 deletions(-) | ||
67 | 16 | ||
68 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 17 | diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h |
69 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
70 | --- a/qapi/block-core.json | 19 | --- a/include/hw/scsi/scsi.h |
71 | +++ b/qapi/block-core.json | 20 | +++ b/include/hw/scsi/scsi.h |
72 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ struct SCSIRequest { |
73 | 22 | SCSIBus *bus; | |
74 | 23 | SCSIDevice *dev; | |
75 | ## | 24 | const SCSIReqOps *ops; |
76 | +# @RbdAuthMode: | 25 | + AioContext *ctx; |
77 | +# | 26 | uint32_t refcount; |
78 | +# Since: 3.0 | 27 | uint32_t tag; |
79 | +## | 28 | uint32_t lun; |
80 | +{ 'enum': 'RbdAuthMode', | 29 | diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c |
81 | + 'data': [ 'cephx', 'none' ] } | ||
82 | + | ||
83 | +## | ||
84 | # @BlockdevOptionsRbd: | ||
85 | # | ||
86 | # @pool: Ceph pool name. | ||
87 | @@ -XXX,XX +XXX,XX @@ | ||
88 | # | ||
89 | # @user: Ceph id name. | ||
90 | # | ||
91 | +# @auth-client-required: Acceptable authentication modes. | ||
92 | +# This maps to Ceph configuration option | ||
93 | +# "auth_client_required". (Since 3.0) | ||
94 | +# | ||
95 | # @server: Monitor host address and port. This maps | ||
96 | # to the "mon_host" Ceph option. | ||
97 | # | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | '*conf': 'str', | ||
100 | '*snapshot': 'str', | ||
101 | '*user': 'str', | ||
102 | + '*auth-client-required': ['RbdAuthMode'], | ||
103 | '*server': ['InetSocketAddressBase'] } } | ||
104 | |||
105 | ## | ||
106 | diff --git a/block/rbd.c b/block/rbd.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
108 | --- a/block/rbd.c | 31 | --- a/hw/scsi/scsi-bus.c |
109 | +++ b/block/rbd.c | 32 | +++ b/hw/scsi/scsi-bus.c |
110 | @@ -XXX,XX +XXX,XX @@ static void qemu_rbd_refresh_limits(BlockDriverState *bs, Error **errp) | 33 | @@ -XXX,XX +XXX,XX @@ invalid_opcode: |
111 | |||
112 | |||
113 | static int qemu_rbd_set_auth(rados_t cluster, const char *secretid, | ||
114 | + BlockdevOptionsRbd *opts, | ||
115 | Error **errp) | ||
116 | { | ||
117 | - if (secretid == 0) { | ||
118 | - return 0; | ||
119 | - } | ||
120 | + char *acr; | ||
121 | + int r; | ||
122 | + GString *accu; | ||
123 | + RbdAuthModeList *auth; | ||
124 | + | ||
125 | + if (secretid) { | ||
126 | + gchar *secret = qcrypto_secret_lookup_as_base64(secretid, | ||
127 | + errp); | ||
128 | + if (!secret) { | ||
129 | + return -1; | ||
130 | + } | ||
131 | |||
132 | - gchar *secret = qcrypto_secret_lookup_as_base64(secretid, | ||
133 | - errp); | ||
134 | - if (!secret) { | ||
135 | - return -1; | ||
136 | + rados_conf_set(cluster, "key", secret); | ||
137 | + g_free(secret); | ||
138 | } | ||
139 | |||
140 | - rados_conf_set(cluster, "key", secret); | ||
141 | - g_free(secret); | ||
142 | + if (opts->has_auth_client_required) { | ||
143 | + accu = g_string_new(""); | ||
144 | + for (auth = opts->auth_client_required; auth; auth = auth->next) { | ||
145 | + if (accu->str[0]) { | ||
146 | + g_string_append_c(accu, ';'); | ||
147 | + } | ||
148 | + g_string_append(accu, RbdAuthMode_str(auth->value)); | ||
149 | + } | ||
150 | + acr = g_string_free(accu, FALSE); | ||
151 | + r = rados_conf_set(cluster, "auth_client_required", acr); | ||
152 | + g_free(acr); | ||
153 | + if (r < 0) { | ||
154 | + error_setg_errno(errp, -r, | ||
155 | + "Could not set 'auth_client_required'"); | ||
156 | + return r; | ||
157 | + } | ||
158 | + } | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, | ||
163 | } | 34 | } |
164 | } | 35 | } |
165 | 36 | ||
166 | - if (qemu_rbd_set_auth(*cluster, secretid, errp) < 0) { | 37 | + req->ctx = qemu_get_current_aio_context(); |
167 | + if (qemu_rbd_set_auth(*cluster, secretid, opts, errp) < 0) { | 38 | req->cmd = cmd; |
168 | r = -EIO; | 39 | req->residual = req->cmd.xfer; |
169 | goto failed_shutdown; | 40 | |
170 | } | 41 | diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c |
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/scsi/scsi-disk.c | ||
44 | +++ b/hw/scsi/scsi-disk.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static void scsi_aio_complete(void *opaque, int ret) | ||
46 | SCSIDiskReq *r = (SCSIDiskReq *)opaque; | ||
47 | SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); | ||
48 | |||
49 | - /* The request must only run in the BlockBackend's AioContext */ | ||
50 | - assert(blk_get_aio_context(s->qdev.conf.blk) == | ||
51 | - qemu_get_current_aio_context()); | ||
52 | + /* The request must run in its AioContext */ | ||
53 | + assert(r->req.ctx == qemu_get_current_aio_context()); | ||
54 | |||
55 | assert(r->req.aiocb != NULL); | ||
56 | r->req.aiocb = NULL; | ||
57 | @@ -XXX,XX +XXX,XX @@ static void scsi_dma_complete(void *opaque, int ret) | ||
58 | |||
59 | static void scsi_read_complete_noio(SCSIDiskReq *r, int ret) | ||
60 | { | ||
61 | - SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); | ||
62 | uint32_t n; | ||
63 | |||
64 | - /* The request must only run in the BlockBackend's AioContext */ | ||
65 | - assert(blk_get_aio_context(s->qdev.conf.blk) == | ||
66 | - qemu_get_current_aio_context()); | ||
67 | + /* The request must run in its AioContext */ | ||
68 | + assert(r->req.ctx == qemu_get_current_aio_context()); | ||
69 | |||
70 | assert(r->req.aiocb == NULL); | ||
71 | if (scsi_disk_req_check_error(r, ret, ret > 0)) { | ||
72 | @@ -XXX,XX +XXX,XX @@ static void scsi_read_data(SCSIRequest *req) | ||
73 | |||
74 | static void scsi_write_complete_noio(SCSIDiskReq *r, int ret) | ||
75 | { | ||
76 | - SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); | ||
77 | uint32_t n; | ||
78 | |||
79 | - /* The request must only run in the BlockBackend's AioContext */ | ||
80 | - assert(blk_get_aio_context(s->qdev.conf.blk) == | ||
81 | - qemu_get_current_aio_context()); | ||
82 | + /* The request must run in its AioContext */ | ||
83 | + assert(r->req.ctx == qemu_get_current_aio_context()); | ||
84 | |||
85 | assert (r->req.aiocb == NULL); | ||
86 | if (scsi_disk_req_check_error(r, ret, ret > 0)) { | ||
171 | -- | 87 | -- |
172 | 2.13.6 | 88 | 2.48.1 |
173 | |||
174 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Remaining uses of qobject_input_visitor_new_keyval() in the block | 3 | SCSIDevice keeps track of in-flight requests for device reset and Task |
4 | subsystem: | 4 | Management Functions (TMFs). The request list requires protection so |
5 | that multi-threaded SCSI emulation can be implemented in commits that | ||
6 | follow. | ||
5 | 7 | ||
6 | * block_crypto_open_opts_init() | 8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Currently doesn't visit any non-string scalars, thus safe. It's | 9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
8 | called from | 10 | Message-ID: <20250311132616.1049687-5-stefanha@redhat.com> |
9 | - block_crypto_open_luks() | ||
10 | Creates the QDict with qemu_opts_to_qdict_filtered(), which | ||
11 | creates only string scalars, but has a TODO asking for other types. | ||
12 | - qcow_open() | ||
13 | - qcow2_open(), qcow2_co_invalidate_cache(), qcow2_reopen_prepare() | ||
14 | |||
15 | * block_crypto_create_opts_init(), called from | ||
16 | - block_crypto_co_create_opts_luks() | ||
17 | Also creates the QDict with qemu_opts_to_qdict_filtered(). | ||
18 | |||
19 | * vdi_co_create_opts() | ||
20 | Also creates the QDict with qemu_opts_to_qdict_filtered(). | ||
21 | |||
22 | Replace these uses by qobject_input_visitor_new_flat_confused() for | ||
23 | robustness. This adds crumpling. Right now, that's a no-op, but if | ||
24 | we ever extend these things in non-flat ways, crumpling will be | ||
25 | needed. | ||
26 | |||
27 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
28 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
29 | --- | 12 | --- |
30 | block/crypto.c | 12 +++++++++--- | 13 | include/hw/scsi/scsi.h | 7 ++- |
31 | block/vdi.c | 8 ++++++-- | 14 | hw/scsi/scsi-bus.c | 120 +++++++++++++++++++++++++++++------------ |
32 | 2 files changed, 15 insertions(+), 5 deletions(-) | 15 | 2 files changed, 88 insertions(+), 39 deletions(-) |
33 | 16 | ||
34 | diff --git a/block/crypto.c b/block/crypto.c | 17 | diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h |
35 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block/crypto.c | 19 | --- a/include/hw/scsi/scsi.h |
37 | +++ b/block/crypto.c | 20 | +++ b/include/hw/scsi/scsi.h |
38 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ struct SCSIRequest { |
39 | #include "qemu/osdep.h" | 22 | bool dma_started; |
40 | 23 | BlockAIOCB *aiocb; | |
41 | #include "block/block_int.h" | 24 | QEMUSGList *sg; |
42 | +#include "block/qdict.h" | 25 | + |
43 | #include "sysemu/block-backend.h" | 26 | + /* Protected by SCSIDevice->requests_lock */ |
44 | #include "crypto/block.h" | 27 | QTAILQ_ENTRY(SCSIRequest) next; |
45 | #include "qapi/opts-visitor.h" | 28 | }; |
46 | #include "qapi/qapi-visit-crypto.h" | 29 | |
47 | -#include "qapi/qmp/qdict.h" | 30 | @@ -XXX,XX +XXX,XX @@ struct SCSIDevice |
48 | #include "qapi/qobject-input-visitor.h" | 31 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
49 | #include "qapi/error.h" | 32 | uint32_t sense_len; |
50 | #include "qemu/option.h" | 33 | |
51 | @@ -XXX,XX +XXX,XX @@ block_crypto_open_opts_init(QCryptoBlockFormat format, | 34 | - /* |
52 | ret = g_new0(QCryptoBlockOpenOptions, 1); | 35 | - * The requests list is only accessed from the AioContext that executes |
53 | ret->format = format; | 36 | - * requests or from the main loop when IOThread processing is stopped. |
54 | 37 | - */ | |
55 | - v = qobject_input_visitor_new_keyval(QOBJECT(opts)); | 38 | + QemuMutex requests_lock; /* protects the requests list */ |
56 | + v = qobject_input_visitor_new_flat_confused(opts, &local_err); | 39 | QTAILQ_HEAD(, SCSIRequest) requests; |
57 | + if (local_err) { | 40 | |
58 | + goto out; | 41 | uint32_t channel; |
42 | diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/scsi/scsi-bus.c | ||
45 | +++ b/hw/scsi/scsi-bus.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static void scsi_device_for_each_req_sync(SCSIDevice *s, | ||
47 | assert(!runstate_is_running()); | ||
48 | assert(qemu_in_main_thread()); | ||
49 | |||
50 | - QTAILQ_FOREACH_SAFE(req, &s->requests, next, next_req) { | ||
51 | - fn(req, opaque); | ||
52 | + /* | ||
53 | + * Locking is not necessary because the guest is stopped and no other | ||
54 | + * threads can be accessing the requests list, but take the lock for | ||
55 | + * consistency. | ||
56 | + */ | ||
57 | + WITH_QEMU_LOCK_GUARD(&s->requests_lock) { | ||
58 | + QTAILQ_FOREACH_SAFE(req, &s->requests, next, next_req) { | ||
59 | + fn(req, opaque); | ||
60 | + } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ static void scsi_device_for_each_req_async_bh(void *opaque) | ||
65 | { | ||
66 | g_autofree SCSIDeviceForEachReqAsyncData *data = opaque; | ||
67 | SCSIDevice *s = data->s; | ||
68 | - AioContext *ctx; | ||
69 | - SCSIRequest *req; | ||
70 | - SCSIRequest *next; | ||
71 | + g_autoptr(GList) reqs = NULL; | ||
72 | |||
73 | /* | ||
74 | - * The BB cannot have changed contexts between this BH being scheduled and | ||
75 | - * now: BBs' AioContexts, when they have a node attached, can only be | ||
76 | - * changed via bdrv_try_change_aio_context(), in a drained section. While | ||
77 | - * we have the in-flight counter incremented, that drain must block. | ||
78 | + * Build a list of requests in this AioContext so fn() can be invoked later | ||
79 | + * outside requests_lock. | ||
80 | */ | ||
81 | - ctx = blk_get_aio_context(s->conf.blk); | ||
82 | - assert(ctx == qemu_get_current_aio_context()); | ||
83 | + WITH_QEMU_LOCK_GUARD(&s->requests_lock) { | ||
84 | + AioContext *ctx = qemu_get_current_aio_context(); | ||
85 | + SCSIRequest *req; | ||
86 | + SCSIRequest *next; | ||
87 | + | ||
88 | + QTAILQ_FOREACH_SAFE(req, &s->requests, next, next) { | ||
89 | + if (req->ctx == ctx) { | ||
90 | + scsi_req_ref(req); /* dropped after calling fn() */ | ||
91 | + reqs = g_list_prepend(reqs, req); | ||
92 | + } | ||
93 | + } | ||
59 | + } | 94 | + } |
60 | 95 | ||
61 | visit_start_struct(v, NULL, NULL, 0, &local_err); | 96 | - QTAILQ_FOREACH_SAFE(req, &s->requests, next, next) { |
97 | - data->fn(req, data->fn_opaque); | ||
98 | + /* Call fn() on each request */ | ||
99 | + for (GList *elem = g_list_first(reqs); elem; elem = g_list_next(elem)) { | ||
100 | + data->fn(elem->data, data->fn_opaque); | ||
101 | + scsi_req_unref(elem->data); | ||
102 | } | ||
103 | |||
104 | /* Drop the reference taken by scsi_device_for_each_req_async() */ | ||
105 | @@ -XXX,XX +XXX,XX @@ static void scsi_device_for_each_req_async_bh(void *opaque) | ||
106 | blk_dec_in_flight(s->conf.blk); | ||
107 | } | ||
108 | |||
109 | +static void scsi_device_for_each_req_async_do_ctx(gpointer key, gpointer value, | ||
110 | + gpointer user_data) | ||
111 | +{ | ||
112 | + AioContext *ctx = key; | ||
113 | + SCSIDeviceForEachReqAsyncData *params = user_data; | ||
114 | + SCSIDeviceForEachReqAsyncData *data; | ||
115 | + | ||
116 | + data = g_new(SCSIDeviceForEachReqAsyncData, 1); | ||
117 | + data->s = params->s; | ||
118 | + data->fn = params->fn; | ||
119 | + data->fn_opaque = params->fn_opaque; | ||
120 | + | ||
121 | + /* | ||
122 | + * Hold a reference to the SCSIDevice until | ||
123 | + * scsi_device_for_each_req_async_bh() finishes. | ||
124 | + */ | ||
125 | + object_ref(OBJECT(data->s)); | ||
126 | + | ||
127 | + /* Paired with scsi_device_for_each_req_async_bh() */ | ||
128 | + blk_inc_in_flight(data->s->conf.blk); | ||
129 | + | ||
130 | + aio_bh_schedule_oneshot(ctx, scsi_device_for_each_req_async_bh, data); | ||
131 | +} | ||
132 | + | ||
133 | /* | ||
134 | * Schedule @fn() to be invoked for each enqueued request in device @s. @fn() | ||
135 | - * runs in the AioContext that is executing the request. | ||
136 | + * must be thread-safe because it runs concurrently in each AioContext that is | ||
137 | + * executing a request. | ||
138 | + * | ||
139 | * Keeps the BlockBackend's in-flight counter incremented until everything is | ||
140 | * done, so draining it will settle all scheduled @fn() calls. | ||
141 | */ | ||
142 | @@ -XXX,XX +XXX,XX @@ static void scsi_device_for_each_req_async(SCSIDevice *s, | ||
143 | { | ||
144 | assert(qemu_in_main_thread()); | ||
145 | |||
146 | - SCSIDeviceForEachReqAsyncData *data = | ||
147 | - g_new(SCSIDeviceForEachReqAsyncData, 1); | ||
148 | - | ||
149 | - data->s = s; | ||
150 | - data->fn = fn; | ||
151 | - data->fn_opaque = opaque; | ||
152 | - | ||
153 | - /* | ||
154 | - * Hold a reference to the SCSIDevice until | ||
155 | - * scsi_device_for_each_req_async_bh() finishes. | ||
156 | - */ | ||
157 | - object_ref(OBJECT(s)); | ||
158 | + /* The set of AioContexts where the requests are being processed */ | ||
159 | + g_autoptr(GHashTable) aio_contexts = g_hash_table_new(NULL, NULL); | ||
160 | + WITH_QEMU_LOCK_GUARD(&s->requests_lock) { | ||
161 | + SCSIRequest *req; | ||
162 | + QTAILQ_FOREACH(req, &s->requests, next) { | ||
163 | + g_hash_table_add(aio_contexts, req->ctx); | ||
164 | + } | ||
165 | + } | ||
166 | |||
167 | - /* Paired with blk_dec_in_flight() in scsi_device_for_each_req_async_bh() */ | ||
168 | - blk_inc_in_flight(s->conf.blk); | ||
169 | - aio_bh_schedule_oneshot(blk_get_aio_context(s->conf.blk), | ||
170 | - scsi_device_for_each_req_async_bh, | ||
171 | - data); | ||
172 | + /* Schedule a BH for each AioContext */ | ||
173 | + SCSIDeviceForEachReqAsyncData params = { | ||
174 | + .s = s, | ||
175 | + .fn = fn, | ||
176 | + .fn_opaque = opaque, | ||
177 | + }; | ||
178 | + g_hash_table_foreach( | ||
179 | + aio_contexts, | ||
180 | + scsi_device_for_each_req_async_do_ctx, | ||
181 | + ¶ms | ||
182 | + ); | ||
183 | } | ||
184 | |||
185 | static void scsi_device_realize(SCSIDevice *s, Error **errp) | ||
186 | @@ -XXX,XX +XXX,XX @@ static void scsi_qdev_realize(DeviceState *qdev, Error **errp) | ||
187 | dev->lun = lun; | ||
188 | } | ||
189 | |||
190 | + qemu_mutex_init(&dev->requests_lock); | ||
191 | QTAILQ_INIT(&dev->requests); | ||
192 | scsi_device_realize(dev, &local_err); | ||
62 | if (local_err) { | 193 | if (local_err) { |
63 | @@ -XXX,XX +XXX,XX @@ block_crypto_create_opts_init(QCryptoBlockFormat format, | 194 | @@ -XXX,XX +XXX,XX @@ static void scsi_qdev_unrealize(DeviceState *qdev) |
64 | ret = g_new0(QCryptoBlockCreateOptions, 1); | 195 | |
65 | ret->format = format; | 196 | scsi_device_purge_requests(dev, SENSE_CODE(NO_SENSE)); |
66 | 197 | ||
67 | - v = qobject_input_visitor_new_keyval(QOBJECT(opts)); | 198 | + qemu_mutex_destroy(&dev->requests_lock); |
68 | + v = qobject_input_visitor_new_flat_confused(opts, &local_err); | 199 | + |
69 | + if (local_err) { | 200 | scsi_device_unrealize(dev); |
70 | + goto out; | 201 | |
202 | blockdev_mark_auto_del(dev->conf.blk); | ||
203 | @@ -XXX,XX +XXX,XX @@ static void scsi_req_enqueue_internal(SCSIRequest *req) | ||
204 | req->sg = NULL; | ||
205 | } | ||
206 | req->enqueued = true; | ||
207 | - QTAILQ_INSERT_TAIL(&req->dev->requests, req, next); | ||
208 | + | ||
209 | + WITH_QEMU_LOCK_GUARD(&req->dev->requests_lock) { | ||
210 | + QTAILQ_INSERT_TAIL(&req->dev->requests, req, next); | ||
71 | + } | 211 | + } |
72 | 212 | } | |
73 | visit_start_struct(v, NULL, NULL, 0, &local_err); | 213 | |
74 | if (local_err) { | 214 | int32_t scsi_req_enqueue(SCSIRequest *req) |
75 | diff --git a/block/vdi.c b/block/vdi.c | 215 | @@ -XXX,XX +XXX,XX @@ static void scsi_req_dequeue(SCSIRequest *req) |
76 | index XXXXXXX..XXXXXXX 100644 | 216 | trace_scsi_req_dequeue(req->dev->id, req->lun, req->tag); |
77 | --- a/block/vdi.c | 217 | req->retry = false; |
78 | +++ b/block/vdi.c | 218 | if (req->enqueued) { |
79 | @@ -XXX,XX +XXX,XX @@ | 219 | - QTAILQ_REMOVE(&req->dev->requests, req, next); |
80 | 220 | + WITH_QEMU_LOCK_GUARD(&req->dev->requests_lock) { | |
81 | #include "qemu/osdep.h" | 221 | + QTAILQ_REMOVE(&req->dev->requests, req, next); |
82 | #include "qapi/error.h" | 222 | + } |
83 | -#include "qapi/qmp/qdict.h" | 223 | req->enqueued = false; |
84 | #include "qapi/qobject-input-visitor.h" | 224 | scsi_req_unref(req); |
85 | #include "qapi/qapi-visit-block-core.h" | 225 | } |
86 | #include "block/block_int.h" | 226 | @@ -XXX,XX +XXX,XX @@ static void scsi_device_class_init(ObjectClass *klass, void *data) |
87 | +#include "block/qdict.h" | 227 | |
88 | #include "sysemu/block-backend.h" | 228 | static void scsi_dev_instance_init(Object *obj) |
89 | #include "qemu/module.h" | 229 | { |
90 | #include "qemu/option.h" | 230 | - DeviceState *dev = DEVICE(obj); |
91 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, | 231 | - SCSIDevice *s = SCSI_DEVICE(dev); |
92 | } | 232 | + SCSIDevice *s = SCSI_DEVICE(obj); |
93 | 233 | ||
94 | /* Get the QAPI object */ | 234 | device_add_bootindex_property(obj, &s->conf.bootindex, |
95 | - v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); | 235 | "bootindex", NULL, |
96 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
97 | + if (!v) { | ||
98 | + ret = -EINVAL; | ||
99 | + goto done; | ||
100 | + } | ||
101 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
102 | visit_free(v); | ||
103 | |||
104 | -- | 236 | -- |
105 | 2.13.6 | 237 | 2.48.1 |
106 | |||
107 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | qdict_flatten_qdict() skips copying scalars from @qdict to @target | 3 | Virtqueues are not thread-safe. Until now this was not a major issue |
4 | when the two are the same. Fair enough, but it uses a non-obvious | 4 | since all virtqueue processing happened in the same thread. The ctrl |
5 | test for "same". Replace it by the obvious one. While there, improve | 5 | queue's Task Management Function (TMF) requests sometimes need the main |
6 | comments. | 6 | loop, so a BH was used to schedule the virtqueue completion back in the |
7 | 7 | thread that has virtqueue access. | |
8 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 8 | |
9 | When IOThread Virtqueue Mapping is introduced in later commits, event | ||
10 | and ctrl virtqueue accesses from other threads will become necessary. | ||
11 | Introduce an optional per-virtqueue lock so the event and ctrl | ||
12 | virtqueues can be protected in the commits that follow. | ||
13 | |||
14 | The addition of the ctrl virtqueue lock makes | ||
15 | virtio_scsi_complete_req_from_main_loop() and its BH unnecessary. | ||
16 | Instead, take the ctrl virtqueue lock from the main loop thread. | ||
17 | |||
18 | The cmd virtqueue does not have a lock because the entirety of SCSI | ||
19 | command processing happens in one thread. Only one thread accesses the | ||
20 | cmd virtqueue and a lock is unnecessary. | ||
21 | |||
22 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 23 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
24 | Message-ID: <20250311132616.1049687-6-stefanha@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 25 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | --- | 26 | --- |
12 | qobject/block-qdict.c | 14 +++++++++----- | 27 | include/hw/virtio/virtio-scsi.h | 3 ++ |
13 | 1 file changed, 9 insertions(+), 5 deletions(-) | 28 | hw/scsi/virtio-scsi.c | 84 ++++++++++++++++++--------------- |
14 | 29 | 2 files changed, 49 insertions(+), 38 deletions(-) | |
15 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 30 | |
31 | diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/qobject/block-qdict.c | 33 | --- a/include/hw/virtio/virtio-scsi.h |
18 | +++ b/qobject/block-qdict.c | 34 | +++ b/include/hw/virtio/virtio-scsi.h |
19 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) | 35 | @@ -XXX,XX +XXX,XX @@ struct VirtIOSCSI { |
20 | value = qlist_entry_obj(entry); | 36 | int resetting; /* written from main loop thread, read from any thread */ |
21 | new_key = g_strdup_printf("%s.%i", prefix, i); | 37 | bool events_dropped; |
22 | 38 | ||
23 | + /* | 39 | + QemuMutex ctrl_lock; /* protects ctrl_vq */ |
24 | + * Flatten non-empty QDict and QList recursively into @target, | 40 | + QemuMutex event_lock; /* protects event_vq */ |
25 | + * copy other objects to @target | 41 | + |
26 | + */ | 42 | /* |
27 | if (qobject_type(value) == QTYPE_QDICT) { | 43 | * TMFs deferred to main loop BH. These fields are protected by |
28 | qdict_flatten_qdict(qobject_to(QDict, value), target, new_key); | 44 | * tmf_bh_lock. |
29 | } else if (qobject_type(value) == QTYPE_QLIST) { | 45 | diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c |
30 | qdict_flatten_qlist(qobject_to(QList, value), target, new_key); | 46 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/hw/scsi/virtio-scsi.c | ||
48 | +++ b/hw/scsi/virtio-scsi.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_free_req(VirtIOSCSIReq *req) | ||
50 | g_free(req); | ||
51 | } | ||
52 | |||
53 | -static void virtio_scsi_complete_req(VirtIOSCSIReq *req) | ||
54 | +static void virtio_scsi_complete_req(VirtIOSCSIReq *req, QemuMutex *vq_lock) | ||
55 | { | ||
56 | VirtIOSCSI *s = req->dev; | ||
57 | VirtQueue *vq = req->vq; | ||
58 | VirtIODevice *vdev = VIRTIO_DEVICE(s); | ||
59 | |||
60 | qemu_iovec_from_buf(&req->resp_iov, 0, &req->resp, req->resp_size); | ||
61 | + | ||
62 | + if (vq_lock) { | ||
63 | + qemu_mutex_lock(vq_lock); | ||
64 | + } | ||
65 | + | ||
66 | virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size); | ||
67 | if (s->dataplane_started && !s->dataplane_fenced) { | ||
68 | virtio_notify_irqfd(vdev, vq); | ||
69 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req) | ||
70 | virtio_notify(vdev, vq); | ||
71 | } | ||
72 | |||
73 | + if (vq_lock) { | ||
74 | + qemu_mutex_unlock(vq_lock); | ||
75 | + } | ||
76 | + | ||
77 | if (req->sreq) { | ||
78 | req->sreq->hba_private = NULL; | ||
79 | scsi_req_unref(req->sreq); | ||
80 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_complete_req(VirtIOSCSIReq *req) | ||
81 | virtio_scsi_free_req(req); | ||
82 | } | ||
83 | |||
84 | -static void virtio_scsi_complete_req_bh(void *opaque) | ||
85 | +static void virtio_scsi_bad_req(VirtIOSCSIReq *req, QemuMutex *vq_lock) | ||
86 | { | ||
87 | - VirtIOSCSIReq *req = opaque; | ||
88 | + virtio_error(VIRTIO_DEVICE(req->dev), "wrong size for virtio-scsi headers"); | ||
89 | |||
90 | - virtio_scsi_complete_req(req); | ||
91 | -} | ||
92 | + if (vq_lock) { | ||
93 | + qemu_mutex_lock(vq_lock); | ||
94 | + } | ||
95 | |||
96 | -/* | ||
97 | - * Called from virtio_scsi_do_one_tmf_bh() in main loop thread. The main loop | ||
98 | - * thread cannot touch the virtqueue since that could race with an IOThread. | ||
99 | - */ | ||
100 | -static void virtio_scsi_complete_req_from_main_loop(VirtIOSCSIReq *req) | ||
101 | -{ | ||
102 | - VirtIOSCSI *s = req->dev; | ||
103 | + virtqueue_detach_element(req->vq, &req->elem, 0); | ||
104 | |||
105 | - if (!s->ctx || s->ctx == qemu_get_aio_context()) { | ||
106 | - /* No need to schedule a BH when there is no IOThread */ | ||
107 | - virtio_scsi_complete_req(req); | ||
108 | - } else { | ||
109 | - /* Run request completion in the IOThread */ | ||
110 | - aio_wait_bh_oneshot(s->ctx, virtio_scsi_complete_req_bh, req); | ||
111 | + if (vq_lock) { | ||
112 | + qemu_mutex_unlock(vq_lock); | ||
113 | } | ||
114 | -} | ||
115 | |||
116 | -static void virtio_scsi_bad_req(VirtIOSCSIReq *req) | ||
117 | -{ | ||
118 | - virtio_error(VIRTIO_DEVICE(req->dev), "wrong size for virtio-scsi headers"); | ||
119 | - virtqueue_detach_element(req->vq, &req->elem, 0); | ||
120 | virtio_scsi_free_req(req); | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req, | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | -static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq) | ||
128 | +static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq, QemuMutex *vq_lock) | ||
129 | { | ||
130 | VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s; | ||
131 | VirtIOSCSIReq *req; | ||
132 | |||
133 | + if (vq_lock) { | ||
134 | + qemu_mutex_lock(vq_lock); | ||
135 | + } | ||
136 | + | ||
137 | req = virtqueue_pop(vq, sizeof(VirtIOSCSIReq) + vs->cdb_size); | ||
138 | + | ||
139 | + if (vq_lock) { | ||
140 | + qemu_mutex_unlock(vq_lock); | ||
141 | + } | ||
142 | + | ||
143 | if (!req) { | ||
144 | return NULL; | ||
145 | } | ||
146 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data) | ||
147 | |||
148 | trace_virtio_scsi_tmf_resp(virtio_scsi_get_lun(req->req.tmf.lun), | ||
149 | req->req.tmf.tag, req->resp.tmf.response); | ||
150 | - virtio_scsi_complete_req(req); | ||
151 | + virtio_scsi_complete_req(req, &req->dev->ctrl_lock); | ||
152 | } | ||
153 | g_free(n); | ||
154 | } | ||
155 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) | ||
156 | |||
157 | out: | ||
158 | object_unref(OBJECT(d)); | ||
159 | - virtio_scsi_complete_req_from_main_loop(req); | ||
160 | + virtio_scsi_complete_req(req, &s->ctrl_lock); | ||
161 | } | ||
162 | |||
163 | /* Some TMFs must be processed from the main loop thread */ | ||
164 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_reset_tmf_bh(VirtIOSCSI *s) | ||
165 | |||
166 | /* SAM-6 6.3.2 Hard reset */ | ||
167 | req->resp.tmf.response = VIRTIO_SCSI_S_TARGET_FAILURE; | ||
168 | - virtio_scsi_complete_req(req); | ||
169 | + virtio_scsi_complete_req(req, &req->dev->ctrl_lock); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
174 | |||
175 | if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0, | ||
176 | &type, sizeof(type)) < sizeof(type)) { | ||
177 | - virtio_scsi_bad_req(req); | ||
178 | + virtio_scsi_bad_req(req, &s->ctrl_lock); | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
183 | if (type == VIRTIO_SCSI_T_TMF) { | ||
184 | if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq), | ||
185 | sizeof(VirtIOSCSICtrlTMFResp)) < 0) { | ||
186 | - virtio_scsi_bad_req(req); | ||
187 | + virtio_scsi_bad_req(req, &s->ctrl_lock); | ||
188 | return; | ||
31 | } else { | 189 | } else { |
32 | - /* All other types are moved to the target unchanged. */ | 190 | r = virtio_scsi_do_tmf(s, req); |
33 | qdict_put_obj(target, new_key, qobject_ref(value)); | 191 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) |
192 | type == VIRTIO_SCSI_T_AN_SUBSCRIBE) { | ||
193 | if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq), | ||
194 | sizeof(VirtIOSCSICtrlANResp)) < 0) { | ||
195 | - virtio_scsi_bad_req(req); | ||
196 | + virtio_scsi_bad_req(req, &s->ctrl_lock); | ||
197 | return; | ||
198 | } else { | ||
199 | req->req.an.event_requested = | ||
200 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
201 | type == VIRTIO_SCSI_T_AN_SUBSCRIBE) | ||
202 | trace_virtio_scsi_an_resp(virtio_scsi_get_lun(req->req.an.lun), | ||
203 | req->resp.an.response); | ||
204 | - virtio_scsi_complete_req(req); | ||
205 | + virtio_scsi_complete_req(req, &s->ctrl_lock); | ||
206 | } else { | ||
207 | assert(r == -EINPROGRESS); | ||
208 | } | ||
209 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq) | ||
210 | { | ||
211 | VirtIOSCSIReq *req; | ||
212 | |||
213 | - while ((req = virtio_scsi_pop_req(s, vq))) { | ||
214 | + while ((req = virtio_scsi_pop_req(s, vq, &s->ctrl_lock))) { | ||
215 | virtio_scsi_handle_ctrl_req(s, req); | ||
216 | } | ||
217 | } | ||
218 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req) | ||
219 | * in virtio_scsi_command_complete. | ||
220 | */ | ||
221 | req->resp_size = sizeof(VirtIOSCSICmdResp); | ||
222 | - virtio_scsi_complete_req(req); | ||
223 | + virtio_scsi_complete_req(req, NULL); | ||
224 | } | ||
225 | |||
226 | static void virtio_scsi_command_failed(SCSIRequest *r) | ||
227 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
228 | virtio_scsi_fail_cmd_req(req); | ||
229 | return -ENOTSUP; | ||
230 | } else { | ||
231 | - virtio_scsi_bad_req(req); | ||
232 | + virtio_scsi_bad_req(req, NULL); | ||
233 | return -EINVAL; | ||
34 | } | 234 | } |
35 | 235 | } | |
36 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 236 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq) |
37 | new_key = g_strdup_printf("%s.%s", prefix, entry->key); | 237 | virtio_queue_set_notification(vq, 0); |
38 | } | 238 | } |
39 | 239 | ||
40 | + /* | 240 | - while ((req = virtio_scsi_pop_req(s, vq))) { |
41 | + * Flatten non-empty QDict and QList recursively into @target, | 241 | + while ((req = virtio_scsi_pop_req(s, vq, NULL))) { |
42 | + * copy other objects to @target | 242 | ret = virtio_scsi_handle_cmd_req_prepare(s, req); |
43 | + */ | 243 | if (!ret) { |
44 | if (qobject_type(value) == QTYPE_QDICT) { | 244 | QTAILQ_INSERT_TAIL(&reqs, req, next); |
45 | - /* Entries of QDicts are processed recursively, the QDict object | 245 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_push_event(VirtIOSCSI *s, |
46 | - * itself disappears. */ | 246 | return; |
47 | qdict_flatten_qdict(qobject_to(QDict, value), target, | 247 | } |
48 | new_key ? new_key : entry->key); | 248 | |
49 | qdict_del(qdict, entry->key); | 249 | - req = virtio_scsi_pop_req(s, vs->event_vq); |
50 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 250 | + req = virtio_scsi_pop_req(s, vs->event_vq, &s->event_lock); |
51 | qdict_flatten_qlist(qobject_to(QList, value), target, | 251 | if (!req) { |
52 | new_key ? new_key : entry->key); | 252 | s->events_dropped = true; |
53 | qdict_del(qdict, entry->key); | 253 | return; |
54 | - } else if (prefix) { | 254 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_push_event(VirtIOSCSI *s, |
55 | - /* All other objects are moved to the target unchanged. */ | 255 | } |
56 | + } else if (target != qdict) { | 256 | |
57 | qdict_put_obj(target, new_key, qobject_ref(value)); | 257 | if (virtio_scsi_parse_req(req, 0, sizeof(VirtIOSCSIEvent))) { |
58 | qdict_del(qdict, entry->key); | 258 | - virtio_scsi_bad_req(req); |
59 | } | 259 | + virtio_scsi_bad_req(req, &s->event_lock); |
260 | return; | ||
261 | } | ||
262 | |||
263 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_push_event(VirtIOSCSI *s, | ||
264 | } | ||
265 | trace_virtio_scsi_event(virtio_scsi_get_lun(evt->lun), event, reason); | ||
266 | |||
267 | - virtio_scsi_complete_req(req); | ||
268 | + virtio_scsi_complete_req(req, &s->event_lock); | ||
269 | } | ||
270 | |||
271 | static void virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq) | ||
272 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp) | ||
273 | Error *err = NULL; | ||
274 | |||
275 | QTAILQ_INIT(&s->tmf_bh_list); | ||
276 | + qemu_mutex_init(&s->ctrl_lock); | ||
277 | + qemu_mutex_init(&s->event_lock); | ||
278 | qemu_mutex_init(&s->tmf_bh_lock); | ||
279 | |||
280 | virtio_scsi_common_realize(dev, | ||
281 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_device_unrealize(DeviceState *dev) | ||
282 | qbus_set_hotplug_handler(BUS(&s->bus), NULL); | ||
283 | virtio_scsi_common_unrealize(dev); | ||
284 | qemu_mutex_destroy(&s->tmf_bh_lock); | ||
285 | + qemu_mutex_destroy(&s->event_lock); | ||
286 | + qemu_mutex_destroy(&s->ctrl_lock); | ||
287 | } | ||
288 | |||
289 | static const Property virtio_scsi_properties[] = { | ||
60 | -- | 290 | -- |
61 | 2.13.6 | 291 | 2.48.1 |
62 | |||
63 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The previous commit fixed -blockdev breakage due to misuse of the | 3 | The block layer can invoke the resize callback from any AioContext that |
4 | qobject input visitor's keyval flavor in bdrv_file_open(). The commit | 4 | is processing requests. The virtqueue is already protected but the |
5 | message explain why using the plain flavor would be just as wrong; it | 5 | events_dropped field also needs to be protected against races. Cover it |
6 | would break -drive. Turns out we break it in three places: | 6 | using the event virtqueue lock because it is closely associated with |
7 | nbd_open(), sd_open() and ssh_file_open(). They are even marked | 7 | accesses to the virtqueue. |
8 | FIXME. Example breakage: | ||
9 | 8 | ||
10 | $ qemu-system-x86 -drive node-name=n1,driver=nbd,server.type=inet,server.host=localhost,server.port=1234,server.numeric=off | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | qemu-system-x86: -drive node-name=n1,driver=nbd,server.type=inet,server.host=localhost,server.port=1234,server.numeric=off: Invalid parameter type for 'numeric', expected: boolean | ||
12 | |||
13 | Fix it the same way: replace qdict_crumple() by | ||
14 | qdict_crumple_for_keyval_qiv(), and switch from plain to the keyval | ||
15 | flavor. | ||
16 | |||
17 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
18 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
11 | Message-ID: <20250311132616.1049687-7-stefanha@redhat.com> | ||
19 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
20 | --- | 13 | --- |
21 | block/nbd.c | 12 ++---------- | 14 | include/hw/virtio/virtio-scsi.h | 3 ++- |
22 | block/sheepdog.c | 12 ++---------- | 15 | hw/scsi/virtio-scsi.c | 29 ++++++++++++++++++++--------- |
23 | block/ssh.c | 12 ++---------- | 16 | 2 files changed, 22 insertions(+), 10 deletions(-) |
24 | 3 files changed, 6 insertions(+), 30 deletions(-) | ||
25 | 17 | ||
26 | diff --git a/block/nbd.c b/block/nbd.c | 18 | diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h |
27 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/block/nbd.c | 20 | --- a/include/hw/virtio/virtio-scsi.h |
29 | +++ b/block/nbd.c | 21 | +++ b/include/hw/virtio/virtio-scsi.h |
30 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, | 22 | @@ -XXX,XX +XXX,XX @@ struct VirtIOSCSI { |
31 | goto done; | 23 | |
24 | SCSIBus bus; | ||
25 | int resetting; /* written from main loop thread, read from any thread */ | ||
26 | + | ||
27 | + QemuMutex event_lock; /* protects event_vq and events_dropped */ | ||
28 | bool events_dropped; | ||
29 | |||
30 | QemuMutex ctrl_lock; /* protects ctrl_vq */ | ||
31 | - QemuMutex event_lock; /* protects event_vq */ | ||
32 | |||
33 | /* | ||
34 | * TMFs deferred to main loop BH. These fields are protected by | ||
35 | diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/hw/scsi/virtio-scsi.c | ||
38 | +++ b/hw/scsi/virtio-scsi.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_reset(VirtIODevice *vdev) | ||
40 | |||
41 | vs->sense_size = VIRTIO_SCSI_SENSE_DEFAULT_SIZE; | ||
42 | vs->cdb_size = VIRTIO_SCSI_CDB_DEFAULT_SIZE; | ||
43 | - s->events_dropped = false; | ||
44 | + | ||
45 | + WITH_QEMU_LOCK_GUARD(&s->event_lock) { | ||
46 | + s->events_dropped = false; | ||
47 | + } | ||
48 | } | ||
49 | |||
50 | typedef struct { | ||
51 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_push_event(VirtIOSCSI *s, | ||
32 | } | 52 | } |
33 | 53 | ||
34 | - crumpled_addr = qdict_crumple(addr, errp); | 54 | req = virtio_scsi_pop_req(s, vs->event_vq, &s->event_lock); |
35 | + crumpled_addr = qdict_crumple_for_keyval_qiv(addr, errp); | 55 | - if (!req) { |
36 | if (!crumpled_addr) { | 56 | - s->events_dropped = true; |
37 | goto done; | 57 | - return; |
58 | - } | ||
59 | + WITH_QEMU_LOCK_GUARD(&s->event_lock) { | ||
60 | + if (!req) { | ||
61 | + s->events_dropped = true; | ||
62 | + return; | ||
63 | + } | ||
64 | |||
65 | - if (s->events_dropped) { | ||
66 | - event |= VIRTIO_SCSI_T_EVENTS_MISSED; | ||
67 | - s->events_dropped = false; | ||
68 | + if (s->events_dropped) { | ||
69 | + event |= VIRTIO_SCSI_T_EVENTS_MISSED; | ||
70 | + s->events_dropped = false; | ||
71 | + } | ||
38 | } | 72 | } |
39 | 73 | ||
40 | - /* | 74 | if (virtio_scsi_parse_req(req, 0, sizeof(VirtIOSCSIEvent))) { |
41 | - * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive | 75 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_push_event(VirtIOSCSI *s, |
42 | - * server.type=inet. .to doesn't matter, it's ignored anyway. | 76 | |
43 | - * That's because when @options come from -blockdev or | 77 | static void virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq) |
44 | - * blockdev_add, members are typed according to the QAPI schema, | 78 | { |
45 | - * but when they come from -drive, they're all QString. The | 79 | - if (s->events_dropped) { |
46 | - * visitor expects the former. | 80 | + bool events_dropped; |
47 | - */ | 81 | + |
48 | - iv = qobject_input_visitor_new(crumpled_addr); | 82 | + WITH_QEMU_LOCK_GUARD(&s->event_lock) { |
49 | + iv = qobject_input_visitor_new_keyval(crumpled_addr); | 83 | + events_dropped = s->events_dropped; |
50 | visit_type_SocketAddress(iv, NULL, &saddr, &local_err); | 84 | + } |
51 | if (local_err) { | 85 | + |
52 | error_propagate(errp, local_err); | 86 | + if (events_dropped) { |
53 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 87 | VirtIOSCSIEventInfo info = { |
54 | index XXXXXXX..XXXXXXX 100644 | 88 | .event = VIRTIO_SCSI_T_NO_EVENT, |
55 | --- a/block/sheepdog.c | 89 | }; |
56 | +++ b/block/sheepdog.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *sd_server_config(QDict *options, Error **errp) | ||
58 | |||
59 | qdict_extract_subqdict(options, &server, "server."); | ||
60 | |||
61 | - crumpled_server = qdict_crumple(server, errp); | ||
62 | + crumpled_server = qdict_crumple_for_keyval_qiv(server, errp); | ||
63 | if (!crumpled_server) { | ||
64 | goto done; | ||
65 | } | ||
66 | |||
67 | - /* | ||
68 | - * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive | ||
69 | - * server.type=inet. .to doesn't matter, it's ignored anyway. | ||
70 | - * That's because when @options come from -blockdev or | ||
71 | - * blockdev_add, members are typed according to the QAPI schema, | ||
72 | - * but when they come from -drive, they're all QString. The | ||
73 | - * visitor expects the former. | ||
74 | - */ | ||
75 | - iv = qobject_input_visitor_new(crumpled_server); | ||
76 | + iv = qobject_input_visitor_new_keyval(crumpled_server); | ||
77 | visit_type_SocketAddress(iv, NULL, &saddr, &local_err); | ||
78 | if (local_err) { | ||
79 | error_propagate(errp, local_err); | ||
80 | diff --git a/block/ssh.c b/block/ssh.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/block/ssh.c | ||
83 | +++ b/block/ssh.c | ||
84 | @@ -XXX,XX +XXX,XX @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp) | ||
85 | } | ||
86 | |||
87 | /* Create the QAPI object */ | ||
88 | - crumpled = qdict_crumple(options, errp); | ||
89 | + crumpled = qdict_crumple_for_keyval_qiv(options, errp); | ||
90 | if (crumpled == NULL) { | ||
91 | goto fail; | ||
92 | } | ||
93 | |||
94 | - /* | ||
95 | - * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive. | ||
96 | - * .to doesn't matter, it's ignored anyway. | ||
97 | - * That's because when @options come from -blockdev or | ||
98 | - * blockdev_add, members are typed according to the QAPI schema, | ||
99 | - * but when they come from -drive, they're all QString. The | ||
100 | - * visitor expects the former. | ||
101 | - */ | ||
102 | - v = qobject_input_visitor_new(crumpled); | ||
103 | + v = qobject_input_visitor_new_keyval(crumpled); | ||
104 | visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err); | ||
105 | visit_free(v); | ||
106 | qobject_unref(crumpled); | ||
107 | -- | 90 | -- |
108 | 2.13.6 | 91 | 2.48.1 |
109 | |||
110 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 3 | With IOThread Virtqueue Mapping there will be multiple AioContexts |
4 | processing SCSI requests. scsi_req_cancel() and other SCSI request | ||
5 | operations must be performed from the AioContext where the request is | ||
6 | running. | ||
7 | |||
8 | Introduce a virtio_scsi_defer_tmf_to_aio_context() function and the | ||
9 | necessary VirtIOSCSIReq->remaining refcount infrastructure to move the | ||
10 | TMF code into the AioContext where the request is running. | ||
11 | |||
12 | For the time being there is still just one AioContext: the main loop or | ||
13 | the IOThread. When the iothread-vq-mapping parameter is added in a later | ||
14 | patch this will be changed to per-virtqueue AioContexts. | ||
15 | |||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 17 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
18 | Message-ID: <20250311132616.1049687-8-stefanha@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 19 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | --- | 20 | --- |
7 | tests/check-block-qdict.c | 57 ++++++++++++++++++++++++----------------------- | 21 | hw/scsi/virtio-scsi.c | 270 ++++++++++++++++++++++++++++++++---------- |
8 | 1 file changed, 29 insertions(+), 28 deletions(-) | 22 | 1 file changed, 206 insertions(+), 64 deletions(-) |
9 | 23 | ||
10 | diff --git a/tests/check-block-qdict.c b/tests/check-block-qdict.c | 24 | diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c |
11 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tests/check-block-qdict.c | 26 | --- a/hw/scsi/virtio-scsi.c |
13 | +++ b/tests/check-block-qdict.c | 27 | +++ b/hw/scsi/virtio-scsi.c |
14 | @@ -XXX,XX +XXX,XX @@ static void qdict_defaults_test(void) | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct VirtIOSCSIReq { |
15 | 29 | /* Used for two-stage request submission and TMFs deferred to BH */ | |
16 | static void qdict_flatten_test(void) | 30 | QTAILQ_ENTRY(VirtIOSCSIReq) next; |
31 | |||
32 | - /* Used for cancellation of request during TMFs */ | ||
33 | + /* Used for cancellation of request during TMFs. Atomic. */ | ||
34 | int remaining; | ||
35 | |||
36 | SCSIRequest *sreq; | ||
37 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
38 | VirtIOSCSIReq *tmf_req; | ||
39 | } VirtIOSCSICancelNotifier; | ||
40 | |||
41 | +static void virtio_scsi_tmf_dec_remaining(VirtIOSCSIReq *tmf) | ||
42 | +{ | ||
43 | + if (qatomic_fetch_dec(&tmf->remaining) == 1) { | ||
44 | + trace_virtio_scsi_tmf_resp(virtio_scsi_get_lun(tmf->req.tmf.lun), | ||
45 | + tmf->req.tmf.tag, tmf->resp.tmf.response); | ||
46 | + | ||
47 | + virtio_scsi_complete_req(tmf, &tmf->dev->ctrl_lock); | ||
48 | + } | ||
49 | +} | ||
50 | + | ||
51 | static void virtio_scsi_cancel_notify(Notifier *notifier, void *data) | ||
17 | { | 52 | { |
18 | - QList *list1 = qlist_new(); | 53 | VirtIOSCSICancelNotifier *n = container_of(notifier, |
19 | - QList *list2 = qlist_new(); | 54 | VirtIOSCSICancelNotifier, |
20 | - QDict *dict1 = qdict_new(); | 55 | notifier); |
21 | - QDict *dict2 = qdict_new(); | 56 | |
22 | - QDict *dict3 = qdict_new(); | 57 | - if (--n->tmf_req->remaining == 0) { |
23 | + QList *e_1 = qlist_new(); | 58 | - VirtIOSCSIReq *req = n->tmf_req; |
24 | + QList *e = qlist_new(); | 59 | - |
25 | + QDict *e_1_2 = qdict_new(); | 60 | - trace_virtio_scsi_tmf_resp(virtio_scsi_get_lun(req->req.tmf.lun), |
26 | + QDict *f = qdict_new(); | 61 | - req->req.tmf.tag, req->resp.tmf.response); |
27 | + QDict *root = qdict_new(); | 62 | - virtio_scsi_complete_req(req, &req->dev->ctrl_lock); |
28 | 63 | - } | |
29 | /* | 64 | + virtio_scsi_tmf_dec_remaining(n->tmf_req); |
30 | * Test the flattening of | 65 | g_free(n); |
31 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | ||
32 | * } | ||
33 | */ | ||
34 | |||
35 | - qdict_put_int(dict1, "a", 0); | ||
36 | - qdict_put_int(dict1, "b", 1); | ||
37 | + qdict_put_int(e_1_2, "a", 0); | ||
38 | + qdict_put_int(e_1_2, "b", 1); | ||
39 | |||
40 | - qlist_append_int(list1, 23); | ||
41 | - qlist_append_int(list1, 66); | ||
42 | - qlist_append(list1, dict1); | ||
43 | - qlist_append_int(list2, 42); | ||
44 | - qlist_append(list2, list1); | ||
45 | + qlist_append_int(e_1, 23); | ||
46 | + qlist_append_int(e_1, 66); | ||
47 | + qlist_append(e_1, e_1_2); | ||
48 | + qlist_append_int(e, 42); | ||
49 | + qlist_append(e, e_1); | ||
50 | |||
51 | - qdict_put_int(dict2, "c", 2); | ||
52 | - qdict_put_int(dict2, "d", 3); | ||
53 | - qdict_put(dict3, "e", list2); | ||
54 | - qdict_put(dict3, "f", dict2); | ||
55 | - qdict_put_int(dict3, "g", 4); | ||
56 | + qdict_put_int(f, "c", 2); | ||
57 | + qdict_put_int(f, "d", 3); | ||
58 | |||
59 | - qdict_flatten(dict3); | ||
60 | + qdict_put(root, "e", e); | ||
61 | + qdict_put(root, "f", f); | ||
62 | + qdict_put_int(root, "g", 4); | ||
63 | |||
64 | - g_assert(qdict_get_int(dict3, "e.0") == 42); | ||
65 | - g_assert(qdict_get_int(dict3, "e.1.0") == 23); | ||
66 | - g_assert(qdict_get_int(dict3, "e.1.1") == 66); | ||
67 | - g_assert(qdict_get_int(dict3, "e.1.2.a") == 0); | ||
68 | - g_assert(qdict_get_int(dict3, "e.1.2.b") == 1); | ||
69 | - g_assert(qdict_get_int(dict3, "f.c") == 2); | ||
70 | - g_assert(qdict_get_int(dict3, "f.d") == 3); | ||
71 | - g_assert(qdict_get_int(dict3, "g") == 4); | ||
72 | + qdict_flatten(root); | ||
73 | |||
74 | - g_assert(qdict_size(dict3) == 8); | ||
75 | + g_assert(qdict_get_int(root, "e.0") == 42); | ||
76 | + g_assert(qdict_get_int(root, "e.1.0") == 23); | ||
77 | + g_assert(qdict_get_int(root, "e.1.1") == 66); | ||
78 | + g_assert(qdict_get_int(root, "e.1.2.a") == 0); | ||
79 | + g_assert(qdict_get_int(root, "e.1.2.b") == 1); | ||
80 | + g_assert(qdict_get_int(root, "f.c") == 2); | ||
81 | + g_assert(qdict_get_int(root, "f.d") == 3); | ||
82 | + g_assert(qdict_get_int(root, "g") == 4); | ||
83 | |||
84 | - qobject_unref(dict3); | ||
85 | + g_assert(qdict_size(root) == 8); | ||
86 | + | ||
87 | + qobject_unref(root); | ||
88 | } | 66 | } |
89 | 67 | ||
90 | static void qdict_array_split_test(void) | 68 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_reset_tmf_bh(VirtIOSCSI *s) |
69 | } | ||
70 | } | ||
71 | |||
72 | -static void virtio_scsi_defer_tmf_to_bh(VirtIOSCSIReq *req) | ||
73 | +static void virtio_scsi_defer_tmf_to_main_loop(VirtIOSCSIReq *req) | ||
74 | { | ||
75 | VirtIOSCSI *s = req->dev; | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_defer_tmf_to_bh(VirtIOSCSIReq *req) | ||
78 | } | ||
79 | } | ||
80 | |||
81 | +static void virtio_scsi_tmf_cancel_req(VirtIOSCSIReq *tmf, SCSIRequest *r) | ||
82 | +{ | ||
83 | + VirtIOSCSICancelNotifier *notifier; | ||
84 | + | ||
85 | + assert(r->ctx == qemu_get_current_aio_context()); | ||
86 | + | ||
87 | + /* Decremented in virtio_scsi_cancel_notify() */ | ||
88 | + qatomic_inc(&tmf->remaining); | ||
89 | + | ||
90 | + notifier = g_new(VirtIOSCSICancelNotifier, 1); | ||
91 | + notifier->notifier.notify = virtio_scsi_cancel_notify; | ||
92 | + notifier->tmf_req = tmf; | ||
93 | + scsi_req_cancel_async(r, ¬ifier->notifier); | ||
94 | +} | ||
95 | + | ||
96 | +/* Execute a TMF on the requests in the current AioContext */ | ||
97 | +static void virtio_scsi_do_tmf_aio_context(void *opaque) | ||
98 | +{ | ||
99 | + AioContext *ctx = qemu_get_current_aio_context(); | ||
100 | + VirtIOSCSIReq *tmf = opaque; | ||
101 | + VirtIOSCSI *s = tmf->dev; | ||
102 | + SCSIDevice *d = virtio_scsi_device_get(s, tmf->req.tmf.lun); | ||
103 | + SCSIRequest *r; | ||
104 | + bool match_tag; | ||
105 | + | ||
106 | + if (!d) { | ||
107 | + tmf->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET; | ||
108 | + virtio_scsi_tmf_dec_remaining(tmf); | ||
109 | + return; | ||
110 | + } | ||
111 | + | ||
112 | + /* | ||
113 | + * This function could handle other subtypes that need to be processed in | ||
114 | + * the request's AioContext in the future, but for now only request | ||
115 | + * cancelation subtypes are performed here. | ||
116 | + */ | ||
117 | + switch (tmf->req.tmf.subtype) { | ||
118 | + case VIRTIO_SCSI_T_TMF_ABORT_TASK: | ||
119 | + match_tag = true; | ||
120 | + break; | ||
121 | + case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: | ||
122 | + case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: | ||
123 | + match_tag = false; | ||
124 | + break; | ||
125 | + default: | ||
126 | + g_assert_not_reached(); | ||
127 | + } | ||
128 | + | ||
129 | + WITH_QEMU_LOCK_GUARD(&d->requests_lock) { | ||
130 | + QTAILQ_FOREACH(r, &d->requests, next) { | ||
131 | + VirtIOSCSIReq *cmd_req = r->hba_private; | ||
132 | + assert(cmd_req); /* request has hba_private while enqueued */ | ||
133 | + | ||
134 | + if (r->ctx != ctx) { | ||
135 | + continue; | ||
136 | + } | ||
137 | + if (match_tag && cmd_req->req.cmd.tag != tmf->req.tmf.tag) { | ||
138 | + continue; | ||
139 | + } | ||
140 | + virtio_scsi_tmf_cancel_req(tmf, r); | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + /* Incremented by virtio_scsi_do_tmf() */ | ||
145 | + virtio_scsi_tmf_dec_remaining(tmf); | ||
146 | + | ||
147 | + object_unref(d); | ||
148 | +} | ||
149 | + | ||
150 | +static void dummy_bh(void *opaque) | ||
151 | +{ | ||
152 | + /* Do nothing */ | ||
153 | +} | ||
154 | + | ||
155 | +/* | ||
156 | + * Wait for pending virtio_scsi_defer_tmf_to_aio_context() BHs. | ||
157 | + */ | ||
158 | +static void virtio_scsi_flush_defer_tmf_to_aio_context(VirtIOSCSI *s) | ||
159 | +{ | ||
160 | + GLOBAL_STATE_CODE(); | ||
161 | + | ||
162 | + assert(!s->dataplane_started); | ||
163 | + | ||
164 | + if (s->ctx) { | ||
165 | + /* Our BH only runs after previously scheduled BHs */ | ||
166 | + aio_wait_bh_oneshot(s->ctx, dummy_bh, NULL); | ||
167 | + } | ||
168 | +} | ||
169 | + | ||
170 | +/* | ||
171 | + * Run the TMF in a specific AioContext, handling only requests in that | ||
172 | + * AioContext. This is necessary because requests can run in different | ||
173 | + * AioContext and it is only possible to cancel them from the AioContext where | ||
174 | + * they are running. | ||
175 | + */ | ||
176 | +static void virtio_scsi_defer_tmf_to_aio_context(VirtIOSCSIReq *tmf, | ||
177 | + AioContext *ctx) | ||
178 | +{ | ||
179 | + /* Decremented in virtio_scsi_do_tmf_aio_context() */ | ||
180 | + qatomic_inc(&tmf->remaining); | ||
181 | + | ||
182 | + /* See virtio_scsi_flush_defer_tmf_to_aio_context() cleanup during reset */ | ||
183 | + aio_bh_schedule_oneshot(ctx, virtio_scsi_do_tmf_aio_context, tmf); | ||
184 | +} | ||
185 | + | ||
186 | +/* | ||
187 | + * Returns the AioContext for a given TMF's tag field or NULL. Note that the | ||
188 | + * request identified by the tag may have completed by the time you can execute | ||
189 | + * a BH in the AioContext, so don't assume the request still exists in your BH. | ||
190 | + */ | ||
191 | +static AioContext *find_aio_context_for_tmf_tag(SCSIDevice *d, | ||
192 | + VirtIOSCSIReq *tmf) | ||
193 | +{ | ||
194 | + WITH_QEMU_LOCK_GUARD(&d->requests_lock) { | ||
195 | + SCSIRequest *r; | ||
196 | + SCSIRequest *next; | ||
197 | + | ||
198 | + QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | ||
199 | + VirtIOSCSIReq *cmd_req = r->hba_private; | ||
200 | + | ||
201 | + /* hba_private is non-NULL while the request is enqueued */ | ||
202 | + assert(cmd_req); | ||
203 | + | ||
204 | + if (cmd_req->req.cmd.tag == tmf->req.tmf.tag) { | ||
205 | + return r->ctx; | ||
206 | + } | ||
207 | + } | ||
208 | + } | ||
209 | + return NULL; | ||
210 | +} | ||
211 | + | ||
212 | /* Return 0 if the request is ready to be completed and return to guest; | ||
213 | * -EINPROGRESS if the request is submitted and will be completed later, in the | ||
214 | * case of async cancellation. */ | ||
215 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
216 | { | ||
217 | SCSIDevice *d = virtio_scsi_device_get(s, req->req.tmf.lun); | ||
218 | SCSIRequest *r, *next; | ||
219 | + AioContext *ctx; | ||
220 | int ret = 0; | ||
221 | |||
222 | virtio_scsi_ctx_check(s, d); | ||
223 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
224 | req->req.tmf.tag, req->req.tmf.subtype); | ||
225 | |||
226 | switch (req->req.tmf.subtype) { | ||
227 | - case VIRTIO_SCSI_T_TMF_ABORT_TASK: | ||
228 | - case VIRTIO_SCSI_T_TMF_QUERY_TASK: | ||
229 | + case VIRTIO_SCSI_T_TMF_ABORT_TASK: { | ||
230 | if (!d) { | ||
231 | goto fail; | ||
232 | } | ||
233 | if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { | ||
234 | goto incorrect_lun; | ||
235 | } | ||
236 | - QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | ||
237 | - VirtIOSCSIReq *cmd_req = r->hba_private; | ||
238 | - if (cmd_req && cmd_req->req.cmd.tag == req->req.tmf.tag) { | ||
239 | - break; | ||
240 | - } | ||
241 | + | ||
242 | + ctx = find_aio_context_for_tmf_tag(d, req); | ||
243 | + if (ctx) { | ||
244 | + virtio_scsi_defer_tmf_to_aio_context(req, ctx); | ||
245 | + ret = -EINPROGRESS; | ||
246 | } | ||
247 | - if (r) { | ||
248 | - /* | ||
249 | - * Assert that the request has not been completed yet, we | ||
250 | - * check for it in the loop above. | ||
251 | - */ | ||
252 | - assert(r->hba_private); | ||
253 | - if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK) { | ||
254 | - /* "If the specified command is present in the task set, then | ||
255 | - * return a service response set to FUNCTION SUCCEEDED". | ||
256 | - */ | ||
257 | - req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; | ||
258 | - } else { | ||
259 | - VirtIOSCSICancelNotifier *notifier; | ||
260 | - | ||
261 | - req->remaining = 1; | ||
262 | - notifier = g_new(VirtIOSCSICancelNotifier, 1); | ||
263 | - notifier->tmf_req = req; | ||
264 | - notifier->notifier.notify = virtio_scsi_cancel_notify; | ||
265 | - scsi_req_cancel_async(r, ¬ifier->notifier); | ||
266 | - ret = -EINPROGRESS; | ||
267 | + break; | ||
268 | + } | ||
269 | + | ||
270 | + case VIRTIO_SCSI_T_TMF_QUERY_TASK: | ||
271 | + if (!d) { | ||
272 | + goto fail; | ||
273 | + } | ||
274 | + if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { | ||
275 | + goto incorrect_lun; | ||
276 | + } | ||
277 | + | ||
278 | + WITH_QEMU_LOCK_GUARD(&d->requests_lock) { | ||
279 | + QTAILQ_FOREACH(r, &d->requests, next) { | ||
280 | + VirtIOSCSIReq *cmd_req = r->hba_private; | ||
281 | + assert(cmd_req); /* request has hba_private while enqueued */ | ||
282 | + | ||
283 | + if (cmd_req->req.cmd.tag == req->req.tmf.tag) { | ||
284 | + /* | ||
285 | + * "If the specified command is present in the task set, | ||
286 | + * then return a service response set to FUNCTION | ||
287 | + * SUCCEEDED". | ||
288 | + */ | ||
289 | + req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; | ||
290 | + } | ||
291 | } | ||
292 | } | ||
293 | break; | ||
294 | |||
295 | case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: | ||
296 | case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: | ||
297 | - virtio_scsi_defer_tmf_to_bh(req); | ||
298 | + virtio_scsi_defer_tmf_to_main_loop(req); | ||
299 | ret = -EINPROGRESS; | ||
300 | break; | ||
301 | |||
302 | case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: | ||
303 | - case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: | ||
304 | + case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: { | ||
305 | + if (!d) { | ||
306 | + goto fail; | ||
307 | + } | ||
308 | + if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { | ||
309 | + goto incorrect_lun; | ||
310 | + } | ||
311 | + | ||
312 | + qatomic_inc(&req->remaining); | ||
313 | + | ||
314 | + ctx = s->ctx ?: qemu_get_aio_context(); | ||
315 | + virtio_scsi_defer_tmf_to_aio_context(req, ctx); | ||
316 | + | ||
317 | + virtio_scsi_tmf_dec_remaining(req); | ||
318 | + ret = -EINPROGRESS; | ||
319 | + break; | ||
320 | + } | ||
321 | + | ||
322 | case VIRTIO_SCSI_T_TMF_QUERY_TASK_SET: | ||
323 | if (!d) { | ||
324 | goto fail; | ||
325 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
326 | goto incorrect_lun; | ||
327 | } | ||
328 | |||
329 | - /* Add 1 to "remaining" until virtio_scsi_do_tmf returns. | ||
330 | - * This way, if the bus starts calling back to the notifiers | ||
331 | - * even before we finish the loop, virtio_scsi_cancel_notify | ||
332 | - * will not complete the TMF too early. | ||
333 | - */ | ||
334 | - req->remaining = 1; | ||
335 | - QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | ||
336 | - if (r->hba_private) { | ||
337 | - if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK_SET) { | ||
338 | - /* "If there is any command present in the task set, then | ||
339 | - * return a service response set to FUNCTION SUCCEEDED". | ||
340 | - */ | ||
341 | - req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; | ||
342 | - break; | ||
343 | - } else { | ||
344 | - VirtIOSCSICancelNotifier *notifier; | ||
345 | - | ||
346 | - req->remaining++; | ||
347 | - notifier = g_new(VirtIOSCSICancelNotifier, 1); | ||
348 | - notifier->notifier.notify = virtio_scsi_cancel_notify; | ||
349 | - notifier->tmf_req = req; | ||
350 | - scsi_req_cancel_async(r, ¬ifier->notifier); | ||
351 | - } | ||
352 | + WITH_QEMU_LOCK_GUARD(&d->requests_lock) { | ||
353 | + QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | ||
354 | + /* Request has hba_private while enqueued */ | ||
355 | + assert(r->hba_private); | ||
356 | + | ||
357 | + /* | ||
358 | + * "If there is any command present in the task set, then | ||
359 | + * return a service response set to FUNCTION SUCCEEDED". | ||
360 | + */ | ||
361 | + req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; | ||
362 | + break; | ||
363 | } | ||
364 | } | ||
365 | - if (--req->remaining > 0) { | ||
366 | - ret = -EINPROGRESS; | ||
367 | - } | ||
368 | break; | ||
369 | |||
370 | case VIRTIO_SCSI_T_TMF_CLEAR_ACA: | ||
371 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_reset(VirtIODevice *vdev) | ||
372 | assert(!s->dataplane_started); | ||
373 | |||
374 | virtio_scsi_reset_tmf_bh(s); | ||
375 | + virtio_scsi_flush_defer_tmf_to_aio_context(s); | ||
376 | |||
377 | qatomic_inc(&s->resetting); | ||
378 | bus_cold_reset(BUS(&s->bus)); | ||
91 | -- | 379 | -- |
92 | 2.13.6 | 380 | 2.48.1 |
93 | |||
94 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Configuration flows through the block subsystem in a rather peculiar | 3 | This is the cleanup function that must be called after |
4 | way. Configuration made with -drive enters it as QemuOpts. | 4 | apply_iothread_vq_mapping() succeeds. virtio-scsi will need this |
5 | Configuration made with -blockdev / blockdev-add enters it as QAPI | 5 | function too, so extract it. |
6 | type BlockdevOptions. The block subsystem uses QDict, QemuOpts and | ||
7 | QAPI types internally. The precise flow is next to impossible to | ||
8 | explain (I tried for this commit message, but gave up after wasting | ||
9 | several hours). What I can explain is a flaw in the BlockDriver | ||
10 | interface that leads to this bug: | ||
11 | 6 | ||
12 | $ qemu-system-x86_64 -blockdev node-name=n1,driver=nfs,server.type=inet,server.host=localhost,path=/foo/bar,user=1234 | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | qemu-system-x86_64: -blockdev node-name=n1,driver=nfs,server.type=inet,server.host=localhost,path=/foo/bar,user=1234: Internal error: parameter user invalid | ||
14 | |||
15 | QMP blockdev-add is broken the same way. | ||
16 | |||
17 | Here's what happens. The block layer passes configuration represented | ||
18 | as flat QDict (with dotted keys) to BlockDriver methods | ||
19 | .bdrv_file_open(). The QDict's members are typed according to the | ||
20 | QAPI schema. | ||
21 | |||
22 | nfs_file_open() converts it to QAPI type BlockdevOptionsNfs, with | ||
23 | qdict_crumple() and a qobject input visitor. | ||
24 | |||
25 | This visitor comes in two flavors. The plain flavor requires scalars | ||
26 | to be typed according to the QAPI schema. That's the case here. The | ||
27 | keyval flavor requires string scalars. That's not the case here. | ||
28 | nfs_file_open() uses the latter, and promptly falls apart for members | ||
29 | @user, @group, @tcp-syn-count, @readahead-size, @page-cache-size, | ||
30 | @debug. | ||
31 | |||
32 | Switching to the plain flavor would fix -blockdev, but break -drive, | ||
33 | because there the scalars arrive in nfs_file_open() as strings. | ||
34 | |||
35 | The proper fix would be to replace the QDict by QAPI type | ||
36 | BlockdevOptions in the BlockDriver interface. Sadly, that's beyond my | ||
37 | reach right now. | ||
38 | |||
39 | Next best would be to fix the block layer to always pass correctly | ||
40 | typed QDicts to the BlockDriver methods. Also beyond my reach. | ||
41 | |||
42 | What I can do is throw another hack onto the pile: have | ||
43 | nfs_file_open() convert all members to string, so use of the keyval | ||
44 | flavor actually works, by replacing qdict_crumple() by new function | ||
45 | qdict_crumple_for_keyval_qiv(). | ||
46 | |||
47 | The pattern "pass result of qdict_crumple() to | ||
48 | qobject_input_visitor_new_keyval()" occurs several times more: | ||
49 | |||
50 | * qemu_rbd_open() | ||
51 | |||
52 | Same issue as nfs_file_open(), but since BlockdevOptionsRbd has only | ||
53 | string members, its only a latent bug. Fix it anyway. | ||
54 | |||
55 | * parallels_co_create_opts(), qcow_co_create_opts(), | ||
56 | qcow2_co_create_opts(), bdrv_qed_co_create_opts(), | ||
57 | sd_co_create_opts(), vhdx_co_create_opts(), vpc_co_create_opts() | ||
58 | |||
59 | These work, because they create the QDict with | ||
60 | qemu_opts_to_qdict_filtered(), which creates only string scalars. | ||
61 | The function sports a TODO comment asking for better typing; that's | ||
62 | going to be fun. Use qdict_crumple_for_keyval_qiv() to be safe. | ||
63 | |||
64 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
65 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
9 | Message-ID: <20250311132616.1049687-9-stefanha@redhat.com> | ||
66 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
67 | --- | 11 | --- |
68 | include/block/qdict.h | 1 + | 12 | hw/block/virtio-blk.c | 27 +++++++++++++++++++++------ |
69 | block/nfs.c | 2 +- | 13 | 1 file changed, 21 insertions(+), 6 deletions(-) |
70 | block/parallels.c | 2 +- | ||
71 | block/qcow.c | 2 +- | ||
72 | block/qcow2.c | 2 +- | ||
73 | block/qed.c | 2 +- | ||
74 | block/rbd.c | 2 +- | ||
75 | block/sheepdog.c | 2 +- | ||
76 | block/vhdx.c | 2 +- | ||
77 | block/vpc.c | 2 +- | ||
78 | qobject/block-qdict.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
79 | 11 files changed, 67 insertions(+), 9 deletions(-) | ||
80 | 14 | ||
81 | diff --git a/include/block/qdict.h b/include/block/qdict.h | 15 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
82 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
83 | --- a/include/block/qdict.h | 17 | --- a/hw/block/virtio-blk.c |
84 | +++ b/include/block/qdict.h | 18 | +++ b/hw/block/virtio-blk.c |
85 | @@ -XXX,XX +XXX,XX @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); | 19 | @@ -XXX,XX +XXX,XX @@ validate_iothread_vq_mapping_list(IOThreadVirtQueueMappingList *list, |
86 | void qdict_array_split(QDict *src, QList **dst); | 20 | * Fill in the AioContext for each virtqueue in the @vq_aio_context array given |
87 | int qdict_array_entries(QDict *src, const char *subqdict); | 21 | * the iothread-vq-mapping parameter in @iothread_vq_mapping_list. |
88 | QObject *qdict_crumple(const QDict *src, Error **errp); | 22 | * |
89 | +QObject *qdict_crumple_for_keyval_qiv(QDict *qdict, Error **errp); | 23 | + * cleanup_iothread_vq_mapping() must be called to free IOThread object |
90 | void qdict_flatten(QDict *qdict); | 24 | + * references after this function returns success. |
91 | 25 | + * | |
92 | typedef struct QDictRenames { | 26 | * Returns: %true on success, %false on failure. |
93 | diff --git a/block/nfs.c b/block/nfs.c | 27 | **/ |
94 | index XXXXXXX..XXXXXXX 100644 | 28 | static bool apply_iothread_vq_mapping( |
95 | --- a/block/nfs.c | 29 | @@ -XXX,XX +XXX,XX @@ static bool apply_iothread_vq_mapping( |
96 | +++ b/block/nfs.c | 30 | return true; |
97 | @@ -XXX,XX +XXX,XX @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options, | ||
98 | const QDictEntry *e; | ||
99 | Error *local_err = NULL; | ||
100 | |||
101 | - crumpled = qdict_crumple(options, errp); | ||
102 | + crumpled = qdict_crumple_for_keyval_qiv(options, errp); | ||
103 | if (crumpled == NULL) { | ||
104 | return NULL; | ||
105 | } | ||
106 | diff --git a/block/parallels.c b/block/parallels.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/block/parallels.c | ||
109 | +++ b/block/parallels.c | ||
110 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create_opts(const char *filename, | ||
111 | qdict_put_str(qdict, "driver", "parallels"); | ||
112 | qdict_put_str(qdict, "file", bs->node_name); | ||
113 | |||
114 | - qobj = qdict_crumple(qdict, errp); | ||
115 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
116 | qobject_unref(qdict); | ||
117 | qdict = qobject_to(QDict, qobj); | ||
118 | if (qdict == NULL) { | ||
119 | diff --git a/block/qcow.c b/block/qcow.c | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/block/qcow.c | ||
122 | +++ b/block/qcow.c | ||
123 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create_opts(const char *filename, | ||
124 | qdict_put_str(qdict, "driver", "qcow"); | ||
125 | qdict_put_str(qdict, "file", bs->node_name); | ||
126 | |||
127 | - qobj = qdict_crumple(qdict, errp); | ||
128 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
129 | qobject_unref(qdict); | ||
130 | qdict = qobject_to(QDict, qobj); | ||
131 | if (qdict == NULL) { | ||
132 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/block/qcow2.c | ||
135 | +++ b/block/qcow2.c | ||
136 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt | ||
137 | qdict_put_str(qdict, "file", bs->node_name); | ||
138 | |||
139 | /* Now get the QAPI type BlockdevCreateOptions */ | ||
140 | - qobj = qdict_crumple(qdict, errp); | ||
141 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
142 | qobject_unref(qdict); | ||
143 | qdict = qobject_to(QDict, qobj); | ||
144 | if (qdict == NULL) { | ||
145 | diff --git a/block/qed.c b/block/qed.c | ||
146 | index XXXXXXX..XXXXXXX 100644 | ||
147 | --- a/block/qed.c | ||
148 | +++ b/block/qed.c | ||
149 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, | ||
150 | qdict_put_str(qdict, "driver", "qed"); | ||
151 | qdict_put_str(qdict, "file", bs->node_name); | ||
152 | |||
153 | - qobj = qdict_crumple(qdict, errp); | ||
154 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
155 | qobject_unref(qdict); | ||
156 | qdict = qobject_to(QDict, qobj); | ||
157 | if (qdict == NULL) { | ||
158 | diff --git a/block/rbd.c b/block/rbd.c | ||
159 | index XXXXXXX..XXXXXXX 100644 | ||
160 | --- a/block/rbd.c | ||
161 | +++ b/block/rbd.c | ||
162 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
163 | } | ||
164 | |||
165 | /* Convert the remaining options into a QAPI object */ | ||
166 | - crumpled = qdict_crumple(options, errp); | ||
167 | + crumpled = qdict_crumple_for_keyval_qiv(options, errp); | ||
168 | if (crumpled == NULL) { | ||
169 | r = -EINVAL; | ||
170 | goto out; | ||
171 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/block/sheepdog.c | ||
174 | +++ b/block/sheepdog.c | ||
175 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts, | ||
176 | } | ||
177 | |||
178 | /* Get the QAPI object */ | ||
179 | - crumpled = qdict_crumple(qdict, errp); | ||
180 | + crumpled = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
181 | if (crumpled == NULL) { | ||
182 | ret = -EINVAL; | ||
183 | goto fail; | ||
184 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
185 | index XXXXXXX..XXXXXXX 100644 | ||
186 | --- a/block/vhdx.c | ||
187 | +++ b/block/vhdx.c | ||
188 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create_opts(const char *filename, | ||
189 | qdict_put_str(qdict, "driver", "vhdx"); | ||
190 | qdict_put_str(qdict, "file", bs->node_name); | ||
191 | |||
192 | - qobj = qdict_crumple(qdict, errp); | ||
193 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
194 | qobject_unref(qdict); | ||
195 | qdict = qobject_to(QDict, qobj); | ||
196 | if (qdict == NULL) { | ||
197 | diff --git a/block/vpc.c b/block/vpc.c | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/block/vpc.c | ||
200 | +++ b/block/vpc.c | ||
201 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_create_opts(const char *filename, | ||
202 | qdict_put_str(qdict, "driver", "vpc"); | ||
203 | qdict_put_str(qdict, "file", bs->node_name); | ||
204 | |||
205 | - qobj = qdict_crumple(qdict, errp); | ||
206 | + qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
207 | qobject_unref(qdict); | ||
208 | qdict = qobject_to(QDict, qobj); | ||
209 | if (qdict == NULL) { | ||
210 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | ||
211 | index XXXXXXX..XXXXXXX 100644 | ||
212 | --- a/qobject/block-qdict.c | ||
213 | +++ b/qobject/block-qdict.c | ||
214 | @@ -XXX,XX +XXX,XX @@ | ||
215 | |||
216 | #include "qemu/osdep.h" | ||
217 | #include "block/qdict.h" | ||
218 | +#include "qapi/qmp/qbool.h" | ||
219 | #include "qapi/qmp/qlist.h" | ||
220 | +#include "qapi/qmp/qnum.h" | ||
221 | +#include "qapi/qmp/qstring.h" | ||
222 | #include "qemu/cutils.h" | ||
223 | #include "qapi/error.h" | ||
224 | |||
225 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | ||
226 | } | 31 | } |
227 | 32 | ||
228 | /** | 33 | +/** |
229 | + * qdict_crumple_for_keyval_qiv: | 34 | + * cleanup_iothread_vq_mapping: |
230 | + * @src: the flat dictionary (only scalar values) to crumple | 35 | + * @list: The mapping of virtqueues to IOThreads. |
231 | + * @errp: location to store error | ||
232 | + * | 36 | + * |
233 | + * Like qdict_crumple(), but additionally transforms scalar values so | 37 | + * Release IOThread object references that were acquired by |
234 | + * the result can be passed to qobject_input_visitor_new_keyval(). | 38 | + * apply_iothread_vq_mapping(). |
235 | + * | ||
236 | + * The block subsystem uses this function to prepare its flat QDict | ||
237 | + * with possibly confused scalar types for a visit. It should not be | ||
238 | + * used for anything else, and it should go away once the block | ||
239 | + * subsystem has been cleaned up. | ||
240 | + */ | 39 | + */ |
241 | +QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp) | 40 | +static void cleanup_iothread_vq_mapping(IOThreadVirtQueueMappingList *list) |
242 | +{ | 41 | +{ |
243 | + QDict *tmp = NULL; | 42 | + IOThreadVirtQueueMappingList *node; |
244 | + char *buf; | ||
245 | + const char *s; | ||
246 | + const QDictEntry *ent; | ||
247 | + QObject *dst; | ||
248 | + | 43 | + |
249 | + for (ent = qdict_first(src); ent; ent = qdict_next(src, ent)) { | 44 | + for (node = list; node; node = node->next) { |
250 | + buf = NULL; | 45 | + IOThread *iothread = iothread_by_id(node->value->iothread); |
251 | + switch (qobject_type(ent->value)) { | 46 | + object_unref(OBJECT(iothread)); |
252 | + case QTYPE_QNULL: | ||
253 | + case QTYPE_QSTRING: | ||
254 | + continue; | ||
255 | + case QTYPE_QNUM: | ||
256 | + s = buf = qnum_to_string(qobject_to(QNum, ent->value)); | ||
257 | + break; | ||
258 | + case QTYPE_QDICT: | ||
259 | + case QTYPE_QLIST: | ||
260 | + /* @src isn't flat; qdict_crumple() will fail */ | ||
261 | + continue; | ||
262 | + case QTYPE_QBOOL: | ||
263 | + s = qbool_get_bool(qobject_to(QBool, ent->value)) | ||
264 | + ? "on" : "off"; | ||
265 | + break; | ||
266 | + default: | ||
267 | + abort(); | ||
268 | + } | ||
269 | + | ||
270 | + if (!tmp) { | ||
271 | + tmp = qdict_clone_shallow(src); | ||
272 | + } | ||
273 | + qdict_put(tmp, ent->key, qstring_from_str(s)); | ||
274 | + g_free(buf); | ||
275 | + } | 47 | + } |
276 | + | ||
277 | + dst = qdict_crumple(tmp ?: src, errp); | ||
278 | + qobject_unref(tmp); | ||
279 | + return dst; | ||
280 | +} | 48 | +} |
281 | + | 49 | + |
282 | +/** | 50 | /* Context: BQL held */ |
283 | * qdict_array_entries(): Returns the number of direct array entries if the | 51 | static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) |
284 | * sub-QDict of src specified by the prefix in subqdict (or src itself for | 52 | { |
285 | * prefix == "") is valid as an array, i.e. the length of the created list if | 53 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) |
54 | assert(!s->ioeventfd_started); | ||
55 | |||
56 | if (conf->iothread_vq_mapping_list) { | ||
57 | - IOThreadVirtQueueMappingList *node; | ||
58 | - | ||
59 | - for (node = conf->iothread_vq_mapping_list; node; node = node->next) { | ||
60 | - IOThread *iothread = iothread_by_id(node->value->iothread); | ||
61 | - object_unref(OBJECT(iothread)); | ||
62 | - } | ||
63 | + cleanup_iothread_vq_mapping(conf->iothread_vq_mapping_list); | ||
64 | } | ||
65 | |||
66 | if (conf->iothread) { | ||
286 | -- | 67 | -- |
287 | 2.13.6 | 68 | 2.48.1 |
288 | |||
289 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 3 | Use noun_verb() function naming instead of verb_noun() because the |
4 | former is the most common naming style for APIs. The next commit will | ||
5 | move these functions into a header file so that virtio-scsi can call | ||
6 | them. | ||
7 | |||
8 | Shorten iothread_vq_mapping_apply()'s iothread_vq_mapping_list argument | ||
9 | to just "list" like in the other functions. | ||
10 | |||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
13 | Message-ID: <20250311132616.1049687-10-stefanha@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | --- | 15 | --- |
7 | include/block/qdict.h | 3 ++- | 16 | hw/block/virtio-blk.c | 33 ++++++++++++++++----------------- |
8 | block/nbd.c | 7 ++----- | 17 | 1 file changed, 16 insertions(+), 17 deletions(-) |
9 | block/nfs.c | 7 ++----- | ||
10 | block/parallels.c | 7 ++----- | ||
11 | block/qcow.c | 7 ++----- | ||
12 | block/qcow2.c | 7 ++----- | ||
13 | block/qed.c | 7 ++----- | ||
14 | block/rbd.c | 7 ++----- | ||
15 | block/sheepdog.c | 14 ++++---------- | ||
16 | block/ssh.c | 7 ++----- | ||
17 | block/vhdx.c | 7 ++----- | ||
18 | block/vpc.c | 7 ++----- | ||
19 | qobject/block-qdict.c | 28 +++++++++++++++++++++++++++- | ||
20 | 13 files changed, 53 insertions(+), 62 deletions(-) | ||
21 | 18 | ||
22 | diff --git a/include/block/qdict.h b/include/block/qdict.h | 19 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
23 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/block/qdict.h | 21 | --- a/hw/block/virtio-blk.c |
25 | +++ b/include/block/qdict.h | 22 | +++ b/hw/block/virtio-blk.c |
26 | @@ -XXX,XX +XXX,XX @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); | 23 | @@ -XXX,XX +XXX,XX @@ static const BlockDevOps virtio_block_ops = { |
27 | void qdict_array_split(QDict *src, QList **dst); | 24 | }; |
28 | int qdict_array_entries(QDict *src, const char *subqdict); | 25 | |
29 | QObject *qdict_crumple(const QDict *src, Error **errp); | 26 | static bool |
30 | -QObject *qdict_crumple_for_keyval_qiv(QDict *qdict, Error **errp); | 27 | -validate_iothread_vq_mapping_list(IOThreadVirtQueueMappingList *list, |
31 | void qdict_flatten(QDict *qdict); | 28 | - uint16_t num_queues, Error **errp) |
32 | 29 | +iothread_vq_mapping_validate(IOThreadVirtQueueMappingList *list, uint16_t | |
33 | typedef struct QDictRenames { | 30 | + num_queues, Error **errp) |
34 | @@ -XXX,XX +XXX,XX @@ typedef struct QDictRenames { | ||
35 | } QDictRenames; | ||
36 | bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp); | ||
37 | |||
38 | +Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict, | ||
39 | + Error **errp); | ||
40 | #endif | ||
41 | diff --git a/block/nbd.c b/block/nbd.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/block/nbd.c | ||
44 | +++ b/block/nbd.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, | ||
46 | { | 31 | { |
47 | SocketAddress *saddr = NULL; | 32 | g_autofree unsigned long *vqs = bitmap_new(num_queues); |
48 | QDict *addr = NULL; | 33 | g_autoptr(GHashTable) iothreads = |
49 | - QObject *crumpled_addr = NULL; | 34 | @@ -XXX,XX +XXX,XX @@ validate_iothread_vq_mapping_list(IOThreadVirtQueueMappingList *list, |
50 | Visitor *iv = NULL; | 35 | } |
51 | Error *local_err = NULL; | 36 | |
52 | 37 | /** | |
53 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, | 38 | - * apply_iothread_vq_mapping: |
54 | goto done; | 39 | - * @iothread_vq_mapping_list: The mapping of virtqueues to IOThreads. |
40 | + * iothread_vq_mapping_apply: | ||
41 | + * @list: The mapping of virtqueues to IOThreads. | ||
42 | * @vq_aio_context: The array of AioContext pointers to fill in. | ||
43 | * @num_queues: The length of @vq_aio_context. | ||
44 | * @errp: If an error occurs, a pointer to the area to store the error. | ||
45 | * | ||
46 | * Fill in the AioContext for each virtqueue in the @vq_aio_context array given | ||
47 | - * the iothread-vq-mapping parameter in @iothread_vq_mapping_list. | ||
48 | + * the iothread-vq-mapping parameter in @list. | ||
49 | * | ||
50 | - * cleanup_iothread_vq_mapping() must be called to free IOThread object | ||
51 | + * iothread_vq_mapping_cleanup() must be called to free IOThread object | ||
52 | * references after this function returns success. | ||
53 | * | ||
54 | * Returns: %true on success, %false on failure. | ||
55 | **/ | ||
56 | -static bool apply_iothread_vq_mapping( | ||
57 | - IOThreadVirtQueueMappingList *iothread_vq_mapping_list, | ||
58 | +static bool iothread_vq_mapping_apply( | ||
59 | + IOThreadVirtQueueMappingList *list, | ||
60 | AioContext **vq_aio_context, | ||
61 | uint16_t num_queues, | ||
62 | Error **errp) | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool apply_iothread_vq_mapping( | ||
64 | size_t num_iothreads = 0; | ||
65 | size_t cur_iothread = 0; | ||
66 | |||
67 | - if (!validate_iothread_vq_mapping_list(iothread_vq_mapping_list, | ||
68 | - num_queues, errp)) { | ||
69 | + if (!iothread_vq_mapping_validate(list, num_queues, errp)) { | ||
70 | return false; | ||
55 | } | 71 | } |
56 | 72 | ||
57 | - crumpled_addr = qdict_crumple_for_keyval_qiv(addr, errp); | 73 | - for (node = iothread_vq_mapping_list; node; node = node->next) { |
58 | - if (!crumpled_addr) { | 74 | + for (node = list; node; node = node->next) { |
59 | + iv = qobject_input_visitor_new_flat_confused(addr, errp); | 75 | num_iothreads++; |
60 | + if (!iv) { | ||
61 | goto done; | ||
62 | } | 76 | } |
63 | 77 | ||
64 | - iv = qobject_input_visitor_new_keyval(crumpled_addr); | 78 | - for (node = iothread_vq_mapping_list; node; node = node->next) { |
65 | visit_type_SocketAddress(iv, NULL, &saddr, &local_err); | 79 | + for (node = list; node; node = node->next) { |
66 | if (local_err) { | 80 | IOThread *iothread = iothread_by_id(node->value->iothread); |
67 | error_propagate(errp, local_err); | 81 | AioContext *ctx = iothread_get_aio_context(iothread); |
68 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, | 82 | |
69 | 83 | @@ -XXX,XX +XXX,XX @@ static bool apply_iothread_vq_mapping( | |
70 | done: | ||
71 | qobject_unref(addr); | ||
72 | - qobject_unref(crumpled_addr); | ||
73 | visit_free(iv); | ||
74 | return saddr; | ||
75 | } | 84 | } |
76 | diff --git a/block/nfs.c b/block/nfs.c | 85 | |
77 | index XXXXXXX..XXXXXXX 100644 | 86 | /** |
78 | --- a/block/nfs.c | 87 | - * cleanup_iothread_vq_mapping: |
79 | +++ b/block/nfs.c | 88 | + * iothread_vq_mapping_cleanup: |
80 | @@ -XXX,XX +XXX,XX @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options, | 89 | * @list: The mapping of virtqueues to IOThreads. |
81 | Error **errp) | 90 | * |
91 | * Release IOThread object references that were acquired by | ||
92 | - * apply_iothread_vq_mapping(). | ||
93 | + * iothread_vq_mapping_apply(). | ||
94 | */ | ||
95 | -static void cleanup_iothread_vq_mapping(IOThreadVirtQueueMappingList *list) | ||
96 | +static void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) | ||
82 | { | 97 | { |
83 | BlockdevOptionsNfs *opts = NULL; | 98 | IOThreadVirtQueueMappingList *node; |
84 | - QObject *crumpled = NULL; | 99 | |
85 | Visitor *v; | 100 | @@ -XXX,XX +XXX,XX @@ static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) |
86 | const QDictEntry *e; | 101 | s->vq_aio_context = g_new(AioContext *, conf->num_queues); |
87 | Error *local_err = NULL; | 102 | |
88 | 103 | if (conf->iothread_vq_mapping_list) { | |
89 | - crumpled = qdict_crumple_for_keyval_qiv(options, errp); | 104 | - if (!apply_iothread_vq_mapping(conf->iothread_vq_mapping_list, |
90 | - if (crumpled == NULL) { | 105 | + if (!iothread_vq_mapping_apply(conf->iothread_vq_mapping_list, |
91 | + v = qobject_input_visitor_new_flat_confused(options, errp); | 106 | s->vq_aio_context, |
92 | + if (!v) { | 107 | conf->num_queues, |
93 | return NULL; | 108 | errp)) { |
109 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s) | ||
110 | assert(!s->ioeventfd_started); | ||
111 | |||
112 | if (conf->iothread_vq_mapping_list) { | ||
113 | - cleanup_iothread_vq_mapping(conf->iothread_vq_mapping_list); | ||
114 | + iothread_vq_mapping_cleanup(conf->iothread_vq_mapping_list); | ||
94 | } | 115 | } |
95 | 116 | ||
96 | - v = qobject_input_visitor_new_keyval(crumpled); | 117 | if (conf->iothread) { |
97 | visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err); | ||
98 | visit_free(v); | ||
99 | - qobject_unref(crumpled); | ||
100 | |||
101 | if (local_err) { | ||
102 | error_propagate(errp, local_err); | ||
103 | diff --git a/block/parallels.c b/block/parallels.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/block/parallels.c | ||
106 | +++ b/block/parallels.c | ||
107 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create_opts(const char *filename, | ||
108 | Error *local_err = NULL; | ||
109 | BlockDriverState *bs = NULL; | ||
110 | QDict *qdict; | ||
111 | - QObject *qobj; | ||
112 | Visitor *v; | ||
113 | int ret; | ||
114 | |||
115 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create_opts(const char *filename, | ||
116 | qdict_put_str(qdict, "driver", "parallels"); | ||
117 | qdict_put_str(qdict, "file", bs->node_name); | ||
118 | |||
119 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
120 | - if (!qobj) { | ||
121 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
122 | + if (!v) { | ||
123 | ret = -EINVAL; | ||
124 | goto done; | ||
125 | } | ||
126 | |||
127 | - v = qobject_input_visitor_new_keyval(qobj); | ||
128 | - qobject_unref(qobj); | ||
129 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
130 | visit_free(v); | ||
131 | |||
132 | diff --git a/block/qcow.c b/block/qcow.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/block/qcow.c | ||
135 | +++ b/block/qcow.c | ||
136 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create_opts(const char *filename, | ||
137 | BlockdevCreateOptions *create_options = NULL; | ||
138 | BlockDriverState *bs = NULL; | ||
139 | QDict *qdict; | ||
140 | - QObject *qobj; | ||
141 | Visitor *v; | ||
142 | const char *val; | ||
143 | Error *local_err = NULL; | ||
144 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create_opts(const char *filename, | ||
145 | qdict_put_str(qdict, "driver", "qcow"); | ||
146 | qdict_put_str(qdict, "file", bs->node_name); | ||
147 | |||
148 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
149 | - if (!qobj) { | ||
150 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
151 | + if (!v) { | ||
152 | ret = -EINVAL; | ||
153 | goto fail; | ||
154 | } | ||
155 | |||
156 | - v = qobject_input_visitor_new_keyval(qobj); | ||
157 | - qobject_unref(qobj); | ||
158 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
159 | visit_free(v); | ||
160 | |||
161 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/block/qcow2.c | ||
164 | +++ b/block/qcow2.c | ||
165 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt | ||
166 | { | ||
167 | BlockdevCreateOptions *create_options = NULL; | ||
168 | QDict *qdict; | ||
169 | - QObject *qobj; | ||
170 | Visitor *v; | ||
171 | BlockDriverState *bs = NULL; | ||
172 | Error *local_err = NULL; | ||
173 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt | ||
174 | qdict_put_str(qdict, "file", bs->node_name); | ||
175 | |||
176 | /* Now get the QAPI type BlockdevCreateOptions */ | ||
177 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
178 | - if (!qobj) { | ||
179 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
180 | + if (!v) { | ||
181 | ret = -EINVAL; | ||
182 | goto finish; | ||
183 | } | ||
184 | |||
185 | - v = qobject_input_visitor_new_keyval(qobj); | ||
186 | - qobject_unref(qobj); | ||
187 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
188 | visit_free(v); | ||
189 | |||
190 | diff --git a/block/qed.c b/block/qed.c | ||
191 | index XXXXXXX..XXXXXXX 100644 | ||
192 | --- a/block/qed.c | ||
193 | +++ b/block/qed.c | ||
194 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, | ||
195 | { | ||
196 | BlockdevCreateOptions *create_options = NULL; | ||
197 | QDict *qdict; | ||
198 | - QObject *qobj; | ||
199 | Visitor *v; | ||
200 | BlockDriverState *bs = NULL; | ||
201 | Error *local_err = NULL; | ||
202 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename, | ||
203 | qdict_put_str(qdict, "driver", "qed"); | ||
204 | qdict_put_str(qdict, "file", bs->node_name); | ||
205 | |||
206 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
207 | - if (!qobj) { | ||
208 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
209 | + if (!v) { | ||
210 | ret = -EINVAL; | ||
211 | goto fail; | ||
212 | } | ||
213 | |||
214 | - v = qobject_input_visitor_new_keyval(qobj); | ||
215 | - qobject_unref(qobj); | ||
216 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
217 | visit_free(v); | ||
218 | |||
219 | diff --git a/block/rbd.c b/block/rbd.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/block/rbd.c | ||
222 | +++ b/block/rbd.c | ||
223 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
224 | BDRVRBDState *s = bs->opaque; | ||
225 | BlockdevOptionsRbd *opts = NULL; | ||
226 | Visitor *v; | ||
227 | - QObject *crumpled = NULL; | ||
228 | const QDictEntry *e; | ||
229 | Error *local_err = NULL; | ||
230 | char *keypairs, *secretid; | ||
231 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
232 | } | ||
233 | |||
234 | /* Convert the remaining options into a QAPI object */ | ||
235 | - crumpled = qdict_crumple_for_keyval_qiv(options, errp); | ||
236 | - if (crumpled == NULL) { | ||
237 | + v = qobject_input_visitor_new_flat_confused(options, errp); | ||
238 | + if (!v) { | ||
239 | r = -EINVAL; | ||
240 | goto out; | ||
241 | } | ||
242 | |||
243 | - v = qobject_input_visitor_new_keyval(crumpled); | ||
244 | visit_type_BlockdevOptionsRbd(v, NULL, &opts, &local_err); | ||
245 | visit_free(v); | ||
246 | - qobject_unref(crumpled); | ||
247 | |||
248 | if (local_err) { | ||
249 | error_propagate(errp, local_err); | ||
250 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
251 | index XXXXXXX..XXXXXXX 100644 | ||
252 | --- a/block/sheepdog.c | ||
253 | +++ b/block/sheepdog.c | ||
254 | @@ -XXX,XX +XXX,XX @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
255 | static SocketAddress *sd_server_config(QDict *options, Error **errp) | ||
256 | { | ||
257 | QDict *server = NULL; | ||
258 | - QObject *crumpled_server = NULL; | ||
259 | Visitor *iv = NULL; | ||
260 | SocketAddress *saddr = NULL; | ||
261 | Error *local_err = NULL; | ||
262 | |||
263 | qdict_extract_subqdict(options, &server, "server."); | ||
264 | |||
265 | - crumpled_server = qdict_crumple_for_keyval_qiv(server, errp); | ||
266 | - if (!crumpled_server) { | ||
267 | + iv = qobject_input_visitor_new_flat_confused(server, errp); | ||
268 | + if (!iv) { | ||
269 | goto done; | ||
270 | } | ||
271 | |||
272 | - iv = qobject_input_visitor_new_keyval(crumpled_server); | ||
273 | visit_type_SocketAddress(iv, NULL, &saddr, &local_err); | ||
274 | if (local_err) { | ||
275 | error_propagate(errp, local_err); | ||
276 | @@ -XXX,XX +XXX,XX @@ static SocketAddress *sd_server_config(QDict *options, Error **errp) | ||
277 | |||
278 | done: | ||
279 | visit_free(iv); | ||
280 | - qobject_unref(crumpled_server); | ||
281 | qobject_unref(server); | ||
282 | return saddr; | ||
283 | } | ||
284 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts, | ||
285 | { | ||
286 | BlockdevCreateOptions *create_options = NULL; | ||
287 | QDict *qdict, *location_qdict; | ||
288 | - QObject *crumpled; | ||
289 | Visitor *v; | ||
290 | char *redundancy; | ||
291 | Error *local_err = NULL; | ||
292 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts, | ||
293 | } | ||
294 | |||
295 | /* Get the QAPI object */ | ||
296 | - crumpled = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
297 | - if (crumpled == NULL) { | ||
298 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
299 | + if (!v) { | ||
300 | ret = -EINVAL; | ||
301 | goto fail; | ||
302 | } | ||
303 | |||
304 | - v = qobject_input_visitor_new_keyval(crumpled); | ||
305 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
306 | visit_free(v); | ||
307 | - qobject_unref(crumpled); | ||
308 | |||
309 | if (local_err) { | ||
310 | error_propagate(errp, local_err); | ||
311 | diff --git a/block/ssh.c b/block/ssh.c | ||
312 | index XXXXXXX..XXXXXXX 100644 | ||
313 | --- a/block/ssh.c | ||
314 | +++ b/block/ssh.c | ||
315 | @@ -XXX,XX +XXX,XX @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp) | ||
316 | BlockdevOptionsSsh *result = NULL; | ||
317 | QemuOpts *opts = NULL; | ||
318 | Error *local_err = NULL; | ||
319 | - QObject *crumpled; | ||
320 | const QDictEntry *e; | ||
321 | Visitor *v; | ||
322 | |||
323 | @@ -XXX,XX +XXX,XX @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp) | ||
324 | } | ||
325 | |||
326 | /* Create the QAPI object */ | ||
327 | - crumpled = qdict_crumple_for_keyval_qiv(options, errp); | ||
328 | - if (crumpled == NULL) { | ||
329 | + v = qobject_input_visitor_new_flat_confused(options, errp); | ||
330 | + if (!v) { | ||
331 | goto fail; | ||
332 | } | ||
333 | |||
334 | - v = qobject_input_visitor_new_keyval(crumpled); | ||
335 | visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err); | ||
336 | visit_free(v); | ||
337 | - qobject_unref(crumpled); | ||
338 | |||
339 | if (local_err) { | ||
340 | error_propagate(errp, local_err); | ||
341 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
342 | index XXXXXXX..XXXXXXX 100644 | ||
343 | --- a/block/vhdx.c | ||
344 | +++ b/block/vhdx.c | ||
345 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create_opts(const char *filename, | ||
346 | { | ||
347 | BlockdevCreateOptions *create_options = NULL; | ||
348 | QDict *qdict; | ||
349 | - QObject *qobj; | ||
350 | Visitor *v; | ||
351 | BlockDriverState *bs = NULL; | ||
352 | Error *local_err = NULL; | ||
353 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create_opts(const char *filename, | ||
354 | qdict_put_str(qdict, "driver", "vhdx"); | ||
355 | qdict_put_str(qdict, "file", bs->node_name); | ||
356 | |||
357 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
358 | - if (!qobj) { | ||
359 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
360 | + if (!v) { | ||
361 | ret = -EINVAL; | ||
362 | goto fail; | ||
363 | } | ||
364 | |||
365 | - v = qobject_input_visitor_new_keyval(qobj); | ||
366 | - qobject_unref(qobj); | ||
367 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
368 | visit_free(v); | ||
369 | |||
370 | diff --git a/block/vpc.c b/block/vpc.c | ||
371 | index XXXXXXX..XXXXXXX 100644 | ||
372 | --- a/block/vpc.c | ||
373 | +++ b/block/vpc.c | ||
374 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_create_opts(const char *filename, | ||
375 | { | ||
376 | BlockdevCreateOptions *create_options = NULL; | ||
377 | QDict *qdict; | ||
378 | - QObject *qobj; | ||
379 | Visitor *v; | ||
380 | BlockDriverState *bs = NULL; | ||
381 | Error *local_err = NULL; | ||
382 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_create_opts(const char *filename, | ||
383 | qdict_put_str(qdict, "driver", "vpc"); | ||
384 | qdict_put_str(qdict, "file", bs->node_name); | ||
385 | |||
386 | - qobj = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
387 | - if (!qobj) { | ||
388 | + v = qobject_input_visitor_new_flat_confused(qdict, errp); | ||
389 | + if (!v) { | ||
390 | ret = -EINVAL; | ||
391 | goto fail; | ||
392 | } | ||
393 | |||
394 | - v = qobject_input_visitor_new_keyval(qobj); | ||
395 | - qobject_unref(qobj); | ||
396 | visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); | ||
397 | visit_free(v); | ||
398 | |||
399 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | ||
400 | index XXXXXXX..XXXXXXX 100644 | ||
401 | --- a/qobject/block-qdict.c | ||
402 | +++ b/qobject/block-qdict.c | ||
403 | @@ -XXX,XX +XXX,XX @@ | ||
404 | #include "qapi/qmp/qlist.h" | ||
405 | #include "qapi/qmp/qnum.h" | ||
406 | #include "qapi/qmp/qstring.h" | ||
407 | +#include "qapi/qobject-input-visitor.h" | ||
408 | #include "qemu/cutils.h" | ||
409 | #include "qapi/error.h" | ||
410 | |||
411 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | ||
412 | * used for anything else, and it should go away once the block | ||
413 | * subsystem has been cleaned up. | ||
414 | */ | ||
415 | -QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp) | ||
416 | +static QObject *qdict_crumple_for_keyval_qiv(QDict *src, Error **errp) | ||
417 | { | ||
418 | QDict *tmp = NULL; | ||
419 | char *buf; | ||
420 | @@ -XXX,XX +XXX,XX @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp) | ||
421 | } | ||
422 | return true; | ||
423 | } | ||
424 | + | ||
425 | +/* | ||
426 | + * Create a QObject input visitor for flat @qdict with possibly | ||
427 | + * confused scalar types. | ||
428 | + * | ||
429 | + * The block subsystem uses this function to visit its flat QDict with | ||
430 | + * possibly confused scalar types. It should not be used for anything | ||
431 | + * else, and it should go away once the block subsystem has been | ||
432 | + * cleaned up. | ||
433 | + */ | ||
434 | +Visitor *qobject_input_visitor_new_flat_confused(QDict *qdict, | ||
435 | + Error **errp) | ||
436 | +{ | ||
437 | + QObject *crumpled; | ||
438 | + Visitor *v; | ||
439 | + | ||
440 | + crumpled = qdict_crumple_for_keyval_qiv(qdict, errp); | ||
441 | + if (!crumpled) { | ||
442 | + return NULL; | ||
443 | + } | ||
444 | + | ||
445 | + v = qobject_input_visitor_new_keyval(crumpled); | ||
446 | + qobject_unref(crumpled); | ||
447 | + return v; | ||
448 | +} | ||
449 | -- | 118 | -- |
450 | 2.13.6 | 119 | 2.48.1 |
451 | |||
452 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Pure code motion, except for two brace placements and a comment | 3 | The code that builds an array of AioContext pointers indexed by the |
4 | tweaked to appease checkpatch. | 4 | virtqueue is not specific to virtio-blk. virtio-scsi will need to do the |
5 | same thing, so extract the functions. | ||
5 | 6 | ||
6 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
9 | Message-ID: <20250311132616.1049687-11-stefanha@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | --- | 11 | --- |
10 | qobject/block-qdict.c | 640 ++++++++++++++++++++++++++++++++++++++++++++ | 12 | include/hw/virtio/iothread-vq-mapping.h | 45 ++++++++ |
11 | qobject/qdict.c | 629 -------------------------------------------- | 13 | hw/block/virtio-blk.c | 142 +----------------------- |
12 | tests/check-block-qdict.c | 655 ++++++++++++++++++++++++++++++++++++++++++++++ | 14 | hw/virtio/iothread-vq-mapping.c | 131 ++++++++++++++++++++++ |
13 | tests/check-qdict.c | 642 --------------------------------------------- | 15 | hw/virtio/meson.build | 1 + |
14 | MAINTAINERS | 2 + | 16 | 4 files changed, 178 insertions(+), 141 deletions(-) |
15 | qobject/Makefile.objs | 1 + | 17 | create mode 100644 include/hw/virtio/iothread-vq-mapping.h |
16 | tests/Makefile.include | 4 + | 18 | create mode 100644 hw/virtio/iothread-vq-mapping.c |
17 | 7 files changed, 1302 insertions(+), 1271 deletions(-) | ||
18 | create mode 100644 qobject/block-qdict.c | ||
19 | create mode 100644 tests/check-block-qdict.c | ||
20 | 19 | ||
21 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 20 | diff --git a/include/hw/virtio/iothread-vq-mapping.h b/include/hw/virtio/iothread-vq-mapping.h |
22 | new file mode 100644 | 21 | new file mode 100644 |
23 | index XXXXXXX..XXXXXXX | 22 | index XXXXXXX..XXXXXXX |
24 | --- /dev/null | 23 | --- /dev/null |
25 | +++ b/qobject/block-qdict.c | 24 | +++ b/include/hw/virtio/iothread-vq-mapping.h |
26 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ |
27 | +/* | 26 | +/* |
28 | + * Special QDict functions used by the block layer | 27 | + * IOThread Virtqueue Mapping |
29 | + * | 28 | + * |
30 | + * Copyright (c) 2013-2018 Red Hat, Inc. | 29 | + * Copyright Red Hat, Inc |
31 | + * | 30 | + * |
32 | + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. | 31 | + * SPDX-License-Identifier: GPL-2.0-only |
33 | + * See the COPYING.LIB file in the top-level directory. | ||
34 | + */ | 32 | + */ |
35 | + | 33 | + |
36 | +#include "qemu/osdep.h" | 34 | +#ifndef HW_VIRTIO_IOTHREAD_VQ_MAPPING_H |
37 | +#include "block/qdict.h" | 35 | +#define HW_VIRTIO_IOTHREAD_VQ_MAPPING_H |
38 | +#include "qapi/qmp/qlist.h" | 36 | + |
39 | +#include "qemu/cutils.h" | ||
40 | +#include "qapi/error.h" | 37 | +#include "qapi/error.h" |
38 | +#include "qapi/qapi-types-virtio.h" | ||
41 | + | 39 | + |
42 | +/** | 40 | +/** |
43 | + * qdict_copy_default(): If no entry mapped by 'key' exists in 'dst' yet, the | 41 | + * iothread_vq_mapping_apply: |
44 | + * value of 'key' in 'src' is copied there (and the refcount increased | 42 | + * @list: The mapping of virtqueues to IOThreads. |
45 | + * accordingly). | 43 | + * @vq_aio_context: The array of AioContext pointers to fill in. |
44 | + * @num_queues: The length of @vq_aio_context. | ||
45 | + * @errp: If an error occurs, a pointer to the area to store the error. | ||
46 | + * | ||
47 | + * Fill in the AioContext for each virtqueue in the @vq_aio_context array given | ||
48 | + * the iothread-vq-mapping parameter in @list. | ||
49 | + * | ||
50 | + * iothread_vq_mapping_cleanup() must be called to free IOThread object | ||
51 | + * references after this function returns success. | ||
52 | + * | ||
53 | + * Returns: %true on success, %false on failure. | ||
54 | + **/ | ||
55 | +bool iothread_vq_mapping_apply( | ||
56 | + IOThreadVirtQueueMappingList *list, | ||
57 | + AioContext **vq_aio_context, | ||
58 | + uint16_t num_queues, | ||
59 | + Error **errp); | ||
60 | + | ||
61 | +/** | ||
62 | + * iothread_vq_mapping_cleanup: | ||
63 | + * @list: The mapping of virtqueues to IOThreads. | ||
64 | + * | ||
65 | + * Release IOThread object references that were acquired by | ||
66 | + * iothread_vq_mapping_apply(). | ||
46 | + */ | 67 | + */ |
47 | +void qdict_copy_default(QDict *dst, QDict *src, const char *key) | 68 | +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list); |
48 | +{ | 69 | + |
49 | + QObject *val; | 70 | +#endif /* HW_VIRTIO_IOTHREAD_VQ_MAPPING_H */ |
50 | + | 71 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
51 | + if (qdict_haskey(dst, key)) { | ||
52 | + return; | ||
53 | + } | ||
54 | + | ||
55 | + val = qdict_get(src, key); | ||
56 | + if (val) { | ||
57 | + qdict_put_obj(dst, key, qobject_ref(val)); | ||
58 | + } | ||
59 | +} | ||
60 | + | ||
61 | +/** | ||
62 | + * qdict_set_default_str(): If no entry mapped by 'key' exists in 'dst' yet, a | ||
63 | + * new QString initialised by 'val' is put there. | ||
64 | + */ | ||
65 | +void qdict_set_default_str(QDict *dst, const char *key, const char *val) | ||
66 | +{ | ||
67 | + if (qdict_haskey(dst, key)) { | ||
68 | + return; | ||
69 | + } | ||
70 | + | ||
71 | + qdict_put_str(dst, key, val); | ||
72 | +} | ||
73 | + | ||
74 | +static void qdict_flatten_qdict(QDict *qdict, QDict *target, | ||
75 | + const char *prefix); | ||
76 | + | ||
77 | +static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) | ||
78 | +{ | ||
79 | + QObject *value; | ||
80 | + const QListEntry *entry; | ||
81 | + char *new_key; | ||
82 | + int i; | ||
83 | + | ||
84 | + /* This function is never called with prefix == NULL, i.e., it is always | ||
85 | + * called from within qdict_flatten_q(list|dict)(). Therefore, it does not | ||
86 | + * need to remove list entries during the iteration (the whole list will be | ||
87 | + * deleted eventually anyway from qdict_flatten_qdict()). */ | ||
88 | + assert(prefix); | ||
89 | + | ||
90 | + entry = qlist_first(qlist); | ||
91 | + | ||
92 | + for (i = 0; entry; entry = qlist_next(entry), i++) { | ||
93 | + value = qlist_entry_obj(entry); | ||
94 | + new_key = g_strdup_printf("%s.%i", prefix, i); | ||
95 | + | ||
96 | + if (qobject_type(value) == QTYPE_QDICT) { | ||
97 | + qdict_flatten_qdict(qobject_to(QDict, value), target, new_key); | ||
98 | + } else if (qobject_type(value) == QTYPE_QLIST) { | ||
99 | + qdict_flatten_qlist(qobject_to(QList, value), target, new_key); | ||
100 | + } else { | ||
101 | + /* All other types are moved to the target unchanged. */ | ||
102 | + qdict_put_obj(target, new_key, qobject_ref(value)); | ||
103 | + } | ||
104 | + | ||
105 | + g_free(new_key); | ||
106 | + } | ||
107 | +} | ||
108 | + | ||
109 | +static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | ||
110 | +{ | ||
111 | + QObject *value; | ||
112 | + const QDictEntry *entry, *next; | ||
113 | + char *new_key; | ||
114 | + bool delete; | ||
115 | + | ||
116 | + entry = qdict_first(qdict); | ||
117 | + | ||
118 | + while (entry != NULL) { | ||
119 | + | ||
120 | + next = qdict_next(qdict, entry); | ||
121 | + value = qdict_entry_value(entry); | ||
122 | + new_key = NULL; | ||
123 | + delete = false; | ||
124 | + | ||
125 | + if (prefix) { | ||
126 | + new_key = g_strdup_printf("%s.%s", prefix, entry->key); | ||
127 | + } | ||
128 | + | ||
129 | + if (qobject_type(value) == QTYPE_QDICT) { | ||
130 | + /* Entries of QDicts are processed recursively, the QDict object | ||
131 | + * itself disappears. */ | ||
132 | + qdict_flatten_qdict(qobject_to(QDict, value), target, | ||
133 | + new_key ? new_key : entry->key); | ||
134 | + delete = true; | ||
135 | + } else if (qobject_type(value) == QTYPE_QLIST) { | ||
136 | + qdict_flatten_qlist(qobject_to(QList, value), target, | ||
137 | + new_key ? new_key : entry->key); | ||
138 | + delete = true; | ||
139 | + } else if (prefix) { | ||
140 | + /* All other objects are moved to the target unchanged. */ | ||
141 | + qdict_put_obj(target, new_key, qobject_ref(value)); | ||
142 | + delete = true; | ||
143 | + } | ||
144 | + | ||
145 | + g_free(new_key); | ||
146 | + | ||
147 | + if (delete) { | ||
148 | + qdict_del(qdict, entry->key); | ||
149 | + | ||
150 | + /* Restart loop after modifying the iterated QDict */ | ||
151 | + entry = qdict_first(qdict); | ||
152 | + continue; | ||
153 | + } | ||
154 | + | ||
155 | + entry = next; | ||
156 | + } | ||
157 | +} | ||
158 | + | ||
159 | +/** | ||
160 | + * qdict_flatten(): For each nested QDict with key x, all fields with key y | ||
161 | + * are moved to this QDict and their key is renamed to "x.y". For each nested | ||
162 | + * QList with key x, the field at index y is moved to this QDict with the key | ||
163 | + * "x.y" (i.e., the reverse of what qdict_array_split() does). | ||
164 | + * This operation is applied recursively for nested QDicts and QLists. | ||
165 | + */ | ||
166 | +void qdict_flatten(QDict *qdict) | ||
167 | +{ | ||
168 | + qdict_flatten_qdict(qdict, qdict, NULL); | ||
169 | +} | ||
170 | + | ||
171 | +/* extract all the src QDict entries starting by start into dst */ | ||
172 | +void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) | ||
173 | + | ||
174 | +{ | ||
175 | + const QDictEntry *entry, *next; | ||
176 | + const char *p; | ||
177 | + | ||
178 | + *dst = qdict_new(); | ||
179 | + entry = qdict_first(src); | ||
180 | + | ||
181 | + while (entry != NULL) { | ||
182 | + next = qdict_next(src, entry); | ||
183 | + if (strstart(entry->key, start, &p)) { | ||
184 | + qdict_put_obj(*dst, p, qobject_ref(entry->value)); | ||
185 | + qdict_del(src, entry->key); | ||
186 | + } | ||
187 | + entry = next; | ||
188 | + } | ||
189 | +} | ||
190 | + | ||
191 | +static int qdict_count_prefixed_entries(const QDict *src, const char *start) | ||
192 | +{ | ||
193 | + const QDictEntry *entry; | ||
194 | + int count = 0; | ||
195 | + | ||
196 | + for (entry = qdict_first(src); entry; entry = qdict_next(src, entry)) { | ||
197 | + if (strstart(entry->key, start, NULL)) { | ||
198 | + if (count == INT_MAX) { | ||
199 | + return -ERANGE; | ||
200 | + } | ||
201 | + count++; | ||
202 | + } | ||
203 | + } | ||
204 | + | ||
205 | + return count; | ||
206 | +} | ||
207 | + | ||
208 | +/** | ||
209 | + * qdict_array_split(): This function moves array-like elements of a QDict into | ||
210 | + * a new QList. Every entry in the original QDict with a key "%u" or one | ||
211 | + * prefixed "%u.", where %u designates an unsigned integer starting at 0 and | ||
212 | + * incrementally counting up, will be moved to a new QDict at index %u in the | ||
213 | + * output QList with the key prefix removed, if that prefix is "%u.". If the | ||
214 | + * whole key is just "%u", the whole QObject will be moved unchanged without | ||
215 | + * creating a new QDict. The function terminates when there is no entry in the | ||
216 | + * QDict with a prefix directly (incrementally) following the last one; it also | ||
217 | + * returns if there are both entries with "%u" and "%u." for the same index %u. | ||
218 | + * Example: {"0.a": 42, "0.b": 23, "1.x": 0, "4.y": 1, "o.o": 7, "2": 66} | ||
219 | + * (or {"1.x": 0, "4.y": 1, "0.a": 42, "o.o": 7, "0.b": 23, "2": 66}) | ||
220 | + * => [{"a": 42, "b": 23}, {"x": 0}, 66] | ||
221 | + * and {"4.y": 1, "o.o": 7} (remainder of the old QDict) | ||
222 | + */ | ||
223 | +void qdict_array_split(QDict *src, QList **dst) | ||
224 | +{ | ||
225 | + unsigned i; | ||
226 | + | ||
227 | + *dst = qlist_new(); | ||
228 | + | ||
229 | + for (i = 0; i < UINT_MAX; i++) { | ||
230 | + QObject *subqobj; | ||
231 | + bool is_subqdict; | ||
232 | + QDict *subqdict; | ||
233 | + char indexstr[32], prefix[32]; | ||
234 | + size_t snprintf_ret; | ||
235 | + | ||
236 | + snprintf_ret = snprintf(indexstr, 32, "%u", i); | ||
237 | + assert(snprintf_ret < 32); | ||
238 | + | ||
239 | + subqobj = qdict_get(src, indexstr); | ||
240 | + | ||
241 | + snprintf_ret = snprintf(prefix, 32, "%u.", i); | ||
242 | + assert(snprintf_ret < 32); | ||
243 | + | ||
244 | + /* Overflow is the same as positive non-zero results */ | ||
245 | + is_subqdict = qdict_count_prefixed_entries(src, prefix); | ||
246 | + | ||
247 | + /* | ||
248 | + * There may be either a single subordinate object (named | ||
249 | + * "%u") or multiple objects (each with a key prefixed "%u."), | ||
250 | + * but not both. | ||
251 | + */ | ||
252 | + if (!subqobj == !is_subqdict) { | ||
253 | + break; | ||
254 | + } | ||
255 | + | ||
256 | + if (is_subqdict) { | ||
257 | + qdict_extract_subqdict(src, &subqdict, prefix); | ||
258 | + assert(qdict_size(subqdict) > 0); | ||
259 | + } else { | ||
260 | + qobject_ref(subqobj); | ||
261 | + qdict_del(src, indexstr); | ||
262 | + } | ||
263 | + | ||
264 | + qlist_append_obj(*dst, subqobj ?: QOBJECT(subqdict)); | ||
265 | + } | ||
266 | +} | ||
267 | + | ||
268 | +/** | ||
269 | + * qdict_split_flat_key: | ||
270 | + * @key: the key string to split | ||
271 | + * @prefix: non-NULL pointer to hold extracted prefix | ||
272 | + * @suffix: non-NULL pointer to remaining suffix | ||
273 | + * | ||
274 | + * Given a flattened key such as 'foo.0.bar', split it into two parts | ||
275 | + * at the first '.' separator. Allows double dot ('..') to escape the | ||
276 | + * normal separator. | ||
277 | + * | ||
278 | + * e.g. | ||
279 | + * 'foo.0.bar' -> prefix='foo' and suffix='0.bar' | ||
280 | + * 'foo..0.bar' -> prefix='foo.0' and suffix='bar' | ||
281 | + * | ||
282 | + * The '..' sequence will be unescaped in the returned 'prefix' | ||
283 | + * string. The 'suffix' string will be left in escaped format, so it | ||
284 | + * can be fed back into the qdict_split_flat_key() key as the input | ||
285 | + * later. | ||
286 | + * | ||
287 | + * The caller is responsible for freeing the string returned in @prefix | ||
288 | + * using g_free(). | ||
289 | + */ | ||
290 | +static void qdict_split_flat_key(const char *key, char **prefix, | ||
291 | + const char **suffix) | ||
292 | +{ | ||
293 | + const char *separator; | ||
294 | + size_t i, j; | ||
295 | + | ||
296 | + /* Find first '.' separator, but if there is a pair '..' | ||
297 | + * that acts as an escape, so skip over '..' */ | ||
298 | + separator = NULL; | ||
299 | + do { | ||
300 | + if (separator) { | ||
301 | + separator += 2; | ||
302 | + } else { | ||
303 | + separator = key; | ||
304 | + } | ||
305 | + separator = strchr(separator, '.'); | ||
306 | + } while (separator && separator[1] == '.'); | ||
307 | + | ||
308 | + if (separator) { | ||
309 | + *prefix = g_strndup(key, separator - key); | ||
310 | + *suffix = separator + 1; | ||
311 | + } else { | ||
312 | + *prefix = g_strdup(key); | ||
313 | + *suffix = NULL; | ||
314 | + } | ||
315 | + | ||
316 | + /* Unescape the '..' sequence into '.' */ | ||
317 | + for (i = 0, j = 0; (*prefix)[i] != '\0'; i++, j++) { | ||
318 | + if ((*prefix)[i] == '.') { | ||
319 | + assert((*prefix)[i + 1] == '.'); | ||
320 | + i++; | ||
321 | + } | ||
322 | + (*prefix)[j] = (*prefix)[i]; | ||
323 | + } | ||
324 | + (*prefix)[j] = '\0'; | ||
325 | +} | ||
326 | + | ||
327 | +/** | ||
328 | + * qdict_is_list: | ||
329 | + * @maybe_list: dict to check if keys represent list elements. | ||
330 | + * | ||
331 | + * Determine whether all keys in @maybe_list are valid list elements. | ||
332 | + * If @maybe_list is non-zero in length and all the keys look like | ||
333 | + * valid list indexes, this will return 1. If @maybe_list is zero | ||
334 | + * length or all keys are non-numeric then it will return 0 to indicate | ||
335 | + * it is a normal qdict. If there is a mix of numeric and non-numeric | ||
336 | + * keys, or the list indexes are non-contiguous, an error is reported. | ||
337 | + * | ||
338 | + * Returns: 1 if a valid list, 0 if a dict, -1 on error | ||
339 | + */ | ||
340 | +static int qdict_is_list(QDict *maybe_list, Error **errp) | ||
341 | +{ | ||
342 | + const QDictEntry *ent; | ||
343 | + ssize_t len = 0; | ||
344 | + ssize_t max = -1; | ||
345 | + int is_list = -1; | ||
346 | + int64_t val; | ||
347 | + | ||
348 | + for (ent = qdict_first(maybe_list); ent != NULL; | ||
349 | + ent = qdict_next(maybe_list, ent)) { | ||
350 | + | ||
351 | + if (qemu_strtoi64(ent->key, NULL, 10, &val) == 0) { | ||
352 | + if (is_list == -1) { | ||
353 | + is_list = 1; | ||
354 | + } else if (!is_list) { | ||
355 | + error_setg(errp, | ||
356 | + "Cannot mix list and non-list keys"); | ||
357 | + return -1; | ||
358 | + } | ||
359 | + len++; | ||
360 | + if (val > max) { | ||
361 | + max = val; | ||
362 | + } | ||
363 | + } else { | ||
364 | + if (is_list == -1) { | ||
365 | + is_list = 0; | ||
366 | + } else if (is_list) { | ||
367 | + error_setg(errp, | ||
368 | + "Cannot mix list and non-list keys"); | ||
369 | + return -1; | ||
370 | + } | ||
371 | + } | ||
372 | + } | ||
373 | + | ||
374 | + if (is_list == -1) { | ||
375 | + assert(!qdict_size(maybe_list)); | ||
376 | + is_list = 0; | ||
377 | + } | ||
378 | + | ||
379 | + /* NB this isn't a perfect check - e.g. it won't catch | ||
380 | + * a list containing '1', '+1', '01', '3', but that | ||
381 | + * does not matter - we've still proved that the | ||
382 | + * input is a list. It is up the caller to do a | ||
383 | + * stricter check if desired */ | ||
384 | + if (len != (max + 1)) { | ||
385 | + error_setg(errp, "List indices are not contiguous, " | ||
386 | + "saw %zd elements but %zd largest index", | ||
387 | + len, max); | ||
388 | + return -1; | ||
389 | + } | ||
390 | + | ||
391 | + return is_list; | ||
392 | +} | ||
393 | + | ||
394 | +/** | ||
395 | + * qdict_crumple: | ||
396 | + * @src: the original flat dictionary (only scalar values) to crumple | ||
397 | + * | ||
398 | + * Takes a flat dictionary whose keys use '.' separator to indicate | ||
399 | + * nesting, and values are scalars, and crumples it into a nested | ||
400 | + * structure. | ||
401 | + * | ||
402 | + * To include a literal '.' in a key name, it must be escaped as '..' | ||
403 | + * | ||
404 | + * For example, an input of: | ||
405 | + * | ||
406 | + * { 'foo.0.bar': 'one', 'foo.0.wizz': '1', | ||
407 | + * 'foo.1.bar': 'two', 'foo.1.wizz': '2' } | ||
408 | + * | ||
409 | + * will result in an output of: | ||
410 | + * | ||
411 | + * { | ||
412 | + * 'foo': [ | ||
413 | + * { 'bar': 'one', 'wizz': '1' }, | ||
414 | + * { 'bar': 'two', 'wizz': '2' } | ||
415 | + * ], | ||
416 | + * } | ||
417 | + * | ||
418 | + * The following scenarios in the input dict will result in an | ||
419 | + * error being returned: | ||
420 | + * | ||
421 | + * - Any values in @src are non-scalar types | ||
422 | + * - If keys in @src imply that a particular level is both a | ||
423 | + * list and a dict. e.g., "foo.0.bar" and "foo.eek.bar". | ||
424 | + * - If keys in @src imply that a particular level is a list, | ||
425 | + * but the indices are non-contiguous. e.g. "foo.0.bar" and | ||
426 | + * "foo.2.bar" without any "foo.1.bar" present. | ||
427 | + * - If keys in @src represent list indexes, but are not in | ||
428 | + * the "%zu" format. e.g. "foo.+0.bar" | ||
429 | + * | ||
430 | + * Returns: either a QDict or QList for the nested data structure, or NULL | ||
431 | + * on error | ||
432 | + */ | ||
433 | +QObject *qdict_crumple(const QDict *src, Error **errp) | ||
434 | +{ | ||
435 | + const QDictEntry *ent; | ||
436 | + QDict *two_level, *multi_level = NULL; | ||
437 | + QObject *dst = NULL, *child; | ||
438 | + size_t i; | ||
439 | + char *prefix = NULL; | ||
440 | + const char *suffix = NULL; | ||
441 | + int is_list; | ||
442 | + | ||
443 | + two_level = qdict_new(); | ||
444 | + | ||
445 | + /* Step 1: split our totally flat dict into a two level dict */ | ||
446 | + for (ent = qdict_first(src); ent != NULL; ent = qdict_next(src, ent)) { | ||
447 | + if (qobject_type(ent->value) == QTYPE_QDICT || | ||
448 | + qobject_type(ent->value) == QTYPE_QLIST) { | ||
449 | + error_setg(errp, "Value %s is not a scalar", | ||
450 | + ent->key); | ||
451 | + goto error; | ||
452 | + } | ||
453 | + | ||
454 | + qdict_split_flat_key(ent->key, &prefix, &suffix); | ||
455 | + | ||
456 | + child = qdict_get(two_level, prefix); | ||
457 | + if (suffix) { | ||
458 | + QDict *child_dict = qobject_to(QDict, child); | ||
459 | + if (!child_dict) { | ||
460 | + if (child) { | ||
461 | + error_setg(errp, "Key %s prefix is already set as a scalar", | ||
462 | + prefix); | ||
463 | + goto error; | ||
464 | + } | ||
465 | + | ||
466 | + child_dict = qdict_new(); | ||
467 | + qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); | ||
468 | + } | ||
469 | + | ||
470 | + qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); | ||
471 | + } else { | ||
472 | + if (child) { | ||
473 | + error_setg(errp, "Key %s prefix is already set as a dict", | ||
474 | + prefix); | ||
475 | + goto error; | ||
476 | + } | ||
477 | + qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); | ||
478 | + } | ||
479 | + | ||
480 | + g_free(prefix); | ||
481 | + prefix = NULL; | ||
482 | + } | ||
483 | + | ||
484 | + /* Step 2: optionally process the two level dict recursively | ||
485 | + * into a multi-level dict */ | ||
486 | + multi_level = qdict_new(); | ||
487 | + for (ent = qdict_first(two_level); ent != NULL; | ||
488 | + ent = qdict_next(two_level, ent)) { | ||
489 | + QDict *dict = qobject_to(QDict, ent->value); | ||
490 | + if (dict) { | ||
491 | + child = qdict_crumple(dict, errp); | ||
492 | + if (!child) { | ||
493 | + goto error; | ||
494 | + } | ||
495 | + | ||
496 | + qdict_put_obj(multi_level, ent->key, child); | ||
497 | + } else { | ||
498 | + qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value)); | ||
499 | + } | ||
500 | + } | ||
501 | + qobject_unref(two_level); | ||
502 | + two_level = NULL; | ||
503 | + | ||
504 | + /* Step 3: detect if we need to turn our dict into list */ | ||
505 | + is_list = qdict_is_list(multi_level, errp); | ||
506 | + if (is_list < 0) { | ||
507 | + goto error; | ||
508 | + } | ||
509 | + | ||
510 | + if (is_list) { | ||
511 | + dst = QOBJECT(qlist_new()); | ||
512 | + | ||
513 | + for (i = 0; i < qdict_size(multi_level); i++) { | ||
514 | + char *key = g_strdup_printf("%zu", i); | ||
515 | + | ||
516 | + child = qdict_get(multi_level, key); | ||
517 | + g_free(key); | ||
518 | + | ||
519 | + if (!child) { | ||
520 | + error_setg(errp, "Missing list index %zu", i); | ||
521 | + goto error; | ||
522 | + } | ||
523 | + | ||
524 | + qlist_append_obj(qobject_to(QList, dst), qobject_ref(child)); | ||
525 | + } | ||
526 | + qobject_unref(multi_level); | ||
527 | + multi_level = NULL; | ||
528 | + } else { | ||
529 | + dst = QOBJECT(multi_level); | ||
530 | + } | ||
531 | + | ||
532 | + return dst; | ||
533 | + | ||
534 | + error: | ||
535 | + g_free(prefix); | ||
536 | + qobject_unref(multi_level); | ||
537 | + qobject_unref(two_level); | ||
538 | + qobject_unref(dst); | ||
539 | + return NULL; | ||
540 | +} | ||
541 | + | ||
542 | +/** | ||
543 | + * qdict_array_entries(): Returns the number of direct array entries if the | ||
544 | + * sub-QDict of src specified by the prefix in subqdict (or src itself for | ||
545 | + * prefix == "") is valid as an array, i.e. the length of the created list if | ||
546 | + * the sub-QDict would become empty after calling qdict_array_split() on it. If | ||
547 | + * the array is not valid, -EINVAL is returned. | ||
548 | + */ | ||
549 | +int qdict_array_entries(QDict *src, const char *subqdict) | ||
550 | +{ | ||
551 | + const QDictEntry *entry; | ||
552 | + unsigned i; | ||
553 | + unsigned entries = 0; | ||
554 | + size_t subqdict_len = strlen(subqdict); | ||
555 | + | ||
556 | + assert(!subqdict_len || subqdict[subqdict_len - 1] == '.'); | ||
557 | + | ||
558 | + /* qdict_array_split() loops until UINT_MAX, but as we want to return | ||
559 | + * negative errors, we only have a signed return value here. Any additional | ||
560 | + * entries will lead to -EINVAL. */ | ||
561 | + for (i = 0; i < INT_MAX; i++) { | ||
562 | + QObject *subqobj; | ||
563 | + int subqdict_entries; | ||
564 | + char *prefix = g_strdup_printf("%s%u.", subqdict, i); | ||
565 | + | ||
566 | + subqdict_entries = qdict_count_prefixed_entries(src, prefix); | ||
567 | + | ||
568 | + /* Remove ending "." */ | ||
569 | + prefix[strlen(prefix) - 1] = 0; | ||
570 | + subqobj = qdict_get(src, prefix); | ||
571 | + | ||
572 | + g_free(prefix); | ||
573 | + | ||
574 | + if (subqdict_entries < 0) { | ||
575 | + return subqdict_entries; | ||
576 | + } | ||
577 | + | ||
578 | + /* There may be either a single subordinate object (named "%u") or | ||
579 | + * multiple objects (each with a key prefixed "%u."), but not both. */ | ||
580 | + if (subqobj && subqdict_entries) { | ||
581 | + return -EINVAL; | ||
582 | + } else if (!subqobj && !subqdict_entries) { | ||
583 | + break; | ||
584 | + } | ||
585 | + | ||
586 | + entries += subqdict_entries ? subqdict_entries : 1; | ||
587 | + } | ||
588 | + | ||
589 | + /* Consider everything handled that isn't part of the given sub-QDict */ | ||
590 | + for (entry = qdict_first(src); entry; entry = qdict_next(src, entry)) { | ||
591 | + if (!strstart(qdict_entry_key(entry), subqdict, NULL)) { | ||
592 | + entries++; | ||
593 | + } | ||
594 | + } | ||
595 | + | ||
596 | + /* Anything left in the sub-QDict that wasn't handled? */ | ||
597 | + if (qdict_size(src) != entries) { | ||
598 | + return -EINVAL; | ||
599 | + } | ||
600 | + | ||
601 | + return i; | ||
602 | +} | ||
603 | + | ||
604 | +/** | ||
605 | + * qdict_join(): Absorb the src QDict into the dest QDict, that is, move all | ||
606 | + * elements from src to dest. | ||
607 | + * | ||
608 | + * If an element from src has a key already present in dest, it will not be | ||
609 | + * moved unless overwrite is true. | ||
610 | + * | ||
611 | + * If overwrite is true, the conflicting values in dest will be discarded and | ||
612 | + * replaced by the corresponding values from src. | ||
613 | + * | ||
614 | + * Therefore, with overwrite being true, the src QDict will always be empty when | ||
615 | + * this function returns. If overwrite is false, the src QDict will be empty | ||
616 | + * iff there were no conflicts. | ||
617 | + */ | ||
618 | +void qdict_join(QDict *dest, QDict *src, bool overwrite) | ||
619 | +{ | ||
620 | + const QDictEntry *entry, *next; | ||
621 | + | ||
622 | + entry = qdict_first(src); | ||
623 | + while (entry) { | ||
624 | + next = qdict_next(src, entry); | ||
625 | + | ||
626 | + if (overwrite || !qdict_haskey(dest, entry->key)) { | ||
627 | + qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); | ||
628 | + qdict_del(src, entry->key); | ||
629 | + } | ||
630 | + | ||
631 | + entry = next; | ||
632 | + } | ||
633 | +} | ||
634 | + | ||
635 | +/** | ||
636 | + * qdict_rename_keys(): Rename keys in qdict according to the replacements | ||
637 | + * specified in the array renames. The array must be terminated by an entry | ||
638 | + * with from = NULL. | ||
639 | + * | ||
640 | + * The renames are performed individually in the order of the array, so entries | ||
641 | + * may be renamed multiple times and may or may not conflict depending on the | ||
642 | + * order of the renames array. | ||
643 | + * | ||
644 | + * Returns true for success, false in error cases. | ||
645 | + */ | ||
646 | +bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp) | ||
647 | +{ | ||
648 | + QObject *qobj; | ||
649 | + | ||
650 | + while (renames->from) { | ||
651 | + if (qdict_haskey(qdict, renames->from)) { | ||
652 | + if (qdict_haskey(qdict, renames->to)) { | ||
653 | + error_setg(errp, "'%s' and its alias '%s' can't be used at the " | ||
654 | + "same time", renames->to, renames->from); | ||
655 | + return false; | ||
656 | + } | ||
657 | + | ||
658 | + qobj = qdict_get(qdict, renames->from); | ||
659 | + qdict_put_obj(qdict, renames->to, qobject_ref(qobj)); | ||
660 | + qdict_del(qdict, renames->from); | ||
661 | + } | ||
662 | + | ||
663 | + renames++; | ||
664 | + } | ||
665 | + return true; | ||
666 | +} | ||
667 | diff --git a/qobject/qdict.c b/qobject/qdict.c | ||
668 | index XXXXXXX..XXXXXXX 100644 | 72 | index XXXXXXX..XXXXXXX 100644 |
669 | --- a/qobject/qdict.c | 73 | --- a/hw/block/virtio-blk.c |
670 | +++ b/qobject/qdict.c | 74 | +++ b/hw/block/virtio-blk.c |
671 | @@ -XXX,XX +XXX,XX @@ | 75 | @@ -XXX,XX +XXX,XX @@ |
672 | */ | 76 | #endif |
673 | 77 | #include "hw/virtio/virtio-bus.h" | |
674 | #include "qemu/osdep.h" | 78 | #include "migration/qemu-file-types.h" |
675 | -#include "block/qdict.h" | 79 | +#include "hw/virtio/iothread-vq-mapping.h" |
676 | #include "qapi/qmp/qnum.h" | 80 | #include "hw/virtio/virtio-access.h" |
677 | #include "qapi/qmp/qdict.h" | 81 | #include "hw/virtio/virtio-blk-common.h" |
678 | #include "qapi/qmp/qbool.h" | 82 | #include "qemu/coroutine.h" |
679 | -#include "qapi/qmp/qlist.h" | 83 | @@ -XXX,XX +XXX,XX @@ static const BlockDevOps virtio_block_ops = { |
680 | #include "qapi/qmp/qnull.h" | 84 | .drained_end = virtio_blk_drained_end, |
681 | #include "qapi/qmp/qstring.h" | 85 | }; |
682 | -#include "qapi/error.h" | 86 | |
683 | -#include "qemu/queue.h" | 87 | -static bool |
684 | -#include "qemu-common.h" | 88 | -iothread_vq_mapping_validate(IOThreadVirtQueueMappingList *list, uint16_t |
685 | -#include "qemu/cutils.h" | 89 | - num_queues, Error **errp) |
686 | |||
687 | /** | ||
688 | * qdict_new(): Create a new QDict | ||
689 | @@ -XXX,XX +XXX,XX @@ void qdict_destroy_obj(QObject *obj) | ||
690 | |||
691 | g_free(qdict); | ||
692 | } | ||
693 | - | ||
694 | -/** | ||
695 | - * qdict_copy_default(): If no entry mapped by 'key' exists in 'dst' yet, the | ||
696 | - * value of 'key' in 'src' is copied there (and the refcount increased | ||
697 | - * accordingly). | ||
698 | - */ | ||
699 | -void qdict_copy_default(QDict *dst, QDict *src, const char *key) | ||
700 | -{ | 90 | -{ |
701 | - QObject *val; | 91 | - g_autofree unsigned long *vqs = bitmap_new(num_queues); |
702 | - | 92 | - g_autoptr(GHashTable) iothreads = |
703 | - if (qdict_haskey(dst, key)) { | 93 | - g_hash_table_new(g_str_hash, g_str_equal); |
704 | - return; | 94 | - |
705 | - } | 95 | - for (IOThreadVirtQueueMappingList *node = list; node; node = node->next) { |
706 | - | 96 | - const char *name = node->value->iothread; |
707 | - val = qdict_get(src, key); | 97 | - uint16List *vq; |
708 | - if (val) { | 98 | - |
709 | - qdict_put_obj(dst, key, qobject_ref(val)); | 99 | - if (!iothread_by_id(name)) { |
710 | - } | 100 | - error_setg(errp, "IOThread \"%s\" object does not exist", name); |
711 | -} | 101 | - return false; |
712 | - | 102 | - } |
713 | -/** | 103 | - |
714 | - * qdict_set_default_str(): If no entry mapped by 'key' exists in 'dst' yet, a | 104 | - if (!g_hash_table_add(iothreads, (gpointer)name)) { |
715 | - * new QString initialised by 'val' is put there. | 105 | - error_setg(errp, |
716 | - */ | 106 | - "duplicate IOThread name \"%s\" in iothread-vq-mapping", |
717 | -void qdict_set_default_str(QDict *dst, const char *key, const char *val) | 107 | - name); |
718 | -{ | 108 | - return false; |
719 | - if (qdict_haskey(dst, key)) { | 109 | - } |
720 | - return; | 110 | - |
721 | - } | 111 | - if (node != list) { |
722 | - | 112 | - if (!!node->value->vqs != !!list->value->vqs) { |
723 | - qdict_put_str(dst, key, val); | 113 | - error_setg(errp, "either all items in iothread-vq-mapping " |
724 | -} | 114 | - "must have vqs or none of them must have it"); |
725 | - | 115 | - return false; |
726 | -static void qdict_flatten_qdict(QDict *qdict, QDict *target, | 116 | - } |
727 | - const char *prefix); | 117 | - } |
728 | - | 118 | - |
729 | -static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) | 119 | - for (vq = node->value->vqs; vq; vq = vq->next) { |
730 | -{ | 120 | - if (vq->value >= num_queues) { |
731 | - QObject *value; | 121 | - error_setg(errp, "vq index %u for IOThread \"%s\" must be " |
732 | - const QListEntry *entry; | 122 | - "less than num_queues %u in iothread-vq-mapping", |
733 | - char *new_key; | 123 | - vq->value, name, num_queues); |
734 | - int i; | 124 | - return false; |
735 | - | 125 | - } |
736 | - /* This function is never called with prefix == NULL, i.e., it is always | 126 | - |
737 | - * called from within qdict_flatten_q(list|dict)(). Therefore, it does not | 127 | - if (test_and_set_bit(vq->value, vqs)) { |
738 | - * need to remove list entries during the iteration (the whole list will be | 128 | - error_setg(errp, "cannot assign vq %u to IOThread \"%s\" " |
739 | - * deleted eventually anyway from qdict_flatten_qdict()). */ | 129 | - "because it is already assigned", vq->value, name); |
740 | - assert(prefix); | 130 | - return false; |
741 | - | 131 | - } |
742 | - entry = qlist_first(qlist); | 132 | - } |
743 | - | 133 | - } |
744 | - for (i = 0; entry; entry = qlist_next(entry), i++) { | 134 | - |
745 | - value = qlist_entry_obj(entry); | 135 | - if (list->value->vqs) { |
746 | - new_key = g_strdup_printf("%s.%i", prefix, i); | 136 | - for (uint16_t i = 0; i < num_queues; i++) { |
747 | - | 137 | - if (!test_bit(i, vqs)) { |
748 | - if (qobject_type(value) == QTYPE_QDICT) { | ||
749 | - qdict_flatten_qdict(qobject_to(QDict, value), target, new_key); | ||
750 | - } else if (qobject_type(value) == QTYPE_QLIST) { | ||
751 | - qdict_flatten_qlist(qobject_to(QList, value), target, new_key); | ||
752 | - } else { | ||
753 | - /* All other types are moved to the target unchanged. */ | ||
754 | - qdict_put_obj(target, new_key, qobject_ref(value)); | ||
755 | - } | ||
756 | - | ||
757 | - g_free(new_key); | ||
758 | - } | ||
759 | -} | ||
760 | - | ||
761 | -static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | ||
762 | -{ | ||
763 | - QObject *value; | ||
764 | - const QDictEntry *entry, *next; | ||
765 | - char *new_key; | ||
766 | - bool delete; | ||
767 | - | ||
768 | - entry = qdict_first(qdict); | ||
769 | - | ||
770 | - while (entry != NULL) { | ||
771 | - | ||
772 | - next = qdict_next(qdict, entry); | ||
773 | - value = qdict_entry_value(entry); | ||
774 | - new_key = NULL; | ||
775 | - delete = false; | ||
776 | - | ||
777 | - if (prefix) { | ||
778 | - new_key = g_strdup_printf("%s.%s", prefix, entry->key); | ||
779 | - } | ||
780 | - | ||
781 | - if (qobject_type(value) == QTYPE_QDICT) { | ||
782 | - /* Entries of QDicts are processed recursively, the QDict object | ||
783 | - * itself disappears. */ | ||
784 | - qdict_flatten_qdict(qobject_to(QDict, value), target, | ||
785 | - new_key ? new_key : entry->key); | ||
786 | - delete = true; | ||
787 | - } else if (qobject_type(value) == QTYPE_QLIST) { | ||
788 | - qdict_flatten_qlist(qobject_to(QList, value), target, | ||
789 | - new_key ? new_key : entry->key); | ||
790 | - delete = true; | ||
791 | - } else if (prefix) { | ||
792 | - /* All other objects are moved to the target unchanged. */ | ||
793 | - qdict_put_obj(target, new_key, qobject_ref(value)); | ||
794 | - delete = true; | ||
795 | - } | ||
796 | - | ||
797 | - g_free(new_key); | ||
798 | - | ||
799 | - if (delete) { | ||
800 | - qdict_del(qdict, entry->key); | ||
801 | - | ||
802 | - /* Restart loop after modifying the iterated QDict */ | ||
803 | - entry = qdict_first(qdict); | ||
804 | - continue; | ||
805 | - } | ||
806 | - | ||
807 | - entry = next; | ||
808 | - } | ||
809 | -} | ||
810 | - | ||
811 | -/** | ||
812 | - * qdict_flatten(): For each nested QDict with key x, all fields with key y | ||
813 | - * are moved to this QDict and their key is renamed to "x.y". For each nested | ||
814 | - * QList with key x, the field at index y is moved to this QDict with the key | ||
815 | - * "x.y" (i.e., the reverse of what qdict_array_split() does). | ||
816 | - * This operation is applied recursively for nested QDicts and QLists. | ||
817 | - */ | ||
818 | -void qdict_flatten(QDict *qdict) | ||
819 | -{ | ||
820 | - qdict_flatten_qdict(qdict, qdict, NULL); | ||
821 | -} | ||
822 | - | ||
823 | -/* extract all the src QDict entries starting by start into dst */ | ||
824 | -void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) | ||
825 | - | ||
826 | -{ | ||
827 | - const QDictEntry *entry, *next; | ||
828 | - const char *p; | ||
829 | - | ||
830 | - *dst = qdict_new(); | ||
831 | - entry = qdict_first(src); | ||
832 | - | ||
833 | - while (entry != NULL) { | ||
834 | - next = qdict_next(src, entry); | ||
835 | - if (strstart(entry->key, start, &p)) { | ||
836 | - qdict_put_obj(*dst, p, qobject_ref(entry->value)); | ||
837 | - qdict_del(src, entry->key); | ||
838 | - } | ||
839 | - entry = next; | ||
840 | - } | ||
841 | -} | ||
842 | - | ||
843 | -static int qdict_count_prefixed_entries(const QDict *src, const char *start) | ||
844 | -{ | ||
845 | - const QDictEntry *entry; | ||
846 | - int count = 0; | ||
847 | - | ||
848 | - for (entry = qdict_first(src); entry; entry = qdict_next(src, entry)) { | ||
849 | - if (strstart(entry->key, start, NULL)) { | ||
850 | - if (count == INT_MAX) { | ||
851 | - return -ERANGE; | ||
852 | - } | ||
853 | - count++; | ||
854 | - } | ||
855 | - } | ||
856 | - | ||
857 | - return count; | ||
858 | -} | ||
859 | - | ||
860 | -/** | ||
861 | - * qdict_array_split(): This function moves array-like elements of a QDict into | ||
862 | - * a new QList. Every entry in the original QDict with a key "%u" or one | ||
863 | - * prefixed "%u.", where %u designates an unsigned integer starting at 0 and | ||
864 | - * incrementally counting up, will be moved to a new QDict at index %u in the | ||
865 | - * output QList with the key prefix removed, if that prefix is "%u.". If the | ||
866 | - * whole key is just "%u", the whole QObject will be moved unchanged without | ||
867 | - * creating a new QDict. The function terminates when there is no entry in the | ||
868 | - * QDict with a prefix directly (incrementally) following the last one; it also | ||
869 | - * returns if there are both entries with "%u" and "%u." for the same index %u. | ||
870 | - * Example: {"0.a": 42, "0.b": 23, "1.x": 0, "4.y": 1, "o.o": 7, "2": 66} | ||
871 | - * (or {"1.x": 0, "4.y": 1, "0.a": 42, "o.o": 7, "0.b": 23, "2": 66}) | ||
872 | - * => [{"a": 42, "b": 23}, {"x": 0}, 66] | ||
873 | - * and {"4.y": 1, "o.o": 7} (remainder of the old QDict) | ||
874 | - */ | ||
875 | -void qdict_array_split(QDict *src, QList **dst) | ||
876 | -{ | ||
877 | - unsigned i; | ||
878 | - | ||
879 | - *dst = qlist_new(); | ||
880 | - | ||
881 | - for (i = 0; i < UINT_MAX; i++) { | ||
882 | - QObject *subqobj; | ||
883 | - bool is_subqdict; | ||
884 | - QDict *subqdict; | ||
885 | - char indexstr[32], prefix[32]; | ||
886 | - size_t snprintf_ret; | ||
887 | - | ||
888 | - snprintf_ret = snprintf(indexstr, 32, "%u", i); | ||
889 | - assert(snprintf_ret < 32); | ||
890 | - | ||
891 | - subqobj = qdict_get(src, indexstr); | ||
892 | - | ||
893 | - snprintf_ret = snprintf(prefix, 32, "%u.", i); | ||
894 | - assert(snprintf_ret < 32); | ||
895 | - | ||
896 | - /* Overflow is the same as positive non-zero results */ | ||
897 | - is_subqdict = qdict_count_prefixed_entries(src, prefix); | ||
898 | - | ||
899 | - // There may be either a single subordinate object (named "%u") or | ||
900 | - // multiple objects (each with a key prefixed "%u."), but not both. | ||
901 | - if (!subqobj == !is_subqdict) { | ||
902 | - break; | ||
903 | - } | ||
904 | - | ||
905 | - if (is_subqdict) { | ||
906 | - qdict_extract_subqdict(src, &subqdict, prefix); | ||
907 | - assert(qdict_size(subqdict) > 0); | ||
908 | - } else { | ||
909 | - qobject_ref(subqobj); | ||
910 | - qdict_del(src, indexstr); | ||
911 | - } | ||
912 | - | ||
913 | - qlist_append_obj(*dst, subqobj ?: QOBJECT(subqdict)); | ||
914 | - } | ||
915 | -} | ||
916 | - | ||
917 | -/** | ||
918 | - * qdict_split_flat_key: | ||
919 | - * @key: the key string to split | ||
920 | - * @prefix: non-NULL pointer to hold extracted prefix | ||
921 | - * @suffix: non-NULL pointer to remaining suffix | ||
922 | - * | ||
923 | - * Given a flattened key such as 'foo.0.bar', split it into two parts | ||
924 | - * at the first '.' separator. Allows double dot ('..') to escape the | ||
925 | - * normal separator. | ||
926 | - * | ||
927 | - * e.g. | ||
928 | - * 'foo.0.bar' -> prefix='foo' and suffix='0.bar' | ||
929 | - * 'foo..0.bar' -> prefix='foo.0' and suffix='bar' | ||
930 | - * | ||
931 | - * The '..' sequence will be unescaped in the returned 'prefix' | ||
932 | - * string. The 'suffix' string will be left in escaped format, so it | ||
933 | - * can be fed back into the qdict_split_flat_key() key as the input | ||
934 | - * later. | ||
935 | - * | ||
936 | - * The caller is responsible for freeing the string returned in @prefix | ||
937 | - * using g_free(). | ||
938 | - */ | ||
939 | -static void qdict_split_flat_key(const char *key, char **prefix, | ||
940 | - const char **suffix) | ||
941 | -{ | ||
942 | - const char *separator; | ||
943 | - size_t i, j; | ||
944 | - | ||
945 | - /* Find first '.' separator, but if there is a pair '..' | ||
946 | - * that acts as an escape, so skip over '..' */ | ||
947 | - separator = NULL; | ||
948 | - do { | ||
949 | - if (separator) { | ||
950 | - separator += 2; | ||
951 | - } else { | ||
952 | - separator = key; | ||
953 | - } | ||
954 | - separator = strchr(separator, '.'); | ||
955 | - } while (separator && separator[1] == '.'); | ||
956 | - | ||
957 | - if (separator) { | ||
958 | - *prefix = g_strndup(key, separator - key); | ||
959 | - *suffix = separator + 1; | ||
960 | - } else { | ||
961 | - *prefix = g_strdup(key); | ||
962 | - *suffix = NULL; | ||
963 | - } | ||
964 | - | ||
965 | - /* Unescape the '..' sequence into '.' */ | ||
966 | - for (i = 0, j = 0; (*prefix)[i] != '\0'; i++, j++) { | ||
967 | - if ((*prefix)[i] == '.') { | ||
968 | - assert((*prefix)[i + 1] == '.'); | ||
969 | - i++; | ||
970 | - } | ||
971 | - (*prefix)[j] = (*prefix)[i]; | ||
972 | - } | ||
973 | - (*prefix)[j] = '\0'; | ||
974 | -} | ||
975 | - | ||
976 | -/** | ||
977 | - * qdict_is_list: | ||
978 | - * @maybe_list: dict to check if keys represent list elements. | ||
979 | - * | ||
980 | - * Determine whether all keys in @maybe_list are valid list elements. | ||
981 | - * If @maybe_list is non-zero in length and all the keys look like | ||
982 | - * valid list indexes, this will return 1. If @maybe_list is zero | ||
983 | - * length or all keys are non-numeric then it will return 0 to indicate | ||
984 | - * it is a normal qdict. If there is a mix of numeric and non-numeric | ||
985 | - * keys, or the list indexes are non-contiguous, an error is reported. | ||
986 | - * | ||
987 | - * Returns: 1 if a valid list, 0 if a dict, -1 on error | ||
988 | - */ | ||
989 | -static int qdict_is_list(QDict *maybe_list, Error **errp) | ||
990 | -{ | ||
991 | - const QDictEntry *ent; | ||
992 | - ssize_t len = 0; | ||
993 | - ssize_t max = -1; | ||
994 | - int is_list = -1; | ||
995 | - int64_t val; | ||
996 | - | ||
997 | - for (ent = qdict_first(maybe_list); ent != NULL; | ||
998 | - ent = qdict_next(maybe_list, ent)) { | ||
999 | - | ||
1000 | - if (qemu_strtoi64(ent->key, NULL, 10, &val) == 0) { | ||
1001 | - if (is_list == -1) { | ||
1002 | - is_list = 1; | ||
1003 | - } else if (!is_list) { | ||
1004 | - error_setg(errp, | 138 | - error_setg(errp, |
1005 | - "Cannot mix list and non-list keys"); | 139 | - "missing vq %u IOThread assignment in iothread-vq-mapping", |
1006 | - return -1; | 140 | - i); |
1007 | - } | ||
1008 | - len++; | ||
1009 | - if (val > max) { | ||
1010 | - max = val; | ||
1011 | - } | ||
1012 | - } else { | ||
1013 | - if (is_list == -1) { | ||
1014 | - is_list = 0; | ||
1015 | - } else if (is_list) { | ||
1016 | - error_setg(errp, | ||
1017 | - "Cannot mix list and non-list keys"); | ||
1018 | - return -1; | ||
1019 | - } | ||
1020 | - } | ||
1021 | - } | ||
1022 | - | ||
1023 | - if (is_list == -1) { | ||
1024 | - assert(!qdict_size(maybe_list)); | ||
1025 | - is_list = 0; | ||
1026 | - } | ||
1027 | - | ||
1028 | - /* NB this isn't a perfect check - e.g. it won't catch | ||
1029 | - * a list containing '1', '+1', '01', '3', but that | ||
1030 | - * does not matter - we've still proved that the | ||
1031 | - * input is a list. It is up the caller to do a | ||
1032 | - * stricter check if desired */ | ||
1033 | - if (len != (max + 1)) { | ||
1034 | - error_setg(errp, "List indices are not contiguous, " | ||
1035 | - "saw %zd elements but %zd largest index", | ||
1036 | - len, max); | ||
1037 | - return -1; | ||
1038 | - } | ||
1039 | - | ||
1040 | - return is_list; | ||
1041 | -} | ||
1042 | - | ||
1043 | -/** | ||
1044 | - * qdict_crumple: | ||
1045 | - * @src: the original flat dictionary (only scalar values) to crumple | ||
1046 | - * | ||
1047 | - * Takes a flat dictionary whose keys use '.' separator to indicate | ||
1048 | - * nesting, and values are scalars, and crumples it into a nested | ||
1049 | - * structure. | ||
1050 | - * | ||
1051 | - * To include a literal '.' in a key name, it must be escaped as '..' | ||
1052 | - * | ||
1053 | - * For example, an input of: | ||
1054 | - * | ||
1055 | - * { 'foo.0.bar': 'one', 'foo.0.wizz': '1', | ||
1056 | - * 'foo.1.bar': 'two', 'foo.1.wizz': '2' } | ||
1057 | - * | ||
1058 | - * will result in an output of: | ||
1059 | - * | ||
1060 | - * { | ||
1061 | - * 'foo': [ | ||
1062 | - * { 'bar': 'one', 'wizz': '1' }, | ||
1063 | - * { 'bar': 'two', 'wizz': '2' } | ||
1064 | - * ], | ||
1065 | - * } | ||
1066 | - * | ||
1067 | - * The following scenarios in the input dict will result in an | ||
1068 | - * error being returned: | ||
1069 | - * | ||
1070 | - * - Any values in @src are non-scalar types | ||
1071 | - * - If keys in @src imply that a particular level is both a | ||
1072 | - * list and a dict. e.g., "foo.0.bar" and "foo.eek.bar". | ||
1073 | - * - If keys in @src imply that a particular level is a list, | ||
1074 | - * but the indices are non-contiguous. e.g. "foo.0.bar" and | ||
1075 | - * "foo.2.bar" without any "foo.1.bar" present. | ||
1076 | - * - If keys in @src represent list indexes, but are not in | ||
1077 | - * the "%zu" format. e.g. "foo.+0.bar" | ||
1078 | - * | ||
1079 | - * Returns: either a QDict or QList for the nested data structure, or NULL | ||
1080 | - * on error | ||
1081 | - */ | ||
1082 | -QObject *qdict_crumple(const QDict *src, Error **errp) | ||
1083 | -{ | ||
1084 | - const QDictEntry *ent; | ||
1085 | - QDict *two_level, *multi_level = NULL; | ||
1086 | - QObject *dst = NULL, *child; | ||
1087 | - size_t i; | ||
1088 | - char *prefix = NULL; | ||
1089 | - const char *suffix = NULL; | ||
1090 | - int is_list; | ||
1091 | - | ||
1092 | - two_level = qdict_new(); | ||
1093 | - | ||
1094 | - /* Step 1: split our totally flat dict into a two level dict */ | ||
1095 | - for (ent = qdict_first(src); ent != NULL; ent = qdict_next(src, ent)) { | ||
1096 | - if (qobject_type(ent->value) == QTYPE_QDICT || | ||
1097 | - qobject_type(ent->value) == QTYPE_QLIST) { | ||
1098 | - error_setg(errp, "Value %s is not a scalar", | ||
1099 | - ent->key); | ||
1100 | - goto error; | ||
1101 | - } | ||
1102 | - | ||
1103 | - qdict_split_flat_key(ent->key, &prefix, &suffix); | ||
1104 | - | ||
1105 | - child = qdict_get(two_level, prefix); | ||
1106 | - if (suffix) { | ||
1107 | - QDict *child_dict = qobject_to(QDict, child); | ||
1108 | - if (!child_dict) { | ||
1109 | - if (child) { | ||
1110 | - error_setg(errp, "Key %s prefix is already set as a scalar", | ||
1111 | - prefix); | ||
1112 | - goto error; | ||
1113 | - } | ||
1114 | - | ||
1115 | - child_dict = qdict_new(); | ||
1116 | - qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); | ||
1117 | - } | ||
1118 | - | ||
1119 | - qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); | ||
1120 | - } else { | ||
1121 | - if (child) { | ||
1122 | - error_setg(errp, "Key %s prefix is already set as a dict", | ||
1123 | - prefix); | ||
1124 | - goto error; | ||
1125 | - } | ||
1126 | - qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); | ||
1127 | - } | ||
1128 | - | ||
1129 | - g_free(prefix); | ||
1130 | - prefix = NULL; | ||
1131 | - } | ||
1132 | - | ||
1133 | - /* Step 2: optionally process the two level dict recursively | ||
1134 | - * into a multi-level dict */ | ||
1135 | - multi_level = qdict_new(); | ||
1136 | - for (ent = qdict_first(two_level); ent != NULL; | ||
1137 | - ent = qdict_next(two_level, ent)) { | ||
1138 | - QDict *dict = qobject_to(QDict, ent->value); | ||
1139 | - if (dict) { | ||
1140 | - child = qdict_crumple(dict, errp); | ||
1141 | - if (!child) { | ||
1142 | - goto error; | ||
1143 | - } | ||
1144 | - | ||
1145 | - qdict_put_obj(multi_level, ent->key, child); | ||
1146 | - } else { | ||
1147 | - qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value)); | ||
1148 | - } | ||
1149 | - } | ||
1150 | - qobject_unref(two_level); | ||
1151 | - two_level = NULL; | ||
1152 | - | ||
1153 | - /* Step 3: detect if we need to turn our dict into list */ | ||
1154 | - is_list = qdict_is_list(multi_level, errp); | ||
1155 | - if (is_list < 0) { | ||
1156 | - goto error; | ||
1157 | - } | ||
1158 | - | ||
1159 | - if (is_list) { | ||
1160 | - dst = QOBJECT(qlist_new()); | ||
1161 | - | ||
1162 | - for (i = 0; i < qdict_size(multi_level); i++) { | ||
1163 | - char *key = g_strdup_printf("%zu", i); | ||
1164 | - | ||
1165 | - child = qdict_get(multi_level, key); | ||
1166 | - g_free(key); | ||
1167 | - | ||
1168 | - if (!child) { | ||
1169 | - error_setg(errp, "Missing list index %zu", i); | ||
1170 | - goto error; | ||
1171 | - } | ||
1172 | - | ||
1173 | - qlist_append_obj(qobject_to(QList, dst), qobject_ref(child)); | ||
1174 | - } | ||
1175 | - qobject_unref(multi_level); | ||
1176 | - multi_level = NULL; | ||
1177 | - } else { | ||
1178 | - dst = QOBJECT(multi_level); | ||
1179 | - } | ||
1180 | - | ||
1181 | - return dst; | ||
1182 | - | ||
1183 | - error: | ||
1184 | - g_free(prefix); | ||
1185 | - qobject_unref(multi_level); | ||
1186 | - qobject_unref(two_level); | ||
1187 | - qobject_unref(dst); | ||
1188 | - return NULL; | ||
1189 | -} | ||
1190 | - | ||
1191 | -/** | ||
1192 | - * qdict_array_entries(): Returns the number of direct array entries if the | ||
1193 | - * sub-QDict of src specified by the prefix in subqdict (or src itself for | ||
1194 | - * prefix == "") is valid as an array, i.e. the length of the created list if | ||
1195 | - * the sub-QDict would become empty after calling qdict_array_split() on it. If | ||
1196 | - * the array is not valid, -EINVAL is returned. | ||
1197 | - */ | ||
1198 | -int qdict_array_entries(QDict *src, const char *subqdict) | ||
1199 | -{ | ||
1200 | - const QDictEntry *entry; | ||
1201 | - unsigned i; | ||
1202 | - unsigned entries = 0; | ||
1203 | - size_t subqdict_len = strlen(subqdict); | ||
1204 | - | ||
1205 | - assert(!subqdict_len || subqdict[subqdict_len - 1] == '.'); | ||
1206 | - | ||
1207 | - /* qdict_array_split() loops until UINT_MAX, but as we want to return | ||
1208 | - * negative errors, we only have a signed return value here. Any additional | ||
1209 | - * entries will lead to -EINVAL. */ | ||
1210 | - for (i = 0; i < INT_MAX; i++) { | ||
1211 | - QObject *subqobj; | ||
1212 | - int subqdict_entries; | ||
1213 | - char *prefix = g_strdup_printf("%s%u.", subqdict, i); | ||
1214 | - | ||
1215 | - subqdict_entries = qdict_count_prefixed_entries(src, prefix); | ||
1216 | - | ||
1217 | - /* Remove ending "." */ | ||
1218 | - prefix[strlen(prefix) - 1] = 0; | ||
1219 | - subqobj = qdict_get(src, prefix); | ||
1220 | - | ||
1221 | - g_free(prefix); | ||
1222 | - | ||
1223 | - if (subqdict_entries < 0) { | ||
1224 | - return subqdict_entries; | ||
1225 | - } | ||
1226 | - | ||
1227 | - /* There may be either a single subordinate object (named "%u") or | ||
1228 | - * multiple objects (each with a key prefixed "%u."), but not both. */ | ||
1229 | - if (subqobj && subqdict_entries) { | ||
1230 | - return -EINVAL; | ||
1231 | - } else if (!subqobj && !subqdict_entries) { | ||
1232 | - break; | ||
1233 | - } | ||
1234 | - | ||
1235 | - entries += subqdict_entries ? subqdict_entries : 1; | ||
1236 | - } | ||
1237 | - | ||
1238 | - /* Consider everything handled that isn't part of the given sub-QDict */ | ||
1239 | - for (entry = qdict_first(src); entry; entry = qdict_next(src, entry)) { | ||
1240 | - if (!strstart(qdict_entry_key(entry), subqdict, NULL)) { | ||
1241 | - entries++; | ||
1242 | - } | ||
1243 | - } | ||
1244 | - | ||
1245 | - /* Anything left in the sub-QDict that wasn't handled? */ | ||
1246 | - if (qdict_size(src) != entries) { | ||
1247 | - return -EINVAL; | ||
1248 | - } | ||
1249 | - | ||
1250 | - return i; | ||
1251 | -} | ||
1252 | - | ||
1253 | -/** | ||
1254 | - * qdict_join(): Absorb the src QDict into the dest QDict, that is, move all | ||
1255 | - * elements from src to dest. | ||
1256 | - * | ||
1257 | - * If an element from src has a key already present in dest, it will not be | ||
1258 | - * moved unless overwrite is true. | ||
1259 | - * | ||
1260 | - * If overwrite is true, the conflicting values in dest will be discarded and | ||
1261 | - * replaced by the corresponding values from src. | ||
1262 | - * | ||
1263 | - * Therefore, with overwrite being true, the src QDict will always be empty when | ||
1264 | - * this function returns. If overwrite is false, the src QDict will be empty | ||
1265 | - * iff there were no conflicts. | ||
1266 | - */ | ||
1267 | -void qdict_join(QDict *dest, QDict *src, bool overwrite) | ||
1268 | -{ | ||
1269 | - const QDictEntry *entry, *next; | ||
1270 | - | ||
1271 | - entry = qdict_first(src); | ||
1272 | - while (entry) { | ||
1273 | - next = qdict_next(src, entry); | ||
1274 | - | ||
1275 | - if (overwrite || !qdict_haskey(dest, entry->key)) { | ||
1276 | - qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); | ||
1277 | - qdict_del(src, entry->key); | ||
1278 | - } | ||
1279 | - | ||
1280 | - entry = next; | ||
1281 | - } | ||
1282 | -} | ||
1283 | - | ||
1284 | -/** | ||
1285 | - * qdict_rename_keys(): Rename keys in qdict according to the replacements | ||
1286 | - * specified in the array renames. The array must be terminated by an entry | ||
1287 | - * with from = NULL. | ||
1288 | - * | ||
1289 | - * The renames are performed individually in the order of the array, so entries | ||
1290 | - * may be renamed multiple times and may or may not conflict depending on the | ||
1291 | - * order of the renames array. | ||
1292 | - * | ||
1293 | - * Returns true for success, false in error cases. | ||
1294 | - */ | ||
1295 | -bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp) | ||
1296 | -{ | ||
1297 | - QObject *qobj; | ||
1298 | - | ||
1299 | - while (renames->from) { | ||
1300 | - if (qdict_haskey(qdict, renames->from)) { | ||
1301 | - if (qdict_haskey(qdict, renames->to)) { | ||
1302 | - error_setg(errp, "'%s' and its alias '%s' can't be used at the " | ||
1303 | - "same time", renames->to, renames->from); | ||
1304 | - return false; | 141 | - return false; |
1305 | - } | 142 | - } |
1306 | - | 143 | - } |
1307 | - qobj = qdict_get(qdict, renames->from); | 144 | - } |
1308 | - qdict_put_obj(qdict, renames->to, qobject_ref(qobj)); | 145 | - |
1309 | - qdict_del(qdict, renames->from); | ||
1310 | - } | ||
1311 | - | ||
1312 | - renames++; | ||
1313 | - } | ||
1314 | - return true; | 146 | - return true; |
1315 | -} | 147 | -} |
1316 | diff --git a/tests/check-block-qdict.c b/tests/check-block-qdict.c | 148 | - |
149 | -/** | ||
150 | - * iothread_vq_mapping_apply: | ||
151 | - * @list: The mapping of virtqueues to IOThreads. | ||
152 | - * @vq_aio_context: The array of AioContext pointers to fill in. | ||
153 | - * @num_queues: The length of @vq_aio_context. | ||
154 | - * @errp: If an error occurs, a pointer to the area to store the error. | ||
155 | - * | ||
156 | - * Fill in the AioContext for each virtqueue in the @vq_aio_context array given | ||
157 | - * the iothread-vq-mapping parameter in @list. | ||
158 | - * | ||
159 | - * iothread_vq_mapping_cleanup() must be called to free IOThread object | ||
160 | - * references after this function returns success. | ||
161 | - * | ||
162 | - * Returns: %true on success, %false on failure. | ||
163 | - **/ | ||
164 | -static bool iothread_vq_mapping_apply( | ||
165 | - IOThreadVirtQueueMappingList *list, | ||
166 | - AioContext **vq_aio_context, | ||
167 | - uint16_t num_queues, | ||
168 | - Error **errp) | ||
169 | -{ | ||
170 | - IOThreadVirtQueueMappingList *node; | ||
171 | - size_t num_iothreads = 0; | ||
172 | - size_t cur_iothread = 0; | ||
173 | - | ||
174 | - if (!iothread_vq_mapping_validate(list, num_queues, errp)) { | ||
175 | - return false; | ||
176 | - } | ||
177 | - | ||
178 | - for (node = list; node; node = node->next) { | ||
179 | - num_iothreads++; | ||
180 | - } | ||
181 | - | ||
182 | - for (node = list; node; node = node->next) { | ||
183 | - IOThread *iothread = iothread_by_id(node->value->iothread); | ||
184 | - AioContext *ctx = iothread_get_aio_context(iothread); | ||
185 | - | ||
186 | - /* Released in virtio_blk_vq_aio_context_cleanup() */ | ||
187 | - object_ref(OBJECT(iothread)); | ||
188 | - | ||
189 | - if (node->value->vqs) { | ||
190 | - uint16List *vq; | ||
191 | - | ||
192 | - /* Explicit vq:IOThread assignment */ | ||
193 | - for (vq = node->value->vqs; vq; vq = vq->next) { | ||
194 | - assert(vq->value < num_queues); | ||
195 | - vq_aio_context[vq->value] = ctx; | ||
196 | - } | ||
197 | - } else { | ||
198 | - /* Round-robin vq:IOThread assignment */ | ||
199 | - for (unsigned i = cur_iothread; i < num_queues; | ||
200 | - i += num_iothreads) { | ||
201 | - vq_aio_context[i] = ctx; | ||
202 | - } | ||
203 | - } | ||
204 | - | ||
205 | - cur_iothread++; | ||
206 | - } | ||
207 | - | ||
208 | - return true; | ||
209 | -} | ||
210 | - | ||
211 | -/** | ||
212 | - * iothread_vq_mapping_cleanup: | ||
213 | - * @list: The mapping of virtqueues to IOThreads. | ||
214 | - * | ||
215 | - * Release IOThread object references that were acquired by | ||
216 | - * iothread_vq_mapping_apply(). | ||
217 | - */ | ||
218 | -static void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) | ||
219 | -{ | ||
220 | - IOThreadVirtQueueMappingList *node; | ||
221 | - | ||
222 | - for (node = list; node; node = node->next) { | ||
223 | - IOThread *iothread = iothread_by_id(node->value->iothread); | ||
224 | - object_unref(OBJECT(iothread)); | ||
225 | - } | ||
226 | -} | ||
227 | - | ||
228 | /* Context: BQL held */ | ||
229 | static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp) | ||
230 | { | ||
231 | diff --git a/hw/virtio/iothread-vq-mapping.c b/hw/virtio/iothread-vq-mapping.c | ||
1317 | new file mode 100644 | 232 | new file mode 100644 |
1318 | index XXXXXXX..XXXXXXX | 233 | index XXXXXXX..XXXXXXX |
1319 | --- /dev/null | 234 | --- /dev/null |
1320 | +++ b/tests/check-block-qdict.c | 235 | +++ b/hw/virtio/iothread-vq-mapping.c |
1321 | @@ -XXX,XX +XXX,XX @@ | 236 | @@ -XXX,XX +XXX,XX @@ |
1322 | +/* | 237 | +/* |
1323 | + * Unit-tests for Block layer QDict extras | 238 | + * IOThread Virtqueue Mapping |
1324 | + * | 239 | + * |
1325 | + * Copyright (c) 2013-2018 Red Hat, Inc. | 240 | + * Copyright Red Hat, Inc |
1326 | + * | 241 | + * |
1327 | + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. | 242 | + * SPDX-License-Identifier: GPL-2.0-only |
1328 | + * See the COPYING.LIB file in the top-level directory. | ||
1329 | + */ | 243 | + */ |
1330 | + | 244 | + |
1331 | +#include "qemu/osdep.h" | 245 | +#include "qemu/osdep.h" |
1332 | +#include "block/qdict.h" | 246 | +#include "system/iothread.h" |
1333 | +#include "qapi/qmp/qlist.h" | 247 | +#include "hw/virtio/iothread-vq-mapping.h" |
1334 | +#include "qapi/qmp/qnum.h" | 248 | + |
1335 | +#include "qapi/error.h" | 249 | +static bool |
1336 | + | 250 | +iothread_vq_mapping_validate(IOThreadVirtQueueMappingList *list, uint16_t |
1337 | +static void qdict_defaults_test(void) | 251 | + num_queues, Error **errp) |
1338 | +{ | 252 | +{ |
1339 | + QDict *dict, *copy; | 253 | + g_autofree unsigned long *vqs = bitmap_new(num_queues); |
1340 | + | 254 | + g_autoptr(GHashTable) iothreads = |
1341 | + dict = qdict_new(); | 255 | + g_hash_table_new(g_str_hash, g_str_equal); |
1342 | + copy = qdict_new(); | 256 | + |
1343 | + | 257 | + for (IOThreadVirtQueueMappingList *node = list; node; node = node->next) { |
1344 | + qdict_set_default_str(dict, "foo", "abc"); | 258 | + const char *name = node->value->iothread; |
1345 | + qdict_set_default_str(dict, "foo", "def"); | 259 | + uint16List *vq; |
1346 | + g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "abc"); | 260 | + |
1347 | + qdict_set_default_str(dict, "bar", "ghi"); | 261 | + if (!iothread_by_id(name)) { |
1348 | + | 262 | + error_setg(errp, "IOThread \"%s\" object does not exist", name); |
1349 | + qdict_copy_default(copy, dict, "foo"); | 263 | + return false; |
1350 | + g_assert_cmpstr(qdict_get_str(copy, "foo"), ==, "abc"); | 264 | + } |
1351 | + qdict_set_default_str(copy, "bar", "xyz"); | 265 | + |
1352 | + qdict_copy_default(copy, dict, "bar"); | 266 | + if (!g_hash_table_add(iothreads, (gpointer)name)) { |
1353 | + g_assert_cmpstr(qdict_get_str(copy, "bar"), ==, "xyz"); | 267 | + error_setg(errp, |
1354 | + | 268 | + "duplicate IOThread name \"%s\" in iothread-vq-mapping", |
1355 | + qobject_unref(copy); | 269 | + name); |
1356 | + qobject_unref(dict); | 270 | + return false; |
271 | + } | ||
272 | + | ||
273 | + if (node != list) { | ||
274 | + if (!!node->value->vqs != !!list->value->vqs) { | ||
275 | + error_setg(errp, "either all items in iothread-vq-mapping " | ||
276 | + "must have vqs or none of them must have it"); | ||
277 | + return false; | ||
278 | + } | ||
279 | + } | ||
280 | + | ||
281 | + for (vq = node->value->vqs; vq; vq = vq->next) { | ||
282 | + if (vq->value >= num_queues) { | ||
283 | + error_setg(errp, "vq index %u for IOThread \"%s\" must be " | ||
284 | + "less than num_queues %u in iothread-vq-mapping", | ||
285 | + vq->value, name, num_queues); | ||
286 | + return false; | ||
287 | + } | ||
288 | + | ||
289 | + if (test_and_set_bit(vq->value, vqs)) { | ||
290 | + error_setg(errp, "cannot assign vq %u to IOThread \"%s\" " | ||
291 | + "because it is already assigned", vq->value, name); | ||
292 | + return false; | ||
293 | + } | ||
294 | + } | ||
295 | + } | ||
296 | + | ||
297 | + if (list->value->vqs) { | ||
298 | + for (uint16_t i = 0; i < num_queues; i++) { | ||
299 | + if (!test_bit(i, vqs)) { | ||
300 | + error_setg(errp, | ||
301 | + "missing vq %u IOThread assignment in iothread-vq-mapping", | ||
302 | + i); | ||
303 | + return false; | ||
304 | + } | ||
305 | + } | ||
306 | + } | ||
307 | + | ||
308 | + return true; | ||
1357 | +} | 309 | +} |
1358 | + | 310 | + |
1359 | +static void qdict_flatten_test(void) | 311 | +bool iothread_vq_mapping_apply( |
312 | + IOThreadVirtQueueMappingList *list, | ||
313 | + AioContext **vq_aio_context, | ||
314 | + uint16_t num_queues, | ||
315 | + Error **errp) | ||
1360 | +{ | 316 | +{ |
1361 | + QList *list1 = qlist_new(); | 317 | + IOThreadVirtQueueMappingList *node; |
1362 | + QList *list2 = qlist_new(); | 318 | + size_t num_iothreads = 0; |
1363 | + QDict *dict1 = qdict_new(); | 319 | + size_t cur_iothread = 0; |
1364 | + QDict *dict2 = qdict_new(); | 320 | + |
1365 | + QDict *dict3 = qdict_new(); | 321 | + if (!iothread_vq_mapping_validate(list, num_queues, errp)) { |
1366 | + | 322 | + return false; |
1367 | + /* | 323 | + } |
1368 | + * Test the flattening of | 324 | + |
1369 | + * | 325 | + for (node = list; node; node = node->next) { |
1370 | + * { | 326 | + num_iothreads++; |
1371 | + * "e": [ | 327 | + } |
1372 | + * 42, | 328 | + |
1373 | + * [ | 329 | + for (node = list; node; node = node->next) { |
1374 | + * 23, | 330 | + IOThread *iothread = iothread_by_id(node->value->iothread); |
1375 | + * 66, | 331 | + AioContext *ctx = iothread_get_aio_context(iothread); |
1376 | + * { | 332 | + |
1377 | + * "a": 0, | 333 | + /* Released in virtio_blk_vq_aio_context_cleanup() */ |
1378 | + * "b": 1 | 334 | + object_ref(OBJECT(iothread)); |
1379 | + * } | 335 | + |
1380 | + * ] | 336 | + if (node->value->vqs) { |
1381 | + * ], | 337 | + uint16List *vq; |
1382 | + * "f": { | 338 | + |
1383 | + * "c": 2, | 339 | + /* Explicit vq:IOThread assignment */ |
1384 | + * "d": 3, | 340 | + for (vq = node->value->vqs; vq; vq = vq->next) { |
1385 | + * }, | 341 | + assert(vq->value < num_queues); |
1386 | + * "g": 4 | 342 | + vq_aio_context[vq->value] = ctx; |
1387 | + * } | 343 | + } |
1388 | + * | 344 | + } else { |
1389 | + * to | 345 | + /* Round-robin vq:IOThread assignment */ |
1390 | + * | 346 | + for (unsigned i = cur_iothread; i < num_queues; |
1391 | + * { | 347 | + i += num_iothreads) { |
1392 | + * "e.0": 42, | 348 | + vq_aio_context[i] = ctx; |
1393 | + * "e.1.0": 23, | 349 | + } |
1394 | + * "e.1.1": 66, | 350 | + } |
1395 | + * "e.1.2.a": 0, | 351 | + |
1396 | + * "e.1.2.b": 1, | 352 | + cur_iothread++; |
1397 | + * "f.c": 2, | 353 | + } |
1398 | + * "f.d": 3, | 354 | + |
1399 | + * "g": 4 | 355 | + return true; |
1400 | + * } | ||
1401 | + */ | ||
1402 | + | ||
1403 | + qdict_put_int(dict1, "a", 0); | ||
1404 | + qdict_put_int(dict1, "b", 1); | ||
1405 | + | ||
1406 | + qlist_append_int(list1, 23); | ||
1407 | + qlist_append_int(list1, 66); | ||
1408 | + qlist_append(list1, dict1); | ||
1409 | + qlist_append_int(list2, 42); | ||
1410 | + qlist_append(list2, list1); | ||
1411 | + | ||
1412 | + qdict_put_int(dict2, "c", 2); | ||
1413 | + qdict_put_int(dict2, "d", 3); | ||
1414 | + qdict_put(dict3, "e", list2); | ||
1415 | + qdict_put(dict3, "f", dict2); | ||
1416 | + qdict_put_int(dict3, "g", 4); | ||
1417 | + | ||
1418 | + qdict_flatten(dict3); | ||
1419 | + | ||
1420 | + g_assert(qdict_get_int(dict3, "e.0") == 42); | ||
1421 | + g_assert(qdict_get_int(dict3, "e.1.0") == 23); | ||
1422 | + g_assert(qdict_get_int(dict3, "e.1.1") == 66); | ||
1423 | + g_assert(qdict_get_int(dict3, "e.1.2.a") == 0); | ||
1424 | + g_assert(qdict_get_int(dict3, "e.1.2.b") == 1); | ||
1425 | + g_assert(qdict_get_int(dict3, "f.c") == 2); | ||
1426 | + g_assert(qdict_get_int(dict3, "f.d") == 3); | ||
1427 | + g_assert(qdict_get_int(dict3, "g") == 4); | ||
1428 | + | ||
1429 | + g_assert(qdict_size(dict3) == 8); | ||
1430 | + | ||
1431 | + qobject_unref(dict3); | ||
1432 | +} | 356 | +} |
1433 | + | 357 | + |
1434 | +static void qdict_array_split_test(void) | 358 | +void iothread_vq_mapping_cleanup(IOThreadVirtQueueMappingList *list) |
1435 | +{ | 359 | +{ |
1436 | + QDict *test_dict = qdict_new(); | 360 | + IOThreadVirtQueueMappingList *node; |
1437 | + QDict *dict1, *dict2; | 361 | + |
1438 | + QNum *int1; | 362 | + for (node = list; node; node = node->next) { |
1439 | + QList *test_list; | 363 | + IOThread *iothread = iothread_by_id(node->value->iothread); |
1440 | + | 364 | + object_unref(OBJECT(iothread)); |
1441 | + /* | 365 | + } |
1442 | + * Test the split of | ||
1443 | + * | ||
1444 | + * { | ||
1445 | + * "1.x": 0, | ||
1446 | + * "4.y": 1, | ||
1447 | + * "0.a": 42, | ||
1448 | + * "o.o": 7, | ||
1449 | + * "0.b": 23, | ||
1450 | + * "2": 66 | ||
1451 | + * } | ||
1452 | + * | ||
1453 | + * to | ||
1454 | + * | ||
1455 | + * [ | ||
1456 | + * { | ||
1457 | + * "a": 42, | ||
1458 | + * "b": 23 | ||
1459 | + * }, | ||
1460 | + * { | ||
1461 | + * "x": 0 | ||
1462 | + * }, | ||
1463 | + * 66 | ||
1464 | + * ] | ||
1465 | + * | ||
1466 | + * and | ||
1467 | + * | ||
1468 | + * { | ||
1469 | + * "4.y": 1, | ||
1470 | + * "o.o": 7 | ||
1471 | + * } | ||
1472 | + * | ||
1473 | + * (remaining in the old QDict) | ||
1474 | + * | ||
1475 | + * This example is given in the comment of qdict_array_split(). | ||
1476 | + */ | ||
1477 | + | ||
1478 | + qdict_put_int(test_dict, "1.x", 0); | ||
1479 | + qdict_put_int(test_dict, "4.y", 1); | ||
1480 | + qdict_put_int(test_dict, "0.a", 42); | ||
1481 | + qdict_put_int(test_dict, "o.o", 7); | ||
1482 | + qdict_put_int(test_dict, "0.b", 23); | ||
1483 | + qdict_put_int(test_dict, "2", 66); | ||
1484 | + | ||
1485 | + qdict_array_split(test_dict, &test_list); | ||
1486 | + | ||
1487 | + dict1 = qobject_to(QDict, qlist_pop(test_list)); | ||
1488 | + dict2 = qobject_to(QDict, qlist_pop(test_list)); | ||
1489 | + int1 = qobject_to(QNum, qlist_pop(test_list)); | ||
1490 | + | ||
1491 | + g_assert(dict1); | ||
1492 | + g_assert(dict2); | ||
1493 | + g_assert(int1); | ||
1494 | + g_assert(qlist_empty(test_list)); | ||
1495 | + | ||
1496 | + qobject_unref(test_list); | ||
1497 | + | ||
1498 | + g_assert(qdict_get_int(dict1, "a") == 42); | ||
1499 | + g_assert(qdict_get_int(dict1, "b") == 23); | ||
1500 | + | ||
1501 | + g_assert(qdict_size(dict1) == 2); | ||
1502 | + | ||
1503 | + qobject_unref(dict1); | ||
1504 | + | ||
1505 | + g_assert(qdict_get_int(dict2, "x") == 0); | ||
1506 | + | ||
1507 | + g_assert(qdict_size(dict2) == 1); | ||
1508 | + | ||
1509 | + qobject_unref(dict2); | ||
1510 | + | ||
1511 | + g_assert_cmpint(qnum_get_int(int1), ==, 66); | ||
1512 | + | ||
1513 | + qobject_unref(int1); | ||
1514 | + | ||
1515 | + g_assert(qdict_get_int(test_dict, "4.y") == 1); | ||
1516 | + g_assert(qdict_get_int(test_dict, "o.o") == 7); | ||
1517 | + | ||
1518 | + g_assert(qdict_size(test_dict) == 2); | ||
1519 | + | ||
1520 | + qobject_unref(test_dict); | ||
1521 | + | ||
1522 | + /* | ||
1523 | + * Test the split of | ||
1524 | + * | ||
1525 | + * { | ||
1526 | + * "0": 42, | ||
1527 | + * "1": 23, | ||
1528 | + * "1.x": 84 | ||
1529 | + * } | ||
1530 | + * | ||
1531 | + * to | ||
1532 | + * | ||
1533 | + * [ | ||
1534 | + * 42 | ||
1535 | + * ] | ||
1536 | + * | ||
1537 | + * and | ||
1538 | + * | ||
1539 | + * { | ||
1540 | + * "1": 23, | ||
1541 | + * "1.x": 84 | ||
1542 | + * } | ||
1543 | + * | ||
1544 | + * That is, test whether splitting stops if there is both an entry with key | ||
1545 | + * of "%u" and other entries with keys prefixed "%u." for the same index. | ||
1546 | + */ | ||
1547 | + | ||
1548 | + test_dict = qdict_new(); | ||
1549 | + | ||
1550 | + qdict_put_int(test_dict, "0", 42); | ||
1551 | + qdict_put_int(test_dict, "1", 23); | ||
1552 | + qdict_put_int(test_dict, "1.x", 84); | ||
1553 | + | ||
1554 | + qdict_array_split(test_dict, &test_list); | ||
1555 | + | ||
1556 | + int1 = qobject_to(QNum, qlist_pop(test_list)); | ||
1557 | + | ||
1558 | + g_assert(int1); | ||
1559 | + g_assert(qlist_empty(test_list)); | ||
1560 | + | ||
1561 | + qobject_unref(test_list); | ||
1562 | + | ||
1563 | + g_assert_cmpint(qnum_get_int(int1), ==, 42); | ||
1564 | + | ||
1565 | + qobject_unref(int1); | ||
1566 | + | ||
1567 | + g_assert(qdict_get_int(test_dict, "1") == 23); | ||
1568 | + g_assert(qdict_get_int(test_dict, "1.x") == 84); | ||
1569 | + | ||
1570 | + g_assert(qdict_size(test_dict) == 2); | ||
1571 | + | ||
1572 | + qobject_unref(test_dict); | ||
1573 | +} | 366 | +} |
1574 | + | 367 | + |
1575 | +static void qdict_array_entries_test(void) | 368 | diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build |
1576 | +{ | ||
1577 | + QDict *dict = qdict_new(); | ||
1578 | + | ||
1579 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); | ||
1580 | + | ||
1581 | + qdict_put_int(dict, "bar", 0); | ||
1582 | + qdict_put_int(dict, "baz.0", 0); | ||
1583 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); | ||
1584 | + | ||
1585 | + qdict_put_int(dict, "foo.1", 0); | ||
1586 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); | ||
1587 | + qdict_put_int(dict, "foo.0", 0); | ||
1588 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2); | ||
1589 | + qdict_put_int(dict, "foo.bar", 0); | ||
1590 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); | ||
1591 | + qdict_del(dict, "foo.bar"); | ||
1592 | + | ||
1593 | + qdict_put_int(dict, "foo.2.a", 0); | ||
1594 | + qdict_put_int(dict, "foo.2.b", 0); | ||
1595 | + qdict_put_int(dict, "foo.2.c", 0); | ||
1596 | + g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3); | ||
1597 | + g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
1598 | + | ||
1599 | + qobject_unref(dict); | ||
1600 | + | ||
1601 | + dict = qdict_new(); | ||
1602 | + qdict_put_int(dict, "1", 0); | ||
1603 | + g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
1604 | + qdict_put_int(dict, "0", 0); | ||
1605 | + g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2); | ||
1606 | + qdict_put_int(dict, "bar", 0); | ||
1607 | + g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
1608 | + qdict_del(dict, "bar"); | ||
1609 | + | ||
1610 | + qdict_put_int(dict, "2.a", 0); | ||
1611 | + qdict_put_int(dict, "2.b", 0); | ||
1612 | + qdict_put_int(dict, "2.c", 0); | ||
1613 | + g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3); | ||
1614 | + | ||
1615 | + qobject_unref(dict); | ||
1616 | +} | ||
1617 | + | ||
1618 | +static void qdict_join_test(void) | ||
1619 | +{ | ||
1620 | + QDict *dict1, *dict2; | ||
1621 | + bool overwrite = false; | ||
1622 | + int i; | ||
1623 | + | ||
1624 | + dict1 = qdict_new(); | ||
1625 | + dict2 = qdict_new(); | ||
1626 | + | ||
1627 | + /* Test everything once without overwrite and once with */ | ||
1628 | + do { | ||
1629 | + /* Test empty dicts */ | ||
1630 | + qdict_join(dict1, dict2, overwrite); | ||
1631 | + | ||
1632 | + g_assert(qdict_size(dict1) == 0); | ||
1633 | + g_assert(qdict_size(dict2) == 0); | ||
1634 | + | ||
1635 | + /* First iteration: Test movement */ | ||
1636 | + /* Second iteration: Test empty source and non-empty destination */ | ||
1637 | + qdict_put_int(dict2, "foo", 42); | ||
1638 | + | ||
1639 | + for (i = 0; i < 2; i++) { | ||
1640 | + qdict_join(dict1, dict2, overwrite); | ||
1641 | + | ||
1642 | + g_assert(qdict_size(dict1) == 1); | ||
1643 | + g_assert(qdict_size(dict2) == 0); | ||
1644 | + | ||
1645 | + g_assert(qdict_get_int(dict1, "foo") == 42); | ||
1646 | + } | ||
1647 | + | ||
1648 | + /* Test non-empty source and destination without conflict */ | ||
1649 | + qdict_put_int(dict2, "bar", 23); | ||
1650 | + | ||
1651 | + qdict_join(dict1, dict2, overwrite); | ||
1652 | + | ||
1653 | + g_assert(qdict_size(dict1) == 2); | ||
1654 | + g_assert(qdict_size(dict2) == 0); | ||
1655 | + | ||
1656 | + g_assert(qdict_get_int(dict1, "foo") == 42); | ||
1657 | + g_assert(qdict_get_int(dict1, "bar") == 23); | ||
1658 | + | ||
1659 | + /* Test conflict */ | ||
1660 | + qdict_put_int(dict2, "foo", 84); | ||
1661 | + | ||
1662 | + qdict_join(dict1, dict2, overwrite); | ||
1663 | + | ||
1664 | + g_assert(qdict_size(dict1) == 2); | ||
1665 | + g_assert(qdict_size(dict2) == !overwrite); | ||
1666 | + | ||
1667 | + g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42)); | ||
1668 | + g_assert(qdict_get_int(dict1, "bar") == 23); | ||
1669 | + | ||
1670 | + if (!overwrite) { | ||
1671 | + g_assert(qdict_get_int(dict2, "foo") == 84); | ||
1672 | + } | ||
1673 | + | ||
1674 | + /* Check the references */ | ||
1675 | + g_assert(qdict_get(dict1, "foo")->base.refcnt == 1); | ||
1676 | + g_assert(qdict_get(dict1, "bar")->base.refcnt == 1); | ||
1677 | + | ||
1678 | + if (!overwrite) { | ||
1679 | + g_assert(qdict_get(dict2, "foo")->base.refcnt == 1); | ||
1680 | + } | ||
1681 | + | ||
1682 | + /* Clean up */ | ||
1683 | + qdict_del(dict1, "foo"); | ||
1684 | + qdict_del(dict1, "bar"); | ||
1685 | + | ||
1686 | + if (!overwrite) { | ||
1687 | + qdict_del(dict2, "foo"); | ||
1688 | + } | ||
1689 | + } while (overwrite ^= true); | ||
1690 | + | ||
1691 | + qobject_unref(dict1); | ||
1692 | + qobject_unref(dict2); | ||
1693 | +} | ||
1694 | + | ||
1695 | +static void qdict_crumple_test_recursive(void) | ||
1696 | +{ | ||
1697 | + QDict *src, *dst, *rule, *vnc, *acl, *listen; | ||
1698 | + QList *rules; | ||
1699 | + | ||
1700 | + src = qdict_new(); | ||
1701 | + qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); | ||
1702 | + qdict_put_str(src, "vnc.listen.port", "5901"); | ||
1703 | + qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); | ||
1704 | + qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); | ||
1705 | + qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); | ||
1706 | + qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); | ||
1707 | + qdict_put_str(src, "vnc.acl.default", "deny"); | ||
1708 | + qdict_put_str(src, "vnc.acl..name", "acl0"); | ||
1709 | + qdict_put_str(src, "vnc.acl.rule..name", "acl0"); | ||
1710 | + | ||
1711 | + dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); | ||
1712 | + g_assert(dst); | ||
1713 | + g_assert_cmpint(qdict_size(dst), ==, 1); | ||
1714 | + | ||
1715 | + vnc = qdict_get_qdict(dst, "vnc"); | ||
1716 | + g_assert(vnc); | ||
1717 | + g_assert_cmpint(qdict_size(vnc), ==, 3); | ||
1718 | + | ||
1719 | + listen = qdict_get_qdict(vnc, "listen"); | ||
1720 | + g_assert(listen); | ||
1721 | + g_assert_cmpint(qdict_size(listen), ==, 2); | ||
1722 | + g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); | ||
1723 | + g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); | ||
1724 | + | ||
1725 | + acl = qdict_get_qdict(vnc, "acl"); | ||
1726 | + g_assert(acl); | ||
1727 | + g_assert_cmpint(qdict_size(acl), ==, 3); | ||
1728 | + | ||
1729 | + rules = qdict_get_qlist(acl, "rules"); | ||
1730 | + g_assert(rules); | ||
1731 | + g_assert_cmpint(qlist_size(rules), ==, 2); | ||
1732 | + | ||
1733 | + rule = qobject_to(QDict, qlist_pop(rules)); | ||
1734 | + g_assert(rule); | ||
1735 | + g_assert_cmpint(qdict_size(rule), ==, 2); | ||
1736 | + g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); | ||
1737 | + g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy")); | ||
1738 | + qobject_unref(rule); | ||
1739 | + | ||
1740 | + rule = qobject_to(QDict, qlist_pop(rules)); | ||
1741 | + g_assert(rule); | ||
1742 | + g_assert_cmpint(qdict_size(rule), ==, 2); | ||
1743 | + g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); | ||
1744 | + g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy")); | ||
1745 | + qobject_unref(rule); | ||
1746 | + | ||
1747 | + /* With recursive crumpling, we should see all names unescaped */ | ||
1748 | + g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); | ||
1749 | + g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); | ||
1750 | + | ||
1751 | + qobject_unref(src); | ||
1752 | + qobject_unref(dst); | ||
1753 | +} | ||
1754 | + | ||
1755 | +static void qdict_crumple_test_empty(void) | ||
1756 | +{ | ||
1757 | + QDict *src, *dst; | ||
1758 | + | ||
1759 | + src = qdict_new(); | ||
1760 | + | ||
1761 | + dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); | ||
1762 | + | ||
1763 | + g_assert_cmpint(qdict_size(dst), ==, 0); | ||
1764 | + | ||
1765 | + qobject_unref(src); | ||
1766 | + qobject_unref(dst); | ||
1767 | +} | ||
1768 | + | ||
1769 | +static int qdict_count_entries(QDict *dict) | ||
1770 | +{ | ||
1771 | + const QDictEntry *e; | ||
1772 | + int count = 0; | ||
1773 | + | ||
1774 | + for (e = qdict_first(dict); e; e = qdict_next(dict, e)) { | ||
1775 | + count++; | ||
1776 | + } | ||
1777 | + | ||
1778 | + return count; | ||
1779 | +} | ||
1780 | + | ||
1781 | +static void qdict_rename_keys_test(void) | ||
1782 | +{ | ||
1783 | + QDict *dict = qdict_new(); | ||
1784 | + QDict *copy; | ||
1785 | + QDictRenames *renames; | ||
1786 | + Error *local_err = NULL; | ||
1787 | + | ||
1788 | + qdict_put_str(dict, "abc", "foo"); | ||
1789 | + qdict_put_str(dict, "abcdef", "bar"); | ||
1790 | + qdict_put_int(dict, "number", 42); | ||
1791 | + qdict_put_bool(dict, "flag", true); | ||
1792 | + qdict_put_null(dict, "nothing"); | ||
1793 | + | ||
1794 | + /* Empty rename list */ | ||
1795 | + renames = (QDictRenames[]) { | ||
1796 | + { NULL, "this can be anything" } | ||
1797 | + }; | ||
1798 | + copy = qdict_clone_shallow(dict); | ||
1799 | + qdict_rename_keys(copy, renames, &error_abort); | ||
1800 | + | ||
1801 | + g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "foo"); | ||
1802 | + g_assert_cmpstr(qdict_get_str(copy, "abcdef"), ==, "bar"); | ||
1803 | + g_assert_cmpint(qdict_get_int(copy, "number"), ==, 42); | ||
1804 | + g_assert_cmpint(qdict_get_bool(copy, "flag"), ==, true); | ||
1805 | + g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL); | ||
1806 | + g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
1807 | + | ||
1808 | + qobject_unref(copy); | ||
1809 | + | ||
1810 | + /* Simple rename of all entries */ | ||
1811 | + renames = (QDictRenames[]) { | ||
1812 | + { "abc", "str1" }, | ||
1813 | + { "abcdef", "str2" }, | ||
1814 | + { "number", "int" }, | ||
1815 | + { "flag", "bool" }, | ||
1816 | + { "nothing", "null" }, | ||
1817 | + { NULL , NULL } | ||
1818 | + }; | ||
1819 | + copy = qdict_clone_shallow(dict); | ||
1820 | + qdict_rename_keys(copy, renames, &error_abort); | ||
1821 | + | ||
1822 | + g_assert(!qdict_haskey(copy, "abc")); | ||
1823 | + g_assert(!qdict_haskey(copy, "abcdef")); | ||
1824 | + g_assert(!qdict_haskey(copy, "number")); | ||
1825 | + g_assert(!qdict_haskey(copy, "flag")); | ||
1826 | + g_assert(!qdict_haskey(copy, "nothing")); | ||
1827 | + | ||
1828 | + g_assert_cmpstr(qdict_get_str(copy, "str1"), ==, "foo"); | ||
1829 | + g_assert_cmpstr(qdict_get_str(copy, "str2"), ==, "bar"); | ||
1830 | + g_assert_cmpint(qdict_get_int(copy, "int"), ==, 42); | ||
1831 | + g_assert_cmpint(qdict_get_bool(copy, "bool"), ==, true); | ||
1832 | + g_assert(qobject_type(qdict_get(copy, "null")) == QTYPE_QNULL); | ||
1833 | + g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
1834 | + | ||
1835 | + qobject_unref(copy); | ||
1836 | + | ||
1837 | + /* Renames are processed top to bottom */ | ||
1838 | + renames = (QDictRenames[]) { | ||
1839 | + { "abc", "tmp" }, | ||
1840 | + { "abcdef", "abc" }, | ||
1841 | + { "number", "abcdef" }, | ||
1842 | + { "flag", "number" }, | ||
1843 | + { "nothing", "flag" }, | ||
1844 | + { "tmp", "nothing" }, | ||
1845 | + { NULL , NULL } | ||
1846 | + }; | ||
1847 | + copy = qdict_clone_shallow(dict); | ||
1848 | + qdict_rename_keys(copy, renames, &error_abort); | ||
1849 | + | ||
1850 | + g_assert_cmpstr(qdict_get_str(copy, "nothing"), ==, "foo"); | ||
1851 | + g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "bar"); | ||
1852 | + g_assert_cmpint(qdict_get_int(copy, "abcdef"), ==, 42); | ||
1853 | + g_assert_cmpint(qdict_get_bool(copy, "number"), ==, true); | ||
1854 | + g_assert(qobject_type(qdict_get(copy, "flag")) == QTYPE_QNULL); | ||
1855 | + g_assert(!qdict_haskey(copy, "tmp")); | ||
1856 | + g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
1857 | + | ||
1858 | + qobject_unref(copy); | ||
1859 | + | ||
1860 | + /* Conflicting rename */ | ||
1861 | + renames = (QDictRenames[]) { | ||
1862 | + { "abcdef", "abc" }, | ||
1863 | + { NULL , NULL } | ||
1864 | + }; | ||
1865 | + copy = qdict_clone_shallow(dict); | ||
1866 | + qdict_rename_keys(copy, renames, &local_err); | ||
1867 | + | ||
1868 | + g_assert(local_err != NULL); | ||
1869 | + error_free(local_err); | ||
1870 | + local_err = NULL; | ||
1871 | + | ||
1872 | + g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "foo"); | ||
1873 | + g_assert_cmpstr(qdict_get_str(copy, "abcdef"), ==, "bar"); | ||
1874 | + g_assert_cmpint(qdict_get_int(copy, "number"), ==, 42); | ||
1875 | + g_assert_cmpint(qdict_get_bool(copy, "flag"), ==, true); | ||
1876 | + g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL); | ||
1877 | + g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
1878 | + | ||
1879 | + qobject_unref(copy); | ||
1880 | + | ||
1881 | + /* Renames in an empty dict */ | ||
1882 | + renames = (QDictRenames[]) { | ||
1883 | + { "abcdef", "abc" }, | ||
1884 | + { NULL , NULL } | ||
1885 | + }; | ||
1886 | + | ||
1887 | + qobject_unref(dict); | ||
1888 | + dict = qdict_new(); | ||
1889 | + | ||
1890 | + qdict_rename_keys(dict, renames, &error_abort); | ||
1891 | + g_assert(qdict_first(dict) == NULL); | ||
1892 | + | ||
1893 | + qobject_unref(dict); | ||
1894 | +} | ||
1895 | + | ||
1896 | +static void qdict_crumple_test_bad_inputs(void) | ||
1897 | +{ | ||
1898 | + QDict *src; | ||
1899 | + Error *error = NULL; | ||
1900 | + | ||
1901 | + src = qdict_new(); | ||
1902 | + /* rule.0 can't be both a string and a dict */ | ||
1903 | + qdict_put_str(src, "rule.0", "fred"); | ||
1904 | + qdict_put_str(src, "rule.0.policy", "allow"); | ||
1905 | + | ||
1906 | + g_assert(qdict_crumple(src, &error) == NULL); | ||
1907 | + g_assert(error != NULL); | ||
1908 | + error_free(error); | ||
1909 | + error = NULL; | ||
1910 | + qobject_unref(src); | ||
1911 | + | ||
1912 | + src = qdict_new(); | ||
1913 | + /* rule can't be both a list and a dict */ | ||
1914 | + qdict_put_str(src, "rule.0", "fred"); | ||
1915 | + qdict_put_str(src, "rule.a", "allow"); | ||
1916 | + | ||
1917 | + g_assert(qdict_crumple(src, &error) == NULL); | ||
1918 | + g_assert(error != NULL); | ||
1919 | + error_free(error); | ||
1920 | + error = NULL; | ||
1921 | + qobject_unref(src); | ||
1922 | + | ||
1923 | + src = qdict_new(); | ||
1924 | + /* The input should be flat, ie no dicts or lists */ | ||
1925 | + qdict_put(src, "rule.a", qdict_new()); | ||
1926 | + qdict_put_str(src, "rule.b", "allow"); | ||
1927 | + | ||
1928 | + g_assert(qdict_crumple(src, &error) == NULL); | ||
1929 | + g_assert(error != NULL); | ||
1930 | + error_free(error); | ||
1931 | + error = NULL; | ||
1932 | + qobject_unref(src); | ||
1933 | + | ||
1934 | + src = qdict_new(); | ||
1935 | + /* List indexes must not have gaps */ | ||
1936 | + qdict_put_str(src, "rule.0", "deny"); | ||
1937 | + qdict_put_str(src, "rule.3", "allow"); | ||
1938 | + | ||
1939 | + g_assert(qdict_crumple(src, &error) == NULL); | ||
1940 | + g_assert(error != NULL); | ||
1941 | + error_free(error); | ||
1942 | + error = NULL; | ||
1943 | + qobject_unref(src); | ||
1944 | + | ||
1945 | + src = qdict_new(); | ||
1946 | + /* List indexes must be in %zu format */ | ||
1947 | + qdict_put_str(src, "rule.0", "deny"); | ||
1948 | + qdict_put_str(src, "rule.+1", "allow"); | ||
1949 | + | ||
1950 | + g_assert(qdict_crumple(src, &error) == NULL); | ||
1951 | + g_assert(error != NULL); | ||
1952 | + error_free(error); | ||
1953 | + error = NULL; | ||
1954 | + qobject_unref(src); | ||
1955 | +} | ||
1956 | + | ||
1957 | +int main(int argc, char **argv) | ||
1958 | +{ | ||
1959 | + g_test_init(&argc, &argv, NULL); | ||
1960 | + | ||
1961 | + g_test_add_func("/public/defaults", qdict_defaults_test); | ||
1962 | + g_test_add_func("/public/flatten", qdict_flatten_test); | ||
1963 | + g_test_add_func("/public/array_split", qdict_array_split_test); | ||
1964 | + g_test_add_func("/public/array_entries", qdict_array_entries_test); | ||
1965 | + g_test_add_func("/public/join", qdict_join_test); | ||
1966 | + g_test_add_func("/public/crumple/recursive", | ||
1967 | + qdict_crumple_test_recursive); | ||
1968 | + g_test_add_func("/public/crumple/empty", | ||
1969 | + qdict_crumple_test_empty); | ||
1970 | + g_test_add_func("/public/crumple/bad_inputs", | ||
1971 | + qdict_crumple_test_bad_inputs); | ||
1972 | + | ||
1973 | + g_test_add_func("/public/rename_keys", qdict_rename_keys_test); | ||
1974 | + | ||
1975 | + return g_test_run(); | ||
1976 | +} | ||
1977 | diff --git a/tests/check-qdict.c b/tests/check-qdict.c | ||
1978 | index XXXXXXX..XXXXXXX 100644 | 369 | index XXXXXXX..XXXXXXX 100644 |
1979 | --- a/tests/check-qdict.c | 370 | --- a/hw/virtio/meson.build |
1980 | +++ b/tests/check-qdict.c | 371 | +++ b/hw/virtio/meson.build |
1981 | @@ -XXX,XX +XXX,XX @@ | 372 | @@ -XXX,XX +XXX,XX @@ |
1982 | */ | 373 | system_virtio_ss = ss.source_set() |
1983 | 374 | system_virtio_ss.add(files('virtio-bus.c')) | |
1984 | #include "qemu/osdep.h" | 375 | +system_virtio_ss.add(files('iothread-vq-mapping.c')) |
1985 | -#include "block/qdict.h" | 376 | system_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true: files('virtio-pci.c')) |
1986 | #include "qapi/qmp/qdict.h" | 377 | system_virtio_ss.add(when: 'CONFIG_VIRTIO_MMIO', if_true: files('virtio-mmio.c')) |
1987 | -#include "qapi/qmp/qlist.h" | 378 | system_virtio_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true: files('virtio-crypto.c')) |
1988 | -#include "qapi/qmp/qnum.h" | ||
1989 | -#include "qapi/qmp/qstring.h" | ||
1990 | -#include "qapi/error.h" | ||
1991 | -#include "qemu-common.h" | ||
1992 | |||
1993 | /* | ||
1994 | * Public Interface test-cases | ||
1995 | @@ -XXX,XX +XXX,XX @@ static void qdict_get_try_str_test(void) | ||
1996 | qobject_unref(tests_dict); | ||
1997 | } | ||
1998 | |||
1999 | -static void qdict_defaults_test(void) | ||
2000 | -{ | ||
2001 | - QDict *dict, *copy; | ||
2002 | - | ||
2003 | - dict = qdict_new(); | ||
2004 | - copy = qdict_new(); | ||
2005 | - | ||
2006 | - qdict_set_default_str(dict, "foo", "abc"); | ||
2007 | - qdict_set_default_str(dict, "foo", "def"); | ||
2008 | - g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "abc"); | ||
2009 | - qdict_set_default_str(dict, "bar", "ghi"); | ||
2010 | - | ||
2011 | - qdict_copy_default(copy, dict, "foo"); | ||
2012 | - g_assert_cmpstr(qdict_get_str(copy, "foo"), ==, "abc"); | ||
2013 | - qdict_set_default_str(copy, "bar", "xyz"); | ||
2014 | - qdict_copy_default(copy, dict, "bar"); | ||
2015 | - g_assert_cmpstr(qdict_get_str(copy, "bar"), ==, "xyz"); | ||
2016 | - | ||
2017 | - qobject_unref(copy); | ||
2018 | - qobject_unref(dict); | ||
2019 | -} | ||
2020 | - | ||
2021 | static void qdict_haskey_not_test(void) | ||
2022 | { | ||
2023 | QDict *tests_dict = qdict_new(); | ||
2024 | @@ -XXX,XX +XXX,XX @@ static void qdict_iterapi_test(void) | ||
2025 | qobject_unref(tests_dict); | ||
2026 | } | ||
2027 | |||
2028 | -static void qdict_flatten_test(void) | ||
2029 | -{ | ||
2030 | - QList *list1 = qlist_new(); | ||
2031 | - QList *list2 = qlist_new(); | ||
2032 | - QDict *dict1 = qdict_new(); | ||
2033 | - QDict *dict2 = qdict_new(); | ||
2034 | - QDict *dict3 = qdict_new(); | ||
2035 | - | ||
2036 | - /* | ||
2037 | - * Test the flattening of | ||
2038 | - * | ||
2039 | - * { | ||
2040 | - * "e": [ | ||
2041 | - * 42, | ||
2042 | - * [ | ||
2043 | - * 23, | ||
2044 | - * 66, | ||
2045 | - * { | ||
2046 | - * "a": 0, | ||
2047 | - * "b": 1 | ||
2048 | - * } | ||
2049 | - * ] | ||
2050 | - * ], | ||
2051 | - * "f": { | ||
2052 | - * "c": 2, | ||
2053 | - * "d": 3, | ||
2054 | - * }, | ||
2055 | - * "g": 4 | ||
2056 | - * } | ||
2057 | - * | ||
2058 | - * to | ||
2059 | - * | ||
2060 | - * { | ||
2061 | - * "e.0": 42, | ||
2062 | - * "e.1.0": 23, | ||
2063 | - * "e.1.1": 66, | ||
2064 | - * "e.1.2.a": 0, | ||
2065 | - * "e.1.2.b": 1, | ||
2066 | - * "f.c": 2, | ||
2067 | - * "f.d": 3, | ||
2068 | - * "g": 4 | ||
2069 | - * } | ||
2070 | - */ | ||
2071 | - | ||
2072 | - qdict_put_int(dict1, "a", 0); | ||
2073 | - qdict_put_int(dict1, "b", 1); | ||
2074 | - | ||
2075 | - qlist_append_int(list1, 23); | ||
2076 | - qlist_append_int(list1, 66); | ||
2077 | - qlist_append(list1, dict1); | ||
2078 | - qlist_append_int(list2, 42); | ||
2079 | - qlist_append(list2, list1); | ||
2080 | - | ||
2081 | - qdict_put_int(dict2, "c", 2); | ||
2082 | - qdict_put_int(dict2, "d", 3); | ||
2083 | - qdict_put(dict3, "e", list2); | ||
2084 | - qdict_put(dict3, "f", dict2); | ||
2085 | - qdict_put_int(dict3, "g", 4); | ||
2086 | - | ||
2087 | - qdict_flatten(dict3); | ||
2088 | - | ||
2089 | - g_assert(qdict_get_int(dict3, "e.0") == 42); | ||
2090 | - g_assert(qdict_get_int(dict3, "e.1.0") == 23); | ||
2091 | - g_assert(qdict_get_int(dict3, "e.1.1") == 66); | ||
2092 | - g_assert(qdict_get_int(dict3, "e.1.2.a") == 0); | ||
2093 | - g_assert(qdict_get_int(dict3, "e.1.2.b") == 1); | ||
2094 | - g_assert(qdict_get_int(dict3, "f.c") == 2); | ||
2095 | - g_assert(qdict_get_int(dict3, "f.d") == 3); | ||
2096 | - g_assert(qdict_get_int(dict3, "g") == 4); | ||
2097 | - | ||
2098 | - g_assert(qdict_size(dict3) == 8); | ||
2099 | - | ||
2100 | - qobject_unref(dict3); | ||
2101 | -} | ||
2102 | - | ||
2103 | -static void qdict_array_split_test(void) | ||
2104 | -{ | ||
2105 | - QDict *test_dict = qdict_new(); | ||
2106 | - QDict *dict1, *dict2; | ||
2107 | - QNum *int1; | ||
2108 | - QList *test_list; | ||
2109 | - | ||
2110 | - /* | ||
2111 | - * Test the split of | ||
2112 | - * | ||
2113 | - * { | ||
2114 | - * "1.x": 0, | ||
2115 | - * "4.y": 1, | ||
2116 | - * "0.a": 42, | ||
2117 | - * "o.o": 7, | ||
2118 | - * "0.b": 23, | ||
2119 | - * "2": 66 | ||
2120 | - * } | ||
2121 | - * | ||
2122 | - * to | ||
2123 | - * | ||
2124 | - * [ | ||
2125 | - * { | ||
2126 | - * "a": 42, | ||
2127 | - * "b": 23 | ||
2128 | - * }, | ||
2129 | - * { | ||
2130 | - * "x": 0 | ||
2131 | - * }, | ||
2132 | - * 66 | ||
2133 | - * ] | ||
2134 | - * | ||
2135 | - * and | ||
2136 | - * | ||
2137 | - * { | ||
2138 | - * "4.y": 1, | ||
2139 | - * "o.o": 7 | ||
2140 | - * } | ||
2141 | - * | ||
2142 | - * (remaining in the old QDict) | ||
2143 | - * | ||
2144 | - * This example is given in the comment of qdict_array_split(). | ||
2145 | - */ | ||
2146 | - | ||
2147 | - qdict_put_int(test_dict, "1.x", 0); | ||
2148 | - qdict_put_int(test_dict, "4.y", 1); | ||
2149 | - qdict_put_int(test_dict, "0.a", 42); | ||
2150 | - qdict_put_int(test_dict, "o.o", 7); | ||
2151 | - qdict_put_int(test_dict, "0.b", 23); | ||
2152 | - qdict_put_int(test_dict, "2", 66); | ||
2153 | - | ||
2154 | - qdict_array_split(test_dict, &test_list); | ||
2155 | - | ||
2156 | - dict1 = qobject_to(QDict, qlist_pop(test_list)); | ||
2157 | - dict2 = qobject_to(QDict, qlist_pop(test_list)); | ||
2158 | - int1 = qobject_to(QNum, qlist_pop(test_list)); | ||
2159 | - | ||
2160 | - g_assert(dict1); | ||
2161 | - g_assert(dict2); | ||
2162 | - g_assert(int1); | ||
2163 | - g_assert(qlist_empty(test_list)); | ||
2164 | - | ||
2165 | - qobject_unref(test_list); | ||
2166 | - | ||
2167 | - g_assert(qdict_get_int(dict1, "a") == 42); | ||
2168 | - g_assert(qdict_get_int(dict1, "b") == 23); | ||
2169 | - | ||
2170 | - g_assert(qdict_size(dict1) == 2); | ||
2171 | - | ||
2172 | - qobject_unref(dict1); | ||
2173 | - | ||
2174 | - g_assert(qdict_get_int(dict2, "x") == 0); | ||
2175 | - | ||
2176 | - g_assert(qdict_size(dict2) == 1); | ||
2177 | - | ||
2178 | - qobject_unref(dict2); | ||
2179 | - | ||
2180 | - g_assert_cmpint(qnum_get_int(int1), ==, 66); | ||
2181 | - | ||
2182 | - qobject_unref(int1); | ||
2183 | - | ||
2184 | - g_assert(qdict_get_int(test_dict, "4.y") == 1); | ||
2185 | - g_assert(qdict_get_int(test_dict, "o.o") == 7); | ||
2186 | - | ||
2187 | - g_assert(qdict_size(test_dict) == 2); | ||
2188 | - | ||
2189 | - qobject_unref(test_dict); | ||
2190 | - | ||
2191 | - /* | ||
2192 | - * Test the split of | ||
2193 | - * | ||
2194 | - * { | ||
2195 | - * "0": 42, | ||
2196 | - * "1": 23, | ||
2197 | - * "1.x": 84 | ||
2198 | - * } | ||
2199 | - * | ||
2200 | - * to | ||
2201 | - * | ||
2202 | - * [ | ||
2203 | - * 42 | ||
2204 | - * ] | ||
2205 | - * | ||
2206 | - * and | ||
2207 | - * | ||
2208 | - * { | ||
2209 | - * "1": 23, | ||
2210 | - * "1.x": 84 | ||
2211 | - * } | ||
2212 | - * | ||
2213 | - * That is, test whether splitting stops if there is both an entry with key | ||
2214 | - * of "%u" and other entries with keys prefixed "%u." for the same index. | ||
2215 | - */ | ||
2216 | - | ||
2217 | - test_dict = qdict_new(); | ||
2218 | - | ||
2219 | - qdict_put_int(test_dict, "0", 42); | ||
2220 | - qdict_put_int(test_dict, "1", 23); | ||
2221 | - qdict_put_int(test_dict, "1.x", 84); | ||
2222 | - | ||
2223 | - qdict_array_split(test_dict, &test_list); | ||
2224 | - | ||
2225 | - int1 = qobject_to(QNum, qlist_pop(test_list)); | ||
2226 | - | ||
2227 | - g_assert(int1); | ||
2228 | - g_assert(qlist_empty(test_list)); | ||
2229 | - | ||
2230 | - qobject_unref(test_list); | ||
2231 | - | ||
2232 | - g_assert_cmpint(qnum_get_int(int1), ==, 42); | ||
2233 | - | ||
2234 | - qobject_unref(int1); | ||
2235 | - | ||
2236 | - g_assert(qdict_get_int(test_dict, "1") == 23); | ||
2237 | - g_assert(qdict_get_int(test_dict, "1.x") == 84); | ||
2238 | - | ||
2239 | - g_assert(qdict_size(test_dict) == 2); | ||
2240 | - | ||
2241 | - qobject_unref(test_dict); | ||
2242 | -} | ||
2243 | - | ||
2244 | -static void qdict_array_entries_test(void) | ||
2245 | -{ | ||
2246 | - QDict *dict = qdict_new(); | ||
2247 | - | ||
2248 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); | ||
2249 | - | ||
2250 | - qdict_put_int(dict, "bar", 0); | ||
2251 | - qdict_put_int(dict, "baz.0", 0); | ||
2252 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0); | ||
2253 | - | ||
2254 | - qdict_put_int(dict, "foo.1", 0); | ||
2255 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); | ||
2256 | - qdict_put_int(dict, "foo.0", 0); | ||
2257 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2); | ||
2258 | - qdict_put_int(dict, "foo.bar", 0); | ||
2259 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL); | ||
2260 | - qdict_del(dict, "foo.bar"); | ||
2261 | - | ||
2262 | - qdict_put_int(dict, "foo.2.a", 0); | ||
2263 | - qdict_put_int(dict, "foo.2.b", 0); | ||
2264 | - qdict_put_int(dict, "foo.2.c", 0); | ||
2265 | - g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3); | ||
2266 | - g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
2267 | - | ||
2268 | - qobject_unref(dict); | ||
2269 | - | ||
2270 | - dict = qdict_new(); | ||
2271 | - qdict_put_int(dict, "1", 0); | ||
2272 | - g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
2273 | - qdict_put_int(dict, "0", 0); | ||
2274 | - g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2); | ||
2275 | - qdict_put_int(dict, "bar", 0); | ||
2276 | - g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL); | ||
2277 | - qdict_del(dict, "bar"); | ||
2278 | - | ||
2279 | - qdict_put_int(dict, "2.a", 0); | ||
2280 | - qdict_put_int(dict, "2.b", 0); | ||
2281 | - qdict_put_int(dict, "2.c", 0); | ||
2282 | - g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3); | ||
2283 | - | ||
2284 | - qobject_unref(dict); | ||
2285 | -} | ||
2286 | - | ||
2287 | -static void qdict_join_test(void) | ||
2288 | -{ | ||
2289 | - QDict *dict1, *dict2; | ||
2290 | - bool overwrite = false; | ||
2291 | - int i; | ||
2292 | - | ||
2293 | - dict1 = qdict_new(); | ||
2294 | - dict2 = qdict_new(); | ||
2295 | - | ||
2296 | - /* Test everything once without overwrite and once with */ | ||
2297 | - do | ||
2298 | - { | ||
2299 | - /* Test empty dicts */ | ||
2300 | - qdict_join(dict1, dict2, overwrite); | ||
2301 | - | ||
2302 | - g_assert(qdict_size(dict1) == 0); | ||
2303 | - g_assert(qdict_size(dict2) == 0); | ||
2304 | - | ||
2305 | - /* First iteration: Test movement */ | ||
2306 | - /* Second iteration: Test empty source and non-empty destination */ | ||
2307 | - qdict_put_int(dict2, "foo", 42); | ||
2308 | - | ||
2309 | - for (i = 0; i < 2; i++) { | ||
2310 | - qdict_join(dict1, dict2, overwrite); | ||
2311 | - | ||
2312 | - g_assert(qdict_size(dict1) == 1); | ||
2313 | - g_assert(qdict_size(dict2) == 0); | ||
2314 | - | ||
2315 | - g_assert(qdict_get_int(dict1, "foo") == 42); | ||
2316 | - } | ||
2317 | - | ||
2318 | - /* Test non-empty source and destination without conflict */ | ||
2319 | - qdict_put_int(dict2, "bar", 23); | ||
2320 | - | ||
2321 | - qdict_join(dict1, dict2, overwrite); | ||
2322 | - | ||
2323 | - g_assert(qdict_size(dict1) == 2); | ||
2324 | - g_assert(qdict_size(dict2) == 0); | ||
2325 | - | ||
2326 | - g_assert(qdict_get_int(dict1, "foo") == 42); | ||
2327 | - g_assert(qdict_get_int(dict1, "bar") == 23); | ||
2328 | - | ||
2329 | - /* Test conflict */ | ||
2330 | - qdict_put_int(dict2, "foo", 84); | ||
2331 | - | ||
2332 | - qdict_join(dict1, dict2, overwrite); | ||
2333 | - | ||
2334 | - g_assert(qdict_size(dict1) == 2); | ||
2335 | - g_assert(qdict_size(dict2) == !overwrite); | ||
2336 | - | ||
2337 | - g_assert(qdict_get_int(dict1, "foo") == (overwrite ? 84 : 42)); | ||
2338 | - g_assert(qdict_get_int(dict1, "bar") == 23); | ||
2339 | - | ||
2340 | - if (!overwrite) { | ||
2341 | - g_assert(qdict_get_int(dict2, "foo") == 84); | ||
2342 | - } | ||
2343 | - | ||
2344 | - /* Check the references */ | ||
2345 | - g_assert(qdict_get(dict1, "foo")->base.refcnt == 1); | ||
2346 | - g_assert(qdict_get(dict1, "bar")->base.refcnt == 1); | ||
2347 | - | ||
2348 | - if (!overwrite) { | ||
2349 | - g_assert(qdict_get(dict2, "foo")->base.refcnt == 1); | ||
2350 | - } | ||
2351 | - | ||
2352 | - /* Clean up */ | ||
2353 | - qdict_del(dict1, "foo"); | ||
2354 | - qdict_del(dict1, "bar"); | ||
2355 | - | ||
2356 | - if (!overwrite) { | ||
2357 | - qdict_del(dict2, "foo"); | ||
2358 | - } | ||
2359 | - } | ||
2360 | - while (overwrite ^= true); | ||
2361 | - | ||
2362 | - qobject_unref(dict1); | ||
2363 | - qobject_unref(dict2); | ||
2364 | -} | ||
2365 | - | ||
2366 | -static void qdict_crumple_test_recursive(void) | ||
2367 | -{ | ||
2368 | - QDict *src, *dst, *rule, *vnc, *acl, *listen; | ||
2369 | - QList *rules; | ||
2370 | - | ||
2371 | - src = qdict_new(); | ||
2372 | - qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); | ||
2373 | - qdict_put_str(src, "vnc.listen.port", "5901"); | ||
2374 | - qdict_put_str(src, "vnc.acl.rules.0.match", "fred"); | ||
2375 | - qdict_put_str(src, "vnc.acl.rules.0.policy", "allow"); | ||
2376 | - qdict_put_str(src, "vnc.acl.rules.1.match", "bob"); | ||
2377 | - qdict_put_str(src, "vnc.acl.rules.1.policy", "deny"); | ||
2378 | - qdict_put_str(src, "vnc.acl.default", "deny"); | ||
2379 | - qdict_put_str(src, "vnc.acl..name", "acl0"); | ||
2380 | - qdict_put_str(src, "vnc.acl.rule..name", "acl0"); | ||
2381 | - | ||
2382 | - dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); | ||
2383 | - g_assert(dst); | ||
2384 | - g_assert_cmpint(qdict_size(dst), ==, 1); | ||
2385 | - | ||
2386 | - vnc = qdict_get_qdict(dst, "vnc"); | ||
2387 | - g_assert(vnc); | ||
2388 | - g_assert_cmpint(qdict_size(vnc), ==, 3); | ||
2389 | - | ||
2390 | - listen = qdict_get_qdict(vnc, "listen"); | ||
2391 | - g_assert(listen); | ||
2392 | - g_assert_cmpint(qdict_size(listen), ==, 2); | ||
2393 | - g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr")); | ||
2394 | - g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port")); | ||
2395 | - | ||
2396 | - acl = qdict_get_qdict(vnc, "acl"); | ||
2397 | - g_assert(acl); | ||
2398 | - g_assert_cmpint(qdict_size(acl), ==, 3); | ||
2399 | - | ||
2400 | - rules = qdict_get_qlist(acl, "rules"); | ||
2401 | - g_assert(rules); | ||
2402 | - g_assert_cmpint(qlist_size(rules), ==, 2); | ||
2403 | - | ||
2404 | - rule = qobject_to(QDict, qlist_pop(rules)); | ||
2405 | - g_assert(rule); | ||
2406 | - g_assert_cmpint(qdict_size(rule), ==, 2); | ||
2407 | - g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match")); | ||
2408 | - g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy")); | ||
2409 | - qobject_unref(rule); | ||
2410 | - | ||
2411 | - rule = qobject_to(QDict, qlist_pop(rules)); | ||
2412 | - g_assert(rule); | ||
2413 | - g_assert_cmpint(qdict_size(rule), ==, 2); | ||
2414 | - g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match")); | ||
2415 | - g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy")); | ||
2416 | - qobject_unref(rule); | ||
2417 | - | ||
2418 | - /* With recursive crumpling, we should see all names unescaped */ | ||
2419 | - g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); | ||
2420 | - g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); | ||
2421 | - | ||
2422 | - qobject_unref(src); | ||
2423 | - qobject_unref(dst); | ||
2424 | -} | ||
2425 | - | ||
2426 | -static void qdict_crumple_test_empty(void) | ||
2427 | -{ | ||
2428 | - QDict *src, *dst; | ||
2429 | - | ||
2430 | - src = qdict_new(); | ||
2431 | - | ||
2432 | - dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); | ||
2433 | - | ||
2434 | - g_assert_cmpint(qdict_size(dst), ==, 0); | ||
2435 | - | ||
2436 | - qobject_unref(src); | ||
2437 | - qobject_unref(dst); | ||
2438 | -} | ||
2439 | - | ||
2440 | -static int qdict_count_entries(QDict *dict) | ||
2441 | -{ | ||
2442 | - const QDictEntry *e; | ||
2443 | - int count = 0; | ||
2444 | - | ||
2445 | - for (e = qdict_first(dict); e; e = qdict_next(dict, e)) { | ||
2446 | - count++; | ||
2447 | - } | ||
2448 | - | ||
2449 | - return count; | ||
2450 | -} | ||
2451 | - | ||
2452 | -static void qdict_rename_keys_test(void) | ||
2453 | -{ | ||
2454 | - QDict *dict = qdict_new(); | ||
2455 | - QDict *copy; | ||
2456 | - QDictRenames *renames; | ||
2457 | - Error *local_err = NULL; | ||
2458 | - | ||
2459 | - qdict_put_str(dict, "abc", "foo"); | ||
2460 | - qdict_put_str(dict, "abcdef", "bar"); | ||
2461 | - qdict_put_int(dict, "number", 42); | ||
2462 | - qdict_put_bool(dict, "flag", true); | ||
2463 | - qdict_put_null(dict, "nothing"); | ||
2464 | - | ||
2465 | - /* Empty rename list */ | ||
2466 | - renames = (QDictRenames[]) { | ||
2467 | - { NULL, "this can be anything" } | ||
2468 | - }; | ||
2469 | - copy = qdict_clone_shallow(dict); | ||
2470 | - qdict_rename_keys(copy, renames, &error_abort); | ||
2471 | - | ||
2472 | - g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "foo"); | ||
2473 | - g_assert_cmpstr(qdict_get_str(copy, "abcdef"), ==, "bar"); | ||
2474 | - g_assert_cmpint(qdict_get_int(copy, "number"), ==, 42); | ||
2475 | - g_assert_cmpint(qdict_get_bool(copy, "flag"), ==, true); | ||
2476 | - g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL); | ||
2477 | - g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
2478 | - | ||
2479 | - qobject_unref(copy); | ||
2480 | - | ||
2481 | - /* Simple rename of all entries */ | ||
2482 | - renames = (QDictRenames[]) { | ||
2483 | - { "abc", "str1" }, | ||
2484 | - { "abcdef", "str2" }, | ||
2485 | - { "number", "int" }, | ||
2486 | - { "flag", "bool" }, | ||
2487 | - { "nothing", "null" }, | ||
2488 | - { NULL , NULL } | ||
2489 | - }; | ||
2490 | - copy = qdict_clone_shallow(dict); | ||
2491 | - qdict_rename_keys(copy, renames, &error_abort); | ||
2492 | - | ||
2493 | - g_assert(!qdict_haskey(copy, "abc")); | ||
2494 | - g_assert(!qdict_haskey(copy, "abcdef")); | ||
2495 | - g_assert(!qdict_haskey(copy, "number")); | ||
2496 | - g_assert(!qdict_haskey(copy, "flag")); | ||
2497 | - g_assert(!qdict_haskey(copy, "nothing")); | ||
2498 | - | ||
2499 | - g_assert_cmpstr(qdict_get_str(copy, "str1"), ==, "foo"); | ||
2500 | - g_assert_cmpstr(qdict_get_str(copy, "str2"), ==, "bar"); | ||
2501 | - g_assert_cmpint(qdict_get_int(copy, "int"), ==, 42); | ||
2502 | - g_assert_cmpint(qdict_get_bool(copy, "bool"), ==, true); | ||
2503 | - g_assert(qobject_type(qdict_get(copy, "null")) == QTYPE_QNULL); | ||
2504 | - g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
2505 | - | ||
2506 | - qobject_unref(copy); | ||
2507 | - | ||
2508 | - /* Renames are processed top to bottom */ | ||
2509 | - renames = (QDictRenames[]) { | ||
2510 | - { "abc", "tmp" }, | ||
2511 | - { "abcdef", "abc" }, | ||
2512 | - { "number", "abcdef" }, | ||
2513 | - { "flag", "number" }, | ||
2514 | - { "nothing", "flag" }, | ||
2515 | - { "tmp", "nothing" }, | ||
2516 | - { NULL , NULL } | ||
2517 | - }; | ||
2518 | - copy = qdict_clone_shallow(dict); | ||
2519 | - qdict_rename_keys(copy, renames, &error_abort); | ||
2520 | - | ||
2521 | - g_assert_cmpstr(qdict_get_str(copy, "nothing"), ==, "foo"); | ||
2522 | - g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "bar"); | ||
2523 | - g_assert_cmpint(qdict_get_int(copy, "abcdef"), ==, 42); | ||
2524 | - g_assert_cmpint(qdict_get_bool(copy, "number"), ==, true); | ||
2525 | - g_assert(qobject_type(qdict_get(copy, "flag")) == QTYPE_QNULL); | ||
2526 | - g_assert(!qdict_haskey(copy, "tmp")); | ||
2527 | - g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
2528 | - | ||
2529 | - qobject_unref(copy); | ||
2530 | - | ||
2531 | - /* Conflicting rename */ | ||
2532 | - renames = (QDictRenames[]) { | ||
2533 | - { "abcdef", "abc" }, | ||
2534 | - { NULL , NULL } | ||
2535 | - }; | ||
2536 | - copy = qdict_clone_shallow(dict); | ||
2537 | - qdict_rename_keys(copy, renames, &local_err); | ||
2538 | - | ||
2539 | - g_assert(local_err != NULL); | ||
2540 | - error_free(local_err); | ||
2541 | - local_err = NULL; | ||
2542 | - | ||
2543 | - g_assert_cmpstr(qdict_get_str(copy, "abc"), ==, "foo"); | ||
2544 | - g_assert_cmpstr(qdict_get_str(copy, "abcdef"), ==, "bar"); | ||
2545 | - g_assert_cmpint(qdict_get_int(copy, "number"), ==, 42); | ||
2546 | - g_assert_cmpint(qdict_get_bool(copy, "flag"), ==, true); | ||
2547 | - g_assert(qobject_type(qdict_get(copy, "nothing")) == QTYPE_QNULL); | ||
2548 | - g_assert_cmpint(qdict_count_entries(copy), ==, 5); | ||
2549 | - | ||
2550 | - qobject_unref(copy); | ||
2551 | - | ||
2552 | - /* Renames in an empty dict */ | ||
2553 | - renames = (QDictRenames[]) { | ||
2554 | - { "abcdef", "abc" }, | ||
2555 | - { NULL , NULL } | ||
2556 | - }; | ||
2557 | - | ||
2558 | - qobject_unref(dict); | ||
2559 | - dict = qdict_new(); | ||
2560 | - | ||
2561 | - qdict_rename_keys(dict, renames, &error_abort); | ||
2562 | - g_assert(qdict_first(dict) == NULL); | ||
2563 | - | ||
2564 | - qobject_unref(dict); | ||
2565 | -} | ||
2566 | - | ||
2567 | -static void qdict_crumple_test_bad_inputs(void) | ||
2568 | -{ | ||
2569 | - QDict *src; | ||
2570 | - Error *error = NULL; | ||
2571 | - | ||
2572 | - src = qdict_new(); | ||
2573 | - /* rule.0 can't be both a string and a dict */ | ||
2574 | - qdict_put_str(src, "rule.0", "fred"); | ||
2575 | - qdict_put_str(src, "rule.0.policy", "allow"); | ||
2576 | - | ||
2577 | - g_assert(qdict_crumple(src, &error) == NULL); | ||
2578 | - g_assert(error != NULL); | ||
2579 | - error_free(error); | ||
2580 | - error = NULL; | ||
2581 | - qobject_unref(src); | ||
2582 | - | ||
2583 | - src = qdict_new(); | ||
2584 | - /* rule can't be both a list and a dict */ | ||
2585 | - qdict_put_str(src, "rule.0", "fred"); | ||
2586 | - qdict_put_str(src, "rule.a", "allow"); | ||
2587 | - | ||
2588 | - g_assert(qdict_crumple(src, &error) == NULL); | ||
2589 | - g_assert(error != NULL); | ||
2590 | - error_free(error); | ||
2591 | - error = NULL; | ||
2592 | - qobject_unref(src); | ||
2593 | - | ||
2594 | - src = qdict_new(); | ||
2595 | - /* The input should be flat, ie no dicts or lists */ | ||
2596 | - qdict_put(src, "rule.a", qdict_new()); | ||
2597 | - qdict_put_str(src, "rule.b", "allow"); | ||
2598 | - | ||
2599 | - g_assert(qdict_crumple(src, &error) == NULL); | ||
2600 | - g_assert(error != NULL); | ||
2601 | - error_free(error); | ||
2602 | - error = NULL; | ||
2603 | - qobject_unref(src); | ||
2604 | - | ||
2605 | - src = qdict_new(); | ||
2606 | - /* List indexes must not have gaps */ | ||
2607 | - qdict_put_str(src, "rule.0", "deny"); | ||
2608 | - qdict_put_str(src, "rule.3", "allow"); | ||
2609 | - | ||
2610 | - g_assert(qdict_crumple(src, &error) == NULL); | ||
2611 | - g_assert(error != NULL); | ||
2612 | - error_free(error); | ||
2613 | - error = NULL; | ||
2614 | - qobject_unref(src); | ||
2615 | - | ||
2616 | - src = qdict_new(); | ||
2617 | - /* List indexes must be in %zu format */ | ||
2618 | - qdict_put_str(src, "rule.0", "deny"); | ||
2619 | - qdict_put_str(src, "rule.+1", "allow"); | ||
2620 | - | ||
2621 | - g_assert(qdict_crumple(src, &error) == NULL); | ||
2622 | - g_assert(error != NULL); | ||
2623 | - error_free(error); | ||
2624 | - error = NULL; | ||
2625 | - qobject_unref(src); | ||
2626 | -} | ||
2627 | - | ||
2628 | /* | ||
2629 | * Errors test-cases | ||
2630 | */ | ||
2631 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
2632 | g_test_add_func("/public/get_try_int", qdict_get_try_int_test); | ||
2633 | g_test_add_func("/public/get_str", qdict_get_str_test); | ||
2634 | g_test_add_func("/public/get_try_str", qdict_get_try_str_test); | ||
2635 | - g_test_add_func("/public/defaults", qdict_defaults_test); | ||
2636 | g_test_add_func("/public/haskey_not", qdict_haskey_not_test); | ||
2637 | g_test_add_func("/public/haskey", qdict_haskey_test); | ||
2638 | g_test_add_func("/public/del", qdict_del_test); | ||
2639 | g_test_add_func("/public/to_qdict", qobject_to_qdict_test); | ||
2640 | g_test_add_func("/public/iterapi", qdict_iterapi_test); | ||
2641 | - g_test_add_func("/public/flatten", qdict_flatten_test); | ||
2642 | - g_test_add_func("/public/array_split", qdict_array_split_test); | ||
2643 | - g_test_add_func("/public/array_entries", qdict_array_entries_test); | ||
2644 | - g_test_add_func("/public/join", qdict_join_test); | ||
2645 | |||
2646 | g_test_add_func("/errors/put_exists", qdict_put_exists_test); | ||
2647 | g_test_add_func("/errors/get_not_exists", qdict_get_not_exists_test); | ||
2648 | |||
2649 | - g_test_add_func("/public/crumple/recursive", | ||
2650 | - qdict_crumple_test_recursive); | ||
2651 | - g_test_add_func("/public/crumple/empty", | ||
2652 | - qdict_crumple_test_empty); | ||
2653 | - g_test_add_func("/public/crumple/bad_inputs", | ||
2654 | - qdict_crumple_test_bad_inputs); | ||
2655 | - | ||
2656 | - g_test_add_func("/public/rename_keys", qdict_rename_keys_test); | ||
2657 | - | ||
2658 | /* The Big one */ | ||
2659 | if (g_test_slow()) { | ||
2660 | g_test_add_func("/stress/test", qdict_stress_test); | ||
2661 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
2662 | index XXXXXXX..XXXXXXX 100644 | ||
2663 | --- a/MAINTAINERS | ||
2664 | +++ b/MAINTAINERS | ||
2665 | @@ -XXX,XX +XXX,XX @@ F: qemu-img* | ||
2666 | F: qemu-io* | ||
2667 | F: tests/qemu-iotests/ | ||
2668 | F: util/qemu-progress.c | ||
2669 | +F: qobject/block-qdict.c | ||
2670 | +F: test/check-block-qdict.c | ||
2671 | T: git git://repo.or.cz/qemu/kevin.git block | ||
2672 | |||
2673 | Block I/O path | ||
2674 | diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs | ||
2675 | index XXXXXXX..XXXXXXX 100644 | ||
2676 | --- a/qobject/Makefile.objs | ||
2677 | +++ b/qobject/Makefile.objs | ||
2678 | @@ -XXX,XX +XXX,XX @@ | ||
2679 | util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o qlit.o | ||
2680 | util-obj-y += qjson.o qobject.o json-lexer.o json-streamer.o json-parser.o | ||
2681 | +util-obj-y += block-qdict.o | ||
2682 | diff --git a/tests/Makefile.include b/tests/Makefile.include | ||
2683 | index XXXXXXX..XXXXXXX 100644 | ||
2684 | --- a/tests/Makefile.include | ||
2685 | +++ b/tests/Makefile.include | ||
2686 | @@ -XXX,XX +XXX,XX @@ SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ | ||
2687 | |||
2688 | check-unit-y = tests/check-qdict$(EXESUF) | ||
2689 | gcov-files-check-qdict-y = qobject/qdict.c | ||
2690 | +check-unit-y = tests/check-block-qdict$(EXESUF) | ||
2691 | +gcov-files-check-block-qdict-y = qobject/block-qdict.c | ||
2692 | check-unit-y += tests/test-char$(EXESUF) | ||
2693 | gcov-files-check-qdict-y = chardev/char.c | ||
2694 | check-unit-y += tests/check-qnum$(EXESUF) | ||
2695 | @@ -XXX,XX +XXX,XX @@ GENERATED_FILES += tests/test-qapi-types.h tests/test-qapi-visit.h \ | ||
2696 | test-obj-y = tests/check-qnum.o tests/check-qstring.o tests/check-qdict.o \ | ||
2697 | tests/check-qlist.o tests/check-qnull.o tests/check-qobject.o \ | ||
2698 | tests/check-qjson.o tests/check-qlit.o \ | ||
2699 | + tests/check-block-qtest.o \ | ||
2700 | tests/test-coroutine.o tests/test-string-output-visitor.o \ | ||
2701 | tests/test-string-input-visitor.o tests/test-qobject-output-visitor.o \ | ||
2702 | tests/test-clone-visitor.o \ | ||
2703 | @@ -XXX,XX +XXX,XX @@ test-block-obj-y = $(block-obj-y) $(test-io-obj-y) tests/iothread.o | ||
2704 | tests/check-qnum$(EXESUF): tests/check-qnum.o $(test-util-obj-y) | ||
2705 | tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y) | ||
2706 | tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y) | ||
2707 | +tests/check-block-qdict$(EXESUF): tests/check-block-qdict.o $(test-util-obj-y) | ||
2708 | tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y) | ||
2709 | tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y) | ||
2710 | tests/check-qobject$(EXESUF): tests/check-qobject.o $(test-util-obj-y) | ||
2711 | -- | 379 | -- |
2712 | 2.13.6 | 380 | 2.48.1 |
2713 | |||
2714 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 3 | Allow virtio-scsi virtqueues to be assigned to different IOThreads. This |
4 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 4 | makes it possible to take advantage of host multi-queue block layer |
5 | scalability by assigning virtqueues that have affinity with vCPUs to | ||
6 | different IOThreads that have affinity with host CPUs. The same feature | ||
7 | was introduced for virtio-blk in the past: | ||
8 | https://developers.redhat.com/articles/2024/09/05/scaling-virtio-blk-disk-io-iothread-virtqueue-mapping | ||
9 | |||
10 | Here are fio randread 4k iodepth=64 results from a 4 vCPU guest with an | ||
11 | Intel P4800X SSD: | ||
12 | iothreads IOPS | ||
13 | ------------------------------ | ||
14 | 1 189576 | ||
15 | 2 312698 | ||
16 | 4 346744 | ||
17 | |||
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | Message-ID: <20250311132616.1049687-12-stefanha@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 20 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | --- | 21 | --- |
7 | tests/check-block-qdict.c | 14 +++++++++++++- | 22 | include/hw/virtio/virtio-scsi.h | 5 +- |
8 | 1 file changed, 13 insertions(+), 1 deletion(-) | 23 | hw/scsi/virtio-scsi-dataplane.c | 90 ++++++++++++++++++++++++--------- |
24 | hw/scsi/virtio-scsi.c | 63 ++++++++++++++--------- | ||
25 | 3 files changed, 107 insertions(+), 51 deletions(-) | ||
9 | 26 | ||
10 | diff --git a/tests/check-block-qdict.c b/tests/check-block-qdict.c | 27 | diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h |
11 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tests/check-block-qdict.c | 29 | --- a/include/hw/virtio/virtio-scsi.h |
13 | +++ b/tests/check-block-qdict.c | 30 | +++ b/include/hw/virtio/virtio-scsi.h |
14 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | 31 | @@ -XXX,XX +XXX,XX @@ |
15 | QList *e = qlist_new(); | 32 | #include "hw/virtio/virtio.h" |
16 | QDict *e_1_2 = qdict_new(); | 33 | #include "hw/scsi/scsi.h" |
17 | QDict *f = qdict_new(); | 34 | #include "chardev/char-fe.h" |
18 | + QList *y = qlist_new(); | 35 | +#include "qapi/qapi-types-virtio.h" |
19 | + QDict *z = qdict_new(); | 36 | #include "system/iothread.h" |
20 | QDict *root = qdict_new(); | 37 | |
38 | #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common" | ||
39 | @@ -XXX,XX +XXX,XX @@ struct VirtIOSCSIConf { | ||
40 | CharBackend chardev; | ||
41 | uint32_t boot_tpgt; | ||
42 | IOThread *iothread; | ||
43 | + IOThreadVirtQueueMappingList *iothread_vq_mapping_list; | ||
44 | }; | ||
45 | |||
46 | struct VirtIOSCSI; | ||
47 | @@ -XXX,XX +XXX,XX @@ struct VirtIOSCSI { | ||
48 | QTAILQ_HEAD(, VirtIOSCSIReq) tmf_bh_list; | ||
49 | |||
50 | /* Fields for dataplane below */ | ||
51 | - AioContext *ctx; /* one iothread per virtio-scsi-pci for now */ | ||
52 | + AioContext **vq_aio_context; /* per-virtqueue AioContext pointer */ | ||
53 | |||
54 | bool dataplane_started; | ||
55 | bool dataplane_starting; | ||
56 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_common_realize(DeviceState *dev, | ||
57 | void virtio_scsi_common_unrealize(DeviceState *dev); | ||
58 | |||
59 | void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp); | ||
60 | +void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s); | ||
61 | int virtio_scsi_dataplane_start(VirtIODevice *s); | ||
62 | void virtio_scsi_dataplane_stop(VirtIODevice *s); | ||
63 | |||
64 | diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/scsi/virtio-scsi-dataplane.c | ||
67 | +++ b/hw/scsi/virtio-scsi-dataplane.c | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "system/block-backend.h" | ||
70 | #include "hw/scsi/scsi.h" | ||
71 | #include "scsi/constants.h" | ||
72 | +#include "hw/virtio/iothread-vq-mapping.h" | ||
73 | #include "hw/virtio/virtio-bus.h" | ||
74 | |||
75 | /* Context: BQL held */ | ||
76 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) | ||
77 | VirtIODevice *vdev = VIRTIO_DEVICE(s); | ||
78 | BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); | ||
79 | VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); | ||
80 | + uint16_t num_vqs = vs->conf.num_queues + VIRTIO_SCSI_VQ_NUM_FIXED; | ||
81 | |||
82 | - if (vs->conf.iothread) { | ||
83 | + if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { | ||
84 | + error_setg(errp, | ||
85 | + "iothread and iothread-vq-mapping properties cannot be set " | ||
86 | + "at the same time"); | ||
87 | + return; | ||
88 | + } | ||
89 | + | ||
90 | + if (vs->conf.iothread || vs->conf.iothread_vq_mapping_list) { | ||
91 | if (!k->set_guest_notifiers || !k->ioeventfd_assign) { | ||
92 | error_setg(errp, | ||
93 | "device is incompatible with iothread " | ||
94 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) | ||
95 | error_setg(errp, "ioeventfd is required for iothread"); | ||
96 | return; | ||
97 | } | ||
98 | - s->ctx = iothread_get_aio_context(vs->conf.iothread); | ||
99 | - } else { | ||
100 | - if (!virtio_device_ioeventfd_enabled(vdev)) { | ||
101 | + } | ||
102 | + | ||
103 | + s->vq_aio_context = g_new(AioContext *, num_vqs); | ||
104 | + | ||
105 | + if (vs->conf.iothread_vq_mapping_list) { | ||
106 | + if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, | ||
107 | + s->vq_aio_context, num_vqs, errp)) { | ||
108 | + g_free(s->vq_aio_context); | ||
109 | + s->vq_aio_context = NULL; | ||
110 | return; | ||
111 | } | ||
112 | - s->ctx = qemu_get_aio_context(); | ||
113 | + } else if (vs->conf.iothread) { | ||
114 | + AioContext *ctx = iothread_get_aio_context(vs->conf.iothread); | ||
115 | + for (uint16_t i = 0; i < num_vqs; i++) { | ||
116 | + s->vq_aio_context[i] = ctx; | ||
117 | + } | ||
118 | + | ||
119 | + /* Released in virtio_scsi_dataplane_cleanup() */ | ||
120 | + object_ref(OBJECT(vs->conf.iothread)); | ||
121 | + } else { | ||
122 | + AioContext *ctx = qemu_get_aio_context(); | ||
123 | + for (unsigned i = 0; i < num_vqs; i++) { | ||
124 | + s->vq_aio_context[i] = ctx; | ||
125 | + } | ||
126 | + } | ||
127 | +} | ||
128 | + | ||
129 | +/* Context: BQL held */ | ||
130 | +void virtio_scsi_dataplane_cleanup(VirtIOSCSI *s) | ||
131 | +{ | ||
132 | + VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); | ||
133 | + | ||
134 | + if (vs->conf.iothread_vq_mapping_list) { | ||
135 | + iothread_vq_mapping_cleanup(vs->conf.iothread_vq_mapping_list); | ||
136 | } | ||
137 | + | ||
138 | + if (vs->conf.iothread) { | ||
139 | + object_unref(OBJECT(vs->conf.iothread)); | ||
140 | + } | ||
141 | + | ||
142 | + g_free(s->vq_aio_context); | ||
143 | + s->vq_aio_context = NULL; | ||
144 | } | ||
145 | |||
146 | static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int n) | ||
147 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int n) | ||
148 | } | ||
149 | |||
150 | /* Context: BH in IOThread */ | ||
151 | -static void virtio_scsi_dataplane_stop_bh(void *opaque) | ||
152 | +static void virtio_scsi_dataplane_stop_vq_bh(void *opaque) | ||
153 | { | ||
154 | - VirtIOSCSI *s = opaque; | ||
155 | - VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); | ||
156 | + AioContext *ctx = qemu_get_current_aio_context(); | ||
157 | + VirtQueue *vq = opaque; | ||
158 | EventNotifier *host_notifier; | ||
159 | - int i; | ||
160 | |||
161 | - virtio_queue_aio_detach_host_notifier(vs->ctrl_vq, s->ctx); | ||
162 | - host_notifier = virtio_queue_get_host_notifier(vs->ctrl_vq); | ||
163 | + virtio_queue_aio_detach_host_notifier(vq, ctx); | ||
164 | + host_notifier = virtio_queue_get_host_notifier(vq); | ||
21 | 165 | ||
22 | /* | 166 | /* |
23 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | 167 | * Test and clear notifier after disabling event, in case poll callback |
24 | * "c": 2, | 168 | * didn't have time to run. |
25 | * "d": 3, | ||
26 | * }, | ||
27 | - * "g": 4 | ||
28 | + * "g": 4, | ||
29 | + * "y": [{}], | ||
30 | + * "z": {"a": []} | ||
31 | * } | ||
32 | * | ||
33 | * to | ||
34 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | ||
35 | * "f.d": 3, | ||
36 | * "g": 4 | ||
37 | * } | ||
38 | + * | ||
39 | + * Note that "y" and "z" get eaten. | ||
40 | */ | 169 | */ |
41 | 170 | virtio_queue_host_notifier_read(host_notifier); | |
42 | qdict_put_int(e_1_2, "a", 0); | 171 | - |
43 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | 172 | - virtio_queue_aio_detach_host_notifier(vs->event_vq, s->ctx); |
44 | qdict_put_int(f, "c", 2); | 173 | - host_notifier = virtio_queue_get_host_notifier(vs->event_vq); |
45 | qdict_put_int(f, "d", 3); | 174 | - virtio_queue_host_notifier_read(host_notifier); |
46 | 175 | - | |
47 | + qlist_append(y, qdict_new()); | 176 | - for (i = 0; i < vs->conf.num_queues; i++) { |
48 | + | 177 | - virtio_queue_aio_detach_host_notifier(vs->cmd_vqs[i], s->ctx); |
49 | + qdict_put(z, "a", qlist_new()); | 178 | - host_notifier = virtio_queue_get_host_notifier(vs->cmd_vqs[i]); |
50 | + | 179 | - virtio_queue_host_notifier_read(host_notifier); |
51 | qdict_put(root, "e", e); | 180 | - } |
52 | qdict_put(root, "f", f); | 181 | } |
53 | qdict_put_int(root, "g", 4); | 182 | |
54 | + qdict_put(root, "y", y); | 183 | /* Context: BQL held */ |
55 | + qdict_put(root, "z", z); | 184 | @@ -XXX,XX +XXX,XX @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) |
56 | 185 | smp_wmb(); /* paired with aio_notify_accept() */ | |
57 | qdict_flatten(root); | 186 | |
58 | 187 | if (s->bus.drain_count == 0) { | |
188 | - virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, s->ctx); | ||
189 | - virtio_queue_aio_attach_host_notifier_no_poll(vs->event_vq, s->ctx); | ||
190 | + virtio_queue_aio_attach_host_notifier(vs->ctrl_vq, | ||
191 | + s->vq_aio_context[0]); | ||
192 | + virtio_queue_aio_attach_host_notifier_no_poll(vs->event_vq, | ||
193 | + s->vq_aio_context[1]); | ||
194 | |||
195 | for (i = 0; i < vs->conf.num_queues; i++) { | ||
196 | - virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], s->ctx); | ||
197 | + AioContext *ctx = s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i]; | ||
198 | + virtio_queue_aio_attach_host_notifier(vs->cmd_vqs[i], ctx); | ||
199 | } | ||
200 | } | ||
201 | return 0; | ||
202 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) | ||
203 | s->dataplane_stopping = true; | ||
204 | |||
205 | if (s->bus.drain_count == 0) { | ||
206 | - aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s); | ||
207 | + for (i = 0; i < vs->conf.num_queues + VIRTIO_SCSI_VQ_NUM_FIXED; i++) { | ||
208 | + VirtQueue *vq = virtio_get_queue(&vs->parent_obj, i); | ||
209 | + AioContext *ctx = s->vq_aio_context[i]; | ||
210 | + aio_wait_bh_oneshot(ctx, virtio_scsi_dataplane_stop_vq_bh, vq); | ||
211 | + } | ||
212 | } | ||
213 | |||
214 | blk_drain_all(); /* ensure there are no in-flight requests */ | ||
215 | diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c | ||
216 | index XXXXXXX..XXXXXXX 100644 | ||
217 | --- a/hw/scsi/virtio-scsi.c | ||
218 | +++ b/hw/scsi/virtio-scsi.c | ||
219 | @@ -XXX,XX +XXX,XX @@ | ||
220 | #include "hw/qdev-properties.h" | ||
221 | #include "hw/scsi/scsi.h" | ||
222 | #include "scsi/constants.h" | ||
223 | +#include "hw/virtio/iothread-vq-mapping.h" | ||
224 | #include "hw/virtio/virtio-bus.h" | ||
225 | #include "hw/virtio/virtio-access.h" | ||
226 | #include "trace.h" | ||
227 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data) | ||
228 | g_free(n); | ||
229 | } | ||
230 | |||
231 | -static inline void virtio_scsi_ctx_check(VirtIOSCSI *s, SCSIDevice *d) | ||
232 | -{ | ||
233 | - if (s->dataplane_started && d && blk_is_available(d->conf.blk)) { | ||
234 | - assert(blk_get_aio_context(d->conf.blk) == s->ctx); | ||
235 | - } | ||
236 | -} | ||
237 | - | ||
238 | static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) | ||
239 | { | ||
240 | VirtIOSCSI *s = req->dev; | ||
241 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_flush_defer_tmf_to_aio_context(VirtIOSCSI *s) | ||
242 | |||
243 | assert(!s->dataplane_started); | ||
244 | |||
245 | - if (s->ctx) { | ||
246 | + for (uint32_t i = 0; i < s->parent_obj.conf.num_queues; i++) { | ||
247 | + AioContext *ctx = s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i]; | ||
248 | + | ||
249 | /* Our BH only runs after previously scheduled BHs */ | ||
250 | - aio_wait_bh_oneshot(s->ctx, dummy_bh, NULL); | ||
251 | + aio_wait_bh_oneshot(ctx, dummy_bh, NULL); | ||
252 | } | ||
253 | } | ||
254 | |||
255 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
256 | AioContext *ctx; | ||
257 | int ret = 0; | ||
258 | |||
259 | - virtio_scsi_ctx_check(s, d); | ||
260 | /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */ | ||
261 | req->resp.tmf.response = VIRTIO_SCSI_S_OK; | ||
262 | |||
263 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
264 | |||
265 | case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: | ||
266 | case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: { | ||
267 | + g_autoptr(GHashTable) aio_contexts = g_hash_table_new(NULL, NULL); | ||
268 | + | ||
269 | if (!d) { | ||
270 | goto fail; | ||
271 | } | ||
272 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
273 | |||
274 | qatomic_inc(&req->remaining); | ||
275 | |||
276 | - ctx = s->ctx ?: qemu_get_aio_context(); | ||
277 | - virtio_scsi_defer_tmf_to_aio_context(req, ctx); | ||
278 | + for (uint32_t i = 0; i < s->parent_obj.conf.num_queues; i++) { | ||
279 | + ctx = s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i]; | ||
280 | + | ||
281 | + if (!g_hash_table_add(aio_contexts, ctx)) { | ||
282 | + continue; /* skip previously added AioContext */ | ||
283 | + } | ||
284 | + | ||
285 | + virtio_scsi_defer_tmf_to_aio_context(req, ctx); | ||
286 | + } | ||
287 | |||
288 | virtio_scsi_tmf_dec_remaining(req); | ||
289 | ret = -EINPROGRESS; | ||
290 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq) | ||
291 | */ | ||
292 | static bool virtio_scsi_defer_to_dataplane(VirtIOSCSI *s) | ||
293 | { | ||
294 | - if (!s->ctx || s->dataplane_started) { | ||
295 | + if (s->dataplane_started) { | ||
296 | return false; | ||
297 | } | ||
298 | + if (s->vq_aio_context[0] == qemu_get_aio_context()) { | ||
299 | + return false; /* not using IOThreads */ | ||
300 | + } | ||
301 | |||
302 | virtio_device_start_ioeventfd(&s->parent_obj.parent_obj); | ||
303 | return !s->dataplane_fenced; | ||
304 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) | ||
305 | virtio_scsi_complete_cmd_req(req); | ||
306 | return -ENOENT; | ||
307 | } | ||
308 | - virtio_scsi_ctx_check(s, d); | ||
309 | req->sreq = scsi_req_new(d, req->req.cmd.tag, | ||
310 | virtio_scsi_get_lun(req->req.cmd.lun), | ||
311 | req->req.cmd.cdb, vs->cdb_size, req); | ||
312 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev, | ||
313 | { | ||
314 | VirtIODevice *vdev = VIRTIO_DEVICE(hotplug_dev); | ||
315 | VirtIOSCSI *s = VIRTIO_SCSI(vdev); | ||
316 | + AioContext *ctx = s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED]; | ||
317 | SCSIDevice *sd = SCSI_DEVICE(dev); | ||
318 | - int ret; | ||
319 | |||
320 | - if (s->ctx && !s->dataplane_fenced) { | ||
321 | - ret = blk_set_aio_context(sd->conf.blk, s->ctx, errp); | ||
322 | - if (ret < 0) { | ||
323 | - return; | ||
324 | - } | ||
325 | + if (ctx != qemu_get_aio_context() && !s->dataplane_fenced) { | ||
326 | + /* | ||
327 | + * Try to make the BlockBackend's AioContext match ours. Ignore failure | ||
328 | + * because I/O will still work although block jobs and other users | ||
329 | + * might be slower when multiple AioContexts use a BlockBackend. | ||
330 | + */ | ||
331 | + blk_set_aio_context(sd->conf.blk, ctx, errp); | ||
332 | } | ||
333 | |||
334 | if (virtio_vdev_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG)) { | ||
335 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, | ||
336 | |||
337 | qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); | ||
338 | |||
339 | - if (s->ctx) { | ||
340 | + if (s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED] != qemu_get_aio_context()) { | ||
341 | /* If other users keep the BlockBackend in the iothread, that's ok */ | ||
342 | blk_set_aio_context(sd->conf.blk, qemu_get_aio_context(), NULL); | ||
343 | } | ||
344 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_drained_begin(SCSIBus *bus) | ||
345 | |||
346 | for (uint32_t i = 0; i < total_queues; i++) { | ||
347 | VirtQueue *vq = virtio_get_queue(vdev, i); | ||
348 | - virtio_queue_aio_detach_host_notifier(vq, s->ctx); | ||
349 | + virtio_queue_aio_detach_host_notifier(vq, s->vq_aio_context[i]); | ||
350 | } | ||
351 | } | ||
352 | |||
353 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_drained_end(SCSIBus *bus) | ||
354 | |||
355 | for (uint32_t i = 0; i < total_queues; i++) { | ||
356 | VirtQueue *vq = virtio_get_queue(vdev, i); | ||
357 | + AioContext *ctx = s->vq_aio_context[i]; | ||
358 | + | ||
359 | if (vq == vs->event_vq) { | ||
360 | - virtio_queue_aio_attach_host_notifier_no_poll(vq, s->ctx); | ||
361 | + virtio_queue_aio_attach_host_notifier_no_poll(vq, ctx); | ||
362 | } else { | ||
363 | - virtio_queue_aio_attach_host_notifier(vq, s->ctx); | ||
364 | + virtio_queue_aio_attach_host_notifier(vq, ctx); | ||
365 | } | ||
366 | } | ||
367 | } | ||
368 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_common_unrealize(DeviceState *dev) | ||
369 | virtio_cleanup(vdev); | ||
370 | } | ||
371 | |||
372 | +/* main loop */ | ||
373 | static void virtio_scsi_device_unrealize(DeviceState *dev) | ||
374 | { | ||
375 | VirtIOSCSI *s = VIRTIO_SCSI(dev); | ||
376 | |||
377 | virtio_scsi_reset_tmf_bh(s); | ||
378 | - | ||
379 | + virtio_scsi_dataplane_cleanup(s); | ||
380 | qbus_set_hotplug_handler(BUS(&s->bus), NULL); | ||
381 | virtio_scsi_common_unrealize(dev); | ||
382 | qemu_mutex_destroy(&s->tmf_bh_lock); | ||
383 | @@ -XXX,XX +XXX,XX @@ static const Property virtio_scsi_properties[] = { | ||
384 | VIRTIO_SCSI_F_CHANGE, true), | ||
385 | DEFINE_PROP_LINK("iothread", VirtIOSCSI, parent_obj.conf.iothread, | ||
386 | TYPE_IOTHREAD, IOThread *), | ||
387 | + DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST("iothread-vq-mapping", VirtIOSCSI, | ||
388 | + parent_obj.conf.iothread_vq_mapping_list), | ||
389 | }; | ||
390 | |||
391 | static const VMStateDescription vmstate_virtio_scsi = { | ||
59 | -- | 392 | -- |
60 | 2.13.6 | 393 | 2.48.1 |
61 | |||
62 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | When you mix scalar and non-scalar keys, whether you get an "already | 3 | Previously the ctrl virtqueue was handled in the AioContext where SCSI |
4 | set as scalar" or an "already set as dict" error depends on qdict | 4 | requests are processed. When IOThread Virtqueue Mapping was added things |
5 | iteration order. Neither message makes much sense. Replace by | 5 | become more complicated because SCSI requests could run in other |
6 | ""Cannot mix scalar and non-scalar keys". This is similar to the | 6 | AioContexts. |
7 | message we get for mixing list and non-list keys. | 7 | |
8 | 8 | Simplify by handling the ctrl virtqueue in the main loop where reset | |
9 | I find qdict_crumple()'s first loop hard to understand. Rearrange it | 9 | operations can be performed. Note that BHs are still used canceling SCSI |
10 | and add a comment. | 10 | requests in their AioContexts but at least the mean loop activity |
11 | 11 | doesn't need BHs anymore. | |
12 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 12 | |
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Message-ID: <20250311132616.1049687-13-stefanha@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 15 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
14 | --- | 16 | --- |
15 | qobject/block-qdict.c | 32 ++++++++++++++++---------------- | 17 | include/hw/virtio/virtio-scsi.h | 8 -- |
16 | 1 file changed, 16 insertions(+), 16 deletions(-) | 18 | hw/scsi/virtio-scsi-dataplane.c | 6 ++ |
17 | 19 | hw/scsi/virtio-scsi.c | 144 ++++++-------------------------- | |
18 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 20 | 3 files changed, 33 insertions(+), 125 deletions(-) |
21 | |||
22 | diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/qobject/block-qdict.c | 24 | --- a/include/hw/virtio/virtio-scsi.h |
21 | +++ b/qobject/block-qdict.c | 25 | +++ b/include/hw/virtio/virtio-scsi.h |
22 | @@ -XXX,XX +XXX,XX @@ static int qdict_is_list(QDict *maybe_list, Error **errp) | 26 | @@ -XXX,XX +XXX,XX @@ struct VirtIOSCSI { |
23 | QObject *qdict_crumple(const QDict *src, Error **errp) | 27 | |
28 | QemuMutex ctrl_lock; /* protects ctrl_vq */ | ||
29 | |||
30 | - /* | ||
31 | - * TMFs deferred to main loop BH. These fields are protected by | ||
32 | - * tmf_bh_lock. | ||
33 | - */ | ||
34 | - QemuMutex tmf_bh_lock; | ||
35 | - QEMUBH *tmf_bh; | ||
36 | - QTAILQ_HEAD(, VirtIOSCSIReq) tmf_bh_list; | ||
37 | - | ||
38 | /* Fields for dataplane below */ | ||
39 | AioContext **vq_aio_context; /* per-virtqueue AioContext pointer */ | ||
40 | |||
41 | diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/scsi/virtio-scsi-dataplane.c | ||
44 | +++ b/hw/scsi/virtio-scsi-dataplane.c | ||
45 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) | ||
46 | s->vq_aio_context[i] = ctx; | ||
47 | } | ||
48 | } | ||
49 | + | ||
50 | + /* | ||
51 | + * Always handle the ctrl virtqueue in the main loop thread where device | ||
52 | + * resets can be performed. | ||
53 | + */ | ||
54 | + s->vq_aio_context[0] = qemu_get_aio_context(); | ||
55 | } | ||
56 | |||
57 | /* Context: BQL held */ | ||
58 | diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/hw/scsi/virtio-scsi.c | ||
61 | +++ b/hw/scsi/virtio-scsi.c | ||
62 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data) | ||
63 | g_free(n); | ||
64 | } | ||
65 | |||
66 | -static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) | ||
67 | -{ | ||
68 | - VirtIOSCSI *s = req->dev; | ||
69 | - SCSIDevice *d = virtio_scsi_device_get(s, req->req.tmf.lun); | ||
70 | - BusChild *kid; | ||
71 | - int target; | ||
72 | - | ||
73 | - switch (req->req.tmf.subtype) { | ||
74 | - case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: | ||
75 | - if (!d) { | ||
76 | - req->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET; | ||
77 | - goto out; | ||
78 | - } | ||
79 | - if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { | ||
80 | - req->resp.tmf.response = VIRTIO_SCSI_S_INCORRECT_LUN; | ||
81 | - goto out; | ||
82 | - } | ||
83 | - qatomic_inc(&s->resetting); | ||
84 | - device_cold_reset(&d->qdev); | ||
85 | - qatomic_dec(&s->resetting); | ||
86 | - break; | ||
87 | - | ||
88 | - case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: | ||
89 | - target = req->req.tmf.lun[1]; | ||
90 | - qatomic_inc(&s->resetting); | ||
91 | - | ||
92 | - rcu_read_lock(); | ||
93 | - QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { | ||
94 | - SCSIDevice *d1 = SCSI_DEVICE(kid->child); | ||
95 | - if (d1->channel == 0 && d1->id == target) { | ||
96 | - device_cold_reset(&d1->qdev); | ||
97 | - } | ||
98 | - } | ||
99 | - rcu_read_unlock(); | ||
100 | - | ||
101 | - qatomic_dec(&s->resetting); | ||
102 | - break; | ||
103 | - | ||
104 | - default: | ||
105 | - g_assert_not_reached(); | ||
106 | - } | ||
107 | - | ||
108 | -out: | ||
109 | - object_unref(OBJECT(d)); | ||
110 | - virtio_scsi_complete_req(req, &s->ctrl_lock); | ||
111 | -} | ||
112 | - | ||
113 | -/* Some TMFs must be processed from the main loop thread */ | ||
114 | -static void virtio_scsi_do_tmf_bh(void *opaque) | ||
115 | -{ | ||
116 | - VirtIOSCSI *s = opaque; | ||
117 | - QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs); | ||
118 | - VirtIOSCSIReq *req; | ||
119 | - VirtIOSCSIReq *tmp; | ||
120 | - | ||
121 | - GLOBAL_STATE_CODE(); | ||
122 | - | ||
123 | - WITH_QEMU_LOCK_GUARD(&s->tmf_bh_lock) { | ||
124 | - QTAILQ_FOREACH_SAFE(req, &s->tmf_bh_list, next, tmp) { | ||
125 | - QTAILQ_REMOVE(&s->tmf_bh_list, req, next); | ||
126 | - QTAILQ_INSERT_TAIL(&reqs, req, next); | ||
127 | - } | ||
128 | - | ||
129 | - qemu_bh_delete(s->tmf_bh); | ||
130 | - s->tmf_bh = NULL; | ||
131 | - } | ||
132 | - | ||
133 | - QTAILQ_FOREACH_SAFE(req, &reqs, next, tmp) { | ||
134 | - QTAILQ_REMOVE(&reqs, req, next); | ||
135 | - virtio_scsi_do_one_tmf_bh(req); | ||
136 | - } | ||
137 | -} | ||
138 | - | ||
139 | -static void virtio_scsi_reset_tmf_bh(VirtIOSCSI *s) | ||
140 | -{ | ||
141 | - VirtIOSCSIReq *req; | ||
142 | - VirtIOSCSIReq *tmp; | ||
143 | - | ||
144 | - GLOBAL_STATE_CODE(); | ||
145 | - | ||
146 | - /* Called after ioeventfd has been stopped, so tmf_bh_lock is not needed */ | ||
147 | - if (s->tmf_bh) { | ||
148 | - qemu_bh_delete(s->tmf_bh); | ||
149 | - s->tmf_bh = NULL; | ||
150 | - } | ||
151 | - | ||
152 | - QTAILQ_FOREACH_SAFE(req, &s->tmf_bh_list, next, tmp) { | ||
153 | - QTAILQ_REMOVE(&s->tmf_bh_list, req, next); | ||
154 | - | ||
155 | - /* SAM-6 6.3.2 Hard reset */ | ||
156 | - req->resp.tmf.response = VIRTIO_SCSI_S_TARGET_FAILURE; | ||
157 | - virtio_scsi_complete_req(req, &req->dev->ctrl_lock); | ||
158 | - } | ||
159 | -} | ||
160 | - | ||
161 | -static void virtio_scsi_defer_tmf_to_main_loop(VirtIOSCSIReq *req) | ||
162 | -{ | ||
163 | - VirtIOSCSI *s = req->dev; | ||
164 | - | ||
165 | - WITH_QEMU_LOCK_GUARD(&s->tmf_bh_lock) { | ||
166 | - QTAILQ_INSERT_TAIL(&s->tmf_bh_list, req, next); | ||
167 | - | ||
168 | - if (!s->tmf_bh) { | ||
169 | - s->tmf_bh = qemu_bh_new(virtio_scsi_do_tmf_bh, s); | ||
170 | - qemu_bh_schedule(s->tmf_bh); | ||
171 | - } | ||
172 | - } | ||
173 | -} | ||
174 | - | ||
175 | static void virtio_scsi_tmf_cancel_req(VirtIOSCSIReq *tmf, SCSIRequest *r) | ||
24 | { | 176 | { |
25 | const QDictEntry *ent; | 177 | VirtIOSCSICancelNotifier *notifier; |
26 | - QDict *two_level, *multi_level = NULL; | 178 | @@ -XXX,XX +XXX,XX @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) |
27 | + QDict *two_level, *multi_level = NULL, *child_dict; | 179 | break; |
28 | QObject *dst = NULL, *child; | 180 | |
29 | size_t i; | 181 | case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: |
30 | char *prefix = NULL; | 182 | - case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: |
31 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | 183 | - virtio_scsi_defer_tmf_to_main_loop(req); |
32 | } | 184 | - ret = -EINPROGRESS; |
33 | 185 | + if (!d) { | |
34 | qdict_split_flat_key(ent->key, &prefix, &suffix); | 186 | + goto fail; |
35 | - | 187 | + } |
36 | child = qdict_get(two_level, prefix); | 188 | + if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { |
37 | + child_dict = qobject_to(QDict, child); | 189 | + goto incorrect_lun; |
38 | + | 190 | + } |
39 | + if (child) { | 191 | + qatomic_inc(&s->resetting); |
40 | + /* | 192 | + device_cold_reset(&d->qdev); |
41 | + * If @child_dict, then all previous keys with this prefix | 193 | + qatomic_dec(&s->resetting); |
42 | + * had a suffix. If @suffix, this one has one as well, | 194 | break; |
43 | + * and we're good, else there's a clash. | 195 | |
44 | + */ | 196 | + case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: { |
45 | + if (!child_dict || !suffix) { | 197 | + BusChild *kid; |
46 | + error_setg(errp, "Cannot mix scalar and non-scalar keys"); | 198 | + int target = req->req.tmf.lun[1]; |
47 | + goto error; | 199 | + qatomic_inc(&s->resetting); |
200 | + | ||
201 | + rcu_read_lock(); | ||
202 | + QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { | ||
203 | + SCSIDevice *d1 = SCSI_DEVICE(kid->child); | ||
204 | + if (d1->channel == 0 && d1->id == target) { | ||
205 | + device_cold_reset(&d1->qdev); | ||
48 | + } | 206 | + } |
49 | + } | 207 | + } |
50 | + | 208 | + rcu_read_unlock(); |
51 | if (suffix) { | 209 | + |
52 | - QDict *child_dict = qobject_to(QDict, child); | 210 | + qatomic_dec(&s->resetting); |
53 | if (!child_dict) { | 211 | + break; |
54 | - if (child) { | 212 | + } |
55 | - error_setg(errp, "Key %s prefix is already set as a scalar", | 213 | + |
56 | - prefix); | 214 | case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: |
57 | - goto error; | 215 | case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: { |
58 | - } | 216 | g_autoptr(GHashTable) aio_contexts = g_hash_table_new(NULL, NULL); |
59 | - | 217 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_reset(VirtIODevice *vdev) |
60 | child_dict = qdict_new(); | 218 | |
61 | - qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); | 219 | assert(!s->dataplane_started); |
62 | + qdict_put(two_level, prefix, child_dict); | 220 | |
63 | } | 221 | - virtio_scsi_reset_tmf_bh(s); |
64 | - | 222 | virtio_scsi_flush_defer_tmf_to_aio_context(s); |
65 | qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); | 223 | |
66 | } else { | 224 | qatomic_inc(&s->resetting); |
67 | - if (child) { | 225 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp) |
68 | - error_setg(errp, "Key %s prefix is already set as a dict", | 226 | VirtIOSCSI *s = VIRTIO_SCSI(dev); |
69 | - prefix); | 227 | Error *err = NULL; |
70 | - goto error; | 228 | |
71 | - } | 229 | - QTAILQ_INIT(&s->tmf_bh_list); |
72 | qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); | 230 | qemu_mutex_init(&s->ctrl_lock); |
73 | } | 231 | qemu_mutex_init(&s->event_lock); |
74 | 232 | - qemu_mutex_init(&s->tmf_bh_lock); | |
233 | |||
234 | virtio_scsi_common_realize(dev, | ||
235 | virtio_scsi_handle_ctrl, | ||
236 | @@ -XXX,XX +XXX,XX @@ static void virtio_scsi_device_unrealize(DeviceState *dev) | ||
237 | { | ||
238 | VirtIOSCSI *s = VIRTIO_SCSI(dev); | ||
239 | |||
240 | - virtio_scsi_reset_tmf_bh(s); | ||
241 | virtio_scsi_dataplane_cleanup(s); | ||
242 | qbus_set_hotplug_handler(BUS(&s->bus), NULL); | ||
243 | virtio_scsi_common_unrealize(dev); | ||
244 | - qemu_mutex_destroy(&s->tmf_bh_lock); | ||
245 | qemu_mutex_destroy(&s->event_lock); | ||
246 | qemu_mutex_destroy(&s->ctrl_lock); | ||
247 | } | ||
75 | -- | 248 | -- |
76 | 2.13.6 | 249 | 2.48.1 |
77 | |||
78 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | -blockdev and blockdev-add silently ignore empty objects and arrays in | 3 | Peter Krempa and Kevin Wolf observed that iothread-vq-mapping is |
4 | their argument. That's because qmp_blockdev_add() converts the | 4 | confusing to use because the control and event virtqueues have a fixed |
5 | argument to a flat QDict, and qdict_flatten() eats empty QDict and | 5 | location before the command virtqueues but need to be treated |
6 | QList members. For instance, we ignore an empty BlockdevOptions | 6 | differently. |
7 | member @cache. No real harm, as absent means the same as empty there. | ||
8 | 7 | ||
9 | Thus, the flaw puts an artificial restriction on the QAPI schema: we | 8 | Only expose the command virtqueues via iothread-vq-mapping so that the |
10 | can't have potentially empty objects and arrays within | 9 | command-line parameter is intuitive: it controls where SCSI requests are |
11 | BlockdevOptions, except when they're optional and "empty" has the same | 10 | processed. |
12 | meaning as "absent". | ||
13 | 11 | ||
14 | Our QAPI schema satisfies this restriction (I checked), but it's a | 12 | The control virtqueue needs to be hardcoded to the main loop thread for |
15 | trap for the unwary, and a temptation to employ awkward workarounds | 13 | technical reasons anyway. Kevin also pointed out that it's better to |
16 | for the wary. Let's get rid of it. | 14 | place the event virtqueue in the main loop thread since its no poll |
15 | behavior would prevent polling if assigned to an IOThread. | ||
17 | 16 | ||
18 | Change qdict_flatten() and qdict_crumple() to treat empty dictionaries | 17 | This change is its own commit to avoid squashing the previous commit. |
19 | and lists exactly like scalars. | ||
20 | 18 | ||
21 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 19 | Suggested-by: Kevin Wolf <kwolf@redhat.com> |
22 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 20 | Suggested-by: Peter Krempa <pkrempa@redhat.com> |
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | Message-ID: <20250311132616.1049687-14-stefanha@redhat.com> | ||
23 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 23 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
24 | --- | 24 | --- |
25 | qobject/block-qdict.c | 54 +++++++++++++++++++++++++++++------------------ | 25 | hw/scsi/virtio-scsi-dataplane.c | 33 ++++++++++++++++++++------------- |
26 | tests/check-block-qdict.c | 38 ++++++++++++++++++++++++++------- | 26 | 1 file changed, 20 insertions(+), 13 deletions(-) |
27 | 2 files changed, 63 insertions(+), 29 deletions(-) | ||
28 | 27 | ||
29 | diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c | 28 | diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c |
30 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/qobject/block-qdict.c | 30 | --- a/hw/scsi/virtio-scsi-dataplane.c |
32 | +++ b/qobject/block-qdict.c | 31 | +++ b/hw/scsi/virtio-scsi-dataplane.c |
33 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) | 32 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) |
34 | { | 33 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
35 | QObject *value; | 34 | BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); |
36 | const QListEntry *entry; | 35 | VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); |
37 | + QDict *dict_val; | 36 | - uint16_t num_vqs = vs->conf.num_queues + VIRTIO_SCSI_VQ_NUM_FIXED; |
38 | + QList *list_val; | 37 | |
39 | char *new_key; | 38 | if (vs->conf.iothread && vs->conf.iothread_vq_mapping_list) { |
40 | int i; | 39 | error_setg(errp, |
41 | 40 | @@ -XXX,XX +XXX,XX @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp) | |
42 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) | ||
43 | |||
44 | for (i = 0; entry; entry = qlist_next(entry), i++) { | ||
45 | value = qlist_entry_obj(entry); | ||
46 | + dict_val = qobject_to(QDict, value); | ||
47 | + list_val = qobject_to(QList, value); | ||
48 | new_key = g_strdup_printf("%s.%i", prefix, i); | ||
49 | |||
50 | /* | ||
51 | * Flatten non-empty QDict and QList recursively into @target, | ||
52 | * copy other objects to @target | ||
53 | */ | ||
54 | - if (qobject_type(value) == QTYPE_QDICT) { | ||
55 | - qdict_flatten_qdict(qobject_to(QDict, value), target, new_key); | ||
56 | - } else if (qobject_type(value) == QTYPE_QLIST) { | ||
57 | - qdict_flatten_qlist(qobject_to(QList, value), target, new_key); | ||
58 | + if (dict_val && qdict_size(dict_val)) { | ||
59 | + qdict_flatten_qdict(dict_val, target, new_key); | ||
60 | + } else if (list_val && !qlist_empty(list_val)) { | ||
61 | + qdict_flatten_qlist(list_val, target, new_key); | ||
62 | } else { | ||
63 | qdict_put_obj(target, new_key, qobject_ref(value)); | ||
64 | } | 41 | } |
65 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 42 | } |
66 | { | 43 | |
67 | QObject *value; | 44 | - s->vq_aio_context = g_new(AioContext *, num_vqs); |
68 | const QDictEntry *entry, *next; | 45 | + s->vq_aio_context = g_new(AioContext *, vs->conf.num_queues + |
69 | + QDict *dict_val; | 46 | + VIRTIO_SCSI_VQ_NUM_FIXED); |
70 | + QList *list_val; | 47 | + |
71 | char *new_key; | 48 | + /* |
72 | 49 | + * Handle the ctrl virtqueue in the main loop thread where device resets | |
73 | entry = qdict_first(qdict); | 50 | + * can be performed. |
74 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 51 | + */ |
75 | while (entry != NULL) { | 52 | + s->vq_aio_context[0] = qemu_get_aio_context(); |
76 | next = qdict_next(qdict, entry); | 53 | + |
77 | value = qdict_entry_value(entry); | 54 | + /* |
78 | + dict_val = qobject_to(QDict, value); | 55 | + * Handle the event virtqueue in the main loop thread where its no_poll |
79 | + list_val = qobject_to(QList, value); | 56 | + * behavior won't stop IOThread polling. |
80 | new_key = NULL; | 57 | + */ |
81 | 58 | + s->vq_aio_context[1] = qemu_get_aio_context(); | |
82 | if (prefix) { | 59 | |
83 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 60 | if (vs->conf.iothread_vq_mapping_list) { |
84 | * Flatten non-empty QDict and QList recursively into @target, | 61 | if (!iothread_vq_mapping_apply(vs->conf.iothread_vq_mapping_list, |
85 | * copy other objects to @target | 62 | - s->vq_aio_context, num_vqs, errp)) { |
86 | */ | 63 | + &s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED], |
87 | - if (qobject_type(value) == QTYPE_QDICT) { | 64 | + vs->conf.num_queues, errp)) { |
88 | - qdict_flatten_qdict(qobject_to(QDict, value), target, | 65 | g_free(s->vq_aio_context); |
89 | + if (dict_val && qdict_size(dict_val)) { | 66 | s->vq_aio_context = NULL; |
90 | + qdict_flatten_qdict(dict_val, target, | 67 | return; |
91 | new_key ? new_key : entry->key); | 68 | } |
92 | qdict_del(qdict, entry->key); | 69 | } else if (vs->conf.iothread) { |
93 | - } else if (qobject_type(value) == QTYPE_QLIST) { | 70 | AioContext *ctx = iothread_get_aio_context(vs->conf.iothread); |
94 | - qdict_flatten_qlist(qobject_to(QList, value), target, | 71 | - for (uint16_t i = 0; i < num_vqs; i++) { |
95 | + } else if (list_val && !qlist_empty(list_val)) { | 72 | - s->vq_aio_context[i] = ctx; |
96 | + qdict_flatten_qlist(list_val, target, | 73 | + for (uint16_t i = 0; i < vs->conf.num_queues; i++) { |
97 | new_key ? new_key : entry->key); | 74 | + s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx; |
98 | qdict_del(qdict, entry->key); | 75 | } |
99 | } else if (target != qdict) { | 76 | |
100 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) | 77 | /* Released in virtio_scsi_dataplane_cleanup() */ |
78 | object_ref(OBJECT(vs->conf.iothread)); | ||
79 | } else { | ||
80 | AioContext *ctx = qemu_get_aio_context(); | ||
81 | - for (unsigned i = 0; i < num_vqs; i++) { | ||
82 | - s->vq_aio_context[i] = ctx; | ||
83 | + for (unsigned i = 0; i < vs->conf.num_queues; i++) { | ||
84 | + s->vq_aio_context[VIRTIO_SCSI_VQ_NUM_FIXED + i] = ctx; | ||
85 | } | ||
86 | } | ||
87 | - | ||
88 | - /* | ||
89 | - * Always handle the ctrl virtqueue in the main loop thread where device | ||
90 | - * resets can be performed. | ||
91 | - */ | ||
92 | - s->vq_aio_context[0] = qemu_get_aio_context(); | ||
101 | } | 93 | } |
102 | 94 | ||
103 | /** | 95 | /* Context: BQL held */ |
104 | - * qdict_flatten(): For each nested QDict with key x, all fields with key y | ||
105 | - * are moved to this QDict and their key is renamed to "x.y". For each nested | ||
106 | - * QList with key x, the field at index y is moved to this QDict with the key | ||
107 | - * "x.y" (i.e., the reverse of what qdict_array_split() does). | ||
108 | + * qdict_flatten(): For each nested non-empty QDict with key x, all | ||
109 | + * fields with key y are moved to this QDict and their key is renamed | ||
110 | + * to "x.y". For each nested non-empty QList with key x, the field at | ||
111 | + * index y is moved to this QDict with the key "x.y" (i.e., the | ||
112 | + * reverse of what qdict_array_split() does). | ||
113 | * This operation is applied recursively for nested QDicts and QLists. | ||
114 | */ | ||
115 | void qdict_flatten(QDict *qdict) | ||
116 | @@ -XXX,XX +XXX,XX @@ static int qdict_is_list(QDict *maybe_list, Error **errp) | ||
117 | * @src: the original flat dictionary (only scalar values) to crumple | ||
118 | * | ||
119 | * Takes a flat dictionary whose keys use '.' separator to indicate | ||
120 | - * nesting, and values are scalars, and crumples it into a nested | ||
121 | - * structure. | ||
122 | + * nesting, and values are scalars, empty dictionaries or empty lists, | ||
123 | + * and crumples it into a nested structure. | ||
124 | * | ||
125 | * To include a literal '.' in a key name, it must be escaped as '..' | ||
126 | * | ||
127 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | ||
128 | { | ||
129 | const QDictEntry *ent; | ||
130 | QDict *two_level, *multi_level = NULL, *child_dict; | ||
131 | + QDict *dict_val; | ||
132 | + QList *list_val; | ||
133 | QObject *dst = NULL, *child; | ||
134 | size_t i; | ||
135 | char *prefix = NULL; | ||
136 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | ||
137 | |||
138 | /* Step 1: split our totally flat dict into a two level dict */ | ||
139 | for (ent = qdict_first(src); ent != NULL; ent = qdict_next(src, ent)) { | ||
140 | - if (qobject_type(ent->value) == QTYPE_QDICT || | ||
141 | - qobject_type(ent->value) == QTYPE_QLIST) { | ||
142 | - error_setg(errp, "Value %s is not a scalar", | ||
143 | - ent->key); | ||
144 | + dict_val = qobject_to(QDict, ent->value); | ||
145 | + list_val = qobject_to(QList, ent->value); | ||
146 | + if ((dict_val && qdict_size(dict_val)) | ||
147 | + || (list_val && !qlist_empty(list_val))) { | ||
148 | + error_setg(errp, "Value %s is not flat", ent->key); | ||
149 | goto error; | ||
150 | } | ||
151 | |||
152 | @@ -XXX,XX +XXX,XX @@ QObject *qdict_crumple(const QDict *src, Error **errp) | ||
153 | multi_level = qdict_new(); | ||
154 | for (ent = qdict_first(two_level); ent != NULL; | ||
155 | ent = qdict_next(two_level, ent)) { | ||
156 | - QDict *dict = qobject_to(QDict, ent->value); | ||
157 | - if (dict) { | ||
158 | - child = qdict_crumple(dict, errp); | ||
159 | + dict_val = qobject_to(QDict, ent->value); | ||
160 | + if (dict_val && qdict_size(dict_val)) { | ||
161 | + child = qdict_crumple(dict_val, errp); | ||
162 | if (!child) { | ||
163 | goto error; | ||
164 | } | ||
165 | diff --git a/tests/check-block-qdict.c b/tests/check-block-qdict.c | ||
166 | index XXXXXXX..XXXXXXX 100644 | ||
167 | --- a/tests/check-block-qdict.c | ||
168 | +++ b/tests/check-block-qdict.c | ||
169 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | ||
170 | * "e.1.2.b": 1, | ||
171 | * "f.c": 2, | ||
172 | * "f.d": 3, | ||
173 | - * "g": 4 | ||
174 | + * "g": 4, | ||
175 | + * "y.0": {}, | ||
176 | + * "z.a": [] | ||
177 | * } | ||
178 | - * | ||
179 | - * Note that "y" and "z" get eaten. | ||
180 | */ | ||
181 | |||
182 | qdict_put_int(e_1_2, "a", 0); | ||
183 | @@ -XXX,XX +XXX,XX @@ static void qdict_flatten_test(void) | ||
184 | g_assert(qdict_get_int(root, "f.c") == 2); | ||
185 | g_assert(qdict_get_int(root, "f.d") == 3); | ||
186 | g_assert(qdict_get_int(root, "g") == 4); | ||
187 | + g_assert(!qdict_size(qdict_get_qdict(root, "y.0"))); | ||
188 | + g_assert(qlist_empty(qdict_get_qlist(root, "z.a"))); | ||
189 | |||
190 | - g_assert(qdict_size(root) == 8); | ||
191 | + g_assert(qdict_size(root) == 10); | ||
192 | |||
193 | qobject_unref(root); | ||
194 | } | ||
195 | @@ -XXX,XX +XXX,XX @@ static void qdict_join_test(void) | ||
196 | static void qdict_crumple_test_recursive(void) | ||
197 | { | ||
198 | QDict *src, *dst, *rule, *vnc, *acl, *listen; | ||
199 | - QList *rules; | ||
200 | + QDict *empty, *empty_dict, *empty_list_0; | ||
201 | + QList *rules, *empty_list, *empty_dict_a; | ||
202 | |||
203 | src = qdict_new(); | ||
204 | qdict_put_str(src, "vnc.listen.addr", "127.0.0.1"); | ||
205 | @@ -XXX,XX +XXX,XX @@ static void qdict_crumple_test_recursive(void) | ||
206 | qdict_put_str(src, "vnc.acl.default", "deny"); | ||
207 | qdict_put_str(src, "vnc.acl..name", "acl0"); | ||
208 | qdict_put_str(src, "vnc.acl.rule..name", "acl0"); | ||
209 | + qdict_put(src, "empty.dict.a", qlist_new()); | ||
210 | + qdict_put(src, "empty.list.0", qdict_new()); | ||
211 | |||
212 | dst = qobject_to(QDict, qdict_crumple(src, &error_abort)); | ||
213 | g_assert(dst); | ||
214 | - g_assert_cmpint(qdict_size(dst), ==, 1); | ||
215 | + g_assert_cmpint(qdict_size(dst), ==, 2); | ||
216 | |||
217 | vnc = qdict_get_qdict(dst, "vnc"); | ||
218 | g_assert(vnc); | ||
219 | @@ -XXX,XX +XXX,XX @@ static void qdict_crumple_test_recursive(void) | ||
220 | g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name")); | ||
221 | g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name")); | ||
222 | |||
223 | + empty = qdict_get_qdict(dst, "empty"); | ||
224 | + g_assert(empty); | ||
225 | + g_assert_cmpint(qdict_size(empty), ==, 2); | ||
226 | + empty_dict = qdict_get_qdict(empty, "dict"); | ||
227 | + g_assert(empty_dict); | ||
228 | + g_assert_cmpint(qdict_size(empty_dict), ==, 1); | ||
229 | + empty_dict_a = qdict_get_qlist(empty_dict, "a"); | ||
230 | + g_assert(empty_dict_a && qlist_empty(empty_dict_a)); | ||
231 | + empty_list = qdict_get_qlist(empty, "list"); | ||
232 | + g_assert(empty_list); | ||
233 | + g_assert_cmpint(qlist_size(empty_list), ==, 1); | ||
234 | + empty_list_0 = qobject_to(QDict, qlist_pop(empty_list)); | ||
235 | + g_assert(empty_list_0); | ||
236 | + g_assert_cmpint(qdict_size(empty_list_0), ==, 0); | ||
237 | + | ||
238 | qobject_unref(src); | ||
239 | qobject_unref(dst); | ||
240 | } | ||
241 | @@ -XXX,XX +XXX,XX @@ static void qdict_rename_keys_test(void) | ||
242 | |||
243 | static void qdict_crumple_test_bad_inputs(void) | ||
244 | { | ||
245 | - QDict *src; | ||
246 | + QDict *src, *nested; | ||
247 | Error *error = NULL; | ||
248 | |||
249 | src = qdict_new(); | ||
250 | @@ -XXX,XX +XXX,XX @@ static void qdict_crumple_test_bad_inputs(void) | ||
251 | |||
252 | src = qdict_new(); | ||
253 | /* The input should be flat, ie no dicts or lists */ | ||
254 | - qdict_put(src, "rule.a", qdict_new()); | ||
255 | + nested = qdict_new(); | ||
256 | + qdict_put(nested, "x", qdict_new()); | ||
257 | + qdict_put(src, "rule.a", nested); | ||
258 | qdict_put_str(src, "rule.b", "allow"); | ||
259 | |||
260 | g_assert(qdict_crumple(src, &error) == NULL); | ||
261 | -- | 96 | -- |
262 | 2.13.6 | 97 | 2.48.1 |
263 | |||
264 | diff view generated by jsdifflib |