1 | The following changes since commit a0def594286d9110a6035e02eef558cf3cf5d847: | 1 | The following changes since commit 36609b4fa36f0ac934874371874416f7533a5408: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-01-30 10:23:20 +0000) | 3 | Merge remote-tracking branch 'remotes/palmer/tags/palmer-for-master-4.2-sf1' into staging (2019-11-02 17:59:03 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request | 7 | https://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to acf6e5f0962c4be670d4a93ede77423512521876: | 9 | for you to fetch changes up to 9fdd7860adec188ed50d2530e9a819e8d953f9bb: |
10 | 10 | ||
11 | sheepdog: reorganize check for overlapping requests (2017-02-01 00:17:20 -0500) | 11 | image-fuzzer: Use OSerror.strerror instead of tuple subscript (2019-11-05 16:36:11 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches | 14 | Pull request |
15 | |||
16 | Let's get the image fuzzer Python 3 changes merged in QEMU 4.2. | ||
17 | |||
15 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
16 | 19 | ||
17 | Paolo Bonzini (5): | 20 | Eduardo Habkost (11): |
18 | sheepdog: remove unused cancellation support | 21 | image-fuzzer: Open image files in binary mode |
19 | sheepdog: reorganize coroutine flow | 22 | image-fuzzer: Write bytes instead of string to image file |
20 | sheepdog: do not use BlockAIOCB | 23 | image-fuzzer: Explicitly use integer division operator |
21 | sheepdog: simplify inflight_aio_head management | 24 | image-fuzzer: Use io.StringIO |
22 | sheepdog: reorganize check for overlapping requests | 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 | ||
23 | 32 | ||
24 | block/sheepdog.c | 289 ++++++++++++++++--------------------------------------- | 33 | tests/image-fuzzer/qcow2/__init__.py | 1 - |
25 | 1 file changed, 84 insertions(+), 205 deletions(-) | 34 | tests/image-fuzzer/qcow2/fuzz.py | 54 +++++++++++++------------- |
35 | tests/image-fuzzer/qcow2/layout.py | 57 ++++++++++++++-------------- | ||
36 | tests/image-fuzzer/runner.py | 16 ++++---- | ||
37 | 4 files changed, 63 insertions(+), 65 deletions(-) | ||
26 | 38 | ||
27 | -- | 39 | -- |
28 | 2.9.3 | 40 | 2.23.0 |
29 | 41 | ||
30 | 42 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eduardo Habkost <ehabkost@redhat.com> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Eduardo Habkost <ehabkost@redhat.com> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | 1 | From: Eduardo Habkost <ehabkost@redhat.com> | |
2 | |||
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 |
New patch | |||
---|---|---|---|
1 | From: Eduardo Habkost <ehabkost@redhat.com> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Eduardo Habkost <ehabkost@redhat.com> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Eduardo Habkost <ehabkost@redhat.com> | ||
1 | 2 | ||
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: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Eduardo Habkost <ehabkost@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Add to the list in add_aio_request and, indirectly, resend_aioreq. Inline | 3 | Field values are supposed to be bytes objects, not unicode |
4 | free_aio_req in the caller, it does not simply undo alloc_aio_req's job. | 4 | strings. Change two constants that were declared as strings. |
5 | 5 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 6 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
7 | Message-id: 20161129113245.32724-5-pbonzini@redhat.com | 7 | Reviewed-by: John Snow <jsnow@redhat.com> |
8 | Signed-off-by: Jeff Cody <jcody@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> | ||
9 | --- | 12 | --- |
10 | block/sheepdog.c | 23 ++++++----------------- | 13 | tests/image-fuzzer/qcow2/layout.py | 4 ++-- |
11 | 1 file changed, 6 insertions(+), 17 deletions(-) | 14 | 1 file changed, 2 insertions(+), 2 deletions(-) |
12 | 15 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 16 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/sheepdog.c | 18 | --- a/tests/image-fuzzer/qcow2/layout.py |
16 | +++ b/block/sheepdog.c | 19 | +++ b/tests/image-fuzzer/qcow2/layout.py |
17 | @@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | 20 | @@ -XXX,XX +XXX,XX @@ class Image(object): |
18 | return aio_req; | 21 | def create_header(self, cluster_bits, backing_file_name=None): |
19 | } | 22 | """Generate a random valid header.""" |
20 | 23 | meta_header = [ | |
21 | -static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | 24 | - ['>4s', 0, "QFI\xfb", 'magic'], |
22 | -{ | 25 | + ['>4s', 0, b"QFI\xfb", 'magic'], |
23 | - SheepdogAIOCB *acb = aio_req->aiocb; | 26 | ['>I', 4, random.randint(2, 3), 'version'], |
24 | - | 27 | ['>Q', 8, 0, 'backing_file_offset'], |
25 | - QLIST_REMOVE(aio_req, aio_siblings); | 28 | ['>I', 16, 0, 'backing_file_size'], |
26 | - g_free(aio_req); | 29 | @@ -XXX,XX +XXX,XX @@ class Image(object): |
27 | - | 30 | feature_tables = [] |
28 | - acb->nr_pending--; | 31 | feature_ids = [] |
29 | -} | 32 | inner_offset = self.ext_offset + ext_header_len |
30 | - | 33 | - feat_name = 'some cool feature' |
31 | static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | 34 | + feat_name = b'some cool feature' |
32 | QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | 35 | while len(feature_tables) < num_fnt_entries * 3: |
33 | int type) | 36 | feat_type, feat_bit = gen_feat_ids() |
34 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void reconnect_to_sdog(void *opaque) | 37 | # Remove duplicates |
35 | while (!QLIST_EMPTY(&s->failed_aio_head)) { | ||
36 | aio_req = QLIST_FIRST(&s->failed_aio_head); | ||
37 | QLIST_REMOVE(aio_req, aio_siblings); | ||
38 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
39 | resend_aioreq(s, aio_req); | ||
40 | } | ||
41 | } | ||
42 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
43 | */ | ||
44 | s->co_recv = NULL; | ||
45 | |||
46 | + QLIST_REMOVE(aio_req, aio_siblings); | ||
47 | switch (rsp.result) { | ||
48 | case SD_RES_SUCCESS: | ||
49 | break; | ||
50 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
51 | break; | ||
52 | } | ||
53 | |||
54 | - free_aio_req(s, aio_req); | ||
55 | - if (!acb->nr_pending) { | ||
56 | + g_free(aio_req); | ||
57 | + | ||
58 | + if (!--acb->nr_pending) { | ||
59 | /* | ||
60 | * We've finished all requests which belong to the AIOCB, so | ||
61 | * we can switch back to sd_co_readv/writev now. | ||
62 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, | ||
63 | uint64_t old_oid = aio_req->base_oid; | ||
64 | bool create = aio_req->create; | ||
65 | |||
66 | + QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
67 | + | ||
68 | if (!nr_copies) { | ||
69 | error_report("bug"); | ||
70 | } | ||
71 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
72 | iov.iov_len = sizeof(s->inode); | ||
73 | aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
74 | data_len, offset, 0, false, 0, offset); | ||
75 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
76 | add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); | ||
77 | if (--acb->nr_pending) { | ||
78 | qemu_coroutine_yield(); | ||
79 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | ||
80 | old_oid, | ||
81 | acb->aiocb_type == AIOCB_DISCARD_OBJ ? | ||
82 | 0 : done); | ||
83 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
84 | - | ||
85 | add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, | ||
86 | acb->aiocb_type); | ||
87 | done: | ||
88 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
89 | acb.nr_pending++; | ||
90 | aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
91 | 0, 0, 0, false, 0, 0); | ||
92 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
93 | add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); | ||
94 | |||
95 | if (--acb.nr_pending) { | ||
96 | -- | 38 | -- |
97 | 2.9.3 | 39 | 2.23.0 |
98 | 40 | ||
99 | 41 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Eduardo Habkost <ehabkost@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Sheepdog's AIOCB are completely internal entities for a group of | 3 | Callers of create_image() will pass strings as arguments, but the |
4 | requests and do not need dynamic allocation. | 4 | Image class will expect bytes objects to be provided. Encode |
5 | them inside create_image(). | ||
5 | 6 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
7 | Message-id: 20161129113245.32724-4-pbonzini@redhat.com | 8 | Reviewed-by: John Snow <jsnow@redhat.com> |
8 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
10 | Message-id: 20191016192430.25098-9-ehabkost@redhat.com | ||
11 | Message-Id: <20191016192430.25098-9-ehabkost@redhat.com> | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 13 | --- |
10 | block/sheepdog.c | 99 ++++++++++++++++++++++---------------------------------- | 14 | tests/image-fuzzer/qcow2/layout.py | 4 ++-- |
11 | 1 file changed, 39 insertions(+), 60 deletions(-) | 15 | 1 file changed, 2 insertions(+), 2 deletions(-) |
12 | 16 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 17 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py |
14 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/sheepdog.c | 19 | --- a/tests/image-fuzzer/qcow2/layout.py |
16 | +++ b/block/sheepdog.c | 20 | +++ b/tests/image-fuzzer/qcow2/layout.py |
17 | @@ -XXX,XX +XXX,XX @@ static inline size_t count_data_objs(const struct SheepdogInode *inode) | 21 | @@ -XXX,XX +XXX,XX @@ class Image(object): |
18 | } while (0) | 22 | def create_image(test_img_path, backing_file_name=None, backing_file_fmt=None, |
19 | 23 | fields_to_fuzz=None): | |
20 | typedef struct SheepdogAIOCB SheepdogAIOCB; | 24 | """Create a fuzzed image and write it to the specified file.""" |
21 | +typedef struct BDRVSheepdogState BDRVSheepdogState; | 25 | - image = Image(backing_file_name) |
22 | 26 | - image.set_backing_file_format(backing_file_fmt) | |
23 | typedef struct AIOReq { | 27 | + image = Image(backing_file_name.encode()) |
24 | SheepdogAIOCB *aiocb; | 28 | + image.set_backing_file_format(backing_file_fmt.encode()) |
25 | @@ -XXX,XX +XXX,XX @@ enum AIOCBState { | 29 | image.create_feature_name_table() |
26 | || y->max_affect_data_idx < x->min_affect_data_idx)) | 30 | image.set_end_of_extension_area() |
27 | 31 | image.create_l_structures() | |
28 | struct SheepdogAIOCB { | ||
29 | - BlockAIOCB common; | ||
30 | + BDRVSheepdogState *s; | ||
31 | |||
32 | QEMUIOVector *qiov; | ||
33 | |||
34 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | ||
35 | QLIST_ENTRY(SheepdogAIOCB) aiocb_siblings; | ||
36 | }; | ||
37 | |||
38 | -typedef struct BDRVSheepdogState { | ||
39 | +struct BDRVSheepdogState { | ||
40 | BlockDriverState *bs; | ||
41 | AioContext *aio_context; | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVSheepdogState { | ||
44 | |||
45 | CoQueue overlapping_queue; | ||
46 | QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; | ||
47 | -} BDRVSheepdogState; | ||
48 | +}; | ||
49 | |||
50 | typedef struct BDRVSheepdogReopenState { | ||
51 | int fd; | ||
52 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | ||
53 | acb->nr_pending--; | ||
54 | } | ||
55 | |||
56 | -static const AIOCBInfo sd_aiocb_info = { | ||
57 | - .aiocb_size = sizeof(SheepdogAIOCB), | ||
58 | -}; | ||
59 | - | ||
60 | -static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
61 | - int64_t sector_num, int nb_sectors) | ||
62 | +static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
63 | + QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | ||
64 | + int type) | ||
65 | { | ||
66 | - SheepdogAIOCB *acb; | ||
67 | uint32_t object_size; | ||
68 | - BDRVSheepdogState *s = bs->opaque; | ||
69 | |||
70 | object_size = (UINT32_C(1) << s->inode.block_size_shift); | ||
71 | |||
72 | - acb = qemu_aio_get(&sd_aiocb_info, bs, NULL, NULL); | ||
73 | + acb->s = s; | ||
74 | |||
75 | acb->qiov = qiov; | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
78 | |||
79 | acb->min_dirty_data_idx = UINT32_MAX; | ||
80 | acb->max_dirty_data_idx = 0; | ||
81 | - | ||
82 | - return acb; | ||
83 | + acb->aiocb_type = type; | ||
84 | } | ||
85 | |||
86 | /* Return -EIO in case of error, file descriptor on success */ | ||
87 | @@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset) | ||
88 | */ | ||
89 | static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
90 | { | ||
91 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
92 | + BDRVSheepdogState *s = acb->s; | ||
93 | struct iovec iov; | ||
94 | AIOReq *aio_req; | ||
95 | uint32_t offset, data_len, mn, mx; | ||
96 | @@ -XXX,XX +XXX,XX @@ out: | ||
97 | * Returns 1 when we need to wait a response, 0 when there is no sent | ||
98 | * request and -errno in error cases. | ||
99 | */ | ||
100 | -static void coroutine_fn sd_co_rw_vector(void *p) | ||
101 | +static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | ||
102 | { | ||
103 | - SheepdogAIOCB *acb = p; | ||
104 | int ret = 0; | ||
105 | unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE; | ||
106 | unsigned long idx; | ||
107 | uint32_t object_size; | ||
108 | uint64_t oid; | ||
109 | uint64_t offset; | ||
110 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
111 | + BDRVSheepdogState *s = acb->s; | ||
112 | SheepdogInode *inode = &s->inode; | ||
113 | AIOReq *aio_req; | ||
114 | |||
115 | @@ -XXX,XX +XXX,XX @@ static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
116 | static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
117 | int nb_sectors, QEMUIOVector *qiov) | ||
118 | { | ||
119 | - SheepdogAIOCB *acb; | ||
120 | + SheepdogAIOCB acb; | ||
121 | int ret; | ||
122 | int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE; | ||
123 | BDRVSheepdogState *s = bs->opaque; | ||
124 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
125 | } | ||
126 | } | ||
127 | |||
128 | - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
129 | - acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
130 | + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); | ||
131 | |||
132 | retry: | ||
133 | - if (check_overlapping_aiocb(s, acb)) { | ||
134 | + if (check_overlapping_aiocb(s, &acb)) { | ||
135 | qemu_co_queue_wait(&s->overlapping_queue); | ||
136 | goto retry; | ||
137 | } | ||
138 | |||
139 | - sd_co_rw_vector(acb); | ||
140 | - sd_write_done(acb); | ||
141 | + sd_co_rw_vector(&acb); | ||
142 | + sd_write_done(&acb); | ||
143 | |||
144 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
145 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
146 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
147 | - ret = acb->ret; | ||
148 | - qemu_aio_unref(acb); | ||
149 | - return ret; | ||
150 | + return acb.ret; | ||
151 | } | ||
152 | |||
153 | static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
154 | int nb_sectors, QEMUIOVector *qiov) | ||
155 | { | ||
156 | - SheepdogAIOCB *acb; | ||
157 | - int ret; | ||
158 | + SheepdogAIOCB acb; | ||
159 | BDRVSheepdogState *s = bs->opaque; | ||
160 | |||
161 | - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
162 | - acb->aiocb_type = AIOCB_READ_UDATA; | ||
163 | + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); | ||
164 | |||
165 | retry: | ||
166 | - if (check_overlapping_aiocb(s, acb)) { | ||
167 | + if (check_overlapping_aiocb(s, &acb)) { | ||
168 | qemu_co_queue_wait(&s->overlapping_queue); | ||
169 | goto retry; | ||
170 | } | ||
171 | |||
172 | - sd_co_rw_vector(acb); | ||
173 | + sd_co_rw_vector(&acb); | ||
174 | |||
175 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
176 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
177 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
178 | - ret = acb->ret; | ||
179 | - qemu_aio_unref(acb); | ||
180 | - return ret; | ||
181 | + return acb.ret; | ||
182 | } | ||
183 | |||
184 | static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
185 | { | ||
186 | BDRVSheepdogState *s = bs->opaque; | ||
187 | - SheepdogAIOCB *acb; | ||
188 | - int ret; | ||
189 | + SheepdogAIOCB acb; | ||
190 | AIOReq *aio_req; | ||
191 | |||
192 | if (s->cache_flags != SD_FLAG_CMD_CACHE) { | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | - acb = sd_aio_setup(bs, NULL, 0, 0); | ||
197 | - acb->aiocb_type = AIOCB_FLUSH_CACHE; | ||
198 | + sd_aio_setup(&acb, s, NULL, 0, 0, AIOCB_FLUSH_CACHE); | ||
199 | |||
200 | - acb->nr_pending++; | ||
201 | - aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
202 | + acb.nr_pending++; | ||
203 | + aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
204 | 0, 0, 0, false, 0, 0); | ||
205 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
206 | - add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); | ||
207 | + add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); | ||
208 | |||
209 | - if (--acb->nr_pending) { | ||
210 | + if (--acb.nr_pending) { | ||
211 | qemu_coroutine_yield(); | ||
212 | } | ||
213 | - ret = acb->ret; | ||
214 | - qemu_aio_unref(acb); | ||
215 | - return ret; | ||
216 | + return acb.ret; | ||
217 | } | ||
218 | |||
219 | static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
220 | @@ -XXX,XX +XXX,XX @@ static int sd_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, | ||
221 | static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
222 | int count) | ||
223 | { | ||
224 | - SheepdogAIOCB *acb; | ||
225 | + SheepdogAIOCB acb; | ||
226 | BDRVSheepdogState *s = bs->opaque; | ||
227 | - int ret; | ||
228 | QEMUIOVector discard_iov; | ||
229 | struct iovec iov; | ||
230 | uint32_t zero = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
232 | if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { | ||
233 | return -ENOTSUP; | ||
234 | } | ||
235 | - acb = sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
236 | - count >> BDRV_SECTOR_BITS); | ||
237 | - acb->aiocb_type = AIOCB_DISCARD_OBJ; | ||
238 | + sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
239 | + count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); | ||
240 | |||
241 | retry: | ||
242 | - if (check_overlapping_aiocb(s, acb)) { | ||
243 | + if (check_overlapping_aiocb(s, &acb)) { | ||
244 | qemu_co_queue_wait(&s->overlapping_queue); | ||
245 | goto retry; | ||
246 | } | ||
247 | |||
248 | - sd_co_rw_vector(acb); | ||
249 | + sd_co_rw_vector(&acb); | ||
250 | |||
251 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
252 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
253 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
254 | - ret = acb->ret; | ||
255 | - qemu_aio_unref(acb); | ||
256 | - return ret; | ||
257 | + return acb.ret; | ||
258 | } | ||
259 | |||
260 | static coroutine_fn int64_t | ||
261 | -- | 32 | -- |
262 | 2.9.3 | 33 | 2.23.0 |
263 | 34 | ||
264 | 35 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Eduardo Habkost <ehabkost@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Delimit co_recv's lifetime clearly in aio_read_response. | 3 | image-fuzzer is now supposed to be ready to run using Python 3. |
4 | Remove the __future__ imports and change the interpreter line to | ||
5 | "#!/usr/bin/env python3". | ||
4 | 6 | ||
5 | Do a simple qemu_coroutine_enter in aio_read_response, letting | 7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
6 | sd_co_writev call sd_write_done. | 8 | Reviewed-by: John Snow <jsnow@redhat.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20191016192430.25098-10-ehabkost@redhat.com | ||
11 | Message-Id: <20191016192430.25098-10-ehabkost@redhat.com> | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | tests/image-fuzzer/qcow2/__init__.py | 1 - | ||
15 | tests/image-fuzzer/qcow2/layout.py | 1 - | ||
16 | tests/image-fuzzer/runner.py | 3 +-- | ||
17 | 3 files changed, 1 insertion(+), 4 deletions(-) | ||
7 | 18 | ||
8 | Handle nr_pending in the same way in sd_co_rw_vector, | 19 | diff --git a/tests/image-fuzzer/qcow2/__init__.py b/tests/image-fuzzer/qcow2/__init__.py |
9 | sd_write_done and sd_co_flush_to_disk. | ||
10 | |||
11 | Remove sd_co_rw_vector's return value; just leave with no | ||
12 | pending requests. | ||
13 | |||
14 | [Jeff: added missing 'return' back, spotted by Paolo after | ||
15 | series was applied.] | ||
16 | |||
17 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
18 | --- | ||
19 | block/sheepdog.c | 115 ++++++++++++++++++++----------------------------------- | ||
20 | 1 file changed, 42 insertions(+), 73 deletions(-) | ||
21 | |||
22 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/block/sheepdog.c | 21 | --- a/tests/image-fuzzer/qcow2/__init__.py |
25 | +++ b/block/sheepdog.c | 22 | +++ b/tests/image-fuzzer/qcow2/__init__.py |
26 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | 23 | @@ -1,2 +1 @@ |
27 | enum AIOCBState aiocb_type; | 24 | -from __future__ import absolute_import |
28 | 25 | from .layout import create_image | |
29 | Coroutine *coroutine; | 26 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py |
30 | - void (*aio_done_func)(SheepdogAIOCB *); | 27 | index XXXXXXX..XXXXXXX 100644 |
31 | - | 28 | --- a/tests/image-fuzzer/qcow2/layout.py |
32 | int nr_pending; | 29 | +++ b/tests/image-fuzzer/qcow2/layout.py |
33 | 30 | @@ -XXX,XX +XXX,XX @@ | |
34 | uint32_t min_affect_data_idx; | 31 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | @@ -XXX,XX +XXX,XX @@ static const char * sd_strerror(int err) | 32 | # |
36 | * | 33 | |
37 | * 1. In sd_co_rw_vector, we send the I/O requests to the server and | 34 | -from __future__ import absolute_import |
38 | * link the requests to the inflight_list in the | 35 | import random |
39 | - * BDRVSheepdogState. The function exits without waiting for | 36 | import struct |
40 | + * BDRVSheepdogState. The function yields while waiting for | 37 | from . import fuzz |
41 | * receiving the response. | 38 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py |
42 | * | 39 | index XXXXXXX..XXXXXXX 100755 |
43 | * 2. We receive the response in aio_read_response, the fd handler to | 40 | --- a/tests/image-fuzzer/runner.py |
44 | - * the sheepdog connection. If metadata update is needed, we send | 41 | +++ b/tests/image-fuzzer/runner.py |
45 | - * the write request to the vdi object in sd_write_done, the write | 42 | @@ -XXX,XX +XXX,XX @@ |
46 | - * completion function. We switch back to sd_co_readv/writev after | 43 | -#!/usr/bin/env python |
47 | - * all the requests belonging to the AIOCB are finished. | 44 | +#!/usr/bin/env python3 |
48 | + * the sheepdog connection. We switch back to sd_co_readv/sd_writev | 45 | |
49 | + * after all the requests belonging to the AIOCB are finished. If | 46 | # Tool for running fuzz tests |
50 | + * needed, sd_co_writev will send another requests for the vdi object. | 47 | # |
51 | */ | 48 | @@ -XXX,XX +XXX,XX @@ |
52 | 49 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
53 | static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | 50 | # |
54 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | 51 | |
55 | acb->nr_pending--; | 52 | -from __future__ import print_function |
56 | } | 53 | import sys |
57 | 54 | import os | |
58 | -static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) | 55 | import signal |
59 | -{ | ||
60 | - qemu_coroutine_enter(acb->coroutine); | ||
61 | - qemu_aio_unref(acb); | ||
62 | -} | ||
63 | - | ||
64 | static const AIOCBInfo sd_aiocb_info = { | ||
65 | .aiocb_size = sizeof(SheepdogAIOCB), | ||
66 | }; | ||
67 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
68 | acb->sector_num = sector_num; | ||
69 | acb->nb_sectors = nb_sectors; | ||
70 | |||
71 | - acb->aio_done_func = NULL; | ||
72 | acb->coroutine = qemu_coroutine_self(); | ||
73 | acb->ret = 0; | ||
74 | acb->nr_pending = 0; | ||
75 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
76 | |||
77 | switch (acb->aiocb_type) { | ||
78 | case AIOCB_WRITE_UDATA: | ||
79 | - /* this coroutine context is no longer suitable for co_recv | ||
80 | - * because we may send data to update vdi objects */ | ||
81 | - s->co_recv = NULL; | ||
82 | if (!is_data_obj(aio_req->oid)) { | ||
83 | break; | ||
84 | } | ||
85 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | + /* No more data for this aio_req (reload_inode below uses its own file | ||
90 | + * descriptor handler which doesn't use co_recv). | ||
91 | + */ | ||
92 | + s->co_recv = NULL; | ||
93 | + | ||
94 | switch (rsp.result) { | ||
95 | case SD_RES_SUCCESS: | ||
96 | break; | ||
97 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
98 | aio_req->oid = vid_to_vdi_oid(s->inode.vdi_id); | ||
99 | } | ||
100 | resend_aioreq(s, aio_req); | ||
101 | - goto out; | ||
102 | + return; | ||
103 | default: | ||
104 | acb->ret = -EIO; | ||
105 | error_report("%s", sd_strerror(rsp.result)); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
107 | * We've finished all requests which belong to the AIOCB, so | ||
108 | * we can switch back to sd_co_readv/writev now. | ||
109 | */ | ||
110 | - acb->aio_done_func(acb); | ||
111 | + qemu_coroutine_enter(acb->coroutine); | ||
112 | } | ||
113 | -out: | ||
114 | - s->co_recv = NULL; | ||
115 | + | ||
116 | return; | ||
117 | + | ||
118 | err: | ||
119 | - s->co_recv = NULL; | ||
120 | reconnect_to_sdog(opaque); | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset) | ||
124 | /* | ||
125 | * This function is called after writing data objects. If we need to | ||
126 | * update metadata, this sends a write request to the vdi object. | ||
127 | - * Otherwise, this switches back to sd_co_readv/writev. | ||
128 | */ | ||
129 | static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
130 | { | ||
131 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
132 | mx = acb->max_dirty_data_idx; | ||
133 | if (mn <= mx) { | ||
134 | /* we need to update the vdi object. */ | ||
135 | + ++acb->nr_pending; | ||
136 | offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) + | ||
137 | mn * sizeof(s->inode.data_vdi_id[0]); | ||
138 | data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]); | ||
139 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
140 | data_len, offset, 0, false, 0, offset); | ||
141 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
142 | add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); | ||
143 | - | ||
144 | - acb->aio_done_func = sd_finish_aiocb; | ||
145 | - acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
146 | - return; | ||
147 | + if (--acb->nr_pending) { | ||
148 | + qemu_coroutine_yield(); | ||
149 | + } | ||
150 | } | ||
151 | - | ||
152 | - sd_finish_aiocb(acb); | ||
153 | } | ||
154 | |||
155 | /* Delete current working VDI on the snapshot chain */ | ||
156 | @@ -XXX,XX +XXX,XX @@ out: | ||
157 | * Returns 1 when we need to wait a response, 0 when there is no sent | ||
158 | * request and -errno in error cases. | ||
159 | */ | ||
160 | -static int coroutine_fn sd_co_rw_vector(void *p) | ||
161 | +static void coroutine_fn sd_co_rw_vector(void *p) | ||
162 | { | ||
163 | SheepdogAIOCB *acb = p; | ||
164 | int ret = 0; | ||
165 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_rw_vector(void *p) | ||
166 | ret = sd_create_branch(s); | ||
167 | if (ret) { | ||
168 | acb->ret = -EIO; | ||
169 | - goto out; | ||
170 | + return; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_rw_vector(void *p) | ||
175 | idx++; | ||
176 | done += len; | ||
177 | } | ||
178 | -out: | ||
179 | - if (!--acb->nr_pending) { | ||
180 | - return acb->ret; | ||
181 | + if (--acb->nr_pending) { | ||
182 | + qemu_coroutine_yield(); | ||
183 | } | ||
184 | - return 1; | ||
185 | } | ||
186 | |||
187 | static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
188 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
189 | } | ||
190 | |||
191 | acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
192 | - acb->aio_done_func = sd_write_done; | ||
193 | acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
194 | |||
195 | retry: | ||
196 | @@ -XXX,XX +XXX,XX @@ retry: | ||
197 | goto retry; | ||
198 | } | ||
199 | |||
200 | - ret = sd_co_rw_vector(acb); | ||
201 | - if (ret <= 0) { | ||
202 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
203 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
204 | - qemu_aio_unref(acb); | ||
205 | - return ret; | ||
206 | - } | ||
207 | - | ||
208 | - qemu_coroutine_yield(); | ||
209 | + sd_co_rw_vector(acb); | ||
210 | + sd_write_done(acb); | ||
211 | |||
212 | QLIST_REMOVE(acb, aiocb_siblings); | ||
213 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
214 | - | ||
215 | - return acb->ret; | ||
216 | + ret = acb->ret; | ||
217 | + qemu_aio_unref(acb); | ||
218 | + return ret; | ||
219 | } | ||
220 | |||
221 | static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
222 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
223 | |||
224 | acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
225 | acb->aiocb_type = AIOCB_READ_UDATA; | ||
226 | - acb->aio_done_func = sd_finish_aiocb; | ||
227 | |||
228 | retry: | ||
229 | if (check_overlapping_aiocb(s, acb)) { | ||
230 | @@ -XXX,XX +XXX,XX @@ retry: | ||
231 | goto retry; | ||
232 | } | ||
233 | |||
234 | - ret = sd_co_rw_vector(acb); | ||
235 | - if (ret <= 0) { | ||
236 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
237 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
238 | - qemu_aio_unref(acb); | ||
239 | - return ret; | ||
240 | - } | ||
241 | - | ||
242 | - qemu_coroutine_yield(); | ||
243 | + sd_co_rw_vector(acb); | ||
244 | |||
245 | QLIST_REMOVE(acb, aiocb_siblings); | ||
246 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
247 | - return acb->ret; | ||
248 | + ret = acb->ret; | ||
249 | + qemu_aio_unref(acb); | ||
250 | + return ret; | ||
251 | } | ||
252 | |||
253 | static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
254 | { | ||
255 | BDRVSheepdogState *s = bs->opaque; | ||
256 | SheepdogAIOCB *acb; | ||
257 | + int ret; | ||
258 | AIOReq *aio_req; | ||
259 | |||
260 | if (s->cache_flags != SD_FLAG_CMD_CACHE) { | ||
261 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
262 | |||
263 | acb = sd_aio_setup(bs, NULL, 0, 0); | ||
264 | acb->aiocb_type = AIOCB_FLUSH_CACHE; | ||
265 | - acb->aio_done_func = sd_finish_aiocb; | ||
266 | |||
267 | + acb->nr_pending++; | ||
268 | aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
269 | 0, 0, 0, false, 0, 0); | ||
270 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
271 | add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); | ||
272 | |||
273 | - qemu_coroutine_yield(); | ||
274 | - return acb->ret; | ||
275 | + if (--acb->nr_pending) { | ||
276 | + qemu_coroutine_yield(); | ||
277 | + } | ||
278 | + ret = acb->ret; | ||
279 | + qemu_aio_unref(acb); | ||
280 | + return ret; | ||
281 | } | ||
282 | |||
283 | static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
284 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
285 | acb = sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
286 | count >> BDRV_SECTOR_BITS); | ||
287 | acb->aiocb_type = AIOCB_DISCARD_OBJ; | ||
288 | - acb->aio_done_func = sd_finish_aiocb; | ||
289 | |||
290 | retry: | ||
291 | if (check_overlapping_aiocb(s, acb)) { | ||
292 | @@ -XXX,XX +XXX,XX @@ retry: | ||
293 | goto retry; | ||
294 | } | ||
295 | |||
296 | - ret = sd_co_rw_vector(acb); | ||
297 | - if (ret <= 0) { | ||
298 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
299 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
300 | - qemu_aio_unref(acb); | ||
301 | - return ret; | ||
302 | - } | ||
303 | - | ||
304 | - qemu_coroutine_yield(); | ||
305 | + sd_co_rw_vector(acb); | ||
306 | |||
307 | QLIST_REMOVE(acb, aiocb_siblings); | ||
308 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
309 | - | ||
310 | - return acb->ret; | ||
311 | + ret = acb->ret; | ||
312 | + qemu_aio_unref(acb); | ||
313 | + return ret; | ||
314 | } | ||
315 | |||
316 | static coroutine_fn int64_t | ||
317 | -- | 56 | -- |
318 | 2.9.3 | 57 | 2.23.0 |
319 | 58 | ||
320 | 59 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Eduardo Habkost <ehabkost@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | SheepdogAIOCB is internal to sheepdog.c, hence it is never canceled. | 3 | Instead of manually encoding stderr and stdout output, use |
4 | `errors` parameter of subprocess.Popen(). This will make | ||
5 | process.communicate() return unicode strings instead of bytes | ||
6 | objects. | ||
4 | 7 | ||
5 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 8 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
6 | Message-id: 20161129113245.32724-2-pbonzini@redhat.com | 9 | Reviewed-by: John Snow <jsnow@redhat.com> |
7 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
11 | Message-id: 20191016192430.25098-11-ehabkost@redhat.com | ||
12 | Message-Id: <20191016192430.25098-11-ehabkost@redhat.com> | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 14 | --- |
9 | block/sheepdog.c | 52 ---------------------------------------------------- | 15 | tests/image-fuzzer/runner.py | 11 ++++------- |
10 | 1 file changed, 52 deletions(-) | 16 | 1 file changed, 4 insertions(+), 7 deletions(-) |
11 | 17 | ||
12 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 18 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py |
13 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100755 |
14 | --- a/block/sheepdog.c | 20 | --- a/tests/image-fuzzer/runner.py |
15 | +++ b/block/sheepdog.c | 21 | +++ b/tests/image-fuzzer/runner.py |
16 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | 22 | @@ -XXX,XX +XXX,XX @@ def run_app(fd, q_args): |
17 | Coroutine *coroutine; | 23 | devnull = open('/dev/null', 'r+') |
18 | void (*aio_done_func)(SheepdogAIOCB *); | 24 | process = subprocess.Popen(q_args, stdin=devnull, |
19 | 25 | stdout=subprocess.PIPE, | |
20 | - bool cancelable; | 26 | - stderr=subprocess.PIPE) |
21 | int nr_pending; | 27 | + stderr=subprocess.PIPE, |
22 | 28 | + errors='replace') | |
23 | uint32_t min_affect_data_idx; | 29 | try: |
24 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | 30 | out, err = process.communicate() |
25 | { | 31 | signal.alarm(0) |
26 | SheepdogAIOCB *acb = aio_req->aiocb; | 32 | - # fd is a text file, so we need to decode the process output before |
27 | 33 | - # writing to it. | |
28 | - acb->cancelable = false; | 34 | - # We could be simply using the `errors` parameter of subprocess.Popen(), |
29 | QLIST_REMOVE(aio_req, aio_siblings); | 35 | - # but this will be possible only after migrating to Python 3 |
30 | g_free(aio_req); | 36 | - fd.write(out.decode(errors='replace')) |
31 | 37 | - fd.write(err.decode(errors='replace')) | |
32 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) | 38 | + fd.write(out) |
33 | qemu_aio_unref(acb); | 39 | + fd.write(err) |
34 | } | 40 | fd.flush() |
35 | 41 | return process.returncode | |
36 | -/* | 42 | |
37 | - * Check whether the specified acb can be canceled | ||
38 | - * | ||
39 | - * We can cancel aio when any request belonging to the acb is: | ||
40 | - * - Not processed by the sheepdog server. | ||
41 | - * - Not linked to the inflight queue. | ||
42 | - */ | ||
43 | -static bool sd_acb_cancelable(const SheepdogAIOCB *acb) | ||
44 | -{ | ||
45 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
46 | - AIOReq *aioreq; | ||
47 | - | ||
48 | - if (!acb->cancelable) { | ||
49 | - return false; | ||
50 | - } | ||
51 | - | ||
52 | - QLIST_FOREACH(aioreq, &s->inflight_aio_head, aio_siblings) { | ||
53 | - if (aioreq->aiocb == acb) { | ||
54 | - return false; | ||
55 | - } | ||
56 | - } | ||
57 | - | ||
58 | - return true; | ||
59 | -} | ||
60 | - | ||
61 | -static void sd_aio_cancel(BlockAIOCB *blockacb) | ||
62 | -{ | ||
63 | - SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb; | ||
64 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
65 | - AIOReq *aioreq, *next; | ||
66 | - | ||
67 | - if (sd_acb_cancelable(acb)) { | ||
68 | - /* Remove outstanding requests from failed queue. */ | ||
69 | - QLIST_FOREACH_SAFE(aioreq, &s->failed_aio_head, aio_siblings, | ||
70 | - next) { | ||
71 | - if (aioreq->aiocb == acb) { | ||
72 | - free_aio_req(s, aioreq); | ||
73 | - } | ||
74 | - } | ||
75 | - | ||
76 | - assert(acb->nr_pending == 0); | ||
77 | - if (acb->common.cb) { | ||
78 | - acb->common.cb(acb->common.opaque, -ECANCELED); | ||
79 | - } | ||
80 | - sd_finish_aiocb(acb); | ||
81 | - } | ||
82 | -} | ||
83 | - | ||
84 | static const AIOCBInfo sd_aiocb_info = { | ||
85 | .aiocb_size = sizeof(SheepdogAIOCB), | ||
86 | - .cancel_async = sd_aio_cancel, | ||
87 | }; | ||
88 | |||
89 | static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
90 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
91 | acb->nb_sectors = nb_sectors; | ||
92 | |||
93 | acb->aio_done_func = NULL; | ||
94 | - acb->cancelable = true; | ||
95 | acb->coroutine = qemu_coroutine_self(); | ||
96 | acb->ret = 0; | ||
97 | acb->nr_pending = 0; | ||
98 | -- | 43 | -- |
99 | 2.9.3 | 44 | 2.23.0 |
100 | 45 | ||
101 | 46 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Eduardo Habkost <ehabkost@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Wrap the code that was copied repeatedly in the two functions, | 3 | OSError can't be used like a tuple on Python 3, so change the |
4 | sd_aio_setup and sd_aio_complete. | 4 | code to use `e.sterror` instead of `e[1]`. |
5 | 5 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 6 | Reported-by: John Snow <jsnow@redhat.com> |
7 | Message-id: 20161129113245.32724-6-pbonzini@redhat.com | 7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> |
8 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 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> | ||
9 | --- | 12 | --- |
10 | block/sheepdog.c | 66 ++++++++++++++++++++++++++------------------------------ | 13 | tests/image-fuzzer/runner.py | 4 ++-- |
11 | 1 file changed, 30 insertions(+), 36 deletions(-) | 14 | 1 file changed, 2 insertions(+), 2 deletions(-) |
12 | 15 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 16 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100755 |
15 | --- a/block/sheepdog.c | 18 | --- a/tests/image-fuzzer/runner.py |
16 | +++ b/block/sheepdog.c | 19 | +++ b/tests/image-fuzzer/runner.py |
17 | @@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | 20 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): |
18 | return aio_req; | 21 | os.makedirs(self.current_dir) |
19 | } | 22 | except OSError as e: |
20 | 23 | print("Error: The working directory '%s' cannot be used. Reason: %s"\ | |
21 | +static void wait_for_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *acb) | 24 | - % (self.work_dir, e[1]), file=sys.stderr) |
22 | +{ | 25 | + % (self.work_dir, e.strerror), file=sys.stderr) |
23 | + SheepdogAIOCB *cb; | 26 | raise TestException |
24 | + | 27 | self.log = open(os.path.join(self.current_dir, "test.log"), "w") |
25 | +retry: | 28 | self.parent_log = open(run_log, "a") |
26 | + QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) { | 29 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): |
27 | + if (AIOCBOverlapping(acb, cb)) { | 30 | except OSError as e: |
28 | + qemu_co_queue_wait(&s->overlapping_queue); | 31 | multilog("%sError: Start of '%s' failed. Reason: %s\n\n" |
29 | + goto retry; | 32 | % (test_summary, os.path.basename(current_cmd[0]), |
30 | + } | 33 | - e[1]), |
31 | + } | 34 | + e.strerror), |
32 | +} | 35 | sys.stderr, self.log, self.parent_log) |
33 | + | 36 | raise TestException |
34 | static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
35 | QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | ||
36 | int type) | ||
37 | @@ -XXX,XX +XXX,XX @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
38 | acb->min_dirty_data_idx = UINT32_MAX; | ||
39 | acb->max_dirty_data_idx = 0; | ||
40 | acb->aiocb_type = type; | ||
41 | + | ||
42 | + if (type == AIOCB_FLUSH_CACHE) { | ||
43 | + return; | ||
44 | + } | ||
45 | + | ||
46 | + wait_for_overlapping_aiocb(s, acb); | ||
47 | + QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); | ||
48 | } | ||
49 | |||
50 | /* Return -EIO in case of error, file descriptor on success */ | ||
51 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | -static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
56 | +static void sd_aio_complete(SheepdogAIOCB *acb) | ||
57 | { | ||
58 | - SheepdogAIOCB *cb; | ||
59 | - | ||
60 | - QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) { | ||
61 | - if (AIOCBOverlapping(aiocb, cb)) { | ||
62 | - return true; | ||
63 | - } | ||
64 | + if (acb->aiocb_type == AIOCB_FLUSH_CACHE) { | ||
65 | + return; | ||
66 | } | ||
67 | |||
68 | - QLIST_INSERT_HEAD(&s->inflight_aiocb_head, aiocb, aiocb_siblings); | ||
69 | - return false; | ||
70 | + QLIST_REMOVE(acb, aiocb_siblings); | ||
71 | + qemu_co_queue_restart_all(&acb->s->overlapping_queue); | ||
72 | } | ||
73 | |||
74 | static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
75 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
76 | } | ||
77 | |||
78 | sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); | ||
79 | - | ||
80 | -retry: | ||
81 | - if (check_overlapping_aiocb(s, &acb)) { | ||
82 | - qemu_co_queue_wait(&s->overlapping_queue); | ||
83 | - goto retry; | ||
84 | - } | ||
85 | - | ||
86 | sd_co_rw_vector(&acb); | ||
87 | sd_write_done(&acb); | ||
88 | + sd_aio_complete(&acb); | ||
89 | |||
90 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
91 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
92 | return acb.ret; | ||
93 | } | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
96 | BDRVSheepdogState *s = bs->opaque; | ||
97 | |||
98 | sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); | ||
99 | - | ||
100 | -retry: | ||
101 | - if (check_overlapping_aiocb(s, &acb)) { | ||
102 | - qemu_co_queue_wait(&s->overlapping_queue); | ||
103 | - goto retry; | ||
104 | - } | ||
105 | - | ||
106 | sd_co_rw_vector(&acb); | ||
107 | + sd_aio_complete(&acb); | ||
108 | |||
109 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
110 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
111 | return acb.ret; | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
115 | if (--acb.nr_pending) { | ||
116 | qemu_coroutine_yield(); | ||
117 | } | ||
118 | + | ||
119 | + sd_aio_complete(&acb); | ||
120 | return acb.ret; | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
124 | } | ||
125 | sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
126 | count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); | ||
127 | - | ||
128 | -retry: | ||
129 | - if (check_overlapping_aiocb(s, &acb)) { | ||
130 | - qemu_co_queue_wait(&s->overlapping_queue); | ||
131 | - goto retry; | ||
132 | - } | ||
133 | - | ||
134 | sd_co_rw_vector(&acb); | ||
135 | + sd_aio_complete(&acb); | ||
136 | |||
137 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
138 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
139 | return acb.ret; | ||
140 | } | ||
141 | 37 | ||
142 | -- | 38 | -- |
143 | 2.9.3 | 39 | 2.23.0 |
144 | 40 | ||
145 | 41 | diff view generated by jsdifflib |