qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org
Cc: kwolf@redhat.com, nsoffer@redhat.com, qemu-block@nongnu.org,
	mreitz@redhat.com
Subject: Re: [PATCH v4 6/9] qemu-img: Add bitmap sub-command
Date: Mon, 18 May 2020 14:07:11 -0500	[thread overview]
Message-ID: <54ab6b66-d22d-820b-f4ad-2859f856de92@redhat.com> (raw)
In-Reply-To: <92016f3f-a7c1-5384-5968-b89de5f01ecb@virtuozzo.com>

On 5/18/20 6:42 AM, Vladimir Sementsov-Ogievskiy wrote:
> 13.05.2020 04:16, Eric Blake wrote:
>> Include actions for --add, --remove, --clear, --enable, --disable, and
>> --merge (note that --clear is a bit of fluff, because the same can be
>> accomplished by removing a bitmap and then adding a new one in its
>> place, but it matches what QMP commands exist).  Listing is omitted,
>> because it does not require a bitmap name and because it was already
>> possible with 'qemu-img info'.  A single command line can play one or
>> more bitmap commands in sequence on the same bitmap name (although all
>> added bitmaps share the same granularity, and and all merged bitmaps
>> come from the same source file).  Merge defaults to other bitmaps in
>> the primary image, but can also be told to merge bitmaps from a
>> distinct image.
>>
>> While this supports --image-opts for the file being modified, I did
>> not think it worth the extra complexity to support that for the source
>> file in a cross-file merges.  Likewise, I chose to have --merge only
>> take a single source rather than following the QMP support for
>> multiple merges in one go (although you can still use more than one
>> --merge in the command line); in part because qemu-img is offline and
>> therefore atomicity is not an issue.
>>

>> +
>> +    blk = img_open(image_opts, filename, fmt, BDRV_O_RDWR, false, false,
>> +                   false);
> 
> fit in one line

That line would be exactly 80; I tend to wrap at 79 or earlier rather 
than exactly on 80.

> 
>> +    if (!blk) {
>> +        goto out;
>> +    }
>> +    bs = blk_bs(blk);
>> +    if (src_filename) {
>> +        src = img_open(NULL, src_filename, src_fmt, 0, false, false,
>> +                       false);
> 
> s/NULL/false/

D'oh.  And yet it still compiles.  Fixing.

> 
> also, fit in one line

Yes, this one's shorter.  Fixing.


>> +
>> +        if (err) {
>> +            error_reportf_err(err, "Operation %s on bitmap %s failed",
> 
> s/failed/failed: /
> 
>> +                              op, bitmap);
>> +            ret = -1;
> 
> dead assignment: you never set ret after first initialization to -1.

Fixing both.

> 
>> +            goto out;
>> +        }
>> +        g_free(act);
>> +    }
>> +
>> +    ret = 0;
>> +
>> + out:
>> +    blk_unref(src);
>> +    blk_unref(blk);
>> +    qemu_opts_del(opts);
>> +    if (ret) {
>> +        return 1;
>> +    }
>> +    return 0;
> 
> Hmm, as it's the only usage of ret, you may initialize it to 1 at 
> function start, and here just "return ret;"

Yep, done.

>> +DEF("bitmap", img_bitmap,
>> +    "bitmap (--merge SOURCE | --add | --remove | --clear | --enable | 
>> --disable)... [-b source_file [-F source_fmt]] [-g granularity] 
>> [--object objectdef] [--image-opts | -f fmt] filename bitmap")
>> +SRST
>> +.. option:: bitmap (--merge SOURCE | --add | --remove | --clear | 
>> --enable | --disable)... [-b SOURCE_FILE [-F SOURCE_FMT]] [-g 
>> GRANULARITY] [--object OBJECTDEF] [--image-opts | -f FMT] FILENAME BITMAP
> 
> Not about this patch, but it's a pity that we have triple duplications 
> (triplications ?) of such lines..

Yes, it is annoying.  But as you say, it's a cleanup for another day, 
for someone who is interested.

> 
> With at least s/NULL/false/ and s/failed/failed: / (or with all my tiny 
> suggestions):
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

Thanks; squashing in:

