Validates the wwn while parsing, error out if it's malformed.
* src/util/util.h: Declare virValidateWWN
* src/util/util.c: Implement virValidateWWN
* src/libvirt_private.syms: Export virValidateWWN.
* src/conf/domain_conf.h: New member 'wwn' for disk def.
* src/conf/domain_conf.c: Parse and format disk <wwn>
---
src/conf/domain_conf.c | 13 ++++++++++++-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 1 +
src/util/util.c | 17 +++++++++++++++++
src/util/util.h | 2 ++
5 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 49327df..f83dfb7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -950,6 +950,7 @@ void virDomainDiskDefFree(virDomainDiskDefPtr def)
VIR_FREE(def->mirror);
VIR_FREE(def->mirrorFormat);
VIR_FREE(def->auth.username);
+ VIR_FREE(def->wwn);
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE)
VIR_FREE(def->auth.secret.usage);
virStorageEncryptionFree(def->encryption);
@@ -3372,7 +3373,6 @@ cleanup:
goto cleanup;
}
-
/* Parse the XML definition for a disk
* @param node XML nodeset to parse for disk definition
*/
@@ -3421,6 +3421,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
char *authUUID = NULL;
char *usageType = NULL;
char *tray = NULL;
+ char *wwn = NULL;
if (VIR_ALLOC(def) < 0) {
virReportOOMError();
@@ -3723,6 +3724,12 @@ virDomainDiskDefParseXML(virCapsPtr caps,
} else if (!serial &&
xmlStrEqual(cur->name, BAD_CAST "serial")) {
serial = (char *)xmlNodeGetContent(cur);
+ } else if (!wwn &&
+ xmlStrEqual(cur->name, BAD_CAST "wwn")) {
+ wwn = (char *)xmlNodeGetContent(cur);
+
+ if (!virValidateWWN(wwn))
+ goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "boot")) {
/* boot is parsed as part of virDomainDeviceInfoParseXML */
}
@@ -4019,6 +4026,8 @@ virDomainDiskDefParseXML(virCapsPtr caps,
encryption = NULL;
def->serial = serial;
serial = NULL;
+ def->wwn = wwn;
+ wwn = NULL;
if (!def->driverType &&
caps->defaultDiskDriverType &&
@@ -4073,6 +4082,7 @@ cleanup:
VIR_FREE(copy_on_read);
VIR_FREE(devaddr);
VIR_FREE(serial);
+ VIR_FREE(wwn);
virStorageEncryptionFree(encryption);
VIR_FREE(startupPolicy);
@@ -11586,6 +11596,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
if (def->transient)
virBufferAddLit(buf, " <transient/>\n");
virBufferEscapeString(buf, " <serial>%s</serial>\n",
def->serial);
+ virBufferEscapeString(buf, " <wwn>%s</wwn>\n",
def->wwn);
if (def->encryption) {
virBufferAdjustIndent(buf, 6);
if (virStorageEncryptionFormat(buf, def->encryption) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 034bebf..b91fa37 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -572,6 +572,7 @@ struct _virDomainDiskDef {
virDomainBlockIoTuneInfo blkdeviotune;
char *serial;
+ char *wwn;
int cachemode;
int error_policy; /* enum virDomainDiskErrorPolicy */
int rerror_policy; /* enum virDomainDiskErrorPolicy */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6f14763..a8274d0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1240,6 +1240,7 @@ virStrToLong_ull;
virStrcpy;
virStrncpy;
virTrimSpaces;
+virValidateWWN;
virVasprintf;
diff --git a/src/util/util.c b/src/util/util.c
index 91eab72..8b1f0dc 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -3052,3 +3052,20 @@ bool virIsDevMapperDevice(const char *dev_name ATTRIBUTE_UNUSED)
return false;
}
#endif
+
+bool
+virValidateWWN(const char *wwn) {
+ int i;
+
+ for (i = 0; wwn[i]; i++)
+ if (!c_isxdigit(wwn[i]))
+ break;
+
+ if (i != 16 || wwn[i]) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Malformed wwn: %s"));
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/util/util.h b/src/util/util.h
index a5d892d..0c0efad 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -277,4 +277,6 @@ int virBuildPathInternal(char **path, ...) ATTRIBUTE_SENTINEL;
bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1);
+bool virValidateWWN(const char *wwn);
+
#endif /* __VIR_UTIL_H__ */
--
1.7.7.3