0a122b
From c8f8c2859899c631415825beee9cb6369e302f43 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <c8f8c2859899c631415825beee9cb6369e302f43.1389014116.git.minovotn@redhat.com>
0a122b
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
0a122b
From: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 14:08:56 +0100
0a122b
Subject: [PATCH 08/50] block: introduce BDRV_REQ_MAY_UNMAP request flag
0a122b
0a122b
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Message-id: <1386598178-11845-11-git-send-email-pbonzini@redhat.com>
0a122b
Patchwork-id: 56047
0a122b
O-Subject: [RHEL 7.0 qemu-kvm PATCH 10/52] block: introduce BDRV_REQ_MAY_UNMAP request flag
0a122b
Bugzilla: 1007815
0a122b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
From: Peter Lieven <pl@kamp.de>
0a122b
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Signed-off-by: Peter Lieven <pl@kamp.de>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit d32f35cbc5a87af5e1100dd55074a79fc2cb5307)
0a122b
0a122b
Conflicts:
0a122b
	block/backup.c [missing]
0a122b
---
0a122b
 block-migration.c     | 3 ++-
0a122b
 block.c               | 4 ++++
0a122b
 include/block/block.h | 7 +++++++
0a122b
 3 files changed, 13 insertions(+), 1 deletion(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 block-migration.c     | 3 ++-
0a122b
 block.c               | 4 ++++
0a122b
 include/block/block.h | 7 +++++++
0a122b
 3 files changed, 13 insertions(+), 1 deletion(-)
0a122b
0a122b
diff --git a/block-migration.c b/block-migration.c
0a122b
index 3b22db6..1844066 100644
0a122b
--- a/block-migration.c
0a122b
+++ b/block-migration.c
0a122b
@@ -780,7 +780,8 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
0a122b
             }
0a122b
 
0a122b
             if (flags & BLK_MIG_FLAG_ZERO_BLOCK) {
0a122b
-                ret = bdrv_write_zeroes(bs, addr, nr_sectors, 0);
0a122b
+                ret = bdrv_write_zeroes(bs, addr, nr_sectors,
0a122b
+                                        BDRV_REQ_MAY_UNMAP);
0a122b
             } else {
0a122b
                 buf = g_malloc(BLOCK_SIZE);
0a122b
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
0a122b
diff --git a/block.c b/block.c
0a122b
index 698334a..77167f0 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -2827,6 +2827,10 @@ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs,
0a122b
 {
0a122b
     trace_bdrv_co_write_zeroes(bs, sector_num, nb_sectors);
0a122b
 
0a122b
+    if (!(bs->open_flags & BDRV_O_UNMAP)) {
0a122b
+        flags &= ~BDRV_REQ_MAY_UNMAP;
0a122b
+    }
0a122b
+
0a122b
     return bdrv_co_do_writev(bs, sector_num, nb_sectors, NULL,
0a122b
                              BDRV_REQ_ZERO_WRITE | flags);
0a122b
 }
0a122b
diff --git a/include/block/block.h b/include/block/block.h
0a122b
index 2d78a84..10abc00 100644
0a122b
--- a/include/block/block.h
0a122b
+++ b/include/block/block.h
0a122b
@@ -65,6 +65,13 @@ typedef struct BlockDevOps {
0a122b
 typedef enum {
0a122b
     BDRV_REQ_COPY_ON_READ = 0x1,
0a122b
     BDRV_REQ_ZERO_WRITE   = 0x2,
0a122b
+    /* The BDRV_REQ_MAY_UNMAP flag is used to indicate that the block driver
0a122b
+     * is allowed to optimize a write zeroes request by unmapping (discarding)
0a122b
+     * blocks if it is guaranteed that the result will read back as
0a122b
+     * zeroes. The flag is only passed to the driver if the block device is
0a122b
+     * opened with BDRV_O_UNMAP.
0a122b
+     */
0a122b
+    BDRV_REQ_MAY_UNMAP    = 0x4,
0a122b
 } BdrvRequestFlags;
0a122b
 
0a122b
 #define BDRV_O_RDWR        0x0002
0a122b
-- 
0a122b
1.7.11.7
0a122b