05bba0
From 4aec281092b790f6a91b657c6d6293171243a187 Mon Sep 17 00:00:00 2001
05bba0
From: Kevin Wolf <kwolf@redhat.com>
05bba0
Date: Fri, 29 May 2015 17:05:11 +0200
05bba0
Subject: [PATCH 1/8] qcow2: Pass discard type to qcow2_discard_clusters()
05bba0
05bba0
Message-id: <1432919112-18076-2-git-send-email-kwolf@redhat.com>
05bba0
Patchwork-id: 65148
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 1/2] qcow2: Pass discard type to qcow2_discard_clusters()
05bba0
Bugzilla: 1208808
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
05bba0
05bba0
The function will be used internally instead of only being called for
05bba0
guest discard requests.
05bba0
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
Reviewed-by: Max Reitz <mreitz@redhat.com>
05bba0
(cherry picked from commit 670df5e3b4b5ef830a7c3c970170dbfa11cbb8d2)
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/qcow2-cluster.c | 8 ++++----
05bba0
 block/qcow2.c         | 2 +-
05bba0
 block/qcow2.h         | 2 +-
05bba0
 3 files changed, 6 insertions(+), 6 deletions(-)
05bba0
05bba0
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
05bba0
index 67f1393..81d90d9 100644
05bba0
--- a/block/qcow2-cluster.c
05bba0
+++ b/block/qcow2-cluster.c
05bba0
@@ -1333,7 +1333,7 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
05bba0
  * clusters.
05bba0
  */
05bba0
 static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
05bba0
-    unsigned int nb_clusters)
05bba0
+    unsigned int nb_clusters, enum qcow2_discard_type type)
05bba0
 {
05bba0
     BDRVQcowState *s = bs->opaque;
05bba0
     uint64_t *l2_table;
05bba0
@@ -1362,7 +1362,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
05bba0
         l2_table[l2_index + i] = cpu_to_be64(0);
05bba0
 
05bba0
         /* Then decrease the refcount */
05bba0
-        qcow2_free_any_clusters(bs, old_offset, 1, QCOW2_DISCARD_REQUEST);
05bba0
+        qcow2_free_any_clusters(bs, old_offset, 1, type);
05bba0
     }
05bba0
 
05bba0
     ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
05bba0
@@ -1374,7 +1374,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
05bba0
 }
05bba0
 
05bba0
 int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
05bba0
-    int nb_sectors)
05bba0
+    int nb_sectors, enum qcow2_discard_type type)
05bba0
 {
05bba0
     BDRVQcowState *s = bs->opaque;
05bba0
     uint64_t end_offset;
05bba0
@@ -1397,7 +1397,7 @@ int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
05bba0
 
05bba0
     /* Each L2 table is handled by its own loop iteration */
05bba0
     while (nb_clusters > 0) {
05bba0
-        ret = discard_single_l2(bs, offset, nb_clusters);
05bba0
+        ret = discard_single_l2(bs, offset, nb_clusters, type);
05bba0
         if (ret < 0) {
05bba0
             goto fail;
05bba0
         }
05bba0
diff --git a/block/qcow2.c b/block/qcow2.c
05bba0
index 005d513..babcb4b 100644
05bba0
--- a/block/qcow2.c
05bba0
+++ b/block/qcow2.c
05bba0
@@ -1870,7 +1870,7 @@ static coroutine_fn int qcow2_co_discard(BlockDriverState *bs,
05bba0
 
05bba0
     qemu_co_mutex_lock(&s->lock);
05bba0
     ret = qcow2_discard_clusters(bs, sector_num << BDRV_SECTOR_BITS,
05bba0
-        nb_sectors);
05bba0
+        nb_sectors, QCOW2_DISCARD_REQUEST);
05bba0
     qemu_co_mutex_unlock(&s->lock);
05bba0
     return ret;
05bba0
 }
05bba0
diff --git a/block/qcow2.h b/block/qcow2.h
05bba0
index 1cc1ef0..9ad8aad 100644
05bba0
--- a/block/qcow2.h
05bba0
+++ b/block/qcow2.h
05bba0
@@ -514,7 +514,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
05bba0
 
05bba0
 int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
05bba0
 int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
05bba0
-    int nb_sectors);
05bba0
+    int nb_sectors, enum qcow2_discard_type type);
05bba0
 int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
05bba0
 
05bba0
 int qcow2_expand_zero_clusters(BlockDriverState *bs);
05bba0
-- 
05bba0
1.8.3.1
05bba0