提交 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,
}
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
virDomainStorageSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt,
......
......@@ -3452,6 +3452,11 @@ int virDomainDiskDefCheckDuplicateInfo(const virDomainDiskDef *a,
const virDomainDiskDef *b)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
virStorageSourcePtr
virDomainStorageSourceParseBase(const char *type,
const char *format,
const char *index)
ATTRIBUTE_RETURN_CHECK;
int virDomainStorageSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt,
......
......@@ -565,6 +565,7 @@ virDomainStateTypeFromString;
virDomainStateTypeToString;
virDomainStorageNetworkParseHost;
virDomainStorageSourceParse;
virDomainStorageSourceParseBase;
virDomainTaintTypeFromString;
virDomainTaintTypeToString;
virDomainTimerModeTypeFromString;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册