提交 18bc52bc 编写于 作者: P Peter Krempa

conf: introduce virDomainStorageSourceParseBase

The helper converts the 'type', 'format' and index values to enum
values/numbers and does validation.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 dfaf170d
...@@ -9039,6 +9039,45 @@ virDomainDiskSourcePRParse(xmlNodePtr node, ...@@ -9039,6 +9039,45 @@ virDomainDiskSourcePRParse(xmlNodePtr node,
} }
virStorageSourcePtr
virDomainStorageSourceParseBase(const char *type,
const char *format,
const char *index)
{
VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
virStorageSourcePtr ret = NULL;
if (!(src = virStorageSourceNew()))
return NULL;
src->type = VIR_STORAGE_TYPE_FILE;
if (type &&
(src->type = virStorageTypeFromString(type)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown storage source type '%s'"), type);
return NULL;
}
if (format &&
(src->format = virStorageFileFormatTypeFromString(format)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown storage source format '%s'"), format);
return NULL;
}
if (index &&
virStrToLong_uip(index, NULL, 10, &src->id) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid storage source index '%s'"), index);
return NULL;
}
VIR_STEAL_PTR(ret, src);
return ret;
}
int int
virDomainStorageSourceParse(xmlNodePtr node, virDomainStorageSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
......
...@@ -3452,6 +3452,11 @@ int virDomainDiskDefCheckDuplicateInfo(const virDomainDiskDef *a, ...@@ -3452,6 +3452,11 @@ int virDomainDiskDefCheckDuplicateInfo(const virDomainDiskDef *a,
const virDomainDiskDef *b) const virDomainDiskDef *b)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
virStorageSourcePtr
virDomainStorageSourceParseBase(const char *type,
const char *format,
const char *index)
ATTRIBUTE_RETURN_CHECK;
int virDomainStorageSourceParse(xmlNodePtr node, int virDomainStorageSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
......
...@@ -565,6 +565,7 @@ virDomainStateTypeFromString; ...@@ -565,6 +565,7 @@ virDomainStateTypeFromString;
virDomainStateTypeToString; virDomainStateTypeToString;
virDomainStorageNetworkParseHost; virDomainStorageNetworkParseHost;
virDomainStorageSourceParse; virDomainStorageSourceParse;
virDomainStorageSourceParseBase;
virDomainTaintTypeFromString; virDomainTaintTypeFromString;
virDomainTaintTypeToString; virDomainTaintTypeToString;
virDomainTimerModeTypeFromString; virDomainTimerModeTypeFromString;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册