From patchwork Wed Feb 13 13:22:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 220163 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 A7C552C0292 for ; Thu, 14 Feb 2013 02:09:01 +1100 (EST) Received: from localhost ([::1]:33657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cIv-00076X-71 for incoming@patchwork.ozlabs.org; Wed, 13 Feb 2013 08:23:17 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cIY-0006kl-Dl for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5cIV-0002yA-LH for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cIV-0002y3-Cz for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:51 -0500 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 r1DDMo0M019839 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Feb 2013 08:22:50 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-192-240.str.redhat.com [10.33.192.240]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1DDMGRm011418; Wed, 13 Feb 2013 08:22:49 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 13 Feb 2013 14:22:05 +0100 Message-Id: <1360761733-25347-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1360761733-25347-1-git-send-email-kwolf@redhat.com> References: <1360761733-25347-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: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, lersek@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [RFC PATCH v2 15/23] qcow2: Allow requests with multiple l2metas 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 Instead of expecting a single l2meta, have a list of them. This allows to still have a single I/O request for the guest data, even though multiple l2meta may be needed in order to describe both a COW overwrite and a new cluster allocation (typical sequential write case). Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 3 +++ block/qcow2.c | 14 +++++++++++--- block/qcow2.h | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 9e6b746..645ea25 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1057,12 +1057,15 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, int alloc_n_start = offset_into_cluster(s, guest_offset) >> BDRV_SECTOR_BITS; int nb_sectors = MIN(requested_sectors, avail_sectors); + QCowL2Meta *old_m = *m; *host_offset = alloc_cluster_offset; *m = g_malloc0(sizeof(**m)); **m = (QCowL2Meta) { + .next = old_m, + .alloc_offset = *host_offset, .offset = start_of_cluster(s, guest_offset), .nb_clusters = nb_clusters, diff --git a/block/qcow2.c b/block/qcow2.c index 971dd42..345487e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -824,7 +824,9 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, goto fail; } - if (l2meta != NULL) { + while (l2meta != NULL) { + QCowL2Meta *next; + ret = qcow2_alloc_cluster_link_l2(bs, l2meta); if (ret < 0) { goto fail; @@ -837,8 +839,9 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, qemu_co_queue_restart_all(&l2meta->dependent_requests); + next = l2meta->next; g_free(l2meta); - l2meta = NULL; + l2meta = next; } remaining_sectors -= cur_nr_sectors; @@ -851,12 +854,17 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, fail: qemu_co_mutex_unlock(&s->lock); - if (l2meta != NULL) { + while (l2meta != NULL) { + QCowL2Meta *next; + if (l2meta->nb_clusters != 0) { QLIST_REMOVE(l2meta, next_in_flight); } qemu_co_queue_restart_all(&l2meta->dependent_requests); + + next = l2meta->next; g_free(l2meta); + l2meta = next; } qemu_iovec_destroy(&hd_qiov); diff --git a/block/qcow2.h b/block/qcow2.h index bfdf71d..9b16538 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -246,6 +246,9 @@ typedef struct QCowL2Meta */ Qcow2COWRegion cow_end; + /** Pointer to next L2Meta of the same write request */ + struct QCowL2Meta *next; + QLIST_ENTRY(QCowL2Meta) next_in_flight; } QCowL2Meta;