diff --git a/src/libvirt_xenconfig.syms b/src/libvirt_xenconfig.syms index 77701c14d9b3faa584371a653cb711fae7dfb97d..603f1ce420489637fe6cea3cd2465ea1f06df755 100644 --- a/src/libvirt_xenconfig.syms +++ b/src/libvirt_xenconfig.syms @@ -6,7 +6,6 @@ xenGetDomIdFromSxpr; xenGetDomIdFromSxprString; xenParseSxprChar; -xenParseSxprVifRate; # xenconfig/xen_xm.h xenFormatXM; diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 3e86491903c136bf063b0be3482220ba806bb99d..a647088e06f1c9e0b70f65eed314e5ec5cf98f7c 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -24,6 +24,8 @@ #include +#include + #include "internal.h" #include "virerror.h" #include "virconf.h" @@ -926,6 +928,66 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge) } +static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$"; + +static int +xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec) +{ + char *trate = NULL; + char *p; + regex_t rec; + int err; + char *suffix; + unsigned long long tmp; + int ret = -1; + + if (VIR_STRDUP(trate, rate) < 0) + return -1; + + p = strchr(trate, '@'); + if (p != NULL) + *p = 0; + + err = regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB); + if (err != 0) { + char error[100]; + regerror(err, &rec, error, sizeof(error)); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to compile regular expression '%s': %s"), + vif_bytes_per_sec_re, error); + goto cleanup; + } + + if (regexec(&rec, trate, 0, NULL, 0)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid rate '%s' specified"), rate); + goto cleanup; + } + + if (virStrToLong_ull(rate, &suffix, 10, &tmp)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse rate '%s'"), rate); + goto cleanup; + } + + if (*suffix == 'G') + tmp *= 1024 * 1024; + else if (*suffix == 'M') + tmp *= 1024; + + if (*suffix == 'b' || *(suffix + 1) == 'b') + tmp /= 8; + + *kbytes_per_sec = tmp; + ret = 0; + + cleanup: + regfree(&rec); + VIR_FREE(trate); + return ret; +} + + static virDomainNetDefPtr xenParseVif(char *entry, const char *vif_typename) { diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 8876350b8fde290063c52d14ec7cb7adef2bac84..953909e7b422678f6463f30c38d8d3a7a7c8288a 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -22,8 +22,6 @@ #include -#include - #include "internal.h" #include "virerror.h" #include "virconf.h" @@ -210,63 +208,3 @@ xenParseSxprChar(const char *value, virDomainChrDefFree(def); return NULL; } - - -static const char *vif_bytes_per_sec_re = "^[0-9]+[GMK]?[Bb]/s$"; - -int -xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec) -{ - char *trate = NULL; - char *p; - regex_t rec; - int err; - char *suffix; - unsigned long long tmp; - int ret = -1; - - if (VIR_STRDUP(trate, rate) < 0) - return -1; - - p = strchr(trate, '@'); - if (p != NULL) - *p = 0; - - err = regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED|REG_NOSUB); - if (err != 0) { - char error[100]; - regerror(err, &rec, error, sizeof(error)); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regular expression '%s': %s"), - vif_bytes_per_sec_re, error); - goto cleanup; - } - - if (regexec(&rec, trate, 0, NULL, 0)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid rate '%s' specified"), rate); - goto cleanup; - } - - if (virStrToLong_ull(rate, &suffix, 10, &tmp)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to parse rate '%s'"), rate); - goto cleanup; - } - - if (*suffix == 'G') - tmp *= 1024 * 1024; - else if (*suffix == 'M') - tmp *= 1024; - - if (*suffix == 'b' || *(suffix + 1) == 'b') - tmp /= 8; - - *kbytes_per_sec = tmp; - ret = 0; - - cleanup: - regfree(&rec); - VIR_FREE(trate); - return ret; -} diff --git a/src/xenconfig/xen_sxpr.h b/src/xenconfig/xen_sxpr.h index 54dfcbb53da536b5f805f8ed75a148f4bbfadfb2..f7112bc6eefbda625066c95f2684925539f89336 100644 --- a/src/xenconfig/xen_sxpr.h +++ b/src/xenconfig/xen_sxpr.h @@ -32,5 +32,3 @@ int xenGetDomIdFromSxprString(const char *sexpr, int *id); int xenGetDomIdFromSxpr(const struct sexpr *root, int *id); virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty); - -int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec);