We do not need to cache the access point for these chunks but need to update our various supporting variables like chunk, sectors_read etc. to keep maintaining our code structure. Call cache_access_point() after reading chunks of these types.
Signed-off-by: Ashijeet Acharya <ashijeetacha...@gmail.com> --- block/dmg.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 073e864..f9045f9 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -680,20 +680,30 @@ update: (char *)s->uncompressed_chunk, (unsigned int) (512 * s->sectorcounts[chunk])); + if (ret < 0) { return ret; } + cache_access_point(drs, NULL, -1, chunk, sectors_read, + sector_offset); break; case 1: /* copy */ - ret = bdrv_pread(bs->file, s->offsets[chunk], - s->uncompressed_chunk, s->lengths[chunk]); - if (ret != s->lengths[chunk]) { - return -1; + if (drs->sectors_read == -1) { + ret = bdrv_pread(bs->file, s->offsets[chunk], + s->uncompressed_chunk, s->lengths[chunk]); + if (ret != s->lengths[chunk]) { + return -1; + } } + cache_access_point(drs, NULL, -1, chunk, sectors_read, + sector_offset); break; case 2: /* zero */ /* see dmg_read, it is treated specially. No buffer needs to be * pre-filled, the zeroes can be set directly. */ + cache_access_point(drs, NULL, -1, chunk, sectors_read, + sector_offset); + break; } s->current_chunk = chunk; -- 2.6.2