1
The following changes since commit 36609b4fa36f0ac934874371874416f7533a5408:
1
The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81:
2
2
3
Merge remote-tracking branch 'remotes/palmer/tags/palmer-for-master-4.2-sf1' into staging (2019-11-02 17:59:03 +0000)
3
Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://github.com/stefanha/qemu.git tags/block-pull-request
7
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
8
8
9
for you to fetch changes up to 9fdd7860adec188ed50d2530e9a819e8d953f9bb:
9
for you to fetch changes up to 9f460c64e13897117f35ffb61f6f5e0102cabc70:
10
10
11
image-fuzzer: Use OSerror.strerror instead of tuple subscript (2019-11-05 16:36:11 +0100)
11
block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Pull request
14
Pull request
15
15
16
Let's get the image fuzzer Python 3 changes merged in QEMU 4.2.
17
18
----------------------------------------------------------------
16
----------------------------------------------------------------
19
17
20
Eduardo Habkost (11):
18
Akihiko Odaki (3):
21
image-fuzzer: Open image files in binary mode
19
block/file-posix: Optimize for macOS
22
image-fuzzer: Write bytes instead of string to image file
20
block: Add backend_defaults property
23
image-fuzzer: Explicitly use integer division operator
21
block/io: Merge discard request alignments
24
image-fuzzer: Use io.StringIO
25
image-fuzzer: Use %r for all fiels at Field.__repr__()
26
image-fuzzer: Return bytes objects on string fuzzing functions
27
image-fuzzer: Use bytes constant for field values
28
image-fuzzer: Encode file name and file format to bytes
29
image-fuzzer: Run using python3
30
image-fuzzer: Use errors parameter of subprocess.Popen()
31
image-fuzzer: Use OSerror.strerror instead of tuple subscript
32
22
33
tests/image-fuzzer/qcow2/__init__.py | 1 -
23
Stefan Hajnoczi (2):
34
tests/image-fuzzer/qcow2/fuzz.py | 54 +++++++++++++-------------
24
util/async: add a human-readable name to BHs for debugging
35
tests/image-fuzzer/qcow2/layout.py | 57 ++++++++++++++--------------
25
util/async: print leaked BH name when AioContext finalizes
36
tests/image-fuzzer/runner.py | 16 ++++----
26
37
4 files changed, 63 insertions(+), 65 deletions(-)
27
include/block/aio.h | 31 ++++++++++++++++++++++---
28
include/hw/block/block.h | 3 +++
29
include/qemu/main-loop.h | 4 +++-
30
block/file-posix.c | 27 ++++++++++++++++++++--
31
block/io.c | 2 ++
32
hw/block/block.c | 42 ++++++++++++++++++++++++++++++----
33
tests/unit/ptimer-test-stubs.c | 2 +-
34
util/async.c | 25 ++++++++++++++++----
35
util/main-loop.c | 4 ++--
36
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++
37
10 files changed, 161 insertions(+), 17 deletions(-)
38
38
39
--
39
--
40
2.23.0
40
2.31.1
41
41
42
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
This probably never caused problems because on Linux there's no
4
actual newline conversion happening, but on Python 3 the
5
binary/text distinction is stronger and we must explicitly open
6
the image file in binary mode.
7
8
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9
Reviewed-by: John Snow <jsnow@redhat.com>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Message-id: 20191016192430.25098-2-ehabkost@redhat.com
12
Message-Id: <20191016192430.25098-2-ehabkost@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
---
15
tests/image-fuzzer/qcow2/layout.py | 2 +-
16
1 file changed, 1 insertion(+), 1 deletion(-)
17
18
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
19
index XXXXXXX..XXXXXXX 100644
20
--- a/tests/image-fuzzer/qcow2/layout.py
21
+++ b/tests/image-fuzzer/qcow2/layout.py
22
@@ -XXX,XX +XXX,XX @@ class Image(object):
23
24
def write(self, filename):
25
"""Write an entire image to the file."""
26
- image_file = open(filename, 'w')
27
+ image_file = open(filename, 'wb')
28
for field in self:
29
image_file.seek(field.offset)
30
image_file.write(struct.pack(field.fmt, field.value))
31
--
32
2.23.0
33
34
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
This is necessary for Python 3 compatibility.
4
5
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
6
Reviewed-by: John Snow <jsnow@redhat.com>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20191016192430.25098-3-ehabkost@redhat.com
9
Message-Id: <20191016192430.25098-3-ehabkost@redhat.com>
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
tests/image-fuzzer/qcow2/layout.py | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
14
15
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/image-fuzzer/qcow2/layout.py
18
+++ b/tests/image-fuzzer/qcow2/layout.py
19
@@ -XXX,XX +XXX,XX @@ class Image(object):
20
rounded = (size + self.cluster_size - 1) & ~(self.cluster_size - 1)
21
if rounded > size:
22
image_file.seek(rounded - 1)
23
- image_file.write("\0")
24
+ image_file.write(b'\x00')
25
image_file.close()
26
27
@staticmethod
28
--
29
2.23.0
30
31
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
Most of the division expressions in image-fuzzer assume integer
4
division. Use the // operator to keep the same behavior when we
5
move to Python 3.
6
7
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Message-id: 20191016192430.25098-4-ehabkost@redhat.com
11
Message-Id: <20191016192430.25098-4-ehabkost@redhat.com>
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
14
tests/image-fuzzer/qcow2/fuzz.py | 12 ++++-----
15
tests/image-fuzzer/qcow2/layout.py | 40 +++++++++++++++---------------
16
2 files changed, 26 insertions(+), 26 deletions(-)
17
18
diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fuzz.py
19
index XXXXXXX..XXXXXXX 100644
20
--- a/tests/image-fuzzer/qcow2/fuzz.py
21
+++ b/tests/image-fuzzer/qcow2/fuzz.py
22
@@ -XXX,XX +XXX,XX @@ UINT64 = 0xffffffffffffffff
23
UINT32_M = 31
24
UINT64_M = 63
25
# Fuzz vectors
26
-UINT8_V = [0, 0x10, UINT8/4, UINT8/2 - 1, UINT8/2, UINT8/2 + 1, UINT8 - 1,
27
+UINT8_V = [0, 0x10, UINT8//4, UINT8//2 - 1, UINT8//2, UINT8//2 + 1, UINT8 - 1,
28
UINT8]
29
-UINT16_V = [0, 0x100, 0x1000, UINT16/4, UINT16/2 - 1, UINT16/2, UINT16/2 + 1,
30
+UINT16_V = [0, 0x100, 0x1000, UINT16//4, UINT16//2 - 1, UINT16//2, UINT16//2 + 1,
31
UINT16 - 1, UINT16]
32
-UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32/4, UINT32/2 - 1,
33
- UINT32/2, UINT32/2 + 1, UINT32 - 1, UINT32]
34
-UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64/4,
35
- UINT64/2 - 1, UINT64/2, UINT64/2 + 1, UINT64 - 1,
36
+UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32//4, UINT32//2 - 1,
37
+ UINT32//2, UINT32//2 + 1, UINT32 - 1, UINT32]
38
+UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4,
39
+ UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1,
40
UINT64]
41
STRING_V = ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x',
42
'%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%20n',
43
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
44
index XXXXXXX..XXXXXXX 100644
45
--- a/tests/image-fuzzer/qcow2/layout.py
46
+++ b/tests/image-fuzzer/qcow2/layout.py
47
@@ -XXX,XX +XXX,XX @@ class Image(object):
48
['>I', self.ext_offset, 0x6803f857, 'ext_magic'],
49
# One feature table contains 3 fields and takes 48 bytes
50
['>I', self.ext_offset + UINT32_S,
51
- len(feature_tables) / 3 * 48, 'ext_length']
52
+ len(feature_tables) // 3 * 48, 'ext_length']
53
] + feature_tables)
54
self.ext_offset = inner_offset
55
56
@@ -XXX,XX +XXX,XX @@ class Image(object):
57
def create_l2_entry(host, guest, l2_cluster):
58
"""Generate one L2 entry."""
59
offset = l2_cluster * self.cluster_size
60
- l2_size = self.cluster_size / UINT64_S
61
+ l2_size = self.cluster_size // UINT64_S
62
entry_offset = offset + UINT64_S * (guest % l2_size)
63
cluster_descriptor = host * self.cluster_size
64
if not self.header['version'][0].value == 2:
65
@@ -XXX,XX +XXX,XX @@ class Image(object):
66
67
def create_l1_entry(l2_cluster, l1_offset, guest):
68
"""Generate one L1 entry."""
69
- l2_size = self.cluster_size / UINT64_S
70
- entry_offset = l1_offset + UINT64_S * (guest / l2_size)
71
+ l2_size = self.cluster_size // UINT64_S
72
+ entry_offset = l1_offset + UINT64_S * (guest // l2_size)
73
# While snapshots are not supported bit #63 = 1
74
entry_val = (1 << 63) + l2_cluster * self.cluster_size
75
return ['>Q', entry_offset, entry_val, 'l1_entry']
76
@@ -XXX,XX +XXX,XX @@ class Image(object):
77
l2 = []
78
else:
79
meta_data = self._get_metadata()
80
- guest_clusters = random.sample(range(self.image_size /
81
+ guest_clusters = random.sample(range(self.image_size //
82
self.cluster_size),
83
len(self.data_clusters))
84
# Number of entries in a L1/L2 table
85
- l_size = self.cluster_size / UINT64_S
86
+ l_size = self.cluster_size // UINT64_S
87
# Number of clusters necessary for L1 table
88
l1_size = int(ceil((max(guest_clusters) + 1) / float(l_size**2)))
89
l1_start = self._get_adjacent_clusters(self.data_clusters |
90
@@ -XXX,XX +XXX,XX @@ class Image(object):
91
# L2 entries
92
l2 = []
93
for host, guest in zip(self.data_clusters, guest_clusters):
94
- l2_id = guest / l_size
95
+ l2_id = guest // l_size
96
if l2_id not in l2_ids:
97
l2_ids.append(l2_id)
98
l2_clusters.append(self._get_adjacent_clusters(
99
@@ -XXX,XX +XXX,XX @@ class Image(object):
100
def allocate_rfc_blocks(data, size):
101
"""Return indices of clusters allocated for refcount blocks."""
102
cluster_ids = set()
103
- diff = block_ids = set([x / size for x in data])
104
+ diff = block_ids = set([x // size for x in data])
105
while len(diff) != 0:
106
# Allocate all yet not allocated clusters
107
new = self._get_available_clusters(data | cluster_ids,
108
len(diff))
109
# Indices of new refcount blocks necessary to cover clusters
110
# in 'new'
111
- diff = set([x / size for x in new]) - block_ids
112
+ diff = set([x // size for x in new]) - block_ids
113
cluster_ids |= new
114
block_ids |= diff
115
return cluster_ids, block_ids
116
@@ -XXX,XX +XXX,XX @@ class Image(object):
117
blocks = set(init_blocks)
118
clusters = set()
119
# Number of entries in one cluster of the refcount table
120
- size = self.cluster_size / UINT64_S
121
+ size = self.cluster_size // UINT64_S
122
# Number of clusters necessary for the refcount table based on
123
# the current number of refcount blocks
124
table_size = int(ceil((max(blocks) + 1) / float(size)))
125
@@ -XXX,XX +XXX,XX @@ class Image(object):
126
table_size + 1))
127
# New refcount blocks necessary for clusters occupied by the
128
# refcount table
129
- diff = set([c / block_size for c in table_clusters]) - blocks
130
+ diff = set([c // block_size for c in table_clusters]) - blocks
131
blocks |= diff
132
while len(diff) != 0:
133
# Allocate clusters for new refcount blocks
134
@@ -XXX,XX +XXX,XX @@ class Image(object):
135
len(diff))
136
# Indices of new refcount blocks necessary to cover
137
# clusters in 'new'
138
- diff = set([x / block_size for x in new]) - blocks
139
+ diff = set([x // block_size for x in new]) - blocks
140
clusters |= new
141
blocks |= diff
142
# Check if the refcount table needs one more cluster
143
if int(ceil((max(blocks) + 1) / float(size))) > table_size:
144
- new_block_id = (table_start + table_size) / block_size
145
+ new_block_id = (table_start + table_size) // block_size
146
# Check if the additional table cluster needs
147
# one more refcount block
148
if new_block_id not in blocks:
149
@@ -XXX,XX +XXX,XX @@ class Image(object):
150
def create_table_entry(table_offset, block_cluster, block_size,
151
cluster):
152
"""Generate a refcount table entry."""
153
- offset = table_offset + UINT64_S * (cluster / block_size)
154
+ offset = table_offset + UINT64_S * (cluster // block_size)
155
return ['>Q', offset, block_cluster * self.cluster_size,
156
'refcount_table_entry']
157
158
def create_block_entry(block_cluster, block_size, cluster):
159
"""Generate a list of entries for the current block."""
160
- entry_size = self.cluster_size / block_size
161
+ entry_size = self.cluster_size // block_size
162
offset = block_cluster * self.cluster_size
163
entry_offset = offset + entry_size * (cluster % block_size)
164
# While snapshots are not supported all refcounts are set to 1
165
@@ -XXX,XX +XXX,XX @@ class Image(object):
166
# Number of refcount entries per refcount block
167
# Convert self.cluster_size from bytes to bits to have the same
168
# base for the numerator and denominator
169
- block_size = self.cluster_size * 8 / refcount_bits
170
+ block_size = self.cluster_size * 8 // refcount_bits
171
meta_data = self._get_metadata()
172
if len(self.data_clusters) == 0:
173
# All metadata for an empty guest image needs 4 clusters:
174
@@ -XXX,XX +XXX,XX @@ class Image(object):
175
rfc_blocks = []
176
177
for cluster in sorted(self.data_clusters | meta_data):
178
- if cluster / block_size != block_id:
179
- block_id = cluster / block_size
180
+ if cluster // block_size != block_id:
181
+ block_id = cluster // block_size
182
block_cluster = block_clusters[block_ids.index(block_id)]
183
rfc_table.append(create_table_entry(table_offset,
184
block_cluster,
185
@@ -XXX,XX +XXX,XX @@ class Image(object):
186
def _alloc_data(img_size, cluster_size):
187
"""Return a set of random indices of clusters allocated for guest data.
188
"""
189
- num_of_cls = img_size/cluster_size
190
+ num_of_cls = img_size // cluster_size
191
return set(random.sample(range(1, num_of_cls + 1),
192
random.randint(0, num_of_cls)))
193
194
@@ -XXX,XX +XXX,XX @@ class Image(object):
195
"""Return indices of clusters allocated for image metadata."""
196
ids = set()
197
for x in self:
198
- ids.add(x.offset/self.cluster_size)
199
+ ids.add(x.offset // self.cluster_size)
200
return ids
201
202
203
--
204
2.23.0
205
206
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
StringIO.StringIO is not available on Python 3, but io.StringIO
4
is available on both Python 2 and 3. io.StringIO is slightly
5
different from the Python 2 StringIO module, though, so we need
6
bytes coming from subprocess.Popen() to be explicitly decoded.
7
8
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9
Reviewed-by: John Snow <jsnow@redhat.com>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Message-id: 20191016192430.25098-5-ehabkost@redhat.com
12
Message-Id: <20191016192430.25098-5-ehabkost@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
---
15
tests/image-fuzzer/runner.py | 14 +++++++++-----
16
1 file changed, 9 insertions(+), 5 deletions(-)
17
18
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py
19
index XXXXXXX..XXXXXXX 100755
20
--- a/tests/image-fuzzer/runner.py
21
+++ b/tests/image-fuzzer/runner.py
22
@@ -XXX,XX +XXX,XX @@ import shutil
23
from itertools import count
24
import time
25
import getopt
26
-import StringIO
27
+import io
28
import resource
29
30
try:
31
@@ -XXX,XX +XXX,XX @@ def run_app(fd, q_args):
32
try:
33
out, err = process.communicate()
34
signal.alarm(0)
35
- fd.write(out)
36
- fd.write(err)
37
+ # fd is a text file, so we need to decode the process output before
38
+ # writing to it.
39
+ # We could be simply using the `errors` parameter of subprocess.Popen(),
40
+ # but this will be possible only after migrating to Python 3
41
+ fd.write(out.decode(errors='replace'))
42
+ fd.write(err.decode(errors='replace'))
43
fd.flush()
44
return process.returncode
45
46
@@ -XXX,XX +XXX,XX @@ class TestEnv(object):
47
MAX_BACKING_FILE_SIZE) * (1 << 20)
48
cmd = self.qemu_img + ['create', '-f', backing_file_fmt,
49
backing_file_name, str(backing_file_size)]
50
- temp_log = StringIO.StringIO()
51
+ temp_log = io.StringIO()
52
retcode = run_app(temp_log, cmd)
53
if retcode == 0:
54
temp_log.close()
55
@@ -XXX,XX +XXX,XX @@ class TestEnv(object):
56
"Backing file: %s\n" \
57
% (self.seed, " ".join(current_cmd),
58
self.current_dir, backing_file_name)
59
- temp_log = StringIO.StringIO()
60
+ temp_log = io.StringIO()
61
try:
62
retcode = run_app(temp_log, current_cmd)
63
except OSError as e:
64
--
65
2.23.0
66
67
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
This makes the formatting code simpler, and safer if we change
4
the type of self.value from str to bytes.
5
6
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7
Reviewed-by: John Snow <jsnow@redhat.com>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20191016192430.25098-6-ehabkost@redhat.com
10
Message-Id: <20191016192430.25098-6-ehabkost@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
13
tests/image-fuzzer/qcow2/layout.py | 4 ++--
14
1 file changed, 2 insertions(+), 2 deletions(-)
15
16
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
17
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/image-fuzzer/qcow2/layout.py
19
+++ b/tests/image-fuzzer/qcow2/layout.py
20
@@ -XXX,XX +XXX,XX @@ class Field(object):
21
return iter([self.fmt, self.offset, self.value, self.name])
22
23
def __repr__(self):
24
- return "Field(fmt='%s', offset=%d, value=%s, name=%s)" % \
25
- (self.fmt, self.offset, str(self.value), self.name)
26
+ return "Field(fmt=%r, offset=%r, value=%r, name=%r)" % \
27
+ (self.fmt, self.offset, self.value, self.name)
28
29
30
class FieldsList(object):
31
--
32
2.23.0
33
34
diff view generated by jsdifflib
Deleted patch
1
From: Eduardo Habkost <ehabkost@redhat.com>
2
1
3
No caller of fuzzer functions is interested in unicode string values,
4
so replace them with bytes sequences.
5
6
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7
Reviewed-by: John Snow <jsnow@redhat.com>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20191016192430.25098-7-ehabkost@redhat.com
10
Message-Id: <20191016192430.25098-7-ehabkost@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
13
tests/image-fuzzer/qcow2/fuzz.py | 42 ++++++++++++++++----------------
14
1 file changed, 21 insertions(+), 21 deletions(-)
15
16
diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fuzz.py
17
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/image-fuzzer/qcow2/fuzz.py
19
+++ b/tests/image-fuzzer/qcow2/fuzz.py
20
@@ -XXX,XX +XXX,XX @@ UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32//4, UINT32//2 - 1,
21
UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4,
22
UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1,
23
UINT64]
24
-STRING_V = ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x',
25
- '%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%20n',
26
- '%%20x', '%%20s', '%s%s%s%s%s%s%s%s%s%s', '%p%p%p%p%p%p%p%p%p%p',
27
- '%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%',
28
- '%s x 129', '%x x 257']
29
+BYTES_V = [b'%s%p%x%d', b'.1024d', b'%.2049d', b'%p%p%p%p', b'%x%x%x%x',
30
+ b'%d%d%d%d', b'%s%s%s%s', b'%99999999999s', b'%08x', b'%%20d', b'%%20n',
31
+ b'%%20x', b'%%20s', b'%s%s%s%s%s%s%s%s%s%s', b'%p%p%p%p%p%p%p%p%p%p',
32
+ b'%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%',
33
+ b'%s x 129', b'%x x 257']
34
35
36
def random_from_intervals(intervals):
37
@@ -XXX,XX +XXX,XX @@ def random_bits(bit_ranges):
38
return val
39
40
41
-def truncate_string(strings, length):
42
- """Return strings truncated to specified length."""
43
- if type(strings) == list:
44
- return [s[:length] for s in strings]
45
+def truncate_bytes(sequences, length):
46
+ """Return sequences truncated to specified length."""
47
+ if type(sequences) == list:
48
+ return [s[:length] for s in sequences]
49
else:
50
- return strings[:length]
51
+ return sequences[:length]
52
53
54
def validator(current, pick, choices):
55
@@ -XXX,XX +XXX,XX @@ def bit_validator(current, bit_ranges):
56
return validator(current, random_bits, bit_ranges)
57
58
59
-def string_validator(current, strings):
60
- """Return a random string value from the list not equal to the current.
61
+def bytes_validator(current, sequences):
62
+ """Return a random bytes value from the list not equal to the current.
63
64
This function is useful for selection from valid values except current one.
65
"""
66
- return validator(current, random.choice, strings)
67
+ return validator(current, random.choice, sequences)
68
69
70
def selector(current, constraints, validate=int_validator):
71
@@ -XXX,XX +XXX,XX @@ def header_length(current):
72
def bf_name(current):
73
"""Fuzz the backing file name."""
74
constraints = [
75
- truncate_string(STRING_V, len(current))
76
+ truncate_bytes(BYTES_V, len(current))
77
]
78
- return selector(current, constraints, string_validator)
79
+ return selector(current, constraints, bytes_validator)
80
81
82
def ext_magic(current):
83
@@ -XXX,XX +XXX,XX @@ def ext_length(current):
84
def bf_format(current):
85
"""Fuzz backing file format in the corresponding header extension."""
86
constraints = [
87
- truncate_string(STRING_V, len(current)),
88
- truncate_string(STRING_V, (len(current) + 7) & ~7) # Fuzz padding
89
+ truncate_bytes(BYTES_V, len(current)),
90
+ truncate_bytes(BYTES_V, (len(current) + 7) & ~7) # Fuzz padding
91
]
92
- return selector(current, constraints, string_validator)
93
+ return selector(current, constraints, bytes_validator)
94
95
96
def feature_type(current):
97
@@ -XXX,XX +XXX,XX @@ def feature_bit_number(current):
98
def feature_name(current):
99
"""Fuzz feature name field of a feature name table header extension."""
100
constraints = [
101
- truncate_string(STRING_V, len(current)),
102
- truncate_string(STRING_V, 46) # Fuzz padding (field length = 46)
103
+ truncate_bytes(BYTES_V, len(current)),
104
+ truncate_bytes(BYTES_V, 46) # Fuzz padding (field length = 46)
105
]
106
- return selector(current, constraints, string_validator)
107
+ return selector(current, constraints, bytes_validator)
108
109
110
def l1_entry(current):
111
--
112
2.23.0
113
114
diff view generated by jsdifflib
1
From: Eduardo Habkost <ehabkost@redhat.com>
1
It can be difficult to debug issues with BHs in production environments.
2
Although BHs can usually be identified by looking up their ->cb()
3
function pointer, this requires debug information for the program. It is
4
also not possible to print human-readable diagnostics about BHs because
5
they have no identifier.
2
6
3
OSError can't be used like a tuple on Python 3, so change the
7
This patch adds a name to each BH. The name is not unique per instance
4
code to use `e.sterror` instead of `e[1]`.
8
but differentiates between cb() functions, which is usually enough. It's
9
done by changing aio_bh_new() and friends to macros that stringify cb.
5
10
6
Reported-by: John Snow <jsnow@redhat.com>
11
The next patch will use the name field when reporting leaked BHs.
7
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
12
8
Reviewed-by: John Snow <jsnow@redhat.com>
9
Message-id: 20191021214117.18091-1-ehabkost@redhat.com
10
Message-Id: <20191021214117.18091-1-ehabkost@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Message-Id: <20210414200247.917496-2-stefanha@redhat.com>
12
---
16
---
13
tests/image-fuzzer/runner.py | 4 ++--
17
include/block/aio.h | 31 ++++++++++++++++++++++++++++---
14
1 file changed, 2 insertions(+), 2 deletions(-)
18
include/qemu/main-loop.h | 4 +++-
19
tests/unit/ptimer-test-stubs.c | 2 +-
20
util/async.c | 9 +++++++--
21
util/main-loop.c | 4 ++--
22
5 files changed, 41 insertions(+), 9 deletions(-)
15
23
16
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py
24
diff --git a/include/block/aio.h b/include/block/aio.h
17
index XXXXXXX..XXXXXXX 100755
25
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/image-fuzzer/runner.py
26
--- a/include/block/aio.h
19
+++ b/tests/image-fuzzer/runner.py
27
+++ b/include/block/aio.h
20
@@ -XXX,XX +XXX,XX @@ class TestEnv(object):
28
@@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx);
21
os.makedirs(self.current_dir)
29
/* Relinquish ownership of the AioContext. */
22
except OSError as e:
30
void aio_context_release(AioContext *ctx);
23
print("Error: The working directory '%s' cannot be used. Reason: %s"\
31
24
- % (self.work_dir, e[1]), file=sys.stderr)
32
+/**
25
+ % (self.work_dir, e.strerror), file=sys.stderr)
33
+ * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will
26
raise TestException
34
+ * run only once and as soon as possible.
27
self.log = open(os.path.join(self.current_dir, "test.log"), "w")
35
+ *
28
self.parent_log = open(run_log, "a")
36
+ * @name: A human-readable identifier for debugging purposes.
29
@@ -XXX,XX +XXX,XX @@ class TestEnv(object):
37
+ */
30
except OSError as e:
38
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
31
multilog("%sError: Start of '%s' failed. Reason: %s\n\n"
39
+ const char *name);
32
% (test_summary, os.path.basename(current_cmd[0]),
40
+
33
- e[1]),
41
/**
34
+ e.strerror),
42
* aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run
35
sys.stderr, self.log, self.parent_log)
43
* only once and as soon as possible.
36
raise TestException
44
+ *
37
45
+ * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the
46
+ * name string.
47
*/
48
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
49
+#define aio_bh_schedule_oneshot(ctx, cb, opaque) \
50
+ aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb)))
51
52
/**
53
- * aio_bh_new: Allocate a new bottom half structure.
54
+ * aio_bh_new_full: Allocate a new bottom half structure.
55
*
56
* Bottom halves are lightweight callbacks whose invocation is guaranteed
57
* to be wait-free, thread-safe and signal-safe. The #QEMUBH structure
58
* is opaque and must be allocated prior to its use.
59
+ *
60
+ * @name: A human-readable identifier for debugging purposes.
61
*/
62
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
63
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
64
+ const char *name);
65
+
66
+/**
67
+ * aio_bh_new: Allocate a new bottom half structure
68
+ *
69
+ * A convenience wrapper for aio_bh_new_full() that uses the cb as the name
70
+ * string.
71
+ */
72
+#define aio_bh_new(ctx, cb, opaque) \
73
+ aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)))
74
75
/**
76
* aio_notify: Force processing of pending events.
77
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
78
index XXXXXXX..XXXXXXX 100644
79
--- a/include/qemu/main-loop.h
80
+++ b/include/qemu/main-loop.h
81
@@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
82
83
void qemu_fd_register(int fd);
84
85
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
86
+#define qemu_bh_new(cb, opaque) \
87
+ qemu_bh_new_full((cb), (opaque), (stringify(cb)))
88
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name);
89
void qemu_bh_schedule_idle(QEMUBH *bh);
90
91
enum {
92
diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c
93
index XXXXXXX..XXXXXXX 100644
94
--- a/tests/unit/ptimer-test-stubs.c
95
+++ b/tests/unit/ptimer-test-stubs.c
96
@@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
97
return deadline;
98
}
99
100
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
101
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
102
{
103
QEMUBH *bh = g_new(QEMUBH, 1);
104
105
diff --git a/util/async.c b/util/async.c
106
index XXXXXXX..XXXXXXX 100644
107
--- a/util/async.c
108
+++ b/util/async.c
109
@@ -XXX,XX +XXX,XX @@ enum {
110
111
struct QEMUBH {
112
AioContext *ctx;
113
+ const char *name;
114
QEMUBHFunc *cb;
115
void *opaque;
116
QSLIST_ENTRY(QEMUBH) next;
117
@@ -XXX,XX +XXX,XX @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags)
118
return bh;
119
}
120
121
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
122
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb,
123
+ void *opaque, const char *name)
124
{
125
QEMUBH *bh;
126
bh = g_new(QEMUBH, 1);
127
@@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
128
.ctx = ctx,
129
.cb = cb,
130
.opaque = opaque,
131
+ .name = name,
132
};
133
aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT);
134
}
135
136
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
137
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
138
+ const char *name)
139
{
140
QEMUBH *bh;
141
bh = g_new(QEMUBH, 1);
142
@@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
143
.ctx = ctx,
144
.cb = cb,
145
.opaque = opaque,
146
+ .name = name,
147
};
148
return bh;
149
}
150
diff --git a/util/main-loop.c b/util/main-loop.c
151
index XXXXXXX..XXXXXXX 100644
152
--- a/util/main-loop.c
153
+++ b/util/main-loop.c
154
@@ -XXX,XX +XXX,XX @@ void main_loop_wait(int nonblocking)
155
156
/* Functions to operate on the main QEMU AioContext. */
157
158
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
159
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
160
{
161
- return aio_bh_new(qemu_aio_context, cb, opaque);
162
+ return aio_bh_new_full(qemu_aio_context, cb, opaque, name);
163
}
164
165
/*
38
--
166
--
39
2.23.0
167
2.31.1
40
168
41
diff view generated by jsdifflib
1
From: Eduardo Habkost <ehabkost@redhat.com>
1
BHs must be deleted before the AioContext is finalized. If not, it's a
2
bug and probably indicates that some part of the program still expects
3
the BH to run in the future. That can lead to memory leaks, inconsistent
4
state, or just hangs.
2
5
3
Instead of manually encoding stderr and stdout output, use
6
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize()
4
`errors` parameter of subprocess.Popen(). This will make
7
is difficult to debug because the assertion failure contains no
5
process.communicate() return unicode strings instead of bytes
8
information about the BH!
6
objects.
7
9
8
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
10
Use the QEMUBH name field added in the previous patch to show a useful
9
Reviewed-by: John Snow <jsnow@redhat.com>
11
error when a leaked BH is detected.
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
11
Message-id: 20191016192430.25098-11-ehabkost@redhat.com
13
Suggested-by: Eric Ernst <eric.g.ernst@gmail.com>
12
Message-Id: <20191016192430.25098-11-ehabkost@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Message-Id: <20210414200247.917496-3-stefanha@redhat.com>
14
---
16
---
15
tests/image-fuzzer/runner.py | 11 ++++-------
17
util/async.c | 16 ++++++++++++++--
16
1 file changed, 4 insertions(+), 7 deletions(-)
18
1 file changed, 14 insertions(+), 2 deletions(-)
17
19
18
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py
20
diff --git a/util/async.c b/util/async.c
19
index XXXXXXX..XXXXXXX 100755
21
index XXXXXXX..XXXXXXX 100644
20
--- a/tests/image-fuzzer/runner.py
22
--- a/util/async.c
21
+++ b/tests/image-fuzzer/runner.py
23
+++ b/util/async.c
22
@@ -XXX,XX +XXX,XX @@ def run_app(fd, q_args):
24
@@ -XXX,XX +XXX,XX @@ aio_ctx_finalize(GSource *source)
23
devnull = open('/dev/null', 'r+')
25
assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list));
24
process = subprocess.Popen(q_args, stdin=devnull,
26
25
stdout=subprocess.PIPE,
27
while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) {
26
- stderr=subprocess.PIPE)
28
- /* qemu_bh_delete() must have been called on BHs in this AioContext */
27
+ stderr=subprocess.PIPE,
29
- assert(flags & BH_DELETED);
28
+ errors='replace')
30
+ /*
29
try:
31
+ * qemu_bh_delete() must have been called on BHs in this AioContext. In
30
out, err = process.communicate()
32
+ * many cases memory leaks, hangs, or inconsistent state occur when a
31
signal.alarm(0)
33
+ * BH is leaked because something still expects it to run.
32
- # fd is a text file, so we need to decode the process output before
34
+ *
33
- # writing to it.
35
+ * If you hit this, fix the lifecycle of the BH so that
34
- # We could be simply using the `errors` parameter of subprocess.Popen(),
36
+ * qemu_bh_delete() and any associated cleanup is called before the
35
- # but this will be possible only after migrating to Python 3
37
+ * AioContext is finalized.
36
- fd.write(out.decode(errors='replace'))
38
+ */
37
- fd.write(err.decode(errors='replace'))
39
+ if (unlikely(!(flags & BH_DELETED))) {
38
+ fd.write(out)
40
+ fprintf(stderr, "%s: BH '%s' leaked, aborting...\n",
39
+ fd.write(err)
41
+ __func__, bh->name);
40
fd.flush()
42
+ abort();
41
return process.returncode
43
+ }
42
44
45
g_free(bh);
46
}
43
--
47
--
44
2.23.0
48
2.31.1
45
49
46
diff view generated by jsdifflib
1
From: Eduardo Habkost <ehabkost@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
image-fuzzer is now supposed to be ready to run using Python 3.
3
This commit introduces "punch hole" operation and optimizes transfer
4
Remove the __future__ imports and change the interpreter line to
4
block size for macOS.
5
"#!/usr/bin/env python3".
6
5
7
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
6
Thanks to Konstantin Nazarov for detailed analysis of a flaw in an
8
Reviewed-by: John Snow <jsnow@redhat.com>
7
old version of this change:
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667
10
Message-id: 20191016192430.25098-10-ehabkost@redhat.com
9
11
Message-Id: <20191016192430.25098-10-ehabkost@redhat.com>
10
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
11
Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
13
---
14
tests/image-fuzzer/qcow2/__init__.py | 1 -
14
block/file-posix.c | 27 +++++++++++++++++++++++++--
15
tests/image-fuzzer/qcow2/layout.py | 1 -
15
1 file changed, 25 insertions(+), 2 deletions(-)
16
tests/image-fuzzer/runner.py | 3 +--
17
3 files changed, 1 insertion(+), 4 deletions(-)
18
16
19
diff --git a/tests/image-fuzzer/qcow2/__init__.py b/tests/image-fuzzer/qcow2/__init__.py
17
diff --git a/block/file-posix.c b/block/file-posix.c
20
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
21
--- a/tests/image-fuzzer/qcow2/__init__.py
19
--- a/block/file-posix.c
22
+++ b/tests/image-fuzzer/qcow2/__init__.py
20
+++ b/block/file-posix.c
23
@@ -1,2 +1 @@
24
-from __future__ import absolute_import
25
from .layout import create_image
26
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
27
index XXXXXXX..XXXXXXX 100644
28
--- a/tests/image-fuzzer/qcow2/layout.py
29
+++ b/tests/image-fuzzer/qcow2/layout.py
30
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
31
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#if defined(HAVE_HOST_BLOCK_DEVICE)
32
#
23
#include <paths.h>
33
24
#include <sys/param.h>
34
-from __future__ import absolute_import
25
+#include <sys/mount.h>
35
import random
26
#include <IOKit/IOKitLib.h>
36
import struct
27
#include <IOKit/IOBSD.h>
37
from . import fuzz
28
#include <IOKit/storage/IOMediaBSDClient.h>
38
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py
29
@@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
39
index XXXXXXX..XXXXXXX 100755
30
return;
40
--- a/tests/image-fuzzer/runner.py
31
}
41
+++ b/tests/image-fuzzer/runner.py
32
42
@@ -XXX,XX +XXX,XX @@
33
+#if defined(__APPLE__) && (__MACH__)
43
-#!/usr/bin/env python
34
+ struct statfs buf;
44
+#!/usr/bin/env python3
35
+
45
36
+ if (!fstatfs(s->fd, &buf)) {
46
# Tool for running fuzz tests
37
+ bs->bl.opt_transfer = buf.f_iosize;
47
#
38
+ bs->bl.pdiscard_alignment = buf.f_bsize;
48
@@ -XXX,XX +XXX,XX @@
39
+ }
49
# along with this program. If not, see <http://www.gnu.org/licenses/>.
40
+#endif
50
#
41
+
51
42
if (bs->sg || S_ISBLK(st.st_mode)) {
52
-from __future__ import print_function
43
int ret = hdev_get_max_hw_transfer(s->fd, &st);
53
import sys
44
54
import os
45
@@ -XXX,XX +XXX,XX @@ out:
55
import signal
46
}
47
}
48
49
+#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD)
50
static int translate_err(int err)
51
{
52
if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP ||
53
@@ -XXX,XX +XXX,XX @@ static int translate_err(int err)
54
}
55
return err;
56
}
57
+#endif
58
59
#ifdef CONFIG_FALLOCATE
60
static int do_fallocate(int fd, int mode, off_t offset, off_t len)
61
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
62
}
63
} while (errno == EINTR);
64
65
- ret = -errno;
66
+ ret = translate_err(-errno);
67
#endif
68
} else {
69
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
70
ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
71
aiocb->aio_offset, aiocb->aio_nbytes);
72
+ ret = translate_err(-errno);
73
+#elif defined(__APPLE__) && (__MACH__)
74
+ fpunchhole_t fpunchhole;
75
+ fpunchhole.fp_flags = 0;
76
+ fpunchhole.reserved = 0;
77
+ fpunchhole.fp_offset = aiocb->aio_offset;
78
+ fpunchhole.fp_length = aiocb->aio_nbytes;
79
+ if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) == -1) {
80
+ ret = errno == ENODEV ? -ENOTSUP : -errno;
81
+ } else {
82
+ ret = 0;
83
+ }
84
#endif
85
}
86
87
- ret = translate_err(ret);
88
if (ret == -ENOTSUP) {
89
s->has_discard = false;
90
}
56
--
91
--
57
2.23.0
92
2.31.1
58
93
59
diff view generated by jsdifflib
1
From: Eduardo Habkost <ehabkost@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
Callers of create_image() will pass strings as arguments, but the
3
backend_defaults property allow users to control if default block
4
Image class will expect bytes objects to be provided. Encode
4
properties should be decided with backend information.
5
them inside create_image().
5
6
6
If it is off, any backend information will be discarded, which is
7
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7
suitable if you plan to perform live migration to a different disk backend.
8
Reviewed-by: John Snow <jsnow@redhat.com>
8
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
If it is on, a block device may utilize backend information more
10
Message-id: 20191016192430.25098-9-ehabkost@redhat.com
10
aggressively.
11
Message-Id: <20191016192430.25098-9-ehabkost@redhat.com>
11
12
By default, it is auto, which uses backend information for block
13
sizes and ignores the others, which is consistent with the older
14
versions.
15
16
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
17
Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
19
---
14
tests/image-fuzzer/qcow2/layout.py | 4 ++--
20
include/hw/block/block.h | 3 +++
15
1 file changed, 2 insertions(+), 2 deletions(-)
21
hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++----
16
22
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++
17
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
23
3 files changed, 79 insertions(+), 4 deletions(-)
24
25
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
18
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
19
--- a/tests/image-fuzzer/qcow2/layout.py
27
--- a/include/hw/block/block.h
20
+++ b/tests/image-fuzzer/qcow2/layout.py
28
+++ b/include/hw/block/block.h
21
@@ -XXX,XX +XXX,XX @@ class Image(object):
29
@@ -XXX,XX +XXX,XX @@
22
def create_image(test_img_path, backing_file_name=None, backing_file_fmt=None,
30
23
fields_to_fuzz=None):
31
typedef struct BlockConf {
24
"""Create a fuzzed image and write it to the specified file."""
32
BlockBackend *blk;
25
- image = Image(backing_file_name)
33
+ OnOffAuto backend_defaults;
26
- image.set_backing_file_format(backing_file_fmt)
34
uint32_t physical_block_size;
27
+ image = Image(backing_file_name.encode())
35
uint32_t logical_block_size;
28
+ image.set_backing_file_format(backing_file_fmt.encode())
36
uint32_t min_io_size;
29
image.create_feature_name_table()
37
@@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
30
image.set_end_of_extension_area()
38
}
31
image.create_l_structures()
39
40
#define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
41
+ DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \
42
+ _conf.backend_defaults, ON_OFF_AUTO_AUTO), \
43
DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
44
_conf.logical_block_size), \
45
DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
46
diff --git a/hw/block/block.c b/hw/block/block.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/hw/block/block.c
49
+++ b/hw/block/block.c
50
@@ -XXX,XX +XXX,XX @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp)
51
{
52
BlockBackend *blk = conf->blk;
53
BlockSizes blocksizes;
54
- int backend_ret;
55
+ BlockDriverState *bs;
56
+ bool use_blocksizes;
57
+ bool use_bs;
58
+
59
+ switch (conf->backend_defaults) {
60
+ case ON_OFF_AUTO_AUTO:
61
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
62
+ use_bs = false;
63
+ break;
64
+
65
+ case ON_OFF_AUTO_ON:
66
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
67
+ bs = blk_bs(blk);
68
+ use_bs = bs;
69
+ break;
70
+
71
+ case ON_OFF_AUTO_OFF:
72
+ use_blocksizes = false;
73
+ use_bs = false;
74
+ break;
75
+
76
+ default:
77
+ abort();
78
+ }
79
80
- backend_ret = blk_probe_blocksizes(blk, &blocksizes);
81
/* fill in detected values if they are not defined via qemu command line */
82
if (!conf->physical_block_size) {
83
- if (!backend_ret) {
84
+ if (use_blocksizes) {
85
conf->physical_block_size = blocksizes.phys;
86
} else {
87
conf->physical_block_size = BDRV_SECTOR_SIZE;
88
}
89
}
90
if (!conf->logical_block_size) {
91
- if (!backend_ret) {
92
+ if (use_blocksizes) {
93
conf->logical_block_size = blocksizes.log;
94
} else {
95
conf->logical_block_size = BDRV_SECTOR_SIZE;
96
}
97
}
98
+ if (use_bs) {
99
+ if (!conf->opt_io_size) {
100
+ conf->opt_io_size = bs->bl.opt_transfer;
101
+ }
102
+ if (conf->discard_granularity == -1) {
103
+ if (bs->bl.pdiscard_alignment) {
104
+ conf->discard_granularity = bs->bl.pdiscard_alignment;
105
+ } else if (bs->bl.request_alignment != 1) {
106
+ conf->discard_granularity = bs->bl.request_alignment;
107
+ }
108
+ }
109
+ }
110
111
if (conf->logical_block_size > conf->physical_block_size) {
112
error_setg(errp,
113
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
114
index XXXXXXX..XXXXXXX 100644
115
--- a/tests/qemu-iotests/172.out
116
+++ b/tests/qemu-iotests/172.out
117
@@ -XXX,XX +XXX,XX @@ Testing:
118
dev: floppy, id ""
119
unit = 0 (0x0)
120
drive = "floppy0"
121
+ backend_defaults = "auto"
122
logical_block_size = 512 (512 B)
123
physical_block_size = 512 (512 B)
124
min_io_size = 0 (0 B)
125
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2
126
dev: floppy, id ""
127
unit = 0 (0x0)
128
drive = "floppy0"
129
+ backend_defaults = "auto"
130
logical_block_size = 512 (512 B)
131
physical_block_size = 512 (512 B)
132
min_io_size = 0 (0 B)
133
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
134
dev: floppy, id ""
135
unit = 1 (0x1)
136
drive = "floppy1"
137
+ backend_defaults = "auto"
138
logical_block_size = 512 (512 B)
139
physical_block_size = 512 (512 B)
140
min_io_size = 0 (0 B)
141
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
142
dev: floppy, id ""
143
unit = 0 (0x0)
144
drive = "floppy0"
145
+ backend_defaults = "auto"
146
logical_block_size = 512 (512 B)
147
physical_block_size = 512 (512 B)
148
min_io_size = 0 (0 B)
149
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
150
dev: floppy, id ""
151
unit = 1 (0x1)
152
drive = "floppy1"
153
+ backend_defaults = "auto"
154
logical_block_size = 512 (512 B)
155
physical_block_size = 512 (512 B)
156
min_io_size = 0 (0 B)
157
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
158
dev: floppy, id ""
159
unit = 0 (0x0)
160
drive = "floppy0"
161
+ backend_defaults = "auto"
162
logical_block_size = 512 (512 B)
163
physical_block_size = 512 (512 B)
164
min_io_size = 0 (0 B)
165
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
166
dev: floppy, id ""
167
unit = 1 (0x1)
168
drive = "floppy1"
169
+ backend_defaults = "auto"
170
logical_block_size = 512 (512 B)
171
physical_block_size = 512 (512 B)
172
min_io_size = 0 (0 B)
173
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
174
dev: floppy, id ""
175
unit = 0 (0x0)
176
drive = "floppy0"
177
+ backend_defaults = "auto"
178
logical_block_size = 512 (512 B)
179
physical_block_size = 512 (512 B)
180
min_io_size = 0 (0 B)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2
182
dev: floppy, id ""
183
unit = 0 (0x0)
184
drive = "floppy0"
185
+ backend_defaults = "auto"
186
logical_block_size = 512 (512 B)
187
physical_block_size = 512 (512 B)
188
min_io_size = 0 (0 B)
189
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
190
dev: floppy, id ""
191
unit = 1 (0x1)
192
drive = "floppy1"
193
+ backend_defaults = "auto"
194
logical_block_size = 512 (512 B)
195
physical_block_size = 512 (512 B)
196
min_io_size = 0 (0 B)
197
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
198
dev: floppy, id ""
199
unit = 0 (0x0)
200
drive = "floppy0"
201
+ backend_defaults = "auto"
202
logical_block_size = 512 (512 B)
203
physical_block_size = 512 (512 B)
204
min_io_size = 0 (0 B)
205
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
206
dev: floppy, id ""
207
unit = 1 (0x1)
208
drive = "floppy1"
209
+ backend_defaults = "auto"
210
logical_block_size = 512 (512 B)
211
physical_block_size = 512 (512 B)
212
min_io_size = 0 (0 B)
213
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
214
dev: floppy, id ""
215
unit = 0 (0x0)
216
drive = "floppy0"
217
+ backend_defaults = "auto"
218
logical_block_size = 512 (512 B)
219
physical_block_size = 512 (512 B)
220
min_io_size = 0 (0 B)
221
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
222
dev: floppy, id ""
223
unit = 0 (0x0)
224
drive = "none0"
225
+ backend_defaults = "auto"
226
logical_block_size = 512 (512 B)
227
physical_block_size = 512 (512 B)
228
min_io_size = 0 (0 B)
229
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
230
dev: floppy, id ""
231
unit = 1 (0x1)
232
drive = "none0"
233
+ backend_defaults = "auto"
234
logical_block_size = 512 (512 B)
235
physical_block_size = 512 (512 B)
236
min_io_size = 0 (0 B)
237
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
238
dev: floppy, id ""
239
unit = 1 (0x1)
240
drive = "none1"
241
+ backend_defaults = "auto"
242
logical_block_size = 512 (512 B)
243
physical_block_size = 512 (512 B)
244
min_io_size = 0 (0 B)
245
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
246
dev: floppy, id ""
247
unit = 0 (0x0)
248
drive = "none0"
249
+ backend_defaults = "auto"
250
logical_block_size = 512 (512 B)
251
physical_block_size = 512 (512 B)
252
min_io_size = 0 (0 B)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
254
dev: floppy, id ""
255
unit = 1 (0x1)
256
drive = "none0"
257
+ backend_defaults = "auto"
258
logical_block_size = 512 (512 B)
259
physical_block_size = 512 (512 B)
260
min_io_size = 0 (0 B)
261
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
262
dev: floppy, id ""
263
unit = 0 (0x0)
264
drive = "floppy0"
265
+ backend_defaults = "auto"
266
logical_block_size = 512 (512 B)
267
physical_block_size = 512 (512 B)
268
min_io_size = 0 (0 B)
269
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
270
dev: floppy, id ""
271
unit = 1 (0x1)
272
drive = "none0"
273
+ backend_defaults = "auto"
274
logical_block_size = 512 (512 B)
275
physical_block_size = 512 (512 B)
276
min_io_size = 0 (0 B)
277
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
278
dev: floppy, id ""
279
unit = 0 (0x0)
280
drive = "floppy0"
281
+ backend_defaults = "auto"
282
logical_block_size = 512 (512 B)
283
physical_block_size = 512 (512 B)
284
min_io_size = 0 (0 B)
285
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
286
dev: floppy, id ""
287
unit = 0 (0x0)
288
drive = "none0"
289
+ backend_defaults = "auto"
290
logical_block_size = 512 (512 B)
291
physical_block_size = 512 (512 B)
292
min_io_size = 0 (0 B)
293
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
294
dev: floppy, id ""
295
unit = 1 (0x1)
296
drive = "floppy1"
297
+ backend_defaults = "auto"
298
logical_block_size = 512 (512 B)
299
physical_block_size = 512 (512 B)
300
min_io_size = 0 (0 B)
301
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
302
dev: floppy, id ""
303
unit = 0 (0x0)
304
drive = "none0"
305
+ backend_defaults = "auto"
306
logical_block_size = 512 (512 B)
307
physical_block_size = 512 (512 B)
308
min_io_size = 0 (0 B)
309
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
310
dev: floppy, id ""
311
unit = 1 (0x1)
312
drive = "floppy1"
313
+ backend_defaults = "auto"
314
logical_block_size = 512 (512 B)
315
physical_block_size = 512 (512 B)
316
min_io_size = 0 (0 B)
317
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
318
dev: floppy, id ""
319
unit = 1 (0x1)
320
drive = "none0"
321
+ backend_defaults = "auto"
322
logical_block_size = 512 (512 B)
323
physical_block_size = 512 (512 B)
324
min_io_size = 0 (0 B)
325
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
326
dev: floppy, id ""
327
unit = 0 (0x0)
328
drive = "floppy0"
329
+ backend_defaults = "auto"
330
logical_block_size = 512 (512 B)
331
physical_block_size = 512 (512 B)
332
min_io_size = 0 (0 B)
333
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
334
dev: floppy, id ""
335
unit = 1 (0x1)
336
drive = "none0"
337
+ backend_defaults = "auto"
338
logical_block_size = 512 (512 B)
339
physical_block_size = 512 (512 B)
340
min_io_size = 0 (0 B)
341
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
342
dev: floppy, id ""
343
unit = 0 (0x0)
344
drive = "floppy0"
345
+ backend_defaults = "auto"
346
logical_block_size = 512 (512 B)
347
physical_block_size = 512 (512 B)
348
min_io_size = 0 (0 B)
349
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device
350
dev: floppy, id ""
351
unit = 0 (0x0)
352
drive = "none0"
353
+ backend_defaults = "auto"
354
logical_block_size = 512 (512 B)
355
physical_block_size = 512 (512 B)
356
min_io_size = 0 (0 B)
357
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy
358
dev: floppy, id ""
359
unit = 0 (0x0)
360
drive = ""
361
+ backend_defaults = "auto"
362
logical_block_size = 512 (512 B)
363
physical_block_size = 512 (512 B)
364
min_io_size = 0 (0 B)
365
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=120
366
dev: floppy, id ""
367
unit = 0 (0x0)
368
drive = ""
369
+ backend_defaults = "auto"
370
logical_block_size = 512 (512 B)
371
physical_block_size = 512 (512 B)
372
min_io_size = 0 (0 B)
373
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=144
374
dev: floppy, id ""
375
unit = 0 (0x0)
376
drive = ""
377
+ backend_defaults = "auto"
378
logical_block_size = 512 (512 B)
379
physical_block_size = 512 (512 B)
380
min_io_size = 0 (0 B)
381
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=288
382
dev: floppy, id ""
383
unit = 0 (0x0)
384
drive = ""
385
+ backend_defaults = "auto"
386
logical_block_size = 512 (512 B)
387
physical_block_size = 512 (512 B)
388
min_io_size = 0 (0 B)
389
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
390
dev: floppy, id ""
391
unit = 0 (0x0)
392
drive = "none0"
393
+ backend_defaults = "auto"
394
logical_block_size = 512 (512 B)
395
physical_block_size = 512 (512 B)
396
min_io_size = 0 (0 B)
397
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
398
dev: floppy, id ""
399
unit = 0 (0x0)
400
drive = "none0"
401
+ backend_defaults = "auto"
402
logical_block_size = 512 (512 B)
403
physical_block_size = 512 (512 B)
404
min_io_size = 0 (0 B)
405
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical
406
dev: floppy, id ""
407
unit = 0 (0x0)
408
drive = "none0"
409
+ backend_defaults = "auto"
410
logical_block_size = 512 (512 B)
411
physical_block_size = 512 (512 B)
412
min_io_size = 0 (0 B)
413
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica
414
dev: floppy, id ""
415
unit = 0 (0x0)
416
drive = "none0"
417
+ backend_defaults = "auto"
418
logical_block_size = 512 (512 B)
419
physical_block_size = 512 (512 B)
420
min_io_size = 0 (0 B)
32
--
421
--
33
2.23.0
422
2.31.1
34
423
35
diff view generated by jsdifflib
1
From: Eduardo Habkost <ehabkost@redhat.com>
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
2
2
3
Field values are supposed to be bytes objects, not unicode
3
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
4
strings. Change two constants that were declared as strings.
4
Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com
5
6
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
7
Reviewed-by: John Snow <jsnow@redhat.com>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20191016192430.25098-8-ehabkost@redhat.com
10
Message-Id: <20191016192430.25098-8-ehabkost@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
6
---
13
tests/image-fuzzer/qcow2/layout.py | 4 ++--
7
block/io.c | 2 ++
14
1 file changed, 2 insertions(+), 2 deletions(-)
8
1 file changed, 2 insertions(+)
15
9
16
diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py
10
diff --git a/block/io.c b/block/io.c
17
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/image-fuzzer/qcow2/layout.py
12
--- a/block/io.c
19
+++ b/tests/image-fuzzer/qcow2/layout.py
13
+++ b/block/io.c
20
@@ -XXX,XX +XXX,XX @@ class Image(object):
14
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
21
def create_header(self, cluster_bits, backing_file_name=None):
15
22
"""Generate a random valid header."""
16
static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
23
meta_header = [
17
{
24
- ['>4s', 0, "QFI\xfb", 'magic'],
18
+ dst->pdiscard_alignment = MAX(dst->pdiscard_alignment,
25
+ ['>4s', 0, b"QFI\xfb", 'magic'],
19
+ src->pdiscard_alignment);
26
['>I', 4, random.randint(2, 3), 'version'],
20
dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer);
27
['>Q', 8, 0, 'backing_file_offset'],
21
dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer);
28
['>I', 16, 0, 'backing_file_size'],
22
dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer,
29
@@ -XXX,XX +XXX,XX @@ class Image(object):
30
feature_tables = []
31
feature_ids = []
32
inner_offset = self.ext_offset + ext_header_len
33
- feat_name = 'some cool feature'
34
+ feat_name = b'some cool feature'
35
while len(feature_tables) < num_fnt_entries * 3:
36
feat_type, feat_bit = gen_feat_ids()
37
# Remove duplicates
38
--
23
--
39
2.23.0
24
2.31.1
40
25
41
diff view generated by jsdifflib