mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-14 16:45:20 +00:00
virStorageSourceGetBackingStoreStr: Move the function earlier
Move it together with virStorageSourceGetRelativeBackingPath which is the main reason why it exists. Upcoming patch will modify the comment and arguments refering to virStorageSourceGetRelativeBackingPath so it's better if they are together. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
b889594a70
commit
489742e76d
@ -1880,6 +1880,56 @@ virStorageSourceGetRelativeBackingPath(virStorageSourcePtr top,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStorageSourceGetBackingStoreStr:
|
||||
* @src: storage object
|
||||
*
|
||||
* Extracts the backing store string as stored in the storage volume described
|
||||
* by @src and returns it to the user. Caller is responsible for freeing it.
|
||||
* In case when the string can't be retrieved or does not exist NULL is
|
||||
* returned.
|
||||
*/
|
||||
int
|
||||
virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
|
||||
char **backing)
|
||||
{
|
||||
ssize_t headerLen;
|
||||
int rv;
|
||||
g_autofree char *buf = NULL;
|
||||
g_autoptr(virStorageSource) tmp = NULL;
|
||||
|
||||
*backing = NULL;
|
||||
|
||||
/* exit if we can't load information about the current image */
|
||||
if (!virStorageSourceSupportsBackingChainTraversal(src))
|
||||
return 0;
|
||||
|
||||
rv = virStorageSourceAccess(src, F_OK);
|
||||
if (rv == -2)
|
||||
return 0;
|
||||
if (rv < 0) {
|
||||
virStorageSourceReportBrokenChain(errno, src, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((headerLen = virStorageSourceRead(src, 0, VIR_STORAGE_MAX_HEADER,
|
||||
&buf)) < 0) {
|
||||
if (headerLen == -2)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(tmp = virStorageSourceCopy(src, false)))
|
||||
return -1;
|
||||
|
||||
if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0)
|
||||
return -1;
|
||||
|
||||
*backing = g_steal_pointer(&tmp->backingStoreRaw);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
virStorageSourceIsInitialized(const virStorageSource *src)
|
||||
{
|
||||
@ -2562,53 +2612,3 @@ virStorageSourceGetMetadata(virStorageSourcePtr src,
|
||||
virHashFree(cycle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virStorageSourceGetBackingStoreStr:
|
||||
* @src: storage object
|
||||
*
|
||||
* Extracts the backing store string as stored in the storage volume described
|
||||
* by @src and returns it to the user. Caller is responsible for freeing it.
|
||||
* In case when the string can't be retrieved or does not exist NULL is
|
||||
* returned.
|
||||
*/
|
||||
int
|
||||
virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
|
||||
char **backing)
|
||||
{
|
||||
ssize_t headerLen;
|
||||
int rv;
|
||||
g_autofree char *buf = NULL;
|
||||
g_autoptr(virStorageSource) tmp = NULL;
|
||||
|
||||
*backing = NULL;
|
||||
|
||||
/* exit if we can't load information about the current image */
|
||||
if (!virStorageSourceSupportsBackingChainTraversal(src))
|
||||
return 0;
|
||||
|
||||
rv = virStorageSourceAccess(src, F_OK);
|
||||
if (rv == -2)
|
||||
return 0;
|
||||
if (rv < 0) {
|
||||
virStorageSourceReportBrokenChain(errno, src, src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((headerLen = virStorageSourceRead(src, 0, VIR_STORAGE_MAX_HEADER,
|
||||
&buf)) < 0) {
|
||||
if (headerLen == -2)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(tmp = virStorageSourceCopy(src, false)))
|
||||
return -1;
|
||||
|
||||
if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0)
|
||||
return -1;
|
||||
|
||||
*backing = g_steal_pointer(&tmp->backingStoreRaw);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user