[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/16] block/parallels: read up to cluster end in on
From: |
Denis V. Lunev |
Subject: |
[Qemu-devel] [PATCH 09/16] block/parallels: read up to cluster end in one go |
Date: |
Mon, 15 Dec 2014 11:27:54 +0300 |
From: Roman Kagan <address@hidden>
Teach parallels_read() to do reads in coarser granularity than just a
single sector: if requested, read up the cluster end in one go.
Signed-off-by: Roman Kagan <address@hidden>
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Jeff Cody <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
---
block/parallels.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index de4f39f..a05bf39 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -377,6 +377,13 @@ static int64_t seek_to_sector(BDRVParallelsState *s,
int64_t sector_num)
return (uint64_t)s->catalog_bitmap[index] * s->off_multiplier + offset;
}
+static int cluster_remainder(BDRVParallelsState *s, int64_t sector_num,
+ int nb_sectors)
+{
+ int ret = s->tracks - sector_num % s->tracks;
+ return MIN(nb_sectors, ret);
+}
+
static int parallels_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
{
@@ -386,17 +393,18 @@ static int parallels_read(BlockDriverState *bs, int64_t
sector_num,
while (nb_sectors > 0) {
int64_t position = seek_to_sector(s, sector_num);
+ int n = cluster_remainder(s, sector_num, nb_sectors);
if (position >= 0) {
- int ret = bdrv_read(bs->file, position, buf, 1);
+ int ret = bdrv_read(bs->file, position, buf, n);
if (ret < 0) {
return ret;
}
} else {
- memset(buf, 0, BDRV_SECTOR_SIZE);
+ memset(buf, 0, n << BDRV_SECTOR_BITS);
}
- nb_sectors--;
- sector_num++;
- buf += BDRV_SECTOR_SIZE;
+ nb_sectors -= n;
+ sector_num += n;
+ buf += n << BDRV_SECTOR_BITS;
}
return 0;
}
--
1.9.1
- [Qemu-devel] [PATCH 14/16] block/parallels: introduce ParallelsSnapshot data structure, (continued)
- [Qemu-devel] [PATCH 14/16] block/parallels: introduce ParallelsSnapshot data structure, Denis V. Lunev, 2014/12/15
- [Qemu-devel] [PATCH 11/16] block/parallels: add support for backing files, Denis V. Lunev, 2014/12/15
- [Qemu-devel] [PATCH 10/16] block/parallels: add get_block_status, Denis V. Lunev, 2014/12/15
- [Qemu-devel] [PATCH 09/16] block/parallels: read up to cluster end in one go,
Denis V. Lunev <=
- [Qemu-devel] [PATCH 12/16] iotests: testcase for backing in parallels format, Denis V. Lunev, 2014/12/15
- [Qemu-devel] [PATCH 08/16] block/parallels: switch to bdrv_read, Denis V. Lunev, 2014/12/15
- [Qemu-devel] [PATCH 01/16] configure: add dependency from libxml2, Denis V. Lunev, 2014/12/15