9ae3a8
From 145376957366516a0b47f4a83d93b6c0c026e469 Mon Sep 17 00:00:00 2001
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Date: Fri, 18 Oct 2013 08:14:44 +0200
9ae3a8
Subject: [PATCH 19/81] raw-posix: return get_block_status data and flags
9ae3a8
9ae3a8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: <1382084091-16636-20-git-send-email-pbonzini@redhat.com>
9ae3a8
Patchwork-id: 55002
9ae3a8
O-Subject: [RHEL 7.0 qemu-kvm PATCH 19/26] raw-posix: return get_block_status data and flags
9ae3a8
Bugzilla: 989646
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
(cherry picked from commit 63390a8d14c9006f42bdaab22291c9c97676322d)
9ae3a8
---
9ae3a8
 block/raw-posix.c | 17 ++++++++++-------
9ae3a8
 1 file changed, 10 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/raw-posix.c |   17 ++++++++++-------
9ae3a8
 1 files changed, 10 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/raw-posix.c b/block/raw-posix.c
9ae3a8
index 9a7c5a8..a829ce0 100644
9ae3a8
--- a/block/raw-posix.c
9ae3a8
+++ b/block/raw-posix.c
9ae3a8
@@ -1089,7 +1089,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
9ae3a8
                                             int nb_sectors, int *pnum)
9ae3a8
 {
9ae3a8
     off_t start, data, hole;
9ae3a8
-    int ret;
9ae3a8
+    int64_t ret;
9ae3a8
 
9ae3a8
     ret = fd_open(bs);
9ae3a8
     if (ret < 0) {
9ae3a8
@@ -1097,6 +1097,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
9ae3a8
     }
9ae3a8
 
9ae3a8
     start = sector_num * BDRV_SECTOR_SIZE;
9ae3a8
+    ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
9ae3a8
 
9ae3a8
 #ifdef CONFIG_FIEMAP
9ae3a8
 
9ae3a8
@@ -1114,7 +1115,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
9ae3a8
     if (ioctl(s->fd, FS_IOC_FIEMAP, &f) == -1) {
9ae3a8
         /* Assume everything is allocated.  */
9ae3a8
         *pnum = nb_sectors;
9ae3a8
-        return 1;
9ae3a8
+        return ret;
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (f.fm.fm_mapped_extents == 0) {
9ae3a8
@@ -1141,7 +1142,7 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
9ae3a8
 
9ae3a8
         /* Most likely EINVAL.  Assume everything is allocated.  */
9ae3a8
         *pnum = nb_sectors;
9ae3a8
-        return 1;
9ae3a8
+        return ret;
9ae3a8
     }
9ae3a8
 
9ae3a8
     if (hole > start) {
9ae3a8
@@ -1154,19 +1155,21 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
9ae3a8
         }
9ae3a8
     }
9ae3a8
 #else
9ae3a8
-    *pnum = nb_sectors;
9ae3a8
-    return 1;
9ae3a8
+    data = 0;
9ae3a8
+    hole = start + nb_sectors * BDRV_SECTOR_SIZE;
9ae3a8
 #endif
9ae3a8
 
9ae3a8
     if (data <= start) {
9ae3a8
         /* On a data extent, compute sectors to the end of the extent.  */
9ae3a8
         *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
9ae3a8
-        return 1;
9ae3a8
     } else {
9ae3a8
         /* On a hole, compute sectors to the beginning of the next extent.  */
9ae3a8
         *pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE);
9ae3a8
-        return 0;
9ae3a8
+        ret &= ~BDRV_BLOCK_DATA;
9ae3a8
+        ret |= BDRV_BLOCK_ZERO;
9ae3a8
     }
9ae3a8
+
9ae3a8
+    return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static coroutine_fn BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8