[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/38] qemu-io: do not reinvent the blk_pwrite_zeroes wheel
From: |
Kevin Wolf |
Subject: |
[PULL 06/38] qemu-io: do not reinvent the blk_pwrite_zeroes wheel |
Date: |
Fri, 20 Jan 2023 13:26:01 +0100 |
From: Paolo Bonzini <pbonzini@redhat.com>
qemu-io's do_co_pwrite_zeroes is reinventing the coroutine wrapper
blk_pwrite_zeroes. Just use the real thing directly.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221215130225.476477-1-pbonzini@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qemu-io-cmds.c | 57 +++++++++-----------------------------------------
1 file changed, 10 insertions(+), 47 deletions(-)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 952dc940f1..7a412d6512 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -572,54 +572,17 @@ static int do_pwrite(BlockBackend *blk, char *buf,
int64_t offset,
return 1;
}
-typedef struct {
- BlockBackend *blk;
- int64_t offset;
- int64_t bytes;
- int64_t *total;
- int flags;
- int ret;
- bool done;
-} CoWriteZeroes;
-
-static void coroutine_fn co_pwrite_zeroes_entry(void *opaque)
-{
- CoWriteZeroes *data = opaque;
-
- data->ret = blk_co_pwrite_zeroes(data->blk, data->offset, data->bytes,
- data->flags);
- data->done = true;
- if (data->ret < 0) {
- *data->total = data->ret;
- return;
- }
-
- *data->total = data->bytes;
-}
-
-static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
+static int do_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes, int flags, int64_t *total)
{
- Coroutine *co;
- CoWriteZeroes data = {
- .blk = blk,
- .offset = offset,
- .bytes = bytes,
- .total = total,
- .flags = flags,
- .done = false,
- };
-
- co = qemu_coroutine_create(co_pwrite_zeroes_entry, &data);
- bdrv_coroutine_enter(blk_bs(blk), co);
- while (!data.done) {
- aio_poll(blk_get_aio_context(blk), true);
- }
- if (data.ret < 0) {
- return data.ret;
- } else {
- return 1;
+ int ret = blk_pwrite_zeroes(blk, offset, bytes,
+ flags | BDRV_REQ_ZERO_WRITE);
+
+ if (ret < 0) {
+ return ret;
}
+ *total = bytes;
+ return 1;
}
static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
@@ -1042,7 +1005,7 @@ static void write_help(void)
" -C, -- report statistics in a machine parsable format\n"
" -q, -- quiet mode, do not show I/O statistics\n"
" -u, -- with -z, allow unmapping\n"
-" -z, -- write zeroes using blk_co_pwrite_zeroes\n"
+" -z, -- write zeroes using blk_pwrite_zeroes\n"
"\n");
}
@@ -1199,7 +1162,7 @@ static int write_f(BlockBackend *blk, int argc, char
**argv)
if (bflag) {
ret = do_save_vmstate(blk, buf, offset, count, &total);
} else if (zflag) {
- ret = do_co_pwrite_zeroes(blk, offset, count, flags, &total);
+ ret = do_pwrite_zeroes(blk, offset, count, flags, &total);
} else if (cflag) {
ret = do_write_compressed(blk, buf, offset, count, &total);
} else {
--
2.38.1
- [PULL 00/38] Block layer patches, Kevin Wolf, 2023/01/20
- [PULL 01/38] tests/qemu-iotests/312: Mark "quorum" as required driver, Kevin Wolf, 2023/01/20
- [PULL 04/38] coroutine: annotate coroutine_fn for libclang, Kevin Wolf, 2023/01/20
- [PULL 03/38] pflash: Only read non-zero parts of backend image, Kevin Wolf, 2023/01/20
- [PULL 02/38] tests/qemu-iotests/262: Check for availability of "blkverify" first, Kevin Wolf, 2023/01/20
- [PULL 06/38] qemu-io: do not reinvent the blk_pwrite_zeroes wheel,
Kevin Wolf <=
- [PULL 07/38] block: remove bdrv_coroutine_enter, Kevin Wolf, 2023/01/20
- [PULL 08/38] qcow2: Fix theoretical corruption in store_bitmap() error path, Kevin Wolf, 2023/01/20
- [PULL 05/38] block: Add no_coroutine_fn and coroutine_mixed_fn marker, Kevin Wolf, 2023/01/20
- [PULL 10/38] qemu-img bitmap: Report errors while closing the image, Kevin Wolf, 2023/01/20
- [PULL 11/38] qemu-iotests: Test qemu-img bitmap/commit exit code on error, Kevin Wolf, 2023/01/20
- [PULL 09/38] qemu-img commit: Report errors while closing the image, Kevin Wolf, 2023/01/20
- [PULL 13/38] block: Convert bdrv_io_plug() to co_wrapper, Kevin Wolf, 2023/01/20
- [PULL 12/38] block-coroutine-wrapper: support void functions, Kevin Wolf, 2023/01/20
- [PULL 14/38] block: Convert bdrv_io_unplug() to co_wrapper, Kevin Wolf, 2023/01/20
- [PULL 15/38] block: Convert bdrv_is_inserted() to co_wrapper, Kevin Wolf, 2023/01/20