1
The following changes since commit 76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb:
1
The following changes since commit ee86981bda9ecd40c8daf81b7307b1d2aff68174:
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
migration: Revert postcopy-blocktime commit set (2018-01-23 10:08:05 +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 8c0c5e636e6b11eaf0556be31fceb68e0baff310:
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
Merge remote-tracking branch 'mreitz/tags/pull-block-2018-01-23' into queue-block (2018-01-23 12:40:46 +0100)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
15
16
Block layer patches
14
Block layer patches
17
15
18
----------------------------------------------------------------
16
----------------------------------------------------------------
19
Anton Nefedov (1):
17
Daniel Henrique Barboza (1):
20
qemu-img: wait for convert coroutines to complete
18
tests/qemu-iotests: adding savevm/loadvm with postcopy flag test
21
19
22
Christoph Hellwig (1):
20
Eric Blake (1):
23
nvme: Implement Write Zeroes
21
iotests: Split 177 into two parts for compat=0.10
24
22
25
Eric Blake (21):
23
Fam Zheng (1):
26
qemu-io: Improve alignment checks
24
osdep: Retry SETLK upon EINTR
27
qemu-io: Switch 'alloc' command to byte-based length
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
25
48
Fam Zheng (23):
26
Hikaru Nishida (1):
49
block: Make bdrv_perm_names public
27
hw/block: Fix pin-based interrupt behaviour of NVMe
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
28
73
John Snow (1):
29
Kevin Wolf (2):
74
blockdev: use drained_begin/end for qmp_block_resize
30
tests/.gitignore: Add test-bdrv-drain
31
Merge remote-tracking branch 'mreitz/tags/pull-block-2018-01-23' into queue-block
75
32
76
Kevin Wolf (7):
33
Max Reitz (24):
77
migration: Unify block node activation error handling
34
qcow2: Repair unaligned preallocated zero clusters
78
block: New BdrvChildRole.activate() for blk_resume_after_migration()
35
iotests: Make BD-{remove,insert}-medium use @id
79
block: Drop permissions when migration completes
36
tests/ahci: Switch tray and medium commands to @id
80
block: Inactivate parents before children
37
blockdev: Drop BD-{remove,insert}-medium's @device
81
block: Fix write/resize permissions for inactive images
38
blockdev: Mark BD-{remove,insert}-medium stable
82
file-posix: Remove .bdrv_inactivate/invalidate_cache
39
qemu-iotests: Fix locking issue in 102
83
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block
40
block/vmdk: Fix , instead of ; at end of line
41
qcow2: No persistent dirty bitmaps for compat=0.10
42
block/qcow: Add blkdebug events
43
block/vmdk: Add blkdebug events
44
iotests: Fix _img_info for backslashes
45
iotests: Drop format-specific in _filter_img_info
46
iotests: Forbid 020 for non-file protocols
47
iotests: Skip 103 for refcount_bits=1
48
iotests: Fix 020 for vmdk
49
iotests: Fix 051 for compat=0.10
50
iotests: Fix 059's reference output
51
iotests: Fix 067 for compat=0.10
52
iotests: Make 089 compatible with compat=0.10
53
iotests: Make 184 image-less
54
iotests: Make 191 work with qcow2 options
55
iotests: Filter compat-dependent info in 198
56
iotests: Make 059 pass on machines with little RAM
57
iotests: Disable some tests for compat=0.10
84
58
85
Max Reitz (5):
59
qapi/block-core.json | 42 ++----
86
qcow2: Fix preallocation size formula
60
hw/block/nvme.h | 1 +
87
qcow2: Reuse preallocated zero clusters
61
block/qcow.c | 16 ++
88
qcow2: Discard preallocated zero clusters
62
block/qcow2-bitmap.c | 10 ++
89
iotests: Extend test 066
63
block/qcow2-refcount.c | 70 +++++++--
90
MAINTAINERS: Add qemu-progress to the block layer
64
block/qcow2.c | 14 +-
65
block/vmdk.c | 18 ++-
66
blockdev.c | 30 +++-
67
hw/block/nvme.c | 39 ++++-
68
tests/ahci-test.c | 16 +-
69
util/osdep.c | 4 +-
70
tests/.gitignore | 1 +
71
tests/qemu-iotests/020 | 17 +--
72
tests/qemu-iotests/020.out | 6 +-
73
tests/qemu-iotests/051 | 2 +
74
tests/qemu-iotests/051.out | 1 +
75
tests/qemu-iotests/051.pc.out | 1 +
76
tests/qemu-iotests/059 | 4 +-
77
tests/qemu-iotests/059.out | 2 +-
78
tests/qemu-iotests/060 | 3 +-
79
tests/qemu-iotests/060.out | 9 ++
80
tests/qemu-iotests/067 | 3 +-
81
tests/qemu-iotests/067.out | 97 ++++--------
82
tests/qemu-iotests/080 | 5 +-
83
tests/qemu-iotests/089 | 4 +-
84
tests/qemu-iotests/089.out | 10 --
85
tests/qemu-iotests/093 | 6 +-
86
tests/qemu-iotests/102 | 7 +-
87
tests/qemu-iotests/102.out | 3 +-
88
tests/qemu-iotests/103 | 2 +
89
tests/qemu-iotests/118 | 184 +++++++++++------------
90
tests/qemu-iotests/130 | 2 +
91
tests/qemu-iotests/137 | 2 +
92
tests/qemu-iotests/139 | 2 +-
93
tests/qemu-iotests/155 | 60 ++++----
94
tests/qemu-iotests/176 | 2 +
95
tests/qemu-iotests/177 | 20 +--
96
tests/qemu-iotests/177.out | 22 +--
97
tests/qemu-iotests/184 | 25 +---
98
tests/qemu-iotests/184.out | 63 ++------
99
tests/qemu-iotests/191 | 5 +-
100
tests/qemu-iotests/191.out | 313 +++++++++++----------------------------
101
tests/qemu-iotests/198 | 8 +-
102
tests/qemu-iotests/198.out | 8 -
103
tests/qemu-iotests/201 | 120 +++++++++++++++
104
tests/qemu-iotests/201.out | 23 +++
105
tests/qemu-iotests/204 | 119 +++++++++++++++
106
tests/qemu-iotests/204.out | 63 ++++++++
107
tests/qemu-iotests/common.filter | 29 +++-
108
tests/qemu-iotests/common.rc | 2 +-
109
tests/qemu-iotests/group | 2 +
110
51 files changed, 870 insertions(+), 647 deletions(-)
111
create mode 100755 tests/qemu-iotests/201
112
create mode 100644 tests/qemu-iotests/201.out
113
create mode 100755 tests/qemu-iotests/204
114
create mode 100644 tests/qemu-iotests/204.out
91
115
92
MAINTAINERS | 1 +
93
block.c | 127 +++++++++++--
94
block/blkdebug.c | 264 +++++++++++++++++++++-----
95
block/block-backend.c | 81 +++++---
96
block/file-posix.c | 248 +++++++++++++++++++++++-
97
block/file-win32.c | 5 +
98
block/qcow2-cluster.c | 252 ++++++++++++++----------
99
block/qcow2-refcount.c | 148 +++++++--------
100
block/qcow2-snapshot.c | 7 +-
101
block/qcow2.c | 47 +++--
102
block/qcow2.h | 26 ++-
103
blockdev.c | 20 +-
104
hw/block/nvme.c | 26 +++
105
hw/block/nvme.h | 1 +
106
include/block/block.h | 41 ++--
107
include/block/block_int.h | 14 ++
108
include/qemu/osdep.h | 3 +
109
migration/migration.c | 13 +-
110
migration/savevm.c | 9 +-
111
qapi/block-core.json | 40 +++-
112
qemu-img-cmds.hx | 36 ++--
113
qemu-img.c | 179 ++++++++++++-----
114
qemu-io-cmds.c | 61 +++---
115
qemu-io.c | 42 +++-
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
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
It can be used outside of block.c for making user friendly messages.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
block.c | 2 +-
9
include/block/block.h | 2 ++
10
2 files changed, 3 insertions(+), 1 deletion(-)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static char *bdrv_child_user_desc(BdrvChild *c)
17
return g_strdup("another user");
18
}
19
20
-static char *bdrv_perm_names(uint64_t perm)
21
+char *bdrv_perm_names(uint64_t perm)
22
{
23
struct perm_name {
24
uint64_t perm;
25
diff --git a/include/block/block.h b/include/block/block.h
26
index XXXXXXX..XXXXXXX 100644
27
--- a/include/block/block.h
28
+++ b/include/block/block.h
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
1.8.3.1
40
41
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
block.c | 17 +++++++++++++++++
7
include/block/block.h | 1 +
8
include/block/block_int.h | 1 +
9
qapi/block-core.json | 3 +++
10
4 files changed, 22 insertions(+)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
17
* the parent. */
18
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
19
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
20
+ qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
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
+
50
+ if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) {
51
+ error_setg(errp,
52
+ BDRV_OPT_FORCE_SHARE
53
+ "=on can only be used with read-only images");
54
+ ret = -EINVAL;
55
+ goto fail_opts;
56
+ }
57
+
58
if (file != NULL) {
59
filename = blk_bs(file)->filename;
60
} else {
61
diff --git a/include/block/block.h b/include/block/block.h
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
--
107
1.8.3.1
108
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
block.c | 32 ++++++++++++++++++++++++--------
7
1 file changed, 24 insertions(+), 8 deletions(-)
8
9
diff --git a/block.c b/block.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/block.c
12
+++ b/block.c
13
@@ -XXX,XX +XXX,XX @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
14
static void bdrv_child_abort_perm_update(BdrvChild *c);
15
static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
16
17
+static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
18
+ BdrvChild *c,
19
+ const BdrvChildRole *role,
20
+ uint64_t parent_perm, uint64_t parent_shared,
21
+ uint64_t *nperm, uint64_t *nshared)
22
+{
23
+ if (bs->drv && bs->drv->bdrv_child_perm) {
24
+ bs->drv->bdrv_child_perm(bs, c, role,
25
+ parent_perm, parent_shared,
26
+ nperm, nshared);
27
+ }
28
+ if (child_bs && child_bs->force_share) {
29
+ *nshared = BLK_PERM_ALL;
30
+ }
31
+}
32
+
33
/*
34
* Check whether permissions on this node can be changed in a way that
35
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
36
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
37
/* Check all children */
38
QLIST_FOREACH(c, &bs->children, next) {
39
uint64_t cur_perm, cur_shared;
40
- drv->bdrv_child_perm(bs, c, c->role,
41
- cumulative_perms, cumulative_shared_perms,
42
- &cur_perm, &cur_shared);
43
+ bdrv_child_perm(bs, c->bs, c, c->role,
44
+ cumulative_perms, cumulative_shared_perms,
45
+ &cur_perm, &cur_shared);
46
ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
47
errp);
48
if (ret < 0) {
49
@@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
50
/* Update all children */
51
QLIST_FOREACH(c, &bs->children, next) {
52
uint64_t cur_perm, cur_shared;
53
- drv->bdrv_child_perm(bs, c, c->role,
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
--
74
1.8.3.1
75
76
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
This will force the opened images to allow sharing all permissions with other
4
programs.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
qemu-img.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++---------------
10
1 file changed, 117 insertions(+), 36 deletions(-)
11
12
diff --git a/qemu-img.c b/qemu-img.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/qemu-img.c
15
+++ b/qemu-img.c
16
@@ -XXX,XX +XXX,XX @@
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
{
54
BlockBackend *blk;
55
Error *local_err = NULL;
56
- QDict *options = NULL;
57
+ QDict *options = qdict_new();
58
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;
342
bool image_opts = false;
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
}
407
}
408
409
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
410
* Ignore the old backing file for unsafe rebase in case we want to correct
411
* the reference to a renamed or moved backing file.
412
*/
413
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
414
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
415
+ false);
416
if (!blk) {
417
ret = -1;
418
goto out;
419
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
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
--
560
1.8.3.1
561
562
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
qemu-img-cmds.hx | 36 ++++++++++++++++++------------------
7
1 file changed, 18 insertions(+), 18 deletions(-)
8
9
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
10
index XXXXXXX..XXXXXXX 100644
11
--- a/qemu-img-cmds.hx
12
+++ b/qemu-img-cmds.hx
13
@@ -XXX,XX +XXX,XX @@ STEXI
14
ETEXI
15
16
DEF("bench", img_bench,
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")
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")
19
STEXI
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}
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}
22
ETEXI
23
24
DEF("check", img_check,
25
- "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename")
26
+ "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] [-U] filename")
27
STEXI
28
-@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename}
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}
30
ETEXI
31
32
DEF("create", img_create,
33
@@ -XXX,XX +XXX,XX @@ STEXI
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
--
94
1.8.3.1
95
96
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
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>
7
---
8
qemu-io.c | 42 ++++++++++++++++++++++++++++++++++--------
9
1 file changed, 34 insertions(+), 8 deletions(-)
10
11
diff --git a/qemu-io.c b/qemu-io.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/qemu-io.c
14
+++ b/qemu-io.c
15
@@ -XXX,XX +XXX,XX @@
16
#include "qemu/readline.h"
17
#include "qemu/log.h"
18
#include "qapi/qmp/qstring.h"
19
+#include "qapi/qmp/qbool.h"
20
#include "qom/object_interfaces.h"
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
};
26
27
-static int openfile(char *name, int flags, bool writethrough, QDict *opts)
28
+static int openfile(char *name, int flags, bool writethrough, bool force_share,
29
+ QDict *opts)
30
{
31
Error *local_err = NULL;
32
BlockDriverState *bs;
33
@@ -XXX,XX +XXX,XX @@ static int openfile(char *name, int flags, bool writethrough, QDict *opts)
34
return 1;
35
}
36
37
+ if (force_share) {
38
+ if (!opts) {
39
+ opts = qdict_new();
40
+ }
41
+ if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
42
+ && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
43
+ error_report("-U conflicts with image options");
44
+ QDECREF(opts);
45
+ return 1;
46
+ }
47
+ qdict_put(opts, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
48
+ }
49
qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err);
50
if (!qemuio_blk) {
51
error_reportf_err(local_err, "can't open%s%s: ",
52
@@ -XXX,XX +XXX,XX @@ static void open_help(void)
53
" -r, -- open file read-only\n"
54
" -s, -- use snapshot file\n"
55
" -n, -- disable host cache, short for -t none\n"
56
+" -U, -- force shared permissions\n"
57
" -k, -- use kernel AIO implementation (on Linux only)\n"
58
" -t, -- use the given cache mode for the image\n"
59
" -d, -- use the given discard mode for the image\n"
60
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t open_cmd = {
61
.argmin = 1,
62
.argmax = -1,
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)
112
{
113
int readonly = 0;
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)
120
{ "trace", required_argument, NULL, 'T' },
121
{ "object", required_argument, NULL, OPTION_OBJECT },
122
{ "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
123
+ { "force-share", no_argument, 0, 'U'},
124
{ NULL, 0, NULL, 0 }
125
};
126
int c;
127
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
128
QDict *opts = NULL;
129
const char *format = NULL;
130
char *trace_file = NULL;
131
+ bool force_share = false;
132
133
#ifdef CONFIG_POSIX
134
signal(SIGPIPE, SIG_IGN);
135
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
136
case 'h':
137
usage(progname);
138
exit(0);
139
+ case 'U':
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
--
165
1.8.3.1
166
167
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
1
From: Fam Zheng <famz@redhat.com>
1
From: Fam Zheng <famz@redhat.com>
2
2
3
We could hit lock failure if there is a signal that makes fcntl return
4
-1 and errno set to EINTR. In this case we should retry.
5
6
Cc: qemu-stable@nongnu.org
3
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Fam Zheng <famz@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
10
---
6
util/osdep.c | 20 ++++++++++----------
11
util/osdep.c | 4 +++-
7
1 file changed, 10 insertions(+), 10 deletions(-)
12
1 file changed, 3 insertions(+), 1 deletion(-)
8
13
9
diff --git a/util/osdep.c b/util/osdep.c
14
diff --git a/util/osdep.c b/util/osdep.c
10
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
11
--- a/util/osdep.c
16
--- a/util/osdep.c
12
+++ b/util/osdep.c
17
+++ b/util/osdep.c
13
@@ -XXX,XX +XXX,XX @@ extern int madvise(caddr_t, size_t, int);
14
#include "qemu/error-report.h"
15
#include "monitor/monitor.h"
16
17
+#ifdef F_OFD_SETLK
18
+#define QEMU_SETLK F_OFD_SETLK
19
+#define QEMU_GETLK F_OFD_GETLK
20
+#else
21
+#define QEMU_SETLK F_SETLK
22
+#define QEMU_GETLK F_GETLK
23
+#endif
24
+
25
static bool fips_enabled = false;
26
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)
18
@@ -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,
19
.l_type = fl_type,
39
};
20
};
40
- ret = fcntl(fd, F_OFD_SETLK, &fl);
21
qemu_probe_lock_ops();
41
+ ret = fcntl(fd, QEMU_SETLK, &fl);
22
- ret = fcntl(fd, fcntl_op_setlk, &fl);
23
+ do {
24
+ ret = fcntl(fd, fcntl_op_setlk, &fl);
25
+ } while (ret == -1 && errno == EINTR);
42
return ret == -1 ? -errno : 0;
26
return ret == -1 ? -errno : 0;
43
-#else
44
- return -ENOTSUP;
45
-#endif
46
}
27
}
47
28
48
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
49
@@ -XXX,XX +XXX,XX @@ int qemu_unlock_fd(int fd, int64_t start, int64_t len)
50
51
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
52
{
53
-#ifdef F_OFD_SETLK
54
int ret;
55
struct flock fl = {
56
.l_whence = SEEK_SET,
57
@@ -XXX,XX +XXX,XX @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
58
.l_len = len,
59
.l_type = exclusive ? F_WRLCK : F_RDLCK,
60
};
61
- ret = fcntl(fd, F_OFD_GETLK, &fl);
62
+ ret = fcntl(fd, QEMU_GETLK, &fl);
63
if (ret == -1) {
64
return -errno;
65
} else {
66
return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
67
}
68
-#else
69
- return -ENOTSUP;
70
-#endif
71
}
72
#endif
73
74
--
29
--
75
1.8.3.1
30
2.13.6
76
31
77
32
diff view generated by jsdifflib
1
From: Christoph Hellwig <hch@lst.de>
1
From: Hikaru Nishida <hikarupsp@gmail.com>
2
2
3
Signed-off-by: Keith Busch <keith.busch@intel.com>
3
Pin-based interrupt of NVMe controller did not work properly
4
[hch: ported over from qemu-nvme.git to mainline]
4
because using an obsolated function pci_irq_pulse().
5
Signed-off-by: Christoph Hellwig <hch@lst.de>
5
To fix this, change to use pci_irq_assert() / pci_irq_deassert()
6
Acked-by: Keith Busch <keith.busch@intel.com>
6
instead of pci_irq_pulse().
7
8
Signed-off-by: Hikaru Nishida <hikarupsp@gmail.com>
9
Reviewed-by: Keith Busch <keith.busch@intel.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
11
---
9
hw/block/nvme.c | 26 ++++++++++++++++++++++++++
10
hw/block/nvme.h | 1 +
12
hw/block/nvme.h | 1 +
11
2 files changed, 27 insertions(+)
13
hw/block/nvme.c | 39 ++++++++++++++++++++++++++++++++++-----
14
2 files changed, 35 insertions(+), 5 deletions(-)
12
15
16
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/block/nvme.h
19
+++ b/hw/block/nvme.h
20
@@ -XXX,XX +XXX,XX @@ typedef struct NvmeCtrl {
21
uint32_t cmbsz;
22
uint32_t cmbloc;
23
uint8_t *cmbuf;
24
+ uint64_t irq_status;
25
26
char *serial;
27
NvmeNamespace *namespaces;
13
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
28
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
14
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/block/nvme.c
30
--- a/hw/block/nvme.c
16
+++ b/hw/block/nvme.c
31
+++ b/hw/block/nvme.c
17
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
32
@@ -XXX,XX +XXX,XX @@ static uint8_t nvme_sq_empty(NvmeSQueue *sq)
18
return NVME_NO_COMPLETE;
33
return sq->head == sq->tail;
19
}
34
}
20
35
21
+static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
36
-static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq)
22
+ NvmeRequest *req)
37
+static void nvme_irq_check(NvmeCtrl *n)
23
+{
38
+{
24
+ NvmeRwCmd *rw = (NvmeRwCmd *)cmd;
39
+ if (msix_enabled(&(n->parent_obj))) {
25
+ const uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
40
+ return;
26
+ const uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
27
+ uint64_t slba = le64_to_cpu(rw->slba);
28
+ uint32_t nlb = le16_to_cpu(rw->nlb) + 1;
29
+ uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
30
+ uint32_t aio_nlb = nlb << (data_shift - BDRV_SECTOR_BITS);
31
+
32
+ if (slba + nlb > ns->id_ns.nsze) {
33
+ return NVME_LBA_RANGE | NVME_DNR;
34
+ }
41
+ }
35
+
42
+ if (~n->bar.intms & n->irq_status) {
36
+ req->has_sg = false;
43
+ pci_irq_assert(&n->parent_obj);
37
+ block_acct_start(blk_get_stats(n->conf.blk), &req->acct, 0,
44
+ } else {
38
+ BLOCK_ACCT_WRITE);
45
+ pci_irq_deassert(&n->parent_obj);
39
+ req->aiocb = blk_aio_pwrite_zeroes(n->conf.blk, aio_slba, aio_nlb,
46
+ }
40
+ BDRV_REQ_MAY_UNMAP, nvme_rw_cb, req);
41
+ return NVME_NO_COMPLETE;
42
+}
47
+}
43
+
48
+
44
static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
49
+static void nvme_irq_assert(NvmeCtrl *n, NvmeCQueue *cq)
45
NvmeRequest *req)
46
{
50
{
47
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
51
if (cq->irq_enabled) {
48
switch (cmd->opcode) {
52
if (msix_enabled(&(n->parent_obj))) {
49
case NVME_CMD_FLUSH:
53
@@ -XXX,XX +XXX,XX @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq)
50
return nvme_flush(n, ns, cmd, req);
54
msix_notify(&(n->parent_obj), cq->vector);
51
+ case NVME_CMD_WRITE_ZEROS:
55
} else {
52
+ return nvme_write_zeros(n, ns, cmd, req);
56
trace_nvme_irq_pin();
53
case NVME_CMD_WRITE:
57
- pci_irq_pulse(&n->parent_obj);
54
case NVME_CMD_READ:
58
+ assert(cq->cqid < 64);
55
return nvme_rw(n, ns, cmd, req);
59
+ n->irq_status |= 1 << cq->cqid;
56
@@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev)
60
+ nvme_irq_check(n);
57
id->sqes = (0x6 << 4) | 0x6;
61
}
58
id->cqes = (0x4 << 4) | 0x4;
62
} else {
59
id->nn = cpu_to_le32(n->num_namespaces);
63
trace_nvme_irq_masked();
60
+ id->oncs = cpu_to_le16(NVME_ONCS_WRITE_ZEROS);
64
}
61
id->psd[0].mp = cpu_to_le16(0x9c4);
65
}
62
id->psd[0].enlat = cpu_to_le32(0x10);
66
63
id->psd[0].exlat = cpu_to_le32(0x4);
67
+static void nvme_irq_deassert(NvmeCtrl *n, NvmeCQueue *cq)
64
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
68
+{
65
index XXXXXXX..XXXXXXX 100644
69
+ if (cq->irq_enabled) {
66
--- a/hw/block/nvme.h
70
+ if (msix_enabled(&(n->parent_obj))) {
67
+++ b/hw/block/nvme.h
71
+ return;
68
@@ -XXX,XX +XXX,XX @@ enum NvmeIoCommands {
72
+ } else {
69
NVME_CMD_READ = 0x02,
73
+ assert(cq->cqid < 64);
70
NVME_CMD_WRITE_UNCOR = 0x04,
74
+ n->irq_status &= ~(1 << cq->cqid);
71
NVME_CMD_COMPARE = 0x05,
75
+ nvme_irq_check(n);
72
+ NVME_CMD_WRITE_ZEROS = 0x08,
76
+ }
73
NVME_CMD_DSM = 0x09,
77
+ }
74
};
78
+}
75
79
+
80
static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1,
81
uint64_t prp2, uint32_t len, NvmeCtrl *n)
82
{
83
@@ -XXX,XX +XXX,XX @@ static void nvme_post_cqes(void *opaque)
84
sizeof(req->cqe));
85
QTAILQ_INSERT_TAIL(&sq->req_list, req, entry);
86
}
87
- nvme_isr_notify(n, cq);
88
+ nvme_irq_assert(n, cq);
89
}
90
91
static void nvme_enqueue_req_completion(NvmeCQueue *cq, NvmeRequest *req)
92
@@ -XXX,XX +XXX,XX @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,
93
n->bar.intmc = n->bar.intms;
94
trace_nvme_mmio_intm_set(data & 0xffffffff,
95
n->bar.intmc);
96
+ nvme_irq_check(n);
97
break;
98
case 0x10: /* INTMC */
99
if (unlikely(msix_enabled(&(n->parent_obj)))) {
100
@@ -XXX,XX +XXX,XX @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,
101
n->bar.intmc = n->bar.intms;
102
trace_nvme_mmio_intm_clr(data & 0xffffffff,
103
n->bar.intmc);
104
+ nvme_irq_check(n);
105
break;
106
case 0x14: /* CC */
107
trace_nvme_mmio_cfg(data & 0xffffffff);
108
@@ -XXX,XX +XXX,XX @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
109
timer_mod(cq->timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 500);
110
}
111
112
- if (cq->tail != cq->head) {
113
- nvme_isr_notify(n, cq);
114
+ if (cq->tail == cq->head) {
115
+ nvme_irq_deassert(n, cq);
116
}
117
} else {
118
/* Submission queue doorbell write */
76
--
119
--
77
1.8.3.1
120
2.13.6
78
121
79
122
diff view generated by jsdifflib
1
Now that the block layer takes care to request a lot less permissions
1
Commit 881cfd17 added a new test binary, include it in .gitignore.
2
for inactive nodes, the special-casing in file-posix isn't necessary any
3
more.
4
2
3
Reported-by: Eric Blake <eblake@redhat.com>
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>
5
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
6
---
8
block/file-posix.c | 33 ---------------------------------
7
tests/.gitignore | 1 +
9
1 file changed, 33 deletions(-)
8
1 file changed, 1 insertion(+)
10
9
11
diff --git a/block/file-posix.c b/block/file-posix.c
10
diff --git a/tests/.gitignore b/tests/.gitignore
12
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
13
--- a/block/file-posix.c
12
--- a/tests/.gitignore
14
+++ b/block/file-posix.c
13
+++ b/tests/.gitignore
15
@@ -XXX,XX +XXX,XX @@ static void raw_abort_perm_update(BlockDriverState *bs)
14
@@ -XXX,XX +XXX,XX @@ test-aio
16
raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
15
test-aio-multithread
17
}
16
test-arm-mptimer
18
17
test-base64
19
-static int raw_inactivate(BlockDriverState *bs)
18
+test-bdrv-drain
20
-{
19
test-bitops
21
- int ret;
20
test-bitcnt
22
- uint64_t perm = 0;
21
test-blockjob
23
- uint64_t shared = BLK_PERM_ALL;
24
-
25
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
26
- if (ret) {
27
- return ret;
28
- }
29
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
30
- return 0;
31
-}
32
-
33
-
34
-static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
35
-{
36
- BDRVRawState *s = bs->opaque;
37
- int ret;
38
-
39
- assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
40
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
41
- errp);
42
- if (ret) {
43
- return;
44
- }
45
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, s->perm, s->shared_perm, NULL);
46
-}
47
-
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
--
22
--
70
1.8.3.1
23
2.13.6
71
24
72
25
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
This patch implements a test case for the scenario that was failing
4
prior to the patch "migration/ram.c: do not set 'postcopy_running' in
5
POSTCOPY_INCOMING_END", commit acab30b85d.
6
7
This new test file 201 was derived from the test file 181 authored
8
by Kevin Wolf.
9
10
CC: Kevin Wolf <kwolf@redhat.com>
11
CC: Max Reitz <mreitz@redhat.com>
12
CC: Cleber Rosa <crosa@redhat.com>
13
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
15
---
6
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++++++
16
tests/qemu-iotests/201 | 120 +++++++++++++++++++++++++++++++++++++++++++++
7
tests/qemu-iotests/153.out | 390 +++++++++++++++++++++++++++++++++++++++++++++
17
tests/qemu-iotests/201.out | 23 +++++++++
8
tests/qemu-iotests/group | 1 +
18
tests/qemu-iotests/group | 1 +
9
3 files changed, 624 insertions(+)
19
3 files changed, 144 insertions(+)
10
create mode 100755 tests/qemu-iotests/153
20
create mode 100755 tests/qemu-iotests/201
11
create mode 100644 tests/qemu-iotests/153.out
21
create mode 100644 tests/qemu-iotests/201.out
12
22
13
diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
23
diff --git a/tests/qemu-iotests/201 b/tests/qemu-iotests/201
14
new file mode 100755
24
new file mode 100755
15
index XXXXXXX..XXXXXXX
25
index XXXXXXX..XXXXXXX
16
--- /dev/null
26
--- /dev/null
17
+++ b/tests/qemu-iotests/153
27
+++ b/tests/qemu-iotests/201
18
@@ -XXX,XX +XXX,XX @@
28
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
29
+#!/bin/bash
20
+#
30
+#
21
+# Test image locking
31
+# Test savevm and loadvm after live migration with postcopy flag
22
+#
32
+#
23
+# Copyright 2016, 2017 Red Hat, Inc.
33
+# Copyright (C) 2017, IBM Corporation.
34
+#
35
+# This file is derived from tests/qemu-iotests/181 by Kevin Wolf
24
+#
36
+#
25
+# This program is free software; you can redistribute it and/or modify
37
+# 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
38
+# 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
39
+# the Free Software Foundation; either version 2 of the License, or
28
+# (at your option) any later version.
40
+# (at your option) any later version.
...
...
32
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
+# GNU General Public License for more details.
45
+# GNU General Public License for more details.
34
+#
46
+#
35
+# You should have received a copy of the GNU General Public License
47
+# 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/>.
48
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
38
+
49
+
39
+# creator
50
+seq=`basename $0`
40
+owner=famz@redhat.com
41
+
42
+seq="$(basename $0)"
43
+echo "QA output created by $seq"
51
+echo "QA output created by $seq"
44
+
52
+
45
+here="$PWD"
46
+tmp=/tmp/$$
47
+status=1    # failure is the default!
53
+status=1    # failure is the default!
48
+
54
+
49
+_cleanup()
55
+MIG_SOCKET="${TEST_DIR}/migrate"
50
+{
51
+ _cleanup_test_img
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
+
56
+
60
+# get standard environment, filters and checks
57
+# get standard environment, filters and checks
61
+. ./common.rc
58
+. ./common.rc
62
+. ./common.filter
59
+. ./common.filter
63
+. ./common.qemu
60
+. ./common.qemu
64
+
61
+
65
+size=32M
62
+_cleanup()
66
+
67
+_check_ofd()
68
+{
63
+{
69
+ _make_test_img $size >/dev/null
64
+ rm -f "${MIG_SOCKET}"
70
+ if $QEMU_IMG_PROG info --image-opts "driver=file,locking=on,filename=$TEST_IMG" 2>&1 |
65
+ _cleanup_test_img
71
+ grep -q 'falling back to POSIX file'; then
66
+ _cleanup_qemu
72
+ return 1
73
+ else
74
+ return 0
75
+ fi
76
+}
67
+}
77
+
68
+trap "_cleanup; exit \$status" 0 1 2 3 15
78
+_check_ofd || _notrun "OFD lock not available"
79
+
69
+
80
+_supported_fmt qcow2
70
+_supported_fmt qcow2
81
+_supported_proto file
71
+_supported_proto generic
82
+_supported_os Linux
72
+_supported_os Linux
83
+
73
+
84
+_run_cmd()
74
+# Internal snapshots are (currently) impossible with refcount_bits=1
85
+{
75
+# This was taken from test 080
86
+ echo
76
+_unsupported_imgopts 'refcount_bits=1[^0-9]'
87
+ (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
88
+}
89
+
77
+
90
+function _do_run_qemu()
78
+size=64M
91
+{
79
+_make_test_img $size
92
+ (
93
+ if ! test -t 0; then
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
+}
101
+
102
+function _run_qemu_with_images()
103
+{
104
+ _do_run_qemu \
105
+ $(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
106
+ | _filter_testdir | _filter_qemu
107
+}
108
+
109
+echo "== readonly=off,force-share=on should be rejected =="
110
+_run_qemu_with_images null-co://,readonly=off,force-share=on
111
+
112
+for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
113
+ echo
114
+ echo "== Creating base image =="
115
+ TEST_IMG="${TEST_IMG}.base" _make_test_img $size
116
+
117
+ echo
118
+ echo "== Creating test image =="
119
+ $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | _filter_img_create
120
+
121
+ echo
122
+ echo "== Launching QEMU, opts: '$opts1' =="
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
+
80
+
178
+echo
81
+echo
179
+echo "== Two devices sharing the same file in backing chain =="
82
+echo === Starting VMs ===
180
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.b"
83
+echo
181
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.c"
84
+
85
+qemu_comm_method="monitor"
86
+
87
+if [ "$IMGOPTSSYNTAX" = "true" ]; then
88
+ _launch_qemu \
89
+ -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk
90
+else
91
+ _launch_qemu \
92
+ -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk
93
+fi
94
+src=$QEMU_HANDLE
95
+
96
+if [ "$IMGOPTSSYNTAX" = "true" ]; then
97
+ _launch_qemu \
98
+ -drive "${TEST_IMG}",cache=${CACHEMODE},id=disk \
99
+ -incoming "unix:${MIG_SOCKET}"
100
+else
101
+ _launch_qemu \
102
+ -drive file="${TEST_IMG}",cache=${CACHEMODE},driver=$IMGFMT,id=disk \
103
+ -incoming "unix:${MIG_SOCKET}"
104
+fi
105
+dest=$QEMU_HANDLE
182
+
106
+
183
+echo
107
+echo
184
+echo "== Backing image also as an active device =="
108
+echo === Set \'migrate_set_capability postcopy-ram on\' and migrate ===
185
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}"
109
+echo
110
+
111
+silent=yes
112
+_send_qemu_cmd $dest 'migrate_set_capability postcopy-ram on' "(qemu)"
113
+_send_qemu_cmd $src 'migrate_set_capability postcopy-ram on' "(qemu)"
114
+_send_qemu_cmd $src "migrate -d unix:${MIG_SOCKET}" "(qemu)"
115
+
116
+QEMU_COMM_TIMEOUT=1 qemu_cmd_repeat=10 silent=yes \
117
+ _send_qemu_cmd $src "info migrate" "completed\|failed"
118
+silent=yes _send_qemu_cmd $src "" "(qemu)"
186
+
119
+
187
+echo
120
+echo
188
+echo "== Backing image also as an active device (ro) =="
121
+echo === Check if migration was successful ===
189
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG},readonly=on"
122
+echo
123
+
124
+QEMU_COMM_TIMEOUT=1 silent=yes \
125
+ _send_qemu_cmd $src "info migrate" "completed"
126
+silent=yes _send_qemu_cmd $src "" "(qemu)"
190
+
127
+
191
+echo
128
+echo
192
+echo "== Symbolic link =="
129
+echo === On destination, execute savevm and loadvm ===
193
+rm -f "${TEST_IMG}.lnk" &>/dev/null
130
+echo
194
+ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link"
131
+
195
+_run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}"
132
+silent=
133
+_send_qemu_cmd $dest 'savevm state1' "(qemu)"
134
+_send_qemu_cmd $dest 'loadvm state1' "(qemu)"
196
+
135
+
197
+echo
136
+echo
198
+echo "== Closing an image should unlock it =="
137
+echo === Shut down and check image ===
199
+_launch_qemu
138
+echo
200
+
139
+
201
+_send_qemu_cmd $QEMU_HANDLE \
140
+_send_qemu_cmd $src 'quit' ""
202
+ "{ 'execute': 'qmp_capabilities' }" \
141
+_send_qemu_cmd $dest 'quit' ""
203
+ 'return'
142
+wait=1 _cleanup_qemu
204
+
143
+
205
+echo "Adding drive"
144
+_check_test_img
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
+
145
+
248
+# success, all done
146
+# success, all done
249
+echo "*** done"
147
+echo "*** done"
250
+rm -f $seq.full
251
+status=0
148
+status=0
252
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
149
diff --git a/tests/qemu-iotests/201.out b/tests/qemu-iotests/201.out
253
new file mode 100644
150
new file mode 100644
254
index XXXXXXX..XXXXXXX
151
index XXXXXXX..XXXXXXX
255
--- /dev/null
152
--- /dev/null
256
+++ b/tests/qemu-iotests/153.out
153
+++ b/tests/qemu-iotests/201.out
257
@@ -XXX,XX +XXX,XX @@
154
@@ -XXX,XX +XXX,XX @@
258
+QA output created by 153
155
+QA output created by 201
259
+== readonly=off,force-share=on should be rejected ==
156
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
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
+
157
+
262
+== Creating base image ==
158
+=== Starting VMs ===
263
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
264
+
159
+
265
+== Creating test image ==
266
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
267
+
160
+
268
+== Launching QEMU, opts: '' ==
161
+=== Set 'migrate_set_capability postcopy-ram on' and migrate ===
269
+
162
+
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
+
163
+
274
+== Launching another QEMU, opts: 'read-only=on' ==
164
+=== Check if migration was successful ===
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
+
165
+
278
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
279
+
166
+
280
+== Running utility commands ==
167
+=== On destination, execute savevm and loadvm ===
281
+
168
+
282
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
169
+(qemu) savevm state1
283
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
170
+(qemu) loadvm state1
284
+Is another process using the image?
285
+
171
+
286
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
172
+=== Shut down and check image ===
287
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
288
+Is another process using the image?
289
+
173
+
290
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
174
+(qemu) quit
291
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
175
+(qemu) quit
292
+Is another process using the image?
176
+No errors were found on 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
177
+*** done
648
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
178
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
649
index XXXXXXX..XXXXXXX 100644
179
index XXXXXXX..XXXXXXX 100644
650
--- a/tests/qemu-iotests/group
180
--- a/tests/qemu-iotests/group
651
+++ b/tests/qemu-iotests/group
181
+++ b/tests/qemu-iotests/group
652
@@ -XXX,XX +XXX,XX @@
182
@@ -XXX,XX +XXX,XX @@
653
149 rw auto sudo
183
197 rw auto quick
654
150 rw auto quick
184
198 rw auto
655
152 rw auto quick
185
200 rw auto
656
+153 rw auto quick
186
+201 rw auto migration
657
154 rw auto backing quick
187
202 rw auto quick
658
155 rw auto
188
203 rw auto
659
156 rw auto quick
660
--
189
--
661
1.8.3.1
190
2.13.6
662
191
663
192
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Treat plain zero clusters differently from allocated ones, so that
3
We can easily repair unaligned preallocated zero clusters by discarding
4
we can simplify the logic of checking whether an offset is present.
4
them, so why not do it?
5
Do this by splitting QCOW2_CLUSTER_ZERO into two new enums,
6
QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC.
7
5
8
I tried to arrange the enum so that we could use
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
'ret <= QCOW2_CLUSTER_ZERO_PLAIN' for all unallocated types, and
7
Message-id: 20171110203759.14018-2-mreitz@redhat.com
10
'ret >= QCOW2_CLUSTER_ZERO_ALLOC' for allocated types, although
8
Reviewed-by: Eric Blake <eblake@redhat.com>
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>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
---
10
---
23
block/qcow2-cluster.c | 79 ++++++++++++++++++----------------------------
11
block/qcow2-refcount.c | 70 ++++++++++++++++++++++++++++++++++++++--------
24
block/qcow2-refcount.c | 44 +++++++++++---------------
12
tests/qemu-iotests/060 | 3 +-
25
block/qcow2.c | 9 ++++--
13
tests/qemu-iotests/060.out | 9 ++++++
26
block/qcow2.h | 8 +++--
14
3 files changed, 69 insertions(+), 13 deletions(-)
27
tests/qemu-iotests/060.out | 6 ++--
28
5 files changed, 63 insertions(+), 83 deletions(-)
29
15
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
16
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
213
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
214
--- a/block/qcow2-refcount.c
18
--- a/block/qcow2-refcount.c
215
+++ b/block/qcow2-refcount.c
19
+++ b/block/qcow2-refcount.c
216
@@ -XXX,XX +XXX,XX @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
20
@@ -XXX,XX +XXX,XX @@ enum {
217
}
21
static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
218
break;
22
void **refcount_table,
219
case QCOW2_CLUSTER_NORMAL:
23
int64_t *refcount_table_size, int64_t l2_offset,
220
- case QCOW2_CLUSTER_ZERO:
24
- int flags)
221
- if (l2_entry & L2E_OFFSET_MASK) {
25
+ int flags, BdrvCheckMode fix)
222
- if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
26
{
223
- qcow2_signal_corruption(bs, false, -1, -1,
27
BDRVQcow2State *s = bs->opaque;
224
- "Cannot free unaligned cluster %#llx",
28
uint64_t *l2_table, l2_entry;
225
- l2_entry & L2E_OFFSET_MASK);
29
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
226
- } else {
30
next_contiguous_offset = offset + s->cluster_size;
227
- qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
31
}
228
- nb_clusters << s->cluster_bits, type);
32
33
+ /* Correct offsets are cluster aligned */
34
+ if (offset_into_cluster(s, offset)) {
35
+ if (qcow2_get_cluster_type(l2_entry) ==
36
+ QCOW2_CLUSTER_ZERO_ALLOC)
37
+ {
38
+ fprintf(stderr, "%s offset=%" PRIx64 ": Preallocated zero "
39
+ "cluster is not properly aligned; L2 entry "
40
+ "corrupted.\n",
41
+ fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR",
42
+ offset);
43
+ if (fix & BDRV_FIX_ERRORS) {
44
+ uint64_t l2e_offset =
45
+ l2_offset + (uint64_t)i * sizeof(uint64_t);
46
+
47
+ l2_entry = QCOW_OFLAG_ZERO;
48
+ l2_table[i] = cpu_to_be64(l2_entry);
49
+ ret = qcow2_pre_write_overlap_check(bs,
50
+ QCOW2_OL_ACTIVE_L2 | QCOW2_OL_INACTIVE_L2,
51
+ l2e_offset, sizeof(uint64_t));
52
+ if (ret < 0) {
53
+ fprintf(stderr, "ERROR: Overlap check failed\n");
54
+ res->check_errors++;
55
+ /* Something is seriously wrong, so abort checking
56
+ * this L2 table */
57
+ goto fail;
58
+ }
59
+
60
+ ret = bdrv_pwrite_sync(bs->file, l2e_offset,
61
+ &l2_table[i], sizeof(uint64_t));
62
+ if (ret < 0) {
63
+ fprintf(stderr, "ERROR: Failed to overwrite L2 "
64
+ "table entry: %s\n", strerror(-ret));
65
+ res->check_errors++;
66
+ /* Do not abort, continue checking the rest of this
67
+ * L2 table's entries */
68
+ } else {
69
+ res->corruptions_fixed++;
70
+ /* Skip marking the cluster as used
71
+ * (it is unused now) */
72
+ continue;
73
+ }
74
+ } else {
75
+ res->corruptions++;
76
+ }
77
+ } else {
78
+ fprintf(stderr, "ERROR offset=%" PRIx64 ": Data cluster is "
79
+ "not properly aligned; L2 entry corrupted.\n", offset);
80
+ res->corruptions++;
81
+ }
82
+ }
83
+
84
/* Mark cluster as used */
85
ret = qcow2_inc_refcounts_imrt(bs, res,
86
refcount_table, refcount_table_size,
87
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
88
if (ret < 0) {
89
goto fail;
90
}
91
-
92
- /* Correct offsets are cluster aligned */
93
- if (offset_into_cluster(s, offset)) {
94
- fprintf(stderr, "ERROR offset=%" PRIx64 ": Cluster is not "
95
- "properly aligned; L2 entry corrupted.\n", offset);
96
- res->corruptions++;
229
- }
97
- }
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;
98
break;
295
}
99
}
296
100
297
+ case QCOW2_CLUSTER_ZERO_PLAIN:
101
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs,
298
case QCOW2_CLUSTER_UNALLOCATED:
102
void **refcount_table,
299
break;
103
int64_t *refcount_table_size,
300
104
int64_t l1_table_offset, int l1_size,
301
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
105
- int flags)
302
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
106
+ int flags, BdrvCheckMode fix)
303
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
107
{
304
108
BDRVQcow2State *s = bs->opaque;
305
- if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
109
uint64_t *l1_table = NULL, l2_offset, l1_size2;
306
- ((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
110
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs,
307
+ if (cluster_type == QCOW2_CLUSTER_NORMAL ||
111
308
+ cluster_type == QCOW2_CLUSTER_ZERO_ALLOC) {
112
/* Process and check L2 entries */
309
ret = qcow2_get_refcount(bs,
113
ret = check_refcounts_l2(bs, res, refcount_table,
310
data_offset >> s->cluster_bits,
114
- refcount_table_size, l2_offset, flags);
311
&refcount);
115
+ refcount_table_size, l2_offset, flags,
312
diff --git a/block/qcow2.c b/block/qcow2.c
116
+ fix);
313
index XXXXXXX..XXXXXXX 100644
117
if (ret < 0) {
314
--- a/block/qcow2.c
118
goto fail;
315
+++ b/block/qcow2.c
119
}
316
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
120
@@ -XXX,XX +XXX,XX @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
317
*file = bs->file->bs;
121
318
status |= BDRV_BLOCK_OFFSET_VALID | cluster_offset;
122
/* current L1 table */
123
ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,
124
- s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);
125
+ s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO,
126
+ fix);
127
if (ret < 0) {
128
return ret;
319
}
129
}
320
- if (ret == QCOW2_CLUSTER_ZERO) {
130
@@ -XXX,XX +XXX,XX @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
321
+ if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) {
131
for (i = 0; i < s->nb_snapshots; i++) {
322
status |= BDRV_BLOCK_ZERO;
132
sn = s->snapshots + i;
323
} else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
133
ret = check_refcounts_l1(bs, res, refcount_table, nb_clusters,
324
status |= BDRV_BLOCK_DATA;
134
- sn->l1_table_offset, sn->l1_size, 0);
325
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
135
+ sn->l1_table_offset, sn->l1_size, 0, fix);
326
}
136
if (ret < 0) {
327
break;
137
return ret;
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
}
138
}
346
diff --git a/block/qcow2.h b/block/qcow2.h
139
diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060
347
index XXXXXXX..XXXXXXX 100644
140
index XXXXXXX..XXXXXXX 100755
348
--- a/block/qcow2.h
141
--- a/tests/qemu-iotests/060
349
+++ b/block/qcow2.h
142
+++ b/tests/qemu-iotests/060
350
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
143
@@ -XXX,XX +XXX,XX @@ poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x00\x2a\x01"
351
144
# Let's write to it!
352
typedef enum QCow2ClusterType {
145
$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
353
QCOW2_CLUSTER_UNALLOCATED,
146
354
+ QCOW2_CLUSTER_ZERO_PLAIN,
147
-# Can't repair this yet (TODO: We can just deallocate the cluster)
355
+ QCOW2_CLUSTER_ZERO_ALLOC,
148
+echo '--- Repairing ---'
356
QCOW2_CLUSTER_NORMAL,
149
+_check_test_img -r all
357
QCOW2_CLUSTER_COMPRESSED,
150
358
- QCOW2_CLUSTER_ZERO
151
echo
359
} QCow2ClusterType;
152
echo '=== Discarding with an unaligned refblock ==='
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
153
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
375
index XXXXXXX..XXXXXXX 100644
154
index XXXXXXX..XXXXXXX 100644
376
--- a/tests/qemu-iotests/060.out
155
--- a/tests/qemu-iotests/060.out
377
+++ b/tests/qemu-iotests/060.out
156
+++ b/tests/qemu-iotests/060.out
378
@@ -XXX,XX +XXX,XX @@ qemu-img: Error while amending options: Input/output error
157
@@ -XXX,XX +XXX,XX @@ discard 65536/65536 bytes at offset 0
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)
158
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
159
qcow2: Marking image as corrupt: Preallocated zero cluster offset 0x2a00 unaligned (guest offset: 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
160
write failed: Input/output error
384
read failed: Input/output error
161
+--- Repairing ---
385
162
+Repairing offset=2a00: Preallocated zero cluster is not properly aligned; L2 entry corrupted.
386
=== Testing unaligned pre-allocated zero cluster ===
163
+The following inconsistencies were found and repaired:
387
@@ -XXX,XX +XXX,XX @@ discard 65536/65536 bytes at offset 0
164
+
388
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
165
+ 0 leaked clusters
389
wrote 65536/65536 bytes at offset 0
166
+ 1 corruptions
390
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
167
+
391
-qcow2: Image is corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
168
+Double checking the fixed image now...
392
+qcow2: Image is corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
169
+No errors were found on the image.
393
read failed: Input/output error
170
394
read failed: Input/output error
171
=== Discarding with an unaligned refblock ===
395
172
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
--
173
--
406
1.8.3.1
174
2.13.6
407
175
408
176
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Double attach is not a valid usage of the target image, drive-backup
3
In some cases, these commands still use the deprecated @device
4
will open the blockdev itself so skip the add_drive call in this case.
4
parameter. Fix that so we can later drop that parameter from their
5
interface.
5
6
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Message-id: 20171110224302.14424-2-mreitz@redhat.com
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Alberto Garcia <berto@igalia.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
11
---
10
tests/qemu-iotests/055 | 32 ++++++++++++++++++--------------
12
tests/qemu-iotests/118 | 184 +++++++++++++++++++++++--------------------------
11
1 file changed, 18 insertions(+), 14 deletions(-)
13
tests/qemu-iotests/155 | 60 ++++++++--------
14
2 files changed, 113 insertions(+), 131 deletions(-)
12
15
13
diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
16
diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
14
index XXXXXXX..XXXXXXX 100755
17
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/055
18
--- a/tests/qemu-iotests/118
16
+++ b/tests/qemu-iotests/055
19
+++ b/tests/qemu-iotests/118
17
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
20
@@ -XXX,XX +XXX,XX @@ from iotests import qemu_img
21
old_img = os.path.join(iotests.test_dir, 'test0.img')
22
new_img = os.path.join(iotests.test_dir, 'test1.img')
23
24
+def interface_to_device_name(interface):
25
+ if interface == 'ide':
26
+ return 'ide-cd'
27
+ elif interface == 'floppy':
28
+ return 'floppy'
29
+ else:
30
+ return None
31
+
32
class ChangeBaseClass(iotests.QMPTestCase):
33
has_opened = False
34
has_closed = False
35
@@ -XXX,XX +XXX,XX @@ class ChangeBaseClass(iotests.QMPTestCase):
36
37
class GeneralChangeTestsBaseClass(ChangeBaseClass):
38
39
- device_name = None
40
+ device_name = 'qdev0'
41
42
def test_change(self):
43
result = self.vm.qmp('change', device='drive0', target=new_img,
44
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
45
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
46
47
def test_blockdev_change_medium(self):
48
- if self.device_name is not None:
49
- result = self.vm.qmp('blockdev-change-medium',
50
- id=self.device_name, filename=new_img,
51
- format=iotests.imgfmt)
52
- else:
53
- result = self.vm.qmp('blockdev-change-medium',
54
- device='drive0', filename=new_img,
55
- format=iotests.imgfmt)
56
+ result = self.vm.qmp('blockdev-change-medium',
57
+ id=self.device_name, filename=new_img,
58
+ format=iotests.imgfmt)
59
60
self.assert_qmp(result, 'return', {})
61
62
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
63
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
64
65
def test_eject(self):
66
- if self.device_name is not None:
67
- result = self.vm.qmp('eject', id=self.device_name, force=True)
68
- else:
69
- result = self.vm.qmp('eject', device='drive0', force=True)
70
+ result = self.vm.qmp('eject', id=self.device_name, force=True)
71
self.assert_qmp(result, 'return', {})
72
73
self.wait_for_open()
74
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
75
self.assert_qmp_absent(result, 'return[0]/inserted')
76
77
def test_tray_eject_change(self):
78
- if self.device_name is not None:
79
- result = self.vm.qmp('eject', id=self.device_name, force=True)
80
- else:
81
- result = self.vm.qmp('eject', device='drive0', force=True)
82
+ result = self.vm.qmp('eject', id=self.device_name, force=True)
83
self.assert_qmp(result, 'return', {})
84
85
self.wait_for_open()
86
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
87
self.assert_qmp(result, 'return[0]/tray_open', True)
88
self.assert_qmp_absent(result, 'return[0]/inserted')
89
90
- if self.device_name is not None:
91
- result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
92
- filename=new_img, format=iotests.imgfmt)
93
- else:
94
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
95
- filename=new_img, format=iotests.imgfmt)
96
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
97
+ filename=new_img, format=iotests.imgfmt)
98
self.assert_qmp(result, 'return', {})
99
100
self.wait_for_close()
101
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
102
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
103
104
def test_tray_open_close(self):
105
- if self.device_name is not None:
106
- result = self.vm.qmp('blockdev-open-tray',
107
- id=self.device_name, force=True)
108
- else:
109
- result = self.vm.qmp('blockdev-open-tray',
110
- device='drive0', force=True)
111
+ result = self.vm.qmp('blockdev-open-tray',
112
+ id=self.device_name, force=True)
113
self.assert_qmp(result, 'return', {})
114
115
self.wait_for_open()
116
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
117
else:
118
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
119
120
- if self.device_name is not None:
121
- result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
122
- else:
123
- result = self.vm.qmp('blockdev-close-tray', device='drive0')
124
+ result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
125
self.assert_qmp(result, 'return', {})
126
127
if self.has_real_tray or not self.was_empty:
128
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
129
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
130
131
def test_tray_eject_close(self):
132
- result = self.vm.qmp('eject', device='drive0', force=True)
133
+ result = self.vm.qmp('eject', id=self.device_name, force=True)
134
self.assert_qmp(result, 'return', {})
135
136
self.wait_for_open()
137
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
138
self.assert_qmp(result, 'return[0]/tray_open', True)
139
self.assert_qmp_absent(result, 'return[0]/inserted')
140
141
- if self.device_name is not None:
142
- result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
143
- else:
144
- result = self.vm.qmp('blockdev-close-tray', device='drive0')
145
+ result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
146
self.assert_qmp(result, 'return', {})
147
148
self.wait_for_close()
149
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
150
self.assert_qmp_absent(result, 'return[0]/inserted')
151
152
def test_tray_open_change(self):
153
- result = self.vm.qmp('blockdev-open-tray', device='drive0', force=True)
154
+ result = self.vm.qmp('blockdev-open-tray', id=self.device_name,
155
+ force=True)
156
self.assert_qmp(result, 'return', {})
157
158
self.wait_for_open()
159
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
160
else:
161
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
162
163
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
164
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
165
filename=new_img,
166
format=iotests.imgfmt)
167
self.assert_qmp(result, 'return', {})
168
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
169
'driver': 'file'})
170
self.assert_qmp(result, 'return', {})
171
172
- if self.device_name is not None:
173
- result = self.vm.qmp('blockdev-open-tray',
174
- id=self.device_name, force=True)
175
- else:
176
- result = self.vm.qmp('blockdev-open-tray',
177
- device='drive0', force=True)
178
+ result = self.vm.qmp('blockdev-open-tray',
179
+ id=self.device_name, force=True)
180
self.assert_qmp(result, 'return', {})
181
182
self.wait_for_open()
183
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
184
else:
185
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
186
187
- if self.device_name is not None:
188
- result = self.vm.qmp('x-blockdev-remove-medium',
189
- id=self.device_name)
190
- else:
191
- result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
192
+ result = self.vm.qmp('x-blockdev-remove-medium',
193
+ id=self.device_name)
194
self.assert_qmp(result, 'return', {})
195
196
result = self.vm.qmp('query-block')
197
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
198
self.assert_qmp(result, 'return[0]/tray_open', True)
199
self.assert_qmp_absent(result, 'return[0]/inserted')
200
201
- if self.device_name is not None:
202
- result = self.vm.qmp('x-blockdev-insert-medium',
203
- id=self.device_name, node_name='new')
204
- else:
205
- result = self.vm.qmp('x-blockdev-insert-medium',
206
- device='drive0', node_name='new')
207
+ result = self.vm.qmp('x-blockdev-insert-medium',
208
+ id=self.device_name, node_name='new')
209
self.assert_qmp(result, 'return', {})
210
211
result = self.vm.qmp('query-block')
212
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
213
self.assert_qmp(result, 'return[0]/tray_open', True)
214
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
215
216
- if self.device_name is not None:
217
- result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
218
- else:
219
- result = self.vm.qmp('blockdev-close-tray', device='drive0')
220
+ result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
221
self.assert_qmp(result, 'return', {})
222
223
self.wait_for_close()
224
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
225
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
226
227
def test_close_on_closed(self):
228
- result = self.vm.qmp('blockdev-close-tray', device='drive0')
229
+ result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
230
# Should be a no-op
231
self.assert_qmp(result, 'return', {})
232
self.assertEquals(self.vm.get_qmp_events(wait=False), [])
233
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
234
if not self.has_real_tray:
235
return
236
237
- result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
238
+ result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
239
self.assert_qmp(result, 'error/class', 'GenericError')
240
241
def test_insert_on_closed(self):
242
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
243
'driver': 'file'})
244
self.assert_qmp(result, 'return', {})
245
246
- result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
247
+ result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
248
node_name='new')
249
self.assert_qmp(result, 'error/class', 'GenericError')
250
251
@@ -XXX,XX +XXX,XX @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
252
qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
253
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
254
self.vm = iotests.VM()
255
- if interface == 'ide':
256
- self.device_name = 'qdev0'
257
- self.vm.add_drive(old_img, 'media=%s' % media, 'none')
258
- self.vm.add_device('ide-cd,drive=drive0,id=%s' % self.device_name)
259
- else:
260
- self.vm.add_drive(old_img, 'media=%s' % media, interface)
261
+ self.vm.add_drive(old_img, 'media=%s' % media, 'none')
262
+ self.vm.add_device('%s,drive=drive0,id=%s' %
263
+ (interface_to_device_name(interface),
264
+ self.device_name))
265
self.vm.launch()
266
267
def tearDown(self):
268
@@ -XXX,XX +XXX,XX @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
269
'driver': 'file'})
270
self.assert_qmp(result, 'return', {})
271
272
- result = self.vm.qmp('blockdev-open-tray', device='drive0')
273
+ result = self.vm.qmp('blockdev-open-tray', id=self.device_name)
274
self.assert_qmp(result, 'return', {})
275
276
self.wait_for_open()
277
278
- result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
279
+ result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
280
node_name='new')
281
self.assert_qmp(result, 'error/class', 'GenericError')
282
283
@@ -XXX,XX +XXX,XX @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
284
285
def setUp(self, media, interface):
286
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
287
- self.vm = iotests.VM().add_drive(None, 'media=%s' % media, interface)
288
+ self.vm = iotests.VM().add_drive(None, 'media=%s' % media, 'none')
289
+ self.vm.add_device('%s,drive=drive0,id=%s' %
290
+ (interface_to_device_name(interface),
291
+ self.device_name))
292
self.vm.launch()
293
294
def tearDown(self):
295
@@ -XXX,XX +XXX,XX @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
296
os.remove(new_img)
297
298
def test_remove_on_empty(self):
299
- result = self.vm.qmp('blockdev-open-tray', device='drive0')
300
+ result = self.vm.qmp('blockdev-open-tray', id=self.device_name)
301
self.assert_qmp(result, 'return', {})
302
303
self.wait_for_open()
304
305
- result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
306
+ result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
307
# Should be a no-op
308
self.assert_qmp(result, 'return', {})
309
310
@@ -XXX,XX +XXX,XX @@ class TestFloppyInitiallyEmpty(TestInitiallyEmpty):
311
self.has_opened = True
312
313
class TestChangeReadOnly(ChangeBaseClass):
314
+ device_name = 'qdev0'
315
+
316
def setUp(self):
317
qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
318
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
319
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
320
def test_ro_ro_retain(self):
321
os.chmod(old_img, 0444)
322
os.chmod(new_img, 0444)
323
- self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
324
+ self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
325
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
326
self.vm.launch()
327
328
result = self.vm.qmp('query-block')
329
self.assert_qmp(result, 'return[0]/inserted/ro', True)
330
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
331
332
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
333
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
334
filename=new_img,
335
format=iotests.imgfmt,
336
read_only_mode='retain')
337
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
338
339
def test_ro_rw_retain(self):
340
os.chmod(old_img, 0444)
341
- self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
342
+ self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
343
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
344
self.vm.launch()
345
346
result = self.vm.qmp('query-block')
347
self.assert_qmp(result, 'return[0]/inserted/ro', True)
348
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
349
350
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
351
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
352
filename=new_img,
353
format=iotests.imgfmt,
354
read_only_mode='retain')
355
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
356
357
def test_rw_ro_retain(self):
358
os.chmod(new_img, 0444)
359
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
360
+ self.vm.add_drive(old_img, 'media=disk', 'none')
361
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
362
self.vm.launch()
363
364
result = self.vm.qmp('query-block')
365
self.assert_qmp(result, 'return[0]/inserted/ro', False)
366
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
367
368
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
369
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
370
filename=new_img,
371
format=iotests.imgfmt,
372
read_only_mode='retain')
373
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
374
375
def test_ro_rw(self):
376
os.chmod(old_img, 0444)
377
- self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
378
+ self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
379
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
380
self.vm.launch()
381
382
result = self.vm.qmp('query-block')
383
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
384
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
385
386
result = self.vm.qmp('blockdev-change-medium',
387
- device='drive0',
388
+ id=self.device_name,
389
filename=new_img,
390
format=iotests.imgfmt,
391
read_only_mode='read-write')
392
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
393
394
def test_rw_ro(self):
395
os.chmod(new_img, 0444)
396
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
397
+ self.vm.add_drive(old_img, 'media=disk', 'none')
398
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
399
self.vm.launch()
400
401
result = self.vm.qmp('query-block')
402
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
403
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
404
405
result = self.vm.qmp('blockdev-change-medium',
406
- device='drive0',
407
+ id=self.device_name,
408
filename=new_img,
409
format=iotests.imgfmt,
410
read_only_mode='read-only')
411
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
412
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
413
414
def test_make_rw_ro(self):
415
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
416
+ self.vm.add_drive(old_img, 'media=disk', 'none')
417
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
418
self.vm.launch()
419
420
result = self.vm.qmp('query-block')
421
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
422
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
423
424
result = self.vm.qmp('blockdev-change-medium',
425
- device='drive0',
426
+ id=self.device_name,
427
filename=new_img,
428
format=iotests.imgfmt,
429
read_only_mode='read-only')
430
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
431
432
def test_make_ro_rw(self):
433
os.chmod(new_img, 0444)
434
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
435
+ self.vm.add_drive(old_img, 'media=disk', 'none')
436
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
437
self.vm.launch()
438
439
result = self.vm.qmp('query-block')
440
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
441
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
442
443
result = self.vm.qmp('blockdev-change-medium',
444
- device='drive0',
445
+ id=self.device_name,
446
filename=new_img,
447
format=iotests.imgfmt,
448
read_only_mode='read-write')
449
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
450
451
def test_make_rw_ro_by_retain(self):
452
os.chmod(old_img, 0444)
453
- self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
454
+ self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
455
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
456
self.vm.launch()
457
458
result = self.vm.qmp('query-block')
459
self.assert_qmp(result, 'return[0]/inserted/ro', True)
460
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
461
462
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
463
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
464
filename=new_img,
465
format=iotests.imgfmt,
466
read_only_mode='retain')
467
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
468
469
def test_make_ro_rw_by_retain(self):
470
os.chmod(new_img, 0444)
471
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
472
+ self.vm.add_drive(old_img, 'media=disk', 'none')
473
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
474
self.vm.launch()
475
476
result = self.vm.qmp('query-block')
477
self.assert_qmp(result, 'return[0]/inserted/ro', False)
478
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
479
480
- result = self.vm.qmp('blockdev-change-medium', device='drive0',
481
+ result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
482
filename=new_img,
483
format=iotests.imgfmt,
484
read_only_mode='retain')
485
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
486
487
def test_rw_ro_cycle(self):
488
os.chmod(new_img, 0444)
489
- self.vm.add_drive(old_img, 'media=disk', 'floppy')
490
+ self.vm.add_drive(old_img, 'media=disk', 'none')
491
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
492
self.vm.launch()
493
494
result = self.vm.qmp('query-block')
495
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
496
self.assert_qmp(result, 'return[0]/inserted/ro', False)
497
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
498
499
- result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
500
+ result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
501
self.assert_qmp(result, 'return', {})
502
503
result = self.vm.qmp('query-block')
504
self.assert_qmp_absent(result, 'return[0]/inserted')
505
506
- result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
507
+ result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
508
node_name='new')
509
self.assert_qmp(result, 'return', {})
510
511
@@ -XXX,XX +XXX,XX @@ TestInitiallyEmpty = None
512
513
514
class TestBlockJobsAfterCycle(ChangeBaseClass):
515
+ device_name = 'qdev0'
516
+
517
def setUp(self):
518
- qemu_img('create', '-f', iotests.imgfmt, old_img, '1M')
519
+ qemu_img('create', '-f', iotests.imgfmt, old_img, '1440K')
520
521
self.vm = iotests.VM()
522
self.vm.add_drive_raw("id=drive0,driver=null-co,if=none")
523
+ self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
524
self.vm.launch()
525
526
result = self.vm.qmp('query-block')
527
@@ -XXX,XX +XXX,XX @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
528
529
# For device-less BBs, calling blockdev-open-tray or blockdev-close-tray
530
# is not necessary
531
- result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
532
+ result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
533
self.assert_qmp(result, 'return', {})
534
535
result = self.vm.qmp('query-block')
536
@@ -XXX,XX +XXX,XX @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
537
'driver': 'file'})
538
self.assert_qmp(result, 'return', {})
539
540
- result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
541
+ result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
542
node_name='node0')
543
self.assert_qmp(result, 'return', {})
544
545
diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155
546
index XXXXXXX..XXXXXXX 100755
547
--- a/tests/qemu-iotests/155
548
+++ b/tests/qemu-iotests/155
549
@@ -XXX,XX +XXX,XX @@ class BaseClass(iotests.QMPTestCase):
550
target_real_backing = None
551
552
def setUp(self):
553
- qemu_img('create', '-f', iotests.imgfmt, back0_img, '1M')
554
+ qemu_img('create', '-f', iotests.imgfmt, back0_img, '1440K')
555
qemu_img('create', '-f', iotests.imgfmt, '-b', back0_img, back1_img)
556
qemu_img('create', '-f', iotests.imgfmt, '-b', back1_img, back2_img)
557
qemu_img('create', '-f', iotests.imgfmt, '-b', back2_img, source_img)
558
559
self.vm = iotests.VM()
560
- self.vm.add_drive(None, '', 'none')
561
- self.vm.launch()
562
-
563
# Add the BDS via blockdev-add so it stays around after the mirror block
564
# job has been completed
565
- result = self.vm.qmp('blockdev-add',
566
- node_name='source',
567
- driver=iotests.imgfmt,
568
- file={'driver': 'file',
569
- 'filename': source_img})
570
- self.assert_qmp(result, 'return', {})
571
-
572
- result = self.vm.qmp('x-blockdev-insert-medium',
573
- device='drive0', node_name='source')
574
- self.assert_qmp(result, 'return', {})
575
+ blockdev = {'node-name': 'source',
576
+ 'driver': iotests.imgfmt,
577
+ 'file': {'driver': 'file',
578
+ 'filename': source_img}}
579
+ self.vm.add_blockdev(self.qmp_to_opts(blockdev))
580
+ self.vm.add_device('floppy,id=qdev0,drive=source')
581
+ self.vm.launch()
582
583
self.assertIntactSourceBackingChain()
584
585
if self.existing:
586
if self.target_backing:
587
qemu_img('create', '-f', iotests.imgfmt,
588
- '-b', self.target_backing, target_img, '1M')
589
+ '-b', self.target_backing, target_img, '1440K')
590
else:
591
- qemu_img('create', '-f', iotests.imgfmt, target_img, '1M')
592
+ qemu_img('create', '-f', iotests.imgfmt, target_img, '1440K')
593
594
if self.cmd == 'blockdev-mirror':
595
options = { 'node-name': 'target',
596
@@ -XXX,XX +XXX,XX @@ class BaseClass(iotests.QMPTestCase):
18
except OSError:
597
except OSError:
19
pass
598
pass
20
599
21
- def do_prepare_drives(self, fmt, args):
600
- def findBlockNode(self, node_name, id=None):
22
+ def do_prepare_drives(self, fmt, args, attach_target):
601
- if id:
23
self.vm = iotests.VM().add_drive(test_img)
602
+ def findBlockNode(self, node_name, qdev=None):
24
603
+ if qdev:
25
qemu_img('create', '-f', fmt, blockdev_target_img,
604
result = self.vm.qmp('query-block')
26
str(TestDriveCompression.image_len), *args)
605
for device in result['return']:
27
- self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
606
- if device['device'] == id:
28
+ if attach_target:
607
+ if device['qdev'] == qdev:
29
+ self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
608
if node_name:
30
609
self.assert_qmp(device, 'inserted/node-name', node_name)
31
self.vm.launch()
610
return device['inserted']
32
611
@@ -XXX,XX +XXX,XX @@ class BaseClass(iotests.QMPTestCase):
33
- def do_test_compress_complete(self, cmd, format, **args):
612
if node['node-name'] == node_name:
34
- self.do_prepare_drives(format['type'], format['args'])
613
return node
35
+ def do_test_compress_complete(self, cmd, format, attach_target, **args):
614
36
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
615
- self.fail('Cannot find node %s/%s' % (id, node_name))
37
616
+ self.fail('Cannot find node %s/%s' % (qdev, node_name))
38
self.assert_no_active_block_jobs()
617
39
618
def assertIntactSourceBackingChain(self):
40
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
619
node = self.findBlockNode('source')
41
620
@@ -XXX,XX +XXX,XX @@ class BaseClass(iotests.QMPTestCase):
42
def test_complete_compress_drive_backup(self):
621
class MirrorBaseClass(BaseClass):
43
for format in TestDriveCompression.fmt_supports_compression:
622
def runMirror(self, sync):
44
- self.do_test_compress_complete('drive-backup', format,
623
if self.cmd == 'blockdev-mirror':
45
+ self.do_test_compress_complete('drive-backup', format, False,
624
- result = self.vm.qmp(self.cmd, device='drive0', sync=sync,
46
target=blockdev_target_img, mode='existing')
625
- target='target')
47
626
+ result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
48
def test_complete_compress_blockdev_backup(self):
627
+ sync=sync, target='target')
49
for format in TestDriveCompression.fmt_supports_compression:
628
else:
50
- self.do_test_compress_complete('blockdev-backup', format, target='drive1')
629
if self.existing:
51
+ self.do_test_compress_complete('blockdev-backup', format, True,
630
mode = 'existing'
52
+ target='drive1')
631
else:
53
632
mode = 'absolute-paths'
54
- def do_test_compress_cancel(self, cmd, format, **args):
633
- result = self.vm.qmp(self.cmd, device='drive0', sync=sync,
55
- self.do_prepare_drives(format['type'], format['args'])
634
- target=target_img, format=iotests.imgfmt,
56
+ def do_test_compress_cancel(self, cmd, format, attach_target, **args):
635
- mode=mode, node_name='target')
57
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
636
+ result = self.vm.qmp(self.cmd, job_id='mirror-job', device='source',
58
637
+ sync=sync, target=target_img,
59
self.assert_no_active_block_jobs()
638
+ format=iotests.imgfmt, mode=mode,
60
639
+ node_name='target')
61
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
640
62
641
self.assert_qmp(result, 'return', {})
63
def test_compress_cancel_drive_backup(self):
642
64
for format in TestDriveCompression.fmt_supports_compression:
643
self.vm.event_wait('BLOCK_JOB_READY')
65
- self.do_test_compress_cancel('drive-backup', format,
644
66
+ self.do_test_compress_cancel('drive-backup', format, False,
645
- result = self.vm.qmp('block-job-complete', device='drive0')
67
target=blockdev_target_img, mode='existing')
646
+ result = self.vm.qmp('block-job-complete', device='mirror-job')
68
647
self.assert_qmp(result, 'return', {})
69
def test_compress_cancel_blockdev_backup(self):
648
70
for format in TestDriveCompression.fmt_supports_compression:
649
self.vm.event_wait('BLOCK_JOB_COMPLETED')
71
- self.do_test_compress_cancel('blockdev-backup', format, target='drive1')
650
@@ -XXX,XX +XXX,XX @@ class MirrorBaseClass(BaseClass):
72
+ self.do_test_compress_cancel('blockdev-backup', format, True,
651
def testFull(self):
73
+ target='drive1')
652
self.runMirror('full')
74
653
75
- def do_test_compress_pause(self, cmd, format, **args):
654
- node = self.findBlockNode('target', 'drive0')
76
- self.do_prepare_drives(format['type'], format['args'])
655
+ node = self.findBlockNode('target', 'qdev0')
77
+ def do_test_compress_pause(self, cmd, format, attach_target, **args):
656
self.assertCorrectBackingImage(node, None)
78
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
657
self.assertIntactSourceBackingChain()
79
658
80
self.assert_no_active_block_jobs()
659
def testTop(self):
81
660
self.runMirror('top')
82
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
661
83
662
- node = self.findBlockNode('target', 'drive0')
84
def test_compress_pause_drive_backup(self):
663
+ node = self.findBlockNode('target', 'qdev0')
85
for format in TestDriveCompression.fmt_supports_compression:
664
self.assertCorrectBackingImage(node, back2_img)
86
- self.do_test_compress_pause('drive-backup', format,
665
self.assertIntactSourceBackingChain()
87
+ self.do_test_compress_pause('drive-backup', format, False,
666
88
target=blockdev_target_img, mode='existing')
667
def testNone(self):
89
668
self.runMirror('none')
90
def test_compress_pause_blockdev_backup(self):
669
91
for format in TestDriveCompression.fmt_supports_compression:
670
- node = self.findBlockNode('target', 'drive0')
92
- self.do_test_compress_pause('blockdev-backup', format, target='drive1')
671
+ node = self.findBlockNode('target', 'qdev0')
93
+ self.do_test_compress_pause('blockdev-backup', format, True,
672
self.assertCorrectBackingImage(node, source_img)
94
+ target='drive1')
673
self.assertIntactSourceBackingChain()
95
674
96
if __name__ == '__main__':
675
@@ -XXX,XX +XXX,XX @@ class TestCommit(BaseClass):
97
iotests.main(supported_fmts=['raw', 'qcow2'])
676
existing = False
677
678
def testCommit(self):
679
- result = self.vm.qmp('block-commit', device='drive0', base=back1_img)
680
+ result = self.vm.qmp('block-commit', job_id='commit-job',
681
+ device='source', base=back1_img)
682
self.assert_qmp(result, 'return', {})
683
684
self.vm.event_wait('BLOCK_JOB_READY')
685
686
- result = self.vm.qmp('block-job-complete', device='drive0')
687
+ result = self.vm.qmp('block-job-complete', device='commit-job')
688
self.assert_qmp(result, 'return', {})
689
690
self.vm.event_wait('BLOCK_JOB_COMPLETED')
691
692
- node = self.findBlockNode(None, 'drive0')
693
+ node = self.findBlockNode(None, 'qdev0')
694
self.assert_qmp(node, 'image' + '/backing-image' * 0 + '/filename',
695
back1_img)
696
self.assert_qmp(node, 'image' + '/backing-image' * 1 + '/filename',
98
--
697
--
99
1.8.3.1
698
2.13.6
100
699
101
700
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
In the case where we test the expected error when a blockdev-snapshot
4
target already has a backing image, the backing chain is opened multiple
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
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
tests/qemu-iotests/085 | 33 +++++++++++++++++++--------------
12
tests/qemu-iotests/085.out | 3 ++-
13
2 files changed, 21 insertions(+), 15 deletions(-)
14
15
diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085
16
index XXXXXXX..XXXXXXX 100755
17
--- a/tests/qemu-iotests/085
18
+++ b/tests/qemu-iotests/085
19
@@ -XXX,XX +XXX,XX @@ _cleanup()
20
rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
21
rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
22
done
23
- rm -f "${TEST_IMG}.1" "${TEST_IMG}.2"
24
+ rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base"
25
26
}
27
trap "_cleanup; exit \$status" 0 1 2 3 15
28
@@ -XXX,XX +XXX,XX @@ function create_group_snapshot()
29
}
30
31
# ${1}: unique identifier for the snapshot filename
32
-# ${2}: true: open backing images; false: don't open them (default)
33
+# ${2}: extra_params to the blockdev-add command
34
+# ${3}: filename
35
+function do_blockdev_add()
36
+{
37
+ cmd="{ 'execute': 'blockdev-add', 'arguments':
38
+ { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
39
+ 'file':
40
+ { 'driver': 'file', 'filename': '${3}',
41
+ 'node-name': 'file_${1}' } } }"
42
+ _send_qemu_cmd $h "${cmd}" "return"
43
+}
44
+
45
+# ${1}: unique identifier for the snapshot filename
46
function add_snapshot_image()
47
{
48
- if [ "${2}" = "true" ]; then
49
- extra_params=""
50
- else
51
- extra_params="'backing': '', "
52
- fi
53
base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
54
snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
55
_make_test_img -b "${base_image}" "$size"
56
mv "${TEST_IMG}" "${snapshot_file}"
57
- cmd="{ 'execute': 'blockdev-add', 'arguments':
58
- { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${extra_params}
59
- 'file':
60
- { 'driver': 'file', 'filename': '${snapshot_file}',
61
- 'node-name': 'file_${1}' } } }"
62
- _send_qemu_cmd $h "${cmd}" "return"
63
+ do_blockdev_add "$1" "'backing': '', " "${snapshot_file}"
64
}
65
66
# ${1}: unique identifier for the snapshot filename
67
@@ -XXX,XX +XXX,XX @@ echo === Invalid command - snapshot node has a backing image ===
68
echo
69
70
SNAPSHOTS=$((${SNAPSHOTS}+1))
71
-add_snapshot_image ${SNAPSHOTS} true
72
+
73
+TEST_IMG="$TEST_IMG.base" _make_test_img "$size"
74
+_make_test_img -b "${TEST_IMG}.base" "$size"
75
+do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}"
76
blockdev_snapshot ${SNAPSHOTS} error
77
78
echo
79
diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out
80
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/085.out
82
+++ b/tests/qemu-iotests/085.out
83
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/
84
85
=== Invalid command - snapshot node has a backing image ===
86
87
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/12-snapshot-v0.IMGFMT
88
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
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
--
94
1.8.3.1
95
96
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
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Passing a byte offset, but sector count, when we ultimately
3
Currently, the tray and medium commands in the AHCI test use the
4
want to operate on cluster granularity, is madness. Clean up
4
deprecated @device parameter. This patch switches all invocations over
5
the external interfaces to take both offset and count as bytes,
5
to use @id.
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
6
12
The internal functions still operate on clusters at a time, and
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
return an int for number of cleared clusters; but on an image
8
Message-id: 20171110224302.14424-3-mreitz@redhat.com
14
with 2M clusters, a single L2 table holds 256k entries that each
9
Reviewed-by: Alberto Garcia <berto@igalia.com>
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
25
Signed-off-by: Eric Blake <eblake@redhat.com>
26
Reviewed-by: Max Reitz <mreitz@redhat.com>
27
Message-id: 20170507000552.20847-13-eblake@redhat.com
28
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
29
---
11
---
30
block/qcow2-cluster.c | 42 ++++++++++++++++++++++--------------------
12
tests/ahci-test.c | 12 ++++++------
31
block/qcow2-snapshot.c | 7 +++----
13
1 file changed, 6 insertions(+), 6 deletions(-)
32
block/qcow2.c | 22 +++++++++-------------
33
block/qcow2.h | 9 +++++----
34
4 files changed, 39 insertions(+), 41 deletions(-)
35
14
36
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
15
diff --git a/tests/ahci-test.c b/tests/ahci-test.c
37
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
38
--- a/block/qcow2-cluster.c
17
--- a/tests/ahci-test.c
39
+++ b/block/qcow2-cluster.c
18
+++ b/tests/ahci-test.c
40
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
19
@@ -XXX,XX +XXX,XX @@ static void test_atapi_tray(void)
41
return nb_clusters;
20
QDict *rsp;
42
}
21
43
22
fd = prepare_iso(iso_size, &tx, &iso);
44
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
23
- ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,format=raw "
45
- int nb_sectors, enum qcow2_discard_type type, bool full_discard)
24
+ ahci = ahci_boot_and_enable("-blockdev node-name=drive0,driver=file,filename=%s "
46
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
25
"-M q35 "
47
+ uint64_t bytes, enum qcow2_discard_type type,
26
- "-device ide-cd,drive=drive0 ", iso);
48
+ bool full_discard)
27
+ "-device ide-cd,id=cd0,drive=drive0 ", iso);
49
{
28
port = ahci_port_select(ahci);
50
BDRVQcow2State *s = bs->opaque;
29
51
- uint64_t end_offset;
30
ahci_atapi_eject(ahci, port);
52
+ uint64_t end_offset = offset + bytes;
31
@@ -XXX,XX +XXX,XX @@ static void test_atapi_tray(void)
53
uint64_t nb_clusters;
32
54
+ int64_t cleared;
33
/* Remove media */
55
int ret;
34
qmp_async("{'execute': 'blockdev-open-tray', "
56
35
- "'arguments': {'device': 'drive0'}}");
57
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
36
+ "'arguments': {'id': 'cd0'}}");
58
-
37
atapi_wait_tray(true);
59
/* Caller must pass aligned values, except at image end */
38
rsp = qmp_receive();
60
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
39
QDECREF(rsp);
61
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
40
62
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
41
qmp_discard_response("{'execute': 'x-blockdev-remove-medium', "
63
42
- "'arguments': {'device': 'drive0'}}");
64
- nb_clusters = size_to_clusters(s, end_offset - offset);
43
+ "'arguments': {'id': 'cd0'}}");
65
+ nb_clusters = size_to_clusters(s, bytes);
44
66
45
/* Test the tray without a medium */
67
s->cache_discards = true;
46
ahci_atapi_load(ahci, port);
68
47
@@ -XXX,XX +XXX,XX @@ static void test_atapi_tray(void)
69
/* Each L2 table is handled by its own loop iteration */
48
"'file': { 'driver': 'file', "
70
while (nb_clusters > 0) {
49
"'filename': %s }}}", iso);
71
- ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);
50
qmp_discard_response("{'execute': 'x-blockdev-insert-medium',"
72
- if (ret < 0) {
51
- "'arguments': { 'device': 'drive0', "
73
+ cleared = discard_single_l2(bs, offset, nb_clusters, type,
52
+ "'arguments': { 'id': 'cd0', "
74
+ full_discard);
53
"'node-name': 'node0' }}");
75
+ if (cleared < 0) {
54
76
+ ret = cleared;
55
/* Again, the event shows up first */
77
goto fail;
56
qmp_async("{'execute': 'blockdev-close-tray', "
78
}
57
- "'arguments': {'device': 'drive0'}}");
79
58
+ "'arguments': {'id': 'cd0'}}");
80
- nb_clusters -= ret;
59
atapi_wait_tray(false);
81
- offset += (ret * s->cluster_size);
60
rsp = qmp_receive();
82
+ nb_clusters -= cleared;
61
QDECREF(rsp);
83
+ offset += (cleared * s->cluster_size);
84
}
85
86
ret = 0;
87
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
88
return nb_clusters;
89
}
90
91
-int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
92
- int flags)
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
}
110
111
/* Each L2 table is handled by its own loop iteration */
112
- nb_clusters = size_to_clusters(s, nb_sectors << BDRV_SECTOR_BITS);
113
+ nb_clusters = size_to_clusters(s, bytes);
114
115
s->cache_discards = true;
116
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
}
131
132
ret = 0;
133
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
134
index XXXXXXX..XXXXXXX 100644
135
--- a/block/qcow2-snapshot.c
136
+++ b/block/qcow2-snapshot.c
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
}
175
@@ -XXX,XX +XXX,XX @@ fail:
176
static int qcow2_make_empty(BlockDriverState *bs)
177
{
178
BDRVQcow2State *s = bs->opaque;
179
- uint64_t start_sector;
180
- int sector_step = (QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size) /
181
- BDRV_SECTOR_SIZE);
182
+ uint64_t offset, end_offset;
183
+ int step = QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size);
184
int l1_clusters, ret = 0;
185
186
l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
187
@@ -XXX,XX +XXX,XX @@ static int qcow2_make_empty(BlockDriverState *bs)
188
189
/* This fallback code simply discards every active cluster; this is slow,
190
* but works in all cases */
191
- for (start_sector = 0; start_sector < bs->total_sectors;
192
- start_sector += sector_step)
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
--
62
--
231
1.8.3.1
63
2.13.6
232
64
233
65
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Making this option available even before implementing it will let
3
This is an incompatible change, which is fine as the commands are
4
converting tests easier: in coming patches they can specify the option
4
experimental.
5
already when necessary, before we actually write code to lock the
6
images.
7
5
8
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Message-id: 20171110224302.14424-4-mreitz@redhat.com
8
Reviewed-by: Alberto Garcia <berto@igalia.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
---
10
---
11
block/file-posix.c | 5 +++++
11
qapi/block-core.json | 10 ++--------
12
qapi/block-core.json | 4 ++++
12
blockdev.c | 30 +++++++++++++++++++++++-------
13
2 files changed, 9 insertions(+)
13
2 files changed, 25 insertions(+), 15 deletions(-)
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 @@
36
#
20
#
37
# @filename: path to the image file
21
# If the tray is open and there is no medium inserted, this will be a no-op.
38
# @aio: AIO backend (default: threads) (since: 2.8)
39
+# @locking: whether to enable file locking. If set to 'auto', only enable
40
+# when Open File Descriptor (OFD) locking API is available
41
+# (default: auto, since 2.10)
42
#
22
#
43
# Since: 2.9
23
-# @device: Block device name (deprecated, use @id instead)
24
-#
25
# @id: The name or QOM path of the guest device (since: 2.8)
26
#
27
# Note: This command is still a work in progress and is considered experimental.
28
@@ -XXX,XX +XXX,XX @@
29
#
44
##
30
##
45
{ 'struct': 'BlockdevOptionsFile',
31
{ 'command': 'x-blockdev-remove-medium',
46
'data': { 'filename': 'str',
32
- 'data': { '*device': 'str',
47
+ '*locking': 'OnOffAuto',
33
- '*id': 'str' } }
48
'*aio': 'BlockdevAioOptions' } }
34
+ 'data': { 'id': 'str' } }
49
35
50
##
36
##
37
# @x-blockdev-insert-medium:
38
@@ -XXX,XX +XXX,XX @@
39
# device's tray must currently be open (unless there is no attached guest
40
# device) and there must be no medium inserted already.
41
#
42
-# @device: Block device name (deprecated, use @id instead)
43
-#
44
# @id: The name or QOM path of the guest device (since: 2.8)
45
#
46
# @node-name: name of a node in the block driver state graph
47
@@ -XXX,XX +XXX,XX @@
48
#
49
##
50
{ 'command': 'x-blockdev-insert-medium',
51
- 'data': { '*device': 'str',
52
- '*id': 'str',
53
+ 'data': { 'id': 'str',
54
'node-name': 'str'} }
55
56
57
diff --git a/blockdev.c b/blockdev.c
58
index XXXXXXX..XXXXXXX 100644
59
--- a/blockdev.c
60
+++ b/blockdev.c
61
@@ -XXX,XX +XXX,XX @@ static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
62
63
static int do_open_tray(const char *blk_name, const char *qdev_id,
64
bool force, Error **errp);
65
+static void blockdev_remove_medium(bool has_device, const char *device,
66
+ bool has_id, const char *id, Error **errp);
67
+static void blockdev_insert_medium(bool has_device, const char *device,
68
+ bool has_id, const char *id,
69
+ const char *node_name, Error **errp);
70
71
static const char *const if_name[IF_COUNT] = {
72
[IF_NONE] = "none",
73
@@ -XXX,XX +XXX,XX @@ void qmp_eject(bool has_device, const char *device,
74
}
75
error_free(local_err);
76
77
- qmp_x_blockdev_remove_medium(has_device, device, has_id, id, errp);
78
+ blockdev_remove_medium(has_device, device, has_id, id, errp);
79
}
80
81
void qmp_block_passwd(bool has_device, const char *device,
82
@@ -XXX,XX +XXX,XX @@ void qmp_blockdev_close_tray(bool has_device, const char *device,
83
}
84
}
85
86
-void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
87
- bool has_id, const char *id, Error **errp)
88
+static void blockdev_remove_medium(bool has_device, const char *device,
89
+ bool has_id, const char *id, Error **errp)
90
{
91
BlockBackend *blk;
92
BlockDriverState *bs;
93
@@ -XXX,XX +XXX,XX @@ out:
94
aio_context_release(aio_context);
95
}
96
97
+void qmp_x_blockdev_remove_medium(const char *id, Error **errp)
98
+{
99
+ blockdev_remove_medium(false, NULL, true, id, errp);
100
+}
101
+
102
static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
103
BlockDriverState *bs, Error **errp)
104
{
105
@@ -XXX,XX +XXX,XX @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
106
}
107
}
108
109
-void qmp_x_blockdev_insert_medium(bool has_device, const char *device,
110
- bool has_id, const char *id,
111
- const char *node_name, Error **errp)
112
+static void blockdev_insert_medium(bool has_device, const char *device,
113
+ bool has_id, const char *id,
114
+ const char *node_name, Error **errp)
115
{
116
BlockBackend *blk;
117
BlockDriverState *bs;
118
@@ -XXX,XX +XXX,XX @@ void qmp_x_blockdev_insert_medium(bool has_device, const char *device,
119
qmp_blockdev_insert_anon_medium(blk, bs, errp);
120
}
121
122
+void qmp_x_blockdev_insert_medium(const char *id, const char *node_name,
123
+ Error **errp)
124
+{
125
+ blockdev_insert_medium(false, NULL, true, id, node_name, errp);
126
+}
127
+
128
void qmp_blockdev_change_medium(bool has_device, const char *device,
129
bool has_id, const char *id,
130
const char *filename,
131
@@ -XXX,XX +XXX,XX @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
132
error_free(err);
133
err = NULL;
134
135
- qmp_x_blockdev_remove_medium(has_device, device, has_id, id, &err);
136
+ blockdev_remove_medium(has_device, device, has_id, id, &err);
137
if (err) {
138
error_propagate(errp, err);
139
goto fail;
51
--
140
--
52
1.8.3.1
141
2.13.6
53
142
54
143
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
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
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>
16
---
17
blockdev.c | 15 ++++++++++++++-
18
1 file changed, 14 insertions(+), 1 deletion(-)
19
20
diff --git a/blockdev.c b/blockdev.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/blockdev.c
23
+++ b/blockdev.c
24
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
25
Error *local_err = NULL;
26
int flags;
27
int64_t size;
28
+ bool set_backing_hd = false;
29
30
if (!backup->has_speed) {
31
backup->speed = 0;
32
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
33
}
34
if (backup->sync == MIRROR_SYNC_MODE_NONE) {
35
source = bs;
36
+ flags |= BDRV_O_NO_BACKING;
37
+ set_backing_hd = true;
38
}
39
40
size = bdrv_getlength(bs);
41
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
42
}
43
44
if (backup->format) {
45
- options = qdict_new();
46
+ if (!options) {
47
+ options = qdict_new();
48
+ }
49
qdict_put_str(options, "driver", backup->format);
50
}
51
52
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
53
54
bdrv_set_aio_context(target_bs, aio_context);
55
56
+ if (set_backing_hd) {
57
+ bdrv_set_backing_hd(target_bs, source, &local_err);
58
+ if (local_err) {
59
+ bdrv_unref(target_bs);
60
+ goto out;
61
+ }
62
+ }
63
+
64
if (backup->has_bitmap) {
65
bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
66
if (!bmap) {
67
--
68
1.8.3.1
69
70
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
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>
9
---
10
include/qemu/osdep.h | 3 +++
11
util/osdep.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
12
2 files changed, 51 insertions(+)
13
14
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/qemu/osdep.h
17
+++ b/include/qemu/osdep.h
18
@@ -XXX,XX +XXX,XX @@ int qemu_close(int fd);
19
#ifndef _WIN32
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
}
36
+
37
+static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
38
+{
39
+#ifdef F_OFD_SETLK
40
+ int ret;
41
+ struct flock fl = {
42
+ .l_whence = SEEK_SET,
43
+ .l_start = start,
44
+ .l_len = len,
45
+ .l_type = fl_type,
46
+ };
47
+ ret = fcntl(fd, F_OFD_SETLK, &fl);
48
+ return ret == -1 ? -errno : 0;
49
+#else
50
+ return -ENOTSUP;
51
+#endif
52
+}
53
+
54
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
55
+{
56
+ return qemu_lock_fcntl(fd, start, len, exclusive ? F_WRLCK : F_RDLCK);
57
+}
58
+
59
+int qemu_unlock_fd(int fd, int64_t start, int64_t len)
60
+{
61
+ return qemu_lock_fcntl(fd, start, len, F_UNLCK);
62
+}
63
+
64
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
65
+{
66
+#ifdef F_OFD_SETLK
67
+ int ret;
68
+ struct flock fl = {
69
+ .l_whence = SEEK_SET,
70
+ .l_start = start,
71
+ .l_len = len,
72
+ .l_type = exclusive ? F_WRLCK : F_RDLCK,
73
+ };
74
+ ret = fcntl(fd, F_OFD_GETLK, &fl);
75
+ if (ret == -1) {
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
--
88
1.8.3.1
89
90
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
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>
18
---
19
block/file-posix.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
20
1 file changed, 275 insertions(+), 1 deletion(-)
21
22
diff --git a/block/file-posix.c b/block/file-posix.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/file-posix.c
25
+++ b/block/file-posix.c
26
@@ -XXX,XX +XXX,XX @@ do { \
27
28
#define MAX_BLOCKSIZE    4096
29
30
+/* Posix file locking bytes. Libvirt takes byte 0, we start from higher bytes,
31
+ * leaving a few more bytes for its future use. */
32
+#define RAW_LOCK_PERM_BASE 100
33
+#define RAW_LOCK_SHARED_BASE 200
34
+
35
typedef struct BDRVRawState {
36
int fd;
37
+ int lock_fd;
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
+
47
#ifdef CONFIG_XFS
48
bool is_xfs:1;
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
+}
177
+
178
+/* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. */
179
+static int raw_check_lock_bytes(BDRVRawState *s,
180
+ uint64_t perm, uint64_t shared_perm,
181
+ Error **errp)
182
+{
183
+ int ret;
184
+ int i;
185
+
186
+ PERM_FOREACH(i) {
187
+ int off = RAW_LOCK_SHARED_BASE + i;
188
+ uint64_t p = 1ULL << i;
189
+ if (perm & p) {
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
+ }
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
+}
222
+
223
+static int raw_handle_perm_lock(BlockDriverState *bs,
224
+ RawPermLockOp op,
225
+ uint64_t new_perm, uint64_t new_shared,
226
+ Error **errp)
227
+{
228
+ BDRVRawState *s = bs->opaque;
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
+}
276
+
277
static int raw_reopen_prepare(BDRVReopenState *state,
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
+{
298
+ return raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, errp);
299
+}
300
+
301
+static void raw_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared)
302
+{
303
+ BDRVRawState *s = bs->opaque;
304
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
305
+ s->perm = perm;
306
+ s->shared_perm = shared;
307
+}
308
+
309
+static void raw_abort_perm_update(BlockDriverState *bs)
310
+{
311
+ raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
312
+}
313
+
314
+static int raw_inactivate(BlockDriverState *bs)
315
+{
316
+ int ret;
317
+ uint64_t perm = 0;
318
+ uint64_t shared = BLK_PERM_ALL;
319
+
320
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
321
+ if (ret) {
322
+ return ret;
323
+ }
324
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
325
+ return 0;
326
+}
327
+
328
+
329
+static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
330
+{
331
+ BDRVRawState *s = bs->opaque;
332
+ int ret;
333
+
334
+ assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
335
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
336
+ errp);
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
--
372
1.8.3.1
373
374
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
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Make it easier to simulate various unusual hardware setups (for
3
Now that iotest 093 test proves that the throttling configuration
4
example, recent commits 3482b9b and b8d0a98 affect the Dell
4
survives a blockdev-remove-medium/blockdev-insert-medium pair, the
5
Equallogic iSCSI with its 15M preferred and maximum unmap and
5
original reason for declaring these commands experimental is gone
6
write zero sizing, or b2f95fe deals with the Linux loopback
6
(see commit 6e0abc251dd4f8eba1f53656dfede12e5840e83b).
7
block device having a max_transfer of 64k), by allowing blkdebug
7
8
to wrap any other device with further restrictions on various
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
alignments.
9
Message-id: 20171110224302.14424-5-mreitz@redhat.com
10
10
Reviewed-by: Alberto Garcia <berto@igalia.com>
11
Signed-off-by: Eric Blake <eblake@redhat.com>
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>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
12
---
16
block/blkdebug.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-
13
qapi/block-core.json | 32 +++++++++++++-------------------
17
qapi/block-core.json | 33 ++++++++++++++++--
14
blockdev.c | 6 +++---
18
2 files changed, 125 insertions(+), 4 deletions(-)
15
tests/ahci-test.c | 4 ++--
19
16
tests/qemu-iotests/093 | 6 +++---
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
17
tests/qemu-iotests/118 | 20 ++++++++++----------
21
index XXXXXXX..XXXXXXX 100644
18
tests/qemu-iotests/139 | 2 +-
22
--- a/block/blkdebug.c
19
6 files changed, 32 insertions(+), 38 deletions(-)
23
+++ b/block/blkdebug.c
20
24
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVBlkdebugState {
25
int state;
26
int new_state;
27
uint64_t align;
28
+ uint64_t max_transfer;
29
+ uint64_t opt_write_zero;
30
+ uint64_t max_write_zero;
31
+ uint64_t opt_discard;
32
+ uint64_t max_discard;
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
}
88
+ align = MAX(s->align, bs->file->bs->bl.request_alignment);
89
+
90
+ s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0);
91
+ if (s->max_transfer &&
92
+ (s->max_transfer >= INT_MAX ||
93
+ !QEMU_IS_ALIGNED(s->max_transfer, align))) {
94
+ error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64,
95
+ s->max_transfer);
96
+ goto out;
97
+ }
98
+
99
+ s->opt_write_zero = qemu_opt_get_size(opts, "opt-write-zero", 0);
100
+ if (s->opt_write_zero &&
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
+ }
158
}
159
160
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
161
diff --git a/qapi/block-core.json b/qapi/block-core.json
21
diff --git a/qapi/block-core.json b/qapi/block-core.json
162
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
163
--- a/qapi/block-core.json
23
--- a/qapi/block-core.json
164
+++ b/qapi/block-core.json
24
+++ b/qapi/block-core.json
165
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@
166
#
26
'*id': 'str' } }
167
# @config: filename of the configuration file
27
168
#
28
##
169
-# @align: required alignment for requests in bytes,
29
-# @x-blockdev-remove-medium:
170
-# must be power of 2, or 0 for default
30
+# @blockdev-remove-medium:
171
+# @align: required alignment for requests in bytes, must be
31
#
172
+# positive power of 2, or 0 for default
32
# Removes a medium (a block driver state tree) from a block device. That block
173
+#
33
# device's tray must currently be open (unless there is no attached guest
174
+# @max-transfer: maximum size for I/O transfers in bytes, must be
34
@@ -XXX,XX +XXX,XX @@
175
+# positive multiple of @align and of the underlying
35
#
176
+# file's request alignment (but need not be a power of
36
# If the tray is open and there is no medium inserted, this will be a no-op.
177
+# 2), or 0 for default (since 2.10)
37
#
178
+#
38
-# @id: The name or QOM path of the guest device (since: 2.8)
179
+# @opt-write-zero: preferred alignment for write zero requests in bytes,
39
-#
180
+# must be positive multiple of @align and of the
40
-# Note: This command is still a work in progress and is considered experimental.
181
+# underlying file's request alignment (but need not be a
41
-# Stay away from it unless you want to help with its development.
182
+# power of 2), or 0 for default (since 2.10)
42
+# @id: The name or QOM path of the guest device
183
+#
43
#
184
+# @max-write-zero: maximum size for write zero requests in bytes, must be
44
-# Since: 2.5
185
+# positive multiple of @align, of @opt-write-zero, and of
45
+# Since: 2.12
186
+# the underlying file's request alignment (but need not
46
#
187
+# be a power of 2), or 0 for default (since 2.10)
47
# Example:
188
+#
48
#
189
+# @opt-discard: preferred alignment for discard requests in bytes, must
49
-# -> { "execute": "x-blockdev-remove-medium",
190
+# be positive multiple of @align and of the underlying
50
+# -> { "execute": "blockdev-remove-medium",
191
+# file's request alignment (but need not be a power of
51
# "arguments": { "id": "ide0-1-0" } }
192
+# 2), or 0 for default (since 2.10)
52
#
193
+#
53
# <- { "error": { "class": "GenericError",
194
+# @max-discard: maximum size for discard requests in bytes, must be
54
@@ -XXX,XX +XXX,XX @@
195
+# positive multiple of @align, of @opt-discard, and of
55
#
196
+# the underlying file's request alignment (but need not
56
# <- { "return": {} }
197
+# be a power of 2), or 0 for default (since 2.10)
57
#
198
#
58
-# -> { "execute": "x-blockdev-remove-medium",
199
# @inject-error: array of error injection descriptions
59
+# -> { "execute": "blockdev-remove-medium",
200
#
60
# "arguments": { "id": "ide0-1-0" } }
201
@@ -XXX,XX +XXX,XX @@
61
#
202
{ 'struct': 'BlockdevOptionsBlkdebug',
62
# <- { "return": {} }
203
'data': { 'image': 'BlockdevRef',
63
#
204
'*config': 'str',
64
##
205
- '*align': 'int',
65
-{ 'command': 'x-blockdev-remove-medium',
206
+ '*align': 'int', '*max-transfer': 'int32',
66
+{ 'command': 'blockdev-remove-medium',
207
+ '*opt-write-zero': 'int32', '*max-write-zero': 'int32',
67
'data': { 'id': 'str' } }
208
+ '*opt-discard': 'int32', '*max-discard': 'int32',
68
209
'*inject-error': ['BlkdebugInjectErrorOptions'],
69
##
210
'*set-state': ['BlkdebugSetStateOptions'] } }
70
-# @x-blockdev-insert-medium:
211
71
+# @blockdev-insert-medium:
72
#
73
# Inserts a medium (a block driver state tree) into a block device. That block
74
# device's tray must currently be open (unless there is no attached guest
75
# device) and there must be no medium inserted already.
76
#
77
-# @id: The name or QOM path of the guest device (since: 2.8)
78
+# @id: The name or QOM path of the guest device
79
#
80
# @node-name: name of a node in the block driver state graph
81
#
82
-# Note: This command is still a work in progress and is considered experimental.
83
-# Stay away from it unless you want to help with its development.
84
-#
85
-# Since: 2.5
86
+# Since: 2.12
87
#
88
# Example:
89
#
90
@@ -XXX,XX +XXX,XX @@
91
# "filename": "fedora.iso" } } }
92
# <- { "return": {} }
93
#
94
-# -> { "execute": "x-blockdev-insert-medium",
95
+# -> { "execute": "blockdev-insert-medium",
96
# "arguments": { "id": "ide0-1-0",
97
# "node-name": "node0" } }
98
#
99
# <- { "return": {} }
100
#
101
##
102
-{ 'command': 'x-blockdev-insert-medium',
103
+{ 'command': 'blockdev-insert-medium',
104
'data': { 'id': 'str',
105
'node-name': 'str'} }
106
107
@@ -XXX,XX +XXX,XX @@
108
#
109
# Changes the medium inserted into a block device by ejecting the current medium
110
# and loading a new image file which is inserted as the new medium (this command
111
-# combines blockdev-open-tray, x-blockdev-remove-medium,
112
-# x-blockdev-insert-medium and blockdev-close-tray).
113
+# combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-medium
114
+# and blockdev-close-tray).
115
#
116
# @device: Block device name (deprecated, use @id instead)
117
#
118
diff --git a/blockdev.c b/blockdev.c
119
index XXXXXXX..XXXXXXX 100644
120
--- a/blockdev.c
121
+++ b/blockdev.c
122
@@ -XXX,XX +XXX,XX @@ out:
123
aio_context_release(aio_context);
124
}
125
126
-void qmp_x_blockdev_remove_medium(const char *id, Error **errp)
127
+void qmp_blockdev_remove_medium(const char *id, Error **errp)
128
{
129
blockdev_remove_medium(false, NULL, true, id, errp);
130
}
131
@@ -XXX,XX +XXX,XX @@ static void blockdev_insert_medium(bool has_device, const char *device,
132
qmp_blockdev_insert_anon_medium(blk, bs, errp);
133
}
134
135
-void qmp_x_blockdev_insert_medium(const char *id, const char *node_name,
136
- Error **errp)
137
+void qmp_blockdev_insert_medium(const char *id, const char *node_name,
138
+ Error **errp)
139
{
140
blockdev_insert_medium(false, NULL, true, id, node_name, errp);
141
}
142
diff --git a/tests/ahci-test.c b/tests/ahci-test.c
143
index XXXXXXX..XXXXXXX 100644
144
--- a/tests/ahci-test.c
145
+++ b/tests/ahci-test.c
146
@@ -XXX,XX +XXX,XX @@ static void test_atapi_tray(void)
147
rsp = qmp_receive();
148
QDECREF(rsp);
149
150
- qmp_discard_response("{'execute': 'x-blockdev-remove-medium', "
151
+ qmp_discard_response("{'execute': 'blockdev-remove-medium', "
152
"'arguments': {'id': 'cd0'}}");
153
154
/* Test the tray without a medium */
155
@@ -XXX,XX +XXX,XX @@ static void test_atapi_tray(void)
156
"'driver': 'raw', "
157
"'file': { 'driver': 'file', "
158
"'filename': %s }}}", iso);
159
- qmp_discard_response("{'execute': 'x-blockdev-insert-medium',"
160
+ qmp_discard_response("{'execute': 'blockdev-insert-medium',"
161
"'arguments': { 'id': 'cd0', "
162
"'node-name': 'node0' }}");
163
164
diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093
165
index XXXXXXX..XXXXXXX 100755
166
--- a/tests/qemu-iotests/093
167
+++ b/tests/qemu-iotests/093
168
@@ -XXX,XX +XXX,XX @@ class ThrottleTestRemovableMedia(iotests.QMPTestCase):
169
# Now eject cd0 and insert cd1
170
result = self.vm.qmp("blockdev-open-tray", id='dev0')
171
self.assert_qmp(result, 'return', {})
172
- result = self.vm.qmp("x-blockdev-remove-medium", id='dev0')
173
+ result = self.vm.qmp("blockdev-remove-medium", id='dev0')
174
self.assert_qmp(result, 'return', {})
175
- result = self.vm.qmp("x-blockdev-insert-medium", id='dev0', node_name='cd1')
176
+ result = self.vm.qmp("blockdev-insert-medium", id='dev0', node_name='cd1')
177
self.assert_qmp(result, 'return', {})
178
179
# Check that the I/O limits are still the same
180
@@ -XXX,XX +XXX,XX @@ class ThrottleTestRemovableMedia(iotests.QMPTestCase):
181
self.assert_qmp(result, 'return[0]/inserted/bps', 50)
182
183
# Eject cd1
184
- result = self.vm.qmp("x-blockdev-remove-medium", id='dev0')
185
+ result = self.vm.qmp("blockdev-remove-medium", id='dev0')
186
self.assert_qmp(result, 'return', {})
187
188
# Check that we can't set limits if the device has no medium
189
diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
190
index XXXXXXX..XXXXXXX 100755
191
--- a/tests/qemu-iotests/118
192
+++ b/tests/qemu-iotests/118
193
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
194
else:
195
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
196
197
- result = self.vm.qmp('x-blockdev-remove-medium',
198
+ result = self.vm.qmp('blockdev-remove-medium',
199
id=self.device_name)
200
self.assert_qmp(result, 'return', {})
201
202
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
203
self.assert_qmp(result, 'return[0]/tray_open', True)
204
self.assert_qmp_absent(result, 'return[0]/inserted')
205
206
- result = self.vm.qmp('x-blockdev-insert-medium',
207
+ result = self.vm.qmp('blockdev-insert-medium',
208
id=self.device_name, node_name='new')
209
self.assert_qmp(result, 'return', {})
210
211
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
212
if not self.has_real_tray:
213
return
214
215
- result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
216
+ result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
217
self.assert_qmp(result, 'error/class', 'GenericError')
218
219
def test_insert_on_closed(self):
220
@@ -XXX,XX +XXX,XX @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
221
'driver': 'file'})
222
self.assert_qmp(result, 'return', {})
223
224
- result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
225
+ result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
226
node_name='new')
227
self.assert_qmp(result, 'error/class', 'GenericError')
228
229
@@ -XXX,XX +XXX,XX @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
230
231
self.wait_for_open()
232
233
- result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
234
+ result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
235
node_name='new')
236
self.assert_qmp(result, 'error/class', 'GenericError')
237
238
@@ -XXX,XX +XXX,XX @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
239
240
self.wait_for_open()
241
242
- result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
243
+ result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
244
# Should be a no-op
245
self.assert_qmp(result, 'return', {})
246
247
@@ -XXX,XX +XXX,XX @@ class TestChangeReadOnly(ChangeBaseClass):
248
self.assert_qmp(result, 'return[0]/inserted/ro', False)
249
self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
250
251
- result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
252
+ result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
253
self.assert_qmp(result, 'return', {})
254
255
result = self.vm.qmp('query-block')
256
self.assert_qmp_absent(result, 'return[0]/inserted')
257
258
- result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
259
+ result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
260
node_name='new')
261
self.assert_qmp(result, 'return', {})
262
263
@@ -XXX,XX +XXX,XX @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
264
265
# For device-less BBs, calling blockdev-open-tray or blockdev-close-tray
266
# is not necessary
267
- result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
268
+ result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
269
self.assert_qmp(result, 'return', {})
270
271
result = self.vm.qmp('query-block')
272
@@ -XXX,XX +XXX,XX @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
273
'driver': 'file'})
274
self.assert_qmp(result, 'return', {})
275
276
- result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
277
+ result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
278
node_name='node0')
279
self.assert_qmp(result, 'return', {})
280
281
diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139
282
index XXXXXXX..XXXXXXX 100644
283
--- a/tests/qemu-iotests/139
284
+++ b/tests/qemu-iotests/139
285
@@ -XXX,XX +XXX,XX @@ class TestBlockdevDel(iotests.QMPTestCase):
286
# Insert a BlockDriverState
287
def insertDrive(self, device, node):
288
self.checkBlockDriverState(node)
289
- result = self.vm.qmp('x-blockdev-insert-medium',
290
+ result = self.vm.qmp('blockdev-insert-medium',
291
id = device, node_name = node)
292
self.assert_qmp(result, 'return', {})
293
self.checkBlockDriverState(node)
212
--
294
--
213
1.8.3.1
295
2.13.6
214
296
215
297
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Mixing byte offset and sector allocation counts is a bit
3
102 truncates a qcow2 file (the raw file) on purpose while a VM is
4
confusing. Also, reporting n/m sectors, where m decreases
4
running. However, image locking will usually prevent exactly this.
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
5
12
Note that 'qemu-io map' is MUCH weaker than 'qemu-img map';
6
The fact that most people have not noticed until now (I suppose you may
13
the former only shows which regions of the active layer are
7
have seen sporadic failures, but not taken them too seriously, like me)
14
allocated, without regards to where the allocation comes from
8
further shows that this truncation is actually not really done
15
or whether the allocated portion is known to read as zero
9
concurrently, but that the VM is still starting up by this point and has
16
(because it is using the weaker bdrv_is_allocated()); while the
10
not yet opened the image. Remedy this by waiting for the monitor shell
17
latter (especially in --output=json mode) reports more details
11
to appear before the qemu-img invocation so we know the VM is up.
18
from bdrv_get_block_status().
19
12
20
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
Message-id: 20170429191419.30051-4-eblake@redhat.com
14
Message-id: 20171129185102.29390-1-mreitz@redhat.com
22
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Reviewed-by: Eric Blake <eblake@redhat.com>
23
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
24
---
17
---
25
qemu-io-cmds.c | 11 ++++++-----
18
tests/qemu-iotests/102 | 7 ++++++-
26
tests/qemu-iotests/102.out | 4 ++--
19
tests/qemu-iotests/102.out | 3 ++-
27
tests/qemu-iotests/146.out | 30 +++++++++++++++---------------
20
2 files changed, 8 insertions(+), 2 deletions(-)
28
3 files changed, 23 insertions(+), 22 deletions(-)
29
21
30
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
22
diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102
31
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100755
32
--- a/qemu-io-cmds.c
24
--- a/tests/qemu-iotests/102
33
+++ b/qemu-io-cmds.c
25
+++ b/tests/qemu-iotests/102
34
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
26
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
35
{
27
36
int64_t offset;
28
qemu_comm_method=monitor _launch_qemu -drive if=none,file="$TEST_IMG",id=drv0
37
int64_t nb_sectors, total_sectors;
29
38
- char s1[64];
30
-$QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024))
39
+ char s1[64], s2[64];
31
+# Wait for a prompt to appear (so we know qemu has opened the image)
40
int64_t num;
32
+_send_qemu_cmd '' '(qemu)'
41
int ret;
33
+
42
const char *retstr;
34
+$QEMU_IMG resize --shrink --image-opts \
43
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
35
+ "driver=raw,file.driver=file,file.filename=$TEST_IMG,file.locking=off" \
44
}
36
+ $((5 * 64 * 1024))
45
37
46
retstr = ret ? " allocated" : "not allocated";
38
_send_qemu_cmd $QEMU_HANDLE 'qemu-io drv0 map' 'allocated' \
47
- cvtstr(offset << 9ULL, s1, sizeof(s1));
39
| sed -e 's/^(qemu).*qemu-io drv0 map...$/(qemu) qemu-io drv0 map/'
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
40
diff --git a/tests/qemu-iotests/102.out b/tests/qemu-iotests/102.out
60
index XXXXXXX..XXXXXXX 100644
41
index XXXXXXX..XXXXXXX 100644
61
--- a/tests/qemu-iotests/102.out
42
--- a/tests/qemu-iotests/102.out
62
+++ b/tests/qemu-iotests/102.out
43
+++ b/tests/qemu-iotests/102.out
63
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
44
@@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File
45
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
64
wrote 65536/65536 bytes at offset 0
46
wrote 65536/65536 bytes at offset 0
65
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
47
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
66
Image resized.
48
-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
49
QEMU X.Y.Z monitor - type 'help' for more information
50
+Image resized.
51
+(qemu)
75
(qemu) qemu-io drv0 map
52
(qemu) qemu-io drv0 map
76
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
53
64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
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
54
*** done
168
--
55
--
169
1.8.3.1
56
2.13.6
170
57
171
58
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
For the 'alloc' command, accepting an offset in bytes but a length
3
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
in sectors, and reporting output in sectors, is confusing. Do
4
Message-id: 20171123020832.8165-2-mreitz@redhat.com
5
everything in bytes, and adjust the expected output accordingly.
5
Reviewed-by: Eric Blake <eblake@redhat.com>
6
6
Reviewed-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Eric Blake <eblake@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>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
8
---
12
qemu-io-cmds.c | 30 ++++++++++++++++++------------
9
block/vmdk.c | 2 +-
13
tests/qemu-iotests/019.out | 8 ++++----
10
1 file changed, 1 insertion(+), 1 deletion(-)
14
tests/qemu-iotests/common.pattern | 2 +-
15
3 files changed, 23 insertions(+), 17 deletions(-)
16
11
17
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
12
diff --git a/block/vmdk.c b/block/vmdk.c
18
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-io-cmds.c
14
--- a/block/vmdk.c
20
+++ b/qemu-io-cmds.c
15
+++ b/block/vmdk.c
21
@@ -XXX,XX +XXX,XX @@ out:
16
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
22
static int alloc_f(BlockBackend *blk, int argc, char **argv)
17
qemu_iovec_concat(&local_qiov, qiov, qiov_offset, n_bytes);
23
{
24
BlockDriverState *bs = blk_bs(blk);
25
- int64_t offset, sector_num, nb_sectors, remaining;
26
+ int64_t offset, sector_num, nb_sectors, remaining, count;
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
}
18
}
32
19
33
if (argc == 3) {
20
- write_offset = cluster_offset + offset_in_cluster,
34
- nb_sectors = cvtnum(argv[2]);
21
+ write_offset = cluster_offset + offset_in_cluster;
35
- if (nb_sectors < 0) {
22
ret = bdrv_co_pwritev(extent->file, write_offset, n_bytes,
36
- print_cvtnum_err(nb_sectors, argv[2]);
23
&local_qiov, 0);
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
}
72
73
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t alloc_cmd = {
74
.argmin = 1,
75
.argmax = 2,
76
.cfunc = alloc_f,
77
- .args = "off [sectors]",
78
- .oneline = "checks if a sector is present in the file",
79
+ .args = "offset [count]",
80
+ .oneline = "checks if offset is allocated in the file",
81
};
82
83
84
diff --git a/tests/qemu-iotests/019.out b/tests/qemu-iotests/019.out
85
index XXXXXXX..XXXXXXX 100644
86
--- a/tests/qemu-iotests/019.out
87
+++ b/tests/qemu-iotests/019.out
88
@@ -XXX,XX +XXX,XX @@ Testing conversion with -B TEST_DIR/t.IMGFMT.base
89
90
Checking if backing clusters are allocated when they shouldn't
91
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
24
123
--
25
--
124
1.8.3.1
26
2.13.6
125
27
126
28
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
When calculating the number of reftable entries, we should actually use
3
Persistent dirty bitmaps require a properly functioning
4
the number of refblocks and not (wrongly[1]) re-calculate it.
4
autoclear_features field, or we cannot track when an unsupporting
5
program might overwrite them. Therefore, we cannot support them for
6
compat=0.10 images.
5
7
6
[1] "Wrongly" means: Dividing the number of clusters by the number of
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
entries per refblock and rounding down instead of up.
9
Message-id: 20171123020832.8165-3-mreitz@redhat.com
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
block/qcow2-bitmap.c | 10 ++++++++++
14
block/qcow2.c | 14 +++++++++++---
15
2 files changed, 21 insertions(+), 3 deletions(-)
8
16
9
Reported-by: Eric Blake <eblake@redhat.com>
17
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
index XXXXXXX..XXXXXXX 100644
11
Reviewed-by: Eric Blake <eblake@redhat.com>
19
--- a/block/qcow2-bitmap.c
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
20
+++ b/block/qcow2-bitmap.c
13
---
21
@@ -XXX,XX +XXX,XX @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
14
block/qcow2.c | 9 +++++----
22
bool found;
15
1 file changed, 5 insertions(+), 4 deletions(-)
23
Qcow2BitmapList *bm_list;
16
24
25
+ if (s->qcow_version < 3) {
26
+ /* Without autoclear_features, we would always have to assume
27
+ * that a program without persistent dirty bitmap support has
28
+ * accessed this qcow2 file when opening it, and would thus
29
+ * have to drop all dirty bitmaps (defeating their purpose).
30
+ */
31
+ error_setg(errp, "Cannot store dirty bitmaps in qcow2 v2 files");
32
+ goto fail;
33
+ }
34
+
35
if (check_constraints_on_bitmap(bs, name, granularity, errp) != 0) {
36
goto fail;
37
}
17
diff --git a/block/qcow2.c b/block/qcow2.c
38
diff --git a/block/qcow2.c b/block/qcow2.c
18
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
19
--- a/block/qcow2.c
40
--- a/block/qcow2.c
20
+++ b/block/qcow2.c
41
+++ b/block/qcow2.c
21
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
42
@@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
22
* too, as long as the bulk is allocated here). Therefore, using
43
}
23
* floating point arithmetic is fine. */
44
24
int64_t meta_size = 0;
45
if (!(s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS)) {
25
- uint64_t nreftablee, nrefblocke, nl1e, nl2e;
46
- warn_report("a program lacking bitmap support "
26
+ uint64_t nreftablee, nrefblocke, nl1e, nl2e, refblock_count;
47
- "modified this file, so all bitmaps are now "
27
int64_t aligned_total_size = align_offset(total_size, cluster_size);
48
- "considered inconsistent");
28
int refblock_bits, refblock_size;
49
+ if (s->qcow_version < 3) {
29
/* refcount entry size in bytes */
50
+ /* Let's be a bit more specific */
30
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
51
+ warn_report("This qcow2 v2 image contains bitmaps, but "
31
nrefblocke = (aligned_total_size + meta_size + cluster_size)
52
+ "they may have been modified by a program "
32
/ (cluster_size - rces - rces * sizeof(uint64_t)
53
+ "without persistent bitmap support; so now "
33
/ cluster_size);
54
+ "they must all be considered inconsistent");
34
- meta_size += DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size;
55
+ } else {
35
+ refblock_count = DIV_ROUND_UP(nrefblocke, refblock_size);
56
+ warn_report("a program lacking bitmap support "
36
+ meta_size += refblock_count * cluster_size;
57
+ "modified this file, so all bitmaps are now "
37
58
+ "considered inconsistent");
38
/* total size of refcount tables */
59
+ }
39
- nreftablee = nrefblocke / refblock_size;
60
error_printf("Some clusters may be leaked, "
40
- nreftablee = align_offset(nreftablee, cluster_size / sizeof(uint64_t));
61
"run 'qemu-img check -r' on the image "
41
+ nreftablee = align_offset(refblock_count,
62
"file to fix.");
42
+ cluster_size / sizeof(uint64_t));
43
meta_size += nreftablee * sizeof(uint64_t);
44
45
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
46
--
63
--
47
1.8.3.1
64
2.13.6
48
65
49
66
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
We were throwing away the preallocation information associated with
3
This is not necessarily complete, but it should include the most
4
zero clusters. But we should be matching the well-defined semantics
4
important places.
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
5
10
count_contiguous_clusters_by_type() is now used only for unallocated
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
cluster runs, hence it gets renamed and tightened.
7
Message-id: 20171123020832.8165-4-mreitz@redhat.com
12
8
Reviewed-by: Eric Blake <eblake@redhat.com>
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>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
26
---
10
---
27
block/qcow2-cluster.c | 45 +++++++++++++++++++++++++++++++++++----------
11
block/qcow.c | 16 ++++++++++++++++
28
1 file changed, 35 insertions(+), 10 deletions(-)
12
1 file changed, 16 insertions(+)
29
13
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
14
diff --git a/block/qcow.c b/block/qcow.c
31
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
16
--- a/block/qcow.c
33
+++ b/block/qcow2-cluster.c
17
+++ b/block/qcow.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
18
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
35
    return i;
19
/* update the L1 entry */
36
}
20
s->l1_table[l1_index] = l2_offset;
37
21
tmp = cpu_to_be64(l2_offset);
38
-static int count_contiguous_clusters_by_type(int nb_clusters,
22
+ BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
39
- uint64_t *l2_table,
23
ret = bdrv_pwrite_sync(bs->file,
40
- int wanted_type)
24
s->l1_table_offset + l1_index * sizeof(tmp),
41
+/*
25
&tmp, sizeof(tmp));
42
+ * Checks how many consecutive unallocated clusters in a given L2
26
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
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
}
27
}
62
}
28
}
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
29
l2_table = s->l2_cache + (min_index << s->l2_bits);
64
ret = -EIO;
30
+ BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
65
goto fail;
31
if (new_l2_table) {
66
}
32
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
67
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
33
ret = bdrv_pwrite_sync(bs->file, l2_offset, l2_table,
68
- QCOW2_CLUSTER_ZERO);
34
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
69
- *cluster_offset = 0;
35
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) {
70
+ /* Distinguish between pure zero clusters and pre-allocated ones */
36
if (!allocate)
71
+ if (*cluster_offset & L2E_OFFSET_MASK) {
37
return 0;
72
+ c = count_contiguous_clusters(nb_clusters, s->cluster_size,
38
+ BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC);
73
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
39
/* allocate a new cluster */
74
+ *cluster_offset &= L2E_OFFSET_MASK;
40
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) &&
75
+ if (offset_into_cluster(s, *cluster_offset)) {
41
(n_end - n_start) < s->cluster_sectors) {
76
+ qcow2_signal_corruption(bs, true, -1, -1,
42
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
77
+ "Preallocated zero cluster offset %#"
43
}
78
+ PRIx64 " unaligned (L2 offset: %#"
44
cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size);
79
+ PRIx64 ", L2 index: %#x)",
45
/* write the cluster content */
80
+ *cluster_offset, l2_offset, l2_index);
46
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
81
+ ret = -EIO;
47
ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache,
82
+ goto fail;
48
s->cluster_size);
83
+ }
49
if (ret < 0) {
50
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
51
NULL) < 0) {
52
return -EIO;
53
}
54
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
55
ret = bdrv_pwrite(bs->file,
56
cluster_offset + i * 512,
57
s->cluster_data, 512);
58
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
59
/* update L2 table */
60
tmp = cpu_to_be64(cluster_offset);
61
l2_table[l2_index] = tmp;
62
+ if (allocate == 2) {
63
+ BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE_COMPRESSED);
84
+ } else {
64
+ } else {
85
+ c = count_contiguous_clusters_unallocated(nb_clusters,
65
+ BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
86
+ &l2_table[l2_index],
87
+ QCOW2_CLUSTER_ZERO);
88
+ *cluster_offset = 0;
89
+ }
66
+ }
90
break;
67
ret = bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp),
91
case QCOW2_CLUSTER_UNALLOCATED:
68
&tmp, sizeof(tmp));
92
/* how many empty clusters ? */
69
if (ret < 0) {
93
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
70
@@ -XXX,XX +XXX,XX @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
94
- QCOW2_CLUSTER_UNALLOCATED);
71
if (s->cluster_cache_offset != coffset) {
95
+ c = count_contiguous_clusters_unallocated(nb_clusters,
72
csize = cluster_offset >> (63 - s->cluster_bits);
96
+ &l2_table[l2_index],
73
csize &= (s->cluster_size - 1);
97
+ QCOW2_CLUSTER_UNALLOCATED);
74
+ BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
98
*cluster_offset = 0;
75
ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize);
99
break;
76
if (ret != csize)
100
case QCOW2_CLUSTER_NORMAL:
77
return -1;
78
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num,
79
hd_iov.iov_len = n * 512;
80
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
81
qemu_co_mutex_unlock(&s->lock);
82
+ /* qcow2 emits this on bs->file instead of bs->backing */
83
+ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
84
ret = bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov);
85
qemu_co_mutex_lock(&s->lock);
86
if (ret < 0) {
87
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num,
88
hd_iov.iov_len = n * 512;
89
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
90
qemu_co_mutex_unlock(&s->lock);
91
+ BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
92
ret = bdrv_co_readv(bs->file,
93
(cluster_offset >> 9) + index_in_cluster,
94
n, &hd_qiov);
95
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num,
96
hd_iov.iov_len = n * 512;
97
qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
98
qemu_co_mutex_unlock(&s->lock);
99
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
100
ret = bdrv_co_writev(bs->file,
101
(cluster_offset >> 9) + index_in_cluster,
102
n, &hd_qiov);
103
@@ -XXX,XX +XXX,XX @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
104
.iov_len = out_len,
105
};
106
qemu_iovec_init_external(&hd_qiov, &iov, 1);
107
+ BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);
108
ret = bdrv_co_pwritev(bs->file, cluster_offset, out_len, &hd_qiov, 0);
109
if (ret < 0) {
110
goto fail;
101
--
111
--
102
1.8.3.1
112
2.13.6
103
113
104
114
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Although it doesn't add all that much type safety (this is C, after
3
This is certainly not complete, but it includes at least write_aio and
4
all), it does add a bit of legibility to use the name QCow2ClusterType
4
read_aio.
5
instead of a plain int.
6
5
7
In particular, qcow2_get_cluster_offset() has an overloaded return
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
type; a QCow2ClusterType on success, and -errno on failure; keeping
7
Message-id: 20171123020832.8165-5-mreitz@redhat.com
9
the cluster type in a separate variable makes it slightly easier for
8
Reviewed-by: Fam Zheng <famz@redhat.com>
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>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
10
---
19
block/qcow2-cluster.c | 21 +++++++++++----------
11
block/vmdk.c | 16 ++++++++++++++++
20
block/qcow2-refcount.c | 2 +-
12
1 file changed, 16 insertions(+)
21
block/qcow2.h | 6 +++---
22
3 files changed, 15 insertions(+), 14 deletions(-)
23
13
24
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
14
diff --git a/block/vmdk.c b/block/vmdk.c
25
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
26
--- a/block/qcow2-cluster.c
16
--- a/block/vmdk.c
27
+++ b/block/qcow2-cluster.c
17
+++ b/block/vmdk.c
28
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
18
@@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs,
29
uint64_t *l2_table, uint64_t stop_flags)
19
/* Read backing data before skip range */
20
if (skip_start_bytes > 0) {
21
if (bs->backing) {
22
+ /* qcow2 emits this on bs->file instead of bs->backing */
23
+ BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
24
ret = bdrv_pread(bs->backing, offset, whole_grain,
25
skip_start_bytes);
26
if (ret < 0) {
27
@@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs,
28
goto exit;
29
}
30
}
31
+ BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
32
ret = bdrv_pwrite(extent->file, cluster_offset, whole_grain,
33
skip_start_bytes);
34
if (ret < 0) {
35
@@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs,
36
/* Read backing data after skip range */
37
if (skip_end_bytes < cluster_bytes) {
38
if (bs->backing) {
39
+ /* qcow2 emits this on bs->file instead of bs->backing */
40
+ BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
41
ret = bdrv_pread(bs->backing, offset + skip_end_bytes,
42
whole_grain + skip_end_bytes,
43
cluster_bytes - skip_end_bytes);
44
@@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs,
45
goto exit;
46
}
47
}
48
+ BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
49
ret = bdrv_pwrite(extent->file, cluster_offset + skip_end_bytes,
50
whole_grain + skip_end_bytes,
51
cluster_bytes - skip_end_bytes);
52
@@ -XXX,XX +XXX,XX @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data,
30
{
53
{
31
int i;
54
offset = cpu_to_le32(offset);
32
- int first_cluster_type;
55
/* update L2 table */
33
+ QCow2ClusterType first_cluster_type;
56
+ BLKDBG_EVENT(extent->file, BLKDBG_L2_UPDATE);
34
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
57
if (bdrv_pwrite_sync(extent->file,
35
uint64_t first_entry = be64_to_cpu(l2_table[0]);
58
((int64_t)m_data->l2_offset * 512)
36
uint64_t offset = first_entry & mask;
59
+ (m_data->l2_index * sizeof(offset)),
37
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
60
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
38
*/
61
}
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
}
62
}
71
63
l2_table = extent->l2_cache + (min_index * extent->l2_size);
72
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
64
+ BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD);
73
if (!l2_offset) {
65
if (bdrv_pread(extent->file,
74
- ret = QCOW2_CLUSTER_UNALLOCATED;
66
(int64_t)l2_offset * 512,
75
+ type = QCOW2_CLUSTER_UNALLOCATED;
67
l2_table,
76
goto out;
68
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
69
.iov_len = n_bytes,
70
};
71
qemu_iovec_init_external(&local_qiov, &iov, 1);
72
+
73
+ BLKDBG_EVENT(extent->file, BLKDBG_WRITE_COMPRESSED);
74
} else {
75
qemu_iovec_init(&local_qiov, qiov->niov);
76
qemu_iovec_concat(&local_qiov, qiov, qiov_offset, n_bytes);
77
+
78
+ BLKDBG_EVENT(extent->file, BLKDBG_WRITE_AIO);
77
}
79
}
78
80
79
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
81
write_offset = cluster_offset + offset_in_cluster;
80
* true */
82
@@ -XXX,XX +XXX,XX @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset,
81
assert(nb_clusters <= INT_MAX);
83
82
84
83
- ret = qcow2_get_cluster_type(*cluster_offset);
85
if (!extent->compressed) {
84
- switch (ret) {
86
+ BLKDBG_EVENT(extent->file, BLKDBG_READ_AIO);
85
+ type = qcow2_get_cluster_type(*cluster_offset);
87
ret = bdrv_co_preadv(extent->file,
86
+ switch (type) {
88
cluster_offset + offset_in_cluster, bytes,
87
case QCOW2_CLUSTER_COMPRESSED:
89
qiov, 0);
88
/* Compressed clusters can only be processed one by one */
90
@@ -XXX,XX +XXX,XX @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset,
89
c = 1;
91
buf_bytes = cluster_bytes * 2;
90
@@ -XXX,XX +XXX,XX @@ out:
92
cluster_buf = g_malloc(buf_bytes);
91
assert(bytes_available - offset_in_cluster <= UINT_MAX);
93
uncomp_buf = g_malloc(cluster_bytes);
92
*bytes = bytes_available - offset_in_cluster;
94
+ BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED);
93
95
ret = bdrv_pread(extent->file,
94
- return ret;
96
cluster_offset,
95
+ return type;
97
cluster_buf, buf_bytes);
96
98
@@ -XXX,XX +XXX,XX @@ vmdk_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
97
fail:
99
qemu_iovec_reset(&local_qiov);
98
qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table);
100
qemu_iovec_concat(&local_qiov, qiov, bytes_done, n_bytes);
99
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
101
100
102
+ /* qcow2 emits this on bs->file instead of bs->backing */
101
for (i = 0; i < nb_clusters; i++) {
103
+ BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
102
uint64_t l2_entry = be64_to_cpu(l2_table[l2_index + i]);
104
ret = bdrv_co_preadv(bs->backing, offset, n_bytes,
103
- int cluster_type = qcow2_get_cluster_type(l2_entry);
105
&local_qiov, 0);
104
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
106
if (ret < 0) {
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
}
152
153
-static inline int qcow2_get_cluster_type(uint64_t l2_entry)
154
+static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
155
{
156
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
157
return QCOW2_CLUSTER_COMPRESSED;
158
--
107
--
159
1.8.3.1
108
2.13.6
160
109
161
110
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
util/qemu-progress.c is currently unmaintained. The only user of its
3
read without -r eats backslashes.
4
functionality is qemu-img, so it effectively is part of the block layer.
5
4
6
Suggested-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Message-id: 20170428165517.30341-1-mreitz@redhat.com
6
Message-id: 20171123020832.8165-6-mreitz@redhat.com
9
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Fam Zheng <famz@redhat.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
9
---
13
MAINTAINERS | 1 +
10
tests/qemu-iotests/common.rc | 2 +-
14
1 file changed, 1 insertion(+)
11
1 file changed, 1 insertion(+), 1 deletion(-)
15
12
16
diff --git a/MAINTAINERS b/MAINTAINERS
13
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
17
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
18
--- a/MAINTAINERS
15
--- a/tests/qemu-iotests/common.rc
19
+++ b/MAINTAINERS
16
+++ b/tests/qemu-iotests/common.rc
20
@@ -XXX,XX +XXX,XX @@ F: include/block/
17
@@ -XXX,XX +XXX,XX @@ _img_info()
21
F: qemu-img*
18
-e "s#$IMGFMT#IMGFMT#g" \
22
F: qemu-io*
19
-e "/^disk size:/ D" \
23
F: tests/qemu-iotests/
20
-e "/actual-size/ D" | \
24
+F: util/qemu-progress.c
21
- while IFS='' read line; do
25
T: git git://repo.or.cz/qemu/kevin.git block
22
+ while IFS='' read -r line; do
26
23
if [[ $format_specific == 1 ]]; then
27
Block I/O path
24
discard=0
25
elif [[ $line == "Format specific information:" ]]; then
28
--
26
--
29
1.8.3.1
27
2.13.6
30
28
31
29
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Although _filter_qemu_img_map documents that it scrubs offsets, it
3
_filter_img_info should remove format-specific information, too. We
4
was only doing so for human mode. Of the existing tests using the
4
already have such a filter in _img_info, and it is very useful for
5
filter (97, 122, 150, 154, 176), two of them are affected, but it
5
query-block-named-block-nodes (etc.), too.
6
does not hurt the validity of the tests to not require particular
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
6
11
Another justification for this patch is that it will allow a future
7
However, in 198 we need that information (but we still want the rest of
12
patch to utilize 'qemu-img map --output=json' to check the status of
8
the filter), so make that filtering optional. Note that "the rest of
13
preallocated zero clusters without regards to the mapping (since
9
the filter" includes filtering of the test directory, so we can drop the
14
the qcow2 mapping can be very sensitive to the chosen cluster size,
10
_filter_testdir from 198 at the same time.
15
when preallocation is not in use).
16
11
17
Signed-off-by: Eric Blake <eblake@redhat.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Message-id: 20171123020832.8165-7-mreitz@redhat.com
19
Message-id: 20170507000552.20847-9-eblake@redhat.com
14
Reviewed-by: Eric Blake <eblake@redhat.com>
15
Reviewed-by: Fam Zheng <famz@redhat.com>
20
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
---
17
---
22
tests/qemu-iotests/122.out | 16 ++++++++--------
18
tests/qemu-iotests/198 | 6 ++++--
23
tests/qemu-iotests/154.out | 30 +++++++++++++++---------------
19
tests/qemu-iotests/common.filter | 29 ++++++++++++++++++++++++++++-
24
tests/qemu-iotests/common.filter | 4 +++-
20
2 files changed, 32 insertions(+), 3 deletions(-)
25
3 files changed, 26 insertions(+), 24 deletions(-)
26
21
27
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
22
diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198
28
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100755
29
--- a/tests/qemu-iotests/122.out
24
--- a/tests/qemu-iotests/198
30
+++ b/tests/qemu-iotests/122.out
25
+++ b/tests/qemu-iotests/198
31
@@ -XXX,XX +XXX,XX @@ read 3145728/3145728 bytes at offset 0
26
@@ -XXX,XX +XXX,XX @@ $QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-op
32
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
27
33
read 63963136/63963136 bytes at offset 3145728
28
echo
34
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
29
echo "== checking image base =="
35
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
30
-$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
36
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
31
+$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \
37
32
+ | sed -e "/^disk size:/ D"
38
convert -c -S 0:
33
39
read 3145728/3145728 bytes at offset 0
34
echo
40
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
35
echo "== checking image layer =="
41
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
36
-$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info | _filter_testdir | sed -e "/^disk size:/ D"
42
read 33554432/33554432 bytes at offset 33554432
37
+$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \
43
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
38
+ | sed -e "/^disk size:/ D"
44
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
39
45
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
40
46
41
# success, all done
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
42
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
186
index XXXXXXX..XXXXXXX 100644
43
index XXXXXXX..XXXXXXX 100644
187
--- a/tests/qemu-iotests/common.filter
44
--- a/tests/qemu-iotests/common.filter
188
+++ b/tests/qemu-iotests/common.filter
45
+++ b/tests/qemu-iotests/common.filter
46
@@ -XXX,XX +XXX,XX @@ _filter_img_create()
47
48
_filter_img_info()
49
{
50
+ if [[ "$1" == "--format-specific" ]]; then
51
+ local format_specific=1
52
+ shift
53
+ else
54
+ local format_specific=0
55
+ fi
56
+
57
+ discard=0
58
+ regex_json_spec_start='^ *"format-specific": \{'
59
sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
60
-e "s#$TEST_DIR#TEST_DIR#g" \
61
-e "s#$IMGFMT#IMGFMT#g" \
189
@@ -XXX,XX +XXX,XX @@ _filter_img_info()
62
@@ -XXX,XX +XXX,XX @@ _filter_img_info()
190
-e "/log_size: [0-9]\\+/d"
63
-e "/block_state_zero: \\(on\\|off\\)/d" \
64
-e "/log_size: [0-9]\\+/d" \
65
-e "s/iters: [0-9]\\+/iters: 1024/" \
66
- -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/"
67
+ -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \
68
+ while IFS='' read -r line; do
69
+ if [[ $format_specific == 1 ]]; then
70
+ discard=0
71
+ elif [[ $line == "Format specific information:" ]]; then
72
+ discard=1
73
+ elif [[ $line =~ $regex_json_spec_start ]]; then
74
+ discard=2
75
+ regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
76
+ fi
77
+ if [[ $discard == 0 ]]; then
78
+ echo "$line"
79
+ elif [[ $discard == 1 && ! $line ]]; then
80
+ echo
81
+ discard=0
82
+ elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
83
+ discard=0
84
+ fi
85
+ done
191
}
86
}
192
87
193
-# filter out offsets and file names from qemu-img map
88
# filter out offsets and file names from qemu-img map; good for both
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
--
89
--
204
1.8.3.1
90
2.13.6
205
91
206
92
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
We already audited (in commit 0c1bd469) that qcow2_discard_clusters()
3
This test does funny things like TEST_IMG="TEST_IMG.base" _make_test_img
4
is only passed cluster-aligned start values; but we can further
4
that usually only work with the file protocol. More specifically, they
5
tighten the assertion that the only unaligned end value is at EOF.
5
do not work with the most interesting non-file protocols, so we might as
6
well skip this for anything but file.
6
7
7
Recent commits have taken advantage of an unaligned tail cluster,
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
for both discard and write zeroes.
9
Message-id: 20171123020832.8165-8-mreitz@redhat.com
9
10
Reviewed-by: Fam Zheng <famz@redhat.com>
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>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
12
---
15
block/qcow2-cluster.c | 15 +++++++++++----
13
tests/qemu-iotests/020 | 8 +-------
16
1 file changed, 11 insertions(+), 4 deletions(-)
14
1 file changed, 1 insertion(+), 7 deletions(-)
17
15
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
16
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100755
20
--- a/block/qcow2-cluster.c
18
--- a/tests/qemu-iotests/020
21
+++ b/block/qcow2-cluster.c
19
+++ b/tests/qemu-iotests/020
22
@@ -XXX,XX +XXX,XX @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
20
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
23
21
24
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
22
# Any format supporting backing files
25
23
_supported_fmt qcow qcow2 vmdk qed
26
- /* The caller must cluster-align start; round end down except at EOF */
24
-_supported_proto generic
27
+ /* Caller must pass aligned values, except at image end */
25
-_unsupported_proto vxhs
28
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
26
+_supported_proto file
29
- if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
27
_supported_os Linux
30
- end_offset = start_of_cluster(s, end_offset);
28
_unsupported_imgopts "subformat=monolithicFlat" \
31
- }
29
"subformat=twoGbMaxExtentFlat" \
32
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
30
"subformat=twoGbMaxExtentSparse"
33
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
31
34
32
-# NFS does not support bdrv_reopen_prepare thus qemu-img commit fails.
35
nb_clusters = size_to_clusters(s, end_offset - offset);
33
-if [ "$IMGPROTO" = "nfs" ]; then
36
34
- _notrun "image protocol $IMGPROTO does not support bdrv_commit"
37
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
35
-fi
38
int flags)
36
-
39
{
37
TEST_OFFSETS="0 4294967296"
40
BDRVQcow2State *s = bs->opaque;
38
41
+ uint64_t end_offset;
39
TEST_IMG_SAVE="$TEST_IMG"
42
uint64_t nb_clusters;
43
int ret;
44
45
+ end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
46
+
47
+ /* Caller must pass aligned values, except at image end */
48
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
49
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
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
--
40
--
56
1.8.3.1
41
2.13.6
57
42
58
43
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
3
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
any I/O to fit within device boundaries. Additionally, when using a
4
Message-id: 20171123020832.8165-9-mreitz@redhat.com
5
minimum alignment of 4k, we want to ensure the block layer does proper
5
Reviewed-by: John Snow <jsnow@redhat.com>
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>
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
7
---
18
block/blkdebug.c | 14 ++++++++++++++
8
tests/qemu-iotests/103 | 2 ++
19
1 file changed, 14 insertions(+)
9
1 file changed, 2 insertions(+)
20
10
21
diff --git a/block/blkdebug.c b/block/blkdebug.c
11
diff --git a/tests/qemu-iotests/103 b/tests/qemu-iotests/103
22
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100755
23
--- a/block/blkdebug.c
13
--- a/tests/qemu-iotests/103
24
+++ b/block/blkdebug.c
14
+++ b/tests/qemu-iotests/103
25
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
15
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
26
BDRVBlkdebugState *s = bs->opaque;
16
_supported_fmt qcow2
27
BlkdebugRule *rule = NULL;
17
_supported_proto file nfs
28
18
_supported_os Linux
29
+ /* Sanity check block layer guarantees */
19
+# Internal snapshots are (currently) impossible with refcount_bits=1
30
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
20
+_unsupported_imgopts 'refcount_bits=1[^0-9]'
31
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
21
32
+ if (bs->bl.max_transfer) {
22
IMG_SIZE=64K
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
23
53
--
24
--
54
1.8.3.1
25
2.13.6
55
26
56
27
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
No tests were covering write zeroes with unmap. Additionally,
3
vmdk cannot work with anything but vmdk backing files, so make the
4
I needed to prove that my previous patches for correct status
4
backing file be the same format as the overlay.
5
reporting and write zeroes optimizations actually had an impact.
6
5
7
The test works for cluster_size between 8k and 2M (for smaller
6
Reported-by: John Snow <jsnow@redhat.com>
8
sizes, it fails because our allocation patterns are not contiguous
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
with small clusters - in part, the largest consecutive allocation
8
Message-id: 20171123020832.8165-11-mreitz@redhat.com
10
we tend to get is often bounded by the size covered by one L2
9
Reviewed-by: John Snow <jsnow@redhat.com>
11
table).
10
Reviewed-by: Fam Zheng <famz@redhat.com>
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>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
27
---
12
---
28
tests/qemu-iotests/179 | 130 +++++++++++++++++++++++++++++++++++++
13
tests/qemu-iotests/020 | 9 ++++++---
29
tests/qemu-iotests/179.out | 156 +++++++++++++++++++++++++++++++++++++++++++++
14
tests/qemu-iotests/020.out | 6 ++++--
30
tests/qemu-iotests/group | 1 +
15
2 files changed, 10 insertions(+), 5 deletions(-)
31
3 files changed, 287 insertions(+)
32
create mode 100755 tests/qemu-iotests/179
33
create mode 100644 tests/qemu-iotests/179.out
34
16
35
diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179
17
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
36
new file mode 100755
18
index XXXXXXX..XXXXXXX 100755
37
index XXXXXXX..XXXXXXX
19
--- a/tests/qemu-iotests/020
38
--- /dev/null
20
+++ b/tests/qemu-iotests/020
39
+++ b/tests/qemu-iotests/179
21
@@ -XXX,XX +XXX,XX @@ echo
40
@@ -XXX,XX +XXX,XX @@
22
echo 'Testing failing commit'
41
+#!/bin/bash
23
echo
42
+#
24
43
+# Test case for write zeroes with unmap
25
+TEST_IMG="$TEST_IMG.base" _make_test_img 1M
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
+
26
+
61
+# creator
27
# Create an image with a null backing file to which committing will fail (with
62
+owner=eblake@redhat.com
28
# ENOSPC so we can distinguish the result from some generic EIO which may be
63
+
29
# generated anywhere in the block layer)
64
+seq="$(basename $0)"
30
-_make_test_img -b "json:{'driver': 'raw',
65
+echo "QA output created by $seq"
31
+_make_test_img -b "json:{'driver': '$IMGFMT',
66
+
32
'file': {
67
+here="$PWD"
33
'driver': 'blkdebug',
68
+status=1    # failure is the default!
34
'inject-error': [{
69
+
35
@@ -XXX,XX +XXX,XX @@ _make_test_img -b "json:{'driver': 'raw',
70
+_cleanup()
36
'once': true
71
+{
37
}],
72
+    _cleanup_test_img
38
'image': {
73
+}
39
- 'driver': 'null-co'
74
+trap "_cleanup; exit \$status" 0 1 2 3 15
40
+ 'driver': 'file',
75
+
41
+ 'filename': '$TEST_IMG.base'
76
+# get standard environment, filters and checks
42
}}}"
77
+. ./common.rc
43
78
+. ./common.filter
44
# Just write anything so committing will not be a no-op
79
+
45
$QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io
80
+_supported_fmt qcow2
46
81
+_supported_proto file
47
$QEMU_IMG commit "$TEST_IMG"
82
+_supported_os Linux
48
-_cleanup_test_img
83
+
49
+_cleanup
84
+# v2 images can't mark clusters as zero
50
85
+_unsupported_imgopts compat=0.10
51
# success, all done
86
+
52
echo "*** done"
87
+echo
53
diff --git a/tests/qemu-iotests/020.out b/tests/qemu-iotests/020.out
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
54
index XXXXXXX..XXXXXXX 100644
335
--- a/tests/qemu-iotests/group
55
--- a/tests/qemu-iotests/020.out
336
+++ b/tests/qemu-iotests/group
56
+++ b/tests/qemu-iotests/020.out
337
@@ -XXX,XX +XXX,XX @@
57
@@ -XXX,XX +XXX,XX @@ No errors were found on the image.
338
175 auto quick
58
339
176 rw auto backing
59
Testing failing commit
340
177 rw auto quick
60
341
+179 rw auto quick
61
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 backing_file=json:{'driver': 'raw',,
342
181 rw auto migration
62
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1048576
343
182 rw auto quick
63
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=json:{'driver': 'IMGFMT',,
64
'file': {
65
'driver': 'blkdebug',,
66
'inject-error': [{
67
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 backing_file=json:{'d
68
'once': true
69
}],,
70
'image': {
71
- 'driver': 'null-co'
72
+ 'driver': 'file',,
73
+ 'filename': 'TEST_DIR/t.IMGFMT.base'
74
}}}
75
wrote 65536/65536 bytes at offset 0
76
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
344
--
77
--
345
1.8.3.1
78
2.13.6
346
79
347
80
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Similar to discard_single_l2(), we should try to avoid dirtying
3
051 has both compat=1.1 and compat=0.10 tests (once it uses
4
the L2 cache when the cluster we are changing already has the
4
lazy_refcounts, once it tests that setting them does not work).
5
right characteristics.
5
For the compat=0.10 tests, it already explicitly creates a suitable
6
image. So let's just ignore the user-specified compat level for the
7
lazy_refcounts test and explicitly create a compat=1.1 image there, too.
6
8
7
Note that by the time we get to zero_single_l2(), BDRV_REQ_MAY_UNMAP
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
is a requirement to unallocate a cluster (this is because the block
10
Message-id: 20171123020832.8165-12-mreitz@redhat.com
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>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
34
---
12
---
35
block/qcow2-cluster.c | 15 +++++++++++++--
13
tests/qemu-iotests/051 | 2 ++
36
1 file changed, 13 insertions(+), 2 deletions(-)
14
tests/qemu-iotests/051.out | 1 +
15
tests/qemu-iotests/051.pc.out | 1 +
16
3 files changed, 4 insertions(+)
37
17
38
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
18
diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
19
index XXXXXXX..XXXXXXX 100755
20
--- a/tests/qemu-iotests/051
21
+++ b/tests/qemu-iotests/051
22
@@ -XXX,XX +XXX,XX @@ echo
23
echo === Enable and disable lazy refcounting on the command line, plus some invalid values ===
24
echo
25
26
+_make_test_img -o compat=1.1 "$size"
27
+
28
run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
29
run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
30
run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
31
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
39
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
40
--- a/block/qcow2-cluster.c
33
--- a/tests/qemu-iotests/051.out
41
+++ b/block/qcow2-cluster.c
34
+++ b/tests/qemu-iotests/051.out
42
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
35
@@ -XXX,XX +XXX,XX @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,file.backing.driver=qcow2,file.backing.f
43
int l2_index;
36
44
int ret;
37
=== Enable and disable lazy refcounting on the command line, plus some invalid values ===
45
int i;
38
46
+ bool unmap = !!(flags & BDRV_REQ_MAY_UNMAP);
39
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
47
40
Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,lazy-refcounts=on
48
ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
41
QEMU X.Y.Z monitor - type 'help' for more information
49
if (ret < 0) {
42
(qemu) quit
50
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
43
diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
51
44
index XXXXXXX..XXXXXXX 100644
52
for (i = 0; i < nb_clusters; i++) {
45
--- a/tests/qemu-iotests/051.pc.out
53
uint64_t old_offset;
46
+++ b/tests/qemu-iotests/051.pc.out
54
+ QCow2ClusterType cluster_type;
47
@@ -XXX,XX +XXX,XX @@ QEMU_PROG: -drive file=TEST_DIR/t.qcow2,file.backing.driver=qcow2,file.backing.f
55
48
56
old_offset = be64_to_cpu(l2_table[l2_index + i]);
49
=== Enable and disable lazy refcounting on the command line, plus some invalid values ===
57
50
58
- /* Update L2 entries */
51
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
59
+ /*
52
Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,lazy-refcounts=on
60
+ * Minimize L2 changes if the cluster already reads back as
53
QEMU X.Y.Z monitor - type 'help' for more information
61
+ * zeroes with correct allocation.
54
(qemu) quit
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
--
55
--
76
1.8.3.1
56
2.13.6
77
57
78
58
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
We've already improved discards to operate efficiently on the tail
3
As of commit 9877860e7bd1e26ee70ab9bb5ebc34c92bf23bf5, vmdk fails
4
of an unaligned qcow2 image; it's time to make a similar improvement
4
differently when opening the sample image.
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
5
11
However, note that for now, the special case of end-of-file is only
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
recognized if there is no backing file, or if the backing file has
7
Message-id: 20171123020832.8165-13-mreitz@redhat.com
13
the same length; that's because when the backing file is shorter
8
Reviewed-by: John Snow <jsnow@redhat.com>
14
than the active layer, we don't have code in place to recognize
9
Reviewed-by: Fam Zheng <famz@redhat.com>
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>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
33
---
11
---
34
block/qcow2.c | 7 ++
12
tests/qemu-iotests/059.out | 2 +-
35
tests/qemu-iotests/154 | 160 ++++++++++++++++++++++++++++++++++++++++++++-
13
1 file changed, 1 insertion(+), 1 deletion(-)
36
tests/qemu-iotests/154.out | 128 ++++++++++++++++++++++++++++++++++++
37
3 files changed, 293 insertions(+), 2 deletions(-)
38
14
39
diff --git a/block/qcow2.c b/block/qcow2.c
15
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
40
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
41
--- a/block/qcow2.c
17
--- a/tests/qemu-iotests/059.out
42
+++ b/block/qcow2.c
18
+++ b/tests/qemu-iotests/059.out
43
@@ -XXX,XX +XXX,XX @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
19
@@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File
44
BlockDriverState *file;
20
0x140000000 0x10000 0x50000 TEST_DIR/t-s003.vmdk
45
int64_t res;
21
46
22
=== Testing afl image with a very large capacity ===
47
+ if (start + count > bs->total_sectors) {
23
-qemu-img: Can't get image size 'TEST_DIR/afl9.IMGFMT': File too large
48
+ count = bs->total_sectors - start;
24
+qemu-img: Could not open 'TEST_DIR/afl9.IMGFMT': Could not open 'TEST_DIR/afl9.IMGFMT': Invalid argument
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
25
*** done
386
--
26
--
387
1.8.3.1
27
2.13.6
388
28
389
29
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
We had some conflicting documentation: a nice 8-way table that
3
067 works very well with compat=0.10 once you remove format-specific
4
described all possible combinations of DATA, ZERO, and
4
information from the QMP output.
5
OFFSET_VALID, contrasted with text that implied that OFFSET_VALID
5
6
always meant raw data could be read directly. Furthermore, the
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
text refers a lot to bs->file, even though the interface was
7
Message-id: 20171123020832.8165-14-mreitz@redhat.com
8
updated back in 67a0fd2a to let the driver pass back a specific
8
Reviewed-by: John Snow <jsnow@redhat.com>
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
13
ALLOCATED is always set by the block layer for convenience (drivers
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>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
23
---
10
---
24
include/block/block.h | 35 +++++++++++++++++++----------------
11
tests/qemu-iotests/067 | 3 +-
25
include/block/block_int.h | 7 +++++++
12
tests/qemu-iotests/067.out | 97 +++++++++++++---------------------------------
26
2 files changed, 26 insertions(+), 16 deletions(-)
13
2 files changed, 28 insertions(+), 72 deletions(-)
27
14
28
diff --git a/include/block/block.h b/include/block/block.h
15
diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067
16
index XXXXXXX..XXXXXXX 100755
17
--- a/tests/qemu-iotests/067
18
+++ b/tests/qemu-iotests/067
19
@@ -XXX,XX +XXX,XX @@ function run_qemu()
20
{
21
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \
22
| _filter_actual_image_size \
23
- | _filter_generated_node_ids | _filter_qmp_events
24
+ | _filter_generated_node_ids | _filter_qmp_events \
25
+ | _filter_img_info
26
}
27
28
size=128M
29
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
29
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
30
--- a/include/block/block.h
31
--- a/tests/qemu-iotests/067.out
31
+++ b/include/block/block.h
32
+++ b/tests/qemu-iotests/067.out
32
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
33
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
33
#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
34
34
35
=== -drive/-device and device_del ===
35
/*
36
36
- * Allocation status flags
37
-Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virtio-blk,drive=disk,id=virtio0
37
- * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_status.
38
+Testing: -drive file=TEST_DIR/t.IMGFMT,format=IMGFMT,if=none,id=disk -device virtio-blk,drive=disk,id=virtio0
38
- * BDRV_BLOCK_ZERO: sectors read as zero
39
{
39
- * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by
40
QMP_VERSION
40
- * bdrv_get_block_status.
41
}
41
+ * Allocation status flags for bdrv_get_block_status() and friends.
42
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
42
+ *
43
"detect_zeroes": "off",
43
+ * Public flags:
44
"image": {
44
+ * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer
45
"virtual-size": 134217728,
45
+ * BDRV_BLOCK_ZERO: offset reads as zero
46
- "filename": "TEST_DIR/t.qcow2",
46
+ * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
47
+ "filename": "TEST_DIR/t.IMGFMT",
47
* BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
48
"cluster-size": 65536,
48
- * layer (as opposed to the backing file)
49
- "format": "qcow2",
49
- * BDRV_BLOCK_RAW: used internally to indicate that the request
50
+ "format": "IMGFMT",
50
- * was answered by the raw driver and that one
51
"actual-size": SIZE,
51
- * should look in bs->file directly.
52
- "format-specific": {
52
+ * layer (short for DATA || ZERO), set by block layer
53
- "type": "qcow2",
53
*
54
- "data": {
54
- * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
55
- "compat": "1.1",
55
- * bs->file where sector data can be read from as raw data.
56
- "lazy-refcounts": false,
56
+ * Internal flag:
57
- "refcount-bits": 16,
57
+ * BDRV_BLOCK_RAW: used internally to indicate that the request was
58
- "corrupt": false
58
+ * answered by a passthrough driver such as raw and that the
59
- }
59
+ * block layer should recompute the answer from bs->file.
60
- },
60
*
61
"dirty-flag": false
61
- * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present.
62
},
62
+ * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK)
63
"iops_wr": 0,
63
+ * represent the offset in the returned BDS that is allocated for the
64
"ro": false,
64
+ * corresponding raw data; however, whether that offset actually contains
65
"node-name": "NODE_NAME",
65
+ * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows:
66
"backing_file_depth": 0,
66
*
67
- "drv": "qcow2",
67
* DATA ZERO OFFSET_VALID
68
+ "drv": "IMGFMT",
68
- * t t t sectors read as zero, bs->file is zero at offset
69
"iops": 0,
69
- * t f t sectors read as valid from bs->file at offset
70
"bps_wr": 0,
70
- * f t t sectors preallocated, read as zero, bs->file not
71
"write_threshold": 0,
71
+ * t t t sectors read as zero, returned file is zero at offset
72
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
72
+ * t f t sectors read as valid from file at offset
73
"direct": false,
73
+ * f t t sectors preallocated, read as zero, returned file not
74
"writeback": true
74
* necessarily zero at offset
75
},
75
* f f t sectors preallocated but read from backing_hd,
76
- "file": "TEST_DIR/t.qcow2",
76
- * bs->file contains garbage at offset
77
+ "file": "TEST_DIR/t.IMGFMT",
77
+ * returned file contains garbage at offset
78
"encryption_key_missing": false
78
* t t f sectors preallocated, read as zero, unknown offset
79
},
79
* t f f sectors read from unknown file or offset
80
"qdev": "/machine/peripheral/virtio0/virtio-backend",
80
* f t f not allocated or unknown offset, read as zero
81
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
81
diff --git a/include/block/block_int.h b/include/block/block_int.h
82
82
index XXXXXXX..XXXXXXX 100644
83
=== -drive/device_add and device_del ===
83
--- a/include/block/block_int.h
84
84
+++ b/include/block/block_int.h
85
-Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
85
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
86
+Testing: -drive file=TEST_DIR/t.IMGFMT,format=IMGFMT,if=none,id=disk
86
int64_t offset, int count, BdrvRequestFlags flags);
87
{
87
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
88
QMP_VERSION
88
int64_t offset, int count);
89
}
89
+
90
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
90
+ /*
91
"detect_zeroes": "off",
91
+ * Building block for bdrv_block_status[_above]. The driver should
92
"image": {
92
+ * answer only according to the current layer, and should not
93
"virtual-size": 134217728,
93
+ * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h
94
- "filename": "TEST_DIR/t.qcow2",
94
+ * for the meaning of _DATA, _ZERO, and _OFFSET_VALID.
95
+ "filename": "TEST_DIR/t.IMGFMT",
95
+ */
96
"cluster-size": 65536,
96
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
97
- "format": "qcow2",
97
int64_t sector_num, int nb_sectors, int *pnum,
98
+ "format": "IMGFMT",
98
BlockDriverState **file);
99
"actual-size": SIZE,
100
- "format-specific": {
101
- "type": "qcow2",
102
- "data": {
103
- "compat": "1.1",
104
- "lazy-refcounts": false,
105
- "refcount-bits": 16,
106
- "corrupt": false
107
- }
108
- },
109
"dirty-flag": false
110
},
111
"iops_wr": 0,
112
"ro": false,
113
"node-name": "NODE_NAME",
114
"backing_file_depth": 0,
115
- "drv": "qcow2",
116
+ "drv": "IMGFMT",
117
"iops": 0,
118
"bps_wr": 0,
119
"write_threshold": 0,
120
@@ -XXX,XX +XXX,XX @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
121
"direct": false,
122
"writeback": true
123
},
124
- "file": "TEST_DIR/t.qcow2",
125
+ "file": "TEST_DIR/t.IMGFMT",
126
"encryption_key_missing": false
127
},
128
"type": "unknown"
129
@@ -XXX,XX +XXX,XX @@ Testing:
130
"detect_zeroes": "off",
131
"image": {
132
"virtual-size": 134217728,
133
- "filename": "TEST_DIR/t.qcow2",
134
+ "filename": "TEST_DIR/t.IMGFMT",
135
"cluster-size": 65536,
136
- "format": "qcow2",
137
+ "format": "IMGFMT",
138
"actual-size": SIZE,
139
- "format-specific": {
140
- "type": "qcow2",
141
- "data": {
142
- "compat": "1.1",
143
- "lazy-refcounts": false,
144
- "refcount-bits": 16,
145
- "corrupt": false
146
- }
147
- },
148
"dirty-flag": false
149
},
150
"iops_wr": 0,
151
"ro": false,
152
"node-name": "NODE_NAME",
153
"backing_file_depth": 0,
154
- "drv": "qcow2",
155
+ "drv": "IMGFMT",
156
"iops": 0,
157
"bps_wr": 0,
158
"write_threshold": 0,
159
@@ -XXX,XX +XXX,XX @@ Testing:
160
"direct": false,
161
"writeback": true
162
},
163
- "file": "TEST_DIR/t.qcow2",
164
+ "file": "TEST_DIR/t.IMGFMT",
165
"encryption_key_missing": false
166
},
167
"type": "unknown"
168
@@ -XXX,XX +XXX,XX @@ Testing:
169
"detect_zeroes": "off",
170
"image": {
171
"virtual-size": 134217728,
172
- "filename": "TEST_DIR/t.qcow2",
173
+ "filename": "TEST_DIR/t.IMGFMT",
174
"cluster-size": 65536,
175
- "format": "qcow2",
176
+ "format": "IMGFMT",
177
"actual-size": SIZE,
178
- "format-specific": {
179
- "type": "qcow2",
180
- "data": {
181
- "compat": "1.1",
182
- "lazy-refcounts": false,
183
- "refcount-bits": 16,
184
- "corrupt": false
185
- }
186
- },
187
"dirty-flag": false
188
},
189
"iops_wr": 0,
190
"ro": false,
191
"node-name": "disk",
192
"backing_file_depth": 0,
193
- "drv": "qcow2",
194
+ "drv": "IMGFMT",
195
"iops": 0,
196
"bps_wr": 0,
197
"write_threshold": 0,
198
@@ -XXX,XX +XXX,XX @@ Testing:
199
"direct": false,
200
"writeback": true
201
},
202
- "file": "TEST_DIR/t.qcow2",
203
+ "file": "TEST_DIR/t.IMGFMT",
204
"encryption_key_missing": false
205
},
206
{
207
@@ -XXX,XX +XXX,XX @@ Testing:
208
"detect_zeroes": "off",
209
"image": {
210
"virtual-size": 197120,
211
- "filename": "TEST_DIR/t.qcow2",
212
+ "filename": "TEST_DIR/t.IMGFMT",
213
"format": "file",
214
"actual-size": SIZE,
215
"dirty-flag": false
216
@@ -XXX,XX +XXX,XX @@ Testing:
217
"direct": false,
218
"writeback": true
219
},
220
- "file": "TEST_DIR/t.qcow2",
221
+ "file": "TEST_DIR/t.IMGFMT",
222
"encryption_key_missing": false
223
}
224
]
225
@@ -XXX,XX +XXX,XX @@ Testing:
226
"detect_zeroes": "off",
227
"image": {
228
"virtual-size": 134217728,
229
- "filename": "TEST_DIR/t.qcow2",
230
+ "filename": "TEST_DIR/t.IMGFMT",
231
"cluster-size": 65536,
232
- "format": "qcow2",
233
+ "format": "IMGFMT",
234
"actual-size": SIZE,
235
- "format-specific": {
236
- "type": "qcow2",
237
- "data": {
238
- "compat": "1.1",
239
- "lazy-refcounts": false,
240
- "refcount-bits": 16,
241
- "corrupt": false
242
- }
243
- },
244
"dirty-flag": false
245
},
246
"iops_wr": 0,
247
"ro": false,
248
"node-name": "disk",
249
"backing_file_depth": 0,
250
- "drv": "qcow2",
251
+ "drv": "IMGFMT",
252
"iops": 0,
253
"bps_wr": 0,
254
"write_threshold": 0,
255
@@ -XXX,XX +XXX,XX @@ Testing:
256
"direct": false,
257
"writeback": true
258
},
259
- "file": "TEST_DIR/t.qcow2",
260
+ "file": "TEST_DIR/t.IMGFMT",
261
"encryption_key_missing": false
262
},
263
{
264
@@ -XXX,XX +XXX,XX @@ Testing:
265
"detect_zeroes": "off",
266
"image": {
267
"virtual-size": 197120,
268
- "filename": "TEST_DIR/t.qcow2",
269
+ "filename": "TEST_DIR/t.IMGFMT",
270
"format": "file",
271
"actual-size": SIZE,
272
"dirty-flag": false
273
@@ -XXX,XX +XXX,XX @@ Testing:
274
"direct": false,
275
"writeback": true
276
},
277
- "file": "TEST_DIR/t.qcow2",
278
+ "file": "TEST_DIR/t.IMGFMT",
279
"encryption_key_missing": false
280
}
281
]
99
--
282
--
100
1.8.3.1
283
2.13.6
101
284
102
285
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Fix a couple of inconsistent indentations, before an upcoming
3
The only thing that is missing is a _filter_img_info after the
4
patch further tweaks the switch statements.
4
"$QEMU_IO -c info" invocations.
5
(best viewed with 'git diff -b').
6
5
7
Signed-off-by: Eric Blake <eblake@redhat.com>
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Message-id: 20171123020832.8165-15-mreitz@redhat.com
9
Message-id: 20170507000552.20847-3-eblake@redhat.com
8
Reviewed-by: John Snow <jsnow@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
10
---
12
block/qcow2-cluster.c | 32 +++++++++----------
11
tests/qemu-iotests/089 | 4 ++--
13
block/qcow2-refcount.c | 84 +++++++++++++++++++++++++-------------------------
12
tests/qemu-iotests/089.out | 10 ----------
14
2 files changed, 58 insertions(+), 58 deletions(-)
13
2 files changed, 2 insertions(+), 12 deletions(-)
15
14
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
15
diff --git a/tests/qemu-iotests/089 b/tests/qemu-iotests/089
16
index XXXXXXX..XXXXXXX 100755
17
--- a/tests/qemu-iotests/089
18
+++ b/tests/qemu-iotests/089
19
@@ -XXX,XX +XXX,XX @@ echo
20
21
# Both options given directly and those given in the filename should be used
22
$QEMU_IO -c "open -o driver=qcow2 json:{\"file.filename\":\"$TEST_IMG\"}" \
23
- -c "info" 2>&1 | _filter_testdir | _filter_imgfmt
24
+ -c "info" 2>&1 | _filter_img_info
25
26
# Options given directly should be prioritized over those given in the filename
27
$QEMU_IO -c "open -o driver=qcow2 json:{\"driver\":\"raw\",\"file.filename\":\"$TEST_IMG\"}" \
28
- -c "info" 2>&1 | _filter_testdir | _filter_imgfmt
29
+ -c "info" 2>&1 | _filter_img_info
30
31
32
# success, all done
33
diff --git a/tests/qemu-iotests/089.out b/tests/qemu-iotests/089.out
17
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
35
--- a/tests/qemu-iotests/089.out
19
+++ b/block/qcow2-cluster.c
36
+++ b/tests/qemu-iotests/089.out
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
37
@@ -XXX,XX +XXX,XX @@ cluster_size: 65536
21
* but rather fall through to the backing file.
38
format name: IMGFMT
22
*/
39
cluster size: 64 KiB
23
switch (qcow2_get_cluster_type(old_l2_entry)) {
40
vm state offset: 512 MiB
24
- case QCOW2_CLUSTER_UNALLOCATED:
41
-Format specific information:
25
- if (full_discard || !bs->backing) {
42
- compat: 1.1
26
- continue;
43
- lazy refcounts: false
27
- }
44
- refcount bits: 16
28
- break;
45
- corrupt: false
29
+ case QCOW2_CLUSTER_UNALLOCATED:
46
format name: IMGFMT
30
+ if (full_discard || !bs->backing) {
47
cluster size: 64 KiB
31
+ continue;
48
vm state offset: 512 MiB
32
+ }
49
-Format specific information:
33
+ break;
50
- compat: 1.1
34
51
- lazy refcounts: false
35
- case QCOW2_CLUSTER_ZERO:
52
- refcount bits: 16
36
- /* Preallocated zero clusters should be discarded in any case */
53
- corrupt: false
37
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
54
*** done
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
--
55
--
171
1.8.3.1
56
2.13.6
172
57
173
58
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
In order to keep checkpatch happy when the next patch changes
3
184 does not need an image, so don't use one.
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
4
10
While touching things, also fix checkpatch warnings about unusual
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
'for' statements.
6
Message-id: 20171123020832.8165-16-mreitz@redhat.com
12
7
Reviewed-by: John Snow <jsnow@redhat.com>
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>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
9
---
19
block/qcow2-refcount.c | 42 ++++++++++++++++++++++--------------------
10
tests/qemu-iotests/184 | 25 ++++--------------
20
1 file changed, 22 insertions(+), 20 deletions(-)
11
tests/qemu-iotests/184.out | 63 +++++++---------------------------------------
12
2 files changed, 14 insertions(+), 74 deletions(-)
21
13
22
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
14
diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184
15
index XXXXXXX..XXXXXXX 100755
16
--- a/tests/qemu-iotests/184
17
+++ b/tests/qemu-iotests/184
18
@@ -XXX,XX +XXX,XX @@ echo "QA output created by $seq"
19
here=`pwd`
20
status=1    # failure is the default!
21
22
-_cleanup()
23
-{
24
- _cleanup_test_img
25
-}
26
-trap "_cleanup; exit \$status" 0 1 2 3 15
27
+trap "exit \$status" 0 1 2 3 15
28
29
# get standard environment, filters and checks
30
. ./common.rc
31
. ./common.filter
32
33
-_supported_fmt qcow2
34
-_supported_proto file
35
_supported_os Linux
36
37
function do_run_qemu()
38
@@ -XXX,XX +XXX,XX @@ function run_qemu()
39
| _filter_actual_image_size
40
}
41
42
-_make_test_img 64M
43
test_throttle=$($QEMU_IMG --help|grep throttle)
44
[ "$test_throttle" = "" ] && _supported_fmt throttle
45
46
@@ -XXX,XX +XXX,XX @@ run_qemu <<EOF
47
{ "execute": "qmp_capabilities" }
48
{ "execute": "blockdev-add",
49
"arguments": {
50
- "driver": "$IMGFMT",
51
- "node-name": "disk0",
52
- "file": {
53
- "driver": "file",
54
- "filename": "$TEST_IMG"
55
- }
56
+ "driver": "null-co",
57
+ "node-name": "disk0"
58
}
59
}
60
{ "execute": "object-add",
61
@@ -XXX,XX +XXX,XX @@ run_qemu <<EOF
62
{ "execute": "qmp_capabilities" }
63
{ "execute": "blockdev-add",
64
"arguments": {
65
- "driver": "$IMGFMT",
66
- "node-name": "disk0",
67
- "file": {
68
- "driver": "file",
69
- "filename": "$TEST_IMG"
70
- }
71
+ "driver": "null-co",
72
+ "node-name": "disk0"
73
}
74
}
75
{ "execute": "blockdev-add",
76
diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out
23
index XXXXXXX..XXXXXXX 100644
77
index XXXXXXX..XXXXXXX 100644
24
--- a/block/qcow2-refcount.c
78
--- a/tests/qemu-iotests/184.out
25
+++ b/block/qcow2-refcount.c
79
+++ b/tests/qemu-iotests/184.out
26
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
80
@@ -XXX,XX +XXX,XX @@
27
int64_t l1_table_offset, int l1_size, int addend)
81
QA output created by 184
28
{
82
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
29
BDRVQcow2State *s = bs->opaque;
83
30
- uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount;
84
== checking interface ==
31
+ uint64_t *l1_table, *l2_table, l2_offset, entry, l1_size2, refcount;
85
Testing:
32
bool l1_allocated = false;
86
@@ -XXX,XX +XXX,XX @@ Testing:
33
- int64_t old_offset, old_l2_offset;
87
"iops_rd": 0,
34
+ int64_t old_entry, old_l2_offset;
88
"detect_zeroes": "off",
35
int i, j, l1_modified = 0, nb_csectors;
89
"image": {
36
int ret;
90
- "virtual-size": 67108864,
37
91
- "filename": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"qcow2\", \"file\": {\"driver\": \"file\", \"filename\": \"TEST_DIR/t.qcow2\"}}}",
38
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
92
- "cluster-size": 65536,
39
goto fail;
93
- "format": "throttle",
94
- "actual-size": SIZE,
95
- "dirty-flag": false
96
+ "virtual-size": 1073741824,
97
+ "filename": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}",
98
+ "format": "throttle"
99
},
100
"iops_wr": 0,
101
"ro": false,
102
@@ -XXX,XX +XXX,XX @@ Testing:
103
"direct": false,
104
"writeback": true
105
},
106
- "file": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"qcow2\", \"file\": {\"driver\": \"file\", \"filename\": \"TEST_DIR/t.qcow2\"}}}",
107
+ "file": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"null-co\"}}",
108
"encryption_key_missing": false
109
},
110
{
111
"iops_rd": 0,
112
"detect_zeroes": "off",
113
"image": {
114
- "virtual-size": 67108864,
115
- "filename": "TEST_DIR/t.qcow2",
116
- "cluster-size": 65536,
117
- "format": "qcow2",
118
- "actual-size": SIZE,
119
- "format-specific": {
120
- "type": "qcow2",
121
- "data": {
122
- "compat": "1.1",
123
- "lazy-refcounts": false,
124
- "refcount-bits": 16,
125
- "corrupt": false
126
- }
127
- },
128
- "dirty-flag": false
129
+ "virtual-size": 1073741824,
130
+ "filename": "null-co://",
131
+ "format": "null-co"
132
},
133
"iops_wr": 0,
134
"ro": false,
135
"node-name": "disk0",
136
"backing_file_depth": 0,
137
- "drv": "qcow2",
138
+ "drv": "null-co",
139
"iops": 0,
140
"bps_wr": 0,
141
"write_threshold": 0,
142
@@ -XXX,XX +XXX,XX @@ Testing:
143
"direct": false,
144
"writeback": true
145
},
146
- "file": "TEST_DIR/t.qcow2",
147
- "encryption_key_missing": false
148
- },
149
- {
150
- "iops_rd": 0,
151
- "detect_zeroes": "off",
152
- "image": {
153
- "virtual-size": 197120,
154
- "filename": "TEST_DIR/t.qcow2",
155
- "format": "file",
156
- "actual-size": SIZE,
157
- "dirty-flag": false
158
- },
159
- "iops_wr": 0,
160
- "ro": false,
161
- "node-name": "NODE_NAME",
162
- "backing_file_depth": 0,
163
- "drv": "file",
164
- "iops": 0,
165
- "bps_wr": 0,
166
- "write_threshold": 0,
167
- "encrypted": false,
168
- "bps": 0,
169
- "bps_rd": 0,
170
- "cache": {
171
- "no-flush": false,
172
- "direct": false,
173
- "writeback": true
174
- },
175
- "file": "TEST_DIR/t.qcow2",
176
+ "file": "null-co://",
177
"encryption_key_missing": false
40
}
178
}
41
179
]
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
--
180
--
130
1.8.3.1
181
2.13.6
131
182
132
183
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Rather than store into a local variable, then copy to the struct
3
In order for 191 to work with an explicit refcount_bits or compat=0.10,
4
if the value is valid, then reporting errors otherwise, it is
4
we should strip format-specific information from the output--and we can
5
simpler to just store into the struct and report errors if the
5
do so by using _filter_img_info.
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
6
12
Signed-off-by: Eric Blake <eblake@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
Message-id: 20170429191419.30051-8-eblake@redhat.com
8
Message-id: 20171123020832.8165-17-mreitz@redhat.com
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Reviewed-by: John Snow <jsnow@redhat.com>
15
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
---
11
---
17
block/blkdebug.c | 16 ++++++----------
12
tests/qemu-iotests/191 | 5 +-
18
1 file changed, 6 insertions(+), 10 deletions(-)
13
tests/qemu-iotests/191.out | 313 +++++++++++++--------------------------------
14
2 files changed, 91 insertions(+), 227 deletions(-)
19
15
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
16
diff --git a/tests/qemu-iotests/191 b/tests/qemu-iotests/191
17
index XXXXXXX..XXXXXXX 100755
18
--- a/tests/qemu-iotests/191
19
+++ b/tests/qemu-iotests/191
20
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
21
. ./common.qemu
22
23
_supported_fmt qcow2
24
-_unsupported_imgopts compat=0.10
25
_supported_proto file
26
_supported_os Linux
27
28
@@ -XXX,XX +XXX,XX @@ echo === Check that both top and top2 point to base now ===
29
echo
30
31
_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
32
- _filter_generated_node_ids | _filter_actual_image_size
33
+ _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
34
35
_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
36
wait=1 _cleanup_qemu
37
@@ -XXX,XX +XXX,XX @@ echo === Check that both top and top2 point to base now ===
38
echo
39
40
_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
41
- _filter_generated_node_ids | _filter_actual_image_size
42
+ _filter_generated_node_ids | _filter_actual_image_size | _filter_img_info
43
44
_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
45
wait=1 _cleanup_qemu
46
diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out
21
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
48
--- a/tests/qemu-iotests/191.out
23
+++ b/block/blkdebug.c
49
+++ b/tests/qemu-iotests/191.out
24
@@ -XXX,XX +XXX,XX @@
50
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
25
typedef struct BDRVBlkdebugState {
51
"image": {
26
int state;
52
"backing-image": {
27
int new_state;
53
"virtual-size": 67108864,
28
- int align;
54
- "filename": "TEST_DIR/t.qcow2.base",
29
+ uint64_t align;
55
+ "filename": "TEST_DIR/t.IMGFMT.base",
30
56
"cluster-size": 65536,
31
/* For blkdebug_refresh_filename() */
57
- "format": "qcow2",
32
char *config_file;
58
+ "format": "IMGFMT",
33
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
59
"actual-size": SIZE,
34
BDRVBlkdebugState *s = bs->opaque;
60
- "format-specific": {
35
QemuOpts *opts;
61
- "type": "qcow2",
36
Error *local_err = NULL;
62
- "data": {
37
- uint64_t align;
63
- "compat": "1.1",
38
int ret;
64
- "lazy-refcounts": false,
39
65
- "refcount-bits": 16,
40
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
66
- "corrupt": false
41
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
67
- }
42
bs->file->bs->supported_write_flags;
68
- },
43
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
69
"dirty-flag": false
44
bs->file->bs->supported_zero_flags;
70
},
45
+ ret = -EINVAL;
71
- "backing-filename-format": "qcow2",
46
72
+ "backing-filename-format": "IMGFMT",
47
/* Set request alignment */
73
"virtual-size": 67108864,
48
- align = qemu_opt_get_size(opts, "align", 0);
74
- "filename": "TEST_DIR/t.qcow2.ovl2",
49
- if (align < INT_MAX && is_power_of_2(align)) {
75
+ "filename": "TEST_DIR/t.IMGFMT.ovl2",
50
- s->align = align;
76
"cluster-size": 65536,
51
- } else if (align) {
77
- "format": "qcow2",
52
- error_setg(errp, "Invalid alignment");
78
+ "format": "IMGFMT",
53
- ret = -EINVAL;
79
"actual-size": SIZE,
54
+ s->align = qemu_opt_get_size(opts, "align", 0);
80
- "format-specific": {
55
+ if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
81
- "type": "qcow2",
56
+ error_setg(errp, "Cannot meet constraints with align %" PRIu64,
82
- "data": {
57
+ s->align);
83
- "compat": "1.1",
58
goto out;
84
- "lazy-refcounts": false,
59
}
85
- "refcount-bits": 16,
60
86
- "corrupt": false
61
ret = 0;
87
- }
62
- goto out;
88
- },
63
-
89
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
64
out:
90
- "backing-filename": "TEST_DIR/t.qcow2.base",
65
if (ret < 0) {
91
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
66
g_free(s->config_file);
92
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
93
"dirty-flag": false
94
},
95
"iops_wr": 0,
96
"ro": false,
97
"node-name": "top2",
98
"backing_file_depth": 1,
99
- "drv": "qcow2",
100
+ "drv": "IMGFMT",
101
"iops": 0,
102
"bps_wr": 0,
103
"write_threshold": 0,
104
- "backing_file": "TEST_DIR/t.qcow2.base",
105
+ "backing_file": "TEST_DIR/t.IMGFMT.base",
106
"encrypted": false,
107
"bps": 0,
108
"bps_rd": 0,
109
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
110
"direct": false,
111
"writeback": true
112
},
113
- "file": "TEST_DIR/t.qcow2.ovl2",
114
+ "file": "TEST_DIR/t.IMGFMT.ovl2",
115
"encryption_key_missing": false
116
},
117
{
118
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
119
"detect_zeroes": "off",
120
"image": {
121
"virtual-size": 197120,
122
- "filename": "TEST_DIR/t.qcow2.ovl2",
123
+ "filename": "TEST_DIR/t.IMGFMT.ovl2",
124
"format": "file",
125
"actual-size": SIZE,
126
"dirty-flag": false
127
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
128
"direct": false,
129
"writeback": true
130
},
131
- "file": "TEST_DIR/t.qcow2.ovl2",
132
+ "file": "TEST_DIR/t.IMGFMT.ovl2",
133
"encryption_key_missing": false
134
},
135
{
136
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
137
"image": {
138
"backing-image": {
139
"virtual-size": 67108864,
140
- "filename": "TEST_DIR/t.qcow2.base",
141
+ "filename": "TEST_DIR/t.IMGFMT.base",
142
"cluster-size": 65536,
143
- "format": "qcow2",
144
+ "format": "IMGFMT",
145
"actual-size": SIZE,
146
- "format-specific": {
147
- "type": "qcow2",
148
- "data": {
149
- "compat": "1.1",
150
- "lazy-refcounts": false,
151
- "refcount-bits": 16,
152
- "corrupt": false
153
- }
154
- },
155
"dirty-flag": false
156
},
157
- "backing-filename-format": "qcow2",
158
+ "backing-filename-format": "IMGFMT",
159
"virtual-size": 67108864,
160
- "filename": "TEST_DIR/t.qcow2",
161
+ "filename": "TEST_DIR/t.IMGFMT",
162
"cluster-size": 65536,
163
- "format": "qcow2",
164
+ "format": "IMGFMT",
165
"actual-size": SIZE,
166
- "format-specific": {
167
- "type": "qcow2",
168
- "data": {
169
- "compat": "1.1",
170
- "lazy-refcounts": false,
171
- "refcount-bits": 16,
172
- "corrupt": false
173
- }
174
- },
175
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
176
- "backing-filename": "TEST_DIR/t.qcow2.base",
177
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
178
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
179
"dirty-flag": false
180
},
181
"iops_wr": 0,
182
"ro": false,
183
"node-name": "top",
184
"backing_file_depth": 1,
185
- "drv": "qcow2",
186
+ "drv": "IMGFMT",
187
"iops": 0,
188
"bps_wr": 0,
189
"write_threshold": 0,
190
- "backing_file": "TEST_DIR/t.qcow2.base",
191
+ "backing_file": "TEST_DIR/t.IMGFMT.base",
192
"encrypted": false,
193
"bps": 0,
194
"bps_rd": 0,
195
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
196
"direct": false,
197
"writeback": true
198
},
199
- "file": "TEST_DIR/t.qcow2",
200
+ "file": "TEST_DIR/t.IMGFMT",
201
"encryption_key_missing": false
202
},
203
{
204
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
205
"detect_zeroes": "off",
206
"image": {
207
"virtual-size": 197120,
208
- "filename": "TEST_DIR/t.qcow2",
209
+ "filename": "TEST_DIR/t.IMGFMT",
210
"format": "file",
211
"actual-size": SIZE,
212
"dirty-flag": false
213
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
214
"direct": false,
215
"writeback": true
216
},
217
- "file": "TEST_DIR/t.qcow2",
218
+ "file": "TEST_DIR/t.IMGFMT",
219
"encryption_key_missing": false
220
},
221
{
222
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
223
"image": {
224
"backing-image": {
225
"virtual-size": 67108864,
226
- "filename": "TEST_DIR/t.qcow2.base",
227
+ "filename": "TEST_DIR/t.IMGFMT.base",
228
"cluster-size": 65536,
229
- "format": "qcow2",
230
+ "format": "IMGFMT",
231
"actual-size": SIZE,
232
- "format-specific": {
233
- "type": "qcow2",
234
- "data": {
235
- "compat": "1.1",
236
- "lazy-refcounts": false,
237
- "refcount-bits": 16,
238
- "corrupt": false
239
- }
240
- },
241
"dirty-flag": false
242
},
243
- "backing-filename-format": "qcow2",
244
+ "backing-filename-format": "IMGFMT",
245
"virtual-size": 67108864,
246
- "filename": "TEST_DIR/t.qcow2.mid",
247
+ "filename": "TEST_DIR/t.IMGFMT.mid",
248
"cluster-size": 65536,
249
- "format": "qcow2",
250
+ "format": "IMGFMT",
251
"actual-size": SIZE,
252
- "format-specific": {
253
- "type": "qcow2",
254
- "data": {
255
- "compat": "1.1",
256
- "lazy-refcounts": false,
257
- "refcount-bits": 16,
258
- "corrupt": false
259
- }
260
- },
261
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
262
- "backing-filename": "TEST_DIR/t.qcow2.base",
263
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
264
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
265
"dirty-flag": false
266
},
267
"iops_wr": 0,
268
"ro": false,
269
"node-name": "mid",
270
"backing_file_depth": 1,
271
- "drv": "qcow2",
272
+ "drv": "IMGFMT",
273
"iops": 0,
274
"bps_wr": 0,
275
"write_threshold": 0,
276
- "backing_file": "TEST_DIR/t.qcow2.base",
277
+ "backing_file": "TEST_DIR/t.IMGFMT.base",
278
"encrypted": false,
279
"bps": 0,
280
"bps_rd": 0,
281
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
282
"direct": false,
283
"writeback": true
284
},
285
- "file": "TEST_DIR/t.qcow2.mid",
286
+ "file": "TEST_DIR/t.IMGFMT.mid",
287
"encryption_key_missing": false
288
},
289
{
290
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
291
"detect_zeroes": "off",
292
"image": {
293
"virtual-size": 393216,
294
- "filename": "TEST_DIR/t.qcow2.mid",
295
+ "filename": "TEST_DIR/t.IMGFMT.mid",
296
"format": "file",
297
"actual-size": SIZE,
298
"dirty-flag": false
299
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
300
"direct": false,
301
"writeback": true
302
},
303
- "file": "TEST_DIR/t.qcow2.mid",
304
+ "file": "TEST_DIR/t.IMGFMT.mid",
305
"encryption_key_missing": false
306
},
307
{
308
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
309
"detect_zeroes": "off",
310
"image": {
311
"virtual-size": 67108864,
312
- "filename": "TEST_DIR/t.qcow2.base",
313
+ "filename": "TEST_DIR/t.IMGFMT.base",
314
"cluster-size": 65536,
315
- "format": "qcow2",
316
+ "format": "IMGFMT",
317
"actual-size": SIZE,
318
- "format-specific": {
319
- "type": "qcow2",
320
- "data": {
321
- "compat": "1.1",
322
- "lazy-refcounts": false,
323
- "refcount-bits": 16,
324
- "corrupt": false
325
- }
326
- },
327
"dirty-flag": false
328
},
329
"iops_wr": 0,
330
"ro": false,
331
"node-name": "base",
332
"backing_file_depth": 0,
333
- "drv": "qcow2",
334
+ "drv": "IMGFMT",
335
"iops": 0,
336
"bps_wr": 0,
337
"write_threshold": 0,
338
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
339
"direct": false,
340
"writeback": true
341
},
342
- "file": "TEST_DIR/t.qcow2.base",
343
+ "file": "TEST_DIR/t.IMGFMT.base",
344
"encryption_key_missing": false
345
},
346
{
347
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
348
"detect_zeroes": "off",
349
"image": {
350
"virtual-size": 393216,
351
- "filename": "TEST_DIR/t.qcow2.base",
352
+ "filename": "TEST_DIR/t.IMGFMT.base",
353
"format": "file",
354
"actual-size": SIZE,
355
"dirty-flag": false
356
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
357
"direct": false,
358
"writeback": true
359
},
360
- "file": "TEST_DIR/t.qcow2.base",
361
+ "file": "TEST_DIR/t.IMGFMT.base",
362
"encryption_key_missing": false
363
}
364
]
365
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
366
"image": {
367
"backing-image": {
368
"virtual-size": 67108864,
369
- "filename": "TEST_DIR/t.qcow2.base",
370
+ "filename": "TEST_DIR/t.IMGFMT.base",
371
"cluster-size": 65536,
372
- "format": "qcow2",
373
+ "format": "IMGFMT",
374
"actual-size": SIZE,
375
- "format-specific": {
376
- "type": "qcow2",
377
- "data": {
378
- "compat": "1.1",
379
- "lazy-refcounts": false,
380
- "refcount-bits": 16,
381
- "corrupt": false
382
- }
383
- },
384
"dirty-flag": false
385
},
386
- "backing-filename-format": "qcow2",
387
+ "backing-filename-format": "IMGFMT",
388
"virtual-size": 67108864,
389
- "filename": "TEST_DIR/t.qcow2.ovl2",
390
+ "filename": "TEST_DIR/t.IMGFMT.ovl2",
391
"cluster-size": 65536,
392
- "format": "qcow2",
393
+ "format": "IMGFMT",
394
"actual-size": SIZE,
395
- "format-specific": {
396
- "type": "qcow2",
397
- "data": {
398
- "compat": "1.1",
399
- "lazy-refcounts": false,
400
- "refcount-bits": 16,
401
- "corrupt": false
402
- }
403
- },
404
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
405
- "backing-filename": "TEST_DIR/t.qcow2.base",
406
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
407
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
408
"dirty-flag": false
409
},
410
"iops_wr": 0,
411
"ro": true,
412
"node-name": "NODE_NAME",
413
"backing_file_depth": 1,
414
- "drv": "qcow2",
415
+ "drv": "IMGFMT",
416
"iops": 0,
417
"bps_wr": 0,
418
"write_threshold": 0,
419
- "backing_file": "TEST_DIR/t.qcow2.base",
420
+ "backing_file": "TEST_DIR/t.IMGFMT.base",
421
"encrypted": false,
422
"bps": 0,
423
"bps_rd": 0,
424
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
425
"direct": false,
426
"writeback": true
427
},
428
- "file": "TEST_DIR/t.qcow2.ovl2",
429
+ "file": "TEST_DIR/t.IMGFMT.ovl2",
430
"encryption_key_missing": false
431
},
432
{
433
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
434
"detect_zeroes": "off",
435
"image": {
436
"virtual-size": 197120,
437
- "filename": "TEST_DIR/t.qcow2.ovl2",
438
+ "filename": "TEST_DIR/t.IMGFMT.ovl2",
439
"format": "file",
440
"actual-size": SIZE,
441
"dirty-flag": false
442
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
443
"direct": false,
444
"writeback": true
445
},
446
- "file": "TEST_DIR/t.qcow2.ovl2",
447
+ "file": "TEST_DIR/t.IMGFMT.ovl2",
448
"encryption_key_missing": false
449
},
450
{
451
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
452
"backing-image": {
453
"backing-image": {
454
"virtual-size": 67108864,
455
- "filename": "TEST_DIR/t.qcow2.base",
456
+ "filename": "TEST_DIR/t.IMGFMT.base",
457
"cluster-size": 65536,
458
- "format": "qcow2",
459
+ "format": "IMGFMT",
460
"actual-size": SIZE,
461
- "format-specific": {
462
- "type": "qcow2",
463
- "data": {
464
- "compat": "1.1",
465
- "lazy-refcounts": false,
466
- "refcount-bits": 16,
467
- "corrupt": false
468
- }
469
- },
470
"dirty-flag": false
471
},
472
- "backing-filename-format": "qcow2",
473
+ "backing-filename-format": "IMGFMT",
474
"virtual-size": 67108864,
475
- "filename": "TEST_DIR/t.qcow2.ovl2",
476
+ "filename": "TEST_DIR/t.IMGFMT.ovl2",
477
"cluster-size": 65536,
478
- "format": "qcow2",
479
+ "format": "IMGFMT",
480
"actual-size": SIZE,
481
- "format-specific": {
482
- "type": "qcow2",
483
- "data": {
484
- "compat": "1.1",
485
- "lazy-refcounts": false,
486
- "refcount-bits": 16,
487
- "corrupt": false
488
- }
489
- },
490
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
491
- "backing-filename": "TEST_DIR/t.qcow2.base",
492
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
493
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
494
"dirty-flag": false
495
},
496
- "backing-filename-format": "qcow2",
497
+ "backing-filename-format": "IMGFMT",
498
"virtual-size": 67108864,
499
- "filename": "TEST_DIR/t.qcow2.ovl3",
500
+ "filename": "TEST_DIR/t.IMGFMT.ovl3",
501
"cluster-size": 65536,
502
- "format": "qcow2",
503
+ "format": "IMGFMT",
504
"actual-size": SIZE,
505
- "format-specific": {
506
- "type": "qcow2",
507
- "data": {
508
- "compat": "1.1",
509
- "lazy-refcounts": false,
510
- "refcount-bits": 16,
511
- "corrupt": false
512
- }
513
- },
514
- "full-backing-filename": "TEST_DIR/t.qcow2.ovl2",
515
- "backing-filename": "TEST_DIR/t.qcow2.ovl2",
516
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.ovl2",
517
+ "backing-filename": "TEST_DIR/t.IMGFMT.ovl2",
518
"dirty-flag": false
519
},
520
"iops_wr": 0,
521
"ro": false,
522
"node-name": "top2",
523
"backing_file_depth": 2,
524
- "drv": "qcow2",
525
+ "drv": "IMGFMT",
526
"iops": 0,
527
"bps_wr": 0,
528
"write_threshold": 0,
529
- "backing_file": "TEST_DIR/t.qcow2.ovl2",
530
+ "backing_file": "TEST_DIR/t.IMGFMT.ovl2",
531
"encrypted": false,
532
"bps": 0,
533
"bps_rd": 0,
534
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
535
"direct": false,
536
"writeback": true
537
},
538
- "file": "TEST_DIR/t.qcow2.ovl3",
539
+ "file": "TEST_DIR/t.IMGFMT.ovl3",
540
"encryption_key_missing": false
541
},
542
{
543
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
544
"detect_zeroes": "off",
545
"image": {
546
"virtual-size": 197120,
547
- "filename": "TEST_DIR/t.qcow2.ovl3",
548
+ "filename": "TEST_DIR/t.IMGFMT.ovl3",
549
"format": "file",
550
"actual-size": SIZE,
551
"dirty-flag": false
552
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
553
"direct": false,
554
"writeback": true
555
},
556
- "file": "TEST_DIR/t.qcow2.ovl3",
557
+ "file": "TEST_DIR/t.IMGFMT.ovl3",
558
"encryption_key_missing": false
559
},
560
{
561
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
562
"detect_zeroes": "off",
563
"image": {
564
"virtual-size": 67108864,
565
- "filename": "TEST_DIR/t.qcow2.base",
566
+ "filename": "TEST_DIR/t.IMGFMT.base",
567
"cluster-size": 65536,
568
- "format": "qcow2",
569
+ "format": "IMGFMT",
570
"actual-size": SIZE,
571
- "format-specific": {
572
- "type": "qcow2",
573
- "data": {
574
- "compat": "1.1",
575
- "lazy-refcounts": false,
576
- "refcount-bits": 16,
577
- "corrupt": false
578
- }
579
- },
580
"dirty-flag": false
581
},
582
"iops_wr": 0,
583
"ro": true,
584
"node-name": "NODE_NAME",
585
"backing_file_depth": 0,
586
- "drv": "qcow2",
587
+ "drv": "IMGFMT",
588
"iops": 0,
589
"bps_wr": 0,
590
"write_threshold": 0,
591
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
592
"direct": false,
593
"writeback": true
594
},
595
- "file": "TEST_DIR/t.qcow2.base",
596
+ "file": "TEST_DIR/t.IMGFMT.base",
597
"encryption_key_missing": false
598
},
599
{
600
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
601
"detect_zeroes": "off",
602
"image": {
603
"virtual-size": 393216,
604
- "filename": "TEST_DIR/t.qcow2.base",
605
+ "filename": "TEST_DIR/t.IMGFMT.base",
606
"format": "file",
607
"actual-size": SIZE,
608
"dirty-flag": false
609
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
610
"direct": false,
611
"writeback": true
612
},
613
- "file": "TEST_DIR/t.qcow2.base",
614
+ "file": "TEST_DIR/t.IMGFMT.base",
615
"encryption_key_missing": false
616
},
617
{
618
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
619
"image": {
620
"backing-image": {
621
"virtual-size": 67108864,
622
- "filename": "TEST_DIR/t.qcow2.base",
623
+ "filename": "TEST_DIR/t.IMGFMT.base",
624
"cluster-size": 65536,
625
- "format": "qcow2",
626
+ "format": "IMGFMT",
627
"actual-size": SIZE,
628
- "format-specific": {
629
- "type": "qcow2",
630
- "data": {
631
- "compat": "1.1",
632
- "lazy-refcounts": false,
633
- "refcount-bits": 16,
634
- "corrupt": false
635
- }
636
- },
637
"dirty-flag": false
638
},
639
- "backing-filename-format": "qcow2",
640
+ "backing-filename-format": "IMGFMT",
641
"virtual-size": 67108864,
642
- "filename": "TEST_DIR/t.qcow2",
643
+ "filename": "TEST_DIR/t.IMGFMT",
644
"cluster-size": 65536,
645
- "format": "qcow2",
646
+ "format": "IMGFMT",
647
"actual-size": SIZE,
648
- "format-specific": {
649
- "type": "qcow2",
650
- "data": {
651
- "compat": "1.1",
652
- "lazy-refcounts": false,
653
- "refcount-bits": 16,
654
- "corrupt": false
655
- }
656
- },
657
- "full-backing-filename": "TEST_DIR/t.qcow2.base",
658
- "backing-filename": "TEST_DIR/t.qcow2.base",
659
+ "full-backing-filename": "TEST_DIR/t.IMGFMT.base",
660
+ "backing-filename": "TEST_DIR/t.IMGFMT.base",
661
"dirty-flag": false
662
},
663
"iops_wr": 0,
664
"ro": false,
665
"node-name": "top",
666
"backing_file_depth": 1,
667
- "drv": "qcow2",
668
+ "drv": "IMGFMT",
669
"iops": 0,
670
"bps_wr": 0,
671
"write_threshold": 0,
672
- "backing_file": "TEST_DIR/t.qcow2.base",
673
+ "backing_file": "TEST_DIR/t.IMGFMT.base",
674
"encrypted": false,
675
"bps": 0,
676
"bps_rd": 0,
677
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
678
"direct": false,
679
"writeback": true
680
},
681
- "file": "TEST_DIR/t.qcow2",
682
+ "file": "TEST_DIR/t.IMGFMT",
683
"encryption_key_missing": false
684
},
685
{
686
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
687
"detect_zeroes": "off",
688
"image": {
689
"virtual-size": 197120,
690
- "filename": "TEST_DIR/t.qcow2",
691
+ "filename": "TEST_DIR/t.IMGFMT",
692
"format": "file",
693
"actual-size": SIZE,
694
"dirty-flag": false
695
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 1048576
696
"direct": false,
697
"writeback": true
698
},
699
- "file": "TEST_DIR/t.qcow2",
700
+ "file": "TEST_DIR/t.IMGFMT",
701
"encryption_key_missing": false
702
}
703
]
67
--
704
--
68
1.8.3.1
705
2.13.6
69
706
70
707
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
066 was supposed to be a test "for discarding preallocated zero
3
There is a bit of image-specific information which depends on the qcow2
4
clusters", but it did so incompletely: While it did check the image
4
compat level. Filter it so that 198 works with compat=0.10 (and any
5
file's integrity after the operation, it did not confirm that the
5
refcount_bits value).
6
clusters are indeed freed. This patch adds this test.
7
6
8
In addition, new cases for writing to preallocated zero clusters are
7
Note that we cannot simply drop the --format-specific switch because we
9
added.
8
do need the "encrypt" information.
10
9
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Message-id: 20171123020832.8165-18-mreitz@redhat.com
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Reviewed-by: John Snow <jsnow@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
14
---
15
tests/qemu-iotests/066 | 128 ++++++++++++++++++++++++++++++++++++++++++++-
15
tests/qemu-iotests/198 | 6 ++++--
16
tests/qemu-iotests/066.out | 46 ++++++++++++++++
16
tests/qemu-iotests/198.out | 8 --------
17
2 files changed, 173 insertions(+), 1 deletion(-)
17
2 files changed, 4 insertions(+), 10 deletions(-)
18
18
19
diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066
19
diff --git a/tests/qemu-iotests/198 b/tests/qemu-iotests/198
20
index XXXXXXX..XXXXXXX 100755
20
index XXXXXXX..XXXXXXX 100755
21
--- a/tests/qemu-iotests/066
21
--- a/tests/qemu-iotests/198
22
+++ b/tests/qemu-iotests/066
22
+++ b/tests/qemu-iotests/198
23
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ $QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0x9 0 $size" --image-op
24
#!/bin/bash
24
echo
25
#
25
echo "== checking image base =="
26
-# Test case for discarding preallocated zero clusters in qcow2
26
$QEMU_IMG info --image-opts $IMGSPECBASE | _filter_img_info --format-specific \
27
+# Test case for preallocated zero clusters in qcow2
27
- | sed -e "/^disk size:/ D"
28
#
28
+ | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \
29
# Copyright (C) 2013 Red Hat, Inc.
29
+ -e '/lazy refcounts:/ D' -e '/corrupt:/ D'
30
#
30
31
@@ -XXX,XX +XXX,XX @@ _make_test_img $IMG_SIZE
31
echo
32
$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \
32
echo "== checking image layer =="
33
     -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \
