qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com,
	mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	philmd@redhat.com
Subject: [PATCH 08/11] qemu-io-cmds: refactor read_f(): drop extra helpers and variables
Date: Sat, 24 Apr 2021 00:40:30 +0300	[thread overview]
Message-ID: <20210423214033.474034-9-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20210423214033.474034-1-vsementsov@virtuozzo.com>

Now all commands are in coroutines, so we want to move to _co_
functions. Let's just drop helpers and use blk_co_ functions directly.
Note that count is checked at start of read_f anyway.
Both blk_co_pread and blk_co_load_vmstate returns 0 on success, so we
should not care to set ret to 0 explicitly. Moreover, no caller is
care, is successful ret of qemuio_command positive or not.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 qemu-io-cmds.c | 44 ++++++--------------------------------------
 1 file changed, 6 insertions(+), 38 deletions(-)

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index adc9e64c37..bbebecba55 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -527,20 +527,6 @@ fail:
     return buf;
 }
 
-static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
-                    int64_t bytes, int64_t *total)
-{
-    if (bytes > INT_MAX) {
-        return -ERANGE;
-    }
-
-    *total = blk_pread(blk, offset, (uint8_t *)buf, bytes);
-    if (*total < 0) {
-        return *total;
-    }
-    return 1;
-}
-
 static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
                      int64_t bytes, int flags, int64_t *total)
 {
@@ -586,20 +572,6 @@ static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
     return 1;
 }
 
-static int do_load_vmstate(BlockBackend *blk, char *buf, int64_t offset,
-                           int64_t count, int64_t *total)
-{
-    if (count > INT_MAX) {
-        return -ERANGE;
-    }
-
-    *total = blk_load_vmstate(blk, (uint8_t *)buf, offset, count);
-    if (*total < 0) {
-        return *total;
-    }
-    return 1;
-}
-
 static int do_save_vmstate(BlockBackend *blk, char *buf, int64_t offset,
                            int64_t count, int64_t *total)
 {
@@ -667,17 +639,16 @@ static const cmdinfo_t read_cmd = {
     .help       = read_help,
 };
 
-static int read_f(BlockBackend *blk, int argc, char **argv)
+static int coroutine_fn read_f(BlockBackend *blk, int argc, char **argv)
 {
     struct timespec t1, t2;
     bool Cflag = false, qflag = false, vflag = false;
     bool Pflag = false, sflag = false, lflag = false, bflag = false;
-    int c, cnt, ret;
-    char *buf;
+    int c, ret;
+    uint8_t *buf;
     int64_t offset;
     int64_t count;
     /* Some compilers get confused and warn if this is not initialized.  */
-    int64_t total = 0;
     int pattern = 0;
     int64_t pattern_offset = 0, pattern_count = 0;
 
@@ -780,9 +751,9 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
 
     clock_gettime(CLOCK_MONOTONIC, &t1);
     if (bflag) {
-        ret = do_load_vmstate(blk, buf, offset, count, &total);
+        ret = blk_co_load_vmstate(blk, buf, offset, count);
     } else {
-        ret = do_pread(blk, buf, offset, count, &total);
+        ret = blk_co_pread(blk, offset, count, buf, 0);
     }
     clock_gettime(CLOCK_MONOTONIC, &t2);
 
@@ -790,9 +761,6 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
         printf("read failed: %s\n", strerror(-ret));
         goto out;
     }
-    cnt = ret;
-
-    ret = 0;
 
     if (Pflag) {
         void *cmp_buf = g_malloc(pattern_count);
@@ -816,7 +784,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
 
     /* Finally, report back -- -C gives a parsable format */
     t2 = tsub(t2, t1);
-    print_report("read", &t2, offset, count, total, cnt, Cflag);
+    print_report("read", &t2, offset, count, count, 1, Cflag);
 
 out:
     qemu_io_free(buf);
-- 
2.29.2



  parent reply	other threads:[~2021-04-23 21:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 21:40 [PATCH 00/11] qemu-io-cmds: move to coroutine Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 01/11] block-coroutine-wrapper: allow non bdrv_ prefix Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 02/11] block-coroutine-wrapper: support BlockBackend first argument Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 03/11] block/block-gen.h: bind monitor Vladimir Sementsov-Ogievskiy
2021-04-24  5:23   ` Markus Armbruster
2021-04-26  9:12     ` Vladimir Sementsov-Ogievskiy
2021-04-26 12:23       ` Markus Armbruster
2021-04-23 21:40 ` [PATCH 04/11] block: introduce bdrv_debug_wait_break Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 05/11] qemu-io-cmds: move qemu-io commands to coroutine Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 06/11] block: drop unused bdrv_debug_is_suspended() Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 07/11] block-backend: add _co_ versions of blk_save_vmstate / blk_load_vmstate Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` Vladimir Sementsov-Ogievskiy [this message]
2021-04-23 21:40 ` [PATCH 09/11] qemu-io-cmds: refactor write_f(): drop extra helpers and variables Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 10/11] qemu-io-cmds: drop do_co_readv() and do_co_writev() helpers Vladimir Sementsov-Ogievskiy
2021-04-23 21:40 ` [PATCH 11/11] block-backend: drop unused blk_save_vmstate() and blk_load_vmstate() Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210423214033.474034-9-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).