提交 5998b3c5 编写于 作者: P Peter Krempa

xen: Move xenParseSxprVifRate to xen_common

It's the only place where it's used.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 228f7ed1
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
xenGetDomIdFromSxpr; xenGetDomIdFromSxpr;
xenGetDomIdFromSxprString; xenGetDomIdFromSxprString;
xenParseSxprChar; xenParseSxprChar;
xenParseSxprVifRate;
# xenconfig/xen_xm.h # xenconfig/xen_xm.h
xenFormatXM; xenFormatXM;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <config.h> #include <config.h>
#include <regex.h>
#include "internal.h" #include "internal.h"
#include "virerror.h" #include "virerror.h"
#include "virconf.h" #include "virconf.h"
...@@ -926,6 +928,66 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge) ...@@ -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 static virDomainNetDefPtr
xenParseVif(char *entry, const char *vif_typename) xenParseVif(char *entry, const char *vif_typename)
{ {
......
...@@ -22,8 +22,6 @@ ...@@ -22,8 +22,6 @@
#include <config.h> #include <config.h>
#include <regex.h>
#include "internal.h" #include "internal.h"
#include "virerror.h" #include "virerror.h"
#include "virconf.h" #include "virconf.h"
...@@ -210,63 +208,3 @@ xenParseSxprChar(const char *value, ...@@ -210,63 +208,3 @@ xenParseSxprChar(const char *value,
virDomainChrDefFree(def); virDomainChrDefFree(def);
return NULL; 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;
}
...@@ -32,5 +32,3 @@ int xenGetDomIdFromSxprString(const char *sexpr, int *id); ...@@ -32,5 +32,3 @@ int xenGetDomIdFromSxprString(const char *sexpr, int *id);
int xenGetDomIdFromSxpr(const struct sexpr *root, int *id); int xenGetDomIdFromSxpr(const struct sexpr *root, int *id);
virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty); virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty);
int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册