33
$QEMU_IMG info --image-opts $IMGSPECLAYER | _filter_img_info --format-specific \
34
| _filter_qemu_io
34
- | sed -e "/^disk size:/ D"
35
+
35
+ | sed -e "/^disk size:/ D" -e '/refcount bits:/ D' -e '/compat:/ D' \
36
# Check the image (there shouldn't be any leaks)
36
+ -e '/lazy refcounts:/ D' -e '/corrupt:/ D'
37
_check_test_img
37
38
+# Map the image (we want all clusters to be gone)
39
+$QEMU_IMG map "$TEST_IMG"
40
+
41
+_cleanup_test_img
42
+
43
+
44
+echo
45
+echo '=== Writing to preallocated zero clusters ==='
46
+echo
47
+
48
+_make_test_img $IMG_SIZE
49
+
50
+# Create data clusters (not aligned to an L2 table)
51
+$QEMU_IO -c 'write -P 42 1M 256k' "$TEST_IMG" | _filter_qemu_io
52
+orig_map=$($QEMU_IMG map --output=json "$TEST_IMG")
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
38
164
# success, all done
39
# success, all done
165
echo "*** done"
40
diff --git a/tests/qemu-iotests/198.out b/tests/qemu-iotests/198.out
166
diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out
167
index XXXXXXX..XXXXXXX 100644
41
index XXXXXXX..XXXXXXX 100644
168
--- a/tests/qemu-iotests/066.out
42
--- a/tests/qemu-iotests/198.out
169
+++ b/tests/qemu-iotests/066.out
43
+++ b/tests/qemu-iotests/198.out
170
@@ -XXX,XX +XXX,XX @@ discard 67109376/67109376 bytes at offset 0
44
@@ -XXX,XX +XXX,XX @@ image: json:{"encrypt.key-secret": "sec0", "driver": "IMGFMT", "file": {"driver"
171
read 67109376/67109376 bytes at offset 0
45
file format: IMGFMT
172
64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
46
virtual size: 16M (16777216 bytes)
173
No errors were found on the image.
47
Format specific information:
174
+Offset Length Mapped to File
48
- compat: 1.1
175
+
49
- lazy refcounts: false
176
+=== Writing to preallocated zero clusters ===
50
- refcount bits: 16
177
+
51
encrypt:
178
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376
52
ivgen alg: plain64
179
+wrote 262144/262144 bytes at offset 1048576
53
hash alg: sha256
180
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
54
@@ -XXX,XX +XXX,XX @@ Format specific information:
181
+wrote 262144/262144 bytes at offset 1048576
55
key offset: 1810432
182
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
56
payload offset: 2068480
183
+wrote 196608/196608 bytes at offset 1081344
57
master key iters: 1024
184
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
58
- corrupt: false
185
+No errors were found on the image.
59
186
+read 32768/32768 bytes at offset 1048576
60
== checking image layer ==
187
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
61
image: json:{"encrypt.key-secret": "sec1", "driver": "IMGFMT", "file": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}}
188
+read 196608/196608 bytes at offset 1081344
62
@@ -XXX,XX +XXX,XX @@ file format: IMGFMT
189
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
63
virtual size: 16M (16777216 bytes)
190
+read 32768/32768 bytes at offset 1277952
64
backing file: TEST_DIR/t.IMGFMT.base
191
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
65
Format specific information:
192
+Successfully reused original clusters.
66
- compat: 1.1
193
+
67
- lazy refcounts: false
194
+=== Writing to a snapshotted preallocated zero cluster ===
68
- refcount bits: 16
195
+
69
encrypt:
196
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
70
ivgen alg: plain64
197
+wrote 65536/65536 bytes at offset 0
71
hash alg: sha256
198
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
72
@@ -XXX,XX +XXX,XX @@ Format specific information:
199
+wrote 65536/65536 bytes at offset 0
73
key offset: 1810432
200
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
74
payload offset: 2068480
201
+wrote 65536/65536 bytes at offset 0
75
master key iters: 1024
202
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
76
- corrupt: false
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
77
*** done
221
--
78
--
222
1.8.3.1
79
2.13.6
223
80
224
81
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
In discard_single_l2(), we completely discard normal clusters instead of
3
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
simply turning them into preallocated zero clusters. That means we
4
Message-id: 20171129192411.6637-1-mreitz@redhat.com
5
should probably do the same with such preallocated zero clusters:
5
Reviewed-by: John Snow <jsnow@redhat.com>
6
Discard them instead of keeping them allocated.
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
---
8
tests/qemu-iotests/059 | 4 +++-
9
1 file changed, 3 insertions(+), 1 deletion(-)
7
10
8
Reported-by: Eric Blake <eblake@redhat.com>
11
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
index XXXXXXX..XXXXXXX 100755
10
Reviewed-by: Eric Blake <eblake@redhat.com>
13
--- a/tests/qemu-iotests/059
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
+++ b/tests/qemu-iotests/059
12
---
15
@@ -XXX,XX +XXX,XX @@ done
13
block/qcow2-cluster.c | 3 ++-
16
echo
14
1 file changed, 2 insertions(+), 1 deletion(-)
17
echo "=== Testing afl image with a very large capacity ==="
15
18
_use_sample_img afl9.vmdk.bz2
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
19
-_img_info
17
index XXXXXXX..XXXXXXX 100644
20
+# The sed makes this test pass on machines with little RAM
18
--- a/block/qcow2-cluster.c
21
+# (and also with 32 bit builds)
19
+++ b/block/qcow2-cluster.c
22
+_img_info | sed -e 's/Cannot allocate memory/Invalid argument/'
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
23
_cleanup_test_img
21
break;
24
22
25
# success, all done
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
--
26
--
31
1.8.3.1
27
2.13.6
32
28
33
29
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Eric Blake <eblake@redhat.com>
2
2
3
Use blkdebug's new geometry constraints to emulate setups that
3
When originally written, test 177 explicitly took care to run
4
have needed past regression fixes: write zeroes asserting
4
with compat=0.10. Then I botched my own test in commit
5
when running through a loopback block device with max-transfer
5
81c219ac and f0a9c18f, by adding additional actions that require
6
smaller than cluster size, and discard rounding away portions
6
v3 images. Split out the new code into a new v3-only test, 204,
7
of requests not aligned to preferred boundaries. Also, add
7
and revert 177 back to its original state other than a new comment.
8
coverage that the block layer is honoring max transfer limits.
8
9
9
Reported-by: Max Reitz <mreitz@redhat.com>
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>
10
Signed-off-by: Eric Blake <eblake@redhat.com>
37
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Message-id: 20180117165420.15946-2-eblake@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>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
42
---
13
---
43
tests/qemu-iotests/177 | 114 +++++++++++++++++++++++++++++++++++++++++++++
14
tests/qemu-iotests/177 | 20 +++-----
44
tests/qemu-iotests/177.out | 49 +++++++++++++++++++
15
tests/qemu-iotests/177.out | 22 ++-------
16
tests/qemu-iotests/204 | 119 +++++++++++++++++++++++++++++++++++++++++++++
17
tests/qemu-iotests/204.out | 63 ++++++++++++++++++++++++
45
tests/qemu-iotests/group | 1 +
18
tests/qemu-iotests/group | 1 +
46
3 files changed, 164 insertions(+)
19
5 files changed, 193 insertions(+), 32 deletions(-)
47
create mode 100755 tests/qemu-iotests/177
20
create mode 100755 tests/qemu-iotests/204
48
create mode 100644 tests/qemu-iotests/177.out
21
create mode 100644 tests/qemu-iotests/204.out
49
22
50
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
23
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
24
index XXXXXXX..XXXXXXX 100755
25
--- a/tests/qemu-iotests/177
26
+++ b/tests/qemu-iotests/177
27
@@ -XXX,XX +XXX,XX @@
28
#
29
# Test corner cases with unusual block geometries
30
#
31
-# Copyright (C) 2016-2017 Red Hat, Inc.
32
+# Copyright (C) 2016-2018 Red Hat, Inc.
33
#
34
# This program is free software; you can redistribute it and/or modify
35
# it under the terms of the GNU General Public License as published by
36
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
37
. ./common.rc
38
. ./common.filter
39
40
+# This test is runnable under compat=0.10; see test 204 for additional
41
+# tests specific to compat=1.1.
42
+
43
_supported_fmt qcow2
44
_supported_proto file
45
46
CLUSTER_SIZE=1M
47
size=128M
48
options=driver=blkdebug,image.driver=qcow2
49
-nested_opts=image.file.driver=file,image.file.filename=$TEST_IMG
50
51
echo
52
echo "== setting up files =="
53
@@ -XXX,XX +XXX,XX @@ echo "== setting up files =="
54
TEST_IMG="$TEST_IMG.base" _make_test_img $size
55
$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
56
_make_test_img -b "$TEST_IMG.base"
57
-$QEMU_IO -c "write -P 22 0 110M" "$TEST_IMG" | _filter_qemu_io
58
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
59
60
# Limited to 64k max-transfer
61
echo
62
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
63
-c "discard 80000001 30M" | _filter_qemu_io
64
65
echo
66
-echo "== block status smaller than alignment =="
67
-limits=align=4k
68
-$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
69
-     -c "alloc 1 1" -c "alloc 0x6dffff0 1000" -c "alloc 127m 5P" \
70
-     -c map | _filter_qemu_io
71
-
72
-echo
73
echo "== verify image content =="
74
75
function verify_io()
76
@@ -XXX,XX +XXX,XX @@ function verify_io()
77
echo read -P 0 32M 32M
78
echo read -P 22 64M 13M
79
echo read -P $discarded 77M 29M
80
- echo read -P 22 106M 4M
81
- echo read -P 11 110M 18M
82
+ echo read -P 22 106M 22M
83
}
84
85
verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
86
-$QEMU_IMG map --image-opts "$options,$nested_opts,align=4k" \
87
- | _filter_qemu_img_map
88
89
_check_test_img
90
91
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
92
index XXXXXXX..XXXXXXX 100644
93
--- a/tests/qemu-iotests/177.out
94
+++ b/tests/qemu-iotests/177.out
95
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
96
wrote 134217728/134217728 bytes at offset 0
97
128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
98
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
99
-wrote 115343360/115343360 bytes at offset 0
100
-110 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
101
+wrote 134217728/134217728 bytes at offset 0
102
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
103
104
== constrained alignment and max-transfer ==
105
wrote 131072/131072 bytes at offset 1000
106
@@ -XXX,XX +XXX,XX @@ wrote 33554432/33554432 bytes at offset 33554432
107
discard 31457280/31457280 bytes at offset 80000001
108
30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
109
110
-== block status smaller than alignment ==
111
-1/1 bytes allocated at offset 1 bytes
112
-16/1000 bytes allocated at offset 110 MiB
113
-0/1048576 bytes allocated at offset 127 MiB
114
-110 MiB (0x6e00000) bytes allocated at offset 0 bytes (0x0)
115
-18 MiB (0x1200000) bytes not allocated at offset 110 MiB (0x6e00000)
116
-
117
== verify image content ==
118
read 1000/1000 bytes at offset 0
119
1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
120
@@ -XXX,XX +XXX,XX @@ read 13631488/13631488 bytes at offset 67108864
121
13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
122
read 30408704/30408704 bytes at offset 80740352
123
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
124
-read 4194304/4194304 bytes at offset 111149056
125
-4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
126
-read 18874368/18874368 bytes at offset 115343360
127
-18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
128
-Offset Length File
129
-0 0x800000 TEST_DIR/t.IMGFMT
130
-0x900000 0x2400000 TEST_DIR/t.IMGFMT
131
-0x3c00000 0x1100000 TEST_DIR/t.IMGFMT
132
-0x6a00000 0x400000 TEST_DIR/t.IMGFMT
133
+read 23068672/23068672 bytes at offset 111149056
134
+22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
135
No errors were found on the image.
136
*** done
137
diff --git a/tests/qemu-iotests/204 b/tests/qemu-iotests/204
51
new file mode 100755
138
new file mode 100755
52
index XXXXXXX..XXXXXXX
139
index XXXXXXX..XXXXXXX
53
--- /dev/null
140
--- /dev/null
54
+++ b/tests/qemu-iotests/177
141
+++ b/tests/qemu-iotests/204
55
@@ -XXX,XX +XXX,XX @@
142
@@ -XXX,XX +XXX,XX @@
56
+#!/bin/bash
143
+#!/bin/bash
57
+#
144
+#
58
+# Test corner cases with unusual block geometries
145
+# Test corner cases with unusual block geometries
59
+#
146
+#
60
+# Copyright (C) 2016-2017 Red Hat, Inc.
147
+# Copyright (C) 2016-2018 Red Hat, Inc.
61
+#
148
+#
62
+# This program is free software; you can redistribute it and/or modify
149
+# 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
150
+# 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
151
+# the Free Software Foundation; either version 2 of the License, or
65
+# (at your option) any later version.
152
+# (at your option) any later version.
...
...
92
+. ./common.rc
179
+. ./common.rc
93
+. ./common.filter
180
+. ./common.filter
94
+
181
+
95
+_supported_fmt qcow2
182
+_supported_fmt qcow2
96
+_supported_proto file
183
+_supported_proto file
184
+# This test assumes that discard leaves zero clusters; see test 177 for
185
+# other tests that also work in older images
186
+_unsupported_imgopts 'compat=0.10'
97
+
187
+
98
+CLUSTER_SIZE=1M
188
+CLUSTER_SIZE=1M
99
+size=128M
189
+size=128M
100
+options=driver=blkdebug,image.driver=qcow2
190
+options=driver=blkdebug,image.driver=qcow2
191
+nested_opts=image.file.driver=file,image.file.filename=$TEST_IMG
101
+
192
+
102
+echo
193
+echo
103
+echo "== setting up files =="
194
+echo "== setting up files =="
104
+
195
+
105
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
196
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
106
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
197
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
107
+_make_test_img -b "$TEST_IMG.base"
198
+_make_test_img -b "$TEST_IMG.base"
108
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
199
+$QEMU_IO -c "write -P 22 0 110M" "$TEST_IMG" | _filter_qemu_io
109
+
200
+
110
+# Limited to 64k max-transfer
201
+# Limited to 64k max-transfer
111
+echo
202
+echo
112
+echo "== constrained alignment and max-transfer =="
203
+echo "== constrained alignment and max-transfer =="
113
+limits=align=4k,max-transfer=64k
204
+limits=align=4k,max-transfer=64k
...
...
134
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
225
+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" \
226
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
136
+ -c "discard 80000001 30M" | _filter_qemu_io
227
+ -c "discard 80000001 30M" | _filter_qemu_io
137
+
228
+
138
+echo
229
+echo
230
+echo "== block status smaller than alignment =="
231
+limits=align=4k
232
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
233
+     -c "alloc 1 1" -c "alloc 0x6dffff0 1000" -c "alloc 127m 5P" \
234
+     -c map | _filter_qemu_io
235
+
236
+echo
139
+echo "== verify image content =="
237
+echo "== verify image content =="
140
+
238
+
141
+function verify_io()
239
+function verify_io()
142
+{
240
+{
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
241
+ echo read -P 22 0 1000
153
+ echo read -P 33 1000 128k
242
+ echo read -P 33 1000 128k
154
+ echo read -P 22 132072 7871512
243
+ echo read -P 22 132072 7871512
155
+ echo read -P 0 8003584 2093056
244
+ echo read -P 0 8003584 2093056
156
+ echo read -P 22 10096640 23457792
245
+ echo read -P 22 10096640 23457792
157
+ echo read -P 0 32M 32M
246
+ echo read -P 0 32M 32M
158
+ echo read -P 22 64M 13M
247
+ echo read -P 22 64M 13M
159
+ echo read -P $discarded 77M 29M
248
+ echo read -P 0 77M 29M
160
+ echo read -P 22 106M 22M
249
+ echo read -P 22 106M 4M
250
+ echo read -P 11 110M 18M
161
+}
251
+}
162
+
252
+
163
+verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
253
+verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
254
+$QEMU_IMG map --image-opts "$options,$nested_opts,align=4k" \
255
+ | _filter_qemu_img_map
164
+
256
+
165
+_check_test_img
257
+_check_test_img
166
+
258
+
167
+# success, all done
259
+# success, all done
168
+echo "*** done"
260
+echo "*** done"
169
+status=0
261
+status=0
170
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
262
diff --git a/tests/qemu-iotests/204.out b/tests/qemu-iotests/204.out
171
new file mode 100644
263
new file mode 100644
172
index XXXXXXX..XXXXXXX
264
index XXXXXXX..XXXXXXX
173
--- /dev/null
265
--- /dev/null
174
+++ b/tests/qemu-iotests/177.out
266
+++ b/tests/qemu-iotests/204.out
175
@@ -XXX,XX +XXX,XX @@
267
@@ -XXX,XX +XXX,XX @@
176
+QA output created by 177
268
+QA output created by 204
177
+
269
+
178
+== setting up files ==
270
+== setting up files ==
179
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
271
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
180
+wrote 134217728/134217728 bytes at offset 0
272
+wrote 134217728/134217728 bytes at offset 0
181
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
273
+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
274
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 134217728/134217728 bytes at offset 0
275
+wrote 115343360/115343360 bytes at offset 0
184
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
276
+110 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+
277
+
186
+== constrained alignment and max-transfer ==
278
+== constrained alignment and max-transfer ==
187
+wrote 131072/131072 bytes at offset 1000
279
+wrote 131072/131072 bytes at offset 1000
188
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
280
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
189
+read 131072/131072 bytes at offset 1000
281
+read 131072/131072 bytes at offset 1000
...
...
198
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
290
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+
291
+
200
+== non-power-of-2 discard limits ==
292
+== non-power-of-2 discard limits ==
201
+discard 31457280/31457280 bytes at offset 80000001
293
+discard 31457280/31457280 bytes at offset 80000001
202
+30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
294
+30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+
296
+== block status smaller than alignment ==
297
+1/1 bytes allocated at offset 1 bytes
298
+16/1000 bytes allocated at offset 110 MiB
299
+0/1048576 bytes allocated at offset 127 MiB
300
+110 MiB (0x6e00000) bytes allocated at offset 0 bytes (0x0)
301
+18 MiB (0x1200000) bytes not allocated at offset 110 MiB (0x6e00000)
203
+
302
+
204
+== verify image content ==
303
+== verify image content ==
205
+read 1000/1000 bytes at offset 0
304
+read 1000/1000 bytes at offset 0
206
+1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
305
+1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
207
+read 131072/131072 bytes at offset 1000
306
+read 131072/131072 bytes at offset 1000
...
...
216
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
315
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
217
+read 13631488/13631488 bytes at offset 67108864
316
+read 13631488/13631488 bytes at offset 67108864
218
+13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
317
+13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
219
+read 30408704/30408704 bytes at offset 80740352
318
+read 30408704/30408704 bytes at offset 80740352
220
+29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
319
+29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
221
+read 23068672/23068672 bytes at offset 111149056
320
+read 4194304/4194304 bytes at offset 111149056
222
+22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
321
+4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
322
+read 18874368/18874368 bytes at offset 115343360
323
+18 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
324
+Offset Length File
325
+0 0x800000 TEST_DIR/t.IMGFMT
326
+0x900000 0x2400000 TEST_DIR/t.IMGFMT
327
+0x3c00000 0x1100000 TEST_DIR/t.IMGFMT
328
+0x6a00000 0x400000 TEST_DIR/t.IMGFMT
223
+No errors were found on the image.
329
+No errors were found on the image.
224
+*** done
330
+*** done
225
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
331
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
226
index XXXXXXX..XXXXXXX 100644
332
index XXXXXXX..XXXXXXX 100644
227
--- a/tests/qemu-iotests/group
333
--- a/tests/qemu-iotests/group
228
+++ b/tests/qemu-iotests/group
334
+++ b/tests/qemu-iotests/group
229
@@ -XXX,XX +XXX,XX @@
335
@@ -XXX,XX +XXX,XX @@
230
174 auto
336
201 rw auto migration
231
175 auto quick
337
202 rw auto quick
232
176 rw auto backing
338
203 rw auto
233
+177 rw auto quick
339
+204 rw auto quick
234
181 rw auto migration
235
182 rw auto quick
236
--
340
--
237
1.8.3.1
341
2.13.6
238
342
239
343
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Max Reitz <mreitz@redhat.com>
2
2
3
Instead of just freeing preallocated zero clusters and completely
3
Tests 080, 130, 137, and 176 simply do not work with compat=0.10 for the
4
allocating them from scratch, reuse them.
4
reasons stated there.
5
5
6
We cannot do this in handle_copied(), however, since this is a COW
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
operation. Therefore, we have to add the new logic to handle_alloc() and
7
Message-Id: <20171123020832.8165-10-mreitz@redhat.com>
8
simply return the existing offset if it exists. The only catch is that
8
[eblake: fix 177 in a separate commit]
9
we have to convince qcow2_alloc_cluster_link_l2() not to free the old
9
Signed-off-by: Eric Blake <eblake@redhat.com>
10
clusters (because we have reused them).
10
Message-id: 20180117165420.15946-3-eblake@redhat.com
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
tests/qemu-iotests/080 | 5 +++--
14
tests/qemu-iotests/130 | 2 ++
15
tests/qemu-iotests/137 | 2 ++
16
tests/qemu-iotests/176 | 2 ++
17
4 files changed, 9 insertions(+), 2 deletions(-)
11
18
12
Reported-by: Eric Blake <eblake@redhat.com>
19
diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
20
index XXXXXXX..XXXXXXX 100755
14
Reviewed-by: Eric Blake <eblake@redhat.com>
21
--- a/tests/qemu-iotests/080
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22
+++ b/tests/qemu-iotests/080
16
---
23
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
17
block/qcow2-cluster.c | 80 +++++++++++++++++++++++++++++++++++----------------
24
_supported_fmt qcow2
18
block/qcow2.h | 3 ++
25
_supported_proto file
19
2 files changed, 59 insertions(+), 24 deletions(-)
26
_supported_os Linux
20
27
-# Internal snapshots are (currently) impossible with refcount_bits=1
21
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
28
-_unsupported_imgopts 'refcount_bits=1[^0-9]'
22
index XXXXXXX..XXXXXXX 100644
29
+# - Internal snapshots are (currently) impossible with refcount_bits=1
23
--- a/block/qcow2-cluster.c
30
+# - This is generally a test for compat=1.1 images
24
+++ b/block/qcow2-cluster.c
31
+_unsupported_imgopts 'refcount_bits=1[^0-9]' 'compat=0.10'
25
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
32
26
uint64_t *l2_table, uint64_t stop_flags)
33
header_size=104
34
35
diff --git a/tests/qemu-iotests/130 b/tests/qemu-iotests/130
36
index XXXXXXX..XXXXXXX 100755
37
--- a/tests/qemu-iotests/130
38
+++ b/tests/qemu-iotests/130
39
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow2
40
_supported_proto generic
41
_unsupported_proto vxhs
42
_supported_os Linux
43
+# We are going to use lazy-refcounts
44
+_unsupported_imgopts 'compat=0.10'
45
46
qemu_comm_method="monitor"
47
48
diff --git a/tests/qemu-iotests/137 b/tests/qemu-iotests/137
49
index XXXXXXX..XXXXXXX 100755
50
--- a/tests/qemu-iotests/137
51
+++ b/tests/qemu-iotests/137
52
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
53
_supported_fmt qcow2
54
_supported_proto file
55
_supported_os Linux
56
+# We are going to use lazy-refcounts
57
+_unsupported_imgopts 'compat=0.10'
58
59
60
_make_test_img 64M
61
diff --git a/tests/qemu-iotests/176 b/tests/qemu-iotests/176
62
index XXXXXXX..XXXXXXX 100755
63
--- a/tests/qemu-iotests/176
64
+++ b/tests/qemu-iotests/176
65
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
66
_supported_fmt qcow2
67
_supported_proto file
68
_supported_os Linux
69
+# Persistent dirty bitmaps require compat=1.1
70
+_unsupported_imgopts 'compat=0.10'
71
72
function run_qemu()
27
{
73
{
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
153
index XXXXXXX..XXXXXXX 100644
154
--- a/block/qcow2.h
155
+++ b/block/qcow2.h
156
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
157
/** Number of newly allocated clusters */
158
int nb_clusters;
159
160
+ /** Do not free the old clusters */
161
+ bool keep_old_clusters;
162
+
163
/**
164
* Requests that overlap with this allocation and wait to be restarted
165
* when the allocating request has completed.
166
--
74
--
167
1.8.3.1
75
2.13.6
168
76
169
77
diff view generated by jsdifflib
Deleted patch
1
Migration code activates all block driver nodes on the destination when
2
the migration completes. It does so by calling
3
bdrv_invalidate_cache_all() and blk_resume_after_migration(). There is
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
1
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
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
---
14
migration/migration.c | 16 +++++-----------
15
migration/savevm.c | 12 +++++-------
16
qmp.c | 18 +++++++++---------
17
3 files changed, 19 insertions(+), 27 deletions(-)
18
19
diff --git a/migration/migration.c b/migration/migration.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/migration/migration.c
22
+++ b/migration/migration.c
23
@@ -XXX,XX +XXX,XX @@ static void process_incoming_migration_bh(void *opaque)
24
Error *local_err = NULL;
25
MigrationIncomingState *mis = opaque;
26
27
- /* Make sure all file formats flush their mutable metadata */
28
+ /* Make sure all file formats flush their mutable metadata.
29
+ * If we get an error here, just don't restart the VM yet. */
30
bdrv_invalidate_cache_all(&local_err);
31
- if (local_err) {
32
- migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
33
- MIGRATION_STATUS_FAILED);
34
- error_report_err(local_err);
35
- migrate_decompress_threads_join();
36
- exit(EXIT_FAILURE);
37
+ if (!local_err) {
38
+ blk_resume_after_migration(&local_err);
39
}
40
-
41
- /* If we get an error here, just don't restart the VM yet. */
42
- blk_resume_after_migration(&local_err);
43
if (local_err) {
44
- error_free(local_err);
45
+ error_report_err(local_err);
46
local_err = NULL;
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
--
105
1.8.3.1
106
107
diff view generated by jsdifflib
Deleted patch
1
Instead of manually calling blk_resume_after_migration() in migration
2
code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend
3
activation with cache invalidation into a single function. This is
4
achieved with a new callback in BdrvChildRole that is called by
5
bdrv_invalidate_cache_all().
6
1
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
---
10
block.c | 12 +++++++++-
11
block/block-backend.c | 56 +++++++++++++++++++++++------------------------
12
include/block/block.h | 2 --
13
include/block/block_int.h | 5 +++++
14
migration/migration.c | 3 ---
15
migration/savevm.c | 3 ---
16
qmp.c | 6 -----
17
7 files changed, 44 insertions(+), 43 deletions(-)
18
19
diff --git a/block.c b/block.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
22
+++ b/block.c
23
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
24
25
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
26
{
27
- BdrvChild *child;
28
+ BdrvChild *child, *parent;
29
Error *local_err = NULL;
30
int ret;
31
32
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
33
error_setg_errno(errp, -ret, "Could not refresh total sector count");
34
return;
35
}
36
+
37
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
38
+ if (parent->role->activate) {
39
+ parent->role->activate(parent, &local_err);
40
+ if (local_err) {
41
+ error_propagate(errp, local_err);
42
+ return;
43
+ }
44
+ }
45
+ }
46
}
47
48
void bdrv_invalidate_cache_all(Error **errp)
49
diff --git a/block/block-backend.c b/block/block-backend.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/block/block-backend.c
52
+++ b/block/block-backend.c
53
@@ -XXX,XX +XXX,XX @@ static const char *blk_root_get_name(BdrvChild *child)
54
return blk_name(child->opaque);
55
}
56
57
+/*
58
+ * Notifies the user of the BlockBackend that migration has completed. qdev
59
+ * devices can tighten their permissions in response (specifically revoke
60
+ * shared write permissions that we needed for storage migration).
61
+ *
62
+ * If an error is returned, the VM cannot be allowed to be resumed.
63
+ */
64
+static void blk_root_activate(BdrvChild *child, Error **errp)
65
+{
66
+ BlockBackend *blk = child->opaque;
67
+ Error *local_err = NULL;
68
+
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) {
171
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 {
204
--
205
1.8.3.1
206
207
diff view generated by jsdifflib
Deleted patch
1
With image locking, permissions affect other qemu processes as well. We
2
want to be sure that the destination can run, so let's drop permissions
3
on the source when migration completes.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
8
block.c | 12 +++++++++++-
9
block/block-backend.c | 25 +++++++++++++++++++++++++
10
include/block/block_int.h | 7 ++++---
11
3 files changed, 40 insertions(+), 4 deletions(-)
12
13
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block.c
16
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache_all(Error **errp)
18
static int bdrv_inactivate_recurse(BlockDriverState *bs,
19
bool setting_flag)
20
{
21
- BdrvChild *child;
22
+ BdrvChild *child, *parent;
23
int ret;
24
25
if (!setting_flag && bs->drv->bdrv_inactivate) {
26
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
27
28
if (setting_flag) {
29
bs->open_flags |= BDRV_O_INACTIVE;
30
+
31
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
32
+ if (parent->role->inactivate) {
33
+ ret = parent->role->inactivate(parent);
34
+ if (ret < 0) {
35
+ bs->open_flags &= ~BDRV_O_INACTIVE;
36
+ return ret;
37
+ }
38
+ }
39
+ }
40
}
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
+{
53
+ BlockBackend *blk = child->opaque;
54
+
55
+ if (blk->disable_perm) {
56
+ return 0;
57
+ }
58
+
59
+ /* Only inactivate BlockBackends for guest devices (which are inactive at
60
+ * this point because the VM is stopped) and unattached monitor-owned
61
+ * BlockBackends. If there is still any other user like a block job, then
62
+ * we simply can't inactivate the image. */
63
+ if (!blk->dev && !blk->name[0]) {
64
+ return -EPERM;
65
+ }
66
+
67
+ blk->disable_perm = true;
68
+ if (blk->root) {
69
+ bdrv_child_try_set_perm(blk->root, 0, BLK_PERM_ALL, &error_abort);
70
+ }
71
+
72
+ return 0;
73
+}
74
+
75
static const BdrvChildRole child_root = {
76
.inherit_options = blk_root_inherit_options,
77
78
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
79
.drained_end = blk_root_drained_end,
80
81
.activate = blk_root_activate,
82
+ .inactivate = blk_root_inactivate,
83
};
84
85
/*
86
diff --git a/include/block/block_int.h b/include/block/block_int.h
87
index XXXXXXX..XXXXXXX 100644
88
--- a/include/block/block_int.h
89
+++ b/include/block/block_int.h
90
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
91
void (*drained_begin)(BdrvChild *child);
92
void (*drained_end)(BdrvChild *child);
93
94
- /* Notifies the parent that the child has been activated (e.g. when
95
- * migration is completing) and it can start requesting permissions and
96
- * doing I/O on it. */
97
+ /* Notifies the parent that the child has been activated/inactivated (e.g.
98
+ * when migration is completing) and it can start/stop requesting
99
+ * permissions and doing I/O on it. */
100
void (*activate)(BdrvChild *child, Error **errp);
101
+ int (*inactivate)(BdrvChild *child);
102
103
void (*attach)(BdrvChild *child);
104
void (*detach)(BdrvChild *child);
105
--
106
1.8.3.1
107
108
diff view generated by jsdifflib
Deleted patch
1
The proper order for inactivating block nodes is that first the parents
2
get inactivated and then the children. If we do things in this order, we
3
can assert that we didn't accidentally leave a parent activated when one
4
of its child nodes is inactive.
5
1
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
---
9
block.c | 25 ++++++++++++++++++-------
10
1 file changed, 18 insertions(+), 7 deletions(-)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child)
17
bdrv_drained_end(bs);
18
}
19
20
+static int bdrv_child_cb_inactivate(BdrvChild *child)
21
+{
22
+ BlockDriverState *bs = child->opaque;
23
+ assert(bs->open_flags & BDRV_O_INACTIVE);
24
+ return 0;
25
+}
26
+
27
/*
28
* Returns the options and flags that a temporary snapshot should get, based on
29
* the originally requested flags (the originally requested image will have
30
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = {
31
.inherit_options = bdrv_inherited_options,
32
.drained_begin = bdrv_child_cb_drained_begin,
33
.drained_end = bdrv_child_cb_drained_end,
34
+ .inactivate = bdrv_child_cb_inactivate,
35
};
36
37
/*
38
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = {
39
.inherit_options = bdrv_inherited_fmt_options,
40
.drained_begin = bdrv_child_cb_drained_begin,
41
.drained_end = bdrv_child_cb_drained_end,
42
+ .inactivate = bdrv_child_cb_inactivate,
43
};
44
45
static void bdrv_backing_attach(BdrvChild *c)
46
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_backing = {
47
.inherit_options = bdrv_backing_options,
48
.drained_begin = bdrv_child_cb_drained_begin,
49
.drained_end = bdrv_child_cb_drained_end,
50
+ .inactivate = bdrv_child_cb_inactivate,
51
};
52
53
static int bdrv_open_flags(BlockDriverState *bs, int flags)
54
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
55
}
56
}
57
58
- QLIST_FOREACH(child, &bs->children, next) {
59
- ret = bdrv_inactivate_recurse(child->bs, setting_flag);
60
- if (ret < 0) {
61
- return ret;
62
- }
63
- }
64
-
65
if (setting_flag) {
66
bs->open_flags |= BDRV_O_INACTIVE;
67
68
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
69
}
70
}
71
}
72
+
73
+ QLIST_FOREACH(child, &bs->children, next) {
74
+ ret = bdrv_inactivate_recurse(child->bs, setting_flag);
75
+ if (ret < 0) {
76
+ return ret;
77
+ }
78
+ }
79
+
80
return 0;
81
}
82
83
--
84
1.8.3.1
85
86
diff view generated by jsdifflib
Deleted patch
1
Format drivers for inactive nodes don't need write/resize permissions on
2
their bs->file and can share write/resize with another VM (in fact, this
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
1
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
---
10
block.c | 35 +++++++++++++++++++++++++++++++++--
11
include/block/block.h | 1 +
12
2 files changed, 34 insertions(+), 2 deletions(-)
13
14
diff --git a/block.c b/block.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
17
+++ b/block.c
18
@@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size,
19
}
20
}
21
22
+/* Returns whether the image file is opened as read-only. Note that this can
23
+ * return false and writing to the image file is still not possible because the
24
+ * image is inactivated. */
25
bool bdrv_is_read_only(BlockDriverState *bs)
26
{
27
return bs->read_only;
28
}
29
30
+/* Returns whether the image file can be written to right now */
31
+bool bdrv_is_writable(BlockDriverState *bs)
32
+{
33
+ return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE);
34
+}
35
+
36
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
37
{
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
}
68
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
69
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
70
{
71
BdrvChild *child, *parent;
72
+ uint64_t perm, shared_perm;
73
Error *local_err = NULL;
74
int ret;
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
}
104
}
105
}
106
+
107
+ /* Update permissions, they may differ for inactive nodes */
108
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
109
+ bdrv_check_perm(bs, perm, shared_perm, NULL, &error_abort);
110
+ bdrv_set_perm(bs, perm, shared_perm);
111
}
112
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
--
127
1.8.3.1
128
129
diff view generated by jsdifflib
Deleted patch
1
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
2
1
3
On error path (like i/o error in one of the coroutines), it's required to
4
- wait for coroutines completion before cleaning the common structures
5
- reenter dependent coroutines so they ever finish
6
7
Introduced in 2d9187bc65.
8
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>
13
---
14
qemu-img.c | 26 +++++++++++---------------
15
1 file changed, 11 insertions(+), 15 deletions(-)
16
17
diff --git a/qemu-img.c b/qemu-img.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-img.c
20
+++ b/qemu-img.c
21
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
22
qemu_co_mutex_lock(&s->lock);
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
}
79
80
-out:
81
qemu_vfree(buf);
82
s->co[index] = NULL;
83
s->running_coroutines--;
84
@@ -XXX,XX +XXX,XX @@ static int convert_do_copy(ImgConvertState *s)
85
qemu_coroutine_enter(s->co[i]);
86
}
87
88
- while (s->ret == -EINPROGRESS) {
89
+ while (s->running_coroutines) {
90
main_loop_wait(false);
91
}
92
93
--
94
1.8.3.1
95
96
diff view generated by jsdifflib
Deleted patch
1
From: John Snow <jsnow@redhat.com>
2
1
3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1447551
4
5
If one tries to issue a block_resize while a guest is busy
6
accessing the disk, it is possible that qemu may deadlock
7
when invoking aio_poll from both the main loop and the iothread.
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>
18
---
19
blockdev.c | 5 ++---
20
1 file changed, 2 insertions(+), 3 deletions(-)
21
22
diff --git a/blockdev.c b/blockdev.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/blockdev.c
25
+++ b/blockdev.c
26
@@ -XXX,XX +XXX,XX @@ void qmp_block_resize(bool has_device, const char *device,
27
goto out;
28
}
29
30
- /* complete all in-flight operations before resizing the device */
31
- bdrv_drain_all();
32
-
33
+ bdrv_drained_begin(bs);
34
ret = blk_truncate(blk, size, errp);
35
+ bdrv_drained_end(bs);
36
37
out:
38
blk_unref(blk);
39
--
40
1.8.3.1
41
42
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Several copy-and-pasted alignment checks exist in qemu-io, which
4
could use some minor improvements:
5
6
- Manual comparison against 0x1ff is not as clean as using our
7
alignment macros (QEMU_IS_ALIGNED) from osdep.h.
8
9
- The error messages aren't quite grammatically correct.
10
11
Suggested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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
--- a/qemu-io-cmds.c
25
+++ b/qemu-io-cmds.c
26
@@ -XXX,XX +XXX,XX @@ static int read_f(BlockBackend *blk, int argc, char **argv)
27
}
28
29
if (bflag) {
30
- if (offset & 0x1ff) {
31
- printf("offset %" PRId64 " is not sector aligned\n",
32
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
33
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
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
}
46
47
if (bflag || cflag) {
48
- if (offset & 0x1ff) {
49
- printf("offset %" PRId64 " is not sector aligned\n",
50
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
51
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
52
offset);
53
return 0;
54
}
55
56
- if (count & 0x1ff) {
57
- printf("count %"PRId64" is not sector aligned\n",
58
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
59
+ printf("%"PRId64" is not a sector-aligned value for 'count'\n",
60
count);
61
return 0;
62
}
63
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
64
if (offset < 0) {
65
print_cvtnum_err(offset, argv[1]);
66
return 0;
67
- } else if (offset & 0x1ff) {
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
}
74
--
75
1.8.3.1
76
77
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than repeat the logic at each caller of checking if a Rule
4
exists that warrants an error injection, fold that logic into
5
inject_error(); and rename it to rule_check() for legibility.
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
9
Signed-off-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Message-id: 20170429191419.30051-6-eblake@redhat.com
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
14
block/blkdebug.c | 74 +++++++++++++++++++++++++-------------------------------
15
1 file changed, 33 insertions(+), 41 deletions(-)
16
17
diff --git a/block/blkdebug.c b/block/blkdebug.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/blkdebug.c
20
+++ b/block/blkdebug.c
21
@@ -XXX,XX +XXX,XX @@ out:
22
return ret;
23
}
24
25
-static int inject_error(BlockDriverState *bs, BlkdebugRule *rule)
26
+static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes)
27
{
28
BDRVBlkdebugState *s = bs->opaque;
29
- int error = rule->options.inject.error;
30
- bool immediately = rule->options.inject.immediately;
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
}
68
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
--
141
1.8.3.1
142
143
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
In order to test the effects of artificial geometry constraints
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
---
40
block/blkdebug.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41
1 file changed, 74 insertions(+)
42
43
diff --git a/block/blkdebug.c b/block/blkdebug.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/block/blkdebug.c
46
+++ b/block/blkdebug.c
47
@@ -XXX,XX +XXX,XX @@
48
/*
49
* Block protocol for I/O error injection
50
*
51
+ * Copyright (C) 2016-2017 Red Hat, Inc.
52
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
53
*
54
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
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
+
64
/* Set request alignment */
65
align = qemu_opt_get_size(opts, "align", 0);
66
if (align < INT_MAX && is_power_of_2(align)) {
67
@@ -XXX,XX +XXX,XX @@ static int blkdebug_co_flush(BlockDriverState *bs)
68
return bdrv_co_flush(bs->file->bs);
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
+
79
+ /* Only pass through requests that are larger than requested
80
+ * preferred alignment (so that we test the fallback to writes on
81
+ * unaligned portions), and check that the block layer never hands
82
+ * us anything unaligned that crosses an alignment boundary. */
83
+ if (count < align) {
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
+
96
+ err = rule_check(bs, offset, count);
97
+ if (err) {
98
+ return err;
99
+ }
100
+
101
+ return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
102
+}
103
+
104
+static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
105
+ int64_t offset, int count)
106
+{
107
+ uint32_t align = bs->bl.pdiscard_alignment;
108
+ int err;
109
+
110
+ /* Only pass through requests that are larger than requested
111
+ * minimum alignment, and ensure that unaligned requests do not
112
+ * cross optimum discard boundaries. */
113
+ if (count < bs->bl.request_alignment) {
114
+ assert(QEMU_IS_ALIGNED(offset, align) ||
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
--
150
1.8.3.1
151
152
diff view generated by jsdifflib