[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 4/7] dmg: Handle zlib compressed chunks
From: |
Ashijeet Acharya |
Subject: |
[Qemu-block] [PATCH v2 4/7] dmg: Handle zlib compressed chunks |
Date: |
Thu, 27 Apr 2017 13:36:34 +0530 |
Set the output buffer size to be equal to the size of number of sectors
stored in @sectors_read. Start inflating to a max output buffer size of
2MB and cache our access point to aid random access later if required.
Signed-off-by: Ashijeet Acharya <address@hidden>
---
block/dmg.c | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/block/dmg.c b/block/dmg.c
index 32623e2..073e864 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -621,27 +621,47 @@ static inline int dmg_read_chunk(BlockDriverState *bs,
uint64_t sector_num,
switch (s->types[chunk]) { /* block entry type */
case 0x80000005: { /* zlib compressed */
- /* we need to buffer, because only the chunk as whole can be
- * inflated. */
- ret = bdrv_pread(bs->file, s->offsets[chunk],
- s->compressed_chunk, s->lengths[chunk]);
- if (ret != s->lengths[chunk]) {
- return -1;
+ /* check for cached random access point */
+ if (drs->saved_next_in == NULL) {
+ /* we need to buffer, because only the chunk as whole can be
+ * inflated. */
+ ret = bdrv_pread(bs->file, s->offsets[chunk],
+ s->compressed_chunk, s->lengths[chunk]);
+ if (ret != s->lengths[chunk]) {
+ return -1;
+ }
+
+ s->zstream.next_in = s->compressed_chunk;
+ s->zstream.avail_in = s->lengths[chunk];
+ } else {
+ s->zstream.next_in = drs->saved_next_in;
+ s->zstream.avail_in = drs->saved_avail_in;
}
- s->zstream.next_in = s->compressed_chunk;
- s->zstream.avail_in = s->lengths[chunk];
s->zstream.next_out = s->uncompressed_chunk;
- s->zstream.avail_out = 512 * s->sectorcounts[chunk];
- ret = inflateReset(&s->zstream);
- if (ret != Z_OK) {
- return -1;
+
+ s->zstream.avail_out = sectors_read * BDRV_SECTOR_SIZE;
+
+ if (drs->saved_next_in == NULL) {
+ ret = inflateReset(&s->zstream);
+ if (ret != Z_OK) {
+ return -1;
+ }
+ }
+ /* reset total_out for each successive call */
+ s->zstream.total_out = 0;
+ ret = inflate(&s->zstream, Z_SYNC_FLUSH);
+ if (ret == Z_OK &&
+ s->zstream.total_out == 512 * sectors_read) {
+ goto update;
}
- ret = inflate(&s->zstream, Z_FINISH);
if (ret != Z_STREAM_END ||
- s->zstream.total_out != 512 * s->sectorcounts[chunk]) {
+ s->zstream.total_out != 512 * sectors_read) {
return -1;
}
+update:
+ cache_access_point(drs, s->zstream.next_in, s->zstream.avail_in,
+ chunk, sectors_read, sector_offset);
break; }
case 0x80000006: /* bzip2 compressed */
if (!dmg_uncompress_bz2) {
--
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, 2017/04/27
- [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 <=
- [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