[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 19/53] raw-posix: raw_co_get_block_status() return va
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 19/53] raw-posix: raw_co_get_block_status() return value |
Date: |
Mon, 3 Nov 2014 11:50:22 +0000 |
From: Max Reitz <address@hidden>
Instead of generating the full return value thrice in try_fiemap(),
try_seek_hole() and as a fall-back in raw_co_get_block_status() itself,
generate the value only in raw_co_get_block_status().
While at it, also remove the pnum parameter from try_fiemap() and
try_seek_hole().
Suggested-by: Kevin Wolf <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block/raw-posix.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index a86b784..e100ae2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1481,12 +1481,12 @@ out:
return result;
}
-static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data,
- off_t *hole, int nb_sectors, int *pnum)
+static int try_fiemap(BlockDriverState *bs, off_t start, off_t *data,
+ off_t *hole, int nb_sectors)
{
#ifdef CONFIG_FIEMAP
BDRVRawState *s = bs->opaque;
- int64_t ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
+ int ret = 0;
struct {
struct fiemap fm;
struct fiemap_extent fe;
@@ -1527,8 +1527,8 @@ static int64_t try_fiemap(BlockDriverState *bs, off_t
start, off_t *data,
#endif
}
-static int64_t try_seek_hole(BlockDriverState *bs, off_t start, off_t *data,
- off_t *hole, int *pnum)
+static int try_seek_hole(BlockDriverState *bs, off_t start, off_t *data,
+ off_t *hole)
{
#if defined SEEK_HOLE && defined SEEK_DATA
BDRVRawState *s = bs->opaque;
@@ -1548,7 +1548,7 @@ static int64_t try_seek_hole(BlockDriverState *bs, off_t
start, off_t *data,
}
}
- return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
+ return 0;
#else
return -ENOTSUP;
#endif
@@ -1575,7 +1575,7 @@ static int64_t coroutine_fn
raw_co_get_block_status(BlockDriverState *bs,
{
off_t start, data = 0, hole = 0;
int64_t total_size;
- int64_t ret;
+ int ret;
ret = fd_open(bs);
if (ret < 0) {
@@ -1593,28 +1593,28 @@ static int64_t coroutine_fn
raw_co_get_block_status(BlockDriverState *bs,
nb_sectors = DIV_ROUND_UP(total_size - start, BDRV_SECTOR_SIZE);
}
- ret = try_seek_hole(bs, start, &data, &hole, pnum);
+ ret = try_seek_hole(bs, start, &data, &hole);
if (ret < 0) {
- ret = try_fiemap(bs, start, &data, &hole, nb_sectors, pnum);
+ ret = try_fiemap(bs, start, &data, &hole, nb_sectors);
if (ret < 0) {
/* Assume everything is allocated. */
data = 0;
hole = start + nb_sectors * BDRV_SECTOR_SIZE;
- ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
+ ret = 0;
}
}
+ assert(ret >= 0);
+
if (data <= start) {
/* On a data extent, compute sectors to the end of the extent. */
*pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
+ return ret | BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
} else {
/* On a hole, compute sectors to the beginning of the next extent. */
*pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE);
- ret &= ~BDRV_BLOCK_DATA;
- ret |= BDRV_BLOCK_ZERO;
+ return ret | BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID | start;
}
-
- return ret;
}
static coroutine_fn BlockAIOCB *raw_aio_discard(BlockDriverState *bs,
--
1.9.3
- [Qemu-devel] [PULL 09/53] ahci: Fix SDB FIS Construction, (continued)
- [Qemu-devel] [PULL 09/53] ahci: Fix SDB FIS Construction, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 10/53] snapshot: Reset err to NULL to avoid double free, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 11/53] iotests: replace fake parallels image with authentic one, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 12/53] iotests: add v2 parallels sample image and simple test for it, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 13/53] block/parallels: fix access to not initialized memory in catalog_bitmap, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 14/53] rbd: Add support for bdrv_invalidate_cache, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 15/53] block.c: Fix type of IoOperationType variable in send_qmp_error_event(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 17/53] block/curl: Improve type safety of s->timeout., Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 16/53] snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 18/53] raw-posix: Fix raw_co_get_block_status() after EOF, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 19/53] raw-posix: raw_co_get_block_status() return value,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 20/53] iotests: Add test for external image truncation, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 21/53] qcow2: Allow "full" discard, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 23/53] qcow2: Optimize bdrv_make_empty(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 24/53] blockjob: Introduce block_job_complete_sync(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 26/53] iotests: Omit length/offset test in 040 and 041, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 25/53] blockjob: Add "ready" field, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 27/53] block/mirror: Improve progress report, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 28/53] qemu-img: Implement commit like QMP, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 29/53] qemu-img: Empty image after commit, Stefan Hajnoczi, 2014/11/03