mirror of https://github.com/xemu-project/xemu.git
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:
parent
88c6588c51
commit
2c3b32d256
|
@ -1147,79 +1147,85 @@ 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
|
*
|
||||||
* the caller handle the rest in its next loop iteration.
|
* 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
|
* b) Real overlaps of two requests. Yield and restart the search
|
||||||
* were sleeping)
|
* 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
|
* c) TODO: Request starts in the same cluster as the in-flight
|
||||||
* cluster_offset to write to the same cluster and set up the right
|
* allocation ends. Shorten the COW of the in-fight allocation,
|
||||||
* synchronisation between the in-flight request and the new one.
|
* set cluster_offset to write to the same cluster and set up
|
||||||
*/
|
* the right synchronisation between the in-flight request and
|
||||||
cur_bytes = remaining;
|
* the new one.
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
start += cur_bytes;
|
|
||||||
remaining -= cur_bytes;
|
|
||||||
cluster_offset += cur_bytes;
|
|
||||||
|
|
||||||
cur_bytes = remaining;
|
cur_bytes = remaining;
|
||||||
} else if (cur_bytes == 0) {
|
ret = handle_dependencies(bs, start, &cur_bytes);
|
||||||
goto done;
|
if (ret == -EAGAIN) {
|
||||||
}
|
goto again;
|
||||||
|
} else if (ret < 0) {
|
||||||
/* If there is something left to allocate, do that now */
|
return ret;
|
||||||
if (remaining == 0) {
|
} else {
|
||||||
goto done;
|
/* handle_dependencies() may have decreased cur_bytes (shortened
|
||||||
}
|
* the allocations below) so that the next dependency is processed
|
||||||
|
* correctly during the next loop iteration. */
|
||||||
/*
|
|
||||||
* 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;
|
* 2. Count contiguous COPIED clusters.
|
||||||
cluster_offset += cur_bytes;
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
start += cur_bytes;
|
||||||
|
remaining -= cur_bytes;
|
||||||
|
cluster_offset += cur_bytes;
|
||||||
|
|
||||||
|
cur_bytes = remaining;
|
||||||
|
} else if (cur_bytes == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If there is something left to allocate, do that now */
|
||||||
|
if (remaining == 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
*num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS);
|
||||||
assert(*num > 0);
|
assert(*num > 0);
|
||||||
assert(*host_offset != 0);
|
assert(*host_offset != 0);
|
||||||
|
|
Loading…
Reference in New Issue