On 20/5/26 23:49, Marc-André Lureau wrote:
Convert the qemu-io command infrastructure to use QEMU's Error API
(Error **errp) for error propagation instead of printing directly to
stdout/stderr via printf/fprintf.

The cfunc_t typedef, all ~35 command functions, the dispatcher chain
(command/init_check_command/qemuio_command), and helper functions
(parse_pattern, create_iovec, qemu_io_alloc_from_file) all gain an
Error **errp parameter. Async completion callbacks (aio_read_done,
aio_write_done, aio_discard_done) use error_report() since they have
no Error path back to the caller.

Update tests:
- error_report_err() prepends qemu-io: prefix
- copy-before-write: check the HMP return value, rather than stdio
- other tests: update to check JSON {"return": "Error: error text"}

Signed-off-by: Marc-André Lureau <[email protected]>
---
  include/qemu-io.h                          |   4 +-
  block/monitor/block-hmp-cmds.c             |   2 +-
  qemu-io-cmds.c                             | 426 +++++++++++++++--------------
  qemu-io.c                                  |  17 +-
  tests/qemu-iotests/004.out                 |  20 +-
  tests/qemu-iotests/021.out                 |  60 ++--
  tests/qemu-iotests/060.out                 |  44 ++-
  tests/qemu-iotests/071.out                 |  10 +-
  tests/qemu-iotests/072.out                 |   2 +-
  tests/qemu-iotests/080.out                 |   4 +-
  tests/qemu-iotests/089.out                 |   4 +-
  tests/qemu-iotests/114.out                 |   2 +-
  tests/qemu-iotests/134.out                 |   2 +-
  tests/qemu-iotests/137.out                 |   2 +-
  tests/qemu-iotests/171                     |   2 +-
  tests/qemu-iotests/171.out                 |  68 ++---
  tests/qemu-iotests/214.out                 |   2 +-
  tests/qemu-iotests/220.out                 |   2 +-
  tests/qemu-iotests/244.out                 |  12 +-
  tests/qemu-iotests/249.out                 |   6 +-
  tests/qemu-iotests/271.out                 |  14 +-
  tests/qemu-iotests/tests/copy-before-write |  66 +++--
  22 files changed, 404 insertions(+), 367 deletions(-)


diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index de4c1966fea..5093aa4169a 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c


-static int reopen_f(BlockBackend *blk, int argc, char **argv)
+static int reopen_f(BlockBackend *blk, int argc, char **argv, Error **errp)
  {
      BlockDriverState *bs = blk_bs(blk);
      QemuOpts *qopts;

@@ -2609,37 +2624,41 @@ static int reopen_f(BlockBackend *blk, int argc, char 
**argv)
          qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & 
BDRV_O_NO_FLUSH);
      }
- bdrv_reopen(bs, opts, true, &local_err);
-
-    if (local_err) {
-        error_report_err(local_err);
-        return -EINVAL;
+    {
+        Error *local_err = NULL;
+        bdrv_reopen(bs, opts, true, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -EINVAL;
+        }
      }

        if (bdrv_reopen(bs, opts, true, errp) < 0) {
            return -EINVAL;
        }

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>

blk_set_enable_write_cache(blk, !writethrough);
      return 0;
  }

Reply via email to