From patchwork Tue Apr 25 19:59:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9699555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ADC5060245 for ; Tue, 25 Apr 2017 20:01:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D34B28674 for ; Tue, 25 Apr 2017 20:01:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9087928676; Tue, 25 Apr 2017 20:01:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A7BC28674 for ; Tue, 25 Apr 2017 20:01:12 +0000 (UTC) Received: from localhost ([::1]:51176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d36e7-0007Vv-Fh for patchwork-qemu-devel@patchwork.kernel.org; Tue, 25 Apr 2017 16:01:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52525) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d36c2-0006re-Rl for qemu-devel@nongnu.org; Tue, 25 Apr 2017 15:59:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d36bz-0003x9-Nt for qemu-devel@nongnu.org; Tue, 25 Apr 2017 15:59:02 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34375) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d36bz-0003x5-IX; Tue, 25 Apr 2017 15:58:59 -0400 Received: by mail-pg0-x243.google.com with SMTP id t7so9745156pgt.1; Tue, 25 Apr 2017 12:58:59 -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=Jw2OL/rYJTcCNEOV8CnxmIeECTs5yGEQamrvjP47fnGC8ie3Ma5wd5Mg9CX5FVoYTx 8O/E/9czXDQYq+EGK4qClSDrFQezLJqIyCMKCSpnowzmiYuhgYU49syNBmjsAqziETGI PvgHLCPkCY1HWBQN8y4DxO/7rzq+se10+sQXY8F0BSY8AbYOIjSLT82IwBOBtUb9YWGC i6vwUglgGSoRwEkBd3TDCWjta7kKeiEyK4UZffFWlZeh1b20j1M9HDQ+D0UUQGI1mS1X eYMlfahgmshGbbInBcUOcDQzMdeiVU8IoFsffYmDZITGuvdqYkoBKYm4OJ95hs2nLQaB 39XQ== 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=oSBnOFXtb1XIkS0iYtnmKEP9qObybQycxYJmLy2C7gO/yyMIy395+jpYN9fcQ+Lvmg ZVr9JJCPltcbfXDyz+AckkVXZQRzaBpKbDTzO7IPWx4AhSZMmrymyKQPMTEpIwLQF6+f WT0XBaaTzpQ/tp51KHciYzx7i/O/R3CeemwTEhIFAwLX/JPVsQTNmksxGkHR+/8IcPIl 3kfsiuQNt/jGhsJ1FY84wp57NpTVekMjaxlTTRQjyFRRY7MaU3MW5kfayzJgXSQUXQ2y 8CKsJrSkRqUY1xBINaqCqVY65Qs8eq7pyGfBQkKhDCmTUCD8heKdjj94wMDRhtF5tntV OJbA== X-Gm-Message-State: AN3rC/7DvIf4yRKktjvi2Jd4hV9JHMXvFdev+OoKBdrrKEvcySg70gzV ByYpGDttWrboIw== X-Received: by 10.98.35.10 with SMTP id j10mr29917781pfj.23.1493150338582; Tue, 25 Apr 2017 12:58:58 -0700 (PDT) Received: from linux.local ([157.51.23.94]) by smtp.gmail.com with ESMTPSA id y187sm37931530pfy.67.2017.04.25.12.58.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 12:58:58 -0700 (PDT) From: Ashijeet Acharya To: stefanha@gmail.com Date: Wed, 26 Apr 2017 01:29:05 +0530 Message-Id: <1493150351-28918-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1493150351-28918-1-git-send-email-ashijeetacharya@gmail.com> References: <1493150351-28918-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v1 2/8] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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);