From patchwork Fri Jul 29 04:49:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Nakamura X-Patchwork-Id: 107346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4E5ABB6F68 for ; Fri, 29 Jul 2011 15:43:53 +1000 (EST) Received: from localhost ([::1]:37648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf37-0004dX-0A for incoming@patchwork.ozlabs.org; Fri, 29 Jul 2011 00:51:49 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf1z-0002Lk-Ic for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qmf1y-0000SQ-HZ for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:39 -0400 Received: from mail-gx0-f173.google.com ([209.85.161.173]:60112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf1y-0000SM-DM for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:38 -0400 Received: by gxk26 with SMTP id 26so2772269gxk.4 for ; Thu, 28 Jul 2011 21:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=oJorwhwocyLJMGw5iZoT0P6+qpIc39sg7g8xuCgBtUE=; b=HwCRLfZtonSy62vgF0+tYKpV+K4moNtXfeTN/tjJnklvUxkPxkKrShuscHvN/bStBs 65V1OTS7BEY2jZQCDL8EOHGVGCukmcxmxUzGT3pQw37q7ZWiQr8gtuBquoDWencQcyR3 KemqwkjkgZRett8IWHE+0RZwtDHP96I354goI= Received: by 10.42.145.71 with SMTP id e7mr672171icv.150.1311915037492; Thu, 28 Jul 2011 21:50:37 -0700 (PDT) Received: from localhost.localdomain (d72-39-252-38.home1.cgocable.net [72.39.252.38]) by mx.google.com with ESMTPS id v16sm1109424ibf.25.2011.07.28.21.50.36 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jul 2011 21:50:36 -0700 (PDT) From: Devin Nakamura To: qemu-devel@nongnu.org Date: Fri, 29 Jul 2011 00:49:47 -0400 Message-Id: <1311914994-20482-18-git-send-email-devin122@gmail.com> X-Mailer: git-send-email 1.7.6.rc1 In-Reply-To: <1311914994-20482-1-git-send-email-devin122@gmail.com> References: <1311914994-20482-1-git-send-email-devin122@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.173 Cc: kwolf@redhat.com, Devin Nakamura Subject: [Qemu-devel] [RFC 17/24] qcow2: add qcow2_get_mapping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Devin Nakamura --- block/qcow2.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 48e1b95..05ea40c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1340,6 +1340,40 @@ static int qcow2_load_vmstate(BlockDriverState *bs, uint8_t *buf, return ret; } +static int qcow2_get_mapping(BlockDriverState *bs, uint64_t *guest_offset, + uint64_t *host_offset, uint64_t *contiguous_bytes) +{ + uint64_t cluster_offset, pos; + //BDRVQcowState *s = bs->opaque; + int ret, count; + pos = *guest_offset + *contiguous_bytes; + + if (pos >= bs->total_sectors << BDRV_SECTOR_BITS) { + *contiguous_bytes = 0; + return 0; + } + count = 0; + do { + pos += count << BDRV_SECTOR_BITS; + count = INT_MAX; + ret = qcow2_get_cluster_offset(bs, pos, &count, &cluster_offset); + if (ret) { + *contiguous_bytes = 0; + return ret; + } + } while (!cluster_offset && pos < bs->total_sectors * BDRV_SECTOR_SIZE); + + if (pos >= bs->total_sectors << BDRV_SECTOR_BITS || !cluster_offset) { + *contiguous_bytes = 0; + return 0; + } + + *contiguous_bytes = count << BDRV_SECTOR_BITS; + *guest_offset = pos; + *host_offset = cluster_offset; + return 0; +} + static QEMUOptionParameter qcow2_create_options[] = { { .name = BLOCK_OPT_SIZE, @@ -1409,6 +1443,8 @@ static BlockDriver bdrv_qcow2 = { .create_options = qcow2_create_options, .bdrv_check = qcow2_check, + + .bdrv_get_mapping = qcow2_get_mapping, }; static void bdrv_qcow2_init(void)