From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/2] raw-posix: raw_co_get_block_status() return value
Date: Mon, 22 Sep 2014 17:36:19 +0200 [thread overview]
Message-ID: <1411400179-10605-3-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1411400179-10605-1-git-send-email-mreitz@redhat.com>
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().
Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/raw-posix.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index dd57992..be030b2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1455,12 +1455,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, int *pnum)
{
#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;
@@ -1501,8 +1501,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, int *pnum)
{
#if defined SEEK_HOLE && defined SEEK_DATA
BDRVRawState *s = bs->opaque;
@@ -1526,7 +1526,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
@@ -1553,7 +1553,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) {
@@ -1576,21 +1576,21 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
/* 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 BlockDriverAIOCB *raw_aio_discard(BlockDriverState *bs,
--
2.1.0
next prev parent reply other threads:[~2014-09-22 15:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-22 15:36 [Qemu-devel] [PATCH v2 0/2] raw-posix: Fix raw_co_get_block_status() Max Reitz
2014-09-22 15:36 ` [Qemu-devel] [PATCH v2 1/2] raw-posix: Fix raw_co_get_block_status() after EOF Max Reitz
2014-10-09 4:13 ` Eric Blake
2014-10-16 8:30 ` Kevin Wolf
2014-09-22 15:36 ` Max Reitz [this message]
2014-10-09 4:16 ` [Qemu-devel] [PATCH v2 2/2] raw-posix: raw_co_get_block_status() return value Eric Blake
2014-10-08 19:43 ` [Qemu-devel] [PATCH v2 0/2] raw-posix: Fix raw_co_get_block_status() Max Reitz
2014-10-09 18:58 ` Benoît Canet
2014-10-11 8:55 ` Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411400179-10605-3-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).