mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
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:
parent
dfaf170df5
commit
18bc52bce0
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user