[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 2/7] dmg: New function to help us cache random ac
From: |
Ashijeet Acharya |
Subject: |
[Qemu-block] [PATCH v2 2/7] dmg: New function to help us cache random access point |
Date: |
Thu, 27 Apr 2017 13:36:32 +0530 |
Introduce a new cache_access_point() function which will help us first
cache a random access point inside a compressed stream and then keep
updating it according to our requirement at appropriate times.
Signed-off-by: Ashijeet Acharya <address@hidden>
---
block/dmg.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/block/dmg.c b/block/dmg.c
index a7d25fc..c6fe8b0 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -128,6 +128,18 @@ static void update_max_chunk_size(BDRVDMGState *s,
uint32_t chunk,
}
}
+static void cache_access_point(DMGReadState *drs, uint8_t *next_in,
+ int64_t avail_in, int32_t chunk,
+ int64_t sectors_read, int32_t sector_offset)
+{
+ drs->saved_next_in = next_in;
+ drs->saved_avail_in = avail_in;
+ drs->saved_chunk_type = chunk;
+ drs->sectors_read = sectors_read;
+ drs->sector_offset_in_chunk = sector_offset;
+ return;
+}
+
static int64_t dmg_find_koly_offset(BdrvChild *file, Error **errp)
{
BlockDriverState *file_bs = file->bs;
@@ -507,6 +519,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options,
int flags,
goto fail;
}
+ s->drs = g_malloc(sizeof(DMGReadState));
+ /* initialise our access point cache */
+ cache_access_point(s->drs, NULL, -1, -1, -1, -1);
+
if (inflateInit(&s->zstream) != Z_OK) {
ret = -EINVAL;
goto fail;
@@ -523,6 +539,7 @@ fail:
g_free(s->lengths);
g_free(s->sectors);
g_free(s->sectorcounts);
+ g_free(s->drs);
qemu_vfree(s->compressed_chunk);
qemu_vfree(s->uncompressed_chunk);
return ret;
@@ -685,6 +702,7 @@ static void dmg_close(BlockDriverState *bs)
g_free(s->lengths);
g_free(s->sectors);
g_free(s->sectorcounts);
+ g_free(s->drs);
qemu_vfree(s->compressed_chunk);
qemu_vfree(s->uncompressed_chunk);
--
2.6.2
- [Qemu-block] [PATCH v2 0/7] Refactor DMG driver to have chunk size independence, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 1/7] dmg: Introduce a new struct to cache random access points, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 2/7] dmg: New function to help us cache random access point,
Ashijeet Acharya <=
- [Qemu-block] [PATCH v2 3/7] dmg: Refactor and prepare dmg_read_chunk() to cache random access points, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 4/7] dmg: Handle zlib compressed chunks, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 5/7] dmg: Handle bz2 compressed/raw/zeroed chunks, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 6/7] dmg: Refactor dmg_co_preadv() to start reading multiple sectors, Ashijeet Acharya, 2017/04/27
- [Qemu-block] [PATCH v2 7/7] dmg: Limit the output buffer size to a max of 2MB, Ashijeet Acharya, 2017/04/27
- Re: [Qemu-block] [PATCH v2 0/7] Refactor DMG driver to have chunk size independence, Ashijeet Acharya, 2017/04/27