1 | The following changes since commit bfec359afba088aaacc7d316f43302f28c6e642a: | 1 | The following changes since commit 497d415d76b9f59fcae27f22df1ca2c3fa4df64e: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qdev-2017-04-21' into staging (2017-04-21 11:42:03 +0100) | 3 | Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20201008-1' into staging (2020-10-08 21:41:20 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/codyprime/qemu-kvm-jtc.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 1507631e438930bc07f776f303af127a9cdb4d41: | 9 | for you to fetch changes up to e969c7b045c90368bc3a5db3479e70b6f0ecb828: |
10 | 10 | ||
11 | qemu-iotests: _cleanup_qemu must be called on exit (2017-04-21 08:32:44 -0400) | 11 | iotests: add commit top->base cases to 274 (2020-10-09 14:32:24 +0100) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | This pull request includes the vhost-user-blk server by Coiby Xu, the block | ||
17 | coroutine code generator by Vladimir Sementsov-Ogievskiy, nvme block driver | ||
18 | statistics by Philippe Mathieu-Daudé, and cleanups/fixes/additions to the | ||
19 | vhost-user-blk server by me. | ||
12 | 20 | ||
13 | ---------------------------------------------------------------- | 21 | ---------------------------------------------------------------- |
14 | 22 | ||
15 | Block patches for 2.10 | 23 | Coiby Xu (7): |
24 | libvhost-user: Allow vu_message_read to be replaced | ||
25 | libvhost-user: remove watch for kick_fd when de-initialize vu-dev | ||
26 | util/vhost-user-server: generic vhost user server | ||
27 | block: move logical block size check function to a common utility | ||
28 | function | ||
29 | block/export: vhost-user block device backend server | ||
30 | test: new qTest case to test the vhost-user-blk-server | ||
31 | MAINTAINERS: Add vhost-user block device backend server maintainer | ||
16 | 32 | ||
17 | ---------------------------------------------------------------- | 33 | Philippe Mathieu-Daudé (1): |
34 | block/nvme: Add driver statistics for access alignment and hw errors | ||
18 | 35 | ||
19 | Ashish Mittal (2): | 36 | Stefan Hajnoczi (17): |
20 | block/vxhs.c: Add support for a new block device type called "vxhs" | 37 | util/vhost-user-server: s/fileds/fields/ typo fix |
21 | block/vxhs.c: Add qemu-iotests for new block device type "vxhs" | 38 | util/vhost-user-server: drop unnecessary QOM cast |
39 | util/vhost-user-server: drop unnecessary watch deletion | ||
40 | block/export: consolidate request structs into VuBlockReq | ||
41 | util/vhost-user-server: drop unused DevicePanicNotifier | ||
42 | util/vhost-user-server: fix memory leak in vu_message_read() | ||
43 | util/vhost-user-server: check EOF when reading payload | ||
44 | util/vhost-user-server: rework vu_client_trip() coroutine lifecycle | ||
45 | block/export: report flush errors | ||
46 | block/export: convert vhost-user-blk server to block export API | ||
47 | util/vhost-user-server: move header to include/ | ||
48 | util/vhost-user-server: use static library in meson.build | ||
49 | qemu-storage-daemon: avoid compiling blockdev_ss twice | ||
50 | block: move block exports to libblockdev | ||
51 | block/export: add iothread and fixed-iothread options | ||
52 | block/export: add vhost-user-blk multi-queue support | ||
53 | tests/qtest: add multi-queue test case to vhost-user-blk-test | ||
22 | 54 | ||
23 | Jeff Cody (10): | 55 | Vladimir Sementsov-Ogievskiy (5): |
24 | qemu-iotests: exclude vxhs from image creation via protocol | 56 | block/io: fix bdrv_co_block_status_above |
25 | block: add bdrv_set_read_only() helper function | 57 | block/io: bdrv_common_block_status_above: support include_base |
26 | block: do not set BDS read_only if copy_on_read enabled | 58 | block/io: bdrv_common_block_status_above: support bs == base |
27 | block: honor BDRV_O_ALLOW_RDWR when clearing bs->read_only | 59 | block/io: fix bdrv_is_allocated_above |
28 | block: code movement | 60 | iotests: add commit top->base cases to 274 |
29 | block: introduce bdrv_can_set_read_only() | ||
30 | block: use bdrv_can_set_read_only() during reopen | ||
31 | block/rbd - update variable names to more apt names | ||
32 | block/rbd: Add support for reopen() | ||
33 | qemu-iotests: _cleanup_qemu must be called on exit | ||
34 | 61 | ||
35 | block.c | 56 +++- | 62 | MAINTAINERS | 10 + |
36 | block/Makefile.objs | 2 + | 63 | qapi/block-core.json | 24 +- |
37 | block/bochs.c | 5 +- | 64 | qapi/block-export.json | 36 +- |
38 | block/cloop.c | 5 +- | 65 | block/coroutines.h | 2 + |
39 | block/dmg.c | 6 +- | 66 | block/export/vhost-user-blk-server.h | 19 + |
40 | block/rbd.c | 65 +++-- | 67 | contrib/libvhost-user/libvhost-user.h | 21 + |
41 | block/trace-events | 17 ++ | 68 | include/qemu/vhost-user-server.h | 65 ++ |
42 | block/vvfat.c | 19 +- | 69 | tests/qtest/libqos/libqtest.h | 17 + |
43 | block/vxhs.c | 575 +++++++++++++++++++++++++++++++++++++++ | 70 | tests/qtest/libqos/vhost-user-blk.h | 48 ++ |
44 | configure | 39 +++ | 71 | util/block-helpers.h | 19 + |
45 | include/block/block.h | 2 + | 72 | block/export/export.c | 37 +- |
46 | qapi/block-core.json | 23 +- | 73 | block/export/vhost-user-blk-server.c | 431 +++++++++++ |
47 | tests/qemu-iotests/017 | 1 + | 74 | block/io.c | 132 ++-- |
48 | tests/qemu-iotests/020 | 1 + | 75 | block/nvme.c | 27 + |
49 | tests/qemu-iotests/028 | 1 + | 76 | block/qcow2.c | 16 +- |
50 | tests/qemu-iotests/029 | 1 + | 77 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- |
51 | tests/qemu-iotests/073 | 1 + | 78 | contrib/libvhost-user/libvhost-user.c | 15 +- |
52 | tests/qemu-iotests/094 | 11 +- | 79 | hw/core/qdev-properties-system.c | 31 +- |
53 | tests/qemu-iotests/102 | 5 +- | 80 | nbd/server.c | 2 - |
54 | tests/qemu-iotests/109 | 1 + | 81 | qemu-nbd.c | 21 +- |
55 | tests/qemu-iotests/114 | 1 + | 82 | softmmu/vl.c | 4 + |
56 | tests/qemu-iotests/117 | 1 + | 83 | stubs/blk-exp-close-all.c | 7 + |
57 | tests/qemu-iotests/130 | 2 + | 84 | tests/qtest/libqos/vhost-user-blk.c | 129 ++++ |
58 | tests/qemu-iotests/134 | 1 + | 85 | tests/qtest/libqtest.c | 36 +- |
59 | tests/qemu-iotests/140 | 1 + | 86 | tests/qtest/vhost-user-blk-test.c | 822 +++++++++++++++++++++ |
60 | tests/qemu-iotests/141 | 1 + | 87 | tests/vhost-user-bridge.c | 2 + |
61 | tests/qemu-iotests/143 | 1 + | 88 | tools/virtiofsd/fuse_virtio.c | 4 +- |
62 | tests/qemu-iotests/156 | 2 + | 89 | util/block-helpers.c | 46 ++ |
63 | tests/qemu-iotests/158 | 1 + | 90 | util/vhost-user-server.c | 446 +++++++++++ |
64 | tests/qemu-iotests/common | 6 + | 91 | block/export/meson.build | 3 +- |
65 | tests/qemu-iotests/common.config | 13 + | 92 | contrib/libvhost-user/meson.build | 1 + |
66 | tests/qemu-iotests/common.filter | 1 + | 93 | meson.build | 22 +- |
67 | tests/qemu-iotests/common.rc | 19 ++ | 94 | nbd/meson.build | 2 + |
68 | 33 files changed, 844 insertions(+), 42 deletions(-) | 95 | storage-daemon/meson.build | 3 +- |
69 | create mode 100644 block/vxhs.c | 96 | stubs/meson.build | 1 + |
97 | tests/qemu-iotests/274 | 20 + | ||
98 | tests/qemu-iotests/274.out | 68 ++ | ||
99 | tests/qtest/libqos/meson.build | 1 + | ||
100 | tests/qtest/meson.build | 4 +- | ||
101 | util/meson.build | 4 + | ||
102 | 40 files changed, 2476 insertions(+), 124 deletions(-) | ||
103 | create mode 100644 block/export/vhost-user-blk-server.h | ||
104 | create mode 100644 include/qemu/vhost-user-server.h | ||
105 | create mode 100644 tests/qtest/libqos/vhost-user-blk.h | ||
106 | create mode 100644 util/block-helpers.h | ||
107 | create mode 100644 block/export/vhost-user-blk-server.c | ||
108 | create mode 100644 stubs/blk-exp-close-all.c | ||
109 | create mode 100644 tests/qtest/libqos/vhost-user-blk.c | ||
110 | create mode 100644 tests/qtest/vhost-user-blk-test.c | ||
111 | create mode 100644 util/block-helpers.c | ||
112 | create mode 100644 util/vhost-user-server.c | ||
70 | 113 | ||
71 | -- | 114 | -- |
72 | 2.9.3 | 115 | 2.26.2 |
73 | 116 | ||
74 | diff view generated by jsdifflib |
1 | We have a helper wrapper for checking for the BDS read_only flag, | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | add a helper wrapper to set the read_only flag as well. | ||
3 | 2 | ||
4 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 3 | Keep statistics of some hardware errors, and number of |
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 4 | aligned/unaligned I/O accesses. |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 5 | |
7 | Message-id: 9b18972d05f5fa2ac16c014f0af98d680553048d.1491597120.git.jcody@redhat.com | 6 | QMP example booting a full RHEL 8.3 aarch64 guest: |
7 | |||
8 | { "execute": "query-blockstats" } | ||
9 | { | ||
10 | "return": [ | ||
11 | { | ||
12 | "device": "", | ||
13 | "node-name": "drive0", | ||
14 | "stats": { | ||
15 | "flush_total_time_ns": 6026948, | ||
16 | "wr_highest_offset": 3383991230464, | ||
17 | "wr_total_time_ns": 807450995, | ||
18 | "failed_wr_operations": 0, | ||
19 | "failed_rd_operations": 0, | ||
20 | "wr_merged": 3, | ||
21 | "wr_bytes": 50133504, | ||
22 | "failed_unmap_operations": 0, | ||
23 | "failed_flush_operations": 0, | ||
24 | "account_invalid": false, | ||
25 | "rd_total_time_ns": 1846979900, | ||
26 | "flush_operations": 130, | ||
27 | "wr_operations": 659, | ||
28 | "rd_merged": 1192, | ||
29 | "rd_bytes": 218244096, | ||
30 | "account_failed": false, | ||
31 | "idle_time_ns": 2678641497, | ||
32 | "rd_operations": 7406, | ||
33 | }, | ||
34 | "driver-specific": { | ||
35 | "driver": "nvme", | ||
36 | "completion-errors": 0, | ||
37 | "unaligned-accesses": 2959, | ||
38 | "aligned-accesses": 4477 | ||
39 | }, | ||
40 | "qdev": "/machine/peripheral-anon/device[0]/virtio-backend" | ||
41 | } | ||
42 | ] | ||
43 | } | ||
44 | |||
45 | Suggested-by: Stefan Hajnoczi <stefanha@gmail.com> | ||
46 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
47 | Acked-by: Markus Armbruster <armbru@redhat.com> | ||
48 | Message-id: 20201001162939.1567915-1-philmd@redhat.com | ||
49 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 50 | --- |
9 | block.c | 5 +++++ | 51 | qapi/block-core.json | 24 +++++++++++++++++++++++- |
10 | block/bochs.c | 2 +- | 52 | block/nvme.c | 27 +++++++++++++++++++++++++++ |
11 | block/cloop.c | 2 +- | 53 | 2 files changed, 50 insertions(+), 1 deletion(-) |
12 | block/dmg.c | 2 +- | ||
13 | block/rbd.c | 2 +- | ||
14 | block/vvfat.c | 4 ++-- | ||
15 | include/block/block.h | 1 + | ||
16 | 7 files changed, 12 insertions(+), 6 deletions(-) | ||
17 | 54 | ||
18 | diff --git a/block.c b/block.c | 55 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
19 | index XXXXXXX..XXXXXXX 100644 | 56 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/block.c | 57 | --- a/qapi/block-core.json |
21 | +++ b/block.c | 58 | +++ b/qapi/block-core.json |
22 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 59 | @@ -XXX,XX +XXX,XX @@ |
60 | 'discard-nb-failed': 'uint64', | ||
61 | 'discard-bytes-ok': 'uint64' } } | ||
62 | |||
63 | +## | ||
64 | +# @BlockStatsSpecificNvme: | ||
65 | +# | ||
66 | +# NVMe driver statistics | ||
67 | +# | ||
68 | +# @completion-errors: The number of completion errors. | ||
69 | +# | ||
70 | +# @aligned-accesses: The number of aligned accesses performed by | ||
71 | +# the driver. | ||
72 | +# | ||
73 | +# @unaligned-accesses: The number of unaligned accesses performed by | ||
74 | +# the driver. | ||
75 | +# | ||
76 | +# Since: 5.2 | ||
77 | +## | ||
78 | +{ 'struct': 'BlockStatsSpecificNvme', | ||
79 | + 'data': { | ||
80 | + 'completion-errors': 'uint64', | ||
81 | + 'aligned-accesses': 'uint64', | ||
82 | + 'unaligned-accesses': 'uint64' } } | ||
83 | + | ||
84 | ## | ||
85 | # @BlockStatsSpecific: | ||
86 | # | ||
87 | @@ -XXX,XX +XXX,XX @@ | ||
88 | 'discriminator': 'driver', | ||
89 | 'data': { | ||
90 | 'file': 'BlockStatsSpecificFile', | ||
91 | - 'host_device': 'BlockStatsSpecificFile' } } | ||
92 | + 'host_device': 'BlockStatsSpecificFile', | ||
93 | + 'nvme': 'BlockStatsSpecificNvme' } } | ||
94 | |||
95 | ## | ||
96 | # @BlockStats: | ||
97 | diff --git a/block/nvme.c b/block/nvme.c | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/block/nvme.c | ||
100 | +++ b/block/nvme.c | ||
101 | @@ -XXX,XX +XXX,XX @@ struct BDRVNVMeState { | ||
102 | |||
103 | /* PCI address (required for nvme_refresh_filename()) */ | ||
104 | char *device; | ||
105 | + | ||
106 | + struct { | ||
107 | + uint64_t completion_errors; | ||
108 | + uint64_t aligned_accesses; | ||
109 | + uint64_t unaligned_accesses; | ||
110 | + } stats; | ||
111 | }; | ||
112 | |||
113 | #define NVME_BLOCK_OPT_DEVICE "device" | ||
114 | @@ -XXX,XX +XXX,XX @@ static bool nvme_process_completion(NVMeQueuePair *q) | ||
115 | break; | ||
116 | } | ||
117 | ret = nvme_translate_error(c); | ||
118 | + if (ret) { | ||
119 | + s->stats.completion_errors++; | ||
120 | + } | ||
121 | q->cq.head = (q->cq.head + 1) % NVME_QUEUE_SIZE; | ||
122 | if (!q->cq.head) { | ||
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, | ||
125 | assert(QEMU_IS_ALIGNED(bytes, s->page_size)); | ||
126 | assert(bytes <= s->max_transfer); | ||
127 | if (nvme_qiov_aligned(bs, qiov)) { | ||
128 | + s->stats.aligned_accesses++; | ||
129 | return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flags); | ||
23 | } | 130 | } |
131 | + s->stats.unaligned_accesses++; | ||
132 | trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); | ||
133 | buf = qemu_try_memalign(s->page_size, bytes); | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ static void nvme_unregister_buf(BlockDriverState *bs, void *host) | ||
136 | qemu_vfio_dma_unmap(s->vfio, host); | ||
24 | } | 137 | } |
25 | 138 | ||
26 | +void bdrv_set_read_only(BlockDriverState *bs, bool read_only) | 139 | +static BlockStatsSpecific *nvme_get_specific_stats(BlockDriverState *bs) |
27 | +{ | 140 | +{ |
28 | + bs->read_only = read_only; | 141 | + BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); |
142 | + BDRVNVMeState *s = bs->opaque; | ||
143 | + | ||
144 | + stats->driver = BLOCKDEV_DRIVER_NVME; | ||
145 | + stats->u.nvme = (BlockStatsSpecificNvme) { | ||
146 | + .completion_errors = s->stats.completion_errors, | ||
147 | + .aligned_accesses = s->stats.aligned_accesses, | ||
148 | + .unaligned_accesses = s->stats.unaligned_accesses, | ||
149 | + }; | ||
150 | + | ||
151 | + return stats; | ||
29 | +} | 152 | +} |
30 | + | 153 | + |
31 | void bdrv_get_full_backing_filename_from_filename(const char *backed, | 154 | static const char *const nvme_strong_runtime_opts[] = { |
32 | const char *backing, | 155 | NVME_BLOCK_OPT_DEVICE, |
33 | char *dest, size_t sz, | 156 | NVME_BLOCK_OPT_NAMESPACE, |
34 | diff --git a/block/bochs.c b/block/bochs.c | 157 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nvme = { |
35 | index XXXXXXX..XXXXXXX 100644 | 158 | .bdrv_refresh_filename = nvme_refresh_filename, |
36 | --- a/block/bochs.c | 159 | .bdrv_refresh_limits = nvme_refresh_limits, |
37 | +++ b/block/bochs.c | 160 | .strong_runtime_opts = nvme_strong_runtime_opts, |
38 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | 161 | + .bdrv_get_specific_stats = nvme_get_specific_stats, |
39 | return -EINVAL; | 162 | |
40 | } | 163 | .bdrv_detach_aio_context = nvme_detach_aio_context, |
41 | 164 | .bdrv_attach_aio_context = nvme_attach_aio_context, | |
42 | - bs->read_only = true; /* no write support yet */ | ||
43 | + bdrv_set_read_only(bs, true); /* no write support yet */ | ||
44 | |||
45 | ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); | ||
46 | if (ret < 0) { | ||
47 | diff --git a/block/cloop.c b/block/cloop.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/block/cloop.c | ||
50 | +++ b/block/cloop.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
52 | return -EINVAL; | ||
53 | } | ||
54 | |||
55 | - bs->read_only = true; | ||
56 | + bdrv_set_read_only(bs, true); | ||
57 | |||
58 | /* read header */ | ||
59 | ret = bdrv_pread(bs->file, 128, &s->block_size, 4); | ||
60 | diff --git a/block/dmg.c b/block/dmg.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/block/dmg.c | ||
63 | +++ b/block/dmg.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | ||
65 | } | ||
66 | |||
67 | block_module_load_one("dmg-bz2"); | ||
68 | - bs->read_only = true; | ||
69 | + bdrv_set_read_only(bs, true); | ||
70 | |||
71 | s->n_chunks = 0; | ||
72 | s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; | ||
73 | diff --git a/block/rbd.c b/block/rbd.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/block/rbd.c | ||
76 | +++ b/block/rbd.c | ||
77 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
78 | goto failed_open; | ||
79 | } | ||
80 | |||
81 | - bs->read_only = (s->snap != NULL); | ||
82 | + bdrv_set_read_only(bs, (s->snap != NULL)); | ||
83 | |||
84 | qemu_opts_del(opts); | ||
85 | return 0; | ||
86 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/block/vvfat.c | ||
89 | +++ b/block/vvfat.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
91 | s->current_cluster=0xffffffff; | ||
92 | |||
93 | /* read only is the default for safety */ | ||
94 | - bs->read_only = true; | ||
95 | + bdrv_set_read_only(bs, true); | ||
96 | s->qcow = NULL; | ||
97 | s->qcow_filename = NULL; | ||
98 | s->fat2 = NULL; | ||
99 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
100 | if (ret < 0) { | ||
101 | goto fail; | ||
102 | } | ||
103 | - bs->read_only = false; | ||
104 | + bdrv_set_read_only(bs, false); | ||
105 | } | ||
106 | |||
107 | bs->total_sectors = cyls * heads * secs; | ||
108 | diff --git a/include/block/block.h b/include/block/block.h | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/include/block/block.h | ||
111 | +++ b/include/block/block.h | ||
112 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | ||
113 | int64_t sector_num, int nb_sectors, int *pnum); | ||
114 | |||
115 | bool bdrv_is_read_only(BlockDriverState *bs); | ||
116 | +void bdrv_set_read_only(BlockDriverState *bs, bool read_only); | ||
117 | bool bdrv_is_sg(BlockDriverState *bs); | ||
118 | bool bdrv_is_inserted(BlockDriverState *bs); | ||
119 | int bdrv_media_changed(BlockDriverState *bs); | ||
120 | -- | 165 | -- |
121 | 2.9.3 | 166 | 2.26.2 |
122 | 167 | ||
123 | diff view generated by jsdifflib |
1 | Introduce check function for setting read_only flags. Will return < 0 on | 1 | From: Coiby Xu <coiby.xu@gmail.com> |
---|---|---|---|
2 | error, with appropriate Error value set. Does not alter any flags. | ||
3 | 2 | ||
4 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 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 | ||
5 | guest. For slave channel, we still use the default vu_message_read. | ||
6 | |||
7 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
8 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | Message-id: 20200918080912.321299-2-coiby.xu@gmail.com |
7 | Message-id: e2bba34ac3bc76a0c42adc390413f358ae0566e8.1491597120.git.jcody@redhat.com | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | --- | 12 | --- |
9 | block.c | 14 +++++++++++++- | 13 | contrib/libvhost-user/libvhost-user.h | 21 +++++++++++++++++++++ |
10 | include/block/block.h | 1 + | 14 | contrib/libvhost-user/libvhost-user-glib.c | 2 +- |
11 | 2 files changed, 14 insertions(+), 1 deletion(-) | 15 | contrib/libvhost-user/libvhost-user.c | 14 +++++++------- |
16 | tests/vhost-user-bridge.c | 2 ++ | ||
17 | tools/virtiofsd/fuse_virtio.c | 4 ++-- | ||
18 | 5 files changed, 33 insertions(+), 10 deletions(-) | ||
12 | 19 | ||
13 | diff --git a/block.c b/block.c | 20 | diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h |
14 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block.c | 22 | --- a/contrib/libvhost-user/libvhost-user.h |
16 | +++ b/block.c | 23 | +++ b/contrib/libvhost-user/libvhost-user.h |
17 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_read_only(BlockDriverState *bs) | 24 | @@ -XXX,XX +XXX,XX @@ |
18 | return bs->read_only; | 25 | */ |
26 | #define VHOST_USER_MAX_RAM_SLOTS 32 | ||
27 | |||
28 | +#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) | ||
29 | + | ||
30 | typedef enum VhostSetConfigType { | ||
31 | VHOST_SET_CONFIG_TYPE_MASTER = 0, | ||
32 | VHOST_SET_CONFIG_TYPE_MIGRATION = 1, | ||
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); | ||
35 | typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, | ||
36 | int *do_reply); | ||
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); | ||
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); | ||
41 | @@ -XXX,XX +XXX,XX @@ struct VuDev { | ||
42 | bool broken; | ||
43 | uint16_t max_queues; | ||
44 | |||
45 | + /* @read_msg: custom method to read vhost-user message | ||
46 | + * | ||
47 | + * Read data from vhost_user socket fd and fill up | ||
48 | + * the passed VhostUserMsg *vmsg struct. | ||
49 | + * | ||
50 | + * If reading fails, it should close the received set of file | ||
51 | + * descriptors as socket message's auxiliary data. | ||
52 | + * | ||
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 | ||
55 | + * calling vu_init | ||
56 | + * | ||
57 | + * Returns: true if vhost-user message successfully received, | ||
58 | + * otherwise return false. | ||
59 | + * | ||
60 | + */ | ||
61 | + vu_read_msg_cb read_msg; | ||
62 | /* @set_watch: add or update the given fd to the watch set, | ||
63 | * call cb when condition is met */ | ||
64 | vu_set_watch_cb set_watch; | ||
65 | @@ -XXX,XX +XXX,XX @@ bool vu_init(VuDev *dev, | ||
66 | uint16_t max_queues, | ||
67 | int socket, | ||
68 | vu_panic_cb panic, | ||
69 | + vu_read_msg_cb read_msg, | ||
70 | vu_set_watch_cb set_watch, | ||
71 | vu_remove_watch_cb remove_watch, | ||
72 | const VuDevIface *iface); | ||
73 | diff --git a/contrib/libvhost-user/libvhost-user-glib.c b/contrib/libvhost-user/libvhost-user-glib.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/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, | ||
78 | g_assert(dev); | ||
79 | g_assert(iface); | ||
80 | |||
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, | ||
83 | remove_watch, iface)) { | ||
84 | return false; | ||
85 | } | ||
86 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/contrib/libvhost-user/libvhost-user.c | ||
89 | +++ b/contrib/libvhost-user/libvhost-user.c | ||
90 | @@ -XXX,XX +XXX,XX @@ | ||
91 | /* The version of inflight buffer */ | ||
92 | #define INFLIGHT_VERSION 1 | ||
93 | |||
94 | -#define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) | ||
95 | - | ||
96 | /* The version of the protocol we support */ | ||
97 | #define VHOST_USER_VERSION 1 | ||
98 | #define LIBVHOST_USER_DEBUG 0 | ||
99 | @@ -XXX,XX +XXX,XX @@ have_userfault(void) | ||
19 | } | 100 | } |
20 | 101 | ||
21 | -int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 102 | static bool |
22 | +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 103 | -vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) |
104 | +vu_message_read_default(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) | ||
23 | { | 105 | { |
24 | /* Do not set read_only if copy_on_read is enabled */ | 106 | char control[CMSG_SPACE(VHOST_MEMORY_BASELINE_NREGIONS * sizeof(int))] = {}; |
25 | if (bs->copy_on_read && read_only) { | 107 | struct iovec iov = { |
26 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 108 | @@ -XXX,XX +XXX,XX @@ vu_process_message_reply(VuDev *dev, const VhostUserMsg *vmsg) |
27 | return -EPERM; | 109 | goto out; |
28 | } | 110 | } |
29 | 111 | ||
30 | + return 0; | 112 | - if (!vu_message_read(dev, dev->slave_fd, &msg_reply)) { |
31 | +} | 113 | + if (!vu_message_read_default(dev, dev->slave_fd, &msg_reply)) { |
32 | + | 114 | goto out; |
33 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 115 | } |
34 | +{ | 116 | |
35 | + int ret = 0; | 117 | @@ -XXX,XX +XXX,XX @@ vu_set_mem_table_exec_postcopy(VuDev *dev, VhostUserMsg *vmsg) |
36 | + | 118 | /* Wait for QEMU to confirm that it's registered the handler for the |
37 | + ret = bdrv_can_set_read_only(bs, read_only, errp); | 119 | * faults. |
38 | + if (ret < 0) { | 120 | */ |
39 | + return ret; | 121 | - if (!vu_message_read(dev, dev->sock, vmsg) || |
40 | + } | 122 | + if (!dev->read_msg(dev, dev->sock, vmsg) || |
41 | + | 123 | vmsg->size != sizeof(vmsg->payload.u64) || |
42 | bs->read_only = read_only; | 124 | vmsg->payload.u64 != 0) { |
125 | vu_panic(dev, "failed to receive valid ack for postcopy set-mem-table"); | ||
126 | @@ -XXX,XX +XXX,XX @@ vu_dispatch(VuDev *dev) | ||
127 | int reply_requested; | ||
128 | bool need_reply, success = false; | ||
129 | |||
130 | - if (!vu_message_read(dev, dev->sock, &vmsg)) { | ||
131 | + if (!dev->read_msg(dev, dev->sock, &vmsg)) { | ||
132 | goto end; | ||
133 | } | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, | ||
136 | uint16_t max_queues, | ||
137 | int socket, | ||
138 | vu_panic_cb panic, | ||
139 | + vu_read_msg_cb read_msg, | ||
140 | vu_set_watch_cb set_watch, | ||
141 | vu_remove_watch_cb remove_watch, | ||
142 | const VuDevIface *iface) | ||
143 | @@ -XXX,XX +XXX,XX @@ vu_init(VuDev *dev, | ||
144 | |||
145 | dev->sock = socket; | ||
146 | dev->panic = panic; | ||
147 | + dev->read_msg = read_msg ? read_msg : vu_message_read_default; | ||
148 | dev->set_watch = set_watch; | ||
149 | dev->remove_watch = remove_watch; | ||
150 | dev->iface = iface; | ||
151 | @@ -XXX,XX +XXX,XX @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync) | ||
152 | |||
153 | vu_message_write(dev, dev->slave_fd, &vmsg); | ||
154 | if (ack) { | ||
155 | - vu_message_read(dev, dev->slave_fd, &vmsg); | ||
156 | + vu_message_read_default(dev, dev->slave_fd, &vmsg); | ||
157 | } | ||
158 | return; | ||
159 | } | ||
160 | diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c | ||
161 | index XXXXXXX..XXXXXXX 100644 | ||
162 | --- a/tests/vhost-user-bridge.c | ||
163 | +++ b/tests/vhost-user-bridge.c | ||
164 | @@ -XXX,XX +XXX,XX @@ vubr_accept_cb(int sock, void *ctx) | ||
165 | VHOST_USER_BRIDGE_MAX_QUEUES, | ||
166 | conn_fd, | ||
167 | vubr_panic, | ||
168 | + NULL, | ||
169 | vubr_set_watch, | ||
170 | vubr_remove_watch, | ||
171 | &vuiface)) { | ||
172 | @@ -XXX,XX +XXX,XX @@ vubr_new(const char *path, bool client) | ||
173 | VHOST_USER_BRIDGE_MAX_QUEUES, | ||
174 | dev->sock, | ||
175 | vubr_panic, | ||
176 | + NULL, | ||
177 | vubr_set_watch, | ||
178 | vubr_remove_watch, | ||
179 | &vuiface)) { | ||
180 | diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c | ||
181 | index XXXXXXX..XXXXXXX 100644 | ||
182 | --- a/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) | ||
185 | se->vu_socketfd = data_sock; | ||
186 | se->virtio_dev->se = se; | ||
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, | ||
189 | - fv_remove_watch, &fv_iface); | ||
190 | + vu_init(&se->virtio_dev->dev, 2, se->vu_socketfd, fv_panic, NULL, | ||
191 | + fv_set_watch, fv_remove_watch, &fv_iface); | ||
192 | |||
43 | return 0; | 193 | return 0; |
44 | } | 194 | } |
45 | diff --git a/include/block/block.h b/include/block/block.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/include/block/block.h | ||
48 | +++ b/include/block/block.h | ||
49 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | ||
50 | int64_t sector_num, int nb_sectors, int *pnum); | ||
51 | |||
52 | bool bdrv_is_read_only(BlockDriverState *bs); | ||
53 | +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | ||
54 | int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | ||
55 | bool bdrv_is_sg(BlockDriverState *bs); | ||
56 | bool bdrv_is_inserted(BlockDriverState *bs); | ||
57 | -- | 195 | -- |
58 | 2.9.3 | 196 | 2.26.2 |
59 | 197 | ||
60 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
1 | 2 | ||
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 | ||
5 | the callback function. | ||
6 | |||
7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
10 | Message-id: 20200918080912.321299-3-coiby.xu@gmail.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | ||
13 | contrib/libvhost-user/libvhost-user.c | 1 + | ||
14 | 1 file changed, 1 insertion(+) | ||
15 | |||
16 | diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/contrib/libvhost-user/libvhost-user.c | ||
19 | +++ b/contrib/libvhost-user/libvhost-user.c | ||
20 | @@ -XXX,XX +XXX,XX @@ vu_deinit(VuDev *dev) | ||
21 | } | ||
22 | |||
23 | if (vq->kick_fd != -1) { | ||
24 | + dev->remove_watch(dev, vq->kick_fd); | ||
25 | close(vq->kick_fd); | ||
26 | vq->kick_fd = -1; | ||
27 | } | ||
28 | -- | ||
29 | 2.26.2 | ||
30 | diff view generated by jsdifflib |
1 | From: Ashish Mittal <ashmit602@gmail.com> | 1 | From: Coiby Xu <coiby.xu@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Source code for the qnio library that this code loads can be downloaded from: | 3 | Sharing QEMU devices via vhost-user protocol. |
4 | https://github.com/VeritasHyperScale/libqnio.git | ||
5 | 4 | ||
6 | Sample command line using JSON syntax: | 5 | Only one vhost-user client can connect to the server one time. |
7 | ./x86_64-softmmu/qemu-system-x86_64 -name instance-00000008 -S -vnc 0.0.0.0:0 | ||
8 | -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 | ||
9 | -msg timestamp=on | ||
10 | 'json:{"driver":"vxhs","vdisk-id":"c3e9095a-a5ee-4dce-afeb-2a59fb387410", | ||
11 | "server":{"host":"172.172.17.4","port":"9999"}}' | ||
12 | 6 | ||
13 | Sample command line using URI syntax: | 7 | Suggested-by: Kevin Wolf <kwolf@redhat.com> |
14 | qemu-img convert -f raw -O raw -n | 8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
15 | /var/lib/nova/instances/_base/0c5eacd5ebea5ed914b6a3e7b18f1ce734c386ad | 9 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> |
16 | vxhs://192.168.0.1:9999/c6718f6b-0401-441d-a8c3-1f0064d75ee0 | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
12 | Message-id: 20200918080912.321299-4-coiby.xu@gmail.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | util/vhost-user-server.h | 65 ++++++ | ||
16 | util/vhost-user-server.c | 428 +++++++++++++++++++++++++++++++++++++++ | ||
17 | util/meson.build | 1 + | ||
18 | 3 files changed, 494 insertions(+) | ||
19 | create mode 100644 util/vhost-user-server.h | ||
20 | create mode 100644 util/vhost-user-server.c | ||
17 | 21 | ||
18 | Sample command line using TLS credentials (run in secure mode): | 22 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h |
19 | ./qemu-io --object | ||
20 | tls-creds-x509,id=tls0,dir=/etc/pki/qemu/vxhs,endpoint=client -c 'read | ||
21 | -v 66000 2.5k' 'json:{"server.host": "127.0.0.1", "server.port": "9999", | ||
22 | "vdisk-id": "/test.raw", "driver": "vxhs", "tls-creds":"tls0"}' | ||
23 | |||
24 | Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com> | ||
25 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
26 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
27 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
28 | Message-id: 1491277689-24949-2-git-send-email-Ashish.Mittal@veritas.com | ||
29 | --- | ||
30 | block/Makefile.objs | 2 + | ||
31 | block/trace-events | 17 ++ | ||
32 | block/vxhs.c | 575 +++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
33 | configure | 39 ++++ | ||
34 | qapi/block-core.json | 23 ++- | ||
35 | 5 files changed, 654 insertions(+), 2 deletions(-) | ||
36 | create mode 100644 block/vxhs.c | ||
37 | |||
38 | diff --git a/block/Makefile.objs b/block/Makefile.objs | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/block/Makefile.objs | ||
41 | +++ b/block/Makefile.objs | ||
42 | @@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_LIBNFS) += nfs.o | ||
43 | block-obj-$(CONFIG_CURL) += curl.o | ||
44 | block-obj-$(CONFIG_RBD) += rbd.o | ||
45 | block-obj-$(CONFIG_GLUSTERFS) += gluster.o | ||
46 | +block-obj-$(CONFIG_VXHS) += vxhs.o | ||
47 | block-obj-$(CONFIG_LIBSSH2) += ssh.o | ||
48 | block-obj-y += accounting.o dirty-bitmap.o | ||
49 | block-obj-y += write-threshold.o | ||
50 | @@ -XXX,XX +XXX,XX @@ rbd.o-cflags := $(RBD_CFLAGS) | ||
51 | rbd.o-libs := $(RBD_LIBS) | ||
52 | gluster.o-cflags := $(GLUSTERFS_CFLAGS) | ||
53 | gluster.o-libs := $(GLUSTERFS_LIBS) | ||
54 | +vxhs.o-libs := $(VXHS_LIBS) | ||
55 | ssh.o-cflags := $(LIBSSH2_CFLAGS) | ||
56 | ssh.o-libs := $(LIBSSH2_LIBS) | ||
57 | block-obj-$(if $(CONFIG_BZIP2),m,n) += dmg-bz2.o | ||
58 | diff --git a/block/trace-events b/block/trace-events | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/block/trace-events | ||
61 | +++ b/block/trace-events | ||
62 | @@ -XXX,XX +XXX,XX @@ qed_aio_write_data(void *s, void *acb, int ret, uint64_t offset, size_t len) "s | ||
63 | qed_aio_write_prefill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 | ||
64 | qed_aio_write_postfill(void *s, void *acb, uint64_t start, size_t len, uint64_t offset) "s %p acb %p start %"PRIu64" len %zu offset %"PRIu64 | ||
65 | qed_aio_write_main(void *s, void *acb, int ret, uint64_t offset, size_t len) "s %p acb %p ret %d offset %"PRIu64" len %zu" | ||
66 | + | ||
67 | +# block/vxhs.c | ||
68 | +vxhs_iio_callback(int error) "ctx is NULL: error %d" | ||
69 | +vxhs_iio_callback_chnfail(int err, int error) "QNIO channel failed, no i/o %d, %d" | ||
70 | +vxhs_iio_callback_unknwn(int opcode, int err) "unexpected opcode %d, errno %d" | ||
71 | +vxhs_aio_rw_invalid(int req) "Invalid I/O request iodir %d" | ||
72 | +vxhs_aio_rw_ioerr(char *guid, int iodir, uint64_t size, uint64_t off, void *acb, int ret, int err) "IO ERROR (vDisk %s) FOR : Read/Write = %d size = %lu offset = %lu ACB = %p. Error = %d, errno = %d" | ||
73 | +vxhs_get_vdisk_stat_err(char *guid, int ret, int err) "vDisk (%s) stat ioctl failed, ret = %d, errno = %d" | ||
74 | +vxhs_get_vdisk_stat(char *vdisk_guid, uint64_t vdisk_size) "vDisk %s stat ioctl returned size %lu" | ||
75 | +vxhs_complete_aio(void *acb, uint64_t ret) "aio failed acb %p ret %ld" | ||
76 | +vxhs_parse_uri_filename(const char *filename) "URI passed via bdrv_parse_filename %s" | ||
77 | +vxhs_open_vdiskid(const char *vdisk_id) "Opening vdisk-id %s" | ||
78 | +vxhs_open_hostinfo(char *of_vsa_addr, int port) "Adding host %s:%d to BDRVVXHSState" | ||
79 | +vxhs_open_iio_open(const char *host) "Failed to connect to storage agent on host %s" | ||
80 | +vxhs_parse_uri_hostinfo(char *host, int port) "Host: IP %s, Port %d" | ||
81 | +vxhs_close(char *vdisk_guid) "Closing vdisk %s" | ||
82 | +vxhs_get_creds(const char *cacert, const char *client_key, const char *client_cert) "cacert %s, client_key %s, client_cert %s" | ||
83 | diff --git a/block/vxhs.c b/block/vxhs.c | ||
84 | new file mode 100644 | 23 | new file mode 100644 |
85 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
86 | --- /dev/null | 25 | --- /dev/null |
87 | +++ b/block/vxhs.c | 26 | +++ b/util/vhost-user-server.h |
88 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
89 | +/* | 28 | +/* |
90 | + * QEMU Block driver for Veritas HyperScale (VxHS) | 29 | + * Sharing QEMU devices via vhost-user protocol |
91 | + * | 30 | + * |
92 | + * Copyright (c) 2017 Veritas Technologies LLC. | 31 | + * Copyright (c) Coiby Xu <coiby.xu@gmail.com>. |
32 | + * Copyright (c) 2020 Red Hat, Inc. | ||
93 | + * | 33 | + * |
94 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 34 | + * This work is licensed under the terms of the GNU GPL, version 2 or |
95 | + * See the COPYING file in the top-level directory. | 35 | + * later. See the COPYING file in the top-level directory. |
36 | + */ | ||
37 | + | ||
38 | +#ifndef VHOST_USER_SERVER_H | ||
39 | +#define VHOST_USER_SERVER_H | ||
40 | + | ||
41 | +#include "contrib/libvhost-user/libvhost-user.h" | ||
42 | +#include "io/channel-socket.h" | ||
43 | +#include "io/channel-file.h" | ||
44 | +#include "io/net-listener.h" | ||
45 | +#include "qemu/error-report.h" | ||
46 | +#include "qapi/error.h" | ||
47 | +#include "standard-headers/linux/virtio_blk.h" | ||
48 | + | ||
49 | +typedef struct VuFdWatch { | ||
50 | + VuDev *vu_dev; | ||
51 | + int fd; /*kick fd*/ | ||
52 | + void *pvt; | ||
53 | + vu_watch_cb cb; | ||
54 | + bool processing; | ||
55 | + QTAILQ_ENTRY(VuFdWatch) next; | ||
56 | +} VuFdWatch; | ||
57 | + | ||
58 | +typedef struct VuServer VuServer; | ||
59 | +typedef void DevicePanicNotifierFn(VuServer *server); | ||
60 | + | ||
61 | +struct VuServer { | ||
62 | + QIONetListener *listener; | ||
63 | + AioContext *ctx; | ||
64 | + DevicePanicNotifierFn *device_panic_notifier; | ||
65 | + int max_queues; | ||
66 | + const VuDevIface *vu_iface; | ||
67 | + VuDev vu_dev; | ||
68 | + QIOChannel *ioc; /* The I/O channel with the client */ | ||
69 | + QIOChannelSocket *sioc; /* The underlying data channel with the client */ | ||
70 | + /* IOChannel for fd provided via VHOST_USER_SET_SLAVE_REQ_FD */ | ||
71 | + QIOChannel *ioc_slave; | ||
72 | + QIOChannelSocket *sioc_slave; | ||
73 | + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | ||
74 | + QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; | ||
75 | + /* restart coroutine co_trip if AIOContext is changed */ | ||
76 | + bool aio_context_changed; | ||
77 | + bool processing_msg; | ||
78 | +}; | ||
79 | + | ||
80 | +bool vhost_user_server_start(VuServer *server, | ||
81 | + SocketAddress *unix_socket, | ||
82 | + AioContext *ctx, | ||
83 | + uint16_t max_queues, | ||
84 | + DevicePanicNotifierFn *device_panic_notifier, | ||
85 | + const VuDevIface *vu_iface, | ||
86 | + Error **errp); | ||
87 | + | ||
88 | +void vhost_user_server_stop(VuServer *server); | ||
89 | + | ||
90 | +void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx); | ||
91 | + | ||
92 | +#endif /* VHOST_USER_SERVER_H */ | ||
93 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
94 | new file mode 100644 | ||
95 | index XXXXXXX..XXXXXXX | ||
96 | --- /dev/null | ||
97 | +++ b/util/vhost-user-server.c | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | +/* | ||
100 | + * Sharing QEMU devices via vhost-user protocol | ||
96 | + * | 101 | + * |
102 | + * Copyright (c) Coiby Xu <coiby.xu@gmail.com>. | ||
103 | + * Copyright (c) 2020 Red Hat, Inc. | ||
104 | + * | ||
105 | + * This work is licensed under the terms of the GNU GPL, version 2 or | ||
106 | + * later. See the COPYING file in the top-level directory. | ||
97 | + */ | 107 | + */ |
98 | + | ||
99 | +#include "qemu/osdep.h" | 108 | +#include "qemu/osdep.h" |
100 | +#include <qnio/qnio_api.h> | 109 | +#include "qemu/main-loop.h" |
101 | +#include <sys/param.h> | 110 | +#include "vhost-user-server.h" |
102 | +#include "block/block_int.h" | 111 | + |
103 | +#include "qapi/qmp/qerror.h" | 112 | +static void vmsg_close_fds(VhostUserMsg *vmsg) |
104 | +#include "qapi/qmp/qdict.h" | 113 | +{ |
105 | +#include "qapi/qmp/qstring.h" | 114 | + int i; |
106 | +#include "trace.h" | 115 | + for (i = 0; i < vmsg->fd_num; i++) { |
107 | +#include "qemu/uri.h" | 116 | + close(vmsg->fds[i]); |
108 | +#include "qapi/error.h" | 117 | + } |
109 | +#include "qemu/uuid.h" | 118 | +} |
110 | +#include "crypto/tlscredsx509.h" | 119 | + |
111 | + | 120 | +static void vmsg_unblock_fds(VhostUserMsg *vmsg) |
112 | +#define VXHS_OPT_FILENAME "filename" | 121 | +{ |
113 | +#define VXHS_OPT_VDISK_ID "vdisk-id" | 122 | + int i; |
114 | +#define VXHS_OPT_SERVER "server" | 123 | + for (i = 0; i < vmsg->fd_num; i++) { |
115 | +#define VXHS_OPT_HOST "host" | 124 | + qemu_set_nonblock(vmsg->fds[i]); |
116 | +#define VXHS_OPT_PORT "port" | 125 | + } |
117 | + | 126 | +} |
118 | +/* Only accessed under QEMU global mutex */ | 127 | + |
119 | +static uint32_t vxhs_ref; | 128 | +static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, |
120 | + | 129 | + gpointer opaque); |
121 | +typedef enum { | 130 | + |
122 | + VDISK_AIO_READ, | 131 | +static void close_client(VuServer *server) |
123 | + VDISK_AIO_WRITE, | 132 | +{ |
124 | +} VDISKAIOCmd; | 133 | + /* |
134 | + * Before closing the client | ||
135 | + * | ||
136 | + * 1. Let vu_client_trip stop processing new vhost-user msg | ||
137 | + * | ||
138 | + * 2. remove kick_handler | ||
139 | + * | ||
140 | + * 3. wait for the kick handler to be finished | ||
141 | + * | ||
142 | + * 4. wait for the current vhost-user msg to be finished processing | ||
143 | + */ | ||
144 | + | ||
145 | + QIOChannelSocket *sioc = server->sioc; | ||
146 | + /* When this is set vu_client_trip will stop new processing vhost-user message */ | ||
147 | + server->sioc = NULL; | ||
148 | + | ||
149 | + VuFdWatch *vu_fd_watch, *next; | ||
150 | + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | ||
151 | + aio_set_fd_handler(server->ioc->ctx, vu_fd_watch->fd, true, NULL, | ||
152 | + NULL, NULL, NULL); | ||
153 | + } | ||
154 | + | ||
155 | + while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { | ||
156 | + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | ||
157 | + if (!vu_fd_watch->processing) { | ||
158 | + QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); | ||
159 | + g_free(vu_fd_watch); | ||
160 | + } | ||
161 | + } | ||
162 | + } | ||
163 | + | ||
164 | + while (server->processing_msg) { | ||
165 | + if (server->ioc->read_coroutine) { | ||
166 | + server->ioc->read_coroutine = NULL; | ||
167 | + qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, NULL, | ||
168 | + NULL, server->ioc); | ||
169 | + server->processing_msg = false; | ||
170 | + } | ||
171 | + } | ||
172 | + | ||
173 | + vu_deinit(&server->vu_dev); | ||
174 | + object_unref(OBJECT(sioc)); | ||
175 | + object_unref(OBJECT(server->ioc)); | ||
176 | +} | ||
177 | + | ||
178 | +static void panic_cb(VuDev *vu_dev, const char *buf) | ||
179 | +{ | ||
180 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
181 | + | ||
182 | + /* avoid while loop in close_client */ | ||
183 | + server->processing_msg = false; | ||
184 | + | ||
185 | + if (buf) { | ||
186 | + error_report("vu_panic: %s", buf); | ||
187 | + } | ||
188 | + | ||
189 | + if (server->sioc) { | ||
190 | + close_client(server); | ||
191 | + } | ||
192 | + | ||
193 | + if (server->device_panic_notifier) { | ||
194 | + server->device_panic_notifier(server); | ||
195 | + } | ||
196 | + | ||
197 | + /* | ||
198 | + * Set the callback function for network listener so another | ||
199 | + * vhost-user client can connect to this server | ||
200 | + */ | ||
201 | + qio_net_listener_set_client_func(server->listener, | ||
202 | + vu_accept, | ||
203 | + server, | ||
204 | + NULL); | ||
205 | +} | ||
206 | + | ||
207 | +static bool coroutine_fn | ||
208 | +vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) | ||
209 | +{ | ||
210 | + struct iovec iov = { | ||
211 | + .iov_base = (char *)vmsg, | ||
212 | + .iov_len = VHOST_USER_HDR_SIZE, | ||
213 | + }; | ||
214 | + int rc, read_bytes = 0; | ||
215 | + Error *local_err = NULL; | ||
216 | + /* | ||
217 | + * Store fds/nfds returned from qio_channel_readv_full into | ||
218 | + * temporary variables. | ||
219 | + * | ||
220 | + * VhostUserMsg is a packed structure, gcc will complain about passing | ||
221 | + * pointer to a packed structure member if we pass &VhostUserMsg.fd_num | ||
222 | + * and &VhostUserMsg.fds directly when calling qio_channel_readv_full, | ||
223 | + * thus two temporary variables nfds and fds are used here. | ||
224 | + */ | ||
225 | + size_t nfds = 0, nfds_t = 0; | ||
226 | + const size_t max_fds = G_N_ELEMENTS(vmsg->fds); | ||
227 | + int *fds_t = NULL; | ||
228 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
229 | + QIOChannel *ioc = server->ioc; | ||
230 | + | ||
231 | + if (!ioc) { | ||
232 | + error_report_err(local_err); | ||
233 | + goto fail; | ||
234 | + } | ||
235 | + | ||
236 | + assert(qemu_in_coroutine()); | ||
237 | + do { | ||
238 | + /* | ||
239 | + * qio_channel_readv_full may have short reads, keeping calling it | ||
240 | + * until getting VHOST_USER_HDR_SIZE or 0 bytes in total | ||
241 | + */ | ||
242 | + rc = qio_channel_readv_full(ioc, &iov, 1, &fds_t, &nfds_t, &local_err); | ||
243 | + if (rc < 0) { | ||
244 | + if (rc == QIO_CHANNEL_ERR_BLOCK) { | ||
245 | + qio_channel_yield(ioc, G_IO_IN); | ||
246 | + continue; | ||
247 | + } else { | ||
248 | + error_report_err(local_err); | ||
249 | + return false; | ||
250 | + } | ||
251 | + } | ||
252 | + read_bytes += rc; | ||
253 | + if (nfds_t > 0) { | ||
254 | + if (nfds + nfds_t > max_fds) { | ||
255 | + error_report("A maximum of %zu fds are allowed, " | ||
256 | + "however got %lu fds now", | ||
257 | + max_fds, nfds + nfds_t); | ||
258 | + goto fail; | ||
259 | + } | ||
260 | + memcpy(vmsg->fds + nfds, fds_t, | ||
261 | + nfds_t *sizeof(vmsg->fds[0])); | ||
262 | + nfds += nfds_t; | ||
263 | + g_free(fds_t); | ||
264 | + } | ||
265 | + if (read_bytes == VHOST_USER_HDR_SIZE || rc == 0) { | ||
266 | + break; | ||
267 | + } | ||
268 | + iov.iov_base = (char *)vmsg + read_bytes; | ||
269 | + iov.iov_len = VHOST_USER_HDR_SIZE - read_bytes; | ||
270 | + } while (true); | ||
271 | + | ||
272 | + vmsg->fd_num = nfds; | ||
273 | + /* qio_channel_readv_full will make socket fds blocking, unblock them */ | ||
274 | + vmsg_unblock_fds(vmsg); | ||
275 | + if (vmsg->size > sizeof(vmsg->payload)) { | ||
276 | + error_report("Error: too big message request: %d, " | ||
277 | + "size: vmsg->size: %u, " | ||
278 | + "while sizeof(vmsg->payload) = %zu", | ||
279 | + vmsg->request, vmsg->size, sizeof(vmsg->payload)); | ||
280 | + goto fail; | ||
281 | + } | ||
282 | + | ||
283 | + struct iovec iov_payload = { | ||
284 | + .iov_base = (char *)&vmsg->payload, | ||
285 | + .iov_len = vmsg->size, | ||
286 | + }; | ||
287 | + if (vmsg->size) { | ||
288 | + rc = qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); | ||
289 | + if (rc == -1) { | ||
290 | + error_report_err(local_err); | ||
291 | + goto fail; | ||
292 | + } | ||
293 | + } | ||
294 | + | ||
295 | + return true; | ||
296 | + | ||
297 | +fail: | ||
298 | + vmsg_close_fds(vmsg); | ||
299 | + | ||
300 | + return false; | ||
301 | +} | ||
302 | + | ||
303 | + | ||
304 | +static void vu_client_start(VuServer *server); | ||
305 | +static coroutine_fn void vu_client_trip(void *opaque) | ||
306 | +{ | ||
307 | + VuServer *server = opaque; | ||
308 | + | ||
309 | + while (!server->aio_context_changed && server->sioc) { | ||
310 | + server->processing_msg = true; | ||
311 | + vu_dispatch(&server->vu_dev); | ||
312 | + server->processing_msg = false; | ||
313 | + } | ||
314 | + | ||
315 | + if (server->aio_context_changed && server->sioc) { | ||
316 | + server->aio_context_changed = false; | ||
317 | + vu_client_start(server); | ||
318 | + } | ||
319 | +} | ||
320 | + | ||
321 | +static void vu_client_start(VuServer *server) | ||
322 | +{ | ||
323 | + server->co_trip = qemu_coroutine_create(vu_client_trip, server); | ||
324 | + aio_co_enter(server->ctx, server->co_trip); | ||
325 | +} | ||
125 | + | 326 | + |
126 | +/* | 327 | +/* |
127 | + * HyperScale AIO callbacks structure | 328 | + * a wrapper for vu_kick_cb |
329 | + * | ||
330 | + * since aio_dispatch can only pass one user data pointer to the | ||
331 | + * callback function, pack VuDev and pvt into a struct. Then unpack it | ||
332 | + * and pass them to vu_kick_cb | ||
128 | + */ | 333 | + */ |
129 | +typedef struct VXHSAIOCB { | 334 | +static void kick_handler(void *opaque) |
130 | + BlockAIOCB common; | 335 | +{ |
131 | + int err; | 336 | + VuFdWatch *vu_fd_watch = opaque; |
132 | +} VXHSAIOCB; | 337 | + vu_fd_watch->processing = true; |
133 | + | 338 | + vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); |
134 | +typedef struct VXHSvDiskHostsInfo { | 339 | + vu_fd_watch->processing = false; |
135 | + void *dev_handle; /* Device handle */ | 340 | +} |
136 | + char *host; /* Host name or IP */ | 341 | + |
137 | + int port; /* Host's port number */ | 342 | + |
138 | +} VXHSvDiskHostsInfo; | 343 | +static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) |
139 | + | 344 | +{ |
140 | +/* | 345 | + |
141 | + * Structure per vDisk maintained for state | 346 | + VuFdWatch *vu_fd_watch, *next; |
142 | + */ | 347 | + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { |
143 | +typedef struct BDRVVXHSState { | 348 | + if (vu_fd_watch->fd == fd) { |
144 | + VXHSvDiskHostsInfo vdisk_hostinfo; /* Per host info */ | 349 | + return vu_fd_watch; |
145 | + char *vdisk_guid; | 350 | + } |
146 | + char *tlscredsid; /* tlscredsid */ | 351 | + } |
147 | +} BDRVVXHSState; | 352 | + return NULL; |
148 | + | 353 | +} |
149 | +static void vxhs_complete_aio_bh(void *opaque) | 354 | + |
150 | +{ | 355 | +static void |
151 | + VXHSAIOCB *acb = opaque; | 356 | +set_watch(VuDev *vu_dev, int fd, int vu_evt, |
152 | + BlockCompletionFunc *cb = acb->common.cb; | 357 | + vu_watch_cb cb, void *pvt) |
153 | + void *cb_opaque = acb->common.opaque; | 358 | +{ |
154 | + int ret = 0; | 359 | + |
155 | + | 360 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); |
156 | + if (acb->err != 0) { | 361 | + g_assert(vu_dev); |
157 | + trace_vxhs_complete_aio(acb, acb->err); | 362 | + g_assert(fd >= 0); |
158 | + ret = (-EIO); | 363 | + g_assert(cb); |
159 | + } | 364 | + |
160 | + | 365 | + VuFdWatch *vu_fd_watch = find_vu_fd_watch(server, fd); |
161 | + qemu_aio_unref(acb); | 366 | + |
162 | + cb(cb_opaque, ret); | 367 | + if (!vu_fd_watch) { |
163 | +} | 368 | + VuFdWatch *vu_fd_watch = g_new0(VuFdWatch, 1); |
164 | + | 369 | + |
165 | +/* | 370 | + QTAILQ_INSERT_TAIL(&server->vu_fd_watches, vu_fd_watch, next); |
166 | + * Called from a libqnio thread | 371 | + |
167 | + */ | 372 | + vu_fd_watch->fd = fd; |
168 | +static void vxhs_iio_callback(void *ctx, uint32_t opcode, uint32_t error) | 373 | + vu_fd_watch->cb = cb; |
169 | +{ | 374 | + qemu_set_nonblock(fd); |
170 | + VXHSAIOCB *acb = NULL; | 375 | + aio_set_fd_handler(server->ioc->ctx, fd, true, kick_handler, |
171 | + | 376 | + NULL, NULL, vu_fd_watch); |
172 | + switch (opcode) { | 377 | + vu_fd_watch->vu_dev = vu_dev; |
173 | + case IRP_READ_REQUEST: | 378 | + vu_fd_watch->pvt = pvt; |
174 | + case IRP_WRITE_REQUEST: | 379 | + } |
175 | + | 380 | +} |
176 | + /* | 381 | + |
177 | + * ctx is VXHSAIOCB* | 382 | + |
178 | + * ctx is NULL if error is QNIOERROR_CHANNEL_HUP | 383 | +static void remove_watch(VuDev *vu_dev, int fd) |
179 | + */ | 384 | +{ |
180 | + if (ctx) { | 385 | + VuServer *server; |
181 | + acb = ctx; | 386 | + g_assert(vu_dev); |
182 | + } else { | 387 | + g_assert(fd >= 0); |
183 | + trace_vxhs_iio_callback(error); | 388 | + |
184 | + goto out; | 389 | + server = container_of(vu_dev, VuServer, vu_dev); |
185 | + } | 390 | + |
186 | + | 391 | + VuFdWatch *vu_fd_watch = find_vu_fd_watch(server, fd); |
187 | + if (error) { | 392 | + |
188 | + if (!acb->err) { | 393 | + if (!vu_fd_watch) { |
189 | + acb->err = error; | ||
190 | + } | ||
191 | + trace_vxhs_iio_callback(error); | ||
192 | + } | ||
193 | + | ||
194 | + aio_bh_schedule_oneshot(bdrv_get_aio_context(acb->common.bs), | ||
195 | + vxhs_complete_aio_bh, acb); | ||
196 | + break; | ||
197 | + | ||
198 | + default: | ||
199 | + if (error == QNIOERROR_HUP) { | ||
200 | + /* | ||
201 | + * Channel failed, spontaneous notification, | ||
202 | + * not in response to I/O | ||
203 | + */ | ||
204 | + trace_vxhs_iio_callback_chnfail(error, errno); | ||
205 | + } else { | ||
206 | + trace_vxhs_iio_callback_unknwn(opcode, error); | ||
207 | + } | ||
208 | + break; | ||
209 | + } | ||
210 | +out: | ||
211 | + return; | ||
212 | +} | ||
213 | + | ||
214 | +static QemuOptsList runtime_opts = { | ||
215 | + .name = "vxhs", | ||
216 | + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), | ||
217 | + .desc = { | ||
218 | + { | ||
219 | + .name = VXHS_OPT_FILENAME, | ||
220 | + .type = QEMU_OPT_STRING, | ||
221 | + .help = "URI to the Veritas HyperScale image", | ||
222 | + }, | ||
223 | + { | ||
224 | + .name = VXHS_OPT_VDISK_ID, | ||
225 | + .type = QEMU_OPT_STRING, | ||
226 | + .help = "UUID of the VxHS vdisk", | ||
227 | + }, | ||
228 | + { | ||
229 | + .name = "tls-creds", | ||
230 | + .type = QEMU_OPT_STRING, | ||
231 | + .help = "ID of the TLS/SSL credentials to use", | ||
232 | + }, | ||
233 | + { /* end of list */ } | ||
234 | + }, | ||
235 | +}; | ||
236 | + | ||
237 | +static QemuOptsList runtime_tcp_opts = { | ||
238 | + .name = "vxhs_tcp", | ||
239 | + .head = QTAILQ_HEAD_INITIALIZER(runtime_tcp_opts.head), | ||
240 | + .desc = { | ||
241 | + { | ||
242 | + .name = VXHS_OPT_HOST, | ||
243 | + .type = QEMU_OPT_STRING, | ||
244 | + .help = "host address (ipv4 addresses)", | ||
245 | + }, | ||
246 | + { | ||
247 | + .name = VXHS_OPT_PORT, | ||
248 | + .type = QEMU_OPT_NUMBER, | ||
249 | + .help = "port number on which VxHSD is listening (default 9999)", | ||
250 | + .def_value_str = "9999" | ||
251 | + }, | ||
252 | + { /* end of list */ } | ||
253 | + }, | ||
254 | +}; | ||
255 | + | ||
256 | +/* | ||
257 | + * Parse incoming URI and populate *options with the host | ||
258 | + * and device information | ||
259 | + */ | ||
260 | +static int vxhs_parse_uri(const char *filename, QDict *options) | ||
261 | +{ | ||
262 | + URI *uri = NULL; | ||
263 | + char *port; | ||
264 | + int ret = 0; | ||
265 | + | ||
266 | + trace_vxhs_parse_uri_filename(filename); | ||
267 | + uri = uri_parse(filename); | ||
268 | + if (!uri || !uri->server || !uri->path) { | ||
269 | + uri_free(uri); | ||
270 | + return -EINVAL; | ||
271 | + } | ||
272 | + | ||
273 | + qdict_put(options, VXHS_OPT_SERVER".host", qstring_from_str(uri->server)); | ||
274 | + | ||
275 | + if (uri->port) { | ||
276 | + port = g_strdup_printf("%d", uri->port); | ||
277 | + qdict_put(options, VXHS_OPT_SERVER".port", qstring_from_str(port)); | ||
278 | + g_free(port); | ||
279 | + } | ||
280 | + | ||
281 | + qdict_put(options, "vdisk-id", qstring_from_str(uri->path)); | ||
282 | + | ||
283 | + trace_vxhs_parse_uri_hostinfo(uri->server, uri->port); | ||
284 | + uri_free(uri); | ||
285 | + | ||
286 | + return ret; | ||
287 | +} | ||
288 | + | ||
289 | +static void vxhs_parse_filename(const char *filename, QDict *options, | ||
290 | + Error **errp) | ||
291 | +{ | ||
292 | + if (qdict_haskey(options, "vdisk-id") || qdict_haskey(options, "server")) { | ||
293 | + error_setg(errp, "vdisk-id/server and a file name may not be specified " | ||
294 | + "at the same time"); | ||
295 | + return; | 394 | + return; |
296 | + } | 395 | + } |
297 | + | 396 | + aio_set_fd_handler(server->ioc->ctx, fd, true, NULL, NULL, NULL, NULL); |
298 | + if (strstr(filename, "://")) { | 397 | + |
299 | + int ret = vxhs_parse_uri(filename, options); | 398 | + QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); |
300 | + if (ret < 0) { | 399 | + g_free(vu_fd_watch); |
301 | + error_setg(errp, "Invalid URI. URI should be of the form " | 400 | +} |
302 | + " vxhs://<host_ip>:<port>/<vdisk-id>"); | 401 | + |
303 | + } | 402 | + |
304 | + } | 403 | +static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, |
305 | +} | 404 | + gpointer opaque) |
306 | + | 405 | +{ |
307 | +static int vxhs_init_and_ref(void) | 406 | + VuServer *server = opaque; |
308 | +{ | 407 | + |
309 | + if (vxhs_ref++ == 0) { | 408 | + if (server->sioc) { |
310 | + if (iio_init(QNIO_VERSION, vxhs_iio_callback)) { | 409 | + warn_report("Only one vhost-user client is allowed to " |
311 | + return -ENODEV; | 410 | + "connect the server one time"); |
312 | + } | ||
313 | + } | ||
314 | + return 0; | ||
315 | +} | ||
316 | + | ||
317 | +static void vxhs_unref(void) | ||
318 | +{ | ||
319 | + if (--vxhs_ref == 0) { | ||
320 | + iio_fini(); | ||
321 | + } | ||
322 | +} | ||
323 | + | ||
324 | +static void vxhs_get_tls_creds(const char *id, char **cacert, | ||
325 | + char **key, char **cert, Error **errp) | ||
326 | +{ | ||
327 | + Object *obj; | ||
328 | + QCryptoTLSCreds *creds; | ||
329 | + QCryptoTLSCredsX509 *creds_x509; | ||
330 | + | ||
331 | + obj = object_resolve_path_component( | ||
332 | + object_get_objects_root(), id); | ||
333 | + | ||
334 | + if (!obj) { | ||
335 | + error_setg(errp, "No TLS credentials with id '%s'", | ||
336 | + id); | ||
337 | + return; | 411 | + return; |
338 | + } | 412 | + } |
339 | + | 413 | + |
340 | + creds_x509 = (QCryptoTLSCredsX509 *) | 414 | + if (!vu_init(&server->vu_dev, server->max_queues, sioc->fd, panic_cb, |
341 | + object_dynamic_cast(obj, TYPE_QCRYPTO_TLS_CREDS_X509); | 415 | + vu_message_read, set_watch, remove_watch, server->vu_iface)) { |
342 | + | 416 | + error_report("Failed to initialize libvhost-user"); |
343 | + if (!creds_x509) { | ||
344 | + error_setg(errp, "Object with id '%s' is not TLS credentials", | ||
345 | + id); | ||
346 | + return; | 417 | + return; |
347 | + } | 418 | + } |
348 | + | 419 | + |
349 | + creds = &creds_x509->parent_obj; | 420 | + /* |
350 | + | 421 | + * Unset the callback function for network listener to make another |
351 | + if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { | 422 | + * vhost-user client keeping waiting until this client disconnects |
352 | + error_setg(errp, | 423 | + */ |
353 | + "Expecting TLS credentials with a client endpoint"); | 424 | + qio_net_listener_set_client_func(server->listener, |
425 | + NULL, | ||
426 | + NULL, | ||
427 | + NULL); | ||
428 | + server->sioc = sioc; | ||
429 | + /* | ||
430 | + * Increase the object reference, so sioc will not freed by | ||
431 | + * qio_net_listener_channel_func which will call object_unref(OBJECT(sioc)) | ||
432 | + */ | ||
433 | + object_ref(OBJECT(server->sioc)); | ||
434 | + qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); | ||
435 | + server->ioc = QIO_CHANNEL(sioc); | ||
436 | + object_ref(OBJECT(server->ioc)); | ||
437 | + qio_channel_attach_aio_context(server->ioc, server->ctx); | ||
438 | + qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); | ||
439 | + vu_client_start(server); | ||
440 | +} | ||
441 | + | ||
442 | + | ||
443 | +void vhost_user_server_stop(VuServer *server) | ||
444 | +{ | ||
445 | + if (server->sioc) { | ||
446 | + close_client(server); | ||
447 | + } | ||
448 | + | ||
449 | + if (server->listener) { | ||
450 | + qio_net_listener_disconnect(server->listener); | ||
451 | + object_unref(OBJECT(server->listener)); | ||
452 | + } | ||
453 | + | ||
454 | +} | ||
455 | + | ||
456 | +void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) | ||
457 | +{ | ||
458 | + VuFdWatch *vu_fd_watch, *next; | ||
459 | + void *opaque = NULL; | ||
460 | + IOHandler *io_read = NULL; | ||
461 | + bool attach; | ||
462 | + | ||
463 | + server->ctx = ctx ? ctx : qemu_get_aio_context(); | ||
464 | + | ||
465 | + if (!server->sioc) { | ||
466 | + /* not yet serving any client*/ | ||
354 | + return; | 467 | + return; |
355 | + } | 468 | + } |
356 | + | 469 | + |
357 | + /* | 470 | + if (ctx) { |
358 | + * Get the cacert, client_cert and client_key file names. | 471 | + qio_channel_attach_aio_context(server->ioc, ctx); |
359 | + */ | 472 | + server->aio_context_changed = true; |
360 | + if (!creds->dir) { | 473 | + io_read = kick_handler; |
361 | + error_setg(errp, "TLS object missing 'dir' property value"); | 474 | + attach = true; |
362 | + return; | 475 | + } else { |
363 | + } | 476 | + qio_channel_detach_aio_context(server->ioc); |
364 | + | 477 | + /* server->ioc->ctx keeps the old AioConext */ |
365 | + *cacert = g_strdup_printf("%s/%s", creds->dir, | 478 | + ctx = server->ioc->ctx; |
366 | + QCRYPTO_TLS_CREDS_X509_CA_CERT); | 479 | + attach = false; |
367 | + *cert = g_strdup_printf("%s/%s", creds->dir, | 480 | + } |
368 | + QCRYPTO_TLS_CREDS_X509_CLIENT_CERT); | 481 | + |
369 | + *key = g_strdup_printf("%s/%s", creds->dir, | 482 | + QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { |
370 | + QCRYPTO_TLS_CREDS_X509_CLIENT_KEY); | 483 | + if (vu_fd_watch->cb) { |
371 | +} | 484 | + opaque = attach ? vu_fd_watch : NULL; |
372 | + | 485 | + aio_set_fd_handler(ctx, vu_fd_watch->fd, true, |
373 | +static int vxhs_open(BlockDriverState *bs, QDict *options, | 486 | + io_read, NULL, NULL, |
374 | + int bdrv_flags, Error **errp) | 487 | + opaque); |
375 | +{ | 488 | + } |
376 | + BDRVVXHSState *s = bs->opaque; | 489 | + } |
377 | + void *dev_handlep; | 490 | +} |
378 | + QDict *backing_options = NULL; | 491 | + |
379 | + QemuOpts *opts = NULL; | 492 | + |
380 | + QemuOpts *tcp_opts = NULL; | 493 | +bool vhost_user_server_start(VuServer *server, |
381 | + char *of_vsa_addr = NULL; | 494 | + SocketAddress *socket_addr, |
382 | + Error *local_err = NULL; | 495 | + AioContext *ctx, |
383 | + const char *vdisk_id_opt; | 496 | + uint16_t max_queues, |
384 | + const char *server_host_opt; | 497 | + DevicePanicNotifierFn *device_panic_notifier, |
385 | + int ret = 0; | 498 | + const VuDevIface *vu_iface, |
386 | + char *cacert = NULL; | 499 | + Error **errp) |
387 | + char *client_key = NULL; | 500 | +{ |
388 | + char *client_cert = NULL; | 501 | + QIONetListener *listener = qio_net_listener_new(); |
389 | + | 502 | + if (qio_net_listener_open_sync(listener, socket_addr, 1, |
390 | + ret = vxhs_init_and_ref(); | 503 | + errp) < 0) { |
391 | + if (ret < 0) { | 504 | + object_unref(OBJECT(listener)); |
392 | + ret = -EINVAL; | 505 | + return false; |
393 | + goto out; | 506 | + } |
394 | + } | 507 | + |
395 | + | 508 | + /* zero out unspecified fileds */ |
396 | + /* Create opts info from runtime_opts and runtime_tcp_opts list */ | 509 | + *server = (VuServer) { |
397 | + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); | 510 | + .listener = listener, |
398 | + tcp_opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort); | 511 | + .vu_iface = vu_iface, |
399 | + | 512 | + .max_queues = max_queues, |
400 | + qemu_opts_absorb_qdict(opts, options, &local_err); | 513 | + .ctx = ctx, |
401 | + if (local_err) { | 514 | + .device_panic_notifier = device_panic_notifier, |
402 | + ret = -EINVAL; | 515 | + }; |
403 | + goto out; | 516 | + |
404 | + } | 517 | + qio_net_listener_set_name(server->listener, "vhost-user-backend-listener"); |
405 | + | 518 | + |
406 | + /* vdisk-id is the disk UUID */ | 519 | + qio_net_listener_set_client_func(server->listener, |
407 | + vdisk_id_opt = qemu_opt_get(opts, VXHS_OPT_VDISK_ID); | 520 | + vu_accept, |
408 | + if (!vdisk_id_opt) { | 521 | + server, |
409 | + error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID); | 522 | + NULL); |
410 | + ret = -EINVAL; | 523 | + |
411 | + goto out; | 524 | + QTAILQ_INIT(&server->vu_fd_watches); |
412 | + } | 525 | + return true; |
413 | + | 526 | +} |
414 | + /* vdisk-id may contain a leading '/' */ | 527 | diff --git a/util/meson.build b/util/meson.build |
415 | + if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) { | ||
416 | + error_setg(&local_err, "vdisk-id cannot be more than %d characters", | ||
417 | + UUID_FMT_LEN); | ||
418 | + ret = -EINVAL; | ||
419 | + goto out; | ||
420 | + } | ||
421 | + | ||
422 | + s->vdisk_guid = g_strdup(vdisk_id_opt); | ||
423 | + trace_vxhs_open_vdiskid(vdisk_id_opt); | ||
424 | + | ||
425 | + /* get the 'server.' arguments */ | ||
426 | + qdict_extract_subqdict(options, &backing_options, VXHS_OPT_SERVER"."); | ||
427 | + | ||
428 | + qemu_opts_absorb_qdict(tcp_opts, backing_options, &local_err); | ||
429 | + if (local_err != NULL) { | ||
430 | + ret = -EINVAL; | ||
431 | + goto out; | ||
432 | + } | ||
433 | + | ||
434 | + server_host_opt = qemu_opt_get(tcp_opts, VXHS_OPT_HOST); | ||
435 | + if (!server_host_opt) { | ||
436 | + error_setg(&local_err, QERR_MISSING_PARAMETER, | ||
437 | + VXHS_OPT_SERVER"."VXHS_OPT_HOST); | ||
438 | + ret = -EINVAL; | ||
439 | + goto out; | ||
440 | + } | ||
441 | + | ||
442 | + if (strlen(server_host_opt) > MAXHOSTNAMELEN) { | ||
443 | + error_setg(&local_err, "server.host cannot be more than %d characters", | ||
444 | + MAXHOSTNAMELEN); | ||
445 | + ret = -EINVAL; | ||
446 | + goto out; | ||
447 | + } | ||
448 | + | ||
449 | + /* check if we got tls-creds via the --object argument */ | ||
450 | + s->tlscredsid = g_strdup(qemu_opt_get(opts, "tls-creds")); | ||
451 | + if (s->tlscredsid) { | ||
452 | + vxhs_get_tls_creds(s->tlscredsid, &cacert, &client_key, | ||
453 | + &client_cert, &local_err); | ||
454 | + if (local_err != NULL) { | ||
455 | + ret = -EINVAL; | ||
456 | + goto out; | ||
457 | + } | ||
458 | + trace_vxhs_get_creds(cacert, client_key, client_cert); | ||
459 | + } | ||
460 | + | ||
461 | + s->vdisk_hostinfo.host = g_strdup(server_host_opt); | ||
462 | + s->vdisk_hostinfo.port = g_ascii_strtoll(qemu_opt_get(tcp_opts, | ||
463 | + VXHS_OPT_PORT), | ||
464 | + NULL, 0); | ||
465 | + | ||
466 | + trace_vxhs_open_hostinfo(s->vdisk_hostinfo.host, | ||
467 | + s->vdisk_hostinfo.port); | ||
468 | + | ||
469 | + of_vsa_addr = g_strdup_printf("of://%s:%d", | ||
470 | + s->vdisk_hostinfo.host, | ||
471 | + s->vdisk_hostinfo.port); | ||
472 | + | ||
473 | + /* | ||
474 | + * Open qnio channel to storage agent if not opened before | ||
475 | + */ | ||
476 | + dev_handlep = iio_open(of_vsa_addr, s->vdisk_guid, 0, | ||
477 | + cacert, client_key, client_cert); | ||
478 | + if (dev_handlep == NULL) { | ||
479 | + trace_vxhs_open_iio_open(of_vsa_addr); | ||
480 | + ret = -ENODEV; | ||
481 | + goto out; | ||
482 | + } | ||
483 | + s->vdisk_hostinfo.dev_handle = dev_handlep; | ||
484 | + | ||
485 | +out: | ||
486 | + g_free(of_vsa_addr); | ||
487 | + QDECREF(backing_options); | ||
488 | + qemu_opts_del(tcp_opts); | ||
489 | + qemu_opts_del(opts); | ||
490 | + g_free(cacert); | ||
491 | + g_free(client_key); | ||
492 | + g_free(client_cert); | ||
493 | + | ||
494 | + if (ret < 0) { | ||
495 | + vxhs_unref(); | ||
496 | + error_propagate(errp, local_err); | ||
497 | + g_free(s->vdisk_hostinfo.host); | ||
498 | + g_free(s->vdisk_guid); | ||
499 | + g_free(s->tlscredsid); | ||
500 | + s->vdisk_guid = NULL; | ||
501 | + } | ||
502 | + | ||
503 | + return ret; | ||
504 | +} | ||
505 | + | ||
506 | +static const AIOCBInfo vxhs_aiocb_info = { | ||
507 | + .aiocb_size = sizeof(VXHSAIOCB) | ||
508 | +}; | ||
509 | + | ||
510 | +/* | ||
511 | + * This allocates QEMU-VXHS callback for each IO | ||
512 | + * and is passed to QNIO. When QNIO completes the work, | ||
513 | + * it will be passed back through the callback. | ||
514 | + */ | ||
515 | +static BlockAIOCB *vxhs_aio_rw(BlockDriverState *bs, int64_t sector_num, | ||
516 | + QEMUIOVector *qiov, int nb_sectors, | ||
517 | + BlockCompletionFunc *cb, void *opaque, | ||
518 | + VDISKAIOCmd iodir) | ||
519 | +{ | ||
520 | + VXHSAIOCB *acb = NULL; | ||
521 | + BDRVVXHSState *s = bs->opaque; | ||
522 | + size_t size; | ||
523 | + uint64_t offset; | ||
524 | + int iio_flags = 0; | ||
525 | + int ret = 0; | ||
526 | + void *dev_handle = s->vdisk_hostinfo.dev_handle; | ||
527 | + | ||
528 | + offset = sector_num * BDRV_SECTOR_SIZE; | ||
529 | + size = nb_sectors * BDRV_SECTOR_SIZE; | ||
530 | + acb = qemu_aio_get(&vxhs_aiocb_info, bs, cb, opaque); | ||
531 | + | ||
532 | + /* | ||
533 | + * Initialize VXHSAIOCB. | ||
534 | + */ | ||
535 | + acb->err = 0; | ||
536 | + | ||
537 | + iio_flags = IIO_FLAG_ASYNC; | ||
538 | + | ||
539 | + switch (iodir) { | ||
540 | + case VDISK_AIO_WRITE: | ||
541 | + ret = iio_writev(dev_handle, acb, qiov->iov, qiov->niov, | ||
542 | + offset, (uint64_t)size, iio_flags); | ||
543 | + break; | ||
544 | + case VDISK_AIO_READ: | ||
545 | + ret = iio_readv(dev_handle, acb, qiov->iov, qiov->niov, | ||
546 | + offset, (uint64_t)size, iio_flags); | ||
547 | + break; | ||
548 | + default: | ||
549 | + trace_vxhs_aio_rw_invalid(iodir); | ||
550 | + goto errout; | ||
551 | + } | ||
552 | + | ||
553 | + if (ret != 0) { | ||
554 | + trace_vxhs_aio_rw_ioerr(s->vdisk_guid, iodir, size, offset, | ||
555 | + acb, ret, errno); | ||
556 | + goto errout; | ||
557 | + } | ||
558 | + return &acb->common; | ||
559 | + | ||
560 | +errout: | ||
561 | + qemu_aio_unref(acb); | ||
562 | + return NULL; | ||
563 | +} | ||
564 | + | ||
565 | +static BlockAIOCB *vxhs_aio_readv(BlockDriverState *bs, | ||
566 | + int64_t sector_num, QEMUIOVector *qiov, | ||
567 | + int nb_sectors, | ||
568 | + BlockCompletionFunc *cb, void *opaque) | ||
569 | +{ | ||
570 | + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, cb, | ||
571 | + opaque, VDISK_AIO_READ); | ||
572 | +} | ||
573 | + | ||
574 | +static BlockAIOCB *vxhs_aio_writev(BlockDriverState *bs, | ||
575 | + int64_t sector_num, QEMUIOVector *qiov, | ||
576 | + int nb_sectors, | ||
577 | + BlockCompletionFunc *cb, void *opaque) | ||
578 | +{ | ||
579 | + return vxhs_aio_rw(bs, sector_num, qiov, nb_sectors, | ||
580 | + cb, opaque, VDISK_AIO_WRITE); | ||
581 | +} | ||
582 | + | ||
583 | +static void vxhs_close(BlockDriverState *bs) | ||
584 | +{ | ||
585 | + BDRVVXHSState *s = bs->opaque; | ||
586 | + | ||
587 | + trace_vxhs_close(s->vdisk_guid); | ||
588 | + | ||
589 | + g_free(s->vdisk_guid); | ||
590 | + s->vdisk_guid = NULL; | ||
591 | + | ||
592 | + /* | ||
593 | + * Close vDisk device | ||
594 | + */ | ||
595 | + if (s->vdisk_hostinfo.dev_handle) { | ||
596 | + iio_close(s->vdisk_hostinfo.dev_handle); | ||
597 | + s->vdisk_hostinfo.dev_handle = NULL; | ||
598 | + } | ||
599 | + | ||
600 | + vxhs_unref(); | ||
601 | + | ||
602 | + /* | ||
603 | + * Free the dynamically allocated host string etc | ||
604 | + */ | ||
605 | + g_free(s->vdisk_hostinfo.host); | ||
606 | + g_free(s->tlscredsid); | ||
607 | + s->tlscredsid = NULL; | ||
608 | + s->vdisk_hostinfo.host = NULL; | ||
609 | + s->vdisk_hostinfo.port = 0; | ||
610 | +} | ||
611 | + | ||
612 | +static int64_t vxhs_get_vdisk_stat(BDRVVXHSState *s) | ||
613 | +{ | ||
614 | + int64_t vdisk_size = -1; | ||
615 | + int ret = 0; | ||
616 | + void *dev_handle = s->vdisk_hostinfo.dev_handle; | ||
617 | + | ||
618 | + ret = iio_ioctl(dev_handle, IOR_VDISK_STAT, &vdisk_size, 0); | ||
619 | + if (ret < 0) { | ||
620 | + trace_vxhs_get_vdisk_stat_err(s->vdisk_guid, ret, errno); | ||
621 | + return -EIO; | ||
622 | + } | ||
623 | + | ||
624 | + trace_vxhs_get_vdisk_stat(s->vdisk_guid, vdisk_size); | ||
625 | + return vdisk_size; | ||
626 | +} | ||
627 | + | ||
628 | +/* | ||
629 | + * Returns the size of vDisk in bytes. This is required | ||
630 | + * by QEMU block upper block layer so that it is visible | ||
631 | + * to guest. | ||
632 | + */ | ||
633 | +static int64_t vxhs_getlength(BlockDriverState *bs) | ||
634 | +{ | ||
635 | + BDRVVXHSState *s = bs->opaque; | ||
636 | + int64_t vdisk_size; | ||
637 | + | ||
638 | + vdisk_size = vxhs_get_vdisk_stat(s); | ||
639 | + if (vdisk_size < 0) { | ||
640 | + return -EIO; | ||
641 | + } | ||
642 | + | ||
643 | + return vdisk_size; | ||
644 | +} | ||
645 | + | ||
646 | +static BlockDriver bdrv_vxhs = { | ||
647 | + .format_name = "vxhs", | ||
648 | + .protocol_name = "vxhs", | ||
649 | + .instance_size = sizeof(BDRVVXHSState), | ||
650 | + .bdrv_file_open = vxhs_open, | ||
651 | + .bdrv_parse_filename = vxhs_parse_filename, | ||
652 | + .bdrv_close = vxhs_close, | ||
653 | + .bdrv_getlength = vxhs_getlength, | ||
654 | + .bdrv_aio_readv = vxhs_aio_readv, | ||
655 | + .bdrv_aio_writev = vxhs_aio_writev, | ||
656 | +}; | ||
657 | + | ||
658 | +static void bdrv_vxhs_init(void) | ||
659 | +{ | ||
660 | + bdrv_register(&bdrv_vxhs); | ||
661 | +} | ||
662 | + | ||
663 | +block_init(bdrv_vxhs_init); | ||
664 | diff --git a/configure b/configure | ||
665 | index XXXXXXX..XXXXXXX 100755 | ||
666 | --- a/configure | ||
667 | +++ b/configure | ||
668 | @@ -XXX,XX +XXX,XX @@ numa="" | ||
669 | tcmalloc="no" | ||
670 | jemalloc="no" | ||
671 | replication="yes" | ||
672 | +vxhs="" | ||
673 | |||
674 | supported_cpu="no" | ||
675 | supported_os="no" | ||
676 | @@ -XXX,XX +XXX,XX @@ for opt do | ||
677 | ;; | ||
678 | --enable-replication) replication="yes" | ||
679 | ;; | ||
680 | + --disable-vxhs) vxhs="no" | ||
681 | + ;; | ||
682 | + --enable-vxhs) vxhs="yes" | ||
683 | + ;; | ||
684 | *) | ||
685 | echo "ERROR: unknown option $opt" | ||
686 | echo "Try '$0 --help' for more information" | ||
687 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available: | ||
688 | xfsctl xfsctl support | ||
689 | qom-cast-debug cast debugging support | ||
690 | tools build qemu-io, qemu-nbd and qemu-image tools | ||
691 | + vxhs Veritas HyperScale vDisk backend support | ||
692 | |||
693 | NOTE: The object files are built at the place where configure is launched | ||
694 | EOF | ||
695 | @@ -XXX,XX +XXX,XX @@ if compile_prog "" "" ; then | ||
696 | fi | ||
697 | |||
698 | ########################################## | ||
699 | +# Veritas HyperScale block driver VxHS | ||
700 | +# Check if libvxhs is installed | ||
701 | + | ||
702 | +if test "$vxhs" != "no" ; then | ||
703 | + cat > $TMPC <<EOF | ||
704 | +#include <stdint.h> | ||
705 | +#include <qnio/qnio_api.h> | ||
706 | + | ||
707 | +void *vxhs_callback; | ||
708 | + | ||
709 | +int main(void) { | ||
710 | + iio_init(QNIO_VERSION, vxhs_callback); | ||
711 | + return 0; | ||
712 | +} | ||
713 | +EOF | ||
714 | + vxhs_libs="-lvxhs -lssl" | ||
715 | + if compile_prog "" "$vxhs_libs" ; then | ||
716 | + vxhs=yes | ||
717 | + else | ||
718 | + if test "$vxhs" = "yes" ; then | ||
719 | + feature_not_found "vxhs block device" "Install libvxhs See github" | ||
720 | + fi | ||
721 | + vxhs=no | ||
722 | + fi | ||
723 | +fi | ||
724 | + | ||
725 | +########################################## | ||
726 | # End of CC checks | ||
727 | # After here, no more $cc or $ld runs | ||
728 | |||
729 | @@ -XXX,XX +XXX,XX @@ echo "tcmalloc support $tcmalloc" | ||
730 | echo "jemalloc support $jemalloc" | ||
731 | echo "avx2 optimization $avx2_opt" | ||
732 | echo "replication support $replication" | ||
733 | +echo "VxHS block device $vxhs" | ||
734 | |||
735 | if test "$sdl_too_old" = "yes"; then | ||
736 | echo "-> Your SDL version is too old - please upgrade to have SDL support" | ||
737 | @@ -XXX,XX +XXX,XX @@ if test "$pthread_setname_np" = "yes" ; then | ||
738 | echo "CONFIG_PTHREAD_SETNAME_NP=y" >> $config_host_mak | ||
739 | fi | ||
740 | |||
741 | +if test "$vxhs" = "yes" ; then | ||
742 | + echo "CONFIG_VXHS=y" >> $config_host_mak | ||
743 | + echo "VXHS_LIBS=$vxhs_libs" >> $config_host_mak | ||
744 | +fi | ||
745 | + | ||
746 | if test "$tcg_interpreter" = "yes"; then | ||
747 | QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" | ||
748 | elif test "$ARCH" = "sparc64" ; then | ||
749 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
750 | index XXXXXXX..XXXXXXX 100644 | 528 | index XXXXXXX..XXXXXXX 100644 |
751 | --- a/qapi/block-core.json | 529 | --- a/util/meson.build |
752 | +++ b/qapi/block-core.json | 530 | +++ b/util/meson.build |
753 | @@ -XXX,XX +XXX,XX @@ | 531 | @@ -XXX,XX +XXX,XX @@ if have_block |
754 | # | 532 | util_ss.add(files('main-loop.c')) |
755 | # Drivers that are supported in block device operations. | 533 | util_ss.add(files('nvdimm-utils.c')) |
756 | # | 534 | util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c')) |
757 | +# @vxhs: Since 2.10 | 535 | + util_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-server.c')) |
758 | +# | 536 | util_ss.add(files('qemu-coroutine-sleep.c')) |
759 | # Since: 2.9 | 537 | util_ss.add(files('qemu-co-shared-resource.c')) |
760 | ## | 538 | util_ss.add(files('thread-pool.c', 'qemu-timer.c')) |
761 | { 'enum': 'BlockdevDriver', | ||
762 | @@ -XXX,XX +XXX,XX @@ | ||
763 | 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', | ||
764 | 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', | ||
765 | 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', | ||
766 | - 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } | ||
767 | + 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } | ||
768 | |||
769 | ## | ||
770 | # @BlockdevOptionsFile: | ||
771 | @@ -XXX,XX +XXX,XX @@ | ||
772 | 'data': { '*offset': 'int', '*size': 'int' } } | ||
773 | |||
774 | ## | ||
775 | +# @BlockdevOptionsVxHS: | ||
776 | +# | ||
777 | +# Driver specific block device options for VxHS | ||
778 | +# | ||
779 | +# @vdisk-id: UUID of VxHS volume | ||
780 | +# @server: vxhs server IP, port | ||
781 | +# @tls-creds: TLS credentials ID | ||
782 | +# | ||
783 | +# Since: 2.10 | ||
784 | +## | ||
785 | +{ 'struct': 'BlockdevOptionsVxHS', | ||
786 | + 'data': { 'vdisk-id': 'str', | ||
787 | + 'server': 'InetSocketAddressBase', | ||
788 | + '*tls-creds': 'str' } } | ||
789 | + | ||
790 | +## | ||
791 | # @BlockdevOptions: | ||
792 | # | ||
793 | # Options for creating a block device. Many options are available for all | ||
794 | @@ -XXX,XX +XXX,XX @@ | ||
795 | 'vhdx': 'BlockdevOptionsGenericFormat', | ||
796 | 'vmdk': 'BlockdevOptionsGenericCOWFormat', | ||
797 | 'vpc': 'BlockdevOptionsGenericFormat', | ||
798 | - 'vvfat': 'BlockdevOptionsVVFAT' | ||
799 | + 'vvfat': 'BlockdevOptionsVVFAT', | ||
800 | + 'vxhs': 'BlockdevOptionsVxHS' | ||
801 | } } | ||
802 | |||
803 | ## | ||
804 | -- | 539 | -- |
805 | 2.9.3 | 540 | 2.26.2 |
806 | 541 | ||
807 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
1 | 2 | ||
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 | ||
5 | |||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
10 | Acked-by: Eduardo Habkost <ehabkost@redhat.com> | ||
11 | Message-id: 20200918080912.321299-5-coiby.xu@gmail.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | util/block-helpers.h | 19 +++++++++++++ | ||
15 | hw/core/qdev-properties-system.c | 31 ++++----------------- | ||
16 | util/block-helpers.c | 46 ++++++++++++++++++++++++++++++++ | ||
17 | util/meson.build | 1 + | ||
18 | 4 files changed, 71 insertions(+), 26 deletions(-) | ||
19 | create mode 100644 util/block-helpers.h | ||
20 | create mode 100644 util/block-helpers.c | ||
21 | |||
22 | diff --git a/util/block-helpers.h b/util/block-helpers.h | ||
23 | new file mode 100644 | ||
24 | index XXXXXXX..XXXXXXX | ||
25 | --- /dev/null | ||
26 | +++ b/util/block-helpers.h | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | +#ifndef BLOCK_HELPERS_H | ||
29 | +#define BLOCK_HELPERS_H | ||
30 | + | ||
31 | +#include "qemu/units.h" | ||
32 | + | ||
33 | +/* lower limit is sector size */ | ||
34 | +#define MIN_BLOCK_SIZE INT64_C(512) | ||
35 | +#define MIN_BLOCK_SIZE_STR "512 B" | ||
36 | +/* | ||
37 | + * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and | ||
38 | + * matches qcow2 cluster size limit | ||
39 | + */ | ||
40 | +#define MAX_BLOCK_SIZE (2 * MiB) | ||
41 | +#define MAX_BLOCK_SIZE_STR "2 MiB" | ||
42 | + | ||
43 | +void check_block_size(const char *id, const char *name, int64_t value, | ||
44 | + Error **errp); | ||
45 | + | ||
46 | +#endif /* BLOCK_HELPERS_H */ | ||
47 | diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/core/qdev-properties-system.c | ||
50 | +++ b/hw/core/qdev-properties-system.c | ||
51 | @@ -XXX,XX +XXX,XX @@ | ||
52 | #include "sysemu/blockdev.h" | ||
53 | #include "net/net.h" | ||
54 | #include "hw/pci/pci.h" | ||
55 | +#include "util/block-helpers.h" | ||
56 | |||
57 | static bool check_prop_still_unset(DeviceState *dev, const char *name, | ||
58 | const void *old_val, const char *new_val, | ||
59 | @@ -XXX,XX +XXX,XX @@ const PropertyInfo qdev_prop_losttickpolicy = { | ||
60 | |||
61 | /* --- blocksize --- */ | ||
62 | |||
63 | -/* lower limit is sector size */ | ||
64 | -#define MIN_BLOCK_SIZE 512 | ||
65 | -#define MIN_BLOCK_SIZE_STR "512 B" | ||
66 | -/* | ||
67 | - * upper limit is arbitrary, 2 MiB looks sufficient for all sensible uses, and | ||
68 | - * matches qcow2 cluster size limit | ||
69 | - */ | ||
70 | -#define MAX_BLOCK_SIZE (2 * MiB) | ||
71 | -#define MAX_BLOCK_SIZE_STR "2 MiB" | ||
72 | - | ||
73 | static void set_blocksize(Object *obj, Visitor *v, const char *name, | ||
74 | void *opaque, Error **errp) | ||
75 | { | ||
76 | @@ -XXX,XX +XXX,XX @@ static void set_blocksize(Object *obj, Visitor *v, const char *name, | ||
77 | Property *prop = opaque; | ||
78 | uint32_t *ptr = qdev_get_prop_ptr(dev, prop); | ||
79 | uint64_t value; | ||
80 | + Error *local_err = NULL; | ||
81 | |||
82 | if (dev->realized) { | ||
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, | ||
85 | if (!visit_type_size(v, name, &value, errp)) { | ||
86 | return; | ||
87 | } | ||
88 | - /* value of 0 means "unset" */ | ||
89 | - if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { | ||
90 | - error_setg(errp, | ||
91 | - "Property %s.%s doesn't take value %" PRIu64 | ||
92 | - " (minimum: " MIN_BLOCK_SIZE_STR | ||
93 | - ", maximum: " MAX_BLOCK_SIZE_STR ")", | ||
94 | - dev->id ? : "", name, value); | ||
95 | + check_block_size(dev->id ? : "", name, value, &local_err); | ||
96 | + if (local_err) { | ||
97 | + error_propagate(errp, local_err); | ||
98 | return; | ||
99 | } | ||
100 | - | ||
101 | - /* We rely on power-of-2 blocksizes for bitmasks */ | ||
102 | - if ((value & (value - 1)) != 0) { | ||
103 | - error_setg(errp, | ||
104 | - "Property %s.%s doesn't take value '%" PRId64 "', " | ||
105 | - "it's not a power of 2", dev->id ?: "", name, (int64_t)value); | ||
106 | - return; | ||
107 | - } | ||
108 | - | ||
109 | *ptr = value; | ||
110 | } | ||
111 | |||
112 | diff --git a/util/block-helpers.c b/util/block-helpers.c | ||
113 | new file mode 100644 | ||
114 | index XXXXXXX..XXXXXXX | ||
115 | --- /dev/null | ||
116 | +++ b/util/block-helpers.c | ||
117 | @@ -XXX,XX +XXX,XX @@ | ||
118 | +/* | ||
119 | + * Block utility functions | ||
120 | + * | ||
121 | + * Copyright IBM, Corp. 2011 | ||
122 | + * Copyright (c) 2020 Coiby Xu <coiby.xu@gmail.com> | ||
123 | + * | ||
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. | ||
126 | + */ | ||
127 | + | ||
128 | +#include "qemu/osdep.h" | ||
129 | +#include "qapi/error.h" | ||
130 | +#include "qapi/qmp/qerror.h" | ||
131 | +#include "block-helpers.h" | ||
132 | + | ||
133 | +/** | ||
134 | + * check_block_size: | ||
135 | + * @id: The unique ID of the object | ||
136 | + * @name: The name of the property being validated | ||
137 | + * @value: The block size in bytes | ||
138 | + * @errp: A pointer to an area to store an error | ||
139 | + * | ||
140 | + * This function checks that the block size meets the following conditions: | ||
141 | + * 1. At least MIN_BLOCK_SIZE | ||
142 | + * 2. No larger than MAX_BLOCK_SIZE | ||
143 | + * 3. A power of 2 | ||
144 | + */ | ||
145 | +void check_block_size(const char *id, const char *name, int64_t value, | ||
146 | + Error **errp) | ||
147 | +{ | ||
148 | + /* value of 0 means "unset" */ | ||
149 | + if (value && (value < MIN_BLOCK_SIZE || value > MAX_BLOCK_SIZE)) { | ||
150 | + error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, | ||
151 | + id, name, value, MIN_BLOCK_SIZE, MAX_BLOCK_SIZE); | ||
152 | + return; | ||
153 | + } | ||
154 | + | ||
155 | + /* We rely on power-of-2 blocksizes for bitmasks */ | ||
156 | + if ((value & (value - 1)) != 0) { | ||
157 | + error_setg(errp, | ||
158 | + "Property %s.%s doesn't take value '%" PRId64 | ||
159 | + "', it's not a power of 2", | ||
160 | + id, name, value); | ||
161 | + return; | ||
162 | + } | ||
163 | +} | ||
164 | diff --git a/util/meson.build b/util/meson.build | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/util/meson.build | ||
167 | +++ b/util/meson.build | ||
168 | @@ -XXX,XX +XXX,XX @@ if have_block | ||
169 | util_ss.add(files('nvdimm-utils.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')) | ||
172 | + util_ss.add(files('block-helpers.c')) | ||
173 | util_ss.add(files('qemu-coroutine-sleep.c')) | ||
174 | util_ss.add(files('qemu-co-shared-resource.c')) | ||
175 | util_ss.add(files('thread-pool.c', 'qemu-timer.c')) | ||
176 | -- | ||
177 | 2.26.2 | ||
178 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
1 | 2 | ||
3 | By making use of libvhost-user, block device drive can be shared to | ||
4 | the connected vhost-user client. Only one client can connect to the | ||
5 | server one time. | ||
6 | |||
7 | Since vhost-user-server needs a block drive to be created first, delay | ||
8 | the creation of this object. | ||
9 | |||
10 | Suggested-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.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 | ||
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=] | ||
19 | --Stefan] | ||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | --- | ||
22 | block/export/vhost-user-blk-server.h | 36 ++ | ||
23 | block/export/vhost-user-blk-server.c | 661 +++++++++++++++++++++++++++ | ||
24 | softmmu/vl.c | 4 + | ||
25 | block/meson.build | 1 + | ||
26 | 4 files changed, 702 insertions(+) | ||
27 | create mode 100644 block/export/vhost-user-blk-server.h | ||
28 | create mode 100644 block/export/vhost-user-blk-server.c | ||
29 | |||
30 | diff --git a/block/export/vhost-user-blk-server.h b/block/export/vhost-user-blk-server.h | ||
31 | new file mode 100644 | ||
32 | index XXXXXXX..XXXXXXX | ||
33 | --- /dev/null | ||
34 | +++ b/block/export/vhost-user-blk-server.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | +/* | ||
37 | + * Sharing QEMU block devices via vhost-user protocal | ||
38 | + * | ||
39 | + * Copyright (c) Coiby Xu <coiby.xu@gmail.com>. | ||
40 | + * Copyright (c) 2020 Red Hat, Inc. | ||
41 | + * | ||
42 | + * This work is licensed under the terms of the GNU GPL, version 2 or | ||
43 | + * later. See the COPYING file in the top-level directory. | ||
44 | + */ | ||
45 | + | ||
46 | +#ifndef VHOST_USER_BLK_SERVER_H | ||
47 | +#define VHOST_USER_BLK_SERVER_H | ||
48 | +#include "util/vhost-user-server.h" | ||
49 | + | ||
50 | +typedef struct VuBlockDev VuBlockDev; | ||
51 | +#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" | ||
52 | +#define VHOST_USER_BLK_SERVER(obj) \ | ||
53 | + OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) | ||
54 | + | ||
55 | +/* vhost user block device */ | ||
56 | +struct VuBlockDev { | ||
57 | + Object parent_obj; | ||
58 | + char *node_name; | ||
59 | + SocketAddress *addr; | ||
60 | + AioContext *ctx; | ||
61 | + VuServer vu_server; | ||
62 | + bool running; | ||
63 | + uint32_t blk_size; | ||
64 | + BlockBackend *backend; | ||
65 | + QIOChannelSocket *sioc; | ||
66 | + QTAILQ_ENTRY(VuBlockDev) next; | ||
67 | + struct virtio_blk_config blkcfg; | ||
68 | + bool writable; | ||
69 | +}; | ||
70 | + | ||
71 | +#endif /* VHOST_USER_BLK_SERVER_H */ | ||
72 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
73 | new file mode 100644 | ||
74 | index XXXXXXX..XXXXXXX | ||
75 | --- /dev/null | ||
76 | +++ b/block/export/vhost-user-blk-server.c | ||
77 | @@ -XXX,XX +XXX,XX @@ | ||
78 | +/* | ||
79 | + * Sharing QEMU block devices via vhost-user protocal | ||
80 | + * | ||
81 | + * Parts of the code based on nbd/server.c. | ||
82 | + * | ||
83 | + * Copyright (c) Coiby Xu <coiby.xu@gmail.com>. | ||
84 | + * Copyright (c) 2020 Red Hat, Inc. | ||
85 | + * | ||
86 | + * This work is licensed under the terms of the GNU GPL, version 2 or | ||
87 | + * later. See the COPYING file in the top-level directory. | ||
88 | + */ | ||
89 | +#include "qemu/osdep.h" | ||
90 | +#include "block/block.h" | ||
91 | +#include "vhost-user-blk-server.h" | ||
92 | +#include "qapi/error.h" | ||
93 | +#include "qom/object_interfaces.h" | ||
94 | +#include "sysemu/block-backend.h" | ||
95 | +#include "util/block-helpers.h" | ||
96 | + | ||
97 | +enum { | ||
98 | + VHOST_USER_BLK_MAX_QUEUES = 1, | ||
99 | +}; | ||
100 | +struct virtio_blk_inhdr { | ||
101 | + unsigned char status; | ||
102 | +}; | ||
103 | + | ||
104 | +typedef struct VuBlockReq { | ||
105 | + VuVirtqElement *elem; | ||
106 | + int64_t sector_num; | ||
107 | + size_t size; | ||
108 | + struct virtio_blk_inhdr *in; | ||
109 | + struct virtio_blk_outhdr out; | ||
110 | + VuServer *server; | ||
111 | + struct VuVirtq *vq; | ||
112 | +} VuBlockReq; | ||
113 | + | ||
114 | +static void vu_block_req_complete(VuBlockReq *req) | ||
115 | +{ | ||
116 | + VuDev *vu_dev = &req->server->vu_dev; | ||
117 | + | ||
118 | + /* IO size with 1 extra status byte */ | ||
119 | + vu_queue_push(vu_dev, req->vq, req->elem, req->size + 1); | ||
120 | + vu_queue_notify(vu_dev, req->vq); | ||
121 | + | ||
122 | + if (req->elem) { | ||
123 | + free(req->elem); | ||
124 | + } | ||
125 | + | ||
126 | + g_free(req); | ||
127 | +} | ||
128 | + | ||
129 | +static VuBlockDev *get_vu_block_device_by_server(VuServer *server) | ||
130 | +{ | ||
131 | + return container_of(server, VuBlockDev, vu_server); | ||
132 | +} | ||
133 | + | ||
134 | +static int coroutine_fn | ||
135 | +vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, | ||
136 | + uint32_t iovcnt, uint32_t type) | ||
137 | +{ | ||
138 | + struct virtio_blk_discard_write_zeroes desc; | ||
139 | + ssize_t size = iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); | ||
140 | + if (unlikely(size != sizeof(desc))) { | ||
141 | + error_report("Invalid size %ld, expect %ld", size, sizeof(desc)); | ||
142 | + return -EINVAL; | ||
143 | + } | ||
144 | + | ||
145 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | ||
146 | + uint64_t range[2] = { le64_to_cpu(desc.sector) << 9, | ||
147 | + le32_to_cpu(desc.num_sectors) << 9 }; | ||
148 | + if (type == VIRTIO_BLK_T_DISCARD) { | ||
149 | + if (blk_co_pdiscard(vdev_blk->backend, range[0], range[1]) == 0) { | ||
150 | + return 0; | ||
151 | + } | ||
152 | + } else if (type == VIRTIO_BLK_T_WRITE_ZEROES) { | ||
153 | + if (blk_co_pwrite_zeroes(vdev_blk->backend, | ||
154 | + range[0], range[1], 0) == 0) { | ||
155 | + return 0; | ||
156 | + } | ||
157 | + } | ||
158 | + | ||
159 | + return -EINVAL; | ||
160 | +} | ||
161 | + | ||
162 | +static void coroutine_fn vu_block_flush(VuBlockReq *req) | ||
163 | +{ | ||
164 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | ||
165 | + BlockBackend *backend = vdev_blk->backend; | ||
166 | + blk_co_flush(backend); | ||
167 | +} | ||
168 | + | ||
169 | +struct req_data { | ||
170 | + VuServer *server; | ||
171 | + VuVirtq *vq; | ||
172 | + VuVirtqElement *elem; | ||
173 | +}; | ||
174 | + | ||
175 | +static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
176 | +{ | ||
177 | + struct req_data *data = opaque; | ||
178 | + VuServer *server = data->server; | ||
179 | + VuVirtq *vq = data->vq; | ||
180 | + VuVirtqElement *elem = data->elem; | ||
181 | + uint32_t type; | ||
182 | + VuBlockReq *req; | ||
183 | + | ||
184 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
185 | + BlockBackend *backend = vdev_blk->backend; | ||
186 | + | ||
187 | + struct iovec *in_iov = elem->in_sg; | ||
188 | + struct iovec *out_iov = elem->out_sg; | ||
189 | + unsigned in_num = elem->in_num; | ||
190 | + unsigned out_num = elem->out_num; | ||
191 | + /* refer to hw/block/virtio_blk.c */ | ||
192 | + if (elem->out_num < 1 || elem->in_num < 1) { | ||
193 | + error_report("virtio-blk request missing headers"); | ||
194 | + free(elem); | ||
195 | + return; | ||
196 | + } | ||
197 | + | ||
198 | + req = g_new0(VuBlockReq, 1); | ||
199 | + req->server = server; | ||
200 | + req->vq = vq; | ||
201 | + req->elem = elem; | ||
202 | + | ||
203 | + if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, | ||
204 | + sizeof(req->out)) != sizeof(req->out))) { | ||
205 | + error_report("virtio-blk request outhdr too short"); | ||
206 | + goto err; | ||
207 | + } | ||
208 | + | ||
209 | + iov_discard_front(&out_iov, &out_num, sizeof(req->out)); | ||
210 | + | ||
211 | + if (in_iov[in_num - 1].iov_len < sizeof(struct virtio_blk_inhdr)) { | ||
212 | + error_report("virtio-blk request inhdr too short"); | ||
213 | + goto err; | ||
214 | + } | ||
215 | + | ||
216 | + /* We always touch the last byte, so just see how big in_iov is. */ | ||
217 | + req->in = (void *)in_iov[in_num - 1].iov_base | ||
218 | + + in_iov[in_num - 1].iov_len | ||
219 | + - sizeof(struct virtio_blk_inhdr); | ||
220 | + iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr)); | ||
221 | + | ||
222 | + type = le32_to_cpu(req->out.type); | ||
223 | + switch (type & ~VIRTIO_BLK_T_BARRIER) { | ||
224 | + case VIRTIO_BLK_T_IN: | ||
225 | + case VIRTIO_BLK_T_OUT: { | ||
226 | + ssize_t ret = 0; | ||
227 | + bool is_write = type & VIRTIO_BLK_T_OUT; | ||
228 | + req->sector_num = le64_to_cpu(req->out.sector); | ||
229 | + | ||
230 | + int64_t offset = req->sector_num * vdev_blk->blk_size; | ||
231 | + QEMUIOVector qiov; | ||
232 | + if (is_write) { | ||
233 | + qemu_iovec_init_external(&qiov, out_iov, out_num); | ||
234 | + ret = blk_co_pwritev(backend, offset, qiov.size, | ||
235 | + &qiov, 0); | ||
236 | + } else { | ||
237 | + qemu_iovec_init_external(&qiov, in_iov, in_num); | ||
238 | + ret = blk_co_preadv(backend, offset, qiov.size, | ||
239 | + &qiov, 0); | ||
240 | + } | ||
241 | + if (ret >= 0) { | ||
242 | + req->in->status = VIRTIO_BLK_S_OK; | ||
243 | + } else { | ||
244 | + req->in->status = VIRTIO_BLK_S_IOERR; | ||
245 | + } | ||
246 | + break; | ||
247 | + } | ||
248 | + case VIRTIO_BLK_T_FLUSH: | ||
249 | + vu_block_flush(req); | ||
250 | + req->in->status = VIRTIO_BLK_S_OK; | ||
251 | + break; | ||
252 | + case VIRTIO_BLK_T_GET_ID: { | ||
253 | + size_t size = MIN(iov_size(&elem->in_sg[0], in_num), | ||
254 | + VIRTIO_BLK_ID_BYTES); | ||
255 | + snprintf(elem->in_sg[0].iov_base, size, "%s", "vhost_user_blk"); | ||
256 | + req->in->status = VIRTIO_BLK_S_OK; | ||
257 | + req->size = elem->in_sg[0].iov_len; | ||
258 | + break; | ||
259 | + } | ||
260 | + case VIRTIO_BLK_T_DISCARD: | ||
261 | + case VIRTIO_BLK_T_WRITE_ZEROES: { | ||
262 | + int rc; | ||
263 | + rc = vu_block_discard_write_zeroes(req, &elem->out_sg[1], | ||
264 | + out_num, type); | ||
265 | + if (rc == 0) { | ||
266 | + req->in->status = VIRTIO_BLK_S_OK; | ||
267 | + } else { | ||
268 | + req->in->status = VIRTIO_BLK_S_IOERR; | ||
269 | + } | ||
270 | + break; | ||
271 | + } | ||
272 | + default: | ||
273 | + req->in->status = VIRTIO_BLK_S_UNSUPP; | ||
274 | + break; | ||
275 | + } | ||
276 | + | ||
277 | + vu_block_req_complete(req); | ||
278 | + return; | ||
279 | + | ||
280 | +err: | ||
281 | + free(elem); | ||
282 | + g_free(req); | ||
283 | + return; | ||
284 | +} | ||
285 | + | ||
286 | +static void vu_block_process_vq(VuDev *vu_dev, int idx) | ||
287 | +{ | ||
288 | + VuServer *server; | ||
289 | + VuVirtq *vq; | ||
290 | + struct req_data *req_data; | ||
291 | + | ||
292 | + server = container_of(vu_dev, VuServer, vu_dev); | ||
293 | + assert(server); | ||
294 | + | ||
295 | + vq = vu_get_queue(vu_dev, idx); | ||
296 | + assert(vq); | ||
297 | + VuVirtqElement *elem; | ||
298 | + while (1) { | ||
299 | + elem = vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + | ||
300 | + sizeof(VuBlockReq)); | ||
301 | + if (elem) { | ||
302 | + req_data = g_new0(struct req_data, 1); | ||
303 | + req_data->server = server; | ||
304 | + req_data->vq = vq; | ||
305 | + req_data->elem = elem; | ||
306 | + Coroutine *co = qemu_coroutine_create(vu_block_virtio_process_req, | ||
307 | + req_data); | ||
308 | + aio_co_enter(server->ioc->ctx, co); | ||
309 | + } else { | ||
310 | + break; | ||
311 | + } | ||
312 | + } | ||
313 | +} | ||
314 | + | ||
315 | +static void vu_block_queue_set_started(VuDev *vu_dev, int idx, bool started) | ||
316 | +{ | ||
317 | + VuVirtq *vq; | ||
318 | + | ||
319 | + assert(vu_dev); | ||
320 | + | ||
321 | + vq = vu_get_queue(vu_dev, idx); | ||
322 | + vu_set_queue_handler(vu_dev, vq, started ? vu_block_process_vq : NULL); | ||
323 | +} | ||
324 | + | ||
325 | +static uint64_t vu_block_get_features(VuDev *dev) | ||
326 | +{ | ||
327 | + uint64_t features; | ||
328 | + VuServer *server = container_of(dev, VuServer, vu_dev); | ||
329 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
330 | + features = 1ull << VIRTIO_BLK_F_SIZE_MAX | | ||
331 | + 1ull << VIRTIO_BLK_F_SEG_MAX | | ||
332 | + 1ull << VIRTIO_BLK_F_TOPOLOGY | | ||
333 | + 1ull << VIRTIO_BLK_F_BLK_SIZE | | ||
334 | + 1ull << VIRTIO_BLK_F_FLUSH | | ||
335 | + 1ull << VIRTIO_BLK_F_DISCARD | | ||
336 | + 1ull << VIRTIO_BLK_F_WRITE_ZEROES | | ||
337 | + 1ull << VIRTIO_BLK_F_CONFIG_WCE | | ||
338 | + 1ull << VIRTIO_F_VERSION_1 | | ||
339 | + 1ull << VIRTIO_RING_F_INDIRECT_DESC | | ||
340 | + 1ull << VIRTIO_RING_F_EVENT_IDX | | ||
341 | + 1ull << VHOST_USER_F_PROTOCOL_FEATURES; | ||
342 | + | ||
343 | + if (!vdev_blk->writable) { | ||
344 | + features |= 1ull << VIRTIO_BLK_F_RO; | ||
345 | + } | ||
346 | + | ||
347 | + return features; | ||
348 | +} | ||
349 | + | ||
350 | +static uint64_t vu_block_get_protocol_features(VuDev *dev) | ||
351 | +{ | ||
352 | + return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | | ||
353 | + 1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; | ||
354 | +} | ||
355 | + | ||
356 | +static int | ||
357 | +vu_block_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) | ||
358 | +{ | ||
359 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
360 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
361 | + memcpy(config, &vdev_blk->blkcfg, len); | ||
362 | + | ||
363 | + return 0; | ||
364 | +} | ||
365 | + | ||
366 | +static int | ||
367 | +vu_block_set_config(VuDev *vu_dev, const uint8_t *data, | ||
368 | + uint32_t offset, uint32_t size, uint32_t flags) | ||
369 | +{ | ||
370 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
371 | + VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
372 | + uint8_t wce; | ||
373 | + | ||
374 | + /* don't support live migration */ | ||
375 | + if (flags != VHOST_SET_CONFIG_TYPE_MASTER) { | ||
376 | + return -EINVAL; | ||
377 | + } | ||
378 | + | ||
379 | + if (offset != offsetof(struct virtio_blk_config, wce) || | ||
380 | + size != 1) { | ||
381 | + return -EINVAL; | ||
382 | + } | ||
383 | + | ||
384 | + wce = *data; | ||
385 | + vdev_blk->blkcfg.wce = wce; | ||
386 | + blk_set_enable_write_cache(vdev_blk->backend, wce); | ||
387 | + return 0; | ||
388 | +} | ||
389 | + | ||
390 | +/* | ||
391 | + * When the client disconnects, it sends a VHOST_USER_NONE request | ||
392 | + * and vu_process_message will simple call exit which cause the VM | ||
393 | + * to exit abruptly. | ||
394 | + * To avoid this issue, process VHOST_USER_NONE request ahead | ||
395 | + * of vu_process_message. | ||
396 | + * | ||
397 | + */ | ||
398 | +static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_reply) | ||
399 | +{ | ||
400 | + if (vmsg->request == VHOST_USER_NONE) { | ||
401 | + dev->panic(dev, "disconnect"); | ||
402 | + return true; | ||
403 | + } | ||
404 | + return false; | ||
405 | +} | ||
406 | + | ||
407 | +static const VuDevIface vu_block_iface = { | ||
408 | + .get_features = vu_block_get_features, | ||
409 | + .queue_set_started = vu_block_queue_set_started, | ||
410 | + .get_protocol_features = vu_block_get_protocol_features, | ||
411 | + .get_config = vu_block_get_config, | ||
412 | + .set_config = vu_block_set_config, | ||
413 | + .process_msg = vu_block_process_msg, | ||
414 | +}; | ||
415 | + | ||
416 | +static void blk_aio_attached(AioContext *ctx, void *opaque) | ||
417 | +{ | ||
418 | + VuBlockDev *vub_dev = opaque; | ||
419 | + aio_context_acquire(ctx); | ||
420 | + vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); | ||
421 | + aio_context_release(ctx); | ||
422 | +} | ||
423 | + | ||
424 | +static void blk_aio_detach(void *opaque) | ||
425 | +{ | ||
426 | + VuBlockDev *vub_dev = opaque; | ||
427 | + AioContext *ctx = vub_dev->vu_server.ctx; | ||
428 | + aio_context_acquire(ctx); | ||
429 | + vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); | ||
430 | + aio_context_release(ctx); | ||
431 | +} | ||
432 | + | ||
433 | +static void | ||
434 | +vu_block_initialize_config(BlockDriverState *bs, | ||
435 | + struct virtio_blk_config *config, uint32_t blk_size) | ||
436 | +{ | ||
437 | + config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; | ||
438 | + config->blk_size = blk_size; | ||
439 | + config->size_max = 0; | ||
440 | + config->seg_max = 128 - 2; | ||
441 | + config->min_io_size = 1; | ||
442 | + config->opt_io_size = 1; | ||
443 | + config->num_queues = VHOST_USER_BLK_MAX_QUEUES; | ||
444 | + config->max_discard_sectors = 32768; | ||
445 | + config->max_discard_seg = 1; | ||
446 | + config->discard_sector_alignment = config->blk_size >> 9; | ||
447 | + config->max_write_zeroes_sectors = 32768; | ||
448 | + config->max_write_zeroes_seg = 1; | ||
449 | +} | ||
450 | + | ||
451 | +static VuBlockDev *vu_block_init(VuBlockDev *vu_block_device, Error **errp) | ||
452 | +{ | ||
453 | + | ||
454 | + BlockBackend *blk; | ||
455 | + Error *local_error = NULL; | ||
456 | + const char *node_name = vu_block_device->node_name; | ||
457 | + bool writable = vu_block_device->writable; | ||
458 | + uint64_t perm = BLK_PERM_CONSISTENT_READ; | ||
459 | + int ret; | ||
460 | + | ||
461 | + AioContext *ctx; | ||
462 | + | ||
463 | + BlockDriverState *bs = bdrv_lookup_bs(node_name, node_name, &local_error); | ||
464 | + | ||
465 | + if (!bs) { | ||
466 | + error_propagate(errp, local_error); | ||
467 | + return NULL; | ||
468 | + } | ||
469 | + | ||
470 | + if (bdrv_is_read_only(bs)) { | ||
471 | + writable = false; | ||
472 | + } | ||
473 | + | ||
474 | + if (writable) { | ||
475 | + perm |= BLK_PERM_WRITE; | ||
476 | + } | ||
477 | + | ||
478 | + ctx = bdrv_get_aio_context(bs); | ||
479 | + aio_context_acquire(ctx); | ||
480 | + bdrv_invalidate_cache(bs, NULL); | ||
481 | + aio_context_release(ctx); | ||
482 | + | ||
483 | + /* | ||
484 | + * Don't allow resize while the vhost user server is running, | ||
485 | + * otherwise we don't care what happens with the node. | ||
486 | + */ | ||
487 | + blk = blk_new(bdrv_get_aio_context(bs), perm, | ||
488 | + BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | | ||
489 | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); | ||
490 | + ret = blk_insert_bs(blk, bs, errp); | ||
491 | + | ||
492 | + if (ret < 0) { | ||
493 | + goto fail; | ||
494 | + } | ||
495 | + | ||
496 | + blk_set_enable_write_cache(blk, false); | ||
497 | + | ||
498 | + blk_set_allow_aio_context_change(blk, true); | ||
499 | + | ||
500 | + vu_block_device->blkcfg.wce = 0; | ||
501 | + vu_block_device->backend = blk; | ||
502 | + if (!vu_block_device->blk_size) { | ||
503 | + vu_block_device->blk_size = BDRV_SECTOR_SIZE; | ||
504 | + } | ||
505 | + vu_block_device->blkcfg.blk_size = vu_block_device->blk_size; | ||
506 | + blk_set_guest_block_size(blk, vu_block_device->blk_size); | ||
507 | + vu_block_initialize_config(bs, &vu_block_device->blkcfg, | ||
508 | + vu_block_device->blk_size); | ||
509 | + return vu_block_device; | ||
510 | + | ||
511 | +fail: | ||
512 | + blk_unref(blk); | ||
513 | + return NULL; | ||
514 | +} | ||
515 | + | ||
516 | +static void vu_block_deinit(VuBlockDev *vu_block_device) | ||
517 | +{ | ||
518 | + if (vu_block_device->backend) { | ||
519 | + blk_remove_aio_context_notifier(vu_block_device->backend, blk_aio_attached, | ||
520 | + blk_aio_detach, vu_block_device); | ||
521 | + } | ||
522 | + | ||
523 | + blk_unref(vu_block_device->backend); | ||
524 | +} | ||
525 | + | ||
526 | +static void vhost_user_blk_server_stop(VuBlockDev *vu_block_device) | ||
527 | +{ | ||
528 | + vhost_user_server_stop(&vu_block_device->vu_server); | ||
529 | + vu_block_deinit(vu_block_device); | ||
530 | +} | ||
531 | + | ||
532 | +static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, | ||
533 | + Error **errp) | ||
534 | +{ | ||
535 | + AioContext *ctx; | ||
536 | + SocketAddress *addr = vu_block_device->addr; | ||
537 | + | ||
538 | + if (!vu_block_init(vu_block_device, errp)) { | ||
539 | + return; | ||
540 | + } | ||
541 | + | ||
542 | + ctx = bdrv_get_aio_context(blk_bs(vu_block_device->backend)); | ||
543 | + | ||
544 | + if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, | ||
545 | + VHOST_USER_BLK_MAX_QUEUES, | ||
546 | + NULL, &vu_block_iface, | ||
547 | + errp)) { | ||
548 | + goto error; | ||
549 | + } | ||
550 | + | ||
551 | + blk_add_aio_context_notifier(vu_block_device->backend, blk_aio_attached, | ||
552 | + blk_aio_detach, vu_block_device); | ||
553 | + vu_block_device->running = true; | ||
554 | + return; | ||
555 | + | ||
556 | + error: | ||
557 | + vu_block_deinit(vu_block_device); | ||
558 | +} | ||
559 | + | ||
560 | +static bool vu_prop_modifiable(VuBlockDev *vus, Error **errp) | ||
561 | +{ | ||
562 | + if (vus->running) { | ||
563 | + error_setg(errp, "The property can't be modified " | ||
564 | + "while the server is running"); | ||
565 | + return false; | ||
566 | + } | ||
567 | + return true; | ||
568 | +} | ||
569 | + | ||
570 | +static void vu_set_node_name(Object *obj, const char *value, Error **errp) | ||
571 | +{ | ||
572 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
573 | + | ||
574 | + if (!vu_prop_modifiable(vus, errp)) { | ||
575 | + return; | ||
576 | + } | ||
577 | + | ||
578 | + if (vus->node_name) { | ||
579 | + g_free(vus->node_name); | ||
580 | + } | ||
581 | + | ||
582 | + vus->node_name = g_strdup(value); | ||
583 | +} | ||
584 | + | ||
585 | +static char *vu_get_node_name(Object *obj, Error **errp) | ||
586 | +{ | ||
587 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
588 | + return g_strdup(vus->node_name); | ||
589 | +} | ||
590 | + | ||
591 | +static void free_socket_addr(SocketAddress *addr) | ||
592 | +{ | ||
593 | + g_free(addr->u.q_unix.path); | ||
594 | + g_free(addr); | ||
595 | +} | ||
596 | + | ||
597 | +static void vu_set_unix_socket(Object *obj, const char *value, | ||
598 | + Error **errp) | ||
599 | +{ | ||
600 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
601 | + | ||
602 | + if (!vu_prop_modifiable(vus, errp)) { | ||
603 | + return; | ||
604 | + } | ||
605 | + | ||
606 | + if (vus->addr) { | ||
607 | + free_socket_addr(vus->addr); | ||
608 | + } | ||
609 | + | ||
610 | + SocketAddress *addr = g_new0(SocketAddress, 1); | ||
611 | + addr->type = SOCKET_ADDRESS_TYPE_UNIX; | ||
612 | + addr->u.q_unix.path = g_strdup(value); | ||
613 | + vus->addr = addr; | ||
614 | +} | ||
615 | + | ||
616 | +static char *vu_get_unix_socket(Object *obj, Error **errp) | ||
617 | +{ | ||
618 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
619 | + return g_strdup(vus->addr->u.q_unix.path); | ||
620 | +} | ||
621 | + | ||
622 | +static bool vu_get_block_writable(Object *obj, Error **errp) | ||
623 | +{ | ||
624 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
625 | + return vus->writable; | ||
626 | +} | ||
627 | + | ||
628 | +static void vu_set_block_writable(Object *obj, bool value, Error **errp) | ||
629 | +{ | ||
630 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
631 | + | ||
632 | + if (!vu_prop_modifiable(vus, errp)) { | ||
633 | + return; | ||
634 | + } | ||
635 | + | ||
636 | + vus->writable = value; | ||
637 | +} | ||
638 | + | ||
639 | +static void vu_get_blk_size(Object *obj, Visitor *v, const char *name, | ||
640 | + void *opaque, Error **errp) | ||
641 | +{ | ||
642 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
643 | + uint32_t value = vus->blk_size; | ||
644 | + | ||
645 | + visit_type_uint32(v, name, &value, errp); | ||
646 | +} | ||
647 | + | ||
648 | +static void vu_set_blk_size(Object *obj, Visitor *v, const char *name, | ||
649 | + void *opaque, Error **errp) | ||
650 | +{ | ||
651 | + VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
652 | + | ||
653 | + Error *local_err = NULL; | ||
654 | + uint32_t value; | ||
655 | + | ||
656 | + if (!vu_prop_modifiable(vus, errp)) { | ||
657 | + return; | ||
658 | + } | ||
659 | + | ||
660 | + visit_type_uint32(v, name, &value, &local_err); | ||
661 | + if (local_err) { | ||
662 | + goto out; | ||
663 | + } | ||
664 | + | ||
665 | + check_block_size(object_get_typename(obj), name, value, &local_err); | ||
666 | + if (local_err) { | ||
667 | + goto out; | ||
668 | + } | ||
669 | + | ||
670 | + vus->blk_size = value; | ||
671 | + | ||
672 | +out: | ||
673 | + error_propagate(errp, local_err); | ||
674 | +} | ||
675 | + | ||
676 | +static void vhost_user_blk_server_instance_finalize(Object *obj) | ||
677 | +{ | ||
678 | + VuBlockDev *vub = VHOST_USER_BLK_SERVER(obj); | ||
679 | + | ||
680 | + vhost_user_blk_server_stop(vub); | ||
681 | + | ||
682 | + /* | ||
683 | + * Unlike object_property_add_str, object_class_property_add_str | ||
684 | + * doesn't have a release method. Thus manual memory freeing is | ||
685 | + * needed. | ||
686 | + */ | ||
687 | + free_socket_addr(vub->addr); | ||
688 | + g_free(vub->node_name); | ||
689 | +} | ||
690 | + | ||
691 | +static void vhost_user_blk_server_complete(UserCreatable *obj, Error **errp) | ||
692 | +{ | ||
693 | + VuBlockDev *vub = VHOST_USER_BLK_SERVER(obj); | ||
694 | + | ||
695 | + vhost_user_blk_server_start(vub, errp); | ||
696 | +} | ||
697 | + | ||
698 | +static void vhost_user_blk_server_class_init(ObjectClass *klass, | ||
699 | + void *class_data) | ||
700 | +{ | ||
701 | + UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); | ||
702 | + ucc->complete = vhost_user_blk_server_complete; | ||
703 | + | ||
704 | + object_class_property_add_bool(klass, "writable", | ||
705 | + vu_get_block_writable, | ||
706 | + vu_set_block_writable); | ||
707 | + | ||
708 | + object_class_property_add_str(klass, "node-name", | ||
709 | + vu_get_node_name, | ||
710 | + vu_set_node_name); | ||
711 | + | ||
712 | + object_class_property_add_str(klass, "unix-socket", | ||
713 | + vu_get_unix_socket, | ||
714 | + vu_set_unix_socket); | ||
715 | + | ||
716 | + object_class_property_add(klass, "logical-block-size", "uint32", | ||
717 | + vu_get_blk_size, vu_set_blk_size, | ||
718 | + NULL, NULL); | ||
719 | +} | ||
720 | + | ||
721 | +static const TypeInfo vhost_user_blk_server_info = { | ||
722 | + .name = TYPE_VHOST_USER_BLK_SERVER, | ||
723 | + .parent = TYPE_OBJECT, | ||
724 | + .instance_size = sizeof(VuBlockDev), | ||
725 | + .instance_finalize = vhost_user_blk_server_instance_finalize, | ||
726 | + .class_init = vhost_user_blk_server_class_init, | ||
727 | + .interfaces = (InterfaceInfo[]) { | ||
728 | + {TYPE_USER_CREATABLE}, | ||
729 | + {} | ||
730 | + }, | ||
731 | +}; | ||
732 | + | ||
733 | +static void vhost_user_blk_server_register_types(void) | ||
734 | +{ | ||
735 | + type_register_static(&vhost_user_blk_server_info); | ||
736 | +} | ||
737 | + | ||
738 | +type_init(vhost_user_blk_server_register_types) | ||
739 | diff --git a/softmmu/vl.c b/softmmu/vl.c | ||
740 | index XXXXXXX..XXXXXXX 100644 | ||
741 | --- a/softmmu/vl.c | ||
742 | +++ b/softmmu/vl.c | ||
743 | @@ -XXX,XX +XXX,XX @@ static bool object_create_initial(const char *type, QemuOpts *opts) | ||
744 | } | ||
745 | #endif | ||
746 | |||
747 | + /* Reason: vhost-user-blk-server property "node-name" */ | ||
748 | + if (g_str_equal(type, "vhost-user-blk-server")) { | ||
749 | + return false; | ||
750 | + } | ||
751 | /* | ||
752 | * Reason: filter-* property "netdev" etc. | ||
753 | */ | ||
754 | diff --git a/block/meson.build b/block/meson.build | ||
755 | index XXXXXXX..XXXXXXX 100644 | ||
756 | --- a/block/meson.build | ||
757 | +++ b/block/meson.build | ||
758 | @@ -XXX,XX +XXX,XX @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-win32.c', 'win32-aio.c') | ||
759 | block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref, iokit]) | ||
760 | block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) | ||
761 | block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) | ||
762 | +block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-server.c', '../contrib/libvhost-user/libvhost-user.c')) | ||
763 | block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) | ||
764 | block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) | ||
765 | block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio.c')) | ||
766 | -- | ||
767 | 2.26.2 | ||
768 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Coiby Xu <coiby.xu@gmail.com> | ||
1 | 2 | ||
3 | Suggested-by: Stefano Garzarella <sgarzare@redhat.com> | ||
4 | Signed-off-by: Coiby Xu <coiby.xu@gmail.com> | ||
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
7 | Message-id: 20200918080912.321299-8-coiby.xu@gmail.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | MAINTAINERS | 8 ++++++++ | ||
11 | 1 file changed, 8 insertions(+) | ||
12 | |||
13 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/MAINTAINERS | ||
16 | +++ b/MAINTAINERS | ||
17 | @@ -XXX,XX +XXX,XX @@ L: qemu-block@nongnu.org | ||
18 | S: Supported | ||
19 | F: tests/image-fuzzer/ | ||
20 | |||
21 | +Vhost-user block device backend server | ||
22 | +M: Coiby Xu <Coiby.Xu@gmail.com> | ||
23 | +S: Maintained | ||
24 | +F: block/export/vhost-user-blk-server.c | ||
25 | +F: util/vhost-user-server.c | ||
26 | +F: tests/qtest/vhost-user-blk-test.c | ||
27 | +F: tests/qtest/libqos/vhost-user-blk.c | ||
28 | + | ||
29 | Replication | ||
30 | M: Wen Congyang <wencongyang2@huawei.com> | ||
31 | M: Xie Changlong <xiechanglong.d@gmail.com> | ||
32 | -- | ||
33 | 2.26.2 | ||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
2 | Message-id: 20200924151549.913737-3-stefanha@redhat.com | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | --- | ||
5 | util/vhost-user-server.c | 2 +- | ||
6 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
1 | 7 | ||
8 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/util/vhost-user-server.c | ||
11 | +++ b/util/vhost-user-server.c | ||
12 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
13 | return false; | ||
14 | } | ||
15 | |||
16 | - /* zero out unspecified fileds */ | ||
17 | + /* zero out unspecified fields */ | ||
18 | *server = (VuServer) { | ||
19 | .listener = listener, | ||
20 | .vu_iface = vu_iface, | ||
21 | -- | ||
22 | 2.26.2 | ||
23 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We already have access to the value with the correct type (ioc and sioc | ||
2 | are the same QIOChannel). | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Message-id: 20200924151549.913737-4-stefanha@redhat.com | ||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | --- | ||
8 | util/vhost-user-server.c | 2 +- | ||
9 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
10 | |||
11 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/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, | ||
16 | server->ioc = QIO_CHANNEL(sioc); | ||
17 | object_ref(OBJECT(server->ioc)); | ||
18 | qio_channel_attach_aio_context(server->ioc, server->ctx); | ||
19 | - qio_channel_set_blocking(QIO_CHANNEL(server->sioc), false, NULL); | ||
20 | + qio_channel_set_blocking(server->ioc, false, NULL); | ||
21 | vu_client_start(server); | ||
22 | } | ||
23 | |||
24 | -- | ||
25 | 2.26.2 | ||
26 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Explicitly deleting watches is not necessary since libvhost-user calls | ||
2 | remove_watch() during vu_deinit(). Add an assertion to check this | ||
3 | though. | ||
1 | 4 | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Message-id: 20200924151549.913737-5-stefanha@redhat.com | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | ||
9 | util/vhost-user-server.c | 19 ++++--------------- | ||
10 | 1 file changed, 4 insertions(+), 15 deletions(-) | ||
11 | |||
12 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/util/vhost-user-server.c | ||
15 | +++ b/util/vhost-user-server.c | ||
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 */ | ||
18 | server->sioc = NULL; | ||
19 | |||
20 | - VuFdWatch *vu_fd_watch, *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, | ||
23 | - NULL, NULL, NULL); | ||
24 | - } | ||
25 | - | ||
26 | - while (!QTAILQ_EMPTY(&server->vu_fd_watches)) { | ||
27 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | ||
28 | - if (!vu_fd_watch->processing) { | ||
29 | - QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); | ||
30 | - g_free(vu_fd_watch); | ||
31 | - } | ||
32 | - } | ||
33 | - } | ||
34 | - | ||
35 | while (server->processing_msg) { | ||
36 | if (server->ioc->read_coroutine) { | ||
37 | server->ioc->read_coroutine = NULL; | ||
38 | @@ -XXX,XX +XXX,XX @@ static void close_client(VuServer *server) | ||
39 | } | ||
40 | |||
41 | vu_deinit(&server->vu_dev); | ||
42 | + | ||
43 | + /* vu_deinit() should have called remove_watch() */ | ||
44 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | ||
45 | + | ||
46 | object_unref(OBJECT(sioc)); | ||
47 | object_unref(OBJECT(server->ioc)); | ||
48 | } | ||
49 | -- | ||
50 | 2.26.2 | ||
51 | diff view generated by jsdifflib |
1 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 1 | Only one struct is needed per request. Drop req_data and the separate |
---|---|---|---|
2 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 2 | VuBlockReq instance. Instead let vu_queue_pop() allocate everything at |
3 | Reviewed-by: John Snow <jsnow@redhat.com> | 3 | once. |
4 | Message-id: 00aed7ffdd7be4b9ed9ce1007d50028a72b34ebe.1491597120.git.jcody@redhat.com | 4 | |
5 | This fixes the req_data memory leak in vu_block_virtio_process_req(). | ||
6 | |||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Message-id: 20200924151549.913737-6-stefanha@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | --- | 10 | --- |
6 | block.c | 14 ++++++++------ | 11 | block/export/vhost-user-blk-server.c | 68 +++++++++------------------- |
7 | 1 file changed, 8 insertions(+), 6 deletions(-) | 12 | 1 file changed, 21 insertions(+), 47 deletions(-) |
8 | 13 | ||
9 | diff --git a/block.c b/block.c | 14 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
10 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/block.c | 16 | --- a/block/export/vhost-user-blk-server.c |
12 | +++ b/block.c | 17 | +++ b/block/export/vhost-user-blk-server.c |
13 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, | 18 | @@ -XXX,XX +XXX,XX @@ struct virtio_blk_inhdr { |
14 | BlockDriver *drv; | 19 | }; |
15 | QemuOpts *opts; | 20 | |
16 | const char *value; | 21 | typedef struct VuBlockReq { |
17 | + bool read_only; | 22 | - VuVirtqElement *elem; |
18 | 23 | + VuVirtqElement elem; | |
19 | assert(reopen_state != NULL); | 24 | int64_t sector_num; |
20 | assert(reopen_state->bs->drv != NULL); | 25 | size_t size; |
21 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, | 26 | struct virtio_blk_inhdr *in; |
22 | qdict_put(reopen_state->options, "driver", qstring_from_str(value)); | 27 | @@ -XXX,XX +XXX,XX @@ static void vu_block_req_complete(VuBlockReq *req) |
28 | VuDev *vu_dev = &req->server->vu_dev; | ||
29 | |||
30 | /* IO size with 1 extra status byte */ | ||
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); | ||
33 | vu_queue_notify(vu_dev, req->vq); | ||
34 | |||
35 | - if (req->elem) { | ||
36 | - free(req->elem); | ||
37 | - } | ||
38 | - | ||
39 | - g_free(req); | ||
40 | + free(req); | ||
41 | } | ||
42 | |||
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) | ||
45 | blk_co_flush(backend); | ||
46 | } | ||
47 | |||
48 | -struct req_data { | ||
49 | - VuServer *server; | ||
50 | - VuVirtq *vq; | ||
51 | - VuVirtqElement *elem; | ||
52 | -}; | ||
53 | - | ||
54 | static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
55 | { | ||
56 | - struct req_data *data = opaque; | ||
57 | - VuServer *server = data->server; | ||
58 | - VuVirtq *vq = data->vq; | ||
59 | - VuVirtqElement *elem = data->elem; | ||
60 | + VuBlockReq *req = opaque; | ||
61 | + VuServer *server = req->server; | ||
62 | + VuVirtqElement *elem = &req->elem; | ||
63 | uint32_t type; | ||
64 | - VuBlockReq *req; | ||
65 | |||
66 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
67 | BlockBackend *backend = vdev_blk->backend; | ||
68 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
69 | struct iovec *out_iov = elem->out_sg; | ||
70 | unsigned in_num = elem->in_num; | ||
71 | unsigned out_num = elem->out_num; | ||
72 | + | ||
73 | /* refer to hw/block/virtio_blk.c */ | ||
74 | if (elem->out_num < 1 || elem->in_num < 1) { | ||
75 | error_report("virtio-blk request missing headers"); | ||
76 | - free(elem); | ||
77 | - return; | ||
78 | + goto err; | ||
23 | } | 79 | } |
24 | 80 | ||
25 | - /* if we are to stay read-only, do not allow permission change | 81 | - req = g_new0(VuBlockReq, 1); |
26 | - * to r/w */ | 82 | - req->server = server; |
27 | - if (!(reopen_state->bs->open_flags & BDRV_O_ALLOW_RDWR) && | 83 | - req->vq = vq; |
28 | - reopen_state->flags & BDRV_O_RDWR) { | 84 | - req->elem = elem; |
29 | - error_setg(errp, "Node '%s' is read only", | 85 | - |
30 | - bdrv_get_device_or_node_name(reopen_state->bs)); | 86 | if (unlikely(iov_to_buf(out_iov, out_num, 0, &req->out, |
31 | + /* If we are to stay read-only, do not allow permission change | 87 | sizeof(req->out)) != sizeof(req->out))) { |
32 | + * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is | 88 | error_report("virtio-blk request outhdr too short"); |
33 | + * not set, or if the BDS still has copy_on_read enabled */ | 89 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) |
34 | + read_only = !(reopen_state->flags & BDRV_O_RDWR); | 90 | |
35 | + ret = bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err); | 91 | err: |
36 | + if (local_err) { | 92 | free(elem); |
37 | + error_propagate(errp, local_err); | 93 | - g_free(req); |
38 | goto error; | 94 | - return; |
95 | } | ||
96 | |||
97 | static void vu_block_process_vq(VuDev *vu_dev, int idx) | ||
98 | { | ||
99 | - VuServer *server; | ||
100 | - VuVirtq *vq; | ||
101 | - struct req_data *req_data; | ||
102 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
103 | + VuVirtq *vq = vu_get_queue(vu_dev, idx); | ||
104 | |||
105 | - server = container_of(vu_dev, VuServer, vu_dev); | ||
106 | - assert(server); | ||
107 | - | ||
108 | - vq = vu_get_queue(vu_dev, idx); | ||
109 | - assert(vq); | ||
110 | - VuVirtqElement *elem; | ||
111 | while (1) { | ||
112 | - elem = vu_queue_pop(vu_dev, vq, sizeof(VuVirtqElement) + | ||
113 | - sizeof(VuBlockReq)); | ||
114 | - if (elem) { | ||
115 | - req_data = g_new0(struct req_data, 1); | ||
116 | - req_data->server = server; | ||
117 | - req_data->vq = vq; | ||
118 | - req_data->elem = elem; | ||
119 | - Coroutine *co = qemu_coroutine_create(vu_block_virtio_process_req, | ||
120 | - req_data); | ||
121 | - aio_co_enter(server->ioc->ctx, co); | ||
122 | - } else { | ||
123 | + VuBlockReq *req; | ||
124 | + | ||
125 | + req = vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); | ||
126 | + if (!req) { | ||
127 | break; | ||
128 | } | ||
129 | + | ||
130 | + req->server = server; | ||
131 | + req->vq = vq; | ||
132 | + | ||
133 | + Coroutine *co = | ||
134 | + qemu_coroutine_create(vu_block_virtio_process_req, req); | ||
135 | + qemu_coroutine_enter(co); | ||
39 | } | 136 | } |
137 | } | ||
40 | 138 | ||
41 | -- | 139 | -- |
42 | 2.9.3 | 140 | 2.26.2 |
43 | 141 | ||
44 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The device panic notifier callback is not used. Drop it. | ||
1 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Message-id: 20200924151549.913737-7-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | util/vhost-user-server.h | 3 --- | ||
8 | block/export/vhost-user-blk-server.c | 3 +-- | ||
9 | util/vhost-user-server.c | 6 ------ | ||
10 | 3 files changed, 1 insertion(+), 11 deletions(-) | ||
11 | |||
12 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/util/vhost-user-server.h | ||
15 | +++ b/util/vhost-user-server.h | ||
16 | @@ -XXX,XX +XXX,XX @@ typedef struct VuFdWatch { | ||
17 | } VuFdWatch; | ||
18 | |||
19 | typedef struct VuServer VuServer; | ||
20 | -typedef void DevicePanicNotifierFn(VuServer *server); | ||
21 | |||
22 | struct VuServer { | ||
23 | QIONetListener *listener; | ||
24 | AioContext *ctx; | ||
25 | - DevicePanicNotifierFn *device_panic_notifier; | ||
26 | int max_queues; | ||
27 | const VuDevIface *vu_iface; | ||
28 | VuDev vu_dev; | ||
29 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
30 | SocketAddress *unix_socket, | ||
31 | AioContext *ctx, | ||
32 | uint16_t max_queues, | ||
33 | - DevicePanicNotifierFn *device_panic_notifier, | ||
34 | const VuDevIface *vu_iface, | ||
35 | Error **errp); | ||
36 | |||
37 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/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, | ||
42 | ctx = bdrv_get_aio_context(blk_bs(vu_block_device->backend)); | ||
43 | |||
44 | if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, | ||
45 | - VHOST_USER_BLK_MAX_QUEUES, | ||
46 | - NULL, &vu_block_iface, | ||
47 | + VHOST_USER_BLK_MAX_QUEUES, &vu_block_iface, | ||
48 | errp)) { | ||
49 | goto error; | ||
50 | } | ||
51 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/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) | ||
56 | close_client(server); | ||
57 | } | ||
58 | |||
59 | - if (server->device_panic_notifier) { | ||
60 | - server->device_panic_notifier(server); | ||
61 | - } | ||
62 | - | ||
63 | /* | ||
64 | * Set the callback function for network listener so another | ||
65 | * vhost-user client can connect to this server | ||
66 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
67 | SocketAddress *socket_addr, | ||
68 | AioContext *ctx, | ||
69 | uint16_t max_queues, | ||
70 | - DevicePanicNotifierFn *device_panic_notifier, | ||
71 | const VuDevIface *vu_iface, | ||
72 | Error **errp) | ||
73 | { | ||
74 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
75 | .vu_iface = vu_iface, | ||
76 | .max_queues = max_queues, | ||
77 | .ctx = ctx, | ||
78 | - .device_panic_notifier = device_panic_notifier, | ||
79 | }; | ||
80 | |||
81 | qio_net_listener_set_name(server->listener, "vhost-user-backend-listener"); | ||
82 | -- | ||
83 | 2.26.2 | ||
84 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | fds[] is leaked when qio_channel_readv_full() fails. | ||
1 | 2 | ||
3 | Use vmsg->fds[] instead of keeping a local fds[] array. Then we can | ||
4 | reuse goto fail to clean up fds. vmsg->fd_num must be zeroed before the | ||
5 | loop to make this safe. | ||
6 | |||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Message-id: 20200924151549.913737-8-stefanha@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | ||
11 | util/vhost-user-server.c | 50 ++++++++++++++++++---------------------- | ||
12 | 1 file changed, 23 insertions(+), 27 deletions(-) | ||
13 | |||
14 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/util/vhost-user-server.c | ||
17 | +++ b/util/vhost-user-server.c | ||
18 | @@ -XXX,XX +XXX,XX @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) | ||
19 | }; | ||
20 | int rc, read_bytes = 0; | ||
21 | Error *local_err = NULL; | ||
22 | - /* | ||
23 | - * Store fds/nfds returned from qio_channel_readv_full into | ||
24 | - * temporary variables. | ||
25 | - * | ||
26 | - * VhostUserMsg is a packed structure, gcc will complain about passing | ||
27 | - * pointer to a packed structure member if we pass &VhostUserMsg.fd_num | ||
28 | - * and &VhostUserMsg.fds directly when calling qio_channel_readv_full, | ||
29 | - * thus two temporary variables nfds and fds are used here. | ||
30 | - */ | ||
31 | - size_t nfds = 0, nfds_t = 0; | ||
32 | const size_t max_fds = G_N_ELEMENTS(vmsg->fds); | ||
33 | - int *fds_t = NULL; | ||
34 | VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
35 | QIOChannel *ioc = server->ioc; | ||
36 | |||
37 | + vmsg->fd_num = 0; | ||
38 | if (!ioc) { | ||
39 | error_report_err(local_err); | ||
40 | goto fail; | ||
41 | @@ -XXX,XX +XXX,XX @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg) | ||
42 | |||
43 | assert(qemu_in_coroutine()); | ||
44 | do { | ||
45 | + size_t nfds = 0; | ||
46 | + int *fds = NULL; | ||
47 | + | ||
48 | /* | ||
49 | * qio_channel_readv_full may have short reads, keeping calling it | ||
50 | * until getting VHOST_USER_HDR_SIZE or 0 bytes in total | ||
51 | */ | ||
52 | - rc = qio_channel_readv_full(ioc, &iov, 1, &fds_t, &nfds_t, &local_err); | ||
53 | + rc = qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, &local_err); | ||
54 | if (rc < 0) { | ||
55 | if (rc == QIO_CHANNEL_ERR_BLOCK) { | ||
56 | + assert(local_err == NULL); | ||
57 | qio_channel_yield(ioc, G_IO_IN); | ||
58 | continue; | ||
59 | } else { | ||
60 | error_report_err(local_err); | ||
61 | - return false; | ||
62 | + goto fail; | ||
63 | } | ||
64 | } | ||
65 | - read_bytes += rc; | ||
66 | - if (nfds_t > 0) { | ||
67 | - if (nfds + nfds_t > max_fds) { | ||
68 | + | ||
69 | + if (nfds > 0) { | ||
70 | + if (vmsg->fd_num + nfds > max_fds) { | ||
71 | error_report("A maximum of %zu fds are allowed, " | ||
72 | "however got %lu fds now", | ||
73 | - max_fds, nfds + nfds_t); | ||
74 | + max_fds, vmsg->fd_num + nfds); | ||
75 | + g_free(fds); | ||
76 | goto fail; | ||
77 | } | ||
78 | - memcpy(vmsg->fds + nfds, fds_t, | ||
79 | - nfds_t *sizeof(vmsg->fds[0])); | ||
80 | - nfds += nfds_t; | ||
81 | - g_free(fds_t); | ||
82 | + memcpy(vmsg->fds + vmsg->fd_num, fds, nfds * sizeof(vmsg->fds[0])); | ||
83 | + vmsg->fd_num += nfds; | ||
84 | + g_free(fds); | ||
85 | } | ||
86 | - if (read_bytes == VHOST_USER_HDR_SIZE || rc == 0) { | ||
87 | - break; | ||
88 | + | ||
89 | + if (rc == 0) { /* socket closed */ | ||
90 | + goto fail; | ||
91 | } | ||
92 | - iov.iov_base = (char *)vmsg + read_bytes; | ||
93 | - iov.iov_len = VHOST_USER_HDR_SIZE - read_bytes; | ||
94 | - } while (true); | ||
95 | |||
96 | - vmsg->fd_num = nfds; | ||
97 | + iov.iov_base += rc; | ||
98 | + iov.iov_len -= rc; | ||
99 | + read_bytes += rc; | ||
100 | + } while (read_bytes != VHOST_USER_HDR_SIZE); | ||
101 | + | ||
102 | /* qio_channel_readv_full will make socket fds blocking, unblock them */ | ||
103 | vmsg_unblock_fds(vmsg); | ||
104 | if (vmsg->size > sizeof(vmsg->payload)) { | ||
105 | -- | ||
106 | 2.26.2 | ||
107 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Unexpected EOF is an error that must be reported. | ||
1 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Message-id: 20200924151549.913737-9-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | util/vhost-user-server.c | 6 ++++-- | ||
8 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
9 | |||
10 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/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) | ||
15 | }; | ||
16 | if (vmsg->size) { | ||
17 | rc = qio_channel_readv_all_eof(ioc, &iov_payload, 1, &local_err); | ||
18 | - if (rc == -1) { | ||
19 | - error_report_err(local_err); | ||
20 | + if (rc != 1) { | ||
21 | + if (local_err) { | ||
22 | + error_report_err(local_err); | ||
23 | + } | ||
24 | goto fail; | ||
25 | } | ||
26 | } | ||
27 | -- | ||
28 | 2.26.2 | ||
29 | diff view generated by jsdifflib |
1 | This adds support for reopen in rbd, for changing between r/w and r/o. | 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 | ||
3 | still access it in some cases. | ||
2 | 4 | ||
3 | Note, that this is only a flag change, but we will block a change from | 5 | Rework the lifecycle to solve these safety issues. |
4 | r/o to r/w if we are using an RBD internal snapshot. | ||
5 | 6 | ||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 8 | Message-id: 20200924151549.913737-10-stefanha@redhat.com |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | Message-id: d4e87539167ec6527d44c97b164eabcccf96e4f3.1491597120.git.jcody@redhat.com | ||
10 | --- | 10 | --- |
11 | block/rbd.c | 21 +++++++++++++++++++++ | 11 | util/vhost-user-server.h | 29 ++-- |
12 | 1 file changed, 21 insertions(+) | 12 | block/export/vhost-user-blk-server.c | 9 +- |
13 | util/vhost-user-server.c | 245 +++++++++++++++------------ | ||
14 | 3 files changed, 155 insertions(+), 128 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/block/rbd.c b/block/rbd.c | 16 | diff --git a/util/vhost-user-server.h b/util/vhost-user-server.h |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/rbd.c | 18 | --- a/util/vhost-user-server.h |
17 | +++ b/block/rbd.c | 19 | +++ b/util/vhost-user-server.h |
18 | @@ -XXX,XX +XXX,XX @@ failed_opts: | 20 | @@ -XXX,XX +XXX,XX @@ |
19 | return r; | 21 | #include "qapi/error.h" |
20 | } | 22 | #include "standard-headers/linux/virtio_blk.h" |
21 | 23 | ||
22 | + | 24 | +/* A kick fd that we monitor on behalf of libvhost-user */ |
23 | +/* Since RBD is currently always opened R/W via the API, | 25 | typedef struct VuFdWatch { |
24 | + * we just need to check if we are using a snapshot or not, in | 26 | VuDev *vu_dev; |
25 | + * order to determine if we will allow it to be R/W */ | 27 | int fd; /*kick fd*/ |
26 | +static int qemu_rbd_reopen_prepare(BDRVReopenState *state, | 28 | void *pvt; |
27 | + BlockReopenQueue *queue, Error **errp) | 29 | vu_watch_cb cb; |
30 | - bool processing; | ||
31 | QTAILQ_ENTRY(VuFdWatch) next; | ||
32 | } VuFdWatch; | ||
33 | |||
34 | -typedef struct VuServer VuServer; | ||
35 | - | ||
36 | -struct VuServer { | ||
37 | +/** | ||
38 | + * VuServer: | ||
39 | + * A vhost-user server instance with user-defined VuDevIface callbacks. | ||
40 | + * Vhost-user device backends can be implemented using VuServer. VuDevIface | ||
41 | + * callbacks and virtqueue kicks run in the given AioContext. | ||
42 | + */ | ||
43 | +typedef struct { | ||
44 | QIONetListener *listener; | ||
45 | + QEMUBH *restart_listener_bh; | ||
46 | AioContext *ctx; | ||
47 | int max_queues; | ||
48 | const VuDevIface *vu_iface; | ||
49 | + | ||
50 | + /* Protected by ctx lock */ | ||
51 | VuDev vu_dev; | ||
52 | QIOChannel *ioc; /* The I/O 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 */ | ||
55 | - QIOChannel *ioc_slave; | ||
56 | - QIOChannelSocket *sioc_slave; | ||
57 | - Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | ||
58 | QTAILQ_HEAD(, VuFdWatch) vu_fd_watches; | ||
59 | - /* restart coroutine co_trip if AIOContext is changed */ | ||
60 | - bool aio_context_changed; | ||
61 | - bool processing_msg; | ||
62 | -}; | ||
63 | + | ||
64 | + Coroutine *co_trip; /* coroutine for processing VhostUserMsg */ | ||
65 | +} VuServer; | ||
66 | |||
67 | bool vhost_user_server_start(VuServer *server, | ||
68 | SocketAddress *unix_socket, | ||
69 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
70 | |||
71 | void vhost_user_server_stop(VuServer *server); | ||
72 | |||
73 | -void vhost_user_server_set_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); | ||
76 | |||
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 | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/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 = { | ||
83 | static void blk_aio_attached(AioContext *ctx, void *opaque) | ||
84 | { | ||
85 | VuBlockDev *vub_dev = opaque; | ||
86 | - aio_context_acquire(ctx); | ||
87 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, ctx); | ||
88 | - aio_context_release(ctx); | ||
89 | + vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); | ||
90 | } | ||
91 | |||
92 | static void blk_aio_detach(void *opaque) | ||
93 | { | ||
94 | VuBlockDev *vub_dev = opaque; | ||
95 | - AioContext *ctx = vub_dev->vu_server.ctx; | ||
96 | - aio_context_acquire(ctx); | ||
97 | - vhost_user_server_set_aio_context(&vub_dev->vu_server, NULL); | ||
98 | - aio_context_release(ctx); | ||
99 | + vhost_user_server_detach_aio_context(&vub_dev->vu_server); | ||
100 | } | ||
101 | |||
102 | static void | ||
103 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/util/vhost-user-server.c | ||
106 | +++ b/util/vhost-user-server.c | ||
107 | @@ -XXX,XX +XXX,XX @@ | ||
108 | */ | ||
109 | #include "qemu/osdep.h" | ||
110 | #include "qemu/main-loop.h" | ||
111 | +#include "block/aio-wait.h" | ||
112 | #include "vhost-user-server.h" | ||
113 | |||
114 | +/* | ||
115 | + * Theory of operation: | ||
116 | + * | ||
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 | ||
119 | + * opens a vhost-user UNIX domain socket and listens for incoming connections. | ||
120 | + * Only one connection is allowed at a time. | ||
121 | + * | ||
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 | ||
124 | + * where libvhost-user calls vu_message_read() to receive the next vhost-user | ||
125 | + * protocol messages over the UNIX domain socket. | ||
126 | + * | ||
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. | ||
129 | + * | ||
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 | ||
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 | ||
134 | + * libvhost-user before terminating the coroutine. vu_deinit() calls | ||
135 | + * remove_watch() to stop monitoring kick fds and this stops virtqueue | ||
136 | + * processing. | ||
137 | + * | ||
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. | ||
140 | + * | ||
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 | ||
143 | + * the dev->broken flag is set. | ||
144 | + * | ||
145 | + * It is possible to switch AioContexts using | ||
146 | + * vhost_user_server_detach_aio_context() and | ||
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() | ||
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 | ||
151 | + * qio_channel_yield(). The coroutine will restart I/O when re-entered from the | ||
152 | + * new AioContext. | ||
153 | + */ | ||
154 | + | ||
155 | static void vmsg_close_fds(VhostUserMsg *vmsg) | ||
156 | { | ||
157 | int i; | ||
158 | @@ -XXX,XX +XXX,XX @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg) | ||
159 | } | ||
160 | } | ||
161 | |||
162 | -static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, | ||
163 | - gpointer opaque); | ||
164 | - | ||
165 | -static void close_client(VuServer *server) | ||
166 | -{ | ||
167 | - /* | ||
168 | - * Before closing the client | ||
169 | - * | ||
170 | - * 1. Let vu_client_trip stop processing new vhost-user msg | ||
171 | - * | ||
172 | - * 2. remove kick_handler | ||
173 | - * | ||
174 | - * 3. wait for the kick handler to be finished | ||
175 | - * | ||
176 | - * 4. wait for the current vhost-user msg to be finished processing | ||
177 | - */ | ||
178 | - | ||
179 | - QIOChannelSocket *sioc = server->sioc; | ||
180 | - /* When this is set vu_client_trip will stop new processing vhost-user message */ | ||
181 | - server->sioc = NULL; | ||
182 | - | ||
183 | - while (server->processing_msg) { | ||
184 | - if (server->ioc->read_coroutine) { | ||
185 | - server->ioc->read_coroutine = NULL; | ||
186 | - qio_channel_set_aio_fd_handler(server->ioc, server->ioc->ctx, NULL, | ||
187 | - NULL, server->ioc); | ||
188 | - server->processing_msg = false; | ||
189 | - } | ||
190 | - } | ||
191 | - | ||
192 | - vu_deinit(&server->vu_dev); | ||
193 | - | ||
194 | - /* vu_deinit() should have called remove_watch() */ | ||
195 | - assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | ||
196 | - | ||
197 | - object_unref(OBJECT(sioc)); | ||
198 | - object_unref(OBJECT(server->ioc)); | ||
199 | -} | ||
200 | - | ||
201 | static void panic_cb(VuDev *vu_dev, const char *buf) | ||
202 | { | ||
203 | - VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
204 | - | ||
205 | - /* avoid while loop in close_client */ | ||
206 | - server->processing_msg = false; | ||
207 | - | ||
208 | - if (buf) { | ||
209 | - error_report("vu_panic: %s", buf); | ||
210 | - } | ||
211 | - | ||
212 | - if (server->sioc) { | ||
213 | - close_client(server); | ||
214 | - } | ||
215 | - | ||
216 | - /* | ||
217 | - * Set the callback function for network listener so another | ||
218 | - * vhost-user client can connect to this server | ||
219 | - */ | ||
220 | - qio_net_listener_set_client_func(server->listener, | ||
221 | - vu_accept, | ||
222 | - server, | ||
223 | - NULL); | ||
224 | + error_report("vu_panic: %s", buf); | ||
225 | } | ||
226 | |||
227 | static bool coroutine_fn | ||
228 | @@ -XXX,XX +XXX,XX @@ fail: | ||
229 | return false; | ||
230 | } | ||
231 | |||
232 | - | ||
233 | -static void vu_client_start(VuServer *server); | ||
234 | static coroutine_fn void vu_client_trip(void *opaque) | ||
235 | { | ||
236 | VuServer *server = opaque; | ||
237 | + VuDev *vu_dev = &server->vu_dev; | ||
238 | |||
239 | - while (!server->aio_context_changed && server->sioc) { | ||
240 | - server->processing_msg = true; | ||
241 | - vu_dispatch(&server->vu_dev); | ||
242 | - server->processing_msg = false; | ||
243 | + while (!vu_dev->broken && vu_dispatch(vu_dev)) { | ||
244 | + /* Keep running */ | ||
245 | } | ||
246 | |||
247 | - if (server->aio_context_changed && server->sioc) { | ||
248 | - server->aio_context_changed = false; | ||
249 | - vu_client_start(server); | ||
250 | - } | ||
251 | -} | ||
252 | + vu_deinit(vu_dev); | ||
253 | + | ||
254 | + /* vu_deinit() should have called remove_watch() */ | ||
255 | + assert(QTAILQ_EMPTY(&server->vu_fd_watches)); | ||
256 | + | ||
257 | + object_unref(OBJECT(server->sioc)); | ||
258 | + server->sioc = NULL; | ||
259 | |||
260 | -static void vu_client_start(VuServer *server) | ||
261 | -{ | ||
262 | - server->co_trip = qemu_coroutine_create(vu_client_trip, server); | ||
263 | - aio_co_enter(server->ctx, server->co_trip); | ||
264 | + object_unref(OBJECT(server->ioc)); | ||
265 | + server->ioc = NULL; | ||
266 | + | ||
267 | + server->co_trip = NULL; | ||
268 | + if (server->restart_listener_bh) { | ||
269 | + qemu_bh_schedule(server->restart_listener_bh); | ||
270 | + } | ||
271 | + aio_wait_kick(); | ||
272 | } | ||
273 | |||
274 | /* | ||
275 | @@ -XXX,XX +XXX,XX @@ static void vu_client_start(VuServer *server) | ||
276 | static void kick_handler(void *opaque) | ||
277 | { | ||
278 | VuFdWatch *vu_fd_watch = opaque; | ||
279 | - vu_fd_watch->processing = true; | ||
280 | - vu_fd_watch->cb(vu_fd_watch->vu_dev, 0, vu_fd_watch->pvt); | ||
281 | - vu_fd_watch->processing = false; | ||
282 | + VuDev *vu_dev = vu_fd_watch->vu_dev; | ||
283 | + | ||
284 | + vu_fd_watch->cb(vu_dev, 0, vu_fd_watch->pvt); | ||
285 | + | ||
286 | + /* Stop vu_client_trip() if an error occurred in vu_fd_watch->cb() */ | ||
287 | + if (vu_dev->broken) { | ||
288 | + VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
289 | + | ||
290 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); | ||
291 | + } | ||
292 | } | ||
293 | |||
294 | - | ||
295 | static VuFdWatch *find_vu_fd_watch(VuServer *server, int fd) | ||
296 | { | ||
297 | |||
298 | @@ -XXX,XX +XXX,XX @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc, | ||
299 | qio_channel_set_name(QIO_CHANNEL(sioc), "vhost-user client"); | ||
300 | server->ioc = QIO_CHANNEL(sioc); | ||
301 | object_ref(OBJECT(server->ioc)); | ||
302 | - qio_channel_attach_aio_context(server->ioc, server->ctx); | ||
303 | + | ||
304 | + /* TODO vu_message_write() spins if non-blocking! */ | ||
305 | qio_channel_set_blocking(server->ioc, false, NULL); | ||
306 | - vu_client_start(server); | ||
307 | + | ||
308 | + server->co_trip = qemu_coroutine_create(vu_client_trip, server); | ||
309 | + | ||
310 | + aio_context_acquire(server->ctx); | ||
311 | + vhost_user_server_attach_aio_context(server, server->ctx); | ||
312 | + aio_context_release(server->ctx); | ||
313 | } | ||
314 | |||
315 | - | ||
316 | void vhost_user_server_stop(VuServer *server) | ||
317 | { | ||
318 | + aio_context_acquire(server->ctx); | ||
319 | + | ||
320 | + qemu_bh_delete(server->restart_listener_bh); | ||
321 | + server->restart_listener_bh = NULL; | ||
322 | + | ||
323 | if (server->sioc) { | ||
324 | - close_client(server); | ||
325 | + VuFdWatch *vu_fd_watch; | ||
326 | + | ||
327 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { | ||
328 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, | ||
329 | + NULL, NULL, NULL, vu_fd_watch); | ||
330 | + } | ||
331 | + | ||
332 | + qio_channel_shutdown(server->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); | ||
333 | + | ||
334 | + AIO_WAIT_WHILE(server->ctx, server->co_trip); | ||
335 | } | ||
336 | |||
337 | + aio_context_release(server->ctx); | ||
338 | + | ||
339 | if (server->listener) { | ||
340 | qio_net_listener_disconnect(server->listener); | ||
341 | object_unref(OBJECT(server->listener)); | ||
342 | } | ||
343 | +} | ||
344 | + | ||
345 | +/* | ||
346 | + * Allow the next client to connect to the server. Called from a BH in the main | ||
347 | + * loop. | ||
348 | + */ | ||
349 | +static void restart_listener_bh(void *opaque) | ||
28 | +{ | 350 | +{ |
29 | + BDRVRBDState *s = state->bs->opaque; | 351 | + VuServer *server = opaque; |
30 | + int ret = 0; | 352 | |
31 | + | 353 | + qio_net_listener_set_client_func(server->listener, vu_accept, server, |
32 | + if (s->snap && state->flags & BDRV_O_RDWR) { | 354 | + NULL); |
33 | + error_setg(errp, | 355 | } |
34 | + "Cannot change node '%s' to r/w when using RBD snapshot", | 356 | |
35 | + bdrv_get_device_or_node_name(state->bs)); | 357 | -void vhost_user_server_set_aio_context(VuServer *server, AioContext *ctx) |
36 | + ret = -EINVAL; | 358 | +/* Called with ctx acquired */ |
359 | +void vhost_user_server_attach_aio_context(VuServer *server, AioContext *ctx) | ||
360 | { | ||
361 | - VuFdWatch *vu_fd_watch, *next; | ||
362 | - void *opaque = NULL; | ||
363 | - IOHandler *io_read = NULL; | ||
364 | - bool attach; | ||
365 | + VuFdWatch *vu_fd_watch; | ||
366 | |||
367 | - server->ctx = ctx ? ctx : qemu_get_aio_context(); | ||
368 | + server->ctx = ctx; | ||
369 | |||
370 | if (!server->sioc) { | ||
371 | - /* not yet serving any client*/ | ||
372 | return; | ||
373 | } | ||
374 | |||
375 | - if (ctx) { | ||
376 | - qio_channel_attach_aio_context(server->ioc, ctx); | ||
377 | - server->aio_context_changed = true; | ||
378 | - io_read = kick_handler; | ||
379 | - attach = true; | ||
380 | - } else { | ||
381 | + qio_channel_attach_aio_context(server->ioc, ctx); | ||
382 | + | ||
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, | ||
385 | + NULL, vu_fd_watch); | ||
37 | + } | 386 | + } |
38 | + | 387 | + |
39 | + return ret; | 388 | + aio_co_schedule(ctx, server->co_trip); |
40 | +} | 389 | +} |
41 | + | 390 | + |
42 | static void qemu_rbd_close(BlockDriverState *bs) | 391 | +/* Called with server->ctx acquired */ |
43 | { | 392 | +void vhost_user_server_detach_aio_context(VuServer *server) |
44 | BDRVRBDState *s = bs->opaque; | 393 | +{ |
45 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_rbd = { | 394 | + if (server->sioc) { |
46 | .bdrv_parse_filename = qemu_rbd_parse_filename, | 395 | + VuFdWatch *vu_fd_watch; |
47 | .bdrv_file_open = qemu_rbd_open, | 396 | + |
48 | .bdrv_close = qemu_rbd_close, | 397 | + QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { |
49 | + .bdrv_reopen_prepare = qemu_rbd_reopen_prepare, | 398 | + aio_set_fd_handler(server->ctx, vu_fd_watch->fd, true, |
50 | .bdrv_create = qemu_rbd_create, | 399 | + NULL, NULL, NULL, vu_fd_watch); |
51 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | 400 | + } |
52 | .bdrv_get_info = qemu_rbd_getinfo, | 401 | + |
402 | qio_channel_detach_aio_context(server->ioc); | ||
403 | - /* server->ioc->ctx keeps the old AioConext */ | ||
404 | - ctx = server->ioc->ctx; | ||
405 | - attach = false; | ||
406 | } | ||
407 | |||
408 | - QTAILQ_FOREACH_SAFE(vu_fd_watch, &server->vu_fd_watches, next, next) { | ||
409 | - if (vu_fd_watch->cb) { | ||
410 | - opaque = attach ? vu_fd_watch : NULL; | ||
411 | - aio_set_fd_handler(ctx, vu_fd_watch->fd, true, | ||
412 | - io_read, NULL, NULL, | ||
413 | - opaque); | ||
414 | - } | ||
415 | - } | ||
416 | + server->ctx = NULL; | ||
417 | } | ||
418 | |||
419 | - | ||
420 | bool vhost_user_server_start(VuServer *server, | ||
421 | SocketAddress *socket_addr, | ||
422 | AioContext *ctx, | ||
423 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
424 | const VuDevIface *vu_iface, | ||
425 | Error **errp) | ||
426 | { | ||
427 | + QEMUBH *bh; | ||
428 | QIONetListener *listener = qio_net_listener_new(); | ||
429 | if (qio_net_listener_open_sync(listener, socket_addr, 1, | ||
430 | errp) < 0) { | ||
431 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
432 | return false; | ||
433 | } | ||
434 | |||
435 | + bh = qemu_bh_new(restart_listener_bh, server); | ||
436 | + | ||
437 | /* zero out unspecified fields */ | ||
438 | *server = (VuServer) { | ||
439 | .listener = listener, | ||
440 | + .restart_listener_bh = bh, | ||
441 | .vu_iface = vu_iface, | ||
442 | .max_queues = max_queues, | ||
443 | .ctx = ctx, | ||
53 | -- | 444 | -- |
54 | 2.9.3 | 445 | 2.26.2 |
55 | 446 | ||
56 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Propagate the flush return value since errors are possible. | ||
1 | 2 | ||
3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Message-id: 20200924151549.913737-11-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | block/export/vhost-user-blk-server.c | 11 +++++++---- | ||
8 | 1 file changed, 7 insertions(+), 4 deletions(-) | ||
9 | |||
10 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/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, | ||
15 | return -EINVAL; | ||
16 | } | ||
17 | |||
18 | -static void coroutine_fn vu_block_flush(VuBlockReq *req) | ||
19 | +static int coroutine_fn vu_block_flush(VuBlockReq *req) | ||
20 | { | ||
21 | VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | ||
22 | BlockBackend *backend = vdev_blk->backend; | ||
23 | - blk_co_flush(backend); | ||
24 | + return blk_co_flush(backend); | ||
25 | } | ||
26 | |||
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) | ||
29 | break; | ||
30 | } | ||
31 | case VIRTIO_BLK_T_FLUSH: | ||
32 | - vu_block_flush(req); | ||
33 | - req->in->status = VIRTIO_BLK_S_OK; | ||
34 | + if (vu_block_flush(req) == 0) { | ||
35 | + req->in->status = VIRTIO_BLK_S_OK; | ||
36 | + } else { | ||
37 | + req->in->status = VIRTIO_BLK_S_IOERR; | ||
38 | + } | ||
39 | break; | ||
40 | case VIRTIO_BLK_T_GET_ID: { | ||
41 | size_t size = MIN(iov_size(&elem->in_sg[0], in_num), | ||
42 | -- | ||
43 | 2.26.2 | ||
44 | diff view generated by jsdifflib |
1 | The BDRV_O_ALLOW_RDWR flag allows / prohibits the changing of | 1 | Use the new QAPI block exports API instead of defining our own QOM |
---|---|---|---|
2 | the BDS 'read_only' state, but there are a few places where it | 2 | objects. |
3 | is ignored. In the bdrv_set_read_only() helper, make sure to | 3 | |
4 | honor the flag. | 4 | This is a large change because the lifecycle of VuBlockDev needs to |
5 | 5 | follow BlockExportDriver. QOM properties are replaced by QAPI options | |
6 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 6 | objects. |
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | VuBlockDev is renamed VuBlkExport and contains a BlockExport field. |
9 | Message-id: be2e5fb2d285cbece2b6d06bed54a6f56520d251.1491597120.git.jcody@redhat.com | 9 | Several fields can be dropped since BlockExport already has equivalents. |
10 | |||
11 | The file names and meson build integration will be adjusted in a future | ||
12 | patch. libvhost-user should probably be built as a static library that | ||
13 | is linked into QEMU instead of as a .c file that results in duplicate | ||
14 | compilation. | ||
15 | |||
16 | The new command-line syntax is: | ||
17 | |||
18 | $ qemu-storage-daemon \ | ||
19 | --blockdev file,node-name=drive0,filename=test.img \ | ||
20 | --export vhost-user-blk,node-name=drive0,id=export0,unix-socket=/tmp/vhost-user-blk.sock | ||
21 | |||
22 | Note that unix-socket is optional because we may wish to accept chardevs | ||
23 | too in the future. | ||
24 | |||
25 | Markus noted that supported address families are not explicit in the | ||
26 | QAPI schema. It is unlikely that support for more address families will | ||
27 | be added since file descriptor passing is required and few address | ||
28 | families support it. If a new address family needs to be added, then the | ||
29 | QAPI 'features' syntax can be used to advertize them. | ||
30 | |||
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
32 | Acked-by: Markus Armbruster <armbru@redhat.com> | ||
33 | Message-id: 20200924151549.913737-12-stefanha@redhat.com | ||
34 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 35 | --- |
11 | block.c | 7 +++++++ | 36 | qapi/block-export.json | 21 +- |
12 | 1 file changed, 7 insertions(+) | 37 | block/export/vhost-user-blk-server.h | 23 +- |
13 | 38 | block/export/export.c | 6 + | |
14 | diff --git a/block.c b/block.c | 39 | block/export/vhost-user-blk-server.c | 452 +++++++-------------------- |
40 | tests/qtest/vhost-user-blk-test.c | 2 +- | ||
41 | util/vhost-user-server.c | 10 +- | ||
42 | block/export/meson.build | 1 + | ||
43 | block/meson.build | 1 - | ||
44 | 8 files changed, 157 insertions(+), 359 deletions(-) | ||
45 | |||
46 | diff --git a/qapi/block-export.json b/qapi/block-export.json | ||
15 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block.c | 48 | --- a/qapi/block-export.json |
17 | +++ b/block.c | 49 | +++ b/qapi/block-export.json |
18 | @@ -XXX,XX +XXX,XX @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 50 | @@ -XXX,XX +XXX,XX @@ |
51 | 'data': { '*name': 'str', '*description': 'str', | ||
52 | '*bitmap': 'str' } } | ||
53 | |||
54 | +## | ||
55 | +# @BlockExportOptionsVhostUserBlk: | ||
56 | +# | ||
57 | +# A vhost-user-blk block export. | ||
58 | +# | ||
59 | +# @addr: The vhost-user socket on which to listen. Both 'unix' and 'fd' | ||
60 | +# SocketAddress types are supported. Passed fds must be UNIX domain | ||
61 | +# sockets. | ||
62 | +# @logical-block-size: Logical block size in bytes. Defaults to 512 bytes. | ||
63 | +# | ||
64 | +# Since: 5.2 | ||
65 | +## | ||
66 | +{ 'struct': 'BlockExportOptionsVhostUserBlk', | ||
67 | + 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } | ||
68 | + | ||
69 | ## | ||
70 | # @NbdServerAddOptions: | ||
71 | # | ||
72 | @@ -XXX,XX +XXX,XX @@ | ||
73 | # An enumeration of block export types | ||
74 | # | ||
75 | # @nbd: NBD export | ||
76 | +# @vhost-user-blk: vhost-user-blk export (since 5.2) | ||
77 | # | ||
78 | # Since: 4.2 | ||
79 | ## | ||
80 | { 'enum': 'BlockExportType', | ||
81 | - 'data': [ 'nbd' ] } | ||
82 | + 'data': [ 'nbd', 'vhost-user-blk' ] } | ||
83 | |||
84 | ## | ||
85 | # @BlockExportOptions: | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | '*writethrough': 'bool' }, | ||
88 | 'discriminator': 'type', | ||
89 | 'data': { | ||
90 | - 'nbd': 'BlockExportOptionsNbd' | ||
91 | + 'nbd': 'BlockExportOptionsNbd', | ||
92 | + 'vhost-user-blk': 'BlockExportOptionsVhostUserBlk' | ||
93 | } } | ||
94 | |||
95 | ## | ||
96 | diff --git a/block/export/vhost-user-blk-server.h b/block/export/vhost-user-blk-server.h | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/block/export/vhost-user-blk-server.h | ||
99 | +++ b/block/export/vhost-user-blk-server.h | ||
100 | @@ -XXX,XX +XXX,XX @@ | ||
101 | |||
102 | #ifndef VHOST_USER_BLK_SERVER_H | ||
103 | #define VHOST_USER_BLK_SERVER_H | ||
104 | -#include "util/vhost-user-server.h" | ||
105 | |||
106 | -typedef struct VuBlockDev VuBlockDev; | ||
107 | -#define TYPE_VHOST_USER_BLK_SERVER "vhost-user-blk-server" | ||
108 | -#define VHOST_USER_BLK_SERVER(obj) \ | ||
109 | - OBJECT_CHECK(VuBlockDev, obj, TYPE_VHOST_USER_BLK_SERVER) | ||
110 | +#include "block/export.h" | ||
111 | |||
112 | -/* vhost user block device */ | ||
113 | -struct VuBlockDev { | ||
114 | - Object parent_obj; | ||
115 | - char *node_name; | ||
116 | - SocketAddress *addr; | ||
117 | - AioContext *ctx; | ||
118 | - VuServer vu_server; | ||
119 | - bool running; | ||
120 | - uint32_t blk_size; | ||
121 | - BlockBackend *backend; | ||
122 | - QIOChannelSocket *sioc; | ||
123 | - QTAILQ_ENTRY(VuBlockDev) next; | ||
124 | - struct virtio_blk_config blkcfg; | ||
125 | - bool writable; | ||
126 | -}; | ||
127 | +/* For block/export/export.c */ | ||
128 | +extern const BlockExportDriver blk_exp_vhost_user_blk; | ||
129 | |||
130 | #endif /* VHOST_USER_BLK_SERVER_H */ | ||
131 | diff --git a/block/export/export.c b/block/export/export.c | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/block/export/export.c | ||
134 | +++ b/block/export/export.c | ||
135 | @@ -XXX,XX +XXX,XX @@ | ||
136 | #include "sysemu/block-backend.h" | ||
137 | #include "block/export.h" | ||
138 | #include "block/nbd.h" | ||
139 | +#if CONFIG_LINUX | ||
140 | +#include "block/export/vhost-user-blk-server.h" | ||
141 | +#endif | ||
142 | #include "qapi/error.h" | ||
143 | #include "qapi/qapi-commands-block-export.h" | ||
144 | #include "qapi/qapi-events-block-export.h" | ||
145 | @@ -XXX,XX +XXX,XX @@ | ||
146 | |||
147 | static const BlockExportDriver *blk_exp_drivers[] = { | ||
148 | &blk_exp_nbd, | ||
149 | +#if CONFIG_LINUX | ||
150 | + &blk_exp_vhost_user_blk, | ||
151 | +#endif | ||
152 | }; | ||
153 | |||
154 | /* Only accessed from the main thread */ | ||
155 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/block/export/vhost-user-blk-server.c | ||
158 | +++ b/block/export/vhost-user-blk-server.c | ||
159 | @@ -XXX,XX +XXX,XX @@ | ||
160 | */ | ||
161 | #include "qemu/osdep.h" | ||
162 | #include "block/block.h" | ||
163 | +#include "contrib/libvhost-user/libvhost-user.h" | ||
164 | +#include "standard-headers/linux/virtio_blk.h" | ||
165 | +#include "util/vhost-user-server.h" | ||
166 | #include "vhost-user-blk-server.h" | ||
167 | #include "qapi/error.h" | ||
168 | #include "qom/object_interfaces.h" | ||
169 | @@ -XXX,XX +XXX,XX @@ struct virtio_blk_inhdr { | ||
170 | unsigned char status; | ||
171 | }; | ||
172 | |||
173 | -typedef struct VuBlockReq { | ||
174 | +typedef struct VuBlkReq { | ||
175 | VuVirtqElement elem; | ||
176 | int64_t sector_num; | ||
177 | size_t size; | ||
178 | @@ -XXX,XX +XXX,XX @@ typedef struct VuBlockReq { | ||
179 | struct virtio_blk_outhdr out; | ||
180 | VuServer *server; | ||
181 | struct VuVirtq *vq; | ||
182 | -} VuBlockReq; | ||
183 | +} VuBlkReq; | ||
184 | |||
185 | -static void vu_block_req_complete(VuBlockReq *req) | ||
186 | +/* vhost user block device */ | ||
187 | +typedef struct { | ||
188 | + BlockExport export; | ||
189 | + VuServer vu_server; | ||
190 | + uint32_t blk_size; | ||
191 | + QIOChannelSocket *sioc; | ||
192 | + struct virtio_blk_config blkcfg; | ||
193 | + bool writable; | ||
194 | +} VuBlkExport; | ||
195 | + | ||
196 | +static void vu_blk_req_complete(VuBlkReq *req) | ||
197 | { | ||
198 | VuDev *vu_dev = &req->server->vu_dev; | ||
199 | |||
200 | @@ -XXX,XX +XXX,XX @@ static void vu_block_req_complete(VuBlockReq *req) | ||
201 | free(req); | ||
202 | } | ||
203 | |||
204 | -static VuBlockDev *get_vu_block_device_by_server(VuServer *server) | ||
205 | -{ | ||
206 | - return container_of(server, VuBlockDev, vu_server); | ||
207 | -} | ||
208 | - | ||
209 | static int coroutine_fn | ||
210 | -vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, | ||
211 | - uint32_t iovcnt, uint32_t type) | ||
212 | +vu_blk_discard_write_zeroes(BlockBackend *blk, struct iovec *iov, | ||
213 | + uint32_t iovcnt, uint32_t type) | ||
214 | { | ||
215 | struct virtio_blk_discard_write_zeroes desc; | ||
216 | ssize_t size = iov_to_buf(iov, iovcnt, 0, &desc, sizeof(desc)); | ||
217 | @@ -XXX,XX +XXX,XX @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, | ||
19 | return -EINVAL; | 218 | return -EINVAL; |
20 | } | 219 | } |
21 | 220 | ||
22 | + /* Do not clear read_only if it is prohibited */ | 221 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); |
23 | + if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) { | 222 | uint64_t range[2] = { le64_to_cpu(desc.sector) << 9, |
24 | + error_setg(errp, "Node '%s' is read only", | 223 | le32_to_cpu(desc.num_sectors) << 9 }; |
25 | + bdrv_get_device_or_node_name(bs)); | 224 | if (type == VIRTIO_BLK_T_DISCARD) { |
26 | + return -EPERM; | 225 | - if (blk_co_pdiscard(vdev_blk->backend, range[0], range[1]) == 0) { |
226 | + if (blk_co_pdiscard(blk, range[0], range[1]) == 0) { | ||
227 | return 0; | ||
228 | } | ||
229 | } else if (type == VIRTIO_BLK_T_WRITE_ZEROES) { | ||
230 | - if (blk_co_pwrite_zeroes(vdev_blk->backend, | ||
231 | - range[0], range[1], 0) == 0) { | ||
232 | + if (blk_co_pwrite_zeroes(blk, range[0], range[1], 0) == 0) { | ||
233 | return 0; | ||
234 | } | ||
235 | } | ||
236 | @@ -XXX,XX +XXX,XX @@ vu_block_discard_write_zeroes(VuBlockReq *req, struct iovec *iov, | ||
237 | return -EINVAL; | ||
238 | } | ||
239 | |||
240 | -static int coroutine_fn vu_block_flush(VuBlockReq *req) | ||
241 | +static void coroutine_fn vu_blk_virtio_process_req(void *opaque) | ||
242 | { | ||
243 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(req->server); | ||
244 | - BlockBackend *backend = vdev_blk->backend; | ||
245 | - return blk_co_flush(backend); | ||
246 | -} | ||
247 | - | ||
248 | -static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
249 | -{ | ||
250 | - VuBlockReq *req = opaque; | ||
251 | + VuBlkReq *req = opaque; | ||
252 | VuServer *server = req->server; | ||
253 | VuVirtqElement *elem = &req->elem; | ||
254 | uint32_t type; | ||
255 | |||
256 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
257 | - BlockBackend *backend = vdev_blk->backend; | ||
258 | + VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); | ||
259 | + BlockBackend *blk = vexp->export.blk; | ||
260 | |||
261 | struct iovec *in_iov = elem->in_sg; | ||
262 | struct iovec *out_iov = elem->out_sg; | ||
263 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
264 | bool is_write = type & VIRTIO_BLK_T_OUT; | ||
265 | req->sector_num = le64_to_cpu(req->out.sector); | ||
266 | |||
267 | - int64_t offset = req->sector_num * vdev_blk->blk_size; | ||
268 | + if (is_write && !vexp->writable) { | ||
269 | + req->in->status = VIRTIO_BLK_S_IOERR; | ||
270 | + break; | ||
271 | + } | ||
272 | + | ||
273 | + int64_t offset = req->sector_num * vexp->blk_size; | ||
274 | QEMUIOVector qiov; | ||
275 | if (is_write) { | ||
276 | qemu_iovec_init_external(&qiov, out_iov, out_num); | ||
277 | - ret = blk_co_pwritev(backend, offset, qiov.size, | ||
278 | - &qiov, 0); | ||
279 | + ret = blk_co_pwritev(blk, offset, qiov.size, &qiov, 0); | ||
280 | } else { | ||
281 | qemu_iovec_init_external(&qiov, in_iov, in_num); | ||
282 | - ret = blk_co_preadv(backend, offset, qiov.size, | ||
283 | - &qiov, 0); | ||
284 | + ret = blk_co_preadv(blk, offset, qiov.size, &qiov, 0); | ||
285 | } | ||
286 | if (ret >= 0) { | ||
287 | req->in->status = VIRTIO_BLK_S_OK; | ||
288 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
289 | break; | ||
290 | } | ||
291 | case VIRTIO_BLK_T_FLUSH: | ||
292 | - if (vu_block_flush(req) == 0) { | ||
293 | + if (blk_co_flush(blk) == 0) { | ||
294 | req->in->status = VIRTIO_BLK_S_OK; | ||
295 | } else { | ||
296 | req->in->status = VIRTIO_BLK_S_IOERR; | ||
297 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
298 | case VIRTIO_BLK_T_DISCARD: | ||
299 | case VIRTIO_BLK_T_WRITE_ZEROES: { | ||
300 | int rc; | ||
301 | - rc = vu_block_discard_write_zeroes(req, &elem->out_sg[1], | ||
302 | - out_num, type); | ||
303 | + | ||
304 | + if (!vexp->writable) { | ||
305 | + req->in->status = VIRTIO_BLK_S_IOERR; | ||
306 | + break; | ||
307 | + } | ||
308 | + | ||
309 | + rc = vu_blk_discard_write_zeroes(blk, &elem->out_sg[1], out_num, type); | ||
310 | if (rc == 0) { | ||
311 | req->in->status = VIRTIO_BLK_S_OK; | ||
312 | } else { | ||
313 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn vu_block_virtio_process_req(void *opaque) | ||
314 | break; | ||
315 | } | ||
316 | |||
317 | - vu_block_req_complete(req); | ||
318 | + vu_blk_req_complete(req); | ||
319 | return; | ||
320 | |||
321 | err: | ||
322 | - free(elem); | ||
323 | + free(req); | ||
324 | } | ||
325 | |||
326 | -static void vu_block_process_vq(VuDev *vu_dev, int idx) | ||
327 | +static void vu_blk_process_vq(VuDev *vu_dev, int idx) | ||
328 | { | ||
329 | VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
330 | VuVirtq *vq = vu_get_queue(vu_dev, idx); | ||
331 | |||
332 | while (1) { | ||
333 | - VuBlockReq *req; | ||
334 | + VuBlkReq *req; | ||
335 | |||
336 | - req = vu_queue_pop(vu_dev, vq, sizeof(VuBlockReq)); | ||
337 | + req = vu_queue_pop(vu_dev, vq, sizeof(VuBlkReq)); | ||
338 | if (!req) { | ||
339 | break; | ||
340 | } | ||
341 | @@ -XXX,XX +XXX,XX @@ static void vu_block_process_vq(VuDev *vu_dev, int idx) | ||
342 | req->vq = vq; | ||
343 | |||
344 | Coroutine *co = | ||
345 | - qemu_coroutine_create(vu_block_virtio_process_req, req); | ||
346 | + qemu_coroutine_create(vu_blk_virtio_process_req, req); | ||
347 | qemu_coroutine_enter(co); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | -static void vu_block_queue_set_started(VuDev *vu_dev, int idx, bool started) | ||
352 | +static void vu_blk_queue_set_started(VuDev *vu_dev, int idx, bool started) | ||
353 | { | ||
354 | VuVirtq *vq; | ||
355 | |||
356 | assert(vu_dev); | ||
357 | |||
358 | vq = vu_get_queue(vu_dev, idx); | ||
359 | - vu_set_queue_handler(vu_dev, vq, started ? vu_block_process_vq : NULL); | ||
360 | + vu_set_queue_handler(vu_dev, vq, started ? vu_blk_process_vq : NULL); | ||
361 | } | ||
362 | |||
363 | -static uint64_t vu_block_get_features(VuDev *dev) | ||
364 | +static uint64_t vu_blk_get_features(VuDev *dev) | ||
365 | { | ||
366 | uint64_t features; | ||
367 | VuServer *server = container_of(dev, VuServer, vu_dev); | ||
368 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
369 | + VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); | ||
370 | features = 1ull << VIRTIO_BLK_F_SIZE_MAX | | ||
371 | 1ull << VIRTIO_BLK_F_SEG_MAX | | ||
372 | 1ull << VIRTIO_BLK_F_TOPOLOGY | | ||
373 | @@ -XXX,XX +XXX,XX @@ static uint64_t vu_block_get_features(VuDev *dev) | ||
374 | 1ull << VIRTIO_RING_F_EVENT_IDX | | ||
375 | 1ull << VHOST_USER_F_PROTOCOL_FEATURES; | ||
376 | |||
377 | - if (!vdev_blk->writable) { | ||
378 | + if (!vexp->writable) { | ||
379 | features |= 1ull << VIRTIO_BLK_F_RO; | ||
380 | } | ||
381 | |||
382 | return features; | ||
383 | } | ||
384 | |||
385 | -static uint64_t vu_block_get_protocol_features(VuDev *dev) | ||
386 | +static uint64_t vu_blk_get_protocol_features(VuDev *dev) | ||
387 | { | ||
388 | return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | | ||
389 | 1ull << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; | ||
390 | } | ||
391 | |||
392 | static int | ||
393 | -vu_block_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) | ||
394 | +vu_blk_get_config(VuDev *vu_dev, uint8_t *config, uint32_t len) | ||
395 | { | ||
396 | + /* TODO blkcfg must be little-endian for VIRTIO 1.0 */ | ||
397 | VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
398 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
399 | - memcpy(config, &vdev_blk->blkcfg, len); | ||
400 | - | ||
401 | + VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); | ||
402 | + memcpy(config, &vexp->blkcfg, len); | ||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | static int | ||
407 | -vu_block_set_config(VuDev *vu_dev, const uint8_t *data, | ||
408 | +vu_blk_set_config(VuDev *vu_dev, const uint8_t *data, | ||
409 | uint32_t offset, uint32_t size, uint32_t flags) | ||
410 | { | ||
411 | VuServer *server = container_of(vu_dev, VuServer, vu_dev); | ||
412 | - VuBlockDev *vdev_blk = get_vu_block_device_by_server(server); | ||
413 | + VuBlkExport *vexp = container_of(server, VuBlkExport, vu_server); | ||
414 | uint8_t wce; | ||
415 | |||
416 | /* don't support live migration */ | ||
417 | @@ -XXX,XX +XXX,XX @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, | ||
418 | } | ||
419 | |||
420 | wce = *data; | ||
421 | - vdev_blk->blkcfg.wce = wce; | ||
422 | - blk_set_enable_write_cache(vdev_blk->backend, wce); | ||
423 | + vexp->blkcfg.wce = wce; | ||
424 | + blk_set_enable_write_cache(vexp->export.blk, wce); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | @@ -XXX,XX +XXX,XX @@ vu_block_set_config(VuDev *vu_dev, const uint8_t *data, | ||
429 | * of vu_process_message. | ||
430 | * | ||
431 | */ | ||
432 | -static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_reply) | ||
433 | +static int vu_blk_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_reply) | ||
434 | { | ||
435 | if (vmsg->request == VHOST_USER_NONE) { | ||
436 | dev->panic(dev, "disconnect"); | ||
437 | @@ -XXX,XX +XXX,XX @@ static int vu_block_process_msg(VuDev *dev, VhostUserMsg *vmsg, int *do_reply) | ||
438 | return false; | ||
439 | } | ||
440 | |||
441 | -static const VuDevIface vu_block_iface = { | ||
442 | - .get_features = vu_block_get_features, | ||
443 | - .queue_set_started = vu_block_queue_set_started, | ||
444 | - .get_protocol_features = vu_block_get_protocol_features, | ||
445 | - .get_config = vu_block_get_config, | ||
446 | - .set_config = vu_block_set_config, | ||
447 | - .process_msg = vu_block_process_msg, | ||
448 | +static const VuDevIface vu_blk_iface = { | ||
449 | + .get_features = vu_blk_get_features, | ||
450 | + .queue_set_started = vu_blk_queue_set_started, | ||
451 | + .get_protocol_features = vu_blk_get_protocol_features, | ||
452 | + .get_config = vu_blk_get_config, | ||
453 | + .set_config = vu_blk_set_config, | ||
454 | + .process_msg = vu_blk_process_msg, | ||
455 | }; | ||
456 | |||
457 | static void blk_aio_attached(AioContext *ctx, void *opaque) | ||
458 | { | ||
459 | - VuBlockDev *vub_dev = opaque; | ||
460 | - vhost_user_server_attach_aio_context(&vub_dev->vu_server, ctx); | ||
461 | + VuBlkExport *vexp = opaque; | ||
462 | + vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); | ||
463 | } | ||
464 | |||
465 | static void blk_aio_detach(void *opaque) | ||
466 | { | ||
467 | - VuBlockDev *vub_dev = opaque; | ||
468 | - vhost_user_server_detach_aio_context(&vub_dev->vu_server); | ||
469 | + VuBlkExport *vexp = opaque; | ||
470 | + vhost_user_server_detach_aio_context(&vexp->vu_server); | ||
471 | } | ||
472 | |||
473 | static void | ||
474 | -vu_block_initialize_config(BlockDriverState *bs, | ||
475 | +vu_blk_initialize_config(BlockDriverState *bs, | ||
476 | struct virtio_blk_config *config, uint32_t blk_size) | ||
477 | { | ||
478 | config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; | ||
479 | @@ -XXX,XX +XXX,XX @@ vu_block_initialize_config(BlockDriverState *bs, | ||
480 | config->max_write_zeroes_seg = 1; | ||
481 | } | ||
482 | |||
483 | -static VuBlockDev *vu_block_init(VuBlockDev *vu_block_device, Error **errp) | ||
484 | +static void vu_blk_exp_request_shutdown(BlockExport *exp) | ||
485 | { | ||
486 | + VuBlkExport *vexp = container_of(exp, VuBlkExport, export); | ||
487 | |||
488 | - BlockBackend *blk; | ||
489 | - Error *local_error = NULL; | ||
490 | - const char *node_name = vu_block_device->node_name; | ||
491 | - bool writable = vu_block_device->writable; | ||
492 | - uint64_t perm = BLK_PERM_CONSISTENT_READ; | ||
493 | - int ret; | ||
494 | - | ||
495 | - AioContext *ctx; | ||
496 | - | ||
497 | - BlockDriverState *bs = bdrv_lookup_bs(node_name, node_name, &local_error); | ||
498 | - | ||
499 | - if (!bs) { | ||
500 | - error_propagate(errp, local_error); | ||
501 | - return NULL; | ||
502 | - } | ||
503 | - | ||
504 | - if (bdrv_is_read_only(bs)) { | ||
505 | - writable = false; | ||
506 | - } | ||
507 | - | ||
508 | - if (writable) { | ||
509 | - perm |= BLK_PERM_WRITE; | ||
510 | - } | ||
511 | - | ||
512 | - ctx = bdrv_get_aio_context(bs); | ||
513 | - aio_context_acquire(ctx); | ||
514 | - bdrv_invalidate_cache(bs, NULL); | ||
515 | - aio_context_release(ctx); | ||
516 | - | ||
517 | - /* | ||
518 | - * Don't allow resize while the vhost user server is running, | ||
519 | - * otherwise we don't care what happens with the node. | ||
520 | - */ | ||
521 | - blk = blk_new(bdrv_get_aio_context(bs), perm, | ||
522 | - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | | ||
523 | - BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); | ||
524 | - ret = blk_insert_bs(blk, bs, errp); | ||
525 | - | ||
526 | - if (ret < 0) { | ||
527 | - goto fail; | ||
528 | - } | ||
529 | - | ||
530 | - blk_set_enable_write_cache(blk, false); | ||
531 | - | ||
532 | - blk_set_allow_aio_context_change(blk, true); | ||
533 | - | ||
534 | - vu_block_device->blkcfg.wce = 0; | ||
535 | - vu_block_device->backend = blk; | ||
536 | - if (!vu_block_device->blk_size) { | ||
537 | - vu_block_device->blk_size = BDRV_SECTOR_SIZE; | ||
538 | - } | ||
539 | - vu_block_device->blkcfg.blk_size = vu_block_device->blk_size; | ||
540 | - blk_set_guest_block_size(blk, vu_block_device->blk_size); | ||
541 | - vu_block_initialize_config(bs, &vu_block_device->blkcfg, | ||
542 | - vu_block_device->blk_size); | ||
543 | - return vu_block_device; | ||
544 | - | ||
545 | -fail: | ||
546 | - blk_unref(blk); | ||
547 | - return NULL; | ||
548 | -} | ||
549 | - | ||
550 | -static void vu_block_deinit(VuBlockDev *vu_block_device) | ||
551 | -{ | ||
552 | - if (vu_block_device->backend) { | ||
553 | - blk_remove_aio_context_notifier(vu_block_device->backend, blk_aio_attached, | ||
554 | - blk_aio_detach, vu_block_device); | ||
555 | - } | ||
556 | - | ||
557 | - blk_unref(vu_block_device->backend); | ||
558 | -} | ||
559 | - | ||
560 | -static void vhost_user_blk_server_stop(VuBlockDev *vu_block_device) | ||
561 | -{ | ||
562 | - vhost_user_server_stop(&vu_block_device->vu_server); | ||
563 | - vu_block_deinit(vu_block_device); | ||
564 | -} | ||
565 | - | ||
566 | -static void vhost_user_blk_server_start(VuBlockDev *vu_block_device, | ||
567 | - Error **errp) | ||
568 | -{ | ||
569 | - AioContext *ctx; | ||
570 | - SocketAddress *addr = vu_block_device->addr; | ||
571 | - | ||
572 | - if (!vu_block_init(vu_block_device, errp)) { | ||
573 | - return; | ||
574 | - } | ||
575 | - | ||
576 | - ctx = bdrv_get_aio_context(blk_bs(vu_block_device->backend)); | ||
577 | - | ||
578 | - if (!vhost_user_server_start(&vu_block_device->vu_server, addr, ctx, | ||
579 | - VHOST_USER_BLK_MAX_QUEUES, &vu_block_iface, | ||
580 | - errp)) { | ||
581 | - goto error; | ||
582 | - } | ||
583 | - | ||
584 | - blk_add_aio_context_notifier(vu_block_device->backend, blk_aio_attached, | ||
585 | - blk_aio_detach, vu_block_device); | ||
586 | - vu_block_device->running = true; | ||
587 | - return; | ||
588 | - | ||
589 | - error: | ||
590 | - vu_block_deinit(vu_block_device); | ||
591 | -} | ||
592 | - | ||
593 | -static bool vu_prop_modifiable(VuBlockDev *vus, Error **errp) | ||
594 | -{ | ||
595 | - if (vus->running) { | ||
596 | - error_setg(errp, "The property can't be modified " | ||
597 | - "while the server is running"); | ||
598 | - return false; | ||
599 | - } | ||
600 | - return true; | ||
601 | -} | ||
602 | - | ||
603 | -static void vu_set_node_name(Object *obj, const char *value, Error **errp) | ||
604 | -{ | ||
605 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
606 | - | ||
607 | - if (!vu_prop_modifiable(vus, errp)) { | ||
608 | - return; | ||
609 | - } | ||
610 | - | ||
611 | - if (vus->node_name) { | ||
612 | - g_free(vus->node_name); | ||
613 | - } | ||
614 | - | ||
615 | - vus->node_name = g_strdup(value); | ||
616 | -} | ||
617 | - | ||
618 | -static char *vu_get_node_name(Object *obj, Error **errp) | ||
619 | -{ | ||
620 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
621 | - return g_strdup(vus->node_name); | ||
622 | -} | ||
623 | - | ||
624 | -static void free_socket_addr(SocketAddress *addr) | ||
625 | -{ | ||
626 | - g_free(addr->u.q_unix.path); | ||
627 | - g_free(addr); | ||
628 | -} | ||
629 | - | ||
630 | -static void vu_set_unix_socket(Object *obj, const char *value, | ||
631 | - Error **errp) | ||
632 | -{ | ||
633 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
634 | - | ||
635 | - if (!vu_prop_modifiable(vus, errp)) { | ||
636 | - return; | ||
637 | - } | ||
638 | - | ||
639 | - if (vus->addr) { | ||
640 | - free_socket_addr(vus->addr); | ||
641 | - } | ||
642 | - | ||
643 | - SocketAddress *addr = g_new0(SocketAddress, 1); | ||
644 | - addr->type = SOCKET_ADDRESS_TYPE_UNIX; | ||
645 | - addr->u.q_unix.path = g_strdup(value); | ||
646 | - vus->addr = addr; | ||
647 | + vhost_user_server_stop(&vexp->vu_server); | ||
648 | } | ||
649 | |||
650 | -static char *vu_get_unix_socket(Object *obj, Error **errp) | ||
651 | +static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | ||
652 | + Error **errp) | ||
653 | { | ||
654 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
655 | - return g_strdup(vus->addr->u.q_unix.path); | ||
656 | -} | ||
657 | - | ||
658 | -static bool vu_get_block_writable(Object *obj, Error **errp) | ||
659 | -{ | ||
660 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
661 | - return vus->writable; | ||
662 | -} | ||
663 | - | ||
664 | -static void vu_set_block_writable(Object *obj, bool value, Error **errp) | ||
665 | -{ | ||
666 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
667 | - | ||
668 | - if (!vu_prop_modifiable(vus, errp)) { | ||
669 | - return; | ||
670 | - } | ||
671 | - | ||
672 | - vus->writable = value; | ||
673 | -} | ||
674 | - | ||
675 | -static void vu_get_blk_size(Object *obj, Visitor *v, const char *name, | ||
676 | - void *opaque, Error **errp) | ||
677 | -{ | ||
678 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
679 | - uint32_t value = vus->blk_size; | ||
680 | - | ||
681 | - visit_type_uint32(v, name, &value, errp); | ||
682 | -} | ||
683 | - | ||
684 | -static void vu_set_blk_size(Object *obj, Visitor *v, const char *name, | ||
685 | - void *opaque, Error **errp) | ||
686 | -{ | ||
687 | - VuBlockDev *vus = VHOST_USER_BLK_SERVER(obj); | ||
688 | - | ||
689 | + VuBlkExport *vexp = container_of(exp, VuBlkExport, export); | ||
690 | + BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk; | ||
691 | Error *local_err = NULL; | ||
692 | - uint32_t value; | ||
693 | + uint64_t logical_block_size; | ||
694 | |||
695 | - if (!vu_prop_modifiable(vus, errp)) { | ||
696 | - return; | ||
697 | - } | ||
698 | + vexp->writable = opts->writable; | ||
699 | + vexp->blkcfg.wce = 0; | ||
700 | |||
701 | - visit_type_uint32(v, name, &value, &local_err); | ||
702 | - if (local_err) { | ||
703 | - goto out; | ||
704 | + if (vu_opts->has_logical_block_size) { | ||
705 | + logical_block_size = vu_opts->logical_block_size; | ||
706 | + } else { | ||
707 | + logical_block_size = BDRV_SECTOR_SIZE; | ||
708 | } | ||
709 | - | ||
710 | - check_block_size(object_get_typename(obj), name, value, &local_err); | ||
711 | + check_block_size(exp->id, "logical-block-size", logical_block_size, | ||
712 | + &local_err); | ||
713 | if (local_err) { | ||
714 | - goto out; | ||
715 | + error_propagate(errp, local_err); | ||
716 | + return -EINVAL; | ||
717 | + } | ||
718 | + vexp->blk_size = logical_block_size; | ||
719 | + blk_set_guest_block_size(exp->blk, logical_block_size); | ||
720 | + vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, | ||
721 | + logical_block_size); | ||
722 | + | ||
723 | + blk_set_allow_aio_context_change(exp->blk, true); | ||
724 | + blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | ||
725 | + vexp); | ||
726 | + | ||
727 | + if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, | ||
728 | + VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, | ||
729 | + errp)) { | ||
730 | + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, | ||
731 | + blk_aio_detach, vexp); | ||
732 | + return -EADDRNOTAVAIL; | ||
733 | } | ||
734 | |||
735 | - vus->blk_size = value; | ||
736 | - | ||
737 | -out: | ||
738 | - error_propagate(errp, local_err); | ||
739 | -} | ||
740 | - | ||
741 | -static void vhost_user_blk_server_instance_finalize(Object *obj) | ||
742 | -{ | ||
743 | - VuBlockDev *vub = VHOST_USER_BLK_SERVER(obj); | ||
744 | - | ||
745 | - vhost_user_blk_server_stop(vub); | ||
746 | - | ||
747 | - /* | ||
748 | - * Unlike object_property_add_str, object_class_property_add_str | ||
749 | - * doesn't have a release method. Thus manual memory freeing is | ||
750 | - * needed. | ||
751 | - */ | ||
752 | - free_socket_addr(vub->addr); | ||
753 | - g_free(vub->node_name); | ||
754 | -} | ||
755 | - | ||
756 | -static void vhost_user_blk_server_complete(UserCreatable *obj, Error **errp) | ||
757 | -{ | ||
758 | - VuBlockDev *vub = VHOST_USER_BLK_SERVER(obj); | ||
759 | - | ||
760 | - vhost_user_blk_server_start(vub, errp); | ||
761 | + return 0; | ||
762 | } | ||
763 | |||
764 | -static void vhost_user_blk_server_class_init(ObjectClass *klass, | ||
765 | - void *class_data) | ||
766 | +static void vu_blk_exp_delete(BlockExport *exp) | ||
767 | { | ||
768 | - UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); | ||
769 | - ucc->complete = vhost_user_blk_server_complete; | ||
770 | - | ||
771 | - object_class_property_add_bool(klass, "writable", | ||
772 | - vu_get_block_writable, | ||
773 | - vu_set_block_writable); | ||
774 | - | ||
775 | - object_class_property_add_str(klass, "node-name", | ||
776 | - vu_get_node_name, | ||
777 | - vu_set_node_name); | ||
778 | - | ||
779 | - object_class_property_add_str(klass, "unix-socket", | ||
780 | - vu_get_unix_socket, | ||
781 | - vu_set_unix_socket); | ||
782 | + VuBlkExport *vexp = container_of(exp, VuBlkExport, export); | ||
783 | |||
784 | - object_class_property_add(klass, "logical-block-size", "uint32", | ||
785 | - vu_get_blk_size, vu_set_blk_size, | ||
786 | - NULL, NULL); | ||
787 | + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | ||
788 | + vexp); | ||
789 | } | ||
790 | |||
791 | -static const TypeInfo vhost_user_blk_server_info = { | ||
792 | - .name = TYPE_VHOST_USER_BLK_SERVER, | ||
793 | - .parent = TYPE_OBJECT, | ||
794 | - .instance_size = sizeof(VuBlockDev), | ||
795 | - .instance_finalize = vhost_user_blk_server_instance_finalize, | ||
796 | - .class_init = vhost_user_blk_server_class_init, | ||
797 | - .interfaces = (InterfaceInfo[]) { | ||
798 | - {TYPE_USER_CREATABLE}, | ||
799 | - {} | ||
800 | - }, | ||
801 | +const BlockExportDriver blk_exp_vhost_user_blk = { | ||
802 | + .type = BLOCK_EXPORT_TYPE_VHOST_USER_BLK, | ||
803 | + .instance_size = sizeof(VuBlkExport), | ||
804 | + .create = vu_blk_exp_create, | ||
805 | + .delete = vu_blk_exp_delete, | ||
806 | + .request_shutdown = vu_blk_exp_request_shutdown, | ||
807 | }; | ||
808 | - | ||
809 | -static void vhost_user_blk_server_register_types(void) | ||
810 | -{ | ||
811 | - type_register_static(&vhost_user_blk_server_info); | ||
812 | -} | ||
813 | - | ||
814 | -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 | ||
829 | index XXXXXXX..XXXXXXX 100644 | ||
830 | --- a/util/vhost-user-server.c | ||
831 | +++ b/util/vhost-user-server.c | ||
832 | @@ -XXX,XX +XXX,XX @@ bool vhost_user_server_start(VuServer *server, | ||
833 | Error **errp) | ||
834 | { | ||
835 | QEMUBH *bh; | ||
836 | - QIONetListener *listener = qio_net_listener_new(); | ||
837 | + QIONetListener *listener; | ||
838 | + | ||
839 | + if (socket_addr->type != SOCKET_ADDRESS_TYPE_UNIX && | ||
840 | + socket_addr->type != SOCKET_ADDRESS_TYPE_FD) { | ||
841 | + error_setg(errp, "Only socket address types 'unix' and 'fd' are supported"); | ||
842 | + return false; | ||
27 | + } | 843 | + } |
28 | + | 844 | + |
29 | bs->read_only = read_only; | 845 | + listener = qio_net_listener_new(); |
30 | return 0; | 846 | if (qio_net_listener_open_sync(listener, socket_addr, 1, |
31 | } | 847 | errp) < 0) { |
848 | object_unref(OBJECT(listener)); | ||
849 | diff --git a/block/export/meson.build b/block/export/meson.build | ||
850 | index XXXXXXX..XXXXXXX 100644 | ||
851 | --- a/block/export/meson.build | ||
852 | +++ b/block/export/meson.build | ||
853 | @@ -1 +1,2 @@ | ||
854 | block_ss.add(files('export.c')) | ||
855 | +block_ss.add(when: 'CONFIG_LINUX', if_true: files('vhost-user-blk-server.c', '../../contrib/libvhost-user/libvhost-user.c')) | ||
856 | diff --git a/block/meson.build b/block/meson.build | ||
857 | index XXXXXXX..XXXXXXX 100644 | ||
858 | --- a/block/meson.build | ||
859 | +++ b/block/meson.build | ||
860 | @@ -XXX,XX +XXX,XX @@ block_ss.add(when: 'CONFIG_WIN32', if_true: files('file-win32.c', 'win32-aio.c') | ||
861 | block_ss.add(when: 'CONFIG_POSIX', if_true: [files('file-posix.c'), coref, iokit]) | ||
862 | block_ss.add(when: 'CONFIG_LIBISCSI', if_true: files('iscsi-opts.c')) | ||
863 | block_ss.add(when: 'CONFIG_LINUX', if_true: files('nvme.c')) | ||
864 | -block_ss.add(when: 'CONFIG_LINUX', if_true: files('export/vhost-user-blk-server.c', '../contrib/libvhost-user/libvhost-user.c')) | ||
865 | block_ss.add(when: 'CONFIG_REPLICATION', if_true: files('replication.c')) | ||
866 | block_ss.add(when: 'CONFIG_SHEEPDOG', if_true: files('sheepdog.c')) | ||
867 | block_ss.add(when: ['CONFIG_LINUX_AIO', libaio], if_true: files('linux-aio.c')) | ||
32 | -- | 868 | -- |
33 | 2.9.3 | 869 | 2.26.2 |
34 | 870 | ||
35 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Headers used by other subsystems are located in include/. Also add the | ||
2 | vhost-user-server and vhost-user-blk-server headers to MAINTAINERS. | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Message-id: 20200924151549.913737-13-stefanha@redhat.com | ||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | --- | ||
8 | MAINTAINERS | 4 +++- | ||
9 | {util => include/qemu}/vhost-user-server.h | 0 | ||
10 | block/export/vhost-user-blk-server.c | 2 +- | ||
11 | util/vhost-user-server.c | 2 +- | ||
12 | 4 files changed, 5 insertions(+), 3 deletions(-) | ||
13 | rename {util => include/qemu}/vhost-user-server.h (100%) | ||
14 | |||
15 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/MAINTAINERS | ||
18 | +++ b/MAINTAINERS | ||
19 | @@ -XXX,XX +XXX,XX @@ Vhost-user block device backend server | ||
20 | M: Coiby Xu <Coiby.Xu@gmail.com> | ||
21 | S: Maintained | ||
22 | F: block/export/vhost-user-blk-server.c | ||
23 | -F: util/vhost-user-server.c | ||
24 | +F: block/export/vhost-user-blk-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 | ||
28 | +F: util/vhost-user-server.c | ||
29 | |||
30 | Replication | ||
31 | M: Wen Congyang <wencongyang2@huawei.com> | ||
32 | diff --git a/util/vhost-user-server.h b/include/qemu/vhost-user-server.h | ||
33 | similarity index 100% | ||
34 | rename from util/vhost-user-server.h | ||
35 | rename to include/qemu/vhost-user-server.h | ||
36 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block/export/vhost-user-blk-server.c | ||
39 | +++ b/block/export/vhost-user-blk-server.c | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | #include "block/block.h" | ||
42 | #include "contrib/libvhost-user/libvhost-user.h" | ||
43 | #include "standard-headers/linux/virtio_blk.h" | ||
44 | -#include "util/vhost-user-server.h" | ||
45 | +#include "qemu/vhost-user-server.h" | ||
46 | #include "vhost-user-blk-server.h" | ||
47 | #include "qapi/error.h" | ||
48 | #include "qom/object_interfaces.h" | ||
49 | diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/util/vhost-user-server.c | ||
52 | +++ b/util/vhost-user-server.c | ||
53 | @@ -XXX,XX +XXX,XX @@ | ||
54 | */ | ||
55 | #include "qemu/osdep.h" | ||
56 | #include "qemu/main-loop.h" | ||
57 | +#include "qemu/vhost-user-server.h" | ||
58 | #include "block/aio-wait.h" | ||
59 | -#include "vhost-user-server.h" | ||
60 | |||
61 | /* | ||
62 | * Theory of operation: | ||
63 | -- | ||
64 | 2.26.2 | ||
65 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Don't compile contrib/libvhost-user/libvhost-user.c again. Instead build | ||
2 | the static library once and then reuse it throughout QEMU. | ||
1 | 3 | ||
4 | Also switch from CONFIG_LINUX to CONFIG_VHOST_USER, which is what the | ||
5 | vhost-user tools (vhost-user-gpu, etc) do. | ||
6 | |||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Message-id: 20200924151549.913737-14-stefanha@redhat.com | ||
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | ||
11 | block/export/export.c | 8 ++++---- | ||
12 | block/export/meson.build | 2 +- | ||
13 | contrib/libvhost-user/meson.build | 1 + | ||
14 | meson.build | 6 +++++- | ||
15 | tests/qtest/meson.build | 2 +- | ||
16 | util/meson.build | 4 +++- | ||
17 | 6 files changed, 15 insertions(+), 8 deletions(-) | ||
18 | |||
19 | diff --git a/block/export/export.c b/block/export/export.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/export/export.c | ||
22 | +++ b/block/export/export.c | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | #include "sysemu/block-backend.h" | ||
25 | #include "block/export.h" | ||
26 | #include "block/nbd.h" | ||
27 | -#if CONFIG_LINUX | ||
28 | -#include "block/export/vhost-user-blk-server.h" | ||
29 | -#endif | ||
30 | #include "qapi/error.h" | ||
31 | #include "qapi/qapi-commands-block-export.h" | ||
32 | #include "qapi/qapi-events-block-export.h" | ||
33 | #include "qemu/id.h" | ||
34 | +#ifdef CONFIG_VHOST_USER | ||
35 | +#include "vhost-user-blk-server.h" | ||
36 | +#endif | ||
37 | |||
38 | static const BlockExportDriver *blk_exp_drivers[] = { | ||
39 | &blk_exp_nbd, | ||
40 | -#if CONFIG_LINUX | ||
41 | +#ifdef CONFIG_VHOST_USER | ||
42 | &blk_exp_vhost_user_blk, | ||
43 | #endif | ||
44 | }; | ||
45 | diff --git a/block/export/meson.build b/block/export/meson.build | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/block/export/meson.build | ||
48 | +++ b/block/export/meson.build | ||
49 | @@ -XXX,XX +XXX,XX @@ | ||
50 | 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_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 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/contrib/libvhost-user/meson.build | ||
56 | +++ b/contrib/libvhost-user/meson.build | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | libvhost_user = static_library('vhost-user', | ||
59 | files('libvhost-user.c', 'libvhost-user-glib.c'), | ||
60 | build_by_default: false) | ||
61 | +vhost_user = declare_dependency(link_with: libvhost_user) | ||
62 | diff --git a/meson.build b/meson.build | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/meson.build | ||
65 | +++ b/meson.build | ||
66 | @@ -XXX,XX +XXX,XX @@ trace_events_subdirs += [ | ||
67 | 'util', | ||
68 | ] | ||
69 | |||
70 | +vhost_user = not_found | ||
71 | +if 'CONFIG_VHOST_USER' in config_host | ||
72 | + subdir('contrib/libvhost-user') | ||
73 | +endif | ||
74 | + | ||
75 | subdir('qapi') | ||
76 | subdir('qobject') | ||
77 | subdir('stubs') | ||
78 | @@ -XXX,XX +XXX,XX @@ if have_tools | ||
79 | install: true) | ||
80 | |||
81 | if 'CONFIG_VHOST_USER' in config_host | ||
82 | - subdir('contrib/libvhost-user') | ||
83 | subdir('contrib/vhost-user-blk') | ||
84 | subdir('contrib/vhost-user-gpu') | ||
85 | 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 | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/util/meson.build | ||
102 | +++ b/util/meson.build | ||
103 | @@ -XXX,XX +XXX,XX @@ if have_block | ||
104 | util_ss.add(files('main-loop.c')) | ||
105 | util_ss.add(files('nvdimm-utils.c')) | ||
106 | 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')) | ||
108 | + util_ss.add(when: 'CONFIG_VHOST_USER', if_true: [ | ||
109 | + files('vhost-user-server.c'), vhost_user | ||
110 | + ]) | ||
111 | util_ss.add(files('block-helpers.c')) | ||
112 | util_ss.add(files('qemu-coroutine-sleep.c')) | ||
113 | util_ss.add(files('qemu-co-shared-resource.c')) | ||
114 | -- | ||
115 | 2.26.2 | ||
116 | diff view generated by jsdifflib |
1 | The protocol VXHS does not support image creation. Some tests expect | 1 | Introduce libblkdev.fa to avoid recompiling blockdev_ss twice. |
---|---|---|---|
2 | to be able to create images through the protocol. Exclude VXHS from | ||
3 | these tests. | ||
4 | 2 | ||
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 3 | Suggested-by: Paolo Bonzini <pbonzini@redhat.com> |
4 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Message-id: 20200929125516.186715-3-stefanha@redhat.com | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | 8 | --- |
7 | tests/qemu-iotests/017 | 1 + | 9 | meson.build | 12 ++++++++++-- |
8 | tests/qemu-iotests/020 | 1 + | 10 | storage-daemon/meson.build | 3 +-- |
9 | tests/qemu-iotests/029 | 1 + | 11 | 2 files changed, 11 insertions(+), 4 deletions(-) |
10 | tests/qemu-iotests/073 | 1 + | ||
11 | tests/qemu-iotests/114 | 1 + | ||
12 | tests/qemu-iotests/130 | 1 + | ||
13 | tests/qemu-iotests/134 | 1 + | ||
14 | tests/qemu-iotests/156 | 1 + | ||
15 | tests/qemu-iotests/158 | 1 + | ||
16 | 9 files changed, 9 insertions(+) | ||
17 | 12 | ||
18 | diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 | 13 | diff --git a/meson.build b/meson.build |
19 | index XXXXXXX..XXXXXXX 100755 | 14 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/qemu-iotests/017 | 15 | --- a/meson.build |
21 | +++ b/tests/qemu-iotests/017 | 16 | +++ b/meson.build |
22 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 17 | @@ -XXX,XX +XXX,XX @@ blockdev_ss.add(files( |
23 | # Any format supporting backing files | 18 | blockdev_ss.add(when: 'CONFIG_POSIX', if_true: files('os-posix.c')) |
24 | _supported_fmt qcow qcow2 vmdk qed | 19 | softmmu_ss.add(when: 'CONFIG_WIN32', if_true: [files('os-win32.c')]) |
25 | _supported_proto generic | 20 | |
26 | +_unsupported_proto vxhs | 21 | -softmmu_ss.add_all(blockdev_ss) |
27 | _supported_os Linux | 22 | softmmu_ss.add(files( |
28 | _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | 23 | 'bootdevice.c', |
29 | 24 | 'dma-helpers.c', | |
30 | diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 | 25 | @@ -XXX,XX +XXX,XX @@ block = declare_dependency(link_whole: [libblock], |
31 | index XXXXXXX..XXXXXXX 100755 | 26 | link_args: '@block.syms', |
32 | --- a/tests/qemu-iotests/020 | 27 | dependencies: [crypto, io]) |
33 | +++ b/tests/qemu-iotests/020 | 28 | |
34 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 29 | +blockdev_ss = blockdev_ss.apply(config_host, strict: false) |
35 | # Any format supporting backing files | 30 | +libblockdev = static_library('blockdev', blockdev_ss.sources() + genh, |
36 | _supported_fmt qcow qcow2 vmdk qed | 31 | + dependencies: blockdev_ss.dependencies(), |
37 | _supported_proto generic | 32 | + name_suffix: 'fa', |
38 | +_unsupported_proto vxhs | 33 | + build_by_default: false) |
39 | _supported_os Linux | 34 | + |
40 | _unsupported_imgopts "subformat=monolithicFlat" \ | 35 | +blockdev = declare_dependency(link_whole: [libblockdev], |
41 | "subformat=twoGbMaxExtentFlat" \ | 36 | + dependencies: [block]) |
42 | diff --git a/tests/qemu-iotests/029 b/tests/qemu-iotests/029 | 37 | + |
43 | index XXXXXXX..XXXXXXX 100755 | 38 | qmp_ss = qmp_ss.apply(config_host, strict: false) |
44 | --- a/tests/qemu-iotests/029 | 39 | libqmp = static_library('qmp', qmp_ss.sources() + genh, |
45 | +++ b/tests/qemu-iotests/029 | 40 | dependencies: qmp_ss.dependencies(), |
46 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 41 | @@ -XXX,XX +XXX,XX @@ foreach m : block_mods + softmmu_mods |
47 | # Any format supporting intenal snapshots | 42 | install_dir: config_host['qemu_moddir']) |
48 | _supported_fmt qcow2 | 43 | endforeach |
49 | _supported_proto generic | 44 | |
50 | +_unsupported_proto vxhs | 45 | -softmmu_ss.add(authz, block, chardev, crypto, io, qmp) |
51 | _supported_os Linux | 46 | +softmmu_ss.add(authz, blockdev, chardev, crypto, io, qmp) |
52 | # Internal snapshots are (currently) impossible with refcount_bits=1 | 47 | common_ss.add(qom, qemuutil) |
53 | _unsupported_imgopts 'refcount_bits=1[^0-9]' | 48 | |
54 | diff --git a/tests/qemu-iotests/073 b/tests/qemu-iotests/073 | 49 | common_ss.add_all(when: 'CONFIG_SOFTMMU', if_true: [softmmu_ss]) |
55 | index XXXXXXX..XXXXXXX 100755 | 50 | diff --git a/storage-daemon/meson.build b/storage-daemon/meson.build |
56 | --- a/tests/qemu-iotests/073 | 51 | index XXXXXXX..XXXXXXX 100644 |
57 | +++ b/tests/qemu-iotests/073 | 52 | --- a/storage-daemon/meson.build |
58 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | 53 | +++ b/storage-daemon/meson.build |
59 | 54 | @@ -XXX,XX +XXX,XX @@ | |
60 | _supported_fmt qcow2 | 55 | qsd_ss = ss.source_set() |
61 | _supported_proto generic | 56 | qsd_ss.add(files('qemu-storage-daemon.c')) |
62 | +_unsupported_proto vxhs | 57 | -qsd_ss.add(block, chardev, qmp, qom, qemuutil) |
63 | _supported_os Linux | 58 | -qsd_ss.add_all(blockdev_ss) |
64 | 59 | +qsd_ss.add(blockdev, chardev, qmp, qom, qemuutil) | |
65 | CLUSTER_SIZE=64k | 60 | |
66 | diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114 | 61 | subdir('qapi') |
67 | index XXXXXXX..XXXXXXX 100755 | ||
68 | --- a/tests/qemu-iotests/114 | ||
69 | +++ b/tests/qemu-iotests/114 | ||
70 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
71 | |||
72 | _supported_fmt qcow2 | ||
73 | _supported_proto generic | ||
74 | +_unsupported_proto vxhs | ||
75 | _supported_os Linux | ||
76 | |||
77 | |||
78 | diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 | ||
79 | index XXXXXXX..XXXXXXX 100755 | ||
80 | --- a/tests/qemu-iotests/130 | ||
81 | +++ b/tests/qemu-iotests/130 | ||
82 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
83 | |||
84 | _supported_fmt qcow2 | ||
85 | _supported_proto generic | ||
86 | +_unsupported_proto vxhs | ||
87 | _supported_os Linux | ||
88 | |||
89 | qemu_comm_method="monitor" | ||
90 | diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 | ||
91 | index XXXXXXX..XXXXXXX 100755 | ||
92 | --- a/tests/qemu-iotests/134 | ||
93 | +++ b/tests/qemu-iotests/134 | ||
94 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
95 | |||
96 | _supported_fmt qcow2 | ||
97 | _supported_proto generic | ||
98 | +_unsupported_proto vxhs | ||
99 | _supported_os Linux | ||
100 | |||
101 | |||
102 | diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 | ||
103 | index XXXXXXX..XXXXXXX 100755 | ||
104 | --- a/tests/qemu-iotests/156 | ||
105 | +++ b/tests/qemu-iotests/156 | ||
106 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
107 | |||
108 | _supported_fmt qcow2 qed | ||
109 | _supported_proto generic | ||
110 | +_unsupported_proto vxhs | ||
111 | _supported_os Linux | ||
112 | |||
113 | # Create source disk | ||
114 | diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 | ||
115 | index XXXXXXX..XXXXXXX 100755 | ||
116 | --- a/tests/qemu-iotests/158 | ||
117 | +++ b/tests/qemu-iotests/158 | ||
118 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
119 | |||
120 | _supported_fmt qcow2 | ||
121 | _supported_proto generic | ||
122 | +_unsupported_proto vxhs | ||
123 | _supported_os Linux | ||
124 | |||
125 | 62 | ||
126 | -- | 63 | -- |
127 | 2.9.3 | 64 | 2.26.2 |
128 | 65 | ||
129 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Block exports are used by softmmu, qemu-storage-daemon, and qemu-nbd. | ||
2 | They are not used by other programs and are not otherwise needed in | ||
3 | libblock. | ||
1 | 4 | ||
5 | Undo the recent move of blockdev-nbd.c from blockdev_ss into block_ss. | ||
6 | Since bdrv_close_all() (libblock) calls blk_exp_close_all() | ||
7 | (libblockdev) a stub function is required.. | ||
8 | |||
9 | Make qemu-nbd.c use signal handling utility functions instead of | ||
10 | duplicating the code. This helps because os-posix.c is in libblockdev | ||
11 | and it depends on a qemu_system_killed() symbol that qemu-nbd.c lacks. | ||
12 | Once we use the signal handling utility functions we also end up | ||
13 | providing the necessary symbol. | ||
14 | |||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
17 | Reviewed-by: Eric Blake <eblake@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 | ||
20 | --Stefan] | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | --- | ||
23 | qemu-nbd.c | 21 +++++++++------------ | ||
24 | stubs/blk-exp-close-all.c | 7 +++++++ | ||
25 | block/export/meson.build | 4 ++-- | ||
26 | meson.build | 4 ++-- | ||
27 | nbd/meson.build | 2 ++ | ||
28 | stubs/meson.build | 1 + | ||
29 | 6 files changed, 23 insertions(+), 16 deletions(-) | ||
30 | create mode 100644 stubs/blk-exp-close-all.c | ||
31 | |||
32 | diff --git a/qemu-nbd.c b/qemu-nbd.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/qemu-nbd.c | ||
35 | +++ b/qemu-nbd.c | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #include "qapi/error.h" | ||
38 | #include "qemu/cutils.h" | ||
39 | #include "sysemu/block-backend.h" | ||
40 | +#include "sysemu/runstate.h" /* for qemu_system_killed() prototype */ | ||
41 | #include "block/block_int.h" | ||
42 | #include "block/nbd.h" | ||
43 | #include "qemu/main-loop.h" | ||
44 | @@ -XXX,XX +XXX,XX @@ QEMU_COPYRIGHT "\n" | ||
45 | } | ||
46 | |||
47 | #if HAVE_NBD_DEVICE | ||
48 | -static void termsig_handler(int signum) | ||
49 | +/* | ||
50 | + * The client thread uses SIGTERM to interrupt the server. A signal | ||
51 | + * handler ensures that "qemu-nbd -v -c" exits with a nice status code. | ||
52 | + */ | ||
53 | +void qemu_system_killed(int signum, pid_t pid) | ||
54 | { | ||
55 | qatomic_cmpxchg(&state, RUNNING, TERMINATE); | ||
56 | qemu_notify_event(); | ||
57 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
58 | const char *pid_file_name = NULL; | ||
59 | BlockExportOptions *export_opts; | ||
60 | |||
61 | + os_setup_early_signal_handling(); | ||
62 | + | ||
63 | #if HAVE_NBD_DEVICE | ||
64 | - /* The client thread uses SIGTERM to interrupt the server. A signal | ||
65 | - * handler ensures that "qemu-nbd -v -c" exits with a nice status code. | ||
66 | - */ | ||
67 | - struct sigaction sa_sigterm; | ||
68 | - memset(&sa_sigterm, 0, sizeof(sa_sigterm)); | ||
69 | - sa_sigterm.sa_handler = termsig_handler; | ||
70 | - sigaction(SIGTERM, &sa_sigterm, NULL); | ||
71 | + os_setup_signal_handling(); | ||
72 | #endif /* HAVE_NBD_DEVICE */ | ||
73 | |||
74 | -#ifdef CONFIG_POSIX | ||
75 | - signal(SIGPIPE, SIG_IGN); | ||
76 | -#endif | ||
77 | - | ||
78 | socket_init(); | ||
79 | error_init(argv[0]); | ||
80 | module_call_init(MODULE_INIT_TRACE); | ||
81 | diff --git a/stubs/blk-exp-close-all.c b/stubs/blk-exp-close-all.c | ||
82 | new file mode 100644 | ||
83 | index XXXXXXX..XXXXXXX | ||
84 | --- /dev/null | ||
85 | +++ b/stubs/blk-exp-close-all.c | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | +#include "qemu/osdep.h" | ||
88 | +#include "block/export.h" | ||
89 | + | ||
90 | +/* Only used in programs that support block exports (libblockdev.fa) */ | ||
91 | +void blk_exp_close_all(void) | ||
92 | +{ | ||
93 | +} | ||
94 | diff --git a/block/export/meson.build b/block/export/meson.build | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/block/export/meson.build | ||
97 | +++ b/block/export/meson.build | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | -block_ss.add(files('export.c')) | ||
100 | -block_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) | ||
101 | +blockdev_ss.add(files('export.c')) | ||
102 | +blockdev_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user-blk-server.c')) | ||
103 | diff --git a/meson.build b/meson.build | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/meson.build | ||
106 | +++ b/meson.build | ||
107 | @@ -XXX,XX +XXX,XX @@ subdir('dump') | ||
108 | |||
109 | block_ss.add(files( | ||
110 | 'block.c', | ||
111 | - 'blockdev-nbd.c', | ||
112 | 'blockjob.c', | ||
113 | 'job.c', | ||
114 | 'qemu-io-cmds.c', | ||
115 | @@ -XXX,XX +XXX,XX @@ subdir('block') | ||
116 | |||
117 | blockdev_ss.add(files( | ||
118 | 'blockdev.c', | ||
119 | + 'blockdev-nbd.c', | ||
120 | 'iothread.c', | ||
121 | 'job-qmp.c', | ||
122 | )) | ||
123 | @@ -XXX,XX +XXX,XX @@ if have_tools | ||
124 | qemu_io = executable('qemu-io', files('qemu-io.c'), | ||
125 | dependencies: [block, qemuutil], install: true) | ||
126 | qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'), | ||
127 | - dependencies: [block, qemuutil], install: true) | ||
128 | + dependencies: [blockdev, qemuutil], install: true) | ||
129 | |||
130 | subdir('storage-daemon') | ||
131 | subdir('contrib/rdmacm-mux') | ||
132 | diff --git a/nbd/meson.build b/nbd/meson.build | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/nbd/meson.build | ||
135 | +++ b/nbd/meson.build | ||
136 | @@ -XXX,XX +XXX,XX @@ | ||
137 | block_ss.add(files( | ||
138 | 'client.c', | ||
139 | 'common.c', | ||
140 | +)) | ||
141 | +blockdev_ss.add(files( | ||
142 | 'server.c', | ||
143 | )) | ||
144 | diff --git a/stubs/meson.build b/stubs/meson.build | ||
145 | index XXXXXXX..XXXXXXX 100644 | ||
146 | --- a/stubs/meson.build | ||
147 | +++ b/stubs/meson.build | ||
148 | @@ -XXX,XX +XXX,XX @@ | ||
149 | stub_ss.add(files('arch_type.c')) | ||
150 | stub_ss.add(files('bdrv-next-monitor-owned.c')) | ||
151 | stub_ss.add(files('blk-commit-all.c')) | ||
152 | +stub_ss.add(files('blk-exp-close-all.c')) | ||
153 | stub_ss.add(files('blockdev-close-all-bdrv-states.c')) | ||
154 | stub_ss.add(files('change-state-handler.c')) | ||
155 | stub_ss.add(files('cmos.c')) | ||
156 | -- | ||
157 | 2.26.2 | ||
158 | diff view generated by jsdifflib |
1 | A few block drivers will set the BDS read_only flag from their | 1 | Make it possible to specify the iothread where the export will run. By |
---|---|---|---|
2 | .bdrv_open() function. This means the bs->read_only flag could | 2 | default the block node can be moved to other AioContexts later and the |
3 | be set after we enable copy_on_read, as the BDRV_O_COPY_ON_READ | 3 | export will follow. The fixed-iothread option forces strict behavior |
4 | flag check occurs prior to the call to bdrv->bdrv_open(). | 4 | that prevents changing AioContext while the export is active. See the |
5 | QAPI docs for details. | ||
5 | 6 | ||
6 | This adds an error return to bdrv_set_read_only(), and an error will be | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
7 | return if we try to set the BDS to read_only while copy_on_read is | 8 | Message-id: 20200929125516.186715-5-stefanha@redhat.com |
8 | enabled. | 9 | [Fix stray '#' character in block-export.json and add missing "(since: |
10 | 5.2)" as suggested by Eric Blake. | ||
11 | --Stefan] | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | qapi/block-export.json | 11 ++++++++++ | ||
15 | block/export/export.c | 31 +++++++++++++++++++++++++++- | ||
16 | block/export/vhost-user-blk-server.c | 5 ++++- | ||
17 | nbd/server.c | 2 -- | ||
18 | 4 files changed, 45 insertions(+), 4 deletions(-) | ||
9 | 19 | ||
10 | This patch also changes the behavior of vvfat. Before, vvfat could | 20 | diff --git a/qapi/block-export.json b/qapi/block-export.json |
11 | override the drive 'readonly' flag with its own, internal 'rw' flag. | ||
12 | |||
13 | For instance, this -drive parameter would result in a writable image: | ||
14 | |||
15 | "-drive format=vvfat,dir=/tmp/vvfat,rw,if=virtio,readonly=on" | ||
16 | |||
17 | This is not correct. Now, attempting to use the above -drive parameter | ||
18 | will result in an error (i.e., 'rw' is incompatible with 'readonly=on'). | ||
19 | |||
20 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
21 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
23 | Message-id: 0c5b4c1cc2c651471b131f21376dfd5ea24d2196.1491597120.git.jcody@redhat.com | ||
24 | --- | ||
25 | block.c | 10 +++++++++- | ||
26 | block/bochs.c | 5 ++++- | ||
27 | block/cloop.c | 5 ++++- | ||
28 | block/dmg.c | 6 +++++- | ||
29 | block/rbd.c | 11 ++++++++++- | ||
30 | block/vvfat.c | 19 +++++++++++++++---- | ||
31 | include/block/block.h | 2 +- | ||
32 | 7 files changed, 48 insertions(+), 10 deletions(-) | ||
33 | |||
34 | diff --git a/block.c b/block.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block.c | 22 | --- a/qapi/block-export.json |
37 | +++ b/block.c | 23 | +++ b/qapi/block-export.json |
38 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 24 | @@ -XXX,XX +XXX,XX @@ |
39 | } | 25 | # export before completion is signalled. (since: 5.2; |
40 | } | 26 | # default: false) |
41 | 27 | # | |
42 | -void bdrv_set_read_only(BlockDriverState *bs, bool read_only) | 28 | +# @iothread: The name of the iothread object where the export will run. The |
43 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 29 | +# default is to use the thread currently associated with the |
30 | +# block node. (since: 5.2) | ||
31 | +# | ||
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 | ||
34 | +# given, export creation fails if the block node cannot be | ||
35 | +# moved to the iothread. The default is false. (since: 5.2) | ||
36 | +# | ||
37 | # Since: 4.2 | ||
38 | ## | ||
39 | { 'union': 'BlockExportOptions', | ||
40 | 'base': { 'type': 'BlockExportType', | ||
41 | 'id': 'str', | ||
42 | + '*fixed-iothread': 'bool', | ||
43 | + '*iothread': 'str', | ||
44 | 'node-name': 'str', | ||
45 | '*writable': 'bool', | ||
46 | '*writethrough': 'bool' }, | ||
47 | diff --git a/block/export/export.c b/block/export/export.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/block/export/export.c | ||
50 | +++ b/block/export/export.c | ||
51 | @@ -XXX,XX +XXX,XX @@ | ||
52 | |||
53 | #include "block/block.h" | ||
54 | #include "sysemu/block-backend.h" | ||
55 | +#include "sysemu/iothread.h" | ||
56 | #include "block/export.h" | ||
57 | #include "block/nbd.h" | ||
58 | #include "qapi/error.h" | ||
59 | @@ -XXX,XX +XXX,XX @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) | ||
60 | |||
61 | BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | ||
44 | { | 62 | { |
45 | + /* Do not set read_only if copy_on_read is enabled */ | 63 | + bool fixed_iothread = export->has_fixed_iothread && export->fixed_iothread; |
46 | + if (bs->copy_on_read && read_only) { | 64 | const BlockExportDriver *drv; |
47 | + error_setg(errp, "Can't set node '%s' to r/o with copy-on-read enabled", | 65 | BlockExport *exp = NULL; |
48 | + bdrv_get_device_or_node_name(bs)); | 66 | BlockDriverState *bs; |
49 | + return -EINVAL; | 67 | - BlockBackend *blk; |
68 | + BlockBackend *blk = NULL; | ||
69 | AioContext *ctx; | ||
70 | uint64_t perm; | ||
71 | int ret; | ||
72 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | ||
73 | ctx = bdrv_get_aio_context(bs); | ||
74 | aio_context_acquire(ctx); | ||
75 | |||
76 | + if (export->has_iothread) { | ||
77 | + IOThread *iothread; | ||
78 | + AioContext *new_ctx; | ||
79 | + | ||
80 | + iothread = iothread_by_id(export->iothread); | ||
81 | + if (!iothread) { | ||
82 | + error_setg(errp, "iothread \"%s\" not found", export->iothread); | ||
83 | + goto fail; | ||
84 | + } | ||
85 | + | ||
86 | + new_ctx = iothread_get_aio_context(iothread); | ||
87 | + | ||
88 | + ret = bdrv_try_set_aio_context(bs, new_ctx, errp); | ||
89 | + if (ret == 0) { | ||
90 | + aio_context_release(ctx); | ||
91 | + aio_context_acquire(new_ctx); | ||
92 | + ctx = new_ctx; | ||
93 | + } else if (fixed_iothread) { | ||
94 | + goto fail; | ||
95 | + } | ||
50 | + } | 96 | + } |
51 | + | 97 | + |
52 | bs->read_only = read_only; | 98 | /* |
53 | + return 0; | 99 | * Block exports are used for non-shared storage migration. Make sure |
54 | } | 100 | * that BDRV_O_INACTIVE is cleared and the image is ready for write |
55 | 101 | @@ -XXX,XX +XXX,XX @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) | |
56 | void bdrv_get_full_backing_filename_from_filename(const char *backed, | ||
57 | diff --git a/block/bochs.c b/block/bochs.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/block/bochs.c | ||
60 | +++ b/block/bochs.c | ||
61 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
62 | return -EINVAL; | ||
63 | } | 102 | } |
64 | 103 | ||
65 | - bdrv_set_read_only(bs, true); /* no write support yet */ | 104 | blk = blk_new(ctx, perm, BLK_PERM_ALL); |
66 | + ret = bdrv_set_read_only(bs, true, errp); /* no write support yet */ | 105 | + |
67 | + if (ret < 0) { | 106 | + if (!fixed_iothread) { |
68 | + return ret; | 107 | + blk_set_allow_aio_context_change(blk, true); |
69 | + } | ||
70 | |||
71 | ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); | ||
72 | if (ret < 0) { | ||
73 | diff --git a/block/cloop.c b/block/cloop.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/block/cloop.c | ||
76 | +++ b/block/cloop.c | ||
77 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
78 | return -EINVAL; | ||
79 | } | ||
80 | |||
81 | - bdrv_set_read_only(bs, true); | ||
82 | + ret = bdrv_set_read_only(bs, true, errp); | ||
83 | + if (ret < 0) { | ||
84 | + return ret; | ||
85 | + } | ||
86 | |||
87 | /* read header */ | ||
88 | ret = bdrv_pread(bs->file, 128, &s->block_size, 4); | ||
89 | diff --git a/block/dmg.c b/block/dmg.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/block/dmg.c | ||
92 | +++ b/block/dmg.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, | ||
94 | return -EINVAL; | ||
95 | } | ||
96 | |||
97 | + ret = bdrv_set_read_only(bs, true, errp); | ||
98 | + if (ret < 0) { | ||
99 | + return ret; | ||
100 | + } | 108 | + } |
101 | + | 109 | + |
102 | block_module_load_one("dmg-bz2"); | 110 | ret = blk_insert_bs(blk, bs, errp); |
103 | - bdrv_set_read_only(bs, true); | 111 | if (ret < 0) { |
104 | 112 | goto fail; | |
105 | s->n_chunks = 0; | 113 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c |
106 | s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; | ||
107 | diff --git a/block/rbd.c b/block/rbd.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | 114 | index XXXXXXX..XXXXXXX 100644 |
109 | --- a/block/rbd.c | 115 | --- a/block/export/vhost-user-blk-server.c |
110 | +++ b/block/rbd.c | 116 | +++ b/block/export/vhost-user-blk-server.c |
111 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | 117 | @@ -XXX,XX +XXX,XX @@ static const VuDevIface vu_blk_iface = { |
112 | goto failed_shutdown; | 118 | static void blk_aio_attached(AioContext *ctx, void *opaque) |
119 | { | ||
120 | VuBlkExport *vexp = opaque; | ||
121 | + | ||
122 | + vexp->export.ctx = ctx; | ||
123 | vhost_user_server_attach_aio_context(&vexp->vu_server, ctx); | ||
124 | } | ||
125 | |||
126 | static void blk_aio_detach(void *opaque) | ||
127 | { | ||
128 | VuBlkExport *vexp = opaque; | ||
129 | + | ||
130 | vhost_user_server_detach_aio_context(&vexp->vu_server); | ||
131 | + vexp->export.ctx = NULL; | ||
132 | } | ||
133 | |||
134 | static void | ||
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, | ||
137 | logical_block_size); | ||
138 | |||
139 | - blk_set_allow_aio_context_change(exp->blk, true); | ||
140 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | ||
141 | vexp); | ||
142 | |||
143 | diff --git a/nbd/server.c b/nbd/server.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/nbd/server.c | ||
146 | +++ b/nbd/server.c | ||
147 | @@ -XXX,XX +XXX,XX @@ static int nbd_export_create(BlockExport *blk_exp, BlockExportOptions *exp_args, | ||
148 | return ret; | ||
113 | } | 149 | } |
114 | 150 | ||
115 | + /* rbd_open is always r/w */ | 151 | - blk_set_allow_aio_context_change(blk, true); |
116 | r = rbd_open(s->io_ctx, s->name, &s->image, s->snap); | 152 | - |
117 | if (r < 0) { | 153 | QTAILQ_INIT(&exp->clients); |
118 | error_setg_errno(errp, -r, "error reading header from %s", s->name); | 154 | exp->name = g_strdup(arg->name); |
119 | goto failed_open; | 155 | exp->description = g_strdup(arg->description); |
120 | } | ||
121 | |||
122 | - bdrv_set_read_only(bs, (s->snap != NULL)); | ||
123 | + /* If we are using an rbd snapshot, we must be r/o, otherwise | ||
124 | + * leave as-is */ | ||
125 | + if (s->snap != NULL) { | ||
126 | + r = bdrv_set_read_only(bs, true, &local_err); | ||
127 | + if (r < 0) { | ||
128 | + error_propagate(errp, local_err); | ||
129 | + goto failed_open; | ||
130 | + } | ||
131 | + } | ||
132 | |||
133 | qemu_opts_del(opts); | ||
134 | return 0; | ||
135 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/block/vvfat.c | ||
138 | +++ b/block/vvfat.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
140 | |||
141 | s->current_cluster=0xffffffff; | ||
142 | |||
143 | - /* read only is the default for safety */ | ||
144 | - bdrv_set_read_only(bs, true); | ||
145 | s->qcow = NULL; | ||
146 | s->qcow_filename = NULL; | ||
147 | s->fat2 = NULL; | ||
148 | @@ -XXX,XX +XXX,XX @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, | ||
149 | s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1); | ||
150 | |||
151 | if (qemu_opt_get_bool(opts, "rw", false)) { | ||
152 | - ret = enable_write_target(bs, errp); | ||
153 | + if (!bdrv_is_read_only(bs)) { | ||
154 | + ret = enable_write_target(bs, errp); | ||
155 | + if (ret < 0) { | ||
156 | + goto fail; | ||
157 | + } | ||
158 | + } else { | ||
159 | + ret = -EPERM; | ||
160 | + error_setg(errp, | ||
161 | + "Unable to set VVFAT to 'rw' when drive is read-only"); | ||
162 | + goto fail; | ||
163 | + } | ||
164 | + } else { | ||
165 | + /* read only is the default for safety */ | ||
166 | + ret = bdrv_set_read_only(bs, true, &local_err); | ||
167 | if (ret < 0) { | ||
168 | + error_propagate(errp, local_err); | ||
169 | goto fail; | ||
170 | } | ||
171 | - bdrv_set_read_only(bs, false); | ||
172 | } | ||
173 | |||
174 | bs->total_sectors = cyls * heads * secs; | ||
175 | diff --git a/include/block/block.h b/include/block/block.h | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/include/block/block.h | ||
178 | +++ b/include/block/block.h | ||
179 | @@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, | ||
180 | int64_t sector_num, int nb_sectors, int *pnum); | ||
181 | |||
182 | bool bdrv_is_read_only(BlockDriverState *bs); | ||
183 | -void bdrv_set_read_only(BlockDriverState *bs, bool read_only); | ||
184 | +int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | ||
185 | bool bdrv_is_sg(BlockDriverState *bs); | ||
186 | bool bdrv_is_inserted(BlockDriverState *bs); | ||
187 | int bdrv_media_changed(BlockDriverState *bs); | ||
188 | -- | 156 | -- |
189 | 2.9.3 | 157 | 2.26.2 |
190 | 158 | ||
191 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
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 | ||
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 | ||
5 | QEMU. | ||
1 | 6 | ||
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 | ||
9 | needed. | ||
10 | |||
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 | ||
13 | configuration space field. It does not promise that there is more than 1 | ||
14 | virtqueue, so we can set it unconditionally. | ||
15 | |||
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 | ||
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. | ||
20 | |||
21 | An automated test is included in the next commit. | ||
22 | |||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
24 | Acked-by: Markus Armbruster <armbru@redhat.com> | ||
25 | Message-id: 20201001144604.559733-2-stefanha@redhat.com | ||
26 | [Fixed accidental tab characters as suggested by Markus Armbruster | ||
27 | --Stefan] | ||
28 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
29 | --- | ||
30 | qapi/block-export.json | 10 +++++++--- | ||
31 | block/export/vhost-user-blk-server.c | 24 ++++++++++++++++++------ | ||
32 | 2 files changed, 25 insertions(+), 9 deletions(-) | ||
33 | |||
34 | diff --git a/qapi/block-export.json b/qapi/block-export.json | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/qapi/block-export.json | ||
37 | +++ b/qapi/block-export.json | ||
38 | @@ -XXX,XX +XXX,XX @@ | ||
39 | # SocketAddress types are supported. Passed fds must be UNIX domain | ||
40 | # sockets. | ||
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 | ||
43 | +# to 1. | ||
44 | # | ||
45 | # Since: 5.2 | ||
46 | ## | ||
47 | { 'struct': 'BlockExportOptionsVhostUserBlk', | ||
48 | - 'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } } | ||
49 | + 'data': { 'addr': 'SocketAddress', | ||
50 | + '*logical-block-size': 'size', | ||
51 | + '*num-queues': 'uint16'} } | ||
52 | |||
53 | ## | ||
54 | # @NbdServerAddOptions: | ||
55 | @@ -XXX,XX +XXX,XX @@ | ||
56 | { 'union': 'BlockExportOptions', | ||
57 | 'base': { 'type': 'BlockExportType', | ||
58 | 'id': 'str', | ||
59 | - '*fixed-iothread': 'bool', | ||
60 | - '*iothread': 'str', | ||
61 | + '*fixed-iothread': 'bool', | ||
62 | + '*iothread': 'str', | ||
63 | 'node-name': 'str', | ||
64 | '*writable': 'bool', | ||
65 | '*writethrough': 'bool' }, | ||
66 | diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/block/export/vhost-user-blk-server.c | ||
69 | +++ b/block/export/vhost-user-blk-server.c | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | #include "util/block-helpers.h" | ||
72 | |||
73 | enum { | ||
74 | - VHOST_USER_BLK_MAX_QUEUES = 1, | ||
75 | + VHOST_USER_BLK_NUM_QUEUES_DEFAULT = 1, | ||
76 | }; | ||
77 | struct virtio_blk_inhdr { | ||
78 | unsigned char status; | ||
79 | @@ -XXX,XX +XXX,XX @@ static uint64_t vu_blk_get_features(VuDev *dev) | ||
80 | 1ull << VIRTIO_BLK_F_DISCARD | | ||
81 | 1ull << VIRTIO_BLK_F_WRITE_ZEROES | | ||
82 | 1ull << VIRTIO_BLK_F_CONFIG_WCE | | ||
83 | + 1ull << VIRTIO_BLK_F_MQ | | ||
84 | 1ull << VIRTIO_F_VERSION_1 | | ||
85 | 1ull << VIRTIO_RING_F_INDIRECT_DESC | | ||
86 | 1ull << VIRTIO_RING_F_EVENT_IDX | | ||
87 | @@ -XXX,XX +XXX,XX @@ static void blk_aio_detach(void *opaque) | ||
88 | |||
89 | static void | ||
90 | vu_blk_initialize_config(BlockDriverState *bs, | ||
91 | - struct virtio_blk_config *config, uint32_t blk_size) | ||
92 | + struct virtio_blk_config *config, | ||
93 | + uint32_t blk_size, | ||
94 | + uint16_t num_queues) | ||
95 | { | ||
96 | config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; | ||
97 | config->blk_size = blk_size; | ||
98 | @@ -XXX,XX +XXX,XX @@ vu_blk_initialize_config(BlockDriverState *bs, | ||
99 | config->seg_max = 128 - 2; | ||
100 | config->min_io_size = 1; | ||
101 | config->opt_io_size = 1; | ||
102 | - config->num_queues = VHOST_USER_BLK_MAX_QUEUES; | ||
103 | + config->num_queues = num_queues; | ||
104 | config->max_discard_sectors = 32768; | ||
105 | config->max_discard_seg = 1; | ||
106 | config->discard_sector_alignment = config->blk_size >> 9; | ||
107 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | ||
108 | BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk; | ||
109 | Error *local_err = NULL; | ||
110 | uint64_t logical_block_size; | ||
111 | + uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT; | ||
112 | |||
113 | vexp->writable = opts->writable; | ||
114 | vexp->blkcfg.wce = 0; | ||
115 | @@ -XXX,XX +XXX,XX @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, | ||
116 | } | ||
117 | vexp->blk_size = logical_block_size; | ||
118 | blk_set_guest_block_size(exp->blk, logical_block_size); | ||
119 | + | ||
120 | + if (vu_opts->has_num_queues) { | ||
121 | + num_queues = vu_opts->num_queues; | ||
122 | + } | ||
123 | + if (num_queues == 0) { | ||
124 | + error_setg(errp, "num-queues must be greater than 0"); | ||
125 | + return -EINVAL; | ||
126 | + } | ||
127 | + | ||
128 | vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg, | ||
129 | - logical_block_size); | ||
130 | + logical_block_size, num_queues); | ||
131 | |||
132 | blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, | ||
133 | vexp); | ||
134 | |||
135 | if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, | ||
136 | - VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface, | ||
137 | - errp)) { | ||
138 | + num_queues, &vu_blk_iface, errp)) { | ||
139 | blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, | ||
140 | blk_aio_detach, vexp); | ||
141 | return -EADDRNOTAVAIL; | ||
142 | -- | ||
143 | 2.26.2 | ||
144 | diff view generated by jsdifflib |
1 | Move bdrv_is_read_only() up with its friends. | 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(-) | ||
2 | 7 | ||
3 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c |
4 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
5 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
6 | Message-id: 73b2399459760c32506f9407efb9dddb3a2789de.1491597120.git.jcody@redhat.com | ||
7 | --- | ||
8 | block.c | 10 +++++----- | ||
9 | 1 file changed, 5 insertions(+), 5 deletions(-) | ||
10 | |||
11 | diff --git a/block.c b/block.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/block.c | 10 | --- a/tests/qtest/vhost-user-blk-test.c |
14 | +++ b/block.c | 11 | +++ b/tests/qtest/vhost-user-blk-test.c |
15 | @@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size, | 12 | @@ -XXX,XX +XXX,XX @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc) |
16 | } | 13 | qpci_unplug_acpi_device_test(qts, "drv1", PCI_SLOT_HP); |
17 | } | 14 | } |
18 | 15 | ||
19 | +bool bdrv_is_read_only(BlockDriverState *bs) | 16 | +static void multiqueue(void *obj, void *data, QGuestAllocator *t_alloc) |
20 | +{ | 17 | +{ |
21 | + return bs->read_only; | 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); | ||
22 | +} | 75 | +} |
23 | + | 76 | + |
24 | int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) | 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) | ||
25 | { | 87 | { |
26 | /* Do not set read_only if copy_on_read is enabled */ | 88 | const char *vhost_user_blk_bin = qtest_qemu_storage_daemon_binary(); |
27 | @@ -XXX,XX +XXX,XX @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) | 89 | int fd, qmp_fd, i; |
28 | *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; | 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; | ||
29 | } | 108 | } |
30 | 109 | ||
31 | -bool bdrv_is_read_only(BlockDriverState *bs) | 110 | @@ -XXX,XX +XXX,XX @@ static void *vhost_user_blk_test_setup(GString *cmd_line, void *arg) |
32 | -{ | 111 | static void *vhost_user_blk_hotplug_test_setup(GString *cmd_line, void *arg) |
33 | - return bs->read_only; | ||
34 | -} | ||
35 | - | ||
36 | bool bdrv_is_sg(BlockDriverState *bs) | ||
37 | { | 112 | { |
38 | return bs->sg; | 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); | ||
39 | -- | 135 | -- |
40 | 2.9.3 | 136 | 2.26.2 |
41 | 137 | ||
42 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | bdrv_co_block_status_above has several design problems with handling | ||
4 | short backing files: | ||
5 | |||
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 | ||
8 | which produces these after-EOF zeros is inside requested backing | ||
9 | sequence. | ||
10 | |||
11 | 2. With want_zero=false, it may return pnum=0 prior to actual EOF, | ||
12 | because of EOF of short backing file. | ||
13 | |||
14 | Fix these things, making logic about short backing files clearer. | ||
15 | |||
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 | ||
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). | ||
20 | |||
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 | ||
23 | vs go-to-backing. | ||
24 | |||
25 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
26 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
27 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
28 | Message-id: 20200924194003.22080-2-vsementsov@virtuozzo.com | ||
29 | [Fix s/comes/come/ as suggested by Eric Blake | ||
30 | --Stefan] | ||
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
32 | --- | ||
33 | block/io.c | 68 ++++++++++++++++++++++++++++++++++++++++----------- | ||
34 | block/qcow2.c | 16 ++++++++++-- | ||
35 | 2 files changed, 68 insertions(+), 16 deletions(-) | ||
36 | |||
37 | diff --git a/block/io.c b/block/io.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/block/io.c | ||
40 | +++ b/block/io.c | ||
41 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | ||
42 | int64_t *map, | ||
43 | BlockDriverState **file) | ||
44 | { | ||
45 | + int ret; | ||
46 | BlockDriverState *p; | ||
47 | - int ret = 0; | ||
48 | - bool first = true; | ||
49 | + int64_t eof = 0; | ||
50 | |||
51 | assert(bs != base); | ||
52 | - for (p = bs; p != base; p = bdrv_filter_or_cow_bs(p)) { | ||
53 | + | ||
54 | + ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); | ||
55 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { | ||
56 | + return ret; | ||
57 | + } | ||
58 | + | ||
59 | + if (ret & BDRV_BLOCK_EOF) { | ||
60 | + eof = offset + *pnum; | ||
61 | + } | ||
62 | + | ||
63 | + assert(*pnum <= bytes); | ||
64 | + bytes = *pnum; | ||
65 | + | ||
66 | + for (p = bdrv_filter_or_cow_bs(bs); p != base; | ||
67 | + p = bdrv_filter_or_cow_bs(p)) | ||
68 | + { | ||
69 | ret = bdrv_co_block_status(p, want_zero, offset, bytes, pnum, map, | ||
70 | file); | ||
71 | if (ret < 0) { | ||
72 | - break; | ||
73 | + return ret; | ||
74 | } | ||
75 | - if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { | ||
76 | + if (*pnum == 0) { | ||
77 | /* | ||
78 | - * Reading beyond the end of the file continues to read | ||
79 | - * zeroes, but we can only widen the result to the | ||
80 | - * unallocated length we learned from an earlier | ||
81 | - * iteration. | ||
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 | ||
84 | + * were allocated at this layer. | ||
85 | + * | ||
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 | ||
88 | + * below. | ||
89 | */ | ||
90 | + assert(ret & BDRV_BLOCK_EOF); | ||
91 | *pnum = bytes; | ||
92 | + if (file) { | ||
93 | + *file = p; | ||
94 | + } | ||
95 | + ret = BDRV_BLOCK_ZERO | BDRV_BLOCK_ALLOCATED; | ||
96 | + break; | ||
97 | } | ||
98 | - if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { | ||
99 | + if (ret & BDRV_BLOCK_ALLOCATED) { | ||
100 | + /* | ||
101 | + * We've found the node and the status, we must break. | ||
102 | + * | ||
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 | ||
105 | + * below. | ||
106 | + */ | ||
107 | + ret &= ~BDRV_BLOCK_EOF; | ||
108 | break; | ||
109 | } | ||
110 | - /* [offset, pnum] unallocated on this layer, which could be only | ||
111 | - * the first part of [offset, bytes]. */ | ||
112 | - bytes = MIN(bytes, *pnum); | ||
113 | - first = false; | ||
114 | + | ||
115 | + /* | ||
116 | + * OK, [offset, offset + *pnum) region is unallocated on this layer, | ||
117 | + * let's continue the diving. | ||
118 | + */ | ||
119 | + assert(*pnum <= bytes); | ||
120 | + bytes = *pnum; | ||
121 | + } | ||
122 | + | ||
123 | + if (offset + *pnum == eof) { | ||
124 | + ret |= BDRV_BLOCK_EOF; | ||
125 | } | ||
126 | + | ||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/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) | ||
135 | if (!bytes) { | ||
136 | return true; | ||
137 | } | ||
138 | - res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); | ||
139 | - return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes; | ||
140 | + | ||
141 | + /* | ||
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 | ||
144 | + * the whole backing chain, and zeros which come because of a short | ||
145 | + * backing file. So, we need a loop. | ||
146 | + */ | ||
147 | + do { | ||
148 | + res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); | ||
149 | + offset += nr; | ||
150 | + bytes -= nr; | ||
151 | + } while (res >= 0 && (res & BDRV_BLOCK_ZERO) && nr && bytes); | ||
152 | + | ||
153 | + return res >= 0 && (res & BDRV_BLOCK_ZERO) && bytes == 0; | ||
154 | } | ||
155 | |||
156 | static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, | ||
157 | -- | ||
158 | 2.26.2 | ||
159 | diff view generated by jsdifflib |
1 | From: Ashish Mittal <ashmit602@gmail.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | These changes use a vxhs test server that is a part of the following | 3 | In order to reuse bdrv_common_block_status_above in |
4 | repository: | 4 | bdrv_is_allocated_above, let's support include_base parameter. |
5 | https://github.com/VeritasHyperScale/libqnio.git | ||
6 | 5 | ||
7 | Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com> | 6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
9 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> |
10 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | Message-id: 20200924194003.22080-3-vsementsov@virtuozzo.com |
11 | Message-id: 1491277689-24949-3-git-send-email-Ashish.Mittal@veritas.com | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 11 | --- |
13 | tests/qemu-iotests/common | 6 ++++++ | 12 | block/coroutines.h | 2 ++ |
14 | tests/qemu-iotests/common.config | 13 +++++++++++++ | 13 | block/io.c | 21 ++++++++++++++------- |
15 | tests/qemu-iotests/common.filter | 1 + | 14 | 2 files changed, 16 insertions(+), 7 deletions(-) |
16 | tests/qemu-iotests/common.rc | 19 +++++++++++++++++++ | ||
17 | 4 files changed, 39 insertions(+) | ||
18 | 15 | ||
19 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | 16 | diff --git a/block/coroutines.h b/block/coroutines.h |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/tests/qemu-iotests/common | 18 | --- a/block/coroutines.h |
22 | +++ b/tests/qemu-iotests/common | 19 | +++ b/block/coroutines.h |
23 | @@ -XXX,XX +XXX,XX @@ check options | 20 | @@ -XXX,XX +XXX,XX @@ bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, |
24 | -ssh test ssh | 21 | int coroutine_fn |
25 | -nfs test nfs | 22 | bdrv_co_common_block_status_above(BlockDriverState *bs, |
26 | -luks test luks | 23 | BlockDriverState *base, |
27 | + -vxhs test vxhs | 24 | + bool include_base, |
28 | -xdiff graphical mode diff | 25 | bool want_zero, |
29 | -nocache use O_DIRECT on backing file | 26 | int64_t offset, |
30 | -misalign misalign memory allocations | 27 | int64_t bytes, |
31 | @@ -XXX,XX +XXX,XX @@ testlist options | 28 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, |
32 | xpand=false | 29 | int generated_co_wrapper |
33 | ;; | 30 | bdrv_common_block_status_above(BlockDriverState *bs, |
34 | 31 | BlockDriverState *base, | |
35 | + -vxhs) | 32 | + bool include_base, |
36 | + IMGPROTO=vxhs | 33 | bool want_zero, |
37 | + xpand=false | 34 | int64_t offset, |
38 | + ;; | 35 | int64_t bytes, |
36 | diff --git a/block/io.c b/block/io.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block/io.c | ||
39 | +++ b/block/io.c | ||
40 | @@ -XXX,XX +XXX,XX @@ early_out: | ||
41 | int coroutine_fn | ||
42 | bdrv_co_common_block_status_above(BlockDriverState *bs, | ||
43 | BlockDriverState *base, | ||
44 | + bool include_base, | ||
45 | bool want_zero, | ||
46 | int64_t offset, | ||
47 | int64_t bytes, | ||
48 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | ||
49 | BlockDriverState *p; | ||
50 | int64_t eof = 0; | ||
51 | |||
52 | - assert(bs != base); | ||
53 | + assert(include_base || bs != base); | ||
54 | + assert(!include_base || base); /* Can't include NULL base */ | ||
55 | |||
56 | ret = bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, file); | ||
57 | - if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED) { | ||
58 | + if (ret < 0 || *pnum == 0 || ret & BDRV_BLOCK_ALLOCATED || bs == base) { | ||
59 | return ret; | ||
60 | } | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | ||
63 | assert(*pnum <= bytes); | ||
64 | bytes = *pnum; | ||
65 | |||
66 | - for (p = bdrv_filter_or_cow_bs(bs); p != base; | ||
67 | + for (p = bdrv_filter_or_cow_bs(bs); include_base || p != base; | ||
68 | p = bdrv_filter_or_cow_bs(p)) | ||
69 | { | ||
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, | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | + if (p == base) { | ||
76 | + assert(include_base); | ||
77 | + break; | ||
78 | + } | ||
39 | + | 79 | + |
40 | -ssh) | 80 | /* |
41 | IMGPROTO=ssh | 81 | * OK, [offset, offset + *pnum) region is unallocated on this layer, |
42 | xpand=false | 82 | * let's continue the diving. |
43 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | 83 | @@ -XXX,XX +XXX,XX @@ int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, |
44 | index XXXXXXX..XXXXXXX 100644 | 84 | int64_t offset, int64_t bytes, int64_t *pnum, |
45 | --- a/tests/qemu-iotests/common.config | 85 | int64_t *map, BlockDriverState **file) |
46 | +++ b/tests/qemu-iotests/common.config | ||
47 | @@ -XXX,XX +XXX,XX @@ if [ -z "$QEMU_NBD_PROG" ]; then | ||
48 | export QEMU_NBD_PROG="`set_prog_path qemu-nbd`" | ||
49 | fi | ||
50 | |||
51 | +if [ -z "$QEMU_VXHS_PROG" ]; then | ||
52 | + export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | ||
53 | +fi | ||
54 | + | ||
55 | _qemu_wrapper() | ||
56 | { | 86 | { |
57 | ( | 87 | - return bdrv_common_block_status_above(bs, base, true, offset, bytes, |
58 | @@ -XXX,XX +XXX,XX @@ _qemu_nbd_wrapper() | 88 | + return bdrv_common_block_status_above(bs, base, false, true, offset, bytes, |
59 | ) | 89 | pnum, map, file); |
60 | } | 90 | } |
61 | 91 | ||
62 | +_qemu_vxhs_wrapper() | 92 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, |
63 | +{ | 93 | int ret; |
64 | + ( | 94 | int64_t dummy; |
65 | + echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" | 95 | |
66 | + exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" | 96 | - ret = bdrv_common_block_status_above(bs, bdrv_filter_or_cow_bs(bs), false, |
67 | + ) | 97 | - offset, bytes, pnum ? pnum : &dummy, |
68 | +} | 98 | - NULL, NULL); |
69 | + | 99 | + ret = bdrv_common_block_status_above(bs, bs, true, false, offset, |
70 | export QEMU=_qemu_wrapper | 100 | + bytes, pnum ? pnum : &dummy, NULL, |
71 | export QEMU_IMG=_qemu_img_wrapper | 101 | + NULL); |
72 | export QEMU_IO=_qemu_io_wrapper | 102 | if (ret < 0) { |
73 | export QEMU_NBD=_qemu_nbd_wrapper | 103 | return ret; |
74 | +export QEMU_VXHS=_qemu_vxhs_wrapper | 104 | } |
75 | |||
76 | QEMU_IMG_EXTRA_ARGS= | ||
77 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
78 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/tests/qemu-iotests/common.filter | ||
81 | +++ b/tests/qemu-iotests/common.filter | ||
82 | @@ -XXX,XX +XXX,XX @@ _filter_img_info() | ||
83 | -e "s#$TEST_DIR#TEST_DIR#g" \ | ||
84 | -e "s#$IMGFMT#IMGFMT#g" \ | ||
85 | -e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \ | ||
86 | + -e 's#json.*vdisk-id.*vxhs"}}#TEST_DIR/t.IMGFMT#' \ | ||
87 | -e "/encrypted: yes/d" \ | ||
88 | -e "/cluster_size: [0-9]\\+/d" \ | ||
89 | -e "/table_size: [0-9]\\+/d" \ | ||
90 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/tests/qemu-iotests/common.rc | ||
93 | +++ b/tests/qemu-iotests/common.rc | ||
94 | @@ -XXX,XX +XXX,XX @@ else | ||
95 | elif [ "$IMGPROTO" = "nfs" ]; then | ||
96 | TEST_DIR="nfs://127.0.0.1/$TEST_DIR" | ||
97 | TEST_IMG=$TEST_DIR/t.$IMGFMT | ||
98 | + elif [ "$IMGPROTO" = "vxhs" ]; then | ||
99 | + TEST_IMG_FILE=$TEST_DIR/t.$IMGFMT | ||
100 | + TEST_IMG="vxhs://127.0.0.1:9999/t.$IMGFMT" | ||
101 | else | ||
102 | TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT | ||
103 | fi | ||
104 | @@ -XXX,XX +XXX,XX @@ _make_test_img() | ||
105 | eval "$QEMU_NBD -v -t -b 127.0.0.1 -p 10810 -f $IMGFMT $TEST_IMG_FILE >/dev/null &" | ||
106 | sleep 1 # FIXME: qemu-nbd needs to be listening before we continue | ||
107 | fi | ||
108 | + | ||
109 | + # Start QNIO server on image directory for vxhs protocol | ||
110 | + if [ $IMGPROTO = "vxhs" ]; then | ||
111 | + eval "$QEMU_VXHS -d $TEST_DIR > /dev/null &" | ||
112 | + sleep 1 # Wait for server to come up. | ||
113 | + fi | ||
114 | } | ||
115 | |||
116 | _rm_test_img() | ||
117 | @@ -XXX,XX +XXX,XX @@ _cleanup_test_img() | ||
118 | fi | ||
119 | rm -f "$TEST_IMG_FILE" | ||
120 | ;; | ||
121 | + vxhs) | ||
122 | + if [ -f "${TEST_DIR}/qemu-vxhs.pid" ]; then | ||
123 | + local QEMU_VXHS_PID | ||
124 | + read QEMU_VXHS_PID < "${TEST_DIR}/qemu-vxhs.pid" | ||
125 | + kill ${QEMU_VXHS_PID} >/dev/null 2>&1 | ||
126 | + rm -f "${TEST_DIR}/qemu-vxhs.pid" | ||
127 | + fi | ||
128 | + rm -f "$TEST_IMG_FILE" | ||
129 | + ;; | ||
130 | + | ||
131 | file) | ||
132 | _rm_test_img "$TEST_DIR/t.$IMGFMT" | ||
133 | _rm_test_img "$TEST_DIR/t.$IMGFMT.orig" | ||
134 | -- | 105 | -- |
135 | 2.9.3 | 106 | 2.26.2 |
136 | 107 | ||
137 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
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 | ||
5 | include_base == false and still bs == base (for ex. from img_rebase()). | ||
6 | |||
7 | So, support this corner case. | ||
8 | |||
9 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
13 | Message-id: 20200924194003.22080-4-vsementsov@virtuozzo.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | ||
16 | block/io.c | 6 +++++- | ||
17 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/block/io.c b/block/io.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block/io.c | ||
22 | +++ b/block/io.c | ||
23 | @@ -XXX,XX +XXX,XX @@ bdrv_co_common_block_status_above(BlockDriverState *bs, | ||
24 | BlockDriverState *p; | ||
25 | int64_t eof = 0; | ||
26 | |||
27 | - assert(include_base || bs != base); | ||
28 | assert(!include_base || base); /* Can't include NULL base */ | ||
29 | |||
30 | + if (!include_base && bs == base) { | ||
31 | + *pnum = bytes; | ||
32 | + return 0; | ||
33 | + } | ||
34 | + | ||
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) { | ||
37 | return ret; | ||
38 | -- | ||
39 | 2.26.2 | ||
40 | diff view generated by jsdifflib |
1 | Update 'clientname' to be 'user', which tracks better with both | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | the QAPI and rados variable naming. | ||
3 | 2 | ||
4 | Update 'name' to be 'image_name', as it indicates the rbd image. | 3 | bdrv_is_allocated_above wrongly handles short backing files: it reports |
5 | Naming it 'image' would have been ideal, but we are using that for | 4 | after-EOF space as UNALLOCATED which is wrong, as on read the data is |
6 | the rados_image_t value returned by rbd_open(). | 5 | generated on the level of short backing file (if all overlays have |
6 | unallocated areas at that place). | ||
7 | 7 | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Reusing bdrv_common_block_status_above fixes the issue and unifies code |
9 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | path. |
10 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | |
11 | Message-id: b7ec1fb2e1cf36f9b6911631447a5b0422590b7d.1491597120.git.jcody@redhat.com | 11 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
13 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
14 | Message-id: 20200924194003.22080-5-vsementsov@virtuozzo.com | ||
15 | [Fix s/has/have/ as suggested by Eric Blake. Fix s/area/areas/. | ||
16 | --Stefan] | ||
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | 18 | --- |
13 | block/rbd.c | 33 +++++++++++++++++---------------- | 19 | block/io.c | 43 +++++-------------------------------------- |
14 | 1 file changed, 17 insertions(+), 16 deletions(-) | 20 | 1 file changed, 5 insertions(+), 38 deletions(-) |
15 | 21 | ||
16 | diff --git a/block/rbd.c b/block/rbd.c | 22 | diff --git a/block/io.c b/block/io.c |
17 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/rbd.c | 24 | --- a/block/io.c |
19 | +++ b/block/rbd.c | 25 | +++ b/block/io.c |
20 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVRBDState { | 26 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, |
21 | rados_t cluster; | 27 | * at 'offset + *pnum' may return the same allocation status (in other |
22 | rados_ioctx_t io_ctx; | 28 | * words, the result is not necessarily the maximum possible range); |
23 | rbd_image_t image; | 29 | * but 'pnum' will only be 0 when end of file is reached. |
24 | - char *name; | 30 | - * |
25 | + char *image_name; | 31 | */ |
26 | char *snap; | 32 | int bdrv_is_allocated_above(BlockDriverState *top, |
27 | } BDRVRBDState; | 33 | BlockDriverState *base, |
28 | 34 | bool include_base, int64_t offset, | |
29 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 35 | int64_t bytes, int64_t *pnum) |
30 | int64_t bytes = 0; | 36 | { |
31 | int64_t objsize; | 37 | - BlockDriverState *intermediate; |
32 | int obj_order = 0; | 38 | - int ret; |
33 | - const char *pool, *name, *conf, *clientname, *keypairs; | 39 | - int64_t n = bytes; |
34 | + const char *pool, *image_name, *conf, *user, *keypairs; | 40 | - |
35 | const char *secretid; | 41 | - assert(base || !include_base); |
36 | rados_t cluster; | 42 | - |
37 | rados_ioctx_t io_ctx; | 43 | - intermediate = top; |
38 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 44 | - while (include_base || intermediate != base) { |
39 | */ | 45 | - int64_t pnum_inter; |
40 | pool = qdict_get_try_str(options, "pool"); | 46 | - int64_t size_inter; |
41 | conf = qdict_get_try_str(options, "conf"); | 47 | - |
42 | - clientname = qdict_get_try_str(options, "user"); | 48 | - assert(intermediate); |
43 | - name = qdict_get_try_str(options, "image"); | 49 | - ret = bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter); |
44 | + user = qdict_get_try_str(options, "user"); | 50 | - if (ret < 0) { |
45 | + image_name = qdict_get_try_str(options, "image"); | 51 | - return ret; |
46 | keypairs = qdict_get_try_str(options, "=keyvalue-pairs"); | 52 | - } |
47 | 53 | - if (ret) { | |
48 | - ret = rados_create(&cluster, clientname); | 54 | - *pnum = pnum_inter; |
49 | + ret = rados_create(&cluster, user); | 55 | - return 1; |
50 | if (ret < 0) { | 56 | - } |
51 | error_setg_errno(errp, -ret, "error initializing"); | 57 | - |
52 | goto exit; | 58 | - size_inter = bdrv_getlength(intermediate); |
53 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp) | 59 | - if (size_inter < 0) { |
54 | goto shutdown; | 60 | - return size_inter; |
61 | - } | ||
62 | - if (n > pnum_inter && | ||
63 | - (intermediate == top || offset + pnum_inter < size_inter)) { | ||
64 | - n = pnum_inter; | ||
65 | - } | ||
66 | - | ||
67 | - if (intermediate == base) { | ||
68 | - break; | ||
69 | - } | ||
70 | - | ||
71 | - intermediate = bdrv_filter_or_cow_bs(intermediate); | ||
72 | + int ret = bdrv_common_block_status_above(top, base, include_base, false, | ||
73 | + offset, bytes, pnum, NULL, NULL); | ||
74 | + if (ret < 0) { | ||
75 | + return ret; | ||
55 | } | 76 | } |
56 | 77 | ||
57 | - ret = rbd_create(io_ctx, name, bytes, &obj_order); | 78 | - *pnum = n; |
58 | + ret = rbd_create(io_ctx, image_name, bytes, &obj_order); | 79 | - return 0; |
59 | if (ret < 0) { | 80 | + return !!(ret & BDRV_BLOCK_ALLOCATED); |
60 | error_setg_errno(errp, -ret, "error rbd create"); | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
63 | Error **errp) | ||
64 | { | ||
65 | BDRVRBDState *s = bs->opaque; | ||
66 | - const char *pool, *snap, *conf, *clientname, *name, *keypairs; | ||
67 | + const char *pool, *snap, *conf, *user, *image_name, *keypairs; | ||
68 | const char *secretid; | ||
69 | QemuOpts *opts; | ||
70 | Error *local_err = NULL; | ||
71 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
72 | pool = qemu_opt_get(opts, "pool"); | ||
73 | conf = qemu_opt_get(opts, "conf"); | ||
74 | snap = qemu_opt_get(opts, "snapshot"); | ||
75 | - clientname = qemu_opt_get(opts, "user"); | ||
76 | - name = qemu_opt_get(opts, "image"); | ||
77 | + user = qemu_opt_get(opts, "user"); | ||
78 | + image_name = qemu_opt_get(opts, "image"); | ||
79 | keypairs = qemu_opt_get(opts, "=keyvalue-pairs"); | ||
80 | |||
81 | - if (!pool || !name) { | ||
82 | + if (!pool || !image_name) { | ||
83 | error_setg(errp, "Parameters 'pool' and 'image' are required"); | ||
84 | r = -EINVAL; | ||
85 | goto failed_opts; | ||
86 | } | ||
87 | |||
88 | - r = rados_create(&s->cluster, clientname); | ||
89 | + r = rados_create(&s->cluster, user); | ||
90 | if (r < 0) { | ||
91 | error_setg_errno(errp, -r, "error initializing"); | ||
92 | goto failed_opts; | ||
93 | } | ||
94 | |||
95 | s->snap = g_strdup(snap); | ||
96 | - s->name = g_strdup(name); | ||
97 | + s->image_name = g_strdup(image_name); | ||
98 | |||
99 | /* try default location when conf=NULL, but ignore failure */ | ||
100 | r = rados_conf_read_file(s->cluster, conf); | ||
101 | @@ -XXX,XX +XXX,XX @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags, | ||
102 | } | ||
103 | |||
104 | /* rbd_open is always r/w */ | ||
105 | - r = rbd_open(s->io_ctx, s->name, &s->image, s->snap); | ||
106 | + r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap); | ||
107 | if (r < 0) { | ||
108 | - error_setg_errno(errp, -r, "error reading header from %s", s->name); | ||
109 | + error_setg_errno(errp, -r, "error reading header from %s", | ||
110 | + s->image_name); | ||
111 | goto failed_open; | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ failed_open: | ||
115 | failed_shutdown: | ||
116 | rados_shutdown(s->cluster); | ||
117 | g_free(s->snap); | ||
118 | - g_free(s->name); | ||
119 | + g_free(s->image_name); | ||
120 | failed_opts: | ||
121 | qemu_opts_del(opts); | ||
122 | g_free(mon_host); | ||
123 | @@ -XXX,XX +XXX,XX @@ static void qemu_rbd_close(BlockDriverState *bs) | ||
124 | rbd_close(s->image); | ||
125 | rados_ioctx_destroy(s->io_ctx); | ||
126 | g_free(s->snap); | ||
127 | - g_free(s->name); | ||
128 | + g_free(s->image_name); | ||
129 | rados_shutdown(s->cluster); | ||
130 | } | 81 | } |
131 | 82 | ||
83 | int coroutine_fn | ||
132 | -- | 84 | -- |
133 | 2.9.3 | 85 | 2.26.2 |
134 | 86 | ||
135 | diff view generated by jsdifflib |
1 | For the tests that use the common.qemu functions for running a QEMU | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | process, _cleanup_qemu must be called in the exit function. | ||
3 | 2 | ||
4 | If it is not, if the qemu process aborts, then not all of the droppings | 3 | These cases are fixed by previous patches around block_status and |
5 | are cleaned up (e.g. pidfile, fifos). | 4 | is_allocated. |
6 | 5 | ||
7 | This updates those tests that did not have a cleanup in qemu-iotests. | 6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
9 | Message-id: 20200924194003.22080-6-vsementsov@virtuozzo.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/274 | 20 +++++++++++ | ||
13 | tests/qemu-iotests/274.out | 68 ++++++++++++++++++++++++++++++++++++++ | ||
14 | 2 files changed, 88 insertions(+) | ||
8 | 15 | ||
9 | (I swapped spaces for tabs in test 102 as well) | 16 | diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274 |
17 | index XXXXXXX..XXXXXXX 100755 | ||
18 | --- a/tests/qemu-iotests/274 | ||
19 | +++ b/tests/qemu-iotests/274 | ||
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) | ||
22 | iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid) | ||
23 | |||
24 | + iotests.log('=== Testing qemu-img commit (top -> base) ===') | ||
25 | + | ||
26 | + create_chain() | ||
27 | + iotests.qemu_img_log('commit', '-b', base, top) | ||
28 | + iotests.img_info_log(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) | ||
31 | + | ||
32 | + iotests.log('=== Testing QMP active commit (top -> base) ===') | ||
33 | + | ||
34 | + create_chain() | ||
35 | + with create_vm() as vm: | ||
36 | + vm.launch() | ||
37 | + vm.qmp_log('block-commit', device='top', base_node='base', | ||
38 | + job_id='job0', auto_dismiss=False) | ||
39 | + vm.run_job('job0', wait=5) | ||
40 | + | ||
41 | + iotests.img_info_log(mid) | ||
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) | ||
44 | |||
45 | iotests.log('== Resize tests ==') | ||
46 | |||
47 | diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/tests/qemu-iotests/274.out | ||
50 | +++ b/tests/qemu-iotests/274.out | ||
51 | @@ -XXX,XX +XXX,XX @@ read 1048576/1048576 bytes at offset 0 | ||
52 | read 1048576/1048576 bytes at offset 1048576 | ||
53 | 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
54 | |||
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 | ||
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 | ||
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 | ||
61 | + | ||
62 | +wrote 2097152/2097152 bytes at offset 0 | ||
63 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
64 | + | ||
65 | +Image committed. | ||
66 | + | ||
67 | +image: TEST_IMG | ||
68 | +file format: IMGFMT | ||
69 | +virtual size: 2 MiB (2097152 bytes) | ||
70 | +cluster_size: 65536 | ||
71 | +Format specific information: | ||
72 | + compat: 1.1 | ||
73 | + compression type: zlib | ||
74 | + lazy refcounts: false | ||
75 | + refcount bits: 16 | ||
76 | + corrupt: false | ||
77 | + extended l2: false | ||
78 | + | ||
79 | +read 1048576/1048576 bytes at offset 0 | ||
80 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
81 | + | ||
82 | +read 1048576/1048576 bytes at offset 1048576 | ||
83 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
84 | + | ||
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 | ||
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 | ||
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 | ||
91 | + | ||
92 | +wrote 2097152/2097152 bytes at offset 0 | ||
93 | +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
94 | + | ||
95 | +{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-node": "base", "device": "top", "job-id": "job0"}} | ||
96 | +{"return": {}} | ||
97 | +{"execute": "job-complete", "arguments": {"id": "job0"}} | ||
98 | +{"return": {}} | ||
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"}} | ||
101 | +{"execute": "job-dismiss", "arguments": {"id": "job0"}} | ||
102 | +{"return": {}} | ||
103 | +image: TEST_IMG | ||
104 | +file format: IMGFMT | ||
105 | +virtual size: 1 MiB (1048576 bytes) | ||
106 | +cluster_size: 65536 | ||
107 | +backing file: TEST_DIR/PID-base | ||
108 | +backing file format: IMGFMT | ||
109 | +Format specific information: | ||
110 | + compat: 1.1 | ||
111 | + compression type: zlib | ||
112 | + lazy refcounts: false | ||
113 | + refcount bits: 16 | ||
114 | + corrupt: false | ||
115 | + extended l2: false | ||
116 | + | ||
117 | +read 1048576/1048576 bytes at offset 0 | ||
118 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
119 | + | ||
120 | +read 1048576/1048576 bytes at offset 1048576 | ||
121 | +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
122 | + | ||
123 | == Resize tests == | ||
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 | ||
126 | -- | ||
127 | 2.26.2 | ||
10 | 128 | ||
11 | Reported-by: Eric Blake <eblake@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
13 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
14 | Message-id: d59c2f6ad6c1da8b9b3c7f357c94a7122ccfc55a.1492544096.git.jcody@redhat.com | ||
15 | --- | ||
16 | tests/qemu-iotests/028 | 1 + | ||
17 | tests/qemu-iotests/094 | 11 ++++++++--- | ||
18 | tests/qemu-iotests/102 | 5 +++-- | ||
19 | tests/qemu-iotests/109 | 1 + | ||
20 | tests/qemu-iotests/117 | 1 + | ||
21 | tests/qemu-iotests/130 | 1 + | ||
22 | tests/qemu-iotests/140 | 1 + | ||
23 | tests/qemu-iotests/141 | 1 + | ||
24 | tests/qemu-iotests/143 | 1 + | ||
25 | tests/qemu-iotests/156 | 1 + | ||
26 | 10 files changed, 19 insertions(+), 5 deletions(-) | ||
27 | |||
28 | diff --git a/tests/qemu-iotests/028 b/tests/qemu-iotests/028 | ||
29 | index XXXXXXX..XXXXXXX 100755 | ||
30 | --- a/tests/qemu-iotests/028 | ||
31 | +++ b/tests/qemu-iotests/028 | ||
32 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
33 | |||
34 | _cleanup() | ||
35 | { | ||
36 | + _cleanup_qemu | ||
37 | rm -f "${TEST_IMG}.copy" | ||
38 | _cleanup_test_img | ||
39 | } | ||
40 | diff --git a/tests/qemu-iotests/094 b/tests/qemu-iotests/094 | ||
41 | index XXXXXXX..XXXXXXX 100755 | ||
42 | --- a/tests/qemu-iotests/094 | ||
43 | +++ b/tests/qemu-iotests/094 | ||
44 | @@ -XXX,XX +XXX,XX @@ echo "QA output created by $seq" | ||
45 | here="$PWD" | ||
46 | status=1 # failure is the default! | ||
47 | |||
48 | -trap "exit \$status" 0 1 2 3 15 | ||
49 | +_cleanup() | ||
50 | +{ | ||
51 | + _cleanup_qemu | ||
52 | + _cleanup_test_img | ||
53 | + rm -f "$TEST_DIR/source.$IMGFMT" | ||
54 | +} | ||
55 | + | ||
56 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
57 | |||
58 | # get standard environment, filters and checks | ||
59 | . ./common.rc | ||
60 | @@ -XXX,XX +XXX,XX @@ _send_qemu_cmd $QEMU_HANDLE \ | ||
61 | |||
62 | wait=1 _cleanup_qemu | ||
63 | |||
64 | -_cleanup_test_img | ||
65 | -rm -f "$TEST_DIR/source.$IMGFMT" | ||
66 | |||
67 | # success, all done | ||
68 | echo '*** done' | ||
69 | diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102 | ||
70 | index XXXXXXX..XXXXXXX 100755 | ||
71 | --- a/tests/qemu-iotests/102 | ||
72 | +++ b/tests/qemu-iotests/102 | ||
73 | @@ -XXX,XX +XXX,XX @@ seq=$(basename $0) | ||
74 | echo "QA output created by $seq" | ||
75 | |||
76 | here=$PWD | ||
77 | -status=1 # failure is the default! | ||
78 | +status=1 # failure is the default! | ||
79 | |||
80 | _cleanup() | ||
81 | { | ||
82 | - _cleanup_test_img | ||
83 | + _cleanup_qemu | ||
84 | + _cleanup_test_img | ||
85 | } | ||
86 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
87 | |||
88 | diff --git a/tests/qemu-iotests/109 b/tests/qemu-iotests/109 | ||
89 | index XXXXXXX..XXXXXXX 100755 | ||
90 | --- a/tests/qemu-iotests/109 | ||
91 | +++ b/tests/qemu-iotests/109 | ||
92 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
93 | |||
94 | _cleanup() | ||
95 | { | ||
96 | + _cleanup_qemu | ||
97 | rm -f $TEST_IMG.src | ||
98 | _cleanup_test_img | ||
99 | } | ||
100 | diff --git a/tests/qemu-iotests/117 b/tests/qemu-iotests/117 | ||
101 | index XXXXXXX..XXXXXXX 100755 | ||
102 | --- a/tests/qemu-iotests/117 | ||
103 | +++ b/tests/qemu-iotests/117 | ||
104 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
105 | |||
106 | _cleanup() | ||
107 | { | ||
108 | + _cleanup_qemu | ||
109 | _cleanup_test_img | ||
110 | } | ||
111 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
112 | diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130 | ||
113 | index XXXXXXX..XXXXXXX 100755 | ||
114 | --- a/tests/qemu-iotests/130 | ||
115 | +++ b/tests/qemu-iotests/130 | ||
116 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
117 | |||
118 | _cleanup() | ||
119 | { | ||
120 | + _cleanup_qemu | ||
121 | _cleanup_test_img | ||
122 | } | ||
123 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
124 | diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140 | ||
125 | index XXXXXXX..XXXXXXX 100755 | ||
126 | --- a/tests/qemu-iotests/140 | ||
127 | +++ b/tests/qemu-iotests/140 | ||
128 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
129 | |||
130 | _cleanup() | ||
131 | { | ||
132 | + _cleanup_qemu | ||
133 | _cleanup_test_img | ||
134 | rm -f "$TEST_DIR/nbd" | ||
135 | } | ||
136 | diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 | ||
137 | index XXXXXXX..XXXXXXX 100755 | ||
138 | --- a/tests/qemu-iotests/141 | ||
139 | +++ b/tests/qemu-iotests/141 | ||
140 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
141 | |||
142 | _cleanup() | ||
143 | { | ||
144 | + _cleanup_qemu | ||
145 | _cleanup_test_img | ||
146 | rm -f "$TEST_DIR/{b,m,o}.$IMGFMT" | ||
147 | } | ||
148 | diff --git a/tests/qemu-iotests/143 b/tests/qemu-iotests/143 | ||
149 | index XXXXXXX..XXXXXXX 100755 | ||
150 | --- a/tests/qemu-iotests/143 | ||
151 | +++ b/tests/qemu-iotests/143 | ||
152 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
153 | |||
154 | _cleanup() | ||
155 | { | ||
156 | + _cleanup_qemu | ||
157 | rm -f "$TEST_DIR/nbd" | ||
158 | } | ||
159 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
160 | diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 | ||
161 | index XXXXXXX..XXXXXXX 100755 | ||
162 | --- a/tests/qemu-iotests/156 | ||
163 | +++ b/tests/qemu-iotests/156 | ||
164 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
165 | |||
166 | _cleanup() | ||
167 | { | ||
168 | + _cleanup_qemu | ||
169 | rm -f "$TEST_IMG{,.target}{,.backing,.overlay}" | ||
170 | } | ||
171 | trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
172 | -- | ||
173 | 2.9.3 | ||
174 | |||
175 | diff view generated by jsdifflib |