mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
qcow2: Refactor get_cluster_table()
After the previous patch we're now always using l2_load() in get_cluster_table() regardless of whether a new L2 table has to be allocated or not. This patch refactors that part of the code to use one single l2_load() call. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: ce31758c4a1fadccea7a6ccb93951eb01d95fd4c.1517840877.git.berto@igalia.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
3861946a5b
commit
05f9ee4689
1 changed files with 7 additions and 14 deletions
|
@ -694,15 +694,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek the l2 table of the given l2 offset */
|
if (!(s->l1_table[l1_index] & QCOW_OFLAG_COPIED)) {
|
||||||
|
|
||||||
if (s->l1_table[l1_index] & QCOW_OFLAG_COPIED) {
|
|
||||||
/* load the l2 table in memory */
|
|
||||||
ret = l2_load(bs, offset, l2_offset, &l2_table);
|
|
||||||
if (ret < 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* First allocate a new L2 table (and do COW if needed) */
|
/* First allocate a new L2 table (and do COW if needed) */
|
||||||
ret = l2_allocate(bs, l1_index);
|
ret = l2_allocate(bs, l1_index);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -718,12 +710,13 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
|
||||||
/* Get the offset of the newly-allocated l2 table */
|
/* Get the offset of the newly-allocated l2 table */
|
||||||
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
|
l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK;
|
||||||
assert(offset_into_cluster(s, l2_offset) == 0);
|
assert(offset_into_cluster(s, l2_offset) == 0);
|
||||||
/* Load the l2 table in memory */
|
}
|
||||||
|
|
||||||
|
/* load the l2 table in memory */
|
||||||
ret = l2_load(bs, offset, l2_offset, &l2_table);
|
ret = l2_load(bs, offset, l2_offset, &l2_table);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* find the cluster offset for the given disk offset */
|
/* find the cluster offset for the given disk offset */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue