conf: introduce virDomainStorageSourceParseBase

The helper converts the 'type', 'format' and index values to enum
values/numbers and does validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-03-20 16:12:45 +01:00
parent dfaf170df5
commit 18bc52bce0
3 changed files with 45 additions and 0 deletions

View File

@ -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,

View File

@ -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,

View File

@ -565,6 +565,7 @@ virDomainStateTypeFromString;
virDomainStateTypeToString;
virDomainStorageNetworkParseHost;
virDomainStorageSourceParse;
virDomainStorageSourceParseBase;
virDomainTaintTypeFromString;
virDomainTaintTypeToString;
virDomainTimerModeTypeFromString;