1
The following changes since commit 76d20ea0f1b26ebd5da2f5fb2fdf3250cde887bb:
1
The following changes since commit 2ccad61746ca7de5dd3e25146062264387e43bd4:
2
2
3
Merge remote-tracking branch 'armbru/tags/pull-qapi-2017-05-04-v3' into staging (2017-05-09 15:49:14 -0400)
3
Merge tag 'pull-tcg-20221109' of https://gitlab.com/rth7680/qemu into staging (2022-11-09 13:26:45 -0500)
4
4
5
are available in the git repository at:
5
are available in the Git repository at:
6
6
7
https://repo.or.cz/qemu/kevin.git tags/for-upstream
7
8
8
git://repo.or.cz/qemu/kevin.git tags/for-upstream
9
for you to fetch changes up to b04af371af685c12970ea93027dc6d8bf86265aa:
9
10
10
for you to fetch changes up to d541e201bd3ad888f02abeddf0e14f7b0c126529:
11
tests/stream-under-throttle: New test (2022-11-11 13:02:43 +0100)
11
12
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block (2017-05-11 14:34:56 +0200)
13
12
14
----------------------------------------------------------------
13
----------------------------------------------------------------
15
16
Block layer patches
14
Block layer patches
17
15
16
- Fix deadlock in graph modification with iothreads
17
- mirror: Fix non-converging cases for active mirror
18
- qapi: Fix BlockdevOptionsNvmeIoUring @path description
19
- blkio: Set BlockDriver::has_variable_length to false
20
18
----------------------------------------------------------------
21
----------------------------------------------------------------
19
Anton Nefedov (1):
22
Alberto Faria (2):
20
qemu-img: wait for convert coroutines to complete
23
qapi/block-core: Fix BlockdevOptionsNvmeIoUring @path description
24
block/blkio: Set BlockDriver::has_variable_length to false
21
25
22
Christoph Hellwig (1):
26
Hanna Reitz (9):
23
nvme: Implement Write Zeroes
27
block/mirror: Do not wait for active writes
28
block/mirror: Drop mirror_wait_for_any_operation()
29
block/mirror: Fix NULL s->job in active writes
30
iotests/151: Test that active mirror progresses
31
iotests/151: Test active requests on mirror start
32
block: Make bdrv_child_get_parent_aio_context I/O
33
block-backend: Update ctx immediately after root
34
block: Start/end drain on correct AioContext
35
tests/stream-under-throttle: New test
24
36
25
Eric Blake (21):
37
qapi/block-core.json | 2 +-
26
qemu-io: Improve alignment checks
38
include/block/block-global-state.h | 1 -
27
qemu-io: Switch 'alloc' command to byte-based length
39
include/block/block-io.h | 2 +
28
qemu-io: Switch 'map' output to byte-based reporting
40
include/block/block_int-common.h | 4 +-
29
blkdebug: Sanity check block layer guarantees
41
block.c | 2 +-
30
blkdebug: Refactor error injection
42
block/blkio.c | 1 -
31
blkdebug: Add pass-through write_zero and discard support
43
block/block-backend.c | 9 +-
32
blkdebug: Simplify override logic
44
block/io.c | 6 +-
33
blkdebug: Add ability to override unmap geometries
45
block/mirror.c | 78 ++++---
34
tests: Add coverage for recent block geometry fixes
46
blockjob.c | 3 +-
35
qcow2: Nicer variable names in qcow2_update_snapshot_refcount()
47
tests/qemu-iotests/151 | 227 ++++++++++++++++++++-
36
qcow2: Use consistent switch indentation
48
tests/qemu-iotests/151.out | 4 +-
37
block: Update comments on BDRV_BLOCK_* meanings
49
tests/qemu-iotests/tests/stream-under-throttle | 121 +++++++++++
38
qcow2: Correctly report status of preallocated zero clusters
50
tests/qemu-iotests/tests/stream-under-throttle.out | 5 +
39
qcow2: Name typedef for cluster type
51
14 files changed, 424 insertions(+), 41 deletions(-)
40
qcow2: Make distinction between zero cluster types obvious
52
create mode 100755 tests/qemu-iotests/tests/stream-under-throttle
41
qcow2: Optimize zero_single_l2() to minimize L2 churn
53
create mode 100644 tests/qemu-iotests/tests/stream-under-throttle.out
42
iotests: Improve _filter_qemu_img_map
43
iotests: Add test 179 to cover write zeroes with unmap
44
qcow2: Optimize write zero of unaligned tail cluster
45
qcow2: Assert that cluster operations are aligned
46
qcow2: Discard/zero clusters by byte count
47
48
Fam Zheng (23):
49
block: Make bdrv_perm_names public
50
block: Add, parse and store "force-share" option
51
block: Respect "force-share" in perm propagating
52
qemu-img: Add --force-share option to subcommands
53
qemu-img: Update documentation for -U
54
qemu-io: Add --force-share option
55
iotests: 030: Prepare for image locking
56
iotests: 046: Prepare for image locking
57
iotests: 055: Don't attach the target image already for drive-backup
58
iotests: 085: Avoid image locking conflict
59
iotests: 087: Don't attach test image twice
60
iotests: 091: Quit QEMU before checking image
61
iotests: 172: Use separate images for multiple devices
62
tests: Use null-co:// instead of /dev/null as the dummy image
63
file-posix: Add 'locking' option
64
file-win32: Error out if locking=on
65
tests: Disable image lock in test-replication
66
block: Reuse bs as backing hd for drive-backup sync=none
67
osdep: Add qemu_lock_fd and qemu_unlock_fd
68
osdep: Fall back to posix lock when OFD lock is unavailable
69
file-posix: Add image locking to perm operations
70
qemu-iotests: Add test case 153 for image locking
71
tests: Add POSIX image locking test case 182
72
73
John Snow (1):
74
blockdev: use drained_begin/end for qmp_block_resize
75
76
Kevin Wolf (7):
77
migration: Unify block node activation error handling
78
block: New BdrvChildRole.activate() for blk_resume_after_migration()
79
block: Drop permissions when migration completes
80
block: Inactivate parents before children
81
block: Fix write/resize permissions for inactive images
82
file-posix: Remove .bdrv_inactivate/invalidate_cache
83
Merge remote-tracking branch 'mreitz/tags/pull-block-2017-05-11' into queue-block
84
85
Max Reitz (5):
86
qcow2: Fix preallocation size formula
87
qcow2: Reuse preallocated zero clusters
88
qcow2: Discard preallocated zero clusters
89
iotests: Extend test 066
90
MAINTAINERS: Add qemu-progress to the block layer
91
92
MAINTAINERS | 1 +
93
block.c | 127 +++++++++++--
94
block/blkdebug.c | 264 +++++++++++++++++++++-----
95
block/block-backend.c | 81 +++++---
96
block/file-posix.c | 248 +++++++++++++++++++++++-
97
block/file-win32.c | 5 +
98
block/qcow2-cluster.c | 252 ++++++++++++++----------
99
block/qcow2-refcount.c | 148 +++++++--------
100
block/qcow2-snapshot.c | 7 +-
101
block/qcow2.c | 47 +++--
102
block/qcow2.h | 26 ++-
103
blockdev.c | 20 +-
104
hw/block/nvme.c | 26 +++
105
hw/block/nvme.h | 1 +
106
include/block/block.h | 41 ++--
107
include/block/block_int.h | 14 ++
108
include/qemu/osdep.h | 3 +
109
migration/migration.c | 13 +-
110
migration/savevm.c | 9 +-
111
qapi/block-core.json | 40 +++-
112
qemu-img-cmds.hx | 36 ++--
113
qemu-img.c | 179 ++++++++++++-----
114
qemu-io-cmds.c | 61 +++---
115
qemu-io.c | 42 +++-
116
qmp.c | 18 +-
117
tests/drive_del-test.c | 2 +-
118
tests/nvme-test.c | 2 +-
119
tests/qemu-iotests/019.out | 8 +-
120
tests/qemu-iotests/030 | 18 +-
121
tests/qemu-iotests/046 | 2 +-
122
tests/qemu-iotests/055 | 32 ++--
123
tests/qemu-iotests/060.out | 6 +-
124
tests/qemu-iotests/066 | 128 ++++++++++++-
125
tests/qemu-iotests/066.out | 46 +++++
126
tests/qemu-iotests/085 | 33 ++--
127
tests/qemu-iotests/085.out | 3 +-
128
tests/qemu-iotests/087 | 6 +-
129
tests/qemu-iotests/091 | 2 +
130
tests/qemu-iotests/102.out | 4 +-
131
tests/qemu-iotests/122.out | 16 +-
132
tests/qemu-iotests/146.out | 30 +--
133
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++
134
tests/qemu-iotests/153.out | 390 ++++++++++++++++++++++++++++++++++++++
135
tests/qemu-iotests/154 | 160 +++++++++++++++-
136
tests/qemu-iotests/154.out | 158 +++++++++++++--
137
tests/qemu-iotests/172 | 55 +++---
138
tests/qemu-iotests/172.out | 50 ++---
139
tests/qemu-iotests/177 | 114 +++++++++++
140
tests/qemu-iotests/177.out | 49 +++++
141
tests/qemu-iotests/179 | 130 +++++++++++++
142
tests/qemu-iotests/179.out | 156 +++++++++++++++
143
tests/qemu-iotests/182 | 68 +++++++
144
tests/qemu-iotests/182.out | 8 +
145
tests/qemu-iotests/common.filter | 4 +-
146
tests/qemu-iotests/common.pattern | 2 +-
147
tests/qemu-iotests/group | 4 +
148
tests/test-replication.c | 9 +-
149
tests/usb-hcd-uhci-test.c | 2 +-
150
tests/usb-hcd-xhci-test.c | 2 +-
151
tests/virtio-blk-test.c | 2 +-
152
tests/virtio-scsi-test.c | 5 +-
153
util/osdep.c | 48 +++++
154
62 files changed, 3086 insertions(+), 610 deletions(-)
155
create mode 100755 tests/qemu-iotests/153
156
create mode 100644 tests/qemu-iotests/153.out
157
create mode 100755 tests/qemu-iotests/177
158
create mode 100644 tests/qemu-iotests/177.out
159
create mode 100755 tests/qemu-iotests/179
160
create mode 100644 tests/qemu-iotests/179.out
161
create mode 100755 tests/qemu-iotests/182
162
create mode 100644 tests/qemu-iotests/182.out
163
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
It can be used outside of block.c for making user friendly messages.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
block.c | 2 +-
9
include/block/block.h | 2 ++
10
2 files changed, 3 insertions(+), 1 deletion(-)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static char *bdrv_child_user_desc(BdrvChild *c)
17
return g_strdup("another user");
18
}
19
20
-static char *bdrv_perm_names(uint64_t perm)
21
+char *bdrv_perm_names(uint64_t perm)
22
{
23
struct perm_name {
24
uint64_t perm;
25
diff --git a/include/block/block.h b/include/block/block.h
26
index XXXXXXX..XXXXXXX 100644
27
--- a/include/block/block.h
28
+++ b/include/block/block.h
29
@@ -XXX,XX +XXX,XX @@ enum {
30
BLK_PERM_ALL = 0x1f,
31
};
32
33
+char *bdrv_perm_names(uint64_t perm);
34
+
35
/* disk I/O throttling */
36
void bdrv_init(void);
37
void bdrv_init_with_whitelist(void);
38
--
39
1.8.3.1
40
41
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
block.c | 17 +++++++++++++++++
7
include/block/block.h | 1 +
8
include/block/block_int.h | 1 +
9
qapi/block-core.json | 3 +++
10
4 files changed, 22 insertions(+)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
17
* the parent. */
18
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
19
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
20
+ qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
21
22
/* Inherit the read-only option from the parent if it's not set */
23
qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY);
24
@@ -XXX,XX +XXX,XX @@ static void bdrv_backing_options(int *child_flags, QDict *child_options,
25
* which is only applied on the top level (BlockBackend) */
26
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
27
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
28
+ qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
29
30
/* backing files always opened read-only */
31
qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on");
32
@@ -XXX,XX +XXX,XX @@ QemuOptsList bdrv_runtime_opts = {
33
.type = QEMU_OPT_STRING,
34
.help = "discard operation (ignore/off, unmap/on)",
35
},
36
+ {
37
+ .name = BDRV_OPT_FORCE_SHARE,
38
+ .type = QEMU_OPT_BOOL,
39
+ .help = "always accept other writers (default: off)",
40
+ },
41
{ /* end of list */ }
42
},
43
};
44
@@ -XXX,XX +XXX,XX @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
45
drv = bdrv_find_format(driver_name);
46
assert(drv != NULL);
47
48
+ bs->force_share = qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, false);
49
+
50
+ if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) {
51
+ error_setg(errp,
52
+ BDRV_OPT_FORCE_SHARE
53
+ "=on can only be used with read-only images");
54
+ ret = -EINVAL;
55
+ goto fail_opts;
56
+ }
57
+
58
if (file != NULL) {
59
filename = blk_bs(file)->filename;
60
} else {
61
diff --git a/include/block/block.h b/include/block/block.h
62
index XXXXXXX..XXXXXXX 100644
63
--- a/include/block/block.h
64
+++ b/include/block/block.h
65
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
66
#define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
67
#define BDRV_OPT_READ_ONLY "read-only"
68
#define BDRV_OPT_DISCARD "discard"
69
+#define BDRV_OPT_FORCE_SHARE "force-share"
70
71
72
#define BDRV_SECTOR_BITS 9
73
diff --git a/include/block/block_int.h b/include/block/block_int.h
74
index XXXXXXX..XXXXXXX 100644
75
--- a/include/block/block_int.h
76
+++ b/include/block/block_int.h
77
@@ -XXX,XX +XXX,XX @@ struct BlockDriverState {
78
bool valid_key; /* if true, a valid encryption key has been set */
79
bool sg; /* if true, the device is a /dev/sg* */
80
bool probed; /* if true, format was probed rather than specified */
81
+ bool force_share; /* if true, always allow all shared permissions */
82
83
BlockDriver *drv; /* NULL means no media */
84
void *opaque;
85
diff --git a/qapi/block-core.json b/qapi/block-core.json
86
index XXXXXXX..XXXXXXX 100644
87
--- a/qapi/block-core.json
88
+++ b/qapi/block-core.json
89
@@ -XXX,XX +XXX,XX @@
90
# (default: false)
91
# @detect-zeroes: detect and optimize zero writes (Since 2.1)
92
# (default: off)
93
+# @force-share: force share all permission on added nodes.
94
+# Requires read-only=true. (Since 2.10)
95
#
96
# Remaining options are determined by the block driver.
97
#
98
@@ -XXX,XX +XXX,XX @@
99
'*discard': 'BlockdevDiscardOptions',
100
'*cache': 'BlockdevCacheOptions',
101
'*read-only': 'bool',
102
+ '*force-share': 'bool',
103
'*detect-zeroes': 'BlockdevDetectZeroesOptions' },
104
'discriminator': 'driver',
105
'data': {
106
--
107
1.8.3.1
108
109
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
block.c | 32 ++++++++++++++++++++++++--------
7
1 file changed, 24 insertions(+), 8 deletions(-)
8
9
diff --git a/block.c b/block.c
10
index XXXXXXX..XXXXXXX 100644
11
--- a/block.c
12
+++ b/block.c
13
@@ -XXX,XX +XXX,XX @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
14
static void bdrv_child_abort_perm_update(BdrvChild *c);
15
static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
16
17
+static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
18
+ BdrvChild *c,
19
+ const BdrvChildRole *role,
20
+ uint64_t parent_perm, uint64_t parent_shared,
21
+ uint64_t *nperm, uint64_t *nshared)
22
+{
23
+ if (bs->drv && bs->drv->bdrv_child_perm) {
24
+ bs->drv->bdrv_child_perm(bs, c, role,
25
+ parent_perm, parent_shared,
26
+ nperm, nshared);
27
+ }
28
+ if (child_bs && child_bs->force_share) {
29
+ *nshared = BLK_PERM_ALL;
30
+ }
31
+}
32
+
33
/*
34
* Check whether permissions on this node can be changed in a way that
35
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
36
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
37
/* Check all children */
38
QLIST_FOREACH(c, &bs->children, next) {
39
uint64_t cur_perm, cur_shared;
40
- drv->bdrv_child_perm(bs, c, c->role,
41
- cumulative_perms, cumulative_shared_perms,
42
- &cur_perm, &cur_shared);
43
+ bdrv_child_perm(bs, c->bs, c, c->role,
44
+ cumulative_perms, cumulative_shared_perms,
45
+ &cur_perm, &cur_shared);
46
ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
47
errp);
48
if (ret < 0) {
49
@@ -XXX,XX +XXX,XX @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
50
/* Update all children */
51
QLIST_FOREACH(c, &bs->children, next) {
52
uint64_t cur_perm, cur_shared;
53
- drv->bdrv_child_perm(bs, c, c->role,
54
- cumulative_perms, cumulative_shared_perms,
55
- &cur_perm, &cur_shared);
56
+ bdrv_child_perm(bs, c->bs, c, c->role,
57
+ cumulative_perms, cumulative_shared_perms,
58
+ &cur_perm, &cur_shared);
59
bdrv_child_set_perm(c, cur_perm, cur_shared);
60
}
61
}
62
@@ -XXX,XX +XXX,XX @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
63
64
assert(parent_bs->drv);
65
assert(bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs));
66
- parent_bs->drv->bdrv_child_perm(parent_bs, NULL, child_role,
67
- perm, shared_perm, &perm, &shared_perm);
68
+ bdrv_child_perm(parent_bs, child_bs, NULL, child_role,
69
+ perm, shared_perm, &perm, &shared_perm);
70
71
child = bdrv_root_attach_child(child_bs, child_name, child_role,
72
perm, shared_perm, parent_bs, errp);
73
--
74
1.8.3.1
75
76
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
This will force the opened images to allow sharing all permissions with other
4
programs.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
qemu-img.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++---------------
10
1 file changed, 117 insertions(+), 36 deletions(-)
11
12
diff --git a/qemu-img.c b/qemu-img.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/qemu-img.c
15
+++ b/qemu-img.c
16
@@ -XXX,XX +XXX,XX @@
17
#include "qapi/qobject-output-visitor.h"
18
#include "qapi/qmp/qerror.h"
19
#include "qapi/qmp/qjson.h"
20
+#include "qapi/qmp/qbool.h"
21
#include "qemu/cutils.h"
22
#include "qemu/config-file.h"
23
#include "qemu/option.h"
24
@@ -XXX,XX +XXX,XX @@ static int img_open_password(BlockBackend *blk, const char *filename,
25
26
static BlockBackend *img_open_opts(const char *optstr,
27
QemuOpts *opts, int flags, bool writethrough,
28
- bool quiet)
29
+ bool quiet, bool force_share)
30
{
31
QDict *options;
32
Error *local_err = NULL;
33
BlockBackend *blk;
34
options = qemu_opts_to_qdict(opts, NULL);
35
+ if (force_share) {
36
+ if (qdict_haskey(options, BDRV_OPT_FORCE_SHARE)
37
+ && !qdict_get_bool(options, BDRV_OPT_FORCE_SHARE)) {
38
+ error_report("--force-share/-U conflicts with image options");
39
+ return NULL;
40
+ }
41
+ qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
42
+ }
43
blk = blk_new_open(NULL, NULL, options, flags, &local_err);
44
if (!blk) {
45
error_reportf_err(local_err, "Could not open '%s': ", optstr);
46
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open_opts(const char *optstr,
47
48
static BlockBackend *img_open_file(const char *filename,
49
const char *fmt, int flags,
50
- bool writethrough, bool quiet)
51
+ bool writethrough, bool quiet,
52
+ bool force_share)
53
{
54
BlockBackend *blk;
55
Error *local_err = NULL;
56
- QDict *options = NULL;
57
+ QDict *options = qdict_new();
58
59
if (fmt) {
60
- options = qdict_new();
61
qdict_put_str(options, "driver", fmt);
62
}
63
64
+ if (force_share) {
65
+ qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
66
+ }
67
blk = blk_new_open(filename, NULL, options, flags, &local_err);
68
if (!blk) {
69
error_reportf_err(local_err, "Could not open '%s': ", filename);
70
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open_file(const char *filename,
71
static BlockBackend *img_open(bool image_opts,
72
const char *filename,
73
const char *fmt, int flags, bool writethrough,
74
- bool quiet)
75
+ bool quiet, bool force_share)
76
{
77
BlockBackend *blk;
78
if (image_opts) {
79
@@ -XXX,XX +XXX,XX @@ static BlockBackend *img_open(bool image_opts,
80
if (!opts) {
81
return NULL;
82
}
83
- blk = img_open_opts(filename, opts, flags, writethrough, quiet);
84
+ blk = img_open_opts(filename, opts, flags, writethrough, quiet,
85
+ force_share);
86
} else {
87
- blk = img_open_file(filename, fmt, flags, writethrough, quiet);
88
+ blk = img_open_file(filename, fmt, flags, writethrough, quiet,
89
+ force_share);
90
}
91
return blk;
92
}
93
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
94
ImageCheck *check;
95
bool quiet = false;
96
bool image_opts = false;
97
+ bool force_share = false;
98
99
fmt = NULL;
100
output = NULL;
101
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
102
{"output", required_argument, 0, OPTION_OUTPUT},
103
{"object", required_argument, 0, OPTION_OBJECT},
104
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
105
+ {"force-share", no_argument, 0, 'U'},
106
{0, 0, 0, 0}
107
};
108
- c = getopt_long(argc, argv, ":hf:r:T:q",
109
+ c = getopt_long(argc, argv, ":hf:r:T:qU",
110
long_options, &option_index);
111
if (c == -1) {
112
break;
113
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
114
case 'q':
115
quiet = true;
116
break;
117
+ case 'U':
118
+ force_share = true;
119
+ break;
120
case OPTION_OBJECT: {
121
QemuOpts *opts;
122
opts = qemu_opts_parse_noisily(&qemu_object_opts,
123
@@ -XXX,XX +XXX,XX @@ static int img_check(int argc, char **argv)
124
return 1;
125
}
126
127
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
128
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
129
+ force_share);
130
if (!blk) {
131
return 1;
132
}
133
@@ -XXX,XX +XXX,XX @@ static int img_commit(int argc, char **argv)
134
return 1;
135
}
136
137
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
138
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
139
+ false);
140
if (!blk) {
141
return 1;
142
}
143
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
144
int c, pnum;
145
uint64_t progress_base;
146
bool image_opts = false;
147
+ bool force_share = false;
148
149
cache = BDRV_DEFAULT_CACHE;
150
for (;;) {
151
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
152
{"help", no_argument, 0, 'h'},
153
{"object", required_argument, 0, OPTION_OBJECT},
154
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
155
+ {"force-share", no_argument, 0, 'U'},
156
{0, 0, 0, 0}
157
};
158
- c = getopt_long(argc, argv, ":hf:F:T:pqs",
159
+ c = getopt_long(argc, argv, ":hf:F:T:pqsU",
160
long_options, NULL);
161
if (c == -1) {
162
break;
163
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
164
case 's':
165
strict = true;
166
break;
167
+ case 'U':
168
+ force_share = true;
169
+ break;
170
case OPTION_OBJECT: {
171
QemuOpts *opts;
172
opts = qemu_opts_parse_noisily(&qemu_object_opts,
173
@@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv)
174
goto out3;
175
}
176
177
- blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet);
178
+ blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet,
179
+ force_share);
180
if (!blk1) {
181
ret = 2;
182
goto out3;
183
}
184
185
- blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet);
186
+ blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet,
187
+ force_share);
188
if (!blk2) {
189
ret = 2;
190
goto out2;
191
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
192
bool writethrough, src_writethrough, quiet = false, image_opts = false,
193
skip_create = false, progress = false;
194
int64_t ret = -EINVAL;
195
+ bool force_share = false;
196
197
ImgConvertState s = (ImgConvertState) {
198
/* Need at least 4k of zeros for sparse detection */
199
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
200
{"help", no_argument, 0, 'h'},
201
{"object", required_argument, 0, OPTION_OBJECT},
202
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
203
+ {"force-share", no_argument, 0, 'U'},
204
{0, 0, 0, 0}
205
};
206
- c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:W",
207
+ c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:WU",
208
long_options, NULL);
209
if (c == -1) {
210
break;
211
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
212
case 'W':
213
s.wr_in_order = false;
214
break;
215
+ case 'U':
216
+ force_share = true;
217
+ break;
218
case OPTION_OBJECT: {
219
QemuOpts *object_opts;
220
object_opts = qemu_opts_parse_noisily(&qemu_object_opts,
221
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
222
223
for (bs_i = 0; bs_i < s.src_num; bs_i++) {
224
s.src[bs_i] = img_open(image_opts, argv[optind + bs_i],
225
- fmt, src_flags, src_writethrough, quiet);
226
+ fmt, src_flags, src_writethrough, quiet,
227
+ force_share);
228
if (!s.src[bs_i]) {
229
ret = -1;
230
goto out;
231
@@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv)
232
* the bdrv_create() call which takes different params.
233
* Not critical right now, so fix can wait...
234
*/
235
- s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet);
236
+ s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet,
237
+ false);
238
if (!s.target) {
239
ret = -1;
240
goto out;
241
@@ -XXX,XX +XXX,XX @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b)
242
static ImageInfoList *collect_image_info_list(bool image_opts,
243
const char *filename,
244
const char *fmt,
245
- bool chain)
246
+ bool chain, bool force_share)
247
{
248
ImageInfoList *head = NULL;
249
ImageInfoList **last = &head;
250
@@ -XXX,XX +XXX,XX @@ static ImageInfoList *collect_image_info_list(bool image_opts,
251
g_hash_table_insert(filenames, (gpointer)filename, NULL);
252
253
blk = img_open(image_opts, filename, fmt,
254
- BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false);
255
+ BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false,
256
+ force_share);
257
if (!blk) {
258
goto err;
259
}
260
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
261
const char *filename, *fmt, *output;
262
ImageInfoList *list;
263
bool image_opts = false;
264
+ bool force_share = false;
265
266
fmt = NULL;
267
output = NULL;
268
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
269
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
270
{"object", required_argument, 0, OPTION_OBJECT},
271
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
272
+ {"force-share", no_argument, 0, 'U'},
273
{0, 0, 0, 0}
274
};
275
- c = getopt_long(argc, argv, ":f:h",
276
+ c = getopt_long(argc, argv, ":f:hU",
277
long_options, &option_index);
278
if (c == -1) {
279
break;
280
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
281
case 'f':
282
fmt = optarg;
283
break;
284
+ case 'U':
285
+ force_share = true;
286
+ break;
287
case OPTION_OUTPUT:
288
output = optarg;
289
break;
290
@@ -XXX,XX +XXX,XX @@ static int img_info(int argc, char **argv)
291
return 1;
292
}
293
294
- list = collect_image_info_list(image_opts, filename, fmt, chain);
295
+ list = collect_image_info_list(image_opts, filename, fmt, chain,
296
+ force_share);
297
if (!list) {
298
return 1;
299
}
300
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
301
MapEntry curr = { .length = 0 }, next;
302
int ret = 0;
303
bool image_opts = false;
304
+ bool force_share = false;
305
306
fmt = NULL;
307
output = NULL;
308
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
309
{"output", required_argument, 0, OPTION_OUTPUT},
310
{"object", required_argument, 0, OPTION_OBJECT},
311
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
312
+ {"force-share", no_argument, 0, 'U'},
313
{0, 0, 0, 0}
314
};
315
- c = getopt_long(argc, argv, ":f:h",
316
+ c = getopt_long(argc, argv, ":f:hU",
317
long_options, &option_index);
318
if (c == -1) {
319
break;
320
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
321
case 'f':
322
fmt = optarg;
323
break;
324
+ case 'U':
325
+ force_share = true;
326
+ break;
327
case OPTION_OUTPUT:
328
output = optarg;
329
break;
330
@@ -XXX,XX +XXX,XX @@ static int img_map(int argc, char **argv)
331
return 1;
332
}
333
334
- blk = img_open(image_opts, filename, fmt, 0, false, false);
335
+ blk = img_open(image_opts, filename, fmt, 0, false, false, force_share);
336
if (!blk) {
337
return 1;
338
}
339
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
340
bool quiet = false;
341
Error *err = NULL;
342
bool image_opts = false;
343
+ bool force_share = false;
344
345
bdrv_oflags = BDRV_O_RDWR;
346
/* Parse commandline parameters */
347
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
348
{"help", no_argument, 0, 'h'},
349
{"object", required_argument, 0, OPTION_OBJECT},
350
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
351
+ {"force-share", no_argument, 0, 'U'},
352
{0, 0, 0, 0}
353
};
354
- c = getopt_long(argc, argv, ":la:c:d:hq",
355
+ c = getopt_long(argc, argv, ":la:c:d:hqU",
356
long_options, NULL);
357
if (c == -1) {
358
break;
359
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
360
case 'q':
361
quiet = true;
362
break;
363
+ case 'U':
364
+ force_share = true;
365
+ break;
366
case OPTION_OBJECT: {
367
QemuOpts *opts;
368
opts = qemu_opts_parse_noisily(&qemu_object_opts,
369
@@ -XXX,XX +XXX,XX @@ static int img_snapshot(int argc, char **argv)
370
}
371
372
/* Open the image */
373
- blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet);
374
+ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet,
375
+ force_share);
376
if (!blk) {
377
return 1;
378
}
379
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
380
int c, flags, src_flags, ret;
381
bool writethrough, src_writethrough;
382
int unsafe = 0;
383
+ bool force_share = false;
384
int progress = 0;
385
bool quiet = false;
386
Error *local_err = NULL;
387
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
388
{"help", no_argument, 0, 'h'},
389
{"object", required_argument, 0, OPTION_OBJECT},
390
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
391
+ {"force-share", no_argument, 0, 'U'},
392
{0, 0, 0, 0}
393
};
394
- c = getopt_long(argc, argv, ":hf:F:b:upt:T:q",
395
+ c = getopt_long(argc, argv, ":hf:F:b:upt:T:qU",
396
long_options, NULL);
397
if (c == -1) {
398
break;
399
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
400
case OPTION_IMAGE_OPTS:
401
image_opts = true;
402
break;
403
+ case 'U':
404
+ force_share = true;
405
+ break;
406
}
407
}
408
409
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
410
* Ignore the old backing file for unsafe rebase in case we want to correct
411
* the reference to a renamed or moved backing file.
412
*/
413
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
414
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
415
+ false);
416
if (!blk) {
417
ret = -1;
418
goto out;
419
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
420
qdict_put_str(options, "driver", bs->backing_format);
421
}
422
423
+ if (force_share) {
424
+ if (!options) {
425
+ options = qdict_new();
426
+ }
427
+ qdict_put(options, BDRV_OPT_FORCE_SHARE,
428
+ qbool_from_bool(true));
429
+ }
430
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
431
blk_old_backing = blk_new_open(backing_name, NULL,
432
options, src_flags, &local_err);
433
@@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv)
434
}
435
436
if (out_baseimg[0]) {
437
+ options = qdict_new();
438
if (out_basefmt) {
439
- options = qdict_new();
440
qdict_put_str(options, "driver", out_basefmt);
441
- } else {
442
- options = NULL;
443
+ }
444
+ if (force_share) {
445
+ qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
446
}
447
448
blk_new_backing = blk_new_open(out_baseimg, NULL,
449
@@ -XXX,XX +XXX,XX @@ static int img_resize(int argc, char **argv)
450
qemu_opts_del(param);
451
452
blk = img_open(image_opts, filename, fmt,
453
- BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);
454
+ BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet,
455
+ false);
456
if (!blk) {
457
ret = -1;
458
goto out;
459
@@ -XXX,XX +XXX,XX @@ static int img_amend(int argc, char **argv)
460
goto out;
461
}
462
463
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
464
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
465
+ false);
466
if (!blk) {
467
ret = -1;
468
goto out;
469
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
470
bool writethrough = false;
471
struct timeval t1, t2;
472
int i;
473
+ bool force_share = false;
474
475
for (;;) {
476
static const struct option long_options[] = {
477
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
478
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
479
{"pattern", required_argument, 0, OPTION_PATTERN},
480
{"no-drain", no_argument, 0, OPTION_NO_DRAIN},
481
+ {"force-share", no_argument, 0, 'U'},
482
{0, 0, 0, 0}
483
};
484
- c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options, NULL);
485
+ c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:wU", long_options, NULL);
486
if (c == -1) {
487
break;
488
}
489
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
490
flags |= BDRV_O_RDWR;
491
is_write = true;
492
break;
493
+ case 'U':
494
+ force_share = true;
495
+ break;
496
case OPTION_PATTERN:
497
{
498
unsigned long res;
499
@@ -XXX,XX +XXX,XX @@ static int img_bench(int argc, char **argv)
500
goto out;
501
}
502
503
- blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
504
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
505
+ force_share);
506
if (!blk) {
507
ret = -1;
508
goto out;
509
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
510
const char *fmt = NULL;
511
int64_t size = 0;
512
int64_t block_count = 0, out_pos, in_pos;
513
+ bool force_share = false;
514
struct DdInfo dd = {
515
.flags = 0,
516
.count = 0,
517
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
518
const struct option long_options[] = {
519
{ "help", no_argument, 0, 'h'},
520
{ "image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
521
+ { "force-share", no_argument, 0, 'U'},
522
{ 0, 0, 0, 0 }
523
};
524
525
- while ((c = getopt_long(argc, argv, ":hf:O:", long_options, NULL))) {
526
+ while ((c = getopt_long(argc, argv, ":hf:O:U", long_options, NULL))) {
527
if (c == EOF) {
528
break;
529
}
530
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
531
case 'h':
532
help();
533
break;
534
+ case 'U':
535
+ force_share = true;
536
+ break;
537
case OPTION_IMAGE_OPTS:
538
image_opts = true;
539
break;
540
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
541
ret = -1;
542
goto out;
543
}
544
- blk1 = img_open(image_opts, in.filename, fmt, 0, false, false);
545
+ blk1 = img_open(image_opts, in.filename, fmt, 0, false, false,
546
+ force_share);
547
548
if (!blk1) {
549
ret = -1;
550
@@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv)
551
}
552
553
blk2 = img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR,
554
- false, false);
555
+ false, false, false);
556
557
if (!blk2) {
558
ret = -1;
559
--
560
1.8.3.1
561
562
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
qemu-img-cmds.hx | 36 ++++++++++++++++++------------------
7
1 file changed, 18 insertions(+), 18 deletions(-)
8
9
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
10
index XXXXXXX..XXXXXXX 100644
11
--- a/qemu-img-cmds.hx
12
+++ b/qemu-img-cmds.hx
13
@@ -XXX,XX +XXX,XX @@ STEXI
14
ETEXI
15
16
DEF("bench", img_bench,
17
- "bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] [-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename")
18
+ "bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] [-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] [-U] filename")
19
STEXI
20
-@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] [--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename}
21
+@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] [--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] [-U] @var{filename}
22
ETEXI
23
24
DEF("check", img_check,
25
- "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename")
26
+ "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] [-U] filename")
27
STEXI
28
-@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename}
29
+@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] [-U] @var{filename}
30
ETEXI
31
32
DEF("create", img_create,
33
@@ -XXX,XX +XXX,XX @@ STEXI
34
ETEXI
35
36
DEF("compare", img_compare,
37
- "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 filename2")
38
+ "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] filename1 filename2")
39
STEXI
40
-@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
41
+@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] [-U] @var{filename1} @var{filename2}
42
ETEXI
43
44
DEF("convert", img_convert,
45
- "convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
46
+ "convert [--object objectdef] [--image-opts] [-U] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_filename")
47
STEXI
48
-@item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename}
49
+@item convert [--object @var{objectdef}] [--image-opts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @var{output_filename}
50
ETEXI
51
52
DEF("dd", img_dd,
53
- "dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] if=input of=output")
54
+ "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] if=input of=output")
55
STEXI
56
-@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
57
+@item dd [--image-opts] [-U] [-f @var{fmt}] [-O @var{output_fmt}] [bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} of=@var{output}
58
ETEXI
59
60
DEF("info", img_info,
61
- "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] filename")
62
+ "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] [-U] filename")
63
STEXI
64
-@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] @var{filename}
65
+@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [--backing-chain] [-U] @var{filename}
66
ETEXI
67
68
DEF("map", img_map,
69
- "map [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] filename")
70
+ "map [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-U] filename")
71
STEXI
72
-@item map [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] @var{filename}
73
+@item map [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [--output=@var{ofmt}] [-U] @var{filename}
74
ETEXI
75
76
DEF("snapshot", img_snapshot,
77
- "snapshot [--object objectdef] [--image-opts] [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
78
+ "snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
79
STEXI
80
-@item snapshot [--object @var{objectdef}] [--image-opts] [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
81
+@item snapshot [--object @var{objectdef}] [--image-opts] [-U] [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
82
ETEXI
83
84
DEF("rebase", img_rebase,
85
- "rebase [--object objectdef] [--image-opts] [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
86
+ "rebase [--object objectdef] [--image-opts] [-U] [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
87
STEXI
88
-@item rebase [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
89
+@item rebase [--object @var{objectdef}] [--image-opts] [-U] [-q] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
90
ETEXI
91
92
DEF("resize", img_resize,
93
--
94
1.8.3.1
95
96
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Add --force-share/-U to program options and -U to open subcommand.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
qemu-io.c | 42 ++++++++++++++++++++++++++++++++++--------
9
1 file changed, 34 insertions(+), 8 deletions(-)
10
11
diff --git a/qemu-io.c b/qemu-io.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/qemu-io.c
14
+++ b/qemu-io.c
15
@@ -XXX,XX +XXX,XX @@
16
#include "qemu/readline.h"
17
#include "qemu/log.h"
18
#include "qapi/qmp/qstring.h"
19
+#include "qapi/qmp/qbool.h"
20
#include "qom/object_interfaces.h"
21
#include "sysemu/block-backend.h"
22
#include "block/block_int.h"
23
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t close_cmd = {
24
.oneline = "close the current open file",
25
};
26
27
-static int openfile(char *name, int flags, bool writethrough, QDict *opts)
28
+static int openfile(char *name, int flags, bool writethrough, bool force_share,
29
+ QDict *opts)
30
{
31
Error *local_err = NULL;
32
BlockDriverState *bs;
33
@@ -XXX,XX +XXX,XX @@ static int openfile(char *name, int flags, bool writethrough, QDict *opts)
34
return 1;
35
}
36
37
+ if (force_share) {
38
+ if (!opts) {
39
+ opts = qdict_new();
40
+ }
41
+ if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
42
+ && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
43
+ error_report("-U conflicts with image options");
44
+ QDECREF(opts);
45
+ return 1;
46
+ }
47
+ qdict_put(opts, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
48
+ }
49
qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err);
50
if (!qemuio_blk) {
51
error_reportf_err(local_err, "can't open%s%s: ",
52
@@ -XXX,XX +XXX,XX @@ static void open_help(void)
53
" -r, -- open file read-only\n"
54
" -s, -- use snapshot file\n"
55
" -n, -- disable host cache, short for -t none\n"
56
+" -U, -- force shared permissions\n"
57
" -k, -- use kernel AIO implementation (on Linux only)\n"
58
" -t, -- use the given cache mode for the image\n"
59
" -d, -- use the given discard mode for the image\n"
60
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t open_cmd = {
61
.argmin = 1,
62
.argmax = -1,
63
.flags = CMD_NOFILE_OK,
64
- .args = "[-rsnk] [-t cache] [-d discard] [-o options] [path]",
65
+ .args = "[-rsnkU] [-t cache] [-d discard] [-o options] [path]",
66
.oneline = "open the file specified by path",
67
.help = open_help,
68
};
69
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
70
int c;
71
QemuOpts *qopts;
72
QDict *opts;
73
+ bool force_share = false;
74
75
- while ((c = getopt(argc, argv, "snro:kt:d:")) != -1) {
76
+ while ((c = getopt(argc, argv, "snro:kt:d:U")) != -1) {
77
switch (c) {
78
case 's':
79
flags |= BDRV_O_SNAPSHOT;
80
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
81
return 0;
82
}
83
break;
84
+ case 'U':
85
+ force_share = true;
86
+ break;
87
default:
88
qemu_opts_reset(&empty_opts);
89
return qemuio_command_usage(&open_cmd);
90
@@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv)
91
qemu_opts_reset(&empty_opts);
92
93
if (optind == argc - 1) {
94
- return openfile(argv[optind], flags, writethrough, opts);
95
+ return openfile(argv[optind], flags, writethrough, force_share, opts);
96
} else if (optind == argc) {
97
- return openfile(NULL, flags, writethrough, opts);
98
+ return openfile(NULL, flags, writethrough, force_share, opts);
99
} else {
100
QDECREF(opts);
101
return qemuio_command_usage(&open_cmd);
102
@@ -XXX,XX +XXX,XX @@ static void usage(const char *name)
103
" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
104
" specify tracing options\n"
105
" see qemu-img(1) man page for full description\n"
106
+" -U, --force-share force shared permissions\n"
107
" -h, --help display this help and exit\n"
108
" -V, --version output version information and exit\n"
109
"\n"
110
@@ -XXX,XX +XXX,XX @@ static QemuOptsList file_opts = {
111
int main(int argc, char **argv)
112
{
113
int readonly = 0;
114
- const char *sopt = "hVc:d:f:rsnmkt:T:";
115
+ const char *sopt = "hVc:d:f:rsnmkt:T:U";
116
const struct option lopt[] = {
117
{ "help", no_argument, NULL, 'h' },
118
{ "version", no_argument, NULL, 'V' },
119
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
120
{ "trace", required_argument, NULL, 'T' },
121
{ "object", required_argument, NULL, OPTION_OBJECT },
122
{ "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
123
+ { "force-share", no_argument, 0, 'U'},
124
{ NULL, 0, NULL, 0 }
125
};
126
int c;
127
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
128
QDict *opts = NULL;
129
const char *format = NULL;
130
char *trace_file = NULL;
131
+ bool force_share = false;
132
133
#ifdef CONFIG_POSIX
134
signal(SIGPIPE, SIG_IGN);
135
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
136
case 'h':
137
usage(progname);
138
exit(0);
139
+ case 'U':
140
+ force_share = true;
141
+ break;
142
case OPTION_OBJECT: {
143
QemuOpts *qopts;
144
qopts = qemu_opts_parse_noisily(&qemu_object_opts,
145
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
146
exit(1);
147
}
148
opts = qemu_opts_to_qdict(qopts, NULL);
149
- if (openfile(NULL, flags, writethrough, opts)) {
150
+ if (openfile(NULL, flags, writethrough, force_share, opts)) {
151
exit(1);
152
}
153
} else {
154
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
155
opts = qdict_new();
156
qdict_put_str(opts, "driver", format);
157
}
158
- if (openfile(argv[optind], flags, writethrough, opts)) {
159
+ if (openfile(argv[optind], flags, writethrough,
160
+ force_share, opts)) {
161
exit(1);
162
}
163
}
164
--
165
1.8.3.1
166
167
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
qemu-img and qemu-io commands when guest is running need "-U" option,
4
add it.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
tests/qemu-iotests/030 | 18 +++++++++---------
10
1 file changed, 9 insertions(+), 9 deletions(-)
11
12
diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/030
15
+++ b/tests/qemu-iotests/030
16
@@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase):
17
def test_stream_intermediate(self):
18
self.assert_no_active_block_jobs()
19
20
- self.assertNotEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img),
21
- qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img),
22
+ self.assertNotEqual(qemu_io('-f', 'raw', '-rU', '-c', 'map', backing_img),
23
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', mid_img),
24
'image file map matches backing file before streaming')
25
26
result = self.vm.qmp('block-stream', device='mid', job_id='stream-mid')
27
@@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase):
28
self.assert_no_active_block_jobs()
29
30
# The image map is empty before the operation
31
- empty_map = qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img)
32
+ empty_map = qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', test_img)
33
34
# This is a no-op: no data should ever be copied from the base image
35
result = self.vm.qmp('block-stream', device='drive0', base=mid_img)
36
@@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase):
37
38
# Check that the maps don't match before the streaming operations
39
for i in range(2, self.num_imgs, 2):
40
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i]),
41
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i-1]),
42
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i]),
43
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i-1]),
44
'image file map matches backing file before streaming')
45
46
# Create all streaming jobs
47
@@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase):
48
def test_stream_base_node_name(self):
49
self.assert_no_active_block_jobs()
50
51
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[4]),
52
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[3]),
53
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[4]),
54
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[3]),
55
'image file map matches backing file before streaming')
56
57
# Error: the base node does not exist
58
@@ -XXX,XX +XXX,XX @@ class TestQuorum(iotests.QMPTestCase):
59
if not iotests.supports_quorum():
60
return
61
62
- self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.children[0]),
63
- qemu_io('-f', iotests.imgfmt, '-c', 'map', self.backing[0]),
64
+ self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.children[0]),
65
+ qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.backing[0]),
66
'image file map matches backing file before streaming')
67
68
self.assert_no_active_block_jobs()
69
--
70
1.8.3.1
71
72
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The qemu-img info command is executed while VM is running, add -U option
4
to avoid the image locking error.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
tests/qemu-iotests/046 | 2 +-
10
1 file changed, 1 insertion(+), 1 deletion(-)
11
12
diff --git a/tests/qemu-iotests/046 b/tests/qemu-iotests/046
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/046
15
+++ b/tests/qemu-iotests/046
16
@@ -XXX,XX +XXX,XX @@ echo "== Verify image content =="
17
18
function verify_io()
19
{
20
- if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
21
+ if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
22
# For v2 images, discarded clusters are read from the backing file
23
# Keep the variable empty so that the backing file value can be used as
24
# the default below
25
--
26
1.8.3.1
27
28
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
Opening the backing image for the second time is bad, especially here
3
Waiting for all active writes to settle before daring to create a
4
when it is also in use as the active image as the source. The
4
background copying operation means that we will never do background
5
drive-backup job itself doesn't read from target->backing for COW,
5
operations while the guest does anything (in write-blocking mode), and
6
instead it gets data from the write notifier, so it's not a big problem.
6
therefore cannot converge. Yes, we also will not diverge, but actually
7
However, exporting the target to NBD etc. won't work, because of the
7
converging would be even nicer.
8
likely stale metadata cache.
9
8
10
Use BDRV_O_NO_BACKING in this case and manually set up the backing
9
It is unclear why we did decide to wait for all active writes to settle
11
BdrvChild.
10
before creating a background operation, but it just does not seem
11
necessary. Active writes will put themselves into the in_flight bitmap
12
and thus properly block actually conflicting background requests.
12
13
13
Cc: qemu-stable@nongnu.org
14
It is important for active requests to wait on overlapping background
14
Signed-off-by: Fam Zheng <famz@redhat.com>
15
requests, which we do in active_write_prepare(). However, so far it was
16
not documented why it is important. Add such documentation now, and
17
also to the other call of mirror_wait_on_conflicts(), so that it becomes
18
more clear why and when requests need to actively wait for other
19
requests to settle.
20
21
Another thing to note is that of course we need to ensure that there are
22
no active requests when the job completes, but that is done by virtue of
23
the BDS being drained anyway, so there cannot be any active requests at
24
that point.
25
26
With this change, we will need to explicitly keep track of how many
27
bytes are in flight in active requests so that
28
job_progress_set_remaining() in mirror_run() can set the correct number
29
of remaining bytes.
30
31
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2123297
32
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
33
Message-Id: <20221109165452.67927-2-hreitz@redhat.com>
34
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
35
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
36
---
17
blockdev.c | 15 ++++++++++++++-
37
block/mirror.c | 37 ++++++++++++++++++++++++++++++-------
18
1 file changed, 14 insertions(+), 1 deletion(-)
38
1 file changed, 30 insertions(+), 7 deletions(-)
19
39
20
diff --git a/blockdev.c b/blockdev.c
40
diff --git a/block/mirror.c b/block/mirror.c
21
index XXXXXXX..XXXXXXX 100644
41
index XXXXXXX..XXXXXXX 100644
22
--- a/blockdev.c
42
--- a/block/mirror.c
23
+++ b/blockdev.c
43
+++ b/block/mirror.c
24
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
44
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorBlockJob {
25
Error *local_err = NULL;
45
int max_iov;
26
int flags;
46
bool initial_zeroing_ongoing;
27
int64_t size;
47
int in_active_write_counter;
28
+ bool set_backing_hd = false;
48
+ int64_t active_write_bytes_in_flight;
29
49
bool prepared;
30
if (!backup->has_speed) {
50
bool in_drain;
31
backup->speed = 0;
51
} MirrorBlockJob;
32
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
52
@@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
33
}
53
}
34
if (backup->sync == MIRROR_SYNC_MODE_NONE) {
54
bdrv_dirty_bitmap_unlock(s->dirty_bitmap);
35
source = bs;
55
36
+ flags |= BDRV_O_NO_BACKING;
56
+ /*
37
+ set_backing_hd = true;
57
+ * Wait for concurrent requests to @offset. The next loop will limit the
58
+ * copied area based on in_flight_bitmap so we only copy an area that does
59
+ * not overlap with concurrent in-flight requests. Still, we would like to
60
+ * copy something, so wait until there are at least no more requests to the
61
+ * very beginning of the area.
62
+ */
63
mirror_wait_on_conflicts(NULL, s, offset, 1);
64
65
job_pause_point(&s->common.job);
66
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
67
int64_t cnt, delta;
68
bool should_complete;
69
70
- /* Do not start passive operations while there are active
71
- * writes in progress */
72
- while (s->in_active_write_counter) {
73
- mirror_wait_for_any_operation(s, true);
74
- }
75
-
76
if (s->ret < 0) {
77
ret = s->ret;
78
goto immediate_exit;
79
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
80
/* cnt is the number of dirty bytes remaining and s->bytes_in_flight is
81
* the number of bytes currently being processed; together those are
82
* the current remaining operation length */
83
- job_progress_set_remaining(&s->common.job, s->bytes_in_flight + cnt);
84
+ job_progress_set_remaining(&s->common.job,
85
+ s->bytes_in_flight + cnt +
86
+ s->active_write_bytes_in_flight);
87
88
/* Note that even when no rate limit is applied we need to yield
89
* periodically with no pending I/O so that bdrv_drain_all() returns.
90
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
91
92
s->in_drain = true;
93
bdrv_drained_begin(bs);
94
+
95
+ /* Must be zero because we are drained */
96
+ assert(s->in_active_write_counter == 0);
97
+
98
cnt = bdrv_get_dirty_count(s->dirty_bitmap);
99
if (cnt > 0 || mirror_flush(s) < 0) {
100
bdrv_drained_end(bs);
101
@@ -XXX,XX +XXX,XX @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
38
}
102
}
39
103
40
size = bdrv_getlength(bs);
104
job_progress_increase_remaining(&job->common.job, bytes);
41
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
105
+ job->active_write_bytes_in_flight += bytes;
106
107
switch (method) {
108
case MIRROR_METHOD_COPY:
109
@@ -XXX,XX +XXX,XX @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
110
abort();
42
}
111
}
43
112
44
if (backup->format) {
113
+ job->active_write_bytes_in_flight -= bytes;
45
- options = qdict_new();
114
if (ret >= 0) {
46
+ if (!options) {
115
job_progress_update(&job->common.job, bytes);
47
+ options = qdict_new();
116
} else {
48
+ }
117
@@ -XXX,XX +XXX,XX @@ static MirrorOp *coroutine_fn active_write_prepare(MirrorBlockJob *s,
49
qdict_put_str(options, "driver", backup->format);
118
50
}
119
s->in_active_write_counter++;
51
120
52
@@ -XXX,XX +XXX,XX @@ static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn,
121
+ /*
53
122
+ * Wait for concurrent requests affecting the area. If there are already
54
bdrv_set_aio_context(target_bs, aio_context);
123
+ * running requests that are copying off now-to-be stale data in the area,
55
124
+ * we must wait for them to finish before we begin writing fresh data to the
56
+ if (set_backing_hd) {
125
+ * target so that the write operations appear in the correct order.
57
+ bdrv_set_backing_hd(target_bs, source, &local_err);
126
+ * Note that background requests (see mirror_iteration()) in contrast only
58
+ if (local_err) {
127
+ * wait for conflicting requests at the start of the dirty area, and then
59
+ bdrv_unref(target_bs);
128
+ * (based on the in_flight_bitmap) truncate the area to copy so it will not
60
+ goto out;
129
+ * conflict with any requests beyond that. For active writes, however, we
61
+ }
130
+ * cannot truncate that area. The request from our parent must be blocked
62
+ }
131
+ * until the area is copied in full. Therefore, we must wait for the whole
63
+
132
+ * area to become free of concurrent requests.
64
if (backup->has_bitmap) {
133
+ */
65
bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
134
mirror_wait_on_conflicts(op, s, offset, bytes);
66
if (!bmap) {
135
136
bitmap_set(s->in_flight_bitmap, start_chunk, end_chunk - start_chunk);
67
--
137
--
68
1.8.3.1
138
2.38.1
69
70
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
This extends the permission bits of op blocker API to external using
3
mirror_wait_for_free_in_flight_slot() is the only remaining user of
4
Linux OFD locks.
4
mirror_wait_for_any_operation(), so inline the latter into the former.
5
5
6
Each permission in @perm and @shared_perm is represented by a locked
6
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
7
byte in the image file. Requesting a permission in @perm is translated
7
Message-Id: <20221109165452.67927-3-hreitz@redhat.com>
8
to a shared lock of the corresponding byte; rejecting to share the same
8
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
permission is translated to a shared lock of a separate byte. With that,
10
we use 2x number of bytes of distinct permission types.
11
12
virtlockd in libvirt locks the first byte, so we do locking from a
13
higher offset.
14
15
Suggested-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Fam Zheng <famz@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
10
---
19
block/file-posix.c | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
11
block/mirror.c | 21 ++++++++-------------
20
1 file changed, 275 insertions(+), 1 deletion(-)
12
1 file changed, 8 insertions(+), 13 deletions(-)
21
13
22
diff --git a/block/file-posix.c b/block/file-posix.c
14
diff --git a/block/mirror.c b/block/mirror.c
23
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
24
--- a/block/file-posix.c
16
--- a/block/mirror.c
25
+++ b/block/file-posix.c
17
+++ b/block/mirror.c
26
@@ -XXX,XX +XXX,XX @@ do { \
18
@@ -XXX,XX +XXX,XX @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,
27
28
#define MAX_BLOCKSIZE    4096
29
30
+/* Posix file locking bytes. Libvirt takes byte 0, we start from higher bytes,
31
+ * leaving a few more bytes for its future use. */
32
+#define RAW_LOCK_PERM_BASE 100
33
+#define RAW_LOCK_SHARED_BASE 200
34
+
35
typedef struct BDRVRawState {
36
int fd;
37
+ int lock_fd;
38
+ bool use_lock;
39
int type;
40
int open_flags;
41
size_t buf_align;
42
43
+ /* The current permissions. */
44
+ uint64_t perm;
45
+ uint64_t shared_perm;
46
+
47
#ifdef CONFIG_XFS
48
bool is_xfs:1;
49
#endif
50
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
51
BlockdevAioOptions aio, aio_default;
52
int fd, ret;
53
struct stat st;
54
+ OnOffAuto locking;
55
56
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
57
qemu_opts_absorb_qdict(opts, options, &local_err);
58
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
59
}
60
s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
61
62
+ locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
63
+ ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err);
64
+ if (local_err) {
65
+ error_propagate(errp, local_err);
66
+ ret = -EINVAL;
67
+ goto fail;
68
+ }
69
+ switch (locking) {
70
+ case ON_OFF_AUTO_ON:
71
+ s->use_lock = true;
72
+#ifndef F_OFD_SETLK
73
+ fprintf(stderr,
74
+ "File lock requested but OFD locking syscall is unavailable, "
75
+ "falling back to POSIX file locks.\n"
76
+ "Due to the implementation, locks can be lost unexpectedly.\n");
77
+#endif
78
+ break;
79
+ case ON_OFF_AUTO_OFF:
80
+ s->use_lock = false;
81
+ break;
82
+ case ON_OFF_AUTO_AUTO:
83
+#ifdef F_OFD_SETLK
84
+ s->use_lock = true;
85
+#else
86
+ s->use_lock = false;
87
+#endif
88
+ break;
89
+ default:
90
+ abort();
91
+ }
92
+
93
s->open_flags = open_flags;
94
raw_parse_flags(bdrv_flags, &s->open_flags);
95
96
@@ -XXX,XX +XXX,XX @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
97
}
98
s->fd = fd;
99
100
+ s->lock_fd = -1;
101
+ if (s->use_lock) {
102
+ fd = qemu_open(filename, s->open_flags);
103
+ if (fd < 0) {
104
+ ret = -errno;
105
+ error_setg_errno(errp, errno, "Could not open '%s' for locking",
106
+ filename);
107
+ qemu_close(s->fd);
108
+ goto fail;
109
+ }
110
+ s->lock_fd = fd;
111
+ }
112
+ s->perm = 0;
113
+ s->shared_perm = BLK_PERM_ALL;
114
+
115
#ifdef CONFIG_LINUX_AIO
116
/* Currently Linux does AIO only for files opened with O_DIRECT */
117
if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) {
118
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
119
return raw_open_common(bs, options, flags, 0, errp);
120
}
19
}
121
20
122
+typedef enum {
21
static inline void coroutine_fn
123
+ RAW_PL_PREPARE,
22
-mirror_wait_for_any_operation(MirrorBlockJob *s, bool active)
124
+ RAW_PL_COMMIT,
23
+mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s)
125
+ RAW_PL_ABORT,
126
+} RawPermLockOp;
127
+
128
+#define PERM_FOREACH(i) \
129
+ for ((i) = 0; (1ULL << (i)) <= BLK_PERM_ALL; i++)
130
+
131
+/* Lock bytes indicated by @perm_lock_bits and @shared_perm_lock_bits in the
132
+ * file; if @unlock == true, also unlock the unneeded bytes.
133
+ * @shared_perm_lock_bits is the mask of all permissions that are NOT shared.
134
+ */
135
+static int raw_apply_lock_bytes(BDRVRawState *s,
136
+ uint64_t perm_lock_bits,
137
+ uint64_t shared_perm_lock_bits,
138
+ bool unlock, Error **errp)
139
+{
140
+ int ret;
141
+ int i;
142
+
143
+ PERM_FOREACH(i) {
144
+ int off = RAW_LOCK_PERM_BASE + i;
145
+ if (perm_lock_bits & (1ULL << i)) {
146
+ ret = qemu_lock_fd(s->lock_fd, off, 1, false);
147
+ if (ret) {
148
+ error_setg(errp, "Failed to lock byte %d", off);
149
+ return ret;
150
+ }
151
+ } else if (unlock) {
152
+ ret = qemu_unlock_fd(s->lock_fd, off, 1);
153
+ if (ret) {
154
+ error_setg(errp, "Failed to unlock byte %d", off);
155
+ return ret;
156
+ }
157
+ }
158
+ }
159
+ PERM_FOREACH(i) {
160
+ int off = RAW_LOCK_SHARED_BASE + i;
161
+ if (shared_perm_lock_bits & (1ULL << i)) {
162
+ ret = qemu_lock_fd(s->lock_fd, off, 1, false);
163
+ if (ret) {
164
+ error_setg(errp, "Failed to lock byte %d", off);
165
+ return ret;
166
+ }
167
+ } else if (unlock) {
168
+ ret = qemu_unlock_fd(s->lock_fd, off, 1);
169
+ if (ret) {
170
+ error_setg(errp, "Failed to unlock byte %d", off);
171
+ return ret;
172
+ }
173
+ }
174
+ }
175
+ return 0;
176
+}
177
+
178
+/* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. */
179
+static int raw_check_lock_bytes(BDRVRawState *s,
180
+ uint64_t perm, uint64_t shared_perm,
181
+ Error **errp)
182
+{
183
+ int ret;
184
+ int i;
185
+
186
+ PERM_FOREACH(i) {
187
+ int off = RAW_LOCK_SHARED_BASE + i;
188
+ uint64_t p = 1ULL << i;
189
+ if (perm & p) {
190
+ ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
191
+ if (ret) {
192
+ char *perm_name = bdrv_perm_names(p);
193
+ error_setg(errp,
194
+ "Failed to get \"%s\" lock",
195
+ perm_name);
196
+ g_free(perm_name);
197
+ error_append_hint(errp,
198
+ "Is another process using the image?\n");
199
+ return ret;
200
+ }
201
+ }
202
+ }
203
+ PERM_FOREACH(i) {
204
+ int off = RAW_LOCK_PERM_BASE + i;
205
+ uint64_t p = 1ULL << i;
206
+ if (!(shared_perm & p)) {
207
+ ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
208
+ if (ret) {
209
+ char *perm_name = bdrv_perm_names(p);
210
+ error_setg(errp,
211
+ "Failed to get shared \"%s\" lock",
212
+ perm_name);
213
+ g_free(perm_name);
214
+ error_append_hint(errp,
215
+ "Is another process using the image?\n");
216
+ return ret;
217
+ }
218
+ }
219
+ }
220
+ return 0;
221
+}
222
+
223
+static int raw_handle_perm_lock(BlockDriverState *bs,
224
+ RawPermLockOp op,
225
+ uint64_t new_perm, uint64_t new_shared,
226
+ Error **errp)
227
+{
228
+ BDRVRawState *s = bs->opaque;
229
+ int ret = 0;
230
+ Error *local_err = NULL;
231
+
232
+ if (!s->use_lock) {
233
+ return 0;
234
+ }
235
+
236
+ if (bdrv_get_flags(bs) & BDRV_O_INACTIVE) {
237
+ return 0;
238
+ }
239
+
240
+ assert(s->lock_fd > 0);
241
+
242
+ switch (op) {
243
+ case RAW_PL_PREPARE:
244
+ ret = raw_apply_lock_bytes(s, s->perm | new_perm,
245
+ ~s->shared_perm | ~new_shared,
246
+ false, errp);
247
+ if (!ret) {
248
+ ret = raw_check_lock_bytes(s, new_perm, new_shared, errp);
249
+ if (!ret) {
250
+ return 0;
251
+ }
252
+ }
253
+ op = RAW_PL_ABORT;
254
+ /* fall through to unlock bytes. */
255
+ case RAW_PL_ABORT:
256
+ raw_apply_lock_bytes(s, s->perm, ~s->shared_perm, true, &local_err);
257
+ if (local_err) {
258
+ /* Theoretically the above call only unlocks bytes and it cannot
259
+ * fail. Something weird happened, report it.
260
+ */
261
+ error_report_err(local_err);
262
+ }
263
+ break;
264
+ case RAW_PL_COMMIT:
265
+ raw_apply_lock_bytes(s, new_perm, ~new_shared, true, &local_err);
266
+ if (local_err) {
267
+ /* Theoretically the above call only unlocks bytes and it cannot
268
+ * fail. Something weird happened, report it.
269
+ */
270
+ error_report_err(local_err);
271
+ }
272
+ break;
273
+ }
274
+ return ret;
275
+}
276
+
277
static int raw_reopen_prepare(BDRVReopenState *state,
278
BlockReopenQueue *queue, Error **errp)
279
{
24
{
280
@@ -XXX,XX +XXX,XX @@ static void raw_close(BlockDriverState *bs)
25
MirrorOp *op;
281
qemu_close(s->fd);
26
282
s->fd = -1;
27
QTAILQ_FOREACH(op, &s->ops_in_flight, next) {
283
}
28
- /* Do not wait on pseudo ops, because it may in turn wait on
284
+ if (s->lock_fd >= 0) {
29
+ /*
285
+ qemu_close(s->lock_fd);
30
+ * Do not wait on pseudo ops, because it may in turn wait on
286
+ s->lock_fd = -1;
31
* some other operation to start, which may in fact be the
287
+ }
32
* caller of this function. Since there is only one pseudo op
33
* at any given time, we will always find some real operation
34
- * to wait on. */
35
- if (!op->is_pseudo_op && op->is_in_flight &&
36
- op->is_active_write == active)
37
- {
38
+ * to wait on.
39
+ * Also, do not wait on active operations, because they do not
40
+ * use up in-flight slots.
41
+ */
42
+ if (!op->is_pseudo_op && op->is_in_flight && !op->is_active_write) {
43
qemu_co_queue_wait(&op->waiting_requests, NULL);
44
return;
45
}
46
@@ -XXX,XX +XXX,XX @@ mirror_wait_for_any_operation(MirrorBlockJob *s, bool active)
47
abort();
288
}
48
}
289
49
290
static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
50
-static inline void coroutine_fn
291
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_create_opts = {
51
-mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s)
292
}
52
-{
293
};
53
- /* Only non-active operations use up in-flight slots */
294
54
- mirror_wait_for_any_operation(s, false);
295
+static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared,
55
-}
296
+ Error **errp)
297
+{
298
+ return raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, errp);
299
+}
300
+
301
+static void raw_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared)
302
+{
303
+ BDRVRawState *s = bs->opaque;
304
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
305
+ s->perm = perm;
306
+ s->shared_perm = shared;
307
+}
308
+
309
+static void raw_abort_perm_update(BlockDriverState *bs)
310
+{
311
+ raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
312
+}
313
+
314
+static int raw_inactivate(BlockDriverState *bs)
315
+{
316
+ int ret;
317
+ uint64_t perm = 0;
318
+ uint64_t shared = BLK_PERM_ALL;
319
+
320
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
321
+ if (ret) {
322
+ return ret;
323
+ }
324
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
325
+ return 0;
326
+}
327
+
328
+
329
+static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
330
+{
331
+ BDRVRawState *s = bs->opaque;
332
+ int ret;
333
+
334
+ assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
335
+ ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
336
+ errp);
337
+ if (ret) {
338
+ return;
339
+ }
340
+ raw_handle_perm_lock(bs, RAW_PL_COMMIT, s->perm, s->shared_perm, NULL);
341
+}
342
+
343
BlockDriver bdrv_file = {
344
.format_name = "file",
345
.protocol_name = "file",
346
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
347
.bdrv_get_info = raw_get_info,
348
.bdrv_get_allocated_file_size
349
= raw_get_allocated_file_size,
350
-
56
-
351
+ .bdrv_inactivate = raw_inactivate,
57
/* Perform a mirror copy operation.
352
+ .bdrv_invalidate_cache = raw_invalidate_cache,
58
*
353
+ .bdrv_check_perm = raw_check_perm,
59
* *op->bytes_handled is set to the number of bytes copied after and
354
+ .bdrv_set_perm = raw_set_perm,
355
+ .bdrv_abort_perm_update = raw_abort_perm_update,
356
.create_opts = &raw_create_opts,
357
};
358
359
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_device = {
360
.bdrv_get_info = raw_get_info,
361
.bdrv_get_allocated_file_size
362
= raw_get_allocated_file_size,
363
+ .bdrv_inactivate = raw_inactivate,
364
+ .bdrv_invalidate_cache = raw_invalidate_cache,
365
+ .bdrv_check_perm = raw_check_perm,
366
+ .bdrv_set_perm = raw_set_perm,
367
+ .bdrv_abort_perm_update = raw_abort_perm_update,
368
.bdrv_probe_blocksizes = hdev_probe_blocksizes,
369
.bdrv_probe_geometry = hdev_probe_geometry,
370
371
--
60
--
372
1.8.3.1
61
2.38.1
373
374
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
Instead of just freeing preallocated zero clusters and completely
3
There is a small gap in mirror_start_job() before putting the mirror
4
allocating them from scratch, reuse them.
4
filter node into the block graph (bdrv_append() call) and the actual job
5
being created. Before the job is created, MirrorBDSOpaque.job is NULL.
5
6
6
We cannot do this in handle_copied(), however, since this is a COW
7
It is possible that requests come in when bdrv_drained_end() is called,
7
operation. Therefore, we have to add the new logic to handle_alloc() and
8
and those requests would see MirrorBDSOpaque.job == NULL. Have our
8
simply return the existing offset if it exists. The only catch is that
9
filter node handle that case gracefully.
9
we have to convince qcow2_alloc_cluster_link_l2() not to free the old
10
clusters (because we have reused them).
11
10
12
Reported-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Message-Id: <20221109165452.67927-4-hreitz@redhat.com>
14
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
15
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
---
15
---
17
block/qcow2-cluster.c | 80 +++++++++++++++++++++++++++++++++++----------------
16
block/mirror.c | 20 ++++++++++++--------
18
block/qcow2.h | 3 ++
17
1 file changed, 12 insertions(+), 8 deletions(-)
19
2 files changed, 59 insertions(+), 24 deletions(-)
20
18
21
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
19
diff --git a/block/mirror.c b/block/mirror.c
22
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
23
--- a/block/qcow2-cluster.c
21
--- a/block/mirror.c
24
+++ b/block/qcow2-cluster.c
22
+++ b/block/mirror.c
25
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
23
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs,
26
uint64_t *l2_table, uint64_t stop_flags)
24
MirrorOp *op = NULL;
27
{
25
MirrorBDSOpaque *s = bs->opaque;
28
int i;
26
int ret = 0;
29
+ int first_cluster_type;
27
- bool copy_to_target;
30
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
28
+ bool copy_to_target = false;
31
uint64_t first_entry = be64_to_cpu(l2_table[0]);
29
32
uint64_t offset = first_entry & mask;
30
- copy_to_target = s->job->ret >= 0 &&
33
31
- !job_is_cancelled(&s->job->common.job) &&
34
- if (!offset)
32
- s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
35
+ if (!offset) {
33
+ if (s->job) {
36
return 0;
34
+ copy_to_target = s->job->ret >= 0 &&
35
+ !job_is_cancelled(&s->job->common.job) &&
36
+ s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
37
+ }
37
+ }
38
38
39
- assert(qcow2_get_cluster_type(first_entry) == QCOW2_CLUSTER_NORMAL);
39
if (copy_to_target) {
40
+ /* must be allocated */
40
op = active_write_prepare(s->job, offset, bytes);
41
+ first_cluster_type = qcow2_get_cluster_type(first_entry);
41
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs,
42
+ assert(first_cluster_type == QCOW2_CLUSTER_NORMAL ||
42
QEMUIOVector bounce_qiov;
43
+ (first_cluster_type == QCOW2_CLUSTER_ZERO &&
43
void *bounce_buf;
44
+ (first_entry & L2E_OFFSET_MASK) != 0));
44
int ret = 0;
45
45
- bool copy_to_target;
46
for (i = 0; i < nb_clusters; i++) {
46
+ bool copy_to_target = false;
47
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
47
48
@@ -XXX,XX +XXX,XX @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
48
- copy_to_target = s->job->ret >= 0 &&
49
* Don't discard clusters that reach a refcount of 0 (e.g. compressed
49
- !job_is_cancelled(&s->job->common.job) &&
50
* clusters), the next write will reuse them anyway.
50
- s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
51
*/
51
+ if (s->job) {
52
- if (j != 0) {
52
+ copy_to_target = s->job->ret >= 0 &&
53
+ if (!m->keep_old_clusters && j != 0) {
53
+ !job_is_cancelled(&s->job->common.job) &&
54
for (i = 0; i < j; i++) {
54
+ s->job->copy_mode == MIRROR_COPY_MODE_WRITE_BLOCKING;
55
qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1,
55
+ }
56
QCOW2_DISCARD_NEVER);
56
57
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
57
if (copy_to_target) {
58
uint64_t entry;
58
/* The guest might concurrently modify the data to write; but
59
uint64_t nb_clusters;
60
int ret;
61
+ bool keep_old_clusters = false;
62
63
- uint64_t alloc_cluster_offset;
64
+ uint64_t alloc_cluster_offset = 0;
65
66
trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,
67
*bytes);
68
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
69
* wrong with our code. */
70
assert(nb_clusters > 0);
71
72
- qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);
73
+ if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO &&
74
+ (entry & L2E_OFFSET_MASK) != 0 && (entry & QCOW_OFLAG_COPIED) &&
75
+ (!*host_offset ||
76
+ start_of_cluster(s, *host_offset) == (entry & L2E_OFFSET_MASK)))
77
+ {
78
+ /* Try to reuse preallocated zero clusters; contiguous normal clusters
79
+ * would be fine, too, but count_cow_clusters() above has limited
80
+ * nb_clusters already to a range of COW clusters */
81
+ int preallocated_nb_clusters =
82
+ count_contiguous_clusters(nb_clusters, s->cluster_size,
83
+ &l2_table[l2_index], QCOW_OFLAG_COPIED);
84
+ assert(preallocated_nb_clusters > 0);
85
86
- /* Allocate, if necessary at a given offset in the image file */
87
- alloc_cluster_offset = start_of_cluster(s, *host_offset);
88
- ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
89
- &nb_clusters);
90
- if (ret < 0) {
91
- goto fail;
92
- }
93
+ nb_clusters = preallocated_nb_clusters;
94
+ alloc_cluster_offset = entry & L2E_OFFSET_MASK;
95
96
- /* Can't extend contiguous allocation */
97
- if (nb_clusters == 0) {
98
- *bytes = 0;
99
- return 0;
100
+ /* We want to reuse these clusters, so qcow2_alloc_cluster_link_l2()
101
+ * should not free them. */
102
+ keep_old_clusters = true;
103
}
104
105
- /* !*host_offset would overwrite the image header and is reserved for "no
106
- * host offset preferred". If 0 was a valid host offset, it'd trigger the
107
- * following overlap check; do that now to avoid having an invalid value in
108
- * *host_offset. */
109
+ qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table);
110
+
111
if (!alloc_cluster_offset) {
112
- ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
113
- nb_clusters * s->cluster_size);
114
- assert(ret < 0);
115
- goto fail;
116
+ /* Allocate, if necessary at a given offset in the image file */
117
+ alloc_cluster_offset = start_of_cluster(s, *host_offset);
118
+ ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
119
+ &nb_clusters);
120
+ if (ret < 0) {
121
+ goto fail;
122
+ }
123
+
124
+ /* Can't extend contiguous allocation */
125
+ if (nb_clusters == 0) {
126
+ *bytes = 0;
127
+ return 0;
128
+ }
129
+
130
+ /* !*host_offset would overwrite the image header and is reserved for
131
+ * "no host offset preferred". If 0 was a valid host offset, it'd
132
+ * trigger the following overlap check; do that now to avoid having an
133
+ * invalid value in *host_offset. */
134
+ if (!alloc_cluster_offset) {
135
+ ret = qcow2_pre_write_overlap_check(bs, 0, alloc_cluster_offset,
136
+ nb_clusters * s->cluster_size);
137
+ assert(ret < 0);
138
+ goto fail;
139
+ }
140
}
141
142
/*
143
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
144
.offset = start_of_cluster(s, guest_offset),
145
.nb_clusters = nb_clusters,
146
147
+ .keep_old_clusters = keep_old_clusters,
148
+
149
.cow_start = {
150
.offset = 0,
151
.nb_bytes = offset_into_cluster(s, guest_offset),
152
diff --git a/block/qcow2.h b/block/qcow2.h
153
index XXXXXXX..XXXXXXX 100644
154
--- a/block/qcow2.h
155
+++ b/block/qcow2.h
156
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
157
/** Number of newly allocated clusters */
158
int nb_clusters;
159
160
+ /** Do not free the old clusters */
161
+ bool keep_old_clusters;
162
+
163
/**
164
* Requests that overlap with this allocation and wait to be restarted
165
* when the allocating request has completed.
166
--
59
--
167
1.8.3.1
60
2.38.1
168
169
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
Double attach is not a valid usage of the target image, drive-backup
3
Before this series, a mirror job in write-blocking mode would pause
4
will open the blockdev itself so skip the add_drive call in this case.
4
issuing background requests while active requests are in flight. Thus,
5
5
if the source is constantly in use by active requests, no actual
6
Signed-off-by: Fam Zheng <famz@redhat.com>
6
progress can be made.
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
8
This series should have fixed that, making the mirror job issue
9
background requests even while active requests are in flight.
10
11
Have a new test case in 151 verify this.
12
13
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
14
Message-Id: <20221109165452.67927-5-hreitz@redhat.com>
15
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
17
---
10
tests/qemu-iotests/055 | 32 ++++++++++++++++++--------------
18
tests/qemu-iotests/151 | 180 ++++++++++++++++++++++++++++++++++++-
11
1 file changed, 18 insertions(+), 14 deletions(-)
19
tests/qemu-iotests/151.out | 4 +-
12
20
2 files changed, 181 insertions(+), 3 deletions(-)
13
diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
21
22
diff --git a/tests/qemu-iotests/151 b/tests/qemu-iotests/151
14
index XXXXXXX..XXXXXXX 100755
23
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/055
24
--- a/tests/qemu-iotests/151
16
+++ b/tests/qemu-iotests/055
25
+++ b/tests/qemu-iotests/151
17
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
26
@@ -XXX,XX +XXX,XX @@
18
except OSError:
27
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
pass
28
#
20
29
21
- def do_prepare_drives(self, fmt, args):
30
+import math
22
+ def do_prepare_drives(self, fmt, args, attach_target):
31
import os
23
self.vm = iotests.VM().add_drive(test_img)
32
+import subprocess
24
33
+from typing import List
25
qemu_img('create', '-f', fmt, blockdev_target_img,
34
import iotests
26
str(TestDriveCompression.image_len), *args)
35
from iotests import qemu_img
27
- self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
36
28
+ if attach_target:
37
@@ -XXX,XX +XXX,XX @@ class TestActiveMirror(iotests.QMPTestCase):
29
+ self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
38
self.vm = iotests.VM()
30
39
self.vm.add_drive_raw(self.vm.qmp_to_opts(blk_source))
40
self.vm.add_blockdev(self.vm.qmp_to_opts(blk_target))
41
- self.vm.add_device('virtio-blk,drive=source')
42
+ self.vm.add_device('virtio-blk,id=vblk,drive=source')
31
self.vm.launch()
43
self.vm.launch()
32
44
33
- def do_test_compress_complete(self, cmd, format, **args):
45
def tearDown(self):
34
- self.do_prepare_drives(format['type'], format['args'])
46
@@ -XXX,XX +XXX,XX @@ class TestActiveMirror(iotests.QMPTestCase):
35
+ def do_test_compress_complete(self, cmd, format, attach_target, **args):
47
self.potential_writes_in_flight = False
36
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
48
37
49
38
self.assert_no_active_block_jobs()
50
+class TestThrottledWithNbdExport(iotests.QMPTestCase):
39
51
+ image_len = 128 * 1024 * 1024 # MB
40
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
52
+ iops = 16
41
53
+ background_processes: List['subprocess.Popen[str]'] = []
42
def test_complete_compress_drive_backup(self):
54
+
43
for format in TestDriveCompression.fmt_supports_compression:
55
+ def setUp(self):
44
- self.do_test_compress_complete('drive-backup', format,
56
+ qemu_img('create', '-f', iotests.imgfmt, source_img, '128M')
45
+ self.do_test_compress_complete('drive-backup', format, False,
57
+ qemu_img('create', '-f', iotests.imgfmt, target_img, '128M')
46
target=blockdev_target_img, mode='existing')
58
+
47
59
+ self.vm = iotests.VM()
48
def test_complete_compress_blockdev_backup(self):
60
+ self.vm.launch()
49
for format in TestDriveCompression.fmt_supports_compression:
61
+
50
- self.do_test_compress_complete('blockdev-backup', format, target='drive1')
62
+ result = self.vm.qmp('object-add', **{
51
+ self.do_test_compress_complete('blockdev-backup', format, True,
63
+ 'qom-type': 'throttle-group',
52
+ target='drive1')
64
+ 'id': 'thrgr',
53
65
+ 'limits': {
54
- def do_test_compress_cancel(self, cmd, format, **args):
66
+ 'iops-total': self.iops,
55
- self.do_prepare_drives(format['type'], format['args'])
67
+ 'iops-total-max': self.iops
56
+ def do_test_compress_cancel(self, cmd, format, attach_target, **args):
68
+ }
57
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
69
+ })
58
70
+ self.assert_qmp(result, 'return', {})
59
self.assert_no_active_block_jobs()
71
+
60
72
+ result = self.vm.qmp('blockdev-add', **{
61
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
73
+ 'node-name': 'source-node',
62
74
+ 'driver': 'throttle',
63
def test_compress_cancel_drive_backup(self):
75
+ 'throttle-group': 'thrgr',
64
for format in TestDriveCompression.fmt_supports_compression:
76
+ 'file': {
65
- self.do_test_compress_cancel('drive-backup', format,
77
+ 'driver': iotests.imgfmt,
66
+ self.do_test_compress_cancel('drive-backup', format, False,
78
+ 'file': {
67
target=blockdev_target_img, mode='existing')
79
+ 'driver': 'file',
68
80
+ 'filename': source_img
69
def test_compress_cancel_blockdev_backup(self):
81
+ }
70
for format in TestDriveCompression.fmt_supports_compression:
82
+ }
71
- self.do_test_compress_cancel('blockdev-backup', format, target='drive1')
83
+ })
72
+ self.do_test_compress_cancel('blockdev-backup', format, True,
84
+ self.assert_qmp(result, 'return', {})
73
+ target='drive1')
85
+
74
86
+ result = self.vm.qmp('blockdev-add', **{
75
- def do_test_compress_pause(self, cmd, format, **args):
87
+ 'node-name': 'target-node',
76
- self.do_prepare_drives(format['type'], format['args'])
88
+ 'driver': iotests.imgfmt,
77
+ def do_test_compress_pause(self, cmd, format, attach_target, **args):
89
+ 'file': {
78
+ self.do_prepare_drives(format['type'], format['args'], attach_target)
90
+ 'driver': 'file',
79
91
+ 'filename': target_img
80
self.assert_no_active_block_jobs()
92
+ }
81
93
+ })
82
@@ -XXX,XX +XXX,XX @@ class TestDriveCompression(iotests.QMPTestCase):
94
+ self.assert_qmp(result, 'return', {})
83
95
+
84
def test_compress_pause_drive_backup(self):
96
+ self.nbd_sock = iotests.file_path('nbd.sock',
85
for format in TestDriveCompression.fmt_supports_compression:
97
+ base_dir=iotests.sock_dir)
86
- self.do_test_compress_pause('drive-backup', format,
98
+ self.nbd_url = f'nbd+unix:///source-node?socket={self.nbd_sock}'
87
+ self.do_test_compress_pause('drive-backup', format, False,
99
+
88
target=blockdev_target_img, mode='existing')
100
+ result = self.vm.qmp('nbd-server-start', addr={
89
101
+ 'type': 'unix',
90
def test_compress_pause_blockdev_backup(self):
102
+ 'data': {
91
for format in TestDriveCompression.fmt_supports_compression:
103
+ 'path': self.nbd_sock
92
- self.do_test_compress_pause('blockdev-backup', format, target='drive1')
104
+ }
93
+ self.do_test_compress_pause('blockdev-backup', format, True,
105
+ })
94
+ target='drive1')
106
+ self.assert_qmp(result, 'return', {})
95
107
+
108
+ result = self.vm.qmp('block-export-add', id='exp0', type='nbd',
109
+ node_name='source-node', writable=True)
110
+ self.assert_qmp(result, 'return', {})
111
+
112
+ def tearDown(self):
113
+ # Wait for background requests to settle
114
+ try:
115
+ while True:
116
+ p = self.background_processes.pop()
117
+ while True:
118
+ try:
119
+ p.wait(timeout=0.0)
120
+ break
121
+ except subprocess.TimeoutExpired:
122
+ self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}')
123
+ except IndexError:
124
+ pass
125
+
126
+ # Cancel ongoing block jobs
127
+ for job in self.vm.qmp('query-jobs')['return']:
128
+ self.vm.qmp('block-job-cancel', device=job['id'], force=True)
129
+
130
+ while True:
131
+ self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}')
132
+ if len(self.vm.qmp('query-jobs')['return']) == 0:
133
+ break
134
+
135
+ self.vm.shutdown()
136
+ os.remove(source_img)
137
+ os.remove(target_img)
138
+
139
+ def testUnderLoad(self):
140
+ '''
141
+ Throttle the source node, then issue a whole bunch of external requests
142
+ while the mirror job (in write-blocking mode) is running. We want to
143
+ see background requests being issued even while the source is under
144
+ full load by active writes, so that progress can be made towards READY.
145
+ '''
146
+
147
+ # Fill the first half of the source image; do not fill the second half,
148
+ # that is where we will have active requests occur. This ensures that
149
+ # active mirroring itself will not directly contribute to the job's
150
+ # progress (because when the job was started, those areas were not
151
+ # intended to be copied, so active mirroring will only lead to not
152
+ # losing progress, but also not making any).
153
+ self.vm.hmp_qemu_io('source-node',
154
+ f'aio_write -P 1 0 {self.image_len // 2}')
155
+ self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}')
156
+
157
+ # Launch the mirror job
158
+ mirror_buf_size = 65536
159
+ result = self.vm.qmp('blockdev-mirror',
160
+ job_id='mirror',
161
+ filter_node_name='mirror-node',
162
+ device='source-node',
163
+ target='target-node',
164
+ sync='full',
165
+ copy_mode='write-blocking',
166
+ buf_size=mirror_buf_size)
167
+ self.assert_qmp(result, 'return', {})
168
+
169
+ # We create the external requests via qemu-io processes on the NBD
170
+ # server. Have their offset start in the middle of the image so they
171
+ # do not overlap with the background requests (which start from the
172
+ # beginning).
173
+ active_request_offset = self.image_len // 2
174
+ active_request_len = 4096
175
+
176
+ # Create enough requests to saturate the node for 5 seconds
177
+ for _ in range(0, 5 * self.iops):
178
+ req = f'write -P 42 {active_request_offset} {active_request_len}'
179
+ active_request_offset += active_request_len
180
+ p = iotests.qemu_io_popen('-f', 'nbd', self.nbd_url, '-c', req)
181
+ self.background_processes += [p]
182
+
183
+ # Now advance the clock one I/O operation at a time by the 4 seconds
184
+ # (i.e. one less than 5). We expect the mirror job to issue background
185
+ # operations here, even though active requests are still in flight.
186
+ # The active requests will take precedence, however, because they have
187
+ # been issued earlier than mirror's background requests.
188
+ # Once the active requests we have started above are done (i.e. after 5
189
+ # virtual seconds), we expect those background requests to be worked
190
+ # on. We only advance 4 seconds here to avoid race conditions.
191
+ for _ in range(0, 4 * self.iops):
192
+ step = math.ceil(1 * 1000 * 1000 * 1000 / self.iops)
193
+ self.vm.qtest(f'clock_step {step}')
194
+
195
+ # Note how much remains to be done until the mirror job is finished
196
+ job_status = self.vm.qmp('query-jobs')['return'][0]
197
+ start_remaining = job_status['total-progress'] - \
198
+ job_status['current-progress']
199
+
200
+ # Create a whole bunch of more active requests
201
+ for _ in range(0, 10 * self.iops):
202
+ req = f'write -P 42 {active_request_offset} {active_request_len}'
203
+ active_request_offset += active_request_len
204
+ p = iotests.qemu_io_popen('-f', 'nbd', self.nbd_url, '-c', req)
205
+ self.background_processes += [p]
206
+
207
+ # Let the clock advance more. After 1 second, as noted above, we
208
+ # expect the background requests to be worked on. Give them a couple
209
+ # of seconds (specifically 4) to see their impact.
210
+ for _ in range(0, 5 * self.iops):
211
+ step = math.ceil(1 * 1000 * 1000 * 1000 / self.iops)
212
+ self.vm.qtest(f'clock_step {step}')
213
+
214
+ # Note how much remains to be done now. We expect this number to be
215
+ # reduced thanks to those background requests.
216
+ job_status = self.vm.qmp('query-jobs')['return'][0]
217
+ end_remaining = job_status['total-progress'] - \
218
+ job_status['current-progress']
219
+
220
+ # See that indeed progress was being made on the job, even while the
221
+ # node was saturated with active requests
222
+ self.assertGreater(start_remaining - end_remaining, 0)
223
+
224
+
96
if __name__ == '__main__':
225
if __name__ == '__main__':
97
iotests.main(supported_fmts=['raw', 'qcow2'])
226
iotests.main(supported_fmts=['qcow2', 'raw'],
227
supported_protocols=['file'])
228
diff --git a/tests/qemu-iotests/151.out b/tests/qemu-iotests/151.out
229
index XXXXXXX..XXXXXXX 100644
230
--- a/tests/qemu-iotests/151.out
231
+++ b/tests/qemu-iotests/151.out
232
@@ -XXX,XX +XXX,XX @@
233
-....
234
+.....
235
----------------------------------------------------------------------
236
-Ran 4 tests
237
+Ran 5 tests
238
239
OK
98
--
240
--
99
1.8.3.1
241
2.38.1
100
101
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
In the case where we test the expected error when a blockdev-snapshot
4
target already has a backing image, the backing chain is opened multiple
5
times. This will be a problem when we use image locking, so use a
6
different backing file that is not already open.
7
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
tests/qemu-iotests/085 | 33 +++++++++++++++++++--------------
12
tests/qemu-iotests/085.out | 3 ++-
13
2 files changed, 21 insertions(+), 15 deletions(-)
14
15
diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085
16
index XXXXXXX..XXXXXXX 100755
17
--- a/tests/qemu-iotests/085
18
+++ b/tests/qemu-iotests/085
19
@@ -XXX,XX +XXX,XX @@ _cleanup()
20
rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
21
rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
22
done
23
- rm -f "${TEST_IMG}.1" "${TEST_IMG}.2"
24
+ rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base"
25
26
}
27
trap "_cleanup; exit \$status" 0 1 2 3 15
28
@@ -XXX,XX +XXX,XX @@ function create_group_snapshot()
29
}
30
31
# ${1}: unique identifier for the snapshot filename
32
-# ${2}: true: open backing images; false: don't open them (default)
33
+# ${2}: extra_params to the blockdev-add command
34
+# ${3}: filename
35
+function do_blockdev_add()
36
+{
37
+ cmd="{ 'execute': 'blockdev-add', 'arguments':
38
+ { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
39
+ 'file':
40
+ { 'driver': 'file', 'filename': '${3}',
41
+ 'node-name': 'file_${1}' } } }"
42
+ _send_qemu_cmd $h "${cmd}" "return"
43
+}
44
+
45
+# ${1}: unique identifier for the snapshot filename
46
function add_snapshot_image()
47
{
48
- if [ "${2}" = "true" ]; then
49
- extra_params=""
50
- else
51
- extra_params="'backing': '', "
52
- fi
53
base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
54
snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
55
_make_test_img -b "${base_image}" "$size"
56
mv "${TEST_IMG}" "${snapshot_file}"
57
- cmd="{ 'execute': 'blockdev-add', 'arguments':
58
- { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${extra_params}
59
- 'file':
60
- { 'driver': 'file', 'filename': '${snapshot_file}',
61
- 'node-name': 'file_${1}' } } }"
62
- _send_qemu_cmd $h "${cmd}" "return"
63
+ do_blockdev_add "$1" "'backing': '', " "${snapshot_file}"
64
}
65
66
# ${1}: unique identifier for the snapshot filename
67
@@ -XXX,XX +XXX,XX @@ echo === Invalid command - snapshot node has a backing image ===
68
echo
69
70
SNAPSHOTS=$((${SNAPSHOTS}+1))
71
-add_snapshot_image ${SNAPSHOTS} true
72
+
73
+TEST_IMG="$TEST_IMG.base" _make_test_img "$size"
74
+_make_test_img -b "${TEST_IMG}.base" "$size"
75
+do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}"
76
blockdev_snapshot ${SNAPSHOTS} error
77
78
echo
79
diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out
80
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/085.out
82
+++ b/tests/qemu-iotests/085.out
83
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/
84
85
=== Invalid command - snapshot node has a backing image ===
86
87
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/12-snapshot-v0.IMGFMT
88
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
89
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
90
{"return": {}}
91
{"error": {"class": "GenericError", "desc": "The snapshot already has a backing image"}}
92
93
--
94
1.8.3.1
95
96
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The test scenario doesn't require the same image, instead it focuses on
4
the duplicated node-name, so use null-co to avoid locking conflict.
5
6
Reviewed-by: Max Reitz <mreitz@redhat.com>
7
Signed-off-by: Fam Zheng <famz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
tests/qemu-iotests/087 | 6 ++----
11
1 file changed, 2 insertions(+), 4 deletions(-)
12
13
diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087
14
index XXXXXXX..XXXXXXX 100755
15
--- a/tests/qemu-iotests/087
16
+++ b/tests/qemu-iotests/087
17
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
18
"driver": "$IMGFMT",
19
"node-name": "disk",
20
"file": {
21
- "driver": "file",
22
- "filename": "$TEST_IMG"
23
+ "driver": "null-co"
24
}
25
}
26
}
27
@@ -XXX,XX +XXX,XX @@ run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EO
28
"driver": "$IMGFMT",
29
"node-name": "test-node",
30
"file": {
31
- "driver": "file",
32
- "filename": "$TEST_IMG"
33
+ "driver": "null-co"
34
}
35
}
36
}
37
--
38
1.8.3.1
39
40
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
7
tests/qemu-iotests/091 | 2 ++
8
1 file changed, 2 insertions(+)
9
10
diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
11
index XXXXXXX..XXXXXXX 100755
12
--- a/tests/qemu-iotests/091
13
+++ b/tests/qemu-iotests/091
14
@@ -XXX,XX +XXX,XX @@ echo "vm2: qemu process running successfully"
15
echo "vm2: flush io, and quit"
16
_send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)"
17
_send_qemu_cmd $h2 'quit' ""
18
+_send_qemu_cmd $h1 'quit' ""
19
20
+wait
21
echo "Check image pattern"
22
${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | _filter_qemu_io
23
24
--
25
1.8.3.1
26
27
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
To avoid image lock failures.
4
5
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
---
8
tests/qemu-iotests/172 | 55 +++++++++++++++++++++++++---------------------
9
tests/qemu-iotests/172.out | 50 +++++++++++++++++++++--------------------
10
2 files changed, 56 insertions(+), 49 deletions(-)
11
12
diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172
13
index XXXXXXX..XXXXXXX 100755
14
--- a/tests/qemu-iotests/172
15
+++ b/tests/qemu-iotests/172
16
@@ -XXX,XX +XXX,XX @@ status=1    # failure is the default!
17
_cleanup()
18
{
19
    _cleanup_test_img
20
+ rm -f "$TEST_IMG.2"
21
+ rm -f "$TEST_IMG.3"
22
}
23
trap "_cleanup; exit \$status" 0 1 2 3 15
24
25
@@ -XXX,XX +XXX,XX @@ size=720k
26
27
_make_test_img $size
28
29
+TEST_IMG="$TEST_IMG.2" _make_test_img $size
30
+TEST_IMG="$TEST_IMG.3" _make_test_img $size
31
+
32
# Default drive semantics:
33
#
34
# By default you get a single empty floppy drive. You can override it with
35
@@ -XXX,XX +XXX,XX @@ echo === Using -fda/-fdb options ===
36
37
check_floppy_qtree -fda "$TEST_IMG"
38
check_floppy_qtree -fdb "$TEST_IMG"
39
-check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG"
40
+check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
41
42
43
echo
44
@@ -XXX,XX +XXX,XX @@ echo === Using -drive options ===
45
46
check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
47
check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
48
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG",index=1
49
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=floppy,file="$TEST_IMG.2",index=1
50
51
echo
52
echo
53
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -global ===
54
55
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
56
check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
57
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
58
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
59
-global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
60
61
echo
62
@@ -XXX,XX +XXX,XX @@ echo === Using -drive if=none and -device ===
63
64
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
65
check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
66
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
67
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
68
-device floppy,drive=none0 -device floppy,drive=none1,unit=1
69
70
echo
71
@@ -XXX,XX +XXX,XX @@ echo
72
echo === Mixing -fdX and -global ===
73
74
# Working
75
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
76
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
77
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
78
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
79
80
# Conflicting (-fdX wins)
81
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
82
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
83
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveA=none0
84
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global isa-fdc.driveB=none0
85
86
echo
87
echo
88
echo === Mixing -fdX and -device ===
89
90
# Working
91
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
92
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
93
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
94
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
95
96
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
97
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
98
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
99
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
100
101
# Conflicting
102
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
103
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
104
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
105
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
106
107
echo
108
echo
109
echo === Mixing -drive and -device ===
110
111
# Working
112
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
113
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=1
114
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0
115
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=1
116
117
# Conflicting
118
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" -device floppy,drive=none0,unit=0
119
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device floppy,drive=none0,unit=0
120
121
echo
122
echo
123
echo === Mixing -global and -device ===
124
125
# Working
126
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
127
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
128
-global isa-fdc.driveA=none0 -device floppy,drive=none1
129
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
130
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
131
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
132
133
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
134
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
135
-global isa-fdc.driveB=none0 -device floppy,drive=none1
136
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
137
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
138
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
139
140
# Conflicting
141
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
142
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
143
-global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
144
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG" \
145
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive if=none,file="$TEST_IMG.2" \
146
-global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
147
148
echo
149
@@ -XXX,XX +XXX,XX @@ echo === Too many floppy drives ===
150
151
# Working
152
check_floppy_qtree -drive if=floppy,file="$TEST_IMG" \
153
- -drive if=none,file="$TEST_IMG" \
154
- -drive if=none,file="$TEST_IMG" \
155
+ -drive if=none,file="$TEST_IMG.2" \
156
+ -drive if=none,file="$TEST_IMG.3" \
157
-global isa-fdc.driveB=none0 \
158
-device floppy,drive=none1
159
160
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
161
index XXXXXXX..XXXXXXX 100644
162
--- a/tests/qemu-iotests/172.out
163
+++ b/tests/qemu-iotests/172.out
164
@@ -XXX,XX +XXX,XX @@
165
QA output created by 172
166
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=737280
167
+Formatting 'TEST_DIR/t.IMGFMT.2', fmt=IMGFMT size=737280
168
+Formatting 'TEST_DIR/t.IMGFMT.3', fmt=IMGFMT size=737280
169
170
171
=== Default ===
172
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
173
share-rw = false
174
drive-type = "288"
175
176
-Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2
177
+Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
178
179
dev: isa-fdc, id ""
180
iobase = 1008 (0x3f0)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
182
share-rw = false
183
drive-type = "288"
184
185
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
186
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t.qcow2.2,index=1
187
188
dev: isa-fdc, id ""
189
iobase = 1008 (0x3f0)
190
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
191
share-rw = false
192
drive-type = "144"
193
194
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
195
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
196
197
dev: isa-fdc, id ""
198
iobase = 1008 (0x3f0)
199
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
200
share-rw = false
201
drive-type = "144"
202
203
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
204
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0 -device floppy,drive=none1,unit=1
205
206
dev: isa-fdc, id ""
207
iobase = 1008 (0x3f0)
208
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
209
210
=== Mixing -fdX and -global ===
211
212
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
213
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
214
215
dev: isa-fdc, id ""
216
iobase = 1008 (0x3f0)
217
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
218
share-rw = false
219
drive-type = "144"
220
221
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
222
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
223
224
dev: isa-fdc, id ""
225
iobase = 1008 (0x3f0)
226
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
227
share-rw = false
228
drive-type = "144"
229
230
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0
231
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0
232
233
dev: isa-fdc, id ""
234
iobase = 1008 (0x3f0)
235
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
236
share-rw = false
237
drive-type = "144"
238
239
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0
240
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0
241
242
dev: isa-fdc, id ""
243
iobase = 1008 (0x3f0)
244
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-
245
246
=== Mixing -fdX and -device ===
247
248
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
249
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
250
251
dev: isa-fdc, id ""
252
iobase = 1008 (0x3f0)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
254
share-rw = false
255
drive-type = "144"
256
257
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
258
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
259
260
dev: isa-fdc, id ""
261
iobase = 1008 (0x3f0)
262
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
263
share-rw = false
264
drive-type = "144"
265
266
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
267
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
268
269
dev: isa-fdc, id ""
270
iobase = 1008 (0x3f0)
271
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
272
share-rw = false
273
drive-type = "144"
274
275
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
276
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
277
278
dev: isa-fdc, id ""
279
iobase = 1008 (0x3f0)
280
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device flop
281
share-rw = false
282
drive-type = "144"
283
284
-Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
285
+Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
286
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
287
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
288
289
-Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
290
+Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
291
QEMU_PROG: -device floppy,drive=none0,unit=1: Floppy unit 1 is in use
292
QEMU_PROG: -device floppy,drive=none0,unit=1: Device initialization failed.
293
294
295
=== Mixing -drive and -device ===
296
297
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
298
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0
299
300
dev: isa-fdc, id ""
301
iobase = 1008 (0x3f0)
302
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
303
share-rw = false
304
drive-type = "144"
305
306
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
307
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=1
308
309
dev: isa-fdc, id ""
310
iobase = 1008 (0x3f0)
311
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
312
share-rw = false
313
drive-type = "144"
314
315
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=0
316
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device floppy,drive=none0,unit=0
317
QEMU_PROG: -device floppy,drive=none0,unit=0: Floppy unit 0 is in use
318
QEMU_PROG: -device floppy,drive=none0,unit=0: Device initialization failed.
319
320
321
=== Mixing -global and -device ===
322
323
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
324
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1
325
326
dev: isa-fdc, id ""
327
iobase = 1008 (0x3f0)
328
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
329
share-rw = false
330
drive-type = "144"
331
332
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
333
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=1
334
335
dev: isa-fdc, id ""
336
iobase = 1008 (0x3f0)
337
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
338
share-rw = false
339
drive-type = "144"
340
341
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
342
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
343
344
dev: isa-fdc, id ""
345
iobase = 1008 (0x3f0)
346
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
347
share-rw = false
348
drive-type = "144"
349
350
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
351
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=0
352
353
dev: isa-fdc, id ""
354
iobase = 1008 (0x3f0)
355
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
356
share-rw = false
357
drive-type = "144"
358
359
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
360
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveA=none0 -device floppy,drive=none1,unit=0
361
QEMU_PROG: -device floppy,drive=none1,unit=0: Floppy unit 0 is in use
362
QEMU_PROG: -device floppy,drive=none1,unit=0: Device initialization failed.
363
364
-Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
365
+Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -global isa-fdc.driveB=none0 -device floppy,drive=none1,unit=1
366
QEMU_PROG: -device floppy,drive=none1,unit=1: Floppy unit 1 is in use
367
QEMU_PROG: -device floppy,drive=none1,unit=1: Device initialization failed.
368
369
370
=== Too many floppy drives ===
371
372
-Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2 -global isa-fdc.driveB=none0 -device floppy,drive=none1
373
+Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -drive if=none,file=TEST_DIR/t.qcow2.3 -global isa-fdc.driveB=none0 -device floppy,drive=none1
374
QEMU_PROG: -device floppy,drive=none1: Can't create floppy unit 2, bus supports only 2 units
375
QEMU_PROG: -device floppy,drive=none1: Device initialization failed.
376
377
--
378
1.8.3.1
379
380
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Reviewed-by: Max Reitz <mreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
---
7
tests/drive_del-test.c | 2 +-
8
tests/nvme-test.c | 2 +-
9
tests/usb-hcd-uhci-test.c | 2 +-
10
tests/usb-hcd-xhci-test.c | 2 +-
11
tests/virtio-blk-test.c | 2 +-
12
tests/virtio-scsi-test.c | 5 +++--
13
6 files changed, 8 insertions(+), 7 deletions(-)
14
15
diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/drive_del-test.c
18
+++ b/tests/drive_del-test.c
19
@@ -XXX,XX +XXX,XX @@ static void test_after_failed_device_add(void)
20
static void test_drive_del_device_del(void)
21
{
22
/* Start with a drive used by a device that unplugs instantaneously */
23
- qtest_start("-drive if=none,id=drive0,file=/dev/null,format=raw"
24
+ qtest_start("-drive if=none,id=drive0,file=null-co://,format=raw"
25
" -device virtio-scsi-pci"
26
" -device scsi-hd,drive=drive0,id=dev0");
27
28
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/tests/nvme-test.c
31
+++ b/tests/nvme-test.c
32
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
33
g_test_init(&argc, &argv, NULL);
34
qtest_add_func("/nvme/nop", nop);
35
36
- qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
37
+ qtest_start("-drive id=drv0,if=none,file=null-co://,format=raw "
38
"-device nvme,drive=drv0,serial=foo");
39
ret = g_test_run();
40
41
diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/tests/usb-hcd-uhci-test.c
44
+++ b/tests/usb-hcd-uhci-test.c
45
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
46
{
47
const char *arch = qtest_get_arch();
48
const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
49
- " -drive id=drive0,if=none,file=/dev/null,format=raw"
50
+ " -drive id=drive0,if=none,file=null-co://,format=raw"
51
" -device usb-tablet,bus=uhci.0,port=1";
52
int ret;
53
54
diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/tests/usb-hcd-xhci-test.c
57
+++ b/tests/usb-hcd-xhci-test.c
58
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
59
qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
60
61
qtest_start("-device nec-usb-xhci,id=xhci"
62
- " -drive id=drive0,if=none,file=/dev/null,format=raw");
63
+ " -drive id=drive0,if=none,file=null-co://,format=raw");
64
ret = g_test_run();
65
qtest_end();
66
67
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/tests/virtio-blk-test.c
70
+++ b/tests/virtio-blk-test.c
71
@@ -XXX,XX +XXX,XX @@ static QOSState *pci_test_start(void)
72
const char *arch = qtest_get_arch();
73
char *tmp_path;
74
const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
75
- "-drive if=none,id=drive1,file=/dev/null,format=raw "
76
+ "-drive if=none,id=drive1,file=null-co://,format=raw "
77
"-device virtio-blk-pci,id=drv0,drive=drive0,"
78
"addr=%x.%x";
79
80
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/tests/virtio-scsi-test.c
83
+++ b/tests/virtio-scsi-test.c
84
@@ -XXX,XX +XXX,XX @@ typedef struct {
85
static QOSState *qvirtio_scsi_start(const char *extra_opts)
86
{
87
const char *arch = qtest_get_arch();
88
- const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw "
89
+ const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
90
"-device virtio-scsi-pci,id=vs0 "
91
"-device scsi-hd,bus=vs0.0,drive=drv0 %s";
92
93
@@ -XXX,XX +XXX,XX @@ static void hotplug(void)
94
QDict *response;
95
QOSState *qs;
96
97
- qs = qvirtio_scsi_start("-drive id=drv1,if=none,file=/dev/null,format=raw");
98
+ qs = qvirtio_scsi_start(
99
+ "-drive id=drv1,if=none,file=null-co://,format=raw");
100
response = qmp("{\"execute\": \"device_add\","
101
" \"arguments\": {"
102
" \"driver\": \"scsi-hd\","
103
--
104
1.8.3.1
105
106
diff view generated by jsdifflib
1
From: Max Reitz <mreitz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
066 was supposed to be a test "for discarding preallocated zero
3
Have write requests happen to the source node right when we start a
4
clusters", but it did so incompletely: While it did check the image
4
mirror job. The mirror filter node may encounter MirrorBDSOpaque.job
5
file's integrity after the operation, it did not confirm that the
5
being NULL, but this should not cause a segfault.
6
clusters are indeed freed. This patch adds this test.
7
6
8
In addition, new cases for writing to preallocated zero clusters are
7
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
9
added.
8
Message-Id: <20221109165452.67927-6-hreitz@redhat.com>
10
9
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
---
11
---
15
tests/qemu-iotests/066 | 128 ++++++++++++++++++++++++++++++++++++++++++++-
12
tests/qemu-iotests/151 | 53 +++++++++++++++++++++++++++++++++++---
16
tests/qemu-iotests/066.out | 46 ++++++++++++++++
13
tests/qemu-iotests/151.out | 4 +--
17
2 files changed, 173 insertions(+), 1 deletion(-)
14
2 files changed, 52 insertions(+), 5 deletions(-)
18
15
19
diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066
16
diff --git a/tests/qemu-iotests/151 b/tests/qemu-iotests/151
20
index XXXXXXX..XXXXXXX 100755
17
index XXXXXXX..XXXXXXX 100755
21
--- a/tests/qemu-iotests/066
18
--- a/tests/qemu-iotests/151
22
+++ b/tests/qemu-iotests/066
19
+++ b/tests/qemu-iotests/151
23
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
24
#!/bin/bash
21
import math
25
#
22
import os
26
-# Test case for discarding preallocated zero clusters in qcow2
23
import subprocess
27
+# Test case for preallocated zero clusters in qcow2
24
-from typing import List
28
#
25
+import time
29
# Copyright (C) 2013 Red Hat, Inc.
26
+from typing import List, Optional
30
#
27
import iotests
31
@@ -XXX,XX +XXX,XX @@ _make_test_img $IMG_SIZE
28
from iotests import qemu_img
32
$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \
29
33
     -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \
30
@@ -XXX,XX +XXX,XX @@ class TestActiveMirror(iotests.QMPTestCase):
34
| _filter_qemu_io
31
self.potential_writes_in_flight = False
32
33
34
-class TestThrottledWithNbdExport(iotests.QMPTestCase):
35
+class TestThrottledWithNbdExportBase(iotests.QMPTestCase):
36
image_len = 128 * 1024 * 1024 # MB
37
- iops = 16
38
+ iops: Optional[int] = None
39
background_processes: List['subprocess.Popen[str]'] = []
40
41
def setUp(self):
42
+ # Must be set by subclasses
43
+ self.assertIsNotNone(self.iops)
35
+
44
+
36
# Check the image (there shouldn't be any leaks)
45
qemu_img('create', '-f', iotests.imgfmt, source_img, '128M')
37
_check_test_img
46
qemu_img('create', '-f', iotests.imgfmt, target_img, '128M')
38
+# Map the image (we want all clusters to be gone)
47
39
+$QEMU_IMG map "$TEST_IMG"
48
@@ -XXX,XX +XXX,XX @@ class TestThrottledWithNbdExport(iotests.QMPTestCase):
49
os.remove(source_img)
50
os.remove(target_img)
51
40
+
52
+
41
+_cleanup_test_img
53
+class TestLowThrottledWithNbdExport(TestThrottledWithNbdExportBase):
54
+ iops = 16
55
+
56
def testUnderLoad(self):
57
'''
58
Throttle the source node, then issue a whole bunch of external requests
59
@@ -XXX,XX +XXX,XX @@ class TestThrottledWithNbdExport(iotests.QMPTestCase):
60
self.assertGreater(start_remaining - end_remaining, 0)
61
62
63
+class TestHighThrottledWithNbdExport(TestThrottledWithNbdExportBase):
64
+ iops = 1024
65
+
66
+ def testActiveOnCreation(self):
67
+ '''
68
+ Issue requests on the mirror source node right as the mirror is
69
+ instated. It's possible that requests occur before the actual job is
70
+ created, but after the node has been put into the graph. Write
71
+ requests across the node must in that case be forwarded to the source
72
+ node without attempting to mirror them (there is no job object yet, so
73
+ attempting to access it would cause a segfault).
74
+ We do this with a lightly throttled node (i.e. quite high IOPS limit).
75
+ Using throttling seems to increase reproductivity, but if the limit is
76
+ too low, all requests allowed per second will be submitted before
77
+ mirror_start_job() gets to the problematic point.
78
+ '''
79
+
80
+ # Let qemu-img bench create write requests (enough for two seconds on
81
+ # the virtual clock)
82
+ bench_args = ['bench', '-w', '-d', '1024', '-f', 'nbd',
83
+ '-c', str(self.iops * 2), self.nbd_url]
84
+ p = iotests.qemu_tool_popen(iotests.qemu_img_args + bench_args)
85
+ self.background_processes += [p]
86
+
87
+ # Give qemu-img bench time to start up and issue requests
88
+ time.sleep(1.0)
89
+ # Flush the request queue, so new requests can come in right as we
90
+ # start blockdev-mirror
91
+ self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}')
92
+
93
+ result = self.vm.qmp('blockdev-mirror',
94
+ job_id='mirror',
95
+ device='source-node',
96
+ target='target-node',
97
+ sync='full',
98
+ copy_mode='write-blocking')
99
+ self.assert_qmp(result, 'return', {})
42
+
100
+
43
+
101
+
44
+echo
102
if __name__ == '__main__':
45
+echo '=== Writing to preallocated zero clusters ==='
103
iotests.main(supported_fmts=['qcow2', 'raw'],
46
+echo
104
supported_protocols=['file'])
47
+
105
diff --git a/tests/qemu-iotests/151.out b/tests/qemu-iotests/151.out
48
+_make_test_img $IMG_SIZE
49
+
50
+# Create data clusters (not aligned to an L2 table)
51
+$QEMU_IO -c 'write -P 42 1M 256k' "$TEST_IMG" | _filter_qemu_io
52
+orig_map=$($QEMU_IMG map --output=json "$TEST_IMG")
53
+
54
+# Convert the data clusters to preallocated zero clusters
55
+$QEMU_IO -c 'write -z 1M 256k' "$TEST_IMG" | _filter_qemu_io
56
+
57
+# Now write to them (with a COW needed for the head and tail)
58
+$QEMU_IO -c "write -P 23 $(((1024 + 32) * 1024)) 192k" "$TEST_IMG" \
59
+ | _filter_qemu_io
60
+
61
+# Check metadata correctness
62
+_check_test_img
63
+
64
+# Check data correctness
65
+$QEMU_IO -c "read -P 0 $(( 1024 * 1024)) 32k" \
66
+ -c "read -P 23 $(((1024 + 32) * 1024)) 192k" \
67
+ -c "read -P 0 $(((1024 + 32 + 192) * 1024)) 32k" \
68
+ "$TEST_IMG" \
69
+ | _filter_qemu_io
70
+
71
+# Check that we have actually reused the original area
72
+new_map=$($QEMU_IMG map --output=json "$TEST_IMG")
73
+if [ "$new_map" = "$orig_map" ]; then
74
+ echo 'Successfully reused original clusters.'
75
+else
76
+ echo 'Failed to reuse original clusters.'
77
+ echo 'Original map:'
78
+ echo "$orig_map"
79
+ echo 'New map:'
80
+ echo "$new_map"
81
+fi
82
+
83
+_cleanup_test_img
84
+
85
+
86
+echo
87
+echo '=== Writing to a snapshotted preallocated zero cluster ==='
88
+echo
89
+
90
+_make_test_img 64k
91
+
92
+# Create a preallocated zero cluster
93
+$QEMU_IO -c 'write -P 42 0 64k' -c 'write -z 0 64k' "$TEST_IMG" \
94
+ | _filter_qemu_io
95
+
96
+# Snapshot it
97
+$QEMU_IMG snapshot -c foo "$TEST_IMG"
98
+
99
+# Write to the cluster
100
+$QEMU_IO -c 'write -P 23 0 64k' "$TEST_IMG" | _filter_qemu_io
101
+
102
+# Check metadata correctness
103
+_check_test_img
104
+
105
+# Check data correctness
106
+$QEMU_IO -c 'read -P 23 0 64k' "$TEST_IMG" | _filter_qemu_io
107
+$QEMU_IMG snapshot -a foo "$TEST_IMG"
108
+$QEMU_IO -c 'read -P 0 0 64k' "$TEST_IMG" | _filter_qemu_io
109
+
110
+_cleanup_test_img
111
+
112
+
113
+echo
114
+echo '=== Consecutive write to a preallocated zero cluster ==='
115
+echo
116
+
117
+_make_test_img 192k
118
+
119
+# Create three normal clusters
120
+$QEMU_IO -c 'write -P 42 0 192k' "$TEST_IMG" | _filter_qemu_io
121
+orig_map=$($QEMU_IMG map --output=json "$TEST_IMG")
122
+
123
+# Make the middle cluster a preallocated zero cluster
124
+$QEMU_IO -c 'write -z 64k 64k' "$TEST_IMG" | _filter_qemu_io
125
+
126
+# Try to overwrite everything: This should reuse the whole range. To test that
127
+# this only issues a single continuous write request, use blkdebug.
128
+$QEMU_IO -c 'write -P 42 0 192k' \
129
+ "json:{
130
+ 'driver': '$IMGFMT',
131
+ 'file': {
132
+ 'driver': 'blkdebug',
133
+ 'image.filename': '$TEST_IMG',
134
+ 'set-state': [{
135
+ 'event': 'write_aio',
136
+ 'new_state': 2
137
+ }],
138
+ 'inject-error': [{
139
+ 'event': 'write_aio',
140
+ 'state': 2
141
+ }]
142
+ }
143
+ }" \
144
+ | _filter_qemu_io
145
+
146
+# Check metadata correctness
147
+_check_test_img
148
+
149
+# Check that we have actually reused the original area
150
+new_map=$($QEMU_IMG map --output=json "$TEST_IMG")
151
+if [ "$new_map" = "$orig_map" ]; then
152
+ echo 'Successfully reused original clusters.'
153
+else
154
+ echo 'Failed to reuse original clusters.'
155
+ echo 'Original map:'
156
+ echo "$orig_map"
157
+ echo 'New map:'
158
+ echo "$new_map"
159
+fi
160
+
161
+_cleanup_test_img
162
+
163
164
# success, all done
165
echo "*** done"
166
diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out
167
index XXXXXXX..XXXXXXX 100644
106
index XXXXXXX..XXXXXXX 100644
168
--- a/tests/qemu-iotests/066.out
107
--- a/tests/qemu-iotests/151.out
169
+++ b/tests/qemu-iotests/066.out
108
+++ b/tests/qemu-iotests/151.out
170
@@ -XXX,XX +XXX,XX @@ discard 67109376/67109376 bytes at offset 0
109
@@ -XXX,XX +XXX,XX @@
171
read 67109376/67109376 bytes at offset 0
110
-.....
172
64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
111
+......
173
No errors were found on the image.
112
----------------------------------------------------------------------
174
+Offset Length Mapped to File
113
-Ran 5 tests
175
+
114
+Ran 6 tests
176
+=== Writing to preallocated zero clusters ===
115
177
+
116
OK
178
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376
179
+wrote 262144/262144 bytes at offset 1048576
180
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
181
+wrote 262144/262144 bytes at offset 1048576
182
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
183
+wrote 196608/196608 bytes at offset 1081344
184
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+No errors were found on the image.
186
+read 32768/32768 bytes at offset 1048576
187
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
188
+read 196608/196608 bytes at offset 1081344
189
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
190
+read 32768/32768 bytes at offset 1277952
191
+32 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
192
+Successfully reused original clusters.
193
+
194
+=== Writing to a snapshotted preallocated zero cluster ===
195
+
196
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
197
+wrote 65536/65536 bytes at offset 0
198
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+wrote 65536/65536 bytes at offset 0
200
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
201
+wrote 65536/65536 bytes at offset 0
202
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+No errors were found on the image.
204
+read 65536/65536 bytes at offset 0
205
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
206
+read 65536/65536 bytes at offset 0
207
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
208
+
209
+=== Consecutive write to a preallocated zero cluster ===
210
+
211
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=196608
212
+wrote 196608/196608 bytes at offset 0
213
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
214
+wrote 65536/65536 bytes at offset 65536
215
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
216
+wrote 196608/196608 bytes at offset 0
217
+192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
218
+No errors were found on the image.
219
+Successfully reused original clusters.
220
*** done
221
--
117
--
222
1.8.3.1
118
2.38.1
223
224
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Alberto Faria <afaria@redhat.com>
2
2
3
Making this option available even before implementing it will let
3
The nvme-io_uring BlockDriver's path option must point at the character
4
converting tests easier: in coming patches they can specify the option
4
device of an NVMe namespace, not at an image file.
5
already when necessary, before we actually write code to lock the
6
images.
7
5
8
Signed-off-by: Fam Zheng <famz@redhat.com>
6
Fixes: fd66dbd424f5 ("blkio: add libblkio block driver")
7
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
8
Signed-off-by: Alberto Faria <afaria@redhat.com>
9
Message-Id: <20221108142347.1322674-1-afaria@redhat.com>
10
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
11
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
13
---
11
block/file-posix.c | 5 +++++
14
qapi/block-core.json | 2 +-
12
qapi/block-core.json | 4 ++++
15
1 file changed, 1 insertion(+), 1 deletion(-)
13
2 files changed, 9 insertions(+)
14
16
15
diff --git a/block/file-posix.c b/block/file-posix.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/file-posix.c
18
+++ b/block/file-posix.c
19
@@ -XXX,XX +XXX,XX @@ static QemuOptsList raw_runtime_opts = {
20
.type = QEMU_OPT_STRING,
21
.help = "host AIO implementation (threads, native)",
22
},
23
+ {
24
+ .name = "locking",
25
+ .type = QEMU_OPT_STRING,
26
+ .help = "file locking mode (on/off/auto, default: auto)",
27
+ },
28
{ /* end of list */ }
29
},
30
};
31
diff --git a/qapi/block-core.json b/qapi/block-core.json
17
diff --git a/qapi/block-core.json b/qapi/block-core.json
32
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
33
--- a/qapi/block-core.json
19
--- a/qapi/block-core.json
34
+++ b/qapi/block-core.json
20
+++ b/qapi/block-core.json
35
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
36
#
22
#
37
# @filename: path to the image file
23
# Driver specific block device options for the nvme-io_uring backend.
38
# @aio: AIO backend (default: threads) (since: 2.8)
39
+# @locking: whether to enable file locking. If set to 'auto', only enable
40
+# when Open File Descriptor (OFD) locking API is available
41
+# (default: auto, since 2.10)
42
#
24
#
43
# Since: 2.9
25
-# @path: path to the image file
44
##
26
+# @path: path to the NVMe namespace's character device (e.g. /dev/ng0n1).
45
{ 'struct': 'BlockdevOptionsFile',
27
#
46
'data': { 'filename': 'str',
28
# Since: 7.2
47
+ '*locking': 'OnOffAuto',
48
'*aio': 'BlockdevAioOptions' } }
49
50
##
29
##
51
--
30
--
52
1.8.3.1
31
2.38.1
53
54
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
We share the same set of QAPI options with file-posix, but locking is
4
not supported here. So error out if it is specified as 'on' for now.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
block/file-win32.c | 5 +++++
10
1 file changed, 5 insertions(+)
11
12
diff --git a/block/file-win32.c b/block/file-win32.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block/file-win32.c
15
+++ b/block/file-win32.c
16
@@ -XXX,XX +XXX,XX @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
17
goto fail;
18
}
19
20
+ if (qdict_get_try_bool(options, "locking", false)) {
21
+ error_setg(errp, "locking=on is not supported on Windows");
22
+ goto fail;
23
+ }
24
+
25
filename = qemu_opt_get(opts, "filename");
26
27
use_aio = get_aio_option(opts, flags, &local_err);
28
--
29
1.8.3.1
30
31
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
The COLO block replication architecture requires one disk to be shared
4
between primary and secondary, in the test both processes use posix file
5
protocol (instead of over NBD) so it is affected by image locking.
6
Disable the lock.
7
8
Signed-off-by: Fam Zheng <famz@redhat.com>
9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
10
---
11
tests/test-replication.c | 9 +++++++--
12
1 file changed, 7 insertions(+), 2 deletions(-)
13
14
diff --git a/tests/test-replication.c b/tests/test-replication.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/tests/test-replication.c
17
+++ b/tests/test-replication.c
18
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_primary(void)
19
char *cmdline;
20
21
cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx,"
22
- "file.driver=qcow2,file.file.filename=%s"
23
+ "file.driver=qcow2,file.file.filename=%s,"
24
+ "file.file.locking=off"
25
, p_local_disk);
26
opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false);
27
g_free(cmdline);
28
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_secondary(void)
29
Error *local_err = NULL;
30
31
/* add s_local_disk and forge S_LOCAL_DISK_ID */
32
- cmdline = g_strdup_printf("file.filename=%s,driver=qcow2", s_local_disk);
33
+ cmdline = g_strdup_printf("file.filename=%s,driver=qcow2,"
34
+ "file.locking=off",
35
+ s_local_disk);
36
opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false);
37
g_free(cmdline);
38
39
@@ -XXX,XX +XXX,XX @@ static BlockBackend *start_secondary(void)
40
/* add S_(ACTIVE/HIDDEN)_DISK and forge S_ID */
41
cmdline = g_strdup_printf("driver=replication,mode=secondary,top-id=%s,"
42
"file.driver=qcow2,file.file.filename=%s,"
43
+ "file.file.locking=off,"
44
"file.backing.driver=qcow2,"
45
"file.backing.file.filename=%s,"
46
+ "file.backing.file.locking=off,"
47
"file.backing.backing=%s"
48
, S_ID, s_active_disk, s_hidden_disk
49
, S_LOCAL_DISK_ID);
50
--
51
1.8.3.1
52
53
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
They are wrappers of POSIX fcntl "file private locking", with a
4
convenient "try lock" wrapper implemented with F_OFD_GETLK.
5
6
Signed-off-by: Fam Zheng <famz@redhat.com>
7
Reviewed-by: Max Reitz <mreitz@redhat.com>
8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9
---
10
include/qemu/osdep.h | 3 +++
11
util/osdep.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
12
2 files changed, 51 insertions(+)
13
14
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/qemu/osdep.h
17
+++ b/include/qemu/osdep.h
18
@@ -XXX,XX +XXX,XX @@ int qemu_close(int fd);
19
#ifndef _WIN32
20
int qemu_dup(int fd);
21
#endif
22
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
23
+int qemu_unlock_fd(int fd, int64_t start, int64_t len);
24
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
25
26
#if defined(__HAIKU__) && defined(__i386__)
27
#define FMT_pid "%ld"
28
diff --git a/util/osdep.c b/util/osdep.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/util/osdep.c
31
+++ b/util/osdep.c
32
@@ -XXX,XX +XXX,XX @@ static int qemu_parse_fdset(const char *param)
33
{
34
return qemu_parse_fd(param);
35
}
36
+
37
+static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
38
+{
39
+#ifdef F_OFD_SETLK
40
+ int ret;
41
+ struct flock fl = {
42
+ .l_whence = SEEK_SET,
43
+ .l_start = start,
44
+ .l_len = len,
45
+ .l_type = fl_type,
46
+ };
47
+ ret = fcntl(fd, F_OFD_SETLK, &fl);
48
+ return ret == -1 ? -errno : 0;
49
+#else
50
+ return -ENOTSUP;
51
+#endif
52
+}
53
+
54
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
55
+{
56
+ return qemu_lock_fcntl(fd, start, len, exclusive ? F_WRLCK : F_RDLCK);
57
+}
58
+
59
+int qemu_unlock_fd(int fd, int64_t start, int64_t len)
60
+{
61
+ return qemu_lock_fcntl(fd, start, len, F_UNLCK);
62
+}
63
+
64
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
65
+{
66
+#ifdef F_OFD_SETLK
67
+ int ret;
68
+ struct flock fl = {
69
+ .l_whence = SEEK_SET,
70
+ .l_start = start,
71
+ .l_len = len,
72
+ .l_type = exclusive ? F_WRLCK : F_RDLCK,
73
+ };
74
+ ret = fcntl(fd, F_OFD_GETLK, &fl);
75
+ if (ret == -1) {
76
+ return -errno;
77
+ } else {
78
+ return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
79
+ }
80
+#else
81
+ return -ENOTSUP;
82
+#endif
83
+}
84
#endif
85
86
/*
87
--
88
1.8.3.1
89
90
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Alberto Faria <afaria@redhat.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
Setting it to true can cause the device size to be queried from libblkio
4
in otherwise fast paths, degrading performance. Set it to false and
5
require users to refresh the device size explicitly instead.
6
7
Fixes: 4c8f4fda0504 ("block/blkio: Tolerate device size changes")
8
Suggested-by: Kevin Wolf <kwolf@redhat.com>
9
Signed-off-by: Alberto Faria <afaria@redhat.com>
10
Message-Id: <20221108144433.1334074-1-afaria@redhat.com>
11
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
13
---
6
util/osdep.c | 20 ++++++++++----------
14
block/blkio.c | 1 -
7
1 file changed, 10 insertions(+), 10 deletions(-)
15
1 file changed, 1 deletion(-)
8
16
9
diff --git a/util/osdep.c b/util/osdep.c
17
diff --git a/block/blkio.c b/block/blkio.c
10
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
11
--- a/util/osdep.c
19
--- a/block/blkio.c
12
+++ b/util/osdep.c
20
+++ b/block/blkio.c
13
@@ -XXX,XX +XXX,XX @@ extern int madvise(caddr_t, size_t, int);
21
@@ -XXX,XX +XXX,XX @@ static void blkio_refresh_limits(BlockDriverState *bs, Error **errp)
14
#include "qemu/error-report.h"
22
{ \
15
#include "monitor/monitor.h"
23
.format_name = name, \
16
24
.protocol_name = name, \
17
+#ifdef F_OFD_SETLK
25
- .has_variable_length = true, \
18
+#define QEMU_SETLK F_OFD_SETLK
26
.instance_size = sizeof(BDRVBlkioState), \
19
+#define QEMU_GETLK F_OFD_GETLK
27
.bdrv_file_open = blkio_file_open, \
20
+#else
28
.bdrv_close = blkio_close, \
21
+#define QEMU_SETLK F_SETLK
22
+#define QEMU_GETLK F_GETLK
23
+#endif
24
+
25
static bool fips_enabled = false;
26
27
static const char *hw_version = QEMU_HW_VERSION;
28
@@ -XXX,XX +XXX,XX @@ static int qemu_parse_fdset(const char *param)
29
30
static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
31
{
32
-#ifdef F_OFD_SETLK
33
int ret;
34
struct flock fl = {
35
.l_whence = SEEK_SET,
36
@@ -XXX,XX +XXX,XX @@ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
37
.l_len = len,
38
.l_type = fl_type,
39
};
40
- ret = fcntl(fd, F_OFD_SETLK, &fl);
41
+ ret = fcntl(fd, QEMU_SETLK, &fl);
42
return ret == -1 ? -errno : 0;
43
-#else
44
- return -ENOTSUP;
45
-#endif
46
}
47
48
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
49
@@ -XXX,XX +XXX,XX @@ int qemu_unlock_fd(int fd, int64_t start, int64_t len)
50
51
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
52
{
53
-#ifdef F_OFD_SETLK
54
int ret;
55
struct flock fl = {
56
.l_whence = SEEK_SET,
57
@@ -XXX,XX +XXX,XX @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
58
.l_len = len,
59
.l_type = exclusive ? F_WRLCK : F_RDLCK,
60
};
61
- ret = fcntl(fd, F_OFD_GETLK, &fl);
62
+ ret = fcntl(fd, QEMU_GETLK, &fl);
63
if (ret == -1) {
64
return -errno;
65
} else {
66
return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
67
}
68
-#else
69
- return -ENOTSUP;
70
-#endif
71
}
72
#endif
73
74
--
29
--
75
1.8.3.1
30
2.38.1
76
77
diff view generated by jsdifflib
1
Instead of manually calling blk_resume_after_migration() in migration
1
From: Hanna Reitz <hreitz@redhat.com>
2
code after doing bdrv_invalidate_cache_all(), integrate the BlockBackend
3
activation with cache invalidation into a single function. This is
4
achieved with a new callback in BdrvChildRole that is called by
5
bdrv_invalidate_cache_all().
6
2
3
We want to use bdrv_child_get_parent_aio_context() from
4
bdrv_parent_drained_{begin,end}_single(), both of which are "I/O or GS"
5
functions.
6
7
Prior to 3ed4f708fe1, all the implementations were I/O code anyway.
8
3ed4f708fe1 has put block jobs' AioContext field under the job mutex, so
9
to make child_job_get_parent_aio_context() work in an I/O context, we
10
need to take that lock there.
11
12
Furthermore, blk_root_get_parent_aio_context() is not marked as
13
anything, but is safe to run in an I/O context, so mark it that way now.
14
(blk_get_aio_context() is an I/O code function.)
15
16
With that done, all implementations explicitly are I/O code, so we can
17
mark bdrv_child_get_parent_aio_context() as I/O code, too, so callers
18
know it is safe to run from both GS and I/O contexts.
19
20
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
21
Message-Id: <20221107151321.211175-2-hreitz@redhat.com>
22
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
23
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
---
24
---
10
block.c | 12 +++++++++-
25
include/block/block-global-state.h | 1 -
11
block/block-backend.c | 56 +++++++++++++++++++++++------------------------
26
include/block/block-io.h | 2 ++
12
include/block/block.h | 2 --
27
include/block/block_int-common.h | 4 ++--
13
include/block/block_int.h | 5 +++++
28
block.c | 2 +-
14
migration/migration.c | 3 ---
29
block/block-backend.c | 1 +
15
migration/savevm.c | 3 ---
30
blockjob.c | 3 ++-
16
qmp.c | 6 -----
31
6 files changed, 8 insertions(+), 5 deletions(-)
17
7 files changed, 44 insertions(+), 43 deletions(-)
18
32
33
diff --git a/include/block/block-global-state.h b/include/block/block-global-state.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/include/block/block-global-state.h
36
+++ b/include/block/block-global-state.h
37
@@ -XXX,XX +XXX,XX @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs);
38
*/
39
void coroutine_fn bdrv_co_unlock(BlockDriverState *bs);
40
41
-AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c);
42
bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx,
43
GHashTable *visited, Transaction *tran,
44
Error **errp);
45
diff --git a/include/block/block-io.h b/include/block/block-io.h
46
index XXXXXXX..XXXXXXX 100644
47
--- a/include/block/block-io.h
48
+++ b/include/block/block-io.h
49
@@ -XXX,XX +XXX,XX @@ void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event);
50
*/
51
AioContext *bdrv_get_aio_context(BlockDriverState *bs);
52
53
+AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c);
54
+
55
/**
56
* Move the current coroutine to the AioContext of @bs and return the old
57
* AioContext of the coroutine. Increase bs->in_flight so that draining @bs
58
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
59
index XXXXXXX..XXXXXXX 100644
60
--- a/include/block/block_int-common.h
61
+++ b/include/block/block_int-common.h
62
@@ -XXX,XX +XXX,XX @@ struct BdrvChildClass {
63
GHashTable *visited, Transaction *tran,
64
Error **errp);
65
66
- AioContext *(*get_parent_aio_context)(BdrvChild *child);
67
-
68
/*
69
* I/O API functions. These functions are thread-safe.
70
*
71
@@ -XXX,XX +XXX,XX @@ struct BdrvChildClass {
72
*/
73
const char *(*get_name)(BdrvChild *child);
74
75
+ AioContext *(*get_parent_aio_context)(BdrvChild *child);
76
+
77
/*
78
* If this pair of functions is implemented, the parent doesn't issue new
79
* requests after returning from .drained_begin() until .drained_end() is
19
diff --git a/block.c b/block.c
80
diff --git a/block.c b/block.c
20
index XXXXXXX..XXXXXXX 100644
81
index XXXXXXX..XXXXXXX 100644
21
--- a/block.c
82
--- a/block.c
22
+++ b/block.c
83
+++ b/block.c
23
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
84
@@ -XXX,XX +XXX,XX @@ const BdrvChildClass child_of_bds = {
24
85
25
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
86
AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c)
26
{
87
{
27
- BdrvChild *child;
88
- GLOBAL_STATE_CODE();
28
+ BdrvChild *child, *parent;
89
+ IO_CODE();
29
Error *local_err = NULL;
90
return c->klass->get_parent_aio_context(c);
30
int ret;
31
32
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
33
error_setg_errno(errp, -ret, "Could not refresh total sector count");
34
return;
35
}
36
+
37
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
38
+ if (parent->role->activate) {
39
+ parent->role->activate(parent, &local_err);
40
+ if (local_err) {
41
+ error_propagate(errp, local_err);
42
+ return;
43
+ }
44
+ }
45
+ }
46
}
91
}
47
92
48
void bdrv_invalidate_cache_all(Error **errp)
49
diff --git a/block/block-backend.c b/block/block-backend.c
93
diff --git a/block/block-backend.c b/block/block-backend.c
50
index XXXXXXX..XXXXXXX 100644
94
index XXXXXXX..XXXXXXX 100644
51
--- a/block/block-backend.c
95
--- a/block/block-backend.c
52
+++ b/block/block-backend.c
96
+++ b/block/block-backend.c
53
@@ -XXX,XX +XXX,XX @@ static const char *blk_root_get_name(BdrvChild *child)
97
@@ -XXX,XX +XXX,XX @@ static void blk_root_detach(BdrvChild *child)
54
return blk_name(child->opaque);
98
static AioContext *blk_root_get_parent_aio_context(BdrvChild *c)
99
{
100
BlockBackend *blk = c->opaque;
101
+ IO_CODE();
102
103
return blk_get_aio_context(blk);
55
}
104
}
56
105
diff --git a/blockjob.c b/blockjob.c
57
+/*
106
index XXXXXXX..XXXXXXX 100644
58
+ * Notifies the user of the BlockBackend that migration has completed. qdev
107
--- a/blockjob.c
59
+ * devices can tighten their permissions in response (specifically revoke
108
+++ b/blockjob.c
60
+ * shared write permissions that we needed for storage migration).
109
@@ -XXX,XX +XXX,XX @@ static bool child_job_change_aio_ctx(BdrvChild *c, AioContext *ctx,
61
+ *
110
static AioContext *child_job_get_parent_aio_context(BdrvChild *c)
62
+ * If an error is returned, the VM cannot be allowed to be resumed.
111
{
63
+ */
112
BlockJob *job = c->opaque;
64
+static void blk_root_activate(BdrvChild *child, Error **errp)
113
- GLOBAL_STATE_CODE();
65
+{
114
+ IO_CODE();
66
+ BlockBackend *blk = child->opaque;
115
+ JOB_LOCK_GUARD();
67
+ Error *local_err = NULL;
116
68
+
117
return job->job.aio_context;
69
+ if (!blk->disable_perm) {
70
+ return;
71
+ }
72
+
73
+ blk->disable_perm = false;
74
+
75
+ blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
76
+ if (local_err) {
77
+ error_propagate(errp, local_err);
78
+ blk->disable_perm = true;
79
+ return;
80
+ }
81
+}
82
+
83
static const BdrvChildRole child_root = {
84
.inherit_options = blk_root_inherit_options,
85
86
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
87
88
.drained_begin = blk_root_drained_begin,
89
.drained_end = blk_root_drained_end,
90
+
91
+ .activate = blk_root_activate,
92
};
93
94
/*
95
@@ -XXX,XX +XXX,XX @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
96
*shared_perm = blk->shared_perm;
97
}
118
}
98
99
-/*
100
- * Notifies the user of all BlockBackends that migration has completed. qdev
101
- * devices can tighten their permissions in response (specifically revoke
102
- * shared write permissions that we needed for storage migration).
103
- *
104
- * If an error is returned, the VM cannot be allowed to be resumed.
105
- */
106
-void blk_resume_after_migration(Error **errp)
107
-{
108
- BlockBackend *blk;
109
- Error *local_err = NULL;
110
-
111
- for (blk = blk_all_next(NULL); blk; blk = blk_all_next(blk)) {
112
- if (!blk->disable_perm) {
113
- continue;
114
- }
115
-
116
- blk->disable_perm = false;
117
-
118
- blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
119
- if (local_err) {
120
- error_propagate(errp, local_err);
121
- blk->disable_perm = true;
122
- return;
123
- }
124
- }
125
-}
126
-
127
static int blk_do_attach_dev(BlockBackend *blk, void *dev)
128
{
129
if (blk->dev) {
130
diff --git a/include/block/block.h b/include/block/block.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/include/block/block.h
133
+++ b/include/block/block.h
134
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
135
void bdrv_invalidate_cache_all(Error **errp);
136
int bdrv_inactivate_all(void);
137
138
-void blk_resume_after_migration(Error **errp);
139
-
140
/* Ensure contents are flushed to disk. */
141
int bdrv_flush(BlockDriverState *bs);
142
int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
143
diff --git a/include/block/block_int.h b/include/block/block_int.h
144
index XXXXXXX..XXXXXXX 100644
145
--- a/include/block/block_int.h
146
+++ b/include/block/block_int.h
147
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
148
void (*drained_begin)(BdrvChild *child);
149
void (*drained_end)(BdrvChild *child);
150
151
+ /* Notifies the parent that the child has been activated (e.g. when
152
+ * migration is completing) and it can start requesting permissions and
153
+ * doing I/O on it. */
154
+ void (*activate)(BdrvChild *child, Error **errp);
155
+
156
void (*attach)(BdrvChild *child);
157
void (*detach)(BdrvChild *child);
158
};
159
diff --git a/migration/migration.c b/migration/migration.c
160
index XXXXXXX..XXXXXXX 100644
161
--- a/migration/migration.c
162
+++ b/migration/migration.c
163
@@ -XXX,XX +XXX,XX @@ static void process_incoming_migration_bh(void *opaque)
164
/* Make sure all file formats flush their mutable metadata.
165
* If we get an error here, just don't restart the VM yet. */
166
bdrv_invalidate_cache_all(&local_err);
167
- if (!local_err) {
168
- blk_resume_after_migration(&local_err);
169
- }
170
if (local_err) {
171
error_report_err(local_err);
172
local_err = NULL;
173
diff --git a/migration/savevm.c b/migration/savevm.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/migration/savevm.c
176
+++ b/migration/savevm.c
177
@@ -XXX,XX +XXX,XX @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
178
/* Make sure all file formats flush their mutable metadata.
179
* If we get an error here, just don't restart the VM yet. */
180
bdrv_invalidate_cache_all(&local_err);
181
- if (!local_err) {
182
- blk_resume_after_migration(&local_err);
183
- }
184
if (local_err) {
185
error_report_err(local_err);
186
local_err = NULL;
187
diff --git a/qmp.c b/qmp.c
188
index XXXXXXX..XXXXXXX 100644
189
--- a/qmp.c
190
+++ b/qmp.c
191
@@ -XXX,XX +XXX,XX @@ void qmp_cont(Error **errp)
192
return;
193
}
194
195
- blk_resume_after_migration(&local_err);
196
- if (local_err) {
197
- error_propagate(errp, local_err);
198
- return;
199
- }
200
-
201
if (runstate_check(RUN_STATE_INMIGRATE)) {
202
autostart = 1;
203
} else {
204
--
119
--
205
1.8.3.1
120
2.38.1
206
207
diff view generated by jsdifflib
1
With image locking, permissions affect other qemu processes as well. We
1
From: Hanna Reitz <hreitz@redhat.com>
2
want to be sure that the destination can run, so let's drop permissions
3
on the source when migration completes.
4
2
3
blk_get_aio_context() asserts that blk->ctx is always equal to the root
4
BDS's context (if there is a root BDS). Therefore,
5
blk_do_set_aio_context() must update blk->ctx immediately after the root
6
BDS's context has changed.
7
8
Without this patch, the next patch would break iotest 238, because
9
bdrv_drained_begin() (called by blk_do_set_aio_context()) may then
10
invoke bdrv_child_get_parent_aio_context() on the root child, i.e.
11
blk_get_aio_context(). However, by this point, blk->ctx would not have
12
been updated and thus differ from the root node's context. This patch
13
fixes that.
14
15
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
16
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
17
Message-Id: <20221107151321.211175-3-hreitz@redhat.com>
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
19
---
8
block.c | 12 +++++++++++-
20
block/block-backend.c | 8 +++++++-
9
block/block-backend.c | 25 +++++++++++++++++++++++++
21
1 file changed, 7 insertions(+), 1 deletion(-)
10
include/block/block_int.h | 7 ++++---
11
3 files changed, 40 insertions(+), 4 deletions(-)
12
22
13
diff --git a/block.c b/block.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/block.c
16
+++ b/block.c
17
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache_all(Error **errp)
18
static int bdrv_inactivate_recurse(BlockDriverState *bs,
19
bool setting_flag)
20
{
21
- BdrvChild *child;
22
+ BdrvChild *child, *parent;
23
int ret;
24
25
if (!setting_flag && bs->drv->bdrv_inactivate) {
26
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
27
28
if (setting_flag) {
29
bs->open_flags |= BDRV_O_INACTIVE;
30
+
31
+ QLIST_FOREACH(parent, &bs->parents, next_parent) {
32
+ if (parent->role->inactivate) {
33
+ ret = parent->role->inactivate(parent);
34
+ if (ret < 0) {
35
+ bs->open_flags &= ~BDRV_O_INACTIVE;
36
+ return ret;
37
+ }
38
+ }
39
+ }
40
}
41
return 0;
42
}
43
diff --git a/block/block-backend.c b/block/block-backend.c
23
diff --git a/block/block-backend.c b/block/block-backend.c
44
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
45
--- a/block/block-backend.c
25
--- a/block/block-backend.c
46
+++ b/block/block-backend.c
26
+++ b/block/block-backend.c
47
@@ -XXX,XX +XXX,XX @@ static void blk_root_activate(BdrvChild *child, Error **errp)
27
@@ -XXX,XX +XXX,XX @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
28
return ret;
29
}
30
}
31
+ /*
32
+ * Make blk->ctx consistent with the root node before we invoke any
33
+ * other operations like drain that might inquire blk->ctx
34
+ */
35
+ blk->ctx = new_context;
36
if (tgm->throttle_state) {
37
bdrv_drained_begin(bs);
38
throttle_group_detach_aio_context(tgm);
39
@@ -XXX,XX +XXX,XX @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
40
}
41
42
bdrv_unref(bs);
43
+ } else {
44
+ blk->ctx = new_context;
48
}
45
}
46
47
- blk->ctx = new_context;
48
return 0;
49
}
49
}
50
50
51
+static int blk_root_inactivate(BdrvChild *child)
52
+{
53
+ BlockBackend *blk = child->opaque;
54
+
55
+ if (blk->disable_perm) {
56
+ return 0;
57
+ }
58
+
59
+ /* Only inactivate BlockBackends for guest devices (which are inactive at
60
+ * this point because the VM is stopped) and unattached monitor-owned
61
+ * BlockBackends. If there is still any other user like a block job, then
62
+ * we simply can't inactivate the image. */
63
+ if (!blk->dev && !blk->name[0]) {
64
+ return -EPERM;
65
+ }
66
+
67
+ blk->disable_perm = true;
68
+ if (blk->root) {
69
+ bdrv_child_try_set_perm(blk->root, 0, BLK_PERM_ALL, &error_abort);
70
+ }
71
+
72
+ return 0;
73
+}
74
+
75
static const BdrvChildRole child_root = {
76
.inherit_options = blk_root_inherit_options,
77
78
@@ -XXX,XX +XXX,XX @@ static const BdrvChildRole child_root = {
79
.drained_end = blk_root_drained_end,
80
81
.activate = blk_root_activate,
82
+ .inactivate = blk_root_inactivate,
83
};
84
85
/*
86
diff --git a/include/block/block_int.h b/include/block/block_int.h
87
index XXXXXXX..XXXXXXX 100644
88
--- a/include/block/block_int.h
89
+++ b/include/block/block_int.h
90
@@ -XXX,XX +XXX,XX @@ struct BdrvChildRole {
91
void (*drained_begin)(BdrvChild *child);
92
void (*drained_end)(BdrvChild *child);
93
94
- /* Notifies the parent that the child has been activated (e.g. when
95
- * migration is completing) and it can start requesting permissions and
96
- * doing I/O on it. */
97
+ /* Notifies the parent that the child has been activated/inactivated (e.g.
98
+ * when migration is completing) and it can start/stop requesting
99
+ * permissions and doing I/O on it. */
100
void (*activate)(BdrvChild *child, Error **errp);
101
+ int (*inactivate)(BdrvChild *child);
102
103
void (*attach)(BdrvChild *child);
104
void (*detach)(BdrvChild *child);
105
--
51
--
106
1.8.3.1
52
2.38.1
107
108
diff view generated by jsdifflib
1
From: Eric Blake <eblake@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
Although _filter_qemu_img_map documents that it scrubs offsets, it
3
bdrv_parent_drained_{begin,end}_single() are supposed to operate on the
4
was only doing so for human mode. Of the existing tests using the
4
parent, not on the child, so they should not attempt to get the context
5
filter (97, 122, 150, 154, 176), two of them are affected, but it
5
to poll from the child but the parent instead. BDRV_POLL_WHILE(c->bs)
6
does not hurt the validity of the tests to not require particular
6
does get the context from the child, so we should replace it with
7
mappings (another test, 66, uses offsets but intentionally does not
7
AIO_WAIT_WHILE() on the parent's context instead.
8
pass through _filter_qemu_img_map, because it checks that offsets
9
are unchanged before and after an operation).
10
8
11
Another justification for this patch is that it will allow a future
9
This problem becomes apparent when bdrv_replace_child_noperm() invokes
12
patch to utilize 'qemu-img map --output=json' to check the status of
10
bdrv_parent_drained_end_single() after removing a child from a subgraph
13
preallocated zero clusters without regards to the mapping (since
11
that is in an I/O thread. By the time bdrv_parent_drained_end_single()
14
the qcow2 mapping can be very sensitive to the chosen cluster size,
12
is called, child->bs is NULL, and so BDRV_POLL_WHILE(c->bs, ...) will
15
when preallocation is not in use).
13
poll the main loop instead of the I/O thread; but anything that
14
bdrv_parent_drained_end_single_no_poll() may have scheduled is going to
15
want to run in the I/O thread, but because we poll the main loop, the
16
I/O thread is never unpaused, and nothing is run, resulting in a
17
deadlock.
16
18
17
Signed-off-by: Eric Blake <eblake@redhat.com>
19
Closes: https://gitlab.com/qemu-project/qemu/-/issues/1215
18
Reviewed-by: Max Reitz <mreitz@redhat.com>
20
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
19
Message-id: 20170507000552.20847-9-eblake@redhat.com
21
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
20
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
Message-Id: <20221107151321.211175-4-hreitz@redhat.com>
23
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
21
---
24
---
22
tests/qemu-iotests/122.out | 16 ++++++++--------
25
block/io.c | 6 ++++--
23
tests/qemu-iotests/154.out | 30 +++++++++++++++---------------
26
1 file changed, 4 insertions(+), 2 deletions(-)
24
tests/qemu-iotests/common.filter | 4 +++-
25
3 files changed, 26 insertions(+), 24 deletions(-)
26
27
27
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
28
diff --git a/block/io.c b/block/io.c
28
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
29
--- a/tests/qemu-iotests/122.out
30
--- a/block/io.c
30
+++ b/tests/qemu-iotests/122.out
31
+++ b/block/io.c
31
@@ -XXX,XX +XXX,XX @@ read 3145728/3145728 bytes at offset 0
32
@@ -XXX,XX +XXX,XX @@ static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c,
32
3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
33
void bdrv_parent_drained_end_single(BdrvChild *c)
33
read 63963136/63963136 bytes at offset 3145728
34
{
34
61 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
35
int drained_end_counter = 0;
35
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
36
+ AioContext *ctx = bdrv_child_get_parent_aio_context(c);
36
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
37
IO_OR_GS_CODE();
37
38
bdrv_parent_drained_end_single_no_poll(c, &drained_end_counter);
38
convert -c -S 0:
39
- BDRV_POLL_WHILE(c->bs, qatomic_read(&drained_end_counter) > 0);
39
read 3145728/3145728 bytes at offset 0
40
+ AIO_WAIT_WHILE(ctx, qatomic_read(&drained_end_counter) > 0);
40
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
41
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
42
read 33554432/33554432 bytes at offset 33554432
43
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
44
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
45
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
46
47
convert -c -S 0 with source backing file:
48
read 3145728/3145728 bytes at offset 0
49
@@ -XXX,XX +XXX,XX @@ read 30408704/30408704 bytes at offset 3145728
50
29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
51
read 33554432/33554432 bytes at offset 33554432
52
32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
53
-[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": 327680}]
54
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
55
56
convert -c -S 0 -B ...
57
read 3145728/3145728 bytes at offset 0
58
@@ -XXX,XX +XXX,XX @@ wrote 1024/1024 bytes at offset 17408
59
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
60
61
convert -S 4k
62
-[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 8192},
63
+[{ "start": 0, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
64
{ "start": 1024, "length": 7168, "depth": 0, "zero": true, "data": false},
65
-{ "start": 8192, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 9216},
66
+{ "start": 8192, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
67
{ "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false},
68
-{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 10240},
69
+{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
70
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
71
72
convert -c -S 4k
73
@@ -XXX,XX +XXX,XX @@ convert -c -S 4k
74
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
75
76
convert -S 8k
77
-[{ "start": 0, "length": 9216, "depth": 0, "zero": false, "data": true, "offset": 8192},
78
+[{ "start": 0, "length": 9216, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
79
{ "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false},
80
-{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": 17408},
81
+{ "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
82
{ "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}]
83
84
convert -c -S 8k
85
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
86
index XXXXXXX..XXXXXXX 100644
87
--- a/tests/qemu-iotests/154.out
88
+++ b/tests/qemu-iotests/154.out
89
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 65536
90
read 2048/2048 bytes at offset 67584
91
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
92
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
93
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
94
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
95
{ "start": 36864, "length": 28672, "depth": 1, "zero": true, "data": false},
96
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
97
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
98
{ "start": 69632, "length": 134148096, "depth": 1, "zero": true, "data": false}]
99
100
== backing file contains non-zero data after write_zeroes ==
101
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 44032
102
read 3072/3072 bytes at offset 40960
103
3 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
104
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
105
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
106
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
107
{ "start": 36864, "length": 4096, "depth": 1, "zero": true, "data": false},
108
-{ "start": 40960, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
109
+{ "start": 40960, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
110
{ "start": 45056, "length": 134172672, "depth": 1, "zero": true, "data": false}]
111
112
== write_zeroes covers non-zero data ==
113
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 67584
114
read 5120/5120 bytes at offset 68608
115
5 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
116
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
117
-{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
118
+{ "start": 32768, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
119
{ "start": 36864, "length": 4096, "depth": 0, "zero": true, "data": false},
120
{ "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false},
121
-{ "start": 49152, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
122
+{ "start": 49152, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
123
{ "start": 53248, "length": 4096, "depth": 0, "zero": true, "data": false},
124
{ "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false},
125
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672},
126
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
127
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
128
{ "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}]
129
130
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 72704
131
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
132
[{ "start": 0, "length": 32768, "depth": 1, "zero": true, "data": false},
133
{ "start": 32768, "length": 4096, "depth": 0, "zero": true, "data": false},
134
-{ "start": 36864, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
135
+{ "start": 36864, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
136
{ "start": 40960, "length": 8192, "depth": 1, "zero": true, "data": false},
137
{ "start": 49152, "length": 4096, "depth": 0, "zero": true, "data": false},
138
-{ "start": 53248, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
139
+{ "start": 53248, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
140
{ "start": 57344, "length": 8192, "depth": 1, "zero": true, "data": false},
141
{ "start": 65536, "length": 4096, "depth": 0, "zero": true, "data": false},
142
-{ "start": 69632, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 28672},
143
+{ "start": 69632, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
144
{ "start": 73728, "length": 134144000, "depth": 1, "zero": true, "data": false}]
145
146
== spanning two clusters, partially overwriting backing file ==
147
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 5120
148
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
149
read 2048/2048 bytes at offset 6144
150
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
151
-[{ "start": 0, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": 20480},
152
+[{ "start": 0, "length": 8192, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
153
{ "start": 8192, "length": 134209536, "depth": 1, "zero": true, "data": false}]
154
155
== spanning multiple clusters, non-zero in first cluster ==
156
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 65536
157
read 10240/10240 bytes at offset 67584
158
10 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
159
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
160
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
161
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
162
{ "start": 69632, "length": 8192, "depth": 0, "zero": true, "data": false},
163
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
164
165
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 75776
166
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
167
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
168
{ "start": 65536, "length": 8192, "depth": 0, "zero": true, "data": false},
169
-{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
170
+{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
171
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
172
173
== spanning multiple clusters, partially overwriting backing file ==
174
@@ -XXX,XX +XXX,XX @@ read 2048/2048 bytes at offset 74752
175
read 1024/1024 bytes at offset 76800
176
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
177
[{ "start": 0, "length": 65536, "depth": 1, "zero": true, "data": false},
178
-{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 20480},
179
+{ "start": 65536, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
180
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
181
-{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": 24576},
182
+{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
183
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
184
*** done
185
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
186
index XXXXXXX..XXXXXXX 100644
187
--- a/tests/qemu-iotests/common.filter
188
+++ b/tests/qemu-iotests/common.filter
189
@@ -XXX,XX +XXX,XX @@ _filter_img_info()
190
-e "/log_size: [0-9]\\+/d"
191
}
41
}
192
42
193
-# filter out offsets and file names from qemu-img map
43
static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore,
194
+# filter out offsets and file names from qemu-img map; good for both
44
@@ -XXX,XX +XXX,XX @@ static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *ignore,
195
+# human and json output
45
196
_filter_qemu_img_map()
46
void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
197
{
47
{
198
sed -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
48
+ AioContext *ctx = bdrv_child_get_parent_aio_context(c);
199
+ -e 's/"offset": [0-9]\+/"offset": OFFSET/g' \
49
IO_OR_GS_CODE();
200
-e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt
50
c->parent_quiesce_counter++;
51
if (c->klass->drained_begin) {
52
c->klass->drained_begin(c);
53
}
54
if (poll) {
55
- BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c));
56
+ AIO_WAIT_WHILE(ctx, bdrv_parent_drained_poll_single(c));
57
}
201
}
58
}
202
59
203
--
60
--
204
1.8.3.1
61
2.38.1
205
206
diff view generated by jsdifflib
1
From: Fam Zheng <famz@redhat.com>
1
From: Hanna Reitz <hreitz@redhat.com>
2
2
3
Signed-off-by: Fam Zheng <famz@redhat.com>
3
Test streaming a base image into the top image underneath two throttle
4
nodes. This was reported to make qemu 7.1 hang
5
(https://gitlab.com/qemu-project/qemu/-/issues/1215), so this serves as
6
a regression test.
7
8
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
9
Message-Id: <20221110160921.33158-1-hreitz@redhat.com>
10
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
12
---
6
tests/qemu-iotests/153 | 233 +++++++++++++++++++++++++++
13
.../qemu-iotests/tests/stream-under-throttle | 121 ++++++++++++++++++
7
tests/qemu-iotests/153.out | 390 +++++++++++++++++++++++++++++++++++++++++++++
14
.../tests/stream-under-throttle.out | 5 +
8
tests/qemu-iotests/group | 1 +
15
2 files changed, 126 insertions(+)
9
3 files changed, 624 insertions(+)
16
create mode 100755 tests/qemu-iotests/tests/stream-under-throttle
10
create mode 100755 tests/qemu-iotests/153
17
create mode 100644 tests/qemu-iotests/tests/stream-under-throttle.out
11
create mode 100644 tests/qemu-iotests/153.out
12
18
13
diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
19
diff --git a/tests/qemu-iotests/tests/stream-under-throttle b/tests/qemu-iotests/tests/stream-under-throttle
14
new file mode 100755
20
new file mode 100755
15
index XXXXXXX..XXXXXXX
21
index XXXXXXX..XXXXXXX
16
--- /dev/null
22
--- /dev/null
17
+++ b/tests/qemu-iotests/153
23
+++ b/tests/qemu-iotests/tests/stream-under-throttle
18
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
25
+#!/usr/bin/env python3
26
+# group: rw
20
+#
27
+#
21
+# Test image locking
28
+# Test streaming with throttle nodes on top
22
+#
29
+#
23
+# Copyright 2016, 2017 Red Hat, Inc.
30
+# Copyright (C) 2022 Red Hat, Inc.
24
+#
31
+#
25
+# This program is free software; you can redistribute it and/or modify
32
+# This program is free software; you can redistribute it and/or modify
26
+# it under the terms of the GNU General Public License as published by
33
+# it under the terms of the GNU General Public License as published by
27
+# the Free Software Foundation; either version 2 of the License, or
34
+# the Free Software Foundation; either version 2 of the License, or
28
+# (at your option) any later version.
35
+# (at your option) any later version.
...
...
34
+#
41
+#
35
+# You should have received a copy of the GNU General Public License
42
+# You should have received a copy of the GNU General Public License
36
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
43
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
44
+#
38
+
45
+
39
+# creator
46
+import asyncio
40
+owner=famz@redhat.com
47
+import os
48
+from typing import List
49
+import iotests
50
+from iotests import qemu_img_create, qemu_io
41
+
51
+
42
+seq="$(basename $0)"
43
+echo "QA output created by $seq"
44
+
52
+
45
+here="$PWD"
53
+image_size = 256 * 1024 * 1024
46
+tmp=/tmp/$$
54
+base_img = os.path.join(iotests.test_dir, 'base.img')
47
+status=1    # failure is the default!
55
+top_img = os.path.join(iotests.test_dir, 'top.img')
48
+
56
+
49
+_cleanup()
50
+{
51
+ _cleanup_test_img
52
+ rm -f "${TEST_IMG}.base"
53
+ rm -f "${TEST_IMG}.convert"
54
+ rm -f "${TEST_IMG}.a"
55
+ rm -f "${TEST_IMG}.b"
56
+ rm -f "${TEST_IMG}.lnk"
57
+}
58
+trap "_cleanup; exit \$status" 0 1 2 3 15
59
+
57
+
60
+# get standard environment, filters and checks
58
+class TcgVM(iotests.VM):
61
+. ./common.rc
59
+ '''
62
+. ./common.filter
60
+ Variant of iotests.VM that uses -accel tcg. Simply using
63
+. ./common.qemu
61
+ iotests.VM.add_args('-accel', 'tcg') is not sufficient, because that will
62
+ put -accel qtest before -accel tcg, and -accel arguments are prioritized in
63
+ the order they appear.
64
+ '''
65
+ @property
66
+ def _base_args(self) -> List[str]:
67
+ # Put -accel tcg first so it takes precedence
68
+ return ['-accel', 'tcg'] + super()._base_args
64
+
69
+
65
+size=32M
66
+
70
+
67
+_check_ofd()
71
+class TestStreamWithThrottle(iotests.QMPTestCase):
68
+{
72
+ def setUp(self) -> None:
69
+ _make_test_img $size >/dev/null
73
+ '''
70
+ if $QEMU_IMG_PROG info --image-opts "driver=file,locking=on,filename=$TEST_IMG" 2>&1 |
74
+ Create a simple backing chain between two images, write something to
71
+ grep -q 'falling back to POSIX file'; then
75
+ the base image. Attach them to the VM underneath two throttle nodes,
72
+ return 1
76
+ one of which has actually no limits set, but the other does. Then put
73
+ else
77
+ a virtio-blk device on top.
74
+ return 0
78
+ This test configuration has been taken from
75
+ fi
79
+ https://gitlab.com/qemu-project/qemu/-/issues/1215
76
+}
80
+ '''
81
+ qemu_img_create('-f', iotests.imgfmt, base_img, str(image_size))
82
+ qemu_img_create('-f', iotests.imgfmt, '-b', base_img, '-F',
83
+ iotests.imgfmt, top_img, str(image_size))
77
+
84
+
78
+_check_ofd || _notrun "OFD lock not available"
85
+ # Write something to stream
86
+ qemu_io(base_img, '-c', f'write 0 {image_size}')
79
+
87
+
80
+_supported_fmt qcow2
88
+ blockdev = {
81
+_supported_proto file
89
+ 'driver': 'throttle',
82
+_supported_os Linux
90
+ 'node-name': 'throttled-node',
91
+ 'throttle-group': 'thrgr-limited',
92
+ 'file': {
93
+ 'driver': 'throttle',
94
+ 'throttle-group': 'thrgr-unlimited',
95
+ 'file': {
96
+ 'driver': iotests.imgfmt,
97
+ 'node-name': 'unthrottled-node',
98
+ 'file': {
99
+ 'driver': 'file',
100
+ 'filename': top_img
101
+ }
102
+ }
103
+ }
104
+ }
83
+
105
+
84
+_run_cmd()
106
+ # Issue 1215 is not reproducible in qtest mode, which is why we need to
85
+{
107
+ # create an -accel tcg VM
86
+ echo
108
+ self.vm = TcgVM()
87
+ (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
109
+ self.vm.add_object('iothread,id=iothr0')
88
+}
110
+ self.vm.add_object('throttle-group,id=thrgr-unlimited')
111
+ self.vm.add_object('throttle-group,id=thrgr-limited,'
112
+ 'x-iops-total=10000,x-bps-total=104857600')
113
+ self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev))
114
+ self.vm.add_device('virtio-blk,iothread=iothr0,drive=throttled-node')
115
+ self.vm.launch()
89
+
116
+
90
+function _do_run_qemu()
117
+ def tearDown(self) -> None:
91
+{
118
+ self.vm.shutdown()
92
+ (
119
+ os.remove(top_img)
93
+ if ! test -t 0; then
120
+ os.remove(base_img)
94
+ while read cmd; do
95
+ echo $cmd
96
+ done
97
+ fi
98
+ echo quit
99
+ ) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
100
+}
101
+
121
+
102
+function _run_qemu_with_images()
122
+ def test_stream(self) -> None:
103
+{
123
+ '''
104
+ _do_run_qemu \
124
+ Do a simple stream beneath the two throttle nodes. Should complete
105
+ $(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
125
+ with no problems.
106
+ | _filter_testdir | _filter_qemu
126
+ '''
107
+}
127
+ result = self.vm.qmp('block-stream',
128
+ job_id='stream',
129
+ device='unthrottled-node')
130
+ self.assert_qmp(result, 'return', {})
108
+
131
+
109
+echo "== readonly=off,force-share=on should be rejected =="
132
+ # Should succeed and not time out
110
+_run_qemu_with_images null-co://,readonly=off,force-share=on
133
+ try:
134
+ self.vm.run_job('stream')
135
+ except asyncio.exceptions.TimeoutError:
136
+ # VM may be stuck, kill it before tearDown()
137
+ self.vm.kill()
138
+ raise
111
+
139
+
112
+for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
113
+ echo
114
+ echo "== Creating base image =="
115
+ TEST_IMG="${TEST_IMG}.base" _make_test_img $size
116
+
140
+
117
+ echo
141
+if __name__ == '__main__':
118
+ echo "== Creating test image =="
142
+ # Must support backing images
119
+ $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | _filter_img_create
143
+ iotests.main(supported_fmts=['qcow', 'qcow2', 'qed'],
120
+
144
+ supported_protocols=['file'],
121
+ echo
145
+ required_fmts=['throttle'])
122
+ echo "== Launching QEMU, opts: '$opts1' =="
146
diff --git a/tests/qemu-iotests/tests/stream-under-throttle.out b/tests/qemu-iotests/tests/stream-under-throttle.out
123
+ _launch_qemu -drive file="${TEST_IMG}",if=none,$opts1
124
+ h=$QEMU_HANDLE
125
+
126
+ for opts2 in "" "read-only=on" "read-only=on,force-share=on"; do
127
+ echo
128
+ echo "== Launching another QEMU, opts: '$opts2' =="
129
+ echo "quit" | \
130
+ $QEMU -nographic -monitor stdio \
131
+ -drive file="${TEST_IMG}",if=none,$opts2 2>&1 1>/dev/null | \
132
+ _filter_testdir | _filter_qemu
133
+ done
134
+
135
+ for L in "" "-U"; do
136
+
137
+ echo
138
+ echo "== Running utility commands $L =="
139
+ _run_cmd $QEMU_IO $L -c "read 0 512" "${TEST_IMG}"
140
+ _run_cmd $QEMU_IO $L -r -c "read 0 512" "${TEST_IMG}"
141
+ _run_cmd $QEMU_IO -c "open $L ${TEST_IMG}" -c "read 0 512"
142
+ _run_cmd $QEMU_IO -c "open -r $L ${TEST_IMG}" -c "read 0 512"
143
+ _run_cmd $QEMU_IMG info $L "${TEST_IMG}"
144
+ _run_cmd $QEMU_IMG check $L "${TEST_IMG}"
145
+ _run_cmd $QEMU_IMG compare $L "${TEST_IMG}" "${TEST_IMG}"
146
+ _run_cmd $QEMU_IMG map $L "${TEST_IMG}"
147
+ _run_cmd $QEMU_IMG amend -o "" $L "${TEST_IMG}"
148
+ _run_cmd $QEMU_IMG commit $L "${TEST_IMG}"
149
+ _run_cmd $QEMU_IMG resize $L "${TEST_IMG}" $size
150
+ _run_cmd $QEMU_IMG rebase $L "${TEST_IMG}" -b "${TEST_IMG}.base"
151
+ _run_cmd $QEMU_IMG snapshot -l $L "${TEST_IMG}"
152
+ _run_cmd $QEMU_IMG convert $L "${TEST_IMG}" "${TEST_IMG}.convert"
153
+ _run_cmd $QEMU_IMG dd $L if="${TEST_IMG}" of="${TEST_IMG}.convert" bs=512 count=1
154
+ _run_cmd $QEMU_IMG bench $L -c 1 "${TEST_IMG}"
155
+ _run_cmd $QEMU_IMG bench $L -w -c 1 "${TEST_IMG}"
156
+ done
157
+ _send_qemu_cmd $h "{ 'execute': 'quit', }" ""
158
+ echo
159
+ echo "Round done"
160
+ _cleanup_qemu
161
+done
162
+
163
+for opt1 in $test_opts; do
164
+ for opt2 in $test_opts; do
165
+ echo
166
+ echo "== Two devices with the same image ($opt1 - $opt2) =="
167
+ _run_qemu_with_images "${TEST_IMG},$opt1" "${TEST_IMG},$opt2"
168
+ done
169
+done
170
+
171
+echo "== Creating ${TEST_IMG}.[abc] ==" | _filter_testdir
172
+(
173
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.a" -b "${TEST_IMG}"
174
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.b" -b "${TEST_IMG}"
175
+ $QEMU_IMG create -f qcow2 "${TEST_IMG}.c" -b "${TEST_IMG}.b"
176
+) | _filter_img_create
177
+
178
+echo
179
+echo "== Two devices sharing the same file in backing chain =="
180
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.b"
181
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.c"
182
+
183
+echo
184
+echo "== Backing image also as an active device =="
185
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}"
186
+
187
+echo
188
+echo "== Backing image also as an active device (ro) =="
189
+_run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG},readonly=on"
190
+
191
+echo
192
+echo "== Symbolic link =="
193
+rm -f "${TEST_IMG}.lnk" &>/dev/null
194
+ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link"
195
+_run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}"
196
+
197
+echo
198
+echo "== Closing an image should unlock it =="
199
+_launch_qemu
200
+
201
+_send_qemu_cmd $QEMU_HANDLE \
202
+ "{ 'execute': 'qmp_capabilities' }" \
203
+ 'return'
204
+
205
+echo "Adding drive"
206
+_send_qemu_cmd $QEMU_HANDLE \
207
+ "{ 'execute': 'human-monitor-command',
208
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=d0,file=${TEST_IMG}' } }" \
209
+ ""
210
+
211
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
212
+
213
+echo "Closing drive"
214
+_send_qemu_cmd $QEMU_HANDLE \
215
+ "{ 'execute': 'human-monitor-command',
216
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
217
+ ""
218
+
219
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
220
+
221
+echo "Adding two and closing one"
222
+for d in d0 d1; do
223
+ _send_qemu_cmd $QEMU_HANDLE \
224
+ "{ 'execute': 'human-monitor-command',
225
+ 'arguments': { 'command-line': 'drive_add 0 if=none,id=$d,file=${TEST_IMG},readonly=on' } }" \
226
+ ""
227
+done
228
+
229
+_run_cmd $QEMU_IMG info "${TEST_IMG}"
230
+
231
+_send_qemu_cmd $QEMU_HANDLE \
232
+ "{ 'execute': 'human-monitor-command',
233
+ 'arguments': { 'command-line': 'drive_del d0' } }" \
234
+ ""
235
+
236
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
237
+
238
+echo "Closing the other"
239
+_send_qemu_cmd $QEMU_HANDLE \
240
+ "{ 'execute': 'human-monitor-command',
241
+ 'arguments': { 'command-line': 'drive_del d1' } }" \
242
+ ""
243
+
244
+_run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
245
+
246
+_cleanup_qemu
247
+
248
+# success, all done
249
+echo "*** done"
250
+rm -f $seq.full
251
+status=0
252
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
253
new file mode 100644
147
new file mode 100644
254
index XXXXXXX..XXXXXXX
148
index XXXXXXX..XXXXXXX
255
--- /dev/null
149
--- /dev/null
256
+++ b/tests/qemu-iotests/153.out
150
+++ b/tests/qemu-iotests/tests/stream-under-throttle.out
257
@@ -XXX,XX +XXX,XX @@
151
@@ -XXX,XX +XXX,XX @@
258
+QA output created by 153
152
+.
259
+== readonly=off,force-share=on should be rejected ==
153
+----------------------------------------------------------------------
260
+QEMU_PROG: -drive if=none,file=null-co://,readonly=off,force-share=on: force-share=on can only be used with read-only images
154
+Ran 1 tests
261
+
155
+
262
+== Creating base image ==
156
+OK
263
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
264
+
265
+== Creating test image ==
266
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
267
+
268
+== Launching QEMU, opts: '' ==
269
+
270
+== Launching another QEMU, opts: '' ==
271
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
272
+Is another process using the image?
273
+
274
+== Launching another QEMU, opts: 'read-only=on' ==
275
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,read-only=on: Failed to get shared "write" lock
276
+Is another process using the image?
277
+
278
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
279
+
280
+== Running utility commands ==
281
+
282
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
283
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
284
+Is another process using the image?
285
+
286
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
287
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
288
+Is another process using the image?
289
+
290
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
291
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
292
+Is another process using the image?
293
+
294
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
295
+can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock
296
+Is another process using the image?
297
+
298
+_qemu_img_wrapper info TEST_DIR/t.qcow2
299
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
300
+Is another process using the image?
301
+
302
+_qemu_img_wrapper check TEST_DIR/t.qcow2
303
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
304
+Is another process using the image?
305
+
306
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
307
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
308
+Is another process using the image?
309
+
310
+_qemu_img_wrapper map TEST_DIR/t.qcow2
311
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
312
+Is another process using the image?
313
+
314
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
315
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
316
+Is another process using the image?
317
+
318
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
319
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
320
+Is another process using the image?
321
+
322
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
323
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
324
+Is another process using the image?
325
+
326
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
327
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
328
+Is another process using the image?
329
+
330
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
331
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
332
+Is another process using the image?
333
+
334
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
335
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
336
+Is another process using the image?
337
+
338
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
339
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
340
+Is another process using the image?
341
+
342
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
343
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" lock
344
+Is another process using the image?
345
+
346
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
347
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
348
+Is another process using the image?
349
+
350
+== Running utility commands -U ==
351
+
352
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
353
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
354
+
355
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
356
+
357
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
358
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
359
+
360
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
361
+
362
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
363
+
364
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
365
+
366
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
367
+
368
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
369
+
370
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
371
+qemu-img: unrecognized option '-U'
372
+Try 'qemu-img --help' for more information
373
+
374
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
375
+qemu-img: unrecognized option '-U'
376
+Try 'qemu-img --help' for more information
377
+
378
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
379
+qemu-img: unrecognized option '-U'
380
+Try 'qemu-img --help' for more information
381
+
382
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
383
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
384
+Is another process using the image?
385
+
386
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
387
+
388
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
389
+
390
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
391
+
392
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
393
+
394
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
395
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
396
+
397
+Round done
398
+
399
+== Creating base image ==
400
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
401
+
402
+== Creating test image ==
403
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
404
+
405
+== Launching QEMU, opts: 'read-only=on' ==
406
+
407
+== Launching another QEMU, opts: '' ==
408
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,: Failed to get "write" lock
409
+Is another process using the image?
410
+
411
+== Launching another QEMU, opts: 'read-only=on' ==
412
+
413
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
414
+
415
+== Running utility commands ==
416
+
417
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
418
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
419
+Is another process using the image?
420
+
421
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
422
+
423
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
424
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
425
+Is another process using the image?
426
+
427
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
428
+
429
+_qemu_img_wrapper info TEST_DIR/t.qcow2
430
+
431
+_qemu_img_wrapper check TEST_DIR/t.qcow2
432
+
433
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
434
+
435
+_qemu_img_wrapper map TEST_DIR/t.qcow2
436
+
437
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
438
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
439
+Is another process using the image?
440
+
441
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
442
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
443
+Is another process using the image?
444
+
445
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
446
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
447
+Is another process using the image?
448
+
449
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
450
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
451
+Is another process using the image?
452
+
453
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
454
+
455
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
456
+
457
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
458
+
459
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
460
+
461
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
462
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
463
+Is another process using the image?
464
+
465
+== Running utility commands -U ==
466
+
467
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
468
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
469
+
470
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
471
+
472
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
473
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
474
+
475
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
476
+
477
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
478
+
479
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
480
+
481
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
482
+
483
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
484
+
485
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
486
+qemu-img: unrecognized option '-U'
487
+Try 'qemu-img --help' for more information
488
+
489
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
490
+qemu-img: unrecognized option '-U'
491
+Try 'qemu-img --help' for more information
492
+
493
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
494
+qemu-img: unrecognized option '-U'
495
+Try 'qemu-img --help' for more information
496
+
497
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
498
+qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
499
+Is another process using the image?
500
+
501
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
502
+
503
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
504
+
505
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
506
+
507
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
508
+
509
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
510
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
511
+
512
+Round done
513
+
514
+== Creating base image ==
515
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=33554432
516
+
517
+== Creating test image ==
518
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.base
519
+
520
+== Launching QEMU, opts: 'read-only=on,force-share=on' ==
521
+
522
+== Launching another QEMU, opts: '' ==
523
+
524
+== Launching another QEMU, opts: 'read-only=on' ==
525
+
526
+== Launching another QEMU, opts: 'read-only=on,force-share=on' ==
527
+
528
+== Running utility commands ==
529
+
530
+_qemu_io_wrapper -c read 0 512 TEST_DIR/t.qcow2
531
+
532
+_qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2
533
+
534
+_qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512
535
+
536
+_qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512
537
+
538
+_qemu_img_wrapper info TEST_DIR/t.qcow2
539
+
540
+_qemu_img_wrapper check TEST_DIR/t.qcow2
541
+
542
+_qemu_img_wrapper compare TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
543
+
544
+_qemu_img_wrapper map TEST_DIR/t.qcow2
545
+
546
+_qemu_img_wrapper amend -o TEST_DIR/t.qcow2
547
+
548
+_qemu_img_wrapper commit TEST_DIR/t.qcow2
549
+
550
+_qemu_img_wrapper resize TEST_DIR/t.qcow2 32M
551
+
552
+_qemu_img_wrapper rebase TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
553
+
554
+_qemu_img_wrapper snapshot -l TEST_DIR/t.qcow2
555
+
556
+_qemu_img_wrapper convert TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
557
+
558
+_qemu_img_wrapper dd if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
559
+
560
+_qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
561
+
562
+_qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
563
+
564
+== Running utility commands -U ==
565
+
566
+_qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
567
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
568
+
569
+_qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2
570
+
571
+_qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512
572
+can't open device TEST_DIR/t.qcow2: force-share=on can only be used with read-only images
573
+
574
+_qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512
575
+
576
+_qemu_img_wrapper info -U TEST_DIR/t.qcow2
577
+
578
+_qemu_img_wrapper check -U TEST_DIR/t.qcow2
579
+
580
+_qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2
581
+
582
+_qemu_img_wrapper map -U TEST_DIR/t.qcow2
583
+
584
+_qemu_img_wrapper amend -o -U TEST_DIR/t.qcow2
585
+qemu-img: unrecognized option '-U'
586
+Try 'qemu-img --help' for more information
587
+
588
+_qemu_img_wrapper commit -U TEST_DIR/t.qcow2
589
+qemu-img: unrecognized option '-U'
590
+Try 'qemu-img --help' for more information
591
+
592
+_qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M
593
+qemu-img: unrecognized option '-U'
594
+Try 'qemu-img --help' for more information
595
+
596
+_qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
597
+
598
+_qemu_img_wrapper snapshot -l -U TEST_DIR/t.qcow2
599
+
600
+_qemu_img_wrapper convert -U TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.convert
601
+
602
+_qemu_img_wrapper dd -U if=TEST_DIR/t.qcow2 of=TEST_DIR/t.qcow2.convert bs=512 count=1
603
+
604
+_qemu_img_wrapper bench -U -c 1 TEST_DIR/t.qcow2
605
+
606
+_qemu_img_wrapper bench -U -w -c 1 TEST_DIR/t.qcow2
607
+qemu-img: Could not open 'TEST_DIR/t.qcow2': force-share=on can only be used with read-only images
608
+
609
+Round done
610
+== Creating TEST_DIR/t.qcow2.[abc] ==
611
+Formatting 'TEST_DIR/t.IMGFMT.a', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT
612
+Formatting 'TEST_DIR/t.IMGFMT.b', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT
613
+Formatting 'TEST_DIR/t.IMGFMT.c', fmt=IMGFMT size=33554432 backing_file=TEST_DIR/t.IMGFMT.b
614
+
615
+== Two devices sharing the same file in backing chain ==
616
+
617
+== Backing image also as an active device ==
618
+QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
619
+Is another process using the image?
620
+
621
+== Backing image also as an active device (ro) ==
622
+
623
+== Symbolic link ==
624
+QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock
625
+Is another process using the image?
626
+
627
+== Closing an image should unlock it ==
628
+{"return": {}}
629
+Adding drive
630
+
631
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
632
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
633
+Is another process using the image?
634
+Closing drive
635
+
636
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
637
+Adding two and closing one
638
+
639
+_qemu_img_wrapper info TEST_DIR/t.qcow2
640
+
641
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
642
+can't open device TEST_DIR/t.qcow2: Failed to get "write" lock
643
+Is another process using the image?
644
+Closing the other
645
+
646
+_qemu_io_wrapper TEST_DIR/t.qcow2 -c write 0 512
647
+*** done
648
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
649
index XXXXXXX..XXXXXXX 100644
650
--- a/tests/qemu-iotests/group
651
+++ b/tests/qemu-iotests/group
652
@@ -XXX,XX +XXX,XX @@
653
149 rw auto sudo
654
150 rw auto quick
655
152 rw auto quick
656
+153 rw auto quick
657
154 rw auto backing quick
658
155 rw auto
659
156 rw auto quick
660
--
157
--
661
1.8.3.1
158
2.38.1
662
663
diff view generated by jsdifflib
Deleted patch
1
From: Fam Zheng <famz@redhat.com>
2
1
3
Signed-off-by: Fam Zheng <famz@redhat.com>
4
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5
---
6
tests/qemu-iotests/182 | 68 ++++++++++++++++++++++++++++++++++++++++++++++
7
tests/qemu-iotests/182.out | 8 ++++++
8
tests/qemu-iotests/group | 1 +
9
3 files changed, 77 insertions(+)
10
create mode 100755 tests/qemu-iotests/182
11
create mode 100644 tests/qemu-iotests/182.out
12
13
diff --git a/tests/qemu-iotests/182 b/tests/qemu-iotests/182
14
new file mode 100755
15
index XXXXXXX..XXXXXXX
16
--- /dev/null
17
+++ b/tests/qemu-iotests/182
18
@@ -XXX,XX +XXX,XX @@
19
+#!/bin/bash
20
+#
21
+# Test image locking for POSIX locks
22
+#
23
+# Copyright 2017 Red Hat, Inc.
24
+#
25
+# This program is free software; you can redistribute it and/or modify
26
+# it under the terms of the GNU General Public License as published by
27
+# the Free Software Foundation; either version 2 of the License, or
28
+# (at your option) any later version.
29
+#
30
+# This program is distributed in the hope that it will be useful,
31
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
+# GNU General Public License for more details.
34
+#
35
+# You should have received a copy of the GNU General Public License
36
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+#
38
+
39
+# creator
40
+owner=famz@redhat.com
41
+
42
+seq="$(basename $0)"
43
+echo "QA output created by $seq"
44
+
45
+here="$PWD"
46
+tmp=/tmp/$$
47
+status=1    # failure is the default!
48
+
49
+_cleanup()
50
+{
51
+ _cleanup_test_img
52
+}
53
+trap "_cleanup; exit \$status" 0 1 2 3 15
54
+
55
+# get standard environment, filters and checks
56
+. ./common.rc
57
+. ./common.filter
58
+. ./common.qemu
59
+
60
+_supported_fmt qcow2
61
+_supported_proto file
62
+_supported_os Linux
63
+
64
+size=32M
65
+
66
+_make_test_img $size
67
+
68
+echo "Starting QEMU"
69
+_launch_qemu -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
70
+ -device virtio-blk-pci,drive=drive0
71
+
72
+echo
73
+echo "Starting a second QEMU using the same image should fail"
74
+echo 'quit' | $QEMU -monitor stdio \
75
+ -drive file=$TEST_IMG,if=none,id=drive0,file.locking=on \
76
+ -device virtio-blk-pci,drive=drive0 2>&1 | _filter_testdir 2>&1 |
77
+ _filter_qemu |
78
+ sed -e '/falling back to POSIX file/d' \
79
+ -e '/locks can be lost unexpectedly/d'
80
+
81
+_cleanup_qemu
82
+
83
+# success, all done
84
+echo "*** done"
85
+rm -f $seq.full
86
+status=0
87
diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out
88
new file mode 100644
89
index XXXXXXX..XXXXXXX
90
--- /dev/null
91
+++ b/tests/qemu-iotests/182.out
92
@@ -XXX,XX +XXX,XX @@
93
+QA output created by 182
94
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=33554432
95
+Starting QEMU
96
+
97
+Starting a second QEMU using the same image should fail
98
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock
99
+Is another process using the image?
100
+*** done
101
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
102
index XXXXXXX..XXXXXXX 100644
103
--- a/tests/qemu-iotests/group
104
+++ b/tests/qemu-iotests/group
105
@@ -XXX,XX +XXX,XX @@
106
175 auto quick
107
176 rw auto backing
108
181 rw auto migration
109
+182 rw auto quick
110
--
111
1.8.3.1
112
113
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
When calculating the number of reftable entries, we should actually use
4
the number of refblocks and not (wrongly[1]) re-calculate it.
5
6
[1] "Wrongly" means: Dividing the number of clusters by the number of
7
entries per refblock and rounding down instead of up.
8
9
Reported-by: Eric Blake <eblake@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
Reviewed-by: Eric Blake <eblake@redhat.com>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
14
block/qcow2.c | 9 +++++----
15
1 file changed, 5 insertions(+), 4 deletions(-)
16
17
diff --git a/block/qcow2.c b/block/qcow2.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/qcow2.c
20
+++ b/block/qcow2.c
21
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
22
* too, as long as the bulk is allocated here). Therefore, using
23
* floating point arithmetic is fine. */
24
int64_t meta_size = 0;
25
- uint64_t nreftablee, nrefblocke, nl1e, nl2e;
26
+ uint64_t nreftablee, nrefblocke, nl1e, nl2e, refblock_count;
27
int64_t aligned_total_size = align_offset(total_size, cluster_size);
28
int refblock_bits, refblock_size;
29
/* refcount entry size in bytes */
30
@@ -XXX,XX +XXX,XX @@ static int qcow2_create2(const char *filename, int64_t total_size,
31
nrefblocke = (aligned_total_size + meta_size + cluster_size)
32
/ (cluster_size - rces - rces * sizeof(uint64_t)
33
/ cluster_size);
34
- meta_size += DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size;
35
+ refblock_count = DIV_ROUND_UP(nrefblocke, refblock_size);
36
+ meta_size += refblock_count * cluster_size;
37
38
/* total size of refcount tables */
39
- nreftablee = nrefblocke / refblock_size;
40
- nreftablee = align_offset(nreftablee, cluster_size / sizeof(uint64_t));
41
+ nreftablee = align_offset(refblock_count,
42
+ cluster_size / sizeof(uint64_t));
43
meta_size += nreftablee * sizeof(uint64_t);
44
45
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
46
--
47
1.8.3.1
48
49
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
In discard_single_l2(), we completely discard normal clusters instead of
4
simply turning them into preallocated zero clusters. That means we
5
should probably do the same with such preallocated zero clusters:
6
Discard them instead of keeping them allocated.
7
8
Reported-by: Eric Blake <eblake@redhat.com>
9
Signed-off-by: Max Reitz <mreitz@redhat.com>
10
Reviewed-by: Eric Blake <eblake@redhat.com>
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
---
13
block/qcow2-cluster.c | 3 ++-
14
1 file changed, 2 insertions(+), 1 deletion(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
break;
22
23
case QCOW2_CLUSTER_ZERO:
24
- if (!full_discard) {
25
+ /* Preallocated zero clusters should be discarded in any case */
26
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
27
continue;
28
}
29
break;
30
--
31
1.8.3.1
32
33
diff view generated by jsdifflib
Deleted patch
1
Migration code activates all block driver nodes on the destination when
2
the migration completes. It does so by calling
3
bdrv_invalidate_cache_all() and blk_resume_after_migration(). There is
4
one code path for precopy and one for postcopy migration, resulting in
5
four function calls, which used to have three different failure modes.
6
1
7
This patch unifies the behaviour so that failure to activate all block
8
nodes is non-fatal, but the error message is logged and the VM isn't
9
automatically started. 'cont' will retry activating the block nodes.
10
11
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
12
Reviewed-by: Eric Blake <eblake@redhat.com>
13
---
14
migration/migration.c | 16 +++++-----------
15
migration/savevm.c | 12 +++++-------
16
qmp.c | 18 +++++++++---------
17
3 files changed, 19 insertions(+), 27 deletions(-)
18
19
diff --git a/migration/migration.c b/migration/migration.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/migration/migration.c
22
+++ b/migration/migration.c
23
@@ -XXX,XX +XXX,XX @@ static void process_incoming_migration_bh(void *opaque)
24
Error *local_err = NULL;
25
MigrationIncomingState *mis = opaque;
26
27
- /* Make sure all file formats flush their mutable metadata */
28
+ /* Make sure all file formats flush their mutable metadata.
29
+ * If we get an error here, just don't restart the VM yet. */
30
bdrv_invalidate_cache_all(&local_err);
31
- if (local_err) {
32
- migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE,
33
- MIGRATION_STATUS_FAILED);
34
- error_report_err(local_err);
35
- migrate_decompress_threads_join();
36
- exit(EXIT_FAILURE);
37
+ if (!local_err) {
38
+ blk_resume_after_migration(&local_err);
39
}
40
-
41
- /* If we get an error here, just don't restart the VM yet. */
42
- blk_resume_after_migration(&local_err);
43
if (local_err) {
44
- error_free(local_err);
45
+ error_report_err(local_err);
46
local_err = NULL;
47
autostart = false;
48
}
49
diff --git a/migration/savevm.c b/migration/savevm.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/migration/savevm.c
52
+++ b/migration/savevm.c
53
@@ -XXX,XX +XXX,XX @@ static void loadvm_postcopy_handle_run_bh(void *opaque)
54
55
qemu_announce_self();
56
57
- /* Make sure all file formats flush their mutable metadata */
58
+ /* Make sure all file formats flush their mutable metadata.
59
+ * If we get an error here, just don't restart the VM yet. */
60
bdrv_invalidate_cache_all(&local_err);
61
- if (local_err) {
62
- error_report_err(local_err);
63
+ if (!local_err) {
64
+ blk_resume_after_migration(&local_err);
65
}
66
-
67
- /* If we get an error here, just don't restart the VM yet. */
68
- blk_resume_after_migration(&local_err);
69
if (local_err) {
70
- error_free(local_err);
71
+ error_report_err(local_err);
72
local_err = NULL;
73
autostart = false;
74
}
75
diff --git a/qmp.c b/qmp.c
76
index XXXXXXX..XXXXXXX 100644
77
--- a/qmp.c
78
+++ b/qmp.c
79
@@ -XXX,XX +XXX,XX @@ void qmp_cont(Error **errp)
80
}
81
82
/* Continuing after completed migration. Images have been inactivated to
83
- * allow the destination to take control. Need to get control back now. */
84
- if (runstate_check(RUN_STATE_FINISH_MIGRATE) ||
85
- runstate_check(RUN_STATE_POSTMIGRATE))
86
- {
87
- bdrv_invalidate_cache_all(&local_err);
88
- if (local_err) {
89
- error_propagate(errp, local_err);
90
- return;
91
- }
92
+ * allow the destination to take control. Need to get control back now.
93
+ *
94
+ * If there are no inactive block nodes (e.g. because the VM was just
95
+ * paused rather than completing a migration), bdrv_inactivate_all() simply
96
+ * doesn't do anything. */
97
+ bdrv_invalidate_cache_all(&local_err);
98
+ if (local_err) {
99
+ error_propagate(errp, local_err);
100
+ return;
101
}
102
103
blk_resume_after_migration(&local_err);
104
--
105
1.8.3.1
106
107
diff view generated by jsdifflib
Deleted patch
1
The proper order for inactivating block nodes is that first the parents
2
get inactivated and then the children. If we do things in this order, we
3
can assert that we didn't accidentally leave a parent activated when one
4
of its child nodes is inactive.
5
1
6
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7
Reviewed-by: Eric Blake <eblake@redhat.com>
8
---
9
block.c | 25 ++++++++++++++++++-------
10
1 file changed, 18 insertions(+), 7 deletions(-)
11
12
diff --git a/block.c b/block.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/block.c
15
+++ b/block.c
16
@@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child)
17
bdrv_drained_end(bs);
18
}
19
20
+static int bdrv_child_cb_inactivate(BdrvChild *child)
21
+{
22
+ BlockDriverState *bs = child->opaque;
23
+ assert(bs->open_flags & BDRV_O_INACTIVE);
24
+ return 0;
25
+}
26
+
27
/*
28
* Returns the options and flags that a temporary snapshot should get, based on
29
* the originally requested flags (the originally requested image will have
30
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = {
31
.inherit_options = bdrv_inherited_options,
32
.drained_begin = bdrv_child_cb_drained_begin,
33
.drained_end = bdrv_child_cb_drained_end,
34
+ .inactivate = bdrv_child_cb_inactivate,
35
};
36
37
/*
38
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = {
39
.inherit_options = bdrv_inherited_fmt_options,
40
.drained_begin = bdrv_child_cb_drained_begin,
41
.drained_end = bdrv_child_cb_drained_end,
42
+ .inactivate = bdrv_child_cb_inactivate,
43
};
44
45
static void bdrv_backing_attach(BdrvChild *c)
46
@@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_backing = {
47
.inherit_options = bdrv_backing_options,
48
.drained_begin = bdrv_child_cb_drained_begin,
49
.drained_end = bdrv_child_cb_drained_end,
50
+ .inactivate = bdrv_child_cb_inactivate,
51
};
52
53
static int bdrv_open_flags(BlockDriverState *bs, int flags)
54
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
55
}
56
}
57
58
- QLIST_FOREACH(child, &bs->children, next) {
59
- ret = bdrv_inactivate_recurse(child->bs, setting_flag);
60
- if (ret < 0) {
61
- return ret;
62
- }
63
- }
64
-
65
if (setting_flag) {
66
bs->open_flags |= BDRV_O_INACTIVE;
67
68
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
69
}
70
}
71
}
72
+
73
+ QLIST_FOREACH(child, &bs->children, next) {
74
+ ret = bdrv_inactivate_recurse(child->bs, setting_flag);
75
+ if (ret < 0) {
76
+ return ret;
77
+ }
78
+ }
79
+
80
return 0;
81
}
82
83
--
84
1.8.3.1
85
86
diff view generated by jsdifflib
Deleted patch
1
Format drivers for inactive nodes don't need write/resize permissions on
2
their bs->file and can share write/resize with another VM (in fact, this
3
is the whole point of keeping images inactive). Represent this fact in
4
the op blocker system, so that image locking does the right thing
5
without special-casing inactive images.
6
1
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
Reviewed-by: Eric Blake <eblake@redhat.com>
9
---
10
block.c | 35 +++++++++++++++++++++++++++++++++--
11
include/block/block.h | 1 +
12
2 files changed, 34 insertions(+), 2 deletions(-)
13
14
diff --git a/block.c b/block.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/block.c
17
+++ b/block.c
18
@@ -XXX,XX +XXX,XX @@ void path_combine(char *dest, int dest_size,
19
}
20
}
21
22
+/* Returns whether the image file is opened as read-only. Note that this can
23
+ * return false and writing to the image file is still not possible because the
24
+ * image is inactivated. */
25
bool bdrv_is_read_only(BlockDriverState *bs)
26
{
27
return bs->read_only;
28
}
29
30
+/* Returns whether the image file can be written to right now */
31
+bool bdrv_is_writable(BlockDriverState *bs)
32
+{
33
+ return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE);
34
+}
35
+
36
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
37
{
38
/* Do not set read_only if copy_on_read is enabled */
39
@@ -XXX,XX +XXX,XX @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t cumulative_perms,
40
41
/* Write permissions never work with read-only images */
42
if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) &&
43
- bdrv_is_read_only(bs))
44
+ !bdrv_is_writable(bs))
45
{
46
error_setg(errp, "Block node is read-only");
47
return -EPERM;
48
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
49
bdrv_filter_default_perms(bs, c, role, perm, shared, &perm, &shared);
50
51
/* Format drivers may touch metadata even if the guest doesn't write */
52
- if (!bdrv_is_read_only(bs)) {
53
+ if (bdrv_is_writable(bs)) {
54
perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
55
}
56
57
@@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
58
BLK_PERM_WRITE_UNCHANGED;
59
}
60
61
+ if (bs->open_flags & BDRV_O_INACTIVE) {
62
+ shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
63
+ }
64
+
65
*nperm = perm;
66
*nshared = shared;
67
}
68
@@ -XXX,XX +XXX,XX @@ void bdrv_init_with_whitelist(void)
69
void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
70
{
71
BdrvChild *child, *parent;
72
+ uint64_t perm, shared_perm;
73
Error *local_err = NULL;
74
int ret;
75
76
@@ -XXX,XX +XXX,XX @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
77
return;
78
}
79
80
+ /* Update permissions, they may differ for inactive nodes */
81
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
82
+ ret = bdrv_check_perm(bs, perm, shared_perm, NULL, &local_err);
83
+ if (ret < 0) {
84
+ bs->open_flags |= BDRV_O_INACTIVE;
85
+ error_propagate(errp, local_err);
86
+ return;
87
+ }
88
+ bdrv_set_perm(bs, perm, shared_perm);
89
+
90
QLIST_FOREACH(parent, &bs->parents, next_parent) {
91
if (parent->role->activate) {
92
parent->role->activate(parent, &local_err);
93
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
94
}
95
96
if (setting_flag) {
97
+ uint64_t perm, shared_perm;
98
+
99
bs->open_flags |= BDRV_O_INACTIVE;
100
101
QLIST_FOREACH(parent, &bs->parents, next_parent) {
102
@@ -XXX,XX +XXX,XX @@ static int bdrv_inactivate_recurse(BlockDriverState *bs,
103
}
104
}
105
}
106
+
107
+ /* Update permissions, they may differ for inactive nodes */
108
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
109
+ bdrv_check_perm(bs, perm, shared_perm, NULL, &error_abort);
110
+ bdrv_set_perm(bs, perm, shared_perm);
111
}
112
113
QLIST_FOREACH(child, &bs->children, next) {
114
diff --git a/include/block/block.h b/include/block/block.h
115
index XXXXXXX..XXXXXXX 100644
116
--- a/include/block/block.h
117
+++ b/include/block/block.h
118
@@ -XXX,XX +XXX,XX @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
119
int64_t sector_num, int nb_sectors, int *pnum);
120
121
bool bdrv_is_read_only(BlockDriverState *bs);
122
+bool bdrv_is_writable(BlockDriverState *bs);
123
int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
124
int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp);
125
bool bdrv_is_sg(BlockDriverState *bs);
126
--
127
1.8.3.1
128
129
diff view generated by jsdifflib
Deleted patch
1
Now that the block layer takes care to request a lot less permissions
2
for inactive nodes, the special-casing in file-posix isn't necessary any
3
more.
4
1
5
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
6
Reviewed-by: Eric Blake <eblake@redhat.com>
7
---
8
block/file-posix.c | 33 ---------------------------------
9
1 file changed, 33 deletions(-)
10
11
diff --git a/block/file-posix.c b/block/file-posix.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/block/file-posix.c
14
+++ b/block/file-posix.c
15
@@ -XXX,XX +XXX,XX @@ static void raw_abort_perm_update(BlockDriverState *bs)
16
raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL);
17
}
18
19
-static int raw_inactivate(BlockDriverState *bs)
20
-{
21
- int ret;
22
- uint64_t perm = 0;
23
- uint64_t shared = BLK_PERM_ALL;
24
-
25
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, perm, shared, NULL);
26
- if (ret) {
27
- return ret;
28
- }
29
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, perm, shared, NULL);
30
- return 0;
31
-}
32
-
33
-
34
-static void raw_invalidate_cache(BlockDriverState *bs, Error **errp)
35
-{
36
- BDRVRawState *s = bs->opaque;
37
- int ret;
38
-
39
- assert(!(bdrv_get_flags(bs) & BDRV_O_INACTIVE));
40
- ret = raw_handle_perm_lock(bs, RAW_PL_PREPARE, s->perm, s->shared_perm,
41
- errp);
42
- if (ret) {
43
- return;
44
- }
45
- raw_handle_perm_lock(bs, RAW_PL_COMMIT, s->perm, s->shared_perm, NULL);
46
-}
47
-
48
BlockDriver bdrv_file = {
49
.format_name = "file",
50
.protocol_name = "file",
51
@@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = {
52
.bdrv_get_info = raw_get_info,
53
.bdrv_get_allocated_file_size
54
= raw_get_allocated_file_size,
55
- .bdrv_inactivate = raw_inactivate,
56
- .bdrv_invalidate_cache = raw_invalidate_cache,
57
.bdrv_check_perm = raw_check_perm,
58
.bdrv_set_perm = raw_set_perm,
59
.bdrv_abort_perm_update = raw_abort_perm_update,
60
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_host_device = {
61
.bdrv_get_info = raw_get_info,
62
.bdrv_get_allocated_file_size
63
= raw_get_allocated_file_size,
64
- .bdrv_inactivate = raw_inactivate,
65
- .bdrv_invalidate_cache = raw_invalidate_cache,
66
.bdrv_check_perm = raw_check_perm,
67
.bdrv_set_perm = raw_set_perm,
68
.bdrv_abort_perm_update = raw_abort_perm_update,
69
--
70
1.8.3.1
71
72
diff view generated by jsdifflib
Deleted patch
1
From: Anton Nefedov <anton.nefedov@virtuozzo.com>
2
1
3
On error path (like i/o error in one of the coroutines), it's required to
4
- wait for coroutines completion before cleaning the common structures
5
- reenter dependent coroutines so they ever finish
6
7
Introduced in 2d9187bc65.
8
9
Cc: qemu-stable@nongnu.org
10
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
11
Reviewed-by: Peter Lieven <pl@kamp.de>
12
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
13
---
14
qemu-img.c | 26 +++++++++++---------------
15
1 file changed, 11 insertions(+), 15 deletions(-)
16
17
diff --git a/qemu-img.c b/qemu-img.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-img.c
20
+++ b/qemu-img.c
21
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
22
qemu_co_mutex_lock(&s->lock);
23
if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) {
24
qemu_co_mutex_unlock(&s->lock);
25
- goto out;
26
+ break;
27
}
28
n = convert_iteration_sectors(s, s->sector_num);
29
if (n < 0) {
30
qemu_co_mutex_unlock(&s->lock);
31
s->ret = n;
32
- goto out;
33
+ break;
34
}
35
/* save current sector and allocation status to local variables */
36
sector_num = s->sector_num;
37
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
38
error_report("error while reading sector %" PRId64
39
": %s", sector_num, strerror(-ret));
40
s->ret = ret;
41
- goto out;
42
}
43
} else if (!s->min_sparse && status == BLK_ZERO) {
44
status = BLK_DATA;
45
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
46
47
if (s->wr_in_order) {
48
/* keep writes in order */
49
- while (s->wr_offs != sector_num) {
50
- if (s->ret != -EINPROGRESS) {
51
- goto out;
52
- }
53
+ while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) {
54
s->wait_sector_num[index] = sector_num;
55
qemu_coroutine_yield();
56
}
57
s->wait_sector_num[index] = -1;
58
}
59
60
- ret = convert_co_write(s, sector_num, n, buf, status);
61
- if (ret < 0) {
62
- error_report("error while writing sector %" PRId64
63
- ": %s", sector_num, strerror(-ret));
64
- s->ret = ret;
65
- goto out;
66
+ if (s->ret == -EINPROGRESS) {
67
+ ret = convert_co_write(s, sector_num, n, buf, status);
68
+ if (ret < 0) {
69
+ error_report("error while writing sector %" PRId64
70
+ ": %s", sector_num, strerror(-ret));
71
+ s->ret = ret;
72
+ }
73
}
74
75
if (s->wr_in_order) {
76
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn convert_co_do_copy(void *opaque)
77
}
78
}
79
80
-out:
81
qemu_vfree(buf);
82
s->co[index] = NULL;
83
s->running_coroutines--;
84
@@ -XXX,XX +XXX,XX @@ static int convert_do_copy(ImgConvertState *s)
85
qemu_coroutine_enter(s->co[i]);
86
}
87
88
- while (s->ret == -EINPROGRESS) {
89
+ while (s->running_coroutines) {
90
main_loop_wait(false);
91
}
92
93
--
94
1.8.3.1
95
96
diff view generated by jsdifflib
Deleted patch
1
From: Christoph Hellwig <hch@lst.de>
2
1
3
Signed-off-by: Keith Busch <keith.busch@intel.com>
4
[hch: ported over from qemu-nvme.git to mainline]
5
Signed-off-by: Christoph Hellwig <hch@lst.de>
6
Acked-by: Keith Busch <keith.busch@intel.com>
7
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
8
---
9
hw/block/nvme.c | 26 ++++++++++++++++++++++++++
10
hw/block/nvme.h | 1 +
11
2 files changed, 27 insertions(+)
12
13
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/block/nvme.c
16
+++ b/hw/block/nvme.c
17
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_flush(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
18
return NVME_NO_COMPLETE;
19
}
20
21
+static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
22
+ NvmeRequest *req)
23
+{
24
+ NvmeRwCmd *rw = (NvmeRwCmd *)cmd;
25
+ const uint8_t lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
26
+ const uint8_t data_shift = ns->id_ns.lbaf[lba_index].ds;
27
+ uint64_t slba = le64_to_cpu(rw->slba);
28
+ uint32_t nlb = le16_to_cpu(rw->nlb) + 1;
29
+ uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS);
30
+ uint32_t aio_nlb = nlb << (data_shift - BDRV_SECTOR_BITS);
31
+
32
+ if (slba + nlb > ns->id_ns.nsze) {
33
+ return NVME_LBA_RANGE | NVME_DNR;
34
+ }
35
+
36
+ req->has_sg = false;
37
+ block_acct_start(blk_get_stats(n->conf.blk), &req->acct, 0,
38
+ BLOCK_ACCT_WRITE);
39
+ req->aiocb = blk_aio_pwrite_zeroes(n->conf.blk, aio_slba, aio_nlb,
40
+ BDRV_REQ_MAY_UNMAP, nvme_rw_cb, req);
41
+ return NVME_NO_COMPLETE;
42
+}
43
+
44
static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd,
45
NvmeRequest *req)
46
{
47
@@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req)
48
switch (cmd->opcode) {
49
case NVME_CMD_FLUSH:
50
return nvme_flush(n, ns, cmd, req);
51
+ case NVME_CMD_WRITE_ZEROS:
52
+ return nvme_write_zeros(n, ns, cmd, req);
53
case NVME_CMD_WRITE:
54
case NVME_CMD_READ:
55
return nvme_rw(n, ns, cmd, req);
56
@@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev)
57
id->sqes = (0x6 << 4) | 0x6;
58
id->cqes = (0x4 << 4) | 0x4;
59
id->nn = cpu_to_le32(n->num_namespaces);
60
+ id->oncs = cpu_to_le16(NVME_ONCS_WRITE_ZEROS);
61
id->psd[0].mp = cpu_to_le16(0x9c4);
62
id->psd[0].enlat = cpu_to_le32(0x10);
63
id->psd[0].exlat = cpu_to_le32(0x4);
64
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
65
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/block/nvme.h
67
+++ b/hw/block/nvme.h
68
@@ -XXX,XX +XXX,XX @@ enum NvmeIoCommands {
69
NVME_CMD_READ = 0x02,
70
NVME_CMD_WRITE_UNCOR = 0x04,
71
NVME_CMD_COMPARE = 0x05,
72
+ NVME_CMD_WRITE_ZEROS = 0x08,
73
NVME_CMD_DSM = 0x09,
74
};
75
76
--
77
1.8.3.1
78
79
diff view generated by jsdifflib
Deleted patch
1
From: John Snow <jsnow@redhat.com>
2
1
3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1447551
4
5
If one tries to issue a block_resize while a guest is busy
6
accessing the disk, it is possible that qemu may deadlock
7
when invoking aio_poll from both the main loop and the iothread.
8
9
Replace another instance of bdrv_drain_all that doesn't
10
quite belong.
11
12
Cc: qemu-stable@nongnu.org
13
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
14
Signed-off-by: John Snow <jsnow@redhat.com>
15
Reviewed-by: Eric Blake <eblake@redhat.com>
16
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
17
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
18
---
19
blockdev.c | 5 ++---
20
1 file changed, 2 insertions(+), 3 deletions(-)
21
22
diff --git a/blockdev.c b/blockdev.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/blockdev.c
25
+++ b/blockdev.c
26
@@ -XXX,XX +XXX,XX @@ void qmp_block_resize(bool has_device, const char *device,
27
goto out;
28
}
29
30
- /* complete all in-flight operations before resizing the device */
31
- bdrv_drain_all();
32
-
33
+ bdrv_drained_begin(bs);
34
ret = blk_truncate(blk, size, errp);
35
+ bdrv_drained_end(bs);
36
37
out:
38
blk_unref(blk);
39
--
40
1.8.3.1
41
42
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Several copy-and-pasted alignment checks exist in qemu-io, which
4
could use some minor improvements:
5
6
- Manual comparison against 0x1ff is not as clean as using our
7
alignment macros (QEMU_IS_ALIGNED) from osdep.h.
8
9
- The error messages aren't quite grammatically correct.
10
11
Suggested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Suggested-by: Max Reitz <mreitz@redhat.com>
13
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Message-id: 20170429191419.30051-2-eblake@redhat.com
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
qemu-io-cmds.c | 20 ++++++++++----------
20
1 file changed, 10 insertions(+), 10 deletions(-)
21
22
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/qemu-io-cmds.c
25
+++ b/qemu-io-cmds.c
26
@@ -XXX,XX +XXX,XX @@ static int read_f(BlockBackend *blk, int argc, char **argv)
27
}
28
29
if (bflag) {
30
- if (offset & 0x1ff) {
31
- printf("offset %" PRId64 " is not sector aligned\n",
32
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
33
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
34
offset);
35
return 0;
36
}
37
- if (count & 0x1ff) {
38
- printf("count %"PRId64" is not sector aligned\n",
39
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
40
+ printf("%"PRId64" is not a sector-aligned value for 'count'\n",
41
count);
42
return 0;
43
}
44
@@ -XXX,XX +XXX,XX @@ static int write_f(BlockBackend *blk, int argc, char **argv)
45
}
46
47
if (bflag || cflag) {
48
- if (offset & 0x1ff) {
49
- printf("offset %" PRId64 " is not sector aligned\n",
50
+ if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
51
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
52
offset);
53
return 0;
54
}
55
56
- if (count & 0x1ff) {
57
- printf("count %"PRId64" is not sector aligned\n",
58
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
59
+ printf("%"PRId64" is not a sector-aligned value for 'count'\n",
60
count);
61
return 0;
62
}
63
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
64
if (offset < 0) {
65
print_cvtnum_err(offset, argv[1]);
66
return 0;
67
- } else if (offset & 0x1ff) {
68
- printf("offset %" PRId64 " is not sector aligned\n",
69
+ } else if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
70
+ printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
71
offset);
72
return 0;
73
}
74
--
75
1.8.3.1
76
77
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
For the 'alloc' command, accepting an offset in bytes but a length
4
in sectors, and reporting output in sectors, is confusing. Do
5
everything in bytes, and adjust the expected output accordingly.
6
7
Signed-off-by: Eric Blake <eblake@redhat.com>
8
Message-id: 20170429191419.30051-3-eblake@redhat.com
9
Reviewed-by: Max Reitz <mreitz@redhat.com>
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
qemu-io-cmds.c | 30 ++++++++++++++++++------------
13
tests/qemu-iotests/019.out | 8 ++++----
14
tests/qemu-iotests/common.pattern | 2 +-
15
3 files changed, 23 insertions(+), 17 deletions(-)
16
17
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/qemu-io-cmds.c
20
+++ b/qemu-io-cmds.c
21
@@ -XXX,XX +XXX,XX @@ out:
22
static int alloc_f(BlockBackend *blk, int argc, char **argv)
23
{
24
BlockDriverState *bs = blk_bs(blk);
25
- int64_t offset, sector_num, nb_sectors, remaining;
26
+ int64_t offset, sector_num, nb_sectors, remaining, count;
27
char s1[64];
28
int num, ret;
29
int64_t sum_alloc;
30
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
31
}
32
33
if (argc == 3) {
34
- nb_sectors = cvtnum(argv[2]);
35
- if (nb_sectors < 0) {
36
- print_cvtnum_err(nb_sectors, argv[2]);
37
+ count = cvtnum(argv[2]);
38
+ if (count < 0) {
39
+ print_cvtnum_err(count, argv[2]);
40
return 0;
41
- } else if (nb_sectors > INT_MAX) {
42
- printf("length argument cannot exceed %d, given %s\n",
43
- INT_MAX, argv[2]);
44
+ } else if (count > INT_MAX * BDRV_SECTOR_SIZE) {
45
+ printf("length argument cannot exceed %llu, given %s\n",
46
+ INT_MAX * BDRV_SECTOR_SIZE, argv[2]);
47
return 0;
48
}
49
} else {
50
- nb_sectors = 1;
51
+ count = BDRV_SECTOR_SIZE;
52
+ }
53
+ if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
54
+ printf("%" PRId64 " is not a sector-aligned value for 'count'\n",
55
+ count);
56
+ return 0;
57
}
58
+ nb_sectors = count >> BDRV_SECTOR_BITS;
59
60
remaining = nb_sectors;
61
sum_alloc = 0;
62
@@ -XXX,XX +XXX,XX @@ static int alloc_f(BlockBackend *blk, int argc, char **argv)
63
64
cvtstr(offset, s1, sizeof(s1));
65
66
- printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n",
67
- sum_alloc, nb_sectors, s1);
68
+ printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n",
69
+ sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, s1);
70
return 0;
71
}
72
73
@@ -XXX,XX +XXX,XX @@ static const cmdinfo_t alloc_cmd = {
74
.argmin = 1,
75
.argmax = 2,
76
.cfunc = alloc_f,
77
- .args = "off [sectors]",
78
- .oneline = "checks if a sector is present in the file",
79
+ .args = "offset [count]",
80
+ .oneline = "checks if offset is allocated in the file",
81
};
82
83
84
diff --git a/tests/qemu-iotests/019.out b/tests/qemu-iotests/019.out
85
index XXXXXXX..XXXXXXX 100644
86
--- a/tests/qemu-iotests/019.out
87
+++ b/tests/qemu-iotests/019.out
88
@@ -XXX,XX +XXX,XX @@ Testing conversion with -B TEST_DIR/t.IMGFMT.base
89
90
Checking if backing clusters are allocated when they shouldn't
91
92
-0/128 sectors allocated at offset 1 MiB
93
-0/128 sectors allocated at offset 4.001 GiB
94
+0/65536 bytes allocated at offset 1 MiB
95
+0/65536 bytes allocated at offset 4.001 GiB
96
Reading
97
98
=== IO: pattern 42
99
@@ -XXX,XX +XXX,XX @@ Testing conversion with -o backing_file=TEST_DIR/t.IMGFMT.base
100
101
Checking if backing clusters are allocated when they shouldn't
102
103
-0/128 sectors allocated at offset 1 MiB
104
-0/128 sectors allocated at offset 4.001 GiB
105
+0/65536 bytes allocated at offset 1 MiB
106
+0/65536 bytes allocated at offset 4.001 GiB
107
Reading
108
109
=== IO: pattern 42
110
diff --git a/tests/qemu-iotests/common.pattern b/tests/qemu-iotests/common.pattern
111
index XXXXXXX..XXXXXXX 100644
112
--- a/tests/qemu-iotests/common.pattern
113
+++ b/tests/qemu-iotests/common.pattern
114
@@ -XXX,XX +XXX,XX @@
115
116
function do_is_allocated() {
117
local start=$1
118
- local size=$(( $2 / 512))
119
+ local size=$2
120
local step=$3
121
local count=$4
122
123
--
124
1.8.3.1
125
126
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Mixing byte offset and sector allocation counts is a bit
4
confusing. Also, reporting n/m sectors, where m decreases
5
according to the remaining size of the file, isn't really
6
adding any useful information; and reporting an offset at
7
both the front and end of the line, with large amounts of
8
whitespace, is pointless. Update the output to use byte
9
counts and shorter lines, then adjust the affected tests
10
(./check -qcow2 102, ./check -vpc 146).
11
12
Note that 'qemu-io map' is MUCH weaker than 'qemu-img map';
13
the former only shows which regions of the active layer are
14
allocated, without regards to where the allocation comes from
15
or whether the allocated portion is known to read as zero
16
(because it is using the weaker bdrv_is_allocated()); while the
17
latter (especially in --output=json mode) reports more details
18
from bdrv_get_block_status().
19
20
Signed-off-by: Eric Blake <eblake@redhat.com>
21
Message-id: 20170429191419.30051-4-eblake@redhat.com
22
Reviewed-by: Max Reitz <mreitz@redhat.com>
23
Signed-off-by: Max Reitz <mreitz@redhat.com>
24
---
25
qemu-io-cmds.c | 11 ++++++-----
26
tests/qemu-iotests/102.out | 4 ++--
27
tests/qemu-iotests/146.out | 30 +++++++++++++++---------------
28
3 files changed, 23 insertions(+), 22 deletions(-)
29
30
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/qemu-io-cmds.c
33
+++ b/qemu-io-cmds.c
34
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
35
{
36
int64_t offset;
37
int64_t nb_sectors, total_sectors;
38
- char s1[64];
39
+ char s1[64], s2[64];
40
int64_t num;
41
int ret;
42
const char *retstr;
43
@@ -XXX,XX +XXX,XX @@ static int map_f(BlockBackend *blk, int argc, char **argv)
44
}
45
46
retstr = ret ? " allocated" : "not allocated";
47
- cvtstr(offset << 9ULL, s1, sizeof(s1));
48
- printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
49
- "at offset %s (%d)\n",
50
- offset << 9ULL, num, nb_sectors, retstr, s1, ret);
51
+ cvtstr(num << BDRV_SECTOR_BITS, s1, sizeof(s1));
52
+ cvtstr(offset << BDRV_SECTOR_BITS, s2, sizeof(s2));
53
+ printf("%s (0x%" PRIx64 ") bytes %s at offset %s (0x%" PRIx64 ")\n",
54
+ s1, num << BDRV_SECTOR_BITS, retstr,
55
+ s2, offset << BDRV_SECTOR_BITS);
56
57
offset += num;
58
nb_sectors -= num;
59
diff --git a/tests/qemu-iotests/102.out b/tests/qemu-iotests/102.out
60
index XXXXXXX..XXXXXXX 100644
61
--- a/tests/qemu-iotests/102.out
62
+++ b/tests/qemu-iotests/102.out
63
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536
64
wrote 65536/65536 bytes at offset 0
65
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
66
Image resized.
67
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
68
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
69
Offset Length Mapped to File
70
71
=== Testing map on an image file truncated outside of qemu ===
72
@@ -XXX,XX +XXX,XX @@ wrote 65536/65536 bytes at offset 0
73
Image resized.
74
QEMU X.Y.Z monitor - type 'help' for more information
75
(qemu) qemu-io drv0 map
76
-[ 0] 128/ 128 sectors allocated at offset 0 bytes (1)
77
+64 KiB (0x10000) bytes allocated at offset 0 bytes (0x0)
78
*** done
79
diff --git a/tests/qemu-iotests/146.out b/tests/qemu-iotests/146.out
80
index XXXXXXX..XXXXXXX 100644
81
--- a/tests/qemu-iotests/146.out
82
+++ b/tests/qemu-iotests/146.out
83
@@ -XXX,XX +XXX,XX @@ QA output created by 146
84
85
=== Testing VPC Autodetect ===
86
87
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
88
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
89
90
=== Testing VPC with current_size force ===
91
92
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
93
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
94
95
=== Testing VPC with chs force ===
96
97
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
98
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
99
100
=== Testing Hyper-V Autodetect ===
101
102
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
103
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
104
105
=== Testing Hyper-V with current_size force ===
106
107
-[ 0] 266338304/ 266338304 sectors not allocated at offset 0 bytes (0)
108
+127 GiB (0x1fc0000000) bytes not allocated at offset 0 bytes (0x0)
109
110
=== Testing Hyper-V with chs force ===
111
112
-[ 0] 266334240/ 266334240 sectors not allocated at offset 0 bytes (0)
113
+126.998 GiB (0x1fbfe04000) bytes not allocated at offset 0 bytes (0x0)
114
115
=== Testing d2v Autodetect ===
116
117
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
118
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
119
120
=== Testing d2v with current_size force ===
121
122
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
123
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
124
125
=== Testing d2v with chs force ===
126
127
-[ 0] 514560/ 514560 sectors allocated at offset 0 bytes (1)
128
+251.250 MiB (0xfb40000) bytes allocated at offset 0 bytes (0x0)
129
130
=== Testing Image create, default ===
131
132
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296
133
134
=== Read created image, default opts ====
135
136
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
137
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
138
139
=== Read created image, force_size_calc=chs ====
140
141
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
142
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
143
144
=== Read created image, force_size_calc=current_size ====
145
146
-[ 0] 8389584/ 8389584 sectors not allocated at offset 0 bytes (0)
147
+4 GiB (0x10007a000) bytes not allocated at offset 0 bytes (0x0)
148
149
=== Testing Image create, force_size ===
150
151
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/IMGFMT-create-test.IMGFMT', fmt=IMGFMT size=4294967296 forc
152
153
=== Read created image, default opts ====
154
155
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
156
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
157
158
=== Read created image, force_size_calc=chs ====
159
160
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
161
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
162
163
=== Read created image, force_size_calc=current_size ====
164
165
-[ 0] 8388608/ 8388608 sectors not allocated at offset 0 bytes (0)
166
+4 GiB (0x100000000) bytes not allocated at offset 0 bytes (0x0)
167
*** done
168
--
169
1.8.3.1
170
171
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Commits 04ed95f4 and 1a62d0ac updated the block layer to auto-fragment
4
any I/O to fit within device boundaries. Additionally, when using a
5
minimum alignment of 4k, we want to ensure the block layer does proper
6
read-modify-write rather than requesting I/O on a slice of a sector.
7
Let's enforce that the contract is obeyed when using blkdebug. For
8
now, blkdebug only allows alignment overrides, and just inherits other
9
limits from whatever device it is wrapping, but a future patch will
10
further enhance things.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Message-id: 20170429191419.30051-5-eblake@redhat.com
16
Signed-off-by: Max Reitz <mreitz@redhat.com>
17
---
18
block/blkdebug.c | 14 ++++++++++++++
19
1 file changed, 14 insertions(+)
20
21
diff --git a/block/blkdebug.c b/block/blkdebug.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/blkdebug.c
24
+++ b/block/blkdebug.c
25
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
26
BDRVBlkdebugState *s = bs->opaque;
27
BlkdebugRule *rule = NULL;
28
29
+ /* Sanity check block layer guarantees */
30
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
31
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
32
+ if (bs->bl.max_transfer) {
33
+ assert(bytes <= bs->bl.max_transfer);
34
+ }
35
+
36
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
37
uint64_t inject_offset = rule->options.inject.offset;
38
39
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
40
BDRVBlkdebugState *s = bs->opaque;
41
BlkdebugRule *rule = NULL;
42
43
+ /* Sanity check block layer guarantees */
44
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
45
+ assert(QEMU_IS_ALIGNED(bytes, bs->bl.request_alignment));
46
+ if (bs->bl.max_transfer) {
47
+ assert(bytes <= bs->bl.max_transfer);
48
+ }
49
+
50
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
51
uint64_t inject_offset = rule->options.inject.offset;
52
53
--
54
1.8.3.1
55
56
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than repeat the logic at each caller of checking if a Rule
4
exists that warrants an error injection, fold that logic into
5
inject_error(); and rename it to rule_check() for legibility.
6
This will help the next patch, which adds two more callers that
7
need to check rules for the potential of injecting errors.
8
9
Signed-off-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Max Reitz <mreitz@redhat.com>
11
Message-id: 20170429191419.30051-6-eblake@redhat.com
12
Signed-off-by: Max Reitz <mreitz@redhat.com>
13
---
14
block/blkdebug.c | 74 +++++++++++++++++++++++++-------------------------------
15
1 file changed, 33 insertions(+), 41 deletions(-)
16
17
diff --git a/block/blkdebug.c b/block/blkdebug.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/blkdebug.c
20
+++ b/block/blkdebug.c
21
@@ -XXX,XX +XXX,XX @@ out:
22
return ret;
23
}
24
25
-static int inject_error(BlockDriverState *bs, BlkdebugRule *rule)
26
+static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes)
27
{
28
BDRVBlkdebugState *s = bs->opaque;
29
- int error = rule->options.inject.error;
30
- bool immediately = rule->options.inject.immediately;
31
+ BlkdebugRule *rule = NULL;
32
+ int error;
33
+ bool immediately;
34
+
35
+ QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
36
+ uint64_t inject_offset = rule->options.inject.offset;
37
+
38
+ if (inject_offset == -1 ||
39
+ (bytes && inject_offset >= offset &&
40
+ inject_offset < offset + bytes))
41
+ {
42
+ break;
43
+ }
44
+ }
45
+
46
+ if (!rule || !rule->options.inject.error) {
47
+ return 0;
48
+ }
49
+
50
+ immediately = rule->options.inject.immediately;
51
+ error = rule->options.inject.error;
52
53
if (rule->options.inject.once) {
54
QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next);
55
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn
56
blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
57
QEMUIOVector *qiov, int flags)
58
{
59
- BDRVBlkdebugState *s = bs->opaque;
60
- BlkdebugRule *rule = NULL;
61
+ int err;
62
63
/* Sanity check block layer guarantees */
64
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
65
@@ -XXX,XX +XXX,XX @@ blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
66
assert(bytes <= bs->bl.max_transfer);
67
}
68
69
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
70
- uint64_t inject_offset = rule->options.inject.offset;
71
-
72
- if (inject_offset == -1 ||
73
- (inject_offset >= offset && inject_offset < offset + bytes))
74
- {
75
- break;
76
- }
77
- }
78
-
79
- if (rule && rule->options.inject.error) {
80
- return inject_error(bs, rule);
81
+ err = rule_check(bs, offset, bytes);
82
+ if (err) {
83
+ return err;
84
}
85
86
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
87
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn
88
blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
89
QEMUIOVector *qiov, int flags)
90
{
91
- BDRVBlkdebugState *s = bs->opaque;
92
- BlkdebugRule *rule = NULL;
93
+ int err;
94
95
/* Sanity check block layer guarantees */
96
assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
97
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
98
assert(bytes <= bs->bl.max_transfer);
99
}
100
101
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
102
- uint64_t inject_offset = rule->options.inject.offset;
103
-
104
- if (inject_offset == -1 ||
105
- (inject_offset >= offset && inject_offset < offset + bytes))
106
- {
107
- break;
108
- }
109
- }
110
-
111
- if (rule && rule->options.inject.error) {
112
- return inject_error(bs, rule);
113
+ err = rule_check(bs, offset, bytes);
114
+ if (err) {
115
+ return err;
116
}
117
118
return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
119
@@ -XXX,XX +XXX,XX @@ blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
120
121
static int blkdebug_co_flush(BlockDriverState *bs)
122
{
123
- BDRVBlkdebugState *s = bs->opaque;
124
- BlkdebugRule *rule = NULL;
125
-
126
- QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
127
- if (rule->options.inject.offset == -1) {
128
- break;
129
- }
130
- }
131
+ int err = rule_check(bs, 0, 0);
132
133
- if (rule && rule->options.inject.error) {
134
- return inject_error(bs, rule);
135
+ if (err) {
136
+ return err;
137
}
138
139
return bdrv_co_flush(bs->file->bs);
140
--
141
1.8.3.1
142
143
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
In order to test the effects of artificial geometry constraints
4
on operations like write zero or discard, we first need blkdebug
5
to manage these actions. It also allows us to inject errors on
6
those operations, just like we can for read/write/flush.
7
8
We can also test the contract promised by the block layer; namely,
9
if a device has specified limits on alignment or maximum size,
10
then those limits must be obeyed (for now, the blkdebug driver
11
merely inherits limits from whatever it is wrapping, but the next
12
patch will further enhance it to allow specific limit overrides).
13
14
This patch intentionally refuses to service requests smaller than
15
the requested alignments; this is because an upcoming patch adds
16
a qemu-iotest to prove that the block layer is correctly handling
17
fragmentation, but the test only works if there is a way to tell
18
the difference at artificial alignment boundaries when blkdebug is
19
using a larger-than-default alignment. If we let the blkdebug
20
layer always defer to the underlying layer, which potentially has
21
a smaller granularity, the iotest will be thwarted.
22
23
Tested by setting up an NBD server with export 'foo', then invoking:
24
$ ./qemu-io
25
qemu-io> open -o driver=blkdebug blkdebug::nbd://localhost:10809/foo
26
qemu-io> d 0 15M
27
qemu-io> w -z 0 15M
28
29
Pre-patch, the server never sees the discard (it was silently
30
eaten by the block layer); post-patch it is passed across the
31
wire. Likewise, pre-patch the write is always passed with
32
NBD_WRITE (with 15M of zeroes on the wire), while post-patch
33
it can utilize NBD_WRITE_ZEROES (for less traffic).
34
35
Signed-off-by: Eric Blake <eblake@redhat.com>
36
Reviewed-by: Max Reitz <mreitz@redhat.com>
37
Message-id: 20170429191419.30051-7-eblake@redhat.com
38
Signed-off-by: Max Reitz <mreitz@redhat.com>
39
---
40
block/blkdebug.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41
1 file changed, 74 insertions(+)
42
43
diff --git a/block/blkdebug.c b/block/blkdebug.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/block/blkdebug.c
46
+++ b/block/blkdebug.c
47
@@ -XXX,XX +XXX,XX @@
48
/*
49
* Block protocol for I/O error injection
50
*
51
+ * Copyright (C) 2016-2017 Red Hat, Inc.
52
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
53
*
54
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
56
goto out;
57
}
58
59
+ bs->supported_write_flags = BDRV_REQ_FUA &
60
+ bs->file->bs->supported_write_flags;
61
+ bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
62
+ bs->file->bs->supported_zero_flags;
63
+
64
/* Set request alignment */
65
align = qemu_opt_get_size(opts, "align", 0);
66
if (align < INT_MAX && is_power_of_2(align)) {
67
@@ -XXX,XX +XXX,XX @@ static int blkdebug_co_flush(BlockDriverState *bs)
68
return bdrv_co_flush(bs->file->bs);
69
}
70
71
+static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs,
72
+ int64_t offset, int count,
73
+ BdrvRequestFlags flags)
74
+{
75
+ uint32_t align = MAX(bs->bl.request_alignment,
76
+ bs->bl.pwrite_zeroes_alignment);
77
+ int err;
78
+
79
+ /* Only pass through requests that are larger than requested
80
+ * preferred alignment (so that we test the fallback to writes on
81
+ * unaligned portions), and check that the block layer never hands
82
+ * us anything unaligned that crosses an alignment boundary. */
83
+ if (count < align) {
84
+ assert(QEMU_IS_ALIGNED(offset, align) ||
85
+ QEMU_IS_ALIGNED(offset + count, align) ||
86
+ DIV_ROUND_UP(offset, align) ==
87
+ DIV_ROUND_UP(offset + count, align));
88
+ return -ENOTSUP;
89
+ }
90
+ assert(QEMU_IS_ALIGNED(offset, align));
91
+ assert(QEMU_IS_ALIGNED(count, align));
92
+ if (bs->bl.max_pwrite_zeroes) {
93
+ assert(count <= bs->bl.max_pwrite_zeroes);
94
+ }
95
+
96
+ err = rule_check(bs, offset, count);
97
+ if (err) {
98
+ return err;
99
+ }
100
+
101
+ return bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
102
+}
103
+
104
+static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs,
105
+ int64_t offset, int count)
106
+{
107
+ uint32_t align = bs->bl.pdiscard_alignment;
108
+ int err;
109
+
110
+ /* Only pass through requests that are larger than requested
111
+ * minimum alignment, and ensure that unaligned requests do not
112
+ * cross optimum discard boundaries. */
113
+ if (count < bs->bl.request_alignment) {
114
+ assert(QEMU_IS_ALIGNED(offset, align) ||
115
+ QEMU_IS_ALIGNED(offset + count, align) ||
116
+ DIV_ROUND_UP(offset, align) ==
117
+ DIV_ROUND_UP(offset + count, align));
118
+ return -ENOTSUP;
119
+ }
120
+ assert(QEMU_IS_ALIGNED(offset, bs->bl.request_alignment));
121
+ assert(QEMU_IS_ALIGNED(count, bs->bl.request_alignment));
122
+ if (align && count >= align) {
123
+ assert(QEMU_IS_ALIGNED(offset, align));
124
+ assert(QEMU_IS_ALIGNED(count, align));
125
+ }
126
+ if (bs->bl.max_pdiscard) {
127
+ assert(count <= bs->bl.max_pdiscard);
128
+ }
129
+
130
+ err = rule_check(bs, offset, count);
131
+ if (err) {
132
+ return err;
133
+ }
134
+
135
+ return bdrv_co_pdiscard(bs->file->bs, offset, count);
136
+}
137
138
static void blkdebug_close(BlockDriverState *bs)
139
{
140
@@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkdebug = {
141
.bdrv_co_preadv = blkdebug_co_preadv,
142
.bdrv_co_pwritev = blkdebug_co_pwritev,
143
.bdrv_co_flush_to_disk = blkdebug_co_flush,
144
+ .bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes,
145
+ .bdrv_co_pdiscard = blkdebug_co_pdiscard,
146
147
.bdrv_debug_event = blkdebug_debug_event,
148
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
149
--
150
1.8.3.1
151
152
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Rather than store into a local variable, then copy to the struct
4
if the value is valid, then reporting errors otherwise, it is
5
simpler to just store into the struct and report errors if the
6
value is invalid. This however requires that the struct store
7
a 64-bit number, rather than a narrower type. Likewise, setting
8
a sane errno value in ret prior to the sequence of parsing and
9
jumping to out: on error makes it easier for the next patch to
10
add a chain of similar checks.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Message-id: 20170429191419.30051-8-eblake@redhat.com
14
Reviewed-by: Max Reitz <mreitz@redhat.com>
15
Signed-off-by: Max Reitz <mreitz@redhat.com>
16
---
17
block/blkdebug.c | 16 ++++++----------
18
1 file changed, 6 insertions(+), 10 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
23
+++ b/block/blkdebug.c
24
@@ -XXX,XX +XXX,XX @@
25
typedef struct BDRVBlkdebugState {
26
int state;
27
int new_state;
28
- int align;
29
+ uint64_t align;
30
31
/* For blkdebug_refresh_filename() */
32
char *config_file;
33
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
34
BDRVBlkdebugState *s = bs->opaque;
35
QemuOpts *opts;
36
Error *local_err = NULL;
37
- uint64_t align;
38
int ret;
39
40
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
41
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
42
bs->file->bs->supported_write_flags;
43
bs->supported_zero_flags = (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) &
44
bs->file->bs->supported_zero_flags;
45
+ ret = -EINVAL;
46
47
/* Set request alignment */
48
- align = qemu_opt_get_size(opts, "align", 0);
49
- if (align < INT_MAX && is_power_of_2(align)) {
50
- s->align = align;
51
- } else if (align) {
52
- error_setg(errp, "Invalid alignment");
53
- ret = -EINVAL;
54
+ s->align = qemu_opt_get_size(opts, "align", 0);
55
+ if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
56
+ error_setg(errp, "Cannot meet constraints with align %" PRIu64,
57
+ s->align);
58
goto out;
59
}
60
61
ret = 0;
62
- goto out;
63
-
64
out:
65
if (ret < 0) {
66
g_free(s->config_file);
67
--
68
1.8.3.1
69
70
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Make it easier to simulate various unusual hardware setups (for
4
example, recent commits 3482b9b and b8d0a98 affect the Dell
5
Equallogic iSCSI with its 15M preferred and maximum unmap and
6
write zero sizing, or b2f95fe deals with the Linux loopback
7
block device having a max_transfer of 64k), by allowing blkdebug
8
to wrap any other device with further restrictions on various
9
alignments.
10
11
Signed-off-by: Eric Blake <eblake@redhat.com>
12
Reviewed-by: Max Reitz <mreitz@redhat.com>
13
Message-id: 20170429191419.30051-9-eblake@redhat.com
14
Signed-off-by: Max Reitz <mreitz@redhat.com>
15
---
16
block/blkdebug.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++-
17
qapi/block-core.json | 33 ++++++++++++++++--
18
2 files changed, 125 insertions(+), 4 deletions(-)
19
20
diff --git a/block/blkdebug.c b/block/blkdebug.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/blkdebug.c
23
+++ b/block/blkdebug.c
24
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVBlkdebugState {
25
int state;
26
int new_state;
27
uint64_t align;
28
+ uint64_t max_transfer;
29
+ uint64_t opt_write_zero;
30
+ uint64_t max_write_zero;
31
+ uint64_t opt_discard;
32
+ uint64_t max_discard;
33
34
/* For blkdebug_refresh_filename() */
35
char *config_file;
36
@@ -XXX,XX +XXX,XX @@ static QemuOptsList runtime_opts = {
37
.type = QEMU_OPT_SIZE,
38
.help = "Required alignment in bytes",
39
},
40
+ {
41
+ .name = "max-transfer",
42
+ .type = QEMU_OPT_SIZE,
43
+ .help = "Maximum transfer size in bytes",
44
+ },
45
+ {
46
+ .name = "opt-write-zero",
47
+ .type = QEMU_OPT_SIZE,
48
+ .help = "Optimum write zero alignment in bytes",
49
+ },
50
+ {
51
+ .name = "max-write-zero",
52
+ .type = QEMU_OPT_SIZE,
53
+ .help = "Maximum write zero size in bytes",
54
+ },
55
+ {
56
+ .name = "opt-discard",
57
+ .type = QEMU_OPT_SIZE,
58
+ .help = "Optimum discard alignment in bytes",
59
+ },
60
+ {
61
+ .name = "max-discard",
62
+ .type = QEMU_OPT_SIZE,
63
+ .help = "Maximum discard size in bytes",
64
+ },
65
{ /* end of list */ }
66
},
67
};
68
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
69
QemuOpts *opts;
70
Error *local_err = NULL;
71
int ret;
72
+ uint64_t align;
73
74
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
75
qemu_opts_absorb_qdict(opts, options, &local_err);
76
@@ -XXX,XX +XXX,XX @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
77
bs->file->bs->supported_zero_flags;
78
ret = -EINVAL;
79
80
- /* Set request alignment */
81
+ /* Set alignment overrides */
82
s->align = qemu_opt_get_size(opts, "align", 0);
83
if (s->align && (s->align >= INT_MAX || !is_power_of_2(s->align))) {
84
error_setg(errp, "Cannot meet constraints with align %" PRIu64,
85
s->align);
86
goto out;
87
}
88
+ align = MAX(s->align, bs->file->bs->bl.request_alignment);
89
+
90
+ s->max_transfer = qemu_opt_get_size(opts, "max-transfer", 0);
91
+ if (s->max_transfer &&
92
+ (s->max_transfer >= INT_MAX ||
93
+ !QEMU_IS_ALIGNED(s->max_transfer, align))) {
94
+ error_setg(errp, "Cannot meet constraints with max-transfer %" PRIu64,
95
+ s->max_transfer);
96
+ goto out;
97
+ }
98
+
99
+ s->opt_write_zero = qemu_opt_get_size(opts, "opt-write-zero", 0);
100
+ if (s->opt_write_zero &&
101
+ (s->opt_write_zero >= INT_MAX ||
102
+ !QEMU_IS_ALIGNED(s->opt_write_zero, align))) {
103
+ error_setg(errp, "Cannot meet constraints with opt-write-zero %" PRIu64,
104
+ s->opt_write_zero);
105
+ goto out;
106
+ }
107
+
108
+ s->max_write_zero = qemu_opt_get_size(opts, "max-write-zero", 0);
109
+ if (s->max_write_zero &&
110
+ (s->max_write_zero >= INT_MAX ||
111
+ !QEMU_IS_ALIGNED(s->max_write_zero,
112
+ MAX(s->opt_write_zero, align)))) {
113
+ error_setg(errp, "Cannot meet constraints with max-write-zero %" PRIu64,
114
+ s->max_write_zero);
115
+ goto out;
116
+ }
117
+
118
+ s->opt_discard = qemu_opt_get_size(opts, "opt-discard", 0);
119
+ if (s->opt_discard &&
120
+ (s->opt_discard >= INT_MAX ||
121
+ !QEMU_IS_ALIGNED(s->opt_discard, align))) {
122
+ error_setg(errp, "Cannot meet constraints with opt-discard %" PRIu64,
123
+ s->opt_discard);
124
+ goto out;
125
+ }
126
+
127
+ s->max_discard = qemu_opt_get_size(opts, "max-discard", 0);
128
+ if (s->max_discard &&
129
+ (s->max_discard >= INT_MAX ||
130
+ !QEMU_IS_ALIGNED(s->max_discard,
131
+ MAX(s->opt_discard, align)))) {
132
+ error_setg(errp, "Cannot meet constraints with max-discard %" PRIu64,
133
+ s->max_discard);
134
+ goto out;
135
+ }
136
137
ret = 0;
138
out:
139
@@ -XXX,XX +XXX,XX @@ static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp)
140
if (s->align) {
141
bs->bl.request_alignment = s->align;
142
}
143
+ if (s->max_transfer) {
144
+ bs->bl.max_transfer = s->max_transfer;
145
+ }
146
+ if (s->opt_write_zero) {
147
+ bs->bl.pwrite_zeroes_alignment = s->opt_write_zero;
148
+ }
149
+ if (s->max_write_zero) {
150
+ bs->bl.max_pwrite_zeroes = s->max_write_zero;
151
+ }
152
+ if (s->opt_discard) {
153
+ bs->bl.pdiscard_alignment = s->opt_discard;
154
+ }
155
+ if (s->max_discard) {
156
+ bs->bl.max_pdiscard = s->max_discard;
157
+ }
158
}
159
160
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
161
diff --git a/qapi/block-core.json b/qapi/block-core.json
162
index XXXXXXX..XXXXXXX 100644
163
--- a/qapi/block-core.json
164
+++ b/qapi/block-core.json
165
@@ -XXX,XX +XXX,XX @@
166
#
167
# @config: filename of the configuration file
168
#
169
-# @align: required alignment for requests in bytes,
170
-# must be power of 2, or 0 for default
171
+# @align: required alignment for requests in bytes, must be
172
+# positive power of 2, or 0 for default
173
+#
174
+# @max-transfer: maximum size for I/O transfers in bytes, must be
175
+# positive multiple of @align and of the underlying
176
+# file's request alignment (but need not be a power of
177
+# 2), or 0 for default (since 2.10)
178
+#
179
+# @opt-write-zero: preferred alignment for write zero requests in bytes,
180
+# must be positive multiple of @align and of the
181
+# underlying file's request alignment (but need not be a
182
+# power of 2), or 0 for default (since 2.10)
183
+#
184
+# @max-write-zero: maximum size for write zero requests in bytes, must be
185
+# positive multiple of @align, of @opt-write-zero, and of
186
+# the underlying file's request alignment (but need not
187
+# be a power of 2), or 0 for default (since 2.10)
188
+#
189
+# @opt-discard: preferred alignment for discard requests in bytes, must
190
+# be positive multiple of @align and of the underlying
191
+# file's request alignment (but need not be a power of
192
+# 2), or 0 for default (since 2.10)
193
+#
194
+# @max-discard: maximum size for discard requests in bytes, must be
195
+# positive multiple of @align, of @opt-discard, and of
196
+# the underlying file's request alignment (but need not
197
+# be a power of 2), or 0 for default (since 2.10)
198
#
199
# @inject-error: array of error injection descriptions
200
#
201
@@ -XXX,XX +XXX,XX @@
202
{ 'struct': 'BlockdevOptionsBlkdebug',
203
'data': { 'image': 'BlockdevRef',
204
'*config': 'str',
205
- '*align': 'int',
206
+ '*align': 'int', '*max-transfer': 'int32',
207
+ '*opt-write-zero': 'int32', '*max-write-zero': 'int32',
208
+ '*opt-discard': 'int32', '*max-discard': 'int32',
209
'*inject-error': ['BlkdebugInjectErrorOptions'],
210
'*set-state': ['BlkdebugSetStateOptions'] } }
211
212
--
213
1.8.3.1
214
215
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Use blkdebug's new geometry constraints to emulate setups that
4
have needed past regression fixes: write zeroes asserting
5
when running through a loopback block device with max-transfer
6
smaller than cluster size, and discard rounding away portions
7
of requests not aligned to preferred boundaries. Also, add
8
coverage that the block layer is honoring max transfer limits.
9
10
For now, a single iotest performs all actions, with the idea
11
that we can add future blkdebug constraint test cases in the
12
same file; but it can be split into multiple iotests if we find
13
reason to run one portion of the test in more setups than what
14
are possible in the other.
15
16
For reference, the final portion of the test (checking whether
17
discard passes as much as possible to the lowest layers of the
18
stack) works as follows:
19
20
qemu-io: discard 30M at 80000001, passed to blkdebug
21
blkdebug: discard 511 bytes at 80000001, -ENOTSUP (smaller than
22
blkdebug's 512 align)
23
blkdebug: discard 14371328 bytes at 80000512, passed to qcow2
24
qcow2: discard 739840 bytes at 80000512, -ENOTSUP (smaller than
25
qcow2's 1M align)
26
qcow2: discard 13M bytes at 77M, succeeds
27
blkdebug: discard 15M bytes at 90M, passed to qcow2
28
qcow2: discard 15M bytes at 90M, succeeds
29
blkdebug: discard 1356800 bytes at 105M, passed to qcow2
30
qcow2: discard 1M at 105M, succeeds
31
qcow2: discard 308224 bytes at 106M, -ENOTSUP (smaller than qcow2's
32
1M align)
33
blkdebug: discard 1 byte at 111457280, -ENOTSUP (smaller than
34
blkdebug's 512 align)
35
36
Signed-off-by: Eric Blake <eblake@redhat.com>
37
Reviewed-by: Max Reitz <mreitz@redhat.com>
38
Message-id: 20170429191419.30051-10-eblake@redhat.com
39
[mreitz: For cooperation with image locking, add -r to the qemu-io
40
invocation which verifies the image content]
41
Signed-off-by: Max Reitz <mreitz@redhat.com>
42
---
43
tests/qemu-iotests/177 | 114 +++++++++++++++++++++++++++++++++++++++++++++
44
tests/qemu-iotests/177.out | 49 +++++++++++++++++++
45
tests/qemu-iotests/group | 1 +
46
3 files changed, 164 insertions(+)
47
create mode 100755 tests/qemu-iotests/177
48
create mode 100644 tests/qemu-iotests/177.out
49
50
diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177
51
new file mode 100755
52
index XXXXXXX..XXXXXXX
53
--- /dev/null
54
+++ b/tests/qemu-iotests/177
55
@@ -XXX,XX +XXX,XX @@
56
+#!/bin/bash
57
+#
58
+# Test corner cases with unusual block geometries
59
+#
60
+# Copyright (C) 2016-2017 Red Hat, Inc.
61
+#
62
+# This program is free software; you can redistribute it and/or modify
63
+# it under the terms of the GNU General Public License as published by
64
+# the Free Software Foundation; either version 2 of the License, or
65
+# (at your option) any later version.
66
+#
67
+# This program is distributed in the hope that it will be useful,
68
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70
+# GNU General Public License for more details.
71
+#
72
+# You should have received a copy of the GNU General Public License
73
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
74
+#
75
+
76
+# creator
77
+owner=eblake@redhat.com
78
+
79
+seq=`basename $0`
80
+echo "QA output created by $seq"
81
+
82
+here=`pwd`
83
+status=1    # failure is the default!
84
+
85
+_cleanup()
86
+{
87
+    _cleanup_test_img
88
+}
89
+trap "_cleanup; exit \$status" 0 1 2 3 15
90
+
91
+# get standard environment, filters and checks
92
+. ./common.rc
93
+. ./common.filter
94
+
95
+_supported_fmt qcow2
96
+_supported_proto file
97
+
98
+CLUSTER_SIZE=1M
99
+size=128M
100
+options=driver=blkdebug,image.driver=qcow2
101
+
102
+echo
103
+echo "== setting up files =="
104
+
105
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
106
+$QEMU_IO -c "write -P 11 0 $size" "$TEST_IMG.base" | _filter_qemu_io
107
+_make_test_img -b "$TEST_IMG.base"
108
+$QEMU_IO -c "write -P 22 0 $size" "$TEST_IMG" | _filter_qemu_io
109
+
110
+# Limited to 64k max-transfer
111
+echo
112
+echo "== constrained alignment and max-transfer =="
113
+limits=align=4k,max-transfer=64k
114
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
115
+ -c "write -P 33 1000 128k" -c "read -P 33 1000 128k" | _filter_qemu_io
116
+
117
+echo
118
+echo "== write zero with constrained max-transfer =="
119
+limits=align=512,max-transfer=64k,opt-write-zero=$CLUSTER_SIZE
120
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
121
+ -c "write -z 8003584 2093056" | _filter_qemu_io
122
+
123
+# non-power-of-2 write-zero/discard alignments
124
+echo
125
+echo "== non-power-of-2 write zeroes limits =="
126
+
127
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
128
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
129
+ -c "write -z 32M 32M" | _filter_qemu_io
130
+
131
+echo
132
+echo "== non-power-of-2 discard limits =="
133
+
134
+limits=align=512,opt-write-zero=15M,max-write-zero=15M,opt-discard=15M,max-discard=15M
135
+$QEMU_IO -c "open -o $options,$limits blkdebug::$TEST_IMG" \
136
+ -c "discard 80000001 30M" | _filter_qemu_io
137
+
138
+echo
139
+echo "== verify image content =="
140
+
141
+function verify_io()
142
+{
143
+ if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" |
144
+     grep "compat: 0.10" > /dev/null); then
145
+ # For v2 images, discarded clusters are read from the backing file
146
+ discarded=11
147
+ else
148
+ # Discarded clusters are zeroed for v3 or later
149
+ discarded=0
150
+ fi
151
+
152
+ echo read -P 22 0 1000
153
+ echo read -P 33 1000 128k
154
+ echo read -P 22 132072 7871512
155
+ echo read -P 0 8003584 2093056
156
+ echo read -P 22 10096640 23457792
157
+ echo read -P 0 32M 32M
158
+ echo read -P 22 64M 13M
159
+ echo read -P $discarded 77M 29M
160
+ echo read -P 22 106M 22M
161
+}
162
+
163
+verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io
164
+
165
+_check_test_img
166
+
167
+# success, all done
168
+echo "*** done"
169
+status=0
170
diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out
171
new file mode 100644
172
index XXXXXXX..XXXXXXX
173
--- /dev/null
174
+++ b/tests/qemu-iotests/177.out
175
@@ -XXX,XX +XXX,XX @@
176
+QA output created by 177
177
+
178
+== setting up files ==
179
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134217728
180
+wrote 134217728/134217728 bytes at offset 0
181
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 134217728/134217728 bytes at offset 0
184
+128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+
186
+== constrained alignment and max-transfer ==
187
+wrote 131072/131072 bytes at offset 1000
188
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
189
+read 131072/131072 bytes at offset 1000
190
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
191
+
192
+== write zero with constrained max-transfer ==
193
+wrote 2093056/2093056 bytes at offset 8003584
194
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+
196
+== non-power-of-2 write zeroes limits ==
197
+wrote 33554432/33554432 bytes at offset 33554432
198
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
199
+
200
+== non-power-of-2 discard limits ==
201
+discard 31457280/31457280 bytes at offset 80000001
202
+30 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
203
+
204
+== verify image content ==
205
+read 1000/1000 bytes at offset 0
206
+1000 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
207
+read 131072/131072 bytes at offset 1000
208
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+read 7871512/7871512 bytes at offset 132072
210
+7.507 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+read 2093056/2093056 bytes at offset 8003584
212
+1.996 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+read 23457792/23457792 bytes at offset 10096640
214
+22.371 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
215
+read 33554432/33554432 bytes at offset 33554432
216
+32 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
217
+read 13631488/13631488 bytes at offset 67108864
218
+13 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
219
+read 30408704/30408704 bytes at offset 80740352
220
+29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
221
+read 23068672/23068672 bytes at offset 111149056
222
+22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
223
+No errors were found on the image.
224
+*** done
225
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
226
index XXXXXXX..XXXXXXX 100644
227
--- a/tests/qemu-iotests/group
228
+++ b/tests/qemu-iotests/group
229
@@ -XXX,XX +XXX,XX @@
230
174 auto
231
175 auto quick
232
176 rw auto backing
233
+177 rw auto quick
234
181 rw auto migration
235
182 rw auto quick
236
--
237
1.8.3.1
238
239
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
In order to keep checkpatch happy when the next patch changes
4
indentation, we first have to shorten some long lines. The easiest
5
approach is to use a new variable in place of
6
'offset & L2E_OFFSET_MASK', except that 'offset' is the best name
7
for that variable. Change '[old_]offset' to '[old_]entry' to
8
make room.
9
10
While touching things, also fix checkpatch warnings about unusual
11
'for' statements.
12
13
Suggested by Max Reitz <mreitz@redhat.com>
14
Signed-off-by: Eric Blake <eblake@redhat.com>
15
Message-id: 20170507000552.20847-2-eblake@redhat.com
16
Reviewed-by: Max Reitz <mreitz@redhat.com>
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-refcount.c | 42 ++++++++++++++++++++++--------------------
20
1 file changed, 22 insertions(+), 20 deletions(-)
21
22
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/block/qcow2-refcount.c
25
+++ b/block/qcow2-refcount.c
26
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
27
int64_t l1_table_offset, int l1_size, int addend)
28
{
29
BDRVQcow2State *s = bs->opaque;
30
- uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount;
31
+ uint64_t *l1_table, *l2_table, l2_offset, entry, l1_size2, refcount;
32
bool l1_allocated = false;
33
- int64_t old_offset, old_l2_offset;
34
+ int64_t old_entry, old_l2_offset;
35
int i, j, l1_modified = 0, nb_csectors;
36
int ret;
37
38
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
39
goto fail;
40
}
41
42
- for(i = 0;i < l1_size; i++)
43
+ for (i = 0; i < l1_size; i++) {
44
be64_to_cpus(&l1_table[i]);
45
+ }
46
} else {
47
assert(l1_size == s->l1_size);
48
l1_table = s->l1_table;
49
l1_allocated = false;
50
}
51
52
- for(i = 0; i < l1_size; i++) {
53
+ for (i = 0; i < l1_size; i++) {
54
l2_offset = l1_table[i];
55
if (l2_offset) {
56
old_l2_offset = l2_offset;
57
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
58
goto fail;
59
}
60
61
- for(j = 0; j < s->l2_size; j++) {
62
+ for (j = 0; j < s->l2_size; j++) {
63
uint64_t cluster_index;
64
+ uint64_t offset;
65
66
- offset = be64_to_cpu(l2_table[j]);
67
- old_offset = offset;
68
- offset &= ~QCOW_OFLAG_COPIED;
69
+ entry = be64_to_cpu(l2_table[j]);
70
+ old_entry = entry;
71
+ entry &= ~QCOW_OFLAG_COPIED;
72
+ offset = entry & L2E_OFFSET_MASK;
73
74
- switch (qcow2_get_cluster_type(offset)) {
75
+ switch (qcow2_get_cluster_type(entry)) {
76
case QCOW2_CLUSTER_COMPRESSED:
77
- nb_csectors = ((offset >> s->csize_shift) &
78
+ nb_csectors = ((entry >> s->csize_shift) &
79
s->csize_mask) + 1;
80
if (addend != 0) {
81
ret = update_refcount(bs,
82
- (offset & s->cluster_offset_mask) & ~511,
83
+ (entry & s->cluster_offset_mask) & ~511,
84
nb_csectors * 512, abs(addend), addend < 0,
85
QCOW2_DISCARD_SNAPSHOT);
86
if (ret < 0) {
87
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
88
89
case QCOW2_CLUSTER_NORMAL:
90
case QCOW2_CLUSTER_ZERO:
91
- if (offset_into_cluster(s, offset & L2E_OFFSET_MASK)) {
92
+ if (offset_into_cluster(s, offset)) {
93
qcow2_signal_corruption(bs, true, -1, -1, "Data "
94
- "cluster offset %#llx "
95
- "unaligned (L2 offset: %#"
96
+ "cluster offset %#" PRIx64
97
+ " unaligned (L2 offset: %#"
98
PRIx64 ", L2 index: %#x)",
99
- offset & L2E_OFFSET_MASK,
100
- l2_offset, j);
101
+ offset, l2_offset, j);
102
ret = -EIO;
103
goto fail;
104
}
105
106
- cluster_index = (offset & L2E_OFFSET_MASK) >> s->cluster_bits;
107
+ cluster_index = offset >> s->cluster_bits;
108
if (!cluster_index) {
109
/* unallocated */
110
refcount = 0;
111
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
112
}
113
114
if (refcount == 1) {
115
- offset |= QCOW_OFLAG_COPIED;
116
+ entry |= QCOW_OFLAG_COPIED;
117
}
118
- if (offset != old_offset) {
119
+ if (entry != old_entry) {
120
if (addend > 0) {
121
qcow2_cache_set_dependency(bs, s->l2_table_cache,
122
s->refcount_block_cache);
123
}
124
- l2_table[j] = cpu_to_be64(offset);
125
+ l2_table[j] = cpu_to_be64(entry);
126
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache,
127
l2_table);
128
}
129
--
130
1.8.3.1
131
132
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Fix a couple of inconsistent indentations, before an upcoming
4
patch further tweaks the switch statements.
5
(best viewed with 'git diff -b').
6
7
Signed-off-by: Eric Blake <eblake@redhat.com>
8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9
Message-id: 20170507000552.20847-3-eblake@redhat.com
10
Signed-off-by: Max Reitz <mreitz@redhat.com>
11
---
12
block/qcow2-cluster.c | 32 +++++++++----------
13
block/qcow2-refcount.c | 84 +++++++++++++++++++++++++-------------------------
14
2 files changed, 58 insertions(+), 58 deletions(-)
15
16
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/block/qcow2-cluster.c
19
+++ b/block/qcow2-cluster.c
20
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
21
* but rather fall through to the backing file.
22
*/
23
switch (qcow2_get_cluster_type(old_l2_entry)) {
24
- case QCOW2_CLUSTER_UNALLOCATED:
25
- if (full_discard || !bs->backing) {
26
- continue;
27
- }
28
- break;
29
+ case QCOW2_CLUSTER_UNALLOCATED:
30
+ if (full_discard || !bs->backing) {
31
+ continue;
32
+ }
33
+ break;
34
35
- case QCOW2_CLUSTER_ZERO:
36
- /* Preallocated zero clusters should be discarded in any case */
37
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
38
- continue;
39
- }
40
- break;
41
+ case QCOW2_CLUSTER_ZERO:
42
+ /* Preallocated zero clusters should be discarded in any case */
43
+ if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
44
+ continue;
45
+ }
46
+ break;
47
48
- case QCOW2_CLUSTER_NORMAL:
49
- case QCOW2_CLUSTER_COMPRESSED:
50
- break;
51
+ case QCOW2_CLUSTER_NORMAL:
52
+ case QCOW2_CLUSTER_COMPRESSED:
53
+ break;
54
55
- default:
56
- abort();
57
+ default:
58
+ abort();
59
}
60
61
/* First remove L2 entries */
62
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/block/qcow2-refcount.c
65
+++ b/block/qcow2-refcount.c
66
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
67
offset = entry & L2E_OFFSET_MASK;
68
69
switch (qcow2_get_cluster_type(entry)) {
70
- case QCOW2_CLUSTER_COMPRESSED:
71
- nb_csectors = ((entry >> s->csize_shift) &
72
- s->csize_mask) + 1;
73
- if (addend != 0) {
74
- ret = update_refcount(bs,
75
+ case QCOW2_CLUSTER_COMPRESSED:
76
+ nb_csectors = ((entry >> s->csize_shift) &
77
+ s->csize_mask) + 1;
78
+ if (addend != 0) {
79
+ ret = update_refcount(bs,
80
(entry & s->cluster_offset_mask) & ~511,
81
nb_csectors * 512, abs(addend), addend < 0,
82
QCOW2_DISCARD_SNAPSHOT);
83
- if (ret < 0) {
84
- goto fail;
85
- }
86
- }
87
- /* compressed clusters are never modified */
88
- refcount = 2;
89
- break;
90
-
91
- case QCOW2_CLUSTER_NORMAL:
92
- case QCOW2_CLUSTER_ZERO:
93
- if (offset_into_cluster(s, offset)) {
94
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
95
- "cluster offset %#" PRIx64
96
- " unaligned (L2 offset: %#"
97
- PRIx64 ", L2 index: %#x)",
98
- offset, l2_offset, j);
99
- ret = -EIO;
100
+ if (ret < 0) {
101
goto fail;
102
}
103
+ }
104
+ /* compressed clusters are never modified */
105
+ refcount = 2;
106
+ break;
107
+
108
+ case QCOW2_CLUSTER_NORMAL:
109
+ case QCOW2_CLUSTER_ZERO:
110
+ if (offset_into_cluster(s, offset)) {
111
+ qcow2_signal_corruption(bs, true, -1, -1, "Data "
112
+ "cluster offset %#" PRIx64
113
+ " unaligned (L2 offset: %#"
114
+ PRIx64 ", L2 index: %#x)",
115
+ offset, l2_offset, j);
116
+ ret = -EIO;
117
+ goto fail;
118
+ }
119
120
- cluster_index = offset >> s->cluster_bits;
121
- if (!cluster_index) {
122
- /* unallocated */
123
- refcount = 0;
124
- break;
125
- }
126
- if (addend != 0) {
127
- ret = qcow2_update_cluster_refcount(bs,
128
+ cluster_index = offset >> s->cluster_bits;
129
+ if (!cluster_index) {
130
+ /* unallocated */
131
+ refcount = 0;
132
+ break;
133
+ }
134
+ if (addend != 0) {
135
+ ret = qcow2_update_cluster_refcount(bs,
136
cluster_index, abs(addend), addend < 0,
137
QCOW2_DISCARD_SNAPSHOT);
138
- if (ret < 0) {
139
- goto fail;
140
- }
141
- }
142
-
143
- ret = qcow2_get_refcount(bs, cluster_index, &refcount);
144
if (ret < 0) {
145
goto fail;
146
}
147
- break;
148
+ }
149
150
- case QCOW2_CLUSTER_UNALLOCATED:
151
- refcount = 0;
152
- break;
153
+ ret = qcow2_get_refcount(bs, cluster_index, &refcount);
154
+ if (ret < 0) {
155
+ goto fail;
156
+ }
157
+ break;
158
+
159
+ case QCOW2_CLUSTER_UNALLOCATED:
160
+ refcount = 0;
161
+ break;
162
163
- default:
164
- abort();
165
+ default:
166
+ abort();
167
}
168
169
if (refcount == 1) {
170
--
171
1.8.3.1
172
173
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We had some conflicting documentation: a nice 8-way table that
4
described all possible combinations of DATA, ZERO, and
5
OFFSET_VALID, contrasted with text that implied that OFFSET_VALID
6
always meant raw data could be read directly. Furthermore, the
7
text refers a lot to bs->file, even though the interface was
8
updated back in 67a0fd2a to let the driver pass back a specific
9
BDS (not necessarily bs->file). As the 8-way table is the
10
intended semantics, simplify the rest of the text to get rid of
11
the confusion.
12
13
ALLOCATED is always set by the block layer for convenience (drivers
14
do not have to worry about it). RAW is used only internally, but
15
by more than the raw driver. Document these additional items on
16
the driver callback.
17
18
Suggested-by: Max Reitz <mreitz@redhat.com>
19
Signed-off-by: Eric Blake <eblake@redhat.com>
20
Reviewed-by: Max Reitz <mreitz@redhat.com>
21
Message-id: 20170507000552.20847-4-eblake@redhat.com
22
Signed-off-by: Max Reitz <mreitz@redhat.com>
23
---
24
include/block/block.h | 35 +++++++++++++++++++----------------
25
include/block/block_int.h | 7 +++++++
26
2 files changed, 26 insertions(+), 16 deletions(-)
27
28
diff --git a/include/block/block.h b/include/block/block.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/include/block/block.h
31
+++ b/include/block/block.h
32
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
33
#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
34
35
/*
36
- * Allocation status flags
37
- * BDRV_BLOCK_DATA: data is read from a file returned by bdrv_get_block_status.
38
- * BDRV_BLOCK_ZERO: sectors read as zero
39
- * BDRV_BLOCK_OFFSET_VALID: sector stored as raw data in a file returned by
40
- * bdrv_get_block_status.
41
+ * Allocation status flags for bdrv_get_block_status() and friends.
42
+ *
43
+ * Public flags:
44
+ * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer
45
+ * BDRV_BLOCK_ZERO: offset reads as zero
46
+ * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
47
* BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
48
- * layer (as opposed to the backing file)
49
- * BDRV_BLOCK_RAW: used internally to indicate that the request
50
- * was answered by the raw driver and that one
51
- * should look in bs->file directly.
52
+ * layer (short for DATA || ZERO), set by block layer
53
*
54
- * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
55
- * bs->file where sector data can be read from as raw data.
56
+ * Internal flag:
57
+ * BDRV_BLOCK_RAW: used internally to indicate that the request was
58
+ * answered by a passthrough driver such as raw and that the
59
+ * block layer should recompute the answer from bs->file.
60
*
61
- * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present.
62
+ * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK)
63
+ * represent the offset in the returned BDS that is allocated for the
64
+ * corresponding raw data; however, whether that offset actually contains
65
+ * data also depends on BDRV_BLOCK_DATA and BDRV_BLOCK_ZERO, as follows:
66
*
67
* DATA ZERO OFFSET_VALID
68
- * t t t sectors read as zero, bs->file is zero at offset
69
- * t f t sectors read as valid from bs->file at offset
70
- * f t t sectors preallocated, read as zero, bs->file not
71
+ * t t t sectors read as zero, returned file is zero at offset
72
+ * t f t sectors read as valid from file at offset
73
+ * f t t sectors preallocated, read as zero, returned file not
74
* necessarily zero at offset
75
* f f t sectors preallocated but read from backing_hd,
76
- * bs->file contains garbage at offset
77
+ * returned file contains garbage at offset
78
* t t f sectors preallocated, read as zero, unknown offset
79
* t f f sectors read from unknown file or offset
80
* f t f not allocated or unknown offset, read as zero
81
diff --git a/include/block/block_int.h b/include/block/block_int.h
82
index XXXXXXX..XXXXXXX 100644
83
--- a/include/block/block_int.h
84
+++ b/include/block/block_int.h
85
@@ -XXX,XX +XXX,XX @@ struct BlockDriver {
86
int64_t offset, int count, BdrvRequestFlags flags);
87
int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs,
88
int64_t offset, int count);
89
+
90
+ /*
91
+ * Building block for bdrv_block_status[_above]. The driver should
92
+ * answer only according to the current layer, and should not
93
+ * set BDRV_BLOCK_ALLOCATED, but may set BDRV_BLOCK_RAW. See block.h
94
+ * for the meaning of _DATA, _ZERO, and _OFFSET_VALID.
95
+ */
96
int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs,
97
int64_t sector_num, int nb_sectors, int *pnum,
98
BlockDriverState **file);
99
--
100
1.8.3.1
101
102
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We were throwing away the preallocation information associated with
4
zero clusters. But we should be matching the well-defined semantics
5
in bdrv_get_block_status(), where (BDRV_BLOCK_ZERO |
6
BDRV_BLOCK_OFFSET_VALID) informs the user which offset is reserved,
7
while still reminding the user that reading from that offset is
8
likely to read garbage.
9
10
count_contiguous_clusters_by_type() is now used only for unallocated
11
cluster runs, hence it gets renamed and tightened.
12
13
Making this change lets us see which portions of an image are zero
14
but preallocated, when using qemu-img map --output=json. The
15
--output=human side intentionally ignores all zero clusters, whether
16
or not they are preallocated.
17
18
The fact that there is no change to qemu-iotests './check -qcow2'
19
merely means that we aren't yet testing this aspect of qemu-img;
20
a later patch will add a test.
21
22
Signed-off-by: Eric Blake <eblake@redhat.com>
23
Reviewed-by: Max Reitz <mreitz@redhat.com>
24
Message-id: 20170507000552.20847-5-eblake@redhat.com
25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26
---
27
block/qcow2-cluster.c | 45 +++++++++++++++++++++++++++++++++++----------
28
1 file changed, 35 insertions(+), 10 deletions(-)
29
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
33
+++ b/block/qcow2-cluster.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
35
    return i;
36
}
37
38
-static int count_contiguous_clusters_by_type(int nb_clusters,
39
- uint64_t *l2_table,
40
- int wanted_type)
41
+/*
42
+ * Checks how many consecutive unallocated clusters in a given L2
43
+ * table have the same cluster type.
44
+ */
45
+static int count_contiguous_clusters_unallocated(int nb_clusters,
46
+ uint64_t *l2_table,
47
+ int wanted_type)
48
{
49
int i;
50
51
+ assert(wanted_type == QCOW2_CLUSTER_ZERO ||
52
+ wanted_type == QCOW2_CLUSTER_UNALLOCATED);
53
for (i = 0; i < nb_clusters; i++) {
54
- int type = qcow2_get_cluster_type(be64_to_cpu(l2_table[i]));
55
+ uint64_t entry = be64_to_cpu(l2_table[i]);
56
+ int type = qcow2_get_cluster_type(entry);
57
58
- if (type != wanted_type) {
59
+ if (type != wanted_type || entry & L2E_OFFSET_MASK) {
60
break;
61
}
62
}
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
ret = -EIO;
65
goto fail;
66
}
67
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
68
- QCOW2_CLUSTER_ZERO);
69
- *cluster_offset = 0;
70
+ /* Distinguish between pure zero clusters and pre-allocated ones */
71
+ if (*cluster_offset & L2E_OFFSET_MASK) {
72
+ c = count_contiguous_clusters(nb_clusters, s->cluster_size,
73
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
74
+ *cluster_offset &= L2E_OFFSET_MASK;
75
+ if (offset_into_cluster(s, *cluster_offset)) {
76
+ qcow2_signal_corruption(bs, true, -1, -1,
77
+ "Preallocated zero cluster offset %#"
78
+ PRIx64 " unaligned (L2 offset: %#"
79
+ PRIx64 ", L2 index: %#x)",
80
+ *cluster_offset, l2_offset, l2_index);
81
+ ret = -EIO;
82
+ goto fail;
83
+ }
84
+ } else {
85
+ c = count_contiguous_clusters_unallocated(nb_clusters,
86
+ &l2_table[l2_index],
87
+ QCOW2_CLUSTER_ZERO);
88
+ *cluster_offset = 0;
89
+ }
90
break;
91
case QCOW2_CLUSTER_UNALLOCATED:
92
/* how many empty clusters ? */
93
- c = count_contiguous_clusters_by_type(nb_clusters, &l2_table[l2_index],
94
- QCOW2_CLUSTER_UNALLOCATED);
95
+ c = count_contiguous_clusters_unallocated(nb_clusters,
96
+ &l2_table[l2_index],
97
+ QCOW2_CLUSTER_UNALLOCATED);
98
*cluster_offset = 0;
99
break;
100
case QCOW2_CLUSTER_NORMAL:
101
--
102
1.8.3.1
103
104
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Although it doesn't add all that much type safety (this is C, after
4
all), it does add a bit of legibility to use the name QCow2ClusterType
5
instead of a plain int.
6
7
In particular, qcow2_get_cluster_offset() has an overloaded return
8
type; a QCow2ClusterType on success, and -errno on failure; keeping
9
the cluster type in a separate variable makes it slightly easier for
10
the next patch to make further computations based on the type.
11
12
Suggested-by: Max Reitz <mreitz@redhat.com>
13
Signed-off-by: Eric Blake <eblake@redhat.com>
14
Message-id: 20170507000552.20847-6-eblake@redhat.com
15
[mreitz: Use the new type in two more places (one of them pulled from
16
the next patch)]
17
Signed-off-by: Max Reitz <mreitz@redhat.com>
18
---
19
block/qcow2-cluster.c | 21 +++++++++++----------
20
block/qcow2-refcount.c | 2 +-
21
block/qcow2.h | 6 +++---
22
3 files changed, 15 insertions(+), 14 deletions(-)
23
24
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/block/qcow2-cluster.c
27
+++ b/block/qcow2-cluster.c
28
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
29
uint64_t *l2_table, uint64_t stop_flags)
30
{
31
int i;
32
- int first_cluster_type;
33
+ QCow2ClusterType first_cluster_type;
34
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
35
uint64_t first_entry = be64_to_cpu(l2_table[0]);
36
uint64_t offset = first_entry & mask;
37
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
38
*/
39
static int count_contiguous_clusters_unallocated(int nb_clusters,
40
uint64_t *l2_table,
41
- int wanted_type)
42
+ QCow2ClusterType wanted_type)
43
{
44
int i;
45
46
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
47
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
48
for (i = 0; i < nb_clusters; i++) {
49
uint64_t entry = be64_to_cpu(l2_table[i]);
50
- int type = qcow2_get_cluster_type(entry);
51
+ QCow2ClusterType type = qcow2_get_cluster_type(entry);
52
53
if (type != wanted_type || entry & L2E_OFFSET_MASK) {
54
break;
55
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
56
int l1_bits, c;
57
unsigned int offset_in_cluster;
58
uint64_t bytes_available, bytes_needed, nb_clusters;
59
+ QCow2ClusterType type;
60
int ret;
61
62
offset_in_cluster = offset_into_cluster(s, offset);
63
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
64
65
l1_index = offset >> l1_bits;
66
if (l1_index >= s->l1_size) {
67
- ret = QCOW2_CLUSTER_UNALLOCATED;
68
+ type = QCOW2_CLUSTER_UNALLOCATED;
69
goto out;
70
}
71
72
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
73
if (!l2_offset) {
74
- ret = QCOW2_CLUSTER_UNALLOCATED;
75
+ type = QCOW2_CLUSTER_UNALLOCATED;
76
goto out;
77
}
78
79
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
80
* true */
81
assert(nb_clusters <= INT_MAX);
82
83
- ret = qcow2_get_cluster_type(*cluster_offset);
84
- switch (ret) {
85
+ type = qcow2_get_cluster_type(*cluster_offset);
86
+ switch (type) {
87
case QCOW2_CLUSTER_COMPRESSED:
88
/* Compressed clusters can only be processed one by one */
89
c = 1;
90
@@ -XXX,XX +XXX,XX @@ out:
91
assert(bytes_available - offset_in_cluster <= UINT_MAX);
92
*bytes = bytes_available - offset_in_cluster;
93
94
- return ret;
95
+ return type;
96
97
fail:
98
qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table);
99
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
100
101
for (i = 0; i < nb_clusters; i++) {
102
uint64_t l2_entry = be64_to_cpu(l2_table[l2_index + i]);
103
- int cluster_type = qcow2_get_cluster_type(l2_entry);
104
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
105
106
switch(cluster_type) {
107
case QCOW2_CLUSTER_NORMAL:
108
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
109
for (j = 0; j < s->l2_size; j++) {
110
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
111
int64_t offset = l2_entry & L2E_OFFSET_MASK;
112
- int cluster_type = qcow2_get_cluster_type(l2_entry);
113
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
114
bool preallocated = offset != 0;
115
116
if (cluster_type != QCOW2_CLUSTER_ZERO) {
117
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
118
index XXXXXXX..XXXXXXX 100644
119
--- a/block/qcow2-refcount.c
120
+++ b/block/qcow2-refcount.c
121
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
122
for (j = 0; j < s->l2_size; j++) {
123
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
124
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
125
- int cluster_type = qcow2_get_cluster_type(l2_entry);
126
+ QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
127
128
if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
129
((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
130
diff --git a/block/qcow2.h b/block/qcow2.h
131
index XXXXXXX..XXXXXXX 100644
132
--- a/block/qcow2.h
133
+++ b/block/qcow2.h
134
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
135
QLIST_ENTRY(QCowL2Meta) next_in_flight;
136
} QCowL2Meta;
137
138
-enum {
139
+typedef enum QCow2ClusterType {
140
QCOW2_CLUSTER_UNALLOCATED,
141
QCOW2_CLUSTER_NORMAL,
142
QCOW2_CLUSTER_COMPRESSED,
143
QCOW2_CLUSTER_ZERO
144
-};
145
+} QCow2ClusterType;
146
147
typedef enum QCow2MetadataOverlap {
148
QCOW2_OL_MAIN_HEADER_BITNR = 0,
149
@@ -XXX,XX +XXX,XX @@ static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State *s)
150
return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
151
}
152
153
-static inline int qcow2_get_cluster_type(uint64_t l2_entry)
154
+static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
155
{
156
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
157
return QCOW2_CLUSTER_COMPRESSED;
158
--
159
1.8.3.1
160
161
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Treat plain zero clusters differently from allocated ones, so that
4
we can simplify the logic of checking whether an offset is present.
5
Do this by splitting QCOW2_CLUSTER_ZERO into two new enums,
6
QCOW2_CLUSTER_ZERO_PLAIN and QCOW2_CLUSTER_ZERO_ALLOC.
7
8
I tried to arrange the enum so that we could use
9
'ret <= QCOW2_CLUSTER_ZERO_PLAIN' for all unallocated types, and
10
'ret >= QCOW2_CLUSTER_ZERO_ALLOC' for allocated types, although
11
I didn't actually end up taking advantage of the layout.
12
13
In many cases, this leads to simpler code, by properly combining
14
cases (sometimes, both zero types pair together, other times,
15
plain zero is more like unallocated while allocated zero is more
16
like normal).
17
18
Signed-off-by: Eric Blake <eblake@redhat.com>
19
Message-id: 20170507000552.20847-7-eblake@redhat.com
20
Reviewed-by: Max Reitz <mreitz@redhat.com>
21
Signed-off-by: Max Reitz <mreitz@redhat.com>
22
---
23
block/qcow2-cluster.c | 79 ++++++++++++++++++----------------------------
24
block/qcow2-refcount.c | 44 +++++++++++---------------
25
block/qcow2.c | 9 ++++--
26
block/qcow2.h | 8 +++--
27
tests/qemu-iotests/060.out | 6 ++--
28
5 files changed, 63 insertions(+), 83 deletions(-)
29
30
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/block/qcow2-cluster.c
33
+++ b/block/qcow2-cluster.c
34
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters(int nb_clusters, int cluster_size,
35
/* must be allocated */
36
first_cluster_type = qcow2_get_cluster_type(first_entry);
37
assert(first_cluster_type == QCOW2_CLUSTER_NORMAL ||
38
- (first_cluster_type == QCOW2_CLUSTER_ZERO &&
39
- (first_entry & L2E_OFFSET_MASK) != 0));
40
+ first_cluster_type == QCOW2_CLUSTER_ZERO_ALLOC);
41
42
for (i = 0; i < nb_clusters; i++) {
43
uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask;
44
@@ -XXX,XX +XXX,XX @@ static int count_contiguous_clusters_unallocated(int nb_clusters,
45
{
46
int i;
47
48
- assert(wanted_type == QCOW2_CLUSTER_ZERO ||
49
+ assert(wanted_type == QCOW2_CLUSTER_ZERO_PLAIN ||
50
wanted_type == QCOW2_CLUSTER_UNALLOCATED);
51
for (i = 0; i < nb_clusters; i++) {
52
uint64_t entry = be64_to_cpu(l2_table[i]);
53
QCow2ClusterType type = qcow2_get_cluster_type(entry);
54
55
- if (type != wanted_type || entry & L2E_OFFSET_MASK) {
56
+ if (type != wanted_type) {
57
break;
58
}
59
}
60
@@ -XXX,XX +XXX,XX @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
61
assert(nb_clusters <= INT_MAX);
62
63
type = qcow2_get_cluster_type(*cluster_offset);
64
+ if (s->qcow_version < 3 && (type == QCOW2_CLUSTER_ZERO_PLAIN ||
65
+ type == QCOW2_CLUSTER_ZERO_ALLOC)) {
66
+ qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
67
+ " in pre-v3 image (L2 offset: %#" PRIx64
68
+ ", L2 index: %#x)", l2_offset, l2_index);
69
+ ret = -EIO;
70
+ goto fail;
71
+ }
72
switch (type) {
73
case QCOW2_CLUSTER_COMPRESSED:
74
/* Compressed clusters can only be processed one by one */
75
c = 1;
76
*cluster_offset &= L2E_COMPRESSED_OFFSET_SIZE_MASK;
77
break;
78
- case QCOW2_CLUSTER_ZERO:
79
- if (s->qcow_version < 3) {
80
- qcow2_signal_corruption(bs, true, -1, -1, "Zero cluster entry found"
81
- " in pre-v3 image (L2 offset: %#" PRIx64
82
- ", L2 index: %#x)", l2_offset, l2_index);
83
- ret = -EIO;
84
- goto fail;
85
- }
86
- /* Distinguish between pure zero clusters and pre-allocated ones */
87
- if (*cluster_offset & L2E_OFFSET_MASK) {
88
- c = count_contiguous_clusters(nb_clusters, s->cluster_size,
89
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
90
- *cluster_offset &= L2E_OFFSET_MASK;
91
- if (offset_into_cluster(s, *cluster_offset)) {
92
- qcow2_signal_corruption(bs, true, -1, -1,
93
- "Preallocated zero cluster offset %#"
94
- PRIx64 " unaligned (L2 offset: %#"
95
- PRIx64 ", L2 index: %#x)",
96
- *cluster_offset, l2_offset, l2_index);
97
- ret = -EIO;
98
- goto fail;
99
- }
100
- } else {
101
- c = count_contiguous_clusters_unallocated(nb_clusters,
102
- &l2_table[l2_index],
103
- QCOW2_CLUSTER_ZERO);
104
- *cluster_offset = 0;
105
- }
106
- break;
107
+ case QCOW2_CLUSTER_ZERO_PLAIN:
108
case QCOW2_CLUSTER_UNALLOCATED:
109
/* how many empty clusters ? */
110
c = count_contiguous_clusters_unallocated(nb_clusters,
111
- &l2_table[l2_index],
112
- QCOW2_CLUSTER_UNALLOCATED);
113
+ &l2_table[l2_index], type);
114
*cluster_offset = 0;
115
break;
116
+ case QCOW2_CLUSTER_ZERO_ALLOC:
117
case QCOW2_CLUSTER_NORMAL:
118
/* how many allocated clusters ? */
119
c = count_contiguous_clusters(nb_clusters, s->cluster_size,
120
- &l2_table[l2_index], QCOW_OFLAG_ZERO);
121
+ &l2_table[l2_index], QCOW_OFLAG_ZERO);
122
*cluster_offset &= L2E_OFFSET_MASK;
123
if (offset_into_cluster(s, *cluster_offset)) {
124
- qcow2_signal_corruption(bs, true, -1, -1, "Data cluster offset %#"
125
+ qcow2_signal_corruption(bs, true, -1, -1,
126
+ "Cluster allocation offset %#"
127
PRIx64 " unaligned (L2 offset: %#" PRIx64
128
", L2 index: %#x)", *cluster_offset,
129
l2_offset, l2_index);
130
@@ -XXX,XX +XXX,XX @@ static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
131
break;
132
case QCOW2_CLUSTER_UNALLOCATED:
133
case QCOW2_CLUSTER_COMPRESSED:
134
- case QCOW2_CLUSTER_ZERO:
135
+ case QCOW2_CLUSTER_ZERO_PLAIN:
136
+ case QCOW2_CLUSTER_ZERO_ALLOC:
137
break;
138
default:
139
abort();
140
@@ -XXX,XX +XXX,XX @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
141
* wrong with our code. */
142
assert(nb_clusters > 0);
143
144
- if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO &&
145
- (entry & L2E_OFFSET_MASK) != 0 && (entry & QCOW_OFLAG_COPIED) &&
146
+ if (qcow2_get_cluster_type(entry) == QCOW2_CLUSTER_ZERO_ALLOC &&
147
+ (entry & QCOW_OFLAG_COPIED) &&
148
(!*host_offset ||
149
start_of_cluster(s, *host_offset) == (entry & L2E_OFFSET_MASK)))
150
{
151
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
152
}
153
break;
154
155
- case QCOW2_CLUSTER_ZERO:
156
- /* Preallocated zero clusters should be discarded in any case */
157
- if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) {
158
+ case QCOW2_CLUSTER_ZERO_PLAIN:
159
+ if (!full_discard) {
160
continue;
161
}
162
break;
163
164
+ case QCOW2_CLUSTER_ZERO_ALLOC:
165
case QCOW2_CLUSTER_NORMAL:
166
case QCOW2_CLUSTER_COMPRESSED:
167
break;
168
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
169
uint64_t l2_entry = be64_to_cpu(l2_table[j]);
170
int64_t offset = l2_entry & L2E_OFFSET_MASK;
171
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
172
- bool preallocated = offset != 0;
173
174
- if (cluster_type != QCOW2_CLUSTER_ZERO) {
175
+ if (cluster_type != QCOW2_CLUSTER_ZERO_PLAIN &&
176
+ cluster_type != QCOW2_CLUSTER_ZERO_ALLOC) {
177
continue;
178
}
179
180
- if (!preallocated) {
181
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
182
if (!bs->backing) {
183
/* not backed; therefore we can simply deallocate the
184
* cluster */
185
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
186
"%#" PRIx64 " unaligned (L2 offset: %#"
187
PRIx64 ", L2 index: %#x)", offset,
188
l2_offset, j);
189
- if (!preallocated) {
190
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
191
qcow2_free_clusters(bs, offset, s->cluster_size,
192
QCOW2_DISCARD_ALWAYS);
193
}
194
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
195
196
ret = qcow2_pre_write_overlap_check(bs, 0, offset, s->cluster_size);
197
if (ret < 0) {
198
- if (!preallocated) {
199
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
200
qcow2_free_clusters(bs, offset, s->cluster_size,
201
QCOW2_DISCARD_ALWAYS);
202
}
203
@@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
204
205
ret = bdrv_pwrite_zeroes(bs->file, offset, s->cluster_size, 0);
206
if (ret < 0) {
207
- if (!preallocated) {
208
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
209
qcow2_free_clusters(bs, offset, s->cluster_size,
210
QCOW2_DISCARD_ALWAYS);
211
}
212
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
213
index XXXXXXX..XXXXXXX 100644
214
--- a/block/qcow2-refcount.c
215
+++ b/block/qcow2-refcount.c
216
@@ -XXX,XX +XXX,XX @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
217
}
218
break;
219
case QCOW2_CLUSTER_NORMAL:
220
- case QCOW2_CLUSTER_ZERO:
221
- if (l2_entry & L2E_OFFSET_MASK) {
222
- if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
223
- qcow2_signal_corruption(bs, false, -1, -1,
224
- "Cannot free unaligned cluster %#llx",
225
- l2_entry & L2E_OFFSET_MASK);
226
- } else {
227
- qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
228
- nb_clusters << s->cluster_bits, type);
229
- }
230
+ case QCOW2_CLUSTER_ZERO_ALLOC:
231
+ if (offset_into_cluster(s, l2_entry & L2E_OFFSET_MASK)) {
232
+ qcow2_signal_corruption(bs, false, -1, -1,
233
+ "Cannot free unaligned cluster %#llx",
234
+ l2_entry & L2E_OFFSET_MASK);
235
+ } else {
236
+ qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
237
+ nb_clusters << s->cluster_bits, type);
238
}
239
break;
240
+ case QCOW2_CLUSTER_ZERO_PLAIN:
241
case QCOW2_CLUSTER_UNALLOCATED:
242
break;
243
default:
244
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
245
break;
246
247
case QCOW2_CLUSTER_NORMAL:
248
- case QCOW2_CLUSTER_ZERO:
249
+ case QCOW2_CLUSTER_ZERO_ALLOC:
250
if (offset_into_cluster(s, offset)) {
251
- qcow2_signal_corruption(bs, true, -1, -1, "Data "
252
- "cluster offset %#" PRIx64
253
+ qcow2_signal_corruption(bs, true, -1, -1, "Cluster "
254
+ "allocation offset %#" PRIx64
255
" unaligned (L2 offset: %#"
256
PRIx64 ", L2 index: %#x)",
257
offset, l2_offset, j);
258
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
259
}
260
261
cluster_index = offset >> s->cluster_bits;
262
- if (!cluster_index) {
263
- /* unallocated */
264
- refcount = 0;
265
- break;
266
- }
267
+ assert(cluster_index);
268
if (addend != 0) {
269
ret = qcow2_update_cluster_refcount(bs,
270
cluster_index, abs(addend), addend < 0,
271
@@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
272
}
273
break;
274
275
+ case QCOW2_CLUSTER_ZERO_PLAIN:
276
case QCOW2_CLUSTER_UNALLOCATED:
277
refcount = 0;
278
break;
279
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
280
}
281
break;
282
283
- case QCOW2_CLUSTER_ZERO:
284
- if ((l2_entry & L2E_OFFSET_MASK) == 0) {
285
- break;
286
- }
287
- /* fall through */
288
-
289
+ case QCOW2_CLUSTER_ZERO_ALLOC:
290
case QCOW2_CLUSTER_NORMAL:
291
{
292
uint64_t offset = l2_entry & L2E_OFFSET_MASK;
293
@@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
294
break;
295
}
296
297
+ case QCOW2_CLUSTER_ZERO_PLAIN:
298
case QCOW2_CLUSTER_UNALLOCATED:
299
break;
300
301
@@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
302
uint64_t data_offset = l2_entry & L2E_OFFSET_MASK;
303
QCow2ClusterType cluster_type = qcow2_get_cluster_type(l2_entry);
304
305
- if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
306
- ((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
307
+ if (cluster_type == QCOW2_CLUSTER_NORMAL ||
308
+ cluster_type == QCOW2_CLUSTER_ZERO_ALLOC) {
309
ret = qcow2_get_refcount(bs,
310
data_offset >> s->cluster_bits,
311
&refcount);
312
diff --git a/block/qcow2.c b/block/qcow2.c
313
index XXXXXXX..XXXXXXX 100644
314
--- a/block/qcow2.c
315
+++ b/block/qcow2.c
316
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs,
317
*file = bs->file->bs;
318
status |= BDRV_BLOCK_OFFSET_VALID | cluster_offset;
319
}
320
- if (ret == QCOW2_CLUSTER_ZERO) {
321
+ if (ret == QCOW2_CLUSTER_ZERO_PLAIN || ret == QCOW2_CLUSTER_ZERO_ALLOC) {
322
status |= BDRV_BLOCK_ZERO;
323
} else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
324
status |= BDRV_BLOCK_DATA;
325
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset,
326
}
327
break;
328
329
- case QCOW2_CLUSTER_ZERO:
330
+ case QCOW2_CLUSTER_ZERO_PLAIN:
331
+ case QCOW2_CLUSTER_ZERO_ALLOC:
332
qemu_iovec_memset(&hd_qiov, 0, 0, cur_bytes);
333
break;
334
335
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
336
count = s->cluster_size;
337
nr = s->cluster_size;
338
ret = qcow2_get_cluster_offset(bs, offset, &nr, &off);
339
- if (ret != QCOW2_CLUSTER_UNALLOCATED && ret != QCOW2_CLUSTER_ZERO) {
340
+ if (ret != QCOW2_CLUSTER_UNALLOCATED &&
341
+ ret != QCOW2_CLUSTER_ZERO_PLAIN &&
342
+ ret != QCOW2_CLUSTER_ZERO_ALLOC) {
343
qemu_co_mutex_unlock(&s->lock);
344
return -ENOTSUP;
345
}
346
diff --git a/block/qcow2.h b/block/qcow2.h
347
index XXXXXXX..XXXXXXX 100644
348
--- a/block/qcow2.h
349
+++ b/block/qcow2.h
350
@@ -XXX,XX +XXX,XX @@ typedef struct QCowL2Meta
351
352
typedef enum QCow2ClusterType {
353
QCOW2_CLUSTER_UNALLOCATED,
354
+ QCOW2_CLUSTER_ZERO_PLAIN,
355
+ QCOW2_CLUSTER_ZERO_ALLOC,
356
QCOW2_CLUSTER_NORMAL,
357
QCOW2_CLUSTER_COMPRESSED,
358
- QCOW2_CLUSTER_ZERO
359
} QCow2ClusterType;
360
361
typedef enum QCow2MetadataOverlap {
362
@@ -XXX,XX +XXX,XX @@ static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry)
363
if (l2_entry & QCOW_OFLAG_COMPRESSED) {
364
return QCOW2_CLUSTER_COMPRESSED;
365
} else if (l2_entry & QCOW_OFLAG_ZERO) {
366
- return QCOW2_CLUSTER_ZERO;
367
+ if (l2_entry & L2E_OFFSET_MASK) {
368
+ return QCOW2_CLUSTER_ZERO_ALLOC;
369
+ }
370
+ return QCOW2_CLUSTER_ZERO_PLAIN;
371
} else if (!(l2_entry & L2E_OFFSET_MASK)) {
372
return QCOW2_CLUSTER_UNALLOCATED;
373
} else {
374
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
375
index XXXXXXX..XXXXXXX 100644
376
--- a/tests/qemu-iotests/060.out
377
+++ b/tests/qemu-iotests/060.out
378
@@ -XXX,XX +XXX,XX @@ qemu-img: Error while amending options: Input/output error
379
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
380
wrote 65536/65536 bytes at offset 0
381
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
382
-qcow2: Marking image as corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
383
+qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
384
read failed: Input/output error
385
386
=== Testing unaligned pre-allocated zero cluster ===
387
@@ -XXX,XX +XXX,XX @@ discard 65536/65536 bytes at offset 0
388
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
389
wrote 65536/65536 bytes at offset 0
390
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
391
-qcow2: Image is corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
392
+qcow2: Image is corrupt: Cluster allocation offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
393
read failed: Input/output error
394
read failed: Input/output error
395
396
@@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
397
wrote 131072/131072 bytes at offset 0
398
128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
399
qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further non-fatal corruption events will be suppressed
400
-qcow2: Marking image as corrupt: Data cluster offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
401
+qcow2: Marking image as corrupt: Cluster allocation offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
402
discard 65536/65536 bytes at offset 0
403
64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
404
read failed: Input/output error
405
--
406
1.8.3.1
407
408
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Similar to discard_single_l2(), we should try to avoid dirtying
4
the L2 cache when the cluster we are changing already has the
5
right characteristics.
6
7
Note that by the time we get to zero_single_l2(), BDRV_REQ_MAY_UNMAP
8
is a requirement to unallocate a cluster (this is because the block
9
layer clears that flag if discard.* flags during open requested that
10
we never punch holes - see the conversation around commit 170f4b2e,
11
https://lists.gnu.org/archive/html/qemu-devel/2016-09/msg07306.html).
12
Therefore, this patch can only reuse a zero cluster as-is if either
13
unmapping is not requested, or if the zero cluster was not associated
14
with an allocation.
15
16
Technically, there are some cases where an unallocated cluster
17
already reads as all zeroes (namely, when there is no backing file
18
[easy: check bs->backing], or when the backing file also reads as
19
zeroes [harder: we can't check bdrv_get_block_status since we are
20
already holding the lock]), where the guest would not immediately see
21
a difference if we left that cluster unallocated. But if the user
22
did not request unmapping, leaving an unallocated cluster is wrong;
23
and even if the user DID request unmapping, keeping a cluster
24
unallocated risks a subtle semantic change of guest-visible contents
25
if a backing file is later added, and it is not worth auditing
26
whether all internal uses such as mirror properly avoid an unmap
27
request. Thus, this patch is intentionally limited to just clusters
28
that are already marked as zero.
29
30
Signed-off-by: Eric Blake <eblake@redhat.com>
31
Reviewed-by: Max Reitz <mreitz@redhat.com>
32
Message-id: 20170507000552.20847-8-eblake@redhat.com
33
Signed-off-by: Max Reitz <mreitz@redhat.com>
34
---
35
block/qcow2-cluster.c | 15 +++++++++++++--
36
1 file changed, 13 insertions(+), 2 deletions(-)
37
38
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/block/qcow2-cluster.c
41
+++ b/block/qcow2-cluster.c
42
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
43
int l2_index;
44
int ret;
45
int i;
46
+ bool unmap = !!(flags & BDRV_REQ_MAY_UNMAP);
47
48
ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
49
if (ret < 0) {
50
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
51
52
for (i = 0; i < nb_clusters; i++) {
53
uint64_t old_offset;
54
+ QCow2ClusterType cluster_type;
55
56
old_offset = be64_to_cpu(l2_table[l2_index + i]);
57
58
- /* Update L2 entries */
59
+ /*
60
+ * Minimize L2 changes if the cluster already reads back as
61
+ * zeroes with correct allocation.
62
+ */
63
+ cluster_type = qcow2_get_cluster_type(old_offset);
64
+ if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN ||
65
+ (cluster_type == QCOW2_CLUSTER_ZERO_ALLOC && !unmap)) {
66
+ continue;
67
+ }
68
+
69
qcow2_cache_entry_mark_dirty(bs, s->l2_table_cache, l2_table);
70
- if (old_offset & QCOW_OFLAG_COMPRESSED || flags & BDRV_REQ_MAY_UNMAP) {
71
+ if (cluster_type == QCOW2_CLUSTER_COMPRESSED || unmap) {
72
l2_table[l2_index + i] = cpu_to_be64(QCOW_OFLAG_ZERO);
73
qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);
74
} else {
75
--
76
1.8.3.1
77
78
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
No tests were covering write zeroes with unmap. Additionally,
4
I needed to prove that my previous patches for correct status
5
reporting and write zeroes optimizations actually had an impact.
6
7
The test works for cluster_size between 8k and 2M (for smaller
8
sizes, it fails because our allocation patterns are not contiguous
9
with small clusters - in part, the largest consecutive allocation
10
we tend to get is often bounded by the size covered by one L2
11
table).
12
13
Note that testing for zero clusters is tricky: 'qemu-io map'
14
reports whether data comes from the current layer of the image
15
(useful for sniffing out which regions of the file have
16
QCOW_OFLAG_ZERO) - but doesn't show which clusters have mappings;
17
while 'qemu-img map' sees "zero":true for both unallocated and
18
zero clusters for any qcow2 with no backing layer (so less useful
19
at detecting true zero clusters), but reliably shows mappings.
20
So we have to rely on both queries side-by-side at each point of
21
the test.
22
23
Signed-off-by: Eric Blake <eblake@redhat.com>
24
Reviewed-by: Max Reitz <mreitz@redhat.com>
25
Message-id: 20170507000552.20847-10-eblake@redhat.com
26
Signed-off-by: Max Reitz <mreitz@redhat.com>
27
---
28
tests/qemu-iotests/179 | 130 +++++++++++++++++++++++++++++++++++++
29
tests/qemu-iotests/179.out | 156 +++++++++++++++++++++++++++++++++++++++++++++
30
tests/qemu-iotests/group | 1 +
31
3 files changed, 287 insertions(+)
32
create mode 100755 tests/qemu-iotests/179
33
create mode 100644 tests/qemu-iotests/179.out
34
35
diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179
36
new file mode 100755
37
index XXXXXXX..XXXXXXX
38
--- /dev/null
39
+++ b/tests/qemu-iotests/179
40
@@ -XXX,XX +XXX,XX @@
41
+#!/bin/bash
42
+#
43
+# Test case for write zeroes with unmap
44
+#
45
+# Copyright (C) 2017 Red Hat, Inc.
46
+#
47
+# This program is free software; you can redistribute it and/or modify
48
+# it under the terms of the GNU General Public License as published by
49
+# the Free Software Foundation; either version 2 of the License, or
50
+# (at your option) any later version.
51
+#
52
+# This program is distributed in the hope that it will be useful,
53
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
54
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
+# GNU General Public License for more details.
56
+#
57
+# You should have received a copy of the GNU General Public License
58
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
59
+#
60
+
61
+# creator
62
+owner=eblake@redhat.com
63
+
64
+seq="$(basename $0)"
65
+echo "QA output created by $seq"
66
+
67
+here="$PWD"
68
+status=1    # failure is the default!
69
+
70
+_cleanup()
71
+{
72
+    _cleanup_test_img
73
+}
74
+trap "_cleanup; exit \$status" 0 1 2 3 15
75
+
76
+# get standard environment, filters and checks
77
+. ./common.rc
78
+. ./common.filter
79
+
80
+_supported_fmt qcow2
81
+_supported_proto file
82
+_supported_os Linux
83
+
84
+# v2 images can't mark clusters as zero
85
+_unsupported_imgopts compat=0.10
86
+
87
+echo
88
+echo '=== Testing write zeroes with unmap ==='
89
+echo
90
+
91
+TEST_IMG="$TEST_IMG.base" _make_test_img 64M
92
+_make_test_img -b "$TEST_IMG.base"
93
+
94
+# Offsets chosen at or near 2M boundaries so test works at all cluster sizes
95
+# 8k and larger (smaller clusters fail due to non-contiguous allocations)
96
+
97
+# Aligned writes to unallocated cluster should not allocate mapping, but must
98
+# mark cluster as zero, whether or not unmap was requested
99
+$QEMU_IO -c "write -z -u 2M 2M" "$TEST_IMG.base" | _filter_qemu_io
100
+$QEMU_IO -c "write -z 6M 2M" "$TEST_IMG.base" | _filter_qemu_io
101
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
102
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
103
+
104
+# Unaligned writes need not allocate mapping if the cluster already reads
105
+# as zero, but must mark cluster as zero, whether or not unmap was requested
106
+$QEMU_IO -c "write -z -u 10485761 2097150" "$TEST_IMG.base" | _filter_qemu_io
107
+$QEMU_IO -c "write -z 14680065 2097150" "$TEST_IMG.base" | _filter_qemu_io
108
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
109
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
110
+
111
+# Requesting unmap of normal data must deallocate; omitting unmap should
112
+# preserve the mapping
113
+$QEMU_IO -c "write 18M 14M" "$TEST_IMG.base" | _filter_qemu_io
114
+$QEMU_IO -c "write -z -u 20M 2M" "$TEST_IMG.base" | _filter_qemu_io
115
+$QEMU_IO -c "write -z 24M 6M" "$TEST_IMG.base" | _filter_qemu_io
116
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
117
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
118
+
119
+# Likewise when writing on already-mapped zero data
120
+$QEMU_IO -c "write -z -u 26M 2M" "$TEST_IMG.base" | _filter_qemu_io
121
+$QEMU_IO -c "write -z 28M 2M" "$TEST_IMG.base" | _filter_qemu_io
122
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
123
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
124
+
125
+# Writing on unmapped zeroes does not allocate
126
+$QEMU_IO -c "write -z 32M 8M" "$TEST_IMG.base" | _filter_qemu_io
127
+$QEMU_IO -c "write -z -u 34M 2M" "$TEST_IMG.base" | _filter_qemu_io
128
+$QEMU_IO -c "write -z 36M 2M" "$TEST_IMG.base" | _filter_qemu_io
129
+$QEMU_IO -c "map" "$TEST_IMG.base" | _filter_qemu_io
130
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
131
+
132
+# Writing zero overrides a backing file, regardless of backing cluster type
133
+$QEMU_IO -c "write -z 40M 8M" "$TEST_IMG.base" | _filter_qemu_io
134
+$QEMU_IO -c "write 48M 8M" "$TEST_IMG.base" | _filter_qemu_io
135
+$QEMU_IO -c "write -z -u 42M 2M" "$TEST_IMG" | _filter_qemu_io
136
+$QEMU_IO -c "write -z 44M 2M" "$TEST_IMG" | _filter_qemu_io
137
+$QEMU_IO -c "write -z -u 50M 2M" "$TEST_IMG" | _filter_qemu_io
138
+$QEMU_IO -c "write -z 52M 2M" "$TEST_IMG" | _filter_qemu_io
139
+$QEMU_IO -c "write -z -u 58M 2M" "$TEST_IMG" | _filter_qemu_io
140
+$QEMU_IO -c "write -z 60M 2M" "$TEST_IMG" | _filter_qemu_io
141
+$QEMU_IO -c "map" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
143
+
144
+# Final check that mappings are correct and images are still sane
145
+TEST_IMG="$TEST_IMG.base" _check_test_img
146
+_check_test_img
147
+
148
+echo
149
+echo '=== Testing cache optimization ==='
150
+echo
151
+
152
+BLKDBG_TEST_IMG="blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG.base"
153
+
154
+cat > "$TEST_DIR/blkdebug.conf" <<EOF
155
+[inject-error]
156
+event = "l2_update"
157
+errno = "5"
158
+immediately = "on"
159
+once = "off"
160
+EOF
161
+
162
+# None of the following writes should trigger an L2 update, because the
163
+# cluster already reads as zero, and we don't have to change allocation
164
+$QEMU_IO -c "w -z -u 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
165
+$QEMU_IO -c "w -z 20M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
166
+$QEMU_IO -c "w -z 28M 2M" "$BLKDBG_TEST_IMG" | _filter_qemu_io
167
+
168
+# success, all done
169
+echo '*** done'
170
+status=0
171
diff --git a/tests/qemu-iotests/179.out b/tests/qemu-iotests/179.out
172
new file mode 100644
173
index XXXXXXX..XXXXXXX
174
--- /dev/null
175
+++ b/tests/qemu-iotests/179.out
176
@@ -XXX,XX +XXX,XX @@
177
+QA output created by 179
178
+
179
+=== Testing write zeroes with unmap ===
180
+
181
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
182
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base
183
+wrote 2097152/2097152 bytes at offset 2097152
184
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
185
+wrote 2097152/2097152 bytes at offset 6291456
186
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
187
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
188
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
189
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
190
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
191
+56 MiB (0x3800000) bytes not allocated at offset 8 MiB (0x800000)
192
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
193
+wrote 2097150/2097150 bytes at offset 10485761
194
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
195
+wrote 2097150/2097150 bytes at offset 14680065
196
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
197
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
198
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
199
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
200
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
201
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
202
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
203
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
204
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
205
+48 MiB (0x3000000) bytes not allocated at offset 16 MiB (0x1000000)
206
+[{ "start": 0, "length": 67108864, "depth": 0, "zero": true, "data": false}]
207
+wrote 14680064/14680064 bytes at offset 18874368
208
+14 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
209
+wrote 2097152/2097152 bytes at offset 20971520
210
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
211
+wrote 6291456/6291456 bytes at offset 25165824
212
+6 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
213
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
214
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
215
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
216
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
217
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
218
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
219
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
220
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
221
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
222
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
223
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
224
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
225
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
226
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
227
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
228
+{ "start": 25165824, "length": 6291456, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
229
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
230
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
231
+wrote 2097152/2097152 bytes at offset 27262976
232
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
233
+wrote 2097152/2097152 bytes at offset 29360128
234
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
235
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
236
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
237
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
238
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
239
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
240
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
241
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
242
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
243
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
244
+14 MiB (0xe00000) bytes allocated at offset 18 MiB (0x1200000)
245
+32 MiB (0x2000000) bytes not allocated at offset 32 MiB (0x2000000)
246
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
247
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
248
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
249
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
250
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
251
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
252
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
253
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
254
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
255
+wrote 8388608/8388608 bytes at offset 33554432
256
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
257
+wrote 2097152/2097152 bytes at offset 35651584
258
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
259
+wrote 2097152/2097152 bytes at offset 37748736
260
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
261
+2 MiB (0x200000) bytes not allocated at offset 0 bytes (0x0)
262
+2 MiB (0x200000) bytes allocated at offset 2 MiB (0x200000)
263
+2 MiB (0x200000) bytes not allocated at offset 4 MiB (0x400000)
264
+2 MiB (0x200000) bytes allocated at offset 6 MiB (0x600000)
265
+2 MiB (0x200000) bytes not allocated at offset 8 MiB (0x800000)
266
+2 MiB (0x200000) bytes allocated at offset 10 MiB (0xa00000)
267
+2 MiB (0x200000) bytes not allocated at offset 12 MiB (0xc00000)
268
+2 MiB (0x200000) bytes allocated at offset 14 MiB (0xe00000)
269
+2 MiB (0x200000) bytes not allocated at offset 16 MiB (0x1000000)
270
+22 MiB (0x1600000) bytes allocated at offset 18 MiB (0x1200000)
271
+24 MiB (0x1800000) bytes not allocated at offset 40 MiB (0x2800000)
272
+[{ "start": 0, "length": 18874368, "depth": 0, "zero": true, "data": false},
273
+{ "start": 18874368, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
274
+{ "start": 20971520, "length": 2097152, "depth": 0, "zero": true, "data": false},
275
+{ "start": 23068672, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
276
+{ "start": 25165824, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
277
+{ "start": 27262976, "length": 2097152, "depth": 0, "zero": true, "data": false},
278
+{ "start": 29360128, "length": 2097152, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
279
+{ "start": 31457280, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
280
+{ "start": 33554432, "length": 33554432, "depth": 0, "zero": true, "data": false}]
281
+wrote 8388608/8388608 bytes at offset 41943040
282
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+wrote 8388608/8388608 bytes at offset 50331648
284
+8 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
285
+wrote 2097152/2097152 bytes at offset 44040192
286
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
287
+wrote 2097152/2097152 bytes at offset 46137344
288
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+wrote 2097152/2097152 bytes at offset 52428800
290
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
291
+wrote 2097152/2097152 bytes at offset 54525952
292
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
293
+wrote 2097152/2097152 bytes at offset 60817408
294
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+wrote 2097152/2097152 bytes at offset 62914560
296
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
297
+42 MiB (0x2a00000) bytes not allocated at offset 0 bytes (0x0)
298
+4 MiB (0x400000) bytes allocated at offset 42 MiB (0x2a00000)
299
+4 MiB (0x400000) bytes not allocated at offset 46 MiB (0x2e00000)
300
+4 MiB (0x400000) bytes allocated at offset 50 MiB (0x3200000)
301
+4 MiB (0x400000) bytes not allocated at offset 54 MiB (0x3600000)
302
+4 MiB (0x400000) bytes allocated at offset 58 MiB (0x3a00000)
303
+2 MiB (0x200000) bytes not allocated at offset 62 MiB (0x3e00000)
304
+[{ "start": 0, "length": 18874368, "depth": 1, "zero": true, "data": false},
305
+{ "start": 18874368, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
306
+{ "start": 20971520, "length": 2097152, "depth": 1, "zero": true, "data": false},
307
+{ "start": 23068672, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
308
+{ "start": 25165824, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
309
+{ "start": 27262976, "length": 2097152, "depth": 1, "zero": true, "data": false},
310
+{ "start": 29360128, "length": 2097152, "depth": 1, "zero": true, "data": false, "offset": OFFSET},
311
+{ "start": 31457280, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
312
+{ "start": 33554432, "length": 10485760, "depth": 1, "zero": true, "data": false},
313
+{ "start": 44040192, "length": 4194304, "depth": 0, "zero": true, "data": false},
314
+{ "start": 48234496, "length": 2097152, "depth": 1, "zero": true, "data": false},
315
+{ "start": 50331648, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
316
+{ "start": 52428800, "length": 4194304, "depth": 0, "zero": true, "data": false},
317
+{ "start": 56623104, "length": 2097152, "depth": 1, "zero": false, "data": true, "offset": OFFSET},
318
+{ "start": 58720256, "length": 2097152, "depth": 1, "zero": true, "data": false},
319
+{ "start": 60817408, "length": 4194304, "depth": 0, "zero": true, "data": false},
320
+{ "start": 65011712, "length": 2097152, "depth": 1, "zero": true, "data": false}]
321
+No errors were found on the image.
322
+No errors were found on the image.
323
+
324
+=== Testing cache optimization ===
325
+
326
+wrote 2097152/2097152 bytes at offset 20971520
327
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
328
+wrote 2097152/2097152 bytes at offset 20971520
329
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
330
+wrote 2097152/2097152 bytes at offset 29360128
331
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
332
+*** done
333
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
334
index XXXXXXX..XXXXXXX 100644
335
--- a/tests/qemu-iotests/group
336
+++ b/tests/qemu-iotests/group
337
@@ -XXX,XX +XXX,XX @@
338
175 auto quick
339
176 rw auto backing
340
177 rw auto quick
341
+179 rw auto quick
342
181 rw auto migration
343
182 rw auto quick
344
--
345
1.8.3.1
346
347
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We've already improved discards to operate efficiently on the tail
4
of an unaligned qcow2 image; it's time to make a similar improvement
5
to write zeroes. The special case is only valid at the tail
6
cluster of a file, where we must recognize that any sectors beyond
7
the image end would implicitly read as zero, and therefore should
8
not penalize our logic for widening a partial cluster into writing
9
the whole cluster as zero.
10
11
However, note that for now, the special case of end-of-file is only
12
recognized if there is no backing file, or if the backing file has
13
the same length; that's because when the backing file is shorter
14
than the active layer, we don't have code in place to recognize
15
that reads of a sector unallocated at the top and beyond the backing
16
end-of-file are implicitly zero. It's not much of a real loss,
17
because most people don't use images that aren't cluster-aligned,
18
or where the active layer is a different size than the backing
19
layer (especially where the difference falls within a single cluster).
20
21
Update test 154 to cover the new scenarios, using two images of
22
intentionally differing length.
23
24
While at it, fix the test to gracefully skip when run as
25
./check -qcow2 -o compat=0.10 154
26
since the older format lacks zero clusters already required earlier
27
in the test.
28
29
Signed-off-by: Eric Blake <eblake@redhat.com>
30
Reviewed-by: Max Reitz <mreitz@redhat.com>
31
Message-id: 20170507000552.20847-11-eblake@redhat.com
32
Signed-off-by: Max Reitz <mreitz@redhat.com>
33
---
34
block/qcow2.c | 7 ++
35
tests/qemu-iotests/154 | 160 ++++++++++++++++++++++++++++++++++++++++++++-
36
tests/qemu-iotests/154.out | 128 ++++++++++++++++++++++++++++++++++++
37
3 files changed, 293 insertions(+), 2 deletions(-)
38
39
diff --git a/block/qcow2.c b/block/qcow2.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/block/qcow2.c
42
+++ b/block/qcow2.c
43
@@ -XXX,XX +XXX,XX @@ static bool is_zero_sectors(BlockDriverState *bs, int64_t start,
44
BlockDriverState *file;
45
int64_t res;
46
47
+ if (start + count > bs->total_sectors) {
48
+ count = bs->total_sectors - start;
49
+ }
50
+
51
if (!count) {
52
return true;
53
}
54
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
55
uint32_t tail = (offset + count) % s->cluster_size;
56
57
trace_qcow2_pwrite_zeroes_start_req(qemu_coroutine_self(), offset, count);
58
+ if (offset + count == bs->total_sectors * BDRV_SECTOR_SIZE) {
59
+ tail = 0;
60
+ }
61
62
if (head || tail) {
63
int64_t cl_start = (offset - head) >> BDRV_SECTOR_BITS;
64
diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154
65
index XXXXXXX..XXXXXXX 100755
66
--- a/tests/qemu-iotests/154
67
+++ b/tests/qemu-iotests/154
68
@@ -XXX,XX +XXX,XX @@
69
#
70
# qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
71
#
72
-# Copyright (C) 2016 Red Hat, Inc.
73
+# Copyright (C) 2016-2017 Red Hat, Inc.
74
#
75
# This program is free software; you can redistribute it and/or modify
76
# it under the terms of the GNU General Public License as published by
77
@@ -XXX,XX +XXX,XX @@ _supported_proto file
78
_supported_os Linux
79
80
CLUSTER_SIZE=4k
81
-size=128M
82
+size=$((128 * 1024 * 1024))
83
+
84
+# This test requires zero clusters, added in v3 images
85
+_unsupported_imgopts compat=0.10
86
87
echo
88
echo == backing file contains zeros ==
89
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io
90
91
$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
92
93
+echo
94
+echo == unaligned image tail cluster, no allocation needed ==
95
+
96
+# With no backing file, write to all or part of unallocated partial cluster
97
+# will mark the cluster as zero, but does not allocate.
98
+# Re-create the image each time to get back to unallocated clusters.
99
+
100
+# Write at the front: sector-wise, the request is: 128m... | 00 -- -- --
101
+_make_test_img $((size + 2048))
102
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
103
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
104
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
105
+
106
+# Write at the back: sector-wise, the request is: 128m... | -- -- -- 00
107
+_make_test_img $((size + 2048))
108
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
109
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
110
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
111
+
112
+# Write at middle: sector-wise, the request is: 128m... | -- 00 00 --
113
+_make_test_img $((size + 2048))
114
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
115
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
116
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
117
+
118
+# Write entire cluster: sector-wise, the request is: 128m... | 00 00 00 00
119
+_make_test_img $((size + 2048))
120
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
121
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
122
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
123
+
124
+# Repeat with backing file holding unallocated cluster.
125
+# TODO: Note that this forces an allocation, because we aren't yet able to
126
+# quickly detect that reads beyond EOF of the backing file are always zero
127
+CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
128
+
129
+# Write at the front: sector-wise, the request is:
130
+# backing: 128m... | -- --
131
+# active: 128m... | 00 -- -- --
132
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
133
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
134
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
135
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
136
+
137
+# Write at the back: sector-wise, the request is:
138
+# backing: 128m... | -- --
139
+# active: 128m... | -- -- -- 00
140
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
141
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
142
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
143
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
144
+
145
+# Write at middle: sector-wise, the request is:
146
+# backing: 128m... | -- --
147
+# active: 128m... | -- 00 00 --
148
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
149
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
150
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
151
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
152
+
153
+# Write entire cluster: sector-wise, the request is:
154
+# backing: 128m... | -- --
155
+# active: 128m... | 00 00 00 00
156
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
157
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
158
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
159
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
160
+
161
+# Repeat with backing file holding zero'd cluster
162
+# TODO: Note that this forces an allocation, because we aren't yet able to
163
+# quickly detect that reads beyond EOF of the backing file are always zero
164
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io
165
+
166
+# Write at the front: sector-wise, the request is:
167
+# backing: 128m... | 00 00
168
+# active: 128m... | 00 -- -- --
169
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
170
+$QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
171
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
172
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
173
+
174
+# Write at the back: sector-wise, the request is:
175
+# backing: 128m... | 00 00
176
+# active: 128m... | -- -- -- 00
177
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
178
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
179
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
180
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
181
+
182
+# Write at middle: sector-wise, the request is:
183
+# backing: 128m... | 00 00
184
+# active: 128m... | -- 00 00 --
185
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
186
+$QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
187
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
188
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
189
+
190
+# Write entire cluster: sector-wise, the request is:
191
+# backing: 128m... | 00 00
192
+# active: 128m... | 00 00 00 00
193
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
194
+$QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
195
+$QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
196
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
197
+
198
+# A preallocated cluster maintains its allocation, whether it stays as
199
+# data due to a partial write:
200
+# Convert 128m... | XX XX => ... | XX 00
201
+_make_test_img $((size + 1024))
202
+$QEMU_IO -c "write -P 1 $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
203
+$QEMU_IO -c "write -z $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
204
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
205
+$QEMU_IO -c "read -P 0 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
206
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
207
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
208
+
209
+# or because it is the entire cluster and can use the zero flag:
210
+# Convert 128m... | XX XX => ... | 00 00
211
+$QEMU_IO -c "write -z $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
212
+$QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
213
+$QEMU_IO -c "read -P 0 $size 1024" "$TEST_IMG" | _filter_qemu_io
214
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
215
+
216
+echo
217
+echo == unaligned image tail cluster, allocation required ==
218
+
219
+# Write beyond backing file must COW
220
+# Backing file: 128m... | XX --
221
+# Active layer: 128m... | -- -- 00 --
222
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
223
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
224
+$QEMU_IO -c "write -P 1 $((size)) 512" "$TEST_IMG.base" | _filter_qemu_io
225
+$QEMU_IO -c "write -z $((size + 1024)) 512" "$TEST_IMG" | _filter_qemu_io
226
+$QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
227
+$QEMU_IO -c "read -P 0 $((size + 512)) 1536" "$TEST_IMG" | _filter_qemu_io
228
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
229
+
230
+# Writes at boundaries of (partial) cluster must not lose mid-cluster data
231
+# Backing file: 128m: ... | -- XX
232
+# Active layer: 128m: ... | 00 -- -- 00
233
+CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
234
+_make_test_img -b "$TEST_IMG.base" $((size + 2048))
235
+$QEMU_IO -c "write -P 1 $((size + 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
236
+$QEMU_IO -c "write -z $((size)) 512" "$TEST_IMG" | _filter_qemu_io
237
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
238
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
239
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
240
+$QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
241
+$QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
242
+$QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
243
+$QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
244
+$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
245
+
246
# success, all done
247
echo "*** done"
248
rm -f $seq.full
249
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
250
index XXXXXXX..XXXXXXX 100644
251
--- a/tests/qemu-iotests/154.out
252
+++ b/tests/qemu-iotests/154.out
253
@@ -XXX,XX +XXX,XX @@ read 1024/1024 bytes at offset 76800
254
{ "start": 69632, "length": 4096, "depth": 0, "zero": true, "data": false},
255
{ "start": 73728, "length": 4096, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
256
{ "start": 77824, "length": 134139904, "depth": 1, "zero": true, "data": false}]
257
+
258
+== unaligned image tail cluster, no allocation needed ==
259
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
260
+wrote 512/512 bytes at offset 134217728
261
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
262
+2048/2048 bytes allocated at offset 128 MiB
263
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
264
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
265
+wrote 512/512 bytes at offset 134219264
266
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
267
+2048/2048 bytes allocated at offset 128 MiB
268
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
269
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
270
+wrote 1024/1024 bytes at offset 134218240
271
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
272
+2048/2048 bytes allocated at offset 128 MiB
273
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
274
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776
275
+wrote 2048/2048 bytes at offset 134217728
276
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
277
+2048/2048 bytes allocated at offset 128 MiB
278
+[{ "start": 0, "length": 134219776, "depth": 0, "zero": true, "data": false}]
279
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
280
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
281
+wrote 512/512 bytes at offset 134217728
282
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
283
+2048/2048 bytes allocated at offset 128 MiB
284
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
285
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
286
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
287
+wrote 512/512 bytes at offset 134219264
288
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
289
+2048/2048 bytes allocated at offset 128 MiB
290
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
291
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
292
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
293
+wrote 1024/1024 bytes at offset 134218240
294
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
295
+2048/2048 bytes allocated at offset 128 MiB
296
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
297
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
298
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
299
+wrote 2048/2048 bytes at offset 134217728
300
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
301
+2048/2048 bytes allocated at offset 128 MiB
302
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
303
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
304
+wrote 512/512 bytes at offset 134217728
305
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
306
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
307
+wrote 512/512 bytes at offset 134217728
308
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
309
+2048/2048 bytes allocated at offset 128 MiB
310
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
311
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
312
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
313
+wrote 512/512 bytes at offset 134219264
314
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
315
+2048/2048 bytes allocated at offset 128 MiB
316
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
317
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
318
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
319
+wrote 1024/1024 bytes at offset 134218240
320
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
321
+2048/2048 bytes allocated at offset 128 MiB
322
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
323
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
324
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
325
+wrote 2048/2048 bytes at offset 134217728
326
+2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
327
+2048/2048 bytes allocated at offset 128 MiB
328
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
329
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
330
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134218752
331
+wrote 1024/1024 bytes at offset 134217728
332
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
333
+wrote 512/512 bytes at offset 134218240
334
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
335
+read 512/512 bytes at offset 134217728
336
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
337
+read 512/512 bytes at offset 134218240
338
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
339
+1024/1024 bytes allocated at offset 128 MiB
340
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
341
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
342
+wrote 1024/1024 bytes at offset 134217728
343
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
344
+1024/1024 bytes allocated at offset 128 MiB
345
+read 1024/1024 bytes at offset 134217728
346
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
347
+[{ "start": 0, "length": 134217728, "depth": 0, "zero": true, "data": false},
348
+{ "start": 134217728, "length": 1024, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
349
+
350
+== unaligned image tail cluster, allocation required ==
351
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
352
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
353
+wrote 512/512 bytes at offset 134217728
354
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
355
+wrote 512/512 bytes at offset 134218752
356
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357
+read 512/512 bytes at offset 134217728
358
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
359
+read 1536/1536 bytes at offset 134218240
360
+1.500 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
361
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
362
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
363
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=134218752
364
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
365
+wrote 512/512 bytes at offset 134218240
366
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
367
+wrote 512/512 bytes at offset 134217728
368
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
369
+read 512/512 bytes at offset 134217728
370
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
371
+read 512/512 bytes at offset 134218240
372
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
373
+read 1024/1024 bytes at offset 134218752
374
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
375
+wrote 512/512 bytes at offset 134219264
376
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
377
+read 512/512 bytes at offset 134217728
378
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
379
+read 512/512 bytes at offset 134218240
380
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
381
+read 1024/1024 bytes at offset 134218752
382
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
383
+[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
384
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
385
*** done
386
--
387
1.8.3.1
388
389
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
We already audited (in commit 0c1bd469) that qcow2_discard_clusters()
4
is only passed cluster-aligned start values; but we can further
5
tighten the assertion that the only unaligned end value is at EOF.
6
7
Recent commits have taken advantage of an unaligned tail cluster,
8
for both discard and write zeroes.
9
10
Signed-off-by: Eric Blake <eblake@redhat.com>
11
Reviewed-by: Max Reitz <mreitz@redhat.com>
12
Message-id: 20170507000552.20847-12-eblake@redhat.com
13
Signed-off-by: Max Reitz <mreitz@redhat.com>
14
---
15
block/qcow2-cluster.c | 15 +++++++++++----
16
1 file changed, 11 insertions(+), 4 deletions(-)
17
18
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/block/qcow2-cluster.c
21
+++ b/block/qcow2-cluster.c
22
@@ -XXX,XX +XXX,XX @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
23
24
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
25
26
- /* The caller must cluster-align start; round end down except at EOF */
27
+ /* Caller must pass aligned values, except at image end */
28
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
29
- if (end_offset != bs->total_sectors * BDRV_SECTOR_SIZE) {
30
- end_offset = start_of_cluster(s, end_offset);
31
- }
32
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
33
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
34
35
nb_clusters = size_to_clusters(s, end_offset - offset);
36
37
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
38
int flags)
39
{
40
BDRVQcow2State *s = bs->opaque;
41
+ uint64_t end_offset;
42
uint64_t nb_clusters;
43
int ret;
44
45
+ end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
46
+
47
+ /* Caller must pass aligned values, except at image end */
48
+ assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
49
+ assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
50
+ end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
51
+
52
/* The zero flag is only supported by version 3 and newer */
53
if (s->qcow_version < 3) {
54
return -ENOTSUP;
55
--
56
1.8.3.1
57
58
diff view generated by jsdifflib
Deleted patch
1
From: Eric Blake <eblake@redhat.com>
2
1
3
Passing a byte offset, but sector count, when we ultimately
4
want to operate on cluster granularity, is madness. Clean up
5
the external interfaces to take both offset and count as bytes,
6
while still keeping the assertion added previously that the
7
caller must align the values to a cluster. Then rename things
8
to make sure backports don't get confused by changed units:
9
instead of qcow2_discard_clusters() and qcow2_zero_clusters(),
10
we now have qcow2_cluster_discard() and qcow2_cluster_zeroize().
11
12
The internal functions still operate on clusters at a time, and
13
return an int for number of cleared clusters; but on an image
14
with 2M clusters, a single L2 table holds 256k entries that each
15
represent a 2M cluster, totalling well over INT_MAX bytes if we
16
ever had a request for that many bytes at once. All our callers
17
currently limit themselves to 32-bit bytes (and therefore fewer
18
clusters), but by making this function 64-bit clean, we have one
19
less place to clean up if we later improve the block layer to
20
support 64-bit bytes through all operations (with the block layer
21
auto-fragmenting on behalf of more-limited drivers), rather than
22
the current state where some interfaces are artificially limited
23
to INT_MAX at a time.
24
25
Signed-off-by: Eric Blake <eblake@redhat.com>
26
Reviewed-by: Max Reitz <mreitz@redhat.com>
27
Message-id: 20170507000552.20847-13-eblake@redhat.com
28
Signed-off-by: Max Reitz <mreitz@redhat.com>
29
---
30
block/qcow2-cluster.c | 42 ++++++++++++++++++++++--------------------
31
block/qcow2-snapshot.c | 7 +++----
32
block/qcow2.c | 22 +++++++++-------------
33
block/qcow2.h | 9 +++++----
34
4 files changed, 39 insertions(+), 41 deletions(-)
35
36
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/block/qcow2-cluster.c
39
+++ b/block/qcow2-cluster.c
40
@@ -XXX,XX +XXX,XX @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
41
return nb_clusters;
42
}
43
44
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
45
- int nb_sectors, enum qcow2_discard_type type, bool full_discard)
46
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
47
+ uint64_t bytes, enum qcow2_discard_type type,
48
+ bool full_discard)
49
{
50
BDRVQcow2State *s = bs->opaque;
51
- uint64_t end_offset;
52
+ uint64_t end_offset = offset + bytes;
53
uint64_t nb_clusters;
54
+ int64_t cleared;
55
int ret;
56
57
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
58
-
59
/* Caller must pass aligned values, except at image end */
60
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
61
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
62
end_offset == bs->total_sectors << BDRV_SECTOR_BITS);
63
64
- nb_clusters = size_to_clusters(s, end_offset - offset);
65
+ nb_clusters = size_to_clusters(s, bytes);
66
67
s->cache_discards = true;
68
69
/* Each L2 table is handled by its own loop iteration */
70
while (nb_clusters > 0) {
71
- ret = discard_single_l2(bs, offset, nb_clusters, type, full_discard);
72
- if (ret < 0) {
73
+ cleared = discard_single_l2(bs, offset, nb_clusters, type,
74
+ full_discard);
75
+ if (cleared < 0) {
76
+ ret = cleared;
77
goto fail;
78
}
79
80
- nb_clusters -= ret;
81
- offset += (ret * s->cluster_size);
82
+ nb_clusters -= cleared;
83
+ offset += (cleared * s->cluster_size);
84
}
85
86
ret = 0;
87
@@ -XXX,XX +XXX,XX @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
88
return nb_clusters;
89
}
90
91
-int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
92
- int flags)
93
+int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
94
+ uint64_t bytes, int flags)
95
{
96
BDRVQcow2State *s = bs->opaque;
97
- uint64_t end_offset;
98
+ uint64_t end_offset = offset + bytes;
99
uint64_t nb_clusters;
100
+ int64_t cleared;
101
int ret;
102
103
- end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
104
-
105
/* Caller must pass aligned values, except at image end */
106
assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
107
assert(QEMU_IS_ALIGNED(end_offset, s->cluster_size) ||
108
@@ -XXX,XX +XXX,XX @@ int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
109
}
110
111
/* Each L2 table is handled by its own loop iteration */
112
- nb_clusters = size_to_clusters(s, nb_sectors << BDRV_SECTOR_BITS);
113
+ nb_clusters = size_to_clusters(s, bytes);
114
115
s->cache_discards = true;
116
117
while (nb_clusters > 0) {
118
- ret = zero_single_l2(bs, offset, nb_clusters, flags);
119
- if (ret < 0) {
120
+ cleared = zero_single_l2(bs, offset, nb_clusters, flags);
121
+ if (cleared < 0) {
122
+ ret = cleared;
123
goto fail;
124
}
125
126
- nb_clusters -= ret;
127
- offset += (ret * s->cluster_size);
128
+ nb_clusters -= cleared;
129
+ offset += (cleared * s->cluster_size);
130
}
131
132
ret = 0;
133
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
134
index XXXXXXX..XXXXXXX 100644
135
--- a/block/qcow2-snapshot.c
136
+++ b/block/qcow2-snapshot.c
137
@@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
138
139
/* The VM state isn't needed any more in the active L1 table; in fact, it
140
* hurts by causing expensive COW for the next snapshot. */
141
- qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),
142
- align_offset(sn->vm_state_size, s->cluster_size)
143
- >> BDRV_SECTOR_BITS,
144
- QCOW2_DISCARD_NEVER, false);
145
+ qcow2_cluster_discard(bs, qcow2_vm_state_offset(s),
146
+ align_offset(sn->vm_state_size, s->cluster_size),
147
+ QCOW2_DISCARD_NEVER, false);
148
149
#ifdef DEBUG_ALLOC
150
{
151
diff --git a/block/qcow2.c b/block/qcow2.c
152
index XXXXXXX..XXXXXXX 100644
153
--- a/block/qcow2.c
154
+++ b/block/qcow2.c
155
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs,
156
trace_qcow2_pwrite_zeroes(qemu_coroutine_self(), offset, count);
157
158
/* Whatever is left can use real zero clusters */
159
- ret = qcow2_zero_clusters(bs, offset, count >> BDRV_SECTOR_BITS, flags);
160
+ ret = qcow2_cluster_zeroize(bs, offset, count, flags);
161
qemu_co_mutex_unlock(&s->lock);
162
163
return ret;
164
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
165
}
166
167
qemu_co_mutex_lock(&s->lock);
168
- ret = qcow2_discard_clusters(bs, offset, count >> BDRV_SECTOR_BITS,
169
- QCOW2_DISCARD_REQUEST, false);
170
+ ret = qcow2_cluster_discard(bs, offset, count, QCOW2_DISCARD_REQUEST,
171
+ false);
172
qemu_co_mutex_unlock(&s->lock);
173
return ret;
174
}
175
@@ -XXX,XX +XXX,XX @@ fail:
176
static int qcow2_make_empty(BlockDriverState *bs)
177
{
178
BDRVQcow2State *s = bs->opaque;
179
- uint64_t start_sector;
180
- int sector_step = (QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size) /
181
- BDRV_SECTOR_SIZE);
182
+ uint64_t offset, end_offset;
183
+ int step = QEMU_ALIGN_DOWN(INT_MAX, s->cluster_size);
184
int l1_clusters, ret = 0;
185
186
l1_clusters = DIV_ROUND_UP(s->l1_size, s->cluster_size / sizeof(uint64_t));
187
@@ -XXX,XX +XXX,XX @@ static int qcow2_make_empty(BlockDriverState *bs)
188
189
/* This fallback code simply discards every active cluster; this is slow,
190
* but works in all cases */
191
- for (start_sector = 0; start_sector < bs->total_sectors;
192
- start_sector += sector_step)
193
- {
194
+ end_offset = bs->total_sectors * BDRV_SECTOR_SIZE;
195
+ for (offset = 0; offset < end_offset; offset += step) {
196
/* As this function is generally used after committing an external
197
* snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
198
* default action for this kind of discard is to pass the discard,
199
* which will ideally result in an actually smaller image file, as
200
* is probably desired. */
201
- ret = qcow2_discard_clusters(bs, start_sector * BDRV_SECTOR_SIZE,
202
- MIN(sector_step,
203
- bs->total_sectors - start_sector),
204
- QCOW2_DISCARD_SNAPSHOT, true);
205
+ ret = qcow2_cluster_discard(bs, offset, MIN(step, end_offset - offset),
206
+ QCOW2_DISCARD_SNAPSHOT, true);
207
if (ret < 0) {
208
break;
209
}
210
diff --git a/block/qcow2.h b/block/qcow2.h
211
index XXXXXXX..XXXXXXX 100644
212
--- a/block/qcow2.h
213
+++ b/block/qcow2.h
214
@@ -XXX,XX +XXX,XX @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
215
int compressed_size);
216
217
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
218
-int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
219
- int nb_sectors, enum qcow2_discard_type type, bool full_discard);
220
-int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors,
221
- int flags);
222
+int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
223
+ uint64_t bytes, enum qcow2_discard_type type,
224
+ bool full_discard);
225
+int qcow2_cluster_zeroize(BlockDriverState *bs, uint64_t offset,
226
+ uint64_t bytes, int flags);
227
228
int qcow2_expand_zero_clusters(BlockDriverState *bs,
229
BlockDriverAmendStatusCB *status_cb,
230
--
231
1.8.3.1
232
233
diff view generated by jsdifflib
Deleted patch
1
From: Max Reitz <mreitz@redhat.com>
2
1
3
util/qemu-progress.c is currently unmaintained. The only user of its
4
functionality is qemu-img, so it effectively is part of the block layer.
5
6
Suggested-by: Fam Zheng <famz@redhat.com>
7
Signed-off-by: Max Reitz <mreitz@redhat.com>
8
Message-id: 20170428165517.30341-1-mreitz@redhat.com
9
Reviewed-by: Eric Blake <eblake@redhat.com>
10
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Max Reitz <mreitz@redhat.com>
12
---
13
MAINTAINERS | 1 +
14
1 file changed, 1 insertion(+)
15
16
diff --git a/MAINTAINERS b/MAINTAINERS
17
index XXXXXXX..XXXXXXX 100644
18
--- a/MAINTAINERS
19
+++ b/MAINTAINERS
20
@@ -XXX,XX +XXX,XX @@ F: include/block/
21
F: qemu-img*
22
F: qemu-io*
23
F: tests/qemu-iotests/
24
+F: util/qemu-progress.c
25
T: git git://repo.or.cz/qemu/kevin.git block
26
27
Block I/O path
28
--
29
1.8.3.1
30
31
diff view generated by jsdifflib