From patchwork Fri Jul 29 04:49:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Nakamura X-Patchwork-Id: 107338 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 86FB3B6F62 for ; Fri, 29 Jul 2011 15:22:25 +1000 (EST) Received: from localhost ([::1]:38533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf3J-00057e-9p for incoming@patchwork.ozlabs.org; Fri, 29 Jul 2011 00:52:01 -0400 Received: from eggs.gnu.org ([140.186.70.92]:41350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf1t-0001qn-85 for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qmf1m-0000QQ-P3 for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:27 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:46817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmf1m-0000NN-Ht for qemu-devel@nongnu.org; Fri, 29 Jul 2011 00:50:26 -0400 Received: by mail-iy0-f173.google.com with SMTP id 39so4186308iyb.4 for ; Thu, 28 Jul 2011 21:50:26 -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=8brX/w8dzEiMGzwQvILITPRYjh2NebKkYrQkLVlTtC8=; b=tUII2y2QrAvZsBt2UafW/cRxb++XB7RS65DCmJOOX8xVGWzDQ5MH0pjTMN+8f/DI83 o72XcDLdVHoEUP50UkiPipxKYHt2I0WSBKHJbR7Emr+KCNcJqKWDX+q6H2+Cu1srWJ57 AuYELsOaTo/+0Dy1iyZCIZsQ5pWSHrj5ttgUk= Received: by 10.42.199.203 with SMTP id et11mr619595icb.257.1311915026129; Thu, 28 Jul 2011 21:50:26 -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.25 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jul 2011 21:50:25 -0700 (PDT) From: Devin Nakamura To: qemu-devel@nongnu.org Date: Fri, 29 Jul 2011 00:49:39 -0400 Message-Id: <1311914994-20482-10-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.210.173 Cc: kwolf@redhat.com, Devin Nakamura Subject: [Qemu-devel] [RFC 09/24] qed: add qed_bdrv_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 Fuction to get drive mapping from qed images Signed-off-by: Devin Nakamura --- block/qed.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/block/qed.c b/block/qed.c index 00cf895..dadb7f8 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1451,6 +1451,37 @@ static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result) return qed_check(s, result, false); } +static int bdrv_qed_get_mapping(BlockDriverState *bs, uint64_t *guest_offset, + uint64_t *host_offset, + uint64_t *contiguous_bytes) +{ + BDRVQEDState *s = bs->opaque; + size_t l2_size = s->header.cluster_size * s->table_nelems; + uint64_t pos = *guest_offset + *contiguous_bytes; + uint64_t offset = pos; + size_t len = 0; + QEDRequest req = {.l2_table = NULL}; + int ret; + + if (pos >= s->header.image_size) { + *contiguous_bytes = 0; + return 0; + } + + do { + pos += len; + ret = qed_find_cluster_sync(s, &req, pos, l2_size, &offset, &len); + } while (ret != QED_CLUSTER_FOUND && pos < s->header.image_size); + *guest_offset = pos; + *host_offset = offset; + if (pos >= s->header.image_size) { + *contiguous_bytes = 0; + } else { + *contiguous_bytes = len; + } + return 0; +} + static QEMUOptionParameter qed_create_options[] = { { .name = BLOCK_OPT_SIZE, @@ -1497,6 +1528,7 @@ static BlockDriver bdrv_qed = { .bdrv_get_info = bdrv_qed_get_info, .bdrv_change_backing_file = bdrv_qed_change_backing_file, .bdrv_check = bdrv_qed_check, + .bdrv_get_mapping = bdrv_qed_get_mapping, }; static void bdrv_qed_init(void)