yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-introduce-BDRV_REQ_MAY_UNMAP-request-flag.patch.patch.patch

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