1 | The following changes since commit 9d662a6b22a0838a85c5432385f35db2488a33a5: | 1 | The following changes since commit 474f3938d79ab36b9231c9ad3b5a9314c2aeacde: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/legoater/tags/pull-ppc-20220305' into staging (2022-03-05 18:03:15 +0000) | 3 | Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-21-2019' into staging (2019-06-21 15:40:50 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/hreitz/qemu.git tags/pull-block-2022-03-07 | 7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-06-24 |
8 | 8 | ||
9 | for you to fetch changes up to 743da0b401cdc3ee94bc519975e339a3cdbe0ad1: | 9 | for you to fetch changes up to ab5d4a30f7f3803ca5106b370969c1b7b54136f8: |
10 | 10 | ||
11 | iotests/image-fleecing: test push backup with fleecing (2022-03-07 09:33:31 +0100) | 11 | iotests: Fix 205 for concurrent runs (2019-06-24 16:01:40 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches for 7.0-rc0: | 14 | Block patches: |
15 | - New fleecing backup scheme | 15 | - The SSH block driver now uses libssh instead of libssh2 |
16 | - iotest fixes | 16 | - The VMDK block driver gets read-only support for the seSparse |
17 | - Fixes for the curl block driver | 17 | subformat |
18 | - Fix for the preallocate block driver | 18 | - Various fixes |
19 | - IDE fix for zero-length TRIM requests | 19 | |
20 | --- | ||
21 | |||
22 | v2: | ||
23 | - Squashed Pino's fix for pre-0.8 libssh into the libssh patch | ||
20 | 24 | ||
21 | ---------------------------------------------------------------- | 25 | ---------------------------------------------------------------- |
22 | Hanna Reitz (2): | 26 | Anton Nefedov (1): |
23 | ide: Increment BB in-flight counter for TRIM BH | 27 | iotest 134: test cluster-misaligned encrypted write |
24 | iotests: Write test output to TEST_DIR | ||
25 | 28 | ||
26 | Peter Maydell (2): | 29 | Klaus Birkelund Jensen (1): |
27 | block/curl.c: Set error message string if curl_init_state() fails | 30 | nvme: do not advertise support for unsupported arbitration mechanism |
28 | block/curl.c: Check error return from curl_easy_setopt() | ||
29 | 31 | ||
30 | Thomas Huth (2): | 32 | Max Reitz (1): |
31 | tests/qemu-iotests/040: Skip TestCommitWithFilters without 'throttle' | 33 | iotests: Fix 205 for concurrent runs |
32 | tests/qemu-iotests/testrunner: Quote "case not run" lines in TAP mode | ||
33 | 34 | ||
34 | Vladimir Sementsov-Ogievskiy (17): | 35 | Pino Toscano (1): |
35 | block: fix preallocate filter: don't do unaligned preallocate requests | 36 | ssh: switch from libssh2 to libssh |
36 | block/block-copy: move copy_bitmap initialization to | ||
37 | block_copy_state_new() | ||
38 | block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value | ||
39 | block/block-copy: block_copy_state_new(): add bitmap parameter | ||
40 | block/copy-before-write: add bitmap open parameter | ||
41 | block/block-copy: add block_copy_reset() | ||
42 | block: intoduce reqlist | ||
43 | block/reqlist: reqlist_find_conflict(): use ranges_overlap() | ||
44 | block/dirty-bitmap: introduce bdrv_dirty_bitmap_status() | ||
45 | block/reqlist: add reqlist_wait_all() | ||
46 | block/io: introduce block driver snapshot-access API | ||
47 | block: introduce snapshot-access block driver | ||
48 | block: copy-before-write: realize snapshot-access API | ||
49 | iotests/image-fleecing: add test-case for fleecing format node | ||
50 | iotests.py: add qemu_io_pipe_and_status() | ||
51 | iotests/image-fleecing: add test case with bitmap | ||
52 | iotests/image-fleecing: test push backup with fleecing | ||
53 | 37 | ||
54 | qapi/block-core.json | 14 +- | 38 | Sam Eiderman (3): |
55 | include/block/block-common.h | 3 +- | 39 | vmdk: Fix comment regarding max l1_size coverage |
56 | include/block/block-copy.h | 2 + | 40 | vmdk: Reduce the max bound for L1 table size |
57 | include/block/block_int-common.h | 24 ++ | 41 | vmdk: Add read-only support for seSparse snapshots |
58 | include/block/block_int-io.h | 9 + | 42 | |
59 | include/block/dirty-bitmap.h | 4 +- | 43 | Vladimir Sementsov-Ogievskiy (1): |
60 | include/block/reqlist.h | 75 ++++++ | 44 | blockdev: enable non-root nodes for transaction drive-backup source |
61 | include/qemu/hbitmap.h | 12 + | 45 | |
62 | block/block-copy.c | 150 +++++------ | 46 | configure | 65 +- |
63 | block/copy-before-write.c | 265 +++++++++++++++++++- | 47 | block/Makefile.objs | 6 +- |
64 | block/curl.c | 92 ++++--- | 48 | block/ssh.c | 652 ++++++++++-------- |
65 | block/dirty-bitmap.c | 15 +- | 49 | block/vmdk.c | 372 +++++++++- |
66 | block/io.c | 76 ++++++ | 50 | blockdev.c | 2 +- |
67 | block/monitor/bitmap-qmp-cmds.c | 5 +- | 51 | hw/block/nvme.c | 1 - |
68 | block/preallocate.c | 15 +- | 52 | .travis.yml | 4 +- |
69 | block/reqlist.c | 85 +++++++ | 53 | block/trace-events | 14 +- |
70 | block/snapshot-access.c | 132 ++++++++++ | 54 | docs/qemu-block-drivers.texi | 2 +- |
71 | hw/ide/core.c | 7 + | 55 | .../dockerfiles/debian-win32-cross.docker | 1 - |
72 | util/hbitmap.c | 33 +++ | 56 | .../dockerfiles/debian-win64-cross.docker | 1 - |
73 | MAINTAINERS | 5 +- | 57 | tests/docker/dockerfiles/fedora.docker | 4 +- |
74 | block/meson.build | 2 + | 58 | tests/docker/dockerfiles/ubuntu.docker | 2 +- |
75 | tests/qemu-iotests/040 | 1 + | 59 | tests/docker/dockerfiles/ubuntu1804.docker | 2 +- |
76 | tests/qemu-iotests/257.out | 224 +++++++++++++++++ | 60 | tests/qemu-iotests/059.out | 2 +- |
77 | tests/qemu-iotests/common.rc | 6 +- | 61 | tests/qemu-iotests/134 | 9 + |
78 | tests/qemu-iotests/iotests.py | 8 +- | 62 | tests/qemu-iotests/134.out | 10 + |
79 | tests/qemu-iotests/testenv.py | 5 +- | 63 | tests/qemu-iotests/205 | 2 +- |
80 | tests/qemu-iotests/testrunner.py | 19 +- | 64 | tests/qemu-iotests/207 | 54 +- |
81 | tests/qemu-iotests/tests/image-fleecing | 185 +++++++++++--- | 65 | tests/qemu-iotests/207.out | 2 +- |
82 | tests/qemu-iotests/tests/image-fleecing.out | 221 +++++++++++++++- | 66 | 20 files changed, 823 insertions(+), 384 deletions(-) |
83 | 29 files changed, 1499 insertions(+), 195 deletions(-) | ||
84 | create mode 100644 include/block/reqlist.h | ||
85 | create mode 100644 block/reqlist.c | ||
86 | create mode 100644 block/snapshot-access.c | ||
87 | 67 | ||
88 | -- | 68 | -- |
89 | 2.34.1 | 69 | 2.21.0 |
70 | |||
71 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Klaus Birkelund Jensen <klaus@birkelund.eu> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 3 | The device mistakenly reports that the Weighted Round Robin with Urgent |
4 | Message-Id: <20220303194349.2304213-17-vsementsov@virtuozzo.com> | 4 | Priority Class arbitration mechanism is supported. |
5 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 5 | |
6 | It is not. | ||
7 | |||
8 | Signed-off-by: Klaus Birkelund Jensen <klaus.jensen@cnexlabs.com> | ||
9 | Message-id: 20190606092530.14206-1-klaus@birkelund.eu | ||
10 | Acked-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
6 | --- | 12 | --- |
7 | tests/qemu-iotests/tests/image-fleecing | 125 +++++++++++++++----- | 13 | hw/block/nvme.c | 1 - |
8 | tests/qemu-iotests/tests/image-fleecing.out | 63 ++++++++++ | 14 | 1 file changed, 1 deletion(-) |
9 | 2 files changed, 156 insertions(+), 32 deletions(-) | ||
10 | 15 | ||
11 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing | 16 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c |
12 | index XXXXXXX..XXXXXXX 100755 | ||
13 | --- a/tests/qemu-iotests/tests/image-fleecing | ||
14 | +++ b/tests/qemu-iotests/tests/image-fleecing | ||
15 | @@ -XXX,XX +XXX,XX @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] | ||
16 | ('0xdc', '32M', '32k'), # Left-end of partial-right [2] | ||
17 | ('0xcd', '0x3ff0000', '64k')] # patterns[3] | ||
18 | |||
19 | -def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
20 | - fleece_img_path, nbd_sock_path, vm, | ||
21 | +def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, | ||
22 | + fleece_img_path, nbd_sock_path=None, | ||
23 | + target_img_path=None, | ||
24 | bitmap=False): | ||
25 | + push_backup = target_img_path is not None | ||
26 | + assert (nbd_sock_path is not None) != push_backup | ||
27 | + if push_backup: | ||
28 | + assert use_cbw | ||
29 | + | ||
30 | log('--- Setting up images ---') | ||
31 | log('') | ||
32 | |||
33 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
34 | else: | ||
35 | assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 | ||
36 | |||
37 | + if push_backup: | ||
38 | + assert qemu_img('create', '-f', 'qcow2', target_img_path, '64M') == 0 | ||
39 | + | ||
40 | for p in patterns: | ||
41 | qemu_io('-f', iotests.imgfmt, | ||
42 | '-c', 'write -P%s %s %s' % p, base_img_path) | ||
43 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
44 | |||
45 | export_node = 'fl-access' if use_snapshot_access_filter else tmp_node | ||
46 | |||
47 | - log('') | ||
48 | - log('--- Setting up NBD Export ---') | ||
49 | - log('') | ||
50 | + if push_backup: | ||
51 | + log('') | ||
52 | + log('--- Starting actual backup ---') | ||
53 | + log('') | ||
54 | |||
55 | - nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) | ||
56 | - log(vm.qmp('nbd-server-start', | ||
57 | - {'addr': {'type': 'unix', | ||
58 | - 'data': {'path': nbd_sock_path}}})) | ||
59 | + log(vm.qmp('blockdev-add', **{ | ||
60 | + 'driver': iotests.imgfmt, | ||
61 | + 'node-name': 'target', | ||
62 | + 'file': { | ||
63 | + 'driver': 'file', | ||
64 | + 'filename': target_img_path | ||
65 | + } | ||
66 | + })) | ||
67 | + log(vm.qmp('blockdev-backup', device=export_node, | ||
68 | + sync='full', target='target', | ||
69 | + job_id='push-backup', speed=1)) | ||
70 | + else: | ||
71 | + log('') | ||
72 | + log('--- Setting up NBD Export ---') | ||
73 | + log('') | ||
74 | |||
75 | - log(vm.qmp('nbd-server-add', device=export_node)) | ||
76 | + nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) | ||
77 | + log(vm.qmp('nbd-server-start', | ||
78 | + {'addr': { 'type': 'unix', | ||
79 | + 'data': { 'path': nbd_sock_path } } })) | ||
80 | |||
81 | - log('') | ||
82 | - log('--- Sanity Check ---') | ||
83 | - log('') | ||
84 | + log(vm.qmp('nbd-server-add', device=export_node)) | ||
85 | |||
86 | - for p in patterns + zeroes: | ||
87 | - cmd = 'read -P%s %s %s' % p | ||
88 | - log(cmd) | ||
89 | - out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
90 | - nbd_uri) | ||
91 | - if ret != 0: | ||
92 | - print(out) | ||
93 | + log('') | ||
94 | + log('--- Sanity Check ---') | ||
95 | + log('') | ||
96 | + | ||
97 | + for p in patterns + zeroes: | ||
98 | + cmd = 'read -P%s %s %s' % p | ||
99 | + log(cmd) | ||
100 | + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
101 | + nbd_uri) | ||
102 | + if ret != 0: | ||
103 | + print(out) | ||
104 | |||
105 | log('') | ||
106 | log('--- Testing COW ---') | ||
107 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
108 | log(cmd) | ||
109 | log(vm.hmp_qemu_io(qom_path, cmd, qdev=True)) | ||
110 | |||
111 | + if push_backup: | ||
112 | + # Check that previous operations were done during backup, not after | ||
113 | + # If backup is already finished, it's possible that it was finished | ||
114 | + # even before hmp qemu_io write, and we didn't actually test | ||
115 | + # copy-before-write operation. This should not happen, as we use | ||
116 | + # speed=1. But worth checking. | ||
117 | + result = vm.qmp('query-block-jobs') | ||
118 | + assert len(result['return']) == 1 | ||
119 | + | ||
120 | + result = vm.qmp('block-job-set-speed', device='push-backup', speed=0) | ||
121 | + assert result == {'return': {}} | ||
122 | + | ||
123 | + log(vm.event_wait(name='BLOCK_JOB_COMPLETED', | ||
124 | + match={'data': {'device': 'push-backup'}}), | ||
125 | + filters=[iotests.filter_qmp_event]) | ||
126 | + log(vm.qmp('blockdev-del', node_name='target')) | ||
127 | + | ||
128 | log('') | ||
129 | log('--- Verifying Data ---') | ||
130 | log('') | ||
131 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
132 | for p in patterns + zeroes: | ||
133 | cmd = 'read -P%s %s %s' % p | ||
134 | log(cmd) | ||
135 | - out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
136 | - nbd_uri) | ||
137 | + args = ['-r', '-c', cmd] | ||
138 | + if push_backup: | ||
139 | + args += [target_img_path] | ||
140 | + else: | ||
141 | + args += ['-f', 'raw', nbd_uri] | ||
142 | + out, ret = qemu_io_pipe_and_status(*args) | ||
143 | if ret != 0: | ||
144 | print(out) | ||
145 | |||
146 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
147 | log('--- Cleanup ---') | ||
148 | log('') | ||
149 | |||
150 | - log(vm.qmp('nbd-server-stop')) | ||
151 | + if not push_backup: | ||
152 | + log(vm.qmp('nbd-server-stop')) | ||
153 | |||
154 | if use_cbw: | ||
155 | if use_snapshot_access_filter: | ||
156 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
157 | log('Done') | ||
158 | |||
159 | |||
160 | -def test(use_cbw, use_snapshot_access_filter, bitmap=False): | ||
161 | +def test(use_cbw, use_snapshot_access_filter, | ||
162 | + nbd_sock_path=None, target_img_path=None, bitmap=False): | ||
163 | with iotests.FilePath('base.img') as base_img_path, \ | ||
164 | iotests.FilePath('fleece.img') as fleece_img_path, \ | ||
165 | - iotests.FilePath('nbd.sock', | ||
166 | - base_dir=iotests.sock_dir) as nbd_sock_path, \ | ||
167 | iotests.VM() as vm: | ||
168 | - do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
169 | - fleece_img_path, nbd_sock_path, vm, bitmap=bitmap) | ||
170 | + do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, | ||
171 | + fleece_img_path, nbd_sock_path, target_img_path, | ||
172 | + bitmap=bitmap) | ||
173 | + | ||
174 | +def test_pull(use_cbw, use_snapshot_access_filter, bitmap=False): | ||
175 | + with iotests.FilePath('nbd.sock', | ||
176 | + base_dir=iotests.sock_dir) as nbd_sock_path: | ||
177 | + test(use_cbw, use_snapshot_access_filter, nbd_sock_path, None, | ||
178 | + bitmap=bitmap) | ||
179 | + | ||
180 | +def test_push(): | ||
181 | + with iotests.FilePath('target.img') as target_img_path: | ||
182 | + test(True, True, None, target_img_path) | ||
183 | |||
184 | |||
185 | log('=== Test backup(sync=none) based fleecing ===\n') | ||
186 | -test(False, False) | ||
187 | +test_pull(False, False) | ||
188 | |||
189 | log('=== Test cbw-filter based fleecing ===\n') | ||
190 | -test(True, False) | ||
191 | +test_pull(True, False) | ||
192 | |||
193 | log('=== Test fleecing-format based fleecing ===\n') | ||
194 | -test(True, True) | ||
195 | +test_pull(True, True) | ||
196 | |||
197 | log('=== Test fleecing-format based fleecing with bitmap ===\n') | ||
198 | -test(True, True, bitmap=True) | ||
199 | +test_pull(True, True, bitmap=True) | ||
200 | + | ||
201 | +log('=== Test push backup with fleecing ===\n') | ||
202 | +test_push() | ||
203 | diff --git a/tests/qemu-iotests/tests/image-fleecing.out b/tests/qemu-iotests/tests/image-fleecing.out | ||
204 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
205 | --- a/tests/qemu-iotests/tests/image-fleecing.out | 18 | --- a/hw/block/nvme.c |
206 | +++ b/tests/qemu-iotests/tests/image-fleecing.out | 19 | +++ b/hw/block/nvme.c |
207 | @@ -XXX,XX +XXX,XX @@ read -P0xdc 32M 32k | 20 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) |
208 | read -P0xcd 0x3ff0000 64k | 21 | n->bar.cap = 0; |
209 | 22 | NVME_CAP_SET_MQES(n->bar.cap, 0x7ff); | |
210 | Done | 23 | NVME_CAP_SET_CQR(n->bar.cap, 1); |
211 | +=== Test push backup with fleecing === | 24 | - NVME_CAP_SET_AMS(n->bar.cap, 1); |
212 | + | 25 | NVME_CAP_SET_TO(n->bar.cap, 0xf); |
213 | +--- Setting up images --- | 26 | NVME_CAP_SET_CSS(n->bar.cap, 1); |
214 | + | 27 | NVME_CAP_SET_MPSMAX(n->bar.cap, 4); |
215 | +Done | ||
216 | + | ||
217 | +--- Launching VM --- | ||
218 | + | ||
219 | +Done | ||
220 | + | ||
221 | +--- Setting up Fleecing Graph --- | ||
222 | + | ||
223 | +{"return": {}} | ||
224 | +{"return": {}} | ||
225 | +{"return": {}} | ||
226 | +{"return": {}} | ||
227 | + | ||
228 | +--- Starting actual backup --- | ||
229 | + | ||
230 | +{"return": {}} | ||
231 | +{"return": {}} | ||
232 | + | ||
233 | +--- Testing COW --- | ||
234 | + | ||
235 | +write -P0xab 0 64k | ||
236 | +{"return": ""} | ||
237 | +write -P0xad 0x00f8000 64k | ||
238 | +{"return": ""} | ||
239 | +write -P0x1d 0x2008000 64k | ||
240 | +{"return": ""} | ||
241 | +write -P0xea 0x3fe0000 64k | ||
242 | +{"return": ""} | ||
243 | +{"data": {"device": "push-backup", "len": 67108864, "offset": 67108864, "speed": 0, "type": "backup"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} | ||
244 | +{"return": {}} | ||
245 | + | ||
246 | +--- Verifying Data --- | ||
247 | + | ||
248 | +read -P0x5d 0 64k | ||
249 | +read -P0xd5 1M 64k | ||
250 | +read -P0xdc 32M 64k | ||
251 | +read -P0xcd 0x3ff0000 64k | ||
252 | +read -P0 0x00f8000 32k | ||
253 | +read -P0 0x2010000 32k | ||
254 | +read -P0 0x3fe0000 64k | ||
255 | + | ||
256 | +--- Cleanup --- | ||
257 | + | ||
258 | +{"return": {}} | ||
259 | +{"return": {}} | ||
260 | +{"return": {}} | ||
261 | +{"return": {}} | ||
262 | + | ||
263 | +--- Confirming writes --- | ||
264 | + | ||
265 | +read -P0xab 0 64k | ||
266 | +read -P0xad 0x00f8000 64k | ||
267 | +read -P0x1d 0x2008000 64k | ||
268 | +read -P0xea 0x3fe0000 64k | ||
269 | +read -P0xd5 0x108000 32k | ||
270 | +read -P0xdc 32M 32k | ||
271 | +read -P0xcd 0x3ff0000 64k | ||
272 | + | ||
273 | +Done | ||
274 | -- | 28 | -- |
275 | 2.34.1 | 29 | 2.21.0 |
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Split intersecting-requests functionality out of block-copy to be | 3 | We forget to enable it for transaction .prepare, while it is already |
4 | reused in copy-before-write filter. | 4 | enabled in do_drive_backup since commit a2d665c1bc362 |
5 | 5 | "blockdev: loosen restrictions on drive-backup source node" | |
6 | Note: while being here, fix tiny typo in MAINTAINERS. | ||
7 | 6 | ||
8 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
9 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | 8 | Message-id: 20190618140804.59214-1-vsementsov@virtuozzo.com |
10 | Message-Id: <20220303194349.2304213-7-vsementsov@virtuozzo.com> | 9 | Reviewed-by: John Snow <jsnow@redhat.com> |
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 10 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
12 | --- | 11 | --- |
13 | include/block/reqlist.h | 67 +++++++++++++++++++++++ | 12 | blockdev.c | 2 +- |
14 | block/block-copy.c | 116 +++++++++++++--------------------------- | 13 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | block/reqlist.c | 76 ++++++++++++++++++++++++++ | ||
16 | MAINTAINERS | 4 +- | ||
17 | block/meson.build | 1 + | ||
18 | 5 files changed, 184 insertions(+), 80 deletions(-) | ||
19 | create mode 100644 include/block/reqlist.h | ||
20 | create mode 100644 block/reqlist.c | ||
21 | 14 | ||
22 | diff --git a/include/block/reqlist.h b/include/block/reqlist.h | 15 | diff --git a/blockdev.c b/blockdev.c |
23 | new file mode 100644 | ||
24 | index XXXXXXX..XXXXXXX | ||
25 | --- /dev/null | ||
26 | +++ b/include/block/reqlist.h | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | +/* | ||
29 | + * reqlist API | ||
30 | + * | ||
31 | + * Copyright (C) 2013 Proxmox Server Solutions | ||
32 | + * Copyright (c) 2021 Virtuozzo International GmbH. | ||
33 | + * | ||
34 | + * Authors: | ||
35 | + * Dietmar Maurer (dietmar@proxmox.com) | ||
36 | + * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
37 | + * | ||
38 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
39 | + * See the COPYING file in the top-level directory. | ||
40 | + */ | ||
41 | + | ||
42 | +#ifndef REQLIST_H | ||
43 | +#define REQLIST_H | ||
44 | + | ||
45 | +#include "qemu/coroutine.h" | ||
46 | + | ||
47 | +/* | ||
48 | + * The API is not thread-safe and shouldn't be. The struct is public to be part | ||
49 | + * of other structures and protected by third-party locks, see | ||
50 | + * block/block-copy.c for example. | ||
51 | + */ | ||
52 | + | ||
53 | +typedef struct BlockReq { | ||
54 | + int64_t offset; | ||
55 | + int64_t bytes; | ||
56 | + | ||
57 | + CoQueue wait_queue; /* coroutines blocked on this req */ | ||
58 | + QLIST_ENTRY(BlockReq) list; | ||
59 | +} BlockReq; | ||
60 | + | ||
61 | +typedef QLIST_HEAD(, BlockReq) BlockReqList; | ||
62 | + | ||
63 | +/* | ||
64 | + * Initialize new request and add it to the list. Caller must be sure that | ||
65 | + * there are no conflicting requests in the list. | ||
66 | + */ | ||
67 | +void reqlist_init_req(BlockReqList *reqs, BlockReq *req, int64_t offset, | ||
68 | + int64_t bytes); | ||
69 | +/* Search for request in the list intersecting with @offset/@bytes area. */ | ||
70 | +BlockReq *reqlist_find_conflict(BlockReqList *reqs, int64_t offset, | ||
71 | + int64_t bytes); | ||
72 | + | ||
73 | +/* | ||
74 | + * If there are no intersecting requests return false. Otherwise, wait for the | ||
75 | + * first found intersecting request to finish and return true. | ||
76 | + * | ||
77 | + * @lock is passed to qemu_co_queue_wait() | ||
78 | + * False return value proves that lock was released at no point. | ||
79 | + */ | ||
80 | +bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset, | ||
81 | + int64_t bytes, CoMutex *lock); | ||
82 | + | ||
83 | +/* | ||
84 | + * Shrink request and wake all waiting coroutines (maybe some of them are not | ||
85 | + * intersecting with shrunk request). | ||
86 | + */ | ||
87 | +void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes); | ||
88 | + | ||
89 | +/* | ||
90 | + * Remove request and wake all waiting coroutines. Do not release any memory. | ||
91 | + */ | ||
92 | +void coroutine_fn reqlist_remove_req(BlockReq *req); | ||
93 | + | ||
94 | +#endif /* REQLIST_H */ | ||
95 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
96 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
97 | --- a/block/block-copy.c | 17 | --- a/blockdev.c |
98 | +++ b/block/block-copy.c | 18 | +++ b/blockdev.c |
99 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) |
100 | #include "trace.h" | 20 | assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); |
101 | #include "qapi/error.h" | 21 | backup = common->action->u.drive_backup.data; |
102 | #include "block/block-copy.h" | 22 | |
103 | +#include "block/reqlist.h" | 23 | - bs = qmp_get_root_bs(backup->device, errp); |
104 | #include "sysemu/block-backend.h" | 24 | + bs = bdrv_lookup_bs(backup->device, backup->device, errp); |
105 | #include "qemu/units.h" | 25 | if (!bs) { |
106 | #include "qemu/coroutine.h" | ||
107 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyTask { | ||
108 | */ | ||
109 | BlockCopyState *s; | ||
110 | BlockCopyCallState *call_state; | ||
111 | - int64_t offset; | ||
112 | /* | ||
113 | * @method can also be set again in the while loop of | ||
114 | * block_copy_dirty_clusters(), but it is never accessed concurrently | ||
115 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyTask { | ||
116 | BlockCopyMethod method; | ||
117 | |||
118 | /* | ||
119 | - * Fields whose state changes throughout the execution | ||
120 | - * Protected by lock in BlockCopyState. | ||
121 | + * Generally, req is protected by lock in BlockCopyState, Still req.offset | ||
122 | + * is only set on task creation, so may be read concurrently after creation. | ||
123 | + * req.bytes is changed at most once, and need only protecting the case of | ||
124 | + * parallel read while updating @bytes value in block_copy_task_shrink(). | ||
125 | */ | ||
126 | - CoQueue wait_queue; /* coroutines blocked on this task */ | ||
127 | - /* | ||
128 | - * Only protect the case of parallel read while updating @bytes | ||
129 | - * value in block_copy_task_shrink(). | ||
130 | - */ | ||
131 | - int64_t bytes; | ||
132 | - QLIST_ENTRY(BlockCopyTask) list; | ||
133 | + BlockReq req; | ||
134 | } BlockCopyTask; | ||
135 | |||
136 | static int64_t task_end(BlockCopyTask *task) | ||
137 | { | ||
138 | - return task->offset + task->bytes; | ||
139 | + return task->req.offset + task->req.bytes; | ||
140 | } | ||
141 | |||
142 | typedef struct BlockCopyState { | ||
143 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyState { | ||
144 | CoMutex lock; | ||
145 | int64_t in_flight_bytes; | ||
146 | BlockCopyMethod method; | ||
147 | - QLIST_HEAD(, BlockCopyTask) tasks; /* All tasks from all block-copy calls */ | ||
148 | + BlockReqList reqs; | ||
149 | QLIST_HEAD(, BlockCopyCallState) calls; | ||
150 | /* | ||
151 | * skip_unallocated: | ||
152 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyState { | ||
153 | RateLimit rate_limit; | ||
154 | } BlockCopyState; | ||
155 | |||
156 | -/* Called with lock held */ | ||
157 | -static BlockCopyTask *find_conflicting_task(BlockCopyState *s, | ||
158 | - int64_t offset, int64_t bytes) | ||
159 | -{ | ||
160 | - BlockCopyTask *t; | ||
161 | - | ||
162 | - QLIST_FOREACH(t, &s->tasks, list) { | ||
163 | - if (offset + bytes > t->offset && offset < t->offset + t->bytes) { | ||
164 | - return t; | ||
165 | - } | ||
166 | - } | ||
167 | - | ||
168 | - return NULL; | ||
169 | -} | ||
170 | - | ||
171 | -/* | ||
172 | - * If there are no intersecting tasks return false. Otherwise, wait for the | ||
173 | - * first found intersecting tasks to finish and return true. | ||
174 | - * | ||
175 | - * Called with lock held. May temporary release the lock. | ||
176 | - * Return value of 0 proves that lock was NOT released. | ||
177 | - */ | ||
178 | -static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t offset, | ||
179 | - int64_t bytes) | ||
180 | -{ | ||
181 | - BlockCopyTask *task = find_conflicting_task(s, offset, bytes); | ||
182 | - | ||
183 | - if (!task) { | ||
184 | - return false; | ||
185 | - } | ||
186 | - | ||
187 | - qemu_co_queue_wait(&task->wait_queue, &s->lock); | ||
188 | - | ||
189 | - return true; | ||
190 | -} | ||
191 | - | ||
192 | /* Called with lock held */ | ||
193 | static int64_t block_copy_chunk_size(BlockCopyState *s) | ||
194 | { | ||
195 | @@ -XXX,XX +XXX,XX @@ block_copy_task_create(BlockCopyState *s, BlockCopyCallState *call_state, | ||
196 | bytes = QEMU_ALIGN_UP(bytes, s->cluster_size); | ||
197 | |||
198 | /* region is dirty, so no existent tasks possible in it */ | ||
199 | - assert(!find_conflicting_task(s, offset, bytes)); | ||
200 | + assert(!reqlist_find_conflict(&s->reqs, offset, bytes)); | ||
201 | |||
202 | bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); | ||
203 | s->in_flight_bytes += bytes; | ||
204 | @@ -XXX,XX +XXX,XX @@ block_copy_task_create(BlockCopyState *s, BlockCopyCallState *call_state, | ||
205 | .task.func = block_copy_task_entry, | ||
206 | .s = s, | ||
207 | .call_state = call_state, | ||
208 | - .offset = offset, | ||
209 | - .bytes = bytes, | ||
210 | .method = s->method, | ||
211 | }; | ||
212 | - qemu_co_queue_init(&task->wait_queue); | ||
213 | - QLIST_INSERT_HEAD(&s->tasks, task, list); | ||
214 | + reqlist_init_req(&s->reqs, &task->req, offset, bytes); | ||
215 | |||
216 | return task; | ||
217 | } | ||
218 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn block_copy_task_shrink(BlockCopyTask *task, | ||
219 | int64_t new_bytes) | ||
220 | { | ||
221 | QEMU_LOCK_GUARD(&task->s->lock); | ||
222 | - if (new_bytes == task->bytes) { | ||
223 | + if (new_bytes == task->req.bytes) { | ||
224 | return; | 26 | return; |
225 | } | 27 | } |
226 | |||
227 | - assert(new_bytes > 0 && new_bytes < task->bytes); | ||
228 | + assert(new_bytes > 0 && new_bytes < task->req.bytes); | ||
229 | |||
230 | - task->s->in_flight_bytes -= task->bytes - new_bytes; | ||
231 | + task->s->in_flight_bytes -= task->req.bytes - new_bytes; | ||
232 | bdrv_set_dirty_bitmap(task->s->copy_bitmap, | ||
233 | - task->offset + new_bytes, task->bytes - new_bytes); | ||
234 | + task->req.offset + new_bytes, | ||
235 | + task->req.bytes - new_bytes); | ||
236 | |||
237 | - task->bytes = new_bytes; | ||
238 | - qemu_co_queue_restart_all(&task->wait_queue); | ||
239 | + reqlist_shrink_req(&task->req, new_bytes); | ||
240 | } | ||
241 | |||
242 | static void coroutine_fn block_copy_task_end(BlockCopyTask *task, int ret) | ||
243 | { | ||
244 | QEMU_LOCK_GUARD(&task->s->lock); | ||
245 | - task->s->in_flight_bytes -= task->bytes; | ||
246 | + task->s->in_flight_bytes -= task->req.bytes; | ||
247 | if (ret < 0) { | ||
248 | - bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->offset, task->bytes); | ||
249 | + bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->req.offset, | ||
250 | + task->req.bytes); | ||
251 | } | ||
252 | - QLIST_REMOVE(task, list); | ||
253 | if (task->s->progress) { | ||
254 | progress_set_remaining(task->s->progress, | ||
255 | bdrv_get_dirty_count(task->s->copy_bitmap) + | ||
256 | task->s->in_flight_bytes); | ||
257 | } | ||
258 | - qemu_co_queue_restart_all(&task->wait_queue); | ||
259 | + reqlist_remove_req(&task->req); | ||
260 | } | ||
261 | |||
262 | void block_copy_state_free(BlockCopyState *s) | ||
263 | @@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, | ||
264 | |||
265 | ratelimit_init(&s->rate_limit); | ||
266 | qemu_co_mutex_init(&s->lock); | ||
267 | - QLIST_INIT(&s->tasks); | ||
268 | + QLIST_INIT(&s->reqs); | ||
269 | QLIST_INIT(&s->calls); | ||
270 | |||
271 | return s; | ||
272 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int block_copy_task_run(AioTaskPool *pool, | ||
273 | |||
274 | aio_task_pool_wait_slot(pool); | ||
275 | if (aio_task_pool_status(pool) < 0) { | ||
276 | - co_put_to_shres(task->s->mem, task->bytes); | ||
277 | + co_put_to_shres(task->s->mem, task->req.bytes); | ||
278 | block_copy_task_end(task, -ECANCELED); | ||
279 | g_free(task); | ||
280 | return -ECANCELED; | ||
281 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int block_copy_task_entry(AioTask *task) | ||
282 | BlockCopyMethod method = t->method; | ||
283 | int ret; | ||
284 | |||
285 | - ret = block_copy_do_copy(s, t->offset, t->bytes, &method, &error_is_read); | ||
286 | + ret = block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, | ||
287 | + &error_is_read); | ||
288 | |||
289 | WITH_QEMU_LOCK_GUARD(&s->lock) { | ||
290 | if (s->method == t->method) { | ||
291 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int block_copy_task_entry(AioTask *task) | ||
292 | t->call_state->error_is_read = error_is_read; | ||
293 | } | ||
294 | } else if (s->progress) { | ||
295 | - progress_work_done(s->progress, t->bytes); | ||
296 | + progress_work_done(s->progress, t->req.bytes); | ||
297 | } | ||
298 | } | ||
299 | - co_put_to_shres(s->mem, t->bytes); | ||
300 | + co_put_to_shres(s->mem, t->req.bytes); | ||
301 | block_copy_task_end(t, ret); | ||
302 | |||
303 | return ret; | ||
304 | @@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) | ||
305 | trace_block_copy_skip_range(s, offset, bytes); | ||
306 | break; | ||
307 | } | ||
308 | - if (task->offset > offset) { | ||
309 | - trace_block_copy_skip_range(s, offset, task->offset - offset); | ||
310 | + if (task->req.offset > offset) { | ||
311 | + trace_block_copy_skip_range(s, offset, task->req.offset - offset); | ||
312 | } | ||
313 | |||
314 | found_dirty = true; | ||
315 | |||
316 | - ret = block_copy_block_status(s, task->offset, task->bytes, | ||
317 | + ret = block_copy_block_status(s, task->req.offset, task->req.bytes, | ||
318 | &status_bytes); | ||
319 | assert(ret >= 0); /* never fail */ | ||
320 | - if (status_bytes < task->bytes) { | ||
321 | + if (status_bytes < task->req.bytes) { | ||
322 | block_copy_task_shrink(task, status_bytes); | ||
323 | } | ||
324 | if (qatomic_read(&s->skip_unallocated) && | ||
325 | !(ret & BDRV_BLOCK_ALLOCATED)) { | ||
326 | block_copy_task_end(task, 0); | ||
327 | - trace_block_copy_skip_range(s, task->offset, task->bytes); | ||
328 | + trace_block_copy_skip_range(s, task->req.offset, task->req.bytes); | ||
329 | offset = task_end(task); | ||
330 | bytes = end - offset; | ||
331 | g_free(task); | ||
332 | @@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) | ||
333 | } | ||
334 | } | ||
335 | |||
336 | - ratelimit_calculate_delay(&s->rate_limit, task->bytes); | ||
337 | + ratelimit_calculate_delay(&s->rate_limit, task->req.bytes); | ||
338 | |||
339 | - trace_block_copy_process(s, task->offset); | ||
340 | + trace_block_copy_process(s, task->req.offset); | ||
341 | |||
342 | - co_get_from_shres(s->mem, task->bytes); | ||
343 | + co_get_from_shres(s->mem, task->req.bytes); | ||
344 | |||
345 | offset = task_end(task); | ||
346 | bytes = end - offset; | ||
347 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) | ||
348 | * Check that there is no task we still need to | ||
349 | * wait to complete | ||
350 | */ | ||
351 | - ret = block_copy_wait_one(s, call_state->offset, | ||
352 | - call_state->bytes); | ||
353 | + ret = reqlist_wait_one(&s->reqs, call_state->offset, | ||
354 | + call_state->bytes, &s->lock); | ||
355 | if (ret == 0) { | ||
356 | /* | ||
357 | * No pending tasks, but check again the bitmap in this | ||
358 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) | ||
359 | * between this and the critical section in | ||
360 | * block_copy_dirty_clusters(). | ||
361 | * | ||
362 | - * block_copy_wait_one return value 0 also means that it | ||
363 | + * reqlist_wait_one return value 0 also means that it | ||
364 | * didn't release the lock. So, we are still in the same | ||
365 | * critical section, not interrupted by any concurrent | ||
366 | * access to state. | ||
367 | diff --git a/block/reqlist.c b/block/reqlist.c | ||
368 | new file mode 100644 | ||
369 | index XXXXXXX..XXXXXXX | ||
370 | --- /dev/null | ||
371 | +++ b/block/reqlist.c | ||
372 | @@ -XXX,XX +XXX,XX @@ | ||
373 | +/* | ||
374 | + * reqlist API | ||
375 | + * | ||
376 | + * Copyright (C) 2013 Proxmox Server Solutions | ||
377 | + * Copyright (c) 2021 Virtuozzo International GmbH. | ||
378 | + * | ||
379 | + * Authors: | ||
380 | + * Dietmar Maurer (dietmar@proxmox.com) | ||
381 | + * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
382 | + * | ||
383 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
384 | + * See the COPYING file in the top-level directory. | ||
385 | + */ | ||
386 | + | ||
387 | +#include "qemu/osdep.h" | ||
388 | + | ||
389 | +#include "block/reqlist.h" | ||
390 | + | ||
391 | +void reqlist_init_req(BlockReqList *reqs, BlockReq *req, int64_t offset, | ||
392 | + int64_t bytes) | ||
393 | +{ | ||
394 | + assert(!reqlist_find_conflict(reqs, offset, bytes)); | ||
395 | + | ||
396 | + *req = (BlockReq) { | ||
397 | + .offset = offset, | ||
398 | + .bytes = bytes, | ||
399 | + }; | ||
400 | + qemu_co_queue_init(&req->wait_queue); | ||
401 | + QLIST_INSERT_HEAD(reqs, req, list); | ||
402 | +} | ||
403 | + | ||
404 | +BlockReq *reqlist_find_conflict(BlockReqList *reqs, int64_t offset, | ||
405 | + int64_t bytes) | ||
406 | +{ | ||
407 | + BlockReq *r; | ||
408 | + | ||
409 | + QLIST_FOREACH(r, reqs, list) { | ||
410 | + if (offset + bytes > r->offset && offset < r->offset + r->bytes) { | ||
411 | + return r; | ||
412 | + } | ||
413 | + } | ||
414 | + | ||
415 | + return NULL; | ||
416 | +} | ||
417 | + | ||
418 | +bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset, | ||
419 | + int64_t bytes, CoMutex *lock) | ||
420 | +{ | ||
421 | + BlockReq *r = reqlist_find_conflict(reqs, offset, bytes); | ||
422 | + | ||
423 | + if (!r) { | ||
424 | + return false; | ||
425 | + } | ||
426 | + | ||
427 | + qemu_co_queue_wait(&r->wait_queue, lock); | ||
428 | + | ||
429 | + return true; | ||
430 | +} | ||
431 | + | ||
432 | +void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes) | ||
433 | +{ | ||
434 | + if (new_bytes == req->bytes) { | ||
435 | + return; | ||
436 | + } | ||
437 | + | ||
438 | + assert(new_bytes > 0 && new_bytes < req->bytes); | ||
439 | + | ||
440 | + req->bytes = new_bytes; | ||
441 | + qemu_co_queue_restart_all(&req->wait_queue); | ||
442 | +} | ||
443 | + | ||
444 | +void coroutine_fn reqlist_remove_req(BlockReq *req) | ||
445 | +{ | ||
446 | + QLIST_REMOVE(req, list); | ||
447 | + qemu_co_queue_restart_all(&req->wait_queue); | ||
448 | +} | ||
449 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
450 | index XXXXXXX..XXXXXXX 100644 | ||
451 | --- a/MAINTAINERS | ||
452 | +++ b/MAINTAINERS | ||
453 | @@ -XXX,XX +XXX,XX @@ F: block/stream.c | ||
454 | F: block/mirror.c | ||
455 | F: qapi/job.json | ||
456 | F: block/block-copy.c | ||
457 | -F: include/block/block-copy.c | ||
458 | +F: include/block/block-copy.h | ||
459 | +F: block/reqlist.c | ||
460 | +F: include/block/reqlist.h | ||
461 | F: block/copy-before-write.h | ||
462 | F: block/copy-before-write.c | ||
463 | F: include/block/aio_task.h | ||
464 | diff --git a/block/meson.build b/block/meson.build | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/block/meson.build | ||
467 | +++ b/block/meson.build | ||
468 | @@ -XXX,XX +XXX,XX @@ block_ss.add(files( | ||
469 | 'qcow2.c', | ||
470 | 'quorum.c', | ||
471 | 'raw-format.c', | ||
472 | + 'reqlist.c', | ||
473 | 'snapshot.c', | ||
474 | 'throttle-groups.c', | ||
475 | 'throttle.c', | ||
476 | -- | 28 | -- |
477 | 2.34.1 | 29 | 2.21.0 |
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Anton Nefedov <anton.nefedov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Note that reads zero areas (not dirty in the bitmap) fails, that's | 3 | COW (even empty/zero) areas require encryption too |
4 | correct. | ||
5 | 4 | ||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 5 | Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com> |
7 | Message-Id: <20220303194349.2304213-16-vsementsov@virtuozzo.com> | 6 | Reviewed-by: Eric Blake <eblake@redhat.com> |
8 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 7 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
9 | Message-id: 20190516143028.81155-1-anton.nefedov@virtuozzo.com | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | 11 | --- |
10 | tests/qemu-iotests/tests/image-fleecing | 38 +++++++--- | 12 | tests/qemu-iotests/134 | 9 +++++++++ |
11 | tests/qemu-iotests/tests/image-fleecing.out | 84 +++++++++++++++++++++ | 13 | tests/qemu-iotests/134.out | 10 ++++++++++ |
12 | 2 files changed, 113 insertions(+), 9 deletions(-) | 14 | 2 files changed, 19 insertions(+) |
13 | 15 | ||
14 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing | 16 | diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 |
15 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100755 |
16 | --- a/tests/qemu-iotests/tests/image-fleecing | 18 | --- a/tests/qemu-iotests/134 |
17 | +++ b/tests/qemu-iotests/tests/image-fleecing | 19 | +++ b/tests/qemu-iotests/134 |
18 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ echo |
19 | # Creator/Owner: John Snow <jsnow@redhat.com> | 21 | echo "== reading whole image ==" |
20 | 22 | $QEMU_IO --object $SECRET -c "read 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | |
21 | import iotests | 23 | |
22 | -from iotests import log, qemu_img, qemu_io, qemu_io_silent | 24 | +echo |
23 | +from iotests import log, qemu_img, qemu_io, qemu_io_silent, \ | 25 | +echo "== rewriting cluster part ==" |
24 | + qemu_io_pipe_and_status | 26 | +$QEMU_IO --object $SECRET -c "write -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
25 | |||
26 | iotests.script_initialize( | ||
27 | - supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk', 'vhdx', 'raw'], | ||
28 | + supported_fmts=['qcow2'], | ||
29 | supported_platforms=['linux'], | ||
30 | required_fmts=['copy-before-write'], | ||
31 | + unsupported_imgopts=['compat'] | ||
32 | ) | ||
33 | |||
34 | patterns = [('0x5d', '0', '64k'), | ||
35 | @@ -XXX,XX +XXX,XX @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] | ||
36 | ('0xcd', '0x3ff0000', '64k')] # patterns[3] | ||
37 | |||
38 | def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
39 | - fleece_img_path, nbd_sock_path, vm): | ||
40 | + fleece_img_path, nbd_sock_path, vm, | ||
41 | + bitmap=False): | ||
42 | log('--- Setting up images ---') | ||
43 | log('') | ||
44 | |||
45 | assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0 | ||
46 | + if bitmap: | ||
47 | + assert qemu_img('bitmap', '--add', base_img_path, 'bitmap0') == 0 | ||
48 | + | 27 | + |
49 | if use_snapshot_access_filter: | 28 | +echo |
50 | assert use_cbw | 29 | +echo "== verify pattern ==" |
51 | assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') == 0 | 30 | +$QEMU_IO --object $SECRET -c "read -P 0 0 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
52 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | 31 | +$QEMU_IO --object $SECRET -c "read -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir |
53 | |||
54 | # Establish CBW from source to fleecing node | ||
55 | if use_cbw: | ||
56 | - log(vm.qmp('blockdev-add', { | ||
57 | + fl_cbw = { | ||
58 | 'driver': 'copy-before-write', | ||
59 | 'node-name': 'fl-cbw', | ||
60 | 'file': src_node, | ||
61 | 'target': tmp_node | ||
62 | - })) | ||
63 | + } | ||
64 | + | 32 | + |
65 | + if bitmap: | 33 | echo |
66 | + fl_cbw['bitmap'] = {'node': src_node, 'name': 'bitmap0'} | 34 | echo "== rewriting whole image ==" |
35 | $QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | ||
36 | diff --git a/tests/qemu-iotests/134.out b/tests/qemu-iotests/134.out | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/tests/qemu-iotests/134.out | ||
39 | +++ b/tests/qemu-iotests/134.out | ||
40 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on encrypt. | ||
41 | read 134217728/134217728 bytes at offset 0 | ||
42 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
43 | |||
44 | +== rewriting cluster part == | ||
45 | +wrote 512/512 bytes at offset 512 | ||
46 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
67 | + | 47 | + |
68 | + log(vm.qmp('blockdev-add', fl_cbw)) | 48 | +== verify pattern == |
69 | 49 | +read 512/512 bytes at offset 0 | |
70 | log(vm.qmp('qom-set', path=qom_path, property='drive', value='fl-cbw')) | 50 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
71 | 51 | +read 512/512 bytes at offset 512 | |
72 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | 52 | +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
73 | for p in patterns + zeroes: | ||
74 | cmd = 'read -P%s %s %s' % p | ||
75 | log(cmd) | ||
76 | - assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0 | ||
77 | + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
78 | + nbd_uri) | ||
79 | + if ret != 0: | ||
80 | + print(out) | ||
81 | |||
82 | log('') | ||
83 | log('--- Testing COW ---') | ||
84 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
85 | for p in patterns + zeroes: | ||
86 | cmd = 'read -P%s %s %s' % p | ||
87 | log(cmd) | ||
88 | - assert qemu_io_silent('-r', '-f', 'raw', '-c', cmd, nbd_uri) == 0 | ||
89 | + out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
90 | + nbd_uri) | ||
91 | + if ret != 0: | ||
92 | + print(out) | ||
93 | |||
94 | log('') | ||
95 | log('--- Cleanup ---') | ||
96 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
97 | log('Done') | ||
98 | |||
99 | |||
100 | -def test(use_cbw, use_snapshot_access_filter): | ||
101 | +def test(use_cbw, use_snapshot_access_filter, bitmap=False): | ||
102 | with iotests.FilePath('base.img') as base_img_path, \ | ||
103 | iotests.FilePath('fleece.img') as fleece_img_path, \ | ||
104 | iotests.FilePath('nbd.sock', | ||
105 | base_dir=iotests.sock_dir) as nbd_sock_path, \ | ||
106 | iotests.VM() as vm: | ||
107 | do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
108 | - fleece_img_path, nbd_sock_path, vm) | ||
109 | + fleece_img_path, nbd_sock_path, vm, bitmap=bitmap) | ||
110 | |||
111 | |||
112 | log('=== Test backup(sync=none) based fleecing ===\n') | ||
113 | @@ -XXX,XX +XXX,XX @@ test(True, False) | ||
114 | |||
115 | log('=== Test fleecing-format based fleecing ===\n') | ||
116 | test(True, True) | ||
117 | + | 53 | + |
118 | +log('=== Test fleecing-format based fleecing with bitmap ===\n') | 54 | == rewriting whole image == |
119 | +test(True, True, bitmap=True) | 55 | wrote 134217728/134217728 bytes at offset 0 |
120 | diff --git a/tests/qemu-iotests/tests/image-fleecing.out b/tests/qemu-iotests/tests/image-fleecing.out | 56 | 128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) |
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/tests/qemu-iotests/tests/image-fleecing.out | ||
123 | +++ b/tests/qemu-iotests/tests/image-fleecing.out | ||
124 | @@ -XXX,XX +XXX,XX @@ read -P0 0x00f8000 32k | ||
125 | read -P0 0x2010000 32k | ||
126 | read -P0 0x3fe0000 64k | ||
127 | |||
128 | +--- Cleanup --- | ||
129 | + | ||
130 | +{"return": {}} | ||
131 | +{"return": {}} | ||
132 | +{"return": {}} | ||
133 | +{"return": {}} | ||
134 | +{"return": {}} | ||
135 | + | ||
136 | +--- Confirming writes --- | ||
137 | + | ||
138 | +read -P0xab 0 64k | ||
139 | +read -P0xad 0x00f8000 64k | ||
140 | +read -P0x1d 0x2008000 64k | ||
141 | +read -P0xea 0x3fe0000 64k | ||
142 | +read -P0xd5 0x108000 32k | ||
143 | +read -P0xdc 32M 32k | ||
144 | +read -P0xcd 0x3ff0000 64k | ||
145 | + | ||
146 | +Done | ||
147 | +=== Test fleecing-format based fleecing with bitmap === | ||
148 | + | ||
149 | +--- Setting up images --- | ||
150 | + | ||
151 | +Done | ||
152 | + | ||
153 | +--- Launching VM --- | ||
154 | + | ||
155 | +Done | ||
156 | + | ||
157 | +--- Setting up Fleecing Graph --- | ||
158 | + | ||
159 | +{"return": {}} | ||
160 | +{"return": {}} | ||
161 | +{"return": {}} | ||
162 | +{"return": {}} | ||
163 | + | ||
164 | +--- Setting up NBD Export --- | ||
165 | + | ||
166 | +{"return": {}} | ||
167 | +{"return": {}} | ||
168 | + | ||
169 | +--- Sanity Check --- | ||
170 | + | ||
171 | +read -P0x5d 0 64k | ||
172 | +read -P0xd5 1M 64k | ||
173 | +read -P0xdc 32M 64k | ||
174 | +read -P0xcd 0x3ff0000 64k | ||
175 | +read -P0 0x00f8000 32k | ||
176 | +read failed: Invalid argument | ||
177 | + | ||
178 | +read -P0 0x2010000 32k | ||
179 | +read failed: Invalid argument | ||
180 | + | ||
181 | +read -P0 0x3fe0000 64k | ||
182 | +read failed: Invalid argument | ||
183 | + | ||
184 | + | ||
185 | +--- Testing COW --- | ||
186 | + | ||
187 | +write -P0xab 0 64k | ||
188 | +{"return": ""} | ||
189 | +write -P0xad 0x00f8000 64k | ||
190 | +{"return": ""} | ||
191 | +write -P0x1d 0x2008000 64k | ||
192 | +{"return": ""} | ||
193 | +write -P0xea 0x3fe0000 64k | ||
194 | +{"return": ""} | ||
195 | + | ||
196 | +--- Verifying Data --- | ||
197 | + | ||
198 | +read -P0x5d 0 64k | ||
199 | +read -P0xd5 1M 64k | ||
200 | +read -P0xdc 32M 64k | ||
201 | +read -P0xcd 0x3ff0000 64k | ||
202 | +read -P0 0x00f8000 32k | ||
203 | +read failed: Invalid argument | ||
204 | + | ||
205 | +read -P0 0x2010000 32k | ||
206 | +read failed: Invalid argument | ||
207 | + | ||
208 | +read -P0 0x3fe0000 64k | ||
209 | +read failed: Invalid argument | ||
210 | + | ||
211 | + | ||
212 | --- Cleanup --- | ||
213 | |||
214 | {"return": {}} | ||
215 | -- | 57 | -- |
216 | 2.34.1 | 58 | 2.21.0 |
59 | |||
60 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Let's reuse convenient helper. | 3 | Commit b0651b8c246d ("vmdk: Move l1_size check into vmdk_add_extent") |
4 | extended the l1_size check from VMDK4 to VMDK3 but did not update the | ||
5 | default coverage in the moved comment. | ||
4 | 6 | ||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | The previous vmdk4 calculation: |
6 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | 8 | |
7 | Message-Id: <20220303194349.2304213-8-vsementsov@virtuozzo.com> | 9 | (512 * 1024 * 1024) * 512(l2 entries) * 65536(grain) = 16PB |
8 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 10 | |
11 | The added vmdk3 calculation: | ||
12 | |||
13 | (512 * 1024 * 1024) * 4096(l2 entries) * 512(grain) = 1PB | ||
14 | |||
15 | Adding the calculation of vmdk3 to the comment. | ||
16 | |||
17 | In any case, VMware does not offer virtual disks more than 2TB for | ||
18 | vmdk4/vmdk3 or 64TB for the new undocumented seSparse format which is | ||
19 | not implemented yet in qemu. | ||
20 | |||
21 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | ||
22 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | ||
23 | Reviewed-by: Liran Alon <liran.alon@oracle.com> | ||
24 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | ||
25 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | ||
26 | Message-id: 20190620091057.47441-2-shmuel.eiderman@oracle.com | ||
27 | Reviewed-by: yuchenlin <yuchenlin@synology.com> | ||
28 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
29 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | 30 | --- |
10 | block/reqlist.c | 3 ++- | 31 | block/vmdk.c | 11 ++++++++--- |
11 | 1 file changed, 2 insertions(+), 1 deletion(-) | 32 | 1 file changed, 8 insertions(+), 3 deletions(-) |
12 | 33 | ||
13 | diff --git a/block/reqlist.c b/block/reqlist.c | 34 | diff --git a/block/vmdk.c b/block/vmdk.c |
14 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/reqlist.c | 36 | --- a/block/vmdk.c |
16 | +++ b/block/reqlist.c | 37 | +++ b/block/vmdk.c |
17 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, |
18 | */ | 39 | return -EFBIG; |
19 | 40 | } | |
20 | #include "qemu/osdep.h" | 41 | if (l1_size > 512 * 1024 * 1024) { |
21 | +#include "qemu/range.h" | 42 | - /* Although with big capacity and small l1_entry_sectors, we can get a |
22 | 43 | + /* | |
23 | #include "block/reqlist.h" | 44 | + * Although with big capacity and small l1_entry_sectors, we can get a |
24 | 45 | * big l1_size, we don't want unbounded value to allocate the table. | |
25 | @@ -XXX,XX +XXX,XX @@ BlockReq *reqlist_find_conflict(BlockReqList *reqs, int64_t offset, | 46 | - * Limit it to 512M, which is 16PB for default cluster and L2 table |
26 | BlockReq *r; | 47 | - * size */ |
27 | 48 | + * Limit it to 512M, which is: | |
28 | QLIST_FOREACH(r, reqs, list) { | 49 | + * 16PB - for default "Hosted Sparse Extent" (VMDK4) |
29 | - if (offset + bytes > r->offset && offset < r->offset + r->bytes) { | 50 | + * cluster size: 64KB, L2 table size: 512 entries |
30 | + if (ranges_overlap(offset, bytes, r->offset, r->bytes)) { | 51 | + * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) |
31 | return r; | 52 | + * cluster size: 512B, L2 table size: 4096 entries |
32 | } | 53 | + */ |
54 | error_setg(errp, "L1 size too big"); | ||
55 | return -EFBIG; | ||
33 | } | 56 | } |
34 | -- | 57 | -- |
35 | 2.34.1 | 58 | 2.21.0 |
59 | |||
60 | diff view generated by jsdifflib |
1 | When we still have an AIOCB registered for DMA operations, we try to | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | settle the respective operation by draining the BlockBackend associated | ||
3 | with the IDE device. | ||
4 | 2 | ||
5 | However, this assumes that every DMA operation is associated with an | 3 | 512M of L1 entries is a very loose bound, only 32M are required to store |
6 | increment of the BlockBackend’s in-flight counter (e.g. through some | 4 | the maximal supported VMDK file size of 2TB. |
7 | ongoing I/O operation), so that draining the BB until its in-flight | ||
8 | counter reaches 0 will settle all DMA operations. That is not the case: | ||
9 | For TRIM, the guest can issue a zero-length operation that will not | ||
10 | result in any I/O operation forwarded to the BlockBackend, and also not | ||
11 | increment the in-flight counter in any other way. In such a case, | ||
12 | blk_drain() will be a no-op if no other operations are in flight. | ||
13 | 5 | ||
14 | It is clear that if blk_drain() is a no-op, the value of | 6 | Fixed qemu-iotest 59# - now failure occures before on impossible L1 |
15 | s->bus->dma->aiocb will not change between checking it in the `if` | 7 | table size. |
16 | condition and asserting that it is NULL after blk_drain(). | ||
17 | 8 | ||
18 | The particular problem is that ide_issue_trim() creates a BH | 9 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> |
19 | (ide_trim_bh_cb()) to settle the TRIM request: iocb->common.cb() is | 10 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> |
20 | ide_dma_cb(), which will either create a new request, or find the | 11 | Reviewed-by: Liran Alon <liran.alon@oracle.com> |
21 | transfer to be done and call ide_set_inactive(), which clears | 12 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> |
22 | s->bus->dma->aiocb. Therefore, the blk_drain() must wait for | 13 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> |
23 | ide_trim_bh_cb() to run, which currently it will not always do. | 14 | Message-id: 20190620091057.47441-3-shmuel.eiderman@oracle.com |
15 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
16 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
17 | --- | ||
18 | block/vmdk.c | 13 +++++++------ | ||
19 | tests/qemu-iotests/059.out | 2 +- | ||
20 | 2 files changed, 8 insertions(+), 7 deletions(-) | ||
24 | 21 | ||
25 | To fix this issue, we increment the BlockBackend's in-flight counter | 22 | diff --git a/block/vmdk.c b/block/vmdk.c |
26 | when the TRIM operation begins (in ide_issue_trim(), when the | ||
27 | ide_trim_bh_cb() BH is created) and decrement it when ide_trim_bh_cb() | ||
28 | is done. | ||
29 | |||
30 | Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2029980 | ||
31 | Suggested-by: Paolo Bonzini <pbonzini@redhat.com> | ||
32 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
33 | Message-Id: <20220120142259.120189-1-hreitz@redhat.com> | ||
34 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
35 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
36 | Tested-by: John Snow <jsnow@redhat.com> | ||
37 | --- | ||
38 | hw/ide/core.c | 7 +++++++ | ||
39 | 1 file changed, 7 insertions(+) | ||
40 | |||
41 | diff --git a/hw/ide/core.c b/hw/ide/core.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/hw/ide/core.c | 24 | --- a/block/vmdk.c |
44 | +++ b/hw/ide/core.c | 25 | +++ b/block/vmdk.c |
45 | @@ -XXX,XX +XXX,XX @@ static const AIOCBInfo trim_aiocb_info = { | 26 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, |
46 | static void ide_trim_bh_cb(void *opaque) | 27 | error_setg(errp, "Invalid granularity, image may be corrupt"); |
47 | { | 28 | return -EFBIG; |
48 | TrimAIOCB *iocb = opaque; | 29 | } |
49 | + BlockBackend *blk = iocb->s->blk; | 30 | - if (l1_size > 512 * 1024 * 1024) { |
50 | 31 | + if (l1_size > 32 * 1024 * 1024) { | |
51 | iocb->common.cb(iocb->common.opaque, iocb->ret); | 32 | /* |
52 | 33 | * Although with big capacity and small l1_entry_sectors, we can get a | |
53 | qemu_bh_delete(iocb->bh); | 34 | * big l1_size, we don't want unbounded value to allocate the table. |
54 | iocb->bh = NULL; | 35 | - * Limit it to 512M, which is: |
55 | qemu_aio_unref(iocb); | 36 | - * 16PB - for default "Hosted Sparse Extent" (VMDK4) |
56 | + | 37 | - * cluster size: 64KB, L2 table size: 512 entries |
57 | + /* Paired with an increment in ide_issue_trim() */ | 38 | - * 1PB - for default "ESXi Host Sparse Extent" (VMDK3/vmfsSparse) |
58 | + blk_dec_in_flight(blk); | 39 | - * cluster size: 512B, L2 table size: 4096 entries |
59 | } | 40 | + * Limit it to 32M, which is enough to store: |
60 | 41 | + * 8TB - for both VMDK3 & VMDK4 with | |
61 | static void ide_issue_trim_cb(void *opaque, int ret) | 42 | + * minimal cluster size: 512B |
62 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *ide_issue_trim( | 43 | + * minimal L2 table size: 512 entries |
63 | IDEState *s = opaque; | 44 | + * 8 TB is still more than the maximal value supported for |
64 | TrimAIOCB *iocb; | 45 | + * VMDK3 & VMDK4 which is 2TB. |
65 | 46 | */ | |
66 | + /* Paired with a decrement in ide_trim_bh_cb() */ | 47 | error_setg(errp, "L1 size too big"); |
67 | + blk_inc_in_flight(s->blk); | 48 | return -EFBIG; |
68 | + | 49 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out |
69 | iocb = blk_aio_get(&trim_aiocb_info, s->blk, cb, cb_opaque); | 50 | index XXXXXXX..XXXXXXX 100644 |
70 | iocb->s = s; | 51 | --- a/tests/qemu-iotests/059.out |
71 | iocb->bh = qemu_bh_new(ide_trim_bh_cb, iocb); | 52 | +++ b/tests/qemu-iotests/059.out |
53 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | ||
54 | 0x140000000 0x10000 0x50000 TEST_DIR/t-s003.vmdk | ||
55 | |||
56 | === Testing afl image with a very large capacity === | ||
57 | -qemu-img: Can't get image size 'TEST_DIR/afl9.IMGFMT': File too large | ||
58 | +qemu-img: Could not open 'TEST_DIR/afl9.IMGFMT': L1 size too big | ||
59 | *** done | ||
72 | -- | 60 | -- |
73 | 2.34.1 | 61 | 2.21.0 |
74 | 62 | ||
75 | 63 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Sam Eiderman <shmuel.eiderman@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | The new block driver simply utilizes snapshot-access API of underlying | 3 | Until ESXi 6.5 VMware used the vmfsSparse format for snapshots (VMDK3 in |
4 | block node. | 4 | QEMU). |
5 | 5 | ||
6 | In further patches we want to use it like this: | 6 | This format was lacking in the following: |
7 | 7 | ||
8 | [guest] [NBD export] | 8 | * Grain directory (L1) and grain table (L2) entries were 32-bit, |
9 | | | | 9 | allowing access to only 2TB (slightly less) of data. |
10 | | root | root | 10 | * The grain size (default) was 512 bytes - leading to data |
11 | v file v | 11 | fragmentation and many grain tables. |
12 | [copy-before-write]<------[snapshot-access] | 12 | * For space reclamation purposes, it was necessary to find all the |
13 | | | | 13 | grains which are not pointed to by any grain table - so a reverse |
14 | | file | target | 14 | mapping of "offset of grain in vmdk" to "grain table" must be |
15 | v v | 15 | constructed - which takes large amounts of CPU/RAM. |
16 | [active-disk] [temp.img] | 16 | |
17 | 17 | The format specification can be found in VMware's documentation: | |
18 | This way, NBD client will be able to read snapshotted state of active | 18 | https://www.vmware.com/support/developer/vddk/vmdk_50_technote.pdf |
19 | disk, when active disk is continued to be written by guest. This is | 19 | |
20 | known as "fleecing", and currently uses another scheme based on qcow2 | 20 | In ESXi 6.5, to support snapshot files larger than 2TB, a new format was |
21 | temporary image which backing file is active-disk. New scheme comes | 21 | introduced: SESparse (Space Efficient). |
22 | with benefits - see next commit. | 22 | |
23 | 23 | This format fixes the above issues: | |
24 | The other possible application is exporting internal snapshots of | 24 | |
25 | qcow2, like this: | 25 | * All entries are now 64-bit. |
26 | 26 | * The grain size (default) is 4KB. | |
27 | [guest] [NBD export] | 27 | * Grain directory and grain tables are now located at the beginning |
28 | | | | 28 | of the file. |
29 | | root | root | 29 | + seSparse format reserves space for all grain tables. |
30 | v file v | 30 | + Grain tables can be addressed using an index. |
31 | [qcow2]<---------[snapshot-access] | 31 | + Grains are located in the end of the file and can also be |
32 | 32 | addressed with an index. | |
33 | For this, we'll need to implement snapshot-access API handlers in | 33 | - seSparse vmdks of large disks (64TB) have huge preallocated |
34 | qcow2 driver, and improve snapshot-access block driver (and API) to | 34 | headers - mainly due to L2 tables, even for empty snapshots. |
35 | make it possible to select snapshot by name. Another thing to improve | 35 | * The header contains a reverse mapping ("backmap") of "offset of |
36 | is size of snapshot. Now for simplicity we just use size of bs->file, | 36 | grain in vmdk" to "grain table" and a bitmap ("free bitmap") which |
37 | which is OK for backup, but for qcow2 snapshots export we'll need to | 37 | specifies for each grain - whether it is allocated or not. |
38 | imporve snapshot-access API to get size of snapshot. | 38 | Using these data structures we can implement space reclamation |
39 | 39 | efficiently. | |
40 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 40 | * Due to the fact that the header now maintains two mappings: |
41 | Message-Id: <20220303194349.2304213-12-vsementsov@virtuozzo.com> | 41 | * The regular one (grain directory & grain tables) |
42 | [hreitz: Rebased on block GS/IO split] | 42 | * A reverse one (backmap and free bitmap) |
43 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 43 | These data structures can lose consistency upon crash and result |
44 | in a corrupted VMDK. | ||
45 | Therefore, a journal is also added to the VMDK and is replayed | ||
46 | when the VMware reopens the file after a crash. | ||
47 | |||
48 | Since ESXi 6.7 - SESparse is the only snapshot format available. | ||
49 | |||
50 | Unfortunately, VMware does not provide documentation regarding the new | ||
51 | seSparse format. | ||
52 | |||
53 | This commit is based on black-box research of the seSparse format. | ||
54 | Various in-guest block operations and their effect on the snapshot file | ||
55 | were tested. | ||
56 | |||
57 | The only VMware provided source of information (regarding the underlying | ||
58 | implementation) was a log file on the ESXi: | ||
59 | |||
60 | /var/log/hostd.log | ||
61 | |||
62 | Whenever an seSparse snapshot is created - the log is being populated | ||
63 | with seSparse records. | ||
64 | |||
65 | Relevant log records are of the form: | ||
66 | |||
67 | [...] Const Header: | ||
68 | [...] constMagic = 0xcafebabe | ||
69 | [...] version = 2.1 | ||
70 | [...] capacity = 204800 | ||
71 | [...] grainSize = 8 | ||
72 | [...] grainTableSize = 64 | ||
73 | [...] flags = 0 | ||
74 | [...] Extents: | ||
75 | [...] Header : <1 : 1> | ||
76 | [...] JournalHdr : <2 : 2> | ||
77 | [...] Journal : <2048 : 2048> | ||
78 | [...] GrainDirectory : <4096 : 2048> | ||
79 | [...] GrainTables : <6144 : 2048> | ||
80 | [...] FreeBitmap : <8192 : 2048> | ||
81 | [...] BackMap : <10240 : 2048> | ||
82 | [...] Grain : <12288 : 204800> | ||
83 | [...] Volatile Header: | ||
84 | [...] volatileMagic = 0xcafecafe | ||
85 | [...] FreeGTNumber = 0 | ||
86 | [...] nextTxnSeqNumber = 0 | ||
87 | [...] replayJournal = 0 | ||
88 | |||
89 | The sizes that are seen in the log file are in sectors. | ||
90 | Extents are of the following format: <offset : size> | ||
91 | |||
92 | This commit is a strict implementation which enforces: | ||
93 | * magics | ||
94 | * version number 2.1 | ||
95 | * grain size of 8 sectors (4KB) | ||
96 | * grain table size of 64 sectors | ||
97 | * zero flags | ||
98 | * extent locations | ||
99 | |||
100 | Additionally, this commit proivdes only a subset of the functionality | ||
101 | offered by seSparse's format: | ||
102 | * Read-only | ||
103 | * No journal replay | ||
104 | * No space reclamation | ||
105 | * No unmap support | ||
106 | |||
107 | Hence, journal header, journal, free bitmap and backmap extents are | ||
108 | unused, only the "classic" (L1 -> L2 -> data) grain access is | ||
109 | implemented. | ||
110 | |||
111 | However there are several differences in the grain access itself. | ||
112 | Grain directory (L1): | ||
113 | * Grain directory entries are indexes (not offsets) to grain | ||
114 | tables. | ||
115 | * Valid grain directory entries have their highest nibble set to | ||
116 | 0x1. | ||
117 | * Since grain tables are always located in the beginning of the | ||
118 | file - the index can fit into 32 bits - so we can use its low | ||
119 | part if it's valid. | ||
120 | Grain table (L2): | ||
121 | * Grain table entries are indexes (not offsets) to grains. | ||
122 | * If the highest nibble of the entry is: | ||
123 | 0x0: | ||
124 | The grain in not allocated. | ||
125 | The rest of the bytes are 0. | ||
126 | 0x1: | ||
127 | The grain is unmapped - guest sees a zero grain. | ||
128 | The rest of the bits point to the previously mapped grain, | ||
129 | see 0x3 case. | ||
130 | 0x2: | ||
131 | The grain is zero. | ||
132 | 0x3: | ||
133 | The grain is allocated - to get the index calculate: | ||
134 | ((entry & 0x0fff000000000000) >> 48) | | ||
135 | ((entry & 0x0000ffffffffffff) << 12) | ||
136 | * The difference between 0x1 and 0x2 is that 0x1 is an unallocated | ||
137 | grain which results from the guest using sg_unmap to unmap the | ||
138 | grain - but the grain itself still exists in the grain extent - a | ||
139 | space reclamation procedure should delete it. | ||
140 | Unmapping a zero grain has no effect (0x2 will not change to 0x1) | ||
141 | but unmapping an unallocated grain will (0x0 to 0x1) - naturally. | ||
142 | |||
143 | In order to implement seSparse some fields had to be changed to support | ||
144 | both 32-bit and 64-bit entry sizes. | ||
145 | |||
146 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> | ||
147 | Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com> | ||
148 | Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com> | ||
149 | Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com> | ||
150 | Message-id: 20190620091057.47441-4-shmuel.eiderman@oracle.com | ||
151 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
44 | --- | 152 | --- |
45 | qapi/block-core.json | 4 +- | 153 | block/vmdk.c | 358 ++++++++++++++++++++++++++++++++++++++++++++++++--- |
46 | include/block/block_int-common.h | 6 ++ | 154 | 1 file changed, 342 insertions(+), 16 deletions(-) |
47 | block/snapshot-access.c | 132 +++++++++++++++++++++++++++++++ | 155 | |
48 | MAINTAINERS | 1 + | 156 | diff --git a/block/vmdk.c b/block/vmdk.c |
49 | block/meson.build | 1 + | ||
50 | 5 files changed, 143 insertions(+), 1 deletion(-) | ||
51 | create mode 100644 block/snapshot-access.c | ||
52 | |||
53 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
54 | index XXXXXXX..XXXXXXX 100644 | 157 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/qapi/block-core.json | 158 | --- a/block/vmdk.c |
56 | +++ b/qapi/block-core.json | 159 | +++ b/block/vmdk.c |
57 | @@ -XXX,XX +XXX,XX @@ | 160 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
58 | # @blkreplay: Since 4.2 | 161 | uint16_t compressAlgorithm; |
59 | # @compress: Since 5.0 | 162 | } QEMU_PACKED VMDK4Header; |
60 | # @copy-before-write: Since 6.2 | 163 | |
61 | +# @snapshot-access: Since 7.0 | 164 | +typedef struct VMDKSESparseConstHeader { |
62 | # | 165 | + uint64_t magic; |
63 | # Since: 2.9 | 166 | + uint64_t version; |
64 | ## | 167 | + uint64_t capacity; |
65 | { 'enum': 'BlockdevDriver', | 168 | + uint64_t grain_size; |
66 | 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', | 169 | + uint64_t grain_table_size; |
67 | 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg', | 170 | + uint64_t flags; |
68 | - 'file', 'ftp', 'ftps', 'gluster', | 171 | + uint64_t reserved1; |
69 | + 'file', 'snapshot-access', 'ftp', 'ftps', 'gluster', | 172 | + uint64_t reserved2; |
70 | {'name': 'host_cdrom', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, | 173 | + uint64_t reserved3; |
71 | {'name': 'host_device', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, | 174 | + uint64_t reserved4; |
72 | 'http', 'https', 'iscsi', | 175 | + uint64_t volatile_header_offset; |
73 | @@ -XXX,XX +XXX,XX @@ | 176 | + uint64_t volatile_header_size; |
74 | 'rbd': 'BlockdevOptionsRbd', | 177 | + uint64_t journal_header_offset; |
75 | 'replication': { 'type': 'BlockdevOptionsReplication', | 178 | + uint64_t journal_header_size; |
76 | 'if': 'CONFIG_REPLICATION' }, | 179 | + uint64_t journal_offset; |
77 | + 'snapshot-access': 'BlockdevOptionsGenericFormat', | 180 | + uint64_t journal_size; |
78 | 'ssh': 'BlockdevOptionsSsh', | 181 | + uint64_t grain_dir_offset; |
79 | 'throttle': 'BlockdevOptionsThrottle', | 182 | + uint64_t grain_dir_size; |
80 | 'vdi': 'BlockdevOptionsGenericFormat', | 183 | + uint64_t grain_tables_offset; |
81 | diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h | 184 | + uint64_t grain_tables_size; |
82 | index XXXXXXX..XXXXXXX 100644 | 185 | + uint64_t free_bitmap_offset; |
83 | --- a/include/block/block_int-common.h | 186 | + uint64_t free_bitmap_size; |
84 | +++ b/include/block/block_int-common.h | 187 | + uint64_t backmap_offset; |
85 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | 188 | + uint64_t backmap_size; |
86 | * in generic block-layer: no serializing, no alignment, no tracked | 189 | + uint64_t grains_offset; |
87 | * requests. So, block-driver that realizes these APIs is fully responsible | 190 | + uint64_t grains_size; |
88 | * for synchronization between snapshot-access API and normal IO requests. | 191 | + uint8_t pad[304]; |
89 | + * | 192 | +} QEMU_PACKED VMDKSESparseConstHeader; |
90 | + * TODO: To be able to support qcow2's internal snapshots, this API will | 193 | + |
91 | + * need to be extended to: | 194 | +typedef struct VMDKSESparseVolatileHeader { |
92 | + * - be able to select a specific snapshot | 195 | + uint64_t magic; |
93 | + * - receive the snapshot's actual length (which may differ from bs's | 196 | + uint64_t free_gt_number; |
94 | + * length) | 197 | + uint64_t next_txn_seq_number; |
95 | */ | 198 | + uint64_t replay_journal; |
96 | int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs, | 199 | + uint8_t pad[480]; |
97 | int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); | 200 | +} QEMU_PACKED VMDKSESparseVolatileHeader; |
98 | diff --git a/block/snapshot-access.c b/block/snapshot-access.c | 201 | + |
99 | new file mode 100644 | 202 | #define L2_CACHE_SIZE 16 |
100 | index XXXXXXX..XXXXXXX | 203 | |
101 | --- /dev/null | 204 | typedef struct VmdkExtent { |
102 | +++ b/block/snapshot-access.c | 205 | @@ -XXX,XX +XXX,XX @@ typedef struct VmdkExtent { |
103 | @@ -XXX,XX +XXX,XX @@ | 206 | bool compressed; |
104 | +/* | 207 | bool has_marker; |
105 | + * snapshot_access block driver | 208 | bool has_zero_grain; |
106 | + * | 209 | + bool sesparse; |
107 | + * Copyright (c) 2022 Virtuozzo International GmbH. | 210 | + uint64_t sesparse_l2_tables_offset; |
108 | + * | 211 | + uint64_t sesparse_clusters_offset; |
109 | + * Author: | 212 | + int32_t entry_size; |
110 | + * Sementsov-Ogievskiy Vladimir <vsementsov@virtuozzo.com> | 213 | int version; |
111 | + * | 214 | int64_t sectors; |
112 | + * This program is free software; you can redistribute it and/or modify | 215 | int64_t end_sector; |
113 | + * it under the terms of the GNU General Public License as published by | 216 | int64_t flat_start_offset; |
114 | + * the Free Software Foundation; either version 2 of the License, or | 217 | int64_t l1_table_offset; |
115 | + * (at your option) any later version. | 218 | int64_t l1_backup_table_offset; |
116 | + * | 219 | - uint32_t *l1_table; |
117 | + * This program is distributed in the hope that it will be useful, | 220 | + void *l1_table; |
118 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 221 | uint32_t *l1_backup_table; |
119 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 222 | unsigned int l1_size; |
120 | + * GNU General Public License for more details. | 223 | uint32_t l1_entry_sectors; |
121 | + * | 224 | |
122 | + * You should have received a copy of the GNU General Public License | 225 | unsigned int l2_size; |
123 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | 226 | - uint32_t *l2_cache; |
124 | + */ | 227 | + void *l2_cache; |
125 | + | 228 | uint32_t l2_cache_offsets[L2_CACHE_SIZE]; |
126 | +#include "qemu/osdep.h" | 229 | uint32_t l2_cache_counts[L2_CACHE_SIZE]; |
127 | + | 230 | |
128 | +#include "sysemu/block-backend.h" | 231 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, |
129 | +#include "qemu/cutils.h" | 232 | * minimal L2 table size: 512 entries |
130 | +#include "block/block_int.h" | 233 | * 8 TB is still more than the maximal value supported for |
131 | + | 234 | * VMDK3 & VMDK4 which is 2TB. |
132 | +static coroutine_fn int | 235 | + * 64TB - for "ESXi seSparse Extent" |
133 | +snapshot_access_co_preadv_part(BlockDriverState *bs, | 236 | + * minimal cluster size: 512B (default is 4KB) |
134 | + int64_t offset, int64_t bytes, | 237 | + * L2 table size: 4096 entries (const). |
135 | + QEMUIOVector *qiov, size_t qiov_offset, | 238 | + * 64TB is more than the maximal value supported for |
136 | + BdrvRequestFlags flags) | 239 | + * seSparse VMDKs (which is slightly less than 64TB) |
240 | */ | ||
241 | error_setg(errp, "L1 size too big"); | ||
242 | return -EFBIG; | ||
243 | @@ -XXX,XX +XXX,XX @@ static int vmdk_add_extent(BlockDriverState *bs, | ||
244 | extent->l2_size = l2_size; | ||
245 | extent->cluster_sectors = flat ? sectors : cluster_sectors; | ||
246 | extent->next_cluster_sector = ROUND_UP(nb_sectors, cluster_sectors); | ||
247 | + extent->entry_size = sizeof(uint32_t); | ||
248 | |||
249 | if (s->num_extents > 1) { | ||
250 | extent->end_sector = (*(extent - 1)).end_sector + extent->sectors; | ||
251 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
252 | int i; | ||
253 | |||
254 | /* read the L1 table */ | ||
255 | - l1_size = extent->l1_size * sizeof(uint32_t); | ||
256 | + l1_size = extent->l1_size * extent->entry_size; | ||
257 | extent->l1_table = g_try_malloc(l1_size); | ||
258 | if (l1_size && extent->l1_table == NULL) { | ||
259 | return -ENOMEM; | ||
260 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
261 | goto fail_l1; | ||
262 | } | ||
263 | for (i = 0; i < extent->l1_size; i++) { | ||
264 | - le32_to_cpus(&extent->l1_table[i]); | ||
265 | + if (extent->entry_size == sizeof(uint64_t)) { | ||
266 | + le64_to_cpus((uint64_t *)extent->l1_table + i); | ||
267 | + } else { | ||
268 | + assert(extent->entry_size == sizeof(uint32_t)); | ||
269 | + le32_to_cpus((uint32_t *)extent->l1_table + i); | ||
270 | + } | ||
271 | } | ||
272 | |||
273 | if (extent->l1_backup_table_offset) { | ||
274 | + assert(!extent->sesparse); | ||
275 | extent->l1_backup_table = g_try_malloc(l1_size); | ||
276 | if (l1_size && extent->l1_backup_table == NULL) { | ||
277 | ret = -ENOMEM; | ||
278 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
279 | } | ||
280 | |||
281 | extent->l2_cache = | ||
282 | - g_new(uint32_t, extent->l2_size * L2_CACHE_SIZE); | ||
283 | + g_malloc(extent->entry_size * extent->l2_size * L2_CACHE_SIZE); | ||
284 | return 0; | ||
285 | fail_l1b: | ||
286 | g_free(extent->l1_backup_table); | ||
287 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, | ||
288 | return ret; | ||
289 | } | ||
290 | |||
291 | +#define SESPARSE_CONST_HEADER_MAGIC UINT64_C(0x00000000cafebabe) | ||
292 | +#define SESPARSE_VOLATILE_HEADER_MAGIC UINT64_C(0x00000000cafecafe) | ||
293 | + | ||
294 | +/* Strict checks - format not officially documented */ | ||
295 | +static int check_se_sparse_const_header(VMDKSESparseConstHeader *header, | ||
296 | + Error **errp) | ||
137 | +{ | 297 | +{ |
138 | + if (flags) { | 298 | + header->magic = le64_to_cpu(header->magic); |
139 | + return -ENOTSUP; | 299 | + header->version = le64_to_cpu(header->version); |
140 | + } | 300 | + header->grain_size = le64_to_cpu(header->grain_size); |
141 | + | 301 | + header->grain_table_size = le64_to_cpu(header->grain_table_size); |
142 | + return bdrv_co_preadv_snapshot(bs->file, offset, bytes, qiov, qiov_offset); | 302 | + header->flags = le64_to_cpu(header->flags); |
143 | +} | 303 | + header->reserved1 = le64_to_cpu(header->reserved1); |
144 | + | 304 | + header->reserved2 = le64_to_cpu(header->reserved2); |
145 | +static int coroutine_fn | 305 | + header->reserved3 = le64_to_cpu(header->reserved3); |
146 | +snapshot_access_co_block_status(BlockDriverState *bs, | 306 | + header->reserved4 = le64_to_cpu(header->reserved4); |
147 | + bool want_zero, int64_t offset, | 307 | + |
148 | + int64_t bytes, int64_t *pnum, | 308 | + header->volatile_header_offset = |
149 | + int64_t *map, BlockDriverState **file) | 309 | + le64_to_cpu(header->volatile_header_offset); |
150 | +{ | 310 | + header->volatile_header_size = le64_to_cpu(header->volatile_header_size); |
151 | + return bdrv_co_snapshot_block_status(bs->file->bs, want_zero, offset, | 311 | + |
152 | + bytes, pnum, map, file); | 312 | + header->journal_header_offset = le64_to_cpu(header->journal_header_offset); |
153 | +} | 313 | + header->journal_header_size = le64_to_cpu(header->journal_header_size); |
154 | + | 314 | + |
155 | +static int coroutine_fn snapshot_access_co_pdiscard(BlockDriverState *bs, | 315 | + header->journal_offset = le64_to_cpu(header->journal_offset); |
156 | + int64_t offset, int64_t bytes) | 316 | + header->journal_size = le64_to_cpu(header->journal_size); |
157 | +{ | 317 | + |
158 | + return bdrv_co_pdiscard_snapshot(bs->file->bs, offset, bytes); | 318 | + header->grain_dir_offset = le64_to_cpu(header->grain_dir_offset); |
159 | +} | 319 | + header->grain_dir_size = le64_to_cpu(header->grain_dir_size); |
160 | + | 320 | + |
161 | +static int coroutine_fn | 321 | + header->grain_tables_offset = le64_to_cpu(header->grain_tables_offset); |
162 | +snapshot_access_co_pwrite_zeroes(BlockDriverState *bs, | 322 | + header->grain_tables_size = le64_to_cpu(header->grain_tables_size); |
163 | + int64_t offset, int64_t bytes, | 323 | + |
164 | + BdrvRequestFlags flags) | 324 | + header->free_bitmap_offset = le64_to_cpu(header->free_bitmap_offset); |
165 | +{ | 325 | + header->free_bitmap_size = le64_to_cpu(header->free_bitmap_size); |
166 | + return -ENOTSUP; | 326 | + |
167 | +} | 327 | + header->backmap_offset = le64_to_cpu(header->backmap_offset); |
168 | + | 328 | + header->backmap_size = le64_to_cpu(header->backmap_size); |
169 | +static coroutine_fn int | 329 | + |
170 | +snapshot_access_co_pwritev_part(BlockDriverState *bs, | 330 | + header->grains_offset = le64_to_cpu(header->grains_offset); |
171 | + int64_t offset, int64_t bytes, | 331 | + header->grains_size = le64_to_cpu(header->grains_size); |
172 | + QEMUIOVector *qiov, size_t qiov_offset, | 332 | + |
173 | + BdrvRequestFlags flags) | 333 | + if (header->magic != SESPARSE_CONST_HEADER_MAGIC) { |
174 | +{ | 334 | + error_setg(errp, "Bad const header magic: 0x%016" PRIx64, |
175 | + return -ENOTSUP; | 335 | + header->magic); |
176 | +} | ||
177 | + | ||
178 | + | ||
179 | +static void snapshot_access_refresh_filename(BlockDriverState *bs) | ||
180 | +{ | ||
181 | + pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), | ||
182 | + bs->file->bs->filename); | ||
183 | +} | ||
184 | + | ||
185 | +static int snapshot_access_open(BlockDriverState *bs, QDict *options, int flags, | ||
186 | + Error **errp) | ||
187 | +{ | ||
188 | + bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
189 | + BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY, | ||
190 | + false, errp); | ||
191 | + if (!bs->file) { | ||
192 | + return -EINVAL; | 336 | + return -EINVAL; |
193 | + } | 337 | + } |
194 | + | 338 | + |
195 | + bs->total_sectors = bs->file->bs->total_sectors; | 339 | + if (header->version != 0x0000000200000001) { |
340 | + error_setg(errp, "Unsupported version: 0x%016" PRIx64, | ||
341 | + header->version); | ||
342 | + return -ENOTSUP; | ||
343 | + } | ||
344 | + | ||
345 | + if (header->grain_size != 8) { | ||
346 | + error_setg(errp, "Unsupported grain size: %" PRIu64, | ||
347 | + header->grain_size); | ||
348 | + return -ENOTSUP; | ||
349 | + } | ||
350 | + | ||
351 | + if (header->grain_table_size != 64) { | ||
352 | + error_setg(errp, "Unsupported grain table size: %" PRIu64, | ||
353 | + header->grain_table_size); | ||
354 | + return -ENOTSUP; | ||
355 | + } | ||
356 | + | ||
357 | + if (header->flags != 0) { | ||
358 | + error_setg(errp, "Unsupported flags: 0x%016" PRIx64, | ||
359 | + header->flags); | ||
360 | + return -ENOTSUP; | ||
361 | + } | ||
362 | + | ||
363 | + if (header->reserved1 != 0 || header->reserved2 != 0 || | ||
364 | + header->reserved3 != 0 || header->reserved4 != 0) { | ||
365 | + error_setg(errp, "Unsupported reserved bits:" | ||
366 | + " 0x%016" PRIx64 " 0x%016" PRIx64 | ||
367 | + " 0x%016" PRIx64 " 0x%016" PRIx64, | ||
368 | + header->reserved1, header->reserved2, | ||
369 | + header->reserved3, header->reserved4); | ||
370 | + return -ENOTSUP; | ||
371 | + } | ||
372 | + | ||
373 | + /* check that padding is 0 */ | ||
374 | + if (!buffer_is_zero(header->pad, sizeof(header->pad))) { | ||
375 | + error_setg(errp, "Unsupported non-zero const header padding"); | ||
376 | + return -ENOTSUP; | ||
377 | + } | ||
196 | + | 378 | + |
197 | + return 0; | 379 | + return 0; |
198 | +} | 380 | +} |
199 | + | 381 | + |
200 | +static void snapshot_access_child_perm(BlockDriverState *bs, BdrvChild *c, | 382 | +static int check_se_sparse_volatile_header(VMDKSESparseVolatileHeader *header, |
201 | + BdrvChildRole role, | 383 | + Error **errp) |
202 | + BlockReopenQueue *reopen_queue, | ||
203 | + uint64_t perm, uint64_t shared, | ||
204 | + uint64_t *nperm, uint64_t *nshared) | ||
205 | +{ | 384 | +{ |
206 | + /* | 385 | + header->magic = le64_to_cpu(header->magic); |
207 | + * Currently, we don't need any permissions. If bs->file provides | 386 | + header->free_gt_number = le64_to_cpu(header->free_gt_number); |
208 | + * snapshot-access API, we can use it. | 387 | + header->next_txn_seq_number = le64_to_cpu(header->next_txn_seq_number); |
209 | + */ | 388 | + header->replay_journal = le64_to_cpu(header->replay_journal); |
210 | + *nperm = 0; | 389 | + |
211 | + *nshared = BLK_PERM_ALL; | 390 | + if (header->magic != SESPARSE_VOLATILE_HEADER_MAGIC) { |
391 | + error_setg(errp, "Bad volatile header magic: 0x%016" PRIx64, | ||
392 | + header->magic); | ||
393 | + return -EINVAL; | ||
394 | + } | ||
395 | + | ||
396 | + if (header->replay_journal) { | ||
397 | + error_setg(errp, "Image is dirty, Replaying journal not supported"); | ||
398 | + return -ENOTSUP; | ||
399 | + } | ||
400 | + | ||
401 | + /* check that padding is 0 */ | ||
402 | + if (!buffer_is_zero(header->pad, sizeof(header->pad))) { | ||
403 | + error_setg(errp, "Unsupported non-zero volatile header padding"); | ||
404 | + return -ENOTSUP; | ||
405 | + } | ||
406 | + | ||
407 | + return 0; | ||
212 | +} | 408 | +} |
213 | + | 409 | + |
214 | +BlockDriver bdrv_snapshot_access_drv = { | 410 | +static int vmdk_open_se_sparse(BlockDriverState *bs, |
215 | + .format_name = "snapshot-access", | 411 | + BdrvChild *file, |
216 | + | 412 | + int flags, Error **errp) |
217 | + .bdrv_open = snapshot_access_open, | ||
218 | + | ||
219 | + .bdrv_co_preadv_part = snapshot_access_co_preadv_part, | ||
220 | + .bdrv_co_pwritev_part = snapshot_access_co_pwritev_part, | ||
221 | + .bdrv_co_pwrite_zeroes = snapshot_access_co_pwrite_zeroes, | ||
222 | + .bdrv_co_pdiscard = snapshot_access_co_pdiscard, | ||
223 | + .bdrv_co_block_status = snapshot_access_co_block_status, | ||
224 | + | ||
225 | + .bdrv_refresh_filename = snapshot_access_refresh_filename, | ||
226 | + | ||
227 | + .bdrv_child_perm = snapshot_access_child_perm, | ||
228 | +}; | ||
229 | + | ||
230 | +static void snapshot_access_init(void) | ||
231 | +{ | 413 | +{ |
232 | + bdrv_register(&bdrv_snapshot_access_drv); | 414 | + int ret; |
415 | + VMDKSESparseConstHeader const_header; | ||
416 | + VMDKSESparseVolatileHeader volatile_header; | ||
417 | + VmdkExtent *extent; | ||
418 | + | ||
419 | + ret = bdrv_apply_auto_read_only(bs, | ||
420 | + "No write support for seSparse images available", errp); | ||
421 | + if (ret < 0) { | ||
422 | + return ret; | ||
423 | + } | ||
424 | + | ||
425 | + assert(sizeof(const_header) == SECTOR_SIZE); | ||
426 | + | ||
427 | + ret = bdrv_pread(file, 0, &const_header, sizeof(const_header)); | ||
428 | + if (ret < 0) { | ||
429 | + bdrv_refresh_filename(file->bs); | ||
430 | + error_setg_errno(errp, -ret, | ||
431 | + "Could not read const header from file '%s'", | ||
432 | + file->bs->filename); | ||
433 | + return ret; | ||
434 | + } | ||
435 | + | ||
436 | + /* check const header */ | ||
437 | + ret = check_se_sparse_const_header(&const_header, errp); | ||
438 | + if (ret < 0) { | ||
439 | + return ret; | ||
440 | + } | ||
441 | + | ||
442 | + assert(sizeof(volatile_header) == SECTOR_SIZE); | ||
443 | + | ||
444 | + ret = bdrv_pread(file, | ||
445 | + const_header.volatile_header_offset * SECTOR_SIZE, | ||
446 | + &volatile_header, sizeof(volatile_header)); | ||
447 | + if (ret < 0) { | ||
448 | + bdrv_refresh_filename(file->bs); | ||
449 | + error_setg_errno(errp, -ret, | ||
450 | + "Could not read volatile header from file '%s'", | ||
451 | + file->bs->filename); | ||
452 | + return ret; | ||
453 | + } | ||
454 | + | ||
455 | + /* check volatile header */ | ||
456 | + ret = check_se_sparse_volatile_header(&volatile_header, errp); | ||
457 | + if (ret < 0) { | ||
458 | + return ret; | ||
459 | + } | ||
460 | + | ||
461 | + ret = vmdk_add_extent(bs, file, false, | ||
462 | + const_header.capacity, | ||
463 | + const_header.grain_dir_offset * SECTOR_SIZE, | ||
464 | + 0, | ||
465 | + const_header.grain_dir_size * | ||
466 | + SECTOR_SIZE / sizeof(uint64_t), | ||
467 | + const_header.grain_table_size * | ||
468 | + SECTOR_SIZE / sizeof(uint64_t), | ||
469 | + const_header.grain_size, | ||
470 | + &extent, | ||
471 | + errp); | ||
472 | + if (ret < 0) { | ||
473 | + return ret; | ||
474 | + } | ||
475 | + | ||
476 | + extent->sesparse = true; | ||
477 | + extent->sesparse_l2_tables_offset = const_header.grain_tables_offset; | ||
478 | + extent->sesparse_clusters_offset = const_header.grains_offset; | ||
479 | + extent->entry_size = sizeof(uint64_t); | ||
480 | + | ||
481 | + ret = vmdk_init_tables(bs, extent, errp); | ||
482 | + if (ret) { | ||
483 | + /* free extent allocated by vmdk_add_extent */ | ||
484 | + vmdk_free_last_extent(bs); | ||
485 | + } | ||
486 | + | ||
487 | + return ret; | ||
233 | +} | 488 | +} |
234 | + | 489 | + |
235 | +block_init(snapshot_access_init); | 490 | static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, |
236 | diff --git a/MAINTAINERS b/MAINTAINERS | 491 | QDict *options, Error **errp); |
237 | index XXXXXXX..XXXXXXX 100644 | 492 | |
238 | --- a/MAINTAINERS | 493 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
239 | +++ b/MAINTAINERS | 494 | * RW [size in sectors] SPARSE "file-name.vmdk" |
240 | @@ -XXX,XX +XXX,XX @@ F: block/reqlist.c | 495 | * RW [size in sectors] VMFS "file-name.vmdk" |
241 | F: include/block/reqlist.h | 496 | * RW [size in sectors] VMFSSPARSE "file-name.vmdk" |
242 | F: block/copy-before-write.h | 497 | + * RW [size in sectors] SESPARSE "file-name.vmdk" |
243 | F: block/copy-before-write.c | 498 | */ |
244 | +F: block/snapshot-access.c | 499 | flat_offset = -1; |
245 | F: include/block/aio_task.h | 500 | matches = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, |
246 | F: block/aio_task.c | 501 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
247 | F: util/qemu-co-shared-resource.c | 502 | |
248 | diff --git a/block/meson.build b/block/meson.build | 503 | if (sectors <= 0 || |
249 | index XXXXXXX..XXXXXXX 100644 | 504 | (strcmp(type, "FLAT") && strcmp(type, "SPARSE") && |
250 | --- a/block/meson.build | 505 | - strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE")) || |
251 | +++ b/block/meson.build | 506 | + strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE") && |
252 | @@ -XXX,XX +XXX,XX @@ block_ss.add(files( | 507 | + strcmp(type, "SESPARSE")) || |
253 | 'raw-format.c', | 508 | (strcmp(access, "RW"))) { |
254 | 'reqlist.c', | 509 | continue; |
255 | 'snapshot.c', | 510 | } |
256 | + 'snapshot-access.c', | 511 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, |
257 | 'throttle-groups.c', | 512 | return ret; |
258 | 'throttle.c', | 513 | } |
259 | 'vhdx-endian.c', | 514 | extent = &s->extents[s->num_extents - 1]; |
515 | + } else if (!strcmp(type, "SESPARSE")) { | ||
516 | + ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); | ||
517 | + if (ret) { | ||
518 | + bdrv_unref_child(bs, extent_file); | ||
519 | + return ret; | ||
520 | + } | ||
521 | + extent = &s->extents[s->num_extents - 1]; | ||
522 | } else { | ||
523 | error_setg(errp, "Unsupported extent type '%s'", type); | ||
524 | bdrv_unref_child(bs, extent_file); | ||
525 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
526 | if (strcmp(ct, "monolithicFlat") && | ||
527 | strcmp(ct, "vmfs") && | ||
528 | strcmp(ct, "vmfsSparse") && | ||
529 | + strcmp(ct, "seSparse") && | ||
530 | strcmp(ct, "twoGbMaxExtentSparse") && | ||
531 | strcmp(ct, "twoGbMaxExtentFlat")) { | ||
532 | error_setg(errp, "Unsupported image type '%s'", ct); | ||
533 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
534 | { | ||
535 | unsigned int l1_index, l2_offset, l2_index; | ||
536 | int min_index, i, j; | ||
537 | - uint32_t min_count, *l2_table; | ||
538 | + uint32_t min_count; | ||
539 | + void *l2_table; | ||
540 | bool zeroed = false; | ||
541 | int64_t ret; | ||
542 | int64_t cluster_sector; | ||
543 | + unsigned int l2_size_bytes = extent->l2_size * extent->entry_size; | ||
544 | |||
545 | if (m_data) { | ||
546 | m_data->valid = 0; | ||
547 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
548 | if (l1_index >= extent->l1_size) { | ||
549 | return VMDK_ERROR; | ||
550 | } | ||
551 | - l2_offset = extent->l1_table[l1_index]; | ||
552 | + if (extent->sesparse) { | ||
553 | + uint64_t l2_offset_u64; | ||
554 | + | ||
555 | + assert(extent->entry_size == sizeof(uint64_t)); | ||
556 | + | ||
557 | + l2_offset_u64 = ((uint64_t *)extent->l1_table)[l1_index]; | ||
558 | + if (l2_offset_u64 == 0) { | ||
559 | + l2_offset = 0; | ||
560 | + } else if ((l2_offset_u64 & 0xffffffff00000000) != 0x1000000000000000) { | ||
561 | + /* | ||
562 | + * Top most nibble is 0x1 if grain table is allocated. | ||
563 | + * strict check - top most 4 bytes must be 0x10000000 since max | ||
564 | + * supported size is 64TB for disk - so no more than 64TB / 16MB | ||
565 | + * grain directories which is smaller than uint32, | ||
566 | + * where 16MB is the only supported default grain table coverage. | ||
567 | + */ | ||
568 | + return VMDK_ERROR; | ||
569 | + } else { | ||
570 | + l2_offset_u64 = l2_offset_u64 & 0x00000000ffffffff; | ||
571 | + l2_offset_u64 = extent->sesparse_l2_tables_offset + | ||
572 | + l2_offset_u64 * l2_size_bytes / SECTOR_SIZE; | ||
573 | + if (l2_offset_u64 > 0x00000000ffffffff) { | ||
574 | + return VMDK_ERROR; | ||
575 | + } | ||
576 | + l2_offset = (unsigned int)(l2_offset_u64); | ||
577 | + } | ||
578 | + } else { | ||
579 | + assert(extent->entry_size == sizeof(uint32_t)); | ||
580 | + l2_offset = ((uint32_t *)extent->l1_table)[l1_index]; | ||
581 | + } | ||
582 | if (!l2_offset) { | ||
583 | return VMDK_UNALLOC; | ||
584 | } | ||
585 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
586 | extent->l2_cache_counts[j] >>= 1; | ||
587 | } | ||
588 | } | ||
589 | - l2_table = extent->l2_cache + (i * extent->l2_size); | ||
590 | + l2_table = (char *)extent->l2_cache + (i * l2_size_bytes); | ||
591 | goto found; | ||
592 | } | ||
593 | } | ||
594 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
595 | min_index = i; | ||
596 | } | ||
597 | } | ||
598 | - l2_table = extent->l2_cache + (min_index * extent->l2_size); | ||
599 | + l2_table = (char *)extent->l2_cache + (min_index * l2_size_bytes); | ||
600 | BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD); | ||
601 | if (bdrv_pread(extent->file, | ||
602 | (int64_t)l2_offset * 512, | ||
603 | l2_table, | ||
604 | - extent->l2_size * sizeof(uint32_t) | ||
605 | - ) != extent->l2_size * sizeof(uint32_t)) { | ||
606 | + l2_size_bytes | ||
607 | + ) != l2_size_bytes) { | ||
608 | return VMDK_ERROR; | ||
609 | } | ||
610 | |||
611 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
612 | extent->l2_cache_counts[min_index] = 1; | ||
613 | found: | ||
614 | l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size; | ||
615 | - cluster_sector = le32_to_cpu(l2_table[l2_index]); | ||
616 | |||
617 | - if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { | ||
618 | - zeroed = true; | ||
619 | + if (extent->sesparse) { | ||
620 | + cluster_sector = le64_to_cpu(((uint64_t *)l2_table)[l2_index]); | ||
621 | + switch (cluster_sector & 0xf000000000000000) { | ||
622 | + case 0x0000000000000000: | ||
623 | + /* unallocated grain */ | ||
624 | + if (cluster_sector != 0) { | ||
625 | + return VMDK_ERROR; | ||
626 | + } | ||
627 | + break; | ||
628 | + case 0x1000000000000000: | ||
629 | + /* scsi-unmapped grain - fallthrough */ | ||
630 | + case 0x2000000000000000: | ||
631 | + /* zero grain */ | ||
632 | + zeroed = true; | ||
633 | + break; | ||
634 | + case 0x3000000000000000: | ||
635 | + /* allocated grain */ | ||
636 | + cluster_sector = (((cluster_sector & 0x0fff000000000000) >> 48) | | ||
637 | + ((cluster_sector & 0x0000ffffffffffff) << 12)); | ||
638 | + cluster_sector = extent->sesparse_clusters_offset + | ||
639 | + cluster_sector * extent->cluster_sectors; | ||
640 | + break; | ||
641 | + default: | ||
642 | + return VMDK_ERROR; | ||
643 | + } | ||
644 | + } else { | ||
645 | + cluster_sector = le32_to_cpu(((uint32_t *)l2_table)[l2_index]); | ||
646 | + | ||
647 | + if (extent->has_zero_grain && cluster_sector == VMDK_GTE_ZEROED) { | ||
648 | + zeroed = true; | ||
649 | + } | ||
650 | } | ||
651 | |||
652 | if (!cluster_sector || zeroed) { | ||
653 | if (!allocate) { | ||
654 | return zeroed ? VMDK_ZEROED : VMDK_UNALLOC; | ||
655 | } | ||
656 | + assert(!extent->sesparse); | ||
657 | |||
658 | if (extent->next_cluster_sector >= VMDK_EXTENT_MAX_SECTORS) { | ||
659 | return VMDK_ERROR; | ||
660 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
661 | m_data->l1_index = l1_index; | ||
662 | m_data->l2_index = l2_index; | ||
663 | m_data->l2_offset = l2_offset; | ||
664 | - m_data->l2_cache_entry = &l2_table[l2_index]; | ||
665 | + m_data->l2_cache_entry = ((uint32_t *)l2_table) + l2_index; | ||
666 | } | ||
667 | } | ||
668 | *cluster_offset = cluster_sector << BDRV_SECTOR_BITS; | ||
669 | @@ -XXX,XX +XXX,XX @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, | ||
670 | if (!extent) { | ||
671 | return -EIO; | ||
672 | } | ||
673 | + if (extent->sesparse) { | ||
674 | + return -ENOTSUP; | ||
675 | + } | ||
676 | offset_in_cluster = vmdk_find_offset_in_cluster(extent, offset); | ||
677 | n_bytes = MIN(bytes, extent->cluster_sectors * BDRV_SECTOR_SIZE | ||
678 | - offset_in_cluster); | ||
260 | -- | 679 | -- |
261 | 2.34.1 | 680 | 2.21.0 |
681 | |||
682 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Pino Toscano <ptoscano@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Current scheme of image fleecing looks like this: | 3 | Rewrite the implementation of the ssh block driver to use libssh instead |
4 | of libssh2. The libssh library has various advantages over libssh2: | ||
5 | - easier API for authentication (for example for using ssh-agent) | ||
6 | - easier API for known_hosts handling | ||
7 | - supports newer types of keys in known_hosts | ||
4 | 8 | ||
5 | [guest] [NBD export] | 9 | Use APIs/features available in libssh 0.8 conditionally, to support |
6 | | | | 10 | older versions (which are not recommended though). |
7 | |root | root | ||
8 | v v | ||
9 | [copy-before-write] -----> [temp.qcow2] | ||
10 | | target | | ||
11 | |file |backing | ||
12 | v | | ||
13 | [active disk] <-------------+ | ||
14 | 11 | ||
15 | - On guest writes copy-before-write filter copies old data from active | 12 | Adjust the iotest 207 according to the different error message, and to |
16 | disk to temp.qcow2. So fleecing client (NBD export) when reads | 13 | find the default key type for localhost (to properly compare the |
17 | changed regions from temp.qcow2 image and unchanged from active disk | 14 | fingerprint with). |
18 | through backing link. | 15 | Contributed-by: Max Reitz <mreitz@redhat.com> |
19 | 16 | ||
20 | This patch makes possible new image fleecing scheme: | 17 | Adjust the various Docker/Travis scripts to use libssh when available |
18 | instead of libssh2. The mingw/mxe testing is dropped for now, as there | ||
19 | are no packages for it. | ||
21 | 20 | ||
22 | [guest] [NBD export] | 21 | Signed-off-by: Pino Toscano <ptoscano@redhat.com> |
23 | | | | 22 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
24 | | root | root | 23 | Acked-by: Alex Bennée <alex.bennee@linaro.org> |
25 | v file v | 24 | Message-id: 20190620200840.17655-1-ptoscano@redhat.com |
26 | [copy-before-write]<------[snapshot-access] | 25 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
27 | | | | 26 | Message-id: 5873173.t2JhDm7DL7@lindworm.usersys.redhat.com |
28 | | file | target | 27 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
29 | v v | 28 | --- |
30 | [active-disk] [temp.img] | 29 | configure | 65 +- |
30 | block/Makefile.objs | 6 +- | ||
31 | block/ssh.c | 652 ++++++++++-------- | ||
32 | .travis.yml | 4 +- | ||
33 | block/trace-events | 14 +- | ||
34 | docs/qemu-block-drivers.texi | 2 +- | ||
35 | .../dockerfiles/debian-win32-cross.docker | 1 - | ||
36 | .../dockerfiles/debian-win64-cross.docker | 1 - | ||
37 | tests/docker/dockerfiles/fedora.docker | 4 +- | ||
38 | tests/docker/dockerfiles/ubuntu.docker | 2 +- | ||
39 | tests/docker/dockerfiles/ubuntu1804.docker | 2 +- | ||
40 | tests/qemu-iotests/207 | 54 +- | ||
41 | tests/qemu-iotests/207.out | 2 +- | ||
42 | 13 files changed, 449 insertions(+), 360 deletions(-) | ||
31 | 43 | ||
32 | - copy-before-write does CBW operations and also provides | 44 | diff --git a/configure b/configure |
33 | snapshot-access API. The API may be accessed through | 45 | index XXXXXXX..XXXXXXX 100755 |
34 | snapshot-access driver. | 46 | --- a/configure |
35 | 47 | +++ b/configure | |
36 | Benefits of new scheme: | 48 | @@ -XXX,XX +XXX,XX @@ auth_pam="" |
37 | 49 | vte="" | |
38 | 1. Access control: if remote client try to read data that not covered | 50 | virglrenderer="" |
39 | by original dirty bitmap used on copy-before-write open, client gets | 51 | tpm="" |
40 | -EACCES. | 52 | -libssh2="" |
41 | 53 | +libssh="" | |
42 | 2. Discard support: if remote client do DISCARD, this additionally to | 54 | live_block_migration="yes" |
43 | discarding data in temp.img informs block-copy process to not copy | 55 | numa="" |
44 | these clusters. Next read from discarded area will return -EACCES. | 56 | tcmalloc="no" |
45 | This is significant thing: when fleecing user reads data that was | 57 | @@ -XXX,XX +XXX,XX @@ for opt do |
46 | not yet copied to temp.img, we can avoid copying it on further guest | 58 | ;; |
47 | write. | 59 | --enable-tpm) tpm="yes" |
48 | 60 | ;; | |
49 | 3. Synchronisation between client reads and block-copy write is more | 61 | - --disable-libssh2) libssh2="no" |
50 | efficient. In old scheme we just rely on BDRV_REQ_SERIALISING flag | 62 | + --disable-libssh) libssh="no" |
51 | used for writes to temp.qcow2. New scheme is less blocking: | 63 | ;; |
52 | - fleecing reads are never blocked: if data region is untouched or | 64 | - --enable-libssh2) libssh2="yes" |
53 | in-flight, we just read from active-disk, otherwise we read from | 65 | + --enable-libssh) libssh="yes" |
54 | temp.img | 66 | ;; |
55 | - writes to temp.img are not blocked by fleecing reads | 67 | --disable-live-block-migration) live_block_migration="no" |
56 | - still, guest writes of-course are blocked by in-flight fleecing | 68 | ;; |
57 | reads, that currently read from active-disk - it's the minimum | 69 | @@ -XXX,XX +XXX,XX @@ disabled with --disable-FEATURE, default is enabled if available: |
58 | necessary blocking | 70 | coroutine-pool coroutine freelist (better performance) |
59 | 71 | glusterfs GlusterFS backend | |
60 | 4. Temporary image may be of any format, as we don't rely on backing | 72 | tpm TPM support |
61 | feature. | 73 | - libssh2 ssh block device support |
62 | 74 | + libssh ssh block device support | |
63 | 5. Permission relation are simplified. With old scheme we have to share | 75 | numa libnuma support |
64 | write permission on target child of copy-before-write, otherwise | 76 | libxml2 for Parallels image format |
65 | backing link conflicts with copy-before-write file child write | 77 | tcmalloc tcmalloc support |
66 | permissions. With new scheme we don't have backing link, and | 78 | @@ -XXX,XX +XXX,XX @@ EOF |
67 | copy-before-write node may have unshared access to temporary node. | 79 | fi |
68 | (Not realized in this commit, will be in future). | 80 | |
69 | 81 | ########################################## | |
70 | 6. Having control on fleecing reads we'll be able to implement | 82 | -# libssh2 probe |
71 | alternative behavior on failed copy-before-write operations. | 83 | -min_libssh2_version=1.2.8 |
72 | Currently we just break guest request (that's a historical behavior | 84 | -if test "$libssh2" != "no" ; then |
73 | of backup). But in some scenarios it's a bad behavior: better | 85 | - if $pkg_config --atleast-version=$min_libssh2_version libssh2; then |
74 | is to drop the backup as failed but don't break guest request. | 86 | - libssh2_cflags=$($pkg_config libssh2 --cflags) |
75 | With new scheme we can simply unset some bits in a bitmap on CBW | 87 | - libssh2_libs=$($pkg_config libssh2 --libs) |
76 | failure and further fleecing reads will -EACCES, or something like | 88 | - libssh2=yes |
77 | this. (Not implemented in this commit, will be in future) | 89 | +# libssh probe |
78 | Additional application for this is implementing timeout for CBW | 90 | +if test "$libssh" != "no" ; then |
79 | operations. | 91 | + if $pkg_config --exists libssh; then |
80 | 92 | + libssh_cflags=$($pkg_config libssh --cflags) | |
81 | Iotest 257 output is updated, as two more bitmaps now live in | 93 | + libssh_libs=$($pkg_config libssh --libs) |
82 | copy-before-write filter. | 94 | + libssh=yes |
83 | 95 | else | |
84 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 96 | - if test "$libssh2" = "yes" ; then |
85 | Message-Id: <20220303194349.2304213-13-vsementsov@virtuozzo.com> | 97 | - error_exit "libssh2 >= $min_libssh2_version required for --enable-libssh2" |
86 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 98 | + if test "$libssh" = "yes" ; then |
87 | --- | 99 | + error_exit "libssh required for --enable-libssh" |
88 | block/copy-before-write.c | 212 ++++++++++++++++++++++++++++++++++- | 100 | fi |
89 | tests/qemu-iotests/257.out | 224 +++++++++++++++++++++++++++++++++++++ | 101 | - libssh2=no |
90 | 2 files changed, 435 insertions(+), 1 deletion(-) | 102 | + libssh=no |
91 | 103 | fi | |
92 | diff --git a/block/copy-before-write.c b/block/copy-before-write.c | 104 | fi |
105 | |||
106 | ########################################## | ||
107 | -# libssh2_sftp_fsync probe | ||
108 | +# Check for libssh 0.8 | ||
109 | +# This is done like this instead of using the LIBSSH_VERSION_* and | ||
110 | +# SSH_VERSION_* macros because some distributions in the past shipped | ||
111 | +# snapshots of the future 0.8 from Git, and those snapshots did not | ||
112 | +# have updated version numbers (still referring to 0.7.0). | ||
113 | |||
114 | -if test "$libssh2" = "yes"; then | ||
115 | +if test "$libssh" = "yes"; then | ||
116 | cat > $TMPC <<EOF | ||
117 | -#include <stdio.h> | ||
118 | -#include <libssh2.h> | ||
119 | -#include <libssh2_sftp.h> | ||
120 | -int main(void) { | ||
121 | - LIBSSH2_SESSION *session; | ||
122 | - LIBSSH2_SFTP *sftp; | ||
123 | - LIBSSH2_SFTP_HANDLE *sftp_handle; | ||
124 | - session = libssh2_session_init (); | ||
125 | - sftp = libssh2_sftp_init (session); | ||
126 | - sftp_handle = libssh2_sftp_open (sftp, "/", 0, 0); | ||
127 | - libssh2_sftp_fsync (sftp_handle); | ||
128 | - return 0; | ||
129 | -} | ||
130 | +#include <libssh/libssh.h> | ||
131 | +int main(void) { return ssh_get_server_publickey(NULL, NULL); } | ||
132 | EOF | ||
133 | - # libssh2_cflags/libssh2_libs defined in previous test. | ||
134 | - if compile_prog "$libssh2_cflags" "$libssh2_libs" ; then | ||
135 | - QEMU_CFLAGS="-DHAS_LIBSSH2_SFTP_FSYNC $QEMU_CFLAGS" | ||
136 | + if compile_prog "$libssh_cflags" "$libssh_libs"; then | ||
137 | + libssh_cflags="-DHAVE_LIBSSH_0_8 $libssh_cflags" | ||
138 | fi | ||
139 | fi | ||
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ echo "GlusterFS support $glusterfs" | ||
142 | echo "gcov $gcov_tool" | ||
143 | echo "gcov enabled $gcov" | ||
144 | echo "TPM support $tpm" | ||
145 | -echo "libssh2 support $libssh2" | ||
146 | +echo "libssh support $libssh" | ||
147 | echo "QOM debugging $qom_cast_debug" | ||
148 | echo "Live block migration $live_block_migration" | ||
149 | echo "lzo support $lzo" | ||
150 | @@ -XXX,XX +XXX,XX @@ if test "$glusterfs_iocb_has_stat" = "yes" ; then | ||
151 | echo "CONFIG_GLUSTERFS_IOCB_HAS_STAT=y" >> $config_host_mak | ||
152 | fi | ||
153 | |||
154 | -if test "$libssh2" = "yes" ; then | ||
155 | - echo "CONFIG_LIBSSH2=m" >> $config_host_mak | ||
156 | - echo "LIBSSH2_CFLAGS=$libssh2_cflags" >> $config_host_mak | ||
157 | - echo "LIBSSH2_LIBS=$libssh2_libs" >> $config_host_mak | ||
158 | +if test "$libssh" = "yes" ; then | ||
159 | + echo "CONFIG_LIBSSH=m" >> $config_host_mak | ||
160 | + echo "LIBSSH_CFLAGS=$libssh_cflags" >> $config_host_mak | ||
161 | + echo "LIBSSH_LIBS=$libssh_libs" >> $config_host_mak | ||
162 | fi | ||
163 | |||
164 | if test "$live_block_migration" = "yes" ; then | ||
165 | diff --git a/block/Makefile.objs b/block/Makefile.objs | ||
93 | index XXXXXXX..XXXXXXX 100644 | 166 | index XXXXXXX..XXXXXXX 100644 |
94 | --- a/block/copy-before-write.c | 167 | --- a/block/Makefile.objs |
95 | +++ b/block/copy-before-write.c | 168 | +++ b/block/Makefile.objs |
169 | @@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_CURL) += curl.o | ||
170 | block-obj-$(CONFIG_RBD) += rbd.o | ||
171 | block-obj-$(CONFIG_GLUSTERFS) += gluster.o | ||
172 | block-obj-$(CONFIG_VXHS) += vxhs.o | ||
173 | -block-obj-$(CONFIG_LIBSSH2) += ssh.o | ||
174 | +block-obj-$(CONFIG_LIBSSH) += ssh.o | ||
175 | block-obj-y += accounting.o dirty-bitmap.o | ||
176 | block-obj-y += write-threshold.o | ||
177 | block-obj-y += backup.o | ||
178 | @@ -XXX,XX +XXX,XX @@ rbd.o-libs := $(RBD_LIBS) | ||
179 | gluster.o-cflags := $(GLUSTERFS_CFLAGS) | ||
180 | gluster.o-libs := $(GLUSTERFS_LIBS) | ||
181 | vxhs.o-libs := $(VXHS_LIBS) | ||
182 | -ssh.o-cflags := $(LIBSSH2_CFLAGS) | ||
183 | -ssh.o-libs := $(LIBSSH2_LIBS) | ||
184 | +ssh.o-cflags := $(LIBSSH_CFLAGS) | ||
185 | +ssh.o-libs := $(LIBSSH_LIBS) | ||
186 | block-obj-dmg-bz2-$(CONFIG_BZIP2) += dmg-bz2.o | ||
187 | block-obj-$(if $(CONFIG_DMG),m,n) += $(block-obj-dmg-bz2-y) | ||
188 | dmg-bz2.o-libs := $(BZIP2_LIBS) | ||
189 | diff --git a/block/ssh.c b/block/ssh.c | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/block/ssh.c | ||
192 | +++ b/block/ssh.c | ||
96 | @@ -XXX,XX +XXX,XX @@ | 193 | @@ -XXX,XX +XXX,XX @@ |
97 | #include "block/block-copy.h" | 194 | |
98 | 195 | #include "qemu/osdep.h" | |
99 | #include "block/copy-before-write.h" | 196 | |
100 | +#include "block/reqlist.h" | 197 | -#include <libssh2.h> |
101 | 198 | -#include <libssh2_sftp.h> | |
102 | #include "qapi/qapi-visit-block-core.h" | 199 | +#include <libssh/libssh.h> |
103 | 200 | +#include <libssh/sftp.h> | |
104 | typedef struct BDRVCopyBeforeWriteState { | 201 | |
105 | BlockCopyState *bcs; | 202 | #include "block/block_int.h" |
106 | BdrvChild *target; | 203 | #include "block/qdict.h" |
107 | + | 204 | @@ -XXX,XX +XXX,XX @@ |
205 | #include "trace.h" | ||
206 | |||
207 | /* | ||
208 | - * TRACE_LIBSSH2=<bitmask> enables tracing in libssh2 itself. Note | ||
209 | - * that this requires that libssh2 was specially compiled with the | ||
210 | - * `./configure --enable-debug' option, so most likely you will have | ||
211 | - * to compile it yourself. The meaning of <bitmask> is described | ||
212 | - * here: http://www.libssh2.org/libssh2_trace.html | ||
213 | + * TRACE_LIBSSH=<level> enables tracing in libssh itself. | ||
214 | + * The meaning of <level> is described here: | ||
215 | + * http://api.libssh.org/master/group__libssh__log.html | ||
216 | */ | ||
217 | -#define TRACE_LIBSSH2 0 /* or try: LIBSSH2_TRACE_SFTP */ | ||
218 | +#define TRACE_LIBSSH 0 /* see: SSH_LOG_* */ | ||
219 | |||
220 | typedef struct BDRVSSHState { | ||
221 | /* Coroutine. */ | ||
222 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVSSHState { | ||
223 | |||
224 | /* SSH connection. */ | ||
225 | int sock; /* socket */ | ||
226 | - LIBSSH2_SESSION *session; /* ssh session */ | ||
227 | - LIBSSH2_SFTP *sftp; /* sftp session */ | ||
228 | - LIBSSH2_SFTP_HANDLE *sftp_handle; /* sftp remote file handle */ | ||
229 | + ssh_session session; /* ssh session */ | ||
230 | + sftp_session sftp; /* sftp session */ | ||
231 | + sftp_file sftp_handle; /* sftp remote file handle */ | ||
232 | |||
233 | - /* See ssh_seek() function below. */ | ||
234 | - int64_t offset; | ||
235 | - bool offset_op_read; | ||
236 | - | ||
237 | - /* File attributes at open. We try to keep the .filesize field | ||
108 | + /* | 238 | + /* |
109 | + * @lock: protects access to @access_bitmap, @done_bitmap and | 239 | + * File attributes at open. We try to keep the .size field |
110 | + * @frozen_read_reqs | 240 | * updated if it changes (eg by writing at the end of the file). |
111 | + */ | 241 | */ |
112 | + CoMutex lock; | 242 | - LIBSSH2_SFTP_ATTRIBUTES attrs; |
113 | + | 243 | + sftp_attributes attrs; |
114 | + /* | 244 | |
115 | + * @access_bitmap: represents areas allowed for reading by fleecing user. | 245 | InetSocketAddress *inet; |
116 | + * Reading from non-dirty areas leads to -EACCES. | 246 | |
117 | + */ | 247 | @@ -XXX,XX +XXX,XX @@ static void ssh_state_init(BDRVSSHState *s) |
118 | + BdrvDirtyBitmap *access_bitmap; | 248 | { |
119 | + | 249 | memset(s, 0, sizeof *s); |
120 | + /* | 250 | s->sock = -1; |
121 | + * @done_bitmap: represents areas that was successfully copied to @target by | 251 | - s->offset = -1; |
122 | + * copy-before-write operations. | 252 | qemu_co_mutex_init(&s->lock); |
123 | + */ | ||
124 | + BdrvDirtyBitmap *done_bitmap; | ||
125 | + | ||
126 | + /* | ||
127 | + * @frozen_read_reqs: current read requests for fleecing user in bs->file | ||
128 | + * node. These areas must not be rewritten by guest. | ||
129 | + */ | ||
130 | + BlockReqList frozen_read_reqs; | ||
131 | } BDRVCopyBeforeWriteState; | ||
132 | |||
133 | static coroutine_fn int cbw_co_preadv( | ||
134 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int cbw_co_preadv( | ||
135 | return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); | ||
136 | } | 253 | } |
137 | 254 | ||
138 | +/* | 255 | @@ -XXX,XX +XXX,XX @@ static void ssh_state_free(BDRVSSHState *s) |
139 | + * Do copy-before-write operation. | ||
140 | + * | ||
141 | + * On failure guest request must be failed too. | ||
142 | + * | ||
143 | + * On success, we also wait for all in-flight fleecing read requests in source | ||
144 | + * node, and it's guaranteed that after cbw_do_copy_before_write() successful | ||
145 | + * return there are no such requests and they will never appear. | ||
146 | + */ | ||
147 | static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, | ||
148 | uint64_t offset, uint64_t bytes, BdrvRequestFlags flags) | ||
149 | { | 256 | { |
150 | BDRVCopyBeforeWriteState *s = bs->opaque; | 257 | g_free(s->user); |
258 | |||
259 | + if (s->attrs) { | ||
260 | + sftp_attributes_free(s->attrs); | ||
261 | + } | ||
262 | if (s->sftp_handle) { | ||
263 | - libssh2_sftp_close(s->sftp_handle); | ||
264 | + sftp_close(s->sftp_handle); | ||
265 | } | ||
266 | if (s->sftp) { | ||
267 | - libssh2_sftp_shutdown(s->sftp); | ||
268 | + sftp_free(s->sftp); | ||
269 | } | ||
270 | if (s->session) { | ||
271 | - libssh2_session_disconnect(s->session, | ||
272 | - "from qemu ssh client: " | ||
273 | - "user closed the connection"); | ||
274 | - libssh2_session_free(s->session); | ||
275 | - } | ||
276 | - if (s->sock >= 0) { | ||
277 | - close(s->sock); | ||
278 | + ssh_disconnect(s->session); | ||
279 | + ssh_free(s->session); /* This frees s->sock */ | ||
280 | } | ||
281 | } | ||
282 | |||
283 | @@ -XXX,XX +XXX,XX @@ session_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
284 | va_end(args); | ||
285 | |||
286 | if (s->session) { | ||
287 | - char *ssh_err; | ||
288 | + const char *ssh_err; | ||
289 | int ssh_err_code; | ||
290 | |||
291 | - /* This is not an errno. See <libssh2.h>. */ | ||
292 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
293 | - &ssh_err, NULL, 0); | ||
294 | - error_setg(errp, "%s: %s (libssh2 error code: %d)", | ||
295 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
296 | + ssh_err = ssh_get_error(s->session); | ||
297 | + ssh_err_code = ssh_get_error_code(s->session); | ||
298 | + error_setg(errp, "%s: %s (libssh error code: %d)", | ||
299 | msg, ssh_err, ssh_err_code); | ||
300 | } else { | ||
301 | error_setg(errp, "%s", msg); | ||
302 | @@ -XXX,XX +XXX,XX @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
303 | va_end(args); | ||
304 | |||
305 | if (s->sftp) { | ||
306 | - char *ssh_err; | ||
307 | + const char *ssh_err; | ||
308 | int ssh_err_code; | ||
309 | - unsigned long sftp_err_code; | ||
310 | + int sftp_err_code; | ||
311 | |||
312 | - /* This is not an errno. See <libssh2.h>. */ | ||
313 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
314 | - &ssh_err, NULL, 0); | ||
315 | - /* See <libssh2_sftp.h>. */ | ||
316 | - sftp_err_code = libssh2_sftp_last_error((s)->sftp); | ||
317 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
318 | + ssh_err = ssh_get_error(s->session); | ||
319 | + ssh_err_code = ssh_get_error_code(s->session); | ||
320 | + /* See <libssh/sftp.h>. */ | ||
321 | + sftp_err_code = sftp_get_error(s->sftp); | ||
322 | |||
323 | error_setg(errp, | ||
324 | - "%s: %s (libssh2 error code: %d, sftp error code: %lu)", | ||
325 | + "%s: %s (libssh error code: %d, sftp error code: %d)", | ||
326 | msg, ssh_err, ssh_err_code, sftp_err_code); | ||
327 | } else { | ||
328 | error_setg(errp, "%s", msg); | ||
329 | @@ -XXX,XX +XXX,XX @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char *fs, ...) | ||
330 | |||
331 | static void sftp_error_trace(BDRVSSHState *s, const char *op) | ||
332 | { | ||
333 | - char *ssh_err; | ||
334 | + const char *ssh_err; | ||
335 | int ssh_err_code; | ||
336 | - unsigned long sftp_err_code; | ||
337 | + int sftp_err_code; | ||
338 | |||
339 | - /* This is not an errno. See <libssh2.h>. */ | ||
340 | - ssh_err_code = libssh2_session_last_error(s->session, | ||
341 | - &ssh_err, NULL, 0); | ||
342 | - /* See <libssh2_sftp.h>. */ | ||
343 | - sftp_err_code = libssh2_sftp_last_error((s)->sftp); | ||
344 | + /* This is not an errno. See <libssh/libssh.h>. */ | ||
345 | + ssh_err = ssh_get_error(s->session); | ||
346 | + ssh_err_code = ssh_get_error_code(s->session); | ||
347 | + /* See <libssh/sftp.h>. */ | ||
348 | + sftp_err_code = sftp_get_error(s->sftp); | ||
349 | |||
350 | trace_sftp_error(op, ssh_err, ssh_err_code, sftp_err_code); | ||
351 | } | ||
352 | @@ -XXX,XX +XXX,XX @@ static void ssh_parse_filename(const char *filename, QDict *options, | ||
353 | parse_uri(filename, options, errp); | ||
354 | } | ||
355 | |||
356 | -static int check_host_key_knownhosts(BDRVSSHState *s, | ||
357 | - const char *host, int port, Error **errp) | ||
358 | +static int check_host_key_knownhosts(BDRVSSHState *s, Error **errp) | ||
359 | { | ||
360 | - const char *home; | ||
361 | - char *knh_file = NULL; | ||
362 | - LIBSSH2_KNOWNHOSTS *knh = NULL; | ||
363 | - struct libssh2_knownhost *found; | ||
364 | - int ret, r; | ||
365 | - const char *hostkey; | ||
366 | - size_t len; | ||
367 | - int type; | ||
368 | - | ||
369 | - hostkey = libssh2_session_hostkey(s->session, &len, &type); | ||
370 | - if (!hostkey) { | ||
151 | + int ret; | 371 | + int ret; |
152 | uint64_t off, end; | 372 | +#ifdef HAVE_LIBSSH_0_8 |
153 | int64_t cluster_size = block_copy_cluster_size(s->bcs); | 373 | + enum ssh_known_hosts_e state; |
154 | 374 | + int r; | |
155 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int cbw_do_copy_before_write(BlockDriverState *bs, | 375 | + ssh_key pubkey; |
156 | off = QEMU_ALIGN_DOWN(offset, cluster_size); | 376 | + enum ssh_keytypes_e pubkey_type; |
157 | end = QEMU_ALIGN_UP(offset + bytes, cluster_size); | 377 | + unsigned char *server_hash = NULL; |
158 | 378 | + size_t server_hash_len; | |
159 | - return block_copy(s->bcs, off, end - off, true); | 379 | + char *fingerprint = NULL; |
160 | + ret = block_copy(s->bcs, off, end - off, true); | 380 | + |
161 | + if (ret < 0) { | 381 | + state = ssh_session_is_known_server(s->session); |
162 | + return ret; | 382 | + trace_ssh_server_status(state); |
163 | + } | 383 | + |
164 | + | 384 | + switch (state) { |
165 | + WITH_QEMU_LOCK_GUARD(&s->lock) { | 385 | + case SSH_KNOWN_HOSTS_OK: |
166 | + bdrv_set_dirty_bitmap(s->done_bitmap, off, end - off); | 386 | + /* OK */ |
167 | + reqlist_wait_all(&s->frozen_read_reqs, off, end - off, &s->lock); | 387 | + trace_ssh_check_host_key_knownhosts(); |
168 | + } | 388 | + break; |
169 | + | 389 | + case SSH_KNOWN_HOSTS_CHANGED: |
170 | + return 0; | 390 | ret = -EINVAL; |
391 | - session_error_setg(errp, s, "failed to read remote host key"); | ||
392 | + r = ssh_get_server_publickey(s->session, &pubkey); | ||
393 | + if (r == 0) { | ||
394 | + r = ssh_get_publickey_hash(pubkey, SSH_PUBLICKEY_HASH_SHA256, | ||
395 | + &server_hash, &server_hash_len); | ||
396 | + pubkey_type = ssh_key_type(pubkey); | ||
397 | + ssh_key_free(pubkey); | ||
398 | + } | ||
399 | + if (r == 0) { | ||
400 | + fingerprint = ssh_get_fingerprint_hash(SSH_PUBLICKEY_HASH_SHA256, | ||
401 | + server_hash, | ||
402 | + server_hash_len); | ||
403 | + ssh_clean_pubkey_hash(&server_hash); | ||
404 | + } | ||
405 | + if (fingerprint) { | ||
406 | + error_setg(errp, | ||
407 | + "host key (%s key with fingerprint %s) does not match " | ||
408 | + "the one in known_hosts; this may be a possible attack", | ||
409 | + ssh_key_type_to_char(pubkey_type), fingerprint); | ||
410 | + ssh_string_free_char(fingerprint); | ||
411 | + } else { | ||
412 | + error_setg(errp, | ||
413 | + "host key does not match the one in known_hosts; this " | ||
414 | + "may be a possible attack"); | ||
415 | + } | ||
416 | goto out; | ||
417 | - } | ||
418 | - | ||
419 | - knh = libssh2_knownhost_init(s->session); | ||
420 | - if (!knh) { | ||
421 | + case SSH_KNOWN_HOSTS_OTHER: | ||
422 | ret = -EINVAL; | ||
423 | - session_error_setg(errp, s, | ||
424 | - "failed to initialize known hosts support"); | ||
425 | + error_setg(errp, | ||
426 | + "host key for this server not found, another type exists"); | ||
427 | + goto out; | ||
428 | + case SSH_KNOWN_HOSTS_UNKNOWN: | ||
429 | + ret = -EINVAL; | ||
430 | + error_setg(errp, "no host key was found in known_hosts"); | ||
431 | + goto out; | ||
432 | + case SSH_KNOWN_HOSTS_NOT_FOUND: | ||
433 | + ret = -ENOENT; | ||
434 | + error_setg(errp, "known_hosts file not found"); | ||
435 | + goto out; | ||
436 | + case SSH_KNOWN_HOSTS_ERROR: | ||
437 | + ret = -EINVAL; | ||
438 | + error_setg(errp, "error while checking the host"); | ||
439 | + goto out; | ||
440 | + default: | ||
441 | + ret = -EINVAL; | ||
442 | + error_setg(errp, "error while checking for known server (%d)", state); | ||
443 | goto out; | ||
444 | } | ||
445 | +#else /* !HAVE_LIBSSH_0_8 */ | ||
446 | + int state; | ||
447 | |||
448 | - home = getenv("HOME"); | ||
449 | - if (home) { | ||
450 | - knh_file = g_strdup_printf("%s/.ssh/known_hosts", home); | ||
451 | - } else { | ||
452 | - knh_file = g_strdup_printf("/root/.ssh/known_hosts"); | ||
453 | - } | ||
454 | - | ||
455 | - /* Read all known hosts from OpenSSH-style known_hosts file. */ | ||
456 | - libssh2_knownhost_readfile(knh, knh_file, LIBSSH2_KNOWNHOST_FILE_OPENSSH); | ||
457 | + state = ssh_is_server_known(s->session); | ||
458 | + trace_ssh_server_status(state); | ||
459 | |||
460 | - r = libssh2_knownhost_checkp(knh, host, port, hostkey, len, | ||
461 | - LIBSSH2_KNOWNHOST_TYPE_PLAIN| | ||
462 | - LIBSSH2_KNOWNHOST_KEYENC_RAW, | ||
463 | - &found); | ||
464 | - switch (r) { | ||
465 | - case LIBSSH2_KNOWNHOST_CHECK_MATCH: | ||
466 | + switch (state) { | ||
467 | + case SSH_SERVER_KNOWN_OK: | ||
468 | /* OK */ | ||
469 | - trace_ssh_check_host_key_knownhosts(found->key); | ||
470 | + trace_ssh_check_host_key_knownhosts(); | ||
471 | break; | ||
472 | - case LIBSSH2_KNOWNHOST_CHECK_MISMATCH: | ||
473 | + case SSH_SERVER_KNOWN_CHANGED: | ||
474 | ret = -EINVAL; | ||
475 | - session_error_setg(errp, s, | ||
476 | - "host key does not match the one in known_hosts" | ||
477 | - " (found key %s)", found->key); | ||
478 | + error_setg(errp, | ||
479 | + "host key does not match the one in known_hosts; this " | ||
480 | + "may be a possible attack"); | ||
481 | goto out; | ||
482 | - case LIBSSH2_KNOWNHOST_CHECK_NOTFOUND: | ||
483 | + case SSH_SERVER_FOUND_OTHER: | ||
484 | ret = -EINVAL; | ||
485 | - session_error_setg(errp, s, "no host key was found in known_hosts"); | ||
486 | + error_setg(errp, | ||
487 | + "host key for this server not found, another type exists"); | ||
488 | + goto out; | ||
489 | + case SSH_SERVER_FILE_NOT_FOUND: | ||
490 | + ret = -ENOENT; | ||
491 | + error_setg(errp, "known_hosts file not found"); | ||
492 | goto out; | ||
493 | - case LIBSSH2_KNOWNHOST_CHECK_FAILURE: | ||
494 | + case SSH_SERVER_NOT_KNOWN: | ||
495 | ret = -EINVAL; | ||
496 | - session_error_setg(errp, s, | ||
497 | - "failure matching the host key with known_hosts"); | ||
498 | + error_setg(errp, "no host key was found in known_hosts"); | ||
499 | + goto out; | ||
500 | + case SSH_SERVER_ERROR: | ||
501 | + ret = -EINVAL; | ||
502 | + error_setg(errp, "server error"); | ||
503 | goto out; | ||
504 | default: | ||
505 | ret = -EINVAL; | ||
506 | - session_error_setg(errp, s, "unknown error matching the host key" | ||
507 | - " with known_hosts (%d)", r); | ||
508 | + error_setg(errp, "error while checking for known server (%d)", state); | ||
509 | goto out; | ||
510 | } | ||
511 | +#endif /* !HAVE_LIBSSH_0_8 */ | ||
512 | |||
513 | /* known_hosts checking successful. */ | ||
514 | ret = 0; | ||
515 | |||
516 | out: | ||
517 | - if (knh != NULL) { | ||
518 | - libssh2_knownhost_free(knh); | ||
519 | - } | ||
520 | - g_free(knh_file); | ||
521 | return ret; | ||
171 | } | 522 | } |
172 | 523 | ||
173 | static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs, | 524 | @@ -XXX,XX +XXX,XX @@ static int compare_fingerprint(const unsigned char *fingerprint, size_t len, |
174 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn cbw_co_flush(BlockDriverState *bs) | 525 | |
175 | return bdrv_co_flush(bs->file->bs); | 526 | static int |
176 | } | 527 | check_host_key_hash(BDRVSSHState *s, const char *hash, |
177 | 528 | - int hash_type, size_t fingerprint_len, Error **errp) | |
178 | +/* | 529 | + enum ssh_publickey_hash_type type, Error **errp) |
179 | + * If @offset not accessible - return NULL. | ||
180 | + * | ||
181 | + * Otherwise, set @pnum to some bytes that accessible from @file (@file is set | ||
182 | + * to bs->file or to s->target). Return newly allocated BlockReq object that | ||
183 | + * should be than passed to cbw_snapshot_read_unlock(). | ||
184 | + * | ||
185 | + * It's guaranteed that guest writes will not interact in the region until | ||
186 | + * cbw_snapshot_read_unlock() called. | ||
187 | + */ | ||
188 | +static BlockReq *cbw_snapshot_read_lock(BlockDriverState *bs, | ||
189 | + int64_t offset, int64_t bytes, | ||
190 | + int64_t *pnum, BdrvChild **file) | ||
191 | +{ | ||
192 | + BDRVCopyBeforeWriteState *s = bs->opaque; | ||
193 | + BlockReq *req = g_new(BlockReq, 1); | ||
194 | + bool done; | ||
195 | + | ||
196 | + QEMU_LOCK_GUARD(&s->lock); | ||
197 | + | ||
198 | + if (bdrv_dirty_bitmap_next_zero(s->access_bitmap, offset, bytes) != -1) { | ||
199 | + g_free(req); | ||
200 | + return NULL; | ||
201 | + } | ||
202 | + | ||
203 | + done = bdrv_dirty_bitmap_status(s->done_bitmap, offset, bytes, pnum); | ||
204 | + if (done) { | ||
205 | + /* | ||
206 | + * Special invalid BlockReq, that is handled in | ||
207 | + * cbw_snapshot_read_unlock(). We don't need to lock something to read | ||
208 | + * from s->target. | ||
209 | + */ | ||
210 | + *req = (BlockReq) {.offset = -1, .bytes = -1}; | ||
211 | + *file = s->target; | ||
212 | + } else { | ||
213 | + reqlist_init_req(&s->frozen_read_reqs, req, offset, bytes); | ||
214 | + *file = bs->file; | ||
215 | + } | ||
216 | + | ||
217 | + return req; | ||
218 | +} | ||
219 | + | ||
220 | +static void cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq *req) | ||
221 | +{ | ||
222 | + BDRVCopyBeforeWriteState *s = bs->opaque; | ||
223 | + | ||
224 | + if (req->offset == -1 && req->bytes == -1) { | ||
225 | + g_free(req); | ||
226 | + return; | ||
227 | + } | ||
228 | + | ||
229 | + QEMU_LOCK_GUARD(&s->lock); | ||
230 | + | ||
231 | + reqlist_remove_req(req); | ||
232 | + g_free(req); | ||
233 | +} | ||
234 | + | ||
235 | +static coroutine_fn int | ||
236 | +cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes, | ||
237 | + QEMUIOVector *qiov, size_t qiov_offset) | ||
238 | +{ | ||
239 | + BlockReq *req; | ||
240 | + BdrvChild *file; | ||
241 | + int ret; | ||
242 | + | ||
243 | + /* TODO: upgrade to async loop using AioTask */ | ||
244 | + while (bytes) { | ||
245 | + int64_t cur_bytes; | ||
246 | + | ||
247 | + req = cbw_snapshot_read_lock(bs, offset, bytes, &cur_bytes, &file); | ||
248 | + if (!req) { | ||
249 | + return -EACCES; | ||
250 | + } | ||
251 | + | ||
252 | + ret = bdrv_co_preadv_part(file, offset, cur_bytes, | ||
253 | + qiov, qiov_offset, 0); | ||
254 | + cbw_snapshot_read_unlock(bs, req); | ||
255 | + if (ret < 0) { | ||
256 | + return ret; | ||
257 | + } | ||
258 | + | ||
259 | + bytes -= cur_bytes; | ||
260 | + offset += cur_bytes; | ||
261 | + qiov_offset += cur_bytes; | ||
262 | + } | ||
263 | + | ||
264 | + return 0; | ||
265 | +} | ||
266 | + | ||
267 | +static int coroutine_fn | ||
268 | +cbw_co_snapshot_block_status(BlockDriverState *bs, | ||
269 | + bool want_zero, int64_t offset, int64_t bytes, | ||
270 | + int64_t *pnum, int64_t *map, | ||
271 | + BlockDriverState **file) | ||
272 | +{ | ||
273 | + BDRVCopyBeforeWriteState *s = bs->opaque; | ||
274 | + BlockReq *req; | ||
275 | + int ret; | ||
276 | + int64_t cur_bytes; | ||
277 | + BdrvChild *child; | ||
278 | + | ||
279 | + req = cbw_snapshot_read_lock(bs, offset, bytes, &cur_bytes, &child); | ||
280 | + if (!req) { | ||
281 | + return -EACCES; | ||
282 | + } | ||
283 | + | ||
284 | + ret = bdrv_block_status(child->bs, offset, cur_bytes, pnum, map, file); | ||
285 | + if (child == s->target) { | ||
286 | + /* | ||
287 | + * We refer to s->target only for areas that we've written to it. | ||
288 | + * And we can not report unallocated blocks in s->target: this will | ||
289 | + * break generic block-status-above logic, that will go to | ||
290 | + * copy-before-write filtered child in this case. | ||
291 | + */ | ||
292 | + assert(ret & BDRV_BLOCK_ALLOCATED); | ||
293 | + } | ||
294 | + | ||
295 | + cbw_snapshot_read_unlock(bs, req); | ||
296 | + | ||
297 | + return ret; | ||
298 | +} | ||
299 | + | ||
300 | +static int coroutine_fn cbw_co_pdiscard_snapshot(BlockDriverState *bs, | ||
301 | + int64_t offset, int64_t bytes) | ||
302 | +{ | ||
303 | + BDRVCopyBeforeWriteState *s = bs->opaque; | ||
304 | + | ||
305 | + WITH_QEMU_LOCK_GUARD(&s->lock) { | ||
306 | + bdrv_reset_dirty_bitmap(s->access_bitmap, offset, bytes); | ||
307 | + } | ||
308 | + | ||
309 | + block_copy_reset(s->bcs, offset, bytes); | ||
310 | + | ||
311 | + return bdrv_co_pdiscard(s->target, offset, bytes); | ||
312 | +} | ||
313 | + | ||
314 | static void cbw_refresh_filename(BlockDriverState *bs) | ||
315 | { | 530 | { |
316 | pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), | 531 | - const char *fingerprint; |
317 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | 532 | - |
318 | { | 533 | - fingerprint = libssh2_hostkey_hash(s->session, hash_type); |
319 | BDRVCopyBeforeWriteState *s = bs->opaque; | 534 | - if (!fingerprint) { |
320 | BdrvDirtyBitmap *bitmap = NULL; | 535 | + int r; |
321 | + int64_t cluster_size; | 536 | + ssh_key pubkey; |
322 | 537 | + unsigned char *server_hash; | |
323 | bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | 538 | + size_t server_hash_len; |
324 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | 539 | + |
325 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | 540 | +#ifdef HAVE_LIBSSH_0_8 |
541 | + r = ssh_get_server_publickey(s->session, &pubkey); | ||
542 | +#else | ||
543 | + r = ssh_get_publickey(s->session, &pubkey); | ||
544 | +#endif | ||
545 | + if (r != SSH_OK) { | ||
546 | session_error_setg(errp, s, "failed to read remote host key"); | ||
326 | return -EINVAL; | 547 | return -EINVAL; |
327 | } | 548 | } |
328 | 549 | ||
329 | + cluster_size = block_copy_cluster_size(s->bcs); | 550 | - if(compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, |
330 | + | 551 | - hash) != 0) { |
331 | + s->done_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp); | 552 | + r = ssh_get_publickey_hash(pubkey, type, &server_hash, &server_hash_len); |
332 | + if (!s->done_bitmap) { | 553 | + ssh_key_free(pubkey); |
554 | + if (r != 0) { | ||
555 | + session_error_setg(errp, s, | ||
556 | + "failed reading the hash of the server SSH key"); | ||
333 | + return -EINVAL; | 557 | + return -EINVAL; |
334 | + } | 558 | + } |
335 | + bdrv_disable_dirty_bitmap(s->done_bitmap); | 559 | + |
336 | + | 560 | + r = compare_fingerprint(server_hash, server_hash_len, hash); |
337 | + /* s->access_bitmap starts equal to bcs bitmap */ | 561 | + ssh_clean_pubkey_hash(&server_hash); |
338 | + s->access_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp); | 562 | + if (r != 0) { |
339 | + if (!s->access_bitmap) { | 563 | error_setg(errp, "remote host key does not match host_key_check '%s'", |
340 | + return -EINVAL; | 564 | hash); |
341 | + } | 565 | return -EPERM; |
342 | + bdrv_disable_dirty_bitmap(s->access_bitmap); | 566 | @@ -XXX,XX +XXX,XX @@ check_host_key_hash(BDRVSSHState *s, const char *hash, |
343 | + bdrv_dirty_bitmap_merge_internal(s->access_bitmap, | ||
344 | + block_copy_dirty_bitmap(s->bcs), NULL, | ||
345 | + true); | ||
346 | + | ||
347 | + qemu_co_mutex_init(&s->lock); | ||
348 | + QLIST_INIT(&s->frozen_read_reqs); | ||
349 | + | ||
350 | return 0; | 567 | return 0; |
351 | } | 568 | } |
352 | 569 | ||
353 | @@ -XXX,XX +XXX,XX @@ static void cbw_close(BlockDriverState *bs) | 570 | -static int check_host_key(BDRVSSHState *s, const char *host, int port, |
571 | - SshHostKeyCheck *hkc, Error **errp) | ||
572 | +static int check_host_key(BDRVSSHState *s, SshHostKeyCheck *hkc, Error **errp) | ||
354 | { | 573 | { |
355 | BDRVCopyBeforeWriteState *s = bs->opaque; | 574 | SshHostKeyCheckMode mode; |
356 | 575 | ||
357 | + bdrv_release_dirty_bitmap(s->access_bitmap); | 576 | @@ -XXX,XX +XXX,XX @@ static int check_host_key(BDRVSSHState *s, const char *host, int port, |
358 | + bdrv_release_dirty_bitmap(s->done_bitmap); | 577 | case SSH_HOST_KEY_CHECK_MODE_HASH: |
359 | + | 578 | if (hkc->u.hash.type == SSH_HOST_KEY_CHECK_HASH_TYPE_MD5) { |
360 | block_copy_state_free(s->bcs); | 579 | return check_host_key_hash(s, hkc->u.hash.hash, |
361 | s->bcs = NULL; | 580 | - LIBSSH2_HOSTKEY_HASH_MD5, 16, errp); |
581 | + SSH_PUBLICKEY_HASH_MD5, errp); | ||
582 | } else if (hkc->u.hash.type == SSH_HOST_KEY_CHECK_HASH_TYPE_SHA1) { | ||
583 | return check_host_key_hash(s, hkc->u.hash.hash, | ||
584 | - LIBSSH2_HOSTKEY_HASH_SHA1, 20, errp); | ||
585 | + SSH_PUBLICKEY_HASH_SHA1, errp); | ||
586 | } | ||
587 | g_assert_not_reached(); | ||
588 | break; | ||
589 | case SSH_HOST_KEY_CHECK_MODE_KNOWN_HOSTS: | ||
590 | - return check_host_key_knownhosts(s, host, port, errp); | ||
591 | + return check_host_key_knownhosts(s, errp); | ||
592 | default: | ||
593 | g_assert_not_reached(); | ||
594 | } | ||
595 | @@ -XXX,XX +XXX,XX @@ static int check_host_key(BDRVSSHState *s, const char *host, int port, | ||
596 | return -EINVAL; | ||
362 | } | 597 | } |
363 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_cbw_filter = { | 598 | |
364 | .bdrv_co_pdiscard = cbw_co_pdiscard, | 599 | -static int authenticate(BDRVSSHState *s, const char *user, Error **errp) |
365 | .bdrv_co_flush = cbw_co_flush, | 600 | +static int authenticate(BDRVSSHState *s, Error **errp) |
366 | 601 | { | |
367 | + .bdrv_co_preadv_snapshot = cbw_co_preadv_snapshot, | 602 | int r, ret; |
368 | + .bdrv_co_pdiscard_snapshot = cbw_co_pdiscard_snapshot, | 603 | - const char *userauthlist; |
369 | + .bdrv_co_snapshot_block_status = cbw_co_snapshot_block_status, | 604 | - LIBSSH2_AGENT *agent = NULL; |
370 | + | 605 | - struct libssh2_agent_publickey *identity; |
371 | .bdrv_refresh_filename = cbw_refresh_filename, | 606 | - struct libssh2_agent_publickey *prev_identity = NULL; |
372 | 607 | + int method; | |
373 | .bdrv_child_perm = cbw_child_perm, | 608 | |
374 | diff --git a/tests/qemu-iotests/257.out b/tests/qemu-iotests/257.out | 609 | - userauthlist = libssh2_userauth_list(s->session, user, strlen(user)); |
610 | - if (strstr(userauthlist, "publickey") == NULL) { | ||
611 | + /* Try to authenticate with the "none" method. */ | ||
612 | + r = ssh_userauth_none(s->session, NULL); | ||
613 | + if (r == SSH_AUTH_ERROR) { | ||
614 | ret = -EPERM; | ||
615 | - error_setg(errp, | ||
616 | - "remote server does not support \"publickey\" authentication"); | ||
617 | + session_error_setg(errp, s, "failed to authenticate using none " | ||
618 | + "authentication"); | ||
619 | goto out; | ||
620 | - } | ||
621 | - | ||
622 | - /* Connect to ssh-agent and try each identity in turn. */ | ||
623 | - agent = libssh2_agent_init(s->session); | ||
624 | - if (!agent) { | ||
625 | - ret = -EINVAL; | ||
626 | - session_error_setg(errp, s, "failed to initialize ssh-agent support"); | ||
627 | - goto out; | ||
628 | - } | ||
629 | - if (libssh2_agent_connect(agent)) { | ||
630 | - ret = -ECONNREFUSED; | ||
631 | - session_error_setg(errp, s, "failed to connect to ssh-agent"); | ||
632 | - goto out; | ||
633 | - } | ||
634 | - if (libssh2_agent_list_identities(agent)) { | ||
635 | - ret = -EINVAL; | ||
636 | - session_error_setg(errp, s, | ||
637 | - "failed requesting identities from ssh-agent"); | ||
638 | + } else if (r == SSH_AUTH_SUCCESS) { | ||
639 | + /* Authenticated! */ | ||
640 | + ret = 0; | ||
641 | goto out; | ||
642 | } | ||
643 | |||
644 | - for(;;) { | ||
645 | - r = libssh2_agent_get_identity(agent, &identity, prev_identity); | ||
646 | - if (r == 1) { /* end of list */ | ||
647 | - break; | ||
648 | - } | ||
649 | - if (r < 0) { | ||
650 | + method = ssh_userauth_list(s->session, NULL); | ||
651 | + trace_ssh_auth_methods(method); | ||
652 | + | ||
653 | + /* | ||
654 | + * Try to authenticate with publickey, using the ssh-agent | ||
655 | + * if available. | ||
656 | + */ | ||
657 | + if (method & SSH_AUTH_METHOD_PUBLICKEY) { | ||
658 | + r = ssh_userauth_publickey_auto(s->session, NULL, NULL); | ||
659 | + if (r == SSH_AUTH_ERROR) { | ||
660 | ret = -EINVAL; | ||
661 | - session_error_setg(errp, s, | ||
662 | - "failed to obtain identity from ssh-agent"); | ||
663 | + session_error_setg(errp, s, "failed to authenticate using " | ||
664 | + "publickey authentication"); | ||
665 | goto out; | ||
666 | - } | ||
667 | - r = libssh2_agent_userauth(agent, user, identity); | ||
668 | - if (r == 0) { | ||
669 | + } else if (r == SSH_AUTH_SUCCESS) { | ||
670 | /* Authenticated! */ | ||
671 | ret = 0; | ||
672 | goto out; | ||
673 | } | ||
674 | - /* Failed to authenticate with this identity, try the next one. */ | ||
675 | - prev_identity = identity; | ||
676 | } | ||
677 | |||
678 | ret = -EPERM; | ||
679 | @@ -XXX,XX +XXX,XX @@ static int authenticate(BDRVSSHState *s, const char *user, Error **errp) | ||
680 | "and the identities held by your ssh-agent"); | ||
681 | |||
682 | out: | ||
683 | - if (agent != NULL) { | ||
684 | - /* Note: libssh2 implementation implicitly calls | ||
685 | - * libssh2_agent_disconnect if necessary. | ||
686 | - */ | ||
687 | - libssh2_agent_free(agent); | ||
688 | - } | ||
689 | - | ||
690 | return ret; | ||
691 | } | ||
692 | |||
693 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
694 | int ssh_flags, int creat_mode, Error **errp) | ||
695 | { | ||
696 | int r, ret; | ||
697 | - long port = 0; | ||
698 | + unsigned int port = 0; | ||
699 | + int new_sock = -1; | ||
700 | |||
701 | if (opts->has_user) { | ||
702 | s->user = g_strdup(opts->user); | ||
703 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
704 | s->inet = opts->server; | ||
705 | opts->server = NULL; | ||
706 | |||
707 | - if (qemu_strtol(s->inet->port, NULL, 10, &port) < 0) { | ||
708 | + if (qemu_strtoui(s->inet->port, NULL, 10, &port) < 0) { | ||
709 | error_setg(errp, "Use only numeric port value"); | ||
710 | ret = -EINVAL; | ||
711 | goto err; | ||
712 | } | ||
713 | |||
714 | /* Open the socket and connect. */ | ||
715 | - s->sock = inet_connect_saddr(s->inet, errp); | ||
716 | - if (s->sock < 0) { | ||
717 | + new_sock = inet_connect_saddr(s->inet, errp); | ||
718 | + if (new_sock < 0) { | ||
719 | ret = -EIO; | ||
720 | goto err; | ||
721 | } | ||
722 | |||
723 | + /* | ||
724 | + * Try to disable the Nagle algorithm on TCP sockets to reduce latency, | ||
725 | + * but do not fail if it cannot be disabled. | ||
726 | + */ | ||
727 | + r = socket_set_nodelay(new_sock); | ||
728 | + if (r < 0) { | ||
729 | + warn_report("can't set TCP_NODELAY for the ssh server %s: %s", | ||
730 | + s->inet->host, strerror(errno)); | ||
731 | + } | ||
732 | + | ||
733 | /* Create SSH session. */ | ||
734 | - s->session = libssh2_session_init(); | ||
735 | + s->session = ssh_new(); | ||
736 | if (!s->session) { | ||
737 | ret = -EINVAL; | ||
738 | - session_error_setg(errp, s, "failed to initialize libssh2 session"); | ||
739 | + session_error_setg(errp, s, "failed to initialize libssh session"); | ||
740 | goto err; | ||
741 | } | ||
742 | |||
743 | -#if TRACE_LIBSSH2 != 0 | ||
744 | - libssh2_trace(s->session, TRACE_LIBSSH2); | ||
745 | -#endif | ||
746 | + /* | ||
747 | + * Make sure we are in blocking mode during the connection and | ||
748 | + * authentication phases. | ||
749 | + */ | ||
750 | + ssh_set_blocking(s->session, 1); | ||
751 | |||
752 | - r = libssh2_session_handshake(s->session, s->sock); | ||
753 | - if (r != 0) { | ||
754 | + r = ssh_options_set(s->session, SSH_OPTIONS_USER, s->user); | ||
755 | + if (r < 0) { | ||
756 | + ret = -EINVAL; | ||
757 | + session_error_setg(errp, s, | ||
758 | + "failed to set the user in the libssh session"); | ||
759 | + goto err; | ||
760 | + } | ||
761 | + | ||
762 | + r = ssh_options_set(s->session, SSH_OPTIONS_HOST, s->inet->host); | ||
763 | + if (r < 0) { | ||
764 | + ret = -EINVAL; | ||
765 | + session_error_setg(errp, s, | ||
766 | + "failed to set the host in the libssh session"); | ||
767 | + goto err; | ||
768 | + } | ||
769 | + | ||
770 | + if (port > 0) { | ||
771 | + r = ssh_options_set(s->session, SSH_OPTIONS_PORT, &port); | ||
772 | + if (r < 0) { | ||
773 | + ret = -EINVAL; | ||
774 | + session_error_setg(errp, s, | ||
775 | + "failed to set the port in the libssh session"); | ||
776 | + goto err; | ||
777 | + } | ||
778 | + } | ||
779 | + | ||
780 | + r = ssh_options_set(s->session, SSH_OPTIONS_COMPRESSION, "none"); | ||
781 | + if (r < 0) { | ||
782 | + ret = -EINVAL; | ||
783 | + session_error_setg(errp, s, | ||
784 | + "failed to disable the compression in the libssh " | ||
785 | + "session"); | ||
786 | + goto err; | ||
787 | + } | ||
788 | + | ||
789 | + /* Read ~/.ssh/config. */ | ||
790 | + r = ssh_options_parse_config(s->session, NULL); | ||
791 | + if (r < 0) { | ||
792 | + ret = -EINVAL; | ||
793 | + session_error_setg(errp, s, "failed to parse ~/.ssh/config"); | ||
794 | + goto err; | ||
795 | + } | ||
796 | + | ||
797 | + r = ssh_options_set(s->session, SSH_OPTIONS_FD, &new_sock); | ||
798 | + if (r < 0) { | ||
799 | + ret = -EINVAL; | ||
800 | + session_error_setg(errp, s, | ||
801 | + "failed to set the socket in the libssh session"); | ||
802 | + goto err; | ||
803 | + } | ||
804 | + /* libssh took ownership of the socket. */ | ||
805 | + s->sock = new_sock; | ||
806 | + new_sock = -1; | ||
807 | + | ||
808 | + /* Connect. */ | ||
809 | + r = ssh_connect(s->session); | ||
810 | + if (r != SSH_OK) { | ||
811 | ret = -EINVAL; | ||
812 | session_error_setg(errp, s, "failed to establish SSH session"); | ||
813 | goto err; | ||
814 | } | ||
815 | |||
816 | /* Check the remote host's key against known_hosts. */ | ||
817 | - ret = check_host_key(s, s->inet->host, port, opts->host_key_check, errp); | ||
818 | + ret = check_host_key(s, opts->host_key_check, errp); | ||
819 | if (ret < 0) { | ||
820 | goto err; | ||
821 | } | ||
822 | |||
823 | /* Authenticate. */ | ||
824 | - ret = authenticate(s, s->user, errp); | ||
825 | + ret = authenticate(s, errp); | ||
826 | if (ret < 0) { | ||
827 | goto err; | ||
828 | } | ||
829 | |||
830 | /* Start SFTP. */ | ||
831 | - s->sftp = libssh2_sftp_init(s->session); | ||
832 | + s->sftp = sftp_new(s->session); | ||
833 | if (!s->sftp) { | ||
834 | - session_error_setg(errp, s, "failed to initialize sftp handle"); | ||
835 | + session_error_setg(errp, s, "failed to create sftp handle"); | ||
836 | + ret = -EINVAL; | ||
837 | + goto err; | ||
838 | + } | ||
839 | + | ||
840 | + r = sftp_init(s->sftp); | ||
841 | + if (r < 0) { | ||
842 | + sftp_error_setg(errp, s, "failed to initialize sftp handle"); | ||
843 | ret = -EINVAL; | ||
844 | goto err; | ||
845 | } | ||
846 | |||
847 | /* Open the remote file. */ | ||
848 | trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode); | ||
849 | - s->sftp_handle = libssh2_sftp_open(s->sftp, opts->path, ssh_flags, | ||
850 | - creat_mode); | ||
851 | + s->sftp_handle = sftp_open(s->sftp, opts->path, ssh_flags, creat_mode); | ||
852 | if (!s->sftp_handle) { | ||
853 | - session_error_setg(errp, s, "failed to open remote file '%s'", | ||
854 | - opts->path); | ||
855 | + sftp_error_setg(errp, s, "failed to open remote file '%s'", | ||
856 | + opts->path); | ||
857 | ret = -EINVAL; | ||
858 | goto err; | ||
859 | } | ||
860 | |||
861 | - r = libssh2_sftp_fstat(s->sftp_handle, &s->attrs); | ||
862 | - if (r < 0) { | ||
863 | + /* Make sure the SFTP file is handled in blocking mode. */ | ||
864 | + sftp_file_set_blocking(s->sftp_handle); | ||
865 | + | ||
866 | + s->attrs = sftp_fstat(s->sftp_handle); | ||
867 | + if (!s->attrs) { | ||
868 | sftp_error_setg(errp, s, "failed to read file attributes"); | ||
869 | return -EINVAL; | ||
870 | } | ||
871 | @@ -XXX,XX +XXX,XX @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts, | ||
872 | return 0; | ||
873 | |||
874 | err: | ||
875 | + if (s->attrs) { | ||
876 | + sftp_attributes_free(s->attrs); | ||
877 | + } | ||
878 | + s->attrs = NULL; | ||
879 | if (s->sftp_handle) { | ||
880 | - libssh2_sftp_close(s->sftp_handle); | ||
881 | + sftp_close(s->sftp_handle); | ||
882 | } | ||
883 | s->sftp_handle = NULL; | ||
884 | if (s->sftp) { | ||
885 | - libssh2_sftp_shutdown(s->sftp); | ||
886 | + sftp_free(s->sftp); | ||
887 | } | ||
888 | s->sftp = NULL; | ||
889 | if (s->session) { | ||
890 | - libssh2_session_disconnect(s->session, | ||
891 | - "from qemu ssh client: " | ||
892 | - "error opening connection"); | ||
893 | - libssh2_session_free(s->session); | ||
894 | + ssh_disconnect(s->session); | ||
895 | + ssh_free(s->session); | ||
896 | } | ||
897 | s->session = NULL; | ||
898 | + s->sock = -1; | ||
899 | + if (new_sock >= 0) { | ||
900 | + close(new_sock); | ||
901 | + } | ||
902 | |||
903 | return ret; | ||
904 | } | ||
905 | @@ -XXX,XX +XXX,XX @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, | ||
906 | |||
907 | ssh_state_init(s); | ||
908 | |||
909 | - ssh_flags = LIBSSH2_FXF_READ; | ||
910 | + ssh_flags = 0; | ||
911 | if (bdrv_flags & BDRV_O_RDWR) { | ||
912 | - ssh_flags |= LIBSSH2_FXF_WRITE; | ||
913 | + ssh_flags |= O_RDWR; | ||
914 | + } else { | ||
915 | + ssh_flags |= O_RDONLY; | ||
916 | } | ||
917 | |||
918 | opts = ssh_parse_options(options, errp); | ||
919 | @@ -XXX,XX +XXX,XX @@ static int ssh_file_open(BlockDriverState *bs, QDict *options, int bdrv_flags, | ||
920 | } | ||
921 | |||
922 | /* Go non-blocking. */ | ||
923 | - libssh2_session_set_blocking(s->session, 0); | ||
924 | + ssh_set_blocking(s->session, 0); | ||
925 | |||
926 | qapi_free_BlockdevOptionsSsh(opts); | ||
927 | |||
928 | return 0; | ||
929 | |||
930 | err: | ||
931 | - if (s->sock >= 0) { | ||
932 | - close(s->sock); | ||
933 | - } | ||
934 | - s->sock = -1; | ||
935 | - | ||
936 | qapi_free_BlockdevOptionsSsh(opts); | ||
937 | |||
938 | return ret; | ||
939 | @@ -XXX,XX +XXX,XX @@ static int ssh_grow_file(BDRVSSHState *s, int64_t offset, Error **errp) | ||
940 | { | ||
941 | ssize_t ret; | ||
942 | char c[1] = { '\0' }; | ||
943 | - int was_blocking = libssh2_session_get_blocking(s->session); | ||
944 | + int was_blocking = ssh_is_blocking(s->session); | ||
945 | |||
946 | /* offset must be strictly greater than the current size so we do | ||
947 | * not overwrite anything */ | ||
948 | - assert(offset > 0 && offset > s->attrs.filesize); | ||
949 | + assert(offset > 0 && offset > s->attrs->size); | ||
950 | |||
951 | - libssh2_session_set_blocking(s->session, 1); | ||
952 | + ssh_set_blocking(s->session, 1); | ||
953 | |||
954 | - libssh2_sftp_seek64(s->sftp_handle, offset - 1); | ||
955 | - ret = libssh2_sftp_write(s->sftp_handle, c, 1); | ||
956 | + sftp_seek64(s->sftp_handle, offset - 1); | ||
957 | + ret = sftp_write(s->sftp_handle, c, 1); | ||
958 | |||
959 | - libssh2_session_set_blocking(s->session, was_blocking); | ||
960 | + ssh_set_blocking(s->session, was_blocking); | ||
961 | |||
962 | if (ret < 0) { | ||
963 | sftp_error_setg(errp, s, "Failed to grow file"); | ||
964 | return -EIO; | ||
965 | } | ||
966 | |||
967 | - s->attrs.filesize = offset; | ||
968 | + s->attrs->size = offset; | ||
969 | return 0; | ||
970 | } | ||
971 | |||
972 | @@ -XXX,XX +XXX,XX @@ static int ssh_co_create(BlockdevCreateOptions *options, Error **errp) | ||
973 | ssh_state_init(&s); | ||
974 | |||
975 | ret = connect_to_ssh(&s, opts->location, | ||
976 | - LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE| | ||
977 | - LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, | ||
978 | + O_RDWR | O_CREAT | O_TRUNC, | ||
979 | 0644, errp); | ||
980 | if (ret < 0) { | ||
981 | goto fail; | ||
982 | @@ -XXX,XX +XXX,XX @@ static int ssh_has_zero_init(BlockDriverState *bs) | ||
983 | /* Assume false, unless we can positively prove it's true. */ | ||
984 | int has_zero_init = 0; | ||
985 | |||
986 | - if (s->attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) { | ||
987 | - if (s->attrs.permissions & LIBSSH2_SFTP_S_IFREG) { | ||
988 | - has_zero_init = 1; | ||
989 | - } | ||
990 | + if (s->attrs->type == SSH_FILEXFER_TYPE_REGULAR) { | ||
991 | + has_zero_init = 1; | ||
992 | } | ||
993 | |||
994 | return has_zero_init; | ||
995 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) | ||
996 | .co = qemu_coroutine_self() | ||
997 | }; | ||
998 | |||
999 | - r = libssh2_session_block_directions(s->session); | ||
1000 | + r = ssh_get_poll_flags(s->session); | ||
1001 | |||
1002 | - if (r & LIBSSH2_SESSION_BLOCK_INBOUND) { | ||
1003 | + if (r & SSH_READ_PENDING) { | ||
1004 | rd_handler = restart_coroutine; | ||
1005 | } | ||
1006 | - if (r & LIBSSH2_SESSION_BLOCK_OUTBOUND) { | ||
1007 | + if (r & SSH_WRITE_PENDING) { | ||
1008 | wr_handler = restart_coroutine; | ||
1009 | } | ||
1010 | |||
1011 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) | ||
1012 | trace_ssh_co_yield_back(s->sock); | ||
1013 | } | ||
1014 | |||
1015 | -/* SFTP has a function `libssh2_sftp_seek64' which seeks to a position | ||
1016 | - * in the remote file. Notice that it just updates a field in the | ||
1017 | - * sftp_handle structure, so there is no network traffic and it cannot | ||
1018 | - * fail. | ||
1019 | - * | ||
1020 | - * However, `libssh2_sftp_seek64' does have a catastrophic effect on | ||
1021 | - * performance since it causes the handle to throw away all in-flight | ||
1022 | - * reads and buffered readahead data. Therefore this function tries | ||
1023 | - * to be intelligent about when to call the underlying libssh2 function. | ||
1024 | - */ | ||
1025 | -#define SSH_SEEK_WRITE 0 | ||
1026 | -#define SSH_SEEK_READ 1 | ||
1027 | -#define SSH_SEEK_FORCE 2 | ||
1028 | - | ||
1029 | -static void ssh_seek(BDRVSSHState *s, int64_t offset, int flags) | ||
1030 | -{ | ||
1031 | - bool op_read = (flags & SSH_SEEK_READ) != 0; | ||
1032 | - bool force = (flags & SSH_SEEK_FORCE) != 0; | ||
1033 | - | ||
1034 | - if (force || op_read != s->offset_op_read || offset != s->offset) { | ||
1035 | - trace_ssh_seek(offset); | ||
1036 | - libssh2_sftp_seek64(s->sftp_handle, offset); | ||
1037 | - s->offset = offset; | ||
1038 | - s->offset_op_read = op_read; | ||
1039 | - } | ||
1040 | -} | ||
1041 | - | ||
1042 | static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1043 | int64_t offset, size_t size, | ||
1044 | QEMUIOVector *qiov) | ||
1045 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1046 | |||
1047 | trace_ssh_read(offset, size); | ||
1048 | |||
1049 | - ssh_seek(s, offset, SSH_SEEK_READ); | ||
1050 | + trace_ssh_seek(offset); | ||
1051 | + sftp_seek64(s->sftp_handle, offset); | ||
1052 | |||
1053 | /* This keeps track of the current iovec element ('i'), where we | ||
1054 | * will write to next ('buf'), and the end of the current iovec | ||
1055 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs, | ||
1056 | buf = i->iov_base; | ||
1057 | end_of_vec = i->iov_base + i->iov_len; | ||
1058 | |||
1059 | - /* libssh2 has a hard-coded limit of 2000 bytes per request, | ||
1060 | - * although it will also do readahead behind our backs. Therefore | ||
1061 | - * we may have to do repeated reads here until we have read 'size' | ||
1062 | - * bytes. | ||
1063 | - */ | ||
1064 | for (got = 0; got < size; ) { | ||
1065 | + size_t request_read_size; | ||
1066 | again: | ||
1067 | - trace_ssh_read_buf(buf, end_of_vec - buf); | ||
1068 | - r = libssh2_sftp_read(s->sftp_handle, buf, end_of_vec - buf); | ||
1069 | - trace_ssh_read_return(r); | ||
1070 | + /* | ||
1071 | + * The size of SFTP packets is limited to 32K bytes, so limit | ||
1072 | + * the amount of data requested to 16K, as libssh currently | ||
1073 | + * does not handle multiple requests on its own. | ||
1074 | + */ | ||
1075 | + request_read_size = MIN(end_of_vec - buf, 16384); | ||
1076 | + trace_ssh_read_buf(buf, end_of_vec - buf, request_read_size); | ||
1077 | + r = sftp_read(s->sftp_handle, buf, request_read_size); | ||
1078 | + trace_ssh_read_return(r, sftp_get_error(s->sftp)); | ||
1079 | |||
1080 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1081 | + if (r == SSH_AGAIN) { | ||
1082 | co_yield(s, bs); | ||
1083 | goto again; | ||
1084 | } | ||
1085 | - if (r < 0) { | ||
1086 | - sftp_error_trace(s, "read"); | ||
1087 | - s->offset = -1; | ||
1088 | - return -EIO; | ||
1089 | - } | ||
1090 | - if (r == 0) { | ||
1091 | + if (r == SSH_EOF || (r == 0 && sftp_get_error(s->sftp) == SSH_FX_EOF)) { | ||
1092 | /* EOF: Short read so pad the buffer with zeroes and return it. */ | ||
1093 | qemu_iovec_memset(qiov, got, 0, size - got); | ||
1094 | return 0; | ||
1095 | } | ||
1096 | + if (r <= 0) { | ||
1097 | + sftp_error_trace(s, "read"); | ||
1098 | + return -EIO; | ||
1099 | + } | ||
1100 | |||
1101 | got += r; | ||
1102 | buf += r; | ||
1103 | - s->offset += r; | ||
1104 | if (buf >= end_of_vec && got < size) { | ||
1105 | i++; | ||
1106 | buf = i->iov_base; | ||
1107 | @@ -XXX,XX +XXX,XX @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, | ||
1108 | |||
1109 | trace_ssh_write(offset, size); | ||
1110 | |||
1111 | - ssh_seek(s, offset, SSH_SEEK_WRITE); | ||
1112 | + trace_ssh_seek(offset); | ||
1113 | + sftp_seek64(s->sftp_handle, offset); | ||
1114 | |||
1115 | /* This keeps track of the current iovec element ('i'), where we | ||
1116 | * will read from next ('buf'), and the end of the current iovec | ||
1117 | @@ -XXX,XX +XXX,XX @@ static int ssh_write(BDRVSSHState *s, BlockDriverState *bs, | ||
1118 | end_of_vec = i->iov_base + i->iov_len; | ||
1119 | |||
1120 | for (written = 0; written < size; ) { | ||
1121 | + size_t request_write_size; | ||
1122 | again: | ||
1123 | - trace_ssh_write_buf(buf, end_of_vec - buf); | ||
1124 | - r = libssh2_sftp_write(s->sftp_handle, buf, end_of_vec - buf); | ||
1125 | - trace_ssh_write_return(r); | ||
1126 | + /* | ||
1127 | + * Avoid too large data packets, as libssh currently does not | ||
1128 | + * handle multiple requests on its own. | ||
1129 | + */ | ||
1130 | + request_write_size = MIN(end_of_vec - buf, 131072); | ||
1131 | + trace_ssh_write_buf(buf, end_of_vec - buf, request_write_size); | ||
1132 | + r = sftp_write(s->sftp_handle, buf, request_write_size); | ||
1133 | + trace_ssh_write_return(r, sftp_get_error(s->sftp)); | ||
1134 | |||
1135 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1136 | + if (r == SSH_AGAIN) { | ||
1137 | co_yield(s, bs); | ||
1138 | goto again; | ||
1139 | } | ||
1140 | if (r < 0) { | ||
1141 | sftp_error_trace(s, "write"); | ||
1142 | - s->offset = -1; | ||
1143 | return -EIO; | ||
1144 | } | ||
1145 | - /* The libssh2 API is very unclear about this. A comment in | ||
1146 | - * the code says "nothing was acked, and no EAGAIN was | ||
1147 | - * received!" which apparently means that no data got sent | ||
1148 | - * out, and the underlying channel didn't return any EAGAIN | ||
1149 | - * indication. I think this is a bug in either libssh2 or | ||
1150 | - * OpenSSH (server-side). In any case, forcing a seek (to | ||
1151 | - * discard libssh2 internal buffers), and then trying again | ||
1152 | - * works for me. | ||
1153 | - */ | ||
1154 | - if (r == 0) { | ||
1155 | - ssh_seek(s, offset + written, SSH_SEEK_WRITE|SSH_SEEK_FORCE); | ||
1156 | - co_yield(s, bs); | ||
1157 | - goto again; | ||
1158 | - } | ||
1159 | |||
1160 | written += r; | ||
1161 | buf += r; | ||
1162 | - s->offset += r; | ||
1163 | if (buf >= end_of_vec && written < size) { | ||
1164 | i++; | ||
1165 | buf = i->iov_base; | ||
1166 | end_of_vec = i->iov_base + i->iov_len; | ||
1167 | } | ||
1168 | |||
1169 | - if (offset + written > s->attrs.filesize) | ||
1170 | - s->attrs.filesize = offset + written; | ||
1171 | + if (offset + written > s->attrs->size) { | ||
1172 | + s->attrs->size = offset + written; | ||
1173 | + } | ||
1174 | } | ||
1175 | |||
1176 | return 0; | ||
1177 | @@ -XXX,XX +XXX,XX @@ static void unsafe_flush_warning(BDRVSSHState *s, const char *what) | ||
1178 | } | ||
1179 | } | ||
1180 | |||
1181 | -#ifdef HAS_LIBSSH2_SFTP_FSYNC | ||
1182 | +#ifdef HAVE_LIBSSH_0_8 | ||
1183 | |||
1184 | static coroutine_fn int ssh_flush(BDRVSSHState *s, BlockDriverState *bs) | ||
1185 | { | ||
1186 | int r; | ||
1187 | |||
1188 | trace_ssh_flush(); | ||
1189 | + | ||
1190 | + if (!sftp_extension_supported(s->sftp, "fsync@openssh.com", "1")) { | ||
1191 | + unsafe_flush_warning(s, "OpenSSH >= 6.3"); | ||
1192 | + return 0; | ||
1193 | + } | ||
1194 | again: | ||
1195 | - r = libssh2_sftp_fsync(s->sftp_handle); | ||
1196 | - if (r == LIBSSH2_ERROR_EAGAIN || r == LIBSSH2_ERROR_TIMEOUT) { | ||
1197 | + r = sftp_fsync(s->sftp_handle); | ||
1198 | + if (r == SSH_AGAIN) { | ||
1199 | co_yield(s, bs); | ||
1200 | goto again; | ||
1201 | } | ||
1202 | - if (r == LIBSSH2_ERROR_SFTP_PROTOCOL && | ||
1203 | - libssh2_sftp_last_error(s->sftp) == LIBSSH2_FX_OP_UNSUPPORTED) { | ||
1204 | - unsafe_flush_warning(s, "OpenSSH >= 6.3"); | ||
1205 | - return 0; | ||
1206 | - } | ||
1207 | if (r < 0) { | ||
1208 | sftp_error_trace(s, "fsync"); | ||
1209 | return -EIO; | ||
1210 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int ssh_co_flush(BlockDriverState *bs) | ||
1211 | return ret; | ||
1212 | } | ||
1213 | |||
1214 | -#else /* !HAS_LIBSSH2_SFTP_FSYNC */ | ||
1215 | +#else /* !HAVE_LIBSSH_0_8 */ | ||
1216 | |||
1217 | static coroutine_fn int ssh_co_flush(BlockDriverState *bs) | ||
1218 | { | ||
1219 | BDRVSSHState *s = bs->opaque; | ||
1220 | |||
1221 | - unsafe_flush_warning(s, "libssh2 >= 1.4.4"); | ||
1222 | + unsafe_flush_warning(s, "libssh >= 0.8.0"); | ||
1223 | return 0; | ||
1224 | } | ||
1225 | |||
1226 | -#endif /* !HAS_LIBSSH2_SFTP_FSYNC */ | ||
1227 | +#endif /* !HAVE_LIBSSH_0_8 */ | ||
1228 | |||
1229 | static int64_t ssh_getlength(BlockDriverState *bs) | ||
1230 | { | ||
1231 | BDRVSSHState *s = bs->opaque; | ||
1232 | int64_t length; | ||
1233 | |||
1234 | - /* Note we cannot make a libssh2 call here. */ | ||
1235 | - length = (int64_t) s->attrs.filesize; | ||
1236 | + /* Note we cannot make a libssh call here. */ | ||
1237 | + length = (int64_t) s->attrs->size; | ||
1238 | trace_ssh_getlength(length); | ||
1239 | |||
1240 | return length; | ||
1241 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn ssh_co_truncate(BlockDriverState *bs, int64_t offset, | ||
1242 | return -ENOTSUP; | ||
1243 | } | ||
1244 | |||
1245 | - if (offset < s->attrs.filesize) { | ||
1246 | + if (offset < s->attrs->size) { | ||
1247 | error_setg(errp, "ssh driver does not support shrinking files"); | ||
1248 | return -ENOTSUP; | ||
1249 | } | ||
1250 | |||
1251 | - if (offset == s->attrs.filesize) { | ||
1252 | + if (offset == s->attrs->size) { | ||
1253 | return 0; | ||
1254 | } | ||
1255 | |||
1256 | @@ -XXX,XX +XXX,XX @@ static void bdrv_ssh_init(void) | ||
1257 | { | ||
1258 | int r; | ||
1259 | |||
1260 | - r = libssh2_init(0); | ||
1261 | + r = ssh_init(); | ||
1262 | if (r != 0) { | ||
1263 | - fprintf(stderr, "libssh2 initialization failed, %d\n", r); | ||
1264 | + fprintf(stderr, "libssh initialization failed, %d\n", r); | ||
1265 | exit(EXIT_FAILURE); | ||
1266 | } | ||
1267 | |||
1268 | +#if TRACE_LIBSSH != 0 | ||
1269 | + ssh_set_log_level(TRACE_LIBSSH); | ||
1270 | +#endif | ||
1271 | + | ||
1272 | bdrv_register(&bdrv_ssh); | ||
1273 | } | ||
1274 | |||
1275 | diff --git a/.travis.yml b/.travis.yml | ||
375 | index XXXXXXX..XXXXXXX 100644 | 1276 | index XXXXXXX..XXXXXXX 100644 |
376 | --- a/tests/qemu-iotests/257.out | 1277 | --- a/.travis.yml |
377 | +++ b/tests/qemu-iotests/257.out | 1278 | +++ b/.travis.yml |
378 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1279 | @@ -XXX,XX +XXX,XX @@ addons: |
379 | {"return": ""} | 1280 | - libseccomp-dev |
380 | { | 1281 | - libspice-protocol-dev |
381 | "bitmaps": { | 1282 | - libspice-server-dev |
382 | + "backup-top": [ | 1283 | - - libssh2-1-dev |
383 | + { | 1284 | + - libssh-dev |
384 | + "busy": false, | 1285 | - liburcu-dev |
385 | + "count": 67108864, | 1286 | - libusb-1.0-0-dev |
386 | + "granularity": 65536, | 1287 | - libvte-2.91-dev |
387 | + "persistent": false, | 1288 | @@ -XXX,XX +XXX,XX @@ matrix: |
388 | + "recording": false | 1289 | - libseccomp-dev |
389 | + }, | 1290 | - libspice-protocol-dev |
390 | + { | 1291 | - libspice-server-dev |
391 | + "busy": false, | 1292 | - - libssh2-1-dev |
392 | + "count": 458752, | 1293 | + - libssh-dev |
393 | + "granularity": 65536, | 1294 | - liburcu-dev |
394 | + "persistent": false, | 1295 | - libusb-1.0-0-dev |
395 | + "recording": false | 1296 | - libvte-2.91-dev |
396 | + } | 1297 | diff --git a/block/trace-events b/block/trace-events |
397 | + ], | 1298 | index XXXXXXX..XXXXXXX 100644 |
398 | "drive0": [ | 1299 | --- a/block/trace-events |
399 | { | 1300 | +++ b/block/trace-events |
400 | "busy": false, | 1301 | @@ -XXX,XX +XXX,XX @@ nbd_client_connect_success(const char *export_name) "export '%s'" |
401 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1302 | # ssh.c |
402 | {"return": ""} | 1303 | ssh_restart_coroutine(void *co) "co=%p" |
403 | { | 1304 | ssh_flush(void) "fsync" |
404 | "bitmaps": { | 1305 | -ssh_check_host_key_knownhosts(const char *key) "host key OK: %s" |
405 | + "backup-top": [ | 1306 | +ssh_check_host_key_knownhosts(void) "host key OK" |
406 | + { | 1307 | ssh_connect_to_ssh(char *path, int flags, int mode) "opening file %s flags=0x%x creat_mode=0%o" |
407 | + "busy": false, | 1308 | ssh_co_yield(int sock, void *rd_handler, void *wr_handler) "s->sock=%d rd_handler=%p wr_handler=%p" |
408 | + "count": 67108864, | 1309 | ssh_co_yield_back(int sock) "s->sock=%d - back" |
409 | + "granularity": 65536, | 1310 | ssh_getlength(int64_t length) "length=%" PRIi64 |
410 | + "persistent": false, | 1311 | ssh_co_create_opts(uint64_t size) "total_size=%" PRIu64 |
411 | + "recording": false | 1312 | ssh_read(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" |
412 | + }, | 1313 | -ssh_read_buf(void *buf, size_t size) "sftp_read buf=%p size=%zu" |
413 | + { | 1314 | -ssh_read_return(ssize_t ret) "sftp_read returned %zd" |
414 | + "busy": false, | 1315 | +ssh_read_buf(void *buf, size_t size, size_t actual_size) "sftp_read buf=%p size=%zu (actual size=%zu)" |
415 | + "count": 458752, | 1316 | +ssh_read_return(ssize_t ret, int sftp_err) "sftp_read returned %zd (sftp error=%d)" |
416 | + "granularity": 65536, | 1317 | ssh_write(int64_t offset, size_t size) "offset=%" PRIi64 " size=%zu" |
417 | + "persistent": false, | 1318 | -ssh_write_buf(void *buf, size_t size) "sftp_write buf=%p size=%zu" |
418 | + "recording": false | 1319 | -ssh_write_return(ssize_t ret) "sftp_write returned %zd" |
419 | + } | 1320 | +ssh_write_buf(void *buf, size_t size, size_t actual_size) "sftp_write buf=%p size=%zu (actual size=%zu)" |
420 | + ], | 1321 | +ssh_write_return(ssize_t ret, int sftp_err) "sftp_write returned %zd (sftp error=%d)" |
421 | "drive0": [ | 1322 | ssh_seek(int64_t offset) "seeking to offset=%" PRIi64 |
422 | { | 1323 | +ssh_auth_methods(int methods) "auth methods=0x%x" |
423 | "busy": false, | 1324 | +ssh_server_status(int status) "server status=%d" |
424 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1325 | |
425 | {"return": ""} | 1326 | # curl.c |
426 | { | 1327 | curl_timer_cb(long timeout_ms) "timer callback timeout_ms %ld" |
427 | "bitmaps": { | 1328 | @@ -XXX,XX +XXX,XX @@ sheepdog_snapshot_create(const char *sn_name, const char *id) "%s %s" |
428 | + "backup-top": [ | 1329 | sheepdog_snapshot_create_inode(const char *name, uint32_t snap, uint32_t vdi) "s->inode: name %s snap_id 0x%" PRIx32 " vdi 0x%" PRIx32 |
429 | + { | 1330 | |
430 | + "busy": false, | 1331 | # ssh.c |
431 | + "count": 67108864, | 1332 | -sftp_error(const char *op, const char *ssh_err, int ssh_err_code, unsigned long sftp_err_code) "%s failed: %s (libssh2 error code: %d, sftp error code: %lu)" |
432 | + "granularity": 65536, | 1333 | +sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp_err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)" |
433 | + "persistent": false, | 1334 | diff --git a/docs/qemu-block-drivers.texi b/docs/qemu-block-drivers.texi |
434 | + "recording": false | 1335 | index XXXXXXX..XXXXXXX 100644 |
435 | + }, | 1336 | --- a/docs/qemu-block-drivers.texi |
436 | + { | 1337 | +++ b/docs/qemu-block-drivers.texi |
437 | + "busy": false, | 1338 | @@ -XXX,XX +XXX,XX @@ print a warning when @code{fsync} is not supported: |
438 | + "count": 458752, | 1339 | |
439 | + "granularity": 65536, | 1340 | warning: ssh server @code{ssh.example.com:22} does not support fsync |
440 | + "persistent": false, | 1341 | |
441 | + "recording": false | 1342 | -With sufficiently new versions of libssh2 and OpenSSH, @code{fsync} is |
442 | + } | 1343 | +With sufficiently new versions of libssh and OpenSSH, @code{fsync} is |
443 | + ], | 1344 | supported. |
444 | "drive0": [ | 1345 | |
445 | { | 1346 | @node disk_images_nvme |
446 | "busy": false, | 1347 | diff --git a/tests/docker/dockerfiles/debian-win32-cross.docker b/tests/docker/dockerfiles/debian-win32-cross.docker |
447 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1348 | index XXXXXXX..XXXXXXX 100644 |
448 | {"return": ""} | 1349 | --- a/tests/docker/dockerfiles/debian-win32-cross.docker |
449 | { | 1350 | +++ b/tests/docker/dockerfiles/debian-win32-cross.docker |
450 | "bitmaps": { | 1351 | @@ -XXX,XX +XXX,XX @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \ |
451 | + "backup-top": [ | 1352 | mxe-$TARGET-w64-mingw32.shared-curl \ |
452 | + { | 1353 | mxe-$TARGET-w64-mingw32.shared-glib \ |
453 | + "busy": false, | 1354 | mxe-$TARGET-w64-mingw32.shared-libgcrypt \ |
454 | + "count": 67108864, | 1355 | - mxe-$TARGET-w64-mingw32.shared-libssh2 \ |
455 | + "granularity": 65536, | 1356 | mxe-$TARGET-w64-mingw32.shared-libusb1 \ |
456 | + "persistent": false, | 1357 | mxe-$TARGET-w64-mingw32.shared-lzo \ |
457 | + "recording": false | 1358 | mxe-$TARGET-w64-mingw32.shared-nettle \ |
458 | + }, | 1359 | diff --git a/tests/docker/dockerfiles/debian-win64-cross.docker b/tests/docker/dockerfiles/debian-win64-cross.docker |
459 | + { | 1360 | index XXXXXXX..XXXXXXX 100644 |
460 | + "busy": false, | 1361 | --- a/tests/docker/dockerfiles/debian-win64-cross.docker |
461 | + "count": 458752, | 1362 | +++ b/tests/docker/dockerfiles/debian-win64-cross.docker |
462 | + "granularity": 65536, | 1363 | @@ -XXX,XX +XXX,XX @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \ |
463 | + "persistent": false, | 1364 | mxe-$TARGET-w64-mingw32.shared-curl \ |
464 | + "recording": false | 1365 | mxe-$TARGET-w64-mingw32.shared-glib \ |
465 | + } | 1366 | mxe-$TARGET-w64-mingw32.shared-libgcrypt \ |
466 | + ], | 1367 | - mxe-$TARGET-w64-mingw32.shared-libssh2 \ |
467 | "drive0": [ | 1368 | mxe-$TARGET-w64-mingw32.shared-libusb1 \ |
468 | { | 1369 | mxe-$TARGET-w64-mingw32.shared-lzo \ |
469 | "busy": false, | 1370 | mxe-$TARGET-w64-mingw32.shared-nettle \ |
470 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1371 | diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfiles/fedora.docker |
471 | {"return": ""} | 1372 | index XXXXXXX..XXXXXXX 100644 |
472 | { | 1373 | --- a/tests/docker/dockerfiles/fedora.docker |
473 | "bitmaps": { | 1374 | +++ b/tests/docker/dockerfiles/fedora.docker |
474 | + "backup-top": [ | 1375 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ |
475 | + { | 1376 | libpng-devel \ |
476 | + "busy": false, | 1377 | librbd-devel \ |
477 | + "count": 67108864, | 1378 | libseccomp-devel \ |
478 | + "granularity": 65536, | 1379 | - libssh2-devel \ |
479 | + "persistent": false, | 1380 | + libssh-devel \ |
480 | + "recording": false | 1381 | libubsan \ |
481 | + }, | 1382 | libusbx-devel \ |
482 | + { | 1383 | libxml2-devel \ |
483 | + "busy": false, | 1384 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ |
484 | + "count": 458752, | 1385 | mingw32-gtk3 \ |
485 | + "granularity": 65536, | 1386 | mingw32-libjpeg-turbo \ |
486 | + "persistent": false, | 1387 | mingw32-libpng \ |
487 | + "recording": false | 1388 | - mingw32-libssh2 \ |
488 | + } | 1389 | mingw32-libtasn1 \ |
489 | + ], | 1390 | mingw32-nettle \ |
490 | "drive0": [ | 1391 | mingw32-pixman \ |
491 | { | 1392 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES \ |
492 | "busy": false, | 1393 | mingw64-gtk3 \ |
493 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1394 | mingw64-libjpeg-turbo \ |
494 | {"return": ""} | 1395 | mingw64-libpng \ |
495 | { | 1396 | - mingw64-libssh2 \ |
496 | "bitmaps": { | 1397 | mingw64-libtasn1 \ |
497 | + "backup-top": [ | 1398 | mingw64-nettle \ |
498 | + { | 1399 | mingw64-pixman \ |
499 | + "busy": false, | 1400 | diff --git a/tests/docker/dockerfiles/ubuntu.docker b/tests/docker/dockerfiles/ubuntu.docker |
500 | + "count": 67108864, | 1401 | index XXXXXXX..XXXXXXX 100644 |
501 | + "granularity": 65536, | 1402 | --- a/tests/docker/dockerfiles/ubuntu.docker |
502 | + "persistent": false, | 1403 | +++ b/tests/docker/dockerfiles/ubuntu.docker |
503 | + "recording": false | 1404 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES flex bison \ |
504 | + }, | 1405 | libsnappy-dev \ |
505 | + { | 1406 | libspice-protocol-dev \ |
506 | + "busy": false, | 1407 | libspice-server-dev \ |
507 | + "count": 458752, | 1408 | - libssh2-1-dev \ |
508 | + "granularity": 65536, | 1409 | + libssh-dev \ |
509 | + "persistent": false, | 1410 | libusb-1.0-0-dev \ |
510 | + "recording": false | 1411 | libusbredirhost-dev \ |
511 | + } | 1412 | libvdeplug-dev \ |
512 | + ], | 1413 | diff --git a/tests/docker/dockerfiles/ubuntu1804.docker b/tests/docker/dockerfiles/ubuntu1804.docker |
513 | "drive0": [ | 1414 | index XXXXXXX..XXXXXXX 100644 |
514 | { | 1415 | --- a/tests/docker/dockerfiles/ubuntu1804.docker |
515 | "busy": false, | 1416 | +++ b/tests/docker/dockerfiles/ubuntu1804.docker |
516 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1417 | @@ -XXX,XX +XXX,XX @@ ENV PACKAGES flex bison \ |
517 | {"return": ""} | 1418 | libsnappy-dev \ |
518 | { | 1419 | libspice-protocol-dev \ |
519 | "bitmaps": { | 1420 | libspice-server-dev \ |
520 | + "backup-top": [ | 1421 | - libssh2-1-dev \ |
521 | + { | 1422 | + libssh-dev \ |
522 | + "busy": false, | 1423 | libusb-1.0-0-dev \ |
523 | + "count": 67108864, | 1424 | libusbredirhost-dev \ |
524 | + "granularity": 65536, | 1425 | libvdeplug-dev \ |
525 | + "persistent": false, | 1426 | diff --git a/tests/qemu-iotests/207 b/tests/qemu-iotests/207 |
526 | + "recording": false | 1427 | index XXXXXXX..XXXXXXX 100755 |
527 | + }, | 1428 | --- a/tests/qemu-iotests/207 |
528 | + { | 1429 | +++ b/tests/qemu-iotests/207 |
529 | + "busy": false, | 1430 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ |
530 | + "count": 458752, | 1431 | |
531 | + "granularity": 65536, | 1432 | iotests.img_info_log(remote_path) |
532 | + "persistent": false, | 1433 | |
533 | + "recording": false | 1434 | - md5_key = subprocess.check_output( |
534 | + } | 1435 | - 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + |
535 | + ], | 1436 | - 'cut -d" " -f3 | base64 -d | md5sum -b | cut -d" " -f1', |
536 | "drive0": [ | 1437 | - shell=True).rstrip().decode('ascii') |
537 | { | 1438 | + keys = subprocess.check_output( |
538 | "busy": false, | 1439 | + 'ssh-keyscan 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + |
539 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1440 | + 'cut -d" " -f3', |
540 | {"return": ""} | 1441 | + shell=True).rstrip().decode('ascii').split('\n') |
541 | { | 1442 | + |
542 | "bitmaps": { | 1443 | + # Mappings of base64 representations to digests |
543 | + "backup-top": [ | 1444 | + md5_keys = {} |
544 | + { | 1445 | + sha1_keys = {} |
545 | + "busy": false, | 1446 | + |
546 | + "count": 67108864, | 1447 | + for key in keys: |
547 | + "granularity": 65536, | 1448 | + md5_keys[key] = subprocess.check_output( |
548 | + "persistent": false, | 1449 | + 'echo %s | base64 -d | md5sum -b | cut -d" " -f1' % key, |
549 | + "recording": false | 1450 | + shell=True).rstrip().decode('ascii') |
550 | + }, | 1451 | + |
551 | + { | 1452 | + sha1_keys[key] = subprocess.check_output( |
552 | + "busy": false, | 1453 | + 'echo %s | base64 -d | sha1sum -b | cut -d" " -f1' % key, |
553 | + "count": 458752, | 1454 | + shell=True).rstrip().decode('ascii') |
554 | + "granularity": 65536, | 1455 | |
555 | + "persistent": false, | 1456 | vm.launch() |
556 | + "recording": false | 1457 | + |
557 | + } | 1458 | + # Find correct key first |
558 | + ], | 1459 | + matching_key = None |
559 | "drive0": [ | 1460 | + for key in keys: |
560 | { | 1461 | + result = vm.qmp('blockdev-add', |
561 | "busy": false, | 1462 | + driver='ssh', node_name='node0', path=disk_path, |
562 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1463 | + server={ |
563 | {"return": ""} | 1464 | + 'host': '127.0.0.1', |
564 | { | 1465 | + 'port': '22', |
565 | "bitmaps": { | 1466 | + }, host_key_check={ |
566 | + "backup-top": [ | 1467 | + 'mode': 'hash', |
567 | + { | 1468 | + 'type': 'md5', |
568 | + "busy": false, | 1469 | + 'hash': md5_keys[key], |
569 | + "count": 67108864, | 1470 | + }) |
570 | + "granularity": 65536, | 1471 | + |
571 | + "persistent": false, | 1472 | + if 'error' not in result: |
572 | + "recording": false | 1473 | + vm.qmp('blockdev-del', node_name='node0') |
573 | + }, | 1474 | + matching_key = key |
574 | + { | 1475 | + break |
575 | + "busy": false, | 1476 | + |
576 | + "count": 458752, | 1477 | + if matching_key is None: |
577 | + "granularity": 65536, | 1478 | + vm.shutdown() |
578 | + "persistent": false, | 1479 | + iotests.notrun('Did not find a key that fits 127.0.0.1') |
579 | + "recording": false | 1480 | + |
580 | + } | 1481 | blockdev_create(vm, { 'driver': 'ssh', |
581 | + ], | 1482 | 'location': { |
582 | "drive0": [ | 1483 | 'path': disk_path, |
583 | { | 1484 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ |
584 | "busy": false, | 1485 | 'host-key-check': { |
585 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1486 | 'mode': 'hash', |
586 | {"return": ""} | 1487 | 'type': 'md5', |
587 | { | 1488 | - 'hash': md5_key, |
588 | "bitmaps": { | 1489 | + 'hash': md5_keys[matching_key], |
589 | + "backup-top": [ | 1490 | } |
590 | + { | 1491 | }, |
591 | + "busy": false, | 1492 | 'size': 8388608 }) |
592 | + "count": 67108864, | 1493 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ |
593 | + "granularity": 65536, | 1494 | |
594 | + "persistent": false, | 1495 | iotests.img_info_log(remote_path) |
595 | + "recording": false | 1496 | |
596 | + }, | 1497 | - sha1_key = subprocess.check_output( |
597 | + { | 1498 | - 'ssh-keyscan -t rsa 127.0.0.1 2>/dev/null | grep -v "\\^#" | ' + |
598 | + "busy": false, | 1499 | - 'cut -d" " -f3 | base64 -d | sha1sum -b | cut -d" " -f1', |
599 | + "count": 458752, | 1500 | - shell=True).rstrip().decode('ascii') |
600 | + "granularity": 65536, | 1501 | - |
601 | + "persistent": false, | 1502 | vm.launch() |
602 | + "recording": false | 1503 | blockdev_create(vm, { 'driver': 'ssh', |
603 | + } | 1504 | 'location': { |
604 | + ], | 1505 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('t.img') as disk_path, \ |
605 | "drive0": [ | 1506 | 'host-key-check': { |
606 | { | 1507 | 'mode': 'hash', |
607 | "busy": false, | 1508 | 'type': 'sha1', |
608 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | 1509 | - 'hash': sha1_key, |
609 | {"return": ""} | 1510 | + 'hash': sha1_keys[matching_key], |
610 | { | 1511 | } |
611 | "bitmaps": { | 1512 | }, |
612 | + "backup-top": [ | 1513 | 'size': 4194304 }) |
613 | + { | 1514 | diff --git a/tests/qemu-iotests/207.out b/tests/qemu-iotests/207.out |
614 | + "busy": false, | 1515 | index XXXXXXX..XXXXXXX 100644 |
615 | + "count": 67108864, | 1516 | --- a/tests/qemu-iotests/207.out |
616 | + "granularity": 65536, | 1517 | +++ b/tests/qemu-iotests/207.out |
617 | + "persistent": false, | 1518 | @@ -XXX,XX +XXX,XX @@ virtual size: 4 MiB (4194304 bytes) |
618 | + "recording": false | 1519 | |
619 | + }, | 1520 | {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "ssh", "location": {"host-key-check": {"mode": "none"}, "path": "/this/is/not/an/existing/path", "server": {"host": "127.0.0.1", "port": "22"}}, "size": 4194304}}} |
620 | + { | 1521 | {"return": {}} |
621 | + "busy": false, | 1522 | -Job failed: failed to open remote file '/this/is/not/an/existing/path': Failed opening remote file (libssh2 error code: -31) |
622 | + "count": 458752, | 1523 | +Job failed: failed to open remote file '/this/is/not/an/existing/path': SFTP server: No such file (libssh error code: 1, sftp error code: 2) |
623 | + "granularity": 65536, | 1524 | {"execute": "job-dismiss", "arguments": {"id": "job0"}} |
624 | + "persistent": false, | 1525 | {"return": {}} |
625 | + "recording": false | 1526 | |
626 | + } | ||
627 | + ], | ||
628 | "drive0": [ | ||
629 | { | ||
630 | "busy": false, | ||
631 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | ||
632 | {"return": ""} | ||
633 | { | ||
634 | "bitmaps": { | ||
635 | + "backup-top": [ | ||
636 | + { | ||
637 | + "busy": false, | ||
638 | + "count": 67108864, | ||
639 | + "granularity": 65536, | ||
640 | + "persistent": false, | ||
641 | + "recording": false | ||
642 | + }, | ||
643 | + { | ||
644 | + "busy": false, | ||
645 | + "count": 458752, | ||
646 | + "granularity": 65536, | ||
647 | + "persistent": false, | ||
648 | + "recording": false | ||
649 | + } | ||
650 | + ], | ||
651 | "drive0": [ | ||
652 | { | ||
653 | "busy": false, | ||
654 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | ||
655 | {"return": ""} | ||
656 | { | ||
657 | "bitmaps": { | ||
658 | + "backup-top": [ | ||
659 | + { | ||
660 | + "busy": false, | ||
661 | + "count": 67108864, | ||
662 | + "granularity": 65536, | ||
663 | + "persistent": false, | ||
664 | + "recording": false | ||
665 | + }, | ||
666 | + { | ||
667 | + "busy": false, | ||
668 | + "count": 458752, | ||
669 | + "granularity": 65536, | ||
670 | + "persistent": false, | ||
671 | + "recording": false | ||
672 | + } | ||
673 | + ], | ||
674 | "drive0": [ | ||
675 | { | ||
676 | "busy": false, | ||
677 | @@ -XXX,XX +XXX,XX @@ write -P0x67 0x3fe0000 0x20000 | ||
678 | {"return": ""} | ||
679 | { | ||
680 | "bitmaps": { | ||
681 | + "backup-top": [ | ||
682 | + { | ||
683 | + "busy": false, | ||
684 | + "count": 67108864, | ||
685 | + "granularity": 65536, | ||
686 | + "persistent": false, | ||
687 | + "recording": false | ||
688 | + }, | ||
689 | + { | ||
690 | + "busy": false, | ||
691 | + "count": 458752, | ||
692 | + "granularity": 65536, | ||
693 | + "persistent": false, | ||
694 | + "recording": false | ||
695 | + } | ||
696 | + ], | ||
697 | "drive0": [ | ||
698 | { | ||
699 | "busy": false, | ||
700 | -- | 1527 | -- |
701 | 2.34.1 | 1528 | 2.21.0 |
1529 | |||
1530 | diff view generated by jsdifflib |
1 | From: Peter Maydell <peter.maydell@linaro.org> | 1 | Tests should place their files into the test directory. This includes |
---|---|---|---|
2 | Unix sockets. 205 currently fails to do so, which prevents it from | ||
3 | being run concurrently. | ||
2 | 4 | ||
3 | In curl_open(), the 'out' label assumes that the state->errmsg string | 5 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
4 | has been set (either by curl_easy_perform() or by manually copying a | 6 | Message-id: 20190618210238.9524-1-mreitz@redhat.com |
5 | string into it); however if curl_init_state() fails we will jump to | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
6 | that label without setting the string. Add the missing error string | 8 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
7 | setup. | 9 | --- |
10 | tests/qemu-iotests/205 | 2 +- | ||
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
8 | 12 | ||
9 | (We can't be specific about the cause of failure: the documentation | 13 | diff --git a/tests/qemu-iotests/205 b/tests/qemu-iotests/205 |
10 | of curl_easy_init() just says "If this function returns NULL, | 14 | index XXXXXXX..XXXXXXX 100755 |
11 | something went wrong".) | 15 | --- a/tests/qemu-iotests/205 |
12 | 16 | +++ b/tests/qemu-iotests/205 | |
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | @@ -XXX,XX +XXX,XX @@ import iotests |
14 | Message-Id: <20220222152341.850419-2-peter.maydell@linaro.org> | 18 | import time |
15 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 19 | from iotests import qemu_img_create, qemu_io, filter_qemu_io, QemuIoInteractive |
16 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | 20 | |
17 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | 21 | -nbd_sock = 'nbd_sock' |
18 | --- | 22 | +nbd_sock = os.path.join(iotests.test_dir, 'nbd_sock') |
19 | block/curl.c | 2 ++ | 23 | nbd_uri = 'nbd+unix:///exp?socket=' + nbd_sock |
20 | 1 file changed, 2 insertions(+) | 24 | disk = os.path.join(iotests.test_dir, 'disk') |
21 | |||
22 | diff --git a/block/curl.c b/block/curl.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block/curl.c | ||
25 | +++ b/block/curl.c | ||
26 | @@ -XXX,XX +XXX,XX @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, | ||
27 | // Get file size | ||
28 | |||
29 | if (curl_init_state(s, state) < 0) { | ||
30 | + pstrcpy(state->errmsg, CURL_ERROR_SIZE, | ||
31 | + "curl library initialization failed."); | ||
32 | goto out; | ||
33 | } | ||
34 | 25 | ||
35 | -- | 26 | -- |
36 | 2.34.1 | 27 | 2.21.0 |
37 | 28 | ||
38 | 29 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Peter Maydell <peter.maydell@linaro.org> | ||
2 | 1 | ||
3 | Coverity points out that we aren't checking the return value | ||
4 | from curl_easy_setopt() for any of the calls to it we make | ||
5 | in block/curl.c. | ||
6 | |||
7 | Some of these options are documented as always succeeding (e.g. | ||
8 | CURLOPT_VERBOSE) but others have documented failure cases (e.g. | ||
9 | CURLOPT_URL). For consistency we check every call, even the ones | ||
10 | that theoretically cannot fail. | ||
11 | |||
12 | Fixes: Coverity CID 1459336, 1459482, 1460331 | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Message-Id: <20220222152341.850419-3-peter.maydell@linaro.org> | ||
15 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
17 | --- | ||
18 | block/curl.c | 90 +++++++++++++++++++++++++++++++++------------------- | ||
19 | 1 file changed, 57 insertions(+), 33 deletions(-) | ||
20 | |||
21 | diff --git a/block/curl.c b/block/curl.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/block/curl.c | ||
24 | +++ b/block/curl.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static int curl_init_state(BDRVCURLState *s, CURLState *state) | ||
26 | if (!state->curl) { | ||
27 | return -EIO; | ||
28 | } | ||
29 | - curl_easy_setopt(state->curl, CURLOPT_URL, s->url); | ||
30 | - curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, | ||
31 | - (long) s->sslverify); | ||
32 | - curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYHOST, | ||
33 | - s->sslverify ? 2L : 0L); | ||
34 | + if (curl_easy_setopt(state->curl, CURLOPT_URL, s->url) || | ||
35 | + curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER, | ||
36 | + (long) s->sslverify) || | ||
37 | + curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYHOST, | ||
38 | + s->sslverify ? 2L : 0L)) { | ||
39 | + goto err; | ||
40 | + } | ||
41 | if (s->cookie) { | ||
42 | - curl_easy_setopt(state->curl, CURLOPT_COOKIE, s->cookie); | ||
43 | + if (curl_easy_setopt(state->curl, CURLOPT_COOKIE, s->cookie)) { | ||
44 | + goto err; | ||
45 | + } | ||
46 | + } | ||
47 | + if (curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, (long)s->timeout) || | ||
48 | + curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, | ||
49 | + (void *)curl_read_cb) || | ||
50 | + curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state) || | ||
51 | + curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state) || | ||
52 | + curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1) || | ||
53 | + curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1) || | ||
54 | + curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1) || | ||
55 | + curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg) || | ||
56 | + curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1)) { | ||
57 | + goto err; | ||
58 | } | ||
59 | - curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, (long)s->timeout); | ||
60 | - curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION, | ||
61 | - (void *)curl_read_cb); | ||
62 | - curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state); | ||
63 | - curl_easy_setopt(state->curl, CURLOPT_PRIVATE, (void *)state); | ||
64 | - curl_easy_setopt(state->curl, CURLOPT_AUTOREFERER, 1); | ||
65 | - curl_easy_setopt(state->curl, CURLOPT_FOLLOWLOCATION, 1); | ||
66 | - curl_easy_setopt(state->curl, CURLOPT_NOSIGNAL, 1); | ||
67 | - curl_easy_setopt(state->curl, CURLOPT_ERRORBUFFER, state->errmsg); | ||
68 | - curl_easy_setopt(state->curl, CURLOPT_FAILONERROR, 1); | ||
69 | - | ||
70 | if (s->username) { | ||
71 | - curl_easy_setopt(state->curl, CURLOPT_USERNAME, s->username); | ||
72 | + if (curl_easy_setopt(state->curl, CURLOPT_USERNAME, s->username)) { | ||
73 | + goto err; | ||
74 | + } | ||
75 | } | ||
76 | if (s->password) { | ||
77 | - curl_easy_setopt(state->curl, CURLOPT_PASSWORD, s->password); | ||
78 | + if (curl_easy_setopt(state->curl, CURLOPT_PASSWORD, s->password)) { | ||
79 | + goto err; | ||
80 | + } | ||
81 | } | ||
82 | if (s->proxyusername) { | ||
83 | - curl_easy_setopt(state->curl, | ||
84 | - CURLOPT_PROXYUSERNAME, s->proxyusername); | ||
85 | + if (curl_easy_setopt(state->curl, | ||
86 | + CURLOPT_PROXYUSERNAME, s->proxyusername)) { | ||
87 | + goto err; | ||
88 | + } | ||
89 | } | ||
90 | if (s->proxypassword) { | ||
91 | - curl_easy_setopt(state->curl, | ||
92 | - CURLOPT_PROXYPASSWORD, s->proxypassword); | ||
93 | + if (curl_easy_setopt(state->curl, | ||
94 | + CURLOPT_PROXYPASSWORD, s->proxypassword)) { | ||
95 | + goto err; | ||
96 | + } | ||
97 | } | ||
98 | |||
99 | /* Restrict supported protocols to avoid security issues in the more | ||
100 | @@ -XXX,XX +XXX,XX @@ static int curl_init_state(BDRVCURLState *s, CURLState *state) | ||
101 | * Restricting protocols is only supported from 7.19.4 upwards. | ||
102 | */ | ||
103 | #if LIBCURL_VERSION_NUM >= 0x071304 | ||
104 | - curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS); | ||
105 | - curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS); | ||
106 | + if (curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS) || | ||
107 | + curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS)) { | ||
108 | + goto err; | ||
109 | + } | ||
110 | #endif | ||
111 | |||
112 | #ifdef DEBUG_VERBOSE | ||
113 | - curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1); | ||
114 | + if (curl_easy_setopt(state->curl, CURLOPT_VERBOSE, 1)) { | ||
115 | + goto err; | ||
116 | + } | ||
117 | #endif | ||
118 | } | ||
119 | |||
120 | state->s = s; | ||
121 | |||
122 | return 0; | ||
123 | + | ||
124 | +err: | ||
125 | + curl_easy_cleanup(state->curl); | ||
126 | + state->curl = NULL; | ||
127 | + return -EIO; | ||
128 | } | ||
129 | |||
130 | /* Called with s->mutex held. */ | ||
131 | @@ -XXX,XX +XXX,XX @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, | ||
132 | } | ||
133 | |||
134 | s->accept_range = false; | ||
135 | - curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1); | ||
136 | - curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION, | ||
137 | - curl_header_cb); | ||
138 | - curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s); | ||
139 | + if (curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1) || | ||
140 | + curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION, curl_header_cb) || | ||
141 | + curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s)) { | ||
142 | + pstrcpy(state->errmsg, CURL_ERROR_SIZE, | ||
143 | + "curl library initialization failed."); | ||
144 | + goto out; | ||
145 | + } | ||
146 | if (curl_easy_perform(state->curl)) | ||
147 | goto out; | ||
148 | if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) { | ||
149 | @@ -XXX,XX +XXX,XX @@ static void curl_setup_preadv(BlockDriverState *bs, CURLAIOCB *acb) | ||
150 | |||
151 | snprintf(state->range, 127, "%" PRIu64 "-%" PRIu64, start, end); | ||
152 | trace_curl_setup_preadv(acb->bytes, start, state->range); | ||
153 | - curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range); | ||
154 | - | ||
155 | - if (curl_multi_add_handle(s->multi, state->curl) != CURLM_OK) { | ||
156 | + if (curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range) || | ||
157 | + curl_multi_add_handle(s->multi, state->curl) != CURLM_OK) { | ||
158 | state->acb[0] = NULL; | ||
159 | acb->ret = -EIO; | ||
160 | |||
161 | -- | ||
162 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | There is a bug in handling BDRV_REQ_NO_WAIT flag: we still may wait in | ||
4 | wait_serialising_requests() if request is unaligned. And this is | ||
5 | possible for the only user of this flag (preallocate filter) if | ||
6 | underlying file is unaligned to its request_alignment on start. | ||
7 | |||
8 | So, we have to fix preallocate filter to do only aligned preallocate | ||
9 | requests. | ||
10 | |||
11 | Next, we should fix generic block/io.c somehow. Keeping in mind that | ||
12 | preallocate is the only user of BDRV_REQ_NO_WAIT and that we have to | ||
13 | fix its behavior now, it seems more safe to just assert that we never | ||
14 | use BDRV_REQ_NO_WAIT with unaligned requests and add corresponding | ||
15 | comment. Let's do so. | ||
16 | |||
17 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
18 | Reviewed-by: Denis V. Lunev <den@openvz.org> | ||
19 | Message-Id: <20220215121609.38570-1-vsementsov@virtuozzo.com> | ||
20 | [hreitz: Rebased on block GS/IO split] | ||
21 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
22 | --- | ||
23 | include/block/block-common.h | 3 ++- | ||
24 | block/io.c | 4 ++++ | ||
25 | block/preallocate.c | 15 ++++++++++++--- | ||
26 | 3 files changed, 18 insertions(+), 4 deletions(-) | ||
27 | |||
28 | diff --git a/include/block/block-common.h b/include/block/block-common.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/include/block/block-common.h | ||
31 | +++ b/include/block/block-common.h | ||
32 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
33 | |||
34 | /* | ||
35 | * If we need to wait for other requests, just fail immediately. Used | ||
36 | - * only together with BDRV_REQ_SERIALISING. | ||
37 | + * only together with BDRV_REQ_SERIALISING. Used only with requests aligned | ||
38 | + * to request_alignment (corresponding assertions are in block/io.c). | ||
39 | */ | ||
40 | BDRV_REQ_NO_WAIT = 0x400, | ||
41 | |||
42 | diff --git a/block/io.c b/block/io.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/block/io.c | ||
45 | +++ b/block/io.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, | ||
47 | |||
48 | padding = bdrv_init_padding(bs, offset, bytes, &pad); | ||
49 | if (padding) { | ||
50 | + assert(!(flags & BDRV_REQ_NO_WAIT)); | ||
51 | bdrv_make_request_serialising(req, align); | ||
52 | |||
53 | bdrv_padding_rmw_read(child, req, &pad, true); | ||
54 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, | ||
55 | * serialize the request to prevent interactions of the | ||
56 | * widened region with other transactions. | ||
57 | */ | ||
58 | + assert(!(flags & BDRV_REQ_NO_WAIT)); | ||
59 | bdrv_make_request_serialising(&req, align); | ||
60 | bdrv_padding_rmw_read(child, &req, &pad, false); | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal( | ||
63 | /* TODO We can support BDRV_REQ_NO_FALLBACK here */ | ||
64 | assert(!(read_flags & BDRV_REQ_NO_FALLBACK)); | ||
65 | assert(!(write_flags & BDRV_REQ_NO_FALLBACK)); | ||
66 | + assert(!(read_flags & BDRV_REQ_NO_WAIT)); | ||
67 | + assert(!(write_flags & BDRV_REQ_NO_WAIT)); | ||
68 | |||
69 | if (!dst || !dst->bs || !bdrv_is_inserted(dst->bs)) { | ||
70 | return -ENOMEDIUM; | ||
71 | diff --git a/block/preallocate.c b/block/preallocate.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/block/preallocate.c | ||
74 | +++ b/block/preallocate.c | ||
75 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset, | ||
76 | int64_t end = offset + bytes; | ||
77 | int64_t prealloc_start, prealloc_end; | ||
78 | int ret; | ||
79 | + uint32_t file_align = bs->file->bs->bl.request_alignment; | ||
80 | + uint32_t prealloc_align = MAX(s->opts.prealloc_align, file_align); | ||
81 | + | ||
82 | + assert(QEMU_IS_ALIGNED(prealloc_align, file_align)); | ||
83 | |||
84 | if (!has_prealloc_perms(bs)) { | ||
85 | /* We don't have state neither should try to recover it */ | ||
86 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset, | ||
87 | |||
88 | /* Now we want new preallocation, as request writes beyond s->file_end. */ | ||
89 | |||
90 | - prealloc_start = want_merge_zero ? MIN(offset, s->file_end) : s->file_end; | ||
91 | - prealloc_end = QEMU_ALIGN_UP(end + s->opts.prealloc_size, | ||
92 | - s->opts.prealloc_align); | ||
93 | + prealloc_start = QEMU_ALIGN_UP( | ||
94 | + want_merge_zero ? MIN(offset, s->file_end) : s->file_end, | ||
95 | + file_align); | ||
96 | + prealloc_end = QEMU_ALIGN_UP( | ||
97 | + MAX(prealloc_start, end) + s->opts.prealloc_size, | ||
98 | + prealloc_align); | ||
99 | + | ||
100 | + want_merge_zero = want_merge_zero && (prealloc_start <= offset); | ||
101 | |||
102 | ret = bdrv_co_pwrite_zeroes( | ||
103 | bs->file, prealloc_start, prealloc_end - prealloc_start, | ||
104 | -- | ||
105 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | iotest 040 already has some checks for the availability of the 'throttle' | ||
4 | driver, but some new code has been added in the course of time that | ||
5 | depends on 'throttle' but does not check for its availability. Add | ||
6 | a check to the TestCommitWithFilters class so that this iotest now | ||
7 | also passes again if 'throttle' has not been enabled in the QEMU | ||
8 | binaries. | ||
9 | |||
10 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
11 | Message-Id: <20220223123127.3206042-1-thuth@redhat.com> | ||
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/040 | 1 + | ||
15 | 1 file changed, 1 insertion(+) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/040 | ||
20 | +++ b/tests/qemu-iotests/040 | ||
21 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): | ||
22 | pattern_file) | ||
23 | self.assertFalse('Pattern verification failed' in result) | ||
24 | |||
25 | + @iotests.skip_if_unsupported(['throttle']) | ||
26 | def setUp(self): | ||
27 | qemu_img('create', '-f', iotests.imgfmt, self.img0, '64M') | ||
28 | qemu_img('create', '-f', iotests.imgfmt, self.img1, '64M') | ||
29 | -- | ||
30 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | In TAP mode, the stdout is reserved for the TAP protocol, so we | ||
4 | have to make sure to mark other lines with a comment '#' character | ||
5 | at the beginning to avoid that the TAP parser at the other end | ||
6 | gets confused. | ||
7 | |||
8 | To test this condition, run "configure" for example with: | ||
9 | |||
10 | --block-drv-rw-whitelist=copy-before-write,qcow2,raw,file,host_device,blkdebug,null-co,copy-on-read | ||
11 | |||
12 | so that iotest 041 will report that some tests are not run due to | ||
13 | the missing "quorum" driver. Without this change, "make check-block" | ||
14 | fails since the meson tap parser gets confused by these messages. | ||
15 | |||
16 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
17 | Message-Id: <20220223124353.3273898-1-thuth@redhat.com> | ||
18 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
19 | --- | ||
20 | tests/qemu-iotests/testrunner.py | 5 ++++- | ||
21 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
22 | |||
23 | diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/tests/qemu-iotests/testrunner.py | ||
26 | +++ b/tests/qemu-iotests/testrunner.py | ||
27 | @@ -XXX,XX +XXX,XX @@ def run_test(self, test: str, | ||
28 | description=res.description) | ||
29 | |||
30 | if res.casenotrun: | ||
31 | - print(res.casenotrun) | ||
32 | + if self.tap: | ||
33 | + print('#' + res.casenotrun.replace('\n', '\n#')) | ||
34 | + else: | ||
35 | + print(res.casenotrun) | ||
36 | |||
37 | return res | ||
38 | |||
39 | -- | ||
40 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Drop the use of OUTPUT_DIR (test/qemu-iotests under the build | ||
2 | directory), and instead write test output files (.out.bad, .notrun, and | ||
3 | .casenotrun) to TEST_DIR. | ||
4 | 1 | ||
5 | With this, the same test can be run concurrently without the separate | ||
6 | instances interfering, because they will need separate TEST_DIRs anyway. | ||
7 | Running the same test separately is useful when running the iotests with | ||
8 | various format/protocol combinations in parallel, or when you just want | ||
9 | to aggressively exercise a single test (e.g. when it fails only | ||
10 | sporadically). | ||
11 | |||
12 | Putting this output into TEST_DIR means that it will stick around for | ||
13 | inspection after the test run is done (though running the same test in | ||
14 | the same TEST_DIR will overwrite it, just as it used to be); but given | ||
15 | that TEST_DIR is a scratch directory, it should be clear that users can | ||
16 | delete all of its content at any point. (And if TEST_DIR is on tmpfs, | ||
17 | it will just disappear on shutdown.) Contrarily, alternative approaches | ||
18 | that would put these output files into OUTPUT_DIR with some prefix to | ||
19 | differentiate between separate test runs might easily lead to cluttering | ||
20 | OUTPUT_DIR. | ||
21 | |||
22 | (This change means OUTPUT_DIR is no longer written to by the iotests, so | ||
23 | we can drop its usage altogether.) | ||
24 | |||
25 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
26 | Message-Id: <20220221172909.762858-1-hreitz@redhat.com> | ||
27 | [hreitz: Simplified `Path(os.path.join(x, y))` to `Path(x, y)`, as | ||
28 | suggested by Vladimir; and rebased on 9086c7639822b6 | ||
29 | ("tests/qemu-iotests: Rework the checks and spots using GNU | ||
30 | sed")] | ||
31 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
32 | --- | ||
33 | tests/qemu-iotests/common.rc | 6 +++--- | ||
34 | tests/qemu-iotests/iotests.py | 5 ++--- | ||
35 | tests/qemu-iotests/testenv.py | 5 +---- | ||
36 | tests/qemu-iotests/testrunner.py | 14 ++++++++------ | ||
37 | 4 files changed, 14 insertions(+), 16 deletions(-) | ||
38 | |||
39 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/tests/qemu-iotests/common.rc | ||
42 | +++ b/tests/qemu-iotests/common.rc | ||
43 | @@ -XXX,XX +XXX,XX @@ | ||
44 | # bail out, setting up .notrun file | ||
45 | _notrun() | ||
46 | { | ||
47 | - echo "$*" >"$OUTPUT_DIR/$seq.notrun" | ||
48 | + echo "$*" >"$TEST_DIR/$seq.notrun" | ||
49 | echo "$seq not run: $*" | ||
50 | status=0 | ||
51 | exit | ||
52 | @@ -XXX,XX +XXX,XX @@ _img_info() | ||
53 | # | ||
54 | _casenotrun() | ||
55 | { | ||
56 | - echo " [case not run] $*" >>"$OUTPUT_DIR/$seq.casenotrun" | ||
57 | + echo " [case not run] $*" >>"$TEST_DIR/$seq.casenotrun" | ||
58 | } | ||
59 | |||
60 | # just plain bail out | ||
61 | # | ||
62 | _fail() | ||
63 | { | ||
64 | - echo "$*" | tee -a "$OUTPUT_DIR/$seq.full" | ||
65 | + echo "$*" | tee -a "$TEST_DIR/$seq.full" | ||
66 | echo "(see $seq.full for details)" | ||
67 | status=1 | ||
68 | exit 1 | ||
69 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/tests/qemu-iotests/iotests.py | ||
72 | +++ b/tests/qemu-iotests/iotests.py | ||
73 | @@ -XXX,XX +XXX,XX @@ | ||
74 | |||
75 | imgfmt = os.environ.get('IMGFMT', 'raw') | ||
76 | imgproto = os.environ.get('IMGPROTO', 'file') | ||
77 | -output_dir = os.environ.get('OUTPUT_DIR', '.') | ||
78 | |||
79 | try: | ||
80 | test_dir = os.environ['TEST_DIR'] | ||
81 | @@ -XXX,XX +XXX,XX @@ def notrun(reason): | ||
82 | # Each test in qemu-iotests has a number ("seq") | ||
83 | seq = os.path.basename(sys.argv[0]) | ||
84 | |||
85 | - with open('%s/%s.notrun' % (output_dir, seq), 'w', encoding='utf-8') \ | ||
86 | + with open('%s/%s.notrun' % (test_dir, seq), 'w', encoding='utf-8') \ | ||
87 | as outfile: | ||
88 | outfile.write(reason + '\n') | ||
89 | logger.warning("%s not run: %s", seq, reason) | ||
90 | @@ -XXX,XX +XXX,XX @@ def case_notrun(reason): | ||
91 | # Each test in qemu-iotests has a number ("seq") | ||
92 | seq = os.path.basename(sys.argv[0]) | ||
93 | |||
94 | - with open('%s/%s.casenotrun' % (output_dir, seq), 'a', encoding='utf-8') \ | ||
95 | + with open('%s/%s.casenotrun' % (test_dir, seq), 'a', encoding='utf-8') \ | ||
96 | as outfile: | ||
97 | outfile.write(' [case not run] ' + reason + '\n') | ||
98 | |||
99 | diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/tests/qemu-iotests/testenv.py | ||
102 | +++ b/tests/qemu-iotests/testenv.py | ||
103 | @@ -XXX,XX +XXX,XX @@ class TestEnv(ContextManager['TestEnv']): | ||
104 | # pylint: disable=too-many-instance-attributes | ||
105 | |||
106 | env_variables = ['PYTHONPATH', 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR', | ||
107 | - 'OUTPUT_DIR', 'PYTHON', 'QEMU_PROG', 'QEMU_IMG_PROG', | ||
108 | + 'PYTHON', 'QEMU_PROG', 'QEMU_IMG_PROG', | ||
109 | 'QEMU_IO_PROG', 'QEMU_NBD_PROG', 'QSD_PROG', | ||
110 | 'QEMU_OPTIONS', 'QEMU_IMG_OPTIONS', | ||
111 | 'QEMU_IO_OPTIONS', 'QEMU_IO_OPTIONS_NO_FMT', | ||
112 | @@ -XXX,XX +XXX,XX @@ def init_directories(self) -> None: | ||
113 | TEST_DIR | ||
114 | SOCK_DIR | ||
115 | SAMPLE_IMG_DIR | ||
116 | - OUTPUT_DIR | ||
117 | """ | ||
118 | |||
119 | # Path where qemu goodies live in this source tree. | ||
120 | @@ -XXX,XX +XXX,XX @@ def init_directories(self) -> None: | ||
121 | os.path.join(self.source_iotests, | ||
122 | 'sample_images')) | ||
123 | |||
124 | - self.output_dir = os.getcwd() # OUTPUT_DIR | ||
125 | - | ||
126 | def init_binaries(self) -> None: | ||
127 | """Init binary path variables: | ||
128 | PYTHON (for bash tests) | ||
129 | diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/tests/qemu-iotests/testrunner.py | ||
132 | +++ b/tests/qemu-iotests/testrunner.py | ||
133 | @@ -XXX,XX +XXX,XX @@ def do_run_test(self, test: str, mp: bool) -> TestResult: | ||
134 | """ | ||
135 | |||
136 | f_test = Path(test) | ||
137 | - f_bad = Path(f_test.name + '.out.bad') | ||
138 | - f_notrun = Path(f_test.name + '.notrun') | ||
139 | - f_casenotrun = Path(f_test.name + '.casenotrun') | ||
140 | f_reference = Path(self.find_reference(test)) | ||
141 | |||
142 | if not f_test.exists(): | ||
143 | @@ -XXX,XX +XXX,XX @@ def do_run_test(self, test: str, mp: bool) -> TestResult: | ||
144 | description='No qualified output ' | ||
145 | f'(expected {f_reference})') | ||
146 | |||
147 | - for p in (f_bad, f_notrun, f_casenotrun): | ||
148 | - silent_unlink(p) | ||
149 | - | ||
150 | args = [str(f_test.resolve())] | ||
151 | env = self.env.prepare_subprocess(args) | ||
152 | if mp: | ||
153 | @@ -XXX,XX +XXX,XX @@ def do_run_test(self, test: str, mp: bool) -> TestResult: | ||
154 | env[d] = os.path.join(env[d], f_test.name) | ||
155 | Path(env[d]).mkdir(parents=True, exist_ok=True) | ||
156 | |||
157 | + test_dir = env['TEST_DIR'] | ||
158 | + f_bad = Path(test_dir, f_test.name + '.out.bad') | ||
159 | + f_notrun = Path(test_dir, f_test.name + '.notrun') | ||
160 | + f_casenotrun = Path(test_dir, f_test.name + '.casenotrun') | ||
161 | + | ||
162 | + for p in (f_notrun, f_casenotrun): | ||
163 | + silent_unlink(p) | ||
164 | + | ||
165 | t0 = time.time() | ||
166 | with f_bad.open('w', encoding="utf-8") as f: | ||
167 | with subprocess.Popen(args, cwd=str(f_test.parent), env=env, | ||
168 | -- | ||
169 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | We are going to complicate bitmap initialization in the further | ||
4 | commit. And in future, backup job will be able to work without filter | ||
5 | (when source is immutable), so we'll need same bitmap initialization in | ||
6 | copy-before-write filter and in backup job. So, it's reasonable to do | ||
7 | it in block-copy. | ||
8 | |||
9 | Note that for now cbw_open() is the only caller of | ||
10 | block_copy_state_new(). | ||
11 | |||
12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
13 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
14 | Message-Id: <20220303194349.2304213-2-vsementsov@virtuozzo.com> | ||
15 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | --- | ||
17 | block/block-copy.c | 1 + | ||
18 | block/copy-before-write.c | 4 ---- | ||
19 | 2 files changed, 1 insertion(+), 4 deletions(-) | ||
20 | |||
21 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/block/block-copy.c | ||
24 | +++ b/block/block-copy.c | ||
25 | @@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, | ||
26 | return NULL; | ||
27 | } | ||
28 | bdrv_disable_dirty_bitmap(copy_bitmap); | ||
29 | + bdrv_set_dirty_bitmap(copy_bitmap, 0, bdrv_dirty_bitmap_size(copy_bitmap)); | ||
30 | |||
31 | /* | ||
32 | * If source is in backing chain of target assume that target is going to be | ||
33 | diff --git a/block/copy-before-write.c b/block/copy-before-write.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/block/copy-before-write.c | ||
36 | +++ b/block/copy-before-write.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
38 | Error **errp) | ||
39 | { | ||
40 | BDRVCopyBeforeWriteState *s = bs->opaque; | ||
41 | - BdrvDirtyBitmap *copy_bitmap; | ||
42 | |||
43 | bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
44 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
45 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
46 | return -EINVAL; | ||
47 | } | ||
48 | |||
49 | - copy_bitmap = block_copy_dirty_bitmap(s->bcs); | ||
50 | - bdrv_set_dirty_bitmap(copy_bitmap, 0, bdrv_dirty_bitmap_size(copy_bitmap)); | ||
51 | - | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | -- | ||
56 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | That simplifies handling failure in existing code and in further new | ||
4 | usage of bdrv_merge_dirty_bitmap(). | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220303194349.2304213-3-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/block/dirty-bitmap.h | 2 +- | ||
12 | block/dirty-bitmap.c | 9 +++++++-- | ||
13 | block/monitor/bitmap-qmp-cmds.c | 5 +---- | ||
14 | 3 files changed, 9 insertions(+), 7 deletions(-) | ||
15 | |||
16 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/block/dirty-bitmap.h | ||
19 | +++ b/include/block/dirty-bitmap.h | ||
20 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, | ||
21 | bool persistent); | ||
22 | void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap); | ||
23 | void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy); | ||
24 | -void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, | ||
25 | +bool bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, | ||
26 | HBitmap **backup, Error **errp); | ||
27 | void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip); | ||
28 | bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset); | ||
29 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/block/dirty-bitmap.c | ||
32 | +++ b/block/dirty-bitmap.c | ||
33 | @@ -XXX,XX +XXX,XX @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, | ||
34 | * Ensures permissions on bitmaps are reasonable; use for public API. | ||
35 | * | ||
36 | * @backup: If provided, make a copy of dest here prior to merge. | ||
37 | + * | ||
38 | + * Returns true on success, false on failure. In case of failure bitmaps are | ||
39 | + * untouched. | ||
40 | */ | ||
41 | -void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, | ||
42 | +bool bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, | ||
43 | HBitmap **backup, Error **errp) | ||
44 | { | ||
45 | - bool ret; | ||
46 | + bool ret = false; | ||
47 | |||
48 | bdrv_dirty_bitmaps_lock(dest->bs); | ||
49 | if (src->bs != dest->bs) { | ||
50 | @@ -XXX,XX +XXX,XX @@ out: | ||
51 | if (src->bs != dest->bs) { | ||
52 | bdrv_dirty_bitmaps_unlock(src->bs); | ||
53 | } | ||
54 | + | ||
55 | + return ret; | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | diff --git a/block/monitor/bitmap-qmp-cmds.c b/block/monitor/bitmap-qmp-cmds.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/block/monitor/bitmap-qmp-cmds.c | ||
62 | +++ b/block/monitor/bitmap-qmp-cmds.c | ||
63 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target, | ||
64 | BlockDriverState *bs; | ||
65 | BdrvDirtyBitmap *dst, *src, *anon; | ||
66 | BlockDirtyBitmapMergeSourceList *lst; | ||
67 | - Error *local_err = NULL; | ||
68 | |||
69 | GLOBAL_STATE_CODE(); | ||
70 | |||
71 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target, | ||
72 | abort(); | ||
73 | } | ||
74 | |||
75 | - bdrv_merge_dirty_bitmap(anon, src, NULL, &local_err); | ||
76 | - if (local_err) { | ||
77 | - error_propagate(errp, local_err); | ||
78 | + if (!bdrv_merge_dirty_bitmap(anon, src, NULL, errp)) { | ||
79 | dst = NULL; | ||
80 | goto out; | ||
81 | } | ||
82 | -- | ||
83 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | This will be used in the following commit to bring "incremental" mode | ||
4 | to copy-before-write filter. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220303194349.2304213-4-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/block/block-copy.h | 1 + | ||
12 | block/block-copy.c | 14 +++++++++++++- | ||
13 | block/copy-before-write.c | 2 +- | ||
14 | 3 files changed, 15 insertions(+), 2 deletions(-) | ||
15 | |||
16 | diff --git a/include/block/block-copy.h b/include/block/block-copy.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/block/block-copy.h | ||
19 | +++ b/include/block/block-copy.h | ||
20 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyState BlockCopyState; | ||
21 | typedef struct BlockCopyCallState BlockCopyCallState; | ||
22 | |||
23 | BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, | ||
24 | + const BdrvDirtyBitmap *bitmap, | ||
25 | Error **errp); | ||
26 | |||
27 | /* Function should be called prior any actual copy request */ | ||
28 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/block/block-copy.c | ||
31 | +++ b/block/block-copy.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int64_t block_copy_calculate_cluster_size(BlockDriverState *target, | ||
33 | } | ||
34 | |||
35 | BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, | ||
36 | + const BdrvDirtyBitmap *bitmap, | ||
37 | Error **errp) | ||
38 | { | ||
39 | + ERRP_GUARD(); | ||
40 | BlockCopyState *s; | ||
41 | int64_t cluster_size; | ||
42 | BdrvDirtyBitmap *copy_bitmap; | ||
43 | @@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, | ||
44 | return NULL; | ||
45 | } | ||
46 | bdrv_disable_dirty_bitmap(copy_bitmap); | ||
47 | - bdrv_set_dirty_bitmap(copy_bitmap, 0, bdrv_dirty_bitmap_size(copy_bitmap)); | ||
48 | + if (bitmap) { | ||
49 | + if (!bdrv_merge_dirty_bitmap(copy_bitmap, bitmap, NULL, errp)) { | ||
50 | + error_prepend(errp, "Failed to merge bitmap '%s' to internal " | ||
51 | + "copy-bitmap: ", bdrv_dirty_bitmap_name(bitmap)); | ||
52 | + bdrv_release_dirty_bitmap(copy_bitmap); | ||
53 | + return NULL; | ||
54 | + } | ||
55 | + } else { | ||
56 | + bdrv_set_dirty_bitmap(copy_bitmap, 0, | ||
57 | + bdrv_dirty_bitmap_size(copy_bitmap)); | ||
58 | + } | ||
59 | |||
60 | /* | ||
61 | * If source is in backing chain of target assume that target is going to be | ||
62 | diff --git a/block/copy-before-write.c b/block/copy-before-write.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/block/copy-before-write.c | ||
65 | +++ b/block/copy-before-write.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
67 | ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & | ||
68 | bs->file->bs->supported_zero_flags); | ||
69 | |||
70 | - s->bcs = block_copy_state_new(bs->file, s->target, errp); | ||
71 | + s->bcs = block_copy_state_new(bs->file, s->target, NULL, errp); | ||
72 | if (!s->bcs) { | ||
73 | error_prepend(errp, "Cannot create block-copy-state: "); | ||
74 | return -EINVAL; | ||
75 | -- | ||
76 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | This brings "incremental" mode to copy-before-write filter: user can | ||
4 | specify bitmap so that filter will copy only "dirty" areas. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Message-Id: <20220303194349.2304213-5-vsementsov@virtuozzo.com> | ||
8 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | --- | ||
10 | qapi/block-core.json | 10 +++++++- | ||
11 | block/copy-before-write.c | 51 ++++++++++++++++++++++++++++++++++++++- | ||
12 | 2 files changed, 59 insertions(+), 2 deletions(-) | ||
13 | |||
14 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/qapi/block-core.json | ||
17 | +++ b/qapi/block-core.json | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | # | ||
20 | # @target: The target for copy-before-write operations. | ||
21 | # | ||
22 | +# @bitmap: If specified, copy-before-write filter will do | ||
23 | +# copy-before-write operations only for dirty regions of the | ||
24 | +# bitmap. Bitmap size must be equal to length of file and | ||
25 | +# target child of the filter. Note also, that bitmap is used | ||
26 | +# only to initialize internal bitmap of the process, so further | ||
27 | +# modifications (or removing) of specified bitmap doesn't | ||
28 | +# influence the filter. (Since 7.0) | ||
29 | +# | ||
30 | # Since: 6.2 | ||
31 | ## | ||
32 | { 'struct': 'BlockdevOptionsCbw', | ||
33 | 'base': 'BlockdevOptionsGenericFormat', | ||
34 | - 'data': { 'target': 'BlockdevRef' } } | ||
35 | + 'data': { 'target': 'BlockdevRef', '*bitmap': 'BlockDirtyBitmap' } } | ||
36 | |||
37 | ## | ||
38 | # @BlockdevOptions: | ||
39 | diff --git a/block/copy-before-write.c b/block/copy-before-write.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/block/copy-before-write.c | ||
42 | +++ b/block/copy-before-write.c | ||
43 | @@ -XXX,XX +XXX,XX @@ | ||
44 | |||
45 | #include "block/copy-before-write.h" | ||
46 | |||
47 | +#include "qapi/qapi-visit-block-core.h" | ||
48 | + | ||
49 | typedef struct BDRVCopyBeforeWriteState { | ||
50 | BlockCopyState *bcs; | ||
51 | BdrvChild *target; | ||
52 | @@ -XXX,XX +XXX,XX @@ static void cbw_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
53 | } | ||
54 | } | ||
55 | |||
56 | +static bool cbw_parse_bitmap_option(QDict *options, BdrvDirtyBitmap **bitmap, | ||
57 | + Error **errp) | ||
58 | +{ | ||
59 | + QDict *bitmap_qdict = NULL; | ||
60 | + BlockDirtyBitmap *bmp_param = NULL; | ||
61 | + Visitor *v = NULL; | ||
62 | + bool ret = false; | ||
63 | + | ||
64 | + *bitmap = NULL; | ||
65 | + | ||
66 | + qdict_extract_subqdict(options, &bitmap_qdict, "bitmap."); | ||
67 | + if (!qdict_size(bitmap_qdict)) { | ||
68 | + ret = true; | ||
69 | + goto out; | ||
70 | + } | ||
71 | + | ||
72 | + v = qobject_input_visitor_new_flat_confused(bitmap_qdict, errp); | ||
73 | + if (!v) { | ||
74 | + goto out; | ||
75 | + } | ||
76 | + | ||
77 | + visit_type_BlockDirtyBitmap(v, NULL, &bmp_param, errp); | ||
78 | + if (!bmp_param) { | ||
79 | + goto out; | ||
80 | + } | ||
81 | + | ||
82 | + *bitmap = block_dirty_bitmap_lookup(bmp_param->node, bmp_param->name, NULL, | ||
83 | + errp); | ||
84 | + if (!*bitmap) { | ||
85 | + goto out; | ||
86 | + } | ||
87 | + | ||
88 | + ret = true; | ||
89 | + | ||
90 | +out: | ||
91 | + qapi_free_BlockDirtyBitmap(bmp_param); | ||
92 | + visit_free(v); | ||
93 | + qobject_unref(bitmap_qdict); | ||
94 | + | ||
95 | + return ret; | ||
96 | +} | ||
97 | + | ||
98 | static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
99 | Error **errp) | ||
100 | { | ||
101 | BDRVCopyBeforeWriteState *s = bs->opaque; | ||
102 | + BdrvDirtyBitmap *bitmap = NULL; | ||
103 | |||
104 | bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds, | ||
105 | BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, | ||
106 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
107 | return -EINVAL; | ||
108 | } | ||
109 | |||
110 | + if (!cbw_parse_bitmap_option(options, &bitmap, errp)) { | ||
111 | + return -EINVAL; | ||
112 | + } | ||
113 | + | ||
114 | bs->total_sectors = bs->file->bs->total_sectors; | ||
115 | bs->supported_write_flags = BDRV_REQ_WRITE_UNCHANGED | | ||
116 | (BDRV_REQ_FUA & bs->file->bs->supported_write_flags); | ||
117 | @@ -XXX,XX +XXX,XX @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags, | ||
118 | ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & | ||
119 | bs->file->bs->supported_zero_flags); | ||
120 | |||
121 | - s->bcs = block_copy_state_new(bs->file, s->target, NULL, errp); | ||
122 | + s->bcs = block_copy_state_new(bs->file, s->target, bitmap, errp); | ||
123 | if (!s->bcs) { | ||
124 | error_prepend(errp, "Cannot create block-copy-state: "); | ||
125 | return -EINVAL; | ||
126 | -- | ||
127 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Split block_copy_reset() out of block_copy_reset_unallocated() to be | ||
4 | used separately later. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220303194349.2304213-6-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/block/block-copy.h | 1 + | ||
12 | block/block-copy.c | 21 +++++++++++++-------- | ||
13 | 2 files changed, 14 insertions(+), 8 deletions(-) | ||
14 | |||
15 | diff --git a/include/block/block-copy.h b/include/block/block-copy.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/block/block-copy.h | ||
18 | +++ b/include/block/block-copy.h | ||
19 | @@ -XXX,XX +XXX,XX @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm); | ||
20 | |||
21 | void block_copy_state_free(BlockCopyState *s); | ||
22 | |||
23 | +void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); | ||
24 | int64_t block_copy_reset_unallocated(BlockCopyState *s, | ||
25 | int64_t offset, int64_t *count); | ||
26 | |||
27 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/block/block-copy.c | ||
30 | +++ b/block/block-copy.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, | ||
32 | } | ||
33 | } | ||
34 | |||
35 | +void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes) | ||
36 | +{ | ||
37 | + QEMU_LOCK_GUARD(&s->lock); | ||
38 | + | ||
39 | + bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); | ||
40 | + if (s->progress) { | ||
41 | + progress_set_remaining(s->progress, | ||
42 | + bdrv_get_dirty_count(s->copy_bitmap) + | ||
43 | + s->in_flight_bytes); | ||
44 | + } | ||
45 | +} | ||
46 | + | ||
47 | /* | ||
48 | * Reset bits in copy_bitmap starting at offset if they represent unallocated | ||
49 | * data in the image. May reset subsequent contiguous bits. | ||
50 | @@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s, | ||
51 | bytes = clusters * s->cluster_size; | ||
52 | |||
53 | if (!ret) { | ||
54 | - qemu_co_mutex_lock(&s->lock); | ||
55 | - bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes); | ||
56 | - if (s->progress) { | ||
57 | - progress_set_remaining(s->progress, | ||
58 | - bdrv_get_dirty_count(s->copy_bitmap) + | ||
59 | - s->in_flight_bytes); | ||
60 | - } | ||
61 | - qemu_co_mutex_unlock(&s->lock); | ||
62 | + block_copy_reset(s, offset, bytes); | ||
63 | } | ||
64 | |||
65 | *count = bytes; | ||
66 | -- | ||
67 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Add a convenient function similar with bdrv_block_status() to get | ||
4 | status of dirty bitmap. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220303194349.2304213-9-vsementsov@virtuozzo.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/block/dirty-bitmap.h | 2 ++ | ||
12 | include/qemu/hbitmap.h | 12 ++++++++++++ | ||
13 | block/dirty-bitmap.c | 6 ++++++ | ||
14 | util/hbitmap.c | 33 +++++++++++++++++++++++++++++++++ | ||
15 | 4 files changed, 53 insertions(+) | ||
16 | |||
17 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/block/dirty-bitmap.h | ||
20 | +++ b/include/block/dirty-bitmap.h | ||
21 | @@ -XXX,XX +XXX,XX @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset, | ||
22 | bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, | ||
23 | int64_t start, int64_t end, int64_t max_dirty_count, | ||
24 | int64_t *dirty_start, int64_t *dirty_count); | ||
25 | +bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset, | ||
26 | + int64_t bytes, int64_t *count); | ||
27 | BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
28 | Error **errp); | ||
29 | |||
30 | diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/qemu/hbitmap.h | ||
33 | +++ b/include/qemu/hbitmap.h | ||
34 | @@ -XXX,XX +XXX,XX @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end, | ||
35 | int64_t max_dirty_count, | ||
36 | int64_t *dirty_start, int64_t *dirty_count); | ||
37 | |||
38 | +/* | ||
39 | + * bdrv_dirty_bitmap_status: | ||
40 | + * @hb: The HBitmap to operate on | ||
41 | + * @start: The bit to start from | ||
42 | + * @count: Number of bits to proceed | ||
43 | + * @pnum: Out-parameter. How many bits has same value starting from @start | ||
44 | + * | ||
45 | + * Returns true if bitmap is dirty at @start, false otherwise. | ||
46 | + */ | ||
47 | +bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count, | ||
48 | + int64_t *pnum); | ||
49 | + | ||
50 | /** | ||
51 | * hbitmap_iter_next: | ||
52 | * @hbi: HBitmapIter to operate on. | ||
53 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/block/dirty-bitmap.c | ||
56 | +++ b/block/dirty-bitmap.c | ||
57 | @@ -XXX,XX +XXX,XX @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, | ||
58 | dirty_start, dirty_count); | ||
59 | } | ||
60 | |||
61 | +bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset, | ||
62 | + int64_t bytes, int64_t *count) | ||
63 | +{ | ||
64 | + return hbitmap_status(bitmap->bitmap, offset, bytes, count); | ||
65 | +} | ||
66 | + | ||
67 | /** | ||
68 | * bdrv_merge_dirty_bitmap: merge src into dest. | ||
69 | * Ensures permissions on bitmaps are reasonable; use for public API. | ||
70 | diff --git a/util/hbitmap.c b/util/hbitmap.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/util/hbitmap.c | ||
73 | +++ b/util/hbitmap.c | ||
74 | @@ -XXX,XX +XXX,XX @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end, | ||
75 | return true; | ||
76 | } | ||
77 | |||
78 | +bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count, | ||
79 | + int64_t *pnum) | ||
80 | +{ | ||
81 | + int64_t next_dirty, next_zero; | ||
82 | + | ||
83 | + assert(start >= 0); | ||
84 | + assert(count > 0); | ||
85 | + assert(start + count <= hb->orig_size); | ||
86 | + | ||
87 | + next_dirty = hbitmap_next_dirty(hb, start, count); | ||
88 | + if (next_dirty == -1) { | ||
89 | + *pnum = count; | ||
90 | + return false; | ||
91 | + } | ||
92 | + | ||
93 | + if (next_dirty > start) { | ||
94 | + *pnum = next_dirty - start; | ||
95 | + return false; | ||
96 | + } | ||
97 | + | ||
98 | + assert(next_dirty == start); | ||
99 | + | ||
100 | + next_zero = hbitmap_next_zero(hb, start, count); | ||
101 | + if (next_zero == -1) { | ||
102 | + *pnum = count; | ||
103 | + return true; | ||
104 | + } | ||
105 | + | ||
106 | + assert(next_zero > start); | ||
107 | + *pnum = next_zero - start; | ||
108 | + return false; | ||
109 | +} | ||
110 | + | ||
111 | bool hbitmap_empty(const HBitmap *hb) | ||
112 | { | ||
113 | return hb->count == 0; | ||
114 | -- | ||
115 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Add function to wait for all intersecting requests. | ||
4 | To be used in the further commit. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Reviewed-by: Nikita Lapshin <nikita.lapshin@virtuozzo.com> | ||
8 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | Message-Id: <20220303194349.2304213-10-vsementsov@virtuozzo.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | include/block/reqlist.h | 8 ++++++++ | ||
13 | block/reqlist.c | 8 ++++++++ | ||
14 | 2 files changed, 16 insertions(+) | ||
15 | |||
16 | diff --git a/include/block/reqlist.h b/include/block/reqlist.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/block/reqlist.h | ||
19 | +++ b/include/block/reqlist.h | ||
20 | @@ -XXX,XX +XXX,XX @@ BlockReq *reqlist_find_conflict(BlockReqList *reqs, int64_t offset, | ||
21 | bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset, | ||
22 | int64_t bytes, CoMutex *lock); | ||
23 | |||
24 | +/* | ||
25 | + * Wait for all intersecting requests. It just calls reqlist_wait_one() in a | ||
26 | + * loop, caller is responsible to stop producing new requests in this region | ||
27 | + * in parallel, otherwise reqlist_wait_all() may never return. | ||
28 | + */ | ||
29 | +void coroutine_fn reqlist_wait_all(BlockReqList *reqs, int64_t offset, | ||
30 | + int64_t bytes, CoMutex *lock); | ||
31 | + | ||
32 | /* | ||
33 | * Shrink request and wake all waiting coroutines (maybe some of them are not | ||
34 | * intersecting with shrunk request). | ||
35 | diff --git a/block/reqlist.c b/block/reqlist.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/block/reqlist.c | ||
38 | +++ b/block/reqlist.c | ||
39 | @@ -XXX,XX +XXX,XX @@ bool coroutine_fn reqlist_wait_one(BlockReqList *reqs, int64_t offset, | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | +void coroutine_fn reqlist_wait_all(BlockReqList *reqs, int64_t offset, | ||
44 | + int64_t bytes, CoMutex *lock) | ||
45 | +{ | ||
46 | + while (reqlist_wait_one(reqs, offset, bytes, lock)) { | ||
47 | + /* continue */ | ||
48 | + } | ||
49 | +} | ||
50 | + | ||
51 | void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes) | ||
52 | { | ||
53 | if (new_bytes == req->bytes) { | ||
54 | -- | ||
55 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Add new block driver handlers and corresponding generic wrappers. | ||
4 | It will be used to allow copy-before-write filter to provide | ||
5 | reach fleecing interface in further commit. | ||
6 | |||
7 | In future this approach may be used to allow reading qcow2 internal | ||
8 | snapshots, for example to export them through NBD. | ||
9 | |||
10 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
11 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | Message-Id: <20220303194349.2304213-11-vsementsov@virtuozzo.com> | ||
13 | [hreitz: Rebased on block GS/IO split] | ||
14 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
15 | --- | ||
16 | include/block/block_int-common.h | 18 ++++++++ | ||
17 | include/block/block_int-io.h | 9 ++++ | ||
18 | block/io.c | 72 ++++++++++++++++++++++++++++++++ | ||
19 | 3 files changed, 99 insertions(+) | ||
20 | |||
21 | diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/block/block_int-common.h | ||
24 | +++ b/include/block/block_int-common.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
26 | bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, | ||
27 | int64_t *map, BlockDriverState **file); | ||
28 | |||
29 | + /* | ||
30 | + * Snapshot-access API. | ||
31 | + * | ||
32 | + * Block-driver may provide snapshot-access API: special functions to access | ||
33 | + * some internal "snapshot". The functions are similar with normal | ||
34 | + * read/block_status/discard handler, but don't have any specific handling | ||
35 | + * in generic block-layer: no serializing, no alignment, no tracked | ||
36 | + * requests. So, block-driver that realizes these APIs is fully responsible | ||
37 | + * for synchronization between snapshot-access API and normal IO requests. | ||
38 | + */ | ||
39 | + int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs, | ||
40 | + int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); | ||
41 | + int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, | ||
42 | + bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, | ||
43 | + int64_t *map, BlockDriverState **file); | ||
44 | + int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs, | ||
45 | + int64_t offset, int64_t bytes); | ||
46 | + | ||
47 | /* | ||
48 | * Invalidate any cached meta-data. | ||
49 | */ | ||
50 | diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/include/block/block_int-io.h | ||
53 | +++ b/include/block/block_int-io.h | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | * the I/O API. | ||
56 | */ | ||
57 | |||
58 | +int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, | ||
59 | + int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); | ||
60 | +int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, | ||
61 | + bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, | ||
62 | + int64_t *map, BlockDriverState **file); | ||
63 | +int coroutine_fn bdrv_co_pdiscard_snapshot(BlockDriverState *bs, | ||
64 | + int64_t offset, int64_t bytes); | ||
65 | + | ||
66 | + | ||
67 | int coroutine_fn bdrv_co_preadv(BdrvChild *child, | ||
68 | int64_t offset, int64_t bytes, QEMUIOVector *qiov, | ||
69 | BdrvRequestFlags flags); | ||
70 | diff --git a/block/io.c b/block/io.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/block/io.c | ||
73 | +++ b/block/io.c | ||
74 | @@ -XXX,XX +XXX,XX @@ void bdrv_cancel_in_flight(BlockDriverState *bs) | ||
75 | bs->drv->bdrv_cancel_in_flight(bs); | ||
76 | } | ||
77 | } | ||
78 | + | ||
79 | +int coroutine_fn | ||
80 | +bdrv_co_preadv_snapshot(BdrvChild *child, int64_t offset, int64_t bytes, | ||
81 | + QEMUIOVector *qiov, size_t qiov_offset) | ||
82 | +{ | ||
83 | + BlockDriverState *bs = child->bs; | ||
84 | + BlockDriver *drv = bs->drv; | ||
85 | + int ret; | ||
86 | + IO_CODE(); | ||
87 | + | ||
88 | + if (!drv) { | ||
89 | + return -ENOMEDIUM; | ||
90 | + } | ||
91 | + | ||
92 | + if (!drv->bdrv_co_preadv_snapshot) { | ||
93 | + return -ENOTSUP; | ||
94 | + } | ||
95 | + | ||
96 | + bdrv_inc_in_flight(bs); | ||
97 | + ret = drv->bdrv_co_preadv_snapshot(bs, offset, bytes, qiov, qiov_offset); | ||
98 | + bdrv_dec_in_flight(bs); | ||
99 | + | ||
100 | + return ret; | ||
101 | +} | ||
102 | + | ||
103 | +int coroutine_fn | ||
104 | +bdrv_co_snapshot_block_status(BlockDriverState *bs, | ||
105 | + bool want_zero, int64_t offset, int64_t bytes, | ||
106 | + int64_t *pnum, int64_t *map, | ||
107 | + BlockDriverState **file) | ||
108 | +{ | ||
109 | + BlockDriver *drv = bs->drv; | ||
110 | + int ret; | ||
111 | + IO_CODE(); | ||
112 | + | ||
113 | + if (!drv) { | ||
114 | + return -ENOMEDIUM; | ||
115 | + } | ||
116 | + | ||
117 | + if (!drv->bdrv_co_snapshot_block_status) { | ||
118 | + return -ENOTSUP; | ||
119 | + } | ||
120 | + | ||
121 | + bdrv_inc_in_flight(bs); | ||
122 | + ret = drv->bdrv_co_snapshot_block_status(bs, want_zero, offset, bytes, | ||
123 | + pnum, map, file); | ||
124 | + bdrv_dec_in_flight(bs); | ||
125 | + | ||
126 | + return ret; | ||
127 | +} | ||
128 | + | ||
129 | +int coroutine_fn | ||
130 | +bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes) | ||
131 | +{ | ||
132 | + BlockDriver *drv = bs->drv; | ||
133 | + int ret; | ||
134 | + IO_CODE(); | ||
135 | + | ||
136 | + if (!drv) { | ||
137 | + return -ENOMEDIUM; | ||
138 | + } | ||
139 | + | ||
140 | + if (!drv->bdrv_co_pdiscard_snapshot) { | ||
141 | + return -ENOTSUP; | ||
142 | + } | ||
143 | + | ||
144 | + bdrv_inc_in_flight(bs); | ||
145 | + ret = drv->bdrv_co_pdiscard_snapshot(bs, offset, bytes); | ||
146 | + bdrv_dec_in_flight(bs); | ||
147 | + | ||
148 | + return ret; | ||
149 | +} | ||
150 | -- | ||
151 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
4 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
5 | Message-Id: <20220303194349.2304213-14-vsementsov@virtuozzo.com> | ||
6 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
7 | --- | ||
8 | tests/qemu-iotests/tests/image-fleecing | 64 +++++++++++++----- | ||
9 | tests/qemu-iotests/tests/image-fleecing.out | 74 ++++++++++++++++++++- | ||
10 | 2 files changed, 119 insertions(+), 19 deletions(-) | ||
11 | |||
12 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing | ||
13 | index XXXXXXX..XXXXXXX 100755 | ||
14 | --- a/tests/qemu-iotests/tests/image-fleecing | ||
15 | +++ b/tests/qemu-iotests/tests/image-fleecing | ||
16 | @@ -XXX,XX +XXX,XX @@ remainder = [('0xd5', '0x108000', '32k'), # Right-end of partial-left [1] | ||
17 | ('0xdc', '32M', '32k'), # Left-end of partial-right [2] | ||
18 | ('0xcd', '0x3ff0000', '64k')] # patterns[3] | ||
19 | |||
20 | -def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
21 | +def do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
22 | + fleece_img_path, nbd_sock_path, vm): | ||
23 | log('--- Setting up images ---') | ||
24 | log('') | ||
25 | |||
26 | assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0 | ||
27 | - assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 | ||
28 | + if use_snapshot_access_filter: | ||
29 | + assert use_cbw | ||
30 | + assert qemu_img('create', '-f', 'raw', fleece_img_path, '64M') == 0 | ||
31 | + else: | ||
32 | + assert qemu_img('create', '-f', 'qcow2', fleece_img_path, '64M') == 0 | ||
33 | |||
34 | for p in patterns: | ||
35 | qemu_io('-f', iotests.imgfmt, | ||
36 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
37 | log('') | ||
38 | |||
39 | |||
40 | - # create tmp_node backed by src_node | ||
41 | - log(vm.qmp('blockdev-add', { | ||
42 | - 'driver': 'qcow2', | ||
43 | - 'node-name': tmp_node, | ||
44 | - 'file': { | ||
45 | + if use_snapshot_access_filter: | ||
46 | + log(vm.qmp('blockdev-add', { | ||
47 | + 'node-name': tmp_node, | ||
48 | 'driver': 'file', | ||
49 | 'filename': fleece_img_path, | ||
50 | - }, | ||
51 | - 'backing': src_node, | ||
52 | - })) | ||
53 | + })) | ||
54 | + else: | ||
55 | + # create tmp_node backed by src_node | ||
56 | + log(vm.qmp('blockdev-add', { | ||
57 | + 'driver': 'qcow2', | ||
58 | + 'node-name': tmp_node, | ||
59 | + 'file': { | ||
60 | + 'driver': 'file', | ||
61 | + 'filename': fleece_img_path, | ||
62 | + }, | ||
63 | + 'backing': src_node, | ||
64 | + })) | ||
65 | |||
66 | # Establish CBW from source to fleecing node | ||
67 | if use_cbw: | ||
68 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
69 | })) | ||
70 | |||
71 | log(vm.qmp('qom-set', path=qom_path, property='drive', value='fl-cbw')) | ||
72 | + | ||
73 | + if use_snapshot_access_filter: | ||
74 | + log(vm.qmp('blockdev-add', { | ||
75 | + 'driver': 'snapshot-access', | ||
76 | + 'node-name': 'fl-access', | ||
77 | + 'file': 'fl-cbw', | ||
78 | + })) | ||
79 | else: | ||
80 | log(vm.qmp('blockdev-backup', | ||
81 | job_id='fleecing', | ||
82 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
83 | target=tmp_node, | ||
84 | sync='none')) | ||
85 | |||
86 | + export_node = 'fl-access' if use_snapshot_access_filter else tmp_node | ||
87 | + | ||
88 | log('') | ||
89 | log('--- Setting up NBD Export ---') | ||
90 | log('') | ||
91 | |||
92 | - nbd_uri = 'nbd+unix:///%s?socket=%s' % (tmp_node, nbd_sock_path) | ||
93 | + nbd_uri = 'nbd+unix:///%s?socket=%s' % (export_node, nbd_sock_path) | ||
94 | log(vm.qmp('nbd-server-start', | ||
95 | {'addr': {'type': 'unix', | ||
96 | 'data': {'path': nbd_sock_path}}})) | ||
97 | |||
98 | - log(vm.qmp('nbd-server-add', device=tmp_node)) | ||
99 | + log(vm.qmp('nbd-server-add', device=export_node)) | ||
100 | |||
101 | log('') | ||
102 | log('--- Sanity Check ---') | ||
103 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
104 | log('--- Cleanup ---') | ||
105 | log('') | ||
106 | |||
107 | + log(vm.qmp('nbd-server-stop')) | ||
108 | + | ||
109 | if use_cbw: | ||
110 | + if use_snapshot_access_filter: | ||
111 | + log(vm.qmp('blockdev-del', node_name='fl-access')) | ||
112 | log(vm.qmp('qom-set', path=qom_path, property='drive', value=src_node)) | ||
113 | log(vm.qmp('blockdev-del', node_name='fl-cbw')) | ||
114 | else: | ||
115 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
116 | assert e is not None | ||
117 | log(e, filters=[iotests.filter_qmp_event]) | ||
118 | |||
119 | - log(vm.qmp('nbd-server-stop')) | ||
120 | log(vm.qmp('blockdev-del', node_name=tmp_node)) | ||
121 | vm.shutdown() | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ def do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm): | ||
124 | log('Done') | ||
125 | |||
126 | |||
127 | -def test(use_cbw): | ||
128 | +def test(use_cbw, use_snapshot_access_filter): | ||
129 | with iotests.FilePath('base.img') as base_img_path, \ | ||
130 | iotests.FilePath('fleece.img') as fleece_img_path, \ | ||
131 | iotests.FilePath('nbd.sock', | ||
132 | base_dir=iotests.sock_dir) as nbd_sock_path, \ | ||
133 | iotests.VM() as vm: | ||
134 | - do_test(use_cbw, base_img_path, fleece_img_path, nbd_sock_path, vm) | ||
135 | + do_test(use_cbw, use_snapshot_access_filter, base_img_path, | ||
136 | + fleece_img_path, nbd_sock_path, vm) | ||
137 | |||
138 | |||
139 | log('=== Test backup(sync=none) based fleecing ===\n') | ||
140 | -test(False) | ||
141 | +test(False, False) | ||
142 | + | ||
143 | +log('=== Test cbw-filter based fleecing ===\n') | ||
144 | +test(True, False) | ||
145 | |||
146 | -log('=== Test filter based fleecing ===\n') | ||
147 | -test(True) | ||
148 | +log('=== Test fleecing-format based fleecing ===\n') | ||
149 | +test(True, True) | ||
150 | diff --git a/tests/qemu-iotests/tests/image-fleecing.out b/tests/qemu-iotests/tests/image-fleecing.out | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/tests/qemu-iotests/tests/image-fleecing.out | ||
153 | +++ b/tests/qemu-iotests/tests/image-fleecing.out | ||
154 | @@ -XXX,XX +XXX,XX @@ read -P0 0x3fe0000 64k | ||
155 | |||
156 | --- Cleanup --- | ||
157 | |||
158 | +{"return": {}} | ||
159 | {"return": {}} | ||
160 | {"data": {"device": "fleecing", "len": 67108864, "offset": 393216, "speed": 0, "type": "backup"}, "event": "BLOCK_JOB_CANCELLED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} | ||
161 | {"return": {}} | ||
162 | + | ||
163 | +--- Confirming writes --- | ||
164 | + | ||
165 | +read -P0xab 0 64k | ||
166 | +read -P0xad 0x00f8000 64k | ||
167 | +read -P0x1d 0x2008000 64k | ||
168 | +read -P0xea 0x3fe0000 64k | ||
169 | +read -P0xd5 0x108000 32k | ||
170 | +read -P0xdc 32M 32k | ||
171 | +read -P0xcd 0x3ff0000 64k | ||
172 | + | ||
173 | +Done | ||
174 | +=== Test cbw-filter based fleecing === | ||
175 | + | ||
176 | +--- Setting up images --- | ||
177 | + | ||
178 | +Done | ||
179 | + | ||
180 | +--- Launching VM --- | ||
181 | + | ||
182 | +Done | ||
183 | + | ||
184 | +--- Setting up Fleecing Graph --- | ||
185 | + | ||
186 | +{"return": {}} | ||
187 | +{"return": {}} | ||
188 | +{"return": {}} | ||
189 | + | ||
190 | +--- Setting up NBD Export --- | ||
191 | + | ||
192 | +{"return": {}} | ||
193 | +{"return": {}} | ||
194 | + | ||
195 | +--- Sanity Check --- | ||
196 | + | ||
197 | +read -P0x5d 0 64k | ||
198 | +read -P0xd5 1M 64k | ||
199 | +read -P0xdc 32M 64k | ||
200 | +read -P0xcd 0x3ff0000 64k | ||
201 | +read -P0 0x00f8000 32k | ||
202 | +read -P0 0x2010000 32k | ||
203 | +read -P0 0x3fe0000 64k | ||
204 | + | ||
205 | +--- Testing COW --- | ||
206 | + | ||
207 | +write -P0xab 0 64k | ||
208 | +{"return": ""} | ||
209 | +write -P0xad 0x00f8000 64k | ||
210 | +{"return": ""} | ||
211 | +write -P0x1d 0x2008000 64k | ||
212 | +{"return": ""} | ||
213 | +write -P0xea 0x3fe0000 64k | ||
214 | +{"return": ""} | ||
215 | + | ||
216 | +--- Verifying Data --- | ||
217 | + | ||
218 | +read -P0x5d 0 64k | ||
219 | +read -P0xd5 1M 64k | ||
220 | +read -P0xdc 32M 64k | ||
221 | +read -P0xcd 0x3ff0000 64k | ||
222 | +read -P0 0x00f8000 32k | ||
223 | +read -P0 0x2010000 32k | ||
224 | +read -P0 0x3fe0000 64k | ||
225 | + | ||
226 | +--- Cleanup --- | ||
227 | + | ||
228 | +{"return": {}} | ||
229 | +{"return": {}} | ||
230 | +{"return": {}} | ||
231 | {"return": {}} | ||
232 | |||
233 | --- Confirming writes --- | ||
234 | @@ -XXX,XX +XXX,XX @@ read -P0xdc 32M 32k | ||
235 | read -P0xcd 0x3ff0000 64k | ||
236 | |||
237 | Done | ||
238 | -=== Test filter based fleecing === | ||
239 | +=== Test fleecing-format based fleecing === | ||
240 | |||
241 | --- Setting up images --- | ||
242 | |||
243 | @@ -XXX,XX +XXX,XX @@ Done | ||
244 | {"return": {}} | ||
245 | {"return": {}} | ||
246 | {"return": {}} | ||
247 | +{"return": {}} | ||
248 | |||
249 | --- Setting up NBD Export --- | ||
250 | |||
251 | @@ -XXX,XX +XXX,XX @@ read -P0 0x3fe0000 64k | ||
252 | {"return": {}} | ||
253 | {"return": {}} | ||
254 | {"return": {}} | ||
255 | +{"return": {}} | ||
256 | |||
257 | --- Confirming writes --- | ||
258 | |||
259 | -- | ||
260 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Add helper that returns both status and output, to be used in the | ||
4 | following commit | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Message-Id: <20220303194349.2304213-15-vsementsov@virtuozzo.com> | ||
8 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/iotests.py | 3 +++ | ||
11 | 1 file changed, 3 insertions(+) | ||
12 | |||
13 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/tests/qemu-iotests/iotests.py | ||
16 | +++ b/tests/qemu-iotests/iotests.py | ||
17 | @@ -XXX,XX +XXX,XX @@ def qemu_io(*args): | ||
18 | '''Run qemu-io and return the stdout data''' | ||
19 | return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args))[0] | ||
20 | |||
21 | +def qemu_io_pipe_and_status(*args): | ||
22 | + return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args)) | ||
23 | + | ||
24 | def qemu_io_log(*args): | ||
25 | result = qemu_io(*args) | ||
26 | log(result, filters=[filter_testfiles, filter_qemu_io]) | ||
27 | -- | ||
28 | 2.34.1 | diff view generated by jsdifflib |