Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

vzsplit, vzctl set: better output of UBC parameters

* src/lib/util.c: introduce ubcstr() function, which
  * doesn't output limit if it is equal to barrier
  * output unlimited as 'unlimited'

* vzsplit: use ubcstr() to output config

* vzctl set: use ubcstr() to save UBC parameters

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
  • Loading branch information...
commit acaf07f95f7d7c5fa20b5e61d4360c27dedaacac 1 parent e274a52
@kolyshkin kolyshkin authored
View
2  include/util.h
@@ -64,6 +64,8 @@ void get_osrelease(vps_res *res);
int get_running_ve_list(envid_t **ves);
int ve_in_list(envid_t *list, int size, envid_t ve);
+const char* ubcstr(unsigned long bar, unsigned long lim);
+
#define logger_enomem(log_level, err, size, file, line) \
logger(log_level, err, "%s:%i: Can't allocate %lu bytes", \
file, line, (unsigned long)size)
View
4 src/lib/config.c
@@ -662,8 +662,8 @@ static int store_ub(vps_param *old_p, vps_param *vps_p,
#define ADD_UB_PARAM(res, id) \
if (ub->res != NULL) { \
conf = conf_get_by_id(config, id); \
- snprintf(buf, sizeof(buf), "%s=\"%lu:%lu\"", conf->name, \
- ub->res[0], ub->res[1]); \
+ snprintf(buf, sizeof(buf), "%s=\"%s\"", conf->name, \
+ ubcstr(ub->res[0], ub->res[1])); \
if (add_str_param(conf_h, buf)) \
return ERR_NOMEM; \
}
View
24 src/lib/util.c
@@ -724,3 +724,27 @@ int ve_in_list(envid_t *list, int size, envid_t ve)
return bsearch(&ve, list, size, sizeof(envid_t),
envid_sort_fn) != NULL;
}
+
+
+const char* ubcstr(unsigned long bar, unsigned long lim)
+{
+ static char str[64];
+ char *p = str;
+ char *e = p + sizeof(str) - 1;
+
+#define PRINT_UBC(val) \
+ if (val == LONG_MAX) \
+ p += snprintf(p, e - p, "unlimited"); \
+ else \
+ p += snprintf(p, e - p, "%lu", val)
+
+ PRINT_UBC(bar);
+
+ if (bar == lim)
+ return str;
+
+ *p++=':';
+ PRINT_UBC(lim);
+
+ return str;
+}
View
7 src/vzsplit.c
@@ -221,9 +221,10 @@ int lconv(char *name)
fprintf(fp, "\n# Secondary parameters\n");
else if (i ==LOCKPG)
fprintf(fp, "\n# Auxiliary parameters\n");
- fprintf(fp, "%s=\"%lu:%lu\"\n", ubcnames[i],
- (unsigned long) params[i].bar,
- (unsigned long) params[i].lim);
+ fprintf(fp, "%s=\"%s\"\n",
+ ubcnames[i], ubcstr(
+ (unsigned long)params[i].bar,
+ (unsigned long)params[i].lim));
}
fprintf(fp, "CPUUNITS=\"%d\"\n", DEF_CPUUNITS);
if (name) {
Please sign in to comment.
Something went wrong with that request. Please try again.