1
The following changes since commit 76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb:
1
The following changes since commit 16aaacb307ed607b9780c12702c44f0fe52edc7e:
2
2
3
Merge remote-tracking branch 'armbru/tags/pull-qapi-2017-05-04-v3' into staging (2017-05-09 15:49:14 -0400)
3
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20200430' into staging (2020-04-30 14:00:36 +0100)
4
4
5
are available in the git repository at:
5
are available in the Git repository at:
6
7
6
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 eaae29ef89d498d0eac553c77b554f310a47f809:
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
qemu-storage-daemon: Fix non-string --object properties (2020-04-30 17:51:07 +0200)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block layer patches:
15
15
16
Block layer patches
16
- Fix resize (extending) of short overlays
17
- nvme: introduce PMR support from NVMe 1.4 spec
18
- qemu-storage-daemon: Fix non-string --object properties
17
19
18
----------------------------------------------------------------
20
----------------------------------------------------------------
19
Anton Nefedov (1):
21
Alberto Garcia (1):
20
qemu-img: wait for convert coroutines to complete
22
qcow2: Add incompatibility note between backing files and raw external data files
21
23
22
Christoph Hellwig (1):
24
Andrzej Jakowski (1):
23
nvme: Implement Write Zeroes
25
nvme: introduce PMR support from NVMe 1.4 spec
24
26
25
Eric Blake (21):
27
Kevin Wolf (12):
26
qemu-io: Improve alignment checks
28
block: Add flags to BlockDriver.bdrv_co_truncate()
27
qemu-io: Switch 'alloc' command to byte-based length
29
block: Add flags to bdrv(_co)_truncate()
28
qemu-io: Switch 'map' output to byte-based reporting
30
block-backend: Add flags to blk_truncate()
29
blkdebug: Sanity check block layer guarantees
31
qcow2: Support BDRV_REQ_ZERO_WRITE for truncate
30
blkdebug: Refactor error injection
32
raw-format: Support BDRV_REQ_ZERO_WRITE for truncate
31
blkdebug: Add pass-through write_zero and discard support
33
file-posix: Support BDRV_REQ_ZERO_WRITE for truncate
32
blkdebug: Simplify override logic
34
block: truncate: Don't make backing file data visible
33
blkdebug: Add ability to override unmap geometries
35
iotests: Filter testfiles out in filter_img_info()
34
tests: Add coverage for recent block geometry fixes
36
iotests: Test committing to short backing file
35
qcow2: Nicer variable names in qcow2_update_snapshot_refcount()
37
qcow2: Forward ZERO_WRITE flag for full preallocation
36
qcow2: Use consistent switch indentation
38
qom: Factor out user_creatable_add_dict()
37
block: Update comments on BDRV_BLOCK_* meanings
39
qemu-storage-daemon: Fix non-string --object properties
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
40
48
Fam Zheng (23):
41
Paolo Bonzini (1):
49
block: Make bdrv_perm_names public
42
qemu-iotests: allow qcow2 external discarded clusters to contain stale data
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
43
73
John Snow (1):
44
docs/interop/qcow2.txt | 3 +
74
blockdev: use drained_begin/end for qmp_block_resize
45
hw/block/nvme.h | 2 +
46
include/block/block.h | 5 +-
47
include/block/block_int.h | 10 +-
48
include/block/nvme.h | 172 ++++++++++++++++++++++++++
49
include/qom/object_interfaces.h | 16 +++
50
include/sysemu/block-backend.h | 2 +-
51
block.c | 3 +-
52
block/block-backend.c | 4 +-
53
block/commit.c | 4 +-
54
block/crypto.c | 7 +-
55
block/file-posix.c | 6 +-
56
block/file-win32.c | 2 +-
57
block/gluster.c | 1 +
58
block/io.c | 43 ++++++-
59
block/iscsi.c | 2 +-
60
block/mirror.c | 2 +-
61
block/nfs.c | 3 +-
62
block/parallels.c | 6 +-
63
block/qcow.c | 4 +-
64
block/qcow2-cluster.c | 2 +-
65
block/qcow2-refcount.c | 2 +-
66
block/qcow2.c | 73 +++++++++--
67
block/qed.c | 3 +-
68
block/raw-format.c | 6 +-
69
block/rbd.c | 1 +
70
block/sheepdog.c | 4 +-
71
block/ssh.c | 2 +-
72
block/vdi.c | 2 +-
73
block/vhdx-log.c | 2 +-
74
block/vhdx.c | 6 +-
75
block/vmdk.c | 8 +-
76
block/vpc.c | 2 +-
77
blockdev.c | 2 +-
78
hw/block/nvme.c | 109 ++++++++++++++++
79
qemu-img.c | 2 +-
80
qemu-io-cmds.c | 2 +-
81
qemu-storage-daemon.c | 4 +-
82
qom/object_interfaces.c | 31 +++++
83
qom/qom-qmp-cmds.c | 24 +---
84
tests/test-block-iothread.c | 9 +-
85
tests/qemu-iotests/iotests.py | 5 +-
86
hw/block/Makefile.objs | 2 +-
87
hw/block/trace-events | 4 +
88
tests/qemu-iotests/244 | 10 +-
89
tests/qemu-iotests/244.out | 9 +-
90
tests/qemu-iotests/274 | 155 +++++++++++++++++++++++
91
tests/qemu-iotests/274.out | 268 ++++++++++++++++++++++++++++++++++++++++
92
tests/qemu-iotests/group | 1 +
93
49 files changed, 951 insertions(+), 96 deletions(-)
94
create mode 100755 tests/qemu-iotests/274
95
create mode 100644 tests/qemu-iotests/274.out
75
96
76
Kevin Wolf (7):
77
migration: Unify block node activation error handling
78
block: New BdrvChildRole.activate() for blk_resume_after_migration()
79
block: Drop permissions when migration completes
80
block: Inactivate parents before children
81
block: Fix write/resize permissions for inactive images
82
file-posix: Remove .bdrv_inactivate/invalidate_cache
83
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block
84
97
85
Max Reitz (5):
86
qcow2: Fix preallocation size formula
87
qcow2: Reuse preallocated zero clusters
88
qcow2: Discard preallocated zero clusters
89
iotests: Extend test 066
90
MAINTAINERS: Add qemu-progress to the block layer
91
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
1
From: Max Reitz <mreitz@redhat.com>
1
From: Alberto Garcia <berto@igalia.com>
2
2
3
Instead of just freeing preallocated zero clusters and completely
3
Backing files and raw external data files are mutually exclusive.
4
allocating them from scratch, reuse them.
4
The documentation of the raw external data bit (in autoclear_features)
5
already indicates that, but we should also mention it on the other
6
side.
5
7
6
We cannot do this in handle_copied(), however, since this is a COW
8
Suggested-by: Eric Blake <eblake@redhat.com>
7
operation. Therefore, we have to add the new logic to handle_alloc() and
9
Signed-off-by: Alberto Garcia <berto@igalia.com>
8
simply return the existing offset if it exists. The only catch is that
10
Message-Id: <20200410121816.8334-1-berto@igalia.com>
9
we have to convince qcow2_alloc_cluster_link_l2() not to free the old
10
clusters (because we have reused them).
11
12
Reported-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
13
---
17
block/qcow2-cluster.c | 80 +++++++++++++++++++++++++++++++++++----------------
14
docs/interop/qcow2.txt | 3 +++
18
block/qcow2.h | 3 ++
15
1 file changed, 3 insertions(+)
19
2 files changed, 59 insertions(+), 24 deletions(-)
20
16
21
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt
22
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
23
--- a/block/qcow2-cluster.c
19
--- a/docs/interop/qcow2.txt
24
+++ b/block/qcow2-cluster.c
20
+++ b/docs/interop/qcow2.txt
25
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
21
@@ -XXX,XX +XXX,XX @@ The first cluster of a qcow2 image contains the file header:
26
uint64_t *l2_table, uint64_t stop_flags)
22
is stored (NB: The string is not null terminated). 0 if the
27
{
23
image doesn't have a backing file.
28
int i;
24
29
+ int first_cluster_type;
25
+ Note: backing files are incompatible with raw external data
30
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
26
+ files (auto-clear feature bit 1).
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
+
27
+
111
if (!alloc_cluster_offset) {
28
16 - 19: backing_file_size
112
- ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
29
Length of the backing file name in bytes. Must not be
113
- nb_clusters * s->cluster_size);
30
longer than 1023 bytes. Undefined if the image doesn't have
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
--
31
--
167
1.8.3.1
32
2.25.3
168
33
169
34
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
Test 244 checks the expected behavior of qcow2 external data files
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
4
with respect to zero and discarded clusters. Filesystems however
5
are free to ignore discard requests, and this seems to be the
6
case for overlayfs. Relax the tests to skip checks on the
7
external data file for discarded areas, which implies not using
8
qemu-img compare in the data_file_raw=on case.
9
10
This fixes docker tests on RHEL8.
11
12
Cc: Kevin Wolf <kwolf@redhat.com>
13
Cc: qemu-block@nongnu.org
14
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
15
Message-Id: <20200409191006.24429-1-pbonzini@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
17
---
7
tests/qemu-iotests/091 | 2 ++
18
tests/qemu-iotests/244 | 10 ++++++++--
8
1 file changed, 2 insertions(+)
19
tests/qemu-iotests/244.out | 9 ++++++---
20
2 files changed, 14 insertions(+), 5 deletions(-)
9
21
10
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
22
diff --git a/tests/qemu-iotests/244 b/tests/qemu-iotests/244
11
index XXXXXXX..XXXXXXX 100755
23
index XXXXXXX..XXXXXXX 100755
12
--- a/tests/qemu-iotests/091
24
--- a/tests/qemu-iotests/244
13
+++ b/tests/qemu-iotests/091
25
+++ b/tests/qemu-iotests/244
14
@@ -XXX,XX +XXX,XX @@ echo "vm2: qemu process running successfully"
26
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c 'read -P 0 0 1M' \
15
echo "vm2: flush io, and quit"
27
echo
16
_send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)"
28
$QEMU_IO -c 'read -P 0 0 1M' \
17
_send_qemu_cmd $h2 'quit' ""
29
-c 'read -P 0x11 1M 1M' \
18
+_send_qemu_cmd $h1 'quit' ""
30
- -c 'read -P 0 2M 2M' \
19
31
-c 'read -P 0x11 4M 1M' \
20
+wait
32
-c 'read -P 0 5M 1M' \
21
echo "Check image pattern"
33
-f raw "$TEST_IMG.data" |
22
${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io
34
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c 'read -P 0 0 1M' \
23
35
-f $IMGFMT "$TEST_IMG" |
36
_filter_qemu_io
37
38
+# Discarded clusters are only marked as such in the qcow2 metadata, but
39
+# they can contain stale data in the external data file. Instead, zero
40
+# clusters must be zeroed in the external data file too.
41
echo
42
-$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG.data"
43
+$QEMU_IO -c 'read -P 0 0 1M' \
44
+ -c 'read -P 0x11 1M 1M' \
45
+ -c 'read -P 0 3M 3M' \
46
+ -f raw "$TEST_IMG".data |
47
+ _filter_qemu_io
48
49
echo -n "qcow2 file size after I/O: "
50
du -b $TEST_IMG | cut -f1
51
diff --git a/tests/qemu-iotests/244.out b/tests/qemu-iotests/244.out
52
index XXXXXXX..XXXXXXX 100644
53
--- a/tests/qemu-iotests/244.out
54
+++ b/tests/qemu-iotests/244.out
55
@@ -XXX,XX +XXX,XX @@ read 1048576/1048576 bytes at offset 0
56
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
57
read 1048576/1048576 bytes at offset 1048576
58
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
59
-read 2097152/2097152 bytes at offset 2097152
60
-2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
61
read 1048576/1048576 bytes at offset 4194304
62
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
63
read 1048576/1048576 bytes at offset 5242880
64
@@ -XXX,XX +XXX,XX @@ read 1048576/1048576 bytes at offset 1048576
65
read 4194304/4194304 bytes at offset 2097152
66
4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
67
68
-Images are identical.
69
+read 1048576/1048576 bytes at offset 0
70
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
71
+read 1048576/1048576 bytes at offset 1048576
72
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
73
+read 3145728/3145728 bytes at offset 3145728
74
+3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
75
qcow2 file size after I/O: 327680
76
77
=== bdrv_co_block_status test for file and offset=0 ===
24
--
78
--
25
1.8.3.1
79
2.25.3
26
80
27
81
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
This adds a new BdrvRequestFlags parameter to the .bdrv_co_truncate()
2
2
driver callbacks, and a supported_truncate_flags field in
3
We share the same set of QAPI options with file-posix, but locking is
3
BlockDriverState that allows drivers to advertise support for request
4
not supported here. So error out if it is specified as 'on' for now.
4
flags in the context of truncate.
5
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
6
For now, we always pass 0 and no drivers declare support for any flag.
7
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
10
Reviewed-by: Alberto Garcia <berto@igalia.com>
11
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Message-Id: <20200424125448.63318-2-kwolf@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
14
---
9
block/file-win32.c | 5 +++++
15
include/block/block_int.h | 10 +++++++++-
10
1 file changed, 5 insertions(+)
16
block/crypto.c | 3 ++-
11
17
block/file-posix.c | 2 +-
18
block/file-win32.c | 2 +-
19
block/gluster.c | 1 +
20
block/io.c | 8 +++++++-
21
block/iscsi.c | 2 +-
22
block/nfs.c | 3 ++-
23
block/qcow2.c | 2 +-
24
block/qed.c | 1 +
25
block/raw-format.c | 2 +-
26
block/rbd.c | 1 +
27
block/sheepdog.c | 4 ++--
28
block/ssh.c | 2 +-
29
tests/test-block-iothread.c | 3 ++-
30
15 files changed, 33 insertions(+), 13 deletions(-)
31
32
diff --git a/include/block/block_int.h b/include/block/block_int.h
33
index XXXXXXX..XXXXXXX 100644
34
--- a/include/block/block_int.h
35
+++ b/include/block/block_int.h
36
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
37
*/
38
int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t offset,
39
bool exact, PreallocMode prealloc,
40
- Error **errp);
41
+ BdrvRequestFlags flags, Error **errp);
42
43
int64_t (*bdrv_getlength)(BlockDriverState *bs);
44
bool has_variable_length;
45
@@ -XXX,XX +XXX,XX @@ struct BlockDriverState {
46
/* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA,
47
* BDRV_REQ_MAY_UNMAP, BDRV_REQ_WRITE_UNCHANGED) */
48
unsigned int supported_zero_flags;
49
+ /*
50
+ * Flags honoured during truncate (so far: BDRV_REQ_ZERO_WRITE).
51
+ *
52
+ * If BDRV_REQ_ZERO_WRITE is given, the truncate operation must make sure
53
+ * that any added space reads as all zeros. If this can't be guaranteed,
54
+ * the operation must fail.
55
+ */
56
+ unsigned int supported_truncate_flags;
57
58
/* the following member gives a name to every node on the bs graph. */
59
char node_name[32];
60
diff --git a/block/crypto.c b/block/crypto.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/block/crypto.c
63
+++ b/block/crypto.c
64
@@ -XXX,XX +XXX,XX @@ static int block_crypto_co_create_generic(BlockDriverState *bs,
65
66
static int coroutine_fn
67
block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
68
- PreallocMode prealloc, Error **errp)
69
+ PreallocMode prealloc, BdrvRequestFlags flags,
70
+ Error **errp)
71
{
72
BlockCrypto *crypto = bs->opaque;
73
uint64_t payload_offset =
74
diff --git a/block/file-posix.c b/block/file-posix.c
75
index XXXXXXX..XXXXXXX 100644
76
--- a/block/file-posix.c
77
+++ b/block/file-posix.c
78
@@ -XXX,XX +XXX,XX @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
79
80
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
81
bool exact, PreallocMode prealloc,
82
- Error **errp)
83
+ BdrvRequestFlags flags, Error **errp)
84
{
85
BDRVRawState *s = bs->opaque;
86
struct stat st;
12
diff --git a/block/file-win32.c b/block/file-win32.c
87
diff --git a/block/file-win32.c b/block/file-win32.c
13
index XXXXXXX..XXXXXXX 100644
88
index XXXXXXX..XXXXXXX 100644
14
--- a/block/file-win32.c
89
--- a/block/file-win32.c
15
+++ b/block/file-win32.c
90
+++ b/block/file-win32.c
16
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
91
@@ -XXX,XX +XXX,XX @@ static void raw_close(BlockDriverState *bs)
17
goto fail;
92
93
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
94
bool exact, PreallocMode prealloc,
95
- Error **errp)
96
+ BdrvRequestFlags flags, Error **errp)
97
{
98
BDRVRawState *s = bs->opaque;
99
LONG low, high;
100
diff --git a/block/gluster.c b/block/gluster.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/block/gluster.c
103
+++ b/block/gluster.c
104
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qemu_gluster_co_truncate(BlockDriverState *bs,
105
int64_t offset,
106
bool exact,
107
PreallocMode prealloc,
108
+ BdrvRequestFlags flags,
109
Error **errp)
110
{
111
BDRVGlusterState *s = bs->opaque;
112
diff --git a/block/io.c b/block/io.c
113
index XXXXXXX..XXXXXXX 100644
114
--- a/block/io.c
115
+++ b/block/io.c
116
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
117
BlockDriverState *bs = child->bs;
118
BlockDriver *drv = bs->drv;
119
BdrvTrackedRequest req;
120
+ BdrvRequestFlags flags = 0;
121
int64_t old_size, new_bytes;
122
int ret;
123
124
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
18
}
125
}
19
126
20
+ if (qdict_get_try_bool(options, "locking", false)) {
127
if (drv->bdrv_co_truncate) {
21
+ error_setg(errp, "locking=on is not supported on Windows");
128
- ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, errp);
22
+ goto fail;
129
+ if (flags & ~bs->supported_truncate_flags) {
23
+ }
130
+ error_setg(errp, "Block driver does not support requested flags");
24
+
131
+ ret = -ENOTSUP;
25
filename = qemu_opt_get(opts, "filename");
132
+ goto out;
26
133
+ }
27
use_aio = get_aio_option(opts, flags, &local_err);
134
+ ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
135
} else if (bs->file && drv->is_filter) {
136
ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
137
} else {
138
diff --git a/block/iscsi.c b/block/iscsi.c
139
index XXXXXXX..XXXXXXX 100644
140
--- a/block/iscsi.c
141
+++ b/block/iscsi.c
142
@@ -XXX,XX +XXX,XX @@ static void iscsi_reopen_commit(BDRVReopenState *reopen_state)
143
144
static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
145
bool exact, PreallocMode prealloc,
146
- Error **errp)
147
+ BdrvRequestFlags flags, Error **errp)
148
{
149
IscsiLun *iscsilun = bs->opaque;
150
int64_t cur_length;
151
diff --git a/block/nfs.c b/block/nfs.c
152
index XXXXXXX..XXXXXXX 100644
153
--- a/block/nfs.c
154
+++ b/block/nfs.c
155
@@ -XXX,XX +XXX,XX @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
156
157
static int coroutine_fn
158
nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
159
- PreallocMode prealloc, Error **errp)
160
+ PreallocMode prealloc, BdrvRequestFlags flags,
161
+ Error **errp)
162
{
163
NFSClient *client = bs->opaque;
164
int ret;
165
diff --git a/block/qcow2.c b/block/qcow2.c
166
index XXXXXXX..XXXXXXX 100644
167
--- a/block/qcow2.c
168
+++ b/block/qcow2.c
169
@@ -XXX,XX +XXX,XX @@ fail:
170
171
static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
172
bool exact, PreallocMode prealloc,
173
- Error **errp)
174
+ BdrvRequestFlags flags, Error **errp)
175
{
176
BDRVQcow2State *s = bs->opaque;
177
uint64_t old_length;
178
diff --git a/block/qed.c b/block/qed.c
179
index XXXXXXX..XXXXXXX 100644
180
--- a/block/qed.c
181
+++ b/block/qed.c
182
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_truncate(BlockDriverState *bs,
183
int64_t offset,
184
bool exact,
185
PreallocMode prealloc,
186
+ BdrvRequestFlags flags,
187
Error **errp)
188
{
189
BDRVQEDState *s = bs->opaque;
190
diff --git a/block/raw-format.c b/block/raw-format.c
191
index XXXXXXX..XXXXXXX 100644
192
--- a/block/raw-format.c
193
+++ b/block/raw-format.c
194
@@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
195
196
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
197
bool exact, PreallocMode prealloc,
198
- Error **errp)
199
+ BdrvRequestFlags flags, Error **errp)
200
{
201
BDRVRawState *s = bs->opaque;
202
203
diff --git a/block/rbd.c b/block/rbd.c
204
index XXXXXXX..XXXXXXX 100644
205
--- a/block/rbd.c
206
+++ b/block/rbd.c
207
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,
208
int64_t offset,
209
bool exact,
210
PreallocMode prealloc,
211
+ BdrvRequestFlags flags,
212
Error **errp)
213
{
214
int r;
215
diff --git a/block/sheepdog.c b/block/sheepdog.c
216
index XXXXXXX..XXXXXXX 100644
217
--- a/block/sheepdog.c
218
+++ b/block/sheepdog.c
219
@@ -XXX,XX +XXX,XX @@ static int64_t sd_getlength(BlockDriverState *bs)
220
221
static int coroutine_fn sd_co_truncate(BlockDriverState *bs, int64_t offset,
222
bool exact, PreallocMode prealloc,
223
- Error **errp)
224
+ BdrvRequestFlags flags, Error **errp)
225
{
226
BDRVSheepdogState *s = bs->opaque;
227
int ret, fd;
228
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
229
230
assert(!flags);
231
if (offset > s->inode.vdi_size) {
232
- ret = sd_co_truncate(bs, offset, false, PREALLOC_MODE_OFF, NULL);
233
+ ret = sd_co_truncate(bs, offset, false, PREALLOC_MODE_OFF, 0, NULL);
234
if (ret < 0) {
235
return ret;
236
}
237
diff --git a/block/ssh.c b/block/ssh.c
238
index XXXXXXX..XXXXXXX 100644
239
--- a/block/ssh.c
240
+++ b/block/ssh.c
241
@@ -XXX,XX +XXX,XX @@ static int64_t ssh_getlength(BlockDriverState *bs)
242
243
static int coroutine_fn ssh_co_truncate(BlockDriverState *bs, int64_t offset,
244
bool exact, PreallocMode prealloc,
245
- Error **errp)
246
+ BdrvRequestFlags flags, Error **errp)
247
{
248
BDRVSSHState *s = bs->opaque;
249
250
diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
251
index XXXXXXX..XXXXXXX 100644
252
--- a/tests/test-block-iothread.c
253
+++ b/tests/test-block-iothread.c
254
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_test_co_pdiscard(BlockDriverState *bs,
255
256
static int coroutine_fn
257
bdrv_test_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
258
- PreallocMode prealloc, Error **errp)
259
+ PreallocMode prealloc, BdrvRequestFlags flags,
260
+ Error **errp)
261
{
262
return 0;
263
}
28
--
264
--
29
1.8.3.1
265
2.25.3
30
266
31
267
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
Now that block drivers can support flags for .bdrv_co_truncate, expose
2
the parameter in the node level interfaces bdrv_co_truncate() and
3
bdrv_truncate().
2
4
3
Treat plain zero clusters differently from allocated ones, so that
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
we can simplify the logic of checking whether an offset is present.
6
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
5
Do this by splitting QCOW2_CLUSTER_ZERO into two new enums,
7
Reviewed-by: Alberto Garcia <berto@igalia.com>
6
QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC.
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-Id: <20200424125448.63318-3-kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
---
12
include/block/block.h | 5 +++--
13
block/block-backend.c | 2 +-
14
block/crypto.c | 2 +-
15
block/io.c | 12 +++++++-----
16
block/parallels.c | 6 +++---
17
block/qcow.c | 4 ++--
18
block/qcow2-refcount.c | 2 +-
19
block/qcow2.c | 15 +++++++++------
20
block/raw-format.c | 2 +-
21
block/vhdx-log.c | 2 +-
22
block/vhdx.c | 2 +-
23
block/vmdk.c | 2 +-
24
tests/test-block-iothread.c | 6 +++---
25
13 files changed, 34 insertions(+), 28 deletions(-)
7
26
8
I tried to arrange the enum so that we could use
27
diff --git a/include/block/block.h b/include/block/block.h
9
'ret <= QCOW2_CLUSTER_ZERO_PLAIN' for all unallocated types, and
28
index XXXXXXX..XXXXXXX 100644
10
'ret >= QCOW2_CLUSTER_ZERO_ALLOC' for allocated types, although
29
--- a/include/block/block.h
11
I didn't actually end up taking advantage of the layout.
30
+++ b/include/block/block.h
12
31
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
13
In many cases, this leads to simpler code, by properly combining
32
void bdrv_refresh_filename(BlockDriverState *bs);
14
cases (sometimes, both zero types pair together, other times,
33
15
plain zero is more like unallocated while allocated zero is more
34
int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
16
like normal).
35
- PreallocMode prealloc, Error **errp);
17
36
+ PreallocMode prealloc, BdrvRequestFlags flags,
18
Signed-off-by: Eric Blake <eblake@redhat.com>
37
+ Error **errp);
19
Message-id: 20170507000552.20847-7-eblake@redhat.com
38
int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
20
Reviewed-by: Max Reitz <mreitz@redhat.com>
39
- PreallocMode prealloc, Error **errp);
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
40
+ PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
22
---
41
23
block/qcow2-cluster.c | 79 ++++++++++++++++++----------------------------
42
int64_t bdrv_nb_sectors(BlockDriverState *bs);
24
block/qcow2-refcount.c | 44 +++++++++++---------------
43
int64_t bdrv_getlength(BlockDriverState *bs);
25
block/qcow2.c | 9 ++++--
44
diff --git a/block/block-backend.c b/block/block-backend.c
26
block/qcow2.h | 8 +++--
45
index XXXXXXX..XXXXXXX 100644
27
tests/qemu-iotests/060.out | 6 ++--
46
--- a/block/block-backend.c
28
5 files changed, 63 insertions(+), 83 deletions(-)
47
+++ b/block/block-backend.c
29
48
@@ -XXX,XX +XXX,XX @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
49
return -ENOMEDIUM;
31
index XXXXXXX..XXXXXXX 100644
50
}
32
--- a/block/qcow2-cluster.c
51
33
+++ b/block/qcow2-cluster.c
52
- return bdrv_truncate(blk->root, offset, exact, prealloc, errp);
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
53
+ return bdrv_truncate(blk->root, offset, exact, prealloc, 0, errp);
35
/* must be allocated */
54
}
36
first_cluster_type = qcow2_get_cluster_type(first_entry);
55
37
assert(first_cluster_type == QCOW2_CLUSTER_NORMAL ||
56
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
38
- (first_cluster_type == QCOW2_CLUSTER_ZERO &&
57
diff --git a/block/crypto.c b/block/crypto.c
39
- (first_entry & L2E_OFFSET_MASK) != 0));
58
index XXXXXXX..XXXXXXX 100644
40
+ first_cluster_type == QCOW2_CLUSTER_ZERO_ALLOC);
59
--- a/block/crypto.c
41
60
+++ b/block/crypto.c
42
for (i = 0; i < nb_clusters; i++) {
61
@@ -XXX,XX +XXX,XX @@ block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
43
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
62
44
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
63
offset += payload_offset;
64
65
- return bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
66
+ return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
67
}
68
69
static void block_crypto_close(BlockDriverState *bs)
70
diff --git a/block/io.c b/block/io.c
71
index XXXXXXX..XXXXXXX 100644
72
--- a/block/io.c
73
+++ b/block/io.c
74
@@ -XXX,XX +XXX,XX @@ static void bdrv_parent_cb_resize(BlockDriverState *bs)
75
* 'offset' bytes in length.
76
*/
77
int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
78
- PreallocMode prealloc, Error **errp)
79
+ PreallocMode prealloc, BdrvRequestFlags flags,
80
+ Error **errp)
45
{
81
{
46
int i;
82
BlockDriverState *bs = child->bs;
47
83
BlockDriver *drv = bs->drv;
48
- assert(wanted_type == QCOW2_CLUSTER_ZERO ||
84
BdrvTrackedRequest req;
49
+ assert(wanted_type == QCOW2_CLUSTER_ZERO_PLAIN ||
85
- BdrvRequestFlags flags = 0;
50
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
86
int64_t old_size, new_bytes;
51
for (i = 0; i < nb_clusters; i++) {
87
int ret;
52
uint64_t entry = be64_to_cpu(l2_table[i]);
88
53
QCow2ClusterType type = qcow2_get_cluster_type(entry);
89
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
54
90
}
55
- if (type != wanted_type || entry & L2E_OFFSET_MASK) {
91
ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
56
+ if (type != wanted_type) {
92
} else if (bs->file && drv->is_filter) {
57
break;
93
- ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
58
}
94
+ ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
59
}
95
} else {
60
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
96
error_setg(errp, "Image format driver does not support resize");
61
assert(nb_clusters <= INT_MAX);
97
ret = -ENOTSUP;
62
98
@@ -XXX,XX +XXX,XX @@ typedef struct TruncateCo {
63
type = qcow2_get_cluster_type(*cluster_offset);
99
int64_t offset;
64
+ if (s->qcow_version < 3 && (type == QCOW2_CLUSTER_ZERO_PLAIN ||
100
bool exact;
65
+ type == QCOW2_CLUSTER_ZERO_ALLOC)) {
101
PreallocMode prealloc;
66
+ qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
102
+ BdrvRequestFlags flags;
67
+ " in pre-v3 image (L2 offset: %#" PRIx64
103
Error **errp;
68
+ ", L2 index: %#x)", l2_offset, l2_index);
104
int ret;
69
+ ret = -EIO;
105
} TruncateCo;
70
+ goto fail;
106
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_truncate_co_entry(void *opaque)
71
+ }
107
{
72
switch (type) {
108
TruncateCo *tco = opaque;
73
case QCOW2_CLUSTER_COMPRESSED:
109
tco->ret = bdrv_co_truncate(tco->child, tco->offset, tco->exact,
74
/* Compressed clusters can only be processed one by one */
110
- tco->prealloc, tco->errp);
75
c = 1;
111
+ tco->prealloc, tco->flags, tco->errp);
76
*cluster_offset &= L2E_COMPRESSED_OFFSET_SIZE_MASK;
112
aio_wait_kick();
77
break;
113
}
78
- case QCOW2_CLUSTER_ZERO:
114
79
- if (s->qcow_version < 3) {
115
int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
80
- qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
116
- PreallocMode prealloc, Error **errp)
81
- " in pre-v3 image (L2 offset: %#" PRIx64
117
+ PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
82
- ", L2 index: %#x)", l2_offset, l2_index);
118
{
83
- ret = -EIO;
119
Coroutine *co;
84
- goto fail;
120
TruncateCo tco = {
85
- }
121
@@ -XXX,XX +XXX,XX @@ int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
86
- /* Distinguish between pure zero clusters and pre-allocated ones */
122
.offset = offset,
87
- if (*cluster_offset & L2E_OFFSET_MASK) {
123
.exact = exact,
88
- c = count_contiguous_clusters(nb_clusters, s->cluster_size,
124
.prealloc = prealloc,
89
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
125
+ .flags = flags,
90
- *cluster_offset &= L2E_OFFSET_MASK;
126
.errp = errp,
91
- if (offset_into_cluster(s, *cluster_offset)) {
127
.ret = NOT_DONE,
92
- qcow2_signal_corruption(bs, true, -1, -1,
128
};
93
- "Preallocated zero cluster offset %#"
129
diff --git a/block/parallels.c b/block/parallels.c
94
- PRIx64 " unaligned (L2 offset: %#"
130
index XXXXXXX..XXXXXXX 100644
95
- PRIx64 ", L2 index: %#x)",
131
--- a/block/parallels.c
96
- *cluster_offset, l2_offset, l2_index);
132
+++ b/block/parallels.c
97
- ret = -EIO;
133
@@ -XXX,XX +XXX,XX @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
98
- goto fail;
134
} else {
99
- }
135
ret = bdrv_truncate(bs->file,
100
- } else {
136
(s->data_end + space) << BDRV_SECTOR_BITS,
101
- c = count_contiguous_clusters_unallocated(nb_clusters,
137
- false, PREALLOC_MODE_OFF, NULL);
102
- &l2_table[l2_index],
138
+ false, PREALLOC_MODE_OFF, 0, NULL);
103
- QCOW2_CLUSTER_ZERO);
139
}
104
- *cluster_offset = 0;
140
if (ret < 0) {
105
- }
141
return ret;
106
- break;
142
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs,
107
+ case QCOW2_CLUSTER_ZERO_PLAIN:
143
* That means we have to pass exact=true.
108
case QCOW2_CLUSTER_UNALLOCATED:
144
*/
109
/* how many empty clusters ? */
145
ret = bdrv_truncate(bs->file, res->image_end_offset, true,
110
c = count_contiguous_clusters_unallocated(nb_clusters,
146
- PREALLOC_MODE_OFF, &local_err);
111
- &l2_table[l2_index],
147
+ PREALLOC_MODE_OFF, 0, &local_err);
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) {
148
if (ret < 0) {
198
- if (!preallocated) {
149
error_report_err(local_err);
199
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
150
res->check_errors++;
200
qcow2_free_clusters(bs, offset, s->cluster_size,
151
@@ -XXX,XX +XXX,XX @@ static void parallels_close(BlockDriverState *bs)
201
QCOW2_DISCARD_ALWAYS);
152
202
}
153
/* errors are ignored, so we might as well pass exact=true */
203
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
154
bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, true,
204
155
- PREALLOC_MODE_OFF, NULL);
205
ret = bdrv_pwrite_zeroes(bs->file, offset, s->cluster_size, 0);
156
+ PREALLOC_MODE_OFF, 0, NULL);
206
if (ret < 0) {
157
}
207
- if (!preallocated) {
158
208
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
159
g_free(s->bat_dirty_bmap);
209
qcow2_free_clusters(bs, offset, s->cluster_size,
160
diff --git a/block/qcow.c b/block/qcow.c
210
QCOW2_DISCARD_ALWAYS);
161
index XXXXXXX..XXXXXXX 100644
211
}
162
--- a/block/qcow.c
163
+++ b/block/qcow.c
164
@@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs,
165
return -E2BIG;
166
}
167
ret = bdrv_truncate(bs->file, cluster_offset + s->cluster_size,
168
- false, PREALLOC_MODE_OFF, NULL);
169
+ false, PREALLOC_MODE_OFF, 0, NULL);
170
if (ret < 0) {
171
return ret;
172
}
173
@@ -XXX,XX +XXX,XX @@ static int qcow_make_empty(BlockDriverState *bs)
174
l1_length) < 0)
175
return -1;
176
ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, false,
177
- PREALLOC_MODE_OFF, NULL);
178
+ PREALLOC_MODE_OFF, 0, NULL);
179
if (ret < 0)
180
return ret;
181
212
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
182
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
213
index XXXXXXX..XXXXXXX 100644
183
index XXXXXXX..XXXXXXX 100644
214
--- a/block/qcow2-refcount.c
184
--- a/block/qcow2-refcount.c
215
+++ b/block/qcow2-refcount.c
185
+++ b/block/qcow2-refcount.c
216
@@ -XXX,XX +XXX,XX @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
186
@@ -XXX,XX +XXX,XX @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
217
}
187
}
218
break;
188
219
case QCOW2_CLUSTER_NORMAL:
189
ret = bdrv_truncate(bs->file, offset + s->cluster_size, false,
220
- case QCOW2_CLUSTER_ZERO:
190
- PREALLOC_MODE_OFF, &local_err);
221
- if (l2_entry & L2E_OFFSET_MASK) {
191
+ PREALLOC_MODE_OFF, 0, &local_err);
222
- if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
192
if (ret < 0) {
223
- qcow2_signal_corruption(bs, false, -1, -1,
193
error_report_err(local_err);
224
- "Cannot free unaligned cluster %#llx",
194
goto resize_fail;
225
- l2_entry & L2E_OFFSET_MASK);
226
- } else {
227
- qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
228
- nb_clusters << s->cluster_bits, type);
229
- }
230
+ case QCOW2_CLUSTER_ZERO_ALLOC:
231
+ if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
232
+ qcow2_signal_corruption(bs, false, -1, -1,
233
+ "Cannot free unaligned cluster %#llx",
234
+ l2_entry & L2E_OFFSET_MASK);
235
+ } else {
236
+ qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
237
+ nb_clusters << s->cluster_bits, type);
238
}
239
break;
240
+ case QCOW2_CLUSTER_ZERO_PLAIN:
241
case QCOW2_CLUSTER_UNALLOCATED:
242
break;
243
default:
244
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
245
break;
246
247
case QCOW2_CLUSTER_NORMAL:
248
- case QCOW2_CLUSTER_ZERO:
249
+ case QCOW2_CLUSTER_ZERO_ALLOC:
250
if (offset_into_cluster(s, offset)) {
251
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
252
- "cluster offset %#" PRIx64
253
+ qcow2_signal_corruption(bs, true, -1, -1, "Cluster "
254
+ "allocation offset %#" PRIx64
255
" unaligned (L2 offset: %#"
256
PRIx64 ", L2 index: %#x)",
257
offset, l2_offset, j);
258
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
259
}
260
261
cluster_index = offset >> s->cluster_bits;
262
- if (!cluster_index) {
263
- /* unallocated */
264
- refcount = 0;
265
- break;
266
- }
267
+ assert(cluster_index);
268
if (addend != 0) {
269
ret = qcow2_update_cluster_refcount(bs,
270
cluster_index, abs(addend), addend < 0,
271
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
272
}
273
break;
274
275
+ case QCOW2_CLUSTER_ZERO_PLAIN:
276
case QCOW2_CLUSTER_UNALLOCATED:
277
refcount = 0;
278
break;
279
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
280
}
281
break;
282
283
- case QCOW2_CLUSTER_ZERO:
284
- if ((l2_entry & L2E_OFFSET_MASK) == 0) {
285
- break;
286
- }
287
- /* fall through */
288
-
289
+ case QCOW2_CLUSTER_ZERO_ALLOC:
290
case QCOW2_CLUSTER_NORMAL:
291
{
292
uint64_t offset = l2_entry & L2E_OFFSET_MASK;
293
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
294
break;
295
}
296
297
+ case QCOW2_CLUSTER_ZERO_PLAIN:
298
case QCOW2_CLUSTER_UNALLOCATED:
299
break;
300
301
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
302
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
303
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
304
305
- if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
306
- ((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
307
+ if (cluster_type == QCOW2_CLUSTER_NORMAL ||
308
+ cluster_type == QCOW2_CLUSTER_ZERO_ALLOC) {
309
ret = qcow2_get_refcount(bs,
310
data_offset >> s->cluster_bits,
311
&refcount);
312
diff --git a/block/qcow2.c b/block/qcow2.c
195
diff --git a/block/qcow2.c b/block/qcow2.c
313
index XXXXXXX..XXXXXXX 100644
196
index XXXXXXX..XXXXXXX 100644
314
--- a/block/qcow2.c
197
--- a/block/qcow2.c
315
+++ b/block/qcow2.c
198
+++ b/block/qcow2.c
316
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
199
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset,
317
*file = bs->file->bs;
200
mode = PREALLOC_MODE_OFF;
318
status |= BDRV_BLOCK_OFFSET_VALID | cluster_offset;
201
}
319
}
202
ret = bdrv_co_truncate(s->data_file, host_offset + cur_bytes, false,
320
- if (ret == QCOW2_CLUSTER_ZERO) {
203
- mode, errp);
321
+ if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) {
204
+ mode, 0, errp);
322
status |= BDRV_BLOCK_ZERO;
205
if (ret < 0) {
323
} else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
206
return ret;
324
status |= BDRV_BLOCK_DATA;
207
}
325
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
208
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
209
* always fulfilled, so there is no need to pass it on.)
210
*/
211
bdrv_co_truncate(bs->file, (last_cluster + 1) * s->cluster_size,
212
- false, PREALLOC_MODE_OFF, &local_err);
213
+ false, PREALLOC_MODE_OFF, 0, &local_err);
214
if (local_err) {
215
warn_reportf_err(local_err,
216
"Failed to truncate the tail of the image: ");
217
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
218
* file should be resized to the exact target size, too,
219
* so we pass @exact here.
220
*/
221
- ret = bdrv_co_truncate(s->data_file, offset, exact, prealloc, errp);
222
+ ret = bdrv_co_truncate(s->data_file, offset, exact, prealloc, 0,
223
+ errp);
224
if (ret < 0) {
225
goto fail;
326
}
226
}
327
break;
227
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
328
228
new_file_size = allocation_start +
329
- case QCOW2_CLUSTER_ZERO:
229
nb_new_data_clusters * s->cluster_size;
330
+ case QCOW2_CLUSTER_ZERO_PLAIN:
230
/* Image file grows, so @exact does not matter */
331
+ case QCOW2_CLUSTER_ZERO_ALLOC:
231
- ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, errp);
332
qemu_iovec_memset(&hd_qiov, 0, 0, cur_bytes);
232
+ ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, 0,
333
break;
233
+ errp);
334
234
if (ret < 0) {
335
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
235
error_prepend(errp, "Failed to resize underlying file: ");
336
count = s->cluster_size;
236
qcow2_free_clusters(bs, allocation_start,
337
nr = s->cluster_size;
237
@@ -XXX,XX +XXX,XX @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,
338
ret = qcow2_get_cluster_offset(bs, offset, &nr, &off);
238
if (len < 0) {
339
- if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO) {
239
return len;
340
+ if (ret != QCOW2_CLUSTER_UNALLOCATED &&
240
}
341
+ ret != QCOW2_CLUSTER_ZERO_PLAIN &&
241
- return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, NULL);
342
+ ret != QCOW2_CLUSTER_ZERO_ALLOC) {
242
+ return bdrv_co_truncate(bs->file, len, false, PREALLOC_MODE_OFF, 0,
343
qemu_co_mutex_unlock(&s->lock);
243
+ NULL);
344
return -ENOTSUP;
244
}
345
}
245
346
diff --git a/block/qcow2.h b/block/qcow2.h
246
if (offset_into_cluster(s, offset)) {
347
index XXXXXXX..XXXXXXX 100644
247
@@ -XXX,XX +XXX,XX @@ static int make_completely_empty(BlockDriverState *bs)
348
--- a/block/qcow2.h
248
}
349
+++ b/block/qcow2.h
249
350
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
250
ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size, false,
351
251
- PREALLOC_MODE_OFF, &local_err);
352
typedef enum QCow2ClusterType {
252
+ PREALLOC_MODE_OFF, 0, &local_err);
353
QCOW2_CLUSTER_UNALLOCATED,
253
if (ret < 0) {
354
+ QCOW2_CLUSTER_ZERO_PLAIN,
254
error_report_err(local_err);
355
+ QCOW2_CLUSTER_ZERO_ALLOC,
255
goto fail;
356
QCOW2_CLUSTER_NORMAL,
256
diff --git a/block/raw-format.c b/block/raw-format.c
357
QCOW2_CLUSTER_COMPRESSED,
257
index XXXXXXX..XXXXXXX 100644
358
- QCOW2_CLUSTER_ZERO
258
--- a/block/raw-format.c
359
} QCow2ClusterType;
259
+++ b/block/raw-format.c
360
260
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
361
typedef enum QCow2MetadataOverlap {
261
362
@@ -XXX,XX +XXX,XX @@ static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
262
s->size = offset;
363
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
263
offset += s->offset;
364
return QCOW2_CLUSTER_COMPRESSED;
264
- return bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
365
} else if (l2_entry & QCOW_OFLAG_ZERO) {
265
+ return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
366
- return QCOW2_CLUSTER_ZERO;
266
}
367
+ if (l2_entry & L2E_OFFSET_MASK) {
267
368
+ return QCOW2_CLUSTER_ZERO_ALLOC;
268
static void raw_eject(BlockDriverState *bs, bool eject_flag)
369
+ }
269
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
370
+ return QCOW2_CLUSTER_ZERO_PLAIN;
270
index XXXXXXX..XXXXXXX 100644
371
} else if (!(l2_entry & L2E_OFFSET_MASK)) {
271
--- a/block/vhdx-log.c
372
return QCOW2_CLUSTER_UNALLOCATED;
272
+++ b/block/vhdx-log.c
373
} else {
273
@@ -XXX,XX +XXX,XX @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s,
374
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
274
goto exit;
375
index XXXXXXX..XXXXXXX 100644
275
}
376
--- a/tests/qemu-iotests/060.out
276
ret = bdrv_truncate(bs->file, new_file_size, false,
377
+++ b/tests/qemu-iotests/060.out
277
- PREALLOC_MODE_OFF, NULL);
378
@@ -XXX,XX +XXX,XX @@ qemu-img: Error while amending options: Input/output error
278
+ PREALLOC_MODE_OFF, 0, NULL);
379
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
279
if (ret < 0) {
380
wrote 65536/65536 bytes at offset 0
280
goto exit;
381
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
281
}
382
-qcow2: Marking image as corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
282
diff --git a/block/vhdx.c b/block/vhdx.c
383
+qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
283
index XXXXXXX..XXXXXXX 100644
384
read failed: Input/output error
284
--- a/block/vhdx.c
385
285
+++ b/block/vhdx.c
386
=== Testing unaligned pre-allocated zero cluster ===
286
@@ -XXX,XX +XXX,XX @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
387
@@ -XXX,XX +XXX,XX @@ discard 65536/65536 bytes at offset 0
287
}
388
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
288
389
wrote 65536/65536 bytes at offset 0
289
return bdrv_truncate(bs->file, *new_offset + s->block_size, false,
390
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
290
- PREALLOC_MODE_OFF, NULL);
391
-qcow2: Image is corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
291
+ PREALLOC_MODE_OFF, 0, NULL);
392
+qcow2: Image is corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
292
}
393
read failed: Input/output error
293
394
read failed: Input/output error
294
/*
395
295
diff --git a/block/vmdk.c b/block/vmdk.c
396
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
296
index XXXXXXX..XXXXXXX 100644
397
wrote 131072/131072 bytes at offset 0
297
--- a/block/vmdk.c
398
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
298
+++ b/block/vmdk.c
399
qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further non-fatal corruption events will be suppressed
299
@@ -XXX,XX +XXX,XX @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
400
-qcow2: Marking image as corrupt: Data cluster offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
300
}
401
+qcow2: Marking image as corrupt: Cluster allocation offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
301
length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
402
discard 65536/65536 bytes at offset 0
302
ret = bdrv_truncate(s->extents[i].file, length, false,
403
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
303
- PREALLOC_MODE_OFF, NULL);
404
read failed: Input/output error
304
+ PREALLOC_MODE_OFF, 0, NULL);
305
if (ret < 0) {
306
return ret;
307
}
308
diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
309
index XXXXXXX..XXXXXXX 100644
310
--- a/tests/test-block-iothread.c
311
+++ b/tests/test-block-iothread.c
312
@@ -XXX,XX +XXX,XX @@ static void test_sync_op_truncate(BdrvChild *c)
313
int ret;
314
315
/* Normal success path */
316
- ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, NULL);
317
+ ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
318
g_assert_cmpint(ret, ==, 0);
319
320
/* Early error: Negative offset */
321
- ret = bdrv_truncate(c, -2, false, PREALLOC_MODE_OFF, NULL);
322
+ ret = bdrv_truncate(c, -2, false, PREALLOC_MODE_OFF, 0, NULL);
323
g_assert_cmpint(ret, ==, -EINVAL);
324
325
/* Error: Read-only image */
326
c->bs->read_only = true;
327
c->bs->open_flags &= ~BDRV_O_RDWR;
328
329
- ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, NULL);
330
+ ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
331
g_assert_cmpint(ret, ==, -EACCES);
332
333
c->bs->read_only = false;
405
--
334
--
406
1.8.3.1
335
2.25.3
407
336
408
337
diff view generated by jsdifflib
1
With image locking, permissions affect other qemu processes as well. We
1
Now that node level interface bdrv_truncate() supports passing request
2
want to be sure that the destination can run, so let's drop permissions
2
flags to the block driver, expose this on the BlockBackend level, too.
3
on the source when migration completes.
4
3
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
5
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Reviewed-by: Alberto Garcia <berto@igalia.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Message-Id: <20200424125448.63318-4-kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
10
---
8
block.c | 12 +++++++++++-
11
include/sysemu/block-backend.h | 2 +-
9
block/block-backend.c | 25 +++++++++++++++++++++++++
12
block.c | 3 ++-
10
include/block/block_int.h | 7 ++++---
13
block/block-backend.c | 4 ++--
11
3 files changed, 40 insertions(+), 4 deletions(-)
14
block/commit.c | 4 ++--
12
15
block/crypto.c | 2 +-
16
block/mirror.c | 2 +-
17
block/qcow2.c | 4 ++--
18
block/qed.c | 2 +-
19
block/vdi.c | 2 +-
20
block/vhdx.c | 4 ++--
21
block/vmdk.c | 6 +++---
22
block/vpc.c | 2 +-
23
blockdev.c | 2 +-
24
qemu-img.c | 2 +-
25
qemu-io-cmds.c | 2 +-
26
15 files changed, 22 insertions(+), 21 deletions(-)
27
28
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/include/sysemu/block-backend.h
31
+++ b/include/sysemu/block-backend.h
32
@@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
33
int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
34
int bytes);
35
int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
36
- PreallocMode prealloc, Error **errp);
37
+ PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
38
int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes);
39
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
40
int64_t pos, int size);
13
diff --git a/block.c b/block.c
41
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
15
--- a/block.c
43
--- a/block.c
16
+++ b/block.c
44
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache_all(Error **errp)
45
@@ -XXX,XX +XXX,XX @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
18
static int bdrv_inactivate_recurse(BlockDriverState *bs,
46
int64_t size;
19
bool setting_flag)
20
{
21
- BdrvChild *child;
22
+ BdrvChild *child, *parent;
23
int ret;
47
int ret;
24
48
25
if (!setting_flag && bs->drv->bdrv_inactivate) {
49
- ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, &local_err);
26
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
50
+ ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
27
51
+ &local_err);
28
if (setting_flag) {
52
if (ret < 0 && ret != -ENOTSUP) {
29
bs->open_flags |= BDRV_O_INACTIVE;
53
error_propagate(errp, local_err);
30
+
54
return ret;
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
55
diff --git a/block/block-backend.c b/block/block-backend.c
44
index XXXXXXX..XXXXXXX 100644
56
index XXXXXXX..XXXXXXX 100644
45
--- a/block/block-backend.c
57
--- a/block/block-backend.c
46
+++ b/block/block-backend.c
58
+++ b/block/block-backend.c
47
@@ -XXX,XX +XXX,XX @@ static void blk_root_activate(BdrvChild *child, Error **errp)
59
@@ -XXX,XX +XXX,XX @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
48
}
49
}
60
}
50
61
51
+static int blk_root_inactivate(BdrvChild *child)
62
int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
52
+{
63
- PreallocMode prealloc, Error **errp)
53
+ BlockBackend *blk = child->opaque;
64
+ PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
54
+
65
{
55
+ if (blk->disable_perm) {
66
if (!blk_is_available(blk)) {
56
+ return 0;
67
error_setg(errp, "No medium inserted");
57
+ }
68
return -ENOMEDIUM;
58
+
69
}
59
+ /* Only inactivate BlockBackends for guest devices (which are inactive at
70
60
+ * this point because the VM is stopped) and unattached monitor-owned
71
- return bdrv_truncate(blk->root, offset, exact, prealloc, 0, errp);
61
+ * BlockBackends. If there is still any other user like a block job, then
72
+ return bdrv_truncate(blk->root, offset, exact, prealloc, flags, errp);
62
+ * we simply can't inactivate the image. */
73
}
63
+ if (!blk->dev && !blk->name[0]) {
74
64
+ return -EPERM;
75
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
65
+ }
76
diff --git a/block/commit.c b/block/commit.c
66
+
77
index XXXXXXX..XXXXXXX 100644
67
+ blk->disable_perm = true;
78
--- a/block/commit.c
68
+ if (blk->root) {
79
+++ b/block/commit.c
69
+ bdrv_child_try_set_perm(blk->root, 0, BLK_PERM_ALL, &error_abort);
80
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn commit_run(Job *job, Error **errp)
70
+ }
81
}
71
+
82
72
+ return 0;
83
if (base_len < len) {
73
+}
84
- ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, NULL);
74
+
85
+ ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL);
75
static const BdrvChildRole child_root = {
86
if (ret) {
76
.inherit_options = blk_root_inherit_options,
87
goto out;
77
88
}
78
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
89
@@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs)
79
.drained_end = blk_root_drained_end,
90
* grow the backing file image if possible. If not possible,
80
91
* we must return an error */
81
.activate = blk_root_activate,
92
if (length > backing_length) {
82
+ .inactivate = blk_root_inactivate,
93
- ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF,
83
};
94
+ ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF, 0,
84
95
&local_err);
85
/*
96
if (ret < 0) {
86
diff --git a/include/block/block_int.h b/include/block/block_int.h
97
error_report_err(local_err);
87
index XXXXXXX..XXXXXXX 100644
98
diff --git a/block/crypto.c b/block/crypto.c
88
--- a/include/block/block_int.h
99
index XXXXXXX..XXXXXXX 100644
89
+++ b/include/block/block_int.h
100
--- a/block/crypto.c
90
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
101
+++ b/block/crypto.c
91
void (*drained_begin)(BdrvChild *child);
102
@@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
92
void (*drained_end)(BdrvChild *child);
103
* which will be used by the crypto header
93
104
*/
94
- /* Notifies the parent that the child has been activated (e.g. when
105
return blk_truncate(data->blk, data->size + headerlen, false,
95
- * migration is completing) and it can start requesting permissions and
106
- data->prealloc, errp);
96
- * doing I/O on it. */
107
+ data->prealloc, 0, errp);
97
+ /* Notifies the parent that the child has been activated/inactivated (e.g.
108
}
98
+ * when migration is completing) and it can start/stop requesting
109
99
+ * permissions and doing I/O on it. */
110
100
void (*activate)(BdrvChild *child, Error **errp);
111
diff --git a/block/mirror.c b/block/mirror.c
101
+ int (*inactivate)(BdrvChild *child);
112
index XXXXXXX..XXXXXXX 100644
102
113
--- a/block/mirror.c
103
void (*attach)(BdrvChild *child);
114
+++ b/block/mirror.c
104
void (*detach)(BdrvChild *child);
115
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
116
117
if (s->bdev_length > base_length) {
118
ret = blk_truncate(s->target, s->bdev_length, false,
119
- PREALLOC_MODE_OFF, NULL);
120
+ PREALLOC_MODE_OFF, 0, NULL);
121
if (ret < 0) {
122
goto immediate_exit;
123
}
124
diff --git a/block/qcow2.c b/block/qcow2.c
125
index XXXXXXX..XXXXXXX 100644
126
--- a/block/qcow2.c
127
+++ b/block/qcow2.c
128
@@ -XXX,XX +XXX,XX @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
129
130
/* Okay, now that we have a valid image, let's give it the right size */
131
ret = blk_truncate(blk, qcow2_opts->size, false, qcow2_opts->preallocation,
132
- errp);
133
+ 0, errp);
134
if (ret < 0) {
135
error_prepend(errp, "Could not resize image: ");
136
goto out;
137
@@ -XXX,XX +XXX,XX @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
138
* Amending image options should ensure that the image has
139
* exactly the given new values, so pass exact=true here.
140
*/
141
- ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, errp);
142
+ ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, 0, errp);
143
blk_unref(blk);
144
if (ret < 0) {
145
return ret;
146
diff --git a/block/qed.c b/block/qed.c
147
index XXXXXXX..XXXXXXX 100644
148
--- a/block/qed.c
149
+++ b/block/qed.c
150
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
151
* The QED format associates file length with allocation status,
152
* so a new file (which is empty) must have a length of 0.
153
*/
154
- ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, errp);
155
+ ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, 0, errp);
156
if (ret < 0) {
157
goto out;
158
}
159
diff --git a/block/vdi.c b/block/vdi.c
160
index XXXXXXX..XXXXXXX 100644
161
--- a/block/vdi.c
162
+++ b/block/vdi.c
163
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
164
165
if (image_type == VDI_TYPE_STATIC) {
166
ret = blk_truncate(blk, offset + blocks * block_size, false,
167
- PREALLOC_MODE_OFF, errp);
168
+ PREALLOC_MODE_OFF, 0, errp);
169
if (ret < 0) {
170
error_prepend(errp, "Failed to statically allocate file");
171
goto exit;
172
diff --git a/block/vhdx.c b/block/vhdx.c
173
index XXXXXXX..XXXXXXX 100644
174
--- a/block/vhdx.c
175
+++ b/block/vhdx.c
176
@@ -XXX,XX +XXX,XX @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
177
/* All zeroes, so we can just extend the file - the end of the BAT
178
* is the furthest thing we have written yet */
179
ret = blk_truncate(blk, data_file_offset, false, PREALLOC_MODE_OFF,
180
- errp);
181
+ 0, errp);
182
if (ret < 0) {
183
goto exit;
184
}
185
} else if (type == VHDX_TYPE_FIXED) {
186
ret = blk_truncate(blk, data_file_offset + image_size, false,
187
- PREALLOC_MODE_OFF, errp);
188
+ PREALLOC_MODE_OFF, 0, errp);
189
if (ret < 0) {
190
goto exit;
191
}
192
diff --git a/block/vmdk.c b/block/vmdk.c
193
index XXXXXXX..XXXXXXX 100644
194
--- a/block/vmdk.c
195
+++ b/block/vmdk.c
196
@@ -XXX,XX +XXX,XX @@ static int vmdk_init_extent(BlockBackend *blk,
197
int gd_buf_size;
198
199
if (flat) {
200
- ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, errp);
201
+ ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
202
goto exit;
203
}
204
magic = cpu_to_be32(VMDK4_MAGIC);
205
@@ -XXX,XX +XXX,XX @@ static int vmdk_init_extent(BlockBackend *blk,
206
}
207
208
ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
209
- PREALLOC_MODE_OFF, errp);
210
+ PREALLOC_MODE_OFF, 0, errp);
211
if (ret < 0) {
212
goto exit;
213
}
214
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
215
/* bdrv_pwrite write padding zeros to align to sector, we don't need that
216
* for description file */
217
if (desc_offset == 0) {
218
- ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, errp);
219
+ ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, 0, errp);
220
if (ret < 0) {
221
goto exit;
222
}
223
diff --git a/block/vpc.c b/block/vpc.c
224
index XXXXXXX..XXXXXXX 100644
225
--- a/block/vpc.c
226
+++ b/block/vpc.c
227
@@ -XXX,XX +XXX,XX @@ static int create_fixed_disk(BlockBackend *blk, uint8_t *buf,
228
/* Add footer to total size */
229
total_size += HEADER_SIZE;
230
231
- ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, errp);
232
+ ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp);
233
if (ret < 0) {
234
return ret;
235
}
236
diff --git a/blockdev.c b/blockdev.c
237
index XXXXXXX..XXXXXXX 100644
238
--- a/blockdev.c
239
+++ b/blockdev.c
240
@@ -XXX,XX +XXX,XX @@ void qmp_block_resize(bool has_device, const char *device,
241
}
242
243
bdrv_drained_begin(bs);
244
- ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp);
245
+ ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, 0, errp);
246
bdrv_drained_end(bs);
247
248
out:
249
diff --git a/qemu-img.c b/qemu-img.c
250
index XXXXXXX..XXXXXXX 100644
251
--- a/qemu-img.c
252
+++ b/qemu-img.c
253
@@ -XXX,XX +XXX,XX @@ static int img_resize(int argc, char **argv)
254
* resizing, so pass @exact=true. It is of no use to report
255
* success when the image has not actually been resized.
256
*/
257
- ret = blk_truncate(blk, total_size, true, prealloc, &err);
258
+ ret = blk_truncate(blk, total_size, true, prealloc, 0, &err);
259
if (!ret) {
260
qprintf(quiet, "Image resized.\n");
261
} else {
262
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
263
index XXXXXXX..XXXXXXX 100644
264
--- a/qemu-io-cmds.c
265
+++ b/qemu-io-cmds.c
266
@@ -XXX,XX +XXX,XX @@ static int truncate_f(BlockBackend *blk, int argc, char **argv)
267
* exact=true. It is better to err on the "emit more errors" side
268
* than to be overly permissive.
269
*/
270
- ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, &local_err);
271
+ ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, 0, &local_err);
272
if (ret < 0) {
273
error_report_err(local_err);
274
return ret;
105
--
275
--
106
1.8.3.1
276
2.25.3
107
277
108
278
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
If BDRV_REQ_ZERO_WRITE is set and we're extending the image, calling
2
qcow2_cluster_zeroize() with flags=0 does the right thing: It doesn't
3
undo any previous preallocation, but just adds the zero flag to all
4
relevant L2 entries. If an external data file is in use, a write_zeroes
5
request to the data file is made instead.
2
6
3
Passing a byte offset, but sector count, when we ultimately
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
want to operate on cluster granularity, is madness. Clean up
8
Message-Id: <20200424125448.63318-5-kwolf@redhat.com>
5
the external interfaces to take both offset and count as bytes,
9
Reviewed-by: Eric Blake <eblake@redhat.com>
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
12
The internal functions still operate on clusters at a time, and
13
return an int for number of cleared clusters; but on an image
14
with 2M clusters, a single L2 table holds 256k entries that each
15
represent a 2M cluster, totalling well over INT_MAX bytes if we
16
ever had a request for that many bytes at once. All our callers
17
currently limit themselves to 32-bit bytes (and therefore fewer
18
clusters), but by making this function 64-bit clean, we have one
19
less place to clean up if we later improve the block layer to
20
support 64-bit bytes through all operations (with the block layer
21
auto-fragmenting on behalf of more-limited drivers), rather than
22
the current state where some interfaces are artificially limited
23
to INT_MAX at a time.
24
25
Signed-off-by: Eric Blake <eblake@redhat.com>
26
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
27
Message-id: 20170507000552.20847-13-eblake@redhat.com
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
28
Signed-off-by: Max Reitz <mreitz@redhat.com>
29
---
12
---
30
block/qcow2-cluster.c | 42 ++++++++++++++++++++++--------------------
13
block/qcow2-cluster.c | 2 +-
31
block/qcow2-snapshot.c | 7 +++----
14
block/qcow2.c | 34 ++++++++++++++++++++++++++++++++++
32
block/qcow2.c | 22 +++++++++-------------
15
2 files changed, 35 insertions(+), 1 deletion(-)
33
block/qcow2.h | 9 +++++----
34
4 files changed, 39 insertions(+), 41 deletions(-)
35
16
36
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
37
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
38
--- a/block/qcow2-cluster.c
19
--- a/block/qcow2-cluster.c
39
+++ b/block/qcow2-cluster.c
20
+++ b/block/qcow2-cluster.c
40
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
@@ -XXX,XX +XXX,XX @@ int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
41
return nb_clusters;
42
}
43
44
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
45
- int nb_sectors, enum qcow2_discard_type type, bool full_discard)
46
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
47
+ uint64_t bytes, enum qcow2_discard_type type,
48
+ bool full_discard)
49
{
50
BDRVQcow2State *s = bs->opaque;
51
- uint64_t end_offset;
52
+ uint64_t end_offset = offset + bytes;
53
uint64_t nb_clusters;
54
+ int64_t cleared;
55
int ret;
56
57
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
58
-
59
/* Caller must pass aligned values, except at image end */
22
/* Caller must pass aligned values, except at image end */
60
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
23
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
61
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
24
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
62
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
25
- end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
63
26
+ end_offset >= bs->total_sectors << BDRV_SECTOR_BITS);
64
- nb_clusters = size_to_clusters(s, end_offset - offset);
27
65
+ nb_clusters = size_to_clusters(s, bytes);
28
/* The zero flag is only supported by version 3 and newer */
66
29
if (s->qcow_version < 3) {
67
s->cache_discards = true;
68
69
/* Each L2 table is handled by its own loop iteration */
70
while (nb_clusters > 0) {
71
- ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);
72
- if (ret < 0) {
73
+ cleared = discard_single_l2(bs, offset, nb_clusters, type,
74
+ full_discard);
75
+ if (cleared < 0) {
76
+ ret = cleared;
77
goto fail;
78
}
79
80
- nb_clusters -= ret;
81
- offset += (ret * s->cluster_size);
82
+ nb_clusters -= cleared;
83
+ offset += (cleared * s->cluster_size);
84
}
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
30
diff --git a/block/qcow2.c b/block/qcow2.c
152
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
153
--- a/block/qcow2.c
32
--- a/block/qcow2.c
154
+++ b/block/qcow2.c
33
+++ b/block/qcow2.c
155
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
34
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
156
trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count);
35
157
36
bs->supported_zero_flags = header.version >= 3 ?
158
/* Whatever is left can use real zero clusters */
37
BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK : 0;
159
- ret = qcow2_zero_clusters(bs, offset, count >> BDRV_SECTOR_BITS, flags);
38
+ bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
160
+ ret = qcow2_cluster_zeroize(bs, offset, count, flags);
39
161
qemu_co_mutex_unlock(&s->lock);
40
/* Repair image if dirty */
162
41
if (!(flags & (BDRV_O_CHECK | BDRV_O_INACTIVE)) && !bs->read_only &&
163
return ret;
42
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
164
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
43
g_assert_not_reached();
165
}
44
}
166
45
167
qemu_co_mutex_lock(&s->lock);
46
+ if ((flags & BDRV_REQ_ZERO_WRITE) && offset > old_length) {
168
- ret = qcow2_discard_clusters(bs, offset, count >> BDRV_SECTOR_BITS,
47
+ uint64_t zero_start = QEMU_ALIGN_UP(old_length, s->cluster_size);
169
- QCOW2_DISCARD_REQUEST, false);
48
+
170
+ ret = qcow2_cluster_discard(bs, offset, count, QCOW2_DISCARD_REQUEST,
49
+ /*
171
+ false);
50
+ * Use zero clusters as much as we can. qcow2_cluster_zeroize()
172
qemu_co_mutex_unlock(&s->lock);
51
+ * requires a cluster-aligned start. The end may be unaligned if it is
173
return ret;
52
+ * at the end of the image (which it is here).
174
}
53
+ */
175
@@ -XXX,XX +XXX,XX @@ fail:
54
+ ret = qcow2_cluster_zeroize(bs, zero_start, offset - zero_start, 0);
176
static int qcow2_make_empty(BlockDriverState *bs)
55
+ if (ret < 0) {
177
{
56
+ error_setg_errno(errp, -ret, "Failed to zero out new clusters");
178
BDRVQcow2State *s = bs->opaque;
57
+ goto fail;
179
- uint64_t start_sector;
58
+ }
180
- int sector_step = (QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size) /
59
+
181
- BDRV_SECTOR_SIZE);
60
+ /* Write explicit zeros for the unaligned head */
182
+ uint64_t offset, end_offset;
61
+ if (zero_start > old_length) {
183
+ int step = QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size);
62
+ uint64_t len = zero_start - old_length;
184
int l1_clusters, ret = 0;
63
+ uint8_t *buf = qemu_blockalign0(bs, len);
185
64
+ QEMUIOVector qiov;
186
l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
65
+ qemu_iovec_init_buf(&qiov, buf, len);
187
@@ -XXX,XX +XXX,XX @@ static int qcow2_make_empty(BlockDriverState *bs)
66
+
188
67
+ qemu_co_mutex_unlock(&s->lock);
189
/* This fallback code simply discards every active cluster; this is slow,
68
+ ret = qcow2_co_pwritev_part(bs, old_length, len, &qiov, 0, 0);
190
* but works in all cases */
69
+ qemu_co_mutex_lock(&s->lock);
191
- for (start_sector = 0; start_sector < bs->total_sectors;
70
+
192
- start_sector += sector_step)
71
+ qemu_vfree(buf);
193
- {
72
+ if (ret < 0) {
194
+ end_offset = bs->total_sectors * BDRV_SECTOR_SIZE;
73
+ error_setg_errno(errp, -ret, "Failed to zero out the new area");
195
+ for (offset = 0; offset < end_offset; offset += step) {
74
+ goto fail;
196
/* As this function is generally used after committing an external
75
+ }
197
* snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
76
+ }
198
* default action for this kind of discard is to pass the discard,
77
+ }
199
* which will ideally result in an actually smaller image file, as
78
+
200
* is probably desired. */
79
if (prealloc != PREALLOC_MODE_OFF) {
201
- ret = qcow2_discard_clusters(bs, start_sector * BDRV_SECTOR_SIZE,
80
/* Flush metadata before actually changing the image size */
202
- MIN(sector_step,
81
ret = qcow2_write_caches(bs);
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
--
82
--
231
1.8.3.1
83
2.25.3
232
84
233
85
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
The raw format driver can simply forward the flag and let its bs->file
2
child take care of actually providing the zeros.
2
3
3
It can be used outside of block.c for making user friendly messages.
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
5
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Message-Id: <20200424125448.63318-6-kwolf@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
10
---
8
block.c | 2 +-
11
block/raw-format.c | 4 +++-
9
include/block/block.h | 2 ++
12
1 file changed, 3 insertions(+), 1 deletion(-)
10
2 files changed, 3 insertions(+), 1 deletion(-)
11
13
12
diff --git a/block.c b/block.c
14
diff --git a/block/raw-format.c b/block/raw-format.c
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
16
--- a/block/raw-format.c
15
+++ b/block.c
17
+++ b/block/raw-format.c
16
@@ -XXX,XX +XXX,XX @@ static char *bdrv_child_user_desc(BdrvChild *c)
18
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
17
return g_strdup("another user");
19
20
s->size = offset;
21
offset += s->offset;
22
- return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp);
23
+ return bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
18
}
24
}
19
25
20
-static char *bdrv_perm_names(uint64_t perm)
26
static void raw_eject(BlockDriverState *bs, bool eject_flag)
21
+char *bdrv_perm_names(uint64_t perm)
27
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
22
{
28
bs->supported_zero_flags = BDRV_REQ_WRITE_UNCHANGED |
23
struct perm_name {
29
((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) &
24
uint64_t perm;
30
bs->file->bs->supported_zero_flags);
25
diff --git a/include/block/block.h b/include/block/block.h
31
+ bs->supported_truncate_flags = bs->file->bs->supported_truncate_flags &
26
index XXXXXXX..XXXXXXX 100644
32
+ BDRV_REQ_ZERO_WRITE;
27
--- a/include/block/block.h
33
28
+++ b/include/block/block.h
34
if (bs->probed && !bdrv_is_read_only(bs)) {
29
@@ -XXX,XX +XXX,XX @@ enum {
35
bdrv_refresh_filename(bs->file->bs);
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
--
36
--
39
1.8.3.1
37
2.25.3
40
38
41
39
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
1
From: Fam Zheng <famz@redhat.com>
1
For regular files, we always get BDRV_REQ_ZERO_WRITE behaviour from the
2
OS, so we can advertise the flag and just ignore it.
2
3
3
Making this option available even before implementing it will let
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4
converting tests easier: in coming patches they can specify the option
5
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
5
already when necessary, before we actually write code to lock the
6
Reviewed-by: Alberto Garcia <berto@igalia.com>
6
images.
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
8
Message-Id: <20200424125448.63318-7-kwolf@redhat.com>
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
10
---
11
block/file-posix.c | 5 +++++
11
block/file-posix.c | 4 ++++
12
qapi/block-core.json | 4 ++++
12
1 file changed, 4 insertions(+)
13
2 files changed, 9 insertions(+)
14
13
15
diff --git a/block/file-posix.c b/block/file-posix.c
14
diff --git a/block/file-posix.c b/block/file-posix.c
16
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
17
--- a/block/file-posix.c
16
--- a/block/file-posix.c
18
+++ b/block/file-posix.c
17
+++ b/block/file-posix.c
19
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_runtime_opts = {
18
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
20
.type = QEMU_OPT_STRING,
19
#endif
21
.help = "host AIO implementation (threads, native)",
20
22
},
21
bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK;
23
+ {
22
+ if (S_ISREG(st.st_mode)) {
24
+ .name = "locking",
23
+ /* When extending regular files, we get zeros from the OS */
25
+ .type = QEMU_OPT_STRING,
24
+ bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
26
+ .help = "file locking mode (on/off/auto, default: auto)",
25
+ }
27
+ },
26
ret = 0;
28
{ /* end of list */ }
27
fail:
29
},
28
if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
30
};
31
diff --git a/qapi/block-core.json b/qapi/block-core.json
32
index XXXXXXX..XXXXXXX 100644
33
--- a/qapi/block-core.json
34
+++ b/qapi/block-core.json
35
@@ -XXX,XX +XXX,XX @@
36
#
37
# @filename: path to the image file
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
#
43
# Since: 2.9
44
##
45
{ 'struct': 'BlockdevOptionsFile',
46
'data': { 'filename': 'str',
47
+ '*locking': 'OnOffAuto',
48
'*aio': 'BlockdevAioOptions' } }
49
50
##
51
--
29
--
52
1.8.3.1
30
2.25.3
53
31
54
32
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
When extending the size of an image that has a backing file larger than
2
its old size, make sure that the backing file data doesn't become
3
visible in the guest, but the added area is properly zeroed out.
2
4
3
This will force the opened images to allow sharing all permissions with other
5
Consider the following scenario where the overlay is shorter than its
4
programs.
6
backing file:
5
7
6
Signed-off-by: Fam Zheng <famz@redhat.com>
8
base.qcow2: AAAAAAAA
9
overlay.qcow2: BBBB
10
11
When resizing (extending) overlay.qcow2, the new blocks should not stay
12
unallocated and make the additional As from base.qcow2 visible like
13
before this patch, but zeros should be read.
14
15
A similar case happens with the various variants of a commit job when an
16
intermediate file is short (- for unallocated):
17
18
base.qcow2: A-A-AAAA
19
mid.qcow2: BB-B
20
top.qcow2: C--C--C-
21
22
After commit top.qcow2 to mid.qcow2, the following happens:
23
24
mid.qcow2: CB-C00C0 (correct result)
25
mid.qcow2: CB-C--C- (before this fix)
26
27
Without the fix, blocks that previously read as zeros on top.qcow2
28
suddenly turn into A.
29
30
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
31
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
32
Message-Id: <20200424125448.63318-8-kwolf@redhat.com>
33
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
35
---
9
qemu-img.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++---------------
36
block/io.c | 25 +++++++++++++++++++++++++
10
1 file changed, 117 insertions(+), 36 deletions(-)
37
1 file changed, 25 insertions(+)
11
38
12
diff --git a/qemu-img.c b/qemu-img.c
39
diff --git a/block/io.c b/block/io.c
13
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
14
--- a/qemu-img.c
41
--- a/block/io.c
15
+++ b/qemu-img.c
42
+++ b/block/io.c
16
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
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;
44
goto out;
461
}
45
}
462
46
463
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
47
+ /*
464
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
48
+ * If the image has a backing file that is large enough that it would
465
+ false);
49
+ * provide data for the new area, we cannot leave it unallocated because
466
if (!blk) {
50
+ * then the backing file content would become visible. Instead, zero-fill
467
ret = -1;
51
+ * the new area.
468
goto out;
52
+ *
469
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
53
+ * Note that if the image has a backing file, but was opened without the
470
bool writethrough = false;
54
+ * backing file, taking care of keeping things consistent with that backing
471
struct timeval t1, t2;
55
+ * file is the user's responsibility.
472
int i;
56
+ */
473
+ bool force_share = false;
57
+ if (new_bytes && bs->backing) {
474
58
+ int64_t backing_len;
475
for (;;) {
59
+
476
static const struct option long_options[] = {
60
+ backing_len = bdrv_getlength(backing_bs(bs));
477
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
61
+ if (backing_len < 0) {
478
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
62
+ ret = backing_len;
479
{"pattern", required_argument, 0, OPTION_PATTERN},
63
+ error_setg_errno(errp, -ret, "Could not get backing file size");
480
{"no-drain", no_argument, 0, OPTION_NO_DRAIN},
64
+ goto out;
481
+ {"force-share", no_argument, 0, 'U'},
65
+ }
482
{0, 0, 0, 0}
66
+
483
};
67
+ if (backing_len > old_size) {
484
- c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options, NULL);
68
+ flags |= BDRV_REQ_ZERO_WRITE;
485
+ c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:wU", long_options, NULL);
69
+ }
486
if (c == -1) {
70
+ }
487
break;
71
+
488
}
72
if (drv->bdrv_co_truncate) {
489
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
73
if (flags & ~bs->supported_truncate_flags) {
490
flags |= BDRV_O_RDWR;
74
error_setg(errp, "Block driver does not support requested flags");
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
--
75
--
560
1.8.3.1
76
2.25.3
561
77
562
78
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
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Double attach is not a valid usage of the target image, drive-backup
4
will open the blockdev itself so skip the add_drive call in this case.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
tests/qemu-iotests/055 | 32 ++++++++++++++++++--------------
11
1 file changed, 18 insertions(+), 14 deletions(-)
12
13
diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
14
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/055
16
+++ b/tests/qemu-iotests/055
17
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
18
except OSError:
19
pass
20
21
- def do_prepare_drives(self, fmt, args):
22
+ def do_prepare_drives(self, fmt, args, attach_target):
23
self.vm = iotests.VM().add_drive(test_img)
24
25
qemu_img('create', '-f', fmt, blockdev_target_img,
26
str(TestDriveCompression.image_len), *args)
27
- self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
28
+ if attach_target:
29
+ self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
30
31
self.vm.launch()
32
33
- def do_test_compress_complete(self, cmd, format, **args):
34
- self.do_prepare_drives(format['type'], format['args'])
35
+ def do_test_compress_complete(self, cmd, format, attach_target, **args):
36
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
37
38
self.assert_no_active_block_jobs()
39
40
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
41
42
def test_complete_compress_drive_backup(self):
43
for format in TestDriveCompression.fmt_supports_compression:
44
- self.do_test_compress_complete('drive-backup', format,
45
+ self.do_test_compress_complete('drive-backup', format, False,
46
target=blockdev_target_img, mode='existing')
47
48
def test_complete_compress_blockdev_backup(self):
49
for format in TestDriveCompression.fmt_supports_compression:
50
- self.do_test_compress_complete('blockdev-backup', format, target='drive1')
51
+ self.do_test_compress_complete('blockdev-backup', format, True,
52
+ target='drive1')
53
54
- def do_test_compress_cancel(self, cmd, format, **args):
55
- self.do_prepare_drives(format['type'], format['args'])
56
+ def do_test_compress_cancel(self, cmd, format, attach_target, **args):
57
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
58
59
self.assert_no_active_block_jobs()
60
61
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
62
63
def test_compress_cancel_drive_backup(self):
64
for format in TestDriveCompression.fmt_supports_compression:
65
- self.do_test_compress_cancel('drive-backup', format,
66
+ self.do_test_compress_cancel('drive-backup', format, False,
67
target=blockdev_target_img, mode='existing')
68
69
def test_compress_cancel_blockdev_backup(self):
70
for format in TestDriveCompression.fmt_supports_compression:
71
- self.do_test_compress_cancel('blockdev-backup', format, target='drive1')
72
+ self.do_test_compress_cancel('blockdev-backup', format, True,
73
+ target='drive1')
74
75
- def do_test_compress_pause(self, cmd, format, **args):
76
- self.do_prepare_drives(format['type'], format['args'])
77
+ def do_test_compress_pause(self, cmd, format, attach_target, **args):
78
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
79
80
self.assert_no_active_block_jobs()
81
82
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
83
84
def test_compress_pause_drive_backup(self):
85
for format in TestDriveCompression.fmt_supports_compression:
86
- self.do_test_compress_pause('drive-backup', format,
87
+ self.do_test_compress_pause('drive-backup', format, False,
88
target=blockdev_target_img, mode='existing')
89
90
def test_compress_pause_blockdev_backup(self):
91
for format in TestDriveCompression.fmt_supports_compression:
92
- self.do_test_compress_pause('blockdev-backup', format, target='drive1')
93
+ self.do_test_compress_pause('blockdev-backup', format, True,
94
+ target='drive1')
95
96
if __name__ == '__main__':
97
iotests.main(supported_fmts=['raw', 'qcow2'])
98
--
99
1.8.3.1
100
101
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
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
1
From: Fam Zheng <famz@redhat.com>
1
We want to keep TEST_IMG for the full path of the main test image, but
2
filter_testfiles() must be called for other test images before replacing
3
other things like the image format because the test directory path could
4
contain the format as a substring.
2
5
3
The test scenario doesn't require the same image, instead it focuses on
6
Insert a filter_testfiles() call between both.
4
the duplicated node-name, so use null-co to avoid locking conflict.
5
7
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Fam Zheng <famz@redhat.com>
10
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11
Message-Id: <20200424125448.63318-9-kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
13
---
10
tests/qemu-iotests/087 | 6 ++----
14
tests/qemu-iotests/iotests.py | 5 +++--
11
1 file changed, 2 insertions(+), 4 deletions(-)
15
1 file changed, 3 insertions(+), 2 deletions(-)
12
16
13
diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087
17
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
14
index XXXXXXX..XXXXXXX 100755
18
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/qemu-iotests/087
19
--- a/tests/qemu-iotests/iotests.py
16
+++ b/tests/qemu-iotests/087
20
+++ b/tests/qemu-iotests/iotests.py
17
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
21
@@ -XXX,XX +XXX,XX @@ def filter_img_info(output, filename):
18
"driver": "$IMGFMT",
22
for line in output.split('\n'):
19
"node-name": "disk",
23
if 'disk size' in line or 'actual-size' in line:
20
"file": {
24
continue
21
- "driver": "file",
25
- line = line.replace(filename, 'TEST_IMG') \
22
- "filename": "$TEST_IMG"
26
- .replace(imgfmt, 'IMGFMT')
23
+ "driver": "null-co"
27
+ line = line.replace(filename, 'TEST_IMG')
24
}
28
+ line = filter_testfiles(line)
25
}
29
+ line = line.replace(imgfmt, 'IMGFMT')
26
}
30
line = re.sub('iters: [0-9]+', 'iters: XXX', line)
27
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
31
line = re.sub('uuid: [-a-f0-9]+', 'uuid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', line)
28
"driver": "$IMGFMT",
32
line = re.sub('cid: [0-9]+', 'cid: XXXXXXXXXX', line)
29
"node-name": "test-node",
30
"file": {
31
- "driver": "file",
32
- "filename": "$TEST_IMG"
33
+ "driver": "null-co"
34
}
35
}
36
}
37
--
33
--
38
1.8.3.1
34
2.25.3
39
35
40
36
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
To avoid image lock failures.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
tests/qemu-iotests/172 | 55 +++++++++++++++++++++++++---------------------
9
tests/qemu-iotests/172.out | 50 +++++++++++++++++++++--------------------
10
2 files changed, 56 insertions(+), 49 deletions(-)
11
12
diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/172
15
+++ b/tests/qemu-iotests/172
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
17
_cleanup()
18
{
19
    _cleanup_test_img
20
+ rm -f "$TEST_IMG.2"
21
+ rm -f "$TEST_IMG.3"
22
}
23
trap "_cleanup; exit \$status" 0 1 2 3 15
24
25
@@ -XXX,XX +XXX,XX @@ size=720k
26
27
_make_test_img $size
28
29
+TEST_IMG="$TEST_IMG.2" _make_test_img $size
30
+TEST_IMG="$TEST_IMG.3" _make_test_img $size
31
+
32
# Default drive semantics:
33
#
34
# By default you get a single empty floppy drive. You can override it with
35
@@ -XXX,XX +XXX,XX @@ echo === Using -fda/-fdb options ===
36
37
check_floppy_qtree -fda "$TEST_IMG"
38
check_floppy_qtree -fdb "$TEST_IMG"
39
-check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG"
40
+check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
41
42
43
echo
44
@@ -XXX,XX +XXX,XX @@ echo === Using -drive options ===
45
46
check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
47
check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
48
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG",index=1
49
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
50
51
echo
52
echo
53
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -global ===
54
55
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
56
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
57
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
58
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
59
-global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
60
61
echo
62
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -device ===
63
64
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
65
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
66
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
67
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
68
-device floppy,drive=none0 -device floppy,drive=none1,unit=1
69
70
echo
71
@@ -XXX,XX +XXX,XX @@ echo
72
echo === Mixing -fdX and -global ===
73
74
# Working
75
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
76
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
77
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
78
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
79
80
# Conflicting (-fdX wins)
81
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
82
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
83
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
84
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
85
86
echo
87
echo
88
echo === Mixing -fdX and -device ===
89
90
# Working
91
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
92
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
93
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
94
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
95
96
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
97
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
98
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
99
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
100
101
# Conflicting
102
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
103
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
104
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
105
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
106
107
echo
108
echo
109
echo === Mixing -drive and -device ===
110
111
# Working
112
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
113
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
114
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
115
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
116
117
# Conflicting
118
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
119
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
120
121
echo
122
echo
123
echo === Mixing -global and -device ===
124
125
# Working
126
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
127
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
128
-global isa-fdc.driveA=none0 -device floppy,drive=none1
129
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
130
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
131
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
132
133
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
134
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
135
-global isa-fdc.driveB=none0 -device floppy,drive=none1
136
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
137
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
138
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
139
140
# Conflicting
141
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
142
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
143
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
144
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
145
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
146
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
147
148
echo
149
@@ -XXX,XX +XXX,XX @@ echo === Too many floppy drives ===
150
151
# Working
152
check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
153
- -drive if=none,file="$TEST_IMG" \
154
- -drive if=none,file="$TEST_IMG" \
155
+ -drive if=none,file="$TEST_IMG.2" \
156
+ -drive if=none,file="$TEST_IMG.3" \
157
-global isa-fdc.driveB=none0 \
158
-device floppy,drive=none1
159
160
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
161
index XXXXXXX..XXXXXXX 100644
162
--- a/tests/qemu-iotests/172.out
163
+++ b/tests/qemu-iotests/172.out
164
@@ -XXX,XX +XXX,XX @@
165
QA output created by 172
166
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=737280
167
+Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=737280
168
+Formatting 'TEST_DIR/t.IMGFMT.3', fmt=IMGFMT size=737280
169
170
171
=== Default ===
172
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
173
share-rw = false
174
drive-type = "288"
175
176
-Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2
177
+Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
178
179
dev: isa-fdc, id ""
180
iobase = 1008 (0x3f0)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
182
share-rw = false
183
drive-type = "288"
184
185
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
186
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2.2,index=1
187
188
dev: isa-fdc, id ""
189
iobase = 1008 (0x3f0)
190
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
191
share-rw = false
192
drive-type = "144"
193
194
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
195
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
196
197
dev: isa-fdc, id ""
198
iobase = 1008 (0x3f0)
199
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
200
share-rw = false
201
drive-type = "144"
202
203
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
204
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
205
206
dev: isa-fdc, id ""
207
iobase = 1008 (0x3f0)
208
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
209
210
=== Mixing -fdX and -global ===
211
212
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
213
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
214
215
dev: isa-fdc, id ""
216
iobase = 1008 (0x3f0)
217
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
218
share-rw = false
219
drive-type = "144"
220
221
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
222
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
223
224
dev: isa-fdc, id ""
225
iobase = 1008 (0x3f0)
226
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
227
share-rw = false
228
drive-type = "144"
229
230
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
231
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
232
233
dev: isa-fdc, id ""
234
iobase = 1008 (0x3f0)
235
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
236
share-rw = false
237
drive-type = "144"
238
239
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
240
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
241
242
dev: isa-fdc, id ""
243
iobase = 1008 (0x3f0)
244
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
245
246
=== Mixing -fdX and -device ===
247
248
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
249
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
250
251
dev: isa-fdc, id ""
252
iobase = 1008 (0x3f0)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
254
share-rw = false
255
drive-type = "144"
256
257
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
258
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
259
260
dev: isa-fdc, id ""
261
iobase = 1008 (0x3f0)
262
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
263
share-rw = false
264
drive-type = "144"
265
266
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
267
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
268
269
dev: isa-fdc, id ""
270
iobase = 1008 (0x3f0)
271
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
272
share-rw = false
273
drive-type = "144"
274
275
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
276
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
277
278
dev: isa-fdc, id ""
279
iobase = 1008 (0x3f0)
280
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
281
share-rw = false
282
drive-type = "144"
283
284
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
285
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
286
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
287
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
288
289
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
290
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
291
QEMU_PROG: -device floppy,drive=none0,unit=1: Floppy unit 1 is in use
292
QEMU_PROG: -device floppy,drive=none0,unit=1: Device initialization failed.
293
294
295
=== Mixing -drive and -device ===
296
297
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
298
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
299
300
dev: isa-fdc, id ""
301
iobase = 1008 (0x3f0)
302
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
303
share-rw = false
304
drive-type = "144"
305
306
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
307
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
308
309
dev: isa-fdc, id ""
310
iobase = 1008 (0x3f0)
311
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
312
share-rw = false
313
drive-type = "144"
314
315
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
316
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
317
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
318
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
319
320
321
=== Mixing -global and -device ===
322
323
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
324
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
325
326
dev: isa-fdc, id ""
327
iobase = 1008 (0x3f0)
328
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
329
share-rw = false
330
drive-type = "144"
331
332
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
333
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
334
335
dev: isa-fdc, id ""
336
iobase = 1008 (0x3f0)
337
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
338
share-rw = false
339
drive-type = "144"
340
341
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
342
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
343
344
dev: isa-fdc, id ""
345
iobase = 1008 (0x3f0)
346
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
347
share-rw = false
348
drive-type = "144"
349
350
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
351
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
352
353
dev: isa-fdc, id ""
354
iobase = 1008 (0x3f0)
355
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
356
share-rw = false
357
drive-type = "144"
358
359
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
360
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
361
QEMU_PROG: -device floppy,drive=none1,unit=0: Floppy unit 0 is in use
362
QEMU_PROG: -device floppy,drive=none1,unit=0: Device initialization failed.
363
364
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
365
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
366
QEMU_PROG: -device floppy,drive=none1,unit=1: Floppy unit 1 is in use
367
QEMU_PROG: -device floppy,drive=none1,unit=1: Device initialization failed.
368
369
370
=== Too many floppy drives ===
371
372
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
373
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -drive if=none,file=TEST_DIR/t.qcow2.3 -global isa-fdc.driveB=none0 -device floppy,drive=none1
374
QEMU_PROG: -device floppy,drive=none1: Can't create floppy unit 2, bus supports only 2 units
375
QEMU_PROG: -device floppy,drive=none1: Device initialization failed.
376
377
--
378
1.8.3.1
379
380
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
7
tests/drive_del-test.c | 2 +-
8
tests/nvme-test.c | 2 +-
9
tests/usb-hcd-uhci-test.c | 2 +-
10
tests/usb-hcd-xhci-test.c | 2 +-
11
tests/virtio-blk-test.c | 2 +-
12
tests/virtio-scsi-test.c | 5 +++--
13
6 files changed, 8 insertions(+), 7 deletions(-)
14
15
diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/drive_del-test.c
18
+++ b/tests/drive_del-test.c
19
@@ -XXX,XX +XXX,XX @@ static void test_after_failed_device_add(void)
20
static void test_drive_del_device_del(void)
21
{
22
/* Start with a drive used by a device that unplugs instantaneously */
23
- qtest_start("-drive if=none,id=drive0,file=/dev/null,format=raw"
24
+ qtest_start("-drive if=none,id=drive0,file=null-co://,format=raw"
25
" -device virtio-scsi-pci"
26
" -device scsi-hd,drive=drive0,id=dev0");
27
28
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/tests/nvme-test.c
31
+++ b/tests/nvme-test.c
32
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
33
g_test_init(&argc, &argv, NULL);
34
qtest_add_func("/nvme/nop", nop);
35
36
- qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
37
+ qtest_start("-drive id=drv0,if=none,file=null-co://,format=raw "
38
"-device nvme,drive=drv0,serial=foo");
39
ret = g_test_run();
40
41
diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/tests/usb-hcd-uhci-test.c
44
+++ b/tests/usb-hcd-uhci-test.c
45
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
46
{
47
const char *arch = qtest_get_arch();
48
const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
49
- " -drive id=drive0,if=none,file=/dev/null,format=raw"
50
+ " -drive id=drive0,if=none,file=null-co://,format=raw"
51
" -device usb-tablet,bus=uhci.0,port=1";
52
int ret;
53
54
diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/tests/usb-hcd-xhci-test.c
57
+++ b/tests/usb-hcd-xhci-test.c
58
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
59
qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
60
61
qtest_start("-device nec-usb-xhci,id=xhci"
62
- " -drive id=drive0,if=none,file=/dev/null,format=raw");
63
+ " -drive id=drive0,if=none,file=null-co://,format=raw");
64
ret = g_test_run();
65
qtest_end();
66
67
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/tests/virtio-blk-test.c
70
+++ b/tests/virtio-blk-test.c
71
@@ -XXX,XX +XXX,XX @@ static QOSState *pci_test_start(void)
72
const char *arch = qtest_get_arch();
73
char *tmp_path;
74
const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
75
- "-drive if=none,id=drive1,file=/dev/null,format=raw "
76
+ "-drive if=none,id=drive1,file=null-co://,format=raw "
77
"-device virtio-blk-pci,id=drv0,drive=drive0,"
78
"addr=%x.%x";
79
80
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/tests/virtio-scsi-test.c
83
+++ b/tests/virtio-scsi-test.c
84
@@ -XXX,XX +XXX,XX @@ typedef struct {
85
static QOSState *qvirtio_scsi_start(const char *extra_opts)
86
{
87
const char *arch = qtest_get_arch();
88
- const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw "
89
+ const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
90
"-device virtio-scsi-pci,id=vs0 "
91
"-device scsi-hd,bus=vs0.0,drive=drv0 %s";
92
93
@@ -XXX,XX +XXX,XX @@ static void hotplug(void)
94
QDict *response;
95
QOSState *qs;
96
97
- qs = qvirtio_scsi_start("-drive id=drv1,if=none,file=/dev/null,format=raw");
98
+ qs = qvirtio_scsi_start(
99
+ "-drive id=drv1,if=none,file=null-co://,format=raw");
100
response = qmp("{\"execute\": \"device_add\","
101
" \"arguments\": {"
102
" \"driver\": \"scsi-hd\","
103
--
104
1.8.3.1
105
106
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
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
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
util/osdep.c | 20 ++++++++++----------
7
1 file changed, 10 insertions(+), 10 deletions(-)
8
9
diff --git a/util/osdep.c b/util/osdep.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/util/osdep.c
12
+++ 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)
37
.l_len = len,
38
.l_type = fl_type,
39
};
40
- ret = fcntl(fd, F_OFD_SETLK, &fl);
41
+ ret = fcntl(fd, QEMU_SETLK, &fl);
42
return ret == -1 ? -errno : 0;
43
-#else
44
- return -ENOTSUP;
45
-#endif
46
}
47
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
--
75
1.8.3.1
76
77
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
1
From: Fam Zheng <famz@redhat.com>
1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2
2
Message-Id: <20200424125448.63318-10-kwolf@redhat.com>
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
Reviewed-by: Max Reitz <mreitz@redhat.com>
4
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
---
6
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++++++
7
tests/qemu-iotests/274 | 155 +++++++++++++++++++++
7
tests/qemu-iotests/153.out | 390 +++++++++++++++++++++++++++++++++++++++++++++
8
tests/qemu-iotests/274.out | 268 +++++++++++++++++++++++++++++++++++++
8
tests/qemu-iotests/group | 1 +
9
tests/qemu-iotests/group | 1 +
9
3 files changed, 624 insertions(+)
10
3 files changed, 424 insertions(+)
10
create mode 100755 tests/qemu-iotests/153
11
create mode 100755 tests/qemu-iotests/274
11
create mode 100644 tests/qemu-iotests/153.out
12
create mode 100644 tests/qemu-iotests/274.out
12
13
13
diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
14
diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274
14
new file mode 100755
15
new file mode 100755
15
index XXXXXXX..XXXXXXX
16
index XXXXXXX..XXXXXXX
16
--- /dev/null
17
--- /dev/null
17
+++ b/tests/qemu-iotests/153
18
+++ b/tests/qemu-iotests/274
18
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
20
+#!/usr/bin/env python3
20
+#
21
+#
21
+# Test image locking
22
+# Copyright (C) 2019 Red Hat, Inc.
22
+#
23
+# Copyright 2016, 2017 Red Hat, Inc.
24
+#
23
+#
25
+# This program is free software; you can redistribute it and/or modify
24
+# 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
25
+# 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
26
+# the Free Software Foundation; either version 2 of the License, or
28
+# (at your option) any later version.
27
+# (at your option) any later version.
...
...
33
+# GNU General Public License for more details.
32
+# GNU General Public License for more details.
34
+#
33
+#
35
+# You should have received a copy of the GNU General Public License
34
+# 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/>.
35
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
36
+#
38
+
37
+# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
39
+# creator
38
+#
40
+owner=famz@redhat.com
39
+# Some tests for short backing files and short overlays
41
+
40
+
42
+seq="$(basename $0)"
41
+import iotests
43
+echo "QA output created by $seq"
42
+
44
+
43
+iotests.verify_image_format(supported_fmts=['qcow2'])
45
+here="$PWD"
44
+iotests.verify_platform(['linux'])
46
+tmp=/tmp/$$
45
+
47
+status=1    # failure is the default!
46
+size_short = 1 * 1024 * 1024
48
+
47
+size_long = 2 * 1024 * 1024
49
+_cleanup()
48
+size_diff = size_long - size_short
50
+{
49
+
51
+ _cleanup_test_img
50
+def create_chain() -> None:
52
+ rm -f "${TEST_IMG}.base"
51
+ iotests.qemu_img_log('create', '-f', iotests.imgfmt, base,
53
+ rm -f "${TEST_IMG}.convert"
52
+ str(size_long))
54
+ rm -f "${TEST_IMG}.a"
53
+ iotests.qemu_img_log('create', '-f', iotests.imgfmt, '-b', base, mid,
55
+ rm -f "${TEST_IMG}.b"
54
+ str(size_short))
56
+ rm -f "${TEST_IMG}.lnk"
55
+ iotests.qemu_img_log('create', '-f', iotests.imgfmt, '-b', mid, top,
57
+}
56
+ str(size_long))
58
+trap "_cleanup; exit \$status" 0 1 2 3 15
57
+
59
+
58
+ iotests.qemu_io_log('-c', 'write -P 1 0 %d' % size_long, base)
60
+# get standard environment, filters and checks
59
+
61
+. ./common.rc
60
+def create_vm() -> iotests.VM:
62
+. ./common.filter
61
+ vm = iotests.VM()
63
+. ./common.qemu
62
+ vm.add_blockdev('file,filename=%s,node-name=base-file' % base)
64
+
63
+ vm.add_blockdev('%s,file=base-file,node-name=base' % iotests.imgfmt)
65
+size=32M
64
+ vm.add_blockdev('file,filename=%s,node-name=mid-file' % mid)
66
+
65
+ vm.add_blockdev('%s,file=mid-file,node-name=mid,backing=base'
67
+_check_ofd()
66
+ % iotests.imgfmt)
68
+{
67
+ vm.add_drive(top, 'backing=mid,node-name=top')
69
+ _make_test_img $size >/dev/null
68
+ return vm
70
+ if $QEMU_IMG_PROG info --image-opts "driver=file,locking=on,filename=$TEST_IMG" 2>&1 |
69
+
71
+ grep -q 'falling back to POSIX file'; then
70
+with iotests.FilePath('base') as base, \
72
+ return 1
71
+ iotests.FilePath('mid') as mid, \
73
+ else
72
+ iotests.FilePath('top') as top:
74
+ return 0
73
+
75
+ fi
74
+ iotests.log('== Commit tests ==')
76
+}
75
+
77
+
76
+ create_chain()
78
+_check_ofd || _notrun "OFD lock not available"
77
+
79
+
78
+ iotests.log('=== Check visible data ===')
80
+_supported_fmt qcow2
79
+
81
+_supported_proto file
80
+ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, top)
82
+_supported_os Linux
81
+ iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), top)
83
+
82
+
84
+_run_cmd()
83
+ iotests.log('=== Checking allocation status ===')
85
+{
84
+
86
+ echo
85
+ iotests.qemu_io_log('-c', 'alloc 0 %d' % size_short,
87
+ (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
86
+ '-c', 'alloc %d %d' % (size_short, size_diff),
88
+}
87
+ base)
89
+
88
+
90
+function _do_run_qemu()
89
+ iotests.qemu_io_log('-c', 'alloc 0 %d' % size_short,
91
+{
90
+ '-c', 'alloc %d %d' % (size_short, size_diff),
92
+ (
91
+ mid)
93
+ if ! test -t 0; then
92
+
94
+ while read cmd; do
93
+ iotests.qemu_io_log('-c', 'alloc 0 %d' % size_short,
95
+ echo $cmd
94
+ '-c', 'alloc %d %d' % (size_short, size_diff),
96
+ done
95
+ top)
97
+ fi
96
+
98
+ echo quit
97
+ iotests.log('=== Checking map ===')
99
+ ) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
98
+
100
+}
99
+ iotests.qemu_img_log('map', '--output=json', base)
101
+
100
+ iotests.qemu_img_log('map', '--output=human', base)
102
+function _run_qemu_with_images()
101
+ iotests.qemu_img_log('map', '--output=json', mid)
103
+{
102
+ iotests.qemu_img_log('map', '--output=human', mid)
104
+ _do_run_qemu \
103
+ iotests.qemu_img_log('map', '--output=json', top)
105
+ $(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
104
+ iotests.qemu_img_log('map', '--output=human', top)
106
+ | _filter_testdir | _filter_qemu
105
+
107
+}
106
+ iotests.log('=== Testing qemu-img commit (top -> mid) ===')
108
+
107
+
109
+echo "== readonly=off,force-share=on should be rejected =="
108
+ iotests.qemu_img_log('commit', top)
110
+_run_qemu_with_images null-co://,readonly=off,force-share=on
109
+ iotests.img_info_log(mid)
111
+
110
+ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid)
112
+for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
111
+ iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid)
113
+ echo
112
+
114
+ echo "== Creating base image =="
113
+ iotests.log('=== Testing HMP commit (top -> mid) ===')
115
+ TEST_IMG="${TEST_IMG}.base" _make_test_img $size
114
+
116
+
115
+ create_chain()
117
+ echo
116
+ with create_vm() as vm:
118
+ echo "== Creating test image =="
117
+ vm.launch()
119
+ $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | _filter_img_create
118
+ vm.qmp_log('human-monitor-command', command_line='commit drive0')
120
+
119
+
121
+ echo
120
+ iotests.img_info_log(mid)
122
+ echo "== Launching QEMU, opts: '$opts1' =="
121
+ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid)
123
+ _launch_qemu -drive file="${TEST_IMG}",if=none,$opts1
122
+ iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid)
124
+ h=$QEMU_HANDLE
123
+
125
+
124
+ iotests.log('=== Testing QMP active commit (top -> mid) ===')
126
+ for opts2 in "" "read-only=on" "read-only=on,force-share=on"; do
125
+
127
+ echo
126
+ create_chain()
128
+ echo "== Launching another QEMU, opts: '$opts2' =="
127
+ with create_vm() as vm:
129
+ echo "quit" | \
128
+ vm.launch()
130
+ $QEMU -nographic -monitor stdio \
129
+ vm.qmp_log('block-commit', device='top', base_node='mid',
131
+ -drive file="${TEST_IMG}",if=none,$opts2 2>&1 1>/dev/null | \
130
+ job_id='job0', auto_dismiss=False)
132
+ _filter_testdir | _filter_qemu
131
+ vm.run_job('job0', wait=5)
133
+ done
132
+
134
+
133
+ iotests.img_info_log(mid)
135
+ for L in "" "-U"; do
134
+ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid)
136
+
135
+ iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff), mid)
137
+ echo
136
+
138
+ echo "== Running utility commands $L =="
137
+
139
+ _run_cmd $QEMU_IO $L -c "read 0 512" "${TEST_IMG}"
138
+ iotests.log('== Resize tests ==')
140
+ _run_cmd $QEMU_IO $L -r -c "read 0 512" "${TEST_IMG}"
139
+
141
+ _run_cmd $QEMU_IO -c "open $L ${TEST_IMG}" -c "read 0 512"
140
+ # Use different sizes for different allocation modes:
142
+ _run_cmd $QEMU_IO -c "open -r $L ${TEST_IMG}" -c "read 0 512"
141
+ #
143
+ _run_cmd $QEMU_IMG info $L "${TEST_IMG}"
142
+ # We want to have at least one test where 32 bit truncation in the size of
144
+ _run_cmd $QEMU_IMG check $L "${TEST_IMG}"
143
+ # the overlapping area becomes visible. This is covered by the
145
+ _run_cmd $QEMU_IMG compare $L "${TEST_IMG}" "${TEST_IMG}"
144
+ # prealloc='off' case (1G to 6G is an overlap of 5G).
146
+ _run_cmd $QEMU_IMG map $L "${TEST_IMG}"
145
+ #
147
+ _run_cmd $QEMU_IMG amend -o "" $L "${TEST_IMG}"
146
+ # However, we can only do this for modes that don't preallocate data
148
+ _run_cmd $QEMU_IMG commit $L "${TEST_IMG}"
147
+ # because otherwise we might run out of space on the test host.
149
+ _run_cmd $QEMU_IMG resize $L "${TEST_IMG}" $size
148
+ #
150
+ _run_cmd $QEMU_IMG rebase $L "${TEST_IMG}" -b "${TEST_IMG}.base"
149
+ # We also want to test some unaligned combinations.
151
+ _run_cmd $QEMU_IMG snapshot -l $L "${TEST_IMG}"
150
+ for (prealloc, base_size, top_size_old, top_size_new, off) in [
152
+ _run_cmd $QEMU_IMG convert $L "${TEST_IMG}" "${TEST_IMG}.convert"
151
+ ('off', '6G', '1G', '8G', '5G'),
153
+ _run_cmd $QEMU_IMG dd $L if="${TEST_IMG}" of="${TEST_IMG}.convert" bs=512 count=1
152
+ ('metadata', '32G', '30G', '33G', '31G'),
154
+ _run_cmd $QEMU_IMG bench $L -c 1 "${TEST_IMG}"
153
+ ('falloc', '10M', '5M', '15M', '9M'),
155
+ _run_cmd $QEMU_IMG bench $L -w -c 1 "${TEST_IMG}"
154
+ ('full', '16M', '8M', '12M', '11M'),
156
+ done
155
+ ('off', '384k', '253k', '512k', '253k'),
157
+ _send_qemu_cmd $h "{ 'execute': 'quit', }" ""
156
+ ('off', '400k', '256k', '512k', '336k'),
158
+ echo
157
+ ('off', '512k', '256k', '500k', '436k')]:
159
+ echo "Round done"
158
+
160
+ _cleanup_qemu
159
+ iotests.log('=== preallocation=%s ===' % prealloc)
161
+done
160
+ iotests.qemu_img_log('create', '-f', iotests.imgfmt, base, base_size)
162
+
161
+ iotests.qemu_img_log('create', '-f', iotests.imgfmt, '-b', base, top,
163
+for opt1 in $test_opts; do
162
+ top_size_old)
164
+ for opt2 in $test_opts; do
163
+ iotests.qemu_io_log('-c', 'write -P 1 %s 64k' % off, base)
165
+ echo
164
+
166
+ echo "== Two devices with the same image ($opt1 - $opt2) =="
165
+ # After this, top_size_old to base_size should be allocated/zeroed.
167
+ _run_qemu_with_images "${TEST_IMG},$opt1" "${TEST_IMG},$opt2"
166
+ #
168
+ done
167
+ # In theory, leaving base_size to top_size_new unallocated would be
169
+done
168
+ # correct, but in practice, if we zero out anything, we zero out
170
+
169
+ # everything up to top_size_new.
171
+echo "== Creating ${TEST_IMG}.[abc] ==" | _filter_testdir
170
+ iotests.qemu_img_log('resize', '-f', iotests.imgfmt,
172
+(
171
+ '--preallocation', prealloc, top, top_size_new)
173
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.a" -b "${TEST_IMG}"
172
+ iotests.qemu_io_log('-c', 'read -P 0 %s 64k' % off, top)
174
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.b" -b "${TEST_IMG}"
173
+ iotests.qemu_io_log('-c', 'map', top)
175
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.c" -b "${TEST_IMG}.b"
174
+ iotests.qemu_img_log('map', '--output=json', top)
176
+) | _filter_img_create
175
diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out
177
+
178
+echo
179
+echo "== Two devices sharing the same file in backing chain =="
180
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.b"
181
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.c"
182
+
183
+echo
184
+echo "== Backing image also as an active device =="
185
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}"
186
+
187
+echo
188
+echo "== Backing image also as an active device (ro) =="
189
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG},readonly=on"
190
+
191
+echo
192
+echo "== Symbolic link =="
193
+rm -f "${TEST_IMG}.lnk" &>/dev/null
194
+ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link"
195
+_run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}"
196
+
197
+echo
198
+echo "== Closing an image should unlock it =="
199
+_launch_qemu
200
+
201
+_send_qemu_cmd $QEMU_HANDLE \
202
+ "{ 'execute': 'qmp_capabilities' }" \
203
+ 'return'
204
+
205
+echo "Adding drive"
206
+_send_qemu_cmd $QEMU_HANDLE \
207
+ "{ 'execute': 'human-monitor-command',
208
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=d0,file=${TEST_IMG}' } }" \
209
+ ""
210
+
211
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
212
+
213
+echo "Closing drive"
214
+_send_qemu_cmd $QEMU_HANDLE \
215
+ "{ 'execute': 'human-monitor-command',
216
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
217
+ ""
218
+
219
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
220
+
221
+echo "Adding two and closing one"
222
+for d in d0 d1; do
223
+ _send_qemu_cmd $QEMU_HANDLE \
224
+ "{ 'execute': 'human-monitor-command',
225
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=$d,file=${TEST_IMG},readonly=on' } }" \
226
+ ""
227
+done
228
+
229
+_run_cmd $QEMU_IMG info "${TEST_IMG}"
230
+
231
+_send_qemu_cmd $QEMU_HANDLE \
232
+ "{ 'execute': 'human-monitor-command',
233
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
234
+ ""
235
+
236
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
237
+
238
+echo "Closing the other"
239
+_send_qemu_cmd $QEMU_HANDLE \
240
+ "{ 'execute': 'human-monitor-command',
241
+ 'arguments': { 'command-line': 'drive_del d1' } }" \
242
+ ""
243
+
244
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
245
+
246
+_cleanup_qemu
247
+
248
+# success, all done
249
+echo "*** done"
250
+rm -f $seq.full
251
+status=0
252
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
253
new file mode 100644
176
new file mode 100644
254
index XXXXXXX..XXXXXXX
177
index XXXXXXX..XXXXXXX
255
--- /dev/null
178
--- /dev/null
256
+++ b/tests/qemu-iotests/153.out
179
+++ b/tests/qemu-iotests/274.out
257
@@ -XXX,XX +XXX,XX @@
180
@@ -XXX,XX +XXX,XX @@
258
+QA output created by 153
181
+== Commit tests ==
259
+== readonly=off,force-share=on should be rejected ==
182
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=2097152 cluster_size=65536 lazy_refcounts=off refcount_bits=16
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
183
+
261
+
184
+Formatting 'TEST_DIR/PID-mid', fmt=qcow2 size=1048576 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
262
+== Creating base image ==
185
+
263
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
186
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=2097152 backing_file=TEST_DIR/PID-mid cluster_size=65536 lazy_refcounts=off refcount_bits=16
264
+
187
+
265
+== Creating test image ==
188
+wrote 2097152/2097152 bytes at offset 0
266
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
189
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
267
+
190
+
268
+== Launching QEMU, opts: '' ==
191
+=== Check visible data ===
269
+
192
+read 1048576/1048576 bytes at offset 0
270
+== Launching another QEMU, opts: '' ==
193
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
271
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
194
+
272
+Is another process using the image?
195
+read 1048576/1048576 bytes at offset 1048576
273
+
196
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
274
+== Launching another QEMU, opts: 'read-only=on' ==
197
+
275
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,read-only=on: Failed to get shared "write" lock
198
+=== Checking allocation status ===
276
+Is another process using the image?
199
+1048576/1048576 bytes allocated at offset 0 bytes
277
+
200
+1048576/1048576 bytes allocated at offset 1 MiB
278
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
201
+
279
+
202
+0/1048576 bytes allocated at offset 0 bytes
280
+== Running utility commands ==
203
+0/0 bytes allocated at offset 1 MiB
281
+
204
+
282
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
205
+0/1048576 bytes allocated at offset 0 bytes
283
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
206
+0/1048576 bytes allocated at offset 1 MiB
284
+Is another process using the image?
207
+
285
+
208
+=== Checking map ===
286
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
209
+[{ "start": 0, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": 327680}]
287
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
210
+
288
+Is another process using the image?
211
+Offset Length Mapped to File
289
+
212
+0 0x200000 0x50000 TEST_DIR/PID-base
290
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
213
+
291
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
214
+[{ "start": 0, "length": 1048576, "depth": 1, "zero": false, "data": true, "offset": 327680}]
292
+Is another process using the image?
215
+
293
+
216
+Offset Length Mapped to File
294
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
217
+0 0x100000 0x50000 TEST_DIR/PID-base
295
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
218
+
296
+Is another process using the image?
219
+[{ "start": 0, "length": 1048576, "depth": 2, "zero": false, "data": true, "offset": 327680},
297
+
220
+{ "start": 1048576, "length": 1048576, "depth": 0, "zero": true, "data": false}]
298
+_qemu_img_wrapper info TEST_DIR/t.qcow2
221
+
299
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
222
+Offset Length Mapped to File
300
+Is another process using the image?
223
+0 0x100000 0x50000 TEST_DIR/PID-base
301
+
224
+
302
+_qemu_img_wrapper check TEST_DIR/t.qcow2
225
+=== Testing qemu-img commit (top -> mid) ===
303
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
226
+Image committed.
304
+Is another process using the image?
227
+
305
+
228
+image: TEST_IMG
306
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
229
+file format: IMGFMT
307
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
230
+virtual size: 2 MiB (2097152 bytes)
308
+Is another process using the image?
231
+cluster_size: 65536
309
+
232
+backing file: TEST_DIR/PID-base
310
+_qemu_img_wrapper map TEST_DIR/t.qcow2
233
+Format specific information:
311
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
234
+ compat: 1.1
312
+Is another process using the image?
235
+ lazy refcounts: false
313
+
236
+ refcount bits: 16
314
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
237
+ corrupt: false
315
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
238
+
316
+Is another process using the image?
239
+read 1048576/1048576 bytes at offset 0
317
+
240
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
318
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
241
+
319
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
242
+read 1048576/1048576 bytes at offset 1048576
320
+Is another process using the image?
243
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
321
+
244
+
322
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
245
+=== Testing HMP commit (top -> mid) ===
323
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
246
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=2097152 cluster_size=65536 lazy_refcounts=off refcount_bits=16
324
+Is another process using the image?
247
+
325
+
248
+Formatting 'TEST_DIR/PID-mid', fmt=qcow2 size=1048576 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
326
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
249
+
327
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
250
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=2097152 backing_file=TEST_DIR/PID-mid cluster_size=65536 lazy_refcounts=off refcount_bits=16
328
+Is another process using the image?
251
+
329
+
252
+wrote 2097152/2097152 bytes at offset 0
330
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
253
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
331
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
254
+
332
+Is another process using the image?
255
+{"execute": "human-monitor-command", "arguments": {"command-line": "commit drive0"}}
333
+
256
+{"return": ""}
334
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
257
+image: TEST_IMG
335
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
258
+file format: IMGFMT
336
+Is another process using the image?
259
+virtual size: 2 MiB (2097152 bytes)
337
+
260
+cluster_size: 65536
338
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
261
+backing file: TEST_DIR/PID-base
339
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
262
+Format specific information:
340
+Is another process using the image?
263
+ compat: 1.1
341
+
264
+ lazy refcounts: false
342
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
265
+ refcount bits: 16
343
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
266
+ corrupt: false
344
+Is another process using the image?
267
+
345
+
268
+read 1048576/1048576 bytes at offset 0
346
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
269
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
347
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
270
+
348
+Is another process using the image?
271
+read 1048576/1048576 bytes at offset 1048576
349
+
272
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
350
+== Running utility commands -U ==
273
+
351
+
274
+=== Testing QMP active commit (top -> mid) ===
352
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
275
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=2097152 cluster_size=65536 lazy_refcounts=off refcount_bits=16
353
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
276
+
354
+
277
+Formatting 'TEST_DIR/PID-mid', fmt=qcow2 size=1048576 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
355
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
278
+
356
+
279
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=2097152 backing_file=TEST_DIR/PID-mid cluster_size=65536 lazy_refcounts=off refcount_bits=16
357
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
280
+
358
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
281
+wrote 2097152/2097152 bytes at offset 0
359
+
282
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
360
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
283
+
361
+
284
+{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-node": "mid", "device": "top", "job-id": "job0"}}
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": {}}
285
+{"return": {}}
629
+Adding drive
286
+{"execute": "job-complete", "arguments": {"id": "job0"}}
630
+
287
+{"return": {}}
631
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
288
+{"data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
632
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
289
+{"data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}}
633
+Is another process using the image?
290
+{"execute": "job-dismiss", "arguments": {"id": "job0"}}
634
+Closing drive
291
+{"return": {}}
635
+
292
+image: TEST_IMG
636
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
293
+file format: IMGFMT
637
+Adding two and closing one
294
+virtual size: 2 MiB (2097152 bytes)
638
+
295
+cluster_size: 65536
639
+_qemu_img_wrapper info TEST_DIR/t.qcow2
296
+backing file: TEST_DIR/PID-base
640
+
297
+Format specific information:
641
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
298
+ compat: 1.1
642
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
299
+ lazy refcounts: false
643
+Is another process using the image?
300
+ refcount bits: 16
644
+Closing the other
301
+ corrupt: false
645
+
302
+
646
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
303
+read 1048576/1048576 bytes at offset 0
647
+*** done
304
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
305
+
306
+read 1048576/1048576 bytes at offset 1048576
307
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
308
+
309
+== Resize tests ==
310
+=== preallocation=off ===
311
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=6442450944 cluster_size=65536 lazy_refcounts=off refcount_bits=16
312
+
313
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=1073741824 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
314
+
315
+wrote 65536/65536 bytes at offset 5368709120
316
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
317
+
318
+Image resized.
319
+
320
+read 65536/65536 bytes at offset 5368709120
321
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
322
+
323
+1 GiB (0x40000000) bytes not allocated at offset 0 bytes (0x0)
324
+7 GiB (0x1c0000000) bytes allocated at offset 1 GiB (0x40000000)
325
+
326
+[{ "start": 0, "length": 1073741824, "depth": 1, "zero": true, "data": false},
327
+{ "start": 1073741824, "length": 7516192768, "depth": 0, "zero": true, "data": false}]
328
+
329
+=== preallocation=metadata ===
330
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=34359738368 cluster_size=65536 lazy_refcounts=off refcount_bits=16
331
+
332
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=32212254720 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
333
+
334
+wrote 65536/65536 bytes at offset 33285996544
335
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
336
+
337
+Image resized.
338
+
339
+read 65536/65536 bytes at offset 33285996544
340
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
341
+
342
+30 GiB (0x780000000) bytes not allocated at offset 0 bytes (0x0)
343
+3 GiB (0xc0000000) bytes allocated at offset 30 GiB (0x780000000)
344
+
345
+[{ "start": 0, "length": 32212254720, "depth": 1, "zero": true, "data": false},
346
+{ "start": 32212254720, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 327680},
347
+{ "start": 32749125632, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 537264128},
348
+{ "start": 33285996544, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 1074200576},
349
+{ "start": 33822867456, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 1611137024},
350
+{ "start": 34359738368, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 2148139008},
351
+{ "start": 34896609280, "length": 536870912, "depth": 0, "zero": true, "data": false, "offset": 2685075456}]
352
+
353
+=== preallocation=falloc ===
354
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=10485760 cluster_size=65536 lazy_refcounts=off refcount_bits=16
355
+
356
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=5242880 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
357
+
358
+wrote 65536/65536 bytes at offset 9437184
359
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
360
+
361
+Image resized.
362
+
363
+read 65536/65536 bytes at offset 9437184
364
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
365
+
366
+5 MiB (0x500000) bytes not allocated at offset 0 bytes (0x0)
367
+10 MiB (0xa00000) bytes allocated at offset 5 MiB (0x500000)
368
+
369
+[{ "start": 0, "length": 5242880, "depth": 1, "zero": true, "data": false},
370
+{ "start": 5242880, "length": 10485760, "depth": 0, "zero": true, "data": false, "offset": 327680}]
371
+
372
+=== preallocation=full ===
373
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=16777216 cluster_size=65536 lazy_refcounts=off refcount_bits=16
374
+
375
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=8388608 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
376
+
377
+wrote 65536/65536 bytes at offset 11534336
378
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
379
+
380
+Image resized.
381
+
382
+read 65536/65536 bytes at offset 11534336
383
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
384
+
385
+8 MiB (0x800000) bytes not allocated at offset 0 bytes (0x0)
386
+4 MiB (0x400000) bytes allocated at offset 8 MiB (0x800000)
387
+
388
+[{ "start": 0, "length": 8388608, "depth": 1, "zero": true, "data": false},
389
+{ "start": 8388608, "length": 4194304, "depth": 0, "zero": true, "data": false, "offset": 327680}]
390
+
391
+=== preallocation=off ===
392
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=393216 cluster_size=65536 lazy_refcounts=off refcount_bits=16
393
+
394
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=259072 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
395
+
396
+wrote 65536/65536 bytes at offset 259072
397
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
398
+
399
+Image resized.
400
+
401
+read 65536/65536 bytes at offset 259072
402
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
403
+
404
+192 KiB (0x30000) bytes not allocated at offset 0 bytes (0x0)
405
+320 KiB (0x50000) bytes allocated at offset 192 KiB (0x30000)
406
+
407
+[{ "start": 0, "length": 196608, "depth": 1, "zero": true, "data": false},
408
+{ "start": 196608, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": 327680},
409
+{ "start": 262144, "length": 262144, "depth": 0, "zero": true, "data": false}]
410
+
411
+=== preallocation=off ===
412
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=409600 cluster_size=65536 lazy_refcounts=off refcount_bits=16
413
+
414
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=262144 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
415
+
416
+wrote 65536/65536 bytes at offset 344064
417
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
418
+
419
+Image resized.
420
+
421
+read 65536/65536 bytes at offset 344064
422
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
423
+
424
+256 KiB (0x40000) bytes not allocated at offset 0 bytes (0x0)
425
+256 KiB (0x40000) bytes allocated at offset 256 KiB (0x40000)
426
+
427
+[{ "start": 0, "length": 262144, "depth": 1, "zero": true, "data": false},
428
+{ "start": 262144, "length": 262144, "depth": 0, "zero": true, "data": false}]
429
+
430
+=== preallocation=off ===
431
+Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=524288 cluster_size=65536 lazy_refcounts=off refcount_bits=16
432
+
433
+Formatting 'TEST_DIR/PID-top', fmt=qcow2 size=262144 backing_file=TEST_DIR/PID-base cluster_size=65536 lazy_refcounts=off refcount_bits=16
434
+
435
+wrote 65536/65536 bytes at offset 446464
436
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
437
+
438
+Image resized.
439
+
440
+read 65536/65536 bytes at offset 446464
441
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
442
+
443
+256 KiB (0x40000) bytes not allocated at offset 0 bytes (0x0)
444
+244 KiB (0x3d000) bytes allocated at offset 256 KiB (0x40000)
445
+
446
+[{ "start": 0, "length": 262144, "depth": 1, "zero": true, "data": false},
447
+{ "start": 262144, "length": 249856, "depth": 0, "zero": true, "data": false}]
448
+
648
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
449
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
649
index XXXXXXX..XXXXXXX 100644
450
index XXXXXXX..XXXXXXX 100644
650
--- a/tests/qemu-iotests/group
451
--- a/tests/qemu-iotests/group
651
+++ b/tests/qemu-iotests/group
452
+++ b/tests/qemu-iotests/group
652
@@ -XXX,XX +XXX,XX @@
453
@@ -XXX,XX +XXX,XX @@
653
149 rw auto sudo
454
270 rw backing quick
654
150 rw auto quick
455
272 rw
655
152 rw auto quick
456
273 backing quick
656
+153 rw auto quick
457
+274 rw backing
657
154 rw auto backing quick
458
277 rw quick
658
155 rw auto
459
279 rw backing quick
659
156 rw auto quick
460
280 rw migration quick
660
--
461
--
661
1.8.3.1
462
2.25.3
662
463
663
464
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: Max Reitz <mreitz@redhat.com>
1
The BDRV_REQ_ZERO_WRITE is currently implemented in a way that first the
2
image is possibly preallocated and then the zero flag is added to all
3
clusters. This means that a copy-on-write operation may be needed when
4
writing to these clusters, despite having used preallocation, negating
5
one of the major benefits of preallocation.
2
6
3
When calculating the number of reftable entries, we should actually use
7
Instead, try to forward the BDRV_REQ_ZERO_WRITE to the protocol driver,
4
the number of refblocks and not (wrongly[1]) re-calculate it.
8
and if the protocol driver can ensure that the new area reads as zeros,
9
we can skip setting the zero flag in the qcow2 layer.
5
10
6
[1] "Wrongly" means: Dividing the number of clusters by the number of
11
Unfortunately, the same approach doesn't work for metadata
7
entries per refblock and rounding down instead of up.
12
preallocation, so we'll still set the zero flag there.
8
13
9
Reported-by: Eric Blake <eblake@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
16
Message-Id: <20200424142701.67053-1-kwolf@redhat.com>
17
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
19
---
14
block/qcow2.c | 9 +++++----
20
block/qcow2.c | 22 +++++++++++++++++++---
15
1 file changed, 5 insertions(+), 4 deletions(-)
21
tests/qemu-iotests/274.out | 4 ++--
22
2 files changed, 21 insertions(+), 5 deletions(-)
16
23
17
diff --git a/block/qcow2.c b/block/qcow2.c
24
diff --git a/block/qcow2.c b/block/qcow2.c
18
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
19
--- a/block/qcow2.c
26
--- a/block/qcow2.c
20
+++ b/block/qcow2.c
27
+++ b/block/qcow2.c
21
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
28
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
22
* too, as long as the bulk is allocated here). Therefore, using
29
/* Allocate the data area */
23
* floating point arithmetic is fine. */
30
new_file_size = allocation_start +
24
int64_t meta_size = 0;
31
nb_new_data_clusters * s->cluster_size;
25
- uint64_t nreftablee, nrefblocke, nl1e, nl2e;
32
- /* Image file grows, so @exact does not matter */
26
+ uint64_t nreftablee, nrefblocke, nl1e, nl2e, refblock_count;
33
- ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, 0,
27
int64_t aligned_total_size = align_offset(total_size, cluster_size);
34
- errp);
28
int refblock_bits, refblock_size;
35
+ /*
29
/* refcount entry size in bytes */
36
+ * Image file grows, so @exact does not matter.
30
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
37
+ *
31
nrefblocke = (aligned_total_size + meta_size + cluster_size)
38
+ * If we need to zero out the new area, try first whether the protocol
32
/ (cluster_size - rces - rces * sizeof(uint64_t)
39
+ * driver can already take care of this.
33
/ cluster_size);
40
+ */
34
- meta_size += DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size;
41
+ if (flags & BDRV_REQ_ZERO_WRITE) {
35
+ refblock_count = DIV_ROUND_UP(nrefblocke, refblock_size);
42
+ ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc,
36
+ meta_size += refblock_count * cluster_size;
43
+ BDRV_REQ_ZERO_WRITE, NULL);
37
44
+ if (ret >= 0) {
38
/* total size of refcount tables */
45
+ flags &= ~BDRV_REQ_ZERO_WRITE;
39
- nreftablee = nrefblocke / refblock_size;
46
+ }
40
- nreftablee = align_offset(nreftablee, cluster_size / sizeof(uint64_t));
47
+ } else {
41
+ nreftablee = align_offset(refblock_count,
48
+ ret = -1;
42
+ cluster_size / sizeof(uint64_t));
49
+ }
43
meta_size += nreftablee * sizeof(uint64_t);
50
+ if (ret < 0) {
44
51
+ ret = bdrv_co_truncate(bs->file, new_file_size, false, prealloc, 0,
45
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
52
+ errp);
53
+ }
54
if (ret < 0) {
55
error_prepend(errp, "Failed to resize underlying file: ");
56
qcow2_free_clusters(bs, allocation_start,
57
diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out
58
index XXXXXXX..XXXXXXX 100644
59
--- a/tests/qemu-iotests/274.out
60
+++ b/tests/qemu-iotests/274.out
61
@@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 9437184
62
10 MiB (0xa00000) bytes allocated at offset 5 MiB (0x500000)
63
64
[{ "start": 0, "length": 5242880, "depth": 1, "zero": true, "data": false},
65
-{ "start": 5242880, "length": 10485760, "depth": 0, "zero": true, "data": false, "offset": 327680}]
66
+{ "start": 5242880, "length": 10485760, "depth": 0, "zero": false, "data": true, "offset": 327680}]
67
68
=== preallocation=full ===
69
Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=16777216 cluster_size=65536 lazy_refcounts=off refcount_bits=16
70
@@ -XXX,XX +XXX,XX @@ read 65536/65536 bytes at offset 11534336
71
4 MiB (0x400000) bytes allocated at offset 8 MiB (0x800000)
72
73
[{ "start": 0, "length": 8388608, "depth": 1, "zero": true, "data": false},
74
-{ "start": 8388608, "length": 4194304, "depth": 0, "zero": true, "data": false, "offset": 327680}]
75
+{ "start": 8388608, "length": 4194304, "depth": 0, "zero": false, "data": true, "offset": 327680}]
76
77
=== preallocation=off ===
78
Formatting 'TEST_DIR/PID-base', fmt=qcow2 size=393216 cluster_size=65536 lazy_refcounts=off refcount_bits=16
46
--
79
--
47
1.8.3.1
80
2.25.3
48
81
49
82
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
In discard_single_l2(), we completely discard normal clusters instead of
4
simply turning them into preallocated zero clusters. That means we
5
should probably do the same with such preallocated zero clusters:
6
Discard them instead of keeping them allocated.
7
8
Reported-by: Eric Blake <eblake@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
13
block/qcow2-cluster.c | 3 ++-
14
1 file changed, 2 insertions(+), 1 deletion(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
break;
22
23
case QCOW2_CLUSTER_ZERO:
24
- if (!full_discard) {
25
+ /* Preallocated zero clusters should be discarded in any case */
26
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
27
continue;
28
}
29
break;
30
--
31
1.8.3.1
32
33
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
066 was supposed to be a test "for discarding preallocated zero
4
clusters", but it did so incompletely: While it did check the image
5
file's integrity after the operation, it did not confirm that the
6
clusters are indeed freed. This patch adds this test.
7
8
In addition, new cases for writing to preallocated zero clusters are
9
added.
10
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
15
tests/qemu-iotests/066 | 128 ++++++++++++++++++++++++++++++++++++++++++++-
16
tests/qemu-iotests/066.out | 46 ++++++++++++++++
17
2 files changed, 173 insertions(+), 1 deletion(-)
18
19
diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066
20
index XXXXXXX..XXXXXXX 100755
21
--- a/tests/qemu-iotests/066
22
+++ b/tests/qemu-iotests/066
23
@@ -XXX,XX +XXX,XX @@
24
#!/bin/bash
25
#
26
-# Test case for discarding preallocated zero clusters in qcow2
27
+# Test case for preallocated zero clusters in qcow2
28
#
29
# Copyright (C) 2013 Red Hat, Inc.
30
#
31
@@ -XXX,XX +XXX,XX @@ _make_test_img $IMG_SIZE
32
$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \
33
     -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \
34
| _filter_qemu_io
35
+
36
# Check the image (there shouldn't be any leaks)
37
_check_test_img
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
164
# success, all done
165
echo "*** done"
166
diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out
167
index XXXXXXX..XXXXXXX 100644
168
--- a/tests/qemu-iotests/066.out
169
+++ b/tests/qemu-iotests/066.out
170
@@ -XXX,XX +XXX,XX @@ discard 67109376/67109376 bytes at offset 0
171
read 67109376/67109376 bytes at offset 0
172
64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
173
No errors were found on the image.
174
+Offset Length Mapped to File
175
+
176
+=== Writing to preallocated zero clusters ===
177
+
178
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376
179
+wrote 262144/262144 bytes at offset 1048576
180
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
181
+wrote 262144/262144 bytes at offset 1048576
182
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
183
+wrote 196608/196608 bytes at offset 1081344
184
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+No errors were found on the image.
186
+read 32768/32768 bytes at offset 1048576
187
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
188
+read 196608/196608 bytes at offset 1081344
189
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
190
+read 32768/32768 bytes at offset 1277952
191
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
192
+Successfully reused original clusters.
193
+
194
+=== Writing to a snapshotted preallocated zero cluster ===
195
+
196
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
197
+wrote 65536/65536 bytes at offset 0
198
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+wrote 65536/65536 bytes at offset 0
200
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
201
+wrote 65536/65536 bytes at offset 0
202
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+No errors were found on the image.
204
+read 65536/65536 bytes at offset 0
205
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
206
+read 65536/65536 bytes at offset 0
207
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
208
+
209
+=== Consecutive write to a preallocated zero cluster ===
210
+
211
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=196608
212
+wrote 196608/196608 bytes at offset 0
213
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
214
+wrote 65536/65536 bytes at offset 65536
215
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
216
+wrote 196608/196608 bytes at offset 0
217
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
218
+No errors were found on the image.
219
+Successfully reused original clusters.
220
*** done
221
--
222
1.8.3.1
223
224
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
1
From: Christoph Hellwig <hch@lst.de>
1
From: Andrzej Jakowski <andrzej.jakowski@linux.intel.com>
2
2
3
Signed-off-by: Keith Busch <keith.busch@intel.com>
3
This patch introduces support for PMR that has been defined as part of NVMe 1.4
4
[hch: ported over from qemu-nvme.git to mainline]
4
spec. User can now specify a pmrdev option that should point to HostMemoryBackend.
5
Signed-off-by: Christoph Hellwig <hch@lst.de>
5
pmrdev memory region will subsequently be exposed as PCI BAR 2 in emulated NVMe
6
Acked-by: Keith Busch <keith.busch@intel.com>
6
device. Guest OS can perform mmio read and writes to the PMR region that will stay
7
persistent across system reboot.
8
9
Signed-off-by: Andrzej Jakowski <andrzej.jakowski@linux.intel.com>
10
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
11
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Message-Id: <20200330164656.9348-1-andrzej.jakowski@linux.intel.com>
13
Reviewed-by: Keith Busch <kbusch@kernel.org>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
15
---
9
hw/block/nvme.c | 26 ++++++++++++++++++++++++++
16
hw/block/nvme.h | 2 +
10
hw/block/nvme.h | 1 +
17
include/block/nvme.h | 172 +++++++++++++++++++++++++++++++++++++++++
11
2 files changed, 27 insertions(+)
18
hw/block/nvme.c | 109 ++++++++++++++++++++++++++
19
hw/block/Makefile.objs | 2 +-
20
hw/block/trace-events | 4 +
21
5 files changed, 288 insertions(+), 1 deletion(-)
12
22
23
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
24
index XXXXXXX..XXXXXXX 100644
25
--- a/hw/block/nvme.h
26
+++ b/hw/block/nvme.h
27
@@ -XXX,XX +XXX,XX @@ typedef struct NvmeCtrl {
28
uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */
29
30
char *serial;
31
+ HostMemoryBackend *pmrdev;
32
+
33
NvmeNamespace *namespaces;
34
NvmeSQueue **sq;
35
NvmeCQueue **cq;
36
diff --git a/include/block/nvme.h b/include/block/nvme.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/block/nvme.h
39
+++ b/include/block/nvme.h
40
@@ -XXX,XX +XXX,XX @@ typedef struct NvmeBar {
41
uint64_t acq;
42
uint32_t cmbloc;
43
uint32_t cmbsz;
44
+ uint8_t padding[3520]; /* not used by QEMU */
45
+ uint32_t pmrcap;
46
+ uint32_t pmrctl;
47
+ uint32_t pmrsts;
48
+ uint32_t pmrebs;
49
+ uint32_t pmrswtp;
50
+ uint32_t pmrmsc;
51
} NvmeBar;
52
53
enum NvmeCapShift {
54
@@ -XXX,XX +XXX,XX @@ enum NvmeCapShift {
55
CAP_CSS_SHIFT = 37,
56
CAP_MPSMIN_SHIFT = 48,
57
CAP_MPSMAX_SHIFT = 52,
58
+ CAP_PMR_SHIFT = 56,
59
};
60
61
enum NvmeCapMask {
62
@@ -XXX,XX +XXX,XX @@ enum NvmeCapMask {
63
CAP_CSS_MASK = 0xff,
64
CAP_MPSMIN_MASK = 0xf,
65
CAP_MPSMAX_MASK = 0xf,
66
+ CAP_PMR_MASK = 0x1,
67
};
68
69
#define NVME_CAP_MQES(cap) (((cap) >> CAP_MQES_SHIFT) & CAP_MQES_MASK)
70
@@ -XXX,XX +XXX,XX @@ enum NvmeCapMask {
71
<< CAP_MPSMIN_SHIFT)
72
#define NVME_CAP_SET_MPSMAX(cap, val) (cap |= (uint64_t)(val & CAP_MPSMAX_MASK)\
73
<< CAP_MPSMAX_SHIFT)
74
+#define NVME_CAP_SET_PMRS(cap, val) (cap |= (uint64_t)(val & CAP_PMR_MASK)\
75
+ << CAP_PMR_SHIFT)
76
77
enum NvmeCcShift {
78
CC_EN_SHIFT = 0,
79
@@ -XXX,XX +XXX,XX @@ enum NvmeCmbszMask {
80
#define NVME_CMBSZ_GETSIZE(cmbsz) \
81
(NVME_CMBSZ_SZ(cmbsz) * (1 << (12 + 4 * NVME_CMBSZ_SZU(cmbsz))))
82
83
+enum NvmePmrcapShift {
84
+ PMRCAP_RDS_SHIFT = 3,
85
+ PMRCAP_WDS_SHIFT = 4,
86
+ PMRCAP_BIR_SHIFT = 5,
87
+ PMRCAP_PMRTU_SHIFT = 8,
88
+ PMRCAP_PMRWBM_SHIFT = 10,
89
+ PMRCAP_PMRTO_SHIFT = 16,
90
+ PMRCAP_CMSS_SHIFT = 24,
91
+};
92
+
93
+enum NvmePmrcapMask {
94
+ PMRCAP_RDS_MASK = 0x1,
95
+ PMRCAP_WDS_MASK = 0x1,
96
+ PMRCAP_BIR_MASK = 0x7,
97
+ PMRCAP_PMRTU_MASK = 0x3,
98
+ PMRCAP_PMRWBM_MASK = 0xf,
99
+ PMRCAP_PMRTO_MASK = 0xff,
100
+ PMRCAP_CMSS_MASK = 0x1,
101
+};
102
+
103
+#define NVME_PMRCAP_RDS(pmrcap) \
104
+ ((pmrcap >> PMRCAP_RDS_SHIFT) & PMRCAP_RDS_MASK)
105
+#define NVME_PMRCAP_WDS(pmrcap) \
106
+ ((pmrcap >> PMRCAP_WDS_SHIFT) & PMRCAP_WDS_MASK)
107
+#define NVME_PMRCAP_BIR(pmrcap) \
108
+ ((pmrcap >> PMRCAP_BIR_SHIFT) & PMRCAP_BIR_MASK)
109
+#define NVME_PMRCAP_PMRTU(pmrcap) \
110
+ ((pmrcap >> PMRCAP_PMRTU_SHIFT) & PMRCAP_PMRTU_MASK)
111
+#define NVME_PMRCAP_PMRWBM(pmrcap) \
112
+ ((pmrcap >> PMRCAP_PMRWBM_SHIFT) & PMRCAP_PMRWBM_MASK)
113
+#define NVME_PMRCAP_PMRTO(pmrcap) \
114
+ ((pmrcap >> PMRCAP_PMRTO_SHIFT) & PMRCAP_PMRTO_MASK)
115
+#define NVME_PMRCAP_CMSS(pmrcap) \
116
+ ((pmrcap >> PMRCAP_CMSS_SHIFT) & PMRCAP_CMSS_MASK)
117
+
118
+#define NVME_PMRCAP_SET_RDS(pmrcap, val) \
119
+ (pmrcap |= (uint64_t)(val & PMRCAP_RDS_MASK) << PMRCAP_RDS_SHIFT)
120
+#define NVME_PMRCAP_SET_WDS(pmrcap, val) \
121
+ (pmrcap |= (uint64_t)(val & PMRCAP_WDS_MASK) << PMRCAP_WDS_SHIFT)
122
+#define NVME_PMRCAP_SET_BIR(pmrcap, val) \
123
+ (pmrcap |= (uint64_t)(val & PMRCAP_BIR_MASK) << PMRCAP_BIR_SHIFT)
124
+#define NVME_PMRCAP_SET_PMRTU(pmrcap, val) \
125
+ (pmrcap |= (uint64_t)(val & PMRCAP_PMRTU_MASK) << PMRCAP_PMRTU_SHIFT)
126
+#define NVME_PMRCAP_SET_PMRWBM(pmrcap, val) \
127
+ (pmrcap |= (uint64_t)(val & PMRCAP_PMRWBM_MASK) << PMRCAP_PMRWBM_SHIFT)
128
+#define NVME_PMRCAP_SET_PMRTO(pmrcap, val) \
129
+ (pmrcap |= (uint64_t)(val & PMRCAP_PMRTO_MASK) << PMRCAP_PMRTO_SHIFT)
130
+#define NVME_PMRCAP_SET_CMSS(pmrcap, val) \
131
+ (pmrcap |= (uint64_t)(val & PMRCAP_CMSS_MASK) << PMRCAP_CMSS_SHIFT)
132
+
133
+enum NvmePmrctlShift {
134
+ PMRCTL_EN_SHIFT = 0,
135
+};
136
+
137
+enum NvmePmrctlMask {
138
+ PMRCTL_EN_MASK = 0x1,
139
+};
140
+
141
+#define NVME_PMRCTL_EN(pmrctl) ((pmrctl >> PMRCTL_EN_SHIFT) & PMRCTL_EN_MASK)
142
+
143
+#define NVME_PMRCTL_SET_EN(pmrctl, val) \
144
+ (pmrctl |= (uint64_t)(val & PMRCTL_EN_MASK) << PMRCTL_EN_SHIFT)
145
+
146
+enum NvmePmrstsShift {
147
+ PMRSTS_ERR_SHIFT = 0,
148
+ PMRSTS_NRDY_SHIFT = 8,
149
+ PMRSTS_HSTS_SHIFT = 9,
150
+ PMRSTS_CBAI_SHIFT = 12,
151
+};
152
+
153
+enum NvmePmrstsMask {
154
+ PMRSTS_ERR_MASK = 0xff,
155
+ PMRSTS_NRDY_MASK = 0x1,
156
+ PMRSTS_HSTS_MASK = 0x7,
157
+ PMRSTS_CBAI_MASK = 0x1,
158
+};
159
+
160
+#define NVME_PMRSTS_ERR(pmrsts) \
161
+ ((pmrsts >> PMRSTS_ERR_SHIFT) & PMRSTS_ERR_MASK)
162
+#define NVME_PMRSTS_NRDY(pmrsts) \
163
+ ((pmrsts >> PMRSTS_NRDY_SHIFT) & PMRSTS_NRDY_MASK)
164
+#define NVME_PMRSTS_HSTS(pmrsts) \
165
+ ((pmrsts >> PMRSTS_HSTS_SHIFT) & PMRSTS_HSTS_MASK)
166
+#define NVME_PMRSTS_CBAI(pmrsts) \
167
+ ((pmrsts >> PMRSTS_CBAI_SHIFT) & PMRSTS_CBAI_MASK)
168
+
169
+#define NVME_PMRSTS_SET_ERR(pmrsts, val) \
170
+ (pmrsts |= (uint64_t)(val & PMRSTS_ERR_MASK) << PMRSTS_ERR_SHIFT)
171
+#define NVME_PMRSTS_SET_NRDY(pmrsts, val) \
172
+ (pmrsts |= (uint64_t)(val & PMRSTS_NRDY_MASK) << PMRSTS_NRDY_SHIFT)
173
+#define NVME_PMRSTS_SET_HSTS(pmrsts, val) \
174
+ (pmrsts |= (uint64_t)(val & PMRSTS_HSTS_MASK) << PMRSTS_HSTS_SHIFT)
175
+#define NVME_PMRSTS_SET_CBAI(pmrsts, val) \
176
+ (pmrsts |= (uint64_t)(val & PMRSTS_CBAI_MASK) << PMRSTS_CBAI_SHIFT)
177
+
178
+enum NvmePmrebsShift {
179
+ PMREBS_PMRSZU_SHIFT = 0,
180
+ PMREBS_RBB_SHIFT = 4,
181
+ PMREBS_PMRWBZ_SHIFT = 8,
182
+};
183
+
184
+enum NvmePmrebsMask {
185
+ PMREBS_PMRSZU_MASK = 0xf,
186
+ PMREBS_RBB_MASK = 0x1,
187
+ PMREBS_PMRWBZ_MASK = 0xffffff,
188
+};
189
+
190
+#define NVME_PMREBS_PMRSZU(pmrebs) \
191
+ ((pmrebs >> PMREBS_PMRSZU_SHIFT) & PMREBS_PMRSZU_MASK)
192
+#define NVME_PMREBS_RBB(pmrebs) \
193
+ ((pmrebs >> PMREBS_RBB_SHIFT) & PMREBS_RBB_MASK)
194
+#define NVME_PMREBS_PMRWBZ(pmrebs) \
195
+ ((pmrebs >> PMREBS_PMRWBZ_SHIFT) & PMREBS_PMRWBZ_MASK)
196
+
197
+#define NVME_PMREBS_SET_PMRSZU(pmrebs, val) \
198
+ (pmrebs |= (uint64_t)(val & PMREBS_PMRSZU_MASK) << PMREBS_PMRSZU_SHIFT)
199
+#define NVME_PMREBS_SET_RBB(pmrebs, val) \
200
+ (pmrebs |= (uint64_t)(val & PMREBS_RBB_MASK) << PMREBS_RBB_SHIFT)
201
+#define NVME_PMREBS_SET_PMRWBZ(pmrebs, val) \
202
+ (pmrebs |= (uint64_t)(val & PMREBS_PMRWBZ_MASK) << PMREBS_PMRWBZ_SHIFT)
203
+
204
+enum NvmePmrswtpShift {
205
+ PMRSWTP_PMRSWTU_SHIFT = 0,
206
+ PMRSWTP_PMRSWTV_SHIFT = 8,
207
+};
208
+
209
+enum NvmePmrswtpMask {
210
+ PMRSWTP_PMRSWTU_MASK = 0xf,
211
+ PMRSWTP_PMRSWTV_MASK = 0xffffff,
212
+};
213
+
214
+#define NVME_PMRSWTP_PMRSWTU(pmrswtp) \
215
+ ((pmrswtp >> PMRSWTP_PMRSWTU_SHIFT) & PMRSWTP_PMRSWTU_MASK)
216
+#define NVME_PMRSWTP_PMRSWTV(pmrswtp) \
217
+ ((pmrswtp >> PMRSWTP_PMRSWTV_SHIFT) & PMRSWTP_PMRSWTV_MASK)
218
+
219
+#define NVME_PMRSWTP_SET_PMRSWTU(pmrswtp, val) \
220
+ (pmrswtp |= (uint64_t)(val & PMRSWTP_PMRSWTU_MASK) << PMRSWTP_PMRSWTU_SHIFT)
221
+#define NVME_PMRSWTP_SET_PMRSWTV(pmrswtp, val) \
222
+ (pmrswtp |= (uint64_t)(val & PMRSWTP_PMRSWTV_MASK) << PMRSWTP_PMRSWTV_SHIFT)
223
+
224
+enum NvmePmrmscShift {
225
+ PMRMSC_CMSE_SHIFT = 1,
226
+ PMRMSC_CBA_SHIFT = 12,
227
+};
228
+
229
+enum NvmePmrmscMask {
230
+ PMRMSC_CMSE_MASK = 0x1,
231
+ PMRMSC_CBA_MASK = 0xfffffffffffff,
232
+};
233
+
234
+#define NVME_PMRMSC_CMSE(pmrmsc) \
235
+ ((pmrmsc >> PMRMSC_CMSE_SHIFT) & PMRMSC_CMSE_MASK)
236
+#define NVME_PMRMSC_CBA(pmrmsc) \
237
+ ((pmrmsc >> PMRMSC_CBA_SHIFT) & PMRMSC_CBA_MASK)
238
+
239
+#define NVME_PMRMSC_SET_CMSE(pmrmsc, val) \
240
+ (pmrmsc |= (uint64_t)(val & PMRMSC_CMSE_MASK) << PMRMSC_CMSE_SHIFT)
241
+#define NVME_PMRMSC_SET_CBA(pmrmsc, val) \
242
+ (pmrmsc |= (uint64_t)(val & PMRMSC_CBA_MASK) << PMRMSC_CBA_SHIFT)
243
+
244
typedef struct NvmeCmd {
245
uint8_t opcode;
246
uint8_t fuse;
13
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
247
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
14
index XXXXXXX..XXXXXXX 100644
248
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/block/nvme.c
249
--- a/hw/block/nvme.c
16
+++ b/hw/block/nvme.c
250
+++ b/hw/block/nvme.c
17
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
251
@@ -XXX,XX +XXX,XX @@
18
return NVME_NO_COMPLETE;
252
* -drive file=<file>,if=none,id=<drive_id>
253
* -device nvme,drive=<drive_id>,serial=<serial>,id=<id[optional]>, \
254
* cmb_size_mb=<cmb_size_mb[optional]>, \
255
+ * [pmrdev=<mem_backend_file_id>,] \
256
* num_queues=<N[optional]>
257
*
258
* Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at
259
* offset 0 in BAR2 and supports only WDS, RDS and SQS for now.
260
+ *
261
+ * cmb_size_mb= and pmrdev= options are mutually exclusive due to limitation
262
+ * in available BAR's. cmb_size_mb= will take precedence over pmrdev= when
263
+ * both provided.
264
+ * Enabling pmr emulation can be achieved by pointing to memory-backend-file.
265
+ * For example:
266
+ * -object memory-backend-file,id=<mem_id>,share=on,mem-path=<file_path>, \
267
+ * size=<size> .... -device nvme,...,pmrdev=<mem_id>
268
*/
269
270
#include "qemu/osdep.h"
271
@@ -XXX,XX +XXX,XX @@
272
#include "sysemu/sysemu.h"
273
#include "qapi/error.h"
274
#include "qapi/visitor.h"
275
+#include "sysemu/hostmem.h"
276
#include "sysemu/block-backend.h"
277
+#include "exec/ram_addr.h"
278
279
#include "qemu/log.h"
280
#include "qemu/module.h"
281
@@ -XXX,XX +XXX,XX @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data,
282
NVME_GUEST_ERR(nvme_ub_mmiowr_cmbsz_readonly,
283
"invalid write to read only CMBSZ, ignored");
284
return;
285
+ case 0xE00: /* PMRCAP */
286
+ NVME_GUEST_ERR(nvme_ub_mmiowr_pmrcap_readonly,
287
+ "invalid write to PMRCAP register, ignored");
288
+ return;
289
+ case 0xE04: /* TODO PMRCTL */
290
+ break;
291
+ case 0xE08: /* PMRSTS */
292
+ NVME_GUEST_ERR(nvme_ub_mmiowr_pmrsts_readonly,
293
+ "invalid write to PMRSTS register, ignored");
294
+ return;
295
+ case 0xE0C: /* PMREBS */
296
+ NVME_GUEST_ERR(nvme_ub_mmiowr_pmrebs_readonly,
297
+ "invalid write to PMREBS register, ignored");
298
+ return;
299
+ case 0xE10: /* PMRSWTP */
300
+ NVME_GUEST_ERR(nvme_ub_mmiowr_pmrswtp_readonly,
301
+ "invalid write to PMRSWTP register, ignored");
302
+ return;
303
+ case 0xE14: /* TODO PMRMSC */
304
+ break;
305
default:
306
NVME_GUEST_ERR(nvme_ub_mmiowr_invalid,
307
"invalid MMIO write,"
308
@@ -XXX,XX +XXX,XX @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
309
}
310
311
if (addr < sizeof(n->bar)) {
312
+ /*
313
+ * When PMRWBM bit 1 is set then read from
314
+ * from PMRSTS should ensure prior writes
315
+ * made it to persistent media
316
+ */
317
+ if (addr == 0xE08 &&
318
+ (NVME_PMRCAP_PMRWBM(n->bar.pmrcap) & 0x02)) {
319
+ qemu_ram_writeback(n->pmrdev->mr.ram_block,
320
+ 0, n->pmrdev->size);
321
+ }
322
memcpy(&val, ptr + addr, size);
323
} else {
324
NVME_GUEST_ERR(nvme_ub_mmiord_invalid_ofs,
325
@@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
326
error_setg(errp, "serial property not set");
327
return;
328
}
329
+
330
+ if (!n->cmb_size_mb && n->pmrdev) {
331
+ if (host_memory_backend_is_mapped(n->pmrdev)) {
332
+ char *path = object_get_canonical_path_component(OBJECT(n->pmrdev));
333
+ error_setg(errp, "can't use already busy memdev: %s", path);
334
+ g_free(path);
335
+ return;
336
+ }
337
+
338
+ if (!is_power_of_2(n->pmrdev->size)) {
339
+ error_setg(errp, "pmr backend size needs to be power of 2 in size");
340
+ return;
341
+ }
342
+
343
+ host_memory_backend_set_mapped(n->pmrdev, true);
344
+ }
345
+
346
blkconf_blocksizes(&n->conf);
347
if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk),
348
false, errp)) {
349
@@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
350
PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64 |
351
PCI_BASE_ADDRESS_MEM_PREFETCH, &n->ctrl_mem);
352
353
+ } else if (n->pmrdev) {
354
+ /* Controller Capabilities register */
355
+ NVME_CAP_SET_PMRS(n->bar.cap, 1);
356
+
357
+ /* PMR Capabities register */
358
+ n->bar.pmrcap = 0;
359
+ NVME_PMRCAP_SET_RDS(n->bar.pmrcap, 0);
360
+ NVME_PMRCAP_SET_WDS(n->bar.pmrcap, 0);
361
+ NVME_PMRCAP_SET_BIR(n->bar.pmrcap, 2);
362
+ NVME_PMRCAP_SET_PMRTU(n->bar.pmrcap, 0);
363
+ /* Turn on bit 1 support */
364
+ NVME_PMRCAP_SET_PMRWBM(n->bar.pmrcap, 0x02);
365
+ NVME_PMRCAP_SET_PMRTO(n->bar.pmrcap, 0);
366
+ NVME_PMRCAP_SET_CMSS(n->bar.pmrcap, 0);
367
+
368
+ /* PMR Control register */
369
+ n->bar.pmrctl = 0;
370
+ NVME_PMRCTL_SET_EN(n->bar.pmrctl, 0);
371
+
372
+ /* PMR Status register */
373
+ n->bar.pmrsts = 0;
374
+ NVME_PMRSTS_SET_ERR(n->bar.pmrsts, 0);
375
+ NVME_PMRSTS_SET_NRDY(n->bar.pmrsts, 0);
376
+ NVME_PMRSTS_SET_HSTS(n->bar.pmrsts, 0);
377
+ NVME_PMRSTS_SET_CBAI(n->bar.pmrsts, 0);
378
+
379
+ /* PMR Elasticity Buffer Size register */
380
+ n->bar.pmrebs = 0;
381
+ NVME_PMREBS_SET_PMRSZU(n->bar.pmrebs, 0);
382
+ NVME_PMREBS_SET_RBB(n->bar.pmrebs, 0);
383
+ NVME_PMREBS_SET_PMRWBZ(n->bar.pmrebs, 0);
384
+
385
+ /* PMR Sustained Write Throughput register */
386
+ n->bar.pmrswtp = 0;
387
+ NVME_PMRSWTP_SET_PMRSWTU(n->bar.pmrswtp, 0);
388
+ NVME_PMRSWTP_SET_PMRSWTV(n->bar.pmrswtp, 0);
389
+
390
+ /* PMR Memory Space Control register */
391
+ n->bar.pmrmsc = 0;
392
+ NVME_PMRMSC_SET_CMSE(n->bar.pmrmsc, 0);
393
+ NVME_PMRMSC_SET_CBA(n->bar.pmrmsc, 0);
394
+
395
+ pci_register_bar(pci_dev, NVME_PMRCAP_BIR(n->bar.pmrcap),
396
+ PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64 |
397
+ PCI_BASE_ADDRESS_MEM_PREFETCH, &n->pmrdev->mr);
398
}
399
400
for (i = 0; i < n->num_namespaces; i++) {
401
@@ -XXX,XX +XXX,XX @@ static void nvme_exit(PCIDevice *pci_dev)
402
if (n->cmb_size_mb) {
403
g_free(n->cmbuf);
404
}
405
+
406
+ if (n->pmrdev) {
407
+ host_memory_backend_set_mapped(n->pmrdev, false);
408
+ }
409
msix_uninit_exclusive_bar(pci_dev);
19
}
410
}
20
411
21
+static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
412
static Property nvme_props[] = {
22
+ NvmeRequest *req)
413
DEFINE_BLOCK_PROPERTIES(NvmeCtrl, conf),
23
+{
414
+ DEFINE_PROP_LINK("pmrdev", NvmeCtrl, pmrdev, TYPE_MEMORY_BACKEND,
24
+ NvmeRwCmd *rw = (NvmeRwCmd *)cmd;
415
+ HostMemoryBackend *),
25
+ const uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
416
DEFINE_PROP_STRING("serial", NvmeCtrl, serial),
26
+ const uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
417
DEFINE_PROP_UINT32("cmb_size_mb", NvmeCtrl, cmb_size_mb, 0),
27
+ uint64_t slba = le64_to_cpu(rw->slba);
418
DEFINE_PROP_UINT32("num_queues", NvmeCtrl, num_queues, 64),
28
+ uint32_t nlb = le16_to_cpu(rw->nlb) + 1;
419
diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs
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
+ }
35
+
36
+ req->has_sg = false;
37
+ block_acct_start(blk_get_stats(n->conf.blk), &req->acct, 0,
38
+ BLOCK_ACCT_WRITE);
39
+ req->aiocb = blk_aio_pwrite_zeroes(n->conf.blk, aio_slba, aio_nlb,
40
+ BDRV_REQ_MAY_UNMAP, nvme_rw_cb, req);
41
+ return NVME_NO_COMPLETE;
42
+}
43
+
44
static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
45
NvmeRequest *req)
46
{
47
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
48
switch (cmd->opcode) {
49
case NVME_CMD_FLUSH:
50
return nvme_flush(n, ns, cmd, req);
51
+ case NVME_CMD_WRITE_ZEROS:
52
+ return nvme_write_zeros(n, ns, cmd, req);
53
case NVME_CMD_WRITE:
54
case NVME_CMD_READ:
55
return nvme_rw(n, ns, cmd, req);
56
@@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev)
57
id->sqes = (0x6 << 4) | 0x6;
58
id->cqes = (0x4 << 4) | 0x4;
59
id->nn = cpu_to_le32(n->num_namespaces);
60
+ id->oncs = cpu_to_le16(NVME_ONCS_WRITE_ZEROS);
61
id->psd[0].mp = cpu_to_le16(0x9c4);
62
id->psd[0].enlat = cpu_to_le32(0x10);
63
id->psd[0].exlat = cpu_to_le32(0x4);
64
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
65
index XXXXXXX..XXXXXXX 100644
420
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/block/nvme.h
421
--- a/hw/block/Makefile.objs
67
+++ b/hw/block/nvme.h
422
+++ b/hw/block/Makefile.objs
68
@@ -XXX,XX +XXX,XX @@ enum NvmeIoCommands {
423
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
69
NVME_CMD_READ = 0x02,
424
common-obj-$(CONFIG_XEN) += xen-block.o
70
NVME_CMD_WRITE_UNCOR = 0x04,
425
common-obj-$(CONFIG_ECC) += ecc.o
71
NVME_CMD_COMPARE = 0x05,
426
common-obj-$(CONFIG_ONENAND) += onenand.o
72
+ NVME_CMD_WRITE_ZEROS = 0x08,
427
-common-obj-$(CONFIG_NVME_PCI) += nvme.o
73
NVME_CMD_DSM = 0x09,
428
common-obj-$(CONFIG_SWIM) += swim.o
74
};
429
75
430
common-obj-$(CONFIG_SH4) += tc58128.o
431
432
obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
433
obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
434
+obj-$(CONFIG_NVME_PCI) += nvme.o
435
436
obj-y += dataplane/
437
diff --git a/hw/block/trace-events b/hw/block/trace-events
438
index XXXXXXX..XXXXXXX 100644
439
--- a/hw/block/trace-events
440
+++ b/hw/block/trace-events
441
@@ -XXX,XX +XXX,XX @@ nvme_ub_mmiowr_ssreset_w1c_unsupported(void) "attempted to W1C CSTS.NSSRO but CA
442
nvme_ub_mmiowr_ssreset_unsupported(void) "attempted NVM subsystem reset but CAP.NSSRS is zero (not supported)"
443
nvme_ub_mmiowr_cmbloc_reserved(void) "invalid write to reserved CMBLOC when CMBSZ is zero, ignored"
444
nvme_ub_mmiowr_cmbsz_readonly(void) "invalid write to read only CMBSZ, ignored"
445
+nvme_ub_mmiowr_pmrcap_readonly(void) "invalid write to read only PMRCAP, ignored"
446
+nvme_ub_mmiowr_pmrsts_readonly(void) "invalid write to read only PMRSTS, ignored"
447
+nvme_ub_mmiowr_pmrebs_readonly(void) "invalid write to read only PMREBS, ignored"
448
+nvme_ub_mmiowr_pmrswtp_readonly(void) "invalid write to read only PMRSWTP, ignored"
449
nvme_ub_mmiowr_invalid(uint64_t offset, uint64_t data) "invalid MMIO write, offset=0x%"PRIx64", data=0x%"PRIx64""
450
nvme_ub_mmiord_misaligned32(uint64_t offset) "MMIO read not 32-bit aligned, offset=0x%"PRIx64""
451
nvme_ub_mmiord_toosmall(uint64_t offset) "MMIO read smaller than 32-bits, offset=0x%"PRIx64""
76
--
452
--
77
1.8.3.1
453
2.25.3
78
454
79
455
diff view generated by jsdifflib
1
Instead of manually calling blk_resume_after_migration() in migration
1
The QMP handler qmp_object_add() and the implementation of --object in
2
code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend
2
qemu-storage-daemon can share most of the code. Currently,
3
activation with cache invalidation into a single function. This is
3
qemu-storage-daemon calls qmp_object_add(), but this is not correct
4
achieved with a new callback in BdrvChildRole that is called by
4
because different visitors need to be used.
5
bdrv_invalidate_cache_all().
5
6
As a first step towards a fix, make qmp_object_add() a wrapper around a
7
new function user_creatable_add_dict() that can get an additional
8
parameter. The handling of "props" is only required for compatibility
9
and not required for the qemu-storage-daemon command line, so it stays
10
in qmp_object_add().
6
11
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
---
13
---
10
block.c | 12 +++++++++-
14
include/qom/object_interfaces.h | 12 ++++++++++++
11
block/block-backend.c | 56 +++++++++++++++++++++++------------------------
15
qom/object_interfaces.c | 27 +++++++++++++++++++++++++++
12
include/block/block.h | 2 --
16
qom/qom-qmp-cmds.c | 24 +-----------------------
13
include/block/block_int.h | 5 +++++
17
3 files changed, 40 insertions(+), 23 deletions(-)
14
migration/migration.c | 3 ---
15
migration/savevm.c | 3 ---
16
qmp.c | 6 -----
17
7 files changed, 44 insertions(+), 43 deletions(-)
18
18
19
diff --git a/block.c b/block.c
19
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
20
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
21
--- a/include/qom/object_interfaces.h
22
+++ b/block.c
22
+++ b/include/qom/object_interfaces.h
23
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
23
@@ -XXX,XX +XXX,XX @@ Object *user_creatable_add_type(const char *type, const char *id,
24
24
const QDict *qdict,
25
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
25
Visitor *v, Error **errp);
26
{
26
27
- BdrvChild *child;
27
+/**
28
+ BdrvChild *child, *parent;
28
+ * user_creatable_add_dict:
29
Error *local_err = NULL;
29
+ * @qdict: the object definition
30
int ret;
30
+ * @errp: if an error occurs, a pointer to an area to store the error
31
31
+ *
32
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
32
+ * Create an instance of the user creatable object that is defined by
33
error_setg_errno(errp, -ret, "Could not refresh total sector count");
33
+ * @qdict. The object type is taken from the QDict key 'qom-type', its
34
return;
34
+ * ID from the key 'id'. The remaining entries in @qdict are used to
35
}
35
+ * initialize the object properties.
36
+ */
37
+void user_creatable_add_dict(QDict *qdict, Error **errp);
36
+
38
+
37
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
39
/**
38
+ if (parent->role->activate) {
40
* user_creatable_add_opts:
39
+ parent->role->activate(parent, &local_err);
41
* @opts: the object definition
40
+ if (local_err) {
42
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
41
+ error_propagate(errp, local_err);
43
index XXXXXXX..XXXXXXX 100644
42
+ return;
44
--- a/qom/object_interfaces.c
43
+ }
45
+++ b/qom/object_interfaces.c
44
+ }
46
@@ -XXX,XX +XXX,XX @@
45
+ }
47
#include "qapi/qmp/qerror.h"
48
#include "qapi/qmp/qjson.h"
49
#include "qapi/qmp/qstring.h"
50
+#include "qapi/qobject-input-visitor.h"
51
#include "qom/object_interfaces.h"
52
#include "qemu/help_option.h"
53
#include "qemu/module.h"
54
@@ -XXX,XX +XXX,XX @@ out:
55
return obj;
46
}
56
}
47
57
48
void bdrv_invalidate_cache_all(Error **errp)
58
+void user_creatable_add_dict(QDict *qdict, 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
+{
59
+{
66
+ BlockBackend *blk = child->opaque;
60
+ Visitor *v;
67
+ Error *local_err = NULL;
61
+ Object *obj;
62
+ g_autofree char *type = NULL;
63
+ g_autofree char *id = NULL;
68
+
64
+
69
+ if (!blk->disable_perm) {
65
+ type = g_strdup(qdict_get_try_str(qdict, "qom-type"));
66
+ if (!type) {
67
+ error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
70
+ return;
68
+ return;
71
+ }
69
+ }
70
+ qdict_del(qdict, "qom-type");
72
+
71
+
73
+ blk->disable_perm = false;
72
+ id = g_strdup(qdict_get_try_str(qdict, "id"));
74
+
73
+ if (!id) {
75
+ blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
74
+ error_setg(errp, QERR_MISSING_PARAMETER, "id");
76
+ if (local_err) {
77
+ error_propagate(errp, local_err);
78
+ blk->disable_perm = true;
79
+ return;
75
+ return;
80
+ }
76
+ }
77
+ qdict_del(qdict, "id");
78
+
79
+ v = qobject_input_visitor_new(QOBJECT(qdict));
80
+ obj = user_creatable_add_type(type, id, qdict, v, errp);
81
+ visit_free(v);
82
+ object_unref(obj);
81
+}
83
+}
82
+
84
83
static const BdrvChildRole child_root = {
85
Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
84
.inherit_options = blk_root_inherit_options,
86
{
85
87
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
86
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
88
index XXXXXXX..XXXXXXX 100644
87
89
--- a/qom/qom-qmp-cmds.c
88
.drained_begin = blk_root_drained_begin,
90
+++ b/qom/qom-qmp-cmds.c
89
.drained_end = blk_root_drained_end,
91
@@ -XXX,XX +XXX,XX @@
90
+
92
#include "qapi/qapi-commands-qom.h"
91
+ .activate = blk_root_activate,
93
#include "qapi/qmp/qdict.h"
92
};
94
#include "qapi/qmp/qerror.h"
93
95
-#include "qapi/qobject-input-visitor.h"
94
/*
96
#include "qemu/cutils.h"
95
@@ -XXX,XX +XXX,XX @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
97
#include "qom/object_interfaces.h"
96
*shared_perm = blk->shared_perm;
98
#include "qom/qom-qobject.h"
97
}
99
@@ -XXX,XX +XXX,XX @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
98
100
{
99
-/*
101
QObject *props;
100
- * Notifies the user of all BlockBackends that migration has completed. qdev
102
QDict *pdict;
101
- * devices can tighten their permissions in response (specifically revoke
103
- Visitor *v;
102
- * shared write permissions that we needed for storage migration).
104
- Object *obj;
103
- *
105
- g_autofree char *type = NULL;
104
- * If an error is returned, the VM cannot be allowed to be resumed.
106
- g_autofree char *id = NULL;
105
- */
106
-void blk_resume_after_migration(Error **errp)
107
-{
108
- BlockBackend *blk;
109
- Error *local_err = NULL;
110
-
107
-
111
- for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
108
- type = g_strdup(qdict_get_try_str(qdict, "qom-type"));
112
- if (!blk->disable_perm) {
109
- if (!type) {
113
- continue;
110
- error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
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;
111
- return;
199
- }
112
- }
113
- qdict_del(qdict, "qom-type");
200
-
114
-
201
if (runstate_check(RUN_STATE_INMIGRATE)) {
115
- id = g_strdup(qdict_get_try_str(qdict, "id"));
202
autostart = 1;
116
- if (!id) {
203
} else {
117
- error_setg(errp, QERR_MISSING_PARAMETER, "id");
118
- return;
119
- }
120
- qdict_del(qdict, "id");
121
122
props = qdict_get(qdict, "props");
123
if (props) {
124
@@ -XXX,XX +XXX,XX @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
125
qobject_unref(pdict);
126
}
127
128
- v = qobject_input_visitor_new(QOBJECT(qdict));
129
- obj = user_creatable_add_type(type, id, qdict, v, errp);
130
- visit_free(v);
131
- object_unref(obj);
132
+ user_creatable_add_dict(qdict, errp);
133
}
134
135
void qmp_object_del(const char *id, Error **errp)
204
--
136
--
205
1.8.3.1
137
2.25.3
206
138
207
139
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
Now that the block layer takes care to request a lot less permissions
2
for inactive nodes, the special-casing in file-posix isn't necessary any
3
more.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
8
block/file-posix.c | 33 ---------------------------------
9
1 file changed, 33 deletions(-)
10
11
diff --git a/block/file-posix.c b/block/file-posix.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/block/file-posix.c
14
+++ b/block/file-posix.c
15
@@ -XXX,XX +XXX,XX @@ static void raw_abort_perm_update(BlockDriverState *bs)
16
raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
17
}
18
19
-static int raw_inactivate(BlockDriverState *bs)
20
-{
21
- int ret;
22
- uint64_t perm = 0;
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
--
70
1.8.3.1
71
72
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
For the 'alloc' command, accepting an offset in bytes but a length
4
in sectors, and reporting output in sectors, is confusing. Do
5
everything in bytes, and adjust the expected output accordingly.
6
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>
11
---
12
qemu-io-cmds.c | 30 ++++++++++++++++++------------
13
tests/qemu-iotests/019.out | 8 ++++----
14
tests/qemu-iotests/common.pattern | 2 +-
15
3 files changed, 23 insertions(+), 17 deletions(-)
16
17
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-io-cmds.c
20
+++ b/qemu-io-cmds.c
21
@@ -XXX,XX +XXX,XX @@ out:
22
static int alloc_f(BlockBackend *blk, int argc, char **argv)
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
}
32
33
if (argc == 3) {
34
- nb_sectors = cvtnum(argv[2]);
35
- if (nb_sectors < 0) {
36
- print_cvtnum_err(nb_sectors, argv[2]);
37
+ count = cvtnum(argv[2]);
38
+ if (count < 0) {
39
+ print_cvtnum_err(count, argv[2]);
40
return 0;
41
- } else if (nb_sectors > INT_MAX) {
42
- printf("length argument cannot exceed %d, given %s\n",
43
- INT_MAX, argv[2]);
44
+ } else if (count > INT_MAX * BDRV_SECTOR_SIZE) {
45
+ printf("length argument cannot exceed %llu, given %s\n",
46
+ INT_MAX * BDRV_SECTOR_SIZE, argv[2]);
47
return 0;
48
}
49
} else {
50
- nb_sectors = 1;
51
+ count = BDRV_SECTOR_SIZE;
52
+ }
53
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
54
+ printf("%" PRId64 " is not a sector-aligned value for 'count'\n",
55
+ count);
56
+ return 0;
57
}
58
+ nb_sectors = count >> BDRV_SECTOR_BITS;
59
60
remaining = nb_sectors;
61
sum_alloc = 0;
62
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
63
64
cvtstr(offset, s1, sizeof(s1));
65
66
- printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n",
67
- sum_alloc, nb_sectors, s1);
68
+ printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n",
69
+ sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, s1);
70
return 0;
71
}
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
123
--
124
1.8.3.1
125
126
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Mixing byte offset and sector allocation counts is a bit
4
confusing. Also, reporting n/m sectors, where m decreases
5
according to the remaining size of the file, isn't really
6
adding any useful information; and reporting an offset at
7
both the front and end of the line, with large amounts of
8
whitespace, is pointless. Update the output to use byte
9
counts and shorter lines, then adjust the affected tests
10
(./check -qcow2 102, ./check -vpc 146).
11
12
Note that 'qemu-io map' is MUCH weaker than 'qemu-img map';
13
the former only shows which regions of the active layer are
14
allocated, without regards to where the allocation comes from
15
or whether the allocated portion is known to read as zero
16
(because it is using the weaker bdrv_is_allocated()); while the
17
latter (especially in --output=json mode) reports more details
18
from bdrv_get_block_status().
19
20
Signed-off-by: Eric Blake <eblake@redhat.com>
21
Message-id: 20170429191419.30051-4-eblake@redhat.com
22
Reviewed-by: Max Reitz <mreitz@redhat.com>
23
Signed-off-by: Max Reitz <mreitz@redhat.com>
24
---
25
qemu-io-cmds.c | 11 ++++++-----
26
tests/qemu-iotests/102.out | 4 ++--
27
tests/qemu-iotests/146.out | 30 +++++++++++++++---------------
28
3 files changed, 23 insertions(+), 22 deletions(-)
29
30
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/qemu-io-cmds.c
33
+++ b/qemu-io-cmds.c
34
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
35
{
36
int64_t offset;
37
int64_t nb_sectors, total_sectors;
38
- char s1[64];
39
+ char s1[64], s2[64];
40
int64_t num;
41
int ret;
42
const char *retstr;
43
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
44
}
45
46
retstr = ret ? " allocated" : "not allocated";
47
- cvtstr(offset << 9ULL, s1, sizeof(s1));
48
- printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
49
- "at offset %s (%d)\n",
50
- offset << 9ULL, num, nb_sectors, retstr, s1, ret);
51
+ cvtstr(num << BDRV_SECTOR_BITS, s1, sizeof(s1));
52
+ cvtstr(offset << BDRV_SECTOR_BITS, s2, sizeof(s2));
53
+ printf("%s (0x%" PRIx64 ") bytes %s at offset %s (0x%" PRIx64 ")\n",
54
+ s1, num << BDRV_SECTOR_BITS, retstr,
55
+ s2, offset << BDRV_SECTOR_BITS);
56
57
offset += num;
58
nb_sectors -= num;
59
diff --git a/tests/qemu-iotests/102.out b/tests/qemu-iotests/102.out
60
index XXXXXXX..XXXXXXX 100644
61
--- a/tests/qemu-iotests/102.out
62
+++ b/tests/qemu-iotests/102.out
63
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
64
wrote 65536/65536 bytes at offset 0
65
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
66
Image resized.
67
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
68
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
69
Offset Length Mapped to File
70
71
=== Testing map on an image file truncated outside of qemu ===
72
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 0
73
Image resized.
74
QEMU X.Y.Z monitor - type 'help' for more information
75
(qemu) qemu-io drv0 map
76
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
77
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
78
*** done
79
diff --git a/tests/qemu-iotests/146.out b/tests/qemu-iotests/146.out
80
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/146.out
82
+++ b/tests/qemu-iotests/146.out
83
@@ -XXX,XX +XXX,XX @@ QA output created by 146
84
85
=== Testing VPC Autodetect ===
86
87
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
88
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
89
90
=== Testing VPC with current_size force ===
91
92
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
93
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
94
95
=== Testing VPC with chs force ===
96
97
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
98
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
99
100
=== Testing Hyper-V Autodetect ===
101
102
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
103
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
104
105
=== Testing Hyper-V with current_size force ===
106
107
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
108
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
109
110
=== Testing Hyper-V with chs force ===
111
112
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
113
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
114
115
=== Testing d2v Autodetect ===
116
117
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
118
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
119
120
=== Testing d2v with current_size force ===
121
122
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
123
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
124
125
=== Testing d2v with chs force ===
126
127
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
128
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
129
130
=== Testing Image create, default ===
131
132
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296
133
134
=== Read created image, default opts ====
135
136
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
137
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
138
139
=== Read created image, force_size_calc=chs ====
140
141
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
142
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
143
144
=== Read created image, force_size_calc=current_size ====
145
146
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
147
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
148
149
=== Testing Image create, force_size ===
150
151
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296 forc
152
153
=== Read created image, default opts ====
154
155
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
156
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
157
158
=== Read created image, force_size_calc=chs ====
159
160
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
161
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
162
163
=== Read created image, force_size_calc=current_size ====
164
165
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
166
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
167
*** done
168
--
169
1.8.3.1
170
171
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
4
any I/O to fit within device boundaries. Additionally, when using a
5
minimum alignment of 4k, we want to ensure the block layer does proper
6
read-modify-write rather than requesting I/O on a slice of a sector.
7
Let's enforce that the contract is obeyed when using blkdebug. For
8
now, blkdebug only allows alignment overrides, and just inherits other
9
limits from whatever device it is wrapping, but a future patch will
10
further enhance things.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Message-id: 20170429191419.30051-5-eblake@redhat.com
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
18
block/blkdebug.c | 14 ++++++++++++++
19
1 file changed, 14 insertions(+)
20
21
diff --git a/block/blkdebug.c b/block/blkdebug.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/blkdebug.c
24
+++ b/block/blkdebug.c
25
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
26
BDRVBlkdebugState *s = bs->opaque;
27
BlkdebugRule *rule = NULL;
28
29
+ /* Sanity check block layer guarantees */
30
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
31
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
32
+ if (bs->bl.max_transfer) {
33
+ assert(bytes <= bs->bl.max_transfer);
34
+ }
35
+
36
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
37
uint64_t inject_offset = rule->options.inject.offset;
38
39
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
40
BDRVBlkdebugState *s = bs->opaque;
41
BlkdebugRule *rule = NULL;
42
43
+ /* Sanity check block layer guarantees */
44
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
45
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
46
+ if (bs->bl.max_transfer) {
47
+ assert(bytes <= bs->bl.max_transfer);
48
+ }
49
+
50
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
51
uint64_t inject_offset = rule->options.inject.offset;
52
53
--
54
1.8.3.1
55
56
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than 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
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than store into a local variable, then copy to the struct
4
if the value is valid, then reporting errors otherwise, it is
5
simpler to just store into the struct and report errors if the
6
value is invalid. This however requires that the struct store
7
a 64-bit number, rather than a narrower type. Likewise, setting
8
a sane errno value in ret prior to the sequence of parsing and
9
jumping to out: on error makes it easier for the next patch to
10
add a chain of similar checks.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Message-id: 20170429191419.30051-8-eblake@redhat.com
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
---
17
block/blkdebug.c | 16 ++++++----------
18
1 file changed, 6 insertions(+), 10 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
23
+++ b/block/blkdebug.c
24
@@ -XXX,XX +XXX,XX @@
25
typedef struct BDRVBlkdebugState {
26
int state;
27
int new_state;
28
- int align;
29
+ uint64_t align;
30
31
/* For blkdebug_refresh_filename() */
32
char *config_file;
33
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
34
BDRVBlkdebugState *s = bs->opaque;
35
QemuOpts *opts;
36
Error *local_err = NULL;
37
- uint64_t align;
38
int ret;
39
40
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
41
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
42
bs->file->bs->supported_write_flags;
43
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
44
bs->file->bs->supported_zero_flags;
45
+ ret = -EINVAL;
46
47
/* Set request alignment */
48
- align = qemu_opt_get_size(opts, "align", 0);
49
- if (align < INT_MAX && is_power_of_2(align)) {
50
- s->align = align;
51
- } else if (align) {
52
- error_setg(errp, "Invalid alignment");
53
- ret = -EINVAL;
54
+ s->align = qemu_opt_get_size(opts, "align", 0);
55
+ if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
56
+ error_setg(errp, "Cannot meet constraints with align %" PRIu64,
57
+ s->align);
58
goto out;
59
}
60
61
ret = 0;
62
- goto out;
63
-
64
out:
65
if (ret < 0) {
66
g_free(s->config_file);
67
--
68
1.8.3.1
69
70
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Make it easier to simulate various unusual hardware setups (for
4
example, recent commits 3482b9b and b8d0a98 affect the Dell
5
Equallogic iSCSI with its 15M preferred and maximum unmap and
6
write zero sizing, or b2f95fe deals with the Linux loopback
7
block device having a max_transfer of 64k), by allowing blkdebug
8
to wrap any other device with further restrictions on various
9
alignments.
10
11
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>
15
---
16
block/blkdebug.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-
17
qapi/block-core.json | 33 ++++++++++++++++--
18
2 files changed, 125 insertions(+), 4 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
23
+++ b/block/blkdebug.c
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
162
index XXXXXXX..XXXXXXX 100644
163
--- a/qapi/block-core.json
164
+++ b/qapi/block-core.json
165
@@ -XXX,XX +XXX,XX @@
166
#
167
# @config: filename of the configuration file
168
#
169
-# @align: required alignment for requests in bytes,
170
-# must be power of 2, or 0 for default
171
+# @align: required alignment for requests in bytes, must be
172
+# positive power of 2, or 0 for default
173
+#
174
+# @max-transfer: maximum size for I/O transfers in bytes, must be
175
+# positive multiple of @align and of the underlying
176
+# file's request alignment (but need not be a power of
177
+# 2), or 0 for default (since 2.10)
178
+#
179
+# @opt-write-zero: preferred alignment for write zero requests in bytes,
180
+# must be positive multiple of @align and of the
181
+# underlying file's request alignment (but need not be a
182
+# power of 2), or 0 for default (since 2.10)
183
+#
184
+# @max-write-zero: maximum size for write zero requests in bytes, must be
185
+# positive multiple of @align, of @opt-write-zero, and of
186
+# the underlying file's request alignment (but need not
187
+# be a power of 2), or 0 for default (since 2.10)
188
+#
189
+# @opt-discard: preferred alignment for discard requests in bytes, must
190
+# be positive multiple of @align and of the underlying
191
+# file's request alignment (but need not be a power of
192
+# 2), or 0 for default (since 2.10)
193
+#
194
+# @max-discard: maximum size for discard requests in bytes, must be
195
+# positive multiple of @align, of @opt-discard, and of
196
+# the underlying file's request alignment (but need not
197
+# be a power of 2), or 0 for default (since 2.10)
198
#
199
# @inject-error: array of error injection descriptions
200
#
201
@@ -XXX,XX +XXX,XX @@
202
{ 'struct': 'BlockdevOptionsBlkdebug',
203
'data': { 'image': 'BlockdevRef',
204
'*config': 'str',
205
- '*align': 'int',
206
+ '*align': 'int', '*max-transfer': 'int32',
207
+ '*opt-write-zero': 'int32', '*max-write-zero': 'int32',
208
+ '*opt-discard': 'int32', '*max-discard': 'int32',
209
'*inject-error': ['BlkdebugInjectErrorOptions'],
210
'*set-state': ['BlkdebugSetStateOptions'] } }
211
212
--
213
1.8.3.1
214
215
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Use blkdebug's new geometry constraints to emulate setups that
4
have needed past regression fixes: write zeroes asserting
5
when running through a loopback block device with max-transfer
6
smaller than cluster size, and discard rounding away portions
7
of requests not aligned to preferred boundaries. Also, add
8
coverage that the block layer is honoring max transfer limits.
9
10
For now, a single iotest performs all actions, with the idea
11
that we can add future blkdebug constraint test cases in the
12
same file; but it can be split into multiple iotests if we find
13
reason to run one portion of the test in more setups than what
14
are possible in the other.
15
16
For reference, the final portion of the test (checking whether
17
discard passes as much as possible to the lowest layers of the
18
stack) works as follows:
19
20
qemu-io: discard 30M at 80000001, passed to blkdebug
21
blkdebug: discard 511 bytes at 80000001, -ENOTSUP (smaller than
22
blkdebug's 512 align)
23
blkdebug: discard 14371328 bytes at 80000512, passed to qcow2
24
qcow2: discard 739840 bytes at 80000512, -ENOTSUP (smaller than
25
qcow2's 1M align)
26
qcow2: discard 13M bytes at 77M, succeeds
27
blkdebug: discard 15M bytes at 90M, passed to qcow2
28
qcow2: discard 15M bytes at 90M, succeeds
29
blkdebug: discard 1356800 bytes at 105M, passed to qcow2
30
qcow2: discard 1M at 105M, succeeds
31
qcow2: discard 308224 bytes at 106M, -ENOTSUP (smaller than qcow2's
32
1M align)
33
blkdebug: discard 1 byte at 111457280, -ENOTSUP (smaller than
34
blkdebug's 512 align)
35
36
Signed-off-by: Eric Blake <eblake@redhat.com>
37
Reviewed-by: Max Reitz <mreitz@redhat.com>
38
Message-id: 20170429191419.30051-10-eblake@redhat.com
39
[mreitz: For cooperation with image locking, add -r to the qemu-io
40
invocation which verifies the image content]
41
Signed-off-by: Max Reitz <mreitz@redhat.com>
42
---
43
tests/qemu-iotests/177 | 114 +++++++++++++++++++++++++++++++++++++++++++++
44
tests/qemu-iotests/177.out | 49 +++++++++++++++++++
45
tests/qemu-iotests/group | 1 +
46
3 files changed, 164 insertions(+)
47
create mode 100755 tests/qemu-iotests/177
48
create mode 100644 tests/qemu-iotests/177.out
49
50
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
51
new file mode 100755
52
index XXXXXXX..XXXXXXX
53
--- /dev/null
54
+++ b/tests/qemu-iotests/177
55
@@ -XXX,XX +XXX,XX @@
56
+#!/bin/bash
57
+#
58
+# Test corner cases with unusual block geometries
59
+#
60
+# Copyright (C) 2016-2017 Red Hat, Inc.
61
+#
62
+# This program is free software; you can redistribute it and/or modify
63
+# it under the terms of the GNU General Public License as published by
64
+# the Free Software Foundation; either version 2 of the License, or
65
+# (at your option) any later version.
66
+#
67
+# This program is distributed in the hope that it will be useful,
68
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70
+# GNU General Public License for more details.
71
+#
72
+# You should have received a copy of the GNU General Public License
73
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
74
+#
75
+
76
+# creator
77
+owner=eblake@redhat.com
78
+
79
+seq=`basename $0`
80
+echo "QA output created by $seq"
81
+
82
+here=`pwd`
83
+status=1    # failure is the default!
84
+
85
+_cleanup()
86
+{
87
+    _cleanup_test_img
88
+}
89
+trap "_cleanup; exit \$status" 0 1 2 3 15
90
+
91
+# get standard environment, filters and checks
92
+. ./common.rc
93
+. ./common.filter
94
+
95
+_supported_fmt qcow2
96
+_supported_proto file
97
+
98
+CLUSTER_SIZE=1M
99
+size=128M
100
+options=driver=blkdebug,image.driver=qcow2
101
+
102
+echo
103
+echo "== setting up files =="
104
+
105
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
106
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
107
+_make_test_img -b "$TEST_IMG.base"
108
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
109
+
110
+# Limited to 64k max-transfer
111
+echo
112
+echo "== constrained alignment and max-transfer =="
113
+limits=align=4k,max-transfer=64k
114
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
115
+ -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
116
+
117
+echo
118
+echo "== write zero with constrained max-transfer =="
119
+limits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
120
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
121
+ -c "write -z 8003584 2093056" | _filter_qemu_io
122
+
123
+# non-power-of-2 write-zero/discard alignments
124
+echo
125
+echo "== non-power-of-2 write zeroes limits =="
126
+
127
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
128
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
129
+ -c "write -z 32M 32M" | _filter_qemu_io
130
+
131
+echo
132
+echo "== non-power-of-2 discard limits =="
133
+
134
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
135
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
136
+ -c "discard 80000001 30M" | _filter_qemu_io
137
+
138
+echo
139
+echo "== verify image content =="
140
+
141
+function verify_io()
142
+{
143
+ if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
144
+     grep "compat: 0.10" > /dev/null); then
145
+ # For v2 images, discarded clusters are read from the backing file
146
+ discarded=11
147
+ else
148
+ # Discarded clusters are zeroed for v3 or later
149
+ discarded=0
150
+ fi
151
+
152
+ echo read -P 22 0 1000
153
+ echo read -P 33 1000 128k
154
+ echo read -P 22 132072 7871512
155
+ echo read -P 0 8003584 2093056
156
+ echo read -P 22 10096640 23457792
157
+ echo read -P 0 32M 32M
158
+ echo read -P 22 64M 13M
159
+ echo read -P $discarded 77M 29M
160
+ echo read -P 22 106M 22M
161
+}
162
+
163
+verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
164
+
165
+_check_test_img
166
+
167
+# success, all done
168
+echo "*** done"
169
+status=0
170
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
171
new file mode 100644
172
index XXXXXXX..XXXXXXX
173
--- /dev/null
174
+++ b/tests/qemu-iotests/177.out
175
@@ -XXX,XX +XXX,XX @@
176
+QA output created by 177
177
+
178
+== setting up files ==
179
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
180
+wrote 134217728/134217728 bytes at offset 0
181
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 134217728/134217728 bytes at offset 0
184
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+
186
+== constrained alignment and max-transfer ==
187
+wrote 131072/131072 bytes at offset 1000
188
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
189
+read 131072/131072 bytes at offset 1000
190
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
191
+
192
+== write zero with constrained max-transfer ==
193
+wrote 2093056/2093056 bytes at offset 8003584
194
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+
196
+== non-power-of-2 write zeroes limits ==
197
+wrote 33554432/33554432 bytes at offset 33554432
198
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+
200
+== non-power-of-2 discard limits ==
201
+discard 31457280/31457280 bytes at offset 80000001
202
+30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+
204
+== verify image content ==
205
+read 1000/1000 bytes at offset 0
206
+1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
207
+read 131072/131072 bytes at offset 1000
208
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+read 7871512/7871512 bytes at offset 132072
210
+7.507 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+read 2093056/2093056 bytes at offset 8003584
212
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+read 23457792/23457792 bytes at offset 10096640
214
+22.371 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
215
+read 33554432/33554432 bytes at offset 33554432
216
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
217
+read 13631488/13631488 bytes at offset 67108864
218
+13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
219
+read 30408704/30408704 bytes at offset 80740352
220
+29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
221
+read 23068672/23068672 bytes at offset 111149056
222
+22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
223
+No errors were found on the image.
224
+*** done
225
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
226
index XXXXXXX..XXXXXXX 100644
227
--- a/tests/qemu-iotests/group
228
+++ b/tests/qemu-iotests/group
229
@@ -XXX,XX +XXX,XX @@
230
174 auto
231
175 auto quick
232
176 rw auto backing
233
+177 rw auto quick
234
181 rw auto migration
235
182 rw auto quick
236
--
237
1.8.3.1
238
239
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
In order to keep checkpatch happy when the next patch changes
4
indentation, we first have to shorten some long lines. The easiest
5
approach is to use a new variable in place of
6
'offset & L2E_OFFSET_MASK', except that 'offset' is the best name
7
for that variable. Change '[old_]offset' to '[old_]entry' to
8
make room.
9
10
While touching things, also fix checkpatch warnings about unusual
11
'for' statements.
12
13
Suggested by Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Eric Blake <eblake@redhat.com>
15
Message-id: 20170507000552.20847-2-eblake@redhat.com
16
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-refcount.c | 42 ++++++++++++++++++++++--------------------
20
1 file changed, 22 insertions(+), 20 deletions(-)
21
22
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/qcow2-refcount.c
25
+++ b/block/qcow2-refcount.c
26
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
27
int64_t l1_table_offset, int l1_size, int addend)
28
{
29
BDRVQcow2State *s = bs->opaque;
30
- uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount;
31
+ uint64_t *l1_table, *l2_table, l2_offset, entry, l1_size2, refcount;
32
bool l1_allocated = false;
33
- int64_t old_offset, old_l2_offset;
34
+ int64_t old_entry, old_l2_offset;
35
int i, j, l1_modified = 0, nb_csectors;
36
int ret;
37
38
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
39
goto fail;
40
}
41
42
- for(i = 0;i < l1_size; i++)
43
+ for (i = 0; i < l1_size; i++) {
44
be64_to_cpus(&l1_table[i]);
45
+ }
46
} else {
47
assert(l1_size == s->l1_size);
48
l1_table = s->l1_table;
49
l1_allocated = false;
50
}
51
52
- for(i = 0; i < l1_size; i++) {
53
+ for (i = 0; i < l1_size; i++) {
54
l2_offset = l1_table[i];
55
if (l2_offset) {
56
old_l2_offset = l2_offset;
57
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
58
goto fail;
59
}
60
61
- for(j = 0; j < s->l2_size; j++) {
62
+ for (j = 0; j < s->l2_size; j++) {
63
uint64_t cluster_index;
64
+ uint64_t offset;
65
66
- offset = be64_to_cpu(l2_table[j]);
67
- old_offset = offset;
68
- offset &= ~QCOW_OFLAG_COPIED;
69
+ entry = be64_to_cpu(l2_table[j]);
70
+ old_entry = entry;
71
+ entry &= ~QCOW_OFLAG_COPIED;
72
+ offset = entry & L2E_OFFSET_MASK;
73
74
- switch (qcow2_get_cluster_type(offset)) {
75
+ switch (qcow2_get_cluster_type(entry)) {
76
case QCOW2_CLUSTER_COMPRESSED:
77
- nb_csectors = ((offset >> s->csize_shift) &
78
+ nb_csectors = ((entry >> s->csize_shift) &
79
s->csize_mask) + 1;
80
if (addend != 0) {
81
ret = update_refcount(bs,
82
- (offset & s->cluster_offset_mask) & ~511,
83
+ (entry & s->cluster_offset_mask) & ~511,
84
nb_csectors * 512, abs(addend), addend < 0,
85
QCOW2_DISCARD_SNAPSHOT);
86
if (ret < 0) {
87
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
88
89
case QCOW2_CLUSTER_NORMAL:
90
case QCOW2_CLUSTER_ZERO:
91
- if (offset_into_cluster(s, offset & L2E_OFFSET_MASK)) {
92
+ if (offset_into_cluster(s, offset)) {
93
qcow2_signal_corruption(bs, true, -1, -1, "Data "
94
- "cluster offset %#llx "
95
- "unaligned (L2 offset: %#"
96
+ "cluster offset %#" PRIx64
97
+ " unaligned (L2 offset: %#"
98
PRIx64 ", L2 index: %#x)",
99
- offset & L2E_OFFSET_MASK,
100
- l2_offset, j);
101
+ offset, l2_offset, j);
102
ret = -EIO;
103
goto fail;
104
}
105
106
- cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
107
+ cluster_index = offset >> s->cluster_bits;
108
if (!cluster_index) {
109
/* unallocated */
110
refcount = 0;
111
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
112
}
113
114
if (refcount == 1) {
115
- offset |= QCOW_OFLAG_COPIED;
116
+ entry |= QCOW_OFLAG_COPIED;
117
}
118
- if (offset != old_offset) {
119
+ if (entry != old_entry) {
120
if (addend > 0) {
121
qcow2_cache_set_dependency(bs, s->l2_table_cache,
122
s->refcount_block_cache);
123
}
124
- l2_table[j] = cpu_to_be64(offset);
125
+ l2_table[j] = cpu_to_be64(entry);
126
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache,
127
l2_table);
128
}
129
--
130
1.8.3.1
131
132
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Fix a couple of inconsistent indentations, before an upcoming
4
patch further tweaks the switch statements.
5
(best viewed with 'git diff -b').
6
7
Signed-off-by: Eric Blake <eblake@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20170507000552.20847-3-eblake@redhat.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/qcow2-cluster.c | 32 +++++++++----------
13
block/qcow2-refcount.c | 84 +++++++++++++++++++++++++-------------------------
14
2 files changed, 58 insertions(+), 58 deletions(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
* but rather fall through to the backing file.
22
*/
23
switch (qcow2_get_cluster_type(old_l2_entry)) {
24
- case QCOW2_CLUSTER_UNALLOCATED:
25
- if (full_discard || !bs->backing) {
26
- continue;
27
- }
28
- break;
29
+ case QCOW2_CLUSTER_UNALLOCATED:
30
+ if (full_discard || !bs->backing) {
31
+ continue;
32
+ }
33
+ break;
34
35
- case QCOW2_CLUSTER_ZERO:
36
- /* Preallocated zero clusters should be discarded in any case */
37
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
38
- continue;
39
- }
40
- break;
41
+ case QCOW2_CLUSTER_ZERO:
42
+ /* Preallocated zero clusters should be discarded in any case */
43
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
44
+ continue;
45
+ }
46
+ break;
47
48
- case QCOW2_CLUSTER_NORMAL:
49
- case QCOW2_CLUSTER_COMPRESSED:
50
- break;
51
+ case QCOW2_CLUSTER_NORMAL:
52
+ case QCOW2_CLUSTER_COMPRESSED:
53
+ break;
54
55
- default:
56
- abort();
57
+ default:
58
+ abort();
59
}
60
61
/* First remove L2 entries */
62
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/block/qcow2-refcount.c
65
+++ b/block/qcow2-refcount.c
66
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
67
offset = entry & L2E_OFFSET_MASK;
68
69
switch (qcow2_get_cluster_type(entry)) {
70
- case QCOW2_CLUSTER_COMPRESSED:
71
- nb_csectors = ((entry >> s->csize_shift) &
72
- s->csize_mask) + 1;
73
- if (addend != 0) {
74
- ret = update_refcount(bs,
75
+ case QCOW2_CLUSTER_COMPRESSED:
76
+ nb_csectors = ((entry >> s->csize_shift) &
77
+ s->csize_mask) + 1;
78
+ if (addend != 0) {
79
+ ret = update_refcount(bs,
80
(entry & s->cluster_offset_mask) & ~511,
81
nb_csectors * 512, abs(addend), addend < 0,
82
QCOW2_DISCARD_SNAPSHOT);
83
- if (ret < 0) {
84
- goto fail;
85
- }
86
- }
87
- /* compressed clusters are never modified */
88
- refcount = 2;
89
- break;
90
-
91
- case QCOW2_CLUSTER_NORMAL:
92
- case QCOW2_CLUSTER_ZERO:
93
- if (offset_into_cluster(s, offset)) {
94
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
95
- "cluster offset %#" PRIx64
96
- " unaligned (L2 offset: %#"
97
- PRIx64 ", L2 index: %#x)",
98
- offset, l2_offset, j);
99
- ret = -EIO;
100
+ if (ret < 0) {
101
goto fail;
102
}
103
+ }
104
+ /* compressed clusters are never modified */
105
+ refcount = 2;
106
+ break;
107
+
108
+ case QCOW2_CLUSTER_NORMAL:
109
+ case QCOW2_CLUSTER_ZERO:
110
+ if (offset_into_cluster(s, offset)) {
111
+ qcow2_signal_corruption(bs, true, -1, -1, "Data "
112
+ "cluster offset %#" PRIx64
113
+ " unaligned (L2 offset: %#"
114
+ PRIx64 ", L2 index: %#x)",
115
+ offset, l2_offset, j);
116
+ ret = -EIO;
117
+ goto fail;
118
+ }
119
120
- cluster_index = offset >> s->cluster_bits;
121
- if (!cluster_index) {
122
- /* unallocated */
123
- refcount = 0;
124
- break;
125
- }
126
- if (addend != 0) {
127
- ret = qcow2_update_cluster_refcount(bs,
128
+ cluster_index = offset >> s->cluster_bits;
129
+ if (!cluster_index) {
130
+ /* unallocated */
131
+ refcount = 0;
132
+ break;
133
+ }
134
+ if (addend != 0) {
135
+ ret = qcow2_update_cluster_refcount(bs,
136
cluster_index, abs(addend), addend < 0,
137
QCOW2_DISCARD_SNAPSHOT);
138
- if (ret < 0) {
139
- goto fail;
140
- }
141
- }
142
-
143
- ret = qcow2_get_refcount(bs, cluster_index, &refcount);
144
if (ret < 0) {
145
goto fail;
146
}
147
- break;
148
+ }
149
150
- case QCOW2_CLUSTER_UNALLOCATED:
151
- refcount = 0;
152
- break;
153
+ ret = qcow2_get_refcount(bs, cluster_index, &refcount);
154
+ if (ret < 0) {
155
+ goto fail;
156
+ }
157
+ break;
158
+
159
+ case QCOW2_CLUSTER_UNALLOCATED:
160
+ refcount = 0;
161
+ break;
162
163
- default:
164
- abort();
165
+ default:
166
+ abort();
167
}
168
169
if (refcount == 1) {
170
--
171
1.8.3.1
172
173
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We had some conflicting documentation: a nice 8-way table that
4
described all possible combinations of DATA, ZERO, and
5
OFFSET_VALID, contrasted with text that implied that OFFSET_VALID
6
always meant raw data could be read directly. Furthermore, the
7
text refers a lot to bs->file, even though the interface was
8
updated back in 67a0fd2a to let the driver pass back a specific
9
BDS (not necessarily bs->file). As the 8-way table is the
10
intended semantics, simplify the rest of the text to get rid of
11
the confusion.
12
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>
23
---
24
include/block/block.h | 35 +++++++++++++++++++----------------
25
include/block/block_int.h | 7 +++++++
26
2 files changed, 26 insertions(+), 16 deletions(-)
27
28
diff --git a/include/block/block.h b/include/block/block.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/include/block/block.h
31
+++ b/include/block/block.h
32
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
33
#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
34
35
/*
36
- * Allocation status flags
37
- * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_status.
38
- * BDRV_BLOCK_ZERO: sectors read as zero
39
- * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by
40
- * bdrv_get_block_status.
41
+ * Allocation status flags for bdrv_get_block_status() and friends.
42
+ *
43
+ * Public flags:
44
+ * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer
45
+ * BDRV_BLOCK_ZERO: offset reads as zero
46
+ * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
47
* BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
48
- * layer (as opposed to the backing file)
49
- * BDRV_BLOCK_RAW: used internally to indicate that the request
50
- * was answered by the raw driver and that one
51
- * should look in bs->file directly.
52
+ * layer (short for DATA || ZERO), set by block layer
53
*
54
- * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
55
- * bs->file where sector data can be read from as raw data.
56
+ * Internal flag:
57
+ * BDRV_BLOCK_RAW: used internally to indicate that the request was
58
+ * answered by a passthrough driver such as raw and that the
59
+ * block layer should recompute the answer from bs->file.
60
*
61
- * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present.
62
+ * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK)
63
+ * represent the offset in the returned BDS that is allocated for the
64
+ * corresponding raw data; however, whether that offset actually contains
65
+ * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows:
66
*
67
* DATA ZERO OFFSET_VALID
68
- * t t t sectors read as zero, bs->file is zero at offset
69
- * t f t sectors read as valid from bs->file at offset
70
- * f t t sectors preallocated, read as zero, bs->file not
71
+ * t t t sectors read as zero, returned file is zero at offset
72
+ * t f t sectors read as valid from file at offset
73
+ * f t t sectors preallocated, read as zero, returned file not
74
* necessarily zero at offset
75
* f f t sectors preallocated but read from backing_hd,
76
- * bs->file contains garbage at offset
77
+ * returned file contains garbage at offset
78
* t t f sectors preallocated, read as zero, unknown offset
79
* t f f sectors read from unknown file or offset
80
* f t f not allocated or unknown offset, read as zero
81
diff --git a/include/block/block_int.h b/include/block/block_int.h
82
index XXXXXXX..XXXXXXX 100644
83
--- a/include/block/block_int.h
84
+++ b/include/block/block_int.h
85
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
86
int64_t offset, int count, BdrvRequestFlags flags);
87
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
88
int64_t offset, int count);
89
+
90
+ /*
91
+ * Building block for bdrv_block_status[_above]. The driver should
92
+ * answer only according to the current layer, and should not
93
+ * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h
94
+ * for the meaning of _DATA, _ZERO, and _OFFSET_VALID.
95
+ */
96
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
97
int64_t sector_num, int nb_sectors, int *pnum,
98
BlockDriverState **file);
99
--
100
1.8.3.1
101
102
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We were throwing away the preallocation information associated with
4
zero clusters. But we should be matching the well-defined semantics
5
in bdrv_get_block_status(), where (BDRV_BLOCK_ZERO |
6
BDRV_BLOCK_OFFSET_VALID) informs the user which offset is reserved,
7
while still reminding the user that reading from that offset is
8
likely to read garbage.
9
10
count_contiguous_clusters_by_type() is now used only for unallocated
11
cluster runs, hence it gets renamed and tightened.
12
13
Making this change lets us see which portions of an image are zero
14
but preallocated, when using qemu-img map --output=json. The
15
--output=human side intentionally ignores all zero clusters, whether
16
or not they are preallocated.
17
18
The fact that there is no change to qemu-iotests './check -qcow2'
19
merely means that we aren't yet testing this aspect of qemu-img;
20
a later patch will add a test.
21
22
Signed-off-by: Eric Blake <eblake@redhat.com>
23
Reviewed-by: Max Reitz <mreitz@redhat.com>
24
Message-id: 20170507000552.20847-5-eblake@redhat.com
25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26
---
27
block/qcow2-cluster.c | 45 +++++++++++++++++++++++++++++++++++----------
28
1 file changed, 35 insertions(+), 10 deletions(-)
29
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
33
+++ b/block/qcow2-cluster.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
35
    return i;
36
}
37
38
-static int count_contiguous_clusters_by_type(int nb_clusters,
39
- uint64_t *l2_table,
40
- int wanted_type)
41
+/*
42
+ * Checks how many consecutive unallocated clusters in a given L2
43
+ * table have the same cluster type.
44
+ */
45
+static int count_contiguous_clusters_unallocated(int nb_clusters,
46
+ uint64_t *l2_table,
47
+ int wanted_type)
48
{
49
int i;
50
51
+ assert(wanted_type == QCOW2_CLUSTER_ZERO ||
52
+ wanted_type == QCOW2_CLUSTER_UNALLOCATED);
53
for (i = 0; i < nb_clusters; i++) {
54
- int type = qcow2_get_cluster_type(be64_to_cpu(l2_table[i]));
55
+ uint64_t entry = be64_to_cpu(l2_table[i]);
56
+ int type = qcow2_get_cluster_type(entry);
57
58
- if (type != wanted_type) {
59
+ if (type != wanted_type || entry & L2E_OFFSET_MASK) {
60
break;
61
}
62
}
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
ret = -EIO;
65
goto fail;
66
}
67
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
68
- QCOW2_CLUSTER_ZERO);
69
- *cluster_offset = 0;
70
+ /* Distinguish between pure zero clusters and pre-allocated ones */
71
+ if (*cluster_offset & L2E_OFFSET_MASK) {
72
+ c = count_contiguous_clusters(nb_clusters, s->cluster_size,
73
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
74
+ *cluster_offset &= L2E_OFFSET_MASK;
75
+ if (offset_into_cluster(s, *cluster_offset)) {
76
+ qcow2_signal_corruption(bs, true, -1, -1,
77
+ "Preallocated zero cluster offset %#"
78
+ PRIx64 " unaligned (L2 offset: %#"
79
+ PRIx64 ", L2 index: %#x)",
80
+ *cluster_offset, l2_offset, l2_index);
81
+ ret = -EIO;
82
+ goto fail;
83
+ }
84
+ } else {
85
+ c = count_contiguous_clusters_unallocated(nb_clusters,
86
+ &l2_table[l2_index],
87
+ QCOW2_CLUSTER_ZERO);
88
+ *cluster_offset = 0;
89
+ }
90
break;
91
case QCOW2_CLUSTER_UNALLOCATED:
92
/* how many empty clusters ? */
93
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
94
- QCOW2_CLUSTER_UNALLOCATED);
95
+ c = count_contiguous_clusters_unallocated(nb_clusters,
96
+ &l2_table[l2_index],
97
+ QCOW2_CLUSTER_UNALLOCATED);
98
*cluster_offset = 0;
99
break;
100
case QCOW2_CLUSTER_NORMAL:
101
--
102
1.8.3.1
103
104
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Although it doesn't add all that much type safety (this is C, after
4
all), it does add a bit of legibility to use the name QCow2ClusterType
5
instead of a plain int.
6
7
In particular, qcow2_get_cluster_offset() has an overloaded return
8
type; a QCow2ClusterType on success, and -errno on failure; keeping
9
the cluster type in a separate variable makes it slightly easier for
10
the next patch to make further computations based on the type.
11
12
Suggested-by: Max Reitz <mreitz@redhat.com>
13
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Message-id: 20170507000552.20847-6-eblake@redhat.com
15
[mreitz: Use the new type in two more places (one of them pulled from
16
the next patch)]
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-cluster.c | 21 +++++++++++----------
20
block/qcow2-refcount.c | 2 +-
21
block/qcow2.h | 6 +++---
22
3 files changed, 15 insertions(+), 14 deletions(-)
23
24
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/block/qcow2-cluster.c
27
+++ b/block/qcow2-cluster.c
28
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
29
uint64_t *l2_table, uint64_t stop_flags)
30
{
31
int i;
32
- int first_cluster_type;
33
+ QCow2ClusterType first_cluster_type;
34
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
35
uint64_t first_entry = be64_to_cpu(l2_table[0]);
36
uint64_t offset = first_entry & mask;
37
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
38
*/
39
static int count_contiguous_clusters_unallocated(int nb_clusters,
40
uint64_t *l2_table,
41
- int wanted_type)
42
+ QCow2ClusterType wanted_type)
43
{
44
int i;
45
46
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
47
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
48
for (i = 0; i < nb_clusters; i++) {
49
uint64_t entry = be64_to_cpu(l2_table[i]);
50
- int type = qcow2_get_cluster_type(entry);
51
+ QCow2ClusterType type = qcow2_get_cluster_type(entry);
52
53
if (type != wanted_type || entry & L2E_OFFSET_MASK) {
54
break;
55
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
56
int l1_bits, c;
57
unsigned int offset_in_cluster;
58
uint64_t bytes_available, bytes_needed, nb_clusters;
59
+ QCow2ClusterType type;
60
int ret;
61
62
offset_in_cluster = offset_into_cluster(s, offset);
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
65
l1_index = offset >> l1_bits;
66
if (l1_index >= s->l1_size) {
67
- ret = QCOW2_CLUSTER_UNALLOCATED;
68
+ type = QCOW2_CLUSTER_UNALLOCATED;
69
goto out;
70
}
71
72
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
73
if (!l2_offset) {
74
- ret = QCOW2_CLUSTER_UNALLOCATED;
75
+ type = QCOW2_CLUSTER_UNALLOCATED;
76
goto out;
77
}
78
79
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
80
* true */
81
assert(nb_clusters <= INT_MAX);
82
83
- ret = qcow2_get_cluster_type(*cluster_offset);
84
- switch (ret) {
85
+ type = qcow2_get_cluster_type(*cluster_offset);
86
+ switch (type) {
87
case QCOW2_CLUSTER_COMPRESSED:
88
/* Compressed clusters can only be processed one by one */
89
c = 1;
90
@@ -XXX,XX +XXX,XX @@ out:
91
assert(bytes_available - offset_in_cluster <= UINT_MAX);
92
*bytes = bytes_available - offset_in_cluster;
93
94
- return ret;
95
+ return type;
96
97
fail:
98
qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table);
99
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
100
101
for (i = 0; i < nb_clusters; i++) {
102
uint64_t l2_entry = be64_to_cpu(l2_table[l2_index + i]);
103
- int cluster_type = qcow2_get_cluster_type(l2_entry);
104
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
105
106
switch(cluster_type) {
107
case QCOW2_CLUSTER_NORMAL:
108
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
109
for (j = 0; j < s->l2_size; j++) {
110
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
111
int64_t offset = l2_entry & L2E_OFFSET_MASK;
112
- int cluster_type = qcow2_get_cluster_type(l2_entry);
113
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
114
bool preallocated = offset != 0;
115
116
if (cluster_type != QCOW2_CLUSTER_ZERO) {
117
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
118
index XXXXXXX..XXXXXXX 100644
119
--- a/block/qcow2-refcount.c
120
+++ b/block/qcow2-refcount.c
121
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
122
for (j = 0; j < s->l2_size; j++) {
123
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
124
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
125
- int cluster_type = qcow2_get_cluster_type(l2_entry);
126
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
127
128
if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
129
((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
130
diff --git a/block/qcow2.h b/block/qcow2.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/block/qcow2.h
133
+++ b/block/qcow2.h
134
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
135
QLIST_ENTRY(QCowL2Meta) next_in_flight;
136
} QCowL2Meta;
137
138
-enum {
139
+typedef enum QCow2ClusterType {
140
QCOW2_CLUSTER_UNALLOCATED,
141
QCOW2_CLUSTER_NORMAL,
142
QCOW2_CLUSTER_COMPRESSED,
143
QCOW2_CLUSTER_ZERO
144
-};
145
+} QCow2ClusterType;
146
147
typedef enum QCow2MetadataOverlap {
148
QCOW2_OL_MAIN_HEADER_BITNR = 0,
149
@@ -XXX,XX +XXX,XX @@ static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State *s)
150
return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
151
}
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
--
159
1.8.3.1
160
161
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Similar to discard_single_l2(), we should try to avoid dirtying
4
the L2 cache when the cluster we are changing already has the
5
right characteristics.
6
7
Note that by the time we get to zero_single_l2(), BDRV_REQ_MAY_UNMAP
8
is a requirement to unallocate a cluster (this is because the block
9
layer clears that flag if discard.* flags during open requested that
10
we never punch holes - see the conversation around commit 170f4b2e,
11
https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg07306.html).
12
Therefore, this patch can only reuse a zero cluster as-is if either
13
unmapping is not requested, or if the zero cluster was not associated
14
with an allocation.
15
16
Technically, there are some cases where an unallocated cluster
17
already reads as all zeroes (namely, when there is no backing file
18
[easy: check bs->backing], or when the backing file also reads as
19
zeroes [harder: we can't check bdrv_get_block_status since we are
20
already holding the lock]), where the guest would not immediately see
21
a difference if we left that cluster unallocated. But if the user
22
did not request unmapping, leaving an unallocated cluster is wrong;
23
and even if the user DID request unmapping, keeping a cluster
24
unallocated risks a subtle semantic change of guest-visible contents
25
if a backing file is later added, and it is not worth auditing
26
whether all internal uses such as mirror properly avoid an unmap
27
request. Thus, this patch is intentionally limited to just clusters
28
that are already marked as zero.
29
30
Signed-off-by: Eric Blake <eblake@redhat.com>
31
Reviewed-by: Max Reitz <mreitz@redhat.com>
32
Message-id: 20170507000552.20847-8-eblake@redhat.com
33
Signed-off-by: Max Reitz <mreitz@redhat.com>
34
---
35
block/qcow2-cluster.c | 15 +++++++++++++--
36
1 file changed, 13 insertions(+), 2 deletions(-)
37
38
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/block/qcow2-cluster.c
41
+++ b/block/qcow2-cluster.c
42
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
43
int l2_index;
44
int ret;
45
int i;
46
+ bool unmap = !!(flags & BDRV_REQ_MAY_UNMAP);
47
48
ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
49
if (ret < 0) {
50
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
51
52
for (i = 0; i < nb_clusters; i++) {
53
uint64_t old_offset;
54
+ QCow2ClusterType cluster_type;
55
56
old_offset = be64_to_cpu(l2_table[l2_index + i]);
57
58
- /* Update L2 entries */
59
+ /*
60
+ * Minimize L2 changes if the cluster already reads back as
61
+ * zeroes with correct allocation.
62
+ */
63
+ cluster_type = qcow2_get_cluster_type(old_offset);
64
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN ||
65
+ (cluster_type == QCOW2_CLUSTER_ZERO_ALLOC && !unmap)) {
66
+ continue;
67
+ }
68
+
69
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);
70
- if (old_offset & QCOW_OFLAG_COMPRESSED || flags & BDRV_REQ_MAY_UNMAP) {
71
+ if (cluster_type == QCOW2_CLUSTER_COMPRESSED || unmap) {
72
l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);
73
qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);
74
} else {
75
--
76
1.8.3.1
77
78
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
After processing the option string with the keyval parser, we get a
2
QDict that contains only strings. This QDict must be fed to a keyval
3
visitor which converts the strings into the right data types.
2
4
3
Although _filter_qemu_img_map documents that it scrubs offsets, it
5
qmp_object_add(), however, uses the normal QObject input visitor, which
4
was only doing so for human mode. Of the existing tests using the
6
expects a QDict where all properties already have the QType that matches
5
filter (97, 122, 150, 154, 176), two of them are affected, but it
7
the data type required by the QOM object type.
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
8
11
Another justification for this patch is that it will allow a future
9
Change the --object implementation in qemu-storage-daemon so that it
12
patch to utilize 'qemu-img map --output=json' to check the status of
10
doesn't call qmp_object_add(), but calls user_creatable_add_dict()
13
preallocated zero clusters without regards to the mapping (since
11
directly instead and pass it a new keyval boolean that decides which
14
the qcow2 mapping can be very sensitive to the chosen cluster size,
12
visitor must be used.
15
when preallocation is not in use).
16
13
17
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Reported-by: Coiby Xu <coiby.xu@gmail.com>
18
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
19
Message-id: 20170507000552.20847-9-eblake@redhat.com
20
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
---
16
---
22
tests/qemu-iotests/122.out | 16 ++++++++--------
17
include/qom/object_interfaces.h | 6 +++++-
23
tests/qemu-iotests/154.out | 30 +++++++++++++++---------------
18
qemu-storage-daemon.c | 4 +---
24
tests/qemu-iotests/common.filter | 4 +++-
19
qom/object_interfaces.c | 8 ++++++--
25
3 files changed, 26 insertions(+), 24 deletions(-)
20
qom/qom-qmp-cmds.c | 2 +-
21
4 files changed, 13 insertions(+), 7 deletions(-)
26
22
27
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
23
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
28
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
29
--- a/tests/qemu-iotests/122.out
25
--- a/include/qom/object_interfaces.h
30
+++ b/tests/qemu-iotests/122.out
26
+++ b/include/qom/object_interfaces.h
31
@@ -XXX,XX +XXX,XX @@ read 3145728/3145728 bytes at offset 0
27
@@ -XXX,XX +XXX,XX @@ Object *user_creatable_add_type(const char *type, const char *id,
32
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
28
/**
33
read 63963136/63963136 bytes at offset 3145728
29
* user_creatable_add_dict:
34
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
30
* @qdict: the object definition
35
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
31
+ * @keyval: if true, use a keyval visitor for processing @qdict (i.e.
36
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
32
+ * assume that all @qdict values are strings); otherwise, use
37
33
+ * the normal QObject visitor (i.e. assume all @qdict values
38
convert -c -S 0:
34
+ * have the QType expected by the QOM object type)
39
read 3145728/3145728 bytes at offset 0
35
* @errp: if an error occurs, a pointer to an area to store the error
40
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
36
*
41
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
37
* Create an instance of the user creatable object that is defined by
42
read 33554432/33554432 bytes at offset 33554432
38
@@ -XXX,XX +XXX,XX @@ Object *user_creatable_add_type(const char *type, const char *id,
43
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
39
* ID from the key 'id'. The remaining entries in @qdict are used to
44
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
40
* initialize the object properties.
45
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
41
*/
46
42
-void user_creatable_add_dict(QDict *qdict, Error **errp);
47
convert -c -S 0 with source backing file:
43
+void user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp);
48
read 3145728/3145728 bytes at offset 0
44
49
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
45
/**
50
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
46
* user_creatable_add_opts:
51
read 33554432/33554432 bytes at offset 33554432
47
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
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
48
index XXXXXXX..XXXXXXX 100644
87
--- a/tests/qemu-iotests/154.out
49
--- a/qemu-storage-daemon.c
88
+++ b/tests/qemu-iotests/154.out
50
+++ b/qemu-storage-daemon.c
89
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 65536
51
@@ -XXX,XX +XXX,XX @@ static void process_options(int argc, char *argv[])
90
read 2048/2048 bytes at offset 67584
52
QemuOpts *opts;
91
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
53
const char *type;
92
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
54
QDict *args;
93
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
55
- QObject *ret_data = NULL;
94
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
56
95
{ "start": 36864, "length": 28672, "depth": 1, "zero": true, "data": false},
57
/* FIXME The keyval parser rejects 'help' arguments, so we must
96
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
58
* unconditionall try QemuOpts first. */
97
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
59
@@ -XXX,XX +XXX,XX @@ static void process_options(int argc, char *argv[])
98
{ "start": 69632, "length": 134148096, "depth": 1, "zero": true, "data": false}]
60
qemu_opts_del(opts);
99
61
100
== backing file contains non-zero data after write_zeroes ==
62
args = keyval_parse(optarg, "qom-type", &error_fatal);
101
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 44032
63
- qmp_object_add(args, &ret_data, &error_fatal);
102
read 3072/3072 bytes at offset 40960
64
+ user_creatable_add_dict(args, true, &error_fatal);
103
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
65
qobject_unref(args);
104
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
66
- qobject_unref(ret_data);
105
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
67
break;
106
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
68
}
107
{ "start": 36864, "length": 4096, "depth": 1, "zero": true, "data": false},
69
default:
108
-{ "start": 40960, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
70
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
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
186
index XXXXXXX..XXXXXXX 100644
71
index XXXXXXX..XXXXXXX 100644
187
--- a/tests/qemu-iotests/common.filter
72
--- a/qom/object_interfaces.c
188
+++ b/tests/qemu-iotests/common.filter
73
+++ b/qom/object_interfaces.c
189
@@ -XXX,XX +XXX,XX @@ _filter_img_info()
74
@@ -XXX,XX +XXX,XX @@ out:
190
-e "/log_size: [0-9]\\+/d"
75
return obj;
191
}
76
}
192
77
193
-# filter out offsets and file names from qemu-img map
78
-void user_creatable_add_dict(QDict *qdict, Error **errp)
194
+# filter out offsets and file names from qemu-img map; good for both
79
+void user_creatable_add_dict(QDict *qdict, bool keyval, Error **errp)
195
+# human and json output
196
_filter_qemu_img_map()
197
{
80
{
198
sed -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
81
Visitor *v;
199
+ -e 's/"offset": [0-9]\+/"offset": OFFSET/g' \
82
Object *obj;
200
-e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt
83
@@ -XXX,XX +XXX,XX @@ void user_creatable_add_dict(QDict *qdict, Error **errp)
84
}
85
qdict_del(qdict, "id");
86
87
- v = qobject_input_visitor_new(QOBJECT(qdict));
88
+ if (keyval) {
89
+ v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
90
+ } else {
91
+ v = qobject_input_visitor_new(QOBJECT(qdict));
92
+ }
93
obj = user_creatable_add_type(type, id, qdict, v, errp);
94
visit_free(v);
95
object_unref(obj);
96
diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c
97
index XXXXXXX..XXXXXXX 100644
98
--- a/qom/qom-qmp-cmds.c
99
+++ b/qom/qom-qmp-cmds.c
100
@@ -XXX,XX +XXX,XX @@ void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
101
qobject_unref(pdict);
102
}
103
104
- user_creatable_add_dict(qdict, errp);
105
+ user_creatable_add_dict(qdict, false, errp);
201
}
106
}
202
107
108
void qmp_object_del(const char *id, Error **errp)
203
--
109
--
204
1.8.3.1
110
2.25.3
205
111
206
112
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
No tests were covering write zeroes with unmap. Additionally,
4
I needed to prove that my previous patches for correct status
5
reporting and write zeroes optimizations actually had an impact.
6
7
The test works for cluster_size between 8k and 2M (for smaller
8
sizes, it fails because our allocation patterns are not contiguous
9
with small clusters - in part, the largest consecutive allocation
10
we tend to get is often bounded by the size covered by one L2
11
table).
12
13
Note that testing for zero clusters is tricky: 'qemu-io map'
14
reports whether data comes from the current layer of the image
15
(useful for sniffing out which regions of the file have
16
QCOW_OFLAG_ZERO) - but doesn't show which clusters have mappings;
17
while 'qemu-img map' sees "zero":true for both unallocated and
18
zero clusters for any qcow2 with no backing layer (so less useful
19
at detecting true zero clusters), but reliably shows mappings.
20
So we have to rely on both queries side-by-side at each point of
21
the test.
22
23
Signed-off-by: Eric Blake <eblake@redhat.com>
24
Reviewed-by: Max Reitz <mreitz@redhat.com>
25
Message-id: 20170507000552.20847-10-eblake@redhat.com
26
Signed-off-by: Max Reitz <mreitz@redhat.com>
27
---
28
tests/qemu-iotests/179 | 130 +++++++++++++++++++++++++++++++++++++
29
tests/qemu-iotests/179.out | 156 +++++++++++++++++++++++++++++++++++++++++++++
30
tests/qemu-iotests/group | 1 +
31
3 files changed, 287 insertions(+)
32
create mode 100755 tests/qemu-iotests/179
33
create mode 100644 tests/qemu-iotests/179.out
34
35
diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179
36
new file mode 100755
37
index XXXXXXX..XXXXXXX
38
--- /dev/null
39
+++ b/tests/qemu-iotests/179
40
@@ -XXX,XX +XXX,XX @@
41
+#!/bin/bash
42
+#
43
+# Test case for write zeroes with unmap
44
+#
45
+# Copyright (C) 2017 Red Hat, Inc.
46
+#
47
+# This program is free software; you can redistribute it and/or modify
48
+# it under the terms of the GNU General Public License as published by
49
+# the Free Software Foundation; either version 2 of the License, or
50
+# (at your option) any later version.
51
+#
52
+# This program is distributed in the hope that it will be useful,
53
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
54
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
+# GNU General Public License for more details.
56
+#
57
+# You should have received a copy of the GNU General Public License
58
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
59
+#
60
+
61
+# creator
62
+owner=eblake@redhat.com
63
+
64
+seq="$(basename $0)"
65
+echo "QA output created by $seq"
66
+
67
+here="$PWD"
68
+status=1    # failure is the default!
69
+
70
+_cleanup()
71
+{
72
+    _cleanup_test_img
73
+}
74
+trap "_cleanup; exit \$status" 0 1 2 3 15
75
+
76
+# get standard environment, filters and checks
77
+. ./common.rc
78
+. ./common.filter
79
+
80
+_supported_fmt qcow2
81
+_supported_proto file
82
+_supported_os Linux
83
+
84
+# v2 images can't mark clusters as zero
85
+_unsupported_imgopts compat=0.10
86
+
87
+echo
88
+echo '=== Testing write zeroes with unmap ==='
89
+echo
90
+
91
+TEST_IMG="$TEST_IMG.base" _make_test_img 64M
92
+_make_test_img -b "$TEST_IMG.base"
93
+
94
+# Offsets chosen at or near 2M boundaries so test works at all cluster sizes
95
+# 8k and larger (smaller clusters fail due to non-contiguous allocations)
96
+
97
+# Aligned writes to unallocated cluster should not allocate mapping, but must
98
+# mark cluster as zero, whether or not unmap was requested
99
+$QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
100
+$QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
101
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
102
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
103
+
104
+# Unaligned writes need not allocate mapping if the cluster already reads
105
+# as zero, but must mark cluster as zero, whether or not unmap was requested
106
+$QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
107
+$QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
108
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
109
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
110
+
111
+# Requesting unmap of normal data must deallocate; omitting unmap should
112
+# preserve the mapping
113
+$QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
114
+$QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
115
+$QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
116
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
117
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
118
+
119
+# Likewise when writing on already-mapped zero data
120
+$QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
121
+$QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
122
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
123
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
124
+
125
+# Writing on unmapped zeroes does not allocate
126
+$QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
127
+$QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
128
+$QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
129
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
130
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
131
+
132
+# Writing zero overrides a backing file, regardless of backing cluster type
133
+$QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
134
+$QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
135
+$QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
136
+$QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
137
+$QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
138
+$QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
139
+$QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
140
+$QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
141
+$QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
143
+
144
+# Final check that mappings are correct and images are still sane
145
+TEST_IMG="$TEST_IMG.base" _check_test_img
146
+_check_test_img
147
+
148
+echo
149
+echo '=== Testing cache optimization ==='
150
+echo
151
+
152
+BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
153
+
154
+cat > "$TEST_DIR/blkdebug.conf" <<EOF
155
+[inject-error]
156
+event = "l2_update"
157
+errno = "5"
158
+immediately = "on"
159
+once = "off"
160
+EOF
161
+
162
+# None of the following writes should trigger an L2 update, because the
163
+# cluster already reads as zero, and we don't have to change allocation
164
+$QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
165
+$QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
166
+$QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
167
+
168
+# success, all done
169
+echo '*** done'
170
+status=0
171
diff --git a/tests/qemu-iotests/179.out b/tests/qemu-iotests/179.out
172
new file mode 100644
173
index XXXXXXX..XXXXXXX
174
--- /dev/null
175
+++ b/tests/qemu-iotests/179.out
176
@@ -XXX,XX +XXX,XX @@
177
+QA output created by 179
178
+
179
+=== Testing write zeroes with unmap ===
180
+
181
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 2097152/2097152 bytes at offset 2097152
184
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+wrote 2097152/2097152 bytes at offset 6291456
186
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
187
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
188
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
189
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
190
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
191
+56 MiB (0x3800000) bytes not allocated at offset 8 MiB (0x800000)
192
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
193
+wrote 2097150/2097150 bytes at offset 10485761
194
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+wrote 2097150/2097150 bytes at offset 14680065
196
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
197
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
198
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
199
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
200
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
201
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
202
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
203
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
204
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
205
+48 MiB (0x3000000) bytes not allocated at offset 16 MiB (0x1000000)
206
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
207
+wrote 14680064/14680064 bytes at offset 18874368
208
+14 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+wrote 2097152/2097152 bytes at offset 20971520
210
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+wrote 6291456/6291456 bytes at offset 25165824
212
+6 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
214
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
215
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
216
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
217
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
218
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
219
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
220
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
221
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
222
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
223
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
224
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
225
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
226
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
227
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
228
+{ "start": 25165824, "length": 6291456, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
229
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
230
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
231
+wrote 2097152/2097152 bytes at offset 27262976
232
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
233
+wrote 2097152/2097152 bytes at offset 29360128
234
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
235
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
236
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
237
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
238
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
239
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
240
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
241
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
242
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
243
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
244
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
245
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
246
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
247
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
248
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
249
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
250
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
251
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
252
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
253
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
254
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
255
+wrote 8388608/8388608 bytes at offset 33554432
256
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
257
+wrote 2097152/2097152 bytes at offset 35651584
258
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
259
+wrote 2097152/2097152 bytes at offset 37748736
260
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
261
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
262
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
263
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
264
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
265
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
266
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
267
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
268
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
269
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
270
+22 MiB (0x1600000) bytes allocated at offset 18 MiB (0x1200000)
271
+24 MiB (0x1800000) bytes not allocated at offset 40 MiB (0x2800000)
272
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
273
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
274
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
275
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
276
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
277
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
278
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
279
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
280
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
281
+wrote 8388608/8388608 bytes at offset 41943040
282
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+wrote 8388608/8388608 bytes at offset 50331648
284
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
285
+wrote 2097152/2097152 bytes at offset 44040192
286
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
287
+wrote 2097152/2097152 bytes at offset 46137344
288
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+wrote 2097152/2097152 bytes at offset 52428800
290
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
291
+wrote 2097152/2097152 bytes at offset 54525952
292
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
293
+wrote 2097152/2097152 bytes at offset 60817408
294
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+wrote 2097152/2097152 bytes at offset 62914560
296
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
297
+42 MiB (0x2a00000) bytes not allocated at offset 0 bytes (0x0)
298
+4 MiB (0x400000) bytes allocated at offset 42 MiB (0x2a00000)
299
+4 MiB (0x400000) bytes not allocated at offset 46 MiB (0x2e00000)
300
+4 MiB (0x400000) bytes allocated at offset 50 MiB (0x3200000)
301
+4 MiB (0x400000) bytes not allocated at offset 54 MiB (0x3600000)
302
+4 MiB (0x400000) bytes allocated at offset 58 MiB (0x3a00000)
303
+2 MiB (0x200000) bytes not allocated at offset 62 MiB (0x3e00000)
304
+[{ "start": 0, "length": 18874368, "depth": 1, "zero": true, "data": false},
305
+{ "start": 18874368, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
306
+{ "start": 20971520, "length": 2097152, "depth": 1, "zero": true, "data": false},
307
+{ "start": 23068672, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
308
+{ "start": 25165824, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
309
+{ "start": 27262976, "length": 2097152, "depth": 1, "zero": true, "data": false},
310
+{ "start": 29360128, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
311
+{ "start": 31457280, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
312
+{ "start": 33554432, "length": 10485760, "depth": 1, "zero": true, "data": false},
313
+{ "start": 44040192, "length": 4194304, "depth": 0, "zero": true, "data": false},
314
+{ "start": 48234496, "length": 2097152, "depth": 1, "zero": true, "data": false},
315
+{ "start": 50331648, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
316
+{ "start": 52428800, "length": 4194304, "depth": 0, "zero": true, "data": false},
317
+{ "start": 56623104, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
318
+{ "start": 58720256, "length": 2097152, "depth": 1, "zero": true, "data": false},
319
+{ "start": 60817408, "length": 4194304, "depth": 0, "zero": true, "data": false},
320
+{ "start": 65011712, "length": 2097152, "depth": 1, "zero": true, "data": false}]
321
+No errors were found on the image.
322
+No errors were found on the image.
323
+
324
+=== Testing cache optimization ===
325
+
326
+wrote 2097152/2097152 bytes at offset 20971520
327
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
328
+wrote 2097152/2097152 bytes at offset 20971520
329
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
330
+wrote 2097152/2097152 bytes at offset 29360128
331
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
332
+*** done
333
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
334
index XXXXXXX..XXXXXXX 100644
335
--- a/tests/qemu-iotests/group
336
+++ b/tests/qemu-iotests/group
337
@@ -XXX,XX +XXX,XX @@
338
175 auto quick
339
176 rw auto backing
340
177 rw auto quick
341
+179 rw auto quick
342
181 rw auto migration
343
182 rw auto quick
344
--
345
1.8.3.1
346
347
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We've already improved discards to operate efficiently on the tail
4
of an unaligned qcow2 image; it's time to make a similar improvement
5
to write zeroes. The special case is only valid at the tail
6
cluster of a file, where we must recognize that any sectors beyond
7
the image end would implicitly read as zero, and therefore should
8
not penalize our logic for widening a partial cluster into writing
9
the whole cluster as zero.
10
11
However, note that for now, the special case of end-of-file is only
12
recognized if there is no backing file, or if the backing file has
13
the same length; that's because when the backing file is shorter
14
than the active layer, we don't have code in place to recognize
15
that reads of a sector unallocated at the top and beyond the backing
16
end-of-file are implicitly zero. It's not much of a real loss,
17
because most people don't use images that aren't cluster-aligned,
18
or where the active layer is a different size than the backing
19
layer (especially where the difference falls within a single cluster).
20
21
Update test 154 to cover the new scenarios, using two images of
22
intentionally differing length.
23
24
While at it, fix the test to gracefully skip when run as
25
./check -qcow2 -o compat=0.10 154
26
since the older format lacks zero clusters already required earlier
27
in the test.
28
29
Signed-off-by: Eric Blake <eblake@redhat.com>
30
Reviewed-by: Max Reitz <mreitz@redhat.com>
31
Message-id: 20170507000552.20847-11-eblake@redhat.com
32
Signed-off-by: Max Reitz <mreitz@redhat.com>
33
---
34
block/qcow2.c | 7 ++
35
tests/qemu-iotests/154 | 160 ++++++++++++++++++++++++++++++++++++++++++++-
36
tests/qemu-iotests/154.out | 128 ++++++++++++++++++++++++++++++++++++
37
3 files changed, 293 insertions(+), 2 deletions(-)
38
39
diff --git a/block/qcow2.c b/block/qcow2.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/block/qcow2.c
42
+++ b/block/qcow2.c
43
@@ -XXX,XX +XXX,XX @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
44
BlockDriverState *file;
45
int64_t res;
46
47
+ if (start + count > bs->total_sectors) {
48
+ count = bs->total_sectors - start;
49
+ }
50
+
51
if (!count) {
52
return true;
53
}
54
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
55
uint32_t tail = (offset + count) % s->cluster_size;
56
57
trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count);
58
+ if (offset + count == bs->total_sectors * BDRV_SECTOR_SIZE) {
59
+ tail = 0;
60
+ }
61
62
if (head || tail) {
63
int64_t cl_start = (offset - head) >> BDRV_SECTOR_BITS;
64
diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154
65
index XXXXXXX..XXXXXXX 100755
66
--- a/tests/qemu-iotests/154
67
+++ b/tests/qemu-iotests/154
68
@@ -XXX,XX +XXX,XX @@
69
#
70
# qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
71
#
72
-# Copyright (C) 2016 Red Hat, Inc.
73
+# Copyright (C) 2016-2017 Red Hat, Inc.
74
#
75
# This program is free software; you can redistribute it and/or modify
76
# it under the terms of the GNU General Public License as published by
77
@@ -XXX,XX +XXX,XX @@ _supported_proto file
78
_supported_os Linux
79
80
CLUSTER_SIZE=4k
81
-size=128M
82
+size=$((128 * 1024 * 1024))
83
+
84
+# This test requires zero clusters, added in v3 images
85
+_unsupported_imgopts compat=0.10
86
87
echo
88
echo == backing file contains zeros ==
89
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io
90
91
$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
92
93
+echo
94
+echo == unaligned image tail cluster, no allocation needed ==
95
+
96
+# With no backing file, write to all or part of unallocated partial cluster
97
+# will mark the cluster as zero, but does not allocate.
98
+# Re-create the image each time to get back to unallocated clusters.
99
+
100
+# Write at the front: sector-wise, the request is: 128m... | 00 -- -- --
101
+_make_test_img $((size + 2048))
102
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
103
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
104
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
105
+
106
+# Write at the back: sector-wise, the request is: 128m... | -- -- -- 00
107
+_make_test_img $((size + 2048))
108
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
109
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
110
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
111
+
112
+# Write at middle: sector-wise, the request is: 128m... | -- 00 00 --
113
+_make_test_img $((size + 2048))
114
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
115
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
116
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
117
+
118
+# Write entire cluster: sector-wise, the request is: 128m... | 00 00 00 00
119
+_make_test_img $((size + 2048))
120
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
121
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
122
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
123
+
124
+# Repeat with backing file holding unallocated cluster.
125
+# TODO: Note that this forces an allocation, because we aren't yet able to
126
+# quickly detect that reads beyond EOF of the backing file are always zero
127
+CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
128
+
129
+# Write at the front: sector-wise, the request is:
130
+# backing: 128m... | -- --
131
+# active: 128m... | 00 -- -- --
132
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
133
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
134
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
135
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
136
+
137
+# Write at the back: sector-wise, the request is:
138
+# backing: 128m... | -- --
139
+# active: 128m... | -- -- -- 00
140
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
141
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
143
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
144
+
145
+# Write at middle: sector-wise, the request is:
146
+# backing: 128m... | -- --
147
+# active: 128m... | -- 00 00 --
148
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
149
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
150
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
151
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
152
+
153
+# Write entire cluster: sector-wise, the request is:
154
+# backing: 128m... | -- --
155
+# active: 128m... | 00 00 00 00
156
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
157
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
158
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
159
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
160
+
161
+# Repeat with backing file holding zero'd cluster
162
+# TODO: Note that this forces an allocation, because we aren't yet able to
163
+# quickly detect that reads beyond EOF of the backing file are always zero
164
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io
165
+
166
+# Write at the front: sector-wise, the request is:
167
+# backing: 128m... | 00 00
168
+# active: 128m... | 00 -- -- --
169
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
170
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
171
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
172
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
173
+
174
+# Write at the back: sector-wise, the request is:
175
+# backing: 128m... | 00 00
176
+# active: 128m... | -- -- -- 00
177
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
178
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
179
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
180
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
181
+
182
+# Write at middle: sector-wise, the request is:
183
+# backing: 128m... | 00 00
184
+# active: 128m... | -- 00 00 --
185
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
186
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
187
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
188
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
189
+
190
+# Write entire cluster: sector-wise, the request is:
191
+# backing: 128m... | 00 00
192
+# active: 128m... | 00 00 00 00
193
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
194
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
195
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
196
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
197
+
198
+# A preallocated cluster maintains its allocation, whether it stays as
199
+# data due to a partial write:
200
+# Convert 128m... | XX XX => ... | XX 00
201
+_make_test_img $((size + 1024))
202
+$QEMU_IO -c "write -P 1 $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
203
+$QEMU_IO -c "write -z $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
204
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
205
+$QEMU_IO -c "read -P 0 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
206
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
207
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
208
+
209
+# or because it is the entire cluster and can use the zero flag:
210
+# Convert 128m... | XX XX => ... | 00 00
211
+$QEMU_IO -c "write -z $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
212
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
213
+$QEMU_IO -c "read -P 0 $size 1024" "$TEST_IMG" | _filter_qemu_io
214
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
215
+
216
+echo
217
+echo == unaligned image tail cluster, allocation required ==
218
+
219
+# Write beyond backing file must COW
220
+# Backing file: 128m... | XX --
221
+# Active layer: 128m... | -- -- 00 --
222
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
223
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
224
+$QEMU_IO -c "write -P 1 $((size)) 512" "$TEST_IMG.base" | _filter_qemu_io
225
+$QEMU_IO -c "write -z $((size + 1024)) 512" "$TEST_IMG" | _filter_qemu_io
226
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
227
+$QEMU_IO -c "read -P 0 $((size + 512)) 1536" "$TEST_IMG" | _filter_qemu_io
228
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
229
+
230
+# Writes at boundaries of (partial) cluster must not lose mid-cluster data
231
+# Backing file: 128m: ... | -- XX
232
+# Active layer: 128m: ... | 00 -- -- 00
233
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
234
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
235
+$QEMU_IO -c "write -P 1 $((size + 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
236
+$QEMU_IO -c "write -z $((size)) 512" "$TEST_IMG" | _filter_qemu_io
237
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
238
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
239
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
240
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
241
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
242
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
243
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
244
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
245
+
246
# success, all done
247
echo "*** done"
248
rm -f $seq.full
249
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
250
index XXXXXXX..XXXXXXX 100644
251
--- a/tests/qemu-iotests/154.out
252
+++ b/tests/qemu-iotests/154.out
253
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 76800
254
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
255
{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
256
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
257
+
258
+== unaligned image tail cluster, no allocation needed ==
259
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
260
+wrote 512/512 bytes at offset 134217728
261
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
262
+2048/2048 bytes allocated at offset 128 MiB
263
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
264
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
265
+wrote 512/512 bytes at offset 134219264
266
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
267
+2048/2048 bytes allocated at offset 128 MiB
268
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
269
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
270
+wrote 1024/1024 bytes at offset 134218240
271
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
272
+2048/2048 bytes allocated at offset 128 MiB
273
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
274
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
275
+wrote 2048/2048 bytes at offset 134217728
276
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
277
+2048/2048 bytes allocated at offset 128 MiB
278
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
279
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
280
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
281
+wrote 512/512 bytes at offset 134217728
282
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+2048/2048 bytes allocated at offset 128 MiB
284
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
285
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
286
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
287
+wrote 512/512 bytes at offset 134219264
288
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+2048/2048 bytes allocated at offset 128 MiB
290
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
291
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
292
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
293
+wrote 1024/1024 bytes at offset 134218240
294
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+2048/2048 bytes allocated at offset 128 MiB
296
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
297
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
298
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
299
+wrote 2048/2048 bytes at offset 134217728
300
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
301
+2048/2048 bytes allocated at offset 128 MiB
302
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
303
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
304
+wrote 512/512 bytes at offset 134217728
305
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
306
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
307
+wrote 512/512 bytes at offset 134217728
308
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
309
+2048/2048 bytes allocated at offset 128 MiB
310
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
311
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
312
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
313
+wrote 512/512 bytes at offset 134219264
314
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
315
+2048/2048 bytes allocated at offset 128 MiB
316
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
317
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
318
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
319
+wrote 1024/1024 bytes at offset 134218240
320
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
321
+2048/2048 bytes allocated at offset 128 MiB
322
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
323
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
324
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
325
+wrote 2048/2048 bytes at offset 134217728
326
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
327
+2048/2048 bytes allocated at offset 128 MiB
328
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
329
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
330
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134218752
331
+wrote 1024/1024 bytes at offset 134217728
332
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
333
+wrote 512/512 bytes at offset 134218240
334
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
335
+read 512/512 bytes at offset 134217728
336
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
337
+read 512/512 bytes at offset 134218240
338
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
339
+1024/1024 bytes allocated at offset 128 MiB
340
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
341
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
342
+wrote 1024/1024 bytes at offset 134217728
343
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
344
+1024/1024 bytes allocated at offset 128 MiB
345
+read 1024/1024 bytes at offset 134217728
346
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
347
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
348
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
349
+
350
+== unaligned image tail cluster, allocation required ==
351
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
352
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
353
+wrote 512/512 bytes at offset 134217728
354
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
355
+wrote 512/512 bytes at offset 134218752
356
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357
+read 512/512 bytes at offset 134217728
358
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
359
+read 1536/1536 bytes at offset 134218240
360
+1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
361
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
362
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
363
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
364
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
365
+wrote 512/512 bytes at offset 134218240
366
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
367
+wrote 512/512 bytes at offset 134217728
368
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
369
+read 512/512 bytes at offset 134217728
370
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
371
+read 512/512 bytes at offset 134218240
372
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
373
+read 1024/1024 bytes at offset 134218752
374
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
375
+wrote 512/512 bytes at offset 134219264
376
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
377
+read 512/512 bytes at offset 134217728
378
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
379
+read 512/512 bytes at offset 134218240
380
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
381
+read 1024/1024 bytes at offset 134218752
382
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
383
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
384
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
385
*** done
386
--
387
1.8.3.1
388
389
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We already audited (in commit 0c1bd469) that qcow2_discard_clusters()
4
is only passed cluster-aligned start values; but we can further
5
tighten the assertion that the only unaligned end value is at EOF.
6
7
Recent commits have taken advantage of an unaligned tail cluster,
8
for both discard and write zeroes.
9
10
Signed-off-by: Eric Blake <eblake@redhat.com>
11
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Message-id: 20170507000552.20847-12-eblake@redhat.com
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
15
block/qcow2-cluster.c | 15 +++++++++++----
16
1 file changed, 11 insertions(+), 4 deletions(-)
17
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2-cluster.c
21
+++ b/block/qcow2-cluster.c
22
@@ -XXX,XX +XXX,XX @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
23
24
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
25
26
- /* The caller must cluster-align start; round end down except at EOF */
27
+ /* Caller must pass aligned values, except at image end */
28
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
29
- if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
30
- end_offset = start_of_cluster(s, end_offset);
31
- }
32
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
33
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
34
35
nb_clusters = size_to_clusters(s, end_offset - offset);
36
37
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
38
int flags)
39
{
40
BDRVQcow2State *s = bs->opaque;
41
+ uint64_t end_offset;
42
uint64_t nb_clusters;
43
int ret;
44
45
+ end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
46
+
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
--
56
1.8.3.1
57
58
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
util/qemu-progress.c is currently unmaintained. The only user of its
4
functionality is qemu-img, so it effectively is part of the block layer.
5
6
Suggested-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Message-id: 20170428165517.30341-1-mreitz@redhat.com
9
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
MAINTAINERS | 1 +
14
1 file changed, 1 insertion(+)
15
16
diff --git a/MAINTAINERS b/MAINTAINERS
17
index XXXXXXX..XXXXXXX 100644
18
--- a/MAINTAINERS
19
+++ b/MAINTAINERS
20
@@ -XXX,XX +XXX,XX @@ F: include/block/
21
F: qemu-img*
22
F: qemu-io*
23
F: tests/qemu-iotests/
24
+F: util/qemu-progress.c
25
T: git git://repo.or.cz/qemu/kevin.git block
26
27
Block I/O path
28
--
29
1.8.3.1
30
31
diff view generated by jsdifflib