1
The following changes since commit 8c1ecb590497b0349c550607db923972b37f6963:
1
The following changes since commit 23919ddfd56135cad3cb468a8f54d5a595f024f4:
2
2
3
Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-next-280519-2' into staging (2019-05-28 17:38:32 +0100)
3
Merge remote-tracking branch 'remotes/aperard/tags/pull-xen-20190827' into staging (2019-08-27 15:52:36 +0100)
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-05-28
7
https://github.com/XanClic/qemu.git tags/pull-block-2019-08-27
8
8
9
for you to fetch changes up to a2d665c1bc3624a8375e2f9a7d569f7565cc1358:
9
for you to fetch changes up to bb043c056cffcc2f3ce88bfdaf2e76e455c09e2c:
10
10
11
blockdev: loosen restrictions on drive-backup source node (2019-05-28 20:30:55 +0200)
11
iotests: Unify cache mode quoting (2019-08-27 19:48:44 +0200)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches:
14
Block patches:
15
- qcow2: Use threads for encrypted I/O
15
- qemu-io now accepts a file to read a write pattern from
16
- qemu-img rebase: Optimizations
16
- Ensure that raw files have their first block allocated so we can probe
17
- backup job: Allow any source node, and some refactoring
17
the O_DIRECT alignment if necessary
18
- Some general simplifications in the block layer
18
- Various fixes
19
19
20
----------------------------------------------------------------
20
----------------------------------------------------------------
21
Alberto Garcia (2):
21
Denis Plotnikov (1):
22
block: Use bdrv_unref_child() for all children in bdrv_close()
22
qemu-io: add pattern file for write command
23
block: Make bdrv_root_attach_child() unref child_bs on failure
24
23
25
Andrey Shinkevich (1):
24
Max Reitz (7):
26
qcow2-bitmap: initialize bitmap directory alignment
25
iotests: Fix _filter_img_create()
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
27
32
28
Anton Nefedov (1):
33
Nir Soffer (3):
29
qcow2: skip writing zero buffers to empty COW areas
34
block: posix: Always allocate the first block
35
iotests: Test allocate_first_block() with O_DIRECT
36
iotests: Unify cache mode quoting
30
37
31
John Snow (1):
38
Stefan Hajnoczi (1):
32
blockdev: loosen restrictions on drive-backup source node
39
file-posix: fix request_alignment typo
33
40
34
Sam Eiderman (3):
41
Thomas Huth (2):
35
qemu-img: rebase: Reuse parent BlockDriverState
42
iotests: Check for enabled drivers before testing them
36
qemu-img: rebase: Reduce reads on in-chain rebase
43
tests/check-block: Skip iotests when sanitizers are enabled
37
qemu-img: rebase: Reuse in-chain BlockDriverState
38
44
39
Vladimir Sementsov-Ogievskiy (13):
45
Vladimir Sementsov-Ogievskiy (1):
40
qcow2.h: add missing include
46
block: fix permission update in bdrv_replace_node
41
qcow2: add separate file for threaded data processing functions
42
qcow2-threads: use thread_pool_submit_co
43
qcow2-threads: qcow2_co_do_compress: protect queuing by mutex
44
qcow2-threads: split out generic path
45
qcow2: qcow2_co_preadv: improve locking
46
qcow2: bdrv_co_pwritev: move encryption code out of the lock
47
qcow2: do encryption in threads
48
block/backup: simplify backup_incremental_init_copy_bitmap
49
block/backup: move to copy_bitmap with granularity
50
block/backup: refactor and tolerate unallocated cluster skipping
51
block/backup: unify different modes code path
52
block/backup: refactor: split out backup_calculate_cluster_size
53
47
54
block/Makefile.objs | 2 +-
48
block.c | 5 +-
55
qapi/block-core.json | 4 +-
49
block/file-posix.c | 53 +++++++++-
56
block/qcow2.h | 26 ++-
50
block/vmdk.c | 64 ++++++++----
57
block.c | 46 +++---
51
qemu-io-cmds.c | 99 +++++++++++++++++--
58
block/backup.c | 243 ++++++++++++---------------
52
tests/check-block.sh | 5 +
59
block/block-backend.c | 3 +-
53
tests/qemu-iotests/002 | 1 +
60
block/qcow2-bitmap.c | 3 +-
54
tests/qemu-iotests/003 | 1 +
61
block/qcow2-cache.c | 1 -
55
tests/qemu-iotests/005 | 3 +-
62
block/qcow2-cluster.c | 10 +-
56
tests/qemu-iotests/009 | 1 +
63
block/qcow2-refcount.c | 1 -
57
tests/qemu-iotests/010 | 1 +
64
block/qcow2-snapshot.c | 1 -
58
tests/qemu-iotests/011 | 1 +
65
block/qcow2-threads.c | 268 ++++++++++++++++++++++++++++++
59
tests/qemu-iotests/017 | 3 +-
66
block/qcow2.c | 320 +++++++++++++-----------------------
60
tests/qemu-iotests/018 | 3 +-
67
block/quorum.c | 1 -
61
tests/qemu-iotests/019 | 3 +-
68
blockdev.c | 7 +-
62
tests/qemu-iotests/020 | 3 +-
69
blockjob.c | 2 +-
63
tests/qemu-iotests/026 | 4 +-
70
qemu-img.c | 85 ++++++----
64
tests/qemu-iotests/027 | 1 +
71
tests/test-bdrv-drain.c | 6 -
65
tests/qemu-iotests/032 | 1 +
72
tests/test-bdrv-graph-mod.c | 1 -
66
tests/qemu-iotests/033 | 1 +
73
block/trace-events | 1 +
67
tests/qemu-iotests/034 | 3 +-
74
tests/qemu-iotests/056 | 2 +-
68
tests/qemu-iotests/037 | 3 +-
75
tests/qemu-iotests/060 | 7 +-
69
tests/qemu-iotests/039 | 4 +-
76
tests/qemu-iotests/060.out | 5 +-
70
tests/qemu-iotests/052 | 2 +-
77
23 files changed, 615 insertions(+), 430 deletions(-)
71
tests/qemu-iotests/059 | 34 ++++++-
78
create mode 100644 block/qcow2-threads.c
72
tests/qemu-iotests/059.out | 26 +++--
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
79
101
80
--
102
--
81
2.21.0
103
2.21.0
82
104
83
105
diff view generated by jsdifflib
Deleted patch
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
1
3
qcow2.h depends on block_int.h. Compilation isn't broken currently only
4
due to block_int.h always included before qcow2.h. Though, it seems
5
better to directly include block_int.h in qcow2.h.
6
7
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: Alberto Garcia <berto@igalia.com>
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Message-id: 20190506142741.41731-2-vsementsov@virtuozzo.com
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
block/qcow2.h | 1 +
14
block/qcow2-bitmap.c | 1 -
15
block/qcow2-cache.c | 1 -
16
block/qcow2-cluster.c | 1 -
17
block/qcow2-refcount.c | 1 -
18
block/qcow2-snapshot.c | 1 -
19
block/qcow2.c | 1 -
20
7 files changed, 1 insertion(+), 6 deletions(-)
21
22
diff --git a/block/qcow2.h b/block/qcow2.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/qcow2.h
25
+++ b/block/qcow2.h
26
@@ -XXX,XX +XXX,XX @@
27
#include "crypto/block.h"
28
#include "qemu/coroutine.h"
29
#include "qemu/units.h"
30
+#include "block/block_int.h"
31
32
//#define DEBUG_ALLOC
33
//#define DEBUG_ALLOC2
34
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/block/qcow2-bitmap.c
37
+++ b/block/qcow2-bitmap.c
38
@@ -XXX,XX +XXX,XX @@
39
#include "qapi/error.h"
40
#include "qemu/cutils.h"
41
42
-#include "block/block_int.h"
43
#include "qcow2.h"
44
45
/* NOTICE: BME here means Bitmaps Extension and used as a namespace for
46
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/block/qcow2-cache.c
49
+++ b/block/qcow2-cache.c
50
@@ -XXX,XX +XXX,XX @@
51
*/
52
53
#include "qemu/osdep.h"
54
-#include "block/block_int.h"
55
#include "qemu-common.h"
56
#include "qcow2.h"
57
#include "trace.h"
58
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/block/qcow2-cluster.c
61
+++ b/block/qcow2-cluster.c
62
@@ -XXX,XX +XXX,XX @@
63
64
#include "qapi/error.h"
65
#include "qemu-common.h"
66
-#include "block/block_int.h"
67
#include "qcow2.h"
68
#include "qemu/bswap.h"
69
#include "trace.h"
70
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
71
index XXXXXXX..XXXXXXX 100644
72
--- a/block/qcow2-refcount.c
73
+++ b/block/qcow2-refcount.c
74
@@ -XXX,XX +XXX,XX @@
75
#include "qemu/osdep.h"
76
#include "qapi/error.h"
77
#include "qemu-common.h"
78
-#include "block/block_int.h"
79
#include "qcow2.h"
80
#include "qemu/range.h"
81
#include "qemu/bswap.h"
82
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/block/qcow2-snapshot.c
85
+++ b/block/qcow2-snapshot.c
86
@@ -XXX,XX +XXX,XX @@
87
88
#include "qemu/osdep.h"
89
#include "qapi/error.h"
90
-#include "block/block_int.h"
91
#include "qcow2.h"
92
#include "qemu/bswap.h"
93
#include "qemu/error-report.h"
94
diff --git a/block/qcow2.c b/block/qcow2.c
95
index XXXXXXX..XXXXXXX 100644
96
--- a/block/qcow2.c
97
+++ b/block/qcow2.c
98
@@ -XXX,XX +XXX,XX @@
99
#define ZLIB_CONST
100
#include <zlib.h>
101
102
-#include "block/block_int.h"
103
#include "block/qdict.h"
104
#include "sysemu/block-backend.h"
105
#include "qemu/module.h"
106
--
107
2.21.0
108
109
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
2
2
3
Split out cluster_size calculation. Move copy-bitmap creation above
3
The patch allows to provide a pattern file for write
4
block-job creation, as we are going to share it with upcoming
4
command. There was no similar ability before.
5
backup-top filter, which also should be created before actual block job
6
creation.
7
5
8
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
9
Message-id: 20190429090842.57910-6-vsementsov@virtuozzo.com
7
Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com
10
[mreitz: Dropped a paragraph from the commit message that was left over
8
Reviewed-by: Eric Blake <eblake@redhat.com>
11
from a previous version]
9
[mreitz: Keep optstring in alphabetical order]
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
11
---
14
block/backup.c | 82 ++++++++++++++++++++++++++++++++------------------
12
qemu-io-cmds.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++---
15
1 file changed, 52 insertions(+), 30 deletions(-)
13
1 file changed, 93 insertions(+), 6 deletions(-)
16
14
17
diff --git a/block/backup.c b/block/backup.c
15
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
19
--- a/block/backup.c
17
--- a/qemu-io-cmds.c
20
+++ b/block/backup.c
18
+++ b/qemu-io-cmds.c
21
@@ -XXX,XX +XXX,XX @@ static const BlockJobDriver backup_job_driver = {
19
@@ -XXX,XX +XXX,XX @@ static void qemu_io_free(void *p)
22
.drain = backup_drain,
20
qemu_vfree(p);
23
};
21
}
24
22
25
+static int64_t backup_calculate_cluster_size(BlockDriverState *target,
23
+/*
26
+ Error **errp)
24
+ * qemu_io_alloc_from_file()
25
+ *
26
+ * Allocates the buffer and populates it with the content of the given file
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)
27
+{
39
+{
28
+ int ret;
40
+ char *buf, *buf_origin;
29
+ BlockDriverInfo bdi;
41
+ FILE *f = fopen(file_name, "r");
42
+ int pattern_len;
30
+
43
+
31
+ /*
44
+ if (!f) {
32
+ * If there is no backing file on the target, we cannot rely on COW if our
45
+ perror(file_name);
33
+ * backup cluster size is smaller than the target cluster size. Even for
46
+ return NULL;
34
+ * targets with a backing file, try to avoid COW if possible.
35
+ */
36
+ ret = bdrv_get_info(target, &bdi);
37
+ if (ret == -ENOTSUP && !target->backing) {
38
+ /* Cluster size is not defined */
39
+ warn_report("The target block device doesn't provide "
40
+ "information about the block size and it doesn't have a "
41
+ "backing file. The default block size of %u bytes is "
42
+ "used. If the actual block size of the target exceeds "
43
+ "this default, the backup may be unusable",
44
+ BACKUP_CLUSTER_SIZE_DEFAULT);
45
+ return BACKUP_CLUSTER_SIZE_DEFAULT;
46
+ } else if (ret < 0 && !target->backing) {
47
+ error_setg_errno(errp, -ret,
48
+ "Couldn't determine the cluster size of the target image, "
49
+ "which has no backing file");
50
+ error_append_hint(errp,
51
+ "Aborting, since this may create an unusable destination image\n");
52
+ return ret;
53
+ } else if (ret < 0 && target->backing) {
54
+ /* Not fatal; just trudge on ahead. */
55
+ return BACKUP_CLUSTER_SIZE_DEFAULT;
56
+ }
47
+ }
57
+
48
+
58
+ return MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
49
+ if (qemuio_misalign) {
59
+}
50
+ len += MISALIGN_OFFSET;
51
+ }
60
+
52
+
61
BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
53
+ buf_origin = buf = blk_blockalign(blk, len);
62
BlockDriverState *target, int64_t speed,
54
+
63
MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap,
55
+ if (qemuio_misalign) {
64
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
56
+ buf_origin += MISALIGN_OFFSET;
65
JobTxn *txn, Error **errp)
57
+ buf += MISALIGN_OFFSET;
66
{
58
+ len -= MISALIGN_OFFSET;
67
int64_t len;
59
+ }
68
- BlockDriverInfo bdi;
60
+
69
BackupBlockJob *job = NULL;
61
+ pattern_len = fread(buf_origin, 1, len, f);
70
int ret;
62
+
71
+ int64_t cluster_size;
63
+ if (ferror(f)) {
72
+ HBitmap *copy_bitmap = NULL;
64
+ perror(file_name);
73
74
assert(bs);
75
assert(target);
76
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
77
goto error;
78
}
79
80
+ cluster_size = backup_calculate_cluster_size(target, errp);
81
+ if (cluster_size < 0) {
82
+ goto error;
65
+ goto error;
83
+ }
66
+ }
84
+
67
+
85
+ copy_bitmap = hbitmap_alloc(len, ctz32(cluster_size));
68
+ if (pattern_len == 0) {
69
+ fprintf(stderr, "%s: file is empty\n", file_name);
70
+ goto error;
71
+ }
86
+
72
+
87
/* job->len is fixed, so we can't allow resize */
73
+ fclose(f);
88
job = block_job_create(job_id, &backup_job_driver, txn, bs,
74
+
89
BLK_PERM_CONSISTENT_READ,
75
+ if (len > pattern_len) {
90
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
76
+ len -= pattern_len;
91
77
+ buf += pattern_len;
92
/* Detect image-fleecing (and similar) schemes */
78
+
93
job->serialize_target_writes = bdrv_chain_contains(target, bs);
79
+ while (len > 0) {
94
-
80
+ size_t len_to_copy = MIN(pattern_len, len);
95
- /* If there is no backing file on the target, we cannot rely on COW if our
81
+
96
- * backup cluster size is smaller than the target cluster size. Even for
82
+ memcpy(buf, buf_origin, len_to_copy);
97
- * targets with a backing file, try to avoid COW if possible. */
83
+
98
- ret = bdrv_get_info(target, &bdi);
84
+ len -= len_to_copy;
99
- if (ret == -ENOTSUP && !target->backing) {
85
+ buf += len_to_copy;
100
- /* Cluster size is not defined */
86
+ }
101
- warn_report("The target block device doesn't provide "
102
- "information about the block size and it doesn't have a "
103
- "backing file. The default block size of %u bytes is "
104
- "used. If the actual block size of the target exceeds "
105
- "this default, the backup may be unusable",
106
- BACKUP_CLUSTER_SIZE_DEFAULT);
107
- job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
108
- } else if (ret < 0 && !target->backing) {
109
- error_setg_errno(errp, -ret,
110
- "Couldn't determine the cluster size of the target image, "
111
- "which has no backing file");
112
- error_append_hint(errp,
113
- "Aborting, since this may create an unusable destination image\n");
114
- goto error;
115
- } else if (ret < 0 && target->backing) {
116
- /* Not fatal; just trudge on ahead. */
117
- job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
118
- } else {
119
- job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
120
- }
121
-
122
- job->copy_bitmap = hbitmap_alloc(len, ctz32(job->cluster_size));
123
+ job->cluster_size = cluster_size;
124
+ job->copy_bitmap = copy_bitmap;
125
+ copy_bitmap = NULL;
126
job->use_copy_range = true;
127
job->copy_range_size = MIN_NON_ZERO(blk_get_max_transfer(job->common.blk),
128
blk_get_max_transfer(job->target));
129
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
130
return &job->common;
131
132
error:
133
+ if (copy_bitmap) {
134
+ assert(!job || !job->copy_bitmap);
135
+ hbitmap_free(copy_bitmap);
136
+ }
87
+ }
137
if (sync_bitmap) {
88
+
138
bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
89
+ return buf_origin;
90
+
91
+error:
92
+ qemu_io_free(buf_origin);
93
+ return NULL;
94
+}
95
+
96
static void dump_buffer(const void *buffer, int64_t offset, int64_t len)
97
{
98
uint64_t i;
99
@@ -XXX,XX +XXX,XX @@ static void write_help(void)
100
" -n, -- with -z, don't allow slow fallback\n"
101
" -p, -- ignored for backwards compatibility\n"
102
" -P, -- use different pattern to fill file\n"
103
+" -s, -- use a pattern file to fill the write buffer\n"
104
" -C, -- report statistics in a machine parsable format\n"
105
" -q, -- quiet mode, do not show I/O statistics\n"
106
" -u, -- with -z, allow unmapping\n"
107
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t write_cmd = {
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;
139
}
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);
140
--
175
--
141
2.21.0
176
2.21.0
142
177
143
178
diff view generated by jsdifflib
1
From: Alberto Garcia <berto@igalia.com>
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
2
3
A consequence of the previous patch is that bdrv_attach_child()
3
It's wrong to OR shared permissions. It may lead to crash on further
4
transfers the reference to child_bs from the caller to parent_bs,
4
permission updates.
5
which will drop it on bdrv_close() or when someone calls
5
Also, no needs to consider previously calculated permissions, as at
6
bdrv_unref_child().
6
this point we already bind all new parents and bdrv_get_cumulative_perm
7
result is enough. So fix the bug by just set permissions by
8
bdrv_get_cumulative_perm result.
7
9
8
But this only happens when bdrv_attach_child() succeeds. If it fails
10
Bug was introduced in long ago 234ac1a9025, in 2.9.
9
then the caller is responsible for dropping the reference to child_bs.
10
11
11
This patch makes bdrv_attach_child() take the reference also when
12
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12
there is an error, freeing the caller for having to do it.
13
Message-id: 20190824100740.61635-1-vsementsov@virtuozzo.com
13
14
A similar situation happens with bdrv_root_attach_child(), so the
15
changes on this patch affect both functions.
16
17
Signed-off-by: Alberto Garcia <berto@igalia.com>
18
Message-id: 20dfb3d9ccec559cdd1a9690146abad5d204a186.1557754872.git.berto@igalia.com
19
[mreitz: Removed now superfluous BdrvChild * variable in
20
bdrv_open_child()]
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
---
15
---
23
block.c | 30 ++++++++++++++++++------------
16
block.c | 5 ++---
24
block/block-backend.c | 3 +--
17
1 file changed, 2 insertions(+), 3 deletions(-)
25
block/quorum.c | 1 -
26
blockjob.c | 2 +-
27
4 files changed, 20 insertions(+), 16 deletions(-)
28
18
29
diff --git a/block.c b/block.c
19
diff --git a/block.c b/block.c
30
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
31
--- a/block.c
21
--- a/block.c
32
+++ b/block.c
22
+++ b/block.c
33
@@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)
23
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
24
{
25
BdrvChild *c, *next;
26
GSList *list = NULL, *p;
27
- uint64_t old_perm, old_shared;
28
uint64_t perm = 0, shared = BLK_PERM_ALL;
29
int ret;
30
31
@@ -XXX,XX +XXX,XX @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
32
bdrv_unref(from);
34
}
33
}
35
}
34
36
35
- bdrv_get_cumulative_perm(to, &old_perm, &old_shared);
37
+/*
36
- bdrv_set_perm(to, old_perm | perm, old_shared | shared);
38
+ * This function steals the reference to child_bs from the caller.
37
+ bdrv_get_cumulative_perm(to, &perm, &shared);
39
+ * That reference is later dropped by bdrv_root_unref_child().
38
+ bdrv_set_perm(to, perm, shared);
40
+ *
41
+ * On failure NULL is returned, errp is set and the reference to
42
+ * child_bs is also dropped.
43
+ */
44
BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
45
const char *child_name,
46
const BdrvChildRole *child_role,
47
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
48
ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp);
49
if (ret < 0) {
50
bdrv_abort_perm_update(child_bs);
51
+ bdrv_unref(child_bs);
52
return NULL;
53
}
54
55
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
56
return child;
57
}
58
59
+/*
60
+ * This function transfers the reference to child_bs from the caller
61
+ * to parent_bs. That reference is later dropped by parent_bs on
62
+ * bdrv_close() or if someone calls bdrv_unref_child().
63
+ *
64
+ * On failure NULL is returned, errp is set and the reference to
65
+ * child_bs is also dropped.
66
+ */
67
BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
68
BlockDriverState *child_bs,
69
const char *child_name,
70
@@ -XXX,XX +XXX,XX @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
71
/* If backing_hd was already part of bs's backing chain, and
72
* inherits_from pointed recursively to bs then let's update it to
73
* point directly to bs (else it will become NULL). */
74
- if (update_inherits_from) {
75
+ if (bs->backing && update_inherits_from) {
76
backing_hd->inherits_from = bs;
77
}
78
- if (!bs->backing) {
79
- bdrv_unref(backing_hd);
80
- }
81
39
82
out:
40
out:
83
bdrv_refresh_limits(bs, NULL);
41
g_slist_free(list);
84
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
85
const BdrvChildRole *child_role,
86
bool allow_none, Error **errp)
87
{
88
- BdrvChild *c;
89
BlockDriverState *bs;
90
91
bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role,
92
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_open_child(const char *filename,
93
return NULL;
94
}
95
96
- c = bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
97
- if (!c) {
98
- bdrv_unref(bs);
99
- return NULL;
100
- }
101
-
102
- return c;
103
+ return bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
104
}
105
106
/* TODO Future callers may need to specify parent/child_role in order for
107
diff --git a/block/block-backend.c b/block/block-backend.c
108
index XXXXXXX..XXXXXXX 100644
109
--- a/block/block-backend.c
110
+++ b/block/block-backend.c
111
@@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
112
blk->root = bdrv_root_attach_child(bs, "root", &child_root,
113
perm, BLK_PERM_ALL, blk, errp);
114
if (!blk->root) {
115
- bdrv_unref(bs);
116
blk_unref(blk);
117
return NULL;
118
}
119
@@ -XXX,XX +XXX,XX @@ void blk_remove_bs(BlockBackend *blk)
120
int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp)
121
{
122
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
123
+ bdrv_ref(bs);
124
blk->root = bdrv_root_attach_child(bs, "root", &child_root,
125
blk->perm, blk->shared_perm, blk, errp);
126
if (blk->root == NULL) {
127
return -EPERM;
128
}
129
- bdrv_ref(bs);
130
131
notifier_list_notify(&blk->insert_bs_notifiers, blk);
132
if (tgm->throttle_state) {
133
diff --git a/block/quorum.c b/block/quorum.c
134
index XXXXXXX..XXXXXXX 100644
135
--- a/block/quorum.c
136
+++ b/block/quorum.c
137
@@ -XXX,XX +XXX,XX @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs,
138
child = bdrv_attach_child(bs, child_bs, indexstr, &child_format, errp);
139
if (child == NULL) {
140
s->next_child_index--;
141
- bdrv_unref(child_bs);
142
goto out;
143
}
144
s->children = g_renew(BdrvChild *, s->children, s->num_children + 1);
145
diff --git a/blockjob.c b/blockjob.c
146
index XXXXXXX..XXXXXXX 100644
147
--- a/blockjob.c
148
+++ b/blockjob.c
149
@@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
150
{
151
BdrvChild *c;
152
153
+ bdrv_ref(bs);
154
c = bdrv_root_attach_child(bs, name, &child_job, perm, shared_perm,
155
job, errp);
156
if (c == NULL) {
157
@@ -XXX,XX +XXX,XX @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
158
}
159
160
job->nodes = g_slist_prepend(job->nodes, c);
161
- bdrv_ref(bs);
162
bdrv_op_block_all(bs, job->blocker);
163
164
return 0;
165
--
42
--
166
2.21.0
43
2.21.0
167
44
168
45
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Nir Soffer <nirsof@gmail.com>
2
2
3
Move compression-on-threads to separate file. Encryption will be in it
3
When creating an image with preallocation "off" or "falloc", the first
4
too.
4
block of the image is typically not allocated. When using Gluster
5
5
storage backed by XFS filesystem, reading this block using direct I/O
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
succeeds regardless of request length, fooling alignment detection.
7
Reviewed-by: Alberto Garcia <berto@igalia.com>
7
8
In this case we fallback to a safe value (4096) instead of the optimal
9
value (512), which may lead to unneeded data copying when aligning
10
requests. Allocating the first block avoids the fallback.
11
12
Since we allocate the first block even with preallocation=off, we no
13
longer create images with zero disk size:
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
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
59
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190506142741.41731-3-vsementsov@virtuozzo.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
60
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
61
---
12
block/Makefile.objs | 2 +-
62
block/file-posix.c | 51 +++++++++++++++++++
13
block/qcow2.h | 7 ++
63
tests/qemu-iotests/059.out | 2 +-
14
block/qcow2-threads.c | 201 ++++++++++++++++++++++++++++++++++++++++++
64
tests/qemu-iotests/{150.out => 150.out.qcow2} | 0
15
block/qcow2.c | 169 -----------------------------------
65
tests/qemu-iotests/150.out.raw | 12 +++++
16
4 files changed, 209 insertions(+), 170 deletions(-)
66
tests/qemu-iotests/175 | 19 ++++---
17
create mode 100644 block/qcow2-threads.c
67
tests/qemu-iotests/175.out | 8 +--
18
68
tests/qemu-iotests/178.out.qcow2 | 4 +-
19
diff --git a/block/Makefile.objs b/block/Makefile.objs
69
tests/qemu-iotests/221.out | 12 +++--
20
index XXXXXXX..XXXXXXX 100644
70
tests/qemu-iotests/253.out | 12 +++--
21
--- a/block/Makefile.objs
71
9 files changed, 99 insertions(+), 21 deletions(-)
22
+++ b/block/Makefile.objs
72
rename tests/qemu-iotests/{150.out => 150.out.qcow2} (100%)
23
@@ -XXX,XX +XXX,XX @@ block-obj-$(CONFIG_BOCHS) += bochs.o
73
create mode 100644 tests/qemu-iotests/150.out.raw
24
block-obj-$(CONFIG_VVFAT) += vvfat.o
74
25
block-obj-$(CONFIG_DMG) += dmg.o
75
diff --git a/block/file-posix.c b/block/file-posix.c
26
76
index XXXXXXX..XXXXXXX 100644
27
-block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o qcow2-bitmap.o
77
--- a/block/file-posix.c
28
+block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o qcow2-bitmap.o qcow2-threads.o
78
+++ b/block/file-posix.c
29
block-obj-$(CONFIG_QED) += qed.o qed-l2-cache.o qed-table.o qed-cluster.o
79
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
30
block-obj-$(CONFIG_QED) += qed-check.o
80
return ret;
31
block-obj-y += vhdx.o vhdx-endian.o vhdx-log.o
81
}
32
diff --git a/block/qcow2.h b/block/qcow2.h
82
33
index XXXXXXX..XXXXXXX 100644
83
+/*
34
--- a/block/qcow2.h
84
+ * Help alignment probing by allocating the first block.
35
+++ b/block/qcow2.h
85
+ *
36
@@ -XXX,XX +XXX,XX @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs,
86
+ * When reading with direct I/O from unallocated area on Gluster backed by XFS,
37
const char *name,
87
+ * reading succeeds regardless of request length. In this case we fallback to
38
Error **errp);
88
+ * safe alignment which is not optimal. Allocating the first block avoids this
39
89
+ * fallback.
40
+ssize_t coroutine_fn
90
+ *
41
+qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
91
+ * fd may be opened with O_DIRECT, but we don't know the buffer alignment or
42
+ const void *src, size_t src_size);
92
+ * request alignment, so we use safe values.
43
+ssize_t coroutine_fn
93
+ *
44
+qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
94
+ * Returns: 0 on success, -errno on failure. Since this is an optimization,
45
+ const void *src, size_t src_size);
95
+ * caller may ignore failures.
46
+
96
+ */
47
#endif
97
+static int allocate_first_block(int fd, size_t max_size)
48
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
98
+{
99
+ size_t write_size = (max_size < MAX_BLOCKSIZE)
100
+ ? BDRV_SECTOR_SIZE
101
+ : MAX_BLOCKSIZE;
102
+ size_t max_align = MAX(MAX_BLOCKSIZE, getpagesize());
103
+ void *buf;
104
+ ssize_t n;
105
+ int ret;
106
+
107
+ buf = qemu_memalign(max_align, write_size);
108
+ memset(buf, 0, write_size);
109
+
110
+ do {
111
+ n = pwrite(fd, buf, write_size, 0);
112
+ } while (n == -1 && errno == EINTR);
113
+
114
+ ret = (n == -1) ? -errno : 0;
115
+
116
+ qemu_vfree(buf);
117
+ return ret;
118
+}
119
+
120
static int handle_aiocb_truncate(void *opaque)
121
{
122
RawPosixAIOData *aiocb = opaque;
123
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_truncate(void *opaque)
124
/* posix_fallocate() doesn't set errno. */
125
error_setg_errno(errp, -result,
126
"Could not preallocate new data");
127
+ } else if (current_length == 0) {
128
+ /*
129
+ * posix_fallocate() uses fallocate() if the filesystem
130
+ * supports it, or fallback to manually writing zeroes. If
131
+ * fallocate() was used, unaligned reads from the fallocated
132
+ * area in raw_probe_alignment() will succeed, hence we need to
133
+ * allocate the first block.
134
+ *
135
+ * Optimize future alignment probing; ignore failures.
136
+ */
137
+ allocate_first_block(fd, offset);
138
}
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
}
149
return result;
150
default:
151
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
152
index XXXXXXX..XXXXXXX 100644
153
--- a/tests/qemu-iotests/059.out
154
+++ b/tests/qemu-iotests/059.out
155
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMax
156
image: TEST_DIR/t.vmdk
157
file format: vmdk
158
virtual size: 0.977 TiB (1073741824000 bytes)
159
-disk size: 16 KiB
160
+disk size: 1.97 MiB
161
Format specific information:
162
cid: XXXXXXXX
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
49
new file mode 100644
169
new file mode 100644
50
index XXXXXXX..XXXXXXX
170
index XXXXXXX..XXXXXXX
51
--- /dev/null
171
--- /dev/null
52
+++ b/block/qcow2-threads.c
172
+++ b/tests/qemu-iotests/150.out.raw
53
@@ -XXX,XX +XXX,XX @@
173
@@ -XXX,XX +XXX,XX @@
54
+/*
174
+QA output created by 150
55
+ * Threaded data processing for Qcow2: compression, encryption
175
+
56
+ *
176
+=== Mapping sparse conversion ===
57
+ * Copyright (c) 2004-2006 Fabrice Bellard
177
+
58
+ * Copyright (c) 2018 Virtuozzo International GmbH. All rights reserved.
178
+Offset Length File
59
+ *
179
+0 0x1000 TEST_DIR/t.IMGFMT
60
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
180
+
61
+ * of this software and associated documentation files (the "Software"), to deal
181
+=== Mapping non-sparse conversion ===
62
+ * in the Software without restriction, including without limitation the rights
182
+
63
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
183
+Offset Length File
64
+ * copies of the Software, and to permit persons to whom the Software is
184
+0 0x100000 TEST_DIR/t.IMGFMT
65
+ * furnished to do so, subject to the following conditions:
185
+*** done
66
+ *
186
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
67
+ * The above copyright notice and this permission notice shall be included in
187
index XXXXXXX..XXXXXXX 100755
68
+ * all copies or substantial portions of the Software.
188
--- a/tests/qemu-iotests/175
69
+ *
189
+++ b/tests/qemu-iotests/175
70
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
190
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
71
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191
# the file size. This function hides the resulting difference in the
72
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
192
# stat -c '%b' output.
73
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
193
# Parameter 1: Number of blocks an empty file occupies
74
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
194
-# Parameter 2: Image size in bytes
75
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
195
+# Parameter 2: Minimal number of blocks in an image
76
+ * THE SOFTWARE.
196
+# Parameter 3: Image size in bytes
77
+ */
197
_filter_blocks()
78
+
198
{
79
+#include "qemu/osdep.h"
199
extra_blocks=$1
80
+
200
- img_size=$2
81
+#define ZLIB_CONST
201
+ min_blocks=$2
82
+#include <zlib.h>
202
+ img_size=$3
83
+
203
84
+#include "qcow2.h"
204
- sed -e "s/blocks=$extra_blocks\\(\$\\|[^0-9]\\)/nothing allocated/" \
85
+#include "block/thread-pool.h"
205
- -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/everything allocated/"
86
+
206
+ sed -e "s/blocks=$min_blocks\\(\$\\|[^0-9]\\)/min allocation/" \
87
+#define MAX_COMPRESS_THREADS 4
207
+ -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
88
+
89
+typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size,
90
+ const void *src, size_t src_size);
91
+typedef struct Qcow2CompressData {
92
+ void *dest;
93
+ size_t dest_size;
94
+ const void *src;
95
+ size_t src_size;
96
+ ssize_t ret;
97
+
98
+ Qcow2CompressFunc func;
99
+} Qcow2CompressData;
100
+
101
+/*
102
+ * qcow2_compress()
103
+ *
104
+ * @dest - destination buffer, @dest_size bytes
105
+ * @src - source buffer, @src_size bytes
106
+ *
107
+ * Returns: compressed size on success
108
+ * -ENOMEM destination buffer is not enough to store compressed data
109
+ * -EIO on any other error
110
+ */
111
+static ssize_t qcow2_compress(void *dest, size_t dest_size,
112
+ const void *src, size_t src_size)
113
+{
114
+ ssize_t ret;
115
+ z_stream strm;
116
+
117
+ /* best compression, small window, no zlib header */
118
+ memset(&strm, 0, sizeof(strm));
119
+ ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
120
+ -12, 9, Z_DEFAULT_STRATEGY);
121
+ if (ret != Z_OK) {
122
+ return -EIO;
123
+ }
124
+
125
+ /*
126
+ * strm.next_in is not const in old zlib versions, such as those used on
127
+ * OpenBSD/NetBSD, so cast the const away
128
+ */
129
+ strm.avail_in = src_size;
130
+ strm.next_in = (void *) src;
131
+ strm.avail_out = dest_size;
132
+ strm.next_out = dest;
133
+
134
+ ret = deflate(&strm, Z_FINISH);
135
+ if (ret == Z_STREAM_END) {
136
+ ret = dest_size - strm.avail_out;
137
+ } else {
138
+ ret = (ret == Z_OK ? -ENOMEM : -EIO);
139
+ }
140
+
141
+ deflateEnd(&strm);
142
+
143
+ return ret;
144
+}
145
+
146
+/*
147
+ * qcow2_decompress()
148
+ *
149
+ * Decompress some data (not more than @src_size bytes) to produce exactly
150
+ * @dest_size bytes.
151
+ *
152
+ * @dest - destination buffer, @dest_size bytes
153
+ * @src - source buffer, @src_size bytes
154
+ *
155
+ * Returns: 0 on success
156
+ * -1 on fail
157
+ */
158
+static ssize_t qcow2_decompress(void *dest, size_t dest_size,
159
+ const void *src, size_t src_size)
160
+{
161
+ int ret = 0;
162
+ z_stream strm;
163
+
164
+ memset(&strm, 0, sizeof(strm));
165
+ strm.avail_in = src_size;
166
+ strm.next_in = (void *) src;
167
+ strm.avail_out = dest_size;
168
+ strm.next_out = dest;
169
+
170
+ ret = inflateInit2(&strm, -12);
171
+ if (ret != Z_OK) {
172
+ return -1;
173
+ }
174
+
175
+ ret = inflate(&strm, Z_FINISH);
176
+ if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
177
+ /*
178
+ * We approve Z_BUF_ERROR because we need @dest buffer to be filled, but
179
+ * @src buffer may be processed partly (because in qcow2 we know size of
180
+ * compressed data with precision of one sector)
181
+ */
182
+ ret = -1;
183
+ }
184
+
185
+ inflateEnd(&strm);
186
+
187
+ return ret;
188
+}
189
+
190
+static int qcow2_compress_pool_func(void *opaque)
191
+{
192
+ Qcow2CompressData *data = opaque;
193
+
194
+ data->ret = data->func(data->dest, data->dest_size,
195
+ data->src, data->src_size);
196
+
197
+ return 0;
198
+}
199
+
200
+static void qcow2_compress_complete(void *opaque, int ret)
201
+{
202
+ qemu_coroutine_enter(opaque);
203
+}
204
+
205
+static ssize_t coroutine_fn
206
+qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
207
+ const void *src, size_t src_size, Qcow2CompressFunc func)
208
+{
209
+ BDRVQcow2State *s = bs->opaque;
210
+ BlockAIOCB *acb;
211
+ ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
212
+ Qcow2CompressData arg = {
213
+ .dest = dest,
214
+ .dest_size = dest_size,
215
+ .src = src,
216
+ .src_size = src_size,
217
+ .func = func,
218
+ };
219
+
220
+ while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
221
+ qemu_co_queue_wait(&s->compress_wait_queue, NULL);
222
+ }
223
+
224
+ s->nb_compress_threads++;
225
+ acb = thread_pool_submit_aio(pool, qcow2_compress_pool_func, &arg,
226
+ qcow2_compress_complete,
227
+ qemu_coroutine_self());
228
+
229
+ if (!acb) {
230
+ s->nb_compress_threads--;
231
+ return -EINVAL;
232
+ }
233
+ qemu_coroutine_yield();
234
+ s->nb_compress_threads--;
235
+ qemu_co_queue_next(&s->compress_wait_queue);
236
+
237
+ return arg.ret;
238
+}
239
+
240
+ssize_t coroutine_fn
241
+qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
242
+ const void *src, size_t src_size)
243
+{
244
+ return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
245
+ qcow2_compress);
246
+}
247
+
248
+ssize_t coroutine_fn
249
+qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
250
+ const void *src, size_t src_size)
251
+{
252
+ return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
253
+ qcow2_decompress);
254
+}
255
diff --git a/block/qcow2.c b/block/qcow2.c
256
index XXXXXXX..XXXXXXX 100644
257
--- a/block/qcow2.c
258
+++ b/block/qcow2.c
259
@@ -XXX,XX +XXX,XX @@
260
261
#include "qemu/osdep.h"
262
263
-#define ZLIB_CONST
264
-#include <zlib.h>
265
-
266
#include "block/qdict.h"
267
#include "sysemu/block-backend.h"
268
#include "qemu/module.h"
269
@@ -XXX,XX +XXX,XX @@
270
#include "qapi/qobject-input-visitor.h"
271
#include "qapi/qapi-visit-block-core.h"
272
#include "crypto.h"
273
-#include "block/thread-pool.h"
274
275
/*
276
Differences with QCOW:
277
@@ -XXX,XX +XXX,XX @@ fail:
278
return ret;
279
}
208
}
280
209
281
-/*
210
# get standard environment, filters and checks
282
- * qcow2_compress()
211
@@ -XXX,XX +XXX,XX @@ size=$((1 * 1024 * 1024))
283
- *
212
touch "$TEST_DIR/empty"
284
- * @dest - destination buffer, @dest_size bytes
213
extra_blocks=$(stat -c '%b' "$TEST_DIR/empty")
285
- * @src - source buffer, @src_size bytes
214
286
- *
215
+# We always write the first byte; check how many blocks this filesystem
287
- * Returns: compressed size on success
216
+# allocates to match empty image alloation.
288
- * -ENOMEM destination buffer is not enough to store compressed data
217
+printf "\0" > "$TEST_DIR/empty"
289
- * -EIO on any other error
218
+min_blocks=$(stat -c '%b' "$TEST_DIR/empty")
290
- */
219
+
291
-static ssize_t qcow2_compress(void *dest, size_t dest_size,
220
echo
292
- const void *src, size_t src_size)
221
echo "== creating image with default preallocation =="
293
-{
222
_make_test_img $size | _filter_imgfmt
294
- ssize_t ret;
223
-stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
295
- z_stream strm;
224
+stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
296
-
225
297
- /* best compression, small window, no zlib header */
226
for mode in off full falloc; do
298
- memset(&strm, 0, sizeof(strm));
227
echo
299
- ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
228
echo "== creating image with preallocation $mode =="
300
- -12, 9, Z_DEFAULT_STRATEGY);
229
IMGOPTS=preallocation=$mode _make_test_img $size | _filter_imgfmt
301
- if (ret != Z_OK) {
230
- stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $size
302
- return -EIO;
231
+ stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
303
- }
232
done
304
-
233
305
- /* strm.next_in is not const in old zlib versions, such as those used on
234
# success, all done
306
- * OpenBSD/NetBSD, so cast the const away */
235
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
307
- strm.avail_in = src_size;
236
index XXXXXXX..XXXXXXX 100644
308
- strm.next_in = (void *) src;
237
--- a/tests/qemu-iotests/175.out
309
- strm.avail_out = dest_size;
238
+++ b/tests/qemu-iotests/175.out
310
- strm.next_out = dest;
239
@@ -XXX,XX +XXX,XX @@ QA output created by 175
311
-
240
312
- ret = deflate(&strm, Z_FINISH);
241
== creating image with default preallocation ==
313
- if (ret == Z_STREAM_END) {
242
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
314
- ret = dest_size - strm.avail_out;
243
-size=1048576, nothing allocated
315
- } else {
244
+size=1048576, min allocation
316
- ret = (ret == Z_OK ? -ENOMEM : -EIO);
245
317
- }
246
== creating image with preallocation off ==
318
-
247
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off
319
- deflateEnd(&strm);
248
-size=1048576, nothing allocated
320
-
249
+size=1048576, min allocation
321
- return ret;
250
322
-}
251
== creating image with preallocation full ==
323
-
252
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full
324
-/*
253
-size=1048576, everything allocated
325
- * qcow2_decompress()
254
+size=1048576, max allocation
326
- *
255
327
- * Decompress some data (not more than @src_size bytes) to produce exactly
256
== creating image with preallocation falloc ==
328
- * @dest_size bytes.
257
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
329
- *
258
-size=1048576, everything allocated
330
- * @dest - destination buffer, @dest_size bytes
259
+size=1048576, max allocation
331
- * @src - source buffer, @src_size bytes
260
*** done
332
- *
261
diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2
333
- * Returns: 0 on success
262
index XXXXXXX..XXXXXXX 100644
334
- * -1 on fail
263
--- a/tests/qemu-iotests/178.out.qcow2
335
- */
264
+++ b/tests/qemu-iotests/178.out.qcow2
336
-static ssize_t qcow2_decompress(void *dest, size_t dest_size,
265
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
337
- const void *src, size_t src_size)
266
== raw input image with data (human) ==
338
-{
267
339
- int ret = 0;
268
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
340
- z_stream strm;
269
-required size: 393216
341
-
270
+required size: 458752
342
- memset(&strm, 0, sizeof(strm));
271
fully allocated size: 1074135040
343
- strm.avail_in = src_size;
272
wrote 512/512 bytes at offset 512
344
- strm.next_in = (void *) src;
273
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
345
- strm.avail_out = dest_size;
274
@@ -XXX,XX +XXX,XX @@ converted image file size in bytes: 196608
346
- strm.next_out = dest;
275
347
-
276
Formatting 'TEST_DIR/t.qcow2', fmt=IMGFMT size=1073741824
348
- ret = inflateInit2(&strm, -12);
277
{
349
- if (ret != Z_OK) {
278
- "required": 393216,
350
- return -1;
279
+ "required": 458752,
351
- }
280
"fully-allocated": 1074135040
352
-
281
}
353
- ret = inflate(&strm, Z_FINISH);
282
wrote 512/512 bytes at offset 512
354
- if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) {
283
diff --git a/tests/qemu-iotests/221.out b/tests/qemu-iotests/221.out
355
- /* We approve Z_BUF_ERROR because we need @dest buffer to be filled, but
284
index XXXXXXX..XXXXXXX 100644
356
- * @src buffer may be processed partly (because in qcow2 we know size of
285
--- a/tests/qemu-iotests/221.out
357
- * compressed data with precision of one sector) */
286
+++ b/tests/qemu-iotests/221.out
358
- ret = -1;
287
@@ -XXX,XX +XXX,XX @@ QA output created by 221
359
- }
288
=== Check mapping of unaligned raw image ===
360
-
289
361
- inflateEnd(&strm);
290
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65537
362
-
291
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
363
- return ret;
292
-[{ "start": 0, "length": 66048, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
364
-}
293
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
365
-
294
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
366
-#define MAX_COMPRESS_THREADS 4
295
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
367
-
296
+{ "start": 4096, "length": 61952, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
368
-typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size,
297
wrote 1/1 bytes at offset 65536
369
- const void *src, size_t src_size);
298
1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
370
-typedef struct Qcow2CompressData {
299
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
371
- void *dest;
300
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
372
- size_t dest_size;
301
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
373
- const void *src;
302
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
374
- size_t src_size;
303
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
375
- ssize_t ret;
304
-[{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
376
-
305
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
377
- Qcow2CompressFunc func;
306
+{ "start": 4096, "length": 61440, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
378
-} Qcow2CompressData;
307
{ "start": 65536, "length": 1, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
379
-
308
{ "start": 65537, "length": 511, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
380
-static int qcow2_compress_pool_func(void *opaque)
309
*** done
381
-{
310
diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out
382
- Qcow2CompressData *data = opaque;
311
index XXXXXXX..XXXXXXX 100644
383
-
312
--- a/tests/qemu-iotests/253.out
384
- data->ret = data->func(data->dest, data->dest_size,
313
+++ b/tests/qemu-iotests/253.out
385
- data->src, data->src_size);
314
@@ -XXX,XX +XXX,XX @@ QA output created by 253
386
-
315
=== Check mapping of unaligned raw image ===
387
- return 0;
316
388
-}
317
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575
389
-
318
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
390
-static void qcow2_compress_complete(void *opaque, int ret)
319
-[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
391
-{
320
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
392
- qemu_coroutine_enter(opaque);
321
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
393
-}
322
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
394
-
323
+{ "start": 4096, "length": 1044480, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
395
-static ssize_t coroutine_fn
324
wrote 65535/65535 bytes at offset 983040
396
-qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
325
63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
397
- const void *src, size_t src_size, Qcow2CompressFunc func)
326
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
398
-{
327
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
399
- BDRVQcow2State *s = bs->opaque;
328
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
400
- BlockAIOCB *acb;
329
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
401
- ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
330
-[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
402
- Qcow2CompressData arg = {
331
+[{ "start": 0, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
403
- .dest = dest,
332
+{ "start": 4096, "length": 978944, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
404
- .dest_size = dest_size,
333
{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
405
- .src = src,
334
*** done
406
- .src_size = src_size,
407
- .func = func,
408
- };
409
-
410
- while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
411
- qemu_co_queue_wait(&s->compress_wait_queue, NULL);
412
- }
413
-
414
- s->nb_compress_threads++;
415
- acb = thread_pool_submit_aio(pool, qcow2_compress_pool_func, &arg,
416
- qcow2_compress_complete,
417
- qemu_coroutine_self());
418
-
419
- if (!acb) {
420
- s->nb_compress_threads--;
421
- return -EINVAL;
422
- }
423
- qemu_coroutine_yield();
424
- s->nb_compress_threads--;
425
- qemu_co_queue_next(&s->compress_wait_queue);
426
-
427
- return arg.ret;
428
-}
429
-
430
-static ssize_t coroutine_fn
431
-qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
432
- const void *src, size_t src_size)
433
-{
434
- return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
435
- qcow2_compress);
436
-}
437
-
438
-static ssize_t coroutine_fn
439
-qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
440
- const void *src, size_t src_size)
441
-{
442
- return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
443
- qcow2_decompress);
444
-}
445
-
446
/* XXX: put compressed sectors first, then all the cluster aligned
447
tables to avoid losing bytes in alignment */
448
static coroutine_fn int
449
--
335
--
450
2.21.0
336
2.21.0
451
337
452
338
diff view generated by jsdifflib
Deleted patch
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
1
3
Use thread_pool_submit_co, instead of reinventing it here. Note, that
4
thread_pool_submit_aio() never returns NULL, so checking it was an
5
extra thing.
6
7
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: Alberto Garcia <berto@igalia.com>
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Message-id: 20190506142741.41731-4-vsementsov@virtuozzo.com
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
block/qcow2-threads.c | 17 ++---------------
14
1 file changed, 2 insertions(+), 15 deletions(-)
15
16
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-threads.c
19
+++ b/block/qcow2-threads.c
20
@@ -XXX,XX +XXX,XX @@ static int qcow2_compress_pool_func(void *opaque)
21
return 0;
22
}
23
24
-static void qcow2_compress_complete(void *opaque, int ret)
25
-{
26
- qemu_coroutine_enter(opaque);
27
-}
28
-
29
static ssize_t coroutine_fn
30
qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
31
const void *src, size_t src_size, Qcow2CompressFunc func)
32
{
33
BDRVQcow2State *s = bs->opaque;
34
- BlockAIOCB *acb;
35
ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
36
Qcow2CompressData arg = {
37
.dest = dest,
38
@@ -XXX,XX +XXX,XX @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
39
}
40
41
s->nb_compress_threads++;
42
- acb = thread_pool_submit_aio(pool, qcow2_compress_pool_func, &arg,
43
- qcow2_compress_complete,
44
- qemu_coroutine_self());
45
-
46
- if (!acb) {
47
- s->nb_compress_threads--;
48
- return -EINVAL;
49
- }
50
- qemu_coroutine_yield();
51
+ thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
52
s->nb_compress_threads--;
53
+
54
qemu_co_queue_next(&s->compress_wait_queue);
55
56
return arg.ret;
57
--
58
2.21.0
59
60
diff view generated by jsdifflib
Deleted patch
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
1
3
Drop dependence on AioContext lock.
4
5
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Reviewed-by: Alberto Garcia <berto@igalia.com>
7
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190506142741.41731-5-vsementsov@virtuozzo.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/qcow2-threads.c | 10 +++++++---
13
1 file changed, 7 insertions(+), 3 deletions(-)
14
15
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/qcow2-threads.c
18
+++ b/block/qcow2-threads.c
19
@@ -XXX,XX +XXX,XX @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
20
.func = func,
21
};
22
23
+ qemu_co_mutex_lock(&s->lock);
24
while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
25
- qemu_co_queue_wait(&s->compress_wait_queue, NULL);
26
+ qemu_co_queue_wait(&s->compress_wait_queue, &s->lock);
27
}
28
-
29
s->nb_compress_threads++;
30
+ qemu_co_mutex_unlock(&s->lock);
31
+
32
thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
33
- s->nb_compress_threads--;
34
35
+ qemu_co_mutex_lock(&s->lock);
36
+ s->nb_compress_threads--;
37
qemu_co_queue_next(&s->compress_wait_queue);
38
+ qemu_co_mutex_unlock(&s->lock);
39
40
return arg.ret;
41
}
42
--
43
2.21.0
44
45
diff view generated by jsdifflib
1
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
1
From: Nir Soffer <nirsof@gmail.com>
2
2
3
If COW areas of the newly allocated clusters are zeroes on the backing
3
Using block_resize we can test allocate_first_block() with file
4
image, efficient bdrv_write_zeroes(flags=BDRV_REQ_NO_FALLBACK) can be
4
descriptor opened with O_DIRECT, ensuring that it works for any size
5
used on the whole cluster instead of writing explicit zero buffers later
5
larger than 4096 bytes.
6
in perform_cow().
7
6
8
iotest 060:
7
Testing smaller sizes is tricky as the result depends on the filesystem
9
write to the discarded cluster does not trigger COW anymore.
8
used for testing. For example on NFS any size will work since O_DIRECT
10
Use a backing image instead.
9
does not require any alignment.
11
10
12
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
11
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
13
Message-id: 20190516142749.81019-2-anton.nefedov@virtuozzo.com
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
14
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
Message-id: 20190827010528.8818-3-nsoffer@redhat.com
15
Reviewed-by: Alberto Garcia <berto@igalia.com>
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
15
---
18
qapi/block-core.json | 4 +-
16
tests/qemu-iotests/175 | 28 ++++++++++++++++++++++++++++
19
block/qcow2.h | 6 +++
17
tests/qemu-iotests/175.out | 8 ++++++++
20
block/qcow2-cluster.c | 2 +-
18
2 files changed, 36 insertions(+)
21
block/qcow2.c | 85 ++++++++++++++++++++++++++++++++++++++
22
block/trace-events | 1 +
23
tests/qemu-iotests/060 | 7 +++-
24
tests/qemu-iotests/060.out | 5 ++-
25
7 files changed, 106 insertions(+), 4 deletions(-)
26
19
27
diff --git a/qapi/block-core.json b/qapi/block-core.json
20
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
28
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100755
29
--- a/qapi/block-core.json
22
--- a/tests/qemu-iotests/175
30
+++ b/qapi/block-core.json
23
+++ b/tests/qemu-iotests/175
31
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@ _filter_blocks()
32
#
25
-e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
33
# @cor_write: a write due to copy-on-read (since 2.11)
26
}
34
#
27
35
+# @cluster_alloc_space: an allocation of file space for a cluster (since 4.1)
28
+# Resize image using block_resize.
36
+#
29
+# Parameter 1: image path
37
# Since: 2.9
30
+# Parameter 2: new size
38
##
31
+_block_resize()
39
{ 'enum': 'BlkdebugEvent', 'prefix': 'BLKDBG',
32
+{
40
@@ -XXX,XX +XXX,XX @@
33
+ local path=$1
41
'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev',
34
+ local size=$2
42
'pwritev_zero', 'pwritev_done', 'empty_image_prepare',
43
'l1_shrink_write_table', 'l1_shrink_free_l2_clusters',
44
- 'cor_write'] }
45
+ 'cor_write', 'cluster_alloc_space'] }
46
47
##
48
# @BlkdebugInjectErrorOptions:
49
diff --git a/block/qcow2.h b/block/qcow2.h
50
index XXXXXXX..XXXXXXX 100644
51
--- a/block/qcow2.h
52
+++ b/block/qcow2.h
53
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
54
*/
55
Qcow2COWRegion cow_end;
56
57
+ /*
58
+ * Indicates that COW regions are already handled and do not require
59
+ * any more processing.
60
+ */
61
+ bool skip_cow;
62
+
35
+
63
/**
36
+ $QEMU -qmp stdio -nographic -nodefaults \
64
* The I/O vector with the data from the actual guest write request.
37
+ -blockdev file,node-name=file,filename=$path,cache.direct=on \
65
* If non-NULL, this is meant to be merged together with the data
38
+ <<EOF
66
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
39
+{'execute': 'qmp_capabilities'}
67
index XXXXXXX..XXXXXXX 100644
40
+{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}}
68
--- a/block/qcow2-cluster.c
41
+{'execute': 'quit'}
69
+++ b/block/qcow2-cluster.c
42
+EOF
70
@@ -XXX,XX +XXX,XX @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m)
71
assert(start->offset + start->nb_bytes <= end->offset);
72
assert(!m->data_qiov || m->data_qiov->size == data_bytes);
73
74
- if (start->nb_bytes == 0 && end->nb_bytes == 0) {
75
+ if ((start->nb_bytes == 0 && end->nb_bytes == 0) || m->skip_cow) {
76
return 0;
77
}
78
79
diff --git a/block/qcow2.c b/block/qcow2.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/block/qcow2.c
82
+++ b/block/qcow2.c
83
@@ -XXX,XX +XXX,XX @@ static bool merge_cow(uint64_t offset, unsigned bytes,
84
continue;
85
}
86
87
+ /* If COW regions are handled already, skip this too */
88
+ if (m->skip_cow) {
89
+ continue;
90
+ }
91
+
92
/* The data (middle) region must be immediately after the
93
* start region */
94
if (l2meta_cow_start(m) + m->cow_start.nb_bytes != offset) {
95
@@ -XXX,XX +XXX,XX @@ static bool merge_cow(uint64_t offset, unsigned bytes,
96
return false;
97
}
98
99
+static bool is_unallocated(BlockDriverState *bs, int64_t offset, int64_t bytes)
100
+{
101
+ int64_t nr;
102
+ return !bytes ||
103
+ (!bdrv_is_allocated_above(bs, NULL, offset, bytes, &nr) && nr == bytes);
104
+}
43
+}
105
+
44
+
106
+static bool is_zero_cow(BlockDriverState *bs, QCowL2Meta *m)
45
# get standard environment, filters and checks
107
+{
46
. ./common.rc
108
+ /*
47
. ./common.filter
109
+ * This check is designed for optimization shortcut so it must be
48
@@ -XXX,XX +XXX,XX @@ _supported_fmt raw
110
+ * efficient.
49
_supported_proto file
111
+ * Instead of is_zero(), use is_unallocated() as it is faster (but not
50
_supported_os Linux
112
+ * as accurate and can result in false negatives).
51
113
+ */
52
+_default_cache_mode none
114
+ return is_unallocated(bs, m->offset + m->cow_start.offset,
53
+_supported_cache_modes none directsync
115
+ m->cow_start.nb_bytes) &&
116
+ is_unallocated(bs, m->offset + m->cow_end.offset,
117
+ m->cow_end.nb_bytes);
118
+}
119
+
54
+
120
+static int handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta)
55
size=$((1 * 1024 * 1024))
121
+{
56
122
+ BDRVQcow2State *s = bs->opaque;
57
touch "$TEST_DIR/empty"
123
+ QCowL2Meta *m;
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
124
+
69
+
125
+ if (!(s->data_file->bs->supported_zero_flags & BDRV_REQ_NO_FALLBACK)) {
70
# success, all done
126
+ return 0;
71
echo "*** done"
127
+ }
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
128
+
81
+
129
+ if (bs->encrypted) {
82
+== resize empty image with block_resize ==
130
+ return 0;
83
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
131
+ }
84
+size=4096, min allocation
132
+
85
+
133
+ for (m = l2meta; m != NULL; m = m->next) {
86
+== resize empty image with block_resize ==
134
+ int ret;
87
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
135
+
88
+size=1048576, min allocation
136
+ if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) {
89
*** done
137
+ continue;
138
+ }
139
+
140
+ if (!is_zero_cow(bs, m)) {
141
+ continue;
142
+ }
143
+
144
+ /*
145
+ * instead of writing zero COW buffers,
146
+ * efficiently zero out the whole clusters
147
+ */
148
+
149
+ ret = qcow2_pre_write_overlap_check(bs, 0, m->alloc_offset,
150
+ m->nb_clusters * s->cluster_size,
151
+ true);
152
+ if (ret < 0) {
153
+ return ret;
154
+ }
155
+
156
+ BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC_SPACE);
157
+ ret = bdrv_co_pwrite_zeroes(s->data_file, m->alloc_offset,
158
+ m->nb_clusters * s->cluster_size,
159
+ BDRV_REQ_NO_FALLBACK);
160
+ if (ret < 0) {
161
+ if (ret != -ENOTSUP && ret != -EAGAIN) {
162
+ return ret;
163
+ }
164
+ continue;
165
+ }
166
+
167
+ trace_qcow2_skip_cow(qemu_coroutine_self(), m->offset, m->nb_clusters);
168
+ m->skip_cow = true;
169
+ }
170
+ return 0;
171
+}
172
+
173
static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
174
uint64_t bytes, QEMUIOVector *qiov,
175
int flags)
176
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
177
qemu_iovec_add(&hd_qiov, cluster_data, cur_bytes);
178
}
179
180
+ /* Try to efficiently initialize the physical space with zeroes */
181
+ ret = handle_alloc_space(bs, l2meta);
182
+ if (ret < 0) {
183
+ goto out_unlocked;
184
+ }
185
+
186
/* If we need to do COW, check if it's possible to merge the
187
* writing of the guest data together with that of the COW regions.
188
* If it's not possible (or not necessary) then write the
189
diff --git a/block/trace-events b/block/trace-events
190
index XXXXXXX..XXXXXXX 100644
191
--- a/block/trace-events
192
+++ b/block/trace-events
193
@@ -XXX,XX +XXX,XX @@ qcow2_writev_done_part(void *co, int cur_bytes) "co %p cur_bytes %d"
194
qcow2_writev_data(void *co, uint64_t offset) "co %p offset 0x%" PRIx64
195
qcow2_pwrite_zeroes_start_req(void *co, int64_t offset, int count) "co %p offset 0x%" PRIx64 " count %d"
196
qcow2_pwrite_zeroes(void *co, int64_t offset, int count) "co %p offset 0x%" PRIx64 " count %d"
197
+qcow2_skip_cow(void *co, uint64_t offset, int nb_clusters) "co %p offset 0x%" PRIx64 " nb_clusters %d"
198
199
# qcow2-cluster.c
200
qcow2_alloc_clusters_offset(void *co, uint64_t offset, int bytes) "co %p offset 0x%" PRIx64 " bytes %d"
201
diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060
202
index XXXXXXX..XXXXXXX 100755
203
--- a/tests/qemu-iotests/060
204
+++ b/tests/qemu-iotests/060
205
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "$OPEN_RO" -c "read -P 1 0 512" | _filter_qemu_io
206
echo
207
echo "=== Testing overlap while COW is in flight ==="
208
echo
209
+BACKING_IMG=$TEST_IMG.base
210
+TEST_IMG=$BACKING_IMG _make_test_img 1G
211
+
212
+$QEMU_IO -c 'write 0k 64k' "$BACKING_IMG" | _filter_qemu_io
213
+
214
# compat=0.10 is required in order to make the following discard actually
215
# unallocate the sector rather than make it a zero sector - we want COW, after
216
# all.
217
-IMGOPTS='compat=0.10' _make_test_img 1G
218
+IMGOPTS='compat=0.10' _make_test_img -b "$BACKING_IMG" 1G
219
# Write two clusters, the second one enforces creation of an L2 table after
220
# the first data cluster.
221
$QEMU_IO -c 'write 0k 64k' -c 'write 512M 64k' "$TEST_IMG" | _filter_qemu_io
222
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
223
index XXXXXXX..XXXXXXX 100644
224
--- a/tests/qemu-iotests/060.out
225
+++ b/tests/qemu-iotests/060.out
226
@@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 0
227
228
=== Testing overlap while COW is in flight ===
229
230
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824
231
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=1073741824
232
+wrote 65536/65536 bytes at offset 0
233
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
234
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824 backing_file=TEST_DIR/t.IMGFMT.base
235
wrote 65536/65536 bytes at offset 0
236
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
237
wrote 65536/65536 bytes at offset 536870912
238
--
90
--
239
2.21.0
91
2.21.0
240
92
241
93
diff view generated by jsdifflib
1
From: John Snow <jsnow@redhat.com>
1
fe646693acc changed qemu-img create's output so that it no longer prints
2
single quotes around parameter values. The subformat and adapter_type
3
filters in _filter_img_create() have never been adapted to that change.
2
4
3
We mandate that the source node must be a root node; but there's no reason
5
Fixes: fe646693acc13ac48b98435d14149ab04dc597bc
4
I am aware of that it needs to be restricted to such. In some cases, we need
6
Signed-off-by: Max Reitz <mreitz@redhat.com>
5
to make sure that there's a medium present, but in the general case we can
7
Reviewed-by: John Snow <jsnow@redhat.com>
6
allow the backup job itself to do the graph checking.
8
Message-id: 20190815153638.4600-2-mreitz@redhat.com
7
9
Reviewed-by: John Snow <jsnow@redhat.com>
8
This patch helps improve the error message when you try to backup from
9
the same node more than once, which is reflected in the change to test
10
056.
11
12
For backups with bitmaps, it will also show a better error message that
13
the bitmap is in use instead of giving you something cryptic like "need
14
a root node."
15
16
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1707303
17
Signed-off-by: John Snow <jsnow@redhat.com>
18
Message-id: 20190521210053.8864-1-jsnow@redhat.com
19
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
20
---
11
---
21
blockdev.c | 7 ++++++-
12
tests/qemu-iotests/059.out | 16 ++++++++--------
22
tests/qemu-iotests/056 | 2 +-
13
tests/qemu-iotests/common.filter | 4 ++--
23
2 files changed, 7 insertions(+), 2 deletions(-)
14
2 files changed, 10 insertions(+), 10 deletions(-)
24
15
25
diff --git a/blockdev.c b/blockdev.c
16
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
26
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
27
--- a/blockdev.c
18
--- a/tests/qemu-iotests/059.out
28
+++ b/blockdev.c
19
+++ b/tests/qemu-iotests/059.out
29
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
20
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
30
backup->compress = false;
21
qemu-io: can't open device TEST_DIR/t.vmdk: L1 size too big
31
}
22
32
23
=== Testing monolithicFlat creation and opening ===
33
- bs = qmp_get_root_bs(backup->device, errp);
24
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
34
+ bs = bdrv_lookup_bs(backup->device, backup->device, errp);
25
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
35
if (!bs) {
26
image: TEST_DIR/t.IMGFMT
36
return NULL;
27
file format: IMGFMT
37
}
28
virtual size: 2 GiB (2147483648 bytes)
38
29
39
+ if (!bs->drv) {
30
=== Testing monolithicFlat with zeroed_grain ===
40
+ error_setg(errp, "Device has no medium");
31
qemu-img: TEST_DIR/t.IMGFMT: Flat image can't enable zeroed grain
41
+ return NULL;
32
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648 subformat=monolithicFlat
42
+ }
33
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=2147483648
43
+
34
44
aio_context = bdrv_get_aio_context(bs);
35
=== Testing big twoGbMaxExtentFlat ===
45
aio_context_acquire(aio_context);
36
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000 subformat=twoGbMaxExtentFlat
46
37
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1073741824000
47
diff --git a/tests/qemu-iotests/056 b/tests/qemu-iotests/056
38
image: TEST_DIR/t.vmdk
48
index XXXXXXX..XXXXXXX 100755
39
file format: vmdk
49
--- a/tests/qemu-iotests/056
40
virtual size: 0.977 TiB (1073741824000 bytes)
50
+++ b/tests/qemu-iotests/056
41
@@ -XXX,XX +XXX,XX @@ Format specific information:
51
@@ -XXX,XX +XXX,XX @@ class BackupTest(iotests.QMPTestCase):
42
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912 VMFS "dummy.IMGFMT" 1
52
res = self.vm.qmp('query-block-jobs')
43
53
self.assert_qmp(res, 'return[0]/status', 'concluded')
44
=== Testing truncated sparse ===
54
# Leave zombie job un-dismissed, observe a failure:
45
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400 subformat=monolithicSparse
55
- res = self.qmp_backup_and_wait(serror='Need a root block node',
46
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
56
+ res = self.qmp_backup_and_wait(serror="Node 'drive0' is busy: block device is in use by block job: backup",
47
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': File truncated, expecting at least 13172736 bytes
57
device='drive0', format=iotests.imgfmt,
48
58
sync='full', target=self.dest_img,
49
=== Converting to streamOptimized from image with small cluster size===
59
auto_dismiss=False)
50
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
51
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
52
53
=== Testing monolithicFlat with internally generated JSON file name ===
54
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 subformat=monolithicFlat
55
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
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"}'
57
58
=== Testing version 3 ===
59
@@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 64931328
60
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
61
62
=== Testing 4TB monolithicFlat creation and IO ===
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" \
60
--
101
--
61
2.21.0
102
2.21.0
62
103
63
104
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
This makes iotest 033 pass with e.g. subformat=monolithicFlat. It also
2
turns a former error in 059 into success.
2
3
3
We are going to share this bitmap between backup and backup-top filter
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
driver, so let's share something more meaningful. It also simplifies
5
Message-id: 20190815153638.4600-3-mreitz@redhat.com
5
some calculations.
6
Reviewed-by: John Snow <jsnow@redhat.com>
6
7
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190429090842.57910-3-vsementsov@virtuozzo.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
8
---
12
block/backup.c | 48 +++++++++++++++++++++++-------------------------
9
block/vmdk.c | 54 ++++++++++++++++++++++++--------------
13
1 file changed, 23 insertions(+), 25 deletions(-)
10
tests/qemu-iotests/059 | 7 +++--
11
tests/qemu-iotests/059.out | 4 ++-
12
3 files changed, 42 insertions(+), 23 deletions(-)
14
13
15
diff --git a/block/backup.c b/block/backup.c
14
diff --git a/block/vmdk.c b/block/vmdk.c
16
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
17
--- a/block/backup.c
16
--- a/block/vmdk.c
18
+++ b/block/backup.c
17
+++ b/block/vmdk.c
19
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
18
@@ -XXX,XX +XXX,XX @@ static const char *next_line(const char *s)
20
int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0;
21
int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
22
23
- hbitmap_reset(job->copy_bitmap, start / job->cluster_size, 1);
24
+ assert(QEMU_IS_ALIGNED(start, job->cluster_size));
25
+ hbitmap_reset(job->copy_bitmap, start, job->cluster_size);
26
nbytes = MIN(job->cluster_size, job->len - start);
27
if (!*bounce_buffer) {
28
*bounce_buffer = blk_blockalign(blk, job->cluster_size);
29
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
30
31
return nbytes;
32
fail:
33
- hbitmap_set(job->copy_bitmap, start / job->cluster_size, 1);
34
+ hbitmap_set(job->copy_bitmap, start, job->cluster_size);
35
return ret;
36
37
}
19
}
38
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job,
20
39
int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
21
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
40
22
- const char *desc_file_path, QDict *options,
41
assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size));
23
- Error **errp)
42
+ assert(QEMU_IS_ALIGNED(start, job->cluster_size));
24
+ QDict *options, Error **errp)
43
nbytes = MIN(job->copy_range_size, end - start);
44
nr_clusters = DIV_ROUND_UP(nbytes, job->cluster_size);
45
- hbitmap_reset(job->copy_bitmap, start / job->cluster_size,
46
- nr_clusters);
47
+ hbitmap_reset(job->copy_bitmap, start, job->cluster_size * nr_clusters);
48
ret = blk_co_copy_range(blk, start, job->target, start, nbytes,
49
read_flags, write_flags);
50
if (ret < 0) {
51
trace_backup_do_cow_copy_range_fail(job, start, ret);
52
- hbitmap_set(job->copy_bitmap, start / job->cluster_size,
53
- nr_clusters);
54
+ hbitmap_set(job->copy_bitmap, start, job->cluster_size * nr_clusters);
55
return ret;
56
}
57
58
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,
59
cow_request_begin(&cow_request, job, start, end);
60
61
while (start < end) {
62
- if (!hbitmap_get(job->copy_bitmap, start / job->cluster_size)) {
63
+ if (!hbitmap_get(job->copy_bitmap, start)) {
64
trace_backup_do_cow_skip(job, start);
65
start += job->cluster_size;
66
continue; /* already copied */
67
@@ -XXX,XX +XXX,XX @@ static void backup_clean(Job *job)
68
assert(s->target);
69
blk_unref(s->target);
70
s->target = NULL;
71
+
72
+ if (s->copy_bitmap) {
73
+ hbitmap_free(s->copy_bitmap);
74
+ s->copy_bitmap = NULL;
75
+ }
76
}
77
78
void backup_do_checkpoint(BlockJob *job, Error **errp)
79
{
80
BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
81
- int64_t len;
82
83
assert(block_job_driver(job) == &backup_job_driver);
84
85
@@ -XXX,XX +XXX,XX @@ void backup_do_checkpoint(BlockJob *job, Error **errp)
86
return;
87
}
88
89
- len = DIV_ROUND_UP(backup_job->len, backup_job->cluster_size);
90
- hbitmap_set(backup_job->copy_bitmap, 0, len);
91
+ hbitmap_set(backup_job->copy_bitmap, 0, backup_job->len);
92
}
93
94
static void backup_drain(BlockJob *job)
95
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
96
{
25
{
97
int ret;
26
int ret;
98
bool error_is_read;
27
int matches;
99
- int64_t cluster;
28
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
100
+ int64_t offset;
29
const char *p, *np;
101
HBitmapIter hbi;
30
int64_t sectors = 0;
102
31
int64_t flat_offset;
103
hbitmap_iter_init(&hbi, job->copy_bitmap, 0);
32
+ char *desc_file_dir = NULL;
104
- while ((cluster = hbitmap_iter_next(&hbi)) != -1) {
33
char *extent_path;
105
+ while ((offset = hbitmap_iter_next(&hbi)) != -1) {
34
BdrvChild *extent_file;
106
do {
35
BDRVVmdkState *s = bs->opaque;
107
if (yield_and_check(job)) {
36
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
108
return 0;
37
continue;
38
}
39
40
- if (!path_is_absolute(fname) && !path_has_protocol(fname) &&
41
- !desc_file_path[0])
42
- {
43
- bdrv_refresh_filename(bs->file->bs);
44
- error_setg(errp, "Cannot use relative extent paths with VMDK "
45
- "descriptor file '%s'", bs->file->bs->filename);
46
- return -EINVAL;
47
- }
48
+ if (path_is_absolute(fname)) {
49
+ extent_path = g_strdup(fname);
50
+ } else {
51
+ if (!desc_file_dir) {
52
+ desc_file_dir = bdrv_dirname(bs->file->bs, errp);
53
+ if (!desc_file_dir) {
54
+ bdrv_refresh_filename(bs->file->bs);
55
+ error_prepend(errp, "Cannot use relative paths with VMDK "
56
+ "descriptor file '%s': ",
57
+ bs->file->bs->filename);
58
+ ret = -EINVAL;
59
+ goto out;
60
+ }
61
+ }
62
63
- extent_path = path_combine(desc_file_path, fname);
64
+ extent_path = g_strconcat(desc_file_dir, fname, NULL);
65
+ }
66
67
ret = snprintf(extent_opt_prefix, 32, "extents.%d", s->num_extents);
68
assert(ret < 32);
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;
109
}
85
}
110
- ret = backup_do_cow(job, cluster * job->cluster_size,
86
extent->flat_start_offset = flat_offset << 9;
111
+ ret = backup_do_cow(job, offset,
87
} else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {
112
job->cluster_size, &error_is_read, false);
88
@@ -XXX,XX +XXX,XX @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
113
if (ret < 0 && backup_error_action(job, error_is_read, -ret) ==
89
g_free(buf);
114
BLOCK_ERROR_ACTION_REPORT)
90
if (ret) {
115
@@ -XXX,XX +XXX,XX @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
91
bdrv_unref_child(bs, extent_file);
116
while (bdrv_dirty_bitmap_next_dirty_area(job->sync_bitmap,
92
- return ret;
117
&offset, &bytes))
93
+ goto out;
118
{
94
}
119
- uint64_t cluster = offset / job->cluster_size;
95
extent = &s->extents[s->num_extents - 1];
120
- uint64_t end_cluster = DIV_ROUND_UP(offset + bytes, job->cluster_size);
96
} else if (!strcmp(type, "SESPARSE")) {
121
+ hbitmap_set(job->copy_bitmap, offset, bytes);
97
ret = vmdk_open_se_sparse(bs, extent_file, bs->open_flags, errp);
122
98
if (ret) {
123
- hbitmap_set(job->copy_bitmap, cluster, end_cluster - cluster);
99
bdrv_unref_child(bs, extent_file);
124
-
100
- return ret;
125
- offset = end_cluster * job->cluster_size;
101
+ goto out;
126
+ offset += bytes;
102
}
127
if (offset >= job->len) {
103
extent = &s->extents[s->num_extents - 1];
128
break;
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;
129
}
110
}
130
@@ -XXX,XX +XXX,XX @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
111
extent->type = g_strdup(type);
131
112
}
132
/* TODO job_progress_set_remaining() would make more sense */
113
- return 0;
133
job_progress_update(&job->common.job,
114
+
134
- job->len - hbitmap_count(job->copy_bitmap) * job->cluster_size);
115
+ ret = 0;
135
+ job->len - hbitmap_count(job->copy_bitmap));
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;
136
}
130
}
137
131
138
static int coroutine_fn backup_run(Job *job, Error **errp)
132
static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
139
{
133
@@ -XXX,XX +XXX,XX @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
140
BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
141
BlockDriverState *bs = blk_bs(s->common.blk);
142
- int64_t offset, nb_clusters;
143
+ int64_t offset;
144
int ret = 0;
145
146
QLIST_INIT(&s->inflight_reqs);
147
qemu_co_rwlock_init(&s->flush_rwlock);
148
149
- nb_clusters = DIV_ROUND_UP(s->len, s->cluster_size);
150
job_progress_set_remaining(job, s->len);
151
152
- s->copy_bitmap = hbitmap_alloc(nb_clusters, 0);
153
if (s->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
154
backup_incremental_init_copy_bitmap(s);
155
} else {
156
- hbitmap_set(s->copy_bitmap, 0, nb_clusters);
157
+ hbitmap_set(s->copy_bitmap, 0, s->len);
158
}
134
}
159
135
s->create_type = g_strdup(ct);
160
-
136
s->desc_offset = 0;
161
s->before_write.notify = backup_before_write_notify;
137
- ret = vmdk_parse_extents(buf, bs, bs->file->bs->exact_filename, options,
162
bdrv_add_before_write_notifier(bs, &s->before_write);
138
- errp);
163
139
+ ret = vmdk_parse_extents(buf, bs, options, errp);
164
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
140
exit:
165
/* wait until pending backup_do_cow() calls have completed */
166
qemu_co_rwlock_wrlock(&s->flush_rwlock);
167
qemu_co_rwlock_unlock(&s->flush_rwlock);
168
- hbitmap_free(s->copy_bitmap);
169
170
return ret;
141
return ret;
171
}
142
}
172
@@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
143
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
173
} else {
144
index XXXXXXX..XXXXXXX 100755
174
job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
145
--- a/tests/qemu-iotests/059
175
}
146
+++ b/tests/qemu-iotests/059
176
+
147
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
177
+ job->copy_bitmap = hbitmap_alloc(len, ctz32(job->cluster_size));
148
178
job->use_copy_range = true;
149
echo
179
job->copy_range_size = MIN_NON_ZERO(blk_get_max_transfer(job->common.blk),
150
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
180
blk_get_max_transfer(job->target));
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
164
--- a/tests/qemu-iotests/059.out
165
+++ b/tests/qemu-iotests/059.out
166
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
167
168
=== Testing monolithicFlat with internally generated JSON file name ===
169
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
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"}'
171
+format name: IMGFMT
172
+cluster size: 0 bytes
173
+vm state offset: 0 bytes
174
175
=== Testing version 3 ===
176
image: TEST_DIR/iotest-version3.IMGFMT
181
--
177
--
182
2.21.0
178
2.21.0
183
179
184
180
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
We had a test for a case where relative extent paths did not work, but
2
unfortunately we just fixed the underlying problem, so it works now.
3
This patch adds a new test case that still fails.
2
4
3
Move generic part out of qcow2_co_do_compress, to reuse it for
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
encryption and rename things that would be shared with encryption path.
6
Reviewed-by: John Snow <jsnow@redhat.com>
5
7
Message-id: 20190815153638.4600-4-mreitz@redhat.com
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
7
Reviewed-by: Alberto Garcia <berto@igalia.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190506142741.41731-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
block/qcow2.h | 4 ++--
11
tests/qemu-iotests/059 | 27 +++++++++++++++++++++++++++
13
block/qcow2-threads.c | 47 ++++++++++++++++++++++++++++---------------
12
tests/qemu-iotests/059.out | 4 ++++
14
block/qcow2.c | 2 +-
13
2 files changed, 31 insertions(+)
15
3 files changed, 34 insertions(+), 19 deletions(-)
16
14
17
diff --git a/block/qcow2.h b/block/qcow2.h
15
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100755
19
--- a/block/qcow2.h
17
--- a/tests/qemu-iotests/059
20
+++ b/block/qcow2.h
18
+++ b/tests/qemu-iotests/059
21
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVQcow2State {
19
@@ -XXX,XX +XXX,XX @@ $QEMU_IMG convert -f qcow2 -O vmdk -o subformat=streamOptimized "$TEST_IMG.qcow2
22
char *image_backing_format;
20
23
char *image_data_file;
21
echo
24
22
echo "=== Testing monolithicFlat with internally generated JSON file name ==="
25
- CoQueue compress_wait_queue;
26
- int nb_compress_threads;
27
+ CoQueue thread_task_queue;
28
+ int nb_threads;
29
30
BdrvChild *data_file;
31
} BDRVQcow2State;
32
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/block/qcow2-threads.c
35
+++ b/block/qcow2-threads.c
36
@@ -XXX,XX +XXX,XX @@
37
#include "qcow2.h"
38
#include "block/thread-pool.h"
39
40
-#define MAX_COMPRESS_THREADS 4
41
+#define QCOW2_MAX_THREADS 4
42
+
23
+
43
+static int coroutine_fn
24
+echo '--- blkdebug ---'
44
+qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *func, void *arg)
25
# Should work, because bdrv_dirname() works fine with blkdebug
45
+{
26
IMGOPTS="subformat=monolithicFlat" _make_test_img 64M
46
+ int ret;
27
$QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TEST_IMG,file.inject-error.0.event=read_aio" \
47
+ BDRVQcow2State *s = bs->opaque;
28
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "open -o driver=$IMGFMT,file.driver=blkdebug,file.image.filename=$TE
48
+ ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
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"
49
+
36
+
50
+ qemu_co_mutex_lock(&s->lock);
37
+filename="json:{
51
+ while (s->nb_threads >= QCOW2_MAX_THREADS) {
38
+ \"driver\": \"$IMGFMT\",
52
+ qemu_co_queue_wait(&s->thread_task_queue, &s->lock);
39
+ \"file\": {
53
+ }
40
+ \"driver\": \"quorum\",
54
+ s->nb_threads++;
41
+ \"children\": [ {
55
+ qemu_co_mutex_unlock(&s->lock);
42
+ \"driver\": \"file\",
43
+ \"filename\": \"$TEST_IMG\"
44
+ }, {
45
+ \"driver\": \"file\",
46
+ \"filename\": \"$TEST_IMG.orig\"
47
+ } ],
48
+ \"vote-threshold\": 1
49
+ } }"
56
+
50
+
57
+ ret = thread_pool_submit_co(pool, func, arg);
51
+filename=$(echo "$filename" | tr '\n' ' ' | sed -e 's/\s\+/ /g')
58
+
52
+$QEMU_IMG info "$filename" 2>&1 \
59
+ qemu_co_mutex_lock(&s->lock);
53
+ | sed -e "s/'json:[^']*'/\$QUORUM_FILE/g" \
60
+ s->nb_threads--;
54
+ | _filter_testdir | _filter_imgfmt | _filter_img_info
61
+ qemu_co_queue_next(&s->thread_task_queue);
62
+ qemu_co_mutex_unlock(&s->lock);
63
+
64
+ return ret;
65
+}
66
+
55
+
67
+
56
+
68
+/*
57
echo
69
+ * Compression
58
echo "=== Testing version 3 ==="
70
+ */
59
_use_sample_img iotest-version3.vmdk.bz2
71
60
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
72
typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size,
73
const void *src, size_t src_size);
74
@@ -XXX,XX +XXX,XX @@ static ssize_t coroutine_fn
75
qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
76
const void *src, size_t src_size, Qcow2CompressFunc func)
77
{
78
- BDRVQcow2State *s = bs->opaque;
79
- ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
80
Qcow2CompressData arg = {
81
.dest = dest,
82
.dest_size = dest_size,
83
@@ -XXX,XX +XXX,XX @@ qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
84
.func = func,
85
};
86
87
- qemu_co_mutex_lock(&s->lock);
88
- while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
89
- qemu_co_queue_wait(&s->compress_wait_queue, &s->lock);
90
- }
91
- s->nb_compress_threads++;
92
- qemu_co_mutex_unlock(&s->lock);
93
-
94
- thread_pool_submit_co(pool, qcow2_compress_pool_func, &arg);
95
-
96
- qemu_co_mutex_lock(&s->lock);
97
- s->nb_compress_threads--;
98
- qemu_co_queue_next(&s->compress_wait_queue);
99
- qemu_co_mutex_unlock(&s->lock);
100
+ qcow2_co_process(bs, qcow2_compress_pool_func, &arg);
101
102
return arg.ret;
103
}
104
diff --git a/block/qcow2.c b/block/qcow2.c
105
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
106
--- a/block/qcow2.c
62
--- a/tests/qemu-iotests/059.out
107
+++ b/block/qcow2.c
63
+++ b/tests/qemu-iotests/059.out
108
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
64
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 10240
109
}
65
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
110
#endif
66
111
67
=== Testing monolithicFlat with internally generated JSON file name ===
112
- qemu_co_queue_init(&s->compress_wait_queue);
68
+--- blkdebug ---
113
+ qemu_co_queue_init(&s->thread_task_queue);
69
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
114
70
format name: IMGFMT
115
return ret;
71
cluster size: 0 bytes
116
72
vm state offset: 0 bytes
73
+--- quorum ---
74
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
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
76
77
=== Testing version 3 ===
78
image: TEST_DIR/iotest-version3.IMGFMT
117
--
79
--
118
2.21.0
80
2.21.0
119
81
120
82
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
Compressed writes generally have to write full clusters, not just in
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:
2
5
3
Do full, top and incremental mode copying all in one place. This
6
$ qemu-img create -f vmdk -o subformat=streamOptimized foo.vmdk 1M
4
unifies the code path and helps further improvements.
7
$ qemu-io -c 'write 4k 4k' -c 'read 4k 4k' foo.vmdk
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
5
11
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
12
(The technical reason is that vmdk_write_extent() just writes the
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
incomplete compressed data actually to offset 4k. When reading the
8
Message-id: 20190429090842.57910-5-vsementsov@virtuozzo.com
14
data, vmdk_read_extent() looks at offset 0 and finds the compressed data
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>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
38
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
---
39
---
11
block/backup.c | 43 ++++++++++---------------------------------
40
block/vmdk.c | 10 ++++++++++
12
1 file changed, 10 insertions(+), 33 deletions(-)
41
1 file changed, 10 insertions(+)
13
42
14
diff --git a/block/backup.c b/block/backup.c
43
diff --git a/block/vmdk.c b/block/vmdk.c
15
index XXXXXXX..XXXXXXX 100644
44
index XXXXXXX..XXXXXXX 100644
16
--- a/block/backup.c
45
--- a/block/vmdk.c
17
+++ b/block/backup.c
46
+++ b/block/vmdk.c
18
@@ -XXX,XX +XXX,XX @@ static bool bdrv_is_unallocated_range(BlockDriverState *bs,
47
@@ -XXX,XX +XXX,XX @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
19
return offset >= end;
48
if (extent->compressed) {
20
}
49
void *compressed_data;
21
50
22
-static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
51
+ /* Only whole clusters */
23
+static int coroutine_fn backup_loop(BackupBlockJob *job)
52
+ if (offset_in_cluster ||
24
{
53
+ n_bytes > (extent->cluster_sectors * SECTOR_SIZE) ||
25
int ret;
54
+ (n_bytes < (extent->cluster_sectors * SECTOR_SIZE) &&
26
bool error_is_read;
55
+ offset + n_bytes != extent->end_sector * SECTOR_SIZE))
27
int64_t offset;
28
HBitmapIter hbi;
29
+ BlockDriverState *bs = blk_bs(job->common.blk);
30
31
hbitmap_iter_init(&hbi, job->copy_bitmap, 0);
32
while ((offset = hbitmap_iter_next(&hbi)) != -1) {
33
+ if (job->sync_mode == MIRROR_SYNC_MODE_TOP &&
34
+ bdrv_is_unallocated_range(bs, offset, job->cluster_size))
35
+ {
56
+ {
36
+ hbitmap_reset(job->copy_bitmap, offset, job->cluster_size);
57
+ ret = -EINVAL;
37
+ continue;
58
+ goto out;
38
+ }
59
+ }
39
+
60
+
40
do {
61
if (!extent->has_marker) {
41
if (yield_and_check(job)) {
62
ret = -EINVAL;
42
return 0;
63
goto out;
43
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
44
{
45
BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
46
BlockDriverState *bs = blk_bs(s->common.blk);
47
- int64_t offset;
48
int ret = 0;
49
50
QLIST_INIT(&s->inflight_reqs);
51
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
52
* notify callback service CoW requests. */
53
job_yield(job);
54
}
55
- } else if (s->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
56
- ret = backup_run_incremental(s);
57
} else {
58
- /* Both FULL and TOP SYNC_MODE's require copying.. */
59
- for (offset = 0; offset < s->len;
60
- offset += s->cluster_size) {
61
- bool error_is_read;
62
-
63
- if (yield_and_check(s)) {
64
- break;
65
- }
66
-
67
- if (s->sync_mode == MIRROR_SYNC_MODE_TOP &&
68
- bdrv_is_unallocated_range(bs, offset, s->cluster_size))
69
- {
70
- continue;
71
- }
72
-
73
- ret = backup_do_cow(s, offset, s->cluster_size,
74
- &error_is_read, false);
75
- if (ret < 0) {
76
- /* Depending on error action, fail now or retry cluster */
77
- BlockErrorAction action =
78
- backup_error_action(s, error_is_read, -ret);
79
- if (action == BLOCK_ERROR_ACTION_REPORT) {
80
- break;
81
- } else {
82
- offset -= s->cluster_size;
83
- continue;
84
- }
85
- }
86
- }
87
+ ret = backup_loop(s);
88
}
89
90
notifier_with_return_remove(&s->before_write);
91
--
64
--
92
2.21.0
65
2.21.0
93
66
94
67
diff view generated by jsdifflib
1
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
1
streamOptimized does not support writes that do not span exactly one
2
cluster. Furthermore, it cannot rewrite already allocated clusters.
3
As such, many iotests do not work with it. Disable them.
2
4
3
Valgrind detects multiple issues in QEMU iotests when the memory is
5
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
used without being initialized. Valgrind may dump lots of unnecessary
6
Message-id: 20190815153638.4600-6-mreitz@redhat.com
5
reports what makes the memory issue analysis harder. Particularly,
7
Reviewed-by: John Snow <jsnow@redhat.com>
6
that is true for the aligned bitmap directory and can be seen while
7
running the iotest #169. Padding the aligned space with zeros eases
8
the pain.
9
10
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
11
Message-id: 1558961521-131620-1-git-send-email-andrey.shinkevich@virtuozzo.com
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
9
---
14
block/qcow2-bitmap.c | 2 +-
10
tests/qemu-iotests/002 | 1 +
15
1 file changed, 1 insertion(+), 1 deletion(-)
11
tests/qemu-iotests/003 | 1 +
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(-)
16
32
17
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
33
diff --git a/tests/qemu-iotests/002 b/tests/qemu-iotests/002
18
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100755
19
--- a/block/qcow2-bitmap.c
35
--- a/tests/qemu-iotests/002
20
+++ b/block/qcow2-bitmap.c
36
+++ b/tests/qemu-iotests/002
21
@@ -XXX,XX +XXX,XX @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list,
37
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
22
dir_offset = *offset;
38
23
}
39
_supported_fmt generic
24
40
_supported_proto generic
25
- dir = g_try_malloc(dir_size);
41
+_unsupported_imgopts "subformat=streamOptimized"
26
+ dir = g_try_malloc0(dir_size);
42
27
if (dir == NULL) {
43
28
return -ENOMEM;
44
size=128M
29
}
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.
30
--
303
--
31
2.21.0
304
2.21.0
32
305
33
306
diff view generated by jsdifflib
1
From: Alberto Garcia <berto@igalia.com>
1
The error message for the test case where we have a quorum node for
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.
2
7
3
bdrv_unref_child() does the following things:
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
9
Reviewed-by: John Snow <jsnow@redhat.com>
5
- Updates the child->bs->inherits_from pointer.
10
Message-id: 20190815153638.4600-7-mreitz@redhat.com
6
- Calls bdrv_detach_child() to remove the BdrvChild from bs->children.
11
Reviewed-by: John Snow <jsnow@redhat.com>
7
- Calls bdrv_unref() to unref the child BlockDriverState.
8
9
When bdrv_unref_child() was introduced in commit 33a604075c it was not
10
used in bdrv_close() because the drivers that had additional children
11
(like quorum or blkverify) had already called bdrv_unref() on their
12
children during their own close functions.
13
14
This was changed later (in 0bd6e91a7e for quorum, in 3e586be0b2 for
15
blkverify) so there's no reason not to use bdrv_unref_child() in
16
bdrv_close() anymore.
17
18
After this there's also no need to remove bs->backing and bs->file
19
separately from the rest of the children, so bdrv_close() can be
20
simplified.
21
22
Now bdrv_close() unrefs all children (before this patch it was only
23
bs->file and bs->backing). As a result, none of the callers of
24
brvd_attach_child() should remove their reference to child_bs (because
25
this function effectively steals that reference). This patch updates a
26
couple of tests that were doing their own bdrv_unref().
27
28
Signed-off-by: Alberto Garcia <berto@igalia.com>
29
Message-id: 6d1d5feaa53aa1ab127adb73d605dc4503e3abd5.1557754872.git.berto@igalia.com
30
[mreitz: s/where/were/]
31
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
32
---
13
---
33
block.c | 16 +++-------------
14
tests/qemu-iotests/110 | 3 ++-
34
tests/test-bdrv-drain.c | 6 ------
15
1 file changed, 2 insertions(+), 1 deletion(-)
35
tests/test-bdrv-graph-mod.c | 1 -
36
3 files changed, 3 insertions(+), 20 deletions(-)
37
16
38
diff --git a/block.c b/block.c
17
diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110
39
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100755
40
--- a/block.c
19
--- a/tests/qemu-iotests/110
41
+++ b/block.c
20
+++ b/tests/qemu-iotests/110
42
@@ -XXX,XX +XXX,XX @@ static void bdrv_close(BlockDriverState *bs)
21
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
43
bs->drv = NULL;
22
# Any format supporting backing files
44
}
23
_supported_fmt qed qcow qcow2 vmdk
45
24
_supported_proto file
46
- bdrv_set_backing_hd(bs, NULL, &error_abort);
25
-_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
47
-
26
+_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
48
- if (bs->file != NULL) {
27
+ "subformat=twoGbMaxExtentSparse"
49
- bdrv_unref_child(bs, bs->file);
28
50
- bs->file = NULL;
29
TEST_IMG_REL=$(basename "$TEST_IMG")
51
- }
52
-
53
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
54
- /* TODO Remove bdrv_unref() from drivers' close function and use
55
- * bdrv_unref_child() here */
56
- if (child->bs->inherits_from == bs) {
57
- child->bs->inherits_from = NULL;
58
- }
59
- bdrv_detach_child(child);
60
+ bdrv_unref_child(bs, child);
61
}
62
63
+ bs->backing = NULL;
64
+ bs->file = NULL;
65
g_free(bs->opaque);
66
bs->opaque = NULL;
67
atomic_set(&bs->copy_on_read, 0);
68
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
69
index XXXXXXX..XXXXXXX 100644
70
--- a/tests/test-bdrv-drain.c
71
+++ b/tests/test-bdrv-drain.c
72
@@ -XXX,XX +XXX,XX @@ static void test_detach_indirect(bool by_parent_cb)
73
bdrv_unref(parent_b);
74
blk_unref(blk);
75
76
- /* XXX Once bdrv_close() unref's children instead of just detaching them,
77
- * this won't be necessary any more. */
78
- bdrv_unref(a);
79
- bdrv_unref(a);
80
- bdrv_unref(c);
81
-
82
g_assert_cmpint(a->refcnt, ==, 1);
83
g_assert_cmpint(b->refcnt, ==, 1);
84
g_assert_cmpint(c->refcnt, ==, 1);
85
diff --git a/tests/test-bdrv-graph-mod.c b/tests/test-bdrv-graph-mod.c
86
index XXXXXXX..XXXXXXX 100644
87
--- a/tests/test-bdrv-graph-mod.c
88
+++ b/tests/test-bdrv-graph-mod.c
89
@@ -XXX,XX +XXX,XX @@ static void test_update_perm_tree(void)
90
g_assert_nonnull(local_err);
91
error_free(local_err);
92
93
- bdrv_unref(bs);
94
blk_unref(root);
95
}
96
30
97
--
31
--
98
2.21.0
32
2.21.0
99
33
100
34
diff view generated by jsdifflib
1
From: Sam Eiderman <shmuel.eiderman@oracle.com>
1
iotest 126 requires backing file support, which flat vmdks cannot offer.
2
Skip this test for such subformats.
2
3
3
If a chain was detected, don't open a new BlockBackend from the target
4
Signed-off-by: Max Reitz <mreitz@redhat.com>
4
backing file which will create a new BlockDriverState. Instead, create
5
Message-id: 20190815153638.4600-8-mreitz@redhat.com
5
an empty BlockBackend and attach the already open BlockDriverState.
6
Reviewed-by: John Snow <jsnow@redhat.com>
6
7
Permissions for blk_new() were copied from blk_new_open() when
8
flags = 0.
9
10
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
11
Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com>
12
Signed-off-by: Sagi Amit <sagi.amit@oracle.com>
13
Co-developed-by: Sagi Amit <sagi.amit@oracle.com>
14
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
15
Message-id: 20190523163337.4497-4-shmuel.eiderman@oracle.com
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
8
---
18
qemu-img.c | 33 +++++++++++++++++++++++----------
9
tests/qemu-iotests/126 | 2 ++
19
1 file changed, 23 insertions(+), 10 deletions(-)
10
1 file changed, 2 insertions(+)
20
11
21
diff --git a/qemu-img.c b/qemu-img.c
12
diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126
22
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100755
23
--- a/qemu-img.c
14
--- a/tests/qemu-iotests/126
24
+++ b/qemu-img.c
15
+++ b/tests/qemu-iotests/126
25
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
26
* in its chain.
17
27
*/
18
# Needs backing file support
28
prefix_chain_bs = bdrv_find_backing_image(bs, out_real_path);
19
_supported_fmt qcow qcow2 qed vmdk
29
-
20
+_unsupported_imgopts "subformat=monolithicFlat" \
30
- blk_new_backing = blk_new_open(out_real_path, NULL,
21
+ "subformat=twoGbMaxExtentFlat"
31
- options, src_flags, &local_err);
22
# This is the default protocol (and we want to test the difference between
32
- g_free(out_real_path);
23
# colons which separate a protocol prefix from the rest and colons which are
33
- if (!blk_new_backing) {
24
# just part of the filename, so we cannot test protocols which require a prefix)
34
- error_reportf_err(local_err,
35
- "Could not open new backing file '%s': ",
36
- out_baseimg);
37
- ret = -1;
38
- goto out;
39
+ if (prefix_chain_bs) {
40
+ g_free(out_real_path);
41
+ blk_new_backing = blk_new(BLK_PERM_CONSISTENT_READ,
42
+ BLK_PERM_ALL);
43
+ ret = blk_insert_bs(blk_new_backing, prefix_chain_bs,
44
+ &local_err);
45
+ if (ret < 0) {
46
+ error_reportf_err(local_err,
47
+ "Could not reuse backing file '%s': ",
48
+ out_baseimg);
49
+ goto out;
50
+ }
51
+ } else {
52
+ blk_new_backing = blk_new_open(out_real_path, NULL,
53
+ options, src_flags, &local_err);
54
+ g_free(out_real_path);
55
+ if (!blk_new_backing) {
56
+ error_reportf_err(local_err,
57
+ "Could not open new backing file '%s': ",
58
+ out_baseimg);
59
+ ret = -1;
60
+ goto out;
61
+ }
62
}
63
}
64
}
65
--
25
--
66
2.21.0
26
2.21.0
67
27
68
28
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Stefan Hajnoczi <stefanha@redhat.com>
2
2
3
Do encryption/decryption in threads, like it is already done for
3
Fixes: a6b257a08e3d72219f03e461a52152672fec0612
4
compression. This improves asynchronous encrypted io.
4
("file-posix: Handle undetectable alignment")
5
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
6
Message-id: 20190827101328.4062-1-stefanha@redhat.com
7
Reviewed-by: Alberto Garcia <berto@igalia.com>
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190506142741.41731-9-vsementsov@virtuozzo.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
9
---
12
block/qcow2.h | 8 ++++++
10
block/file-posix.c | 2 +-
13
block/qcow2-cluster.c | 7 ++---
11
1 file changed, 1 insertion(+), 1 deletion(-)
14
block/qcow2-threads.c | 65 +++++++++++++++++++++++++++++++++++++++++--
15
block/qcow2.c | 22 +++++----------
16
4 files changed, 81 insertions(+), 21 deletions(-)
17
12
18
diff --git a/block/qcow2.h b/block/qcow2.h
13
diff --git a/block/file-posix.c b/block/file-posix.c
19
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2.h
15
--- a/block/file-posix.c
21
+++ b/block/qcow2.h
16
+++ b/block/file-posix.c
22
@@ -XXX,XX +XXX,XX @@ typedef struct Qcow2BitmapHeaderExt {
17
@@ -XXX,XX +XXX,XX @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
23
uint64_t bitmap_directory_offset;
18
for (i = 0; i < ARRAY_SIZE(alignments); i++) {
24
} QEMU_PACKED Qcow2BitmapHeaderExt;
19
align = alignments[i];
25
20
if (raw_is_io_aligned(fd, buf + align, max_align)) {
26
+#define QCOW2_MAX_THREADS 4
21
- /* Fallback to request_aligment. */
27
+
22
+ /* Fallback to request_alignment. */
28
typedef struct BDRVQcow2State {
23
s->buf_align = (align != 1) ? align : bs->bl.request_alignment;
29
int cluster_bits;
24
break;
30
int cluster_size;
31
@@ -XXX,XX +XXX,XX @@ qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
32
ssize_t coroutine_fn
33
qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
34
const void *src, size_t src_size);
35
+int coroutine_fn
36
+qcow2_co_encrypt(BlockDriverState *bs, uint64_t file_cluster_offset,
37
+ uint64_t offset, void *buf, size_t len);
38
+int coroutine_fn
39
+qcow2_co_decrypt(BlockDriverState *bs, uint64_t file_cluster_offset,
40
+ uint64_t offset, void *buf, size_t len);
41
42
#endif
43
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/block/qcow2-cluster.c
46
+++ b/block/qcow2-cluster.c
47
@@ -XXX,XX +XXX,XX @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs,
48
{
49
if (bytes && bs->encrypted) {
50
BDRVQcow2State *s = bs->opaque;
51
- int64_t offset = (s->crypt_physical_offset ?
52
- (cluster_offset + offset_in_cluster) :
53
- (src_cluster_offset + offset_in_cluster));
54
assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0);
55
assert((bytes & ~BDRV_SECTOR_MASK) == 0);
56
assert(s->crypto);
57
- if (qcrypto_block_encrypt(s->crypto, offset, buffer, bytes, NULL) < 0) {
58
+ if (qcow2_co_encrypt(bs, cluster_offset,
59
+ src_cluster_offset + offset_in_cluster,
60
+ buffer, bytes) < 0) {
61
return false;
62
}
63
}
64
diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/block/qcow2-threads.c
67
+++ b/block/qcow2-threads.c
68
@@ -XXX,XX +XXX,XX @@
69
70
#include "qcow2.h"
71
#include "block/thread-pool.h"
72
-
73
-#define QCOW2_MAX_THREADS 4
74
+#include "crypto.h"
75
76
static int coroutine_fn
77
qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *func, void *arg)
78
@@ -XXX,XX +XXX,XX @@ qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
79
return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
80
qcow2_decompress);
81
}
82
+
83
+
84
+/*
85
+ * Cryptography
86
+ */
87
+
88
+/*
89
+ * Qcow2EncDecFunc: common prototype of qcrypto_block_encrypt() and
90
+ * qcrypto_block_decrypt() functions.
91
+ */
92
+typedef int (*Qcow2EncDecFunc)(QCryptoBlock *block, uint64_t offset,
93
+ uint8_t *buf, size_t len, Error **errp);
94
+
95
+typedef struct Qcow2EncDecData {
96
+ QCryptoBlock *block;
97
+ uint64_t offset;
98
+ uint8_t *buf;
99
+ size_t len;
100
+
101
+ Qcow2EncDecFunc func;
102
+} Qcow2EncDecData;
103
+
104
+static int qcow2_encdec_pool_func(void *opaque)
105
+{
106
+ Qcow2EncDecData *data = opaque;
107
+
108
+ return data->func(data->block, data->offset, data->buf, data->len, NULL);
109
+}
110
+
111
+static int coroutine_fn
112
+qcow2_co_encdec(BlockDriverState *bs, uint64_t file_cluster_offset,
113
+ uint64_t offset, void *buf, size_t len, Qcow2EncDecFunc func)
114
+{
115
+ BDRVQcow2State *s = bs->opaque;
116
+ Qcow2EncDecData arg = {
117
+ .block = s->crypto,
118
+ .offset = s->crypt_physical_offset ?
119
+ file_cluster_offset + offset_into_cluster(s, offset) :
120
+ offset,
121
+ .buf = buf,
122
+ .len = len,
123
+ .func = func,
124
+ };
125
+
126
+ return qcow2_co_process(bs, qcow2_encdec_pool_func, &arg);
127
+}
128
+
129
+int coroutine_fn
130
+qcow2_co_encrypt(BlockDriverState *bs, uint64_t file_cluster_offset,
131
+ uint64_t offset, void *buf, size_t len)
132
+{
133
+ return qcow2_co_encdec(bs, file_cluster_offset, offset, buf, len,
134
+ qcrypto_block_encrypt);
135
+}
136
+
137
+int coroutine_fn
138
+qcow2_co_decrypt(BlockDriverState *bs, uint64_t file_cluster_offset,
139
+ uint64_t offset, void *buf, size_t len)
140
+{
141
+ return qcow2_co_encdec(bs, file_cluster_offset, offset, buf, len,
142
+ qcrypto_block_decrypt);
143
+}
144
diff --git a/block/qcow2.c b/block/qcow2.c
145
index XXXXXXX..XXXXXXX 100644
146
--- a/block/qcow2.c
147
+++ b/block/qcow2.c
148
@@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
149
}
150
s->crypto = qcrypto_block_open(s->crypto_opts, "encrypt.",
151
qcow2_crypto_hdr_read_func,
152
- bs, cflags, 1, errp);
153
+ bs, cflags, QCOW2_MAX_THREADS, errp);
154
if (!s->crypto) {
155
return -EINVAL;
156
}
157
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
158
cflags |= QCRYPTO_BLOCK_OPEN_NO_IO;
159
}
160
s->crypto = qcrypto_block_open(s->crypto_opts, "encrypt.",
161
- NULL, NULL, cflags, 1, errp);
162
+ NULL, NULL, cflags,
163
+ QCOW2_MAX_THREADS, errp);
164
if (!s->crypto) {
165
ret = -EINVAL;
166
goto fail;
167
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
168
assert(s->crypto);
169
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
170
assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
171
- if (qcrypto_block_decrypt(s->crypto,
172
- (s->crypt_physical_offset ?
173
- cluster_offset + offset_in_cluster :
174
- offset),
175
- cluster_data,
176
- cur_bytes,
177
- NULL) < 0) {
178
+ if (qcow2_co_decrypt(bs, cluster_offset, offset,
179
+ cluster_data, cur_bytes) < 0) {
180
ret = -EIO;
181
goto fail;
182
}
183
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
184
QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size);
185
qemu_iovec_to_buf(&hd_qiov, 0, cluster_data, hd_qiov.size);
186
187
- if (qcrypto_block_encrypt(s->crypto,
188
- (s->crypt_physical_offset ?
189
- cluster_offset + offset_in_cluster :
190
- offset),
191
- cluster_data,
192
- cur_bytes, NULL) < 0) {
193
+ if (qcow2_co_encrypt(bs, cluster_offset, offset,
194
+ cluster_data, cur_bytes) < 0) {
195
ret = -EIO;
196
goto out_unlocked;
197
}
25
}
198
--
26
--
199
2.21.0
27
2.21.0
200
28
201
29
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
Split allocation checking to separate function and reduce nesting.
3
It is possible to enable only a subset of the block drivers with the
4
Consider bdrv_is_allocated() fail as allocated area, as copying more
4
"--block-drv-rw-whitelist" option of the "configure" script. All other
5
than needed is not wrong (and we do it anyway) and seems better than
5
drivers are marked as unusable (or only included as read-only with the
6
fail the whole job. And, most probably we will fail on the next read,
6
"--block-drv-ro-whitelist" option). If an iotest is now using such a
7
if there are real problem with source.
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.
8
12
9
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
13
This patch mainly targets the test in the "auto" group which should
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
14
never fail in such a case, but also improves some of the other tests
11
Message-id: 20190429090842.57910-4-vsementsov@virtuozzo.com
15
along the way. Note that we also assume that the "qcow2" and "file"
16
drivers are always available - otherwise it does not make sense to
17
run "make check-block" at all (which only tests with qcow2 by default).
18
19
Signed-off-by: Thomas Huth <thuth@redhat.com>
20
Message-id: 20190823133552.11680-1-thuth@redhat.com
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
22
---
14
block/backup.c | 60 +++++++++++++++++++-------------------------------
23
tests/qemu-iotests/071 | 1 +
15
1 file changed, 23 insertions(+), 37 deletions(-)
24
tests/qemu-iotests/081 | 4 +---
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(-)
16
32
17
diff --git a/block/backup.c b/block/backup.c
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
18
index XXXXXXX..XXXXXXX 100644
131
index XXXXXXX..XXXXXXX 100644
19
--- a/block/backup.c
132
--- a/tests/qemu-iotests/common.rc
20
+++ b/block/backup.c
133
+++ b/tests/qemu-iotests/common.rc
21
@@ -XXX,XX +XXX,XX @@ static bool coroutine_fn yield_and_check(BackupBlockJob *job)
134
@@ -XXX,XX +XXX,XX @@ _require_command()
22
return false;
135
[ -x "$c" ] || _notrun "$1 utility required, skipped this test"
23
}
136
}
24
137
25
+static bool bdrv_is_unallocated_range(BlockDriverState *bs,
138
+# Check that a set of drivers has been whitelisted in the QEMU binary
26
+ int64_t offset, int64_t bytes)
139
+#
140
+_require_drivers()
27
+{
141
+{
28
+ int64_t end = offset + bytes;
142
+ available=$($QEMU -drive format=help | \
29
+
143
+ sed -e '/Supported formats:/!d' -e 's/Supported formats://')
30
+ while (offset < end && !bdrv_is_allocated(bs, offset, bytes, &bytes)) {
144
+ for driver
31
+ if (bytes == 0) {
145
+ do
32
+ return true;
146
+ if ! echo "$available" | grep -q " $driver\( \|$\)"; then
33
+ }
147
+ _notrun "$driver not available"
34
+ offset += bytes;
148
+ fi
35
+ bytes = end - offset;
149
+ done
36
+ }
37
+
38
+ return offset >= end;
39
+}
150
+}
40
+
151
+
41
static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
152
# make sure this script returns success
42
{
153
true
43
int ret;
44
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *job, Error **errp)
45
for (offset = 0; offset < s->len;
46
offset += s->cluster_size) {
47
bool error_is_read;
48
- int alloced = 0;
49
50
if (yield_and_check(s)) {
51
break;
52
}
53
54
- if (s->sync_mode == MIRROR_SYNC_MODE_TOP) {
55
- int i;
56
- int64_t n;
57
-
58
- /* Check to see if these blocks are already in the
59
- * backing file. */
60
-
61
- for (i = 0; i < s->cluster_size;) {
62
- /* bdrv_is_allocated() only returns true/false based
63
- * on the first set of sectors it comes across that
64
- * are are all in the same state.
65
- * For that reason we must verify each sector in the
66
- * backup cluster length. We end up copying more than
67
- * needed but at some point that is always the case. */
68
- alloced =
69
- bdrv_is_allocated(bs, offset + i,
70
- s->cluster_size - i, &n);
71
- i += n;
72
-
73
- if (alloced || n == 0) {
74
- break;
75
- }
76
- }
77
-
78
- /* If the above loop never found any sectors that are in
79
- * the topmost image, skip this backup. */
80
- if (alloced == 0) {
81
- continue;
82
- }
83
- }
84
- /* FULL sync mode we copy the whole drive. */
85
- if (alloced < 0) {
86
- ret = alloced;
87
- } else {
88
- ret = backup_do_cow(s, offset, s->cluster_size,
89
- &error_is_read, false);
90
+ if (s->sync_mode == MIRROR_SYNC_MODE_TOP &&
91
+ bdrv_is_unallocated_range(bs, offset, s->cluster_size))
92
+ {
93
+ continue;
94
}
95
+
96
+ ret = backup_do_cow(s, offset, s->cluster_size,
97
+ &error_is_read, false);
98
if (ret < 0) {
99
/* Depending on error action, fail now or retry cluster */
100
BlockErrorAction action =
101
--
154
--
102
2.21.0
155
2.21.0
103
156
104
157
diff view generated by jsdifflib
1
From: Sam Eiderman <shmuel.eiderman@oracle.com>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
In the following case:
3
The sanitizers (especially the address sanitizer from Clang) are
4
sometimes printing out warnings or false positives - this spoils
5
the output of the iotests, causing some of the tests to fail.
6
Thus let's skip the automatic iotests during "make check" when the
7
user configured QEMU with --enable-sanitizers.
4
8
5
(base) A <- B <- C (tip)
9
Signed-off-by: Thomas Huth <thuth@redhat.com>
6
10
Message-id: 20190823084203.29734-1-thuth@redhat.com
7
when running:
8
9
qemu-img rebase -b A C
10
11
QEMU would read all sectors not allocated in the file being rebased (C)
12
and compare them to the new base image (A), regardless of whether they
13
were changed or even allocated anywhere along the chain between the new
14
base and the top image (B). This causes many unneeded reads when
15
rebasing an image which represents a small diff of a large disk, as it
16
would read most of the disk's sectors.
17
18
Instead, use bdrv_is_allocated_above() to reduce the number of
19
unnecessary reads.
20
21
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
22
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
23
Signed-off-by: Eyal Moscovici <eyal.moscovici@oracle.com>
24
Message-id: 20190523163337.4497-3-shmuel.eiderman@oracle.com
25
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
26
---
12
---
27
qemu-img.c | 25 ++++++++++++++++++++++++-
13
tests/check-block.sh | 5 +++++
28
1 file changed, 24 insertions(+), 1 deletion(-)
14
1 file changed, 5 insertions(+)
29
15
30
diff --git a/qemu-img.c b/qemu-img.c
16
diff --git a/tests/check-block.sh b/tests/check-block.sh
31
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100755
32
--- a/qemu-img.c
18
--- a/tests/check-block.sh
33
+++ b/qemu-img.c
19
+++ b/tests/check-block.sh
34
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
20
@@ -XXX,XX +XXX,XX @@ if grep -q "TARGET_GPROF=y" *-softmmu/config-target.mak 2>/dev/null ; then
35
BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL;
21
exit 0
36
uint8_t *buf_old = NULL;
22
fi
37
uint8_t *buf_new = NULL;
23
38
- BlockDriverState *bs = NULL;
24
+if grep -q "CFLAGS.*-fsanitize" config-host.mak 2>/dev/null ; then
39
+ BlockDriverState *bs = NULL, *prefix_chain_bs = NULL;
25
+ echo "Sanitizers are enabled ==> Not running the qemu-iotests."
40
char *filename;
26
+ exit 0
41
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
27
+fi
42
int c, flags, src_flags, ret;
43
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
44
goto out;
45
}
46
47
+ /*
48
+ * Find out whether we rebase an image on top of a previous image
49
+ * in its chain.
50
+ */
51
+ prefix_chain_bs = bdrv_find_backing_image(bs, out_real_path);
52
+
28
+
53
blk_new_backing = blk_new_open(out_real_path, NULL,
29
if [ -z "$(find . -name 'qemu-system-*' -print)" ]; then
54
options, src_flags, &local_err);
30
echo "No qemu-system binary available ==> Not running the qemu-iotests."
55
g_free(out_real_path);
31
exit 0
56
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
57
continue;
58
}
59
60
+ if (prefix_chain_bs) {
61
+ /*
62
+ * If cluster wasn't changed since prefix_chain, we don't need
63
+ * to take action
64
+ */
65
+ ret = bdrv_is_allocated_above(backing_bs(bs), prefix_chain_bs,
66
+ offset, n, &n);
67
+ if (ret < 0) {
68
+ error_report("error while reading image metadata: %s",
69
+ strerror(-ret));
70
+ goto out;
71
+ }
72
+ if (!ret) {
73
+ continue;
74
+ }
75
+ }
76
+
77
/*
78
* Read old and new backing file and take into consideration that
79
* backing files may be smaller than the COW image.
80
--
32
--
81
2.21.0
33
2.21.0
82
34
83
35
diff view generated by jsdifflib
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1
From: Nir Soffer <nirsof@gmail.com>
2
2
3
Background: decryption will be done in threads, to take benefit of it,
3
Quoting cache mode is not needed, and most tests use unquoted values.
4
we should move it out of the lock first.
4
Unify all test to use the same style.
5
5
6
But let's go further: it turns out, that only
6
Message-id: 20190827173432.7656-1-nsoffer@redhat.com
7
qcow2_get_cluster_offset() needs locking, so reduce locking to it.
7
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
8
9
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
10
Message-id: 20190506142741.41731-7-vsementsov@virtuozzo.com
11
Reviewed-by: Alberto Garcia <berto@igalia.com>
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
9
---
14
block/qcow2.c | 12 ++----------
10
tests/qemu-iotests/026 | 4 ++--
15
1 file changed, 2 insertions(+), 10 deletions(-)
11
tests/qemu-iotests/039 | 4 ++--
12
tests/qemu-iotests/052 | 2 +-
13
tests/qemu-iotests/091 | 4 ++--
14
4 files changed, 7 insertions(+), 7 deletions(-)
16
15
17
diff --git a/block/qcow2.c b/block/qcow2.c
16
diff --git a/tests/qemu-iotests/026 b/tests/qemu-iotests/026
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100755
19
--- a/block/qcow2.c
18
--- a/tests/qemu-iotests/026
20
+++ b/block/qcow2.c
19
+++ b/tests/qemu-iotests/026
21
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
20
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
22
21
# Currently only qcow2 supports rebasing
23
qemu_iovec_init(&hd_qiov, qiov->niov);
22
_supported_fmt qcow2
24
23
_supported_proto file
25
- qemu_co_mutex_lock(&s->lock);
24
-_default_cache_mode "writethrough"
26
-
25
-_supported_cache_modes "writethrough" "none"
27
while (bytes != 0) {
26
+_default_cache_mode writethrough
28
27
+_supported_cache_modes writethrough none
29
/* prepare next request */
28
# The refcount table tests expect a certain minimum width for refcount entries
30
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
29
# (so that the refcount table actually needs to grow); that minimum is 16 bits,
31
QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size);
30
# being the default refcount entry width.
32
}
31
diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039
33
32
index XXXXXXX..XXXXXXX 100755
34
+ qemu_co_mutex_lock(&s->lock);
33
--- a/tests/qemu-iotests/039
35
ret = qcow2_get_cluster_offset(bs, offset, &cur_bytes, &cluster_offset);
34
+++ b/tests/qemu-iotests/039
36
+ qemu_co_mutex_unlock(&s->lock);
35
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
37
if (ret < 0) {
36
_supported_fmt qcow2
38
goto fail;
37
_supported_proto file
39
}
38
_supported_os Linux
40
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
39
-_default_cache_mode "writethrough"
41
40
-_supported_cache_modes "writethrough"
42
if (bs->backing) {
41
+_default_cache_mode writethrough
43
BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO);
42
+_supported_cache_modes writethrough
44
- qemu_co_mutex_unlock(&s->lock);
43
45
ret = bdrv_co_preadv(bs->backing, offset, cur_bytes,
44
size=128M
46
&hd_qiov, 0);
45
47
- qemu_co_mutex_lock(&s->lock);
46
diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052
48
if (ret < 0) {
47
index XXXXXXX..XXXXXXX 100755
49
goto fail;
48
--- a/tests/qemu-iotests/052
50
}
49
+++ b/tests/qemu-iotests/052
51
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
50
@@ -XXX,XX +XXX,XX @@ _supported_fmt generic
52
break;
51
_supported_proto file
53
52
54
case QCOW2_CLUSTER_COMPRESSED:
53
# Don't do O_DIRECT on tmpfs
55
- qemu_co_mutex_unlock(&s->lock);
54
-_supported_cache_modes "writeback" "writethrough" "unsafe"
56
ret = qcow2_co_preadv_compressed(bs, cluster_offset,
55
+_supported_cache_modes writeback writethrough unsafe
57
offset, cur_bytes,
56
58
&hd_qiov);
57
size=128M
59
- qemu_co_mutex_lock(&s->lock);
58
_make_test_img $size
60
if (ret < 0) {
59
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
61
goto fail;
60
index XXXXXXX..XXXXXXX 100755
62
}
61
--- a/tests/qemu-iotests/091
63
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
62
+++ b/tests/qemu-iotests/091
64
}
63
@@ -XXX,XX +XXX,XX @@ trap "_cleanup; exit \$status" 0 1 2 3 15
65
64
_supported_fmt qcow2
66
BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
65
_supported_proto file
67
- qemu_co_mutex_unlock(&s->lock);
66
_supported_os Linux
68
ret = bdrv_co_preadv(s->data_file,
67
-_default_cache_mode "none"
69
cluster_offset + offset_in_cluster,
68
-_supported_cache_modes "writethrough" "none" "writeback"
70
cur_bytes, &hd_qiov, 0);
69
+_default_cache_mode none
71
- qemu_co_mutex_lock(&s->lock);
70
+_supported_cache_modes writethrough none writeback
72
if (ret < 0) {
71
73
goto fail;
72
size=1G
74
}
75
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
76
ret = 0;
77
78
fail:
79
- qemu_co_mutex_unlock(&s->lock);
80
-
81
qemu_iovec_destroy(&hd_qiov);
82
qemu_vfree(cluster_data);
83
73
84
--
74
--
85
2.21.0
75
2.21.0
86
76
87
77
diff view generated by jsdifflib
Deleted patch
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
1
3
Encryption will be done in threads, to take benefit of it, we should
4
move it out of the lock first.
5
6
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Reviewed-by: Alberto Garcia <berto@igalia.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20190506142741.41731-8-vsementsov@virtuozzo.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/qcow2.c | 35 +++++++++++++++++++++--------------
13
1 file changed, 21 insertions(+), 14 deletions(-)
14
15
diff --git a/block/qcow2.c b/block/qcow2.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/qcow2.c
18
+++ b/block/qcow2.c
19
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
20
ret = qcow2_alloc_cluster_offset(bs, offset, &cur_bytes,
21
&cluster_offset, &l2meta);
22
if (ret < 0) {
23
- goto fail;
24
+ goto out_locked;
25
}
26
27
assert((cluster_offset & 511) == 0);
28
29
+ ret = qcow2_pre_write_overlap_check(bs, 0,
30
+ cluster_offset + offset_in_cluster,
31
+ cur_bytes, true);
32
+ if (ret < 0) {
33
+ goto out_locked;
34
+ }
35
+
36
+ qemu_co_mutex_unlock(&s->lock);
37
+
38
qemu_iovec_reset(&hd_qiov);
39
qemu_iovec_concat(&hd_qiov, qiov, bytes_done, cur_bytes);
40
41
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
42
* s->cluster_size);
43
if (cluster_data == NULL) {
44
ret = -ENOMEM;
45
- goto fail;
46
+ goto out_unlocked;
47
}
48
}
49
50
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
51
cluster_data,
52
cur_bytes, NULL) < 0) {
53
ret = -EIO;
54
- goto fail;
55
+ goto out_unlocked;
56
}
57
58
qemu_iovec_reset(&hd_qiov);
59
qemu_iovec_add(&hd_qiov, cluster_data, cur_bytes);
60
}
61
62
- ret = qcow2_pre_write_overlap_check(bs, 0,
63
- cluster_offset + offset_in_cluster, cur_bytes, true);
64
- if (ret < 0) {
65
- goto fail;
66
- }
67
-
68
/* If we need to do COW, check if it's possible to merge the
69
* writing of the guest data together with that of the COW regions.
70
* If it's not possible (or not necessary) then write the
71
* guest data now. */
72
if (!merge_cow(offset, cur_bytes, &hd_qiov, l2meta)) {
73
- qemu_co_mutex_unlock(&s->lock);
74
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
75
trace_qcow2_writev_data(qemu_coroutine_self(),
76
cluster_offset + offset_in_cluster);
77
ret = bdrv_co_pwritev(s->data_file,
78
cluster_offset + offset_in_cluster,
79
cur_bytes, &hd_qiov, 0);
80
- qemu_co_mutex_lock(&s->lock);
81
if (ret < 0) {
82
- goto fail;
83
+ goto out_unlocked;
84
}
85
}
86
87
+ qemu_co_mutex_lock(&s->lock);
88
+
89
ret = qcow2_handle_l2meta(bs, &l2meta, true);
90
if (ret) {
91
- goto fail;
92
+ goto out_locked;
93
}
94
95
bytes -= cur_bytes;
96
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset,
97
trace_qcow2_writev_done_part(qemu_coroutine_self(), cur_bytes);
98
}
99
ret = 0;
100
+ goto out_locked;
101
102
-fail:
103
+out_unlocked:
104
+ qemu_co_mutex_lock(&s->lock);
105
+
106
+out_locked:
107
qcow2_handle_l2meta(bs, &l2meta, false);
108
109
qemu_co_mutex_unlock(&s->lock);
110
--
111
2.21.0
112
113
diff view generated by jsdifflib
Deleted patch
1
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2
1
3
Simplify backup_incremental_init_copy_bitmap using the function
4
bdrv_dirty_bitmap_next_dirty_area.
5
6
Note: move to job->len instead of bitmap size: it should not matter but
7
less code.
8
9
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Message-id: 20190429090842.57910-2-vsementsov@virtuozzo.com
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
14
block/backup.c | 40 ++++++++++++----------------------------
15
1 file changed, 12 insertions(+), 28 deletions(-)
16
17
diff --git a/block/backup.c b/block/backup.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/backup.c
20
+++ b/block/backup.c
21
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job)
22
/* init copy_bitmap from sync_bitmap */
23
static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
24
{
25
- BdrvDirtyBitmapIter *dbi;
26
- int64_t offset;
27
- int64_t end = DIV_ROUND_UP(bdrv_dirty_bitmap_size(job->sync_bitmap),
28
- job->cluster_size);
29
-
30
- dbi = bdrv_dirty_iter_new(job->sync_bitmap);
31
- while ((offset = bdrv_dirty_iter_next(dbi)) != -1) {
32
- int64_t cluster = offset / job->cluster_size;
33
- int64_t next_cluster;
34
-
35
- offset += bdrv_dirty_bitmap_granularity(job->sync_bitmap);
36
- if (offset >= bdrv_dirty_bitmap_size(job->sync_bitmap)) {
37
- hbitmap_set(job->copy_bitmap, cluster, end - cluster);
38
- break;
39
- }
40
+ uint64_t offset = 0;
41
+ uint64_t bytes = job->len;
42
43
- offset = bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset,
44
- UINT64_MAX);
45
- if (offset == -1) {
46
- hbitmap_set(job->copy_bitmap, cluster, end - cluster);
47
- break;
48
- }
49
+ while (bdrv_dirty_bitmap_next_dirty_area(job->sync_bitmap,
50
+ &offset, &bytes))
51
+ {
52
+ uint64_t cluster = offset / job->cluster_size;
53
+ uint64_t end_cluster = DIV_ROUND_UP(offset + bytes, job->cluster_size);
54
55
- next_cluster = DIV_ROUND_UP(offset, job->cluster_size);
56
- hbitmap_set(job->copy_bitmap, cluster, next_cluster - cluster);
57
- if (next_cluster >= end) {
58
+ hbitmap_set(job->copy_bitmap, cluster, end_cluster - cluster);
59
+
60
+ offset = end_cluster * job->cluster_size;
61
+ if (offset >= job->len) {
62
break;
63
}
64
-
65
- bdrv_set_dirty_iter(dbi, next_cluster * job->cluster_size);
66
+ bytes = job->len - offset;
67
}
68
69
/* TODO job_progress_set_remaining() would make more sense */
70
job_progress_update(&job->common.job,
71
job->len - hbitmap_count(job->copy_bitmap) * job->cluster_size);
72
-
73
- bdrv_dirty_iter_free(dbi);
74
}
75
76
static int coroutine_fn backup_run(Job *job, Error **errp)
77
--
78
2.21.0
79
80
diff view generated by jsdifflib
Deleted patch
1
From: Sam Eiderman <shmuel.eiderman@oracle.com>
2
1
3
In safe mode we open the entire chain, including the parent backing
4
file of the rebased file.
5
Do not open a new BlockBackend for the parent backing file, which
6
saves opening the rest of the chain twice, which for long chains
7
saves many "pricy" bdrv_open() calls.
8
9
Permissions for blk_new() were copied from blk_new_open() when
10
flags = 0.
11
12
Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
13
Reviewed-by: Eyal Moscovici <eyal.moscovici@oracle.com>
14
Signed-off-by: Sagi Amit <sagi.amit@oracle.com>
15
Co-developed-by: Sagi Amit <sagi.amit@oracle.com>
16
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
17
Message-id: 20190523163337.4497-2-shmuel.eiderman@oracle.com
18
Signed-off-by: Max Reitz <mreitz@redhat.com>
19
---
20
qemu-img.c | 29 +++++++++--------------------
21
1 file changed, 9 insertions(+), 20 deletions(-)
22
23
diff --git a/qemu-img.c b/qemu-img.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/qemu-img.c
26
+++ b/qemu-img.c
27
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
28
29
/* For safe rebasing we need to compare old and new backing file */
30
if (!unsafe) {
31
- char backing_name[PATH_MAX];
32
QDict *options = NULL;
33
+ BlockDriverState *base_bs = backing_bs(bs);
34
35
- if (bs->backing) {
36
- if (bs->backing_format[0] != '\0') {
37
- options = qdict_new();
38
- qdict_put_str(options, "driver", bs->backing_format);
39
- }
40
-
41
- if (force_share) {
42
- if (!options) {
43
- options = qdict_new();
44
- }
45
- qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
46
- }
47
- bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
48
- blk_old_backing = blk_new_open(backing_name, NULL,
49
- options, src_flags, &local_err);
50
- if (!blk_old_backing) {
51
+ if (base_bs) {
52
+ blk_old_backing = blk_new(BLK_PERM_CONSISTENT_READ,
53
+ BLK_PERM_ALL);
54
+ ret = blk_insert_bs(blk_old_backing, base_bs,
55
+ &local_err);
56
+ if (ret < 0) {
57
error_reportf_err(local_err,
58
- "Could not open old backing file '%s': ",
59
- backing_name);
60
- ret = -1;
61
+ "Could not reuse old backing file '%s': ",
62
+ base_bs->filename);
63
goto out;
64
}
65
} else {
66
--
67
2.21.0
68
69
diff view generated by jsdifflib