1
The following changes since commit 64175afc695c0672876fbbfc31b299c86d562cb4:
1
The following changes since commit 36f87b4513373b3cd79c87c9197d17face95d4ac:
2
2
3
arm_gicv3: Fix ICC_BPR1 reset value when EL3 not implemented (2017-06-07 17:21:44 +0100)
3
Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.10-20170630' into staging (2017-06-30 11:58:49 +0100)
4
4
5
are available in the git repository at:
5
are available in the git repository at:
6
6
7
git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request
7
git://github.com/famz/qemu.git tags/block-pull-request
8
8
9
for you to fetch changes up to 56faeb9bb6872b3f926b3b3e0452a70beea10af2:
9
for you to fetch changes up to c61e684e44272f2acb2bef34cf2aa234582a73a9:
10
10
11
block/gluster.c: Handle qdict_array_entries() failure (2017-06-09 08:41:29 -0400)
11
block: Exploit BDRV_BLOCK_EOF for larger zero blocks (2017-06-30 21:48:06 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Gluster patch
14
15
Hi Peter,
16
17
Here are Eric Blake's enhancement to block layer API. Thanks!
18
15
----------------------------------------------------------------
19
----------------------------------------------------------------
16
20
17
Peter Maydell (1):
21
Eric Blake (2):
18
block/gluster.c: Handle qdict_array_entries() failure
22
block: Add BDRV_BLOCK_EOF to bdrv_get_block_status()
23
block: Exploit BDRV_BLOCK_EOF for larger zero blocks
19
24
20
block/gluster.c | 3 +--
25
block/io.c | 42 +++++++++++++++++++++++++++++++++---------
21
1 file changed, 1 insertion(+), 2 deletions(-)
26
include/block/block.h | 2 ++
27
tests/qemu-iotests/154 | 4 ----
28
tests/qemu-iotests/154.out | 12 ++++++------
29
4 files changed, 41 insertions(+), 19 deletions(-)
22
30
23
--
31
--
24
2.9.3
32
2.9.4
25
33
26
34
diff view generated by jsdifflib
New patch
1
From: Eric Blake <eblake@redhat.com>
1
2
3
Just as the block layer already sets BDRV_BLOCK_ALLOCATED as a
4
shortcut for subsequent operations, there are also some optimizations
5
that are made easier if we can quickly tell that *pnum will advance
6
us to the end of a file, via a new BDRV_BLOCK_EOF which gets set
7
by the block layer.
8
9
This just plumbs up the new bit; subsequent patches will make use
10
of it.
11
12
Signed-off-by: Eric Blake <eblake@redhat.com>
13
Message-Id: <20170505021500.19315-2-eblake@redhat.com>
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Signed-off-by: Fam Zheng <famz@redhat.com>
16
---
17
block/io.c | 15 +++++++++++----
18
include/block/block.h | 2 ++
19
2 files changed, 13 insertions(+), 4 deletions(-)
20
21
diff --git a/block/io.c b/block/io.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/block/io.c
24
+++ b/block/io.c
25
@@ -XXX,XX +XXX,XX @@ typedef struct BdrvCoGetBlockStatusData {
26
* Drivers not implementing the functionality are assumed to not support
27
* backing files, hence all their sectors are reported as allocated.
28
*
29
- * If 'sector_num' is beyond the end of the disk image the return value is 0
30
- * and 'pnum' is set to 0.
31
+ * If 'sector_num' is beyond the end of the disk image the return value is
32
+ * BDRV_BLOCK_EOF and 'pnum' is set to 0.
33
*
34
* 'pnum' is set to the number of sectors (including and immediately following
35
* the specified sector) that are known to be in the same
36
* allocated/unallocated state.
37
*
38
* 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes
39
- * beyond the end of the disk image it will be clamped.
40
+ * beyond the end of the disk image it will be clamped; if 'pnum' is set to
41
+ * the end of the image, then the returned value will include BDRV_BLOCK_EOF.
42
*
43
* If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, 'file'
44
* points to the BDS which the sector range is allocated in.
45
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
46
47
if (sector_num >= total_sectors) {
48
*pnum = 0;
49
- return 0;
50
+ return BDRV_BLOCK_EOF;
51
}
52
53
n = total_sectors - sector_num;
54
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
55
if (!bs->drv->bdrv_co_get_block_status) {
56
*pnum = nb_sectors;
57
ret = BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED;
58
+ if (sector_num + nb_sectors == total_sectors) {
59
+ ret |= BDRV_BLOCK_EOF;
60
+ }
61
if (bs->drv->protocol_name) {
62
ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
63
}
64
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
65
66
out:
67
bdrv_dec_in_flight(bs);
68
+ if (ret >= 0 && sector_num + *pnum == total_sectors) {
69
+ ret |= BDRV_BLOCK_EOF;
70
+ }
71
return ret;
72
}
73
74
diff --git a/include/block/block.h b/include/block/block.h
75
index XXXXXXX..XXXXXXX 100644
76
--- a/include/block/block.h
77
+++ b/include/block/block.h
78
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
79
* BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
80
* BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
81
* layer (short for DATA || ZERO), set by block layer
82
+ * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this layer
83
*
84
* Internal flag:
85
* BDRV_BLOCK_RAW: used internally to indicate that the request was
86
@@ -XXX,XX +XXX,XX @@ typedef struct HDGeometry {
87
#define BDRV_BLOCK_OFFSET_VALID 0x04
88
#define BDRV_BLOCK_RAW 0x08
89
#define BDRV_BLOCK_ALLOCATED 0x10
90
+#define BDRV_BLOCK_EOF 0x20
91
#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK
92
93
typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
94
--
95
2.9.4
96
97
diff view generated by jsdifflib
1
From: Peter Maydell <peter.maydell@linaro.org>
1
From: Eric Blake <eblake@redhat.com>
2
2
3
In qemu_gluster_parse_json(), the call to qdict_array_entries()
3
When we have a BDS with unallocated clusters, but asking the status
4
could return a negative error code, which we were ignoring
4
of its underlying bs->file or backing layer encounters an end-of-file
5
because we assigned the result to an unsigned variable.
5
condition, we know that the rest of the unallocated area will read as
6
Fix this by using the 'int' type instead, which matches the
6
zeroes. However, pre-patch, this required two separate calls to
7
return type of qdict_array_entries() and also the type
7
bdrv_get_block_status(), as the first call stops at the point where
8
we use for the loop enumeration variable 'i'.
8
the underlying file ends. Thanks to BDRV_BLOCK_EOF, we can now widen
9
the results of the primary status if the secondary status already
10
includes BDRV_BLOCK_ZERO.
9
11
10
(Spotted by Coverity, CID 1360960.)
12
In turn, this fixes a TODO mentioned in iotest 154, where we can now
13
see that all sectors in a partial cluster at the end of a file read
14
as zero when coupling the shorter backing file's status along with our
15
knowledge that the remaining sectors came from an unallocated cluster.
11
16
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Also, note that the loop in bdrv_co_get_block_status_above() had an
13
Reviewed-by: Eric Blake <eblake@redhat.com>
18
inefficent exit: in cases where the active layer sets BDRV_BLOCK_ZERO
14
Reviewed-by: Jeff Cody <jcody@redhat.com>
19
but does NOT set BDRV_BLOCK_ALLOCATED (namely, where we know we read
15
Message-id: 1496682098-1540-1-git-send-email-peter.maydell@linaro.org
20
zeroes merely because our unallocated clusters lie beyond the backing
16
Signed-off-by: Jeff Cody <jcody@redhat.com>
21
file's shorter length), we still ended up probing the backing layer
22
even though we already had a good answer.
23
24
Signed-off-by: Eric Blake <eblake@redhat.com>
25
Message-Id: <20170505021500.19315-3-eblake@redhat.com>
26
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
27
Signed-off-by: Fam Zheng <famz@redhat.com>
17
---
28
---
18
block/gluster.c | 3 +--
29
block/io.c | 27 ++++++++++++++++++++++-----
19
1 file changed, 1 insertion(+), 2 deletions(-)
30
tests/qemu-iotests/154 | 4 ----
31
tests/qemu-iotests/154.out | 12 ++++++------
32
3 files changed, 28 insertions(+), 15 deletions(-)
20
33
21
diff --git a/block/gluster.c b/block/gluster.c
34
diff --git a/block/io.c b/block/io.c
22
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
23
--- a/block/gluster.c
36
--- a/block/io.c
24
+++ b/block/gluster.c
37
+++ b/block/io.c
25
@@ -XXX,XX +XXX,XX @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
38
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
26
Error *local_err = NULL;
39
/* Ignore errors. This is just providing extra information, it
27
char *str = NULL;
40
* is useful but not necessary.
28
const char *ptr;
41
*/
29
- size_t num_servers;
42
- if (!file_pnum) {
30
- int i, type;
43
- /* !file_pnum indicates an offset at or beyond the EOF; it is
31
+ int i, type, num_servers;
44
- * perfectly valid for the format block driver to point to such
32
45
- * offsets, so catch it and mark everything as zero */
33
/* create opts info from runtime_json_opts list */
46
+ if (ret2 & BDRV_BLOCK_EOF &&
34
opts = qemu_opts_create(&runtime_json_opts, NULL, 0, &error_abort);
47
+ (!file_pnum || ret2 & BDRV_BLOCK_ZERO)) {
48
+ /*
49
+ * It is valid for the format block driver to read
50
+ * beyond the end of the underlying file's current
51
+ * size; such areas read as zero.
52
+ */
53
ret |= BDRV_BLOCK_ZERO;
54
} else {
55
/* Limit request to the range reported by the protocol driver */
56
@@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs,
57
{
58
BlockDriverState *p;
59
int64_t ret = 0;
60
+ bool first = true;
61
62
assert(bs != base);
63
for (p = bs; p != base; p = backing_bs(p)) {
64
ret = bdrv_co_get_block_status(p, sector_num, nb_sectors, pnum, file);
65
- if (ret < 0 || ret & BDRV_BLOCK_ALLOCATED) {
66
+ if (ret < 0) {
67
+ break;
68
+ }
69
+ if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) {
70
+ /*
71
+ * Reading beyond the end of the file continues to read
72
+ * zeroes, but we can only widen the result to the
73
+ * unallocated length we learned from an earlier
74
+ * iteration.
75
+ */
76
+ *pnum = nb_sectors;
77
+ }
78
+ if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) {
79
break;
80
}
81
/* [sector_num, pnum] unallocated on this layer, which could be only
82
* the first part of [sector_num, nb_sectors]. */
83
nb_sectors = MIN(nb_sectors, *pnum);
84
+ first = false;
85
}
86
return ret;
87
}
88
diff --git a/tests/qemu-iotests/154 b/tests/qemu-iotests/154
89
index XXXXXXX..XXXXXXX 100755
90
--- a/tests/qemu-iotests/154
91
+++ b/tests/qemu-iotests/154
92
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
93
$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
94
95
# Repeat with backing file holding unallocated cluster.
96
-# TODO: Note that this forces an allocation, because we aren't yet able to
97
-# quickly detect that reads beyond EOF of the backing file are always zero
98
CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
99
100
# Write at the front: sector-wise, the request is:
101
@@ -XXX,XX +XXX,XX @@ $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
102
$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
103
104
# Repeat with backing file holding zero'd cluster
105
-# TODO: Note that this forces an allocation, because we aren't yet able to
106
-# quickly detect that reads beyond EOF of the backing file are always zero
107
$QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io
108
109
# Write at the front: sector-wise, the request is:
110
diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out
111
index XXXXXXX..XXXXXXX 100644
112
--- a/tests/qemu-iotests/154.out
113
+++ b/tests/qemu-iotests/154.out
114
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 134217728
115
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
116
2048/2048 bytes allocated at offset 128 MiB
117
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
118
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
119
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
120
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
121
wrote 512/512 bytes at offset 134219264
122
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
123
2048/2048 bytes allocated at offset 128 MiB
124
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
125
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
126
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
127
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
128
wrote 1024/1024 bytes at offset 134218240
129
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
130
2048/2048 bytes allocated at offset 128 MiB
131
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
132
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
133
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
134
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
135
wrote 2048/2048 bytes at offset 134217728
136
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
137
@@ -XXX,XX +XXX,XX @@ wrote 512/512 bytes at offset 134217728
138
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
139
2048/2048 bytes allocated at offset 128 MiB
140
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
141
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
142
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
143
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
144
wrote 512/512 bytes at offset 134219264
145
512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
146
2048/2048 bytes allocated at offset 128 MiB
147
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
148
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
149
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
150
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
151
wrote 1024/1024 bytes at offset 134218240
152
1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
153
2048/2048 bytes allocated at offset 128 MiB
154
[{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": false},
155
-{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
156
+{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": false}]
157
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134219776 backing_file=TEST_DIR/t.IMGFMT.base
158
wrote 2048/2048 bytes at offset 134217728
159
2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
35
--
160
--
36
2.9.3
161
2.9.4
37
162
38
163
diff view generated by jsdifflib