[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 21/23] qcow2: Move cluster gathering to a non-loopin
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 21/23] qcow2: Move cluster gathering to a non-looping loop |
Date: |
Thu, 28 Mar 2013 17:40:35 +0100 |
From: Kevin Wolf <address@hidden>
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 <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
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 6dc7f7f..960d446 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1147,79 +1147,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 = start_of_cluster(s, 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 = start_of_cluster(s, 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 = start_of_cluster(s, 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 = start_of_cluster(s, 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);
--
1.8.1.4
- [Qemu-devel] [PATCH 10/23] qcow2: handle_alloc(): Get rid of nb_clusters parameter, (continued)
- [Qemu-devel] [PATCH 10/23] qcow2: handle_alloc(): Get rid of nb_clusters parameter, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 12/23] qcow2: Finalise interface of handle_alloc(), Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 13/23] qcow2: Clean up handle_alloc(), Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 14/23] qcow2: Factor out handle_copied(), Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 15/23] qcow2: handle_copied(): Get rid of nb_clusters parameter, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 16/23] qcow2: handle_copied(): Get rid of keep_clusters parameter, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 18/23] qcow2: Prepare handle_alloc/copied() for byte granularity, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 17/23] qcow2: handle_copied(): Implement non-zero host_offset, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 19/23] qcow2: Use byte granularity in qcow2_alloc_cluster_offset(), Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 20/23] qcow2: Allow requests with multiple l2metas, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 21/23] qcow2: Move cluster gathering to a non-looping loop,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH 22/23] qcow2: Gather clusters in a looping loop, Stefan Hajnoczi, 2013/03/28
- [Qemu-devel] [PATCH 23/23] block: Fix direct use of protocols as driver for bdrv_open(), Stefan Hajnoczi, 2013/03/28