From patchwork Tue Sep 18 11:40:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 184681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 23CBC2C0091 for ; Tue, 18 Sep 2012 21:41:25 +1000 (EST) Received: from localhost ([::1]:59044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDwB8-0007Qv-FB for incoming@patchwork.ozlabs.org; Tue, 18 Sep 2012 07:41:22 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDwAh-00077Z-PZ for qemu-devel@nongnu.org; Tue, 18 Sep 2012 07:41:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TDwAa-0005Gj-L1 for qemu-devel@nongnu.org; Tue, 18 Sep 2012 07:40:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61474) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDwAa-0005GW-B5 for qemu-devel@nongnu.org; Tue, 18 Sep 2012 07:40:48 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8IBejJ4023761 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 18 Sep 2012 07:40:47 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8IBegGL028821; Tue, 18 Sep 2012 07:40:44 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 18 Sep 2012 13:40:27 +0200 Message-Id: <1347968442-8860-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1347968442-8860-1-git-send-email-kwolf@redhat.com> References: <1347968442-8860-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [RFC PATCH 01/16] qcow2: Round QCowL2Meta.offset down to cluster boundary 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 The offset within the cluster is already present as n_start and this is what the code uses. QCowL2Meta.offset is only needed at a cluster granularity. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 4 ++-- block/qcow2.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e179211..d17a37c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -631,7 +631,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) old_cluster = g_malloc(m->nb_clusters * sizeof(uint64_t)); /* copy content of unmodified sectors */ - start_sect = (m->offset & ~(s->cluster_size - 1)) >> 9; + start_sect = m->offset >> 9; if (m->n_start) { cow = true; qemu_co_mutex_unlock(&s->lock); @@ -966,7 +966,7 @@ again: .cluster_offset = keep_clusters == 0 ? alloc_cluster_offset : cluster_offset, .alloc_offset = alloc_cluster_offset, - .offset = alloc_offset, + .offset = alloc_offset & ~(s->cluster_size - 1), .n_start = keep_clusters == 0 ? n_start : 0, .nb_clusters = nb_clusters, .nb_available = MIN(requested_sectors, avail_sectors), diff --git a/block/qcow2.h b/block/qcow2.h index b4eb654..2a406a7 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -199,12 +199,34 @@ struct QCowAIOCB; /* XXX This could be private for qcow2-cluster.c */ typedef struct QCowL2Meta { + /** Guest offset of the first newly allocated cluster */ uint64_t offset; + + /** Host offset of the first cluster of the request */ uint64_t cluster_offset; + + /** Host offset of the first newly allocated cluster */ uint64_t alloc_offset; + + /** + * Number of sectors between the start of the first allocated cluster and + * the area that the guest actually writes to. + */ int n_start; + + /** + * Number of sectors from the start of the first allocated cluster to + * the end of the (possibly shortened) request + */ int nb_available; + + /** Number of newly allocated clusters */ int nb_clusters; + + /** + * Requests that overlap with this allocation and wait to be restarted + * when the allocating request has completed. + */ CoQueue dependent_requests; QLIST_ENTRY(QCowL2Meta) next_in_flight;