qcow2: Move cluster gathering to a non-looping loop

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 <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Kevin Wolf 2013-03-26 17:50:12 +01:00 committed by Stefan Hajnoczi
parent 88c6588c51
commit 2c3b32d256

View file

@ -1147,22 +1147,24 @@ again:
cluster_offset = 0; cluster_offset = 0;
*host_offset = 0; *host_offset = 0;
while (true) {
/* /*
* Now start gathering as many contiguous clusters as possible: * Now start gathering as many contiguous clusters as possible:
* *
* 1. Check for overlaps with in-flight allocations * 1. Check for overlaps with in-flight allocations
* *
* a) Overlap not in the first cluster -> shorten this request and let * a) Overlap not in the first cluster -> shorten this request and
* the caller handle the rest in its next loop iteration. * let the caller handle the rest in its next loop iteration.
* *
* b) Real overlaps of two requests. Yield and restart the search for * b) Real overlaps of two requests. Yield and restart the search
* contiguous clusters (the situation could have changed while we * for contiguous clusters (the situation could have changed
* were sleeping) * while we were sleeping)
* *
* c) TODO: Request starts in the same cluster as the in-flight * c) TODO: Request starts in the same cluster as the in-flight
* allocation ends. Shorten the COW of the in-fight allocation, set * allocation ends. Shorten the COW of the in-fight allocation,
* cluster_offset to write to the same cluster and set up the right * set cluster_offset to write to the same cluster and set up
* synchronisation between the in-flight request and the new one. * the right synchronisation between the in-flight request and
* the new one.
*/ */
cur_bytes = remaining; cur_bytes = remaining;
ret = handle_dependencies(bs, start, &cur_bytes); ret = handle_dependencies(bs, start, &cur_bytes);
@ -1193,12 +1195,12 @@ again:
cur_bytes = remaining; cur_bytes = remaining;
} else if (cur_bytes == 0) { } else if (cur_bytes == 0) {
goto done; break;
} }
/* If there is something left to allocate, do that now */ /* If there is something left to allocate, do that now */
if (remaining == 0) { if (remaining == 0) {
goto done; break;
} }
/* /*
@ -1216,10 +1218,14 @@ again:
start += cur_bytes; start += cur_bytes;
remaining -= cur_bytes; remaining -= cur_bytes;
cluster_offset += 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); *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS);
assert(*num > 0); assert(*num > 0);
assert(*host_offset != 0); assert(*host_offset != 0);