958e1b
From 89ef5998670954140a6e605f6a5e6286ee3a5eb2 Mon Sep 17 00:00:00 2001
09b1b5
From: Max Reitz <mreitz@redhat.com>
09b1b5
Date: Tue, 18 Nov 2014 15:30:18 +0100
958e1b
Subject: [PATCH 39/41] raw-posix: raw_co_get_block_status() return value
09b1b5
09b1b5
Message-id: <1416324620-16229-6-git-send-email-mreitz@redhat.com>
09b1b5
Patchwork-id: 62440
09b1b5
O-Subject: [RHEL-7.1/7.0.z qemu-kvm PATCH v3 5/7] raw-posix: raw_co_get_block_status() return value
958e1b
Bugzilla: 1160237
09b1b5
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
09b1b5
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
09b1b5
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
09b1b5
09b1b5
Instead of generating the full return value thrice in try_fiemap(),
09b1b5
try_seek_hole() and as a fall-back in raw_co_get_block_status() itself,
09b1b5
generate the value only in raw_co_get_block_status().
09b1b5
09b1b5
While at it, also remove the pnum parameter from try_fiemap() and
09b1b5
try_seek_hole().
09b1b5
09b1b5
Suggested-by: Kevin Wolf <kwolf@redhat.com>
09b1b5
Signed-off-by: Max Reitz <mreitz@redhat.com>
09b1b5
Reviewed-by: Eric Blake <eblake@redhat.com>
09b1b5
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
09b1b5
Message-id: 1414148280-17949-3-git-send-email-mreitz@redhat.com
09b1b5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
09b1b5
(cherry picked from commit d7f62751a14d1d34c7d388431a3e403ef1fe28a5)
09b1b5
09b1b5
Signed-off-by: Max Reitz <mreitz@redhat.com>
09b1b5
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
09b1b5
---
09b1b5
 block/raw-posix.c | 28 ++++++++++++++--------------
09b1b5
 1 file changed, 14 insertions(+), 14 deletions(-)
09b1b5
09b1b5
diff --git a/block/raw-posix.c b/block/raw-posix.c
958e1b
index 75a81b1..a46e50b 100644
09b1b5
--- a/block/raw-posix.c
09b1b5
+++ b/block/raw-posix.c
958e1b
@@ -1308,12 +1308,12 @@ out:
09b1b5
     return result;
09b1b5
 }
09b1b5
 
09b1b5
-static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
-                          off_t *hole, int nb_sectors, int *pnum)
09b1b5
+static int try_fiemap(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
+                      off_t *hole, int nb_sectors)
09b1b5
 {
09b1b5
 #ifdef CONFIG_FIEMAP
09b1b5
     BDRVRawState *s = bs->opaque;
09b1b5
-    int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
09b1b5
+    int ret = 0;
09b1b5
     struct {
09b1b5
         struct fiemap fm;
09b1b5
         struct fiemap_extent fe;
958e1b
@@ -1354,8 +1354,8 @@ static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
 #endif
09b1b5
 }
09b1b5
 
09b1b5
-static int64_t try_seek_hole(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
-                             off_t *hole, int *pnum)
09b1b5
+static int try_seek_hole(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
+                         off_t *hole)
09b1b5
 {
09b1b5
 #if defined SEEK_HOLE && defined SEEK_DATA
09b1b5
     BDRVRawState *s = bs->opaque;
958e1b
@@ -1375,7 +1375,7 @@ static int64_t try_seek_hole(BlockDriverState *bs, off_t start, off_t *data,
09b1b5
         }
09b1b5
     }
09b1b5
 
09b1b5
-    return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
09b1b5
+    return 0;
09b1b5
 #else
09b1b5
     return -ENOTSUP;
09b1b5
 #endif
958e1b
@@ -1402,7 +1402,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
09b1b5
 {
09b1b5
     off_t start, data = 0, hole = 0;
09b1b5
     int64_t total_size;
09b1b5
-    int64_t ret;
09b1b5
+    int ret;
09b1b5
 
09b1b5
     ret = fd_open(bs);
09b1b5
     if (ret < 0) {
958e1b
@@ -1420,28 +1420,28 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
09b1b5
         nb_sectors = DIV_ROUND_UP(total_size - start, BDRV_SECTOR_SIZE);
09b1b5
     }
09b1b5
 
09b1b5
-    ret = try_seek_hole(bs, start, &data, &hole, pnum);
09b1b5
+    ret = try_seek_hole(bs, start, &data, &hole);
09b1b5
     if (ret < 0) {
09b1b5
-        ret = try_fiemap(bs, start, &data, &hole, nb_sectors, pnum);
09b1b5
+        ret = try_fiemap(bs, start, &data, &hole, nb_sectors);
09b1b5
         if (ret < 0) {
09b1b5
             /* Assume everything is allocated. */
09b1b5
             data = 0;
09b1b5
             hole = start + nb_sectors * BDRV_SECTOR_SIZE;
09b1b5
-            ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
09b1b5
+            ret = 0;
09b1b5
         }
09b1b5
     }
09b1b5
 
09b1b5
+    assert(ret >= 0);
09b1b5
+
09b1b5
     if (data <= start) {
09b1b5
         /* On a data extent, compute sectors to the end of the extent.  */
09b1b5
         *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
09b1b5
+        return ret | BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
09b1b5
     } else {
09b1b5
         /* On a hole, compute sectors to the beginning of the next extent.  */
09b1b5
         *pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE);
09b1b5
-        ret &= ~BDRV_BLOCK_DATA;
09b1b5
-        ret |= BDRV_BLOCK_ZERO;
09b1b5
+        return ret | BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID | start;
09b1b5
     }
09b1b5
-
09b1b5
-    return ret;
09b1b5
 }
09b1b5
 
09b1b5
 static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,
09b1b5
-- 
09b1b5
1.8.3.1
09b1b5