diff --git i/qemu-img.c w/qemu-img.c
index 8c99e68ba8aa..f940137cb0e5 100644
--- i/qemu-img.c
+++ w/qemu-img.c
@@ -4493,7 +4493,7 @@ typedef struct ImgBitmapAction {
  static int img_bitmap(int argc, char **argv)
  {
      Error *err = NULL;
-    int c, ret = -1;
+    int c, ret = 1;
      QemuOpts *opts = NULL;
      const char *fmt = NULL, *src_fmt = NULL, *src_filename = NULL;
      const char *filename, *bitmap;
@@ -4641,8 +4641,7 @@ static int img_bitmap(int argc, char **argv)
      }
      bs = blk_bs(blk);
      if (src_filename) {
-        src = img_open(NULL, src_filename, src_fmt, 0, false, false,
-                       false);
+        src = img_open(false, src_filename, src_fmt, 0, false, false, 
false);
          if (!src) {
              goto out;
          }
@@ -4695,9 +4694,8 @@ static int img_bitmap(int argc, char **argv)
          }

          if (err) {
-            error_reportf_err(err, "Operation %s on bitmap %s failed",
+            error_reportf_err(err, "Operation %s on bitmap %s failed: ",
                                op, bitmap);
-            ret = -1;
              goto out;
          }
          g_free(act);
@@ -4709,10 +4707,7 @@ static int img_bitmap(int argc, char **argv)
      blk_unref(src);
      blk_unref(blk);
      qemu_opts_del(opts);
-    if (ret) {
-        return 1;
-    }
-    return 0;
+    return ret;
  }

  #define C_BS      01

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2020-05-18 19:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13  1:16 [PATCH v4 0/9] qemu-img: Add convert --bitmaps Eric Blake
2020-05-13  1:16 ` [PATCH v4 1/9] docs: Sort sections on qemu-img subcommand parameters Eric Blake
2020-05-14  5:02   ` Vladimir Sementsov-Ogievskiy
2020-05-13  1:16 ` [PATCH v4 2/9] qemu-img: Fix stale comments on doc location Eric Blake
2020-05-14  5:06   ` Vladimir Sementsov-Ogievskiy
2020-05-13  1:16 ` [PATCH v4 3/9] block: Make it easier to learn which BDS support bitmaps Eric Blake
2020-05-14  5:19   ` Vladimir Sementsov-Ogievskiy
2020-05-14 14:09     ` Eric Blake
2020-05-13  1:16 ` [PATCH v4 4/9] blockdev: Promote several bitmap functions to non-static Eric Blake
2020-05-14  5:45   ` Vladimir Sementsov-Ogievskiy
2020-05-14 11:45   ` Vladimir Sementsov-Ogievskiy
2020-05-14 14:10     ` Eric Blake
2020-05-13  1:16 ` [PATCH v4 5/9] blockdev: Split off basic bitmap operations for qemu-img Eric Blake
2020-05-14  6:21   ` Vladimir Sementsov-Ogievskiy
2020-05-14 14:15     ` Eric Blake
2020-05-13  1:16 ` [PATCH v4 6/9] qemu-img: Add bitmap sub-command Eric Blake
2020-05-14  6:45   ` Vladimir Sementsov-Ogievskiy
2020-05-14 14:20     ` Eric Blake
2020-05-14 15:09       ` Vladimir Sementsov-Ogievskiy
2020-05-18 11:42   ` Vladimir Sementsov-Ogievskiy
2020-05-18 19:07     ` Eric Blake [this message]
2020-05-18 19:38       ` Vladimir Sementsov-Ogievskiy
2020-05-13  1:16 ` [PATCH v4 7/9] qcow2: Expose bitmaps' size during measure Eric Blake
2020-05-18 13:07   ` Vladimir Sementsov-Ogievskiy
2020-05-18 19:17     ` Eric Blake
2020-05-18 19:47       ` Vladimir Sementsov-Ogievskiy
2020-05-13  1:16 ` [PATCH v4 8/9] qemu-img: Add convert --bitmaps option Eric Blake
2020-05-18 13:33   ` Vladimir Sementsov-Ogievskiy
2020-05-13  1:16 ` [PATCH v4 9/9] iotests: Add test 291 to for qemu-img bitmap coverage Eric Blake
2020-05-18 14:43   ` 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=54ab6b66-d22d-820b-f4ad-2859f856de92@redhat.com \
    --to=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=nsoffer@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /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).