The helper converts the 'type', 'format' and index values to enum
values/numbers and does validation.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 39 +++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 5 +++++
src/libvirt_private.syms | 1 +
3 files changed, 45 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c93c4df929..9b64e33ff5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f550c257d6..ce6e5b4748 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 681ff911b6..6246b4c034 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -565,6 +565,7 @@ virDomainStateTypeFromString;
virDomainStateTypeToString;
virDomainStorageNetworkParseHost;
virDomainStorageSourceParse;
+virDomainStorageSourceParseBase;
virDomainTaintTypeFromString;
virDomainTaintTypeToString;
virDomainTimerModeTypeFromString;
--
2.20.1