1 | The following changes since commit 248b23735645f7cbb503d9be6f5bf825f2a603ab: | 1 | The following changes since commit 9548cbeffffd4253e38570d29b8cff0bf77c998f: |
---|---|---|---|
2 | 2 | ||
3 | Update version for v2.10.0-rc4 release (2017-08-24 17:34:26 +0100) | 3 | iotests/copy-before-write: specify required_fmts (2022-07-12 13:21:02 +0530) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/hreitz/qemu.git tags/pull-block-2022-07-12 |
8 | 8 | ||
9 | for you to fetch changes up to 3e4c705212abfe8c9882a00beb2d1466a8a53cec: | 9 | for you to fetch changes up to 85c4bf8aa6c93c24876e8870ae7cf8ab2e5a96cf: |
10 | 10 | ||
11 | qcow2: allocate cluster_cache/cluster_data on demand (2017-08-30 18:02:10 +0100) | 11 | vl: Unlink absolute PID file path (2022-07-12 14:31:15 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches: | ||
15 | - Refactoring for non-coroutine variants of bdrv/blk_co_* functions: | ||
16 | Auto-generate more of them with the block coroutine wrapper generator | ||
17 | script | ||
18 | - iotest fixes | ||
19 | - Both for the storage daemon and the system emulator: Fix PID file | ||
20 | handling when daemonizing (store the absolute path and delete that on | ||
21 | exit, which is necessary because daemonizing will change the working | ||
22 | directory to /) | ||
14 | 23 | ||
15 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
25 | Alberto Faria (28): | ||
26 | block: Add a 'flags' param to bdrv_{pread,pwrite,pwrite_sync}() | ||
27 | block: Change bdrv_{pread,pwrite,pwrite_sync}() param order | ||
28 | block: Make bdrv_{pread,pwrite}() return 0 on success | ||
29 | crypto: Make block callbacks return 0 on success | ||
30 | block: Make bdrv_co_pwrite() take a const buffer | ||
31 | block: Make 'bytes' param of bdrv_co_{pread,pwrite,preadv,pwritev}() | ||
32 | an int64_t | ||
33 | block: Implement bdrv_{pread,pwrite,pwrite_zeroes}() using | ||
34 | generated_co_wrapper | ||
35 | block: Add bdrv_co_pwrite_sync() | ||
36 | block: Use bdrv_co_pwrite_sync() when caller is coroutine_fn | ||
37 | block/qcow2: Use bdrv_pwrite_sync() in qcow2_mark_dirty() | ||
38 | block: Make blk_{pread,pwrite}() return 0 on success | ||
39 | block: Add a 'flags' param to blk_pread() | ||
40 | block: Change blk_{pread,pwrite}() param order | ||
41 | block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t | ||
42 | block: Make blk_co_pwrite() take a const buffer | ||
43 | block: Implement blk_{pread,pwrite}() using generated_co_wrapper | ||
44 | block: Add blk_{preadv,pwritev}() | ||
45 | block: Add blk_[co_]preadv_part() | ||
46 | block: Export blk_pwritev_part() in block-backend-io.h | ||
47 | block: Change blk_pwrite_compressed() param order | ||
48 | block: Add blk_co_pwrite_compressed() | ||
49 | block: Implement blk_pwrite_zeroes() using generated_co_wrapper | ||
50 | block: Implement blk_pdiscard() using generated_co_wrapper | ||
51 | block: Implement blk_flush() using generated_co_wrapper | ||
52 | block: Add blk_co_ioctl() | ||
53 | block: Add blk_co_truncate() | ||
54 | block: Reorganize some declarations in block-backend-io.h | ||
55 | block: Remove remaining unused symbols in coroutines.h | ||
16 | 56 | ||
17 | Alberto Garcia (8): | 57 | Hanna Reitz (5): |
18 | throttle: Fix wrong variable name in the header documentation | 58 | qsd: Do not use error_report() before monitor_init |
19 | throttle: Update the throttle_fix_bucket() documentation | 59 | iotests/297: Have mypy ignore unused ignores |
20 | throttle: Make throttle_is_valid() a bit less verbose | 60 | qsd: Unlink absolute PID file path |
21 | throttle: Remove throttle_fix_bucket() / throttle_unfix_bucket() | 61 | vl: Conditionally register PID file unlink notifier |
22 | throttle: Make LeakyBucket.avg and LeakyBucket.max integer types | 62 | vl: Unlink absolute PID file path |
23 | throttle: Make burst_length 64bit and add range checks | ||
24 | throttle: Test the valid range of config values | ||
25 | misc: Remove unused Error variables | ||
26 | 63 | ||
27 | Dan Aloni (1): | 64 | John Snow (2): |
28 | nvme: Fix get/set number of queues feature, again | 65 | tests/qemu-iotests: hotfix for 307, 223 output |
66 | tests/qemu-iotests: skip 108 when FUSE is not loaded | ||
29 | 67 | ||
30 | Eduardo Habkost (1): | 68 | block/coroutines.h | 44 -------- |
31 | oslib-posix: Print errors before aborting on qemu_alloc_stack() | 69 | include/block/block-io.h | 22 ++-- |
32 | 70 | include/block/block_int-io.h | 4 +- | |
33 | Fred Rolland (1): | 71 | include/crypto/block.h | 32 +++--- |
34 | qemu-doc: Add UUID support in initiator name | 72 | include/sysemu/block-backend-io.h | 97 ++++++++++------- |
35 | 73 | block.c | 10 +- | |
36 | Stefan Hajnoczi (4): | 74 | block/blklogwrites.c | 6 +- |
37 | scripts: add argparse module for Python 2.6 compatibility | 75 | block/block-backend.c | 150 +++++++++++--------------- |
38 | docker.py: Python 2.6 argparse compatibility | 76 | block/bochs.c | 10 +- |
39 | tests: migration/guestperf Python 2.6 argparse compatibility | 77 | block/cloop.c | 12 +-- |
40 | qcow2: allocate cluster_cache/cluster_data on demand | 78 | block/commit.c | 4 +- |
41 | 79 | block/crypto.c | 58 +++++----- | |
42 | include/qemu/throttle.h | 8 +- | 80 | block/dmg.c | 36 +++---- |
43 | block/qcow.c | 12 +- | 81 | block/export/fuse.c | 4 +- |
44 | block/qcow2-cluster.c | 17 + | 82 | block/io.c | 55 +--------- |
45 | block/qcow2.c | 20 +- | 83 | block/parallels-ext.c | 6 +- |
46 | dump.c | 4 +- | 84 | block/parallels.c | 14 +-- |
47 | hw/block/nvme.c | 4 +- | 85 | block/qcow.c | 55 +++++----- |
48 | tests/test-throttle.c | 80 +- | 86 | block/qcow2-bitmap.c | 14 +-- |
49 | util/oslib-posix.c | 2 + | 87 | block/qcow2-cache.c | 9 +- |
50 | util/throttle.c | 86 +- | 88 | block/qcow2-cluster.c | 19 ++-- |
51 | COPYING.PYTHON | 270 ++++ | 89 | block/qcow2-refcount.c | 58 +++++----- |
52 | qemu-doc.texi | 5 +- | 90 | block/qcow2-snapshot.c | 53 +++++----- |
53 | scripts/argparse.py | 2406 ++++++++++++++++++++++++++++++++++++ | 91 | block/qcow2.c | 84 +++++++-------- |
54 | tests/docker/docker.py | 4 +- | 92 | block/qed.c | 21 ++-- |
55 | tests/migration/guestperf/shell.py | 8 +- | 93 | block/vdi.c | 20 ++-- |
56 | 14 files changed, 2831 insertions(+), 95 deletions(-) | 94 | block/vhdx-log.c | 23 ++-- |
57 | create mode 100644 COPYING.PYTHON | 95 | block/vhdx.c | 56 +++++----- |
58 | create mode 100644 scripts/argparse.py | 96 | block/vmdk.c | 80 +++++++------- |
97 | block/vpc.c | 35 +++--- | ||
98 | block/vvfat.c | 11 +- | ||
99 | crypto/block-luks.c | 8 +- | ||
100 | crypto/block.c | 6 +- | ||
101 | hw/arm/allwinner-h3.c | 2 +- | ||
102 | hw/arm/aspeed.c | 2 +- | ||
103 | hw/block/block.c | 2 +- | ||
104 | hw/block/fdc.c | 20 ++-- | ||
105 | hw/block/hd-geometry.c | 2 +- | ||
106 | hw/block/m25p80.c | 2 +- | ||
107 | hw/block/nand.c | 47 ++++---- | ||
108 | hw/block/onenand.c | 32 +++--- | ||
109 | hw/block/pflash_cfi01.c | 4 +- | ||
110 | hw/block/pflash_cfi02.c | 4 +- | ||
111 | hw/ide/atapi.c | 4 +- | ||
112 | hw/misc/mac_via.c | 6 +- | ||
113 | hw/misc/sifive_u_otp.c | 14 +-- | ||
114 | hw/nvram/eeprom_at24c.c | 8 +- | ||
115 | hw/nvram/spapr_nvram.c | 16 +-- | ||
116 | hw/nvram/xlnx-bbram.c | 4 +- | ||
117 | hw/nvram/xlnx-efuse.c | 4 +- | ||
118 | hw/ppc/pnv_pnor.c | 6 +- | ||
119 | hw/sd/sd.c | 4 +- | ||
120 | migration/block.c | 8 +- | ||
121 | nbd/server.c | 8 +- | ||
122 | qemu-img.c | 41 +++---- | ||
123 | qemu-io-cmds.c | 20 ++-- | ||
124 | softmmu/vl.c | 42 ++++++-- | ||
125 | storage-daemon/qemu-storage-daemon.c | 17 ++- | ||
126 | tests/unit/test-block-iothread.c | 153 ++++++++++++++++++++++++--- | ||
127 | tests/unit/test-crypto-block.c | 38 +++---- | ||
128 | block/meson.build | 1 + | ||
129 | tests/qemu-iotests/108 | 5 + | ||
130 | tests/qemu-iotests/223.out | 4 +- | ||
131 | tests/qemu-iotests/307.out | 4 +- | ||
132 | tests/qemu-iotests/mypy.ini | 2 +- | ||
133 | 65 files changed, 856 insertions(+), 786 deletions(-) | ||
59 | 134 | ||
60 | -- | 135 | -- |
61 | 2.13.5 | 136 | 2.35.3 |
62 | |||
63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | For consistency with other I/O functions, and in preparation to | ||
4 | implement them using generated_co_wrapper. | ||
5 | |||
6 | Callers were updated using this Coccinelle script: | ||
7 | |||
8 | @@ expression child, offset, buf, bytes; @@ | ||
9 | - bdrv_pread(child, offset, buf, bytes) | ||
10 | + bdrv_pread(child, offset, buf, bytes, 0) | ||
11 | |||
12 | @@ expression child, offset, buf, bytes; @@ | ||
13 | - bdrv_pwrite(child, offset, buf, bytes) | ||
14 | + bdrv_pwrite(child, offset, buf, bytes, 0) | ||
15 | |||
16 | @@ expression child, offset, buf, bytes; @@ | ||
17 | - bdrv_pwrite_sync(child, offset, buf, bytes) | ||
18 | + bdrv_pwrite_sync(child, offset, buf, bytes, 0) | ||
19 | |||
20 | Resulting overly-long lines were then fixed by hand. | ||
21 | |||
22 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
23 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
24 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
25 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> | ||
26 | Message-Id: <20220609152744.3891847-2-afaria@redhat.com> | ||
27 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
28 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
29 | --- | ||
30 | include/block/block-io.h | 7 ++-- | ||
31 | block/blklogwrites.c | 4 +-- | ||
32 | block/bochs.c | 6 ++-- | ||
33 | block/cloop.c | 10 +++--- | ||
34 | block/crypto.c | 4 +-- | ||
35 | block/dmg.c | 24 +++++++------- | ||
36 | block/io.c | 13 ++++---- | ||
37 | block/parallels-ext.c | 4 +-- | ||
38 | block/parallels.c | 12 +++---- | ||
39 | block/qcow.c | 27 ++++++++------- | ||
40 | block/qcow2-bitmap.c | 14 ++++---- | ||
41 | block/qcow2-cache.c | 7 ++-- | ||
42 | block/qcow2-cluster.c | 21 ++++++------ | ||
43 | block/qcow2-refcount.c | 42 +++++++++++------------ | ||
44 | block/qcow2-snapshot.c | 39 +++++++++++----------- | ||
45 | block/qcow2.c | 44 ++++++++++++------------ | ||
46 | block/qed.c | 8 ++--- | ||
47 | block/vdi.c | 10 +++--- | ||
48 | block/vhdx-log.c | 19 +++++------ | ||
49 | block/vhdx.c | 32 ++++++++++-------- | ||
50 | block/vmdk.c | 57 ++++++++++++++------------------ | ||
51 | block/vpc.c | 19 ++++++----- | ||
52 | block/vvfat.c | 7 ++-- | ||
53 | tests/unit/test-block-iothread.c | 8 ++--- | ||
54 | 24 files changed, 219 insertions(+), 219 deletions(-) | ||
55 | |||
56 | diff --git a/include/block/block-io.h b/include/block/block-io.h | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/include/block/block-io.h | ||
59 | +++ b/include/block/block-io.h | ||
60 | @@ -XXX,XX +XXX,XX @@ | ||
61 | int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, | ||
62 | int64_t bytes, BdrvRequestFlags flags); | ||
63 | int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); | ||
64 | -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes); | ||
65 | +int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, | ||
66 | + BdrvRequestFlags flags); | ||
67 | int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
68 | - int64_t bytes); | ||
69 | + int64_t bytes, BdrvRequestFlags flags); | ||
70 | int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, | ||
71 | - const void *buf, int64_t bytes); | ||
72 | + const void *buf, int64_t bytes, BdrvRequestFlags flags); | ||
73 | /* | ||
74 | * Efficiently zero a region of the disk image. Note that this is a regular | ||
75 | * I/O request like read or write and should have a reasonable size. This | ||
76 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/block/blklogwrites.c | ||
79 | +++ b/block/blklogwrites.c | ||
80 | @@ -XXX,XX +XXX,XX @@ static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log, | ||
81 | |||
82 | while (cur_idx < nr_entries) { | ||
83 | int read_ret = bdrv_pread(log, cur_sector << sector_bits, &cur_entry, | ||
84 | - sizeof(cur_entry)); | ||
85 | + sizeof(cur_entry), 0); | ||
86 | if (read_ret < 0) { | ||
87 | error_setg_errno(errp, -read_ret, | ||
88 | "Failed to read log entry %"PRIu64, cur_idx); | ||
89 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
90 | log_sb.nr_entries = cpu_to_le64(0); | ||
91 | log_sb.sectorsize = cpu_to_le32(BDRV_SECTOR_SIZE); | ||
92 | } else { | ||
93 | - ret = bdrv_pread(s->log_file, 0, &log_sb, sizeof(log_sb)); | ||
94 | + ret = bdrv_pread(s->log_file, 0, &log_sb, sizeof(log_sb), 0); | ||
95 | if (ret < 0) { | ||
96 | error_setg_errno(errp, -ret, "Could not read log superblock"); | ||
97 | goto fail_log; | ||
98 | diff --git a/block/bochs.c b/block/bochs.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/block/bochs.c | ||
101 | +++ b/block/bochs.c | ||
102 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | - ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); | ||
107 | + ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs), 0); | ||
108 | if (ret < 0) { | ||
109 | return ret; | ||
110 | } | ||
111 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
112 | } | ||
113 | |||
114 | ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, | ||
115 | - s->catalog_size * 4); | ||
116 | + s->catalog_size * 4, 0); | ||
117 | if (ret < 0) { | ||
118 | goto fail; | ||
119 | } | ||
120 | @@ -XXX,XX +XXX,XX @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num) | ||
121 | |||
122 | /* read in bitmap for current extent */ | ||
123 | ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), | ||
124 | - &bitmap_entry, 1); | ||
125 | + &bitmap_entry, 1, 0); | ||
126 | if (ret < 0) { | ||
127 | return ret; | ||
128 | } | ||
129 | diff --git a/block/cloop.c b/block/cloop.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/block/cloop.c | ||
132 | +++ b/block/cloop.c | ||
133 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
134 | } | ||
135 | |||
136 | /* read header */ | ||
137 | - ret = bdrv_pread(bs->file, 128, &s->block_size, 4); | ||
138 | + ret = bdrv_pread(bs->file, 128, &s->block_size, 4, 0); | ||
139 | if (ret < 0) { | ||
140 | return ret; | ||
141 | } | ||
142 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
143 | return -EINVAL; | ||
144 | } | ||
145 | |||
146 | - ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4); | ||
147 | + ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4, 0); | ||
148 | if (ret < 0) { | ||
149 | return ret; | ||
150 | } | ||
151 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
152 | return -ENOMEM; | ||
153 | } | ||
154 | |||
155 | - ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size); | ||
156 | + ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size, 0); | ||
157 | if (ret < 0) { | ||
158 | goto fail; | ||
159 | } | ||
160 | @@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num) | ||
161 | int ret; | ||
162 | uint32_t bytes = s->offsets[block_num + 1] - s->offsets[block_num]; | ||
163 | |||
164 | - ret = bdrv_pread(bs->file, s->offsets[block_num], | ||
165 | - s->compressed_block, bytes); | ||
166 | + ret = bdrv_pread(bs->file, s->offsets[block_num], s->compressed_block, | ||
167 | + bytes, 0); | ||
168 | if (ret != bytes) { | ||
169 | return -1; | ||
170 | } | ||
171 | diff --git a/block/crypto.c b/block/crypto.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/block/crypto.c | ||
174 | +++ b/block/crypto.c | ||
175 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, | ||
176 | BlockDriverState *bs = opaque; | ||
177 | ssize_t ret; | ||
178 | |||
179 | - ret = bdrv_pread(bs->file, offset, buf, buflen); | ||
180 | + ret = bdrv_pread(bs->file, offset, buf, buflen, 0); | ||
181 | if (ret < 0) { | ||
182 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
183 | return ret; | ||
184 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
185 | BlockDriverState *bs = opaque; | ||
186 | ssize_t ret; | ||
187 | |||
188 | - ret = bdrv_pwrite(bs->file, offset, buf, buflen); | ||
189 | + ret = bdrv_pwrite(bs->file, offset, buf, buflen, 0); | ||
190 | if (ret < 0) { | ||
191 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
192 | return ret; | ||
193 | diff --git a/block/dmg.c b/block/dmg.c | ||
194 | index XXXXXXX..XXXXXXX 100644 | ||
195 | --- a/block/dmg.c | ||
196 | +++ b/block/dmg.c | ||
197 | @@ -XXX,XX +XXX,XX @@ static int read_uint64(BlockDriverState *bs, int64_t offset, uint64_t *result) | ||
198 | uint64_t buffer; | ||
199 | int ret; | ||
200 | |||
201 | - ret = bdrv_pread(bs->file, offset, &buffer, 8); | ||
202 | + ret = bdrv_pread(bs->file, offset, &buffer, 8, 0); | ||
203 | if (ret < 0) { | ||
204 | return ret; | ||
205 | } | ||
206 | @@ -XXX,XX +XXX,XX @@ static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result) | ||
207 | uint32_t buffer; | ||
208 | int ret; | ||
209 | |||
210 | - ret = bdrv_pread(bs->file, offset, &buffer, 4); | ||
211 | + ret = bdrv_pread(bs->file, offset, &buffer, 4, 0); | ||
212 | if (ret < 0) { | ||
213 | return ret; | ||
214 | } | ||
215 | @@ -XXX,XX +XXX,XX @@ static int64_t dmg_find_koly_offset(BdrvChild *file, Error **errp) | ||
216 | offset = length - 511 - 512; | ||
217 | } | ||
218 | length = length < 515 ? length : 515; | ||
219 | - ret = bdrv_pread(file, offset, buffer, length); | ||
220 | + ret = bdrv_pread(file, offset, buffer, length, 0); | ||
221 | if (ret < 0) { | ||
222 | error_setg_errno(errp, -ret, "Failed while reading UDIF trailer"); | ||
223 | return ret; | ||
224 | @@ -XXX,XX +XXX,XX @@ static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds, | ||
225 | offset += 4; | ||
226 | |||
227 | buffer = g_realloc(buffer, count); | ||
228 | - ret = bdrv_pread(bs->file, offset, buffer, count); | ||
229 | + ret = bdrv_pread(bs->file, offset, buffer, count, 0); | ||
230 | if (ret < 0) { | ||
231 | goto fail; | ||
232 | } | ||
233 | @@ -XXX,XX +XXX,XX @@ static int dmg_read_plist_xml(BlockDriverState *bs, DmgHeaderState *ds, | ||
234 | |||
235 | buffer = g_malloc(info_length + 1); | ||
236 | buffer[info_length] = '\0'; | ||
237 | - ret = bdrv_pread(bs->file, info_begin, buffer, info_length); | ||
238 | + ret = bdrv_pread(bs->file, info_begin, buffer, info_length, 0); | ||
239 | if (ret != info_length) { | ||
240 | ret = -EINVAL; | ||
241 | goto fail; | ||
242 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
243 | case UDZO: { /* zlib compressed */ | ||
244 | /* we need to buffer, because only the chunk as whole can be | ||
245 | * inflated. */ | ||
246 | - ret = bdrv_pread(bs->file, s->offsets[chunk], | ||
247 | - s->compressed_chunk, s->lengths[chunk]); | ||
248 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
249 | + s->lengths[chunk], 0); | ||
250 | if (ret != s->lengths[chunk]) { | ||
251 | return -1; | ||
252 | } | ||
253 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
254 | } | ||
255 | /* we need to buffer, because only the chunk as whole can be | ||
256 | * inflated. */ | ||
257 | - ret = bdrv_pread(bs->file, s->offsets[chunk], | ||
258 | - s->compressed_chunk, s->lengths[chunk]); | ||
259 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
260 | + s->lengths[chunk], 0); | ||
261 | if (ret != s->lengths[chunk]) { | ||
262 | return -1; | ||
263 | } | ||
264 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
265 | } | ||
266 | /* we need to buffer, because only the chunk as whole can be | ||
267 | * inflated. */ | ||
268 | - ret = bdrv_pread(bs->file, s->offsets[chunk], | ||
269 | - s->compressed_chunk, s->lengths[chunk]); | ||
270 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
271 | + s->lengths[chunk], 0); | ||
272 | if (ret != s->lengths[chunk]) { | ||
273 | return -1; | ||
274 | } | ||
275 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
276 | break; | ||
277 | case UDRW: /* copy */ | ||
278 | ret = bdrv_pread(bs->file, s->offsets[chunk], | ||
279 | - s->uncompressed_chunk, s->lengths[chunk]); | ||
280 | + s->uncompressed_chunk, s->lengths[chunk], 0); | ||
281 | if (ret != s->lengths[chunk]) { | ||
282 | return -1; | ||
283 | } | ||
284 | diff --git a/block/io.c b/block/io.c | ||
285 | index XXXXXXX..XXXXXXX 100644 | ||
286 | --- a/block/io.c | ||
287 | +++ b/block/io.c | ||
288 | @@ -XXX,XX +XXX,XX @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) | ||
289 | } | ||
290 | |||
291 | /* See bdrv_pwrite() for the return codes */ | ||
292 | -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes) | ||
293 | +int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, | ||
294 | + BdrvRequestFlags flags) | ||
295 | { | ||
296 | int ret; | ||
297 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
298 | @@ -XXX,XX +XXX,XX @@ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes) | ||
299 | return -EINVAL; | ||
300 | } | ||
301 | |||
302 | - ret = bdrv_preadv(child, offset, bytes, &qiov, 0); | ||
303 | + ret = bdrv_preadv(child, offset, bytes, &qiov, flags); | ||
304 | |||
305 | return ret < 0 ? ret : bytes; | ||
306 | } | ||
307 | @@ -XXX,XX +XXX,XX @@ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes) | ||
308 | -EACCES Trying to write a read-only device | ||
309 | */ | ||
310 | int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
311 | - int64_t bytes) | ||
312 | + int64_t bytes, BdrvRequestFlags flags) | ||
313 | { | ||
314 | int ret; | ||
315 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
316 | @@ -XXX,XX +XXX,XX @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
317 | return -EINVAL; | ||
318 | } | ||
319 | |||
320 | - ret = bdrv_pwritev(child, offset, bytes, &qiov, 0); | ||
321 | + ret = bdrv_pwritev(child, offset, bytes, &qiov, flags); | ||
322 | |||
323 | return ret < 0 ? ret : bytes; | ||
324 | } | ||
325 | @@ -XXX,XX +XXX,XX @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
326 | * Returns 0 on success, -errno in error cases. | ||
327 | */ | ||
328 | int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, | ||
329 | - const void *buf, int64_t count) | ||
330 | + const void *buf, int64_t count, BdrvRequestFlags flags) | ||
331 | { | ||
332 | int ret; | ||
333 | IO_CODE(); | ||
334 | |||
335 | - ret = bdrv_pwrite(child, offset, buf, count); | ||
336 | + ret = bdrv_pwrite(child, offset, buf, count, flags); | ||
337 | if (ret < 0) { | ||
338 | return ret; | ||
339 | } | ||
340 | diff --git a/block/parallels-ext.c b/block/parallels-ext.c | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/block/parallels-ext.c | ||
343 | +++ b/block/parallels-ext.c | ||
344 | @@ -XXX,XX +XXX,XX @@ static int parallels_load_bitmap_data(BlockDriverState *bs, | ||
345 | bdrv_dirty_bitmap_deserialize_ones(bitmap, offset, count, false); | ||
346 | } else { | ||
347 | ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS, buf, | ||
348 | - s->cluster_size); | ||
349 | + s->cluster_size, 0); | ||
350 | if (ret < 0) { | ||
351 | error_setg_errno(errp, -ret, | ||
352 | "Failed to read bitmap data cluster"); | ||
353 | @@ -XXX,XX +XXX,XX @@ int parallels_read_format_extension(BlockDriverState *bs, | ||
354 | |||
355 | assert(ext_off > 0); | ||
356 | |||
357 | - ret = bdrv_pread(bs->file, ext_off, ext_cluster, s->cluster_size); | ||
358 | + ret = bdrv_pread(bs->file, ext_off, ext_cluster, s->cluster_size, 0); | ||
359 | if (ret < 0) { | ||
360 | error_setg_errno(errp, -ret, "Failed to read Format Extension cluster"); | ||
361 | goto out; | ||
362 | diff --git a/block/parallels.c b/block/parallels.c | ||
363 | index XXXXXXX..XXXXXXX 100644 | ||
364 | --- a/block/parallels.c | ||
365 | +++ b/block/parallels.c | ||
366 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) | ||
367 | if (off + to_write > s->header_size) { | ||
368 | to_write = s->header_size - off; | ||
369 | } | ||
370 | - ret = bdrv_pwrite(bs->file, off, (uint8_t *)s->header + off, | ||
371 | - to_write); | ||
372 | + ret = bdrv_pwrite(bs->file, off, (uint8_t *)s->header + off, to_write, | ||
373 | + 0); | ||
374 | if (ret < 0) { | ||
375 | qemu_co_mutex_unlock(&s->lock); | ||
376 | return ret; | ||
377 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, | ||
378 | |||
379 | ret = 0; | ||
380 | if (flush_bat) { | ||
381 | - ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size); | ||
382 | + ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size, 0); | ||
383 | if (ret < 0) { | ||
384 | res->check_errors++; | ||
385 | goto out; | ||
386 | @@ -XXX,XX +XXX,XX @@ static int parallels_update_header(BlockDriverState *bs) | ||
387 | if (size > s->header_size) { | ||
388 | size = s->header_size; | ||
389 | } | ||
390 | - return bdrv_pwrite_sync(bs->file, 0, s->header, size); | ||
391 | + return bdrv_pwrite_sync(bs->file, 0, s->header, size, 0); | ||
392 | } | ||
393 | |||
394 | static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
395 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
396 | return -EINVAL; | ||
397 | } | ||
398 | |||
399 | - ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph)); | ||
400 | + ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph), 0); | ||
401 | if (ret < 0) { | ||
402 | goto fail; | ||
403 | } | ||
404 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
405 | s->header_size = size; | ||
406 | } | ||
407 | |||
408 | - ret = bdrv_pread(bs->file, 0, s->header, s->header_size); | ||
409 | + ret = bdrv_pread(bs->file, 0, s->header, s->header_size, 0); | ||
410 | if (ret < 0) { | ||
411 | goto fail; | ||
412 | } | ||
413 | diff --git a/block/qcow.c b/block/qcow.c | ||
414 | index XXXXXXX..XXXXXXX 100644 | ||
415 | --- a/block/qcow.c | ||
416 | +++ b/block/qcow.c | ||
417 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
418 | goto fail; | ||
419 | } | ||
420 | |||
421 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); | ||
422 | + ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
423 | if (ret < 0) { | ||
424 | goto fail; | ||
425 | } | ||
426 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
427 | } | ||
428 | |||
429 | ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, | ||
430 | - s->l1_size * sizeof(uint64_t)); | ||
431 | + s->l1_size * sizeof(uint64_t), 0); | ||
432 | if (ret < 0) { | ||
433 | goto fail; | ||
434 | } | ||
435 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
436 | goto fail; | ||
437 | } | ||
438 | ret = bdrv_pread(bs->file, header.backing_file_offset, | ||
439 | - bs->auto_backing_file, len); | ||
440 | + bs->auto_backing_file, len, 0); | ||
441 | if (ret < 0) { | ||
442 | goto fail; | ||
443 | } | ||
444 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
445 | BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); | ||
446 | ret = bdrv_pwrite_sync(bs->file, | ||
447 | s->l1_table_offset + l1_index * sizeof(tmp), | ||
448 | - &tmp, sizeof(tmp)); | ||
449 | + &tmp, sizeof(tmp), 0); | ||
450 | if (ret < 0) { | ||
451 | return ret; | ||
452 | } | ||
453 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
454 | if (new_l2_table) { | ||
455 | memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); | ||
456 | ret = bdrv_pwrite_sync(bs->file, l2_offset, l2_table, | ||
457 | - s->l2_size * sizeof(uint64_t)); | ||
458 | + s->l2_size * sizeof(uint64_t), 0); | ||
459 | if (ret < 0) { | ||
460 | return ret; | ||
461 | } | ||
462 | } else { | ||
463 | ret = bdrv_pread(bs->file, l2_offset, l2_table, | ||
464 | - s->l2_size * sizeof(uint64_t)); | ||
465 | + s->l2_size * sizeof(uint64_t), 0); | ||
466 | if (ret < 0) { | ||
467 | return ret; | ||
468 | } | ||
469 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
470 | /* write the cluster content */ | ||
471 | BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); | ||
472 | ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, | ||
473 | - s->cluster_size); | ||
474 | + s->cluster_size, 0); | ||
475 | if (ret < 0) { | ||
476 | return ret; | ||
477 | } | ||
478 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
479 | return -EIO; | ||
480 | } | ||
481 | BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); | ||
482 | - ret = bdrv_pwrite(bs->file, | ||
483 | - cluster_offset + i, | ||
484 | + ret = bdrv_pwrite(bs->file, cluster_offset + i, | ||
485 | s->cluster_data, | ||
486 | - BDRV_SECTOR_SIZE); | ||
487 | + BDRV_SECTOR_SIZE, 0); | ||
488 | if (ret < 0) { | ||
489 | return ret; | ||
490 | } | ||
491 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
492 | BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE); | ||
493 | } | ||
494 | ret = bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp), | ||
495 | - &tmp, sizeof(tmp)); | ||
496 | + &tmp, sizeof(tmp), 0); | ||
497 | if (ret < 0) { | ||
498 | return ret; | ||
499 | } | ||
500 | @@ -XXX,XX +XXX,XX @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) | ||
501 | csize = cluster_offset >> (63 - s->cluster_bits); | ||
502 | csize &= (s->cluster_size - 1); | ||
503 | BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); | ||
504 | - ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize); | ||
505 | + ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize, 0); | ||
506 | if (ret != csize) | ||
507 | return -1; | ||
508 | if (decompress_buffer(s->cluster_cache, s->cluster_size, | ||
509 | @@ -XXX,XX +XXX,XX @@ static int qcow_make_empty(BlockDriverState *bs) | ||
510 | int ret; | ||
511 | |||
512 | memset(s->l1_table, 0, l1_length); | ||
513 | - if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, | ||
514 | - l1_length) < 0) | ||
515 | + if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, l1_length, | ||
516 | + 0) < 0) | ||
517 | return -1; | ||
518 | ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, false, | ||
519 | PREALLOC_MODE_OFF, 0, NULL); | ||
520 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
521 | index XXXXXXX..XXXXXXX 100644 | ||
522 | --- a/block/qcow2-bitmap.c | ||
523 | +++ b/block/qcow2-bitmap.c | ||
524 | @@ -XXX,XX +XXX,XX @@ static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb, | ||
525 | } | ||
526 | |||
527 | assert(tb->size <= BME_MAX_TABLE_SIZE); | ||
528 | - ret = bdrv_pread(bs->file, tb->offset, | ||
529 | - table, tb->size * BME_TABLE_ENTRY_SIZE); | ||
530 | + ret = bdrv_pread(bs->file, tb->offset, table, | ||
531 | + tb->size * BME_TABLE_ENTRY_SIZE, 0); | ||
532 | if (ret < 0) { | ||
533 | goto fail; | ||
534 | } | ||
535 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
536 | * already cleared */ | ||
537 | } | ||
538 | } else { | ||
539 | - ret = bdrv_pread(bs->file, data_offset, buf, s->cluster_size); | ||
540 | + ret = bdrv_pread(bs->file, data_offset, buf, s->cluster_size, 0); | ||
541 | if (ret < 0) { | ||
542 | goto finish; | ||
543 | } | ||
544 | @@ -XXX,XX +XXX,XX @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset, | ||
545 | } | ||
546 | dir_end = dir + size; | ||
547 | |||
548 | - ret = bdrv_pread(bs->file, offset, dir, size); | ||
549 | + ret = bdrv_pread(bs->file, offset, dir, size, 0); | ||
550 | if (ret < 0) { | ||
551 | error_setg_errno(errp, -ret, "Failed to read bitmap directory"); | ||
552 | goto fail; | ||
553 | @@ -XXX,XX +XXX,XX @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list, | ||
554 | goto fail; | ||
555 | } | ||
556 | |||
557 | - ret = bdrv_pwrite(bs->file, dir_offset, dir, dir_size); | ||
558 | + ret = bdrv_pwrite(bs->file, dir_offset, dir, dir_size, 0); | ||
559 | if (ret < 0) { | ||
560 | goto fail; | ||
561 | } | ||
562 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
563 | goto fail; | ||
564 | } | ||
565 | |||
566 | - ret = bdrv_pwrite(bs->file, off, buf, s->cluster_size); | ||
567 | + ret = bdrv_pwrite(bs->file, off, buf, s->cluster_size, 0); | ||
568 | if (ret < 0) { | ||
569 | error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file", | ||
570 | bm_name); | ||
571 | @@ -XXX,XX +XXX,XX @@ static int store_bitmap(BlockDriverState *bs, Qcow2Bitmap *bm, Error **errp) | ||
572 | } | ||
573 | |||
574 | bitmap_table_to_be(tb, tb_size); | ||
575 | - ret = bdrv_pwrite(bs->file, tb_offset, tb, tb_size * sizeof(tb[0])); | ||
576 | + ret = bdrv_pwrite(bs->file, tb_offset, tb, tb_size * sizeof(tb[0]), 0); | ||
577 | if (ret < 0) { | ||
578 | error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file", | ||
579 | bm_name); | ||
580 | diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c | ||
581 | index XXXXXXX..XXXXXXX 100644 | ||
582 | --- a/block/qcow2-cache.c | ||
583 | +++ b/block/qcow2-cache.c | ||
584 | @@ -XXX,XX +XXX,XX @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i) | ||
585 | } | ||
586 | |||
587 | ret = bdrv_pwrite(bs->file, c->entries[i].offset, | ||
588 | - qcow2_cache_get_table_addr(c, i), c->table_size); | ||
589 | + qcow2_cache_get_table_addr(c, i), c->table_size, 0); | ||
590 | if (ret < 0) { | ||
591 | return ret; | ||
592 | } | ||
593 | @@ -XXX,XX +XXX,XX @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c, | ||
594 | BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD); | ||
595 | } | ||
596 | |||
597 | - ret = bdrv_pread(bs->file, offset, | ||
598 | - qcow2_cache_get_table_addr(c, i), | ||
599 | - c->table_size); | ||
600 | + ret = bdrv_pread(bs->file, offset, qcow2_cache_get_table_addr(c, i), | ||
601 | + c->table_size, 0); | ||
602 | if (ret < 0) { | ||
603 | return ret; | ||
604 | } | ||
605 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | ||
606 | index XXXXXXX..XXXXXXX 100644 | ||
607 | --- a/block/qcow2-cluster.c | ||
608 | +++ b/block/qcow2-cluster.c | ||
609 | @@ -XXX,XX +XXX,XX @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, | ||
610 | BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE); | ||
611 | for(i = 0; i < s->l1_size; i++) | ||
612 | new_l1_table[i] = cpu_to_be64(new_l1_table[i]); | ||
613 | - ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, | ||
614 | - new_l1_table, new_l1_size2); | ||
615 | + ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, new_l1_table, | ||
616 | + new_l1_size2, 0); | ||
617 | if (ret < 0) | ||
618 | goto fail; | ||
619 | for(i = 0; i < s->l1_size; i++) | ||
620 | @@ -XXX,XX +XXX,XX @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, | ||
621 | BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE); | ||
622 | stl_be_p(data, new_l1_size); | ||
623 | stq_be_p(data + 4, new_l1_table_offset); | ||
624 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), | ||
625 | - data, sizeof(data)); | ||
626 | + ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), data, | ||
627 | + sizeof(data), 0); | ||
628 | if (ret < 0) { | ||
629 | goto fail; | ||
630 | } | ||
631 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index) | ||
632 | BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); | ||
633 | ret = bdrv_pwrite_sync(bs->file, | ||
634 | s->l1_table_offset + L1E_SIZE * l1_start_index, | ||
635 | - buf, bufsize); | ||
636 | + buf, bufsize, 0); | ||
637 | if (ret < 0) { | ||
638 | return ret; | ||
639 | } | ||
640 | @@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, | ||
641 | (void **)&l2_slice); | ||
642 | } else { | ||
643 | /* load inactive L2 tables from disk */ | ||
644 | - ret = bdrv_pread(bs->file, slice_offset, l2_slice, slice_size2); | ||
645 | + ret = bdrv_pread(bs->file, slice_offset, l2_slice, | ||
646 | + slice_size2, 0); | ||
647 | } | ||
648 | if (ret < 0) { | ||
649 | goto fail; | ||
650 | @@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, | ||
651 | goto fail; | ||
652 | } | ||
653 | |||
654 | - ret = bdrv_pwrite(bs->file, slice_offset, | ||
655 | - l2_slice, slice_size2); | ||
656 | + ret = bdrv_pwrite(bs->file, slice_offset, l2_slice, | ||
657 | + slice_size2, 0); | ||
658 | if (ret < 0) { | ||
659 | goto fail; | ||
660 | } | ||
661 | @@ -XXX,XX +XXX,XX @@ int qcow2_expand_zero_clusters(BlockDriverState *bs, | ||
662 | |||
663 | l1_table = new_l1_table; | ||
664 | |||
665 | - ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset, | ||
666 | - l1_table, l1_size2); | ||
667 | + ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset, l1_table, | ||
668 | + l1_size2, 0); | ||
669 | if (ret < 0) { | ||
670 | goto fail; | ||
671 | } | ||
672 | diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c | ||
673 | index XXXXXXX..XXXXXXX 100644 | ||
674 | --- a/block/qcow2-refcount.c | ||
675 | +++ b/block/qcow2-refcount.c | ||
676 | @@ -XXX,XX +XXX,XX @@ int qcow2_refcount_init(BlockDriverState *bs) | ||
677 | } | ||
678 | BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD); | ||
679 | ret = bdrv_pread(bs->file, s->refcount_table_offset, | ||
680 | - s->refcount_table, refcount_table_size2); | ||
681 | + s->refcount_table, refcount_table_size2, 0); | ||
682 | if (ret < 0) { | ||
683 | goto fail; | ||
684 | } | ||
685 | @@ -XXX,XX +XXX,XX @@ static int alloc_refcount_block(BlockDriverState *bs, | ||
686 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP); | ||
687 | ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset + | ||
688 | refcount_table_index * REFTABLE_ENTRY_SIZE, | ||
689 | - &data64, sizeof(data64)); | ||
690 | + &data64, sizeof(data64), 0); | ||
691 | if (ret < 0) { | ||
692 | goto fail; | ||
693 | } | ||
694 | @@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset, | ||
695 | |||
696 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE); | ||
697 | ret = bdrv_pwrite_sync(bs->file, table_offset, new_table, | ||
698 | - table_size * REFTABLE_ENTRY_SIZE); | ||
699 | + table_size * REFTABLE_ENTRY_SIZE, 0); | ||
700 | if (ret < 0) { | ||
701 | goto fail; | ||
702 | } | ||
703 | @@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset, | ||
704 | data.d32 = cpu_to_be32(table_clusters); | ||
705 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE); | ||
706 | ret = bdrv_pwrite_sync(bs->file, | ||
707 | - offsetof(QCowHeader, refcount_table_offset), | ||
708 | - &data, sizeof(data)); | ||
709 | + offsetof(QCowHeader, refcount_table_offset), &data, | ||
710 | + sizeof(data), 0); | ||
711 | if (ret < 0) { | ||
712 | goto fail; | ||
713 | } | ||
714 | @@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, | ||
715 | } | ||
716 | l1_allocated = true; | ||
717 | |||
718 | - ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2); | ||
719 | + ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2, 0); | ||
720 | if (ret < 0) { | ||
721 | goto fail; | ||
722 | } | ||
723 | @@ -XXX,XX +XXX,XX @@ fail: | ||
724 | cpu_to_be64s(&l1_table[i]); | ||
725 | } | ||
726 | |||
727 | - ret = bdrv_pwrite_sync(bs->file, l1_table_offset, | ||
728 | - l1_table, l1_size2); | ||
729 | + ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table, l1_size2, | ||
730 | + 0); | ||
731 | |||
732 | for (i = 0; i < l1_size; i++) { | ||
733 | be64_to_cpus(&l1_table[i]); | ||
734 | @@ -XXX,XX +XXX,XX @@ static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res, | ||
735 | } | ||
736 | |||
737 | ret = bdrv_pwrite_sync(bs->file, l2e_offset, &l2_table[idx], | ||
738 | - l2_entry_size(s)); | ||
739 | + l2_entry_size(s), 0); | ||
740 | if (ret < 0) { | ||
741 | fprintf(stderr, "ERROR: Failed to overwrite L2 " | ||
742 | "table entry: %s\n", strerror(-ret)); | ||
743 | @@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, | ||
744 | bool metadata_overlap; | ||
745 | |||
746 | /* Read L2 table from disk */ | ||
747 | - ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes); | ||
748 | + ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes, 0); | ||
749 | if (ret < 0) { | ||
750 | fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); | ||
751 | res->check_errors++; | ||
752 | @@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs, | ||
753 | } | ||
754 | |||
755 | /* Read L1 table entries from disk */ | ||
756 | - ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes); | ||
757 | + ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes, 0); | ||
758 | if (ret < 0) { | ||
759 | fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n"); | ||
760 | res->check_errors++; | ||
761 | @@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, | ||
762 | } | ||
763 | |||
764 | ret = bdrv_pread(bs->file, l2_offset, l2_table, | ||
765 | - s->l2_size * l2_entry_size(s)); | ||
766 | + s->l2_size * l2_entry_size(s), 0); | ||
767 | if (ret < 0) { | ||
768 | fprintf(stderr, "ERROR: Could not read L2 table: %s\n", | ||
769 | strerror(-ret)); | ||
770 | @@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, | ||
771 | goto fail; | ||
772 | } | ||
773 | |||
774 | - ret = bdrv_pwrite(bs->file, l2_offset, l2_table, | ||
775 | - s->cluster_size); | ||
776 | + ret = bdrv_pwrite(bs->file, l2_offset, l2_table, s->cluster_size, | ||
777 | + 0); | ||
778 | if (ret < 0) { | ||
779 | fprintf(stderr, "ERROR: Could not write L2 table: %s\n", | ||
780 | strerror(-ret)); | ||
781 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcounts_write_refblocks( | ||
782 | refblock_index * s->cluster_size); | ||
783 | |||
784 | ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock, | ||
785 | - s->cluster_size); | ||
786 | + s->cluster_size, 0); | ||
787 | if (ret < 0) { | ||
788 | error_setg_errno(errp, -ret, "ERROR writing refblock"); | ||
789 | return ret; | ||
790 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs, | ||
791 | |||
792 | assert(reftable_length < INT_MAX); | ||
793 | ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable, | ||
794 | - reftable_length); | ||
795 | + reftable_length, 0); | ||
796 | if (ret < 0) { | ||
797 | error_setg_errno(errp, -ret, "ERROR writing reftable"); | ||
798 | goto fail; | ||
799 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs, | ||
800 | ret = bdrv_pwrite_sync(bs->file, | ||
801 | offsetof(QCowHeader, refcount_table_offset), | ||
802 | &reftable_offset_and_clusters, | ||
803 | - sizeof(reftable_offset_and_clusters)); | ||
804 | + sizeof(reftable_offset_and_clusters), 0); | ||
805 | if (ret < 0) { | ||
806 | error_setg_errno(errp, -ret, "ERROR setting reftable"); | ||
807 | goto fail; | ||
808 | @@ -XXX,XX +XXX,XX @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, | ||
809 | return -ENOMEM; | ||
810 | } | ||
811 | |||
812 | - ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2); | ||
813 | + ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2, 0); | ||
814 | if (ret < 0) { | ||
815 | g_free(l1); | ||
816 | return ret; | ||
817 | @@ -XXX,XX +XXX,XX @@ static int flush_refblock(BlockDriverState *bs, uint64_t **reftable, | ||
818 | return ret; | ||
819 | } | ||
820 | |||
821 | - ret = bdrv_pwrite(bs->file, offset, refblock, s->cluster_size); | ||
822 | + ret = bdrv_pwrite(bs->file, offset, refblock, s->cluster_size, 0); | ||
823 | if (ret < 0) { | ||
824 | error_setg_errno(errp, -ret, "Failed to write refblock"); | ||
825 | return ret; | ||
826 | @@ -XXX,XX +XXX,XX @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, | ||
827 | } | ||
828 | |||
829 | ret = bdrv_pwrite(bs->file, new_reftable_offset, new_reftable, | ||
830 | - new_reftable_size * REFTABLE_ENTRY_SIZE); | ||
831 | + new_reftable_size * REFTABLE_ENTRY_SIZE, 0); | ||
832 | |||
833 | for (i = 0; i < new_reftable_size; i++) { | ||
834 | be64_to_cpus(&new_reftable[i]); | ||
835 | @@ -XXX,XX +XXX,XX @@ int qcow2_shrink_reftable(BlockDriverState *bs) | ||
836 | } | ||
837 | |||
838 | ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset, reftable_tmp, | ||
839 | - s->refcount_table_size * REFTABLE_ENTRY_SIZE); | ||
840 | + s->refcount_table_size * REFTABLE_ENTRY_SIZE, 0); | ||
841 | /* | ||
842 | * If the write in the reftable failed the image may contain a partially | ||
843 | * overwritten reftable. In this case it would be better to clear the | ||
844 | diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c | ||
845 | index XXXXXXX..XXXXXXX 100644 | ||
846 | --- a/block/qcow2-snapshot.c | ||
847 | +++ b/block/qcow2-snapshot.c | ||
848 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
849 | |||
850 | /* Read statically sized part of the snapshot header */ | ||
851 | offset = ROUND_UP(offset, 8); | ||
852 | - ret = bdrv_pread(bs->file, offset, &h, sizeof(h)); | ||
853 | + ret = bdrv_pread(bs->file, offset, &h, sizeof(h), 0); | ||
854 | if (ret < 0) { | ||
855 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
856 | goto fail; | ||
857 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
858 | |||
859 | /* Read known extra data */ | ||
860 | ret = bdrv_pread(bs->file, offset, &extra, | ||
861 | - MIN(sizeof(extra), sn->extra_data_size)); | ||
862 | + MIN(sizeof(extra), sn->extra_data_size), 0); | ||
863 | if (ret < 0) { | ||
864 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
865 | goto fail; | ||
866 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
867 | unknown_extra_data_size = sn->extra_data_size - sizeof(extra); | ||
868 | sn->unknown_extra_data = g_malloc(unknown_extra_data_size); | ||
869 | ret = bdrv_pread(bs->file, offset, sn->unknown_extra_data, | ||
870 | - unknown_extra_data_size); | ||
871 | + unknown_extra_data_size, 0); | ||
872 | if (ret < 0) { | ||
873 | error_setg_errno(errp, -ret, | ||
874 | "Failed to read snapshot table"); | ||
875 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
876 | |||
877 | /* Read snapshot ID */ | ||
878 | sn->id_str = g_malloc(id_str_size + 1); | ||
879 | - ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size); | ||
880 | + ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size, 0); | ||
881 | if (ret < 0) { | ||
882 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
883 | goto fail; | ||
884 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
885 | |||
886 | /* Read snapshot name */ | ||
887 | sn->name = g_malloc(name_size + 1); | ||
888 | - ret = bdrv_pread(bs->file, offset, sn->name, name_size); | ||
889 | + ret = bdrv_pread(bs->file, offset, sn->name, name_size, 0); | ||
890 | if (ret < 0) { | ||
891 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
892 | goto fail; | ||
893 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
894 | h.name_size = cpu_to_be16(name_size); | ||
895 | offset = ROUND_UP(offset, 8); | ||
896 | |||
897 | - ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h)); | ||
898 | + ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h), 0); | ||
899 | if (ret < 0) { | ||
900 | goto fail; | ||
901 | } | ||
902 | offset += sizeof(h); | ||
903 | |||
904 | - ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra)); | ||
905 | + ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra), 0); | ||
906 | if (ret < 0) { | ||
907 | goto fail; | ||
908 | } | ||
909 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
910 | assert(sn->unknown_extra_data); | ||
911 | |||
912 | ret = bdrv_pwrite(bs->file, offset, sn->unknown_extra_data, | ||
913 | - unknown_extra_data_size); | ||
914 | + unknown_extra_data_size, 0); | ||
915 | if (ret < 0) { | ||
916 | goto fail; | ||
917 | } | ||
918 | offset += unknown_extra_data_size; | ||
919 | } | ||
920 | |||
921 | - ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size); | ||
922 | + ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size, 0); | ||
923 | if (ret < 0) { | ||
924 | goto fail; | ||
925 | } | ||
926 | offset += id_str_size; | ||
927 | |||
928 | - ret = bdrv_pwrite(bs->file, offset, sn->name, name_size); | ||
929 | + ret = bdrv_pwrite(bs->file, offset, sn->name, name_size, 0); | ||
930 | if (ret < 0) { | ||
931 | goto fail; | ||
932 | } | ||
933 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
934 | header_data.snapshots_offset = cpu_to_be64(snapshots_offset); | ||
935 | |||
936 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
937 | - &header_data, sizeof(header_data)); | ||
938 | + &header_data, sizeof(header_data), 0); | ||
939 | if (ret < 0) { | ||
940 | goto fail; | ||
941 | } | ||
942 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, | ||
943 | |||
944 | /* qcow2_do_open() discards this information in check mode */ | ||
945 | ret = bdrv_pread(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
946 | - &snapshot_table_pointer, sizeof(snapshot_table_pointer)); | ||
947 | + &snapshot_table_pointer, sizeof(snapshot_table_pointer), | ||
948 | + 0); | ||
949 | if (ret < 0) { | ||
950 | result->check_errors++; | ||
951 | fprintf(stderr, "ERROR failed to read the snapshot table pointer from " | ||
952 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, | ||
953 | snapshot_table_pointer.nb_snapshots = cpu_to_be32(s->nb_snapshots); | ||
954 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
955 | &snapshot_table_pointer.nb_snapshots, | ||
956 | - sizeof(snapshot_table_pointer.nb_snapshots)); | ||
957 | + sizeof(snapshot_table_pointer.nb_snapshots), 0); | ||
958 | if (ret < 0) { | ||
959 | result->check_errors++; | ||
960 | fprintf(stderr, "ERROR failed to update the snapshot count in the " | ||
961 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
962 | } | ||
963 | |||
964 | ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table, | ||
965 | - s->l1_size * L1E_SIZE); | ||
966 | + s->l1_size * L1E_SIZE, 0); | ||
967 | if (ret < 0) { | ||
968 | goto fail; | ||
969 | } | ||
970 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) | ||
971 | goto fail; | ||
972 | } | ||
973 | |||
974 | - ret = bdrv_pread(bs->file, sn->l1_table_offset, | ||
975 | - sn_l1_table, sn_l1_bytes); | ||
976 | + ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_table, sn_l1_bytes, | ||
977 | + 0); | ||
978 | if (ret < 0) { | ||
979 | goto fail; | ||
980 | } | ||
981 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) | ||
982 | } | ||
983 | |||
984 | ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table, | ||
985 | - cur_l1_bytes); | ||
986 | + cur_l1_bytes, 0); | ||
987 | if (ret < 0) { | ||
988 | goto fail; | ||
989 | } | ||
990 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, | ||
991 | return -ENOMEM; | ||
992 | } | ||
993 | |||
994 | - ret = bdrv_pread(bs->file, sn->l1_table_offset, | ||
995 | - new_l1_table, new_l1_bytes); | ||
996 | + ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_table, | ||
997 | + new_l1_bytes, 0); | ||
998 | if (ret < 0) { | ||
999 | error_setg(errp, "Failed to read l1 table for snapshot"); | ||
1000 | qemu_vfree(new_l1_table); | ||
1001 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
1002 | index XXXXXXX..XXXXXXX 100644 | ||
1003 | --- a/block/qcow2.c | ||
1004 | +++ b/block/qcow2.c | ||
1005 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, | ||
1006 | return -1; | ||
1007 | } | ||
1008 | |||
1009 | - ret = bdrv_pread(bs->file, | ||
1010 | - s->crypto_header.offset + offset, buf, buflen); | ||
1011 | + ret = bdrv_pread(bs->file, s->crypto_header.offset + offset, buf, buflen, | ||
1012 | + 0); | ||
1013 | if (ret < 0) { | ||
1014 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
1015 | return -1; | ||
1016 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, | ||
1017 | return -1; | ||
1018 | } | ||
1019 | |||
1020 | - ret = bdrv_pwrite(bs->file, | ||
1021 | - s->crypto_header.offset + offset, buf, buflen); | ||
1022 | + ret = bdrv_pwrite(bs->file, s->crypto_header.offset + offset, buf, buflen, | ||
1023 | + 0); | ||
1024 | if (ret < 0) { | ||
1025 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
1026 | return -1; | ||
1027 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1028 | printf("attempting to read extended header in offset %lu\n", offset); | ||
1029 | #endif | ||
1030 | |||
1031 | - ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext)); | ||
1032 | + ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext), 0); | ||
1033 | if (ret < 0) { | ||
1034 | error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: " | ||
1035 | "pread fail from offset %" PRIu64, offset); | ||
1036 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1037 | sizeof(bs->backing_format)); | ||
1038 | return 2; | ||
1039 | } | ||
1040 | - ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len); | ||
1041 | + ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len, 0); | ||
1042 | if (ret < 0) { | ||
1043 | error_setg_errno(errp, -ret, "ERROR: ext_backing_format: " | ||
1044 | "Could not read format name"); | ||
1045 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1046 | case QCOW2_EXT_MAGIC_FEATURE_TABLE: | ||
1047 | if (p_feature_table != NULL) { | ||
1048 | void *feature_table = g_malloc0(ext.len + 2 * sizeof(Qcow2Feature)); | ||
1049 | - ret = bdrv_pread(bs->file, offset , feature_table, ext.len); | ||
1050 | + ret = bdrv_pread(bs->file, offset, feature_table, ext.len, 0); | ||
1051 | if (ret < 0) { | ||
1052 | error_setg_errno(errp, -ret, "ERROR: ext_feature_table: " | ||
1053 | "Could not read table"); | ||
1054 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1055 | return -EINVAL; | ||
1056 | } | ||
1057 | |||
1058 | - ret = bdrv_pread(bs->file, offset, &s->crypto_header, ext.len); | ||
1059 | + ret = bdrv_pread(bs->file, offset, &s->crypto_header, ext.len, 0); | ||
1060 | if (ret < 0) { | ||
1061 | error_setg_errno(errp, -ret, | ||
1062 | "Unable to read CRYPTO header extension"); | ||
1063 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1064 | break; | ||
1065 | } | ||
1066 | |||
1067 | - ret = bdrv_pread(bs->file, offset, &bitmaps_ext, ext.len); | ||
1068 | + ret = bdrv_pread(bs->file, offset, &bitmaps_ext, ext.len, 0); | ||
1069 | if (ret < 0) { | ||
1070 | error_setg_errno(errp, -ret, "bitmaps_ext: " | ||
1071 | "Could not read ext header"); | ||
1072 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1073 | case QCOW2_EXT_MAGIC_DATA_FILE: | ||
1074 | { | ||
1075 | s->image_data_file = g_malloc0(ext.len + 1); | ||
1076 | - ret = bdrv_pread(bs->file, offset, s->image_data_file, ext.len); | ||
1077 | + ret = bdrv_pread(bs->file, offset, s->image_data_file, ext.len, 0); | ||
1078 | if (ret < 0) { | ||
1079 | error_setg_errno(errp, -ret, | ||
1080 | "ERROR: Could not read data file name"); | ||
1081 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1082 | uext->len = ext.len; | ||
1083 | QLIST_INSERT_HEAD(&s->unknown_header_ext, uext, next); | ||
1084 | |||
1085 | - ret = bdrv_pread(bs->file, offset , uext->data, uext->len); | ||
1086 | + ret = bdrv_pread(bs->file, offset, uext->data, uext->len, 0); | ||
1087 | if (ret < 0) { | ||
1088 | error_setg_errno(errp, -ret, "ERROR: unknown extension: " | ||
1089 | "Could not read data"); | ||
1090 | @@ -XXX,XX +XXX,XX @@ int qcow2_mark_dirty(BlockDriverState *bs) | ||
1091 | |||
1092 | val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); | ||
1093 | ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features), | ||
1094 | - &val, sizeof(val)); | ||
1095 | + &val, sizeof(val), 0); | ||
1096 | if (ret < 0) { | ||
1097 | return ret; | ||
1098 | } | ||
1099 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1100 | uint64_t l1_vm_state_index; | ||
1101 | bool update_header = false; | ||
1102 | |||
1103 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); | ||
1104 | + ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
1105 | if (ret < 0) { | ||
1106 | error_setg_errno(errp, -ret, "Could not read qcow2 header"); | ||
1107 | goto fail; | ||
1108 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1109 | s->unknown_header_fields_size = header.header_length - sizeof(header); | ||
1110 | s->unknown_header_fields = g_malloc(s->unknown_header_fields_size); | ||
1111 | ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields, | ||
1112 | - s->unknown_header_fields_size); | ||
1113 | + s->unknown_header_fields_size, 0); | ||
1114 | if (ret < 0) { | ||
1115 | error_setg_errno(errp, -ret, "Could not read unknown qcow2 header " | ||
1116 | "fields"); | ||
1117 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1118 | goto fail; | ||
1119 | } | ||
1120 | ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, | ||
1121 | - s->l1_size * L1E_SIZE); | ||
1122 | + s->l1_size * L1E_SIZE, 0); | ||
1123 | if (ret < 0) { | ||
1124 | error_setg_errno(errp, -ret, "Could not read L1 table"); | ||
1125 | goto fail; | ||
1126 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1127 | goto fail; | ||
1128 | } | ||
1129 | ret = bdrv_pread(bs->file, header.backing_file_offset, | ||
1130 | - bs->auto_backing_file, len); | ||
1131 | + bs->auto_backing_file, len, 0); | ||
1132 | if (ret < 0) { | ||
1133 | error_setg_errno(errp, -ret, "Could not read backing file name"); | ||
1134 | goto fail; | ||
1135 | @@ -XXX,XX +XXX,XX @@ int qcow2_update_header(BlockDriverState *bs) | ||
1136 | } | ||
1137 | |||
1138 | /* Write the new header */ | ||
1139 | - ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size); | ||
1140 | + ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size, 0); | ||
1141 | if (ret < 0) { | ||
1142 | goto fail; | ||
1143 | } | ||
1144 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset, | ||
1145 | |||
1146 | /* write updated header.size */ | ||
1147 | offset = cpu_to_be64(offset); | ||
1148 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), | ||
1149 | - &offset, sizeof(offset)); | ||
1150 | + ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), &offset, | ||
1151 | + sizeof(offset), 0); | ||
1152 | if (ret < 0) { | ||
1153 | error_setg_errno(errp, -ret, "Failed to update the image size"); | ||
1154 | goto fail; | ||
1155 | @@ -XXX,XX +XXX,XX @@ static int make_completely_empty(BlockDriverState *bs) | ||
1156 | l1_ofs_rt_ofs_cls.reftable_offset = cpu_to_be64(s->cluster_size); | ||
1157 | l1_ofs_rt_ofs_cls.reftable_clusters = cpu_to_be32(1); | ||
1158 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_table_offset), | ||
1159 | - &l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls)); | ||
1160 | + &l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls), 0); | ||
1161 | if (ret < 0) { | ||
1162 | goto fail_broken_refcounts; | ||
1163 | } | ||
1164 | @@ -XXX,XX +XXX,XX @@ static int make_completely_empty(BlockDriverState *bs) | ||
1165 | |||
1166 | /* Enter the first refblock into the reftable */ | ||
1167 | rt_entry = cpu_to_be64(2 * s->cluster_size); | ||
1168 | - ret = bdrv_pwrite_sync(bs->file, s->cluster_size, | ||
1169 | - &rt_entry, sizeof(rt_entry)); | ||
1170 | + ret = bdrv_pwrite_sync(bs->file, s->cluster_size, &rt_entry, | ||
1171 | + sizeof(rt_entry), 0); | ||
1172 | if (ret < 0) { | ||
1173 | goto fail_broken_refcounts; | ||
1174 | } | ||
1175 | diff --git a/block/qed.c b/block/qed.c | ||
1176 | index XXXXXXX..XXXXXXX 100644 | ||
1177 | --- a/block/qed.c | ||
1178 | +++ b/block/qed.c | ||
1179 | @@ -XXX,XX +XXX,XX @@ int qed_write_header_sync(BDRVQEDState *s) | ||
1180 | int ret; | ||
1181 | |||
1182 | qed_header_cpu_to_le(&s->header, &le); | ||
1183 | - ret = bdrv_pwrite(s->bs->file, 0, &le, sizeof(le)); | ||
1184 | + ret = bdrv_pwrite(s->bs->file, 0, &le, sizeof(le), 0); | ||
1185 | if (ret != sizeof(le)) { | ||
1186 | return ret; | ||
1187 | } | ||
1188 | @@ -XXX,XX +XXX,XX @@ static int qed_read_string(BdrvChild *file, uint64_t offset, size_t n, | ||
1189 | if (n >= buflen) { | ||
1190 | return -EINVAL; | ||
1191 | } | ||
1192 | - ret = bdrv_pread(file, offset, buf, n); | ||
1193 | + ret = bdrv_pread(file, offset, buf, n, 0); | ||
1194 | if (ret < 0) { | ||
1195 | return ret; | ||
1196 | } | ||
1197 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, | ||
1198 | int64_t file_size; | ||
1199 | int ret; | ||
1200 | |||
1201 | - ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header)); | ||
1202 | + ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header), 0); | ||
1203 | if (ret < 0) { | ||
1204 | error_setg(errp, "Failed to read QED header"); | ||
1205 | return ret; | ||
1206 | @@ -XXX,XX +XXX,XX @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs, | ||
1207 | } | ||
1208 | |||
1209 | /* Write new header */ | ||
1210 | - ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len); | ||
1211 | + ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len, 0); | ||
1212 | g_free(buffer); | ||
1213 | if (ret == 0) { | ||
1214 | memcpy(&s->header, &new_header, sizeof(new_header)); | ||
1215 | diff --git a/block/vdi.c b/block/vdi.c | ||
1216 | index XXXXXXX..XXXXXXX 100644 | ||
1217 | --- a/block/vdi.c | ||
1218 | +++ b/block/vdi.c | ||
1219 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
1220 | |||
1221 | logout("\n"); | ||
1222 | |||
1223 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); | ||
1224 | + ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
1225 | if (ret < 0) { | ||
1226 | goto fail; | ||
1227 | } | ||
1228 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
1229 | } | ||
1230 | |||
1231 | ret = bdrv_pread(bs->file, header.offset_bmap, s->bmap, | ||
1232 | - bmap_size * SECTOR_SIZE); | ||
1233 | + bmap_size * SECTOR_SIZE, 0); | ||
1234 | if (ret < 0) { | ||
1235 | goto fail_free_bmap; | ||
1236 | } | ||
1237 | @@ -XXX,XX +XXX,XX @@ vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, | ||
1238 | * so this full-cluster write does not overlap a partial write | ||
1239 | * of the same cluster, issued from the "else" branch. | ||
1240 | */ | ||
1241 | - ret = bdrv_pwrite(bs->file, data_offset, block, s->block_size); | ||
1242 | + ret = bdrv_pwrite(bs->file, data_offset, block, s->block_size, 0); | ||
1243 | qemu_co_rwlock_unlock(&s->bmap_lock); | ||
1244 | } else { | ||
1245 | nonallocating_write: | ||
1246 | @@ -XXX,XX +XXX,XX @@ nonallocating_write: | ||
1247 | assert(VDI_IS_ALLOCATED(bmap_first)); | ||
1248 | *header = s->header; | ||
1249 | vdi_header_to_le(header); | ||
1250 | - ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header)); | ||
1251 | + ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header), 0); | ||
1252 | g_free(header); | ||
1253 | |||
1254 | if (ret < 0) { | ||
1255 | @@ -XXX,XX +XXX,XX @@ nonallocating_write: | ||
1256 | logout("will write %u block map sectors starting from entry %u\n", | ||
1257 | n_sectors, bmap_first); | ||
1258 | ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base, | ||
1259 | - n_sectors * SECTOR_SIZE); | ||
1260 | + n_sectors * SECTOR_SIZE, 0); | ||
1261 | } | ||
1262 | |||
1263 | return ret < 0 ? ret : 0; | ||
1264 | diff --git a/block/vhdx-log.c b/block/vhdx-log.c | ||
1265 | index XXXXXXX..XXXXXXX 100644 | ||
1266 | --- a/block/vhdx-log.c | ||
1267 | +++ b/block/vhdx-log.c | ||
1268 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log, | ||
1269 | |||
1270 | offset = log->offset + read; | ||
1271 | |||
1272 | - ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader)); | ||
1273 | + ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader), 0); | ||
1274 | if (ret < 0) { | ||
1275 | goto exit; | ||
1276 | } | ||
1277 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_read_sectors(BlockDriverState *bs, VHDXLogEntries *log, | ||
1278 | } | ||
1279 | offset = log->offset + read; | ||
1280 | |||
1281 | - ret = bdrv_pread(bs->file, offset, buffer, VHDX_LOG_SECTOR_SIZE); | ||
1282 | + ret = bdrv_pread(bs->file, offset, buffer, VHDX_LOG_SECTOR_SIZE, 0); | ||
1283 | if (ret < 0) { | ||
1284 | goto exit; | ||
1285 | } | ||
1286 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log, | ||
1287 | /* full */ | ||
1288 | break; | ||
1289 | } | ||
1290 | - ret = bdrv_pwrite(bs->file, offset, buffer_tmp, | ||
1291 | - VHDX_LOG_SECTOR_SIZE); | ||
1292 | + ret = bdrv_pwrite(bs->file, offset, buffer_tmp, VHDX_LOG_SECTOR_SIZE, | ||
1293 | + 0); | ||
1294 | if (ret < 0) { | ||
1295 | goto exit; | ||
1296 | } | ||
1297 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_flush_desc(BlockDriverState *bs, VHDXLogDescriptor *desc, | ||
1298 | /* count is only > 1 if we are writing zeroes */ | ||
1299 | for (i = 0; i < count; i++) { | ||
1300 | ret = bdrv_pwrite_sync(bs->file, file_offset, buffer, | ||
1301 | - VHDX_LOG_SECTOR_SIZE); | ||
1302 | + VHDX_LOG_SECTOR_SIZE, 0); | ||
1303 | if (ret < 0) { | ||
1304 | goto exit; | ||
1305 | } | ||
1306 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, | ||
1307 | if (i == 0 && leading_length) { | ||
1308 | /* partial sector at the front of the buffer */ | ||
1309 | ret = bdrv_pread(bs->file, file_offset, merged_sector, | ||
1310 | - VHDX_LOG_SECTOR_SIZE); | ||
1311 | + VHDX_LOG_SECTOR_SIZE, 0); | ||
1312 | if (ret < 0) { | ||
1313 | goto exit; | ||
1314 | } | ||
1315 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, | ||
1316 | sector_write = merged_sector; | ||
1317 | } else if (i == sectors - 1 && trailing_length) { | ||
1318 | /* partial sector at the end of the buffer */ | ||
1319 | - ret = bdrv_pread(bs->file, | ||
1320 | - file_offset, | ||
1321 | - merged_sector + trailing_length, | ||
1322 | - VHDX_LOG_SECTOR_SIZE - trailing_length); | ||
1323 | + ret = bdrv_pread(bs->file, file_offset, | ||
1324 | + merged_sector + trailing_length, | ||
1325 | + VHDX_LOG_SECTOR_SIZE - trailing_length, 0); | ||
1326 | if (ret < 0) { | ||
1327 | goto exit; | ||
1328 | } | ||
1329 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
1330 | index XXXXXXX..XXXXXXX 100644 | ||
1331 | --- a/block/vhdx.c | ||
1332 | +++ b/block/vhdx.c | ||
1333 | @@ -XXX,XX +XXX,XX @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr, | ||
1334 | buffer = qemu_blockalign(bs_file, VHDX_HEADER_SIZE); | ||
1335 | if (read) { | ||
1336 | /* if true, we can't assume the extra reserved bytes are 0 */ | ||
1337 | - ret = bdrv_pread(file, offset, buffer, VHDX_HEADER_SIZE); | ||
1338 | + ret = bdrv_pread(file, offset, buffer, VHDX_HEADER_SIZE, 0); | ||
1339 | if (ret < 0) { | ||
1340 | goto exit; | ||
1341 | } | ||
1342 | @@ -XXX,XX +XXX,XX @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr, | ||
1343 | vhdx_header_le_export(hdr, header_le); | ||
1344 | vhdx_update_checksum(buffer, VHDX_HEADER_SIZE, | ||
1345 | offsetof(VHDXHeader, checksum)); | ||
1346 | - ret = bdrv_pwrite_sync(file, offset, header_le, sizeof(VHDXHeader)); | ||
1347 | + ret = bdrv_pwrite_sync(file, offset, header_le, sizeof(VHDXHeader), 0); | ||
1348 | |||
1349 | exit: | ||
1350 | qemu_vfree(buffer); | ||
1351 | @@ -XXX,XX +XXX,XX @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s, | ||
1352 | /* We have to read the whole VHDX_HEADER_SIZE instead of | ||
1353 | * sizeof(VHDXHeader), because the checksum is over the whole | ||
1354 | * region */ | ||
1355 | - ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, buffer, | ||
1356 | - VHDX_HEADER_SIZE); | ||
1357 | + ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, buffer, VHDX_HEADER_SIZE, | ||
1358 | + 0); | ||
1359 | if (ret < 0) { | ||
1360 | goto fail; | ||
1361 | } | ||
1362 | @@ -XXX,XX +XXX,XX @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s, | ||
1363 | } | ||
1364 | } | ||
1365 | |||
1366 | - ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, buffer, | ||
1367 | - VHDX_HEADER_SIZE); | ||
1368 | + ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, buffer, VHDX_HEADER_SIZE, | ||
1369 | + 0); | ||
1370 | if (ret < 0) { | ||
1371 | goto fail; | ||
1372 | } | ||
1373 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s) | ||
1374 | buffer = qemu_blockalign(bs, VHDX_HEADER_BLOCK_SIZE); | ||
1375 | |||
1376 | ret = bdrv_pread(bs->file, VHDX_REGION_TABLE_OFFSET, buffer, | ||
1377 | - VHDX_HEADER_BLOCK_SIZE); | ||
1378 | + VHDX_HEADER_BLOCK_SIZE, 0); | ||
1379 | if (ret < 0) { | ||
1380 | goto fail; | ||
1381 | } | ||
1382 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1383 | buffer = qemu_blockalign(bs, VHDX_METADATA_TABLE_MAX_SIZE); | ||
1384 | |||
1385 | ret = bdrv_pread(bs->file, s->metadata_rt.file_offset, buffer, | ||
1386 | - VHDX_METADATA_TABLE_MAX_SIZE); | ||
1387 | + VHDX_METADATA_TABLE_MAX_SIZE, 0); | ||
1388 | if (ret < 0) { | ||
1389 | goto exit; | ||
1390 | } | ||
1391 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1392 | s->metadata_entries.file_parameters_entry.offset | ||
1393 | + s->metadata_rt.file_offset, | ||
1394 | &s->params, | ||
1395 | - sizeof(s->params)); | ||
1396 | + sizeof(s->params), | ||
1397 | + 0); | ||
1398 | |||
1399 | if (ret < 0) { | ||
1400 | goto exit; | ||
1401 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1402 | s->metadata_entries.virtual_disk_size_entry.offset | ||
1403 | + s->metadata_rt.file_offset, | ||
1404 | &s->virtual_disk_size, | ||
1405 | - sizeof(uint64_t)); | ||
1406 | + sizeof(uint64_t), | ||
1407 | + 0); | ||
1408 | if (ret < 0) { | ||
1409 | goto exit; | ||
1410 | } | ||
1411 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1412 | s->metadata_entries.logical_sector_size_entry.offset | ||
1413 | + s->metadata_rt.file_offset, | ||
1414 | &s->logical_sector_size, | ||
1415 | - sizeof(uint32_t)); | ||
1416 | + sizeof(uint32_t), | ||
1417 | + 0); | ||
1418 | if (ret < 0) { | ||
1419 | goto exit; | ||
1420 | } | ||
1421 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1422 | s->metadata_entries.phys_sector_size_entry.offset | ||
1423 | + s->metadata_rt.file_offset, | ||
1424 | &s->physical_sector_size, | ||
1425 | - sizeof(uint32_t)); | ||
1426 | + sizeof(uint32_t), | ||
1427 | + 0); | ||
1428 | if (ret < 0) { | ||
1429 | goto exit; | ||
1430 | } | ||
1431 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
1432 | QLIST_INIT(&s->regions); | ||
1433 | |||
1434 | /* validate the file signature */ | ||
1435 | - ret = bdrv_pread(bs->file, 0, &signature, sizeof(uint64_t)); | ||
1436 | + ret = bdrv_pread(bs->file, 0, &signature, sizeof(uint64_t), 0); | ||
1437 | if (ret < 0) { | ||
1438 | goto fail; | ||
1439 | } | ||
1440 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
1441 | goto fail; | ||
1442 | } | ||
1443 | |||
1444 | - ret = bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.length); | ||
1445 | + ret = bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.length, 0); | ||
1446 | if (ret < 0) { | ||
1447 | goto fail; | ||
1448 | } | ||
1449 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
1450 | index XXXXXXX..XXXXXXX 100644 | ||
1451 | --- a/block/vmdk.c | ||
1452 | +++ b/block/vmdk.c | ||
1453 | @@ -XXX,XX +XXX,XX @@ static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid) | ||
1454 | int ret; | ||
1455 | |||
1456 | desc = g_malloc0(DESC_SIZE); | ||
1457 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE); | ||
1458 | + ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1459 | if (ret < 0) { | ||
1460 | goto out; | ||
1461 | } | ||
1462 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) | ||
1463 | |||
1464 | desc = g_malloc0(DESC_SIZE); | ||
1465 | tmp_desc = g_malloc0(DESC_SIZE); | ||
1466 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE); | ||
1467 | + ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1468 | if (ret < 0) { | ||
1469 | goto out; | ||
1470 | } | ||
1471 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) | ||
1472 | pstrcat(desc, DESC_SIZE, tmp_desc); | ||
1473 | } | ||
1474 | |||
1475 | - ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE); | ||
1476 | + ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1477 | |||
1478 | out: | ||
1479 | g_free(desc); | ||
1480 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parent_open(BlockDriverState *bs) | ||
1481 | int ret; | ||
1482 | |||
1483 | desc = g_malloc0(DESC_SIZE + 1); | ||
1484 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE); | ||
1485 | + ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1486 | if (ret < 0) { | ||
1487 | goto out; | ||
1488 | } | ||
1489 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
1490 | return -ENOMEM; | ||
1491 | } | ||
1492 | |||
1493 | - ret = bdrv_pread(extent->file, | ||
1494 | - extent->l1_table_offset, | ||
1495 | - extent->l1_table, | ||
1496 | - l1_size); | ||
1497 | + ret = bdrv_pread(extent->file, extent->l1_table_offset, extent->l1_table, | ||
1498 | + l1_size, 0); | ||
1499 | if (ret < 0) { | ||
1500 | bdrv_refresh_filename(extent->file->bs); | ||
1501 | error_setg_errno(errp, -ret, | ||
1502 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
1503 | ret = -ENOMEM; | ||
1504 | goto fail_l1; | ||
1505 | } | ||
1506 | - ret = bdrv_pread(extent->file, | ||
1507 | - extent->l1_backup_table_offset, | ||
1508 | - extent->l1_backup_table, | ||
1509 | - l1_size); | ||
1510 | + ret = bdrv_pread(extent->file, extent->l1_backup_table_offset, | ||
1511 | + extent->l1_backup_table, l1_size, 0); | ||
1512 | if (ret < 0) { | ||
1513 | bdrv_refresh_filename(extent->file->bs); | ||
1514 | error_setg_errno(errp, -ret, | ||
1515 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, | ||
1516 | VMDK3Header header; | ||
1517 | VmdkExtent *extent = NULL; | ||
1518 | |||
1519 | - ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header)); | ||
1520 | + ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header), 0); | ||
1521 | if (ret < 0) { | ||
1522 | bdrv_refresh_filename(file->bs); | ||
1523 | error_setg_errno(errp, -ret, | ||
1524 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_se_sparse(BlockDriverState *bs, | ||
1525 | |||
1526 | assert(sizeof(const_header) == SECTOR_SIZE); | ||
1527 | |||
1528 | - ret = bdrv_pread(file, 0, &const_header, sizeof(const_header)); | ||
1529 | + ret = bdrv_pread(file, 0, &const_header, sizeof(const_header), 0); | ||
1530 | if (ret < 0) { | ||
1531 | bdrv_refresh_filename(file->bs); | ||
1532 | error_setg_errno(errp, -ret, | ||
1533 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_se_sparse(BlockDriverState *bs, | ||
1534 | |||
1535 | assert(sizeof(volatile_header) == SECTOR_SIZE); | ||
1536 | |||
1537 | - ret = bdrv_pread(file, | ||
1538 | - const_header.volatile_header_offset * SECTOR_SIZE, | ||
1539 | - &volatile_header, sizeof(volatile_header)); | ||
1540 | + ret = bdrv_pread(file, const_header.volatile_header_offset * SECTOR_SIZE, | ||
1541 | + &volatile_header, sizeof(volatile_header), 0); | ||
1542 | if (ret < 0) { | ||
1543 | bdrv_refresh_filename(file->bs); | ||
1544 | error_setg_errno(errp, -ret, | ||
1545 | @@ -XXX,XX +XXX,XX @@ static char *vmdk_read_desc(BdrvChild *file, uint64_t desc_offset, Error **errp) | ||
1546 | size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */ | ||
1547 | buf = g_malloc(size + 1); | ||
1548 | |||
1549 | - ret = bdrv_pread(file, desc_offset, buf, size); | ||
1550 | + ret = bdrv_pread(file, desc_offset, buf, size, 0); | ||
1551 | if (ret < 0) { | ||
1552 | error_setg_errno(errp, -ret, "Could not read from file"); | ||
1553 | g_free(buf); | ||
1554 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmdk4(BlockDriverState *bs, | ||
1555 | int64_t l1_backup_offset = 0; | ||
1556 | bool compressed; | ||
1557 | |||
1558 | - ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header)); | ||
1559 | + ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header), 0); | ||
1560 | if (ret < 0) { | ||
1561 | bdrv_refresh_filename(file->bs); | ||
1562 | error_setg_errno(errp, -ret, | ||
1563 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmdk4(BlockDriverState *bs, | ||
1564 | } QEMU_PACKED eos_marker; | ||
1565 | } QEMU_PACKED footer; | ||
1566 | |||
1567 | - ret = bdrv_pread(file, | ||
1568 | - bs->file->bs->total_sectors * 512 - 1536, | ||
1569 | - &footer, sizeof(footer)); | ||
1570 | + ret = bdrv_pread(file, bs->file->bs->total_sectors * 512 - 1536, | ||
1571 | + &footer, sizeof(footer), 0); | ||
1572 | if (ret < 0) { | ||
1573 | error_setg_errno(errp, -ret, "Failed to read footer"); | ||
1574 | return ret; | ||
1575 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1576 | /* qcow2 emits this on bs->file instead of bs->backing */ | ||
1577 | BLKDBG_EVENT(extent->file, BLKDBG_COW_READ); | ||
1578 | ret = bdrv_pread(bs->backing, offset, whole_grain, | ||
1579 | - skip_start_bytes); | ||
1580 | + skip_start_bytes, 0); | ||
1581 | if (ret < 0) { | ||
1582 | ret = VMDK_ERROR; | ||
1583 | goto exit; | ||
1584 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1585 | } | ||
1586 | BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE); | ||
1587 | ret = bdrv_pwrite(extent->file, cluster_offset, whole_grain, | ||
1588 | - skip_start_bytes); | ||
1589 | + skip_start_bytes, 0); | ||
1590 | if (ret < 0) { | ||
1591 | ret = VMDK_ERROR; | ||
1592 | goto exit; | ||
1593 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1594 | BLKDBG_EVENT(extent->file, BLKDBG_COW_READ); | ||
1595 | ret = bdrv_pread(bs->backing, offset + skip_end_bytes, | ||
1596 | whole_grain + skip_end_bytes, | ||
1597 | - cluster_bytes - skip_end_bytes); | ||
1598 | + cluster_bytes - skip_end_bytes, 0); | ||
1599 | if (ret < 0) { | ||
1600 | ret = VMDK_ERROR; | ||
1601 | goto exit; | ||
1602 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1603 | BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE); | ||
1604 | ret = bdrv_pwrite(extent->file, cluster_offset + skip_end_bytes, | ||
1605 | whole_grain + skip_end_bytes, | ||
1606 | - cluster_bytes - skip_end_bytes); | ||
1607 | + cluster_bytes - skip_end_bytes, 0); | ||
1608 | if (ret < 0) { | ||
1609 | ret = VMDK_ERROR; | ||
1610 | goto exit; | ||
1611 | @@ -XXX,XX +XXX,XX @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, | ||
1612 | if (bdrv_pwrite(extent->file, | ||
1613 | ((int64_t)m_data->l2_offset * 512) | ||
1614 | + (m_data->l2_index * sizeof(offset)), | ||
1615 | - &offset, sizeof(offset)) < 0) { | ||
1616 | + &offset, sizeof(offset), 0) < 0) { | ||
1617 | return VMDK_ERROR; | ||
1618 | } | ||
1619 | /* update backup L2 table */ | ||
1620 | @@ -XXX,XX +XXX,XX @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, | ||
1621 | if (bdrv_pwrite(extent->file, | ||
1622 | ((int64_t)m_data->l2_offset * 512) | ||
1623 | + (m_data->l2_index * sizeof(offset)), | ||
1624 | - &offset, sizeof(offset)) < 0) { | ||
1625 | + &offset, sizeof(offset), 0) < 0) { | ||
1626 | return VMDK_ERROR; | ||
1627 | } | ||
1628 | } | ||
1629 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
1630 | if (bdrv_pread(extent->file, | ||
1631 | (int64_t)l2_offset * 512, | ||
1632 | l2_table, | ||
1633 | - l2_size_bytes | ||
1634 | + l2_size_bytes, | ||
1635 | + 0 | ||
1636 | ) != l2_size_bytes) { | ||
1637 | return VMDK_ERROR; | ||
1638 | } | ||
1639 | @@ -XXX,XX +XXX,XX @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, | ||
1640 | cluster_buf = g_malloc(buf_bytes); | ||
1641 | uncomp_buf = g_malloc(cluster_bytes); | ||
1642 | BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED); | ||
1643 | - ret = bdrv_pread(extent->file, | ||
1644 | - cluster_offset, | ||
1645 | - cluster_buf, buf_bytes); | ||
1646 | + ret = bdrv_pread(extent->file, cluster_offset, cluster_buf, buf_bytes, 0); | ||
1647 | if (ret < 0) { | ||
1648 | goto out; | ||
1649 | } | ||
1650 | diff --git a/block/vpc.c b/block/vpc.c | ||
1651 | index XXXXXXX..XXXXXXX 100644 | ||
1652 | --- a/block/vpc.c | ||
1653 | +++ b/block/vpc.c | ||
1654 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1655 | goto fail; | ||
1656 | } | ||
1657 | |||
1658 | - ret = bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer)); | ||
1659 | + ret = bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer), 0); | ||
1660 | if (ret < 0) { | ||
1661 | error_setg(errp, "Unable to read VHD header"); | ||
1662 | goto fail; | ||
1663 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1664 | } | ||
1665 | |||
1666 | /* If a fixed disk, the footer is found only at the end of the file */ | ||
1667 | - ret = bdrv_pread(bs->file, offset - sizeof(*footer), | ||
1668 | - footer, sizeof(*footer)); | ||
1669 | + ret = bdrv_pread(bs->file, offset - sizeof(*footer), footer, | ||
1670 | + sizeof(*footer), 0); | ||
1671 | if (ret < 0) { | ||
1672 | goto fail; | ||
1673 | } | ||
1674 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1675 | |||
1676 | if (disk_type == VHD_DYNAMIC) { | ||
1677 | ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), | ||
1678 | - &dyndisk_header, sizeof(dyndisk_header)); | ||
1679 | + &dyndisk_header, sizeof(dyndisk_header), 0); | ||
1680 | if (ret < 0) { | ||
1681 | error_setg(errp, "Error reading dynamic VHD header"); | ||
1682 | goto fail; | ||
1683 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1684 | s->bat_offset = be64_to_cpu(dyndisk_header.table_offset); | ||
1685 | |||
1686 | ret = bdrv_pread(bs->file, s->bat_offset, s->pagetable, | ||
1687 | - pagetable_size); | ||
1688 | + pagetable_size, 0); | ||
1689 | if (ret < 0) { | ||
1690 | error_setg(errp, "Error reading pagetable"); | ||
1691 | goto fail; | ||
1692 | @@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset, | ||
1693 | |||
1694 | s->last_bitmap_offset = bitmap_offset; | ||
1695 | memset(bitmap, 0xff, s->bitmap_size); | ||
1696 | - r = bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size); | ||
1697 | + r = bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size, | ||
1698 | + 0); | ||
1699 | if (r < 0) { | ||
1700 | *err = r; | ||
1701 | return -2; | ||
1702 | @@ -XXX,XX +XXX,XX @@ static int rewrite_footer(BlockDriverState *bs) | ||
1703 | BDRVVPCState *s = bs->opaque; | ||
1704 | int64_t offset = s->free_data_block_offset; | ||
1705 | |||
1706 | - ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->footer)); | ||
1707 | + ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->footer), 0); | ||
1708 | if (ret < 0) | ||
1709 | return ret; | ||
1710 | |||
1711 | @@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset) | ||
1712 | /* Initialize the block's bitmap */ | ||
1713 | memset(bitmap, 0xff, s->bitmap_size); | ||
1714 | ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap, | ||
1715 | - s->bitmap_size); | ||
1716 | + s->bitmap_size, 0); | ||
1717 | if (ret < 0) { | ||
1718 | return ret; | ||
1719 | } | ||
1720 | @@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset) | ||
1721 | /* Write BAT entry to disk */ | ||
1722 | bat_offset = s->bat_offset + (4 * index); | ||
1723 | bat_value = cpu_to_be32(s->pagetable[index]); | ||
1724 | - ret = bdrv_pwrite_sync(bs->file, bat_offset, &bat_value, 4); | ||
1725 | + ret = bdrv_pwrite_sync(bs->file, bat_offset, &bat_value, 4, 0); | ||
1726 | if (ret < 0) | ||
1727 | goto fail; | ||
1728 | |||
1729 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
1730 | index XXXXXXX..XXXXXXX 100644 | ||
1731 | --- a/block/vvfat.c | ||
1732 | +++ b/block/vvfat.c | ||
1733 | @@ -XXX,XX +XXX,XX @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, | ||
1734 | " allocated\n", sector_num, | ||
1735 | n >> BDRV_SECTOR_BITS)); | ||
1736 | if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, | ||
1737 | - buf + i * 0x200, n) < 0) { | ||
1738 | + buf + i * 0x200, n, 0) < 0) { | ||
1739 | return -1; | ||
1740 | } | ||
1741 | i += (n >> BDRV_SECTOR_BITS) - 1; | ||
1742 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, | ||
1743 | return -1; | ||
1744 | } | ||
1745 | res = bdrv_pwrite(s->qcow, offset * BDRV_SECTOR_SIZE, | ||
1746 | - s->cluster_buffer, BDRV_SECTOR_SIZE); | ||
1747 | + s->cluster_buffer, BDRV_SECTOR_SIZE, | ||
1748 | + 0); | ||
1749 | if (res < 0) { | ||
1750 | return -2; | ||
1751 | } | ||
1752 | @@ -XXX,XX +XXX,XX @@ DLOG(checkpoint()); | ||
1753 | */ | ||
1754 | DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors)); | ||
1755 | ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, buf, | ||
1756 | - nb_sectors * BDRV_SECTOR_SIZE); | ||
1757 | + nb_sectors * BDRV_SECTOR_SIZE, 0); | ||
1758 | if (ret < 0) { | ||
1759 | fprintf(stderr, "Error writing to qcow backend\n"); | ||
1760 | return ret; | ||
1761 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
1762 | index XXXXXXX..XXXXXXX 100644 | ||
1763 | --- a/tests/unit/test-block-iothread.c | ||
1764 | +++ b/tests/unit/test-block-iothread.c | ||
1765 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pread(BdrvChild *c) | ||
1766 | int ret; | ||
1767 | |||
1768 | /* Success */ | ||
1769 | - ret = bdrv_pread(c, 0, buf, sizeof(buf)); | ||
1770 | + ret = bdrv_pread(c, 0, buf, sizeof(buf), 0); | ||
1771 | g_assert_cmpint(ret, ==, 512); | ||
1772 | |||
1773 | /* Early error: Negative offset */ | ||
1774 | - ret = bdrv_pread(c, -2, buf, sizeof(buf)); | ||
1775 | + ret = bdrv_pread(c, -2, buf, sizeof(buf), 0); | ||
1776 | g_assert_cmpint(ret, ==, -EIO); | ||
1777 | } | ||
1778 | |||
1779 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pwrite(BdrvChild *c) | ||
1780 | int ret; | ||
1781 | |||
1782 | /* Success */ | ||
1783 | - ret = bdrv_pwrite(c, 0, buf, sizeof(buf)); | ||
1784 | + ret = bdrv_pwrite(c, 0, buf, sizeof(buf), 0); | ||
1785 | g_assert_cmpint(ret, ==, 512); | ||
1786 | |||
1787 | /* Early error: Negative offset */ | ||
1788 | - ret = bdrv_pwrite(c, -2, buf, sizeof(buf)); | ||
1789 | + ret = bdrv_pwrite(c, -2, buf, sizeof(buf), 0); | ||
1790 | g_assert_cmpint(ret, ==, -EIO); | ||
1791 | } | ||
1792 | |||
1793 | -- | ||
1794 | 2.35.3 | diff view generated by jsdifflib |
1 | Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1) | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | * cluster_size + 512 bytes upfront. Allocate s->cluster_cache and | ||
3 | s->cluster_data when the first read operation is performance on a | ||
4 | compressed cluster. | ||
5 | 2 | ||
6 | The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any | 3 | Swap 'buf' and 'bytes' around for consistency with |
7 | code paths that can allocate these buffers, so remove the free functions | 4 | bdrv_co_{pread,pwrite}(), and in preparation to implement these |
8 | in the error code path. | 5 | functions using generated_co_wrapper. |
9 | 6 | ||
10 | This patch can result in significant memory savings when many qcow2 | 7 | Callers were updated using this Coccinelle script: |
11 | disks are attached or backing file chains are long: | ||
12 | 8 | ||
13 | Before 12.81% (1,023,193,088B) | 9 | @@ expression child, offset, buf, bytes, flags; @@ |
14 | After 5.36% (393,893,888B) | 10 | - bdrv_pread(child, offset, buf, bytes, flags) |
11 | + bdrv_pread(child, offset, bytes, buf, flags) | ||
15 | 12 | ||
16 | Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru> | 13 | @@ expression child, offset, buf, bytes, flags; @@ |
17 | Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> | 14 | - bdrv_pwrite(child, offset, buf, bytes, flags) |
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | 15 | + bdrv_pwrite(child, offset, bytes, buf, flags) |
19 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 16 | |
20 | Message-id: 20170821135530.32344-1-stefanha@redhat.com | 17 | @@ expression child, offset, buf, bytes, flags; @@ |
21 | Cc: Kevin Wolf <kwolf@redhat.com> | 18 | - bdrv_pwrite_sync(child, offset, buf, bytes, flags) |
22 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 19 | + bdrv_pwrite_sync(child, offset, bytes, buf, flags) |
20 | |||
21 | Resulting overly-long lines were then fixed by hand. | ||
22 | |||
23 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
24 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
25 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
26 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> | ||
27 | Message-Id: <20220609152744.3891847-3-afaria@redhat.com> | ||
28 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
29 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
23 | --- | 30 | --- |
24 | block/qcow2-cluster.c | 17 +++++++++++++++++ | 31 | include/block/block-io.h | 10 +++--- |
25 | block/qcow2.c | 12 ------------ | 32 | block/blklogwrites.c | 6 ++-- |
26 | 2 files changed, 17 insertions(+), 12 deletions(-) | 33 | block/bochs.c | 10 +++--- |
34 | block/cloop.c | 10 +++--- | ||
35 | block/crypto.c | 4 +-- | ||
36 | block/dmg.c | 26 +++++++-------- | ||
37 | block/io.c | 12 +++---- | ||
38 | block/parallels-ext.c | 6 ++-- | ||
39 | block/parallels.c | 10 +++--- | ||
40 | block/qcow.c | 34 +++++++++---------- | ||
41 | block/qcow2-bitmap.c | 14 ++++---- | ||
42 | block/qcow2-cache.c | 8 ++--- | ||
43 | block/qcow2-cluster.c | 22 ++++++------- | ||
44 | block/qcow2-refcount.c | 56 +++++++++++++++++--------------- | ||
45 | block/qcow2-snapshot.c | 48 +++++++++++++-------------- | ||
46 | block/qcow2.c | 47 ++++++++++++++------------- | ||
47 | block/qed.c | 8 ++--- | ||
48 | block/vdi.c | 14 ++++---- | ||
49 | block/vhdx-log.c | 18 +++++----- | ||
50 | block/vhdx.c | 28 ++++++++-------- | ||
51 | block/vmdk.c | 50 ++++++++++++++-------------- | ||
52 | block/vpc.c | 22 ++++++------- | ||
53 | block/vvfat.c | 10 +++--- | ||
54 | tests/unit/test-block-iothread.c | 8 ++--- | ||
55 | 24 files changed, 242 insertions(+), 239 deletions(-) | ||
27 | 56 | ||
57 | diff --git a/include/block/block-io.h b/include/block/block-io.h | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/include/block/block-io.h | ||
60 | +++ b/include/block/block-io.h | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, | ||
63 | int64_t bytes, BdrvRequestFlags flags); | ||
64 | int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); | ||
65 | -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, | ||
66 | +int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, | ||
67 | BdrvRequestFlags flags); | ||
68 | -int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
69 | - int64_t bytes, BdrvRequestFlags flags); | ||
70 | -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, | ||
71 | - const void *buf, int64_t bytes, BdrvRequestFlags flags); | ||
72 | +int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, | ||
73 | + const void *buf, BdrvRequestFlags flags); | ||
74 | +int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, | ||
75 | + const void *buf, BdrvRequestFlags flags); | ||
76 | /* | ||
77 | * Efficiently zero a region of the disk image. Note that this is a regular | ||
78 | * I/O request like read or write and should have a reasonable size. This | ||
79 | diff --git a/block/blklogwrites.c b/block/blklogwrites.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/block/blklogwrites.c | ||
82 | +++ b/block/blklogwrites.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log, | ||
84 | struct log_write_entry cur_entry; | ||
85 | |||
86 | while (cur_idx < nr_entries) { | ||
87 | - int read_ret = bdrv_pread(log, cur_sector << sector_bits, &cur_entry, | ||
88 | - sizeof(cur_entry), 0); | ||
89 | + int read_ret = bdrv_pread(log, cur_sector << sector_bits, | ||
90 | + sizeof(cur_entry), &cur_entry, 0); | ||
91 | if (read_ret < 0) { | ||
92 | error_setg_errno(errp, -read_ret, | ||
93 | "Failed to read log entry %"PRIu64, cur_idx); | ||
94 | @@ -XXX,XX +XXX,XX @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags, | ||
95 | log_sb.nr_entries = cpu_to_le64(0); | ||
96 | log_sb.sectorsize = cpu_to_le32(BDRV_SECTOR_SIZE); | ||
97 | } else { | ||
98 | - ret = bdrv_pread(s->log_file, 0, &log_sb, sizeof(log_sb), 0); | ||
99 | + ret = bdrv_pread(s->log_file, 0, sizeof(log_sb), &log_sb, 0); | ||
100 | if (ret < 0) { | ||
101 | error_setg_errno(errp, -ret, "Could not read log superblock"); | ||
102 | goto fail_log; | ||
103 | diff --git a/block/bochs.c b/block/bochs.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/block/bochs.c | ||
106 | +++ b/block/bochs.c | ||
107 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
108 | return -EINVAL; | ||
109 | } | ||
110 | |||
111 | - ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs), 0); | ||
112 | + ret = bdrv_pread(bs->file, 0, sizeof(bochs), &bochs, 0); | ||
113 | if (ret < 0) { | ||
114 | return ret; | ||
115 | } | ||
116 | @@ -XXX,XX +XXX,XX @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, | ||
117 | return -ENOMEM; | ||
118 | } | ||
119 | |||
120 | - ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, | ||
121 | - s->catalog_size * 4, 0); | ||
122 | + ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_size * 4, | ||
123 | + s->catalog_bitmap, 0); | ||
124 | if (ret < 0) { | ||
125 | goto fail; | ||
126 | } | ||
127 | @@ -XXX,XX +XXX,XX @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num) | ||
128 | (s->extent_blocks + s->bitmap_blocks)); | ||
129 | |||
130 | /* read in bitmap for current extent */ | ||
131 | - ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), | ||
132 | - &bitmap_entry, 1, 0); | ||
133 | + ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), 1, | ||
134 | + &bitmap_entry, 0); | ||
135 | if (ret < 0) { | ||
136 | return ret; | ||
137 | } | ||
138 | diff --git a/block/cloop.c b/block/cloop.c | ||
139 | index XXXXXXX..XXXXXXX 100644 | ||
140 | --- a/block/cloop.c | ||
141 | +++ b/block/cloop.c | ||
142 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
143 | } | ||
144 | |||
145 | /* read header */ | ||
146 | - ret = bdrv_pread(bs->file, 128, &s->block_size, 4, 0); | ||
147 | + ret = bdrv_pread(bs->file, 128, 4, &s->block_size, 0); | ||
148 | if (ret < 0) { | ||
149 | return ret; | ||
150 | } | ||
151 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
152 | return -EINVAL; | ||
153 | } | ||
154 | |||
155 | - ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4, 0); | ||
156 | + ret = bdrv_pread(bs->file, 128 + 4, 4, &s->n_blocks, 0); | ||
157 | if (ret < 0) { | ||
158 | return ret; | ||
159 | } | ||
160 | @@ -XXX,XX +XXX,XX @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, | ||
161 | return -ENOMEM; | ||
162 | } | ||
163 | |||
164 | - ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size, 0); | ||
165 | + ret = bdrv_pread(bs->file, 128 + 4 + 4, offsets_size, s->offsets, 0); | ||
166 | if (ret < 0) { | ||
167 | goto fail; | ||
168 | } | ||
169 | @@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num) | ||
170 | int ret; | ||
171 | uint32_t bytes = s->offsets[block_num + 1] - s->offsets[block_num]; | ||
172 | |||
173 | - ret = bdrv_pread(bs->file, s->offsets[block_num], s->compressed_block, | ||
174 | - bytes, 0); | ||
175 | + ret = bdrv_pread(bs->file, s->offsets[block_num], bytes, | ||
176 | + s->compressed_block, 0); | ||
177 | if (ret != bytes) { | ||
178 | return -1; | ||
179 | } | ||
180 | diff --git a/block/crypto.c b/block/crypto.c | ||
181 | index XXXXXXX..XXXXXXX 100644 | ||
182 | --- a/block/crypto.c | ||
183 | +++ b/block/crypto.c | ||
184 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, | ||
185 | BlockDriverState *bs = opaque; | ||
186 | ssize_t ret; | ||
187 | |||
188 | - ret = bdrv_pread(bs->file, offset, buf, buflen, 0); | ||
189 | + ret = bdrv_pread(bs->file, offset, buflen, buf, 0); | ||
190 | if (ret < 0) { | ||
191 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
192 | return ret; | ||
193 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
194 | BlockDriverState *bs = opaque; | ||
195 | ssize_t ret; | ||
196 | |||
197 | - ret = bdrv_pwrite(bs->file, offset, buf, buflen, 0); | ||
198 | + ret = bdrv_pwrite(bs->file, offset, buflen, buf, 0); | ||
199 | if (ret < 0) { | ||
200 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
201 | return ret; | ||
202 | diff --git a/block/dmg.c b/block/dmg.c | ||
203 | index XXXXXXX..XXXXXXX 100644 | ||
204 | --- a/block/dmg.c | ||
205 | +++ b/block/dmg.c | ||
206 | @@ -XXX,XX +XXX,XX @@ static int read_uint64(BlockDriverState *bs, int64_t offset, uint64_t *result) | ||
207 | uint64_t buffer; | ||
208 | int ret; | ||
209 | |||
210 | - ret = bdrv_pread(bs->file, offset, &buffer, 8, 0); | ||
211 | + ret = bdrv_pread(bs->file, offset, 8, &buffer, 0); | ||
212 | if (ret < 0) { | ||
213 | return ret; | ||
214 | } | ||
215 | @@ -XXX,XX +XXX,XX @@ static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result) | ||
216 | uint32_t buffer; | ||
217 | int ret; | ||
218 | |||
219 | - ret = bdrv_pread(bs->file, offset, &buffer, 4, 0); | ||
220 | + ret = bdrv_pread(bs->file, offset, 4, &buffer, 0); | ||
221 | if (ret < 0) { | ||
222 | return ret; | ||
223 | } | ||
224 | @@ -XXX,XX +XXX,XX @@ static int64_t dmg_find_koly_offset(BdrvChild *file, Error **errp) | ||
225 | offset = length - 511 - 512; | ||
226 | } | ||
227 | length = length < 515 ? length : 515; | ||
228 | - ret = bdrv_pread(file, offset, buffer, length, 0); | ||
229 | + ret = bdrv_pread(file, offset, length, buffer, 0); | ||
230 | if (ret < 0) { | ||
231 | error_setg_errno(errp, -ret, "Failed while reading UDIF trailer"); | ||
232 | return ret; | ||
233 | @@ -XXX,XX +XXX,XX @@ static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds, | ||
234 | offset += 4; | ||
235 | |||
236 | buffer = g_realloc(buffer, count); | ||
237 | - ret = bdrv_pread(bs->file, offset, buffer, count, 0); | ||
238 | + ret = bdrv_pread(bs->file, offset, count, buffer, 0); | ||
239 | if (ret < 0) { | ||
240 | goto fail; | ||
241 | } | ||
242 | @@ -XXX,XX +XXX,XX @@ static int dmg_read_plist_xml(BlockDriverState *bs, DmgHeaderState *ds, | ||
243 | |||
244 | buffer = g_malloc(info_length + 1); | ||
245 | buffer[info_length] = '\0'; | ||
246 | - ret = bdrv_pread(bs->file, info_begin, buffer, info_length, 0); | ||
247 | + ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0); | ||
248 | if (ret != info_length) { | ||
249 | ret = -EINVAL; | ||
250 | goto fail; | ||
251 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
252 | case UDZO: { /* zlib compressed */ | ||
253 | /* we need to buffer, because only the chunk as whole can be | ||
254 | * inflated. */ | ||
255 | - ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
256 | - s->lengths[chunk], 0); | ||
257 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
258 | + s->compressed_chunk, 0); | ||
259 | if (ret != s->lengths[chunk]) { | ||
260 | return -1; | ||
261 | } | ||
262 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
263 | } | ||
264 | /* we need to buffer, because only the chunk as whole can be | ||
265 | * inflated. */ | ||
266 | - ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
267 | - s->lengths[chunk], 0); | ||
268 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
269 | + s->compressed_chunk, 0); | ||
270 | if (ret != s->lengths[chunk]) { | ||
271 | return -1; | ||
272 | } | ||
273 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
274 | } | ||
275 | /* we need to buffer, because only the chunk as whole can be | ||
276 | * inflated. */ | ||
277 | - ret = bdrv_pread(bs->file, s->offsets[chunk], s->compressed_chunk, | ||
278 | - s->lengths[chunk], 0); | ||
279 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
280 | + s->compressed_chunk, 0); | ||
281 | if (ret != s->lengths[chunk]) { | ||
282 | return -1; | ||
283 | } | ||
284 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
285 | } | ||
286 | break; | ||
287 | case UDRW: /* copy */ | ||
288 | - ret = bdrv_pread(bs->file, s->offsets[chunk], | ||
289 | - s->uncompressed_chunk, s->lengths[chunk], 0); | ||
290 | + ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
291 | + s->uncompressed_chunk, 0); | ||
292 | if (ret != s->lengths[chunk]) { | ||
293 | return -1; | ||
294 | } | ||
295 | diff --git a/block/io.c b/block/io.c | ||
296 | index XXXXXXX..XXXXXXX 100644 | ||
297 | --- a/block/io.c | ||
298 | +++ b/block/io.c | ||
299 | @@ -XXX,XX +XXX,XX @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) | ||
300 | } | ||
301 | |||
302 | /* See bdrv_pwrite() for the return codes */ | ||
303 | -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, | ||
304 | +int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, | ||
305 | BdrvRequestFlags flags) | ||
306 | { | ||
307 | int ret; | ||
308 | @@ -XXX,XX +XXX,XX @@ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, | ||
309 | -EINVAL Invalid offset or number of bytes | ||
310 | -EACCES Trying to write a read-only device | ||
311 | */ | ||
312 | -int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
313 | - int64_t bytes, BdrvRequestFlags flags) | ||
314 | +int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, | ||
315 | + const void *buf, BdrvRequestFlags flags) | ||
316 | { | ||
317 | int ret; | ||
318 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
319 | @@ -XXX,XX +XXX,XX @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, | ||
320 | * | ||
321 | * Returns 0 on success, -errno in error cases. | ||
322 | */ | ||
323 | -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, | ||
324 | - const void *buf, int64_t count, BdrvRequestFlags flags) | ||
325 | +int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, | ||
326 | + const void *buf, BdrvRequestFlags flags) | ||
327 | { | ||
328 | int ret; | ||
329 | IO_CODE(); | ||
330 | |||
331 | - ret = bdrv_pwrite(child, offset, buf, count, flags); | ||
332 | + ret = bdrv_pwrite(child, offset, bytes, buf, flags); | ||
333 | if (ret < 0) { | ||
334 | return ret; | ||
335 | } | ||
336 | diff --git a/block/parallels-ext.c b/block/parallels-ext.c | ||
337 | index XXXXXXX..XXXXXXX 100644 | ||
338 | --- a/block/parallels-ext.c | ||
339 | +++ b/block/parallels-ext.c | ||
340 | @@ -XXX,XX +XXX,XX @@ static int parallels_load_bitmap_data(BlockDriverState *bs, | ||
341 | if (entry == 1) { | ||
342 | bdrv_dirty_bitmap_deserialize_ones(bitmap, offset, count, false); | ||
343 | } else { | ||
344 | - ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS, buf, | ||
345 | - s->cluster_size, 0); | ||
346 | + ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS, | ||
347 | + s->cluster_size, buf, 0); | ||
348 | if (ret < 0) { | ||
349 | error_setg_errno(errp, -ret, | ||
350 | "Failed to read bitmap data cluster"); | ||
351 | @@ -XXX,XX +XXX,XX @@ int parallels_read_format_extension(BlockDriverState *bs, | ||
352 | |||
353 | assert(ext_off > 0); | ||
354 | |||
355 | - ret = bdrv_pread(bs->file, ext_off, ext_cluster, s->cluster_size, 0); | ||
356 | + ret = bdrv_pread(bs->file, ext_off, s->cluster_size, ext_cluster, 0); | ||
357 | if (ret < 0) { | ||
358 | error_setg_errno(errp, -ret, "Failed to read Format Extension cluster"); | ||
359 | goto out; | ||
360 | diff --git a/block/parallels.c b/block/parallels.c | ||
361 | index XXXXXXX..XXXXXXX 100644 | ||
362 | --- a/block/parallels.c | ||
363 | +++ b/block/parallels.c | ||
364 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) | ||
365 | if (off + to_write > s->header_size) { | ||
366 | to_write = s->header_size - off; | ||
367 | } | ||
368 | - ret = bdrv_pwrite(bs->file, off, (uint8_t *)s->header + off, to_write, | ||
369 | + ret = bdrv_pwrite(bs->file, off, to_write, (uint8_t *)s->header + off, | ||
370 | 0); | ||
371 | if (ret < 0) { | ||
372 | qemu_co_mutex_unlock(&s->lock); | ||
373 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, | ||
374 | |||
375 | ret = 0; | ||
376 | if (flush_bat) { | ||
377 | - ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size, 0); | ||
378 | + ret = bdrv_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); | ||
379 | if (ret < 0) { | ||
380 | res->check_errors++; | ||
381 | goto out; | ||
382 | @@ -XXX,XX +XXX,XX @@ static int parallels_update_header(BlockDriverState *bs) | ||
383 | if (size > s->header_size) { | ||
384 | size = s->header_size; | ||
385 | } | ||
386 | - return bdrv_pwrite_sync(bs->file, 0, s->header, size, 0); | ||
387 | + return bdrv_pwrite_sync(bs->file, 0, size, s->header, 0); | ||
388 | } | ||
389 | |||
390 | static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
391 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
392 | return -EINVAL; | ||
393 | } | ||
394 | |||
395 | - ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph), 0); | ||
396 | + ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0); | ||
397 | if (ret < 0) { | ||
398 | goto fail; | ||
399 | } | ||
400 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | ||
401 | s->header_size = size; | ||
402 | } | ||
403 | |||
404 | - ret = bdrv_pread(bs->file, 0, s->header, s->header_size, 0); | ||
405 | + ret = bdrv_pread(bs->file, 0, s->header_size, s->header, 0); | ||
406 | if (ret < 0) { | ||
407 | goto fail; | ||
408 | } | ||
409 | diff --git a/block/qcow.c b/block/qcow.c | ||
410 | index XXXXXXX..XXXXXXX 100644 | ||
411 | --- a/block/qcow.c | ||
412 | +++ b/block/qcow.c | ||
413 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
414 | goto fail; | ||
415 | } | ||
416 | |||
417 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
418 | + ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0); | ||
419 | if (ret < 0) { | ||
420 | goto fail; | ||
421 | } | ||
422 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
423 | goto fail; | ||
424 | } | ||
425 | |||
426 | - ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, | ||
427 | - s->l1_size * sizeof(uint64_t), 0); | ||
428 | + ret = bdrv_pread(bs->file, s->l1_table_offset, | ||
429 | + s->l1_size * sizeof(uint64_t), s->l1_table, 0); | ||
430 | if (ret < 0) { | ||
431 | goto fail; | ||
432 | } | ||
433 | @@ -XXX,XX +XXX,XX @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags, | ||
434 | ret = -EINVAL; | ||
435 | goto fail; | ||
436 | } | ||
437 | - ret = bdrv_pread(bs->file, header.backing_file_offset, | ||
438 | - bs->auto_backing_file, len, 0); | ||
439 | + ret = bdrv_pread(bs->file, header.backing_file_offset, len, | ||
440 | + bs->auto_backing_file, 0); | ||
441 | if (ret < 0) { | ||
442 | goto fail; | ||
443 | } | ||
444 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
445 | BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); | ||
446 | ret = bdrv_pwrite_sync(bs->file, | ||
447 | s->l1_table_offset + l1_index * sizeof(tmp), | ||
448 | - &tmp, sizeof(tmp), 0); | ||
449 | + sizeof(tmp), &tmp, 0); | ||
450 | if (ret < 0) { | ||
451 | return ret; | ||
452 | } | ||
453 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
454 | BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD); | ||
455 | if (new_l2_table) { | ||
456 | memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); | ||
457 | - ret = bdrv_pwrite_sync(bs->file, l2_offset, l2_table, | ||
458 | - s->l2_size * sizeof(uint64_t), 0); | ||
459 | + ret = bdrv_pwrite_sync(bs->file, l2_offset, | ||
460 | + s->l2_size * sizeof(uint64_t), l2_table, 0); | ||
461 | if (ret < 0) { | ||
462 | return ret; | ||
463 | } | ||
464 | } else { | ||
465 | - ret = bdrv_pread(bs->file, l2_offset, l2_table, | ||
466 | - s->l2_size * sizeof(uint64_t), 0); | ||
467 | + ret = bdrv_pread(bs->file, l2_offset, s->l2_size * sizeof(uint64_t), | ||
468 | + l2_table, 0); | ||
469 | if (ret < 0) { | ||
470 | return ret; | ||
471 | } | ||
472 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
473 | cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size); | ||
474 | /* write the cluster content */ | ||
475 | BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); | ||
476 | - ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, | ||
477 | - s->cluster_size, 0); | ||
478 | + ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_size, | ||
479 | + s->cluster_cache, 0); | ||
480 | if (ret < 0) { | ||
481 | return ret; | ||
482 | } | ||
483 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
484 | } | ||
485 | BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); | ||
486 | ret = bdrv_pwrite(bs->file, cluster_offset + i, | ||
487 | - s->cluster_data, | ||
488 | - BDRV_SECTOR_SIZE, 0); | ||
489 | + BDRV_SECTOR_SIZE, | ||
490 | + s->cluster_data, 0); | ||
491 | if (ret < 0) { | ||
492 | return ret; | ||
493 | } | ||
494 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
495 | BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE); | ||
496 | } | ||
497 | ret = bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp), | ||
498 | - &tmp, sizeof(tmp), 0); | ||
499 | + sizeof(tmp), &tmp, 0); | ||
500 | if (ret < 0) { | ||
501 | return ret; | ||
502 | } | ||
503 | @@ -XXX,XX +XXX,XX @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) | ||
504 | csize = cluster_offset >> (63 - s->cluster_bits); | ||
505 | csize &= (s->cluster_size - 1); | ||
506 | BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); | ||
507 | - ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize, 0); | ||
508 | + ret = bdrv_pread(bs->file, coffset, csize, s->cluster_data, 0); | ||
509 | if (ret != csize) | ||
510 | return -1; | ||
511 | if (decompress_buffer(s->cluster_cache, s->cluster_size, | ||
512 | @@ -XXX,XX +XXX,XX @@ static int qcow_make_empty(BlockDriverState *bs) | ||
513 | int ret; | ||
514 | |||
515 | memset(s->l1_table, 0, l1_length); | ||
516 | - if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, l1_length, | ||
517 | + if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, l1_length, s->l1_table, | ||
518 | 0) < 0) | ||
519 | return -1; | ||
520 | ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, false, | ||
521 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
522 | index XXXXXXX..XXXXXXX 100644 | ||
523 | --- a/block/qcow2-bitmap.c | ||
524 | +++ b/block/qcow2-bitmap.c | ||
525 | @@ -XXX,XX +XXX,XX @@ static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb, | ||
526 | } | ||
527 | |||
528 | assert(tb->size <= BME_MAX_TABLE_SIZE); | ||
529 | - ret = bdrv_pread(bs->file, tb->offset, table, | ||
530 | - tb->size * BME_TABLE_ENTRY_SIZE, 0); | ||
531 | + ret = bdrv_pread(bs->file, tb->offset, tb->size * BME_TABLE_ENTRY_SIZE, | ||
532 | + table, 0); | ||
533 | if (ret < 0) { | ||
534 | goto fail; | ||
535 | } | ||
536 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
537 | * already cleared */ | ||
538 | } | ||
539 | } else { | ||
540 | - ret = bdrv_pread(bs->file, data_offset, buf, s->cluster_size, 0); | ||
541 | + ret = bdrv_pread(bs->file, data_offset, s->cluster_size, buf, 0); | ||
542 | if (ret < 0) { | ||
543 | goto finish; | ||
544 | } | ||
545 | @@ -XXX,XX +XXX,XX @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset, | ||
546 | } | ||
547 | dir_end = dir + size; | ||
548 | |||
549 | - ret = bdrv_pread(bs->file, offset, dir, size, 0); | ||
550 | + ret = bdrv_pread(bs->file, offset, size, dir, 0); | ||
551 | if (ret < 0) { | ||
552 | error_setg_errno(errp, -ret, "Failed to read bitmap directory"); | ||
553 | goto fail; | ||
554 | @@ -XXX,XX +XXX,XX @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list, | ||
555 | goto fail; | ||
556 | } | ||
557 | |||
558 | - ret = bdrv_pwrite(bs->file, dir_offset, dir, dir_size, 0); | ||
559 | + ret = bdrv_pwrite(bs->file, dir_offset, dir_size, dir, 0); | ||
560 | if (ret < 0) { | ||
561 | goto fail; | ||
562 | } | ||
563 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
564 | goto fail; | ||
565 | } | ||
566 | |||
567 | - ret = bdrv_pwrite(bs->file, off, buf, s->cluster_size, 0); | ||
568 | + ret = bdrv_pwrite(bs->file, off, s->cluster_size, buf, 0); | ||
569 | if (ret < 0) { | ||
570 | error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file", | ||
571 | bm_name); | ||
572 | @@ -XXX,XX +XXX,XX @@ static int store_bitmap(BlockDriverState *bs, Qcow2Bitmap *bm, Error **errp) | ||
573 | } | ||
574 | |||
575 | bitmap_table_to_be(tb, tb_size); | ||
576 | - ret = bdrv_pwrite(bs->file, tb_offset, tb, tb_size * sizeof(tb[0]), 0); | ||
577 | + ret = bdrv_pwrite(bs->file, tb_offset, tb_size * sizeof(tb[0]), tb, 0); | ||
578 | if (ret < 0) { | ||
579 | error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file", | ||
580 | bm_name); | ||
581 | diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c | ||
582 | index XXXXXXX..XXXXXXX 100644 | ||
583 | --- a/block/qcow2-cache.c | ||
584 | +++ b/block/qcow2-cache.c | ||
585 | @@ -XXX,XX +XXX,XX @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i) | ||
586 | BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE); | ||
587 | } | ||
588 | |||
589 | - ret = bdrv_pwrite(bs->file, c->entries[i].offset, | ||
590 | - qcow2_cache_get_table_addr(c, i), c->table_size, 0); | ||
591 | + ret = bdrv_pwrite(bs->file, c->entries[i].offset, c->table_size, | ||
592 | + qcow2_cache_get_table_addr(c, i), 0); | ||
593 | if (ret < 0) { | ||
594 | return ret; | ||
595 | } | ||
596 | @@ -XXX,XX +XXX,XX @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c, | ||
597 | BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD); | ||
598 | } | ||
599 | |||
600 | - ret = bdrv_pread(bs->file, offset, qcow2_cache_get_table_addr(c, i), | ||
601 | - c->table_size, 0); | ||
602 | + ret = bdrv_pread(bs->file, offset, c->table_size, | ||
603 | + qcow2_cache_get_table_addr(c, i), 0); | ||
604 | if (ret < 0) { | ||
605 | return ret; | ||
606 | } | ||
28 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | 607 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c |
29 | index XXXXXXX..XXXXXXX 100644 | 608 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/block/qcow2-cluster.c | 609 | --- a/block/qcow2-cluster.c |
31 | +++ b/block/qcow2-cluster.c | 610 | +++ b/block/qcow2-cluster.c |
32 | @@ -XXX,XX +XXX,XX @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) | 611 | @@ -XXX,XX +XXX,XX @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, |
33 | nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; | 612 | BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE); |
34 | sector_offset = coffset & 511; | 613 | for(i = 0; i < s->l1_size; i++) |
35 | csize = nb_csectors * 512 - sector_offset; | 614 | new_l1_table[i] = cpu_to_be64(new_l1_table[i]); |
36 | + | 615 | - ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, new_l1_table, |
37 | + /* Allocate buffers on first decompress operation, most images are | 616 | - new_l1_size2, 0); |
38 | + * uncompressed and the memory overhead can be avoided. The buffers | 617 | + ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, new_l1_size2, |
39 | + * are freed in .bdrv_close(). | 618 | + new_l1_table, 0); |
40 | + */ | 619 | if (ret < 0) |
41 | + if (!s->cluster_data) { | 620 | goto fail; |
42 | + /* one more sector for decompressed data alignment */ | 621 | for(i = 0; i < s->l1_size; i++) |
43 | + s->cluster_data = qemu_try_blockalign(bs->file->bs, | 622 | @@ -XXX,XX +XXX,XX @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, |
44 | + QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); | 623 | BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE); |
45 | + if (!s->cluster_data) { | 624 | stl_be_p(data, new_l1_size); |
46 | + return -ENOMEM; | 625 | stq_be_p(data + 4, new_l1_table_offset); |
47 | + } | 626 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), data, |
48 | + } | 627 | - sizeof(data), 0); |
49 | + if (!s->cluster_cache) { | 628 | + ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), |
50 | + s->cluster_cache = g_malloc(s->cluster_size); | 629 | + sizeof(data), data, 0); |
51 | + } | 630 | if (ret < 0) { |
52 | + | 631 | goto fail; |
53 | BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); | 632 | } |
54 | ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data, | 633 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index) |
55 | nb_csectors); | 634 | BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); |
635 | ret = bdrv_pwrite_sync(bs->file, | ||
636 | s->l1_table_offset + L1E_SIZE * l1_start_index, | ||
637 | - buf, bufsize, 0); | ||
638 | + bufsize, buf, 0); | ||
639 | if (ret < 0) { | ||
640 | return ret; | ||
641 | } | ||
642 | @@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, | ||
643 | (void **)&l2_slice); | ||
644 | } else { | ||
645 | /* load inactive L2 tables from disk */ | ||
646 | - ret = bdrv_pread(bs->file, slice_offset, l2_slice, | ||
647 | - slice_size2, 0); | ||
648 | + ret = bdrv_pread(bs->file, slice_offset, slice_size2, | ||
649 | + l2_slice, 0); | ||
650 | } | ||
651 | if (ret < 0) { | ||
652 | goto fail; | ||
653 | @@ -XXX,XX +XXX,XX @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table, | ||
654 | goto fail; | ||
655 | } | ||
656 | |||
657 | - ret = bdrv_pwrite(bs->file, slice_offset, l2_slice, | ||
658 | - slice_size2, 0); | ||
659 | + ret = bdrv_pwrite(bs->file, slice_offset, slice_size2, | ||
660 | + l2_slice, 0); | ||
661 | if (ret < 0) { | ||
662 | goto fail; | ||
663 | } | ||
664 | @@ -XXX,XX +XXX,XX @@ int qcow2_expand_zero_clusters(BlockDriverState *bs, | ||
665 | |||
666 | l1_table = new_l1_table; | ||
667 | |||
668 | - ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset, l1_table, | ||
669 | - l1_size2, 0); | ||
670 | + ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset, l1_size2, | ||
671 | + l1_table, 0); | ||
672 | if (ret < 0) { | ||
673 | goto fail; | ||
674 | } | ||
675 | diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c | ||
676 | index XXXXXXX..XXXXXXX 100644 | ||
677 | --- a/block/qcow2-refcount.c | ||
678 | +++ b/block/qcow2-refcount.c | ||
679 | @@ -XXX,XX +XXX,XX @@ int qcow2_refcount_init(BlockDriverState *bs) | ||
680 | } | ||
681 | BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD); | ||
682 | ret = bdrv_pread(bs->file, s->refcount_table_offset, | ||
683 | - s->refcount_table, refcount_table_size2, 0); | ||
684 | + refcount_table_size2, s->refcount_table, 0); | ||
685 | if (ret < 0) { | ||
686 | goto fail; | ||
687 | } | ||
688 | @@ -XXX,XX +XXX,XX @@ static int alloc_refcount_block(BlockDriverState *bs, | ||
689 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP); | ||
690 | ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset + | ||
691 | refcount_table_index * REFTABLE_ENTRY_SIZE, | ||
692 | - &data64, sizeof(data64), 0); | ||
693 | + sizeof(data64), &data64, 0); | ||
694 | if (ret < 0) { | ||
695 | goto fail; | ||
696 | } | ||
697 | @@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset, | ||
698 | } | ||
699 | |||
700 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE); | ||
701 | - ret = bdrv_pwrite_sync(bs->file, table_offset, new_table, | ||
702 | - table_size * REFTABLE_ENTRY_SIZE, 0); | ||
703 | + ret = bdrv_pwrite_sync(bs->file, table_offset, | ||
704 | + table_size * REFTABLE_ENTRY_SIZE, new_table, 0); | ||
705 | if (ret < 0) { | ||
706 | goto fail; | ||
707 | } | ||
708 | @@ -XXX,XX +XXX,XX @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset, | ||
709 | data.d32 = cpu_to_be32(table_clusters); | ||
710 | BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE); | ||
711 | ret = bdrv_pwrite_sync(bs->file, | ||
712 | - offsetof(QCowHeader, refcount_table_offset), &data, | ||
713 | - sizeof(data), 0); | ||
714 | + offsetof(QCowHeader, refcount_table_offset), | ||
715 | + sizeof(data), &data, 0); | ||
716 | if (ret < 0) { | ||
717 | goto fail; | ||
718 | } | ||
719 | @@ -XXX,XX +XXX,XX @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, | ||
720 | } | ||
721 | l1_allocated = true; | ||
722 | |||
723 | - ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2, 0); | ||
724 | + ret = bdrv_pread(bs->file, l1_table_offset, l1_size2, l1_table, 0); | ||
725 | if (ret < 0) { | ||
726 | goto fail; | ||
727 | } | ||
728 | @@ -XXX,XX +XXX,XX @@ fail: | ||
729 | cpu_to_be64s(&l1_table[i]); | ||
730 | } | ||
731 | |||
732 | - ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_table, l1_size2, | ||
733 | + ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_size2, l1_table, | ||
734 | 0); | ||
735 | |||
736 | for (i = 0; i < l1_size; i++) { | ||
737 | @@ -XXX,XX +XXX,XX @@ static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res, | ||
738 | goto fail; | ||
739 | } | ||
740 | |||
741 | - ret = bdrv_pwrite_sync(bs->file, l2e_offset, &l2_table[idx], | ||
742 | - l2_entry_size(s), 0); | ||
743 | + ret = bdrv_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s), | ||
744 | + &l2_table[idx], 0); | ||
745 | if (ret < 0) { | ||
746 | fprintf(stderr, "ERROR: Failed to overwrite L2 " | ||
747 | "table entry: %s\n", strerror(-ret)); | ||
748 | @@ -XXX,XX +XXX,XX @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, | ||
749 | bool metadata_overlap; | ||
750 | |||
751 | /* Read L2 table from disk */ | ||
752 | - ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes, 0); | ||
753 | + ret = bdrv_pread(bs->file, l2_offset, l2_size_bytes, l2_table, 0); | ||
754 | if (ret < 0) { | ||
755 | fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n"); | ||
756 | res->check_errors++; | ||
757 | @@ -XXX,XX +XXX,XX @@ static int check_refcounts_l1(BlockDriverState *bs, | ||
758 | } | ||
759 | |||
760 | /* Read L1 table entries from disk */ | ||
761 | - ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes, 0); | ||
762 | + ret = bdrv_pread(bs->file, l1_table_offset, l1_size_bytes, l1_table, 0); | ||
763 | if (ret < 0) { | ||
764 | fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n"); | ||
765 | res->check_errors++; | ||
766 | @@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, | ||
767 | } | ||
768 | } | ||
769 | |||
770 | - ret = bdrv_pread(bs->file, l2_offset, l2_table, | ||
771 | - s->l2_size * l2_entry_size(s), 0); | ||
772 | + ret = bdrv_pread(bs->file, l2_offset, s->l2_size * l2_entry_size(s), | ||
773 | + l2_table, 0); | ||
774 | if (ret < 0) { | ||
775 | fprintf(stderr, "ERROR: Could not read L2 table: %s\n", | ||
776 | strerror(-ret)); | ||
777 | @@ -XXX,XX +XXX,XX @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res, | ||
778 | goto fail; | ||
779 | } | ||
780 | |||
781 | - ret = bdrv_pwrite(bs->file, l2_offset, l2_table, s->cluster_size, | ||
782 | + ret = bdrv_pwrite(bs->file, l2_offset, s->cluster_size, l2_table, | ||
783 | 0); | ||
784 | if (ret < 0) { | ||
785 | fprintf(stderr, "ERROR: Could not write L2 table: %s\n", | ||
786 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcounts_write_refblocks( | ||
787 | on_disk_refblock = (void *)((char *) *refcount_table + | ||
788 | refblock_index * s->cluster_size); | ||
789 | |||
790 | - ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock, | ||
791 | - s->cluster_size, 0); | ||
792 | + ret = bdrv_pwrite(bs->file, refblock_offset, s->cluster_size, | ||
793 | + on_disk_refblock, 0); | ||
794 | if (ret < 0) { | ||
795 | error_setg_errno(errp, -ret, "ERROR writing refblock"); | ||
796 | return ret; | ||
797 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs, | ||
798 | } | ||
799 | |||
800 | assert(reftable_length < INT_MAX); | ||
801 | - ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable, | ||
802 | - reftable_length, 0); | ||
803 | + ret = bdrv_pwrite(bs->file, reftable_offset, reftable_length, | ||
804 | + on_disk_reftable, 0); | ||
805 | if (ret < 0) { | ||
806 | error_setg_errno(errp, -ret, "ERROR writing reftable"); | ||
807 | goto fail; | ||
808 | @@ -XXX,XX +XXX,XX @@ static int rebuild_refcount_structure(BlockDriverState *bs, | ||
809 | cpu_to_be32(reftable_clusters); | ||
810 | ret = bdrv_pwrite_sync(bs->file, | ||
811 | offsetof(QCowHeader, refcount_table_offset), | ||
812 | - &reftable_offset_and_clusters, | ||
813 | - sizeof(reftable_offset_and_clusters), 0); | ||
814 | + sizeof(reftable_offset_and_clusters), | ||
815 | + &reftable_offset_and_clusters, 0); | ||
816 | if (ret < 0) { | ||
817 | error_setg_errno(errp, -ret, "ERROR setting reftable"); | ||
818 | goto fail; | ||
819 | @@ -XXX,XX +XXX,XX @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, | ||
820 | return -ENOMEM; | ||
821 | } | ||
822 | |||
823 | - ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2, 0); | ||
824 | + ret = bdrv_pread(bs->file, l1_ofs, l1_sz2, l1, 0); | ||
825 | if (ret < 0) { | ||
826 | g_free(l1); | ||
827 | return ret; | ||
828 | @@ -XXX,XX +XXX,XX @@ static int flush_refblock(BlockDriverState *bs, uint64_t **reftable, | ||
829 | return ret; | ||
830 | } | ||
831 | |||
832 | - ret = bdrv_pwrite(bs->file, offset, refblock, s->cluster_size, 0); | ||
833 | + ret = bdrv_pwrite(bs->file, offset, s->cluster_size, refblock, 0); | ||
834 | if (ret < 0) { | ||
835 | error_setg_errno(errp, -ret, "Failed to write refblock"); | ||
836 | return ret; | ||
837 | @@ -XXX,XX +XXX,XX @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, | ||
838 | cpu_to_be64s(&new_reftable[i]); | ||
839 | } | ||
840 | |||
841 | - ret = bdrv_pwrite(bs->file, new_reftable_offset, new_reftable, | ||
842 | - new_reftable_size * REFTABLE_ENTRY_SIZE, 0); | ||
843 | + ret = bdrv_pwrite(bs->file, new_reftable_offset, | ||
844 | + new_reftable_size * REFTABLE_ENTRY_SIZE, new_reftable, | ||
845 | + 0); | ||
846 | |||
847 | for (i = 0; i < new_reftable_size; i++) { | ||
848 | be64_to_cpus(&new_reftable[i]); | ||
849 | @@ -XXX,XX +XXX,XX @@ int qcow2_shrink_reftable(BlockDriverState *bs) | ||
850 | reftable_tmp[i] = unused_block ? 0 : cpu_to_be64(s->refcount_table[i]); | ||
851 | } | ||
852 | |||
853 | - ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset, reftable_tmp, | ||
854 | - s->refcount_table_size * REFTABLE_ENTRY_SIZE, 0); | ||
855 | + ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset, | ||
856 | + s->refcount_table_size * REFTABLE_ENTRY_SIZE, | ||
857 | + reftable_tmp, 0); | ||
858 | /* | ||
859 | * If the write in the reftable failed the image may contain a partially | ||
860 | * overwritten reftable. In this case it would be better to clear the | ||
861 | diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c | ||
862 | index XXXXXXX..XXXXXXX 100644 | ||
863 | --- a/block/qcow2-snapshot.c | ||
864 | +++ b/block/qcow2-snapshot.c | ||
865 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
866 | |||
867 | /* Read statically sized part of the snapshot header */ | ||
868 | offset = ROUND_UP(offset, 8); | ||
869 | - ret = bdrv_pread(bs->file, offset, &h, sizeof(h), 0); | ||
870 | + ret = bdrv_pread(bs->file, offset, sizeof(h), &h, 0); | ||
871 | if (ret < 0) { | ||
872 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
873 | goto fail; | ||
874 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
875 | } | ||
876 | |||
877 | /* Read known extra data */ | ||
878 | - ret = bdrv_pread(bs->file, offset, &extra, | ||
879 | - MIN(sizeof(extra), sn->extra_data_size), 0); | ||
880 | + ret = bdrv_pread(bs->file, offset, | ||
881 | + MIN(sizeof(extra), sn->extra_data_size), &extra, 0); | ||
882 | if (ret < 0) { | ||
883 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
884 | goto fail; | ||
885 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
886 | /* Store unknown extra data */ | ||
887 | unknown_extra_data_size = sn->extra_data_size - sizeof(extra); | ||
888 | sn->unknown_extra_data = g_malloc(unknown_extra_data_size); | ||
889 | - ret = bdrv_pread(bs->file, offset, sn->unknown_extra_data, | ||
890 | - unknown_extra_data_size, 0); | ||
891 | + ret = bdrv_pread(bs->file, offset, unknown_extra_data_size, | ||
892 | + sn->unknown_extra_data, 0); | ||
893 | if (ret < 0) { | ||
894 | error_setg_errno(errp, -ret, | ||
895 | "Failed to read snapshot table"); | ||
896 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
897 | |||
898 | /* Read snapshot ID */ | ||
899 | sn->id_str = g_malloc(id_str_size + 1); | ||
900 | - ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size, 0); | ||
901 | + ret = bdrv_pread(bs->file, offset, id_str_size, sn->id_str, 0); | ||
902 | if (ret < 0) { | ||
903 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
904 | goto fail; | ||
905 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, | ||
906 | |||
907 | /* Read snapshot name */ | ||
908 | sn->name = g_malloc(name_size + 1); | ||
909 | - ret = bdrv_pread(bs->file, offset, sn->name, name_size, 0); | ||
910 | + ret = bdrv_pread(bs->file, offset, name_size, sn->name, 0); | ||
911 | if (ret < 0) { | ||
912 | error_setg_errno(errp, -ret, "Failed to read snapshot table"); | ||
913 | goto fail; | ||
914 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
915 | h.name_size = cpu_to_be16(name_size); | ||
916 | offset = ROUND_UP(offset, 8); | ||
917 | |||
918 | - ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h), 0); | ||
919 | + ret = bdrv_pwrite(bs->file, offset, sizeof(h), &h, 0); | ||
920 | if (ret < 0) { | ||
921 | goto fail; | ||
922 | } | ||
923 | offset += sizeof(h); | ||
924 | |||
925 | - ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra), 0); | ||
926 | + ret = bdrv_pwrite(bs->file, offset, sizeof(extra), &extra, 0); | ||
927 | if (ret < 0) { | ||
928 | goto fail; | ||
929 | } | ||
930 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
931 | assert(unknown_extra_data_size <= BDRV_REQUEST_MAX_BYTES); | ||
932 | assert(sn->unknown_extra_data); | ||
933 | |||
934 | - ret = bdrv_pwrite(bs->file, offset, sn->unknown_extra_data, | ||
935 | - unknown_extra_data_size, 0); | ||
936 | + ret = bdrv_pwrite(bs->file, offset, unknown_extra_data_size, | ||
937 | + sn->unknown_extra_data, 0); | ||
938 | if (ret < 0) { | ||
939 | goto fail; | ||
940 | } | ||
941 | offset += unknown_extra_data_size; | ||
942 | } | ||
943 | |||
944 | - ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size, 0); | ||
945 | + ret = bdrv_pwrite(bs->file, offset, id_str_size, sn->id_str, 0); | ||
946 | if (ret < 0) { | ||
947 | goto fail; | ||
948 | } | ||
949 | offset += id_str_size; | ||
950 | |||
951 | - ret = bdrv_pwrite(bs->file, offset, sn->name, name_size, 0); | ||
952 | + ret = bdrv_pwrite(bs->file, offset, name_size, sn->name, 0); | ||
953 | if (ret < 0) { | ||
954 | goto fail; | ||
955 | } | ||
956 | @@ -XXX,XX +XXX,XX @@ int qcow2_write_snapshots(BlockDriverState *bs) | ||
957 | header_data.snapshots_offset = cpu_to_be64(snapshots_offset); | ||
958 | |||
959 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
960 | - &header_data, sizeof(header_data), 0); | ||
961 | + sizeof(header_data), &header_data, 0); | ||
962 | if (ret < 0) { | ||
963 | goto fail; | ||
964 | } | ||
965 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, | ||
966 | |||
967 | /* qcow2_do_open() discards this information in check mode */ | ||
968 | ret = bdrv_pread(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
969 | - &snapshot_table_pointer, sizeof(snapshot_table_pointer), | ||
970 | + sizeof(snapshot_table_pointer), &snapshot_table_pointer, | ||
971 | 0); | ||
972 | if (ret < 0) { | ||
973 | result->check_errors++; | ||
974 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, | ||
975 | |||
976 | snapshot_table_pointer.nb_snapshots = cpu_to_be32(s->nb_snapshots); | ||
977 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
978 | - &snapshot_table_pointer.nb_snapshots, | ||
979 | - sizeof(snapshot_table_pointer.nb_snapshots), 0); | ||
980 | + sizeof(snapshot_table_pointer.nb_snapshots), | ||
981 | + &snapshot_table_pointer.nb_snapshots, 0); | ||
982 | if (ret < 0) { | ||
983 | result->check_errors++; | ||
984 | fprintf(stderr, "ERROR failed to update the snapshot count in the " | ||
985 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
986 | goto fail; | ||
987 | } | ||
988 | |||
989 | - ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table, | ||
990 | - s->l1_size * L1E_SIZE, 0); | ||
991 | + ret = bdrv_pwrite(bs->file, sn->l1_table_offset, s->l1_size * L1E_SIZE, | ||
992 | + l1_table, 0); | ||
993 | if (ret < 0) { | ||
994 | goto fail; | ||
995 | } | ||
996 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) | ||
997 | goto fail; | ||
998 | } | ||
999 | |||
1000 | - ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_table, sn_l1_bytes, | ||
1001 | + ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_bytes, sn_l1_table, | ||
1002 | 0); | ||
1003 | if (ret < 0) { | ||
1004 | goto fail; | ||
1005 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) | ||
1006 | goto fail; | ||
1007 | } | ||
1008 | |||
1009 | - ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table, | ||
1010 | - cur_l1_bytes, 0); | ||
1011 | + ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, cur_l1_bytes, | ||
1012 | + sn_l1_table, 0); | ||
1013 | if (ret < 0) { | ||
1014 | goto fail; | ||
1015 | } | ||
1016 | @@ -XXX,XX +XXX,XX @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, | ||
1017 | return -ENOMEM; | ||
1018 | } | ||
1019 | |||
1020 | - ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_table, | ||
1021 | - new_l1_bytes, 0); | ||
1022 | + ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_bytes, | ||
1023 | + new_l1_table, 0); | ||
1024 | if (ret < 0) { | ||
1025 | error_setg(errp, "Failed to read l1 table for snapshot"); | ||
1026 | qemu_vfree(new_l1_table); | ||
56 | diff --git a/block/qcow2.c b/block/qcow2.c | 1027 | diff --git a/block/qcow2.c b/block/qcow2.c |
57 | index XXXXXXX..XXXXXXX 100644 | 1028 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/block/qcow2.c | 1029 | --- a/block/qcow2.c |
59 | +++ b/block/qcow2.c | 1030 | +++ b/block/qcow2.c |
60 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, | 1031 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, |
61 | goto fail; | 1032 | return -1; |
62 | } | 1033 | } |
63 | 1034 | ||
64 | - s->cluster_cache = g_malloc(s->cluster_size); | 1035 | - ret = bdrv_pread(bs->file, s->crypto_header.offset + offset, buf, buflen, |
65 | - /* one more sector for decompressed data alignment */ | 1036 | + ret = bdrv_pread(bs->file, s->crypto_header.offset + offset, buflen, buf, |
66 | - s->cluster_data = qemu_try_blockalign(bs->file->bs, QCOW_MAX_CRYPT_CLUSTERS | 1037 | 0); |
67 | - * s->cluster_size + 512); | 1038 | if (ret < 0) { |
68 | - if (s->cluster_data == NULL) { | 1039 | error_setg_errno(errp, -ret, "Could not read encryption header"); |
69 | - error_setg(errp, "Could not allocate temporary cluster buffer"); | 1040 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, |
70 | - ret = -ENOMEM; | 1041 | return -1; |
71 | - goto fail; | 1042 | } |
72 | - } | 1043 | |
73 | - | 1044 | - ret = bdrv_pwrite(bs->file, s->crypto_header.offset + offset, buf, buflen, |
74 | s->cluster_cache_offset = -1; | 1045 | + ret = bdrv_pwrite(bs->file, s->crypto_header.offset + offset, buflen, buf, |
75 | s->flags = flags; | 1046 | 0); |
76 | 1047 | if (ret < 0) { | |
77 | @@ -XXX,XX +XXX,XX @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, | 1048 | error_setg_errno(errp, -ret, "Could not read encryption header"); |
78 | if (s->refcount_block_cache) { | 1049 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, |
79 | qcow2_cache_destroy(bs, s->refcount_block_cache); | 1050 | printf("attempting to read extended header in offset %lu\n", offset); |
80 | } | 1051 | #endif |
81 | - g_free(s->cluster_cache); | 1052 | |
82 | - qemu_vfree(s->cluster_data); | 1053 | - ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext), 0); |
83 | qcrypto_block_free(s->crypto); | 1054 | + ret = bdrv_pread(bs->file, offset, sizeof(ext), &ext, 0); |
84 | qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); | 1055 | if (ret < 0) { |
85 | return ret; | 1056 | error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: " |
1057 | "pread fail from offset %" PRIu64, offset); | ||
1058 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1059 | sizeof(bs->backing_format)); | ||
1060 | return 2; | ||
1061 | } | ||
1062 | - ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len, 0); | ||
1063 | + ret = bdrv_pread(bs->file, offset, ext.len, bs->backing_format, 0); | ||
1064 | if (ret < 0) { | ||
1065 | error_setg_errno(errp, -ret, "ERROR: ext_backing_format: " | ||
1066 | "Could not read format name"); | ||
1067 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1068 | case QCOW2_EXT_MAGIC_FEATURE_TABLE: | ||
1069 | if (p_feature_table != NULL) { | ||
1070 | void *feature_table = g_malloc0(ext.len + 2 * sizeof(Qcow2Feature)); | ||
1071 | - ret = bdrv_pread(bs->file, offset, feature_table, ext.len, 0); | ||
1072 | + ret = bdrv_pread(bs->file, offset, ext.len, feature_table, 0); | ||
1073 | if (ret < 0) { | ||
1074 | error_setg_errno(errp, -ret, "ERROR: ext_feature_table: " | ||
1075 | "Could not read table"); | ||
1076 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1077 | return -EINVAL; | ||
1078 | } | ||
1079 | |||
1080 | - ret = bdrv_pread(bs->file, offset, &s->crypto_header, ext.len, 0); | ||
1081 | + ret = bdrv_pread(bs->file, offset, ext.len, &s->crypto_header, 0); | ||
1082 | if (ret < 0) { | ||
1083 | error_setg_errno(errp, -ret, | ||
1084 | "Unable to read CRYPTO header extension"); | ||
1085 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1086 | break; | ||
1087 | } | ||
1088 | |||
1089 | - ret = bdrv_pread(bs->file, offset, &bitmaps_ext, ext.len, 0); | ||
1090 | + ret = bdrv_pread(bs->file, offset, ext.len, &bitmaps_ext, 0); | ||
1091 | if (ret < 0) { | ||
1092 | error_setg_errno(errp, -ret, "bitmaps_ext: " | ||
1093 | "Could not read ext header"); | ||
1094 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1095 | case QCOW2_EXT_MAGIC_DATA_FILE: | ||
1096 | { | ||
1097 | s->image_data_file = g_malloc0(ext.len + 1); | ||
1098 | - ret = bdrv_pread(bs->file, offset, s->image_data_file, ext.len, 0); | ||
1099 | + ret = bdrv_pread(bs->file, offset, ext.len, s->image_data_file, 0); | ||
1100 | if (ret < 0) { | ||
1101 | error_setg_errno(errp, -ret, | ||
1102 | "ERROR: Could not read data file name"); | ||
1103 | @@ -XXX,XX +XXX,XX @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, | ||
1104 | uext->len = ext.len; | ||
1105 | QLIST_INSERT_HEAD(&s->unknown_header_ext, uext, next); | ||
1106 | |||
1107 | - ret = bdrv_pread(bs->file, offset, uext->data, uext->len, 0); | ||
1108 | + ret = bdrv_pread(bs->file, offset, uext->len, uext->data, 0); | ||
1109 | if (ret < 0) { | ||
1110 | error_setg_errno(errp, -ret, "ERROR: unknown extension: " | ||
1111 | "Could not read data"); | ||
1112 | @@ -XXX,XX +XXX,XX @@ int qcow2_mark_dirty(BlockDriverState *bs) | ||
1113 | |||
1114 | val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); | ||
1115 | ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features), | ||
1116 | - &val, sizeof(val), 0); | ||
1117 | + sizeof(val), &val, 0); | ||
1118 | if (ret < 0) { | ||
1119 | return ret; | ||
1120 | } | ||
1121 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1122 | uint64_t l1_vm_state_index; | ||
1123 | bool update_header = false; | ||
1124 | |||
1125 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
1126 | + ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0); | ||
1127 | if (ret < 0) { | ||
1128 | error_setg_errno(errp, -ret, "Could not read qcow2 header"); | ||
1129 | goto fail; | ||
1130 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1131 | if (header.header_length > sizeof(header)) { | ||
1132 | s->unknown_header_fields_size = header.header_length - sizeof(header); | ||
1133 | s->unknown_header_fields = g_malloc(s->unknown_header_fields_size); | ||
1134 | - ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields, | ||
1135 | - s->unknown_header_fields_size, 0); | ||
1136 | + ret = bdrv_pread(bs->file, sizeof(header), | ||
1137 | + s->unknown_header_fields_size, | ||
1138 | + s->unknown_header_fields, 0); | ||
1139 | if (ret < 0) { | ||
1140 | error_setg_errno(errp, -ret, "Could not read unknown qcow2 header " | ||
1141 | "fields"); | ||
1142 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1143 | ret = -ENOMEM; | ||
1144 | goto fail; | ||
1145 | } | ||
1146 | - ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, | ||
1147 | - s->l1_size * L1E_SIZE, 0); | ||
1148 | + ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_size * L1E_SIZE, | ||
1149 | + s->l1_table, 0); | ||
1150 | if (ret < 0) { | ||
1151 | error_setg_errno(errp, -ret, "Could not read L1 table"); | ||
1152 | goto fail; | ||
1153 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, | ||
1154 | ret = -EINVAL; | ||
1155 | goto fail; | ||
1156 | } | ||
1157 | - ret = bdrv_pread(bs->file, header.backing_file_offset, | ||
1158 | - bs->auto_backing_file, len, 0); | ||
1159 | + ret = bdrv_pread(bs->file, header.backing_file_offset, len, | ||
1160 | + bs->auto_backing_file, 0); | ||
1161 | if (ret < 0) { | ||
1162 | error_setg_errno(errp, -ret, "Could not read backing file name"); | ||
1163 | goto fail; | ||
1164 | @@ -XXX,XX +XXX,XX @@ int qcow2_update_header(BlockDriverState *bs) | ||
1165 | } | ||
1166 | |||
1167 | /* Write the new header */ | ||
1168 | - ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size, 0); | ||
1169 | + ret = bdrv_pwrite(bs->file, 0, s->cluster_size, header, 0); | ||
1170 | if (ret < 0) { | ||
1171 | goto fail; | ||
1172 | } | ||
1173 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset, | ||
1174 | |||
1175 | /* write updated header.size */ | ||
1176 | offset = cpu_to_be64(offset); | ||
1177 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), &offset, | ||
1178 | - sizeof(offset), 0); | ||
1179 | + ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), | ||
1180 | + sizeof(offset), &offset, 0); | ||
1181 | if (ret < 0) { | ||
1182 | error_setg_errno(errp, -ret, "Failed to update the image size"); | ||
1183 | goto fail; | ||
1184 | @@ -XXX,XX +XXX,XX @@ static int make_completely_empty(BlockDriverState *bs) | ||
1185 | l1_ofs_rt_ofs_cls.reftable_offset = cpu_to_be64(s->cluster_size); | ||
1186 | l1_ofs_rt_ofs_cls.reftable_clusters = cpu_to_be32(1); | ||
1187 | ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_table_offset), | ||
1188 | - &l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls), 0); | ||
1189 | + sizeof(l1_ofs_rt_ofs_cls), &l1_ofs_rt_ofs_cls, 0); | ||
1190 | if (ret < 0) { | ||
1191 | goto fail_broken_refcounts; | ||
1192 | } | ||
1193 | @@ -XXX,XX +XXX,XX @@ static int make_completely_empty(BlockDriverState *bs) | ||
1194 | |||
1195 | /* Enter the first refblock into the reftable */ | ||
1196 | rt_entry = cpu_to_be64(2 * s->cluster_size); | ||
1197 | - ret = bdrv_pwrite_sync(bs->file, s->cluster_size, &rt_entry, | ||
1198 | - sizeof(rt_entry), 0); | ||
1199 | + ret = bdrv_pwrite_sync(bs->file, s->cluster_size, sizeof(rt_entry), | ||
1200 | + &rt_entry, 0); | ||
1201 | if (ret < 0) { | ||
1202 | goto fail_broken_refcounts; | ||
1203 | } | ||
1204 | diff --git a/block/qed.c b/block/qed.c | ||
1205 | index XXXXXXX..XXXXXXX 100644 | ||
1206 | --- a/block/qed.c | ||
1207 | +++ b/block/qed.c | ||
1208 | @@ -XXX,XX +XXX,XX @@ int qed_write_header_sync(BDRVQEDState *s) | ||
1209 | int ret; | ||
1210 | |||
1211 | qed_header_cpu_to_le(&s->header, &le); | ||
1212 | - ret = bdrv_pwrite(s->bs->file, 0, &le, sizeof(le), 0); | ||
1213 | + ret = bdrv_pwrite(s->bs->file, 0, sizeof(le), &le, 0); | ||
1214 | if (ret != sizeof(le)) { | ||
1215 | return ret; | ||
1216 | } | ||
1217 | @@ -XXX,XX +XXX,XX @@ static int qed_read_string(BdrvChild *file, uint64_t offset, size_t n, | ||
1218 | if (n >= buflen) { | ||
1219 | return -EINVAL; | ||
1220 | } | ||
1221 | - ret = bdrv_pread(file, offset, buf, n, 0); | ||
1222 | + ret = bdrv_pread(file, offset, n, buf, 0); | ||
1223 | if (ret < 0) { | ||
1224 | return ret; | ||
1225 | } | ||
1226 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options, | ||
1227 | int64_t file_size; | ||
1228 | int ret; | ||
1229 | |||
1230 | - ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header), 0); | ||
1231 | + ret = bdrv_pread(bs->file, 0, sizeof(le_header), &le_header, 0); | ||
1232 | if (ret < 0) { | ||
1233 | error_setg(errp, "Failed to read QED header"); | ||
1234 | return ret; | ||
1235 | @@ -XXX,XX +XXX,XX @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs, | ||
1236 | } | ||
1237 | |||
1238 | /* Write new header */ | ||
1239 | - ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len, 0); | ||
1240 | + ret = bdrv_pwrite_sync(bs->file, 0, buffer_len, buffer, 0); | ||
1241 | g_free(buffer); | ||
1242 | if (ret == 0) { | ||
1243 | memcpy(&s->header, &new_header, sizeof(new_header)); | ||
1244 | diff --git a/block/vdi.c b/block/vdi.c | ||
1245 | index XXXXXXX..XXXXXXX 100644 | ||
1246 | --- a/block/vdi.c | ||
1247 | +++ b/block/vdi.c | ||
1248 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
1249 | |||
1250 | logout("\n"); | ||
1251 | |||
1252 | - ret = bdrv_pread(bs->file, 0, &header, sizeof(header), 0); | ||
1253 | + ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0); | ||
1254 | if (ret < 0) { | ||
1255 | goto fail; | ||
1256 | } | ||
1257 | @@ -XXX,XX +XXX,XX @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, | ||
1258 | goto fail; | ||
1259 | } | ||
1260 | |||
1261 | - ret = bdrv_pread(bs->file, header.offset_bmap, s->bmap, | ||
1262 | - bmap_size * SECTOR_SIZE, 0); | ||
1263 | + ret = bdrv_pread(bs->file, header.offset_bmap, bmap_size * SECTOR_SIZE, | ||
1264 | + s->bmap, 0); | ||
1265 | if (ret < 0) { | ||
1266 | goto fail_free_bmap; | ||
1267 | } | ||
1268 | @@ -XXX,XX +XXX,XX @@ vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, | ||
1269 | * so this full-cluster write does not overlap a partial write | ||
1270 | * of the same cluster, issued from the "else" branch. | ||
1271 | */ | ||
1272 | - ret = bdrv_pwrite(bs->file, data_offset, block, s->block_size, 0); | ||
1273 | + ret = bdrv_pwrite(bs->file, data_offset, s->block_size, block, 0); | ||
1274 | qemu_co_rwlock_unlock(&s->bmap_lock); | ||
1275 | } else { | ||
1276 | nonallocating_write: | ||
1277 | @@ -XXX,XX +XXX,XX @@ nonallocating_write: | ||
1278 | assert(VDI_IS_ALLOCATED(bmap_first)); | ||
1279 | *header = s->header; | ||
1280 | vdi_header_to_le(header); | ||
1281 | - ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header), 0); | ||
1282 | + ret = bdrv_pwrite(bs->file, 0, sizeof(*header), header, 0); | ||
1283 | g_free(header); | ||
1284 | |||
1285 | if (ret < 0) { | ||
1286 | @@ -XXX,XX +XXX,XX @@ nonallocating_write: | ||
1287 | base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE; | ||
1288 | logout("will write %u block map sectors starting from entry %u\n", | ||
1289 | n_sectors, bmap_first); | ||
1290 | - ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base, | ||
1291 | - n_sectors * SECTOR_SIZE, 0); | ||
1292 | + ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, | ||
1293 | + n_sectors * SECTOR_SIZE, base, 0); | ||
1294 | } | ||
1295 | |||
1296 | return ret < 0 ? ret : 0; | ||
1297 | diff --git a/block/vhdx-log.c b/block/vhdx-log.c | ||
1298 | index XXXXXXX..XXXXXXX 100644 | ||
1299 | --- a/block/vhdx-log.c | ||
1300 | +++ b/block/vhdx-log.c | ||
1301 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log, | ||
1302 | |||
1303 | offset = log->offset + read; | ||
1304 | |||
1305 | - ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader), 0); | ||
1306 | + ret = bdrv_pread(bs->file, offset, sizeof(VHDXLogEntryHeader), hdr, 0); | ||
1307 | if (ret < 0) { | ||
1308 | goto exit; | ||
1309 | } | ||
1310 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_read_sectors(BlockDriverState *bs, VHDXLogEntries *log, | ||
1311 | } | ||
1312 | offset = log->offset + read; | ||
1313 | |||
1314 | - ret = bdrv_pread(bs->file, offset, buffer, VHDX_LOG_SECTOR_SIZE, 0); | ||
1315 | + ret = bdrv_pread(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer, 0); | ||
1316 | if (ret < 0) { | ||
1317 | goto exit; | ||
1318 | } | ||
1319 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log, | ||
1320 | /* full */ | ||
1321 | break; | ||
1322 | } | ||
1323 | - ret = bdrv_pwrite(bs->file, offset, buffer_tmp, VHDX_LOG_SECTOR_SIZE, | ||
1324 | + ret = bdrv_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp, | ||
1325 | 0); | ||
1326 | if (ret < 0) { | ||
1327 | goto exit; | ||
1328 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_flush_desc(BlockDriverState *bs, VHDXLogDescriptor *desc, | ||
1329 | |||
1330 | /* count is only > 1 if we are writing zeroes */ | ||
1331 | for (i = 0; i < count; i++) { | ||
1332 | - ret = bdrv_pwrite_sync(bs->file, file_offset, buffer, | ||
1333 | - VHDX_LOG_SECTOR_SIZE, 0); | ||
1334 | + ret = bdrv_pwrite_sync(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE, | ||
1335 | + buffer, 0); | ||
1336 | if (ret < 0) { | ||
1337 | goto exit; | ||
1338 | } | ||
1339 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, | ||
1340 | |||
1341 | if (i == 0 && leading_length) { | ||
1342 | /* partial sector at the front of the buffer */ | ||
1343 | - ret = bdrv_pread(bs->file, file_offset, merged_sector, | ||
1344 | - VHDX_LOG_SECTOR_SIZE, 0); | ||
1345 | + ret = bdrv_pread(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE, | ||
1346 | + merged_sector, 0); | ||
1347 | if (ret < 0) { | ||
1348 | goto exit; | ||
1349 | } | ||
1350 | @@ -XXX,XX +XXX,XX @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s, | ||
1351 | } else if (i == sectors - 1 && trailing_length) { | ||
1352 | /* partial sector at the end of the buffer */ | ||
1353 | ret = bdrv_pread(bs->file, file_offset, | ||
1354 | - merged_sector + trailing_length, | ||
1355 | - VHDX_LOG_SECTOR_SIZE - trailing_length, 0); | ||
1356 | + VHDX_LOG_SECTOR_SIZE - trailing_length, | ||
1357 | + merged_sector + trailing_length, 0); | ||
1358 | if (ret < 0) { | ||
1359 | goto exit; | ||
1360 | } | ||
1361 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
1362 | index XXXXXXX..XXXXXXX 100644 | ||
1363 | --- a/block/vhdx.c | ||
1364 | +++ b/block/vhdx.c | ||
1365 | @@ -XXX,XX +XXX,XX @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr, | ||
1366 | buffer = qemu_blockalign(bs_file, VHDX_HEADER_SIZE); | ||
1367 | if (read) { | ||
1368 | /* if true, we can't assume the extra reserved bytes are 0 */ | ||
1369 | - ret = bdrv_pread(file, offset, buffer, VHDX_HEADER_SIZE, 0); | ||
1370 | + ret = bdrv_pread(file, offset, VHDX_HEADER_SIZE, buffer, 0); | ||
1371 | if (ret < 0) { | ||
1372 | goto exit; | ||
1373 | } | ||
1374 | @@ -XXX,XX +XXX,XX @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr, | ||
1375 | vhdx_header_le_export(hdr, header_le); | ||
1376 | vhdx_update_checksum(buffer, VHDX_HEADER_SIZE, | ||
1377 | offsetof(VHDXHeader, checksum)); | ||
1378 | - ret = bdrv_pwrite_sync(file, offset, header_le, sizeof(VHDXHeader), 0); | ||
1379 | + ret = bdrv_pwrite_sync(file, offset, sizeof(VHDXHeader), header_le, 0); | ||
1380 | |||
1381 | exit: | ||
1382 | qemu_vfree(buffer); | ||
1383 | @@ -XXX,XX +XXX,XX @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s, | ||
1384 | /* We have to read the whole VHDX_HEADER_SIZE instead of | ||
1385 | * sizeof(VHDXHeader), because the checksum is over the whole | ||
1386 | * region */ | ||
1387 | - ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, buffer, VHDX_HEADER_SIZE, | ||
1388 | + ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, VHDX_HEADER_SIZE, buffer, | ||
1389 | 0); | ||
1390 | if (ret < 0) { | ||
1391 | goto fail; | ||
1392 | @@ -XXX,XX +XXX,XX @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s, | ||
1393 | } | ||
1394 | } | ||
1395 | |||
1396 | - ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, buffer, VHDX_HEADER_SIZE, | ||
1397 | + ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, VHDX_HEADER_SIZE, buffer, | ||
1398 | 0); | ||
1399 | if (ret < 0) { | ||
1400 | goto fail; | ||
1401 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s) | ||
1402 | * whole block */ | ||
1403 | buffer = qemu_blockalign(bs, VHDX_HEADER_BLOCK_SIZE); | ||
1404 | |||
1405 | - ret = bdrv_pread(bs->file, VHDX_REGION_TABLE_OFFSET, buffer, | ||
1406 | - VHDX_HEADER_BLOCK_SIZE, 0); | ||
1407 | + ret = bdrv_pread(bs->file, VHDX_REGION_TABLE_OFFSET, | ||
1408 | + VHDX_HEADER_BLOCK_SIZE, buffer, 0); | ||
1409 | if (ret < 0) { | ||
1410 | goto fail; | ||
1411 | } | ||
1412 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1413 | |||
1414 | buffer = qemu_blockalign(bs, VHDX_METADATA_TABLE_MAX_SIZE); | ||
1415 | |||
1416 | - ret = bdrv_pread(bs->file, s->metadata_rt.file_offset, buffer, | ||
1417 | - VHDX_METADATA_TABLE_MAX_SIZE, 0); | ||
1418 | + ret = bdrv_pread(bs->file, s->metadata_rt.file_offset, | ||
1419 | + VHDX_METADATA_TABLE_MAX_SIZE, buffer, 0); | ||
1420 | if (ret < 0) { | ||
1421 | goto exit; | ||
1422 | } | ||
1423 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1424 | ret = bdrv_pread(bs->file, | ||
1425 | s->metadata_entries.file_parameters_entry.offset | ||
1426 | + s->metadata_rt.file_offset, | ||
1427 | - &s->params, | ||
1428 | sizeof(s->params), | ||
1429 | + &s->params, | ||
1430 | 0); | ||
1431 | |||
1432 | if (ret < 0) { | ||
1433 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1434 | ret = bdrv_pread(bs->file, | ||
1435 | s->metadata_entries.virtual_disk_size_entry.offset | ||
1436 | + s->metadata_rt.file_offset, | ||
1437 | - &s->virtual_disk_size, | ||
1438 | sizeof(uint64_t), | ||
1439 | + &s->virtual_disk_size, | ||
1440 | 0); | ||
1441 | if (ret < 0) { | ||
1442 | goto exit; | ||
1443 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1444 | ret = bdrv_pread(bs->file, | ||
1445 | s->metadata_entries.logical_sector_size_entry.offset | ||
1446 | + s->metadata_rt.file_offset, | ||
1447 | - &s->logical_sector_size, | ||
1448 | sizeof(uint32_t), | ||
1449 | + &s->logical_sector_size, | ||
1450 | 0); | ||
1451 | if (ret < 0) { | ||
1452 | goto exit; | ||
1453 | @@ -XXX,XX +XXX,XX @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s) | ||
1454 | ret = bdrv_pread(bs->file, | ||
1455 | s->metadata_entries.phys_sector_size_entry.offset | ||
1456 | + s->metadata_rt.file_offset, | ||
1457 | - &s->physical_sector_size, | ||
1458 | sizeof(uint32_t), | ||
1459 | + &s->physical_sector_size, | ||
1460 | 0); | ||
1461 | if (ret < 0) { | ||
1462 | goto exit; | ||
1463 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
1464 | QLIST_INIT(&s->regions); | ||
1465 | |||
1466 | /* validate the file signature */ | ||
1467 | - ret = bdrv_pread(bs->file, 0, &signature, sizeof(uint64_t), 0); | ||
1468 | + ret = bdrv_pread(bs->file, 0, sizeof(uint64_t), &signature, 0); | ||
1469 | if (ret < 0) { | ||
1470 | goto fail; | ||
1471 | } | ||
1472 | @@ -XXX,XX +XXX,XX @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, | ||
1473 | goto fail; | ||
1474 | } | ||
1475 | |||
1476 | - ret = bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.length, 0); | ||
1477 | + ret = bdrv_pread(bs->file, s->bat_offset, s->bat_rt.length, s->bat, 0); | ||
1478 | if (ret < 0) { | ||
1479 | goto fail; | ||
1480 | } | ||
1481 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
1482 | index XXXXXXX..XXXXXXX 100644 | ||
1483 | --- a/block/vmdk.c | ||
1484 | +++ b/block/vmdk.c | ||
1485 | @@ -XXX,XX +XXX,XX @@ static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid) | ||
1486 | int ret; | ||
1487 | |||
1488 | desc = g_malloc0(DESC_SIZE); | ||
1489 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1490 | + ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0); | ||
1491 | if (ret < 0) { | ||
1492 | goto out; | ||
1493 | } | ||
1494 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) | ||
1495 | |||
1496 | desc = g_malloc0(DESC_SIZE); | ||
1497 | tmp_desc = g_malloc0(DESC_SIZE); | ||
1498 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1499 | + ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0); | ||
1500 | if (ret < 0) { | ||
1501 | goto out; | ||
1502 | } | ||
1503 | @@ -XXX,XX +XXX,XX @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) | ||
1504 | pstrcat(desc, DESC_SIZE, tmp_desc); | ||
1505 | } | ||
1506 | |||
1507 | - ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1508 | + ret = bdrv_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0); | ||
1509 | |||
1510 | out: | ||
1511 | g_free(desc); | ||
1512 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parent_open(BlockDriverState *bs) | ||
1513 | int ret; | ||
1514 | |||
1515 | desc = g_malloc0(DESC_SIZE + 1); | ||
1516 | - ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE, 0); | ||
1517 | + ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0); | ||
1518 | if (ret < 0) { | ||
1519 | goto out; | ||
1520 | } | ||
1521 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
1522 | return -ENOMEM; | ||
1523 | } | ||
1524 | |||
1525 | - ret = bdrv_pread(extent->file, extent->l1_table_offset, extent->l1_table, | ||
1526 | - l1_size, 0); | ||
1527 | + ret = bdrv_pread(extent->file, extent->l1_table_offset, l1_size, | ||
1528 | + extent->l1_table, 0); | ||
1529 | if (ret < 0) { | ||
1530 | bdrv_refresh_filename(extent->file->bs); | ||
1531 | error_setg_errno(errp, -ret, | ||
1532 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent, | ||
1533 | goto fail_l1; | ||
1534 | } | ||
1535 | ret = bdrv_pread(extent->file, extent->l1_backup_table_offset, | ||
1536 | - extent->l1_backup_table, l1_size, 0); | ||
1537 | + l1_size, extent->l1_backup_table, 0); | ||
1538 | if (ret < 0) { | ||
1539 | bdrv_refresh_filename(extent->file->bs); | ||
1540 | error_setg_errno(errp, -ret, | ||
1541 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, | ||
1542 | VMDK3Header header; | ||
1543 | VmdkExtent *extent = NULL; | ||
1544 | |||
1545 | - ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header), 0); | ||
1546 | + ret = bdrv_pread(file, sizeof(magic), sizeof(header), &header, 0); | ||
1547 | if (ret < 0) { | ||
1548 | bdrv_refresh_filename(file->bs); | ||
1549 | error_setg_errno(errp, -ret, | ||
1550 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_se_sparse(BlockDriverState *bs, | ||
1551 | |||
1552 | assert(sizeof(const_header) == SECTOR_SIZE); | ||
1553 | |||
1554 | - ret = bdrv_pread(file, 0, &const_header, sizeof(const_header), 0); | ||
1555 | + ret = bdrv_pread(file, 0, sizeof(const_header), &const_header, 0); | ||
1556 | if (ret < 0) { | ||
1557 | bdrv_refresh_filename(file->bs); | ||
1558 | error_setg_errno(errp, -ret, | ||
1559 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_se_sparse(BlockDriverState *bs, | ||
1560 | assert(sizeof(volatile_header) == SECTOR_SIZE); | ||
1561 | |||
1562 | ret = bdrv_pread(file, const_header.volatile_header_offset * SECTOR_SIZE, | ||
1563 | - &volatile_header, sizeof(volatile_header), 0); | ||
1564 | + sizeof(volatile_header), &volatile_header, 0); | ||
1565 | if (ret < 0) { | ||
1566 | bdrv_refresh_filename(file->bs); | ||
1567 | error_setg_errno(errp, -ret, | ||
1568 | @@ -XXX,XX +XXX,XX @@ static char *vmdk_read_desc(BdrvChild *file, uint64_t desc_offset, Error **errp) | ||
1569 | size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */ | ||
1570 | buf = g_malloc(size + 1); | ||
1571 | |||
1572 | - ret = bdrv_pread(file, desc_offset, buf, size, 0); | ||
1573 | + ret = bdrv_pread(file, desc_offset, size, buf, 0); | ||
1574 | if (ret < 0) { | ||
1575 | error_setg_errno(errp, -ret, "Could not read from file"); | ||
1576 | g_free(buf); | ||
1577 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmdk4(BlockDriverState *bs, | ||
1578 | int64_t l1_backup_offset = 0; | ||
1579 | bool compressed; | ||
1580 | |||
1581 | - ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header), 0); | ||
1582 | + ret = bdrv_pread(file, sizeof(magic), sizeof(header), &header, 0); | ||
1583 | if (ret < 0) { | ||
1584 | bdrv_refresh_filename(file->bs); | ||
1585 | error_setg_errno(errp, -ret, | ||
1586 | @@ -XXX,XX +XXX,XX @@ static int vmdk_open_vmdk4(BlockDriverState *bs, | ||
1587 | } QEMU_PACKED footer; | ||
1588 | |||
1589 | ret = bdrv_pread(file, bs->file->bs->total_sectors * 512 - 1536, | ||
1590 | - &footer, sizeof(footer), 0); | ||
1591 | + sizeof(footer), &footer, 0); | ||
1592 | if (ret < 0) { | ||
1593 | error_setg_errno(errp, -ret, "Failed to read footer"); | ||
1594 | return ret; | ||
1595 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1596 | if (copy_from_backing) { | ||
1597 | /* qcow2 emits this on bs->file instead of bs->backing */ | ||
1598 | BLKDBG_EVENT(extent->file, BLKDBG_COW_READ); | ||
1599 | - ret = bdrv_pread(bs->backing, offset, whole_grain, | ||
1600 | - skip_start_bytes, 0); | ||
1601 | + ret = bdrv_pread(bs->backing, offset, skip_start_bytes, | ||
1602 | + whole_grain, 0); | ||
1603 | if (ret < 0) { | ||
1604 | ret = VMDK_ERROR; | ||
1605 | goto exit; | ||
1606 | } | ||
1607 | } | ||
1608 | BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE); | ||
1609 | - ret = bdrv_pwrite(extent->file, cluster_offset, whole_grain, | ||
1610 | - skip_start_bytes, 0); | ||
1611 | + ret = bdrv_pwrite(extent->file, cluster_offset, skip_start_bytes, | ||
1612 | + whole_grain, 0); | ||
1613 | if (ret < 0) { | ||
1614 | ret = VMDK_ERROR; | ||
1615 | goto exit; | ||
1616 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1617 | /* qcow2 emits this on bs->file instead of bs->backing */ | ||
1618 | BLKDBG_EVENT(extent->file, BLKDBG_COW_READ); | ||
1619 | ret = bdrv_pread(bs->backing, offset + skip_end_bytes, | ||
1620 | - whole_grain + skip_end_bytes, | ||
1621 | - cluster_bytes - skip_end_bytes, 0); | ||
1622 | + cluster_bytes - skip_end_bytes, | ||
1623 | + whole_grain + skip_end_bytes, 0); | ||
1624 | if (ret < 0) { | ||
1625 | ret = VMDK_ERROR; | ||
1626 | goto exit; | ||
1627 | @@ -XXX,XX +XXX,XX @@ static int get_whole_cluster(BlockDriverState *bs, | ||
1628 | } | ||
1629 | BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE); | ||
1630 | ret = bdrv_pwrite(extent->file, cluster_offset + skip_end_bytes, | ||
1631 | - whole_grain + skip_end_bytes, | ||
1632 | - cluster_bytes - skip_end_bytes, 0); | ||
1633 | + cluster_bytes - skip_end_bytes, | ||
1634 | + whole_grain + skip_end_bytes, 0); | ||
1635 | if (ret < 0) { | ||
1636 | ret = VMDK_ERROR; | ||
1637 | goto exit; | ||
1638 | @@ -XXX,XX +XXX,XX @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, | ||
1639 | if (bdrv_pwrite(extent->file, | ||
1640 | ((int64_t)m_data->l2_offset * 512) | ||
1641 | + (m_data->l2_index * sizeof(offset)), | ||
1642 | - &offset, sizeof(offset), 0) < 0) { | ||
1643 | + sizeof(offset), &offset, 0) < 0) { | ||
1644 | return VMDK_ERROR; | ||
1645 | } | ||
1646 | /* update backup L2 table */ | ||
1647 | @@ -XXX,XX +XXX,XX @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, | ||
1648 | if (bdrv_pwrite(extent->file, | ||
1649 | ((int64_t)m_data->l2_offset * 512) | ||
1650 | + (m_data->l2_index * sizeof(offset)), | ||
1651 | - &offset, sizeof(offset), 0) < 0) { | ||
1652 | + sizeof(offset), &offset, 0) < 0) { | ||
1653 | return VMDK_ERROR; | ||
1654 | } | ||
1655 | } | ||
1656 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
1657 | BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD); | ||
1658 | if (bdrv_pread(extent->file, | ||
1659 | (int64_t)l2_offset * 512, | ||
1660 | - l2_table, | ||
1661 | l2_size_bytes, | ||
1662 | + l2_table, | ||
1663 | 0 | ||
1664 | ) != l2_size_bytes) { | ||
1665 | return VMDK_ERROR; | ||
1666 | @@ -XXX,XX +XXX,XX @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, | ||
1667 | cluster_buf = g_malloc(buf_bytes); | ||
1668 | uncomp_buf = g_malloc(cluster_bytes); | ||
1669 | BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED); | ||
1670 | - ret = bdrv_pread(extent->file, cluster_offset, cluster_buf, buf_bytes, 0); | ||
1671 | + ret = bdrv_pread(extent->file, cluster_offset, buf_bytes, cluster_buf, 0); | ||
1672 | if (ret < 0) { | ||
1673 | goto out; | ||
1674 | } | ||
1675 | diff --git a/block/vpc.c b/block/vpc.c | ||
1676 | index XXXXXXX..XXXXXXX 100644 | ||
1677 | --- a/block/vpc.c | ||
1678 | +++ b/block/vpc.c | ||
1679 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1680 | goto fail; | ||
1681 | } | ||
1682 | |||
1683 | - ret = bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer), 0); | ||
1684 | + ret = bdrv_pread(bs->file, 0, sizeof(s->footer), &s->footer, 0); | ||
1685 | if (ret < 0) { | ||
1686 | error_setg(errp, "Unable to read VHD header"); | ||
1687 | goto fail; | ||
1688 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1689 | } | ||
1690 | |||
1691 | /* If a fixed disk, the footer is found only at the end of the file */ | ||
1692 | - ret = bdrv_pread(bs->file, offset - sizeof(*footer), footer, | ||
1693 | - sizeof(*footer), 0); | ||
1694 | + ret = bdrv_pread(bs->file, offset - sizeof(*footer), sizeof(*footer), | ||
1695 | + footer, 0); | ||
1696 | if (ret < 0) { | ||
1697 | goto fail; | ||
1698 | } | ||
1699 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1700 | |||
1701 | if (disk_type == VHD_DYNAMIC) { | ||
1702 | ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), | ||
1703 | - &dyndisk_header, sizeof(dyndisk_header), 0); | ||
1704 | + sizeof(dyndisk_header), &dyndisk_header, 0); | ||
1705 | if (ret < 0) { | ||
1706 | error_setg(errp, "Error reading dynamic VHD header"); | ||
1707 | goto fail; | ||
1708 | @@ -XXX,XX +XXX,XX @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, | ||
1709 | |||
1710 | s->bat_offset = be64_to_cpu(dyndisk_header.table_offset); | ||
1711 | |||
1712 | - ret = bdrv_pread(bs->file, s->bat_offset, s->pagetable, | ||
1713 | - pagetable_size, 0); | ||
1714 | + ret = bdrv_pread(bs->file, s->bat_offset, pagetable_size, | ||
1715 | + s->pagetable, 0); | ||
1716 | if (ret < 0) { | ||
1717 | error_setg(errp, "Error reading pagetable"); | ||
1718 | goto fail; | ||
1719 | @@ -XXX,XX +XXX,XX @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset, | ||
1720 | |||
1721 | s->last_bitmap_offset = bitmap_offset; | ||
1722 | memset(bitmap, 0xff, s->bitmap_size); | ||
1723 | - r = bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size, | ||
1724 | + r = bdrv_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap, | ||
1725 | 0); | ||
1726 | if (r < 0) { | ||
1727 | *err = r; | ||
1728 | @@ -XXX,XX +XXX,XX @@ static int rewrite_footer(BlockDriverState *bs) | ||
1729 | BDRVVPCState *s = bs->opaque; | ||
1730 | int64_t offset = s->free_data_block_offset; | ||
1731 | |||
1732 | - ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->footer), 0); | ||
1733 | + ret = bdrv_pwrite_sync(bs->file, offset, sizeof(s->footer), &s->footer, 0); | ||
1734 | if (ret < 0) | ||
1735 | return ret; | ||
1736 | |||
1737 | @@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset) | ||
1738 | |||
1739 | /* Initialize the block's bitmap */ | ||
1740 | memset(bitmap, 0xff, s->bitmap_size); | ||
1741 | - ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap, | ||
1742 | - s->bitmap_size, 0); | ||
1743 | + ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, | ||
1744 | + s->bitmap_size, bitmap, 0); | ||
1745 | if (ret < 0) { | ||
1746 | return ret; | ||
1747 | } | ||
1748 | @@ -XXX,XX +XXX,XX @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset) | ||
1749 | /* Write BAT entry to disk */ | ||
1750 | bat_offset = s->bat_offset + (4 * index); | ||
1751 | bat_value = cpu_to_be32(s->pagetable[index]); | ||
1752 | - ret = bdrv_pwrite_sync(bs->file, bat_offset, &bat_value, 4, 0); | ||
1753 | + ret = bdrv_pwrite_sync(bs->file, bat_offset, 4, &bat_value, 0); | ||
1754 | if (ret < 0) | ||
1755 | goto fail; | ||
1756 | |||
1757 | diff --git a/block/vvfat.c b/block/vvfat.c | ||
1758 | index XXXXXXX..XXXXXXX 100644 | ||
1759 | --- a/block/vvfat.c | ||
1760 | +++ b/block/vvfat.c | ||
1761 | @@ -XXX,XX +XXX,XX @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, | ||
1762 | DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64 | ||
1763 | " allocated\n", sector_num, | ||
1764 | n >> BDRV_SECTOR_BITS)); | ||
1765 | - if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, | ||
1766 | - buf + i * 0x200, n, 0) < 0) { | ||
1767 | + if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, n, | ||
1768 | + buf + i * 0x200, 0) < 0) { | ||
1769 | return -1; | ||
1770 | } | ||
1771 | i += (n >> BDRV_SECTOR_BITS) - 1; | ||
1772 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, | ||
1773 | return -1; | ||
1774 | } | ||
1775 | res = bdrv_pwrite(s->qcow, offset * BDRV_SECTOR_SIZE, | ||
1776 | - s->cluster_buffer, BDRV_SECTOR_SIZE, | ||
1777 | + BDRV_SECTOR_SIZE, s->cluster_buffer, | ||
1778 | 0); | ||
1779 | if (res < 0) { | ||
1780 | return -2; | ||
1781 | @@ -XXX,XX +XXX,XX @@ DLOG(checkpoint()); | ||
1782 | * Use qcow backend. Commit later. | ||
1783 | */ | ||
1784 | DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors)); | ||
1785 | - ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, buf, | ||
1786 | - nb_sectors * BDRV_SECTOR_SIZE, 0); | ||
1787 | + ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, | ||
1788 | + nb_sectors * BDRV_SECTOR_SIZE, buf, 0); | ||
1789 | if (ret < 0) { | ||
1790 | fprintf(stderr, "Error writing to qcow backend\n"); | ||
1791 | return ret; | ||
1792 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
1793 | index XXXXXXX..XXXXXXX 100644 | ||
1794 | --- a/tests/unit/test-block-iothread.c | ||
1795 | +++ b/tests/unit/test-block-iothread.c | ||
1796 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pread(BdrvChild *c) | ||
1797 | int ret; | ||
1798 | |||
1799 | /* Success */ | ||
1800 | - ret = bdrv_pread(c, 0, buf, sizeof(buf), 0); | ||
1801 | + ret = bdrv_pread(c, 0, sizeof(buf), buf, 0); | ||
1802 | g_assert_cmpint(ret, ==, 512); | ||
1803 | |||
1804 | /* Early error: Negative offset */ | ||
1805 | - ret = bdrv_pread(c, -2, buf, sizeof(buf), 0); | ||
1806 | + ret = bdrv_pread(c, -2, sizeof(buf), buf, 0); | ||
1807 | g_assert_cmpint(ret, ==, -EIO); | ||
1808 | } | ||
1809 | |||
1810 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pwrite(BdrvChild *c) | ||
1811 | int ret; | ||
1812 | |||
1813 | /* Success */ | ||
1814 | - ret = bdrv_pwrite(c, 0, buf, sizeof(buf), 0); | ||
1815 | + ret = bdrv_pwrite(c, 0, sizeof(buf), buf, 0); | ||
1816 | g_assert_cmpint(ret, ==, 512); | ||
1817 | |||
1818 | /* Early error: Negative offset */ | ||
1819 | - ret = bdrv_pwrite(c, -2, buf, sizeof(buf), 0); | ||
1820 | + ret = bdrv_pwrite(c, -2, sizeof(buf), buf, 0); | ||
1821 | g_assert_cmpint(ret, ==, -EIO); | ||
1822 | } | ||
1823 | |||
86 | -- | 1824 | -- |
87 | 2.13.5 | 1825 | 2.35.3 |
88 | |||
89 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Alberto Faria <afaria@redhat.com> | |
2 | |||
3 | They currently return the value of their 'bytes' parameter on success. | ||
4 | |||
5 | Make them return 0 instead, for consistency with other I/O functions and | ||
6 | in preparation to implement them using generated_co_wrapper. This also | ||
7 | makes it clear that short reads/writes are not possible. | ||
8 | |||
9 | The few callers that rely on the previous behavior are adjusted | ||
10 | accordingly by hand. | ||
11 | |||
12 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
13 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Message-Id: <20220609152744.3891847-4-afaria@redhat.com> | ||
16 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
17 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
18 | --- | ||
19 | block/cloop.c | 2 +- | ||
20 | block/crypto.c | 4 ++-- | ||
21 | block/dmg.c | 10 +++++----- | ||
22 | block/io.c | 10 ++-------- | ||
23 | block/qcow.c | 2 +- | ||
24 | block/qcow2.c | 4 ++-- | ||
25 | block/qed.c | 7 +------ | ||
26 | block/vdi.c | 2 +- | ||
27 | block/vmdk.c | 5 ++--- | ||
28 | tests/unit/test-block-iothread.c | 4 ++-- | ||
29 | 10 files changed, 19 insertions(+), 31 deletions(-) | ||
30 | |||
31 | diff --git a/block/cloop.c b/block/cloop.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block/cloop.c | ||
34 | +++ b/block/cloop.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num) | ||
36 | |||
37 | ret = bdrv_pread(bs->file, s->offsets[block_num], bytes, | ||
38 | s->compressed_block, 0); | ||
39 | - if (ret != bytes) { | ||
40 | + if (ret < 0) { | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | diff --git a/block/crypto.c b/block/crypto.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/block/crypto.c | ||
47 | +++ b/block/crypto.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, | ||
49 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
50 | return ret; | ||
51 | } | ||
52 | - return ret; | ||
53 | + return buflen; | ||
54 | } | ||
55 | |||
56 | static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
57 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
58 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
59 | return ret; | ||
60 | } | ||
61 | - return ret; | ||
62 | + return buflen; | ||
63 | } | ||
64 | |||
65 | |||
66 | diff --git a/block/dmg.c b/block/dmg.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/block/dmg.c | ||
69 | +++ b/block/dmg.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static int dmg_read_plist_xml(BlockDriverState *bs, DmgHeaderState *ds, | ||
71 | buffer = g_malloc(info_length + 1); | ||
72 | buffer[info_length] = '\0'; | ||
73 | ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0); | ||
74 | - if (ret != info_length) { | ||
75 | + if (ret < 0) { | ||
76 | ret = -EINVAL; | ||
77 | goto fail; | ||
78 | } | ||
79 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
80 | * inflated. */ | ||
81 | ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
82 | s->compressed_chunk, 0); | ||
83 | - if (ret != s->lengths[chunk]) { | ||
84 | + if (ret < 0) { | ||
85 | return -1; | ||
86 | } | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
89 | * inflated. */ | ||
90 | ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
91 | s->compressed_chunk, 0); | ||
92 | - if (ret != s->lengths[chunk]) { | ||
93 | + if (ret < 0) { | ||
94 | return -1; | ||
95 | } | ||
96 | |||
97 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
98 | * inflated. */ | ||
99 | ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
100 | s->compressed_chunk, 0); | ||
101 | - if (ret != s->lengths[chunk]) { | ||
102 | + if (ret < 0) { | ||
103 | return -1; | ||
104 | } | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) | ||
107 | case UDRW: /* copy */ | ||
108 | ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], | ||
109 | s->uncompressed_chunk, 0); | ||
110 | - if (ret != s->lengths[chunk]) { | ||
111 | + if (ret < 0) { | ||
112 | return -1; | ||
113 | } | ||
114 | break; | ||
115 | diff --git a/block/io.c b/block/io.c | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/block/io.c | ||
118 | +++ b/block/io.c | ||
119 | @@ -XXX,XX +XXX,XX @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) | ||
120 | int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, | ||
121 | BdrvRequestFlags flags) | ||
122 | { | ||
123 | - int ret; | ||
124 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
125 | IO_CODE(); | ||
126 | |||
127 | @@ -XXX,XX +XXX,XX @@ int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, | ||
128 | return -EINVAL; | ||
129 | } | ||
130 | |||
131 | - ret = bdrv_preadv(child, offset, bytes, &qiov, flags); | ||
132 | - | ||
133 | - return ret < 0 ? ret : bytes; | ||
134 | + return bdrv_preadv(child, offset, bytes, &qiov, flags); | ||
135 | } | ||
136 | |||
137 | /* Return no. of bytes on success or < 0 on error. Important errors are: | ||
138 | @@ -XXX,XX +XXX,XX @@ int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, | ||
139 | int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, | ||
140 | const void *buf, BdrvRequestFlags flags) | ||
141 | { | ||
142 | - int ret; | ||
143 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
144 | IO_CODE(); | ||
145 | |||
146 | @@ -XXX,XX +XXX,XX @@ int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, | ||
147 | return -EINVAL; | ||
148 | } | ||
149 | |||
150 | - ret = bdrv_pwritev(child, offset, bytes, &qiov, flags); | ||
151 | - | ||
152 | - return ret < 0 ? ret : bytes; | ||
153 | + return bdrv_pwritev(child, offset, bytes, &qiov, flags); | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | diff --git a/block/qcow.c b/block/qcow.c | ||
158 | index XXXXXXX..XXXXXXX 100644 | ||
159 | --- a/block/qcow.c | ||
160 | +++ b/block/qcow.c | ||
161 | @@ -XXX,XX +XXX,XX @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) | ||
162 | csize &= (s->cluster_size - 1); | ||
163 | BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); | ||
164 | ret = bdrv_pread(bs->file, coffset, csize, s->cluster_data, 0); | ||
165 | - if (ret != csize) | ||
166 | + if (ret < 0) | ||
167 | return -1; | ||
168 | if (decompress_buffer(s->cluster_cache, s->cluster_size, | ||
169 | s->cluster_data, csize) < 0) { | ||
170 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/block/qcow2.c | ||
173 | +++ b/block/qcow2.c | ||
174 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, | ||
175 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
176 | return -1; | ||
177 | } | ||
178 | - return ret; | ||
179 | + return buflen; | ||
180 | } | ||
181 | |||
182 | |||
183 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, | ||
184 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
185 | return -1; | ||
186 | } | ||
187 | - return ret; | ||
188 | + return buflen; | ||
189 | } | ||
190 | |||
191 | static QDict* | ||
192 | diff --git a/block/qed.c b/block/qed.c | ||
193 | index XXXXXXX..XXXXXXX 100644 | ||
194 | --- a/block/qed.c | ||
195 | +++ b/block/qed.c | ||
196 | @@ -XXX,XX +XXX,XX @@ static void qed_header_cpu_to_le(const QEDHeader *cpu, QEDHeader *le) | ||
197 | int qed_write_header_sync(BDRVQEDState *s) | ||
198 | { | ||
199 | QEDHeader le; | ||
200 | - int ret; | ||
201 | |||
202 | qed_header_cpu_to_le(&s->header, &le); | ||
203 | - ret = bdrv_pwrite(s->bs->file, 0, sizeof(le), &le, 0); | ||
204 | - if (ret != sizeof(le)) { | ||
205 | - return ret; | ||
206 | - } | ||
207 | - return 0; | ||
208 | + return bdrv_pwrite(s->bs->file, 0, sizeof(le), &le, 0); | ||
209 | } | ||
210 | |||
211 | /** | ||
212 | diff --git a/block/vdi.c b/block/vdi.c | ||
213 | index XXXXXXX..XXXXXXX 100644 | ||
214 | --- a/block/vdi.c | ||
215 | +++ b/block/vdi.c | ||
216 | @@ -XXX,XX +XXX,XX @@ nonallocating_write: | ||
217 | n_sectors * SECTOR_SIZE, base, 0); | ||
218 | } | ||
219 | |||
220 | - return ret < 0 ? ret : 0; | ||
221 | + return ret; | ||
222 | } | ||
223 | |||
224 | static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | ||
225 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
226 | index XXXXXXX..XXXXXXX 100644 | ||
227 | --- a/block/vmdk.c | ||
228 | +++ b/block/vmdk.c | ||
229 | @@ -XXX,XX +XXX,XX @@ static int vmdk_parent_open(BlockDriverState *bs) | ||
230 | if (ret < 0) { | ||
231 | goto out; | ||
232 | } | ||
233 | - ret = 0; | ||
234 | |||
235 | p_name = strstr(desc, "parentFileNameHint"); | ||
236 | if (p_name != NULL) { | ||
237 | @@ -XXX,XX +XXX,XX @@ static char *vmdk_read_desc(BdrvChild *file, uint64_t desc_offset, Error **errp) | ||
238 | g_free(buf); | ||
239 | return NULL; | ||
240 | } | ||
241 | - buf[ret] = 0; | ||
242 | + buf[size] = 0; | ||
243 | |||
244 | return buf; | ||
245 | } | ||
246 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
247 | l2_size_bytes, | ||
248 | l2_table, | ||
249 | 0 | ||
250 | - ) != l2_size_bytes) { | ||
251 | + ) < 0) { | ||
252 | return VMDK_ERROR; | ||
253 | } | ||
254 | |||
255 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
256 | index XXXXXXX..XXXXXXX 100644 | ||
257 | --- a/tests/unit/test-block-iothread.c | ||
258 | +++ b/tests/unit/test-block-iothread.c | ||
259 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pread(BdrvChild *c) | ||
260 | |||
261 | /* Success */ | ||
262 | ret = bdrv_pread(c, 0, sizeof(buf), buf, 0); | ||
263 | - g_assert_cmpint(ret, ==, 512); | ||
264 | + g_assert_cmpint(ret, ==, 0); | ||
265 | |||
266 | /* Early error: Negative offset */ | ||
267 | ret = bdrv_pread(c, -2, sizeof(buf), buf, 0); | ||
268 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_pwrite(BdrvChild *c) | ||
269 | |||
270 | /* Success */ | ||
271 | ret = bdrv_pwrite(c, 0, sizeof(buf), buf, 0); | ||
272 | - g_assert_cmpint(ret, ==, 512); | ||
273 | + g_assert_cmpint(ret, ==, 0); | ||
274 | |||
275 | /* Early error: Negative offset */ | ||
276 | ret = bdrv_pwrite(c, -2, sizeof(buf), buf, 0); | ||
277 | -- | ||
278 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | They currently return the value of their headerlen/buflen parameter on | ||
4 | success. Returning 0 instead makes it clear that short reads/writes are | ||
5 | not possible. | ||
6 | |||
7 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Message-Id: <20220609152744.3891847-5-afaria@redhat.com> | ||
11 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | ||
14 | include/crypto/block.h | 32 ++++++++++----------- | ||
15 | block/crypto.c | 52 +++++++++++++++++----------------- | ||
16 | block/qcow2.c | 22 +++++++------- | ||
17 | crypto/block-luks.c | 8 +++--- | ||
18 | crypto/block.c | 6 ++-- | ||
19 | tests/unit/test-crypto-block.c | 38 ++++++++++++------------- | ||
20 | 6 files changed, 79 insertions(+), 79 deletions(-) | ||
21 | |||
22 | diff --git a/include/crypto/block.h b/include/crypto/block.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/include/crypto/block.h | ||
25 | +++ b/include/crypto/block.h | ||
26 | @@ -XXX,XX +XXX,XX @@ typedef struct QCryptoBlock QCryptoBlock; | ||
27 | /* See also QCryptoBlockFormat, QCryptoBlockCreateOptions | ||
28 | * and QCryptoBlockOpenOptions in qapi/crypto.json */ | ||
29 | |||
30 | -typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block, | ||
31 | - size_t offset, | ||
32 | - uint8_t *buf, | ||
33 | - size_t buflen, | ||
34 | - void *opaque, | ||
35 | - Error **errp); | ||
36 | +typedef int (*QCryptoBlockReadFunc)(QCryptoBlock *block, | ||
37 | + size_t offset, | ||
38 | + uint8_t *buf, | ||
39 | + size_t buflen, | ||
40 | + void *opaque, | ||
41 | + Error **errp); | ||
42 | |||
43 | -typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block, | ||
44 | - size_t headerlen, | ||
45 | - void *opaque, | ||
46 | - Error **errp); | ||
47 | +typedef int (*QCryptoBlockInitFunc)(QCryptoBlock *block, | ||
48 | + size_t headerlen, | ||
49 | + void *opaque, | ||
50 | + Error **errp); | ||
51 | |||
52 | -typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block, | ||
53 | - size_t offset, | ||
54 | - const uint8_t *buf, | ||
55 | - size_t buflen, | ||
56 | - void *opaque, | ||
57 | - Error **errp); | ||
58 | +typedef int (*QCryptoBlockWriteFunc)(QCryptoBlock *block, | ||
59 | + size_t offset, | ||
60 | + const uint8_t *buf, | ||
61 | + size_t buflen, | ||
62 | + void *opaque, | ||
63 | + Error **errp); | ||
64 | |||
65 | /** | ||
66 | * qcrypto_block_has_format: | ||
67 | diff --git a/block/crypto.c b/block/crypto.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/block/crypto.c | ||
70 | +++ b/block/crypto.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, | ||
72 | } | ||
73 | |||
74 | |||
75 | -static ssize_t block_crypto_read_func(QCryptoBlock *block, | ||
76 | - size_t offset, | ||
77 | - uint8_t *buf, | ||
78 | - size_t buflen, | ||
79 | - void *opaque, | ||
80 | - Error **errp) | ||
81 | +static int block_crypto_read_func(QCryptoBlock *block, | ||
82 | + size_t offset, | ||
83 | + uint8_t *buf, | ||
84 | + size_t buflen, | ||
85 | + void *opaque, | ||
86 | + Error **errp) | ||
87 | { | ||
88 | BlockDriverState *bs = opaque; | ||
89 | ssize_t ret; | ||
90 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, | ||
91 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
92 | return ret; | ||
93 | } | ||
94 | - return buflen; | ||
95 | + return 0; | ||
96 | } | ||
97 | |||
98 | -static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
99 | - size_t offset, | ||
100 | - const uint8_t *buf, | ||
101 | - size_t buflen, | ||
102 | - void *opaque, | ||
103 | - Error **errp) | ||
104 | +static int block_crypto_write_func(QCryptoBlock *block, | ||
105 | + size_t offset, | ||
106 | + const uint8_t *buf, | ||
107 | + size_t buflen, | ||
108 | + void *opaque, | ||
109 | + Error **errp) | ||
110 | { | ||
111 | BlockDriverState *bs = opaque; | ||
112 | ssize_t ret; | ||
113 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_write_func(QCryptoBlock *block, | ||
114 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
115 | return ret; | ||
116 | } | ||
117 | - return buflen; | ||
118 | + return 0; | ||
119 | } | ||
120 | |||
121 | |||
122 | @@ -XXX,XX +XXX,XX @@ struct BlockCryptoCreateData { | ||
123 | }; | ||
124 | |||
125 | |||
126 | -static ssize_t block_crypto_create_write_func(QCryptoBlock *block, | ||
127 | - size_t offset, | ||
128 | - const uint8_t *buf, | ||
129 | - size_t buflen, | ||
130 | - void *opaque, | ||
131 | - Error **errp) | ||
132 | +static int block_crypto_create_write_func(QCryptoBlock *block, | ||
133 | + size_t offset, | ||
134 | + const uint8_t *buf, | ||
135 | + size_t buflen, | ||
136 | + void *opaque, | ||
137 | + Error **errp) | ||
138 | { | ||
139 | struct BlockCryptoCreateData *data = opaque; | ||
140 | ssize_t ret; | ||
141 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_create_write_func(QCryptoBlock *block, | ||
142 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
143 | return ret; | ||
144 | } | ||
145 | - return ret; | ||
146 | + return 0; | ||
147 | } | ||
148 | |||
149 | -static ssize_t block_crypto_create_init_func(QCryptoBlock *block, | ||
150 | - size_t headerlen, | ||
151 | - void *opaque, | ||
152 | - Error **errp) | ||
153 | +static int block_crypto_create_init_func(QCryptoBlock *block, | ||
154 | + size_t headerlen, | ||
155 | + void *opaque, | ||
156 | + Error **errp) | ||
157 | { | ||
158 | struct BlockCryptoCreateData *data = opaque; | ||
159 | Error *local_error = NULL; | ||
160 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_create_init_func(QCryptoBlock *block, | ||
161 | data->prealloc, 0, &local_error); | ||
162 | |||
163 | if (ret >= 0) { | ||
164 | - return ret; | ||
165 | + return 0; | ||
166 | } | ||
167 | |||
168 | error: | ||
169 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
170 | index XXXXXXX..XXXXXXX 100644 | ||
171 | --- a/block/qcow2.c | ||
172 | +++ b/block/qcow2.c | ||
173 | @@ -XXX,XX +XXX,XX @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename) | ||
174 | } | ||
175 | |||
176 | |||
177 | -static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, | ||
178 | - uint8_t *buf, size_t buflen, | ||
179 | - void *opaque, Error **errp) | ||
180 | +static int qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, | ||
181 | + uint8_t *buf, size_t buflen, | ||
182 | + void *opaque, Error **errp) | ||
183 | { | ||
184 | BlockDriverState *bs = opaque; | ||
185 | BDRVQcow2State *s = bs->opaque; | ||
186 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset, | ||
187 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
188 | return -1; | ||
189 | } | ||
190 | - return buflen; | ||
191 | + return 0; | ||
192 | } | ||
193 | |||
194 | |||
195 | -static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen, | ||
196 | - void *opaque, Error **errp) | ||
197 | +static int qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen, | ||
198 | + void *opaque, Error **errp) | ||
199 | { | ||
200 | BlockDriverState *bs = opaque; | ||
201 | BDRVQcow2State *s = bs->opaque; | ||
202 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen, | ||
203 | return -1; | ||
204 | } | ||
205 | |||
206 | - return ret; | ||
207 | + return 0; | ||
208 | } | ||
209 | |||
210 | |||
211 | -static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, | ||
212 | - const uint8_t *buf, size_t buflen, | ||
213 | - void *opaque, Error **errp) | ||
214 | +static int qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, | ||
215 | + const uint8_t *buf, size_t buflen, | ||
216 | + void *opaque, Error **errp) | ||
217 | { | ||
218 | BlockDriverState *bs = opaque; | ||
219 | BDRVQcow2State *s = bs->opaque; | ||
220 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset, | ||
221 | error_setg_errno(errp, -ret, "Could not read encryption header"); | ||
222 | return -1; | ||
223 | } | ||
224 | - return buflen; | ||
225 | + return 0; | ||
226 | } | ||
227 | |||
228 | static QDict* | ||
229 | diff --git a/crypto/block-luks.c b/crypto/block-luks.c | ||
230 | index XXXXXXX..XXXXXXX 100644 | ||
231 | --- a/crypto/block-luks.c | ||
232 | +++ b/crypto/block-luks.c | ||
233 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_load_header(QCryptoBlock *block, | ||
234 | void *opaque, | ||
235 | Error **errp) | ||
236 | { | ||
237 | - ssize_t rv; | ||
238 | + int rv; | ||
239 | size_t i; | ||
240 | QCryptoBlockLUKS *luks = block->opaque; | ||
241 | |||
242 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_store_key(QCryptoBlock *block, | ||
243 | QCRYPTO_BLOCK_LUKS_SECTOR_SIZE, | ||
244 | splitkey, splitkeylen, | ||
245 | opaque, | ||
246 | - errp) != splitkeylen) { | ||
247 | + errp) < 0) { | ||
248 | goto cleanup; | ||
249 | } | ||
250 | |||
251 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_load_key(QCryptoBlock *block, | ||
252 | g_autofree uint8_t *splitkey = NULL; | ||
253 | size_t splitkeylen; | ||
254 | g_autofree uint8_t *possiblekey = NULL; | ||
255 | - ssize_t rv; | ||
256 | + int rv; | ||
257 | g_autoptr(QCryptoCipher) cipher = NULL; | ||
258 | uint8_t keydigest[QCRYPTO_BLOCK_LUKS_DIGEST_LEN]; | ||
259 | g_autoptr(QCryptoIVGen) ivgen = NULL; | ||
260 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_erase_key(QCryptoBlock *block, | ||
261 | garbagesplitkey, | ||
262 | splitkeylen, | ||
263 | opaque, | ||
264 | - &local_err) != splitkeylen) { | ||
265 | + &local_err) < 0) { | ||
266 | error_propagate(errp, local_err); | ||
267 | return -1; | ||
268 | } | ||
269 | diff --git a/crypto/block.c b/crypto/block.c | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/crypto/block.c | ||
272 | +++ b/crypto/block.c | ||
273 | @@ -XXX,XX +XXX,XX @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options, | ||
274 | } | ||
275 | |||
276 | |||
277 | -static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block, | ||
278 | +static int qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block, | ||
279 | size_t headerlen, void *opaque, Error **errp) | ||
280 | { | ||
281 | size_t *headerlenp = opaque; | ||
282 | @@ -XXX,XX +XXX,XX @@ static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block, | ||
283 | } | ||
284 | |||
285 | |||
286 | -static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block, | ||
287 | +static int qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block, | ||
288 | size_t offset, const uint8_t *buf, size_t buflen, | ||
289 | void *opaque, Error **errp) | ||
290 | { | ||
291 | /* Discard the bytes, we're not actually writing to an image */ | ||
292 | - return buflen; | ||
293 | + return 0; | ||
294 | } | ||
295 | |||
296 | |||
297 | diff --git a/tests/unit/test-crypto-block.c b/tests/unit/test-crypto-block.c | ||
298 | index XXXXXXX..XXXXXXX 100644 | ||
299 | --- a/tests/unit/test-crypto-block.c | ||
300 | +++ b/tests/unit/test-crypto-block.c | ||
301 | @@ -XXX,XX +XXX,XX @@ static struct QCryptoBlockTestData { | ||
302 | }; | ||
303 | |||
304 | |||
305 | -static ssize_t test_block_read_func(QCryptoBlock *block, | ||
306 | - size_t offset, | ||
307 | - uint8_t *buf, | ||
308 | - size_t buflen, | ||
309 | - void *opaque, | ||
310 | - Error **errp) | ||
311 | +static int test_block_read_func(QCryptoBlock *block, | ||
312 | + size_t offset, | ||
313 | + uint8_t *buf, | ||
314 | + size_t buflen, | ||
315 | + void *opaque, | ||
316 | + Error **errp) | ||
317 | { | ||
318 | Buffer *header = opaque; | ||
319 | |||
320 | @@ -XXX,XX +XXX,XX @@ static ssize_t test_block_read_func(QCryptoBlock *block, | ||
321 | |||
322 | memcpy(buf, header->buffer + offset, buflen); | ||
323 | |||
324 | - return buflen; | ||
325 | + return 0; | ||
326 | } | ||
327 | |||
328 | |||
329 | -static ssize_t test_block_init_func(QCryptoBlock *block, | ||
330 | - size_t headerlen, | ||
331 | - void *opaque, | ||
332 | - Error **errp) | ||
333 | +static int test_block_init_func(QCryptoBlock *block, | ||
334 | + size_t headerlen, | ||
335 | + void *opaque, | ||
336 | + Error **errp) | ||
337 | { | ||
338 | Buffer *header = opaque; | ||
339 | |||
340 | @@ -XXX,XX +XXX,XX @@ static ssize_t test_block_init_func(QCryptoBlock *block, | ||
341 | |||
342 | buffer_reserve(header, headerlen); | ||
343 | |||
344 | - return headerlen; | ||
345 | + return 0; | ||
346 | } | ||
347 | |||
348 | |||
349 | -static ssize_t test_block_write_func(QCryptoBlock *block, | ||
350 | - size_t offset, | ||
351 | - const uint8_t *buf, | ||
352 | - size_t buflen, | ||
353 | - void *opaque, | ||
354 | - Error **errp) | ||
355 | +static int test_block_write_func(QCryptoBlock *block, | ||
356 | + size_t offset, | ||
357 | + const uint8_t *buf, | ||
358 | + size_t buflen, | ||
359 | + void *opaque, | ||
360 | + Error **errp) | ||
361 | { | ||
362 | Buffer *header = opaque; | ||
363 | |||
364 | @@ -XXX,XX +XXX,XX @@ static ssize_t test_block_write_func(QCryptoBlock *block, | ||
365 | memcpy(header->buffer + offset, buf, buflen); | ||
366 | header->offset = offset + buflen; | ||
367 | |||
368 | - return buflen; | ||
369 | + return 0; | ||
370 | } | ||
371 | |||
372 | |||
373 | -- | ||
374 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | It does not mutate the buffer. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | Message-Id: <20220609152744.3891847-6-afaria@redhat.com> | ||
9 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | include/block/block_int-io.h | 2 +- | ||
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/block/block_int-io.h | ||
18 | +++ b/include/block/block_int-io.h | ||
19 | @@ -XXX,XX +XXX,XX @@ static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, | ||
20 | } | ||
21 | |||
22 | static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, | ||
23 | - int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags) | ||
24 | + int64_t offset, unsigned int bytes, const void *buf, BdrvRequestFlags flags) | ||
25 | { | ||
26 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
27 | IO_CODE(); | ||
28 | -- | ||
29 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | For consistency with other I/O functions, and in preparation to | ||
4 | implement bdrv_{pread,pwrite}() using generated_co_wrapper. | ||
5 | |||
6 | unsigned int fits in int64_t, so all callers remain correct. | ||
7 | |||
8 | bdrv_check_request32() is called further down the stack and causes -EIO | ||
9 | to be returned if 'bytes' is negative or greater than | ||
10 | BDRV_REQUEST_MAX_BYTES, which in turns never exceeds SIZE_MAX. | ||
11 | |||
12 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
13 | Message-Id: <20220609152744.3891847-7-afaria@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
17 | --- | ||
18 | block/coroutines.h | 4 ++-- | ||
19 | include/block/block_int-io.h | 4 ++-- | ||
20 | 2 files changed, 4 insertions(+), 4 deletions(-) | ||
21 | |||
22 | diff --git a/block/coroutines.h b/block/coroutines.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block/coroutines.h | ||
25 | +++ b/block/coroutines.h | ||
26 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_do_flush(BlockBackend *blk); | ||
27 | */ | ||
28 | |||
29 | int generated_co_wrapper | ||
30 | -bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes, | ||
31 | +bdrv_preadv(BdrvChild *child, int64_t offset, int64_t bytes, | ||
32 | QEMUIOVector *qiov, BdrvRequestFlags flags); | ||
33 | |||
34 | int generated_co_wrapper | ||
35 | -bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, | ||
36 | +bdrv_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, | ||
37 | QEMUIOVector *qiov, BdrvRequestFlags flags); | ||
38 | |||
39 | int generated_co_wrapper | ||
40 | diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/include/block/block_int-io.h | ||
43 | +++ b/include/block/block_int-io.h | ||
44 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, | ||
45 | QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); | ||
46 | |||
47 | static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, | ||
48 | - int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags) | ||
49 | + int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags) | ||
50 | { | ||
51 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
52 | IO_CODE(); | ||
53 | @@ -XXX,XX +XXX,XX @@ static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, | ||
54 | } | ||
55 | |||
56 | static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, | ||
57 | - int64_t offset, unsigned int bytes, const void *buf, BdrvRequestFlags flags) | ||
58 | + int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags) | ||
59 | { | ||
60 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
61 | IO_CODE(); | ||
62 | -- | ||
63 | 2.35.3 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Both the throttling limits set with the throttling.iops-* and | 3 | bdrv_{pread,pwrite}() now return -EIO instead of -EINVAL when 'bytes' is |
4 | throttling.bps-* options and their QMP equivalents defined in the | 4 | negative, making them consistent with bdrv_{preadv,pwritev}() and |
5 | BlockIOThrottle struct are integer values. | 5 | bdrv_co_{pread,pwrite,preadv,pwritev}(). |
6 | 6 | ||
7 | Those limits are also reported in the BlockDeviceInfo struct and they | 7 | bdrv_pwrite_zeroes() now also calls trace_bdrv_co_pwrite_zeroes() and |
8 | are integers there as well. | 8 | clears the BDRV_REQ_MAY_UNMAP flag when appropriate, which it didn't |
9 | previously. | ||
9 | 10 | ||
10 | Therefore there's no reason to store them internally as double and do | 11 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
11 | the conversion everytime we're setting or querying them, so this patch | 12 | Message-Id: <20220609152744.3891847-8-afaria@redhat.com> |
12 | uses uint64_t for those types. Let's also use an unsigned type because | 13 | Reviewed-by: Eric Blake <eblake@redhat.com> |
13 | we don't allow negative values anyway. | 14 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
15 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | --- | ||
17 | include/block/block-io.h | 15 +++++++++------ | ||
18 | block/io.c | 41 ---------------------------------------- | ||
19 | 2 files changed, 9 insertions(+), 47 deletions(-) | ||
14 | 20 | ||
15 | LeakyBucket.level and LeakyBucket.burst_level do however remain double | 21 | diff --git a/include/block/block-io.h b/include/block/block-io.h |
16 | because their value changes depending on the fraction of time elapsed | ||
17 | since the previous I/O operation. | ||
18 | |||
19 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
20 | Message-id: f29b840422767b5be2c41c2dfdbbbf6c5f8fedf8.1503580370.git.berto@igalia.com | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | --- | ||
23 | include/qemu/throttle.h | 4 ++-- | ||
24 | tests/test-throttle.c | 3 ++- | ||
25 | util/throttle.c | 7 +++---- | ||
26 | 3 files changed, 7 insertions(+), 7 deletions(-) | ||
27 | |||
28 | diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/include/qemu/throttle.h | 23 | --- a/include/block/block-io.h |
31 | +++ b/include/qemu/throttle.h | 24 | +++ b/include/block/block-io.h |
32 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 25 | @@ -XXX,XX +XXX,XX @@ |
26 | * to catch when they are accidentally called by the wrong API. | ||
33 | */ | 27 | */ |
34 | 28 | ||
35 | typedef struct LeakyBucket { | 29 | -int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, |
36 | - double avg; /* average goal in units per second */ | 30 | - int64_t bytes, BdrvRequestFlags flags); |
37 | - double max; /* leaky bucket max burst in units */ | 31 | +int generated_co_wrapper bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, |
38 | + uint64_t avg; /* average goal in units per second */ | 32 | + int64_t bytes, |
39 | + uint64_t max; /* leaky bucket max burst in units */ | 33 | + BdrvRequestFlags flags); |
40 | double level; /* bucket level in units */ | 34 | int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); |
41 | double burst_level; /* bucket level in units (for computing bursts) */ | 35 | -int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, |
42 | unsigned burst_length; /* max length of the burst period, in seconds */ | 36 | - BdrvRequestFlags flags); |
43 | diff --git a/tests/test-throttle.c b/tests/test-throttle.c | 37 | -int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, |
38 | - const void *buf, BdrvRequestFlags flags); | ||
39 | +int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset, | ||
40 | + int64_t bytes, void *buf, | ||
41 | + BdrvRequestFlags flags); | ||
42 | +int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset, | ||
43 | + int64_t bytes, const void *buf, | ||
44 | + BdrvRequestFlags flags); | ||
45 | int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, | ||
46 | const void *buf, BdrvRequestFlags flags); | ||
47 | /* | ||
48 | diff --git a/block/io.c b/block/io.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/tests/test-throttle.c | 50 | --- a/block/io.c |
46 | +++ b/tests/test-throttle.c | 51 | +++ b/block/io.c |
47 | @@ -XXX,XX +XXX,XX @@ static void test_enabled(void) | 52 | @@ -XXX,XX +XXX,XX @@ static int bdrv_check_request32(int64_t offset, int64_t bytes, |
48 | for (i = 0; i < BUCKETS_COUNT; i++) { | 53 | return 0; |
49 | throttle_config_init(&cfg); | 54 | } |
50 | set_cfg_value(false, i, 150); | 55 | |
51 | + g_assert(throttle_is_valid(&cfg, NULL)); | 56 | -int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, |
52 | g_assert(throttle_enabled(&cfg)); | 57 | - int64_t bytes, BdrvRequestFlags flags) |
53 | } | 58 | -{ |
54 | 59 | - IO_CODE(); | |
55 | for (i = 0; i < BUCKETS_COUNT; i++) { | 60 | - return bdrv_pwritev(child, offset, bytes, NULL, |
56 | throttle_config_init(&cfg); | 61 | - BDRV_REQ_ZERO_WRITE | flags); |
57 | set_cfg_value(false, i, -150); | 62 | -} |
58 | - g_assert(!throttle_enabled(&cfg)); | 63 | - |
59 | + g_assert(!throttle_is_valid(&cfg, NULL)); | 64 | /* |
65 | * Completely zero out a block device with the help of bdrv_pwrite_zeroes. | ||
66 | * The operation is sped up by checking the block status and only writing | ||
67 | @@ -XXX,XX +XXX,XX @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) | ||
60 | } | 68 | } |
61 | } | 69 | } |
62 | 70 | ||
63 | diff --git a/util/throttle.c b/util/throttle.c | 71 | -/* See bdrv_pwrite() for the return codes */ |
64 | index XXXXXXX..XXXXXXX 100644 | 72 | -int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, |
65 | --- a/util/throttle.c | 73 | - BdrvRequestFlags flags) |
66 | +++ b/util/throttle.c | 74 | -{ |
67 | @@ -XXX,XX +XXX,XX @@ int64_t throttle_compute_wait(LeakyBucket *bkt) | 75 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); |
68 | /* If bkt->max is 0 we still want to allow short bursts of I/O | 76 | - IO_CODE(); |
69 | * from the guest, otherwise every other request will be throttled | 77 | - |
70 | * and performance will suffer considerably. */ | 78 | - if (bytes < 0) { |
71 | - bucket_size = bkt->avg / 10; | 79 | - return -EINVAL; |
72 | + bucket_size = (double) bkt->avg / 10; | 80 | - } |
73 | burst_bucket_size = 0; | 81 | - |
74 | } else { | 82 | - return bdrv_preadv(child, offset, bytes, &qiov, flags); |
75 | /* If we have a burst limit then we have to wait until all I/O | 83 | -} |
76 | * at burst rate has finished before throttling to bkt->avg */ | 84 | - |
77 | bucket_size = bkt->max * bkt->burst_length; | 85 | -/* Return no. of bytes on success or < 0 on error. Important errors are: |
78 | - burst_bucket_size = bkt->max / 10; | 86 | - -EIO generic I/O error (may happen for all errors) |
79 | + burst_bucket_size = (double) bkt->max / 10; | 87 | - -ENOMEDIUM No media inserted. |
80 | } | 88 | - -EINVAL Invalid offset or number of bytes |
81 | 89 | - -EACCES Trying to write a read-only device | |
82 | /* If the main bucket is full then we have to wait */ | 90 | -*/ |
83 | @@ -XXX,XX +XXX,XX @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp) | 91 | -int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, |
84 | 92 | - const void *buf, BdrvRequestFlags flags) | |
85 | for (i = 0; i < BUCKETS_COUNT; i++) { | 93 | -{ |
86 | LeakyBucket *bkt = &cfg->buckets[i]; | 94 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); |
87 | - if (bkt->avg < 0 || bkt->max < 0 || | 95 | - IO_CODE(); |
88 | - bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) { | 96 | - |
89 | + if (bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) { | 97 | - if (bytes < 0) { |
90 | error_setg(errp, "bps/iops/max values must be within [0, %lld]", | 98 | - return -EINVAL; |
91 | THROTTLE_VALUE_MAX); | 99 | - } |
92 | return false; | 100 | - |
101 | - return bdrv_pwritev(child, offset, bytes, &qiov, flags); | ||
102 | -} | ||
103 | - | ||
104 | /* | ||
105 | * Writes to the file and ensures that no writes are reordered across this | ||
106 | * request (acts as a barrier) | ||
93 | -- | 107 | -- |
94 | 2.13.5 | 108 | 2.35.3 |
95 | |||
96 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Also convert bdrv_pwrite_sync() to being implemented using | ||
4 | generated_co_wrapper. | ||
5 | |||
6 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Message-Id: <20220609152744.3891847-9-afaria@redhat.com> | ||
10 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | ||
13 | include/block/block-io.h | 8 ++++++-- | ||
14 | block/io.c | 9 +++++---- | ||
15 | 2 files changed, 11 insertions(+), 6 deletions(-) | ||
16 | |||
17 | diff --git a/include/block/block-io.h b/include/block/block-io.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/block/block-io.h | ||
20 | +++ b/include/block/block-io.h | ||
21 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset, | ||
22 | int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset, | ||
23 | int64_t bytes, const void *buf, | ||
24 | BdrvRequestFlags flags); | ||
25 | -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, | ||
26 | - const void *buf, BdrvRequestFlags flags); | ||
27 | +int generated_co_wrapper bdrv_pwrite_sync(BdrvChild *child, int64_t offset, | ||
28 | + int64_t bytes, const void *buf, | ||
29 | + BdrvRequestFlags flags); | ||
30 | +int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, | ||
31 | + int64_t bytes, const void *buf, | ||
32 | + BdrvRequestFlags flags); | ||
33 | /* | ||
34 | * Efficiently zero a region of the disk image. Note that this is a regular | ||
35 | * I/O request like read or write and should have a reasonable size. This | ||
36 | diff --git a/block/io.c b/block/io.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block/io.c | ||
39 | +++ b/block/io.c | ||
40 | @@ -XXX,XX +XXX,XX @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) | ||
41 | * | ||
42 | * Returns 0 on success, -errno in error cases. | ||
43 | */ | ||
44 | -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, | ||
45 | - const void *buf, BdrvRequestFlags flags) | ||
46 | +int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, | ||
47 | + int64_t bytes, const void *buf, | ||
48 | + BdrvRequestFlags flags) | ||
49 | { | ||
50 | int ret; | ||
51 | IO_CODE(); | ||
52 | |||
53 | - ret = bdrv_pwrite(child, offset, bytes, buf, flags); | ||
54 | + ret = bdrv_co_pwrite(child, offset, bytes, buf, flags); | ||
55 | if (ret < 0) { | ||
56 | return ret; | ||
57 | } | ||
58 | |||
59 | - ret = bdrv_flush(child->bs); | ||
60 | + ret = bdrv_co_flush(child->bs); | ||
61 | if (ret < 0) { | ||
62 | return ret; | ||
63 | } | ||
64 | -- | ||
65 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Convert uses of bdrv_pwrite_sync() into bdrv_co_pwrite_sync() when the | ||
4 | callers are already coroutine_fn. | ||
5 | |||
6 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Message-Id: <20220609152744.3891847-10-afaria@redhat.com> | ||
10 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | ||
13 | block/parallels.c | 2 +- | ||
14 | block/qcow2-snapshot.c | 6 +++--- | ||
15 | block/qcow2.c | 4 ++-- | ||
16 | 3 files changed, 6 insertions(+), 6 deletions(-) | ||
17 | |||
18 | diff --git a/block/parallels.c b/block/parallels.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/parallels.c | ||
21 | +++ b/block/parallels.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, | ||
23 | |||
24 | ret = 0; | ||
25 | if (flush_bat) { | ||
26 | - ret = bdrv_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); | ||
27 | + ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); | ||
28 | if (ret < 0) { | ||
29 | res->check_errors++; | ||
30 | goto out; | ||
31 | diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/block/qcow2-snapshot.c | ||
34 | +++ b/block/qcow2-snapshot.c | ||
35 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, | ||
36 | assert(fix & BDRV_FIX_ERRORS); | ||
37 | |||
38 | snapshot_table_pointer.nb_snapshots = cpu_to_be32(s->nb_snapshots); | ||
39 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
40 | - sizeof(snapshot_table_pointer.nb_snapshots), | ||
41 | - &snapshot_table_pointer.nb_snapshots, 0); | ||
42 | + ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots), | ||
43 | + sizeof(snapshot_table_pointer.nb_snapshots), | ||
44 | + &snapshot_table_pointer.nb_snapshots, 0); | ||
45 | if (ret < 0) { | ||
46 | result->check_errors++; | ||
47 | fprintf(stderr, "ERROR failed to update the snapshot count in the " | ||
48 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/block/qcow2.c | ||
51 | +++ b/block/qcow2.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset, | ||
53 | |||
54 | /* write updated header.size */ | ||
55 | offset = cpu_to_be64(offset); | ||
56 | - ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), | ||
57 | - sizeof(offset), &offset, 0); | ||
58 | + ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, size), | ||
59 | + sizeof(offset), &offset, 0); | ||
60 | if (ret < 0) { | ||
61 | error_setg_errno(errp, -ret, "Failed to update the image size"); | ||
62 | goto fail; | ||
63 | -- | ||
64 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Use bdrv_pwrite_sync() instead of calling bdrv_pwrite() and bdrv_flush() | ||
4 | separately. | ||
5 | |||
6 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Message-Id: <20220609152744.3891847-11-afaria@redhat.com> | ||
10 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | ||
13 | block/qcow2.c | 9 +++------ | ||
14 | 1 file changed, 3 insertions(+), 6 deletions(-) | ||
15 | |||
16 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/qcow2.c | ||
19 | +++ b/block/qcow2.c | ||
20 | @@ -XXX,XX +XXX,XX @@ int qcow2_mark_dirty(BlockDriverState *bs) | ||
21 | } | ||
22 | |||
23 | val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); | ||
24 | - ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features), | ||
25 | - sizeof(val), &val, 0); | ||
26 | - if (ret < 0) { | ||
27 | - return ret; | ||
28 | - } | ||
29 | - ret = bdrv_flush(bs->file->bs); | ||
30 | + ret = bdrv_pwrite_sync(bs->file, | ||
31 | + offsetof(QCowHeader, incompatible_features), | ||
32 | + sizeof(val), &val, 0); | ||
33 | if (ret < 0) { | ||
34 | return ret; | ||
35 | } | ||
36 | -- | ||
37 | 2.35.3 | diff view generated by jsdifflib |
1 | From: Fred Rolland <rollandf@gmail.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Update doc with the usage of UUID for initiator name. | 3 | Fixes: 58a6fdcc |
4 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
5 | Tested-by: Daniel P. Berrangé <berrange@redhat.com> | ||
6 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
7 | Message-Id: <20220616142659.3184115-2-jsnow@redhat.com> | ||
8 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | tests/qemu-iotests/223.out | 4 ++-- | ||
12 | tests/qemu-iotests/307.out | 4 ++-- | ||
13 | 2 files changed, 4 insertions(+), 4 deletions(-) | ||
4 | 14 | ||
5 | Related-To: https://bugzilla.redhat.com/1006468 | 15 | diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out |
6 | Signed-off-by: Fred Rolland <frolland@redhat.com> | ||
7 | Message-id: 20170823084830.30500-1-frolland@redhat.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | qemu-doc.texi | 5 +++-- | ||
11 | 1 file changed, 3 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/qemu-doc.texi | 17 | --- a/tests/qemu-iotests/223.out |
16 | +++ b/qemu-doc.texi | 18 | +++ b/tests/qemu-iotests/223.out |
17 | @@ -XXX,XX +XXX,XX @@ in a configuration file provided via '-readconfig' or directly on the | 19 | @@ -XXX,XX +XXX,XX @@ exports available: 3 |
18 | command line. | 20 | export: 'n2' |
19 | 21 | description: some text | |
20 | If the initiator-name is not specified qemu will use a default name | 22 | size: 4194304 |
21 | -of 'iqn.2008-11.org.linux-kvm[:<name>'] where <name> is the name of the | 23 | - flags: 0xced ( flush fua trim zeroes df cache fast-zero ) |
22 | +of 'iqn.2008-11.org.linux-kvm[:<uuid>'] where <uuid> is the UUID of the | 24 | + flags: 0xded ( flush fua trim zeroes df multi cache fast-zero ) |
23 | +virtual machine. If the UUID is not specified qemu will use | 25 | min block: 1 |
24 | +'iqn.2008-11.org.linux-kvm[:<name>'] where <name> is the name of the | 26 | opt block: 4096 |
25 | virtual machine. | 27 | max block: 33554432 |
26 | 28 | @@ -XXX,XX +XXX,XX @@ exports available: 3 | |
27 | - | 29 | export: 'n2' |
28 | @example | 30 | description: some text |
29 | Setting a specific initiator name to use when logging in to the target | 31 | size: 4194304 |
30 | -iscsi initiator-name=iqn.qemu.test:my-initiator | 32 | - flags: 0xced ( flush fua trim zeroes df cache fast-zero ) |
33 | + flags: 0xded ( flush fua trim zeroes df multi cache fast-zero ) | ||
34 | min block: 1 | ||
35 | opt block: 4096 | ||
36 | max block: 33554432 | ||
37 | diff --git a/tests/qemu-iotests/307.out b/tests/qemu-iotests/307.out | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/tests/qemu-iotests/307.out | ||
40 | +++ b/tests/qemu-iotests/307.out | ||
41 | @@ -XXX,XX +XXX,XX @@ exports available: 2 | ||
42 | export: 'export1' | ||
43 | description: This is the writable second export | ||
44 | size: 67108864 | ||
45 | - flags: 0xced ( flush fua trim zeroes df cache fast-zero ) | ||
46 | + flags: 0xded ( flush fua trim zeroes df multi cache fast-zero ) | ||
47 | min block: XXX | ||
48 | opt block: XXX | ||
49 | max block: XXX | ||
50 | @@ -XXX,XX +XXX,XX @@ exports available: 1 | ||
51 | export: 'export1' | ||
52 | description: This is the writable second export | ||
53 | size: 67108864 | ||
54 | - flags: 0xced ( flush fua trim zeroes df cache fast-zero ) | ||
55 | + flags: 0xded ( flush fua trim zeroes df multi cache fast-zero ) | ||
56 | min block: XXX | ||
57 | opt block: XXX | ||
58 | max block: XXX | ||
31 | -- | 59 | -- |
32 | 2.13.5 | 60 | 2.35.3 |
33 | 61 | ||
34 | 62 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | In certain container environments we may not have FUSE at all, so skip | ||
4 | the test in this circumstance too. | ||
5 | |||
6 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
7 | Message-Id: <20220616142659.3184115-3-jsnow@redhat.com> | ||
8 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
9 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/108 | 5 +++++ | ||
13 | 1 file changed, 5 insertions(+) | ||
14 | |||
15 | diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108 | ||
16 | index XXXXXXX..XXXXXXX 100755 | ||
17 | --- a/tests/qemu-iotests/108 | ||
18 | +++ b/tests/qemu-iotests/108 | ||
19 | @@ -XXX,XX +XXX,XX @@ if sudo -n losetup &>/dev/null; then | ||
20 | else | ||
21 | loopdev=false | ||
22 | |||
23 | + # Check for usable FUSE in the host environment: | ||
24 | + if test ! -c "/dev/fuse"; then | ||
25 | + _notrun 'No passwordless sudo nor usable /dev/fuse' | ||
26 | + fi | ||
27 | + | ||
28 | # QSD --export fuse will either yield "Parameter 'id' is missing" | ||
29 | # or "Invalid parameter 'fuse'", depending on whether there is | ||
30 | # FUSE support or not. | ||
31 | -- | ||
32 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | They currently return the value of their 'bytes' parameter on success. | ||
4 | |||
5 | Make them return 0 instead, for consistency with other I/O functions and | ||
6 | in preparation to implement them using generated_co_wrapper. This also | ||
7 | makes it clear that short reads/writes are not possible. | ||
8 | |||
9 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
10 | Message-Id: <20220705161527.1054072-2-afaria@redhat.com> | ||
11 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | ||
14 | block.c | 8 +++++--- | ||
15 | block/block-backend.c | 7 ++----- | ||
16 | block/qcow.c | 6 +++--- | ||
17 | hw/block/m25p80.c | 2 +- | ||
18 | hw/misc/mac_via.c | 4 ++-- | ||
19 | hw/misc/sifive_u_otp.c | 2 +- | ||
20 | hw/nvram/eeprom_at24c.c | 8 ++++---- | ||
21 | hw/nvram/spapr_nvram.c | 14 +++++++------- | ||
22 | hw/ppc/pnv_pnor.c | 2 +- | ||
23 | qemu-img.c | 25 +++++++++---------------- | ||
24 | qemu-io-cmds.c | 18 ++++++++++++------ | ||
25 | tests/unit/test-block-iothread.c | 4 ++-- | ||
26 | 12 files changed, 49 insertions(+), 51 deletions(-) | ||
27 | |||
28 | diff --git a/block.c b/block.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/block.c | ||
31 | +++ b/block.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int find_image_format(BlockBackend *file, const char *filename, | ||
33 | return ret; | ||
34 | } | ||
35 | |||
36 | - drv = bdrv_probe_all(buf, ret, filename); | ||
37 | + drv = bdrv_probe_all(buf, sizeof(buf), filename); | ||
38 | if (!drv) { | ||
39 | error_setg(errp, "Could not determine image format: No compatible " | ||
40 | "driver found"); | ||
41 | - ret = -ENOENT; | ||
42 | + *pdrv = NULL; | ||
43 | + return -ENOENT; | ||
44 | } | ||
45 | + | ||
46 | *pdrv = drv; | ||
47 | - return ret; | ||
48 | + return 0; | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/block/block-backend.c | ||
55 | +++ b/block/block-backend.c | ||
56 | @@ -XXX,XX +XXX,XX @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes) | ||
57 | ret = blk_do_preadv(blk, offset, bytes, &qiov, 0); | ||
58 | blk_dec_in_flight(blk); | ||
59 | |||
60 | - return ret < 0 ? ret : bytes; | ||
61 | + return ret; | ||
62 | } | ||
63 | |||
64 | int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, | ||
65 | BdrvRequestFlags flags) | ||
66 | { | ||
67 | - int ret; | ||
68 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
69 | IO_OR_GS_CODE(); | ||
70 | |||
71 | - ret = blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags); | ||
72 | - | ||
73 | - return ret < 0 ? ret : bytes; | ||
74 | + return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags); | ||
75 | } | ||
76 | |||
77 | int64_t blk_getlength(BlockBackend *blk) | ||
78 | diff --git a/block/qcow.c b/block/qcow.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/block/qcow.c | ||
81 | +++ b/block/qcow.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, | ||
83 | |||
84 | /* write all the data */ | ||
85 | ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0); | ||
86 | - if (ret != sizeof(header)) { | ||
87 | + if (ret < 0) { | ||
88 | goto exit; | ||
89 | } | ||
90 | |||
91 | if (qcow_opts->has_backing_file) { | ||
92 | ret = blk_pwrite(qcow_blk, sizeof(header), | ||
93 | qcow_opts->backing_file, backing_filename_len, 0); | ||
94 | - if (ret != backing_filename_len) { | ||
95 | + if (ret < 0) { | ||
96 | goto exit; | ||
97 | } | ||
98 | } | ||
99 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, | ||
100 | i++) { | ||
101 | ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i, | ||
102 | tmp, BDRV_SECTOR_SIZE, 0); | ||
103 | - if (ret != BDRV_SECTOR_SIZE) { | ||
104 | + if (ret < 0) { | ||
105 | g_free(tmp); | ||
106 | goto exit; | ||
107 | } | ||
108 | diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/hw/block/m25p80.c | ||
111 | +++ b/hw/block/m25p80.c | ||
112 | @@ -XXX,XX +XXX,XX @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp) | ||
113 | trace_m25p80_binding(s); | ||
114 | s->storage = blk_blockalign(s->blk, s->size); | ||
115 | |||
116 | - if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) { | ||
117 | + if (blk_pread(s->blk, 0, s->storage, s->size) < 0) { | ||
118 | error_setg(errp, "failed to read the initial flash content"); | ||
119 | return; | ||
120 | } | ||
121 | diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c | ||
122 | index XXXXXXX..XXXXXXX 100644 | ||
123 | --- a/hw/misc/mac_via.c | ||
124 | +++ b/hw/misc/mac_via.c | ||
125 | @@ -XXX,XX +XXX,XX @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp) | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | - len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM)); | ||
130 | - if (len != sizeof(v1s->PRAM)) { | ||
131 | + ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM)); | ||
132 | + if (ret < 0) { | ||
133 | error_setg(errp, "can't read PRAM contents"); | ||
134 | return; | ||
135 | } | ||
136 | diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/hw/misc/sifive_u_otp.c | ||
139 | +++ b/hw/misc/sifive_u_otp.c | ||
140 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp) | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | - if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) { | ||
145 | + if (blk_pread(s->blk, 0, s->fuse, filesize) < 0) { | ||
146 | error_setg(errp, "failed to read the initial flash content"); | ||
147 | return; | ||
148 | } | ||
149 | diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/hw/nvram/eeprom_at24c.c | ||
152 | +++ b/hw/nvram/eeprom_at24c.c | ||
153 | @@ -XXX,XX +XXX,XX @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event) | ||
154 | case I2C_START_RECV: | ||
155 | DPRINTK("clear\n"); | ||
156 | if (ee->blk && ee->changed) { | ||
157 | - int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0); | ||
158 | - if (len != ee->rsize) { | ||
159 | + int ret = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0); | ||
160 | + if (ret < 0) { | ||
161 | ERR(TYPE_AT24C_EE | ||
162 | " : failed to write backing file\n"); | ||
163 | } | ||
164 | @@ -XXX,XX +XXX,XX @@ void at24c_eeprom_reset(DeviceState *state) | ||
165 | memset(ee->mem, 0, ee->rsize); | ||
166 | |||
167 | if (ee->blk) { | ||
168 | - int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize); | ||
169 | + int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize); | ||
170 | |||
171 | - if (len != ee->rsize) { | ||
172 | + if (ret < 0) { | ||
173 | ERR(TYPE_AT24C_EE | ||
174 | " : Failed initial sync with backing file\n"); | ||
175 | } | ||
176 | diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c | ||
177 | index XXXXXXX..XXXXXXX 100644 | ||
178 | --- a/hw/nvram/spapr_nvram.c | ||
179 | +++ b/hw/nvram/spapr_nvram.c | ||
180 | @@ -XXX,XX +XXX,XX @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr, | ||
181 | { | ||
182 | SpaprNvram *nvram = spapr->nvram; | ||
183 | hwaddr offset, buffer, len; | ||
184 | - int alen; | ||
185 | + int ret; | ||
186 | void *membuf; | ||
187 | |||
188 | if ((nargs != 3) || (nret != 2)) { | ||
189 | @@ -XXX,XX +XXX,XX @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr, | ||
190 | |||
191 | membuf = cpu_physical_memory_map(buffer, &len, false); | ||
192 | |||
193 | - alen = len; | ||
194 | + ret = 0; | ||
195 | if (nvram->blk) { | ||
196 | - alen = blk_pwrite(nvram->blk, offset, membuf, len, 0); | ||
197 | + ret = blk_pwrite(nvram->blk, offset, membuf, len, 0); | ||
198 | } | ||
199 | |||
200 | assert(nvram->buf); | ||
201 | @@ -XXX,XX +XXX,XX @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr, | ||
202 | |||
203 | cpu_physical_memory_unmap(membuf, len, 0, len); | ||
204 | |||
205 | - rtas_st(rets, 0, (alen < len) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS); | ||
206 | - rtas_st(rets, 1, (alen < 0) ? 0 : alen); | ||
207 | + rtas_st(rets, 0, (ret < 0) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS); | ||
208 | + rtas_st(rets, 1, (ret < 0) ? 0 : len); | ||
209 | } | ||
210 | |||
211 | static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp) | ||
212 | @@ -XXX,XX +XXX,XX @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp) | ||
213 | } | ||
214 | |||
215 | if (nvram->blk) { | ||
216 | - int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size); | ||
217 | + ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size); | ||
218 | |||
219 | - if (alen != nvram->size) { | ||
220 | + if (ret < 0) { | ||
221 | error_setg(errp, "can't read spapr-nvram contents"); | ||
222 | return; | ||
223 | } | ||
224 | diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c | ||
225 | index XXXXXXX..XXXXXXX 100644 | ||
226 | --- a/hw/ppc/pnv_pnor.c | ||
227 | +++ b/hw/ppc/pnv_pnor.c | ||
228 | @@ -XXX,XX +XXX,XX @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) | ||
229 | |||
230 | s->storage = blk_blockalign(s->blk, s->size); | ||
231 | |||
232 | - if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) { | ||
233 | + if (blk_pread(s->blk, 0, s->storage, s->size) < 0) { | ||
234 | error_setg(errp, "failed to read the initial flash content"); | ||
235 | return; | ||
236 | } | ||
237 | diff --git a/qemu-img.c b/qemu-img.c | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/qemu-img.c | ||
240 | +++ b/qemu-img.c | ||
241 | @@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv) | ||
242 | in.buf = g_new(uint8_t, in.bsz); | ||
243 | |||
244 | for (out_pos = 0; in_pos < size; block_count++) { | ||
245 | - int in_ret, out_ret; | ||
246 | + int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; | ||
247 | |||
248 | - if (in_pos + in.bsz > size) { | ||
249 | - in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos); | ||
250 | - } else { | ||
251 | - in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz); | ||
252 | - } | ||
253 | - if (in_ret < 0) { | ||
254 | + ret = blk_pread(blk1, in_pos, in.buf, bytes); | ||
255 | + if (ret < 0) { | ||
256 | error_report("error while reading from input image file: %s", | ||
257 | - strerror(-in_ret)); | ||
258 | - ret = -1; | ||
259 | + strerror(-ret)); | ||
260 | goto out; | ||
261 | } | ||
262 | - in_pos += in_ret; | ||
263 | + in_pos += bytes; | ||
264 | |||
265 | - out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0); | ||
266 | - | ||
267 | - if (out_ret < 0) { | ||
268 | + ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0); | ||
269 | + if (ret < 0) { | ||
270 | error_report("error while writing to output image file: %s", | ||
271 | - strerror(-out_ret)); | ||
272 | - ret = -1; | ||
273 | + strerror(-ret)); | ||
274 | goto out; | ||
275 | } | ||
276 | - out_pos += out_ret; | ||
277 | + out_pos += bytes; | ||
278 | } | ||
279 | |||
280 | out: | ||
281 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | ||
282 | index XXXXXXX..XXXXXXX 100644 | ||
283 | --- a/qemu-io-cmds.c | ||
284 | +++ b/qemu-io-cmds.c | ||
285 | @@ -XXX,XX +XXX,XX @@ fail: | ||
286 | static int do_pread(BlockBackend *blk, char *buf, int64_t offset, | ||
287 | int64_t bytes, int64_t *total) | ||
288 | { | ||
289 | + int ret; | ||
290 | + | ||
291 | if (bytes > INT_MAX) { | ||
292 | return -ERANGE; | ||
293 | } | ||
294 | |||
295 | - *total = blk_pread(blk, offset, (uint8_t *)buf, bytes); | ||
296 | - if (*total < 0) { | ||
297 | - return *total; | ||
298 | + ret = blk_pread(blk, offset, (uint8_t *)buf, bytes); | ||
299 | + if (ret < 0) { | ||
300 | + return ret; | ||
301 | } | ||
302 | + *total = bytes; | ||
303 | return 1; | ||
304 | } | ||
305 | |||
306 | static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, | ||
307 | int64_t bytes, int flags, int64_t *total) | ||
308 | { | ||
309 | + int ret; | ||
310 | + | ||
311 | if (bytes > INT_MAX) { | ||
312 | return -ERANGE; | ||
313 | } | ||
314 | |||
315 | - *total = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags); | ||
316 | - if (*total < 0) { | ||
317 | - return *total; | ||
318 | + ret = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags); | ||
319 | + if (ret < 0) { | ||
320 | + return ret; | ||
321 | } | ||
322 | + *total = bytes; | ||
323 | return 1; | ||
324 | } | ||
325 | |||
326 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
327 | index XXXXXXX..XXXXXXX 100644 | ||
328 | --- a/tests/unit/test-block-iothread.c | ||
329 | +++ b/tests/unit/test-block-iothread.c | ||
330 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pread(BlockBackend *blk) | ||
331 | |||
332 | /* Success */ | ||
333 | ret = blk_pread(blk, 0, buf, sizeof(buf)); | ||
334 | - g_assert_cmpint(ret, ==, 512); | ||
335 | + g_assert_cmpint(ret, ==, 0); | ||
336 | |||
337 | /* Early error: Negative offset */ | ||
338 | ret = blk_pread(blk, -2, buf, sizeof(buf)); | ||
339 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwrite(BlockBackend *blk) | ||
340 | |||
341 | /* Success */ | ||
342 | ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0); | ||
343 | - g_assert_cmpint(ret, ==, 512); | ||
344 | + g_assert_cmpint(ret, ==, 0); | ||
345 | |||
346 | /* Early error: Negative offset */ | ||
347 | ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0); | ||
348 | -- | ||
349 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Alberto Faria <afaria@redhat.com> | |
2 | |||
3 | For consistency with other I/O functions, and in preparation to | ||
4 | implement it using generated_co_wrapper. | ||
5 | |||
6 | Callers were updated using this Coccinelle script: | ||
7 | |||
8 | @@ expression blk, offset, buf, bytes; @@ | ||
9 | - blk_pread(blk, offset, buf, bytes) | ||
10 | + blk_pread(blk, offset, buf, bytes, 0) | ||
11 | |||
12 | It had no effect on hw/block/nand.c, presumably due to the #if, so that | ||
13 | file was updated manually. | ||
14 | |||
15 | Overly-long lines were then fixed by hand. | ||
16 | |||
17 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
18 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
19 | Reviewed-by: Greg Kurz <groug@kaod.org> | ||
20 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
21 | Message-Id: <20220705161527.1054072-3-afaria@redhat.com> | ||
22 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
23 | --- | ||
24 | include/sysemu/block-backend-io.h | 3 ++- | ||
25 | block.c | 2 +- | ||
26 | block/block-backend.c | 5 +++-- | ||
27 | block/commit.c | 2 +- | ||
28 | block/export/fuse.c | 2 +- | ||
29 | hw/arm/allwinner-h3.c | 2 +- | ||
30 | hw/arm/aspeed.c | 2 +- | ||
31 | hw/block/block.c | 2 +- | ||
32 | hw/block/fdc.c | 6 +++--- | ||
33 | hw/block/hd-geometry.c | 2 +- | ||
34 | hw/block/m25p80.c | 2 +- | ||
35 | hw/block/nand.c | 12 ++++++------ | ||
36 | hw/block/onenand.c | 12 ++++++------ | ||
37 | hw/ide/atapi.c | 4 ++-- | ||
38 | hw/misc/mac_via.c | 2 +- | ||
39 | hw/misc/sifive_u_otp.c | 4 ++-- | ||
40 | hw/nvram/eeprom_at24c.c | 2 +- | ||
41 | hw/nvram/spapr_nvram.c | 2 +- | ||
42 | hw/nvram/xlnx-bbram.c | 2 +- | ||
43 | hw/nvram/xlnx-efuse.c | 2 +- | ||
44 | hw/ppc/pnv_pnor.c | 2 +- | ||
45 | hw/sd/sd.c | 2 +- | ||
46 | migration/block.c | 4 ++-- | ||
47 | nbd/server.c | 4 ++-- | ||
48 | qemu-img.c | 12 ++++++------ | ||
49 | qemu-io-cmds.c | 2 +- | ||
50 | tests/unit/test-block-iothread.c | 4 ++-- | ||
51 | 27 files changed, 52 insertions(+), 50 deletions(-) | ||
52 | |||
53 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/include/sysemu/block-backend-io.h | ||
56 | +++ b/include/sysemu/block-backend-io.h | ||
57 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, | ||
58 | * the "I/O or GS" API. | ||
59 | */ | ||
60 | |||
61 | -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes); | ||
62 | +int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, | ||
63 | + BdrvRequestFlags flags); | ||
64 | int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, | ||
65 | BdrvRequestFlags flags); | ||
66 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
67 | diff --git a/block.c b/block.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/block.c | ||
70 | +++ b/block.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static int find_image_format(BlockBackend *file, const char *filename, | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | - ret = blk_pread(file, 0, buf, sizeof(buf)); | ||
76 | + ret = blk_pread(file, 0, buf, sizeof(buf), 0); | ||
77 | if (ret < 0) { | ||
78 | error_setg_errno(errp, -ret, "Could not read image for determining its " | ||
79 | "format"); | ||
80 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/block/block-backend.c | ||
83 | +++ b/block/block-backend.c | ||
84 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
85 | flags | BDRV_REQ_ZERO_WRITE, cb, opaque); | ||
86 | } | ||
87 | |||
88 | -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes) | ||
89 | +int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, | ||
90 | + BdrvRequestFlags flags) | ||
91 | { | ||
92 | int ret; | ||
93 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
94 | IO_OR_GS_CODE(); | ||
95 | |||
96 | blk_inc_in_flight(blk); | ||
97 | - ret = blk_do_preadv(blk, offset, bytes, &qiov, 0); | ||
98 | + ret = blk_do_preadv(blk, offset, bytes, &qiov, flags); | ||
99 | blk_dec_in_flight(blk); | ||
100 | |||
101 | return ret; | ||
102 | diff --git a/block/commit.c b/block/commit.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/block/commit.c | ||
105 | +++ b/block/commit.c | ||
106 | @@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs) | ||
107 | goto ro_cleanup; | ||
108 | } | ||
109 | if (ret) { | ||
110 | - ret = blk_pread(src, offset, buf, n); | ||
111 | + ret = blk_pread(src, offset, buf, n, 0); | ||
112 | if (ret < 0) { | ||
113 | goto ro_cleanup; | ||
114 | } | ||
115 | diff --git a/block/export/fuse.c b/block/export/fuse.c | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/block/export/fuse.c | ||
118 | +++ b/block/export/fuse.c | ||
119 | @@ -XXX,XX +XXX,XX @@ static void fuse_read(fuse_req_t req, fuse_ino_t inode, | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | - ret = blk_pread(exp->common.blk, offset, buf, size); | ||
124 | + ret = blk_pread(exp->common.blk, offset, buf, size, 0); | ||
125 | if (ret >= 0) { | ||
126 | fuse_reply_buf(req, buf, size); | ||
127 | } else { | ||
128 | diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c | ||
129 | index XXXXXXX..XXXXXXX 100644 | ||
130 | --- a/hw/arm/allwinner-h3.c | ||
131 | +++ b/hw/arm/allwinner-h3.c | ||
132 | @@ -XXX,XX +XXX,XX @@ void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk) | ||
133 | const int64_t rom_size = 32 * KiB; | ||
134 | g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size); | ||
135 | |||
136 | - if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) { | ||
137 | + if (blk_pread(blk, 8 * KiB, buffer, rom_size, 0) < 0) { | ||
138 | error_setg(&error_fatal, "%s: failed to read BlockBackend data", | ||
139 | __func__); | ||
140 | return; | ||
141 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | ||
142 | index XXXXXXX..XXXXXXX 100644 | ||
143 | --- a/hw/arm/aspeed.c | ||
144 | +++ b/hw/arm/aspeed.c | ||
145 | @@ -XXX,XX +XXX,XX @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size, | ||
146 | } | ||
147 | |||
148 | storage = g_malloc0(rom_size); | ||
149 | - if (blk_pread(blk, 0, storage, rom_size) < 0) { | ||
150 | + if (blk_pread(blk, 0, storage, rom_size, 0) < 0) { | ||
151 | error_setg(errp, "failed to read the initial flash content"); | ||
152 | return; | ||
153 | } | ||
154 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
155 | index XXXXXXX..XXXXXXX 100644 | ||
156 | --- a/hw/block/block.c | ||
157 | +++ b/hw/block/block.c | ||
158 | @@ -XXX,XX +XXX,XX @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size, | ||
159 | * block device and read only on demand. | ||
160 | */ | ||
161 | assert(size <= BDRV_REQUEST_MAX_BYTES); | ||
162 | - ret = blk_pread(blk, 0, buf, size); | ||
163 | + ret = blk_pread(blk, 0, buf, size, 0); | ||
164 | if (ret < 0) { | ||
165 | error_setg_errno(errp, -ret, "can't read block backend"); | ||
166 | return false; | ||
167 | diff --git a/hw/block/fdc.c b/hw/block/fdc.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/hw/block/fdc.c | ||
170 | +++ b/hw/block/fdc.c | ||
171 | @@ -XXX,XX +XXX,XX @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len) | ||
172 | if (fdctrl->data_dir != FD_DIR_WRITE || | ||
173 | len < FD_SECTOR_LEN || rel_pos != 0) { | ||
174 | /* READ & SCAN commands and realign to a sector for WRITE */ | ||
175 | - if (blk_pread(cur_drv->blk, fd_offset(cur_drv), | ||
176 | - fdctrl->fifo, BDRV_SECTOR_SIZE) < 0) { | ||
177 | + if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, | ||
178 | + BDRV_SECTOR_SIZE, 0) < 0) { | ||
179 | FLOPPY_DPRINTF("Floppy: error getting sector %d\n", | ||
180 | fd_sector(cur_drv)); | ||
181 | /* Sure, image size is too small... */ | ||
182 | @@ -XXX,XX +XXX,XX @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl) | ||
183 | return 0; | ||
184 | } | ||
185 | if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, | ||
186 | - BDRV_SECTOR_SIZE) | ||
187 | + BDRV_SECTOR_SIZE, 0) | ||
188 | < 0) { | ||
189 | FLOPPY_DPRINTF("error getting sector %d\n", | ||
190 | fd_sector(cur_drv)); | ||
191 | diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c | ||
192 | index XXXXXXX..XXXXXXX 100644 | ||
193 | --- a/hw/block/hd-geometry.c | ||
194 | +++ b/hw/block/hd-geometry.c | ||
195 | @@ -XXX,XX +XXX,XX @@ static int guess_disk_lchs(BlockBackend *blk, | ||
196 | |||
197 | blk_get_geometry(blk, &nb_sectors); | ||
198 | |||
199 | - if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) { | ||
200 | + if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE, 0) < 0) { | ||
201 | return -1; | ||
202 | } | ||
203 | /* test msdos magic */ | ||
204 | diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c | ||
205 | index XXXXXXX..XXXXXXX 100644 | ||
206 | --- a/hw/block/m25p80.c | ||
207 | +++ b/hw/block/m25p80.c | ||
208 | @@ -XXX,XX +XXX,XX @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp) | ||
209 | trace_m25p80_binding(s); | ||
210 | s->storage = blk_blockalign(s->blk, s->size); | ||
211 | |||
212 | - if (blk_pread(s->blk, 0, s->storage, s->size) < 0) { | ||
213 | + if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { | ||
214 | error_setg(errp, "failed to read the initial flash content"); | ||
215 | return; | ||
216 | } | ||
217 | diff --git a/hw/block/nand.c b/hw/block/nand.c | ||
218 | index XXXXXXX..XXXXXXX 100644 | ||
219 | --- a/hw/block/nand.c | ||
220 | +++ b/hw/block/nand.c | ||
221 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
222 | off = (s->addr & PAGE_MASK) + s->offset; | ||
223 | soff = SECTOR_OFFSET(s->addr); | ||
224 | if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
225 | - PAGE_SECTORS << BDRV_SECTOR_BITS) < 0) { | ||
226 | + PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { | ||
227 | printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); | ||
228 | return; | ||
229 | } | ||
230 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
231 | sector = off >> 9; | ||
232 | soff = off & 0x1ff; | ||
233 | if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
234 | - (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS) < 0) { | ||
235 | + (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { | ||
236 | printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); | ||
237 | return; | ||
238 | } | ||
239 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
240 | addr = PAGE_START(addr); | ||
241 | page = addr >> 9; | ||
242 | if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
243 | - BDRV_SECTOR_SIZE) < 0) { | ||
244 | + BDRV_SECTOR_SIZE, 0) < 0) { | ||
245 | printf("%s: read error in sector %" PRIu64 "\n", __func__, page); | ||
246 | } | ||
247 | memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1); | ||
248 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
249 | |||
250 | page = i >> 9; | ||
251 | if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
252 | - BDRV_SECTOR_SIZE) < 0) { | ||
253 | + BDRV_SECTOR_SIZE, 0) < 0) { | ||
254 | printf("%s: read error in sector %" PRIu64 "\n", __func__, page); | ||
255 | } | ||
256 | memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1); | ||
257 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, | ||
258 | if (s->blk) { | ||
259 | if (s->mem_oob) { | ||
260 | if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS, s->io, | ||
261 | - PAGE_SECTORS << BDRV_SECTOR_BITS) < 0) { | ||
262 | + PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { | ||
263 | printf("%s: read error in sector %" PRIu64 "\n", | ||
264 | __func__, SECTOR(addr)); | ||
265 | } | ||
266 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, | ||
267 | s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; | ||
268 | } else { | ||
269 | if (blk_pread(s->blk, PAGE_START(addr), s->io, | ||
270 | - (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS) < 0) { | ||
271 | + (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { | ||
272 | printf("%s: read error in sector %" PRIu64 "\n", | ||
273 | __func__, PAGE_START(addr) >> 9); | ||
274 | } | ||
275 | diff --git a/hw/block/onenand.c b/hw/block/onenand.c | ||
276 | index XXXXXXX..XXXXXXX 100644 | ||
277 | --- a/hw/block/onenand.c | ||
278 | +++ b/hw/block/onenand.c | ||
279 | @@ -XXX,XX +XXX,XX @@ static void onenand_reset(OneNANDState *s, int cold) | ||
280 | memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); | ||
281 | |||
282 | if (s->blk_cur && blk_pread(s->blk_cur, 0, s->boot[0], | ||
283 | - 8 << BDRV_SECTOR_BITS) < 0) { | ||
284 | + 8 << BDRV_SECTOR_BITS, 0) < 0) { | ||
285 | hw_error("%s: Loading the BootRAM failed.\n", __func__); | ||
286 | } | ||
287 | } | ||
288 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn, | ||
289 | assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn); | ||
290 | if (s->blk_cur) { | ||
291 | return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, dest, | ||
292 | - secn << BDRV_SECTOR_BITS) < 0; | ||
293 | + secn << BDRV_SECTOR_BITS, 0) < 0; | ||
294 | } else if (sec + secn > s->secs_cur) { | ||
295 | return 1; | ||
296 | } | ||
297 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, | ||
298 | uint8_t *dp = 0; | ||
299 | if (s->blk_cur) { | ||
300 | dp = g_malloc(size); | ||
301 | - if (!dp || blk_pread(s->blk_cur, offset, dp, size) < 0) { | ||
302 | + if (!dp || blk_pread(s->blk_cur, offset, dp, size, 0) < 0) { | ||
303 | result = 1; | ||
304 | } | ||
305 | } else { | ||
306 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn, | ||
307 | |||
308 | if (s->blk_cur) { | ||
309 | uint32_t offset = (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS; | ||
310 | - if (blk_pread(s->blk_cur, offset, buf, BDRV_SECTOR_SIZE) < 0) { | ||
311 | + if (blk_pread(s->blk_cur, offset, buf, BDRV_SECTOR_SIZE, 0) < 0) { | ||
312 | return 1; | ||
313 | } | ||
314 | memcpy(dest, buf + ((sec & 31) << 4), secn << 4); | ||
315 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, | ||
316 | if (s->blk_cur) { | ||
317 | dp = g_malloc(512); | ||
318 | if (!dp | ||
319 | - || blk_pread(s->blk_cur, offset, dp, BDRV_SECTOR_SIZE) < 0) { | ||
320 | + || blk_pread(s->blk_cur, offset, dp, BDRV_SECTOR_SIZE, 0) < 0) { | ||
321 | result = 1; | ||
322 | } else { | ||
323 | dpp = dp + ((sec & 31) << 4); | ||
324 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_erase(OneNANDState *s, int sec, int num) | ||
325 | goto fail; | ||
326 | } | ||
327 | if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf, | ||
328 | - BDRV_SECTOR_SIZE) < 0) { | ||
329 | + BDRV_SECTOR_SIZE, 0) < 0) { | ||
330 | goto fail; | ||
331 | } | ||
332 | memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); | ||
333 | diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c | ||
334 | index XXXXXXX..XXXXXXX 100644 | ||
335 | --- a/hw/ide/atapi.c | ||
336 | +++ b/hw/ide/atapi.c | ||
337 | @@ -XXX,XX +XXX,XX @@ cd_read_sector_sync(IDEState *s) | ||
338 | switch (s->cd_sector_size) { | ||
339 | case 2048: | ||
340 | ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, | ||
341 | - s->io_buffer, ATAPI_SECTOR_SIZE); | ||
342 | + s->io_buffer, ATAPI_SECTOR_SIZE, 0); | ||
343 | break; | ||
344 | case 2352: | ||
345 | ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, | ||
346 | - s->io_buffer + 16, ATAPI_SECTOR_SIZE); | ||
347 | + s->io_buffer + 16, ATAPI_SECTOR_SIZE, 0); | ||
348 | if (ret >= 0) { | ||
349 | cd_data_to_raw(s->io_buffer, s->lba); | ||
350 | } | ||
351 | diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c | ||
352 | index XXXXXXX..XXXXXXX 100644 | ||
353 | --- a/hw/misc/mac_via.c | ||
354 | +++ b/hw/misc/mac_via.c | ||
355 | @@ -XXX,XX +XXX,XX @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp) | ||
356 | return; | ||
357 | } | ||
358 | |||
359 | - ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM)); | ||
360 | + ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0); | ||
361 | if (ret < 0) { | ||
362 | error_setg(errp, "can't read PRAM contents"); | ||
363 | return; | ||
364 | diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c | ||
365 | index XXXXXXX..XXXXXXX 100644 | ||
366 | --- a/hw/misc/sifive_u_otp.c | ||
367 | +++ b/hw/misc/sifive_u_otp.c | ||
368 | @@ -XXX,XX +XXX,XX @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size) | ||
369 | int32_t buf; | ||
370 | |||
371 | if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf, | ||
372 | - SIFIVE_U_OTP_FUSE_WORD) < 0) { | ||
373 | + SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { | ||
374 | error_report("read error index<%d>", s->pa); | ||
375 | return 0xff; | ||
376 | } | ||
377 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp) | ||
378 | return; | ||
379 | } | ||
380 | |||
381 | - if (blk_pread(s->blk, 0, s->fuse, filesize) < 0) { | ||
382 | + if (blk_pread(s->blk, 0, s->fuse, filesize, 0) < 0) { | ||
383 | error_setg(errp, "failed to read the initial flash content"); | ||
384 | return; | ||
385 | } | ||
386 | diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c | ||
387 | index XXXXXXX..XXXXXXX 100644 | ||
388 | --- a/hw/nvram/eeprom_at24c.c | ||
389 | +++ b/hw/nvram/eeprom_at24c.c | ||
390 | @@ -XXX,XX +XXX,XX @@ void at24c_eeprom_reset(DeviceState *state) | ||
391 | memset(ee->mem, 0, ee->rsize); | ||
392 | |||
393 | if (ee->blk) { | ||
394 | - int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize); | ||
395 | + int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0); | ||
396 | |||
397 | if (ret < 0) { | ||
398 | ERR(TYPE_AT24C_EE | ||
399 | diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c | ||
400 | index XXXXXXX..XXXXXXX 100644 | ||
401 | --- a/hw/nvram/spapr_nvram.c | ||
402 | +++ b/hw/nvram/spapr_nvram.c | ||
403 | @@ -XXX,XX +XXX,XX @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp) | ||
404 | } | ||
405 | |||
406 | if (nvram->blk) { | ||
407 | - ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size); | ||
408 | + ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0); | ||
409 | |||
410 | if (ret < 0) { | ||
411 | error_setg(errp, "can't read spapr-nvram contents"); | ||
412 | diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c | ||
413 | index XXXXXXX..XXXXXXX 100644 | ||
414 | --- a/hw/nvram/xlnx-bbram.c | ||
415 | +++ b/hw/nvram/xlnx-bbram.c | ||
416 | @@ -XXX,XX +XXX,XX @@ static void bbram_bdrv_read(XlnxBBRam *s, Error **errp) | ||
417 | blk_name(s->blk)); | ||
418 | } | ||
419 | |||
420 | - if (blk_pread(s->blk, 0, ram, nr) < 0) { | ||
421 | + if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { | ||
422 | error_setg(errp, | ||
423 | "%s: Failed to read %u bytes from BBRAM backstore.", | ||
424 | blk_name(s->blk), nr); | ||
425 | diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c | ||
426 | index XXXXXXX..XXXXXXX 100644 | ||
427 | --- a/hw/nvram/xlnx-efuse.c | ||
428 | +++ b/hw/nvram/xlnx-efuse.c | ||
429 | @@ -XXX,XX +XXX,XX @@ static int efuse_bdrv_read(XlnxEFuse *s, Error **errp) | ||
430 | blk_name(s->blk)); | ||
431 | } | ||
432 | |||
433 | - if (blk_pread(s->blk, 0, ram, nr) < 0) { | ||
434 | + if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { | ||
435 | error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.", | ||
436 | blk_name(s->blk), nr); | ||
437 | return -1; | ||
438 | diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c | ||
439 | index XXXXXXX..XXXXXXX 100644 | ||
440 | --- a/hw/ppc/pnv_pnor.c | ||
441 | +++ b/hw/ppc/pnv_pnor.c | ||
442 | @@ -XXX,XX +XXX,XX @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) | ||
443 | |||
444 | s->storage = blk_blockalign(s->blk, s->size); | ||
445 | |||
446 | - if (blk_pread(s->blk, 0, s->storage, s->size) < 0) { | ||
447 | + if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { | ||
448 | error_setg(errp, "failed to read the initial flash content"); | ||
449 | return; | ||
450 | } | ||
451 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
452 | index XXXXXXX..XXXXXXX 100644 | ||
453 | --- a/hw/sd/sd.c | ||
454 | +++ b/hw/sd/sd.c | ||
455 | @@ -XXX,XX +XXX,XX @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) | ||
456 | static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) | ||
457 | { | ||
458 | trace_sdcard_read_block(addr, len); | ||
459 | - if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len) < 0) { | ||
460 | + if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len, 0) < 0) { | ||
461 | fprintf(stderr, "sd_blk_read: read error on host side\n"); | ||
462 | } | ||
463 | } | ||
464 | diff --git a/migration/block.c b/migration/block.c | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/migration/block.c | ||
467 | +++ b/migration/block.c | ||
468 | @@ -XXX,XX +XXX,XX @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds, | ||
469 | bmds_set_aio_inflight(bmds, sector, nr_sectors, 1); | ||
470 | blk_mig_unlock(); | ||
471 | } else { | ||
472 | - ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, blk->buf, | ||
473 | - nr_sectors * BDRV_SECTOR_SIZE); | ||
474 | + ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, | ||
475 | + blk->buf, nr_sectors * BDRV_SECTOR_SIZE, 0); | ||
476 | if (ret < 0) { | ||
477 | goto error; | ||
478 | } | ||
479 | diff --git a/nbd/server.c b/nbd/server.c | ||
480 | index XXXXXXX..XXXXXXX 100644 | ||
481 | --- a/nbd/server.c | ||
482 | +++ b/nbd/server.c | ||
483 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, | ||
484 | ret = nbd_co_send_iov(client, iov, 1, errp); | ||
485 | } else { | ||
486 | ret = blk_pread(exp->common.blk, offset + progress, | ||
487 | - data + progress, pnum); | ||
488 | + data + progress, pnum, 0); | ||
489 | if (ret < 0) { | ||
490 | error_setg_errno(errp, -ret, "reading from file failed"); | ||
491 | break; | ||
492 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request, | ||
493 | data, request->len, errp); | ||
494 | } | ||
495 | |||
496 | - ret = blk_pread(exp->common.blk, request->from, data, request->len); | ||
497 | + ret = blk_pread(exp->common.blk, request->from, data, request->len, 0); | ||
498 | if (ret < 0) { | ||
499 | return nbd_send_generic_reply(client, request->handle, ret, | ||
500 | "reading from file failed", errp); | ||
501 | diff --git a/qemu-img.c b/qemu-img.c | ||
502 | index XXXXXXX..XXXXXXX 100644 | ||
503 | --- a/qemu-img.c | ||
504 | +++ b/qemu-img.c | ||
505 | @@ -XXX,XX +XXX,XX @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset, | ||
506 | int ret = 0; | ||
507 | int64_t idx; | ||
508 | |||
509 | - ret = blk_pread(blk, offset, buffer, bytes); | ||
510 | + ret = blk_pread(blk, offset, buffer, bytes, 0); | ||
511 | if (ret < 0) { | ||
512 | error_report("Error while reading offset %" PRId64 " of %s: %s", | ||
513 | offset, filename, strerror(-ret)); | ||
514 | @@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv) | ||
515 | int64_t pnum; | ||
516 | |||
517 | chunk = MIN(chunk, IO_BUF_SIZE); | ||
518 | - ret = blk_pread(blk1, offset, buf1, chunk); | ||
519 | + ret = blk_pread(blk1, offset, buf1, chunk, 0); | ||
520 | if (ret < 0) { | ||
521 | error_report("Error while reading offset %" PRId64 | ||
522 | " of %s: %s", | ||
523 | @@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv) | ||
524 | ret = 4; | ||
525 | goto out; | ||
526 | } | ||
527 | - ret = blk_pread(blk2, offset, buf2, chunk); | ||
528 | + ret = blk_pread(blk2, offset, buf2, chunk, 0); | ||
529 | if (ret < 0) { | ||
530 | error_report("Error while reading offset %" PRId64 | ||
531 | " of %s: %s", | ||
532 | @@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv) | ||
533 | n = old_backing_size - offset; | ||
534 | } | ||
535 | |||
536 | - ret = blk_pread(blk_old_backing, offset, buf_old, n); | ||
537 | + ret = blk_pread(blk_old_backing, offset, buf_old, n, 0); | ||
538 | if (ret < 0) { | ||
539 | error_report("error while reading from old backing file"); | ||
540 | goto out; | ||
541 | @@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv) | ||
542 | n = new_backing_size - offset; | ||
543 | } | ||
544 | |||
545 | - ret = blk_pread(blk_new_backing, offset, buf_new, n); | ||
546 | + ret = blk_pread(blk_new_backing, offset, buf_new, n, 0); | ||
547 | if (ret < 0) { | ||
548 | error_report("error while reading from new backing file"); | ||
549 | goto out; | ||
550 | @@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv) | ||
551 | for (out_pos = 0; in_pos < size; block_count++) { | ||
552 | int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; | ||
553 | |||
554 | - ret = blk_pread(blk1, in_pos, in.buf, bytes); | ||
555 | + ret = blk_pread(blk1, in_pos, in.buf, bytes, 0); | ||
556 | if (ret < 0) { | ||
557 | error_report("error while reading from input image file: %s", | ||
558 | strerror(-ret)); | ||
559 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | ||
560 | index XXXXXXX..XXXXXXX 100644 | ||
561 | --- a/qemu-io-cmds.c | ||
562 | +++ b/qemu-io-cmds.c | ||
563 | @@ -XXX,XX +XXX,XX @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset, | ||
564 | return -ERANGE; | ||
565 | } | ||
566 | |||
567 | - ret = blk_pread(blk, offset, (uint8_t *)buf, bytes); | ||
568 | + ret = blk_pread(blk, offset, (uint8_t *)buf, bytes, 0); | ||
569 | if (ret < 0) { | ||
570 | return ret; | ||
571 | } | ||
572 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
573 | index XXXXXXX..XXXXXXX 100644 | ||
574 | --- a/tests/unit/test-block-iothread.c | ||
575 | +++ b/tests/unit/test-block-iothread.c | ||
576 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pread(BlockBackend *blk) | ||
577 | int ret; | ||
578 | |||
579 | /* Success */ | ||
580 | - ret = blk_pread(blk, 0, buf, sizeof(buf)); | ||
581 | + ret = blk_pread(blk, 0, buf, sizeof(buf), 0); | ||
582 | g_assert_cmpint(ret, ==, 0); | ||
583 | |||
584 | /* Early error: Negative offset */ | ||
585 | - ret = blk_pread(blk, -2, buf, sizeof(buf)); | ||
586 | + ret = blk_pread(blk, -2, buf, sizeof(buf), 0); | ||
587 | g_assert_cmpint(ret, ==, -EIO); | ||
588 | } | ||
589 | |||
590 | -- | ||
591 | 2.35.3 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | There's a few cases which we're passing an Error pointer to a function | 3 | Swap 'buf' and 'bytes' around for consistency with |
4 | only to discard it immediately afterwards without checking it. In | 4 | blk_co_{pread,pwrite}(), and in preparation to implement these functions |
5 | these cases we can simply remove the variable and pass NULL instead. | 5 | using generated_co_wrapper. |
6 | 6 | ||
7 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 7 | Callers were updated using this Coccinelle script: |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | |
9 | @@ expression blk, offset, buf, bytes, flags; @@ | ||
10 | - blk_pread(blk, offset, buf, bytes, flags) | ||
11 | + blk_pread(blk, offset, bytes, buf, flags) | ||
12 | |||
13 | @@ expression blk, offset, buf, bytes, flags; @@ | ||
14 | - blk_pwrite(blk, offset, buf, bytes, flags) | ||
15 | + blk_pwrite(blk, offset, bytes, buf, flags) | ||
16 | |||
17 | It had no effect on hw/block/nand.c, presumably due to the #if, so that | ||
18 | file was updated manually. | ||
19 | |||
20 | Overly-long lines were then fixed by hand. | ||
21 | |||
22 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | 23 | Reviewed-by: Eric Blake <eblake@redhat.com> |
10 | Message-id: 20170829120836.16091-1-berto@igalia.com | 24 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 25 | Message-Id: <20220705161527.1054072-4-afaria@redhat.com> |
26 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | 27 | --- |
13 | block/qcow.c | 12 +++--------- | 28 | include/sysemu/block-backend-io.h | 4 +-- |
14 | block/qcow2.c | 8 ++------ | 29 | block.c | 2 +- |
15 | dump.c | 4 +--- | 30 | block/block-backend.c | 4 +-- |
16 | 3 files changed, 6 insertions(+), 18 deletions(-) | 31 | block/commit.c | 4 +-- |
32 | block/crypto.c | 2 +- | ||
33 | block/export/fuse.c | 4 +-- | ||
34 | block/parallels.c | 2 +- | ||
35 | block/qcow.c | 8 +++--- | ||
36 | block/qcow2.c | 4 +-- | ||
37 | block/qed.c | 8 +++--- | ||
38 | block/vdi.c | 4 +-- | ||
39 | block/vhdx.c | 20 ++++++------- | ||
40 | block/vmdk.c | 10 +++---- | ||
41 | block/vpc.c | 12 ++++---- | ||
42 | hw/arm/allwinner-h3.c | 2 +- | ||
43 | hw/arm/aspeed.c | 2 +- | ||
44 | hw/block/block.c | 2 +- | ||
45 | hw/block/fdc.c | 20 ++++++------- | ||
46 | hw/block/hd-geometry.c | 2 +- | ||
47 | hw/block/m25p80.c | 2 +- | ||
48 | hw/block/nand.c | 47 ++++++++++++++++--------------- | ||
49 | hw/block/onenand.c | 32 ++++++++++----------- | ||
50 | hw/block/pflash_cfi01.c | 4 +-- | ||
51 | hw/block/pflash_cfi02.c | 4 +-- | ||
52 | hw/ide/atapi.c | 4 +-- | ||
53 | hw/misc/mac_via.c | 4 +-- | ||
54 | hw/misc/sifive_u_otp.c | 14 ++++----- | ||
55 | hw/nvram/eeprom_at24c.c | 4 +-- | ||
56 | hw/nvram/spapr_nvram.c | 6 ++-- | ||
57 | hw/nvram/xlnx-bbram.c | 4 +-- | ||
58 | hw/nvram/xlnx-efuse.c | 4 +-- | ||
59 | hw/ppc/pnv_pnor.c | 6 ++-- | ||
60 | hw/sd/sd.c | 4 +-- | ||
61 | migration/block.c | 6 ++-- | ||
62 | nbd/server.c | 8 +++--- | ||
63 | qemu-img.c | 18 ++++++------ | ||
64 | qemu-io-cmds.c | 4 +-- | ||
65 | tests/unit/test-block-iothread.c | 8 +++--- | ||
66 | 38 files changed, 150 insertions(+), 149 deletions(-) | ||
17 | 67 | ||
68 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/include/sysemu/block-backend-io.h | ||
71 | +++ b/include/sysemu/block-backend-io.h | ||
72 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, | ||
73 | * the "I/O or GS" API. | ||
74 | */ | ||
75 | |||
76 | -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, | ||
77 | +int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, | ||
78 | BdrvRequestFlags flags); | ||
79 | -int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, | ||
80 | +int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, | ||
81 | BdrvRequestFlags flags); | ||
82 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
83 | int64_t bytes, QEMUIOVector *qiov, | ||
84 | diff --git a/block.c b/block.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/block.c | ||
87 | +++ b/block.c | ||
88 | @@ -XXX,XX +XXX,XX @@ static int find_image_format(BlockBackend *file, const char *filename, | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | - ret = blk_pread(file, 0, buf, sizeof(buf), 0); | ||
93 | + ret = blk_pread(file, 0, sizeof(buf), buf, 0); | ||
94 | if (ret < 0) { | ||
95 | error_setg_errno(errp, -ret, "Could not read image for determining its " | ||
96 | "format"); | ||
97 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/block/block-backend.c | ||
100 | +++ b/block/block-backend.c | ||
101 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
102 | flags | BDRV_REQ_ZERO_WRITE, cb, opaque); | ||
103 | } | ||
104 | |||
105 | -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, | ||
106 | +int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, | ||
107 | BdrvRequestFlags flags) | ||
108 | { | ||
109 | int ret; | ||
110 | @@ -XXX,XX +XXX,XX @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, | ||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | -int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, | ||
115 | +int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, | ||
116 | BdrvRequestFlags flags) | ||
117 | { | ||
118 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
119 | diff --git a/block/commit.c b/block/commit.c | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/block/commit.c | ||
122 | +++ b/block/commit.c | ||
123 | @@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs) | ||
124 | goto ro_cleanup; | ||
125 | } | ||
126 | if (ret) { | ||
127 | - ret = blk_pread(src, offset, buf, n, 0); | ||
128 | + ret = blk_pread(src, offset, n, buf, 0); | ||
129 | if (ret < 0) { | ||
130 | goto ro_cleanup; | ||
131 | } | ||
132 | |||
133 | - ret = blk_pwrite(backing, offset, buf, n, 0); | ||
134 | + ret = blk_pwrite(backing, offset, n, buf, 0); | ||
135 | if (ret < 0) { | ||
136 | goto ro_cleanup; | ||
137 | } | ||
138 | diff --git a/block/crypto.c b/block/crypto.c | ||
139 | index XXXXXXX..XXXXXXX 100644 | ||
140 | --- a/block/crypto.c | ||
141 | +++ b/block/crypto.c | ||
142 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_create_write_func(QCryptoBlock *block, | ||
143 | struct BlockCryptoCreateData *data = opaque; | ||
144 | ssize_t ret; | ||
145 | |||
146 | - ret = blk_pwrite(data->blk, offset, buf, buflen, 0); | ||
147 | + ret = blk_pwrite(data->blk, offset, buflen, buf, 0); | ||
148 | if (ret < 0) { | ||
149 | error_setg_errno(errp, -ret, "Could not write encryption header"); | ||
150 | return ret; | ||
151 | diff --git a/block/export/fuse.c b/block/export/fuse.c | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/block/export/fuse.c | ||
154 | +++ b/block/export/fuse.c | ||
155 | @@ -XXX,XX +XXX,XX @@ static void fuse_read(fuse_req_t req, fuse_ino_t inode, | ||
156 | return; | ||
157 | } | ||
158 | |||
159 | - ret = blk_pread(exp->common.blk, offset, buf, size, 0); | ||
160 | + ret = blk_pread(exp->common.blk, offset, size, buf, 0); | ||
161 | if (ret >= 0) { | ||
162 | fuse_reply_buf(req, buf, size); | ||
163 | } else { | ||
164 | @@ -XXX,XX +XXX,XX @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf, | ||
165 | } | ||
166 | } | ||
167 | |||
168 | - ret = blk_pwrite(exp->common.blk, offset, buf, size, 0); | ||
169 | + ret = blk_pwrite(exp->common.blk, offset, size, buf, 0); | ||
170 | if (ret >= 0) { | ||
171 | fuse_reply_write(req, size); | ||
172 | } else { | ||
173 | diff --git a/block/parallels.c b/block/parallels.c | ||
174 | index XXXXXXX..XXXXXXX 100644 | ||
175 | --- a/block/parallels.c | ||
176 | +++ b/block/parallels.c | ||
177 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, | ||
178 | memset(tmp, 0, sizeof(tmp)); | ||
179 | memcpy(tmp, &header, sizeof(header)); | ||
180 | |||
181 | - ret = blk_pwrite(blk, 0, tmp, BDRV_SECTOR_SIZE, 0); | ||
182 | + ret = blk_pwrite(blk, 0, BDRV_SECTOR_SIZE, tmp, 0); | ||
183 | if (ret < 0) { | ||
184 | goto exit; | ||
185 | } | ||
18 | diff --git a/block/qcow.c b/block/qcow.c | 186 | diff --git a/block/qcow.c b/block/qcow.c |
19 | index XXXXXXX..XXXXXXX 100644 | 187 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/block/qcow.c | 188 | --- a/block/qcow.c |
21 | +++ b/block/qcow.c | 189 | +++ b/block/qcow.c |
22 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | 190 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, |
23 | start_sect = (offset & ~(s->cluster_size - 1)) >> 9; | 191 | } |
24 | for(i = 0; i < s->cluster_sectors; i++) { | 192 | |
25 | if (i < n_start || i >= n_end) { | 193 | /* write all the data */ |
26 | - Error *err = NULL; | 194 | - ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0); |
27 | memset(s->cluster_data, 0x00, 512); | 195 | + ret = blk_pwrite(qcow_blk, 0, sizeof(header), &header, 0); |
28 | if (qcrypto_block_encrypt(s->crypto, start_sect + i, | 196 | if (ret < 0) { |
29 | s->cluster_data, | 197 | goto exit; |
30 | BDRV_SECTOR_SIZE, | 198 | } |
31 | - &err) < 0) { | 199 | |
32 | - error_free(err); | 200 | if (qcow_opts->has_backing_file) { |
33 | + NULL) < 0) { | 201 | - ret = blk_pwrite(qcow_blk, sizeof(header), |
34 | errno = EIO; | 202 | - qcow_opts->backing_file, backing_filename_len, 0); |
35 | return -1; | 203 | + ret = blk_pwrite(qcow_blk, sizeof(header), backing_filename_len, |
36 | } | 204 | + qcow_opts->backing_file, 0); |
37 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | 205 | if (ret < 0) { |
38 | QEMUIOVector hd_qiov; | 206 | goto exit; |
39 | uint8_t *buf; | 207 | } |
40 | void *orig_buf; | 208 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts, |
41 | - Error *err = NULL; | 209 | for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE); |
42 | 210 | i++) { | |
43 | if (qiov->niov > 1) { | 211 | ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i, |
44 | buf = orig_buf = qemu_try_blockalign(bs, qiov->size); | 212 | - tmp, BDRV_SECTOR_SIZE, 0); |
45 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | 213 | + BDRV_SECTOR_SIZE, tmp, 0); |
46 | if (bs->encrypted) { | 214 | if (ret < 0) { |
47 | assert(s->crypto); | 215 | g_free(tmp); |
48 | if (qcrypto_block_decrypt(s->crypto, sector_num, buf, | 216 | goto exit; |
49 | - n * BDRV_SECTOR_SIZE, &err) < 0) { | ||
50 | + n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
51 | goto fail; | ||
52 | } | ||
53 | } | ||
54 | @@ -XXX,XX +XXX,XX @@ done: | ||
55 | return ret; | ||
56 | |||
57 | fail: | ||
58 | - error_free(err); | ||
59 | ret = -EIO; | ||
60 | goto done; | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
63 | break; | ||
64 | } | ||
65 | if (bs->encrypted) { | ||
66 | - Error *err = NULL; | ||
67 | assert(s->crypto); | ||
68 | if (qcrypto_block_encrypt(s->crypto, sector_num, buf, | ||
69 | - n * BDRV_SECTOR_SIZE, &err) < 0) { | ||
70 | - error_free(err); | ||
71 | + n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
72 | ret = -EIO; | ||
73 | break; | ||
74 | } | ||
75 | diff --git a/block/qcow2.c b/block/qcow2.c | 217 | diff --git a/block/qcow2.c b/block/qcow2.c |
76 | index XXXXXXX..XXXXXXX 100644 | 218 | index XXXXXXX..XXXXXXX 100644 |
77 | --- a/block/qcow2.c | 219 | --- a/block/qcow2.c |
78 | +++ b/block/qcow2.c | 220 | +++ b/block/qcow2.c |
79 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, | 221 | @@ -XXX,XX +XXX,XX @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) |
80 | assert(s->crypto); | 222 | cpu_to_be64(QCOW2_INCOMPAT_EXTL2); |
81 | assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0); | 223 | } |
82 | assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) == 0); | 224 | |
83 | - Error *err = NULL; | 225 | - ret = blk_pwrite(blk, 0, header, cluster_size, 0); |
84 | if (qcrypto_block_decrypt(s->crypto, | 226 | + ret = blk_pwrite(blk, 0, cluster_size, header, 0); |
85 | (s->crypt_physical_offset ? | 227 | g_free(header); |
86 | cluster_offset + offset_in_cluster : | 228 | if (ret < 0) { |
87 | offset) >> BDRV_SECTOR_BITS, | 229 | error_setg_errno(errp, -ret, "Could not write qcow2 header"); |
88 | cluster_data, | 230 | @@ -XXX,XX +XXX,XX @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) |
89 | cur_bytes, | 231 | /* Write a refcount table with one refcount block */ |
90 | - &err) < 0) { | 232 | refcount_table = g_malloc0(2 * cluster_size); |
91 | - error_free(err); | 233 | refcount_table[0] = cpu_to_be64(2 * cluster_size); |
92 | + NULL) < 0) { | 234 | - ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size, 0); |
93 | ret = -EIO; | 235 | + ret = blk_pwrite(blk, cluster_size, 2 * cluster_size, refcount_table, 0); |
94 | goto fail; | 236 | g_free(refcount_table); |
237 | |||
238 | if (ret < 0) { | ||
239 | diff --git a/block/qed.c b/block/qed.c | ||
240 | index XXXXXXX..XXXXXXX 100644 | ||
241 | --- a/block/qed.c | ||
242 | +++ b/block/qed.c | ||
243 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts, | ||
244 | } | ||
245 | |||
246 | qed_header_cpu_to_le(&header, &le_header); | ||
247 | - ret = blk_pwrite(blk, 0, &le_header, sizeof(le_header), 0); | ||
248 | + ret = blk_pwrite(blk, 0, sizeof(le_header), &le_header, 0); | ||
249 | if (ret < 0) { | ||
250 | goto out; | ||
251 | } | ||
252 | - ret = blk_pwrite(blk, sizeof(le_header), qed_opts->backing_file, | ||
253 | - header.backing_filename_size, 0); | ||
254 | + ret = blk_pwrite(blk, sizeof(le_header), header.backing_filename_size, | ||
255 | + qed_opts->backing_file, 0); | ||
256 | if (ret < 0) { | ||
257 | goto out; | ||
258 | } | ||
259 | |||
260 | l1_table = g_malloc0(l1_size); | ||
261 | - ret = blk_pwrite(blk, header.l1_table_offset, l1_table, l1_size, 0); | ||
262 | + ret = blk_pwrite(blk, header.l1_table_offset, l1_size, l1_table, 0); | ||
263 | if (ret < 0) { | ||
264 | goto out; | ||
265 | } | ||
266 | diff --git a/block/vdi.c b/block/vdi.c | ||
267 | index XXXXXXX..XXXXXXX 100644 | ||
268 | --- a/block/vdi.c | ||
269 | +++ b/block/vdi.c | ||
270 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | ||
271 | vdi_header_print(&header); | ||
272 | } | ||
273 | vdi_header_to_le(&header); | ||
274 | - ret = blk_pwrite(blk, offset, &header, sizeof(header), 0); | ||
275 | + ret = blk_pwrite(blk, offset, sizeof(header), &header, 0); | ||
276 | if (ret < 0) { | ||
277 | error_setg(errp, "Error writing header"); | ||
278 | goto exit; | ||
279 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, | ||
280 | bmap[i] = VDI_UNALLOCATED; | ||
281 | } | ||
282 | } | ||
283 | - ret = blk_pwrite(blk, offset, bmap, bmap_size, 0); | ||
284 | + ret = blk_pwrite(blk, offset, bmap_size, bmap, 0); | ||
285 | if (ret < 0) { | ||
286 | error_setg(errp, "Error writing bmap"); | ||
287 | goto exit; | ||
288 | diff --git a/block/vhdx.c b/block/vhdx.c | ||
289 | index XXXXXXX..XXXXXXX 100644 | ||
290 | --- a/block/vhdx.c | ||
291 | +++ b/block/vhdx.c | ||
292 | @@ -XXX,XX +XXX,XX @@ static int vhdx_create_new_metadata(BlockBackend *blk, | ||
293 | VHDX_META_FLAGS_IS_VIRTUAL_DISK; | ||
294 | vhdx_metadata_entry_le_export(&md_table_entry[4]); | ||
295 | |||
296 | - ret = blk_pwrite(blk, metadata_offset, buffer, VHDX_HEADER_BLOCK_SIZE, 0); | ||
297 | + ret = blk_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0); | ||
298 | if (ret < 0) { | ||
299 | goto exit; | ||
300 | } | ||
301 | |||
302 | - ret = blk_pwrite(blk, metadata_offset + (64 * KiB), entry_buffer, | ||
303 | - VHDX_METADATA_ENTRY_BUFFER_SIZE, 0); | ||
304 | + ret = blk_pwrite(blk, metadata_offset + (64 * KiB), | ||
305 | + VHDX_METADATA_ENTRY_BUFFER_SIZE, entry_buffer, 0); | ||
306 | if (ret < 0) { | ||
307 | goto exit; | ||
308 | } | ||
309 | @@ -XXX,XX +XXX,XX @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s, | ||
310 | s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]); | ||
311 | sector_num += s->sectors_per_block; | ||
312 | } | ||
313 | - ret = blk_pwrite(blk, file_offset, s->bat, length, 0); | ||
314 | + ret = blk_pwrite(blk, file_offset, length, s->bat, 0); | ||
315 | if (ret < 0) { | ||
316 | error_setg_errno(errp, -ret, "Failed to write the BAT"); | ||
317 | goto exit; | ||
318 | @@ -XXX,XX +XXX,XX @@ static int vhdx_create_new_region_table(BlockBackend *blk, | ||
319 | } | ||
320 | |||
321 | /* Now write out the region headers to disk */ | ||
322 | - ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer, | ||
323 | - VHDX_HEADER_BLOCK_SIZE, 0); | ||
324 | + ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, VHDX_HEADER_BLOCK_SIZE, | ||
325 | + buffer, 0); | ||
326 | if (ret < 0) { | ||
327 | error_setg_errno(errp, -ret, "Failed to write first region table"); | ||
328 | goto exit; | ||
329 | } | ||
330 | |||
331 | - ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer, | ||
332 | - VHDX_HEADER_BLOCK_SIZE, 0); | ||
333 | + ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, VHDX_HEADER_BLOCK_SIZE, | ||
334 | + buffer, 0); | ||
335 | if (ret < 0) { | ||
336 | error_setg_errno(errp, -ret, "Failed to write second region table"); | ||
337 | goto exit; | ||
338 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | ||
339 | creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL, | ||
340 | &creator_items, NULL); | ||
341 | signature = cpu_to_le64(VHDX_FILE_SIGNATURE); | ||
342 | - ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature), | ||
343 | + ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, sizeof(signature), &signature, | ||
344 | 0); | ||
345 | if (ret < 0) { | ||
346 | error_setg_errno(errp, -ret, "Failed to write file signature"); | ||
347 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, | ||
348 | } | ||
349 | if (creator) { | ||
350 | ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature), | ||
351 | - creator, creator_items * sizeof(gunichar2), 0); | ||
352 | + creator_items * sizeof(gunichar2), creator, 0); | ||
353 | if (ret < 0) { | ||
354 | error_setg_errno(errp, -ret, "Failed to write creator field"); | ||
355 | goto delete_and_exit; | ||
356 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
357 | index XXXXXXX..XXXXXXX 100644 | ||
358 | --- a/block/vmdk.c | ||
359 | +++ b/block/vmdk.c | ||
360 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_extent(BlockBackend *blk, | ||
361 | header.check_bytes[3] = 0xa; | ||
362 | |||
363 | /* write all the data */ | ||
364 | - ret = blk_pwrite(blk, 0, &magic, sizeof(magic), 0); | ||
365 | + ret = blk_pwrite(blk, 0, sizeof(magic), &magic, 0); | ||
366 | if (ret < 0) { | ||
367 | error_setg(errp, QERR_IO_ERROR); | ||
368 | goto exit; | ||
369 | } | ||
370 | - ret = blk_pwrite(blk, sizeof(magic), &header, sizeof(header), 0); | ||
371 | + ret = blk_pwrite(blk, sizeof(magic), sizeof(header), &header, 0); | ||
372 | if (ret < 0) { | ||
373 | error_setg(errp, QERR_IO_ERROR); | ||
374 | goto exit; | ||
375 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_extent(BlockBackend *blk, | ||
376 | gd_buf[i] = cpu_to_le32(tmp); | ||
377 | } | ||
378 | ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE, | ||
379 | - gd_buf, gd_buf_size, 0); | ||
380 | + gd_buf_size, gd_buf, 0); | ||
381 | if (ret < 0) { | ||
382 | error_setg(errp, QERR_IO_ERROR); | ||
383 | goto exit; | ||
384 | @@ -XXX,XX +XXX,XX @@ static int vmdk_init_extent(BlockBackend *blk, | ||
385 | gd_buf[i] = cpu_to_le32(tmp); | ||
386 | } | ||
387 | ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE, | ||
388 | - gd_buf, gd_buf_size, 0); | ||
389 | + gd_buf_size, gd_buf, 0); | ||
390 | if (ret < 0) { | ||
391 | error_setg(errp, QERR_IO_ERROR); | ||
392 | } | ||
393 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vmdk_co_do_create(int64_t size, | ||
394 | desc_offset = 0x200; | ||
395 | } | ||
396 | |||
397 | - ret = blk_pwrite(blk, desc_offset, desc, desc_len, 0); | ||
398 | + ret = blk_pwrite(blk, desc_offset, desc_len, desc, 0); | ||
399 | if (ret < 0) { | ||
400 | error_setg_errno(errp, -ret, "Could not write description"); | ||
401 | goto exit; | ||
402 | diff --git a/block/vpc.c b/block/vpc.c | ||
403 | index XXXXXXX..XXXXXXX 100644 | ||
404 | --- a/block/vpc.c | ||
405 | +++ b/block/vpc.c | ||
406 | @@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer, | ||
407 | block_size = 0x200000; | ||
408 | num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512); | ||
409 | |||
410 | - ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); | ||
411 | + ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0); | ||
412 | if (ret < 0) { | ||
413 | goto fail; | ||
414 | } | ||
415 | |||
416 | offset = 1536 + ((num_bat_entries * 4 + 511) & ~511); | ||
417 | - ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0); | ||
418 | + ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0); | ||
419 | if (ret < 0) { | ||
420 | goto fail; | ||
421 | } | ||
422 | @@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer, | ||
423 | |||
424 | memset(bat_sector, 0xFF, 512); | ||
425 | for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) { | ||
426 | - ret = blk_pwrite(blk, offset, bat_sector, 512, 0); | ||
427 | + ret = blk_pwrite(blk, offset, 512, bat_sector, 0); | ||
428 | if (ret < 0) { | ||
429 | goto fail; | ||
430 | } | ||
431 | @@ -XXX,XX +XXX,XX @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer, | ||
432 | /* Write the header */ | ||
433 | offset = 512; | ||
434 | |||
435 | - ret = blk_pwrite(blk, offset, &dyndisk_header, sizeof(dyndisk_header), 0); | ||
436 | + ret = blk_pwrite(blk, offset, sizeof(dyndisk_header), &dyndisk_header, 0); | ||
437 | if (ret < 0) { | ||
438 | goto fail; | ||
439 | } | ||
440 | @@ -XXX,XX +XXX,XX @@ static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer, | ||
441 | return ret; | ||
442 | } | ||
443 | |||
444 | - ret = blk_pwrite(blk, total_size - sizeof(*footer), | ||
445 | - footer, sizeof(*footer), 0); | ||
446 | + ret = blk_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer), | ||
447 | + footer, 0); | ||
448 | if (ret < 0) { | ||
449 | error_setg_errno(errp, -ret, "Unable to write VHD header"); | ||
450 | return ret; | ||
451 | diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c | ||
452 | index XXXXXXX..XXXXXXX 100644 | ||
453 | --- a/hw/arm/allwinner-h3.c | ||
454 | +++ b/hw/arm/allwinner-h3.c | ||
455 | @@ -XXX,XX +XXX,XX @@ void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk) | ||
456 | const int64_t rom_size = 32 * KiB; | ||
457 | g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size); | ||
458 | |||
459 | - if (blk_pread(blk, 8 * KiB, buffer, rom_size, 0) < 0) { | ||
460 | + if (blk_pread(blk, 8 * KiB, rom_size, buffer, 0) < 0) { | ||
461 | error_setg(&error_fatal, "%s: failed to read BlockBackend data", | ||
462 | __func__); | ||
463 | return; | ||
464 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/hw/arm/aspeed.c | ||
467 | +++ b/hw/arm/aspeed.c | ||
468 | @@ -XXX,XX +XXX,XX @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size, | ||
469 | } | ||
470 | |||
471 | storage = g_malloc0(rom_size); | ||
472 | - if (blk_pread(blk, 0, storage, rom_size, 0) < 0) { | ||
473 | + if (blk_pread(blk, 0, rom_size, storage, 0) < 0) { | ||
474 | error_setg(errp, "failed to read the initial flash content"); | ||
475 | return; | ||
476 | } | ||
477 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
478 | index XXXXXXX..XXXXXXX 100644 | ||
479 | --- a/hw/block/block.c | ||
480 | +++ b/hw/block/block.c | ||
481 | @@ -XXX,XX +XXX,XX @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size, | ||
482 | * block device and read only on demand. | ||
483 | */ | ||
484 | assert(size <= BDRV_REQUEST_MAX_BYTES); | ||
485 | - ret = blk_pread(blk, 0, buf, size, 0); | ||
486 | + ret = blk_pread(blk, 0, size, buf, 0); | ||
487 | if (ret < 0) { | ||
488 | error_setg_errno(errp, -ret, "can't read block backend"); | ||
489 | return false; | ||
490 | diff --git a/hw/block/fdc.c b/hw/block/fdc.c | ||
491 | index XXXXXXX..XXXXXXX 100644 | ||
492 | --- a/hw/block/fdc.c | ||
493 | +++ b/hw/block/fdc.c | ||
494 | @@ -XXX,XX +XXX,XX @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len) | ||
495 | if (fdctrl->data_dir != FD_DIR_WRITE || | ||
496 | len < FD_SECTOR_LEN || rel_pos != 0) { | ||
497 | /* READ & SCAN commands and realign to a sector for WRITE */ | ||
498 | - if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, | ||
499 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
500 | + if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE, | ||
501 | + fdctrl->fifo, 0) < 0) { | ||
502 | FLOPPY_DPRINTF("Floppy: error getting sector %d\n", | ||
503 | fd_sector(cur_drv)); | ||
504 | /* Sure, image size is too small... */ | ||
505 | @@ -XXX,XX +XXX,XX @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len) | ||
506 | |||
507 | k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos, | ||
508 | fdctrl->data_pos, len); | ||
509 | - if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), | ||
510 | - fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) { | ||
511 | + if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE, | ||
512 | + fdctrl->fifo, 0) < 0) { | ||
513 | FLOPPY_DPRINTF("error writing sector %d\n", | ||
514 | fd_sector(cur_drv)); | ||
515 | fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); | ||
516 | @@ -XXX,XX +XXX,XX @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl) | ||
517 | fd_sector(cur_drv)); | ||
518 | return 0; | ||
95 | } | 519 | } |
96 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, | 520 | - if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, |
97 | qemu_iovec_concat(&hd_qiov, qiov, bytes_done, cur_bytes); | 521 | - BDRV_SECTOR_SIZE, 0) |
98 | 522 | + if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE, | |
99 | if (bs->encrypted) { | 523 | + fdctrl->fifo, 0) |
100 | - Error *err = NULL; | 524 | < 0) { |
101 | assert(s->crypto); | 525 | FLOPPY_DPRINTF("error getting sector %d\n", |
102 | if (!cluster_data) { | 526 | fd_sector(cur_drv)); |
103 | cluster_data = qemu_try_blockalign(bs->file->bs, | 527 | @@ -XXX,XX +XXX,XX @@ static void fdctrl_format_sector(FDCtrl *fdctrl) |
104 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, | 528 | } |
105 | cluster_offset + offset_in_cluster : | 529 | memset(fdctrl->fifo, 0, FD_SECTOR_LEN); |
106 | offset) >> BDRV_SECTOR_BITS, | 530 | if (cur_drv->blk == NULL || |
107 | cluster_data, | 531 | - blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, |
108 | - cur_bytes, &err) < 0) { | 532 | - BDRV_SECTOR_SIZE, 0) < 0) { |
109 | - error_free(err); | 533 | + blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE, |
110 | + cur_bytes, NULL) < 0) { | 534 | + fdctrl->fifo, 0) < 0) { |
111 | ret = -EIO; | 535 | FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv)); |
536 | fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00); | ||
537 | } else { | ||
538 | @@ -XXX,XX +XXX,XX @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value) | ||
539 | if (pos == FD_SECTOR_LEN - 1 || | ||
540 | fdctrl->data_pos == fdctrl->data_len) { | ||
541 | cur_drv = get_cur_drv(fdctrl); | ||
542 | - if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo, | ||
543 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
544 | + if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE, | ||
545 | + fdctrl->fifo, 0) < 0) { | ||
546 | FLOPPY_DPRINTF("error writing sector %d\n", | ||
547 | fd_sector(cur_drv)); | ||
548 | break; | ||
549 | diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c | ||
550 | index XXXXXXX..XXXXXXX 100644 | ||
551 | --- a/hw/block/hd-geometry.c | ||
552 | +++ b/hw/block/hd-geometry.c | ||
553 | @@ -XXX,XX +XXX,XX @@ static int guess_disk_lchs(BlockBackend *blk, | ||
554 | |||
555 | blk_get_geometry(blk, &nb_sectors); | ||
556 | |||
557 | - if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE, 0) < 0) { | ||
558 | + if (blk_pread(blk, 0, BDRV_SECTOR_SIZE, buf, 0) < 0) { | ||
559 | return -1; | ||
560 | } | ||
561 | /* test msdos magic */ | ||
562 | diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c | ||
563 | index XXXXXXX..XXXXXXX 100644 | ||
564 | --- a/hw/block/m25p80.c | ||
565 | +++ b/hw/block/m25p80.c | ||
566 | @@ -XXX,XX +XXX,XX @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp) | ||
567 | trace_m25p80_binding(s); | ||
568 | s->storage = blk_blockalign(s->blk, s->size); | ||
569 | |||
570 | - if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { | ||
571 | + if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) { | ||
572 | error_setg(errp, "failed to read the initial flash content"); | ||
573 | return; | ||
574 | } | ||
575 | diff --git a/hw/block/nand.c b/hw/block/nand.c | ||
576 | index XXXXXXX..XXXXXXX 100644 | ||
577 | --- a/hw/block/nand.c | ||
578 | +++ b/hw/block/nand.c | ||
579 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
580 | sector = SECTOR(s->addr); | ||
581 | off = (s->addr & PAGE_MASK) + s->offset; | ||
582 | soff = SECTOR_OFFSET(s->addr); | ||
583 | - if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
584 | - PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { | ||
585 | + if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, | ||
586 | + PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) { | ||
587 | printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); | ||
588 | return; | ||
589 | } | ||
590 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
591 | MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE)); | ||
592 | } | ||
593 | |||
594 | - if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
595 | - PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { | ||
596 | + if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, | ||
597 | + PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) { | ||
598 | printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); | ||
599 | } | ||
600 | } else { | ||
601 | off = PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset; | ||
602 | sector = off >> 9; | ||
603 | soff = off & 0x1ff; | ||
604 | - if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
605 | - (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { | ||
606 | + if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, | ||
607 | + (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) { | ||
608 | printf("%s: read error in sector %" PRIu64 "\n", __func__, sector); | ||
609 | return; | ||
610 | } | ||
611 | |||
612 | mem_and(iobuf + soff, s->io, s->iolen); | ||
613 | |||
614 | - if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, | ||
615 | - (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { | ||
616 | + if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, | ||
617 | + (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) { | ||
618 | printf("%s: write error in sector %" PRIu64 "\n", __func__, sector); | ||
619 | } | ||
620 | } | ||
621 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
622 | i = SECTOR(addr); | ||
623 | page = SECTOR(addr + (1 << (ADDR_SHIFT + s->erase_shift))); | ||
624 | for (; i < page; i ++) | ||
625 | - if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS, iobuf, | ||
626 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
627 | + if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS, | ||
628 | + BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
629 | printf("%s: write error in sector %" PRIu64 "\n", __func__, i); | ||
630 | } | ||
631 | } else { | ||
632 | addr = PAGE_START(addr); | ||
633 | page = addr >> 9; | ||
634 | - if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
635 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
636 | + if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, | ||
637 | + BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
638 | printf("%s: read error in sector %" PRIu64 "\n", __func__, page); | ||
639 | } | ||
640 | memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1); | ||
641 | - if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
642 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
643 | + if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, | ||
644 | + BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
645 | printf("%s: write error in sector %" PRIu64 "\n", __func__, page); | ||
646 | } | ||
647 | |||
648 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) | ||
649 | i = (addr & ~0x1ff) + 0x200; | ||
650 | for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; | ||
651 | i < addr; i += 0x200) { | ||
652 | - if (blk_pwrite(s->blk, i, iobuf, BDRV_SECTOR_SIZE, 0) < 0) { | ||
653 | + if (blk_pwrite(s->blk, i, BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
654 | printf("%s: write error in sector %" PRIu64 "\n", | ||
655 | __func__, i >> 9); | ||
656 | } | ||
657 | } | ||
658 | |||
659 | page = i >> 9; | ||
660 | - if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
661 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
662 | + if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, | ||
663 | + BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
664 | printf("%s: read error in sector %" PRIu64 "\n", __func__, page); | ||
665 | } | ||
666 | memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1); | ||
667 | - if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf, | ||
668 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
669 | + if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, | ||
670 | + BDRV_SECTOR_SIZE, iobuf, 0) < 0) { | ||
671 | printf("%s: write error in sector %" PRIu64 "\n", __func__, page); | ||
672 | } | ||
673 | } | ||
674 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, | ||
675 | |||
676 | if (s->blk) { | ||
677 | if (s->mem_oob) { | ||
678 | - if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS, s->io, | ||
679 | - PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) { | ||
680 | + if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS, | ||
681 | + PAGE_SECTORS << BDRV_SECTOR_BITS, s->io, 0) < 0) { | ||
682 | printf("%s: read error in sector %" PRIu64 "\n", | ||
683 | __func__, SECTOR(addr)); | ||
684 | } | ||
685 | @@ -XXX,XX +XXX,XX @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, | ||
686 | OOB_SIZE); | ||
687 | s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; | ||
688 | } else { | ||
689 | - if (blk_pread(s->blk, PAGE_START(addr), s->io, | ||
690 | - (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) { | ||
691 | + if (blk_pread(s->blk, PAGE_START(addr), | ||
692 | + (PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, s->io, 0) | ||
693 | + < 0) { | ||
694 | printf("%s: read error in sector %" PRIu64 "\n", | ||
695 | __func__, PAGE_START(addr) >> 9); | ||
696 | } | ||
697 | diff --git a/hw/block/onenand.c b/hw/block/onenand.c | ||
698 | index XXXXXXX..XXXXXXX 100644 | ||
699 | --- a/hw/block/onenand.c | ||
700 | +++ b/hw/block/onenand.c | ||
701 | @@ -XXX,XX +XXX,XX @@ static void onenand_reset(OneNANDState *s, int cold) | ||
702 | /* Lock the whole flash */ | ||
703 | memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); | ||
704 | |||
705 | - if (s->blk_cur && blk_pread(s->blk_cur, 0, s->boot[0], | ||
706 | - 8 << BDRV_SECTOR_BITS, 0) < 0) { | ||
707 | + if (s->blk_cur && blk_pread(s->blk_cur, 0, 8 << BDRV_SECTOR_BITS, | ||
708 | + s->boot[0], 0) < 0) { | ||
709 | hw_error("%s: Loading the BootRAM failed.\n", __func__); | ||
710 | } | ||
711 | } | ||
712 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn, | ||
713 | assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec); | ||
714 | assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn); | ||
715 | if (s->blk_cur) { | ||
716 | - return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, dest, | ||
717 | - secn << BDRV_SECTOR_BITS, 0) < 0; | ||
718 | + return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, | ||
719 | + secn << BDRV_SECTOR_BITS, dest, 0) < 0; | ||
720 | } else if (sec + secn > s->secs_cur) { | ||
721 | return 1; | ||
722 | } | ||
723 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, | ||
724 | uint8_t *dp = 0; | ||
725 | if (s->blk_cur) { | ||
726 | dp = g_malloc(size); | ||
727 | - if (!dp || blk_pread(s->blk_cur, offset, dp, size, 0) < 0) { | ||
728 | + if (!dp || blk_pread(s->blk_cur, offset, size, dp, 0) < 0) { | ||
729 | result = 1; | ||
730 | } | ||
731 | } else { | ||
732 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, | ||
733 | dp[i] &= sp[i]; | ||
734 | } | ||
735 | if (s->blk_cur) { | ||
736 | - result = blk_pwrite(s->blk_cur, offset, dp, size, 0) < 0; | ||
737 | + result = blk_pwrite(s->blk_cur, offset, size, dp, 0) < 0; | ||
738 | } | ||
739 | } | ||
740 | if (dp && s->blk_cur) { | ||
741 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn, | ||
742 | |||
743 | if (s->blk_cur) { | ||
744 | uint32_t offset = (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS; | ||
745 | - if (blk_pread(s->blk_cur, offset, buf, BDRV_SECTOR_SIZE, 0) < 0) { | ||
746 | + if (blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, buf, 0) < 0) { | ||
747 | return 1; | ||
748 | } | ||
749 | memcpy(dest, buf + ((sec & 31) << 4), secn << 4); | ||
750 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, | ||
751 | if (s->blk_cur) { | ||
752 | dp = g_malloc(512); | ||
753 | if (!dp | ||
754 | - || blk_pread(s->blk_cur, offset, dp, BDRV_SECTOR_SIZE, 0) < 0) { | ||
755 | + || blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp, 0) < 0) { | ||
756 | result = 1; | ||
757 | } else { | ||
758 | dpp = dp + ((sec & 31) << 4); | ||
759 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, | ||
760 | dpp[i] &= sp[i]; | ||
761 | } | ||
762 | if (s->blk_cur) { | ||
763 | - result = blk_pwrite(s->blk_cur, offset, dp, | ||
764 | - BDRV_SECTOR_SIZE, 0) < 0; | ||
765 | + result = blk_pwrite(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp, | ||
766 | + 0) < 0; | ||
767 | } | ||
768 | } | ||
769 | g_free(dp); | ||
770 | @@ -XXX,XX +XXX,XX @@ static inline int onenand_erase(OneNANDState *s, int sec, int num) | ||
771 | for (; num > 0; num--, sec++) { | ||
772 | if (s->blk_cur) { | ||
773 | int erasesec = s->secs_cur + (sec >> 5); | ||
774 | - if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS, blankbuf, | ||
775 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
776 | + if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS, | ||
777 | + BDRV_SECTOR_SIZE, blankbuf, 0) < 0) { | ||
112 | goto fail; | 778 | goto fail; |
113 | } | 779 | } |
114 | diff --git a/dump.c b/dump.c | 780 | - if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf, |
115 | index XXXXXXX..XXXXXXX 100644 | 781 | - BDRV_SECTOR_SIZE, 0) < 0) { |
116 | --- a/dump.c | 782 | + if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, |
117 | +++ b/dump.c | 783 | + BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) { |
118 | @@ -XXX,XX +XXX,XX @@ static void dump_process(DumpState *s, Error **errp) | 784 | goto fail; |
119 | 785 | } | |
120 | static void *dump_thread(void *data) | 786 | memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); |
787 | - if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf, | ||
788 | - BDRV_SECTOR_SIZE, 0) < 0) { | ||
789 | + if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS, | ||
790 | + BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) { | ||
791 | goto fail; | ||
792 | } | ||
793 | } else { | ||
794 | diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c | ||
795 | index XXXXXXX..XXXXXXX 100644 | ||
796 | --- a/hw/block/pflash_cfi01.c | ||
797 | +++ b/hw/block/pflash_cfi01.c | ||
798 | @@ -XXX,XX +XXX,XX @@ static void pflash_update(PFlashCFI01 *pfl, int offset, | ||
799 | /* widen to sector boundaries */ | ||
800 | offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); | ||
801 | offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); | ||
802 | - ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset, | ||
803 | - offset_end - offset, 0); | ||
804 | + ret = blk_pwrite(pfl->blk, offset, offset_end - offset, | ||
805 | + pfl->storage + offset, 0); | ||
806 | if (ret < 0) { | ||
807 | /* TODO set error bit in status */ | ||
808 | error_report("Could not update PFLASH: %s", strerror(-ret)); | ||
809 | diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c | ||
810 | index XXXXXXX..XXXXXXX 100644 | ||
811 | --- a/hw/block/pflash_cfi02.c | ||
812 | +++ b/hw/block/pflash_cfi02.c | ||
813 | @@ -XXX,XX +XXX,XX @@ static void pflash_update(PFlashCFI02 *pfl, int offset, int size) | ||
814 | /* widen to sector boundaries */ | ||
815 | offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); | ||
816 | offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); | ||
817 | - ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset, | ||
818 | - offset_end - offset, 0); | ||
819 | + ret = blk_pwrite(pfl->blk, offset, offset_end - offset, | ||
820 | + pfl->storage + offset, 0); | ||
821 | if (ret < 0) { | ||
822 | /* TODO set error bit in status */ | ||
823 | error_report("Could not update PFLASH: %s", strerror(-ret)); | ||
824 | diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c | ||
825 | index XXXXXXX..XXXXXXX 100644 | ||
826 | --- a/hw/ide/atapi.c | ||
827 | +++ b/hw/ide/atapi.c | ||
828 | @@ -XXX,XX +XXX,XX @@ cd_read_sector_sync(IDEState *s) | ||
829 | switch (s->cd_sector_size) { | ||
830 | case 2048: | ||
831 | ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, | ||
832 | - s->io_buffer, ATAPI_SECTOR_SIZE, 0); | ||
833 | + ATAPI_SECTOR_SIZE, s->io_buffer, 0); | ||
834 | break; | ||
835 | case 2352: | ||
836 | ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS, | ||
837 | - s->io_buffer + 16, ATAPI_SECTOR_SIZE, 0); | ||
838 | + ATAPI_SECTOR_SIZE, s->io_buffer + 16, 0); | ||
839 | if (ret >= 0) { | ||
840 | cd_data_to_raw(s->io_buffer, s->lba); | ||
841 | } | ||
842 | diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c | ||
843 | index XXXXXXX..XXXXXXX 100644 | ||
844 | --- a/hw/misc/mac_via.c | ||
845 | +++ b/hw/misc/mac_via.c | ||
846 | @@ -XXX,XX +XXX,XX @@ static void via1_one_second(void *opaque) | ||
847 | static void pram_update(MOS6522Q800VIA1State *v1s) | ||
121 | { | 848 | { |
122 | - Error *err = NULL; | 849 | if (v1s->blk) { |
123 | DumpState *s = (DumpState *)data; | 850 | - if (blk_pwrite(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0) < 0) { |
124 | - dump_process(s, &err); | 851 | + if (blk_pwrite(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0) < 0) { |
125 | - error_free(err); | 852 | qemu_log("pram_update: cannot write to file\n"); |
126 | + dump_process(s, NULL); | 853 | } |
127 | return NULL; | 854 | } |
855 | @@ -XXX,XX +XXX,XX @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp) | ||
856 | return; | ||
857 | } | ||
858 | |||
859 | - ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0); | ||
860 | + ret = blk_pread(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0); | ||
861 | if (ret < 0) { | ||
862 | error_setg(errp, "can't read PRAM contents"); | ||
863 | return; | ||
864 | diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c | ||
865 | index XXXXXXX..XXXXXXX 100644 | ||
866 | --- a/hw/misc/sifive_u_otp.c | ||
867 | +++ b/hw/misc/sifive_u_otp.c | ||
868 | @@ -XXX,XX +XXX,XX @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size) | ||
869 | if (s->blk) { | ||
870 | int32_t buf; | ||
871 | |||
872 | - if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf, | ||
873 | - SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { | ||
874 | + if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, | ||
875 | + SIFIVE_U_OTP_FUSE_WORD, &buf, 0) < 0) { | ||
876 | error_report("read error index<%d>", s->pa); | ||
877 | return 0xff; | ||
878 | } | ||
879 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_write(void *opaque, hwaddr addr, | ||
880 | /* write to backend */ | ||
881 | if (s->blk) { | ||
882 | if (blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, | ||
883 | - &s->fuse[s->pa], SIFIVE_U_OTP_FUSE_WORD, | ||
884 | - 0) < 0) { | ||
885 | + SIFIVE_U_OTP_FUSE_WORD, &s->fuse[s->pa], 0) | ||
886 | + < 0) { | ||
887 | error_report("write error index<%d>", s->pa); | ||
888 | } | ||
889 | } | ||
890 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp) | ||
891 | return; | ||
892 | } | ||
893 | |||
894 | - if (blk_pread(s->blk, 0, s->fuse, filesize, 0) < 0) { | ||
895 | + if (blk_pread(s->blk, 0, filesize, s->fuse, 0) < 0) { | ||
896 | error_setg(errp, "failed to read the initial flash content"); | ||
897 | return; | ||
898 | } | ||
899 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp) | ||
900 | |||
901 | serial_data = s->serial; | ||
902 | if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD, | ||
903 | - &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { | ||
904 | + SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) { | ||
905 | error_setg(errp, "failed to write index<%d>", index); | ||
906 | return; | ||
907 | } | ||
908 | |||
909 | serial_data = ~(s->serial); | ||
910 | if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD, | ||
911 | - &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) { | ||
912 | + SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) { | ||
913 | error_setg(errp, "failed to write index<%d>", index + 1); | ||
914 | return; | ||
915 | } | ||
916 | diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c | ||
917 | index XXXXXXX..XXXXXXX 100644 | ||
918 | --- a/hw/nvram/eeprom_at24c.c | ||
919 | +++ b/hw/nvram/eeprom_at24c.c | ||
920 | @@ -XXX,XX +XXX,XX @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event) | ||
921 | case I2C_START_RECV: | ||
922 | DPRINTK("clear\n"); | ||
923 | if (ee->blk && ee->changed) { | ||
924 | - int ret = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0); | ||
925 | + int ret = blk_pwrite(ee->blk, 0, ee->rsize, ee->mem, 0); | ||
926 | if (ret < 0) { | ||
927 | ERR(TYPE_AT24C_EE | ||
928 | " : failed to write backing file\n"); | ||
929 | @@ -XXX,XX +XXX,XX @@ void at24c_eeprom_reset(DeviceState *state) | ||
930 | memset(ee->mem, 0, ee->rsize); | ||
931 | |||
932 | if (ee->blk) { | ||
933 | - int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0); | ||
934 | + int ret = blk_pread(ee->blk, 0, ee->rsize, ee->mem, 0); | ||
935 | |||
936 | if (ret < 0) { | ||
937 | ERR(TYPE_AT24C_EE | ||
938 | diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c | ||
939 | index XXXXXXX..XXXXXXX 100644 | ||
940 | --- a/hw/nvram/spapr_nvram.c | ||
941 | +++ b/hw/nvram/spapr_nvram.c | ||
942 | @@ -XXX,XX +XXX,XX @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr, | ||
943 | |||
944 | ret = 0; | ||
945 | if (nvram->blk) { | ||
946 | - ret = blk_pwrite(nvram->blk, offset, membuf, len, 0); | ||
947 | + ret = blk_pwrite(nvram->blk, offset, len, membuf, 0); | ||
948 | } | ||
949 | |||
950 | assert(nvram->buf); | ||
951 | @@ -XXX,XX +XXX,XX @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp) | ||
952 | } | ||
953 | |||
954 | if (nvram->blk) { | ||
955 | - ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0); | ||
956 | + ret = blk_pread(nvram->blk, 0, nvram->size, nvram->buf, 0); | ||
957 | |||
958 | if (ret < 0) { | ||
959 | error_setg(errp, "can't read spapr-nvram contents"); | ||
960 | @@ -XXX,XX +XXX,XX @@ static void postload_update_cb(void *opaque, bool running, RunState state) | ||
961 | qemu_del_vm_change_state_handler(nvram->vmstate); | ||
962 | nvram->vmstate = NULL; | ||
963 | |||
964 | - blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0); | ||
965 | + blk_pwrite(nvram->blk, 0, nvram->size, nvram->buf, 0); | ||
128 | } | 966 | } |
129 | 967 | ||
968 | static int spapr_nvram_post_load(void *opaque, int version_id) | ||
969 | diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c | ||
970 | index XXXXXXX..XXXXXXX 100644 | ||
971 | --- a/hw/nvram/xlnx-bbram.c | ||
972 | +++ b/hw/nvram/xlnx-bbram.c | ||
973 | @@ -XXX,XX +XXX,XX @@ static void bbram_bdrv_read(XlnxBBRam *s, Error **errp) | ||
974 | blk_name(s->blk)); | ||
975 | } | ||
976 | |||
977 | - if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { | ||
978 | + if (blk_pread(s->blk, 0, nr, ram, 0) < 0) { | ||
979 | error_setg(errp, | ||
980 | "%s: Failed to read %u bytes from BBRAM backstore.", | ||
981 | blk_name(s->blk), nr); | ||
982 | @@ -XXX,XX +XXX,XX @@ static void bbram_bdrv_sync(XlnxBBRam *s, uint64_t hwaddr) | ||
983 | } | ||
984 | |||
985 | offset = hwaddr - A_BBRAM_0; | ||
986 | - rc = blk_pwrite(s->blk, offset, &le32, 4, 0); | ||
987 | + rc = blk_pwrite(s->blk, offset, 4, &le32, 0); | ||
988 | if (rc < 0) { | ||
989 | bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offset)); | ||
990 | } | ||
991 | diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c | ||
992 | index XXXXXXX..XXXXXXX 100644 | ||
993 | --- a/hw/nvram/xlnx-efuse.c | ||
994 | +++ b/hw/nvram/xlnx-efuse.c | ||
995 | @@ -XXX,XX +XXX,XX @@ static int efuse_bdrv_read(XlnxEFuse *s, Error **errp) | ||
996 | blk_name(s->blk)); | ||
997 | } | ||
998 | |||
999 | - if (blk_pread(s->blk, 0, ram, nr, 0) < 0) { | ||
1000 | + if (blk_pread(s->blk, 0, nr, ram, 0) < 0) { | ||
1001 | error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.", | ||
1002 | blk_name(s->blk), nr); | ||
1003 | return -1; | ||
1004 | @@ -XXX,XX +XXX,XX @@ static void efuse_bdrv_sync(XlnxEFuse *s, unsigned int bit) | ||
1005 | le32 = cpu_to_le32(xlnx_efuse_get_row(s, bit)); | ||
1006 | |||
1007 | row_offset = (bit / 32) * 4; | ||
1008 | - if (blk_pwrite(s->blk, row_offset, &le32, 4, 0) < 0) { | ||
1009 | + if (blk_pwrite(s->blk, row_offset, 4, &le32, 0) < 0) { | ||
1010 | error_report("%s: Failed to write offset %u of eFUSE backstore.", | ||
1011 | blk_name(s->blk), row_offset); | ||
1012 | } | ||
1013 | diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c | ||
1014 | index XXXXXXX..XXXXXXX 100644 | ||
1015 | --- a/hw/ppc/pnv_pnor.c | ||
1016 | +++ b/hw/ppc/pnv_pnor.c | ||
1017 | @@ -XXX,XX +XXX,XX @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size) | ||
1018 | offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); | ||
1019 | offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE); | ||
1020 | |||
1021 | - ret = blk_pwrite(s->blk, offset, s->storage + offset, | ||
1022 | - offset_end - offset, 0); | ||
1023 | + ret = blk_pwrite(s->blk, offset, offset_end - offset, s->storage + offset, | ||
1024 | + 0); | ||
1025 | if (ret < 0) { | ||
1026 | error_report("Could not update PNOR offset=0x%" PRIx32" : %s", offset, | ||
1027 | strerror(-ret)); | ||
1028 | @@ -XXX,XX +XXX,XX @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp) | ||
1029 | |||
1030 | s->storage = blk_blockalign(s->blk, s->size); | ||
1031 | |||
1032 | - if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) { | ||
1033 | + if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) { | ||
1034 | error_setg(errp, "failed to read the initial flash content"); | ||
1035 | return; | ||
1036 | } | ||
1037 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
1038 | index XXXXXXX..XXXXXXX 100644 | ||
1039 | --- a/hw/sd/sd.c | ||
1040 | +++ b/hw/sd/sd.c | ||
1041 | @@ -XXX,XX +XXX,XX @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) | ||
1042 | static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) | ||
1043 | { | ||
1044 | trace_sdcard_read_block(addr, len); | ||
1045 | - if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len, 0) < 0) { | ||
1046 | + if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) { | ||
1047 | fprintf(stderr, "sd_blk_read: read error on host side\n"); | ||
1048 | } | ||
1049 | } | ||
1050 | @@ -XXX,XX +XXX,XX @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) | ||
1051 | static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) | ||
1052 | { | ||
1053 | trace_sdcard_write_block(addr, len); | ||
1054 | - if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) { | ||
1055 | + if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) { | ||
1056 | fprintf(stderr, "sd_blk_write: write error on host side\n"); | ||
1057 | } | ||
1058 | } | ||
1059 | diff --git a/migration/block.c b/migration/block.c | ||
1060 | index XXXXXXX..XXXXXXX 100644 | ||
1061 | --- a/migration/block.c | ||
1062 | +++ b/migration/block.c | ||
1063 | @@ -XXX,XX +XXX,XX @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds, | ||
1064 | blk_mig_unlock(); | ||
1065 | } else { | ||
1066 | ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, | ||
1067 | - blk->buf, nr_sectors * BDRV_SECTOR_SIZE, 0); | ||
1068 | + nr_sectors * BDRV_SECTOR_SIZE, blk->buf, 0); | ||
1069 | if (ret < 0) { | ||
1070 | goto error; | ||
1071 | } | ||
1072 | @@ -XXX,XX +XXX,XX @@ static int block_load(QEMUFile *f, void *opaque, int version_id) | ||
1073 | cluster_size, | ||
1074 | BDRV_REQ_MAY_UNMAP); | ||
1075 | } else { | ||
1076 | - ret = blk_pwrite(blk, cur_addr, cur_buf, | ||
1077 | - cluster_size, 0); | ||
1078 | + ret = blk_pwrite(blk, cur_addr, cluster_size, cur_buf, | ||
1079 | + 0); | ||
1080 | } | ||
1081 | if (ret < 0) { | ||
1082 | break; | ||
1083 | diff --git a/nbd/server.c b/nbd/server.c | ||
1084 | index XXXXXXX..XXXXXXX 100644 | ||
1085 | --- a/nbd/server.c | ||
1086 | +++ b/nbd/server.c | ||
1087 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, | ||
1088 | stl_be_p(&chunk.length, pnum); | ||
1089 | ret = nbd_co_send_iov(client, iov, 1, errp); | ||
1090 | } else { | ||
1091 | - ret = blk_pread(exp->common.blk, offset + progress, | ||
1092 | - data + progress, pnum, 0); | ||
1093 | + ret = blk_pread(exp->common.blk, offset + progress, pnum, | ||
1094 | + data + progress, 0); | ||
1095 | if (ret < 0) { | ||
1096 | error_setg_errno(errp, -ret, "reading from file failed"); | ||
1097 | break; | ||
1098 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request, | ||
1099 | data, request->len, errp); | ||
1100 | } | ||
1101 | |||
1102 | - ret = blk_pread(exp->common.blk, request->from, data, request->len, 0); | ||
1103 | + ret = blk_pread(exp->common.blk, request->from, request->len, data, 0); | ||
1104 | if (ret < 0) { | ||
1105 | return nbd_send_generic_reply(client, request->handle, ret, | ||
1106 | "reading from file failed", errp); | ||
1107 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int nbd_handle_request(NBDClient *client, | ||
1108 | if (request->flags & NBD_CMD_FLAG_FUA) { | ||
1109 | flags |= BDRV_REQ_FUA; | ||
1110 | } | ||
1111 | - ret = blk_pwrite(exp->common.blk, request->from, data, request->len, | ||
1112 | + ret = blk_pwrite(exp->common.blk, request->from, request->len, data, | ||
1113 | flags); | ||
1114 | return nbd_send_generic_reply(client, request->handle, ret, | ||
1115 | "writing to file failed", errp); | ||
1116 | diff --git a/qemu-img.c b/qemu-img.c | ||
1117 | index XXXXXXX..XXXXXXX 100644 | ||
1118 | --- a/qemu-img.c | ||
1119 | +++ b/qemu-img.c | ||
1120 | @@ -XXX,XX +XXX,XX @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset, | ||
1121 | int ret = 0; | ||
1122 | int64_t idx; | ||
1123 | |||
1124 | - ret = blk_pread(blk, offset, buffer, bytes, 0); | ||
1125 | + ret = blk_pread(blk, offset, bytes, buffer, 0); | ||
1126 | if (ret < 0) { | ||
1127 | error_report("Error while reading offset %" PRId64 " of %s: %s", | ||
1128 | offset, filename, strerror(-ret)); | ||
1129 | @@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv) | ||
1130 | int64_t pnum; | ||
1131 | |||
1132 | chunk = MIN(chunk, IO_BUF_SIZE); | ||
1133 | - ret = blk_pread(blk1, offset, buf1, chunk, 0); | ||
1134 | + ret = blk_pread(blk1, offset, chunk, buf1, 0); | ||
1135 | if (ret < 0) { | ||
1136 | error_report("Error while reading offset %" PRId64 | ||
1137 | " of %s: %s", | ||
1138 | @@ -XXX,XX +XXX,XX @@ static int img_compare(int argc, char **argv) | ||
1139 | ret = 4; | ||
1140 | goto out; | ||
1141 | } | ||
1142 | - ret = blk_pread(blk2, offset, buf2, chunk, 0); | ||
1143 | + ret = blk_pread(blk2, offset, chunk, buf2, 0); | ||
1144 | if (ret < 0) { | ||
1145 | error_report("Error while reading offset %" PRId64 | ||
1146 | " of %s: %s", | ||
1147 | @@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv) | ||
1148 | n = old_backing_size - offset; | ||
1149 | } | ||
1150 | |||
1151 | - ret = blk_pread(blk_old_backing, offset, buf_old, n, 0); | ||
1152 | + ret = blk_pread(blk_old_backing, offset, n, buf_old, 0); | ||
1153 | if (ret < 0) { | ||
1154 | error_report("error while reading from old backing file"); | ||
1155 | goto out; | ||
1156 | @@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv) | ||
1157 | n = new_backing_size - offset; | ||
1158 | } | ||
1159 | |||
1160 | - ret = blk_pread(blk_new_backing, offset, buf_new, n, 0); | ||
1161 | + ret = blk_pread(blk_new_backing, offset, n, buf_new, 0); | ||
1162 | if (ret < 0) { | ||
1163 | error_report("error while reading from new backing file"); | ||
1164 | goto out; | ||
1165 | @@ -XXX,XX +XXX,XX @@ static int img_rebase(int argc, char **argv) | ||
1166 | if (buf_old_is_zero) { | ||
1167 | ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0); | ||
1168 | } else { | ||
1169 | - ret = blk_pwrite(blk, offset + written, | ||
1170 | - buf_old + written, pnum, 0); | ||
1171 | + ret = blk_pwrite(blk, offset + written, pnum, | ||
1172 | + buf_old + written, 0); | ||
1173 | } | ||
1174 | if (ret < 0) { | ||
1175 | error_report("Error while writing to COW image: %s", | ||
1176 | @@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv) | ||
1177 | for (out_pos = 0; in_pos < size; block_count++) { | ||
1178 | int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; | ||
1179 | |||
1180 | - ret = blk_pread(blk1, in_pos, in.buf, bytes, 0); | ||
1181 | + ret = blk_pread(blk1, in_pos, bytes, in.buf, 0); | ||
1182 | if (ret < 0) { | ||
1183 | error_report("error while reading from input image file: %s", | ||
1184 | strerror(-ret)); | ||
1185 | @@ -XXX,XX +XXX,XX @@ static int img_dd(int argc, char **argv) | ||
1186 | } | ||
1187 | in_pos += bytes; | ||
1188 | |||
1189 | - ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0); | ||
1190 | + ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0); | ||
1191 | if (ret < 0) { | ||
1192 | error_report("error while writing to output image file: %s", | ||
1193 | strerror(-ret)); | ||
1194 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | ||
1195 | index XXXXXXX..XXXXXXX 100644 | ||
1196 | --- a/qemu-io-cmds.c | ||
1197 | +++ b/qemu-io-cmds.c | ||
1198 | @@ -XXX,XX +XXX,XX @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset, | ||
1199 | return -ERANGE; | ||
1200 | } | ||
1201 | |||
1202 | - ret = blk_pread(blk, offset, (uint8_t *)buf, bytes, 0); | ||
1203 | + ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, 0); | ||
1204 | if (ret < 0) { | ||
1205 | return ret; | ||
1206 | } | ||
1207 | @@ -XXX,XX +XXX,XX @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, | ||
1208 | return -ERANGE; | ||
1209 | } | ||
1210 | |||
1211 | - ret = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags); | ||
1212 | + ret = blk_pwrite(blk, offset, bytes, (uint8_t *)buf, flags); | ||
1213 | if (ret < 0) { | ||
1214 | return ret; | ||
1215 | } | ||
1216 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
1217 | index XXXXXXX..XXXXXXX 100644 | ||
1218 | --- a/tests/unit/test-block-iothread.c | ||
1219 | +++ b/tests/unit/test-block-iothread.c | ||
1220 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pread(BlockBackend *blk) | ||
1221 | int ret; | ||
1222 | |||
1223 | /* Success */ | ||
1224 | - ret = blk_pread(blk, 0, buf, sizeof(buf), 0); | ||
1225 | + ret = blk_pread(blk, 0, sizeof(buf), buf, 0); | ||
1226 | g_assert_cmpint(ret, ==, 0); | ||
1227 | |||
1228 | /* Early error: Negative offset */ | ||
1229 | - ret = blk_pread(blk, -2, buf, sizeof(buf), 0); | ||
1230 | + ret = blk_pread(blk, -2, sizeof(buf), buf, 0); | ||
1231 | g_assert_cmpint(ret, ==, -EIO); | ||
1232 | } | ||
1233 | |||
1234 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwrite(BlockBackend *blk) | ||
1235 | int ret; | ||
1236 | |||
1237 | /* Success */ | ||
1238 | - ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0); | ||
1239 | + ret = blk_pwrite(blk, 0, sizeof(buf), buf, 0); | ||
1240 | g_assert_cmpint(ret, ==, 0); | ||
1241 | |||
1242 | /* Early error: Negative offset */ | ||
1243 | - ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0); | ||
1244 | + ret = blk_pwrite(blk, -2, sizeof(buf), buf, 0); | ||
1245 | g_assert_cmpint(ret, ==, -EIO); | ||
1246 | } | ||
1247 | |||
130 | -- | 1248 | -- |
131 | 2.13.5 | 1249 | 2.35.3 |
132 | |||
133 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | For consistency with other I/O functions, and in preparation to | ||
4 | implement them using generated_co_wrapper. | ||
5 | |||
6 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
7 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
8 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | Message-Id: <20220705161527.1054072-5-afaria@redhat.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | include/sysemu/block-backend-io.h | 6 +++--- | ||
13 | block/block-backend.c | 6 +++--- | ||
14 | 2 files changed, 6 insertions(+), 6 deletions(-) | ||
15 | |||
16 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/sysemu/block-backend-io.h | ||
19 | +++ b/include/sysemu/block-backend-io.h | ||
20 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, | ||
21 | * the "I/O or GS" API. | ||
22 | */ | ||
23 | |||
24 | -int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, | ||
25 | +int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, | ||
26 | BdrvRequestFlags flags); | ||
27 | -int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, | ||
28 | - BdrvRequestFlags flags); | ||
29 | +int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
30 | + const void *buf, BdrvRequestFlags flags); | ||
31 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
32 | int64_t bytes, QEMUIOVector *qiov, | ||
33 | BdrvRequestFlags flags); | ||
34 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block/block-backend.c | ||
37 | +++ b/block/block-backend.c | ||
38 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
39 | flags | BDRV_REQ_ZERO_WRITE, cb, opaque); | ||
40 | } | ||
41 | |||
42 | -int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, | ||
43 | +int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, | ||
44 | BdrvRequestFlags flags) | ||
45 | { | ||
46 | int ret; | ||
47 | @@ -XXX,XX +XXX,XX @@ int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | -int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, | ||
52 | - BdrvRequestFlags flags) | ||
53 | +int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
54 | + const void *buf, BdrvRequestFlags flags) | ||
55 | { | ||
56 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
57 | IO_OR_GS_CODE(); | ||
58 | -- | ||
59 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | It does not mutate the buffer. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-6-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/sysemu/block-backend-io.h | 2 +- | ||
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/sysemu/block-backend-io.h | ||
17 | +++ b/include/sysemu/block-backend-io.h | ||
18 | @@ -XXX,XX +XXX,XX @@ static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, | ||
19 | } | ||
20 | |||
21 | static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, | ||
22 | - int64_t bytes, void *buf, | ||
23 | + int64_t bytes, const void *buf, | ||
24 | BdrvRequestFlags flags) | ||
25 | { | ||
26 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
27 | -- | ||
28 | 2.35.3 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The throttling code can change internally the value of bkt->max if it | 3 | We need to add include/sysemu/block-backend-io.h to the inputs of the |
4 | hasn't been set by the user. The problem with this is that if we want | 4 | block-gen.c target defined in block/meson.build. |
5 | to retrieve the original value we have to undo this change first. This | ||
6 | is ugly and unnecessary: this patch removes the throttle_fix_bucket() | ||
7 | and throttle_unfix_bucket() functions completely and moves the logic | ||
8 | to throttle_compute_wait(). | ||
9 | 5 | ||
10 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 6 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
11 | Reviewed-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | 7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
12 | Message-id: 5b0b9e1ac6eb208d709eddc7b09e7669a523bff3.1503580370.git.berto@igalia.com | 8 | Message-Id: <20220705161527.1054072-7-afaria@redhat.com> |
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
14 | --- | 10 | --- |
15 | util/throttle.c | 62 +++++++++++++++++++++------------------------------------ | 11 | block/coroutines.h | 4 ---- |
16 | 1 file changed, 23 insertions(+), 39 deletions(-) | 12 | include/sysemu/block-backend-io.h | 10 ++++++---- |
13 | block/block-backend.c | 23 ----------------------- | ||
14 | block/meson.build | 1 + | ||
15 | 4 files changed, 7 insertions(+), 31 deletions(-) | ||
17 | 16 | ||
18 | diff --git a/util/throttle.c b/util/throttle.c | 17 | diff --git a/block/coroutines.h b/block/coroutines.h |
19 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/util/throttle.c | 19 | --- a/block/coroutines.h |
21 | +++ b/util/throttle.c | 20 | +++ b/block/coroutines.h |
22 | @@ -XXX,XX +XXX,XX @@ static int64_t throttle_do_compute_wait(double limit, double extra) | 21 | @@ -XXX,XX +XXX,XX @@ bdrv_common_block_status_above(BlockDriverState *bs, |
23 | int64_t throttle_compute_wait(LeakyBucket *bkt) | 22 | int generated_co_wrapper |
24 | { | 23 | nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); |
25 | double extra; /* the number of extra units blocking the io */ | 24 | |
26 | + double bucket_size; /* I/O before throttling to bkt->avg */ | 25 | -int generated_co_wrapper |
27 | + double burst_bucket_size; /* Before throttling to bkt->max */ | 26 | -blk_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, |
28 | 27 | - QEMUIOVector *qiov, BdrvRequestFlags flags); | |
29 | if (!bkt->avg) { | 28 | - |
30 | return 0; | 29 | int generated_co_wrapper |
31 | } | 30 | blk_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, |
32 | 31 | QEMUIOVector *qiov, size_t qiov_offset, | |
33 | - /* If the bucket is full then we have to wait */ | 32 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h |
34 | - extra = bkt->level - bkt->max * bkt->burst_length; | 33 | index XXXXXXX..XXXXXXX 100644 |
35 | + if (!bkt->max) { | 34 | --- a/include/sysemu/block-backend-io.h |
36 | + /* If bkt->max is 0 we still want to allow short bursts of I/O | 35 | +++ b/include/sysemu/block-backend-io.h |
37 | + * from the guest, otherwise every other request will be throttled | 36 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, |
38 | + * and performance will suffer considerably. */ | 37 | * the "I/O or GS" API. |
39 | + bucket_size = bkt->avg / 10; | 38 | */ |
40 | + burst_bucket_size = 0; | 39 | |
41 | + } else { | 40 | -int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, |
42 | + /* If we have a burst limit then we have to wait until all I/O | 41 | - BdrvRequestFlags flags); |
43 | + * at burst rate has finished before throttling to bkt->avg */ | 42 | -int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, |
44 | + bucket_size = bkt->max * bkt->burst_length; | 43 | - const void *buf, BdrvRequestFlags flags); |
45 | + burst_bucket_size = bkt->max / 10; | 44 | +int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, |
46 | + } | 45 | + int64_t bytes, void *buf, |
47 | + | 46 | + BdrvRequestFlags flags); |
48 | + /* If the main bucket is full then we have to wait */ | 47 | +int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, |
49 | + extra = bkt->level - bucket_size; | 48 | + int64_t bytes, const void *buf, |
50 | if (extra > 0) { | 49 | + BdrvRequestFlags flags); |
51 | return throttle_do_compute_wait(bkt->avg, extra); | 50 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, |
52 | } | 51 | int64_t bytes, QEMUIOVector *qiov, |
53 | 52 | BdrvRequestFlags flags); | |
54 | - /* If the bucket is not full yet we have to make sure that we | 53 | diff --git a/block/block-backend.c b/block/block-backend.c |
55 | - * fulfill the goal of bkt->max units per second. */ | 54 | index XXXXXXX..XXXXXXX 100644 |
56 | + /* If the main bucket is not full yet we still have to check the | 55 | --- a/block/block-backend.c |
57 | + * burst bucket in order to enforce the burst limit */ | 56 | +++ b/block/block-backend.c |
58 | if (bkt->burst_length > 1) { | 57 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset, |
59 | - /* We use 1/10 of the max value to smooth the throttling. | 58 | flags | BDRV_REQ_ZERO_WRITE, cb, opaque); |
60 | - * See throttle_fix_bucket() for more details. */ | ||
61 | - extra = bkt->burst_level - bkt->max / 10; | ||
62 | + extra = bkt->burst_level - burst_bucket_size; | ||
63 | if (extra > 0) { | ||
64 | return throttle_do_compute_wait(bkt->max, extra); | ||
65 | } | ||
66 | @@ -XXX,XX +XXX,XX @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp) | ||
67 | return true; | ||
68 | } | 59 | } |
69 | 60 | ||
70 | -/* fix bucket parameters */ | 61 | -int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, |
71 | -static void throttle_fix_bucket(LeakyBucket *bkt) | 62 | - BdrvRequestFlags flags) |
72 | -{ | 63 | -{ |
73 | - double min; | 64 | - int ret; |
65 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
66 | - IO_OR_GS_CODE(); | ||
74 | - | 67 | - |
75 | - /* zero bucket level */ | 68 | - blk_inc_in_flight(blk); |
76 | - bkt->level = bkt->burst_level = 0; | 69 | - ret = blk_do_preadv(blk, offset, bytes, &qiov, flags); |
70 | - blk_dec_in_flight(blk); | ||
77 | - | 71 | - |
78 | - /* If bkt->max is 0 we still want to allow short bursts of I/O | 72 | - return ret; |
79 | - * from the guest, otherwise every other request will be throttled | ||
80 | - * and performance will suffer considerably. */ | ||
81 | - min = bkt->avg / 10; | ||
82 | - if (bkt->avg && !bkt->max) { | ||
83 | - bkt->max = min; | ||
84 | - } | ||
85 | -} | 73 | -} |
86 | - | 74 | - |
87 | -/* undo internal bucket parameter changes (see throttle_fix_bucket()) */ | 75 | -int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, |
88 | -static void throttle_unfix_bucket(LeakyBucket *bkt) | 76 | - const void *buf, BdrvRequestFlags flags) |
89 | -{ | 77 | -{ |
90 | - if (bkt->max < bkt->avg) { | 78 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); |
91 | - bkt->max = 0; | 79 | - IO_OR_GS_CODE(); |
92 | - } | 80 | - |
81 | - return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags); | ||
93 | -} | 82 | -} |
94 | - | 83 | - |
95 | /* Used to configure the throttle | 84 | int64_t blk_getlength(BlockBackend *blk) |
96 | * | ||
97 | * @ts: the throttle state we are working on | ||
98 | @@ -XXX,XX +XXX,XX @@ void throttle_config(ThrottleState *ts, | ||
99 | |||
100 | ts->cfg = *cfg; | ||
101 | |||
102 | + /* Zero bucket level */ | ||
103 | for (i = 0; i < BUCKETS_COUNT; i++) { | ||
104 | - throttle_fix_bucket(&ts->cfg.buckets[i]); | ||
105 | + ts->cfg.buckets[i].level = 0; | ||
106 | + ts->cfg.buckets[i].burst_level = 0; | ||
107 | } | ||
108 | |||
109 | ts->previous_leak = qemu_clock_get_ns(clock_type); | ||
110 | @@ -XXX,XX +XXX,XX @@ void throttle_config(ThrottleState *ts, | ||
111 | */ | ||
112 | void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg) | ||
113 | { | 85 | { |
114 | - int i; | 86 | IO_CODE(); |
115 | - | 87 | diff --git a/block/meson.build b/block/meson.build |
116 | *cfg = ts->cfg; | 88 | index XXXXXXX..XXXXXXX 100644 |
117 | - | 89 | --- a/block/meson.build |
118 | - for (i = 0; i < BUCKETS_COUNT; i++) { | 90 | +++ b/block/meson.build |
119 | - throttle_unfix_bucket(&cfg->buckets[i]); | 91 | @@ -XXX,XX +XXX,XX @@ block_gen_c = custom_target('block-gen.c', |
120 | - } | 92 | input: files( |
121 | } | 93 | '../include/block/block-io.h', |
122 | 94 | '../include/block/block-global-state.h', | |
123 | 95 | + '../include/sysemu/block-backend-io.h', | |
96 | 'coroutines.h' | ||
97 | ), | ||
98 | command: [wrapper_py, '@OUTPUT@', '@INPUT@']) | ||
124 | -- | 99 | -- |
125 | 2.13.5 | 100 | 2.35.3 |
126 | |||
127 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Implement them using generated_co_wrapper. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-8-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/sysemu/block-backend-io.h | 6 +++++ | ||
12 | tests/unit/test-block-iothread.c | 42 ++++++++++++++++++++++++++++++- | ||
13 | 2 files changed, 47 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/sysemu/block-backend-io.h | ||
18 | +++ b/include/sysemu/block-backend-io.h | ||
19 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, | ||
20 | int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, | ||
21 | int64_t bytes, const void *buf, | ||
22 | BdrvRequestFlags flags); | ||
23 | +int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, | ||
24 | + int64_t bytes, QEMUIOVector *qiov, | ||
25 | + BdrvRequestFlags flags); | ||
26 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
27 | int64_t bytes, QEMUIOVector *qiov, | ||
28 | BdrvRequestFlags flags); | ||
29 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, | ||
30 | int64_t bytes, | ||
31 | QEMUIOVector *qiov, size_t qiov_offset, | ||
32 | BdrvRequestFlags flags); | ||
33 | +int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, | ||
34 | + int64_t bytes, QEMUIOVector *qiov, | ||
35 | + BdrvRequestFlags flags); | ||
36 | int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
37 | int64_t bytes, QEMUIOVector *qiov, | ||
38 | BdrvRequestFlags flags); | ||
39 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/tests/unit/test-block-iothread.c | ||
42 | +++ b/tests/unit/test-block-iothread.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwrite(BlockBackend *blk) | ||
44 | g_assert_cmpint(ret, ==, -EIO); | ||
45 | } | ||
46 | |||
47 | +static void test_sync_op_blk_preadv(BlockBackend *blk) | ||
48 | +{ | ||
49 | + uint8_t buf[512]; | ||
50 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf)); | ||
51 | + int ret; | ||
52 | + | ||
53 | + /* Success */ | ||
54 | + ret = blk_preadv(blk, 0, sizeof(buf), &qiov, 0); | ||
55 | + g_assert_cmpint(ret, ==, 0); | ||
56 | + | ||
57 | + /* Early error: Negative offset */ | ||
58 | + ret = blk_preadv(blk, -2, sizeof(buf), &qiov, 0); | ||
59 | + g_assert_cmpint(ret, ==, -EIO); | ||
60 | +} | ||
61 | + | ||
62 | +static void test_sync_op_blk_pwritev(BlockBackend *blk) | ||
63 | +{ | ||
64 | + uint8_t buf[512] = { 0 }; | ||
65 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf)); | ||
66 | + int ret; | ||
67 | + | ||
68 | + /* Success */ | ||
69 | + ret = blk_pwritev(blk, 0, sizeof(buf), &qiov, 0); | ||
70 | + g_assert_cmpint(ret, ==, 0); | ||
71 | + | ||
72 | + /* Early error: Negative offset */ | ||
73 | + ret = blk_pwritev(blk, -2, sizeof(buf), &qiov, 0); | ||
74 | + g_assert_cmpint(ret, ==, -EIO); | ||
75 | +} | ||
76 | + | ||
77 | static void test_sync_op_load_vmstate(BdrvChild *c) | ||
78 | { | ||
79 | uint8_t buf[512]; | ||
80 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { | ||
81 | .name = "/sync-op/pwrite", | ||
82 | .fn = test_sync_op_pwrite, | ||
83 | .blkfn = test_sync_op_blk_pwrite, | ||
84 | + }, { | ||
85 | + .name = "/sync-op/preadv", | ||
86 | + .fn = NULL, | ||
87 | + .blkfn = test_sync_op_blk_preadv, | ||
88 | + }, { | ||
89 | + .name = "/sync-op/pwritev", | ||
90 | + .fn = NULL, | ||
91 | + .blkfn = test_sync_op_blk_pwritev, | ||
92 | }, { | ||
93 | .name = "/sync-op/load_vmstate", | ||
94 | .fn = test_sync_op_load_vmstate, | ||
95 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op(const void *opaque) | ||
96 | |||
97 | blk_set_aio_context(blk, ctx, &error_abort); | ||
98 | aio_context_acquire(ctx); | ||
99 | - t->fn(c); | ||
100 | + if (t->fn) { | ||
101 | + t->fn(c); | ||
102 | + } | ||
103 | if (t->blkfn) { | ||
104 | t->blkfn(blk); | ||
105 | } | ||
106 | -- | ||
107 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Implement blk_preadv_part() using generated_co_wrapper. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-9-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | block/coroutines.h | 5 ----- | ||
12 | include/sysemu/block-backend-io.h | 7 +++++++ | ||
13 | block/block-backend.c | 30 +++++++++++++++++++++++------- | ||
14 | tests/unit/test-block-iothread.c | 19 +++++++++++++++++++ | ||
15 | 4 files changed, 49 insertions(+), 12 deletions(-) | ||
16 | |||
17 | diff --git a/block/coroutines.h b/block/coroutines.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/coroutines.h | ||
20 | +++ b/block/coroutines.h | ||
21 | @@ -XXX,XX +XXX,XX @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking, | ||
22 | Error **errp); | ||
23 | |||
24 | |||
25 | -int coroutine_fn | ||
26 | -blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
27 | - QEMUIOVector *qiov, BdrvRequestFlags flags); | ||
28 | - | ||
29 | - | ||
30 | int coroutine_fn | ||
31 | blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
32 | QEMUIOVector *qiov, size_t qiov_offset, | ||
33 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/sysemu/block-backend-io.h | ||
36 | +++ b/include/sysemu/block-backend-io.h | ||
37 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, | ||
38 | int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, | ||
39 | int64_t bytes, const void *buf, | ||
40 | BdrvRequestFlags flags); | ||
41 | +int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, | ||
42 | + int64_t bytes, QEMUIOVector *qiov, | ||
43 | + size_t qiov_offset, | ||
44 | + BdrvRequestFlags flags); | ||
45 | +int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, | ||
46 | + int64_t bytes, QEMUIOVector *qiov, | ||
47 | + size_t qiov_offset, BdrvRequestFlags flags); | ||
48 | int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, | ||
49 | int64_t bytes, QEMUIOVector *qiov, | ||
50 | BdrvRequestFlags flags); | ||
51 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/block/block-backend.c | ||
54 | +++ b/block/block-backend.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) | ||
56 | } | ||
57 | |||
58 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ | ||
59 | -int coroutine_fn | ||
60 | -blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
61 | - QEMUIOVector *qiov, BdrvRequestFlags flags) | ||
62 | +static int coroutine_fn | ||
63 | +blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
64 | + QEMUIOVector *qiov, size_t qiov_offset, | ||
65 | + BdrvRequestFlags flags) | ||
66 | { | ||
67 | int ret; | ||
68 | BlockDriverState *bs; | ||
69 | @@ -XXX,XX +XXX,XX @@ blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
70 | bytes, false); | ||
71 | } | ||
72 | |||
73 | - ret = bdrv_co_preadv(blk->root, offset, bytes, qiov, flags); | ||
74 | + ret = bdrv_co_preadv_part(blk->root, offset, bytes, qiov, qiov_offset, | ||
75 | + flags); | ||
76 | bdrv_dec_in_flight(bs); | ||
77 | return ret; | ||
78 | } | ||
79 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
80 | IO_OR_GS_CODE(); | ||
81 | |||
82 | blk_inc_in_flight(blk); | ||
83 | - ret = blk_co_do_preadv(blk, offset, bytes, qiov, flags); | ||
84 | + ret = blk_co_do_preadv_part(blk, offset, bytes, qiov, 0, flags); | ||
85 | + blk_dec_in_flight(blk); | ||
86 | + | ||
87 | + return ret; | ||
88 | +} | ||
89 | + | ||
90 | +int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, | ||
91 | + int64_t bytes, QEMUIOVector *qiov, | ||
92 | + size_t qiov_offset, BdrvRequestFlags flags) | ||
93 | +{ | ||
94 | + int ret; | ||
95 | + IO_OR_GS_CODE(); | ||
96 | + | ||
97 | + blk_inc_in_flight(blk); | ||
98 | + ret = blk_co_do_preadv_part(blk, offset, bytes, qiov, qiov_offset, flags); | ||
99 | blk_dec_in_flight(blk); | ||
100 | |||
101 | return ret; | ||
102 | @@ -XXX,XX +XXX,XX @@ static void blk_aio_read_entry(void *opaque) | ||
103 | QEMUIOVector *qiov = rwco->iobuf; | ||
104 | |||
105 | assert(qiov->size == acb->bytes); | ||
106 | - rwco->ret = blk_co_do_preadv(rwco->blk, rwco->offset, acb->bytes, | ||
107 | - qiov, rwco->flags); | ||
108 | + rwco->ret = blk_co_do_preadv_part(rwco->blk, rwco->offset, acb->bytes, qiov, | ||
109 | + 0, rwco->flags); | ||
110 | blk_aio_complete(acb); | ||
111 | } | ||
112 | |||
113 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/tests/unit/test-block-iothread.c | ||
116 | +++ b/tests/unit/test-block-iothread.c | ||
117 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwritev(BlockBackend *blk) | ||
118 | g_assert_cmpint(ret, ==, -EIO); | ||
119 | } | ||
120 | |||
121 | +static void test_sync_op_blk_preadv_part(BlockBackend *blk) | ||
122 | +{ | ||
123 | + uint8_t buf[512]; | ||
124 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf)); | ||
125 | + int ret; | ||
126 | + | ||
127 | + /* Success */ | ||
128 | + ret = blk_preadv_part(blk, 0, sizeof(buf), &qiov, 0, 0); | ||
129 | + g_assert_cmpint(ret, ==, 0); | ||
130 | + | ||
131 | + /* Early error: Negative offset */ | ||
132 | + ret = blk_preadv_part(blk, -2, sizeof(buf), &qiov, 0, 0); | ||
133 | + g_assert_cmpint(ret, ==, -EIO); | ||
134 | +} | ||
135 | + | ||
136 | static void test_sync_op_load_vmstate(BdrvChild *c) | ||
137 | { | ||
138 | uint8_t buf[512]; | ||
139 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { | ||
140 | .name = "/sync-op/pwritev", | ||
141 | .fn = NULL, | ||
142 | .blkfn = test_sync_op_blk_pwritev, | ||
143 | + }, { | ||
144 | + .name = "/sync-op/preadv_part", | ||
145 | + .fn = NULL, | ||
146 | + .blkfn = test_sync_op_blk_preadv_part, | ||
147 | }, { | ||
148 | .name = "/sync-op/load_vmstate", | ||
149 | .fn = test_sync_op_load_vmstate, | ||
150 | -- | ||
151 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Also convert it into a generated_co_wrapper. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-10-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | block/coroutines.h | 5 ----- | ||
12 | include/sysemu/block-backend-io.h | 4 ++++ | ||
13 | block/block-backend.c | 14 -------------- | ||
14 | tests/unit/test-block-iothread.c | 19 +++++++++++++++++++ | ||
15 | 4 files changed, 23 insertions(+), 19 deletions(-) | ||
16 | |||
17 | diff --git a/block/coroutines.h b/block/coroutines.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/coroutines.h | ||
20 | +++ b/block/coroutines.h | ||
21 | @@ -XXX,XX +XXX,XX @@ bdrv_common_block_status_above(BlockDriverState *bs, | ||
22 | int generated_co_wrapper | ||
23 | nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); | ||
24 | |||
25 | -int generated_co_wrapper | ||
26 | -blk_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
27 | - QEMUIOVector *qiov, size_t qiov_offset, | ||
28 | - BdrvRequestFlags flags); | ||
29 | - | ||
30 | int generated_co_wrapper | ||
31 | blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
32 | |||
33 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/sysemu/block-backend-io.h | ||
36 | +++ b/include/sysemu/block-backend-io.h | ||
37 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, | ||
38 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
39 | int64_t bytes, QEMUIOVector *qiov, | ||
40 | BdrvRequestFlags flags); | ||
41 | +int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset, | ||
42 | + int64_t bytes, QEMUIOVector *qiov, | ||
43 | + size_t qiov_offset, | ||
44 | + BdrvRequestFlags flags); | ||
45 | int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, | ||
46 | int64_t bytes, | ||
47 | QEMUIOVector *qiov, size_t qiov_offset, | ||
48 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/block/block-backend.c | ||
51 | +++ b/block/block-backend.c | ||
52 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
53 | return blk_co_pwritev_part(blk, offset, bytes, qiov, 0, flags); | ||
54 | } | ||
55 | |||
56 | -static int coroutine_fn blk_pwritev_part(BlockBackend *blk, int64_t offset, | ||
57 | - int64_t bytes, | ||
58 | - QEMUIOVector *qiov, size_t qiov_offset, | ||
59 | - BdrvRequestFlags flags) | ||
60 | -{ | ||
61 | - int ret; | ||
62 | - | ||
63 | - blk_inc_in_flight(blk); | ||
64 | - ret = blk_do_pwritev_part(blk, offset, bytes, qiov, qiov_offset, flags); | ||
65 | - blk_dec_in_flight(blk); | ||
66 | - | ||
67 | - return ret; | ||
68 | -} | ||
69 | - | ||
70 | typedef struct BlkRwCo { | ||
71 | BlockBackend *blk; | ||
72 | int64_t offset; | ||
73 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/tests/unit/test-block-iothread.c | ||
76 | +++ b/tests/unit/test-block-iothread.c | ||
77 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_preadv_part(BlockBackend *blk) | ||
78 | g_assert_cmpint(ret, ==, -EIO); | ||
79 | } | ||
80 | |||
81 | +static void test_sync_op_blk_pwritev_part(BlockBackend *blk) | ||
82 | +{ | ||
83 | + uint8_t buf[512] = { 0 }; | ||
84 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf)); | ||
85 | + int ret; | ||
86 | + | ||
87 | + /* Success */ | ||
88 | + ret = blk_pwritev_part(blk, 0, sizeof(buf), &qiov, 0, 0); | ||
89 | + g_assert_cmpint(ret, ==, 0); | ||
90 | + | ||
91 | + /* Early error: Negative offset */ | ||
92 | + ret = blk_pwritev_part(blk, -2, sizeof(buf), &qiov, 0, 0); | ||
93 | + g_assert_cmpint(ret, ==, -EIO); | ||
94 | +} | ||
95 | + | ||
96 | static void test_sync_op_load_vmstate(BdrvChild *c) | ||
97 | { | ||
98 | uint8_t buf[512]; | ||
99 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { | ||
100 | .name = "/sync-op/preadv_part", | ||
101 | .fn = NULL, | ||
102 | .blkfn = test_sync_op_blk_preadv_part, | ||
103 | + }, { | ||
104 | + .name = "/sync-op/pwritev_part", | ||
105 | + .fn = NULL, | ||
106 | + .blkfn = test_sync_op_blk_pwritev_part, | ||
107 | }, { | ||
108 | .name = "/sync-op/load_vmstate", | ||
109 | .fn = test_sync_op_load_vmstate, | ||
110 | -- | ||
111 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Swap 'buf' and 'bytes' around for consistency with other I/O functions. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-11-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/sysemu/block-backend-io.h | 4 ++-- | ||
12 | block/block-backend.c | 4 ++-- | ||
13 | qemu-img.c | 2 +- | ||
14 | qemu-io-cmds.c | 2 +- | ||
15 | 4 files changed, 6 insertions(+), 6 deletions(-) | ||
16 | |||
17 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/sysemu/block-backend-io.h | ||
20 | +++ b/include/sysemu/block-backend-io.h | ||
21 | @@ -XXX,XX +XXX,XX @@ int blk_flush(BlockBackend *blk); | ||
22 | |||
23 | int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
24 | |||
25 | -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf, | ||
26 | - int64_t bytes); | ||
27 | +int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
28 | + const void *buf); | ||
29 | int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); | ||
30 | int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
31 | int64_t bytes, BdrvRequestFlags flags); | ||
32 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/block/block-backend.c | ||
35 | +++ b/block/block-backend.c | ||
36 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
37 | flags | BDRV_REQ_ZERO_WRITE); | ||
38 | } | ||
39 | |||
40 | -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf, | ||
41 | - int64_t bytes) | ||
42 | +int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
43 | + const void *buf) | ||
44 | { | ||
45 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
46 | IO_OR_GS_CODE(); | ||
47 | diff --git a/qemu-img.c b/qemu-img.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/qemu-img.c | ||
50 | +++ b/qemu-img.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static int convert_do_copy(ImgConvertState *s) | ||
52 | |||
53 | if (s->compressed && !s->ret) { | ||
54 | /* signal EOF to align */ | ||
55 | - ret = blk_pwrite_compressed(s->target, 0, NULL, 0); | ||
56 | + ret = blk_pwrite_compressed(s->target, 0, 0, NULL); | ||
57 | if (ret < 0) { | ||
58 | return ret; | ||
59 | } | ||
60 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/qemu-io-cmds.c | ||
63 | +++ b/qemu-io-cmds.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset, | ||
65 | return -ERANGE; | ||
66 | } | ||
67 | |||
68 | - ret = blk_pwrite_compressed(blk, offset, buf, bytes); | ||
69 | + ret = blk_pwrite_compressed(blk, offset, bytes, buf); | ||
70 | if (ret < 0) { | ||
71 | return ret; | ||
72 | } | ||
73 | -- | ||
74 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Also convert blk_pwrite_compressed() into a generated_co_wrapper. | ||
4 | |||
5 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | Message-Id: <20220705161527.1054072-12-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | ||
11 | include/sysemu/block-backend-io.h | 7 +++++-- | ||
12 | block/block-backend.c | 8 ++++---- | ||
13 | tests/unit/test-block-iothread.c | 18 ++++++++++++++++++ | ||
14 | 3 files changed, 27 insertions(+), 6 deletions(-) | ||
15 | |||
16 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/sysemu/block-backend-io.h | ||
19 | +++ b/include/sysemu/block-backend-io.h | ||
20 | @@ -XXX,XX +XXX,XX @@ int blk_flush(BlockBackend *blk); | ||
21 | |||
22 | int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
23 | |||
24 | -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
25 | - const void *buf); | ||
26 | +int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
27 | + int64_t offset, int64_t bytes, | ||
28 | + const void *buf); | ||
29 | +int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
30 | + int64_t bytes, const void *buf); | ||
31 | int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); | ||
32 | int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
33 | int64_t bytes, BdrvRequestFlags flags); | ||
34 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block/block-backend.c | ||
37 | +++ b/block/block-backend.c | ||
38 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
39 | flags | BDRV_REQ_ZERO_WRITE); | ||
40 | } | ||
41 | |||
42 | -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
43 | - const void *buf) | ||
44 | +int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
45 | + int64_t bytes, const void *buf) | ||
46 | { | ||
47 | QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
48 | IO_OR_GS_CODE(); | ||
49 | - return blk_pwritev_part(blk, offset, bytes, &qiov, 0, | ||
50 | - BDRV_REQ_WRITE_COMPRESSED); | ||
51 | + return blk_co_pwritev_part(blk, offset, bytes, &qiov, 0, | ||
52 | + BDRV_REQ_WRITE_COMPRESSED); | ||
53 | } | ||
54 | |||
55 | int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
56 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/tests/unit/test-block-iothread.c | ||
59 | +++ b/tests/unit/test-block-iothread.c | ||
60 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwritev_part(BlockBackend *blk) | ||
61 | g_assert_cmpint(ret, ==, -EIO); | ||
62 | } | ||
63 | |||
64 | +static void test_sync_op_blk_pwrite_compressed(BlockBackend *blk) | ||
65 | +{ | ||
66 | + uint8_t buf[512] = { 0 }; | ||
67 | + int ret; | ||
68 | + | ||
69 | + /* Late error: Not supported */ | ||
70 | + ret = blk_pwrite_compressed(blk, 0, sizeof(buf), buf); | ||
71 | + g_assert_cmpint(ret, ==, -ENOTSUP); | ||
72 | + | ||
73 | + /* Early error: Negative offset */ | ||
74 | + ret = blk_pwrite_compressed(blk, -2, sizeof(buf), buf); | ||
75 | + g_assert_cmpint(ret, ==, -EIO); | ||
76 | +} | ||
77 | + | ||
78 | static void test_sync_op_load_vmstate(BdrvChild *c) | ||
79 | { | ||
80 | uint8_t buf[512]; | ||
81 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { | ||
82 | .name = "/sync-op/pwritev_part", | ||
83 | .fn = NULL, | ||
84 | .blkfn = test_sync_op_blk_pwritev_part, | ||
85 | + }, { | ||
86 | + .name = "/sync-op/pwrite_compressed", | ||
87 | + .fn = NULL, | ||
88 | + .blkfn = test_sync_op_blk_pwrite_compressed, | ||
89 | }, { | ||
90 | .name = "/sync-op/load_vmstate", | ||
91 | .fn = test_sync_op_load_vmstate, | ||
92 | -- | ||
93 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
4 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
5 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
6 | Message-Id: <20220705161527.1054072-13-afaria@redhat.com> | ||
7 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | --- | ||
9 | include/sysemu/block-backend-io.h | 5 +++-- | ||
10 | block/block-backend.c | 8 -------- | ||
11 | tests/unit/test-block-iothread.c | 17 +++++++++++++++++ | ||
12 | 3 files changed, 20 insertions(+), 10 deletions(-) | ||
13 | |||
14 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/sysemu/block-backend-io.h | ||
17 | +++ b/include/sysemu/block-backend-io.h | ||
18 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
19 | int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
20 | int64_t bytes, const void *buf); | ||
21 | int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); | ||
22 | -int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
23 | - int64_t bytes, BdrvRequestFlags flags); | ||
24 | +int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
25 | + int64_t bytes, | ||
26 | + BdrvRequestFlags flags); | ||
27 | int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
28 | int64_t bytes, BdrvRequestFlags flags); | ||
29 | int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
30 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/block/block-backend.c | ||
33 | +++ b/block/block-backend.c | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct BlkRwCo { | ||
35 | BdrvRequestFlags flags; | ||
36 | } BlkRwCo; | ||
37 | |||
38 | -int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
39 | - int64_t bytes, BdrvRequestFlags flags) | ||
40 | -{ | ||
41 | - IO_OR_GS_CODE(); | ||
42 | - return blk_pwritev_part(blk, offset, bytes, NULL, 0, | ||
43 | - flags | BDRV_REQ_ZERO_WRITE); | ||
44 | -} | ||
45 | - | ||
46 | int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags) | ||
47 | { | ||
48 | GLOBAL_STATE_CODE(); | ||
49 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/tests/unit/test-block-iothread.c | ||
52 | +++ b/tests/unit/test-block-iothread.c | ||
53 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_blk_pwrite_compressed(BlockBackend *blk) | ||
54 | g_assert_cmpint(ret, ==, -EIO); | ||
55 | } | ||
56 | |||
57 | +static void test_sync_op_blk_pwrite_zeroes(BlockBackend *blk) | ||
58 | +{ | ||
59 | + int ret; | ||
60 | + | ||
61 | + /* Success */ | ||
62 | + ret = blk_pwrite_zeroes(blk, 0, 512, 0); | ||
63 | + g_assert_cmpint(ret, ==, 0); | ||
64 | + | ||
65 | + /* Early error: Negative offset */ | ||
66 | + ret = blk_pwrite_zeroes(blk, -2, 512, 0); | ||
67 | + g_assert_cmpint(ret, ==, -EIO); | ||
68 | +} | ||
69 | + | ||
70 | static void test_sync_op_load_vmstate(BdrvChild *c) | ||
71 | { | ||
72 | uint8_t buf[512]; | ||
73 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { | ||
74 | .name = "/sync-op/pwrite_compressed", | ||
75 | .fn = NULL, | ||
76 | .blkfn = test_sync_op_blk_pwrite_compressed, | ||
77 | + }, { | ||
78 | + .name = "/sync-op/pwrite_zeroes", | ||
79 | + .fn = NULL, | ||
80 | + .blkfn = test_sync_op_blk_pwrite_zeroes, | ||
81 | }, { | ||
82 | .name = "/sync-op/load_vmstate", | ||
83 | .fn = test_sync_op_load_vmstate, | ||
84 | -- | ||
85 | 2.35.3 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alberto Faria <afaria@redhat.com> | ||
1 | 2 | ||
3 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
4 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
5 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
6 | Message-Id: <20220705161527.1054072-14-afaria@redhat.com> | ||
7 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
8 | --- | ||
9 | block/coroutines.h | 3 --- | ||
10 | include/sysemu/block-backend-io.h | 3 ++- | ||
11 | block/block-backend.c | 12 ------------ | ||
12 | 3 files changed, 2 insertions(+), 16 deletions(-) | ||
13 | |||
14 | diff --git a/block/coroutines.h b/block/coroutines.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block/coroutines.h | ||
17 | +++ b/block/coroutines.h | ||
18 | @@ -XXX,XX +XXX,XX @@ nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); | ||
19 | int generated_co_wrapper | ||
20 | blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
21 | |||
22 | -int generated_co_wrapper | ||
23 | -blk_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); | ||
24 | - | ||
25 | int generated_co_wrapper blk_do_flush(BlockBackend *blk); | ||
26 | |||
27 | #endif /* BLOCK_COROUTINES_H */ | ||
28 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/include/sysemu/block-backend-io.h | ||
31 | +++ b/include/sysemu/block-backend-io.h | ||
32 | @@ -XXX,XX +XXX,XX @@ static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, | ||
33 | return blk_co_pwritev(blk, offset, bytes, &qiov, flags); | ||
34 | } | ||
35 | |||
36 | +int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, | ||
37 | + int64_t bytes); | ||
38 | int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, | ||
39 | int64_t bytes); | ||
40 | |||
41 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
42 | const void *buf); | ||
43 | int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
44 | int64_t bytes, const void *buf); | ||
45 | -int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); | ||
46 | int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
47 | int64_t bytes, | ||
48 | BdrvRequestFlags flags); | ||
49 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/block/block-backend.c | ||
52 | +++ b/block/block-backend.c | ||
53 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, | ||
54 | return ret; | ||
55 | } | ||
56 | |||
57 | -int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes) | ||
58 | -{ | ||
59 | - int ret; | ||
60 | - IO_OR_GS_CODE(); | ||
61 | - | ||
62 | - blk_inc_in_flight(blk); | ||
63 | - ret = blk_do_pdiscard(blk, offset, bytes); | ||
64 | - blk_dec_in_flight(blk); | ||
65 | - | ||
66 | - return ret; | ||
67 | -} | ||
68 | - | ||
69 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ | ||
70 | int coroutine_fn blk_co_do_flush(BlockBackend *blk) | ||
71 | { | ||
72 | -- | ||
73 | 2.35.3 | diff view generated by jsdifflib |
1 | Add the scripts/ directory to sys.path so Python 2.6 will be able to | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | import argparse. | ||
3 | 2 | ||
4 | Cc: Daniel P. Berrange <berrange@redhat.com> | 3 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 4 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> |
6 | Acked-by: John Snow <jsnow@redhat.com> | 5 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
7 | Acked-by: Fam Zheng <famz@redhat.com> | 6 | Message-Id: <20220705161527.1054072-15-afaria@redhat.com> |
8 | Message-id: 20170825155732.15665-4-stefanha@redhat.com | 7 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 8 | --- |
11 | tests/migration/guestperf/shell.py | 8 +++++--- | 9 | block/coroutines.h | 2 -- |
12 | 1 file changed, 5 insertions(+), 3 deletions(-) | 10 | include/sysemu/block-backend-io.h | 2 +- |
11 | block/block-backend.c | 11 ----------- | ||
12 | 3 files changed, 1 insertion(+), 14 deletions(-) | ||
13 | 13 | ||
14 | diff --git a/tests/migration/guestperf/shell.py b/tests/migration/guestperf/shell.py | 14 | diff --git a/block/coroutines.h b/block/coroutines.h |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tests/migration/guestperf/shell.py | 16 | --- a/block/coroutines.h |
17 | +++ b/tests/migration/guestperf/shell.py | 17 | +++ b/block/coroutines.h |
18 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); |
19 | # | 19 | int generated_co_wrapper |
20 | 20 | blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | |
21 | 21 | ||
22 | -import argparse | 22 | -int generated_co_wrapper blk_do_flush(BlockBackend *blk); |
23 | -import fnmatch | 23 | - |
24 | import os | 24 | #endif /* BLOCK_COROUTINES_H */ |
25 | import os.path | 25 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h |
26 | -import platform | 26 | index XXXXXXX..XXXXXXX 100644 |
27 | import sys | 27 | --- a/include/sysemu/block-backend-io.h |
28 | +sys.path.append(os.path.join(os.path.dirname(__file__), | 28 | +++ b/include/sysemu/block-backend-io.h |
29 | + '..', '..', '..', 'scripts')) | 29 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, |
30 | +import argparse | 30 | int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, |
31 | +import fnmatch | 31 | int64_t bytes); |
32 | +import platform | 32 | |
33 | 33 | +int generated_co_wrapper blk_flush(BlockBackend *blk); | |
34 | from guestperf.hardware import Hardware | 34 | int coroutine_fn blk_co_flush(BlockBackend *blk); |
35 | from guestperf.engine import Engine | 35 | -int blk_flush(BlockBackend *blk); |
36 | |||
37 | int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
38 | |||
39 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/block/block-backend.c | ||
42 | +++ b/block/block-backend.c | ||
43 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_flush(BlockBackend *blk) | ||
44 | return ret; | ||
45 | } | ||
46 | |||
47 | -int blk_flush(BlockBackend *blk) | ||
48 | -{ | ||
49 | - int ret; | ||
50 | - | ||
51 | - blk_inc_in_flight(blk); | ||
52 | - ret = blk_do_flush(blk); | ||
53 | - blk_dec_in_flight(blk); | ||
54 | - | ||
55 | - return ret; | ||
56 | -} | ||
57 | - | ||
58 | void blk_drain(BlockBackend *blk) | ||
59 | { | ||
60 | BlockDriverState *bs = blk_bs(blk); | ||
36 | -- | 61 | -- |
37 | 2.13.5 | 62 | 2.35.3 |
38 | |||
39 | diff view generated by jsdifflib |
1 | Add the scripts/ directory to sys.path so Python 2.6 will be able to | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | import argparse. | ||
3 | 2 | ||
4 | Cc: Fam Zheng <famz@redhat.com> | 3 | Also convert blk_ioctl() into a generated_co_wrapper. |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 4 | |
6 | Acked-by: John Snow <jsnow@redhat.com> | 5 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
7 | Acked-by: Fam Zheng <famz@redhat.com> | 6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> |
8 | Message-id: 20170825155732.15665-3-stefanha@redhat.com | 7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 8 | Message-Id: <20220705161527.1054072-16-afaria@redhat.com> |
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | 10 | --- |
11 | tests/docker/docker.py | 4 +++- | 11 | block/coroutines.h | 6 ------ |
12 | 1 file changed, 3 insertions(+), 1 deletion(-) | 12 | include/sysemu/block-backend-io.h | 5 ++++- |
13 | block/block-backend.c | 7 ++++--- | ||
14 | 3 files changed, 8 insertions(+), 10 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/tests/docker/docker.py b/tests/docker/docker.py | 16 | diff --git a/block/coroutines.h b/block/coroutines.h |
15 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tests/docker/docker.py | 18 | --- a/block/coroutines.h |
17 | +++ b/tests/docker/docker.py | 19 | +++ b/block/coroutines.h |
18 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, |
19 | 21 | QEMUIOVector *qiov, size_t qiov_offset, | |
20 | import os | 22 | BdrvRequestFlags flags); |
21 | import sys | 23 | |
22 | +sys.path.append(os.path.join(os.path.dirname(__file__), | 24 | -int coroutine_fn |
23 | + '..', '..', 'scripts')) | 25 | -blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf); |
24 | +import argparse | 26 | - |
25 | import subprocess | 27 | int coroutine_fn |
26 | import json | 28 | blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); |
27 | import hashlib | 29 | |
28 | import atexit | 30 | @@ -XXX,XX +XXX,XX @@ bdrv_common_block_status_above(BlockDriverState *bs, |
29 | import uuid | 31 | int generated_co_wrapper |
30 | -import argparse | 32 | nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); |
31 | import tempfile | 33 | |
32 | import re | 34 | -int generated_co_wrapper |
33 | import signal | 35 | -blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf); |
36 | - | ||
37 | #endif /* BLOCK_COROUTINES_H */ | ||
38 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/include/sysemu/block-backend-io.h | ||
41 | +++ b/include/sysemu/block-backend-io.h | ||
42 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, | ||
43 | int generated_co_wrapper blk_flush(BlockBackend *blk); | ||
44 | int coroutine_fn blk_co_flush(BlockBackend *blk); | ||
45 | |||
46 | -int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); | ||
47 | +int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req, | ||
48 | + void *buf); | ||
49 | +int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, | ||
50 | + void *buf); | ||
51 | |||
52 | int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
53 | int64_t offset, int64_t bytes, | ||
54 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/block/block-backend.c | ||
57 | +++ b/block/block-backend.c | ||
58 | @@ -XXX,XX +XXX,XX @@ void blk_aio_cancel_async(BlockAIOCB *acb) | ||
59 | } | ||
60 | |||
61 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ | ||
62 | -int coroutine_fn | ||
63 | +static int coroutine_fn | ||
64 | blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf) | ||
65 | { | ||
66 | IO_CODE(); | ||
67 | @@ -XXX,XX +XXX,XX @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf) | ||
68 | return bdrv_co_ioctl(blk_bs(blk), req, buf); | ||
69 | } | ||
70 | |||
71 | -int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf) | ||
72 | +int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, | ||
73 | + void *buf) | ||
74 | { | ||
75 | int ret; | ||
76 | IO_OR_GS_CODE(); | ||
77 | |||
78 | blk_inc_in_flight(blk); | ||
79 | - ret = blk_do_ioctl(blk, req, buf); | ||
80 | + ret = blk_co_do_ioctl(blk, req, buf); | ||
81 | blk_dec_in_flight(blk); | ||
82 | |||
83 | return ret; | ||
34 | -- | 84 | -- |
35 | 2.13.5 | 85 | 2.35.3 |
36 | |||
37 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Use a pointer to the bucket instead of repeating cfg->buckets[i] all | 3 | Also convert blk_truncate() into a generated_co_wrapper. |
4 | the time. This makes the code more concise and will help us expand the | ||
5 | checks later and save a few line breaks. | ||
6 | 4 | ||
7 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 5 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
8 | Message-id: 763ffc40a26b17d54cf93f5a999e4656049fcf0c.1503580370.git.berto@igalia.com | 6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
8 | Message-Id: <20220705161527.1054072-17-afaria@redhat.com> | ||
9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | --- | 10 | --- |
11 | util/throttle.c | 15 +++++++-------- | 11 | include/sysemu/block-backend-io.h | 8 ++++++-- |
12 | 1 file changed, 7 insertions(+), 8 deletions(-) | 12 | block/block-backend.c | 7 ++++--- |
13 | tests/unit/test-block-iothread.c | 14 ++++++++++++++ | ||
14 | 3 files changed, 24 insertions(+), 5 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/util/throttle.c b/util/throttle.c | 16 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/util/throttle.c | 18 | --- a/include/sysemu/block-backend-io.h |
17 | +++ b/util/throttle.c | 19 | +++ b/include/sysemu/block-backend-io.h |
18 | @@ -XXX,XX +XXX,XX @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp) | 20 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, |
21 | BdrvRequestFlags flags); | ||
22 | int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
23 | int64_t bytes, BdrvRequestFlags flags); | ||
24 | -int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
25 | - PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); | ||
26 | +int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset, | ||
27 | + bool exact, PreallocMode prealloc, | ||
28 | + BdrvRequestFlags flags, Error **errp); | ||
29 | +int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
30 | + PreallocMode prealloc, BdrvRequestFlags flags, | ||
31 | + Error **errp); | ||
32 | |||
33 | #endif /* BLOCK_BACKEND_IO_H */ | ||
34 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block/block-backend.c | ||
37 | +++ b/block/block-backend.c | ||
38 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
39 | BDRV_REQ_WRITE_COMPRESSED); | ||
40 | } | ||
41 | |||
42 | -int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
43 | - PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) | ||
44 | +int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
45 | + PreallocMode prealloc, BdrvRequestFlags flags, | ||
46 | + Error **errp) | ||
47 | { | ||
48 | IO_OR_GS_CODE(); | ||
49 | if (!blk_is_available(blk)) { | ||
50 | @@ -XXX,XX +XXX,XX @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, | ||
51 | return -ENOMEDIUM; | ||
19 | } | 52 | } |
20 | 53 | ||
21 | for (i = 0; i < BUCKETS_COUNT; i++) { | 54 | - return bdrv_truncate(blk->root, offset, exact, prealloc, flags, errp); |
22 | - if (cfg->buckets[i].avg < 0 || | 55 | + return bdrv_co_truncate(blk->root, offset, exact, prealloc, flags, errp); |
23 | - cfg->buckets[i].max < 0 || | 56 | } |
24 | - cfg->buckets[i].avg > THROTTLE_VALUE_MAX || | 57 | |
25 | - cfg->buckets[i].max > THROTTLE_VALUE_MAX) { | 58 | int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, |
26 | + LeakyBucket *bkt = &cfg->buckets[i]; | 59 | diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c |
27 | + if (bkt->avg < 0 || bkt->max < 0 || | 60 | index XXXXXXX..XXXXXXX 100644 |
28 | + bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) { | 61 | --- a/tests/unit/test-block-iothread.c |
29 | error_setg(errp, "bps/iops/max values must be within [0, %lld]", | 62 | +++ b/tests/unit/test-block-iothread.c |
30 | THROTTLE_VALUE_MAX); | 63 | @@ -XXX,XX +XXX,XX @@ static void test_sync_op_truncate(BdrvChild *c) |
31 | return false; | 64 | c->bs->open_flags |= BDRV_O_RDWR; |
32 | } | 65 | } |
33 | 66 | ||
34 | - if (!cfg->buckets[i].burst_length) { | 67 | +static void test_sync_op_blk_truncate(BlockBackend *blk) |
35 | + if (!bkt->burst_length) { | 68 | +{ |
36 | error_setg(errp, "the burst length cannot be 0"); | 69 | + int ret; |
37 | return false; | 70 | + |
38 | } | 71 | + /* Normal success path */ |
39 | 72 | + ret = blk_truncate(blk, 65536, false, PREALLOC_MODE_OFF, 0, NULL); | |
40 | - if (cfg->buckets[i].burst_length > 1 && !cfg->buckets[i].max) { | 73 | + g_assert_cmpint(ret, ==, 0); |
41 | + if (bkt->burst_length > 1 && !bkt->max) { | 74 | + |
42 | error_setg(errp, "burst length set without burst rate"); | 75 | + /* Early error: Negative offset */ |
43 | return false; | 76 | + ret = blk_truncate(blk, -2, false, PREALLOC_MODE_OFF, 0, NULL); |
44 | } | 77 | + g_assert_cmpint(ret, ==, -EINVAL); |
45 | 78 | +} | |
46 | - if (cfg->buckets[i].max && !cfg->buckets[i].avg) { | 79 | + |
47 | + if (bkt->max && !bkt->avg) { | 80 | static void test_sync_op_block_status(BdrvChild *c) |
48 | error_setg(errp, "bps_max/iops_max require corresponding" | 81 | { |
49 | " bps/iops values"); | 82 | int ret; |
50 | return false; | 83 | @@ -XXX,XX +XXX,XX @@ const SyncOpTest sync_op_tests[] = { |
51 | } | 84 | }, { |
52 | 85 | .name = "/sync-op/truncate", | |
53 | - if (cfg->buckets[i].max && cfg->buckets[i].max < cfg->buckets[i].avg) { | 86 | .fn = test_sync_op_truncate, |
54 | + if (bkt->max && bkt->max < bkt->avg) { | 87 | + .blkfn = test_sync_op_blk_truncate, |
55 | error_setg(errp, "bps_max/iops_max cannot be lower than bps/iops"); | 88 | }, { |
56 | return false; | 89 | .name = "/sync-op/block_status", |
57 | } | 90 | .fn = test_sync_op_block_status, |
58 | -- | 91 | -- |
59 | 2.13.5 | 92 | 2.35.3 |
60 | |||
61 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 3 | Keep generated_co_wrapper and coroutine_fn pairs together. This should |
4 | Message-id: a57dd6274e1b6dc9c28769fec4c7ea543be5c5e3.1503580370.git.berto@igalia.com | 4 | make it clear that each I/O function has these two versions. |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | |
6 | Also move blk_co_{pread,pwrite}()'s implementations out of the header | ||
7 | file for consistency. | ||
8 | |||
9 | Signed-off-by: Alberto Faria <afaria@redhat.com> | ||
10 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
11 | Message-Id: <20220705161527.1054072-18-afaria@redhat.com> | ||
12 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
6 | --- | 14 | --- |
7 | tests/test-throttle.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ | 15 | include/sysemu/block-backend-io.h | 77 +++++++++++++------------------ |
8 | 1 file changed, 77 insertions(+) | 16 | block/block-backend.c | 22 +++++++++ |
17 | 2 files changed, 54 insertions(+), 45 deletions(-) | ||
9 | 18 | ||
10 | diff --git a/tests/test-throttle.c b/tests/test-throttle.c | 19 | diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h |
11 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tests/test-throttle.c | 21 | --- a/include/sysemu/block-backend-io.h |
13 | +++ b/tests/test-throttle.c | 22 | +++ b/include/sysemu/block-backend-io.h |
14 | @@ -XXX,XX +XXX,XX @@ static void test_is_valid(void) | 23 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, |
15 | test_is_valid_for_value(1, true); | 24 | int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, |
25 | int64_t bytes, void *buf, | ||
26 | BdrvRequestFlags flags); | ||
27 | -int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, | ||
28 | - int64_t bytes, const void *buf, | ||
29 | +int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
30 | + void *buf, BdrvRequestFlags flags); | ||
31 | + | ||
32 | +int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, | ||
33 | + int64_t bytes, QEMUIOVector *qiov, | ||
34 | BdrvRequestFlags flags); | ||
35 | +int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
36 | + int64_t bytes, QEMUIOVector *qiov, | ||
37 | + BdrvRequestFlags flags); | ||
38 | + | ||
39 | int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, | ||
40 | int64_t bytes, QEMUIOVector *qiov, | ||
41 | size_t qiov_offset, | ||
42 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, | ||
43 | int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, | ||
44 | int64_t bytes, QEMUIOVector *qiov, | ||
45 | size_t qiov_offset, BdrvRequestFlags flags); | ||
46 | -int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, | ||
47 | - int64_t bytes, QEMUIOVector *qiov, | ||
48 | + | ||
49 | +int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, | ||
50 | + int64_t bytes, const void *buf, | ||
51 | BdrvRequestFlags flags); | ||
52 | -int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
53 | - int64_t bytes, QEMUIOVector *qiov, | ||
54 | - BdrvRequestFlags flags); | ||
55 | +int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
56 | + const void *buf, BdrvRequestFlags flags); | ||
57 | + | ||
58 | +int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, | ||
59 | + int64_t bytes, QEMUIOVector *qiov, | ||
60 | + BdrvRequestFlags flags); | ||
61 | +int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
62 | + int64_t bytes, QEMUIOVector *qiov, | ||
63 | + BdrvRequestFlags flags); | ||
64 | + | ||
65 | int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset, | ||
66 | int64_t bytes, QEMUIOVector *qiov, | ||
67 | size_t qiov_offset, | ||
68 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, | ||
69 | int64_t bytes, | ||
70 | QEMUIOVector *qiov, size_t qiov_offset, | ||
71 | BdrvRequestFlags flags); | ||
72 | -int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, | ||
73 | - int64_t bytes, QEMUIOVector *qiov, | ||
74 | - BdrvRequestFlags flags); | ||
75 | -int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
76 | - int64_t bytes, QEMUIOVector *qiov, | ||
77 | - BdrvRequestFlags flags); | ||
78 | - | ||
79 | -static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, | ||
80 | - int64_t bytes, void *buf, | ||
81 | - BdrvRequestFlags flags) | ||
82 | -{ | ||
83 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
84 | - IO_OR_GS_CODE(); | ||
85 | - | ||
86 | - assert(bytes <= SIZE_MAX); | ||
87 | - | ||
88 | - return blk_co_preadv(blk, offset, bytes, &qiov, flags); | ||
89 | -} | ||
90 | - | ||
91 | -static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, | ||
92 | - int64_t bytes, const void *buf, | ||
93 | - BdrvRequestFlags flags) | ||
94 | -{ | ||
95 | - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); | ||
96 | - IO_OR_GS_CODE(); | ||
97 | |||
98 | - assert(bytes <= SIZE_MAX); | ||
99 | +int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
100 | + int64_t offset, int64_t bytes, | ||
101 | + const void *buf); | ||
102 | +int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
103 | + int64_t bytes, const void *buf); | ||
104 | |||
105 | - return blk_co_pwritev(blk, offset, bytes, &qiov, flags); | ||
106 | -} | ||
107 | +int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
108 | + int64_t bytes, | ||
109 | + BdrvRequestFlags flags); | ||
110 | +int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
111 | + int64_t bytes, BdrvRequestFlags flags); | ||
112 | |||
113 | int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, | ||
114 | int64_t bytes); | ||
115 | @@ -XXX,XX +XXX,XX @@ int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req, | ||
116 | int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, | ||
117 | void *buf); | ||
118 | |||
119 | -int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, | ||
120 | - int64_t offset, int64_t bytes, | ||
121 | - const void *buf); | ||
122 | -int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, | ||
123 | - int64_t bytes, const void *buf); | ||
124 | -int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
125 | - int64_t bytes, | ||
126 | - BdrvRequestFlags flags); | ||
127 | -int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, | ||
128 | - int64_t bytes, BdrvRequestFlags flags); | ||
129 | int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset, | ||
130 | bool exact, PreallocMode prealloc, | ||
131 | BdrvRequestFlags flags, Error **errp); | ||
132 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/block/block-backend.c | ||
135 | +++ b/block/block-backend.c | ||
136 | @@ -XXX,XX +XXX,XX @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, | ||
137 | return ret; | ||
16 | } | 138 | } |
17 | 139 | ||
18 | +static void test_ranges(void) | 140 | +int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes, |
141 | + void *buf, BdrvRequestFlags flags) | ||
19 | +{ | 142 | +{ |
20 | + int i; | 143 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); |
144 | + IO_OR_GS_CODE(); | ||
21 | + | 145 | + |
22 | + for (i = 0; i < BUCKETS_COUNT; i++) { | 146 | + assert(bytes <= SIZE_MAX); |
23 | + LeakyBucket *b = &cfg.buckets[i]; | ||
24 | + throttle_config_init(&cfg); | ||
25 | + | 147 | + |
26 | + /* avg = 0 means throttling is disabled, but the config is valid */ | 148 | + return blk_co_preadv(blk, offset, bytes, &qiov, flags); |
27 | + b->avg = 0; | ||
28 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
29 | + g_assert(!throttle_enabled(&cfg)); | ||
30 | + | ||
31 | + /* These are valid configurations (values <= THROTTLE_VALUE_MAX) */ | ||
32 | + b->avg = 1; | ||
33 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
34 | + | ||
35 | + b->avg = THROTTLE_VALUE_MAX; | ||
36 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
37 | + | ||
38 | + b->avg = THROTTLE_VALUE_MAX; | ||
39 | + b->max = THROTTLE_VALUE_MAX; | ||
40 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
41 | + | ||
42 | + /* Values over THROTTLE_VALUE_MAX are not allowed */ | ||
43 | + b->avg = THROTTLE_VALUE_MAX + 1; | ||
44 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
45 | + | ||
46 | + b->avg = THROTTLE_VALUE_MAX; | ||
47 | + b->max = THROTTLE_VALUE_MAX + 1; | ||
48 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
49 | + | ||
50 | + /* burst_length must be between 1 and THROTTLE_VALUE_MAX */ | ||
51 | + b->avg = 1; | ||
52 | + b->max = 1; | ||
53 | + b->burst_length = 0; | ||
54 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
55 | + | ||
56 | + b->avg = 1; | ||
57 | + b->max = 1; | ||
58 | + b->burst_length = 1; | ||
59 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
60 | + | ||
61 | + b->avg = 1; | ||
62 | + b->max = 1; | ||
63 | + b->burst_length = THROTTLE_VALUE_MAX; | ||
64 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
65 | + | ||
66 | + b->avg = 1; | ||
67 | + b->max = 1; | ||
68 | + b->burst_length = THROTTLE_VALUE_MAX + 1; | ||
69 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
70 | + | ||
71 | + /* burst_length * max cannot exceed THROTTLE_VALUE_MAX */ | ||
72 | + b->avg = 1; | ||
73 | + b->max = 2; | ||
74 | + b->burst_length = THROTTLE_VALUE_MAX / 2; | ||
75 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
76 | + | ||
77 | + b->avg = 1; | ||
78 | + b->max = 3; | ||
79 | + b->burst_length = THROTTLE_VALUE_MAX / 2; | ||
80 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
81 | + | ||
82 | + b->avg = 1; | ||
83 | + b->max = THROTTLE_VALUE_MAX; | ||
84 | + b->burst_length = 1; | ||
85 | + g_assert(throttle_is_valid(&cfg, NULL)); | ||
86 | + | ||
87 | + b->avg = 1; | ||
88 | + b->max = THROTTLE_VALUE_MAX; | ||
89 | + b->burst_length = 2; | ||
90 | + g_assert(!throttle_is_valid(&cfg, NULL)); | ||
91 | + } | ||
92 | +} | 149 | +} |
93 | + | 150 | + |
94 | static void test_max_is_missing_limit(void) | 151 | int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, |
95 | { | 152 | int64_t bytes, QEMUIOVector *qiov, |
96 | int i; | 153 | BdrvRequestFlags flags) |
97 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | 154 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, |
98 | g_test_add_func("/throttle/config/enabled", test_enabled); | 155 | return ret; |
99 | g_test_add_func("/throttle/config/conflicting", test_conflicting_config); | 156 | } |
100 | g_test_add_func("/throttle/config/is_valid", test_is_valid); | 157 | |
101 | + g_test_add_func("/throttle/config/ranges", test_ranges); | 158 | +int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, |
102 | g_test_add_func("/throttle/config/max", test_max_is_missing_limit); | 159 | + const void *buf, BdrvRequestFlags flags) |
103 | g_test_add_func("/throttle/config/iops_size", | 160 | +{ |
104 | test_iops_size_is_missing_limit); | 161 | + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); |
162 | + IO_OR_GS_CODE(); | ||
163 | + | ||
164 | + assert(bytes <= SIZE_MAX); | ||
165 | + | ||
166 | + return blk_co_pwritev(blk, offset, bytes, &qiov, flags); | ||
167 | +} | ||
168 | + | ||
169 | int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
170 | int64_t bytes, QEMUIOVector *qiov, | ||
171 | BdrvRequestFlags flags) | ||
105 | -- | 172 | -- |
106 | 2.13.5 | 173 | 2.35.3 |
107 | |||
108 | diff view generated by jsdifflib |
1 | The minimum Python version supported by QEMU is 2.6. The argparse | 1 | From: Alberto Faria <afaria@redhat.com> |
---|---|---|---|
2 | standard library module was only added in Python 2.7. Many scripts | ||
3 | would like to use argparse because it supports command-line | ||
4 | sub-commands. | ||
5 | 2 | ||
6 | This patch adds argparse. See the top of argparse.py for details. | 3 | Some can be made static, others are unused generated_co_wrappers. |
7 | 4 | ||
8 | Suggested-by: Daniel P. Berrange <berrange@redhat.com> | 5 | Signed-off-by: Alberto Faria <afaria@redhat.com> |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 6 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> |
10 | Acked-by: John Snow <jsnow@redhat.com> | 7 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
11 | Message-id: 20170825155732.15665-2-stefanha@redhat.com | 8 | Message-Id: <20220705161527.1054072-19-afaria@redhat.com> |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
13 | --- | 10 | --- |
14 | COPYING.PYTHON | 270 ++++++ | 11 | block/coroutines.h | 19 ------------------- |
15 | scripts/argparse.py | 2406 +++++++++++++++++++++++++++++++++++++++++++++++++++ | 12 | block/block-backend.c | 6 +++--- |
16 | 2 files changed, 2676 insertions(+) | 13 | 2 files changed, 3 insertions(+), 22 deletions(-) |
17 | create mode 100644 COPYING.PYTHON | ||
18 | create mode 100644 scripts/argparse.py | ||
19 | 14 | ||
20 | diff --git a/COPYING.PYTHON b/COPYING.PYTHON | 15 | diff --git a/block/coroutines.h b/block/coroutines.h |
21 | new file mode 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
22 | index XXXXXXX..XXXXXXX | 17 | --- a/block/coroutines.h |
23 | --- /dev/null | 18 | +++ b/block/coroutines.h |
24 | +++ b/COPYING.PYTHON | 19 | @@ -XXX,XX +XXX,XX @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking, |
25 | @@ -XXX,XX +XXX,XX @@ | 20 | Error **errp); |
26 | +A. HISTORY OF THE SOFTWARE | 21 | |
27 | +========================== | 22 | |
28 | + | 23 | -int coroutine_fn |
29 | +Python was created in the early 1990s by Guido van Rossum at Stichting | 24 | -blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, |
30 | +Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands | 25 | - QEMUIOVector *qiov, size_t qiov_offset, |
31 | +as a successor of a language called ABC. Guido remains Python's | 26 | - BdrvRequestFlags flags); |
32 | +principal author, although it includes many contributions from others. | 27 | - |
33 | + | 28 | -int coroutine_fn |
34 | +In 1995, Guido continued his work on Python at the Corporation for | 29 | -blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); |
35 | +National Research Initiatives (CNRI, see http://www.cnri.reston.va.us) | 30 | - |
36 | +in Reston, Virginia where he released several versions of the | 31 | -int coroutine_fn blk_co_do_flush(BlockBackend *blk); |
37 | +software. | 32 | - |
38 | + | 33 | - |
39 | +In May 2000, Guido and the Python core development team moved to | 34 | /* |
40 | +BeOpen.com to form the BeOpen PythonLabs team. In October of the same | 35 | * "I/O or GS" API functions. These functions can run without |
41 | +year, the PythonLabs team moved to Digital Creations (now Zope | 36 | * the BQL, but only in one specific iothread/main loop. |
42 | +Corporation, see http://www.zope.com). In 2001, the Python Software | 37 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_do_flush(BlockBackend *blk); |
43 | +Foundation (PSF, see http://www.python.org/psf/) was formed, a | 38 | * the "I/O or GS" API. |
44 | +non-profit organization created specifically to own Python-related | 39 | */ |
45 | +Intellectual Property. Zope Corporation is a sponsoring member of | 40 | |
46 | +the PSF. | 41 | -int generated_co_wrapper |
47 | + | 42 | -bdrv_preadv(BdrvChild *child, int64_t offset, int64_t bytes, |
48 | +All Python releases are Open Source (see http://www.opensource.org for | 43 | - QEMUIOVector *qiov, BdrvRequestFlags flags); |
49 | +the Open Source Definition). Historically, most, but not all, Python | 44 | - |
50 | +releases have also been GPL-compatible; the table below summarizes | 45 | -int generated_co_wrapper |
51 | +the various releases. | 46 | -bdrv_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, |
52 | + | 47 | - QEMUIOVector *qiov, BdrvRequestFlags flags); |
53 | + Release Derived Year Owner GPL- | 48 | - |
54 | + from compatible? (1) | 49 | int generated_co_wrapper |
55 | + | 50 | bdrv_common_block_status_above(BlockDriverState *bs, |
56 | + 0.9.0 thru 1.2 1991-1995 CWI yes | 51 | BlockDriverState *base, |
57 | + 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes | 52 | diff --git a/block/block-backend.c b/block/block-backend.c |
58 | + 1.6 1.5.2 2000 CNRI no | 53 | index XXXXXXX..XXXXXXX 100644 |
59 | + 2.0 1.6 2000 BeOpen.com no | 54 | --- a/block/block-backend.c |
60 | + 1.6.1 1.6 2001 CNRI yes (2) | 55 | +++ b/block/block-backend.c |
61 | + 2.1 2.0+1.6.1 2001 PSF no | 56 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, |
62 | + 2.0.1 2.0+1.6.1 2001 PSF yes | 57 | } |
63 | + 2.1.1 2.1+2.0.1 2001 PSF yes | 58 | |
64 | + 2.2 2.1.1 2001 PSF yes | 59 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ |
65 | + 2.1.2 2.1.1 2002 PSF yes | 60 | -int coroutine_fn |
66 | + 2.1.3 2.1.2 2002 PSF yes | 61 | +static int coroutine_fn |
67 | + 2.2.1 2.2 2002 PSF yes | 62 | blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, |
68 | + 2.2.2 2.2.1 2002 PSF yes | 63 | QEMUIOVector *qiov, size_t qiov_offset, |
69 | + 2.2.3 2.2.2 2003 PSF yes | 64 | BdrvRequestFlags flags) |
70 | + 2.3 2.2.2 2002-2003 PSF yes | 65 | @@ -XXX,XX +XXX,XX @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf, |
71 | + 2.3.1 2.3 2002-2003 PSF yes | 66 | } |
72 | + 2.3.2 2.3.1 2002-2003 PSF yes | 67 | |
73 | + 2.3.3 2.3.2 2002-2003 PSF yes | 68 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ |
74 | + 2.3.4 2.3.3 2004 PSF yes | 69 | -int coroutine_fn |
75 | + 2.3.5 2.3.4 2005 PSF yes | 70 | +static int coroutine_fn |
76 | + 2.4 2.3 2004 PSF yes | 71 | blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes) |
77 | + 2.4.1 2.4 2005 PSF yes | 72 | { |
78 | + 2.4.2 2.4.1 2005 PSF yes | 73 | int ret; |
79 | + 2.4.3 2.4.2 2006 PSF yes | 74 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, |
80 | + 2.5 2.4 2006 PSF yes | 75 | } |
81 | + 2.7 2.6 2010 PSF yes | 76 | |
82 | + | 77 | /* To be called between exactly one pair of blk_inc/dec_in_flight() */ |
83 | +Footnotes: | 78 | -int coroutine_fn blk_co_do_flush(BlockBackend *blk) |
84 | + | 79 | +static int coroutine_fn blk_co_do_flush(BlockBackend *blk) |
85 | +(1) GPL-compatible doesn't mean that we're distributing Python under | 80 | { |
86 | + the GPL. All Python licenses, unlike the GPL, let you distribute | 81 | blk_wait_while_drained(blk); |
87 | + a modified version without making your changes open source. The | 82 | IO_CODE(); |
88 | + GPL-compatible licenses make it possible to combine Python with | ||
89 | + other software that is released under the GPL; the others don't. | ||
90 | + | ||
91 | +(2) According to Richard Stallman, 1.6.1 is not GPL-compatible, | ||
92 | + because its license has a choice of law clause. According to | ||
93 | + CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1 | ||
94 | + is "not incompatible" with the GPL. | ||
95 | + | ||
96 | +Thanks to the many outside volunteers who have worked under Guido's | ||
97 | +direction to make these releases possible. | ||
98 | + | ||
99 | + | ||
100 | +B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON | ||
101 | +=============================================================== | ||
102 | + | ||
103 | +PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 | ||
104 | +-------------------------------------------- | ||
105 | + | ||
106 | +1. This LICENSE AGREEMENT is between the Python Software Foundation | ||
107 | +("PSF"), and the Individual or Organization ("Licensee") accessing and | ||
108 | +otherwise using this software ("Python") in source or binary form and | ||
109 | +its associated documentation. | ||
110 | + | ||
111 | +2. Subject to the terms and conditions of this License Agreement, PSF | ||
112 | +hereby grants Licensee a nonexclusive, royalty-free, world-wide | ||
113 | +license to reproduce, analyze, test, perform and/or display publicly, | ||
114 | +prepare derivative works, distribute, and otherwise use Python | ||
115 | +alone or in any derivative version, provided, however, that PSF's | ||
116 | +License Agreement and PSF's notice of copyright, i.e., "Copyright (c) | ||
117 | +2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation; All Rights | ||
118 | +Reserved" are retained in Python alone or in any derivative version | ||
119 | +prepared by Licensee. | ||
120 | + | ||
121 | +3. In the event Licensee prepares a derivative work that is based on | ||
122 | +or incorporates Python or any part thereof, and wants to make | ||
123 | +the derivative work available to others as provided herein, then | ||
124 | +Licensee hereby agrees to include in any such work a brief summary of | ||
125 | +the changes made to Python. | ||
126 | + | ||
127 | +4. PSF is making Python available to Licensee on an "AS IS" | ||
128 | +basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
129 | +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND | ||
130 | +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
131 | +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT | ||
132 | +INFRINGE ANY THIRD PARTY RIGHTS. | ||
133 | + | ||
134 | +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON | ||
135 | +FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS | ||
136 | +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, | ||
137 | +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
138 | + | ||
139 | +6. This License Agreement will automatically terminate upon a material | ||
140 | +breach of its terms and conditions. | ||
141 | + | ||
142 | +7. Nothing in this License Agreement shall be deemed to create any | ||
143 | +relationship of agency, partnership, or joint venture between PSF and | ||
144 | +Licensee. This License Agreement does not grant permission to use PSF | ||
145 | +trademarks or trade name in a trademark sense to endorse or promote | ||
146 | +products or services of Licensee, or any third party. | ||
147 | + | ||
148 | +8. By copying, installing or otherwise using Python, Licensee | ||
149 | +agrees to be bound by the terms and conditions of this License | ||
150 | +Agreement. | ||
151 | + | ||
152 | + | ||
153 | +BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 | ||
154 | +------------------------------------------- | ||
155 | + | ||
156 | +BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 | ||
157 | + | ||
158 | +1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an | ||
159 | +office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the | ||
160 | +Individual or Organization ("Licensee") accessing and otherwise using | ||
161 | +this software in source or binary form and its associated | ||
162 | +documentation ("the Software"). | ||
163 | + | ||
164 | +2. Subject to the terms and conditions of this BeOpen Python License | ||
165 | +Agreement, BeOpen hereby grants Licensee a non-exclusive, | ||
166 | +royalty-free, world-wide license to reproduce, analyze, test, perform | ||
167 | +and/or display publicly, prepare derivative works, distribute, and | ||
168 | +otherwise use the Software alone or in any derivative version, | ||
169 | +provided, however, that the BeOpen Python License is retained in the | ||
170 | +Software, alone or in any derivative version prepared by Licensee. | ||
171 | + | ||
172 | +3. BeOpen is making the Software available to Licensee on an "AS IS" | ||
173 | +basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
174 | +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND | ||
175 | +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
176 | +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT | ||
177 | +INFRINGE ANY THIRD PARTY RIGHTS. | ||
178 | + | ||
179 | +4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE | ||
180 | +SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS | ||
181 | +AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY | ||
182 | +DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
183 | + | ||
184 | +5. This License Agreement will automatically terminate upon a material | ||
185 | +breach of its terms and conditions. | ||
186 | + | ||
187 | +6. This License Agreement shall be governed by and interpreted in all | ||
188 | +respects by the law of the State of California, excluding conflict of | ||
189 | +law provisions. Nothing in this License Agreement shall be deemed to | ||
190 | +create any relationship of agency, partnership, or joint venture | ||
191 | +between BeOpen and Licensee. This License Agreement does not grant | ||
192 | +permission to use BeOpen trademarks or trade names in a trademark | ||
193 | +sense to endorse or promote products or services of Licensee, or any | ||
194 | +third party. As an exception, the "BeOpen Python" logos available at | ||
195 | +http://www.pythonlabs.com/logos.html may be used according to the | ||
196 | +permissions granted on that web page. | ||
197 | + | ||
198 | +7. By copying, installing or otherwise using the software, Licensee | ||
199 | +agrees to be bound by the terms and conditions of this License | ||
200 | +Agreement. | ||
201 | + | ||
202 | + | ||
203 | +CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 | ||
204 | +--------------------------------------- | ||
205 | + | ||
206 | +1. This LICENSE AGREEMENT is between the Corporation for National | ||
207 | +Research Initiatives, having an office at 1895 Preston White Drive, | ||
208 | +Reston, VA 20191 ("CNRI"), and the Individual or Organization | ||
209 | +("Licensee") accessing and otherwise using Python 1.6.1 software in | ||
210 | +source or binary form and its associated documentation. | ||
211 | + | ||
212 | +2. Subject to the terms and conditions of this License Agreement, CNRI | ||
213 | +hereby grants Licensee a nonexclusive, royalty-free, world-wide | ||
214 | +license to reproduce, analyze, test, perform and/or display publicly, | ||
215 | +prepare derivative works, distribute, and otherwise use Python 1.6.1 | ||
216 | +alone or in any derivative version, provided, however, that CNRI's | ||
217 | +License Agreement and CNRI's notice of copyright, i.e., "Copyright (c) | ||
218 | +1995-2001 Corporation for National Research Initiatives; All Rights | ||
219 | +Reserved" are retained in Python 1.6.1 alone or in any derivative | ||
220 | +version prepared by Licensee. Alternately, in lieu of CNRI's License | ||
221 | +Agreement, Licensee may substitute the following text (omitting the | ||
222 | +quotes): "Python 1.6.1 is made available subject to the terms and | ||
223 | +conditions in CNRI's License Agreement. This Agreement together with | ||
224 | +Python 1.6.1 may be located on the Internet using the following | ||
225 | +unique, persistent identifier (known as a handle): 1895.22/1013. This | ||
226 | +Agreement may also be obtained from a proxy server on the Internet | ||
227 | +using the following URL: http://hdl.handle.net/1895.22/1013". | ||
228 | + | ||
229 | +3. In the event Licensee prepares a derivative work that is based on | ||
230 | +or incorporates Python 1.6.1 or any part thereof, and wants to make | ||
231 | +the derivative work available to others as provided herein, then | ||
232 | +Licensee hereby agrees to include in any such work a brief summary of | ||
233 | +the changes made to Python 1.6.1. | ||
234 | + | ||
235 | +4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" | ||
236 | +basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR | ||
237 | +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND | ||
238 | +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS | ||
239 | +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT | ||
240 | +INFRINGE ANY THIRD PARTY RIGHTS. | ||
241 | + | ||
242 | +5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON | ||
243 | +1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS | ||
244 | +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, | ||
245 | +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. | ||
246 | + | ||
247 | +6. This License Agreement will automatically terminate upon a material | ||
248 | +breach of its terms and conditions. | ||
249 | + | ||
250 | +7. This License Agreement shall be governed by the federal | ||
251 | +intellectual property law of the United States, including without | ||
252 | +limitation the federal copyright law, and, to the extent such | ||
253 | +U.S. federal law does not apply, by the law of the Commonwealth of | ||
254 | +Virginia, excluding Virginia's conflict of law provisions. | ||
255 | +Notwithstanding the foregoing, with regard to derivative works based | ||
256 | +on Python 1.6.1 that incorporate non-separable material that was | ||
257 | +previously distributed under the GNU General Public License (GPL), the | ||
258 | +law of the Commonwealth of Virginia shall govern this License | ||
259 | +Agreement only as to issues arising under or with respect to | ||
260 | +Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this | ||
261 | +License Agreement shall be deemed to create any relationship of | ||
262 | +agency, partnership, or joint venture between CNRI and Licensee. This | ||
263 | +License Agreement does not grant permission to use CNRI trademarks or | ||
264 | +trade name in a trademark sense to endorse or promote products or | ||
265 | +services of Licensee, or any third party. | ||
266 | + | ||
267 | +8. By clicking on the "ACCEPT" button where indicated, or by copying, | ||
268 | +installing or otherwise using Python 1.6.1, Licensee agrees to be | ||
269 | +bound by the terms and conditions of this License Agreement. | ||
270 | + | ||
271 | + ACCEPT | ||
272 | + | ||
273 | + | ||
274 | +CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 | ||
275 | +-------------------------------------------------- | ||
276 | + | ||
277 | +Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam, | ||
278 | +The Netherlands. All rights reserved. | ||
279 | + | ||
280 | +Permission to use, copy, modify, and distribute this software and its | ||
281 | +documentation for any purpose and without fee is hereby granted, | ||
282 | +provided that the above copyright notice appear in all copies and that | ||
283 | +both that copyright notice and this permission notice appear in | ||
284 | +supporting documentation, and that the name of Stichting Mathematisch | ||
285 | +Centrum or CWI not be used in advertising or publicity pertaining to | ||
286 | +distribution of the software without specific, written prior | ||
287 | +permission. | ||
288 | + | ||
289 | +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | ||
290 | +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
291 | +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | ||
292 | +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
293 | +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
294 | +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | ||
295 | +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
296 | diff --git a/scripts/argparse.py b/scripts/argparse.py | ||
297 | new file mode 100644 | ||
298 | index XXXXXXX..XXXXXXX | ||
299 | --- /dev/null | ||
300 | +++ b/scripts/argparse.py | ||
301 | @@ -XXX,XX +XXX,XX @@ | ||
302 | +# This is a local copy of the standard library argparse module taken from PyPI. | ||
303 | +# It is licensed under the Python Software Foundation License. This is a | ||
304 | +# fallback for Python 2.6 which does not include this module. Python 2.7+ and | ||
305 | +# 3+ will never load this module because built-in modules are loaded before | ||
306 | +# anything in sys.path. | ||
307 | +# | ||
308 | +# If your script is not located in the same directory as this file, import it | ||
309 | +# like this: | ||
310 | +# | ||
311 | +# import os | ||
312 | +# import sys | ||
313 | +# sys.path.append(os.path.join(os.path.dirname(__file__), ..., 'scripts')) | ||
314 | +# import argparse | ||
315 | + | ||
316 | +# Author: Steven J. Bethard <steven.bethard@gmail.com>. | ||
317 | +# Maintainer: Thomas Waldmann <tw@waldmann-edv.de> | ||
318 | + | ||
319 | +"""Command-line parsing library | ||
320 | + | ||
321 | +This module is an optparse-inspired command-line parsing library that: | ||
322 | + | ||
323 | + - handles both optional and positional arguments | ||
324 | + - produces highly informative usage messages | ||
325 | + - supports parsers that dispatch to sub-parsers | ||
326 | + | ||
327 | +The following is a simple usage example that sums integers from the | ||
328 | +command-line and writes the result to a file:: | ||
329 | + | ||
330 | + parser = argparse.ArgumentParser( | ||
331 | + description='sum the integers at the command line') | ||
332 | + parser.add_argument( | ||
333 | + 'integers', metavar='int', nargs='+', type=int, | ||
334 | + help='an integer to be summed') | ||
335 | + parser.add_argument( | ||
336 | + '--log', default=sys.stdout, type=argparse.FileType('w'), | ||
337 | + help='the file where the sum should be written') | ||
338 | + args = parser.parse_args() | ||
339 | + args.log.write('%s' % sum(args.integers)) | ||
340 | + args.log.close() | ||
341 | + | ||
342 | +The module contains the following public classes: | ||
343 | + | ||
344 | + - ArgumentParser -- The main entry point for command-line parsing. As the | ||
345 | + example above shows, the add_argument() method is used to populate | ||
346 | + the parser with actions for optional and positional arguments. Then | ||
347 | + the parse_args() method is invoked to convert the args at the | ||
348 | + command-line into an object with attributes. | ||
349 | + | ||
350 | + - ArgumentError -- The exception raised by ArgumentParser objects when | ||
351 | + there are errors with the parser's actions. Errors raised while | ||
352 | + parsing the command-line are caught by ArgumentParser and emitted | ||
353 | + as command-line messages. | ||
354 | + | ||
355 | + - FileType -- A factory for defining types of files to be created. As the | ||
356 | + example above shows, instances of FileType are typically passed as | ||
357 | + the type= argument of add_argument() calls. | ||
358 | + | ||
359 | + - Action -- The base class for parser actions. Typically actions are | ||
360 | + selected by passing strings like 'store_true' or 'append_const' to | ||
361 | + the action= argument of add_argument(). However, for greater | ||
362 | + customization of ArgumentParser actions, subclasses of Action may | ||
363 | + be defined and passed as the action= argument. | ||
364 | + | ||
365 | + - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter, | ||
366 | + ArgumentDefaultsHelpFormatter -- Formatter classes which | ||
367 | + may be passed as the formatter_class= argument to the | ||
368 | + ArgumentParser constructor. HelpFormatter is the default, | ||
369 | + RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser | ||
370 | + not to change the formatting for help text, and | ||
371 | + ArgumentDefaultsHelpFormatter adds information about argument defaults | ||
372 | + to the help. | ||
373 | + | ||
374 | +All other classes in this module are considered implementation details. | ||
375 | +(Also note that HelpFormatter and RawDescriptionHelpFormatter are only | ||
376 | +considered public as object names -- the API of the formatter objects is | ||
377 | +still considered an implementation detail.) | ||
378 | +""" | ||
379 | + | ||
380 | +__version__ = '1.4.0' # we use our own version number independant of the | ||
381 | + # one in stdlib and we release this on pypi. | ||
382 | + | ||
383 | +__external_lib__ = True # to make sure the tests really test THIS lib, | ||
384 | + # not the builtin one in Python stdlib | ||
385 | + | ||
386 | +__all__ = [ | ||
387 | + 'ArgumentParser', | ||
388 | + 'ArgumentError', | ||
389 | + 'ArgumentTypeError', | ||
390 | + 'FileType', | ||
391 | + 'HelpFormatter', | ||
392 | + 'ArgumentDefaultsHelpFormatter', | ||
393 | + 'RawDescriptionHelpFormatter', | ||
394 | + 'RawTextHelpFormatter', | ||
395 | + 'Namespace', | ||
396 | + 'Action', | ||
397 | + 'ONE_OR_MORE', | ||
398 | + 'OPTIONAL', | ||
399 | + 'PARSER', | ||
400 | + 'REMAINDER', | ||
401 | + 'SUPPRESS', | ||
402 | + 'ZERO_OR_MORE', | ||
403 | +] | ||
404 | + | ||
405 | + | ||
406 | +import copy as _copy | ||
407 | +import os as _os | ||
408 | +import re as _re | ||
409 | +import sys as _sys | ||
410 | +import textwrap as _textwrap | ||
411 | + | ||
412 | +from gettext import gettext as _ | ||
413 | + | ||
414 | +try: | ||
415 | + set | ||
416 | +except NameError: | ||
417 | + # for python < 2.4 compatibility (sets module is there since 2.3): | ||
418 | + from sets import Set as set | ||
419 | + | ||
420 | +try: | ||
421 | + basestring | ||
422 | +except NameError: | ||
423 | + basestring = str | ||
424 | + | ||
425 | +try: | ||
426 | + sorted | ||
427 | +except NameError: | ||
428 | + # for python < 2.4 compatibility: | ||
429 | + def sorted(iterable, reverse=False): | ||
430 | + result = list(iterable) | ||
431 | + result.sort() | ||
432 | + if reverse: | ||
433 | + result.reverse() | ||
434 | + return result | ||
435 | + | ||
436 | + | ||
437 | +def _callable(obj): | ||
438 | + return hasattr(obj, '__call__') or hasattr(obj, '__bases__') | ||
439 | + | ||
440 | + | ||
441 | +SUPPRESS = '==SUPPRESS==' | ||
442 | + | ||
443 | +OPTIONAL = '?' | ||
444 | +ZERO_OR_MORE = '*' | ||
445 | +ONE_OR_MORE = '+' | ||
446 | +PARSER = 'A...' | ||
447 | +REMAINDER = '...' | ||
448 | +_UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args' | ||
449 | + | ||
450 | +# ============================= | ||
451 | +# Utility functions and classes | ||
452 | +# ============================= | ||
453 | + | ||
454 | +class _AttributeHolder(object): | ||
455 | + """Abstract base class that provides __repr__. | ||
456 | + | ||
457 | + The __repr__ method returns a string in the format:: | ||
458 | + ClassName(attr=name, attr=name, ...) | ||
459 | + The attributes are determined either by a class-level attribute, | ||
460 | + '_kwarg_names', or by inspecting the instance __dict__. | ||
461 | + """ | ||
462 | + | ||
463 | + def __repr__(self): | ||
464 | + type_name = type(self).__name__ | ||
465 | + arg_strings = [] | ||
466 | + for arg in self._get_args(): | ||
467 | + arg_strings.append(repr(arg)) | ||
468 | + for name, value in self._get_kwargs(): | ||
469 | + arg_strings.append('%s=%r' % (name, value)) | ||
470 | + return '%s(%s)' % (type_name, ', '.join(arg_strings)) | ||
471 | + | ||
472 | + def _get_kwargs(self): | ||
473 | + return sorted(self.__dict__.items()) | ||
474 | + | ||
475 | + def _get_args(self): | ||
476 | + return [] | ||
477 | + | ||
478 | + | ||
479 | +def _ensure_value(namespace, name, value): | ||
480 | + if getattr(namespace, name, None) is None: | ||
481 | + setattr(namespace, name, value) | ||
482 | + return getattr(namespace, name) | ||
483 | + | ||
484 | + | ||
485 | +# =============== | ||
486 | +# Formatting Help | ||
487 | +# =============== | ||
488 | + | ||
489 | +class HelpFormatter(object): | ||
490 | + """Formatter for generating usage messages and argument help strings. | ||
491 | + | ||
492 | + Only the name of this class is considered a public API. All the methods | ||
493 | + provided by the class are considered an implementation detail. | ||
494 | + """ | ||
495 | + | ||
496 | + def __init__(self, | ||
497 | + prog, | ||
498 | + indent_increment=2, | ||
499 | + max_help_position=24, | ||
500 | + width=None): | ||
501 | + | ||
502 | + # default setting for width | ||
503 | + if width is None: | ||
504 | + try: | ||
505 | + width = int(_os.environ['COLUMNS']) | ||
506 | + except (KeyError, ValueError): | ||
507 | + width = 80 | ||
508 | + width -= 2 | ||
509 | + | ||
510 | + self._prog = prog | ||
511 | + self._indent_increment = indent_increment | ||
512 | + self._max_help_position = max_help_position | ||
513 | + self._width = width | ||
514 | + | ||
515 | + self._current_indent = 0 | ||
516 | + self._level = 0 | ||
517 | + self._action_max_length = 0 | ||
518 | + | ||
519 | + self._root_section = self._Section(self, None) | ||
520 | + self._current_section = self._root_section | ||
521 | + | ||
522 | + self._whitespace_matcher = _re.compile(r'\s+') | ||
523 | + self._long_break_matcher = _re.compile(r'\n\n\n+') | ||
524 | + | ||
525 | + # =============================== | ||
526 | + # Section and indentation methods | ||
527 | + # =============================== | ||
528 | + def _indent(self): | ||
529 | + self._current_indent += self._indent_increment | ||
530 | + self._level += 1 | ||
531 | + | ||
532 | + def _dedent(self): | ||
533 | + self._current_indent -= self._indent_increment | ||
534 | + assert self._current_indent >= 0, 'Indent decreased below 0.' | ||
535 | + self._level -= 1 | ||
536 | + | ||
537 | + class _Section(object): | ||
538 | + | ||
539 | + def __init__(self, formatter, parent, heading=None): | ||
540 | + self.formatter = formatter | ||
541 | + self.parent = parent | ||
542 | + self.heading = heading | ||
543 | + self.items = [] | ||
544 | + | ||
545 | + def format_help(self): | ||
546 | + # format the indented section | ||
547 | + if self.parent is not None: | ||
548 | + self.formatter._indent() | ||
549 | + join = self.formatter._join_parts | ||
550 | + for func, args in self.items: | ||
551 | + func(*args) | ||
552 | + item_help = join([func(*args) for func, args in self.items]) | ||
553 | + if self.parent is not None: | ||
554 | + self.formatter._dedent() | ||
555 | + | ||
556 | + # return nothing if the section was empty | ||
557 | + if not item_help: | ||
558 | + return '' | ||
559 | + | ||
560 | + # add the heading if the section was non-empty | ||
561 | + if self.heading is not SUPPRESS and self.heading is not None: | ||
562 | + current_indent = self.formatter._current_indent | ||
563 | + heading = '%*s%s:\n' % (current_indent, '', self.heading) | ||
564 | + else: | ||
565 | + heading = '' | ||
566 | + | ||
567 | + # join the section-initial newline, the heading and the help | ||
568 | + return join(['\n', heading, item_help, '\n']) | ||
569 | + | ||
570 | + def _add_item(self, func, args): | ||
571 | + self._current_section.items.append((func, args)) | ||
572 | + | ||
573 | + # ======================== | ||
574 | + # Message building methods | ||
575 | + # ======================== | ||
576 | + def start_section(self, heading): | ||
577 | + self._indent() | ||
578 | + section = self._Section(self, self._current_section, heading) | ||
579 | + self._add_item(section.format_help, []) | ||
580 | + self._current_section = section | ||
581 | + | ||
582 | + def end_section(self): | ||
583 | + self._current_section = self._current_section.parent | ||
584 | + self._dedent() | ||
585 | + | ||
586 | + def add_text(self, text): | ||
587 | + if text is not SUPPRESS and text is not None: | ||
588 | + self._add_item(self._format_text, [text]) | ||
589 | + | ||
590 | + def add_usage(self, usage, actions, groups, prefix=None): | ||
591 | + if usage is not SUPPRESS: | ||
592 | + args = usage, actions, groups, prefix | ||
593 | + self._add_item(self._format_usage, args) | ||
594 | + | ||
595 | + def add_argument(self, action): | ||
596 | + if action.help is not SUPPRESS: | ||
597 | + | ||
598 | + # find all invocations | ||
599 | + get_invocation = self._format_action_invocation | ||
600 | + invocations = [get_invocation(action)] | ||
601 | + for subaction in self._iter_indented_subactions(action): | ||
602 | + invocations.append(get_invocation(subaction)) | ||
603 | + | ||
604 | + # update the maximum item length | ||
605 | + invocation_length = max([len(s) for s in invocations]) | ||
606 | + action_length = invocation_length + self._current_indent | ||
607 | + self._action_max_length = max(self._action_max_length, | ||
608 | + action_length) | ||
609 | + | ||
610 | + # add the item to the list | ||
611 | + self._add_item(self._format_action, [action]) | ||
612 | + | ||
613 | + def add_arguments(self, actions): | ||
614 | + for action in actions: | ||
615 | + self.add_argument(action) | ||
616 | + | ||
617 | + # ======================= | ||
618 | + # Help-formatting methods | ||
619 | + # ======================= | ||
620 | + def format_help(self): | ||
621 | + help = self._root_section.format_help() | ||
622 | + if help: | ||
623 | + help = self._long_break_matcher.sub('\n\n', help) | ||
624 | + help = help.strip('\n') + '\n' | ||
625 | + return help | ||
626 | + | ||
627 | + def _join_parts(self, part_strings): | ||
628 | + return ''.join([part | ||
629 | + for part in part_strings | ||
630 | + if part and part is not SUPPRESS]) | ||
631 | + | ||
632 | + def _format_usage(self, usage, actions, groups, prefix): | ||
633 | + if prefix is None: | ||
634 | + prefix = _('usage: ') | ||
635 | + | ||
636 | + # if usage is specified, use that | ||
637 | + if usage is not None: | ||
638 | + usage = usage % dict(prog=self._prog) | ||
639 | + | ||
640 | + # if no optionals or positionals are available, usage is just prog | ||
641 | + elif usage is None and not actions: | ||
642 | + usage = '%(prog)s' % dict(prog=self._prog) | ||
643 | + | ||
644 | + # if optionals and positionals are available, calculate usage | ||
645 | + elif usage is None: | ||
646 | + prog = '%(prog)s' % dict(prog=self._prog) | ||
647 | + | ||
648 | + # split optionals from positionals | ||
649 | + optionals = [] | ||
650 | + positionals = [] | ||
651 | + for action in actions: | ||
652 | + if action.option_strings: | ||
653 | + optionals.append(action) | ||
654 | + else: | ||
655 | + positionals.append(action) | ||
656 | + | ||
657 | + # build full usage string | ||
658 | + format = self._format_actions_usage | ||
659 | + action_usage = format(optionals + positionals, groups) | ||
660 | + usage = ' '.join([s for s in [prog, action_usage] if s]) | ||
661 | + | ||
662 | + # wrap the usage parts if it's too long | ||
663 | + text_width = self._width - self._current_indent | ||
664 | + if len(prefix) + len(usage) > text_width: | ||
665 | + | ||
666 | + # break usage into wrappable parts | ||
667 | + part_regexp = r'\(.*?\)+|\[.*?\]+|\S+' | ||
668 | + opt_usage = format(optionals, groups) | ||
669 | + pos_usage = format(positionals, groups) | ||
670 | + opt_parts = _re.findall(part_regexp, opt_usage) | ||
671 | + pos_parts = _re.findall(part_regexp, pos_usage) | ||
672 | + assert ' '.join(opt_parts) == opt_usage | ||
673 | + assert ' '.join(pos_parts) == pos_usage | ||
674 | + | ||
675 | + # helper for wrapping lines | ||
676 | + def get_lines(parts, indent, prefix=None): | ||
677 | + lines = [] | ||
678 | + line = [] | ||
679 | + if prefix is not None: | ||
680 | + line_len = len(prefix) - 1 | ||
681 | + else: | ||
682 | + line_len = len(indent) - 1 | ||
683 | + for part in parts: | ||
684 | + if line_len + 1 + len(part) > text_width: | ||
685 | + lines.append(indent + ' '.join(line)) | ||
686 | + line = [] | ||
687 | + line_len = len(indent) - 1 | ||
688 | + line.append(part) | ||
689 | + line_len += len(part) + 1 | ||
690 | + if line: | ||
691 | + lines.append(indent + ' '.join(line)) | ||
692 | + if prefix is not None: | ||
693 | + lines[0] = lines[0][len(indent):] | ||
694 | + return lines | ||
695 | + | ||
696 | + # if prog is short, follow it with optionals or positionals | ||
697 | + if len(prefix) + len(prog) <= 0.75 * text_width: | ||
698 | + indent = ' ' * (len(prefix) + len(prog) + 1) | ||
699 | + if opt_parts: | ||
700 | + lines = get_lines([prog] + opt_parts, indent, prefix) | ||
701 | + lines.extend(get_lines(pos_parts, indent)) | ||
702 | + elif pos_parts: | ||
703 | + lines = get_lines([prog] + pos_parts, indent, prefix) | ||
704 | + else: | ||
705 | + lines = [prog] | ||
706 | + | ||
707 | + # if prog is long, put it on its own line | ||
708 | + else: | ||
709 | + indent = ' ' * len(prefix) | ||
710 | + parts = opt_parts + pos_parts | ||
711 | + lines = get_lines(parts, indent) | ||
712 | + if len(lines) > 1: | ||
713 | + lines = [] | ||
714 | + lines.extend(get_lines(opt_parts, indent)) | ||
715 | + lines.extend(get_lines(pos_parts, indent)) | ||
716 | + lines = [prog] + lines | ||
717 | + | ||
718 | + # join lines into usage | ||
719 | + usage = '\n'.join(lines) | ||
720 | + | ||
721 | + # prefix with 'usage:' | ||
722 | + return '%s%s\n\n' % (prefix, usage) | ||
723 | + | ||
724 | + def _format_actions_usage(self, actions, groups): | ||
725 | + # find group indices and identify actions in groups | ||
726 | + group_actions = set() | ||
727 | + inserts = {} | ||
728 | + for group in groups: | ||
729 | + try: | ||
730 | + start = actions.index(group._group_actions[0]) | ||
731 | + except ValueError: | ||
732 | + continue | ||
733 | + else: | ||
734 | + end = start + len(group._group_actions) | ||
735 | + if actions[start:end] == group._group_actions: | ||
736 | + for action in group._group_actions: | ||
737 | + group_actions.add(action) | ||
738 | + if not group.required: | ||
739 | + if start in inserts: | ||
740 | + inserts[start] += ' [' | ||
741 | + else: | ||
742 | + inserts[start] = '[' | ||
743 | + inserts[end] = ']' | ||
744 | + else: | ||
745 | + if start in inserts: | ||
746 | + inserts[start] += ' (' | ||
747 | + else: | ||
748 | + inserts[start] = '(' | ||
749 | + inserts[end] = ')' | ||
750 | + for i in range(start + 1, end): | ||
751 | + inserts[i] = '|' | ||
752 | + | ||
753 | + # collect all actions format strings | ||
754 | + parts = [] | ||
755 | + for i, action in enumerate(actions): | ||
756 | + | ||
757 | + # suppressed arguments are marked with None | ||
758 | + # remove | separators for suppressed arguments | ||
759 | + if action.help is SUPPRESS: | ||
760 | + parts.append(None) | ||
761 | + if inserts.get(i) == '|': | ||
762 | + inserts.pop(i) | ||
763 | + elif inserts.get(i + 1) == '|': | ||
764 | + inserts.pop(i + 1) | ||
765 | + | ||
766 | + # produce all arg strings | ||
767 | + elif not action.option_strings: | ||
768 | + part = self._format_args(action, action.dest) | ||
769 | + | ||
770 | + # if it's in a group, strip the outer [] | ||
771 | + if action in group_actions: | ||
772 | + if part[0] == '[' and part[-1] == ']': | ||
773 | + part = part[1:-1] | ||
774 | + | ||
775 | + # add the action string to the list | ||
776 | + parts.append(part) | ||
777 | + | ||
778 | + # produce the first way to invoke the option in brackets | ||
779 | + else: | ||
780 | + option_string = action.option_strings[0] | ||
781 | + | ||
782 | + # if the Optional doesn't take a value, format is: | ||
783 | + # -s or --long | ||
784 | + if action.nargs == 0: | ||
785 | + part = '%s' % option_string | ||
786 | + | ||
787 | + # if the Optional takes a value, format is: | ||
788 | + # -s ARGS or --long ARGS | ||
789 | + else: | ||
790 | + default = action.dest.upper() | ||
791 | + args_string = self._format_args(action, default) | ||
792 | + part = '%s %s' % (option_string, args_string) | ||
793 | + | ||
794 | + # make it look optional if it's not required or in a group | ||
795 | + if not action.required and action not in group_actions: | ||
796 | + part = '[%s]' % part | ||
797 | + | ||
798 | + # add the action string to the list | ||
799 | + parts.append(part) | ||
800 | + | ||
801 | + # insert things at the necessary indices | ||
802 | + for i in sorted(inserts, reverse=True): | ||
803 | + parts[i:i] = [inserts[i]] | ||
804 | + | ||
805 | + # join all the action items with spaces | ||
806 | + text = ' '.join([item for item in parts if item is not None]) | ||
807 | + | ||
808 | + # clean up separators for mutually exclusive groups | ||
809 | + open = r'[\[(]' | ||
810 | + close = r'[\])]' | ||
811 | + text = _re.sub(r'(%s) ' % open, r'\1', text) | ||
812 | + text = _re.sub(r' (%s)' % close, r'\1', text) | ||
813 | + text = _re.sub(r'%s *%s' % (open, close), r'', text) | ||
814 | + text = _re.sub(r'\(([^|]*)\)', r'\1', text) | ||
815 | + text = text.strip() | ||
816 | + | ||
817 | + # return the text | ||
818 | + return text | ||
819 | + | ||
820 | + def _format_text(self, text): | ||
821 | + if '%(prog)' in text: | ||
822 | + text = text % dict(prog=self._prog) | ||
823 | + text_width = self._width - self._current_indent | ||
824 | + indent = ' ' * self._current_indent | ||
825 | + return self._fill_text(text, text_width, indent) + '\n\n' | ||
826 | + | ||
827 | + def _format_action(self, action): | ||
828 | + # determine the required width and the entry label | ||
829 | + help_position = min(self._action_max_length + 2, | ||
830 | + self._max_help_position) | ||
831 | + help_width = self._width - help_position | ||
832 | + action_width = help_position - self._current_indent - 2 | ||
833 | + action_header = self._format_action_invocation(action) | ||
834 | + | ||
835 | + # ho nelp; start on same line and add a final newline | ||
836 | + if not action.help: | ||
837 | + tup = self._current_indent, '', action_header | ||
838 | + action_header = '%*s%s\n' % tup | ||
839 | + | ||
840 | + # short action name; start on the same line and pad two spaces | ||
841 | + elif len(action_header) <= action_width: | ||
842 | + tup = self._current_indent, '', action_width, action_header | ||
843 | + action_header = '%*s%-*s ' % tup | ||
844 | + indent_first = 0 | ||
845 | + | ||
846 | + # long action name; start on the next line | ||
847 | + else: | ||
848 | + tup = self._current_indent, '', action_header | ||
849 | + action_header = '%*s%s\n' % tup | ||
850 | + indent_first = help_position | ||
851 | + | ||
852 | + # collect the pieces of the action help | ||
853 | + parts = [action_header] | ||
854 | + | ||
855 | + # if there was help for the action, add lines of help text | ||
856 | + if action.help: | ||
857 | + help_text = self._expand_help(action) | ||
858 | + help_lines = self._split_lines(help_text, help_width) | ||
859 | + parts.append('%*s%s\n' % (indent_first, '', help_lines[0])) | ||
860 | + for line in help_lines[1:]: | ||
861 | + parts.append('%*s%s\n' % (help_position, '', line)) | ||
862 | + | ||
863 | + # or add a newline if the description doesn't end with one | ||
864 | + elif not action_header.endswith('\n'): | ||
865 | + parts.append('\n') | ||
866 | + | ||
867 | + # if there are any sub-actions, add their help as well | ||
868 | + for subaction in self._iter_indented_subactions(action): | ||
869 | + parts.append(self._format_action(subaction)) | ||
870 | + | ||
871 | + # return a single string | ||
872 | + return self._join_parts(parts) | ||
873 | + | ||
874 | + def _format_action_invocation(self, action): | ||
875 | + if not action.option_strings: | ||
876 | + metavar, = self._metavar_formatter(action, action.dest)(1) | ||
877 | + return metavar | ||
878 | + | ||
879 | + else: | ||
880 | + parts = [] | ||
881 | + | ||
882 | + # if the Optional doesn't take a value, format is: | ||
883 | + # -s, --long | ||
884 | + if action.nargs == 0: | ||
885 | + parts.extend(action.option_strings) | ||
886 | + | ||
887 | + # if the Optional takes a value, format is: | ||
888 | + # -s ARGS, --long ARGS | ||
889 | + else: | ||
890 | + default = action.dest.upper() | ||
891 | + args_string = self._format_args(action, default) | ||
892 | + for option_string in action.option_strings: | ||
893 | + parts.append('%s %s' % (option_string, args_string)) | ||
894 | + | ||
895 | + return ', '.join(parts) | ||
896 | + | ||
897 | + def _metavar_formatter(self, action, default_metavar): | ||
898 | + if action.metavar is not None: | ||
899 | + result = action.metavar | ||
900 | + elif action.choices is not None: | ||
901 | + choice_strs = [str(choice) for choice in action.choices] | ||
902 | + result = '{%s}' % ','.join(choice_strs) | ||
903 | + else: | ||
904 | + result = default_metavar | ||
905 | + | ||
906 | + def format(tuple_size): | ||
907 | + if isinstance(result, tuple): | ||
908 | + return result | ||
909 | + else: | ||
910 | + return (result, ) * tuple_size | ||
911 | + return format | ||
912 | + | ||
913 | + def _format_args(self, action, default_metavar): | ||
914 | + get_metavar = self._metavar_formatter(action, default_metavar) | ||
915 | + if action.nargs is None: | ||
916 | + result = '%s' % get_metavar(1) | ||
917 | + elif action.nargs == OPTIONAL: | ||
918 | + result = '[%s]' % get_metavar(1) | ||
919 | + elif action.nargs == ZERO_OR_MORE: | ||
920 | + result = '[%s [%s ...]]' % get_metavar(2) | ||
921 | + elif action.nargs == ONE_OR_MORE: | ||
922 | + result = '%s [%s ...]' % get_metavar(2) | ||
923 | + elif action.nargs == REMAINDER: | ||
924 | + result = '...' | ||
925 | + elif action.nargs == PARSER: | ||
926 | + result = '%s ...' % get_metavar(1) | ||
927 | + else: | ||
928 | + formats = ['%s' for _ in range(action.nargs)] | ||
929 | + result = ' '.join(formats) % get_metavar(action.nargs) | ||
930 | + return result | ||
931 | + | ||
932 | + def _expand_help(self, action): | ||
933 | + params = dict(vars(action), prog=self._prog) | ||
934 | + for name in list(params): | ||
935 | + if params[name] is SUPPRESS: | ||
936 | + del params[name] | ||
937 | + for name in list(params): | ||
938 | + if hasattr(params[name], '__name__'): | ||
939 | + params[name] = params[name].__name__ | ||
940 | + if params.get('choices') is not None: | ||
941 | + choices_str = ', '.join([str(c) for c in params['choices']]) | ||
942 | + params['choices'] = choices_str | ||
943 | + return self._get_help_string(action) % params | ||
944 | + | ||
945 | + def _iter_indented_subactions(self, action): | ||
946 | + try: | ||
947 | + get_subactions = action._get_subactions | ||
948 | + except AttributeError: | ||
949 | + pass | ||
950 | + else: | ||
951 | + self._indent() | ||
952 | + for subaction in get_subactions(): | ||
953 | + yield subaction | ||
954 | + self._dedent() | ||
955 | + | ||
956 | + def _split_lines(self, text, width): | ||
957 | + text = self._whitespace_matcher.sub(' ', text).strip() | ||
958 | + return _textwrap.wrap(text, width) | ||
959 | + | ||
960 | + def _fill_text(self, text, width, indent): | ||
961 | + text = self._whitespace_matcher.sub(' ', text).strip() | ||
962 | + return _textwrap.fill(text, width, initial_indent=indent, | ||
963 | + subsequent_indent=indent) | ||
964 | + | ||
965 | + def _get_help_string(self, action): | ||
966 | + return action.help | ||
967 | + | ||
968 | + | ||
969 | +class RawDescriptionHelpFormatter(HelpFormatter): | ||
970 | + """Help message formatter which retains any formatting in descriptions. | ||
971 | + | ||
972 | + Only the name of this class is considered a public API. All the methods | ||
973 | + provided by the class are considered an implementation detail. | ||
974 | + """ | ||
975 | + | ||
976 | + def _fill_text(self, text, width, indent): | ||
977 | + return ''.join([indent + line for line in text.splitlines(True)]) | ||
978 | + | ||
979 | + | ||
980 | +class RawTextHelpFormatter(RawDescriptionHelpFormatter): | ||
981 | + """Help message formatter which retains formatting of all help text. | ||
982 | + | ||
983 | + Only the name of this class is considered a public API. All the methods | ||
984 | + provided by the class are considered an implementation detail. | ||
985 | + """ | ||
986 | + | ||
987 | + def _split_lines(self, text, width): | ||
988 | + return text.splitlines() | ||
989 | + | ||
990 | + | ||
991 | +class ArgumentDefaultsHelpFormatter(HelpFormatter): | ||
992 | + """Help message formatter which adds default values to argument help. | ||
993 | + | ||
994 | + Only the name of this class is considered a public API. All the methods | ||
995 | + provided by the class are considered an implementation detail. | ||
996 | + """ | ||
997 | + | ||
998 | + def _get_help_string(self, action): | ||
999 | + help = action.help | ||
1000 | + if '%(default)' not in action.help: | ||
1001 | + if action.default is not SUPPRESS: | ||
1002 | + defaulting_nargs = [OPTIONAL, ZERO_OR_MORE] | ||
1003 | + if action.option_strings or action.nargs in defaulting_nargs: | ||
1004 | + help += ' (default: %(default)s)' | ||
1005 | + return help | ||
1006 | + | ||
1007 | + | ||
1008 | +# ===================== | ||
1009 | +# Options and Arguments | ||
1010 | +# ===================== | ||
1011 | + | ||
1012 | +def _get_action_name(argument): | ||
1013 | + if argument is None: | ||
1014 | + return None | ||
1015 | + elif argument.option_strings: | ||
1016 | + return '/'.join(argument.option_strings) | ||
1017 | + elif argument.metavar not in (None, SUPPRESS): | ||
1018 | + return argument.metavar | ||
1019 | + elif argument.dest not in (None, SUPPRESS): | ||
1020 | + return argument.dest | ||
1021 | + else: | ||
1022 | + return None | ||
1023 | + | ||
1024 | + | ||
1025 | +class ArgumentError(Exception): | ||
1026 | + """An error from creating or using an argument (optional or positional). | ||
1027 | + | ||
1028 | + The string value of this exception is the message, augmented with | ||
1029 | + information about the argument that caused it. | ||
1030 | + """ | ||
1031 | + | ||
1032 | + def __init__(self, argument, message): | ||
1033 | + self.argument_name = _get_action_name(argument) | ||
1034 | + self.message = message | ||
1035 | + | ||
1036 | + def __str__(self): | ||
1037 | + if self.argument_name is None: | ||
1038 | + format = '%(message)s' | ||
1039 | + else: | ||
1040 | + format = 'argument %(argument_name)s: %(message)s' | ||
1041 | + return format % dict(message=self.message, | ||
1042 | + argument_name=self.argument_name) | ||
1043 | + | ||
1044 | + | ||
1045 | +class ArgumentTypeError(Exception): | ||
1046 | + """An error from trying to convert a command line string to a type.""" | ||
1047 | + pass | ||
1048 | + | ||
1049 | + | ||
1050 | +# ============== | ||
1051 | +# Action classes | ||
1052 | +# ============== | ||
1053 | + | ||
1054 | +class Action(_AttributeHolder): | ||
1055 | + """Information about how to convert command line strings to Python objects. | ||
1056 | + | ||
1057 | + Action objects are used by an ArgumentParser to represent the information | ||
1058 | + needed to parse a single argument from one or more strings from the | ||
1059 | + command line. The keyword arguments to the Action constructor are also | ||
1060 | + all attributes of Action instances. | ||
1061 | + | ||
1062 | + Keyword Arguments: | ||
1063 | + | ||
1064 | + - option_strings -- A list of command-line option strings which | ||
1065 | + should be associated with this action. | ||
1066 | + | ||
1067 | + - dest -- The name of the attribute to hold the created object(s) | ||
1068 | + | ||
1069 | + - nargs -- The number of command-line arguments that should be | ||
1070 | + consumed. By default, one argument will be consumed and a single | ||
1071 | + value will be produced. Other values include: | ||
1072 | + - N (an integer) consumes N arguments (and produces a list) | ||
1073 | + - '?' consumes zero or one arguments | ||
1074 | + - '*' consumes zero or more arguments (and produces a list) | ||
1075 | + - '+' consumes one or more arguments (and produces a list) | ||
1076 | + Note that the difference between the default and nargs=1 is that | ||
1077 | + with the default, a single value will be produced, while with | ||
1078 | + nargs=1, a list containing a single value will be produced. | ||
1079 | + | ||
1080 | + - const -- The value to be produced if the option is specified and the | ||
1081 | + option uses an action that takes no values. | ||
1082 | + | ||
1083 | + - default -- The value to be produced if the option is not specified. | ||
1084 | + | ||
1085 | + - type -- The type which the command-line arguments should be converted | ||
1086 | + to, should be one of 'string', 'int', 'float', 'complex' or a | ||
1087 | + callable object that accepts a single string argument. If None, | ||
1088 | + 'string' is assumed. | ||
1089 | + | ||
1090 | + - choices -- A container of values that should be allowed. If not None, | ||
1091 | + after a command-line argument has been converted to the appropriate | ||
1092 | + type, an exception will be raised if it is not a member of this | ||
1093 | + collection. | ||
1094 | + | ||
1095 | + - required -- True if the action must always be specified at the | ||
1096 | + command line. This is only meaningful for optional command-line | ||
1097 | + arguments. | ||
1098 | + | ||
1099 | + - help -- The help string describing the argument. | ||
1100 | + | ||
1101 | + - metavar -- The name to be used for the option's argument with the | ||
1102 | + help string. If None, the 'dest' value will be used as the name. | ||
1103 | + """ | ||
1104 | + | ||
1105 | + def __init__(self, | ||
1106 | + option_strings, | ||
1107 | + dest, | ||
1108 | + nargs=None, | ||
1109 | + const=None, | ||
1110 | + default=None, | ||
1111 | + type=None, | ||
1112 | + choices=None, | ||
1113 | + required=False, | ||
1114 | + help=None, | ||
1115 | + metavar=None): | ||
1116 | + self.option_strings = option_strings | ||
1117 | + self.dest = dest | ||
1118 | + self.nargs = nargs | ||
1119 | + self.const = const | ||
1120 | + self.default = default | ||
1121 | + self.type = type | ||
1122 | + self.choices = choices | ||
1123 | + self.required = required | ||
1124 | + self.help = help | ||
1125 | + self.metavar = metavar | ||
1126 | + | ||
1127 | + def _get_kwargs(self): | ||
1128 | + names = [ | ||
1129 | + 'option_strings', | ||
1130 | + 'dest', | ||
1131 | + 'nargs', | ||
1132 | + 'const', | ||
1133 | + 'default', | ||
1134 | + 'type', | ||
1135 | + 'choices', | ||
1136 | + 'help', | ||
1137 | + 'metavar', | ||
1138 | + ] | ||
1139 | + return [(name, getattr(self, name)) for name in names] | ||
1140 | + | ||
1141 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1142 | + raise NotImplementedError(_('.__call__() not defined')) | ||
1143 | + | ||
1144 | + | ||
1145 | +class _StoreAction(Action): | ||
1146 | + | ||
1147 | + def __init__(self, | ||
1148 | + option_strings, | ||
1149 | + dest, | ||
1150 | + nargs=None, | ||
1151 | + const=None, | ||
1152 | + default=None, | ||
1153 | + type=None, | ||
1154 | + choices=None, | ||
1155 | + required=False, | ||
1156 | + help=None, | ||
1157 | + metavar=None): | ||
1158 | + if nargs == 0: | ||
1159 | + raise ValueError('nargs for store actions must be > 0; if you ' | ||
1160 | + 'have nothing to store, actions such as store ' | ||
1161 | + 'true or store const may be more appropriate') | ||
1162 | + if const is not None and nargs != OPTIONAL: | ||
1163 | + raise ValueError('nargs must be %r to supply const' % OPTIONAL) | ||
1164 | + super(_StoreAction, self).__init__( | ||
1165 | + option_strings=option_strings, | ||
1166 | + dest=dest, | ||
1167 | + nargs=nargs, | ||
1168 | + const=const, | ||
1169 | + default=default, | ||
1170 | + type=type, | ||
1171 | + choices=choices, | ||
1172 | + required=required, | ||
1173 | + help=help, | ||
1174 | + metavar=metavar) | ||
1175 | + | ||
1176 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1177 | + setattr(namespace, self.dest, values) | ||
1178 | + | ||
1179 | + | ||
1180 | +class _StoreConstAction(Action): | ||
1181 | + | ||
1182 | + def __init__(self, | ||
1183 | + option_strings, | ||
1184 | + dest, | ||
1185 | + const, | ||
1186 | + default=None, | ||
1187 | + required=False, | ||
1188 | + help=None, | ||
1189 | + metavar=None): | ||
1190 | + super(_StoreConstAction, self).__init__( | ||
1191 | + option_strings=option_strings, | ||
1192 | + dest=dest, | ||
1193 | + nargs=0, | ||
1194 | + const=const, | ||
1195 | + default=default, | ||
1196 | + required=required, | ||
1197 | + help=help) | ||
1198 | + | ||
1199 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1200 | + setattr(namespace, self.dest, self.const) | ||
1201 | + | ||
1202 | + | ||
1203 | +class _StoreTrueAction(_StoreConstAction): | ||
1204 | + | ||
1205 | + def __init__(self, | ||
1206 | + option_strings, | ||
1207 | + dest, | ||
1208 | + default=False, | ||
1209 | + required=False, | ||
1210 | + help=None): | ||
1211 | + super(_StoreTrueAction, self).__init__( | ||
1212 | + option_strings=option_strings, | ||
1213 | + dest=dest, | ||
1214 | + const=True, | ||
1215 | + default=default, | ||
1216 | + required=required, | ||
1217 | + help=help) | ||
1218 | + | ||
1219 | + | ||
1220 | +class _StoreFalseAction(_StoreConstAction): | ||
1221 | + | ||
1222 | + def __init__(self, | ||
1223 | + option_strings, | ||
1224 | + dest, | ||
1225 | + default=True, | ||
1226 | + required=False, | ||
1227 | + help=None): | ||
1228 | + super(_StoreFalseAction, self).__init__( | ||
1229 | + option_strings=option_strings, | ||
1230 | + dest=dest, | ||
1231 | + const=False, | ||
1232 | + default=default, | ||
1233 | + required=required, | ||
1234 | + help=help) | ||
1235 | + | ||
1236 | + | ||
1237 | +class _AppendAction(Action): | ||
1238 | + | ||
1239 | + def __init__(self, | ||
1240 | + option_strings, | ||
1241 | + dest, | ||
1242 | + nargs=None, | ||
1243 | + const=None, | ||
1244 | + default=None, | ||
1245 | + type=None, | ||
1246 | + choices=None, | ||
1247 | + required=False, | ||
1248 | + help=None, | ||
1249 | + metavar=None): | ||
1250 | + if nargs == 0: | ||
1251 | + raise ValueError('nargs for append actions must be > 0; if arg ' | ||
1252 | + 'strings are not supplying the value to append, ' | ||
1253 | + 'the append const action may be more appropriate') | ||
1254 | + if const is not None and nargs != OPTIONAL: | ||
1255 | + raise ValueError('nargs must be %r to supply const' % OPTIONAL) | ||
1256 | + super(_AppendAction, self).__init__( | ||
1257 | + option_strings=option_strings, | ||
1258 | + dest=dest, | ||
1259 | + nargs=nargs, | ||
1260 | + const=const, | ||
1261 | + default=default, | ||
1262 | + type=type, | ||
1263 | + choices=choices, | ||
1264 | + required=required, | ||
1265 | + help=help, | ||
1266 | + metavar=metavar) | ||
1267 | + | ||
1268 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1269 | + items = _copy.copy(_ensure_value(namespace, self.dest, [])) | ||
1270 | + items.append(values) | ||
1271 | + setattr(namespace, self.dest, items) | ||
1272 | + | ||
1273 | + | ||
1274 | +class _AppendConstAction(Action): | ||
1275 | + | ||
1276 | + def __init__(self, | ||
1277 | + option_strings, | ||
1278 | + dest, | ||
1279 | + const, | ||
1280 | + default=None, | ||
1281 | + required=False, | ||
1282 | + help=None, | ||
1283 | + metavar=None): | ||
1284 | + super(_AppendConstAction, self).__init__( | ||
1285 | + option_strings=option_strings, | ||
1286 | + dest=dest, | ||
1287 | + nargs=0, | ||
1288 | + const=const, | ||
1289 | + default=default, | ||
1290 | + required=required, | ||
1291 | + help=help, | ||
1292 | + metavar=metavar) | ||
1293 | + | ||
1294 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1295 | + items = _copy.copy(_ensure_value(namespace, self.dest, [])) | ||
1296 | + items.append(self.const) | ||
1297 | + setattr(namespace, self.dest, items) | ||
1298 | + | ||
1299 | + | ||
1300 | +class _CountAction(Action): | ||
1301 | + | ||
1302 | + def __init__(self, | ||
1303 | + option_strings, | ||
1304 | + dest, | ||
1305 | + default=None, | ||
1306 | + required=False, | ||
1307 | + help=None): | ||
1308 | + super(_CountAction, self).__init__( | ||
1309 | + option_strings=option_strings, | ||
1310 | + dest=dest, | ||
1311 | + nargs=0, | ||
1312 | + default=default, | ||
1313 | + required=required, | ||
1314 | + help=help) | ||
1315 | + | ||
1316 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1317 | + new_count = _ensure_value(namespace, self.dest, 0) + 1 | ||
1318 | + setattr(namespace, self.dest, new_count) | ||
1319 | + | ||
1320 | + | ||
1321 | +class _HelpAction(Action): | ||
1322 | + | ||
1323 | + def __init__(self, | ||
1324 | + option_strings, | ||
1325 | + dest=SUPPRESS, | ||
1326 | + default=SUPPRESS, | ||
1327 | + help=None): | ||
1328 | + super(_HelpAction, self).__init__( | ||
1329 | + option_strings=option_strings, | ||
1330 | + dest=dest, | ||
1331 | + default=default, | ||
1332 | + nargs=0, | ||
1333 | + help=help) | ||
1334 | + | ||
1335 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1336 | + parser.print_help() | ||
1337 | + parser.exit() | ||
1338 | + | ||
1339 | + | ||
1340 | +class _VersionAction(Action): | ||
1341 | + | ||
1342 | + def __init__(self, | ||
1343 | + option_strings, | ||
1344 | + version=None, | ||
1345 | + dest=SUPPRESS, | ||
1346 | + default=SUPPRESS, | ||
1347 | + help="show program's version number and exit"): | ||
1348 | + super(_VersionAction, self).__init__( | ||
1349 | + option_strings=option_strings, | ||
1350 | + dest=dest, | ||
1351 | + default=default, | ||
1352 | + nargs=0, | ||
1353 | + help=help) | ||
1354 | + self.version = version | ||
1355 | + | ||
1356 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1357 | + version = self.version | ||
1358 | + if version is None: | ||
1359 | + version = parser.version | ||
1360 | + formatter = parser._get_formatter() | ||
1361 | + formatter.add_text(version) | ||
1362 | + parser.exit(message=formatter.format_help()) | ||
1363 | + | ||
1364 | + | ||
1365 | +class _SubParsersAction(Action): | ||
1366 | + | ||
1367 | + class _ChoicesPseudoAction(Action): | ||
1368 | + | ||
1369 | + def __init__(self, name, aliases, help): | ||
1370 | + metavar = dest = name | ||
1371 | + if aliases: | ||
1372 | + metavar += ' (%s)' % ', '.join(aliases) | ||
1373 | + sup = super(_SubParsersAction._ChoicesPseudoAction, self) | ||
1374 | + sup.__init__(option_strings=[], dest=dest, help=help, | ||
1375 | + metavar=metavar) | ||
1376 | + | ||
1377 | + def __init__(self, | ||
1378 | + option_strings, | ||
1379 | + prog, | ||
1380 | + parser_class, | ||
1381 | + dest=SUPPRESS, | ||
1382 | + help=None, | ||
1383 | + metavar=None): | ||
1384 | + | ||
1385 | + self._prog_prefix = prog | ||
1386 | + self._parser_class = parser_class | ||
1387 | + self._name_parser_map = {} | ||
1388 | + self._choices_actions = [] | ||
1389 | + | ||
1390 | + super(_SubParsersAction, self).__init__( | ||
1391 | + option_strings=option_strings, | ||
1392 | + dest=dest, | ||
1393 | + nargs=PARSER, | ||
1394 | + choices=self._name_parser_map, | ||
1395 | + help=help, | ||
1396 | + metavar=metavar) | ||
1397 | + | ||
1398 | + def add_parser(self, name, **kwargs): | ||
1399 | + # set prog from the existing prefix | ||
1400 | + if kwargs.get('prog') is None: | ||
1401 | + kwargs['prog'] = '%s %s' % (self._prog_prefix, name) | ||
1402 | + | ||
1403 | + aliases = kwargs.pop('aliases', ()) | ||
1404 | + | ||
1405 | + # create a pseudo-action to hold the choice help | ||
1406 | + if 'help' in kwargs: | ||
1407 | + help = kwargs.pop('help') | ||
1408 | + choice_action = self._ChoicesPseudoAction(name, aliases, help) | ||
1409 | + self._choices_actions.append(choice_action) | ||
1410 | + | ||
1411 | + # create the parser and add it to the map | ||
1412 | + parser = self._parser_class(**kwargs) | ||
1413 | + self._name_parser_map[name] = parser | ||
1414 | + | ||
1415 | + # make parser available under aliases also | ||
1416 | + for alias in aliases: | ||
1417 | + self._name_parser_map[alias] = parser | ||
1418 | + | ||
1419 | + return parser | ||
1420 | + | ||
1421 | + def _get_subactions(self): | ||
1422 | + return self._choices_actions | ||
1423 | + | ||
1424 | + def __call__(self, parser, namespace, values, option_string=None): | ||
1425 | + parser_name = values[0] | ||
1426 | + arg_strings = values[1:] | ||
1427 | + | ||
1428 | + # set the parser name if requested | ||
1429 | + if self.dest is not SUPPRESS: | ||
1430 | + setattr(namespace, self.dest, parser_name) | ||
1431 | + | ||
1432 | + # select the parser | ||
1433 | + try: | ||
1434 | + parser = self._name_parser_map[parser_name] | ||
1435 | + except KeyError: | ||
1436 | + tup = parser_name, ', '.join(self._name_parser_map) | ||
1437 | + msg = _('unknown parser %r (choices: %s)' % tup) | ||
1438 | + raise ArgumentError(self, msg) | ||
1439 | + | ||
1440 | + # parse all the remaining options into the namespace | ||
1441 | + # store any unrecognized options on the object, so that the top | ||
1442 | + # level parser can decide what to do with them | ||
1443 | + namespace, arg_strings = parser.parse_known_args(arg_strings, namespace) | ||
1444 | + if arg_strings: | ||
1445 | + vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, []) | ||
1446 | + getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings) | ||
1447 | + | ||
1448 | + | ||
1449 | +# ============== | ||
1450 | +# Type classes | ||
1451 | +# ============== | ||
1452 | + | ||
1453 | +class FileType(object): | ||
1454 | + """Factory for creating file object types | ||
1455 | + | ||
1456 | + Instances of FileType are typically passed as type= arguments to the | ||
1457 | + ArgumentParser add_argument() method. | ||
1458 | + | ||
1459 | + Keyword Arguments: | ||
1460 | + - mode -- A string indicating how the file is to be opened. Accepts the | ||
1461 | + same values as the builtin open() function. | ||
1462 | + - bufsize -- The file's desired buffer size. Accepts the same values as | ||
1463 | + the builtin open() function. | ||
1464 | + """ | ||
1465 | + | ||
1466 | + def __init__(self, mode='r', bufsize=None): | ||
1467 | + self._mode = mode | ||
1468 | + self._bufsize = bufsize | ||
1469 | + | ||
1470 | + def __call__(self, string): | ||
1471 | + # the special argument "-" means sys.std{in,out} | ||
1472 | + if string == '-': | ||
1473 | + if 'r' in self._mode: | ||
1474 | + return _sys.stdin | ||
1475 | + elif 'w' in self._mode: | ||
1476 | + return _sys.stdout | ||
1477 | + else: | ||
1478 | + msg = _('argument "-" with mode %r' % self._mode) | ||
1479 | + raise ValueError(msg) | ||
1480 | + | ||
1481 | + try: | ||
1482 | + # all other arguments are used as file names | ||
1483 | + if self._bufsize: | ||
1484 | + return open(string, self._mode, self._bufsize) | ||
1485 | + else: | ||
1486 | + return open(string, self._mode) | ||
1487 | + except IOError: | ||
1488 | + err = _sys.exc_info()[1] | ||
1489 | + message = _("can't open '%s': %s") | ||
1490 | + raise ArgumentTypeError(message % (string, err)) | ||
1491 | + | ||
1492 | + def __repr__(self): | ||
1493 | + args = [self._mode, self._bufsize] | ||
1494 | + args_str = ', '.join([repr(arg) for arg in args if arg is not None]) | ||
1495 | + return '%s(%s)' % (type(self).__name__, args_str) | ||
1496 | + | ||
1497 | +# =========================== | ||
1498 | +# Optional and Positional Parsing | ||
1499 | +# =========================== | ||
1500 | + | ||
1501 | +class Namespace(_AttributeHolder): | ||
1502 | + """Simple object for storing attributes. | ||
1503 | + | ||
1504 | + Implements equality by attribute names and values, and provides a simple | ||
1505 | + string representation. | ||
1506 | + """ | ||
1507 | + | ||
1508 | + def __init__(self, **kwargs): | ||
1509 | + for name in kwargs: | ||
1510 | + setattr(self, name, kwargs[name]) | ||
1511 | + | ||
1512 | + __hash__ = None | ||
1513 | + | ||
1514 | + def __eq__(self, other): | ||
1515 | + return vars(self) == vars(other) | ||
1516 | + | ||
1517 | + def __ne__(self, other): | ||
1518 | + return not (self == other) | ||
1519 | + | ||
1520 | + def __contains__(self, key): | ||
1521 | + return key in self.__dict__ | ||
1522 | + | ||
1523 | + | ||
1524 | +class _ActionsContainer(object): | ||
1525 | + | ||
1526 | + def __init__(self, | ||
1527 | + description, | ||
1528 | + prefix_chars, | ||
1529 | + argument_default, | ||
1530 | + conflict_handler): | ||
1531 | + super(_ActionsContainer, self).__init__() | ||
1532 | + | ||
1533 | + self.description = description | ||
1534 | + self.argument_default = argument_default | ||
1535 | + self.prefix_chars = prefix_chars | ||
1536 | + self.conflict_handler = conflict_handler | ||
1537 | + | ||
1538 | + # set up registries | ||
1539 | + self._registries = {} | ||
1540 | + | ||
1541 | + # register actions | ||
1542 | + self.register('action', None, _StoreAction) | ||
1543 | + self.register('action', 'store', _StoreAction) | ||
1544 | + self.register('action', 'store_const', _StoreConstAction) | ||
1545 | + self.register('action', 'store_true', _StoreTrueAction) | ||
1546 | + self.register('action', 'store_false', _StoreFalseAction) | ||
1547 | + self.register('action', 'append', _AppendAction) | ||
1548 | + self.register('action', 'append_const', _AppendConstAction) | ||
1549 | + self.register('action', 'count', _CountAction) | ||
1550 | + self.register('action', 'help', _HelpAction) | ||
1551 | + self.register('action', 'version', _VersionAction) | ||
1552 | + self.register('action', 'parsers', _SubParsersAction) | ||
1553 | + | ||
1554 | + # raise an exception if the conflict handler is invalid | ||
1555 | + self._get_handler() | ||
1556 | + | ||
1557 | + # action storage | ||
1558 | + self._actions = [] | ||
1559 | + self._option_string_actions = {} | ||
1560 | + | ||
1561 | + # groups | ||
1562 | + self._action_groups = [] | ||
1563 | + self._mutually_exclusive_groups = [] | ||
1564 | + | ||
1565 | + # defaults storage | ||
1566 | + self._defaults = {} | ||
1567 | + | ||
1568 | + # determines whether an "option" looks like a negative number | ||
1569 | + self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$') | ||
1570 | + | ||
1571 | + # whether or not there are any optionals that look like negative | ||
1572 | + # numbers -- uses a list so it can be shared and edited | ||
1573 | + self._has_negative_number_optionals = [] | ||
1574 | + | ||
1575 | + # ==================== | ||
1576 | + # Registration methods | ||
1577 | + # ==================== | ||
1578 | + def register(self, registry_name, value, object): | ||
1579 | + registry = self._registries.setdefault(registry_name, {}) | ||
1580 | + registry[value] = object | ||
1581 | + | ||
1582 | + def _registry_get(self, registry_name, value, default=None): | ||
1583 | + return self._registries[registry_name].get(value, default) | ||
1584 | + | ||
1585 | + # ================================== | ||
1586 | + # Namespace default accessor methods | ||
1587 | + # ================================== | ||
1588 | + def set_defaults(self, **kwargs): | ||
1589 | + self._defaults.update(kwargs) | ||
1590 | + | ||
1591 | + # if these defaults match any existing arguments, replace | ||
1592 | + # the previous default on the object with the new one | ||
1593 | + for action in self._actions: | ||
1594 | + if action.dest in kwargs: | ||
1595 | + action.default = kwargs[action.dest] | ||
1596 | + | ||
1597 | + def get_default(self, dest): | ||
1598 | + for action in self._actions: | ||
1599 | + if action.dest == dest and action.default is not None: | ||
1600 | + return action.default | ||
1601 | + return self._defaults.get(dest, None) | ||
1602 | + | ||
1603 | + | ||
1604 | + # ======================= | ||
1605 | + # Adding argument actions | ||
1606 | + # ======================= | ||
1607 | + def add_argument(self, *args, **kwargs): | ||
1608 | + """ | ||
1609 | + add_argument(dest, ..., name=value, ...) | ||
1610 | + add_argument(option_string, option_string, ..., name=value, ...) | ||
1611 | + """ | ||
1612 | + | ||
1613 | + # if no positional args are supplied or only one is supplied and | ||
1614 | + # it doesn't look like an option string, parse a positional | ||
1615 | + # argument | ||
1616 | + chars = self.prefix_chars | ||
1617 | + if not args or len(args) == 1 and args[0][0] not in chars: | ||
1618 | + if args and 'dest' in kwargs: | ||
1619 | + raise ValueError('dest supplied twice for positional argument') | ||
1620 | + kwargs = self._get_positional_kwargs(*args, **kwargs) | ||
1621 | + | ||
1622 | + # otherwise, we're adding an optional argument | ||
1623 | + else: | ||
1624 | + kwargs = self._get_optional_kwargs(*args, **kwargs) | ||
1625 | + | ||
1626 | + # if no default was supplied, use the parser-level default | ||
1627 | + if 'default' not in kwargs: | ||
1628 | + dest = kwargs['dest'] | ||
1629 | + if dest in self._defaults: | ||
1630 | + kwargs['default'] = self._defaults[dest] | ||
1631 | + elif self.argument_default is not None: | ||
1632 | + kwargs['default'] = self.argument_default | ||
1633 | + | ||
1634 | + # create the action object, and add it to the parser | ||
1635 | + action_class = self._pop_action_class(kwargs) | ||
1636 | + if not _callable(action_class): | ||
1637 | + raise ValueError('unknown action "%s"' % action_class) | ||
1638 | + action = action_class(**kwargs) | ||
1639 | + | ||
1640 | + # raise an error if the action type is not callable | ||
1641 | + type_func = self._registry_get('type', action.type, action.type) | ||
1642 | + if not _callable(type_func): | ||
1643 | + raise ValueError('%r is not callable' % type_func) | ||
1644 | + | ||
1645 | + return self._add_action(action) | ||
1646 | + | ||
1647 | + def add_argument_group(self, *args, **kwargs): | ||
1648 | + group = _ArgumentGroup(self, *args, **kwargs) | ||
1649 | + self._action_groups.append(group) | ||
1650 | + return group | ||
1651 | + | ||
1652 | + def add_mutually_exclusive_group(self, **kwargs): | ||
1653 | + group = _MutuallyExclusiveGroup(self, **kwargs) | ||
1654 | + self._mutually_exclusive_groups.append(group) | ||
1655 | + return group | ||
1656 | + | ||
1657 | + def _add_action(self, action): | ||
1658 | + # resolve any conflicts | ||
1659 | + self._check_conflict(action) | ||
1660 | + | ||
1661 | + # add to actions list | ||
1662 | + self._actions.append(action) | ||
1663 | + action.container = self | ||
1664 | + | ||
1665 | + # index the action by any option strings it has | ||
1666 | + for option_string in action.option_strings: | ||
1667 | + self._option_string_actions[option_string] = action | ||
1668 | + | ||
1669 | + # set the flag if any option strings look like negative numbers | ||
1670 | + for option_string in action.option_strings: | ||
1671 | + if self._negative_number_matcher.match(option_string): | ||
1672 | + if not self._has_negative_number_optionals: | ||
1673 | + self._has_negative_number_optionals.append(True) | ||
1674 | + | ||
1675 | + # return the created action | ||
1676 | + return action | ||
1677 | + | ||
1678 | + def _remove_action(self, action): | ||
1679 | + self._actions.remove(action) | ||
1680 | + | ||
1681 | + def _add_container_actions(self, container): | ||
1682 | + # collect groups by titles | ||
1683 | + title_group_map = {} | ||
1684 | + for group in self._action_groups: | ||
1685 | + if group.title in title_group_map: | ||
1686 | + msg = _('cannot merge actions - two groups are named %r') | ||
1687 | + raise ValueError(msg % (group.title)) | ||
1688 | + title_group_map[group.title] = group | ||
1689 | + | ||
1690 | + # map each action to its group | ||
1691 | + group_map = {} | ||
1692 | + for group in container._action_groups: | ||
1693 | + | ||
1694 | + # if a group with the title exists, use that, otherwise | ||
1695 | + # create a new group matching the container's group | ||
1696 | + if group.title not in title_group_map: | ||
1697 | + title_group_map[group.title] = self.add_argument_group( | ||
1698 | + title=group.title, | ||
1699 | + description=group.description, | ||
1700 | + conflict_handler=group.conflict_handler) | ||
1701 | + | ||
1702 | + # map the actions to their new group | ||
1703 | + for action in group._group_actions: | ||
1704 | + group_map[action] = title_group_map[group.title] | ||
1705 | + | ||
1706 | + # add container's mutually exclusive groups | ||
1707 | + # NOTE: if add_mutually_exclusive_group ever gains title= and | ||
1708 | + # description= then this code will need to be expanded as above | ||
1709 | + for group in container._mutually_exclusive_groups: | ||
1710 | + mutex_group = self.add_mutually_exclusive_group( | ||
1711 | + required=group.required) | ||
1712 | + | ||
1713 | + # map the actions to their new mutex group | ||
1714 | + for action in group._group_actions: | ||
1715 | + group_map[action] = mutex_group | ||
1716 | + | ||
1717 | + # add all actions to this container or their group | ||
1718 | + for action in container._actions: | ||
1719 | + group_map.get(action, self)._add_action(action) | ||
1720 | + | ||
1721 | + def _get_positional_kwargs(self, dest, **kwargs): | ||
1722 | + # make sure required is not specified | ||
1723 | + if 'required' in kwargs: | ||
1724 | + msg = _("'required' is an invalid argument for positionals") | ||
1725 | + raise TypeError(msg) | ||
1726 | + | ||
1727 | + # mark positional arguments as required if at least one is | ||
1728 | + # always required | ||
1729 | + if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]: | ||
1730 | + kwargs['required'] = True | ||
1731 | + if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs: | ||
1732 | + kwargs['required'] = True | ||
1733 | + | ||
1734 | + # return the keyword arguments with no option strings | ||
1735 | + return dict(kwargs, dest=dest, option_strings=[]) | ||
1736 | + | ||
1737 | + def _get_optional_kwargs(self, *args, **kwargs): | ||
1738 | + # determine short and long option strings | ||
1739 | + option_strings = [] | ||
1740 | + long_option_strings = [] | ||
1741 | + for option_string in args: | ||
1742 | + # error on strings that don't start with an appropriate prefix | ||
1743 | + if not option_string[0] in self.prefix_chars: | ||
1744 | + msg = _('invalid option string %r: ' | ||
1745 | + 'must start with a character %r') | ||
1746 | + tup = option_string, self.prefix_chars | ||
1747 | + raise ValueError(msg % tup) | ||
1748 | + | ||
1749 | + # strings starting with two prefix characters are long options | ||
1750 | + option_strings.append(option_string) | ||
1751 | + if option_string[0] in self.prefix_chars: | ||
1752 | + if len(option_string) > 1: | ||
1753 | + if option_string[1] in self.prefix_chars: | ||
1754 | + long_option_strings.append(option_string) | ||
1755 | + | ||
1756 | + # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x' | ||
1757 | + dest = kwargs.pop('dest', None) | ||
1758 | + if dest is None: | ||
1759 | + if long_option_strings: | ||
1760 | + dest_option_string = long_option_strings[0] | ||
1761 | + else: | ||
1762 | + dest_option_string = option_strings[0] | ||
1763 | + dest = dest_option_string.lstrip(self.prefix_chars) | ||
1764 | + if not dest: | ||
1765 | + msg = _('dest= is required for options like %r') | ||
1766 | + raise ValueError(msg % option_string) | ||
1767 | + dest = dest.replace('-', '_') | ||
1768 | + | ||
1769 | + # return the updated keyword arguments | ||
1770 | + return dict(kwargs, dest=dest, option_strings=option_strings) | ||
1771 | + | ||
1772 | + def _pop_action_class(self, kwargs, default=None): | ||
1773 | + action = kwargs.pop('action', default) | ||
1774 | + return self._registry_get('action', action, action) | ||
1775 | + | ||
1776 | + def _get_handler(self): | ||
1777 | + # determine function from conflict handler string | ||
1778 | + handler_func_name = '_handle_conflict_%s' % self.conflict_handler | ||
1779 | + try: | ||
1780 | + return getattr(self, handler_func_name) | ||
1781 | + except AttributeError: | ||
1782 | + msg = _('invalid conflict_resolution value: %r') | ||
1783 | + raise ValueError(msg % self.conflict_handler) | ||
1784 | + | ||
1785 | + def _check_conflict(self, action): | ||
1786 | + | ||
1787 | + # find all options that conflict with this option | ||
1788 | + confl_optionals = [] | ||
1789 | + for option_string in action.option_strings: | ||
1790 | + if option_string in self._option_string_actions: | ||
1791 | + confl_optional = self._option_string_actions[option_string] | ||
1792 | + confl_optionals.append((option_string, confl_optional)) | ||
1793 | + | ||
1794 | + # resolve any conflicts | ||
1795 | + if confl_optionals: | ||
1796 | + conflict_handler = self._get_handler() | ||
1797 | + conflict_handler(action, confl_optionals) | ||
1798 | + | ||
1799 | + def _handle_conflict_error(self, action, conflicting_actions): | ||
1800 | + message = _('conflicting option string(s): %s') | ||
1801 | + conflict_string = ', '.join([option_string | ||
1802 | + for option_string, action | ||
1803 | + in conflicting_actions]) | ||
1804 | + raise ArgumentError(action, message % conflict_string) | ||
1805 | + | ||
1806 | + def _handle_conflict_resolve(self, action, conflicting_actions): | ||
1807 | + | ||
1808 | + # remove all conflicting options | ||
1809 | + for option_string, action in conflicting_actions: | ||
1810 | + | ||
1811 | + # remove the conflicting option | ||
1812 | + action.option_strings.remove(option_string) | ||
1813 | + self._option_string_actions.pop(option_string, None) | ||
1814 | + | ||
1815 | + # if the option now has no option string, remove it from the | ||
1816 | + # container holding it | ||
1817 | + if not action.option_strings: | ||
1818 | + action.container._remove_action(action) | ||
1819 | + | ||
1820 | + | ||
1821 | +class _ArgumentGroup(_ActionsContainer): | ||
1822 | + | ||
1823 | + def __init__(self, container, title=None, description=None, **kwargs): | ||
1824 | + # add any missing keyword arguments by checking the container | ||
1825 | + update = kwargs.setdefault | ||
1826 | + update('conflict_handler', container.conflict_handler) | ||
1827 | + update('prefix_chars', container.prefix_chars) | ||
1828 | + update('argument_default', container.argument_default) | ||
1829 | + super_init = super(_ArgumentGroup, self).__init__ | ||
1830 | + super_init(description=description, **kwargs) | ||
1831 | + | ||
1832 | + # group attributes | ||
1833 | + self.title = title | ||
1834 | + self._group_actions = [] | ||
1835 | + | ||
1836 | + # share most attributes with the container | ||
1837 | + self._registries = container._registries | ||
1838 | + self._actions = container._actions | ||
1839 | + self._option_string_actions = container._option_string_actions | ||
1840 | + self._defaults = container._defaults | ||
1841 | + self._has_negative_number_optionals = \ | ||
1842 | + container._has_negative_number_optionals | ||
1843 | + | ||
1844 | + def _add_action(self, action): | ||
1845 | + action = super(_ArgumentGroup, self)._add_action(action) | ||
1846 | + self._group_actions.append(action) | ||
1847 | + return action | ||
1848 | + | ||
1849 | + def _remove_action(self, action): | ||
1850 | + super(_ArgumentGroup, self)._remove_action(action) | ||
1851 | + self._group_actions.remove(action) | ||
1852 | + | ||
1853 | + | ||
1854 | +class _MutuallyExclusiveGroup(_ArgumentGroup): | ||
1855 | + | ||
1856 | + def __init__(self, container, required=False): | ||
1857 | + super(_MutuallyExclusiveGroup, self).__init__(container) | ||
1858 | + self.required = required | ||
1859 | + self._container = container | ||
1860 | + | ||
1861 | + def _add_action(self, action): | ||
1862 | + if action.required: | ||
1863 | + msg = _('mutually exclusive arguments must be optional') | ||
1864 | + raise ValueError(msg) | ||
1865 | + action = self._container._add_action(action) | ||
1866 | + self._group_actions.append(action) | ||
1867 | + return action | ||
1868 | + | ||
1869 | + def _remove_action(self, action): | ||
1870 | + self._container._remove_action(action) | ||
1871 | + self._group_actions.remove(action) | ||
1872 | + | ||
1873 | + | ||
1874 | +class ArgumentParser(_AttributeHolder, _ActionsContainer): | ||
1875 | + """Object for parsing command line strings into Python objects. | ||
1876 | + | ||
1877 | + Keyword Arguments: | ||
1878 | + - prog -- The name of the program (default: sys.argv[0]) | ||
1879 | + - usage -- A usage message (default: auto-generated from arguments) | ||
1880 | + - description -- A description of what the program does | ||
1881 | + - epilog -- Text following the argument descriptions | ||
1882 | + - parents -- Parsers whose arguments should be copied into this one | ||
1883 | + - formatter_class -- HelpFormatter class for printing help messages | ||
1884 | + - prefix_chars -- Characters that prefix optional arguments | ||
1885 | + - fromfile_prefix_chars -- Characters that prefix files containing | ||
1886 | + additional arguments | ||
1887 | + - argument_default -- The default value for all arguments | ||
1888 | + - conflict_handler -- String indicating how to handle conflicts | ||
1889 | + - add_help -- Add a -h/-help option | ||
1890 | + """ | ||
1891 | + | ||
1892 | + def __init__(self, | ||
1893 | + prog=None, | ||
1894 | + usage=None, | ||
1895 | + description=None, | ||
1896 | + epilog=None, | ||
1897 | + version=None, | ||
1898 | + parents=[], | ||
1899 | + formatter_class=HelpFormatter, | ||
1900 | + prefix_chars='-', | ||
1901 | + fromfile_prefix_chars=None, | ||
1902 | + argument_default=None, | ||
1903 | + conflict_handler='error', | ||
1904 | + add_help=True): | ||
1905 | + | ||
1906 | + if version is not None: | ||
1907 | + import warnings | ||
1908 | + warnings.warn( | ||
1909 | + """The "version" argument to ArgumentParser is deprecated. """ | ||
1910 | + """Please use """ | ||
1911 | + """"add_argument(..., action='version', version="N", ...)" """ | ||
1912 | + """instead""", DeprecationWarning) | ||
1913 | + | ||
1914 | + superinit = super(ArgumentParser, self).__init__ | ||
1915 | + superinit(description=description, | ||
1916 | + prefix_chars=prefix_chars, | ||
1917 | + argument_default=argument_default, | ||
1918 | + conflict_handler=conflict_handler) | ||
1919 | + | ||
1920 | + # default setting for prog | ||
1921 | + if prog is None: | ||
1922 | + prog = _os.path.basename(_sys.argv[0]) | ||
1923 | + | ||
1924 | + self.prog = prog | ||
1925 | + self.usage = usage | ||
1926 | + self.epilog = epilog | ||
1927 | + self.version = version | ||
1928 | + self.formatter_class = formatter_class | ||
1929 | + self.fromfile_prefix_chars = fromfile_prefix_chars | ||
1930 | + self.add_help = add_help | ||
1931 | + | ||
1932 | + add_group = self.add_argument_group | ||
1933 | + self._positionals = add_group(_('positional arguments')) | ||
1934 | + self._optionals = add_group(_('optional arguments')) | ||
1935 | + self._subparsers = None | ||
1936 | + | ||
1937 | + # register types | ||
1938 | + def identity(string): | ||
1939 | + return string | ||
1940 | + self.register('type', None, identity) | ||
1941 | + | ||
1942 | + # add help and version arguments if necessary | ||
1943 | + # (using explicit default to override global argument_default) | ||
1944 | + if '-' in prefix_chars: | ||
1945 | + default_prefix = '-' | ||
1946 | + else: | ||
1947 | + default_prefix = prefix_chars[0] | ||
1948 | + if self.add_help: | ||
1949 | + self.add_argument( | ||
1950 | + default_prefix+'h', default_prefix*2+'help', | ||
1951 | + action='help', default=SUPPRESS, | ||
1952 | + help=_('show this help message and exit')) | ||
1953 | + if self.version: | ||
1954 | + self.add_argument( | ||
1955 | + default_prefix+'v', default_prefix*2+'version', | ||
1956 | + action='version', default=SUPPRESS, | ||
1957 | + version=self.version, | ||
1958 | + help=_("show program's version number and exit")) | ||
1959 | + | ||
1960 | + # add parent arguments and defaults | ||
1961 | + for parent in parents: | ||
1962 | + self._add_container_actions(parent) | ||
1963 | + try: | ||
1964 | + defaults = parent._defaults | ||
1965 | + except AttributeError: | ||
1966 | + pass | ||
1967 | + else: | ||
1968 | + self._defaults.update(defaults) | ||
1969 | + | ||
1970 | + # ======================= | ||
1971 | + # Pretty __repr__ methods | ||
1972 | + # ======================= | ||
1973 | + def _get_kwargs(self): | ||
1974 | + names = [ | ||
1975 | + 'prog', | ||
1976 | + 'usage', | ||
1977 | + 'description', | ||
1978 | + 'version', | ||
1979 | + 'formatter_class', | ||
1980 | + 'conflict_handler', | ||
1981 | + 'add_help', | ||
1982 | + ] | ||
1983 | + return [(name, getattr(self, name)) for name in names] | ||
1984 | + | ||
1985 | + # ================================== | ||
1986 | + # Optional/Positional adding methods | ||
1987 | + # ================================== | ||
1988 | + def add_subparsers(self, **kwargs): | ||
1989 | + if self._subparsers is not None: | ||
1990 | + self.error(_('cannot have multiple subparser arguments')) | ||
1991 | + | ||
1992 | + # add the parser class to the arguments if it's not present | ||
1993 | + kwargs.setdefault('parser_class', type(self)) | ||
1994 | + | ||
1995 | + if 'title' in kwargs or 'description' in kwargs: | ||
1996 | + title = _(kwargs.pop('title', 'subcommands')) | ||
1997 | + description = _(kwargs.pop('description', None)) | ||
1998 | + self._subparsers = self.add_argument_group(title, description) | ||
1999 | + else: | ||
2000 | + self._subparsers = self._positionals | ||
2001 | + | ||
2002 | + # prog defaults to the usage message of this parser, skipping | ||
2003 | + # optional arguments and with no "usage:" prefix | ||
2004 | + if kwargs.get('prog') is None: | ||
2005 | + formatter = self._get_formatter() | ||
2006 | + positionals = self._get_positional_actions() | ||
2007 | + groups = self._mutually_exclusive_groups | ||
2008 | + formatter.add_usage(self.usage, positionals, groups, '') | ||
2009 | + kwargs['prog'] = formatter.format_help().strip() | ||
2010 | + | ||
2011 | + # create the parsers action and add it to the positionals list | ||
2012 | + parsers_class = self._pop_action_class(kwargs, 'parsers') | ||
2013 | + action = parsers_class(option_strings=[], **kwargs) | ||
2014 | + self._subparsers._add_action(action) | ||
2015 | + | ||
2016 | + # return the created parsers action | ||
2017 | + return action | ||
2018 | + | ||
2019 | + def _add_action(self, action): | ||
2020 | + if action.option_strings: | ||
2021 | + self._optionals._add_action(action) | ||
2022 | + else: | ||
2023 | + self._positionals._add_action(action) | ||
2024 | + return action | ||
2025 | + | ||
2026 | + def _get_optional_actions(self): | ||
2027 | + return [action | ||
2028 | + for action in self._actions | ||
2029 | + if action.option_strings] | ||
2030 | + | ||
2031 | + def _get_positional_actions(self): | ||
2032 | + return [action | ||
2033 | + for action in self._actions | ||
2034 | + if not action.option_strings] | ||
2035 | + | ||
2036 | + # ===================================== | ||
2037 | + # Command line argument parsing methods | ||
2038 | + # ===================================== | ||
2039 | + def parse_args(self, args=None, namespace=None): | ||
2040 | + args, argv = self.parse_known_args(args, namespace) | ||
2041 | + if argv: | ||
2042 | + msg = _('unrecognized arguments: %s') | ||
2043 | + self.error(msg % ' '.join(argv)) | ||
2044 | + return args | ||
2045 | + | ||
2046 | + def parse_known_args(self, args=None, namespace=None): | ||
2047 | + # args default to the system args | ||
2048 | + if args is None: | ||
2049 | + args = _sys.argv[1:] | ||
2050 | + | ||
2051 | + # default Namespace built from parser defaults | ||
2052 | + if namespace is None: | ||
2053 | + namespace = Namespace() | ||
2054 | + | ||
2055 | + # add any action defaults that aren't present | ||
2056 | + for action in self._actions: | ||
2057 | + if action.dest is not SUPPRESS: | ||
2058 | + if not hasattr(namespace, action.dest): | ||
2059 | + if action.default is not SUPPRESS: | ||
2060 | + setattr(namespace, action.dest, action.default) | ||
2061 | + | ||
2062 | + # add any parser defaults that aren't present | ||
2063 | + for dest in self._defaults: | ||
2064 | + if not hasattr(namespace, dest): | ||
2065 | + setattr(namespace, dest, self._defaults[dest]) | ||
2066 | + | ||
2067 | + # parse the arguments and exit if there are any errors | ||
2068 | + try: | ||
2069 | + namespace, args = self._parse_known_args(args, namespace) | ||
2070 | + if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR): | ||
2071 | + args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR)) | ||
2072 | + delattr(namespace, _UNRECOGNIZED_ARGS_ATTR) | ||
2073 | + return namespace, args | ||
2074 | + except ArgumentError: | ||
2075 | + err = _sys.exc_info()[1] | ||
2076 | + self.error(str(err)) | ||
2077 | + | ||
2078 | + def _parse_known_args(self, arg_strings, namespace): | ||
2079 | + # replace arg strings that are file references | ||
2080 | + if self.fromfile_prefix_chars is not None: | ||
2081 | + arg_strings = self._read_args_from_files(arg_strings) | ||
2082 | + | ||
2083 | + # map all mutually exclusive arguments to the other arguments | ||
2084 | + # they can't occur with | ||
2085 | + action_conflicts = {} | ||
2086 | + for mutex_group in self._mutually_exclusive_groups: | ||
2087 | + group_actions = mutex_group._group_actions | ||
2088 | + for i, mutex_action in enumerate(mutex_group._group_actions): | ||
2089 | + conflicts = action_conflicts.setdefault(mutex_action, []) | ||
2090 | + conflicts.extend(group_actions[:i]) | ||
2091 | + conflicts.extend(group_actions[i + 1:]) | ||
2092 | + | ||
2093 | + # find all option indices, and determine the arg_string_pattern | ||
2094 | + # which has an 'O' if there is an option at an index, | ||
2095 | + # an 'A' if there is an argument, or a '-' if there is a '--' | ||
2096 | + option_string_indices = {} | ||
2097 | + arg_string_pattern_parts = [] | ||
2098 | + arg_strings_iter = iter(arg_strings) | ||
2099 | + for i, arg_string in enumerate(arg_strings_iter): | ||
2100 | + | ||
2101 | + # all args after -- are non-options | ||
2102 | + if arg_string == '--': | ||
2103 | + arg_string_pattern_parts.append('-') | ||
2104 | + for arg_string in arg_strings_iter: | ||
2105 | + arg_string_pattern_parts.append('A') | ||
2106 | + | ||
2107 | + # otherwise, add the arg to the arg strings | ||
2108 | + # and note the index if it was an option | ||
2109 | + else: | ||
2110 | + option_tuple = self._parse_optional(arg_string) | ||
2111 | + if option_tuple is None: | ||
2112 | + pattern = 'A' | ||
2113 | + else: | ||
2114 | + option_string_indices[i] = option_tuple | ||
2115 | + pattern = 'O' | ||
2116 | + arg_string_pattern_parts.append(pattern) | ||
2117 | + | ||
2118 | + # join the pieces together to form the pattern | ||
2119 | + arg_strings_pattern = ''.join(arg_string_pattern_parts) | ||
2120 | + | ||
2121 | + # converts arg strings to the appropriate and then takes the action | ||
2122 | + seen_actions = set() | ||
2123 | + seen_non_default_actions = set() | ||
2124 | + | ||
2125 | + def take_action(action, argument_strings, option_string=None): | ||
2126 | + seen_actions.add(action) | ||
2127 | + argument_values = self._get_values(action, argument_strings) | ||
2128 | + | ||
2129 | + # error if this argument is not allowed with other previously | ||
2130 | + # seen arguments, assuming that actions that use the default | ||
2131 | + # value don't really count as "present" | ||
2132 | + if argument_values is not action.default: | ||
2133 | + seen_non_default_actions.add(action) | ||
2134 | + for conflict_action in action_conflicts.get(action, []): | ||
2135 | + if conflict_action in seen_non_default_actions: | ||
2136 | + msg = _('not allowed with argument %s') | ||
2137 | + action_name = _get_action_name(conflict_action) | ||
2138 | + raise ArgumentError(action, msg % action_name) | ||
2139 | + | ||
2140 | + # take the action if we didn't receive a SUPPRESS value | ||
2141 | + # (e.g. from a default) | ||
2142 | + if argument_values is not SUPPRESS: | ||
2143 | + action(self, namespace, argument_values, option_string) | ||
2144 | + | ||
2145 | + # function to convert arg_strings into an optional action | ||
2146 | + def consume_optional(start_index): | ||
2147 | + | ||
2148 | + # get the optional identified at this index | ||
2149 | + option_tuple = option_string_indices[start_index] | ||
2150 | + action, option_string, explicit_arg = option_tuple | ||
2151 | + | ||
2152 | + # identify additional optionals in the same arg string | ||
2153 | + # (e.g. -xyz is the same as -x -y -z if no args are required) | ||
2154 | + match_argument = self._match_argument | ||
2155 | + action_tuples = [] | ||
2156 | + while True: | ||
2157 | + | ||
2158 | + # if we found no optional action, skip it | ||
2159 | + if action is None: | ||
2160 | + extras.append(arg_strings[start_index]) | ||
2161 | + return start_index + 1 | ||
2162 | + | ||
2163 | + # if there is an explicit argument, try to match the | ||
2164 | + # optional's string arguments to only this | ||
2165 | + if explicit_arg is not None: | ||
2166 | + arg_count = match_argument(action, 'A') | ||
2167 | + | ||
2168 | + # if the action is a single-dash option and takes no | ||
2169 | + # arguments, try to parse more single-dash options out | ||
2170 | + # of the tail of the option string | ||
2171 | + chars = self.prefix_chars | ||
2172 | + if arg_count == 0 and option_string[1] not in chars: | ||
2173 | + action_tuples.append((action, [], option_string)) | ||
2174 | + char = option_string[0] | ||
2175 | + option_string = char + explicit_arg[0] | ||
2176 | + new_explicit_arg = explicit_arg[1:] or None | ||
2177 | + optionals_map = self._option_string_actions | ||
2178 | + if option_string in optionals_map: | ||
2179 | + action = optionals_map[option_string] | ||
2180 | + explicit_arg = new_explicit_arg | ||
2181 | + else: | ||
2182 | + msg = _('ignored explicit argument %r') | ||
2183 | + raise ArgumentError(action, msg % explicit_arg) | ||
2184 | + | ||
2185 | + # if the action expect exactly one argument, we've | ||
2186 | + # successfully matched the option; exit the loop | ||
2187 | + elif arg_count == 1: | ||
2188 | + stop = start_index + 1 | ||
2189 | + args = [explicit_arg] | ||
2190 | + action_tuples.append((action, args, option_string)) | ||
2191 | + break | ||
2192 | + | ||
2193 | + # error if a double-dash option did not use the | ||
2194 | + # explicit argument | ||
2195 | + else: | ||
2196 | + msg = _('ignored explicit argument %r') | ||
2197 | + raise ArgumentError(action, msg % explicit_arg) | ||
2198 | + | ||
2199 | + # if there is no explicit argument, try to match the | ||
2200 | + # optional's string arguments with the following strings | ||
2201 | + # if successful, exit the loop | ||
2202 | + else: | ||
2203 | + start = start_index + 1 | ||
2204 | + selected_patterns = arg_strings_pattern[start:] | ||
2205 | + arg_count = match_argument(action, selected_patterns) | ||
2206 | + stop = start + arg_count | ||
2207 | + args = arg_strings[start:stop] | ||
2208 | + action_tuples.append((action, args, option_string)) | ||
2209 | + break | ||
2210 | + | ||
2211 | + # add the Optional to the list and return the index at which | ||
2212 | + # the Optional's string args stopped | ||
2213 | + assert action_tuples | ||
2214 | + for action, args, option_string in action_tuples: | ||
2215 | + take_action(action, args, option_string) | ||
2216 | + return stop | ||
2217 | + | ||
2218 | + # the list of Positionals left to be parsed; this is modified | ||
2219 | + # by consume_positionals() | ||
2220 | + positionals = self._get_positional_actions() | ||
2221 | + | ||
2222 | + # function to convert arg_strings into positional actions | ||
2223 | + def consume_positionals(start_index): | ||
2224 | + # match as many Positionals as possible | ||
2225 | + match_partial = self._match_arguments_partial | ||
2226 | + selected_pattern = arg_strings_pattern[start_index:] | ||
2227 | + arg_counts = match_partial(positionals, selected_pattern) | ||
2228 | + | ||
2229 | + # slice off the appropriate arg strings for each Positional | ||
2230 | + # and add the Positional and its args to the list | ||
2231 | + for action, arg_count in zip(positionals, arg_counts): | ||
2232 | + args = arg_strings[start_index: start_index + arg_count] | ||
2233 | + start_index += arg_count | ||
2234 | + take_action(action, args) | ||
2235 | + | ||
2236 | + # slice off the Positionals that we just parsed and return the | ||
2237 | + # index at which the Positionals' string args stopped | ||
2238 | + positionals[:] = positionals[len(arg_counts):] | ||
2239 | + return start_index | ||
2240 | + | ||
2241 | + # consume Positionals and Optionals alternately, until we have | ||
2242 | + # passed the last option string | ||
2243 | + extras = [] | ||
2244 | + start_index = 0 | ||
2245 | + if option_string_indices: | ||
2246 | + max_option_string_index = max(option_string_indices) | ||
2247 | + else: | ||
2248 | + max_option_string_index = -1 | ||
2249 | + while start_index <= max_option_string_index: | ||
2250 | + | ||
2251 | + # consume any Positionals preceding the next option | ||
2252 | + next_option_string_index = min([ | ||
2253 | + index | ||
2254 | + for index in option_string_indices | ||
2255 | + if index >= start_index]) | ||
2256 | + if start_index != next_option_string_index: | ||
2257 | + positionals_end_index = consume_positionals(start_index) | ||
2258 | + | ||
2259 | + # only try to parse the next optional if we didn't consume | ||
2260 | + # the option string during the positionals parsing | ||
2261 | + if positionals_end_index > start_index: | ||
2262 | + start_index = positionals_end_index | ||
2263 | + continue | ||
2264 | + else: | ||
2265 | + start_index = positionals_end_index | ||
2266 | + | ||
2267 | + # if we consumed all the positionals we could and we're not | ||
2268 | + # at the index of an option string, there were extra arguments | ||
2269 | + if start_index not in option_string_indices: | ||
2270 | + strings = arg_strings[start_index:next_option_string_index] | ||
2271 | + extras.extend(strings) | ||
2272 | + start_index = next_option_string_index | ||
2273 | + | ||
2274 | + # consume the next optional and any arguments for it | ||
2275 | + start_index = consume_optional(start_index) | ||
2276 | + | ||
2277 | + # consume any positionals following the last Optional | ||
2278 | + stop_index = consume_positionals(start_index) | ||
2279 | + | ||
2280 | + # if we didn't consume all the argument strings, there were extras | ||
2281 | + extras.extend(arg_strings[stop_index:]) | ||
2282 | + | ||
2283 | + # if we didn't use all the Positional objects, there were too few | ||
2284 | + # arg strings supplied. | ||
2285 | + if positionals: | ||
2286 | + self.error(_('too few arguments')) | ||
2287 | + | ||
2288 | + # make sure all required actions were present, and convert defaults. | ||
2289 | + for action in self._actions: | ||
2290 | + if action not in seen_actions: | ||
2291 | + if action.required: | ||
2292 | + name = _get_action_name(action) | ||
2293 | + self.error(_('argument %s is required') % name) | ||
2294 | + else: | ||
2295 | + # Convert action default now instead of doing it before | ||
2296 | + # parsing arguments to avoid calling convert functions | ||
2297 | + # twice (which may fail) if the argument was given, but | ||
2298 | + # only if it was defined already in the namespace | ||
2299 | + if (action.default is not None and | ||
2300 | + isinstance(action.default, basestring) and | ||
2301 | + hasattr(namespace, action.dest) and | ||
2302 | + action.default is getattr(namespace, action.dest)): | ||
2303 | + setattr(namespace, action.dest, | ||
2304 | + self._get_value(action, action.default)) | ||
2305 | + | ||
2306 | + # make sure all required groups had one option present | ||
2307 | + for group in self._mutually_exclusive_groups: | ||
2308 | + if group.required: | ||
2309 | + for action in group._group_actions: | ||
2310 | + if action in seen_non_default_actions: | ||
2311 | + break | ||
2312 | + | ||
2313 | + # if no actions were used, report the error | ||
2314 | + else: | ||
2315 | + names = [_get_action_name(action) | ||
2316 | + for action in group._group_actions | ||
2317 | + if action.help is not SUPPRESS] | ||
2318 | + msg = _('one of the arguments %s is required') | ||
2319 | + self.error(msg % ' '.join(names)) | ||
2320 | + | ||
2321 | + # return the updated namespace and the extra arguments | ||
2322 | + return namespace, extras | ||
2323 | + | ||
2324 | + def _read_args_from_files(self, arg_strings): | ||
2325 | + # expand arguments referencing files | ||
2326 | + new_arg_strings = [] | ||
2327 | + for arg_string in arg_strings: | ||
2328 | + | ||
2329 | + # for regular arguments, just add them back into the list | ||
2330 | + if arg_string[0] not in self.fromfile_prefix_chars: | ||
2331 | + new_arg_strings.append(arg_string) | ||
2332 | + | ||
2333 | + # replace arguments referencing files with the file content | ||
2334 | + else: | ||
2335 | + try: | ||
2336 | + args_file = open(arg_string[1:]) | ||
2337 | + try: | ||
2338 | + arg_strings = [] | ||
2339 | + for arg_line in args_file.read().splitlines(): | ||
2340 | + for arg in self.convert_arg_line_to_args(arg_line): | ||
2341 | + arg_strings.append(arg) | ||
2342 | + arg_strings = self._read_args_from_files(arg_strings) | ||
2343 | + new_arg_strings.extend(arg_strings) | ||
2344 | + finally: | ||
2345 | + args_file.close() | ||
2346 | + except IOError: | ||
2347 | + err = _sys.exc_info()[1] | ||
2348 | + self.error(str(err)) | ||
2349 | + | ||
2350 | + # return the modified argument list | ||
2351 | + return new_arg_strings | ||
2352 | + | ||
2353 | + def convert_arg_line_to_args(self, arg_line): | ||
2354 | + return [arg_line] | ||
2355 | + | ||
2356 | + def _match_argument(self, action, arg_strings_pattern): | ||
2357 | + # match the pattern for this action to the arg strings | ||
2358 | + nargs_pattern = self._get_nargs_pattern(action) | ||
2359 | + match = _re.match(nargs_pattern, arg_strings_pattern) | ||
2360 | + | ||
2361 | + # raise an exception if we weren't able to find a match | ||
2362 | + if match is None: | ||
2363 | + nargs_errors = { | ||
2364 | + None: _('expected one argument'), | ||
2365 | + OPTIONAL: _('expected at most one argument'), | ||
2366 | + ONE_OR_MORE: _('expected at least one argument'), | ||
2367 | + } | ||
2368 | + default = _('expected %s argument(s)') % action.nargs | ||
2369 | + msg = nargs_errors.get(action.nargs, default) | ||
2370 | + raise ArgumentError(action, msg) | ||
2371 | + | ||
2372 | + # return the number of arguments matched | ||
2373 | + return len(match.group(1)) | ||
2374 | + | ||
2375 | + def _match_arguments_partial(self, actions, arg_strings_pattern): | ||
2376 | + # progressively shorten the actions list by slicing off the | ||
2377 | + # final actions until we find a match | ||
2378 | + result = [] | ||
2379 | + for i in range(len(actions), 0, -1): | ||
2380 | + actions_slice = actions[:i] | ||
2381 | + pattern = ''.join([self._get_nargs_pattern(action) | ||
2382 | + for action in actions_slice]) | ||
2383 | + match = _re.match(pattern, arg_strings_pattern) | ||
2384 | + if match is not None: | ||
2385 | + result.extend([len(string) for string in match.groups()]) | ||
2386 | + break | ||
2387 | + | ||
2388 | + # return the list of arg string counts | ||
2389 | + return result | ||
2390 | + | ||
2391 | + def _parse_optional(self, arg_string): | ||
2392 | + # if it's an empty string, it was meant to be a positional | ||
2393 | + if not arg_string: | ||
2394 | + return None | ||
2395 | + | ||
2396 | + # if it doesn't start with a prefix, it was meant to be positional | ||
2397 | + if not arg_string[0] in self.prefix_chars: | ||
2398 | + return None | ||
2399 | + | ||
2400 | + # if the option string is present in the parser, return the action | ||
2401 | + if arg_string in self._option_string_actions: | ||
2402 | + action = self._option_string_actions[arg_string] | ||
2403 | + return action, arg_string, None | ||
2404 | + | ||
2405 | + # if it's just a single character, it was meant to be positional | ||
2406 | + if len(arg_string) == 1: | ||
2407 | + return None | ||
2408 | + | ||
2409 | + # if the option string before the "=" is present, return the action | ||
2410 | + if '=' in arg_string: | ||
2411 | + option_string, explicit_arg = arg_string.split('=', 1) | ||
2412 | + if option_string in self._option_string_actions: | ||
2413 | + action = self._option_string_actions[option_string] | ||
2414 | + return action, option_string, explicit_arg | ||
2415 | + | ||
2416 | + # search through all possible prefixes of the option string | ||
2417 | + # and all actions in the parser for possible interpretations | ||
2418 | + option_tuples = self._get_option_tuples(arg_string) | ||
2419 | + | ||
2420 | + # if multiple actions match, the option string was ambiguous | ||
2421 | + if len(option_tuples) > 1: | ||
2422 | + options = ', '.join([option_string | ||
2423 | + for action, option_string, explicit_arg in option_tuples]) | ||
2424 | + tup = arg_string, options | ||
2425 | + self.error(_('ambiguous option: %s could match %s') % tup) | ||
2426 | + | ||
2427 | + # if exactly one action matched, this segmentation is good, | ||
2428 | + # so return the parsed action | ||
2429 | + elif len(option_tuples) == 1: | ||
2430 | + option_tuple, = option_tuples | ||
2431 | + return option_tuple | ||
2432 | + | ||
2433 | + # if it was not found as an option, but it looks like a negative | ||
2434 | + # number, it was meant to be positional | ||
2435 | + # unless there are negative-number-like options | ||
2436 | + if self._negative_number_matcher.match(arg_string): | ||
2437 | + if not self._has_negative_number_optionals: | ||
2438 | + return None | ||
2439 | + | ||
2440 | + # if it contains a space, it was meant to be a positional | ||
2441 | + if ' ' in arg_string: | ||
2442 | + return None | ||
2443 | + | ||
2444 | + # it was meant to be an optional but there is no such option | ||
2445 | + # in this parser (though it might be a valid option in a subparser) | ||
2446 | + return None, arg_string, None | ||
2447 | + | ||
2448 | + def _get_option_tuples(self, option_string): | ||
2449 | + result = [] | ||
2450 | + | ||
2451 | + # option strings starting with two prefix characters are only | ||
2452 | + # split at the '=' | ||
2453 | + chars = self.prefix_chars | ||
2454 | + if option_string[0] in chars and option_string[1] in chars: | ||
2455 | + if '=' in option_string: | ||
2456 | + option_prefix, explicit_arg = option_string.split('=', 1) | ||
2457 | + else: | ||
2458 | + option_prefix = option_string | ||
2459 | + explicit_arg = None | ||
2460 | + for option_string in self._option_string_actions: | ||
2461 | + if option_string.startswith(option_prefix): | ||
2462 | + action = self._option_string_actions[option_string] | ||
2463 | + tup = action, option_string, explicit_arg | ||
2464 | + result.append(tup) | ||
2465 | + | ||
2466 | + # single character options can be concatenated with their arguments | ||
2467 | + # but multiple character options always have to have their argument | ||
2468 | + # separate | ||
2469 | + elif option_string[0] in chars and option_string[1] not in chars: | ||
2470 | + option_prefix = option_string | ||
2471 | + explicit_arg = None | ||
2472 | + short_option_prefix = option_string[:2] | ||
2473 | + short_explicit_arg = option_string[2:] | ||
2474 | + | ||
2475 | + for option_string in self._option_string_actions: | ||
2476 | + if option_string == short_option_prefix: | ||
2477 | + action = self._option_string_actions[option_string] | ||
2478 | + tup = action, option_string, short_explicit_arg | ||
2479 | + result.append(tup) | ||
2480 | + elif option_string.startswith(option_prefix): | ||
2481 | + action = self._option_string_actions[option_string] | ||
2482 | + tup = action, option_string, explicit_arg | ||
2483 | + result.append(tup) | ||
2484 | + | ||
2485 | + # shouldn't ever get here | ||
2486 | + else: | ||
2487 | + self.error(_('unexpected option string: %s') % option_string) | ||
2488 | + | ||
2489 | + # return the collected option tuples | ||
2490 | + return result | ||
2491 | + | ||
2492 | + def _get_nargs_pattern(self, action): | ||
2493 | + # in all examples below, we have to allow for '--' args | ||
2494 | + # which are represented as '-' in the pattern | ||
2495 | + nargs = action.nargs | ||
2496 | + | ||
2497 | + # the default (None) is assumed to be a single argument | ||
2498 | + if nargs is None: | ||
2499 | + nargs_pattern = '(-*A-*)' | ||
2500 | + | ||
2501 | + # allow zero or one arguments | ||
2502 | + elif nargs == OPTIONAL: | ||
2503 | + nargs_pattern = '(-*A?-*)' | ||
2504 | + | ||
2505 | + # allow zero or more arguments | ||
2506 | + elif nargs == ZERO_OR_MORE: | ||
2507 | + nargs_pattern = '(-*[A-]*)' | ||
2508 | + | ||
2509 | + # allow one or more arguments | ||
2510 | + elif nargs == ONE_OR_MORE: | ||
2511 | + nargs_pattern = '(-*A[A-]*)' | ||
2512 | + | ||
2513 | + # allow any number of options or arguments | ||
2514 | + elif nargs == REMAINDER: | ||
2515 | + nargs_pattern = '([-AO]*)' | ||
2516 | + | ||
2517 | + # allow one argument followed by any number of options or arguments | ||
2518 | + elif nargs == PARSER: | ||
2519 | + nargs_pattern = '(-*A[-AO]*)' | ||
2520 | + | ||
2521 | + # all others should be integers | ||
2522 | + else: | ||
2523 | + nargs_pattern = '(-*%s-*)' % '-*'.join('A' * nargs) | ||
2524 | + | ||
2525 | + # if this is an optional action, -- is not allowed | ||
2526 | + if action.option_strings: | ||
2527 | + nargs_pattern = nargs_pattern.replace('-*', '') | ||
2528 | + nargs_pattern = nargs_pattern.replace('-', '') | ||
2529 | + | ||
2530 | + # return the pattern | ||
2531 | + return nargs_pattern | ||
2532 | + | ||
2533 | + # ======================== | ||
2534 | + # Value conversion methods | ||
2535 | + # ======================== | ||
2536 | + def _get_values(self, action, arg_strings): | ||
2537 | + # for everything but PARSER args, strip out '--' | ||
2538 | + if action.nargs not in [PARSER, REMAINDER]: | ||
2539 | + arg_strings = [s for s in arg_strings if s != '--'] | ||
2540 | + | ||
2541 | + # optional argument produces a default when not present | ||
2542 | + if not arg_strings and action.nargs == OPTIONAL: | ||
2543 | + if action.option_strings: | ||
2544 | + value = action.const | ||
2545 | + else: | ||
2546 | + value = action.default | ||
2547 | + if isinstance(value, basestring): | ||
2548 | + value = self._get_value(action, value) | ||
2549 | + self._check_value(action, value) | ||
2550 | + | ||
2551 | + # when nargs='*' on a positional, if there were no command-line | ||
2552 | + # args, use the default if it is anything other than None | ||
2553 | + elif (not arg_strings and action.nargs == ZERO_OR_MORE and | ||
2554 | + not action.option_strings): | ||
2555 | + if action.default is not None: | ||
2556 | + value = action.default | ||
2557 | + else: | ||
2558 | + value = arg_strings | ||
2559 | + self._check_value(action, value) | ||
2560 | + | ||
2561 | + # single argument or optional argument produces a single value | ||
2562 | + elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]: | ||
2563 | + arg_string, = arg_strings | ||
2564 | + value = self._get_value(action, arg_string) | ||
2565 | + self._check_value(action, value) | ||
2566 | + | ||
2567 | + # REMAINDER arguments convert all values, checking none | ||
2568 | + elif action.nargs == REMAINDER: | ||
2569 | + value = [self._get_value(action, v) for v in arg_strings] | ||
2570 | + | ||
2571 | + # PARSER arguments convert all values, but check only the first | ||
2572 | + elif action.nargs == PARSER: | ||
2573 | + value = [self._get_value(action, v) for v in arg_strings] | ||
2574 | + self._check_value(action, value[0]) | ||
2575 | + | ||
2576 | + # all other types of nargs produce a list | ||
2577 | + else: | ||
2578 | + value = [self._get_value(action, v) for v in arg_strings] | ||
2579 | + for v in value: | ||
2580 | + self._check_value(action, v) | ||
2581 | + | ||
2582 | + # return the converted value | ||
2583 | + return value | ||
2584 | + | ||
2585 | + def _get_value(self, action, arg_string): | ||
2586 | + type_func = self._registry_get('type', action.type, action.type) | ||
2587 | + if not _callable(type_func): | ||
2588 | + msg = _('%r is not callable') | ||
2589 | + raise ArgumentError(action, msg % type_func) | ||
2590 | + | ||
2591 | + # convert the value to the appropriate type | ||
2592 | + try: | ||
2593 | + result = type_func(arg_string) | ||
2594 | + | ||
2595 | + # ArgumentTypeErrors indicate errors | ||
2596 | + except ArgumentTypeError: | ||
2597 | + name = getattr(action.type, '__name__', repr(action.type)) | ||
2598 | + msg = str(_sys.exc_info()[1]) | ||
2599 | + raise ArgumentError(action, msg) | ||
2600 | + | ||
2601 | + # TypeErrors or ValueErrors also indicate errors | ||
2602 | + except (TypeError, ValueError): | ||
2603 | + name = getattr(action.type, '__name__', repr(action.type)) | ||
2604 | + msg = _('invalid %s value: %r') | ||
2605 | + raise ArgumentError(action, msg % (name, arg_string)) | ||
2606 | + | ||
2607 | + # return the converted value | ||
2608 | + return result | ||
2609 | + | ||
2610 | + def _check_value(self, action, value): | ||
2611 | + # converted value must be one of the choices (if specified) | ||
2612 | + if action.choices is not None and value not in action.choices: | ||
2613 | + tup = value, ', '.join(map(repr, action.choices)) | ||
2614 | + msg = _('invalid choice: %r (choose from %s)') % tup | ||
2615 | + raise ArgumentError(action, msg) | ||
2616 | + | ||
2617 | + # ======================= | ||
2618 | + # Help-formatting methods | ||
2619 | + # ======================= | ||
2620 | + def format_usage(self): | ||
2621 | + formatter = self._get_formatter() | ||
2622 | + formatter.add_usage(self.usage, self._actions, | ||
2623 | + self._mutually_exclusive_groups) | ||
2624 | + return formatter.format_help() | ||
2625 | + | ||
2626 | + def format_help(self): | ||
2627 | + formatter = self._get_formatter() | ||
2628 | + | ||
2629 | + # usage | ||
2630 | + formatter.add_usage(self.usage, self._actions, | ||
2631 | + self._mutually_exclusive_groups) | ||
2632 | + | ||
2633 | + # description | ||
2634 | + formatter.add_text(self.description) | ||
2635 | + | ||
2636 | + # positionals, optionals and user-defined groups | ||
2637 | + for action_group in self._action_groups: | ||
2638 | + formatter.start_section(action_group.title) | ||
2639 | + formatter.add_text(action_group.description) | ||
2640 | + formatter.add_arguments(action_group._group_actions) | ||
2641 | + formatter.end_section() | ||
2642 | + | ||
2643 | + # epilog | ||
2644 | + formatter.add_text(self.epilog) | ||
2645 | + | ||
2646 | + # determine help from format above | ||
2647 | + return formatter.format_help() | ||
2648 | + | ||
2649 | + def format_version(self): | ||
2650 | + import warnings | ||
2651 | + warnings.warn( | ||
2652 | + 'The format_version method is deprecated -- the "version" ' | ||
2653 | + 'argument to ArgumentParser is no longer supported.', | ||
2654 | + DeprecationWarning) | ||
2655 | + formatter = self._get_formatter() | ||
2656 | + formatter.add_text(self.version) | ||
2657 | + return formatter.format_help() | ||
2658 | + | ||
2659 | + def _get_formatter(self): | ||
2660 | + return self.formatter_class(prog=self.prog) | ||
2661 | + | ||
2662 | + # ===================== | ||
2663 | + # Help-printing methods | ||
2664 | + # ===================== | ||
2665 | + def print_usage(self, file=None): | ||
2666 | + if file is None: | ||
2667 | + file = _sys.stdout | ||
2668 | + self._print_message(self.format_usage(), file) | ||
2669 | + | ||
2670 | + def print_help(self, file=None): | ||
2671 | + if file is None: | ||
2672 | + file = _sys.stdout | ||
2673 | + self._print_message(self.format_help(), file) | ||
2674 | + | ||
2675 | + def print_version(self, file=None): | ||
2676 | + import warnings | ||
2677 | + warnings.warn( | ||
2678 | + 'The print_version method is deprecated -- the "version" ' | ||
2679 | + 'argument to ArgumentParser is no longer supported.', | ||
2680 | + DeprecationWarning) | ||
2681 | + self._print_message(self.format_version(), file) | ||
2682 | + | ||
2683 | + def _print_message(self, message, file=None): | ||
2684 | + if message: | ||
2685 | + if file is None: | ||
2686 | + file = _sys.stderr | ||
2687 | + file.write(message) | ||
2688 | + | ||
2689 | + # =============== | ||
2690 | + # Exiting methods | ||
2691 | + # =============== | ||
2692 | + def exit(self, status=0, message=None): | ||
2693 | + if message: | ||
2694 | + self._print_message(message, _sys.stderr) | ||
2695 | + _sys.exit(status) | ||
2696 | + | ||
2697 | + def error(self, message): | ||
2698 | + """error(message: string) | ||
2699 | + | ||
2700 | + Prints a usage message incorporating the message to stderr and | ||
2701 | + exits. | ||
2702 | + | ||
2703 | + If you override this in a subclass, it should not return -- it | ||
2704 | + should either exit or raise an exception. | ||
2705 | + """ | ||
2706 | + self.print_usage(_sys.stderr) | ||
2707 | + self.exit(2, _('%s: error: %s\n') % (self.prog, message)) | ||
2708 | -- | 83 | -- |
2709 | 2.13.5 | 84 | 2.35.3 |
2710 | |||
2711 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | error_report() only works once monitor_init_globals_core() has been |
---|---|---|---|
2 | called, which is not the case when parsing the --daemonize option. Use | ||
3 | fprintf(stderr, ...) instead. | ||
2 | 4 | ||
3 | The way the throttling algorithm works is that requests start being | 5 | Fixes: 2525edd85fec53e23fda98974a15e3b3c8957596 ("qsd: Add --daemonize") |
4 | throttled once the bucket level exceeds the burst limit. When we get | 6 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
5 | there the bucket leaks at the level set by the user (bkt->avg), and | 7 | Message-Id: <20220609122852.21140-1-hreitz@redhat.com> |
6 | that leak rate is what prevents guest I/O from exceeding the desired | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | limit. | 9 | --- |
10 | storage-daemon/qemu-storage-daemon.c | 6 +++++- | ||
11 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
8 | 12 | ||
9 | If we don't allow bursts (i.e. bkt->max == 0) then we can start | 13 | diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c |
10 | throttling requests immediately. The problem with keeping the | ||
11 | threshold at 0 is that it only allows one request at a time, and as | ||
12 | soon as there's a bit of I/O from the guest every other request will | ||
13 | be throttled and performance will suffer considerably. That can even | ||
14 | make the guest unable to reach the throttle limit if that limit is | ||
15 | high enough, and that happens regardless of the block scheduler used | ||
16 | by the guest. | ||
17 | |||
18 | Increasing that threshold gives flexibility to the guest, allowing it | ||
19 | to perform short bursts of I/O before being throttled. Increasing the | ||
20 | threshold too much does not make a difference in the long run (because | ||
21 | it's the leak rate what defines the actual throughput) but it does | ||
22 | allow the guest to perform longer initial bursts and exceed the | ||
23 | throttle limit for a short while. | ||
24 | |||
25 | A burst value of bkt->avg / 10 allows the guest to perform 100ms' | ||
26 | worth of I/O at the target rate without being throttled. | ||
27 | |||
28 | Signed-off-by: Alberto Garcia <berto@igalia.com> | ||
29 | Message-id: 31aae6645f0d1fbf3860fb2b528b757236f0c0a7.1503580370.git.berto@igalia.com | ||
30 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
31 | --- | ||
32 | util/throttle.c | 11 +++-------- | ||
33 | 1 file changed, 3 insertions(+), 8 deletions(-) | ||
34 | |||
35 | diff --git a/util/throttle.c b/util/throttle.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/util/throttle.c | 15 | --- a/storage-daemon/qemu-storage-daemon.c |
38 | +++ b/util/throttle.c | 16 | +++ b/storage-daemon/qemu-storage-daemon.c |
39 | @@ -XXX,XX +XXX,XX @@ static void throttle_fix_bucket(LeakyBucket *bkt) | 17 | @@ -XXX,XX +XXX,XX @@ static void process_options(int argc, char *argv[], bool pre_init_pass) |
40 | /* zero bucket level */ | 18 | } |
41 | bkt->level = bkt->burst_level = 0; | 19 | case OPTION_DAEMONIZE: |
42 | 20 | if (os_set_daemonize(true) < 0) { | |
43 | - /* The following is done to cope with the Linux CFQ block scheduler | 21 | - error_report("--daemonize not supported in this build"); |
44 | - * which regroup reads and writes by block of 100ms in the guest. | 22 | + /* |
45 | - * When they are two process one making reads and one making writes cfq | 23 | + * --daemonize is parsed before monitor_init_globals_core(), so |
46 | - * make a pattern looking like the following: | 24 | + * error_report() does not work yet |
47 | - * WWWWWWWWWWWRRRRRRRRRRRRRRWWWWWWWWWWWWWwRRRRRRRRRRRRRRRRR | 25 | + */ |
48 | - * Having a max burst value of 100ms of the average will help smooth the | 26 | + fprintf(stderr, "--daemonize not supported in this build\n"); |
49 | - * throttling | 27 | exit(EXIT_FAILURE); |
50 | - */ | 28 | } |
51 | + /* If bkt->max is 0 we still want to allow short bursts of I/O | 29 | break; |
52 | + * from the guest, otherwise every other request will be throttled | ||
53 | + * and performance will suffer considerably. */ | ||
54 | min = bkt->avg / 10; | ||
55 | if (bkt->avg && !bkt->max) { | ||
56 | bkt->max = min; | ||
57 | -- | 30 | -- |
58 | 2.13.5 | 31 | 2.35.3 |
59 | 32 | ||
60 | 33 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | e7874a50ff3f5b20fb46f36958ad ("python: update for mypy 0.950") has added |
---|---|---|---|
2 | `warn_unused_ignores = False` to python/setup.cfg, to be able to keep | ||
3 | compatibility with both pre- and post-0.950 mypy versions. | ||
2 | 4 | ||
3 | The level of the burst bucket is stored in bkt.burst_level, not | 5 | The iotests' mypy.ini needs the same, or 297 will fail (on both pre- and |
4 | bkt.burst_length. | 6 | post-0.950 mypy, as far as I can tell; just for different `ignore` |
7 | lines). | ||
5 | 8 | ||
6 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 9 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
7 | Reviewed-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | 10 | Message-Id: <20220621092536.19837-1-hreitz@redhat.com> |
8 | Message-id: 49aab2711d02f285567f3b3b13a113847af33812.1503580370.git.berto@igalia.com | 11 | Acked-by: John Snow <jsnow@redhat.com> |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 12 | --- |
11 | include/qemu/throttle.h | 2 +- | 13 | tests/qemu-iotests/mypy.ini | 2 +- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h | 16 | diff --git a/tests/qemu-iotests/mypy.ini b/tests/qemu-iotests/mypy.ini |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/qemu/throttle.h | 18 | --- a/tests/qemu-iotests/mypy.ini |
17 | +++ b/include/qemu/throttle.h | 19 | +++ b/tests/qemu-iotests/mypy.ini |
18 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 20 | @@ -XXX,XX +XXX,XX @@ no_implicit_optional = True |
19 | * - The bkt.avg rate does not apply until the bucket is full, | 21 | scripts_are_modules = True |
20 | * allowing the user to do bursts until then. The I/O limit during | 22 | warn_redundant_casts = True |
21 | * bursts is bkt.max. To enforce this limit we keep an additional | 23 | warn_unused_configs = True |
22 | - * bucket in bkt.burst_length that leaks at a rate of bkt.max units | 24 | -warn_unused_ignores = True |
23 | + * bucket in bkt.burst_level that leaks at a rate of bkt.max units | 25 | +warn_unused_ignores = False |
24 | * per second. | ||
25 | * | ||
26 | * - Because of all of the above, the user can perform I/O at a | ||
27 | -- | 26 | -- |
28 | 2.13.5 | 27 | 2.35.3 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | After writing the PID file, we register an atexit() handler to unlink it |
---|---|---|---|
2 | when the process terminates. However, if the process has changed its | ||
3 | working directory in the meantime (e.g. in os_setup_post() when | ||
4 | daemonizing), this will not work when the PID file path was relative. | ||
5 | Therefore, pass the absolute path (created with realpath()) to the | ||
6 | unlink() call in the atexit() handler. | ||
2 | 7 | ||
3 | If QEMU is running on a system that's out of memory and mmap() | 8 | (realpath() needs a path pointing to an existing file, so we cannot use |
4 | fails, QEMU aborts with no error message at all, making it hard | 9 | it before qemu_write_pidfile().) |
5 | to debug the reason for the failure. | ||
6 | 10 | ||
7 | Add perror() calls that will print error information before | 11 | Reproducer: |
8 | aborting. | 12 | $ cd /tmp |
13 | $ qemu-storage-daemon --daemonize --pidfile qsd.pid | ||
14 | $ file qsd.pid | ||
15 | qsd.pid: ASCII text | ||
16 | $ kill $(cat qsd.pid) | ||
17 | $ file qsd.pid | ||
18 | qsd.pid: ASCII text | ||
9 | 19 | ||
10 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 20 | (qsd.pid should be gone after the process has terminated.) |
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 21 | |
12 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 22 | Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2092322 |
13 | Message-id: 20170829212053.6003-1-ehabkost@redhat.com | 23 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 24 | Message-Id: <20220609122701.17172-2-hreitz@redhat.com> |
25 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
15 | --- | 26 | --- |
16 | util/oslib-posix.c | 2 ++ | 27 | storage-daemon/qemu-storage-daemon.c | 11 ++++++++++- |
17 | 1 file changed, 2 insertions(+) | 28 | 1 file changed, 10 insertions(+), 1 deletion(-) |
18 | 29 | ||
19 | diff --git a/util/oslib-posix.c b/util/oslib-posix.c | 30 | diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c |
20 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/util/oslib-posix.c | 32 | --- a/storage-daemon/qemu-storage-daemon.c |
22 | +++ b/util/oslib-posix.c | 33 | +++ b/storage-daemon/qemu-storage-daemon.c |
23 | @@ -XXX,XX +XXX,XX @@ void *qemu_alloc_stack(size_t *sz) | 34 | @@ -XXX,XX +XXX,XX @@ |
24 | ptr = mmap(NULL, *sz, PROT_READ | PROT_WRITE, | 35 | #include "trace/control.h" |
25 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 36 | |
26 | if (ptr == MAP_FAILED) { | 37 | static const char *pid_file; |
27 | + perror("failed to allocate memory for stack"); | 38 | +static char *pid_file_realpath; |
28 | abort(); | 39 | static volatile bool exit_requested = false; |
40 | |||
41 | void qemu_system_killed(int signal, pid_t pid) | ||
42 | @@ -XXX,XX +XXX,XX @@ static void process_options(int argc, char *argv[], bool pre_init_pass) | ||
43 | |||
44 | static void pid_file_cleanup(void) | ||
45 | { | ||
46 | - unlink(pid_file); | ||
47 | + unlink(pid_file_realpath); | ||
48 | } | ||
49 | |||
50 | static void pid_file_init(void) | ||
51 | @@ -XXX,XX +XXX,XX @@ static void pid_file_init(void) | ||
52 | exit(EXIT_FAILURE); | ||
29 | } | 53 | } |
30 | 54 | ||
31 | @@ -XXX,XX +XXX,XX @@ void *qemu_alloc_stack(size_t *sz) | 55 | + pid_file_realpath = g_malloc(PATH_MAX); |
32 | guardpage = ptr; | 56 | + if (!realpath(pid_file, pid_file_realpath)) { |
33 | #endif | 57 | + error_report("cannot resolve PID file path: %s: %s", |
34 | if (mprotect(guardpage, pagesz, PROT_NONE) != 0) { | 58 | + pid_file, strerror(errno)); |
35 | + perror("failed to set up stack guard page"); | 59 | + unlink(pid_file); |
36 | abort(); | 60 | + exit(EXIT_FAILURE); |
37 | } | 61 | + } |
62 | + | ||
63 | atexit(pid_file_cleanup); | ||
64 | } | ||
38 | 65 | ||
39 | -- | 66 | -- |
40 | 2.13.5 | 67 | 2.35.3 |
41 | 68 | ||
42 | 69 | diff view generated by jsdifflib |
1 | From: Dan Aloni <dan@kernelim.com> | 1 | Currently, the exit notifier for unlinking the PID file is registered |
---|---|---|---|
2 | unconditionally. Limit it to only when we actually do create a PID | ||
3 | file. | ||
2 | 4 | ||
3 | The number of queues that should be return by the admin command should: | 5 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
6 | Message-Id: <20220609122701.17172-3-hreitz@redhat.com> | ||
7 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
8 | --- | ||
9 | softmmu/vl.c | 18 +++++++++--------- | ||
10 | 1 file changed, 9 insertions(+), 9 deletions(-) | ||
4 | 11 | ||
5 | 1) Only mention the number of non-admin queues. | 12 | diff --git a/softmmu/vl.c b/softmmu/vl.c |
6 | 2) It is zero-based, meaning that '0 == one non-admin queue', | ||
7 | '1 == two non-admin queues', and so forth. | ||
8 | |||
9 | Because our `num_queues` means the number of queues _plus_ the admin | ||
10 | queue, then the right calculation for the number returned from the admin | ||
11 | command is `num_queues - 2`, combining the two requirements mentioned. | ||
12 | |||
13 | The issue was discovered by reducing num_queues from 64 to 8 and running | ||
14 | a Linux VM with an SMP parameter larger than that (e.g. 22). It tries to | ||
15 | utilize all queues, and therefore fails with an invalid queue number | ||
16 | when trying to queue I/Os on the last queue. | ||
17 | |||
18 | Signed-off-by: Dan Aloni <dan@kernelim.com> | ||
19 | CC: Alex Friedman <alex@e8storage.com> | ||
20 | CC: Keith Busch <keith.busch@intel.com> | ||
21 | CC: Stefan Hajnoczi <stefanha@redhat.com> | ||
22 | Reviewed-by: Keith Busch <keith.busch@intel.com> | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
24 | --- | ||
25 | hw/block/nvme.c | 4 ++-- | ||
26 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
27 | |||
28 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/block/nvme.c | 14 | --- a/softmmu/vl.c |
31 | +++ b/hw/block/nvme.c | 15 | +++ b/softmmu/vl.c |
32 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | 16 | @@ -XXX,XX +XXX,XX @@ static Notifier qemu_unlink_pidfile_notifier; |
33 | result = blk_enable_write_cache(n->conf.blk); | 17 | |
34 | break; | 18 | static void qemu_unlink_pidfile(Notifier *n, void *data) |
35 | case NVME_NUMBER_OF_QUEUES: | 19 | { |
36 | - result = cpu_to_le32((n->num_queues - 1) | ((n->num_queues - 1) << 16)); | 20 | - if (pid_file) { |
37 | + result = cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16)); | 21 | - unlink(pid_file); |
38 | break; | 22 | - } |
39 | default: | 23 | + unlink(pid_file); |
40 | return NVME_INVALID_FIELD | NVME_DNR; | 24 | } |
41 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | 25 | |
42 | break; | 26 | static const QEMUOption *lookup_opt(int argc, char **argv, |
43 | case NVME_NUMBER_OF_QUEUES: | 27 | @@ -XXX,XX +XXX,XX @@ static void qemu_maybe_daemonize(const char *pid_file) |
44 | req->cqe.result = | 28 | os_daemonize(); |
45 | - cpu_to_le32((n->num_queues - 1) | ((n->num_queues - 1) << 16)); | 29 | rcu_disable_atfork(); |
46 | + cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16)); | 30 | |
47 | break; | 31 | - if (pid_file && !qemu_write_pidfile(pid_file, &err)) { |
48 | default: | 32 | - error_reportf_err(err, "cannot create PID file: "); |
49 | return NVME_INVALID_FIELD | NVME_DNR; | 33 | - exit(1); |
34 | - } | ||
35 | + if (pid_file) { | ||
36 | + if (!qemu_write_pidfile(pid_file, &err)) { | ||
37 | + error_reportf_err(err, "cannot create PID file: "); | ||
38 | + exit(1); | ||
39 | + } | ||
40 | |||
41 | - qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | ||
42 | - qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | ||
43 | + qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; | ||
44 | + qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); | ||
45 | + } | ||
46 | } | ||
47 | |||
48 | static void qemu_init_displays(void) | ||
50 | -- | 49 | -- |
51 | 2.13.5 | 50 | 2.35.3 |
52 | 51 | ||
53 | 52 | diff view generated by jsdifflib |
1 | From: Alberto Garcia <berto@igalia.com> | 1 | After writing the PID file, we register an exit notifier to unlink it |
---|---|---|---|
2 | when the process terminates. However, if the process has changed its | ||
3 | working directory in the meantime (e.g. in os_setup_post() when | ||
4 | daemonizing), this will not work when the PID file path was relative. | ||
5 | Therefore, pass the absolute path (created with realpath()) to the | ||
6 | unlink() call in the exit notifier. | ||
2 | 7 | ||
3 | LeakyBucket.burst_length is defined as an unsigned integer but the | 8 | (realpath() needs a path pointing to an existing file, so we cannot use |
4 | code never checks for overflows and it only makes sure that the value | 9 | it before qemu_write_pidfile().) |
5 | is not 0. | ||
6 | 10 | ||
7 | In practice this means that the user can set something like | 11 | Reproducer: |
8 | throttling.iops-total-max-length=4294967300 despite being larger than | 12 | $ cd /tmp |
9 | UINT_MAX and the final value after casting to unsigned int will be 4. | 13 | $ qemu-system-x86_64 --daemonize --pidfile qemu.pid |
14 | $ file qemu.pid | ||
15 | qemu.pid: ASCII text | ||
16 | $ kill $(cat qemu.pid) | ||
17 | $ file qemu.pid | ||
18 | qemu.pid: ASCII text | ||
10 | 19 | ||
11 | This patch changes the data type to uint64_t. This does not increase | 20 | (qemu.pid should be gone after the process has terminated.) |
12 | the storage size of LeakyBucket, and allows us to assign the value | ||
13 | directly from qemu_opt_get_number() or BlockIOThrottle and then do the | ||
14 | checks directly in throttle_is_valid(). | ||
15 | 21 | ||
16 | The value of burst_length does not have a specific upper limit, | 22 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
17 | but since the bucket size is defined by max * burst_length we have | 23 | Message-Id: <20220609122701.17172-4-hreitz@redhat.com> |
18 | to prevent overflows. Instead of going for UINT64_MAX or something | 24 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> |
19 | similar this patch reuses THROTTLE_VALUE_MAX, which allows I/O bursts | 25 | --- |
20 | of 1 GiB/s for 10 days in a row. | 26 | softmmu/vl.c | 30 ++++++++++++++++++++++++++---- |
27 | 1 file changed, 26 insertions(+), 4 deletions(-) | ||
21 | 28 | ||
22 | Signed-off-by: Alberto Garcia <berto@igalia.com> | 29 | diff --git a/softmmu/vl.c b/softmmu/vl.c |
23 | Message-id: 1b2e3049803f71cafb2e1fa1be4fb47147a0d398.1503580370.git.berto@igalia.com | ||
24 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
25 | --- | ||
26 | include/qemu/throttle.h | 2 +- | ||
27 | util/throttle.c | 5 +++++ | ||
28 | 2 files changed, 6 insertions(+), 1 deletion(-) | ||
29 | |||
30 | diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/include/qemu/throttle.h | 31 | --- a/softmmu/vl.c |
33 | +++ b/include/qemu/throttle.h | 32 | +++ b/softmmu/vl.c |
34 | @@ -XXX,XX +XXX,XX @@ typedef struct LeakyBucket { | 33 | @@ -XXX,XX +XXX,XX @@ machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, |
35 | uint64_t max; /* leaky bucket max burst in units */ | 34 | } |
36 | double level; /* bucket level in units */ | 35 | |
37 | double burst_level; /* bucket level in units (for computing bursts) */ | 36 | static const char *pid_file; |
38 | - unsigned burst_length; /* max length of the burst period, in seconds */ | 37 | -static Notifier qemu_unlink_pidfile_notifier; |
39 | + uint64_t burst_length; /* max length of the burst period, in seconds */ | 38 | +struct UnlinkPidfileNotifier { |
40 | } LeakyBucket; | 39 | + Notifier notifier; |
41 | 40 | + char *pid_file_realpath; | |
42 | /* The following structure is used to configure a ThrottleState | 41 | +}; |
43 | diff --git a/util/throttle.c b/util/throttle.c | 42 | +static struct UnlinkPidfileNotifier qemu_unlink_pidfile_notifier; |
44 | index XXXXXXX..XXXXXXX 100644 | 43 | |
45 | --- a/util/throttle.c | 44 | static void qemu_unlink_pidfile(Notifier *n, void *data) |
46 | +++ b/util/throttle.c | 45 | { |
47 | @@ -XXX,XX +XXX,XX @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **errp) | 46 | - unlink(pid_file); |
48 | return false; | 47 | + struct UnlinkPidfileNotifier *upn; |
48 | + | ||
49 | + upn = DO_UPCAST(struct UnlinkPidfileNotifier, notifier, n); | ||
50 | + unlink(upn->pid_file_realpath); | ||
51 | } | ||
52 | |||
53 | static const QEMUOption *lookup_opt(int argc, char **argv, | ||
54 | @@ -XXX,XX +XXX,XX @@ static void qemu_maybe_daemonize(const char *pid_file) | ||
55 | rcu_disable_atfork(); | ||
56 | |||
57 | if (pid_file) { | ||
58 | + char *pid_file_realpath = NULL; | ||
59 | + | ||
60 | if (!qemu_write_pidfile(pid_file, &err)) { | ||
61 | error_reportf_err(err, "cannot create PID file: "); | ||
62 | exit(1); | ||
49 | } | 63 | } |
50 | 64 | ||
51 | + if (bkt->max && bkt->burst_length > THROTTLE_VALUE_MAX / bkt->max) { | 65 | - qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile; |
52 | + error_setg(errp, "burst length too high for this burst rate"); | 66 | - qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier); |
53 | + return false; | 67 | + pid_file_realpath = g_malloc0(PATH_MAX); |
68 | + if (!realpath(pid_file, pid_file_realpath)) { | ||
69 | + error_report("cannot resolve PID file path: %s: %s", | ||
70 | + pid_file, strerror(errno)); | ||
71 | + unlink(pid_file); | ||
72 | + exit(1); | ||
54 | + } | 73 | + } |
55 | + | 74 | + |
56 | if (bkt->max && !bkt->avg) { | 75 | + qemu_unlink_pidfile_notifier = (struct UnlinkPidfileNotifier) { |
57 | error_setg(errp, "bps_max/iops_max require corresponding" | 76 | + .notifier = { |
58 | " bps/iops values"); | 77 | + .notify = qemu_unlink_pidfile, |
78 | + }, | ||
79 | + .pid_file_realpath = pid_file_realpath, | ||
80 | + }; | ||
81 | + qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier.notifier); | ||
82 | } | ||
83 | } | ||
84 | |||
59 | -- | 85 | -- |
60 | 2.13.5 | 86 | 2.35.3 |
61 | 87 | ||
62 | 88 | diff view generated by jsdifflib |