From patchwork Mon Mar 25 17:30:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 230808 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 330CF2C0092 for ; Tue, 26 Mar 2013 04:39:48 +1100 (EST) Received: from localhost ([::1]:60755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKBN4-0000aL-FV for incoming@patchwork.ozlabs.org; Mon, 25 Mar 2013 13:39:46 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKBEo-0005Pv-Fe for qemu-devel@nongnu.org; Mon, 25 Mar 2013 13:31:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKBEm-00047A-Ll for qemu-devel@nongnu.org; Mon, 25 Mar 2013 13:31:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20345) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKBEm-00046n-E5 for qemu-devel@nongnu.org; Mon, 25 Mar 2013 13:31:12 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2PHVBwp012128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Mar 2013 13:31:11 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-73.ams2.redhat.com [10.36.116.73]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2PHUd7X010200; Mon, 25 Mar 2013 13:31:10 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 25 Mar 2013 18:30:19 +0100 Message-Id: <1364232620-5293-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1364232620-5293-1-git-send-email-kwolf@redhat.com> References: <1364232620-5293-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 18/19] qcow2: Move cluster gathering to a non-looping loop 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 This patch is mainly to separate the indentation change from the semantic changes. All that really changes here is that everything moves into a while loop, all 'goto done' become 'break' and at the end of the loop a new 'break is inserted. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 134 ++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index aba549e..39a574f 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1140,79 +1140,85 @@ again: cluster_offset = 0; *host_offset = 0; - /* - * Now start gathering as many contiguous clusters as possible: - * - * 1. Check for overlaps with in-flight allocations - * - * a) Overlap not in the first cluster -> shorten this request and let - * the caller handle the rest in its next loop iteration. - * - * b) Real overlaps of two requests. Yield and restart the search for - * contiguous clusters (the situation could have changed while we - * were sleeping) - * - * c) TODO: Request starts in the same cluster as the in-flight - * allocation ends. Shorten the COW of the in-fight allocation, set - * cluster_offset to write to the same cluster and set up the right - * synchronisation between the in-flight request and the new one. - */ - cur_bytes = remaining; - ret = handle_dependencies(bs, start, &cur_bytes); - if (ret == -EAGAIN) { - goto again; - } else if (ret < 0) { - return ret; - } else { - /* handle_dependencies() may have decreased cur_bytes (shortened - * the allocations below) so that the next dependency is processed - * correctly during the next loop iteration. */ - } - - /* - * 2. Count contiguous COPIED clusters. - */ - ret = handle_copied(bs, start, &cluster_offset, &cur_bytes, m); - if (ret < 0) { - return ret; - } else if (ret) { - if (!*host_offset) { - *host_offset = cluster_offset; + while (true) { + /* + * Now start gathering as many contiguous clusters as possible: + * + * 1. Check for overlaps with in-flight allocations + * + * a) Overlap not in the first cluster -> shorten this request and + * let the caller handle the rest in its next loop iteration. + * + * b) Real overlaps of two requests. Yield and restart the search + * for contiguous clusters (the situation could have changed + * while we were sleeping) + * + * c) TODO: Request starts in the same cluster as the in-flight + * allocation ends. Shorten the COW of the in-fight allocation, + * set cluster_offset to write to the same cluster and set up + * the right synchronisation between the in-flight request and + * the new one. + */ + cur_bytes = remaining; + ret = handle_dependencies(bs, start, &cur_bytes); + if (ret == -EAGAIN) { + goto again; + } else if (ret < 0) { + return ret; + } else { + /* handle_dependencies() may have decreased cur_bytes (shortened + * the allocations below) so that the next dependency is processed + * correctly during the next loop iteration. */ } - start += cur_bytes; - remaining -= cur_bytes; - cluster_offset += cur_bytes; + /* + * 2. Count contiguous COPIED clusters. + */ + ret = handle_copied(bs, start, &cluster_offset, &cur_bytes, m); + if (ret < 0) { + return ret; + } else if (ret) { + if (!*host_offset) { + *host_offset = cluster_offset; + } - cur_bytes = remaining; - } else if (cur_bytes == 0) { - goto done; - } + start += cur_bytes; + remaining -= cur_bytes; + cluster_offset += cur_bytes; - /* If there is something left to allocate, do that now */ - if (remaining == 0) { - goto done; - } + cur_bytes = remaining; + } else if (cur_bytes == 0) { + break; + } - /* - * 3. If the request still hasn't completed, allocate new clusters, - * considering any cluster_offset of steps 1c or 2. - */ - ret = handle_alloc(bs, start, &cluster_offset, &cur_bytes, m); - if (ret < 0) { - return ret; - } else if (ret) { - if (!*host_offset) { - *host_offset = cluster_offset; + /* If there is something left to allocate, do that now */ + if (remaining == 0) { + break; } - start += cur_bytes; - remaining -= cur_bytes; - cluster_offset += cur_bytes; + /* + * 3. If the request still hasn't completed, allocate new clusters, + * considering any cluster_offset of steps 1c or 2. + */ + ret = handle_alloc(bs, start, &cluster_offset, &cur_bytes, m); + if (ret < 0) { + return ret; + } else if (ret) { + if (!*host_offset) { + *host_offset = cluster_offset; + } + + start += cur_bytes; + remaining -= cur_bytes; + cluster_offset += cur_bytes; + + break; + } else { + assert(cur_bytes == 0); + break; + } } - /* Some cleanup work */ -done: *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS); assert(*num > 0); assert(*host_offset != 0);