qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 12/47] block: Use bdrv_filter_(bs|child) where obvious


From: Andrey Shinkevich
Subject: Re: [PATCH v7 12/47] block: Use bdrv_filter_(bs|child) where obvious
Date: Wed, 8 Jul 2020 21:24:49 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.9.0

On 25.06.2020 18:21, Max Reitz wrote:
Places that use patterns like

     if (bs->drv->is_filter && bs->file) {
         ... something about bs->file->bs ...
     }

should be

     BlockDriverState *filtered = bdrv_filter_bs(bs);
     if (filtered) {
         ... something about @filtered ...
     }

instead.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
  block.c                        | 31 ++++++++++++++++++++-----------
  block/io.c                     |  7 +++++--
  migration/block-dirty-bitmap.c |  8 +-------
  3 files changed, 26 insertions(+), 20 deletions(-)

...
diff --git a/block/io.c b/block/io.c
index df8f2a98d4..385176b331 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3307,6 +3307,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, 
int64_t offset, bool exact,
                                    Error **errp)
  {
      BlockDriverState *bs = child->bs;
+    BdrvChild *filtered;
      BlockDriver *drv = bs->drv;
      BdrvTrackedRequest req;
      int64_t old_size, new_bytes;
@@ -3358,6 +3359,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, 
int64_t offset, bool exact,
          goto out;
      }
+ filtered = bdrv_filter_child(bs);
+

Isn't better to have this initialization right before the relevant if/else block?

Andrey

      /*
       * If the image has a backing file that is large enough that it would
       * provide data for the new area, we cannot leave it unallocated because
@@ -3390,8 +3393,8 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, 
int64_t offset, bool exact,
              goto out;
          }
          ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
-    } else if (bs->file && drv->is_filter) {
-        ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
+    } else if (filtered) {
+        ret = bdrv_co_truncate(filtered, offset, exact, prealloc, flags, errp);
      } else {
          error_setg(errp, "Image format driver does not support resize");
          ret = -ENOTSUP;

...

Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]