mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
util: storagefile: Add handling of unusable storage sources
Introduce new semantics to virStorageSourceNewFromBacking and some of the helpers used by it which propagate the return value from the callers. The new return value introduced by this patch allows to notify the calller that the parsed virStorageSource correctly describes the source but contains data such as inline authentication which libvirt does not want to support directly. This means that such file would e.g. unusable as a storage source (e.g. when actively commiting the overlay to it) or would not work with blockdev. The caller will then be able to decide whether to consider this backing file as viable or just fall back to qemu dealing with it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
e1189ae5f3
commit
9467c37e96
@ -3556,6 +3556,13 @@ virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src,
|
||||
|
||||
struct virStorageSourceJSONDriverParser {
|
||||
const char *drvname;
|
||||
/**
|
||||
* The callback gets a pre-allocated storage source @src and the JSON
|
||||
* object to parse. The callback shall return -1 on error and report error
|
||||
* 0 on success and 1 in cases when the configuration itself is valid, but
|
||||
* can't be converted to libvirt's configuration (e.g. inline authentication
|
||||
* credentials are present).
|
||||
*/
|
||||
int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
|
||||
int opaque;
|
||||
};
|
||||
@ -3640,15 +3647,17 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
|
||||
* @path: string representing absolute location of a storage source
|
||||
* @src: filled with virStorageSource object representing @path
|
||||
*
|
||||
* Returns 0 on success and fills @src or -1 on error and reports appropriate
|
||||
* error.
|
||||
* Returns 0 on success, 1 if we could parse all location data but @path
|
||||
* specified other data unrepresentable by libvirt (e.g. inline authentication).
|
||||
* In both cases @src is filled. On error -1 is returned @src is NULL and an
|
||||
* error is reported.
|
||||
*/
|
||||
int
|
||||
virStorageSourceNewFromBackingAbsolute(const char *path,
|
||||
virStorageSourcePtr *src)
|
||||
{
|
||||
const char *json;
|
||||
int rc;
|
||||
int rc = 0;
|
||||
VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
|
||||
|
||||
*src = NULL;
|
||||
@ -3689,7 +3698,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
|
||||
}
|
||||
|
||||
VIR_STEAL_PTR(*src, def);
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@ -3703,7 +3712,11 @@ virStorageSourceNewFromBackingAbsolute(const char *path,
|
||||
* 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).
|
||||
* Returns 0 on success, 1 if we could parse all location data but the backinig
|
||||
* store specification contained other data unrepresentable by libvirt (e.g.
|
||||
* inline authentication).
|
||||
* In both cases @src is filled. On error -1 is returned @src is NULL and an
|
||||
* error is reported.
|
||||
*/
|
||||
int
|
||||
virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||
@ -3711,6 +3724,7 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||
{
|
||||
struct stat st;
|
||||
VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
|
||||
int rc = 0;
|
||||
|
||||
*backing = NULL;
|
||||
|
||||
@ -3719,8 +3733,8 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||
parent->backingStoreRaw)))
|
||||
return -1;
|
||||
} else {
|
||||
if (virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,
|
||||
&def) < 0)
|
||||
if ((rc = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,
|
||||
&def)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -3744,7 +3758,7 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
|
||||
def->detected = true;
|
||||
|
||||
VIR_STEAL_PTR(*backing, def);
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user