9ae3a8
From f6f47020d06eca20a99967b6ac9eef65326dfdde Mon Sep 17 00:00:00 2001
9ae3a8
From: Orit Wasserman <owasserm@redhat.com>
9ae3a8
Date: Wed, 9 Oct 2013 10:09:06 +0200
9ae3a8
Subject: [PATCH 11/25] block: add bdrv_write_zeroes()
9ae3a8
9ae3a8
RH-Author: Orit Wasserman <owasserm@redhat.com>
9ae3a8
Message-id: <1381313355-15641-2-git-send-email-owasserm@redhat.com>
9ae3a8
Patchwork-id: 54797
9ae3a8
O-Subject: [RHEL7.0 qemu-kvm v2 01/10] block: add bdrv_write_zeroes()
9ae3a8
Bugzilla: 921465
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
9ae3a8
From: Peter Lieven <pl@kamp.de>
9ae3a8
9ae3a8
Signed-off-by: Peter Lieven <pl@kamp.de>
9ae3a8
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 4105eaaab9376ea959de711b81bba9e1494c971d)
9ae3a8
---
9ae3a8
 block.c               | 27 +++++++++++++++++++--------
9ae3a8
 include/block/block.h |  2 ++
9ae3a8
 2 files changed, 21 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c               |   27 +++++++++++++++++++--------
9ae3a8
 include/block/block.h |    2 ++
9ae3a8
 2 files changed, 21 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index bd52c13..b160f62 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -2190,6 +2190,7 @@ typedef struct RwCo {
9ae3a8
     QEMUIOVector *qiov;
9ae3a8
     bool is_write;
9ae3a8
     int ret;
9ae3a8
+    BdrvRequestFlags flags;
9ae3a8
 } RwCo;
9ae3a8
 
9ae3a8
 static void coroutine_fn bdrv_rw_co_entry(void *opaque)
9ae3a8
@@ -2198,10 +2199,12 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque)
9ae3a8
 
9ae3a8
     if (!rwco->is_write) {
9ae3a8
         rwco->ret = bdrv_co_do_readv(rwco->bs, rwco->sector_num,
9ae3a8
-                                     rwco->nb_sectors, rwco->qiov, 0);
9ae3a8
+                                     rwco->nb_sectors, rwco->qiov,
9ae3a8
+                                     rwco->flags);
9ae3a8
     } else {
9ae3a8
         rwco->ret = bdrv_co_do_writev(rwco->bs, rwco->sector_num,
9ae3a8
-                                      rwco->nb_sectors, rwco->qiov, 0);
9ae3a8
+                                      rwco->nb_sectors, rwco->qiov,
9ae3a8
+                                      rwco->flags);
9ae3a8
     }
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -2209,7 +2212,8 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque)
9ae3a8
  * Process a vectored synchronous request using coroutines
9ae3a8
  */
9ae3a8
 static int bdrv_rwv_co(BlockDriverState *bs, int64_t sector_num,
9ae3a8
-                       QEMUIOVector *qiov, bool is_write)
9ae3a8
+                       QEMUIOVector *qiov, bool is_write,
9ae3a8
+                       BdrvRequestFlags flags)
9ae3a8
 {
9ae3a8
     Coroutine *co;
9ae3a8
     RwCo rwco = {
9ae3a8
@@ -2219,6 +2223,7 @@ static int bdrv_rwv_co(BlockDriverState *bs, int64_t sector_num,
9ae3a8
         .qiov = qiov,
9ae3a8
         .is_write = is_write,
9ae3a8
         .ret = NOT_DONE,
9ae3a8
+        .flags = flags,
9ae3a8
     };
9ae3a8
     assert((qiov->size & (BDRV_SECTOR_SIZE - 1)) == 0);
9ae3a8
 
9ae3a8
@@ -2250,7 +2255,7 @@ static int bdrv_rwv_co(BlockDriverState *bs, int64_t sector_num,
9ae3a8
  * Process a synchronous request using coroutines
9ae3a8
  */
9ae3a8
 static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
9ae3a8
-                      int nb_sectors, bool is_write)
9ae3a8
+                      int nb_sectors, bool is_write, BdrvRequestFlags flags)
9ae3a8
 {
9ae3a8
     QEMUIOVector qiov;
9ae3a8
     struct iovec iov = {
9ae3a8
@@ -2259,14 +2264,14 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
9ae3a8
     };
9ae3a8
 
9ae3a8
     qemu_iovec_init_external(&qiov, &iov, 1);
9ae3a8
-    return bdrv_rwv_co(bs, sector_num, &qiov, is_write);
9ae3a8
+    return bdrv_rwv_co(bs, sector_num, &qiov, is_write, flags);
9ae3a8
 }
9ae3a8
 
9ae3a8
 /* return < 0 if error. See bdrv_write() for the return codes */
9ae3a8
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
9ae3a8
               uint8_t *buf, int nb_sectors)
9ae3a8
 {
9ae3a8
-    return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false);
9ae3a8
+    return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false, 0);
9ae3a8
 }
9ae3a8
 
9ae3a8
 /* Just like bdrv_read(), but with I/O throttling temporarily disabled */
9ae3a8
@@ -2292,12 +2297,18 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
9ae3a8
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
9ae3a8
                const uint8_t *buf, int nb_sectors)
9ae3a8
 {
9ae3a8
-    return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true);
9ae3a8
+    return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true, 0);
9ae3a8
 }
9ae3a8
 
9ae3a8
 int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
9ae3a8
 {
9ae3a8
-    return bdrv_rwv_co(bs, sector_num, qiov, true);
9ae3a8
+    return bdrv_rwv_co(bs, sector_num, qiov, true, 0);
9ae3a8
+}
9ae3a8
+
9ae3a8
+int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
9ae3a8
+{
9ae3a8
+    return bdrv_rw_co(bs, sector_num, NULL, nb_sectors, true,
9ae3a8
+                      BDRV_REQ_ZERO_WRITE);
9ae3a8
 }
9ae3a8
 
9ae3a8
 int bdrv_pread(BlockDriverState *bs, int64_t offset,
9ae3a8
diff --git a/include/block/block.h b/include/block/block.h
9ae3a8
index 174295b..1a3ed22 100644
9ae3a8
--- a/include/block/block.h
9ae3a8
+++ b/include/block/block.h
9ae3a8
@@ -168,6 +168,8 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
9ae3a8
                           uint8_t *buf, int nb_sectors);
9ae3a8
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
9ae3a8
                const uint8_t *buf, int nb_sectors);
9ae3a8
+int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
9ae3a8
+               int nb_sectors);
9ae3a8
 int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
9ae3a8
 int bdrv_pread(BlockDriverState *bs, int64_t offset,
9ae3a8
                void *buf, int count);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8