All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com,
	stefanha@redhat.com, codyprime@gmail.com, sw@weilnetz.de,
	pl@kamp.de, qemu-devel@nongnu.org, mreitz@redhat.com,
	ronniesahlberg@gmail.com, den@openvz.org, pbonzini@redhat.com
Subject: [PATCH v2 9/9] block: drop unallocated_blocks_are_zero
Date: Thu,  7 May 2020 11:48:00 +0300	[thread overview]
Message-ID: <20200507084800.20596-10-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20200507084800.20596-1-vsementsov@virtuozzo.com>

Currently this field only set by qed and qcow2. But in fact, all
backing-supporting formats (parallels, qcow, qcow2, qed, vmdk) share
these semantics: on unallocated blocks, if there is no backing file they
just memset the buffer with zeroes.

So, document this behavior for .supports_backing and drop
.unallocated_blocks_are_zero

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/block.h     |  5 -----
 include/block/block_int.h | 12 +++++++++++-
 block/io.c                |  9 ++-------
 block/qcow2.c             |  1 -
 block/qed.c               |  1 -
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index 931003a476..db1cb503ec 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -21,11 +21,6 @@ typedef struct BlockDriverInfo {
     /* offset at which the VM state can be saved (0 if not possible) */
     int64_t vm_state_offset;
     bool is_dirty;
-    /*
-     * True if unallocated blocks read back as zeroes. This is equivalent
-     * to the LBPRZ flag in the SCSI logical block provisioning page.
-     */
-    bool unallocated_blocks_are_zero;
     /*
      * True if this block driver only supports compressed writes
      */
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 92335f33c7..8fac6c3ce2 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -115,7 +115,17 @@ struct BlockDriver {
      */
     bool bdrv_needs_filename;
 
-    /* Set if a driver can support backing files */
+    /*
+     * Set if a driver can support backing files. This also implies the
+     * following semantics:
+     *
+     *  - Return status 0 of .bdrv_co_block_status means that corresponding
+     *    blocks are not allocated in this layer of backing-chain
+     *  - For such (unallocated) blocks, read will:
+     *    - fill buffer with zeros if there is no backing file
+     *    - read from the backing file otherwise, where the block layer
+     *      takes care of reading zeros beyond EOF if backing file is short
+     */
     bool supports_backing;
 
     /* For handling image reopen for split or non-split files */
diff --git a/block/io.c b/block/io.c
index 00e7371d50..484adec5a1 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2385,7 +2385,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
 
     if (ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO)) {
         ret |= BDRV_BLOCK_ALLOCATED;
-    } else if (want_zero) {
+    } else if (want_zero && bs->drv->supports_backing) {
         if (bs->backing) {
             BlockDriverState *bs2 = bs->backing->bs;
             int64_t size2 = bdrv_getlength(bs2);
@@ -2394,12 +2394,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
                 ret |= BDRV_BLOCK_ZERO;
             }
         } else {
-            BlockDriverInfo bdi;
-            int ret2 = bdrv_get_info(bs, &bdi);
-
-            if (ret2 == 0 && bdi.unallocated_blocks_are_zero) {
-                ret |= BDRV_BLOCK_ZERO;
-            }
+            ret |= BDRV_BLOCK_ZERO;
         }
     }
 
diff --git a/block/qcow2.c b/block/qcow2.c
index 2ba0b17c39..dc3c0aac2b 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -4858,7 +4858,6 @@ err:
 static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 {
     BDRVQcow2State *s = bs->opaque;
-    bdi->unallocated_blocks_are_zero = true;
     bdi->cluster_size = s->cluster_size;
     bdi->vm_state_offset = qcow2_vm_state_offset(s);
     return 0;
diff --git a/block/qed.c b/block/qed.c
index b0fdb8f565..fb7833dc8b 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1514,7 +1514,6 @@ static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     memset(bdi, 0, sizeof(*bdi));
     bdi->cluster_size = s->header.cluster_size;
     bdi->is_dirty = s->header.features & QED_F_NEED_CHECK;
-    bdi->unallocated_blocks_are_zero = true;
     return 0;
 }
 
-- 
2.21.0



  parent reply	other threads:[~2020-05-07  8:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07  8:47 [PATCH v2 0/9] drop unallocated_blocks_are_zero Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 1/9] qemu-img: convert: don't use unallocated_blocks_are_zero Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 2/9] block: inline bdrv_unallocated_blocks_are_zero() Vladimir Sementsov-Ogievskiy
2020-05-07 14:08   ` Eric Blake
2020-05-28  9:31     ` Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 3/9] block/vdi: return ZERO block-status when appropriate Vladimir Sementsov-Ogievskiy
2020-05-07 14:10   ` Eric Blake
2020-05-07  8:47 ` [PATCH v2 4/9] block/vpc: " Vladimir Sementsov-Ogievskiy
2020-05-07 14:11   ` Eric Blake
2020-05-07  8:47 ` [PATCH v2 5/9] block/crypto: drop unallocated_blocks_are_zero Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 6/9] block/iscsi: " Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 7/9] block/file-posix: " Vladimir Sementsov-Ogievskiy
2020-05-07  8:47 ` [PATCH v2 8/9] block/vhdx: " Vladimir Sementsov-Ogievskiy
2020-05-07  8:48 ` Vladimir Sementsov-Ogievskiy [this message]
2020-05-07 14:21   ` [PATCH v2 9/9] block: " Eric Blake
2020-05-07 14:45 ` [PATCH v2 10/9] qed: Simplify backing reads Eric Blake
2020-05-07 15:22   ` Eric Blake
2020-05-07 18:22   ` Vladimir Sementsov-Ogievskiy
2020-05-19 17:40 ` [PATCH v2 0/9] drop unallocated_blocks_are_zero 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=20200507084800.20596-10-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=codyprime@gmail.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    --cc=sw@weilnetz.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.