mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
storagefile: Push 'start' into qcow2GetBackingStoreFormat
This is a step towards making this qcow2GetBackingStoreFormat into a generic qcow2 extensions parser Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
242e7ac590
commit
bd6b4646c7
@ -430,10 +430,22 @@ static int
|
||||
qcow2GetBackingStoreFormat(int *format,
|
||||
const char *buf,
|
||||
size_t buf_size,
|
||||
size_t extension_start,
|
||||
size_t extension_end)
|
||||
{
|
||||
size_t offset = extension_start;
|
||||
size_t offset;
|
||||
size_t extension_start;
|
||||
int version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
|
||||
|
||||
if (version < 2) {
|
||||
/* QCow1 doesn't have the extensions capability
|
||||
* used to store backing format */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (version == 2)
|
||||
extension_start = QCOW2_HDR_TOTAL_SIZE;
|
||||
else
|
||||
extension_start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE);
|
||||
|
||||
/*
|
||||
* The extensions take format of
|
||||
@ -445,6 +457,7 @@ qcow2GetBackingStoreFormat(int *format,
|
||||
* Unknown extensions can be ignored by skipping
|
||||
* over "length" bytes in the data stream.
|
||||
*/
|
||||
offset = extension_start;
|
||||
while (offset < (buf_size-8) &&
|
||||
offset < (extension_end-8)) {
|
||||
unsigned int magic = virReadBufInt32BE(buf + offset);
|
||||
@ -487,8 +500,6 @@ qcowXGetBackingStore(char **res,
|
||||
{
|
||||
unsigned long long offset;
|
||||
unsigned int size;
|
||||
unsigned long long start;
|
||||
int version;
|
||||
|
||||
*res = NULL;
|
||||
*format = VIR_STORAGE_FILE_AUTO;
|
||||
@ -546,18 +557,8 @@ qcowXGetBackingStore(char **res,
|
||||
* is stored at QCOW2v3_HDR_SIZE
|
||||
*/
|
||||
|
||||
version = virReadBufInt32BE(buf + QCOWX_HDR_VERSION);
|
||||
if (version >= 2) {
|
||||
/* QCow1 doesn't have the extensions capability
|
||||
* used to store backing format */
|
||||
if (version == 2)
|
||||
start = QCOW2_HDR_TOTAL_SIZE;
|
||||
else
|
||||
start = virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE);
|
||||
if (qcow2GetBackingStoreFormat(format, buf, buf_size,
|
||||
start, offset) < 0)
|
||||
return BACKING_STORE_INVALID;
|
||||
}
|
||||
if (qcow2GetBackingStoreFormat(format, buf, buf_size, offset) < 0)
|
||||
return BACKING_STORE_INVALID;
|
||||
|
||||
return BACKING_STORE_OK;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user