1
The following changes since commit 76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb:
1
The following changes since commit 281f327487c9c9b1599f93c589a408bbf4a651b8:
2
2
3
Merge remote-tracking branch 'armbru/tags/pull-qapi-2017-05-04-v3' into staging (2017-05-09 15:49:14 -0400)
3
Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-2.12-pull-request' into staging (2017-12-22 00:11:36 +0000)
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 d541e201bd3ad888f02abeddf0e14f7b0c126529:
9
for you to fetch changes up to 1a63a907507fbbcfaee3f622907ec244b7eabda8:
11
10
12
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block (2017-05-11 14:34:56 +0200)
11
block: Keep nodes drained between reopen_queue/multiple (2017-12-22 15:05:32 +0100)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
15
16
Block layer patches
14
Block layer patches
17
15
18
----------------------------------------------------------------
16
----------------------------------------------------------------
19
Anton Nefedov (1):
17
Doug Gale (1):
20
qemu-img: wait for convert coroutines to complete
18
nvme: Add tracing
21
19
22
Christoph Hellwig (1):
20
Edgar Kaziakhmedov (1):
23
nvme: Implement Write Zeroes
21
qcow2: get rid of qcow2_backing_read1 routine
24
22
25
Eric Blake (21):
23
Fam Zheng (2):
26
qemu-io: Improve alignment checks
24
block: Open backing image in force share mode for size probe
27
qemu-io: Switch 'alloc' command to byte-based length
25
block: Remove unused bdrv_requests_pending
28
qemu-io: Switch 'map' output to byte-based reporting
29
blkdebug: Sanity check block layer guarantees
30
blkdebug: Refactor error injection
31
blkdebug: Add pass-through write_zero and discard support
32
blkdebug: Simplify override logic
33
blkdebug: Add ability to override unmap geometries
34
tests: Add coverage for recent block geometry fixes
35
qcow2: Nicer variable names in qcow2_update_snapshot_refcount()
36
qcow2: Use consistent switch indentation
37
block: Update comments on BDRV_BLOCK_* meanings
38
qcow2: Correctly report status of preallocated zero clusters
39
qcow2: Name typedef for cluster type
40
qcow2: Make distinction between zero cluster types obvious
41
qcow2: Optimize zero_single_l2() to minimize L2 churn
42
iotests: Improve _filter_qemu_img_map
43
iotests: Add test 179 to cover write zeroes with unmap
44
qcow2: Optimize write zero of unaligned tail cluster
45
qcow2: Assert that cluster operations are aligned
46
qcow2: Discard/zero clusters by byte count
47
48
Fam Zheng (23):
49
block: Make bdrv_perm_names public
50
block: Add, parse and store "force-share" option
51
block: Respect "force-share" in perm propagating
52
qemu-img: Add --force-share option to subcommands
53
qemu-img: Update documentation for -U
54
qemu-io: Add --force-share option
55
iotests: 030: Prepare for image locking
56
iotests: 046: Prepare for image locking
57
iotests: 055: Don't attach the target image already for drive-backup
58
iotests: 085: Avoid image locking conflict
59
iotests: 087: Don't attach test image twice
60
iotests: 091: Quit QEMU before checking image
61
iotests: 172: Use separate images for multiple devices
62
tests: Use null-co:// instead of /dev/null as the dummy image
63
file-posix: Add 'locking' option
64
file-win32: Error out if locking=on
65
tests: Disable image lock in test-replication
66
block: Reuse bs as backing hd for drive-backup sync=none
67
osdep: Add qemu_lock_fd and qemu_unlock_fd
68
osdep: Fall back to posix lock when OFD lock is unavailable
69
file-posix: Add image locking to perm operations
70
qemu-iotests: Add test case 153 for image locking
71
tests: Add POSIX image locking test case 182
72
26
73
John Snow (1):
27
John Snow (1):
74
blockdev: use drained_begin/end for qmp_block_resize
28
iotests: fix 197 for vpc
75
29
76
Kevin Wolf (7):
30
Kevin Wolf (27):
77
migration: Unify block node activation error handling
31
block: Formats don't need CONSISTENT_READ with NO_IO
78
block: New BdrvChildRole.activate() for blk_resume_after_migration()
32
block: Make bdrv_drain_invoke() recursive
79
block: Drop permissions when migration completes
33
block: Call .drain_begin only once in bdrv_drain_all_begin()
80
block: Inactivate parents before children
34
test-bdrv-drain: Test BlockDriver callbacks for drain
81
block: Fix write/resize permissions for inactive images
35
block: bdrv_drain_recurse(): Remove unused begin parameter
82
file-posix: Remove .bdrv_inactivate/invalidate_cache
36
block: Don't wait for requests in bdrv_drain*_end()
83
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block
37
block: Unify order in drain functions
38
block: Don't acquire AioContext in hmp_qemu_io()
39
block: Document that x-blockdev-change breaks quorum children list
40
block: Assert drain_all is only called from main AioContext
41
block: Make bdrv_drain() driver callbacks non-recursive
42
test-bdrv-drain: Test callback for bdrv_drain
43
test-bdrv-drain: Test bs->quiesce_counter
44
blockjob: Pause job on draining any job BDS
45
test-bdrv-drain: Test drain vs. block jobs
46
block: Don't block_job_pause_all() in bdrv_drain_all()
47
block: Nested drain_end must still call callbacks
48
test-bdrv-drain: Test nested drain sections
49
block: Don't notify parents in drain call chain
50
block: Add bdrv_subtree_drained_begin/end()
51
test-bdrv-drain: Tests for bdrv_subtree_drain
52
test-bdrv-drain: Test behaviour in coroutine context
53
test-bdrv-drain: Recursive draining with multiple parents
54
block: Allow graph changes in subtree drained section
55
test-bdrv-drain: Test graph changes in drained section
56
commit: Simplify reopen of base
57
block: Keep nodes drained between reopen_queue/multiple
84
58
85
Max Reitz (5):
59
Thomas Huth (3):
86
qcow2: Fix preallocation size formula
60
block: Remove the obsolete -drive boot=on|off parameter
87
qcow2: Reuse preallocated zero clusters
61
block: Remove the deprecated -hdachs option
88
qcow2: Discard preallocated zero clusters
62
block: Mention -drive cyls/heads/secs/trans/serial/addr in deprecation chapter
89
iotests: Extend test 066
90
MAINTAINERS: Add qemu-progress to the block layer
91
63
92
MAINTAINERS | 1 +
64
qapi/block-core.json | 4 +
93
block.c | 127 +++++++++++--
65
block/qcow2.h | 3 -
94
block/blkdebug.c | 264 +++++++++++++++++++++-----
66
include/block/block.h | 15 +-
95
block/block-backend.c | 81 +++++---
67
include/block/block_int.h | 6 +-
96
block/file-posix.c | 248 +++++++++++++++++++++++-
68
block.c | 75 ++++-
97
block/file-win32.c | 5 +
69
block/commit.c | 8 +-
98
block/qcow2-cluster.c | 252 ++++++++++++++----------
70
block/io.c | 164 +++++++---
99
block/qcow2-refcount.c | 148 +++++++--------
71
block/qcow2.c | 51 +--
100
block/qcow2-snapshot.c | 7 +-
72
block/replication.c | 6 +
101
block/qcow2.c | 47 +++--
73
blockdev.c | 11 -
102
block/qcow2.h | 26 ++-
74
blockjob.c | 22 +-
103
blockdev.c | 20 +-
75
hmp.c | 6 -
104
hw/block/nvme.c | 26 +++
76
hw/block/nvme.c | 349 +++++++++++++++++----
105
hw/block/nvme.h | 1 +
77
qemu-io-cmds.c | 3 +
106
include/block/block.h | 41 ++--
78
tests/test-bdrv-drain.c | 651 +++++++++++++++++++++++++++++++++++++++
107
include/block/block_int.h | 14 ++
79
vl.c | 86 +-----
108
include/qemu/osdep.h | 3 +
80
hw/block/trace-events | 93 ++++++
109
migration/migration.c | 13 +-
81
qemu-doc.texi | 29 +-
110
migration/savevm.c | 9 +-
82
qemu-options.hx | 19 +-
111
qapi/block-core.json | 40 +++-
83
tests/Makefile.include | 2 +
112
qemu-img-cmds.hx | 36 ++--
84
tests/qemu-iotests/197 | 4 +
113
qemu-img.c | 179 ++++++++++++-----
85
tests/qemu-iotests/common.filter | 3 +-
114
qemu-io-cmds.c | 61 +++---
86
22 files changed, 1294 insertions(+), 316 deletions(-)
115
qemu-io.c | 42 +++-
87
create mode 100644 tests/test-bdrv-drain.c
116
qmp.c | 18 +-
117
tests/drive_del-test.c | 2 +-
118
tests/nvme-test.c | 2 +-
119
tests/qemu-iotests/019.out | 8 +-
120
tests/qemu-iotests/030 | 18 +-
121
tests/qemu-iotests/046 | 2 +-
122
tests/qemu-iotests/055 | 32 ++--
123
tests/qemu-iotests/060.out | 6 +-
124
tests/qemu-iotests/066 | 128 ++++++++++++-
125
tests/qemu-iotests/066.out | 46 +++++
126
tests/qemu-iotests/085 | 33 ++--
127
tests/qemu-iotests/085.out | 3 +-
128
tests/qemu-iotests/087 | 6 +-
129
tests/qemu-iotests/091 | 2 +
130
tests/qemu-iotests/102.out | 4 +-
131
tests/qemu-iotests/122.out | 16 +-
132
tests/qemu-iotests/146.out | 30 +--
133
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++
134
tests/qemu-iotests/153.out | 390 ++++++++++++++++++++++++++++++++++++++
135
tests/qemu-iotests/154 | 160 +++++++++++++++-
136
tests/qemu-iotests/154.out | 158 +++++++++++++--
137
tests/qemu-iotests/172 | 55 +++---
138
tests/qemu-iotests/172.out | 50 ++---
139
tests/qemu-iotests/177 | 114 +++++++++++
140
tests/qemu-iotests/177.out | 49 +++++
141
tests/qemu-iotests/179 | 130 +++++++++++++
142
tests/qemu-iotests/179.out | 156 +++++++++++++++
143
tests/qemu-iotests/182 | 68 +++++++
144
tests/qemu-iotests/182.out | 8 +
145
tests/qemu-iotests/common.filter | 4 +-
146
tests/qemu-iotests/common.pattern | 2 +-
147
tests/qemu-iotests/group | 4 +
148
tests/test-replication.c | 9 +-
149
tests/usb-hcd-uhci-test.c | 2 +-
150
tests/usb-hcd-xhci-test.c | 2 +-
151
tests/virtio-blk-test.c | 2 +-
152
tests/virtio-scsi-test.c | 5 +-
153
util/osdep.c | 48 +++++
154
62 files changed, 3086 insertions(+), 610 deletions(-)
155
create mode 100755 tests/qemu-iotests/153
156
create mode 100644 tests/qemu-iotests/153.out
157
create mode 100755 tests/qemu-iotests/177
158
create mode 100644 tests/qemu-iotests/177.out
159
create mode 100755 tests/qemu-iotests/179
160
create mode 100644 tests/qemu-iotests/179.out
161
create mode 100755 tests/qemu-iotests/182
162
create mode 100644 tests/qemu-iotests/182.out
163
88
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Commit 1f4ad7d fixed 'qemu-img info' for raw images that are currently
2
in use as a mirror target. It is not enough for image formats, though,
3
as these still unconditionally request BLK_PERM_CONSISTENT_READ.
2
4
3
Signed-off-by: Fam Zheng <famz@redhat.com>
5
As this permission is geared towards whether the guest-visible data is
6
consistent, and has no impact on whether the metadata is sane, and
7
'qemu-img info' does not read guest-visible data (except for the raw
8
format), it makes sense to not require BLK_PERM_CONSISTENT_READ if there
9
is not going to be any guest I/O performed, regardless of image format.
10
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
12
---
6
block.c | 17 +++++++++++++++++
13
block.c | 6 +++++-
7
include/block/block.h | 1 +
14
1 file changed, 5 insertions(+), 1 deletion(-)
8
include/block/block_int.h | 1 +
9
qapi/block-core.json | 3 +++
10
4 files changed, 22 insertions(+)
11
15
12
diff --git a/block.c b/block.c
16
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
18
--- a/block.c
15
+++ b/block.c
19
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
20
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
17
* the parent. */
21
assert(role == &child_backing || role == &child_file);
18
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
22
19
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
23
if (!backing) {
20
+ qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
24
+ int flags = bdrv_reopen_get_flags(reopen_queue, bs);
21
22
/* Inherit the read-only option from the parent if it's not set */
23
qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY);
24
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_options(int *child_flags, QDict *child_options,
25
* which is only applied on the top level (BlockBackend) */
26
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
27
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
28
+ qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
29
30
/* backing files always opened read-only */
31
qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on");
32
@@ -XXX,XX +XXX,XX @@ QemuOptsList bdrv_runtime_opts = {
33
.type = QEMU_OPT_STRING,
34
.help = "discard operation (ignore/off, unmap/on)",
35
},
36
+ {
37
+ .name = BDRV_OPT_FORCE_SHARE,
38
+ .type = QEMU_OPT_BOOL,
39
+ .help = "always accept other writers (default: off)",
40
+ },
41
{ /* end of list */ }
42
},
43
};
44
@@ -XXX,XX +XXX,XX @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
45
drv = bdrv_find_format(driver_name);
46
assert(drv != NULL);
47
48
+ bs->force_share = qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, false);
49
+
25
+
50
+ if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) {
26
/* Apart from the modifications below, the same permissions are
51
+ error_setg(errp,
27
* forwarded and left alone as for filters */
52
+ BDRV_OPT_FORCE_SHARE
28
bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared,
53
+ "=on can only be used with read-only images");
29
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
54
+ ret = -EINVAL;
30
55
+ goto fail_opts;
31
/* bs->file always needs to be consistent because of the metadata. We
56
+ }
32
* can never allow other users to resize or write to it. */
57
+
33
- perm |= BLK_PERM_CONSISTENT_READ;
58
if (file != NULL) {
34
+ if (!(flags & BDRV_O_NO_IO)) {
59
filename = blk_bs(file)->filename;
35
+ perm |= BLK_PERM_CONSISTENT_READ;
36
+ }
37
shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
60
} else {
38
} else {
61
diff --git a/include/block/block.h b/include/block/block.h
39
/* We want consistent read from backing files if the parent needs it.
62
index XXXXXXX..XXXXXXX 100644
63
--- a/include/block/block.h
64
+++ b/include/block/block.h
65
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
66
#define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
67
#define BDRV_OPT_READ_ONLY "read-only"
68
#define BDRV_OPT_DISCARD "discard"
69
+#define BDRV_OPT_FORCE_SHARE "force-share"
70
71
72
#define BDRV_SECTOR_BITS 9
73
diff --git a/include/block/block_int.h b/include/block/block_int.h
74
index XXXXXXX..XXXXXXX 100644
75
--- a/include/block/block_int.h
76
+++ b/include/block/block_int.h
77
@@ -XXX,XX +XXX,XX @@ struct BlockDriverState {
78
bool valid_key; /* if true, a valid encryption key has been set */
79
bool sg; /* if true, the device is a /dev/sg* */
80
bool probed; /* if true, format was probed rather than specified */
81
+ bool force_share; /* if true, always allow all shared permissions */
82
83
BlockDriver *drv; /* NULL means no media */
84
void *opaque;
85
diff --git a/qapi/block-core.json b/qapi/block-core.json
86
index XXXXXXX..XXXXXXX 100644
87
--- a/qapi/block-core.json
88
+++ b/qapi/block-core.json
89
@@ -XXX,XX +XXX,XX @@
90
# (default: false)
91
# @detect-zeroes: detect and optimize zero writes (Since 2.1)
92
# (default: off)
93
+# @force-share: force share all permission on added nodes.
94
+# Requires read-only=true. (Since 2.10)
95
#
96
# Remaining options are determined by the block driver.
97
#
98
@@ -XXX,XX +XXX,XX @@
99
'*discard': 'BlockdevDiscardOptions',
100
'*cache': 'BlockdevCacheOptions',
101
'*read-only': 'bool',
102
+ '*force-share': 'bool',
103
'*detect-zeroes': 'BlockdevDetectZeroesOptions' },
104
'discriminator': 'driver',
105
'data': {
106
--
40
--
107
1.8.3.1
41
2.13.6
108
42
109
43
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: John Snow <jsnow@redhat.com>
2
2
3
Although _filter_qemu_img_map documents that it scrubs offsets, it
3
VPC has some difficulty creating geometries of particular size.
4
was only doing so for human mode. Of the existing tests using the
4
However, we can indeed force it to use a literal one, so let's
5
filter (97, 122, 150, 154, 176), two of them are affected, but it
5
do that for the sake of test 197, which is testing some specific
6
does not hurt the validity of the tests to not require particular
6
offsets.
7
mappings (another test, 66, uses offsets but intentionally does not
8
pass through _filter_qemu_img_map, because it checks that offsets
9
are unchanged before and after an operation).
10
7
11
Another justification for this patch is that it will allow a future
8
Signed-off-by: John Snow <jsnow@redhat.com>
12
patch to utilize 'qemu-img map --output=json' to check the status of
9
Reviewed-by: Eric Blake <eblake@redhat.com>
13
preallocated zero clusters without regards to the mapping (since
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
the qcow2 mapping can be very sensitive to the chosen cluster size,
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
when preallocation is not in use).
12
Reviewed-by: Lukáš Doktor <ldoktor@redhat.com>
13
---
14
tests/qemu-iotests/197 | 4 ++++
15
tests/qemu-iotests/common.filter | 3 ++-
16
2 files changed, 6 insertions(+), 1 deletion(-)
16
17
17
Signed-off-by: Eric Blake <eblake@redhat.com>
18
diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197
18
Reviewed-by: Max Reitz <mreitz@redhat.com>
19
index XXXXXXX..XXXXXXX 100755
19
Message-id: 20170507000552.20847-9-eblake@redhat.com
20
--- a/tests/qemu-iotests/197
20
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
+++ b/tests/qemu-iotests/197
21
---
22
@@ -XXX,XX +XXX,XX @@ echo '=== Copy-on-read ==='
22
tests/qemu-iotests/122.out | 16 ++++++++--------
23
echo
23
tests/qemu-iotests/154.out | 30 +++++++++++++++---------------
24
24
tests/qemu-iotests/common.filter | 4 +++-
25
# Prep the images
25
3 files changed, 26 insertions(+), 24 deletions(-)
26
+# VPC rounds image sizes to a specific geometry, force a specific size.
26
27
+if [ "$IMGFMT" = "vpc" ]; then
27
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
28
+ IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size")
28
index XXXXXXX..XXXXXXX 100644
29
+fi
29
--- a/tests/qemu-iotests/122.out
30
_make_test_img 4G
30
+++ b/tests/qemu-iotests/122.out
31
$QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io
31
@@ -XXX,XX +XXX,XX @@ read 3145728/3145728 bytes at offset 0
32
IMGPROTO=file IMGFMT=qcow2 IMGOPTS= TEST_IMG_FILE="$TEST_WRAP" \
32
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
33
read 63963136/63963136 bytes at offset 3145728
34
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
35
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
36
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
37
38
convert -c -S 0:
39
read 3145728/3145728 bytes at offset 0
40
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
41
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
42
read 33554432/33554432 bytes at offset 33554432
43
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
44
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
45
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
46
47
convert -c -S 0 with source backing file:
48
read 3145728/3145728 bytes at offset 0
49
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
50
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
51
read 33554432/33554432 bytes at offset 33554432
52
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
53
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
54
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
55
56
convert -c -S 0 -B ...
57
read 3145728/3145728 bytes at offset 0
58
@@ -XXX,XX +XXX,XX @@ wrote 1024/1024 bytes at offset 17408
59
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
60
61
convert -S 4k
62
-[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 8192},
63
+[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
64
{ "start": 1024, "length": 7168, "depth": 0, "zero": true, "data": false},
65
-{ "start": 8192, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 9216},
66
+{ "start": 8192, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
67
{ "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false},
68
-{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 10240},
69
+{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
70
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
71
72
convert -c -S 4k
73
@@ -XXX,XX +XXX,XX @@ convert -c -S 4k
74
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
75
76
convert -S 8k
77
-[{ "start": 0, "length": 9216, "depth": 0, "zero": false, "data": true, "offset": 8192},
78
+[{ "start": 0, "length": 9216, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
79
{ "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false},
80
-{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 17408},
81
+{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
82
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
83
84
convert -c -S 8k
85
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
86
index XXXXXXX..XXXXXXX 100644
87
--- a/tests/qemu-iotests/154.out
88
+++ b/tests/qemu-iotests/154.out
89
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 65536
90
read 2048/2048 bytes at offset 67584
91
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
92
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
93
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
94
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
95
{ "start": 36864, "length": 28672, "depth": 1, "zero": true, "data": false},
96
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
97
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
98
{ "start": 69632, "length": 134148096, "depth": 1, "zero": true, "data": false}]
99
100
== backing file contains non-zero data after write_zeroes ==
101
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 44032
102
read 3072/3072 bytes at offset 40960
103
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
104
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
105
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
106
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
107
{ "start": 36864, "length": 4096, "depth": 1, "zero": true, "data": false},
108
-{ "start": 40960, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
109
+{ "start": 40960, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
110
{ "start": 45056, "length": 134172672, "depth": 1, "zero": true, "data": false}]
111
112
== write_zeroes covers non-zero data ==
113
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 67584
114
read 5120/5120 bytes at offset 68608
115
5 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
116
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
117
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
118
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
119
{ "start": 36864, "length": 4096, "depth": 0, "zero": true, "data": false},
120
{ "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false},
121
-{ "start": 49152, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
122
+{ "start": 49152, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
123
{ "start": 53248, "length": 4096, "depth": 0, "zero": true, "data": false},
124
{ "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false},
125
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672},
126
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
127
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
128
{ "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}]
129
130
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 72704
131
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
132
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
133
{ "start": 32768, "length": 4096, "depth": 0, "zero": true, "data": false},
134
-{ "start": 36864, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
135
+{ "start": 36864, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
136
{ "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false},
137
{ "start": 49152, "length": 4096, "depth": 0, "zero": true, "data": false},
138
-{ "start": 53248, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
139
+{ "start": 53248, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
140
{ "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false},
141
{ "start": 65536, "length": 4096, "depth": 0, "zero": true, "data": false},
142
-{ "start": 69632, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672},
143
+{ "start": 69632, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
144
{ "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}]
145
146
== spanning two clusters, partially overwriting backing file ==
147
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 5120
148
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
149
read 2048/2048 bytes at offset 6144
150
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
151
-[{ "start": 0, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 20480},
152
+[{ "start": 0, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
153
{ "start": 8192, "length": 134209536, "depth": 1, "zero": true, "data": false}]
154
155
== spanning multiple clusters, non-zero in first cluster ==
156
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 65536
157
read 10240/10240 bytes at offset 67584
158
10 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
159
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
160
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
161
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
162
{ "start": 69632, "length": 8192, "depth": 0, "zero": true, "data": false},
163
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
164
165
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 75776
166
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
167
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
168
{ "start": 65536, "length": 8192, "depth": 0, "zero": true, "data": false},
169
-{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
170
+{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
171
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
172
173
== spanning multiple clusters, partially overwriting backing file ==
174
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 74752
175
read 1024/1024 bytes at offset 76800
176
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
177
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
178
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
179
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
180
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
181
-{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
182
+{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
183
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
184
*** done
185
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
33
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
186
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
187
--- a/tests/qemu-iotests/common.filter
35
--- a/tests/qemu-iotests/common.filter
188
+++ b/tests/qemu-iotests/common.filter
36
+++ b/tests/qemu-iotests/common.filter
189
@@ -XXX,XX +XXX,XX @@ _filter_img_info()
37
@@ -XXX,XX +XXX,XX @@ _filter_img_create()
190
-e "/log_size: [0-9]\\+/d"
38
-e "s# log_size=[0-9]\\+##g" \
39
-e "s# refcount_bits=[0-9]\\+##g" \
40
-e "s# key-secret=[a-zA-Z0-9]\\+##g" \
41
- -e "s# iter-time=[0-9]\\+##g"
42
+ -e "s# iter-time=[0-9]\\+##g" \
43
+ -e "s# force_size=\\(on\\|off\\)##g"
191
}
44
}
192
45
193
-# filter out offsets and file names from qemu-img map
46
_filter_img_info()
194
+# filter out offsets and file names from qemu-img map; good for both
195
+# human and json output
196
_filter_qemu_img_map()
197
{
198
sed -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
199
+ -e 's/"offset": [0-9]\+/"offset": OFFSET/g' \
200
-e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt
201
}
202
203
--
47
--
204
1.8.3.1
48
2.13.6
205
49
206
50
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
This change separates bdrv_drain_invoke(), which calls the BlockDriver
2
drain callbacks, from bdrv_drain_recurse(). Instead, the function
3
performs its own recursion now.
2
4
3
Several copy-and-pasted alignment checks exist in qemu-io, which
5
One reason for this is that bdrv_drain_recurse() can be called multiple
4
could use some minor improvements:
6
times by bdrv_drain_all_begin(), but the callbacks may only be called
7
once. The separation is necessary to fix this bug.
5
8
6
- Manual comparison against 0x1ff is not as clean as using our
9
The other reason is that we intend to go to a model where we call all
7
alignment macros (QEMU_IS_ALIGNED) from osdep.h.
10
driver callbacks first, and only then start polling. This is not fully
11
achieved yet with this patch, as bdrv_drain_invoke() contains a
12
BDRV_POLL_WHILE() loop for the block driver callbacks, which can still
13
call callbacks for any unrelated event. It's a step in this direction
14
anyway.
8
15
9
- The error messages aren't quite grammatically correct.
16
Cc: qemu-stable@nongnu.org
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
19
---
20
block/io.c | 14 +++++++++++---
21
1 file changed, 11 insertions(+), 3 deletions(-)
10
22
11
Suggested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
23
diff --git a/block/io.c b/block/io.c
12
Suggested-by: Max Reitz <mreitz@redhat.com>
13
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Message-id: 20170429191419.30051-2-eblake@redhat.com
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
qemu-io-cmds.c | 20 ++++++++++----------
20
1 file changed, 10 insertions(+), 10 deletions(-)
21
22
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
23
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
24
--- a/qemu-io-cmds.c
25
--- a/block/io.c
25
+++ b/qemu-io-cmds.c
26
+++ b/block/io.c
26
@@ -XXX,XX +XXX,XX @@ static int read_f(BlockBackend *blk, int argc, char **argv)
27
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
28
bdrv_wakeup(bs);
29
}
30
31
+/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */
32
static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
33
{
34
+ BdrvChild *child, *tmp;
35
BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin};
36
37
if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) ||
38
@@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
39
data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data);
40
bdrv_coroutine_enter(bs, data.co);
41
BDRV_POLL_WHILE(bs, !data.done);
42
+
43
+ QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) {
44
+ bdrv_drain_invoke(child->bs, begin);
45
+ }
46
}
47
48
static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin)
49
@@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin)
50
BdrvChild *child, *tmp;
51
bool waited;
52
53
- /* Ensure any pending metadata writes are submitted to bs->file. */
54
- bdrv_drain_invoke(bs, begin);
55
-
56
/* Wait for drained requests to finish */
57
waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0);
58
59
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs)
60
bdrv_parent_drained_begin(bs);
27
}
61
}
28
62
29
if (bflag) {
63
+ bdrv_drain_invoke(bs, true);
30
- if (offset & 0x1ff) {
64
bdrv_drain_recurse(bs, true);
31
- printf("offset %" PRId64 " is not sector aligned\n",
65
}
32
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
66
33
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
67
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
34
offset);
35
return 0;
36
}
37
- if (count & 0x1ff) {
38
- printf("count %"PRId64" is not sector aligned\n",
39
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
40
+ printf("%"PRId64" is not a sector-aligned value for 'count'\n",
41
count);
42
return 0;
43
}
44
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
45
}
68
}
46
69
47
if (bflag || cflag) {
70
bdrv_parent_drained_end(bs);
48
- if (offset & 0x1ff) {
71
+ bdrv_drain_invoke(bs, false);
49
- printf("offset %" PRId64 " is not sector aligned\n",
72
bdrv_drain_recurse(bs, false);
50
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
73
aio_enable_external(bdrv_get_aio_context(bs));
51
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
74
}
52
offset);
75
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
53
return 0;
76
aio_context_acquire(aio_context);
54
}
77
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
55
78
if (aio_context == bdrv_get_aio_context(bs)) {
56
- if (count & 0x1ff) {
79
+ /* FIXME Calling this multiple times is wrong */
57
- printf("count %"PRId64" is not sector aligned\n",
80
+ bdrv_drain_invoke(bs, true);
58
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
81
waited |= bdrv_drain_recurse(bs, true);
59
+ printf("%"PRId64" is not a sector-aligned value for 'count'\n",
82
}
60
count);
83
}
61
return 0;
84
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
62
}
85
aio_context_acquire(aio_context);
63
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
86
aio_enable_external(aio_context);
64
if (offset < 0) {
87
bdrv_parent_drained_end(bs);
65
print_cvtnum_err(offset, argv[1]);
88
+ bdrv_drain_invoke(bs, false);
66
return 0;
89
bdrv_drain_recurse(bs, false);
67
- } else if (offset & 0x1ff) {
90
aio_context_release(aio_context);
68
- printf("offset %" PRId64 " is not sector aligned\n",
69
+ } else if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
70
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
71
offset);
72
return 0;
73
}
91
}
74
--
92
--
75
1.8.3.1
93
2.13.6
76
94
77
95
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
bdrv_drain_all_begin() used to call the .bdrv_co_drain_begin() driver
2
callback inside its polling loop. This means that how many times it got
3
called for each node depended on long it had to poll the event loop.
2
4
3
util/qemu-progress.c is currently unmaintained. The only user of its
5
This is obviously not right and results in nodes that stay drained even
4
functionality is qemu-img, so it effectively is part of the block layer.
6
after bdrv_drain_all_end(), which calls .bdrv_co_drain_begin() once per
7
node.
5
8
6
Suggested-by: Fam Zheng <famz@redhat.com>
9
Fix bdrv_drain_all_begin() to call the callback only once, too.
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
8
Message-id: 20170428165517.30341-1-mreitz@redhat.com
11
Cc: qemu-stable@nongnu.org
9
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
14
---
13
MAINTAINERS | 1 +
15
block/io.c | 3 +--
14
1 file changed, 1 insertion(+)
16
1 file changed, 1 insertion(+), 2 deletions(-)
15
17
16
diff --git a/MAINTAINERS b/MAINTAINERS
18
diff --git a/block/io.c b/block/io.c
17
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
18
--- a/MAINTAINERS
20
--- a/block/io.c
19
+++ b/MAINTAINERS
21
+++ b/block/io.c
20
@@ -XXX,XX +XXX,XX @@ F: include/block/
22
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
21
F: qemu-img*
23
aio_context_acquire(aio_context);
22
F: qemu-io*
24
bdrv_parent_drained_begin(bs);
23
F: tests/qemu-iotests/
25
aio_disable_external(aio_context);
24
+F: util/qemu-progress.c
26
+ bdrv_drain_invoke(bs, true);
25
T: git git://repo.or.cz/qemu/kevin.git block
27
aio_context_release(aio_context);
26
28
27
Block I/O path
29
if (!g_slist_find(aio_ctxs, aio_context)) {
30
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
31
aio_context_acquire(aio_context);
32
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
33
if (aio_context == bdrv_get_aio_context(bs)) {
34
- /* FIXME Calling this multiple times is wrong */
35
- bdrv_drain_invoke(bs, true);
36
waited |= bdrv_drain_recurse(bs, true);
37
}
38
}
28
--
39
--
29
1.8.3.1
40
2.13.6
30
41
31
42
diff view generated by jsdifflib
1
With image locking, permissions affect other qemu processes as well. We
1
This adds a test case that the BlockDriver callbacks for drain are
2
want to be sure that the destination can run, so let's drop permissions
2
called in bdrv_drained_all_begin/end(), and that both of them are called
3
on the source when migration completes.
3
exactly once.
4
4
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
8
---
8
block.c | 12 +++++++++++-
9
tests/test-bdrv-drain.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++
9
block/block-backend.c | 25 +++++++++++++++++++++++++
10
tests/Makefile.include | 2 +
10
include/block/block_int.h | 7 ++++---
11
2 files changed, 139 insertions(+)
11
3 files changed, 40 insertions(+), 4 deletions(-)
12
create mode 100644 tests/test-bdrv-drain.c
12
13
13
diff --git a/block.c b/block.c
14
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
14
index XXXXXXX..XXXXXXX 100644
15
new file mode 100644
15
--- a/block.c
16
index XXXXXXX..XXXXXXX
16
+++ b/block.c
17
--- /dev/null
17
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache_all(Error **errp)
18
+++ b/tests/test-bdrv-drain.c
18
static int bdrv_inactivate_recurse(BlockDriverState *bs,
19
@@ -XXX,XX +XXX,XX @@
19
bool setting_flag)
20
+/*
20
{
21
+ * Block node draining tests
21
- BdrvChild *child;
22
+ *
22
+ BdrvChild *child, *parent;
23
+ * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com>
23
int ret;
24
+ *
24
25
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
25
if (!setting_flag && bs->drv->bdrv_inactivate) {
26
+ * of this software and associated documentation files (the "Software"), to deal
26
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
27
+ * in the Software without restriction, including without limitation the rights
27
28
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
if (setting_flag) {
29
+ * copies of the Software, and to permit persons to whom the Software is
29
bs->open_flags |= BDRV_O_INACTIVE;
30
+ * furnished to do so, subject to the following conditions:
31
+ *
32
+ * The above copyright notice and this permission notice shall be included in
33
+ * all copies or substantial portions of the Software.
34
+ *
35
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
38
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41
+ * THE SOFTWARE.
42
+ */
30
+
43
+
31
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
44
+#include "qemu/osdep.h"
32
+ if (parent->role->inactivate) {
45
+#include "block/block.h"
33
+ ret = parent->role->inactivate(parent);
46
+#include "sysemu/block-backend.h"
34
+ if (ret < 0) {
47
+#include "qapi/error.h"
35
+ bs->open_flags &= ~BDRV_O_INACTIVE;
48
+
36
+ return ret;
49
+typedef struct BDRVTestState {
37
+ }
50
+ int drain_count;
38
+ }
51
+} BDRVTestState;
39
+ }
52
+
40
}
53
+static void coroutine_fn bdrv_test_co_drain_begin(BlockDriverState *bs)
41
return 0;
42
}
43
diff --git a/block/block-backend.c b/block/block-backend.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/block/block-backend.c
46
+++ b/block/block-backend.c
47
@@ -XXX,XX +XXX,XX @@ static void blk_root_activate(BdrvChild *child, Error **errp)
48
}
49
}
50
51
+static int blk_root_inactivate(BdrvChild *child)
52
+{
54
+{
53
+ BlockBackend *blk = child->opaque;
55
+ BDRVTestState *s = bs->opaque;
56
+ s->drain_count++;
57
+}
54
+
58
+
55
+ if (blk->disable_perm) {
59
+static void coroutine_fn bdrv_test_co_drain_end(BlockDriverState *bs)
56
+ return 0;
60
+{
57
+ }
61
+ BDRVTestState *s = bs->opaque;
62
+ s->drain_count--;
63
+}
58
+
64
+
59
+ /* Only inactivate BlockBackends for guest devices (which are inactive at
65
+static void bdrv_test_close(BlockDriverState *bs)
60
+ * this point because the VM is stopped) and unattached monitor-owned
66
+{
61
+ * BlockBackends. If there is still any other user like a block job, then
67
+ BDRVTestState *s = bs->opaque;
62
+ * we simply can't inactivate the image. */
68
+ g_assert_cmpint(s->drain_count, >, 0);
63
+ if (!blk->dev && !blk->name[0]) {
69
+}
64
+ return -EPERM;
65
+ }
66
+
70
+
67
+ blk->disable_perm = true;
71
+static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs,
68
+ if (blk->root) {
72
+ uint64_t offset, uint64_t bytes,
69
+ bdrv_child_try_set_perm(blk->root, 0, BLK_PERM_ALL, &error_abort);
73
+ QEMUIOVector *qiov, int flags)
70
+ }
74
+{
75
+ /* We want this request to stay until the polling loop in drain waits for
76
+ * it to complete. We need to sleep a while as bdrv_drain_invoke() comes
77
+ * first and polls its result, too, but it shouldn't accidentally complete
78
+ * this request yet. */
79
+ qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
71
+
80
+
72
+ return 0;
81
+ return 0;
73
+}
82
+}
74
+
83
+
75
static const BdrvChildRole child_root = {
84
+static BlockDriver bdrv_test = {
76
.inherit_options = blk_root_inherit_options,
85
+ .format_name = "test",
77
86
+ .instance_size = sizeof(BDRVTestState),
78
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
87
+
79
.drained_end = blk_root_drained_end,
88
+ .bdrv_close = bdrv_test_close,
80
89
+ .bdrv_co_preadv = bdrv_test_co_preadv,
81
.activate = blk_root_activate,
90
+
82
+ .inactivate = blk_root_inactivate,
91
+ .bdrv_co_drain_begin = bdrv_test_co_drain_begin,
83
};
92
+ .bdrv_co_drain_end = bdrv_test_co_drain_end,
84
93
+};
85
/*
94
+
86
diff --git a/include/block/block_int.h b/include/block/block_int.h
95
+static void aio_ret_cb(void *opaque, int ret)
96
+{
97
+ int *aio_ret = opaque;
98
+ *aio_ret = ret;
99
+}
100
+
101
+static void test_drv_cb_drain_all(void)
102
+{
103
+ BlockBackend *blk;
104
+ BlockDriverState *bs;
105
+ BDRVTestState *s;
106
+ BlockAIOCB *acb;
107
+ int aio_ret;
108
+
109
+ QEMUIOVector qiov;
110
+ struct iovec iov = {
111
+ .iov_base = NULL,
112
+ .iov_len = 0,
113
+ };
114
+ qemu_iovec_init_external(&qiov, &iov, 1);
115
+
116
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
117
+ bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
118
+ &error_abort);
119
+ s = bs->opaque;
120
+ blk_insert_bs(blk, bs, &error_abort);
121
+
122
+ /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */
123
+ g_assert_cmpint(s->drain_count, ==, 0);
124
+ bdrv_drain_all_begin();
125
+ g_assert_cmpint(s->drain_count, ==, 1);
126
+ bdrv_drain_all_end();
127
+ g_assert_cmpint(s->drain_count, ==, 0);
128
+
129
+ /* Now do the same while a request is pending */
130
+ aio_ret = -EINPROGRESS;
131
+ acb = blk_aio_preadv(blk, 0, &qiov, 0, aio_ret_cb, &aio_ret);
132
+ g_assert(acb != NULL);
133
+ g_assert_cmpint(aio_ret, ==, -EINPROGRESS);
134
+
135
+ g_assert_cmpint(s->drain_count, ==, 0);
136
+ bdrv_drain_all_begin();
137
+ g_assert_cmpint(aio_ret, ==, 0);
138
+ g_assert_cmpint(s->drain_count, ==, 1);
139
+ bdrv_drain_all_end();
140
+ g_assert_cmpint(s->drain_count, ==, 0);
141
+
142
+ bdrv_unref(bs);
143
+ blk_unref(blk);
144
+}
145
+
146
+int main(int argc, char **argv)
147
+{
148
+ bdrv_init();
149
+ qemu_init_main_loop(&error_abort);
150
+
151
+ g_test_init(&argc, &argv, NULL);
152
+
153
+ g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all);
154
+
155
+ return g_test_run();
156
+}
157
diff --git a/tests/Makefile.include b/tests/Makefile.include
87
index XXXXXXX..XXXXXXX 100644
158
index XXXXXXX..XXXXXXX 100644
88
--- a/include/block/block_int.h
159
--- a/tests/Makefile.include
89
+++ b/include/block/block_int.h
160
+++ b/tests/Makefile.include
90
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
161
@@ -XXX,XX +XXX,XX @@ gcov-files-test-thread-pool-y = thread-pool.c
91
void (*drained_begin)(BdrvChild *child);
162
gcov-files-test-hbitmap-y = util/hbitmap.c
92
void (*drained_end)(BdrvChild *child);
163
check-unit-y += tests/test-hbitmap$(EXESUF)
93
164
gcov-files-test-hbitmap-y = blockjob.c
94
- /* Notifies the parent that the child has been activated (e.g. when
165
+check-unit-y += tests/test-bdrv-drain$(EXESUF)
95
- * migration is completing) and it can start requesting permissions and
166
check-unit-y += tests/test-blockjob$(EXESUF)
96
- * doing I/O on it. */
167
check-unit-y += tests/test-blockjob-txn$(EXESUF)
97
+ /* Notifies the parent that the child has been activated/inactivated (e.g.
168
check-unit-y += tests/test-x86-cpuid$(EXESUF)
98
+ * when migration is completing) and it can start/stop requesting
169
@@ -XXX,XX +XXX,XX @@ tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y)
99
+ * permissions and doing I/O on it. */
170
tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y)
100
void (*activate)(BdrvChild *child, Error **errp);
171
tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-block-obj-y)
101
+ int (*inactivate)(BdrvChild *child);
172
tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y)
102
173
+tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y) $(test-util-obj-y)
103
void (*attach)(BdrvChild *child);
174
tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-util-obj-y)
104
void (*detach)(BdrvChild *child);
175
tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y)
176
tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y)
105
--
177
--
106
1.8.3.1
178
2.13.6
107
179
108
180
diff view generated by jsdifflib
1
Format drivers for inactive nodes don't need write/resize permissions on
1
Now that the bdrv_drain_invoke() calls are pulled up to the callers of
2
their bs->file and can share write/resize with another VM (in fact, this
2
bdrv_drain_recurse(), the 'begin' parameter isn't needed any more.
3
is the whole point of keeping images inactive). Represent this fact in
4
the op blocker system, so that image locking does the right thing
5
without special-casing inactive images.
6
3
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
5
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
6
---
10
block.c | 35 +++++++++++++++++++++++++++++++++--
7
block/io.c | 12 ++++++------
11
include/block/block.h | 1 +
8
1 file changed, 6 insertions(+), 6 deletions(-)
12
2 files changed, 34 insertions(+), 2 deletions(-)
13
9
14
diff --git a/block.c b/block.c
10
diff --git a/block/io.c b/block/io.c
15
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
12
--- a/block/io.c
17
+++ b/block.c
13
+++ b/block/io.c
18
@@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size,
14
@@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
19
}
15
}
20
}
16
}
21
17
22
+/* Returns whether the image file is opened as read-only. Note that this can
18
-static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin)
23
+ * return false and writing to the image file is still not possible because the
19
+static bool bdrv_drain_recurse(BlockDriverState *bs)
24
+ * image is inactivated. */
25
bool bdrv_is_read_only(BlockDriverState *bs)
26
{
20
{
27
return bs->read_only;
21
BdrvChild *child, *tmp;
22
bool waited;
23
@@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin)
24
*/
25
bdrv_ref(bs);
26
}
27
- waited |= bdrv_drain_recurse(bs, begin);
28
+ waited |= bdrv_drain_recurse(bs);
29
if (in_main_loop) {
30
bdrv_unref(bs);
31
}
32
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs)
33
}
34
35
bdrv_drain_invoke(bs, true);
36
- bdrv_drain_recurse(bs, true);
37
+ bdrv_drain_recurse(bs);
28
}
38
}
29
39
30
+/* Returns whether the image file can be written to right now */
40
void bdrv_drained_end(BlockDriverState *bs)
31
+bool bdrv_is_writable(BlockDriverState *bs)
41
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
32
+{
42
33
+ return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE);
43
bdrv_parent_drained_end(bs);
34
+}
44
bdrv_drain_invoke(bs, false);
35
+
45
- bdrv_drain_recurse(bs, false);
36
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
46
+ bdrv_drain_recurse(bs);
37
{
47
aio_enable_external(bdrv_get_aio_context(bs));
38
/* Do not set read_only if copy_on_read is enabled */
39
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
40
41
/* Write permissions never work with read-only images */
42
if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) &&
43
- bdrv_is_read_only(bs))
44
+ !bdrv_is_writable(bs))
45
{
46
error_setg(errp, "Block node is read-only");
47
return -EPERM;
48
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
49
bdrv_filter_default_perms(bs, c, role, perm, shared, &perm, &shared);
50
51
/* Format drivers may touch metadata even if the guest doesn't write */
52
- if (!bdrv_is_read_only(bs)) {
53
+ if (bdrv_is_writable(bs)) {
54
perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
55
}
56
57
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
58
BLK_PERM_WRITE_UNCHANGED;
59
}
60
61
+ if (bs->open_flags & BDRV_O_INACTIVE) {
62
+ shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
63
+ }
64
+
65
*nperm = perm;
66
*nshared = shared;
67
}
48
}
68
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
49
69
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
50
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
70
{
51
aio_context_acquire(aio_context);
71
BdrvChild *child, *parent;
52
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
72
+ uint64_t perm, shared_perm;
53
if (aio_context == bdrv_get_aio_context(bs)) {
73
Error *local_err = NULL;
54
- waited |= bdrv_drain_recurse(bs, true);
74
int ret;
55
+ waited |= bdrv_drain_recurse(bs);
75
76
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
77
return;
78
}
79
80
+ /* Update permissions, they may differ for inactive nodes */
81
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
82
+ ret = bdrv_check_perm(bs, perm, shared_perm, NULL, &local_err);
83
+ if (ret < 0) {
84
+ bs->open_flags |= BDRV_O_INACTIVE;
85
+ error_propagate(errp, local_err);
86
+ return;
87
+ }
88
+ bdrv_set_perm(bs, perm, shared_perm);
89
+
90
QLIST_FOREACH(parent, &bs->parents, next_parent) {
91
if (parent->role->activate) {
92
parent->role->activate(parent, &local_err);
93
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
94
}
95
96
if (setting_flag) {
97
+ uint64_t perm, shared_perm;
98
+
99
bs->open_flags |= BDRV_O_INACTIVE;
100
101
QLIST_FOREACH(parent, &bs->parents, next_parent) {
102
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
103
}
56
}
104
}
57
}
105
}
58
aio_context_release(aio_context);
106
+
59
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
107
+ /* Update permissions, they may differ for inactive nodes */
60
aio_enable_external(aio_context);
108
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
61
bdrv_parent_drained_end(bs);
109
+ bdrv_check_perm(bs, perm, shared_perm, NULL, &error_abort);
62
bdrv_drain_invoke(bs, false);
110
+ bdrv_set_perm(bs, perm, shared_perm);
63
- bdrv_drain_recurse(bs, false);
64
+ bdrv_drain_recurse(bs);
65
aio_context_release(aio_context);
111
}
66
}
112
67
113
QLIST_FOREACH(child, &bs->children, next) {
114
diff --git a/include/block/block.h b/include/block/block.h
115
index XXXXXXX..XXXXXXX 100644
116
--- a/include/block/block.h
117
+++ b/include/block/block.h
118
@@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
119
int64_t sector_num, int nb_sectors, int *pnum);
120
121
bool bdrv_is_read_only(BlockDriverState *bs);
122
+bool bdrv_is_writable(BlockDriverState *bs);
123
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
124
int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
125
bool bdrv_is_sg(BlockDriverState *bs);
126
--
68
--
127
1.8.3.1
69
2.13.6
128
70
129
71
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
The device is drained, so there is no point in waiting for requests at
2
the end of the drained section. Remove the bdrv_drain_recurse() calls
3
there.
2
4
3
Rather than repeat the logic at each caller of checking if a Rule
5
The bdrv_drain_recurse() calls were introduced in commit 481cad48e5e
4
exists that warrants an error injection, fold that logic into
6
in order to call the .bdrv_co_drain_end() driver callback. This is now
5
inject_error(); and rename it to rule_check() for legibility.
7
done by a separate bdrv_drain_invoke() call.
6
This will help the next patch, which adds two more callers that
7
need to check rules for the potential of injecting errors.
8
8
9
Signed-off-by: Eric Blake <eblake@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
11
Message-id: 20170429191419.30051-6-eblake@redhat.com
11
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
12
---
14
block/blkdebug.c | 74 +++++++++++++++++++++++++-------------------------------
13
block/io.c | 2 --
15
1 file changed, 33 insertions(+), 41 deletions(-)
14
1 file changed, 2 deletions(-)
16
15
17
diff --git a/block/blkdebug.c b/block/blkdebug.c
16
diff --git a/block/io.c b/block/io.c
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
19
--- a/block/blkdebug.c
18
--- a/block/io.c
20
+++ b/block/blkdebug.c
19
+++ b/block/io.c
21
@@ -XXX,XX +XXX,XX @@ out:
20
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
22
return ret;
21
22
bdrv_parent_drained_end(bs);
23
bdrv_drain_invoke(bs, false);
24
- bdrv_drain_recurse(bs);
25
aio_enable_external(bdrv_get_aio_context(bs));
23
}
26
}
24
27
25
-static int inject_error(BlockDriverState *bs, BlkdebugRule *rule)
28
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
26
+static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes)
29
aio_enable_external(aio_context);
27
{
30
bdrv_parent_drained_end(bs);
28
BDRVBlkdebugState *s = bs->opaque;
31
bdrv_drain_invoke(bs, false);
29
- int error = rule->options.inject.error;
32
- bdrv_drain_recurse(bs);
30
- bool immediately = rule->options.inject.immediately;
33
aio_context_release(aio_context);
31
+ BlkdebugRule *rule = NULL;
32
+ int error;
33
+ bool immediately;
34
+
35
+ QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
36
+ uint64_t inject_offset = rule->options.inject.offset;
37
+
38
+ if (inject_offset == -1 ||
39
+ (bytes && inject_offset >= offset &&
40
+ inject_offset < offset + bytes))
41
+ {
42
+ break;
43
+ }
44
+ }
45
+
46
+ if (!rule || !rule->options.inject.error) {
47
+ return 0;
48
+ }
49
+
50
+ immediately = rule->options.inject.immediately;
51
+ error = rule->options.inject.error;
52
53
if (rule->options.inject.once) {
54
QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next);
55
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn
56
blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
57
QEMUIOVector *qiov, int flags)
58
{
59
- BDRVBlkdebugState *s = bs->opaque;
60
- BlkdebugRule *rule = NULL;
61
+ int err;
62
63
/* Sanity check block layer guarantees */
64
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
65
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
66
assert(bytes <= bs->bl.max_transfer);
67
}
34
}
68
35
69
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
70
- uint64_t inject_offset = rule->options.inject.offset;
71
-
72
- if (inject_offset == -1 ||
73
- (inject_offset >= offset && inject_offset < offset + bytes))
74
- {
75
- break;
76
- }
77
- }
78
-
79
- if (rule && rule->options.inject.error) {
80
- return inject_error(bs, rule);
81
+ err = rule_check(bs, offset, bytes);
82
+ if (err) {
83
+ return err;
84
}
85
86
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
87
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn
88
blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
89
QEMUIOVector *qiov, int flags)
90
{
91
- BDRVBlkdebugState *s = bs->opaque;
92
- BlkdebugRule *rule = NULL;
93
+ int err;
94
95
/* Sanity check block layer guarantees */
96
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
97
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
98
assert(bytes <= bs->bl.max_transfer);
99
}
100
101
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
102
- uint64_t inject_offset = rule->options.inject.offset;
103
-
104
- if (inject_offset == -1 ||
105
- (inject_offset >= offset && inject_offset < offset + bytes))
106
- {
107
- break;
108
- }
109
- }
110
-
111
- if (rule && rule->options.inject.error) {
112
- return inject_error(bs, rule);
113
+ err = rule_check(bs, offset, bytes);
114
+ if (err) {
115
+ return err;
116
}
117
118
return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
119
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
120
121
static int blkdebug_co_flush(BlockDriverState *bs)
122
{
123
- BDRVBlkdebugState *s = bs->opaque;
124
- BlkdebugRule *rule = NULL;
125
-
126
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
127
- if (rule->options.inject.offset == -1) {
128
- break;
129
- }
130
- }
131
+ int err = rule_check(bs, 0, 0);
132
133
- if (rule && rule->options.inject.error) {
134
- return inject_error(bs, rule);
135
+ if (err) {
136
+ return err;
137
}
138
139
return bdrv_co_flush(bs->file->bs);
140
--
36
--
141
1.8.3.1
37
2.13.6
142
38
143
39
diff view generated by jsdifflib
1
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
1
Drain requests are propagated to child nodes, parent nodes and directly
2
to the AioContext. The order in which this happened was different
3
between all combinations of drain/drain_all and begin/end.
2
4
3
On error path (like i/o error in one of the coroutines), it's required to
5
The correct order is to keep children only drained when their parents
4
- wait for coroutines completion before cleaning the common structures
6
are also drained. This means that at the start of a drained section, the
5
- reenter dependent coroutines so they ever finish
7
AioContext needs to be drained first, the parents second and only then
8
the children. The correct order for the end of a drained section is the
9
opposite.
6
10
7
Introduced in 2d9187bc65.
11
This patch changes the three other functions to follow the example of
12
bdrv_drained_begin(), which is the only one that got it right.
8
13
9
Cc: qemu-stable@nongnu.org
10
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
11
Reviewed-by: Peter Lieven <pl@kamp.de>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
15
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
16
---
14
qemu-img.c | 26 +++++++++++---------------
17
block/io.c | 12 ++++++++----
15
1 file changed, 11 insertions(+), 15 deletions(-)
18
1 file changed, 8 insertions(+), 4 deletions(-)
16
19
17
diff --git a/qemu-img.c b/qemu-img.c
20
diff --git a/block/io.c b/block/io.c
18
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-img.c
22
--- a/block/io.c
20
+++ b/qemu-img.c
23
+++ b/block/io.c
21
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
24
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs)
22
qemu_co_mutex_lock(&s->lock);
25
return;
23
if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
24
qemu_co_mutex_unlock(&s->lock);
25
- goto out;
26
+ break;
27
}
28
n = convert_iteration_sectors(s, s->sector_num);
29
if (n < 0) {
30
qemu_co_mutex_unlock(&s->lock);
31
s->ret = n;
32
- goto out;
33
+ break;
34
}
35
/* save current sector and allocation status to local variables */
36
sector_num = s->sector_num;
37
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
38
error_report("error while reading sector %" PRId64
39
": %s", sector_num, strerror(-ret));
40
s->ret = ret;
41
- goto out;
42
}
43
} else if (!s->min_sparse && status == BLK_ZERO) {
44
status = BLK_DATA;
45
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
46
47
if (s->wr_in_order) {
48
/* keep writes in order */
49
- while (s->wr_offs != sector_num) {
50
- if (s->ret != -EINPROGRESS) {
51
- goto out;
52
- }
53
+ while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) {
54
s->wait_sector_num[index] = sector_num;
55
qemu_coroutine_yield();
56
}
57
s->wait_sector_num[index] = -1;
58
}
59
60
- ret = convert_co_write(s, sector_num, n, buf, status);
61
- if (ret < 0) {
62
- error_report("error while writing sector %" PRId64
63
- ": %s", sector_num, strerror(-ret));
64
- s->ret = ret;
65
- goto out;
66
+ if (s->ret == -EINPROGRESS) {
67
+ ret = convert_co_write(s, sector_num, n, buf, status);
68
+ if (ret < 0) {
69
+ error_report("error while writing sector %" PRId64
70
+ ": %s", sector_num, strerror(-ret));
71
+ s->ret = ret;
72
+ }
73
}
74
75
if (s->wr_in_order) {
76
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
77
}
78
}
26
}
79
27
80
-out:
28
+ /* Stop things in parent-to-child order */
81
qemu_vfree(buf);
29
if (atomic_fetch_inc(&bs->quiesce_counter) == 0) {
82
s->co[index] = NULL;
30
aio_disable_external(bdrv_get_aio_context(bs));
83
s->running_coroutines--;
31
bdrv_parent_drained_begin(bs);
84
@@ -XXX,XX +XXX,XX @@ static int convert_do_copy(ImgConvertState *s)
32
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
85
qemu_coroutine_enter(s->co[i]);
33
return;
86
}
34
}
87
35
88
- while (s->ret == -EINPROGRESS) {
36
- bdrv_parent_drained_end(bs);
89
+ while (s->running_coroutines) {
37
+ /* Re-enable things in child-to-parent order */
90
main_loop_wait(false);
38
bdrv_drain_invoke(bs, false);
39
+ bdrv_parent_drained_end(bs);
40
aio_enable_external(bdrv_get_aio_context(bs));
41
}
42
43
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
44
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
45
AioContext *aio_context = bdrv_get_aio_context(bs);
46
47
+ /* Stop things in parent-to-child order */
48
aio_context_acquire(aio_context);
49
- bdrv_parent_drained_begin(bs);
50
aio_disable_external(aio_context);
51
+ bdrv_parent_drained_begin(bs);
52
bdrv_drain_invoke(bs, true);
53
aio_context_release(aio_context);
54
55
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
56
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
57
AioContext *aio_context = bdrv_get_aio_context(bs);
58
59
+ /* Re-enable things in child-to-parent order */
60
aio_context_acquire(aio_context);
61
- aio_enable_external(aio_context);
62
- bdrv_parent_drained_end(bs);
63
bdrv_drain_invoke(bs, false);
64
+ bdrv_parent_drained_end(bs);
65
+ aio_enable_external(aio_context);
66
aio_context_release(aio_context);
91
}
67
}
92
68
93
--
69
--
94
1.8.3.1
70
2.13.6
95
71
96
72
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Commit 15afd94a047 added code to acquire and release the AioContext in
2
qemuio_command(). This means that the lock is taken twice now in the
3
call path from hmp_qemu_io(). This causes BDRV_POLL_WHILE() to hang for
4
any requests issued to nodes in a non-mainloop AioContext.
2
5
3
This will force the opened images to allow sharing all permissions with other
6
Dropping the first locking from hmp_qemu_io() fixes the problem.
4
programs.
5
7
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
10
---
9
qemu-img.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++---------------
11
hmp.c | 6 ------
10
1 file changed, 117 insertions(+), 36 deletions(-)
12
1 file changed, 6 deletions(-)
11
13
12
diff --git a/qemu-img.c b/qemu-img.c
14
diff --git a/hmp.c b/hmp.c
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/qemu-img.c
16
--- a/hmp.c
15
+++ b/qemu-img.c
17
+++ b/hmp.c
16
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
17
#include "qapi/qobject-output-visitor.h"
18
#include "qapi/qmp/qerror.h"
19
#include "qapi/qmp/qjson.h"
20
+#include "qapi/qmp/qbool.h"
21
#include "qemu/cutils.h"
22
#include "qemu/config-file.h"
23
#include "qemu/option.h"
24
@@ -XXX,XX +XXX,XX @@ static int img_open_password(BlockBackend *blk, const char *filename,
25
26
static BlockBackend *img_open_opts(const char *optstr,
27
QemuOpts *opts, int flags, bool writethrough,
28
- bool quiet)
29
+ bool quiet, bool force_share)
30
{
31
QDict *options;
32
Error *local_err = NULL;
33
BlockBackend *blk;
34
options = qemu_opts_to_qdict(opts, NULL);
35
+ if (force_share) {
36
+ if (qdict_haskey(options, BDRV_OPT_FORCE_SHARE)
37
+ && !qdict_get_bool(options, BDRV_OPT_FORCE_SHARE)) {
38
+ error_report("--force-share/-U conflicts with image options");
39
+ return NULL;
40
+ }
41
+ qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
42
+ }
43
blk = blk_new_open(NULL, NULL, options, flags, &local_err);
44
if (!blk) {
45
error_reportf_err(local_err, "Could not open '%s': ", optstr);
46
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open_opts(const char *optstr,
47
48
static BlockBackend *img_open_file(const char *filename,
49
const char *fmt, int flags,
50
- bool writethrough, bool quiet)
51
+ bool writethrough, bool quiet,
52
+ bool force_share)
53
{
19
{
54
BlockBackend *blk;
20
BlockBackend *blk;
55
Error *local_err = NULL;
21
BlockBackend *local_blk = NULL;
56
- QDict *options = NULL;
22
- AioContext *aio_context;
57
+ QDict *options = qdict_new();
23
const char* device = qdict_get_str(qdict, "device");
58
24
const char* command = qdict_get_str(qdict, "command");
59
if (fmt) {
60
- options = qdict_new();
61
qdict_put_str(options, "driver", fmt);
62
}
63
64
+ if (force_share) {
65
+ qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
66
+ }
67
blk = blk_new_open(filename, NULL, options, flags, &local_err);
68
if (!blk) {
69
error_reportf_err(local_err, "Could not open '%s': ", filename);
70
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open_file(const char *filename,
71
static BlockBackend *img_open(bool image_opts,
72
const char *filename,
73
const char *fmt, int flags, bool writethrough,
74
- bool quiet)
75
+ bool quiet, bool force_share)
76
{
77
BlockBackend *blk;
78
if (image_opts) {
79
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open(bool image_opts,
80
if (!opts) {
81
return NULL;
82
}
83
- blk = img_open_opts(filename, opts, flags, writethrough, quiet);
84
+ blk = img_open_opts(filename, opts, flags, writethrough, quiet,
85
+ force_share);
86
} else {
87
- blk = img_open_file(filename, fmt, flags, writethrough, quiet);
88
+ blk = img_open_file(filename, fmt, flags, writethrough, quiet,
89
+ force_share);
90
}
91
return blk;
92
}
93
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
94
ImageCheck *check;
95
bool quiet = false;
96
bool image_opts = false;
97
+ bool force_share = false;
98
99
fmt = NULL;
100
output = NULL;
101
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
102
{"output", required_argument, 0, OPTION_OUTPUT},
103
{"object", required_argument, 0, OPTION_OBJECT},
104
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
105
+ {"force-share", no_argument, 0, 'U'},
106
{0, 0, 0, 0}
107
};
108
- c = getopt_long(argc, argv, ":hf:r:T:q",
109
+ c = getopt_long(argc, argv, ":hf:r:T:qU",
110
long_options, &option_index);
111
if (c == -1) {
112
break;
113
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
114
case 'q':
115
quiet = true;
116
break;
117
+ case 'U':
118
+ force_share = true;
119
+ break;
120
case OPTION_OBJECT: {
121
QemuOpts *opts;
122
opts = qemu_opts_parse_noisily(&qemu_object_opts,
123
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
124
return 1;
125
}
126
127
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
128
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
129
+ force_share);
130
if (!blk) {
131
return 1;
132
}
133
@@ -XXX,XX +XXX,XX @@ static int img_commit(int argc, char **argv)
134
return 1;
135
}
136
137
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
138
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
139
+ false);
140
if (!blk) {
141
return 1;
142
}
143
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
144
int c, pnum;
145
uint64_t progress_base;
146
bool image_opts = false;
147
+ bool force_share = false;
148
149
cache = BDRV_DEFAULT_CACHE;
150
for (;;) {
151
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
152
{"help", no_argument, 0, 'h'},
153
{"object", required_argument, 0, OPTION_OBJECT},
154
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
155
+ {"force-share", no_argument, 0, 'U'},
156
{0, 0, 0, 0}
157
};
158
- c = getopt_long(argc, argv, ":hf:F:T:pqs",
159
+ c = getopt_long(argc, argv, ":hf:F:T:pqsU",
160
long_options, NULL);
161
if (c == -1) {
162
break;
163
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
164
case 's':
165
strict = true;
166
break;
167
+ case 'U':
168
+ force_share = true;
169
+ break;
170
case OPTION_OBJECT: {
171
QemuOpts *opts;
172
opts = qemu_opts_parse_noisily(&qemu_object_opts,
173
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
174
goto out3;
175
}
176
177
- blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet);
178
+ blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet,
179
+ force_share);
180
if (!blk1) {
181
ret = 2;
182
goto out3;
183
}
184
185
- blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet);
186
+ blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet,
187
+ force_share);
188
if (!blk2) {
189
ret = 2;
190
goto out2;
191
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
192
bool writethrough, src_writethrough, quiet = false, image_opts = false,
193
skip_create = false, progress = false;
194
int64_t ret = -EINVAL;
195
+ bool force_share = false;
196
197
ImgConvertState s = (ImgConvertState) {
198
/* Need at least 4k of zeros for sparse detection */
199
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
200
{"help", no_argument, 0, 'h'},
201
{"object", required_argument, 0, OPTION_OBJECT},
202
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
203
+ {"force-share", no_argument, 0, 'U'},
204
{0, 0, 0, 0}
205
};
206
- c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:W",
207
+ c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:WU",
208
long_options, NULL);
209
if (c == -1) {
210
break;
211
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
212
case 'W':
213
s.wr_in_order = false;
214
break;
215
+ case 'U':
216
+ force_share = true;
217
+ break;
218
case OPTION_OBJECT: {
219
QemuOpts *object_opts;
220
object_opts = qemu_opts_parse_noisily(&qemu_object_opts,
221
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
222
223
for (bs_i = 0; bs_i < s.src_num; bs_i++) {
224
s.src[bs_i] = img_open(image_opts, argv[optind + bs_i],
225
- fmt, src_flags, src_writethrough, quiet);
226
+ fmt, src_flags, src_writethrough, quiet,
227
+ force_share);
228
if (!s.src[bs_i]) {
229
ret = -1;
230
goto out;
231
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
232
* the bdrv_create() call which takes different params.
233
* Not critical right now, so fix can wait...
234
*/
235
- s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet);
236
+ s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet,
237
+ false);
238
if (!s.target) {
239
ret = -1;
240
goto out;
241
@@ -XXX,XX +XXX,XX @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b)
242
static ImageInfoList *collect_image_info_list(bool image_opts,
243
const char *filename,
244
const char *fmt,
245
- bool chain)
246
+ bool chain, bool force_share)
247
{
248
ImageInfoList *head = NULL;
249
ImageInfoList **last = &head;
250
@@ -XXX,XX +XXX,XX @@ static ImageInfoList *collect_image_info_list(bool image_opts,
251
g_hash_table_insert(filenames, (gpointer)filename, NULL);
252
253
blk = img_open(image_opts, filename, fmt,
254
- BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false);
255
+ BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false,
256
+ force_share);
257
if (!blk) {
258
goto err;
259
}
260
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
261
const char *filename, *fmt, *output;
262
ImageInfoList *list;
263
bool image_opts = false;
264
+ bool force_share = false;
265
266
fmt = NULL;
267
output = NULL;
268
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
269
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
270
{"object", required_argument, 0, OPTION_OBJECT},
271
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
272
+ {"force-share", no_argument, 0, 'U'},
273
{0, 0, 0, 0}
274
};
275
- c = getopt_long(argc, argv, ":f:h",
276
+ c = getopt_long(argc, argv, ":f:hU",
277
long_options, &option_index);
278
if (c == -1) {
279
break;
280
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
281
case 'f':
282
fmt = optarg;
283
break;
284
+ case 'U':
285
+ force_share = true;
286
+ break;
287
case OPTION_OUTPUT:
288
output = optarg;
289
break;
290
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
291
return 1;
292
}
293
294
- list = collect_image_info_list(image_opts, filename, fmt, chain);
295
+ list = collect_image_info_list(image_opts, filename, fmt, chain,
296
+ force_share);
297
if (!list) {
298
return 1;
299
}
300
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
301
MapEntry curr = { .length = 0 }, next;
302
int ret = 0;
303
bool image_opts = false;
304
+ bool force_share = false;
305
306
fmt = NULL;
307
output = NULL;
308
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
309
{"output", required_argument, 0, OPTION_OUTPUT},
310
{"object", required_argument, 0, OPTION_OBJECT},
311
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
312
+ {"force-share", no_argument, 0, 'U'},
313
{0, 0, 0, 0}
314
};
315
- c = getopt_long(argc, argv, ":f:h",
316
+ c = getopt_long(argc, argv, ":f:hU",
317
long_options, &option_index);
318
if (c == -1) {
319
break;
320
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
321
case 'f':
322
fmt = optarg;
323
break;
324
+ case 'U':
325
+ force_share = true;
326
+ break;
327
case OPTION_OUTPUT:
328
output = optarg;
329
break;
330
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
331
return 1;
332
}
333
334
- blk = img_open(image_opts, filename, fmt, 0, false, false);
335
+ blk = img_open(image_opts, filename, fmt, 0, false, false, force_share);
336
if (!blk) {
337
return 1;
338
}
339
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
340
bool quiet = false;
341
Error *err = NULL;
25
Error *err = NULL;
342
bool image_opts = false;
26
@@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
343
+ bool force_share = false;
344
345
bdrv_oflags = BDRV_O_RDWR;
346
/* Parse commandline parameters */
347
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
348
{"help", no_argument, 0, 'h'},
349
{"object", required_argument, 0, OPTION_OBJECT},
350
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
351
+ {"force-share", no_argument, 0, 'U'},
352
{0, 0, 0, 0}
353
};
354
- c = getopt_long(argc, argv, ":la:c:d:hq",
355
+ c = getopt_long(argc, argv, ":la:c:d:hqU",
356
long_options, NULL);
357
if (c == -1) {
358
break;
359
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
360
case 'q':
361
quiet = true;
362
break;
363
+ case 'U':
364
+ force_share = true;
365
+ break;
366
case OPTION_OBJECT: {
367
QemuOpts *opts;
368
opts = qemu_opts_parse_noisily(&qemu_object_opts,
369
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
370
}
371
372
/* Open the image */
373
- blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet);
374
+ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet,
375
+ force_share);
376
if (!blk) {
377
return 1;
378
}
379
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
380
int c, flags, src_flags, ret;
381
bool writethrough, src_writethrough;
382
int unsafe = 0;
383
+ bool force_share = false;
384
int progress = 0;
385
bool quiet = false;
386
Error *local_err = NULL;
387
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
388
{"help", no_argument, 0, 'h'},
389
{"object", required_argument, 0, OPTION_OBJECT},
390
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
391
+ {"force-share", no_argument, 0, 'U'},
392
{0, 0, 0, 0}
393
};
394
- c = getopt_long(argc, argv, ":hf:F:b:upt:T:q",
395
+ c = getopt_long(argc, argv, ":hf:F:b:upt:T:qU",
396
long_options, NULL);
397
if (c == -1) {
398
break;
399
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
400
case OPTION_IMAGE_OPTS:
401
image_opts = true;
402
break;
403
+ case 'U':
404
+ force_share = true;
405
+ break;
406
}
27
}
407
}
28
}
408
29
409
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
30
- aio_context = blk_get_aio_context(blk);
410
* Ignore the old backing file for unsafe rebase in case we want to correct
31
- aio_context_acquire(aio_context);
411
* the reference to a renamed or moved backing file.
32
-
33
/*
34
* Notably absent: Proper permission management. This is sad, but it seems
35
* almost impossible to achieve without changing the semantics and thereby
36
@@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
412
*/
37
*/
413
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
38
qemuio_command(blk, command);
414
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
39
415
+ false);
40
- aio_context_release(aio_context);
416
if (!blk) {
41
-
417
ret = -1;
42
fail:
418
goto out;
43
blk_unref(local_blk);
419
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
44
hmp_handle_error(mon, &err);
420
qdict_put_str(options, "driver", bs->backing_format);
421
}
422
423
+ if (force_share) {
424
+ if (!options) {
425
+ options = qdict_new();
426
+ }
427
+ qdict_put(options, BDRV_OPT_FORCE_SHARE,
428
+ qbool_from_bool(true));
429
+ }
430
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
431
blk_old_backing = blk_new_open(backing_name, NULL,
432
options, src_flags, &local_err);
433
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
434
}
435
436
if (out_baseimg[0]) {
437
+ options = qdict_new();
438
if (out_basefmt) {
439
- options = qdict_new();
440
qdict_put_str(options, "driver", out_basefmt);
441
- } else {
442
- options = NULL;
443
+ }
444
+ if (force_share) {
445
+ qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
446
}
447
448
blk_new_backing = blk_new_open(out_baseimg, NULL,
449
@@ -XXX,XX +XXX,XX @@ static int img_resize(int argc, char **argv)
450
qemu_opts_del(param);
451
452
blk = img_open(image_opts, filename, fmt,
453
- BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);
454
+ BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet,
455
+ false);
456
if (!blk) {
457
ret = -1;
458
goto out;
459
@@ -XXX,XX +XXX,XX @@ static int img_amend(int argc, char **argv)
460
goto out;
461
}
462
463
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
464
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
465
+ false);
466
if (!blk) {
467
ret = -1;
468
goto out;
469
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
470
bool writethrough = false;
471
struct timeval t1, t2;
472
int i;
473
+ bool force_share = false;
474
475
for (;;) {
476
static const struct option long_options[] = {
477
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
478
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
479
{"pattern", required_argument, 0, OPTION_PATTERN},
480
{"no-drain", no_argument, 0, OPTION_NO_DRAIN},
481
+ {"force-share", no_argument, 0, 'U'},
482
{0, 0, 0, 0}
483
};
484
- c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options, NULL);
485
+ c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:wU", long_options, NULL);
486
if (c == -1) {
487
break;
488
}
489
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
490
flags |= BDRV_O_RDWR;
491
is_write = true;
492
break;
493
+ case 'U':
494
+ force_share = true;
495
+ break;
496
case OPTION_PATTERN:
497
{
498
unsigned long res;
499
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
500
goto out;
501
}
502
503
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
504
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
505
+ force_share);
506
if (!blk) {
507
ret = -1;
508
goto out;
509
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
510
const char *fmt = NULL;
511
int64_t size = 0;
512
int64_t block_count = 0, out_pos, in_pos;
513
+ bool force_share = false;
514
struct DdInfo dd = {
515
.flags = 0,
516
.count = 0,
517
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
518
const struct option long_options[] = {
519
{ "help", no_argument, 0, 'h'},
520
{ "image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
521
+ { "force-share", no_argument, 0, 'U'},
522
{ 0, 0, 0, 0 }
523
};
524
525
- while ((c = getopt_long(argc, argv, ":hf:O:", long_options, NULL))) {
526
+ while ((c = getopt_long(argc, argv, ":hf:O:U", long_options, NULL))) {
527
if (c == EOF) {
528
break;
529
}
530
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
531
case 'h':
532
help();
533
break;
534
+ case 'U':
535
+ force_share = true;
536
+ break;
537
case OPTION_IMAGE_OPTS:
538
image_opts = true;
539
break;
540
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
541
ret = -1;
542
goto out;
543
}
544
- blk1 = img_open(image_opts, in.filename, fmt, 0, false, false);
545
+ blk1 = img_open(image_opts, in.filename, fmt, 0, false, false,
546
+ force_share);
547
548
if (!blk1) {
549
ret = -1;
550
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
551
}
552
553
blk2 = img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR,
554
- false, false);
555
+ false, false, false);
556
557
if (!blk2) {
558
ret = -1;
559
--
45
--
560
1.8.3.1
46
2.13.6
561
47
562
48
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
2
2
3
Instead of just freeing preallocated zero clusters and completely
3
Since bdrv_co_preadv does all neccessary checks including
4
allocating them from scratch, reuse them.
4
reading after the end of the backing file, avoid duplication
5
of verification before bdrv_co_preadv call.
5
6
6
We cannot do this in handle_copied(), however, since this is a COW
7
Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
7
operation. Therefore, we have to add the new logic to handle_alloc() and
8
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
simply return the existing offset if it exists. The only catch is that
9
we have to convince qcow2_alloc_cluster_link_l2() not to free the old
10
clusters (because we have reused them).
11
12
Reported-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
Reviewed-by: Eric Blake <eblake@redhat.com>
9
Reviewed-by: Eric Blake <eblake@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
11
---
17
block/qcow2-cluster.c | 80 +++++++++++++++++++++++++++++++++++----------------
12
block/qcow2.h | 3 ---
18
block/qcow2.h | 3 ++
13
block/qcow2.c | 51 ++++++++-------------------------------------------
19
2 files changed, 59 insertions(+), 24 deletions(-)
14
2 files changed, 8 insertions(+), 46 deletions(-)
20
15
21
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/qcow2-cluster.c
24
+++ b/block/qcow2-cluster.c
25
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
26
uint64_t *l2_table, uint64_t stop_flags)
27
{
28
int i;
29
+ int first_cluster_type;
30
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
31
uint64_t first_entry = be64_to_cpu(l2_table[0]);
32
uint64_t offset = first_entry & mask;
33
34
- if (!offset)
35
+ if (!offset) {
36
return 0;
37
+ }
38
39
- assert(qcow2_get_cluster_type(first_entry) == QCOW2_CLUSTER_NORMAL);
40
+ /* must be allocated */
41
+ first_cluster_type = qcow2_get_cluster_type(first_entry);
42
+ assert(first_cluster_type == QCOW2_CLUSTER_NORMAL ||
43
+ (first_cluster_type == QCOW2_CLUSTER_ZERO &&
44
+ (first_entry & L2E_OFFSET_MASK) != 0));
45
46
for (i = 0; i < nb_clusters; i++) {
47
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
48
@@ -XXX,XX +XXX,XX @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
49
* Don't discard clusters that reach a refcount of 0 (e.g. compressed
50
* clusters), the next write will reuse them anyway.
51
*/
52
- if (j != 0) {
53
+ if (!m->keep_old_clusters && j != 0) {
54
for (i = 0; i < j; i++) {
55
qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1,
56
QCOW2_DISCARD_NEVER);
57
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
58
uint64_t entry;
59
uint64_t nb_clusters;
60
int ret;
61
+ bool keep_old_clusters = false;
62
63
- uint64_t alloc_cluster_offset;
64
+ uint64_t alloc_cluster_offset = 0;
65
66
trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,
67
*bytes);
68
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
69
* wrong with our code. */
70
assert(nb_clusters > 0);
71
72
- qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);
73
+ if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO &&
74
+ (entry & L2E_OFFSET_MASK) != 0 && (entry & QCOW_OFLAG_COPIED) &&
75
+ (!*host_offset ||
76
+ start_of_cluster(s, *host_offset) == (entry & L2E_OFFSET_MASK)))
77
+ {
78
+ /* Try to reuse preallocated zero clusters; contiguous normal clusters
79
+ * would be fine, too, but count_cow_clusters() above has limited
80
+ * nb_clusters already to a range of COW clusters */
81
+ int preallocated_nb_clusters =
82
+ count_contiguous_clusters(nb_clusters, s->cluster_size,
83
+ &l2_table[l2_index], QCOW_OFLAG_COPIED);
84
+ assert(preallocated_nb_clusters > 0);
85
86
- /* Allocate, if necessary at a given offset in the image file */
87
- alloc_cluster_offset = start_of_cluster(s, *host_offset);
88
- ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
89
- &nb_clusters);
90
- if (ret < 0) {
91
- goto fail;
92
- }
93
+ nb_clusters = preallocated_nb_clusters;
94
+ alloc_cluster_offset = entry & L2E_OFFSET_MASK;
95
96
- /* Can't extend contiguous allocation */
97
- if (nb_clusters == 0) {
98
- *bytes = 0;
99
- return 0;
100
+ /* We want to reuse these clusters, so qcow2_alloc_cluster_link_l2()
101
+ * should not free them. */
102
+ keep_old_clusters = true;
103
}
104
105
- /* !*host_offset would overwrite the image header and is reserved for "no
106
- * host offset preferred". If 0 was a valid host offset, it'd trigger the
107
- * following overlap check; do that now to avoid having an invalid value in
108
- * *host_offset. */
109
+ qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);
110
+
111
if (!alloc_cluster_offset) {
112
- ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
113
- nb_clusters * s->cluster_size);
114
- assert(ret < 0);
115
- goto fail;
116
+ /* Allocate, if necessary at a given offset in the image file */
117
+ alloc_cluster_offset = start_of_cluster(s, *host_offset);
118
+ ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
119
+ &nb_clusters);
120
+ if (ret < 0) {
121
+ goto fail;
122
+ }
123
+
124
+ /* Can't extend contiguous allocation */
125
+ if (nb_clusters == 0) {
126
+ *bytes = 0;
127
+ return 0;
128
+ }
129
+
130
+ /* !*host_offset would overwrite the image header and is reserved for
131
+ * "no host offset preferred". If 0 was a valid host offset, it'd
132
+ * trigger the following overlap check; do that now to avoid having an
133
+ * invalid value in *host_offset. */
134
+ if (!alloc_cluster_offset) {
135
+ ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
136
+ nb_clusters * s->cluster_size);
137
+ assert(ret < 0);
138
+ goto fail;
139
+ }
140
}
141
142
/*
143
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
144
.offset = start_of_cluster(s, guest_offset),
145
.nb_clusters = nb_clusters,
146
147
+ .keep_old_clusters = keep_old_clusters,
148
+
149
.cow_start = {
150
.offset = 0,
151
.nb_bytes = offset_into_cluster(s, guest_offset),
152
diff --git a/block/qcow2.h b/block/qcow2.h
16
diff --git a/block/qcow2.h b/block/qcow2.h
153
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
154
--- a/block/qcow2.h
18
--- a/block/qcow2.h
155
+++ b/block/qcow2.h
19
+++ b/block/qcow2.h
156
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
20
@@ -XXX,XX +XXX,XX @@ uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset)
157
/** Number of newly allocated clusters */
21
}
158
int nb_clusters;
22
159
23
/* qcow2.c functions */
160
+ /** Do not free the old clusters */
24
-int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
161
+ bool keep_old_clusters;
25
- int64_t sector_num, int nb_sectors);
162
+
26
-
163
/**
27
int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size,
164
* Requests that overlap with this allocation and wait to be restarted
28
int refcount_order, bool generous_increase,
165
* when the allocating request has completed.
29
uint64_t *refblock_count);
30
diff --git a/block/qcow2.c b/block/qcow2.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2.c
33
+++ b/block/qcow2.c
34
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
35
return status;
36
}
37
38
-/* handle reading after the end of the backing file */
39
-int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
40
- int64_t offset, int bytes)
41
-{
42
- uint64_t bs_size = bs->total_sectors * BDRV_SECTOR_SIZE;
43
- int n1;
44
-
45
- if ((offset + bytes) <= bs_size) {
46
- return bytes;
47
- }
48
-
49
- if (offset >= bs_size) {
50
- n1 = 0;
51
- } else {
52
- n1 = bs_size - offset;
53
- }
54
-
55
- qemu_iovec_memset(qiov, n1, 0, bytes - n1);
56
-
57
- return n1;
58
-}
59
-
60
static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
61
uint64_t bytes, QEMUIOVector *qiov,
62
int flags)
63
{
64
BDRVQcow2State *s = bs->opaque;
65
- int offset_in_cluster, n1;
66
+ int offset_in_cluster;
67
int ret;
68
unsigned int cur_bytes; /* number of bytes in current iteration */
69
uint64_t cluster_offset = 0;
70
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
71
case QCOW2_CLUSTER_UNALLOCATED:
72
73
if (bs->backing) {
74
- /* read from the base image */
75
- n1 = qcow2_backing_read1(bs->backing->bs, &hd_qiov,
76
- offset, cur_bytes);
77
- if (n1 > 0) {
78
- QEMUIOVector local_qiov;
79
-
80
- qemu_iovec_init(&local_qiov, hd_qiov.niov);
81
- qemu_iovec_concat(&local_qiov, &hd_qiov, 0, n1);
82
-
83
- BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
84
- qemu_co_mutex_unlock(&s->lock);
85
- ret = bdrv_co_preadv(bs->backing, offset, n1,
86
- &local_qiov, 0);
87
- qemu_co_mutex_lock(&s->lock);
88
-
89
- qemu_iovec_destroy(&local_qiov);
90
-
91
- if (ret < 0) {
92
- goto fail;
93
- }
94
+ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
95
+ qemu_co_mutex_unlock(&s->lock);
96
+ ret = bdrv_co_preadv(bs->backing, offset, cur_bytes,
97
+ &hd_qiov, 0);
98
+ qemu_co_mutex_lock(&s->lock);
99
+ if (ret < 0) {
100
+ goto fail;
101
}
102
} else {
103
/* Note: in this case, no need to wait */
166
--
104
--
167
1.8.3.1
105
2.13.6
168
106
169
107
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Removing a quorum child node with x-blockdev-change results in a quorum
2
driver state that cannot be recreated with create options because it
3
would require a list with gaps. This causes trouble in at least
4
.bdrv_refresh_filename().
2
5
3
Making this option available even before implementing it will let
6
Document this problem so that we won't accidentally mark the command
4
converting tests easier: in coming patches they can specify the option
7
stable without having addressed it.
5
already when necessary, before we actually write code to lock the
6
images.
7
8
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Reviewed-by: Alberto Garcia <berto@igalia.com>
10
---
11
---
11
block/file-posix.c | 5 +++++
12
qapi/block-core.json | 4 ++++
12
qapi/block-core.json | 4 ++++
13
2 files changed, 9 insertions(+)
13
1 file changed, 4 insertions(+)
14
14
15
diff --git a/block/file-posix.c b/block/file-posix.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/file-posix.c
18
+++ b/block/file-posix.c
19
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_runtime_opts = {
20
.type = QEMU_OPT_STRING,
21
.help = "host AIO implementation (threads, native)",
22
},
23
+ {
24
+ .name = "locking",
25
+ .type = QEMU_OPT_STRING,
26
+ .help = "file locking mode (on/off/auto, default: auto)",
27
+ },
28
{ /* end of list */ }
29
},
30
};
31
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
32
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
33
--- a/qapi/block-core.json
17
--- a/qapi/block-core.json
34
+++ b/qapi/block-core.json
18
+++ b/qapi/block-core.json
35
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
20
# does not support all kinds of operations, all kinds of children, nor
21
# all block drivers.
36
#
22
#
37
# @filename: path to the image file
23
+# FIXME Removing children from a quorum node means introducing gaps in the
38
# @aio: AIO backend (default: threads) (since: 2.8)
24
+# child indices. This cannot be represented in the 'children' list of
39
+# @locking: whether to enable file locking. If set to 'auto', only enable
25
+# BlockdevOptionsQuorum, as returned by .bdrv_refresh_filename().
40
+# when Open File Descriptor (OFD) locking API is available
26
+#
41
+# (default: auto, since 2.10)
27
# Warning: The data in a new quorum child MUST be consistent with that of
28
# the rest of the array.
42
#
29
#
43
# Since: 2.9
44
##
45
{ 'struct': 'BlockdevOptionsFile',
46
'data': { 'filename': 'str',
47
+ '*locking': 'OnOffAuto',
48
'*aio': 'BlockdevAioOptions' } }
49
50
##
51
--
30
--
52
1.8.3.1
31
2.13.6
53
32
54
33
diff view generated by jsdifflib
1
From: Christoph Hellwig <hch@lst.de>
1
From: Doug Gale <doug16k@gmail.com>
2
2
3
Signed-off-by: Keith Busch <keith.busch@intel.com>
3
Add trace output for commands, errors, and undefined behavior.
4
[hch: ported over from qemu-nvme.git to mainline]
4
Add guest error log output for undefined behavior.
5
Signed-off-by: Christoph Hellwig <hch@lst.de>
5
Report invalid undefined accesses to MMIO.
6
Acked-by: Keith Busch <keith.busch@intel.com>
6
Annotate unlikely error checks with unlikely.
7
8
Signed-off-by: Doug Gale <doug16k@gmail.com>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
12
---
9
hw/block/nvme.c | 26 ++++++++++++++++++++++++++
13
hw/block/nvme.c | 349 ++++++++++++++++++++++++++++++++++++++++++--------
10
hw/block/nvme.h | 1 +
14
hw/block/trace-events | 93 ++++++++++++++
11
2 files changed, 27 insertions(+)
15
2 files changed, 390 insertions(+), 52 deletions(-)
12
16
13
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
17
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
14
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/block/nvme.c
19
--- a/hw/block/nvme.c
16
+++ b/hw/block/nvme.c
20
+++ b/hw/block/nvme.c
17
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
21
@@ -XXX,XX +XXX,XX @@
18
return NVME_NO_COMPLETE;
22
#include "qapi/visitor.h"
19
}
23
#include "sysemu/block-backend.h"
20
24
21
+static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
25
+#include "qemu/log.h"
22
+ NvmeRequest *req)
26
+#include "trace.h"
23
+{
27
#include "nvme.h"
24
+ NvmeRwCmd *rw = (NvmeRwCmd *)cmd;
28
25
+ const uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
29
+#define NVME_GUEST_ERR(trace, fmt, ...) \
26
+ const uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
30
+ do { \
27
+ uint64_t slba = le64_to_cpu(rw->slba);
31
+ (trace_##trace)(__VA_ARGS__); \
28
+ uint32_t nlb = le16_to_cpu(rw->nlb) + 1;
32
+ qemu_log_mask(LOG_GUEST_ERROR, #trace \
29
+ uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
33
+ " in %s: " fmt "\n", __func__, ## __VA_ARGS__); \
30
+ uint32_t aio_nlb = nlb << (data_shift - BDRV_SECTOR_BITS);
34
+ } while (0)
31
+
35
+
32
+ if (slba + nlb > ns->id_ns.nsze) {
36
static void nvme_process_sq(void *opaque);
33
+ return NVME_LBA_RANGE | NVME_DNR;
37
34
+ }
38
static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)
35
+
39
@@ -XXX,XX +XXX,XX @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq)
36
+ req->has_sg = false;
37
+ block_acct_start(blk_get_stats(n->conf.blk), &req->acct, 0,
38
+ BLOCK_ACCT_WRITE);
39
+ req->aiocb = blk_aio_pwrite_zeroes(n->conf.blk, aio_slba, aio_nlb,
40
+ BDRV_REQ_MAY_UNMAP, nvme_rw_cb, req);
41
+ return NVME_NO_COMPLETE;
42
+}
43
+
44
static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
45
NvmeRequest *req)
46
{
40
{
41
if (cq->irq_enabled) {
42
if (msix_enabled(&(n->parent_obj))) {
43
+ trace_nvme_irq_msix(cq->vector);
44
msix_notify(&(n->parent_obj), cq->vector);
45
} else {
46
+ trace_nvme_irq_pin();
47
pci_irq_pulse(&n->parent_obj);
48
}
49
+ } else {
50
+ trace_nvme_irq_masked();
51
}
52
}
53
54
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
55
trans_len = MIN(len, trans_len);
56
int num_prps = (len >> n->page_bits) + 1;
57
58
- if (!prp1) {
59
+ if (unlikely(!prp1)) {
60
+ trace_nvme_err_invalid_prp();
61
return NVME_INVALID_FIELD | NVME_DNR;
62
} else if (n->cmbsz && prp1 >= n->ctrl_mem.addr &&
63
prp1 < n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size)) {
64
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
65
}
66
len -= trans_len;
67
if (len) {
68
- if (!prp2) {
69
+ if (unlikely(!prp2)) {
70
+ trace_nvme_err_invalid_prp2_missing();
71
goto unmap;
72
}
73
if (len > n->page_size) {
74
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
75
uint64_t prp_ent = le64_to_cpu(prp_list[i]);
76
77
if (i == n->max_prp_ents - 1 && len > n->page_size) {
78
- if (!prp_ent || prp_ent & (n->page_size - 1)) {
79
+ if (unlikely(!prp_ent || prp_ent & (n->page_size - 1))) {
80
+ trace_nvme_err_invalid_prplist_ent(prp_ent);
81
goto unmap;
82
}
83
84
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
85
prp_ent = le64_to_cpu(prp_list[i]);
86
}
87
88
- if (!prp_ent || prp_ent & (n->page_size - 1)) {
89
+ if (unlikely(!prp_ent || prp_ent & (n->page_size - 1))) {
90
+ trace_nvme_err_invalid_prplist_ent(prp_ent);
91
goto unmap;
92
}
93
94
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
95
i++;
96
}
97
} else {
98
- if (prp2 & (n->page_size - 1)) {
99
+ if (unlikely(prp2 & (n->page_size - 1))) {
100
+ trace_nvme_err_invalid_prp2_align(prp2);
101
goto unmap;
102
}
103
if (qsg->nsg) {
104
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
105
QEMUIOVector iov;
106
uint16_t status = NVME_SUCCESS;
107
108
+ trace_nvme_dma_read(prp1, prp2);
109
+
110
if (nvme_map_prp(&qsg, &iov, prp1, prp2, len, n)) {
111
return NVME_INVALID_FIELD | NVME_DNR;
112
}
113
if (qsg.nsg > 0) {
114
- if (dma_buf_read(ptr, len, &qsg)) {
115
+ if (unlikely(dma_buf_read(ptr, len, &qsg))) {
116
+ trace_nvme_err_invalid_dma();
117
status = NVME_INVALID_FIELD | NVME_DNR;
118
}
119
qemu_sglist_destroy(&qsg);
120
} else {
121
- if (qemu_iovec_to_buf(&iov, 0, ptr, len) != len) {
122
+ if (unlikely(qemu_iovec_to_buf(&iov, 0, ptr, len) != len)) {
123
+ trace_nvme_err_invalid_dma();
124
status = NVME_INVALID_FIELD | NVME_DNR;
125
}
126
qemu_iovec_destroy(&iov);
127
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
128
uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
129
uint32_t aio_nlb = nlb << (data_shift - BDRV_SECTOR_BITS);
130
131
- if (slba + nlb > ns->id_ns.nsze) {
132
+ if (unlikely(slba + nlb > ns->id_ns.nsze)) {
133
+ trace_nvme_err_invalid_lba_range(slba, nlb, ns->id_ns.nsze);
134
return NVME_LBA_RANGE | NVME_DNR;
135
}
136
137
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
138
int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0;
139
enum BlockAcctType acct = is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ;
140
141
- if ((slba + nlb) > ns->id_ns.nsze) {
142
+ trace_nvme_rw(is_write ? "write" : "read", nlb, data_size, slba);
143
+
144
+ if (unlikely((slba + nlb) > ns->id_ns.nsze)) {
145
block_acct_invalid(blk_get_stats(n->conf.blk), acct);
146
+ trace_nvme_err_invalid_lba_range(slba, nlb, ns->id_ns.nsze);
147
return NVME_LBA_RANGE | NVME_DNR;
148
}
149
47
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
150
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
48
switch (cmd->opcode) {
151
NvmeNamespace *ns;
49
case NVME_CMD_FLUSH:
152
uint32_t nsid = le32_to_cpu(cmd->nsid);
50
return nvme_flush(n, ns, cmd, req);
153
51
+ case NVME_CMD_WRITE_ZEROS:
154
- if (nsid == 0 || nsid > n->num_namespaces) {
52
+ return nvme_write_zeros(n, ns, cmd, req);
155
+ if (unlikely(nsid == 0 || nsid > n->num_namespaces)) {
53
case NVME_CMD_WRITE:
156
+ trace_nvme_err_invalid_ns(nsid, n->num_namespaces);
157
return NVME_INVALID_NSID | NVME_DNR;
158
}
159
160
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
54
case NVME_CMD_READ:
161
case NVME_CMD_READ:
55
return nvme_rw(n, ns, cmd, req);
162
return nvme_rw(n, ns, cmd, req);
56
@@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev)
163
default:
57
id->sqes = (0x6 << 4) | 0x6;
164
+ trace_nvme_err_invalid_opc(cmd->opcode);
58
id->cqes = (0x4 << 4) | 0x4;
165
return NVME_INVALID_OPCODE | NVME_DNR;
59
id->nn = cpu_to_le32(n->num_namespaces);
166
}
60
+ id->oncs = cpu_to_le16(NVME_ONCS_WRITE_ZEROS);
167
}
61
id->psd[0].mp = cpu_to_le16(0x9c4);
168
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_del_sq(NvmeCtrl *n, NvmeCmd *cmd)
62
id->psd[0].enlat = cpu_to_le32(0x10);
169
NvmeCQueue *cq;
63
id->psd[0].exlat = cpu_to_le32(0x4);
170
uint16_t qid = le16_to_cpu(c->qid);
64
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
171
172
- if (!qid || nvme_check_sqid(n, qid)) {
173
+ if (unlikely(!qid || nvme_check_sqid(n, qid))) {
174
+ trace_nvme_err_invalid_del_sq(qid);
175
return NVME_INVALID_QID | NVME_DNR;
176
}
177
178
+ trace_nvme_del_sq(qid);
179
+
180
sq = n->sq[qid];
181
while (!QTAILQ_EMPTY(&sq->out_req_list)) {
182
req = QTAILQ_FIRST(&sq->out_req_list);
183
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd)
184
uint16_t qflags = le16_to_cpu(c->sq_flags);
185
uint64_t prp1 = le64_to_cpu(c->prp1);
186
187
- if (!cqid || nvme_check_cqid(n, cqid)) {
188
+ trace_nvme_create_sq(prp1, sqid, cqid, qsize, qflags);
189
+
190
+ if (unlikely(!cqid || nvme_check_cqid(n, cqid))) {
191
+ trace_nvme_err_invalid_create_sq_cqid(cqid);
192
return NVME_INVALID_CQID | NVME_DNR;
193
}
194
- if (!sqid || !nvme_check_sqid(n, sqid)) {
195
+ if (unlikely(!sqid || !nvme_check_sqid(n, sqid))) {
196
+ trace_nvme_err_invalid_create_sq_sqid(sqid);
197
return NVME_INVALID_QID | NVME_DNR;
198
}
199
- if (!qsize || qsize > NVME_CAP_MQES(n->bar.cap)) {
200
+ if (unlikely(!qsize || qsize > NVME_CAP_MQES(n->bar.cap))) {
201
+ trace_nvme_err_invalid_create_sq_size(qsize);
202
return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR;
203
}
204
- if (!prp1 || prp1 & (n->page_size - 1)) {
205
+ if (unlikely(!prp1 || prp1 & (n->page_size - 1))) {
206
+ trace_nvme_err_invalid_create_sq_addr(prp1);
207
return NVME_INVALID_FIELD | NVME_DNR;
208
}
209
- if (!(NVME_SQ_FLAGS_PC(qflags))) {
210
+ if (unlikely(!(NVME_SQ_FLAGS_PC(qflags)))) {
211
+ trace_nvme_err_invalid_create_sq_qflags(NVME_SQ_FLAGS_PC(qflags));
212
return NVME_INVALID_FIELD | NVME_DNR;
213
}
214
sq = g_malloc0(sizeof(*sq));
215
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_del_cq(NvmeCtrl *n, NvmeCmd *cmd)
216
NvmeCQueue *cq;
217
uint16_t qid = le16_to_cpu(c->qid);
218
219
- if (!qid || nvme_check_cqid(n, qid)) {
220
+ if (unlikely(!qid || nvme_check_cqid(n, qid))) {
221
+ trace_nvme_err_invalid_del_cq_cqid(qid);
222
return NVME_INVALID_CQID | NVME_DNR;
223
}
224
225
cq = n->cq[qid];
226
- if (!QTAILQ_EMPTY(&cq->sq_list)) {
227
+ if (unlikely(!QTAILQ_EMPTY(&cq->sq_list))) {
228
+ trace_nvme_err_invalid_del_cq_notempty(qid);
229
return NVME_INVALID_QUEUE_DEL;
230
}
231
+ trace_nvme_del_cq(qid);
232
nvme_free_cq(cq, n);
233
return NVME_SUCCESS;
234
}
235
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)
236
uint16_t qflags = le16_to_cpu(c->cq_flags);
237
uint64_t prp1 = le64_to_cpu(c->prp1);
238
239
- if (!cqid || !nvme_check_cqid(n, cqid)) {
240
+ trace_nvme_create_cq(prp1, cqid, vector, qsize, qflags,
241
+ NVME_CQ_FLAGS_IEN(qflags) != 0);
242
+
243
+ if (unlikely(!cqid || !nvme_check_cqid(n, cqid))) {
244
+ trace_nvme_err_invalid_create_cq_cqid(cqid);
245
return NVME_INVALID_CQID | NVME_DNR;
246
}
247
- if (!qsize || qsize > NVME_CAP_MQES(n->bar.cap)) {
248
+ if (unlikely(!qsize || qsize > NVME_CAP_MQES(n->bar.cap))) {
249
+ trace_nvme_err_invalid_create_cq_size(qsize);
250
return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR;
251
}
252
- if (!prp1) {
253
+ if (unlikely(!prp1)) {
254
+ trace_nvme_err_invalid_create_cq_addr(prp1);
255
return NVME_INVALID_FIELD | NVME_DNR;
256
}
257
- if (vector > n->num_queues) {
258
+ if (unlikely(vector > n->num_queues)) {
259
+ trace_nvme_err_invalid_create_cq_vector(vector);
260
return NVME_INVALID_IRQ_VECTOR | NVME_DNR;
261
}
262
- if (!(NVME_CQ_FLAGS_PC(qflags))) {
263
+ if (unlikely(!(NVME_CQ_FLAGS_PC(qflags)))) {
264
+ trace_nvme_err_invalid_create_cq_qflags(NVME_CQ_FLAGS_PC(qflags));
265
return NVME_INVALID_FIELD | NVME_DNR;
266
}
267
268
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeIdentify *c)
269
uint64_t prp1 = le64_to_cpu(c->prp1);
270
uint64_t prp2 = le64_to_cpu(c->prp2);
271
272
+ trace_nvme_identify_ctrl();
273
+
274
return nvme_dma_read_prp(n, (uint8_t *)&n->id_ctrl, sizeof(n->id_ctrl),
275
prp1, prp2);
276
}
277
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify *c)
278
uint64_t prp1 = le64_to_cpu(c->prp1);
279
uint64_t prp2 = le64_to_cpu(c->prp2);
280
281
- if (nsid == 0 || nsid > n->num_namespaces) {
282
+ trace_nvme_identify_ns(nsid);
283
+
284
+ if (unlikely(nsid == 0 || nsid > n->num_namespaces)) {
285
+ trace_nvme_err_invalid_ns(nsid, n->num_namespaces);
286
return NVME_INVALID_NSID | NVME_DNR;
287
}
288
289
ns = &n->namespaces[nsid - 1];
290
+
291
return nvme_dma_read_prp(n, (uint8_t *)&ns->id_ns, sizeof(ns->id_ns),
292
prp1, prp2);
293
}
294
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeIdentify *c)
295
uint16_t ret;
296
int i, j = 0;
297
298
+ trace_nvme_identify_nslist(min_nsid);
299
+
300
list = g_malloc0(data_len);
301
for (i = 0; i < n->num_namespaces; i++) {
302
if (i < min_nsid) {
303
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeCmd *cmd)
304
case 0x02:
305
return nvme_identify_nslist(n, c);
306
default:
307
+ trace_nvme_err_invalid_identify_cns(le32_to_cpu(c->cns));
308
return NVME_INVALID_FIELD | NVME_DNR;
309
}
310
}
311
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
312
switch (dw10) {
313
case NVME_VOLATILE_WRITE_CACHE:
314
result = blk_enable_write_cache(n->conf.blk);
315
+ trace_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
316
break;
317
case NVME_NUMBER_OF_QUEUES:
318
result = cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16));
319
+ trace_nvme_getfeat_numq(result);
320
break;
321
default:
322
+ trace_nvme_err_invalid_getfeat(dw10);
323
return NVME_INVALID_FIELD | NVME_DNR;
324
}
325
326
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
327
blk_set_enable_write_cache(n->conf.blk, dw11 & 1);
328
break;
329
case NVME_NUMBER_OF_QUEUES:
330
+ trace_nvme_setfeat_numq((dw11 & 0xFFFF) + 1,
331
+ ((dw11 >> 16) & 0xFFFF) + 1,
332
+ n->num_queues - 1, n->num_queues - 1);
333
req->cqe.result =
334
cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16));
335
break;
336
default:
337
+ trace_nvme_err_invalid_setfeat(dw10);
338
return NVME_INVALID_FIELD | NVME_DNR;
339
}
340
return NVME_SUCCESS;
341
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
342
case NVME_ADM_CMD_GET_FEATURES:
343
return nvme_get_feature(n, cmd, req);
344
default:
345
+ trace_nvme_err_invalid_admin_opc(cmd->opcode);
346
return NVME_INVALID_OPCODE | NVME_DNR;
347
}
348
}
349
@@ -XXX,XX +XXX,XX @@ static int nvme_start_ctrl(NvmeCtrl *n)
350
uint32_t page_bits = NVME_CC_MPS(n->bar.cc) + 12;
351
uint32_t page_size = 1 << page_bits;
352
353
- if (n->cq[0] || n->sq[0] || !n->bar.asq || !n->bar.acq ||
354
- n->bar.asq & (page_size - 1) || n->bar.acq & (page_size - 1) ||
355
- NVME_CC_MPS(n->bar.cc) < NVME_CAP_MPSMIN(n->bar.cap) ||
356
- NVME_CC_MPS(n->bar.cc) > NVME_CAP_MPSMAX(n->bar.cap) ||
357
- NVME_CC_IOCQES(n->bar.cc) < NVME_CTRL_CQES_MIN(n->id_ctrl.cqes) ||
358
- NVME_CC_IOCQES(n->bar.cc) > NVME_CTRL_CQES_MAX(n->id_ctrl.cqes) ||
359
- NVME_CC_IOSQES(n->bar.cc) < NVME_CTRL_SQES_MIN(n->id_ctrl.sqes) ||
360
- NVME_CC_IOSQES(n->bar.cc) > NVME_CTRL_SQES_MAX(n->id_ctrl.sqes) ||
361
- !NVME_AQA_ASQS(n->bar.aqa) || !NVME_AQA_ACQS(n->bar.aqa)) {
362
+ if (unlikely(n->cq[0])) {
363
+ trace_nvme_err_startfail_cq();
364
+ return -1;
365
+ }
366
+ if (unlikely(n->sq[0])) {
367
+ trace_nvme_err_startfail_sq();
368
+ return -1;
369
+ }
370
+ if (unlikely(!n->bar.asq)) {
371
+ trace_nvme_err_startfail_nbarasq();
372
+ return -1;
373
+ }
374
+ if (unlikely(!n->bar.acq)) {
375
+ trace_nvme_err_startfail_nbaracq();
376
+ return -1;
377
+ }
378
+ if (unlikely(n->bar.asq & (page_size - 1))) {
379
+ trace_nvme_err_startfail_asq_misaligned(n->bar.asq);
380
+ return -1;
381
+ }
382
+ if (unlikely(n->bar.acq & (page_size - 1))) {
383
+ trace_nvme_err_startfail_acq_misaligned(n->bar.acq);
384
+ return -1;
385
+ }
386
+ if (unlikely(NVME_CC_MPS(n->bar.cc) <
387
+ NVME_CAP_MPSMIN(n->bar.cap))) {
388
+ trace_nvme_err_startfail_page_too_small(
389
+ NVME_CC_MPS(n->bar.cc),
390
+ NVME_CAP_MPSMIN(n->bar.cap));
391
+ return -1;
392
+ }
393
+ if (unlikely(NVME_CC_MPS(n->bar.cc) >
394
+ NVME_CAP_MPSMAX(n->bar.cap))) {
395
+ trace_nvme_err_startfail_page_too_large(
396
+ NVME_CC_MPS(n->bar.cc),
397
+ NVME_CAP_MPSMAX(n->bar.cap));
398
+ return -1;
399
+ }
400
+ if (unlikely(NVME_CC_IOCQES(n->bar.cc) <
401
+ NVME_CTRL_CQES_MIN(n->id_ctrl.cqes))) {
402
+ trace_nvme_err_startfail_cqent_too_small(
403
+ NVME_CC_IOCQES(n->bar.cc),
404
+ NVME_CTRL_CQES_MIN(n->bar.cap));
405
+ return -1;
406
+ }
407
+ if (unlikely(NVME_CC_IOCQES(n->bar.cc) >
408
+ NVME_CTRL_CQES_MAX(n->id_ctrl.cqes))) {
409
+ trace_nvme_err_startfail_cqent_too_large(
410
+ NVME_CC_IOCQES(n->bar.cc),
411
+ NVME_CTRL_CQES_MAX(n->bar.cap));
412
+ return -1;
413
+ }
414
+ if (unlikely(NVME_CC_IOSQES(n->bar.cc) <
415
+ NVME_CTRL_SQES_MIN(n->id_ctrl.sqes))) {
416
+ trace_nvme_err_startfail_sqent_too_small(
417
+ NVME_CC_IOSQES(n->bar.cc),
418
+ NVME_CTRL_SQES_MIN(n->bar.cap));
419
+ return -1;
420
+ }
421
+ if (unlikely(NVME_CC_IOSQES(n->bar.cc) >
422
+ NVME_CTRL_SQES_MAX(n->id_ctrl.sqes))) {
423
+ trace_nvme_err_startfail_sqent_too_large(
424
+ NVME_CC_IOSQES(n->bar.cc),
425
+ NVME_CTRL_SQES_MAX(n->bar.cap));
426
+ return -1;
427
+ }
428
+ if (unlikely(!NVME_AQA_ASQS(n->bar.aqa))) {
429
+ trace_nvme_err_startfail_asqent_sz_zero();
430
+ return -1;
431
+ }
432
+ if (unlikely(!NVME_AQA_ACQS(n->bar.aqa))) {
433
+ trace_nvme_err_startfail_acqent_sz_zero();
434
return -1;
435
}
436
437
@@ -XXX,XX +XXX,XX @@ static int nvme_start_ctrl(NvmeCtrl *n)
438
static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,
439
unsigned size)
440
{
441
+ if (unlikely(offset & (sizeof(uint32_t) - 1))) {
442
+ NVME_GUEST_ERR(nvme_ub_mmiowr_misaligned32,
443
+ "MMIO write not 32-bit aligned,"
444
+ " offset=0x%"PRIx64"", offset);
445
+ /* should be ignored, fall through for now */
446
+ }
447
+
448
+ if (unlikely(size < sizeof(uint32_t))) {
449
+ NVME_GUEST_ERR(nvme_ub_mmiowr_toosmall,
450
+ "MMIO write smaller than 32-bits,"
451
+ " offset=0x%"PRIx64", size=%u",
452
+ offset, size);
453
+ /* should be ignored, fall through for now */
454
+ }
455
+
456
switch (offset) {
457
- case 0xc:
458
+ case 0xc: /* INTMS */
459
+ if (unlikely(msix_enabled(&(n->parent_obj)))) {
460
+ NVME_GUEST_ERR(nvme_ub_mmiowr_intmask_with_msix,
461
+ "undefined access to interrupt mask set"
462
+ " when MSI-X is enabled");
463
+ /* should be ignored, fall through for now */
464
+ }
465
n->bar.intms |= data & 0xffffffff;
466
n->bar.intmc = n->bar.intms;
467
+ trace_nvme_mmio_intm_set(data & 0xffffffff,
468
+ n->bar.intmc);
469
break;
470
- case 0x10:
471
+ case 0x10: /* INTMC */
472
+ if (unlikely(msix_enabled(&(n->parent_obj)))) {
473
+ NVME_GUEST_ERR(nvme_ub_mmiowr_intmask_with_msix,
474
+ "undefined access to interrupt mask clr"
475
+ " when MSI-X is enabled");
476
+ /* should be ignored, fall through for now */
477
+ }
478
n->bar.intms &= ~(data & 0xffffffff);
479
n->bar.intmc = n->bar.intms;
480
+ trace_nvme_mmio_intm_clr(data & 0xffffffff,
481
+ n->bar.intmc);
482
break;
483
- case 0x14:
484
+ case 0x14: /* CC */
485
+ trace_nvme_mmio_cfg(data & 0xffffffff);
486
/* Windows first sends data, then sends enable bit */
487
if (!NVME_CC_EN(data) && !NVME_CC_EN(n->bar.cc) &&
488
!NVME_CC_SHN(data) && !NVME_CC_SHN(n->bar.cc))
489
@@ -XXX,XX +XXX,XX @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,
490
491
if (NVME_CC_EN(data) && !NVME_CC_EN(n->bar.cc)) {
492
n->bar.cc = data;
493
- if (nvme_start_ctrl(n)) {
494
+ if (unlikely(nvme_start_ctrl(n))) {
495
+ trace_nvme_err_startfail();
496
n->bar.csts = NVME_CSTS_FAILED;
497
} else {
498
+ trace_nvme_mmio_start_success();
499
n->bar.csts = NVME_CSTS_READY;
500
}
501
} else if (!NVME_CC_EN(data) && NVME_CC_EN(n->bar.cc)) {
502
+ trace_nvme_mmio_stopped();
503
nvme_clear_ctrl(n);
504
n->bar.csts &= ~NVME_CSTS_READY;
505
}
506
if (NVME_CC_SHN(data) && !(NVME_CC_SHN(n->bar.cc))) {
507
- nvme_clear_ctrl(n);
508
- n->bar.cc = data;
509
- n->bar.csts |= NVME_CSTS_SHST_COMPLETE;
510
+ trace_nvme_mmio_shutdown_set();
511
+ nvme_clear_ctrl(n);
512
+ n->bar.cc = data;
513
+ n->bar.csts |= NVME_CSTS_SHST_COMPLETE;
514
} else if (!NVME_CC_SHN(data) && NVME_CC_SHN(n->bar.cc)) {
515
- n->bar.csts &= ~NVME_CSTS_SHST_COMPLETE;
516
- n->bar.cc = data;
517
+ trace_nvme_mmio_shutdown_cleared();
518
+ n->bar.csts &= ~NVME_CSTS_SHST_COMPLETE;
519
+ n->bar.cc = data;
520
+ }
521
+ break;
522
+ case 0x1C: /* CSTS */
523
+ if (data & (1 << 4)) {
524
+ NVME_GUEST_ERR(nvme_ub_mmiowr_ssreset_w1c_unsupported,
525
+ "attempted to W1C CSTS.NSSRO"
526
+ " but CAP.NSSRS is zero (not supported)");
527
+ } else if (data != 0) {
528
+ NVME_GUEST_ERR(nvme_ub_mmiowr_ro_csts,
529
+ "attempted to set a read only bit"
530
+ " of controller status");
531
+ }
532
+ break;
533
+ case 0x20: /* NSSR */
534
+ if (data == 0x4E564D65) {
535
+ trace_nvme_ub_mmiowr_ssreset_unsupported();
536
+ } else {
537
+ /* The spec says that writes of other values have no effect */
538
+ return;
539
}
540
break;
541
- case 0x24:
542
+ case 0x24: /* AQA */
543
n->bar.aqa = data & 0xffffffff;
544
+ trace_nvme_mmio_aqattr(data & 0xffffffff);
545
break;
546
- case 0x28:
547
+ case 0x28: /* ASQ */
548
n->bar.asq = data;
549
+ trace_nvme_mmio_asqaddr(data);
550
break;
551
- case 0x2c:
552
+ case 0x2c: /* ASQ hi */
553
n->bar.asq |= data << 32;
554
+ trace_nvme_mmio_asqaddr_hi(data, n->bar.asq);
555
break;
556
- case 0x30:
557
+ case 0x30: /* ACQ */
558
+ trace_nvme_mmio_acqaddr(data);
559
n->bar.acq = data;
560
break;
561
- case 0x34:
562
+ case 0x34: /* ACQ hi */
563
n->bar.acq |= data << 32;
564
+ trace_nvme_mmio_acqaddr_hi(data, n->bar.acq);
565
break;
566
+ case 0x38: /* CMBLOC */
567
+ NVME_GUEST_ERR(nvme_ub_mmiowr_cmbloc_reserved,
568
+ "invalid write to reserved CMBLOC"
569
+ " when CMBSZ is zero, ignored");
570
+ return;
571
+ case 0x3C: /* CMBSZ */
572
+ NVME_GUEST_ERR(nvme_ub_mmiowr_cmbsz_readonly,
573
+ "invalid write to read only CMBSZ, ignored");
574
+ return;
575
default:
576
+ NVME_GUEST_ERR(nvme_ub_mmiowr_invalid,
577
+ "invalid MMIO write,"
578
+ " offset=0x%"PRIx64", data=%"PRIx64"",
579
+ offset, data);
580
break;
581
}
582
}
583
@@ -XXX,XX +XXX,XX @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
584
uint8_t *ptr = (uint8_t *)&n->bar;
585
uint64_t val = 0;
586
587
+ if (unlikely(addr & (sizeof(uint32_t) - 1))) {
588
+ NVME_GUEST_ERR(nvme_ub_mmiord_misaligned32,
589
+ "MMIO read not 32-bit aligned,"
590
+ " offset=0x%"PRIx64"", addr);
591
+ /* should RAZ, fall through for now */
592
+ } else if (unlikely(size < sizeof(uint32_t))) {
593
+ NVME_GUEST_ERR(nvme_ub_mmiord_toosmall,
594
+ "MMIO read smaller than 32-bits,"
595
+ " offset=0x%"PRIx64"", addr);
596
+ /* should RAZ, fall through for now */
597
+ }
598
+
599
if (addr < sizeof(n->bar)) {
600
memcpy(&val, ptr + addr, size);
601
+ } else {
602
+ NVME_GUEST_ERR(nvme_ub_mmiord_invalid_ofs,
603
+ "MMIO read beyond last register,"
604
+ " offset=0x%"PRIx64", returning 0", addr);
605
}
606
+
607
return val;
608
}
609
610
@@ -XXX,XX +XXX,XX @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
611
{
612
uint32_t qid;
613
614
- if (addr & ((1 << 2) - 1)) {
615
+ if (unlikely(addr & ((1 << 2) - 1))) {
616
+ NVME_GUEST_ERR(nvme_ub_db_wr_misaligned,
617
+ "doorbell write not 32-bit aligned,"
618
+ " offset=0x%"PRIx64", ignoring", addr);
619
return;
620
}
621
622
if (((addr - 0x1000) >> 2) & 1) {
623
+ /* Completion queue doorbell write */
624
+
625
uint16_t new_head = val & 0xffff;
626
int start_sqs;
627
NvmeCQueue *cq;
628
629
qid = (addr - (0x1000 + (1 << 2))) >> 3;
630
- if (nvme_check_cqid(n, qid)) {
631
+ if (unlikely(nvme_check_cqid(n, qid))) {
632
+ NVME_GUEST_ERR(nvme_ub_db_wr_invalid_cq,
633
+ "completion queue doorbell write"
634
+ " for nonexistent queue,"
635
+ " sqid=%"PRIu32", ignoring", qid);
636
return;
637
}
638
639
cq = n->cq[qid];
640
- if (new_head >= cq->size) {
641
+ if (unlikely(new_head >= cq->size)) {
642
+ NVME_GUEST_ERR(nvme_ub_db_wr_invalid_cqhead,
643
+ "completion queue doorbell write value"
644
+ " beyond queue size, sqid=%"PRIu32","
645
+ " new_head=%"PRIu16", ignoring",
646
+ qid, new_head);
647
return;
648
}
649
650
@@ -XXX,XX +XXX,XX @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
651
nvme_isr_notify(n, cq);
652
}
653
} else {
654
+ /* Submission queue doorbell write */
655
+
656
uint16_t new_tail = val & 0xffff;
657
NvmeSQueue *sq;
658
659
qid = (addr - 0x1000) >> 3;
660
- if (nvme_check_sqid(n, qid)) {
661
+ if (unlikely(nvme_check_sqid(n, qid))) {
662
+ NVME_GUEST_ERR(nvme_ub_db_wr_invalid_sq,
663
+ "submission queue doorbell write"
664
+ " for nonexistent queue,"
665
+ " sqid=%"PRIu32", ignoring", qid);
666
return;
667
}
668
669
sq = n->sq[qid];
670
- if (new_tail >= sq->size) {
671
+ if (unlikely(new_tail >= sq->size)) {
672
+ NVME_GUEST_ERR(nvme_ub_db_wr_invalid_sqtail,
673
+ "submission queue doorbell write value"
674
+ " beyond queue size, sqid=%"PRIu32","
675
+ " new_tail=%"PRIu16", ignoring",
676
+ qid, new_tail);
677
return;
678
}
679
680
diff --git a/hw/block/trace-events b/hw/block/trace-events
65
index XXXXXXX..XXXXXXX 100644
681
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/block/nvme.h
682
--- a/hw/block/trace-events
67
+++ b/hw/block/nvme.h
683
+++ b/hw/block/trace-events
68
@@ -XXX,XX +XXX,XX @@ enum NvmeIoCommands {
684
@@ -XXX,XX +XXX,XX @@ virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs, uint6
69
NVME_CMD_READ = 0x02,
685
hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p LCHS %d %d %d"
70
NVME_CMD_WRITE_UNCOR = 0x04,
686
hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs, int trans) "blk %p CHS %u %u %u trans %d"
71
NVME_CMD_COMPARE = 0x05,
687
72
+ NVME_CMD_WRITE_ZEROS = 0x08,
688
+# hw/block/nvme.c
73
NVME_CMD_DSM = 0x09,
689
+# nvme traces for successful events
74
};
690
+nvme_irq_msix(uint32_t vector) "raising MSI-X IRQ vector %u"
75
691
+nvme_irq_pin(void) "pulsing IRQ pin"
692
+nvme_irq_masked(void) "IRQ is masked"
693
+nvme_dma_read(uint64_t prp1, uint64_t prp2) "DMA read, prp1=0x%"PRIx64" prp2=0x%"PRIx64""
694
+nvme_rw(char const *verb, uint32_t blk_count, uint64_t byte_count, uint64_t lba) "%s %"PRIu32" blocks (%"PRIu64" bytes) from LBA %"PRIu64""
695
+nvme_create_sq(uint64_t addr, uint16_t sqid, uint16_t cqid, uint16_t qsize, uint16_t qflags) "create submission queue, addr=0x%"PRIx64", sqid=%"PRIu16", cqid=%"PRIu16", qsize=%"PRIu16", qflags=%"PRIu16""
696
+nvme_create_cq(uint64_t addr, uint16_t cqid, uint16_t vector, uint16_t size, uint16_t qflags, int ien) "create completion queue, addr=0x%"PRIx64", cqid=%"PRIu16", vector=%"PRIu16", qsize=%"PRIu16", qflags=%"PRIu16", ien=%d"
697
+nvme_del_sq(uint16_t qid) "deleting submission queue sqid=%"PRIu16""
698
+nvme_del_cq(uint16_t cqid) "deleted completion queue, sqid=%"PRIu16""
699
+nvme_identify_ctrl(void) "identify controller"
700
+nvme_identify_ns(uint16_t ns) "identify namespace, nsid=%"PRIu16""
701
+nvme_identify_nslist(uint16_t ns) "identify namespace list, nsid=%"PRIu16""
702
+nvme_getfeat_vwcache(char const* result) "get feature volatile write cache, result=%s"
703
+nvme_getfeat_numq(int result) "get feature number of queues, result=%d"
704
+nvme_setfeat_numq(int reqcq, int reqsq, int gotcq, int gotsq) "requested cq_count=%d sq_count=%d, responding with cq_count=%d sq_count=%d"
705
+nvme_mmio_intm_set(uint64_t data, uint64_t new_mask) "wrote MMIO, interrupt mask set, data=0x%"PRIx64", new_mask=0x%"PRIx64""
706
+nvme_mmio_intm_clr(uint64_t data, uint64_t new_mask) "wrote MMIO, interrupt mask clr, data=0x%"PRIx64", new_mask=0x%"PRIx64""
707
+nvme_mmio_cfg(uint64_t data) "wrote MMIO, config controller config=0x%"PRIx64""
708
+nvme_mmio_aqattr(uint64_t data) "wrote MMIO, admin queue attributes=0x%"PRIx64""
709
+nvme_mmio_asqaddr(uint64_t data) "wrote MMIO, admin submission queue address=0x%"PRIx64""
710
+nvme_mmio_acqaddr(uint64_t data) "wrote MMIO, admin completion queue address=0x%"PRIx64""
711
+nvme_mmio_asqaddr_hi(uint64_t data, uint64_t new_addr) "wrote MMIO, admin submission queue high half=0x%"PRIx64", new_address=0x%"PRIx64""
712
+nvme_mmio_acqaddr_hi(uint64_t data, uint64_t new_addr) "wrote MMIO, admin completion queue high half=0x%"PRIx64", new_address=0x%"PRIx64""
713
+nvme_mmio_start_success(void) "setting controller enable bit succeeded"
714
+nvme_mmio_stopped(void) "cleared controller enable bit"
715
+nvme_mmio_shutdown_set(void) "shutdown bit set"
716
+nvme_mmio_shutdown_cleared(void) "shutdown bit cleared"
717
+
718
+# nvme traces for error conditions
719
+nvme_err_invalid_dma(void) "PRP/SGL is too small for transfer size"
720
+nvme_err_invalid_prplist_ent(uint64_t prplist) "PRP list entry is null or not page aligned: 0x%"PRIx64""
721
+nvme_err_invalid_prp2_align(uint64_t prp2) "PRP2 is not page aligned: 0x%"PRIx64""
722
+nvme_err_invalid_prp2_missing(void) "PRP2 is null and more data to be transferred"
723
+nvme_err_invalid_field(void) "invalid field"
724
+nvme_err_invalid_prp(void) "invalid PRP"
725
+nvme_err_invalid_sgl(void) "invalid SGL"
726
+nvme_err_invalid_ns(uint32_t ns, uint32_t limit) "invalid namespace %u not within 1-%u"
727
+nvme_err_invalid_opc(uint8_t opc) "invalid opcode 0x%"PRIx8""
728
+nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx8""
729
+nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limit) "Invalid LBA start=%"PRIu64" len=%"PRIu64" limit=%"PRIu64""
730
+nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16""
731
+nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16""
732
+nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submission queue, invalid sqid=%"PRIu16""
733
+nvme_err_invalid_create_sq_size(uint16_t qsize) "failed creating submission queue, invalid qsize=%"PRIu16""
734
+nvme_err_invalid_create_sq_addr(uint64_t addr) "failed creating submission queue, addr=0x%"PRIx64""
735
+nvme_err_invalid_create_sq_qflags(uint16_t qflags) "failed creating submission queue, qflags=%"PRIu16""
736
+nvme_err_invalid_del_cq_cqid(uint16_t cqid) "failed deleting completion queue, cqid=%"PRIu16""
737
+nvme_err_invalid_del_cq_notempty(uint16_t cqid) "failed deleting completion queue, it is not empty, cqid=%"PRIu16""
738
+nvme_err_invalid_create_cq_cqid(uint16_t cqid) "failed creating completion queue, cqid=%"PRIu16""
739
+nvme_err_invalid_create_cq_size(uint16_t size) "failed creating completion queue, size=%"PRIu16""
740
+nvme_err_invalid_create_cq_addr(uint64_t addr) "failed creating completion queue, addr=0x%"PRIx64""
741
+nvme_err_invalid_create_cq_vector(uint16_t vector) "failed creating completion queue, vector=%"PRIu16""
742
+nvme_err_invalid_create_cq_qflags(uint16_t qflags) "failed creating completion queue, qflags=%"PRIu16""
743
+nvme_err_invalid_identify_cns(uint16_t cns) "identify, invalid cns=0x%"PRIx16""
744
+nvme_err_invalid_getfeat(int dw10) "invalid get features, dw10=0x%"PRIx32""
745
+nvme_err_invalid_setfeat(uint32_t dw10) "invalid set features, dw10=0x%"PRIx32""
746
+nvme_err_startfail_cq(void) "nvme_start_ctrl failed because there are non-admin completion queues"
747
+nvme_err_startfail_sq(void) "nvme_start_ctrl failed because there are non-admin submission queues"
748
+nvme_err_startfail_nbarasq(void) "nvme_start_ctrl failed because the admin submission queue address is null"
749
+nvme_err_startfail_nbaracq(void) "nvme_start_ctrl failed because the admin completion queue address is null"
750
+nvme_err_startfail_asq_misaligned(uint64_t addr) "nvme_start_ctrl failed because the admin submission queue address is misaligned: 0x%"PRIx64""
751
+nvme_err_startfail_acq_misaligned(uint64_t addr) "nvme_start_ctrl failed because the admin completion queue address is misaligned: 0x%"PRIx64""
752
+nvme_err_startfail_page_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the page size is too small: log2size=%u, min=%u"
753
+nvme_err_startfail_page_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the page size is too large: log2size=%u, max=%u"
754
+nvme_err_startfail_cqent_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the completion queue entry size is too small: log2size=%u, min=%u"
755
+nvme_err_startfail_cqent_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the completion queue entry size is too large: log2size=%u, max=%u"
756
+nvme_err_startfail_sqent_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the submission queue entry size is too small: log2size=%u, min=%u"
757
+nvme_err_startfail_sqent_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the submission queue entry size is too large: log2size=%u, max=%u"
758
+nvme_err_startfail_asqent_sz_zero(void) "nvme_start_ctrl failed because the admin submission queue size is zero"
759
+nvme_err_startfail_acqent_sz_zero(void) "nvme_start_ctrl failed because the admin completion queue size is zero"
760
+nvme_err_startfail(void) "setting controller enable bit failed"
761
+
762
+# Traces for undefined behavior
763
+nvme_ub_mmiowr_misaligned32(uint64_t offset) "MMIO write not 32-bit aligned, offset=0x%"PRIx64""
764
+nvme_ub_mmiowr_toosmall(uint64_t offset, unsigned size) "MMIO write smaller than 32 bits, offset=0x%"PRIx64", size=%u"
765
+nvme_ub_mmiowr_intmask_with_msix(void) "undefined access to interrupt mask set when MSI-X is enabled"
766
+nvme_ub_mmiowr_ro_csts(void) "attempted to set a read only bit of controller status"
767
+nvme_ub_mmiowr_ssreset_w1c_unsupported(void) "attempted to W1C CSTS.NSSRO but CAP.NSSRS is zero (not supported)"
768
+nvme_ub_mmiowr_ssreset_unsupported(void) "attempted NVM subsystem reset but CAP.NSSRS is zero (not supported)"
769
+nvme_ub_mmiowr_cmbloc_reserved(void) "invalid write to reserved CMBLOC when CMBSZ is zero, ignored"
770
+nvme_ub_mmiowr_cmbsz_readonly(void) "invalid write to read only CMBSZ, ignored"
771
+nvme_ub_mmiowr_invalid(uint64_t offset, uint64_t data) "invalid MMIO write, offset=0x%"PRIx64", data=0x%"PRIx64""
772
+nvme_ub_mmiord_misaligned32(uint64_t offset) "MMIO read not 32-bit aligned, offset=0x%"PRIx64""
773
+nvme_ub_mmiord_toosmall(uint64_t offset) "MMIO read smaller than 32-bits, offset=0x%"PRIx64""
774
+nvme_ub_mmiord_invalid_ofs(uint64_t offset) "MMIO read beyond last register, offset=0x%"PRIx64", returning 0"
775
+nvme_ub_db_wr_misaligned(uint64_t offset) "doorbell write not 32-bit aligned, offset=0x%"PRIx64", ignoring"
776
+nvme_ub_db_wr_invalid_cq(uint32_t qid) "completion queue doorbell write for nonexistent queue, cqid=%"PRIu32", ignoring"
777
+nvme_ub_db_wr_invalid_cqhead(uint32_t qid, uint16_t new_head) "completion queue doorbell write value beyond queue size, cqid=%"PRIu32", new_head=%"PRIu16", ignoring"
778
+nvme_ub_db_wr_invalid_sq(uint32_t qid) "submission queue doorbell write for nonexistent queue, sqid=%"PRIu32", ignoring"
779
+nvme_ub_db_wr_invalid_sqtail(uint32_t qid, uint16_t new_tail) "submission queue doorbell write value beyond queue size, sqid=%"PRIu32", new_head=%"PRIu16", ignoring"
780
+
781
# hw/block/xen_disk.c
782
xen_disk_alloc(char *name) "%s"
783
xen_disk_init(char *name) "%s"
76
--
784
--
77
1.8.3.1
785
2.13.6
78
786
79
787
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Fam Zheng <famz@redhat.com>
2
2
3
It can be used outside of block.c for making user friendly messages.
3
Management tools create overlays of running guests with qemu-img:
4
4
5
$ qemu-img create -b /image/in/use.qcow2 -f qcow2 /overlay/image.qcow2
6
7
but this doesn't work anymore due to image locking:
8
9
qemu-img: /overlay/image.qcow2: Failed to get shared "write" lock
10
Is another process using the image?
11
Could not open backing image to determine size.
12
Use the force share option to allow this use case again.
13
14
Cc: qemu-stable@nongnu.org
5
Signed-off-by: Fam Zheng <famz@redhat.com>
15
Signed-off-by: Fam Zheng <famz@redhat.com>
16
Reviewed-by: Eric Blake <eblake@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
18
---
8
block.c | 2 +-
19
block.c | 3 ++-
9
include/block/block.h | 2 ++
20
1 file changed, 2 insertions(+), 1 deletion(-)
10
2 files changed, 3 insertions(+), 1 deletion(-)
11
21
12
diff --git a/block.c b/block.c
22
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
24
--- a/block.c
15
+++ b/block.c
25
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static char *bdrv_child_user_desc(BdrvChild *c)
26
@@ -XXX,XX +XXX,XX @@ void bdrv_img_create(const char *filename, const char *fmt,
17
return g_strdup("another user");
27
back_flags = flags;
18
}
28
back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
19
29
20
-static char *bdrv_perm_names(uint64_t perm)
30
+ backing_options = qdict_new();
21
+char *bdrv_perm_names(uint64_t perm)
31
if (backing_fmt) {
22
{
32
- backing_options = qdict_new();
23
struct perm_name {
33
qdict_put_str(backing_options, "driver", backing_fmt);
24
uint64_t perm;
34
}
25
diff --git a/include/block/block.h b/include/block/block.h
35
+ qdict_put_bool(backing_options, BDRV_OPT_FORCE_SHARE, true);
26
index XXXXXXX..XXXXXXX 100644
36
27
--- a/include/block/block.h
37
bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
28
+++ b/include/block/block.h
38
&local_err);
29
@@ -XXX,XX +XXX,XX @@ enum {
30
BLK_PERM_ALL = 0x1f,
31
};
32
33
+char *bdrv_perm_names(uint64_t perm);
34
+
35
/* disk I/O throttling */
36
void bdrv_init(void);
37
void bdrv_init_with_whitelist(void);
38
--
39
--
39
1.8.3.1
40
2.13.6
40
41
41
42
diff view generated by jsdifflib
1
From: John Snow <jsnow@redhat.com>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1447551
3
It's not working anymore since QEMU v1.3.0 - time to remove it now.
4
4
5
If one tries to issue a block_resize while a guest is busy
5
Signed-off-by: Thomas Huth <thuth@redhat.com>
6
accessing the disk, it is possible that qemu may deadlock
6
Reviewed-by: John Snow <jsnow@redhat.com>
7
when invoking aio_poll from both the main loop and the iothread.
7
Reviewed-by: Markus Armbruster <armbru@redhat.com>
8
9
Replace another instance of bdrv_drain_all that doesn't
10
quite belong.
11
12
Cc: qemu-stable@nongnu.org
13
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
14
Signed-off-by: John Snow <jsnow@redhat.com>
15
Reviewed-by: Eric Blake <eblake@redhat.com>
16
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
9
---
19
blockdev.c | 5 ++---
10
blockdev.c | 11 -----------
20
1 file changed, 2 insertions(+), 3 deletions(-)
11
qemu-doc.texi | 6 ------
12
2 files changed, 17 deletions(-)
21
13
22
diff --git a/blockdev.c b/blockdev.c
14
diff --git a/blockdev.c b/blockdev.c
23
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
24
--- a/blockdev.c
16
--- a/blockdev.c
25
+++ b/blockdev.c
17
+++ b/blockdev.c
26
@@ -XXX,XX +XXX,XX @@ void qmp_block_resize(bool has_device, const char *device,
18
@@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = {
27
goto out;
19
.type = QEMU_OPT_STRING,
20
.help = "chs translation (auto, lba, none)",
21
},{
22
- .name = "boot",
23
- .type = QEMU_OPT_BOOL,
24
- .help = "(deprecated, ignored)",
25
- },{
26
.name = "addr",
27
.type = QEMU_OPT_STRING,
28
.help = "pci address (virtio only)",
29
@@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
30
goto fail;
28
}
31
}
29
32
30
- /* complete all in-flight operations before resizing the device */
33
- /* Deprecated option boot=[on|off] */
31
- bdrv_drain_all();
34
- if (qemu_opt_get(legacy_opts, "boot") != NULL) {
35
- fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be "
36
- "ignored. Future versions will reject this parameter. Please "
37
- "update your scripts.\n");
38
- }
32
-
39
-
33
+ bdrv_drained_begin(bs);
40
/* Other deprecated options */
34
ret = blk_truncate(blk, size, errp);
41
if (!qtest_enabled()) {
35
+ bdrv_drained_end(bs);
42
for (i = 0; i < ARRAY_SIZE(deprecated); i++) {
36
43
diff --git a/qemu-doc.texi b/qemu-doc.texi
37
out:
44
index XXXXXXX..XXXXXXX 100644
38
blk_unref(blk);
45
--- a/qemu-doc.texi
46
+++ b/qemu-doc.texi
47
@@ -XXX,XX +XXX,XX @@ deprecated.
48
49
@section System emulator command line arguments
50
51
-@subsection -drive boot=on|off (since 1.3.0)
52
-
53
-The ``boot=on|off'' option to the ``-drive'' argument is
54
-ignored. Applications should use the ``bootindex=N'' parameter
55
-to set an absolute ordering between devices instead.
56
-
57
@subsection -tdf (since 1.3.0)
58
59
The ``-tdf'' argument is ignored. The behaviour implemented
39
--
60
--
40
1.8.3.1
61
2.13.6
41
62
42
63
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
It's been marked as deprecated since QEMU v2.10.0, and so far nobody
4
complained that we should keep it, so let's remove this legacy option
5
now to simplify the code quite a bit.
6
7
Signed-off-by: Thomas Huth <thuth@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
Reviewed-by: Markus Armbruster <armbru@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
11
---
6
qemu-img-cmds.hx | 36 ++++++++++++++++++------------------
12
vl.c | 86 ++-------------------------------------------------------
7
1 file changed, 18 insertions(+), 18 deletions(-)
13
qemu-doc.texi | 8 ------
8
14
qemu-options.hx | 19 ++-----------
9
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
15
3 files changed, 4 insertions(+), 109 deletions(-)
16
17
diff --git a/vl.c b/vl.c
10
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
11
--- a/qemu-img-cmds.hx
19
--- a/vl.c
12
+++ b/qemu-img-cmds.hx
20
+++ b/vl.c
13
@@ -XXX,XX +XXX,XX @@ STEXI
21
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
22
const char *boot_order = NULL;
23
const char *boot_once = NULL;
24
DisplayState *ds;
25
- int cyls, heads, secs, translation;
26
QemuOpts *opts, *machine_opts;
27
- QemuOpts *hda_opts = NULL, *icount_opts = NULL, *accel_opts = NULL;
28
+ QemuOpts *icount_opts = NULL, *accel_opts = NULL;
29
QemuOptsList *olist;
30
int optind;
31
const char *optarg;
32
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
33
34
cpu_model = NULL;
35
snapshot = 0;
36
- cyls = heads = secs = 0;
37
- translation = BIOS_ATA_TRANSLATION_AUTO;
38
39
nb_nics = 0;
40
41
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
42
if (optind >= argc)
43
break;
44
if (argv[optind][0] != '-') {
45
- hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
46
+ drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
47
} else {
48
const QEMUOption *popt;
49
50
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
51
cpu_model = optarg;
52
break;
53
case QEMU_OPTION_hda:
54
- {
55
- char buf[256];
56
- if (cyls == 0)
57
- snprintf(buf, sizeof(buf), "%s", HD_OPTS);
58
- else
59
- snprintf(buf, sizeof(buf),
60
- "%s,cyls=%d,heads=%d,secs=%d%s",
61
- HD_OPTS , cyls, heads, secs,
62
- translation == BIOS_ATA_TRANSLATION_LBA ?
63
- ",trans=lba" :
64
- translation == BIOS_ATA_TRANSLATION_NONE ?
65
- ",trans=none" : "");
66
- drive_add(IF_DEFAULT, 0, optarg, buf);
67
- break;
68
- }
69
case QEMU_OPTION_hdb:
70
case QEMU_OPTION_hdc:
71
case QEMU_OPTION_hdd:
72
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
73
case QEMU_OPTION_snapshot:
74
snapshot = 1;
75
break;
76
- case QEMU_OPTION_hdachs:
77
- {
78
- const char *p;
79
- p = optarg;
80
- cyls = strtol(p, (char **)&p, 0);
81
- if (cyls < 1 || cyls > 16383)
82
- goto chs_fail;
83
- if (*p != ',')
84
- goto chs_fail;
85
- p++;
86
- heads = strtol(p, (char **)&p, 0);
87
- if (heads < 1 || heads > 16)
88
- goto chs_fail;
89
- if (*p != ',')
90
- goto chs_fail;
91
- p++;
92
- secs = strtol(p, (char **)&p, 0);
93
- if (secs < 1 || secs > 63)
94
- goto chs_fail;
95
- if (*p == ',') {
96
- p++;
97
- if (!strcmp(p, "large")) {
98
- translation = BIOS_ATA_TRANSLATION_LARGE;
99
- } else if (!strcmp(p, "rechs")) {
100
- translation = BIOS_ATA_TRANSLATION_RECHS;
101
- } else if (!strcmp(p, "none")) {
102
- translation = BIOS_ATA_TRANSLATION_NONE;
103
- } else if (!strcmp(p, "lba")) {
104
- translation = BIOS_ATA_TRANSLATION_LBA;
105
- } else if (!strcmp(p, "auto")) {
106
- translation = BIOS_ATA_TRANSLATION_AUTO;
107
- } else {
108
- goto chs_fail;
109
- }
110
- } else if (*p != '\0') {
111
- chs_fail:
112
- error_report("invalid physical CHS format");
113
- exit(1);
114
- }
115
- if (hda_opts != NULL) {
116
- qemu_opt_set_number(hda_opts, "cyls", cyls,
117
- &error_abort);
118
- qemu_opt_set_number(hda_opts, "heads", heads,
119
- &error_abort);
120
- qemu_opt_set_number(hda_opts, "secs", secs,
121
- &error_abort);
122
- if (translation == BIOS_ATA_TRANSLATION_LARGE) {
123
- qemu_opt_set(hda_opts, "trans", "large",
124
- &error_abort);
125
- } else if (translation == BIOS_ATA_TRANSLATION_RECHS) {
126
- qemu_opt_set(hda_opts, "trans", "rechs",
127
- &error_abort);
128
- } else if (translation == BIOS_ATA_TRANSLATION_LBA) {
129
- qemu_opt_set(hda_opts, "trans", "lba",
130
- &error_abort);
131
- } else if (translation == BIOS_ATA_TRANSLATION_NONE) {
132
- qemu_opt_set(hda_opts, "trans", "none",
133
- &error_abort);
134
- }
135
- }
136
- }
137
- error_report("'-hdachs' is deprecated, please use '-device"
138
- " ide-hd,cyls=c,heads=h,secs=s,...' instead");
139
- break;
140
case QEMU_OPTION_numa:
141
opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
142
optarg, true);
143
diff --git a/qemu-doc.texi b/qemu-doc.texi
144
index XXXXXXX..XXXXXXX 100644
145
--- a/qemu-doc.texi
146
+++ b/qemu-doc.texi
147
@@ -XXX,XX +XXX,XX @@ The ``--net dump'' argument is now replaced with the
148
``-object filter-dump'' argument which works in combination
149
with the modern ``-netdev`` backends instead.
150
151
-@subsection -hdachs (since 2.10.0)
152
-
153
-The ``-hdachs'' argument is now a synonym for setting
154
-the ``cyls'', ``heads'', ``secs'', and ``trans'' properties
155
-on the ``ide-hd'' device using the ``-device'' argument.
156
-The new syntax allows different settings to be provided
157
-per disk.
158
-
159
@subsection -usbdevice (since 2.10.0)
160
161
The ``-usbdevice DEV'' argument is now a synonym for setting
162
diff --git a/qemu-options.hx b/qemu-options.hx
163
index XXXXXXX..XXXXXXX 100644
164
--- a/qemu-options.hx
165
+++ b/qemu-options.hx
166
@@ -XXX,XX +XXX,XX @@ of available connectors of a given interface type.
167
@item media=@var{media}
168
This option defines the type of the media: disk or cdrom.
169
@item cyls=@var{c},heads=@var{h},secs=@var{s}[,trans=@var{t}]
170
-These options have the same definition as they have in @option{-hdachs}.
171
-These parameters are deprecated, use the corresponding parameters
172
+Force disk physical geometry and the optional BIOS translation (trans=none or
173
+lba). These parameters are deprecated, use the corresponding parameters
174
of @code{-device} instead.
175
@item snapshot=@var{snapshot}
176
@var{snapshot} is "on" or "off" and controls snapshot mode for the given drive
177
@@ -XXX,XX +XXX,XX @@ the raw disk image you use is not written back. You can however force
178
the write back by pressing @key{C-a s} (@pxref{disk_images}).
14
ETEXI
179
ETEXI
15
180
16
DEF("bench", img_bench,
181
-DEF("hdachs", HAS_ARG, QEMU_OPTION_hdachs, \
17
- "bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] [-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename")
182
- "-hdachs c,h,s[,t]\n" \
18
+ "bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] [-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] [-U] filename")
183
- " force hard disk 0 physical geometry and the optional BIOS\n" \
19
STEXI
184
- " translation (t=none or lba) (usually QEMU can guess them)\n",
20
-@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] [--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename}
185
- QEMU_ARCH_ALL)
21
+@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] [--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] [-U] @var{filename}
186
-STEXI
22
ETEXI
187
-@item -hdachs @var{c},@var{h},@var{s},[,@var{t}]
23
188
-@findex -hdachs
24
DEF("check", img_check,
189
-Force hard disk 0 physical geometry (1 <= @var{c} <= 16383, 1 <=
25
- "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename")
190
-@var{h} <= 16, 1 <= @var{s} <= 63) and optionally force the BIOS
26
+ "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] [-U] filename")
191
-translation mode (@var{t}=none, lba or auto). Usually QEMU can guess
27
STEXI
192
-all those parameters. This option is deprecated, please use
28
-@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename}
193
-@code{-device ide-hd,cyls=c,heads=h,secs=s,...} instead.
29
+@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] [-U] @var{filename}
194
-ETEXI
30
ETEXI
195
-
31
196
DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
32
DEF("create", img_create,
197
"-fsdev fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}]\n"
33
@@ -XXX,XX +XXX,XX @@ STEXI
198
" [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd][,fmode=fmode][,dmode=dmode]\n"
34
ETEXI
35
36
DEF("compare", img_compare,
37
- "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 filename2")
38
+ "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] filename1 filename2")
39
STEXI
40
-@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
41
+@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] [-U] @var{filename1} @var{filename2}
42
ETEXI
43
44
DEF("convert", img_convert,
45
- "convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
46
+ "convert [--object objectdef] [--image-opts] [-U] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
47
STEXI
48
-@item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename}
49
+@item convert [--object @var{objectdef}] [--image-opts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename}
50
ETEXI
51
52
DEF("dd", img_dd,
53
- "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] if=input of=output")
54
+ "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] if=input of=output")
55
STEXI
56
-@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
57
+@item dd [--image-opts] [-U] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
58
ETEXI
59
60
DEF("info", img_info,
61
- "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] filename")
62
+ "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] [-U] filename")
63
STEXI
64
-@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] @var{filename}
65
+@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] [-U] @var{filename}
66
ETEXI
67
68
DEF("map", img_map,
69
- "map [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] filename")
70
+ "map [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-U] filename")
71
STEXI
72
-@item map [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] @var{filename}
73
+@item map [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [-U] @var{filename}
74
ETEXI
75
76
DEF("snapshot", img_snapshot,
77
- "snapshot [--object objectdef] [--image-opts] [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
78
+ "snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
79
STEXI
80
-@item snapshot [--object @var{objectdef}] [--image-opts] [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
81
+@item snapshot [--object @var{objectdef}] [--image-opts] [-U] [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
82
ETEXI
83
84
DEF("rebase", img_rebase,
85
- "rebase [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
86
+ "rebase [--object objectdef] [--image-opts] [-U] [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
87
STEXI
88
-@item rebase [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
89
+@item rebase [--object @var{objectdef}] [--image-opts] [-U] [-q] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
90
ETEXI
91
92
DEF("resize", img_resize,
93
--
199
--
94
1.8.3.1
200
2.13.6
95
201
96
202
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
066 was supposed to be a test "for discarding preallocated zero
3
Looks like we forgot to announce the deprecation of these options in
4
clusters", but it did so incompletely: While it did check the image
4
the corresponding chapter of the qemu-doc text, so let's do that now.
5
file's integrity after the operation, it did not confirm that the
6
clusters are indeed freed. This patch adds this test.
7
5
8
In addition, new cases for writing to preallocated zero clusters are
6
Signed-off-by: Thomas Huth <thuth@redhat.com>
9
added.
7
Reviewed-by: John Snow <jsnow@redhat.com>
10
8
Reviewed-by: Markus Armbruster <armbru@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
10
---
15
tests/qemu-iotests/066 | 128 ++++++++++++++++++++++++++++++++++++++++++++-
11
qemu-doc.texi | 15 +++++++++++++++
16
tests/qemu-iotests/066.out | 46 ++++++++++++++++
12
1 file changed, 15 insertions(+)
17
2 files changed, 173 insertions(+), 1 deletion(-)
18
13
19
diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066
14
diff --git a/qemu-doc.texi b/qemu-doc.texi
20
index XXXXXXX..XXXXXXX 100755
15
index XXXXXXX..XXXXXXX 100644
21
--- a/tests/qemu-iotests/066
16
--- a/qemu-doc.texi
22
+++ b/tests/qemu-iotests/066
17
+++ b/qemu-doc.texi
23
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ longer be directly supported in QEMU.
24
#!/bin/bash
19
The ``-drive if=scsi'' argument is replaced by the the
25
#
20
``-device BUS-TYPE'' argument combined with ``-drive if=none''.
26
-# Test case for discarding preallocated zero clusters in qcow2
21
27
+# Test case for preallocated zero clusters in qcow2
22
+@subsection -drive cyls=...,heads=...,secs=...,trans=... (since 2.10.0)
28
#
29
# Copyright (C) 2013 Red Hat, Inc.
30
#
31
@@ -XXX,XX +XXX,XX @@ _make_test_img $IMG_SIZE
32
$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \
33
     -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \
34
| _filter_qemu_io
35
+
23
+
36
# Check the image (there shouldn't be any leaks)
24
+The drive geometry arguments are replaced by the the geometry arguments
37
_check_test_img
25
+that can be specified with the ``-device'' parameter.
38
+# Map the image (we want all clusters to be gone)
39
+$QEMU_IMG map "$TEST_IMG"
40
+
26
+
41
+_cleanup_test_img
27
+@subsection -drive serial=... (since 2.10.0)
42
+
28
+
29
+The drive serial argument is replaced by the the serial argument
30
+that can be specified with the ``-device'' parameter.
43
+
31
+
44
+echo
32
+@subsection -drive addr=... (since 2.10.0)
45
+echo '=== Writing to preallocated zero clusters ==='
46
+echo
47
+
33
+
48
+_make_test_img $IMG_SIZE
34
+The drive addr argument is replaced by the the addr argument
35
+that can be specified with the ``-device'' parameter.
49
+
36
+
50
+# Create data clusters (not aligned to an L2 table)
37
@subsection -net dump (since 2.10.0)
51
+$QEMU_IO -c 'write -P 42 1M 256k' "$TEST_IMG" | _filter_qemu_io
38
52
+orig_map=$($QEMU_IMG map --output=json "$TEST_IMG")
39
The ``--net dump'' argument is now replaced with the
53
+
54
+# Convert the data clusters to preallocated zero clusters
55
+$QEMU_IO -c 'write -z 1M 256k' "$TEST_IMG" | _filter_qemu_io
56
+
57
+# Now write to them (with a COW needed for the head and tail)
58
+$QEMU_IO -c "write -P 23 $(((1024 + 32) * 1024)) 192k" "$TEST_IMG" \
59
+ | _filter_qemu_io
60
+
61
+# Check metadata correctness
62
+_check_test_img
63
+
64
+# Check data correctness
65
+$QEMU_IO -c "read -P 0 $(( 1024 * 1024)) 32k" \
66
+ -c "read -P 23 $(((1024 + 32) * 1024)) 192k" \
67
+ -c "read -P 0 $(((1024 + 32 + 192) * 1024)) 32k" \
68
+ "$TEST_IMG" \
69
+ | _filter_qemu_io
70
+
71
+# Check that we have actually reused the original area
72
+new_map=$($QEMU_IMG map --output=json "$TEST_IMG")
73
+if [ "$new_map" = "$orig_map" ]; then
74
+ echo 'Successfully reused original clusters.'
75
+else
76
+ echo 'Failed to reuse original clusters.'
77
+ echo 'Original map:'
78
+ echo "$orig_map"
79
+ echo 'New map:'
80
+ echo "$new_map"
81
+fi
82
+
83
+_cleanup_test_img
84
+
85
+
86
+echo
87
+echo '=== Writing to a snapshotted preallocated zero cluster ==='
88
+echo
89
+
90
+_make_test_img 64k
91
+
92
+# Create a preallocated zero cluster
93
+$QEMU_IO -c 'write -P 42 0 64k' -c 'write -z 0 64k' "$TEST_IMG" \
94
+ | _filter_qemu_io
95
+
96
+# Snapshot it
97
+$QEMU_IMG snapshot -c foo "$TEST_IMG"
98
+
99
+# Write to the cluster
100
+$QEMU_IO -c 'write -P 23 0 64k' "$TEST_IMG" | _filter_qemu_io
101
+
102
+# Check metadata correctness
103
+_check_test_img
104
+
105
+# Check data correctness
106
+$QEMU_IO -c 'read -P 23 0 64k' "$TEST_IMG" | _filter_qemu_io
107
+$QEMU_IMG snapshot -a foo "$TEST_IMG"
108
+$QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io
109
+
110
+_cleanup_test_img
111
+
112
+
113
+echo
114
+echo '=== Consecutive write to a preallocated zero cluster ==='
115
+echo
116
+
117
+_make_test_img 192k
118
+
119
+# Create three normal clusters
120
+$QEMU_IO -c 'write -P 42 0 192k' "$TEST_IMG" | _filter_qemu_io
121
+orig_map=$($QEMU_IMG map --output=json "$TEST_IMG")
122
+
123
+# Make the middle cluster a preallocated zero cluster
124
+$QEMU_IO -c 'write -z 64k 64k' "$TEST_IMG" | _filter_qemu_io
125
+
126
+# Try to overwrite everything: This should reuse the whole range. To test that
127
+# this only issues a single continuous write request, use blkdebug.
128
+$QEMU_IO -c 'write -P 42 0 192k' \
129
+ "json:{
130
+ 'driver': '$IMGFMT',
131
+ 'file': {
132
+ 'driver': 'blkdebug',
133
+ 'image.filename': '$TEST_IMG',
134
+ 'set-state': [{
135
+ 'event': 'write_aio',
136
+ 'new_state': 2
137
+ }],
138
+ 'inject-error': [{
139
+ 'event': 'write_aio',
140
+ 'state': 2
141
+ }]
142
+ }
143
+ }" \
144
+ | _filter_qemu_io
145
+
146
+# Check metadata correctness
147
+_check_test_img
148
+
149
+# Check that we have actually reused the original area
150
+new_map=$($QEMU_IMG map --output=json "$TEST_IMG")
151
+if [ "$new_map" = "$orig_map" ]; then
152
+ echo 'Successfully reused original clusters.'
153
+else
154
+ echo 'Failed to reuse original clusters.'
155
+ echo 'Original map:'
156
+ echo "$orig_map"
157
+ echo 'New map:'
158
+ echo "$new_map"
159
+fi
160
+
161
+_cleanup_test_img
162
+
163
164
# success, all done
165
echo "*** done"
166
diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out
167
index XXXXXXX..XXXXXXX 100644
168
--- a/tests/qemu-iotests/066.out
169
+++ b/tests/qemu-iotests/066.out
170
@@ -XXX,XX +XXX,XX @@ discard 67109376/67109376 bytes at offset 0
171
read 67109376/67109376 bytes at offset 0
172
64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
173
No errors were found on the image.
174
+Offset Length Mapped to File
175
+
176
+=== Writing to preallocated zero clusters ===
177
+
178
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376
179
+wrote 262144/262144 bytes at offset 1048576
180
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
181
+wrote 262144/262144 bytes at offset 1048576
182
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
183
+wrote 196608/196608 bytes at offset 1081344
184
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+No errors were found on the image.
186
+read 32768/32768 bytes at offset 1048576
187
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
188
+read 196608/196608 bytes at offset 1081344
189
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
190
+read 32768/32768 bytes at offset 1277952
191
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
192
+Successfully reused original clusters.
193
+
194
+=== Writing to a snapshotted preallocated zero cluster ===
195
+
196
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
197
+wrote 65536/65536 bytes at offset 0
198
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+wrote 65536/65536 bytes at offset 0
200
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
201
+wrote 65536/65536 bytes at offset 0
202
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+No errors were found on the image.
204
+read 65536/65536 bytes at offset 0
205
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
206
+read 65536/65536 bytes at offset 0
207
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
208
+
209
+=== Consecutive write to a preallocated zero cluster ===
210
+
211
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=196608
212
+wrote 196608/196608 bytes at offset 0
213
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
214
+wrote 65536/65536 bytes at offset 65536
215
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
216
+wrote 196608/196608 bytes at offset 0
217
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
218
+No errors were found on the image.
219
+Successfully reused original clusters.
220
*** done
221
--
40
--
222
1.8.3.1
41
2.13.6
223
42
224
43
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Fam Zheng <famz@redhat.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
5
---
6
util/osdep.c | 20 ++++++++++----------
6
include/block/block_int.h | 1 -
7
1 file changed, 10 insertions(+), 10 deletions(-)
7
block/io.c | 18 ------------------
8
2 files changed, 19 deletions(-)
8
9
9
diff --git a/util/osdep.c b/util/osdep.c
10
diff --git a/include/block/block_int.h b/include/block/block_int.h
10
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
11
--- a/util/osdep.c
12
--- a/include/block/block_int.h
12
+++ b/util/osdep.c
13
+++ b/include/block/block_int.h
13
@@ -XXX,XX +XXX,XX @@ extern int madvise(caddr_t, size_t, int);
14
@@ -XXX,XX +XXX,XX @@ bool blk_dev_is_tray_open(BlockBackend *blk);
14
#include "qemu/error-report.h"
15
bool blk_dev_is_medium_locked(BlockBackend *blk);
15
#include "monitor/monitor.h"
16
16
17
void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes);
17
+#ifdef F_OFD_SETLK
18
-bool bdrv_requests_pending(BlockDriverState *bs);
18
+#define QEMU_SETLK F_OFD_SETLK
19
19
+#define QEMU_GETLK F_OFD_GETLK
20
void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out);
20
+#else
21
void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in);
21
+#define QEMU_SETLK F_SETLK
22
diff --git a/block/io.c b/block/io.c
22
+#define QEMU_GETLK F_GETLK
23
index XXXXXXX..XXXXXXX 100644
23
+#endif
24
--- a/block/io.c
24
+
25
+++ b/block/io.c
25
static bool fips_enabled = false;
26
@@ -XXX,XX +XXX,XX @@ void bdrv_disable_copy_on_read(BlockDriverState *bs)
26
27
assert(old >= 1);
27
static const char *hw_version = QEMU_HW_VERSION;
28
@@ -XXX,XX +XXX,XX @@ static int qemu_parse_fdset(const char *param)
29
30
static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
31
{
32
-#ifdef F_OFD_SETLK
33
int ret;
34
struct flock fl = {
35
.l_whence = SEEK_SET,
36
@@ -XXX,XX +XXX,XX @@ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
37
.l_len = len,
38
.l_type = fl_type,
39
};
40
- ret = fcntl(fd, F_OFD_SETLK, &fl);
41
+ ret = fcntl(fd, QEMU_SETLK, &fl);
42
return ret == -1 ? -errno : 0;
43
-#else
44
- return -ENOTSUP;
45
-#endif
46
}
28
}
47
29
48
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
30
-/* Check if any requests are in-flight (including throttled requests) */
49
@@ -XXX,XX +XXX,XX @@ int qemu_unlock_fd(int fd, int64_t start, int64_t len)
31
-bool bdrv_requests_pending(BlockDriverState *bs)
50
32
-{
51
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
33
- BdrvChild *child;
52
{
34
-
53
-#ifdef F_OFD_SETLK
35
- if (atomic_read(&bs->in_flight)) {
54
int ret;
36
- return true;
55
struct flock fl = {
37
- }
56
.l_whence = SEEK_SET,
38
-
57
@@ -XXX,XX +XXX,XX @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
39
- QLIST_FOREACH(child, &bs->children, next) {
58
.l_len = len,
40
- if (bdrv_requests_pending(child->bs)) {
59
.l_type = exclusive ? F_WRLCK : F_RDLCK,
41
- return true;
60
};
42
- }
61
- ret = fcntl(fd, F_OFD_GETLK, &fl);
43
- }
62
+ ret = fcntl(fd, QEMU_GETLK, &fl);
44
-
63
if (ret == -1) {
45
- return false;
64
return -errno;
46
-}
65
} else {
47
-
66
return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
48
typedef struct {
67
}
49
Coroutine *co;
68
-#else
50
BlockDriverState *bs;
69
- return -ENOTSUP;
70
-#endif
71
}
72
#endif
73
74
--
51
--
75
1.8.3.1
52
2.13.6
76
53
77
54
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
Reviewed-by: Fam Zheng <famz@redhat.com>
3
---
4
block/io.c | 6 ++++++
5
1 file changed, 6 insertions(+)
2
6
3
We already audited (in commit 0c1bd469) that qcow2_discard_clusters()
7
diff --git a/block/io.c b/block/io.c
4
is only passed cluster-aligned start values; but we can further
5
tighten the assertion that the only unaligned end value is at EOF.
6
7
Recent commits have taken advantage of an unaligned tail cluster,
8
for both discard and write zeroes.
9
10
Signed-off-by: Eric Blake <eblake@redhat.com>
11
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Message-id: 20170507000552.20847-12-eblake@redhat.com
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
15
block/qcow2-cluster.c | 15 +++++++++++----
16
1 file changed, 11 insertions(+), 4 deletions(-)
17
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
19
index XXXXXXX..XXXXXXX 100644
8
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2-cluster.c
9
--- a/block/io.c
21
+++ b/block/qcow2-cluster.c
10
+++ b/block/io.c
22
@@ -XXX,XX +XXX,XX @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
11
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
23
12
BdrvNextIterator it;
24
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
13
GSList *aio_ctxs = NULL, *ctx;
25
14
26
- /* The caller must cluster-align start; round end down except at EOF */
15
+ /* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread
27
+ /* Caller must pass aligned values, except at image end */
16
+ * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on
28
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
17
+ * nodes in several different AioContexts, so make sure we're in the main
29
- if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
18
+ * context. */
30
- end_offset = start_of_cluster(s, end_offset);
19
+ assert(qemu_get_current_aio_context() == qemu_get_aio_context());
31
- }
32
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
33
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
34
35
nb_clusters = size_to_clusters(s, end_offset - offset);
36
37
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
38
int flags)
39
{
40
BDRVQcow2State *s = bs->opaque;
41
+ uint64_t end_offset;
42
uint64_t nb_clusters;
43
int ret;
44
45
+ end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
46
+
20
+
47
+ /* Caller must pass aligned values, except at image end */
21
block_job_pause_all();
48
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
22
49
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
23
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
50
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
51
+
52
/* The zero flag is only supported by version 3 and newer */
53
if (s->qcow_version < 3) {
54
return -ENOTSUP;
55
--
24
--
56
1.8.3.1
25
2.13.6
57
26
58
27
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
bdrv_drained_begin() doesn't increase bs->quiesce_counter recursively
2
and also doesn't notify other parent nodes of children, which both means
3
that the child nodes are not actually drained, and bdrv_drained_begin()
4
is providing useful functionality only on a single node.
2
5
3
Passing a byte offset, but sector count, when we ultimately
6
To keep things consistent, we also shouldn't call the block driver
4
want to operate on cluster granularity, is madness. Clean up
7
callbacks recursively.
5
the external interfaces to take both offset and count as bytes,
6
while still keeping the assertion added previously that the
7
caller must align the values to a cluster. Then rename things
8
to make sure backports don't get confused by changed units:
9
instead of qcow2_discard_clusters() and qcow2_zero_clusters(),
10
we now have qcow2_cluster_discard() and qcow2_cluster_zeroize().
11
8
12
The internal functions still operate on clusters at a time, and
9
A proper recursive drain version that provides an actually working
13
return an int for number of cleared clusters; but on an image
10
drained section for child nodes will be introduced later.
14
with 2M clusters, a single L2 table holds 256k entries that each
15
represent a 2M cluster, totalling well over INT_MAX bytes if we
16
ever had a request for that many bytes at once. All our callers
17
currently limit themselves to 32-bit bytes (and therefore fewer
18
clusters), but by making this function 64-bit clean, we have one
19
less place to clean up if we later improve the block layer to
20
support 64-bit bytes through all operations (with the block layer
21
auto-fragmenting on behalf of more-limited drivers), rather than
22
the current state where some interfaces are artificially limited
23
to INT_MAX at a time.
24
11
25
Signed-off-by: Eric Blake <eblake@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Reviewed-by: Fam Zheng <famz@redhat.com>
27
Message-id: 20170507000552.20847-13-eblake@redhat.com
28
Signed-off-by: Max Reitz <mreitz@redhat.com>
29
---
14
---
30
block/qcow2-cluster.c | 42 ++++++++++++++++++++++--------------------
15
block/io.c | 16 +++++++++-------
31
block/qcow2-snapshot.c | 7 +++----
16
1 file changed, 9 insertions(+), 7 deletions(-)
32
block/qcow2.c | 22 +++++++++-------------
33
block/qcow2.h | 9 +++++----
34
4 files changed, 39 insertions(+), 41 deletions(-)
35
17
36
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
18
diff --git a/block/io.c b/block/io.c
37
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
38
--- a/block/qcow2-cluster.c
20
--- a/block/io.c
39
+++ b/block/qcow2-cluster.c
21
+++ b/block/io.c
40
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
22
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
41
return nb_clusters;
42
}
23
}
43
24
44
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
25
/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */
45
- int nb_sectors, enum qcow2_discard_type type, bool full_discard)
26
-static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
46
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
27
+static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, bool recursive)
47
+ uint64_t bytes, enum qcow2_discard_type type,
48
+ bool full_discard)
49
{
28
{
50
BDRVQcow2State *s = bs->opaque;
29
BdrvChild *child, *tmp;
51
- uint64_t end_offset;
30
BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin};
52
+ uint64_t end_offset = offset + bytes;
31
@@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
53
uint64_t nb_clusters;
32
bdrv_coroutine_enter(bs, data.co);
54
+ int64_t cleared;
33
BDRV_POLL_WHILE(bs, !data.done);
55
int ret;
34
56
35
- QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) {
57
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
36
- bdrv_drain_invoke(child->bs, begin);
58
-
37
+ if (recursive) {
59
/* Caller must pass aligned values, except at image end */
38
+ QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) {
60
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
39
+ bdrv_drain_invoke(child->bs, begin, true);
61
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
40
+ }
62
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
63
64
- nb_clusters = size_to_clusters(s, end_offset - offset);
65
+ nb_clusters = size_to_clusters(s, bytes);
66
67
s->cache_discards = true;
68
69
/* Each L2 table is handled by its own loop iteration */
70
while (nb_clusters > 0) {
71
- ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);
72
- if (ret < 0) {
73
+ cleared = discard_single_l2(bs, offset, nb_clusters, type,
74
+ full_discard);
75
+ if (cleared < 0) {
76
+ ret = cleared;
77
goto fail;
78
}
79
80
- nb_clusters -= ret;
81
- offset += (ret * s->cluster_size);
82
+ nb_clusters -= cleared;
83
+ offset += (cleared * s->cluster_size);
84
}
41
}
85
86
ret = 0;
87
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
88
return nb_clusters;
89
}
42
}
90
43
91
-int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
44
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs)
92
- int flags)
45
bdrv_parent_drained_begin(bs);
93
+int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
94
+ uint64_t bytes, int flags)
95
{
96
BDRVQcow2State *s = bs->opaque;
97
- uint64_t end_offset;
98
+ uint64_t end_offset = offset + bytes;
99
uint64_t nb_clusters;
100
+ int64_t cleared;
101
int ret;
102
103
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
104
-
105
/* Caller must pass aligned values, except at image end */
106
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
107
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
108
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
109
}
46
}
110
47
111
/* Each L2 table is handled by its own loop iteration */
48
- bdrv_drain_invoke(bs, true);
112
- nb_clusters = size_to_clusters(s, nb_sectors << BDRV_SECTOR_BITS);
49
+ bdrv_drain_invoke(bs, true, false);
113
+ nb_clusters = size_to_clusters(s, bytes);
50
bdrv_drain_recurse(bs);
114
51
}
115
s->cache_discards = true;
52
116
53
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
117
while (nb_clusters > 0) {
118
- ret = zero_single_l2(bs, offset, nb_clusters, flags);
119
- if (ret < 0) {
120
+ cleared = zero_single_l2(bs, offset, nb_clusters, flags);
121
+ if (cleared < 0) {
122
+ ret = cleared;
123
goto fail;
124
}
125
126
- nb_clusters -= ret;
127
- offset += (ret * s->cluster_size);
128
+ nb_clusters -= cleared;
129
+ offset += (cleared * s->cluster_size);
130
}
54
}
131
55
132
ret = 0;
56
/* Re-enable things in child-to-parent order */
133
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
57
- bdrv_drain_invoke(bs, false);
134
index XXXXXXX..XXXXXXX 100644
58
+ bdrv_drain_invoke(bs, false, false);
135
--- a/block/qcow2-snapshot.c
59
bdrv_parent_drained_end(bs);
136
+++ b/block/qcow2-snapshot.c
60
aio_enable_external(bdrv_get_aio_context(bs));
137
@@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
138
139
/* The VM state isn't needed any more in the active L1 table; in fact, it
140
* hurts by causing expensive COW for the next snapshot. */
141
- qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),
142
- align_offset(sn->vm_state_size, s->cluster_size)
143
- >> BDRV_SECTOR_BITS,
144
- QCOW2_DISCARD_NEVER, false);
145
+ qcow2_cluster_discard(bs, qcow2_vm_state_offset(s),
146
+ align_offset(sn->vm_state_size, s->cluster_size),
147
+ QCOW2_DISCARD_NEVER, false);
148
149
#ifdef DEBUG_ALLOC
150
{
151
diff --git a/block/qcow2.c b/block/qcow2.c
152
index XXXXXXX..XXXXXXX 100644
153
--- a/block/qcow2.c
154
+++ b/block/qcow2.c
155
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
156
trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count);
157
158
/* Whatever is left can use real zero clusters */
159
- ret = qcow2_zero_clusters(bs, offset, count >> BDRV_SECTOR_BITS, flags);
160
+ ret = qcow2_cluster_zeroize(bs, offset, count, flags);
161
qemu_co_mutex_unlock(&s->lock);
162
163
return ret;
164
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
165
}
166
167
qemu_co_mutex_lock(&s->lock);
168
- ret = qcow2_discard_clusters(bs, offset, count >> BDRV_SECTOR_BITS,
169
- QCOW2_DISCARD_REQUEST, false);
170
+ ret = qcow2_cluster_discard(bs, offset, count, QCOW2_DISCARD_REQUEST,
171
+ false);
172
qemu_co_mutex_unlock(&s->lock);
173
return ret;
174
}
61
}
175
@@ -XXX,XX +XXX,XX @@ fail:
62
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
176
static int qcow2_make_empty(BlockDriverState *bs)
63
aio_context_acquire(aio_context);
177
{
64
aio_disable_external(aio_context);
178
BDRVQcow2State *s = bs->opaque;
65
bdrv_parent_drained_begin(bs);
179
- uint64_t start_sector;
66
- bdrv_drain_invoke(bs, true);
180
- int sector_step = (QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size) /
67
+ bdrv_drain_invoke(bs, true, true);
181
- BDRV_SECTOR_SIZE);
68
aio_context_release(aio_context);
182
+ uint64_t offset, end_offset;
69
183
+ int step = QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size);
70
if (!g_slist_find(aio_ctxs, aio_context)) {
184
int l1_clusters, ret = 0;
71
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
185
72
186
l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
73
/* Re-enable things in child-to-parent order */
187
@@ -XXX,XX +XXX,XX @@ static int qcow2_make_empty(BlockDriverState *bs)
74
aio_context_acquire(aio_context);
188
75
- bdrv_drain_invoke(bs, false);
189
/* This fallback code simply discards every active cluster; this is slow,
76
+ bdrv_drain_invoke(bs, false, true);
190
* but works in all cases */
77
bdrv_parent_drained_end(bs);
191
- for (start_sector = 0; start_sector < bs->total_sectors;
78
aio_enable_external(aio_context);
192
- start_sector += sector_step)
79
aio_context_release(aio_context);
193
- {
194
+ end_offset = bs->total_sectors * BDRV_SECTOR_SIZE;
195
+ for (offset = 0; offset < end_offset; offset += step) {
196
/* As this function is generally used after committing an external
197
* snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
198
* default action for this kind of discard is to pass the discard,
199
* which will ideally result in an actually smaller image file, as
200
* is probably desired. */
201
- ret = qcow2_discard_clusters(bs, start_sector * BDRV_SECTOR_SIZE,
202
- MIN(sector_step,
203
- bs->total_sectors - start_sector),
204
- QCOW2_DISCARD_SNAPSHOT, true);
205
+ ret = qcow2_cluster_discard(bs, offset, MIN(step, end_offset - offset),
206
+ QCOW2_DISCARD_SNAPSHOT, true);
207
if (ret < 0) {
208
break;
209
}
210
diff --git a/block/qcow2.h b/block/qcow2.h
211
index XXXXXXX..XXXXXXX 100644
212
--- a/block/qcow2.h
213
+++ b/block/qcow2.h
214
@@ -XXX,XX +XXX,XX @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
215
int compressed_size);
216
217
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
218
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
219
- int nb_sectors, enum qcow2_discard_type type, bool full_discard);
220
-int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
221
- int flags);
222
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
223
+ uint64_t bytes, enum qcow2_discard_type type,
224
+ bool full_discard);
225
+int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
226
+ uint64_t bytes, int flags);
227
228
int qcow2_expand_zero_clusters(BlockDriverState *bs,
229
BlockDriverAmendStatusCB *status_cb,
230
--
80
--
231
1.8.3.1
81
2.13.6
232
82
233
83
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
The existing test is for bdrv_drain_all_begin/end() only. Generalise the
2
test case so that it can be run for the other variants as well. At the
3
moment this is only bdrv_drain_begin/end(), but in a while, we'll add
4
another one.
2
5
3
In the case where we test the expected error when a blockdev-snapshot
6
Also, add a backing file to the test node to test whether the operations
4
target already has a backing image, the backing chain is opened multiple
7
work recursively.
5
times. This will be a problem when we use image locking, so use a
6
different backing file that is not already open.
7
8
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
10
---
11
tests/qemu-iotests/085 | 33 +++++++++++++++++++--------------
11
tests/test-bdrv-drain.c | 69 ++++++++++++++++++++++++++++++++++++++++++++-----
12
tests/qemu-iotests/085.out | 3 ++-
12
1 file changed, 62 insertions(+), 7 deletions(-)
13
2 files changed, 21 insertions(+), 15 deletions(-)
14
13
15
diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085
14
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
16
index XXXXXXX..XXXXXXX 100755
15
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/qemu-iotests/085
16
--- a/tests/test-bdrv-drain.c
18
+++ b/tests/qemu-iotests/085
17
+++ b/tests/test-bdrv-drain.c
19
@@ -XXX,XX +XXX,XX @@ _cleanup()
18
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test = {
20
rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
19
21
rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
20
.bdrv_co_drain_begin = bdrv_test_co_drain_begin,
22
done
21
.bdrv_co_drain_end = bdrv_test_co_drain_end,
23
- rm -f "${TEST_IMG}.1" "${TEST_IMG}.2"
22
+
24
+ rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base"
23
+ .bdrv_child_perm = bdrv_format_default_perms,
25
24
};
25
26
static void aio_ret_cb(void *opaque, int ret)
27
@@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret)
28
*aio_ret = ret;
26
}
29
}
27
trap "_cleanup; exit \$status" 0 1 2 3 15
30
28
@@ -XXX,XX +XXX,XX @@ function create_group_snapshot()
31
-static void test_drv_cb_drain_all(void)
29
}
32
+enum drain_type {
30
33
+ BDRV_DRAIN_ALL,
31
# ${1}: unique identifier for the snapshot filename
34
+ BDRV_DRAIN,
32
-# ${2}: true: open backing images; false: don't open them (default)
35
+};
33
+# ${2}: extra_params to the blockdev-add command
36
+
34
+# ${3}: filename
37
+static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs)
35
+function do_blockdev_add()
36
+{
38
+{
37
+ cmd="{ 'execute': 'blockdev-add', 'arguments':
39
+ switch (drain_type) {
38
+ { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
40
+ case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break;
39
+ 'file':
41
+ case BDRV_DRAIN: bdrv_drained_begin(bs); break;
40
+ { 'driver': 'file', 'filename': '${3}',
42
+ default: g_assert_not_reached();
41
+ 'node-name': 'file_${1}' } } }"
43
+ }
42
+ _send_qemu_cmd $h "${cmd}" "return"
43
+}
44
+}
44
+
45
+
45
+# ${1}: unique identifier for the snapshot filename
46
+static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs)
46
function add_snapshot_image()
47
+{
48
+ switch (drain_type) {
49
+ case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break;
50
+ case BDRV_DRAIN: bdrv_drained_end(bs); break;
51
+ default: g_assert_not_reached();
52
+ }
53
+}
54
+
55
+static void test_drv_cb_common(enum drain_type drain_type, bool recursive)
47
{
56
{
48
- if [ "${2}" = "true" ]; then
57
BlockBackend *blk;
49
- extra_params=""
58
- BlockDriverState *bs;
50
- else
59
- BDRVTestState *s;
51
- extra_params="'backing': '', "
60
+ BlockDriverState *bs, *backing;
52
- fi
61
+ BDRVTestState *s, *backing_s;
53
base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
62
BlockAIOCB *acb;
54
snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
63
int aio_ret;
55
_make_test_img -b "${base_image}" "$size"
64
56
mv "${TEST_IMG}" "${snapshot_file}"
65
@@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_all(void)
57
- cmd="{ 'execute': 'blockdev-add', 'arguments':
66
s = bs->opaque;
58
- { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${extra_params}
67
blk_insert_bs(blk, bs, &error_abort);
59
- 'file':
68
60
- { 'driver': 'file', 'filename': '${snapshot_file}',
69
+ backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
61
- 'node-name': 'file_${1}' } } }"
70
+ backing_s = backing->opaque;
62
- _send_qemu_cmd $h "${cmd}" "return"
71
+ bdrv_set_backing_hd(bs, backing, &error_abort);
63
+ do_blockdev_add "$1" "'backing': '', " "${snapshot_file}"
72
+
73
/* Simple bdrv_drain_all_begin/end pair, check that CBs are called */
74
g_assert_cmpint(s->drain_count, ==, 0);
75
- bdrv_drain_all_begin();
76
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
77
+
78
+ do_drain_begin(drain_type, bs);
79
+
80
g_assert_cmpint(s->drain_count, ==, 1);
81
- bdrv_drain_all_end();
82
+ g_assert_cmpint(backing_s->drain_count, ==, !!recursive);
83
+
84
+ do_drain_end(drain_type, bs);
85
+
86
g_assert_cmpint(s->drain_count, ==, 0);
87
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
88
89
/* Now do the same while a request is pending */
90
aio_ret = -EINPROGRESS;
91
@@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_all(void)
92
g_assert_cmpint(aio_ret, ==, -EINPROGRESS);
93
94
g_assert_cmpint(s->drain_count, ==, 0);
95
- bdrv_drain_all_begin();
96
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
97
+
98
+ do_drain_begin(drain_type, bs);
99
+
100
g_assert_cmpint(aio_ret, ==, 0);
101
g_assert_cmpint(s->drain_count, ==, 1);
102
- bdrv_drain_all_end();
103
+ g_assert_cmpint(backing_s->drain_count, ==, !!recursive);
104
+
105
+ do_drain_end(drain_type, bs);
106
+
107
g_assert_cmpint(s->drain_count, ==, 0);
108
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
109
110
+ bdrv_unref(backing);
111
bdrv_unref(bs);
112
blk_unref(blk);
64
}
113
}
65
114
66
# ${1}: unique identifier for the snapshot filename
115
+static void test_drv_cb_drain_all(void)
67
@@ -XXX,XX +XXX,XX @@ echo === Invalid command - snapshot node has a backing image ===
116
+{
68
echo
117
+ test_drv_cb_common(BDRV_DRAIN_ALL, true);
69
118
+}
70
SNAPSHOTS=$((${SNAPSHOTS}+1))
71
-add_snapshot_image ${SNAPSHOTS} true
72
+
119
+
73
+TEST_IMG="$TEST_IMG.base" _make_test_img "$size"
120
+static void test_drv_cb_drain(void)
74
+_make_test_img -b "${TEST_IMG}.base" "$size"
121
+{
75
+do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}"
122
+ test_drv_cb_common(BDRV_DRAIN, false);
76
blockdev_snapshot ${SNAPSHOTS} error
123
+}
77
124
+
78
echo
125
int main(int argc, char **argv)
79
diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out
126
{
80
index XXXXXXX..XXXXXXX 100644
127
bdrv_init();
81
--- a/tests/qemu-iotests/085.out
128
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
82
+++ b/tests/qemu-iotests/085.out
129
g_test_init(&argc, &argv, NULL);
83
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/
130
84
131
g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all);
85
=== Invalid command - snapshot node has a backing image ===
132
+ g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain);
86
133
87
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/12-snapshot-v0.IMGFMT
134
return g_test_run();
88
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
135
}
89
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
90
{"return": {}}
91
{"error": {"class": "GenericError", "desc": "The snapshot already has a backing image"}}
92
93
--
136
--
94
1.8.3.1
137
2.13.6
95
138
96
139
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
This is currently only working correctly for bdrv_drain(), not for
2
bdrv_drain_all(). Leave a comment for the drain_all case, we'll address
3
it later.
2
4
3
They are wrappers of POSIX fcntl "file private locking", with a
4
convenient "try lock" wrapper implemented with F_OFD_GETLK.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
6
---
10
include/qemu/osdep.h | 3 +++
7
tests/test-bdrv-drain.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
11
util/osdep.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
8
1 file changed, 45 insertions(+)
12
2 files changed, 51 insertions(+)
13
9
14
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
10
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
15
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
16
--- a/include/qemu/osdep.h
12
--- a/tests/test-bdrv-drain.c
17
+++ b/include/qemu/osdep.h
13
+++ b/tests/test-bdrv-drain.c
18
@@ -XXX,XX +XXX,XX @@ int qemu_close(int fd);
14
@@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void)
19
#ifndef _WIN32
15
test_drv_cb_common(BDRV_DRAIN, false);
20
int qemu_dup(int fd);
21
#endif
22
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
23
+int qemu_unlock_fd(int fd, int64_t start, int64_t len);
24
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
25
26
#if defined(__HAIKU__) && defined(__i386__)
27
#define FMT_pid "%ld"
28
diff --git a/util/osdep.c b/util/osdep.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/util/osdep.c
31
+++ b/util/osdep.c
32
@@ -XXX,XX +XXX,XX @@ static int qemu_parse_fdset(const char *param)
33
{
34
return qemu_parse_fd(param);
35
}
16
}
17
18
+static void test_quiesce_common(enum drain_type drain_type, bool recursive)
19
+{
20
+ BlockBackend *blk;
21
+ BlockDriverState *bs, *backing;
36
+
22
+
37
+static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
23
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
38
+{
24
+ bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
39
+#ifdef F_OFD_SETLK
25
+ &error_abort);
40
+ int ret;
26
+ blk_insert_bs(blk, bs, &error_abort);
41
+ struct flock fl = {
27
+
42
+ .l_whence = SEEK_SET,
28
+ backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
43
+ .l_start = start,
29
+ bdrv_set_backing_hd(bs, backing, &error_abort);
44
+ .l_len = len,
30
+
45
+ .l_type = fl_type,
31
+ g_assert_cmpint(bs->quiesce_counter, ==, 0);
46
+ };
32
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
47
+ ret = fcntl(fd, F_OFD_SETLK, &fl);
33
+
48
+ return ret == -1 ? -errno : 0;
34
+ do_drain_begin(drain_type, bs);
49
+#else
35
+
50
+ return -ENOTSUP;
36
+ g_assert_cmpint(bs->quiesce_counter, ==, 1);
51
+#endif
37
+ g_assert_cmpint(backing->quiesce_counter, ==, !!recursive);
38
+
39
+ do_drain_end(drain_type, bs);
40
+
41
+ g_assert_cmpint(bs->quiesce_counter, ==, 0);
42
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
43
+
44
+ bdrv_unref(backing);
45
+ bdrv_unref(bs);
46
+ blk_unref(blk);
52
+}
47
+}
53
+
48
+
54
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
49
+static void test_quiesce_drain_all(void)
55
+{
50
+{
56
+ return qemu_lock_fcntl(fd, start, len, exclusive ? F_WRLCK : F_RDLCK);
51
+ // XXX drain_all doesn't quiesce
52
+ //test_quiesce_common(BDRV_DRAIN_ALL, true);
57
+}
53
+}
58
+
54
+
59
+int qemu_unlock_fd(int fd, int64_t start, int64_t len)
55
+static void test_quiesce_drain(void)
60
+{
56
+{
61
+ return qemu_lock_fcntl(fd, start, len, F_UNLCK);
57
+ test_quiesce_common(BDRV_DRAIN, false);
62
+}
58
+}
63
+
59
+
64
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
60
int main(int argc, char **argv)
65
+{
61
{
66
+#ifdef F_OFD_SETLK
62
bdrv_init();
67
+ int ret;
63
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
68
+ struct flock fl = {
64
g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all);
69
+ .l_whence = SEEK_SET,
65
g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain);
70
+ .l_start = start,
66
71
+ .l_len = len,
67
+ g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all);
72
+ .l_type = exclusive ? F_WRLCK : F_RDLCK,
68
+ g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain);
73
+ };
69
+
74
+ ret = fcntl(fd, F_OFD_GETLK, &fl);
70
return g_test_run();
75
+ if (ret == -1) {
71
}
76
+ return -errno;
77
+ } else {
78
+ return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
79
+ }
80
+#else
81
+ return -ENOTSUP;
82
+#endif
83
+}
84
#endif
85
86
/*
87
--
72
--
88
1.8.3.1
73
2.13.6
89
74
90
75
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
Block jobs already paused themselves when their main BlockBackend
2
entered a drained section. This is not good enough: We also want to
3
pause a block job and may not submit new requests if, for example, the
4
mirror target node should be drained.
2
5
3
For the 'alloc' command, accepting an offset in bytes but a length
6
This implements .drained_begin/end callbacks in child_job in order to
4
in sectors, and reporting output in sectors, is confusing. Do
7
consider all block nodes related to the job, and removes the
5
everything in bytes, and adjust the expected output accordingly.
8
BlockBackend callbacks which are unnecessary now because the root of the
9
job main BlockBackend is always referenced with a child_job, too.
6
10
7
Signed-off-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Message-id: 20170429191419.30051-3-eblake@redhat.com
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
---
12
qemu-io-cmds.c | 30 ++++++++++++++++++------------
13
blockjob.c | 22 +++++++++-------------
13
tests/qemu-iotests/019.out | 8 ++++----
14
1 file changed, 9 insertions(+), 13 deletions(-)
14
tests/qemu-iotests/common.pattern | 2 +-
15
3 files changed, 23 insertions(+), 17 deletions(-)
16
15
17
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
16
diff --git a/blockjob.c b/blockjob.c
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-io-cmds.c
18
--- a/blockjob.c
20
+++ b/qemu-io-cmds.c
19
+++ b/blockjob.c
21
@@ -XXX,XX +XXX,XX @@ out:
20
@@ -XXX,XX +XXX,XX @@ static char *child_job_get_parent_desc(BdrvChild *c)
22
static int alloc_f(BlockBackend *blk, int argc, char **argv)
21
job->id);
22
}
23
24
-static const BdrvChildRole child_job = {
25
- .get_parent_desc = child_job_get_parent_desc,
26
- .stay_at_node = true,
27
-};
28
-
29
-static void block_job_drained_begin(void *opaque)
30
+static void child_job_drained_begin(BdrvChild *c)
23
{
31
{
24
BlockDriverState *bs = blk_bs(blk);
32
- BlockJob *job = opaque;
25
- int64_t offset, sector_num, nb_sectors, remaining;
33
+ BlockJob *job = c->opaque;
26
+ int64_t offset, sector_num, nb_sectors, remaining, count;
34
block_job_pause(job);
27
char s1[64];
28
int num, ret;
29
int64_t sum_alloc;
30
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
31
}
32
33
if (argc == 3) {
34
- nb_sectors = cvtnum(argv[2]);
35
- if (nb_sectors < 0) {
36
- print_cvtnum_err(nb_sectors, argv[2]);
37
+ count = cvtnum(argv[2]);
38
+ if (count < 0) {
39
+ print_cvtnum_err(count, argv[2]);
40
return 0;
41
- } else if (nb_sectors > INT_MAX) {
42
- printf("length argument cannot exceed %d, given %s\n",
43
- INT_MAX, argv[2]);
44
+ } else if (count > INT_MAX * BDRV_SECTOR_SIZE) {
45
+ printf("length argument cannot exceed %llu, given %s\n",
46
+ INT_MAX * BDRV_SECTOR_SIZE, argv[2]);
47
return 0;
48
}
49
} else {
50
- nb_sectors = 1;
51
+ count = BDRV_SECTOR_SIZE;
52
+ }
53
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
54
+ printf("%" PRId64 " is not a sector-aligned value for 'count'\n",
55
+ count);
56
+ return 0;
57
}
58
+ nb_sectors = count >> BDRV_SECTOR_BITS;
59
60
remaining = nb_sectors;
61
sum_alloc = 0;
62
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
63
64
cvtstr(offset, s1, sizeof(s1));
65
66
- printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n",
67
- sum_alloc, nb_sectors, s1);
68
+ printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n",
69
+ sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, s1);
70
return 0;
71
}
35
}
72
36
73
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t alloc_cmd = {
37
-static void block_job_drained_end(void *opaque)
74
.argmin = 1,
38
+static void child_job_drained_end(BdrvChild *c)
75
.argmax = 2,
39
{
76
.cfunc = alloc_f,
40
- BlockJob *job = opaque;
77
- .args = "off [sectors]",
41
+ BlockJob *job = c->opaque;
78
- .oneline = "checks if a sector is present in the file",
42
block_job_resume(job);
79
+ .args = "offset [count]",
43
}
80
+ .oneline = "checks if offset is allocated in the file",
44
45
-static const BlockDevOps block_job_dev_ops = {
46
- .drained_begin = block_job_drained_begin,
47
- .drained_end = block_job_drained_end,
48
+static const BdrvChildRole child_job = {
49
+ .get_parent_desc = child_job_get_parent_desc,
50
+ .drained_begin = child_job_drained_begin,
51
+ .drained_end = child_job_drained_end,
52
+ .stay_at_node = true,
81
};
53
};
82
54
83
55
void block_job_remove_all_bdrv(BlockJob *job)
84
diff --git a/tests/qemu-iotests/019.out b/tests/qemu-iotests/019.out
56
@@ -XXX,XX +XXX,XX @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
85
index XXXXXXX..XXXXXXX 100644
57
block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
86
--- a/tests/qemu-iotests/019.out
58
bs->job = job;
87
+++ b/tests/qemu-iotests/019.out
59
88
@@ -XXX,XX +XXX,XX @@ Testing conversion with -B TEST_DIR/t.IMGFMT.base
60
- blk_set_dev_ops(blk, &block_job_dev_ops, job);
89
61
bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker);
90
Checking if backing clusters are allocated when they shouldn't
62
91
63
QLIST_INSERT_HEAD(&block_jobs, job, job_list);
92
-0/128 sectors allocated at offset 1 MiB
93
-0/128 sectors allocated at offset 4.001 GiB
94
+0/65536 bytes allocated at offset 1 MiB
95
+0/65536 bytes allocated at offset 4.001 GiB
96
Reading
97
98
=== IO: pattern 42
99
@@ -XXX,XX +XXX,XX @@ Testing conversion with -o backing_file=TEST_DIR/t.IMGFMT.base
100
101
Checking if backing clusters are allocated when they shouldn't
102
103
-0/128 sectors allocated at offset 1 MiB
104
-0/128 sectors allocated at offset 4.001 GiB
105
+0/65536 bytes allocated at offset 1 MiB
106
+0/65536 bytes allocated at offset 4.001 GiB
107
Reading
108
109
=== IO: pattern 42
110
diff --git a/tests/qemu-iotests/common.pattern b/tests/qemu-iotests/common.pattern
111
index XXXXXXX..XXXXXXX 100644
112
--- a/tests/qemu-iotests/common.pattern
113
+++ b/tests/qemu-iotests/common.pattern
114
@@ -XXX,XX +XXX,XX @@
115
116
function do_is_allocated() {
117
local start=$1
118
- local size=$(( $2 / 512))
119
+ local size=$2
120
local step=$3
121
local count=$4
122
123
--
64
--
124
1.8.3.1
65
2.13.6
125
66
126
67
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Block jobs must be paused if any of the involved nodes are drained.
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
4
---
6
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++++++
5
tests/test-bdrv-drain.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++
7
tests/qemu-iotests/153.out | 390 +++++++++++++++++++++++++++++++++++++++++++++
6
1 file changed, 121 insertions(+)
8
tests/qemu-iotests/group | 1 +
9
3 files changed, 624 insertions(+)
10
create mode 100755 tests/qemu-iotests/153
11
create mode 100644 tests/qemu-iotests/153.out
12
7
13
diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
8
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
14
new file mode 100755
9
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX
10
--- a/tests/test-bdrv-drain.c
16
--- /dev/null
11
+++ b/tests/test-bdrv-drain.c
17
+++ b/tests/qemu-iotests/153
18
@@ -XXX,XX +XXX,XX @@
12
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
13
20
+#
14
#include "qemu/osdep.h"
21
+# Test image locking
15
#include "block/block.h"
22
+#
16
+#include "block/blockjob_int.h"
23
+# Copyright 2016, 2017 Red Hat, Inc.
17
#include "sysemu/block-backend.h"
24
+#
18
#include "qapi/error.h"
25
+# This program is free software; you can redistribute it and/or modify
19
26
+# it under the terms of the GNU General Public License as published by
20
@@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void)
27
+# the Free Software Foundation; either version 2 of the License, or
21
test_quiesce_common(BDRV_DRAIN, false);
28
+# (at your option) any later version.
22
}
29
+#
23
30
+# This program is distributed in the hope that it will be useful,
31
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
+# GNU General Public License for more details.
34
+#
35
+# You should have received a copy of the GNU General Public License
36
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
38
+
24
+
39
+# creator
25
+typedef struct TestBlockJob {
40
+owner=famz@redhat.com
26
+ BlockJob common;
27
+ bool should_complete;
28
+} TestBlockJob;
41
+
29
+
42
+seq="$(basename $0)"
30
+static void test_job_completed(BlockJob *job, void *opaque)
43
+echo "QA output created by $seq"
44
+
45
+here="$PWD"
46
+tmp=/tmp/$$
47
+status=1    # failure is the default!
48
+
49
+_cleanup()
50
+{
31
+{
51
+ _cleanup_test_img
32
+ block_job_completed(job, 0);
52
+ rm -f "${TEST_IMG}.base"
53
+ rm -f "${TEST_IMG}.convert"
54
+ rm -f "${TEST_IMG}.a"
55
+ rm -f "${TEST_IMG}.b"
56
+ rm -f "${TEST_IMG}.lnk"
57
+}
58
+trap "_cleanup; exit \$status" 0 1 2 3 15
59
+
60
+# get standard environment, filters and checks
61
+. ./common.rc
62
+. ./common.filter
63
+. ./common.qemu
64
+
65
+size=32M
66
+
67
+_check_ofd()
68
+{
69
+ _make_test_img $size >/dev/null
70
+ if $QEMU_IMG_PROG info --image-opts "driver=file,locking=on,filename=$TEST_IMG" 2>&1 |
71
+ grep -q 'falling back to POSIX file'; then
72
+ return 1
73
+ else
74
+ return 0
75
+ fi
76
+}
33
+}
77
+
34
+
78
+_check_ofd || _notrun "OFD lock not available"
35
+static void coroutine_fn test_job_start(void *opaque)
36
+{
37
+ TestBlockJob *s = opaque;
79
+
38
+
80
+_supported_fmt qcow2
39
+ while (!s->should_complete) {
81
+_supported_proto file
40
+ block_job_sleep_ns(&s->common, 100000);
82
+_supported_os Linux
41
+ }
83
+
42
+
84
+_run_cmd()
43
+ block_job_defer_to_main_loop(&s->common, test_job_completed, NULL);
85
+{
86
+ echo
87
+ (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
88
+}
44
+}
89
+
45
+
90
+function _do_run_qemu()
46
+static void test_job_complete(BlockJob *job, Error **errp)
91
+{
47
+{
92
+ (
48
+ TestBlockJob *s = container_of(job, TestBlockJob, common);
93
+ if ! test -t 0; then
49
+ s->should_complete = true;
94
+ while read cmd; do
95
+ echo $cmd
96
+ done
97
+ fi
98
+ echo quit
99
+ ) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
100
+}
50
+}
101
+
51
+
102
+function _run_qemu_with_images()
52
+BlockJobDriver test_job_driver = {
53
+ .instance_size = sizeof(TestBlockJob),
54
+ .start = test_job_start,
55
+ .complete = test_job_complete,
56
+};
57
+
58
+static void test_blockjob_common(enum drain_type drain_type)
103
+{
59
+{
104
+ _do_run_qemu \
60
+ BlockBackend *blk_src, *blk_target;
105
+ $(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
61
+ BlockDriverState *src, *target;
106
+ | _filter_testdir | _filter_qemu
62
+ BlockJob *job;
63
+ int ret;
64
+
65
+ src = bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR,
66
+ &error_abort);
67
+ blk_src = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
68
+ blk_insert_bs(blk_src, src, &error_abort);
69
+
70
+ target = bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR,
71
+ &error_abort);
72
+ blk_target = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
73
+ blk_insert_bs(blk_target, target, &error_abort);
74
+
75
+ job = block_job_create("job0", &test_job_driver, src, 0, BLK_PERM_ALL, 0,
76
+ 0, NULL, NULL, &error_abort);
77
+ block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abort);
78
+ block_job_start(job);
79
+
80
+ g_assert_cmpint(job->pause_count, ==, 0);
81
+ g_assert_false(job->paused);
82
+ g_assert_false(job->busy); /* We're in block_job_sleep_ns() */
83
+
84
+ do_drain_begin(drain_type, src);
85
+
86
+ if (drain_type == BDRV_DRAIN_ALL) {
87
+ /* bdrv_drain_all() drains both src and target, and involves an
88
+ * additional block_job_pause_all() */
89
+ g_assert_cmpint(job->pause_count, ==, 3);
90
+ } else {
91
+ g_assert_cmpint(job->pause_count, ==, 1);
92
+ }
93
+ /* XXX We don't wait until the job is actually paused. Is this okay? */
94
+ /* g_assert_true(job->paused); */
95
+ g_assert_false(job->busy); /* The job is paused */
96
+
97
+ do_drain_end(drain_type, src);
98
+
99
+ g_assert_cmpint(job->pause_count, ==, 0);
100
+ g_assert_false(job->paused);
101
+ g_assert_false(job->busy); /* We're in block_job_sleep_ns() */
102
+
103
+ do_drain_begin(drain_type, target);
104
+
105
+ if (drain_type == BDRV_DRAIN_ALL) {
106
+ /* bdrv_drain_all() drains both src and target, and involves an
107
+ * additional block_job_pause_all() */
108
+ g_assert_cmpint(job->pause_count, ==, 3);
109
+ } else {
110
+ g_assert_cmpint(job->pause_count, ==, 1);
111
+ }
112
+ /* XXX We don't wait until the job is actually paused. Is this okay? */
113
+ /* g_assert_true(job->paused); */
114
+ g_assert_false(job->busy); /* The job is paused */
115
+
116
+ do_drain_end(drain_type, target);
117
+
118
+ g_assert_cmpint(job->pause_count, ==, 0);
119
+ g_assert_false(job->paused);
120
+ g_assert_false(job->busy); /* We're in block_job_sleep_ns() */
121
+
122
+ ret = block_job_complete_sync(job, &error_abort);
123
+ g_assert_cmpint(ret, ==, 0);
124
+
125
+ blk_unref(blk_src);
126
+ blk_unref(blk_target);
127
+ bdrv_unref(src);
128
+ bdrv_unref(target);
107
+}
129
+}
108
+
130
+
109
+echo "== readonly=off,force-share=on should be rejected =="
131
+static void test_blockjob_drain_all(void)
110
+_run_qemu_with_images null-co://,readonly=off,force-share=on
132
+{
133
+ test_blockjob_common(BDRV_DRAIN_ALL);
134
+}
111
+
135
+
112
+for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
136
+static void test_blockjob_drain(void)
113
+ echo
137
+{
114
+ echo "== Creating base image =="
138
+ test_blockjob_common(BDRV_DRAIN);
115
+ TEST_IMG="${TEST_IMG}.base" _make_test_img $size
139
+}
116
+
140
+
117
+ echo
141
int main(int argc, char **argv)
118
+ echo "== Creating test image =="
142
{
119
+ $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | _filter_img_create
143
bdrv_init();
144
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
145
g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all);
146
g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain);
147
148
+ g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
149
+ g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain);
120
+
150
+
121
+ echo
151
return g_test_run();
122
+ echo "== Launching QEMU, opts: '$opts1' =="
152
}
123
+ _launch_qemu -drive file="${TEST_IMG}",if=none,$opts1
124
+ h=$QEMU_HANDLE
125
+
126
+ for opts2 in "" "read-only=on" "read-only=on,force-share=on"; do
127
+ echo
128
+ echo "== Launching another QEMU, opts: '$opts2' =="
129
+ echo "quit" | \
130
+ $QEMU -nographic -monitor stdio \
131
+ -drive file="${TEST_IMG}",if=none,$opts2 2>&1 1>/dev/null | \
132
+ _filter_testdir | _filter_qemu
133
+ done
134
+
135
+ for L in "" "-U"; do
136
+
137
+ echo
138
+ echo "== Running utility commands $L =="
139
+ _run_cmd $QEMU_IO $L -c "read 0 512" "${TEST_IMG}"
140
+ _run_cmd $QEMU_IO $L -r -c "read 0 512" "${TEST_IMG}"
141
+ _run_cmd $QEMU_IO -c "open $L ${TEST_IMG}" -c "read 0 512"
142
+ _run_cmd $QEMU_IO -c "open -r $L ${TEST_IMG}" -c "read 0 512"
143
+ _run_cmd $QEMU_IMG info $L "${TEST_IMG}"
144
+ _run_cmd $QEMU_IMG check $L "${TEST_IMG}"
145
+ _run_cmd $QEMU_IMG compare $L "${TEST_IMG}" "${TEST_IMG}"
146
+ _run_cmd $QEMU_IMG map $L "${TEST_IMG}"
147
+ _run_cmd $QEMU_IMG amend -o "" $L "${TEST_IMG}"
148
+ _run_cmd $QEMU_IMG commit $L "${TEST_IMG}"
149
+ _run_cmd $QEMU_IMG resize $L "${TEST_IMG}" $size
150
+ _run_cmd $QEMU_IMG rebase $L "${TEST_IMG}" -b "${TEST_IMG}.base"
151
+ _run_cmd $QEMU_IMG snapshot -l $L "${TEST_IMG}"
152
+ _run_cmd $QEMU_IMG convert $L "${TEST_IMG}" "${TEST_IMG}.convert"
153
+ _run_cmd $QEMU_IMG dd $L if="${TEST_IMG}" of="${TEST_IMG}.convert" bs=512 count=1
154
+ _run_cmd $QEMU_IMG bench $L -c 1 "${TEST_IMG}"
155
+ _run_cmd $QEMU_IMG bench $L -w -c 1 "${TEST_IMG}"
156
+ done
157
+ _send_qemu_cmd $h "{ 'execute': 'quit', }" ""
158
+ echo
159
+ echo "Round done"
160
+ _cleanup_qemu
161
+done
162
+
163
+for opt1 in $test_opts; do
164
+ for opt2 in $test_opts; do
165
+ echo
166
+ echo "== Two devices with the same image ($opt1 - $opt2) =="
167
+ _run_qemu_with_images "${TEST_IMG},$opt1" "${TEST_IMG},$opt2"
168
+ done
169
+done
170
+
171
+echo "== Creating ${TEST_IMG}.[abc] ==" | _filter_testdir
172
+(
173
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.a" -b "${TEST_IMG}"
174
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.b" -b "${TEST_IMG}"
175
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.c" -b "${TEST_IMG}.b"
176
+) | _filter_img_create
177
+
178
+echo
179
+echo "== Two devices sharing the same file in backing chain =="
180
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.b"
181
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.c"
182
+
183
+echo
184
+echo "== Backing image also as an active device =="
185
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}"
186
+
187
+echo
188
+echo "== Backing image also as an active device (ro) =="
189
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG},readonly=on"
190
+
191
+echo
192
+echo "== Symbolic link =="
193
+rm -f "${TEST_IMG}.lnk" &>/dev/null
194
+ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link"
195
+_run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}"
196
+
197
+echo
198
+echo "== Closing an image should unlock it =="
199
+_launch_qemu
200
+
201
+_send_qemu_cmd $QEMU_HANDLE \
202
+ "{ 'execute': 'qmp_capabilities' }" \
203
+ 'return'
204
+
205
+echo "Adding drive"
206
+_send_qemu_cmd $QEMU_HANDLE \
207
+ "{ 'execute': 'human-monitor-command',
208
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=d0,file=${TEST_IMG}' } }" \
209
+ ""
210
+
211
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
212
+
213
+echo "Closing drive"
214
+_send_qemu_cmd $QEMU_HANDLE \
215
+ "{ 'execute': 'human-monitor-command',
216
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
217
+ ""
218
+
219
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
220
+
221
+echo "Adding two and closing one"
222
+for d in d0 d1; do
223
+ _send_qemu_cmd $QEMU_HANDLE \
224
+ "{ 'execute': 'human-monitor-command',
225
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=$d,file=${TEST_IMG},readonly=on' } }" \
226
+ ""
227
+done
228
+
229
+_run_cmd $QEMU_IMG info "${TEST_IMG}"
230
+
231
+_send_qemu_cmd $QEMU_HANDLE \
232
+ "{ 'execute': 'human-monitor-command',
233
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
234
+ ""
235
+
236
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
237
+
238
+echo "Closing the other"
239
+_send_qemu_cmd $QEMU_HANDLE \
240
+ "{ 'execute': 'human-monitor-command',
241
+ 'arguments': { 'command-line': 'drive_del d1' } }" \
242
+ ""
243
+
244
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
245
+
246
+_cleanup_qemu
247
+
248
+# success, all done
249
+echo "*** done"
250
+rm -f $seq.full
251
+status=0
252
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
253
new file mode 100644
254
index XXXXXXX..XXXXXXX
255
--- /dev/null
256
+++ b/tests/qemu-iotests/153.out
257
@@ -XXX,XX +XXX,XX @@
258
+QA output created by 153
259
+== readonly=off,force-share=on should be rejected ==
260
+QEMU_PROG: -drive if=none,file=null-co://,readonly=off,force-share=on: force-share=on can only be used with read-only images
261
+
262
+== Creating base image ==
263
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
264
+
265
+== Creating test image ==
266
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
267
+
268
+== Launching QEMU, opts: '' ==
269
+
270
+== Launching another QEMU, opts: '' ==
271
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
272
+Is another process using the image?
273
+
274
+== Launching another QEMU, opts: 'read-only=on' ==
275
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,read-only=on: Failed to get shared "write" lock
276
+Is another process using the image?
277
+
278
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
279
+
280
+== Running utility commands ==
281
+
282
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
283
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
284
+Is another process using the image?
285
+
286
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
287
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
288
+Is another process using the image?
289
+
290
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
291
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
292
+Is another process using the image?
293
+
294
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
295
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
296
+Is another process using the image?
297
+
298
+_qemu_img_wrapper info TEST_DIR/t.qcow2
299
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
300
+Is another process using the image?
301
+
302
+_qemu_img_wrapper check TEST_DIR/t.qcow2
303
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
304
+Is another process using the image?
305
+
306
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
307
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
308
+Is another process using the image?
309
+
310
+_qemu_img_wrapper map TEST_DIR/t.qcow2
311
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
312
+Is another process using the image?
313
+
314
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
315
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
316
+Is another process using the image?
317
+
318
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
319
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
320
+Is another process using the image?
321
+
322
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
323
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
324
+Is another process using the image?
325
+
326
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
327
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
328
+Is another process using the image?
329
+
330
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
331
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
332
+Is another process using the image?
333
+
334
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
335
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
336
+Is another process using the image?
337
+
338
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
339
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
340
+Is another process using the image?
341
+
342
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
343
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
344
+Is another process using the image?
345
+
346
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
347
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
348
+Is another process using the image?
349
+
350
+== Running utility commands -U ==
351
+
352
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
353
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
354
+
355
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
356
+
357
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
358
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
359
+
360
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
361
+
362
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
363
+
364
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
365
+
366
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
367
+
368
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
369
+
370
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
371
+qemu-img: unrecognized option '-U'
372
+Try 'qemu-img --help' for more information
373
+
374
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
375
+qemu-img: unrecognized option '-U'
376
+Try 'qemu-img --help' for more information
377
+
378
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
379
+qemu-img: unrecognized option '-U'
380
+Try 'qemu-img --help' for more information
381
+
382
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
383
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
384
+Is another process using the image?
385
+
386
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
387
+
388
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
389
+
390
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
391
+
392
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
393
+
394
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
395
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
396
+
397
+Round done
398
+
399
+== Creating base image ==
400
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
401
+
402
+== Creating test image ==
403
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
404
+
405
+== Launching QEMU, opts: 'read-only=on' ==
406
+
407
+== Launching another QEMU, opts: '' ==
408
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
409
+Is another process using the image?
410
+
411
+== Launching another QEMU, opts: 'read-only=on' ==
412
+
413
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
414
+
415
+== Running utility commands ==
416
+
417
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
418
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
419
+Is another process using the image?
420
+
421
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
422
+
423
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
424
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
425
+Is another process using the image?
426
+
427
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
428
+
429
+_qemu_img_wrapper info TEST_DIR/t.qcow2
430
+
431
+_qemu_img_wrapper check TEST_DIR/t.qcow2
432
+
433
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
434
+
435
+_qemu_img_wrapper map TEST_DIR/t.qcow2
436
+
437
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
438
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
439
+Is another process using the image?
440
+
441
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
442
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
443
+Is another process using the image?
444
+
445
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
446
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
447
+Is another process using the image?
448
+
449
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
450
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
451
+Is another process using the image?
452
+
453
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
454
+
455
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
456
+
457
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
458
+
459
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
460
+
461
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
462
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
463
+Is another process using the image?
464
+
465
+== Running utility commands -U ==
466
+
467
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
468
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
469
+
470
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
471
+
472
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
473
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
474
+
475
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
476
+
477
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
478
+
479
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
480
+
481
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
482
+
483
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
484
+
485
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
486
+qemu-img: unrecognized option '-U'
487
+Try 'qemu-img --help' for more information
488
+
489
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
490
+qemu-img: unrecognized option '-U'
491
+Try 'qemu-img --help' for more information
492
+
493
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
494
+qemu-img: unrecognized option '-U'
495
+Try 'qemu-img --help' for more information
496
+
497
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
498
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
499
+Is another process using the image?
500
+
501
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
502
+
503
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
504
+
505
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
506
+
507
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
508
+
509
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
510
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
511
+
512
+Round done
513
+
514
+== Creating base image ==
515
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
516
+
517
+== Creating test image ==
518
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
519
+
520
+== Launching QEMU, opts: 'read-only=on,force-share=on' ==
521
+
522
+== Launching another QEMU, opts: '' ==
523
+
524
+== Launching another QEMU, opts: 'read-only=on' ==
525
+
526
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
527
+
528
+== Running utility commands ==
529
+
530
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
531
+
532
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
533
+
534
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
535
+
536
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
537
+
538
+_qemu_img_wrapper info TEST_DIR/t.qcow2
539
+
540
+_qemu_img_wrapper check TEST_DIR/t.qcow2
541
+
542
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
543
+
544
+_qemu_img_wrapper map TEST_DIR/t.qcow2
545
+
546
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
547
+
548
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
549
+
550
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
551
+
552
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
553
+
554
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
555
+
556
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
557
+
558
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
559
+
560
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
561
+
562
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
563
+
564
+== Running utility commands -U ==
565
+
566
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
567
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
568
+
569
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
570
+
571
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
572
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
573
+
574
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
575
+
576
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
577
+
578
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
579
+
580
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
581
+
582
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
583
+
584
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
585
+qemu-img: unrecognized option '-U'
586
+Try 'qemu-img --help' for more information
587
+
588
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
589
+qemu-img: unrecognized option '-U'
590
+Try 'qemu-img --help' for more information
591
+
592
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
593
+qemu-img: unrecognized option '-U'
594
+Try 'qemu-img --help' for more information
595
+
596
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
597
+
598
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
599
+
600
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
601
+
602
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
603
+
604
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
605
+
606
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
607
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
608
+
609
+Round done
610
+== Creating TEST_DIR/t.qcow2.[abc] ==
611
+Formatting 'TEST_DIR/t.IMGFMT.a', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT
612
+Formatting 'TEST_DIR/t.IMGFMT.b', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT
613
+Formatting 'TEST_DIR/t.IMGFMT.c', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.b
614
+
615
+== Two devices sharing the same file in backing chain ==
616
+
617
+== Backing image also as an active device ==
618
+QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
619
+Is another process using the image?
620
+
621
+== Backing image also as an active device (ro) ==
622
+
623
+== Symbolic link ==
624
+QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
625
+Is another process using the image?
626
+
627
+== Closing an image should unlock it ==
628
+{"return": {}}
629
+Adding drive
630
+
631
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
632
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
633
+Is another process using the image?
634
+Closing drive
635
+
636
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
637
+Adding two and closing one
638
+
639
+_qemu_img_wrapper info TEST_DIR/t.qcow2
640
+
641
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
642
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
643
+Is another process using the image?
644
+Closing the other
645
+
646
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
647
+*** done
648
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
649
index XXXXXXX..XXXXXXX 100644
650
--- a/tests/qemu-iotests/group
651
+++ b/tests/qemu-iotests/group
652
@@ -XXX,XX +XXX,XX @@
653
149 rw auto sudo
654
150 rw auto quick
655
152 rw auto quick
656
+153 rw auto quick
657
154 rw auto backing quick
658
155 rw auto
659
156 rw auto quick
660
--
153
--
661
1.8.3.1
154
2.13.6
662
155
663
156
diff view generated by jsdifflib
1
Now that the block layer takes care to request a lot less permissions
1
Block jobs are already paused using the BdrvChildRole drain callbacks,
2
for inactive nodes, the special-casing in file-posix isn't necessary any
2
so we don't need an additional block_job_pause_all() call.
3
more.
4
3
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
5
---
8
block/file-posix.c | 33 ---------------------------------
6
block/io.c | 4 ----
9
1 file changed, 33 deletions(-)
7
tests/test-bdrv-drain.c | 10 ++++------
8
2 files changed, 4 insertions(+), 10 deletions(-)
10
9
11
diff --git a/block/file-posix.c b/block/file-posix.c
10
diff --git a/block/io.c b/block/io.c
12
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
13
--- a/block/file-posix.c
12
--- a/block/io.c
14
+++ b/block/file-posix.c
13
+++ b/block/io.c
15
@@ -XXX,XX +XXX,XX @@ static void raw_abort_perm_update(BlockDriverState *bs)
14
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
16
raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
15
* context. */
16
assert(qemu_get_current_aio_context() == qemu_get_aio_context());
17
18
- block_job_pause_all();
19
-
20
for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
21
AioContext *aio_context = bdrv_get_aio_context(bs);
22
23
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
24
aio_enable_external(aio_context);
25
aio_context_release(aio_context);
26
}
27
-
28
- block_job_resume_all();
17
}
29
}
18
30
19
-static int raw_inactivate(BlockDriverState *bs)
31
void bdrv_drain_all(void)
20
-{
32
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
21
- int ret;
33
index XXXXXXX..XXXXXXX 100644
22
- uint64_t perm = 0;
34
--- a/tests/test-bdrv-drain.c
23
- uint64_t shared = BLK_PERM_ALL;
35
+++ b/tests/test-bdrv-drain.c
24
-
36
@@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type)
25
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
37
do_drain_begin(drain_type, src);
26
- if (ret) {
38
27
- return ret;
39
if (drain_type == BDRV_DRAIN_ALL) {
28
- }
40
- /* bdrv_drain_all() drains both src and target, and involves an
29
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
41
- * additional block_job_pause_all() */
30
- return 0;
42
- g_assert_cmpint(job->pause_count, ==, 3);
31
-}
43
+ /* bdrv_drain_all() drains both src and target */
32
-
44
+ g_assert_cmpint(job->pause_count, ==, 2);
33
-
45
} else {
34
-static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
46
g_assert_cmpint(job->pause_count, ==, 1);
35
-{
47
}
36
- BDRVRawState *s = bs->opaque;
48
@@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type)
37
- int ret;
49
do_drain_begin(drain_type, target);
38
-
50
39
- assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
51
if (drain_type == BDRV_DRAIN_ALL) {
40
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
52
- /* bdrv_drain_all() drains both src and target, and involves an
41
- errp);
53
- * additional block_job_pause_all() */
42
- if (ret) {
54
- g_assert_cmpint(job->pause_count, ==, 3);
43
- return;
55
+ /* bdrv_drain_all() drains both src and target */
44
- }
56
+ g_assert_cmpint(job->pause_count, ==, 2);
45
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, s->perm, s->shared_perm, NULL);
57
} else {
46
-}
58
g_assert_cmpint(job->pause_count, ==, 1);
47
-
59
}
48
BlockDriver bdrv_file = {
49
.format_name = "file",
50
.protocol_name = "file",
51
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
52
.bdrv_get_info = raw_get_info,
53
.bdrv_get_allocated_file_size
54
= raw_get_allocated_file_size,
55
- .bdrv_inactivate = raw_inactivate,
56
- .bdrv_invalidate_cache = raw_invalidate_cache,
57
.bdrv_check_perm = raw_check_perm,
58
.bdrv_set_perm = raw_set_perm,
59
.bdrv_abort_perm_update = raw_abort_perm_update,
60
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_device = {
61
.bdrv_get_info = raw_get_info,
62
.bdrv_get_allocated_file_size
63
= raw_get_allocated_file_size,
64
- .bdrv_inactivate = raw_inactivate,
65
- .bdrv_invalidate_cache = raw_invalidate_cache,
66
.bdrv_check_perm = raw_check_perm,
67
.bdrv_set_perm = raw_set_perm,
68
.bdrv_abort_perm_update = raw_abort_perm_update,
69
--
60
--
70
1.8.3.1
61
2.13.6
71
62
72
63
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
bdrv_do_drained_begin() restricts the call of parent callbacks and
2
aio_disable_external() to the outermost drain section, but the block
3
driver callbacks are always called. bdrv_do_drained_end() must match
4
this behaviour, otherwise nodes stay drained even if begin/end calls
5
were balanced.
2
6
3
Make it easier to simulate various unusual hardware setups (for
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
example, recent commits 3482b9b and b8d0a98 affect the Dell
8
---
5
Equallogic iSCSI with its 15M preferred and maximum unmap and
9
block/io.c | 12 +++++++-----
6
write zero sizing, or b2f95fe deals with the Linux loopback
10
1 file changed, 7 insertions(+), 5 deletions(-)
7
block device having a max_transfer of 64k), by allowing blkdebug
8
to wrap any other device with further restrictions on various
9
alignments.
10
11
11
Signed-off-by: Eric Blake <eblake@redhat.com>
12
diff --git a/block/io.c b/block/io.c
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Message-id: 20170429191419.30051-9-eblake@redhat.com
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
16
block/blkdebug.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-
17
qapi/block-core.json | 33 ++++++++++++++++--
18
2 files changed, 125 insertions(+), 4 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
14
--- a/block/io.c
23
+++ b/block/blkdebug.c
15
+++ b/block/io.c
24
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVBlkdebugState {
16
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs)
25
int state;
17
26
int new_state;
18
void bdrv_drained_end(BlockDriverState *bs)
27
uint64_t align;
19
{
28
+ uint64_t max_transfer;
20
+ int old_quiesce_counter;
29
+ uint64_t opt_write_zero;
21
+
30
+ uint64_t max_write_zero;
22
if (qemu_in_coroutine()) {
31
+ uint64_t opt_discard;
23
bdrv_co_yield_to_drain(bs, false);
32
+ uint64_t max_discard;
24
return;
33
34
/* For blkdebug_refresh_filename() */
35
char *config_file;
36
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
37
.type = QEMU_OPT_SIZE,
38
.help = "Required alignment in bytes",
39
},
40
+ {
41
+ .name = "max-transfer",
42
+ .type = QEMU_OPT_SIZE,
43
+ .help = "Maximum transfer size in bytes",
44
+ },
45
+ {
46
+ .name = "opt-write-zero",
47
+ .type = QEMU_OPT_SIZE,
48
+ .help = "Optimum write zero alignment in bytes",
49
+ },
50
+ {
51
+ .name = "max-write-zero",
52
+ .type = QEMU_OPT_SIZE,
53
+ .help = "Maximum write zero size in bytes",
54
+ },
55
+ {
56
+ .name = "opt-discard",
57
+ .type = QEMU_OPT_SIZE,
58
+ .help = "Optimum discard alignment in bytes",
59
+ },
60
+ {
61
+ .name = "max-discard",
62
+ .type = QEMU_OPT_SIZE,
63
+ .help = "Maximum discard size in bytes",
64
+ },
65
{ /* end of list */ }
66
},
67
};
68
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
69
QemuOpts *opts;
70
Error *local_err = NULL;
71
int ret;
72
+ uint64_t align;
73
74
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
75
qemu_opts_absorb_qdict(opts, options, &local_err);
76
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
77
bs->file->bs->supported_zero_flags;
78
ret = -EINVAL;
79
80
- /* Set request alignment */
81
+ /* Set alignment overrides */
82
s->align = qemu_opt_get_size(opts, "align", 0);
83
if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
84
error_setg(errp, "Cannot meet constraints with align %" PRIu64,
85
s->align);
86
goto out;
87
}
25
}
88
+ align = MAX(s->align, bs->file->bs->bl.request_alignment);
26
assert(bs->quiesce_counter > 0);
89
+
27
- if (atomic_fetch_dec(&bs->quiesce_counter) > 1) {
90
+ s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0);
28
- return;
91
+ if (s->max_transfer &&
29
- }
92
+ (s->max_transfer >= INT_MAX ||
30
+ old_quiesce_counter = atomic_fetch_dec(&bs->quiesce_counter);
93
+ !QEMU_IS_ALIGNED(s->max_transfer, align))) {
31
94
+ error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64,
32
/* Re-enable things in child-to-parent order */
95
+ s->max_transfer);
33
bdrv_drain_invoke(bs, false, false);
96
+ goto out;
34
- bdrv_parent_drained_end(bs);
97
+ }
35
- aio_enable_external(bdrv_get_aio_context(bs));
98
+
36
+ if (old_quiesce_counter == 1) {
99
+ s->opt_write_zero = qemu_opt_get_size(opts, "opt-write-zero", 0);
37
+ bdrv_parent_drained_end(bs);
100
+ if (s->opt_write_zero &&
38
+ aio_enable_external(bdrv_get_aio_context(bs));
101
+ (s->opt_write_zero >= INT_MAX ||
102
+ !QEMU_IS_ALIGNED(s->opt_write_zero, align))) {
103
+ error_setg(errp, "Cannot meet constraints with opt-write-zero %" PRIu64,
104
+ s->opt_write_zero);
105
+ goto out;
106
+ }
107
+
108
+ s->max_write_zero = qemu_opt_get_size(opts, "max-write-zero", 0);
109
+ if (s->max_write_zero &&
110
+ (s->max_write_zero >= INT_MAX ||
111
+ !QEMU_IS_ALIGNED(s->max_write_zero,
112
+ MAX(s->opt_write_zero, align)))) {
113
+ error_setg(errp, "Cannot meet constraints with max-write-zero %" PRIu64,
114
+ s->max_write_zero);
115
+ goto out;
116
+ }
117
+
118
+ s->opt_discard = qemu_opt_get_size(opts, "opt-discard", 0);
119
+ if (s->opt_discard &&
120
+ (s->opt_discard >= INT_MAX ||
121
+ !QEMU_IS_ALIGNED(s->opt_discard, align))) {
122
+ error_setg(errp, "Cannot meet constraints with opt-discard %" PRIu64,
123
+ s->opt_discard);
124
+ goto out;
125
+ }
126
+
127
+ s->max_discard = qemu_opt_get_size(opts, "max-discard", 0);
128
+ if (s->max_discard &&
129
+ (s->max_discard >= INT_MAX ||
130
+ !QEMU_IS_ALIGNED(s->max_discard,
131
+ MAX(s->opt_discard, align)))) {
132
+ error_setg(errp, "Cannot meet constraints with max-discard %" PRIu64,
133
+ s->max_discard);
134
+ goto out;
135
+ }
136
137
ret = 0;
138
out:
139
@@ -XXX,XX +XXX,XX @@ static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp)
140
if (s->align) {
141
bs->bl.request_alignment = s->align;
142
}
143
+ if (s->max_transfer) {
144
+ bs->bl.max_transfer = s->max_transfer;
145
+ }
146
+ if (s->opt_write_zero) {
147
+ bs->bl.pwrite_zeroes_alignment = s->opt_write_zero;
148
+ }
149
+ if (s->max_write_zero) {
150
+ bs->bl.max_pwrite_zeroes = s->max_write_zero;
151
+ }
152
+ if (s->opt_discard) {
153
+ bs->bl.pdiscard_alignment = s->opt_discard;
154
+ }
155
+ if (s->max_discard) {
156
+ bs->bl.max_pdiscard = s->max_discard;
157
+ }
39
+ }
158
}
40
}
159
41
160
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
42
/*
161
diff --git a/qapi/block-core.json b/qapi/block-core.json
162
index XXXXXXX..XXXXXXX 100644
163
--- a/qapi/block-core.json
164
+++ b/qapi/block-core.json
165
@@ -XXX,XX +XXX,XX @@
166
#
167
# @config: filename of the configuration file
168
#
169
-# @align: required alignment for requests in bytes,
170
-# must be power of 2, or 0 for default
171
+# @align: required alignment for requests in bytes, must be
172
+# positive power of 2, or 0 for default
173
+#
174
+# @max-transfer: maximum size for I/O transfers in bytes, must be
175
+# positive multiple of @align and of the underlying
176
+# file's request alignment (but need not be a power of
177
+# 2), or 0 for default (since 2.10)
178
+#
179
+# @opt-write-zero: preferred alignment for write zero requests in bytes,
180
+# must be positive multiple of @align and of the
181
+# underlying file's request alignment (but need not be a
182
+# power of 2), or 0 for default (since 2.10)
183
+#
184
+# @max-write-zero: maximum size for write zero requests in bytes, must be
185
+# positive multiple of @align, of @opt-write-zero, and of
186
+# the underlying file's request alignment (but need not
187
+# be a power of 2), or 0 for default (since 2.10)
188
+#
189
+# @opt-discard: preferred alignment for discard requests in bytes, must
190
+# be positive multiple of @align and of the underlying
191
+# file's request alignment (but need not be a power of
192
+# 2), or 0 for default (since 2.10)
193
+#
194
+# @max-discard: maximum size for discard requests in bytes, must be
195
+# positive multiple of @align, of @opt-discard, and of
196
+# the underlying file's request alignment (but need not
197
+# be a power of 2), or 0 for default (since 2.10)
198
#
199
# @inject-error: array of error injection descriptions
200
#
201
@@ -XXX,XX +XXX,XX @@
202
{ 'struct': 'BlockdevOptionsBlkdebug',
203
'data': { 'image': 'BlockdevRef',
204
'*config': 'str',
205
- '*align': 'int',
206
+ '*align': 'int', '*max-transfer': 'int32',
207
+ '*opt-write-zero': 'int32', '*max-write-zero': 'int32',
208
+ '*opt-discard': 'int32', '*max-discard': 'int32',
209
'*inject-error': ['BlkdebugInjectErrorOptions'],
210
'*set-state': ['BlkdebugSetStateOptions'] } }
211
212
--
43
--
213
1.8.3.1
44
2.13.6
214
45
215
46
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
2
3
Opening the backing image for the second time is bad, especially here
4
when it is also in use as the active image as the source. The
5
drive-backup job itself doesn't read from target->backing for COW,
6
instead it gets data from the write notifier, so it's not a big problem.
7
However, exporting the target to NBD etc. won't work, because of the
8
likely stale metadata cache.
9
10
Use BDRV_O_NO_BACKING in this case and manually set up the backing
11
BdrvChild.
12
13
Cc: qemu-stable@nongnu.org
14
Signed-off-by: Fam Zheng <famz@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
2
---
17
blockdev.c | 15 ++++++++++++++-
3
tests/test-bdrv-drain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
18
1 file changed, 14 insertions(+), 1 deletion(-)
4
1 file changed, 57 insertions(+)
19
5
20
diff --git a/blockdev.c b/blockdev.c
6
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
21
index XXXXXXX..XXXXXXX 100644
7
index XXXXXXX..XXXXXXX 100644
22
--- a/blockdev.c
8
--- a/tests/test-bdrv-drain.c
23
+++ b/blockdev.c
9
+++ b/tests/test-bdrv-drain.c
24
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
10
@@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret)
25
Error *local_err = NULL;
11
enum drain_type {
26
int flags;
12
BDRV_DRAIN_ALL,
27
int64_t size;
13
BDRV_DRAIN,
28
+ bool set_backing_hd = false;
14
+ DRAIN_TYPE_MAX,
29
15
};
30
if (!backup->has_speed) {
16
31
backup->speed = 0;
17
static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs)
32
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
18
@@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void)
33
}
19
test_quiesce_common(BDRV_DRAIN, false);
34
if (backup->sync == MIRROR_SYNC_MODE_NONE) {
20
}
35
source = bs;
21
36
+ flags |= BDRV_O_NO_BACKING;
22
+static void test_nested(void)
37
+ set_backing_hd = true;
23
+{
38
}
24
+ BlockBackend *blk;
39
25
+ BlockDriverState *bs, *backing;
40
size = bdrv_getlength(bs);
26
+ BDRVTestState *s, *backing_s;
41
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
27
+ enum drain_type outer, inner;
42
}
28
+
43
29
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
44
if (backup->format) {
30
+ bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
45
- options = qdict_new();
31
+ &error_abort);
46
+ if (!options) {
32
+ s = bs->opaque;
47
+ options = qdict_new();
33
+ blk_insert_bs(blk, bs, &error_abort);
48
+ }
34
+
49
qdict_put_str(options, "driver", backup->format);
35
+ backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
50
}
36
+ backing_s = backing->opaque;
51
37
+ bdrv_set_backing_hd(bs, backing, &error_abort);
52
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
38
+
53
39
+ for (outer = 0; outer < DRAIN_TYPE_MAX; outer++) {
54
bdrv_set_aio_context(target_bs, aio_context);
40
+ for (inner = 0; inner < DRAIN_TYPE_MAX; inner++) {
55
41
+ /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */
56
+ if (set_backing_hd) {
42
+ int bs_quiesce = (outer != BDRV_DRAIN_ALL) +
57
+ bdrv_set_backing_hd(target_bs, source, &local_err);
43
+ (inner != BDRV_DRAIN_ALL);
58
+ if (local_err) {
44
+ int backing_quiesce = 0;
59
+ bdrv_unref(target_bs);
45
+ int backing_cb_cnt = (outer != BDRV_DRAIN) +
60
+ goto out;
46
+ (inner != BDRV_DRAIN);
47
+
48
+ g_assert_cmpint(bs->quiesce_counter, ==, 0);
49
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
50
+ g_assert_cmpint(s->drain_count, ==, 0);
51
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
52
+
53
+ do_drain_begin(outer, bs);
54
+ do_drain_begin(inner, bs);
55
+
56
+ g_assert_cmpint(bs->quiesce_counter, ==, bs_quiesce);
57
+ g_assert_cmpint(backing->quiesce_counter, ==, backing_quiesce);
58
+ g_assert_cmpint(s->drain_count, ==, 2);
59
+ g_assert_cmpint(backing_s->drain_count, ==, backing_cb_cnt);
60
+
61
+ do_drain_end(inner, bs);
62
+ do_drain_end(outer, bs);
63
+
64
+ g_assert_cmpint(bs->quiesce_counter, ==, 0);
65
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
66
+ g_assert_cmpint(s->drain_count, ==, 0);
67
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
61
+ }
68
+ }
62
+ }
69
+ }
63
+
70
+
64
if (backup->has_bitmap) {
71
+ bdrv_unref(backing);
65
bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
72
+ bdrv_unref(bs);
66
if (!bmap) {
73
+ blk_unref(blk);
74
+}
75
+
76
77
typedef struct TestBlockJob {
78
BlockJob common;
79
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
80
g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all);
81
g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain);
82
83
+ g_test_add_func("/bdrv-drain/nested", test_nested);
84
+
85
g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
86
g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain);
87
67
--
88
--
68
1.8.3.1
89
2.13.6
69
90
70
91
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
This is in preparation for subtree drains, i.e. drained sections that
2
2
affect not only a single node, but recursively all child nodes, too.
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
4
Calling the parent callbacks for drain is pointless when we just came
5
from that parent node recursively and leads to multiple increases of
6
bs->quiesce_counter in a single drain call. Don't do it.
7
8
In order for this to work correctly, the parent callback must be called
9
for every bdrv_drain_begin/end() call, not only for the outermost one:
10
11
If we have a node N with two parents A and B, recursive draining of A
12
should cause the quiesce_counter of B to increase because its child N is
13
drained independently of B. If now B is recursively drained, too, A must
14
increase its quiesce_counter because N is drained independently of A
15
only now, even if N is going from quiesce_counter 1 to 2.
16
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
18
---
6
block.c | 32 ++++++++++++++++++++++++--------
19
include/block/block.h | 4 ++--
7
1 file changed, 24 insertions(+), 8 deletions(-)
20
block.c | 13 +++++++++----
8
21
block/io.c | 47 ++++++++++++++++++++++++++++++++++-------------
22
3 files changed, 45 insertions(+), 19 deletions(-)
23
24
diff --git a/include/block/block.h b/include/block/block.h
25
index XXXXXXX..XXXXXXX 100644
26
--- a/include/block/block.h
27
+++ b/include/block/block.h
28
@@ -XXX,XX +XXX,XX @@ void bdrv_io_unplug(BlockDriverState *bs);
29
* Begin a quiesced section of all users of @bs. This is part of
30
* bdrv_drained_begin.
31
*/
32
-void bdrv_parent_drained_begin(BlockDriverState *bs);
33
+void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore);
34
35
/**
36
* bdrv_parent_drained_end:
37
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin(BlockDriverState *bs);
38
* End a quiesced section of all users of @bs. This is part of
39
* bdrv_drained_end.
40
*/
41
-void bdrv_parent_drained_end(BlockDriverState *bs);
42
+void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore);
43
44
/**
45
* bdrv_drained_begin:
9
diff --git a/block.c b/block.c
46
diff --git a/block.c b/block.c
10
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
11
--- a/block.c
48
--- a/block.c
12
+++ b/block.c
49
+++ b/block.c
13
@@ -XXX,XX +XXX,XX @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
50
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child,
14
static void bdrv_child_abort_perm_update(BdrvChild *c);
51
BlockDriverState *new_bs)
15
static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
52
{
16
53
BlockDriverState *old_bs = child->bs;
17
+static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
54
+ int i;
18
+ BdrvChild *c,
55
19
+ const BdrvChildRole *role,
56
if (old_bs && new_bs) {
20
+ uint64_t parent_perm, uint64_t parent_shared,
57
assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs));
21
+ uint64_t *nperm, uint64_t *nshared)
58
}
59
if (old_bs) {
60
if (old_bs->quiesce_counter && child->role->drained_end) {
61
- child->role->drained_end(child);
62
+ for (i = 0; i < old_bs->quiesce_counter; i++) {
63
+ child->role->drained_end(child);
64
+ }
65
}
66
if (child->role->detach) {
67
child->role->detach(child);
68
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child,
69
if (new_bs) {
70
QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
71
if (new_bs->quiesce_counter && child->role->drained_begin) {
72
- child->role->drained_begin(child);
73
+ for (i = 0; i < new_bs->quiesce_counter; i++) {
74
+ child->role->drained_begin(child);
75
+ }
76
}
77
78
if (child->role->attach) {
79
@@ -XXX,XX +XXX,XX @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
80
AioContext *ctx = bdrv_get_aio_context(bs);
81
82
aio_disable_external(ctx);
83
- bdrv_parent_drained_begin(bs);
84
+ bdrv_parent_drained_begin(bs, NULL);
85
bdrv_drain(bs); /* ensure there are no in-flight requests */
86
87
while (aio_poll(ctx, false)) {
88
@@ -XXX,XX +XXX,XX @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
89
*/
90
aio_context_acquire(new_context);
91
bdrv_attach_aio_context(bs, new_context);
92
- bdrv_parent_drained_end(bs);
93
+ bdrv_parent_drained_end(bs, NULL);
94
aio_enable_external(ctx);
95
aio_context_release(new_context);
96
}
97
diff --git a/block/io.c b/block/io.c
98
index XXXXXXX..XXXXXXX 100644
99
--- a/block/io.c
100
+++ b/block/io.c
101
@@ -XXX,XX +XXX,XX @@
102
static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
103
int64_t offset, int bytes, BdrvRequestFlags flags);
104
105
-void bdrv_parent_drained_begin(BlockDriverState *bs)
106
+void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore)
107
{
108
BdrvChild *c, *next;
109
110
QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) {
111
+ if (c == ignore) {
112
+ continue;
113
+ }
114
if (c->role->drained_begin) {
115
c->role->drained_begin(c);
116
}
117
}
118
}
119
120
-void bdrv_parent_drained_end(BlockDriverState *bs)
121
+void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore)
122
{
123
BdrvChild *c, *next;
124
125
QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) {
126
+ if (c == ignore) {
127
+ continue;
128
+ }
129
if (c->role->drained_end) {
130
c->role->drained_end(c);
131
}
132
@@ -XXX,XX +XXX,XX @@ typedef struct {
133
BlockDriverState *bs;
134
bool done;
135
bool begin;
136
+ BdrvChild *parent;
137
} BdrvCoDrainData;
138
139
static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
140
@@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs)
141
return waited;
142
}
143
144
+static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent);
145
+static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent);
146
+
147
static void bdrv_co_drain_bh_cb(void *opaque)
148
{
149
BdrvCoDrainData *data = opaque;
150
@@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque)
151
152
bdrv_dec_in_flight(bs);
153
if (data->begin) {
154
- bdrv_drained_begin(bs);
155
+ bdrv_do_drained_begin(bs, data->parent);
156
} else {
157
- bdrv_drained_end(bs);
158
+ bdrv_do_drained_end(bs, data->parent);
159
}
160
161
data->done = true;
162
@@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque)
163
}
164
165
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
166
- bool begin)
167
+ bool begin, BdrvChild *parent)
168
{
169
BdrvCoDrainData data;
170
171
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
172
.bs = bs,
173
.done = false,
174
.begin = begin,
175
+ .parent = parent,
176
};
177
bdrv_inc_in_flight(bs);
178
aio_bh_schedule_oneshot(bdrv_get_aio_context(bs),
179
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
180
assert(data.done);
181
}
182
183
-void bdrv_drained_begin(BlockDriverState *bs)
184
+static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent)
185
{
186
if (qemu_in_coroutine()) {
187
- bdrv_co_yield_to_drain(bs, true);
188
+ bdrv_co_yield_to_drain(bs, true, parent);
189
return;
190
}
191
192
/* Stop things in parent-to-child order */
193
if (atomic_fetch_inc(&bs->quiesce_counter) == 0) {
194
aio_disable_external(bdrv_get_aio_context(bs));
195
- bdrv_parent_drained_begin(bs);
196
}
197
198
+ bdrv_parent_drained_begin(bs, parent);
199
bdrv_drain_invoke(bs, true, false);
200
bdrv_drain_recurse(bs);
201
}
202
203
-void bdrv_drained_end(BlockDriverState *bs)
204
+void bdrv_drained_begin(BlockDriverState *bs)
22
+{
205
+{
23
+ if (bs->drv && bs->drv->bdrv_child_perm) {
206
+ bdrv_do_drained_begin(bs, NULL);
24
+ bs->drv->bdrv_child_perm(bs, c, role,
207
+}
25
+ parent_perm, parent_shared,
208
+
26
+ nperm, nshared);
209
+static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
27
+ }
210
{
28
+ if (child_bs && child_bs->force_share) {
211
int old_quiesce_counter;
29
+ *nshared = BLK_PERM_ALL;
212
30
+ }
213
if (qemu_in_coroutine()) {
214
- bdrv_co_yield_to_drain(bs, false);
215
+ bdrv_co_yield_to_drain(bs, false, parent);
216
return;
217
}
218
assert(bs->quiesce_counter > 0);
219
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs)
220
221
/* Re-enable things in child-to-parent order */
222
bdrv_drain_invoke(bs, false, false);
223
+ bdrv_parent_drained_end(bs, parent);
224
if (old_quiesce_counter == 1) {
225
- bdrv_parent_drained_end(bs);
226
aio_enable_external(bdrv_get_aio_context(bs));
227
}
228
}
229
230
+void bdrv_drained_end(BlockDriverState *bs)
231
+{
232
+ bdrv_do_drained_end(bs, NULL);
31
+}
233
+}
32
+
234
+
33
/*
235
/*
34
* Check whether permissions on this node can be changed in a way that
236
* Wait for pending requests to complete on a single BlockDriverState subtree,
35
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
237
* and suspend block driver's internal I/O until next request arrives.
36
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
238
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void)
37
/* Check all children */
239
/* Stop things in parent-to-child order */
38
QLIST_FOREACH(c, &bs->children, next) {
240
aio_context_acquire(aio_context);
39
uint64_t cur_perm, cur_shared;
241
aio_disable_external(aio_context);
40
- drv->bdrv_child_perm(bs, c, c->role,
242
- bdrv_parent_drained_begin(bs);
41
- cumulative_perms, cumulative_shared_perms,
243
+ bdrv_parent_drained_begin(bs, NULL);
42
- &cur_perm, &cur_shared);
244
bdrv_drain_invoke(bs, true, true);
43
+ bdrv_child_perm(bs, c->bs, c, c->role,
245
aio_context_release(aio_context);
44
+ cumulative_perms, cumulative_shared_perms,
246
45
+ &cur_perm, &cur_shared);
247
@@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void)
46
ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
248
/* Re-enable things in child-to-parent order */
47
errp);
249
aio_context_acquire(aio_context);
48
if (ret < 0) {
250
bdrv_drain_invoke(bs, false, true);
49
@@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
251
- bdrv_parent_drained_end(bs);
50
/* Update all children */
252
+ bdrv_parent_drained_end(bs, NULL);
51
QLIST_FOREACH(c, &bs->children, next) {
253
aio_enable_external(aio_context);
52
uint64_t cur_perm, cur_shared;
254
aio_context_release(aio_context);
53
- drv->bdrv_child_perm(bs, c, c->role,
255
}
54
- cumulative_perms, cumulative_shared_perms,
55
- &cur_perm, &cur_shared);
56
+ bdrv_child_perm(bs, c->bs, c, c->role,
57
+ cumulative_perms, cumulative_shared_perms,
58
+ &cur_perm, &cur_shared);
59
bdrv_child_set_perm(c, cur_perm, cur_shared);
60
}
61
}
62
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
63
64
assert(parent_bs->drv);
65
assert(bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs));
66
- parent_bs->drv->bdrv_child_perm(parent_bs, NULL, child_role,
67
- perm, shared_perm, &perm, &shared_perm);
68
+ bdrv_child_perm(parent_bs, child_bs, NULL, child_role,
69
+ perm, shared_perm, &perm, &shared_perm);
70
71
child = bdrv_root_attach_child(child_bs, child_name, child_role,
72
perm, shared_perm, parent_bs, errp);
73
--
256
--
74
1.8.3.1
257
2.13.6
75
258
76
259
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
bdrv_drained_begin() waits for the completion of requests in the whole
2
subtree, but it only actually keeps its immediate bs parameter quiesced
3
until bdrv_drained_end().
2
4
3
We had some conflicting documentation: a nice 8-way table that
5
Add a version that keeps the whole subtree drained. As of this commit,
4
described all possible combinations of DATA, ZERO, and
6
graph changes cannot be allowed during a subtree drained section, but
5
OFFSET_VALID, contrasted with text that implied that OFFSET_VALID
7
this will be fixed soon.
6
always meant raw data could be read directly. Furthermore, the
7
text refers a lot to bs->file, even though the interface was
8
updated back in 67a0fd2a to let the driver pass back a specific
9
BDS (not necessarily bs->file). As the 8-way table is the
10
intended semantics, simplify the rest of the text to get rid of
11
the confusion.
12
8
13
ALLOCATED is always set by the block layer for convenience (drivers
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
do not have to worry about it). RAW is used only internally, but
15
by more than the raw driver. Document these additional items on
16
the driver callback.
17
18
Suggested-by: Max Reitz <mreitz@redhat.com>
19
Signed-off-by: Eric Blake <eblake@redhat.com>
20
Reviewed-by: Max Reitz <mreitz@redhat.com>
21
Message-id: 20170507000552.20847-4-eblake@redhat.com
22
Signed-off-by: Max Reitz <mreitz@redhat.com>
23
---
10
---
24
include/block/block.h | 35 +++++++++++++++++++----------------
11
include/block/block.h | 13 +++++++++++++
25
include/block/block_int.h | 7 +++++++
12
block/io.c | 54 ++++++++++++++++++++++++++++++++++++++++-----------
26
2 files changed, 26 insertions(+), 16 deletions(-)
13
2 files changed, 56 insertions(+), 11 deletions(-)
27
14
28
diff --git a/include/block/block.h b/include/block/block.h
15
diff --git a/include/block/block.h b/include/block/block.h
29
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
30
--- a/include/block/block.h
17
--- a/include/block/block.h
31
+++ b/include/block/block.h
18
+++ b/include/block/block.h
32
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
19
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore);
33
#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
20
void bdrv_drained_begin(BlockDriverState *bs);
21
22
/**
23
+ * Like bdrv_drained_begin, but recursively begins a quiesced section for
24
+ * exclusive access to all child nodes as well.
25
+ *
26
+ * Graph changes are not allowed during a subtree drain section.
27
+ */
28
+void bdrv_subtree_drained_begin(BlockDriverState *bs);
29
+
30
+/**
31
* bdrv_drained_end:
32
*
33
* End a quiescent section started by bdrv_drained_begin().
34
*/
35
void bdrv_drained_end(BlockDriverState *bs);
36
37
+/**
38
+ * End a quiescent section started by bdrv_subtree_drained_begin().
39
+ */
40
+void bdrv_subtree_drained_end(BlockDriverState *bs);
41
+
42
void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child,
43
Error **errp);
44
void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp);
45
diff --git a/block/io.c b/block/io.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/block/io.c
48
+++ b/block/io.c
49
@@ -XXX,XX +XXX,XX @@ typedef struct {
50
BlockDriverState *bs;
51
bool done;
52
bool begin;
53
+ bool recursive;
54
BdrvChild *parent;
55
} BdrvCoDrainData;
56
57
@@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs)
58
return waited;
59
}
60
61
-static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent);
62
-static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent);
63
+static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
64
+ BdrvChild *parent);
65
+static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
66
+ BdrvChild *parent);
67
68
static void bdrv_co_drain_bh_cb(void *opaque)
69
{
70
@@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque)
71
72
bdrv_dec_in_flight(bs);
73
if (data->begin) {
74
- bdrv_do_drained_begin(bs, data->parent);
75
+ bdrv_do_drained_begin(bs, data->recursive, data->parent);
76
} else {
77
- bdrv_do_drained_end(bs, data->parent);
78
+ bdrv_do_drained_end(bs, data->recursive, data->parent);
79
}
80
81
data->done = true;
82
@@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque)
83
}
84
85
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
86
- bool begin, BdrvChild *parent)
87
+ bool begin, bool recursive,
88
+ BdrvChild *parent)
89
{
90
BdrvCoDrainData data;
91
92
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
93
.bs = bs,
94
.done = false,
95
.begin = begin,
96
+ .recursive = recursive,
97
.parent = parent,
98
};
99
bdrv_inc_in_flight(bs);
100
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
101
assert(data.done);
102
}
103
104
-static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent)
105
+static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
106
+ BdrvChild *parent)
107
{
108
+ BdrvChild *child, *next;
109
+
110
if (qemu_in_coroutine()) {
111
- bdrv_co_yield_to_drain(bs, true, parent);
112
+ bdrv_co_yield_to_drain(bs, true, recursive, parent);
113
return;
114
}
115
116
@@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent)
117
bdrv_parent_drained_begin(bs, parent);
118
bdrv_drain_invoke(bs, true, false);
119
bdrv_drain_recurse(bs);
120
+
121
+ if (recursive) {
122
+ QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
123
+ bdrv_do_drained_begin(child->bs, true, child);
124
+ }
125
+ }
126
}
127
128
void bdrv_drained_begin(BlockDriverState *bs)
129
{
130
- bdrv_do_drained_begin(bs, NULL);
131
+ bdrv_do_drained_begin(bs, false, NULL);
132
+}
133
+
134
+void bdrv_subtree_drained_begin(BlockDriverState *bs)
135
+{
136
+ bdrv_do_drained_begin(bs, true, NULL);
137
}
138
139
-static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
140
+static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
141
+ BdrvChild *parent)
142
{
143
+ BdrvChild *child, *next;
144
int old_quiesce_counter;
145
146
if (qemu_in_coroutine()) {
147
- bdrv_co_yield_to_drain(bs, false, parent);
148
+ bdrv_co_yield_to_drain(bs, false, recursive, parent);
149
return;
150
}
151
assert(bs->quiesce_counter > 0);
152
@@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
153
if (old_quiesce_counter == 1) {
154
aio_enable_external(bdrv_get_aio_context(bs));
155
}
156
+
157
+ if (recursive) {
158
+ QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
159
+ bdrv_do_drained_end(child->bs, true, child);
160
+ }
161
+ }
162
}
163
164
void bdrv_drained_end(BlockDriverState *bs)
165
{
166
- bdrv_do_drained_end(bs, NULL);
167
+ bdrv_do_drained_end(bs, false, NULL);
168
+}
169
+
170
+void bdrv_subtree_drained_end(BlockDriverState *bs)
171
+{
172
+ bdrv_do_drained_end(bs, true, NULL);
173
}
34
174
35
/*
175
/*
36
- * Allocation status flags
37
- * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_status.
38
- * BDRV_BLOCK_ZERO: sectors read as zero
39
- * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by
40
- * bdrv_get_block_status.
41
+ * Allocation status flags for bdrv_get_block_status() and friends.
42
+ *
43
+ * Public flags:
44
+ * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer
45
+ * BDRV_BLOCK_ZERO: offset reads as zero
46
+ * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
47
* BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
48
- * layer (as opposed to the backing file)
49
- * BDRV_BLOCK_RAW: used internally to indicate that the request
50
- * was answered by the raw driver and that one
51
- * should look in bs->file directly.
52
+ * layer (short for DATA || ZERO), set by block layer
53
*
54
- * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
55
- * bs->file where sector data can be read from as raw data.
56
+ * Internal flag:
57
+ * BDRV_BLOCK_RAW: used internally to indicate that the request was
58
+ * answered by a passthrough driver such as raw and that the
59
+ * block layer should recompute the answer from bs->file.
60
*
61
- * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present.
62
+ * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK)
63
+ * represent the offset in the returned BDS that is allocated for the
64
+ * corresponding raw data; however, whether that offset actually contains
65
+ * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows:
66
*
67
* DATA ZERO OFFSET_VALID
68
- * t t t sectors read as zero, bs->file is zero at offset
69
- * t f t sectors read as valid from bs->file at offset
70
- * f t t sectors preallocated, read as zero, bs->file not
71
+ * t t t sectors read as zero, returned file is zero at offset
72
+ * t f t sectors read as valid from file at offset
73
+ * f t t sectors preallocated, read as zero, returned file not
74
* necessarily zero at offset
75
* f f t sectors preallocated but read from backing_hd,
76
- * bs->file contains garbage at offset
77
+ * returned file contains garbage at offset
78
* t t f sectors preallocated, read as zero, unknown offset
79
* t f f sectors read from unknown file or offset
80
* f t f not allocated or unknown offset, read as zero
81
diff --git a/include/block/block_int.h b/include/block/block_int.h
82
index XXXXXXX..XXXXXXX 100644
83
--- a/include/block/block_int.h
84
+++ b/include/block/block_int.h
85
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
86
int64_t offset, int count, BdrvRequestFlags flags);
87
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
88
int64_t offset, int count);
89
+
90
+ /*
91
+ * Building block for bdrv_block_status[_above]. The driver should
92
+ * answer only according to the current layer, and should not
93
+ * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h
94
+ * for the meaning of _DATA, _ZERO, and _OFFSET_VALID.
95
+ */
96
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
97
int64_t sector_num, int nb_sectors, int *pnum,
98
BlockDriverState **file);
99
--
176
--
100
1.8.3.1
177
2.13.6
101
178
102
179
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
Add a subtree drain version to the existing test cases.
2
2
3
Add --force-share/-U to program options and -U to open subcommand.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
4
---
8
qemu-io.c | 42 ++++++++++++++++++++++++++++++++++--------
5
tests/test-bdrv-drain.c | 27 ++++++++++++++++++++++++++-
9
1 file changed, 34 insertions(+), 8 deletions(-)
6
1 file changed, 26 insertions(+), 1 deletion(-)
10
7
11
diff --git a/qemu-io.c b/qemu-io.c
8
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
12
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
13
--- a/qemu-io.c
10
--- a/tests/test-bdrv-drain.c
14
+++ b/qemu-io.c
11
+++ b/tests/test-bdrv-drain.c
15
@@ -XXX,XX +XXX,XX @@
12
@@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret)
16
#include "qemu/readline.h"
13
enum drain_type {
17
#include "qemu/log.h"
14
BDRV_DRAIN_ALL,
18
#include "qapi/qmp/qstring.h"
15
BDRV_DRAIN,
19
+#include "qapi/qmp/qbool.h"
16
+ BDRV_SUBTREE_DRAIN,
20
#include "qom/object_interfaces.h"
17
DRAIN_TYPE_MAX,
21
#include "sysemu/block-backend.h"
22
#include "block/block_int.h"
23
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t close_cmd = {
24
.oneline = "close the current open file",
25
};
18
};
26
19
27
-static int openfile(char *name, int flags, bool writethrough, QDict *opts)
20
@@ -XXX,XX +XXX,XX @@ static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs)
28
+static int openfile(char *name, int flags, bool writethrough, bool force_share,
21
switch (drain_type) {
29
+ QDict *opts)
22
case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break;
23
case BDRV_DRAIN: bdrv_drained_begin(bs); break;
24
+ case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_begin(bs); break;
25
default: g_assert_not_reached();
26
}
27
}
28
@@ -XXX,XX +XXX,XX @@ static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs)
29
switch (drain_type) {
30
case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break;
31
case BDRV_DRAIN: bdrv_drained_end(bs); break;
32
+ case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_end(bs); break;
33
default: g_assert_not_reached();
34
}
35
}
36
@@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void)
37
test_drv_cb_common(BDRV_DRAIN, false);
38
}
39
40
+static void test_drv_cb_drain_subtree(void)
41
+{
42
+ test_drv_cb_common(BDRV_SUBTREE_DRAIN, true);
43
+}
44
+
45
static void test_quiesce_common(enum drain_type drain_type, bool recursive)
30
{
46
{
31
Error *local_err = NULL;
47
BlockBackend *blk;
32
BlockDriverState *bs;
48
@@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void)
33
@@ -XXX,XX +XXX,XX @@ static int openfile(char *name, int flags, bool writethrough, QDict *opts)
49
test_quiesce_common(BDRV_DRAIN, false);
34
return 1;
50
}
35
}
51
36
52
+static void test_quiesce_drain_subtree(void)
37
+ if (force_share) {
53
+{
38
+ if (!opts) {
54
+ test_quiesce_common(BDRV_SUBTREE_DRAIN, true);
39
+ opts = qdict_new();
55
+}
40
+ }
56
+
41
+ if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
57
static void test_nested(void)
42
+ && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
58
{
43
+ error_report("-U conflicts with image options");
59
BlockBackend *blk;
44
+ QDECREF(opts);
60
@@ -XXX,XX +XXX,XX @@ static void test_nested(void)
45
+ return 1;
61
/* XXX bdrv_drain_all() doesn't increase the quiesce_counter */
46
+ }
62
int bs_quiesce = (outer != BDRV_DRAIN_ALL) +
47
+ qdict_put(opts, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
63
(inner != BDRV_DRAIN_ALL);
48
+ }
64
- int backing_quiesce = 0;
49
qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err);
65
+ int backing_quiesce = (outer == BDRV_SUBTREE_DRAIN) +
50
if (!qemuio_blk) {
66
+ (inner == BDRV_SUBTREE_DRAIN);
51
error_reportf_err(local_err, "can't open%s%s: ",
67
int backing_cb_cnt = (outer != BDRV_DRAIN) +
52
@@ -XXX,XX +XXX,XX @@ static void open_help(void)
68
(inner != BDRV_DRAIN);
53
" -r, -- open file read-only\n"
69
54
" -s, -- use snapshot file\n"
70
@@ -XXX,XX +XXX,XX @@ static void test_blockjob_drain(void)
55
" -n, -- disable host cache, short for -t none\n"
71
test_blockjob_common(BDRV_DRAIN);
56
+" -U, -- force shared permissions\n"
72
}
57
" -k, -- use kernel AIO implementation (on Linux only)\n"
73
58
" -t, -- use the given cache mode for the image\n"
74
+static void test_blockjob_drain_subtree(void)
59
" -d, -- use the given discard mode for the image\n"
75
+{
60
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t open_cmd = {
76
+ test_blockjob_common(BDRV_SUBTREE_DRAIN);
61
.argmin = 1,
77
+}
62
.argmax = -1,
78
+
63
.flags = CMD_NOFILE_OK,
64
- .args = "[-rsnk] [-t cache] [-d discard] [-o options] [path]",
65
+ .args = "[-rsnkU] [-t cache] [-d discard] [-o options] [path]",
66
.oneline = "open the file specified by path",
67
.help = open_help,
68
};
69
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
70
int c;
71
QemuOpts *qopts;
72
QDict *opts;
73
+ bool force_share = false;
74
75
- while ((c = getopt(argc, argv, "snro:kt:d:")) != -1) {
76
+ while ((c = getopt(argc, argv, "snro:kt:d:U")) != -1) {
77
switch (c) {
78
case 's':
79
flags |= BDRV_O_SNAPSHOT;
80
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
81
return 0;
82
}
83
break;
84
+ case 'U':
85
+ force_share = true;
86
+ break;
87
default:
88
qemu_opts_reset(&empty_opts);
89
return qemuio_command_usage(&open_cmd);
90
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
91
qemu_opts_reset(&empty_opts);
92
93
if (optind == argc - 1) {
94
- return openfile(argv[optind], flags, writethrough, opts);
95
+ return openfile(argv[optind], flags, writethrough, force_share, opts);
96
} else if (optind == argc) {
97
- return openfile(NULL, flags, writethrough, opts);
98
+ return openfile(NULL, flags, writethrough, force_share, opts);
99
} else {
100
QDECREF(opts);
101
return qemuio_command_usage(&open_cmd);
102
@@ -XXX,XX +XXX,XX @@ static void usage(const char *name)
103
" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
104
" specify tracing options\n"
105
" see qemu-img(1) man page for full description\n"
106
+" -U, --force-share force shared permissions\n"
107
" -h, --help display this help and exit\n"
108
" -V, --version output version information and exit\n"
109
"\n"
110
@@ -XXX,XX +XXX,XX @@ static QemuOptsList file_opts = {
111
int main(int argc, char **argv)
79
int main(int argc, char **argv)
112
{
80
{
113
int readonly = 0;
81
bdrv_init();
114
- const char *sopt = "hVc:d:f:rsnmkt:T:";
115
+ const char *sopt = "hVc:d:f:rsnmkt:T:U";
116
const struct option lopt[] = {
117
{ "help", no_argument, NULL, 'h' },
118
{ "version", no_argument, NULL, 'V' },
119
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
82
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
120
{ "trace", required_argument, NULL, 'T' },
83
121
{ "object", required_argument, NULL, OPTION_OBJECT },
84
g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all);
122
{ "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
85
g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain);
123
+ { "force-share", no_argument, 0, 'U'},
86
+ g_test_add_func("/bdrv-drain/driver-cb/drain_subtree",
124
{ NULL, 0, NULL, 0 }
87
+ test_drv_cb_drain_subtree);
125
};
88
126
int c;
89
g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all);
127
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
90
g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain);
128
QDict *opts = NULL;
91
+ g_test_add_func("/bdrv-drain/quiesce/drain_subtree",
129
const char *format = NULL;
92
+ test_quiesce_drain_subtree);
130
char *trace_file = NULL;
93
131
+ bool force_share = false;
94
g_test_add_func("/bdrv-drain/nested", test_nested);
132
95
133
#ifdef CONFIG_POSIX
96
g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
134
signal(SIGPIPE, SIG_IGN);
97
g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain);
135
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
98
+ g_test_add_func("/bdrv-drain/blockjob/drain_subtree",
136
case 'h':
99
+ test_blockjob_drain_subtree);
137
usage(progname);
100
138
exit(0);
101
return g_test_run();
139
+ case 'U':
102
}
140
+ force_share = true;
141
+ break;
142
case OPTION_OBJECT: {
143
QemuOpts *qopts;
144
qopts = qemu_opts_parse_noisily(&qemu_object_opts,
145
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
146
exit(1);
147
}
148
opts = qemu_opts_to_qdict(qopts, NULL);
149
- if (openfile(NULL, flags, writethrough, opts)) {
150
+ if (openfile(NULL, flags, writethrough, force_share, opts)) {
151
exit(1);
152
}
153
} else {
154
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
155
opts = qdict_new();
156
qdict_put_str(opts, "driver", format);
157
}
158
- if (openfile(argv[optind], flags, writethrough, opts)) {
159
+ if (openfile(argv[optind], flags, writethrough,
160
+ force_share, opts)) {
161
exit(1);
162
}
163
}
164
--
103
--
165
1.8.3.1
104
2.13.6
166
105
167
106
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
qemu-img and qemu-io commands when guest is running need "-U" option,
4
add it.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
tests/qemu-iotests/030 | 18 +++++++++---------
10
1 file changed, 9 insertions(+), 9 deletions(-)
11
12
diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/030
15
+++ b/tests/qemu-iotests/030
16
@@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase):
17
def test_stream_intermediate(self):
18
self.assert_no_active_block_jobs()
19
20
- self.assertNotEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img),
21
- qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img),
22
+ self.assertNotEqual(qemu_io('-f', 'raw', '-rU', '-c', 'map', backing_img),
23
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', mid_img),
24
'image file map matches backing file before streaming')
25
26
result = self.vm.qmp('block-stream', device='mid', job_id='stream-mid')
27
@@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase):
28
self.assert_no_active_block_jobs()
29
30
# The image map is empty before the operation
31
- empty_map = qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img)
32
+ empty_map = qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', test_img)
33
34
# This is a no-op: no data should ever be copied from the base image
35
result = self.vm.qmp('block-stream', device='drive0', base=mid_img)
36
@@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase):
37
38
# Check that the maps don't match before the streaming operations
39
for i in range(2, self.num_imgs, 2):
40
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i]),
41
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i-1]),
42
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i]),
43
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i-1]),
44
'image file map matches backing file before streaming')
45
46
# Create all streaming jobs
47
@@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase):
48
def test_stream_base_node_name(self):
49
self.assert_no_active_block_jobs()
50
51
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[4]),
52
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[3]),
53
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[4]),
54
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[3]),
55
'image file map matches backing file before streaming')
56
57
# Error: the base node does not exist
58
@@ -XXX,XX +XXX,XX @@ class TestQuorum(iotests.QMPTestCase):
59
if not iotests.supports_quorum():
60
return
61
62
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.children[0]),
63
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.backing[0]),
64
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.children[0]),
65
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.backing[0]),
66
'image file map matches backing file before streaming')
67
68
self.assert_no_active_block_jobs()
69
--
70
1.8.3.1
71
72
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The qemu-img info command is executed while VM is running, add -U option
4
to avoid the image locking error.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
tests/qemu-iotests/046 | 2 +-
10
1 file changed, 1 insertion(+), 1 deletion(-)
11
12
diff --git a/tests/qemu-iotests/046 b/tests/qemu-iotests/046
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/046
15
+++ b/tests/qemu-iotests/046
16
@@ -XXX,XX +XXX,XX @@ echo "== Verify image content =="
17
18
function verify_io()
19
{
20
- if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
21
+ if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
22
# For v2 images, discarded clusters are read from the backing file
23
# Keep the variable empty so that the backing file value can be used as
24
# the default below
25
--
26
1.8.3.1
27
28
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Double attach is not a valid usage of the target image, drive-backup
4
will open the blockdev itself so skip the add_drive call in this case.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
tests/qemu-iotests/055 | 32 ++++++++++++++++++--------------
11
1 file changed, 18 insertions(+), 14 deletions(-)
12
13
diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
14
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/055
16
+++ b/tests/qemu-iotests/055
17
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
18
except OSError:
19
pass
20
21
- def do_prepare_drives(self, fmt, args):
22
+ def do_prepare_drives(self, fmt, args, attach_target):
23
self.vm = iotests.VM().add_drive(test_img)
24
25
qemu_img('create', '-f', fmt, blockdev_target_img,
26
str(TestDriveCompression.image_len), *args)
27
- self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
28
+ if attach_target:
29
+ self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
30
31
self.vm.launch()
32
33
- def do_test_compress_complete(self, cmd, format, **args):
34
- self.do_prepare_drives(format['type'], format['args'])
35
+ def do_test_compress_complete(self, cmd, format, attach_target, **args):
36
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
37
38
self.assert_no_active_block_jobs()
39
40
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
41
42
def test_complete_compress_drive_backup(self):
43
for format in TestDriveCompression.fmt_supports_compression:
44
- self.do_test_compress_complete('drive-backup', format,
45
+ self.do_test_compress_complete('drive-backup', format, False,
46
target=blockdev_target_img, mode='existing')
47
48
def test_complete_compress_blockdev_backup(self):
49
for format in TestDriveCompression.fmt_supports_compression:
50
- self.do_test_compress_complete('blockdev-backup', format, target='drive1')
51
+ self.do_test_compress_complete('blockdev-backup', format, True,
52
+ target='drive1')
53
54
- def do_test_compress_cancel(self, cmd, format, **args):
55
- self.do_prepare_drives(format['type'], format['args'])
56
+ def do_test_compress_cancel(self, cmd, format, attach_target, **args):
57
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
58
59
self.assert_no_active_block_jobs()
60
61
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
62
63
def test_compress_cancel_drive_backup(self):
64
for format in TestDriveCompression.fmt_supports_compression:
65
- self.do_test_compress_cancel('drive-backup', format,
66
+ self.do_test_compress_cancel('drive-backup', format, False,
67
target=blockdev_target_img, mode='existing')
68
69
def test_compress_cancel_blockdev_backup(self):
70
for format in TestDriveCompression.fmt_supports_compression:
71
- self.do_test_compress_cancel('blockdev-backup', format, target='drive1')
72
+ self.do_test_compress_cancel('blockdev-backup', format, True,
73
+ target='drive1')
74
75
- def do_test_compress_pause(self, cmd, format, **args):
76
- self.do_prepare_drives(format['type'], format['args'])
77
+ def do_test_compress_pause(self, cmd, format, attach_target, **args):
78
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
79
80
self.assert_no_active_block_jobs()
81
82
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
83
84
def test_compress_pause_drive_backup(self):
85
for format in TestDriveCompression.fmt_supports_compression:
86
- self.do_test_compress_pause('drive-backup', format,
87
+ self.do_test_compress_pause('drive-backup', format, False,
88
target=blockdev_target_img, mode='existing')
89
90
def test_compress_pause_blockdev_backup(self):
91
for format in TestDriveCompression.fmt_supports_compression:
92
- self.do_test_compress_pause('blockdev-backup', format, target='drive1')
93
+ self.do_test_compress_pause('blockdev-backup', format, True,
94
+ target='drive1')
95
96
if __name__ == '__main__':
97
iotests.main(supported_fmts=['raw', 'qcow2'])
98
--
99
1.8.3.1
100
101
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The test scenario doesn't require the same image, instead it focuses on
4
the duplicated node-name, so use null-co to avoid locking conflict.
5
6
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Fam Zheng <famz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
tests/qemu-iotests/087 | 6 ++----
11
1 file changed, 2 insertions(+), 4 deletions(-)
12
13
diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087
14
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/087
16
+++ b/tests/qemu-iotests/087
17
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
18
"driver": "$IMGFMT",
19
"node-name": "disk",
20
"file": {
21
- "driver": "file",
22
- "filename": "$TEST_IMG"
23
+ "driver": "null-co"
24
}
25
}
26
}
27
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
28
"driver": "$IMGFMT",
29
"node-name": "test-node",
30
"file": {
31
- "driver": "file",
32
- "filename": "$TEST_IMG"
33
+ "driver": "null-co"
34
}
35
}
36
}
37
--
38
1.8.3.1
39
40
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
7
tests/qemu-iotests/091 | 2 ++
8
1 file changed, 2 insertions(+)
9
10
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
11
index XXXXXXX..XXXXXXX 100755
12
--- a/tests/qemu-iotests/091
13
+++ b/tests/qemu-iotests/091
14
@@ -XXX,XX +XXX,XX @@ echo "vm2: qemu process running successfully"
15
echo "vm2: flush io, and quit"
16
_send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)"
17
_send_qemu_cmd $h2 'quit' ""
18
+_send_qemu_cmd $h1 'quit' ""
19
20
+wait
21
echo "Check image pattern"
22
${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io
23
24
--
25
1.8.3.1
26
27
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
To avoid image lock failures.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
tests/qemu-iotests/172 | 55 +++++++++++++++++++++++++---------------------
9
tests/qemu-iotests/172.out | 50 +++++++++++++++++++++--------------------
10
2 files changed, 56 insertions(+), 49 deletions(-)
11
12
diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/172
15
+++ b/tests/qemu-iotests/172
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
17
_cleanup()
18
{
19
    _cleanup_test_img
20
+ rm -f "$TEST_IMG.2"
21
+ rm -f "$TEST_IMG.3"
22
}
23
trap "_cleanup; exit \$status" 0 1 2 3 15
24
25
@@ -XXX,XX +XXX,XX @@ size=720k
26
27
_make_test_img $size
28
29
+TEST_IMG="$TEST_IMG.2" _make_test_img $size
30
+TEST_IMG="$TEST_IMG.3" _make_test_img $size
31
+
32
# Default drive semantics:
33
#
34
# By default you get a single empty floppy drive. You can override it with
35
@@ -XXX,XX +XXX,XX @@ echo === Using -fda/-fdb options ===
36
37
check_floppy_qtree -fda "$TEST_IMG"
38
check_floppy_qtree -fdb "$TEST_IMG"
39
-check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG"
40
+check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
41
42
43
echo
44
@@ -XXX,XX +XXX,XX @@ echo === Using -drive options ===
45
46
check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
47
check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
48
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG",index=1
49
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
50
51
echo
52
echo
53
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -global ===
54
55
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
56
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
57
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
58
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
59
-global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
60
61
echo
62
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -device ===
63
64
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
65
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
66
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
67
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
68
-device floppy,drive=none0 -device floppy,drive=none1,unit=1
69
70
echo
71
@@ -XXX,XX +XXX,XX @@ echo
72
echo === Mixing -fdX and -global ===
73
74
# Working
75
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
76
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
77
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
78
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
79
80
# Conflicting (-fdX wins)
81
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
82
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
83
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
84
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
85
86
echo
87
echo
88
echo === Mixing -fdX and -device ===
89
90
# Working
91
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
92
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
93
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
94
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
95
96
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
97
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
98
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
99
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
100
101
# Conflicting
102
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
103
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
104
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
105
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
106
107
echo
108
echo
109
echo === Mixing -drive and -device ===
110
111
# Working
112
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
113
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
114
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
115
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
116
117
# Conflicting
118
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
119
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
120
121
echo
122
echo
123
echo === Mixing -global and -device ===
124
125
# Working
126
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
127
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
128
-global isa-fdc.driveA=none0 -device floppy,drive=none1
129
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
130
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
131
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
132
133
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
134
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
135
-global isa-fdc.driveB=none0 -device floppy,drive=none1
136
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
137
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
138
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
139
140
# Conflicting
141
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
142
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
143
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
144
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
145
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
146
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
147
148
echo
149
@@ -XXX,XX +XXX,XX @@ echo === Too many floppy drives ===
150
151
# Working
152
check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
153
- -drive if=none,file="$TEST_IMG" \
154
- -drive if=none,file="$TEST_IMG" \
155
+ -drive if=none,file="$TEST_IMG.2" \
156
+ -drive if=none,file="$TEST_IMG.3" \
157
-global isa-fdc.driveB=none0 \
158
-device floppy,drive=none1
159
160
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
161
index XXXXXXX..XXXXXXX 100644
162
--- a/tests/qemu-iotests/172.out
163
+++ b/tests/qemu-iotests/172.out
164
@@ -XXX,XX +XXX,XX @@
165
QA output created by 172
166
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=737280
167
+Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=737280
168
+Formatting 'TEST_DIR/t.IMGFMT.3', fmt=IMGFMT size=737280
169
170
171
=== Default ===
172
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
173
share-rw = false
174
drive-type = "288"
175
176
-Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2
177
+Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
178
179
dev: isa-fdc, id ""
180
iobase = 1008 (0x3f0)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
182
share-rw = false
183
drive-type = "288"
184
185
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
186
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2.2,index=1
187
188
dev: isa-fdc, id ""
189
iobase = 1008 (0x3f0)
190
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
191
share-rw = false
192
drive-type = "144"
193
194
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
195
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
196
197
dev: isa-fdc, id ""
198
iobase = 1008 (0x3f0)
199
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
200
share-rw = false
201
drive-type = "144"
202
203
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
204
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
205
206
dev: isa-fdc, id ""
207
iobase = 1008 (0x3f0)
208
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
209
210
=== Mixing -fdX and -global ===
211
212
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
213
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
214
215
dev: isa-fdc, id ""
216
iobase = 1008 (0x3f0)
217
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
218
share-rw = false
219
drive-type = "144"
220
221
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
222
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
223
224
dev: isa-fdc, id ""
225
iobase = 1008 (0x3f0)
226
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
227
share-rw = false
228
drive-type = "144"
229
230
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
231
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
232
233
dev: isa-fdc, id ""
234
iobase = 1008 (0x3f0)
235
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
236
share-rw = false
237
drive-type = "144"
238
239
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
240
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
241
242
dev: isa-fdc, id ""
243
iobase = 1008 (0x3f0)
244
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
245
246
=== Mixing -fdX and -device ===
247
248
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
249
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
250
251
dev: isa-fdc, id ""
252
iobase = 1008 (0x3f0)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
254
share-rw = false
255
drive-type = "144"
256
257
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
258
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
259
260
dev: isa-fdc, id ""
261
iobase = 1008 (0x3f0)
262
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
263
share-rw = false
264
drive-type = "144"
265
266
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
267
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
268
269
dev: isa-fdc, id ""
270
iobase = 1008 (0x3f0)
271
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
272
share-rw = false
273
drive-type = "144"
274
275
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
276
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
277
278
dev: isa-fdc, id ""
279
iobase = 1008 (0x3f0)
280
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
281
share-rw = false
282
drive-type = "144"
283
284
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
285
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
286
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
287
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
288
289
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
290
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
291
QEMU_PROG: -device floppy,drive=none0,unit=1: Floppy unit 1 is in use
292
QEMU_PROG: -device floppy,drive=none0,unit=1: Device initialization failed.
293
294
295
=== Mixing -drive and -device ===
296
297
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
298
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
299
300
dev: isa-fdc, id ""
301
iobase = 1008 (0x3f0)
302
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
303
share-rw = false
304
drive-type = "144"
305
306
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
307
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
308
309
dev: isa-fdc, id ""
310
iobase = 1008 (0x3f0)
311
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
312
share-rw = false
313
drive-type = "144"
314
315
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
316
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
317
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
318
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
319
320
321
=== Mixing -global and -device ===
322
323
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
324
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
325
326
dev: isa-fdc, id ""
327
iobase = 1008 (0x3f0)
328
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
329
share-rw = false
330
drive-type = "144"
331
332
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
333
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
334
335
dev: isa-fdc, id ""
336
iobase = 1008 (0x3f0)
337
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
338
share-rw = false
339
drive-type = "144"
340
341
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
342
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
343
344
dev: isa-fdc, id ""
345
iobase = 1008 (0x3f0)
346
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
347
share-rw = false
348
drive-type = "144"
349
350
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
351
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
352
353
dev: isa-fdc, id ""
354
iobase = 1008 (0x3f0)
355
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
356
share-rw = false
357
drive-type = "144"
358
359
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
360
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
361
QEMU_PROG: -device floppy,drive=none1,unit=0: Floppy unit 0 is in use
362
QEMU_PROG: -device floppy,drive=none1,unit=0: Device initialization failed.
363
364
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
365
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
366
QEMU_PROG: -device floppy,drive=none1,unit=1: Floppy unit 1 is in use
367
QEMU_PROG: -device floppy,drive=none1,unit=1: Device initialization failed.
368
369
370
=== Too many floppy drives ===
371
372
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
373
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -drive if=none,file=TEST_DIR/t.qcow2.3 -global isa-fdc.driveB=none0 -device floppy,drive=none1
374
QEMU_PROG: -device floppy,drive=none1: Can't create floppy unit 2, bus supports only 2 units
375
QEMU_PROG: -device floppy,drive=none1: Device initialization failed.
376
377
--
378
1.8.3.1
379
380
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
7
tests/drive_del-test.c | 2 +-
8
tests/nvme-test.c | 2 +-
9
tests/usb-hcd-uhci-test.c | 2 +-
10
tests/usb-hcd-xhci-test.c | 2 +-
11
tests/virtio-blk-test.c | 2 +-
12
tests/virtio-scsi-test.c | 5 +++--
13
6 files changed, 8 insertions(+), 7 deletions(-)
14
15
diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/drive_del-test.c
18
+++ b/tests/drive_del-test.c
19
@@ -XXX,XX +XXX,XX @@ static void test_after_failed_device_add(void)
20
static void test_drive_del_device_del(void)
21
{
22
/* Start with a drive used by a device that unplugs instantaneously */
23
- qtest_start("-drive if=none,id=drive0,file=/dev/null,format=raw"
24
+ qtest_start("-drive if=none,id=drive0,file=null-co://,format=raw"
25
" -device virtio-scsi-pci"
26
" -device scsi-hd,drive=drive0,id=dev0");
27
28
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/tests/nvme-test.c
31
+++ b/tests/nvme-test.c
32
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
33
g_test_init(&argc, &argv, NULL);
34
qtest_add_func("/nvme/nop", nop);
35
36
- qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
37
+ qtest_start("-drive id=drv0,if=none,file=null-co://,format=raw "
38
"-device nvme,drive=drv0,serial=foo");
39
ret = g_test_run();
40
41
diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/tests/usb-hcd-uhci-test.c
44
+++ b/tests/usb-hcd-uhci-test.c
45
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
46
{
47
const char *arch = qtest_get_arch();
48
const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
49
- " -drive id=drive0,if=none,file=/dev/null,format=raw"
50
+ " -drive id=drive0,if=none,file=null-co://,format=raw"
51
" -device usb-tablet,bus=uhci.0,port=1";
52
int ret;
53
54
diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/tests/usb-hcd-xhci-test.c
57
+++ b/tests/usb-hcd-xhci-test.c
58
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
59
qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
60
61
qtest_start("-device nec-usb-xhci,id=xhci"
62
- " -drive id=drive0,if=none,file=/dev/null,format=raw");
63
+ " -drive id=drive0,if=none,file=null-co://,format=raw");
64
ret = g_test_run();
65
qtest_end();
66
67
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/tests/virtio-blk-test.c
70
+++ b/tests/virtio-blk-test.c
71
@@ -XXX,XX +XXX,XX @@ static QOSState *pci_test_start(void)
72
const char *arch = qtest_get_arch();
73
char *tmp_path;
74
const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
75
- "-drive if=none,id=drive1,file=/dev/null,format=raw "
76
+ "-drive if=none,id=drive1,file=null-co://,format=raw "
77
"-device virtio-blk-pci,id=drv0,drive=drive0,"
78
"addr=%x.%x";
79
80
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/tests/virtio-scsi-test.c
83
+++ b/tests/virtio-scsi-test.c
84
@@ -XXX,XX +XXX,XX @@ typedef struct {
85
static QOSState *qvirtio_scsi_start(const char *extra_opts)
86
{
87
const char *arch = qtest_get_arch();
88
- const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw "
89
+ const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
90
"-device virtio-scsi-pci,id=vs0 "
91
"-device scsi-hd,bus=vs0.0,drive=drv0 %s";
92
93
@@ -XXX,XX +XXX,XX @@ static void hotplug(void)
94
QDict *response;
95
QOSState *qs;
96
97
- qs = qvirtio_scsi_start("-drive id=drv1,if=none,file=/dev/null,format=raw");
98
+ qs = qvirtio_scsi_start(
99
+ "-drive id=drv1,if=none,file=null-co://,format=raw");
100
response = qmp("{\"execute\": \"device_add\","
101
" \"arguments\": {"
102
" \"driver\": \"scsi-hd\","
103
--
104
1.8.3.1
105
106
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
We share the same set of QAPI options with file-posix, but locking is
4
not supported here. So error out if it is specified as 'on' for now.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
block/file-win32.c | 5 +++++
10
1 file changed, 5 insertions(+)
11
12
diff --git a/block/file-win32.c b/block/file-win32.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block/file-win32.c
15
+++ b/block/file-win32.c
16
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
17
goto fail;
18
}
19
20
+ if (qdict_get_try_bool(options, "locking", false)) {
21
+ error_setg(errp, "locking=on is not supported on Windows");
22
+ goto fail;
23
+ }
24
+
25
filename = qemu_opt_get(opts, "filename");
26
27
use_aio = get_aio_option(opts, flags, &local_err);
28
--
29
1.8.3.1
30
31
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The COLO block replication architecture requires one disk to be shared
4
between primary and secondary, in the test both processes use posix file
5
protocol (instead of over NBD) so it is affected by image locking.
6
Disable the lock.
7
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
tests/test-replication.c | 9 +++++++--
12
1 file changed, 7 insertions(+), 2 deletions(-)
13
14
diff --git a/tests/test-replication.c b/tests/test-replication.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/tests/test-replication.c
17
+++ b/tests/test-replication.c
18
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_primary(void)
19
char *cmdline;
20
21
cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx,"
22
- "file.driver=qcow2,file.file.filename=%s"
23
+ "file.driver=qcow2,file.file.filename=%s,"
24
+ "file.file.locking=off"
25
, p_local_disk);
26
opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false);
27
g_free(cmdline);
28
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_secondary(void)
29
Error *local_err = NULL;
30
31
/* add s_local_disk and forge S_LOCAL_DISK_ID */
32
- cmdline = g_strdup_printf("file.filename=%s,driver=qcow2", s_local_disk);
33
+ cmdline = g_strdup_printf("file.filename=%s,driver=qcow2,"
34
+ "file.locking=off",
35
+ s_local_disk);
36
opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false);
37
g_free(cmdline);
38
39
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_secondary(void)
40
/* add S_(ACTIVE/HIDDEN)_DISK and forge S_ID */
41
cmdline = g_strdup_printf("driver=replication,mode=secondary,top-id=%s,"
42
"file.driver=qcow2,file.file.filename=%s,"
43
+ "file.file.locking=off,"
44
"file.backing.driver=qcow2,"
45
"file.backing.file.filename=%s,"
46
+ "file.backing.file.locking=off,"
47
"file.backing.backing=%s"
48
, S_ID, s_active_disk, s_hidden_disk
49
, S_LOCAL_DISK_ID);
50
--
51
1.8.3.1
52
53
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
If bdrv_do_drained_begin/end() are called in coroutine context, they
2
first use a BH to get out of the coroutine context. Call some existing
3
tests again from a coroutine to cover this code path.
2
4
3
This extends the permission bits of op blocker API to external using
4
Linux OFD locks.
5
6
Each permission in @perm and @shared_perm is represented by a locked
7
byte in the image file. Requesting a permission in @perm is translated
8
to a shared lock of the corresponding byte; rejecting to share the same
9
permission is translated to a shared lock of a separate byte. With that,
10
we use 2x number of bytes of distinct permission types.
11
12
virtlockd in libvirt locks the first byte, so we do locking from a
13
higher offset.
14
15
Suggested-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Fam Zheng <famz@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
6
---
19
block/file-posix.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
7
tests/test-bdrv-drain.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
20
1 file changed, 275 insertions(+), 1 deletion(-)
8
1 file changed, 59 insertions(+)
21
9
22
diff --git a/block/file-posix.c b/block/file-posix.c
10
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
23
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
24
--- a/block/file-posix.c
12
--- a/tests/test-bdrv-drain.c
25
+++ b/block/file-posix.c
13
+++ b/tests/test-bdrv-drain.c
26
@@ -XXX,XX +XXX,XX @@ do { \
14
@@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret)
27
15
*aio_ret = ret;
28
#define MAX_BLOCKSIZE    4096
16
}
29
17
30
+/* Posix file locking bytes. Libvirt takes byte 0, we start from higher bytes,
18
+typedef struct CallInCoroutineData {
31
+ * leaving a few more bytes for its future use. */
19
+ void (*entry)(void);
32
+#define RAW_LOCK_PERM_BASE 100
20
+ bool done;
33
+#define RAW_LOCK_SHARED_BASE 200
21
+} CallInCoroutineData;
34
+
22
+
35
typedef struct BDRVRawState {
23
+static coroutine_fn void call_in_coroutine_entry(void *opaque)
36
int fd;
24
+{
37
+ int lock_fd;
25
+ CallInCoroutineData *data = opaque;
38
+ bool use_lock;
39
int type;
40
int open_flags;
41
size_t buf_align;
42
43
+ /* The current permissions. */
44
+ uint64_t perm;
45
+ uint64_t shared_perm;
46
+
26
+
47
#ifdef CONFIG_XFS
27
+ data->entry();
48
bool is_xfs:1;
28
+ data->done = true;
49
#endif
50
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
51
BlockdevAioOptions aio, aio_default;
52
int fd, ret;
53
struct stat st;
54
+ OnOffAuto locking;
55
56
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
57
qemu_opts_absorb_qdict(opts, options, &local_err);
58
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
59
}
60
s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
61
62
+ locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
63
+ ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err);
64
+ if (local_err) {
65
+ error_propagate(errp, local_err);
66
+ ret = -EINVAL;
67
+ goto fail;
68
+ }
69
+ switch (locking) {
70
+ case ON_OFF_AUTO_ON:
71
+ s->use_lock = true;
72
+#ifndef F_OFD_SETLK
73
+ fprintf(stderr,
74
+ "File lock requested but OFD locking syscall is unavailable, "
75
+ "falling back to POSIX file locks.\n"
76
+ "Due to the implementation, locks can be lost unexpectedly.\n");
77
+#endif
78
+ break;
79
+ case ON_OFF_AUTO_OFF:
80
+ s->use_lock = false;
81
+ break;
82
+ case ON_OFF_AUTO_AUTO:
83
+#ifdef F_OFD_SETLK
84
+ s->use_lock = true;
85
+#else
86
+ s->use_lock = false;
87
+#endif
88
+ break;
89
+ default:
90
+ abort();
91
+ }
92
+
93
s->open_flags = open_flags;
94
raw_parse_flags(bdrv_flags, &s->open_flags);
95
96
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
97
}
98
s->fd = fd;
99
100
+ s->lock_fd = -1;
101
+ if (s->use_lock) {
102
+ fd = qemu_open(filename, s->open_flags);
103
+ if (fd < 0) {
104
+ ret = -errno;
105
+ error_setg_errno(errp, errno, "Could not open '%s' for locking",
106
+ filename);
107
+ qemu_close(s->fd);
108
+ goto fail;
109
+ }
110
+ s->lock_fd = fd;
111
+ }
112
+ s->perm = 0;
113
+ s->shared_perm = BLK_PERM_ALL;
114
+
115
#ifdef CONFIG_LINUX_AIO
116
/* Currently Linux does AIO only for files opened with O_DIRECT */
117
if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) {
118
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
119
return raw_open_common(bs, options, flags, 0, errp);
120
}
121
122
+typedef enum {
123
+ RAW_PL_PREPARE,
124
+ RAW_PL_COMMIT,
125
+ RAW_PL_ABORT,
126
+} RawPermLockOp;
127
+
128
+#define PERM_FOREACH(i) \
129
+ for ((i) = 0; (1ULL << (i)) <= BLK_PERM_ALL; i++)
130
+
131
+/* Lock bytes indicated by @perm_lock_bits and @shared_perm_lock_bits in the
132
+ * file; if @unlock == true, also unlock the unneeded bytes.
133
+ * @shared_perm_lock_bits is the mask of all permissions that are NOT shared.
134
+ */
135
+static int raw_apply_lock_bytes(BDRVRawState *s,
136
+ uint64_t perm_lock_bits,
137
+ uint64_t shared_perm_lock_bits,
138
+ bool unlock, Error **errp)
139
+{
140
+ int ret;
141
+ int i;
142
+
143
+ PERM_FOREACH(i) {
144
+ int off = RAW_LOCK_PERM_BASE + i;
145
+ if (perm_lock_bits & (1ULL << i)) {
146
+ ret = qemu_lock_fd(s->lock_fd, off, 1, false);
147
+ if (ret) {
148
+ error_setg(errp, "Failed to lock byte %d", off);
149
+ return ret;
150
+ }
151
+ } else if (unlock) {
152
+ ret = qemu_unlock_fd(s->lock_fd, off, 1);
153
+ if (ret) {
154
+ error_setg(errp, "Failed to unlock byte %d", off);
155
+ return ret;
156
+ }
157
+ }
158
+ }
159
+ PERM_FOREACH(i) {
160
+ int off = RAW_LOCK_SHARED_BASE + i;
161
+ if (shared_perm_lock_bits & (1ULL << i)) {
162
+ ret = qemu_lock_fd(s->lock_fd, off, 1, false);
163
+ if (ret) {
164
+ error_setg(errp, "Failed to lock byte %d", off);
165
+ return ret;
166
+ }
167
+ } else if (unlock) {
168
+ ret = qemu_unlock_fd(s->lock_fd, off, 1);
169
+ if (ret) {
170
+ error_setg(errp, "Failed to unlock byte %d", off);
171
+ return ret;
172
+ }
173
+ }
174
+ }
175
+ return 0;
176
+}
29
+}
177
+
30
+
178
+/* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. */
31
+static void call_in_coroutine(void (*entry)(void))
179
+static int raw_check_lock_bytes(BDRVRawState *s,
180
+ uint64_t perm, uint64_t shared_perm,
181
+ Error **errp)
182
+{
32
+{
183
+ int ret;
33
+ Coroutine *co;
184
+ int i;
34
+ CallInCoroutineData data = {
35
+ .entry = entry,
36
+ .done = false,
37
+ };
185
+
38
+
186
+ PERM_FOREACH(i) {
39
+ co = qemu_coroutine_create(call_in_coroutine_entry, &data);
187
+ int off = RAW_LOCK_SHARED_BASE + i;
40
+ qemu_coroutine_enter(co);
188
+ uint64_t p = 1ULL << i;
41
+ while (!data.done) {
189
+ if (perm & p) {
42
+ aio_poll(qemu_get_aio_context(), true);
190
+ ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
191
+ if (ret) {
192
+ char *perm_name = bdrv_perm_names(p);
193
+ error_setg(errp,
194
+ "Failed to get \"%s\" lock",
195
+ perm_name);
196
+ g_free(perm_name);
197
+ error_append_hint(errp,
198
+ "Is another process using the image?\n");
199
+ return ret;
200
+ }
201
+ }
202
+ }
43
+ }
203
+ PERM_FOREACH(i) {
204
+ int off = RAW_LOCK_PERM_BASE + i;
205
+ uint64_t p = 1ULL << i;
206
+ if (!(shared_perm & p)) {
207
+ ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
208
+ if (ret) {
209
+ char *perm_name = bdrv_perm_names(p);
210
+ error_setg(errp,
211
+ "Failed to get shared \"%s\" lock",
212
+ perm_name);
213
+ g_free(perm_name);
214
+ error_append_hint(errp,
215
+ "Is another process using the image?\n");
216
+ return ret;
217
+ }
218
+ }
219
+ }
220
+ return 0;
221
+}
44
+}
222
+
45
+
223
+static int raw_handle_perm_lock(BlockDriverState *bs,
46
enum drain_type {
224
+ RawPermLockOp op,
47
BDRV_DRAIN_ALL,
225
+ uint64_t new_perm, uint64_t new_shared,
48
BDRV_DRAIN,
226
+ Error **errp)
49
@@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_subtree(void)
50
test_drv_cb_common(BDRV_SUBTREE_DRAIN, true);
51
}
52
53
+static void test_drv_cb_co_drain(void)
227
+{
54
+{
228
+ BDRVRawState *s = bs->opaque;
55
+ call_in_coroutine(test_drv_cb_drain);
229
+ int ret = 0;
230
+ Error *local_err = NULL;
231
+
232
+ if (!s->use_lock) {
233
+ return 0;
234
+ }
235
+
236
+ if (bdrv_get_flags(bs) & BDRV_O_INACTIVE) {
237
+ return 0;
238
+ }
239
+
240
+ assert(s->lock_fd > 0);
241
+
242
+ switch (op) {
243
+ case RAW_PL_PREPARE:
244
+ ret = raw_apply_lock_bytes(s, s->perm | new_perm,
245
+ ~s->shared_perm | ~new_shared,
246
+ false, errp);
247
+ if (!ret) {
248
+ ret = raw_check_lock_bytes(s, new_perm, new_shared, errp);
249
+ if (!ret) {
250
+ return 0;
251
+ }
252
+ }
253
+ op = RAW_PL_ABORT;
254
+ /* fall through to unlock bytes. */
255
+ case RAW_PL_ABORT:
256
+ raw_apply_lock_bytes(s, s->perm, ~s->shared_perm, true, &local_err);
257
+ if (local_err) {
258
+ /* Theoretically the above call only unlocks bytes and it cannot
259
+ * fail. Something weird happened, report it.
260
+ */
261
+ error_report_err(local_err);
262
+ }
263
+ break;
264
+ case RAW_PL_COMMIT:
265
+ raw_apply_lock_bytes(s, new_perm, ~new_shared, true, &local_err);
266
+ if (local_err) {
267
+ /* Theoretically the above call only unlocks bytes and it cannot
268
+ * fail. Something weird happened, report it.
269
+ */
270
+ error_report_err(local_err);
271
+ }
272
+ break;
273
+ }
274
+ return ret;
275
+}
56
+}
276
+
57
+
277
static int raw_reopen_prepare(BDRVReopenState *state,
58
+static void test_drv_cb_co_drain_subtree(void)
278
BlockReopenQueue *queue, Error **errp)
279
{
280
@@ -XXX,XX +XXX,XX @@ static void raw_close(BlockDriverState *bs)
281
qemu_close(s->fd);
282
s->fd = -1;
283
}
284
+ if (s->lock_fd >= 0) {
285
+ qemu_close(s->lock_fd);
286
+ s->lock_fd = -1;
287
+ }
288
}
289
290
static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
291
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_create_opts = {
292
}
293
};
294
295
+static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared,
296
+ Error **errp)
297
+{
59
+{
298
+ return raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, errp);
60
+ call_in_coroutine(test_drv_cb_drain_subtree);
299
+}
61
+}
300
+
62
+
301
+static void raw_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared)
63
static void test_quiesce_common(enum drain_type drain_type, bool recursive)
64
{
65
BlockBackend *blk;
66
@@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain_subtree(void)
67
test_quiesce_common(BDRV_SUBTREE_DRAIN, true);
68
}
69
70
+static void test_quiesce_co_drain(void)
302
+{
71
+{
303
+ BDRVRawState *s = bs->opaque;
72
+ call_in_coroutine(test_quiesce_drain);
304
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
305
+ s->perm = perm;
306
+ s->shared_perm = shared;
307
+}
73
+}
308
+
74
+
309
+static void raw_abort_perm_update(BlockDriverState *bs)
75
+static void test_quiesce_co_drain_subtree(void)
310
+{
76
+{
311
+ raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
77
+ call_in_coroutine(test_quiesce_drain_subtree);
312
+}
78
+}
313
+
79
+
314
+static int raw_inactivate(BlockDriverState *bs)
80
static void test_nested(void)
315
+{
81
{
316
+ int ret;
82
BlockBackend *blk;
317
+ uint64_t perm = 0;
83
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
318
+ uint64_t shared = BLK_PERM_ALL;
84
g_test_add_func("/bdrv-drain/driver-cb/drain_subtree",
319
+
85
test_drv_cb_drain_subtree);
320
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
86
321
+ if (ret) {
87
+ // XXX bdrv_drain_all() doesn't work in coroutine context
322
+ return ret;
88
+ g_test_add_func("/bdrv-drain/driver-cb/co/drain", test_drv_cb_co_drain);
323
+ }
89
+ g_test_add_func("/bdrv-drain/driver-cb/co/drain_subtree",
324
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
90
+ test_drv_cb_co_drain_subtree);
325
+ return 0;
326
+}
327
+
91
+
328
+
92
+
329
+static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
93
g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all);
330
+{
94
g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain);
331
+ BDRVRawState *s = bs->opaque;
95
g_test_add_func("/bdrv-drain/quiesce/drain_subtree",
332
+ int ret;
96
test_quiesce_drain_subtree);
97
98
+ // XXX bdrv_drain_all() doesn't work in coroutine context
99
+ g_test_add_func("/bdrv-drain/quiesce/co/drain", test_quiesce_co_drain);
100
+ g_test_add_func("/bdrv-drain/quiesce/co/drain_subtree",
101
+ test_quiesce_co_drain_subtree);
333
+
102
+
334
+ assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
103
g_test_add_func("/bdrv-drain/nested", test_nested);
335
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
104
336
+ errp);
105
g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
337
+ if (ret) {
338
+ return;
339
+ }
340
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, s->perm, s->shared_perm, NULL);
341
+}
342
+
343
BlockDriver bdrv_file = {
344
.format_name = "file",
345
.protocol_name = "file",
346
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
347
.bdrv_get_info = raw_get_info,
348
.bdrv_get_allocated_file_size
349
= raw_get_allocated_file_size,
350
-
351
+ .bdrv_inactivate = raw_inactivate,
352
+ .bdrv_invalidate_cache = raw_invalidate_cache,
353
+ .bdrv_check_perm = raw_check_perm,
354
+ .bdrv_set_perm = raw_set_perm,
355
+ .bdrv_abort_perm_update = raw_abort_perm_update,
356
.create_opts = &raw_create_opts,
357
};
358
359
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_device = {
360
.bdrv_get_info = raw_get_info,
361
.bdrv_get_allocated_file_size
362
= raw_get_allocated_file_size,
363
+ .bdrv_inactivate = raw_inactivate,
364
+ .bdrv_invalidate_cache = raw_invalidate_cache,
365
+ .bdrv_check_perm = raw_check_perm,
366
+ .bdrv_set_perm = raw_set_perm,
367
+ .bdrv_abort_perm_update = raw_abort_perm_update,
368
.bdrv_probe_blocksizes = hdev_probe_blocksizes,
369
.bdrv_probe_geometry = hdev_probe_geometry,
370
371
--
106
--
372
1.8.3.1
107
2.13.6
373
108
374
109
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
tests/qemu-iotests/182 | 68 ++++++++++++++++++++++++++++++++++++++++++++++
7
tests/qemu-iotests/182.out | 8 ++++++
8
tests/qemu-iotests/group | 1 +
9
3 files changed, 77 insertions(+)
10
create mode 100755 tests/qemu-iotests/182
11
create mode 100644 tests/qemu-iotests/182.out
12
13
diff --git a/tests/qemu-iotests/182 b/tests/qemu-iotests/182
14
new file mode 100755
15
index XXXXXXX..XXXXXXX
16
--- /dev/null
17
+++ b/tests/qemu-iotests/182
18
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
20
+#
21
+# Test image locking for POSIX locks
22
+#
23
+# Copyright 2017 Red Hat, Inc.
24
+#
25
+# This program is free software; you can redistribute it and/or modify
26
+# it under the terms of the GNU General Public License as published by
27
+# the Free Software Foundation; either version 2 of the License, or
28
+# (at your option) any later version.
29
+#
30
+# This program is distributed in the hope that it will be useful,
31
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
+# GNU General Public License for more details.
34
+#
35
+# You should have received a copy of the GNU General Public License
36
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
38
+
39
+# creator
40
+owner=famz@redhat.com
41
+
42
+seq="$(basename $0)"
43
+echo "QA output created by $seq"
44
+
45
+here="$PWD"
46
+tmp=/tmp/$$
47
+status=1    # failure is the default!
48
+
49
+_cleanup()
50
+{
51
+ _cleanup_test_img
52
+}
53
+trap "_cleanup; exit \$status" 0 1 2 3 15
54
+
55
+# get standard environment, filters and checks
56
+. ./common.rc
57
+. ./common.filter
58
+. ./common.qemu
59
+
60
+_supported_fmt qcow2
61
+_supported_proto file
62
+_supported_os Linux
63
+
64
+size=32M
65
+
66
+_make_test_img $size
67
+
68
+echo "Starting QEMU"
69
+_launch_qemu -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
70
+ -device virtio-blk-pci,drive=drive0
71
+
72
+echo
73
+echo "Starting a second QEMU using the same image should fail"
74
+echo 'quit' | $QEMU -monitor stdio \
75
+ -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
76
+ -device virtio-blk-pci,drive=drive0 2>&1 | _filter_testdir 2>&1 |
77
+ _filter_qemu |
78
+ sed -e '/falling back to POSIX file/d' \
79
+ -e '/locks can be lost unexpectedly/d'
80
+
81
+_cleanup_qemu
82
+
83
+# success, all done
84
+echo "*** done"
85
+rm -f $seq.full
86
+status=0
87
diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out
88
new file mode 100644
89
index XXXXXXX..XXXXXXX
90
--- /dev/null
91
+++ b/tests/qemu-iotests/182.out
92
@@ -XXX,XX +XXX,XX @@
93
+QA output created by 182
94
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432
95
+Starting QEMU
96
+
97
+Starting a second QEMU using the same image should fail
98
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock
99
+Is another process using the image?
100
+*** done
101
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
102
index XXXXXXX..XXXXXXX 100644
103
--- a/tests/qemu-iotests/group
104
+++ b/tests/qemu-iotests/group
105
@@ -XXX,XX +XXX,XX @@
106
175 auto quick
107
176 rw auto backing
108
181 rw auto migration
109
+182 rw auto quick
110
--
111
1.8.3.1
112
113
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
When calculating the number of reftable entries, we should actually use
4
the number of refblocks and not (wrongly[1]) re-calculate it.
5
6
[1] "Wrongly" means: Dividing the number of clusters by the number of
7
entries per refblock and rounding down instead of up.
8
9
Reported-by: Eric Blake <eblake@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
14
block/qcow2.c | 9 +++++----
15
1 file changed, 5 insertions(+), 4 deletions(-)
16
17
diff --git a/block/qcow2.c b/block/qcow2.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/qcow2.c
20
+++ b/block/qcow2.c
21
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
22
* too, as long as the bulk is allocated here). Therefore, using
23
* floating point arithmetic is fine. */
24
int64_t meta_size = 0;
25
- uint64_t nreftablee, nrefblocke, nl1e, nl2e;
26
+ uint64_t nreftablee, nrefblocke, nl1e, nl2e, refblock_count;
27
int64_t aligned_total_size = align_offset(total_size, cluster_size);
28
int refblock_bits, refblock_size;
29
/* refcount entry size in bytes */
30
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
31
nrefblocke = (aligned_total_size + meta_size + cluster_size)
32
/ (cluster_size - rces - rces * sizeof(uint64_t)
33
/ cluster_size);
34
- meta_size += DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size;
35
+ refblock_count = DIV_ROUND_UP(nrefblocke, refblock_size);
36
+ meta_size += refblock_count * cluster_size;
37
38
/* total size of refcount tables */
39
- nreftablee = nrefblocke / refblock_size;
40
- nreftablee = align_offset(nreftablee, cluster_size / sizeof(uint64_t));
41
+ nreftablee = align_offset(refblock_count,
42
+ cluster_size / sizeof(uint64_t));
43
meta_size += nreftablee * sizeof(uint64_t);
44
45
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
46
--
47
1.8.3.1
48
49
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
In discard_single_l2(), we completely discard normal clusters instead of
4
simply turning them into preallocated zero clusters. That means we
5
should probably do the same with such preallocated zero clusters:
6
Discard them instead of keeping them allocated.
7
8
Reported-by: Eric Blake <eblake@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
13
block/qcow2-cluster.c | 3 ++-
14
1 file changed, 2 insertions(+), 1 deletion(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
break;
22
23
case QCOW2_CLUSTER_ZERO:
24
- if (!full_discard) {
25
+ /* Preallocated zero clusters should be discarded in any case */
26
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
27
continue;
28
}
29
break;
30
--
31
1.8.3.1
32
33
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
Test that drain sections are correctly propagated through the graph.
2
2
3
In order to test the effects of artificial geometry constraints
3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
on operations like write zero or discard, we first need blkdebug
5
to manage these actions. It also allows us to inject errors on
6
those operations, just like we can for read/write/flush.
7
8
We can also test the contract promised by the block layer; namely,
9
if a device has specified limits on alignment or maximum size,
10
then those limits must be obeyed (for now, the blkdebug driver
11
merely inherits limits from whatever it is wrapping, but the next
12
patch will further enhance it to allow specific limit overrides).
13
14
This patch intentionally refuses to service requests smaller than
15
the requested alignments; this is because an upcoming patch adds
16
a qemu-iotest to prove that the block layer is correctly handling
17
fragmentation, but the test only works if there is a way to tell
18
the difference at artificial alignment boundaries when blkdebug is
19
using a larger-than-default alignment. If we let the blkdebug
20
layer always defer to the underlying layer, which potentially has
21
a smaller granularity, the iotest will be thwarted.
22
23
Tested by setting up an NBD server with export 'foo', then invoking:
24
$ ./qemu-io
25
qemu-io> open -o driver=blkdebug blkdebug::nbd://localhost:10809/foo
26
qemu-io> d 0 15M
27
qemu-io> w -z 0 15M
28
29
Pre-patch, the server never sees the discard (it was silently
30
eaten by the block layer); post-patch it is passed across the
31
wire. Likewise, pre-patch the write is always passed with
32
NBD_WRITE (with 15M of zeroes on the wire), while post-patch
33
it can utilize NBD_WRITE_ZEROES (for less traffic).
34
35
Signed-off-by: Eric Blake <eblake@redhat.com>
36
Reviewed-by: Max Reitz <mreitz@redhat.com>
37
Message-id: 20170429191419.30051-7-eblake@redhat.com
38
Signed-off-by: Max Reitz <mreitz@redhat.com>
39
---
4
---
40
block/blkdebug.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
tests/test-bdrv-drain.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++
41
1 file changed, 74 insertions(+)
6
1 file changed, 74 insertions(+)
42
7
43
diff --git a/block/blkdebug.c b/block/blkdebug.c
8
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
44
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
45
--- a/block/blkdebug.c
10
--- a/tests/test-bdrv-drain.c
46
+++ b/block/blkdebug.c
11
+++ b/tests/test-bdrv-drain.c
47
@@ -XXX,XX +XXX,XX @@
12
@@ -XXX,XX +XXX,XX @@ static void test_nested(void)
48
/*
13
blk_unref(blk);
49
* Block protocol for I/O error injection
14
}
50
*
15
51
+ * Copyright (C) 2016-2017 Red Hat, Inc.
16
+static void test_multiparent(void)
52
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
17
+{
53
*
18
+ BlockBackend *blk_a, *blk_b;
54
* Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ BlockDriverState *bs_a, *bs_b, *backing;
55
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
20
+ BDRVTestState *a_s, *b_s, *backing_s;
56
goto out;
57
}
58
59
+ bs->supported_write_flags = BDRV_REQ_FUA &
60
+ bs->file->bs->supported_write_flags;
61
+ bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
62
+ bs->file->bs->supported_zero_flags;
63
+
21
+
64
/* Set request alignment */
22
+ blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
65
align = qemu_opt_get_size(opts, "align", 0);
23
+ bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR,
66
if (align < INT_MAX && is_power_of_2(align)) {
24
+ &error_abort);
67
@@ -XXX,XX +XXX,XX @@ static int blkdebug_co_flush(BlockDriverState *bs)
25
+ a_s = bs_a->opaque;
68
return bdrv_co_flush(bs->file->bs);
26
+ blk_insert_bs(blk_a, bs_a, &error_abort);
69
}
70
71
+static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
72
+ int64_t offset, int count,
73
+ BdrvRequestFlags flags)
74
+{
75
+ uint32_t align = MAX(bs->bl.request_alignment,
76
+ bs->bl.pwrite_zeroes_alignment);
77
+ int err;
78
+
27
+
79
+ /* Only pass through requests that are larger than requested
28
+ blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
80
+ * preferred alignment (so that we test the fallback to writes on
29
+ bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR,
81
+ * unaligned portions), and check that the block layer never hands
30
+ &error_abort);
82
+ * us anything unaligned that crosses an alignment boundary. */
31
+ b_s = bs_b->opaque;
83
+ if (count < align) {
32
+ blk_insert_bs(blk_b, bs_b, &error_abort);
84
+ assert(QEMU_IS_ALIGNED(offset, align) ||
85
+ QEMU_IS_ALIGNED(offset + count, align) ||
86
+ DIV_ROUND_UP(offset, align) ==
87
+ DIV_ROUND_UP(offset + count, align));
88
+ return -ENOTSUP;
89
+ }
90
+ assert(QEMU_IS_ALIGNED(offset, align));
91
+ assert(QEMU_IS_ALIGNED(count, align));
92
+ if (bs->bl.max_pwrite_zeroes) {
93
+ assert(count <= bs->bl.max_pwrite_zeroes);
94
+ }
95
+
33
+
96
+ err = rule_check(bs, offset, count);
34
+ backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
97
+ if (err) {
35
+ backing_s = backing->opaque;
98
+ return err;
36
+ bdrv_set_backing_hd(bs_a, backing, &error_abort);
99
+ }
37
+ bdrv_set_backing_hd(bs_b, backing, &error_abort);
100
+
38
+
101
+ return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
39
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
40
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
41
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
42
+ g_assert_cmpint(a_s->drain_count, ==, 0);
43
+ g_assert_cmpint(b_s->drain_count, ==, 0);
44
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
45
+
46
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a);
47
+
48
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
49
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
50
+ g_assert_cmpint(backing->quiesce_counter, ==, 1);
51
+ g_assert_cmpint(a_s->drain_count, ==, 1);
52
+ g_assert_cmpint(b_s->drain_count, ==, 1);
53
+ g_assert_cmpint(backing_s->drain_count, ==, 1);
54
+
55
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b);
56
+
57
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 2);
58
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 2);
59
+ g_assert_cmpint(backing->quiesce_counter, ==, 2);
60
+ g_assert_cmpint(a_s->drain_count, ==, 2);
61
+ g_assert_cmpint(b_s->drain_count, ==, 2);
62
+ g_assert_cmpint(backing_s->drain_count, ==, 2);
63
+
64
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_b);
65
+
66
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
67
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
68
+ g_assert_cmpint(backing->quiesce_counter, ==, 1);
69
+ g_assert_cmpint(a_s->drain_count, ==, 1);
70
+ g_assert_cmpint(b_s->drain_count, ==, 1);
71
+ g_assert_cmpint(backing_s->drain_count, ==, 1);
72
+
73
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_a);
74
+
75
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
76
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
77
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
78
+ g_assert_cmpint(a_s->drain_count, ==, 0);
79
+ g_assert_cmpint(b_s->drain_count, ==, 0);
80
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
81
+
82
+ bdrv_unref(backing);
83
+ bdrv_unref(bs_a);
84
+ bdrv_unref(bs_b);
85
+ blk_unref(blk_a);
86
+ blk_unref(blk_b);
102
+}
87
+}
103
+
88
+
104
+static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
89
105
+ int64_t offset, int count)
90
typedef struct TestBlockJob {
106
+{
91
BlockJob common;
107
+ uint32_t align = bs->bl.pdiscard_alignment;
92
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
108
+ int err;
93
test_quiesce_co_drain_subtree);
109
+
94
110
+ /* Only pass through requests that are larger than requested
95
g_test_add_func("/bdrv-drain/nested", test_nested);
111
+ * minimum alignment, and ensure that unaligned requests do not
96
+ g_test_add_func("/bdrv-drain/multiparent", test_multiparent);
112
+ * cross optimum discard boundaries. */
97
113
+ if (count < bs->bl.request_alignment) {
98
g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
114
+ assert(QEMU_IS_ALIGNED(offset, align) ||
99
g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain);
115
+ QEMU_IS_ALIGNED(offset + count, align) ||
116
+ DIV_ROUND_UP(offset, align) ==
117
+ DIV_ROUND_UP(offset + count, align));
118
+ return -ENOTSUP;
119
+ }
120
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
121
+ assert(QEMU_IS_ALIGNED(count, bs->bl.request_alignment));
122
+ if (align && count >= align) {
123
+ assert(QEMU_IS_ALIGNED(offset, align));
124
+ assert(QEMU_IS_ALIGNED(count, align));
125
+ }
126
+ if (bs->bl.max_pdiscard) {
127
+ assert(count <= bs->bl.max_pdiscard);
128
+ }
129
+
130
+ err = rule_check(bs, offset, count);
131
+ if (err) {
132
+ return err;
133
+ }
134
+
135
+ return bdrv_co_pdiscard(bs->file->bs, offset, count);
136
+}
137
138
static void blkdebug_close(BlockDriverState *bs)
139
{
140
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkdebug = {
141
.bdrv_co_preadv = blkdebug_co_preadv,
142
.bdrv_co_pwritev = blkdebug_co_pwritev,
143
.bdrv_co_flush_to_disk = blkdebug_co_flush,
144
+ .bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes,
145
+ .bdrv_co_pdiscard = blkdebug_co_pdiscard,
146
147
.bdrv_debug_event = blkdebug_debug_event,
148
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
149
--
100
--
150
1.8.3.1
101
2.13.6
151
102
152
103
diff view generated by jsdifflib
1
The proper order for inactivating block nodes is that first the parents
1
We need to remember how many of the drain sections in which a node is
2
get inactivated and then the children. If we do things in this order, we
2
were recursive (i.e. subtree drain rather than node drain), so that they
3
can assert that we didn't accidentally leave a parent activated when one
3
can be correctly applied when children are added or removed during the
4
of its child nodes is inactive.
4
drained section.
5
6
With this change, it is safe to modify the graph even inside a
7
bdrv_subtree_drained_begin/end() section.
5
8
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
---
10
---
9
block.c | 25 ++++++++++++++++++-------
11
include/block/block.h | 2 --
10
1 file changed, 18 insertions(+), 7 deletions(-)
12
include/block/block_int.h | 5 +++++
11
13
block.c | 32 +++++++++++++++++++++++++++++---
14
block/io.c | 28 ++++++++++++++++++++++++----
15
4 files changed, 58 insertions(+), 9 deletions(-)
16
17
diff --git a/include/block/block.h b/include/block/block.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/block/block.h
20
+++ b/include/block/block.h
21
@@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs);
22
/**
23
* Like bdrv_drained_begin, but recursively begins a quiesced section for
24
* exclusive access to all child nodes as well.
25
- *
26
- * Graph changes are not allowed during a subtree drain section.
27
*/
28
void bdrv_subtree_drained_begin(BlockDriverState *bs);
29
30
diff --git a/include/block/block_int.h b/include/block/block_int.h
31
index XXXXXXX..XXXXXXX 100644
32
--- a/include/block/block_int.h
33
+++ b/include/block/block_int.h
34
@@ -XXX,XX +XXX,XX @@ struct BlockDriverState {
35
36
/* Accessed with atomic ops. */
37
int quiesce_counter;
38
+ int recursive_quiesce_counter;
39
+
40
unsigned int write_gen; /* Current data generation */
41
42
/* Protected by reqs_lock. */
43
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child,
44
int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
45
BdrvRequestFlags flags);
46
47
+void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent);
48
+void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_parent);
49
+
50
int get_tmp_filename(char *filename, int size);
51
BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
52
const char *filename);
12
diff --git a/block.c b/block.c
53
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
54
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
55
--- a/block.c
15
+++ b/block.c
56
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child)
57
@@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child)
17
bdrv_drained_end(bs);
58
bdrv_drained_end(bs);
18
}
59
}
19
60
20
+static int bdrv_child_cb_inactivate(BdrvChild *child)
61
+static void bdrv_child_cb_attach(BdrvChild *child)
21
+{
62
+{
22
+ BlockDriverState *bs = child->opaque;
63
+ BlockDriverState *bs = child->opaque;
23
+ assert(bs->open_flags & BDRV_O_INACTIVE);
64
+ bdrv_apply_subtree_drain(child, bs);
24
+ return 0;
65
+}
25
+}
66
+
26
+
67
+static void bdrv_child_cb_detach(BdrvChild *child)
27
/*
68
+{
28
* Returns the options and flags that a temporary snapshot should get, based on
69
+ BlockDriverState *bs = child->opaque;
29
* the originally requested flags (the originally requested image will have
70
+ bdrv_unapply_subtree_drain(child, bs);
71
+}
72
+
73
static int bdrv_child_cb_inactivate(BdrvChild *child)
74
{
75
BlockDriverState *bs = child->opaque;
30
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = {
76
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = {
31
.inherit_options = bdrv_inherited_options,
77
.inherit_options = bdrv_inherited_options,
32
.drained_begin = bdrv_child_cb_drained_begin,
78
.drained_begin = bdrv_child_cb_drained_begin,
33
.drained_end = bdrv_child_cb_drained_end,
79
.drained_end = bdrv_child_cb_drained_end,
34
+ .inactivate = bdrv_child_cb_inactivate,
80
+ .attach = bdrv_child_cb_attach,
81
+ .detach = bdrv_child_cb_detach,
82
.inactivate = bdrv_child_cb_inactivate,
35
};
83
};
36
84
37
/*
38
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = {
85
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = {
39
.inherit_options = bdrv_inherited_fmt_options,
86
.inherit_options = bdrv_inherited_fmt_options,
40
.drained_begin = bdrv_child_cb_drained_begin,
87
.drained_begin = bdrv_child_cb_drained_begin,
41
.drained_end = bdrv_child_cb_drained_end,
88
.drained_end = bdrv_child_cb_drained_end,
42
+ .inactivate = bdrv_child_cb_inactivate,
89
+ .attach = bdrv_child_cb_attach,
90
+ .detach = bdrv_child_cb_detach,
91
.inactivate = bdrv_child_cb_inactivate,
43
};
92
};
44
93
45
static void bdrv_backing_attach(BdrvChild *c)
94
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_attach(BdrvChild *c)
46
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_backing = {
95
parent->backing_blocker);
47
.inherit_options = bdrv_backing_options,
96
bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET,
48
.drained_begin = bdrv_child_cb_drained_begin,
97
parent->backing_blocker);
49
.drained_end = bdrv_child_cb_drained_end,
98
+
50
+ .inactivate = bdrv_child_cb_inactivate,
99
+ bdrv_child_cb_attach(c);
51
};
100
}
52
101
53
static int bdrv_open_flags(BlockDriverState *bs, int flags)
102
static void bdrv_backing_detach(BdrvChild *c)
54
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
103
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c)
55
}
104
bdrv_op_unblock_all(c->bs, parent->backing_blocker);
105
error_free(parent->backing_blocker);
106
parent->backing_blocker = NULL;
107
+
108
+ bdrv_child_cb_detach(c);
109
}
110
111
/*
112
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child,
113
assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs));
56
}
114
}
57
115
if (old_bs) {
58
- QLIST_FOREACH(child, &bs->children, next) {
116
+ /* Detach first so that the recursive drain sections coming from @child
59
- ret = bdrv_inactivate_recurse(child->bs, setting_flag);
117
+ * are already gone and we only end the drain sections that came from
60
- if (ret < 0) {
118
+ * elsewhere. */
61
- return ret;
119
+ if (child->role->detach) {
120
+ child->role->detach(child);
121
+ }
122
if (old_bs->quiesce_counter && child->role->drained_end) {
123
for (i = 0; i < old_bs->quiesce_counter; i++) {
124
child->role->drained_end(child);
125
}
126
}
127
- if (child->role->detach) {
128
- child->role->detach(child);
62
- }
129
- }
63
- }
130
QLIST_REMOVE(child, next_parent);
64
-
131
}
65
if (setting_flag) {
132
66
bs->open_flags |= BDRV_O_INACTIVE;
133
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child,
67
68
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
69
}
134
}
70
}
135
}
136
137
+ /* Attach only after starting new drained sections, so that recursive
138
+ * drain sections coming from @child don't get an extra .drained_begin
139
+ * callback. */
140
if (child->role->attach) {
141
child->role->attach(child);
142
}
143
diff --git a/block/io.c b/block/io.c
144
index XXXXXXX..XXXXXXX 100644
145
--- a/block/io.c
146
+++ b/block/io.c
147
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
148
assert(data.done);
149
}
150
151
-static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
152
- BdrvChild *parent)
153
+void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
154
+ BdrvChild *parent)
155
{
156
BdrvChild *child, *next;
157
158
@@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
159
bdrv_drain_recurse(bs);
160
161
if (recursive) {
162
+ bs->recursive_quiesce_counter++;
163
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
164
bdrv_do_drained_begin(child->bs, true, child);
165
}
166
@@ -XXX,XX +XXX,XX @@ void bdrv_subtree_drained_begin(BlockDriverState *bs)
167
bdrv_do_drained_begin(bs, true, NULL);
168
}
169
170
-static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
171
- BdrvChild *parent)
172
+void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
173
+ BdrvChild *parent)
174
{
175
BdrvChild *child, *next;
176
int old_quiesce_counter;
177
@@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
71
}
178
}
72
+
179
73
+ QLIST_FOREACH(child, &bs->children, next) {
180
if (recursive) {
74
+ ret = bdrv_inactivate_recurse(child->bs, setting_flag);
181
+ bs->recursive_quiesce_counter--;
75
+ if (ret < 0) {
182
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
76
+ return ret;
183
bdrv_do_drained_end(child->bs, true, child);
77
+ }
184
}
185
@@ -XXX,XX +XXX,XX @@ void bdrv_subtree_drained_end(BlockDriverState *bs)
186
bdrv_do_drained_end(bs, true, NULL);
187
}
188
189
+void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent)
190
+{
191
+ int i;
192
+
193
+ for (i = 0; i < new_parent->recursive_quiesce_counter; i++) {
194
+ bdrv_do_drained_begin(child->bs, true, child);
78
+ }
195
+ }
79
+
196
+}
80
return 0;
197
+
81
}
198
+void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_parent)
82
199
+{
200
+ int i;
201
+
202
+ for (i = 0; i < old_parent->recursive_quiesce_counter; i++) {
203
+ bdrv_do_drained_end(child->bs, true, child);
204
+ }
205
+}
206
+
207
/*
208
* Wait for pending requests to complete on a single BlockDriverState subtree,
209
* and suspend block driver's internal I/O until next request arrives.
83
--
210
--
84
1.8.3.1
211
2.13.6
85
212
86
213
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
---
3
tests/test-bdrv-drain.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++
4
1 file changed, 80 insertions(+)
2
5
3
Although it doesn't add all that much type safety (this is C, after
6
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
4
all), it does add a bit of legibility to use the name QCow2ClusterType
5
instead of a plain int.
6
7
In particular, qcow2_get_cluster_offset() has an overloaded return
8
type; a QCow2ClusterType on success, and -errno on failure; keeping
9
the cluster type in a separate variable makes it slightly easier for
10
the next patch to make further computations based on the type.
11
12
Suggested-by: Max Reitz <mreitz@redhat.com>
13
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Message-id: 20170507000552.20847-6-eblake@redhat.com
15
[mreitz: Use the new type in two more places (one of them pulled from
16
the next patch)]
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-cluster.c | 21 +++++++++++----------
20
block/qcow2-refcount.c | 2 +-
21
block/qcow2.h | 6 +++---
22
3 files changed, 15 insertions(+), 14 deletions(-)
23
24
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
25
index XXXXXXX..XXXXXXX 100644
7
index XXXXXXX..XXXXXXX 100644
26
--- a/block/qcow2-cluster.c
8
--- a/tests/test-bdrv-drain.c
27
+++ b/block/qcow2-cluster.c
9
+++ b/tests/test-bdrv-drain.c
28
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
10
@@ -XXX,XX +XXX,XX @@ static void test_multiparent(void)
29
uint64_t *l2_table, uint64_t stop_flags)
11
blk_unref(blk_b);
30
{
31
int i;
32
- int first_cluster_type;
33
+ QCow2ClusterType first_cluster_type;
34
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
35
uint64_t first_entry = be64_to_cpu(l2_table[0]);
36
uint64_t offset = first_entry & mask;
37
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
38
*/
39
static int count_contiguous_clusters_unallocated(int nb_clusters,
40
uint64_t *l2_table,
41
- int wanted_type)
42
+ QCow2ClusterType wanted_type)
43
{
44
int i;
45
46
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
47
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
48
for (i = 0; i < nb_clusters; i++) {
49
uint64_t entry = be64_to_cpu(l2_table[i]);
50
- int type = qcow2_get_cluster_type(entry);
51
+ QCow2ClusterType type = qcow2_get_cluster_type(entry);
52
53
if (type != wanted_type || entry & L2E_OFFSET_MASK) {
54
break;
55
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
56
int l1_bits, c;
57
unsigned int offset_in_cluster;
58
uint64_t bytes_available, bytes_needed, nb_clusters;
59
+ QCow2ClusterType type;
60
int ret;
61
62
offset_in_cluster = offset_into_cluster(s, offset);
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
65
l1_index = offset >> l1_bits;
66
if (l1_index >= s->l1_size) {
67
- ret = QCOW2_CLUSTER_UNALLOCATED;
68
+ type = QCOW2_CLUSTER_UNALLOCATED;
69
goto out;
70
}
71
72
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
73
if (!l2_offset) {
74
- ret = QCOW2_CLUSTER_UNALLOCATED;
75
+ type = QCOW2_CLUSTER_UNALLOCATED;
76
goto out;
77
}
78
79
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
80
* true */
81
assert(nb_clusters <= INT_MAX);
82
83
- ret = qcow2_get_cluster_type(*cluster_offset);
84
- switch (ret) {
85
+ type = qcow2_get_cluster_type(*cluster_offset);
86
+ switch (type) {
87
case QCOW2_CLUSTER_COMPRESSED:
88
/* Compressed clusters can only be processed one by one */
89
c = 1;
90
@@ -XXX,XX +XXX,XX @@ out:
91
assert(bytes_available - offset_in_cluster <= UINT_MAX);
92
*bytes = bytes_available - offset_in_cluster;
93
94
- return ret;
95
+ return type;
96
97
fail:
98
qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table);
99
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
100
101
for (i = 0; i < nb_clusters; i++) {
102
uint64_t l2_entry = be64_to_cpu(l2_table[l2_index + i]);
103
- int cluster_type = qcow2_get_cluster_type(l2_entry);
104
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
105
106
switch(cluster_type) {
107
case QCOW2_CLUSTER_NORMAL:
108
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
109
for (j = 0; j < s->l2_size; j++) {
110
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
111
int64_t offset = l2_entry & L2E_OFFSET_MASK;
112
- int cluster_type = qcow2_get_cluster_type(l2_entry);
113
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
114
bool preallocated = offset != 0;
115
116
if (cluster_type != QCOW2_CLUSTER_ZERO) {
117
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
118
index XXXXXXX..XXXXXXX 100644
119
--- a/block/qcow2-refcount.c
120
+++ b/block/qcow2-refcount.c
121
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
122
for (j = 0; j < s->l2_size; j++) {
123
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
124
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
125
- int cluster_type = qcow2_get_cluster_type(l2_entry);
126
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
127
128
if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
129
((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
130
diff --git a/block/qcow2.h b/block/qcow2.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/block/qcow2.h
133
+++ b/block/qcow2.h
134
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
135
QLIST_ENTRY(QCowL2Meta) next_in_flight;
136
} QCowL2Meta;
137
138
-enum {
139
+typedef enum QCow2ClusterType {
140
QCOW2_CLUSTER_UNALLOCATED,
141
QCOW2_CLUSTER_NORMAL,
142
QCOW2_CLUSTER_COMPRESSED,
143
QCOW2_CLUSTER_ZERO
144
-};
145
+} QCow2ClusterType;
146
147
typedef enum QCow2MetadataOverlap {
148
QCOW2_OL_MAIN_HEADER_BITNR = 0,
149
@@ -XXX,XX +XXX,XX @@ static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State *s)
150
return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
151
}
12
}
152
13
153
-static inline int qcow2_get_cluster_type(uint64_t l2_entry)
14
+static void test_graph_change(void)
154
+static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
15
+{
155
{
16
+ BlockBackend *blk_a, *blk_b;
156
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
17
+ BlockDriverState *bs_a, *bs_b, *backing;
157
return QCOW2_CLUSTER_COMPRESSED;
18
+ BDRVTestState *a_s, *b_s, *backing_s;
19
+
20
+ blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
21
+ bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR,
22
+ &error_abort);
23
+ a_s = bs_a->opaque;
24
+ blk_insert_bs(blk_a, bs_a, &error_abort);
25
+
26
+ blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
27
+ bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR,
28
+ &error_abort);
29
+ b_s = bs_b->opaque;
30
+ blk_insert_bs(blk_b, bs_b, &error_abort);
31
+
32
+ backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
33
+ backing_s = backing->opaque;
34
+ bdrv_set_backing_hd(bs_a, backing, &error_abort);
35
+
36
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
37
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
38
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
39
+ g_assert_cmpint(a_s->drain_count, ==, 0);
40
+ g_assert_cmpint(b_s->drain_count, ==, 0);
41
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
42
+
43
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a);
44
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a);
45
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a);
46
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b);
47
+ do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b);
48
+
49
+ bdrv_set_backing_hd(bs_b, backing, &error_abort);
50
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 5);
51
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 5);
52
+ g_assert_cmpint(backing->quiesce_counter, ==, 5);
53
+ g_assert_cmpint(a_s->drain_count, ==, 5);
54
+ g_assert_cmpint(b_s->drain_count, ==, 5);
55
+ g_assert_cmpint(backing_s->drain_count, ==, 5);
56
+
57
+ bdrv_set_backing_hd(bs_b, NULL, &error_abort);
58
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 3);
59
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 2);
60
+ g_assert_cmpint(backing->quiesce_counter, ==, 3);
61
+ g_assert_cmpint(a_s->drain_count, ==, 3);
62
+ g_assert_cmpint(b_s->drain_count, ==, 2);
63
+ g_assert_cmpint(backing_s->drain_count, ==, 3);
64
+
65
+ bdrv_set_backing_hd(bs_b, backing, &error_abort);
66
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 5);
67
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 5);
68
+ g_assert_cmpint(backing->quiesce_counter, ==, 5);
69
+ g_assert_cmpint(a_s->drain_count, ==, 5);
70
+ g_assert_cmpint(b_s->drain_count, ==, 5);
71
+ g_assert_cmpint(backing_s->drain_count, ==, 5);
72
+
73
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_b);
74
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_b);
75
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_a);
76
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_a);
77
+ do_drain_end(BDRV_SUBTREE_DRAIN, bs_a);
78
+
79
+ g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
80
+ g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
81
+ g_assert_cmpint(backing->quiesce_counter, ==, 0);
82
+ g_assert_cmpint(a_s->drain_count, ==, 0);
83
+ g_assert_cmpint(b_s->drain_count, ==, 0);
84
+ g_assert_cmpint(backing_s->drain_count, ==, 0);
85
+
86
+ bdrv_unref(backing);
87
+ bdrv_unref(bs_a);
88
+ bdrv_unref(bs_b);
89
+ blk_unref(blk_a);
90
+ blk_unref(blk_b);
91
+}
92
+
93
94
typedef struct TestBlockJob {
95
BlockJob common;
96
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
97
98
g_test_add_func("/bdrv-drain/nested", test_nested);
99
g_test_add_func("/bdrv-drain/multiparent", test_multiparent);
100
+ g_test_add_func("/bdrv-drain/graph-change", test_graph_change);
101
102
g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all);
103
g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain);
158
--
104
--
159
1.8.3.1
105
2.13.6
160
106
161
107
diff view generated by jsdifflib
1
Migration code activates all block driver nodes on the destination when
1
Since commit bde70715, base is the only node that is reopened in
2
the migration completes. It does so by calling
2
commit_start(). This means that the code, which still involves an
3
bdrv_invalidate_cache_all() and blk_resume_after_migration(). There is
3
explicit BlockReopenQueue, can now be simplified by using bdrv_reopen().
4
one code path for precopy and one for postcopy migration, resulting in
5
four function calls, which used to have three different failure modes.
6
7
This patch unifies the behaviour so that failure to activate all block
8
nodes is non-fatal, but the error message is logged and the VM isn't
9
automatically started. 'cont' will retry activating the block nodes.
10
4
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
6
Reviewed-by: Fam Zheng <famz@redhat.com>
13
---
7
---
14
migration/migration.c | 16 +++++-----------
8
block/commit.c | 8 +-------
15
migration/savevm.c | 12 +++++-------
9
1 file changed, 1 insertion(+), 7 deletions(-)
16
qmp.c | 18 +++++++++---------
17
3 files changed, 19 insertions(+), 27 deletions(-)
18
10
19
diff --git a/migration/migration.c b/migration/migration.c
11
diff --git a/block/commit.c b/block/commit.c
20
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
21
--- a/migration/migration.c
13
--- a/block/commit.c
22
+++ b/migration/migration.c
14
+++ b/block/commit.c
23
@@ -XXX,XX +XXX,XX @@ static void process_incoming_migration_bh(void *opaque)
15
@@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs,
24
Error *local_err = NULL;
16
const char *filter_node_name, Error **errp)
25
MigrationIncomingState *mis = opaque;
17
{
26
18
CommitBlockJob *s;
27
- /* Make sure all file formats flush their mutable metadata */
19
- BlockReopenQueue *reopen_queue = NULL;
28
+ /* Make sure all file formats flush their mutable metadata.
20
int orig_base_flags;
29
+ * If we get an error here, just don't restart the VM yet. */
21
BlockDriverState *iter;
30
bdrv_invalidate_cache_all(&local_err);
22
BlockDriverState *commit_top_bs = NULL;
31
- if (local_err) {
23
@@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs,
32
- migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
24
/* convert base to r/w, if necessary */
33
- MIGRATION_STATUS_FAILED);
25
orig_base_flags = bdrv_get_flags(base);
34
- error_report_err(local_err);
26
if (!(orig_base_flags & BDRV_O_RDWR)) {
35
- migrate_decompress_threads_join();
27
- reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL,
36
- exit(EXIT_FAILURE);
28
- orig_base_flags | BDRV_O_RDWR);
37
+ if (!local_err) {
29
- }
38
+ blk_resume_after_migration(&local_err);
39
}
40
-
30
-
41
- /* If we get an error here, just don't restart the VM yet. */
31
- if (reopen_queue) {
42
- blk_resume_after_migration(&local_err);
32
- bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &local_err);
43
if (local_err) {
33
+ bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err);
44
- error_free(local_err);
34
if (local_err != NULL) {
45
+ error_report_err(local_err);
35
error_propagate(errp, local_err);
46
local_err = NULL;
36
goto fail;
47
autostart = false;
48
}
49
diff --git a/migration/savevm.c b/migration/savevm.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/migration/savevm.c
52
+++ b/migration/savevm.c
53
@@ -XXX,XX +XXX,XX @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
54
55
qemu_announce_self();
56
57
- /* Make sure all file formats flush their mutable metadata */
58
+ /* Make sure all file formats flush their mutable metadata.
59
+ * If we get an error here, just don't restart the VM yet. */
60
bdrv_invalidate_cache_all(&local_err);
61
- if (local_err) {
62
- error_report_err(local_err);
63
+ if (!local_err) {
64
+ blk_resume_after_migration(&local_err);
65
}
66
-
67
- /* If we get an error here, just don't restart the VM yet. */
68
- blk_resume_after_migration(&local_err);
69
if (local_err) {
70
- error_free(local_err);
71
+ error_report_err(local_err);
72
local_err = NULL;
73
autostart = false;
74
}
75
diff --git a/qmp.c b/qmp.c
76
index XXXXXXX..XXXXXXX 100644
77
--- a/qmp.c
78
+++ b/qmp.c
79
@@ -XXX,XX +XXX,XX @@ void qmp_cont(Error **errp)
80
}
81
82
/* Continuing after completed migration. Images have been inactivated to
83
- * allow the destination to take control. Need to get control back now. */
84
- if (runstate_check(RUN_STATE_FINISH_MIGRATE) ||
85
- runstate_check(RUN_STATE_POSTMIGRATE))
86
- {
87
- bdrv_invalidate_cache_all(&local_err);
88
- if (local_err) {
89
- error_propagate(errp, local_err);
90
- return;
91
- }
92
+ * allow the destination to take control. Need to get control back now.
93
+ *
94
+ * If there are no inactive block nodes (e.g. because the VM was just
95
+ * paused rather than completing a migration), bdrv_inactivate_all() simply
96
+ * doesn't do anything. */
97
+ bdrv_invalidate_cache_all(&local_err);
98
+ if (local_err) {
99
+ error_propagate(errp, local_err);
100
+ return;
101
}
102
103
blk_resume_after_migration(&local_err);
104
--
37
--
105
1.8.3.1
38
2.13.6
106
39
107
40
diff view generated by jsdifflib
1
Instead of manually calling blk_resume_after_migration() in migration
1
The bdrv_reopen*() implementation doesn't like it if the graph is
2
code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend
2
changed between queuing nodes for reopen and actually reopening them
3
activation with cache invalidation into a single function. This is
3
(one of the reasons is that queuing can be recursive).
4
achieved with a new callback in BdrvChildRole that is called by
4
5
bdrv_invalidate_cache_all().
5
So instead of draining the device only in bdrv_reopen_multiple(),
6
require that callers already drained all affected nodes, and assert this
7
in bdrv_reopen_queue().
6
8
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Fam Zheng <famz@redhat.com>
9
---
11
---
10
block.c | 12 +++++++++-
12
block.c | 23 ++++++++++++++++-------
11
block/block-backend.c | 56 +++++++++++++++++++++++------------------------
13
block/replication.c | 6 ++++++
12
include/block/block.h | 2 --
14
qemu-io-cmds.c | 3 +++
13
include/block/block_int.h | 5 +++++
15
3 files changed, 25 insertions(+), 7 deletions(-)
14
migration/migration.c | 3 ---
15
migration/savevm.c | 3 ---
16
qmp.c | 6 -----
17
7 files changed, 44 insertions(+), 43 deletions(-)
18
16
19
diff --git a/block.c b/block.c
17
diff --git a/block.c b/block.c
20
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
19
--- a/block.c
22
+++ b/block.c
20
+++ b/block.c
23
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
21
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open(const char *filename, const char *reference,
24
22
* returns a pointer to bs_queue, which is either the newly allocated
25
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
23
* bs_queue, or the existing bs_queue being used.
24
*
25
+ * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple().
26
*/
27
static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
28
BlockDriverState *bs,
29
@@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,
30
BdrvChild *child;
31
QDict *old_options, *explicit_options;
32
33
+ /* Make sure that the caller remembered to use a drained section. This is
34
+ * important to avoid graph changes between the recursive queuing here and
35
+ * bdrv_reopen_multiple(). */
36
+ assert(bs->quiesce_counter > 0);
37
+
38
if (bs_queue == NULL) {
39
bs_queue = g_new0(BlockReopenQueue, 1);
40
QSIMPLEQ_INIT(bs_queue);
41
@@ -XXX,XX +XXX,XX @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
42
* If all devices prepare successfully, then the changes are committed
43
* to all devices.
44
*
45
+ * All affected nodes must be drained between bdrv_reopen_queue() and
46
+ * bdrv_reopen_multiple().
47
*/
48
int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp)
26
{
49
{
27
- BdrvChild *child;
50
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **er
28
+ BdrvChild *child, *parent;
51
52
assert(bs_queue != NULL);
53
54
- aio_context_release(ctx);
55
- bdrv_drain_all_begin();
56
- aio_context_acquire(ctx);
57
-
58
QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
59
+ assert(bs_entry->state.bs->quiesce_counter > 0);
60
if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, &local_err)) {
61
error_propagate(errp, local_err);
62
goto cleanup;
63
@@ -XXX,XX +XXX,XX @@ cleanup:
64
}
65
g_free(bs_queue);
66
67
- bdrv_drain_all_end();
68
-
69
return ret;
70
}
71
72
@@ -XXX,XX +XXX,XX @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp)
73
{
74
int ret = -1;
29
Error *local_err = NULL;
75
Error *local_err = NULL;
30
int ret;
76
- BlockReopenQueue *queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags);
31
77
+ BlockReopenQueue *queue;
32
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
78
33
error_setg_errno(errp, -ret, "Could not refresh total sector count");
79
+ bdrv_subtree_drained_begin(bs);
34
return;
80
+
81
+ queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags);
82
ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_err);
83
if (local_err != NULL) {
84
error_propagate(errp, local_err);
35
}
85
}
36
+
86
+
37
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
87
+ bdrv_subtree_drained_end(bs);
38
+ if (parent->role->activate) {
88
+
39
+ parent->role->activate(parent, &local_err);
89
return ret;
40
+ if (local_err) {
41
+ error_propagate(errp, local_err);
42
+ return;
43
+ }
44
+ }
45
+ }
46
}
90
}
47
91
48
void bdrv_invalidate_cache_all(Error **errp)
92
diff --git a/block/replication.c b/block/replication.c
49
diff --git a/block/block-backend.c b/block/block-backend.c
50
index XXXXXXX..XXXXXXX 100644
93
index XXXXXXX..XXXXXXX 100644
51
--- a/block/block-backend.c
94
--- a/block/replication.c
52
+++ b/block/block-backend.c
95
+++ b/block/replication.c
53
@@ -XXX,XX +XXX,XX @@ static const char *blk_root_get_name(BdrvChild *child)
96
@@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable,
54
return blk_name(child->opaque);
97
new_secondary_flags = s->orig_secondary_flags;
98
}
99
100
+ bdrv_subtree_drained_begin(s->hidden_disk->bs);
101
+ bdrv_subtree_drained_begin(s->secondary_disk->bs);
102
+
103
if (orig_hidden_flags != new_hidden_flags) {
104
reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL,
105
new_hidden_flags);
106
@@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable,
107
reopen_queue, &local_err);
108
error_propagate(errp, local_err);
109
}
110
+
111
+ bdrv_subtree_drained_end(s->hidden_disk->bs);
112
+ bdrv_subtree_drained_end(s->secondary_disk->bs);
55
}
113
}
56
114
57
+/*
115
static void backup_job_cleanup(BlockDriverState *bs)
58
+ * Notifies the user of the BlockBackend that migration has completed. qdev
116
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
59
+ * devices can tighten their permissions in response (specifically revoke
117
index XXXXXXX..XXXXXXX 100644
60
+ * shared write permissions that we needed for storage migration).
118
--- a/qemu-io-cmds.c
61
+ *
119
+++ b/qemu-io-cmds.c
62
+ * If an error is returned, the VM cannot be allowed to be resumed.
120
@@ -XXX,XX +XXX,XX @@ static int reopen_f(BlockBackend *blk, int argc, char **argv)
63
+ */
121
opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
64
+static void blk_root_activate(BdrvChild *child, Error **errp)
122
qemu_opts_reset(&reopen_opts);
65
+{
123
66
+ BlockBackend *blk = child->opaque;
124
+ bdrv_subtree_drained_begin(bs);
67
+ Error *local_err = NULL;
125
brq = bdrv_reopen_queue(NULL, bs, opts, flags);
126
bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err);
127
+ bdrv_subtree_drained_end(bs);
68
+
128
+
69
+ if (!blk->disable_perm) {
70
+ return;
71
+ }
72
+
73
+ blk->disable_perm = false;
74
+
75
+ blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
76
+ if (local_err) {
77
+ error_propagate(errp, local_err);
78
+ blk->disable_perm = true;
79
+ return;
80
+ }
81
+}
82
+
83
static const BdrvChildRole child_root = {
84
.inherit_options = blk_root_inherit_options,
85
86
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
87
88
.drained_begin = blk_root_drained_begin,
89
.drained_end = blk_root_drained_end,
90
+
91
+ .activate = blk_root_activate,
92
};
93
94
/*
95
@@ -XXX,XX +XXX,XX @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
96
*shared_perm = blk->shared_perm;
97
}
98
99
-/*
100
- * Notifies the user of all BlockBackends that migration has completed. qdev
101
- * devices can tighten their permissions in response (specifically revoke
102
- * shared write permissions that we needed for storage migration).
103
- *
104
- * If an error is returned, the VM cannot be allowed to be resumed.
105
- */
106
-void blk_resume_after_migration(Error **errp)
107
-{
108
- BlockBackend *blk;
109
- Error *local_err = NULL;
110
-
111
- for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
112
- if (!blk->disable_perm) {
113
- continue;
114
- }
115
-
116
- blk->disable_perm = false;
117
-
118
- blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
119
- if (local_err) {
120
- error_propagate(errp, local_err);
121
- blk->disable_perm = true;
122
- return;
123
- }
124
- }
125
-}
126
-
127
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
128
{
129
if (blk->dev) {
130
diff --git a/include/block/block.h b/include/block/block.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/include/block/block.h
133
+++ b/include/block/block.h
134
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
135
void bdrv_invalidate_cache_all(Error **errp);
136
int bdrv_inactivate_all(void);
137
138
-void blk_resume_after_migration(Error **errp);
139
-
140
/* Ensure contents are flushed to disk. */
141
int bdrv_flush(BlockDriverState *bs);
142
int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
143
diff --git a/include/block/block_int.h b/include/block/block_int.h
144
index XXXXXXX..XXXXXXX 100644
145
--- a/include/block/block_int.h
146
+++ b/include/block/block_int.h
147
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
148
void (*drained_begin)(BdrvChild *child);
149
void (*drained_end)(BdrvChild *child);
150
151
+ /* Notifies the parent that the child has been activated (e.g. when
152
+ * migration is completing) and it can start requesting permissions and
153
+ * doing I/O on it. */
154
+ void (*activate)(BdrvChild *child, Error **errp);
155
+
156
void (*attach)(BdrvChild *child);
157
void (*detach)(BdrvChild *child);
158
};
159
diff --git a/migration/migration.c b/migration/migration.c
160
index XXXXXXX..XXXXXXX 100644
161
--- a/migration/migration.c
162
+++ b/migration/migration.c
163
@@ -XXX,XX +XXX,XX @@ static void process_incoming_migration_bh(void *opaque)
164
/* Make sure all file formats flush their mutable metadata.
165
* If we get an error here, just don't restart the VM yet. */
166
bdrv_invalidate_cache_all(&local_err);
167
- if (!local_err) {
168
- blk_resume_after_migration(&local_err);
169
- }
170
if (local_err) {
129
if (local_err) {
171
error_report_err(local_err);
130
error_report_err(local_err);
172
local_err = NULL;
173
diff --git a/migration/savevm.c b/migration/savevm.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/migration/savevm.c
176
+++ b/migration/savevm.c
177
@@ -XXX,XX +XXX,XX @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
178
/* Make sure all file formats flush their mutable metadata.
179
* If we get an error here, just don't restart the VM yet. */
180
bdrv_invalidate_cache_all(&local_err);
181
- if (!local_err) {
182
- blk_resume_after_migration(&local_err);
183
- }
184
if (local_err) {
185
error_report_err(local_err);
186
local_err = NULL;
187
diff --git a/qmp.c b/qmp.c
188
index XXXXXXX..XXXXXXX 100644
189
--- a/qmp.c
190
+++ b/qmp.c
191
@@ -XXX,XX +XXX,XX @@ void qmp_cont(Error **errp)
192
return;
193
}
194
195
- blk_resume_after_migration(&local_err);
196
- if (local_err) {
197
- error_propagate(errp, local_err);
198
- return;
199
- }
200
-
201
if (runstate_check(RUN_STATE_INMIGRATE)) {
202
autostart = 1;
203
} else {
131
} else {
204
--
132
--
205
1.8.3.1
133
2.13.6
206
134
207
135
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Mixing byte offset and sector allocation counts is a bit
4
confusing. Also, reporting n/m sectors, where m decreases
5
according to the remaining size of the file, isn't really
6
adding any useful information; and reporting an offset at
7
both the front and end of the line, with large amounts of
8
whitespace, is pointless. Update the output to use byte
9
counts and shorter lines, then adjust the affected tests
10
(./check -qcow2 102, ./check -vpc 146).
11
12
Note that 'qemu-io map' is MUCH weaker than 'qemu-img map';
13
the former only shows which regions of the active layer are
14
allocated, without regards to where the allocation comes from
15
or whether the allocated portion is known to read as zero
16
(because it is using the weaker bdrv_is_allocated()); while the
17
latter (especially in --output=json mode) reports more details
18
from bdrv_get_block_status().
19
20
Signed-off-by: Eric Blake <eblake@redhat.com>
21
Message-id: 20170429191419.30051-4-eblake@redhat.com
22
Reviewed-by: Max Reitz <mreitz@redhat.com>
23
Signed-off-by: Max Reitz <mreitz@redhat.com>
24
---
25
qemu-io-cmds.c | 11 ++++++-----
26
tests/qemu-iotests/102.out | 4 ++--
27
tests/qemu-iotests/146.out | 30 +++++++++++++++---------------
28
3 files changed, 23 insertions(+), 22 deletions(-)
29
30
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/qemu-io-cmds.c
33
+++ b/qemu-io-cmds.c
34
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
35
{
36
int64_t offset;
37
int64_t nb_sectors, total_sectors;
38
- char s1[64];
39
+ char s1[64], s2[64];
40
int64_t num;
41
int ret;
42
const char *retstr;
43
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
44
}
45
46
retstr = ret ? " allocated" : "not allocated";
47
- cvtstr(offset << 9ULL, s1, sizeof(s1));
48
- printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
49
- "at offset %s (%d)\n",
50
- offset << 9ULL, num, nb_sectors, retstr, s1, ret);
51
+ cvtstr(num << BDRV_SECTOR_BITS, s1, sizeof(s1));
52
+ cvtstr(offset << BDRV_SECTOR_BITS, s2, sizeof(s2));
53
+ printf("%s (0x%" PRIx64 ") bytes %s at offset %s (0x%" PRIx64 ")\n",
54
+ s1, num << BDRV_SECTOR_BITS, retstr,
55
+ s2, offset << BDRV_SECTOR_BITS);
56
57
offset += num;
58
nb_sectors -= num;
59
diff --git a/tests/qemu-iotests/102.out b/tests/qemu-iotests/102.out
60
index XXXXXXX..XXXXXXX 100644
61
--- a/tests/qemu-iotests/102.out
62
+++ b/tests/qemu-iotests/102.out
63
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
64
wrote 65536/65536 bytes at offset 0
65
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
66
Image resized.
67
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
68
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
69
Offset Length Mapped to File
70
71
=== Testing map on an image file truncated outside of qemu ===
72
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 0
73
Image resized.
74
QEMU X.Y.Z monitor - type 'help' for more information
75
(qemu) qemu-io drv0 map
76
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
77
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
78
*** done
79
diff --git a/tests/qemu-iotests/146.out b/tests/qemu-iotests/146.out
80
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/146.out
82
+++ b/tests/qemu-iotests/146.out
83
@@ -XXX,XX +XXX,XX @@ QA output created by 146
84
85
=== Testing VPC Autodetect ===
86
87
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
88
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
89
90
=== Testing VPC with current_size force ===
91
92
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
93
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
94
95
=== Testing VPC with chs force ===
96
97
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
98
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
99
100
=== Testing Hyper-V Autodetect ===
101
102
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
103
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
104
105
=== Testing Hyper-V with current_size force ===
106
107
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
108
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
109
110
=== Testing Hyper-V with chs force ===
111
112
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
113
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
114
115
=== Testing d2v Autodetect ===
116
117
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
118
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
119
120
=== Testing d2v with current_size force ===
121
122
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
123
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
124
125
=== Testing d2v with chs force ===
126
127
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
128
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
129
130
=== Testing Image create, default ===
131
132
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296
133
134
=== Read created image, default opts ====
135
136
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
137
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
138
139
=== Read created image, force_size_calc=chs ====
140
141
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
142
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
143
144
=== Read created image, force_size_calc=current_size ====
145
146
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
147
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
148
149
=== Testing Image create, force_size ===
150
151
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296 forc
152
153
=== Read created image, default opts ====
154
155
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
156
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
157
158
=== Read created image, force_size_calc=chs ====
159
160
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
161
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
162
163
=== Read created image, force_size_calc=current_size ====
164
165
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
166
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
167
*** done
168
--
169
1.8.3.1
170
171
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
4
any I/O to fit within device boundaries. Additionally, when using a
5
minimum alignment of 4k, we want to ensure the block layer does proper
6
read-modify-write rather than requesting I/O on a slice of a sector.
7
Let's enforce that the contract is obeyed when using blkdebug. For
8
now, blkdebug only allows alignment overrides, and just inherits other
9
limits from whatever device it is wrapping, but a future patch will
10
further enhance things.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Message-id: 20170429191419.30051-5-eblake@redhat.com
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
18
block/blkdebug.c | 14 ++++++++++++++
19
1 file changed, 14 insertions(+)
20
21
diff --git a/block/blkdebug.c b/block/blkdebug.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/blkdebug.c
24
+++ b/block/blkdebug.c
25
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
26
BDRVBlkdebugState *s = bs->opaque;
27
BlkdebugRule *rule = NULL;
28
29
+ /* Sanity check block layer guarantees */
30
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
31
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
32
+ if (bs->bl.max_transfer) {
33
+ assert(bytes <= bs->bl.max_transfer);
34
+ }
35
+
36
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
37
uint64_t inject_offset = rule->options.inject.offset;
38
39
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
40
BDRVBlkdebugState *s = bs->opaque;
41
BlkdebugRule *rule = NULL;
42
43
+ /* Sanity check block layer guarantees */
44
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
45
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
46
+ if (bs->bl.max_transfer) {
47
+ assert(bytes <= bs->bl.max_transfer);
48
+ }
49
+
50
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
51
uint64_t inject_offset = rule->options.inject.offset;
52
53
--
54
1.8.3.1
55
56
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than store into a local variable, then copy to the struct
4
if the value is valid, then reporting errors otherwise, it is
5
simpler to just store into the struct and report errors if the
6
value is invalid. This however requires that the struct store
7
a 64-bit number, rather than a narrower type. Likewise, setting
8
a sane errno value in ret prior to the sequence of parsing and
9
jumping to out: on error makes it easier for the next patch to
10
add a chain of similar checks.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Message-id: 20170429191419.30051-8-eblake@redhat.com
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
---
17
block/blkdebug.c | 16 ++++++----------
18
1 file changed, 6 insertions(+), 10 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
23
+++ b/block/blkdebug.c
24
@@ -XXX,XX +XXX,XX @@
25
typedef struct BDRVBlkdebugState {
26
int state;
27
int new_state;
28
- int align;
29
+ uint64_t align;
30
31
/* For blkdebug_refresh_filename() */
32
char *config_file;
33
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
34
BDRVBlkdebugState *s = bs->opaque;
35
QemuOpts *opts;
36
Error *local_err = NULL;
37
- uint64_t align;
38
int ret;
39
40
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
41
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
42
bs->file->bs->supported_write_flags;
43
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
44
bs->file->bs->supported_zero_flags;
45
+ ret = -EINVAL;
46
47
/* Set request alignment */
48
- align = qemu_opt_get_size(opts, "align", 0);
49
- if (align < INT_MAX && is_power_of_2(align)) {
50
- s->align = align;
51
- } else if (align) {
52
- error_setg(errp, "Invalid alignment");
53
- ret = -EINVAL;
54
+ s->align = qemu_opt_get_size(opts, "align", 0);
55
+ if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
56
+ error_setg(errp, "Cannot meet constraints with align %" PRIu64,
57
+ s->align);
58
goto out;
59
}
60
61
ret = 0;
62
- goto out;
63
-
64
out:
65
if (ret < 0) {
66
g_free(s->config_file);
67
--
68
1.8.3.1
69
70
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Use blkdebug's new geometry constraints to emulate setups that
4
have needed past regression fixes: write zeroes asserting
5
when running through a loopback block device with max-transfer
6
smaller than cluster size, and discard rounding away portions
7
of requests not aligned to preferred boundaries. Also, add
8
coverage that the block layer is honoring max transfer limits.
9
10
For now, a single iotest performs all actions, with the idea
11
that we can add future blkdebug constraint test cases in the
12
same file; but it can be split into multiple iotests if we find
13
reason to run one portion of the test in more setups than what
14
are possible in the other.
15
16
For reference, the final portion of the test (checking whether
17
discard passes as much as possible to the lowest layers of the
18
stack) works as follows:
19
20
qemu-io: discard 30M at 80000001, passed to blkdebug
21
blkdebug: discard 511 bytes at 80000001, -ENOTSUP (smaller than
22
blkdebug's 512 align)
23
blkdebug: discard 14371328 bytes at 80000512, passed to qcow2
24
qcow2: discard 739840 bytes at 80000512, -ENOTSUP (smaller than
25
qcow2's 1M align)
26
qcow2: discard 13M bytes at 77M, succeeds
27
blkdebug: discard 15M bytes at 90M, passed to qcow2
28
qcow2: discard 15M bytes at 90M, succeeds
29
blkdebug: discard 1356800 bytes at 105M, passed to qcow2
30
qcow2: discard 1M at 105M, succeeds
31
qcow2: discard 308224 bytes at 106M, -ENOTSUP (smaller than qcow2's
32
1M align)
33
blkdebug: discard 1 byte at 111457280, -ENOTSUP (smaller than
34
blkdebug's 512 align)
35
36
Signed-off-by: Eric Blake <eblake@redhat.com>
37
Reviewed-by: Max Reitz <mreitz@redhat.com>
38
Message-id: 20170429191419.30051-10-eblake@redhat.com
39
[mreitz: For cooperation with image locking, add -r to the qemu-io
40
invocation which verifies the image content]
41
Signed-off-by: Max Reitz <mreitz@redhat.com>
42
---
43
tests/qemu-iotests/177 | 114 +++++++++++++++++++++++++++++++++++++++++++++
44
tests/qemu-iotests/177.out | 49 +++++++++++++++++++
45
tests/qemu-iotests/group | 1 +
46
3 files changed, 164 insertions(+)
47
create mode 100755 tests/qemu-iotests/177
48
create mode 100644 tests/qemu-iotests/177.out
49
50
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
51
new file mode 100755
52
index XXXXXXX..XXXXXXX
53
--- /dev/null
54
+++ b/tests/qemu-iotests/177
55
@@ -XXX,XX +XXX,XX @@
56
+#!/bin/bash
57
+#
58
+# Test corner cases with unusual block geometries
59
+#
60
+# Copyright (C) 2016-2017 Red Hat, Inc.
61
+#
62
+# This program is free software; you can redistribute it and/or modify
63
+# it under the terms of the GNU General Public License as published by
64
+# the Free Software Foundation; either version 2 of the License, or
65
+# (at your option) any later version.
66
+#
67
+# This program is distributed in the hope that it will be useful,
68
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70
+# GNU General Public License for more details.
71
+#
72
+# You should have received a copy of the GNU General Public License
73
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
74
+#
75
+
76
+# creator
77
+owner=eblake@redhat.com
78
+
79
+seq=`basename $0`
80
+echo "QA output created by $seq"
81
+
82
+here=`pwd`
83
+status=1    # failure is the default!
84
+
85
+_cleanup()
86
+{
87
+    _cleanup_test_img
88
+}
89
+trap "_cleanup; exit \$status" 0 1 2 3 15
90
+
91
+# get standard environment, filters and checks
92
+. ./common.rc
93
+. ./common.filter
94
+
95
+_supported_fmt qcow2
96
+_supported_proto file
97
+
98
+CLUSTER_SIZE=1M
99
+size=128M
100
+options=driver=blkdebug,image.driver=qcow2
101
+
102
+echo
103
+echo "== setting up files =="
104
+
105
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
106
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
107
+_make_test_img -b "$TEST_IMG.base"
108
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
109
+
110
+# Limited to 64k max-transfer
111
+echo
112
+echo "== constrained alignment and max-transfer =="
113
+limits=align=4k,max-transfer=64k
114
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
115
+ -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
116
+
117
+echo
118
+echo "== write zero with constrained max-transfer =="
119
+limits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
120
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
121
+ -c "write -z 8003584 2093056" | _filter_qemu_io
122
+
123
+# non-power-of-2 write-zero/discard alignments
124
+echo
125
+echo "== non-power-of-2 write zeroes limits =="
126
+
127
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
128
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
129
+ -c "write -z 32M 32M" | _filter_qemu_io
130
+
131
+echo
132
+echo "== non-power-of-2 discard limits =="
133
+
134
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
135
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
136
+ -c "discard 80000001 30M" | _filter_qemu_io
137
+
138
+echo
139
+echo "== verify image content =="
140
+
141
+function verify_io()
142
+{
143
+ if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
144
+     grep "compat: 0.10" > /dev/null); then
145
+ # For v2 images, discarded clusters are read from the backing file
146
+ discarded=11
147
+ else
148
+ # Discarded clusters are zeroed for v3 or later
149
+ discarded=0
150
+ fi
151
+
152
+ echo read -P 22 0 1000
153
+ echo read -P 33 1000 128k
154
+ echo read -P 22 132072 7871512
155
+ echo read -P 0 8003584 2093056
156
+ echo read -P 22 10096640 23457792
157
+ echo read -P 0 32M 32M
158
+ echo read -P 22 64M 13M
159
+ echo read -P $discarded 77M 29M
160
+ echo read -P 22 106M 22M
161
+}
162
+
163
+verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
164
+
165
+_check_test_img
166
+
167
+# success, all done
168
+echo "*** done"
169
+status=0
170
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
171
new file mode 100644
172
index XXXXXXX..XXXXXXX
173
--- /dev/null
174
+++ b/tests/qemu-iotests/177.out
175
@@ -XXX,XX +XXX,XX @@
176
+QA output created by 177
177
+
178
+== setting up files ==
179
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
180
+wrote 134217728/134217728 bytes at offset 0
181
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 134217728/134217728 bytes at offset 0
184
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+
186
+== constrained alignment and max-transfer ==
187
+wrote 131072/131072 bytes at offset 1000
188
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
189
+read 131072/131072 bytes at offset 1000
190
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
191
+
192
+== write zero with constrained max-transfer ==
193
+wrote 2093056/2093056 bytes at offset 8003584
194
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+
196
+== non-power-of-2 write zeroes limits ==
197
+wrote 33554432/33554432 bytes at offset 33554432
198
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+
200
+== non-power-of-2 discard limits ==
201
+discard 31457280/31457280 bytes at offset 80000001
202
+30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+
204
+== verify image content ==
205
+read 1000/1000 bytes at offset 0
206
+1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
207
+read 131072/131072 bytes at offset 1000
208
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+read 7871512/7871512 bytes at offset 132072
210
+7.507 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+read 2093056/2093056 bytes at offset 8003584
212
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+read 23457792/23457792 bytes at offset 10096640
214
+22.371 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
215
+read 33554432/33554432 bytes at offset 33554432
216
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
217
+read 13631488/13631488 bytes at offset 67108864
218
+13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
219
+read 30408704/30408704 bytes at offset 80740352
220
+29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
221
+read 23068672/23068672 bytes at offset 111149056
222
+22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
223
+No errors were found on the image.
224
+*** done
225
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
226
index XXXXXXX..XXXXXXX 100644
227
--- a/tests/qemu-iotests/group
228
+++ b/tests/qemu-iotests/group
229
@@ -XXX,XX +XXX,XX @@
230
174 auto
231
175 auto quick
232
176 rw auto backing
233
+177 rw auto quick
234
181 rw auto migration
235
182 rw auto quick
236
--
237
1.8.3.1
238
239
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
In order to keep checkpatch happy when the next patch changes
4
indentation, we first have to shorten some long lines. The easiest
5
approach is to use a new variable in place of
6
'offset & L2E_OFFSET_MASK', except that 'offset' is the best name
7
for that variable. Change '[old_]offset' to '[old_]entry' to
8
make room.
9
10
While touching things, also fix checkpatch warnings about unusual
11
'for' statements.
12
13
Suggested by Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Eric Blake <eblake@redhat.com>
15
Message-id: 20170507000552.20847-2-eblake@redhat.com
16
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-refcount.c | 42 ++++++++++++++++++++++--------------------
20
1 file changed, 22 insertions(+), 20 deletions(-)
21
22
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/qcow2-refcount.c
25
+++ b/block/qcow2-refcount.c
26
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
27
int64_t l1_table_offset, int l1_size, int addend)
28
{
29
BDRVQcow2State *s = bs->opaque;
30
- uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount;
31
+ uint64_t *l1_table, *l2_table, l2_offset, entry, l1_size2, refcount;
32
bool l1_allocated = false;
33
- int64_t old_offset, old_l2_offset;
34
+ int64_t old_entry, old_l2_offset;
35
int i, j, l1_modified = 0, nb_csectors;
36
int ret;
37
38
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
39
goto fail;
40
}
41
42
- for(i = 0;i < l1_size; i++)
43
+ for (i = 0; i < l1_size; i++) {
44
be64_to_cpus(&l1_table[i]);
45
+ }
46
} else {
47
assert(l1_size == s->l1_size);
48
l1_table = s->l1_table;
49
l1_allocated = false;
50
}
51
52
- for(i = 0; i < l1_size; i++) {
53
+ for (i = 0; i < l1_size; i++) {
54
l2_offset = l1_table[i];
55
if (l2_offset) {
56
old_l2_offset = l2_offset;
57
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
58
goto fail;
59
}
60
61
- for(j = 0; j < s->l2_size; j++) {
62
+ for (j = 0; j < s->l2_size; j++) {
63
uint64_t cluster_index;
64
+ uint64_t offset;
65
66
- offset = be64_to_cpu(l2_table[j]);
67
- old_offset = offset;
68
- offset &= ~QCOW_OFLAG_COPIED;
69
+ entry = be64_to_cpu(l2_table[j]);
70
+ old_entry = entry;
71
+ entry &= ~QCOW_OFLAG_COPIED;
72
+ offset = entry & L2E_OFFSET_MASK;
73
74
- switch (qcow2_get_cluster_type(offset)) {
75
+ switch (qcow2_get_cluster_type(entry)) {
76
case QCOW2_CLUSTER_COMPRESSED:
77
- nb_csectors = ((offset >> s->csize_shift) &
78
+ nb_csectors = ((entry >> s->csize_shift) &
79
s->csize_mask) + 1;
80
if (addend != 0) {
81
ret = update_refcount(bs,
82
- (offset & s->cluster_offset_mask) & ~511,
83
+ (entry & s->cluster_offset_mask) & ~511,
84
nb_csectors * 512, abs(addend), addend < 0,
85
QCOW2_DISCARD_SNAPSHOT);
86
if (ret < 0) {
87
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
88
89
case QCOW2_CLUSTER_NORMAL:
90
case QCOW2_CLUSTER_ZERO:
91
- if (offset_into_cluster(s, offset & L2E_OFFSET_MASK)) {
92
+ if (offset_into_cluster(s, offset)) {
93
qcow2_signal_corruption(bs, true, -1, -1, "Data "
94
- "cluster offset %#llx "
95
- "unaligned (L2 offset: %#"
96
+ "cluster offset %#" PRIx64
97
+ " unaligned (L2 offset: %#"
98
PRIx64 ", L2 index: %#x)",
99
- offset & L2E_OFFSET_MASK,
100
- l2_offset, j);
101
+ offset, l2_offset, j);
102
ret = -EIO;
103
goto fail;
104
}
105
106
- cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
107
+ cluster_index = offset >> s->cluster_bits;
108
if (!cluster_index) {
109
/* unallocated */
110
refcount = 0;
111
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
112
}
113
114
if (refcount == 1) {
115
- offset |= QCOW_OFLAG_COPIED;
116
+ entry |= QCOW_OFLAG_COPIED;
117
}
118
- if (offset != old_offset) {
119
+ if (entry != old_entry) {
120
if (addend > 0) {
121
qcow2_cache_set_dependency(bs, s->l2_table_cache,
122
s->refcount_block_cache);
123
}
124
- l2_table[j] = cpu_to_be64(offset);
125
+ l2_table[j] = cpu_to_be64(entry);
126
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache,
127
l2_table);
128
}
129
--
130
1.8.3.1
131
132
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Fix a couple of inconsistent indentations, before an upcoming
4
patch further tweaks the switch statements.
5
(best viewed with 'git diff -b').
6
7
Signed-off-by: Eric Blake <eblake@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20170507000552.20847-3-eblake@redhat.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/qcow2-cluster.c | 32 +++++++++----------
13
block/qcow2-refcount.c | 84 +++++++++++++++++++++++++-------------------------
14
2 files changed, 58 insertions(+), 58 deletions(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
* but rather fall through to the backing file.
22
*/
23
switch (qcow2_get_cluster_type(old_l2_entry)) {
24
- case QCOW2_CLUSTER_UNALLOCATED:
25
- if (full_discard || !bs->backing) {
26
- continue;
27
- }
28
- break;
29
+ case QCOW2_CLUSTER_UNALLOCATED:
30
+ if (full_discard || !bs->backing) {
31
+ continue;
32
+ }
33
+ break;
34
35
- case QCOW2_CLUSTER_ZERO:
36
- /* Preallocated zero clusters should be discarded in any case */
37
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
38
- continue;
39
- }
40
- break;
41
+ case QCOW2_CLUSTER_ZERO:
42
+ /* Preallocated zero clusters should be discarded in any case */
43
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
44
+ continue;
45
+ }
46
+ break;
47
48
- case QCOW2_CLUSTER_NORMAL:
49
- case QCOW2_CLUSTER_COMPRESSED:
50
- break;
51
+ case QCOW2_CLUSTER_NORMAL:
52
+ case QCOW2_CLUSTER_COMPRESSED:
53
+ break;
54
55
- default:
56
- abort();
57
+ default:
58
+ abort();
59
}
60
61
/* First remove L2 entries */
62
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/block/qcow2-refcount.c
65
+++ b/block/qcow2-refcount.c
66
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
67
offset = entry & L2E_OFFSET_MASK;
68
69
switch (qcow2_get_cluster_type(entry)) {
70
- case QCOW2_CLUSTER_COMPRESSED:
71
- nb_csectors = ((entry >> s->csize_shift) &
72
- s->csize_mask) + 1;
73
- if (addend != 0) {
74
- ret = update_refcount(bs,
75
+ case QCOW2_CLUSTER_COMPRESSED:
76
+ nb_csectors = ((entry >> s->csize_shift) &
77
+ s->csize_mask) + 1;
78
+ if (addend != 0) {
79
+ ret = update_refcount(bs,
80
(entry & s->cluster_offset_mask) & ~511,
81
nb_csectors * 512, abs(addend), addend < 0,
82
QCOW2_DISCARD_SNAPSHOT);
83
- if (ret < 0) {
84
- goto fail;
85
- }
86
- }
87
- /* compressed clusters are never modified */
88
- refcount = 2;
89
- break;
90
-
91
- case QCOW2_CLUSTER_NORMAL:
92
- case QCOW2_CLUSTER_ZERO:
93
- if (offset_into_cluster(s, offset)) {
94
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
95
- "cluster offset %#" PRIx64
96
- " unaligned (L2 offset: %#"
97
- PRIx64 ", L2 index: %#x)",
98
- offset, l2_offset, j);
99
- ret = -EIO;
100
+ if (ret < 0) {
101
goto fail;
102
}
103
+ }
104
+ /* compressed clusters are never modified */
105
+ refcount = 2;
106
+ break;
107
+
108
+ case QCOW2_CLUSTER_NORMAL:
109
+ case QCOW2_CLUSTER_ZERO:
110
+ if (offset_into_cluster(s, offset)) {
111
+ qcow2_signal_corruption(bs, true, -1, -1, "Data "
112
+ "cluster offset %#" PRIx64
113
+ " unaligned (L2 offset: %#"
114
+ PRIx64 ", L2 index: %#x)",
115
+ offset, l2_offset, j);
116
+ ret = -EIO;
117
+ goto fail;
118
+ }
119
120
- cluster_index = offset >> s->cluster_bits;
121
- if (!cluster_index) {
122
- /* unallocated */
123
- refcount = 0;
124
- break;
125
- }
126
- if (addend != 0) {
127
- ret = qcow2_update_cluster_refcount(bs,
128
+ cluster_index = offset >> s->cluster_bits;
129
+ if (!cluster_index) {
130
+ /* unallocated */
131
+ refcount = 0;
132
+ break;
133
+ }
134
+ if (addend != 0) {
135
+ ret = qcow2_update_cluster_refcount(bs,
136
cluster_index, abs(addend), addend < 0,
137
QCOW2_DISCARD_SNAPSHOT);
138
- if (ret < 0) {
139
- goto fail;
140
- }
141
- }
142
-
143
- ret = qcow2_get_refcount(bs, cluster_index, &refcount);
144
if (ret < 0) {
145
goto fail;
146
}
147
- break;
148
+ }
149
150
- case QCOW2_CLUSTER_UNALLOCATED:
151
- refcount = 0;
152
- break;
153
+ ret = qcow2_get_refcount(bs, cluster_index, &refcount);
154
+ if (ret < 0) {
155
+ goto fail;
156
+ }
157
+ break;
158
+
159
+ case QCOW2_CLUSTER_UNALLOCATED:
160
+ refcount = 0;
161
+ break;
162
163
- default:
164
- abort();
165
+ default:
166
+ abort();
167
}
168
169
if (refcount == 1) {
170
--
171
1.8.3.1
172
173
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We were throwing away the preallocation information associated with
4
zero clusters. But we should be matching the well-defined semantics
5
in bdrv_get_block_status(), where (BDRV_BLOCK_ZERO |
6
BDRV_BLOCK_OFFSET_VALID) informs the user which offset is reserved,
7
while still reminding the user that reading from that offset is
8
likely to read garbage.
9
10
count_contiguous_clusters_by_type() is now used only for unallocated
11
cluster runs, hence it gets renamed and tightened.
12
13
Making this change lets us see which portions of an image are zero
14
but preallocated, when using qemu-img map --output=json. The
15
--output=human side intentionally ignores all zero clusters, whether
16
or not they are preallocated.
17
18
The fact that there is no change to qemu-iotests './check -qcow2'
19
merely means that we aren't yet testing this aspect of qemu-img;
20
a later patch will add a test.
21
22
Signed-off-by: Eric Blake <eblake@redhat.com>
23
Reviewed-by: Max Reitz <mreitz@redhat.com>
24
Message-id: 20170507000552.20847-5-eblake@redhat.com
25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26
---
27
block/qcow2-cluster.c | 45 +++++++++++++++++++++++++++++++++++----------
28
1 file changed, 35 insertions(+), 10 deletions(-)
29
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
33
+++ b/block/qcow2-cluster.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
35
    return i;
36
}
37
38
-static int count_contiguous_clusters_by_type(int nb_clusters,
39
- uint64_t *l2_table,
40
- int wanted_type)
41
+/*
42
+ * Checks how many consecutive unallocated clusters in a given L2
43
+ * table have the same cluster type.
44
+ */
45
+static int count_contiguous_clusters_unallocated(int nb_clusters,
46
+ uint64_t *l2_table,
47
+ int wanted_type)
48
{
49
int i;
50
51
+ assert(wanted_type == QCOW2_CLUSTER_ZERO ||
52
+ wanted_type == QCOW2_CLUSTER_UNALLOCATED);
53
for (i = 0; i < nb_clusters; i++) {
54
- int type = qcow2_get_cluster_type(be64_to_cpu(l2_table[i]));
55
+ uint64_t entry = be64_to_cpu(l2_table[i]);
56
+ int type = qcow2_get_cluster_type(entry);
57
58
- if (type != wanted_type) {
59
+ if (type != wanted_type || entry & L2E_OFFSET_MASK) {
60
break;
61
}
62
}
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
ret = -EIO;
65
goto fail;
66
}
67
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
68
- QCOW2_CLUSTER_ZERO);
69
- *cluster_offset = 0;
70
+ /* Distinguish between pure zero clusters and pre-allocated ones */
71
+ if (*cluster_offset & L2E_OFFSET_MASK) {
72
+ c = count_contiguous_clusters(nb_clusters, s->cluster_size,
73
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
74
+ *cluster_offset &= L2E_OFFSET_MASK;
75
+ if (offset_into_cluster(s, *cluster_offset)) {
76
+ qcow2_signal_corruption(bs, true, -1, -1,
77
+ "Preallocated zero cluster offset %#"
78
+ PRIx64 " unaligned (L2 offset: %#"
79
+ PRIx64 ", L2 index: %#x)",
80
+ *cluster_offset, l2_offset, l2_index);
81
+ ret = -EIO;
82
+ goto fail;
83
+ }
84
+ } else {
85
+ c = count_contiguous_clusters_unallocated(nb_clusters,
86
+ &l2_table[l2_index],
87
+ QCOW2_CLUSTER_ZERO);
88
+ *cluster_offset = 0;
89
+ }
90
break;
91
case QCOW2_CLUSTER_UNALLOCATED:
92
/* how many empty clusters ? */
93
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
94
- QCOW2_CLUSTER_UNALLOCATED);
95
+ c = count_contiguous_clusters_unallocated(nb_clusters,
96
+ &l2_table[l2_index],
97
+ QCOW2_CLUSTER_UNALLOCATED);
98
*cluster_offset = 0;
99
break;
100
case QCOW2_CLUSTER_NORMAL:
101
--
102
1.8.3.1
103
104
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Treat plain zero clusters differently from allocated ones, so that
4
we can simplify the logic of checking whether an offset is present.
5
Do this by splitting QCOW2_CLUSTER_ZERO into two new enums,
6
QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC.
7
8
I tried to arrange the enum so that we could use
9
'ret <= QCOW2_CLUSTER_ZERO_PLAIN' for all unallocated types, and
10
'ret >= QCOW2_CLUSTER_ZERO_ALLOC' for allocated types, although
11
I didn't actually end up taking advantage of the layout.
12
13
In many cases, this leads to simpler code, by properly combining
14
cases (sometimes, both zero types pair together, other times,
15
plain zero is more like unallocated while allocated zero is more
16
like normal).
17
18
Signed-off-by: Eric Blake <eblake@redhat.com>
19
Message-id: 20170507000552.20847-7-eblake@redhat.com
20
Reviewed-by: Max Reitz <mreitz@redhat.com>
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
---
23
block/qcow2-cluster.c | 79 ++++++++++++++++++----------------------------
24
block/qcow2-refcount.c | 44 +++++++++++---------------
25
block/qcow2.c | 9 ++++--
26
block/qcow2.h | 8 +++--
27
tests/qemu-iotests/060.out | 6 ++--
28
5 files changed, 63 insertions(+), 83 deletions(-)
29
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
33
+++ b/block/qcow2-cluster.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
35
/* must be allocated */
36
first_cluster_type = qcow2_get_cluster_type(first_entry);
37
assert(first_cluster_type == QCOW2_CLUSTER_NORMAL ||
38
- (first_cluster_type == QCOW2_CLUSTER_ZERO &&
39
- (first_entry & L2E_OFFSET_MASK) != 0));
40
+ first_cluster_type == QCOW2_CLUSTER_ZERO_ALLOC);
41
42
for (i = 0; i < nb_clusters; i++) {
43
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
44
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
45
{
46
int i;
47
48
- assert(wanted_type == QCOW2_CLUSTER_ZERO ||
49
+ assert(wanted_type == QCOW2_CLUSTER_ZERO_PLAIN ||
50
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
51
for (i = 0; i < nb_clusters; i++) {
52
uint64_t entry = be64_to_cpu(l2_table[i]);
53
QCow2ClusterType type = qcow2_get_cluster_type(entry);
54
55
- if (type != wanted_type || entry & L2E_OFFSET_MASK) {
56
+ if (type != wanted_type) {
57
break;
58
}
59
}
60
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
61
assert(nb_clusters <= INT_MAX);
62
63
type = qcow2_get_cluster_type(*cluster_offset);
64
+ if (s->qcow_version < 3 && (type == QCOW2_CLUSTER_ZERO_PLAIN ||
65
+ type == QCOW2_CLUSTER_ZERO_ALLOC)) {
66
+ qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
67
+ " in pre-v3 image (L2 offset: %#" PRIx64
68
+ ", L2 index: %#x)", l2_offset, l2_index);
69
+ ret = -EIO;
70
+ goto fail;
71
+ }
72
switch (type) {
73
case QCOW2_CLUSTER_COMPRESSED:
74
/* Compressed clusters can only be processed one by one */
75
c = 1;
76
*cluster_offset &= L2E_COMPRESSED_OFFSET_SIZE_MASK;
77
break;
78
- case QCOW2_CLUSTER_ZERO:
79
- if (s->qcow_version < 3) {
80
- qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
81
- " in pre-v3 image (L2 offset: %#" PRIx64
82
- ", L2 index: %#x)", l2_offset, l2_index);
83
- ret = -EIO;
84
- goto fail;
85
- }
86
- /* Distinguish between pure zero clusters and pre-allocated ones */
87
- if (*cluster_offset & L2E_OFFSET_MASK) {
88
- c = count_contiguous_clusters(nb_clusters, s->cluster_size,
89
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
90
- *cluster_offset &= L2E_OFFSET_MASK;
91
- if (offset_into_cluster(s, *cluster_offset)) {
92
- qcow2_signal_corruption(bs, true, -1, -1,
93
- "Preallocated zero cluster offset %#"
94
- PRIx64 " unaligned (L2 offset: %#"
95
- PRIx64 ", L2 index: %#x)",
96
- *cluster_offset, l2_offset, l2_index);
97
- ret = -EIO;
98
- goto fail;
99
- }
100
- } else {
101
- c = count_contiguous_clusters_unallocated(nb_clusters,
102
- &l2_table[l2_index],
103
- QCOW2_CLUSTER_ZERO);
104
- *cluster_offset = 0;
105
- }
106
- break;
107
+ case QCOW2_CLUSTER_ZERO_PLAIN:
108
case QCOW2_CLUSTER_UNALLOCATED:
109
/* how many empty clusters ? */
110
c = count_contiguous_clusters_unallocated(nb_clusters,
111
- &l2_table[l2_index],
112
- QCOW2_CLUSTER_UNALLOCATED);
113
+ &l2_table[l2_index], type);
114
*cluster_offset = 0;
115
break;
116
+ case QCOW2_CLUSTER_ZERO_ALLOC:
117
case QCOW2_CLUSTER_NORMAL:
118
/* how many allocated clusters ? */
119
c = count_contiguous_clusters(nb_clusters, s->cluster_size,
120
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
121
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
122
*cluster_offset &= L2E_OFFSET_MASK;
123
if (offset_into_cluster(s, *cluster_offset)) {
124
- qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset %#"
125
+ qcow2_signal_corruption(bs, true, -1, -1,
126
+ "Cluster allocation offset %#"
127
PRIx64 " unaligned (L2 offset: %#" PRIx64
128
", L2 index: %#x)", *cluster_offset,
129
l2_offset, l2_index);
130
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
131
break;
132
case QCOW2_CLUSTER_UNALLOCATED:
133
case QCOW2_CLUSTER_COMPRESSED:
134
- case QCOW2_CLUSTER_ZERO:
135
+ case QCOW2_CLUSTER_ZERO_PLAIN:
136
+ case QCOW2_CLUSTER_ZERO_ALLOC:
137
break;
138
default:
139
abort();
140
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
141
* wrong with our code. */
142
assert(nb_clusters > 0);
143
144
- if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO &&
145
- (entry & L2E_OFFSET_MASK) != 0 && (entry & QCOW_OFLAG_COPIED) &&
146
+ if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO_ALLOC &&
147
+ (entry & QCOW_OFLAG_COPIED) &&
148
(!*host_offset ||
149
start_of_cluster(s, *host_offset) == (entry & L2E_OFFSET_MASK)))
150
{
151
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
152
}
153
break;
154
155
- case QCOW2_CLUSTER_ZERO:
156
- /* Preallocated zero clusters should be discarded in any case */
157
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
158
+ case QCOW2_CLUSTER_ZERO_PLAIN:
159
+ if (!full_discard) {
160
continue;
161
}
162
break;
163
164
+ case QCOW2_CLUSTER_ZERO_ALLOC:
165
case QCOW2_CLUSTER_NORMAL:
166
case QCOW2_CLUSTER_COMPRESSED:
167
break;
168
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
169
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
170
int64_t offset = l2_entry & L2E_OFFSET_MASK;
171
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
172
- bool preallocated = offset != 0;
173
174
- if (cluster_type != QCOW2_CLUSTER_ZERO) {
175
+ if (cluster_type != QCOW2_CLUSTER_ZERO_PLAIN &&
176
+ cluster_type != QCOW2_CLUSTER_ZERO_ALLOC) {
177
continue;
178
}
179
180
- if (!preallocated) {
181
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
182
if (!bs->backing) {
183
/* not backed; therefore we can simply deallocate the
184
* cluster */
185
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
186
"%#" PRIx64 " unaligned (L2 offset: %#"
187
PRIx64 ", L2 index: %#x)", offset,
188
l2_offset, j);
189
- if (!preallocated) {
190
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
191
qcow2_free_clusters(bs, offset, s->cluster_size,
192
QCOW2_DISCARD_ALWAYS);
193
}
194
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
195
196
ret = qcow2_pre_write_overlap_check(bs, 0, offset, s->cluster_size);
197
if (ret < 0) {
198
- if (!preallocated) {
199
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
200
qcow2_free_clusters(bs, offset, s->cluster_size,
201
QCOW2_DISCARD_ALWAYS);
202
}
203
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
204
205
ret = bdrv_pwrite_zeroes(bs->file, offset, s->cluster_size, 0);
206
if (ret < 0) {
207
- if (!preallocated) {
208
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
209
qcow2_free_clusters(bs, offset, s->cluster_size,
210
QCOW2_DISCARD_ALWAYS);
211
}
212
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
213
index XXXXXXX..XXXXXXX 100644
214
--- a/block/qcow2-refcount.c
215
+++ b/block/qcow2-refcount.c
216
@@ -XXX,XX +XXX,XX @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
217
}
218
break;
219
case QCOW2_CLUSTER_NORMAL:
220
- case QCOW2_CLUSTER_ZERO:
221
- if (l2_entry & L2E_OFFSET_MASK) {
222
- if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
223
- qcow2_signal_corruption(bs, false, -1, -1,
224
- "Cannot free unaligned cluster %#llx",
225
- l2_entry & L2E_OFFSET_MASK);
226
- } else {
227
- qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
228
- nb_clusters << s->cluster_bits, type);
229
- }
230
+ case QCOW2_CLUSTER_ZERO_ALLOC:
231
+ if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
232
+ qcow2_signal_corruption(bs, false, -1, -1,
233
+ "Cannot free unaligned cluster %#llx",
234
+ l2_entry & L2E_OFFSET_MASK);
235
+ } else {
236
+ qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
237
+ nb_clusters << s->cluster_bits, type);
238
}
239
break;
240
+ case QCOW2_CLUSTER_ZERO_PLAIN:
241
case QCOW2_CLUSTER_UNALLOCATED:
242
break;
243
default:
244
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
245
break;
246
247
case QCOW2_CLUSTER_NORMAL:
248
- case QCOW2_CLUSTER_ZERO:
249
+ case QCOW2_CLUSTER_ZERO_ALLOC:
250
if (offset_into_cluster(s, offset)) {
251
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
252
- "cluster offset %#" PRIx64
253
+ qcow2_signal_corruption(bs, true, -1, -1, "Cluster "
254
+ "allocation offset %#" PRIx64
255
" unaligned (L2 offset: %#"
256
PRIx64 ", L2 index: %#x)",
257
offset, l2_offset, j);
258
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
259
}
260
261
cluster_index = offset >> s->cluster_bits;
262
- if (!cluster_index) {
263
- /* unallocated */
264
- refcount = 0;
265
- break;
266
- }
267
+ assert(cluster_index);
268
if (addend != 0) {
269
ret = qcow2_update_cluster_refcount(bs,
270
cluster_index, abs(addend), addend < 0,
271
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
272
}
273
break;
274
275
+ case QCOW2_CLUSTER_ZERO_PLAIN:
276
case QCOW2_CLUSTER_UNALLOCATED:
277
refcount = 0;
278
break;
279
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
280
}
281
break;
282
283
- case QCOW2_CLUSTER_ZERO:
284
- if ((l2_entry & L2E_OFFSET_MASK) == 0) {
285
- break;
286
- }
287
- /* fall through */
288
-
289
+ case QCOW2_CLUSTER_ZERO_ALLOC:
290
case QCOW2_CLUSTER_NORMAL:
291
{
292
uint64_t offset = l2_entry & L2E_OFFSET_MASK;
293
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
294
break;
295
}
296
297
+ case QCOW2_CLUSTER_ZERO_PLAIN:
298
case QCOW2_CLUSTER_UNALLOCATED:
299
break;
300
301
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
302
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
303
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
304
305
- if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
306
- ((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
307
+ if (cluster_type == QCOW2_CLUSTER_NORMAL ||
308
+ cluster_type == QCOW2_CLUSTER_ZERO_ALLOC) {
309
ret = qcow2_get_refcount(bs,
310
data_offset >> s->cluster_bits,
311
&refcount);
312
diff --git a/block/qcow2.c b/block/qcow2.c
313
index XXXXXXX..XXXXXXX 100644
314
--- a/block/qcow2.c
315
+++ b/block/qcow2.c
316
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
317
*file = bs->file->bs;
318
status |= BDRV_BLOCK_OFFSET_VALID | cluster_offset;
319
}
320
- if (ret == QCOW2_CLUSTER_ZERO) {
321
+ if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) {
322
status |= BDRV_BLOCK_ZERO;
323
} else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
324
status |= BDRV_BLOCK_DATA;
325
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
326
}
327
break;
328
329
- case QCOW2_CLUSTER_ZERO:
330
+ case QCOW2_CLUSTER_ZERO_PLAIN:
331
+ case QCOW2_CLUSTER_ZERO_ALLOC:
332
qemu_iovec_memset(&hd_qiov, 0, 0, cur_bytes);
333
break;
334
335
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
336
count = s->cluster_size;
337
nr = s->cluster_size;
338
ret = qcow2_get_cluster_offset(bs, offset, &nr, &off);
339
- if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO) {
340
+ if (ret != QCOW2_CLUSTER_UNALLOCATED &&
341
+ ret != QCOW2_CLUSTER_ZERO_PLAIN &&
342
+ ret != QCOW2_CLUSTER_ZERO_ALLOC) {
343
qemu_co_mutex_unlock(&s->lock);
344
return -ENOTSUP;
345
}
346
diff --git a/block/qcow2.h b/block/qcow2.h
347
index XXXXXXX..XXXXXXX 100644
348
--- a/block/qcow2.h
349
+++ b/block/qcow2.h
350
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
351
352
typedef enum QCow2ClusterType {
353
QCOW2_CLUSTER_UNALLOCATED,
354
+ QCOW2_CLUSTER_ZERO_PLAIN,
355
+ QCOW2_CLUSTER_ZERO_ALLOC,
356
QCOW2_CLUSTER_NORMAL,
357
QCOW2_CLUSTER_COMPRESSED,
358
- QCOW2_CLUSTER_ZERO
359
} QCow2ClusterType;
360
361
typedef enum QCow2MetadataOverlap {
362
@@ -XXX,XX +XXX,XX @@ static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
363
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
364
return QCOW2_CLUSTER_COMPRESSED;
365
} else if (l2_entry & QCOW_OFLAG_ZERO) {
366
- return QCOW2_CLUSTER_ZERO;
367
+ if (l2_entry & L2E_OFFSET_MASK) {
368
+ return QCOW2_CLUSTER_ZERO_ALLOC;
369
+ }
370
+ return QCOW2_CLUSTER_ZERO_PLAIN;
371
} else if (!(l2_entry & L2E_OFFSET_MASK)) {
372
return QCOW2_CLUSTER_UNALLOCATED;
373
} else {
374
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
375
index XXXXXXX..XXXXXXX 100644
376
--- a/tests/qemu-iotests/060.out
377
+++ b/tests/qemu-iotests/060.out
378
@@ -XXX,XX +XXX,XX @@ qemu-img: Error while amending options: Input/output error
379
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
380
wrote 65536/65536 bytes at offset 0
381
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
382
-qcow2: Marking image as corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
383
+qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
384
read failed: Input/output error
385
386
=== Testing unaligned pre-allocated zero cluster ===
387
@@ -XXX,XX +XXX,XX @@ discard 65536/65536 bytes at offset 0
388
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
389
wrote 65536/65536 bytes at offset 0
390
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
391
-qcow2: Image is corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
392
+qcow2: Image is corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
393
read failed: Input/output error
394
read failed: Input/output error
395
396
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
397
wrote 131072/131072 bytes at offset 0
398
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
399
qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further non-fatal corruption events will be suppressed
400
-qcow2: Marking image as corrupt: Data cluster offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
401
+qcow2: Marking image as corrupt: Cluster allocation offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
402
discard 65536/65536 bytes at offset 0
403
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
404
read failed: Input/output error
405
--
406
1.8.3.1
407
408
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Similar to discard_single_l2(), we should try to avoid dirtying
4
the L2 cache when the cluster we are changing already has the
5
right characteristics.
6
7
Note that by the time we get to zero_single_l2(), BDRV_REQ_MAY_UNMAP
8
is a requirement to unallocate a cluster (this is because the block
9
layer clears that flag if discard.* flags during open requested that
10
we never punch holes - see the conversation around commit 170f4b2e,
11
https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg07306.html).
12
Therefore, this patch can only reuse a zero cluster as-is if either
13
unmapping is not requested, or if the zero cluster was not associated
14
with an allocation.
15
16
Technically, there are some cases where an unallocated cluster
17
already reads as all zeroes (namely, when there is no backing file
18
[easy: check bs->backing], or when the backing file also reads as
19
zeroes [harder: we can't check bdrv_get_block_status since we are
20
already holding the lock]), where the guest would not immediately see
21
a difference if we left that cluster unallocated. But if the user
22
did not request unmapping, leaving an unallocated cluster is wrong;
23
and even if the user DID request unmapping, keeping a cluster
24
unallocated risks a subtle semantic change of guest-visible contents
25
if a backing file is later added, and it is not worth auditing
26
whether all internal uses such as mirror properly avoid an unmap
27
request. Thus, this patch is intentionally limited to just clusters
28
that are already marked as zero.
29
30
Signed-off-by: Eric Blake <eblake@redhat.com>
31
Reviewed-by: Max Reitz <mreitz@redhat.com>
32
Message-id: 20170507000552.20847-8-eblake@redhat.com
33
Signed-off-by: Max Reitz <mreitz@redhat.com>
34
---
35
block/qcow2-cluster.c | 15 +++++++++++++--
36
1 file changed, 13 insertions(+), 2 deletions(-)
37
38
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/block/qcow2-cluster.c
41
+++ b/block/qcow2-cluster.c
42
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
43
int l2_index;
44
int ret;
45
int i;
46
+ bool unmap = !!(flags & BDRV_REQ_MAY_UNMAP);
47
48
ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
49
if (ret < 0) {
50
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
51
52
for (i = 0; i < nb_clusters; i++) {
53
uint64_t old_offset;
54
+ QCow2ClusterType cluster_type;
55
56
old_offset = be64_to_cpu(l2_table[l2_index + i]);
57
58
- /* Update L2 entries */
59
+ /*
60
+ * Minimize L2 changes if the cluster already reads back as
61
+ * zeroes with correct allocation.
62
+ */
63
+ cluster_type = qcow2_get_cluster_type(old_offset);
64
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN ||
65
+ (cluster_type == QCOW2_CLUSTER_ZERO_ALLOC && !unmap)) {
66
+ continue;
67
+ }
68
+
69
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);
70
- if (old_offset & QCOW_OFLAG_COMPRESSED || flags & BDRV_REQ_MAY_UNMAP) {
71
+ if (cluster_type == QCOW2_CLUSTER_COMPRESSED || unmap) {
72
l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);
73
qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);
74
} else {
75
--
76
1.8.3.1
77
78
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
No tests were covering write zeroes with unmap. Additionally,
4
I needed to prove that my previous patches for correct status
5
reporting and write zeroes optimizations actually had an impact.
6
7
The test works for cluster_size between 8k and 2M (for smaller
8
sizes, it fails because our allocation patterns are not contiguous
9
with small clusters - in part, the largest consecutive allocation
10
we tend to get is often bounded by the size covered by one L2
11
table).
12
13
Note that testing for zero clusters is tricky: 'qemu-io map'
14
reports whether data comes from the current layer of the image
15
(useful for sniffing out which regions of the file have
16
QCOW_OFLAG_ZERO) - but doesn't show which clusters have mappings;
17
while 'qemu-img map' sees "zero":true for both unallocated and
18
zero clusters for any qcow2 with no backing layer (so less useful
19
at detecting true zero clusters), but reliably shows mappings.
20
So we have to rely on both queries side-by-side at each point of
21
the test.
22
23
Signed-off-by: Eric Blake <eblake@redhat.com>
24
Reviewed-by: Max Reitz <mreitz@redhat.com>
25
Message-id: 20170507000552.20847-10-eblake@redhat.com
26
Signed-off-by: Max Reitz <mreitz@redhat.com>
27
---
28
tests/qemu-iotests/179 | 130 +++++++++++++++++++++++++++++++++++++
29
tests/qemu-iotests/179.out | 156 +++++++++++++++++++++++++++++++++++++++++++++
30
tests/qemu-iotests/group | 1 +
31
3 files changed, 287 insertions(+)
32
create mode 100755 tests/qemu-iotests/179
33
create mode 100644 tests/qemu-iotests/179.out
34
35
diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179
36
new file mode 100755
37
index XXXXXXX..XXXXXXX
38
--- /dev/null
39
+++ b/tests/qemu-iotests/179
40
@@ -XXX,XX +XXX,XX @@
41
+#!/bin/bash
42
+#
43
+# Test case for write zeroes with unmap
44
+#
45
+# Copyright (C) 2017 Red Hat, Inc.
46
+#
47
+# This program is free software; you can redistribute it and/or modify
48
+# it under the terms of the GNU General Public License as published by
49
+# the Free Software Foundation; either version 2 of the License, or
50
+# (at your option) any later version.
51
+#
52
+# This program is distributed in the hope that it will be useful,
53
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
54
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
+# GNU General Public License for more details.
56
+#
57
+# You should have received a copy of the GNU General Public License
58
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
59
+#
60
+
61
+# creator
62
+owner=eblake@redhat.com
63
+
64
+seq="$(basename $0)"
65
+echo "QA output created by $seq"
66
+
67
+here="$PWD"
68
+status=1    # failure is the default!
69
+
70
+_cleanup()
71
+{
72
+    _cleanup_test_img
73
+}
74
+trap "_cleanup; exit \$status" 0 1 2 3 15
75
+
76
+# get standard environment, filters and checks
77
+. ./common.rc
78
+. ./common.filter
79
+
80
+_supported_fmt qcow2
81
+_supported_proto file
82
+_supported_os Linux
83
+
84
+# v2 images can't mark clusters as zero
85
+_unsupported_imgopts compat=0.10
86
+
87
+echo
88
+echo '=== Testing write zeroes with unmap ==='
89
+echo
90
+
91
+TEST_IMG="$TEST_IMG.base" _make_test_img 64M
92
+_make_test_img -b "$TEST_IMG.base"
93
+
94
+# Offsets chosen at or near 2M boundaries so test works at all cluster sizes
95
+# 8k and larger (smaller clusters fail due to non-contiguous allocations)
96
+
97
+# Aligned writes to unallocated cluster should not allocate mapping, but must
98
+# mark cluster as zero, whether or not unmap was requested
99
+$QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
100
+$QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
101
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
102
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
103
+
104
+# Unaligned writes need not allocate mapping if the cluster already reads
105
+# as zero, but must mark cluster as zero, whether or not unmap was requested
106
+$QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
107
+$QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
108
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
109
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
110
+
111
+# Requesting unmap of normal data must deallocate; omitting unmap should
112
+# preserve the mapping
113
+$QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
114
+$QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
115
+$QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
116
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
117
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
118
+
119
+# Likewise when writing on already-mapped zero data
120
+$QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
121
+$QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
122
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
123
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
124
+
125
+# Writing on unmapped zeroes does not allocate
126
+$QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
127
+$QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
128
+$QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
129
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
130
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
131
+
132
+# Writing zero overrides a backing file, regardless of backing cluster type
133
+$QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
134
+$QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
135
+$QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
136
+$QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
137
+$QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
138
+$QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
139
+$QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
140
+$QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
141
+$QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
143
+
144
+# Final check that mappings are correct and images are still sane
145
+TEST_IMG="$TEST_IMG.base" _check_test_img
146
+_check_test_img
147
+
148
+echo
149
+echo '=== Testing cache optimization ==='
150
+echo
151
+
152
+BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
153
+
154
+cat > "$TEST_DIR/blkdebug.conf" <<EOF
155
+[inject-error]
156
+event = "l2_update"
157
+errno = "5"
158
+immediately = "on"
159
+once = "off"
160
+EOF
161
+
162
+# None of the following writes should trigger an L2 update, because the
163
+# cluster already reads as zero, and we don't have to change allocation
164
+$QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
165
+$QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
166
+$QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
167
+
168
+# success, all done
169
+echo '*** done'
170
+status=0
171
diff --git a/tests/qemu-iotests/179.out b/tests/qemu-iotests/179.out
172
new file mode 100644
173
index XXXXXXX..XXXXXXX
174
--- /dev/null
175
+++ b/tests/qemu-iotests/179.out
176
@@ -XXX,XX +XXX,XX @@
177
+QA output created by 179
178
+
179
+=== Testing write zeroes with unmap ===
180
+
181
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 2097152/2097152 bytes at offset 2097152
184
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+wrote 2097152/2097152 bytes at offset 6291456
186
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
187
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
188
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
189
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
190
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
191
+56 MiB (0x3800000) bytes not allocated at offset 8 MiB (0x800000)
192
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
193
+wrote 2097150/2097150 bytes at offset 10485761
194
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+wrote 2097150/2097150 bytes at offset 14680065
196
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
197
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
198
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
199
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
200
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
201
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
202
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
203
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
204
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
205
+48 MiB (0x3000000) bytes not allocated at offset 16 MiB (0x1000000)
206
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
207
+wrote 14680064/14680064 bytes at offset 18874368
208
+14 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+wrote 2097152/2097152 bytes at offset 20971520
210
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+wrote 6291456/6291456 bytes at offset 25165824
212
+6 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
214
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
215
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
216
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
217
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
218
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
219
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
220
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
221
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
222
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
223
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
224
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
225
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
226
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
227
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
228
+{ "start": 25165824, "length": 6291456, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
229
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
230
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
231
+wrote 2097152/2097152 bytes at offset 27262976
232
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
233
+wrote 2097152/2097152 bytes at offset 29360128
234
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
235
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
236
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
237
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
238
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
239
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
240
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
241
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
242
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
243
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
244
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
245
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
246
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
247
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
248
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
249
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
250
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
251
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
252
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
253
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
254
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
255
+wrote 8388608/8388608 bytes at offset 33554432
256
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
257
+wrote 2097152/2097152 bytes at offset 35651584
258
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
259
+wrote 2097152/2097152 bytes at offset 37748736
260
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
261
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
262
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
263
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
264
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
265
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
266
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
267
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
268
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
269
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
270
+22 MiB (0x1600000) bytes allocated at offset 18 MiB (0x1200000)
271
+24 MiB (0x1800000) bytes not allocated at offset 40 MiB (0x2800000)
272
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
273
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
274
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
275
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
276
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
277
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
278
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
279
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
280
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
281
+wrote 8388608/8388608 bytes at offset 41943040
282
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+wrote 8388608/8388608 bytes at offset 50331648
284
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
285
+wrote 2097152/2097152 bytes at offset 44040192
286
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
287
+wrote 2097152/2097152 bytes at offset 46137344
288
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+wrote 2097152/2097152 bytes at offset 52428800
290
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
291
+wrote 2097152/2097152 bytes at offset 54525952
292
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
293
+wrote 2097152/2097152 bytes at offset 60817408
294
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+wrote 2097152/2097152 bytes at offset 62914560
296
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
297
+42 MiB (0x2a00000) bytes not allocated at offset 0 bytes (0x0)
298
+4 MiB (0x400000) bytes allocated at offset 42 MiB (0x2a00000)
299
+4 MiB (0x400000) bytes not allocated at offset 46 MiB (0x2e00000)
300
+4 MiB (0x400000) bytes allocated at offset 50 MiB (0x3200000)
301
+4 MiB (0x400000) bytes not allocated at offset 54 MiB (0x3600000)
302
+4 MiB (0x400000) bytes allocated at offset 58 MiB (0x3a00000)
303
+2 MiB (0x200000) bytes not allocated at offset 62 MiB (0x3e00000)
304
+[{ "start": 0, "length": 18874368, "depth": 1, "zero": true, "data": false},
305
+{ "start": 18874368, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
306
+{ "start": 20971520, "length": 2097152, "depth": 1, "zero": true, "data": false},
307
+{ "start": 23068672, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
308
+{ "start": 25165824, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
309
+{ "start": 27262976, "length": 2097152, "depth": 1, "zero": true, "data": false},
310
+{ "start": 29360128, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
311
+{ "start": 31457280, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
312
+{ "start": 33554432, "length": 10485760, "depth": 1, "zero": true, "data": false},
313
+{ "start": 44040192, "length": 4194304, "depth": 0, "zero": true, "data": false},
314
+{ "start": 48234496, "length": 2097152, "depth": 1, "zero": true, "data": false},
315
+{ "start": 50331648, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
316
+{ "start": 52428800, "length": 4194304, "depth": 0, "zero": true, "data": false},
317
+{ "start": 56623104, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
318
+{ "start": 58720256, "length": 2097152, "depth": 1, "zero": true, "data": false},
319
+{ "start": 60817408, "length": 4194304, "depth": 0, "zero": true, "data": false},
320
+{ "start": 65011712, "length": 2097152, "depth": 1, "zero": true, "data": false}]
321
+No errors were found on the image.
322
+No errors were found on the image.
323
+
324
+=== Testing cache optimization ===
325
+
326
+wrote 2097152/2097152 bytes at offset 20971520
327
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
328
+wrote 2097152/2097152 bytes at offset 20971520
329
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
330
+wrote 2097152/2097152 bytes at offset 29360128
331
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
332
+*** done
333
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
334
index XXXXXXX..XXXXXXX 100644
335
--- a/tests/qemu-iotests/group
336
+++ b/tests/qemu-iotests/group
337
@@ -XXX,XX +XXX,XX @@
338
175 auto quick
339
176 rw auto backing
340
177 rw auto quick
341
+179 rw auto quick
342
181 rw auto migration
343
182 rw auto quick
344
--
345
1.8.3.1
346
347
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We've already improved discards to operate efficiently on the tail
4
of an unaligned qcow2 image; it's time to make a similar improvement
5
to write zeroes. The special case is only valid at the tail
6
cluster of a file, where we must recognize that any sectors beyond
7
the image end would implicitly read as zero, and therefore should
8
not penalize our logic for widening a partial cluster into writing
9
the whole cluster as zero.
10
11
However, note that for now, the special case of end-of-file is only
12
recognized if there is no backing file, or if the backing file has
13
the same length; that's because when the backing file is shorter
14
than the active layer, we don't have code in place to recognize
15
that reads of a sector unallocated at the top and beyond the backing
16
end-of-file are implicitly zero. It's not much of a real loss,
17
because most people don't use images that aren't cluster-aligned,
18
or where the active layer is a different size than the backing
19
layer (especially where the difference falls within a single cluster).
20
21
Update test 154 to cover the new scenarios, using two images of
22
intentionally differing length.
23
24
While at it, fix the test to gracefully skip when run as
25
./check -qcow2 -o compat=0.10 154
26
since the older format lacks zero clusters already required earlier
27
in the test.
28
29
Signed-off-by: Eric Blake <eblake@redhat.com>
30
Reviewed-by: Max Reitz <mreitz@redhat.com>
31
Message-id: 20170507000552.20847-11-eblake@redhat.com
32
Signed-off-by: Max Reitz <mreitz@redhat.com>
33
---
34
block/qcow2.c | 7 ++
35
tests/qemu-iotests/154 | 160 ++++++++++++++++++++++++++++++++++++++++++++-
36
tests/qemu-iotests/154.out | 128 ++++++++++++++++++++++++++++++++++++
37
3 files changed, 293 insertions(+), 2 deletions(-)
38
39
diff --git a/block/qcow2.c b/block/qcow2.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/block/qcow2.c
42
+++ b/block/qcow2.c
43
@@ -XXX,XX +XXX,XX @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
44
BlockDriverState *file;
45
int64_t res;
46
47
+ if (start + count > bs->total_sectors) {
48
+ count = bs->total_sectors - start;
49
+ }
50
+
51
if (!count) {
52
return true;
53
}
54
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
55
uint32_t tail = (offset + count) % s->cluster_size;
56
57
trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count);
58
+ if (offset + count == bs->total_sectors * BDRV_SECTOR_SIZE) {
59
+ tail = 0;
60
+ }
61
62
if (head || tail) {
63
int64_t cl_start = (offset - head) >> BDRV_SECTOR_BITS;
64
diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154
65
index XXXXXXX..XXXXXXX 100755
66
--- a/tests/qemu-iotests/154
67
+++ b/tests/qemu-iotests/154
68
@@ -XXX,XX +XXX,XX @@
69
#
70
# qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
71
#
72
-# Copyright (C) 2016 Red Hat, Inc.
73
+# Copyright (C) 2016-2017 Red Hat, Inc.
74
#
75
# This program is free software; you can redistribute it and/or modify
76
# it under the terms of the GNU General Public License as published by
77
@@ -XXX,XX +XXX,XX @@ _supported_proto file
78
_supported_os Linux
79
80
CLUSTER_SIZE=4k
81
-size=128M
82
+size=$((128 * 1024 * 1024))
83
+
84
+# This test requires zero clusters, added in v3 images
85
+_unsupported_imgopts compat=0.10
86
87
echo
88
echo == backing file contains zeros ==
89
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io
90
91
$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
92
93
+echo
94
+echo == unaligned image tail cluster, no allocation needed ==
95
+
96
+# With no backing file, write to all or part of unallocated partial cluster
97
+# will mark the cluster as zero, but does not allocate.
98
+# Re-create the image each time to get back to unallocated clusters.
99
+
100
+# Write at the front: sector-wise, the request is: 128m... | 00 -- -- --
101
+_make_test_img $((size + 2048))
102
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
103
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
104
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
105
+
106
+# Write at the back: sector-wise, the request is: 128m... | -- -- -- 00
107
+_make_test_img $((size + 2048))
108
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
109
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
110
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
111
+
112
+# Write at middle: sector-wise, the request is: 128m... | -- 00 00 --
113
+_make_test_img $((size + 2048))
114
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
115
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
116
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
117
+
118
+# Write entire cluster: sector-wise, the request is: 128m... | 00 00 00 00
119
+_make_test_img $((size + 2048))
120
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
121
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
122
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
123
+
124
+# Repeat with backing file holding unallocated cluster.
125
+# TODO: Note that this forces an allocation, because we aren't yet able to
126
+# quickly detect that reads beyond EOF of the backing file are always zero
127
+CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
128
+
129
+# Write at the front: sector-wise, the request is:
130
+# backing: 128m... | -- --
131
+# active: 128m... | 00 -- -- --
132
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
133
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
134
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
135
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
136
+
137
+# Write at the back: sector-wise, the request is:
138
+# backing: 128m... | -- --
139
+# active: 128m... | -- -- -- 00
140
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
141
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
143
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
144
+
145
+# Write at middle: sector-wise, the request is:
146
+# backing: 128m... | -- --
147
+# active: 128m... | -- 00 00 --
148
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
149
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
150
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
151
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
152
+
153
+# Write entire cluster: sector-wise, the request is:
154
+# backing: 128m... | -- --
155
+# active: 128m... | 00 00 00 00
156
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
157
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
158
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
159
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
160
+
161
+# Repeat with backing file holding zero'd cluster
162
+# TODO: Note that this forces an allocation, because we aren't yet able to
163
+# quickly detect that reads beyond EOF of the backing file are always zero
164
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io
165
+
166
+# Write at the front: sector-wise, the request is:
167
+# backing: 128m... | 00 00
168
+# active: 128m... | 00 -- -- --
169
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
170
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
171
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
172
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
173
+
174
+# Write at the back: sector-wise, the request is:
175
+# backing: 128m... | 00 00
176
+# active: 128m... | -- -- -- 00
177
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
178
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
179
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
180
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
181
+
182
+# Write at middle: sector-wise, the request is:
183
+# backing: 128m... | 00 00
184
+# active: 128m... | -- 00 00 --
185
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
186
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
187
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
188
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
189
+
190
+# Write entire cluster: sector-wise, the request is:
191
+# backing: 128m... | 00 00
192
+# active: 128m... | 00 00 00 00
193
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
194
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
195
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
196
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
197
+
198
+# A preallocated cluster maintains its allocation, whether it stays as
199
+# data due to a partial write:
200
+# Convert 128m... | XX XX => ... | XX 00
201
+_make_test_img $((size + 1024))
202
+$QEMU_IO -c "write -P 1 $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
203
+$QEMU_IO -c "write -z $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
204
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
205
+$QEMU_IO -c "read -P 0 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
206
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
207
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
208
+
209
+# or because it is the entire cluster and can use the zero flag:
210
+# Convert 128m... | XX XX => ... | 00 00
211
+$QEMU_IO -c "write -z $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
212
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
213
+$QEMU_IO -c "read -P 0 $size 1024" "$TEST_IMG" | _filter_qemu_io
214
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
215
+
216
+echo
217
+echo == unaligned image tail cluster, allocation required ==
218
+
219
+# Write beyond backing file must COW
220
+# Backing file: 128m... | XX --
221
+# Active layer: 128m... | -- -- 00 --
222
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
223
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
224
+$QEMU_IO -c "write -P 1 $((size)) 512" "$TEST_IMG.base" | _filter_qemu_io
225
+$QEMU_IO -c "write -z $((size + 1024)) 512" "$TEST_IMG" | _filter_qemu_io
226
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
227
+$QEMU_IO -c "read -P 0 $((size + 512)) 1536" "$TEST_IMG" | _filter_qemu_io
228
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
229
+
230
+# Writes at boundaries of (partial) cluster must not lose mid-cluster data
231
+# Backing file: 128m: ... | -- XX
232
+# Active layer: 128m: ... | 00 -- -- 00
233
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
234
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
235
+$QEMU_IO -c "write -P 1 $((size + 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
236
+$QEMU_IO -c "write -z $((size)) 512" "$TEST_IMG" | _filter_qemu_io
237
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
238
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
239
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
240
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
241
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
242
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
243
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
244
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
245
+
246
# success, all done
247
echo "*** done"
248
rm -f $seq.full
249
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
250
index XXXXXXX..XXXXXXX 100644
251
--- a/tests/qemu-iotests/154.out
252
+++ b/tests/qemu-iotests/154.out
253
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 76800
254
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
255
{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
256
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
257
+
258
+== unaligned image tail cluster, no allocation needed ==
259
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
260
+wrote 512/512 bytes at offset 134217728
261
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
262
+2048/2048 bytes allocated at offset 128 MiB
263
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
264
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
265
+wrote 512/512 bytes at offset 134219264
266
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
267
+2048/2048 bytes allocated at offset 128 MiB
268
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
269
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
270
+wrote 1024/1024 bytes at offset 134218240
271
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
272
+2048/2048 bytes allocated at offset 128 MiB
273
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
274
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
275
+wrote 2048/2048 bytes at offset 134217728
276
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
277
+2048/2048 bytes allocated at offset 128 MiB
278
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
279
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
280
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
281
+wrote 512/512 bytes at offset 134217728
282
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+2048/2048 bytes allocated at offset 128 MiB
284
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
285
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
286
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
287
+wrote 512/512 bytes at offset 134219264
288
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+2048/2048 bytes allocated at offset 128 MiB
290
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
291
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
292
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
293
+wrote 1024/1024 bytes at offset 134218240
294
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+2048/2048 bytes allocated at offset 128 MiB
296
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
297
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
298
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
299
+wrote 2048/2048 bytes at offset 134217728
300
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
301
+2048/2048 bytes allocated at offset 128 MiB
302
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
303
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
304
+wrote 512/512 bytes at offset 134217728
305
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
306
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
307
+wrote 512/512 bytes at offset 134217728
308
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
309
+2048/2048 bytes allocated at offset 128 MiB
310
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
311
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
312
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
313
+wrote 512/512 bytes at offset 134219264
314
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
315
+2048/2048 bytes allocated at offset 128 MiB
316
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
317
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
318
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
319
+wrote 1024/1024 bytes at offset 134218240
320
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
321
+2048/2048 bytes allocated at offset 128 MiB
322
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
323
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
324
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
325
+wrote 2048/2048 bytes at offset 134217728
326
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
327
+2048/2048 bytes allocated at offset 128 MiB
328
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
329
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
330
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134218752
331
+wrote 1024/1024 bytes at offset 134217728
332
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
333
+wrote 512/512 bytes at offset 134218240
334
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
335
+read 512/512 bytes at offset 134217728
336
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
337
+read 512/512 bytes at offset 134218240
338
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
339
+1024/1024 bytes allocated at offset 128 MiB
340
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
341
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
342
+wrote 1024/1024 bytes at offset 134217728
343
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
344
+1024/1024 bytes allocated at offset 128 MiB
345
+read 1024/1024 bytes at offset 134217728
346
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
347
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
348
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
349
+
350
+== unaligned image tail cluster, allocation required ==
351
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
352
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
353
+wrote 512/512 bytes at offset 134217728
354
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
355
+wrote 512/512 bytes at offset 134218752
356
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357
+read 512/512 bytes at offset 134217728
358
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
359
+read 1536/1536 bytes at offset 134218240
360
+1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
361
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
362
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
363
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
364
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
365
+wrote 512/512 bytes at offset 134218240
366
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
367
+wrote 512/512 bytes at offset 134217728
368
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
369
+read 512/512 bytes at offset 134217728
370
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
371
+read 512/512 bytes at offset 134218240
372
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
373
+read 1024/1024 bytes at offset 134218752
374
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
375
+wrote 512/512 bytes at offset 134219264
376
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
377
+read 512/512 bytes at offset 134217728
378
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
379
+read 512/512 bytes at offset 134218240
380
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
381
+read 1024/1024 bytes at offset 134218752
382
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
383
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
384
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
385
*** done
386
--
387
1.8.3.1
388
389
diff view generated by jsdifflib