-- 2 new macroses brought in: MIN_OF and MUL_BOUND; -- Actually NOT needed local variables removed. --- include/util.h | 5 +++++ src/vzcfgscale.c | 34 ++++++---------------------------- 2 files changed, 11 insertions(+), 28 deletions(-)
diff --git a/include/util.h b/include/util.h index 0f87e6e..c1175d6 100644 --- a/include/util.h +++ b/include/util.h @@ -99,6 +99,11 @@ int vzctl_get_normalized_guid(const char *str, char *buf, int len); #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) +#define MIN_OF(arg_A, arg_B) ( ( (arg_A) < (arg_B) ) ? (arg_A) : (arg_B) ) + +#define MUL_BOUND(arg_2mult, arg_mult_by, arg_max2use) \ + ( arg_2mult = MIN_OF( (arg_2mult) * (arg_mult_by), (arg_max2use) ) ) + /* Usage: printf("MAC=" MAC2STR_FMT, MAC2STR(dev)); */ #define MAC2STR_FMT "%02X:%02X:%02X:%02X:%02X:%02X" #define MAC2STR(dev) \ diff --git a/src/vzcfgscale.c b/src/vzcfgscale.c index 414aec5..7fc466a 100644 --- a/src/vzcfgscale.c +++ b/src/vzcfgscale.c @@ -73,32 +73,16 @@ do { \ void scale(float ubc_k, float cpu_k, float disk_k, float net_k, struct CParam *param) { - unsigned long val0, val1; - #define SCALE_UBC(name, k) \ if (param->name != NULL) { \ - val0 = param->name[0]; \ - val1 = param->name[1]; \ - if (val0 != LONG_MAX) \ - val0 *= k; \ - if (val0 > LONG_MAX) \ - val0 = LONG_MAX; \ - if (val1 != LONG_MAX) \ - val1 *= k; \ - if (val1 > LONG_MAX) \ - val1 = LONG_MAX; \ - param->name[0] = val0; \ - param->name[1] = val1; \ + MUL_BOUND(param->name[0], k, LONG_MAX); \ + MUL_BOUND(param->name[1], k, LONG_MAX); \ } else #define SCALE_PARAM(name, k) \ if (param->name != NULL) { \ - param->name[0] *= k; \ - param->name[1] *= k; \ - if (param->name[0] > LONG_MAX) \ - param->name[0] = LONG_MAX; \ - if (param->name[1] > LONG_MAX) \ - param->name[1] = LONG_MAX; \ + MUL_BOUND(param->name[0], k, LONG_MAX); \ + MUL_BOUND(param->name[1], k, LONG_MAX); \ } else if (ubc_k) @@ -126,11 +110,7 @@ if (param->name != NULL) { \ SCALE_UBC(numiptent, ubc_k); } if (cpu_k && param->cpu_units != NULL) - { - *param->cpu_units *= cpu_k; - if (*param->cpu_units > MAXCPUUNITS) - *param->cpu_units = MAXCPUUNITS; - } + MUL_BOUND(*param->cpu_units, cpu_k, MAXCPUUNITS); if (disk_k) { SCALE_PARAM(quota_block, disk_k); @@ -144,9 +124,7 @@ if (param->name != NULL) { \ { if (p->val2 == NULL) continue; - *p->val2 *= net_k; - if (*p->val2 > LONG_MAX) - *p->val2 = LONG_MAX; + MUL_BOUND(*p->val2, net_k, LONG_MAX); } } -- 1.7.9.5 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel