mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
util: storage: Modify return value of virStorageSourceNewFromBacking
Return the storage source definition via a pointer in the arguments and document the returned values. This will simplify the possibility to ignore certain backing store types which are not representable by libvirt. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ffabad7572
commit
36cde66708
@ -3391,7 +3391,7 @@ storageBackendProbeTarget(virStorageSourcePtr target,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (meta->backingStoreRaw) {
|
if (meta->backingStoreRaw) {
|
||||||
if (!(target->backingStore = virStorageSourceNewFromBacking(meta)))
|
if (virStorageSourceNewFromBacking(meta, &target->backingStore) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
target->backingStore->format = backingStoreFormat;
|
target->backingStore->format = backingStoreFormat;
|
||||||
|
@ -3681,42 +3681,57 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virStorageSourcePtr
|
/**
|
||||||
virStorageSourceNewFromBacking(virStorageSourcePtr parent)
|
* virStorageSourceNewFromBacking:
|
||||||
|
* @parent: storage source parent
|
||||||
|
* @backing: returned backing store definition
|
||||||
|
*
|
||||||
|
* Creates a storage source which describes the backing image of @parent and
|
||||||
|
* fills it into @backing depending on the 'backingStoreRaw' property of @parent
|
||||||
|
* and other data. Note that for local storage this function accesses the file
|
||||||
|
* to update the actual type of the backing store.
|
||||||
|
*
|
||||||
|
* Returns 0 and fills @backing, or -1 on error (with appropriate error reported).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||||
|
virStorageSourcePtr *backing)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
virStorageSourcePtr ret = NULL;
|
|
||||||
VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
|
VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
|
||||||
|
|
||||||
|
*backing = NULL;
|
||||||
|
|
||||||
if (virStorageIsRelative(parent->backingStoreRaw))
|
if (virStorageIsRelative(parent->backingStoreRaw))
|
||||||
def = virStorageSourceNewFromBackingRelative(parent,
|
def = virStorageSourceNewFromBackingRelative(parent,
|
||||||
parent->backingStoreRaw);
|
parent->backingStoreRaw);
|
||||||
else
|
else
|
||||||
def = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
|
def = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
|
||||||
|
|
||||||
if (def) {
|
if (!def)
|
||||||
/* possibly update local type */
|
return -1;
|
||||||
if (def->type == VIR_STORAGE_TYPE_FILE) {
|
|
||||||
if (stat(def->path, &st) == 0) {
|
/* possibly update local type */
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (def->type == VIR_STORAGE_TYPE_FILE) {
|
||||||
def->type = VIR_STORAGE_TYPE_DIR;
|
if (stat(def->path, &st) == 0) {
|
||||||
def->format = VIR_STORAGE_FILE_DIR;
|
if (S_ISDIR(st.st_mode)) {
|
||||||
} else if (S_ISBLK(st.st_mode)) {
|
def->type = VIR_STORAGE_TYPE_DIR;
|
||||||
def->type = VIR_STORAGE_TYPE_BLOCK;
|
def->format = VIR_STORAGE_FILE_DIR;
|
||||||
}
|
} else if (S_ISBLK(st.st_mode)) {
|
||||||
|
def->type = VIR_STORAGE_TYPE_BLOCK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy parent's labelling and other top level stuff */
|
|
||||||
if (virStorageSourceInitChainElement(def, parent, true) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
def->readonly = true;
|
|
||||||
def->detected = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, def);
|
/* copy parent's labelling and other top level stuff */
|
||||||
return ret;
|
if (virStorageSourceInitChainElement(def, parent, true) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
def->readonly = true;
|
||||||
|
def->detected = true;
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(*backing, def);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4893,7 +4908,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (src->backingStoreRaw) {
|
if (src->backingStoreRaw) {
|
||||||
if (!(backingStore = virStorageSourceNewFromBacking(src)))
|
if (virStorageSourceNewFromBacking(src, &backingStore) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (backingFormat == VIR_STORAGE_FILE_AUTO)
|
if (backingFormat == VIR_STORAGE_FILE_AUTO)
|
||||||
|
@ -444,7 +444,9 @@ int virStorageSourceUpdateCapacity(virStorageSourcePtr src,
|
|||||||
char *buf, ssize_t len,
|
char *buf, ssize_t len,
|
||||||
bool probe);
|
bool probe);
|
||||||
|
|
||||||
virStorageSourcePtr virStorageSourceNewFromBacking(virStorageSourcePtr parent);
|
int virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||||
|
virStorageSourcePtr *backing);
|
||||||
|
|
||||||
virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src,
|
virStorageSourcePtr virStorageSourceCopy(const virStorageSource *src,
|
||||||
bool backingChain)
|
bool backingChain)
|
||||||
ATTRIBUTE_NONNULL(1);
|
ATTRIBUTE_NONNULL(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user