1
The following changes since commit 23919ddfd56135cad3cb468a8f54d5a595f024f4:
1
The following changes since commit ba29883206d92a29ad5a466e679ccfc2ee6132ef:
2
2
3
Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20190827' into staging (2019-08-27 15:52:36 +0100)
3
Merge remote-tracking branch 'remotes/borntraeger/tags/s390x-20200310' into staging (2020-03-10 16:50:28 +0000)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/XanClic/qemu.git tags/pull-block-2019-08-27
7
https://github.com/XanClic/qemu.git tags/pull-block-2020-03-11
8
8
9
for you to fetch changes up to bb043c056cffcc2f3ce88bfdaf2e76e455c09e2c:
9
for you to fetch changes up to 397f4e9d83e9c0000905f0a988ba1aeda162571c:
10
10
11
iotests: Unify cache mode quoting (2019-08-27 19:48:44 +0200)
11
block/block-copy: hide structure definitions (2020-03-11 12:42:30 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches:
14
Block patches for the 5.0 softfreeze:
15
- qemu-io now accepts a file to read a write pattern from
15
- qemu-img measure for LUKS
16
- Ensure that raw files have their first block allocated so we can probe
16
- Improve block-copy's performance by reducing inter-request
17
the O_DIRECT alignment if necessary
17
dependencies
18
- Various fixes
18
- Make curl's detection of accept-ranges more robust
19
- Memleak fixes
20
- iotest fix
19
21
20
----------------------------------------------------------------
22
----------------------------------------------------------------
21
Denis Plotnikov (1):
23
David Edmondson (2):
22
qemu-io: add pattern file for write command
24
block/curl: HTTP header fields allow whitespace around values
25
block/curl: HTTP header field names are case insensitive
23
26
24
Max Reitz (7):
27
Eric Blake (1):
25
iotests: Fix _filter_img_create()
28
iotests: Fix nonportable use of od --endian
26
vmdk: Use bdrv_dirname() for relative extent paths
27
iotests: Keep testing broken relative extent paths
28
vmdk: Reject invalid compressed writes
29
iotests: Disable broken streamOptimized tests
30
iotests: Disable 110 for vmdk.twoGbMaxExtentSparse
31
iotests: Disable 126 for flat vmdk subformats
32
29
33
Nir Soffer (3):
30
Pan Nengyuan (2):
34
block: posix: Always allocate the first block
31
block/qcow2: do free crypto_opts in qcow2_close()
35
iotests: Test allocate_first_block() with O_DIRECT
32
qemu-img: free memory before re-assign
36
iotests: Unify cache mode quoting
37
33
38
Stefan Hajnoczi (1):
34
Stefan Hajnoczi (4):
39
file-posix: fix request_alignment typo
35
luks: extract qcrypto_block_calculate_payload_offset()
36
luks: implement .bdrv_measure()
37
qemu-img: allow qemu-img measure --object without a filename
38
iotests: add 288 luks qemu-img measure test
40
39
41
Thomas Huth (2):
40
Vladimir Sementsov-Ogievskiy (10):
42
iotests: Check for enabled drivers before testing them
41
block/qcow2-threads: fix qcow2_decompress
43
tests/check-block: Skip iotests when sanitizers are enabled
42
job: refactor progress to separate object
43
block/block-copy: fix progress calculation
44
block/block-copy: specialcase first copy_range request
45
block/block-copy: use block_status
46
block/block-copy: factor out find_conflicting_inflight_req
47
block/block-copy: refactor interfaces to use bytes instead of end
48
block/block-copy: rename start to offset in interfaces
49
block/block-copy: reduce intersecting request lock
50
block/block-copy: hide structure definitions
44
51
45
Vladimir Sementsov-Ogievskiy (1):
52
block/backup-top.c | 6 +-
46
block: fix permission update in bdrv_replace_node
53
block/backup.c | 38 ++-
47
54
block/block-copy.c | 405 ++++++++++++++++++++++++-------
48
block.c | 5 +-
55
block/crypto.c | 62 +++++
49
block/file-posix.c | 53 +++++++++-
56
block/curl.c | 32 ++-
50
block/vmdk.c | 64 ++++++++----
57
block/qcow2-threads.c | 12 +-
51
qemu-io-cmds.c | 99 +++++++++++++++++--
58
block/qcow2.c | 75 ++----
52
tests/check-block.sh | 5 +
59
block/trace-events | 1 +
53
tests/qemu-iotests/002 | 1 +
60
blockjob.c | 16 +-
54
tests/qemu-iotests/003 | 1 +
61
crypto/block.c | 36 +++
55
tests/qemu-iotests/005 | 3 +-
62
include/block/block-copy.h | 65 +----
56
tests/qemu-iotests/009 | 1 +
63
include/crypto/block.h | 22 ++
57
tests/qemu-iotests/010 | 1 +
64
include/qemu/job.h | 11 +-
58
tests/qemu-iotests/011 | 1 +
65
include/qemu/progress_meter.h | 58 +++++
59
tests/qemu-iotests/017 | 3 +-
66
job-qmp.c | 4 +-
60
tests/qemu-iotests/018 | 3 +-
67
job.c | 6 +-
61
tests/qemu-iotests/019 | 3 +-
68
qemu-img.c | 14 +-
62
tests/qemu-iotests/020 | 3 +-
69
tests/qemu-iotests/178 | 2 +-
63
tests/qemu-iotests/026 | 4 +-
70
tests/qemu-iotests/178.out.qcow2 | 8 +-
64
tests/qemu-iotests/027 | 1 +
71
tests/qemu-iotests/178.out.raw | 8 +-
65
tests/qemu-iotests/032 | 1 +
72
tests/qemu-iotests/288 | 93 +++++++
66
tests/qemu-iotests/033 | 1 +
73
tests/qemu-iotests/288.out | 30 +++
67
tests/qemu-iotests/034 | 3 +-
74
tests/qemu-iotests/common.rc | 22 +-
68
tests/qemu-iotests/037 | 3 +-
75
tests/qemu-iotests/group | 1 +
69
tests/qemu-iotests/039 | 4 +-
76
24 files changed, 749 insertions(+), 278 deletions(-)
70
tests/qemu-iotests/052 | 2 +-
77
create mode 100644 include/qemu/progress_meter.h
71
tests/qemu-iotests/059 | 34 ++++++-
78
create mode 100755 tests/qemu-iotests/288
72
tests/qemu-iotests/059.out | 26 +++--
79
create mode 100644 tests/qemu-iotests/288.out
73
tests/qemu-iotests/063 | 3 +-
74
tests/qemu-iotests/071 | 1 +
75
tests/qemu-iotests/072 | 1 +
76
tests/qemu-iotests/081 | 4 +-
77
tests/qemu-iotests/091 | 4 +-
78
tests/qemu-iotests/099 | 1 +
79
tests/qemu-iotests/105 | 3 +-
80
tests/qemu-iotests/110 | 3 +-
81
tests/qemu-iotests/120 | 1 +
82
tests/qemu-iotests/126 | 2 +
83
tests/qemu-iotests/{150.out => 150.out.qcow2} | 0
84
tests/qemu-iotests/150.out.raw | 12 +++
85
tests/qemu-iotests/162 | 4 +-
86
tests/qemu-iotests/175 | 47 +++++++--
87
tests/qemu-iotests/175.out | 16 ++-
88
tests/qemu-iotests/178.out.qcow2 | 4 +-
89
tests/qemu-iotests/184 | 1 +
90
tests/qemu-iotests/186 | 1 +
91
tests/qemu-iotests/197 | 1 +
92
tests/qemu-iotests/215 | 1 +
93
tests/qemu-iotests/221.out | 12 ++-
94
tests/qemu-iotests/251 | 1 +
95
tests/qemu-iotests/253.out | 12 ++-
96
tests/qemu-iotests/common.filter | 4 +-
97
tests/qemu-iotests/common.rc | 14 +++
98
50 files changed, 391 insertions(+), 87 deletions(-)
99
rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%)
100
create mode 100644 tests/qemu-iotests/150.out.raw
101
80
102
--
81
--
103
2.21.0
82
2.24.1
104
83
105
84
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
2
3
Quoting cache mode is not needed, and most tests use unquoted values.
3
The qcow2 .bdrv_measure() code calculates the crypto payload offset.
4
Unify all test to use the same style.
4
This logic really belongs in crypto/block.c where it can be reused by
5
5
other image formats.
6
Message-id: 20190827173432.7656-1-nsoffer@redhat.com
6
7
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
7
The "luks" block driver will need this same logic in order to implement
8
.bdrv_measure(), so extract the qcrypto_block_calculate_payload_offset()
9
function now.
10
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Message-Id: <20200221112522.1497712-2-stefanha@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
15
---
10
tests/qemu-iotests/026 | 4 ++--
16
block/qcow2.c | 74 +++++++++++-------------------------------
11
tests/qemu-iotests/039 | 4 ++--
17
crypto/block.c | 36 ++++++++++++++++++++
12
tests/qemu-iotests/052 | 2 +-
18
include/crypto/block.h | 22 +++++++++++++
13
tests/qemu-iotests/091 | 4 ++--
19
3 files changed, 77 insertions(+), 55 deletions(-)
14
4 files changed, 7 insertions(+), 7 deletions(-)
20
15
21
diff --git a/block/qcow2.c b/block/qcow2.c
16
diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
22
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100755
23
--- a/block/qcow2.c
18
--- a/tests/qemu-iotests/026
24
+++ b/block/qcow2.c
19
+++ b/tests/qemu-iotests/026
25
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_flush_to_os(BlockDriverState *bs)
20
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
26
return ret;
21
# Currently only qcow2 supports rebasing
27
}
22
_supported_fmt qcow2
28
23
_supported_proto file
29
-static ssize_t qcow2_measure_crypto_hdr_init_func(QCryptoBlock *block,
24
-_default_cache_mode "writethrough"
30
- size_t headerlen, void *opaque, Error **errp)
25
-_supported_cache_modes "writethrough" "none"
31
-{
26
+_default_cache_mode writethrough
32
- size_t *headerlenp = opaque;
27
+_supported_cache_modes writethrough none
33
-
28
# The refcount table tests expect a certain minimum width for refcount entries
34
- /* Stash away the payload size */
29
# (so that the refcount table actually needs to grow); that minimum is 16 bits,
35
- *headerlenp = headerlen;
30
# being the default refcount entry width.
36
- return 0;
31
diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
37
-}
32
index XXXXXXX..XXXXXXX 100755
38
-
33
--- a/tests/qemu-iotests/039
39
-static ssize_t qcow2_measure_crypto_hdr_write_func(QCryptoBlock *block,
34
+++ b/tests/qemu-iotests/039
40
- size_t offset, const uint8_t *buf, size_t buflen,
35
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
41
- void *opaque, Error **errp)
36
_supported_fmt qcow2
42
-{
37
_supported_proto file
43
- /* Discard the bytes, we're not actually writing to an image */
38
_supported_os Linux
44
- return buflen;
39
-_default_cache_mode "writethrough"
45
-}
40
-_supported_cache_modes "writethrough"
46
-
41
+_default_cache_mode writethrough
47
-/* Determine the number of bytes for the LUKS payload */
42
+_supported_cache_modes writethrough
48
-static bool qcow2_measure_luks_headerlen(QemuOpts *opts, size_t *len,
43
49
- Error **errp)
44
size=128M
50
-{
45
51
- QDict *opts_qdict;
46
diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052
52
- QDict *cryptoopts_qdict;
47
index XXXXXXX..XXXXXXX 100755
53
- QCryptoBlockCreateOptions *cryptoopts;
48
--- a/tests/qemu-iotests/052
54
- QCryptoBlock *crypto;
49
+++ b/tests/qemu-iotests/052
55
-
50
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
56
- /* Extract "encrypt." options into a qdict */
51
_supported_proto file
57
- opts_qdict = qemu_opts_to_qdict(opts, NULL);
52
58
- qdict_extract_subqdict(opts_qdict, &cryptoopts_qdict, "encrypt.");
53
# Don't do O_DIRECT on tmpfs
59
- qobject_unref(opts_qdict);
54
-_supported_cache_modes "writeback" "writethrough" "unsafe"
60
-
55
+_supported_cache_modes writeback writethrough unsafe
61
- /* Build QCryptoBlockCreateOptions object from qdict */
56
62
- qdict_put_str(cryptoopts_qdict, "format", "luks");
57
size=128M
63
- cryptoopts = block_crypto_create_opts_init(cryptoopts_qdict, errp);
58
_make_test_img $size
64
- qobject_unref(cryptoopts_qdict);
59
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
65
- if (!cryptoopts) {
60
index XXXXXXX..XXXXXXX 100755
66
- return false;
61
--- a/tests/qemu-iotests/091
67
- }
62
+++ b/tests/qemu-iotests/091
68
-
63
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
69
- /* Fake LUKS creation in order to determine the payload size */
64
_supported_fmt qcow2
70
- crypto = qcrypto_block_create(cryptoopts, "encrypt.",
65
_supported_proto file
71
- qcow2_measure_crypto_hdr_init_func,
66
_supported_os Linux
72
- qcow2_measure_crypto_hdr_write_func,
67
-_default_cache_mode "none"
73
- len, errp);
68
-_supported_cache_modes "writethrough" "none" "writeback"
74
- qapi_free_QCryptoBlockCreateOptions(cryptoopts);
69
+_default_cache_mode none
75
- if (!crypto) {
70
+_supported_cache_modes writethrough none writeback
76
- return false;
71
77
- }
72
size=1G
78
-
73
79
- qcrypto_block_free(crypto);
80
- return true;
81
-}
82
-
83
static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
84
Error **errp)
85
{
86
@@ -XXX,XX +XXX,XX @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
87
g_free(optstr);
88
89
if (has_luks) {
90
+ g_autoptr(QCryptoBlockCreateOptions) create_opts = NULL;
91
+ QDict *opts_qdict;
92
+ QDict *cryptoopts;
93
size_t headerlen;
94
95
- if (!qcow2_measure_luks_headerlen(opts, &headerlen, &local_err)) {
96
+ opts_qdict = qemu_opts_to_qdict(opts, NULL);
97
+ qdict_extract_subqdict(opts_qdict, &cryptoopts, "encrypt.");
98
+ qobject_unref(opts_qdict);
99
+
100
+ qdict_put_str(cryptoopts, "format", "luks");
101
+
102
+ create_opts = block_crypto_create_opts_init(cryptoopts, errp);
103
+ qobject_unref(cryptoopts);
104
+ if (!create_opts) {
105
+ goto err;
106
+ }
107
+
108
+ if (!qcrypto_block_calculate_payload_offset(create_opts,
109
+ "encrypt.",
110
+ &headerlen,
111
+ &local_err)) {
112
goto err;
113
}
114
115
diff --git a/crypto/block.c b/crypto/block.c
116
index XXXXXXX..XXXXXXX 100644
117
--- a/crypto/block.c
118
+++ b/crypto/block.c
119
@@ -XXX,XX +XXX,XX @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
120
}
121
122
123
+static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
124
+ size_t headerlen, void *opaque, Error **errp)
125
+{
126
+ size_t *headerlenp = opaque;
127
+
128
+ /* Stash away the payload size */
129
+ *headerlenp = headerlen;
130
+ return 0;
131
+}
132
+
133
+
134
+static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
135
+ size_t offset, const uint8_t *buf, size_t buflen,
136
+ void *opaque, Error **errp)
137
+{
138
+ /* Discard the bytes, we're not actually writing to an image */
139
+ return buflen;
140
+}
141
+
142
+
143
+bool
144
+qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_opts,
145
+ const char *optprefix,
146
+ size_t *len,
147
+ Error **errp)
148
+{
149
+ /* Fake LUKS creation in order to determine the payload size */
150
+ g_autoptr(QCryptoBlock) crypto =
151
+ qcrypto_block_create(create_opts, optprefix,
152
+ qcrypto_block_headerlen_hdr_init_func,
153
+ qcrypto_block_headerlen_hdr_write_func,
154
+ len, errp);
155
+ return crypto != NULL;
156
+}
157
+
158
+
159
QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
160
Error **errp)
161
{
162
diff --git a/include/crypto/block.h b/include/crypto/block.h
163
index XXXXXXX..XXXXXXX 100644
164
--- a/include/crypto/block.h
165
+++ b/include/crypto/block.h
166
@@ -XXX,XX +XXX,XX @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
167
Error **errp);
168
169
170
+/**
171
+ * qcrypto_block_calculate_payload_offset:
172
+ * @create_opts: the encryption options
173
+ * @optprefix: name prefix for options
174
+ * @len: output for number of header bytes before payload
175
+ * @errp: pointer to a NULL-initialized error object
176
+ *
177
+ * Calculate the number of header bytes before the payload in an encrypted
178
+ * storage volume. The header is an area before the payload that is reserved
179
+ * for encryption metadata.
180
+ *
181
+ * Returns: true on success, false on error
182
+ */
183
+bool
184
+qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_opts,
185
+ const char *optprefix,
186
+ size_t *len,
187
+ Error **errp);
188
+
189
+
190
/**
191
* qcrypto_block_get_info:
192
* @block: the block encryption object
193
@@ -XXX,XX +XXX,XX @@ uint64_t qcrypto_block_get_sector_size(QCryptoBlock *block);
194
void qcrypto_block_free(QCryptoBlock *block);
195
196
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free)
197
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlockCreateOptions,
198
+ qapi_free_QCryptoBlockCreateOptions)
199
200
#endif /* QCRYPTO_BLOCK_H */
74
--
201
--
75
2.21.0
202
2.24.1
76
203
77
204
diff view generated by jsdifflib
1
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
2
3
The patch allows to provide a pattern file for write
3
Add qemu-img measure support in the "luks" block driver.
4
command. There was no similar ability before.
5
4
6
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7
Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com
6
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
7
Message-Id: <20200221112522.1497712-3-stefanha@redhat.com>
9
[mreitz: Keep optstring in alphabetical order]
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
9
---
12
qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++---
10
block/crypto.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
13
1 file changed, 93 insertions(+), 6 deletions(-)
11
1 file changed, 62 insertions(+)
14
12
15
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
13
diff --git a/block/crypto.c b/block/crypto.c
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/qemu-io-cmds.c
15
--- a/block/crypto.c
18
+++ b/qemu-io-cmds.c
16
+++ b/block/crypto.c
19
@@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p)
17
@@ -XXX,XX +XXX,XX @@ static int64_t block_crypto_getlength(BlockDriverState *bs)
20
qemu_vfree(p);
21
}
18
}
22
19
23
+/*
20
24
+ * qemu_io_alloc_from_file()
21
+static BlockMeasureInfo *block_crypto_measure(QemuOpts *opts,
25
+ *
22
+ BlockDriverState *in_bs,
26
+ * Allocates the buffer and populates it with the content of the given file
23
+ Error **errp)
27
+ * up to @len bytes. If the file length is less than @len, then the buffer
28
+ * is populated with the file content cyclically.
29
+ *
30
+ * @blk - the block backend where the buffer content is going to be written to
31
+ * @len - the buffer length
32
+ * @file_name - the file to read the content from
33
+ *
34
+ * Returns: the buffer pointer on success
35
+ * NULL on error
36
+ */
37
+static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
38
+ const char *file_name)
39
+{
24
+{
40
+ char *buf, *buf_origin;
25
+ g_autoptr(QCryptoBlockCreateOptions) create_opts = NULL;
41
+ FILE *f = fopen(file_name, "r");
26
+ Error *local_err = NULL;
42
+ int pattern_len;
27
+ BlockMeasureInfo *info;
28
+ uint64_t size;
29
+ size_t luks_payload_size;
30
+ QDict *cryptoopts;
43
+
31
+
44
+ if (!f) {
32
+ /*
45
+ perror(file_name);
33
+ * Preallocation mode doesn't affect size requirements but we must consume
46
+ return NULL;
34
+ * the option.
35
+ */
36
+ g_free(qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC));
37
+
38
+ size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
39
+
40
+ if (in_bs) {
41
+ int64_t ssize = bdrv_getlength(in_bs);
42
+
43
+ if (ssize < 0) {
44
+ error_setg_errno(&local_err, -ssize,
45
+ "Unable to get image virtual_size");
46
+ goto err;
47
+ }
48
+
49
+ size = ssize;
47
+ }
50
+ }
48
+
51
+
49
+ if (qemuio_misalign) {
52
+ cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL,
50
+ len += MISALIGN_OFFSET;
53
+ &block_crypto_create_opts_luks, true);
54
+ qdict_put_str(cryptoopts, "format", "luks");
55
+ create_opts = block_crypto_create_opts_init(cryptoopts, &local_err);
56
+ qobject_unref(cryptoopts);
57
+ if (!create_opts) {
58
+ goto err;
51
+ }
59
+ }
52
+
60
+
53
+ buf_origin = buf = blk_blockalign(blk, len);
61
+ if (!qcrypto_block_calculate_payload_offset(create_opts, NULL,
54
+
62
+ &luks_payload_size,
55
+ if (qemuio_misalign) {
63
+ &local_err)) {
56
+ buf_origin += MISALIGN_OFFSET;
64
+ goto err;
57
+ buf += MISALIGN_OFFSET;
58
+ len -= MISALIGN_OFFSET;
59
+ }
65
+ }
60
+
66
+
61
+ pattern_len = fread(buf_origin, 1, len, f);
67
+ /*
68
+ * Unallocated blocks are still encrypted so allocation status makes no
69
+ * difference to the file size.
70
+ */
71
+ info = g_new(BlockMeasureInfo, 1);
72
+ info->fully_allocated = luks_payload_size + size;
73
+ info->required = luks_payload_size + size;
74
+ return info;
62
+
75
+
63
+ if (ferror(f)) {
76
+err:
64
+ perror(file_name);
77
+ error_propagate(errp, local_err);
65
+ goto error;
66
+ }
67
+
68
+ if (pattern_len == 0) {
69
+ fprintf(stderr, "%s: file is empty\n", file_name);
70
+ goto error;
71
+ }
72
+
73
+ fclose(f);
74
+
75
+ if (len > pattern_len) {
76
+ len -= pattern_len;
77
+ buf += pattern_len;
78
+
79
+ while (len > 0) {
80
+ size_t len_to_copy = MIN(pattern_len, len);
81
+
82
+ memcpy(buf, buf_origin, len_to_copy);
83
+
84
+ len -= len_to_copy;
85
+ buf += len_to_copy;
86
+ }
87
+ }
88
+
89
+ return buf_origin;
90
+
91
+error:
92
+ qemu_io_free(buf_origin);
93
+ return NULL;
78
+ return NULL;
94
+}
79
+}
95
+
80
+
96
static void dump_buffer(const void *buffer, int64_t offset, int64_t len)
81
+
97
{
82
static int block_crypto_probe_luks(const uint8_t *buf,
98
uint64_t i;
83
int buf_size,
99
@@ -XXX,XX +XXX,XX @@ static void write_help(void)
84
const char *filename) {
100
" -n, -- with -z, don't allow slow fallback\n"
85
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_crypto_luks = {
101
" -p, -- ignored for backwards compatibility\n"
86
.bdrv_co_preadv = block_crypto_co_preadv,
102
" -P, -- use different pattern to fill file\n"
87
.bdrv_co_pwritev = block_crypto_co_pwritev,
103
+" -s, -- use a pattern file to fill the write buffer\n"
88
.bdrv_getlength = block_crypto_getlength,
104
" -C, -- report statistics in a machine parsable format\n"
89
+ .bdrv_measure = block_crypto_measure,
105
" -q, -- quiet mode, do not show I/O statistics\n"
90
.bdrv_get_info = block_crypto_get_info_luks,
106
" -u, -- with -z, allow unmapping\n"
91
.bdrv_get_specific_info = block_crypto_get_specific_info_luks,
107
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = {
92
108
.perm = BLK_PERM_WRITE,
109
.argmin = 2,
110
.argmax = -1,
111
- .args = "[-bcCfnquz] [-P pattern] off len",
112
+ .args = "[-bcCfnquz] [-P pattern | -s source_file] off len",
113
.oneline = "writes a number of bytes at a specified offset",
114
.help = write_help,
115
};
116
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
117
{
118
struct timespec t1, t2;
119
bool Cflag = false, qflag = false, bflag = false;
120
- bool Pflag = false, zflag = false, cflag = false;
121
+ bool Pflag = false, zflag = false, cflag = false, sflag = false;
122
int flags = 0;
123
int c, cnt, ret;
124
char *buf = NULL;
125
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
126
/* Some compilers get confused and warn if this is not initialized. */
127
int64_t total = 0;
128
int pattern = 0xcd;
129
+ const char *file_name = NULL;
130
131
- while ((c = getopt(argc, argv, "bcCfnpP:quz")) != -1) {
132
+ while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) {
133
switch (c) {
134
case 'b':
135
bflag = true;
136
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
137
case 'q':
138
qflag = true;
139
break;
140
+ case 's':
141
+ sflag = true;
142
+ file_name = optarg;
143
+ break;
144
case 'u':
145
flags |= BDRV_REQ_MAY_UNMAP;
146
break;
147
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
148
return -EINVAL;
149
}
150
151
- if (zflag && Pflag) {
152
- printf("-z and -P cannot be specified at the same time\n");
153
+ if (zflag + Pflag + sflag > 1) {
154
+ printf("Only one of -z, -P, and -s "
155
+ "can be specified at the same time\n");
156
return -EINVAL;
157
}
158
159
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
160
}
161
162
if (!zflag) {
163
- buf = qemu_io_alloc(blk, count, pattern);
164
+ if (sflag) {
165
+ buf = qemu_io_alloc_from_file(blk, count, file_name);
166
+ if (!buf) {
167
+ return -EINVAL;
168
+ }
169
+ } else {
170
+ buf = qemu_io_alloc(blk, count, pattern);
171
+ }
172
}
173
174
clock_gettime(CLOCK_MONOTONIC, &t1);
175
--
93
--
176
2.21.0
94
2.24.1
177
95
178
96
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
2
3
The sanitizers (especially the address sanitizer from Clang) are
3
In most qemu-img sub-commands the --object option only makes sense when
4
sometimes printing out warnings or false positives - this spoils
4
there is a filename. qemu-img measure is an exception because objects
5
the output of the iotests, causing some of the tests to fail.
5
may be referenced from the image creation options instead of an existing
6
Thus let's skip the automatic iotests during "make check" when the
6
image file. Allow --object without a filename.
7
user configured QEMU with --enable-sanitizers.
8
7
9
Signed-off-by: Thomas Huth <thuth@redhat.com>
8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
Message-id: 20190823084203.29734-1-thuth@redhat.com
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Message-Id: <20200221112522.1497712-4-stefanha@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
12
---
13
tests/check-block.sh | 5 +++++
13
qemu-img.c | 6 ++----
14
1 file changed, 5 insertions(+)
14
tests/qemu-iotests/178 | 2 +-
15
tests/qemu-iotests/178.out.qcow2 | 8 ++++----
16
tests/qemu-iotests/178.out.raw | 8 ++++----
17
4 files changed, 11 insertions(+), 13 deletions(-)
15
18
16
diff --git a/tests/check-block.sh b/tests/check-block.sh
19
diff --git a/qemu-img.c b/qemu-img.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/qemu-img.c
22
+++ b/qemu-img.c
23
@@ -XXX,XX +XXX,XX @@ static int img_measure(int argc, char **argv)
24
filename = argv[optind];
25
}
26
27
- if (!filename &&
28
- (object_opts || image_opts || fmt || snapshot_name || sn_opts)) {
29
- error_report("--object, --image-opts, -f, and -l "
30
- "require a filename argument.");
31
+ if (!filename && (image_opts || fmt || snapshot_name || sn_opts)) {
32
+ error_report("--image-opts, -f, and -l require a filename argument.");
33
goto out;
34
}
35
if (filename && img_size != UINT64_MAX) {
36
diff --git a/tests/qemu-iotests/178 b/tests/qemu-iotests/178
17
index XXXXXXX..XXXXXXX 100755
37
index XXXXXXX..XXXXXXX 100755
18
--- a/tests/check-block.sh
38
--- a/tests/qemu-iotests/178
19
+++ b/tests/check-block.sh
39
+++ b/tests/qemu-iotests/178
20
@@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then
40
@@ -XXX,XX +XXX,XX @@ _make_test_img 1G
21
exit 0
41
$QEMU_IMG measure # missing arguments
22
fi
42
$QEMU_IMG measure --size 2G "$TEST_IMG" # only one allowed
23
43
$QEMU_IMG measure "$TEST_IMG" a # only one filename allowed
24
+if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then
44
-$QEMU_IMG measure --object secret,id=sec0,data=MTIzNDU2,format=base64 # missing filename
25
+ echo "Sanitizers are enabled ==> Not running the qemu-iotests."
45
+$QEMU_IMG measure --object secret,id=sec0,data=MTIzNDU2,format=base64 # size or filename needed
26
+ exit 0
46
$QEMU_IMG measure --image-opts # missing filename
27
+fi
47
$QEMU_IMG measure -f qcow2 # missing filename
28
+
48
$QEMU_IMG measure -l snap1 # missing filename
29
if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then
49
diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2
30
echo "No qemu-system binary available ==> Not running the qemu-iotests."
50
index XXXXXXX..XXXXXXX 100644
31
exit 0
51
--- a/tests/qemu-iotests/178.out.qcow2
52
+++ b/tests/qemu-iotests/178.out.qcow2
53
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
54
qemu-img: Either --size N or one filename must be specified.
55
qemu-img: --size N cannot be used together with a filename.
56
qemu-img: At most one filename argument is allowed.
57
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
58
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
59
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
60
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
61
+qemu-img: Either --size N or one filename must be specified.
62
+qemu-img: --image-opts, -f, and -l require a filename argument.
63
+qemu-img: --image-opts, -f, and -l require a filename argument.
64
+qemu-img: --image-opts, -f, and -l require a filename argument.
65
qemu-img: Invalid option list: ,
66
qemu-img: Invalid parameter 'snapshot.foo'
67
qemu-img: Failed in parsing snapshot param 'snapshot.foo'
68
diff --git a/tests/qemu-iotests/178.out.raw b/tests/qemu-iotests/178.out.raw
69
index XXXXXXX..XXXXXXX 100644
70
--- a/tests/qemu-iotests/178.out.raw
71
+++ b/tests/qemu-iotests/178.out.raw
72
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
73
qemu-img: Either --size N or one filename must be specified.
74
qemu-img: --size N cannot be used together with a filename.
75
qemu-img: At most one filename argument is allowed.
76
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
77
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
78
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
79
-qemu-img: --object, --image-opts, -f, and -l require a filename argument.
80
+qemu-img: Either --size N or one filename must be specified.
81
+qemu-img: --image-opts, -f, and -l require a filename argument.
82
+qemu-img: --image-opts, -f, and -l require a filename argument.
83
+qemu-img: --image-opts, -f, and -l require a filename argument.
84
qemu-img: Invalid option list: ,
85
qemu-img: Invalid parameter 'snapshot.foo'
86
qemu-img: Failed in parsing snapshot param 'snapshot.foo'
32
--
87
--
33
2.21.0
88
2.24.1
34
89
35
90
diff view generated by jsdifflib
1
From: Stefan Hajnoczi <stefanha@redhat.com>
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
2
3
Fixes: a6b257a08e3d72219f03e461a52152672fec0612
3
This test exercises the block/crypto.c "luks" block driver
4
("file-posix: Handle undetectable alignment")
4
.bdrv_measure() code.
5
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Message-id: 20190827101328.4062-1-stefanha@redhat.com
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
8
Message-Id: <20200221112522.1497712-5-stefanha@redhat.com>
9
[mreitz: Renamed test from 282 to 288]
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
11
---
10
block/file-posix.c | 2 +-
12
tests/qemu-iotests/288 | 93 ++++++++++++++++++++++++++++++++++++++
11
1 file changed, 1 insertion(+), 1 deletion(-)
13
tests/qemu-iotests/288.out | 30 ++++++++++++
14
tests/qemu-iotests/group | 1 +
15
3 files changed, 124 insertions(+)
16
create mode 100755 tests/qemu-iotests/288
17
create mode 100644 tests/qemu-iotests/288.out
12
18
13
diff --git a/block/file-posix.c b/block/file-posix.c
19
diff --git a/tests/qemu-iotests/288 b/tests/qemu-iotests/288
20
new file mode 100755
21
index XXXXXXX..XXXXXXX
22
--- /dev/null
23
+++ b/tests/qemu-iotests/288
24
@@ -XXX,XX +XXX,XX @@
25
+#!/usr/bin/env bash
26
+#
27
+# qemu-img measure tests for LUKS images
28
+#
29
+# Copyright (C) 2020 Red Hat, Inc.
30
+#
31
+# This program is free software; you can redistribute it and/or modify
32
+# it under the terms of the GNU General Public License as published by
33
+# the Free Software Foundation; either version 2 of the License, or
34
+# (at your option) any later version.
35
+#
36
+# This program is distributed in the hope that it will be useful,
37
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
38
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39
+# GNU General Public License for more details.
40
+#
41
+# You should have received a copy of the GNU General Public License
42
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
43
+#
44
+
45
+# creator
46
+owner=stefanha@redhat.com
47
+
48
+seq=`basename $0`
49
+echo "QA output created by $seq"
50
+
51
+status=1 # failure is the default!
52
+
53
+_cleanup()
54
+{
55
+ _cleanup_test_img
56
+ rm -f "$TEST_IMG.converted"
57
+}
58
+trap "_cleanup; exit \$status" 0 1 2 3 15
59
+
60
+# get standard environment, filters and checks
61
+. ./common.rc
62
+. ./common.filter
63
+. ./common.pattern
64
+
65
+_supported_fmt luks
66
+_supported_proto file
67
+_supported_os Linux
68
+
69
+SECRET=secret,id=sec0,data=passphrase
70
+
71
+echo "== measure 1G image file =="
72
+echo
73
+
74
+$QEMU_IMG measure --object "$SECRET" \
75
+     -O "$IMGFMT" \
76
+         -o key-secret=sec0,iter-time=10 \
77
+         --size 1G
78
+
79
+echo
80
+echo "== create 1G image file (size should be no greater than measured) =="
81
+echo
82
+
83
+_make_test_img 1G
84
+stat -c "image file size in bytes: %s" "$TEST_IMG_FILE"
85
+
86
+echo
87
+echo "== modified 1G image file (size should be no greater than measured) =="
88
+echo
89
+
90
+$QEMU_IO --object "$SECRET" --image-opts "$TEST_IMG" -c "write -P 0x51 0x10000 0x400" | _filter_qemu_io | _filter_testdir
91
+stat -c "image file size in bytes: %s" "$TEST_IMG_FILE"
92
+
93
+echo
94
+echo "== measure preallocation=falloc 1G image file =="
95
+echo
96
+
97
+$QEMU_IMG measure --object "$SECRET" \
98
+     -O "$IMGFMT" \
99
+         -o key-secret=sec0,iter-time=10,preallocation=falloc \
100
+         --size 1G
101
+
102
+echo
103
+echo "== measure with input image file =="
104
+echo
105
+
106
+IMGFMT=raw IMGKEYSECRET= IMGOPTS= _make_test_img 1G | _filter_imgfmt
107
+QEMU_IO_OPTIONS= IMGOPTSSYNTAX= $QEMU_IO -f raw -c "write -P 0x51 0x10000 0x400" "$TEST_IMG_FILE" | _filter_qemu_io | _filter_testdir
108
+$QEMU_IMG measure --object "$SECRET" \
109
+     -O "$IMGFMT" \
110
+         -o key-secret=sec0,iter-time=10 \
111
+         -f raw \
112
+         "$TEST_IMG_FILE"
113
+
114
+# success, all done
115
+echo "*** done"
116
+rm -f $seq.full
117
+status=0
118
diff --git a/tests/qemu-iotests/288.out b/tests/qemu-iotests/288.out
119
new file mode 100644
120
index XXXXXXX..XXXXXXX
121
--- /dev/null
122
+++ b/tests/qemu-iotests/288.out
123
@@ -XXX,XX +XXX,XX @@
124
+QA output created by 288
125
+== measure 1G image file ==
126
+
127
+required size: 1075810304
128
+fully allocated size: 1075810304
129
+
130
+== create 1G image file (size should be no greater than measured) ==
131
+
132
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
133
+image file size in bytes: 1075810304
134
+
135
+== modified 1G image file (size should be no greater than measured) ==
136
+
137
+wrote 1024/1024 bytes at offset 65536
138
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
139
+image file size in bytes: 1075810304
140
+
141
+== measure preallocation=falloc 1G image file ==
142
+
143
+required size: 1075810304
144
+fully allocated size: 1075810304
145
+
146
+== measure with input image file ==
147
+
148
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
149
+wrote 1024/1024 bytes at offset 65536
150
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
151
+required size: 1075810304
152
+fully allocated size: 1075810304
153
+*** done
154
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
14
index XXXXXXX..XXXXXXX 100644
155
index XXXXXXX..XXXXXXX 100644
15
--- a/block/file-posix.c
156
--- a/tests/qemu-iotests/group
16
+++ b/block/file-posix.c
157
+++ b/tests/qemu-iotests/group
17
@@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
158
@@ -XXX,XX +XXX,XX @@
18
for (i = 0; i < ARRAY_SIZE(alignments); i++) {
159
283 auto quick
19
align = alignments[i];
160
284 rw
20
if (raw_is_io_aligned(fd, buf + align, max_align)) {
161
286 rw quick
21
- /* Fallback to request_aligment. */
162
+288 quick
22
+ /* Fallback to request_alignment. */
23
s->buf_align = (align != 1) ? align : bs->bl.request_alignment;
24
break;
25
}
26
--
163
--
27
2.21.0
164
2.24.1
28
165
29
166
diff view generated by jsdifflib
1
Compressed writes generally have to write full clusters, not just in
1
From: David Edmondson <david.edmondson@oracle.com>
2
theory but also in practice when it comes to vmdk's streamOptimized
3
subformat. It currently is just silently broken for writes with
4
non-zero in-cluster offsets:
5
2
6
$ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M
3
RFC 7230 section 3.2 indicates that whitespace is permitted between
7
$ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk
4
the field name and field value and after the field value.
8
wrote 4096/4096 bytes at offset 4096
9
4 KiB, 1 ops; 00.01 sec (443.724 KiB/sec and 110.9309 ops/sec)
10
read failed: Invalid argument
11
5
12
(The technical reason is that vmdk_write_extent() just writes the
6
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
13
incomplete compressed data actually to offset 4k. When reading the
7
Message-Id: <20200224101310.101169-2-david.edmondson@oracle.com>
14
data, vmdk_read_extent() looks at offset 0 and finds the compressed data
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
size to be 0, because that is what it reads from there. This yields an
16
error.)
17
18
For incomplete writes with zero in-cluster offsets, the error path when
19
reading the rest of the cluster is a bit different, but the result is
20
the same:
21
22
$ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M
23
$ qemu-io -c 'write 0k 4k' -c 'read 4k 4k' foo.vmdk
24
wrote 4096/4096 bytes at offset 0
25
4 KiB, 1 ops; 00.01 sec (362.641 KiB/sec and 90.6603 ops/sec)
26
read failed: Invalid argument
27
28
(Here, vmdk_read_extent() finds the data and then sees that the
29
uncompressed data is short.)
30
31
It is better to reject invalid writes than to make the user believe they
32
might have succeeded and then fail when trying to read it back.
33
34
Signed-off-by: Max Reitz <mreitz@redhat.com>
35
Reviewed-by: John Snow <jsnow@redhat.com>
36
Message-id: 20190815153638.4600-5-mreitz@redhat.com
37
Reviewed-by: John Snow <jsnow@redhat.com>
38
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
39
---
10
---
40
block/vmdk.c | 10 ++++++++++
11
block/curl.c | 31 +++++++++++++++++++++++++++----
41
1 file changed, 10 insertions(+)
12
1 file changed, 27 insertions(+), 4 deletions(-)
42
13
43
diff --git a/block/vmdk.c b/block/vmdk.c
14
diff --git a/block/curl.c b/block/curl.c
44
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
45
--- a/block/vmdk.c
16
--- a/block/curl.c
46
+++ b/block/vmdk.c
17
+++ b/block/curl.c
47
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
18
@@ -XXX,XX +XXX,XX @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
48
if (extent->compressed) {
19
{
49
void *compressed_data;
20
BDRVCURLState *s = opaque;
50
21
size_t realsize = size * nmemb;
51
+ /* Only whole clusters */
22
- const char *accept_line = "Accept-Ranges: bytes";
52
+ if (offset_in_cluster ||
23
+ const char *header = (char *)ptr;
53
+ n_bytes > (extent->cluster_sectors * SECTOR_SIZE) ||
24
+ const char *end = header + realsize;
54
+ (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) &&
25
+ const char *accept_ranges = "Accept-Ranges:";
55
+ offset + n_bytes != extent->end_sector * SECTOR_SIZE))
26
+ const char *bytes = "bytes";
56
+ {
27
57
+ ret = -EINVAL;
28
- if (realsize >= strlen(accept_line)
58
+ goto out;
29
- && strncmp((char *)ptr, accept_line, strlen(accept_line)) == 0) {
30
- s->accept_range = true;
31
+ if (realsize >= strlen(accept_ranges)
32
+ && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
33
+
34
+ char *p = strchr(header, ':') + 1;
35
+
36
+ /* Skip whitespace between the header name and value. */
37
+ while (p < end && *p && g_ascii_isspace(*p)) {
38
+ p++;
59
+ }
39
+ }
60
+
40
+
61
if (!extent->has_marker) {
41
+ if (end - p >= strlen(bytes)
62
ret = -EINVAL;
42
+ && strncmp(p, bytes, strlen(bytes)) == 0) {
63
goto out;
43
+
44
+ /* Check that there is nothing but whitespace after the value. */
45
+ p += strlen(bytes);
46
+ while (p < end && *p && g_ascii_isspace(*p)) {
47
+ p++;
48
+ }
49
+
50
+ if (p == end || !*p) {
51
+ s->accept_range = true;
52
+ }
53
+ }
54
}
55
56
return realsize;
64
--
57
--
65
2.21.0
58
2.24.1
66
59
67
60
diff view generated by jsdifflib
1
The error message for the test case where we have a quorum node for
1
From: David Edmondson <david.edmondson@oracle.com>
2
which no directory name can be generated is different: For
3
twoGbMaxExtentSparse, it complains that it cannot open the extent file.
4
For other (sub)formats, it just notes that it cannot determine the
5
backing file path. Both are fine, but just disable twoGbMaxExtentSparse
6
for simplicity's sake.
7
2
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
RFC 7230 section 3.2 indicates that HTTP header field names are case
9
Reviewed-by: John Snow <jsnow@redhat.com>
4
insensitive.
10
Message-id: 20190815153638.4600-7-mreitz@redhat.com
5
11
Reviewed-by: John Snow <jsnow@redhat.com>
6
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
7
Message-Id: <20200224101310.101169-3-david.edmondson@oracle.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
10
---
14
tests/qemu-iotests/110 | 3 ++-
11
block/curl.c | 5 +++--
15
1 file changed, 2 insertions(+), 1 deletion(-)
12
1 file changed, 3 insertions(+), 2 deletions(-)
16
13
17
diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110
14
diff --git a/block/curl.c b/block/curl.c
18
index XXXXXXX..XXXXXXX 100755
15
index XXXXXXX..XXXXXXX 100644
19
--- a/tests/qemu-iotests/110
16
--- a/block/curl.c
20
+++ b/tests/qemu-iotests/110
17
+++ b/block/curl.c
21
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
18
@@ -XXX,XX +XXX,XX @@ static size_t curl_header_cb(void *ptr, size_t size, size_t nmemb, void *opaque)
22
# Any format supporting backing files
19
size_t realsize = size * nmemb;
23
_supported_fmt qed qcow qcow2 vmdk
20
const char *header = (char *)ptr;
24
_supported_proto file
21
const char *end = header + realsize;
25
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
22
- const char *accept_ranges = "Accept-Ranges:";
26
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
23
+ const char *accept_ranges = "accept-ranges:";
27
+ "subformat=twoGbMaxExtentSparse"
24
const char *bytes = "bytes";
28
25
29
TEST_IMG_REL=$(basename "$TEST_IMG")
26
if (realsize >= strlen(accept_ranges)
27
- && strncmp(header, accept_ranges, strlen(accept_ranges)) == 0) {
28
+ && g_ascii_strncasecmp(header, accept_ranges,
29
+ strlen(accept_ranges)) == 0) {
30
31
char *p = strchr(header, ':') + 1;
30
32
31
--
33
--
32
2.21.0
34
2.24.1
33
35
34
36
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Eric Blake <eblake@redhat.com>
2
2
3
It is possible to enable only a subset of the block drivers with the
3
Tests 261 and 272 fail on RHEL 7 with coreutils 8.22, since od
4
"--block-drv-rw-whitelist" option of the "configure" script. All other
4
--endian was not added until coreutils 8.23. Fix this by manually
5
drivers are marked as unusable (or only included as read-only with the
5
constructing the final value one byte at a time.
6
"--block-drv-ro-whitelist" option). If an iotest is now using such a
7
disabled block driver, it is failing - which is bad, since at least the
8
tests in the "auto" group should be able to deal with this situation.
9
Thus let's introduce a "_require_drivers" function that can be used by
10
the shell tests to check for the availability of certain drivers first,
11
and marks the test as "not run" if one of the drivers is missing.
12
6
13
This patch mainly targets the test in the "auto" group which should
7
Fixes: fc8ba423
14
never fail in such a case, but also improves some of the other tests
8
Reported-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
15
along the way. Note that we also assume that the "qcow2" and "file"
9
Signed-off-by: Eric Blake <eblake@redhat.com>
16
drivers are always available - otherwise it does not make sense to
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
run "make check-block" at all (which only tests with qcow2 by default).
11
Message-Id: <20200226125424.481840-1-eblake@redhat.com>
18
19
Signed-off-by: Thomas Huth <thuth@redhat.com>
20
Message-id: 20190823133552.11680-1-thuth@redhat.com
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
---
13
---
23
tests/qemu-iotests/071 | 1 +
14
tests/qemu-iotests/common.rc | 22 +++++++++++++++++-----
24
tests/qemu-iotests/081 | 4 +---
15
1 file changed, 17 insertions(+), 5 deletions(-)
25
tests/qemu-iotests/099 | 1 +
26
tests/qemu-iotests/120 | 1 +
27
tests/qemu-iotests/162 | 4 +---
28
tests/qemu-iotests/184 | 1 +
29
tests/qemu-iotests/186 | 1 +
30
tests/qemu-iotests/common.rc | 14 ++++++++++++++
31
8 files changed, 21 insertions(+), 6 deletions(-)
32
16
33
diff --git a/tests/qemu-iotests/071 b/tests/qemu-iotests/071
34
index XXXXXXX..XXXXXXX 100755
35
--- a/tests/qemu-iotests/071
36
+++ b/tests/qemu-iotests/071
37
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
38
39
_supported_fmt qcow2
40
_supported_proto file
41
+_require_drivers blkdebug blkverify
42
43
do_run_qemu()
44
{
45
diff --git a/tests/qemu-iotests/081 b/tests/qemu-iotests/081
46
index XXXXXXX..XXXXXXX 100755
47
--- a/tests/qemu-iotests/081
48
+++ b/tests/qemu-iotests/081
49
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
50
_supported_fmt raw
51
_supported_proto file
52
_supported_os Linux
53
+_require_drivers quorum
54
55
do_run_qemu()
56
{
57
@@ -XXX,XX +XXX,XX @@ run_qemu()
58
| _filter_qemu_io | _filter_generated_node_ids
59
}
60
61
-test_quorum=$($QEMU_IMG --help|grep quorum)
62
-[ "$test_quorum" = "" ] && _supported_fmt quorum
63
-
64
quorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
65
quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
66
quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
67
diff --git a/tests/qemu-iotests/099 b/tests/qemu-iotests/099
68
index XXXXXXX..XXXXXXX 100755
69
--- a/tests/qemu-iotests/099
70
+++ b/tests/qemu-iotests/099
71
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
72
_supported_fmt qcow qcow2 qed vdi vhdx vmdk vpc
73
_supported_proto file
74
_supported_os Linux
75
+_require_drivers blkdebug blkverify
76
_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
77
"subformat=twoGbMaxExtentSparse"
78
79
diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120
80
index XXXXXXX..XXXXXXX 100755
81
--- a/tests/qemu-iotests/120
82
+++ b/tests/qemu-iotests/120
83
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
84
_supported_fmt generic
85
_supported_proto file
86
_unsupported_fmt luks
87
+_require_drivers raw
88
89
_make_test_img 64M
90
91
diff --git a/tests/qemu-iotests/162 b/tests/qemu-iotests/162
92
index XXXXXXX..XXXXXXX 100755
93
--- a/tests/qemu-iotests/162
94
+++ b/tests/qemu-iotests/162
95
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
96
. ./common.filter
97
98
_supported_fmt generic
99
-
100
-test_ssh=$($QEMU_IMG --help | grep '^Supported formats:.* ssh\( \|$\)')
101
-[ "$test_ssh" = "" ] && _notrun "ssh support required"
102
+_require_drivers ssh
103
104
echo
105
echo '=== NBD ==='
106
diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184
107
index XXXXXXX..XXXXXXX 100755
108
--- a/tests/qemu-iotests/184
109
+++ b/tests/qemu-iotests/184
110
@@ -XXX,XX +XXX,XX @@ trap "exit \$status" 0 1 2 3 15
111
. ./common.filter
112
113
_supported_os Linux
114
+_require_drivers throttle
115
116
do_run_qemu()
117
{
118
diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186
119
index XXXXXXX..XXXXXXX 100755
120
--- a/tests/qemu-iotests/186
121
+++ b/tests/qemu-iotests/186
122
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
123
124
_supported_fmt qcow2
125
_supported_proto file
126
+_require_drivers null-co
127
128
if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then
129
_notrun "Requires a PC machine"
130
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
17
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
131
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
132
--- a/tests/qemu-iotests/common.rc
19
--- a/tests/qemu-iotests/common.rc
133
+++ b/tests/qemu-iotests/common.rc
20
+++ b/tests/qemu-iotests/common.rc
134
@@ -XXX,XX +XXX,XX @@ _require_command()
21
@@ -XXX,XX +XXX,XX @@ poke_file()
135
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
22
# peek_file_le 'test.img' 512 2 => 65534
23
peek_file_le()
24
{
25
- # Wrap in echo $() to strip spaces
26
- echo $(od -j"$2" -N"$3" --endian=little -An -vtu"$3" "$1")
27
+ local val=0 shift=0 byte
28
+
29
+ # coreutils' od --endian is not portable, so manually assemble bytes.
30
+ for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
31
+ val=$(( val | (byte << shift) ))
32
+ shift=$((shift + 8))
33
+ done
34
+ printf %llu $val
136
}
35
}
137
36
138
+# Check that a set of drivers has been whitelisted in the QEMU binary
37
# peek_file_be 'test.img' 512 2 => 65279
139
+#
38
peek_file_be()
140
+_require_drivers()
39
{
141
+{
40
- # Wrap in echo $() to strip spaces
142
+ available=$($QEMU -drive format=help | \
41
- echo $(od -j"$2" -N"$3" --endian=big -An -vtu"$3" "$1")
143
+ sed -e '/Supported formats:/!d' -e 's/Supported formats://')
42
+ local val=0 byte
144
+ for driver
43
+
145
+ do
44
+ # coreutils' od --endian is not portable, so manually assemble bytes.
146
+ if ! echo "$available" | grep -q " $driver\( \|$\)"; then
45
+ for byte in $(od -j"$2" -N"$3" -An -v -tu1 "$1"); do
147
+ _notrun "$driver not available"
46
+ val=$(( (val << 8) | byte ))
148
+ fi
149
+ done
47
+ done
150
+}
48
+ printf %llu $val
151
+
49
}
152
# make sure this script returns success
50
153
true
51
-# peek_file_raw 'test.img' 512 2 => '\xff\xfe'
52
+# peek_file_raw 'test.img' 512 2 => '\xff\xfe'. Do not use if the raw data
53
+# is likely to contain \0 or trailing \n.
54
peek_file_raw()
55
{
56
dd if="$1" bs=1 skip="$2" count="$3" status=none
154
--
57
--
155
2.21.0
58
2.24.1
156
59
157
60
diff view generated by jsdifflib
1
streamOptimized does not support writes that do not span exactly one
1
From: Pan Nengyuan <pannengyuan@huawei.com>
2
cluster. Furthermore, it cannot rewrite already allocated clusters.
3
As such, many iotests do not work with it. Disable them.
4
2
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
'crypto_opts' forgot to free in qcow2_close(), this patch fix the bellow leak stack:
6
Message-id: 20190815153638.4600-6-mreitz@redhat.com
4
7
Reviewed-by: John Snow <jsnow@redhat.com>
5
Direct leak of 24 byte(s) in 1 object(s) allocated from:
6
#0 0x7f0edd81f970 in __interceptor_calloc (/lib64/libasan.so.5+0xef970)
7
#1 0x7f0edc6d149d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5249d)
8
#2 0x55d7eaede63d in qobject_input_start_struct /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qobject-input-visitor.c:295
9
#3 0x55d7eaed78b8 in visit_start_struct /mnt/sdb/qemu-new/qemu_test/qemu/qapi/qapi-visit-core.c:49
10
#4 0x55d7eaf5140b in visit_type_QCryptoBlockOpenOptions qapi/qapi-visit-crypto.c:290
11
#5 0x55d7eae43af3 in block_crypto_open_opts_init /mnt/sdb/qemu-new/qemu_test/qemu/block/crypto.c:163
12
#6 0x55d7eacd2924 in qcow2_update_options_prepare /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:1148
13
#7 0x55d7eacd33f7 in qcow2_update_options /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:1232
14
#8 0x55d7eacd9680 in qcow2_do_open /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:1512
15
#9 0x55d7eacdc55e in qcow2_open_entry /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:1792
16
#10 0x55d7eacdc8fe in qcow2_open /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:1819
17
#11 0x55d7eac3742d in bdrv_open_driver /mnt/sdb/qemu-new/qemu_test/qemu/block.c:1317
18
#12 0x55d7eac3e990 in bdrv_open_common /mnt/sdb/qemu-new/qemu_test/qemu/block.c:1575
19
#13 0x55d7eac4442c in bdrv_open_inherit /mnt/sdb/qemu-new/qemu_test/qemu/block.c:3126
20
#14 0x55d7eac45c3f in bdrv_open /mnt/sdb/qemu-new/qemu_test/qemu/block.c:3219
21
#15 0x55d7ead8e8a4 in blk_new_open /mnt/sdb/qemu-new/qemu_test/qemu/block/block-backend.c:397
22
#16 0x55d7eacde74c in qcow2_co_create /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:3534
23
#17 0x55d7eacdfa6d in qcow2_co_create_opts /mnt/sdb/qemu-new/qemu_test/qemu/block/qcow2.c:3668
24
#18 0x55d7eac1c678 in bdrv_create_co_entry /mnt/sdb/qemu-new/qemu_test/qemu/block.c:485
25
#19 0x55d7eb0024d2 in coroutine_trampoline /mnt/sdb/qemu-new/qemu_test/qemu/util/coroutine-ucontext.c:115
26
27
Reported-by: Euler Robot <euler.robot@huawei.com>
28
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
29
Reviewed-by: Max Reitz <mreitz@redhat.com>
30
Message-Id: <20200227012950.12256-2-pannengyuan@huawei.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
31
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
---
32
---
10
tests/qemu-iotests/002 | 1 +
33
block/qcow2.c | 1 +
11
tests/qemu-iotests/003 | 1 +
34
1 file changed, 1 insertion(+)
12
tests/qemu-iotests/005 | 3 ++-
13
tests/qemu-iotests/009 | 1 +
14
tests/qemu-iotests/010 | 1 +
15
tests/qemu-iotests/011 | 1 +
16
tests/qemu-iotests/017 | 3 ++-
17
tests/qemu-iotests/018 | 3 ++-
18
tests/qemu-iotests/019 | 3 ++-
19
tests/qemu-iotests/020 | 3 ++-
20
tests/qemu-iotests/027 | 1 +
21
tests/qemu-iotests/032 | 1 +
22
tests/qemu-iotests/033 | 1 +
23
tests/qemu-iotests/034 | 3 ++-
24
tests/qemu-iotests/037 | 3 ++-
25
tests/qemu-iotests/063 | 3 ++-
26
tests/qemu-iotests/072 | 1 +
27
tests/qemu-iotests/105 | 3 ++-
28
tests/qemu-iotests/197 | 1 +
29
tests/qemu-iotests/215 | 1 +
30
tests/qemu-iotests/251 | 1 +
31
21 files changed, 30 insertions(+), 9 deletions(-)
32
35
33
diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002
36
diff --git a/block/qcow2.c b/block/qcow2.c
34
index XXXXXXX..XXXXXXX 100755
37
index XXXXXXX..XXXXXXX 100644
35
--- a/tests/qemu-iotests/002
38
--- a/block/qcow2.c
36
+++ b/tests/qemu-iotests/002
39
+++ b/block/qcow2.c
37
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
40
@@ -XXX,XX +XXX,XX @@ static void qcow2_close(BlockDriverState *bs)
38
41
39
_supported_fmt generic
42
qcrypto_block_free(s->crypto);
40
_supported_proto generic
43
s->crypto = NULL;
41
+_unsupported_imgopts "subformat=streamOptimized"
44
+ qapi_free_QCryptoBlockOpenOptions(s->crypto_opts);
42
45
43
46
g_free(s->unknown_header_fields);
44
size=128M
47
cleanup_unknown_header_ext(bs);
45
diff --git a/tests/qemu-iotests/003 b/tests/qemu-iotests/003
46
index XXXXXXX..XXXXXXX 100755
47
--- a/tests/qemu-iotests/003
48
+++ b/tests/qemu-iotests/003
49
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
50
51
_supported_fmt generic
52
_supported_proto generic
53
+_unsupported_imgopts "subformat=streamOptimized"
54
55
size=128M
56
offset=67M
57
diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005
58
index XXXXXXX..XXXXXXX 100755
59
--- a/tests/qemu-iotests/005
60
+++ b/tests/qemu-iotests/005
61
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
62
_supported_proto generic
63
_supported_os Linux
64
_unsupported_imgopts "subformat=twoGbMaxExtentFlat" \
65
- "subformat=twoGbMaxExtentSparse"
66
+ "subformat=twoGbMaxExtentSparse" \
67
+ "subformat=streamOptimized"
68
69
# vpc is limited to 127GB, so we can't test it here
70
if [ "$IMGFMT" = "vpc" ]; then
71
diff --git a/tests/qemu-iotests/009 b/tests/qemu-iotests/009
72
index XXXXXXX..XXXXXXX 100755
73
--- a/tests/qemu-iotests/009
74
+++ b/tests/qemu-iotests/009
75
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
76
77
_supported_fmt generic
78
_supported_proto generic
79
+_unsupported_imgopts "subformat=streamOptimized"
80
81
82
size=6G
83
diff --git a/tests/qemu-iotests/010 b/tests/qemu-iotests/010
84
index XXXXXXX..XXXXXXX 100755
85
--- a/tests/qemu-iotests/010
86
+++ b/tests/qemu-iotests/010
87
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
88
89
_supported_fmt generic
90
_supported_proto generic
91
+_unsupported_imgopts "subformat=streamOptimized"
92
93
94
size=6G
95
diff --git a/tests/qemu-iotests/011 b/tests/qemu-iotests/011
96
index XXXXXXX..XXXXXXX 100755
97
--- a/tests/qemu-iotests/011
98
+++ b/tests/qemu-iotests/011
99
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
100
101
_supported_fmt generic
102
_supported_proto generic
103
+_unsupported_imgopts "subformat=streamOptimized"
104
105
106
size=6G
107
diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017
108
index XXXXXXX..XXXXXXX 100755
109
--- a/tests/qemu-iotests/017
110
+++ b/tests/qemu-iotests/017
111
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
112
_supported_fmt qcow qcow2 vmdk qed
113
_supported_proto generic
114
_unsupported_proto vxhs
115
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
116
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
117
+ "subformat=streamOptimized"
118
119
TEST_OFFSETS="0 4294967296"
120
121
diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018
122
index XXXXXXX..XXXXXXX 100755
123
--- a/tests/qemu-iotests/018
124
+++ b/tests/qemu-iotests/018
125
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
126
_supported_fmt qcow qcow2 vmdk qed
127
_supported_proto file
128
_supported_os Linux
129
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
130
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
131
+ "streamOptimized"
132
133
TEST_OFFSETS="0 4294967296"
134
135
diff --git a/tests/qemu-iotests/019 b/tests/qemu-iotests/019
136
index XXXXXXX..XXXXXXX 100755
137
--- a/tests/qemu-iotests/019
138
+++ b/tests/qemu-iotests/019
139
@@ -XXX,XX +XXX,XX @@ _supported_proto file
140
_supported_os Linux
141
_unsupported_imgopts "subformat=monolithicFlat" \
142
"subformat=twoGbMaxExtentFlat" \
143
- "subformat=twoGbMaxExtentSparse"
144
+ "subformat=twoGbMaxExtentSparse" \
145
+ "subformat=streamOptimized"
146
147
TEST_OFFSETS="0 4294967296"
148
CLUSTER_SIZE=65536
149
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
150
index XXXXXXX..XXXXXXX 100755
151
--- a/tests/qemu-iotests/020
152
+++ b/tests/qemu-iotests/020
153
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed
154
_supported_proto file
155
_unsupported_imgopts "subformat=monolithicFlat" \
156
"subformat=twoGbMaxExtentFlat" \
157
- "subformat=twoGbMaxExtentSparse"
158
+ "subformat=twoGbMaxExtentSparse" \
159
+ "subformat=streamOptimized"
160
161
TEST_OFFSETS="0 4294967296"
162
163
diff --git a/tests/qemu-iotests/027 b/tests/qemu-iotests/027
164
index XXXXXXX..XXXXXXX 100755
165
--- a/tests/qemu-iotests/027
166
+++ b/tests/qemu-iotests/027
167
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
168
169
_supported_fmt vmdk qcow qcow2 qed
170
_supported_proto generic
171
+_unsupported_imgopts "subformat=streamOptimized"
172
173
174
size=128M
175
diff --git a/tests/qemu-iotests/032 b/tests/qemu-iotests/032
176
index XXXXXXX..XXXXXXX 100755
177
--- a/tests/qemu-iotests/032
178
+++ b/tests/qemu-iotests/032
179
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
180
# This works for any image format (though unlikely to segfault for raw)
181
_supported_fmt generic
182
_supported_proto generic
183
+_unsupported_imgopts "subformat=streamOptimized"
184
185
echo
186
echo === Prepare image ===
187
diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033
188
index XXXXXXX..XXXXXXX 100755
189
--- a/tests/qemu-iotests/033
190
+++ b/tests/qemu-iotests/033
191
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
192
193
_supported_fmt generic
194
_supported_proto generic
195
+_unsupported_imgopts "subformat=streamOptimized"
196
197
198
size=128M
199
diff --git a/tests/qemu-iotests/034 b/tests/qemu-iotests/034
200
index XXXXXXX..XXXXXXX 100755
201
--- a/tests/qemu-iotests/034
202
+++ b/tests/qemu-iotests/034
203
@@ -XXX,XX +XXX,XX @@ _supported_proto file
204
_supported_os Linux
205
_unsupported_imgopts "subformat=monolithicFlat" \
206
"subformat=twoGbMaxExtentFlat" \
207
- "subformat=twoGbMaxExtentSparse"
208
+ "subformat=twoGbMaxExtentSparse" \
209
+ "subformat=streamOptimized"
210
211
CLUSTER_SIZE=4k
212
size=128M
213
diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037
214
index XXXXXXX..XXXXXXX 100755
215
--- a/tests/qemu-iotests/037
216
+++ b/tests/qemu-iotests/037
217
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed
218
_supported_proto file
219
_unsupported_imgopts "subformat=monolithicFlat" \
220
"subformat=twoGbMaxExtentFlat" \
221
- "subformat=twoGbMaxExtentSparse"
222
+ "subformat=twoGbMaxExtentSparse" \
223
+ "subformat=streamOptimized"
224
225
CLUSTER_SIZE=4k
226
size=128M
227
diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063
228
index XXXXXXX..XXXXXXX 100755
229
--- a/tests/qemu-iotests/063
230
+++ b/tests/qemu-iotests/063
231
@@ -XXX,XX +XXX,XX @@ _supported_fmt qcow qcow2 vmdk qed raw
232
_supported_proto file
233
_unsupported_imgopts "subformat=monolithicFlat" \
234
"subformat=twoGbMaxExtentFlat" \
235
- "subformat=twoGbMaxExtentSparse"
236
+ "subformat=twoGbMaxExtentSparse" \
237
+ "subformat=streamOptimized"
238
239
_make_test_img 4M
240
241
diff --git a/tests/qemu-iotests/072 b/tests/qemu-iotests/072
242
index XXXXXXX..XXXXXXX 100755
243
--- a/tests/qemu-iotests/072
244
+++ b/tests/qemu-iotests/072
245
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
246
247
_supported_fmt vpc vmdk vhdx vdi qed qcow2 qcow
248
_supported_proto file
249
+_unsupported_imgopts "subformat=streamOptimized"
250
251
IMG_SIZE=64M
252
253
diff --git a/tests/qemu-iotests/105 b/tests/qemu-iotests/105
254
index XXXXXXX..XXXXXXX 100755
255
--- a/tests/qemu-iotests/105
256
+++ b/tests/qemu-iotests/105
257
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
258
_supported_fmt qcow2 vmdk vhdx qed
259
_supported_proto generic
260
_unsupported_imgopts "subformat=twoGbMaxExtentFlat" \
261
- "subformat=twoGbMaxExtentSparse"
262
+ "subformat=twoGbMaxExtentSparse" \
263
+ "subformat=streamOptimized"
264
265
echo
266
echo "creating large image"
267
diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197
268
index XXXXXXX..XXXXXXX 100755
269
--- a/tests/qemu-iotests/197
270
+++ b/tests/qemu-iotests/197
271
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
272
_supported_proto generic
273
# LUKS support may be possible, but it complicates things.
274
_unsupported_fmt luks
275
+_unsupported_imgopts "subformat=streamOptimized"
276
277
echo
278
echo '=== Copy-on-read ==='
279
diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215
280
index XXXXXXX..XXXXXXX 100755
281
--- a/tests/qemu-iotests/215
282
+++ b/tests/qemu-iotests/215
283
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
284
_supported_proto generic
285
# LUKS support may be possible, but it complicates things.
286
_unsupported_fmt luks
287
+_unsupported_imgopts "subformat=streamOptimized"
288
289
echo
290
echo '=== Copy-on-read ==='
291
diff --git a/tests/qemu-iotests/251 b/tests/qemu-iotests/251
292
index XXXXXXX..XXXXXXX 100755
293
--- a/tests/qemu-iotests/251
294
+++ b/tests/qemu-iotests/251
295
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
296
_supported_fmt generic
297
_supported_proto file
298
_supported_os Linux
299
+_unsupported_imgopts "subformat=streamOptimized"
300
301
if [ "$IMGOPTSSYNTAX" = "true" ]; then
302
# We use json:{} filenames here, so we cannot work with additional options.
303
--
48
--
304
2.21.0
49
2.24.1
305
50
306
51
diff view generated by jsdifflib
1
iotest 126 requires backing file support, which flat vmdks cannot offer.
1
From: Pan Nengyuan <pannengyuan@huawei.com>
2
Skip this test for such subformats.
3
2
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
collect_image_check() is called twice in img_check(), the filename/format will be alloced without free the original memory.
5
Message-id: 20190815153638.4600-8-mreitz@redhat.com
4
It is not a big deal since the process will exit anyway, but seems like a clean code and it will remove the warning spotted by asan.
6
Reviewed-by: John Snow <jsnow@redhat.com>
5
6
Reported-by: Euler Robot <euler.robot@huawei.com>
7
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
8
Message-Id: <20200227012950.12256-3-pannengyuan@huawei.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
---
10
---
9
tests/qemu-iotests/126 | 2 ++
11
qemu-img.c | 2 ++
10
1 file changed, 2 insertions(+)
12
1 file changed, 2 insertions(+)
11
13
12
diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126
14
diff --git a/qemu-img.c b/qemu-img.c
13
index XXXXXXX..XXXXXXX 100755
15
index XXXXXXX..XXXXXXX 100644
14
--- a/tests/qemu-iotests/126
16
--- a/qemu-img.c
15
+++ b/tests/qemu-iotests/126
17
+++ b/qemu-img.c
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
18
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
17
19
check->corruptions_fixed);
18
# Needs backing file support
20
}
19
_supported_fmt qcow qcow2 qed vmdk
21
20
+_unsupported_imgopts "subformat=monolithicFlat" \
22
+ qapi_free_ImageCheck(check);
21
+ "subformat=twoGbMaxExtentFlat"
23
+ check = g_new0(ImageCheck, 1);
22
# This is the default protocol (and we want to test the difference between
24
ret = collect_image_check(bs, check, filename, fmt, 0);
23
# colons which separate a protocol prefix from the rest and colons which are
25
24
# just part of the filename, so we cannot test protocols which require a prefix)
26
check->leaks_fixed = leaks_fixed;
25
--
27
--
26
2.21.0
28
2.24.1
27
29
28
30
diff view generated by jsdifflib
1
We had a test for a case where relative extent paths did not work, but
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
unfortunately we just fixed the underlying problem, so it works now.
3
This patch adds a new test case that still fails.
4
2
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
3
On success path we return what inflate() returns instead of 0. And it
6
Reviewed-by: John Snow <jsnow@redhat.com>
4
most probably works for Z_STREAM_END as it is positive, but is
7
Message-id: 20190815153638.4600-4-mreitz@redhat.com
5
definitely broken for Z_BUF_ERROR.
8
Reviewed-by: John Snow <jsnow@redhat.com>
6
7
While being here, switch to errno return code, to be closer to
8
qcow2_compress API (and usual expectations).
9
10
Revert condition in if to be more positive. Drop dead initialization of
11
ret.
12
13
Cc: qemu-stable@nongnu.org # v4.0
14
Fixes: 341926ab83e2b
15
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
16
Message-Id: <20200302150930.16218-1-vsementsov@virtuozzo.com>
17
Reviewed-by: Alberto Garcia <berto@igalia.com>
18
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
19
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
---
20
---
11
tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++
21
block/qcow2-threads.c | 12 +++++++-----
12
tests/qemu-iotests/059.out | 4 ++++
22
1 file changed, 7 insertions(+), 5 deletions(-)
13
2 files changed, 31 insertions(+)
14
23
15
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
24
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
16
index XXXXXXX..XXXXXXX 100755
17
--- a/tests/qemu-iotests/059
18
+++ b/tests/qemu-iotests/059
19
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
20
21
echo
22
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
23
+
24
+echo '--- blkdebug ---'
25
# Should work, because bdrv_dirname() works fine with blkdebug
26
IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
27
$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
28
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE
29
| _filter_testdir | _filter_imgfmt | _filter_img_info
30
_cleanup_test_img
31
32
+echo '--- quorum ---'
33
+# Should not work, because bdrv_dirname() does not work with quorum
34
+IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
35
+cp "$TEST_IMG" "$TEST_IMG.orig"
36
+
37
+filename="json:{
38
+ \"driver\": \"$IMGFMT\",
39
+ \"file\": {
40
+ \"driver\": \"quorum\",
41
+ \"children\": [ {
42
+ \"driver\": \"file\",
43
+ \"filename\": \"$TEST_IMG\"
44
+ }, {
45
+ \"driver\": \"file\",
46
+ \"filename\": \"$TEST_IMG.orig\"
47
+ } ],
48
+ \"vote-threshold\": 1
49
+ } }"
50
+
51
+filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g')
52
+$QEMU_IMG info "$filename" 2>&1 \
53
+ | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \
54
+ | _filter_testdir | _filter_imgfmt | _filter_img_info
55
+
56
+
57
echo
58
echo "=== Testing version 3 ==="
59
_use_sample_img iotest-version3.vmdk.bz2
60
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
61
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
62
--- a/tests/qemu-iotests/059.out
26
--- a/block/qcow2-threads.c
63
+++ b/tests/qemu-iotests/059.out
27
+++ b/block/qcow2-threads.c
64
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
28
@@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_compress(void *dest, size_t dest_size,
65
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
29
* @src - source buffer, @src_size bytes
66
30
*
67
=== Testing monolithicFlat with internally generated JSON file name ===
31
* Returns: 0 on success
68
+--- blkdebug ---
32
- * -1 on fail
69
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
33
+ * -EIO on fail
70
format name: IMGFMT
34
*/
71
cluster size: 0 bytes
35
static ssize_t qcow2_decompress(void *dest, size_t dest_size,
72
vm state offset: 0 bytes
36
const void *src, size_t src_size)
73
+--- quorum ---
37
{
74
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
38
- int ret = 0;
75
+qemu-img: Could not open $QUORUM_FILE: Cannot use relative paths with VMDK descriptor file $QUORUM_FILE: Cannot generate a base directory for quorum nodes
39
+ int ret;
76
40
z_stream strm;
77
=== Testing version 3 ===
41
78
image: TEST_DIR/iotest-version3.IMGFMT
42
memset(&strm, 0, sizeof(strm));
43
@@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_decompress(void *dest, size_t dest_size,
44
45
ret = inflateInit2(&strm, -12);
46
if (ret != Z_OK) {
47
- return -1;
48
+ return -EIO;
49
}
50
51
ret = inflate(&strm, Z_FINISH);
52
- if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
53
+ if ((ret == Z_STREAM_END || ret == Z_BUF_ERROR) && strm.avail_out == 0) {
54
/*
55
* We approve Z_BUF_ERROR because we need @dest buffer to be filled, but
56
* @src buffer may be processed partly (because in qcow2 we know size of
57
* compressed data with precision of one sector)
58
*/
59
- ret = -1;
60
+ ret = 0;
61
+ } else {
62
+ ret = -EIO;
63
}
64
65
inflateEnd(&strm);
79
--
66
--
80
2.21.0
67
2.24.1
81
68
82
69
diff view generated by jsdifflib
New patch
1
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
3
We need it in separate to pass to the block-copy object in the next
4
commit.
5
6
Cc: qemu-stable@nongnu.org
7
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Message-Id: <20200311103004.7649-2-vsementsov@virtuozzo.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
blockjob.c | 16 +++++-----
14
include/qemu/job.h | 11 ++-----
15
include/qemu/progress_meter.h | 58 +++++++++++++++++++++++++++++++++++
16
job-qmp.c | 4 +--
17
job.c | 6 ++--
18
qemu-img.c | 6 ++--
19
6 files changed, 76 insertions(+), 25 deletions(-)
20
create mode 100644 include/qemu/progress_meter.h
21
22
diff --git a/blockjob.c b/blockjob.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/blockjob.c
25
+++ b/blockjob.c
26
@@ -XXX,XX +XXX,XX @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
27
info->device = g_strdup(job->job.id);
28
info->busy = atomic_read(&job->job.busy);
29
info->paused = job->job.pause_count > 0;
30
- info->offset = job->job.progress_current;
31
- info->len = job->job.progress_total;
32
+ info->offset = job->job.progress.current;
33
+ info->len = job->job.progress.total;
34
info->speed = job->speed;
35
info->io_status = job->iostatus;
36
info->ready = job_is_ready(&job->job),
37
@@ -XXX,XX +XXX,XX @@ static void block_job_event_cancelled(Notifier *n, void *opaque)
38
39
qapi_event_send_block_job_cancelled(job_type(&job->job),
40
job->job.id,
41
- job->job.progress_total,
42
- job->job.progress_current,
43
+ job->job.progress.total,
44
+ job->job.progress.current,
45
job->speed);
46
}
47
48
@@ -XXX,XX +XXX,XX @@ static void block_job_event_completed(Notifier *n, void *opaque)
49
50
qapi_event_send_block_job_completed(job_type(&job->job),
51
job->job.id,
52
- job->job.progress_total,
53
- job->job.progress_current,
54
+ job->job.progress.total,
55
+ job->job.progress.current,
56
job->speed,
57
!!msg,
58
msg);
59
@@ -XXX,XX +XXX,XX @@ static void block_job_event_ready(Notifier *n, void *opaque)
60
61
qapi_event_send_block_job_ready(job_type(&job->job),
62
job->job.id,
63
- job->job.progress_total,
64
- job->job.progress_current,
65
+ job->job.progress.total,
66
+ job->job.progress.current,
67
job->speed);
68
}
69
70
diff --git a/include/qemu/job.h b/include/qemu/job.h
71
index XXXXXXX..XXXXXXX 100644
72
--- a/include/qemu/job.h
73
+++ b/include/qemu/job.h
74
@@ -XXX,XX +XXX,XX @@
75
76
#include "qapi/qapi-types-job.h"
77
#include "qemu/queue.h"
78
+#include "qemu/progress_meter.h"
79
#include "qemu/coroutine.h"
80
#include "block/aio.h"
81
82
@@ -XXX,XX +XXX,XX @@ typedef struct Job {
83
/** True if this job should automatically dismiss itself */
84
bool auto_dismiss;
85
86
- /**
87
- * Current progress. The unit is arbitrary as long as the ratio between
88
- * progress_current and progress_total represents the estimated percentage
89
- * of work already done.
90
- */
91
- int64_t progress_current;
92
-
93
- /** Estimated progress_current value at the completion of the job */
94
- int64_t progress_total;
95
+ ProgressMeter progress;
96
97
/**
98
* Return code from @run and/or @prepare callback(s).
99
diff --git a/include/qemu/progress_meter.h b/include/qemu/progress_meter.h
100
new file mode 100644
101
index XXXXXXX..XXXXXXX
102
--- /dev/null
103
+++ b/include/qemu/progress_meter.h
104
@@ -XXX,XX +XXX,XX @@
105
+/*
106
+ * Helper functionality for some process progress tracking.
107
+ *
108
+ * Copyright (c) 2011 IBM Corp.
109
+ * Copyright (c) 2012, 2018 Red Hat, Inc.
110
+ * Copyright (c) 2020 Virtuozzo International GmbH
111
+ *
112
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
113
+ * of this software and associated documentation files (the "Software"), to deal
114
+ * in the Software without restriction, including without limitation the rights
115
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
116
+ * copies of the Software, and to permit persons to whom the Software is
117
+ * furnished to do so, subject to the following conditions:
118
+ *
119
+ * The above copyright notice and this permission notice shall be included in
120
+ * all copies or substantial portions of the Software.
121
+ *
122
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
123
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
124
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
125
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
126
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
127
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
128
+ * THE SOFTWARE.
129
+ */
130
+
131
+#ifndef QEMU_PROGRESS_METER_H
132
+#define QEMU_PROGRESS_METER_H
133
+
134
+typedef struct ProgressMeter {
135
+ /**
136
+ * Current progress. The unit is arbitrary as long as the ratio between
137
+ * current and total represents the estimated percentage
138
+ * of work already done.
139
+ */
140
+ uint64_t current;
141
+
142
+ /** Estimated current value at the completion of the process */
143
+ uint64_t total;
144
+} ProgressMeter;
145
+
146
+static inline void progress_work_done(ProgressMeter *pm, uint64_t done)
147
+{
148
+ pm->current += done;
149
+}
150
+
151
+static inline void progress_set_remaining(ProgressMeter *pm, uint64_t remaining)
152
+{
153
+ pm->total = pm->current + remaining;
154
+}
155
+
156
+static inline void progress_increase_remaining(ProgressMeter *pm,
157
+ uint64_t delta)
158
+{
159
+ pm->total += delta;
160
+}
161
+
162
+#endif /* QEMU_PROGRESS_METER_H */
163
diff --git a/job-qmp.c b/job-qmp.c
164
index XXXXXXX..XXXXXXX 100644
165
--- a/job-qmp.c
166
+++ b/job-qmp.c
167
@@ -XXX,XX +XXX,XX @@ static JobInfo *job_query_single(Job *job, Error **errp)
168
.id = g_strdup(job->id),
169
.type = job_type(job),
170
.status = job->status,
171
- .current_progress = job->progress_current,
172
- .total_progress = job->progress_total,
173
+ .current_progress = job->progress.current,
174
+ .total_progress = job->progress.total,
175
.has_error = !!job->err,
176
.error = job->err ? \
177
g_strdup(error_get_pretty(job->err)) : NULL,
178
diff --git a/job.c b/job.c
179
index XXXXXXX..XXXXXXX 100644
180
--- a/job.c
181
+++ b/job.c
182
@@ -XXX,XX +XXX,XX @@ void job_unref(Job *job)
183
184
void job_progress_update(Job *job, uint64_t done)
185
{
186
- job->progress_current += done;
187
+ progress_work_done(&job->progress, done);
188
}
189
190
void job_progress_set_remaining(Job *job, uint64_t remaining)
191
{
192
- job->progress_total = job->progress_current + remaining;
193
+ progress_set_remaining(&job->progress, remaining);
194
}
195
196
void job_progress_increase_remaining(Job *job, uint64_t delta)
197
{
198
- job->progress_total += delta;
199
+ progress_increase_remaining(&job->progress, delta);
200
}
201
202
void job_event_cancelled(Job *job)
203
diff --git a/qemu-img.c b/qemu-img.c
204
index XXXXXXX..XXXXXXX 100644
205
--- a/qemu-img.c
206
+++ b/qemu-img.c
207
@@ -XXX,XX +XXX,XX @@ static void run_block_job(BlockJob *job, Error **errp)
208
do {
209
float progress = 0.0f;
210
aio_poll(aio_context, true);
211
- if (job->job.progress_total) {
212
- progress = (float)job->job.progress_current /
213
- job->job.progress_total * 100.f;
214
+ if (job->job.progress.total) {
215
+ progress = (float)job->job.progress.current /
216
+ job->job.progress.total * 100.f;
217
}
218
qemu_progress_print(progress, 0);
219
} while (!job_is_ready(&job->job) && !job_is_completed(&job->job));
220
--
221
2.24.1
222
223
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
2
3
Using block_resize we can test allocate_first_block() with file
3
Assume we have two regions, A and B, and region B is in-flight now,
4
descriptor opened with O_DIRECT, ensuring that it works for any size
4
region A is not yet touched, but it is unallocated and should be
5
larger than 4096 bytes.
5
skipped.
6
6
7
Testing smaller sizes is tricky as the result depends on the filesystem
7
Correspondingly, as progress we have
8
used for testing. For example on NFS any size will work since O_DIRECT
9
does not require any alignment.
10
8
11
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
9
total = A + B
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
current = 0
13
Message-id: 20190827010528.8818-3-nsoffer@redhat.com
11
12
If we reset unallocated region A and call progress_reset_callback,
13
it will calculate 0 bytes dirty in the bitmap and call
14
job_progress_set_remaining, which will set
15
16
total = current + 0 = 0 + 0 = 0
17
18
So, B bytes are actually removed from total accounting. When job
19
finishes we'll have
20
21
total = 0
22
current = B
23
24
, which doesn't sound good.
25
26
This is because we didn't considered in-flight bytes, actually when
27
calculating remaining, we should have set (in_flight + dirty_bytes)
28
as remaining, not only dirty_bytes.
29
30
To fix it, let's refactor progress calculation, moving it to block-copy
31
itself instead of fixing callback. And, of course, track in_flight
32
bytes count.
33
34
We still have to keep one callback, to maintain backup job bytes_read
35
calculation, but it will go on soon, when we turn the whole backup
36
process into one block_copy call.
37
38
Cc: qemu-stable@nongnu.org
39
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
40
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
41
Message-Id: <20200311103004.7649-3-vsementsov@virtuozzo.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
42
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
43
---
16
tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++
44
block/backup.c | 13 ++-----------
17
tests/qemu-iotests/175.out | 8 ++++++++
45
block/block-copy.c | 16 ++++++++++++----
18
2 files changed, 36 insertions(+)
46
include/block/block-copy.h | 15 +++++----------
47
3 files changed, 19 insertions(+), 25 deletions(-)
19
48
20
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
49
diff --git a/block/backup.c b/block/backup.c
21
index XXXXXXX..XXXXXXX 100755
50
index XXXXXXX..XXXXXXX 100644
22
--- a/tests/qemu-iotests/175
51
--- a/block/backup.c
23
+++ b/tests/qemu-iotests/175
52
+++ b/block/backup.c
24
@@ -XXX,XX +XXX,XX @@ _filter_blocks()
53
@@ -XXX,XX +XXX,XX @@ static void backup_progress_bytes_callback(int64_t bytes, void *opaque)
25
-e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
54
BackupBlockJob *s = opaque;
55
56
s->bytes_read += bytes;
57
- job_progress_update(&s->common.job, bytes);
58
-}
59
-
60
-static void backup_progress_reset_callback(void *opaque)
61
-{
62
- BackupBlockJob *s = opaque;
63
- uint64_t estimate = bdrv_get_dirty_count(s->bcs->copy_bitmap);
64
-
65
- job_progress_set_remaining(&s->common.job, estimate);
26
}
66
}
27
67
28
+# Resize image using block_resize.
68
static int coroutine_fn backup_do_cow(BackupBlockJob *job,
29
+# Parameter 1: image path
69
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
30
+# Parameter 2: new size
70
job->cluster_size = cluster_size;
31
+_block_resize()
71
job->len = len;
72
73
- block_copy_set_callbacks(bcs, backup_progress_bytes_callback,
74
- backup_progress_reset_callback, job);
75
+ block_copy_set_progress_callback(bcs, backup_progress_bytes_callback, job);
76
+ block_copy_set_progress_meter(bcs, &job->common.job.progress);
77
78
/* Required permissions are already taken by backup-top target */
79
block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
80
diff --git a/block/block-copy.c b/block/block-copy.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/block/block-copy.c
83
+++ b/block/block-copy.c
84
@@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
85
return s;
86
}
87
88
-void block_copy_set_callbacks(
89
+void block_copy_set_progress_callback(
90
BlockCopyState *s,
91
ProgressBytesCallbackFunc progress_bytes_callback,
92
- ProgressResetCallbackFunc progress_reset_callback,
93
void *progress_opaque)
94
{
95
s->progress_bytes_callback = progress_bytes_callback;
96
- s->progress_reset_callback = progress_reset_callback;
97
s->progress_opaque = progress_opaque;
98
}
99
100
+void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
32
+{
101
+{
33
+ local path=$1
102
+ s->progress = pm;
34
+ local size=$2
35
+
36
+ $QEMU -qmp stdio -nographic -nodefaults \
37
+ -blockdev file,node-name=file,filename=$path,cache.direct=on \
38
+ <<EOF
39
+{'execute': 'qmp_capabilities'}
40
+{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}}
41
+{'execute': 'quit'}
42
+EOF
43
+}
103
+}
44
+
104
+
45
# get standard environment, filters and checks
105
/*
46
. ./common.rc
106
* block_copy_do_copy
47
. ./common.filter
107
*
48
@@ -XXX,XX +XXX,XX @@ _supported_fmt raw
108
@@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
49
_supported_proto file
109
50
_supported_os Linux
110
if (!ret) {
51
111
bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
52
+_default_cache_mode none
112
- s->progress_reset_callback(s->progress_opaque);
53
+_supported_cache_modes none directsync
113
+ progress_set_remaining(s->progress,
114
+ bdrv_get_dirty_count(s->copy_bitmap) +
115
+ s->in_flight_bytes);
116
}
117
118
*count = bytes;
119
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
120
trace_block_copy_process(s, start);
121
122
bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
123
+ s->in_flight_bytes += chunk_end - start;
124
125
co_get_from_shres(s->mem, chunk_end - start);
126
ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
127
co_put_to_shres(s->mem, chunk_end - start);
128
+ s->in_flight_bytes -= chunk_end - start;
129
if (ret < 0) {
130
bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
131
break;
132
}
133
134
+ progress_work_done(s->progress, chunk_end - start);
135
s->progress_bytes_callback(chunk_end - start, s->progress_opaque);
136
start = chunk_end;
137
ret = 0;
138
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
139
index XXXXXXX..XXXXXXX 100644
140
--- a/include/block/block-copy.h
141
+++ b/include/block/block-copy.h
142
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyInFlightReq {
143
} BlockCopyInFlightReq;
144
145
typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);
146
-typedef void (*ProgressResetCallbackFunc)(void *opaque);
147
typedef struct BlockCopyState {
148
/*
149
* BdrvChild objects are not owned or managed by block-copy. They are
150
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyState {
151
BdrvChild *source;
152
BdrvChild *target;
153
BdrvDirtyBitmap *copy_bitmap;
154
+ int64_t in_flight_bytes;
155
int64_t cluster_size;
156
bool use_copy_range;
157
int64_t copy_size;
158
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyState {
159
*/
160
bool skip_unallocated;
161
162
+ ProgressMeter *progress;
163
/* progress_bytes_callback: called when some copying progress is done. */
164
ProgressBytesCallbackFunc progress_bytes_callback;
165
-
166
- /*
167
- * progress_reset_callback: called when some bytes reset from copy_bitmap
168
- * (see @skip_unallocated above). The callee is assumed to recalculate how
169
- * many bytes remain based on the dirty bit count of copy_bitmap.
170
- */
171
- ProgressResetCallbackFunc progress_reset_callback;
172
void *progress_opaque;
173
174
SharedResource *mem;
175
@@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
176
BdrvRequestFlags write_flags,
177
Error **errp);
178
179
-void block_copy_set_callbacks(
180
+void block_copy_set_progress_callback(
181
BlockCopyState *s,
182
ProgressBytesCallbackFunc progress_bytes_callback,
183
- ProgressResetCallbackFunc progress_reset_callback,
184
void *progress_opaque);
185
186
+void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
54
+
187
+
55
size=$((1 * 1024 * 1024))
188
void block_copy_state_free(BlockCopyState *s);
56
189
57
touch "$TEST_DIR/empty"
190
int64_t block_copy_reset_unallocated(BlockCopyState *s,
58
@@ -XXX,XX +XXX,XX @@ for mode in off full falloc; do
59
stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
60
done
61
62
+for new_size in 4096 1048576; do
63
+ echo
64
+ echo "== resize empty image with block_resize =="
65
+ _make_test_img 0 | _filter_imgfmt
66
+ _block_resize $TEST_IMG $new_size >/dev/null
67
+ stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size
68
+done
69
+
70
# success, all done
71
echo "*** done"
72
rm -f $seq.full
73
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
74
index XXXXXXX..XXXXXXX 100644
75
--- a/tests/qemu-iotests/175.out
76
+++ b/tests/qemu-iotests/175.out
77
@@ -XXX,XX +XXX,XX @@ size=1048576, max allocation
78
== creating image with preallocation falloc ==
79
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
80
size=1048576, max allocation
81
+
82
+== resize empty image with block_resize ==
83
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
84
+size=4096, min allocation
85
+
86
+== resize empty image with block_resize ==
87
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
88
+size=1048576, min allocation
89
*** done
90
--
191
--
91
2.21.0
192
2.24.1
92
193
93
194
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
2
3
It's wrong to OR shared permissions. It may lead to crash on further
3
In block_copy_do_copy we fallback to read+write if copy_range failed.
4
permission updates.
4
In this case copy_size is larger than defined for buffered IO, and
5
Also, no needs to consider previously calculated permissions, as at
5
there is corresponding commit. Still, backup copies data cluster by
6
this point we already bind all new parents and bdrv_get_cumulative_perm
6
cluster, and most of requests are limited to one cluster anyway, so the
7
result is enough. So fix the bug by just set permissions by
7
only source of this one bad-limited request is copy-before-write
8
bdrv_get_cumulative_perm result.
8
operation.
9
9
10
Bug was introduced in long ago 234ac1a9025, in 2.9.
10
Further patch will move backup to use block_copy directly, than for
11
cases where copy_range is not supported, first request will be
12
oversized in each backup. It's not good, let's change it now.
13
14
Fix is simple: just limit first copy_range request like buffer-based
15
request. If it succeed, set larger copy_range limit.
11
16
12
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
17
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com
18
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
19
Reviewed-by: Max Reitz <mreitz@redhat.com>
20
Message-Id: <20200311103004.7649-4-vsementsov@virtuozzo.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
22
---
16
block.c | 5 ++---
23
block/block-copy.c | 41 +++++++++++++++++++++++++++++++----------
17
1 file changed, 2 insertions(+), 3 deletions(-)
24
1 file changed, 31 insertions(+), 10 deletions(-)
18
25
19
diff --git a/block.c b/block.c
26
diff --git a/block/block-copy.c b/block/block-copy.c
20
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
28
--- a/block/block-copy.c
22
+++ b/block.c
29
+++ b/block/block-copy.c
23
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
30
@@ -XXX,XX +XXX,XX @@ void block_copy_state_free(BlockCopyState *s)
31
g_free(s);
32
}
33
34
+static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *target)
35
+{
36
+ return MIN_NON_ZERO(INT_MAX,
37
+ MIN_NON_ZERO(source->bs->bl.max_transfer,
38
+ target->bs->bl.max_transfer));
39
+}
40
+
41
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
42
int64_t cluster_size,
43
BdrvRequestFlags write_flags, Error **errp)
24
{
44
{
25
BdrvChild *c, *next;
45
BlockCopyState *s;
26
GSList *list = NULL, *p;
46
BdrvDirtyBitmap *copy_bitmap;
27
- uint64_t old_perm, old_shared;
47
- uint32_t max_transfer =
28
uint64_t perm = 0, shared = BLK_PERM_ALL;
48
- MIN_NON_ZERO(INT_MAX,
29
int ret;
49
- MIN_NON_ZERO(source->bs->bl.max_transfer,
30
50
- target->bs->bl.max_transfer));
31
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
51
32
bdrv_unref(from);
52
copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL,
53
errp);
54
@@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
55
.mem = shres_create(BLOCK_COPY_MAX_MEM),
56
};
57
58
- if (max_transfer < cluster_size) {
59
+ if (block_copy_max_transfer(source, target) < cluster_size) {
60
/*
61
* copy_range does not respect max_transfer. We don't want to bother
62
* with requests smaller than block-copy cluster size, so fallback to
63
@@ -XXX,XX +XXX,XX @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
64
s->copy_size = cluster_size;
65
} else {
66
/*
67
- * copy_range does not respect max_transfer (it's a TODO), so we factor
68
- * that in here.
69
+ * We enable copy-range, but keep small copy_size, until first
70
+ * successful copy_range (look at block_copy_do_copy).
71
*/
72
s->use_copy_range = true;
73
- s->copy_size = MIN(MAX(cluster_size, BLOCK_COPY_MAX_COPY_RANGE),
74
- QEMU_ALIGN_DOWN(max_transfer, cluster_size));
75
+ s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
33
}
76
}
34
77
35
- bdrv_get_cumulative_perm(to, &old_perm, &old_shared);
78
QLIST_INIT(&s->inflight_reqs);
36
- bdrv_set_perm(to, old_perm | perm, old_shared | shared);
79
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
37
+ bdrv_get_cumulative_perm(to, &perm, &shared);
80
s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
38
+ bdrv_set_perm(to, perm, shared);
81
/* Fallback to read+write with allocated buffer */
39
82
} else {
40
out:
83
+ if (s->use_copy_range) {
41
g_slist_free(list);
84
+ /*
85
+ * Successful copy-range. Now increase copy_size. copy_range
86
+ * does not respect max_transfer (it's a TODO), so we factor
87
+ * that in here.
88
+ *
89
+ * Note: we double-check s->use_copy_range for the case when
90
+ * parallel block-copy request unsets it during previous
91
+ * bdrv_co_copy_range call.
92
+ */
93
+ s->copy_size =
94
+ MIN(MAX(s->cluster_size, BLOCK_COPY_MAX_COPY_RANGE),
95
+ QEMU_ALIGN_DOWN(block_copy_max_transfer(s->source,
96
+ s->target),
97
+ s->cluster_size));
98
+ }
99
goto out;
100
}
101
}
102
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
103
/*
104
* In case of failed copy_range request above, we may proceed with buffered
105
* request larger than BLOCK_COPY_MAX_BUFFER. Still, further requests will
106
- * be properly limited, so don't care too much.
107
+ * be properly limited, so don't care too much. Moreover the most likely
108
+ * case (copy_range is unsupported for the configuration, so the very first
109
+ * copy_range request fails) is handled by setting large copy_size only
110
+ * after first successful copy_range.
111
*/
112
113
bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
42
--
114
--
43
2.21.0
115
2.24.1
44
116
45
117
diff view generated by jsdifflib
1
From: Nir Soffer <nirsof@gmail.com>
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
2
3
When creating an image with preallocation "off" or "falloc", the first
3
Use bdrv_block_status_above to chose effective chunk size and to handle
4
block of the image is typically not allocated. When using Gluster
4
zeroes effectively.
5
storage backed by XFS filesystem, reading this block using direct I/O
6
succeeds regardless of request length, fooling alignment detection.
7
5
8
In this case we fallback to a safe value (4096) instead of the optimal
6
This substitutes checking for just being allocated or not, and drops
9
value (512), which may lead to unneeded data copying when aligning
7
old code path for it. Assistance by backup job is dropped too, as
10
requests. Allocating the first block avoids the fallback.
8
caching block-status information is more difficult than just caching
9
is-allocated information in our dirty bitmap, and backup job is not
10
good place for this caching anyway.
11
11
12
Since we allocate the first block even with preallocation=off, we no
12
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
longer create images with zero disk size:
13
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
14
15
$ ./qemu-img create -f raw test.raw 1g
16
Formatting 'test.raw', fmt=raw size=1073741824
17
18
$ ls -lhs test.raw
19
4.0K -rw-r--r--. 1 nsoffer nsoffer 1.0G Aug 16 23:48 test.raw
20
21
And converting the image requires additional cluster:
22
23
$ ./qemu-img measure -f raw -O qcow2 test.raw
24
required size: 458752
25
fully allocated size: 1074135040
26
27
When using format like vmdk with multiple files per image, we allocate
28
one block per file:
29
30
$ ./qemu-img create -f vmdk -o subformat=twoGbMaxExtentFlat test.vmdk 4g
31
Formatting 'test.vmdk', fmt=vmdk size=4294967296 compat6=off hwversion=undefined subformat=twoGbMaxExtentFlat
32
33
$ ls -lhs test*.vmdk
34
4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f001.vmdk
35
4.0K -rw-r--r--. 1 nsoffer nsoffer 2.0G Aug 27 03:23 test-f002.vmdk
36
4.0K -rw-r--r--. 1 nsoffer nsoffer 353 Aug 27 03:23 test.vmdk
37
38
I did quick performance test for copying disks with qemu-img convert to
39
new raw target image to Gluster storage with sector size of 512 bytes:
40
41
for i in $(seq 10); do
42
rm -f dst.raw
43
sleep 10
44
time ./qemu-img convert -f raw -O raw -t none -T none src.raw dst.raw
45
done
46
47
Here is a table comparing the total time spent:
48
49
Type Before(s) After(s) Diff(%)
50
---------------------------------------
51
real 530.028 469.123 -11.4
52
user 17.204 10.768 -37.4
53
sys 17.881 7.011 -60.7
54
55
We can see very clear improvement in CPU usage.
56
57
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
58
Message-id: 20190827010528.8818-2-nsoffer@redhat.com
59
Reviewed-by: Max Reitz <mreitz@redhat.com>
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Message-Id: <20200311103004.7649-5-vsementsov@virtuozzo.com>
60
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
61
---
17
---
62
block/file-posix.c | 51 +++++++++++++++++++
18
block/block-copy.c | 73 +++++++++++++++++++++++++++++++++++++---------
63
tests/qemu-iotests/059.out | 2 +-
19
block/trace-events | 1 +
64
tests/qemu-iotests/{150.out => 150.out.qcow2} | 0
20
2 files changed, 61 insertions(+), 13 deletions(-)
65
tests/qemu-iotests/150.out.raw | 12 +++++
66
tests/qemu-iotests/175 | 19 ++++---
67
tests/qemu-iotests/175.out | 8 +--
68
tests/qemu-iotests/178.out.qcow2 | 4 +-
69
tests/qemu-iotests/221.out | 12 +++--
70
tests/qemu-iotests/253.out | 12 +++--
71
9 files changed, 99 insertions(+), 21 deletions(-)
72
rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%)
73
create mode 100644 tests/qemu-iotests/150.out.raw
74
21
75
diff --git a/block/file-posix.c b/block/file-posix.c
22
diff --git a/block/block-copy.c b/block/block-copy.c
76
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
77
--- a/block/file-posix.c
24
--- a/block/block-copy.c
78
+++ b/block/file-posix.c
25
+++ b/block/block-copy.c
79
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
26
@@ -XXX,XX +XXX,XX @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
27
*/
28
static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
29
int64_t start, int64_t end,
30
- bool *error_is_read)
31
+ bool zeroes, bool *error_is_read)
32
{
33
int ret;
34
int nbytes = MIN(end, s->len) - start;
35
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
36
assert(QEMU_IS_ALIGNED(end, s->cluster_size));
37
assert(end < s->len || end == QEMU_ALIGN_UP(s->len, s->cluster_size));
38
39
+ if (zeroes) {
40
+ ret = bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_flags &
41
+ ~BDRV_REQ_WRITE_COMPRESSED);
42
+ if (ret < 0) {
43
+ trace_block_copy_write_zeroes_fail(s, start, ret);
44
+ if (error_is_read) {
45
+ *error_is_read = false;
46
+ }
47
+ }
48
+ return ret;
49
+ }
50
+
51
if (s->use_copy_range) {
52
ret = bdrv_co_copy_range(s->source, start, s->target, start, nbytes,
53
0, s->write_flags);
54
@@ -XXX,XX +XXX,XX @@ out:
80
return ret;
55
return ret;
81
}
56
}
82
57
83
+/*
58
+static int block_copy_block_status(BlockCopyState *s, int64_t offset,
84
+ * Help alignment probing by allocating the first block.
59
+ int64_t bytes, int64_t *pnum)
85
+ *
86
+ * When reading with direct I/O from unallocated area on Gluster backed by XFS,
87
+ * reading succeeds regardless of request length. In this case we fallback to
88
+ * safe alignment which is not optimal. Allocating the first block avoids this
89
+ * fallback.
90
+ *
91
+ * fd may be opened with O_DIRECT, but we don't know the buffer alignment or
92
+ * request alignment, so we use safe values.
93
+ *
94
+ * Returns: 0 on success, -errno on failure. Since this is an optimization,
95
+ * caller may ignore failures.
96
+ */
97
+static int allocate_first_block(int fd, size_t max_size)
98
+{
60
+{
99
+ size_t write_size = (max_size < MAX_BLOCKSIZE)
61
+ int64_t num;
100
+ ? BDRV_SECTOR_SIZE
62
+ BlockDriverState *base;
101
+ : MAX_BLOCKSIZE;
102
+ size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
103
+ void *buf;
104
+ ssize_t n;
105
+ int ret;
63
+ int ret;
106
+
64
+
107
+ buf = qemu_memalign(max_align, write_size);
65
+ if (s->skip_unallocated && s->source->bs->backing) {
108
+ memset(buf, 0, write_size);
66
+ base = s->source->bs->backing->bs;
67
+ } else {
68
+ base = NULL;
69
+ }
109
+
70
+
110
+ do {
71
+ ret = bdrv_block_status_above(s->source->bs, base, offset, bytes, &num,
111
+ n = pwrite(fd, buf, write_size, 0);
72
+ NULL, NULL);
112
+ } while (n == -1 && errno == EINTR);
73
+ if (ret < 0 || num < s->cluster_size) {
74
+ /*
75
+ * On error or if failed to obtain large enough chunk just fallback to
76
+ * copy one cluster.
77
+ */
78
+ num = s->cluster_size;
79
+ ret = BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_DATA;
80
+ } else if (offset + num == s->len) {
81
+ num = QEMU_ALIGN_UP(num, s->cluster_size);
82
+ } else {
83
+ num = QEMU_ALIGN_DOWN(num, s->cluster_size);
84
+ }
113
+
85
+
114
+ ret = (n == -1) ? -errno : 0;
86
+ *pnum = num;
115
+
116
+ qemu_vfree(buf);
117
+ return ret;
87
+ return ret;
118
+}
88
+}
119
+
89
+
120
static int handle_aiocb_truncate(void *opaque)
90
/*
91
* Check if the cluster starting at offset is allocated or not.
92
* return via pnum the number of contiguous clusters sharing this allocation.
93
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
121
{
94
{
122
RawPosixAIOData *aiocb = opaque;
95
int ret = 0;
123
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque)
96
int64_t end = bytes + start; /* bytes */
124
/* posix_fallocate() doesn't set errno. */
97
- int64_t status_bytes;
125
error_setg_errno(errp, -result,
98
BlockCopyInFlightReq req;
126
"Could not preallocate new data");
99
127
+ } else if (current_length == 0) {
100
/*
128
+ /*
101
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
129
+ * posix_fallocate() uses fallocate() if the filesystem
102
block_copy_inflight_req_begin(s, &req, start, end);
130
+ * supports it, or fallback to manually writing zeroes. If
103
131
+ * fallocate() was used, unaligned reads from the fallocated
104
while (start < end) {
132
+ * area in raw_probe_alignment() will succeed, hence we need to
105
- int64_t next_zero, chunk_end;
133
+ * allocate the first block.
106
+ int64_t next_zero, chunk_end, status_bytes;
134
+ *
107
135
+ * Optimize future alignment probing; ignore failures.
108
if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) {
136
+ */
109
trace_block_copy_skip(s, start);
137
+ allocate_first_block(fd, offset);
110
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
138
}
111
chunk_end = next_zero;
139
} else {
140
result = 0;
141
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque)
142
if (ftruncate(fd, offset) != 0) {
143
result = -errno;
144
error_setg_errno(errp, -result, "Could not resize file");
145
+ } else if (current_length == 0 && offset > current_length) {
146
+ /* Optimize future alignment probing; ignore failures. */
147
+ allocate_first_block(fd, offset);
148
}
112
}
149
return result;
113
150
default:
114
- if (s->skip_unallocated) {
151
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
115
- ret = block_copy_reset_unallocated(s, start, &status_bytes);
116
- if (ret == 0) {
117
- trace_block_copy_skip_range(s, start, status_bytes);
118
- start += status_bytes;
119
- continue;
120
- }
121
- /* Clamp to known allocated region */
122
- chunk_end = MIN(chunk_end, start + status_bytes);
123
+ ret = block_copy_block_status(s, start, chunk_end - start,
124
+ &status_bytes);
125
+ if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
126
+ bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes);
127
+ progress_set_remaining(s->progress,
128
+ bdrv_get_dirty_count(s->copy_bitmap) +
129
+ s->in_flight_bytes);
130
+ trace_block_copy_skip_range(s, start, status_bytes);
131
+ start += status_bytes;
132
+ continue;
133
}
134
135
+ chunk_end = MIN(chunk_end, start + status_bytes);
136
+
137
trace_block_copy_process(s, start);
138
139
bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
140
s->in_flight_bytes += chunk_end - start;
141
142
co_get_from_shres(s->mem, chunk_end - start);
143
- ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
144
+ ret = block_copy_do_copy(s, start, chunk_end, ret & BDRV_BLOCK_ZERO,
145
+ error_is_read);
146
co_put_to_shres(s->mem, chunk_end - start);
147
s->in_flight_bytes -= chunk_end - start;
148
if (ret < 0) {
149
diff --git a/block/trace-events b/block/trace-events
152
index XXXXXXX..XXXXXXX 100644
150
index XXXXXXX..XXXXXXX 100644
153
--- a/tests/qemu-iotests/059.out
151
--- a/block/trace-events
154
+++ b/tests/qemu-iotests/059.out
152
+++ b/block/trace-events
155
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax
153
@@ -XXX,XX +XXX,XX @@ block_copy_process(void *bcs, int64_t start) "bcs %p start %"PRId64
156
image: TEST_DIR/t.vmdk
154
block_copy_copy_range_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PRId64" ret %d"
157
file format: vmdk
155
block_copy_read_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PRId64" ret %d"
158
virtual size: 0.977 TiB (1073741824000 bytes)
156
block_copy_write_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PRId64" ret %d"
159
-disk size: 16 KiB
157
+block_copy_write_zeroes_fail(void *bcs, int64_t start, int ret) "bcs %p start %"PRId64" ret %d"
160
+disk size: 1.97 MiB
158
161
Format specific information:
159
# ../blockdev.c
162
cid: XXXXXXXX
160
qmp_block_job_cancel(void *job) "job %p"
163
parent cid: XXXXXXXX
164
diff --git a/tests/qemu-iotests/150.out b/tests/qemu-iotests/150.out.qcow2
165
similarity index 100%
166
rename from tests/qemu-iotests/150.out
167
rename to tests/qemu-iotests/150.out.qcow2
168
diff --git a/tests/qemu-iotests/150.out.raw b/tests/qemu-iotests/150.out.raw
169
new file mode 100644
170
index XXXXXXX..XXXXXXX
171
--- /dev/null
172
+++ b/tests/qemu-iotests/150.out.raw
173
@@ -XXX,XX +XXX,XX @@
174
+QA output created by 150
175
+
176
+=== Mapping sparse conversion ===
177
+
178
+Offset Length File
179
+0 0x1000 TEST_DIR/t.IMGFMT
180
+
181
+=== Mapping non-sparse conversion ===
182
+
183
+Offset Length File
184
+0 0x100000 TEST_DIR/t.IMGFMT
185
+*** done
186
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
187
index XXXXXXX..XXXXXXX 100755
188
--- a/tests/qemu-iotests/175
189
+++ b/tests/qemu-iotests/175
190
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
191
# the file size. This function hides the resulting difference in the
192
# stat -c '%b' output.
193
# Parameter 1: Number of blocks an empty file occupies
194
-# Parameter 2: Image size in bytes
195
+# Parameter 2: Minimal number of blocks in an image
196
+# Parameter 3: Image size in bytes
197
_filter_blocks()
198
{
199
extra_blocks=$1
200
- img_size=$2
201
+ min_blocks=$2
202
+ img_size=$3
203
204
- sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \
205
- -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/"
206
+ sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \
207
+ -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
208
}
209
210
# get standard environment, filters and checks
211
@@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024))
212
touch "$TEST_DIR/empty"
213
extra_blocks=$(stat -c '%b' "$TEST_DIR/empty")
214
215
+# We always write the first byte; check how many blocks this filesystem
216
+# allocates to match empty image alloation.
217
+printf "\0" > "$TEST_DIR/empty"
218
+min_blocks=$(stat -c '%b' "$TEST_DIR/empty")
219
+
220
echo
221
echo "== creating image with default preallocation =="
222
_make_test_img $size | _filter_imgfmt
223
-stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
224
+stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
225
226
for mode in off full falloc; do
227
echo
228
echo "== creating image with preallocation $mode =="
229
IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt
230
- stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
231
+ stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
232
done
233
234
# success, all done
235
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
236
index XXXXXXX..XXXXXXX 100644
237
--- a/tests/qemu-iotests/175.out
238
+++ b/tests/qemu-iotests/175.out
239
@@ -XXX,XX +XXX,XX @@ QA output created by 175
240
241
== creating image with default preallocation ==
242
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
243
-size=1048576, nothing allocated
244
+size=1048576, min allocation
245
246
== creating image with preallocation off ==
247
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off
248
-size=1048576, nothing allocated
249
+size=1048576, min allocation
250
251
== creating image with preallocation full ==
252
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full
253
-size=1048576, everything allocated
254
+size=1048576, max allocation
255
256
== creating image with preallocation falloc ==
257
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
258
-size=1048576, everything allocated
259
+size=1048576, max allocation
260
*** done
261
diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2
262
index XXXXXXX..XXXXXXX 100644
263
--- a/tests/qemu-iotests/178.out.qcow2
264
+++ b/tests/qemu-iotests/178.out.qcow2
265
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
266
== raw input image with data (human) ==
267
268
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
269
-required size: 393216
270
+required size: 458752
271
fully allocated size: 1074135040
272
wrote 512/512 bytes at offset 512
273
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
274
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
275
276
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
277
{
278
- "required": 393216,
279
+ "required": 458752,
280
"fully-allocated": 1074135040
281
}
282
wrote 512/512 bytes at offset 512
283
diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out
284
index XXXXXXX..XXXXXXX 100644
285
--- a/tests/qemu-iotests/221.out
286
+++ b/tests/qemu-iotests/221.out
287
@@ -XXX,XX +XXX,XX @@ QA output created by 221
288
=== Check mapping of unaligned raw image ===
289
290
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537
291
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
292
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
293
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
294
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
295
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
296
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
297
wrote 1/1 bytes at offset 65536
298
1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
299
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
300
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
301
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
302
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
303
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
304
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
305
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
306
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
307
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
308
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
309
*** done
310
diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out
311
index XXXXXXX..XXXXXXX 100644
312
--- a/tests/qemu-iotests/253.out
313
+++ b/tests/qemu-iotests/253.out
314
@@ -XXX,XX +XXX,XX @@ QA output created by 253
315
=== Check mapping of unaligned raw image ===
316
317
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575
318
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
319
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
320
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
321
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
322
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
323
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
324
wrote 65535/65535 bytes at offset 983040
325
63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
326
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
327
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
328
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
329
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
330
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
331
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
332
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
333
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
334
*** done
335
--
161
--
336
2.21.0
162
2.24.1
337
163
338
164
diff view generated by jsdifflib
1
fe646693acc changed qemu-img create's output so that it no longer prints
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
single quotes around parameter values. The subformat and adapter_type
3
filters in _filter_img_create() have never been adapted to that change.
4
2
5
Fixes: fe646693acc13ac48b98435d14149ab04dc597bc
3
Split find_conflicting_inflight_req to be used separately.
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
7
Reviewed-by: John Snow <jsnow@redhat.com>
5
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Message-id: 20190815153638.4600-2-mreitz@redhat.com
6
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
9
Reviewed-by: John Snow <jsnow@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Message-Id: <20200311103004.7649-6-vsementsov@virtuozzo.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
10
---
12
tests/qemu-iotests/059.out | 16 ++++++++--------
11
block/block-copy.c | 31 +++++++++++++++++++------------
13
tests/qemu-iotests/common.filter | 4 ++--
12
1 file changed, 19 insertions(+), 12 deletions(-)
14
2 files changed, 10 insertions(+), 10 deletions(-)
15
13
16
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
14
diff --git a/block/block-copy.c b/block/block-copy.c
17
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/qemu-iotests/059.out
16
--- a/block/block-copy.c
19
+++ b/tests/qemu-iotests/059.out
17
+++ b/block/block-copy.c
20
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
18
@@ -XXX,XX +XXX,XX @@
21
qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big
19
#define BLOCK_COPY_MAX_BUFFER (1 * MiB)
22
20
#define BLOCK_COPY_MAX_MEM (128 * MiB)
23
=== Testing monolithicFlat creation and opening ===
21
24
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
22
+static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
25
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
23
+ int64_t start,
26
image: TEST_DIR/t.IMGFMT
24
+ int64_t end)
27
file format: IMGFMT
25
+{
28
virtual size: 2 GiB (2147483648 bytes)
26
+ BlockCopyInFlightReq *req;
29
27
+
30
=== Testing monolithicFlat with zeroed_grain ===
28
+ QLIST_FOREACH(req, &s->inflight_reqs, list) {
31
qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain
29
+ if (end > req->start_byte && start < req->end_byte) {
32
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
30
+ return req;
33
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
31
+ }
34
32
+ }
35
=== Testing big twoGbMaxExtentFlat ===
33
+
36
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat
34
+ return NULL;
37
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000
35
+}
38
image: TEST_DIR/t.vmdk
36
+
39
file format: vmdk
37
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
40
virtual size: 0.977 TiB (1073741824000 bytes)
38
int64_t start,
41
@@ -XXX,XX +XXX,XX @@ Format specific information:
39
int64_t end)
42
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1
40
{
43
41
BlockCopyInFlightReq *req;
44
=== Testing truncated sparse ===
42
- bool waited;
45
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse
43
-
46
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
44
- do {
47
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes
45
- waited = false;
48
46
- QLIST_FOREACH(req, &s->inflight_reqs, list) {
49
=== Converting to streamOptimized from image with small cluster size===
47
- if (end > req->start_byte && start < req->end_byte) {
50
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
48
- qemu_co_queue_wait(&req->wait_queue, NULL);
51
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
49
- waited = true;
52
50
- break;
53
=== Testing monolithicFlat with internally generated JSON file name ===
51
- }
54
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat
52
- }
55
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
53
- } while (waited);
56
qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}'
54
+
57
55
+ while ((req = find_conflicting_inflight_req(s, start, end))) {
58
=== Testing version 3 ===
56
+ qemu_co_queue_wait(&req->wait_queue, NULL);
59
@@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328
57
+ }
60
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
58
}
61
59
62
=== Testing 4TB monolithicFlat creation and IO ===
60
static void block_copy_inflight_req_begin(BlockCopyState *s,
63
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104 subformat=monolithicFlat
64
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4398046511104
65
image: TEST_DIR/t.IMGFMT
66
file format: IMGFMT
67
virtual size: 4 TiB (4398046511104 bytes)
68
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 966367641600
69
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
70
71
=== Testing qemu-img map on extents ===
72
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=monolithicSparse
73
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544
74
wrote 1024/1024 bytes at offset 65024
75
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
76
wrote 1024/1024 bytes at offset 2147483136
77
@@ -XXX,XX +XXX,XX @@ Offset Length Mapped to File
78
0 0x20000 0x3f0000 TEST_DIR/t.vmdk
79
0x7fff0000 0x20000 0x410000 TEST_DIR/t.vmdk
80
0x140000000 0x10000 0x430000 TEST_DIR/t.vmdk
81
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544 subformat=twoGbMaxExtentSparse
82
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33285996544
83
wrote 1024/1024 bytes at offset 65024
84
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
85
wrote 1024/1024 bytes at offset 2147483136
86
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
87
index XXXXXXX..XXXXXXX 100644
88
--- a/tests/qemu-iotests/common.filter
89
+++ b/tests/qemu-iotests/common.filter
90
@@ -XXX,XX +XXX,XX @@ _filter_img_create()
91
-e "s# compat6=\\(on\\|off\\)##g" \
92
-e "s# static=\\(on\\|off\\)##g" \
93
-e "s# zeroed_grain=\\(on\\|off\\)##g" \
94
- -e "s# subformat='[^']*'##g" \
95
- -e "s# adapter_type='[^']*'##g" \
96
+ -e "s# subformat=[^ ]*##g" \
97
+ -e "s# adapter_type=[^ ]*##g" \
98
-e "s# hwversion=[^ ]*##g" \
99
-e "s# lazy_refcounts=\\(on\\|off\\)##g" \
100
-e "s# block_size=[0-9]\\+##g" \
101
--
61
--
102
2.21.0
62
2.24.1
103
63
104
64
diff view generated by jsdifflib
New patch
1
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
3
We have a lot of "chunk_end - start" invocations, let's switch to
4
bytes/cur_bytes scheme instead.
5
6
While being here, improve check on block_copy_do_copy parameters to not
7
overflow when calculating nbytes and use int64_t for bytes in
8
block_copy for consistency.
9
10
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Message-Id: <20200311103004.7649-7-vsementsov@virtuozzo.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
16
block/block-copy.c | 78 ++++++++++++++++++++------------------
17
include/block/block-copy.h | 6 +--
18
2 files changed, 44 insertions(+), 40 deletions(-)
19
20
diff --git a/block/block-copy.c b/block/block-copy.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/block-copy.c
23
+++ b/block/block-copy.c
24
@@ -XXX,XX +XXX,XX @@
25
26
static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
27
int64_t start,
28
- int64_t end)
29
+ int64_t bytes)
30
{
31
BlockCopyInFlightReq *req;
32
33
QLIST_FOREACH(req, &s->inflight_reqs, list) {
34
- if (end > req->start_byte && start < req->end_byte) {
35
+ if (start + bytes > req->start && start < req->start + req->bytes) {
36
return req;
37
}
38
}
39
@@ -XXX,XX +XXX,XX @@ static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
40
41
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
42
int64_t start,
43
- int64_t end)
44
+ int64_t bytes)
45
{
46
BlockCopyInFlightReq *req;
47
48
- while ((req = find_conflicting_inflight_req(s, start, end))) {
49
+ while ((req = find_conflicting_inflight_req(s, start, bytes))) {
50
qemu_co_queue_wait(&req->wait_queue, NULL);
51
}
52
}
53
54
static void block_copy_inflight_req_begin(BlockCopyState *s,
55
BlockCopyInFlightReq *req,
56
- int64_t start, int64_t end)
57
+ int64_t start, int64_t bytes)
58
{
59
- req->start_byte = start;
60
- req->end_byte = end;
61
+ req->start = start;
62
+ req->bytes = bytes;
63
qemu_co_queue_init(&req->wait_queue);
64
QLIST_INSERT_HEAD(&s->inflight_reqs, req, list);
65
}
66
@@ -XXX,XX +XXX,XX @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
67
/*
68
* block_copy_do_copy
69
*
70
- * Do copy of cluser-aligned chunk. @end is allowed to exceed s->len only to
71
- * cover last cluster when s->len is not aligned to clusters.
72
+ * Do copy of cluster-aligned chunk. Requested region is allowed to exceed
73
+ * s->len only to cover last cluster when s->len is not aligned to clusters.
74
*
75
* No sync here: nor bitmap neighter intersecting requests handling, only copy.
76
*
77
* Returns 0 on success.
78
*/
79
static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
80
- int64_t start, int64_t end,
81
+ int64_t start, int64_t bytes,
82
bool zeroes, bool *error_is_read)
83
{
84
int ret;
85
- int nbytes = MIN(end, s->len) - start;
86
+ int64_t nbytes = MIN(start + bytes, s->len) - start;
87
void *bounce_buffer = NULL;
88
89
+ assert(start >= 0 && bytes > 0 && INT64_MAX - start >= bytes);
90
assert(QEMU_IS_ALIGNED(start, s->cluster_size));
91
- assert(QEMU_IS_ALIGNED(end, s->cluster_size));
92
- assert(end < s->len || end == QEMU_ALIGN_UP(s->len, s->cluster_size));
93
+ assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
94
+ assert(start < s->len);
95
+ assert(start + bytes <= s->len ||
96
+ start + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
97
+ assert(nbytes < INT_MAX);
98
99
if (zeroes) {
100
ret = bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_flags &
101
@@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
102
}
103
104
int coroutine_fn block_copy(BlockCopyState *s,
105
- int64_t start, uint64_t bytes,
106
+ int64_t start, int64_t bytes,
107
bool *error_is_read)
108
{
109
int ret = 0;
110
- int64_t end = bytes + start; /* bytes */
111
BlockCopyInFlightReq req;
112
113
/*
114
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
115
bdrv_get_aio_context(s->target->bs));
116
117
assert(QEMU_IS_ALIGNED(start, s->cluster_size));
118
- assert(QEMU_IS_ALIGNED(end, s->cluster_size));
119
+ assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
120
121
block_copy_wait_inflight_reqs(s, start, bytes);
122
- block_copy_inflight_req_begin(s, &req, start, end);
123
+ block_copy_inflight_req_begin(s, &req, start, bytes);
124
125
- while (start < end) {
126
- int64_t next_zero, chunk_end, status_bytes;
127
+ while (bytes) {
128
+ int64_t next_zero, cur_bytes, status_bytes;
129
130
if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) {
131
trace_block_copy_skip(s, start);
132
start += s->cluster_size;
133
+ bytes -= s->cluster_size;
134
continue; /* already copied */
135
}
136
137
- chunk_end = MIN(end, start + s->copy_size);
138
+ cur_bytes = MIN(bytes, s->copy_size);
139
140
next_zero = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start,
141
- chunk_end - start);
142
+ cur_bytes);
143
if (next_zero >= 0) {
144
assert(next_zero > start); /* start is dirty */
145
- assert(next_zero < chunk_end); /* no need to do MIN() */
146
- chunk_end = next_zero;
147
+ assert(next_zero < start + cur_bytes); /* no need to do MIN() */
148
+ cur_bytes = next_zero - start;
149
}
150
151
- ret = block_copy_block_status(s, start, chunk_end - start,
152
- &status_bytes);
153
+ ret = block_copy_block_status(s, start, cur_bytes, &status_bytes);
154
if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
155
bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes);
156
progress_set_remaining(s->progress,
157
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
158
s->in_flight_bytes);
159
trace_block_copy_skip_range(s, start, status_bytes);
160
start += status_bytes;
161
+ bytes -= status_bytes;
162
continue;
163
}
164
165
- chunk_end = MIN(chunk_end, start + status_bytes);
166
+ cur_bytes = MIN(cur_bytes, status_bytes);
167
168
trace_block_copy_process(s, start);
169
170
- bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
171
- s->in_flight_bytes += chunk_end - start;
172
+ bdrv_reset_dirty_bitmap(s->copy_bitmap, start, cur_bytes);
173
+ s->in_flight_bytes += cur_bytes;
174
175
- co_get_from_shres(s->mem, chunk_end - start);
176
- ret = block_copy_do_copy(s, start, chunk_end, ret & BDRV_BLOCK_ZERO,
177
+ co_get_from_shres(s->mem, cur_bytes);
178
+ ret = block_copy_do_copy(s, start, cur_bytes, ret & BDRV_BLOCK_ZERO,
179
error_is_read);
180
- co_put_to_shres(s->mem, chunk_end - start);
181
- s->in_flight_bytes -= chunk_end - start;
182
+ co_put_to_shres(s->mem, cur_bytes);
183
+ s->in_flight_bytes -= cur_bytes;
184
if (ret < 0) {
185
- bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
186
+ bdrv_set_dirty_bitmap(s->copy_bitmap, start, cur_bytes);
187
break;
188
}
189
190
- progress_work_done(s->progress, chunk_end - start);
191
- s->progress_bytes_callback(chunk_end - start, s->progress_opaque);
192
- start = chunk_end;
193
- ret = 0;
194
+ progress_work_done(s->progress, cur_bytes);
195
+ s->progress_bytes_callback(cur_bytes, s->progress_opaque);
196
+ start += cur_bytes;
197
+ bytes -= cur_bytes;
198
}
199
200
block_copy_inflight_req_end(&req);
201
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
202
index XXXXXXX..XXXXXXX 100644
203
--- a/include/block/block-copy.h
204
+++ b/include/block/block-copy.h
205
@@ -XXX,XX +XXX,XX @@
206
#include "qemu/co-shared-resource.h"
207
208
typedef struct BlockCopyInFlightReq {
209
- int64_t start_byte;
210
- int64_t end_byte;
211
+ int64_t start;
212
+ int64_t bytes;
213
QLIST_ENTRY(BlockCopyInFlightReq) list;
214
CoQueue wait_queue; /* coroutines blocked on this request */
215
} BlockCopyInFlightReq;
216
@@ -XXX,XX +XXX,XX @@ void block_copy_state_free(BlockCopyState *s);
217
int64_t block_copy_reset_unallocated(BlockCopyState *s,
218
int64_t offset, int64_t *count);
219
220
-int coroutine_fn block_copy(BlockCopyState *s, int64_t start, uint64_t bytes,
221
+int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
222
bool *error_is_read);
223
224
#endif /* BLOCK_COPY_H */
225
--
226
2.24.1
227
228
diff view generated by jsdifflib
1
This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
turns a former error in 059 into success.
2
3
3
offset/bytes pair is more usual naming in block layer, let's use it.
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
5
Message-id: 20190815153638.4600-3-mreitz@redhat.com
5
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Reviewed-by: John Snow <jsnow@redhat.com>
6
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Message-Id: <20200311103004.7649-8-vsementsov@virtuozzo.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
---
10
---
9
block/vmdk.c | 54 ++++++++++++++++++++++++--------------
11
block/block-copy.c | 82 +++++++++++++++++++-------------------
10
tests/qemu-iotests/059 | 7 +++--
12
include/block/block-copy.h | 4 +-
11
tests/qemu-iotests/059.out | 4 ++-
13
2 files changed, 43 insertions(+), 43 deletions(-)
12
3 files changed, 42 insertions(+), 23 deletions(-)
14
13
15
diff --git a/block/block-copy.c b/block/block-copy.c
14
diff --git a/block/vmdk.c b/block/vmdk.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/block/vmdk.c
17
--- a/block/block-copy.c
17
+++ b/block/vmdk.c
18
+++ b/block/block-copy.c
18
@@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s)
19
@@ -XXX,XX +XXX,XX @@
20
#define BLOCK_COPY_MAX_MEM (128 * MiB)
21
22
static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
23
- int64_t start,
24
+ int64_t offset,
25
int64_t bytes)
26
{
27
BlockCopyInFlightReq *req;
28
29
QLIST_FOREACH(req, &s->inflight_reqs, list) {
30
- if (start + bytes > req->start && start < req->start + req->bytes) {
31
+ if (offset + bytes > req->offset && offset < req->offset + req->bytes) {
32
return req;
33
}
34
}
35
@@ -XXX,XX +XXX,XX @@ static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
19
}
36
}
20
37
21
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
38
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
22
- const char *desc_file_path, QDict *options,
39
- int64_t start,
23
- Error **errp)
40
+ int64_t offset,
24
+ QDict *options, Error **errp)
41
int64_t bytes)
42
{
43
BlockCopyInFlightReq *req;
44
45
- while ((req = find_conflicting_inflight_req(s, start, bytes))) {
46
+ while ((req = find_conflicting_inflight_req(s, offset, bytes))) {
47
qemu_co_queue_wait(&req->wait_queue, NULL);
48
}
49
}
50
51
static void block_copy_inflight_req_begin(BlockCopyState *s,
52
BlockCopyInFlightReq *req,
53
- int64_t start, int64_t bytes)
54
+ int64_t offset, int64_t bytes)
55
{
56
- req->start = start;
57
+ req->offset = offset;
58
req->bytes = bytes;
59
qemu_co_queue_init(&req->wait_queue);
60
QLIST_INSERT_HEAD(&s->inflight_reqs, req, list);
61
@@ -XXX,XX +XXX,XX @@ void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
62
* Returns 0 on success.
63
*/
64
static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
65
- int64_t start, int64_t bytes,
66
+ int64_t offset, int64_t bytes,
67
bool zeroes, bool *error_is_read)
25
{
68
{
26
int ret;
69
int ret;
27
int matches;
70
- int64_t nbytes = MIN(start + bytes, s->len) - start;
28
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
71
+ int64_t nbytes = MIN(offset + bytes, s->len) - offset;
29
const char *p, *np;
72
void *bounce_buffer = NULL;
30
int64_t sectors = 0;
73
31
int64_t flat_offset;
74
- assert(start >= 0 && bytes > 0 && INT64_MAX - start >= bytes);
32
+ char *desc_file_dir = NULL;
75
- assert(QEMU_IS_ALIGNED(start, s->cluster_size));
33
char *extent_path;
76
+ assert(offset >= 0 && bytes > 0 && INT64_MAX - offset >= bytes);
34
BdrvChild *extent_file;
77
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
35
BDRVVmdkState *s = bs->opaque;
78
assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
36
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
79
- assert(start < s->len);
80
- assert(start + bytes <= s->len ||
81
- start + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
82
+ assert(offset < s->len);
83
+ assert(offset + bytes <= s->len ||
84
+ offset + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
85
assert(nbytes < INT_MAX);
86
87
if (zeroes) {
88
- ret = bdrv_co_pwrite_zeroes(s->target, start, nbytes, s->write_flags &
89
+ ret = bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_flags &
90
~BDRV_REQ_WRITE_COMPRESSED);
91
if (ret < 0) {
92
- trace_block_copy_write_zeroes_fail(s, start, ret);
93
+ trace_block_copy_write_zeroes_fail(s, offset, ret);
94
if (error_is_read) {
95
*error_is_read = false;
96
}
97
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
98
}
99
100
if (s->use_copy_range) {
101
- ret = bdrv_co_copy_range(s->source, start, s->target, start, nbytes,
102
+ ret = bdrv_co_copy_range(s->source, offset, s->target, offset, nbytes,
103
0, s->write_flags);
104
if (ret < 0) {
105
- trace_block_copy_copy_range_fail(s, start, ret);
106
+ trace_block_copy_copy_range_fail(s, offset, ret);
107
s->use_copy_range = false;
108
s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
109
/* Fallback to read+write with allocated buffer */
110
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
111
112
bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
113
114
- ret = bdrv_co_pread(s->source, start, nbytes, bounce_buffer, 0);
115
+ ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0);
116
if (ret < 0) {
117
- trace_block_copy_read_fail(s, start, ret);
118
+ trace_block_copy_read_fail(s, offset, ret);
119
if (error_is_read) {
120
*error_is_read = true;
121
}
122
goto out;
123
}
124
125
- ret = bdrv_co_pwrite(s->target, start, nbytes, bounce_buffer,
126
+ ret = bdrv_co_pwrite(s->target, offset, nbytes, bounce_buffer,
127
s->write_flags);
128
if (ret < 0) {
129
- trace_block_copy_write_fail(s, start, ret);
130
+ trace_block_copy_write_fail(s, offset, ret);
131
if (error_is_read) {
132
*error_is_read = false;
133
}
134
@@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
135
}
136
137
int coroutine_fn block_copy(BlockCopyState *s,
138
- int64_t start, int64_t bytes,
139
+ int64_t offset, int64_t bytes,
140
bool *error_is_read)
141
{
142
int ret = 0;
143
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
144
assert(bdrv_get_aio_context(s->source->bs) ==
145
bdrv_get_aio_context(s->target->bs));
146
147
- assert(QEMU_IS_ALIGNED(start, s->cluster_size));
148
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
149
assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
150
151
- block_copy_wait_inflight_reqs(s, start, bytes);
152
- block_copy_inflight_req_begin(s, &req, start, bytes);
153
+ block_copy_wait_inflight_reqs(s, offset, bytes);
154
+ block_copy_inflight_req_begin(s, &req, offset, bytes);
155
156
while (bytes) {
157
int64_t next_zero, cur_bytes, status_bytes;
158
159
- if (!bdrv_dirty_bitmap_get(s->copy_bitmap, start)) {
160
- trace_block_copy_skip(s, start);
161
- start += s->cluster_size;
162
+ if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) {
163
+ trace_block_copy_skip(s, offset);
164
+ offset += s->cluster_size;
165
bytes -= s->cluster_size;
166
continue; /* already copied */
167
}
168
169
cur_bytes = MIN(bytes, s->copy_size);
170
171
- next_zero = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, start,
172
+ next_zero = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset,
173
cur_bytes);
174
if (next_zero >= 0) {
175
- assert(next_zero > start); /* start is dirty */
176
- assert(next_zero < start + cur_bytes); /* no need to do MIN() */
177
- cur_bytes = next_zero - start;
178
+ assert(next_zero > offset); /* offset is dirty */
179
+ assert(next_zero < offset + cur_bytes); /* no need to do MIN() */
180
+ cur_bytes = next_zero - offset;
181
}
182
183
- ret = block_copy_block_status(s, start, cur_bytes, &status_bytes);
184
+ ret = block_copy_block_status(s, offset, cur_bytes, &status_bytes);
185
if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
186
- bdrv_reset_dirty_bitmap(s->copy_bitmap, start, status_bytes);
187
+ bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, status_bytes);
188
progress_set_remaining(s->progress,
189
bdrv_get_dirty_count(s->copy_bitmap) +
190
s->in_flight_bytes);
191
- trace_block_copy_skip_range(s, start, status_bytes);
192
- start += status_bytes;
193
+ trace_block_copy_skip_range(s, offset, status_bytes);
194
+ offset += status_bytes;
195
bytes -= status_bytes;
37
continue;
196
continue;
38
}
197
}
39
198
40
- if (!path_is_absolute(fname) && !path_has_protocol(fname) &&
199
cur_bytes = MIN(cur_bytes, status_bytes);
41
- !desc_file_path[0])
200
42
- {
201
- trace_block_copy_process(s, start);
43
- bdrv_refresh_filename(bs->file->bs);
202
+ trace_block_copy_process(s, offset);
44
- error_setg(errp, "Cannot use relative extent paths with VMDK "
203
45
- "descriptor file '%s'", bs->file->bs->filename);
204
- bdrv_reset_dirty_bitmap(s->copy_bitmap, start, cur_bytes);
46
- return -EINVAL;
205
+ bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, cur_bytes);
47
- }
206
s->in_flight_bytes += cur_bytes;
48
+ if (path_is_absolute(fname)) {
207
49
+ extent_path = g_strdup(fname);
208
co_get_from_shres(s->mem, cur_bytes);
50
+ } else {
209
- ret = block_copy_do_copy(s, start, cur_bytes, ret & BDRV_BLOCK_ZERO,
51
+ if (!desc_file_dir) {
210
+ ret = block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_ZERO,
52
+ desc_file_dir = bdrv_dirname(bs->file->bs, errp);
211
error_is_read);
53
+ if (!desc_file_dir) {
212
co_put_to_shres(s->mem, cur_bytes);
54
+ bdrv_refresh_filename(bs->file->bs);
213
s->in_flight_bytes -= cur_bytes;
55
+ error_prepend(errp, "Cannot use relative paths with VMDK "
214
if (ret < 0) {
56
+ "descriptor file '%s': ",
215
- bdrv_set_dirty_bitmap(s->copy_bitmap, start, cur_bytes);
57
+ bs->file->bs->filename);
216
+ bdrv_set_dirty_bitmap(s->copy_bitmap, offset, cur_bytes);
58
+ ret = -EINVAL;
217
break;
59
+ goto out;
218
}
60
+ }
219
61
+ }
220
progress_work_done(s->progress, cur_bytes);
62
221
s->progress_bytes_callback(cur_bytes, s->progress_opaque);
63
- extent_path = path_combine(desc_file_path, fname);
222
- start += cur_bytes;
64
+ extent_path = g_strconcat(desc_file_dir, fname, NULL);
223
+ offset += cur_bytes;
65
+ }
224
bytes -= cur_bytes;
66
225
}
67
ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
226
68
assert(ret < 32);
227
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
69
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
70
g_free(extent_path);
71
if (local_err) {
72
error_propagate(errp, local_err);
73
- return -EINVAL;
74
+ ret = -EINVAL;
75
+ goto out;
76
}
77
78
/* save to extents array */
79
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
80
0, 0, 0, 0, 0, &extent, errp);
81
if (ret < 0) {
82
bdrv_unref_child(bs, extent_file);
83
- return ret;
84
+ goto out;
85
}
86
extent->flat_start_offset = flat_offset << 9;
87
} else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {
88
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
89
g_free(buf);
90
if (ret) {
91
bdrv_unref_child(bs, extent_file);
92
- return ret;
93
+ goto out;
94
}
95
extent = &s->extents[s->num_extents - 1];
96
} else if (!strcmp(type, "SESPARSE")) {
97
ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp);
98
if (ret) {
99
bdrv_unref_child(bs, extent_file);
100
- return ret;
101
+ goto out;
102
}
103
extent = &s->extents[s->num_extents - 1];
104
} else {
105
error_setg(errp, "Unsupported extent type '%s'", type);
106
bdrv_unref_child(bs, extent_file);
107
- return -ENOTSUP;
108
+ ret = -ENOTSUP;
109
+ goto out;
110
}
111
extent->type = g_strdup(type);
112
}
113
- return 0;
114
+
115
+ ret = 0;
116
+ goto out;
117
118
invalid:
119
np = next_line(p);
120
@@ -XXX,XX +XXX,XX @@ invalid:
121
np--;
122
}
123
error_setg(errp, "Invalid extent line: %.*s", (int)(np - p), p);
124
- return -EINVAL;
125
+ ret = -EINVAL;
126
+
127
+out:
128
+ g_free(desc_file_dir);
129
+ return ret;
130
}
131
132
static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
133
@@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
134
}
135
s->create_type = g_strdup(ct);
136
s->desc_offset = 0;
137
- ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options,
138
- errp);
139
+ ret = vmdk_parse_extents(buf, bs, options, errp);
140
exit:
141
return ret;
142
}
143
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
144
index XXXXXXX..XXXXXXX 100755
145
--- a/tests/qemu-iotests/059
146
+++ b/tests/qemu-iotests/059
147
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
148
149
echo
150
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
151
+# Should work, because bdrv_dirname() works fine with blkdebug
152
IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
153
-$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" 2>&1 \
154
- | _filter_testdir | _filter_imgfmt
155
+$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
156
+ -c info \
157
+ 2>&1 \
158
+ | _filter_testdir | _filter_imgfmt | _filter_img_info
159
_cleanup_test_img
160
161
echo
162
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
163
index XXXXXXX..XXXXXXX 100644
228
index XXXXXXX..XXXXXXX 100644
164
--- a/tests/qemu-iotests/059.out
229
--- a/include/block/block-copy.h
165
+++ b/tests/qemu-iotests/059.out
230
+++ b/include/block/block-copy.h
166
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
231
@@ -XXX,XX +XXX,XX @@
167
232
#include "qemu/co-shared-resource.h"
168
=== Testing monolithicFlat with internally generated JSON file name ===
233
169
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
234
typedef struct BlockCopyInFlightReq {
170
-qemu-io: can't open: Cannot use relative extent paths with VMDK descriptor file 'json:{"image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "blkdebug", "inject-error.0.event": "read_aio"}'
235
- int64_t start;
171
+format name: IMGFMT
236
+ int64_t offset;
172
+cluster size: 0 bytes
237
int64_t bytes;
173
+vm state offset: 0 bytes
238
QLIST_ENTRY(BlockCopyInFlightReq) list;
174
239
CoQueue wait_queue; /* coroutines blocked on this request */
175
=== Testing version 3 ===
240
@@ -XXX,XX +XXX,XX @@ void block_copy_state_free(BlockCopyState *s);
176
image: TEST_DIR/iotest-version3.IMGFMT
241
int64_t block_copy_reset_unallocated(BlockCopyState *s,
242
int64_t offset, int64_t *count);
243
244
-int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
245
+int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
246
bool *error_is_read);
247
248
#endif /* BLOCK_COPY_H */
177
--
249
--
178
2.21.0
250
2.24.1
179
251
180
252
diff view generated by jsdifflib
New patch
1
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
3
Currently, block_copy operation lock the whole requested region. But
4
there is no reason to lock clusters, which are already copied, it will
5
disturb other parallel block_copy requests for no reason.
6
7
Let's instead do the following:
8
9
Lock only sub-region, which we are going to operate on. Then, after
10
copying all dirty sub-regions, we should wait for intersecting
11
requests block-copy, if they failed, we should retry these new dirty
12
clusters.
13
14
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
15
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
16
Message-Id: <20200311103004.7649-9-vsementsov@virtuozzo.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/block-copy.c | 129 ++++++++++++++++++++++++++++++++++++---------
20
1 file changed, 105 insertions(+), 24 deletions(-)
21
22
diff --git a/block/block-copy.c b/block/block-copy.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/block-copy.c
25
+++ b/block/block-copy.c
26
@@ -XXX,XX +XXX,XX @@ static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
27
return NULL;
28
}
29
30
-static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
31
- int64_t offset,
32
- int64_t bytes)
33
+/*
34
+ * If there are no intersecting requests return false. Otherwise, wait for the
35
+ * first found intersecting request to finish and return true.
36
+ */
37
+static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t offset,
38
+ int64_t bytes)
39
{
40
- BlockCopyInFlightReq *req;
41
+ BlockCopyInFlightReq *req = find_conflicting_inflight_req(s, offset, bytes);
42
43
- while ((req = find_conflicting_inflight_req(s, offset, bytes))) {
44
- qemu_co_queue_wait(&req->wait_queue, NULL);
45
+ if (!req) {
46
+ return false;
47
}
48
+
49
+ qemu_co_queue_wait(&req->wait_queue, NULL);
50
+
51
+ return true;
52
}
53
54
+/* Called only on full-dirty region */
55
static void block_copy_inflight_req_begin(BlockCopyState *s,
56
BlockCopyInFlightReq *req,
57
int64_t offset, int64_t bytes)
58
{
59
+ assert(!find_conflicting_inflight_req(s, offset, bytes));
60
+
61
+ bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
62
+ s->in_flight_bytes += bytes;
63
+
64
req->offset = offset;
65
req->bytes = bytes;
66
qemu_co_queue_init(&req->wait_queue);
67
QLIST_INSERT_HEAD(&s->inflight_reqs, req, list);
68
}
69
70
-static void coroutine_fn block_copy_inflight_req_end(BlockCopyInFlightReq *req)
71
+/*
72
+ * block_copy_inflight_req_shrink
73
+ *
74
+ * Drop the tail of the request to be handled later. Set dirty bits back and
75
+ * wake up all requests waiting for us (may be some of them are not intersecting
76
+ * with shrunk request)
77
+ */
78
+static void coroutine_fn block_copy_inflight_req_shrink(BlockCopyState *s,
79
+ BlockCopyInFlightReq *req, int64_t new_bytes)
80
{
81
+ if (new_bytes == req->bytes) {
82
+ return;
83
+ }
84
+
85
+ assert(new_bytes > 0 && new_bytes < req->bytes);
86
+
87
+ s->in_flight_bytes -= req->bytes - new_bytes;
88
+ bdrv_set_dirty_bitmap(s->copy_bitmap,
89
+ req->offset + new_bytes, req->bytes - new_bytes);
90
+
91
+ req->bytes = new_bytes;
92
+ qemu_co_queue_restart_all(&req->wait_queue);
93
+}
94
+
95
+static void coroutine_fn block_copy_inflight_req_end(BlockCopyState *s,
96
+ BlockCopyInFlightReq *req,
97
+ int ret)
98
+{
99
+ s->in_flight_bytes -= req->bytes;
100
+ if (ret < 0) {
101
+ bdrv_set_dirty_bitmap(s->copy_bitmap, req->offset, req->bytes);
102
+ }
103
QLIST_REMOVE(req, list);
104
qemu_co_queue_restart_all(&req->wait_queue);
105
}
106
@@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
107
return ret;
108
}
109
110
-int coroutine_fn block_copy(BlockCopyState *s,
111
- int64_t offset, int64_t bytes,
112
- bool *error_is_read)
113
+/*
114
+ * block_copy_dirty_clusters
115
+ *
116
+ * Copy dirty clusters in @offset/@bytes range.
117
+ * Returns 1 if dirty clusters found and successfully copied, 0 if no dirty
118
+ * clusters found and -errno on failure.
119
+ */
120
+static int coroutine_fn block_copy_dirty_clusters(BlockCopyState *s,
121
+ int64_t offset, int64_t bytes,
122
+ bool *error_is_read)
123
{
124
int ret = 0;
125
- BlockCopyInFlightReq req;
126
+ bool found_dirty = false;
127
128
/*
129
* block_copy() user is responsible for keeping source and target in same
130
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
131
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
132
assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
133
134
- block_copy_wait_inflight_reqs(s, offset, bytes);
135
- block_copy_inflight_req_begin(s, &req, offset, bytes);
136
-
137
while (bytes) {
138
+ BlockCopyInFlightReq req;
139
int64_t next_zero, cur_bytes, status_bytes;
140
141
if (!bdrv_dirty_bitmap_get(s->copy_bitmap, offset)) {
142
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
143
continue; /* already copied */
144
}
145
146
+ found_dirty = true;
147
+
148
cur_bytes = MIN(bytes, s->copy_size);
149
150
next_zero = bdrv_dirty_bitmap_next_zero(s->copy_bitmap, offset,
151
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
152
assert(next_zero < offset + cur_bytes); /* no need to do MIN() */
153
cur_bytes = next_zero - offset;
154
}
155
+ block_copy_inflight_req_begin(s, &req, offset, cur_bytes);
156
157
ret = block_copy_block_status(s, offset, cur_bytes, &status_bytes);
158
+ assert(ret >= 0); /* never fail */
159
+ cur_bytes = MIN(cur_bytes, status_bytes);
160
+ block_copy_inflight_req_shrink(s, &req, cur_bytes);
161
if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
162
- bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, status_bytes);
163
+ block_copy_inflight_req_end(s, &req, 0);
164
progress_set_remaining(s->progress,
165
bdrv_get_dirty_count(s->copy_bitmap) +
166
s->in_flight_bytes);
167
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
168
continue;
169
}
170
171
- cur_bytes = MIN(cur_bytes, status_bytes);
172
-
173
trace_block_copy_process(s, offset);
174
175
- bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, cur_bytes);
176
- s->in_flight_bytes += cur_bytes;
177
-
178
co_get_from_shres(s->mem, cur_bytes);
179
ret = block_copy_do_copy(s, offset, cur_bytes, ret & BDRV_BLOCK_ZERO,
180
error_is_read);
181
co_put_to_shres(s->mem, cur_bytes);
182
- s->in_flight_bytes -= cur_bytes;
183
+ block_copy_inflight_req_end(s, &req, ret);
184
if (ret < 0) {
185
- bdrv_set_dirty_bitmap(s->copy_bitmap, offset, cur_bytes);
186
- break;
187
+ return ret;
188
}
189
190
progress_work_done(s->progress, cur_bytes);
191
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s,
192
bytes -= cur_bytes;
193
}
194
195
- block_copy_inflight_req_end(&req);
196
+ return found_dirty;
197
+}
198
+
199
+/*
200
+ * block_copy
201
+ *
202
+ * Copy requested region, accordingly to dirty bitmap.
203
+ * Collaborate with parallel block_copy requests: if they succeed it will help
204
+ * us. If they fail, we will retry not-copied regions. So, if we return error,
205
+ * it means that some I/O operation failed in context of _this_ block_copy call,
206
+ * not some parallel operation.
207
+ */
208
+int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
209
+ bool *error_is_read)
210
+{
211
+ int ret;
212
+
213
+ do {
214
+ ret = block_copy_dirty_clusters(s, offset, bytes, error_is_read);
215
+
216
+ if (ret == 0) {
217
+ ret = block_copy_wait_one(s, offset, bytes);
218
+ }
219
+
220
+ /*
221
+ * We retry in two cases:
222
+ * 1. Some progress done
223
+ * Something was copied, which means that there were yield points
224
+ * and some new dirty bits may have appeared (due to failed parallel
225
+ * block-copy requests).
226
+ * 2. We have waited for some intersecting block-copy request
227
+ * It may have failed and produced new dirty bits.
228
+ */
229
+ } while (ret > 0);
230
231
return ret;
232
}
233
--
234
2.24.1
235
236
diff view generated by jsdifflib
New patch
1
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
3
Hide structure definitions and add explicit API instead, to keep an
4
eye on the scope of the shared fields.
5
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-Id: <20200311103004.7649-10-vsementsov@virtuozzo.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/backup-top.c | 6 ++--
13
block/backup.c | 25 ++++++++--------
14
block/block-copy.c | 59 ++++++++++++++++++++++++++++++++++++++
15
include/block/block-copy.h | 52 +++------------------------------
16
4 files changed, 80 insertions(+), 62 deletions(-)
17
18
diff --git a/block/backup-top.c b/block/backup-top.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/backup-top.c
21
+++ b/block/backup-top.c
22
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVBackupTopState {
23
BlockCopyState *bcs;
24
BdrvChild *target;
25
bool active;
26
+ int64_t cluster_size;
27
} BDRVBackupTopState;
28
29
static coroutine_fn int backup_top_co_preadv(
30
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int backup_top_cbw(BlockDriverState *bs, uint64_t offset,
31
return 0;
32
}
33
34
- off = QEMU_ALIGN_DOWN(offset, s->bcs->cluster_size);
35
- end = QEMU_ALIGN_UP(offset + bytes, s->bcs->cluster_size);
36
+ off = QEMU_ALIGN_DOWN(offset, s->cluster_size);
37
+ end = QEMU_ALIGN_UP(offset + bytes, s->cluster_size);
38
39
return block_copy(s->bcs, off, end - off, NULL);
40
}
41
@@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_backup_top_append(BlockDriverState *source,
42
goto fail;
43
}
44
45
+ state->cluster_size = cluster_size;
46
state->bcs = block_copy_state_new(top->backing, state->target,
47
cluster_size, write_flags, &local_err);
48
if (local_err) {
49
diff --git a/block/backup.c b/block/backup.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/block/backup.c
52
+++ b/block/backup.c
53
@@ -XXX,XX +XXX,XX @@ static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
54
55
if (ret < 0 && job->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS) {
56
/* If we failed and synced, merge in the bits we didn't copy: */
57
- bdrv_dirty_bitmap_merge_internal(bm, job->bcs->copy_bitmap,
58
+ bdrv_dirty_bitmap_merge_internal(bm, block_copy_dirty_bitmap(job->bcs),
59
NULL, true);
60
}
61
}
62
@@ -XXX,XX +XXX,XX @@ void backup_do_checkpoint(BlockJob *job, Error **errp)
63
return;
64
}
65
66
- bdrv_set_dirty_bitmap(backup_job->bcs->copy_bitmap, 0, backup_job->len);
67
+ bdrv_set_dirty_bitmap(block_copy_dirty_bitmap(backup_job->bcs), 0,
68
+ backup_job->len);
69
}
70
71
static BlockErrorAction backup_error_action(BackupBlockJob *job,
72
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_loop(BackupBlockJob *job)
73
BdrvDirtyBitmapIter *bdbi;
74
int ret = 0;
75
76
- bdbi = bdrv_dirty_iter_new(job->bcs->copy_bitmap);
77
+ bdbi = bdrv_dirty_iter_new(block_copy_dirty_bitmap(job->bcs));
78
while ((offset = bdrv_dirty_iter_next(bdbi)) != -1) {
79
do {
80
if (yield_and_check(job)) {
81
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_loop(BackupBlockJob *job)
82
return ret;
83
}
84
85
-static void backup_init_copy_bitmap(BackupBlockJob *job)
86
+static void backup_init_bcs_bitmap(BackupBlockJob *job)
87
{
88
bool ret;
89
uint64_t estimate;
90
+ BdrvDirtyBitmap *bcs_bitmap = block_copy_dirty_bitmap(job->bcs);
91
92
if (job->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
93
- ret = bdrv_dirty_bitmap_merge_internal(job->bcs->copy_bitmap,
94
- job->sync_bitmap,
95
+ ret = bdrv_dirty_bitmap_merge_internal(bcs_bitmap, job->sync_bitmap,
96
NULL, true);
97
assert(ret);
98
} else {
99
@@ -XXX,XX +XXX,XX @@ static void backup_init_copy_bitmap(BackupBlockJob *job)
100
* We can't hog the coroutine to initialize this thoroughly.
101
* Set a flag and resume work when we are able to yield safely.
102
*/
103
- job->bcs->skip_unallocated = true;
104
+ block_copy_set_skip_unallocated(job->bcs, true);
105
}
106
- bdrv_set_dirty_bitmap(job->bcs->copy_bitmap, 0, job->len);
107
+ bdrv_set_dirty_bitmap(bcs_bitmap, 0, job->len);
108
}
109
110
- estimate = bdrv_get_dirty_count(job->bcs->copy_bitmap);
111
+ estimate = bdrv_get_dirty_count(bcs_bitmap);
112
job_progress_set_remaining(&job->common.job, estimate);
113
}
114
115
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
116
BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
117
int ret = 0;
118
119
- backup_init_copy_bitmap(s);
120
+ backup_init_bcs_bitmap(s);
121
122
if (s->sync_mode == MIRROR_SYNC_MODE_TOP) {
123
int64_t offset = 0;
124
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
125
126
offset += count;
127
}
128
- s->bcs->skip_unallocated = false;
129
+ block_copy_set_skip_unallocated(s->bcs, false);
130
}
131
132
if (s->sync_mode == MIRROR_SYNC_MODE_NONE) {
133
/*
134
- * All bits are set in copy_bitmap to allow any cluster to be copied.
135
+ * All bits are set in bcs bitmap to allow any cluster to be copied.
136
* This does not actually require them to be copied.
137
*/
138
while (!job_is_cancelled(job)) {
139
diff --git a/block/block-copy.c b/block/block-copy.c
140
index XXXXXXX..XXXXXXX 100644
141
--- a/block/block-copy.c
142
+++ b/block/block-copy.c
143
@@ -XXX,XX +XXX,XX @@
144
#define BLOCK_COPY_MAX_BUFFER (1 * MiB)
145
#define BLOCK_COPY_MAX_MEM (128 * MiB)
146
147
+typedef struct BlockCopyInFlightReq {
148
+ int64_t offset;
149
+ int64_t bytes;
150
+ QLIST_ENTRY(BlockCopyInFlightReq) list;
151
+ CoQueue wait_queue; /* coroutines blocked on this request */
152
+} BlockCopyInFlightReq;
153
+
154
+typedef struct BlockCopyState {
155
+ /*
156
+ * BdrvChild objects are not owned or managed by block-copy. They are
157
+ * provided by block-copy user and user is responsible for appropriate
158
+ * permissions on these children.
159
+ */
160
+ BdrvChild *source;
161
+ BdrvChild *target;
162
+ BdrvDirtyBitmap *copy_bitmap;
163
+ int64_t in_flight_bytes;
164
+ int64_t cluster_size;
165
+ bool use_copy_range;
166
+ int64_t copy_size;
167
+ uint64_t len;
168
+ QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs;
169
+
170
+ BdrvRequestFlags write_flags;
171
+
172
+ /*
173
+ * skip_unallocated:
174
+ *
175
+ * Used by sync=top jobs, which first scan the source node for unallocated
176
+ * areas and clear them in the copy_bitmap. During this process, the bitmap
177
+ * is thus not fully initialized: It may still have bits set for areas that
178
+ * are unallocated and should actually not be copied.
179
+ *
180
+ * This is indicated by skip_unallocated.
181
+ *
182
+ * In this case, block_copy() will query the source’s allocation status,
183
+ * skip unallocated regions, clear them in the copy_bitmap, and invoke
184
+ * block_copy_reset_unallocated() every time it does.
185
+ */
186
+ bool skip_unallocated;
187
+
188
+ ProgressMeter *progress;
189
+ /* progress_bytes_callback: called when some copying progress is done. */
190
+ ProgressBytesCallbackFunc progress_bytes_callback;
191
+ void *progress_opaque;
192
+
193
+ SharedResource *mem;
194
+} BlockCopyState;
195
+
196
static BlockCopyInFlightReq *find_conflicting_inflight_req(BlockCopyState *s,
197
int64_t offset,
198
int64_t bytes)
199
@@ -XXX,XX +XXX,XX @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
200
201
return ret;
202
}
203
+
204
+BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s)
205
+{
206
+ return s->copy_bitmap;
207
+}
208
+
209
+void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip)
210
+{
211
+ s->skip_unallocated = skip;
212
+}
213
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
214
index XXXXXXX..XXXXXXX 100644
215
--- a/include/block/block-copy.h
216
+++ b/include/block/block-copy.h
217
@@ -XXX,XX +XXX,XX @@
218
#include "block/block.h"
219
#include "qemu/co-shared-resource.h"
220
221
-typedef struct BlockCopyInFlightReq {
222
- int64_t offset;
223
- int64_t bytes;
224
- QLIST_ENTRY(BlockCopyInFlightReq) list;
225
- CoQueue wait_queue; /* coroutines blocked on this request */
226
-} BlockCopyInFlightReq;
227
-
228
typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);
229
-typedef struct BlockCopyState {
230
- /*
231
- * BdrvChild objects are not owned or managed by block-copy. They are
232
- * provided by block-copy user and user is responsible for appropriate
233
- * permissions on these children.
234
- */
235
- BdrvChild *source;
236
- BdrvChild *target;
237
- BdrvDirtyBitmap *copy_bitmap;
238
- int64_t in_flight_bytes;
239
- int64_t cluster_size;
240
- bool use_copy_range;
241
- int64_t copy_size;
242
- uint64_t len;
243
- QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs;
244
-
245
- BdrvRequestFlags write_flags;
246
-
247
- /*
248
- * skip_unallocated:
249
- *
250
- * Used by sync=top jobs, which first scan the source node for unallocated
251
- * areas and clear them in the copy_bitmap. During this process, the bitmap
252
- * is thus not fully initialized: It may still have bits set for areas that
253
- * are unallocated and should actually not be copied.
254
- *
255
- * This is indicated by skip_unallocated.
256
- *
257
- * In this case, block_copy() will query the source’s allocation status,
258
- * skip unallocated regions, clear them in the copy_bitmap, and invoke
259
- * block_copy_reset_unallocated() every time it does.
260
- */
261
- bool skip_unallocated;
262
-
263
- ProgressMeter *progress;
264
- /* progress_bytes_callback: called when some copying progress is done. */
265
- ProgressBytesCallbackFunc progress_bytes_callback;
266
- void *progress_opaque;
267
-
268
- SharedResource *mem;
269
-} BlockCopyState;
270
+typedef struct BlockCopyState BlockCopyState;
271
272
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
273
int64_t cluster_size,
274
@@ -XXX,XX +XXX,XX @@ int64_t block_copy_reset_unallocated(BlockCopyState *s,
275
int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
276
bool *error_is_read);
277
278
+BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s);
279
+void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip);
280
+
281
#endif /* BLOCK_COPY_H */
282
--
283
2.24.1
284
285
diff view generated by jsdifflib