1
The following changes since commit 718d7f4f9cf772e5784093d8e6085680a235acdb:
1
The following changes since commit 07f426c35eddd79388a23d11cb278600d7e3831d:
2
2
3
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2017-07-18 13:09:51 +0100)
3
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180926' into staging (2018-09-28 18:56:09 +0100)
4
4
5
are available in the git repository at:
5
are available in the git repository at:
6
6
7
8
git://repo.or.cz/qemu/kevin.git tags/for-upstream
7
git://repo.or.cz/qemu/kevin.git tags/for-upstream
9
8
10
for you to fetch changes up to 6e6e55f5c2e5b520d6506c2716287ba3b5d1bbc8:
9
for you to fetch changes up to dd353157942a59c21da07da5ac8749a871f7c3ed:
11
10
12
qemu-img: Check for backing image if specified during create (2017-07-18 15:27:37 +0200)
11
tests/test-bdrv-drain: Fix too late qemu_event_reset() (2018-10-01 19:13:55 +0200)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
15
Block layer patches
14
Block layer patches:
15
16
- qcow2 cache option default changes (Linux: 32 MB maximum, limited by
17
whatever cache size can be made use of with the specific image;
18
default cache-clean-interval of 10 minutes)
19
- reopen: Allow specifying unchanged child node references, and changing
20
a few generic options (discard, detect-zeroes)
21
- Fix werror/rerror defaults for -device drive=<node-name>
22
- Test case fixes
16
23
17
----------------------------------------------------------------
24
----------------------------------------------------------------
18
Hervé Poussineau (4):
25
Alberto Garcia (9):
19
vvfat: add constants for special values of name[0]
26
qemu-io: Fix writethrough check in reopen
20
vvfat: add a constant for bootsector name
27
file-posix: x-check-cache-dropped should default to false on reopen
21
vvfat: correctly parse non-ASCII short and long file names
28
block: Remove child references from bs->{options,explicit_options}
22
vvfat: initialize memory after allocating it
29
block: Don't look for child references in append_open_options()
30
block: Allow child references on reopen
31
block: Forbid trying to change unsupported options during reopen
32
file-posix: Forbid trying to change unsupported options during reopen
33
block: Allow changing 'discard' on reopen
34
block: Allow changing 'detect-zeroes' on reopen
23
35
24
John Snow (2):
36
Fam Zheng (1):
25
blockdev: move BDRV_O_NO_BACKING option forward
37
file-posix: Include filename in locking error message
26
qemu-img: Check for backing image if specified during create
27
38
28
Kevin Wolf (10):
39
Kevin Wolf (3):
29
commit: Add NULL check for overlay_bs
40
block-backend: Set werror/rerror defaults in blk_new()
30
block: Make blk_get_attached_dev_id() public
41
test-replication: Lock AioContext around blk_unref()
31
block/qapi: Add qdev device name to query-block
42
tests/test-bdrv-drain: Fix too late qemu_event_reset()
32
block: Make blk_all_next() public
33
block/qapi: Use blk_all_next() for query-block
34
block: List anonymous device BBs in query-block
35
ide: bdrv_attach_dev() for empty CD-ROM
36
scsi-disk: bdrv_attach_dev() for empty CD-ROM
37
qemu-iotests: Test 'info block'
38
qemu-iotests: Test unplug of -device without drive
39
43
40
Manos Pitsidianakis (2):
44
Leonid Bloch (10):
41
block: add clock_type field to ThrottleGroup
45
qcow2: Options' documentation fixes
42
block: remove timer canceling in throttle_config()
46
include: Add a lookup table of sizes
47
qcow2: Make sizes more humanly readable
48
qcow2: Avoid duplication in setting the refcount cache size
49
qcow2: Assign the L2 cache relatively to the image size
50
qcow2: Increase the default upper limit on the L2 cache size
51
qcow2: Resize the cache upon image resizing
52
qcow2: Set the default cache-clean-interval to 10 minutes
53
qcow2: Explicit number replaced by a constant
54
qcow2: Fix cache-clean-interval documentation
43
55
44
Max Reitz (1):
56
qapi/block-core.json | 4 +-
45
block/vvfat: Fix compiler warning with gcc 7
57
docs/qcow2-cache.txt | 59 ++++++++++++--------
58
block/qcow2.h | 19 ++++---
59
include/block/block.h | 1 +
60
include/qemu/units.h | 55 ++++++++++++++++++
61
block.c | 135 +++++++++++++++++++++++++++++----------------
62
block/block-backend.c | 3 +
63
block/file-posix.c | 19 +++++--
64
block/qcow2.c | 43 +++++++++------
65
qemu-io-cmds.c | 2 +-
66
tests/test-bdrv-drain.c | 4 +-
67
tests/test-replication.c | 11 ++++
68
qemu-options.hx | 12 ++--
69
tests/qemu-iotests/067.out | 1 +
70
tests/qemu-iotests/137 | 8 ++-
71
tests/qemu-iotests/137.out | 4 +-
72
tests/qemu-iotests/153.out | 76 ++++++++++++-------------
73
tests/qemu-iotests/182.out | 2 +-
74
18 files changed, 307 insertions(+), 151 deletions(-)
46
75
47
Peter Maydell (2):
48
block/vmdk: Report failures in vmdk_read_cid()
49
block/vpc.c: Handle write failures in get_image_offset()
50
51
block.c | 94 ++++----
52
block/block-backend.c | 5 +-
53
block/commit.c | 4 +-
54
block/qapi.c | 20 +-
55
block/throttle-groups.c | 28 +--
56
block/vmdk.c | 44 +++-
57
block/vpc.c | 30 ++-
58
block/vvfat.c | 90 +++++---
59
blockdev.c | 11 +-
60
fsdev/qemu-fsdev-throttle.c | 2 +-
61
hmp.c | 11 +-
62
hw/ide/qdev.c | 3 +
63
hw/scsi/scsi-disk.c | 5 +
64
include/qemu/throttle.h | 2 +-
65
include/sysemu/block-backend.h | 2 +
66
qapi/block-core.json | 9 +-
67
qemu-img-cmds.hx | 4 +-
68
qemu-img.c | 16 +-
69
qemu-img.texi | 9 +-
70
tests/qemu-iotests/067 | 13 ++
71
tests/qemu-iotests/067.out | 40 ++++
72
tests/qemu-iotests/082 | 4 +-
73
tests/qemu-iotests/082.out | 4 +-
74
tests/qemu-iotests/085 | 2 +-
75
tests/qemu-iotests/111.out | 1 +
76
tests/qemu-iotests/139 | 2 +-
77
tests/qemu-iotests/156 | 2 +-
78
tests/qemu-iotests/158 | 2 +-
79
tests/qemu-iotests/186 | 147 +++++++++++++
80
tests/qemu-iotests/186.out | 489 +++++++++++++++++++++++++++++++++++++++++
81
tests/qemu-iotests/189 | 2 +-
82
tests/qemu-iotests/group | 1 +
83
tests/test-throttle.c | 4 +-
84
util/throttle.c | 18 +-
85
34 files changed, 958 insertions(+), 162 deletions(-)
86
create mode 100755 tests/qemu-iotests/186
87
create mode 100644 tests/qemu-iotests/186.out
88
diff view generated by jsdifflib
New patch
1
1
From: Fam Zheng <famz@redhat.com>
2
3
Image locking errors happening at device initialization time doesn't say
4
which file cannot be locked, for instance,
5
6
-device scsi-disk,drive=drive-1: Failed to get shared "write" lock
7
Is another process using the image?
8
9
could refer to either the overlay image or its backing image.
10
11
Hoist the error_append_hint to the caller of raw_check_lock_bytes where
12
file name is known, and include it in the error hint.
13
14
Signed-off-by: Fam Zheng <famz@redhat.com>
15
Reviewed-by: Eric Blake <eblake@redhat.com>
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
---
18
block/file-posix.c | 10 +++---
19
tests/qemu-iotests/153.out | 76 +++++++++++++++++++++++-----------------------
20
tests/qemu-iotests/182.out | 2 +-
21
3 files changed, 45 insertions(+), 43 deletions(-)
22
23
diff --git a/block/file-posix.c b/block/file-posix.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/block/file-posix.c
26
+++ b/block/file-posix.c
27
@@ -XXX,XX +XXX,XX @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm,
28
"Failed to get \"%s\" lock",
29
perm_name);
30
g_free(perm_name);
31
- error_append_hint(errp,
32
- "Is another process using the image?\n");
33
return ret;
34
}
35
}
36
@@ -XXX,XX +XXX,XX @@ static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm,
37
"Failed to get shared \"%s\" lock",
38
perm_name);
39
g_free(perm_name);
40
- error_append_hint(errp,
41
- "Is another process using the image?\n");
42
return ret;
43
}
44
}
45
@@ -XXX,XX +XXX,XX @@ static int raw_handle_perm_lock(BlockDriverState *bs,
46
if (!ret) {
47
return 0;
48
}
49
+ error_append_hint(errp,
50
+ "Is another process using the image [%s]?\n",
51
+ bs->filename);
52
}
53
op = RAW_PL_ABORT;
54
/* fall through to unlock bytes. */
55
@@ -XXX,XX +XXX,XX @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
56
/* Step two: Check that nobody else has taken conflicting locks */
57
result = raw_check_lock_bytes(fd, perm, shared, errp);
58
if (result < 0) {
59
+ error_append_hint(errp,
60
+ "Is another process using the image [%s]?\n",
61
+ file_opts->filename);
62
goto out_unlock;
63
}
64
65
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
66
index XXXXXXX..XXXXXXX 100644
67
--- a/tests/qemu-iotests/153.out
68
+++ b/tests/qemu-iotests/153.out
69
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t
70
71
== Launching another QEMU, opts: '' ==
72
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
73
-Is another process using the image?
74
+Is another process using the image [TEST_DIR/t.qcow2]?
75
76
== Launching another QEMU, opts: 'read-only=on' ==
77
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,read-only=on: Failed to get shared "write" lock
78
-Is another process using the image?
79
+Is another process using the image [TEST_DIR/t.qcow2]?
80
81
== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
82
83
@@ -XXX,XX +XXX,XX @@ Is another process using the image?
84
85
_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
86
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
87
-Is another process using the image?
88
+Is another process using the image [TEST_DIR/t.qcow2]?
89
90
_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
91
can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
92
-Is another process using the image?
93
+Is another process using the image [TEST_DIR/t.qcow2]?
94
95
_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
96
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
97
-Is another process using the image?
98
+Is another process using the image [TEST_DIR/t.qcow2]?
99
no file open, try 'help open'
100
101
_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
102
can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
103
-Is another process using the image?
104
+Is another process using the image [TEST_DIR/t.qcow2]?
105
no file open, try 'help open'
106
107
_qemu_img_wrapper info TEST_DIR/t.qcow2
108
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
109
-Is another process using the image?
110
+Is another process using the image [TEST_DIR/t.qcow2]?
111
112
_qemu_img_wrapper check TEST_DIR/t.qcow2
113
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
114
-Is another process using the image?
115
+Is another process using the image [TEST_DIR/t.qcow2]?
116
117
_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
118
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
119
-Is another process using the image?
120
+Is another process using the image [TEST_DIR/t.qcow2]?
121
122
_qemu_img_wrapper map TEST_DIR/t.qcow2
123
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
124
-Is another process using the image?
125
+Is another process using the image [TEST_DIR/t.qcow2]?
126
127
_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
128
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
129
-Is another process using the image?
130
+Is another process using the image [TEST_DIR/t.qcow2]?
131
132
_qemu_img_wrapper commit TEST_DIR/t.qcow2
133
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
134
-Is another process using the image?
135
+Is another process using the image [TEST_DIR/t.qcow2]?
136
137
_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
138
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
139
-Is another process using the image?
140
+Is another process using the image [TEST_DIR/t.qcow2]?
141
142
_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
143
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
144
-Is another process using the image?
145
+Is another process using the image [TEST_DIR/t.qcow2]?
146
147
_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
148
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
149
-Is another process using the image?
150
+Is another process using the image [TEST_DIR/t.qcow2]?
151
152
_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
153
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
154
-Is another process using the image?
155
+Is another process using the image [TEST_DIR/t.qcow2]?
156
157
_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
158
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
159
-Is another process using the image?
160
+Is another process using the image [TEST_DIR/t.qcow2]?
161
162
_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
163
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
164
-Is another process using the image?
165
+Is another process using the image [TEST_DIR/t.qcow2]?
166
167
_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
168
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
169
-Is another process using the image?
170
+Is another process using the image [TEST_DIR/t.qcow2]?
171
172
_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
173
qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock
174
-Is another process using the image?
175
+Is another process using the image [TEST_DIR/t.qcow2]?
176
file format: IMGFMT
177
178
== Running utility commands -U ==
179
@@ -XXX,XX +XXX,XX @@ Try 'qemu-img --help' for more information
180
181
_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
182
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
183
-Is another process using the image?
184
+Is another process using the image [TEST_DIR/t.qcow2]?
185
186
_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
187
188
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t
189
190
== Launching another QEMU, opts: '' ==
191
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
192
-Is another process using the image?
193
+Is another process using the image [TEST_DIR/t.qcow2]?
194
195
== Launching another QEMU, opts: 'read-only=on' ==
196
197
@@ -XXX,XX +XXX,XX @@ Is another process using the image?
198
199
_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
200
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
201
-Is another process using the image?
202
+Is another process using the image [TEST_DIR/t.qcow2]?
203
204
_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
205
206
_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
207
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
208
-Is another process using the image?
209
+Is another process using the image [TEST_DIR/t.qcow2]?
210
no file open, try 'help open'
211
212
_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
213
@@ -XXX,XX +XXX,XX @@ _qemu_img_wrapper map TEST_DIR/t.qcow2
214
215
_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
216
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
217
-Is another process using the image?
218
+Is another process using the image [TEST_DIR/t.qcow2]?
219
220
_qemu_img_wrapper commit TEST_DIR/t.qcow2
221
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
222
-Is another process using the image?
223
+Is another process using the image [TEST_DIR/t.qcow2]?
224
225
_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
226
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
227
-Is another process using the image?
228
+Is another process using the image [TEST_DIR/t.qcow2]?
229
230
_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
231
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
232
-Is another process using the image?
233
+Is another process using the image [TEST_DIR/t.qcow2]?
234
235
_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
236
237
@@ -XXX,XX +XXX,XX @@ _qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
238
239
_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
240
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
241
-Is another process using the image?
242
+Is another process using the image [TEST_DIR/t.qcow2]?
243
244
_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
245
qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock
246
-Is another process using the image?
247
+Is another process using the image [TEST_DIR/t.qcow2]?
248
file format: IMGFMT
249
250
== Running utility commands -U ==
251
@@ -XXX,XX +XXX,XX @@ Try 'qemu-img --help' for more information
252
253
_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
254
qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
255
-Is another process using the image?
256
+Is another process using the image [TEST_DIR/t.qcow2]?
257
258
_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
259
260
@@ -XXX,XX +XXX,XX @@ Round done
261
262
== Two devices with the same image (read-only=off - read-only=off) ==
263
QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,read-only=off: Failed to get "write" lock
264
-Is another process using the image?
265
+Is another process using the image [TEST_DIR/t.qcow2]?
266
267
== Two devices with the same image (read-only=off - read-only=on) ==
268
QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,read-only=on: Failed to get shared "write" lock
269
-Is another process using the image?
270
+Is another process using the image [TEST_DIR/t.qcow2]?
271
272
== Two devices with the same image (read-only=off - read-only=on,force-share=on) ==
273
274
== Two devices with the same image (read-only=on - read-only=off) ==
275
QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,read-only=off: Failed to get "write" lock
276
-Is another process using the image?
277
+Is another process using the image [TEST_DIR/t.qcow2]?
278
279
== Two devices with the same image (read-only=on - read-only=on) ==
280
281
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.c', fmt=IMGFMT size=33554432 backing_file=TEST_DIR
282
283
== Backing image also as an active device ==
284
QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
285
-Is another process using the image?
286
+Is another process using the image [TEST_DIR/t.qcow2]?
287
288
== Backing image also as an active device (ro) ==
289
290
== Symbolic link ==
291
QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
292
-Is another process using the image?
293
+Is another process using the image [TEST_DIR/t.qcow2]?
294
295
== Active commit to intermediate layer should work when base in use ==
296
{"return": {}}
297
@@ -XXX,XX +XXX,XX @@ Adding drive
298
299
_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
300
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
301
-Is another process using the image?
302
+Is another process using the image [TEST_DIR/t.qcow2]?
303
Creating overlay with qemu-img when the guest is running should be allowed
304
305
_qemu_img_wrapper create -f qcow2 -b TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.overlay
306
@@ -XXX,XX +XXX,XX @@ _qemu_img_wrapper info TEST_DIR/t.qcow2
307
308
_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
309
can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
310
-Is another process using the image?
311
+Is another process using the image [TEST_DIR/t.qcow2]?
312
Closing the other
313
314
_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
315
diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out
316
index XXXXXXX..XXXXXXX 100644
317
--- a/tests/qemu-iotests/182.out
318
+++ b/tests/qemu-iotests/182.out
319
@@ -XXX,XX +XXX,XX @@ Starting QEMU
320
321
Starting a second QEMU using the same image should fail
322
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock
323
-Is another process using the image?
324
+Is another process using the image [TEST_DIR/t.qcow2]?
325
*** done
326
--
327
2.13.6
328
329
diff view generated by jsdifflib
1
From: John Snow <jsnow@redhat.com>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
For both external_snapshot_prepare and qmp_drive_mirror, we eventually
3
"qemu-io reopen" doesn't allow changing the writethrough setting of
4
append the option BDRV_O_NO_BACKING. However, we generally do so after
4
the cache, but the check is wrong, causing an error even on a simple
5
we create the image.
5
reopen with the default parameters:
6
6
7
To accommodate image creation wanting to verify that a backing file
7
$ qemu-img create -f qcow2 hd.qcow2 1M
8
exists or not, add this option prior to create to override checking
8
$ qemu-system-x86_64 -monitor stdio -drive if=virtio,file=hd.qcow2
9
the existence of the backing file. This prevents QEMU from trying to
9
(qemu) qemu-io virtio0 reopen
10
re-open a backing file that's already in use (thanks to qcow2 locking).
10
Cannot change cache.writeback: Device attached
11
11
12
Signed-off-by: John Snow <jsnow@redhat.com>
12
Signed-off-by: Alberto Garcia <berto@igalia.com>
13
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
---
15
---
16
blockdev.c | 11 ++++++-----
16
qemu-io-cmds.c | 2 +-
17
1 file changed, 6 insertions(+), 5 deletions(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
18
18
19
diff --git a/blockdev.c b/blockdev.c
19
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
20
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
21
--- a/blockdev.c
21
--- a/qemu-io-cmds.c
22
+++ b/blockdev.c
22
+++ b/qemu-io-cmds.c
23
@@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common,
23
@@ -XXX,XX +XXX,XX @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)
24
}
24
return -EINVAL;
25
26
flags = state->old_bs->open_flags;
27
- flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ);
28
+ flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_COPY_ON_READ);
29
+ flags |= BDRV_O_NO_BACKING;
30
31
/* create new image w/backing file */
32
mode = s->has_mode ? s->mode : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
33
@@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common,
34
qdict_put_str(options, "node-name", snapshot_node_name);
35
}
36
qdict_put_str(options, "driver", format);
37
-
38
- flags |= BDRV_O_NO_BACKING;
39
}
25
}
40
26
41
state->new_bs = bdrv_open(new_image_file, snapshot_ref, options, flags,
27
- if (writethrough != blk_enable_write_cache(blk) &&
42
@@ -XXX,XX +XXX,XX @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
28
+ if (!writethrough != blk_enable_write_cache(blk) &&
43
backing_mode = MIRROR_OPEN_BACKING_CHAIN;
29
blk_get_attached_dev(blk))
44
}
45
46
+ /* Don't open backing image in create() */
47
+ flags |= BDRV_O_NO_BACKING;
48
+
49
if ((arg->sync == MIRROR_SYNC_MODE_FULL || !source)
50
&& arg->mode != NEW_IMAGE_MODE_EXISTING)
51
{
30
{
52
@@ -XXX,XX +XXX,XX @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
31
error_report("Cannot change cache.writeback: Device attached");
53
/* Mirroring takes care of copy-on-write using the source's backing
54
* file.
55
*/
56
- target_bs = bdrv_open(arg->target, NULL, options,
57
- flags | BDRV_O_NO_BACKING, errp);
58
+ target_bs = bdrv_open(arg->target, NULL, options, flags, errp);
59
if (!target_bs) {
60
goto out;
61
}
62
--
32
--
63
1.8.3.1
33
2.13.6
64
34
65
35
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
gcc 7 complains that the sprintf() might write a null byte beyond the
3
The default value of x-check-cache-dropped is false. There's no reason
4
end of the tail buffer. That is wrong, but we can silence it by making
4
to use the previous value as a default in raw_reopen_prepare() because
5
i unsigned (it can never be negative anyway, see the if condition right
5
bdrv_reopen_queue_child() already takes care of putting the old
6
before). For some reason, this allows gcc to suddenly accurately
6
options in the BDRVReopenState.options QDict.
7
calculate the range of i so we can give the tail[] array the exact size
8
it needs to have (which is 8 bytes) without gcc complaining.
9
7
10
In addition, let us convert the sprintf() to snprintf(), because that is
8
If x-check-cache-dropped was previously set but is now missing from
11
always nicer, and add an assertion about the range of the return value
9
the reopen QDict then it should be reset to false.
12
afterwards so we can see that "8 - len" will never be negative and thus
13
"entry->name + MIN(j, 8 - len)" will never be out of bounds.
14
10
15
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Signed-off-by: Alberto Garcia <berto@igalia.com>
16
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
14
---
19
block/vvfat.c | 5 +++--
15
block/file-posix.c | 2 +-
20
1 file changed, 3 insertions(+), 2 deletions(-)
16
1 file changed, 1 insertion(+), 1 deletion(-)
21
17
22
diff --git a/block/vvfat.c b/block/vvfat.c
18
diff --git a/block/file-posix.c b/block/file-posix.c
23
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
24
--- a/block/vvfat.c
20
--- a/block/file-posix.c
25
+++ b/block/vvfat.c
21
+++ b/block/file-posix.c
26
@@ -XXX,XX +XXX,XX @@ static direntry_t *create_short_filename(BDRVVVFATState *s,
22
@@ -XXX,XX +XXX,XX @@ static int raw_reopen_prepare(BDRVReopenState *state,
27
const gchar *p, *last_dot = NULL;
23
}
28
gunichar c;
24
29
bool lossy_conversion = false;
25
rs->check_cache_dropped = qemu_opt_get_bool(opts, "x-check-cache-dropped",
30
- char tail[11];
26
- s->check_cache_dropped);
31
+ char tail[8];
27
+ false);
32
28
33
if (!entry) {
29
if (s->type == FTYPE_CD) {
34
return NULL;
30
rs->open_flags |= O_NONBLOCK;
35
@@ -XXX,XX +XXX,XX @@ static direntry_t *create_short_filename(BDRVVVFATState *s,
36
for (i = lossy_conversion ? 1 : 0; i < 999999; i++) {
37
direntry_t *entry1;
38
if (i > 0) {
39
- int len = sprintf(tail, "~%d", i);
40
+ int len = snprintf(tail, sizeof(tail), "~%u", (unsigned)i);
41
+ assert(len <= 7);
42
memcpy(entry->name + MIN(j, 8 - len), tail, len);
43
}
44
for (entry1 = array_get(&(s->directory), directory_start);
45
--
31
--
46
1.8.3.1
32
2.13.6
47
33
48
34
diff view generated by jsdifflib
1
From: Hervé Poussineau <hpoussin@reactos.org>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
3
Block drivers allow opening their children using a reference to an
4
existing BlockDriverState. These references remain stored in the
5
'options' and 'explicit_options' QDicts, but we don't need to keep
6
them once everything is open.
7
8
What is more important, these values can become wrong if the children
9
change:
10
11
$ qemu-img create -f qcow2 hd0.qcow2 10M
12
$ qemu-img create -f qcow2 hd1.qcow2 10M
13
$ qemu-img create -f qcow2 hd2.qcow2 10M
14
$ $QEMU -drive if=none,file=hd0.qcow2,node-name=hd0 \
15
-drive if=none,file=hd1.qcow2,node-name=hd1,backing=hd0 \
16
-drive file=hd2.qcow2,node-name=hd2,backing=hd1
17
18
After this hd2 has hd1 as its backing file. Now let's remove it using
19
block_stream:
20
21
(qemu) block_stream hd2 0 hd0.qcow2
22
23
Now hd0 is the backing file of hd2, but hd2's options QDicts still
24
contain backing=hd1.
25
26
Signed-off-by: Alberto Garcia <berto@igalia.com>
27
Reviewed-by: Max Reitz <mreitz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
28
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
29
---
6
block/vvfat.c | 17 +++++++++++------
30
block.c | 13 ++++++++++++-
7
1 file changed, 11 insertions(+), 6 deletions(-)
31
1 file changed, 12 insertions(+), 1 deletion(-)
8
32
9
diff --git a/block/vvfat.c b/block/vvfat.c
33
diff --git a/block.c b/block.c
10
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
11
--- a/block/vvfat.c
35
--- a/block.c
12
+++ b/block/vvfat.c
36
+++ b/block.c
13
@@ -XXX,XX +XXX,XX @@ void nonono(const char* file, int line, const char* msg) {
37
@@ -XXX,XX +XXX,XX @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
14
15
#endif
16
17
+#define DIR_DELETED 0xe5
18
+#define DIR_KANJI DIR_DELETED
19
+#define DIR_KANJI_FAKE 0x05
20
+#define DIR_FREE 0x00
21
+
22
/* dynamic array functions */
23
typedef struct array_t {
24
char* pointer;
25
@@ -XXX,XX +XXX,XX @@ static direntry_t *create_long_filename(BDRVVVFATState *s, const char *filename)
26
27
static char is_free(const direntry_t* direntry)
28
{
29
- return direntry->name[0]==0xe5 || direntry->name[0]==0x00;
30
+ return direntry->name[0] == DIR_DELETED || direntry->name[0] == DIR_FREE;
31
}
32
33
static char is_volume_label(const direntry_t* direntry)
34
@@ -XXX,XX +XXX,XX @@ static char is_short_name(const direntry_t* direntry)
35
36
static char is_directory(const direntry_t* direntry)
37
{
38
- return direntry->attributes & 0x10 && direntry->name[0] != 0xe5;
39
+ return direntry->attributes & 0x10 && direntry->name[0] != DIR_DELETED;
40
}
41
42
static inline char is_dot(const direntry_t* direntry)
43
@@ -XXX,XX +XXX,XX @@ static direntry_t *create_short_filename(BDRVVVFATState *s,
44
}
38
}
45
}
39
}
46
40
47
- if (entry->name[0] == 0xe5) {
41
- /* Remove all children options from bs->options and bs->explicit_options */
48
- entry->name[0] = 0x05;
42
+ /* Remove all children options and references
49
+ if (entry->name[0] == DIR_KANJI) {
43
+ * from bs->options and bs->explicit_options */
50
+ entry->name[0] = DIR_KANJI_FAKE;
44
QLIST_FOREACH(child, &bs->children, next) {
45
char *child_key_dot;
46
child_key_dot = g_strdup_printf("%s.", child->name);
47
qdict_extract_subqdict(bs->explicit_options, NULL, child_key_dot);
48
qdict_extract_subqdict(bs->options, NULL, child_key_dot);
49
+ qdict_del(bs->explicit_options, child->name);
50
+ qdict_del(bs->options, child->name);
51
g_free(child_key_dot);
51
}
52
}
52
53
53
/* numeric-tail generation */
54
@@ -XXX,XX +XXX,XX @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state)
54
@@ -XXX,XX +XXX,XX @@ static int parse_short_name(BDRVVVFATState* s,
55
{
55
} else
56
BlockDriver *drv;
56
lfn->name[i + j + 1] = '\0';
57
BlockDriverState *bs;
57
58
+ BdrvChild *child;
58
- if (lfn->name[0] == 0x05) {
59
bool old_can_write, new_can_write;
59
- lfn->name[0] = 0xe5;
60
60
+ if (lfn->name[0] == DIR_KANJI_FAKE) {
61
assert(reopen_state != NULL);
61
+ lfn->name[0] = DIR_KANJI;
62
@@ -XXX,XX +XXX,XX @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state)
62
}
63
bs->open_flags = reopen_state->flags;
63
lfn->len = strlen((char*)lfn->name);
64
bs->read_only = !(reopen_state->flags & BDRV_O_RDWR);
64
65
66
+ /* Remove child references from bs->options and bs->explicit_options.
67
+ * Child options were already removed in bdrv_reopen_queue_child() */
68
+ QLIST_FOREACH(child, &bs->children, next) {
69
+ qdict_del(bs->explicit_options, child->name);
70
+ qdict_del(bs->options, child->name);
71
+ }
72
+
73
bdrv_refresh_limits(bs, NULL);
74
75
bdrv_set_perm(reopen_state->bs, reopen_state->perm,
65
--
76
--
66
1.8.3.1
77
2.13.6
67
78
68
79
diff view generated by jsdifflib
1
From: Hervé Poussineau <hpoussin@reactos.org>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
This prevents some host to guest memory content leaks.
3
In the previous patch we removed child references from bs->options, so
4
there's no need to look for them here anymore.
4
5
5
Fixes: https://bugs.launchpad.net/qemu/+bug/1599539
6
Signed-off-by: Alberto Garcia <berto@igalia.com>
6
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
9
---
10
block/vvfat.c | 1 +
10
block.c | 13 +------------
11
1 file changed, 1 insertion(+)
11
1 file changed, 1 insertion(+), 12 deletions(-)
12
12
13
diff --git a/block/vvfat.c b/block/vvfat.c
13
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block/vvfat.c
15
--- a/block.c
16
+++ b/block/vvfat.c
16
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ static inline int array_ensure_allocated(array_t* array, int index)
17
@@ -XXX,XX +XXX,XX @@ static bool append_open_options(QDict *d, BlockDriverState *bs)
18
array->pointer = g_realloc(array->pointer, new_size);
18
{
19
if (!array->pointer)
19
const QDictEntry *entry;
20
return -1;
20
QemuOptDesc *desc;
21
+ memset(array->pointer + array->size, 0, new_size - array->size);
21
- BdrvChild *child;
22
array->size = new_size;
22
bool found_any = false;
23
array->next = index + 1;
23
24
}
24
for (entry = qdict_first(bs->options); entry;
25
entry = qdict_next(bs->options, entry))
26
{
27
- /* Exclude node-name references to children */
28
- QLIST_FOREACH(child, &bs->children, next) {
29
- if (!strcmp(entry->key, child->name)) {
30
- break;
31
- }
32
- }
33
- if (child) {
34
- continue;
35
- }
36
-
37
- /* And exclude all non-driver-specific options */
38
+ /* Exclude all non-driver-specific options */
39
for (desc = bdrv_runtime_opts.desc; desc->name; desc++) {
40
if (!strcmp(qdict_entry_key(entry), desc->name)) {
41
break;
25
--
42
--
26
1.8.3.1
43
2.13.6
27
44
28
45
diff view generated by jsdifflib
1
From: John Snow <jsnow@redhat.com>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
Or, rather, force the open of a backing image if one was specified
3
In the previous patches we removed all child references from
4
for creation. Using a similar -unsafe option as rebase, allow qemu-img
4
bs->{options,explicit_options} because keeping them is useless and
5
to ignore the backing file validation if possible.
5
wrong.
6
6
7
It may not always be possible, as in the existing case when a filesize
7
Because of this, any attempt to reopen a BlockDriverState using a
8
for the new image was not specified.
8
child reference as one of its options would result in a failure,
9
because bdrv_reopen_prepare() would detect that there's a new option
10
(the child reference) that wasn't present in bs->options.
9
11
10
This is accomplished by shifting around the conditionals in
12
But passing child references on reopen can be useful. It's a way to
11
bdrv_img_create, such that a backing file is always opened unless we
13
specify a BDS's child without having to pass recursively all of the
12
provide BDRV_O_NO_BACKING. qemu-img is adjusted to pass this new flag
14
child's options, and if the reference points to a different BDS then
13
when -u is provided to create.
15
this can allow us to replace the child.
14
16
15
Sorry for the heinous looking diffstat, but it's mostly whitespace.
17
However, replacing the child is something that needs to be implemented
18
case by case and only when it makes sense. For now, this patch allows
19
passing a child reference as long as it points to the current child of
20
the BlockDriverState.
16
21
17
Inspired by: https://bugzilla.redhat.com/show_bug.cgi?id=1213786
22
It's also important to remember that, as a consequence of the
23
previous patches, this child reference will be removed from
24
bs->{options,explicit_options} after the reopening has been completed.
18
25
19
Signed-off-by: John Snow <jsnow@redhat.com>
26
Signed-off-by: Alberto Garcia <berto@igalia.com>
27
Reviewed-by: Max Reitz <mreitz@redhat.com>
20
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
28
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
21
---
29
---
22
block.c | 94 +++++++++++++++++++++++++---------------------
30
block.c | 18 ++++++++++++++++++
23
qemu-img-cmds.hx | 4 +-
31
1 file changed, 18 insertions(+)
24
qemu-img.c | 16 +++++---
25
qemu-img.texi | 9 ++++-
26
tests/qemu-iotests/082 | 4 +-
27
tests/qemu-iotests/082.out | 4 +-
28
tests/qemu-iotests/085 | 2 +-
29
tests/qemu-iotests/111.out | 1 +
30
tests/qemu-iotests/139 | 2 +-
31
tests/qemu-iotests/156 | 2 +-
32
tests/qemu-iotests/158 | 2 +-
33
tests/qemu-iotests/189 | 2 +-
34
12 files changed, 83 insertions(+), 59 deletions(-)
35
32
36
diff --git a/block.c b/block.c
33
diff --git a/block.c b/block.c
37
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
38
--- a/block.c
35
--- a/block.c
39
+++ b/block.c
36
+++ b/block.c
40
@@ -XXX,XX +XXX,XX @@ void bdrv_img_create(const char *filename, const char *fmt,
37
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
41
38
QObject *new = entry->value;
42
backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
39
QObject *old = qdict_get(reopen_state->bs->options, entry->key);
43
40
44
- // The size for the image must always be specified, with one exception:
41
+ /* Allow child references (child_name=node_name) as long as they
45
- // If we are using a backing file, we can obtain the size from there
42
+ * point to the current child (i.e. everything stays the same). */
46
+ /* The size for the image must always be specified, unless we have a backing
43
+ if (qobject_type(new) == QTYPE_QSTRING) {
47
+ * file and we have not been forbidden from opening it. */
44
+ BdrvChild *child;
48
size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0);
45
+ QLIST_FOREACH(child, &reopen_state->bs->children, next) {
49
- if (size == -1) {
46
+ if (!strcmp(child->name, entry->key)) {
50
- if (backing_file) {
47
+ break;
51
- BlockDriverState *bs;
48
+ }
52
- char *full_backing = g_new0(char, PATH_MAX);
49
+ }
53
- int64_t size;
54
- int back_flags;
55
- QDict *backing_options = NULL;
56
-
57
- bdrv_get_full_backing_filename_from_filename(filename, backing_file,
58
- full_backing, PATH_MAX,
59
- &local_err);
60
- if (local_err) {
61
- g_free(full_backing);
62
- goto out;
63
- }
64
+ if (backing_file && !(flags & BDRV_O_NO_BACKING)) {
65
+ BlockDriverState *bs;
66
+ char *full_backing = g_new0(char, PATH_MAX);
67
+ int back_flags;
68
+ QDict *backing_options = NULL;
69
+
50
+
70
+ bdrv_get_full_backing_filename_from_filename(filename, backing_file,
51
+ if (child) {
71
+ full_backing, PATH_MAX,
52
+ const char *str = qobject_get_try_str(new);
72
+ &local_err);
53
+ if (!strcmp(child->bs->node_name, str)) {
73
+ if (local_err) {
54
+ continue; /* Found child with this name, skip option */
74
+ g_free(full_backing);
55
+ }
75
+ goto out;
76
+ }
77
78
- /* backing files always opened read-only */
79
- back_flags = flags;
80
- back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
81
+ /* backing files always opened read-only */
82
+ back_flags = flags;
83
+ back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
84
85
- if (backing_fmt) {
86
- backing_options = qdict_new();
87
- qdict_put_str(backing_options, "driver", backing_fmt);
88
- }
89
+ if (backing_fmt) {
90
+ backing_options = qdict_new();
91
+ qdict_put_str(backing_options, "driver", backing_fmt);
92
+ }
93
94
- bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
95
- &local_err);
96
- g_free(full_backing);
97
- if (!bs) {
98
- goto out;
99
- }
100
- size = bdrv_getlength(bs);
101
- if (size < 0) {
102
- error_setg_errno(errp, -size, "Could not get size of '%s'",
103
- backing_file);
104
- bdrv_unref(bs);
105
- goto out;
106
+ bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
107
+ &local_err);
108
+ g_free(full_backing);
109
+ if (!bs && size != -1) {
110
+ /* Couldn't open BS, but we have a size, so it's nonfatal */
111
+ warn_reportf_err(local_err,
112
+ "Could not verify backing image. "
113
+ "This may become an error in future versions.\n");
114
+ local_err = NULL;
115
+ } else if (!bs) {
116
+ /* Couldn't open bs, do not have size */
117
+ error_append_hint(&local_err,
118
+ "Could not open backing image to determine size.\n");
119
+ goto out;
120
+ } else {
121
+ if (size == -1) {
122
+ /* Opened BS, have no size */
123
+ size = bdrv_getlength(bs);
124
+ if (size < 0) {
125
+ error_setg_errno(errp, -size, "Could not get size of '%s'",
126
+ backing_file);
127
+ bdrv_unref(bs);
128
+ goto out;
129
+ }
56
+ }
130
+ qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abort);
57
+ }
131
}
132
-
133
- qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abort);
134
-
135
bdrv_unref(bs);
136
- } else {
137
- error_setg(errp, "Image creation needs a size parameter");
138
- goto out;
139
}
140
+ } /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */
141
+
58
+
142
+ if (size == -1) {
59
/*
143
+ error_setg(errp, "Image creation needs a size parameter");
60
* TODO: When using -drive to specify blockdev options, all values
144
+ goto out;
61
* will be strings; however, when using -blockdev, blockdev-add or
145
}
146
147
if (!quiet) {
148
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
149
index XXXXXXX..XXXXXXX 100644
150
--- a/qemu-img-cmds.hx
151
+++ b/qemu-img-cmds.hx
152
@@ -XXX,XX +XXX,XX @@ STEXI
153
ETEXI
154
155
DEF("create", img_create,
156
- "create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backing_fmt] [-o options] filename [size]")
157
+ "create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backing_fmt] [-u] [-o options] filename [size]")
158
STEXI
159
-@item create [--object @var{objectdef}] [-q] [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}] [-o @var{options}] @var{filename} [@var{size}]
160
+@item create [--object @var{objectdef}] [-q] [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}] [-u] [-o @var{options}] @var{filename} [@var{size}]
161
ETEXI
162
163
DEF("commit", img_commit,
164
diff --git a/qemu-img.c b/qemu-img.c
165
index XXXXXXX..XXXXXXX 100644
166
--- a/qemu-img.c
167
+++ b/qemu-img.c
168
@@ -XXX,XX +XXX,XX @@ static void QEMU_NORETURN help(void)
169
" 'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n"
170
" instead\n"
171
" '-c' indicates that target image must be compressed (qcow format only)\n"
172
- " '-u' enables unsafe rebasing. It is assumed that old and new backing file\n"
173
- " match exactly. The image doesn't need a working backing file before\n"
174
- " rebasing in this case (useful for renaming the backing file)\n"
175
+ " '-u' allows unsafe backing chains. For rebasing, it is assumed that old and\n"
176
+ " new backing file match exactly. The image doesn't need a working\n"
177
+ " backing file before rebasing in this case (useful for renaming the\n"
178
+ " backing file). For image creation, allow creating without attempting\n"
179
+ " to open the backing file.\n"
180
" '-h' with or without a command shows this help and lists the supported formats\n"
181
" '-p' show progress of command (only certain commands)\n"
182
" '-q' use Quiet mode - do not print any output (except errors)\n"
183
@@ -XXX,XX +XXX,XX @@ static int img_create(int argc, char **argv)
184
char *options = NULL;
185
Error *local_err = NULL;
186
bool quiet = false;
187
+ int flags = 0;
188
189
for(;;) {
190
static const struct option long_options[] = {
191
@@ -XXX,XX +XXX,XX @@ static int img_create(int argc, char **argv)
192
{"object", required_argument, 0, OPTION_OBJECT},
193
{0, 0, 0, 0}
194
};
195
- c = getopt_long(argc, argv, ":F:b:f:ho:q",
196
+ c = getopt_long(argc, argv, ":F:b:f:ho:qu",
197
long_options, NULL);
198
if (c == -1) {
199
break;
200
@@ -XXX,XX +XXX,XX @@ static int img_create(int argc, char **argv)
201
case 'q':
202
quiet = true;
203
break;
204
+ case 'u':
205
+ flags |= BDRV_O_NO_BACKING;
206
+ break;
207
case OPTION_OBJECT: {
208
QemuOpts *opts;
209
opts = qemu_opts_parse_noisily(&qemu_object_opts,
210
@@ -XXX,XX +XXX,XX @@ static int img_create(int argc, char **argv)
211
}
212
213
bdrv_img_create(filename, fmt, base_filename, base_fmt,
214
- options, img_size, 0, quiet, &local_err);
215
+ options, img_size, flags, quiet, &local_err);
216
if (local_err) {
217
error_reportf_err(local_err, "%s: ", filename);
218
goto fail;
219
diff --git a/qemu-img.texi b/qemu-img.texi
220
index XXXXXXX..XXXXXXX 100644
221
--- a/qemu-img.texi
222
+++ b/qemu-img.texi
223
@@ -XXX,XX +XXX,XX @@ If @code{-r} is specified, exit codes representing the image state refer to the
224
state after (the attempt at) repairing it. That is, a successful @code{-r all}
225
will yield the exit code 0, independently of the image state before.
226
227
-@item create [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}] [-o @var{options}] @var{filename} [@var{size}]
228
+@item create [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}] [-u] [-o @var{options}] @var{filename} [@var{size}]
229
230
Create the new disk image @var{filename} of size @var{size} and format
231
@var{fmt}. Depending on the file format, you can add one or more @var{options}
232
@@ -XXX,XX +XXX,XX @@ only the differences from @var{backing_file}. No size needs to be specified in
233
this case. @var{backing_file} will never be modified unless you use the
234
@code{commit} monitor command (or qemu-img commit).
235
236
+Note that a given backing file will be opened to check that it is valid. Use
237
+the @code{-u} option to enable unsafe backing file mode, which means that the
238
+image will be created even if the associated backing file cannot be opened. A
239
+matching backing file must be created or additional options be used to make the
240
+backing file specification valid when you want to use an image created this
241
+way.
242
+
243
The size can also be specified using the @var{size} option with @code{-o},
244
it doesn't need to be specified separately in this case.
245
246
diff --git a/tests/qemu-iotests/082 b/tests/qemu-iotests/082
247
index XXXXXXX..XXXXXXX 100755
248
--- a/tests/qemu-iotests/082
249
+++ b/tests/qemu-iotests/082
250
@@ -XXX,XX +XXX,XX @@ run_qemu_img create -f $IMGFMT -o cluster_size=4k -o help "$TEST_IMG" $size
251
run_qemu_img create -f $IMGFMT -o cluster_size=4k -o \? "$TEST_IMG" $size
252
253
# Looks like a help option, but is part of the backing file name
254
-run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size
255
-run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size
256
+run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,help "$TEST_IMG" $size
257
+run_qemu_img create -f $IMGFMT -u -o backing_file="$TEST_IMG",,\? "$TEST_IMG" $size
258
259
# Try to trick qemu-img into creating escaped commas
260
run_qemu_img create -f $IMGFMT -o backing_file="$TEST_IMG", -o help "$TEST_IMG" $size
261
diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out
262
index XXXXXXX..XXXXXXX 100644
263
--- a/tests/qemu-iotests/082.out
264
+++ b/tests/qemu-iotests/082.out
265
@@ -XXX,XX +XXX,XX @@ lazy_refcounts Postpone refcount updates
266
refcount_bits Width of a reference count entry in bits
267
nocow Turn off copy-on-write (valid only on btrfs)
268
269
-Testing: create -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 128M
270
+Testing: create -f qcow2 -u -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 128M
271
Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=134217728 backing_file=TEST_DIR/t.qcow2,,help cluster_size=65536 lazy_refcounts=off refcount_bits=16
272
273
-Testing: create -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,? TEST_DIR/t.qcow2 128M
274
+Testing: create -f qcow2 -u -o backing_file=TEST_DIR/t.qcow2,,? TEST_DIR/t.qcow2 128M
275
Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=134217728 backing_file=TEST_DIR/t.qcow2,,? cluster_size=65536 lazy_refcounts=off refcount_bits=16
276
277
Testing: create -f qcow2 -o backing_file=TEST_DIR/t.qcow2, -o help TEST_DIR/t.qcow2 128M
278
diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085
279
index XXXXXXX..XXXXXXX 100755
280
--- a/tests/qemu-iotests/085
281
+++ b/tests/qemu-iotests/085
282
@@ -XXX,XX +XXX,XX @@ function add_snapshot_image()
283
{
284
base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
285
snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
286
- _make_test_img -b "${base_image}" "$size"
287
+ _make_test_img -u -b "${base_image}" "$size"
288
mv "${TEST_IMG}" "${snapshot_file}"
289
do_blockdev_add "$1" "'backing': '', " "${snapshot_file}"
290
}
291
diff --git a/tests/qemu-iotests/111.out b/tests/qemu-iotests/111.out
292
index XXXXXXX..XXXXXXX 100644
293
--- a/tests/qemu-iotests/111.out
294
+++ b/tests/qemu-iotests/111.out
295
@@ -XXX,XX +XXX,XX @@
296
QA output created by 111
297
qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.inexistent': No such file or directory
298
+Could not open backing image to determine size.
299
*** done
300
diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139
301
index XXXXXXX..XXXXXXX 100644
302
--- a/tests/qemu-iotests/139
303
+++ b/tests/qemu-iotests/139
304
@@ -XXX,XX +XXX,XX @@ class TestBlockdevDel(iotests.QMPTestCase):
305
# Add a BlockDriverState that will be used as overlay for the base_img BDS
306
def addBlockDriverStateOverlay(self, node):
307
self.checkBlockDriverState(node, False)
308
- iotests.qemu_img('create', '-f', iotests.imgfmt,
309
+ iotests.qemu_img('create', '-u', '-f', iotests.imgfmt,
310
'-b', base_img, new_img, '1M')
311
opts = {'driver': iotests.imgfmt,
312
'node-name': node,
313
diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156
314
index XXXXXXX..XXXXXXX 100755
315
--- a/tests/qemu-iotests/156
316
+++ b/tests/qemu-iotests/156
317
@@ -XXX,XX +XXX,XX @@ _send_qemu_cmd $QEMU_HANDLE \
318
'return'
319
320
# Create snapshot
321
-TEST_IMG="$TEST_IMG.overlay" _make_test_img -b "$TEST_IMG" 1M
322
+TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M
323
_send_qemu_cmd $QEMU_HANDLE \
324
"{ 'execute': 'blockdev-snapshot-sync',
325
'arguments': { 'device': 'source',
326
diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158
327
index XXXXXXX..XXXXXXX 100755
328
--- a/tests/qemu-iotests/158
329
+++ b/tests/qemu-iotests/158
330
@@ -XXX,XX +XXX,XX @@ echo "== verify pattern =="
331
$QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir
332
333
echo "== create overlay =="
334
-_make_test_img --object $SECRET -o "encryption=on,encrypt.key-secret=sec0" -b "$TEST_IMG_BASE" $size
335
+_make_test_img -u --object $SECRET -o "encryption=on,encrypt.key-secret=sec0" -b "$TEST_IMG_BASE" $size
336
337
echo
338
echo "== writing part of a cluster =="
339
diff --git a/tests/qemu-iotests/189 b/tests/qemu-iotests/189
340
index XXXXXXX..XXXXXXX 100755
341
--- a/tests/qemu-iotests/189
342
+++ b/tests/qemu-iotests/189
343
@@ -XXX,XX +XXX,XX @@ echo "== verify pattern =="
344
$QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECBASE | _filter_qemu_io | _filter_testdir
345
346
echo "== create overlay =="
347
-_make_test_img --object $SECRET1 -o "encrypt.format=luks,encrypt.key-secret=sec1,encrypt.iter-time=10" -b "$TEST_IMG_BASE" $size
348
+_make_test_img --object $SECRET1 -o "encrypt.format=luks,encrypt.key-secret=sec1,encrypt.iter-time=10" -u -b "$TEST_IMG_BASE" $size
349
350
echo
351
echo "== writing part of a cluster =="
352
--
62
--
353
1.8.3.1
63
2.13.6
354
64
355
65
diff view generated by jsdifflib
1
From: Hervé Poussineau <hpoussin@reactos.org>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
Write support works again when image contains non-ASCII names. It is either the
3
The bdrv_reopen_prepare() function checks all options passed to each
4
case when user created a non-ASCII filename, or when initial directory contained
4
BlockDriverState (in the reopen_state->options QDict) and makes all
5
a non-ASCII filename (since 0c36111f57ec2188f679e7fa810291b7386bdca1)
5
necessary preparations to apply the option changes requested by the
6
user.
6
7
7
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
8
Options are removed from the QDict as they are processed, so at the
9
end of bdrv_reopen_prepare() only the options that can't be changed
10
are left. Then a loop goes over all remaining options and verifies
11
that the old and new values are identical, returning an error if
12
they're not.
13
14
The problem is that at the moment there are options that are removed
15
from the QDict although they can't be changed. The consequence of this
16
is any modification to any of those options is silently ignored:
17
18
(qemu) qemu-io virtio0 "reopen -o discard=on"
19
20
This happens when all options from bdrv_runtime_opts are removed
21
from the QDict but then only a few of them are processed. Since
22
it's especially important that "node-name" and "driver" are not
23
changed, the code puts them back into the QDict so they are checked
24
at the end of the function. Instead of putting only those two options
25
back into the QDict, this patch puts all unprocessed options using
26
qemu_opts_to_qdict().
27
28
update_flags_from_options() also needs to be modified to prevent
29
BDRV_OPT_CACHE_NO_FLUSH, BDRV_OPT_CACHE_DIRECT and BDRV_OPT_READ_ONLY
30
from going back to the QDict.
31
32
Signed-off-by: Alberto Garcia <berto@igalia.com>
33
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
35
---
10
block/vvfat.c | 59 +++++++++++++++++++++++++++++++++++++----------------------
36
block.c | 22 +++++++---------------
11
1 file changed, 37 insertions(+), 22 deletions(-)
37
1 file changed, 7 insertions(+), 15 deletions(-)
12
38
13
diff --git a/block/vvfat.c b/block/vvfat.c
39
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
15
--- a/block/vvfat.c
41
--- a/block.c
16
+++ b/block/vvfat.c
42
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ typedef struct {
43
@@ -XXX,XX +XXX,XX @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
18
* filename length is 0x3f * 13 bytes.
44
*flags &= ~BDRV_O_CACHE_MASK;
19
*/
45
20
unsigned char name[0x3f * 13 + 1];
46
assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH));
21
+ gunichar2 name2[0x3f * 13 + 1];
47
- if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
22
int checksum, len;
48
+ if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
23
int sequence_number;
49
*flags |= BDRV_O_NO_FLUSH;
24
} long_file_name;
25
@@ -XXX,XX +XXX,XX @@ static int parse_long_name(long_file_name* lfn,
26
return 1;
27
28
if (pointer[0] & 0x40) {
29
+ /* first entry; do some initialization */
30
lfn->sequence_number = pointer[0] & 0x3f;
31
lfn->checksum = pointer[13];
32
lfn->name[0] = 0;
33
lfn->name[lfn->sequence_number * 13] = 0;
34
- } else if ((pointer[0] & 0x3f) != --lfn->sequence_number)
35
+ } else if ((pointer[0] & 0x3f) != --lfn->sequence_number) {
36
+ /* not the expected sequence number */
37
return -1;
38
- else if (pointer[13] != lfn->checksum)
39
+ } else if (pointer[13] != lfn->checksum) {
40
+ /* not the expected checksum */
41
return -2;
42
- else if (pointer[12] || pointer[26] || pointer[27])
43
+ } else if (pointer[12] || pointer[26] || pointer[27]) {
44
+ /* invalid zero fields */
45
return -3;
46
+ }
47
48
offset = 13 * (lfn->sequence_number - 1);
49
for (i = 0, j = 1; i < 13; i++, j+=2) {
50
@@ -XXX,XX +XXX,XX @@ static int parse_long_name(long_file_name* lfn,
51
else if (j == 26)
52
j = 28;
53
54
- if (pointer[j+1] == 0)
55
- lfn->name[offset + i] = pointer[j];
56
- else if (pointer[j+1] != 0xff || (pointer[0] & 0x40) == 0)
57
- return -4;
58
- else
59
- lfn->name[offset + i] = 0;
60
+ if (pointer[j] == 0 && pointer[j + 1] == 0) {
61
+ /* end of long file name */
62
+ break;
63
+ }
64
+ gunichar2 c = (pointer[j + 1] << 8) + pointer[j];
65
+ lfn->name2[offset + i] = c;
66
}
50
}
67
51
68
- if (pointer[0] & 0x40)
52
assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT));
69
- lfn->len = offset + strlen((char*)lfn->name + offset);
53
- if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_DIRECT, false)) {
70
+ if (pointer[0] & 0x40) {
54
+ if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) {
71
+ /* first entry; set len */
55
*flags |= BDRV_O_NOCACHE;
72
+ lfn->len = offset + i;
73
+ }
74
+ if ((pointer[0] & 0x3f) == 0x01) {
75
+ /* last entry; finalize entry */
76
+ glong olen;
77
+ gchar *utf8 = g_utf16_to_utf8(lfn->name2, lfn->len, NULL, &olen, NULL);
78
+ if (!utf8) {
79
+ return -4;
80
+ }
81
+ lfn->len = olen;
82
+ memcpy(lfn->name, utf8, olen + 1);
83
+ g_free(utf8);
84
+ }
85
86
return 0;
87
}
88
@@ -XXX,XX +XXX,XX @@ static int parse_short_name(BDRVVVFATState* s,
89
90
for (j = 7; j >= 0 && direntry->name[j] == ' '; j--);
91
for (i = 0; i <= j; i++) {
92
- if (direntry->name[i] <= ' ' || direntry->name[i] > 0x7f)
93
+ uint8_t c = direntry->name[i];
94
+ if (c != to_valid_short_char(c)) {
95
return -1;
96
- else if (s->downcase_short_names)
97
+ } else if (s->downcase_short_names) {
98
lfn->name[i] = qemu_tolower(direntry->name[i]);
99
- else
100
+ } else {
101
lfn->name[i] = direntry->name[i];
102
+ }
103
}
56
}
104
57
105
for (j = 2; j >= 0 && direntry->name[8 + j] == ' '; j--) {
58
*flags &= ~BDRV_O_RDWR;
106
@@ -XXX,XX +XXX,XX @@ static int parse_short_name(BDRVVVFATState* s,
59
107
lfn->name[i + j + 1] = '\0';
60
assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY));
108
for (;j >= 0; j--) {
61
- if (!qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false)) {
109
uint8_t c = direntry->name[8 + j];
62
+ if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) {
110
- if (c <= ' ' || c > 0x7f) {
63
*flags |= BDRV_O_RDWR;
111
+ if (c != to_valid_short_char(c)) {
64
}
112
return -2;
65
113
} else if (s->downcase_short_names) {
66
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
114
lfn->name[i + j] = qemu_tolower(c);
67
BlockDriver *drv;
115
@@ -XXX,XX +XXX,XX @@ DLOG(checkpoint());
68
QemuOpts *opts;
116
/*
69
QDict *orig_reopen_opts;
117
* Some sanity checks:
70
- const char *value;
118
* - do not allow writing to the boot sector
71
bool read_only;
119
- * - do not allow to write non-ASCII filenames
72
120
*/
73
assert(reopen_state != NULL);
121
74
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
122
if (sector_num < s->offset_to_fat)
75
123
@@ -XXX,XX +XXX,XX @@ DLOG(checkpoint());
76
update_flags_from_options(&reopen_state->flags, opts);
124
direntries = (direntry_t*)(buf + 0x200 * (begin - sector_num));
77
125
78
- /* node-name and driver must be unchanged. Put them back into the QDict, so
126
for (k = 0; k < (end - begin) * 0x10; k++) {
79
- * that they are checked at the end of this function. */
127
- /* do not allow non-ASCII filenames */
80
- value = qemu_opt_get(opts, "node-name");
128
- if (parse_long_name(&lfn, direntries + k) < 0) {
81
- if (value) {
129
- fprintf(stderr, "Warning: non-ASCII filename\n");
82
- qdict_put_str(reopen_state->options, "node-name", value);
130
- return -1;
83
- }
131
- }
84
-
132
/* no access to the direntry of a read-only file */
85
- value = qemu_opt_get(opts, "driver");
133
- else if (is_short_name(direntries+k) &&
86
- if (value) {
134
+ if (is_short_name(direntries + k) &&
87
- qdict_put_str(reopen_state->options, "driver", value);
135
(direntries[k].attributes & 1)) {
88
- }
136
if (memcmp(direntries + k,
89
+ /* All other options (including node-name and driver) must be unchanged.
137
array_get(&(s->directory), dir_index + k),
90
+ * Put them back into the QDict, so that they are checked at the end
91
+ * of this function. */
92
+ qemu_opts_to_qdict(opts, reopen_state->options);
93
94
/* If we are to stay read-only, do not allow permission change
95
* to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is
138
--
96
--
139
1.8.3.1
97
2.13.6
140
98
141
99
diff view generated by jsdifflib
1
If no drive=... option is passed (for an empty drive), we don't only
1
From: Alberto Garcia <berto@igalia.com>
2
lack the BlockBackend normally created by parse_drive(), but we also
3
need to manually call blk_attach_dev().
4
2
5
This fixes at least a segfault when unplugging such devices, the bug
3
The file-posix code is used for the "file", "host_device" and
6
that they didn't show up in query-block, and probably some more
4
"host_cdrom" drivers, and it allows reopening images. However the only
7
problems.
5
option that is actually processed is "x-check-cache-dropped", and
6
changes in all other options (e.g. "filename") are silently ignored:
8
7
8
(qemu) qemu-io virtio0 "reopen -o file.filename=no-such-file"
9
10
While we could allow changing some of the other options, let's keep
11
things as they are for now but return an error if the user tries to
12
change any of them.
13
14
Signed-off-by: Alberto Garcia <berto@igalia.com>
15
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Reviewed-by: John Snow <jsnow@redhat.com>
12
---
17
---
13
hw/scsi/scsi-disk.c | 5 +++++
18
block/file-posix.c | 9 +++++++--
14
1 file changed, 5 insertions(+)
19
1 file changed, 7 insertions(+), 2 deletions(-)
15
20
16
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
21
diff --git a/block/file-posix.c b/block/file-posix.c
17
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/scsi/scsi-disk.c
23
--- a/block/file-posix.c
19
+++ b/hw/scsi/scsi-disk.c
24
+++ b/block/file-posix.c
20
@@ -XXX,XX +XXX,XX @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
25
@@ -XXX,XX +XXX,XX @@ static int raw_reopen_prepare(BDRVReopenState *state,
21
static void scsi_cd_realize(SCSIDevice *dev, Error **errp)
26
goto out;
22
{
23
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
24
+ int ret;
25
26
if (!dev->conf.blk) {
27
+ /* Anonymous BlockBackend for an empty drive. As we put it into
28
+ * dev->conf, qdev takes care of detaching on unplug. */
29
dev->conf.blk = blk_new(0, BLK_PERM_ALL);
30
+ ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
31
+ assert(ret == 0);
32
}
27
}
33
28
34
s->qdev.blocksize = 2048;
29
- rs->check_cache_dropped = qemu_opt_get_bool(opts, "x-check-cache-dropped",
30
- false);
31
+ rs->check_cache_dropped =
32
+ qemu_opt_get_bool_del(opts, "x-check-cache-dropped", false);
33
+
34
+ /* This driver's reopen function doesn't currently allow changing
35
+ * other options, so let's put them back in the original QDict and
36
+ * bdrv_reopen_prepare() will detect changes and complain. */
37
+ qemu_opts_to_qdict(opts, state->options);
38
39
if (s->type == FTYPE_CD) {
40
rs->open_flags |= O_NONBLOCK;
35
--
41
--
36
1.8.3.1
42
2.13.6
37
43
38
44
diff view generated by jsdifflib
1
From: Alberto Garcia <berto@igalia.com>
2
3
'discard' is one of the basic BlockdevOptions available for all
4
drivers, but it's not handled by bdrv_reopen_prepare() so any attempt
5
to change it results in an error:
6
7
(qemu) qemu-io virtio0 "reopen -o discard=on"
8
Cannot change the option 'discard'
9
10
Since there's no reason why we shouldn't allow changing it and the
11
implementation is simple let's just do it.
12
13
Signed-off-by: Alberto Garcia <berto@igalia.com>
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Eric Blake <eblake@redhat.com>
3
Reviewed-by: John Snow <jsnow@redhat.com>
4
---
15
---
5
block/block-backend.c | 2 +-
16
block.c | 11 +++++++++++
6
include/sysemu/block-backend.h | 1 +
17
1 file changed, 11 insertions(+)
7
2 files changed, 2 insertions(+), 1 deletion(-)
8
18
9
diff --git a/block/block-backend.c b/block/block-backend.c
19
diff --git a/block.c b/block.c
10
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
11
--- a/block/block-backend.c
21
--- a/block.c
12
+++ b/block/block-backend.c
22
+++ b/block.c
13
@@ -XXX,XX +XXX,XX @@ void blk_unref(BlockBackend *blk)
23
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
14
* Behaves similarly to blk_next() but iterates over all BlockBackends, even the
24
BlockDriver *drv;
15
* ones which are hidden (i.e. are not referenced by the monitor).
25
QemuOpts *opts;
16
*/
26
QDict *orig_reopen_opts;
17
-static BlockBackend *blk_all_next(BlockBackend *blk)
27
+ char *discard = NULL;
18
+BlockBackend *blk_all_next(BlockBackend *blk)
28
bool read_only;
19
{
29
20
return blk ? QTAILQ_NEXT(blk, link)
30
assert(reopen_state != NULL);
21
: QTAILQ_FIRST(&block_backends);
31
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
22
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
32
23
index XXXXXXX..XXXXXXX 100644
33
update_flags_from_options(&reopen_state->flags, opts);
24
--- a/include/sysemu/block-backend.h
34
25
+++ b/include/sysemu/block-backend.h
35
+ discard = qemu_opt_get_del(opts, "discard");
26
@@ -XXX,XX +XXX,XX @@ void blk_remove_all_bs(void);
36
+ if (discard != NULL) {
27
const char *blk_name(const BlockBackend *blk);
37
+ if (bdrv_parse_discard_flags(discard, &reopen_state->flags) != 0) {
28
BlockBackend *blk_by_name(const char *name);
38
+ error_setg(errp, "Invalid discard option");
29
BlockBackend *blk_next(BlockBackend *blk);
39
+ ret = -EINVAL;
30
+BlockBackend *blk_all_next(BlockBackend *blk);
40
+ goto error;
31
bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp);
41
+ }
32
void monitor_remove_blk(BlockBackend *blk);
42
+ }
43
+
44
/* All other options (including node-name and driver) must be unchanged.
45
* Put them back into the QDict, so that they are checked at the end
46
* of this function. */
47
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
48
error:
49
qemu_opts_del(opts);
50
qobject_unref(orig_reopen_opts);
51
+ g_free(discard);
52
return ret;
53
}
33
54
34
--
55
--
35
1.8.3.1
56
2.13.6
36
57
37
58
diff view generated by jsdifflib
1
From: Manos Pitsidianakis <el13635@mail.ntua.gr>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
throttle_config() cancels the timers of the calling BlockBackend. This
3
'detect-zeroes' is one of the basic BlockdevOptions available for all
4
doesn't make sense because other BlockBackends in the group remain
4
drivers, but it's not handled by bdrv_reopen_prepare(), so any attempt
5
untouched. There's no need to cancel the timers in the one specific
5
to change it results in an error:
6
BlockBackend so let's not do that. Throttled requests will run as
7
scheduled and future requests will follow the new configuration. This
8
also allows a throttle group's configuration to be changed even when it
9
has no members.
10
6
11
Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
7
(qemu) qemu-io virtio0 "reopen -o detect-zeroes=on"
12
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Cannot change the option 'detect-zeroes'
9
10
Since there's no reason why we shouldn't allow changing it and the
11
implementation is simple let's just do it.
12
13
Signed-off-by: Alberto Garcia <berto@igalia.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
15
---
15
block/throttle-groups.c | 10 +---------
16
include/block/block.h | 1 +
16
fsdev/qemu-fsdev-throttle.c | 2 +-
17
block.c | 64 ++++++++++++++++++++++++++++++++-------------------
17
include/qemu/throttle.h | 1 -
18
2 files changed, 41 insertions(+), 24 deletions(-)
18
tests/test-throttle.c | 4 ++--
19
util/throttle.c | 14 --------------
20
5 files changed, 4 insertions(+), 27 deletions(-)
21
19
22
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
20
diff --git a/include/block/block.h b/include/block/block.h
23
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
24
--- a/block/throttle-groups.c
22
--- a/include/block/block.h
25
+++ b/block/throttle-groups.c
23
+++ b/include/block/block.h
26
@@ -XXX,XX +XXX,XX @@ void throttle_group_restart_blk(BlockBackend *blk)
24
@@ -XXX,XX +XXX,XX @@ typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
27
void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg)
25
typedef struct BDRVReopenState {
28
{
26
BlockDriverState *bs;
29
BlockBackendPublic *blkp = blk_get_public(blk);
27
int flags;
30
- ThrottleTimers *tt = &blkp->throttle_timers;
28
+ BlockdevDetectZeroesOptions detect_zeroes;
31
ThrottleState *ts = blkp->throttle_state;
29
uint64_t perm, shared_perm;
32
ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
30
QDict *options;
33
qemu_mutex_lock(&tg->lock);
31
QDict *explicit_options;
34
- /* throttle_config() cancels the timers */
32
diff --git a/block.c b/block.c
35
- if (timer_pending(tt->timers[0])) {
36
- tg->any_timer_armed[0] = false;
37
- }
38
- if (timer_pending(tt->timers[1])) {
39
- tg->any_timer_armed[1] = false;
40
- }
41
- throttle_config(ts, tg->clock_type, tt, cfg);
42
+ throttle_config(ts, tg->clock_type, cfg);
43
qemu_mutex_unlock(&tg->lock);
44
45
throttle_group_restart_blk(blk);
46
diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
47
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
48
--- a/fsdev/qemu-fsdev-throttle.c
34
--- a/block.c
49
+++ b/fsdev/qemu-fsdev-throttle.c
35
+++ b/block.c
50
@@ -XXX,XX +XXX,XX @@ void fsdev_throttle_init(FsThrottle *fst)
36
@@ -XXX,XX +XXX,XX @@ static void bdrv_join_options(BlockDriverState *bs, QDict *options,
51
fsdev_throttle_read_timer_cb,
52
fsdev_throttle_write_timer_cb,
53
fst);
54
- throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg);
55
+ throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->cfg);
56
qemu_co_queue_init(&fst->throttled_reqs[0]);
57
qemu_co_queue_init(&fst->throttled_reqs[1]);
58
}
59
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
60
index XXXXXXX..XXXXXXX 100644
61
--- a/include/qemu/throttle.h
62
+++ b/include/qemu/throttle.h
63
@@ -XXX,XX +XXX,XX @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp);
64
65
void throttle_config(ThrottleState *ts,
66
QEMUClockType clock_type,
67
- ThrottleTimers *tt,
68
ThrottleConfig *cfg);
69
70
void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg);
71
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
72
index XXXXXXX..XXXXXXX 100644
73
--- a/tests/test-throttle.c
74
+++ b/tests/test-throttle.c
75
@@ -XXX,XX +XXX,XX @@ static void test_config_functions(void)
76
read_timer_cb, write_timer_cb, &ts);
77
/* structure reset by throttle_init previous_leak should be null */
78
g_assert(!ts.previous_leak);
79
- throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg);
80
+ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &orig_cfg);
81
82
/* has previous leak been initialized by throttle_config ? */
83
g_assert(ts.previous_leak);
84
@@ -XXX,XX +XXX,XX @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
85
throttle_init(&ts);
86
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
87
read_timer_cb, write_timer_cb, &ts);
88
- throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg);
89
+ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg);
90
91
/* account a read */
92
throttle_account(&ts, false, size);
93
diff --git a/util/throttle.c b/util/throttle.c
94
index XXXXXXX..XXXXXXX 100644
95
--- a/util/throttle.c
96
+++ b/util/throttle.c
97
@@ -XXX,XX +XXX,XX @@ static void throttle_unfix_bucket(LeakyBucket *bkt)
98
}
37
}
99
}
38
}
100
39
101
-/* take care of canceling a timer */
40
+static BlockdevDetectZeroesOptions bdrv_parse_detect_zeroes(QemuOpts *opts,
102
-static void throttle_cancel_timer(QEMUTimer *timer)
41
+ int open_flags,
103
-{
42
+ Error **errp)
104
- assert(timer != NULL);
43
+{
44
+ Error *local_err = NULL;
45
+ char *value = qemu_opt_get_del(opts, "detect-zeroes");
46
+ BlockdevDetectZeroesOptions detect_zeroes =
47
+ qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, value,
48
+ BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err);
49
+ g_free(value);
50
+ if (local_err) {
51
+ error_propagate(errp, local_err);
52
+ return detect_zeroes;
53
+ }
54
+
55
+ if (detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
56
+ !(open_flags & BDRV_O_UNMAP))
57
+ {
58
+ error_setg(errp, "setting detect-zeroes to unmap is not allowed "
59
+ "without setting discard operation to unmap");
60
+ }
61
+
62
+ return detect_zeroes;
63
+}
64
+
65
/**
66
* Set open flags for a given discard mode
67
*
68
@@ -XXX,XX +XXX,XX @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
69
const char *driver_name = NULL;
70
const char *node_name = NULL;
71
const char *discard;
72
- const char *detect_zeroes;
73
QemuOpts *opts;
74
BlockDriver *drv;
75
Error *local_err = NULL;
76
@@ -XXX,XX +XXX,XX @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
77
}
78
}
79
80
- detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
81
- if (detect_zeroes) {
82
- BlockdevDetectZeroesOptions value =
83
- qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
84
- detect_zeroes,
85
- BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
86
- &local_err);
87
- if (local_err) {
88
- error_propagate(errp, local_err);
89
- ret = -EINVAL;
90
- goto fail_opts;
91
- }
105
-
92
-
106
- timer_del(timer);
93
- if (value == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
107
-}
94
- !(bs->open_flags & BDRV_O_UNMAP))
95
- {
96
- error_setg(errp, "setting detect-zeroes to unmap is not allowed "
97
- "without setting discard operation to unmap");
98
- ret = -EINVAL;
99
- goto fail_opts;
100
- }
108
-
101
-
109
/* Used to configure the throttle
102
- bs->detect_zeroes = value;
110
*
103
+ bs->detect_zeroes =
111
* @ts: the throttle state we are working on
104
+ bdrv_parse_detect_zeroes(opts, bs->open_flags, &local_err);
112
* @clock_type: the group's clock_type
105
+ if (local_err) {
113
- * @tt: the throttle timers we use in this aio context
106
+ error_propagate(errp, local_err);
114
* @cfg: the config to set
107
+ ret = -EINVAL;
115
*/
108
+ goto fail_opts;
116
void throttle_config(ThrottleState *ts,
117
QEMUClockType clock_type,
118
- ThrottleTimers *tt,
119
ThrottleConfig *cfg)
120
{
121
int i;
122
@@ -XXX,XX +XXX,XX @@ void throttle_config(ThrottleState *ts,
123
}
109
}
124
110
125
ts->previous_leak = qemu_clock_get_ns(clock_type);
111
if (filename != NULL) {
126
-
112
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
127
- for (i = 0; i < 2; i++) {
113
}
128
- throttle_cancel_timer(tt->timers[i]);
114
}
129
- }
115
130
}
116
+ reopen_state->detect_zeroes =
131
117
+ bdrv_parse_detect_zeroes(opts, reopen_state->flags, &local_err);
132
/* used to get config
118
+ if (local_err) {
119
+ error_propagate(errp, local_err);
120
+ ret = -EINVAL;
121
+ goto error;
122
+ }
123
+
124
/* All other options (including node-name and driver) must be unchanged.
125
* Put them back into the QDict, so that they are checked at the end
126
* of this function. */
127
@@ -XXX,XX +XXX,XX @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state)
128
bs->options = reopen_state->options;
129
bs->open_flags = reopen_state->flags;
130
bs->read_only = !(reopen_state->flags & BDRV_O_RDWR);
131
+ bs->detect_zeroes = reopen_state->detect_zeroes;
132
133
/* Remove child references from bs->options and bs->explicit_options.
134
* Child options were already removed in bdrv_reopen_queue_child() */
133
--
135
--
134
1.8.3.1
136
2.13.6
135
137
136
138
diff view generated by jsdifflib
1
This caused an assertion failure until recently because the BlockBackend
1
From: Leonid Bloch <lbloch@janustech.com>
2
would be detached on unplug, but was in fact never attached in the first
3
place. Add a regression test.
4
2
3
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
4
Reviewed-by: Alberto Garcia <berto@igalia.com>
5
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: John Snow <jsnow@redhat.com>
8
---
7
---
9
tests/qemu-iotests/067 | 13 +++++++++++++
8
docs/qcow2-cache.txt | 21 ++++++++++++++-------
10
tests/qemu-iotests/067.out | 39 +++++++++++++++++++++++++++++++++++++++
9
qemu-options.hx | 9 ++++++---
11
2 files changed, 52 insertions(+)
10
2 files changed, 20 insertions(+), 10 deletions(-)
12
11
13
diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067
12
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt
14
index XXXXXXX..XXXXXXX 100755
13
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/qemu-iotests/067
14
--- a/docs/qcow2-cache.txt
16
+++ b/tests/qemu-iotests/067
15
+++ b/docs/qcow2-cache.txt
17
@@ -XXX,XX +XXX,XX @@ run_qemu <<EOF
16
@@ -XXX,XX +XXX,XX @@ Choosing the right cache sizes
18
{ "execute": "quit" }
17
In order to choose the cache sizes we need to know how they relate to
19
EOF
18
the amount of allocated space.
20
19
21
+echo
20
-The amount of virtual disk that can be mapped by the L2 and refcount
22
+echo === Empty drive with -device and device_del ===
21
+The part of the virtual disk that can be mapped by the L2 and refcount
23
+echo
22
caches (in bytes) is:
23
24
disk_size = l2_cache_size * cluster_size / 8
25
disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits
26
27
With the default values for cluster_size (64KB) and refcount_bits
28
-(16), that is
29
+(16), this becomes:
30
31
disk_size = l2_cache_size * 8192
32
disk_size = refcount_cache_size * 32768
33
@@ -XXX,XX +XXX,XX @@ need:
34
l2_cache_size = disk_size_GB * 131072
35
refcount_cache_size = disk_size_GB * 32768
36
37
-QEMU has a default L2 cache of 1MB (1048576 bytes) and a refcount
38
-cache of 256KB (262144 bytes), so using the formulas we've just seen
39
-we have
40
+For example, 1MB of L2 cache is needed to cover every 8 GB of the virtual
41
+image size (given that the default cluster size is used):
42
43
- 1048576 / 131072 = 8 GB of virtual disk covered by that cache
44
- 262144 / 32768 = 8 GB
45
+ 8 GB / 8192 = 1 MB
24
+
46
+
25
+run_qemu -device virtio-scsi-pci -device scsi-cd,id=cd0 <<EOF
47
+The refcount cache is 4 times the cluster size by default. With the default
26
+{ "execute": "qmp_capabilities" }
48
+cluster size of 64 KB, it is 256 KB (262144 bytes). This is sufficient for
27
+{ "execute": "query-block" }
49
+8 GB of image size:
28
+{ "execute": "device_del", "arguments": { "id": "cd0" } }
29
+{ "execute": "system_reset" }
30
+{ "execute": "query-block" }
31
+{ "execute": "quit" }
32
+EOF
33
+
50
+
34
# success, all done
51
+ 262144 * 32768 = 8 GB
35
echo "*** done"
52
36
rm -f $seq.full
53
37
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
54
How to configure the cache sizes
55
@@ -XXX,XX +XXX,XX @@ There are a few things that need to be taken into account:
56
memory as possible to the L2 cache before increasing the refcount
57
cache size.
58
59
+ - At most two of "l2-cache-size", "refcount-cache-size", and "cache-size"
60
+ can be set simultaneously.
61
+
62
Unlike L2 tables, refcount blocks are not used during normal I/O but
63
only during allocations and internal snapshots. In most cases they are
64
accessed sequentially (even during random guest I/O) so increasing the
65
diff --git a/qemu-options.hx b/qemu-options.hx
38
index XXXXXXX..XXXXXXX 100644
66
index XXXXXXX..XXXXXXX 100644
39
--- a/tests/qemu-iotests/067.out
67
--- a/qemu-options.hx
40
+++ b/tests/qemu-iotests/067.out
68
+++ b/qemu-options.hx
41
@@ -XXX,XX +XXX,XX @@ Testing:
69
@@ -XXX,XX +XXX,XX @@ image file)
42
"return": {
70
43
}
71
@item cache-size
44
}
72
The maximum total size of the L2 table and refcount block caches in bytes
45
+
73
-(default: 1048576 bytes or 8 clusters, whichever is larger)
46
+=== Empty drive with -device and device_del ===
74
+(default: the sum of l2-cache-size and refcount-cache-size)
47
+
75
48
+Testing: -device virtio-scsi-pci -device scsi-cd,id=cd0
76
@item l2-cache-size
49
+{
77
The maximum size of the L2 table cache in bytes
50
+ QMP_VERSION
78
-(default: 4/5 of the total cache size)
51
+}
79
+(default: if cache-size is not defined - 1048576 bytes or 8 clusters, whichever
52
+{
80
+is larger; otherwise, as large as possible or needed within the cache-size,
53
+ "return": {
81
+while permitting the requested or the minimal refcount cache size)
54
+ }
82
55
+}
83
@item refcount-cache-size
56
+{
84
The maximum size of the refcount block cache in bytes
57
+ "return": [
85
-(default: 1/5 of the total cache size)
58
+ {
86
+(default: 4 times the cluster size; or if cache-size is specified, the part of
59
+ "device": "",
87
+it which is not used for the L2 cache)
60
+ "locked": false,
88
61
+ "removable": true,
89
@item cache-clean-interval
62
+ "qdev": "cd0",
90
Clean unused entries in the L2 and refcount caches. The interval is in seconds.
63
+ "tray_open": false,
64
+ "type": "unknown"
65
+ }
66
+ ]
67
+}
68
+{
69
+ "return": {
70
+ }
71
+}
72
+{
73
+ "return": {
74
+ }
75
+}
76
+{
77
+ "return": [
78
+ ]
79
+}
80
+{
81
+ "return": {
82
+ }
83
+}
84
*** done
85
--
91
--
86
1.8.3.1
92
2.13.6
87
93
88
94
diff view generated by jsdifflib
1
This test makes sure that all block devices show up on 'info block',
1
From: Leonid Bloch <lbloch@janustech.com>
2
with all of the expected information, in different configurations.
3
2
3
Adding a lookup table for the powers of two, with the appropriate size
4
prefixes. This is needed when a size has to be stringified, in which
5
case something like '(1 * KiB)' would become a literal '(1 * (1L << 10))'
6
string. Powers of two are used very often for sizes, so such a table
7
will also make it easier and more intuitive to write them.
8
9
This table is generatred using the following AWK script:
10
11
BEGIN {
12
    suffix="KMGTPE";
13
    for(i=10; i<64; i++) {
14
        val=2**i;
15
        s=substr(suffix, int(i/10), 1);
16
        n=2**(i%10);
17
        pad=21-int(log(n)/log(10));
18
        printf("#define S_%d%siB %*d\n", n, s, pad, val);
19
    }
20
}
21
22
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
23
Reviewed-by: Alberto Garcia <berto@igalia.com>
24
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Reviewed-by: Eric Blake <eblake@redhat.com>
6
Reviewed-by: John Snow <jsnow@redhat.com>
7
---
26
---
8
tests/qemu-iotests/186 | 147 ++++++++++++++
27
include/qemu/units.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
9
tests/qemu-iotests/186.out | 489 +++++++++++++++++++++++++++++++++++++++++++++
28
1 file changed, 55 insertions(+)
10
tests/qemu-iotests/group | 1 +
11
3 files changed, 637 insertions(+)
12
create mode 100755 tests/qemu-iotests/186
13
create mode 100644 tests/qemu-iotests/186.out
14
29
15
diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186
30
diff --git a/include/qemu/units.h b/include/qemu/units.h
16
new file mode 100755
31
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX
32
--- a/include/qemu/units.h
18
--- /dev/null
33
+++ b/include/qemu/units.h
19
+++ b/tests/qemu-iotests/186
20
@@ -XXX,XX +XXX,XX @@
34
@@ -XXX,XX +XXX,XX @@
21
+#!/bin/bash
35
#define PiB (INT64_C(1) << 50)
22
+#
36
#define EiB (INT64_C(1) << 60)
23
+# Test 'info block' with all kinds of configurations
37
24
+#
38
+#define S_1KiB 1024
25
+# Copyright (C) 2017 Red Hat, Inc.
39
+#define S_2KiB 2048
26
+#
40
+#define S_4KiB 4096
27
+# This program is free software; you can redistribute it and/or modify
41
+#define S_8KiB 8192
28
+# it under the terms of the GNU General Public License as published by
42
+#define S_16KiB 16384
29
+# the Free Software Foundation; either version 2 of the License, or
43
+#define S_32KiB 32768
30
+# (at your option) any later version.
44
+#define S_64KiB 65536
31
+#
45
+#define S_128KiB 131072
32
+# This program is distributed in the hope that it will be useful,
46
+#define S_256KiB 262144
33
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47
+#define S_512KiB 524288
34
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48
+#define S_1MiB 1048576
35
+# GNU General Public License for more details.
49
+#define S_2MiB 2097152
36
+#
50
+#define S_4MiB 4194304
37
+# You should have received a copy of the GNU General Public License
51
+#define S_8MiB 8388608
38
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52
+#define S_16MiB 16777216
39
+#
53
+#define S_32MiB 33554432
54
+#define S_64MiB 67108864
55
+#define S_128MiB 134217728
56
+#define S_256MiB 268435456
57
+#define S_512MiB 536870912
58
+#define S_1GiB 1073741824
59
+#define S_2GiB 2147483648
60
+#define S_4GiB 4294967296
61
+#define S_8GiB 8589934592
62
+#define S_16GiB 17179869184
63
+#define S_32GiB 34359738368
64
+#define S_64GiB 68719476736
65
+#define S_128GiB 137438953472
66
+#define S_256GiB 274877906944
67
+#define S_512GiB 549755813888
68
+#define S_1TiB 1099511627776
69
+#define S_2TiB 2199023255552
70
+#define S_4TiB 4398046511104
71
+#define S_8TiB 8796093022208
72
+#define S_16TiB 17592186044416
73
+#define S_32TiB 35184372088832
74
+#define S_64TiB 70368744177664
75
+#define S_128TiB 140737488355328
76
+#define S_256TiB 281474976710656
77
+#define S_512TiB 562949953421312
78
+#define S_1PiB 1125899906842624
79
+#define S_2PiB 2251799813685248
80
+#define S_4PiB 4503599627370496
81
+#define S_8PiB 9007199254740992
82
+#define S_16PiB 18014398509481984
83
+#define S_32PiB 36028797018963968
84
+#define S_64PiB 72057594037927936
85
+#define S_128PiB 144115188075855872
86
+#define S_256PiB 288230376151711744
87
+#define S_512PiB 576460752303423488
88
+#define S_1EiB 1152921504606846976
89
+#define S_2EiB 2305843009213693952
90
+#define S_4EiB 4611686018427387904
91
+#define S_8EiB 9223372036854775808
40
+
92
+
41
+# creator
93
#endif
42
+owner=kwolf@redhat.com
43
+
44
+seq=`basename $0`
45
+echo "QA output created by $seq"
46
+
47
+here=`pwd`
48
+status=1    # failure is the default!
49
+
50
+_cleanup()
51
+{
52
+    _cleanup_test_img
53
+}
54
+trap "_cleanup; exit \$status" 0 1 2 3 15
55
+
56
+# get standard environment, filters and checks
57
+. ./common.rc
58
+. ./common.filter
59
+
60
+_supported_fmt qcow2
61
+_supported_proto file
62
+_supported_os Linux
63
+
64
+if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
65
+ _notrun "Requires a PC machine"
66
+fi
67
+
68
+function do_run_qemu()
69
+{
70
+ echo Testing: "$@"
71
+
72
+ (
73
+ if ! test -t 0; then
74
+ while read cmd; do
75
+ echo $cmd
76
+ done
77
+ fi
78
+ echo quit
79
+ ) | $QEMU -S -nodefaults -display none -device virtio-scsi-pci -monitor stdio "$@"
80
+ echo
81
+}
82
+
83
+function check_info_block()
84
+{
85
+ echo "info block" |
86
+ QEMU_OPTIONS="" do_run_qemu "$@" | _filter_win32 | _filter_hmp |
87
+ _filter_qemu | _filter_generated_node_ids
88
+}
89
+
90
+
91
+size=64M
92
+_make_test_img $size
93
+
94
+removable="floppy ide-cd scsi-cd"
95
+fixed="ide-hd scsi-hd virtio-blk-pci"
96
+
97
+echo
98
+echo "=== Empty drives ==="
99
+echo
100
+
101
+for dev in $removable; do
102
+ check_info_block -device $dev
103
+ check_info_block -device $dev,id=qdev_id
104
+done
105
+
106
+echo
107
+echo "=== -blockdev/-device=<node-name> ==="
108
+echo
109
+
110
+for dev in $fixed $removable; do
111
+ check_info_block -blockdev driver=null-co,node-name=null -device $dev,drive=null
112
+ check_info_block -blockdev driver=null-co,node-name=null -device $dev,drive=null,id=qdev_id
113
+done
114
+
115
+echo
116
+echo "=== -drive if=none/-device=<node-name> ==="
117
+echo
118
+
119
+# This creates two BlockBackends that will show up in 'info block'!
120
+# A monitor-owned one from -drive, and anonymous one from -device
121
+for dev in $fixed $removable; do
122
+ check_info_block -drive if=none,driver=null-co,node-name=null -device $dev,drive=null,id=qdev_id
123
+done
124
+
125
+echo
126
+echo "=== -drive if=none/-device=<bb-name> (with medium) ==="
127
+echo
128
+
129
+for dev in $fixed $removable; do
130
+ check_info_block -drive if=none,driver=null-co,node-name=null -device $dev,drive=none0
131
+ check_info_block -drive if=none,driver=null-co,node-name=null -device $dev,drive=none0,id=qdev_id
132
+done
133
+
134
+echo
135
+echo "=== -drive if=none/-device=<bb-name> (without medium) ==="
136
+echo
137
+
138
+check_info_block -drive if=none
139
+
140
+for dev in $removable; do
141
+ check_info_block -drive if=none -device $dev,drive=none0
142
+ check_info_block -drive if=none -device $dev,drive=none0,id=qdev_id
143
+done
144
+
145
+echo
146
+echo "=== -drive if=... ==="
147
+echo
148
+
149
+check_info_block -drive if=floppy
150
+check_info_block -drive if=floppy,driver=null-co
151
+
152
+check_info_block -drive if=ide,driver=null-co
153
+check_info_block -drive if=ide,media=cdrom
154
+check_info_block -drive if=ide,driver=null-co,media=cdrom
155
+
156
+check_info_block -drive if=scsi,driver=null-co
157
+check_info_block -drive if=scsi,media=cdrom
158
+check_info_block -drive if=scsi,driver=null-co,media=cdrom
159
+
160
+check_info_block -drive if=virtio,driver=null-co
161
+
162
+check_info_block -drive if=pflash,driver=null-co,size=1M
163
+
164
+# success, all done
165
+echo "*** done"
166
+rm -f $seq.full
167
+status=0
168
diff --git a/tests/qemu-iotests/186.out b/tests/qemu-iotests/186.out
169
new file mode 100644
170
index XXXXXXX..XXXXXXX
171
--- /dev/null
172
+++ b/tests/qemu-iotests/186.out
173
@@ -XXX,XX +XXX,XX @@
174
+QA output created by 186
175
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
176
+
177
+=== Empty drives ===
178
+
179
+Testing: -device floppy
180
+QEMU X.Y.Z monitor - type 'help' for more information
181
+(qemu) info block
182
+/machine/peripheral-anon/device[1]: [not inserted]
183
+ Attached to: /machine/peripheral-anon/device[1]
184
+ Removable device: not locked, tray closed
185
+(qemu) quit
186
+
187
+Testing: -device floppy,id=qdev_id
188
+QEMU X.Y.Z monitor - type 'help' for more information
189
+(qemu) info block
190
+qdev_id: [not inserted]
191
+ Attached to: qdev_id
192
+ Removable device: not locked, tray closed
193
+(qemu) quit
194
+
195
+Testing: -device ide-cd
196
+QEMU X.Y.Z monitor - type 'help' for more information
197
+(qemu) info block
198
+/machine/peripheral-anon/device[1]: [not inserted]
199
+ Attached to: /machine/peripheral-anon/device[1]
200
+ Removable device: not locked, tray closed
201
+(qemu) quit
202
+
203
+Testing: -device ide-cd,id=qdev_id
204
+QEMU X.Y.Z monitor - type 'help' for more information
205
+(qemu) info block
206
+qdev_id: [not inserted]
207
+ Attached to: qdev_id
208
+ Removable device: not locked, tray closed
209
+(qemu) quit
210
+
211
+Testing: -device scsi-cd
212
+QEMU X.Y.Z monitor - type 'help' for more information
213
+(qemu) info block
214
+/machine/peripheral-anon/device[1]: [not inserted]
215
+ Attached to: /machine/peripheral-anon/device[1]
216
+ Removable device: not locked, tray closed
217
+(qemu) quit
218
+
219
+Testing: -device scsi-cd,id=qdev_id
220
+QEMU X.Y.Z monitor - type 'help' for more information
221
+(qemu) info block
222
+qdev_id: [not inserted]
223
+ Attached to: qdev_id
224
+ Removable device: not locked, tray closed
225
+(qemu) quit
226
+
227
+
228
+=== -blockdev/-device=<node-name> ===
229
+
230
+Testing: -blockdev driver=null-co,node-name=null -device ide-hd,drive=null
231
+QEMU X.Y.Z monitor - type 'help' for more information
232
+(qemu) info block
233
+null: null-co:// (null-co)
234
+ Attached to: /machine/peripheral-anon/device[1]
235
+ Cache mode: writeback
236
+(qemu) quit
237
+
238
+Testing: -blockdev driver=null-co,node-name=null -device ide-hd,drive=null,id=qdev_id
239
+QEMU X.Y.Z monitor - type 'help' for more information
240
+(qemu) info block
241
+null: null-co:// (null-co)
242
+ Attached to: qdev_id
243
+ Cache mode: writeback
244
+(qemu) quit
245
+
246
+Testing: -blockdev driver=null-co,node-name=null -device scsi-hd,drive=null
247
+QEMU X.Y.Z monitor - type 'help' for more information
248
+(qemu) info block
249
+null: null-co:// (null-co)
250
+ Attached to: /machine/peripheral-anon/device[1]
251
+ Cache mode: writeback
252
+(qemu) quit
253
+
254
+Testing: -blockdev driver=null-co,node-name=null -device scsi-hd,drive=null,id=qdev_id
255
+QEMU X.Y.Z monitor - type 'help' for more information
256
+(qemu) info block
257
+null: null-co:// (null-co)
258
+ Attached to: qdev_id
259
+ Cache mode: writeback
260
+(qemu) quit
261
+
262
+Testing: -blockdev driver=null-co,node-name=null -device virtio-blk-pci,drive=null
263
+QEMU X.Y.Z monitor - type 'help' for more information
264
+(qemu) info block
265
+null: null-co:// (null-co)
266
+ Attached to: /machine/peripheral-anon/device[1]/virtio-backend
267
+ Cache mode: writeback
268
+(qemu) quit
269
+
270
+Testing: -blockdev driver=null-co,node-name=null -device virtio-blk-pci,drive=null,id=qdev_id
271
+QEMU X.Y.Z monitor - type 'help' for more information
272
+(qemu) info block
273
+null: null-co:// (null-co)
274
+ Attached to: /machine/peripheral/qdev_id/virtio-backend
275
+ Cache mode: writeback
276
+(qemu) quit
277
+
278
+Testing: -blockdev driver=null-co,node-name=null -device floppy,drive=null
279
+QEMU X.Y.Z monitor - type 'help' for more information
280
+(qemu) info block
281
+null: null-co:// (null-co)
282
+ Attached to: /machine/peripheral-anon/device[1]
283
+ Removable device: not locked, tray closed
284
+ Cache mode: writeback
285
+(qemu) quit
286
+
287
+Testing: -blockdev driver=null-co,node-name=null -device floppy,drive=null,id=qdev_id
288
+QEMU X.Y.Z monitor - type 'help' for more information
289
+(qemu) info block
290
+null: null-co:// (null-co)
291
+ Attached to: qdev_id
292
+ Removable device: not locked, tray closed
293
+ Cache mode: writeback
294
+(qemu) quit
295
+
296
+Testing: -blockdev driver=null-co,node-name=null -device ide-cd,drive=null
297
+QEMU X.Y.Z monitor - type 'help' for more information
298
+(qemu) info block
299
+null: null-co:// (null-co)
300
+ Attached to: /machine/peripheral-anon/device[1]
301
+ Removable device: not locked, tray closed
302
+ Cache mode: writeback
303
+(qemu) quit
304
+
305
+Testing: -blockdev driver=null-co,node-name=null -device ide-cd,drive=null,id=qdev_id
306
+QEMU X.Y.Z monitor - type 'help' for more information
307
+(qemu) info block
308
+null: null-co:// (null-co)
309
+ Attached to: qdev_id
310
+ Removable device: not locked, tray closed
311
+ Cache mode: writeback
312
+(qemu) quit
313
+
314
+Testing: -blockdev driver=null-co,node-name=null -device scsi-cd,drive=null
315
+QEMU X.Y.Z monitor - type 'help' for more information
316
+(qemu) info block
317
+null: null-co:// (null-co)
318
+ Attached to: /machine/peripheral-anon/device[1]
319
+ Removable device: not locked, tray closed
320
+ Cache mode: writeback
321
+(qemu) quit
322
+
323
+Testing: -blockdev driver=null-co,node-name=null -device scsi-cd,drive=null,id=qdev_id
324
+QEMU X.Y.Z monitor - type 'help' for more information
325
+(qemu) info block
326
+null: null-co:// (null-co)
327
+ Attached to: qdev_id
328
+ Removable device: not locked, tray closed
329
+ Cache mode: writeback
330
+(qemu) quit
331
+
332
+
333
+=== -drive if=none/-device=<node-name> ===
334
+
335
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-hd,drive=null,id=qdev_id
336
+QEMU X.Y.Z monitor - type 'help' for more information
337
+(qemu) info block
338
+none0 (null): null-co:// (null-co)
339
+ Removable device: not locked, tray closed
340
+ Cache mode: writeback
341
+
342
+null: null-co:// (null-co)
343
+ Attached to: qdev_id
344
+ Cache mode: writeback
345
+(qemu) quit
346
+
347
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-hd,drive=null,id=qdev_id
348
+QEMU X.Y.Z monitor - type 'help' for more information
349
+(qemu) info block
350
+none0 (null): null-co:// (null-co)
351
+ Removable device: not locked, tray closed
352
+ Cache mode: writeback
353
+
354
+null: null-co:// (null-co)
355
+ Attached to: qdev_id
356
+ Cache mode: writeback
357
+(qemu) quit
358
+
359
+Testing: -drive if=none,driver=null-co,node-name=null -device virtio-blk-pci,drive=null,id=qdev_id
360
+QEMU X.Y.Z monitor - type 'help' for more information
361
+(qemu) info block
362
+none0 (null): null-co:// (null-co)
363
+ Removable device: not locked, tray closed
364
+ Cache mode: writeback
365
+
366
+null: null-co:// (null-co)
367
+ Attached to: /machine/peripheral/qdev_id/virtio-backend
368
+ Cache mode: writeback
369
+(qemu) quit
370
+
371
+Testing: -drive if=none,driver=null-co,node-name=null -device floppy,drive=null,id=qdev_id
372
+QEMU X.Y.Z monitor - type 'help' for more information
373
+(qemu) info block
374
+none0 (null): null-co:// (null-co)
375
+ Removable device: not locked, tray closed
376
+ Cache mode: writeback
377
+
378
+null: null-co:// (null-co)
379
+ Attached to: qdev_id
380
+ Removable device: not locked, tray closed
381
+ Cache mode: writeback
382
+(qemu) quit
383
+
384
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-cd,drive=null,id=qdev_id
385
+QEMU X.Y.Z monitor - type 'help' for more information
386
+(qemu) info block
387
+none0 (null): null-co:// (null-co)
388
+ Removable device: not locked, tray closed
389
+ Cache mode: writeback
390
+
391
+null: null-co:// (null-co)
392
+ Attached to: qdev_id
393
+ Removable device: not locked, tray closed
394
+ Cache mode: writeback
395
+(qemu) quit
396
+
397
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-cd,drive=null,id=qdev_id
398
+QEMU X.Y.Z monitor - type 'help' for more information
399
+(qemu) info block
400
+none0 (null): null-co:// (null-co)
401
+ Removable device: not locked, tray closed
402
+ Cache mode: writeback
403
+
404
+null: null-co:// (null-co)
405
+ Attached to: qdev_id
406
+ Removable device: not locked, tray closed
407
+ Cache mode: writeback
408
+(qemu) quit
409
+
410
+
411
+=== -drive if=none/-device=<bb-name> (with medium) ===
412
+
413
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-hd,drive=none0
414
+QEMU X.Y.Z monitor - type 'help' for more information
415
+(qemu) info block
416
+none0 (null): null-co:// (null-co)
417
+ Attached to: /machine/peripheral-anon/device[1]
418
+ Cache mode: writeback
419
+(qemu) quit
420
+
421
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-hd,drive=none0,id=qdev_id
422
+QEMU X.Y.Z monitor - type 'help' for more information
423
+(qemu) info block
424
+none0 (null): null-co:// (null-co)
425
+ Attached to: qdev_id
426
+ Cache mode: writeback
427
+(qemu) quit
428
+
429
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-hd,drive=none0
430
+QEMU X.Y.Z monitor - type 'help' for more information
431
+(qemu) info block
432
+none0 (null): null-co:// (null-co)
433
+ Attached to: /machine/peripheral-anon/device[1]
434
+ Cache mode: writeback
435
+(qemu) quit
436
+
437
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-hd,drive=none0,id=qdev_id
438
+QEMU X.Y.Z monitor - type 'help' for more information
439
+(qemu) info block
440
+none0 (null): null-co:// (null-co)
441
+ Attached to: qdev_id
442
+ Cache mode: writeback
443
+(qemu) quit
444
+
445
+Testing: -drive if=none,driver=null-co,node-name=null -device virtio-blk-pci,drive=none0
446
+QEMU X.Y.Z monitor - type 'help' for more information
447
+(qemu) info block
448
+none0 (null): null-co:// (null-co)
449
+ Attached to: /machine/peripheral-anon/device[1]/virtio-backend
450
+ Cache mode: writeback
451
+(qemu) quit
452
+
453
+Testing: -drive if=none,driver=null-co,node-name=null -device virtio-blk-pci,drive=none0,id=qdev_id
454
+QEMU X.Y.Z monitor - type 'help' for more information
455
+(qemu) info block
456
+none0 (null): null-co:// (null-co)
457
+ Attached to: /machine/peripheral/qdev_id/virtio-backend
458
+ Cache mode: writeback
459
+(qemu) quit
460
+
461
+Testing: -drive if=none,driver=null-co,node-name=null -device floppy,drive=none0
462
+QEMU X.Y.Z monitor - type 'help' for more information
463
+(qemu) info block
464
+none0 (null): null-co:// (null-co)
465
+ Attached to: /machine/peripheral-anon/device[1]
466
+ Removable device: not locked, tray closed
467
+ Cache mode: writeback
468
+(qemu) quit
469
+
470
+Testing: -drive if=none,driver=null-co,node-name=null -device floppy,drive=none0,id=qdev_id
471
+QEMU X.Y.Z monitor - type 'help' for more information
472
+(qemu) info block
473
+none0 (null): null-co:// (null-co)
474
+ Attached to: qdev_id
475
+ Removable device: not locked, tray closed
476
+ Cache mode: writeback
477
+(qemu) quit
478
+
479
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-cd,drive=none0
480
+QEMU X.Y.Z monitor - type 'help' for more information
481
+(qemu) info block
482
+none0 (null): null-co:// (null-co)
483
+ Attached to: /machine/peripheral-anon/device[1]
484
+ Removable device: not locked, tray closed
485
+ Cache mode: writeback
486
+(qemu) quit
487
+
488
+Testing: -drive if=none,driver=null-co,node-name=null -device ide-cd,drive=none0,id=qdev_id
489
+QEMU X.Y.Z monitor - type 'help' for more information
490
+(qemu) info block
491
+none0 (null): null-co:// (null-co)
492
+ Attached to: qdev_id
493
+ Removable device: not locked, tray closed
494
+ Cache mode: writeback
495
+(qemu) quit
496
+
497
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-cd,drive=none0
498
+QEMU X.Y.Z monitor - type 'help' for more information
499
+(qemu) info block
500
+none0 (null): null-co:// (null-co)
501
+ Attached to: /machine/peripheral-anon/device[1]
502
+ Removable device: not locked, tray closed
503
+ Cache mode: writeback
504
+(qemu) quit
505
+
506
+Testing: -drive if=none,driver=null-co,node-name=null -device scsi-cd,drive=none0,id=qdev_id
507
+QEMU X.Y.Z monitor - type 'help' for more information
508
+(qemu) info block
509
+none0 (null): null-co:// (null-co)
510
+ Attached to: qdev_id
511
+ Removable device: not locked, tray closed
512
+ Cache mode: writeback
513
+(qemu) quit
514
+
515
+
516
+=== -drive if=none/-device=<bb-name> (without medium) ===
517
+
518
+Testing: -drive if=none
519
+QEMU X.Y.Z monitor - type 'help' for more information
520
+(qemu) info block
521
+none0: [not inserted]
522
+ Removable device: not locked, tray closed
523
+(qemu) quit
524
+
525
+Testing: -drive if=none -device floppy,drive=none0
526
+QEMU X.Y.Z monitor - type 'help' for more information
527
+(qemu) info block
528
+none0: [not inserted]
529
+ Attached to: /machine/peripheral-anon/device[1]
530
+ Removable device: not locked, tray closed
531
+(qemu) quit
532
+
533
+Testing: -drive if=none -device floppy,drive=none0,id=qdev_id
534
+QEMU X.Y.Z monitor - type 'help' for more information
535
+(qemu) info block
536
+none0: [not inserted]
537
+ Attached to: qdev_id
538
+ Removable device: not locked, tray closed
539
+(qemu) quit
540
+
541
+Testing: -drive if=none -device ide-cd,drive=none0
542
+QEMU X.Y.Z monitor - type 'help' for more information
543
+(qemu) info block
544
+none0: [not inserted]
545
+ Attached to: /machine/peripheral-anon/device[1]
546
+ Removable device: not locked, tray closed
547
+(qemu) quit
548
+
549
+Testing: -drive if=none -device ide-cd,drive=none0,id=qdev_id
550
+QEMU X.Y.Z monitor - type 'help' for more information
551
+(qemu) info block
552
+none0: [not inserted]
553
+ Attached to: qdev_id
554
+ Removable device: not locked, tray closed
555
+(qemu) quit
556
+
557
+Testing: -drive if=none -device scsi-cd,drive=none0
558
+QEMU X.Y.Z monitor - type 'help' for more information
559
+(qemu) info block
560
+none0: [not inserted]
561
+ Attached to: /machine/peripheral-anon/device[1]
562
+ Removable device: not locked, tray closed
563
+(qemu) quit
564
+
565
+Testing: -drive if=none -device scsi-cd,drive=none0,id=qdev_id
566
+QEMU X.Y.Z monitor - type 'help' for more information
567
+(qemu) info block
568
+none0: [not inserted]
569
+ Attached to: qdev_id
570
+ Removable device: not locked, tray closed
571
+(qemu) quit
572
+
573
+
574
+=== -drive if=... ===
575
+
576
+Testing: -drive if=floppy
577
+QEMU X.Y.Z monitor - type 'help' for more information
578
+(qemu) info block
579
+floppy0: [not inserted]
580
+ Attached to: /machine/unattached/device[17]
581
+ Removable device: not locked, tray closed
582
+(qemu) quit
583
+
584
+Testing: -drive if=floppy,driver=null-co
585
+QEMU X.Y.Z monitor - type 'help' for more information
586
+(qemu) info block
587
+floppy0 (NODE_NAME): null-co:// (null-co)
588
+ Attached to: /machine/unattached/device[17]
589
+ Removable device: not locked, tray closed
590
+ Cache mode: writeback
591
+(qemu) quit
592
+
593
+Testing: -drive if=ide,driver=null-co
594
+QEMU X.Y.Z monitor - type 'help' for more information
595
+(qemu) info block
596
+ide0-hd0 (NODE_NAME): null-co:// (null-co)
597
+ Attached to: /machine/unattached/device[18]
598
+ Cache mode: writeback
599
+(qemu) quit
600
+
601
+Testing: -drive if=ide,media=cdrom
602
+QEMU X.Y.Z monitor - type 'help' for more information
603
+(qemu) info block
604
+ide0-cd0: [not inserted]
605
+ Attached to: /machine/unattached/device[18]
606
+ Removable device: not locked, tray closed
607
+(qemu) quit
608
+
609
+Testing: -drive if=ide,driver=null-co,media=cdrom
610
+QEMU X.Y.Z monitor - type 'help' for more information
611
+(qemu) info block
612
+ide0-cd0 (NODE_NAME): null-co:// (null-co, read-only)
613
+ Attached to: /machine/unattached/device[18]
614
+ Removable device: not locked, tray closed
615
+ Cache mode: writeback
616
+(qemu) quit
617
+
618
+warning: qemu-system-x86_64: -drive if=scsi,driver=null-co: bus=0,unit=0 is deprecated with this machine type
619
+Testing: -drive if=scsi,driver=null-co
620
+QEMU X.Y.Z monitor - type 'help' for more information
621
+(qemu) info block
622
+scsi0-hd0 (NODE_NAME): null-co:// (null-co)
623
+ Attached to: /machine/unattached/device[27]/scsi.0/legacy[0]
624
+ Cache mode: writeback
625
+(qemu) quit
626
+
627
+warning: qemu-system-x86_64: -drive if=scsi,media=cdrom: bus=0,unit=0 is deprecated with this machine type
628
+Testing: -drive if=scsi,media=cdrom
629
+QEMU X.Y.Z monitor - type 'help' for more information
630
+(qemu) info block
631
+scsi0-cd0: [not inserted]
632
+ Attached to: /machine/unattached/device[27]/scsi.0/legacy[0]
633
+ Removable device: not locked, tray closed
634
+(qemu) quit
635
+
636
+warning: qemu-system-x86_64: -drive if=scsi,driver=null-co,media=cdrom: bus=0,unit=0 is deprecated with this machine type
637
+Testing: -drive if=scsi,driver=null-co,media=cdrom
638
+QEMU X.Y.Z monitor - type 'help' for more information
639
+(qemu) info block
640
+scsi0-cd0 (NODE_NAME): null-co:// (null-co, read-only)
641
+ Attached to: /machine/unattached/device[27]/scsi.0/legacy[0]
642
+ Removable device: not locked, tray closed
643
+ Cache mode: writeback
644
+(qemu) quit
645
+
646
+Testing: -drive if=virtio,driver=null-co
647
+QEMU X.Y.Z monitor - type 'help' for more information
648
+(qemu) info block
649
+virtio0 (NODE_NAME): null-co:// (null-co)
650
+ Attached to: /machine/peripheral-anon/device[1]/virtio-backend
651
+ Cache mode: writeback
652
+(qemu) quit
653
+
654
+Testing: -drive if=pflash,driver=null-co,size=1M
655
+QEMU X.Y.Z monitor - type 'help' for more information
656
+(qemu) info block
657
+pflash0 (NODE_NAME): json:{"driver": "null-co", "size": "1M"} (null-co)
658
+ Attached to: /machine/unattached/device[2]
659
+ Cache mode: writeback
660
+(qemu) quit
661
+
662
+*** done
663
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
664
index XXXXXXX..XXXXXXX 100644
665
--- a/tests/qemu-iotests/group
666
+++ b/tests/qemu-iotests/group
667
@@ -XXX,XX +XXX,XX @@
668
182 rw auto quick
669
183 rw auto migration
670
185 rw auto
671
+186 rw auto
672
188 rw auto quick
673
189 rw auto quick
674
--
94
--
675
1.8.3.1
95
2.13.6
676
96
677
97
diff view generated by jsdifflib
1
Instead of listing only monitor-owned BlockBackends in query-block, also
1
From: Leonid Bloch <lbloch@janustech.com>
2
add those anonymous BlockBackends that are owned by a qdev device and as
3
such under the control of the user.
4
2
5
This allows using query-block to inspect BlockBackends for the modern
3
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
6
configuration syntax with -blockdev and -device.
4
Reviewed-by: Alberto Garcia <berto@igalia.com>
5
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
block/qcow2.h | 9 +++++----
9
block/qcow2.c | 2 +-
10
2 files changed, 6 insertions(+), 5 deletions(-)
7
11
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
diff --git a/block/qcow2.h b/block/qcow2.h
9
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: John Snow <jsnow@redhat.com>
11
---
12
block/qapi.c | 2 +-
13
hmp.c | 8 ++++----
14
2 files changed, 5 insertions(+), 5 deletions(-)
15
16
diff --git a/block/qapi.c b/block/qapi.c
17
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qapi.c
14
--- a/block/qcow2.h
19
+++ b/block/qapi.c
15
+++ b/block/qcow2.h
20
@@ -XXX,XX +XXX,XX @@ BlockInfoList *qmp_query_block(Error **errp)
16
@@ -XXX,XX +XXX,XX @@
21
for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
17
22
BlockInfoList *info;
18
#include "crypto/block.h"
23
19
#include "qemu/coroutine.h"
24
- if (!*blk_name(blk)) {
20
+#include "qemu/units.h"
25
+ if (!*blk_name(blk) && !blk_get_attached_dev(blk)) {
21
26
continue;
22
//#define DEBUG_ALLOC
27
}
23
//#define DEBUG_ALLOC2
28
24
@@ -XXX,XX +XXX,XX @@
29
diff --git a/hmp.c b/hmp.c
25
26
/* 8 MB refcount table is enough for 2 PB images at 64k cluster size
27
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
28
-#define QCOW_MAX_REFTABLE_SIZE 0x800000
29
+#define QCOW_MAX_REFTABLE_SIZE S_8MiB
30
31
/* 32 MB L1 table is enough for 2 PB images at 64k cluster size
32
* (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
33
-#define QCOW_MAX_L1_SIZE 0x2000000
34
+#define QCOW_MAX_L1_SIZE S_32MiB
35
36
/* Allow for an average of 1k per snapshot table entry, should be plenty of
37
* space for snapshot names and IDs */
38
@@ -XXX,XX +XXX,XX @@
39
40
/* Whichever is more */
41
#define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */
42
-#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */
43
+#define DEFAULT_L2_CACHE_SIZE S_1MiB
44
45
-#define DEFAULT_CLUSTER_SIZE 65536
46
+#define DEFAULT_CLUSTER_SIZE S_64KiB
47
48
49
#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
50
diff --git a/block/qcow2.c b/block/qcow2.c
30
index XXXXXXX..XXXXXXX 100644
51
index XXXXXXX..XXXXXXX 100644
31
--- a/hmp.c
52
--- a/block/qcow2.c
32
+++ b/hmp.c
53
+++ b/block/qcow2.c
33
@@ -XXX,XX +XXX,XX @@ static void print_block_info(Monitor *mon, BlockInfo *info,
54
@@ -XXX,XX +XXX,XX @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
34
35
assert(!info || !info->has_inserted || info->inserted == inserted);
36
37
- if (info) {
38
+ if (info && *info->device) {
39
monitor_printf(mon, "%s", info->device);
40
if (inserted && inserted->has_node_name) {
41
monitor_printf(mon, " (%s)", inserted->node_name);
42
}
55
}
43
} else {
56
} else {
44
- assert(inserted);
57
if (!l2_cache_size_set) {
45
+ assert(info || inserted);
58
- *l2_cache_size = MAX(DEFAULT_L2_CACHE_BYTE_SIZE,
46
monitor_printf(mon, "%s",
59
+ *l2_cache_size = MAX(DEFAULT_L2_CACHE_SIZE,
47
- inserted->has_node_name
60
(uint64_t)DEFAULT_L2_CACHE_CLUSTERS
48
- ? inserted->node_name
61
* s->cluster_size);
49
+ inserted && inserted->has_node_name ? inserted->node_name
62
}
50
+ : info && info->has_qdev ? info->qdev
51
: "<anonymous>");
52
}
53
54
--
63
--
55
1.8.3.1
64
2.13.6
56
65
57
66
diff view generated by jsdifflib
1
From: Manos Pitsidianakis <el13635@mail.ntua.gr>
1
From: Leonid Bloch <lbloch@janustech.com>
2
2
3
Clock type in throttling is currently inferred by the ThrottleTimer's
3
The refcount cache size does not need to be set to its minimum value in
4
clock type even though it is a per-ThrottleGroup property; it doesn't
4
read_cache_sizes(), as it is set to at least its minimum value in
5
make sense to have different clock types in the same group. Moving this
5
qcow2_update_options_prepare().
6
to a field in ThrottleGroup can simplify some of the throttle functions.
7
6
8
Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
7
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Reviewed-by: Alberto Garcia <berto@igalia.com>
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
11
---
12
block/throttle-groups.c | 20 ++++++++++----------
12
block/qcow2.c | 5 ++---
13
fsdev/qemu-fsdev-throttle.c | 2 +-
13
1 file changed, 2 insertions(+), 3 deletions(-)
14
include/qemu/throttle.h | 1 +
15
tests/test-throttle.c | 4 ++--
16
util/throttle.c | 4 +++-
17
5 files changed, 17 insertions(+), 14 deletions(-)
18
14
19
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
15
diff --git a/block/qcow2.c b/block/qcow2.c
20
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
21
--- a/block/throttle-groups.c
17
--- a/block/qcow2.c
22
+++ b/block/throttle-groups.c
18
+++ b/block/qcow2.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct ThrottleGroup {
19
@@ -XXX,XX +XXX,XX @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
24
QLIST_HEAD(, BlockBackendPublic) head;
20
(uint64_t)DEFAULT_L2_CACHE_CLUSTERS
25
BlockBackend *tokens[2];
21
* s->cluster_size);
26
bool any_timer_armed[2];
27
+ QEMUClockType clock_type;
28
29
/* These two are protected by the global throttle_groups_lock */
30
unsigned refcount;
31
@@ -XXX,XX +XXX,XX @@ ThrottleState *throttle_group_incref(const char *name)
32
if (!tg) {
33
tg = g_new0(ThrottleGroup, 1);
34
tg->name = g_strdup(name);
35
+ tg->clock_type = QEMU_CLOCK_REALTIME;
36
+
37
+ if (qtest_enabled()) {
38
+ /* For testing block IO throttling only */
39
+ tg->clock_type = QEMU_CLOCK_VIRTUAL;
40
+ }
41
qemu_mutex_init(&tg->lock);
42
throttle_init(&tg->ts);
43
QLIST_INIT(&tg->head);
44
@@ -XXX,XX +XXX,XX @@ static void schedule_next_request(BlockBackend *blk, bool is_write)
45
token = blk;
46
} else {
47
ThrottleTimers *tt = &blk_get_public(token)->throttle_timers;
48
- int64_t now = qemu_clock_get_ns(tt->clock_type);
49
+ int64_t now = qemu_clock_get_ns(tg->clock_type);
50
timer_mod(tt->timers[is_write], now);
51
tg->any_timer_armed[is_write] = true;
52
}
22
}
53
@@ -XXX,XX +XXX,XX @@ void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg)
23
- if (!refcount_cache_size_set) {
54
if (timer_pending(tt->timers[1])) {
24
- *refcount_cache_size = min_refcount_cache;
55
tg->any_timer_armed[1] = false;
25
- }
56
}
26
}
57
- throttle_config(ts, tt, cfg);
27
+ /* l2_cache_size and refcount_cache_size are ensured to have at least
58
+ throttle_config(ts, tg->clock_type, tt, cfg);
28
+ * their minimum values in qcow2_update_options_prepare() */
59
qemu_mutex_unlock(&tg->lock);
29
60
30
if (*l2_cache_entry_size < (1 << MIN_CLUSTER_BITS) ||
61
throttle_group_restart_blk(blk);
31
*l2_cache_entry_size > s->cluster_size ||
62
@@ -XXX,XX +XXX,XX @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)
63
BlockBackendPublic *blkp = blk_get_public(blk);
64
ThrottleState *ts = throttle_group_incref(groupname);
65
ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
66
- int clock_type = QEMU_CLOCK_REALTIME;
67
-
68
- if (qtest_enabled()) {
69
- /* For testing block IO throttling only */
70
- clock_type = QEMU_CLOCK_VIRTUAL;
71
- }
72
-
73
blkp->throttle_state = ts;
74
75
qemu_mutex_lock(&tg->lock);
76
@@ -XXX,XX +XXX,XX @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname)
77
78
throttle_timers_init(&blkp->throttle_timers,
79
blk_get_aio_context(blk),
80
- clock_type,
81
+ tg->clock_type,
82
read_timer_cb,
83
write_timer_cb,
84
blk);
85
diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c
86
index XXXXXXX..XXXXXXX 100644
87
--- a/fsdev/qemu-fsdev-throttle.c
88
+++ b/fsdev/qemu-fsdev-throttle.c
89
@@ -XXX,XX +XXX,XX @@ void fsdev_throttle_init(FsThrottle *fst)
90
fsdev_throttle_read_timer_cb,
91
fsdev_throttle_write_timer_cb,
92
fst);
93
- throttle_config(&fst->ts, &fst->tt, &fst->cfg);
94
+ throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg);
95
qemu_co_queue_init(&fst->throttled_reqs[0]);
96
qemu_co_queue_init(&fst->throttled_reqs[1]);
97
}
98
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
99
index XXXXXXX..XXXXXXX 100644
100
--- a/include/qemu/throttle.h
101
+++ b/include/qemu/throttle.h
102
@@ -XXX,XX +XXX,XX @@ bool throttle_enabled(ThrottleConfig *cfg);
103
bool throttle_is_valid(ThrottleConfig *cfg, Error **errp);
104
105
void throttle_config(ThrottleState *ts,
106
+ QEMUClockType clock_type,
107
ThrottleTimers *tt,
108
ThrottleConfig *cfg);
109
110
diff --git a/tests/test-throttle.c b/tests/test-throttle.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/tests/test-throttle.c
113
+++ b/tests/test-throttle.c
114
@@ -XXX,XX +XXX,XX @@ static void test_config_functions(void)
115
read_timer_cb, write_timer_cb, &ts);
116
/* structure reset by throttle_init previous_leak should be null */
117
g_assert(!ts.previous_leak);
118
- throttle_config(&ts, &tt, &orig_cfg);
119
+ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg);
120
121
/* has previous leak been initialized by throttle_config ? */
122
g_assert(ts.previous_leak);
123
@@ -XXX,XX +XXX,XX @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */
124
throttle_init(&ts);
125
throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL,
126
read_timer_cb, write_timer_cb, &ts);
127
- throttle_config(&ts, &tt, &cfg);
128
+ throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg);
129
130
/* account a read */
131
throttle_account(&ts, false, size);
132
diff --git a/util/throttle.c b/util/throttle.c
133
index XXXXXXX..XXXXXXX 100644
134
--- a/util/throttle.c
135
+++ b/util/throttle.c
136
@@ -XXX,XX +XXX,XX @@ static void throttle_cancel_timer(QEMUTimer *timer)
137
/* Used to configure the throttle
138
*
139
* @ts: the throttle state we are working on
140
+ * @clock_type: the group's clock_type
141
* @tt: the throttle timers we use in this aio context
142
* @cfg: the config to set
143
*/
144
void throttle_config(ThrottleState *ts,
145
+ QEMUClockType clock_type,
146
ThrottleTimers *tt,
147
ThrottleConfig *cfg)
148
{
149
@@ -XXX,XX +XXX,XX @@ void throttle_config(ThrottleState *ts,
150
throttle_fix_bucket(&ts->cfg.buckets[i]);
151
}
152
153
- ts->previous_leak = qemu_clock_get_ns(tt->clock_type);
154
+ ts->previous_leak = qemu_clock_get_ns(clock_type);
155
156
for (i = 0; i < 2; i++) {
157
throttle_cancel_timer(tt->timers[i]);
158
--
32
--
159
1.8.3.1
33
2.13.6
160
34
161
35
diff view generated by jsdifflib
New patch
1
1
From: Leonid Bloch <lbloch@janustech.com>
2
3
Sufficient L2 cache can noticeably improve the performance when using
4
large images with frequent I/O.
5
6
Previously, unless 'cache-size' was specified and was large enough, the
7
L2 cache was set to a certain size without taking the virtual image size
8
into account.
9
10
Now, the L2 cache assignment is aware of the virtual size of the image,
11
and will cover the entire image, unless the cache size needed for that is
12
larger than a certain maximum. This maximum is set to 1 MB by default
13
(enough to cover an 8 GB image with the default cluster size) but can
14
be increased or decreased using the 'l2-cache-size' option. This option
15
was previously documented as the *maximum* L2 cache size, and this patch
16
makes it behave as such, instead of as a constant size. Also, the
17
existing option 'cache-size' can limit the sum of both L2 and refcount
18
caches, as previously.
19
20
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
21
Reviewed-by: Alberto Garcia <berto@igalia.com>
22
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
23
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
24
---
25
docs/qcow2-cache.txt | 15 ++++++++++-----
26
block/qcow2.h | 4 +---
27
block/qcow2.c | 21 +++++++++------------
28
qemu-options.hx | 6 +++---
29
tests/qemu-iotests/137 | 8 +++++++-
30
tests/qemu-iotests/137.out | 4 +++-
31
6 files changed, 33 insertions(+), 25 deletions(-)
32
33
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt
34
index XXXXXXX..XXXXXXX 100644
35
--- a/docs/qcow2-cache.txt
36
+++ b/docs/qcow2-cache.txt
37
@@ -XXX,XX +XXX,XX @@ There are a few things that need to be taken into account:
38
- Both caches must have a size that is a multiple of the cluster size
39
(or the cache entry size: see "Using smaller cache sizes" below).
40
41
- - The default L2 cache size is 8 clusters or 1MB (whichever is more),
42
- and the minimum is 2 clusters (or 2 cache entries, see below).
43
+ - The maximum L2 cache size is 1 MB by default (enough for full coverage
44
+ of 8 GB images, with the default cluster size). This value can be
45
+ modified using the "l2-cache-size" option. QEMU will not use more memory
46
+ than needed to hold all of the image's L2 tables, regardless of this max.
47
+ value. The minimal L2 cache size is 2 clusters (or 2 cache entries, see
48
+ below).
49
50
- The default (and minimum) refcount cache size is 4 clusters.
51
52
@@ -XXX,XX +XXX,XX @@ Some things to take into account:
53
always uses the cluster size as the entry size.
54
55
- If the L2 cache is big enough to hold all of the image's L2 tables
56
- (as explained in the "Choosing the right cache sizes" section
57
- earlier in this document) then none of this is necessary and you
58
- can omit the "l2-cache-entry-size" parameter altogether.
59
+ (as explained in the "Choosing the right cache sizes" and "How to
60
+ configure the cache sizes" sections in this document) then none of
61
+ this is necessary and you can omit the "l2-cache-entry-size"
62
+ parameter altogether.
63
64
65
Reducing the memory usage
66
diff --git a/block/qcow2.h b/block/qcow2.h
67
index XXXXXXX..XXXXXXX 100644
68
--- a/block/qcow2.h
69
+++ b/block/qcow2.h
70
@@ -XXX,XX +XXX,XX @@
71
/* Must be at least 4 to cover all cases of refcount table growth */
72
#define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
73
74
-/* Whichever is more */
75
-#define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */
76
-#define DEFAULT_L2_CACHE_SIZE S_1MiB
77
+#define DEFAULT_L2_CACHE_MAX_SIZE S_1MiB
78
79
#define DEFAULT_CLUSTER_SIZE S_64KiB
80
81
diff --git a/block/qcow2.c b/block/qcow2.c
82
index XXXXXXX..XXXXXXX 100644
83
--- a/block/qcow2.c
84
+++ b/block/qcow2.c
85
@@ -XXX,XX +XXX,XX @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
86
uint64_t *refcount_cache_size, Error **errp)
87
{
88
BDRVQcow2State *s = bs->opaque;
89
- uint64_t combined_cache_size;
90
+ uint64_t combined_cache_size, l2_cache_max_setting;
91
bool l2_cache_size_set, refcount_cache_size_set, combined_cache_size_set;
92
int min_refcount_cache = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
93
+ uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
94
+ uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8);
95
96
combined_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE);
97
l2_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_L2_CACHE_SIZE);
98
refcount_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_REFCOUNT_CACHE_SIZE);
99
100
combined_cache_size = qemu_opt_get_size(opts, QCOW2_OPT_CACHE_SIZE, 0);
101
- *l2_cache_size = qemu_opt_get_size(opts, QCOW2_OPT_L2_CACHE_SIZE, 0);
102
+ l2_cache_max_setting = qemu_opt_get_size(opts, QCOW2_OPT_L2_CACHE_SIZE,
103
+ DEFAULT_L2_CACHE_MAX_SIZE);
104
*refcount_cache_size = qemu_opt_get_size(opts,
105
QCOW2_OPT_REFCOUNT_CACHE_SIZE, 0);
106
107
*l2_cache_entry_size = qemu_opt_get_size(
108
opts, QCOW2_OPT_L2_CACHE_ENTRY_SIZE, s->cluster_size);
109
110
+ *l2_cache_size = MIN(max_l2_cache, l2_cache_max_setting);
111
+
112
if (combined_cache_size_set) {
113
if (l2_cache_size_set && refcount_cache_size_set) {
114
error_setg(errp, QCOW2_OPT_CACHE_SIZE ", " QCOW2_OPT_L2_CACHE_SIZE
115
" and " QCOW2_OPT_REFCOUNT_CACHE_SIZE " may not be set "
116
"at the same time");
117
return;
118
- } else if (*l2_cache_size > combined_cache_size) {
119
+ } else if (l2_cache_size_set &&
120
+ (l2_cache_max_setting > combined_cache_size)) {
121
error_setg(errp, QCOW2_OPT_L2_CACHE_SIZE " may not exceed "
122
QCOW2_OPT_CACHE_SIZE);
123
return;
124
@@ -XXX,XX +XXX,XX @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
125
} else if (refcount_cache_size_set) {
126
*l2_cache_size = combined_cache_size - *refcount_cache_size;
127
} else {
128
- uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
129
- uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8);
130
-
131
/* Assign as much memory as possible to the L2 cache, and
132
* use the remainder for the refcount cache */
133
if (combined_cache_size >= max_l2_cache + min_refcount_cache) {
134
@@ -XXX,XX +XXX,XX @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
135
*l2_cache_size = combined_cache_size - *refcount_cache_size;
136
}
137
}
138
- } else {
139
- if (!l2_cache_size_set) {
140
- *l2_cache_size = MAX(DEFAULT_L2_CACHE_SIZE,
141
- (uint64_t)DEFAULT_L2_CACHE_CLUSTERS
142
- * s->cluster_size);
143
- }
144
}
145
/* l2_cache_size and refcount_cache_size are ensured to have at least
146
* their minimum values in qcow2_update_options_prepare() */
147
diff --git a/qemu-options.hx b/qemu-options.hx
148
index XXXXXXX..XXXXXXX 100644
149
--- a/qemu-options.hx
150
+++ b/qemu-options.hx
151
@@ -XXX,XX +XXX,XX @@ The maximum total size of the L2 table and refcount block caches in bytes
152
153
@item l2-cache-size
154
The maximum size of the L2 table cache in bytes
155
-(default: if cache-size is not defined - 1048576 bytes or 8 clusters, whichever
156
-is larger; otherwise, as large as possible or needed within the cache-size,
157
-while permitting the requested or the minimal refcount cache size)
158
+(default: if cache-size is not specified - 1M; otherwise, as large as possible
159
+within the cache-size, while permitting the requested or the minimal refcount
160
+cache size)
161
162
@item refcount-cache-size
163
The maximum size of the refcount block cache in bytes
164
diff --git a/tests/qemu-iotests/137 b/tests/qemu-iotests/137
165
index XXXXXXX..XXXXXXX 100755
166
--- a/tests/qemu-iotests/137
167
+++ b/tests/qemu-iotests/137
168
@@ -XXX,XX +XXX,XX @@ $QEMU_IO \
169
-c "reopen -o cache-size=1M,l2-cache-size=64k,refcount-cache-size=64k" \
170
-c "reopen -o cache-size=1M,l2-cache-size=2M" \
171
-c "reopen -o cache-size=1M,refcount-cache-size=2M" \
172
- -c "reopen -o l2-cache-size=256T" \
173
-c "reopen -o l2-cache-entry-size=33k" \
174
-c "reopen -o l2-cache-entry-size=128k" \
175
-c "reopen -o refcount-cache-size=256T" \
176
@@ -XXX,XX +XXX,XX @@ $QEMU_IO \
177
-c "reopen -o cache-clean-interval=-1" \
178
"$TEST_IMG" | _filter_qemu_io
179
180
+IMGOPTS="cluster_size=256k" _make_test_img 32P
181
+$QEMU_IO \
182
+ -c "reopen -o l2-cache-entry-size=512,l2-cache-size=1T" \
183
+ "$TEST_IMG" | _filter_qemu_io
184
+
185
+_make_test_img 64M
186
+
187
echo
188
echo === Test transaction semantics ===
189
echo
190
diff --git a/tests/qemu-iotests/137.out b/tests/qemu-iotests/137.out
191
index XXXXXXX..XXXXXXX 100644
192
--- a/tests/qemu-iotests/137.out
193
+++ b/tests/qemu-iotests/137.out
194
@@ -XXX,XX +XXX,XX @@ Parameter 'lazy-refcounts' expects 'on' or 'off'
195
cache-size, l2-cache-size and refcount-cache-size may not be set at the same time
196
l2-cache-size may not exceed cache-size
197
refcount-cache-size may not exceed cache-size
198
-L2 cache size too big
199
L2 cache entry size must be a power of two between 512 and the cluster size (65536)
200
L2 cache entry size must be a power of two between 512 and the cluster size (65536)
201
Refcount cache size too big
202
@@ -XXX,XX +XXX,XX @@ Conflicting values for qcow2 options 'overlap-check' ('constant') and 'overlap-c
203
Unsupported value 'blubb' for qcow2 option 'overlap-check'. Allowed are any of the following: none, constant, cached, all
204
Unsupported value 'blubb' for qcow2 option 'overlap-check'. Allowed are any of the following: none, constant, cached, all
205
Cache clean interval too big
206
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=36028797018963968
207
+L2 cache size too big
208
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
209
210
=== Test transaction semantics ===
211
212
--
213
2.13.6
214
215
diff view generated by jsdifflib
1
I can't see how overlay_bs could become NULL with the current code, but
1
From: Leonid Bloch <lbloch@janustech.com>
2
other code in this function already checks it and we can make Coverity
3
happy with this check, so let's add it.
4
2
5
Cc: qemu-stable@nongnu.org
3
The upper limit on the L2 cache size is increased from 1 MB to 32 MB
4
on Linux platforms, and to 8 MB on other platforms (this difference is
5
caused by the ability to set intervals for cache cleaning on Linux
6
platforms only).
7
8
This is done in order to allow default full coverage with the L2 cache
9
for images of up to 256 GB in size (was 8 GB). Note, that only the
10
needed amount to cover the full image is allocated. The value which is
11
changed here is just the upper limit on the L2 cache size, beyond which
12
it will not grow, even if the size of the image will require it to.
13
14
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
15
Reviewed-by: Alberto Garcia <berto@igalia.com>
16
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
18
---
9
block/commit.c | 4 +++-
19
docs/qcow2-cache.txt | 15 +++++++++------
10
1 file changed, 3 insertions(+), 1 deletion(-)
20
block/qcow2.h | 6 +++++-
21
qemu-options.hx | 6 +++---
22
3 files changed, 17 insertions(+), 10 deletions(-)
11
23
12
diff --git a/block/commit.c b/block/commit.c
24
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt
13
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
14
--- a/block/commit.c
26
--- a/docs/qcow2-cache.txt
15
+++ b/block/commit.c
27
+++ b/docs/qcow2-cache.txt
16
@@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque)
28
@@ -XXX,XX +XXX,XX @@ There are a few things that need to be taken into account:
17
29
- Both caches must have a size that is a multiple of the cluster size
18
/* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */
30
(or the cache entry size: see "Using smaller cache sizes" below).
19
bdrv_ref(top);
31
20
- bdrv_ref(overlay_bs);
32
- - The maximum L2 cache size is 1 MB by default (enough for full coverage
21
+ if (overlay_bs) {
33
- of 8 GB images, with the default cluster size). This value can be
22
+ bdrv_ref(overlay_bs);
34
- modified using the "l2-cache-size" option. QEMU will not use more memory
23
+ }
35
- than needed to hold all of the image's L2 tables, regardless of this max.
24
36
- value. The minimal L2 cache size is 2 clusters (or 2 cache entries, see
25
/* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before
37
- below).
26
* the normal backing chain can be restored. */
38
+ - The maximum L2 cache size is 32 MB by default on Linux platforms (enough
39
+ for full coverage of 256 GB images, with the default cluster size). This
40
+ value can be modified using the "l2-cache-size" option. QEMU will not use
41
+ more memory than needed to hold all of the image's L2 tables, regardless
42
+ of this max. value.
43
+ On non-Linux platforms the maximal value is smaller by default (8 MB) and
44
+ this difference stems from the fact that on Linux the cache can be cleared
45
+ periodically if needed, using the "cache-clean-interval" option (see below).
46
+ The minimal L2 cache size is 2 clusters (or 2 cache entries, see below).
47
48
- The default (and minimum) refcount cache size is 4 clusters.
49
50
diff --git a/block/qcow2.h b/block/qcow2.h
51
index XXXXXXX..XXXXXXX 100644
52
--- a/block/qcow2.h
53
+++ b/block/qcow2.h
54
@@ -XXX,XX +XXX,XX @@
55
/* Must be at least 4 to cover all cases of refcount table growth */
56
#define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
57
58
-#define DEFAULT_L2_CACHE_MAX_SIZE S_1MiB
59
+#ifdef CONFIG_LINUX
60
+#define DEFAULT_L2_CACHE_MAX_SIZE S_32MiB
61
+#else
62
+#define DEFAULT_L2_CACHE_MAX_SIZE S_8MiB
63
+#endif
64
65
#define DEFAULT_CLUSTER_SIZE S_64KiB
66
67
diff --git a/qemu-options.hx b/qemu-options.hx
68
index XXXXXXX..XXXXXXX 100644
69
--- a/qemu-options.hx
70
+++ b/qemu-options.hx
71
@@ -XXX,XX +XXX,XX @@ The maximum total size of the L2 table and refcount block caches in bytes
72
73
@item l2-cache-size
74
The maximum size of the L2 table cache in bytes
75
-(default: if cache-size is not specified - 1M; otherwise, as large as possible
76
-within the cache-size, while permitting the requested or the minimal refcount
77
-cache size)
78
+(default: if cache-size is not specified - 32M on Linux platforms, and 8M on
79
+non-Linux platforms; otherwise, as large as possible within the cache-size,
80
+while permitting the requested or the minimal refcount cache size)
81
82
@item refcount-cache-size
83
The maximum size of the refcount block cache in bytes
27
--
84
--
28
1.8.3.1
85
2.13.6
29
86
30
87
diff view generated by jsdifflib
1
If no drive=... option is passed (for an empty drive), we don't only
1
From: Leonid Bloch <lbloch@janustech.com>
2
lack the BlockBackend normally created by parse_drive(), but we also
3
need to manually call blk_attach_dev().
4
2
5
IDE does not support hot unplug, but if it did, qdev would take care to
3
The caches are now recalculated upon image resizing. This is done
6
call the matching blk_detach_dev() on unplug.
4
because the new default behavior of assigning L2 cache relatively to
5
the image size, implies that the cache will be adapted accordingly
6
after an image resize.
7
7
8
This fixes at least the bug that such devices didn't show up in
8
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
9
query-block, and probably some more problems.
9
Reviewed-by: Alberto Garcia <berto@igalia.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
block/qcow2.c | 11 +++++++++++
13
1 file changed, 11 insertions(+)
10
14
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
diff --git a/block/qcow2.c b/block/qcow2.c
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: John Snow <jsnow@redhat.com>
14
---
15
hw/ide/qdev.c | 3 +++
16
1 file changed, 3 insertions(+)
17
18
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
19
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/ide/qdev.c
17
--- a/block/qcow2.c
21
+++ b/hw/ide/qdev.c
18
+++ b/block/qcow2.c
22
@@ -XXX,XX +XXX,XX @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
19
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
23
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
20
uint64_t old_length;
24
IDEState *s = bus->ifs + dev->unit;
21
int64_t new_l1_size;
25
Error *err = NULL;
22
int ret;
26
+ int ret;
23
+ QDict *options;
27
24
28
if (!dev->conf.blk) {
25
if (prealloc != PREALLOC_MODE_OFF && prealloc != PREALLOC_MODE_METADATA &&
29
if (kind != IDE_CD) {
26
prealloc != PREALLOC_MODE_FALLOC && prealloc != PREALLOC_MODE_FULL)
30
@@ -XXX,XX +XXX,XX @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
27
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
31
} else {
32
/* Anonymous BlockBackend for an empty drive */
33
dev->conf.blk = blk_new(0, BLK_PERM_ALL);
34
+ ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
35
+ assert(ret == 0);
36
}
28
}
37
}
29
}
38
30
31
+ bs->total_sectors = offset / BDRV_SECTOR_SIZE;
32
+
33
/* write updated header.size */
34
offset = cpu_to_be64(offset);
35
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size),
36
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
37
}
38
39
s->l1_vm_state_index = new_l1_size;
40
+
41
+ /* Update cache sizes */
42
+ options = qdict_clone_shallow(bs->options);
43
+ ret = qcow2_update_options(bs, options, s->flags, errp);
44
+ qobject_unref(options);
45
+ if (ret < 0) {
46
+ goto fail;
47
+ }
48
ret = 0;
49
fail:
50
qemu_co_mutex_unlock(&s->lock);
39
--
51
--
40
1.8.3.1
52
2.13.6
41
53
42
54
diff view generated by jsdifflib
1
From: Hervé Poussineau <hpoussin@reactos.org>
1
From: Leonid Bloch <lbloch@janustech.com>
2
2
3
Also add links to related compatibility problems.
3
The default cache-clean-interval is set to 10 minutes, in order to lower
4
the overhead of the qcow2 caches (before the default was 0, i.e.
5
disabled).
4
6
5
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
7
* For non-Linux platforms the default is kept at 0, because
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
cache-clean-interval is not supported there yet.
9
10
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
11
Reviewed-by: Alberto Garcia <berto@igalia.com>
12
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
14
---
9
block/vvfat.c | 8 +++++++-
15
qapi/block-core.json | 3 ++-
10
1 file changed, 7 insertions(+), 1 deletion(-)
16
docs/qcow2-cache.txt | 4 ++--
17
block/qcow2.h | 4 +++-
18
block/qcow2.c | 2 +-
19
qemu-options.hx | 2 +-
20
5 files changed, 9 insertions(+), 6 deletions(-)
11
21
12
diff --git a/block/vvfat.c b/block/vvfat.c
22
diff --git a/qapi/block-core.json b/qapi/block-core.json
13
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
14
--- a/block/vvfat.c
24
--- a/qapi/block-core.json
15
+++ b/block/vvfat.c
25
+++ b/qapi/block-core.json
16
@@ -XXX,XX +XXX,XX @@ void nonono(const char* file, int line, const char* msg) {
26
@@ -XXX,XX +XXX,XX @@
17
27
#
28
# @cache-clean-interval: clean unused entries in the L2 and refcount
29
# caches. The interval is in seconds. The default value
30
-# is 0 and it disables this feature (since 2.5)
31
+# is 600, and 0 disables this feature. (since 2.5)
32
+#
33
# @encrypt: Image decryption options. Mandatory for
34
# encrypted images, except when doing a metadata-only
35
# probe of the image. (since 2.10)
36
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt
37
index XXXXXXX..XXXXXXX 100644
38
--- a/docs/qcow2-cache.txt
39
+++ b/docs/qcow2-cache.txt
40
@@ -XXX,XX +XXX,XX @@ This example removes all unused cache entries every 15 minutes:
41
42
-drive file=hd.qcow2,cache-clean-interval=900
43
44
-If unset, the default value for this parameter is 0 and it disables
45
-this feature.
46
+If unset, the default value for this parameter is 600. Setting it to 0
47
+disables this feature.
48
49
Note that this functionality currently relies on the MADV_DONTNEED
50
argument for madvise() to actually free the memory. This is a
51
diff --git a/block/qcow2.h b/block/qcow2.h
52
index XXXXXXX..XXXXXXX 100644
53
--- a/block/qcow2.h
54
+++ b/block/qcow2.h
55
@@ -XXX,XX +XXX,XX @@
56
57
#ifdef CONFIG_LINUX
58
#define DEFAULT_L2_CACHE_MAX_SIZE S_32MiB
59
+#define DEFAULT_CACHE_CLEAN_INTERVAL 600 /* seconds */
60
#else
61
#define DEFAULT_L2_CACHE_MAX_SIZE S_8MiB
62
+/* Cache clean interval is currently available only on Linux, so must be 0 */
63
+#define DEFAULT_CACHE_CLEAN_INTERVAL 0
18
#endif
64
#endif
19
65
20
+/* bootsector OEM name. see related compatibility problems at:
66
#define DEFAULT_CLUSTER_SIZE S_64KiB
21
+ * https://jdebp.eu/FGA/volume-boot-block-oem-name-field.html
67
22
+ * http://seasip.info/Misc/oemid.html
68
-
23
+ */
69
#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
24
+#define BOOTSECTOR_OEM_NAME "MSWIN4.1"
70
#define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
25
+
71
#define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
26
#define DIR_DELETED 0xe5
72
diff --git a/block/qcow2.c b/block/qcow2.c
27
#define DIR_KANJI DIR_DELETED
73
index XXXXXXX..XXXXXXX 100644
28
#define DIR_KANJI_FAKE 0x05
74
--- a/block/qcow2.c
29
@@ -XXX,XX +XXX,XX @@ static int init_directories(BDRVVVFATState* s,
75
+++ b/block/qcow2.c
30
bootsector->jump[0]=0xeb;
76
@@ -XXX,XX +XXX,XX @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
31
bootsector->jump[1]=0x3e;
77
/* New interval for cache cleanup timer */
32
bootsector->jump[2]=0x90;
78
r->cache_clean_interval =
33
- memcpy(bootsector->name, "MSWIN4.1", 8);
79
qemu_opt_get_number(opts, QCOW2_OPT_CACHE_CLEAN_INTERVAL,
34
+ memcpy(bootsector->name, BOOTSECTOR_OEM_NAME, 8);
80
- s->cache_clean_interval);
35
bootsector->sector_size=cpu_to_le16(0x200);
81
+ DEFAULT_CACHE_CLEAN_INTERVAL);
36
bootsector->sectors_per_cluster=s->sectors_per_cluster;
82
#ifndef CONFIG_LINUX
37
bootsector->reserved_sectors=cpu_to_le16(1);
83
if (r->cache_clean_interval != 0) {
84
error_setg(errp, QCOW2_OPT_CACHE_CLEAN_INTERVAL
85
diff --git a/qemu-options.hx b/qemu-options.hx
86
index XXXXXXX..XXXXXXX 100644
87
--- a/qemu-options.hx
88
+++ b/qemu-options.hx
89
@@ -XXX,XX +XXX,XX @@ it which is not used for the L2 cache)
90
91
@item cache-clean-interval
92
Clean unused entries in the L2 and refcount caches. The interval is in seconds.
93
-The default value is 0 and it disables this feature.
94
+The default value is 600. Setting it to 0 disables this feature.
95
96
@item pass-discard-request
97
Whether discard requests to the qcow2 device should be forwarded to the data
38
--
98
--
39
1.8.3.1
99
2.13.6
40
100
41
101
diff view generated by jsdifflib
1
From: Peter Maydell <peter.maydell@linaro.org>
1
From: Leonid Bloch <lbloch@janustech.com>
2
2
3
Coverity (CID 1355236) points out that get_image_offset() doesn't check that
3
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
4
it actually succeeded in writing the updated block bitmap to the file.
4
Reviewed-by: Alberto Garcia <berto@igalia.com>
5
Check the error return from bdrv_pwrite_sync() and propagate an error
5
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
6
response back up to the function which calls get_image_offset() for
7
a write so that it can return the error to its caller.
8
9
get_sector_offset() is only used for reads, but we move it to the
10
same API for consistency.
11
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
7
---
15
block/vpc.c | 30 +++++++++++++++++++++++-------
8
block/qcow2.c | 4 ++--
16
1 file changed, 23 insertions(+), 7 deletions(-)
9
1 file changed, 2 insertions(+), 2 deletions(-)
17
10
18
diff --git a/block/vpc.c b/block/vpc.c
11
diff --git a/block/qcow2.c b/block/qcow2.c
19
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
20
--- a/block/vpc.c
13
--- a/block/qcow2.c
21
+++ b/block/vpc.c
14
+++ b/block/qcow2.c
22
@@ -XXX,XX +XXX,XX @@ static int vpc_reopen_prepare(BDRVReopenState *state,
15
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
23
/*
16
/* 2^(s->refcount_order - 3) is the refcount width in bytes */
24
* Returns the absolute byte offset of the given sector in the image file.
17
s->refcount_block_bits = s->cluster_bits - (s->refcount_order - 3);
25
* If the sector is not allocated, -1 is returned instead.
18
s->refcount_block_size = 1 << s->refcount_block_bits;
26
+ * If an error occurred trying to write an updated block bitmap back to
19
- bs->total_sectors = header.size / 512;
27
+ * the file, -2 is returned, and the error value is written to *err.
20
+ bs->total_sectors = header.size / BDRV_SECTOR_SIZE;
28
+ * This can only happen for a write operation.
21
s->csize_shift = (62 - (s->cluster_bits - 8));
29
*
22
s->csize_mask = (1 << (s->cluster_bits - 8)) - 1;
30
* The parameter write must be 1 if the offset will be used for a write
23
s->cluster_offset_mask = (1LL << s->csize_shift) - 1;
31
* operation (the block bitmaps is updated then), 0 otherwise.
24
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
32
+ * If write is true then err must not be NULL.
25
goto fail;
33
*/
34
static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
35
- bool write)
36
+ bool write, int *err)
37
{
38
BDRVVPCState *s = bs->opaque;
39
uint64_t bitmap_offset, block_offset;
40
uint32_t pagetable_index, offset_in_block;
41
42
+ assert(!(write && err == NULL));
43
+
44
pagetable_index = offset / s->block_size;
45
offset_in_block = offset % s->block_size;
46
47
@@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
48
correctness. */
49
if (write && (s->last_bitmap_offset != bitmap_offset)) {
50
uint8_t bitmap[s->bitmap_size];
51
+ int r;
52
53
s->last_bitmap_offset = bitmap_offset;
54
memset(bitmap, 0xff, s->bitmap_size);
55
- bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size);
56
+ r = bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size);
57
+ if (r < 0) {
58
+ *err = r;
59
+ return -2;
60
+ }
61
}
26
}
62
27
63
return block_offset;
28
- old_length = bs->total_sectors * 512;
64
@@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState* bs, int64_t offset)
29
+ old_length = bs->total_sectors * BDRV_SECTOR_SIZE;
65
if (ret < 0)
30
new_l1_size = size_to_l1(s, offset);
66
goto fail;
31
67
32
if (offset < old_length) {
68
- return get_image_offset(bs, offset, false);
69
+ return get_image_offset(bs, offset, false, NULL);
70
71
fail:
72
s->free_data_block_offset -= (s->block_size + s->bitmap_size);
73
@@ -XXX,XX +XXX,XX @@ vpc_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
74
qemu_iovec_init(&local_qiov, qiov->niov);
75
76
while (bytes > 0) {
77
- image_offset = get_image_offset(bs, offset, false);
78
+ image_offset = get_image_offset(bs, offset, false, NULL);
79
n_bytes = MIN(bytes, s->block_size - (offset % s->block_size));
80
81
if (image_offset == -1) {
82
@@ -XXX,XX +XXX,XX @@ vpc_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
83
qemu_iovec_init(&local_qiov, qiov->niov);
84
85
while (bytes > 0) {
86
- image_offset = get_image_offset(bs, offset, true);
87
+ image_offset = get_image_offset(bs, offset, true, &ret);
88
+ if (image_offset == -2) {
89
+ /* Failed to write block bitmap: can't proceed with write */
90
+ goto fail;
91
+ }
92
n_bytes = MIN(bytes, s->block_size - (offset % s->block_size));
93
94
if (image_offset == -1) {
95
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
96
97
qemu_co_mutex_lock(&s->lock);
98
99
- offset = get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false);
100
+ offset = get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false, NULL);
101
start = offset;
102
allocated = (offset != -1);
103
*pnum = 0;
104
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
105
if (nb_sectors == 0) {
106
break;
107
}
108
- offset = get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false);
109
+ offset = get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false,
110
+ NULL);
111
} while (offset == -1);
112
113
qemu_co_mutex_unlock(&s->lock);
114
--
33
--
115
1.8.3.1
34
2.13.6
116
35
117
36
diff view generated by jsdifflib
1
Currently, the default values for werror and rerror have to be set
2
explicitly with blk_set_on_error() by the callers of blk_new(). The only
3
caller actually doing this is blockdev_init(), which is called for
4
BlockBackends created using -drive.
5
6
In particular, anonymous BlockBackends created with
7
-device ...,drive=<node-name> didn't get the correct default set and
8
instead defaulted to the integer value 0 (= BLOCKDEV_ON_ERROR_REPORT).
9
This is the intended default for rerror anyway, but the default for
10
werror should be BLOCKDEV_ON_ERROR_ENOSPC.
11
12
Set the defaults in blk_new() instead so that they apply no matter what
13
way the BlockBackend was created.
14
15
Cc: qemu-stable@nongnu.org
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Eric Blake <eblake@redhat.com>
17
Reviewed-by: Eric Blake <eblake@redhat.com>
3
Reviewed-by: John Snow <jsnow@redhat.com>
18
Reviewed-by: Fam Zheng <famz@redhat.com>
4
---
19
---
5
block/block-backend.c | 3 +--
20
block/block-backend.c | 3 +++
6
include/sysemu/block-backend.h | 1 +
21
tests/qemu-iotests/067.out | 1 +
7
2 files changed, 2 insertions(+), 2 deletions(-)
22
2 files changed, 4 insertions(+)
8
23
9
diff --git a/block/block-backend.c b/block/block-backend.c
24
diff --git a/block/block-backend.c b/block/block-backend.c
10
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
11
--- a/block/block-backend.c
26
--- a/block/block-backend.c
12
+++ b/block/block-backend.c
27
+++ b/block/block-backend.c
13
@@ -XXX,XX +XXX,XX @@ static const AIOCBInfo block_backend_aiocb_info = {
28
@@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm)
14
29
blk->shared_perm = shared_perm;
15
static void drive_info_del(DriveInfo *dinfo);
30
blk_set_enable_write_cache(blk, true);
16
static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
31
17
-static char *blk_get_attached_dev_id(BlockBackend *blk);
32
+ blk->on_read_error = BLOCKDEV_ON_ERROR_REPORT;
18
33
+ blk->on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
19
/* All BlockBackends */
34
+
20
static QTAILQ_HEAD(, BlockBackend) block_backends =
35
block_acct_init(&blk->stats);
21
@@ -XXX,XX +XXX,XX @@ void *blk_get_attached_dev(BlockBackend *blk)
36
22
37
notifier_list_init(&blk->remove_bs_notifiers);
23
/* Return the qdev ID, or if no ID is assigned the QOM path, of the block
38
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
24
* device attached to the BlockBackend. */
39
index XXXXXXX..XXXXXXX 100644
25
-static char *blk_get_attached_dev_id(BlockBackend *blk)
40
--- a/tests/qemu-iotests/067.out
26
+char *blk_get_attached_dev_id(BlockBackend *blk)
41
+++ b/tests/qemu-iotests/067.out
42
@@ -XXX,XX +XXX,XX @@ Testing: -device virtio-scsi -device scsi-cd,id=cd0
27
{
43
{
28
DeviceState *dev;
44
"return": [
29
45
{
30
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
46
+ "io-status": "ok",
31
index XXXXXXX..XXXXXXX 100644
47
"device": "",
32
--- a/include/sysemu/block-backend.h
48
"locked": false,
33
+++ b/include/sysemu/block-backend.h
49
"removable": true,
34
@@ -XXX,XX +XXX,XX @@ int blk_attach_dev(BlockBackend *blk, DeviceState *dev);
35
void blk_attach_dev_legacy(BlockBackend *blk, void *dev);
36
void blk_detach_dev(BlockBackend *blk, void *dev);
37
void *blk_get_attached_dev(BlockBackend *blk);
38
+char *blk_get_attached_dev_id(BlockBackend *blk);
39
BlockBackend *blk_by_dev(void *dev);
40
BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
41
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
42
--
50
--
43
1.8.3.1
51
2.13.6
44
52
45
53
diff view generated by jsdifflib
1
With -blockdev/-device, users can indirectly create anonymous
1
From: Leonid Bloch <lbloch@janustech.com>
2
BlockBackends, while the state of such backends is still of interest. As
3
a preparation for making such BBs visible in query-block, make sure that
4
they can be identified even without a name by adding the ID/QOM path of
5
their qdev device to BlockInfo.
6
2
3
Fixing cache-clean-interval documentation following the recent change to
4
a default of 600 seconds on supported plarforms (only Linux currently).
5
6
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
---
9
---
10
block/qapi.c | 10 ++++++++++
10
qapi/block-core.json | 3 ++-
11
hmp.c | 3 +++
11
docs/qcow2-cache.txt | 20 ++++++++++----------
12
qapi/block-core.json | 9 ++++++++-
12
qemu-options.hx | 3 ++-
13
tests/qemu-iotests/067.out | 1 +
13
3 files changed, 14 insertions(+), 12 deletions(-)
14
4 files changed, 22 insertions(+), 1 deletion(-)
15
14
16
diff --git a/block/qapi.c b/block/qapi.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qapi.c
19
+++ b/block/qapi.c
20
@@ -XXX,XX +XXX,XX @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
21
{
22
BlockInfo *info = g_malloc0(sizeof(*info));
23
BlockDriverState *bs = blk_bs(blk);
24
+ char *qdev;
25
+
26
info->device = g_strdup(blk_name(blk));
27
info->type = g_strdup("unknown");
28
info->locked = blk_dev_is_medium_locked(blk);
29
info->removable = blk_dev_has_removable_media(blk);
30
31
+ qdev = blk_get_attached_dev_id(blk);
32
+ if (qdev && *qdev) {
33
+ info->has_qdev = true;
34
+ info->qdev = qdev;
35
+ } else {
36
+ g_free(qdev);
37
+ }
38
+
39
if (blk_dev_has_tray(blk)) {
40
info->has_tray_open = true;
41
info->tray_open = blk_dev_is_tray_open(blk);
42
diff --git a/hmp.c b/hmp.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/hmp.c
45
+++ b/hmp.c
46
@@ -XXX,XX +XXX,XX @@ static void print_block_info(Monitor *mon, BlockInfo *info,
47
}
48
49
if (info) {
50
+ if (info->has_qdev) {
51
+ monitor_printf(mon, " Attached to: %s\n", info->qdev);
52
+ }
53
if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
54
monitor_printf(mon, " I/O status: %s\n",
55
BlockDeviceIoStatus_lookup[info->io_status]);
56
diff --git a/qapi/block-core.json b/qapi/block-core.json
15
diff --git a/qapi/block-core.json b/qapi/block-core.json
57
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
58
--- a/qapi/block-core.json
17
--- a/qapi/block-core.json
59
+++ b/qapi/block-core.json
18
+++ b/qapi/block-core.json
60
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
61
#
20
#
62
# @device: The device name associated with the virtual device.
21
# @cache-clean-interval: clean unused entries in the L2 and refcount
22
# caches. The interval is in seconds. The default value
23
-# is 600, and 0 disables this feature. (since 2.5)
24
+# is 600 on supporting platforms, and 0 on other
25
+# platforms. 0 disables this feature. (since 2.5)
63
#
26
#
64
+# @qdev: The qdev ID, or if no ID is assigned, the QOM path of the block
27
# @encrypt: Image decryption options. Mandatory for
65
+# device. (since 2.10)
28
# encrypted images, except when doing a metadata-only
66
+#
29
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt
67
# @type: This field is returned only for compatibility reasons, it should
68
# not be used (always returns 'unknown')
69
#
70
@@ -XXX,XX +XXX,XX @@
71
# Since: 0.14.0
72
##
73
{ 'struct': 'BlockInfo',
74
- 'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
75
+ 'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'bool',
76
'locked': 'bool', '*inserted': 'BlockDeviceInfo',
77
'*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus',
78
'*dirty-bitmaps': ['BlockDirtyInfo'] } }
79
@@ -XXX,XX +XXX,XX @@
80
# }
81
# }
82
# },
83
+# "qdev": "ide_disk",
84
# "type":"unknown"
85
# },
86
# {
87
@@ -XXX,XX +XXX,XX @@
88
# "device":"ide1-cd0",
89
# "locked":false,
90
# "removable":true,
91
+# "qdev": "/machine/unattached/device[23]",
92
+# "tray_open": false,
93
# "type":"unknown"
94
# },
95
# {
96
# "device":"floppy0",
97
# "locked":false,
98
# "removable":true,
99
+# "qdev": "/machine/unattached/device[20]",
100
# "type":"unknown"
101
# },
102
# {
103
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
104
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
105
--- a/tests/qemu-iotests/067.out
31
--- a/docs/qcow2-cache.txt
106
+++ b/tests/qemu-iotests/067.out
32
+++ b/docs/qcow2-cache.txt
107
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
33
@@ -XXX,XX +XXX,XX @@ Reducing the memory usage
108
"file": "TEST_DIR/t.qcow2",
34
It is possible to clean unused cache entries in order to reduce the
109
"encryption_key_missing": false
35
memory usage during periods of low I/O activity.
110
},
36
111
+ "qdev": "/machine/peripheral/virtio0/virtio-backend",
37
-The parameter "cache-clean-interval" defines an interval (in seconds).
112
"type": "unknown"
38
-All cache entries that haven't been accessed during that interval are
113
}
39
-removed from memory.
114
]
40
+The parameter "cache-clean-interval" defines an interval (in seconds),
41
+after which all the cache entries that haven't been accessed during the
42
+interval are removed from memory. Setting this parameter to 0 disables this
43
+feature.
44
45
-This example removes all unused cache entries every 15 minutes:
46
+The following example removes all unused cache entries every 15 minutes:
47
48
-drive file=hd.qcow2,cache-clean-interval=900
49
50
-If unset, the default value for this parameter is 600. Setting it to 0
51
-disables this feature.
52
+If unset, the default value for this parameter is 600 on platforms which
53
+support this functionality, and is 0 (disabled) on other platforms.
54
55
-Note that this functionality currently relies on the MADV_DONTNEED
56
-argument for madvise() to actually free the memory. This is a
57
-Linux-specific feature, so cache-clean-interval is not supported in
58
-other systems.
59
+This functionality currently relies on the MADV_DONTNEED argument for
60
+madvise() to actually free the memory. This is a Linux-specific feature,
61
+so cache-clean-interval is not supported on other systems.
62
diff --git a/qemu-options.hx b/qemu-options.hx
63
index XXXXXXX..XXXXXXX 100644
64
--- a/qemu-options.hx
65
+++ b/qemu-options.hx
66
@@ -XXX,XX +XXX,XX @@ it which is not used for the L2 cache)
67
68
@item cache-clean-interval
69
Clean unused entries in the L2 and refcount caches. The interval is in seconds.
70
-The default value is 600. Setting it to 0 disables this feature.
71
+The default value is 600 on supporting platforms, and 0 on other platforms.
72
+Setting it to 0 disables this feature.
73
74
@item pass-discard-request
75
Whether discard requests to the qcow2 device should be forwarded to the data
115
--
76
--
116
1.8.3.1
77
2.13.6
117
78
118
79
diff view generated by jsdifflib
1
From: Peter Maydell <peter.maydell@linaro.org>
1
Recently, the test case has started failing because some job related
2
functions want to drop the AioContext lock even though it hasn't been
3
taken:
2
4
3
The function vmdk_read_cid() can fail if the read on the underlying
5
(gdb) bt
4
block device fails, or if there's a format error in the VMDK file.
6
#0 0x00007f51c067c9fb in raise () from /lib64/libc.so.6
5
However its API doesn't provide a mechanism to report these errors,
7
#1 0x00007f51c067e77d in abort () from /lib64/libc.so.6
6
and in some cases we were returning a CID of 0 and in some cases a
8
#2 0x0000558c9d5dde7b in error_exit (err=<optimized out>, msg=msg@entry=0x558c9d6fe120 <__func__.18373> "qemu_mutex_unlock_impl") at util/qemu-thread-posix.c:36
7
CID of 0xffffffff, either of which might potentially be valid values.
9
#3 0x0000558c9d6b5263 in qemu_mutex_unlock_impl (mutex=mutex@entry=0x558c9f3999a0, file=file@entry=0x558c9d6fd36f "util/async.c", line=line@entry=516) at util/qemu-thread-posix.c:96
10
#4 0x0000558c9d6b0565 in aio_context_release (ctx=ctx@entry=0x558c9f399940) at util/async.c:516
11
#5 0x0000558c9d5eb3da in job_completed_txn_abort (job=0x558c9f68e640) at job.c:738
12
#6 0x0000558c9d5eb227 in job_finish_sync (job=0x558c9f68e640, finish=finish@entry=0x558c9d5eb8d0 <job_cancel_err>, errp=errp@entry=0x0) at job.c:986
13
#7 0x0000558c9d5eb8ee in job_cancel_sync (job=<optimized out>) at job.c:941
14
#8 0x0000558c9d64d853 in replication_close (bs=<optimized out>) at block/replication.c:148
15
#9 0x0000558c9d5e5c9f in bdrv_close (bs=0x558c9f41b020) at block.c:3420
16
#10 bdrv_delete (bs=0x558c9f41b020) at block.c:3629
17
#11 bdrv_unref (bs=0x558c9f41b020) at block.c:4685
18
#12 0x0000558c9d62a3f3 in blk_remove_bs (blk=blk@entry=0x558c9f42a7c0) at block/block-backend.c:783
19
#13 0x0000558c9d62a667 in blk_delete (blk=0x558c9f42a7c0) at block/block-backend.c:402
20
#14 blk_unref (blk=0x558c9f42a7c0) at block/block-backend.c:457
21
#15 0x0000558c9d5dfcea in test_secondary_stop () at tests/test-replication.c:478
22
#16 0x00007f51c1f13178 in g_test_run_suite_internal () from /lib64/libglib-2.0.so.0
23
#17 0x00007f51c1f1337b in g_test_run_suite_internal () from /lib64/libglib-2.0.so.0
24
#18 0x00007f51c1f1337b in g_test_run_suite_internal () from /lib64/libglib-2.0.so.0
25
#19 0x00007f51c1f13552 in g_test_run_suite () from /lib64/libglib-2.0.so.0
26
#20 0x00007f51c1f13571 in g_test_run () from /lib64/libglib-2.0.so.0
27
#21 0x0000558c9d5de31f in main (argc=<optimized out>, argv=<optimized out>) at tests/test-replication.c:581
8
28
9
Change the function to return 0 on success or a negative errno, and
29
It is yet unclear whether this should really be considered a bug in the
10
return the CID via a uint32_t* argument. Update the callsites to
30
test case or whether blk_unref() should work for callers that haven't
11
handle and propagate the error appropriately.
31
taken the AioContext lock, but in order to fix the build tests quickly,
32
just take the AioContext lock around blk_unref().
12
33
13
This fixes in passing a Coverity-spotted issue (CID 1350038) where
14
we weren't checking the return value from sscanf().
15
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Fam Zheng <famz@redhat.com>
18
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
19
---
35
---
20
block/vmdk.c | 44 ++++++++++++++++++++++++++++++++------------
36
tests/test-replication.c | 11 +++++++++++
21
1 file changed, 32 insertions(+), 12 deletions(-)
37
1 file changed, 11 insertions(+)
22
38
23
diff --git a/block/vmdk.c b/block/vmdk.c
39
diff --git a/tests/test-replication.c b/tests/test-replication.c
24
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
25
--- a/block/vmdk.c
41
--- a/tests/test-replication.c
26
+++ b/block/vmdk.c
42
+++ b/tests/test-replication.c
27
@@ -XXX,XX +XXX,XX @@ static void vmdk_free_last_extent(BlockDriverState *bs)
43
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_primary(void)
28
s->extents = g_renew(VmdkExtent, s->extents, s->num_extents);
44
static void teardown_primary(void)
45
{
46
BlockBackend *blk;
47
+ AioContext *ctx;
48
49
/* remove P_ID */
50
blk = blk_by_name(P_ID);
51
assert(blk);
52
53
+ ctx = blk_get_aio_context(blk);
54
+ aio_context_acquire(ctx);
55
monitor_remove_blk(blk);
56
blk_unref(blk);
57
+ aio_context_release(ctx);
29
}
58
}
30
59
31
-static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
60
static void test_primary_read(void)
32
+/* Return -ve errno, or 0 on success and write CID into *pcid. */
61
@@ -XXX,XX +XXX,XX @@ static void teardown_secondary(void)
33
+static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid)
34
{
62
{
35
char *desc;
63
/* only need to destroy two BBs */
36
- uint32_t cid = 0xffffffff;
64
BlockBackend *blk;
37
+ uint32_t cid;
65
+ AioContext *ctx;
38
const char *p_name, *cid_str;
66
39
size_t cid_str_size;
67
/* remove S_LOCAL_DISK_ID */
40
BDRVVmdkState *s = bs->opaque;
68
blk = blk_by_name(S_LOCAL_DISK_ID);
41
@@ -XXX,XX +XXX,XX @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
69
assert(blk);
42
desc = g_malloc0(DESC_SIZE);
70
43
ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
71
+ ctx = blk_get_aio_context(blk);
44
if (ret < 0) {
72
+ aio_context_acquire(ctx);
45
- g_free(desc);
73
monitor_remove_blk(blk);
46
- return 0;
74
blk_unref(blk);
47
+ goto out;
75
+ aio_context_release(ctx);
48
}
76
49
77
/* remove S_ID */
50
if (parent) {
78
blk = blk_by_name(S_ID);
51
@@ -XXX,XX +XXX,XX @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
79
assert(blk);
52
80
53
desc[DESC_SIZE - 1] = '\0';
81
+ ctx = blk_get_aio_context(blk);
54
p_name = strstr(desc, cid_str);
82
+ aio_context_acquire(ctx);
55
- if (p_name != NULL) {
83
monitor_remove_blk(blk);
56
- p_name += cid_str_size;
84
blk_unref(blk);
57
- sscanf(p_name, "%" SCNx32, &cid);
85
+ aio_context_release(ctx);
58
+ if (p_name == NULL) {
59
+ ret = -EINVAL;
60
+ goto out;
61
}
62
+ p_name += cid_str_size;
63
+ if (sscanf(p_name, "%" SCNx32, &cid) != 1) {
64
+ ret = -EINVAL;
65
+ goto out;
66
+ }
67
+ *pcid = cid;
68
+ ret = 0;
69
70
+out:
71
g_free(desc);
72
- return cid;
73
+ return ret;
74
}
86
}
75
87
76
static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
88
static void test_secondary_read(void)
77
@@ -XXX,XX +XXX,XX @@ static int vmdk_is_cid_valid(BlockDriverState *bs)
78
if (!s->cid_checked && bs->backing) {
79
BlockDriverState *p_bs = bs->backing->bs;
80
81
- cur_pcid = vmdk_read_cid(p_bs, 0);
82
+ if (vmdk_read_cid(p_bs, 0, &cur_pcid) != 0) {
83
+ /* read failure: report as not valid */
84
+ return 0;
85
+ }
86
if (s->parent_cid != cur_pcid) {
87
/* CID not valid */
88
return 0;
89
@@ -XXX,XX +XXX,XX @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
90
if (ret) {
91
goto fail;
92
}
93
- s->cid = vmdk_read_cid(bs, 0);
94
- s->parent_cid = vmdk_read_cid(bs, 1);
95
+ ret = vmdk_read_cid(bs, 0, &s->cid);
96
+ if (ret) {
97
+ goto fail;
98
+ }
99
+ ret = vmdk_read_cid(bs, 1, &s->parent_cid);
100
+ if (ret) {
101
+ goto fail;
102
+ }
103
qemu_co_mutex_init(&s->lock);
104
105
/* Disable migration when VMDK images are used */
106
@@ -XXX,XX +XXX,XX @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
107
ret = -EINVAL;
108
goto exit;
109
}
110
- parent_cid = vmdk_read_cid(blk_bs(blk), 0);
111
+ ret = vmdk_read_cid(blk_bs(blk), 0, &parent_cid);
112
blk_unref(blk);
113
+ if (ret) {
114
+ goto exit;
115
+ }
116
snprintf(parent_desc_line, BUF_SIZE,
117
"parentFileNameHint=\"%s\"", backing_file);
118
}
119
--
89
--
120
1.8.3.1
90
2.13.6
121
91
122
92
diff view generated by jsdifflib
1
This patch replaces the blk_next() loop in query-block by a
1
qemu_event_reset() must be called before the AIO request in a different
2
blk_all_next() one so that we also get access to BlockBackends that
2
iothread is submitted. Otherwise the request could be completed before
3
aren't owned by the monitor. For now, the next thing we do is check
3
we do the qemu_event_reset() and the test would hang in
4
whether each BB has a name, so there is no semantic difference.
4
qemu_event_wait().
5
5
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
8
Tested-by: Max Reitz <mreitz@redhat.com>
9
---
9
---
10
block/qapi.c | 10 ++++++++--
10
tests/test-bdrv-drain.c | 4 ++--
11
1 file changed, 8 insertions(+), 2 deletions(-)
11
1 file changed, 2 insertions(+), 2 deletions(-)
12
12
13
diff --git a/block/qapi.c b/block/qapi.c
13
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block/qapi.c
15
--- a/tests/test-bdrv-drain.c
16
+++ b/block/qapi.c
16
+++ b/tests/test-bdrv-drain.c
17
@@ -XXX,XX +XXX,XX @@ BlockInfoList *qmp_query_block(Error **errp)
17
@@ -XXX,XX +XXX,XX @@ static void test_iothread_common(enum drain_type drain_type, int drain_thread)
18
BlockBackend *blk;
18
s->bh_indirection_ctx = ctx_b;
19
Error *local_err = NULL;
19
20
20
aio_ret = -EINPROGRESS;
21
- for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
21
+ qemu_event_reset(&done_event);
22
- BlockInfoList *info = g_malloc0(sizeof(*info));
23
+ for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
24
+ BlockInfoList *info;
25
+
22
+
26
+ if (!*blk_name(blk)) {
23
if (drain_thread == 0) {
27
+ continue;
24
acb = blk_aio_preadv(blk, 0, &qiov, 0, test_iothread_aio_cb, &aio_ret);
28
+ }
25
} else {
29
+
26
@@ -XXX,XX +XXX,XX @@ static void test_iothread_common(enum drain_type drain_type, int drain_thread)
30
+ info = g_malloc0(sizeof(*info));
27
* but the drain in this thread can continue immediately after
31
bdrv_query_info(blk, &info->value, &local_err);
28
* bdrv_dec_in_flight() and aio_ret might be assigned only slightly
32
if (local_err) {
29
* later. */
33
error_propagate(errp, local_err);
30
- qemu_event_reset(&done_event);
31
do_drain_begin(drain_type, bs);
32
g_assert_cmpint(bs->in_flight, ==, 0);
33
34
@@ -XXX,XX +XXX,XX @@ static void test_iothread_common(enum drain_type drain_type, int drain_thread)
35
}
36
break;
37
case 1:
38
- qemu_event_reset(&done_event);
39
aio_bh_schedule_oneshot(ctx_a, test_iothread_drain_entry, &data);
40
qemu_event_wait(&done_event);
41
break;
34
--
42
--
35
1.8.3.1
43
2.13.6
36
44
37
45
diff view generated by jsdifflib