[GEDI] [PATCH 12/17] gluster: Support BDRV_ZERO_OPEN

Eric Blake eblake at redhat.com
Fri Jan 31 17:44:31 UTC 2020


Since gluster already copies file-posix for lseek usage in block
status, it also makes sense to copy it for learning if the image
currently reads as all zeroes.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 block/gluster.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/block/gluster.c b/block/gluster.c
index 9d952c70981b..0417a86547c8 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1464,6 +1464,22 @@ exit:
     return -ENOTSUP;
 }

+static int qemu_gluster_known_zeroes(BlockDriverState *bs)
+{
+    /*
+     * GlusterFS volume could be backed by a block device, with no way
+     * to query if regions added by creation or truncation will read
+     * as zeroes.  However, we can use lseek(SEEK_DATA) to check if
+     * contents currently read as zero.
+     */
+    off_t data, hole;
+
+    if (find_allocation(bs, 0, &data, &hole) == -ENXIO) {
+        return BDRV_ZERO_OPEN;
+    }
+    return 0;
+}
+
 /*
  * Returns the allocation status of the specified offset.
  *
@@ -1561,6 +1577,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
     .bdrv_co_flush_to_disk        = qemu_gluster_co_flush_to_disk,
+    .bdrv_known_zeroes            = qemu_gluster_known_zeroes,
 #ifdef CONFIG_GLUSTERFS_DISCARD
     .bdrv_co_pdiscard             = qemu_gluster_co_pdiscard,
 #endif
@@ -1591,6 +1608,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
     .bdrv_co_flush_to_disk        = qemu_gluster_co_flush_to_disk,
+    .bdrv_known_zeroes            = qemu_gluster_known_zeroes,
 #ifdef CONFIG_GLUSTERFS_DISCARD
     .bdrv_co_pdiscard             = qemu_gluster_co_pdiscard,
 #endif
@@ -1621,6 +1639,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
     .bdrv_co_flush_to_disk        = qemu_gluster_co_flush_to_disk,
+    .bdrv_known_zeroes            = qemu_gluster_known_zeroes,
 #ifdef CONFIG_GLUSTERFS_DISCARD
     .bdrv_co_pdiscard             = qemu_gluster_co_pdiscard,
 #endif
@@ -1657,6 +1676,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
     .bdrv_co_flush_to_disk        = qemu_gluster_co_flush_to_disk,
+    .bdrv_known_zeroes            = qemu_gluster_known_zeroes,
 #ifdef CONFIG_GLUSTERFS_DISCARD
     .bdrv_co_pdiscard             = qemu_gluster_co_pdiscard,
 #endif
-- 
2.24.1



More information about the integration mailing list