1 | The following changes since commit ca4e667dbf431d4a2a5a619cde79d30dd2ac3eb2: | 1 | The following changes since commit 23919ddfd56135cad3cb468a8f54d5a595f024f4: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/kraxel/tags/usb-20170717-pull-request' into staging (2017-07-17 17:54:17 +0100) | 3 | Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20190827' into staging (2019-08-27 15:52:36 +0100) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request | 7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-08-27 |
8 | 8 | ||
9 | for you to fetch changes up to 8508eee740c78d1465e25dad7c3e06137485dfbc: | 9 | for you to fetch changes up to bb043c056cffcc2f3ce88bfdaf2e76e455c09e2c: |
10 | 10 | ||
11 | live-block-ops.txt: Rename, rewrite, and improve it (2017-07-18 00:11:01 -0400) | 11 | iotests: Unify cache mode quoting (2019-08-27 19:48:44 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches (documentation) | 14 | Block patches: |
15 | - qemu-io now accepts a file to read a write pattern from | ||
16 | - Ensure that raw files have their first block allocated so we can probe | ||
17 | the O_DIRECT alignment if necessary | ||
18 | - Various fixes | ||
19 | |||
15 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
21 | Denis Plotnikov (1): | ||
22 | qemu-io: add pattern file for write command | ||
16 | 23 | ||
17 | Kashyap Chamarthy (2): | 24 | Max Reitz (7): |
18 | bitmaps.md: Convert to rST; move it into 'interop' dir | 25 | iotests: Fix _filter_img_create() |
19 | live-block-ops.txt: Rename, rewrite, and improve it | 26 | vmdk: Use bdrv_dirname() for relative extent paths |
27 | iotests: Keep testing broken relative extent paths | ||
28 | vmdk: Reject invalid compressed writes | ||
29 | iotests: Disable broken streamOptimized tests | ||
30 | iotests: Disable 110 for vmdk.twoGbMaxExtentSparse | ||
31 | iotests: Disable 126 for flat vmdk subformats | ||
20 | 32 | ||
21 | docs/devel/bitmaps.md | 505 --------------- | 33 | Nir Soffer (3): |
22 | docs/interop/bitmaps.rst | 555 ++++++++++++++++ | 34 | block: posix: Always allocate the first block |
23 | docs/interop/live-block-operations.rst | 1088 ++++++++++++++++++++++++++++++++ | 35 | iotests: Test allocate_first_block() with O_DIRECT |
24 | docs/live-block-ops.txt | 72 --- | 36 | iotests: Unify cache mode quoting |
25 | 4 files changed, 1643 insertions(+), 577 deletions(-) | 37 | |
26 | delete mode 100644 docs/devel/bitmaps.md | 38 | Stefan Hajnoczi (1): |
27 | create mode 100644 docs/interop/bitmaps.rst | 39 | file-posix: fix request_alignment typo |
28 | create mode 100644 docs/interop/live-block-operations.rst | 40 | |
29 | delete mode 100644 docs/live-block-ops.txt | 41 | Thomas Huth (2): |
42 | iotests: Check for enabled drivers before testing them | ||
43 | tests/check-block: Skip iotests when sanitizers are enabled | ||
44 | |||
45 | Vladimir Sementsov-Ogievskiy (1): | ||
46 | block: fix permission update in bdrv_replace_node | ||
47 | |||
48 | block.c | 5 +- | ||
49 | block/file-posix.c | 53 +++++++++- | ||
50 | block/vmdk.c | 64 ++++++++---- | ||
51 | qemu-io-cmds.c | 99 +++++++++++++++++-- | ||
52 | tests/check-block.sh | 5 + | ||
53 | tests/qemu-iotests/002 | 1 + | ||
54 | tests/qemu-iotests/003 | 1 + | ||
55 | tests/qemu-iotests/005 | 3 +- | ||
56 | tests/qemu-iotests/009 | 1 + | ||
57 | tests/qemu-iotests/010 | 1 + | ||
58 | tests/qemu-iotests/011 | 1 + | ||
59 | tests/qemu-iotests/017 | 3 +- | ||
60 | tests/qemu-iotests/018 | 3 +- | ||
61 | tests/qemu-iotests/019 | 3 +- | ||
62 | tests/qemu-iotests/020 | 3 +- | ||
63 | tests/qemu-iotests/026 | 4 +- | ||
64 | tests/qemu-iotests/027 | 1 + | ||
65 | tests/qemu-iotests/032 | 1 + | ||
66 | tests/qemu-iotests/033 | 1 + | ||
67 | tests/qemu-iotests/034 | 3 +- | ||
68 | tests/qemu-iotests/037 | 3 +- | ||
69 | tests/qemu-iotests/039 | 4 +- | ||
70 | tests/qemu-iotests/052 | 2 +- | ||
71 | tests/qemu-iotests/059 | 34 ++++++- | ||
72 | tests/qemu-iotests/059.out | 26 +++-- | ||
73 | tests/qemu-iotests/063 | 3 +- | ||
74 | tests/qemu-iotests/071 | 1 + | ||
75 | tests/qemu-iotests/072 | 1 + | ||
76 | tests/qemu-iotests/081 | 4 +- | ||
77 | tests/qemu-iotests/091 | 4 +- | ||
78 | tests/qemu-iotests/099 | 1 + | ||
79 | tests/qemu-iotests/105 | 3 +- | ||
80 | tests/qemu-iotests/110 | 3 +- | ||
81 | tests/qemu-iotests/120 | 1 + | ||
82 | tests/qemu-iotests/126 | 2 + | ||
83 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 | ||
84 | tests/qemu-iotests/150.out.raw | 12 +++ | ||
85 | tests/qemu-iotests/162 | 4 +- | ||
86 | tests/qemu-iotests/175 | 47 +++++++-- | ||
87 | tests/qemu-iotests/175.out | 16 ++- | ||
88 | tests/qemu-iotests/178.out.qcow2 | 4 +- | ||
89 | tests/qemu-iotests/184 | 1 + | ||
90 | tests/qemu-iotests/186 | 1 + | ||
91 | tests/qemu-iotests/197 | 1 + | ||
92 | tests/qemu-iotests/215 | 1 + | ||
93 | tests/qemu-iotests/221.out | 12 ++- | ||
94 | tests/qemu-iotests/251 | 1 + | ||
95 | tests/qemu-iotests/253.out | 12 ++- | ||
96 | tests/qemu-iotests/common.filter | 4 +- | ||
97 | tests/qemu-iotests/common.rc | 14 +++ | ||
98 | 50 files changed, 391 insertions(+), 87 deletions(-) | ||
99 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) | ||
100 | create mode 100644 tests/qemu-iotests/150.out.raw | ||
30 | 101 | ||
31 | -- | 102 | -- |
32 | 2.9.4 | 103 | 2.21.0 |
33 | 104 | ||
34 | 105 | diff view generated by jsdifflib |
1 | From: Kashyap Chamarthy <kchamart@redhat.com> | 1 | From: Denis Plotnikov <dplotnikov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | This is part of the on-going effort to convert QEMU upstream | 3 | The patch allows to provide a pattern file for write |
4 | documentation syntax to reStructuredText (rST). | 4 | command. There was no similar ability before. |
5 | 5 | ||
6 | The conversion to rST was done using: | 6 | Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com> |
7 | Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | [mreitz: Keep optstring in alphabetical order] | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++--- | ||
13 | 1 file changed, 93 insertions(+), 6 deletions(-) | ||
7 | 14 | ||
8 | $ pandoc -f markdown -t rst bitmaps.md -o bitmaps.rst | 15 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c |
9 | 16 | index XXXXXXX..XXXXXXX 100644 | |
10 | Then, make a couple of small syntactical adjustments. While at it, | 17 | --- a/qemu-io-cmds.c |
11 | reword a statement to avoid ambiguity. Addressing the feedback from | 18 | +++ b/qemu-io-cmds.c |
12 | this thread: | 19 | @@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p) |
13 | 20 | qemu_vfree(p); | |
14 | https://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg05428.html | 21 | } |
15 | 22 | ||
16 | Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com> | 23 | +/* |
17 | Reviewed-by: John Snow <jsnow@redhat.com> | 24 | + * qemu_io_alloc_from_file() |
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | 25 | + * |
19 | Message-id: 20170717105205.32639-2-kchamart@redhat.com | 26 | + * Allocates the buffer and populates it with the content of the given file |
20 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 27 | + * up to @len bytes. If the file length is less than @len, then the buffer |
21 | --- | 28 | + * is populated with the file content cyclically. |
22 | docs/devel/bitmaps.md | 505 ------------------------------------------ | 29 | + * |
23 | docs/interop/bitmaps.rst | 555 +++++++++++++++++++++++++++++++++++++++++++++++ | 30 | + * @blk - the block backend where the buffer content is going to be written to |
24 | 2 files changed, 555 insertions(+), 505 deletions(-) | 31 | + * @len - the buffer length |
25 | delete mode 100644 docs/devel/bitmaps.md | 32 | + * @file_name - the file to read the content from |
26 | create mode 100644 docs/interop/bitmaps.rst | 33 | + * |
27 | 34 | + * Returns: the buffer pointer on success | |
28 | diff --git a/docs/devel/bitmaps.md b/docs/devel/bitmaps.md | 35 | + * NULL on error |
29 | deleted file mode 100644 | 36 | + */ |
30 | index XXXXXXX..XXXXXXX | 37 | +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len, |
31 | --- a/docs/devel/bitmaps.md | 38 | + const char *file_name) |
32 | +++ /dev/null | 39 | +{ |
33 | @@ -XXX,XX +XXX,XX @@ | 40 | + char *buf, *buf_origin; |
34 | -<!-- | 41 | + FILE *f = fopen(file_name, "r"); |
35 | -Copyright 2015 John Snow <jsnow@redhat.com> and Red Hat, Inc. | 42 | + int pattern_len; |
36 | -All rights reserved. | ||
37 | - | ||
38 | -This file is licensed via The FreeBSD Documentation License, the full text of | ||
39 | -which is included at the end of this document. | ||
40 | ---> | ||
41 | - | ||
42 | -# Dirty Bitmaps and Incremental Backup | ||
43 | - | ||
44 | -* Dirty Bitmaps are objects that track which data needs to be backed up for the | ||
45 | - next incremental backup. | ||
46 | - | ||
47 | -* Dirty bitmaps can be created at any time and attached to any node | ||
48 | - (not just complete drives.) | ||
49 | - | ||
50 | -## Dirty Bitmap Names | ||
51 | - | ||
52 | -* A dirty bitmap's name is unique to the node, but bitmaps attached to different | ||
53 | - nodes can share the same name. | ||
54 | - | ||
55 | -* Dirty bitmaps created for internal use by QEMU may be anonymous and have no | ||
56 | - name, but any user-created bitmaps may not be. There can be any number of | ||
57 | - anonymous bitmaps per node. | ||
58 | - | ||
59 | -* The name of a user-created bitmap must not be empty (""). | ||
60 | - | ||
61 | -## Bitmap Modes | ||
62 | - | ||
63 | -* A Bitmap can be "frozen," which means that it is currently in-use by a backup | ||
64 | - operation and cannot be deleted, renamed, written to, reset, | ||
65 | - etc. | ||
66 | - | ||
67 | -* The normal operating mode for a bitmap is "active." | ||
68 | - | ||
69 | -## Basic QMP Usage | ||
70 | - | ||
71 | -### Supported Commands ### | ||
72 | - | ||
73 | -* block-dirty-bitmap-add | ||
74 | -* block-dirty-bitmap-remove | ||
75 | -* block-dirty-bitmap-clear | ||
76 | - | ||
77 | -### Creation | ||
78 | - | ||
79 | -* To create a new bitmap, enabled, on the drive with id=drive0: | ||
80 | - | ||
81 | -```json | ||
82 | -{ "execute": "block-dirty-bitmap-add", | ||
83 | - "arguments": { | ||
84 | - "node": "drive0", | ||
85 | - "name": "bitmap0" | ||
86 | - } | ||
87 | -} | ||
88 | -``` | ||
89 | - | ||
90 | -* This bitmap will have a default granularity that matches the cluster size of | ||
91 | - its associated drive, if available, clamped to between [4KiB, 64KiB]. | ||
92 | - The current default for qcow2 is 64KiB. | ||
93 | - | ||
94 | -* To create a new bitmap that tracks changes in 32KiB segments: | ||
95 | - | ||
96 | -```json | ||
97 | -{ "execute": "block-dirty-bitmap-add", | ||
98 | - "arguments": { | ||
99 | - "node": "drive0", | ||
100 | - "name": "bitmap0", | ||
101 | - "granularity": 32768 | ||
102 | - } | ||
103 | -} | ||
104 | -``` | ||
105 | - | ||
106 | -### Deletion | ||
107 | - | ||
108 | -* Bitmaps that are frozen cannot be deleted. | ||
109 | - | ||
110 | -* Deleting the bitmap does not impact any other bitmaps attached to the same | ||
111 | - node, nor does it affect any backups already created from this node. | ||
112 | - | ||
113 | -* Because bitmaps are only unique to the node to which they are attached, | ||
114 | - you must specify the node/drive name here, too. | ||
115 | - | ||
116 | -```json | ||
117 | -{ "execute": "block-dirty-bitmap-remove", | ||
118 | - "arguments": { | ||
119 | - "node": "drive0", | ||
120 | - "name": "bitmap0" | ||
121 | - } | ||
122 | -} | ||
123 | -``` | ||
124 | - | ||
125 | -### Resetting | ||
126 | - | ||
127 | -* Resetting a bitmap will clear all information it holds. | ||
128 | - | ||
129 | -* An incremental backup created from an empty bitmap will copy no data, | ||
130 | - as if nothing has changed. | ||
131 | - | ||
132 | -```json | ||
133 | -{ "execute": "block-dirty-bitmap-clear", | ||
134 | - "arguments": { | ||
135 | - "node": "drive0", | ||
136 | - "name": "bitmap0" | ||
137 | - } | ||
138 | -} | ||
139 | -``` | ||
140 | - | ||
141 | -## Transactions | ||
142 | - | ||
143 | -### Justification | ||
144 | - | ||
145 | -Bitmaps can be safely modified when the VM is paused or halted by using | ||
146 | -the basic QMP commands. For instance, you might perform the following actions: | ||
147 | - | ||
148 | -1. Boot the VM in a paused state. | ||
149 | -2. Create a full drive backup of drive0. | ||
150 | -3. Create a new bitmap attached to drive0. | ||
151 | -4. Resume execution of the VM. | ||
152 | -5. Incremental backups are ready to be created. | ||
153 | - | ||
154 | -At this point, the bitmap and drive backup would be correctly in sync, | ||
155 | -and incremental backups made from this point forward would be correctly aligned | ||
156 | -to the full drive backup. | ||
157 | - | ||
158 | -This is not particularly useful if we decide we want to start incremental | ||
159 | -backups after the VM has been running for a while, for which we will need to | ||
160 | -perform actions such as the following: | ||
161 | - | ||
162 | -1. Boot the VM and begin execution. | ||
163 | -2. Using a single transaction, perform the following operations: | ||
164 | - * Create bitmap0. | ||
165 | - * Create a full drive backup of drive0. | ||
166 | -3. Incremental backups are now ready to be created. | ||
167 | - | ||
168 | -### Supported Bitmap Transactions | ||
169 | - | ||
170 | -* block-dirty-bitmap-add | ||
171 | -* block-dirty-bitmap-clear | ||
172 | - | ||
173 | -The usages are identical to their respective QMP commands, but see below | ||
174 | -for examples. | ||
175 | - | ||
176 | -### Example: New Incremental Backup | ||
177 | - | ||
178 | -As outlined in the justification, perhaps we want to create a new incremental | ||
179 | -backup chain attached to a drive. | ||
180 | - | ||
181 | -```json | ||
182 | -{ "execute": "transaction", | ||
183 | - "arguments": { | ||
184 | - "actions": [ | ||
185 | - {"type": "block-dirty-bitmap-add", | ||
186 | - "data": {"node": "drive0", "name": "bitmap0"} }, | ||
187 | - {"type": "drive-backup", | ||
188 | - "data": {"device": "drive0", "target": "/path/to/full_backup.img", | ||
189 | - "sync": "full", "format": "qcow2"} } | ||
190 | - ] | ||
191 | - } | ||
192 | -} | ||
193 | -``` | ||
194 | - | ||
195 | -### Example: New Incremental Backup Anchor Point | ||
196 | - | ||
197 | -Maybe we just want to create a new full backup with an existing bitmap and | ||
198 | -want to reset the bitmap to track the new chain. | ||
199 | - | ||
200 | -```json | ||
201 | -{ "execute": "transaction", | ||
202 | - "arguments": { | ||
203 | - "actions": [ | ||
204 | - {"type": "block-dirty-bitmap-clear", | ||
205 | - "data": {"node": "drive0", "name": "bitmap0"} }, | ||
206 | - {"type": "drive-backup", | ||
207 | - "data": {"device": "drive0", "target": "/path/to/new_full_backup.img", | ||
208 | - "sync": "full", "format": "qcow2"} } | ||
209 | - ] | ||
210 | - } | ||
211 | -} | ||
212 | -``` | ||
213 | - | ||
214 | -## Incremental Backups | ||
215 | - | ||
216 | -The star of the show. | ||
217 | - | ||
218 | -**Nota Bene!** Only incremental backups of entire drives are supported for now. | ||
219 | -So despite the fact that you can attach a bitmap to any arbitrary node, they are | ||
220 | -only currently useful when attached to the root node. This is because | ||
221 | -drive-backup only supports drives/devices instead of arbitrary nodes. | ||
222 | - | ||
223 | -### Example: First Incremental Backup | ||
224 | - | ||
225 | -1. Create a full backup and sync it to the dirty bitmap, as in the transactional | ||
226 | -examples above; or with the VM offline, manually create a full copy and then | ||
227 | -create a new bitmap before the VM begins execution. | ||
228 | - | ||
229 | - * Let's assume the full backup is named 'full_backup.img'. | ||
230 | - * Let's assume the bitmap you created is 'bitmap0' attached to 'drive0'. | ||
231 | - | ||
232 | -2. Create a destination image for the incremental backup that utilizes the | ||
233 | -full backup as a backing image. | ||
234 | - | ||
235 | - * Let's assume it is named 'incremental.0.img'. | ||
236 | - | ||
237 | - ```sh | ||
238 | - # qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | ||
239 | - ``` | ||
240 | - | ||
241 | -3. Issue the incremental backup command: | ||
242 | - | ||
243 | - ```json | ||
244 | - { "execute": "drive-backup", | ||
245 | - "arguments": { | ||
246 | - "device": "drive0", | ||
247 | - "bitmap": "bitmap0", | ||
248 | - "target": "incremental.0.img", | ||
249 | - "format": "qcow2", | ||
250 | - "sync": "incremental", | ||
251 | - "mode": "existing" | ||
252 | - } | ||
253 | - } | ||
254 | - ``` | ||
255 | - | ||
256 | -### Example: Second Incremental Backup | ||
257 | - | ||
258 | -1. Create a new destination image for the incremental backup that points to the | ||
259 | - previous one, e.g.: 'incremental.1.img' | ||
260 | - | ||
261 | - ```sh | ||
262 | - # qemu-img create -f qcow2 incremental.1.img -b incremental.0.img -F qcow2 | ||
263 | - ``` | ||
264 | - | ||
265 | -2. Issue a new incremental backup command. The only difference here is that we | ||
266 | - have changed the target image below. | ||
267 | - | ||
268 | - ```json | ||
269 | - { "execute": "drive-backup", | ||
270 | - "arguments": { | ||
271 | - "device": "drive0", | ||
272 | - "bitmap": "bitmap0", | ||
273 | - "target": "incremental.1.img", | ||
274 | - "format": "qcow2", | ||
275 | - "sync": "incremental", | ||
276 | - "mode": "existing" | ||
277 | - } | ||
278 | - } | ||
279 | - ``` | ||
280 | - | ||
281 | -## Errors | ||
282 | - | ||
283 | -* In the event of an error that occurs after a backup job is successfully | ||
284 | - launched, either by a direct QMP command or a QMP transaction, the user | ||
285 | - will receive a BLOCK_JOB_COMPLETE event with a failure message, accompanied | ||
286 | - by a BLOCK_JOB_ERROR event. | ||
287 | - | ||
288 | -* In the case of an event being cancelled, the user will receive a | ||
289 | - BLOCK_JOB_CANCELLED event instead of a pair of COMPLETE and ERROR events. | ||
290 | - | ||
291 | -* In either case, the incremental backup data contained within the bitmap is | ||
292 | - safely rolled back, and the data within the bitmap is not lost. The image | ||
293 | - file created for the failed attempt can be safely deleted. | ||
294 | - | ||
295 | -* Once the underlying problem is fixed (e.g. more storage space is freed up), | ||
296 | - you can simply retry the incremental backup command with the same bitmap. | ||
297 | - | ||
298 | -### Example | ||
299 | - | ||
300 | -1. Create a target image: | ||
301 | - | ||
302 | - ```sh | ||
303 | - # qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | ||
304 | - ``` | ||
305 | - | ||
306 | -2. Attempt to create an incremental backup via QMP: | ||
307 | - | ||
308 | - ```json | ||
309 | - { "execute": "drive-backup", | ||
310 | - "arguments": { | ||
311 | - "device": "drive0", | ||
312 | - "bitmap": "bitmap0", | ||
313 | - "target": "incremental.0.img", | ||
314 | - "format": "qcow2", | ||
315 | - "sync": "incremental", | ||
316 | - "mode": "existing" | ||
317 | - } | ||
318 | - } | ||
319 | - ``` | ||
320 | - | ||
321 | -3. Receive an event notifying us of failure: | ||
322 | - | ||
323 | - ```json | ||
324 | - { "timestamp": { "seconds": 1424709442, "microseconds": 844524 }, | ||
325 | - "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
326 | - "error": "No space left on device", | ||
327 | - "device": "drive1", "type": "backup" }, | ||
328 | - "event": "BLOCK_JOB_COMPLETED" } | ||
329 | - ``` | ||
330 | - | ||
331 | -4. Delete the failed incremental, and re-create the image. | ||
332 | - | ||
333 | - ```sh | ||
334 | - # rm incremental.0.img | ||
335 | - # qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | ||
336 | - ``` | ||
337 | - | ||
338 | -5. Retry the command after fixing the underlying problem, | ||
339 | - such as freeing up space on the backup volume: | ||
340 | - | ||
341 | - ```json | ||
342 | - { "execute": "drive-backup", | ||
343 | - "arguments": { | ||
344 | - "device": "drive0", | ||
345 | - "bitmap": "bitmap0", | ||
346 | - "target": "incremental.0.img", | ||
347 | - "format": "qcow2", | ||
348 | - "sync": "incremental", | ||
349 | - "mode": "existing" | ||
350 | - } | ||
351 | - } | ||
352 | - ``` | ||
353 | - | ||
354 | -6. Receive confirmation that the job completed successfully: | ||
355 | - | ||
356 | - ```json | ||
357 | - { "timestamp": { "seconds": 1424709668, "microseconds": 526525 }, | ||
358 | - "data": { "device": "drive1", "type": "backup", | ||
359 | - "speed": 0, "len": 67108864, "offset": 67108864}, | ||
360 | - "event": "BLOCK_JOB_COMPLETED" } | ||
361 | - ``` | ||
362 | - | ||
363 | -### Partial Transactional Failures | ||
364 | - | ||
365 | -* Sometimes, a transaction will succeed in launching and return success, | ||
366 | - but then later the backup jobs themselves may fail. It is possible that | ||
367 | - a management application may have to deal with a partial backup failure | ||
368 | - after a successful transaction. | ||
369 | - | ||
370 | -* If multiple backup jobs are specified in a single transaction, when one of | ||
371 | - them fails, it will not interact with the other backup jobs in any way. | ||
372 | - | ||
373 | -* The job(s) that succeeded will clear the dirty bitmap associated with the | ||
374 | - operation, but the job(s) that failed will not. It is not "safe" to delete | ||
375 | - any incremental backups that were created successfully in this scenario, | ||
376 | - even though others failed. | ||
377 | - | ||
378 | -#### Example | ||
379 | - | ||
380 | -* QMP example highlighting two backup jobs: | ||
381 | - | ||
382 | - ```json | ||
383 | - { "execute": "transaction", | ||
384 | - "arguments": { | ||
385 | - "actions": [ | ||
386 | - { "type": "drive-backup", | ||
387 | - "data": { "device": "drive0", "bitmap": "bitmap0", | ||
388 | - "format": "qcow2", "mode": "existing", | ||
389 | - "sync": "incremental", "target": "d0-incr-1.qcow2" } }, | ||
390 | - { "type": "drive-backup", | ||
391 | - "data": { "device": "drive1", "bitmap": "bitmap1", | ||
392 | - "format": "qcow2", "mode": "existing", | ||
393 | - "sync": "incremental", "target": "d1-incr-1.qcow2" } }, | ||
394 | - ] | ||
395 | - } | ||
396 | - } | ||
397 | - ``` | ||
398 | - | ||
399 | -* QMP example response, highlighting one success and one failure: | ||
400 | - * Acknowledgement that the Transaction was accepted and jobs were launched: | ||
401 | - ```json | ||
402 | - { "return": {} } | ||
403 | - ``` | ||
404 | - | ||
405 | - * Later, QEMU sends notice that the first job was completed: | ||
406 | - ```json | ||
407 | - { "timestamp": { "seconds": 1447192343, "microseconds": 615698 }, | ||
408 | - "data": { "device": "drive0", "type": "backup", | ||
409 | - "speed": 0, "len": 67108864, "offset": 67108864 }, | ||
410 | - "event": "BLOCK_JOB_COMPLETED" | ||
411 | - } | ||
412 | - ``` | ||
413 | - | ||
414 | - * Later yet, QEMU sends notice that the second job has failed: | ||
415 | - ```json | ||
416 | - { "timestamp": { "seconds": 1447192399, "microseconds": 683015 }, | ||
417 | - "data": { "device": "drive1", "action": "report", | ||
418 | - "operation": "read" }, | ||
419 | - "event": "BLOCK_JOB_ERROR" } | ||
420 | - ``` | ||
421 | - | ||
422 | - ```json | ||
423 | - { "timestamp": { "seconds": 1447192399, "microseconds": 685853 }, | ||
424 | - "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
425 | - "error": "Input/output error", | ||
426 | - "device": "drive1", "type": "backup" }, | ||
427 | - "event": "BLOCK_JOB_COMPLETED" } | ||
428 | - | ||
429 | -* In the above example, "d0-incr-1.qcow2" is valid and must be kept, | ||
430 | - but "d1-incr-1.qcow2" is invalid and should be deleted. If a VM-wide | ||
431 | - incremental backup of all drives at a point-in-time is to be made, | ||
432 | - new backups for both drives will need to be made, taking into account | ||
433 | - that a new incremental backup for drive0 needs to be based on top of | ||
434 | - "d0-incr-1.qcow2." | ||
435 | - | ||
436 | -### Grouped Completion Mode | ||
437 | - | ||
438 | -* While jobs launched by transactions normally complete or fail on their own, | ||
439 | - it is possible to instruct them to complete or fail together as a group. | ||
440 | - | ||
441 | -* QMP transactions take an optional properties structure that can affect | ||
442 | - the semantics of the transaction. | ||
443 | - | ||
444 | -* The "completion-mode" transaction property can be either "individual" | ||
445 | - which is the default, legacy behavior described above, or "grouped," | ||
446 | - a new behavior detailed below. | ||
447 | - | ||
448 | -* Delayed Completion: In grouped completion mode, no jobs will report | ||
449 | - success until all jobs are ready to report success. | ||
450 | - | ||
451 | -* Grouped failure: If any job fails in grouped completion mode, all remaining | ||
452 | - jobs will be cancelled. Any incremental backups will restore their dirty | ||
453 | - bitmap objects as if no backup command was ever issued. | ||
454 | - | ||
455 | - * Regardless of if QEMU reports a particular incremental backup job as | ||
456 | - CANCELLED or as an ERROR, the in-memory bitmap will be restored. | ||
457 | - | ||
458 | -#### Example | ||
459 | - | ||
460 | -* Here's the same example scenario from above with the new property: | ||
461 | - | ||
462 | - ```json | ||
463 | - { "execute": "transaction", | ||
464 | - "arguments": { | ||
465 | - "actions": [ | ||
466 | - { "type": "drive-backup", | ||
467 | - "data": { "device": "drive0", "bitmap": "bitmap0", | ||
468 | - "format": "qcow2", "mode": "existing", | ||
469 | - "sync": "incremental", "target": "d0-incr-1.qcow2" } }, | ||
470 | - { "type": "drive-backup", | ||
471 | - "data": { "device": "drive1", "bitmap": "bitmap1", | ||
472 | - "format": "qcow2", "mode": "existing", | ||
473 | - "sync": "incremental", "target": "d1-incr-1.qcow2" } }, | ||
474 | - ], | ||
475 | - "properties": { | ||
476 | - "completion-mode": "grouped" | ||
477 | - } | ||
478 | - } | ||
479 | - } | ||
480 | - ``` | ||
481 | - | ||
482 | -* QMP example response, highlighting a failure for drive2: | ||
483 | - * Acknowledgement that the Transaction was accepted and jobs were launched: | ||
484 | - ```json | ||
485 | - { "return": {} } | ||
486 | - ``` | ||
487 | - | ||
488 | - * Later, QEMU sends notice that the second job has errored out, | ||
489 | - but that the first job was also cancelled: | ||
490 | - ```json | ||
491 | - { "timestamp": { "seconds": 1447193702, "microseconds": 632377 }, | ||
492 | - "data": { "device": "drive1", "action": "report", | ||
493 | - "operation": "read" }, | ||
494 | - "event": "BLOCK_JOB_ERROR" } | ||
495 | - ``` | ||
496 | - | ||
497 | - ```json | ||
498 | - { "timestamp": { "seconds": 1447193702, "microseconds": 640074 }, | ||
499 | - "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
500 | - "error": "Input/output error", | ||
501 | - "device": "drive1", "type": "backup" }, | ||
502 | - "event": "BLOCK_JOB_COMPLETED" } | ||
503 | - ``` | ||
504 | - | ||
505 | - ```json | ||
506 | - { "timestamp": { "seconds": 1447193702, "microseconds": 640163 }, | ||
507 | - "data": { "device": "drive0", "type": "backup", "speed": 0, | ||
508 | - "len": 67108864, "offset": 16777216 }, | ||
509 | - "event": "BLOCK_JOB_CANCELLED" } | ||
510 | - ``` | ||
511 | - | ||
512 | -<!-- | ||
513 | -The FreeBSD Documentation License | ||
514 | - | ||
515 | -Redistribution and use in source (Markdown) and 'compiled' forms (SGML, HTML, | ||
516 | -PDF, PostScript, RTF and so forth) with or without modification, are permitted | ||
517 | -provided that the following conditions are met: | ||
518 | - | ||
519 | -Redistributions of source code (Markdown) must retain the above copyright | ||
520 | -notice, this list of conditions and the following disclaimer of this file | ||
521 | -unmodified. | ||
522 | - | ||
523 | -Redistributions in compiled form (transformed to other DTDs, converted to PDF, | ||
524 | -PostScript, RTF and other formats) must reproduce the above copyright notice, | ||
525 | -this list of conditions and the following disclaimer in the documentation and/or | ||
526 | -other materials provided with the distribution. | ||
527 | - | ||
528 | -THIS DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
529 | -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
530 | -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
531 | -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
532 | -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
533 | -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
534 | -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
535 | -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
536 | -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
537 | -THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
538 | ---> | ||
539 | diff --git a/docs/interop/bitmaps.rst b/docs/interop/bitmaps.rst | ||
540 | new file mode 100644 | ||
541 | index XXXXXXX..XXXXXXX | ||
542 | --- /dev/null | ||
543 | +++ b/docs/interop/bitmaps.rst | ||
544 | @@ -XXX,XX +XXX,XX @@ | ||
545 | +.. | ||
546 | + Copyright 2015 John Snow <jsnow@redhat.com> and Red Hat, Inc. | ||
547 | + All rights reserved. | ||
548 | + | 43 | + |
549 | + This file is licensed via The FreeBSD Documentation License, the full | 44 | + if (!f) { |
550 | + text of which is included at the end of this document. | 45 | + perror(file_name); |
551 | + | 46 | + return NULL; |
552 | +==================================== | ||
553 | +Dirty Bitmaps and Incremental Backup | ||
554 | +==================================== | ||
555 | + | ||
556 | +- Dirty Bitmaps are objects that track which data needs to be backed up | ||
557 | + for the next incremental backup. | ||
558 | + | ||
559 | +- Dirty bitmaps can be created at any time and attached to any node | ||
560 | + (not just complete drives). | ||
561 | + | ||
562 | +.. contents:: | ||
563 | + | ||
564 | +Dirty Bitmap Names | ||
565 | +------------------ | ||
566 | + | ||
567 | +- A dirty bitmap's name is unique to the node, but bitmaps attached to | ||
568 | + different nodes can share the same name. | ||
569 | + | ||
570 | +- Dirty bitmaps created for internal use by QEMU may be anonymous and | ||
571 | + have no name, but any user-created bitmaps must have a name. There | ||
572 | + can be any number of anonymous bitmaps per node. | ||
573 | + | ||
574 | +- The name of a user-created bitmap must not be empty (""). | ||
575 | + | ||
576 | +Bitmap Modes | ||
577 | +------------ | ||
578 | + | ||
579 | +- A bitmap can be "frozen," which means that it is currently in-use by | ||
580 | + a backup operation and cannot be deleted, renamed, written to, reset, | ||
581 | + etc. | ||
582 | + | ||
583 | +- The normal operating mode for a bitmap is "active." | ||
584 | + | ||
585 | +Basic QMP Usage | ||
586 | +--------------- | ||
587 | + | ||
588 | +Supported Commands | ||
589 | +~~~~~~~~~~~~~~~~~~ | ||
590 | + | ||
591 | +- ``block-dirty-bitmap-add`` | ||
592 | +- ``block-dirty-bitmap-remove`` | ||
593 | +- ``block-dirty-bitmap-clear`` | ||
594 | + | ||
595 | +Creation | ||
596 | +~~~~~~~~ | ||
597 | + | ||
598 | +- To create a new bitmap, enabled, on the drive with id=drive0: | ||
599 | + | ||
600 | +.. code:: json | ||
601 | + | ||
602 | + { "execute": "block-dirty-bitmap-add", | ||
603 | + "arguments": { | ||
604 | + "node": "drive0", | ||
605 | + "name": "bitmap0" | ||
606 | + } | ||
607 | + } | 47 | + } |
608 | + | 48 | + |
609 | +- This bitmap will have a default granularity that matches the cluster | 49 | + if (qemuio_misalign) { |
610 | + size of its associated drive, if available, clamped to between [4KiB, | 50 | + len += MISALIGN_OFFSET; |
611 | + 64KiB]. The current default for qcow2 is 64KiB. | ||
612 | + | ||
613 | +- To create a new bitmap that tracks changes in 32KiB segments: | ||
614 | + | ||
615 | +.. code:: json | ||
616 | + | ||
617 | + { "execute": "block-dirty-bitmap-add", | ||
618 | + "arguments": { | ||
619 | + "node": "drive0", | ||
620 | + "name": "bitmap0", | ||
621 | + "granularity": 32768 | ||
622 | + } | ||
623 | + } | 51 | + } |
624 | + | 52 | + |
625 | +Deletion | 53 | + buf_origin = buf = blk_blockalign(blk, len); |
626 | +~~~~~~~~ | ||
627 | + | 54 | + |
628 | +- Bitmaps that are frozen cannot be deleted. | 55 | + if (qemuio_misalign) { |
629 | + | 56 | + buf_origin += MISALIGN_OFFSET; |
630 | +- Deleting the bitmap does not impact any other bitmaps attached to the | 57 | + buf += MISALIGN_OFFSET; |
631 | + same node, nor does it affect any backups already created from this | 58 | + len -= MISALIGN_OFFSET; |
632 | + node. | ||
633 | + | ||
634 | +- Because bitmaps are only unique to the node to which they are | ||
635 | + attached, you must specify the node/drive name here, too. | ||
636 | + | ||
637 | +.. code:: json | ||
638 | + | ||
639 | + { "execute": "block-dirty-bitmap-remove", | ||
640 | + "arguments": { | ||
641 | + "node": "drive0", | ||
642 | + "name": "bitmap0" | ||
643 | + } | ||
644 | + } | 59 | + } |
645 | + | 60 | + |
646 | +Resetting | 61 | + pattern_len = fread(buf_origin, 1, len, f); |
647 | +~~~~~~~~~ | ||
648 | + | 62 | + |
649 | +- Resetting a bitmap will clear all information it holds. | 63 | + if (ferror(f)) { |
650 | + | 64 | + perror(file_name); |
651 | +- An incremental backup created from an empty bitmap will copy no data, | 65 | + goto error; |
652 | + as if nothing has changed. | ||
653 | + | ||
654 | +.. code:: json | ||
655 | + | ||
656 | + { "execute": "block-dirty-bitmap-clear", | ||
657 | + "arguments": { | ||
658 | + "node": "drive0", | ||
659 | + "name": "bitmap0" | ||
660 | + } | ||
661 | + } | 66 | + } |
662 | + | 67 | + |
663 | +Transactions | 68 | + if (pattern_len == 0) { |
664 | +------------ | 69 | + fprintf(stderr, "%s: file is empty\n", file_name); |
665 | + | 70 | + goto error; |
666 | +Justification | ||
667 | +~~~~~~~~~~~~~ | ||
668 | + | ||
669 | +Bitmaps can be safely modified when the VM is paused or halted by using | ||
670 | +the basic QMP commands. For instance, you might perform the following | ||
671 | +actions: | ||
672 | + | ||
673 | +1. Boot the VM in a paused state. | ||
674 | +2. Create a full drive backup of drive0. | ||
675 | +3. Create a new bitmap attached to drive0. | ||
676 | +4. Resume execution of the VM. | ||
677 | +5. Incremental backups are ready to be created. | ||
678 | + | ||
679 | +At this point, the bitmap and drive backup would be correctly in sync, | ||
680 | +and incremental backups made from this point forward would be correctly | ||
681 | +aligned to the full drive backup. | ||
682 | + | ||
683 | +This is not particularly useful if we decide we want to start | ||
684 | +incremental backups after the VM has been running for a while, for which | ||
685 | +we will need to perform actions such as the following: | ||
686 | + | ||
687 | +1. Boot the VM and begin execution. | ||
688 | +2. Using a single transaction, perform the following operations: | ||
689 | + | ||
690 | + - Create ``bitmap0``. | ||
691 | + - Create a full drive backup of ``drive0``. | ||
692 | + | ||
693 | +3. Incremental backups are now ready to be created. | ||
694 | + | ||
695 | +Supported Bitmap Transactions | ||
696 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
697 | + | ||
698 | +- ``block-dirty-bitmap-add`` | ||
699 | +- ``block-dirty-bitmap-clear`` | ||
700 | + | ||
701 | +The usages are identical to their respective QMP commands, but see below | ||
702 | +for examples. | ||
703 | + | ||
704 | +Example: New Incremental Backup | ||
705 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
706 | + | ||
707 | +As outlined in the justification, perhaps we want to create a new | ||
708 | +incremental backup chain attached to a drive. | ||
709 | + | ||
710 | +.. code:: json | ||
711 | + | ||
712 | + { "execute": "transaction", | ||
713 | + "arguments": { | ||
714 | + "actions": [ | ||
715 | + {"type": "block-dirty-bitmap-add", | ||
716 | + "data": {"node": "drive0", "name": "bitmap0"} }, | ||
717 | + {"type": "drive-backup", | ||
718 | + "data": {"device": "drive0", "target": "/path/to/full_backup.img", | ||
719 | + "sync": "full", "format": "qcow2"} } | ||
720 | + ] | ||
721 | + } | ||
722 | + } | 71 | + } |
723 | + | 72 | + |
724 | +Example: New Incremental Backup Anchor Point | 73 | + fclose(f); |
725 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
726 | + | 74 | + |
727 | +Maybe we just want to create a new full backup with an existing bitmap | 75 | + if (len > pattern_len) { |
728 | +and want to reset the bitmap to track the new chain. | 76 | + len -= pattern_len; |
77 | + buf += pattern_len; | ||
729 | + | 78 | + |
730 | +.. code:: json | 79 | + while (len > 0) { |
80 | + size_t len_to_copy = MIN(pattern_len, len); | ||
731 | + | 81 | + |
732 | + { "execute": "transaction", | 82 | + memcpy(buf, buf_origin, len_to_copy); |
733 | + "arguments": { | 83 | + |
734 | + "actions": [ | 84 | + len -= len_to_copy; |
735 | + {"type": "block-dirty-bitmap-clear", | 85 | + buf += len_to_copy; |
736 | + "data": {"node": "drive0", "name": "bitmap0"} }, | 86 | + } |
737 | + {"type": "drive-backup", | ||
738 | + "data": {"device": "drive0", "target": "/path/to/new_full_backup.img", | ||
739 | + "sync": "full", "format": "qcow2"} } | ||
740 | + ] | ||
741 | + } | ||
742 | + } | 87 | + } |
743 | + | 88 | + |
744 | +Incremental Backups | 89 | + return buf_origin; |
745 | +------------------- | ||
746 | + | 90 | + |
747 | +The star of the show. | 91 | +error: |
92 | + qemu_io_free(buf_origin); | ||
93 | + return NULL; | ||
94 | +} | ||
748 | + | 95 | + |
749 | +**Nota Bene!** Only incremental backups of entire drives are supported | 96 | static void dump_buffer(const void *buffer, int64_t offset, int64_t len) |
750 | +for now. So despite the fact that you can attach a bitmap to any | 97 | { |
751 | +arbitrary node, they are only currently useful when attached to the root | 98 | uint64_t i; |
752 | +node. This is because drive-backup only supports drives/devices instead | 99 | @@ -XXX,XX +XXX,XX @@ static void write_help(void) |
753 | +of arbitrary nodes. | 100 | " -n, -- with -z, don't allow slow fallback\n" |
754 | + | 101 | " -p, -- ignored for backwards compatibility\n" |
755 | +Example: First Incremental Backup | 102 | " -P, -- use different pattern to fill file\n" |
756 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 103 | +" -s, -- use a pattern file to fill the write buffer\n" |
757 | + | 104 | " -C, -- report statistics in a machine parsable format\n" |
758 | +1. Create a full backup and sync it to the dirty bitmap, as in the | 105 | " -q, -- quiet mode, do not show I/O statistics\n" |
759 | + transactional examples above; or with the VM offline, manually create | 106 | " -u, -- with -z, allow unmapping\n" |
760 | + a full copy and then create a new bitmap before the VM begins | 107 | @@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = { |
761 | + execution. | 108 | .perm = BLK_PERM_WRITE, |
762 | + | 109 | .argmin = 2, |
763 | + - Let's assume the full backup is named ``full_backup.img``. | 110 | .argmax = -1, |
764 | + - Let's assume the bitmap you created is ``bitmap0`` attached to | 111 | - .args = "[-bcCfnquz] [-P pattern] off len", |
765 | + ``drive0``. | 112 | + .args = "[-bcCfnquz] [-P pattern | -s source_file] off len", |
766 | + | 113 | .oneline = "writes a number of bytes at a specified offset", |
767 | +2. Create a destination image for the incremental backup that utilizes | 114 | .help = write_help, |
768 | + the full backup as a backing image. | 115 | }; |
769 | + | 116 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
770 | + - Let's assume the new incremental image is named | 117 | { |
771 | + ``incremental.0.img``. | 118 | struct timespec t1, t2; |
772 | + | 119 | bool Cflag = false, qflag = false, bflag = false; |
773 | + .. code:: bash | 120 | - bool Pflag = false, zflag = false, cflag = false; |
774 | + | 121 | + bool Pflag = false, zflag = false, cflag = false, sflag = false; |
775 | + $ qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | 122 | int flags = 0; |
776 | + | 123 | int c, cnt, ret; |
777 | +3. Issue the incremental backup command: | 124 | char *buf = NULL; |
778 | + | 125 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
779 | + .. code:: json | 126 | /* Some compilers get confused and warn if this is not initialized. */ |
780 | + | 127 | int64_t total = 0; |
781 | + { "execute": "drive-backup", | 128 | int pattern = 0xcd; |
782 | + "arguments": { | 129 | + const char *file_name = NULL; |
783 | + "device": "drive0", | 130 | |
784 | + "bitmap": "bitmap0", | 131 | - while ((c = getopt(argc, argv, "bcCfnpP:quz")) != -1) { |
785 | + "target": "incremental.0.img", | 132 | + while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) { |
786 | + "format": "qcow2", | 133 | switch (c) { |
787 | + "sync": "incremental", | 134 | case 'b': |
788 | + "mode": "existing" | 135 | bflag = true; |
789 | + } | 136 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
790 | + } | 137 | case 'q': |
791 | + | 138 | qflag = true; |
792 | +Example: Second Incremental Backup | 139 | break; |
793 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 140 | + case 's': |
794 | + | 141 | + sflag = true; |
795 | +1. Create a new destination image for the incremental backup that points | 142 | + file_name = optarg; |
796 | + to the previous one, e.g.: ``incremental.1.img`` | 143 | + break; |
797 | + | 144 | case 'u': |
798 | + .. code:: bash | 145 | flags |= BDRV_REQ_MAY_UNMAP; |
799 | + | 146 | break; |
800 | + $ qemu-img create -f qcow2 incremental.1.img -b incremental.0.img -F qcow2 | 147 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
801 | + | 148 | return -EINVAL; |
802 | +2. Issue a new incremental backup command. The only difference here is | 149 | } |
803 | + that we have changed the target image below. | 150 | |
804 | + | 151 | - if (zflag && Pflag) { |
805 | + .. code:: json | 152 | - printf("-z and -P cannot be specified at the same time\n"); |
806 | + | 153 | + if (zflag + Pflag + sflag > 1) { |
807 | + { "execute": "drive-backup", | 154 | + printf("Only one of -z, -P, and -s " |
808 | + "arguments": { | 155 | + "can be specified at the same time\n"); |
809 | + "device": "drive0", | 156 | return -EINVAL; |
810 | + "bitmap": "bitmap0", | 157 | } |
811 | + "target": "incremental.1.img", | 158 | |
812 | + "format": "qcow2", | 159 | @@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv) |
813 | + "sync": "incremental", | 160 | } |
814 | + "mode": "existing" | 161 | |
815 | + } | 162 | if (!zflag) { |
816 | + } | 163 | - buf = qemu_io_alloc(blk, count, pattern); |
817 | + | 164 | + if (sflag) { |
818 | +Errors | 165 | + buf = qemu_io_alloc_from_file(blk, count, file_name); |
819 | +------ | 166 | + if (!buf) { |
820 | + | 167 | + return -EINVAL; |
821 | +- In the event of an error that occurs after a backup job is | 168 | + } |
822 | + successfully launched, either by a direct QMP command or a QMP | 169 | + } else { |
823 | + transaction, the user will receive a ``BLOCK_JOB_COMPLETE`` event with | 170 | + buf = qemu_io_alloc(blk, count, pattern); |
824 | + a failure message, accompanied by a ``BLOCK_JOB_ERROR`` event. | 171 | + } |
825 | + | 172 | } |
826 | +- In the case of an event being cancelled, the user will receive a | 173 | |
827 | + ``BLOCK_JOB_CANCELLED`` event instead of a pair of COMPLETE and ERROR | 174 | clock_gettime(CLOCK_MONOTONIC, &t1); |
828 | + events. | ||
829 | + | ||
830 | +- In either case, the incremental backup data contained within the | ||
831 | + bitmap is safely rolled back, and the data within the bitmap is not | ||
832 | + lost. The image file created for the failed attempt can be safely | ||
833 | + deleted. | ||
834 | + | ||
835 | +- Once the underlying problem is fixed (e.g. more storage space is | ||
836 | + freed up), you can simply retry the incremental backup command with | ||
837 | + the same bitmap. | ||
838 | + | ||
839 | +Example | ||
840 | +~~~~~~~ | ||
841 | + | ||
842 | +1. Create a target image: | ||
843 | + | ||
844 | + .. code:: bash | ||
845 | + | ||
846 | + $ qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | ||
847 | + | ||
848 | +2. Attempt to create an incremental backup via QMP: | ||
849 | + | ||
850 | + .. code:: json | ||
851 | + | ||
852 | + { "execute": "drive-backup", | ||
853 | + "arguments": { | ||
854 | + "device": "drive0", | ||
855 | + "bitmap": "bitmap0", | ||
856 | + "target": "incremental.0.img", | ||
857 | + "format": "qcow2", | ||
858 | + "sync": "incremental", | ||
859 | + "mode": "existing" | ||
860 | + } | ||
861 | + } | ||
862 | + | ||
863 | +3. Receive an event notifying us of failure: | ||
864 | + | ||
865 | + .. code:: json | ||
866 | + | ||
867 | + { "timestamp": { "seconds": 1424709442, "microseconds": 844524 }, | ||
868 | + "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
869 | + "error": "No space left on device", | ||
870 | + "device": "drive1", "type": "backup" }, | ||
871 | + "event": "BLOCK_JOB_COMPLETED" } | ||
872 | + | ||
873 | +4. Delete the failed incremental, and re-create the image. | ||
874 | + | ||
875 | + .. code:: bash | ||
876 | + | ||
877 | + $ rm incremental.0.img | ||
878 | + $ qemu-img create -f qcow2 incremental.0.img -b full_backup.img -F qcow2 | ||
879 | + | ||
880 | +5. Retry the command after fixing the underlying problem, such as | ||
881 | + freeing up space on the backup volume: | ||
882 | + | ||
883 | + .. code:: json | ||
884 | + | ||
885 | + { "execute": "drive-backup", | ||
886 | + "arguments": { | ||
887 | + "device": "drive0", | ||
888 | + "bitmap": "bitmap0", | ||
889 | + "target": "incremental.0.img", | ||
890 | + "format": "qcow2", | ||
891 | + "sync": "incremental", | ||
892 | + "mode": "existing" | ||
893 | + } | ||
894 | + } | ||
895 | + | ||
896 | +6. Receive confirmation that the job completed successfully: | ||
897 | + | ||
898 | + .. code:: json | ||
899 | + | ||
900 | + { "timestamp": { "seconds": 1424709668, "microseconds": 526525 }, | ||
901 | + "data": { "device": "drive1", "type": "backup", | ||
902 | + "speed": 0, "len": 67108864, "offset": 67108864}, | ||
903 | + "event": "BLOCK_JOB_COMPLETED" } | ||
904 | + | ||
905 | +Partial Transactional Failures | ||
906 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
907 | + | ||
908 | +- Sometimes, a transaction will succeed in launching and return | ||
909 | + success, but then later the backup jobs themselves may fail. It is | ||
910 | + possible that a management application may have to deal with a | ||
911 | + partial backup failure after a successful transaction. | ||
912 | + | ||
913 | +- If multiple backup jobs are specified in a single transaction, when | ||
914 | + one of them fails, it will not interact with the other backup jobs in | ||
915 | + any way. | ||
916 | + | ||
917 | +- The job(s) that succeeded will clear the dirty bitmap associated with | ||
918 | + the operation, but the job(s) that failed will not. It is not "safe" | ||
919 | + to delete any incremental backups that were created successfully in | ||
920 | + this scenario, even though others failed. | ||
921 | + | ||
922 | +Example | ||
923 | +^^^^^^^ | ||
924 | + | ||
925 | +- QMP example highlighting two backup jobs: | ||
926 | + | ||
927 | + .. code:: json | ||
928 | + | ||
929 | + { "execute": "transaction", | ||
930 | + "arguments": { | ||
931 | + "actions": [ | ||
932 | + { "type": "drive-backup", | ||
933 | + "data": { "device": "drive0", "bitmap": "bitmap0", | ||
934 | + "format": "qcow2", "mode": "existing", | ||
935 | + "sync": "incremental", "target": "d0-incr-1.qcow2" } }, | ||
936 | + { "type": "drive-backup", | ||
937 | + "data": { "device": "drive1", "bitmap": "bitmap1", | ||
938 | + "format": "qcow2", "mode": "existing", | ||
939 | + "sync": "incremental", "target": "d1-incr-1.qcow2" } }, | ||
940 | + ] | ||
941 | + } | ||
942 | + } | ||
943 | + | ||
944 | +- QMP example response, highlighting one success and one failure: | ||
945 | + | ||
946 | + - Acknowledgement that the Transaction was accepted and jobs were | ||
947 | + launched: | ||
948 | + | ||
949 | + .. code:: json | ||
950 | + | ||
951 | + { "return": {} } | ||
952 | + | ||
953 | + - Later, QEMU sends notice that the first job was completed: | ||
954 | + | ||
955 | + .. code:: json | ||
956 | + | ||
957 | + { "timestamp": { "seconds": 1447192343, "microseconds": 615698 }, | ||
958 | + "data": { "device": "drive0", "type": "backup", | ||
959 | + "speed": 0, "len": 67108864, "offset": 67108864 }, | ||
960 | + "event": "BLOCK_JOB_COMPLETED" | ||
961 | + } | ||
962 | + | ||
963 | + - Later yet, QEMU sends notice that the second job has failed: | ||
964 | + | ||
965 | + .. code:: json | ||
966 | + | ||
967 | + { "timestamp": { "seconds": 1447192399, "microseconds": 683015 }, | ||
968 | + "data": { "device": "drive1", "action": "report", | ||
969 | + "operation": "read" }, | ||
970 | + "event": "BLOCK_JOB_ERROR" } | ||
971 | + | ||
972 | + .. code:: json | ||
973 | + | ||
974 | + { "timestamp": { "seconds": 1447192399, "microseconds": | ||
975 | + 685853 }, "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
976 | + "error": "Input/output error", "device": "drive1", "type": | ||
977 | + "backup" }, "event": "BLOCK_JOB_COMPLETED" } | ||
978 | + | ||
979 | +- In the above example, ``d0-incr-1.qcow2`` is valid and must be kept, | ||
980 | + but ``d1-incr-1.qcow2`` is invalid and should be deleted. If a VM-wide | ||
981 | + incremental backup of all drives at a point-in-time is to be made, | ||
982 | + new backups for both drives will need to be made, taking into account | ||
983 | + that a new incremental backup for drive0 needs to be based on top of | ||
984 | + ``d0-incr-1.qcow2``. | ||
985 | + | ||
986 | +Grouped Completion Mode | ||
987 | +~~~~~~~~~~~~~~~~~~~~~~~ | ||
988 | + | ||
989 | +- While jobs launched by transactions normally complete or fail on | ||
990 | + their own, it is possible to instruct them to complete or fail | ||
991 | + together as a group. | ||
992 | + | ||
993 | +- QMP transactions take an optional properties structure that can | ||
994 | + affect the semantics of the transaction. | ||
995 | + | ||
996 | +- The "completion-mode" transaction property can be either "individual" | ||
997 | + which is the default, legacy behavior described above, or "grouped," | ||
998 | + a new behavior detailed below. | ||
999 | + | ||
1000 | +- Delayed Completion: In grouped completion mode, no jobs will report | ||
1001 | + success until all jobs are ready to report success. | ||
1002 | + | ||
1003 | +- Grouped failure: If any job fails in grouped completion mode, all | ||
1004 | + remaining jobs will be cancelled. Any incremental backups will | ||
1005 | + restore their dirty bitmap objects as if no backup command was ever | ||
1006 | + issued. | ||
1007 | + | ||
1008 | + - Regardless of if QEMU reports a particular incremental backup job | ||
1009 | + as CANCELLED or as an ERROR, the in-memory bitmap will be | ||
1010 | + restored. | ||
1011 | + | ||
1012 | +Example | ||
1013 | +^^^^^^^ | ||
1014 | + | ||
1015 | +- Here's the same example scenario from above with the new property: | ||
1016 | + | ||
1017 | + .. code:: json | ||
1018 | + | ||
1019 | + { "execute": "transaction", | ||
1020 | + "arguments": { | ||
1021 | + "actions": [ | ||
1022 | + { "type": "drive-backup", | ||
1023 | + "data": { "device": "drive0", "bitmap": "bitmap0", | ||
1024 | + "format": "qcow2", "mode": "existing", | ||
1025 | + "sync": "incremental", "target": "d0-incr-1.qcow2" } }, | ||
1026 | + { "type": "drive-backup", | ||
1027 | + "data": { "device": "drive1", "bitmap": "bitmap1", | ||
1028 | + "format": "qcow2", "mode": "existing", | ||
1029 | + "sync": "incremental", "target": "d1-incr-1.qcow2" } }, | ||
1030 | + ], | ||
1031 | + "properties": { | ||
1032 | + "completion-mode": "grouped" | ||
1033 | + } | ||
1034 | + } | ||
1035 | + } | ||
1036 | + | ||
1037 | +- QMP example response, highlighting a failure for ``drive2``: | ||
1038 | + | ||
1039 | + - Acknowledgement that the Transaction was accepted and jobs were | ||
1040 | + launched: | ||
1041 | + | ||
1042 | + .. code:: json | ||
1043 | + | ||
1044 | + { "return": {} } | ||
1045 | + | ||
1046 | + - Later, QEMU sends notice that the second job has errored out, but | ||
1047 | + that the first job was also cancelled: | ||
1048 | + | ||
1049 | + .. code:: json | ||
1050 | + | ||
1051 | + { "timestamp": { "seconds": 1447193702, "microseconds": 632377 }, | ||
1052 | + "data": { "device": "drive1", "action": "report", | ||
1053 | + "operation": "read" }, | ||
1054 | + "event": "BLOCK_JOB_ERROR" } | ||
1055 | + | ||
1056 | + .. code:: json | ||
1057 | + | ||
1058 | + { "timestamp": { "seconds": 1447193702, "microseconds": 640074 }, | ||
1059 | + "data": { "speed": 0, "offset": 0, "len": 67108864, | ||
1060 | + "error": "Input/output error", | ||
1061 | + "device": "drive1", "type": "backup" }, | ||
1062 | + "event": "BLOCK_JOB_COMPLETED" } | ||
1063 | + | ||
1064 | + .. code:: json | ||
1065 | + | ||
1066 | + { "timestamp": { "seconds": 1447193702, "microseconds": 640163 }, | ||
1067 | + "data": { "device": "drive0", "type": "backup", "speed": 0, | ||
1068 | + "len": 67108864, "offset": 16777216 }, | ||
1069 | + "event": "BLOCK_JOB_CANCELLED" } | ||
1070 | + | ||
1071 | +.. raw:: html | ||
1072 | + | ||
1073 | + <!-- | ||
1074 | + The FreeBSD Documentation License | ||
1075 | + | ||
1076 | + Redistribution and use in source (Markdown) and 'compiled' forms (SGML, HTML, | ||
1077 | + PDF, PostScript, RTF and so forth) with or without modification, are permitted | ||
1078 | + provided that the following conditions are met: | ||
1079 | + | ||
1080 | + Redistributions of source code (Markdown) must retain the above copyright | ||
1081 | + notice, this list of conditions and the following disclaimer of this file | ||
1082 | + unmodified. | ||
1083 | + | ||
1084 | + Redistributions in compiled form (transformed to other DTDs, converted to PDF, | ||
1085 | + PostScript, RTF and other formats) must reproduce the above copyright notice, | ||
1086 | + this list of conditions and the following disclaimer in the documentation and/or | ||
1087 | + other materials provided with the distribution. | ||
1088 | + | ||
1089 | + THIS DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
1090 | + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
1091 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
1092 | + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
1093 | + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
1094 | + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
1095 | + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
1096 | + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
1097 | + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
1098 | + THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
1099 | + --> | ||
1100 | -- | 175 | -- |
1101 | 2.9.4 | 176 | 2.21.0 |
1102 | 177 | ||
1103 | 178 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
1 | 2 | ||
3 | It's wrong to OR shared permissions. It may lead to crash on further | ||
4 | permission updates. | ||
5 | Also, no needs to consider previously calculated permissions, as at | ||
6 | this point we already bind all new parents and bdrv_get_cumulative_perm | ||
7 | result is enough. So fix the bug by just set permissions by | ||
8 | bdrv_get_cumulative_perm result. | ||
9 | |||
10 | Bug was introduced in long ago 234ac1a9025, in 2.9. | ||
11 | |||
12 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
13 | Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | block.c | 5 ++--- | ||
17 | 1 file changed, 2 insertions(+), 3 deletions(-) | ||
18 | |||
19 | diff --git a/block.c b/block.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/block.c | ||
22 | +++ b/block.c | ||
23 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
24 | { | ||
25 | BdrvChild *c, *next; | ||
26 | GSList *list = NULL, *p; | ||
27 | - uint64_t old_perm, old_shared; | ||
28 | uint64_t perm = 0, shared = BLK_PERM_ALL; | ||
29 | int ret; | ||
30 | |||
31 | @@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, | ||
32 | bdrv_unref(from); | ||
33 | } | ||
34 | |||
35 | - bdrv_get_cumulative_perm(to, &old_perm, &old_shared); | ||
36 | - bdrv_set_perm(to, old_perm | perm, old_shared | shared); | ||
37 | + bdrv_get_cumulative_perm(to, &perm, &shared); | ||
38 | + bdrv_set_perm(to, perm, shared); | ||
39 | |||
40 | out: | ||
41 | g_slist_free(list); | ||
42 | -- | ||
43 | 2.21.0 | ||
44 | |||
45 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Nir Soffer <nirsof@gmail.com> | |
2 | |||
3 | When creating an image with preallocation "off" or "falloc", the first | ||
4 | block of the image is typically not allocated. When using Gluster | ||
5 | storage backed by XFS filesystem, reading this block using direct I/O | ||
6 | succeeds regardless of request length, fooling alignment detection. | ||
7 | |||
8 | In this case we fallback to a safe value (4096) instead of the optimal | ||
9 | value (512), which may lead to unneeded data copying when aligning | ||
10 | requests. Allocating the first block avoids the fallback. | ||
11 | |||
12 | Since we allocate the first block even with preallocation=off, we no | ||
13 | longer create images with zero disk size: | ||
14 | |||
15 | $ ./qemu-img create -f raw test.raw 1g | ||
16 | Formatting 'test.raw', fmt=raw size=1073741824 | ||
17 | |||
18 | $ ls -lhs test.raw | ||
19 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw | ||
20 | |||
21 | And converting the image requires additional cluster: | ||
22 | |||
23 | $ ./qemu-img measure -f raw -O qcow2 test.raw | ||
24 | required size: 458752 | ||
25 | fully allocated size: 1074135040 | ||
26 | |||
27 | When using format like vmdk with multiple files per image, we allocate | ||
28 | one block per file: | ||
29 | |||
30 | $ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g | ||
31 | Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat | ||
32 | |||
33 | $ ls -lhs test*.vmdk | ||
34 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk | ||
35 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk | ||
36 | 4.0K -rw-r--r--. 1 nsoffer nsoffer 353 Aug 27 03:23 test.vmdk | ||
37 | |||
38 | I did quick performance test for copying disks with qemu-img convert to | ||
39 | new raw target image to Gluster storage with sector size of 512 bytes: | ||
40 | |||
41 | for i in $(seq 10); do | ||
42 | rm -f dst.raw | ||
43 | sleep 10 | ||
44 | time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw | ||
45 | done | ||
46 | |||
47 | Here is a table comparing the total time spent: | ||
48 | |||
49 | Type Before(s) After(s) Diff(%) | ||
50 | --------------------------------------- | ||
51 | real 530.028 469.123 -11.4 | ||
52 | user 17.204 10.768 -37.4 | ||
53 | sys 17.881 7.011 -60.7 | ||
54 | |||
55 | We can see very clear improvement in CPU usage. | ||
56 | |||
57 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
58 | Message-id: 20190827010528.8818-2-nsoffer@redhat.com | ||
59 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
60 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
61 | --- | ||
62 | block/file-posix.c | 51 +++++++++++++++++++ | ||
63 | tests/qemu-iotests/059.out | 2 +- | ||
64 | tests/qemu-iotests/{150.out => 150.out.qcow2} | 0 | ||
65 | tests/qemu-iotests/150.out.raw | 12 +++++ | ||
66 | tests/qemu-iotests/175 | 19 ++++--- | ||
67 | tests/qemu-iotests/175.out | 8 +-- | ||
68 | tests/qemu-iotests/178.out.qcow2 | 4 +- | ||
69 | tests/qemu-iotests/221.out | 12 +++-- | ||
70 | tests/qemu-iotests/253.out | 12 +++-- | ||
71 | 9 files changed, 99 insertions(+), 21 deletions(-) | ||
72 | rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%) | ||
73 | create mode 100644 tests/qemu-iotests/150.out.raw | ||
74 | |||
75 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/block/file-posix.c | ||
78 | +++ b/block/file-posix.c | ||
79 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque) | ||
80 | return ret; | ||
81 | } | ||
82 | |||
83 | +/* | ||
84 | + * Help alignment probing by allocating the first block. | ||
85 | + * | ||
86 | + * When reading with direct I/O from unallocated area on Gluster backed by XFS, | ||
87 | + * reading succeeds regardless of request length. In this case we fallback to | ||
88 | + * safe alignment which is not optimal. Allocating the first block avoids this | ||
89 | + * fallback. | ||
90 | + * | ||
91 | + * fd may be opened with O_DIRECT, but we don't know the buffer alignment or | ||
92 | + * request alignment, so we use safe values. | ||
93 | + * | ||
94 | + * Returns: 0 on success, -errno on failure. Since this is an optimization, | ||
95 | + * caller may ignore failures. | ||
96 | + */ | ||
97 | +static int allocate_first_block(int fd, size_t max_size) | ||
98 | +{ | ||
99 | + size_t write_size = (max_size < MAX_BLOCKSIZE) | ||
100 | + ? BDRV_SECTOR_SIZE | ||
101 | + : MAX_BLOCKSIZE; | ||
102 | + size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize()); | ||
103 | + void *buf; | ||
104 | + ssize_t n; | ||
105 | + int ret; | ||
106 | + | ||
107 | + buf = qemu_memalign(max_align, write_size); | ||
108 | + memset(buf, 0, write_size); | ||
109 | + | ||
110 | + do { | ||
111 | + n = pwrite(fd, buf, write_size, 0); | ||
112 | + } while (n == -1 && errno == EINTR); | ||
113 | + | ||
114 | + ret = (n == -1) ? -errno : 0; | ||
115 | + | ||
116 | + qemu_vfree(buf); | ||
117 | + return ret; | ||
118 | +} | ||
119 | + | ||
120 | static int handle_aiocb_truncate(void *opaque) | ||
121 | { | ||
122 | RawPosixAIOData *aiocb = opaque; | ||
123 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
124 | /* posix_fallocate() doesn't set errno. */ | ||
125 | error_setg_errno(errp, -result, | ||
126 | "Could not preallocate new data"); | ||
127 | + } else if (current_length == 0) { | ||
128 | + /* | ||
129 | + * posix_fallocate() uses fallocate() if the filesystem | ||
130 | + * supports it, or fallback to manually writing zeroes. If | ||
131 | + * fallocate() was used, unaligned reads from the fallocated | ||
132 | + * area in raw_probe_alignment() will succeed, hence we need to | ||
133 | + * allocate the first block. | ||
134 | + * | ||
135 | + * Optimize future alignment probing; ignore failures. | ||
136 | + */ | ||
137 | + allocate_first_block(fd, offset); | ||
138 | } | ||
139 | } else { | ||
140 | result = 0; | ||
141 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque) | ||
142 | if (ftruncate(fd, offset) != 0) { | ||
143 | result = -errno; | ||
144 | error_setg_errno(errp, -result, "Could not resize file"); | ||
145 | + } else if (current_length == 0 && offset > current_length) { | ||
146 | + /* Optimize future alignment probing; ignore failures. */ | ||
147 | + allocate_first_block(fd, offset); | ||
148 | } | ||
149 | return result; | ||
150 | default: | ||
151 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/tests/qemu-iotests/059.out | ||
154 | +++ b/tests/qemu-iotests/059.out | ||
155 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax | ||
156 | image: TEST_DIR/t.vmdk | ||
157 | file format: vmdk | ||
158 | virtual size: 0.977 TiB (1073741824000 bytes) | ||
159 | -disk size: 16 KiB | ||
160 | +disk size: 1.97 MiB | ||
161 | Format specific information: | ||
162 | cid: XXXXXXXX | ||
163 | parent cid: XXXXXXXX | ||
164 | diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2 | ||
165 | similarity index 100% | ||
166 | rename from tests/qemu-iotests/150.out | ||
167 | rename to tests/qemu-iotests/150.out.qcow2 | ||
168 | diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw | ||
169 | new file mode 100644 | ||
170 | index XXXXXXX..XXXXXXX | ||
171 | --- /dev/null | ||
172 | +++ b/tests/qemu-iotests/150.out.raw | ||
173 | @@ -XXX,XX +XXX,XX @@ | ||
174 | +QA output created by 150 | ||
175 | + | ||
176 | +=== Mapping sparse conversion === | ||
177 | + | ||
178 | +Offset Length File | ||
179 | +0 0x1000 TEST_DIR/t.IMGFMT | ||
180 | + | ||
181 | +=== Mapping non-sparse conversion === | ||
182 | + | ||
183 | +Offset Length File | ||
184 | +0 0x100000 TEST_DIR/t.IMGFMT | ||
185 | +*** done | ||
186 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | ||
187 | index XXXXXXX..XXXXXXX 100755 | ||
188 | --- a/tests/qemu-iotests/175 | ||
189 | +++ b/tests/qemu-iotests/175 | ||
190 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
191 | # the file size. This function hides the resulting difference in the | ||
192 | # stat -c '%b' output. | ||
193 | # Parameter 1: Number of blocks an empty file occupies | ||
194 | -# Parameter 2: Image size in bytes | ||
195 | +# Parameter 2: Minimal number of blocks in an image | ||
196 | +# Parameter 3: Image size in bytes | ||
197 | _filter_blocks() | ||
198 | { | ||
199 | extra_blocks=$1 | ||
200 | - img_size=$2 | ||
201 | + min_blocks=$2 | ||
202 | + img_size=$3 | ||
203 | |||
204 | - sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \ | ||
205 | - -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/" | ||
206 | + sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \ | ||
207 | + -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | ||
208 | } | ||
209 | |||
210 | # get standard environment, filters and checks | ||
211 | @@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024)) | ||
212 | touch "$TEST_DIR/empty" | ||
213 | extra_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
214 | |||
215 | +# We always write the first byte; check how many blocks this filesystem | ||
216 | +# allocates to match empty image alloation. | ||
217 | +printf "\0" > "$TEST_DIR/empty" | ||
218 | +min_blocks=$(stat -c '%b' "$TEST_DIR/empty") | ||
219 | + | ||
220 | echo | ||
221 | echo "== creating image with default preallocation ==" | ||
222 | _make_test_img $size | _filter_imgfmt | ||
223 | -stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
224 | +stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
225 | |||
226 | for mode in off full falloc; do | ||
227 | echo | ||
228 | echo "== creating image with preallocation $mode ==" | ||
229 | IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt | ||
230 | - stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size | ||
231 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
232 | done | ||
233 | |||
234 | # success, all done | ||
235 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | ||
236 | index XXXXXXX..XXXXXXX 100644 | ||
237 | --- a/tests/qemu-iotests/175.out | ||
238 | +++ b/tests/qemu-iotests/175.out | ||
239 | @@ -XXX,XX +XXX,XX @@ QA output created by 175 | ||
240 | |||
241 | == creating image with default preallocation == | ||
242 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 | ||
243 | -size=1048576, nothing allocated | ||
244 | +size=1048576, min allocation | ||
245 | |||
246 | == creating image with preallocation off == | ||
247 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off | ||
248 | -size=1048576, nothing allocated | ||
249 | +size=1048576, min allocation | ||
250 | |||
251 | == creating image with preallocation full == | ||
252 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full | ||
253 | -size=1048576, everything allocated | ||
254 | +size=1048576, max allocation | ||
255 | |||
256 | == creating image with preallocation falloc == | ||
257 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | ||
258 | -size=1048576, everything allocated | ||
259 | +size=1048576, max allocation | ||
260 | *** done | ||
261 | diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2 | ||
262 | index XXXXXXX..XXXXXXX 100644 | ||
263 | --- a/tests/qemu-iotests/178.out.qcow2 | ||
264 | +++ b/tests/qemu-iotests/178.out.qcow2 | ||
265 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
266 | == raw input image with data (human) == | ||
267 | |||
268 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
269 | -required size: 393216 | ||
270 | +required size: 458752 | ||
271 | fully allocated size: 1074135040 | ||
272 | wrote 512/512 bytes at offset 512 | ||
273 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
274 | @@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608 | ||
275 | |||
276 | Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824 | ||
277 | { | ||
278 | - "required": 393216, | ||
279 | + "required": 458752, | ||
280 | "fully-allocated": 1074135040 | ||
281 | } | ||
282 | wrote 512/512 bytes at offset 512 | ||
283 | diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/tests/qemu-iotests/221.out | ||
286 | +++ b/tests/qemu-iotests/221.out | ||
287 | @@ -XXX,XX +XXX,XX @@ QA output created by 221 | ||
288 | === Check mapping of unaligned raw image === | ||
289 | |||
290 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537 | ||
291 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
292 | -[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
293 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
294 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
295 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
296 | +{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
297 | wrote 1/1 bytes at offset 65536 | ||
298 | 1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
299 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
300 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
301 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
302 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
303 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
304 | -[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
305 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
306 | +{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
307 | { "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
308 | { "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
309 | *** done | ||
310 | diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out | ||
311 | index XXXXXXX..XXXXXXX 100644 | ||
312 | --- a/tests/qemu-iotests/253.out | ||
313 | +++ b/tests/qemu-iotests/253.out | ||
314 | @@ -XXX,XX +XXX,XX @@ QA output created by 253 | ||
315 | === Check mapping of unaligned raw image === | ||
316 | |||
317 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575 | ||
318 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
319 | -[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
320 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
321 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
322 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
323 | +{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}] | ||
324 | wrote 65535/65535 bytes at offset 983040 | ||
325 | 63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
326 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
327 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
328 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
329 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
330 | -[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
331 | +[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, | ||
332 | +{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET}, | ||
333 | { "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] | ||
334 | *** done | ||
335 | -- | ||
336 | 2.21.0 | ||
337 | |||
338 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
1 | 2 | ||
3 | Using block_resize we can test allocate_first_block() with file | ||
4 | descriptor opened with O_DIRECT, ensuring that it works for any size | ||
5 | larger than 4096 bytes. | ||
6 | |||
7 | Testing smaller sizes is tricky as the result depends on the filesystem | ||
8 | used for testing. For example on NFS any size will work since O_DIRECT | ||
9 | does not require any alignment. | ||
10 | |||
11 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
12 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
13 | Message-id: 20190827010528.8818-3-nsoffer@redhat.com | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++ | ||
17 | tests/qemu-iotests/175.out | 8 ++++++++ | ||
18 | 2 files changed, 36 insertions(+) | ||
19 | |||
20 | diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175 | ||
21 | index XXXXXXX..XXXXXXX 100755 | ||
22 | --- a/tests/qemu-iotests/175 | ||
23 | +++ b/tests/qemu-iotests/175 | ||
24 | @@ -XXX,XX +XXX,XX @@ _filter_blocks() | ||
25 | -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/" | ||
26 | } | ||
27 | |||
28 | +# Resize image using block_resize. | ||
29 | +# Parameter 1: image path | ||
30 | +# Parameter 2: new size | ||
31 | +_block_resize() | ||
32 | +{ | ||
33 | + local path=$1 | ||
34 | + local size=$2 | ||
35 | + | ||
36 | + $QEMU -qmp stdio -nographic -nodefaults \ | ||
37 | + -blockdev file,node-name=file,filename=$path,cache.direct=on \ | ||
38 | + <<EOF | ||
39 | +{'execute': 'qmp_capabilities'} | ||
40 | +{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}} | ||
41 | +{'execute': 'quit'} | ||
42 | +EOF | ||
43 | +} | ||
44 | + | ||
45 | # get standard environment, filters and checks | ||
46 | . ./common.rc | ||
47 | . ./common.filter | ||
48 | @@ -XXX,XX +XXX,XX @@ _supported_fmt raw | ||
49 | _supported_proto file | ||
50 | _supported_os Linux | ||
51 | |||
52 | +_default_cache_mode none | ||
53 | +_supported_cache_modes none directsync | ||
54 | + | ||
55 | size=$((1 * 1024 * 1024)) | ||
56 | |||
57 | touch "$TEST_DIR/empty" | ||
58 | @@ -XXX,XX +XXX,XX @@ for mode in off full falloc; do | ||
59 | stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size | ||
60 | done | ||
61 | |||
62 | +for new_size in 4096 1048576; do | ||
63 | + echo | ||
64 | + echo "== resize empty image with block_resize ==" | ||
65 | + _make_test_img 0 | _filter_imgfmt | ||
66 | + _block_resize $TEST_IMG $new_size >/dev/null | ||
67 | + stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size | ||
68 | +done | ||
69 | + | ||
70 | # success, all done | ||
71 | echo "*** done" | ||
72 | rm -f $seq.full | ||
73 | diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/tests/qemu-iotests/175.out | ||
76 | +++ b/tests/qemu-iotests/175.out | ||
77 | @@ -XXX,XX +XXX,XX @@ size=1048576, max allocation | ||
78 | == creating image with preallocation falloc == | ||
79 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc | ||
80 | size=1048576, max allocation | ||
81 | + | ||
82 | +== resize empty image with block_resize == | ||
83 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | ||
84 | +size=4096, min allocation | ||
85 | + | ||
86 | +== resize empty image with block_resize == | ||
87 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0 | ||
88 | +size=1048576, min allocation | ||
89 | *** done | ||
90 | -- | ||
91 | 2.21.0 | ||
92 | |||
93 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | fe646693acc changed qemu-img create's output so that it no longer prints | ||
2 | single quotes around parameter values. The subformat and adapter_type | ||
3 | filters in _filter_img_create() have never been adapted to that change. | ||
1 | 4 | ||
5 | Fixes: fe646693acc13ac48b98435d14149ab04dc597bc | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Message-id: 20190815153638.4600-2-mreitz@redhat.com | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/059.out | 16 ++++++++-------- | ||
13 | tests/qemu-iotests/common.filter | 4 ++-- | ||
14 | 2 files changed, 10 insertions(+), 10 deletions(-) | ||
15 | |||
16 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/tests/qemu-iotests/059.out | ||
19 | +++ b/tests/qemu-iotests/059.out | ||
20 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
21 | qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big | ||
22 | |||
23 | === Testing monolithicFlat creation and opening === | ||
24 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
25 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
26 | image: TEST_DIR/t.IMGFMT | ||
27 | file format: IMGFMT | ||
28 | virtual size: 2 GiB (2147483648 bytes) | ||
29 | |||
30 | === Testing monolithicFlat with zeroed_grain === | ||
31 | qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain | ||
32 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat | ||
33 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 | ||
34 | |||
35 | === Testing big twoGbMaxExtentFlat === | ||
36 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat | ||
37 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 | ||
38 | image: TEST_DIR/t.vmdk | ||
39 | file format: vmdk | ||
40 | virtual size: 0.977 TiB (1073741824000 bytes) | ||
41 | @@ -XXX,XX +XXX,XX @@ Format specific information: | ||
42 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1 | ||
43 | |||
44 | === Testing truncated sparse === | ||
45 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse | ||
46 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 | ||
47 | qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes | ||
48 | |||
49 | === Converting to streamOptimized from image with small cluster size=== | ||
50 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
51 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
52 | |||
53 | === Testing monolithicFlat with internally generated JSON file name === | ||
54 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat | ||
55 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
56 | qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' | ||
57 | |||
58 | === Testing version 3 === | ||
59 | @@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328 | ||
60 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
61 | |||
62 | === Testing 4TB monolithicFlat creation and IO === | ||
63 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 subformat=monolithicFlat | ||
64 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 | ||
65 | image: TEST_DIR/t.IMGFMT | ||
66 | file format: IMGFMT | ||
67 | virtual size: 4 TiB (4398046511104 bytes) | ||
68 | @@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 966367641600 | ||
69 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
70 | |||
71 | === Testing qemu-img map on extents === | ||
72 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=monolithicSparse | ||
73 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
74 | wrote 1024/1024 bytes at offset 65024 | ||
75 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
76 | wrote 1024/1024 bytes at offset 2147483136 | ||
77 | @@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File | ||
78 | 0 0x20000 0x3f0000 TEST_DIR/t.vmdk | ||
79 | 0x7fff0000 0x20000 0x410000 TEST_DIR/t.vmdk | ||
80 | 0x140000000 0x10000 0x430000 TEST_DIR/t.vmdk | ||
81 | -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse | ||
82 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 | ||
83 | wrote 1024/1024 bytes at offset 65024 | ||
84 | 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
85 | wrote 1024/1024 bytes at offset 2147483136 | ||
86 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/tests/qemu-iotests/common.filter | ||
89 | +++ b/tests/qemu-iotests/common.filter | ||
90 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | ||
91 | -e "s# compat6=\\(on\\|off\\)##g" \ | ||
92 | -e "s# static=\\(on\\|off\\)##g" \ | ||
93 | -e "s# zeroed_grain=\\(on\\|off\\)##g" \ | ||
94 | - -e "s# subformat='[^']*'##g" \ | ||
95 | - -e "s# adapter_type='[^']*'##g" \ | ||
96 | + -e "s# subformat=[^ ]*##g" \ | ||
97 | + -e "s# adapter_type=[^ ]*##g" \ | ||
98 | -e "s# hwversion=[^ ]*##g" \ | ||
99 | -e "s# lazy_refcounts=\\(on\\|off\\)##g" \ | ||
100 | -e "s# block_size=[0-9]\\+##g" \ | ||
101 | -- | ||
102 | 2.21.0 | ||
103 | |||
104 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also | ||
2 | turns a former error in 059 into success. | ||
1 | 3 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
5 | Message-id: 20190815153638.4600-3-mreitz@redhat.com | ||
6 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
8 | --- | ||
9 | block/vmdk.c | 54 ++++++++++++++++++++++++-------------- | ||
10 | tests/qemu-iotests/059 | 7 +++-- | ||
11 | tests/qemu-iotests/059.out | 4 ++- | ||
12 | 3 files changed, 42 insertions(+), 23 deletions(-) | ||
13 | |||
14 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block/vmdk.c | ||
17 | +++ b/block/vmdk.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s) | ||
19 | } | ||
20 | |||
21 | static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
22 | - const char *desc_file_path, QDict *options, | ||
23 | - Error **errp) | ||
24 | + QDict *options, Error **errp) | ||
25 | { | ||
26 | int ret; | ||
27 | int matches; | ||
28 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
29 | const char *p, *np; | ||
30 | int64_t sectors = 0; | ||
31 | int64_t flat_offset; | ||
32 | + char *desc_file_dir = NULL; | ||
33 | char *extent_path; | ||
34 | BdrvChild *extent_file; | ||
35 | BDRVVmdkState *s = bs->opaque; | ||
36 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
37 | continue; | ||
38 | } | ||
39 | |||
40 | - if (!path_is_absolute(fname) && !path_has_protocol(fname) && | ||
41 | - !desc_file_path[0]) | ||
42 | - { | ||
43 | - bdrv_refresh_filename(bs->file->bs); | ||
44 | - error_setg(errp, "Cannot use relative extent paths with VMDK " | ||
45 | - "descriptor file '%s'", bs->file->bs->filename); | ||
46 | - return -EINVAL; | ||
47 | - } | ||
48 | + if (path_is_absolute(fname)) { | ||
49 | + extent_path = g_strdup(fname); | ||
50 | + } else { | ||
51 | + if (!desc_file_dir) { | ||
52 | + desc_file_dir = bdrv_dirname(bs->file->bs, errp); | ||
53 | + if (!desc_file_dir) { | ||
54 | + bdrv_refresh_filename(bs->file->bs); | ||
55 | + error_prepend(errp, "Cannot use relative paths with VMDK " | ||
56 | + "descriptor file '%s': ", | ||
57 | + bs->file->bs->filename); | ||
58 | + ret = -EINVAL; | ||
59 | + goto out; | ||
60 | + } | ||
61 | + } | ||
62 | |||
63 | - extent_path = path_combine(desc_file_path, fname); | ||
64 | + extent_path = g_strconcat(desc_file_dir, fname, NULL); | ||
65 | + } | ||
66 | |||
67 | ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents); | ||
68 | assert(ret < 32); | ||
69 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
70 | g_free(extent_path); | ||
71 | if (local_err) { | ||
72 | error_propagate(errp, local_err); | ||
73 | - return -EINVAL; | ||
74 | + ret = -EINVAL; | ||
75 | + goto out; | ||
76 | } | ||
77 | |||
78 | /* save to extents array */ | ||
79 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
80 | 0, 0, 0, 0, 0, &extent, errp); | ||
81 | if (ret < 0) { | ||
82 | bdrv_unref_child(bs, extent_file); | ||
83 | - return ret; | ||
84 | + goto out; | ||
85 | } | ||
86 | extent->flat_start_offset = flat_offset << 9; | ||
87 | } else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) { | ||
88 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, | ||
89 | g_free(buf); | ||
90 | if (ret) { | ||
91 | bdrv_unref_child(bs, extent_file); | ||
92 | - return ret; | ||
93 | + goto out; | ||
94 | } | ||
95 | extent = &s->extents[s->num_extents - 1]; | ||
96 | } else if (!strcmp(type, "SESPARSE")) { | ||
97 | ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp); | ||
98 | if (ret) { | ||
99 | bdrv_unref_child(bs, extent_file); | ||
100 | - return ret; | ||
101 | + goto out; | ||
102 | } | ||
103 | extent = &s->extents[s->num_extents - 1]; | ||
104 | } else { | ||
105 | error_setg(errp, "Unsupported extent type '%s'", type); | ||
106 | bdrv_unref_child(bs, extent_file); | ||
107 | - return -ENOTSUP; | ||
108 | + ret = -ENOTSUP; | ||
109 | + goto out; | ||
110 | } | ||
111 | extent->type = g_strdup(type); | ||
112 | } | ||
113 | - return 0; | ||
114 | + | ||
115 | + ret = 0; | ||
116 | + goto out; | ||
117 | |||
118 | invalid: | ||
119 | np = next_line(p); | ||
120 | @@ -XXX,XX +XXX,XX @@ invalid: | ||
121 | np--; | ||
122 | } | ||
123 | error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p); | ||
124 | - return -EINVAL; | ||
125 | + ret = -EINVAL; | ||
126 | + | ||
127 | +out: | ||
128 | + g_free(desc_file_dir); | ||
129 | + return ret; | ||
130 | } | ||
131 | |||
132 | static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
133 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf, | ||
134 | } | ||
135 | s->create_type = g_strdup(ct); | ||
136 | s->desc_offset = 0; | ||
137 | - ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options, | ||
138 | - errp); | ||
139 | + ret = vmdk_parse_extents(buf, bs, options, errp); | ||
140 | exit: | ||
141 | return ret; | ||
142 | } | ||
143 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 | ||
144 | index XXXXXXX..XXXXXXX 100755 | ||
145 | --- a/tests/qemu-iotests/059 | ||
146 | +++ b/tests/qemu-iotests/059 | ||
147 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 | ||
148 | |||
149 | echo | ||
150 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" | ||
151 | +# Should work, because bdrv_dirname() works fine with blkdebug | ||
152 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | ||
153 | -$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \ | ||
154 | - | _filter_testdir | _filter_imgfmt | ||
155 | +$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ | ||
156 | + -c info \ | ||
157 | + 2>&1 \ | ||
158 | + | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
159 | _cleanup_test_img | ||
160 | |||
161 | echo | ||
162 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/tests/qemu-iotests/059.out | ||
165 | +++ b/tests/qemu-iotests/059.out | ||
166 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
167 | |||
168 | === Testing monolithicFlat with internally generated JSON file name === | ||
169 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
170 | -qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}' | ||
171 | +format name: IMGFMT | ||
172 | +cluster size: 0 bytes | ||
173 | +vm state offset: 0 bytes | ||
174 | |||
175 | === Testing version 3 === | ||
176 | image: TEST_DIR/iotest-version3.IMGFMT | ||
177 | -- | ||
178 | 2.21.0 | ||
179 | |||
180 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We had a test for a case where relative extent paths did not work, but | ||
2 | unfortunately we just fixed the underlying problem, so it works now. | ||
3 | This patch adds a new test case that still fails. | ||
1 | 4 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
6 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
7 | Message-id: 20190815153638.4600-4-mreitz@redhat.com | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | --- | ||
11 | tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++ | ||
12 | tests/qemu-iotests/059.out | 4 ++++ | ||
13 | 2 files changed, 31 insertions(+) | ||
14 | |||
15 | diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 | ||
16 | index XXXXXXX..XXXXXXX 100755 | ||
17 | --- a/tests/qemu-iotests/059 | ||
18 | +++ b/tests/qemu-iotests/059 | ||
19 | @@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2 | ||
20 | |||
21 | echo | ||
22 | echo "=== Testing monolithicFlat with internally generated JSON file name ===" | ||
23 | + | ||
24 | +echo '--- blkdebug ---' | ||
25 | # Should work, because bdrv_dirname() works fine with blkdebug | ||
26 | IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | ||
27 | $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \ | ||
28 | @@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE | ||
29 | | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
30 | _cleanup_test_img | ||
31 | |||
32 | +echo '--- quorum ---' | ||
33 | +# Should not work, because bdrv_dirname() does not work with quorum | ||
34 | +IMGOPTS="subformat=monolithicFlat" _make_test_img 64M | ||
35 | +cp "$TEST_IMG" "$TEST_IMG.orig" | ||
36 | + | ||
37 | +filename="json:{ | ||
38 | + \"driver\": \"$IMGFMT\", | ||
39 | + \"file\": { | ||
40 | + \"driver\": \"quorum\", | ||
41 | + \"children\": [ { | ||
42 | + \"driver\": \"file\", | ||
43 | + \"filename\": \"$TEST_IMG\" | ||
44 | + }, { | ||
45 | + \"driver\": \"file\", | ||
46 | + \"filename\": \"$TEST_IMG.orig\" | ||
47 | + } ], | ||
48 | + \"vote-threshold\": 1 | ||
49 | + } }" | ||
50 | + | ||
51 | +filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g') | ||
52 | +$QEMU_IMG info "$filename" 2>&1 \ | ||
53 | + | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \ | ||
54 | + | _filter_testdir | _filter_imgfmt | _filter_img_info | ||
55 | + | ||
56 | + | ||
57 | echo | ||
58 | echo "=== Testing version 3 ===" | ||
59 | _use_sample_img iotest-version3.vmdk.bz2 | ||
60 | diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/tests/qemu-iotests/059.out | ||
63 | +++ b/tests/qemu-iotests/059.out | ||
64 | @@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240 | ||
65 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
66 | |||
67 | === Testing monolithicFlat with internally generated JSON file name === | ||
68 | +--- blkdebug --- | ||
69 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
70 | format name: IMGFMT | ||
71 | cluster size: 0 bytes | ||
72 | vm state offset: 0 bytes | ||
73 | +--- quorum --- | ||
74 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
75 | +qemu-img: Could not open $QUORUM_FILE: Cannot use relative paths with VMDK descriptor file $QUORUM_FILE: Cannot generate a base directory for quorum nodes | ||
76 | |||
77 | === Testing version 3 === | ||
78 | image: TEST_DIR/iotest-version3.IMGFMT | ||
79 | -- | ||
80 | 2.21.0 | ||
81 | |||
82 | diff view generated by jsdifflib |
1 | From: Kashyap Chamarthy <kchamart@redhat.com> | 1 | Compressed writes generally have to write full clusters, not just in |
---|---|---|---|
2 | theory but also in practice when it comes to vmdk's streamOptimized | ||
3 | subformat. It currently is just silently broken for writes with | ||
4 | non-zero in-cluster offsets: | ||
2 | 5 | ||
3 | This patch documents (including their QMP invocations) all the four | 6 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M |
4 | major kinds of live block operations: | 7 | $ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk |
8 | wrote 4096/4096 bytes at offset 4096 | ||
9 | 4 KiB, 1 ops; 00.01 sec (443.724 KiB/sec and 110.9309 ops/sec) | ||
10 | read failed: Invalid argument | ||
5 | 11 | ||
6 | - `block-stream` | 12 | (The technical reason is that vmdk_write_extent() just writes the |
7 | - `block-commit` | 13 | incomplete compressed data actually to offset 4k. When reading the |
8 | - `drive-mirror` (& `blockdev-mirror`) | 14 | data, vmdk_read_extent() looks at offset 0 and finds the compressed data |
9 | - `drive-backup` (& `blockdev-backup`) | 15 | size to be 0, because that is what it reads from there. This yields an |
16 | error.) | ||
10 | 17 | ||
11 | Things considered while writing this document: | 18 | For incomplete writes with zero in-cluster offsets, the error path when |
19 | reading the rest of the cluster is a bit different, but the result is | ||
20 | the same: | ||
12 | 21 | ||
13 | - Use reStructuredText as markup language (with the goal of generating | 22 | $ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M |
14 | the HTML output using the Sphinx Documentation Generator). It is | 23 | $ qemu-io -c 'write 0k 4k' -c 'read 4k 4k' foo.vmdk |
15 | gentler on the eye, and can be trivially converted to different | 24 | wrote 4096/4096 bytes at offset 0 |
16 | formats. (Another reason: upstream QEMU is considering to switch to | 25 | 4 KiB, 1 ops; 00.01 sec (362.641 KiB/sec and 90.6603 ops/sec) |
17 | Sphinx, which uses reStructuredText as its markup language.) | 26 | read failed: Invalid argument |
18 | 27 | ||
19 | - Raw QMP JSON output vs. 'qmp-shell'. I debated with myself whether | 28 | (Here, vmdk_read_extent() finds the data and then sees that the |
20 | to only show raw QMP JSON output (as that is the canonical | 29 | uncompressed data is short.) |
21 | representation), or use 'qmp-shell', which takes key-value pairs. I | ||
22 | settled on the approach of: for the first occurrence of a command, | ||
23 | use raw JSON; for subsequent occurrences, use 'qmp-shell', with an | ||
24 | occasional exception. | ||
25 | 30 | ||
26 | - Usage of `-blockdev` command-line. | 31 | It is better to reject invalid writes than to make the user believe they |
32 | might have succeeded and then fail when trying to read it back. | ||
27 | 33 | ||
28 | - Usage of 'node-name' vs. file path to refer to disks. While we have | 34 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
29 | `blockdev-{mirror, backup}` as 'node-name'-alternatives for | 35 | Reviewed-by: John Snow <jsnow@redhat.com> |
30 | `drive-{mirror, backup}`, the `block-commit` command still operates | 36 | Message-id: 20190815153638.4600-5-mreitz@redhat.com |
31 | on file names for parameters 'base' and 'top'. So I added a caveat | 37 | Reviewed-by: John Snow <jsnow@redhat.com> |
32 | at the beginning to that effect. | 38 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
39 | --- | ||
40 | block/vmdk.c | 10 ++++++++++ | ||
41 | 1 file changed, 10 insertions(+) | ||
33 | 42 | ||
34 | Refer this related thread that I started (where I learnt | 43 | diff --git a/block/vmdk.c b/block/vmdk.c |
35 | `block-stream` was recently reworked to accept 'node-name' for 'top' | 44 | index XXXXXXX..XXXXXXX 100644 |
36 | and 'base' parameters): | 45 | --- a/block/vmdk.c |
37 | https://lists.nongnu.org/archive/html/qemu-devel/2017-05/msg06466.html | 46 | +++ b/block/vmdk.c |
38 | "[RFC] Making 'block-stream', and 'block-commit' accept node-name" | 47 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, |
39 | 48 | if (extent->compressed) { | |
40 | All commands showed in this document were tested while documenting. | 49 | void *compressed_data; |
41 | 50 | ||
42 | Thanks: Eric Blake for the section: "A note on points-in-time vs file | 51 | + /* Only whole clusters */ |
43 | names". This useful bit was originally articulated by Eric in his | 52 | + if (offset_in_cluster || |
44 | KVMForum 2015 presentation, so I included that specific bit in this | 53 | + n_bytes > (extent->cluster_sectors * SECTOR_SIZE) || |
45 | document. | 54 | + (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) && |
46 | 55 | + offset + n_bytes != extent->end_sector * SECTOR_SIZE)) | |
47 | Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com> | ||
48 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
49 | Message-id: 20170717105205.32639-3-kchamart@redhat.com | ||
50 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
51 | --- | ||
52 | docs/interop/live-block-operations.rst | 1088 ++++++++++++++++++++++++++++++++ | ||
53 | docs/live-block-ops.txt | 72 --- | ||
54 | 2 files changed, 1088 insertions(+), 72 deletions(-) | ||
55 | create mode 100644 docs/interop/live-block-operations.rst | ||
56 | delete mode 100644 docs/live-block-ops.txt | ||
57 | |||
58 | diff --git a/docs/interop/live-block-operations.rst b/docs/interop/live-block-operations.rst | ||
59 | new file mode 100644 | ||
60 | index XXXXXXX..XXXXXXX | ||
61 | --- /dev/null | ||
62 | +++ b/docs/interop/live-block-operations.rst | ||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | +.. | ||
65 | + Copyright (C) 2017 Red Hat Inc. | ||
66 | + | ||
67 | + This work is licensed under the terms of the GNU GPL, version 2 or | ||
68 | + later. See the COPYING file in the top-level directory. | ||
69 | + | ||
70 | +============================ | ||
71 | +Live Block Device Operations | ||
72 | +============================ | ||
73 | + | ||
74 | +QEMU Block Layer currently (as of QEMU 2.9) supports four major kinds of | ||
75 | +live block device jobs -- stream, commit, mirror, and backup. These can | ||
76 | +be used to manipulate disk image chains to accomplish certain tasks, | ||
77 | +namely: live copy data from backing files into overlays; shorten long | ||
78 | +disk image chains by merging data from overlays into backing files; live | ||
79 | +synchronize data from a disk image chain (including current active disk) | ||
80 | +to another target image; and point-in-time (and incremental) backups of | ||
81 | +a block device. Below is a description of the said block (QMP) | ||
82 | +primitives, and some (non-exhaustive list of) examples to illustrate | ||
83 | +their use. | ||
84 | + | ||
85 | +.. note:: | ||
86 | + The file ``qapi/block-core.json`` in the QEMU source tree has the | ||
87 | + canonical QEMU API (QAPI) schema documentation for the QMP | ||
88 | + primitives discussed here. | ||
89 | + | ||
90 | +.. todo (kashyapc):: Remove the ".. contents::" directive when Sphinx is | ||
91 | + integrated. | ||
92 | + | ||
93 | +.. contents:: | ||
94 | + | ||
95 | +Disk image backing chain notation | ||
96 | +--------------------------------- | ||
97 | + | ||
98 | +A simple disk image chain. (This can be created live using QMP | ||
99 | +``blockdev-snapshot-sync``, or offline via ``qemu-img``):: | ||
100 | + | ||
101 | + (Live QEMU) | ||
102 | + | | ||
103 | + . | ||
104 | + V | ||
105 | + | ||
106 | + [A] <----- [B] | ||
107 | + | ||
108 | + (backing file) (overlay) | ||
109 | + | ||
110 | +The arrow can be read as: Image [A] is the backing file of disk image | ||
111 | +[B]. And live QEMU is currently writing to image [B], consequently, it | ||
112 | +is also referred to as the "active layer". | ||
113 | + | ||
114 | +There are two kinds of terminology that are common when referring to | ||
115 | +files in a disk image backing chain: | ||
116 | + | ||
117 | +(1) Directional: 'base' and 'top'. Given the simple disk image chain | ||
118 | + above, image [A] can be referred to as 'base', and image [B] as | ||
119 | + 'top'. (This terminology can be seen in in QAPI schema file, | ||
120 | + block-core.json.) | ||
121 | + | ||
122 | +(2) Relational: 'backing file' and 'overlay'. Again, taking the same | ||
123 | + simple disk image chain from the above, disk image [A] is referred | ||
124 | + to as the backing file, and image [B] as overlay. | ||
125 | + | ||
126 | + Throughout this document, we will use the relational terminology. | ||
127 | + | ||
128 | +.. important:: | ||
129 | + The overlay files can generally be any format that supports a | ||
130 | + backing file, although QCOW2 is the preferred format and the one | ||
131 | + used in this document. | ||
132 | + | ||
133 | + | ||
134 | +Brief overview of live block QMP primitives | ||
135 | +------------------------------------------- | ||
136 | + | ||
137 | +The following are the four different kinds of live block operations that | ||
138 | +QEMU block layer supports. | ||
139 | + | ||
140 | +(1) ``block-stream``: Live copy of data from backing files into overlay | ||
141 | + files. | ||
142 | + | ||
143 | + .. note:: Once the 'stream' operation has finished, three things to | ||
144 | + note: | ||
145 | + | ||
146 | + (a) QEMU rewrites the backing chain to remove | ||
147 | + reference to the now-streamed and redundant backing | ||
148 | + file; | ||
149 | + | ||
150 | + (b) the streamed file *itself* won't be removed by QEMU, | ||
151 | + and must be explicitly discarded by the user; | ||
152 | + | ||
153 | + (c) the streamed file remains valid -- i.e. further | ||
154 | + overlays can be created based on it. Refer the | ||
155 | + ``block-stream`` section further below for more | ||
156 | + details. | ||
157 | + | ||
158 | +(2) ``block-commit``: Live merge of data from overlay files into backing | ||
159 | + files (with the optional goal of removing the overlay file from the | ||
160 | + chain). Since QEMU 2.0, this includes "active ``block-commit``" | ||
161 | + (i.e. merge the current active layer into the base image). | ||
162 | + | ||
163 | + .. note:: Once the 'commit' operation has finished, there are three | ||
164 | + things to note here as well: | ||
165 | + | ||
166 | + (a) QEMU rewrites the backing chain to remove reference | ||
167 | + to now-redundant overlay images that have been | ||
168 | + committed into a backing file; | ||
169 | + | ||
170 | + (b) the committed file *itself* won't be removed by QEMU | ||
171 | + -- it ought to be manually removed; | ||
172 | + | ||
173 | + (c) however, unlike in the case of ``block-stream``, the | ||
174 | + intermediate images will be rendered invalid -- i.e. | ||
175 | + no more further overlays can be created based on | ||
176 | + them. Refer the ``block-commit`` section further | ||
177 | + below for more details. | ||
178 | + | ||
179 | +(3) ``drive-mirror`` (and ``blockdev-mirror``): Synchronize a running | ||
180 | + disk to another image. | ||
181 | + | ||
182 | +(4) ``drive-backup`` (and ``blockdev-backup``): Point-in-time (live) copy | ||
183 | + of a block device to a destination. | ||
184 | + | ||
185 | + | ||
186 | +.. _`Interacting with a QEMU instance`: | ||
187 | + | ||
188 | +Interacting with a QEMU instance | ||
189 | +-------------------------------- | ||
190 | + | ||
191 | +To show some example invocations of command-line, we will use the | ||
192 | +following invocation of QEMU, with a QMP server running over UNIX | ||
193 | +socket:: | ||
194 | + | ||
195 | + $ ./x86_64-softmmu/qemu-system-x86_64 -display none -nodefconfig \ | ||
196 | + -M q35 -nodefaults -m 512 \ | ||
197 | + -blockdev node-name=node-A,driver=qcow2,file.driver=file,file.node-name=file,file.filename=./a.qcow2 \ | ||
198 | + -device virtio-blk,drive=node-A,id=virtio0 \ | ||
199 | + -monitor stdio -qmp unix:/tmp/qmp-sock,server,nowait | ||
200 | + | ||
201 | +The ``-blockdev`` command-line option, used above, is available from | ||
202 | +QEMU 2.9 onwards. In the above invocation, notice the ``node-name`` | ||
203 | +parameter that is used to refer to the disk image a.qcow2 ('node-A') -- | ||
204 | +this is a cleaner way to refer to a disk image (as opposed to referring | ||
205 | +to it by spelling out file paths). So, we will continue to designate a | ||
206 | +``node-name`` to each further disk image created (either via | ||
207 | +``blockdev-snapshot-sync``, or ``blockdev-add``) as part of the disk | ||
208 | +image chain, and continue to refer to the disks using their | ||
209 | +``node-name`` (where possible, because ``block-commit`` does not yet, as | ||
210 | +of QEMU 2.9, accept ``node-name`` parameter) when performing various | ||
211 | +block operations. | ||
212 | + | ||
213 | +To interact with the QEMU instance launched above, we will use the | ||
214 | +``qmp-shell`` utility (located at: ``qemu/scripts/qmp``, as part of the | ||
215 | +QEMU source directory), which takes key-value pairs for QMP commands. | ||
216 | +Invoke it as below (which will also print out the complete raw JSON | ||
217 | +syntax for reference -- examples in the following sections):: | ||
218 | + | ||
219 | + $ ./qmp-shell -v -p /tmp/qmp-sock | ||
220 | + (QEMU) | ||
221 | + | ||
222 | +.. note:: | ||
223 | + In the event we have to repeat a certain QMP command, we will: for | ||
224 | + the first occurrence of it, show the ``qmp-shell`` invocation, *and* | ||
225 | + the corresponding raw JSON QMP syntax; but for subsequent | ||
226 | + invocations, present just the ``qmp-shell`` syntax, and omit the | ||
227 | + equivalent JSON output. | ||
228 | + | ||
229 | + | ||
230 | +Example disk image chain | ||
231 | +------------------------ | ||
232 | + | ||
233 | +We will use the below disk image chain (and occasionally spelling it | ||
234 | +out where appropriate) when discussing various primitives:: | ||
235 | + | ||
236 | + [A] <-- [B] <-- [C] <-- [D] | ||
237 | + | ||
238 | +Where [A] is the original base image; [B] and [C] are intermediate | ||
239 | +overlay images; image [D] is the active layer -- i.e. live QEMU is | ||
240 | +writing to it. (The rule of thumb is: live QEMU will always be pointing | ||
241 | +to the rightmost image in a disk image chain.) | ||
242 | + | ||
243 | +The above image chain can be created by invoking | ||
244 | +``blockdev-snapshot-sync`` commands as following (which shows the | ||
245 | +creation of overlay image [B]) using the ``qmp-shell`` (our invocation | ||
246 | +also prints the raw JSON invocation of it):: | ||
247 | + | ||
248 | + (QEMU) blockdev-snapshot-sync node-name=node-A snapshot-file=b.qcow2 snapshot-node-name=node-B format=qcow2 | ||
249 | + { | ||
250 | + "execute": "blockdev-snapshot-sync", | ||
251 | + "arguments": { | ||
252 | + "node-name": "node-A", | ||
253 | + "snapshot-file": "b.qcow2", | ||
254 | + "format": "qcow2", | ||
255 | + "snapshot-node-name": "node-B" | ||
256 | + } | ||
257 | + } | ||
258 | + | ||
259 | +Here, "node-A" is the name QEMU internally uses to refer to the base | ||
260 | +image [A] -- it is the backing file, based on which the overlay image, | ||
261 | +[B], is created. | ||
262 | + | ||
263 | +To create the rest of the overlay images, [C], and [D] (omitting the raw | ||
264 | +JSON output for brevity):: | ||
265 | + | ||
266 | + (QEMU) blockdev-snapshot-sync node-name=node-B snapshot-file=c.qcow2 snapshot-node-name=node-C format=qcow2 | ||
267 | + (QEMU) blockdev-snapshot-sync node-name=node-C snapshot-file=d.qcow2 snapshot-node-name=node-D format=qcow2 | ||
268 | + | ||
269 | + | ||
270 | +A note on points-in-time vs file names | ||
271 | +-------------------------------------- | ||
272 | + | ||
273 | +In our disk image chain:: | ||
274 | + | ||
275 | + [A] <-- [B] <-- [C] <-- [D] | ||
276 | + | ||
277 | +We have *three* points in time and an active layer: | ||
278 | + | ||
279 | +- Point 1: Guest state when [B] was created is contained in file [A] | ||
280 | +- Point 2: Guest state when [C] was created is contained in [A] + [B] | ||
281 | +- Point 3: Guest state when [D] was created is contained in | ||
282 | + [A] + [B] + [C] | ||
283 | +- Active layer: Current guest state is contained in [A] + [B] + [C] + | ||
284 | + [D] | ||
285 | + | ||
286 | +Therefore, be aware with naming choices: | ||
287 | + | ||
288 | +- Naming a file after the time it is created is misleading -- the | ||
289 | + guest data for that point in time is *not* contained in that file | ||
290 | + (as explained earlier) | ||
291 | +- Rather, think of files as a *delta* from the backing file | ||
292 | + | ||
293 | + | ||
294 | +Live block streaming --- ``block-stream`` | ||
295 | +----------------------------------------- | ||
296 | + | ||
297 | +The ``block-stream`` command allows you to do live copy data from backing | ||
298 | +files into overlay images. | ||
299 | + | ||
300 | +Given our original example disk image chain from earlier:: | ||
301 | + | ||
302 | + [A] <-- [B] <-- [C] <-- [D] | ||
303 | + | ||
304 | +The disk image chain can be shortened in one of the following different | ||
305 | +ways (not an exhaustive list). | ||
306 | + | ||
307 | +.. _`Case-1`: | ||
308 | + | ||
309 | +(1) Merge everything into the active layer: I.e. copy all contents from | ||
310 | + the base image, [A], and overlay images, [B] and [C], into [D], | ||
311 | + *while* the guest is running. The resulting chain will be a | ||
312 | + standalone image, [D] -- with contents from [A], [B] and [C] merged | ||
313 | + into it (where live QEMU writes go to):: | ||
314 | + | ||
315 | + [D] | ||
316 | + | ||
317 | +.. _`Case-2`: | ||
318 | + | ||
319 | +(2) Taking the same example disk image chain mentioned earlier, merge | ||
320 | + only images [B] and [C] into [D], the active layer. The result will | ||
321 | + be contents of images [B] and [C] will be copied into [D], and the | ||
322 | + backing file pointer of image [D] will be adjusted to point to image | ||
323 | + [A]. The resulting chain will be:: | ||
324 | + | ||
325 | + [A] <-- [D] | ||
326 | + | ||
327 | +.. _`Case-3`: | ||
328 | + | ||
329 | +(3) Intermediate streaming (available since QEMU 2.8): Starting afresh | ||
330 | + with the original example disk image chain, with a total of four | ||
331 | + images, it is possible to copy contents from image [B] into image | ||
332 | + [C]. Once the copy is finished, image [B] can now be (optionally) | ||
333 | + discarded; and the backing file pointer of image [C] will be | ||
334 | + adjusted to point to [A]. I.e. after performing "intermediate | ||
335 | + streaming" of [B] into [C], the resulting image chain will be (where | ||
336 | + live QEMU is writing to [D]):: | ||
337 | + | ||
338 | + [A] <-- [C] <-- [D] | ||
339 | + | ||
340 | + | ||
341 | +QMP invocation for ``block-stream`` | ||
342 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
343 | + | ||
344 | +For `Case-1`_, to merge contents of all the backing files into the | ||
345 | +active layer, where 'node-D' is the current active image (by default | ||
346 | +``block-stream`` will flatten the entire chain); ``qmp-shell`` (and its | ||
347 | +corresponding JSON output):: | ||
348 | + | ||
349 | + (QEMU) block-stream device=node-D job-id=job0 | ||
350 | + { | ||
351 | + "execute": "block-stream", | ||
352 | + "arguments": { | ||
353 | + "device": "node-D", | ||
354 | + "job-id": "job0" | ||
355 | + } | ||
356 | + } | ||
357 | + | ||
358 | +For `Case-2`_, merge contents of the images [B] and [C] into [D], where | ||
359 | +image [D] ends up referring to image [A] as its backing file:: | ||
360 | + | ||
361 | + (QEMU) block-stream device=node-D base-node=node-A job-id=job0 | ||
362 | + | ||
363 | +And for `Case-3`_, of "intermediate" streaming", merge contents of | ||
364 | +images [B] into [C], where [C] ends up referring to [A] as its backing | ||
365 | +image:: | ||
366 | + | ||
367 | + (QEMU) block-stream device=node-C base-node=node-A job-id=job0 | ||
368 | + | ||
369 | +Progress of a ``block-stream`` operation can be monitored via the QMP | ||
370 | +command:: | ||
371 | + | ||
372 | + (QEMU) query-block-jobs | ||
373 | + { | ||
374 | + "execute": "query-block-jobs", | ||
375 | + "arguments": {} | ||
376 | + } | ||
377 | + | ||
378 | + | ||
379 | +Once the ``block-stream`` operation has completed, QEMU will emit an | ||
380 | +event, ``BLOCK_JOB_COMPLETED``. The intermediate overlays remain valid, | ||
381 | +and can now be (optionally) discarded, or retained to create further | ||
382 | +overlays based on them. Finally, the ``block-stream`` jobs can be | ||
383 | +restarted at anytime. | ||
384 | + | ||
385 | + | ||
386 | +Live block commit --- ``block-commit`` | ||
387 | +-------------------------------------- | ||
388 | + | ||
389 | +The ``block-commit`` command lets you merge live data from overlay | ||
390 | +images into backing file(s). Since QEMU 2.0, this includes "live active | ||
391 | +commit" (i.e. it is possible to merge the "active layer", the right-most | ||
392 | +image in a disk image chain where live QEMU will be writing to, into the | ||
393 | +base image). This is analogous to ``block-stream``, but in the opposite | ||
394 | +direction. | ||
395 | + | ||
396 | +Again, starting afresh with our example disk image chain, where live | ||
397 | +QEMU is writing to the right-most image in the chain, [D]:: | ||
398 | + | ||
399 | + [A] <-- [B] <-- [C] <-- [D] | ||
400 | + | ||
401 | +The disk image chain can be shortened in one of the following ways: | ||
402 | + | ||
403 | +.. _`block-commit_Case-1`: | ||
404 | + | ||
405 | +(1) Commit content from only image [B] into image [A]. The resulting | ||
406 | + chain is the following, where image [C] is adjusted to point at [A] | ||
407 | + as its new backing file:: | ||
408 | + | ||
409 | + [A] <-- [C] <-- [D] | ||
410 | + | ||
411 | +(2) Commit content from images [B] and [C] into image [A]. The | ||
412 | + resulting chain, where image [D] is adjusted to point to image [A] | ||
413 | + as its new backing file:: | ||
414 | + | ||
415 | + [A] <-- [D] | ||
416 | + | ||
417 | +.. _`block-commit_Case-3`: | ||
418 | + | ||
419 | +(3) Commit content from images [B], [C], and the active layer [D] into | ||
420 | + image [A]. The resulting chain (in this case, a consolidated single | ||
421 | + image):: | ||
422 | + | ||
423 | + [A] | ||
424 | + | ||
425 | +(4) Commit content from image only image [C] into image [B]. The | ||
426 | + resulting chain:: | ||
427 | + | ||
428 | + [A] <-- [B] <-- [D] | ||
429 | + | ||
430 | +(5) Commit content from image [C] and the active layer [D] into image | ||
431 | + [B]. The resulting chain:: | ||
432 | + | ||
433 | + [A] <-- [B] | ||
434 | + | ||
435 | + | ||
436 | +QMP invocation for ``block-commit`` | ||
437 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
438 | + | ||
439 | +For :ref:`Case-1 <block-commit_Case-1>`, to merge contents only from | ||
440 | +image [B] into image [A], the invocation is as follows:: | ||
441 | + | ||
442 | + (QEMU) block-commit device=node-D base=a.qcow2 top=b.qcow2 job-id=job0 | ||
443 | + { | ||
444 | + "execute": "block-commit", | ||
445 | + "arguments": { | ||
446 | + "device": "node-D", | ||
447 | + "job-id": "job0", | ||
448 | + "top": "b.qcow2", | ||
449 | + "base": "a.qcow2" | ||
450 | + } | ||
451 | + } | ||
452 | + | ||
453 | +Once the above ``block-commit`` operation has completed, a | ||
454 | +``BLOCK_JOB_COMPLETED`` event will be issued, and no further action is | ||
455 | +required. As the end result, the backing file of image [C] is adjusted | ||
456 | +to point to image [A], and the original 4-image chain will end up being | ||
457 | +transformed to:: | ||
458 | + | ||
459 | + [A] <-- [C] <-- [D] | ||
460 | + | ||
461 | +.. note:: | ||
462 | + The intermediate image [B] is invalid (as in: no more further | ||
463 | + overlays based on it can be created). | ||
464 | + | ||
465 | + Reasoning: An intermediate image after a 'stream' operation still | ||
466 | + represents that old point-in-time, and may be valid in that context. | ||
467 | + However, an intermediate image after a 'commit' operation no longer | ||
468 | + represents any point-in-time, and is invalid in any context. | ||
469 | + | ||
470 | + | ||
471 | +However, :ref:`Case-3 <block-commit_Case-3>` (also called: "active | ||
472 | +``block-commit``") is a *two-phase* operation: In the first phase, the | ||
473 | +content from the active overlay, along with the intermediate overlays, | ||
474 | +is copied into the backing file (also called the base image). In the | ||
475 | +second phase, adjust the said backing file as the current active image | ||
476 | +-- possible via issuing the command ``block-job-complete``. Optionally, | ||
477 | +the ``block-commit`` operation can be cancelled by issuing the command | ||
478 | +``block-job-cancel``, but be careful when doing this. | ||
479 | + | ||
480 | +Once the ``block-commit`` operation has completed, the event | ||
481 | +``BLOCK_JOB_READY`` will be emitted, signalling that the synchronization | ||
482 | +has finished. Now the job can be gracefully completed by issuing the | ||
483 | +command ``block-job-complete`` -- until such a command is issued, the | ||
484 | +'commit' operation remains active. | ||
485 | + | ||
486 | +The following is the flow for :ref:`Case-3 <block-commit_Case-3>` to | ||
487 | +convert a disk image chain such as this:: | ||
488 | + | ||
489 | + [A] <-- [B] <-- [C] <-- [D] | ||
490 | + | ||
491 | +Into:: | ||
492 | + | ||
493 | + [A] | ||
494 | + | ||
495 | +Where content from all the subsequent overlays, [B], and [C], including | ||
496 | +the active layer, [D], is committed back to [A] -- which is where live | ||
497 | +QEMU is performing all its current writes). | ||
498 | + | ||
499 | +Start the "active ``block-commit``" operation:: | ||
500 | + | ||
501 | + (QEMU) block-commit device=node-D base=a.qcow2 top=d.qcow2 job-id=job0 | ||
502 | + { | ||
503 | + "execute": "block-commit", | ||
504 | + "arguments": { | ||
505 | + "device": "node-D", | ||
506 | + "job-id": "job0", | ||
507 | + "top": "d.qcow2", | ||
508 | + "base": "a.qcow2" | ||
509 | + } | ||
510 | + } | ||
511 | + | ||
512 | + | ||
513 | +Once the synchronization has completed, the event ``BLOCK_JOB_READY`` will | ||
514 | +be emitted. | ||
515 | + | ||
516 | +Then, optionally query for the status of the active block operations. | ||
517 | +We can see the 'commit' job is now ready to be completed, as indicated | ||
518 | +by the line *"ready": true*:: | ||
519 | + | ||
520 | + (QEMU) query-block-jobs | ||
521 | + { | ||
522 | + "execute": "query-block-jobs", | ||
523 | + "arguments": {} | ||
524 | + } | ||
525 | + { | ||
526 | + "return": [ | ||
527 | + { | ||
528 | + "busy": false, | ||
529 | + "type": "commit", | ||
530 | + "len": 1376256, | ||
531 | + "paused": false, | ||
532 | + "ready": true, | ||
533 | + "io-status": "ok", | ||
534 | + "offset": 1376256, | ||
535 | + "device": "job0", | ||
536 | + "speed": 0 | ||
537 | + } | ||
538 | + ] | ||
539 | + } | ||
540 | + | ||
541 | +Gracefully complete the 'commit' block device job:: | ||
542 | + | ||
543 | + (QEMU) block-job-complete device=job0 | ||
544 | + { | ||
545 | + "execute": "block-job-complete", | ||
546 | + "arguments": { | ||
547 | + "device": "job0" | ||
548 | + } | ||
549 | + } | ||
550 | + { | ||
551 | + "return": {} | ||
552 | + } | ||
553 | + | ||
554 | +Finally, once the above job is completed, an event | ||
555 | +``BLOCK_JOB_COMPLETED`` will be emitted. | ||
556 | + | ||
557 | +.. note:: | ||
558 | + The invocation for rest of the cases (2, 4, and 5), discussed in the | ||
559 | + previous section, is omitted for brevity. | ||
560 | + | ||
561 | + | ||
562 | +Live disk synchronization --- ``drive-mirror`` and ``blockdev-mirror`` | ||
563 | +---------------------------------------------------------------------- | ||
564 | + | ||
565 | +Synchronize a running disk image chain (all or part of it) to a target | ||
566 | +image. | ||
567 | + | ||
568 | +Again, given our familiar disk image chain:: | ||
569 | + | ||
570 | + [A] <-- [B] <-- [C] <-- [D] | ||
571 | + | ||
572 | +The ``drive-mirror`` (and its newer equivalent ``blockdev-mirror``) allows | ||
573 | +you to copy data from the entire chain into a single target image (which | ||
574 | +can be located on a different host). | ||
575 | + | ||
576 | +Once a 'mirror' job has started, there are two possible actions while a | ||
577 | +``drive-mirror`` job is active: | ||
578 | + | ||
579 | +(1) Issuing the command ``block-job-cancel`` after it emits the event | ||
580 | + ``BLOCK_JOB_CANCELLED``: will (after completing synchronization of | ||
581 | + the content from the disk image chain to the target image, [E]) | ||
582 | + create a point-in-time (which is at the time of *triggering* the | ||
583 | + cancel command) copy, contained in image [E], of the the entire disk | ||
584 | + image chain (or only the top-most image, depending on the ``sync`` | ||
585 | + mode). | ||
586 | + | ||
587 | +(2) Issuing the command ``block-job-complete`` after it emits the event | ||
588 | + ``BLOCK_JOB_COMPLETED``: will, after completing synchronization of | ||
589 | + the content, adjust the guest device (i.e. live QEMU) to point to | ||
590 | + the target image, and, causing all the new writes from this point on | ||
591 | + to happen there. One use case for this is live storage migration. | ||
592 | + | ||
593 | +About synchronization modes: The synchronization mode determines | ||
594 | +*which* part of the disk image chain will be copied to the target. | ||
595 | +Currently, there are four different kinds: | ||
596 | + | ||
597 | +(1) ``full`` -- Synchronize the content of entire disk image chain to | ||
598 | + the target | ||
599 | + | ||
600 | +(2) ``top`` -- Synchronize only the contents of the top-most disk image | ||
601 | + in the chain to the target | ||
602 | + | ||
603 | +(3) ``none`` -- Synchronize only the new writes from this point on. | ||
604 | + | ||
605 | + .. note:: In the case of ``drive-backup`` (or ``blockdev-backup``), | ||
606 | + the behavior of ``none`` synchronization mode is different. | ||
607 | + Normally, a ``backup`` job consists of two parts: Anything | ||
608 | + that is overwritten by the guest is first copied out to | ||
609 | + the backup, and in the background the whole image is | ||
610 | + copied from start to end. With ``sync=none``, it's only | ||
611 | + the first part. | ||
612 | + | ||
613 | +(4) ``incremental`` -- Synchronize content that is described by the | ||
614 | + dirty bitmap | ||
615 | + | ||
616 | +.. note:: | ||
617 | + Refer to the :doc:`bitmaps` document in the QEMU source | ||
618 | + tree to learn about the detailed workings of the ``incremental`` | ||
619 | + synchronization mode. | ||
620 | + | ||
621 | + | ||
622 | +QMP invocation for ``drive-mirror`` | ||
623 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
624 | + | ||
625 | +To copy the contents of the entire disk image chain, from [A] all the | ||
626 | +way to [D], to a new target (``drive-mirror`` will create the destination | ||
627 | +file, if it doesn't already exist), call it [E]:: | ||
628 | + | ||
629 | + (QEMU) drive-mirror device=node-D target=e.qcow2 sync=full job-id=job0 | ||
630 | + { | ||
631 | + "execute": "drive-mirror", | ||
632 | + "arguments": { | ||
633 | + "device": "node-D", | ||
634 | + "job-id": "job0", | ||
635 | + "target": "e.qcow2", | ||
636 | + "sync": "full" | ||
637 | + } | ||
638 | + } | ||
639 | + | ||
640 | +The ``"sync": "full"``, from the above, means: copy the *entire* chain | ||
641 | +to the destination. | ||
642 | + | ||
643 | +Following the above, querying for active block jobs will show that a | ||
644 | +'mirror' job is "ready" to be completed (and QEMU will also emit an | ||
645 | +event, ``BLOCK_JOB_READY``):: | ||
646 | + | ||
647 | + (QEMU) query-block-jobs | ||
648 | + { | ||
649 | + "execute": "query-block-jobs", | ||
650 | + "arguments": {} | ||
651 | + } | ||
652 | + { | ||
653 | + "return": [ | ||
654 | + { | ||
655 | + "busy": false, | ||
656 | + "type": "mirror", | ||
657 | + "len": 21757952, | ||
658 | + "paused": false, | ||
659 | + "ready": true, | ||
660 | + "io-status": "ok", | ||
661 | + "offset": 21757952, | ||
662 | + "device": "job0", | ||
663 | + "speed": 0 | ||
664 | + } | ||
665 | + ] | ||
666 | + } | ||
667 | + | ||
668 | +And, as noted in the previous section, there are two possible actions | ||
669 | +at this point: | ||
670 | + | ||
671 | +(a) Create a point-in-time snapshot by ending the synchronization. The | ||
672 | + point-in-time is at the time of *ending* the sync. (The result of | ||
673 | + the following being: the target image, [E], will be populated with | ||
674 | + content from the entire chain, [A] to [D]):: | ||
675 | + | ||
676 | + (QEMU) block-job-cancel device=job0 | ||
677 | + { | 56 | + { |
678 | + "execute": "block-job-cancel", | 57 | + ret = -EINVAL; |
679 | + "arguments": { | 58 | + goto out; |
680 | + "device": "job0" | ||
681 | + } | ||
682 | + } | 59 | + } |
683 | + | 60 | + |
684 | +(b) Or, complete the operation and pivot the live QEMU to the target | 61 | if (!extent->has_marker) { |
685 | + copy:: | 62 | ret = -EINVAL; |
686 | + | 63 | goto out; |
687 | + (QEMU) block-job-complete device=job0 | ||
688 | + | ||
689 | +In either of the above cases, if you once again run the | ||
690 | +`query-block-jobs` command, there should not be any active block | ||
691 | +operation. | ||
692 | + | ||
693 | +Comparing 'commit' and 'mirror': In both then cases, the overlay images | ||
694 | +can be discarded. However, with 'commit', the *existing* base image | ||
695 | +will be modified (by updating it with contents from overlays); while in | ||
696 | +the case of 'mirror', a *new* target image is populated with the data | ||
697 | +from the disk image chain. | ||
698 | + | ||
699 | + | ||
700 | +QMP invocation for live storage migration with ``drive-mirror`` + NBD | ||
701 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
702 | + | ||
703 | +Live storage migration (without shared storage setup) is one of the most | ||
704 | +common use-cases that takes advantage of the ``drive-mirror`` primitive | ||
705 | +and QEMU's built-in Network Block Device (NBD) server. Here's a quick | ||
706 | +walk-through of this setup. | ||
707 | + | ||
708 | +Given the disk image chain:: | ||
709 | + | ||
710 | + [A] <-- [B] <-- [C] <-- [D] | ||
711 | + | ||
712 | +Instead of copying content from the entire chain, synchronize *only* the | ||
713 | +contents of the *top*-most disk image (i.e. the active layer), [D], to a | ||
714 | +target, say, [TargetDisk]. | ||
715 | + | ||
716 | +.. important:: | ||
717 | + The destination host must already have the contents of the backing | ||
718 | + chain, involving images [A], [B], and [C], visible via other means | ||
719 | + -- whether by ``cp``, ``rsync``, or by some storage array-specific | ||
720 | + command.) | ||
721 | + | ||
722 | +Sometimes, this is also referred to as "shallow copy" -- because only | ||
723 | +the "active layer", and not the rest of the image chain, is copied to | ||
724 | +the destination. | ||
725 | + | ||
726 | +.. note:: | ||
727 | + In this example, for the sake of simplicity, we'll be using the same | ||
728 | + ``localhost`` as both source and destination. | ||
729 | + | ||
730 | +As noted earlier, on the destination host the contents of the backing | ||
731 | +chain -- from images [A] to [C] -- are already expected to exist in some | ||
732 | +form (e.g. in a file called, ``Contents-of-A-B-C.qcow2``). Now, on the | ||
733 | +destination host, let's create a target overlay image (with the image | ||
734 | +``Contents-of-A-B-C.qcow2`` as its backing file), to which the contents | ||
735 | +of image [D] (from the source QEMU) will be mirrored to:: | ||
736 | + | ||
737 | + $ qemu-img create -f qcow2 -b ./Contents-of-A-B-C.qcow2 \ | ||
738 | + -F qcow2 ./target-disk.qcow2 | ||
739 | + | ||
740 | +And start the destination QEMU (we already have the source QEMU running | ||
741 | +-- discussed in the section: `Interacting with a QEMU instance`_) | ||
742 | +instance, with the following invocation. (As noted earlier, for | ||
743 | +simplicity's sake, the destination QEMU is started on the same host, but | ||
744 | +it could be located elsewhere):: | ||
745 | + | ||
746 | + $ ./x86_64-softmmu/qemu-system-x86_64 -display none -nodefconfig \ | ||
747 | + -M q35 -nodefaults -m 512 \ | ||
748 | + -blockdev node-name=node-TargetDisk,driver=qcow2,file.driver=file,file.node-name=file,file.filename=./target-disk.qcow2 \ | ||
749 | + -device virtio-blk,drive=node-TargetDisk,id=virtio0 \ | ||
750 | + -S -monitor stdio -qmp unix:./qmp-sock2,server,nowait \ | ||
751 | + -incoming tcp:localhost:6666 | ||
752 | + | ||
753 | +Given the disk image chain on source QEMU:: | ||
754 | + | ||
755 | + [A] <-- [B] <-- [C] <-- [D] | ||
756 | + | ||
757 | +On the destination host, it is expected that the contents of the chain | ||
758 | +``[A] <-- [B] <-- [C]`` are *already* present, and therefore copy *only* | ||
759 | +the content of image [D]. | ||
760 | + | ||
761 | +(1) [On *destination* QEMU] As part of the first step, start the | ||
762 | + built-in NBD server on a given host (local host, represented by | ||
763 | + ``::``)and port:: | ||
764 | + | ||
765 | + (QEMU) nbd-server-start addr={"type":"inet","data":{"host":"::","port":"49153"}} | ||
766 | + { | ||
767 | + "execute": "nbd-server-start", | ||
768 | + "arguments": { | ||
769 | + "addr": { | ||
770 | + "data": { | ||
771 | + "host": "::", | ||
772 | + "port": "49153" | ||
773 | + }, | ||
774 | + "type": "inet" | ||
775 | + } | ||
776 | + } | ||
777 | + } | ||
778 | + | ||
779 | +(2) [On *destination* QEMU] And export the destination disk image using | ||
780 | + QEMU's built-in NBD server:: | ||
781 | + | ||
782 | + (QEMU) nbd-server-add device=node-TargetDisk writable=true | ||
783 | + { | ||
784 | + "execute": "nbd-server-add", | ||
785 | + "arguments": { | ||
786 | + "device": "node-TargetDisk" | ||
787 | + } | ||
788 | + } | ||
789 | + | ||
790 | +(3) [On *source* QEMU] Then, invoke ``drive-mirror`` (NB: since we're | ||
791 | + running ``drive-mirror`` with ``mode=existing`` (meaning: | ||
792 | + synchronize to a pre-created file, therefore 'existing', file on the | ||
793 | + target host), with the synchronization mode as 'top' (``"sync: | ||
794 | + "top"``):: | ||
795 | + | ||
796 | + (QEMU) drive-mirror device=node-D target=nbd:localhost:49153:exportname=node-TargetDisk sync=top mode=existing job-id=job0 | ||
797 | + { | ||
798 | + "execute": "drive-mirror", | ||
799 | + "arguments": { | ||
800 | + "device": "node-D", | ||
801 | + "mode": "existing", | ||
802 | + "job-id": "job0", | ||
803 | + "target": "nbd:localhost:49153:exportname=node-TargetDisk", | ||
804 | + "sync": "top" | ||
805 | + } | ||
806 | + } | ||
807 | + | ||
808 | +(4) [On *source* QEMU] Once ``drive-mirror`` copies the entire data, and the | ||
809 | + event ``BLOCK_JOB_READY`` is emitted, issue ``block-job-cancel`` to | ||
810 | + gracefully end the synchronization, from source QEMU:: | ||
811 | + | ||
812 | + (QEMU) block-job-cancel device=job0 | ||
813 | + { | ||
814 | + "execute": "block-job-cancel", | ||
815 | + "arguments": { | ||
816 | + "device": "job0" | ||
817 | + } | ||
818 | + } | ||
819 | + | ||
820 | +(5) [On *destination* QEMU] Then, stop the NBD server:: | ||
821 | + | ||
822 | + (QEMU) nbd-server-stop | ||
823 | + { | ||
824 | + "execute": "nbd-server-stop", | ||
825 | + "arguments": {} | ||
826 | + } | ||
827 | + | ||
828 | +(6) [On *destination* QEMU] Finally, resume the guest vCPUs by issuing the | ||
829 | + QMP command `cont`:: | ||
830 | + | ||
831 | + (QEMU) cont | ||
832 | + { | ||
833 | + "execute": "cont", | ||
834 | + "arguments": {} | ||
835 | + } | ||
836 | + | ||
837 | +.. note:: | ||
838 | + Higher-level libraries (e.g. libvirt) automate the entire above | ||
839 | + process (although note that libvirt does not allow same-host | ||
840 | + migrations to localhost for other reasons). | ||
841 | + | ||
842 | + | ||
843 | +Notes on ``blockdev-mirror`` | ||
844 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
845 | + | ||
846 | +The ``blockdev-mirror`` command is equivalent in core functionality to | ||
847 | +``drive-mirror``, except that it operates at node-level in a BDS graph. | ||
848 | + | ||
849 | +Also: for ``blockdev-mirror``, the 'target' image needs to be explicitly | ||
850 | +created (using ``qemu-img``) and attach it to live QEMU via | ||
851 | +``blockdev-add``, which assigns a name to the to-be created target node. | ||
852 | + | ||
853 | +E.g. the sequence of actions to create a point-in-time backup of an | ||
854 | +entire disk image chain, to a target, using ``blockdev-mirror`` would be: | ||
855 | + | ||
856 | +(0) Create the QCOW2 overlays, to arrive at a backing chain of desired | ||
857 | + depth | ||
858 | + | ||
859 | +(1) Create the target image (using ``qemu-img``), say, ``e.qcow2`` | ||
860 | + | ||
861 | +(2) Attach the above created file (``e.qcow2``), run-time, using | ||
862 | + ``blockdev-add`` to QEMU | ||
863 | + | ||
864 | +(3) Perform ``blockdev-mirror`` (use ``"sync": "full"`` to copy the | ||
865 | + entire chain to the target). And notice the event | ||
866 | + ``BLOCK_JOB_READY`` | ||
867 | + | ||
868 | +(4) Optionally, query for active block jobs, there should be a 'mirror' | ||
869 | + job ready to be completed | ||
870 | + | ||
871 | +(5) Gracefully complete the 'mirror' block device job, and notice the | ||
872 | + the event ``BLOCK_JOB_COMPLETED`` | ||
873 | + | ||
874 | +(6) Shutdown the guest by issuing the QMP ``quit`` command so that | ||
875 | + caches are flushed | ||
876 | + | ||
877 | +(7) Then, finally, compare the contents of the disk image chain, and | ||
878 | + the target copy with ``qemu-img compare``. You should notice: | ||
879 | + "Images are identical" | ||
880 | + | ||
881 | + | ||
882 | +QMP invocation for ``blockdev-mirror`` | ||
883 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
884 | + | ||
885 | +Given the disk image chain:: | ||
886 | + | ||
887 | + [A] <-- [B] <-- [C] <-- [D] | ||
888 | + | ||
889 | +To copy the contents of the entire disk image chain, from [A] all the | ||
890 | +way to [D], to a new target, call it [E]. The following is the flow. | ||
891 | + | ||
892 | +Create the overlay images, [B], [C], and [D]:: | ||
893 | + | ||
894 | + (QEMU) blockdev-snapshot-sync node-name=node-A snapshot-file=b.qcow2 snapshot-node-name=node-B format=qcow2 | ||
895 | + (QEMU) blockdev-snapshot-sync node-name=node-B snapshot-file=c.qcow2 snapshot-node-name=node-C format=qcow2 | ||
896 | + (QEMU) blockdev-snapshot-sync node-name=node-C snapshot-file=d.qcow2 snapshot-node-name=node-D format=qcow2 | ||
897 | + | ||
898 | +Create the target image, [E]:: | ||
899 | + | ||
900 | + $ qemu-img create -f qcow2 e.qcow2 39M | ||
901 | + | ||
902 | +Add the above created target image to QEMU, via ``blockdev-add``:: | ||
903 | + | ||
904 | + (QEMU) blockdev-add driver=qcow2 node-name=node-E file={"driver":"file","filename":"e.qcow2"} | ||
905 | + { | ||
906 | + "execute": "blockdev-add", | ||
907 | + "arguments": { | ||
908 | + "node-name": "node-E", | ||
909 | + "driver": "qcow2", | ||
910 | + "file": { | ||
911 | + "driver": "file", | ||
912 | + "filename": "e.qcow2" | ||
913 | + } | ||
914 | + } | ||
915 | + } | ||
916 | + | ||
917 | +Perform ``blockdev-mirror``, and notice the event ``BLOCK_JOB_READY``:: | ||
918 | + | ||
919 | + (QEMU) blockdev-mirror device=node-B target=node-E sync=full job-id=job0 | ||
920 | + { | ||
921 | + "execute": "blockdev-mirror", | ||
922 | + "arguments": { | ||
923 | + "device": "node-D", | ||
924 | + "job-id": "job0", | ||
925 | + "target": "node-E", | ||
926 | + "sync": "full" | ||
927 | + } | ||
928 | + } | ||
929 | + | ||
930 | +Query for active block jobs, there should be a 'mirror' job ready:: | ||
931 | + | ||
932 | + (QEMU) query-block-jobs | ||
933 | + { | ||
934 | + "execute": "query-block-jobs", | ||
935 | + "arguments": {} | ||
936 | + } | ||
937 | + { | ||
938 | + "return": [ | ||
939 | + { | ||
940 | + "busy": false, | ||
941 | + "type": "mirror", | ||
942 | + "len": 21561344, | ||
943 | + "paused": false, | ||
944 | + "ready": true, | ||
945 | + "io-status": "ok", | ||
946 | + "offset": 21561344, | ||
947 | + "device": "job0", | ||
948 | + "speed": 0 | ||
949 | + } | ||
950 | + ] | ||
951 | + } | ||
952 | + | ||
953 | +Gracefully complete the block device job operation, and notice the | ||
954 | +event ``BLOCK_JOB_COMPLETED``:: | ||
955 | + | ||
956 | + (QEMU) block-job-complete device=job0 | ||
957 | + { | ||
958 | + "execute": "block-job-complete", | ||
959 | + "arguments": { | ||
960 | + "device": "job0" | ||
961 | + } | ||
962 | + } | ||
963 | + { | ||
964 | + "return": {} | ||
965 | + } | ||
966 | + | ||
967 | +Shutdown the guest, by issuing the ``quit`` QMP command:: | ||
968 | + | ||
969 | + (QEMU) quit | ||
970 | + { | ||
971 | + "execute": "quit", | ||
972 | + "arguments": {} | ||
973 | + } | ||
974 | + | ||
975 | + | ||
976 | +Live disk backup --- ``drive-backup`` and ``blockdev-backup`` | ||
977 | +------------------------------------------------------------- | ||
978 | + | ||
979 | +The ``drive-backup`` (and its newer equivalent ``blockdev-backup``) allows | ||
980 | +you to create a point-in-time snapshot. | ||
981 | + | ||
982 | +In this case, the point-in-time is when you *start* the ``drive-backup`` | ||
983 | +(or its newer equivalent ``blockdev-backup``) command. | ||
984 | + | ||
985 | + | ||
986 | +QMP invocation for ``drive-backup`` | ||
987 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
988 | + | ||
989 | +Yet again, starting afresh with our example disk image chain:: | ||
990 | + | ||
991 | + [A] <-- [B] <-- [C] <-- [D] | ||
992 | + | ||
993 | +To create a target image [E], with content populated from image [A] to | ||
994 | +[D], from the above chain, the following is the syntax. (If the target | ||
995 | +image does not exist, ``drive-backup`` will create it):: | ||
996 | + | ||
997 | + (QEMU) drive-backup device=node-D sync=full target=e.qcow2 job-id=job0 | ||
998 | + { | ||
999 | + "execute": "drive-backup", | ||
1000 | + "arguments": { | ||
1001 | + "device": "node-D", | ||
1002 | + "job-id": "job0", | ||
1003 | + "sync": "full", | ||
1004 | + "target": "e.qcow2" | ||
1005 | + } | ||
1006 | + } | ||
1007 | + | ||
1008 | +Once the above ``drive-backup`` has completed, a ``BLOCK_JOB_COMPLETED`` event | ||
1009 | +will be issued, indicating the live block device job operation has | ||
1010 | +completed, and no further action is required. | ||
1011 | + | ||
1012 | + | ||
1013 | +Notes on ``blockdev-backup`` | ||
1014 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
1015 | + | ||
1016 | +The ``blockdev-backup`` command is equivalent in functionality to | ||
1017 | +``drive-backup``, except that it operates at node-level in a Block Driver | ||
1018 | +State (BDS) graph. | ||
1019 | + | ||
1020 | +E.g. the sequence of actions to create a point-in-time backup | ||
1021 | +of an entire disk image chain, to a target, using ``blockdev-backup`` | ||
1022 | +would be: | ||
1023 | + | ||
1024 | +(0) Create the QCOW2 overlays, to arrive at a backing chain of desired | ||
1025 | + depth | ||
1026 | + | ||
1027 | +(1) Create the target image (using ``qemu-img``), say, ``e.qcow2`` | ||
1028 | + | ||
1029 | +(2) Attach the above created file (``e.qcow2``), run-time, using | ||
1030 | + ``blockdev-add`` to QEMU | ||
1031 | + | ||
1032 | +(3) Perform ``blockdev-backup`` (use ``"sync": "full"`` to copy the | ||
1033 | + entire chain to the target). And notice the event | ||
1034 | + ``BLOCK_JOB_COMPLETED`` | ||
1035 | + | ||
1036 | +(4) Shutdown the guest, by issuing the QMP ``quit`` command, so that | ||
1037 | + caches are flushed | ||
1038 | + | ||
1039 | +(5) Then, finally, compare the contents of the disk image chain, and | ||
1040 | + the target copy with ``qemu-img compare``. You should notice: | ||
1041 | + "Images are identical" | ||
1042 | + | ||
1043 | +The following section shows an example QMP invocation for | ||
1044 | +``blockdev-backup``. | ||
1045 | + | ||
1046 | +QMP invocation for ``blockdev-backup`` | ||
1047 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
1048 | + | ||
1049 | +Given a disk image chain of depth 1 where image [B] is the active | ||
1050 | +overlay (live QEMU is writing to it):: | ||
1051 | + | ||
1052 | + [A] <-- [B] | ||
1053 | + | ||
1054 | +The following is the procedure to copy the content from the entire chain | ||
1055 | +to a target image (say, [E]), which has the full content from [A] and | ||
1056 | +[B]. | ||
1057 | + | ||
1058 | +Create the overlay [B]:: | ||
1059 | + | ||
1060 | + (QEMU) blockdev-snapshot-sync node-name=node-A snapshot-file=b.qcow2 snapshot-node-name=node-B format=qcow2 | ||
1061 | + { | ||
1062 | + "execute": "blockdev-snapshot-sync", | ||
1063 | + "arguments": { | ||
1064 | + "node-name": "node-A", | ||
1065 | + "snapshot-file": "b.qcow2", | ||
1066 | + "format": "qcow2", | ||
1067 | + "snapshot-node-name": "node-B" | ||
1068 | + } | ||
1069 | + } | ||
1070 | + | ||
1071 | + | ||
1072 | +Create a target image that will contain the copy:: | ||
1073 | + | ||
1074 | + $ qemu-img create -f qcow2 e.qcow2 39M | ||
1075 | + | ||
1076 | +Then add it to QEMU via ``blockdev-add``:: | ||
1077 | + | ||
1078 | + (QEMU) blockdev-add driver=qcow2 node-name=node-E file={"driver":"file","filename":"e.qcow2"} | ||
1079 | + { | ||
1080 | + "execute": "blockdev-add", | ||
1081 | + "arguments": { | ||
1082 | + "node-name": "node-E", | ||
1083 | + "driver": "qcow2", | ||
1084 | + "file": { | ||
1085 | + "driver": "file", | ||
1086 | + "filename": "e.qcow2" | ||
1087 | + } | ||
1088 | + } | ||
1089 | + } | ||
1090 | + | ||
1091 | +Then invoke ``blockdev-backup`` to copy the contents from the entire | ||
1092 | +image chain, consisting of images [A] and [B] to the target image | ||
1093 | +'e.qcow2':: | ||
1094 | + | ||
1095 | + (QEMU) blockdev-backup device=node-B target=node-E sync=full job-id=job0 | ||
1096 | + { | ||
1097 | + "execute": "blockdev-backup", | ||
1098 | + "arguments": { | ||
1099 | + "device": "node-B", | ||
1100 | + "job-id": "job0", | ||
1101 | + "target": "node-E", | ||
1102 | + "sync": "full" | ||
1103 | + } | ||
1104 | + } | ||
1105 | + | ||
1106 | +Once the above 'backup' operation has completed, the event, | ||
1107 | +``BLOCK_JOB_COMPLETED`` will be emitted, signalling successful | ||
1108 | +completion. | ||
1109 | + | ||
1110 | +Next, query for any active block device jobs (there should be none):: | ||
1111 | + | ||
1112 | + (QEMU) query-block-jobs | ||
1113 | + { | ||
1114 | + "execute": "query-block-jobs", | ||
1115 | + "arguments": {} | ||
1116 | + } | ||
1117 | + | ||
1118 | +Shutdown the guest:: | ||
1119 | + | ||
1120 | + (QEMU) quit | ||
1121 | + { | ||
1122 | + "execute": "quit", | ||
1123 | + "arguments": {} | ||
1124 | + } | ||
1125 | + "return": {} | ||
1126 | + } | ||
1127 | + | ||
1128 | +.. note:: | ||
1129 | + The above step is really important; if forgotten, an error, "Failed | ||
1130 | + to get shared "write" lock on e.qcow2", will be thrown when you do | ||
1131 | + ``qemu-img compare`` to verify the integrity of the disk image | ||
1132 | + with the backup content. | ||
1133 | + | ||
1134 | + | ||
1135 | +The end result will be the image 'e.qcow2' containing a | ||
1136 | +point-in-time backup of the disk image chain -- i.e. contents from | ||
1137 | +images [A] and [B] at the time the ``blockdev-backup`` command was | ||
1138 | +initiated. | ||
1139 | + | ||
1140 | +One way to confirm the backup disk image contains the identical content | ||
1141 | +with the disk image chain is to compare the backup and the contents of | ||
1142 | +the chain, you should see "Images are identical". (NB: this is assuming | ||
1143 | +QEMU was launched with ``-S`` option, which will not start the CPUs at | ||
1144 | +guest boot up):: | ||
1145 | + | ||
1146 | + $ qemu-img compare b.qcow2 e.qcow2 | ||
1147 | + Warning: Image size mismatch! | ||
1148 | + Images are identical. | ||
1149 | + | ||
1150 | +NOTE: The "Warning: Image size mismatch!" is expected, as we created the | ||
1151 | +target image (e.qcow2) with 39M size. | ||
1152 | diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt | ||
1153 | deleted file mode 100644 | ||
1154 | index XXXXXXX..XXXXXXX | ||
1155 | --- a/docs/live-block-ops.txt | ||
1156 | +++ /dev/null | ||
1157 | @@ -XXX,XX +XXX,XX @@ | ||
1158 | -LIVE BLOCK OPERATIONS | ||
1159 | -===================== | ||
1160 | - | ||
1161 | -High level description of live block operations. Note these are not | ||
1162 | -supported for use with the raw format at the moment. | ||
1163 | - | ||
1164 | -Note also that this document is incomplete and it currently only | ||
1165 | -covers the 'stream' operation. Other operations supported by QEMU such | ||
1166 | -as 'commit', 'mirror' and 'backup' are not described here yet. Please | ||
1167 | -refer to the qapi/block-core.json file for an overview of those. | ||
1168 | - | ||
1169 | -Snapshot live merge | ||
1170 | -=================== | ||
1171 | - | ||
1172 | -Given a snapshot chain, described in this document in the following | ||
1173 | -format: | ||
1174 | - | ||
1175 | -[A] <- [B] <- [C] <- [D] <- [E] | ||
1176 | - | ||
1177 | -Where the rightmost object ([E] in the example) described is the current | ||
1178 | -image which the guest OS has write access to. To the left of it is its base | ||
1179 | -image, and so on accordingly until the leftmost image, which has no | ||
1180 | -base. | ||
1181 | - | ||
1182 | -The snapshot live merge operation transforms such a chain into a | ||
1183 | -smaller one with fewer elements, such as this transformation relative | ||
1184 | -to the first example: | ||
1185 | - | ||
1186 | -[A] <- [E] | ||
1187 | - | ||
1188 | -Data is copied in the right direction with destination being the | ||
1189 | -rightmost image, but any other intermediate image can be specified | ||
1190 | -instead. In this example data is copied from [C] into [D], so [D] can | ||
1191 | -be backed by [B]: | ||
1192 | - | ||
1193 | -[A] <- [B] <- [D] <- [E] | ||
1194 | - | ||
1195 | -The operation is implemented in QEMU through image streaming facilities. | ||
1196 | - | ||
1197 | -The basic idea is to execute 'block_stream virtio0' while the guest is | ||
1198 | -running. Progress can be monitored using 'info block-jobs'. When the | ||
1199 | -streaming operation completes it raises a QMP event. 'block_stream' | ||
1200 | -copies data from the backing file(s) into the active image. When finished, | ||
1201 | -it adjusts the backing file pointer. | ||
1202 | - | ||
1203 | -The 'base' parameter specifies an image which data need not be | ||
1204 | -streamed from. This image will be used as the backing file for the | ||
1205 | -destination image when the operation is finished. | ||
1206 | - | ||
1207 | -In the first example above, the command would be: | ||
1208 | - | ||
1209 | -(qemu) block_stream virtio0 file-A.img | ||
1210 | - | ||
1211 | -In order to specify a destination image different from the active | ||
1212 | -(rightmost) one we can use its node name instead. | ||
1213 | - | ||
1214 | -In the second example above, the command would be: | ||
1215 | - | ||
1216 | -(qemu) block_stream node-D file-B.img | ||
1217 | - | ||
1218 | -Live block copy | ||
1219 | -=============== | ||
1220 | - | ||
1221 | -To copy an in use image to another destination in the filesystem, one | ||
1222 | -should create a live snapshot in the desired destination, then stream | ||
1223 | -into that image. Example: | ||
1224 | - | ||
1225 | -(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img qcow2 | ||
1226 | - | ||
1227 | -(qemu) block_stream ide0-hd0 | ||
1228 | - | ||
1229 | - | ||
1230 | -- | 64 | -- |
1231 | 2.9.4 | 65 | 2.21.0 |
1232 | 66 | ||
1233 | 67 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | streamOptimized does not support writes that do not span exactly one | ||
2 | cluster. Furthermore, it cannot rewrite already allocated clusters. | ||
3 | As such, many iotests do not work with it. Disable them. | ||
1 | 4 | ||
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
6 | Message-id: 20190815153638.4600-6-mreitz@redhat.com | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/002 | 1 + | ||
11 | tests/qemu-iotests/003 | 1 + | ||
12 | tests/qemu-iotests/005 | 3 ++- | ||
13 | tests/qemu-iotests/009 | 1 + | ||
14 | tests/qemu-iotests/010 | 1 + | ||
15 | tests/qemu-iotests/011 | 1 + | ||
16 | tests/qemu-iotests/017 | 3 ++- | ||
17 | tests/qemu-iotests/018 | 3 ++- | ||
18 | tests/qemu-iotests/019 | 3 ++- | ||
19 | tests/qemu-iotests/020 | 3 ++- | ||
20 | tests/qemu-iotests/027 | 1 + | ||
21 | tests/qemu-iotests/032 | 1 + | ||
22 | tests/qemu-iotests/033 | 1 + | ||
23 | tests/qemu-iotests/034 | 3 ++- | ||
24 | tests/qemu-iotests/037 | 3 ++- | ||
25 | tests/qemu-iotests/063 | 3 ++- | ||
26 | tests/qemu-iotests/072 | 1 + | ||
27 | tests/qemu-iotests/105 | 3 ++- | ||
28 | tests/qemu-iotests/197 | 1 + | ||
29 | tests/qemu-iotests/215 | 1 + | ||
30 | tests/qemu-iotests/251 | 1 + | ||
31 | 21 files changed, 30 insertions(+), 9 deletions(-) | ||
32 | |||
33 | diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002 | ||
34 | index XXXXXXX..XXXXXXX 100755 | ||
35 | --- a/tests/qemu-iotests/002 | ||
36 | +++ b/tests/qemu-iotests/002 | ||
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
38 | |||
39 | _supported_fmt generic | ||
40 | _supported_proto generic | ||
41 | +_unsupported_imgopts "subformat=streamOptimized" | ||
42 | |||
43 | |||
44 | size=128M | ||
45 | diff --git a/tests/qemu-iotests/003 b/tests/qemu-iotests/003 | ||
46 | index XXXXXXX..XXXXXXX 100755 | ||
47 | --- a/tests/qemu-iotests/003 | ||
48 | +++ b/tests/qemu-iotests/003 | ||
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
50 | |||
51 | _supported_fmt generic | ||
52 | _supported_proto generic | ||
53 | +_unsupported_imgopts "subformat=streamOptimized" | ||
54 | |||
55 | size=128M | ||
56 | offset=67M | ||
57 | diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005 | ||
58 | index XXXXXXX..XXXXXXX 100755 | ||
59 | --- a/tests/qemu-iotests/005 | ||
60 | +++ b/tests/qemu-iotests/005 | ||
61 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
62 | _supported_proto generic | ||
63 | _supported_os Linux | ||
64 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
65 | - "subformat=twoGbMaxExtentSparse" | ||
66 | + "subformat=twoGbMaxExtentSparse" \ | ||
67 | + "subformat=streamOptimized" | ||
68 | |||
69 | # vpc is limited to 127GB, so we can't test it here | ||
70 | if [ "$IMGFMT" = "vpc" ]; then | ||
71 | diff --git a/tests/qemu-iotests/009 b/tests/qemu-iotests/009 | ||
72 | index XXXXXXX..XXXXXXX 100755 | ||
73 | --- a/tests/qemu-iotests/009 | ||
74 | +++ b/tests/qemu-iotests/009 | ||
75 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
76 | |||
77 | _supported_fmt generic | ||
78 | _supported_proto generic | ||
79 | +_unsupported_imgopts "subformat=streamOptimized" | ||
80 | |||
81 | |||
82 | size=6G | ||
83 | diff --git a/tests/qemu-iotests/010 b/tests/qemu-iotests/010 | ||
84 | index XXXXXXX..XXXXXXX 100755 | ||
85 | --- a/tests/qemu-iotests/010 | ||
86 | +++ b/tests/qemu-iotests/010 | ||
87 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
88 | |||
89 | _supported_fmt generic | ||
90 | _supported_proto generic | ||
91 | +_unsupported_imgopts "subformat=streamOptimized" | ||
92 | |||
93 | |||
94 | size=6G | ||
95 | diff --git a/tests/qemu-iotests/011 b/tests/qemu-iotests/011 | ||
96 | index XXXXXXX..XXXXXXX 100755 | ||
97 | --- a/tests/qemu-iotests/011 | ||
98 | +++ b/tests/qemu-iotests/011 | ||
99 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
100 | |||
101 | _supported_fmt generic | ||
102 | _supported_proto generic | ||
103 | +_unsupported_imgopts "subformat=streamOptimized" | ||
104 | |||
105 | |||
106 | size=6G | ||
107 | diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017 | ||
108 | index XXXXXXX..XXXXXXX 100755 | ||
109 | --- a/tests/qemu-iotests/017 | ||
110 | +++ b/tests/qemu-iotests/017 | ||
111 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
112 | _supported_fmt qcow qcow2 vmdk qed | ||
113 | _supported_proto generic | ||
114 | _unsupported_proto vxhs | ||
115 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
116 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
117 | + "subformat=streamOptimized" | ||
118 | |||
119 | TEST_OFFSETS="0 4294967296" | ||
120 | |||
121 | diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018 | ||
122 | index XXXXXXX..XXXXXXX 100755 | ||
123 | --- a/tests/qemu-iotests/018 | ||
124 | +++ b/tests/qemu-iotests/018 | ||
125 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
126 | _supported_fmt qcow qcow2 vmdk qed | ||
127 | _supported_proto file | ||
128 | _supported_os Linux | ||
129 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
130 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
131 | + "streamOptimized" | ||
132 | |||
133 | TEST_OFFSETS="0 4294967296" | ||
134 | |||
135 | diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019 | ||
136 | index XXXXXXX..XXXXXXX 100755 | ||
137 | --- a/tests/qemu-iotests/019 | ||
138 | +++ b/tests/qemu-iotests/019 | ||
139 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
140 | _supported_os Linux | ||
141 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
142 | "subformat=twoGbMaxExtentFlat" \ | ||
143 | - "subformat=twoGbMaxExtentSparse" | ||
144 | + "subformat=twoGbMaxExtentSparse" \ | ||
145 | + "subformat=streamOptimized" | ||
146 | |||
147 | TEST_OFFSETS="0 4294967296" | ||
148 | CLUSTER_SIZE=65536 | ||
149 | diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020 | ||
150 | index XXXXXXX..XXXXXXX 100755 | ||
151 | --- a/tests/qemu-iotests/020 | ||
152 | +++ b/tests/qemu-iotests/020 | ||
153 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
154 | _supported_proto file | ||
155 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
156 | "subformat=twoGbMaxExtentFlat" \ | ||
157 | - "subformat=twoGbMaxExtentSparse" | ||
158 | + "subformat=twoGbMaxExtentSparse" \ | ||
159 | + "subformat=streamOptimized" | ||
160 | |||
161 | TEST_OFFSETS="0 4294967296" | ||
162 | |||
163 | diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027 | ||
164 | index XXXXXXX..XXXXXXX 100755 | ||
165 | --- a/tests/qemu-iotests/027 | ||
166 | +++ b/tests/qemu-iotests/027 | ||
167 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
168 | |||
169 | _supported_fmt vmdk qcow qcow2 qed | ||
170 | _supported_proto generic | ||
171 | +_unsupported_imgopts "subformat=streamOptimized" | ||
172 | |||
173 | |||
174 | size=128M | ||
175 | diff --git a/tests/qemu-iotests/032 b/tests/qemu-iotests/032 | ||
176 | index XXXXXXX..XXXXXXX 100755 | ||
177 | --- a/tests/qemu-iotests/032 | ||
178 | +++ b/tests/qemu-iotests/032 | ||
179 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
180 | # This works for any image format (though unlikely to segfault for raw) | ||
181 | _supported_fmt generic | ||
182 | _supported_proto generic | ||
183 | +_unsupported_imgopts "subformat=streamOptimized" | ||
184 | |||
185 | echo | ||
186 | echo === Prepare image === | ||
187 | diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 | ||
188 | index XXXXXXX..XXXXXXX 100755 | ||
189 | --- a/tests/qemu-iotests/033 | ||
190 | +++ b/tests/qemu-iotests/033 | ||
191 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
192 | |||
193 | _supported_fmt generic | ||
194 | _supported_proto generic | ||
195 | +_unsupported_imgopts "subformat=streamOptimized" | ||
196 | |||
197 | |||
198 | size=128M | ||
199 | diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034 | ||
200 | index XXXXXXX..XXXXXXX 100755 | ||
201 | --- a/tests/qemu-iotests/034 | ||
202 | +++ b/tests/qemu-iotests/034 | ||
203 | @@ -XXX,XX +XXX,XX @@ _supported_proto file | ||
204 | _supported_os Linux | ||
205 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
206 | "subformat=twoGbMaxExtentFlat" \ | ||
207 | - "subformat=twoGbMaxExtentSparse" | ||
208 | + "subformat=twoGbMaxExtentSparse" \ | ||
209 | + "subformat=streamOptimized" | ||
210 | |||
211 | CLUSTER_SIZE=4k | ||
212 | size=128M | ||
213 | diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037 | ||
214 | index XXXXXXX..XXXXXXX 100755 | ||
215 | --- a/tests/qemu-iotests/037 | ||
216 | +++ b/tests/qemu-iotests/037 | ||
217 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed | ||
218 | _supported_proto file | ||
219 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
220 | "subformat=twoGbMaxExtentFlat" \ | ||
221 | - "subformat=twoGbMaxExtentSparse" | ||
222 | + "subformat=twoGbMaxExtentSparse" \ | ||
223 | + "subformat=streamOptimized" | ||
224 | |||
225 | CLUSTER_SIZE=4k | ||
226 | size=128M | ||
227 | diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063 | ||
228 | index XXXXXXX..XXXXXXX 100755 | ||
229 | --- a/tests/qemu-iotests/063 | ||
230 | +++ b/tests/qemu-iotests/063 | ||
231 | @@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed raw | ||
232 | _supported_proto file | ||
233 | _unsupported_imgopts "subformat=monolithicFlat" \ | ||
234 | "subformat=twoGbMaxExtentFlat" \ | ||
235 | - "subformat=twoGbMaxExtentSparse" | ||
236 | + "subformat=twoGbMaxExtentSparse" \ | ||
237 | + "subformat=streamOptimized" | ||
238 | |||
239 | _make_test_img 4M | ||
240 | |||
241 | diff --git a/tests/qemu-iotests/072 b/tests/qemu-iotests/072 | ||
242 | index XXXXXXX..XXXXXXX 100755 | ||
243 | --- a/tests/qemu-iotests/072 | ||
244 | +++ b/tests/qemu-iotests/072 | ||
245 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
246 | |||
247 | _supported_fmt vpc vmdk vhdx vdi qed qcow2 qcow | ||
248 | _supported_proto file | ||
249 | +_unsupported_imgopts "subformat=streamOptimized" | ||
250 | |||
251 | IMG_SIZE=64M | ||
252 | |||
253 | diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105 | ||
254 | index XXXXXXX..XXXXXXX 100755 | ||
255 | --- a/tests/qemu-iotests/105 | ||
256 | +++ b/tests/qemu-iotests/105 | ||
257 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
258 | _supported_fmt qcow2 vmdk vhdx qed | ||
259 | _supported_proto generic | ||
260 | _unsupported_imgopts "subformat=twoGbMaxExtentFlat" \ | ||
261 | - "subformat=twoGbMaxExtentSparse" | ||
262 | + "subformat=twoGbMaxExtentSparse" \ | ||
263 | + "subformat=streamOptimized" | ||
264 | |||
265 | echo | ||
266 | echo "creating large image" | ||
267 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 | ||
268 | index XXXXXXX..XXXXXXX 100755 | ||
269 | --- a/tests/qemu-iotests/197 | ||
270 | +++ b/tests/qemu-iotests/197 | ||
271 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
272 | _supported_proto generic | ||
273 | # LUKS support may be possible, but it complicates things. | ||
274 | _unsupported_fmt luks | ||
275 | +_unsupported_imgopts "subformat=streamOptimized" | ||
276 | |||
277 | echo | ||
278 | echo '=== Copy-on-read ===' | ||
279 | diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215 | ||
280 | index XXXXXXX..XXXXXXX 100755 | ||
281 | --- a/tests/qemu-iotests/215 | ||
282 | +++ b/tests/qemu-iotests/215 | ||
283 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
284 | _supported_proto generic | ||
285 | # LUKS support may be possible, but it complicates things. | ||
286 | _unsupported_fmt luks | ||
287 | +_unsupported_imgopts "subformat=streamOptimized" | ||
288 | |||
289 | echo | ||
290 | echo '=== Copy-on-read ===' | ||
291 | diff --git a/tests/qemu-iotests/251 b/tests/qemu-iotests/251 | ||
292 | index XXXXXXX..XXXXXXX 100755 | ||
293 | --- a/tests/qemu-iotests/251 | ||
294 | +++ b/tests/qemu-iotests/251 | ||
295 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
296 | _supported_fmt generic | ||
297 | _supported_proto file | ||
298 | _supported_os Linux | ||
299 | +_unsupported_imgopts "subformat=streamOptimized" | ||
300 | |||
301 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
302 | # We use json:{} filenames here, so we cannot work with additional options. | ||
303 | -- | ||
304 | 2.21.0 | ||
305 | |||
306 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The error message for the test case where we have a quorum node for | ||
2 | which no directory name can be generated is different: For | ||
3 | twoGbMaxExtentSparse, it complains that it cannot open the extent file. | ||
4 | For other (sub)formats, it just notes that it cannot determine the | ||
5 | backing file path. Both are fine, but just disable twoGbMaxExtentSparse | ||
6 | for simplicity's sake. | ||
1 | 7 | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Message-id: 20190815153638.4600-7-mreitz@redhat.com | ||
11 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/110 | 3 ++- | ||
15 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/110 | ||
20 | +++ b/tests/qemu-iotests/110 | ||
21 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
22 | # Any format supporting backing files | ||
23 | _supported_fmt qed qcow qcow2 vmdk | ||
24 | _supported_proto file | ||
25 | -_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" | ||
26 | +_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
27 | + "subformat=twoGbMaxExtentSparse" | ||
28 | |||
29 | TEST_IMG_REL=$(basename "$TEST_IMG") | ||
30 | |||
31 | -- | ||
32 | 2.21.0 | ||
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | iotest 126 requires backing file support, which flat vmdks cannot offer. | ||
2 | Skip this test for such subformats. | ||
1 | 3 | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
5 | Message-id: 20190815153638.4600-8-mreitz@redhat.com | ||
6 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
8 | --- | ||
9 | tests/qemu-iotests/126 | 2 ++ | ||
10 | 1 file changed, 2 insertions(+) | ||
11 | |||
12 | diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126 | ||
13 | index XXXXXXX..XXXXXXX 100755 | ||
14 | --- a/tests/qemu-iotests/126 | ||
15 | +++ b/tests/qemu-iotests/126 | ||
16 | @@ -XXX,XX +XXX,XX @@ status=1 # failure is the default! | ||
17 | |||
18 | # Needs backing file support | ||
19 | _supported_fmt qcow qcow2 qed vmdk | ||
20 | +_unsupported_imgopts "subformat=monolithicFlat" \ | ||
21 | + "subformat=twoGbMaxExtentFlat" | ||
22 | # This is the default protocol (and we want to test the difference between | ||
23 | # colons which separate a protocol prefix from the rest and colons which are | ||
24 | # just part of the filename, so we cannot test protocols which require a prefix) | ||
25 | -- | ||
26 | 2.21.0 | ||
27 | |||
28 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Stefan Hajnoczi <stefanha@redhat.com> | ||
1 | 2 | ||
3 | Fixes: a6b257a08e3d72219f03e461a52152672fec0612 | ||
4 | ("file-posix: Handle undetectable alignment") | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Message-id: 20190827101328.4062-1-stefanha@redhat.com | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | block/file-posix.c | 2 +- | ||
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/block/file-posix.c | ||
16 | +++ b/block/file-posix.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp) | ||
18 | for (i = 0; i < ARRAY_SIZE(alignments); i++) { | ||
19 | align = alignments[i]; | ||
20 | if (raw_is_io_aligned(fd, buf + align, max_align)) { | ||
21 | - /* Fallback to request_aligment. */ | ||
22 | + /* Fallback to request_alignment. */ | ||
23 | s->buf_align = (align != 1) ? align : bs->bl.request_alignment; | ||
24 | break; | ||
25 | } | ||
26 | -- | ||
27 | 2.21.0 | ||
28 | |||
29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | It is possible to enable only a subset of the block drivers with the | ||
4 | "--block-drv-rw-whitelist" option of the "configure" script. All other | ||
5 | drivers are marked as unusable (or only included as read-only with the | ||
6 | "--block-drv-ro-whitelist" option). If an iotest is now using such a | ||
7 | disabled block driver, it is failing - which is bad, since at least the | ||
8 | tests in the "auto" group should be able to deal with this situation. | ||
9 | Thus let's introduce a "_require_drivers" function that can be used by | ||
10 | the shell tests to check for the availability of certain drivers first, | ||
11 | and marks the test as "not run" if one of the drivers is missing. | ||
12 | |||
13 | This patch mainly targets the test in the "auto" group which should | ||
14 | never fail in such a case, but also improves some of the other tests | ||
15 | along the way. Note that we also assume that the "qcow2" and "file" | ||
16 | drivers are always available - otherwise it does not make sense to | ||
17 | run "make check-block" at all (which only tests with qcow2 by default). | ||
18 | |||
19 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
20 | Message-id: 20190823133552.11680-1-thuth@redhat.com | ||
21 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
22 | --- | ||
23 | tests/qemu-iotests/071 | 1 + | ||
24 | tests/qemu-iotests/081 | 4 +--- | ||
25 | tests/qemu-iotests/099 | 1 + | ||
26 | tests/qemu-iotests/120 | 1 + | ||
27 | tests/qemu-iotests/162 | 4 +--- | ||
28 | tests/qemu-iotests/184 | 1 + | ||
29 | tests/qemu-iotests/186 | 1 + | ||
30 | tests/qemu-iotests/common.rc | 14 ++++++++++++++ | ||
31 | 8 files changed, 21 insertions(+), 6 deletions(-) | ||
32 | |||
33 | diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071 | ||
34 | index XXXXXXX..XXXXXXX 100755 | ||
35 | --- a/tests/qemu-iotests/071 | ||
36 | +++ b/tests/qemu-iotests/071 | ||
37 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
38 | |||
39 | _supported_fmt qcow2 | ||
40 | _supported_proto file | ||
41 | +_require_drivers blkdebug blkverify | ||
42 | |||
43 | do_run_qemu() | ||
44 | { | ||
45 | diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081 | ||
46 | index XXXXXXX..XXXXXXX 100755 | ||
47 | --- a/tests/qemu-iotests/081 | ||
48 | +++ b/tests/qemu-iotests/081 | ||
49 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
50 | _supported_fmt raw | ||
51 | _supported_proto file | ||
52 | _supported_os Linux | ||
53 | +_require_drivers quorum | ||
54 | |||
55 | do_run_qemu() | ||
56 | { | ||
57 | @@ -XXX,XX +XXX,XX @@ run_qemu() | ||
58 | | _filter_qemu_io | _filter_generated_node_ids | ||
59 | } | ||
60 | |||
61 | -test_quorum=$($QEMU_IMG --help|grep quorum) | ||
62 | -[ "$test_quorum" = "" ] && _supported_fmt quorum | ||
63 | - | ||
64 | quorum="driver=raw,file.driver=quorum,file.vote-threshold=2" | ||
65 | quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" | ||
66 | quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" | ||
67 | diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099 | ||
68 | index XXXXXXX..XXXXXXX 100755 | ||
69 | --- a/tests/qemu-iotests/099 | ||
70 | +++ b/tests/qemu-iotests/099 | ||
71 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
72 | _supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc | ||
73 | _supported_proto file | ||
74 | _supported_os Linux | ||
75 | +_require_drivers blkdebug blkverify | ||
76 | _unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \ | ||
77 | "subformat=twoGbMaxExtentSparse" | ||
78 | |||
79 | diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120 | ||
80 | index XXXXXXX..XXXXXXX 100755 | ||
81 | --- a/tests/qemu-iotests/120 | ||
82 | +++ b/tests/qemu-iotests/120 | ||
83 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
84 | _supported_fmt generic | ||
85 | _supported_proto file | ||
86 | _unsupported_fmt luks | ||
87 | +_require_drivers raw | ||
88 | |||
89 | _make_test_img 64M | ||
90 | |||
91 | diff --git a/tests/qemu-iotests/162 b/tests/qemu-iotests/162 | ||
92 | index XXXXXXX..XXXXXXX 100755 | ||
93 | --- a/tests/qemu-iotests/162 | ||
94 | +++ b/tests/qemu-iotests/162 | ||
95 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
96 | . ./common.filter | ||
97 | |||
98 | _supported_fmt generic | ||
99 | - | ||
100 | -test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)') | ||
101 | -[ "$test_ssh" = "" ] && _notrun "ssh support required" | ||
102 | +_require_drivers ssh | ||
103 | |||
104 | echo | ||
105 | echo '=== NBD ===' | ||
106 | diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184 | ||
107 | index XXXXXXX..XXXXXXX 100755 | ||
108 | --- a/tests/qemu-iotests/184 | ||
109 | +++ b/tests/qemu-iotests/184 | ||
110 | @@ -XXX,XX +XXX,XX @@ trap "exit \$status" 0 1 2 3 15 | ||
111 | . ./common.filter | ||
112 | |||
113 | _supported_os Linux | ||
114 | +_require_drivers throttle | ||
115 | |||
116 | do_run_qemu() | ||
117 | { | ||
118 | diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186 | ||
119 | index XXXXXXX..XXXXXXX 100755 | ||
120 | --- a/tests/qemu-iotests/186 | ||
121 | +++ b/tests/qemu-iotests/186 | ||
122 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
123 | |||
124 | _supported_fmt qcow2 | ||
125 | _supported_proto file | ||
126 | +_require_drivers null-co | ||
127 | |||
128 | if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then | ||
129 | _notrun "Requires a PC machine" | ||
130 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/tests/qemu-iotests/common.rc | ||
133 | +++ b/tests/qemu-iotests/common.rc | ||
134 | @@ -XXX,XX +XXX,XX @@ _require_command() | ||
135 | [ -x "$c" ] || _notrun "$1 utility required, skipped this test" | ||
136 | } | ||
137 | |||
138 | +# Check that a set of drivers has been whitelisted in the QEMU binary | ||
139 | +# | ||
140 | +_require_drivers() | ||
141 | +{ | ||
142 | + available=$($QEMU -drive format=help | \ | ||
143 | + sed -e '/Supported formats:/!d' -e 's/Supported formats://') | ||
144 | + for driver | ||
145 | + do | ||
146 | + if ! echo "$available" | grep -q " $driver\( \|$\)"; then | ||
147 | + _notrun "$driver not available" | ||
148 | + fi | ||
149 | + done | ||
150 | +} | ||
151 | + | ||
152 | # make sure this script returns success | ||
153 | true | ||
154 | -- | ||
155 | 2.21.0 | ||
156 | |||
157 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | The sanitizers (especially the address sanitizer from Clang) are | ||
4 | sometimes printing out warnings or false positives - this spoils | ||
5 | the output of the iotests, causing some of the tests to fail. | ||
6 | Thus let's skip the automatic iotests during "make check" when the | ||
7 | user configured QEMU with --enable-sanitizers. | ||
8 | |||
9 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
10 | Message-id: 20190823084203.29734-1-thuth@redhat.com | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
12 | --- | ||
13 | tests/check-block.sh | 5 +++++ | ||
14 | 1 file changed, 5 insertions(+) | ||
15 | |||
16 | diff --git a/tests/check-block.sh b/tests/check-block.sh | ||
17 | index XXXXXXX..XXXXXXX 100755 | ||
18 | --- a/tests/check-block.sh | ||
19 | +++ b/tests/check-block.sh | ||
20 | @@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then | ||
21 | exit 0 | ||
22 | fi | ||
23 | |||
24 | +if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then | ||
25 | + echo "Sanitizers are enabled ==> Not running the qemu-iotests." | ||
26 | + exit 0 | ||
27 | +fi | ||
28 | + | ||
29 | if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then | ||
30 | echo "No qemu-system binary available ==> Not running the qemu-iotests." | ||
31 | exit 0 | ||
32 | -- | ||
33 | 2.21.0 | ||
34 | |||
35 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Nir Soffer <nirsof@gmail.com> | ||
1 | 2 | ||
3 | Quoting cache mode is not needed, and most tests use unquoted values. | ||
4 | Unify all test to use the same style. | ||
5 | |||
6 | Message-id: 20190827173432.7656-1-nsoffer@redhat.com | ||
7 | Signed-off-by: Nir Soffer <nsoffer@redhat.com> | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/026 | 4 ++-- | ||
11 | tests/qemu-iotests/039 | 4 ++-- | ||
12 | tests/qemu-iotests/052 | 2 +- | ||
13 | tests/qemu-iotests/091 | 4 ++-- | ||
14 | 4 files changed, 7 insertions(+), 7 deletions(-) | ||
15 | |||
16 | diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026 | ||
17 | index XXXXXXX..XXXXXXX 100755 | ||
18 | --- a/tests/qemu-iotests/026 | ||
19 | +++ b/tests/qemu-iotests/026 | ||
20 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
21 | # Currently only qcow2 supports rebasing | ||
22 | _supported_fmt qcow2 | ||
23 | _supported_proto file | ||
24 | -_default_cache_mode "writethrough" | ||
25 | -_supported_cache_modes "writethrough" "none" | ||
26 | +_default_cache_mode writethrough | ||
27 | +_supported_cache_modes writethrough none | ||
28 | # The refcount table tests expect a certain minimum width for refcount entries | ||
29 | # (so that the refcount table actually needs to grow); that minimum is 16 bits, | ||
30 | # being the default refcount entry width. | ||
31 | diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039 | ||
32 | index XXXXXXX..XXXXXXX 100755 | ||
33 | --- a/tests/qemu-iotests/039 | ||
34 | +++ b/tests/qemu-iotests/039 | ||
35 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
36 | _supported_fmt qcow2 | ||
37 | _supported_proto file | ||
38 | _supported_os Linux | ||
39 | -_default_cache_mode "writethrough" | ||
40 | -_supported_cache_modes "writethrough" | ||
41 | +_default_cache_mode writethrough | ||
42 | +_supported_cache_modes writethrough | ||
43 | |||
44 | size=128M | ||
45 | |||
46 | diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052 | ||
47 | index XXXXXXX..XXXXXXX 100755 | ||
48 | --- a/tests/qemu-iotests/052 | ||
49 | +++ b/tests/qemu-iotests/052 | ||
50 | @@ -XXX,XX +XXX,XX @@ _supported_fmt generic | ||
51 | _supported_proto file | ||
52 | |||
53 | # Don't do O_DIRECT on tmpfs | ||
54 | -_supported_cache_modes "writeback" "writethrough" "unsafe" | ||
55 | +_supported_cache_modes writeback writethrough unsafe | ||
56 | |||
57 | size=128M | ||
58 | _make_test_img $size | ||
59 | diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091 | ||
60 | index XXXXXXX..XXXXXXX 100755 | ||
61 | --- a/tests/qemu-iotests/091 | ||
62 | +++ b/tests/qemu-iotests/091 | ||
63 | @@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
64 | _supported_fmt qcow2 | ||
65 | _supported_proto file | ||
66 | _supported_os Linux | ||
67 | -_default_cache_mode "none" | ||
68 | -_supported_cache_modes "writethrough" "none" "writeback" | ||
69 | +_default_cache_mode none | ||
70 | +_supported_cache_modes writethrough none writeback | ||
71 | |||
72 | size=1G | ||
73 | |||
74 | -- | ||
75 | 2.21.0 | ||
76 | |||
77 | diff view generated by jsdifflib |