From patchwork Thu Apr 27 08:06:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 755869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wD8mV61SVz9s75 for ; Thu, 27 Apr 2017 18:11:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VeDYM9JD"; dkim-atps=neutral Received: from localhost ([::1]:59317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3eWW-0007mq-Bg for incoming@patchwork.ozlabs.org; Thu, 27 Apr 2017 04:11:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3eRJ-0003G3-2G for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3eRI-0008Cz-2n for qemu-devel@nongnu.org; Thu, 27 Apr 2017 04:06:13 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:36571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3eRH-0008BX-Sp; Thu, 27 Apr 2017 04:06:12 -0400 Received: by mail-pf0-x242.google.com with SMTP id v14so7445428pfd.3; Thu, 27 Apr 2017 01:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vKRWlpiWK/pGAzUMPnNXBO77u7wg9oKIRckfGdnlhB4=; b=VeDYM9JDkdmFavM5IjIVZ0y2nWWHjMlNf9VVKO3Gf4vjIVxaLi1Iq+k0D0M8/f2F3p lCbze536AglLXn33kaWUTO9UtW5evJY70rAommcUbA9Eb7wizEOJ45j7TYcqTTtdZ7sU m8OIeDdIecdCDAjGf1oAF3rSAxtRlrsoWt16uTVZ7dLXG7xvuLv6DScwJ/oDjN8jHxT+ 0Cqp6vCREx99L5hWNEbF9RjWWdr6UjNc2YTuJOwNm4fsiaS4RXJDOTmcbthnXhEnxsEB TiONiNDpW/F5kQZ5n4kwvutadtbJIf0yB4UVE7i7XQB8WhGIyWwc9cdKMgBCDz3nIS7p TOgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vKRWlpiWK/pGAzUMPnNXBO77u7wg9oKIRckfGdnlhB4=; b=FD5Jd0WY3qyG35sr0L+iT/vR4wqkBM1GeGxePwSN9VvTYmNDMk2iGI9HqXIdh469KI 1ZfWPSz/afA2sRYitvylH4+fid9zd8y1Nz/eOF6RP3O2alqwCfBtzYg5HDf3GwtZncd3 EQSc54Hj16CINmLeNiviQjtKEcYIHDPJiDXjY86YRqcTvpmt/r0Z+VWues6TZaDJg8AZ vQqLHSEgKgnLuSBeIMJG7s4LsS3JRzcLPrZtcV4ij8LSU6KeENuv/bbAzAvBJG5uUMbq 3FuK2vU7fwR/usjGE3RKqvm97Whq1J3qZrdmi6KZCiuub/HXr6gXrE93Q3ichODVVcIY XVqA== X-Gm-Message-State: AN3rC/4v1H6kmRDOW1THRH7DSrWeq1tt4ibL9to5z2GPHc38krcEBKFI 6OSjAYMT8edjXA== X-Received: by 10.84.247.9 with SMTP id n9mr5303447pll.119.1493280371074; Thu, 27 Apr 2017 01:06:11 -0700 (PDT) Received: from linux.local ([157.51.104.251]) by smtp.gmail.com with ESMTPSA id 12sm3295277pgb.35.2017.04.27.01.06.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 01:06:10 -0700 (PDT) From: Ashijeet Acharya To: stefanha@gmail.com Date: Thu, 27 Apr 2017 13:36:32 +0530 Message-Id: <1493280397-9622-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> References: <1493280397-9622-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH v2 2/7] dmg: New function to help us cache random access point X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, peter@lekensteyn.nl, Ashijeet Acharya , jsnow@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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);