From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, carnold@suse.com, jcody@redhat.com,
Peter Lieven <pl@kamp.de>,
mreitz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 2/5] block/vpc: simplify vpc_read
Date: Mon, 23 Feb 2015 15:27:38 +0100 [thread overview]
Message-ID: <1424701661-21241-3-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1424701661-21241-1-git-send-email-pl@kamp.de>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
block/vpc.c | 116 +++++++++++++++++++++++++++--------------------------------
1 file changed, 52 insertions(+), 64 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 326c2bb..4e5ba85 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -497,40 +497,70 @@ static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
-static int vpc_read(BlockDriverState *bs, int64_t sector_num,
- uint8_t *buf, int nb_sectors)
+static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, int *pnum)
{
BDRVVPCState *s = bs->opaque;
- int ret;
- int64_t offset;
- int64_t sectors, sectors_per_block;
- VHDFooter *footer = (VHDFooter *) s->footer_buf;
+ VHDFooter *footer = (VHDFooter*) s->footer_buf;
+ int64_t start, offset;
+ bool allocated;
+ int n;
if (be32_to_cpu(footer->type) == VHD_FIXED) {
- return bdrv_read(bs->file, sector_num, buf, nb_sectors);
+ *pnum = nb_sectors;
+ return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
+ (sector_num << BDRV_SECTOR_BITS);
}
- while (nb_sectors > 0) {
- offset = get_sector_offset(bs, sector_num, 0);
- sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;
- sectors = sectors_per_block - (sector_num % sectors_per_block);
- if (sectors > nb_sectors) {
- sectors = nb_sectors;
+ offset = get_sector_offset(bs, sector_num, 0);
+ start = offset;
+ allocated = (offset != -1);
+ *pnum = 0;
+
+ do {
+ /* All sectors in a block are contiguous (without using the bitmap) */
+ n = ROUND_UP(sector_num + 1, s->block_size / BDRV_SECTOR_SIZE)
+ - sector_num;
+ n = MIN(n, nb_sectors);
+
+ *pnum += n;
+ sector_num += n;
+ nb_sectors -= n;
+
+ if (allocated) {
+ return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
}
+ if (nb_sectors == 0) {
+ break;
+ }
+ offset = get_sector_offset(bs, sector_num, 0);
+ } while (offset == -1);
- if (offset == -1) {
- memset(buf, 0, sectors * BDRV_SECTOR_SIZE);
- } else {
- ret = bdrv_pread(bs->file, offset, buf,
- sectors * BDRV_SECTOR_SIZE);
- if (ret != sectors * BDRV_SECTOR_SIZE) {
+ return 0;
+}
+
+static int vpc_read(BlockDriverState *bs, int64_t sector_num,
+ uint8_t *buf, int nb_sectors)
+{
+ int ret, n;
+ int64_t ret2;
+
+ while (nb_sectors > 0) {
+ ret2 = vpc_co_get_block_status(bs, sector_num, nb_sectors, &n);
+
+ if (ret2 & BDRV_BLOCK_OFFSET_VALID) {
+ ret = bdrv_pread(bs->file, ret2 & BDRV_SECTOR_MASK, buf,
+ n * BDRV_SECTOR_SIZE);
+ if (ret != n * BDRV_SECTOR_SIZE) {
return -1;
}
+ } else {
+ memset(buf, 0x00, n * BDRV_SECTOR_SIZE);
}
- nb_sectors -= sectors;
- sector_num += sectors;
- buf += sectors * BDRV_SECTOR_SIZE;
+ sector_num += n;
+ nb_sectors -= n;
+ buf += n * BDRV_SECTOR_SIZE;
}
return 0;
}
@@ -597,48 +627,6 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num,
return ret;
}
-static int64_t coroutine_fn vpc_co_get_block_status(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors, int *pnum)
-{
- BDRVVPCState *s = bs->opaque;
- VHDFooter *footer = (VHDFooter*) s->footer_buf;
- int64_t start, offset;
- bool allocated;
- int n;
-
- if (be32_to_cpu(footer->type) == VHD_FIXED) {
- *pnum = nb_sectors;
- return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
- (sector_num << BDRV_SECTOR_BITS);
- }
-
- offset = get_sector_offset(bs, sector_num, 0);
- start = offset;
- allocated = (offset != -1);
- *pnum = 0;
-
- do {
- /* All sectors in a block are contiguous (without using the bitmap) */
- n = ROUND_UP(sector_num + 1, s->block_size / BDRV_SECTOR_SIZE)
- - sector_num;
- n = MIN(n, nb_sectors);
-
- *pnum += n;
- sector_num += n;
- nb_sectors -= n;
-
- if (allocated) {
- return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
- }
- if (nb_sectors == 0) {
- break;
- }
- offset = get_sector_offset(bs, sector_num, 0);
- } while (offset == -1);
-
- return 0;
-}
-
/*
* Calculates the number of cylinders, heads and sectors per cylinder
* based on a given number of sectors. This is the algorithm described
--
1.7.9.5
next prev parent reply other threads:[~2015-02-23 14:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 14:27 [Qemu-devel] [PATCH 0/5] block/vpc optimizations Peter Lieven
2015-02-23 14:27 ` [Qemu-devel] [PATCH 1/5] block/vpc: optimize vpc_co_get_block_status Peter Lieven
2015-02-23 18:08 ` Max Reitz
2015-02-24 6:41 ` Peter Lieven
2015-02-23 14:27 ` Peter Lieven [this message]
2015-02-23 18:29 ` [Qemu-devel] [PATCH 2/5] block/vpc: simplify vpc_read Max Reitz
2015-02-24 6:44 ` Peter Lieven
2015-02-24 14:09 ` Max Reitz
2015-02-23 14:27 ` [Qemu-devel] [PATCH 3/5] vpc: Ignore geometry for large images Peter Lieven
2015-02-23 18:34 ` Max Reitz
2015-02-24 6:45 ` Peter Lieven
2015-02-24 14:12 ` Max Reitz
2015-02-23 14:27 ` [Qemu-devel] [PATCH 4/5] block/vpc: make calculate_geometry spec conform Peter Lieven
2015-02-23 18:59 ` Max Reitz
2015-02-24 6:49 ` Peter Lieven
2015-02-24 14:14 ` Max Reitz
2015-02-23 14:27 ` [Qemu-devel] [PATCH 5/5] block/vpc: rename footer->size -> footer->current_size Peter Lieven
2015-02-23 19:04 ` 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=1424701661-21241-3-git-send-email-pl@kamp.de \
--to=pl@kamp.de \
--cc=carnold@suse.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@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).