1 | The following changes since commit 2387df497b4b4bcf754eb7398edca82889e2ef54: | 1 | The following changes since commit ac793156f650ae2d77834932d72224175ee69086: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2020-10-10' into staging (2020-10-12 11:29:42 +0100) | 3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20201020-1' into staging (2020-10-20 21:11:35 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 3664ec6bbe236126b79d251d4037889e7181ab55: | 9 | for you to fetch changes up to 32a3fd65e7e3551337fd26bfc0e2f899d70c028c: |
10 | 10 | ||
11 | iotests: add commit top->base cases to 274 (2020-10-12 16:47:58 +0100) | 11 | iotests: add commit top->base cases to 274 (2020-10-22 09:55:39 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | v2: | 16 | v2: |
17 | * Rebase and resolve conflict with commit 029a88c9a7e3 ("qemu-nbd: Honor | 17 | * Fix format string issues on 32-bit hosts [Peter] |
18 | SIGINT and SIGHUP") [Peter] | 18 | * Fix qemu-nbd.c CONFIG_POSIX ifdef issue [Eric] |
19 | * Fix missing eventfd.h header on macOS [Peter] | ||
20 | * Drop unreliable vhost-user-blk test (will send a new patch when ready) [Peter] | ||
21 | |||
22 | This pull request contains the vhost-user-blk server by Coiby Xu along with my | ||
23 | additions, block/nvme.c alignment and hardware error statistics by Philippe | ||
24 | Mathieu-Daudé, and bdrv_co_block_status_above() fixes by Vladimir | ||
25 | Sementsov-Ogievskiy. | ||
19 | 26 | ||
20 | ---------------------------------------------------------------- | 27 | ---------------------------------------------------------------- |
21 | 28 | ||
22 | Coiby Xu (7): | 29 | Coiby Xu (6): |
23 | libvhost-user: Allow vu_message_read to be replaced | 30 | libvhost-user: Allow vu_message_read to be replaced |
24 | libvhost-user: remove watch for kick_fd when de-initialize vu-dev | 31 | libvhost-user: remove watch for kick_fd when de-initialize vu-dev |
25 | util/vhost-user-server: generic vhost user server | 32 | util/vhost-user-server: generic vhost user server |
26 | block: move logical block size check function to a common utility | 33 | block: move logical block size check function to a common utility |
27 | function | 34 | function |
28 | block/export: vhost-user block device backend server | 35 | block/export: vhost-user block device backend server |
29 | test: new qTest case to test the vhost-user-blk-server | ||
30 | MAINTAINERS: Add vhost-user block device backend server maintainer | 36 | MAINTAINERS: Add vhost-user block device backend server maintainer |
31 | 37 | ||
32 | Philippe Mathieu-Daudé (1): | 38 | Philippe Mathieu-Daudé (1): |
33 | block/nvme: Add driver statistics for access alignment and hw errors | 39 | block/nvme: Add driver statistics for access alignment and hw errors |
34 | 40 | ||
35 | Stefan Hajnoczi (17): | 41 | Stefan Hajnoczi (16): |
36 | util/vhost-user-server: s/fileds/fields/ typo fix | 42 | util/vhost-user-server: s/fileds/fields/ typo fix |
37 | util/vhost-user-server: drop unnecessary QOM cast | 43 | util/vhost-user-server: drop unnecessary QOM cast |
38 | util/vhost-user-server: drop unnecessary watch deletion | 44 | util/vhost-user-server: drop unnecessary watch deletion |
39 | block/export: consolidate request structs into VuBlockReq | 45 | block/export: consolidate request structs into VuBlockReq |
40 | util/vhost-user-server: drop unused DevicePanicNotifier | 46 | util/vhost-user-server: drop unused DevicePanicNotifier |
... | ... | ||
47 | util/vhost-user-server: use static library in meson.build | 53 | util/vhost-user-server: use static library in meson.build |
48 | qemu-storage-daemon: avoid compiling blockdev_ss twice | 54 | qemu-storage-daemon: avoid compiling blockdev_ss twice |
49 | block: move block exports to libblockdev | 55 | block: move block exports to libblockdev |
50 | block/export: add iothread and fixed-iothread options | 56 | block/export: add iothread and fixed-iothread options |
51 | block/export: add vhost-user-blk multi-queue support | 57 | block/export: add vhost-user-blk multi-queue support |
52 | tests/qtest: add multi-queue test case to vhost-user-blk-test | ||
53 | 58 | ||
54 | Vladimir Sementsov-Ogievskiy (5): | 59 | Vladimir Sementsov-Ogievskiy (5): |
55 | block/io: fix bdrv_co_block_status_above | 60 | block/io: fix bdrv_co_block_status_above |
56 | block/io: bdrv_common_block_status_above: support include_base | 61 | block/io: bdrv_common_block_status_above: support include_base |
57 | block/io: bdrv_common_block_status_above: support bs == base | 62 | block/io: bdrv_common_block_status_above: support bs == base |
58 | block/io: fix bdrv_is_allocated_above | 63 | block/io: fix bdrv_is_allocated_above |
59 | iotests: add commit top->base cases to 274 | 64 | iotests: add commit top->base cases to 274 |
60 | 65 | ||
61 | MAINTAINERS | 10 + | 66 | MAINTAINERS | 9 + |
62 | qapi/block-core.json | 24 +- | 67 | qapi/block-core.json | 24 +- |
63 | qapi/block-export.json | 36 +- | 68 | qapi/block-export.json | 36 +- |
64 | block/coroutines.h | 2 + | 69 | block/coroutines.h | 2 + |
65 | block/export/vhost-user-blk-server.h | 19 + | 70 | block/export/vhost-user-blk-server.h | 19 + |
66 | contrib/libvhost-user/libvhost-user.h | 21 + | 71 | contrib/libvhost-user/libvhost-user.h | 21 + |
67 | include/qemu/vhost-user-server.h | 65 ++ | 72 | include/qemu/vhost-user-server.h | 65 +++ |
68 | tests/qtest/libqos/libqtest.h | 17 + | ||
69 | tests/qtest/libqos/vhost-user-blk.h | 48 ++ | ||
70 | util/block-helpers.h | 19 + | 73 | util/block-helpers.h | 19 + |
71 | block/export/export.c | 37 +- | 74 | block/export/export.c | 37 +- |
72 | block/export/vhost-user-blk-server.c | 431 +++++++++++ | 75 | block/export/vhost-user-blk-server.c | 431 ++++++++++++++++++++ |
73 | block/io.c | 132 ++-- | 76 | block/io.c | 132 +++--- |
74 | block/nvme.c | 27 + | 77 | block/nvme.c | 27 ++ |
75 | block/qcow2.c | 16 +- | 78 | block/qcow2.c | 16 +- |
76 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- | 79 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- |
77 | contrib/libvhost-user/libvhost-user.c | 15 +- | 80 | contrib/libvhost-user/libvhost-user.c | 15 +- |
78 | hw/core/qdev-properties-system.c | 31 +- | 81 | hw/core/qdev-properties-system.c | 31 +- |
79 | nbd/server.c | 2 - | 82 | nbd/server.c | 2 - |
80 | qemu-nbd.c | 25 +- | 83 | qemu-nbd.c | 21 +- |
81 | softmmu/vl.c | 4 + | 84 | softmmu/vl.c | 4 + |
82 | stubs/blk-exp-close-all.c | 7 + | 85 | stubs/blk-exp-close-all.c | 7 + |
83 | tests/qtest/libqos/vhost-user-blk.c | 129 ++++ | ||
84 | tests/qtest/libqtest.c | 36 +- | ||
85 | tests/qtest/vhost-user-blk-test.c | 822 +++++++++++++++++++++ | ||
86 | tests/vhost-user-bridge.c | 2 + | 86 | tests/vhost-user-bridge.c | 2 + |
87 | tools/virtiofsd/fuse_virtio.c | 4 +- | 87 | tools/virtiofsd/fuse_virtio.c | 4 +- |
88 | util/block-helpers.c | 46 ++ | 88 | util/block-helpers.c | 46 +++ |
89 | util/vhost-user-server.c | 446 +++++++++++ | 89 | util/vhost-user-server.c | 446 +++++++++++++++++++++ |
90 | block/export/meson.build | 3 +- | 90 | block/export/meson.build | 3 +- |
91 | contrib/libvhost-user/meson.build | 1 + | 91 | contrib/libvhost-user/meson.build | 1 + |
92 | meson.build | 22 +- | 92 | meson.build | 22 +- |
93 | nbd/meson.build | 2 + | 93 | nbd/meson.build | 2 + |
94 | storage-daemon/meson.build | 3 +- | 94 | storage-daemon/meson.build | 3 +- |
95 | stubs/meson.build | 1 + | 95 | stubs/meson.build | 1 + |
96 | tests/qemu-iotests/274 | 20 + | 96 | tests/qemu-iotests/274 | 20 + |
97 | tests/qemu-iotests/274.out | 68 ++ | 97 | tests/qemu-iotests/274.out | 68 ++++ |
98 | tests/qtest/libqos/meson.build | 1 + | ||
99 | tests/qtest/meson.build | 4 +- | ||
100 | util/meson.build | 4 + | 98 | util/meson.build | 4 + |
101 | 40 files changed, 2476 insertions(+), 128 deletions(-) | 99 | 33 files changed, 1420 insertions(+), 122 deletions(-) |
102 | create mode 100644 block/export/vhost-user-blk-server.h | 100 | create mode 100644 block/export/vhost-user-blk-server.h |
103 | create mode 100644 include/qemu/vhost-user-server.h | 101 | create mode 100644 include/qemu/vhost-user-server.h |
104 | create mode 100644 tests/qtest/libqos/vhost-user-blk.h | ||
105 | create mode 100644 util/block-helpers.h | 102 | create mode 100644 util/block-helpers.h |
106 | create mode 100644 block/export/vhost-user-blk-server.c | 103 | create mode 100644 block/export/vhost-user-blk-server.c |
107 | create mode 100644 stubs/blk-exp-close-all.c | 104 | create mode 100644 stubs/blk-exp-close-all.c |
108 | create mode 100644 tests/qtest/libqos/vhost-user-blk.c | ||
109 | create mode 100644 tests/qtest/vhost-user-blk-test.c | ||
110 | create mode 100644 util/block-helpers.c | 105 | create mode 100644 util/block-helpers.c |
111 | create mode 100644 util/vhost-user-server.c | 106 | create mode 100644 util/vhost-user-server.c |
112 | 107 | ||
113 | -- | 108 | -- |
114 | 2.26.2 | 109 | 2.26.2 |
115 | 110 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Keep statistics of some hardware errors, and number of | 3 | Keep statistics of some hardware errors, and number of |
4 | aligned/unaligned I/O accesses. | 4 | aligned/unaligned I/O accesses. |
5 | 5 | ||
6 | QMP example booting a full RHEL 8.3 aarch64 guest: | 6 | QMP example booting a full RHEL 8.3 aarch64 guest: |
7 | 7 | ||
8 | { "execute": "query-blockstats" } | 8 | { "execute": "query-blockstats" } |
9 | { | 9 | { |
10 | "return": [ | 10 | "return": [ |
11 | { | 11 | { |
12 | "device": "", | 12 | "device": "", |
13 | "node-name": "drive0", | 13 | "node-name": "drive0", |
14 | "stats": { | 14 | "stats": { |
15 | "flush_total_time_ns": 6026948, | 15 | "flush_total_time_ns": 6026948, |
16 | "wr_highest_offset": 3383991230464, | 16 | "wr_highest_offset": 3383991230464, |
17 | "wr_total_time_ns": 807450995, | 17 | "wr_total_time_ns": 807450995, |
18 | "failed_wr_operations": 0, | 18 | "failed_wr_operations": 0, |
19 | "failed_rd_operations": 0, | 19 | "failed_rd_operations": 0, |
20 | "wr_merged": 3, | 20 | "wr_merged": 3, |
21 | "wr_bytes": 50133504, | 21 | "wr_bytes": 50133504, |
22 | "failed_unmap_operations": 0, | 22 | "failed_unmap_operations": 0, |
23 | "failed_flush_operations": 0, | 23 | "failed_flush_operations": 0, |
24 | "account_invalid": false, | 24 | "account_invalid": false, |
25 | "rd_total_time_ns": 1846979900, | 25 | "rd_total_time_ns": 1846979900, |
26 | "flush_operations": 130, | 26 | "flush_operations": 130, |
27 | "wr_operations": 659, | 27 | "wr_operations": 659, |
28 | "rd_merged": 1192, | 28 | "rd_merged": 1192, |
29 | "rd_bytes": 218244096, | 29 | "rd_bytes": 218244096, |
30 | "account_failed": false, | 30 | "account_failed": false, |
31 | "idle_time_ns": 2678641497, | 31 | "idle_time_ns": 2678641497, |
32 | "rd_operations": 7406, | 32 | "rd_operations": 7406, |
33 | }, | 33 | }, |
34 | "driver-specific": { | 34 | "driver-specific": { |
35 | "driver": "nvme", | 35 | "driver": "nvme", |
36 | "completion-errors": 0, | 36 | "completion-errors": 0, |
37 | "unaligned-accesses": 2959, | 37 | "unaligned-accesses": 2959, |
38 | "aligned-accesses": 4477 | 38 | "aligned-accesses": 4477 |
39 | }, | 39 | }, |
40 | "qdev": "/machine/peripheral-anon/device[0]/virtio-backend" | 40 | "qdev": "/machine/peripheral-anon/device[0]/virtio-backend" |
41 | } | 41 | } |
42 | ] | 42 | ] |
43 | } | 43 | } |
44 | 44 | ||
45 | Suggested-by: Stefan Hajnoczi <stefanha@gmail.com> | 45 | Suggested-by: Stefan Hajnoczi <stefanha@gmail.com> |
46 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 46 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
47 | Acked-by: Markus Armbruster <armbru@redhat.com> | 47 | Acked-by: Markus Armbruster <armbru@redhat.com> |
48 | Message-id: 20201001162939.1567915-1-philmd@redhat.com | 48 | Message-id: 20201001162939.1567915-1-philmd@redhat.com |
49 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 49 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
50 | --- | 50 | --- |
51 | qapi/block-core.json | 24 +++++++++++++++++++++++- | 51 | qapi/block-core.json | 24 +++++++++++++++++++++++- |
52 | block/nvme.c | 27 +++++++++++++++++++++++++++ | 52 | block/nvme.c | 27 +++++++++++++++++++++++++++ |
53 | 2 files changed, 50 insertions(+), 1 deletion(-) | 53 | 2 files changed, 50 insertions(+), 1 deletion(-) |
54 | 54 | ||
55 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 55 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
56 | index XXXXXXX..XXXXXXX 100644 | 56 | index XXXXXXX..XXXXXXX 100644 |
57 | --- a/qapi/block-core.json | 57 | --- a/qapi/block-core.json |
58 | +++ b/qapi/block-core.json | 58 | +++ b/qapi/block-core.json |
59 | @@ -XXX,XX +XXX,XX @@ | 59 | @@ -XXX,XX +XXX,XX @@ |
60 | 'discard-nb-failed': 'uint64', | 60 | 'discard-nb-failed': 'uint64', |
61 | 'discard-bytes-ok': 'uint64' } } | 61 | 'discard-bytes-ok': 'uint64' } } |
62 | 62 | ||
63 | +## | 63 | +## |
64 | +# @BlockStatsSpecificNvme: | 64 | +# @BlockStatsSpecificNvme: |
65 | +# | 65 | +# |
66 | +# NVMe driver statistics | 66 | +# NVMe driver statistics |
67 | +# | 67 | +# |
68 | +# @completion-errors: The number of completion errors. | 68 | +# @completion-errors: The number of completion errors. |
69 | +# | 69 | +# |
70 | +# @aligned-accesses: The number of aligned accesses performed by | 70 | +# @aligned-accesses: The number of aligned accesses performed by |
71 | +# the driver. | 71 | +# the driver. |
72 | +# | 72 | +# |
73 | +# @unaligned-accesses: The number of unaligned accesses performed by | 73 | +# @unaligned-accesses: The number of unaligned accesses performed by |
74 | +# the driver. | 74 | +# the driver. |
75 | +# | 75 | +# |
76 | +# Since: 5.2 | 76 | +# Since: 5.2 |
77 | +## | 77 | +## |
78 | +{ 'struct': 'BlockStatsSpecificNvme', | 78 | +{ 'struct': 'BlockStatsSpecificNvme', |
79 | + 'data': { | 79 | + 'data': { |
80 | + 'completion-errors': 'uint64', | 80 | + 'completion-errors': 'uint64', |
81 | + 'aligned-accesses': 'uint64', | 81 | + 'aligned-accesses': 'uint64', |
82 | + 'unaligned-accesses': 'uint64' } } | 82 | + 'unaligned-accesses': 'uint64' } } |
83 | + | 83 | + |
84 | ## | 84 | ## |
85 | # @BlockStatsSpecific: | 85 | # @BlockStatsSpecific: |
86 | # | 86 | # |
87 | @@ -XXX,XX +XXX,XX @@ | 87 | @@ -XXX,XX +XXX,XX @@ |
88 | 'discriminator': 'driver', | 88 | 'discriminator': 'driver', |
89 | 'data': { | 89 | 'data': { |
90 | 'file': 'BlockStatsSpecificFile', | 90 | 'file': 'BlockStatsSpecificFile', |
91 | - 'host_device': 'BlockStatsSpecificFile' } } | 91 | - 'host_device': 'BlockStatsSpecificFile' } } |
92 | + 'host_device': 'BlockStatsSpecificFile', | 92 | + 'host_device': 'BlockStatsSpecificFile', |
93 | + 'nvme': 'BlockStatsSpecificNvme' } } | 93 | + 'nvme': 'BlockStatsSpecificNvme' } } |
94 | 94 | ||
95 | ## | 95 | ## |
96 | # @BlockStats: | 96 | # @BlockStats: |
97 | diff --git a/block/nvme.c b/block/nvme.c | 97 | diff --git a/block/nvme.c b/block/nvme.c |
98 | index XXXXXXX..XXXXXXX 100644 | 98 | index XXXXXXX..XXXXXXX 100644 |
99 | --- a/block/nvme.c | 99 | --- a/block/nvme.c |
100 | +++ b/block/nvme.c | 100 | +++ b/block/nvme.c |
101 | @@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState { | 101 | @@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState { |
102 | 102 | ||
103 | /* PCI address (required for nvme_refresh_filename()) */ | 103 | /* PCI address (required for nvme_refresh_filename()) */ |
104 | char *device; | 104 | char *device; |
105 | + | 105 | + |
106 | + struct { | 106 | + struct { |
107 | + uint64_t completion_errors; | 107 | + uint64_t completion_errors; |
108 | + uint64_t aligned_accesses; | 108 | + uint64_t aligned_accesses; |
109 | + uint64_t unaligned_accesses; | 109 | + uint64_t unaligned_accesses; |
110 | + } stats; | 110 | + } stats; |
111 | }; | 111 | }; |
112 | 112 | ||
113 | #define NVME_BLOCK_OPT_DEVICE "device" | 113 | #define NVME_BLOCK_OPT_DEVICE "device" |
114 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | 114 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) |
115 | break; | 115 | break; |
116 | } | 116 | } |
117 | ret = nvme_translate_error(c); | 117 | ret = nvme_translate_error(c); |
118 | + if (ret) { | 118 | + if (ret) { |
119 | + s->stats.completion_errors++; | 119 | + s->stats.completion_errors++; |
120 | + } | 120 | + } |
121 | q->cq.head = (q->cq.head + 1) % NVME_QUEUE_SIZE; | 121 | q->cq.head = (q->cq.head + 1) % NVME_QUEUE_SIZE; |
122 | if (!q->cq.head) { | 122 | if (!q->cq.head) { |
123 | q->cq_phase = !q->cq_phase; | 123 | q->cq_phase = !q->cq_phase; |
124 | @@ -XXX,XX +XXX,XX @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | 124 | @@ -XXX,XX +XXX,XX @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, |
125 | assert(QEMU_IS_ALIGNED(bytes, s->page_size)); | 125 | assert(QEMU_IS_ALIGNED(bytes, s->page_size)); |
126 | assert(bytes <= s->max_transfer); | 126 | assert(bytes <= s->max_transfer); |
127 | if (nvme_qiov_aligned(bs, qiov)) { | 127 | if (nvme_qiov_aligned(bs, qiov)) { |
128 | + s->stats.aligned_accesses++; | 128 | + s->stats.aligned_accesses++; |
129 | return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flags); | 129 | return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flags); |
130 | } | 130 | } |
131 | + s->stats.unaligned_accesses++; | 131 | + s->stats.unaligned_accesses++; |
132 | trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); | 132 | trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); |
133 | buf = qemu_try_memalign(s->page_size, bytes); | 133 | buf = qemu_try_memalign(s->page_size, bytes); |
134 | 134 | ||
135 | @@ -XXX,XX +XXX,XX @@ static void nvme_unregister_buf(BlockDriverState *bs, void *host) | 135 | @@ -XXX,XX +XXX,XX @@ static void nvme_unregister_buf(BlockDriverState *bs, void *host) |
136 | qemu_vfio_dma_unmap(s->vfio, host); | 136 | qemu_vfio_dma_unmap(s->vfio, host); |
137 | } | 137 | } |
138 | 138 | ||
139 | +static BlockStatsSpecific *nvme_get_specific_stats(BlockDriverState *bs) | 139 | +static BlockStatsSpecific *nvme_get_specific_stats(BlockDriverState *bs) |
140 | +{ | 140 | +{ |
141 | + BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); | 141 | + BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); |
142 | + BDRVNVMeState *s = bs->opaque; | 142 | + BDRVNVMeState *s = bs->opaque; |
143 | + | 143 | + |
144 | + stats->driver = BLOCKDEV_DRIVER_NVME; | 144 | + stats->driver = BLOCKDEV_DRIVER_NVME; |
145 | + stats->u.nvme = (BlockStatsSpecificNvme) { | 145 | + stats->u.nvme = (BlockStatsSpecificNvme) { |
146 | + .completion_errors = s->stats.completion_errors, | 146 | + .completion_errors = s->stats.completion_errors, |
147 | + .aligned_accesses = s->stats.aligned_accesses, | 147 | + .aligned_accesses = s->stats.aligned_accesses, |
148 | + .unaligned_accesses = s->stats.unaligned_accesses, | 148 | + .unaligned_accesses = s->stats.unaligned_accesses, |
149 | + }; | 149 | + }; |
150 | + | 150 | + |
151 | + return stats; | 151 | + return stats; |
152 | +} | 152 | +} |
153 | + | 153 | + |
154 | static const char *const nvme_strong_runtime_opts[] = { | 154 | static const char *const nvme_strong_runtime_opts[] = { |
155 | NVME_BLOCK_OPT_DEVICE, | 155 | NVME_BLOCK_OPT_DEVICE, |
156 | NVME_BLOCK_OPT_NAMESPACE, | 156 | NVME_BLOCK_OPT_NAMESPACE, |
157 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nvme = { | 157 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nvme = { |
158 | .bdrv_refresh_filename = nvme_refresh_filename, | 158 | .bdrv_refresh_filename = nvme_refresh_filename, |
159 | .bdrv_refresh_limits = nvme_refresh_limits, | 159 | .bdrv_refresh_limits = nvme_refresh_limits, |
160 | .strong_runtime_opts = nvme_strong_runtime_opts, | 160 | .strong_runtime_opts = nvme_strong_runtime_opts, |
161 | + .bdrv_get_specific_stats = nvme_get_specific_stats, | 161 | + .bdrv_get_specific_stats = nvme_get_specific_stats, |
162 | 162 | ||
163 | .bdrv_detach_aio_context = nvme_detach_aio_context, | 163 | .bdrv_detach_aio_context = nvme_detach_aio_context, |
164 | .bdrv_attach_aio_context = nvme_attach_aio_context, | 164 | .bdrv_attach_aio_context = nvme_attach_aio_context, |
165 | -- | 165 | -- |
166 | 2.26.2 | 166 | 2.26.2 |
167 | 167 | diff view generated by jsdifflib |
1 | From: Coiby Xu <coiby.xu@gmail.com> | 1 | From: Coiby Xu <coiby.xu@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Allow vu_message_read to be replaced by one which will make use of the | 3 | Allow vu_message_read to be replaced by one which will make use of the |
4 | QIOChannel functions. Thus reading vhost-user message won't stall the | 4 | QIOChannel functions. Thus reading vhost-user message won't stall the |
5 | guest. For slave channel, we still use the default vu_message_read. | 5 | guest. For slave channel, we still use the default vu_message_read. |
6 | 6 | ||
7 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 7 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
8 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | 8 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | Message-id: 20200918080912.321299-2-coiby.xu@gmail.com | 10 | Message-id: 20200918080912.321299-2-coiby.xu@gmail.com |
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 12 | --- |
13 | contrib/libvhost-user/libvhost-user.h | 21 +++++++++++++++++++++ | 13 | contrib/libvhost-user/libvhost-user.h | 21 +++++++++++++++++++++ |
14 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- | 14 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- |
15 | contrib/libvhost-user/libvhost-user.c | 14 +++++++------- | 15 | contrib/libvhost-user/libvhost-user.c | 14 +++++++------- |
16 | tests/vhost-user-bridge.c | 2 ++ | 16 | tests/vhost-user-bridge.c | 2 ++ |
17 | tools/virtiofsd/fuse_virtio.c | 4 ++-- | 17 | tools/virtiofsd/fuse_virtio.c | 4 ++-- |
18 | 5 files changed, 33 insertions(+), 10 deletions(-) | 18 | 5 files changed, 33 insertions(+), 10 deletions(-) |
19 | 19 | ||
20 | diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h | 20 | diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h |
21 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/contrib/libvhost-user/libvhost-user.h | 22 | --- a/contrib/libvhost-user/libvhost-user.h |
23 | +++ b/contrib/libvhost-user/libvhost-user.h | 23 | +++ b/contrib/libvhost-user/libvhost-user.h |
24 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
25 | */ | 25 | */ |
26 | #define VHOST_USER_MAX_RAM_SLOTS 32 | 26 | #define VHOST_USER_MAX_RAM_SLOTS 32 |
27 | 27 | ||
28 | +#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) | 28 | +#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) |
29 | + | 29 | + |
30 | typedef enum VhostSetConfigType { | 30 | typedef enum VhostSetConfigType { |
31 | VHOST_SET_CONFIG_TYPE_MASTER = 0, | 31 | VHOST_SET_CONFIG_TYPE_MASTER = 0, |
32 | VHOST_SET_CONFIG_TYPE_MIGRATION = 1, | 32 | VHOST_SET_CONFIG_TYPE_MIGRATION = 1, |
33 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t (*vu_get_features_cb) (VuDev *dev); | 33 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t (*vu_get_features_cb) (VuDev *dev); |
34 | typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features); | 34 | typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features); |
35 | typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, | 35 | typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, |
36 | int *do_reply); | 36 | int *do_reply); |
37 | +typedef bool (*vu_read_msg_cb) (VuDev *dev, int sock, VhostUserMsg *vmsg); | 37 | +typedef bool (*vu_read_msg_cb) (VuDev *dev, int sock, VhostUserMsg *vmsg); |
38 | typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started); | 38 | typedef void (*vu_queue_set_started_cb) (VuDev *dev, int qidx, bool started); |
39 | typedef bool (*vu_queue_is_processed_in_order_cb) (VuDev *dev, int qidx); | 39 | typedef bool (*vu_queue_is_processed_in_order_cb) (VuDev *dev, int qidx); |
40 | typedef int (*vu_get_config_cb) (VuDev *dev, uint8_t *config, uint32_t len); | 40 | typedef int (*vu_get_config_cb) (VuDev *dev, uint8_t *config, uint32_t len); |
41 | @@ -XXX,XX +XXX,XX @@ struct VuDev { | 41 | @@ -XXX,XX +XXX,XX @@ struct VuDev { |
42 | bool broken; | 42 | bool broken; |
43 | uint16_t max_queues; | 43 | uint16_t max_queues; |
44 | 44 | ||
45 | + /* @read_msg: custom method to read vhost-user message | 45 | + /* @read_msg: custom method to read vhost-user message |
46 | + * | 46 | + * |
47 | + * Read data from vhost_user socket fd and fill up | 47 | + * Read data from vhost_user socket fd and fill up |
48 | + * the passed VhostUserMsg *vmsg struct. | 48 | + * the passed VhostUserMsg *vmsg struct. |
49 | + * | 49 | + * |
50 | + * If reading fails, it should close the received set of file | 50 | + * If reading fails, it should close the received set of file |
51 | + * descriptors as socket message's auxiliary data. | 51 | + * descriptors as socket message's auxiliary data. |
52 | + * | 52 | + * |
53 | + * For the details, please refer to vu_message_read in libvhost-user.c | 53 | + * For the details, please refer to vu_message_read in libvhost-user.c |
54 | + * which will be used by default if not custom method is provided when | 54 | + * which will be used by default if not custom method is provided when |
55 | + * calling vu_init | 55 | + * calling vu_init |
56 | + * | 56 | + * |
57 | + * Returns: true if vhost-user message successfully received, | 57 | + * Returns: true if vhost-user message successfully received, |
58 | + * otherwise return false. | 58 | + * otherwise return false. |
59 | + * | 59 | + * |
60 | + */ | 60 | + */ |
61 | + vu_read_msg_cb read_msg; | 61 | + vu_read_msg_cb read_msg; |
62 | /* @set_watch: add or update the given fd to the watch set, | 62 | /* @set_watch: add or update the given fd to the watch set, |
63 | * call cb when condition is met */ | 63 | * call cb when condition is met */ |
64 | vu_set_watch_cb set_watch; | 64 | vu_set_watch_cb set_watch; |
65 | @@ -XXX,XX +XXX,XX @@ bool vu_init(VuDev *dev, | 65 | @@ -XXX,XX +XXX,XX @@ bool vu_init(VuDev *dev, |
66 | uint16_t max_queues, | 66 | uint16_t max_queues, |
67 | int socket, | 67 | int socket, |
68 | vu_panic_cb panic, | 68 | vu_panic_cb panic, |
69 | + vu_read_msg_cb read_msg, | 69 | + vu_read_msg_cb read_msg, |
70 | vu_set_watch_cb set_watch, | 70 | vu_set_watch_cb set_watch, |
71 | vu_remove_watch_cb remove_watch, | 71 | vu_remove_watch_cb remove_watch, |
72 | const VuDevIface *iface); | 72 | const VuDevIface *iface); |
73 | diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c | 73 | diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c |
74 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/contrib/libvhost-user/libvhost-user-glib.c | 75 | --- a/contrib/libvhost-user/libvhost-user-glib.c |
76 | +++ b/contrib/libvhost-user/libvhost-user-glib.c | 76 | +++ b/contrib/libvhost-user/libvhost-user-glib.c |
77 | @@ -XXX,XX +XXX,XX @@ vug_init(VugDev *dev, uint16_t max_queues, int socket, | 77 | @@ -XXX,XX +XXX,XX @@ vug_init(VugDev *dev, uint16_t max_queues, int socket, |
78 | g_assert(dev); | 78 | g_assert(dev); |
79 | g_assert(iface); | 79 | g_assert(iface); |
80 | 80 | ||
81 | - if (!vu_init(&dev->parent, max_queues, socket, panic, set_watch, | 81 | - if (!vu_init(&dev->parent, max_queues, socket, panic, set_watch, |
82 | + if (!vu_init(&dev->parent, max_queues, socket, panic, NULL, set_watch, | 82 | + if (!vu_init(&dev->parent, max_queues, socket, panic, NULL, set_watch, |
83 | remove_watch, iface)) { | 83 | remove_watch, iface)) { |
84 | return false; | 84 | return false; |
85 | } | 85 | } |
86 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c | 86 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c |
87 | index XXXXXXX..XXXXXXX 100644 | 87 | index XXXXXXX..XXXXXXX 100644 |
88 | --- a/contrib/libvhost-user/libvhost-user.c | 88 | --- a/contrib/libvhost-user/libvhost-user.c |
89 | +++ b/contrib/libvhost-user/libvhost-user.c | 89 | +++ b/contrib/libvhost-user/libvhost-user.c |
90 | @@ -XXX,XX +XXX,XX @@ | 90 | @@ -XXX,XX +XXX,XX @@ |
91 | /* The version of inflight buffer */ | 91 | /* The version of inflight buffer */ |
92 | #define INFLIGHT_VERSION 1 | 92 | #define INFLIGHT_VERSION 1 |
93 | 93 | ||
94 | -#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) | 94 | -#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) |
95 | - | 95 | - |
96 | /* The version of the protocol we support */ | 96 | /* The version of the protocol we support */ |
97 | #define VHOST_USER_VERSION 1 | 97 | #define VHOST_USER_VERSION 1 |
98 | #define LIBVHOST_USER_DEBUG 0 | 98 | #define LIBVHOST_USER_DEBUG 0 |
99 | @@ -XXX,XX +XXX,XX @@ have_userfault(void) | 99 | @@ -XXX,XX +XXX,XX @@ have_userfault(void) |
100 | } | 100 | } |
101 | 101 | ||
102 | static bool | 102 | static bool |
103 | -vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) | 103 | -vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) |
104 | +vu_message_read_default(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) | 104 | +vu_message_read_default(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) |
105 | { | 105 | { |
106 | char control[CMSG_SPACE(VHOST_MEMORY_BASELINE_NREGIONS * sizeof(int))] = {}; | 106 | char control[CMSG_SPACE(VHOST_MEMORY_BASELINE_NREGIONS * sizeof(int))] = {}; |
107 | struct iovec iov = { | 107 | struct iovec iov = { |
108 | @@ -XXX,XX +XXX,XX @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg) | 108 | @@ -XXX,XX +XXX,XX @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg) |
109 | goto out; | 109 | goto out; |
110 | } | 110 | } |
111 | 111 | ||
112 | - if (!vu_message_read(dev, dev->slave_fd, &msg_reply)) { | 112 | - if (!vu_message_read(dev, dev->slave_fd, &msg_reply)) { |
113 | + if (!vu_message_read_default(dev, dev->slave_fd, &msg_reply)) { | 113 | + if (!vu_message_read_default(dev, dev->slave_fd, &msg_reply)) { |
114 | goto out; | 114 | goto out; |
115 | } | 115 | } |
116 | 116 | ||
117 | @@ -XXX,XX +XXX,XX @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg) | 117 | @@ -XXX,XX +XXX,XX @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg) |
118 | /* Wait for QEMU to confirm that it's registered the handler for the | 118 | /* Wait for QEMU to confirm that it's registered the handler for the |
119 | * faults. | 119 | * faults. |
120 | */ | 120 | */ |
121 | - if (!vu_message_read(dev, dev->sock, vmsg) || | 121 | - if (!vu_message_read(dev, dev->sock, vmsg) || |
122 | + if (!dev->read_msg(dev, dev->sock, vmsg) || | 122 | + if (!dev->read_msg(dev, dev->sock, vmsg) || |
123 | vmsg->size != sizeof(vmsg->payload.u64) || | 123 | vmsg->size != sizeof(vmsg->payload.u64) || |
124 | vmsg->payload.u64 != 0) { | 124 | vmsg->payload.u64 != 0) { |
125 | vu_panic(dev, "failed to receive valid ack for postcopy set-mem-table"); | 125 | vu_panic(dev, "failed to receive valid ack for postcopy set-mem-table"); |
126 | @@ -XXX,XX +XXX,XX @@ vu_dispatch(VuDev *dev) | 126 | @@ -XXX,XX +XXX,XX @@ vu_dispatch(VuDev *dev) |
127 | int reply_requested; | 127 | int reply_requested; |
128 | bool need_reply, success = false; | 128 | bool need_reply, success = false; |
129 | 129 | ||
130 | - if (!vu_message_read(dev, dev->sock, &vmsg)) { | 130 | - if (!vu_message_read(dev, dev->sock, &vmsg)) { |
131 | + if (!dev->read_msg(dev, dev->sock, &vmsg)) { | 131 | + if (!dev->read_msg(dev, dev->sock, &vmsg)) { |
132 | goto end; | 132 | goto end; |
133 | } | 133 | } |
134 | 134 | ||
135 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, | 135 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, |
136 | uint16_t max_queues, | 136 | uint16_t max_queues, |
137 | int socket, | 137 | int socket, |
138 | vu_panic_cb panic, | 138 | vu_panic_cb panic, |
139 | + vu_read_msg_cb read_msg, | 139 | + vu_read_msg_cb read_msg, |
140 | vu_set_watch_cb set_watch, | 140 | vu_set_watch_cb set_watch, |
141 | vu_remove_watch_cb remove_watch, | 141 | vu_remove_watch_cb remove_watch, |
142 | const VuDevIface *iface) | 142 | const VuDevIface *iface) |
143 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, | 143 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, |
144 | 144 | ||
145 | dev->sock = socket; | 145 | dev->sock = socket; |
146 | dev->panic = panic; | 146 | dev->panic = panic; |
147 | + dev->read_msg = read_msg ? read_msg : vu_message_read_default; | 147 | + dev->read_msg = read_msg ? read_msg : vu_message_read_default; |
148 | dev->set_watch = set_watch; | 148 | dev->set_watch = set_watch; |
149 | dev->remove_watch = remove_watch; | 149 | dev->remove_watch = remove_watch; |
150 | dev->iface = iface; | 150 | dev->iface = iface; |
151 | @@ -XXX,XX +XXX,XX @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) | 151 | @@ -XXX,XX +XXX,XX @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) |
152 | 152 | ||
153 | vu_message_write(dev, dev->slave_fd, &vmsg); | 153 | vu_message_write(dev, dev->slave_fd, &vmsg); |
154 | if (ack) { | 154 | if (ack) { |
155 | - vu_message_read(dev, dev->slave_fd, &vmsg); | 155 | - vu_message_read(dev, dev->slave_fd, &vmsg); |
156 | + vu_message_read_default(dev, dev->slave_fd, &vmsg); | 156 | + vu_message_read_default(dev, dev->slave_fd, &vmsg); |
157 | } | 157 | } |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c | 160 | diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c |
161 | index XXXXXXX..XXXXXXX 100644 | 161 | index XXXXXXX..XXXXXXX 100644 |
162 | --- a/tests/vhost-user-bridge.c | 162 | --- a/tests/vhost-user-bridge.c |
163 | +++ b/tests/vhost-user-bridge.c | 163 | +++ b/tests/vhost-user-bridge.c |
164 | @@ -XXX,XX +XXX,XX @@ vubr_accept_cb(int sock, void *ctx) | 164 | @@ -XXX,XX +XXX,XX @@ vubr_accept_cb(int sock, void *ctx) |
165 | VHOST_USER_BRIDGE_MAX_QUEUES, | 165 | VHOST_USER_BRIDGE_MAX_QUEUES, |
166 | conn_fd, | 166 | conn_fd, |
167 | vubr_panic, | 167 | vubr_panic, |
168 | + NULL, | 168 | + NULL, |
169 | vubr_set_watch, | 169 | vubr_set_watch, |
170 | vubr_remove_watch, | 170 | vubr_remove_watch, |
171 | &vuiface)) { | 171 | &vuiface)) { |
172 | @@ -XXX,XX +XXX,XX @@ vubr_new(const char *path, bool client) | 172 | @@ -XXX,XX +XXX,XX @@ vubr_new(const char *path, bool client) |
173 | VHOST_USER_BRIDGE_MAX_QUEUES, | 173 | VHOST_USER_BRIDGE_MAX_QUEUES, |
174 | dev->sock, | 174 | dev->sock, |
175 | vubr_panic, | 175 | vubr_panic, |
176 | + NULL, | 176 | + NULL, |
177 | vubr_set_watch, | 177 | vubr_set_watch, |
178 | vubr_remove_watch, | 178 | vubr_remove_watch, |
179 | &vuiface)) { | 179 | &vuiface)) { |
180 | diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c | 180 | diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c |
181 | index XXXXXXX..XXXXXXX 100644 | 181 | index XXXXXXX..XXXXXXX 100644 |
182 | --- a/tools/virtiofsd/fuse_virtio.c | 182 | --- a/tools/virtiofsd/fuse_virtio.c |
183 | +++ b/tools/virtiofsd/fuse_virtio.c | 183 | +++ b/tools/virtiofsd/fuse_virtio.c |
184 | @@ -XXX,XX +XXX,XX @@ int virtio_session_mount(struct fuse_session *se) | 184 | @@ -XXX,XX +XXX,XX @@ int virtio_session_mount(struct fuse_session *se) |
185 | se->vu_socketfd = data_sock; | 185 | se->vu_socketfd = data_sock; |
186 | se->virtio_dev->se = se; | 186 | se->virtio_dev->se = se; |
187 | pthread_rwlock_init(&se->virtio_dev->vu_dispatch_rwlock, NULL); | 187 | pthread_rwlock_init(&se->virtio_dev->vu_dispatch_rwlock, NULL); |
188 | - vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, fv_set_watch, | 188 | - vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, fv_set_watch, |
189 | - fv_remove_watch, &fv_iface); | 189 | - fv_remove_watch, &fv_iface); |
190 | + vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, NULL, | 190 | + vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, NULL, |
191 | + fv_set_watch, fv_remove_watch, &fv_iface); | 191 | + fv_set_watch, fv_remove_watch, &fv_iface); |
192 | 192 | ||
193 | return 0; | 193 | return 0; |
194 | } | 194 | } |
195 | -- | 195 | -- |
196 | 2.26.2 | 196 | 2.26.2 |
197 | 197 | diff view generated by jsdifflib |
1 | From: Coiby Xu <coiby.xu@gmail.com> | 1 | From: Coiby Xu <coiby.xu@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | When the client is running in gdb and quit command is run in gdb, | 3 | When the client is running in gdb and quit command is run in gdb, |
4 | QEMU will still dispatch the event which will cause segment fault in | 4 | QEMU will still dispatch the event which will cause segment fault in |
5 | the callback function. | 5 | the callback function. |
6 | 6 | ||
7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | 7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
10 | Message-id: 20200918080912.321299-3-coiby.xu@gmail.com | 10 | Message-id: 20200918080912.321299-3-coiby.xu@gmail.com |
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 12 | --- |
13 | contrib/libvhost-user/libvhost-user.c | 1 + | 13 | contrib/libvhost-user/libvhost-user.c | 1 + |
14 | 1 file changed, 1 insertion(+) | 14 | 1 file changed, 1 insertion(+) |
15 | 15 | ||
16 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c | 16 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/contrib/libvhost-user/libvhost-user.c | 18 | --- a/contrib/libvhost-user/libvhost-user.c |
19 | +++ b/contrib/libvhost-user/libvhost-user.c | 19 | +++ b/contrib/libvhost-user/libvhost-user.c |
20 | @@ -XXX,XX +XXX,XX @@ vu_deinit(VuDev *dev) | 20 | @@ -XXX,XX +XXX,XX @@ vu_deinit(VuDev *dev) |
21 | } | 21 | } |
22 | 22 | ||
23 | if (vq->kick_fd != -1) { | 23 | if (vq->kick_fd != -1) { |
24 | + dev->remove_watch(dev, vq->kick_fd); | 24 | + dev->remove_watch(dev, vq->kick_fd); |
25 | close(vq->kick_fd); | 25 | close(vq->kick_fd); |
26 | vq->kick_fd = -1; | 26 | vq->kick_fd = -1; |
27 | } | 27 | } |
28 | -- | 28 | -- |
29 | 2.26.2 | 29 | 2.26.2 |
30 | 30 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | 9 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 11 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
12 | Message-id: 20200918080912.321299-4-coiby.xu@gmail.com | 12 | Message-id: 20200918080912.321299-4-coiby.xu@gmail.com |
13 | [Fixed size_t %lu -> %zu format string compiler error. | ||
14 | --Stefan] | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 16 | --- |
15 | util/vhost-user-server.h | 65 ++++++ | 17 | util/vhost-user-server.h | 65 ++++++ |
16 | util/vhost-user-server.c | 428 +++++++++++++++++++++++++++++++++++++++ | 18 | util/vhost-user-server.c | 428 +++++++++++++++++++++++++++++++++++++++ |
17 | util/meson.build | 1 + | 19 | util/meson.build | 1 + |
... | ... | ||
251 | + } | 253 | + } |
252 | + read_bytes += rc; | 254 | + read_bytes += rc; |
253 | + if (nfds_t > 0) { | 255 | + if (nfds_t > 0) { |
254 | + if (nfds + nfds_t > max_fds) { | 256 | + if (nfds + nfds_t > max_fds) { |
255 | + error_report("A maximum of %zu fds are allowed, " | 257 | + error_report("A maximum of %zu fds are allowed, " |
256 | + "however got %lu fds now", | 258 | + "however got %zu fds now", |
257 | + max_fds, nfds + nfds_t); | 259 | + max_fds, nfds + nfds_t); |
258 | + goto fail; | 260 | + goto fail; |
259 | + } | 261 | + } |
260 | + memcpy(vmsg->fds + nfds, fds_t, | 262 | + memcpy(vmsg->fds + nfds, fds_t, |
261 | + nfds_t *sizeof(vmsg->fds[0])); | 263 | + nfds_t *sizeof(vmsg->fds[0])); |
... | ... | diff view generated by jsdifflib |
1 | From: Coiby Xu <coiby.xu@gmail.com> | 1 | From: Coiby Xu <coiby.xu@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Move the constants from hw/core/qdev-properties.c to | 3 | Move the constants from hw/core/qdev-properties.c to |
4 | util/block-helpers.h so that knowledge of the min/max values is | 4 | util/block-helpers.h so that knowledge of the min/max values is |
5 | 5 | ||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | 7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
10 | Acked-by: Eduardo Habkost <ehabkost@redhat.com> | 10 | Acked-by: Eduardo Habkost <ehabkost@redhat.com> |
11 | Message-id: 20200918080912.321299-5-coiby.xu@gmail.com | 11 | Message-id: 20200918080912.321299-5-coiby.xu@gmail.com |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 13 | --- |
14 | util/block-helpers.h | 19 +++++++++++++ | 14 | util/block-helpers.h | 19 +++++++++++++ |
15 | hw/core/qdev-properties-system.c | 31 ++++----------------- | 15 | hw/core/qdev-properties-system.c | 31 ++++----------------- |
16 | util/block-helpers.c | 46 ++++++++++++++++++++++++++++++++ | 16 | util/block-helpers.c | 46 ++++++++++++++++++++++++++++++++ |
17 | util/meson.build | 1 + | 17 | util/meson.build | 1 + |
18 | 4 files changed, 71 insertions(+), 26 deletions(-) | 18 | 4 files changed, 71 insertions(+), 26 deletions(-) |
19 | create mode 100644 util/block-helpers.h | 19 | create mode 100644 util/block-helpers.h |
20 | create mode 100644 util/block-helpers.c | 20 | create mode 100644 util/block-helpers.c |
21 | 21 | ||
22 | diff --git a/util/block-helpers.h b/util/block-helpers.h | 22 | diff --git a/util/block-helpers.h b/util/block-helpers.h |
23 | new file mode 100644 | 23 | new file mode 100644 |
24 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
25 | --- /dev/null | 25 | --- /dev/null |
26 | +++ b/util/block-helpers.h | 26 | +++ b/util/block-helpers.h |
27 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
28 | +#ifndef BLOCK_HELPERS_H | 28 | +#ifndef BLOCK_HELPERS_H |
29 | +#define BLOCK_HELPERS_H | 29 | +#define BLOCK_HELPERS_H |
30 | + | 30 | + |
31 | +#include "qemu/units.h" | 31 | +#include "qemu/units.h" |
32 | + | 32 | + |
33 | +/* lower limit is sector size */ | 33 | +/* lower limit is sector size */ |
34 | +#define MIN_BLOCK_SIZE INT64_C(512) | 34 | +#define MIN_BLOCK_SIZE INT64_C(512) |
35 | +#define MIN_BLOCK_SIZE_STR "512 B" | 35 | +#define MIN_BLOCK_SIZE_STR "512 B" |
36 | +/* | 36 | +/* |
37 | + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and | 37 | + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and |
38 | + * matches qcow2 cluster size limit | 38 | + * matches qcow2 cluster size limit |
39 | + */ | 39 | + */ |
40 | +#define MAX_BLOCK_SIZE (2 * MiB) | 40 | +#define MAX_BLOCK_SIZE (2 * MiB) |
41 | +#define MAX_BLOCK_SIZE_STR "2 MiB" | 41 | +#define MAX_BLOCK_SIZE_STR "2 MiB" |
42 | + | 42 | + |
43 | +void check_block_size(const char *id, const char *name, int64_t value, | 43 | +void check_block_size(const char *id, const char *name, int64_t value, |
44 | + Error **errp); | 44 | + Error **errp); |
45 | + | 45 | + |
46 | +#endif /* BLOCK_HELPERS_H */ | 46 | +#endif /* BLOCK_HELPERS_H */ |
47 | diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c | 47 | diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c |
48 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/hw/core/qdev-properties-system.c | 49 | --- a/hw/core/qdev-properties-system.c |
50 | +++ b/hw/core/qdev-properties-system.c | 50 | +++ b/hw/core/qdev-properties-system.c |
51 | @@ -XXX,XX +XXX,XX @@ | 51 | @@ -XXX,XX +XXX,XX @@ |
52 | #include "sysemu/blockdev.h" | 52 | #include "sysemu/blockdev.h" |
53 | #include "net/net.h" | 53 | #include "net/net.h" |
54 | #include "hw/pci/pci.h" | 54 | #include "hw/pci/pci.h" |
55 | +#include "util/block-helpers.h" | 55 | +#include "util/block-helpers.h" |
56 | 56 | ||
57 | static bool check_prop_still_unset(DeviceState *dev, const char *name, | 57 | static bool check_prop_still_unset(DeviceState *dev, const char *name, |
58 | const void *old_val, const char *new_val, | 58 | const void *old_val, const char *new_val, |
59 | @@ -XXX,XX +XXX,XX @@ const PropertyInfo qdev_prop_losttickpolicy = { | 59 | @@ -XXX,XX +XXX,XX @@ const PropertyInfo qdev_prop_losttickpolicy = { |
60 | 60 | ||
61 | /* --- blocksize --- */ | 61 | /* --- blocksize --- */ |
62 | 62 | ||
63 | -/* lower limit is sector size */ | 63 | -/* lower limit is sector size */ |
64 | -#define MIN_BLOCK_SIZE 512 | 64 | -#define MIN_BLOCK_SIZE 512 |
65 | -#define MIN_BLOCK_SIZE_STR "512 B" | 65 | -#define MIN_BLOCK_SIZE_STR "512 B" |
66 | -/* | 66 | -/* |
67 | - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and | 67 | - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and |
68 | - * matches qcow2 cluster size limit | 68 | - * matches qcow2 cluster size limit |
69 | - */ | 69 | - */ |
70 | -#define MAX_BLOCK_SIZE (2 * MiB) | 70 | -#define MAX_BLOCK_SIZE (2 * MiB) |
71 | -#define MAX_BLOCK_SIZE_STR "2 MiB" | 71 | -#define MAX_BLOCK_SIZE_STR "2 MiB" |
72 | - | 72 | - |
73 | static void set_blocksize(Object *obj, Visitor *v, const char *name, | 73 | static void set_blocksize(Object *obj, Visitor *v, const char *name, |
74 | void *opaque, Error **errp) | 74 | void *opaque, Error **errp) |
75 | { | 75 | { |
76 | @@ -XXX,XX +XXX,XX @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, | 76 | @@ -XXX,XX +XXX,XX @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, |
77 | Property *prop = opaque; | 77 | Property *prop = opaque; |
78 | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); | 78 | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); |
79 | uint64_t value; | 79 | uint64_t value; |
80 | + Error *local_err = NULL; | 80 | + Error *local_err = NULL; |
81 | 81 | ||
82 | if (dev->realized) { | 82 | if (dev->realized) { |
83 | qdev_prop_set_after_realize(dev, name, errp); | 83 | qdev_prop_set_after_realize(dev, name, errp); |
84 | @@ -XXX,XX +XXX,XX @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, | 84 | @@ -XXX,XX +XXX,XX @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, |
85 | if (!visit_type_size(v, name, &value, errp)) { | 85 | if (!visit_type_size(v, name, &value, errp)) { |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | - /* value of 0 means "unset" */ | 88 | - /* value of 0 means "unset" */ |
89 | - if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { | 89 | - if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { |
90 | - error_setg(errp, | 90 | - error_setg(errp, |
91 | - "Property %s.%s doesn't take value %" PRIu64 | 91 | - "Property %s.%s doesn't take value %" PRIu64 |
92 | - " (minimum: " MIN_BLOCK_SIZE_STR | 92 | - " (minimum: " MIN_BLOCK_SIZE_STR |
93 | - ", maximum: " MAX_BLOCK_SIZE_STR ")", | 93 | - ", maximum: " MAX_BLOCK_SIZE_STR ")", |
94 | - dev->id ? : "", name, value); | 94 | - dev->id ? : "", name, value); |
95 | + check_block_size(dev->id ? : "", name, value, &local_err); | 95 | + check_block_size(dev->id ? : "", name, value, &local_err); |
96 | + if (local_err) { | 96 | + if (local_err) { |
97 | + error_propagate(errp, local_err); | 97 | + error_propagate(errp, local_err); |
98 | return; | 98 | return; |
99 | } | 99 | } |
100 | - | 100 | - |
101 | - /* We rely on power-of-2 blocksizes for bitmasks */ | 101 | - /* We rely on power-of-2 blocksizes for bitmasks */ |
102 | - if ((value & (value - 1)) != 0) { | 102 | - if ((value & (value - 1)) != 0) { |
103 | - error_setg(errp, | 103 | - error_setg(errp, |
104 | - "Property %s.%s doesn't take value '%" PRId64 "', " | 104 | - "Property %s.%s doesn't take value '%" PRId64 "', " |
105 | - "it's not a power of 2", dev->id ?: "", name, (int64_t)value); | 105 | - "it's not a power of 2", dev->id ?: "", name, (int64_t)value); |
106 | - return; | 106 | - return; |
107 | - } | 107 | - } |
108 | - | 108 | - |
109 | *ptr = value; | 109 | *ptr = value; |
110 | } | 110 | } |
111 | 111 | ||
112 | diff --git a/util/block-helpers.c b/util/block-helpers.c | 112 | diff --git a/util/block-helpers.c b/util/block-helpers.c |
113 | new file mode 100644 | 113 | new file mode 100644 |
114 | index XXXXXXX..XXXXXXX | 114 | index XXXXXXX..XXXXXXX |
115 | --- /dev/null | 115 | --- /dev/null |
116 | +++ b/util/block-helpers.c | 116 | +++ b/util/block-helpers.c |
117 | @@ -XXX,XX +XXX,XX @@ | 117 | @@ -XXX,XX +XXX,XX @@ |
118 | +/* | 118 | +/* |
119 | + * Block utility functions | 119 | + * Block utility functions |
120 | + * | 120 | + * |
121 | + * Copyright IBM, Corp. 2011 | 121 | + * Copyright IBM, Corp. 2011 |
122 | + * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com> | 122 | + * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com> |
123 | + * | 123 | + * |
124 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 124 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
125 | + * See the COPYING file in the top-level directory. | 125 | + * See the COPYING file in the top-level directory. |
126 | + */ | 126 | + */ |
127 | + | 127 | + |
128 | +#include "qemu/osdep.h" | 128 | +#include "qemu/osdep.h" |
129 | +#include "qapi/error.h" | 129 | +#include "qapi/error.h" |
130 | +#include "qapi/qmp/qerror.h" | 130 | +#include "qapi/qmp/qerror.h" |
131 | +#include "block-helpers.h" | 131 | +#include "block-helpers.h" |
132 | + | 132 | + |
133 | +/** | 133 | +/** |
134 | + * check_block_size: | 134 | + * check_block_size: |
135 | + * @id: The unique ID of the object | 135 | + * @id: The unique ID of the object |
136 | + * @name: The name of the property being validated | 136 | + * @name: The name of the property being validated |
137 | + * @value: The block size in bytes | 137 | + * @value: The block size in bytes |
138 | + * @errp: A pointer to an area to store an error | 138 | + * @errp: A pointer to an area to store an error |
139 | + * | 139 | + * |
140 | + * This function checks that the block size meets the following conditions: | 140 | + * This function checks that the block size meets the following conditions: |
141 | + * 1. At least MIN_BLOCK_SIZE | 141 | + * 1. At least MIN_BLOCK_SIZE |
142 | + * 2. No larger than MAX_BLOCK_SIZE | 142 | + * 2. No larger than MAX_BLOCK_SIZE |
143 | + * 3. A power of 2 | 143 | + * 3. A power of 2 |
144 | + */ | 144 | + */ |
145 | +void check_block_size(const char *id, const char *name, int64_t value, | 145 | +void check_block_size(const char *id, const char *name, int64_t value, |
146 | + Error **errp) | 146 | + Error **errp) |
147 | +{ | 147 | +{ |
148 | + /* value of 0 means "unset" */ | 148 | + /* value of 0 means "unset" */ |
149 | + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { | 149 | + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { |
150 | + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, | 150 | + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, |
151 | + id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE); | 151 | + id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE); |
152 | + return; | 152 | + return; |
153 | + } | 153 | + } |
154 | + | 154 | + |
155 | + /* We rely on power-of-2 blocksizes for bitmasks */ | 155 | + /* We rely on power-of-2 blocksizes for bitmasks */ |
156 | + if ((value & (value - 1)) != 0) { | 156 | + if ((value & (value - 1)) != 0) { |
157 | + error_setg(errp, | 157 | + error_setg(errp, |
158 | + "Property %s.%s doesn't take value '%" PRId64 | 158 | + "Property %s.%s doesn't take value '%" PRId64 |
159 | + "', it's not a power of 2", | 159 | + "', it's not a power of 2", |
160 | + id, name, value); | 160 | + id, name, value); |
161 | + return; | 161 | + return; |
162 | + } | 162 | + } |
163 | +} | 163 | +} |
164 | diff --git a/util/meson.build b/util/meson.build | 164 | diff --git a/util/meson.build b/util/meson.build |
165 | index XXXXXXX..XXXXXXX 100644 | 165 | index XXXXXXX..XXXXXXX 100644 |
166 | --- a/util/meson.build | 166 | --- a/util/meson.build |
167 | +++ b/util/meson.build | 167 | +++ b/util/meson.build |
168 | @@ -XXX,XX +XXX,XX @@ if have_block | 168 | @@ -XXX,XX +XXX,XX @@ if have_block |
169 | util_ss.add(files('nvdimm-utils.c')) | 169 | util_ss.add(files('nvdimm-utils.c')) |
170 | util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) | 170 | util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) |
171 | util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) | 171 | util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) |
172 | + util_ss.add(files('block-helpers.c')) | 172 | + util_ss.add(files('block-helpers.c')) |
173 | util_ss.add(files('qemu-coroutine-sleep.c')) | 173 | util_ss.add(files('qemu-coroutine-sleep.c')) |
174 | util_ss.add(files('qemu-co-shared-resource.c')) | 174 | util_ss.add(files('qemu-co-shared-resource.c')) |
175 | util_ss.add(files('thread-pool.c', 'qemu-timer.c')) | 175 | util_ss.add(files('thread-pool.c', 'qemu-timer.c')) |
176 | -- | 176 | -- |
177 | 2.26.2 | 177 | 2.26.2 |
178 | 178 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
14 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 14 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
15 | Message-id: 20200918080912.321299-6-coiby.xu@gmail.com | 15 | Message-id: 20200918080912.321299-6-coiby.xu@gmail.com |
16 | [Shorten "vhost_user_blk_server" string to "vhost_user_blk" to avoid the | 16 | [Shorten "vhost_user_blk_server" string to "vhost_user_blk" to avoid the |
17 | following compiler warning: | 17 | following compiler warning: |
18 | ../block/export/vhost-user-blk-server.c:178:50: error: ‘%s’ directive output truncated writing 21 bytes into a region of size 20 [-Werror=format-truncation=] | 18 | ../block/export/vhost-user-blk-server.c:178:50: error: ‘%s’ directive output truncated writing 21 bytes into a region of size 20 [-Werror=format-truncation=] |
19 | and fix "Invalid size %ld ..." ssize_t format string arguments for | ||
20 | 32-bit hosts. | ||
19 | --Stefan] | 21 | --Stefan] |
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 22 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
21 | --- | 23 | --- |
22 | block/export/vhost-user-blk-server.h | 36 ++ | 24 | block/export/vhost-user-blk-server.h | 36 ++ |
23 | block/export/vhost-user-blk-server.c | 661 +++++++++++++++++++++++++++ | 25 | block/export/vhost-user-blk-server.c | 661 +++++++++++++++++++++++++++ |
... | ... | ||
136 | + uint32_t iovcnt, uint32_t type) | 138 | + uint32_t iovcnt, uint32_t type) |
137 | +{ | 139 | +{ |
138 | + struct virtio_blk_discard_write_zeroes desc; | 140 | + struct virtio_blk_discard_write_zeroes desc; |
139 | + ssize_t size = iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); | 141 | + ssize_t size = iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); |
140 | + if (unlikely(size != sizeof(desc))) { | 142 | + if (unlikely(size != sizeof(desc))) { |
141 | + error_report("Invalid size %ld, expect %ld", size, sizeof(desc)); | 143 | + error_report("Invalid size %zd, expect %zu", size, sizeof(desc)); |
142 | + return -EINVAL; | 144 | + return -EINVAL; |
143 | + } | 145 | + } |
144 | + | 146 | + |
145 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | 147 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); |
146 | + uint64_t range[2] = { le64_to_cpu(desc.sector) << 9, | 148 | + uint64_t range[2] = { le64_to_cpu(desc.sector) << 9, |
... | ... | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
2 | 1 | ||
3 | This test case has the same tests as tests/virtio-blk-test.c except for | ||
4 | tests have block_resize. Since vhost-user server can only server one | ||
5 | client one time, two instances of vhost-user-blk-server are started by | ||
6 | qemu-storage-daemon for the hotplug test. | ||
7 | |||
8 | In order to not block scripts/tap-driver.pl, vhost-user-blk-server will | ||
9 | send "quit" command to qemu-storage-daemon's QMP monitor. So a function | ||
10 | is added to libqtest.c to establish socket connection with socket | ||
11 | server. | ||
12 | |||
13 | Suggested-by: Thomas Huth <thuth@redhat.com> | ||
14 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
17 | Message-id: 20200918080912.321299-7-coiby.xu@gmail.com | ||
18 | [Update meson.build to only test when CONFIG_TOOLS has built | ||
19 | qemu-storage-daemon. This prevents CI failures with --disable-tools. | ||
20 | --Stefan] | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | --- | ||
23 | tests/qtest/libqos/libqtest.h | 17 + | ||
24 | tests/qtest/libqos/vhost-user-blk.h | 48 ++ | ||
25 | tests/qtest/libqos/vhost-user-blk.c | 129 +++++ | ||
26 | tests/qtest/libqtest.c | 36 +- | ||
27 | tests/qtest/vhost-user-blk-test.c | 751 ++++++++++++++++++++++++++++ | ||
28 | tests/qtest/libqos/meson.build | 1 + | ||
29 | tests/qtest/meson.build | 4 +- | ||
30 | 7 files changed, 983 insertions(+), 3 deletions(-) | ||
31 | create mode 100644 tests/qtest/libqos/vhost-user-blk.h | ||
32 | create mode 100644 tests/qtest/libqos/vhost-user-blk.c | ||
33 | create mode 100644 tests/qtest/vhost-user-blk-test.c | ||
34 | |||
35 | diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/tests/qtest/libqos/libqtest.h | ||
38 | +++ b/tests/qtest/libqos/libqtest.h | ||
39 | @@ -XXX,XX +XXX,XX @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...) | ||
40 | void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) | ||
41 | GCC_FMT_ATTR(2, 3); | ||
42 | |||
43 | +/** | ||
44 | + * qtest_socket_client: | ||
45 | + * @server_socket_path: the socket server's path | ||
46 | + * | ||
47 | + * Connect to a socket server. | ||
48 | + */ | ||
49 | +int qtest_socket_client(char *server_socket_path); | ||
50 | + | ||
51 | +/** | ||
52 | + * qtest_create_state_with_qmp_fd: | ||
53 | + * @fd: socket fd | ||
54 | + * | ||
55 | + * Wrap socket fd in QTestState to make use of qtest_qmp* | ||
56 | + * functions | ||
57 | + */ | ||
58 | +QTestState *qtest_create_state_with_qmp_fd(int fd); | ||
59 | + | ||
60 | /** | ||
61 | * qtest_vqmp_fds: | ||
62 | * @s: #QTestState instance to operate on. | ||
63 | diff --git a/tests/qtest/libqos/vhost-user-blk.h b/tests/qtest/libqos/vhost-user-blk.h | ||
64 | new file mode 100644 | ||
65 | index XXXXXXX..XXXXXXX | ||
66 | --- /dev/null | ||
67 | +++ b/tests/qtest/libqos/vhost-user-blk.h | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | +/* | ||
70 | + * libqos driver framework | ||
71 | + * | ||
72 | + * Based on tests/qtest/libqos/virtio-blk.c | ||
73 | + * | ||
74 | + * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com> | ||
75 | + * | ||
76 | + * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com> | ||
77 | + * | ||
78 | + * This library is free software; you can redistribute it and/or | ||
79 | + * modify it under the terms of the GNU Lesser General Public | ||
80 | + * License version 2 as published by the Free Software Foundation. | ||
81 | + * | ||
82 | + * This library is distributed in the hope that it will be useful, | ||
83 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
84 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
85 | + * Lesser General Public License for more details. | ||
86 | + * | ||
87 | + * You should have received a copy of the GNU Lesser General Public | ||
88 | + * License along with this library; if not, see <http://www.gnu.org/licenses/> | ||
89 | + */ | ||
90 | + | ||
91 | +#ifndef TESTS_LIBQOS_VHOST_USER_BLK_H | ||
92 | +#define TESTS_LIBQOS_VHOST_USER_BLK_H | ||
93 | + | ||
94 | +#include "qgraph.h" | ||
95 | +#include "virtio.h" | ||
96 | +#include "virtio-pci.h" | ||
97 | + | ||
98 | +typedef struct QVhostUserBlk QVhostUserBlk; | ||
99 | +typedef struct QVhostUserBlkPCI QVhostUserBlkPCI; | ||
100 | +typedef struct QVhostUserBlkDevice QVhostUserBlkDevice; | ||
101 | + | ||
102 | +struct QVhostUserBlk { | ||
103 | + QVirtioDevice *vdev; | ||
104 | +}; | ||
105 | + | ||
106 | +struct QVhostUserBlkPCI { | ||
107 | + QVirtioPCIDevice pci_vdev; | ||
108 | + QVhostUserBlk blk; | ||
109 | +}; | ||
110 | + | ||
111 | +struct QVhostUserBlkDevice { | ||
112 | + QOSGraphObject obj; | ||
113 | + QVhostUserBlk blk; | ||
114 | +}; | ||
115 | + | ||
116 | +#endif | ||
117 | diff --git a/tests/qtest/libqos/vhost-user-blk.c b/tests/qtest/libqos/vhost-user-blk.c | ||
118 | new file mode 100644 | ||
119 | index XXXXXXX..XXXXXXX | ||
120 | --- /dev/null | ||
121 | +++ b/tests/qtest/libqos/vhost-user-blk.c | ||
122 | @@ -XXX,XX +XXX,XX @@ | ||
123 | +/* | ||
124 | + * libqos driver framework | ||
125 | + * | ||
126 | + * Based on tests/qtest/libqos/virtio-blk.c | ||
127 | + * | ||
128 | + * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com> | ||
129 | + * | ||
130 | + * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com> | ||
131 | + * | ||
132 | + * This library is free software; you can redistribute it and/or | ||
133 | + * modify it under the terms of the GNU Lesser General Public | ||
134 | + * License version 2.1 as published by the Free Software Foundation. | ||
135 | + * | ||
136 | + * This library is distributed in the hope that it will be useful, | ||
137 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
138 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
139 | + * Lesser General Public License for more details. | ||
140 | + * | ||
141 | + * You should have received a copy of the GNU Lesser General Public | ||
142 | + * License along with this library; if not, see <http://www.gnu.org/licenses/> | ||
143 | + */ | ||
144 | + | ||
145 | +#include "qemu/osdep.h" | ||
146 | +#include "libqtest.h" | ||
147 | +#include "qemu/module.h" | ||
148 | +#include "standard-headers/linux/virtio_blk.h" | ||
149 | +#include "vhost-user-blk.h" | ||
150 | + | ||
151 | +#define PCI_SLOT 0x04 | ||
152 | +#define PCI_FN 0x00 | ||
153 | + | ||
154 | +/* virtio-blk-device */ | ||
155 | +static void *qvhost_user_blk_get_driver(QVhostUserBlk *v_blk, | ||
156 | + const char *interface) | ||
157 | +{ | ||
158 | + if (!g_strcmp0(interface, "vhost-user-blk")) { | ||
159 | + return v_blk; | ||
160 | + } | ||
161 | + if (!g_strcmp0(interface, "virtio")) { | ||
162 | + return v_blk->vdev; | ||
163 | + } | ||
164 | + | ||
165 | + fprintf(stderr, "%s not present in vhost-user-blk-device\n", interface); | ||
166 | + g_assert_not_reached(); | ||
167 | +} | ||
168 | + | ||
169 | +static void *qvhost_user_blk_device_get_driver(void *object, | ||
170 | + const char *interface) | ||
171 | +{ | ||
172 | + QVhostUserBlkDevice *v_blk = object; | ||
173 | + return qvhost_user_blk_get_driver(&v_blk->blk, interface); | ||
174 | +} | ||
175 | + | ||
176 | +static void *vhost_user_blk_device_create(void *virtio_dev, | ||
177 | + QGuestAllocator *t_alloc, | ||
178 | + void *addr) | ||
179 | +{ | ||
180 | + QVhostUserBlkDevice *vhost_user_blk = g_new0(QVhostUserBlkDevice, 1); | ||
181 | + QVhostUserBlk *interface = &vhost_user_blk->blk; | ||
182 | + | ||
183 | + interface->vdev = virtio_dev; | ||
184 | + | ||
185 | + vhost_user_blk->obj.get_driver = qvhost_user_blk_device_get_driver; | ||
186 | + | ||
187 | + return &vhost_user_blk->obj; | ||
188 | +} | ||
189 | + | ||
190 | +/* virtio-blk-pci */ | ||
191 | +static void *qvhost_user_blk_pci_get_driver(void *object, const char *interface) | ||
192 | +{ | ||
193 | + QVhostUserBlkPCI *v_blk = object; | ||
194 | + if (!g_strcmp0(interface, "pci-device")) { | ||
195 | + return v_blk->pci_vdev.pdev; | ||
196 | + } | ||
197 | + return qvhost_user_blk_get_driver(&v_blk->blk, interface); | ||
198 | +} | ||
199 | + | ||
200 | +static void *vhost_user_blk_pci_create(void *pci_bus, QGuestAllocator *t_alloc, | ||
201 | + void *addr) | ||
202 | +{ | ||
203 | + QVhostUserBlkPCI *vhost_user_blk = g_new0(QVhostUserBlkPCI, 1); | ||
204 | + QVhostUserBlk *interface = &vhost_user_blk->blk; | ||
205 | + QOSGraphObject *obj = &vhost_user_blk->pci_vdev.obj; | ||
206 | + | ||
207 | + virtio_pci_init(&vhost_user_blk->pci_vdev, pci_bus, addr); | ||
208 | + interface->vdev = &vhost_user_blk->pci_vdev.vdev; | ||
209 | + | ||
210 | + g_assert_cmphex(interface->vdev->device_type, ==, VIRTIO_ID_BLOCK); | ||
211 | + | ||
212 | + obj->get_driver = qvhost_user_blk_pci_get_driver; | ||
213 | + | ||
214 | + return obj; | ||
215 | +} | ||
216 | + | ||
217 | +static void vhost_user_blk_register_nodes(void) | ||
218 | +{ | ||
219 | + /* | ||
220 | + * FIXME: every test using these two nodes needs to setup a | ||
221 | + * -drive,id=drive0 otherwise QEMU is not going to start. | ||
222 | + * Therefore, we do not include "produces" edge for virtio | ||
223 | + * and pci-device yet. | ||
224 | + */ | ||
225 | + | ||
226 | + char *arg = g_strdup_printf("id=drv0,chardev=char1,addr=%x.%x", | ||
227 | + PCI_SLOT, PCI_FN); | ||
228 | + | ||
229 | + QPCIAddress addr = { | ||
230 | + .devfn = QPCI_DEVFN(PCI_SLOT, PCI_FN), | ||
231 | + }; | ||
232 | + | ||
233 | + QOSGraphEdgeOptions opts = { }; | ||
234 | + | ||
235 | + /* virtio-blk-device */ | ||
236 | + /** opts.extra_device_opts = "drive=drive0"; */ | ||
237 | + qos_node_create_driver("vhost-user-blk-device", vhost_user_blk_device_create); | ||
238 | + qos_node_consumes("vhost-user-blk-device", "virtio-bus", &opts); | ||
239 | + qos_node_produces("vhost-user-blk-device", "vhost-user-blk"); | ||
240 | + | ||
241 | + /* virtio-blk-pci */ | ||
242 | + opts.extra_device_opts = arg; | ||
243 | + add_qpci_address(&opts, &addr); | ||
244 | + qos_node_create_driver("vhost-user-blk-pci", vhost_user_blk_pci_create); | ||
245 | + qos_node_consumes("vhost-user-blk-pci", "pci-bus", &opts); | ||
246 | + qos_node_produces("vhost-user-blk-pci", "vhost-user-blk"); | ||
247 | + | ||
248 | + g_free(arg); | ||
249 | +} | ||
250 | + | ||
251 | +libqos_init(vhost_user_blk_register_nodes); | ||
252 | diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c | ||
253 | index XXXXXXX..XXXXXXX 100644 | ||
254 | --- a/tests/qtest/libqtest.c | ||
255 | +++ b/tests/qtest/libqtest.c | ||
256 | @@ -XXX,XX +XXX,XX @@ | ||
257 | * Copyright IBM, Corp. 2012 | ||
258 | * Copyright Red Hat, Inc. 2012 | ||
259 | * Copyright SUSE LINUX Products GmbH 2013 | ||
260 | + * Copyright Copyright (c) Coiby Xu | ||
261 | * | ||
262 | * Authors: | ||
263 | * Anthony Liguori <aliguori@us.ibm.com> | ||
264 | * Paolo Bonzini <pbonzini@redhat.com> | ||
265 | * Andreas Färber <afaerber@suse.de> | ||
266 | + * Coiby Xu <coiby.xu@gmail.com> | ||
267 | * | ||
268 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
269 | * See the COPYING file in the top-level directory. | ||
270 | @@ -XXX,XX +XXX,XX @@ typedef struct QTestClientTransportOps { | ||
271 | QTestRecvFn recv_line; /* for receiving qtest command responses */ | ||
272 | } QTestTransportOps; | ||
273 | |||
274 | -struct QTestState | ||
275 | -{ | ||
276 | +struct QTestState { | ||
277 | int fd; | ||
278 | int qmp_fd; | ||
279 | pid_t qemu_pid; /* our child QEMU process */ | ||
280 | @@ -XXX,XX +XXX,XX @@ QDict *qtest_qmp_receive(QTestState *s) | ||
281 | return qmp_fd_receive(s->qmp_fd); | ||
282 | } | ||
283 | |||
284 | +QTestState *qtest_create_state_with_qmp_fd(int fd) | ||
285 | +{ | ||
286 | + QTestState *qmp_test_state = g_new0(QTestState, 1); | ||
287 | + qmp_test_state->qmp_fd = fd; | ||
288 | + return qmp_test_state; | ||
289 | +} | ||
290 | + | ||
291 | +int qtest_socket_client(char *server_socket_path) | ||
292 | +{ | ||
293 | + struct sockaddr_un serv_addr; | ||
294 | + int sock; | ||
295 | + int ret; | ||
296 | + int retries = 0; | ||
297 | + sock = socket(PF_UNIX, SOCK_STREAM, 0); | ||
298 | + g_assert_cmpint(sock, !=, -1); | ||
299 | + serv_addr.sun_family = AF_UNIX; | ||
300 | + snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s", | ||
301 | + server_socket_path); | ||
302 | + | ||
303 | + for (retries = 0; retries < 3; retries++) { | ||
304 | + ret = connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); | ||
305 | + if (ret == 0) { | ||
306 | + break; | ||
307 | + } | ||
308 | + g_usleep(G_USEC_PER_SEC); | ||
309 | + } | ||
310 | + | ||
311 | + g_assert_cmpint(ret, ==, 0); | ||
312 | + return sock; | ||
313 | +} | ||
314 | + | ||
315 | /** | ||
316 | * Allow users to send a message without waiting for the reply, | ||
317 | * in the case that they choose to discard all replies up until | ||
318 | diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c | ||
319 | new file mode 100644 | ||
320 | index XXXXXXX..XXXXXXX | ||
321 | --- /dev/null | ||
322 | +++ b/tests/qtest/vhost-user-blk-test.c | ||
323 | @@ -XXX,XX +XXX,XX @@ | ||
324 | +/* | ||
325 | + * QTest testcase for Vhost-user Block Device | ||
326 | + * | ||
327 | + * Based on tests/qtest//virtio-blk-test.c | ||
328 | + | ||
329 | + * Copyright (c) 2014 SUSE LINUX Products GmbH | ||
330 | + * Copyright (c) 2014 Marc Marí | ||
331 | + * Copyright (c) 2020 Coiby Xu | ||
332 | + * | ||
333 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
334 | + * See the COPYING file in the top-level directory. | ||
335 | + */ | ||
336 | + | ||
337 | +#include "qemu/osdep.h" | ||
338 | +#include "libqtest-single.h" | ||
339 | +#include "qemu/bswap.h" | ||
340 | +#include "qemu/module.h" | ||
341 | +#include "standard-headers/linux/virtio_blk.h" | ||
342 | +#include "standard-headers/linux/virtio_pci.h" | ||
343 | +#include "libqos/qgraph.h" | ||
344 | +#include "libqos/vhost-user-blk.h" | ||
345 | +#include "libqos/libqos-pc.h" | ||
346 | + | ||
347 | +#define TEST_IMAGE_SIZE (64 * 1024 * 1024) | ||
348 | +#define QVIRTIO_BLK_TIMEOUT_US (30 * 1000 * 1000) | ||
349 | +#define PCI_SLOT_HP 0x06 | ||
350 | + | ||
351 | +typedef struct QVirtioBlkReq { | ||
352 | + uint32_t type; | ||
353 | + uint32_t ioprio; | ||
354 | + uint64_t sector; | ||
355 | + char *data; | ||
356 | + uint8_t status; | ||
357 | +} QVirtioBlkReq; | ||
358 | + | ||
359 | +#ifdef HOST_WORDS_BIGENDIAN | ||
360 | +static const bool host_is_big_endian = true; | ||
361 | +#else | ||
362 | +static const bool host_is_big_endian; /* false */ | ||
363 | +#endif | ||
364 | + | ||
365 | +static inline void virtio_blk_fix_request(QVirtioDevice *d, QVirtioBlkReq *req) | ||
366 | +{ | ||
367 | + if (qvirtio_is_big_endian(d) != host_is_big_endian) { | ||
368 | + req->type = bswap32(req->type); | ||
369 | + req->ioprio = bswap32(req->ioprio); | ||
370 | + req->sector = bswap64(req->sector); | ||
371 | + } | ||
372 | +} | ||
373 | + | ||
374 | +static inline void virtio_blk_fix_dwz_hdr(QVirtioDevice *d, | ||
375 | + struct virtio_blk_discard_write_zeroes *dwz_hdr) | ||
376 | +{ | ||
377 | + if (qvirtio_is_big_endian(d) != host_is_big_endian) { | ||
378 | + dwz_hdr->sector = bswap64(dwz_hdr->sector); | ||
379 | + dwz_hdr->num_sectors = bswap32(dwz_hdr->num_sectors); | ||
380 | + dwz_hdr->flags = bswap32(dwz_hdr->flags); | ||
381 | + } | ||
382 | +} | ||
383 | + | ||
384 | +static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d, | ||
385 | + QVirtioBlkReq *req, uint64_t data_size) | ||
386 | +{ | ||
387 | + uint64_t addr; | ||
388 | + uint8_t status = 0xFF; | ||
389 | + QTestState *qts = global_qtest; | ||
390 | + | ||
391 | + switch (req->type) { | ||
392 | + case VIRTIO_BLK_T_IN: | ||
393 | + case VIRTIO_BLK_T_OUT: | ||
394 | + g_assert_cmpuint(data_size % 512, ==, 0); | ||
395 | + break; | ||
396 | + case VIRTIO_BLK_T_DISCARD: | ||
397 | + case VIRTIO_BLK_T_WRITE_ZEROES: | ||
398 | + g_assert_cmpuint(data_size % | ||
399 | + sizeof(struct virtio_blk_discard_write_zeroes), ==, 0); | ||
400 | + break; | ||
401 | + default: | ||
402 | + g_assert_cmpuint(data_size, ==, 0); | ||
403 | + } | ||
404 | + | ||
405 | + addr = guest_alloc(alloc, sizeof(*req) + data_size); | ||
406 | + | ||
407 | + virtio_blk_fix_request(d, req); | ||
408 | + | ||
409 | + qtest_memwrite(qts, addr, req, 16); | ||
410 | + qtest_memwrite(qts, addr + 16, req->data, data_size); | ||
411 | + qtest_memwrite(qts, addr + 16 + data_size, &status, sizeof(status)); | ||
412 | + | ||
413 | + return addr; | ||
414 | +} | ||
415 | + | ||
416 | +/* Returns the request virtqueue so the caller can perform further tests */ | ||
417 | +static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc) | ||
418 | +{ | ||
419 | + QVirtioBlkReq req; | ||
420 | + uint64_t req_addr; | ||
421 | + uint64_t capacity; | ||
422 | + uint64_t features; | ||
423 | + uint32_t free_head; | ||
424 | + uint8_t status; | ||
425 | + char *data; | ||
426 | + QTestState *qts = global_qtest; | ||
427 | + QVirtQueue *vq; | ||
428 | + | ||
429 | + features = qvirtio_get_features(dev); | ||
430 | + features = features & ~(QVIRTIO_F_BAD_FEATURE | | ||
431 | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | | ||
432 | + (1u << VIRTIO_RING_F_EVENT_IDX) | | ||
433 | + (1u << VIRTIO_BLK_F_SCSI)); | ||
434 | + qvirtio_set_features(dev, features); | ||
435 | + | ||
436 | + capacity = qvirtio_config_readq(dev, 0); | ||
437 | + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); | ||
438 | + | ||
439 | + vq = qvirtqueue_setup(dev, alloc, 0); | ||
440 | + | ||
441 | + qvirtio_set_driver_ok(dev); | ||
442 | + | ||
443 | + /* Write and read with 3 descriptor layout */ | ||
444 | + /* Write request */ | ||
445 | + req.type = VIRTIO_BLK_T_OUT; | ||
446 | + req.ioprio = 1; | ||
447 | + req.sector = 0; | ||
448 | + req.data = g_malloc0(512); | ||
449 | + strcpy(req.data, "TEST"); | ||
450 | + | ||
451 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | ||
452 | + | ||
453 | + g_free(req.data); | ||
454 | + | ||
455 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
456 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); | ||
457 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
458 | + | ||
459 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
460 | + | ||
461 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
462 | + QVIRTIO_BLK_TIMEOUT_US); | ||
463 | + status = readb(req_addr + 528); | ||
464 | + g_assert_cmpint(status, ==, 0); | ||
465 | + | ||
466 | + guest_free(alloc, req_addr); | ||
467 | + | ||
468 | + /* Read request */ | ||
469 | + req.type = VIRTIO_BLK_T_IN; | ||
470 | + req.ioprio = 1; | ||
471 | + req.sector = 0; | ||
472 | + req.data = g_malloc0(512); | ||
473 | + | ||
474 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | ||
475 | + | ||
476 | + g_free(req.data); | ||
477 | + | ||
478 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
479 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); | ||
480 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
481 | + | ||
482 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
483 | + | ||
484 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
485 | + QVIRTIO_BLK_TIMEOUT_US); | ||
486 | + status = readb(req_addr + 528); | ||
487 | + g_assert_cmpint(status, ==, 0); | ||
488 | + | ||
489 | + data = g_malloc0(512); | ||
490 | + qtest_memread(qts, req_addr + 16, data, 512); | ||
491 | + g_assert_cmpstr(data, ==, "TEST"); | ||
492 | + g_free(data); | ||
493 | + | ||
494 | + guest_free(alloc, req_addr); | ||
495 | + | ||
496 | + if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) { | ||
497 | + struct virtio_blk_discard_write_zeroes dwz_hdr; | ||
498 | + void *expected; | ||
499 | + | ||
500 | + /* | ||
501 | + * WRITE_ZEROES request on the same sector of previous test where | ||
502 | + * we wrote "TEST". | ||
503 | + */ | ||
504 | + req.type = VIRTIO_BLK_T_WRITE_ZEROES; | ||
505 | + req.data = (char *) &dwz_hdr; | ||
506 | + dwz_hdr.sector = 0; | ||
507 | + dwz_hdr.num_sectors = 1; | ||
508 | + dwz_hdr.flags = 0; | ||
509 | + | ||
510 | + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); | ||
511 | + | ||
512 | + req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); | ||
513 | + | ||
514 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
515 | + qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true); | ||
516 | + qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, | ||
517 | + false); | ||
518 | + | ||
519 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
520 | + | ||
521 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
522 | + QVIRTIO_BLK_TIMEOUT_US); | ||
523 | + status = readb(req_addr + 16 + sizeof(dwz_hdr)); | ||
524 | + g_assert_cmpint(status, ==, 0); | ||
525 | + | ||
526 | + guest_free(alloc, req_addr); | ||
527 | + | ||
528 | + /* Read request to check if the sector contains all zeroes */ | ||
529 | + req.type = VIRTIO_BLK_T_IN; | ||
530 | + req.ioprio = 1; | ||
531 | + req.sector = 0; | ||
532 | + req.data = g_malloc0(512); | ||
533 | + | ||
534 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | ||
535 | + | ||
536 | + g_free(req.data); | ||
537 | + | ||
538 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
539 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); | ||
540 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
541 | + | ||
542 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
543 | + | ||
544 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
545 | + QVIRTIO_BLK_TIMEOUT_US); | ||
546 | + status = readb(req_addr + 528); | ||
547 | + g_assert_cmpint(status, ==, 0); | ||
548 | + | ||
549 | + data = g_malloc(512); | ||
550 | + expected = g_malloc0(512); | ||
551 | + qtest_memread(qts, req_addr + 16, data, 512); | ||
552 | + g_assert_cmpmem(data, 512, expected, 512); | ||
553 | + g_free(expected); | ||
554 | + g_free(data); | ||
555 | + | ||
556 | + guest_free(alloc, req_addr); | ||
557 | + } | ||
558 | + | ||
559 | + if (features & (1u << VIRTIO_BLK_F_DISCARD)) { | ||
560 | + struct virtio_blk_discard_write_zeroes dwz_hdr; | ||
561 | + | ||
562 | + req.type = VIRTIO_BLK_T_DISCARD; | ||
563 | + req.data = (char *) &dwz_hdr; | ||
564 | + dwz_hdr.sector = 0; | ||
565 | + dwz_hdr.num_sectors = 1; | ||
566 | + dwz_hdr.flags = 0; | ||
567 | + | ||
568 | + virtio_blk_fix_dwz_hdr(dev, &dwz_hdr); | ||
569 | + | ||
570 | + req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); | ||
571 | + | ||
572 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
573 | + qvirtqueue_add(qts, vq, req_addr + 16, sizeof(dwz_hdr), false, true); | ||
574 | + qvirtqueue_add(qts, vq, req_addr + 16 + sizeof(dwz_hdr), | ||
575 | + 1, true, false); | ||
576 | + | ||
577 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
578 | + | ||
579 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
580 | + QVIRTIO_BLK_TIMEOUT_US); | ||
581 | + status = readb(req_addr + 16 + sizeof(dwz_hdr)); | ||
582 | + g_assert_cmpint(status, ==, 0); | ||
583 | + | ||
584 | + guest_free(alloc, req_addr); | ||
585 | + } | ||
586 | + | ||
587 | + if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { | ||
588 | + /* Write and read with 2 descriptor layout */ | ||
589 | + /* Write request */ | ||
590 | + req.type = VIRTIO_BLK_T_OUT; | ||
591 | + req.ioprio = 1; | ||
592 | + req.sector = 1; | ||
593 | + req.data = g_malloc0(512); | ||
594 | + strcpy(req.data, "TEST"); | ||
595 | + | ||
596 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | ||
597 | + | ||
598 | + g_free(req.data); | ||
599 | + | ||
600 | + free_head = qvirtqueue_add(qts, vq, req_addr, 528, false, true); | ||
601 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
602 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
603 | + | ||
604 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
605 | + QVIRTIO_BLK_TIMEOUT_US); | ||
606 | + status = readb(req_addr + 528); | ||
607 | + g_assert_cmpint(status, ==, 0); | ||
608 | + | ||
609 | + guest_free(alloc, req_addr); | ||
610 | + | ||
611 | + /* Read request */ | ||
612 | + req.type = VIRTIO_BLK_T_IN; | ||
613 | + req.ioprio = 1; | ||
614 | + req.sector = 1; | ||
615 | + req.data = g_malloc0(512); | ||
616 | + | ||
617 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | ||
618 | + | ||
619 | + g_free(req.data); | ||
620 | + | ||
621 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
622 | + qvirtqueue_add(qts, vq, req_addr + 16, 513, true, false); | ||
623 | + | ||
624 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
625 | + | ||
626 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
627 | + QVIRTIO_BLK_TIMEOUT_US); | ||
628 | + status = readb(req_addr + 528); | ||
629 | + g_assert_cmpint(status, ==, 0); | ||
630 | + | ||
631 | + data = g_malloc0(512); | ||
632 | + qtest_memread(qts, req_addr + 16, data, 512); | ||
633 | + g_assert_cmpstr(data, ==, "TEST"); | ||
634 | + g_free(data); | ||
635 | + | ||
636 | + guest_free(alloc, req_addr); | ||
637 | + } | ||
638 | + | ||
639 | + return vq; | ||
640 | +} | ||
641 | + | ||
642 | +static void basic(void *obj, void *data, QGuestAllocator *t_alloc) | ||
643 | +{ | ||
644 | + QVhostUserBlk *blk_if = obj; | ||
645 | + QVirtQueue *vq; | ||
646 | + | ||
647 | + vq = test_basic(blk_if->vdev, t_alloc); | ||
648 | + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); | ||
649 | + | ||
650 | +} | ||
651 | + | ||
652 | +static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc) | ||
653 | +{ | ||
654 | + QVirtQueue *vq; | ||
655 | + QVhostUserBlk *blk_if = obj; | ||
656 | + QVirtioDevice *dev = blk_if->vdev; | ||
657 | + QVirtioBlkReq req; | ||
658 | + QVRingIndirectDesc *indirect; | ||
659 | + uint64_t req_addr; | ||
660 | + uint64_t capacity; | ||
661 | + uint64_t features; | ||
662 | + uint32_t free_head; | ||
663 | + uint8_t status; | ||
664 | + char *data; | ||
665 | + QTestState *qts = global_qtest; | ||
666 | + | ||
667 | + features = qvirtio_get_features(dev); | ||
668 | + g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); | ||
669 | + features = features & ~(QVIRTIO_F_BAD_FEATURE | | ||
670 | + (1u << VIRTIO_RING_F_EVENT_IDX) | | ||
671 | + (1u << VIRTIO_BLK_F_SCSI)); | ||
672 | + qvirtio_set_features(dev, features); | ||
673 | + | ||
674 | + capacity = qvirtio_config_readq(dev, 0); | ||
675 | + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); | ||
676 | + | ||
677 | + vq = qvirtqueue_setup(dev, t_alloc, 0); | ||
678 | + qvirtio_set_driver_ok(dev); | ||
679 | + | ||
680 | + /* Write request */ | ||
681 | + req.type = VIRTIO_BLK_T_OUT; | ||
682 | + req.ioprio = 1; | ||
683 | + req.sector = 0; | ||
684 | + req.data = g_malloc0(512); | ||
685 | + strcpy(req.data, "TEST"); | ||
686 | + | ||
687 | + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); | ||
688 | + | ||
689 | + g_free(req.data); | ||
690 | + | ||
691 | + indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2); | ||
692 | + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 528, false); | ||
693 | + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 528, 1, true); | ||
694 | + free_head = qvirtqueue_add_indirect(qts, vq, indirect); | ||
695 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
696 | + | ||
697 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
698 | + QVIRTIO_BLK_TIMEOUT_US); | ||
699 | + status = readb(req_addr + 528); | ||
700 | + g_assert_cmpint(status, ==, 0); | ||
701 | + | ||
702 | + g_free(indirect); | ||
703 | + guest_free(t_alloc, req_addr); | ||
704 | + | ||
705 | + /* Read request */ | ||
706 | + req.type = VIRTIO_BLK_T_IN; | ||
707 | + req.ioprio = 1; | ||
708 | + req.sector = 0; | ||
709 | + req.data = g_malloc0(512); | ||
710 | + strcpy(req.data, "TEST"); | ||
711 | + | ||
712 | + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); | ||
713 | + | ||
714 | + g_free(req.data); | ||
715 | + | ||
716 | + indirect = qvring_indirect_desc_setup(qts, dev, t_alloc, 2); | ||
717 | + qvring_indirect_desc_add(dev, qts, indirect, req_addr, 16, false); | ||
718 | + qvring_indirect_desc_add(dev, qts, indirect, req_addr + 16, 513, true); | ||
719 | + free_head = qvirtqueue_add_indirect(qts, vq, indirect); | ||
720 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
721 | + | ||
722 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
723 | + QVIRTIO_BLK_TIMEOUT_US); | ||
724 | + status = readb(req_addr + 528); | ||
725 | + g_assert_cmpint(status, ==, 0); | ||
726 | + | ||
727 | + data = g_malloc0(512); | ||
728 | + qtest_memread(qts, req_addr + 16, data, 512); | ||
729 | + g_assert_cmpstr(data, ==, "TEST"); | ||
730 | + g_free(data); | ||
731 | + | ||
732 | + g_free(indirect); | ||
733 | + guest_free(t_alloc, req_addr); | ||
734 | + qvirtqueue_cleanup(dev->bus, vq, t_alloc); | ||
735 | +} | ||
736 | + | ||
737 | +static void idx(void *obj, void *u_data, QGuestAllocator *t_alloc) | ||
738 | +{ | ||
739 | + QVirtQueue *vq; | ||
740 | + QVhostUserBlkPCI *blk = obj; | ||
741 | + QVirtioPCIDevice *pdev = &blk->pci_vdev; | ||
742 | + QVirtioDevice *dev = &pdev->vdev; | ||
743 | + QVirtioBlkReq req; | ||
744 | + uint64_t req_addr; | ||
745 | + uint64_t capacity; | ||
746 | + uint64_t features; | ||
747 | + uint32_t free_head; | ||
748 | + uint32_t write_head; | ||
749 | + uint32_t desc_idx; | ||
750 | + uint8_t status; | ||
751 | + char *data; | ||
752 | + QOSGraphObject *blk_object = obj; | ||
753 | + QPCIDevice *pci_dev = blk_object->get_driver(blk_object, "pci-device"); | ||
754 | + QTestState *qts = global_qtest; | ||
755 | + | ||
756 | + if (qpci_check_buggy_msi(pci_dev)) { | ||
757 | + return; | ||
758 | + } | ||
759 | + | ||
760 | + qpci_msix_enable(pdev->pdev); | ||
761 | + qvirtio_pci_set_msix_configuration_vector(pdev, t_alloc, 0); | ||
762 | + | ||
763 | + features = qvirtio_get_features(dev); | ||
764 | + features = features & ~(QVIRTIO_F_BAD_FEATURE | | ||
765 | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | | ||
766 | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | | ||
767 | + (1u << VIRTIO_BLK_F_SCSI)); | ||
768 | + qvirtio_set_features(dev, features); | ||
769 | + | ||
770 | + capacity = qvirtio_config_readq(dev, 0); | ||
771 | + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); | ||
772 | + | ||
773 | + vq = qvirtqueue_setup(dev, t_alloc, 0); | ||
774 | + qvirtqueue_pci_msix_setup(pdev, (QVirtQueuePCI *)vq, t_alloc, 1); | ||
775 | + | ||
776 | + qvirtio_set_driver_ok(dev); | ||
777 | + | ||
778 | + /* Write request */ | ||
779 | + req.type = VIRTIO_BLK_T_OUT; | ||
780 | + req.ioprio = 1; | ||
781 | + req.sector = 0; | ||
782 | + req.data = g_malloc0(512); | ||
783 | + strcpy(req.data, "TEST"); | ||
784 | + | ||
785 | + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); | ||
786 | + | ||
787 | + g_free(req.data); | ||
788 | + | ||
789 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
790 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); | ||
791 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
792 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
793 | + | ||
794 | + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, | ||
795 | + QVIRTIO_BLK_TIMEOUT_US); | ||
796 | + | ||
797 | + /* Write request */ | ||
798 | + req.type = VIRTIO_BLK_T_OUT; | ||
799 | + req.ioprio = 1; | ||
800 | + req.sector = 1; | ||
801 | + req.data = g_malloc0(512); | ||
802 | + strcpy(req.data, "TEST"); | ||
803 | + | ||
804 | + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); | ||
805 | + | ||
806 | + g_free(req.data); | ||
807 | + | ||
808 | + /* Notify after processing the third request */ | ||
809 | + qvirtqueue_set_used_event(qts, vq, 2); | ||
810 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
811 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, false, true); | ||
812 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
813 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
814 | + write_head = free_head; | ||
815 | + | ||
816 | + /* No notification expected */ | ||
817 | + status = qvirtio_wait_status_byte_no_isr(qts, dev, | ||
818 | + vq, req_addr + 528, | ||
819 | + QVIRTIO_BLK_TIMEOUT_US); | ||
820 | + g_assert_cmpint(status, ==, 0); | ||
821 | + | ||
822 | + guest_free(t_alloc, req_addr); | ||
823 | + | ||
824 | + /* Read request */ | ||
825 | + req.type = VIRTIO_BLK_T_IN; | ||
826 | + req.ioprio = 1; | ||
827 | + req.sector = 1; | ||
828 | + req.data = g_malloc0(512); | ||
829 | + | ||
830 | + req_addr = virtio_blk_request(t_alloc, dev, &req, 512); | ||
831 | + | ||
832 | + g_free(req.data); | ||
833 | + | ||
834 | + free_head = qvirtqueue_add(qts, vq, req_addr, 16, false, true); | ||
835 | + qvirtqueue_add(qts, vq, req_addr + 16, 512, true, true); | ||
836 | + qvirtqueue_add(qts, vq, req_addr + 528, 1, true, false); | ||
837 | + | ||
838 | + qvirtqueue_kick(qts, dev, vq, free_head); | ||
839 | + | ||
840 | + /* We get just one notification for both requests */ | ||
841 | + qvirtio_wait_used_elem(qts, dev, vq, write_head, NULL, | ||
842 | + QVIRTIO_BLK_TIMEOUT_US); | ||
843 | + g_assert(qvirtqueue_get_buf(qts, vq, &desc_idx, NULL)); | ||
844 | + g_assert_cmpint(desc_idx, ==, free_head); | ||
845 | + | ||
846 | + status = readb(req_addr + 528); | ||
847 | + g_assert_cmpint(status, ==, 0); | ||
848 | + | ||
849 | + data = g_malloc0(512); | ||
850 | + qtest_memread(qts, req_addr + 16, data, 512); | ||
851 | + g_assert_cmpstr(data, ==, "TEST"); | ||
852 | + g_free(data); | ||
853 | + | ||
854 | + guest_free(t_alloc, req_addr); | ||
855 | + | ||
856 | + /* End test */ | ||
857 | + qpci_msix_disable(pdev->pdev); | ||
858 | + | ||
859 | + qvirtqueue_cleanup(dev->bus, vq, t_alloc); | ||
860 | +} | ||
861 | + | ||
862 | +static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) | ||
863 | +{ | ||
864 | + QVirtioPCIDevice *dev1 = obj; | ||
865 | + QVirtioPCIDevice *dev; | ||
866 | + QTestState *qts = dev1->pdev->bus->qts; | ||
867 | + | ||
868 | + /* plug secondary disk */ | ||
869 | + qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", | ||
870 | + "{'addr': %s, 'chardev': 'char2'}", | ||
871 | + stringify(PCI_SLOT_HP) ".0"); | ||
872 | + | ||
873 | + dev = virtio_pci_new(dev1->pdev->bus, | ||
874 | + &(QPCIAddress) { .devfn = QPCI_DEVFN(PCI_SLOT_HP, 0) | ||
875 | + }); | ||
876 | + g_assert_nonnull(dev); | ||
877 | + g_assert_cmpint(dev->vdev.device_type, ==, VIRTIO_ID_BLOCK); | ||
878 | + qvirtio_pci_device_disable(dev); | ||
879 | + qos_object_destroy((QOSGraphObject *)dev); | ||
880 | + | ||
881 | + /* unplug secondary disk */ | ||
882 | + qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); | ||
883 | +} | ||
884 | + | ||
885 | +/* | ||
886 | + * Check that setting the vring addr on a non-existent virtqueue does | ||
887 | + * not crash. | ||
888 | + */ | ||
889 | +static void test_nonexistent_virtqueue(void *obj, void *data, | ||
890 | + QGuestAllocator *t_alloc) | ||
891 | +{ | ||
892 | + QVhostUserBlkPCI *blk = obj; | ||
893 | + QVirtioPCIDevice *pdev = &blk->pci_vdev; | ||
894 | + QPCIBar bar0; | ||
895 | + QPCIDevice *dev; | ||
896 | + | ||
897 | + dev = qpci_device_find(pdev->pdev->bus, QPCI_DEVFN(4, 0)); | ||
898 | + g_assert(dev != NULL); | ||
899 | + qpci_device_enable(dev); | ||
900 | + | ||
901 | + bar0 = qpci_iomap(dev, 0, NULL); | ||
902 | + | ||
903 | + qpci_io_writeb(dev, bar0, VIRTIO_PCI_QUEUE_SEL, 2); | ||
904 | + qpci_io_writel(dev, bar0, VIRTIO_PCI_QUEUE_PFN, 1); | ||
905 | + | ||
906 | + g_free(dev); | ||
907 | +} | ||
908 | + | ||
909 | +static const char *qtest_qemu_storage_daemon_binary(void) | ||
910 | +{ | ||
911 | + const char *qemu_storage_daemon_bin; | ||
912 | + | ||
913 | + qemu_storage_daemon_bin = getenv("QTEST_QEMU_STORAGE_DAEMON_BINARY"); | ||
914 | + if (!qemu_storage_daemon_bin) { | ||
915 | + fprintf(stderr, "Environment variable " | ||
916 | + "QTEST_QEMU_STORAGE_DAEMON_BINARY required\n"); | ||
917 | + exit(0); | ||
918 | + } | ||
919 | + | ||
920 | + return qemu_storage_daemon_bin; | ||
921 | +} | ||
922 | + | ||
923 | +static void drive_destroy(void *path) | ||
924 | +{ | ||
925 | + unlink(path); | ||
926 | + g_free(path); | ||
927 | + qos_invalidate_command_line(); | ||
928 | +} | ||
929 | + | ||
930 | +static char *drive_create(void) | ||
931 | +{ | ||
932 | + int fd, ret; | ||
933 | + /** vhost-user-blk won't recognize drive located in /tmp */ | ||
934 | + char *t_path = g_strdup("qtest.XXXXXX"); | ||
935 | + | ||
936 | + /** Create a temporary raw image */ | ||
937 | + fd = mkstemp(t_path); | ||
938 | + g_assert_cmpint(fd, >=, 0); | ||
939 | + ret = ftruncate(fd, TEST_IMAGE_SIZE); | ||
940 | + g_assert_cmpint(ret, ==, 0); | ||
941 | + close(fd); | ||
942 | + | ||
943 | + g_test_queue_destroy(drive_destroy, t_path); | ||
944 | + return t_path; | ||
945 | +} | ||
946 | + | ||
947 | +static char sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.XXXXXX"; | ||
948 | +static char qmp_sock_path_tempate[] = "/tmp/qtest.vhost_user_blk.qmp.XXXXXX"; | ||
949 | + | ||
950 | +static void quit_storage_daemon(void *qmp_test_state) | ||
951 | +{ | ||
952 | + const char quit_str[] = "{ 'execute': 'quit' }"; | ||
953 | + | ||
954 | + /* Before quiting storate-daemon, quit qemu to avoid dubious messages */ | ||
955 | + qobject_unref(qtest_qmp(global_qtest, quit_str)); | ||
956 | + | ||
957 | + /* | ||
958 | + * Give storage-daemon enough time to wake up&terminate | ||
959 | + * vu_client_trip coroutine so the Coroutine object could | ||
960 | + * be cleaned up. Otherwise LeakSanitizer would complain | ||
961 | + * about memory leaks. | ||
962 | + */ | ||
963 | + g_usleep(1000); | ||
964 | + | ||
965 | + qobject_unref(qtest_qmp((QTestState *)qmp_test_state, quit_str)); | ||
966 | + g_free(qmp_test_state); | ||
967 | +} | ||
968 | + | ||
969 | +static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) | ||
970 | +{ | ||
971 | + const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); | ||
972 | + int fd, qmp_fd, i; | ||
973 | + QTestState *qmp_test_state; | ||
974 | + gchar *img_path; | ||
975 | + char *sock_path = NULL; | ||
976 | + char *qmp_sock_path = g_strdup(qmp_sock_path_tempate); | ||
977 | + GString *storage_daemon_command = g_string_new(NULL); | ||
978 | + | ||
979 | + qmp_fd = mkstemp(qmp_sock_path); | ||
980 | + g_assert_cmpint(qmp_fd, >=, 0); | ||
981 | + g_test_queue_destroy(drive_destroy, qmp_sock_path); | ||
982 | + | ||
983 | + g_string_append_printf(storage_daemon_command, | ||
984 | + "exec %s " | ||
985 | + "--chardev socket,id=qmp,path=%s,server,nowait --monitor chardev=qmp ", | ||
986 | + vhost_user_blk_bin, qmp_sock_path); | ||
987 | + | ||
988 | + g_string_append_printf(cmd_line, | ||
989 | + " -object memory-backend-memfd,id=mem,size=128M,share=on -numa node,memdev=mem "); | ||
990 | + | ||
991 | + for (i = 0; i < vus_instances; i++) { | ||
992 | + sock_path = g_strdup(sock_path_tempate); | ||
993 | + fd = mkstemp(sock_path); | ||
994 | + g_assert_cmpint(fd, >=, 0); | ||
995 | + g_test_queue_destroy(drive_destroy, sock_path); | ||
996 | + /* create image file */ | ||
997 | + img_path = drive_create(); | ||
998 | + g_string_append_printf(storage_daemon_command, | ||
999 | + "--blockdev driver=file,node-name=disk%d,filename=%s " | ||
1000 | + "--object vhost-user-blk-server,id=disk%d,unix-socket=%s," | ||
1001 | + "node-name=disk%i,writable=on ", | ||
1002 | + i, img_path, i, sock_path, i); | ||
1003 | + | ||
1004 | + g_string_append_printf(cmd_line, "-chardev socket,id=char%d,path=%s ", | ||
1005 | + i + 1, sock_path); | ||
1006 | + } | ||
1007 | + | ||
1008 | + g_test_message("starting vhost-user backend: %s", | ||
1009 | + storage_daemon_command->str); | ||
1010 | + pid_t pid = fork(); | ||
1011 | + if (pid == 0) { | ||
1012 | + execlp("/bin/sh", "sh", "-c", storage_daemon_command->str, NULL); | ||
1013 | + exit(1); | ||
1014 | + } | ||
1015 | + g_string_free(storage_daemon_command, true); | ||
1016 | + | ||
1017 | + qmp_test_state = qtest_create_state_with_qmp_fd( | ||
1018 | + qtest_socket_client(qmp_sock_path)); | ||
1019 | + /* | ||
1020 | + * Ask qemu-storage-daemon to quit so it | ||
1021 | + * will not block scripts/tap-driver.pl. | ||
1022 | + */ | ||
1023 | + g_test_queue_destroy(quit_storage_daemon, qmp_test_state); | ||
1024 | + | ||
1025 | + qobject_unref(qtest_qmp(qmp_test_state, "{'execute': 'qmp_capabilities'}")); | ||
1026 | + return sock_path; | ||
1027 | +} | ||
1028 | + | ||
1029 | +static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) | ||
1030 | +{ | ||
1031 | + start_vhost_user_blk(cmd_line, 1); | ||
1032 | + return arg; | ||
1033 | +} | ||
1034 | + | ||
1035 | +/* | ||
1036 | + * Setup for hotplug. | ||
1037 | + * | ||
1038 | + * Since vhost-user server only serves one vhost-user client one time, | ||
1039 | + * another exprot | ||
1040 | + * | ||
1041 | + */ | ||
1042 | +static void *vhost_user_blk_hotplug_test_setup(GString *cmd_line, void *arg) | ||
1043 | +{ | ||
1044 | + /* "-chardev socket,id=char2" is used for pci_hotplug*/ | ||
1045 | + start_vhost_user_blk(cmd_line, 2); | ||
1046 | + return arg; | ||
1047 | +} | ||
1048 | + | ||
1049 | +static void register_vhost_user_blk_test(void) | ||
1050 | +{ | ||
1051 | + QOSGraphTestOptions opts = { | ||
1052 | + .before = vhost_user_blk_test_setup, | ||
1053 | + }; | ||
1054 | + | ||
1055 | + /* | ||
1056 | + * tests for vhost-user-blk and vhost-user-blk-pci | ||
1057 | + * The tests are borrowed from tests/virtio-blk-test.c. But some tests | ||
1058 | + * regarding block_resize don't work for vhost-user-blk. | ||
1059 | + * vhost-user-blk device doesn't have -drive, so tests containing | ||
1060 | + * block_resize are also abandoned, | ||
1061 | + * - config | ||
1062 | + * - resize | ||
1063 | + */ | ||
1064 | + qos_add_test("basic", "vhost-user-blk", basic, &opts); | ||
1065 | + qos_add_test("indirect", "vhost-user-blk", indirect, &opts); | ||
1066 | + qos_add_test("idx", "vhost-user-blk-pci", idx, &opts); | ||
1067 | + qos_add_test("nxvirtq", "vhost-user-blk-pci", | ||
1068 | + test_nonexistent_virtqueue, &opts); | ||
1069 | + | ||
1070 | + opts.before = vhost_user_blk_hotplug_test_setup; | ||
1071 | + qos_add_test("hotplug", "vhost-user-blk-pci", pci_hotplug, &opts); | ||
1072 | +} | ||
1073 | + | ||
1074 | +libqos_init(register_vhost_user_blk_test); | ||
1075 | diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build | ||
1076 | index XXXXXXX..XXXXXXX 100644 | ||
1077 | --- a/tests/qtest/libqos/meson.build | ||
1078 | +++ b/tests/qtest/libqos/meson.build | ||
1079 | @@ -XXX,XX +XXX,XX @@ libqos_srcs = files('../libqtest.c', | ||
1080 | 'virtio-9p.c', | ||
1081 | 'virtio-balloon.c', | ||
1082 | 'virtio-blk.c', | ||
1083 | + 'vhost-user-blk.c', | ||
1084 | 'virtio-mmio.c', | ||
1085 | 'virtio-net.c', | ||
1086 | 'virtio-pci.c', | ||
1087 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
1088 | index XXXXXXX..XXXXXXX 100644 | ||
1089 | --- a/tests/qtest/meson.build | ||
1090 | +++ b/tests/qtest/meson.build | ||
1091 | @@ -XXX,XX +XXX,XX @@ qos_test_ss.add( | ||
1092 | ) | ||
1093 | qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) | ||
1094 | qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) | ||
1095 | +qos_test_ss.add(when: ['CONFIG_LINUX', 'CONFIG_TOOLS'], if_true: files('vhost-user-blk-test.c')) | ||
1096 | |||
1097 | extra_qtest_deps = { | ||
1098 | 'bios-tables-test': [io], | ||
1099 | @@ -XXX,XX +XXX,XX @@ foreach dir : target_dirs | ||
1100 | endif | ||
1101 | qtest_env.set('G_TEST_DBUS_DAEMON', meson.source_root() / 'tests/dbus-vmstate-daemon.sh') | ||
1102 | qtest_env.set('QTEST_QEMU_BINARY', './qemu-system-' + target_base) | ||
1103 | - | ||
1104 | + qtest_env.set('QTEST_QEMU_STORAGE_DAEMON_BINARY', './storage-daemon/qemu-storage-daemon') | ||
1105 | + | ||
1106 | foreach test : qtests | ||
1107 | # Executables are shared across targets, declare them only the first time we | ||
1108 | # encounter them | ||
1109 | -- | ||
1110 | 2.26.2 | ||
1111 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
3 | Suggested-by: Stefano Garzarella <sgarzare@redhat.com> | 3 | Suggested-by: Stefano Garzarella <sgarzare@redhat.com> |
4 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | 4 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | 6 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
7 | Message-id: 20200918080912.321299-8-coiby.xu@gmail.com | 7 | Message-id: 20200918080912.321299-8-coiby.xu@gmail.com |
8 | [Removed reference to vhost-user-blk-test.c, it will be sent in a | ||
9 | separate pull request. | ||
10 | --Stefan] | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | --- | 12 | --- |
10 | MAINTAINERS | 8 ++++++++ | 13 | MAINTAINERS | 7 +++++++ |
11 | 1 file changed, 8 insertions(+) | 14 | 1 file changed, 7 insertions(+) |
12 | 15 | ||
13 | diff --git a/MAINTAINERS b/MAINTAINERS | 16 | diff --git a/MAINTAINERS b/MAINTAINERS |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/MAINTAINERS | 18 | --- a/MAINTAINERS |
16 | +++ b/MAINTAINERS | 19 | +++ b/MAINTAINERS |
... | ... | ||
21 | +Vhost-user block device backend server | 24 | +Vhost-user block device backend server |
22 | +M: Coiby Xu <Coiby.Xu@gmail.com> | 25 | +M: Coiby Xu <Coiby.Xu@gmail.com> |
23 | +S: Maintained | 26 | +S: Maintained |
24 | +F: block/export/vhost-user-blk-server.c | 27 | +F: block/export/vhost-user-blk-server.c |
25 | +F: util/vhost-user-server.c | 28 | +F: util/vhost-user-server.c |
26 | +F: tests/qtest/vhost-user-blk-test.c | ||
27 | +F: tests/qtest/libqos/vhost-user-blk.c | 29 | +F: tests/qtest/libqos/vhost-user-blk.c |
28 | + | 30 | + |
29 | Replication | 31 | Replication |
30 | M: Wen Congyang <wencongyang2@huawei.com> | 32 | M: Wen Congyang <wencongyang2@huawei.com> |
31 | M: Xie Changlong <xiechanglong.d@gmail.com> | 33 | M: Xie Changlong <xiechanglong.d@gmail.com> |
32 | -- | 34 | -- |
33 | 2.26.2 | 35 | 2.26.2 |
34 | 36 | diff view generated by jsdifflib |
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
---|---|---|---|
2 | Message-id: 20200924151549.913737-3-stefanha@redhat.com | 2 | Message-id: 20200924151549.913737-3-stefanha@redhat.com |
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | --- | 4 | --- |
5 | util/vhost-user-server.c | 2 +- | 5 | util/vhost-user-server.c | 2 +- |
6 | 1 file changed, 1 insertion(+), 1 deletion(-) | 6 | 1 file changed, 1 insertion(+), 1 deletion(-) |
7 | 7 | ||
8 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 8 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/util/vhost-user-server.c | 10 | --- a/util/vhost-user-server.c |
11 | +++ b/util/vhost-user-server.c | 11 | +++ b/util/vhost-user-server.c |
12 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 12 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
13 | return false; | 13 | return false; |
14 | } | 14 | } |
15 | 15 | ||
16 | - /* zero out unspecified fileds */ | 16 | - /* zero out unspecified fileds */ |
17 | + /* zero out unspecified fields */ | 17 | + /* zero out unspecified fields */ |
18 | *server = (VuServer) { | 18 | *server = (VuServer) { |
19 | .listener = listener, | 19 | .listener = listener, |
20 | .vu_iface = vu_iface, | 20 | .vu_iface = vu_iface, |
21 | -- | 21 | -- |
22 | 2.26.2 | 22 | 2.26.2 |
23 | 23 | diff view generated by jsdifflib |
1 | We already have access to the value with the correct type (ioc and sioc | 1 | We already have access to the value with the correct type (ioc and sioc |
---|---|---|---|
2 | are the same QIOChannel). | 2 | are the same QIOChannel). |
3 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | Message-id: 20200924151549.913737-4-stefanha@redhat.com | 5 | Message-id: 20200924151549.913737-4-stefanha@redhat.com |
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | --- | 7 | --- |
8 | util/vhost-user-server.c | 2 +- | 8 | util/vhost-user-server.c | 2 +- |
9 | 1 file changed, 1 insertion(+), 1 deletion(-) | 9 | 1 file changed, 1 insertion(+), 1 deletion(-) |
10 | 10 | ||
11 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 11 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/util/vhost-user-server.c | 13 | --- a/util/vhost-user-server.c |
14 | +++ b/util/vhost-user-server.c | 14 | +++ b/util/vhost-user-server.c |
15 | @@ -XXX,XX +XXX,XX @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, | 15 | @@ -XXX,XX +XXX,XX @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, |
16 | server->ioc = QIO_CHANNEL(sioc); | 16 | server->ioc = QIO_CHANNEL(sioc); |
17 | object_ref(OBJECT(server->ioc)); | 17 | object_ref(OBJECT(server->ioc)); |
18 | qio_channel_attach_aio_context(server->ioc, server->ctx); | 18 | qio_channel_attach_aio_context(server->ioc, server->ctx); |
19 | - qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); | 19 | - qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); |
20 | + qio_channel_set_blocking(server->ioc, false, NULL); | 20 | + qio_channel_set_blocking(server->ioc, false, NULL); |
21 | vu_client_start(server); | 21 | vu_client_start(server); |
22 | } | 22 | } |
23 | 23 | ||
24 | -- | 24 | -- |
25 | 2.26.2 | 25 | 2.26.2 |
26 | 26 | diff view generated by jsdifflib |
1 | Explicitly deleting watches is not necessary since libvhost-user calls | 1 | Explicitly deleting watches is not necessary since libvhost-user calls |
---|---|---|---|
2 | remove_watch() during vu_deinit(). Add an assertion to check this | 2 | remove_watch() during vu_deinit(). Add an assertion to check this |
3 | though. | 3 | though. |
4 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Message-id: 20200924151549.913737-5-stefanha@redhat.com | 6 | Message-id: 20200924151549.913737-5-stefanha@redhat.com |
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | --- | 8 | --- |
9 | util/vhost-user-server.c | 19 ++++--------------- | 9 | util/vhost-user-server.c | 19 ++++--------------- |
10 | 1 file changed, 4 insertions(+), 15 deletions(-) | 10 | 1 file changed, 4 insertions(+), 15 deletions(-) |
11 | 11 | ||
12 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 12 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
13 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/util/vhost-user-server.c | 14 | --- a/util/vhost-user-server.c |
15 | +++ b/util/vhost-user-server.c | 15 | +++ b/util/vhost-user-server.c |
16 | @@ -XXX,XX +XXX,XX @@ static void close_client(VuServer *server) | 16 | @@ -XXX,XX +XXX,XX @@ static void close_client(VuServer *server) |
17 | /* When this is set vu_client_trip will stop new processing vhost-user message */ | 17 | /* When this is set vu_client_trip will stop new processing vhost-user message */ |
18 | server->sioc = NULL; | 18 | server->sioc = NULL; |
19 | 19 | ||
20 | - VuFdWatch *vu_fd_watch, *next; | 20 | - VuFdWatch *vu_fd_watch, *next; |
21 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | 21 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { |
22 | - aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, | 22 | - aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, |
23 | - NULL, NULL, NULL); | 23 | - NULL, NULL, NULL); |
24 | - } | 24 | - } |
25 | - | 25 | - |
26 | - while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { | 26 | - while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { |
27 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | 27 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { |
28 | - if (!vu_fd_watch->processing) { | 28 | - if (!vu_fd_watch->processing) { |
29 | - QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); | 29 | - QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); |
30 | - g_free(vu_fd_watch); | 30 | - g_free(vu_fd_watch); |
31 | - } | 31 | - } |
32 | - } | 32 | - } |
33 | - } | 33 | - } |
34 | - | 34 | - |
35 | while (server->processing_msg) { | 35 | while (server->processing_msg) { |
36 | if (server->ioc->read_coroutine) { | 36 | if (server->ioc->read_coroutine) { |
37 | server->ioc->read_coroutine = NULL; | 37 | server->ioc->read_coroutine = NULL; |
38 | @@ -XXX,XX +XXX,XX @@ static void close_client(VuServer *server) | 38 | @@ -XXX,XX +XXX,XX @@ static void close_client(VuServer *server) |
39 | } | 39 | } |
40 | 40 | ||
41 | vu_deinit(&server->vu_dev); | 41 | vu_deinit(&server->vu_dev); |
42 | + | 42 | + |
43 | + /* vu_deinit() should have called remove_watch() */ | 43 | + /* vu_deinit() should have called remove_watch() */ |
44 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | 44 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); |
45 | + | 45 | + |
46 | object_unref(OBJECT(sioc)); | 46 | object_unref(OBJECT(sioc)); |
47 | object_unref(OBJECT(server->ioc)); | 47 | object_unref(OBJECT(server->ioc)); |
48 | } | 48 | } |
49 | -- | 49 | -- |
50 | 2.26.2 | 50 | 2.26.2 |
51 | 51 | diff view generated by jsdifflib |
1 | Only one struct is needed per request. Drop req_data and the separate | 1 | Only one struct is needed per request. Drop req_data and the separate |
---|---|---|---|
2 | VuBlockReq instance. Instead let vu_queue_pop() allocate everything at | 2 | VuBlockReq instance. Instead let vu_queue_pop() allocate everything at |
3 | once. | 3 | once. |
4 | 4 | ||
5 | This fixes the req_data memory leak in vu_block_virtio_process_req(). | 5 | This fixes the req_data memory leak in vu_block_virtio_process_req(). |
6 | 6 | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Message-id: 20200924151549.913737-6-stefanha@redhat.com | 8 | Message-id: 20200924151549.913737-6-stefanha@redhat.com |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | --- | 10 | --- |
11 | block/export/vhost-user-blk-server.c | 68 +++++++++------------------- | 11 | block/export/vhost-user-blk-server.c | 68 +++++++++------------------- |
12 | 1 file changed, 21 insertions(+), 47 deletions(-) | 12 | 1 file changed, 21 insertions(+), 47 deletions(-) |
13 | 13 | ||
14 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 14 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/export/vhost-user-blk-server.c | 16 | --- a/block/export/vhost-user-blk-server.c |
17 | +++ b/block/export/vhost-user-blk-server.c | 17 | +++ b/block/export/vhost-user-blk-server.c |
18 | @@ -XXX,XX +XXX,XX @@ struct virtio_blk_inhdr { | 18 | @@ -XXX,XX +XXX,XX @@ struct virtio_blk_inhdr { |
19 | }; | 19 | }; |
20 | 20 | ||
21 | typedef struct VuBlockReq { | 21 | typedef struct VuBlockReq { |
22 | - VuVirtqElement *elem; | 22 | - VuVirtqElement *elem; |
23 | + VuVirtqElement elem; | 23 | + VuVirtqElement elem; |
24 | int64_t sector_num; | 24 | int64_t sector_num; |
25 | size_t size; | 25 | size_t size; |
26 | struct virtio_blk_inhdr *in; | 26 | struct virtio_blk_inhdr *in; |
27 | @@ -XXX,XX +XXX,XX @@ static void vu_block_req_complete(VuBlockReq *req) | 27 | @@ -XXX,XX +XXX,XX @@ static void vu_block_req_complete(VuBlockReq *req) |
28 | VuDev *vu_dev = &req->server->vu_dev; | 28 | VuDev *vu_dev = &req->server->vu_dev; |
29 | 29 | ||
30 | /* IO size with 1 extra status byte */ | 30 | /* IO size with 1 extra status byte */ |
31 | - vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); | 31 | - vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); |
32 | + vu_queue_push(vu_dev, req->vq, &req->elem, req->size + 1); | 32 | + vu_queue_push(vu_dev, req->vq, &req->elem, req->size + 1); |
33 | vu_queue_notify(vu_dev, req->vq); | 33 | vu_queue_notify(vu_dev, req->vq); |
34 | 34 | ||
35 | - if (req->elem) { | 35 | - if (req->elem) { |
36 | - free(req->elem); | 36 | - free(req->elem); |
37 | - } | 37 | - } |
38 | - | 38 | - |
39 | - g_free(req); | 39 | - g_free(req); |
40 | + free(req); | 40 | + free(req); |
41 | } | 41 | } |
42 | 42 | ||
43 | static VuBlockDev *get_vu_block_device_by_server(VuServer *server) | 43 | static VuBlockDev *get_vu_block_device_by_server(VuServer *server) |
44 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_flush(VuBlockReq *req) | 44 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_flush(VuBlockReq *req) |
45 | blk_co_flush(backend); | 45 | blk_co_flush(backend); |
46 | } | 46 | } |
47 | 47 | ||
48 | -struct req_data { | 48 | -struct req_data { |
49 | - VuServer *server; | 49 | - VuServer *server; |
50 | - VuVirtq *vq; | 50 | - VuVirtq *vq; |
51 | - VuVirtqElement *elem; | 51 | - VuVirtqElement *elem; |
52 | -}; | 52 | -}; |
53 | - | 53 | - |
54 | static void coroutine_fn vu_block_virtio_process_req(void *opaque) | 54 | static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
55 | { | 55 | { |
56 | - struct req_data *data = opaque; | 56 | - struct req_data *data = opaque; |
57 | - VuServer *server = data->server; | 57 | - VuServer *server = data->server; |
58 | - VuVirtq *vq = data->vq; | 58 | - VuVirtq *vq = data->vq; |
59 | - VuVirtqElement *elem = data->elem; | 59 | - VuVirtqElement *elem = data->elem; |
60 | + VuBlockReq *req = opaque; | 60 | + VuBlockReq *req = opaque; |
61 | + VuServer *server = req->server; | 61 | + VuServer *server = req->server; |
62 | + VuVirtqElement *elem = &req->elem; | 62 | + VuVirtqElement *elem = &req->elem; |
63 | uint32_t type; | 63 | uint32_t type; |
64 | - VuBlockReq *req; | 64 | - VuBlockReq *req; |
65 | 65 | ||
66 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | 66 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); |
67 | BlockBackend *backend = vdev_blk->backend; | 67 | BlockBackend *backend = vdev_blk->backend; |
68 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | 68 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
69 | struct iovec *out_iov = elem->out_sg; | 69 | struct iovec *out_iov = elem->out_sg; |
70 | unsigned in_num = elem->in_num; | 70 | unsigned in_num = elem->in_num; |
71 | unsigned out_num = elem->out_num; | 71 | unsigned out_num = elem->out_num; |
72 | + | 72 | + |
73 | /* refer to hw/block/virtio_blk.c */ | 73 | /* refer to hw/block/virtio_blk.c */ |
74 | if (elem->out_num < 1 || elem->in_num < 1) { | 74 | if (elem->out_num < 1 || elem->in_num < 1) { |
75 | error_report("virtio-blk request missing headers"); | 75 | error_report("virtio-blk request missing headers"); |
76 | - free(elem); | 76 | - free(elem); |
77 | - return; | 77 | - return; |
78 | + goto err; | 78 | + goto err; |
79 | } | 79 | } |
80 | 80 | ||
81 | - req = g_new0(VuBlockReq, 1); | 81 | - req = g_new0(VuBlockReq, 1); |
82 | - req->server = server; | 82 | - req->server = server; |
83 | - req->vq = vq; | 83 | - req->vq = vq; |
84 | - req->elem = elem; | 84 | - req->elem = elem; |
85 | - | 85 | - |
86 | if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, | 86 | if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, |
87 | sizeof(req->out)) != sizeof(req->out))) { | 87 | sizeof(req->out)) != sizeof(req->out))) { |
88 | error_report("virtio-blk request outhdr too short"); | 88 | error_report("virtio-blk request outhdr too short"); |
89 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | 89 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
90 | 90 | ||
91 | err: | 91 | err: |
92 | free(elem); | 92 | free(elem); |
93 | - g_free(req); | 93 | - g_free(req); |
94 | - return; | 94 | - return; |
95 | } | 95 | } |
96 | 96 | ||
97 | static void vu_block_process_vq(VuDev *vu_dev, int idx) | 97 | static void vu_block_process_vq(VuDev *vu_dev, int idx) |
98 | { | 98 | { |
99 | - VuServer *server; | 99 | - VuServer *server; |
100 | - VuVirtq *vq; | 100 | - VuVirtq *vq; |
101 | - struct req_data *req_data; | 101 | - struct req_data *req_data; |
102 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | 102 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); |
103 | + VuVirtq *vq = vu_get_queue(vu_dev, idx); | 103 | + VuVirtq *vq = vu_get_queue(vu_dev, idx); |
104 | 104 | ||
105 | - server = container_of(vu_dev, VuServer, vu_dev); | 105 | - server = container_of(vu_dev, VuServer, vu_dev); |
106 | - assert(server); | 106 | - assert(server); |
107 | - | 107 | - |
108 | - vq = vu_get_queue(vu_dev, idx); | 108 | - vq = vu_get_queue(vu_dev, idx); |
109 | - assert(vq); | 109 | - assert(vq); |
110 | - VuVirtqElement *elem; | 110 | - VuVirtqElement *elem; |
111 | while (1) { | 111 | while (1) { |
112 | - elem = vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + | 112 | - elem = vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + |
113 | - sizeof(VuBlockReq)); | 113 | - sizeof(VuBlockReq)); |
114 | - if (elem) { | 114 | - if (elem) { |
115 | - req_data = g_new0(struct req_data, 1); | 115 | - req_data = g_new0(struct req_data, 1); |
116 | - req_data->server = server; | 116 | - req_data->server = server; |
117 | - req_data->vq = vq; | 117 | - req_data->vq = vq; |
118 | - req_data->elem = elem; | 118 | - req_data->elem = elem; |
119 | - Coroutine *co = qemu_coroutine_create(vu_block_virtio_process_req, | 119 | - Coroutine *co = qemu_coroutine_create(vu_block_virtio_process_req, |
120 | - req_data); | 120 | - req_data); |
121 | - aio_co_enter(server->ioc->ctx, co); | 121 | - aio_co_enter(server->ioc->ctx, co); |
122 | - } else { | 122 | - } else { |
123 | + VuBlockReq *req; | 123 | + VuBlockReq *req; |
124 | + | 124 | + |
125 | + req = vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); | 125 | + req = vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); |
126 | + if (!req) { | 126 | + if (!req) { |
127 | break; | 127 | break; |
128 | } | 128 | } |
129 | + | 129 | + |
130 | + req->server = server; | 130 | + req->server = server; |
131 | + req->vq = vq; | 131 | + req->vq = vq; |
132 | + | 132 | + |
133 | + Coroutine *co = | 133 | + Coroutine *co = |
134 | + qemu_coroutine_create(vu_block_virtio_process_req, req); | 134 | + qemu_coroutine_create(vu_block_virtio_process_req, req); |
135 | + qemu_coroutine_enter(co); | 135 | + qemu_coroutine_enter(co); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | -- | 139 | -- |
140 | 2.26.2 | 140 | 2.26.2 |
141 | 141 | diff view generated by jsdifflib |
1 | The device panic notifier callback is not used. Drop it. | 1 | The device panic notifier callback is not used. Drop it. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Message-id: 20200924151549.913737-7-stefanha@redhat.com | 4 | Message-id: 20200924151549.913737-7-stefanha@redhat.com |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | --- | 6 | --- |
7 | util/vhost-user-server.h | 3 --- | 7 | util/vhost-user-server.h | 3 --- |
8 | block/export/vhost-user-blk-server.c | 3 +-- | 8 | block/export/vhost-user-blk-server.c | 3 +-- |
9 | util/vhost-user-server.c | 6 ------ | 9 | util/vhost-user-server.c | 6 ------ |
10 | 3 files changed, 1 insertion(+), 11 deletions(-) | 10 | 3 files changed, 1 insertion(+), 11 deletions(-) |
11 | 11 | ||
12 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h | 12 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h |
13 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/util/vhost-user-server.h | 14 | --- a/util/vhost-user-server.h |
15 | +++ b/util/vhost-user-server.h | 15 | +++ b/util/vhost-user-server.h |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct VuFdWatch { | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct VuFdWatch { |
17 | } VuFdWatch; | 17 | } VuFdWatch; |
18 | 18 | ||
19 | typedef struct VuServer VuServer; | 19 | typedef struct VuServer VuServer; |
20 | -typedef void DevicePanicNotifierFn(VuServer *server); | 20 | -typedef void DevicePanicNotifierFn(VuServer *server); |
21 | 21 | ||
22 | struct VuServer { | 22 | struct VuServer { |
23 | QIONetListener *listener; | 23 | QIONetListener *listener; |
24 | AioContext *ctx; | 24 | AioContext *ctx; |
25 | - DevicePanicNotifierFn *device_panic_notifier; | 25 | - DevicePanicNotifierFn *device_panic_notifier; |
26 | int max_queues; | 26 | int max_queues; |
27 | const VuDevIface *vu_iface; | 27 | const VuDevIface *vu_iface; |
28 | VuDev vu_dev; | 28 | VuDev vu_dev; |
29 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 29 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
30 | SocketAddress *unix_socket, | 30 | SocketAddress *unix_socket, |
31 | AioContext *ctx, | 31 | AioContext *ctx, |
32 | uint16_t max_queues, | 32 | uint16_t max_queues, |
33 | - DevicePanicNotifierFn *device_panic_notifier, | 33 | - DevicePanicNotifierFn *device_panic_notifier, |
34 | const VuDevIface *vu_iface, | 34 | const VuDevIface *vu_iface, |
35 | Error **errp); | 35 | Error **errp); |
36 | 36 | ||
37 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 37 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
38 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/block/export/vhost-user-blk-server.c | 39 | --- a/block/export/vhost-user-blk-server.c |
40 | +++ b/block/export/vhost-user-blk-server.c | 40 | +++ b/block/export/vhost-user-blk-server.c |
41 | @@ -XXX,XX +XXX,XX @@ static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, | 41 | @@ -XXX,XX +XXX,XX @@ static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, |
42 | ctx = bdrv_get_aio_context(blk_bs(vu_block_device->backend)); | 42 | ctx = bdrv_get_aio_context(blk_bs(vu_block_device->backend)); |
43 | 43 | ||
44 | if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, | 44 | if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, |
45 | - VHOST_USER_BLK_MAX_QUEUES, | 45 | - VHOST_USER_BLK_MAX_QUEUES, |
46 | - NULL, &vu_block_iface, | 46 | - NULL, &vu_block_iface, |
47 | + VHOST_USER_BLK_MAX_QUEUES, &vu_block_iface, | 47 | + VHOST_USER_BLK_MAX_QUEUES, &vu_block_iface, |
48 | errp)) { | 48 | errp)) { |
49 | goto error; | 49 | goto error; |
50 | } | 50 | } |
51 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 51 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
52 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/util/vhost-user-server.c | 53 | --- a/util/vhost-user-server.c |
54 | +++ b/util/vhost-user-server.c | 54 | +++ b/util/vhost-user-server.c |
55 | @@ -XXX,XX +XXX,XX @@ static void panic_cb(VuDev *vu_dev, const char *buf) | 55 | @@ -XXX,XX +XXX,XX @@ static void panic_cb(VuDev *vu_dev, const char *buf) |
56 | close_client(server); | 56 | close_client(server); |
57 | } | 57 | } |
58 | 58 | ||
59 | - if (server->device_panic_notifier) { | 59 | - if (server->device_panic_notifier) { |
60 | - server->device_panic_notifier(server); | 60 | - server->device_panic_notifier(server); |
61 | - } | 61 | - } |
62 | - | 62 | - |
63 | /* | 63 | /* |
64 | * Set the callback function for network listener so another | 64 | * Set the callback function for network listener so another |
65 | * vhost-user client can connect to this server | 65 | * vhost-user client can connect to this server |
66 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 66 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
67 | SocketAddress *socket_addr, | 67 | SocketAddress *socket_addr, |
68 | AioContext *ctx, | 68 | AioContext *ctx, |
69 | uint16_t max_queues, | 69 | uint16_t max_queues, |
70 | - DevicePanicNotifierFn *device_panic_notifier, | 70 | - DevicePanicNotifierFn *device_panic_notifier, |
71 | const VuDevIface *vu_iface, | 71 | const VuDevIface *vu_iface, |
72 | Error **errp) | 72 | Error **errp) |
73 | { | 73 | { |
74 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 74 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
75 | .vu_iface = vu_iface, | 75 | .vu_iface = vu_iface, |
76 | .max_queues = max_queues, | 76 | .max_queues = max_queues, |
77 | .ctx = ctx, | 77 | .ctx = ctx, |
78 | - .device_panic_notifier = device_panic_notifier, | 78 | - .device_panic_notifier = device_panic_notifier, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | qio_net_listener_set_name(server->listener, "vhost-user-backend-listener"); | 81 | qio_net_listener_set_name(server->listener, "vhost-user-backend-listener"); |
82 | -- | 82 | -- |
83 | 2.26.2 | 83 | 2.26.2 |
84 | 84 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
67 | - if (nfds + nfds_t > max_fds) { | 67 | - if (nfds + nfds_t > max_fds) { |
68 | + | 68 | + |
69 | + if (nfds > 0) { | 69 | + if (nfds > 0) { |
70 | + if (vmsg->fd_num + nfds > max_fds) { | 70 | + if (vmsg->fd_num + nfds > max_fds) { |
71 | error_report("A maximum of %zu fds are allowed, " | 71 | error_report("A maximum of %zu fds are allowed, " |
72 | "however got %lu fds now", | 72 | "however got %zu fds now", |
73 | - max_fds, nfds + nfds_t); | 73 | - max_fds, nfds + nfds_t); |
74 | + max_fds, vmsg->fd_num + nfds); | 74 | + max_fds, vmsg->fd_num + nfds); |
75 | + g_free(fds); | 75 | + g_free(fds); |
76 | goto fail; | 76 | goto fail; |
77 | } | 77 | } |
... | ... | diff view generated by jsdifflib |
1 | Unexpected EOF is an error that must be reported. | 1 | Unexpected EOF is an error that must be reported. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Message-id: 20200924151549.913737-9-stefanha@redhat.com | 4 | Message-id: 20200924151549.913737-9-stefanha@redhat.com |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | --- | 6 | --- |
7 | util/vhost-user-server.c | 6 ++++-- | 7 | util/vhost-user-server.c | 6 ++++-- |
8 | 1 file changed, 4 insertions(+), 2 deletions(-) | 8 | 1 file changed, 4 insertions(+), 2 deletions(-) |
9 | 9 | ||
10 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 10 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
11 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/util/vhost-user-server.c | 12 | --- a/util/vhost-user-server.c |
13 | +++ b/util/vhost-user-server.c | 13 | +++ b/util/vhost-user-server.c |
14 | @@ -XXX,XX +XXX,XX @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) | 14 | @@ -XXX,XX +XXX,XX @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) |
15 | }; | 15 | }; |
16 | if (vmsg->size) { | 16 | if (vmsg->size) { |
17 | rc = qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); | 17 | rc = qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); |
18 | - if (rc == -1) { | 18 | - if (rc == -1) { |
19 | - error_report_err(local_err); | 19 | - error_report_err(local_err); |
20 | + if (rc != 1) { | 20 | + if (rc != 1) { |
21 | + if (local_err) { | 21 | + if (local_err) { |
22 | + error_report_err(local_err); | 22 | + error_report_err(local_err); |
23 | + } | 23 | + } |
24 | goto fail; | 24 | goto fail; |
25 | } | 25 | } |
26 | } | 26 | } |
27 | -- | 27 | -- |
28 | 2.26.2 | 28 | 2.26.2 |
29 | 29 | diff view generated by jsdifflib |
1 | The vu_client_trip() coroutine is leaked during AioContext switching. It | 1 | The vu_client_trip() coroutine is leaked during AioContext switching. It |
---|---|---|---|
2 | is also unsafe to destroy the vu_dev in panic_cb() since its callers | 2 | is also unsafe to destroy the vu_dev in panic_cb() since its callers |
3 | still access it in some cases. | 3 | still access it in some cases. |
4 | 4 | ||
5 | Rework the lifecycle to solve these safety issues. | 5 | Rework the lifecycle to solve these safety issues. |
6 | 6 | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Message-id: 20200924151549.913737-10-stefanha@redhat.com | 8 | Message-id: 20200924151549.913737-10-stefanha@redhat.com |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | --- | 10 | --- |
11 | util/vhost-user-server.h | 29 ++-- | 11 | util/vhost-user-server.h | 29 ++-- |
12 | block/export/vhost-user-blk-server.c | 9 +- | 12 | block/export/vhost-user-blk-server.c | 9 +- |
13 | util/vhost-user-server.c | 245 +++++++++++++++------------ | 13 | util/vhost-user-server.c | 245 +++++++++++++++------------ |
14 | 3 files changed, 155 insertions(+), 128 deletions(-) | 14 | 3 files changed, 155 insertions(+), 128 deletions(-) |
15 | 15 | ||
16 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h | 16 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/util/vhost-user-server.h | 18 | --- a/util/vhost-user-server.h |
19 | +++ b/util/vhost-user-server.h | 19 | +++ b/util/vhost-user-server.h |
20 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ |
21 | #include "qapi/error.h" | 21 | #include "qapi/error.h" |
22 | #include "standard-headers/linux/virtio_blk.h" | 22 | #include "standard-headers/linux/virtio_blk.h" |
23 | 23 | ||
24 | +/* A kick fd that we monitor on behalf of libvhost-user */ | 24 | +/* A kick fd that we monitor on behalf of libvhost-user */ |
25 | typedef struct VuFdWatch { | 25 | typedef struct VuFdWatch { |
26 | VuDev *vu_dev; | 26 | VuDev *vu_dev; |
27 | int fd; /*kick fd*/ | 27 | int fd; /*kick fd*/ |
28 | void *pvt; | 28 | void *pvt; |
29 | vu_watch_cb cb; | 29 | vu_watch_cb cb; |
30 | - bool processing; | 30 | - bool processing; |
31 | QTAILQ_ENTRY(VuFdWatch) next; | 31 | QTAILQ_ENTRY(VuFdWatch) next; |
32 | } VuFdWatch; | 32 | } VuFdWatch; |
33 | 33 | ||
34 | -typedef struct VuServer VuServer; | 34 | -typedef struct VuServer VuServer; |
35 | - | 35 | - |
36 | -struct VuServer { | 36 | -struct VuServer { |
37 | +/** | 37 | +/** |
38 | + * VuServer: | 38 | + * VuServer: |
39 | + * A vhost-user server instance with user-defined VuDevIface callbacks. | 39 | + * A vhost-user server instance with user-defined VuDevIface callbacks. |
40 | + * Vhost-user device backends can be implemented using VuServer. VuDevIface | 40 | + * Vhost-user device backends can be implemented using VuServer. VuDevIface |
41 | + * callbacks and virtqueue kicks run in the given AioContext. | 41 | + * callbacks and virtqueue kicks run in the given AioContext. |
42 | + */ | 42 | + */ |
43 | +typedef struct { | 43 | +typedef struct { |
44 | QIONetListener *listener; | 44 | QIONetListener *listener; |
45 | + QEMUBH *restart_listener_bh; | 45 | + QEMUBH *restart_listener_bh; |
46 | AioContext *ctx; | 46 | AioContext *ctx; |
47 | int max_queues; | 47 | int max_queues; |
48 | const VuDevIface *vu_iface; | 48 | const VuDevIface *vu_iface; |
49 | + | 49 | + |
50 | + /* Protected by ctx lock */ | 50 | + /* Protected by ctx lock */ |
51 | VuDev vu_dev; | 51 | VuDev vu_dev; |
52 | QIOChannel *ioc; /* The I/O channel with the client */ | 52 | QIOChannel *ioc; /* The I/O channel with the client */ |
53 | QIOChannelSocket *sioc; /* The underlying data channel with the client */ | 53 | QIOChannelSocket *sioc; /* The underlying data channel with the client */ |
54 | - /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ | 54 | - /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ |
55 | - QIOChannel *ioc_slave; | 55 | - QIOChannel *ioc_slave; |
56 | - QIOChannelSocket *sioc_slave; | 56 | - QIOChannelSocket *sioc_slave; |
57 | - Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | 57 | - Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ |
58 | QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; | 58 | QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; |
59 | - /* restart coroutine co_trip if AIOContext is changed */ | 59 | - /* restart coroutine co_trip if AIOContext is changed */ |
60 | - bool aio_context_changed; | 60 | - bool aio_context_changed; |
61 | - bool processing_msg; | 61 | - bool processing_msg; |
62 | -}; | 62 | -}; |
63 | + | 63 | + |
64 | + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | 64 | + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ |
65 | +} VuServer; | 65 | +} VuServer; |
66 | 66 | ||
67 | bool vhost_user_server_start(VuServer *server, | 67 | bool vhost_user_server_start(VuServer *server, |
68 | SocketAddress *unix_socket, | 68 | SocketAddress *unix_socket, |
69 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 69 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
70 | 70 | ||
71 | void vhost_user_server_stop(VuServer *server); | 71 | void vhost_user_server_stop(VuServer *server); |
72 | 72 | ||
73 | -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); | 73 | -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); |
74 | +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx); | 74 | +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx); |
75 | +void vhost_user_server_detach_aio_context(VuServer *server); | 75 | +void vhost_user_server_detach_aio_context(VuServer *server); |
76 | 76 | ||
77 | #endif /* VHOST_USER_SERVER_H */ | 77 | #endif /* VHOST_USER_SERVER_H */ |
78 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 78 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
79 | index XXXXXXX..XXXXXXX 100644 | 79 | index XXXXXXX..XXXXXXX 100644 |
80 | --- a/block/export/vhost-user-blk-server.c | 80 | --- a/block/export/vhost-user-blk-server.c |
81 | +++ b/block/export/vhost-user-blk-server.c | 81 | +++ b/block/export/vhost-user-blk-server.c |
82 | @@ -XXX,XX +XXX,XX @@ static const VuDevIface vu_block_iface = { | 82 | @@ -XXX,XX +XXX,XX @@ static const VuDevIface vu_block_iface = { |
83 | static void blk_aio_attached(AioContext *ctx, void *opaque) | 83 | static void blk_aio_attached(AioContext *ctx, void *opaque) |
84 | { | 84 | { |
85 | VuBlockDev *vub_dev = opaque; | 85 | VuBlockDev *vub_dev = opaque; |
86 | - aio_context_acquire(ctx); | 86 | - aio_context_acquire(ctx); |
87 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); | 87 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); |
88 | - aio_context_release(ctx); | 88 | - aio_context_release(ctx); |
89 | + vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); | 89 | + vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); |
90 | } | 90 | } |
91 | 91 | ||
92 | static void blk_aio_detach(void *opaque) | 92 | static void blk_aio_detach(void *opaque) |
93 | { | 93 | { |
94 | VuBlockDev *vub_dev = opaque; | 94 | VuBlockDev *vub_dev = opaque; |
95 | - AioContext *ctx = vub_dev->vu_server.ctx; | 95 | - AioContext *ctx = vub_dev->vu_server.ctx; |
96 | - aio_context_acquire(ctx); | 96 | - aio_context_acquire(ctx); |
97 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); | 97 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); |
98 | - aio_context_release(ctx); | 98 | - aio_context_release(ctx); |
99 | + vhost_user_server_detach_aio_context(&vub_dev->vu_server); | 99 | + vhost_user_server_detach_aio_context(&vub_dev->vu_server); |
100 | } | 100 | } |
101 | 101 | ||
102 | static void | 102 | static void |
103 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 103 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
104 | index XXXXXXX..XXXXXXX 100644 | 104 | index XXXXXXX..XXXXXXX 100644 |
105 | --- a/util/vhost-user-server.c | 105 | --- a/util/vhost-user-server.c |
106 | +++ b/util/vhost-user-server.c | 106 | +++ b/util/vhost-user-server.c |
107 | @@ -XXX,XX +XXX,XX @@ | 107 | @@ -XXX,XX +XXX,XX @@ |
108 | */ | 108 | */ |
109 | #include "qemu/osdep.h" | 109 | #include "qemu/osdep.h" |
110 | #include "qemu/main-loop.h" | 110 | #include "qemu/main-loop.h" |
111 | +#include "block/aio-wait.h" | 111 | +#include "block/aio-wait.h" |
112 | #include "vhost-user-server.h" | 112 | #include "vhost-user-server.h" |
113 | 113 | ||
114 | +/* | 114 | +/* |
115 | + * Theory of operation: | 115 | + * Theory of operation: |
116 | + * | 116 | + * |
117 | + * VuServer is started and stopped by vhost_user_server_start() and | 117 | + * VuServer is started and stopped by vhost_user_server_start() and |
118 | + * vhost_user_server_stop() from the main loop thread. Starting the server | 118 | + * vhost_user_server_stop() from the main loop thread. Starting the server |
119 | + * opens a vhost-user UNIX domain socket and listens for incoming connections. | 119 | + * opens a vhost-user UNIX domain socket and listens for incoming connections. |
120 | + * Only one connection is allowed at a time. | 120 | + * Only one connection is allowed at a time. |
121 | + * | 121 | + * |
122 | + * The connection is handled by the vu_client_trip() coroutine in the | 122 | + * The connection is handled by the vu_client_trip() coroutine in the |
123 | + * VuServer->ctx AioContext. The coroutine consists of a vu_dispatch() loop | 123 | + * VuServer->ctx AioContext. The coroutine consists of a vu_dispatch() loop |
124 | + * where libvhost-user calls vu_message_read() to receive the next vhost-user | 124 | + * where libvhost-user calls vu_message_read() to receive the next vhost-user |
125 | + * protocol messages over the UNIX domain socket. | 125 | + * protocol messages over the UNIX domain socket. |
126 | + * | 126 | + * |
127 | + * When virtqueues are set up libvhost-user calls set_watch() to monitor kick | 127 | + * When virtqueues are set up libvhost-user calls set_watch() to monitor kick |
128 | + * fds. These fds are also handled in the VuServer->ctx AioContext. | 128 | + * fds. These fds are also handled in the VuServer->ctx AioContext. |
129 | + * | 129 | + * |
130 | + * Both vu_client_trip() and kick fd monitoring can be stopped by shutting down | 130 | + * Both vu_client_trip() and kick fd monitoring can be stopped by shutting down |
131 | + * the socket connection. Shutting down the socket connection causes | 131 | + * the socket connection. Shutting down the socket connection causes |
132 | + * vu_message_read() to fail since no more data can be received from the socket. | 132 | + * vu_message_read() to fail since no more data can be received from the socket. |
133 | + * After vu_dispatch() fails, vu_client_trip() calls vu_deinit() to stop | 133 | + * After vu_dispatch() fails, vu_client_trip() calls vu_deinit() to stop |
134 | + * libvhost-user before terminating the coroutine. vu_deinit() calls | 134 | + * libvhost-user before terminating the coroutine. vu_deinit() calls |
135 | + * remove_watch() to stop monitoring kick fds and this stops virtqueue | 135 | + * remove_watch() to stop monitoring kick fds and this stops virtqueue |
136 | + * processing. | 136 | + * processing. |
137 | + * | 137 | + * |
138 | + * When vu_client_trip() has finished cleaning up it schedules a BH in the main | 138 | + * When vu_client_trip() has finished cleaning up it schedules a BH in the main |
139 | + * loop thread to accept the next client connection. | 139 | + * loop thread to accept the next client connection. |
140 | + * | 140 | + * |
141 | + * When libvhost-user detects an error it calls panic_cb() and sets the | 141 | + * When libvhost-user detects an error it calls panic_cb() and sets the |
142 | + * dev->broken flag. Both vu_client_trip() and kick fd processing stop when | 142 | + * dev->broken flag. Both vu_client_trip() and kick fd processing stop when |
143 | + * the dev->broken flag is set. | 143 | + * the dev->broken flag is set. |
144 | + * | 144 | + * |
145 | + * It is possible to switch AioContexts using | 145 | + * It is possible to switch AioContexts using |
146 | + * vhost_user_server_detach_aio_context() and | 146 | + * vhost_user_server_detach_aio_context() and |
147 | + * vhost_user_server_attach_aio_context(). They stop monitoring fds in the old | 147 | + * vhost_user_server_attach_aio_context(). They stop monitoring fds in the old |
148 | + * AioContext and resume monitoring in the new AioContext. The vu_client_trip() | 148 | + * AioContext and resume monitoring in the new AioContext. The vu_client_trip() |
149 | + * coroutine remains in a yielded state during the switch. This is made | 149 | + * coroutine remains in a yielded state during the switch. This is made |
150 | + * possible by QIOChannel's support for spurious coroutine re-entry in | 150 | + * possible by QIOChannel's support for spurious coroutine re-entry in |
151 | + * qio_channel_yield(). The coroutine will restart I/O when re-entered from the | 151 | + * qio_channel_yield(). The coroutine will restart I/O when re-entered from the |
152 | + * new AioContext. | 152 | + * new AioContext. |
153 | + */ | 153 | + */ |
154 | + | 154 | + |
155 | static void vmsg_close_fds(VhostUserMsg *vmsg) | 155 | static void vmsg_close_fds(VhostUserMsg *vmsg) |
156 | { | 156 | { |
157 | int i; | 157 | int i; |
158 | @@ -XXX,XX +XXX,XX @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) | 158 | @@ -XXX,XX +XXX,XX @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | -static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, | 162 | -static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, |
163 | - gpointer opaque); | 163 | - gpointer opaque); |
164 | - | 164 | - |
165 | -static void close_client(VuServer *server) | 165 | -static void close_client(VuServer *server) |
166 | -{ | 166 | -{ |
167 | - /* | 167 | - /* |
168 | - * Before closing the client | 168 | - * Before closing the client |
169 | - * | 169 | - * |
170 | - * 1. Let vu_client_trip stop processing new vhost-user msg | 170 | - * 1. Let vu_client_trip stop processing new vhost-user msg |
171 | - * | 171 | - * |
172 | - * 2. remove kick_handler | 172 | - * 2. remove kick_handler |
173 | - * | 173 | - * |
174 | - * 3. wait for the kick handler to be finished | 174 | - * 3. wait for the kick handler to be finished |
175 | - * | 175 | - * |
176 | - * 4. wait for the current vhost-user msg to be finished processing | 176 | - * 4. wait for the current vhost-user msg to be finished processing |
177 | - */ | 177 | - */ |
178 | - | 178 | - |
179 | - QIOChannelSocket *sioc = server->sioc; | 179 | - QIOChannelSocket *sioc = server->sioc; |
180 | - /* When this is set vu_client_trip will stop new processing vhost-user message */ | 180 | - /* When this is set vu_client_trip will stop new processing vhost-user message */ |
181 | - server->sioc = NULL; | 181 | - server->sioc = NULL; |
182 | - | 182 | - |
183 | - while (server->processing_msg) { | 183 | - while (server->processing_msg) { |
184 | - if (server->ioc->read_coroutine) { | 184 | - if (server->ioc->read_coroutine) { |
185 | - server->ioc->read_coroutine = NULL; | 185 | - server->ioc->read_coroutine = NULL; |
186 | - qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, NULL, | 186 | - qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, NULL, |
187 | - NULL, server->ioc); | 187 | - NULL, server->ioc); |
188 | - server->processing_msg = false; | 188 | - server->processing_msg = false; |
189 | - } | 189 | - } |
190 | - } | 190 | - } |
191 | - | 191 | - |
192 | - vu_deinit(&server->vu_dev); | 192 | - vu_deinit(&server->vu_dev); |
193 | - | 193 | - |
194 | - /* vu_deinit() should have called remove_watch() */ | 194 | - /* vu_deinit() should have called remove_watch() */ |
195 | - assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | 195 | - assert(QTAILQ_EMPTY(&server->vu_fd_watches)); |
196 | - | 196 | - |
197 | - object_unref(OBJECT(sioc)); | 197 | - object_unref(OBJECT(sioc)); |
198 | - object_unref(OBJECT(server->ioc)); | 198 | - object_unref(OBJECT(server->ioc)); |
199 | -} | 199 | -} |
200 | - | 200 | - |
201 | static void panic_cb(VuDev *vu_dev, const char *buf) | 201 | static void panic_cb(VuDev *vu_dev, const char *buf) |
202 | { | 202 | { |
203 | - VuServer *server = container_of(vu_dev, VuServer, vu_dev); | 203 | - VuServer *server = container_of(vu_dev, VuServer, vu_dev); |
204 | - | 204 | - |
205 | - /* avoid while loop in close_client */ | 205 | - /* avoid while loop in close_client */ |
206 | - server->processing_msg = false; | 206 | - server->processing_msg = false; |
207 | - | 207 | - |
208 | - if (buf) { | 208 | - if (buf) { |
209 | - error_report("vu_panic: %s", buf); | 209 | - error_report("vu_panic: %s", buf); |
210 | - } | 210 | - } |
211 | - | 211 | - |
212 | - if (server->sioc) { | 212 | - if (server->sioc) { |
213 | - close_client(server); | 213 | - close_client(server); |
214 | - } | 214 | - } |
215 | - | 215 | - |
216 | - /* | 216 | - /* |
217 | - * Set the callback function for network listener so another | 217 | - * Set the callback function for network listener so another |
218 | - * vhost-user client can connect to this server | 218 | - * vhost-user client can connect to this server |
219 | - */ | 219 | - */ |
220 | - qio_net_listener_set_client_func(server->listener, | 220 | - qio_net_listener_set_client_func(server->listener, |
221 | - vu_accept, | 221 | - vu_accept, |
222 | - server, | 222 | - server, |
223 | - NULL); | 223 | - NULL); |
224 | + error_report("vu_panic: %s", buf); | 224 | + error_report("vu_panic: %s", buf); |
225 | } | 225 | } |
226 | 226 | ||
227 | static bool coroutine_fn | 227 | static bool coroutine_fn |
228 | @@ -XXX,XX +XXX,XX @@ fail: | 228 | @@ -XXX,XX +XXX,XX @@ fail: |
229 | return false; | 229 | return false; |
230 | } | 230 | } |
231 | 231 | ||
232 | - | 232 | - |
233 | -static void vu_client_start(VuServer *server); | 233 | -static void vu_client_start(VuServer *server); |
234 | static coroutine_fn void vu_client_trip(void *opaque) | 234 | static coroutine_fn void vu_client_trip(void *opaque) |
235 | { | 235 | { |
236 | VuServer *server = opaque; | 236 | VuServer *server = opaque; |
237 | + VuDev *vu_dev = &server->vu_dev; | 237 | + VuDev *vu_dev = &server->vu_dev; |
238 | 238 | ||
239 | - while (!server->aio_context_changed && server->sioc) { | 239 | - while (!server->aio_context_changed && server->sioc) { |
240 | - server->processing_msg = true; | 240 | - server->processing_msg = true; |
241 | - vu_dispatch(&server->vu_dev); | 241 | - vu_dispatch(&server->vu_dev); |
242 | - server->processing_msg = false; | 242 | - server->processing_msg = false; |
243 | + while (!vu_dev->broken && vu_dispatch(vu_dev)) { | 243 | + while (!vu_dev->broken && vu_dispatch(vu_dev)) { |
244 | + /* Keep running */ | 244 | + /* Keep running */ |
245 | } | 245 | } |
246 | 246 | ||
247 | - if (server->aio_context_changed && server->sioc) { | 247 | - if (server->aio_context_changed && server->sioc) { |
248 | - server->aio_context_changed = false; | 248 | - server->aio_context_changed = false; |
249 | - vu_client_start(server); | 249 | - vu_client_start(server); |
250 | - } | 250 | - } |
251 | -} | 251 | -} |
252 | + vu_deinit(vu_dev); | 252 | + vu_deinit(vu_dev); |
253 | + | 253 | + |
254 | + /* vu_deinit() should have called remove_watch() */ | 254 | + /* vu_deinit() should have called remove_watch() */ |
255 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | 255 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); |
256 | + | 256 | + |
257 | + object_unref(OBJECT(server->sioc)); | 257 | + object_unref(OBJECT(server->sioc)); |
258 | + server->sioc = NULL; | 258 | + server->sioc = NULL; |
259 | 259 | ||
260 | -static void vu_client_start(VuServer *server) | 260 | -static void vu_client_start(VuServer *server) |
261 | -{ | 261 | -{ |
262 | - server->co_trip = qemu_coroutine_create(vu_client_trip, server); | 262 | - server->co_trip = qemu_coroutine_create(vu_client_trip, server); |
263 | - aio_co_enter(server->ctx, server->co_trip); | 263 | - aio_co_enter(server->ctx, server->co_trip); |
264 | + object_unref(OBJECT(server->ioc)); | 264 | + object_unref(OBJECT(server->ioc)); |
265 | + server->ioc = NULL; | 265 | + server->ioc = NULL; |
266 | + | 266 | + |
267 | + server->co_trip = NULL; | 267 | + server->co_trip = NULL; |
268 | + if (server->restart_listener_bh) { | 268 | + if (server->restart_listener_bh) { |
269 | + qemu_bh_schedule(server->restart_listener_bh); | 269 | + qemu_bh_schedule(server->restart_listener_bh); |
270 | + } | 270 | + } |
271 | + aio_wait_kick(); | 271 | + aio_wait_kick(); |
272 | } | 272 | } |
273 | 273 | ||
274 | /* | 274 | /* |
275 | @@ -XXX,XX +XXX,XX @@ static void vu_client_start(VuServer *server) | 275 | @@ -XXX,XX +XXX,XX @@ static void vu_client_start(VuServer *server) |
276 | static void kick_handler(void *opaque) | 276 | static void kick_handler(void *opaque) |
277 | { | 277 | { |
278 | VuFdWatch *vu_fd_watch = opaque; | 278 | VuFdWatch *vu_fd_watch = opaque; |
279 | - vu_fd_watch->processing = true; | 279 | - vu_fd_watch->processing = true; |
280 | - vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); | 280 | - vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); |
281 | - vu_fd_watch->processing = false; | 281 | - vu_fd_watch->processing = false; |
282 | + VuDev *vu_dev = vu_fd_watch->vu_dev; | 282 | + VuDev *vu_dev = vu_fd_watch->vu_dev; |
283 | + | 283 | + |
284 | + vu_fd_watch->cb(vu_dev, 0, vu_fd_watch->pvt); | 284 | + vu_fd_watch->cb(vu_dev, 0, vu_fd_watch->pvt); |
285 | + | 285 | + |
286 | + /* Stop vu_client_trip() if an error occurred in vu_fd_watch->cb() */ | 286 | + /* Stop vu_client_trip() if an error occurred in vu_fd_watch->cb() */ |
287 | + if (vu_dev->broken) { | 287 | + if (vu_dev->broken) { |
288 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | 288 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); |
289 | + | 289 | + |
290 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); | 290 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); |
291 | + } | 291 | + } |
292 | } | 292 | } |
293 | 293 | ||
294 | - | 294 | - |
295 | static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) | 295 | static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) |
296 | { | 296 | { |
297 | 297 | ||
298 | @@ -XXX,XX +XXX,XX @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, | 298 | @@ -XXX,XX +XXX,XX @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, |
299 | qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); | 299 | qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); |
300 | server->ioc = QIO_CHANNEL(sioc); | 300 | server->ioc = QIO_CHANNEL(sioc); |
301 | object_ref(OBJECT(server->ioc)); | 301 | object_ref(OBJECT(server->ioc)); |
302 | - qio_channel_attach_aio_context(server->ioc, server->ctx); | 302 | - qio_channel_attach_aio_context(server->ioc, server->ctx); |
303 | + | 303 | + |
304 | + /* TODO vu_message_write() spins if non-blocking! */ | 304 | + /* TODO vu_message_write() spins if non-blocking! */ |
305 | qio_channel_set_blocking(server->ioc, false, NULL); | 305 | qio_channel_set_blocking(server->ioc, false, NULL); |
306 | - vu_client_start(server); | 306 | - vu_client_start(server); |
307 | + | 307 | + |
308 | + server->co_trip = qemu_coroutine_create(vu_client_trip, server); | 308 | + server->co_trip = qemu_coroutine_create(vu_client_trip, server); |
309 | + | 309 | + |
310 | + aio_context_acquire(server->ctx); | 310 | + aio_context_acquire(server->ctx); |
311 | + vhost_user_server_attach_aio_context(server, server->ctx); | 311 | + vhost_user_server_attach_aio_context(server, server->ctx); |
312 | + aio_context_release(server->ctx); | 312 | + aio_context_release(server->ctx); |
313 | } | 313 | } |
314 | 314 | ||
315 | - | 315 | - |
316 | void vhost_user_server_stop(VuServer *server) | 316 | void vhost_user_server_stop(VuServer *server) |
317 | { | 317 | { |
318 | + aio_context_acquire(server->ctx); | 318 | + aio_context_acquire(server->ctx); |
319 | + | 319 | + |
320 | + qemu_bh_delete(server->restart_listener_bh); | 320 | + qemu_bh_delete(server->restart_listener_bh); |
321 | + server->restart_listener_bh = NULL; | 321 | + server->restart_listener_bh = NULL; |
322 | + | 322 | + |
323 | if (server->sioc) { | 323 | if (server->sioc) { |
324 | - close_client(server); | 324 | - close_client(server); |
325 | + VuFdWatch *vu_fd_watch; | 325 | + VuFdWatch *vu_fd_watch; |
326 | + | 326 | + |
327 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { | 327 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { |
328 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, | 328 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, |
329 | + NULL, NULL, NULL, vu_fd_watch); | 329 | + NULL, NULL, NULL, vu_fd_watch); |
330 | + } | 330 | + } |
331 | + | 331 | + |
332 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); | 332 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); |
333 | + | 333 | + |
334 | + AIO_WAIT_WHILE(server->ctx, server->co_trip); | 334 | + AIO_WAIT_WHILE(server->ctx, server->co_trip); |
335 | } | 335 | } |
336 | 336 | ||
337 | + aio_context_release(server->ctx); | 337 | + aio_context_release(server->ctx); |
338 | + | 338 | + |
339 | if (server->listener) { | 339 | if (server->listener) { |
340 | qio_net_listener_disconnect(server->listener); | 340 | qio_net_listener_disconnect(server->listener); |
341 | object_unref(OBJECT(server->listener)); | 341 | object_unref(OBJECT(server->listener)); |
342 | } | 342 | } |
343 | +} | 343 | +} |
344 | + | 344 | + |
345 | +/* | 345 | +/* |
346 | + * Allow the next client to connect to the server. Called from a BH in the main | 346 | + * Allow the next client to connect to the server. Called from a BH in the main |
347 | + * loop. | 347 | + * loop. |
348 | + */ | 348 | + */ |
349 | +static void restart_listener_bh(void *opaque) | 349 | +static void restart_listener_bh(void *opaque) |
350 | +{ | 350 | +{ |
351 | + VuServer *server = opaque; | 351 | + VuServer *server = opaque; |
352 | 352 | ||
353 | + qio_net_listener_set_client_func(server->listener, vu_accept, server, | 353 | + qio_net_listener_set_client_func(server->listener, vu_accept, server, |
354 | + NULL); | 354 | + NULL); |
355 | } | 355 | } |
356 | 356 | ||
357 | -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) | 357 | -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) |
358 | +/* Called with ctx acquired */ | 358 | +/* Called with ctx acquired */ |
359 | +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx) | 359 | +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx) |
360 | { | 360 | { |
361 | - VuFdWatch *vu_fd_watch, *next; | 361 | - VuFdWatch *vu_fd_watch, *next; |
362 | - void *opaque = NULL; | 362 | - void *opaque = NULL; |
363 | - IOHandler *io_read = NULL; | 363 | - IOHandler *io_read = NULL; |
364 | - bool attach; | 364 | - bool attach; |
365 | + VuFdWatch *vu_fd_watch; | 365 | + VuFdWatch *vu_fd_watch; |
366 | 366 | ||
367 | - server->ctx = ctx ? ctx : qemu_get_aio_context(); | 367 | - server->ctx = ctx ? ctx : qemu_get_aio_context(); |
368 | + server->ctx = ctx; | 368 | + server->ctx = ctx; |
369 | 369 | ||
370 | if (!server->sioc) { | 370 | if (!server->sioc) { |
371 | - /* not yet serving any client*/ | 371 | - /* not yet serving any client*/ |
372 | return; | 372 | return; |
373 | } | 373 | } |
374 | 374 | ||
375 | - if (ctx) { | 375 | - if (ctx) { |
376 | - qio_channel_attach_aio_context(server->ioc, ctx); | 376 | - qio_channel_attach_aio_context(server->ioc, ctx); |
377 | - server->aio_context_changed = true; | 377 | - server->aio_context_changed = true; |
378 | - io_read = kick_handler; | 378 | - io_read = kick_handler; |
379 | - attach = true; | 379 | - attach = true; |
380 | - } else { | 380 | - } else { |
381 | + qio_channel_attach_aio_context(server->ioc, ctx); | 381 | + qio_channel_attach_aio_context(server->ioc, ctx); |
382 | + | 382 | + |
383 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { | 383 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { |
384 | + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, | 384 | + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, kick_handler, NULL, |
385 | + NULL, vu_fd_watch); | 385 | + NULL, vu_fd_watch); |
386 | + } | 386 | + } |
387 | + | 387 | + |
388 | + aio_co_schedule(ctx, server->co_trip); | 388 | + aio_co_schedule(ctx, server->co_trip); |
389 | +} | 389 | +} |
390 | + | 390 | + |
391 | +/* Called with server->ctx acquired */ | 391 | +/* Called with server->ctx acquired */ |
392 | +void vhost_user_server_detach_aio_context(VuServer *server) | 392 | +void vhost_user_server_detach_aio_context(VuServer *server) |
393 | +{ | 393 | +{ |
394 | + if (server->sioc) { | 394 | + if (server->sioc) { |
395 | + VuFdWatch *vu_fd_watch; | 395 | + VuFdWatch *vu_fd_watch; |
396 | + | 396 | + |
397 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { | 397 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { |
398 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, | 398 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, |
399 | + NULL, NULL, NULL, vu_fd_watch); | 399 | + NULL, NULL, NULL, vu_fd_watch); |
400 | + } | 400 | + } |
401 | + | 401 | + |
402 | qio_channel_detach_aio_context(server->ioc); | 402 | qio_channel_detach_aio_context(server->ioc); |
403 | - /* server->ioc->ctx keeps the old AioConext */ | 403 | - /* server->ioc->ctx keeps the old AioConext */ |
404 | - ctx = server->ioc->ctx; | 404 | - ctx = server->ioc->ctx; |
405 | - attach = false; | 405 | - attach = false; |
406 | } | 406 | } |
407 | 407 | ||
408 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | 408 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { |
409 | - if (vu_fd_watch->cb) { | 409 | - if (vu_fd_watch->cb) { |
410 | - opaque = attach ? vu_fd_watch : NULL; | 410 | - opaque = attach ? vu_fd_watch : NULL; |
411 | - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, | 411 | - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, |
412 | - io_read, NULL, NULL, | 412 | - io_read, NULL, NULL, |
413 | - opaque); | 413 | - opaque); |
414 | - } | 414 | - } |
415 | - } | 415 | - } |
416 | + server->ctx = NULL; | 416 | + server->ctx = NULL; |
417 | } | 417 | } |
418 | 418 | ||
419 | - | 419 | - |
420 | bool vhost_user_server_start(VuServer *server, | 420 | bool vhost_user_server_start(VuServer *server, |
421 | SocketAddress *socket_addr, | 421 | SocketAddress *socket_addr, |
422 | AioContext *ctx, | 422 | AioContext *ctx, |
423 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 423 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
424 | const VuDevIface *vu_iface, | 424 | const VuDevIface *vu_iface, |
425 | Error **errp) | 425 | Error **errp) |
426 | { | 426 | { |
427 | + QEMUBH *bh; | 427 | + QEMUBH *bh; |
428 | QIONetListener *listener = qio_net_listener_new(); | 428 | QIONetListener *listener = qio_net_listener_new(); |
429 | if (qio_net_listener_open_sync(listener, socket_addr, 1, | 429 | if (qio_net_listener_open_sync(listener, socket_addr, 1, |
430 | errp) < 0) { | 430 | errp) < 0) { |
431 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 431 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
432 | return false; | 432 | return false; |
433 | } | 433 | } |
434 | 434 | ||
435 | + bh = qemu_bh_new(restart_listener_bh, server); | 435 | + bh = qemu_bh_new(restart_listener_bh, server); |
436 | + | 436 | + |
437 | /* zero out unspecified fields */ | 437 | /* zero out unspecified fields */ |
438 | *server = (VuServer) { | 438 | *server = (VuServer) { |
439 | .listener = listener, | 439 | .listener = listener, |
440 | + .restart_listener_bh = bh, | 440 | + .restart_listener_bh = bh, |
441 | .vu_iface = vu_iface, | 441 | .vu_iface = vu_iface, |
442 | .max_queues = max_queues, | 442 | .max_queues = max_queues, |
443 | .ctx = ctx, | 443 | .ctx = ctx, |
444 | -- | 444 | -- |
445 | 2.26.2 | 445 | 2.26.2 |
446 | 446 | diff view generated by jsdifflib |
1 | Propagate the flush return value since errors are possible. | 1 | Propagate the flush return value since errors are possible. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Message-id: 20200924151549.913737-11-stefanha@redhat.com | 4 | Message-id: 20200924151549.913737-11-stefanha@redhat.com |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | --- | 6 | --- |
7 | block/export/vhost-user-blk-server.c | 11 +++++++---- | 7 | block/export/vhost-user-blk-server.c | 11 +++++++---- |
8 | 1 file changed, 7 insertions(+), 4 deletions(-) | 8 | 1 file changed, 7 insertions(+), 4 deletions(-) |
9 | 9 | ||
10 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 10 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
11 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/block/export/vhost-user-blk-server.c | 12 | --- a/block/export/vhost-user-blk-server.c |
13 | +++ b/block/export/vhost-user-blk-server.c | 13 | +++ b/block/export/vhost-user-blk-server.c |
14 | @@ -XXX,XX +XXX,XX @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, | 14 | @@ -XXX,XX +XXX,XX @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, |
15 | return -EINVAL; | 15 | return -EINVAL; |
16 | } | 16 | } |
17 | 17 | ||
18 | -static void coroutine_fn vu_block_flush(VuBlockReq *req) | 18 | -static void coroutine_fn vu_block_flush(VuBlockReq *req) |
19 | +static int coroutine_fn vu_block_flush(VuBlockReq *req) | 19 | +static int coroutine_fn vu_block_flush(VuBlockReq *req) |
20 | { | 20 | { |
21 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | 21 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); |
22 | BlockBackend *backend = vdev_blk->backend; | 22 | BlockBackend *backend = vdev_blk->backend; |
23 | - blk_co_flush(backend); | 23 | - blk_co_flush(backend); |
24 | + return blk_co_flush(backend); | 24 | + return blk_co_flush(backend); |
25 | } | 25 | } |
26 | 26 | ||
27 | static void coroutine_fn vu_block_virtio_process_req(void *opaque) | 27 | static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
28 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | 28 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
29 | break; | 29 | break; |
30 | } | 30 | } |
31 | case VIRTIO_BLK_T_FLUSH: | 31 | case VIRTIO_BLK_T_FLUSH: |
32 | - vu_block_flush(req); | 32 | - vu_block_flush(req); |
33 | - req->in->status = VIRTIO_BLK_S_OK; | 33 | - req->in->status = VIRTIO_BLK_S_OK; |
34 | + if (vu_block_flush(req) == 0) { | 34 | + if (vu_block_flush(req) == 0) { |
35 | + req->in->status = VIRTIO_BLK_S_OK; | 35 | + req->in->status = VIRTIO_BLK_S_OK; |
36 | + } else { | 36 | + } else { |
37 | + req->in->status = VIRTIO_BLK_S_IOERR; | 37 | + req->in->status = VIRTIO_BLK_S_IOERR; |
38 | + } | 38 | + } |
39 | break; | 39 | break; |
40 | case VIRTIO_BLK_T_GET_ID: { | 40 | case VIRTIO_BLK_T_GET_ID: { |
41 | size_t size = MIN(iov_size(&elem->in_sg[0], in_num), | 41 | size_t size = MIN(iov_size(&elem->in_sg[0], in_num), |
42 | -- | 42 | -- |
43 | 2.26.2 | 43 | 2.26.2 |
44 | 44 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
29 | QAPI 'features' syntax can be used to advertize them. | 29 | QAPI 'features' syntax can be used to advertize them. |
30 | 30 | ||
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
32 | Acked-by: Markus Armbruster <armbru@redhat.com> | 32 | Acked-by: Markus Armbruster <armbru@redhat.com> |
33 | Message-id: 20200924151549.913737-12-stefanha@redhat.com | 33 | Message-id: 20200924151549.913737-12-stefanha@redhat.com |
34 | [Skip test on big-endian host architectures because this device doesn't | ||
35 | support them yet (as already mentioned in a code comment). | ||
36 | --Stefan] | ||
34 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 37 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
35 | --- | 38 | --- |
36 | qapi/block-export.json | 21 +- | 39 | qapi/block-export.json | 21 +- |
37 | block/export/vhost-user-blk-server.h | 23 +- | 40 | block/export/vhost-user-blk-server.h | 23 +- |
38 | block/export/export.c | 6 + | 41 | block/export/export.c | 6 + |
39 | block/export/vhost-user-blk-server.c | 452 +++++++-------------------- | 42 | block/export/vhost-user-blk-server.c | 452 +++++++-------------------- |
40 | tests/qtest/vhost-user-blk-test.c | 2 +- | ||
41 | util/vhost-user-server.c | 10 +- | 43 | util/vhost-user-server.c | 10 +- |
42 | block/export/meson.build | 1 + | 44 | block/export/meson.build | 1 + |
43 | block/meson.build | 1 - | 45 | block/meson.build | 1 - |
44 | 8 files changed, 157 insertions(+), 359 deletions(-) | 46 | 7 files changed, 156 insertions(+), 358 deletions(-) |
45 | 47 | ||
46 | diff --git a/qapi/block-export.json b/qapi/block-export.json | 48 | diff --git a/qapi/block-export.json b/qapi/block-export.json |
47 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/qapi/block-export.json | 50 | --- a/qapi/block-export.json |
49 | +++ b/qapi/block-export.json | 51 | +++ b/qapi/block-export.json |
... | ... | ||
810 | -{ | 812 | -{ |
811 | - type_register_static(&vhost_user_blk_server_info); | 813 | - type_register_static(&vhost_user_blk_server_info); |
812 | -} | 814 | -} |
813 | - | 815 | - |
814 | -type_init(vhost_user_blk_server_register_types) | 816 | -type_init(vhost_user_blk_server_register_types) |
815 | diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c | ||
816 | index XXXXXXX..XXXXXXX 100644 | ||
817 | --- a/tests/qtest/vhost-user-blk-test.c | ||
818 | +++ b/tests/qtest/vhost-user-blk-test.c | ||
819 | @@ -XXX,XX +XXX,XX @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) | ||
820 | img_path = drive_create(); | ||
821 | g_string_append_printf(storage_daemon_command, | ||
822 | "--blockdev driver=file,node-name=disk%d,filename=%s " | ||
823 | - "--object vhost-user-blk-server,id=disk%d,unix-socket=%s," | ||
824 | + "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," | ||
825 | "node-name=disk%i,writable=on ", | ||
826 | i, img_path, i, sock_path, i); | ||
827 | |||
828 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | 817 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c |
829 | index XXXXXXX..XXXXXXX 100644 | 818 | index XXXXXXX..XXXXXXX 100644 |
830 | --- a/util/vhost-user-server.c | 819 | --- a/util/vhost-user-server.c |
831 | +++ b/util/vhost-user-server.c | 820 | +++ b/util/vhost-user-server.c |
832 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | 821 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
21 | S: Maintained | 21 | S: Maintained |
22 | F: block/export/vhost-user-blk-server.c | 22 | F: block/export/vhost-user-blk-server.c |
23 | -F: util/vhost-user-server.c | 23 | -F: util/vhost-user-server.c |
24 | +F: block/export/vhost-user-blk-server.h | 24 | +F: block/export/vhost-user-blk-server.h |
25 | +F: include/qemu/vhost-user-server.h | 25 | +F: include/qemu/vhost-user-server.h |
26 | F: tests/qtest/vhost-user-blk-test.c | ||
27 | F: tests/qtest/libqos/vhost-user-blk.c | 26 | F: tests/qtest/libqos/vhost-user-blk.c |
28 | +F: util/vhost-user-server.c | 27 | +F: util/vhost-user-server.c |
29 | 28 | ||
30 | Replication | 29 | Replication |
31 | M: Wen Congyang <wencongyang2@huawei.com> | 30 | M: Wen Congyang <wencongyang2@huawei.com> |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
4 | Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the | 4 | Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the |
5 | vhost-user tools (vhost-user-gpu, etc) do. | 5 | vhost-user tools (vhost-user-gpu, etc) do. |
6 | 6 | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Message-id: 20200924151549.913737-14-stefanha@redhat.com | 8 | Message-id: 20200924151549.913737-14-stefanha@redhat.com |
9 | [Added CONFIG_LINUX again because libvhost-user doesn't build on macOS. | ||
10 | --Stefan] | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | --- | 12 | --- |
11 | block/export/export.c | 8 ++++---- | 13 | block/export/export.c | 8 ++++---- |
12 | block/export/meson.build | 2 +- | 14 | block/export/meson.build | 2 +- |
13 | contrib/libvhost-user/meson.build | 1 + | 15 | contrib/libvhost-user/meson.build | 1 + |
14 | meson.build | 6 +++++- | 16 | meson.build | 6 +++++- |
15 | tests/qtest/meson.build | 2 +- | ||
16 | util/meson.build | 4 +++- | 17 | util/meson.build | 4 +++- |
17 | 6 files changed, 15 insertions(+), 8 deletions(-) | 18 | 5 files changed, 14 insertions(+), 7 deletions(-) |
18 | 19 | ||
19 | diff --git a/block/export/export.c b/block/export/export.c | 20 | diff --git a/block/export/export.c b/block/export/export.c |
20 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/block/export/export.c | 22 | --- a/block/export/export.c |
22 | +++ b/block/export/export.c | 23 | +++ b/block/export/export.c |
... | ... | ||
47 | --- a/block/export/meson.build | 48 | --- a/block/export/meson.build |
48 | +++ b/block/export/meson.build | 49 | +++ b/block/export/meson.build |
49 | @@ -XXX,XX +XXX,XX @@ | 50 | @@ -XXX,XX +XXX,XX @@ |
50 | block_ss.add(files('export.c')) | 51 | block_ss.add(files('export.c')) |
51 | -block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c')) | 52 | -block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c')) |
52 | +block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) | 53 | +block_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('vhost-user-blk-server.c')) |
53 | diff --git a/contrib/libvhost-user/meson.build b/contrib/libvhost-user/meson.build | 54 | diff --git a/contrib/libvhost-user/meson.build b/contrib/libvhost-user/meson.build |
54 | index XXXXXXX..XXXXXXX 100644 | 55 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/contrib/libvhost-user/meson.build | 56 | --- a/contrib/libvhost-user/meson.build |
56 | +++ b/contrib/libvhost-user/meson.build | 57 | +++ b/contrib/libvhost-user/meson.build |
57 | @@ -XXX,XX +XXX,XX @@ | 58 | @@ -XXX,XX +XXX,XX @@ |
... | ... | ||
81 | if 'CONFIG_VHOST_USER' in config_host | 82 | if 'CONFIG_VHOST_USER' in config_host |
82 | - subdir('contrib/libvhost-user') | 83 | - subdir('contrib/libvhost-user') |
83 | subdir('contrib/vhost-user-blk') | 84 | subdir('contrib/vhost-user-blk') |
84 | subdir('contrib/vhost-user-gpu') | 85 | subdir('contrib/vhost-user-gpu') |
85 | subdir('contrib/vhost-user-input') | 86 | subdir('contrib/vhost-user-input') |
86 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/tests/qtest/meson.build | ||
89 | +++ b/tests/qtest/meson.build | ||
90 | @@ -XXX,XX +XXX,XX @@ qos_test_ss.add( | ||
91 | ) | ||
92 | qos_test_ss.add(when: 'CONFIG_VIRTFS', if_true: files('virtio-9p-test.c')) | ||
93 | qos_test_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-test.c')) | ||
94 | -qos_test_ss.add(when: ['CONFIG_LINUX', 'CONFIG_TOOLS'], if_true: files('vhost-user-blk-test.c')) | ||
95 | +qos_test_ss.add(when: ['CONFIG_VHOST_USER', 'CONFIG_TOOLS'], if_true: files('vhost-user-blk-test.c')) | ||
96 | |||
97 | extra_qtest_deps = { | ||
98 | 'bios-tables-test': [io], | ||
99 | diff --git a/util/meson.build b/util/meson.build | 87 | diff --git a/util/meson.build b/util/meson.build |
100 | index XXXXXXX..XXXXXXX 100644 | 88 | index XXXXXXX..XXXXXXX 100644 |
101 | --- a/util/meson.build | 89 | --- a/util/meson.build |
102 | +++ b/util/meson.build | 90 | +++ b/util/meson.build |
103 | @@ -XXX,XX +XXX,XX @@ if have_block | 91 | @@ -XXX,XX +XXX,XX @@ if have_block |
104 | util_ss.add(files('main-loop.c')) | 92 | util_ss.add(files('main-loop.c')) |
105 | util_ss.add(files('nvdimm-utils.c')) | 93 | util_ss.add(files('nvdimm-utils.c')) |
106 | util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) | 94 | util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) |
107 | - util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) | 95 | - util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) |
108 | + util_ss.add(when: 'CONFIG_VHOST_USER', if_true: [ | 96 | + util_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: [ |
109 | + files('vhost-user-server.c'), vhost_user | 97 | + files('vhost-user-server.c'), vhost_user |
110 | + ]) | 98 | + ]) |
111 | util_ss.add(files('block-helpers.c')) | 99 | util_ss.add(files('block-helpers.c')) |
112 | util_ss.add(files('qemu-coroutine-sleep.c')) | 100 | util_ss.add(files('qemu-coroutine-sleep.c')) |
113 | util_ss.add(files('qemu-co-shared-resource.c')) | 101 | util_ss.add(files('qemu-co-shared-resource.c')) |
114 | -- | 102 | -- |
115 | 2.26.2 | 103 | 2.26.2 |
116 | 104 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
13 | diff --git a/meson.build b/meson.build | 13 | diff --git a/meson.build b/meson.build |
14 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/meson.build | 15 | --- a/meson.build |
16 | +++ b/meson.build | 16 | +++ b/meson.build |
17 | @@ -XXX,XX +XXX,XX @@ blockdev_ss.add(files( | 17 | @@ -XXX,XX +XXX,XX @@ blockdev_ss.add(files( |
18 | # os-win32.c does not | ||
18 | blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c')) | 19 | blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c')) |
19 | softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')]) | 20 | softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')]) |
20 | |||
21 | -softmmu_ss.add_all(blockdev_ss) | 21 | -softmmu_ss.add_all(blockdev_ss) |
22 | softmmu_ss.add(files( | 22 | |
23 | 'bootdevice.c', | 23 | common_ss.add(files('cpus-common.c')) |
24 | 'dma-helpers.c', | 24 | |
25 | @@ -XXX,XX +XXX,XX @@ block = declare_dependency(link_whole: [libblock], | 25 | @@ -XXX,XX +XXX,XX @@ block = declare_dependency(link_whole: [libblock], |
26 | link_args: '@block.syms', | 26 | link_args: '@block.syms', |
27 | dependencies: [crypto, io]) | 27 | dependencies: [crypto, io]) |
28 | 28 | ||
29 | +blockdev_ss = blockdev_ss.apply(config_host, strict: false) | 29 | +blockdev_ss = blockdev_ss.apply(config_host, strict: false) |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
18 | Message-id: 20200929125516.186715-4-stefanha@redhat.com | 18 | Message-id: 20200929125516.186715-4-stefanha@redhat.com |
19 | [Fixed s/ndb/nbd/ typo in commit description as suggested by Eric Blake | 19 | [Fixed s/ndb/nbd/ typo in commit description as suggested by Eric Blake |
20 | --Stefan] | 20 | --Stefan] |
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | --- | 22 | --- |
23 | qemu-nbd.c | 25 +++++++++---------------- | 23 | qemu-nbd.c | 21 ++++++++------------- |
24 | stubs/blk-exp-close-all.c | 7 +++++++ | 24 | stubs/blk-exp-close-all.c | 7 +++++++ |
25 | block/export/meson.build | 4 ++-- | 25 | block/export/meson.build | 4 ++-- |
26 | meson.build | 4 ++-- | 26 | meson.build | 4 ++-- |
27 | nbd/meson.build | 2 ++ | 27 | nbd/meson.build | 2 ++ |
28 | stubs/meson.build | 1 + | 28 | stubs/meson.build | 1 + |
29 | 6 files changed, 23 insertions(+), 20 deletions(-) | 29 | 6 files changed, 22 insertions(+), 17 deletions(-) |
30 | create mode 100644 stubs/blk-exp-close-all.c | 30 | create mode 100644 stubs/blk-exp-close-all.c |
31 | 31 | ||
32 | diff --git a/qemu-nbd.c b/qemu-nbd.c | 32 | diff --git a/qemu-nbd.c b/qemu-nbd.c |
33 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/qemu-nbd.c | 34 | --- a/qemu-nbd.c |
... | ... | ||
40 | +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ | 40 | +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ |
41 | #include "block/block_int.h" | 41 | #include "block/block_int.h" |
42 | #include "block/nbd.h" | 42 | #include "block/nbd.h" |
43 | #include "qemu/main-loop.h" | 43 | #include "qemu/main-loop.h" |
44 | @@ -XXX,XX +XXX,XX @@ QEMU_COPYRIGHT "\n" | 44 | @@ -XXX,XX +XXX,XX @@ QEMU_COPYRIGHT "\n" |
45 | , name); | ||
46 | } | 45 | } |
47 | 46 | ||
48 | -#ifdef CONFIG_POSIX | 47 | #ifdef CONFIG_POSIX |
49 | -static void termsig_handler(int signum) | 48 | -static void termsig_handler(int signum) |
50 | +#if CONFIG_POSIX | ||
51 | +/* | 49 | +/* |
52 | + * The client thread uses SIGTERM to interrupt the server. A signal | 50 | + * The client thread uses SIGTERM to interrupt the server. A signal |
53 | + * handler ensures that "qemu-nbd -v -c" exits with a nice status code. | 51 | + * handler ensures that "qemu-nbd -v -c" exits with a nice status code. |
54 | + */ | 52 | + */ |
55 | +void qemu_system_killed(int signum, pid_t pid) | 53 | +void qemu_system_killed(int signum, pid_t pid) |
56 | { | 54 | { |
57 | qatomic_cmpxchg(&state, RUNNING, TERMINATE); | 55 | qatomic_cmpxchg(&state, RUNNING, TERMINATE); |
58 | qemu_notify_event(); | 56 | qemu_notify_event(); |
59 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | 57 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
60 | const char *pid_file_name = NULL; | ||
61 | BlockExportOptions *export_opts; | 58 | BlockExportOptions *export_opts; |
62 | 59 | ||
63 | -#ifdef CONFIG_POSIX | 60 | #ifdef CONFIG_POSIX |
64 | - /* | 61 | - /* |
65 | - * Exit gracefully on various signals, which includes SIGTERM used | 62 | - * Exit gracefully on various signals, which includes SIGTERM used |
66 | - * by 'qemu-nbd -v -c'. | 63 | - * by 'qemu-nbd -v -c'. |
67 | - */ | 64 | - */ |
68 | - struct sigaction sa_sigterm; | 65 | - struct sigaction sa_sigterm; |
... | ... | ||
71 | - sigaction(SIGTERM, &sa_sigterm, NULL); | 68 | - sigaction(SIGTERM, &sa_sigterm, NULL); |
72 | - sigaction(SIGINT, &sa_sigterm, NULL); | 69 | - sigaction(SIGINT, &sa_sigterm, NULL); |
73 | - sigaction(SIGHUP, &sa_sigterm, NULL); | 70 | - sigaction(SIGHUP, &sa_sigterm, NULL); |
74 | - | 71 | - |
75 | - signal(SIGPIPE, SIG_IGN); | 72 | - signal(SIGPIPE, SIG_IGN); |
76 | -#endif | ||
77 | + os_setup_early_signal_handling(); | 73 | + os_setup_early_signal_handling(); |
78 | + os_setup_signal_handling(); | 74 | + os_setup_signal_handling(); |
75 | #endif | ||
79 | 76 | ||
80 | socket_init(); | 77 | socket_init(); |
81 | error_init(argv[0]); | ||
82 | diff --git a/stubs/blk-exp-close-all.c b/stubs/blk-exp-close-all.c | 78 | diff --git a/stubs/blk-exp-close-all.c b/stubs/blk-exp-close-all.c |
83 | new file mode 100644 | 79 | new file mode 100644 |
84 | index XXXXXXX..XXXXXXX | 80 | index XXXXXXX..XXXXXXX |
85 | --- /dev/null | 81 | --- /dev/null |
86 | +++ b/stubs/blk-exp-close-all.c | 82 | +++ b/stubs/blk-exp-close-all.c |
... | ... | ||
96 | index XXXXXXX..XXXXXXX 100644 | 92 | index XXXXXXX..XXXXXXX 100644 |
97 | --- a/block/export/meson.build | 93 | --- a/block/export/meson.build |
98 | +++ b/block/export/meson.build | 94 | +++ b/block/export/meson.build |
99 | @@ -XXX,XX +XXX,XX @@ | 95 | @@ -XXX,XX +XXX,XX @@ |
100 | -block_ss.add(files('export.c')) | 96 | -block_ss.add(files('export.c')) |
101 | -block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) | 97 | -block_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('vhost-user-blk-server.c')) |
102 | +blockdev_ss.add(files('export.c')) | 98 | +blockdev_ss.add(files('export.c')) |
103 | +blockdev_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) | 99 | +blockdev_ss.add(when: ['CONFIG_LINUX', 'CONFIG_VHOST_USER'], if_true: files('vhost-user-blk-server.c')) |
104 | diff --git a/meson.build b/meson.build | 100 | diff --git a/meson.build b/meson.build |
105 | index XXXXXXX..XXXXXXX 100644 | 101 | index XXXXXXX..XXXXXXX 100644 |
106 | --- a/meson.build | 102 | --- a/meson.build |
107 | +++ b/meson.build | 103 | +++ b/meson.build |
108 | @@ -XXX,XX +XXX,XX @@ subdir('dump') | 104 | @@ -XXX,XX +XXX,XX @@ subdir('dump') |
... | ... | diff view generated by jsdifflib |
1 | Make it possible to specify the iothread where the export will run. By | 1 | Make it possible to specify the iothread where the export will run. By |
---|---|---|---|
2 | default the block node can be moved to other AioContexts later and the | 2 | default the block node can be moved to other AioContexts later and the |
3 | export will follow. The fixed-iothread option forces strict behavior | 3 | export will follow. The fixed-iothread option forces strict behavior |
4 | that prevents changing AioContext while the export is active. See the | 4 | that prevents changing AioContext while the export is active. See the |
5 | QAPI docs for details. | 5 | QAPI docs for details. |
6 | 6 | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Message-id: 20200929125516.186715-5-stefanha@redhat.com | 8 | Message-id: 20200929125516.186715-5-stefanha@redhat.com |
9 | [Fix stray '#' character in block-export.json and add missing "(since: | 9 | [Fix stray '#' character in block-export.json and add missing "(since: |
10 | 5.2)" as suggested by Eric Blake. | 10 | 5.2)" as suggested by Eric Blake. |
11 | --Stefan] | 11 | --Stefan] |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 13 | --- |
14 | qapi/block-export.json | 11 ++++++++++ | 14 | qapi/block-export.json | 11 ++++++++++ |
15 | block/export/export.c | 31 +++++++++++++++++++++++++++- | 15 | block/export/export.c | 31 +++++++++++++++++++++++++++- |
16 | block/export/vhost-user-blk-server.c | 5 ++++- | 16 | block/export/vhost-user-blk-server.c | 5 ++++- |
17 | nbd/server.c | 2 -- | 17 | nbd/server.c | 2 -- |
18 | 4 files changed, 45 insertions(+), 4 deletions(-) | 18 | 4 files changed, 45 insertions(+), 4 deletions(-) |
19 | 19 | ||
20 | diff --git a/qapi/block-export.json b/qapi/block-export.json | 20 | diff --git a/qapi/block-export.json b/qapi/block-export.json |
21 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/qapi/block-export.json | 22 | --- a/qapi/block-export.json |
23 | +++ b/qapi/block-export.json | 23 | +++ b/qapi/block-export.json |
24 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
25 | # export before completion is signalled. (since: 5.2; | 25 | # export before completion is signalled. (since: 5.2; |
26 | # default: false) | 26 | # default: false) |
27 | # | 27 | # |
28 | +# @iothread: The name of the iothread object where the export will run. The | 28 | +# @iothread: The name of the iothread object where the export will run. The |
29 | +# default is to use the thread currently associated with the | 29 | +# default is to use the thread currently associated with the |
30 | +# block node. (since: 5.2) | 30 | +# block node. (since: 5.2) |
31 | +# | 31 | +# |
32 | +# @fixed-iothread: True prevents the block node from being moved to another | 32 | +# @fixed-iothread: True prevents the block node from being moved to another |
33 | +# thread while the export is active. If true and @iothread is | 33 | +# thread while the export is active. If true and @iothread is |
34 | +# given, export creation fails if the block node cannot be | 34 | +# given, export creation fails if the block node cannot be |
35 | +# moved to the iothread. The default is false. (since: 5.2) | 35 | +# moved to the iothread. The default is false. (since: 5.2) |
36 | +# | 36 | +# |
37 | # Since: 4.2 | 37 | # Since: 4.2 |
38 | ## | 38 | ## |
39 | { 'union': 'BlockExportOptions', | 39 | { 'union': 'BlockExportOptions', |
40 | 'base': { 'type': 'BlockExportType', | 40 | 'base': { 'type': 'BlockExportType', |
41 | 'id': 'str', | 41 | 'id': 'str', |
42 | + '*fixed-iothread': 'bool', | 42 | + '*fixed-iothread': 'bool', |
43 | + '*iothread': 'str', | 43 | + '*iothread': 'str', |
44 | 'node-name': 'str', | 44 | 'node-name': 'str', |
45 | '*writable': 'bool', | 45 | '*writable': 'bool', |
46 | '*writethrough': 'bool' }, | 46 | '*writethrough': 'bool' }, |
47 | diff --git a/block/export/export.c b/block/export/export.c | 47 | diff --git a/block/export/export.c b/block/export/export.c |
48 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/block/export/export.c | 49 | --- a/block/export/export.c |
50 | +++ b/block/export/export.c | 50 | +++ b/block/export/export.c |
51 | @@ -XXX,XX +XXX,XX @@ | 51 | @@ -XXX,XX +XXX,XX @@ |
52 | 52 | ||
53 | #include "block/block.h" | 53 | #include "block/block.h" |
54 | #include "sysemu/block-backend.h" | 54 | #include "sysemu/block-backend.h" |
55 | +#include "sysemu/iothread.h" | 55 | +#include "sysemu/iothread.h" |
56 | #include "block/export.h" | 56 | #include "block/export.h" |
57 | #include "block/nbd.h" | 57 | #include "block/nbd.h" |
58 | #include "qapi/error.h" | 58 | #include "qapi/error.h" |
59 | @@ -XXX,XX +XXX,XX @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) | 59 | @@ -XXX,XX +XXX,XX @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) |
60 | 60 | ||
61 | BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | 61 | BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) |
62 | { | 62 | { |
63 | + bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread; | 63 | + bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread; |
64 | const BlockExportDriver *drv; | 64 | const BlockExportDriver *drv; |
65 | BlockExport *exp = NULL; | 65 | BlockExport *exp = NULL; |
66 | BlockDriverState *bs; | 66 | BlockDriverState *bs; |
67 | - BlockBackend *blk; | 67 | - BlockBackend *blk; |
68 | + BlockBackend *blk = NULL; | 68 | + BlockBackend *blk = NULL; |
69 | AioContext *ctx; | 69 | AioContext *ctx; |
70 | uint64_t perm; | 70 | uint64_t perm; |
71 | int ret; | 71 | int ret; |
72 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | 72 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) |
73 | ctx = bdrv_get_aio_context(bs); | 73 | ctx = bdrv_get_aio_context(bs); |
74 | aio_context_acquire(ctx); | 74 | aio_context_acquire(ctx); |
75 | 75 | ||
76 | + if (export->has_iothread) { | 76 | + if (export->has_iothread) { |
77 | + IOThread *iothread; | 77 | + IOThread *iothread; |
78 | + AioContext *new_ctx; | 78 | + AioContext *new_ctx; |
79 | + | 79 | + |
80 | + iothread = iothread_by_id(export->iothread); | 80 | + iothread = iothread_by_id(export->iothread); |
81 | + if (!iothread) { | 81 | + if (!iothread) { |
82 | + error_setg(errp, "iothread \"%s\" not found", export->iothread); | 82 | + error_setg(errp, "iothread \"%s\" not found", export->iothread); |
83 | + goto fail; | 83 | + goto fail; |
84 | + } | 84 | + } |
85 | + | 85 | + |
86 | + new_ctx = iothread_get_aio_context(iothread); | 86 | + new_ctx = iothread_get_aio_context(iothread); |
87 | + | 87 | + |
88 | + ret = bdrv_try_set_aio_context(bs, new_ctx, errp); | 88 | + ret = bdrv_try_set_aio_context(bs, new_ctx, errp); |
89 | + if (ret == 0) { | 89 | + if (ret == 0) { |
90 | + aio_context_release(ctx); | 90 | + aio_context_release(ctx); |
91 | + aio_context_acquire(new_ctx); | 91 | + aio_context_acquire(new_ctx); |
92 | + ctx = new_ctx; | 92 | + ctx = new_ctx; |
93 | + } else if (fixed_iothread) { | 93 | + } else if (fixed_iothread) { |
94 | + goto fail; | 94 | + goto fail; |
95 | + } | 95 | + } |
96 | + } | 96 | + } |
97 | + | 97 | + |
98 | /* | 98 | /* |
99 | * Block exports are used for non-shared storage migration. Make sure | 99 | * Block exports are used for non-shared storage migration. Make sure |
100 | * that BDRV_O_INACTIVE is cleared and the image is ready for write | 100 | * that BDRV_O_INACTIVE is cleared and the image is ready for write |
101 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | 101 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) |
102 | } | 102 | } |
103 | 103 | ||
104 | blk = blk_new(ctx, perm, BLK_PERM_ALL); | 104 | blk = blk_new(ctx, perm, BLK_PERM_ALL); |
105 | + | 105 | + |
106 | + if (!fixed_iothread) { | 106 | + if (!fixed_iothread) { |
107 | + blk_set_allow_aio_context_change(blk, true); | 107 | + blk_set_allow_aio_context_change(blk, true); |
108 | + } | 108 | + } |
109 | + | 109 | + |
110 | ret = blk_insert_bs(blk, bs, errp); | 110 | ret = blk_insert_bs(blk, bs, errp); |
111 | if (ret < 0) { | 111 | if (ret < 0) { |
112 | goto fail; | 112 | goto fail; |
113 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 113 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
114 | index XXXXXXX..XXXXXXX 100644 | 114 | index XXXXXXX..XXXXXXX 100644 |
115 | --- a/block/export/vhost-user-blk-server.c | 115 | --- a/block/export/vhost-user-blk-server.c |
116 | +++ b/block/export/vhost-user-blk-server.c | 116 | +++ b/block/export/vhost-user-blk-server.c |
117 | @@ -XXX,XX +XXX,XX @@ static const VuDevIface vu_blk_iface = { | 117 | @@ -XXX,XX +XXX,XX @@ static const VuDevIface vu_blk_iface = { |
118 | static void blk_aio_attached(AioContext *ctx, void *opaque) | 118 | static void blk_aio_attached(AioContext *ctx, void *opaque) |
119 | { | 119 | { |
120 | VuBlkExport *vexp = opaque; | 120 | VuBlkExport *vexp = opaque; |
121 | + | 121 | + |
122 | + vexp->export.ctx = ctx; | 122 | + vexp->export.ctx = ctx; |
123 | vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); | 123 | vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); |
124 | } | 124 | } |
125 | 125 | ||
126 | static void blk_aio_detach(void *opaque) | 126 | static void blk_aio_detach(void *opaque) |
127 | { | 127 | { |
128 | VuBlkExport *vexp = opaque; | 128 | VuBlkExport *vexp = opaque; |
129 | + | 129 | + |
130 | vhost_user_server_detach_aio_context(&vexp->vu_server); | 130 | vhost_user_server_detach_aio_context(&vexp->vu_server); |
131 | + vexp->export.ctx = NULL; | 131 | + vexp->export.ctx = NULL; |
132 | } | 132 | } |
133 | 133 | ||
134 | static void | 134 | static void |
135 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | 135 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, |
136 | vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, | 136 | vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, |
137 | logical_block_size); | 137 | logical_block_size); |
138 | 138 | ||
139 | - blk_set_allow_aio_context_change(exp->blk, true); | 139 | - blk_set_allow_aio_context_change(exp->blk, true); |
140 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | 140 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, |
141 | vexp); | 141 | vexp); |
142 | 142 | ||
143 | diff --git a/nbd/server.c b/nbd/server.c | 143 | diff --git a/nbd/server.c b/nbd/server.c |
144 | index XXXXXXX..XXXXXXX 100644 | 144 | index XXXXXXX..XXXXXXX 100644 |
145 | --- a/nbd/server.c | 145 | --- a/nbd/server.c |
146 | +++ b/nbd/server.c | 146 | +++ b/nbd/server.c |
147 | @@ -XXX,XX +XXX,XX @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args, | 147 | @@ -XXX,XX +XXX,XX @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args, |
148 | return ret; | 148 | return ret; |
149 | } | 149 | } |
150 | 150 | ||
151 | - blk_set_allow_aio_context_change(blk, true); | 151 | - blk_set_allow_aio_context_change(blk, true); |
152 | - | 152 | - |
153 | QTAILQ_INIT(&exp->clients); | 153 | QTAILQ_INIT(&exp->clients); |
154 | exp->name = g_strdup(arg->name); | 154 | exp->name = g_strdup(arg->name); |
155 | exp->description = g_strdup(arg->description); | 155 | exp->description = g_strdup(arg->description); |
156 | -- | 156 | -- |
157 | 2.26.2 | 157 | 2.26.2 |
158 | 158 | diff view generated by jsdifflib |
1 | Allow the number of queues to be configured using --export | 1 | Allow the number of queues to be configured using --export |
---|---|---|---|
2 | vhost-user-blk,num-queues=N. This setting should match the QEMU --device | 2 | vhost-user-blk,num-queues=N. This setting should match the QEMU --device |
3 | vhost-user-blk-pci,num-queues=N setting but QEMU vhost-user-blk.c lowers | 3 | vhost-user-blk-pci,num-queues=N setting but QEMU vhost-user-blk.c lowers |
4 | its own value if the vhost-user-blk backend offers fewer queues than | 4 | its own value if the vhost-user-blk backend offers fewer queues than |
5 | QEMU. | 5 | QEMU. |
6 | 6 | ||
7 | The vhost-user-blk-server.c code is already capable of multi-queue. All | 7 | The vhost-user-blk-server.c code is already capable of multi-queue. All |
8 | virtqueue processing runs in the same AioContext. No new locking is | 8 | virtqueue processing runs in the same AioContext. No new locking is |
9 | needed. | 9 | needed. |
10 | 10 | ||
11 | Add the num-queues=N option and set the VIRTIO_BLK_F_MQ feature bit. | 11 | Add the num-queues=N option and set the VIRTIO_BLK_F_MQ feature bit. |
12 | Note that the feature bit only announces the presence of the num_queues | 12 | Note that the feature bit only announces the presence of the num_queues |
13 | configuration space field. It does not promise that there is more than 1 | 13 | configuration space field. It does not promise that there is more than 1 |
14 | virtqueue, so we can set it unconditionally. | 14 | virtqueue, so we can set it unconditionally. |
15 | 15 | ||
16 | I tested multi-queue by running a random read fio test with numjobs=4 on | 16 | I tested multi-queue by running a random read fio test with numjobs=4 on |
17 | an -smp 4 guest. After the benchmark finished the guest /proc/interrupts | 17 | an -smp 4 guest. After the benchmark finished the guest /proc/interrupts |
18 | file showed activity on all 4 virtio-blk MSI-X. The /sys/block/vda/mq/ | 18 | file showed activity on all 4 virtio-blk MSI-X. The /sys/block/vda/mq/ |
19 | directory shows that Linux blk-mq has 4 queues configured. | 19 | directory shows that Linux blk-mq has 4 queues configured. |
20 | 20 | ||
21 | An automated test is included in the next commit. | 21 | An automated test is included in the next commit. |
22 | 22 | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
24 | Acked-by: Markus Armbruster <armbru@redhat.com> | 24 | Acked-by: Markus Armbruster <armbru@redhat.com> |
25 | Message-id: 20201001144604.559733-2-stefanha@redhat.com | 25 | Message-id: 20201001144604.559733-2-stefanha@redhat.com |
26 | [Fixed accidental tab characters as suggested by Markus Armbruster | 26 | [Fixed accidental tab characters as suggested by Markus Armbruster |
27 | --Stefan] | 27 | --Stefan] |
28 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 28 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
29 | --- | 29 | --- |
30 | qapi/block-export.json | 10 +++++++--- | 30 | qapi/block-export.json | 10 +++++++--- |
31 | block/export/vhost-user-blk-server.c | 24 ++++++++++++++++++------ | 31 | block/export/vhost-user-blk-server.c | 24 ++++++++++++++++++------ |
32 | 2 files changed, 25 insertions(+), 9 deletions(-) | 32 | 2 files changed, 25 insertions(+), 9 deletions(-) |
33 | 33 | ||
34 | diff --git a/qapi/block-export.json b/qapi/block-export.json | 34 | diff --git a/qapi/block-export.json b/qapi/block-export.json |
35 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/qapi/block-export.json | 36 | --- a/qapi/block-export.json |
37 | +++ b/qapi/block-export.json | 37 | +++ b/qapi/block-export.json |
38 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ |
39 | # SocketAddress types are supported. Passed fds must be UNIX domain | 39 | # SocketAddress types are supported. Passed fds must be UNIX domain |
40 | # sockets. | 40 | # sockets. |
41 | # @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. | 41 | # @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. |
42 | +# @num-queues: Number of request virtqueues. Must be greater than 0. Defaults | 42 | +# @num-queues: Number of request virtqueues. Must be greater than 0. Defaults |
43 | +# to 1. | 43 | +# to 1. |
44 | # | 44 | # |
45 | # Since: 5.2 | 45 | # Since: 5.2 |
46 | ## | 46 | ## |
47 | { 'struct': 'BlockExportOptionsVhostUserBlk', | 47 | { 'struct': 'BlockExportOptionsVhostUserBlk', |
48 | - 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } | 48 | - 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } |
49 | + 'data': { 'addr': 'SocketAddress', | 49 | + 'data': { 'addr': 'SocketAddress', |
50 | + '*logical-block-size': 'size', | 50 | + '*logical-block-size': 'size', |
51 | + '*num-queues': 'uint16'} } | 51 | + '*num-queues': 'uint16'} } |
52 | 52 | ||
53 | ## | 53 | ## |
54 | # @NbdServerAddOptions: | 54 | # @NbdServerAddOptions: |
55 | @@ -XXX,XX +XXX,XX @@ | 55 | @@ -XXX,XX +XXX,XX @@ |
56 | { 'union': 'BlockExportOptions', | 56 | { 'union': 'BlockExportOptions', |
57 | 'base': { 'type': 'BlockExportType', | 57 | 'base': { 'type': 'BlockExportType', |
58 | 'id': 'str', | 58 | 'id': 'str', |
59 | - '*fixed-iothread': 'bool', | 59 | - '*fixed-iothread': 'bool', |
60 | - '*iothread': 'str', | 60 | - '*iothread': 'str', |
61 | + '*fixed-iothread': 'bool', | 61 | + '*fixed-iothread': 'bool', |
62 | + '*iothread': 'str', | 62 | + '*iothread': 'str', |
63 | 'node-name': 'str', | 63 | 'node-name': 'str', |
64 | '*writable': 'bool', | 64 | '*writable': 'bool', |
65 | '*writethrough': 'bool' }, | 65 | '*writethrough': 'bool' }, |
66 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | 66 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
67 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/block/export/vhost-user-blk-server.c | 68 | --- a/block/export/vhost-user-blk-server.c |
69 | +++ b/block/export/vhost-user-blk-server.c | 69 | +++ b/block/export/vhost-user-blk-server.c |
70 | @@ -XXX,XX +XXX,XX @@ | 70 | @@ -XXX,XX +XXX,XX @@ |
71 | #include "util/block-helpers.h" | 71 | #include "util/block-helpers.h" |
72 | 72 | ||
73 | enum { | 73 | enum { |
74 | - VHOST_USER_BLK_MAX_QUEUES = 1, | 74 | - VHOST_USER_BLK_MAX_QUEUES = 1, |
75 | + VHOST_USER_BLK_NUM_QUEUES_DEFAULT = 1, | 75 | + VHOST_USER_BLK_NUM_QUEUES_DEFAULT = 1, |
76 | }; | 76 | }; |
77 | struct virtio_blk_inhdr { | 77 | struct virtio_blk_inhdr { |
78 | unsigned char status; | 78 | unsigned char status; |
79 | @@ -XXX,XX +XXX,XX @@ static uint64_t vu_blk_get_features(VuDev *dev) | 79 | @@ -XXX,XX +XXX,XX @@ static uint64_t vu_blk_get_features(VuDev *dev) |
80 | 1ull << VIRTIO_BLK_F_DISCARD | | 80 | 1ull << VIRTIO_BLK_F_DISCARD | |
81 | 1ull << VIRTIO_BLK_F_WRITE_ZEROES | | 81 | 1ull << VIRTIO_BLK_F_WRITE_ZEROES | |
82 | 1ull << VIRTIO_BLK_F_CONFIG_WCE | | 82 | 1ull << VIRTIO_BLK_F_CONFIG_WCE | |
83 | + 1ull << VIRTIO_BLK_F_MQ | | 83 | + 1ull << VIRTIO_BLK_F_MQ | |
84 | 1ull << VIRTIO_F_VERSION_1 | | 84 | 1ull << VIRTIO_F_VERSION_1 | |
85 | 1ull << VIRTIO_RING_F_INDIRECT_DESC | | 85 | 1ull << VIRTIO_RING_F_INDIRECT_DESC | |
86 | 1ull << VIRTIO_RING_F_EVENT_IDX | | 86 | 1ull << VIRTIO_RING_F_EVENT_IDX | |
87 | @@ -XXX,XX +XXX,XX @@ static void blk_aio_detach(void *opaque) | 87 | @@ -XXX,XX +XXX,XX @@ static void blk_aio_detach(void *opaque) |
88 | 88 | ||
89 | static void | 89 | static void |
90 | vu_blk_initialize_config(BlockDriverState *bs, | 90 | vu_blk_initialize_config(BlockDriverState *bs, |
91 | - struct virtio_blk_config *config, uint32_t blk_size) | 91 | - struct virtio_blk_config *config, uint32_t blk_size) |
92 | + struct virtio_blk_config *config, | 92 | + struct virtio_blk_config *config, |
93 | + uint32_t blk_size, | 93 | + uint32_t blk_size, |
94 | + uint16_t num_queues) | 94 | + uint16_t num_queues) |
95 | { | 95 | { |
96 | config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; | 96 | config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; |
97 | config->blk_size = blk_size; | 97 | config->blk_size = blk_size; |
98 | @@ -XXX,XX +XXX,XX @@ vu_blk_initialize_config(BlockDriverState *bs, | 98 | @@ -XXX,XX +XXX,XX @@ vu_blk_initialize_config(BlockDriverState *bs, |
99 | config->seg_max = 128 - 2; | 99 | config->seg_max = 128 - 2; |
100 | config->min_io_size = 1; | 100 | config->min_io_size = 1; |
101 | config->opt_io_size = 1; | 101 | config->opt_io_size = 1; |
102 | - config->num_queues = VHOST_USER_BLK_MAX_QUEUES; | 102 | - config->num_queues = VHOST_USER_BLK_MAX_QUEUES; |
103 | + config->num_queues = num_queues; | 103 | + config->num_queues = num_queues; |
104 | config->max_discard_sectors = 32768; | 104 | config->max_discard_sectors = 32768; |
105 | config->max_discard_seg = 1; | 105 | config->max_discard_seg = 1; |
106 | config->discard_sector_alignment = config->blk_size >> 9; | 106 | config->discard_sector_alignment = config->blk_size >> 9; |
107 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | 107 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, |
108 | BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk; | 108 | BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk; |
109 | Error *local_err = NULL; | 109 | Error *local_err = NULL; |
110 | uint64_t logical_block_size; | 110 | uint64_t logical_block_size; |
111 | + uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT; | 111 | + uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT; |
112 | 112 | ||
113 | vexp->writable = opts->writable; | 113 | vexp->writable = opts->writable; |
114 | vexp->blkcfg.wce = 0; | 114 | vexp->blkcfg.wce = 0; |
115 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | 115 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, |
116 | } | 116 | } |
117 | vexp->blk_size = logical_block_size; | 117 | vexp->blk_size = logical_block_size; |
118 | blk_set_guest_block_size(exp->blk, logical_block_size); | 118 | blk_set_guest_block_size(exp->blk, logical_block_size); |
119 | + | 119 | + |
120 | + if (vu_opts->has_num_queues) { | 120 | + if (vu_opts->has_num_queues) { |
121 | + num_queues = vu_opts->num_queues; | 121 | + num_queues = vu_opts->num_queues; |
122 | + } | 122 | + } |
123 | + if (num_queues == 0) { | 123 | + if (num_queues == 0) { |
124 | + error_setg(errp, "num-queues must be greater than 0"); | 124 | + error_setg(errp, "num-queues must be greater than 0"); |
125 | + return -EINVAL; | 125 | + return -EINVAL; |
126 | + } | 126 | + } |
127 | + | 127 | + |
128 | vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, | 128 | vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, |
129 | - logical_block_size); | 129 | - logical_block_size); |
130 | + logical_block_size, num_queues); | 130 | + logical_block_size, num_queues); |
131 | 131 | ||
132 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | 132 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, |
133 | vexp); | 133 | vexp); |
134 | 134 | ||
135 | if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, | 135 | if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, |
136 | - VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, | 136 | - VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, |
137 | - errp)) { | 137 | - errp)) { |
138 | + num_queues, &vu_blk_iface, errp)) { | 138 | + num_queues, &vu_blk_iface, errp)) { |
139 | blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, | 139 | blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, |
140 | blk_aio_detach, vexp); | 140 | blk_aio_detach, vexp); |
141 | return -EADDRNOTAVAIL; | 141 | return -EADDRNOTAVAIL; |
142 | -- | 142 | -- |
143 | 2.26.2 | 143 | 2.26.2 |
144 | 144 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
2 | Message-id: 20201001144604.559733-3-stefanha@redhat.com | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | --- | ||
5 | tests/qtest/vhost-user-blk-test.c | 81 +++++++++++++++++++++++++++++-- | ||
6 | 1 file changed, 76 insertions(+), 5 deletions(-) | ||
7 | 1 | ||
8 | diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/tests/qtest/vhost-user-blk-test.c | ||
11 | +++ b/tests/qtest/vhost-user-blk-test.c | ||
12 | @@ -XXX,XX +XXX,XX @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) | ||
13 | qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); | ||
14 | } | ||
15 | |||
16 | +static void multiqueue(void *obj, void *data, QGuestAllocator *t_alloc) | ||
17 | +{ | ||
18 | + QVirtioPCIDevice *pdev1 = obj; | ||
19 | + QVirtioDevice *dev1 = &pdev1->vdev; | ||
20 | + QVirtioPCIDevice *pdev8; | ||
21 | + QVirtioDevice *dev8; | ||
22 | + QTestState *qts = pdev1->pdev->bus->qts; | ||
23 | + uint64_t features; | ||
24 | + uint16_t num_queues; | ||
25 | + | ||
26 | + /* | ||
27 | + * The primary device has 1 queue and VIRTIO_BLK_F_MQ is not enabled. The | ||
28 | + * VIRTIO specification allows VIRTIO_BLK_F_MQ to be enabled when there is | ||
29 | + * only 1 virtqueue, but --device vhost-user-blk-pci doesn't do this (which | ||
30 | + * is also spec-compliant). | ||
31 | + */ | ||
32 | + features = qvirtio_get_features(dev1); | ||
33 | + g_assert_cmpint(features & (1u << VIRTIO_BLK_F_MQ), ==, 0); | ||
34 | + features = features & ~(QVIRTIO_F_BAD_FEATURE | | ||
35 | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | | ||
36 | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | | ||
37 | + (1u << VIRTIO_BLK_F_SCSI)); | ||
38 | + qvirtio_set_features(dev1, features); | ||
39 | + | ||
40 | + /* Hotplug a secondary device with 8 queues */ | ||
41 | + qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", | ||
42 | + "{'addr': %s, 'chardev': 'char2', 'num-queues': 8}", | ||
43 | + stringify(PCI_SLOT_HP) ".0"); | ||
44 | + | ||
45 | + pdev8 = virtio_pci_new(pdev1->pdev->bus, | ||
46 | + &(QPCIAddress) { | ||
47 | + .devfn = QPCI_DEVFN(PCI_SLOT_HP, 0) | ||
48 | + }); | ||
49 | + g_assert_nonnull(pdev8); | ||
50 | + g_assert_cmpint(pdev8->vdev.device_type, ==, VIRTIO_ID_BLOCK); | ||
51 | + | ||
52 | + qos_object_start_hw(&pdev8->obj); | ||
53 | + | ||
54 | + dev8 = &pdev8->vdev; | ||
55 | + features = qvirtio_get_features(dev8); | ||
56 | + g_assert_cmpint(features & (1u << VIRTIO_BLK_F_MQ), | ||
57 | + ==, | ||
58 | + (1u << VIRTIO_BLK_F_MQ)); | ||
59 | + features = features & ~(QVIRTIO_F_BAD_FEATURE | | ||
60 | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | | ||
61 | + (1u << VIRTIO_F_NOTIFY_ON_EMPTY) | | ||
62 | + (1u << VIRTIO_BLK_F_SCSI) | | ||
63 | + (1u << VIRTIO_BLK_F_MQ)); | ||
64 | + qvirtio_set_features(dev8, features); | ||
65 | + | ||
66 | + num_queues = qvirtio_config_readw(dev8, | ||
67 | + offsetof(struct virtio_blk_config, num_queues)); | ||
68 | + g_assert_cmpint(num_queues, ==, 8); | ||
69 | + | ||
70 | + qvirtio_pci_device_disable(pdev8); | ||
71 | + qos_object_destroy(&pdev8->obj); | ||
72 | + | ||
73 | + /* unplug secondary disk */ | ||
74 | + qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); | ||
75 | +} | ||
76 | + | ||
77 | /* | ||
78 | * Check that setting the vring addr on a non-existent virtqueue does | ||
79 | * not crash. | ||
80 | @@ -XXX,XX +XXX,XX @@ static void quit_storage_daemon(void *qmp_test_state) | ||
81 | g_free(qmp_test_state); | ||
82 | } | ||
83 | |||
84 | -static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) | ||
85 | +static char *start_vhost_user_blk(GString *cmd_line, int vus_instances, | ||
86 | + int num_queues) | ||
87 | { | ||
88 | const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); | ||
89 | int fd, qmp_fd, i; | ||
90 | @@ -XXX,XX +XXX,XX @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) | ||
91 | g_string_append_printf(storage_daemon_command, | ||
92 | "--blockdev driver=file,node-name=disk%d,filename=%s " | ||
93 | "--export type=vhost-user-blk,id=disk%d,addr.type=unix,addr.path=%s," | ||
94 | - "node-name=disk%i,writable=on ", | ||
95 | - i, img_path, i, sock_path, i); | ||
96 | + "node-name=disk%i,writable=on,num-queues=%d ", | ||
97 | + i, img_path, i, sock_path, i, num_queues); | ||
98 | |||
99 | g_string_append_printf(cmd_line, "-chardev socket,id=char%d,path=%s ", | ||
100 | i + 1, sock_path); | ||
101 | @@ -XXX,XX +XXX,XX @@ static char *start_vhost_user_blk(GString *cmd_line, int vus_instances) | ||
102 | |||
103 | static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) | ||
104 | { | ||
105 | - start_vhost_user_blk(cmd_line, 1); | ||
106 | + start_vhost_user_blk(cmd_line, 1, 1); | ||
107 | return arg; | ||
108 | } | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) | ||
111 | static void *vhost_user_blk_hotplug_test_setup(GString *cmd_line, void *arg) | ||
112 | { | ||
113 | /* "-chardev socket,id=char2" is used for pci_hotplug*/ | ||
114 | - start_vhost_user_blk(cmd_line, 2); | ||
115 | + start_vhost_user_blk(cmd_line, 2, 1); | ||
116 | + return arg; | ||
117 | +} | ||
118 | + | ||
119 | +static void *vhost_user_blk_multiqueue_test_setup(GString *cmd_line, void *arg) | ||
120 | +{ | ||
121 | + start_vhost_user_blk(cmd_line, 2, 8); | ||
122 | return arg; | ||
123 | } | ||
124 | |||
125 | @@ -XXX,XX +XXX,XX @@ static void register_vhost_user_blk_test(void) | ||
126 | |||
127 | opts.before = vhost_user_blk_hotplug_test_setup; | ||
128 | qos_add_test("hotplug", "vhost-user-blk-pci", pci_hotplug, &opts); | ||
129 | + | ||
130 | + opts.before = vhost_user_blk_multiqueue_test_setup; | ||
131 | + qos_add_test("multiqueue", "vhost-user-blk-pci", multiqueue, &opts); | ||
132 | } | ||
133 | |||
134 | libqos_init(register_vhost_user_blk_test); | ||
135 | -- | ||
136 | 2.26.2 | ||
137 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | bdrv_co_block_status_above has several design problems with handling | 3 | bdrv_co_block_status_above has several design problems with handling |
4 | short backing files: | 4 | short backing files: |
5 | 5 | ||
6 | 1. With want_zeros=true, it may return ret with BDRV_BLOCK_ZERO but | 6 | 1. With want_zeros=true, it may return ret with BDRV_BLOCK_ZERO but |
7 | without BDRV_BLOCK_ALLOCATED flag, when actually short backing file | 7 | without BDRV_BLOCK_ALLOCATED flag, when actually short backing file |
8 | which produces these after-EOF zeros is inside requested backing | 8 | which produces these after-EOF zeros is inside requested backing |
9 | sequence. | 9 | sequence. |
10 | 10 | ||
11 | 2. With want_zero=false, it may return pnum=0 prior to actual EOF, | 11 | 2. With want_zero=false, it may return pnum=0 prior to actual EOF, |
12 | because of EOF of short backing file. | 12 | because of EOF of short backing file. |
13 | 13 | ||
14 | Fix these things, making logic about short backing files clearer. | 14 | Fix these things, making logic about short backing files clearer. |
15 | 15 | ||
16 | With fixed bdrv_block_status_above we also have to improve is_zero in | 16 | With fixed bdrv_block_status_above we also have to improve is_zero in |
17 | qcow2 code, otherwise iotest 154 will fail, because with this patch we | 17 | qcow2 code, otherwise iotest 154 will fail, because with this patch we |
18 | stop to merge zeros of different types (produced by fully unallocated | 18 | stop to merge zeros of different types (produced by fully unallocated |
19 | in the whole backing chain regions vs produced by short backing files). | 19 | in the whole backing chain regions vs produced by short backing files). |
20 | 20 | ||
21 | Note also, that this patch leaves for another day the general problem | 21 | Note also, that this patch leaves for another day the general problem |
22 | around block-status: misuse of BDRV_BLOCK_ALLOCATED as is-fs-allocated | 22 | around block-status: misuse of BDRV_BLOCK_ALLOCATED as is-fs-allocated |
23 | vs go-to-backing. | 23 | vs go-to-backing. |
24 | 24 | ||
25 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 25 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
26 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 26 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
27 | Reviewed-by: Eric Blake <eblake@redhat.com> | 27 | Reviewed-by: Eric Blake <eblake@redhat.com> |
28 | Message-id: 20200924194003.22080-2-vsementsov@virtuozzo.com | 28 | Message-id: 20200924194003.22080-2-vsementsov@virtuozzo.com |
29 | [Fix s/comes/come/ as suggested by Eric Blake | 29 | [Fix s/comes/come/ as suggested by Eric Blake |
30 | --Stefan] | 30 | --Stefan] |
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
32 | --- | 32 | --- |
33 | block/io.c | 68 ++++++++++++++++++++++++++++++++++++++++----------- | 33 | block/io.c | 68 ++++++++++++++++++++++++++++++++++++++++----------- |
34 | block/qcow2.c | 16 ++++++++++-- | 34 | block/qcow2.c | 16 ++++++++++-- |
35 | 2 files changed, 68 insertions(+), 16 deletions(-) | 35 | 2 files changed, 68 insertions(+), 16 deletions(-) |
36 | 36 | ||
37 | diff --git a/block/io.c b/block/io.c | 37 | diff --git a/block/io.c b/block/io.c |
38 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/block/io.c | 39 | --- a/block/io.c |
40 | +++ b/block/io.c | 40 | +++ b/block/io.c |
41 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 41 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
42 | int64_t *map, | 42 | int64_t *map, |
43 | BlockDriverState **file) | 43 | BlockDriverState **file) |
44 | { | 44 | { |
45 | + int ret; | 45 | + int ret; |
46 | BlockDriverState *p; | 46 | BlockDriverState *p; |
47 | - int ret = 0; | 47 | - int ret = 0; |
48 | - bool first = true; | 48 | - bool first = true; |
49 | + int64_t eof = 0; | 49 | + int64_t eof = 0; |
50 | 50 | ||
51 | assert(bs != base); | 51 | assert(bs != base); |
52 | - for (p = bs; p != base; p = bdrv_filter_or_cow_bs(p)) { | 52 | - for (p = bs; p != base; p = bdrv_filter_or_cow_bs(p)) { |
53 | + | 53 | + |
54 | + ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); | 54 | + ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); |
55 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { | 55 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { |
56 | + return ret; | 56 | + return ret; |
57 | + } | 57 | + } |
58 | + | 58 | + |
59 | + if (ret & BDRV_BLOCK_EOF) { | 59 | + if (ret & BDRV_BLOCK_EOF) { |
60 | + eof = offset + *pnum; | 60 | + eof = offset + *pnum; |
61 | + } | 61 | + } |
62 | + | 62 | + |
63 | + assert(*pnum <= bytes); | 63 | + assert(*pnum <= bytes); |
64 | + bytes = *pnum; | 64 | + bytes = *pnum; |
65 | + | 65 | + |
66 | + for (p = bdrv_filter_or_cow_bs(bs); p != base; | 66 | + for (p = bdrv_filter_or_cow_bs(bs); p != base; |
67 | + p = bdrv_filter_or_cow_bs(p)) | 67 | + p = bdrv_filter_or_cow_bs(p)) |
68 | + { | 68 | + { |
69 | ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, | 69 | ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, |
70 | file); | 70 | file); |
71 | if (ret < 0) { | 71 | if (ret < 0) { |
72 | - break; | 72 | - break; |
73 | + return ret; | 73 | + return ret; |
74 | } | 74 | } |
75 | - if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { | 75 | - if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { |
76 | + if (*pnum == 0) { | 76 | + if (*pnum == 0) { |
77 | /* | 77 | /* |
78 | - * Reading beyond the end of the file continues to read | 78 | - * Reading beyond the end of the file continues to read |
79 | - * zeroes, but we can only widen the result to the | 79 | - * zeroes, but we can only widen the result to the |
80 | - * unallocated length we learned from an earlier | 80 | - * unallocated length we learned from an earlier |
81 | - * iteration. | 81 | - * iteration. |
82 | + * The top layer deferred to this layer, and because this layer is | 82 | + * The top layer deferred to this layer, and because this layer is |
83 | + * short, any zeroes that we synthesize beyond EOF behave as if they | 83 | + * short, any zeroes that we synthesize beyond EOF behave as if they |
84 | + * were allocated at this layer. | 84 | + * were allocated at this layer. |
85 | + * | 85 | + * |
86 | + * We don't include BDRV_BLOCK_EOF into ret, as upper layer may be | 86 | + * We don't include BDRV_BLOCK_EOF into ret, as upper layer may be |
87 | + * larger. We'll add BDRV_BLOCK_EOF if needed at function end, see | 87 | + * larger. We'll add BDRV_BLOCK_EOF if needed at function end, see |
88 | + * below. | 88 | + * below. |
89 | */ | 89 | */ |
90 | + assert(ret & BDRV_BLOCK_EOF); | 90 | + assert(ret & BDRV_BLOCK_EOF); |
91 | *pnum = bytes; | 91 | *pnum = bytes; |
92 | + if (file) { | 92 | + if (file) { |
93 | + *file = p; | 93 | + *file = p; |
94 | + } | 94 | + } |
95 | + ret = BDRV_BLOCK_ZERO | BDRV_BLOCK_ALLOCATED; | 95 | + ret = BDRV_BLOCK_ZERO | BDRV_BLOCK_ALLOCATED; |
96 | + break; | 96 | + break; |
97 | } | 97 | } |
98 | - if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { | 98 | - if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { |
99 | + if (ret & BDRV_BLOCK_ALLOCATED) { | 99 | + if (ret & BDRV_BLOCK_ALLOCATED) { |
100 | + /* | 100 | + /* |
101 | + * We've found the node and the status, we must break. | 101 | + * We've found the node and the status, we must break. |
102 | + * | 102 | + * |
103 | + * Drop BDRV_BLOCK_EOF, as it's not for upper layer, which may be | 103 | + * Drop BDRV_BLOCK_EOF, as it's not for upper layer, which may be |
104 | + * larger. We'll add BDRV_BLOCK_EOF if needed at function end, see | 104 | + * larger. We'll add BDRV_BLOCK_EOF if needed at function end, see |
105 | + * below. | 105 | + * below. |
106 | + */ | 106 | + */ |
107 | + ret &= ~BDRV_BLOCK_EOF; | 107 | + ret &= ~BDRV_BLOCK_EOF; |
108 | break; | 108 | break; |
109 | } | 109 | } |
110 | - /* [offset, pnum] unallocated on this layer, which could be only | 110 | - /* [offset, pnum] unallocated on this layer, which could be only |
111 | - * the first part of [offset, bytes]. */ | 111 | - * the first part of [offset, bytes]. */ |
112 | - bytes = MIN(bytes, *pnum); | 112 | - bytes = MIN(bytes, *pnum); |
113 | - first = false; | 113 | - first = false; |
114 | + | 114 | + |
115 | + /* | 115 | + /* |
116 | + * OK, [offset, offset + *pnum) region is unallocated on this layer, | 116 | + * OK, [offset, offset + *pnum) region is unallocated on this layer, |
117 | + * let's continue the diving. | 117 | + * let's continue the diving. |
118 | + */ | 118 | + */ |
119 | + assert(*pnum <= bytes); | 119 | + assert(*pnum <= bytes); |
120 | + bytes = *pnum; | 120 | + bytes = *pnum; |
121 | + } | 121 | + } |
122 | + | 122 | + |
123 | + if (offset + *pnum == eof) { | 123 | + if (offset + *pnum == eof) { |
124 | + ret |= BDRV_BLOCK_EOF; | 124 | + ret |= BDRV_BLOCK_EOF; |
125 | } | 125 | } |
126 | + | 126 | + |
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
129 | 129 | ||
130 | diff --git a/block/qcow2.c b/block/qcow2.c | 130 | diff --git a/block/qcow2.c b/block/qcow2.c |
131 | index XXXXXXX..XXXXXXX 100644 | 131 | index XXXXXXX..XXXXXXX 100644 |
132 | --- a/block/qcow2.c | 132 | --- a/block/qcow2.c |
133 | +++ b/block/qcow2.c | 133 | +++ b/block/qcow2.c |
134 | @@ -XXX,XX +XXX,XX @@ static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) | 134 | @@ -XXX,XX +XXX,XX @@ static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) |
135 | if (!bytes) { | 135 | if (!bytes) { |
136 | return true; | 136 | return true; |
137 | } | 137 | } |
138 | - res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); | 138 | - res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); |
139 | - return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes; | 139 | - return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes; |
140 | + | 140 | + |
141 | + /* | 141 | + /* |
142 | + * bdrv_block_status_above doesn't merge different types of zeros, for | 142 | + * bdrv_block_status_above doesn't merge different types of zeros, for |
143 | + * example, zeros which come from the region which is unallocated in | 143 | + * example, zeros which come from the region which is unallocated in |
144 | + * the whole backing chain, and zeros which come because of a short | 144 | + * the whole backing chain, and zeros which come because of a short |
145 | + * backing file. So, we need a loop. | 145 | + * backing file. So, we need a loop. |
146 | + */ | 146 | + */ |
147 | + do { | 147 | + do { |
148 | + res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); | 148 | + res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); |
149 | + offset += nr; | 149 | + offset += nr; |
150 | + bytes -= nr; | 150 | + bytes -= nr; |
151 | + } while (res >= 0 && (res & BDRV_BLOCK_ZERO) && nr && bytes); | 151 | + } while (res >= 0 && (res & BDRV_BLOCK_ZERO) && nr && bytes); |
152 | + | 152 | + |
153 | + return res >= 0 && (res & BDRV_BLOCK_ZERO) && bytes == 0; | 153 | + return res >= 0 && (res & BDRV_BLOCK_ZERO) && bytes == 0; |
154 | } | 154 | } |
155 | 155 | ||
156 | static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, | 156 | static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, |
157 | -- | 157 | -- |
158 | 2.26.2 | 158 | 2.26.2 |
159 | 159 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | In order to reuse bdrv_common_block_status_above in | 3 | In order to reuse bdrv_common_block_status_above in |
4 | bdrv_is_allocated_above, let's support include_base parameter. | 4 | bdrv_is_allocated_above, let's support include_base parameter. |
5 | 5 | ||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
7 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 7 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> |
9 | Message-id: 20200924194003.22080-3-vsementsov@virtuozzo.com | 9 | Message-id: 20200924194003.22080-3-vsementsov@virtuozzo.com |
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | --- | 11 | --- |
12 | block/coroutines.h | 2 ++ | 12 | block/coroutines.h | 2 ++ |
13 | block/io.c | 21 ++++++++++++++------- | 13 | block/io.c | 21 ++++++++++++++------- |
14 | 2 files changed, 16 insertions(+), 7 deletions(-) | 14 | 2 files changed, 16 insertions(+), 7 deletions(-) |
15 | 15 | ||
16 | diff --git a/block/coroutines.h b/block/coroutines.h | 16 | diff --git a/block/coroutines.h b/block/coroutines.h |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/coroutines.h | 18 | --- a/block/coroutines.h |
19 | +++ b/block/coroutines.h | 19 | +++ b/block/coroutines.h |
20 | @@ -XXX,XX +XXX,XX @@ bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, | 20 | @@ -XXX,XX +XXX,XX @@ bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, |
21 | int coroutine_fn | 21 | int coroutine_fn |
22 | bdrv_co_common_block_status_above(BlockDriverState *bs, | 22 | bdrv_co_common_block_status_above(BlockDriverState *bs, |
23 | BlockDriverState *base, | 23 | BlockDriverState *base, |
24 | + bool include_base, | 24 | + bool include_base, |
25 | bool want_zero, | 25 | bool want_zero, |
26 | int64_t offset, | 26 | int64_t offset, |
27 | int64_t bytes, | 27 | int64_t bytes, |
28 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 28 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
29 | int generated_co_wrapper | 29 | int generated_co_wrapper |
30 | bdrv_common_block_status_above(BlockDriverState *bs, | 30 | bdrv_common_block_status_above(BlockDriverState *bs, |
31 | BlockDriverState *base, | 31 | BlockDriverState *base, |
32 | + bool include_base, | 32 | + bool include_base, |
33 | bool want_zero, | 33 | bool want_zero, |
34 | int64_t offset, | 34 | int64_t offset, |
35 | int64_t bytes, | 35 | int64_t bytes, |
36 | diff --git a/block/io.c b/block/io.c | 36 | diff --git a/block/io.c b/block/io.c |
37 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/block/io.c | 38 | --- a/block/io.c |
39 | +++ b/block/io.c | 39 | +++ b/block/io.c |
40 | @@ -XXX,XX +XXX,XX @@ early_out: | 40 | @@ -XXX,XX +XXX,XX @@ early_out: |
41 | int coroutine_fn | 41 | int coroutine_fn |
42 | bdrv_co_common_block_status_above(BlockDriverState *bs, | 42 | bdrv_co_common_block_status_above(BlockDriverState *bs, |
43 | BlockDriverState *base, | 43 | BlockDriverState *base, |
44 | + bool include_base, | 44 | + bool include_base, |
45 | bool want_zero, | 45 | bool want_zero, |
46 | int64_t offset, | 46 | int64_t offset, |
47 | int64_t bytes, | 47 | int64_t bytes, |
48 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 48 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
49 | BlockDriverState *p; | 49 | BlockDriverState *p; |
50 | int64_t eof = 0; | 50 | int64_t eof = 0; |
51 | 51 | ||
52 | - assert(bs != base); | 52 | - assert(bs != base); |
53 | + assert(include_base || bs != base); | 53 | + assert(include_base || bs != base); |
54 | + assert(!include_base || base); /* Can't include NULL base */ | 54 | + assert(!include_base || base); /* Can't include NULL base */ |
55 | 55 | ||
56 | ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); | 56 | ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); |
57 | - if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { | 57 | - if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { |
58 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) { | 58 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) { |
59 | return ret; | 59 | return ret; |
60 | } | 60 | } |
61 | 61 | ||
62 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 62 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
63 | assert(*pnum <= bytes); | 63 | assert(*pnum <= bytes); |
64 | bytes = *pnum; | 64 | bytes = *pnum; |
65 | 65 | ||
66 | - for (p = bdrv_filter_or_cow_bs(bs); p != base; | 66 | - for (p = bdrv_filter_or_cow_bs(bs); p != base; |
67 | + for (p = bdrv_filter_or_cow_bs(bs); include_base || p != base; | 67 | + for (p = bdrv_filter_or_cow_bs(bs); include_base || p != base; |
68 | p = bdrv_filter_or_cow_bs(p)) | 68 | p = bdrv_filter_or_cow_bs(p)) |
69 | { | 69 | { |
70 | ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, | 70 | ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, |
71 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 71 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
72 | break; | 72 | break; |
73 | } | 73 | } |
74 | 74 | ||
75 | + if (p == base) { | 75 | + if (p == base) { |
76 | + assert(include_base); | 76 | + assert(include_base); |
77 | + break; | 77 | + break; |
78 | + } | 78 | + } |
79 | + | 79 | + |
80 | /* | 80 | /* |
81 | * OK, [offset, offset + *pnum) region is unallocated on this layer, | 81 | * OK, [offset, offset + *pnum) region is unallocated on this layer, |
82 | * let's continue the diving. | 82 | * let's continue the diving. |
83 | @@ -XXX,XX +XXX,XX @@ int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, | 83 | @@ -XXX,XX +XXX,XX @@ int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, |
84 | int64_t offset, int64_t bytes, int64_t *pnum, | 84 | int64_t offset, int64_t bytes, int64_t *pnum, |
85 | int64_t *map, BlockDriverState **file) | 85 | int64_t *map, BlockDriverState **file) |
86 | { | 86 | { |
87 | - return bdrv_common_block_status_above(bs, base, true, offset, bytes, | 87 | - return bdrv_common_block_status_above(bs, base, true, offset, bytes, |
88 | + return bdrv_common_block_status_above(bs, base, false, true, offset, bytes, | 88 | + return bdrv_common_block_status_above(bs, base, false, true, offset, bytes, |
89 | pnum, map, file); | 89 | pnum, map, file); |
90 | } | 90 | } |
91 | 91 | ||
92 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, | 92 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, |
93 | int ret; | 93 | int ret; |
94 | int64_t dummy; | 94 | int64_t dummy; |
95 | 95 | ||
96 | - ret = bdrv_common_block_status_above(bs, bdrv_filter_or_cow_bs(bs), false, | 96 | - ret = bdrv_common_block_status_above(bs, bdrv_filter_or_cow_bs(bs), false, |
97 | - offset, bytes, pnum ? pnum : &dummy, | 97 | - offset, bytes, pnum ? pnum : &dummy, |
98 | - NULL, NULL); | 98 | - NULL, NULL); |
99 | + ret = bdrv_common_block_status_above(bs, bs, true, false, offset, | 99 | + ret = bdrv_common_block_status_above(bs, bs, true, false, offset, |
100 | + bytes, pnum ? pnum : &dummy, NULL, | 100 | + bytes, pnum ? pnum : &dummy, NULL, |
101 | + NULL); | 101 | + NULL); |
102 | if (ret < 0) { | 102 | if (ret < 0) { |
103 | return ret; | 103 | return ret; |
104 | } | 104 | } |
105 | -- | 105 | -- |
106 | 2.26.2 | 106 | 2.26.2 |
107 | 107 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | We are going to reuse bdrv_common_block_status_above in | 3 | We are going to reuse bdrv_common_block_status_above in |
4 | bdrv_is_allocated_above. bdrv_is_allocated_above may be called with | 4 | bdrv_is_allocated_above. bdrv_is_allocated_above may be called with |
5 | include_base == false and still bs == base (for ex. from img_rebase()). | 5 | include_base == false and still bs == base (for ex. from img_rebase()). |
6 | 6 | ||
7 | So, support this corner case. | 7 | So, support this corner case. |
8 | 8 | ||
9 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 9 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | 11 | Reviewed-by: Eric Blake <eblake@redhat.com> |
12 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 12 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
13 | Message-id: 20200924194003.22080-4-vsementsov@virtuozzo.com | 13 | Message-id: 20200924194003.22080-4-vsementsov@virtuozzo.com |
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
15 | --- | 15 | --- |
16 | block/io.c | 6 +++++- | 16 | block/io.c | 6 +++++- |
17 | 1 file changed, 5 insertions(+), 1 deletion(-) | 17 | 1 file changed, 5 insertions(+), 1 deletion(-) |
18 | 18 | ||
19 | diff --git a/block/io.c b/block/io.c | 19 | diff --git a/block/io.c b/block/io.c |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/block/io.c | 21 | --- a/block/io.c |
22 | +++ b/block/io.c | 22 | +++ b/block/io.c |
23 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | 23 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
24 | BlockDriverState *p; | 24 | BlockDriverState *p; |
25 | int64_t eof = 0; | 25 | int64_t eof = 0; |
26 | 26 | ||
27 | - assert(include_base || bs != base); | 27 | - assert(include_base || bs != base); |
28 | assert(!include_base || base); /* Can't include NULL base */ | 28 | assert(!include_base || base); /* Can't include NULL base */ |
29 | 29 | ||
30 | + if (!include_base && bs == base) { | 30 | + if (!include_base && bs == base) { |
31 | + *pnum = bytes; | 31 | + *pnum = bytes; |
32 | + return 0; | 32 | + return 0; |
33 | + } | 33 | + } |
34 | + | 34 | + |
35 | ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); | 35 | ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); |
36 | if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) { | 36 | if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) { |
37 | return ret; | 37 | return ret; |
38 | -- | 38 | -- |
39 | 2.26.2 | 39 | 2.26.2 |
40 | 40 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | bdrv_is_allocated_above wrongly handles short backing files: it reports | 3 | bdrv_is_allocated_above wrongly handles short backing files: it reports |
4 | after-EOF space as UNALLOCATED which is wrong, as on read the data is | 4 | after-EOF space as UNALLOCATED which is wrong, as on read the data is |
5 | generated on the level of short backing file (if all overlays have | 5 | generated on the level of short backing file (if all overlays have |
6 | unallocated areas at that place). | 6 | unallocated areas at that place). |
7 | 7 | ||
8 | Reusing bdrv_common_block_status_above fixes the issue and unifies code | 8 | Reusing bdrv_common_block_status_above fixes the issue and unifies code |
9 | path. | 9 | path. |
10 | 10 | ||
11 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 11 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | 12 | Reviewed-by: Eric Blake <eblake@redhat.com> |
13 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 13 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
14 | Message-id: 20200924194003.22080-5-vsementsov@virtuozzo.com | 14 | Message-id: 20200924194003.22080-5-vsementsov@virtuozzo.com |
15 | [Fix s/has/have/ as suggested by Eric Blake. Fix s/area/areas/. | 15 | [Fix s/has/have/ as suggested by Eric Blake. Fix s/area/areas/. |
16 | --Stefan] | 16 | --Stefan] |
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
18 | --- | 18 | --- |
19 | block/io.c | 43 +++++-------------------------------------- | 19 | block/io.c | 43 +++++-------------------------------------- |
20 | 1 file changed, 5 insertions(+), 38 deletions(-) | 20 | 1 file changed, 5 insertions(+), 38 deletions(-) |
21 | 21 | ||
22 | diff --git a/block/io.c b/block/io.c | 22 | diff --git a/block/io.c b/block/io.c |
23 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/block/io.c | 24 | --- a/block/io.c |
25 | +++ b/block/io.c | 25 | +++ b/block/io.c |
26 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, | 26 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, |
27 | * at 'offset + *pnum' may return the same allocation status (in other | 27 | * at 'offset + *pnum' may return the same allocation status (in other |
28 | * words, the result is not necessarily the maximum possible range); | 28 | * words, the result is not necessarily the maximum possible range); |
29 | * but 'pnum' will only be 0 when end of file is reached. | 29 | * but 'pnum' will only be 0 when end of file is reached. |
30 | - * | 30 | - * |
31 | */ | 31 | */ |
32 | int bdrv_is_allocated_above(BlockDriverState *top, | 32 | int bdrv_is_allocated_above(BlockDriverState *top, |
33 | BlockDriverState *base, | 33 | BlockDriverState *base, |
34 | bool include_base, int64_t offset, | 34 | bool include_base, int64_t offset, |
35 | int64_t bytes, int64_t *pnum) | 35 | int64_t bytes, int64_t *pnum) |
36 | { | 36 | { |
37 | - BlockDriverState *intermediate; | 37 | - BlockDriverState *intermediate; |
38 | - int ret; | 38 | - int ret; |
39 | - int64_t n = bytes; | 39 | - int64_t n = bytes; |
40 | - | 40 | - |
41 | - assert(base || !include_base); | 41 | - assert(base || !include_base); |
42 | - | 42 | - |
43 | - intermediate = top; | 43 | - intermediate = top; |
44 | - while (include_base || intermediate != base) { | 44 | - while (include_base || intermediate != base) { |
45 | - int64_t pnum_inter; | 45 | - int64_t pnum_inter; |
46 | - int64_t size_inter; | 46 | - int64_t size_inter; |
47 | - | 47 | - |
48 | - assert(intermediate); | 48 | - assert(intermediate); |
49 | - ret = bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter); | 49 | - ret = bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter); |
50 | - if (ret < 0) { | 50 | - if (ret < 0) { |
51 | - return ret; | 51 | - return ret; |
52 | - } | 52 | - } |
53 | - if (ret) { | 53 | - if (ret) { |
54 | - *pnum = pnum_inter; | 54 | - *pnum = pnum_inter; |
55 | - return 1; | 55 | - return 1; |
56 | - } | 56 | - } |
57 | - | 57 | - |
58 | - size_inter = bdrv_getlength(intermediate); | 58 | - size_inter = bdrv_getlength(intermediate); |
59 | - if (size_inter < 0) { | 59 | - if (size_inter < 0) { |
60 | - return size_inter; | 60 | - return size_inter; |
61 | - } | 61 | - } |
62 | - if (n > pnum_inter && | 62 | - if (n > pnum_inter && |
63 | - (intermediate == top || offset + pnum_inter < size_inter)) { | 63 | - (intermediate == top || offset + pnum_inter < size_inter)) { |
64 | - n = pnum_inter; | 64 | - n = pnum_inter; |
65 | - } | 65 | - } |
66 | - | 66 | - |
67 | - if (intermediate == base) { | 67 | - if (intermediate == base) { |
68 | - break; | 68 | - break; |
69 | - } | 69 | - } |
70 | - | 70 | - |
71 | - intermediate = bdrv_filter_or_cow_bs(intermediate); | 71 | - intermediate = bdrv_filter_or_cow_bs(intermediate); |
72 | + int ret = bdrv_common_block_status_above(top, base, include_base, false, | 72 | + int ret = bdrv_common_block_status_above(top, base, include_base, false, |
73 | + offset, bytes, pnum, NULL, NULL); | 73 | + offset, bytes, pnum, NULL, NULL); |
74 | + if (ret < 0) { | 74 | + if (ret < 0) { |
75 | + return ret; | 75 | + return ret; |
76 | } | 76 | } |
77 | 77 | ||
78 | - *pnum = n; | 78 | - *pnum = n; |
79 | - return 0; | 79 | - return 0; |
80 | + return !!(ret & BDRV_BLOCK_ALLOCATED); | 80 | + return !!(ret & BDRV_BLOCK_ALLOCATED); |
81 | } | 81 | } |
82 | 82 | ||
83 | int coroutine_fn | 83 | int coroutine_fn |
84 | -- | 84 | -- |
85 | 2.26.2 | 85 | 2.26.2 |
86 | 86 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | These cases are fixed by previous patches around block_status and | 3 | These cases are fixed by previous patches around block_status and |
4 | is_allocated. | 4 | is_allocated. |
5 | 5 | ||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 8 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
9 | Message-id: 20200924194003.22080-6-vsementsov@virtuozzo.com | 9 | Message-id: 20200924194003.22080-6-vsementsov@virtuozzo.com |
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | --- | 11 | --- |
12 | tests/qemu-iotests/274 | 20 +++++++++++ | 12 | tests/qemu-iotests/274 | 20 +++++++++++ |
13 | tests/qemu-iotests/274.out | 68 ++++++++++++++++++++++++++++++++++++++ | 13 | tests/qemu-iotests/274.out | 68 ++++++++++++++++++++++++++++++++++++++ |
14 | 2 files changed, 88 insertions(+) | 14 | 2 files changed, 88 insertions(+) |
15 | 15 | ||
16 | diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274 | 16 | diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274 |
17 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100755 |
18 | --- a/tests/qemu-iotests/274 | 18 | --- a/tests/qemu-iotests/274 |
19 | +++ b/tests/qemu-iotests/274 | 19 | +++ b/tests/qemu-iotests/274 |
20 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base') as base, \ | 20 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base') as base, \ |
21 | iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid) | 21 | iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid) |
22 | iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid) | 22 | iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid) |
23 | 23 | ||
24 | + iotests.log('=== Testing qemu-img commit (top -> base) ===') | 24 | + iotests.log('=== Testing qemu-img commit (top -> base) ===') |
25 | + | 25 | + |
26 | + create_chain() | 26 | + create_chain() |
27 | + iotests.qemu_img_log('commit', '-b', base, top) | 27 | + iotests.qemu_img_log('commit', '-b', base, top) |
28 | + iotests.img_info_log(base) | 28 | + iotests.img_info_log(base) |
29 | + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) | 29 | + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) |
30 | + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), base) | 30 | + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), base) |
31 | + | 31 | + |
32 | + iotests.log('=== Testing QMP active commit (top -> base) ===') | 32 | + iotests.log('=== Testing QMP active commit (top -> base) ===') |
33 | + | 33 | + |
34 | + create_chain() | 34 | + create_chain() |
35 | + with create_vm() as vm: | 35 | + with create_vm() as vm: |
36 | + vm.launch() | 36 | + vm.launch() |
37 | + vm.qmp_log('block-commit', device='top', base_node='base', | 37 | + vm.qmp_log('block-commit', device='top', base_node='base', |
38 | + job_id='job0', auto_dismiss=False) | 38 | + job_id='job0', auto_dismiss=False) |
39 | + vm.run_job('job0', wait=5) | 39 | + vm.run_job('job0', wait=5) |
40 | + | 40 | + |
41 | + iotests.img_info_log(mid) | 41 | + iotests.img_info_log(mid) |
42 | + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) | 42 | + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) |
43 | + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), base) | 43 | + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), base) |
44 | 44 | ||
45 | iotests.log('== Resize tests ==') | 45 | iotests.log('== Resize tests ==') |
46 | 46 | ||
47 | diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out | 47 | diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out |
48 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/tests/qemu-iotests/274.out | 49 | --- a/tests/qemu-iotests/274.out |
50 | +++ b/tests/qemu-iotests/274.out | 50 | +++ b/tests/qemu-iotests/274.out |
51 | @@ -XXX,XX +XXX,XX @@ read 1048576/1048576 bytes at offset 0 | 51 | @@ -XXX,XX +XXX,XX @@ read 1048576/1048576 bytes at offset 0 |
52 | read 1048576/1048576 bytes at offset 1048576 | 52 | read 1048576/1048576 bytes at offset 1048576 |
53 | 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 53 | 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
54 | 54 | ||
55 | +=== Testing qemu-img commit (top -> base) === | 55 | +=== Testing qemu-img commit (top -> base) === |
56 | +Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 lazy_refcounts=off refcount_bits=16 | 56 | +Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 lazy_refcounts=off refcount_bits=16 |
57 | + | 57 | + |
58 | +Formatting 'TEST_DIR/PID-mid', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 backing_file=TEST_DIR/PID-base backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 | 58 | +Formatting 'TEST_DIR/PID-mid', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 backing_file=TEST_DIR/PID-base backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 |
59 | + | 59 | + |
60 | +Formatting 'TEST_DIR/PID-top', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 backing_file=TEST_DIR/PID-mid backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 | 60 | +Formatting 'TEST_DIR/PID-top', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 backing_file=TEST_DIR/PID-mid backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 |
61 | + | 61 | + |
62 | +wrote 2097152/2097152 bytes at offset 0 | 62 | +wrote 2097152/2097152 bytes at offset 0 |
63 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 63 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
64 | + | 64 | + |
65 | +Image committed. | 65 | +Image committed. |
66 | + | 66 | + |
67 | +image: TEST_IMG | 67 | +image: TEST_IMG |
68 | +file format: IMGFMT | 68 | +file format: IMGFMT |
69 | +virtual size: 2 MiB (2097152 bytes) | 69 | +virtual size: 2 MiB (2097152 bytes) |
70 | +cluster_size: 65536 | 70 | +cluster_size: 65536 |
71 | +Format specific information: | 71 | +Format specific information: |
72 | + compat: 1.1 | 72 | + compat: 1.1 |
73 | + compression type: zlib | 73 | + compression type: zlib |
74 | + lazy refcounts: false | 74 | + lazy refcounts: false |
75 | + refcount bits: 16 | 75 | + refcount bits: 16 |
76 | + corrupt: false | 76 | + corrupt: false |
77 | + extended l2: false | 77 | + extended l2: false |
78 | + | 78 | + |
79 | +read 1048576/1048576 bytes at offset 0 | 79 | +read 1048576/1048576 bytes at offset 0 |
80 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 80 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
81 | + | 81 | + |
82 | +read 1048576/1048576 bytes at offset 1048576 | 82 | +read 1048576/1048576 bytes at offset 1048576 |
83 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 83 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
84 | + | 84 | + |
85 | +=== Testing QMP active commit (top -> base) === | 85 | +=== Testing QMP active commit (top -> base) === |
86 | +Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 lazy_refcounts=off refcount_bits=16 | 86 | +Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 lazy_refcounts=off refcount_bits=16 |
87 | + | 87 | + |
88 | +Formatting 'TEST_DIR/PID-mid', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 backing_file=TEST_DIR/PID-base backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 | 88 | +Formatting 'TEST_DIR/PID-mid', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=1048576 backing_file=TEST_DIR/PID-base backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 |
89 | + | 89 | + |
90 | +Formatting 'TEST_DIR/PID-top', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 backing_file=TEST_DIR/PID-mid backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 | 90 | +Formatting 'TEST_DIR/PID-top', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=2097152 backing_file=TEST_DIR/PID-mid backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 |
91 | + | 91 | + |
92 | +wrote 2097152/2097152 bytes at offset 0 | 92 | +wrote 2097152/2097152 bytes at offset 0 |
93 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 93 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
94 | + | 94 | + |
95 | +{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-node": "base", "device": "top", "job-id": "job0"}} | 95 | +{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-node": "base", "device": "top", "job-id": "job0"}} |
96 | +{"return": {}} | 96 | +{"return": {}} |
97 | +{"execute": "job-complete", "arguments": {"id": "job0"}} | 97 | +{"execute": "job-complete", "arguments": {"id": "job0"}} |
98 | +{"return": {}} | 98 | +{"return": {}} |
99 | +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} | 99 | +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} |
100 | +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} | 100 | +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} |
101 | +{"execute": "job-dismiss", "arguments": {"id": "job0"}} | 101 | +{"execute": "job-dismiss", "arguments": {"id": "job0"}} |
102 | +{"return": {}} | 102 | +{"return": {}} |
103 | +image: TEST_IMG | 103 | +image: TEST_IMG |
104 | +file format: IMGFMT | 104 | +file format: IMGFMT |
105 | +virtual size: 1 MiB (1048576 bytes) | 105 | +virtual size: 1 MiB (1048576 bytes) |
106 | +cluster_size: 65536 | 106 | +cluster_size: 65536 |
107 | +backing file: TEST_DIR/PID-base | 107 | +backing file: TEST_DIR/PID-base |
108 | +backing file format: IMGFMT | 108 | +backing file format: IMGFMT |
109 | +Format specific information: | 109 | +Format specific information: |
110 | + compat: 1.1 | 110 | + compat: 1.1 |
111 | + compression type: zlib | 111 | + compression type: zlib |
112 | + lazy refcounts: false | 112 | + lazy refcounts: false |
113 | + refcount bits: 16 | 113 | + refcount bits: 16 |
114 | + corrupt: false | 114 | + corrupt: false |
115 | + extended l2: false | 115 | + extended l2: false |
116 | + | 116 | + |
117 | +read 1048576/1048576 bytes at offset 0 | 117 | +read 1048576/1048576 bytes at offset 0 |
118 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 118 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
119 | + | 119 | + |
120 | +read 1048576/1048576 bytes at offset 1048576 | 120 | +read 1048576/1048576 bytes at offset 1048576 |
121 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 121 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
122 | + | 122 | + |
123 | == Resize tests == | 123 | == Resize tests == |
124 | === preallocation=off === | 124 | === preallocation=off === |
125 | Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=6442450944 lazy_refcounts=off refcount_bits=16 | 125 | Formatting 'TEST_DIR/PID-base', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=6442450944 lazy_refcounts=off refcount_bits=16 |
126 | -- | 126 | -- |
127 | 2.26.2 | 127 | 2.26.2 |
128 | 128 | diff view generated by jsdifflib |