summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorOsier Yang <jyang@redhat.com>2012-09-11 16:57:02 +0800
committerOsier Yang <jyang@redhat.com>2012-09-18 14:42:33 +0800
commitfacc1c005738d745536c2d525187a54a75978db7 (patch)
treedd5ad5652c7646bb0f492d1bf96d6f9f4c22b0c5 /src/util
parentschema: Add schema for disk <wwn> (diff)
downloadlibvirt-facc1c005738d745536c2d525187a54a75978db7.tar.gz
libvirt-facc1c005738d745536c2d525187a54a75978db7.tar.bz2
libvirt-facc1c005738d745536c2d525187a54a75978db7.zip
conf: Parse and format disk <wwn>
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>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.c17
-rw-r--r--src/util/util.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c
index 91eab7210..8b1f0dc5b 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 a5d892dd4..0c0efad15 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__ */