提交 12459d1e 编写于 作者: M Matthias Bolte

xen: Replace statsErrorFunc with a macro

Also mark error messages in block_stats.c for translation, add the
new macro to the msg_gen functions in cfg.mk and add block_stats.c
to po/POTFILES.in
上级 60d769a1
...@@ -420,6 +420,7 @@ msg_gen_function += xenUnifiedError ...@@ -420,6 +420,7 @@ msg_gen_function += xenUnifiedError
msg_gen_function += xenXMError msg_gen_function += xenXMError
msg_gen_function += VIR_ERROR msg_gen_function += VIR_ERROR
msg_gen_function += VIR_ERROR0 msg_gen_function += VIR_ERROR0
msg_gen_function += statsError
# Uncomment the following and run "make syntax-check" to see diagnostics # Uncomment the following and run "make syntax-check" to see diagnostics
# that are not yet marked for translation, but that need to be rewritten # that are not yet marked for translation, but that need to be rewritten
......
...@@ -114,6 +114,7 @@ src/vbox/vbox_tmpl.c ...@@ -114,6 +114,7 @@ src/vbox/vbox_tmpl.c
src/vmware/vmware_conf.c src/vmware/vmware_conf.c
src/vmware/vmware_driver.c src/vmware/vmware_driver.c
src/vmx/vmx.c src/vmx/vmx.c
src/xen/block_stats.c
src/xen/xen_driver.c src/xen/xen_driver.c
src/xen/xen_hypervisor.c src/xen/xen_hypervisor.c
src/xen/xen_inotify.c src/xen/xen_inotify.c
......
...@@ -31,34 +31,12 @@ ...@@ -31,34 +31,12 @@
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX # define VIR_FROM_THIS VIR_FROM_STATS_LINUX
/**
* statsErrorFunc:
* @conn: the connection # define statsError(code, ...) \
* @error: the error number virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, __FUNCTION__, \
* @func: the function failing __LINE__, __VA_ARGS__)
* @info: extra information string
* @value: extra information number
*
* Handle a stats error.
*/
static void
statsErrorFunc (virErrorNumber error, const char *func, const char *info,
int value)
{
char fullinfo[1000];
const char *errmsg;
errmsg = virErrorMsg(error, info);
if (func != NULL) {
snprintf(fullinfo, sizeof (fullinfo) - 1, "%s: %s", func, info);
fullinfo[sizeof (fullinfo) - 1] = 0;
info = fullinfo;
}
virRaiseError(NULL, NULL, VIR_FROM_STATS_LINUX, error,
VIR_ERR_ERROR,
errmsg, info, NULL, value, 0, errmsg, info,
value);
}
/*-------------------- Xen: block stats --------------------*/ /*-------------------- Xen: block stats --------------------*/
...@@ -194,8 +172,9 @@ read_bd_stats(xenUnifiedPrivatePtr priv, ...@@ -194,8 +172,9 @@ read_bd_stats(xenUnifiedPrivatePtr priv,
if (stats->rd_req == -1 && stats->rd_bytes == -1 && if (stats->rd_req == -1 && stats->rd_bytes == -1 &&
stats->wr_req == -1 && stats->wr_bytes == -1 && stats->wr_req == -1 && stats->wr_bytes == -1 &&
stats->errs == -1) { stats->errs == -1) {
statsErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__, statsError(VIR_ERR_INTERNAL_ERROR,
"Failed to read any block statistics", domid); _("Failed to read any block statistics for domain %d"),
domid);
return -1; return -1;
} }
...@@ -207,8 +186,9 @@ read_bd_stats(xenUnifiedPrivatePtr priv, ...@@ -207,8 +186,9 @@ read_bd_stats(xenUnifiedPrivatePtr priv,
stats->wr_req == 0 && stats->wr_bytes == 0 && stats->wr_req == 0 && stats->wr_bytes == 0 &&
stats->errs == 0 && stats->errs == 0 &&
!check_bd_connected (priv, device, domid)) { !check_bd_connected (priv, device, domid)) {
statsErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__, statsError(VIR_ERR_INTERNAL_ERROR,
"Frontend block device not connected", domid); _("Frontend block device not connected for domain %d"),
domid);
return -1; return -1;
} }
...@@ -217,18 +197,18 @@ read_bd_stats(xenUnifiedPrivatePtr priv, ...@@ -217,18 +197,18 @@ read_bd_stats(xenUnifiedPrivatePtr priv,
*/ */
if (stats->rd_bytes > 0) { if (stats->rd_bytes > 0) {
if (stats->rd_bytes >= ((unsigned long long)1)<<(63-9)) { if (stats->rd_bytes >= ((unsigned long long)1)<<(63-9)) {
statsErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__, statsError(VIR_ERR_INTERNAL_ERROR,
"stats->rd_bytes would overflow 64 bit counter", _("stats->rd_bytes would overflow 64 bit counter for domain %d"),
domid); domid);
return -1; return -1;
} }
stats->rd_bytes *= 512; stats->rd_bytes *= 512;
} }
if (stats->wr_bytes > 0) { if (stats->wr_bytes > 0) {
if (stats->wr_bytes >= ((unsigned long long)1)<<(63-9)) { if (stats->wr_bytes >= ((unsigned long long)1)<<(63-9)) {
statsErrorFunc(VIR_ERR_INTERNAL_ERROR, __FUNCTION__, statsError(VIR_ERR_INTERNAL_ERROR,
"stats->wr_bytes would overflow 64 bit counter", _("stats->wr_bytes would overflow 64 bit counter for domain %d"),
domid); domid);
return -1; return -1;
} }
stats->wr_bytes *= 512; stats->wr_bytes *= 512;
...@@ -346,20 +326,21 @@ xenLinuxDomainDeviceID(int domid, const char *path) ...@@ -346,20 +326,21 @@ xenLinuxDomainDeviceID(int domid, const char *path)
* beginning of the strings for better error messages * beginning of the strings for better error messages
*/ */
else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/sd")) else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/sd"))
statsErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, statsError(VIR_ERR_INVALID_ARG,
"invalid path, device names must be in the range sda[1-15] - sdiv[1-15]", _("invalid path, device names must be in the range "
domid); "sda[1-15] - sdiv[1-15] for domain %d"), domid);
else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/hd")) else if (strlen(mod_path) >= 7 && STRPREFIX(mod_path, "/dev/hd"))
statsErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, statsError(VIR_ERR_INVALID_ARG,
"invalid path, device names must be in the range hda[1-63] - hdt[1-63]", _("invalid path, device names must be in the range "
domid); "hda[1-63] - hdt[1-63] for domain %d"), domid);
else if (strlen(mod_path) >= 8 && STRPREFIX(mod_path, "/dev/xvd")) else if (strlen(mod_path) >= 8 && STRPREFIX(mod_path, "/dev/xvd"))
statsErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, statsError(VIR_ERR_INVALID_ARG,
"invalid path, device names must be in the range xvda[1-15] - xvdiz[1-15]", _("invalid path, device names must be in the range "
domid); "xvda[1-15] - xvdiz[1-15] for domain %d"), domid);
else else
statsErrorFunc(VIR_ERR_INVALID_ARG, __FUNCTION__, statsError(VIR_ERR_INVALID_ARG,
"unsupported path, use xvdN, hdN, or sdN", domid); _("unsupported path, use xvdN, hdN, or sdN for domain %d"),
domid);
VIR_FREE(mod_path); VIR_FREE(mod_path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册