提交 5265743d 编写于 作者: P Peter Krempa

util: storagefile: Modify arguments of virStorageSourceNewFromBackingAbsolue

Return the parsed storage source via an pointer in arguments and return
an integer from the function. Describe the semantics with a comment for
the function and adjust callers to the new semantics.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 dddc5524
...@@ -3635,22 +3635,32 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src, ...@@ -3635,22 +3635,32 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
} }
virStorageSourcePtr /**
virStorageSourceNewFromBackingAbsolute(const char *path) * virStorageSourceNewFromBackingAbsolute
* @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.
*/
int
virStorageSourceNewFromBackingAbsolute(const char *path,
virStorageSourcePtr *src)
{ {
const char *json; const char *json;
virStorageSourcePtr ret = NULL;
int rc; int rc;
VIR_AUTOUNREF(virStorageSourcePtr) def = NULL; VIR_AUTOUNREF(virStorageSourcePtr) def = NULL;
*src = NULL;
if (!(def = virStorageSourceNew())) if (!(def = virStorageSourceNew()))
return NULL; return -1;
if (virStorageIsFile(path)) { if (virStorageIsFile(path)) {
def->type = VIR_STORAGE_TYPE_FILE; def->type = VIR_STORAGE_TYPE_FILE;
if (VIR_STRDUP(def->path, path) < 0) if (VIR_STRDUP(def->path, path) < 0)
return NULL; return -1;
} else { } else {
def->type = VIR_STORAGE_TYPE_NETWORK; def->type = VIR_STORAGE_TYPE_NETWORK;
...@@ -3665,7 +3675,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path) ...@@ -3665,7 +3675,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
rc = virStorageSourceParseBackingColon(def, path); rc = virStorageSourceParseBackingColon(def, path);
if (rc < 0) if (rc < 0)
return NULL; return -1;
virStorageSourceNetworkAssignDefaultPorts(def); virStorageSourceNetworkAssignDefaultPorts(def);
...@@ -3678,8 +3688,8 @@ virStorageSourceNewFromBackingAbsolute(const char *path) ...@@ -3678,8 +3688,8 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
} }
} }
VIR_STEAL_PTR(ret, def); VIR_STEAL_PTR(*src, def);
return ret; return 0;
} }
...@@ -3704,14 +3714,15 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent, ...@@ -3704,14 +3714,15 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent,
*backing = NULL; *backing = NULL;
if (virStorageIsRelative(parent->backingStoreRaw)) if (virStorageIsRelative(parent->backingStoreRaw)) {
def = virStorageSourceNewFromBackingRelative(parent, if (!(def = virStorageSourceNewFromBackingRelative(parent,
parent->backingStoreRaw); parent->backingStoreRaw)))
else
def = virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw);
if (!def)
return -1; return -1;
} else {
if (virStorageSourceNewFromBackingAbsolute(parent->backingStoreRaw,
&def) < 0)
return -1;
}
/* possibly update local type */ /* possibly update local type */
if (def->type == VIR_STORAGE_TYPE_FILE) { if (def->type == VIR_STORAGE_TYPE_FILE) {
......
...@@ -473,7 +473,8 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from, ...@@ -473,7 +473,8 @@ int virStorageFileGetRelativeBackingPath(virStorageSourcePtr from,
int virStorageFileCheckCompat(const char *compat); int virStorageFileCheckCompat(const char *compat);
virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path); int virStorageSourceNewFromBackingAbsolute(const char *path,
virStorageSourcePtr *src);
bool virStorageSourceIsRelative(virStorageSourcePtr src); bool virStorageSourceIsRelative(virStorageSourcePtr src);
......
...@@ -85,7 +85,8 @@ testBackingXMLjsonXML(const void *args) ...@@ -85,7 +85,8 @@ testBackingXMLjsonXML(const void *args)
if (virAsprintf(&protocolwrapper, "json:%s", propsstr) < 0) if (virAsprintf(&protocolwrapper, "json:%s", propsstr) < 0)
return -1; return -1;
if (!(jsonsrc = virStorageSourceNewFromBackingAbsolute(protocolwrapper))) { if (virStorageSourceNewFromBackingAbsolute(protocolwrapper,
&jsonsrc) < 0) {
fprintf(stderr, "failed to parse disk json\n"); fprintf(stderr, "failed to parse disk json\n");
return -1; return -1;
} }
......
...@@ -613,7 +613,7 @@ testBackingParse(const void *args) ...@@ -613,7 +613,7 @@ testBackingParse(const void *args)
VIR_AUTOFREE(char *) xml = NULL; VIR_AUTOFREE(char *) xml = NULL;
VIR_AUTOUNREF(virStorageSourcePtr) src = NULL; VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
if (!(src = virStorageSourceNewFromBackingAbsolute(data->backing))) { if (virStorageSourceNewFromBackingAbsolute(data->backing, &src) < 0) {
if (!data->expect) if (!data->expect)
return 0; return 0;
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册