Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

vzcfgvalidate: add support for vswap configs

For vswap config, these checks are performed:
1. only check physpages and swappages
2. barrier should be zero for both
3. physpages.limit should not exceed host RAM
4. swappages.limit should not exceed host swap

Everything else we just ignore.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
  • Loading branch information...
commit 103382b8015e681011eeec04c3b38638e04fe593 1 parent 1d41510
Kirill Kolyshkin kolyshkin authored
Showing with 75 additions and 5 deletions.
  1. +1 −1  include/validate.h
  2. +72 −3 src/validate.c
  3. +2 −1  src/vzcfgvalidate.c
2  include/validate.h
View
@@ -57,7 +57,7 @@ struct mem_struct {
struct ub_struct;
struct vps_res;
-int validate(struct vps_res *param, int recover, int ask);
+int validate(struct vps_res *param, int recover, int ask, int vswap);
int calc_ve_utilization(struct ub_struct *param, struct CRusage *rusage,
struct mem_struct *mem, int numerator);
int calc_ve_commitment(struct ub_struct *param, struct CRusage *rusage,
75 src/validate.c
View
@@ -79,7 +79,76 @@ static int check_param(struct ub_struct *param, int log)
return ret;
}
-int validate(vps_res *param, int recover, int ask)
+#define SET_MES(val) logger(0, 0, "set to %lu", val);
+#define SET2_MES(val1, val2) logger(0, 0,"set to %lu:%lu", val1, val2);
+
+/** Validate vswap config
+ * Current ideas are:
+ * 1. only check physpages and swappages
+ * 2. barrier should be zero for both
+ * 3. physpages.limit should not exceed host RAM
+ * 4. swappages.limit should not exceed host swap
+ */
+static int validate_vswap(vps_res *param, int recover, int ask)
+{
+ struct ub_struct *ub = &param->ub;
+ int changed = 0;
+ int ret = 0;
+ unsigned long long tmp;
+ unsigned long ram, swap;
+
+#define CHECK_VSWAP(name, limit) \
+ if (ub->name != NULL) { \
+ if (ub->name[0] != 0) { \
+ logger(-1, 0, "Error: " #name ".bar should be " \
+ "= 0 (currently, %lu)", \
+ ub->name[0]); \
+ if (ask || recover) { \
+ SET_MES((unsigned long) 0); \
+ if (ask) \
+ recover = read_yn(); \
+ if (recover) { \
+ ub->name[0] = 0; \
+ changed++; \
+ } \
+ } \
+ if (!recover) ret = 1; \
+ } \
+ if (ub->name[1] > limit) { \
+ logger(-1, 0, "Warning: " #name ".lim should " \
+ "be <= %lu (currently, %lu)", \
+ limit, ub->name[1]); \
+ if (ask || recover) { \
+ SET_MES((unsigned long) limit); \
+ if (ask) \
+ recover = read_yn(); \
+ if (recover) { \
+ ub->name[1] = limit; \
+ changed++; \
+ } \
+ } \
+ if (!recover) ret = 1; \
+ } \
+ } else { \
+ logger(-1, 0, "Error: parameter " #name " not found"); \
+ ret = 1; \
+ }
+
+ if (get_mem(&tmp) < 0)
+ return -1;
+ ram = tmp / page_size;
+
+ if (get_swap(&tmp) < 0)
+ return -1;
+ swap = tmp / page_size;
+
+ CHECK_VSWAP(physpages, ram);
+ CHECK_VSWAP(swappages, swap);
+
+ return ret;
+}
+
+int validate(vps_res *param, int recover, int ask, int vswap)
{
unsigned long avnumproc;
int ret = 0;
@@ -88,8 +157,8 @@ int validate(vps_res *param, int recover, int ask)
int changed = 0;
struct ub_struct *ub;
-#define SET_MES(val) logger(0, 0, "set to %lu", val);
-#define SET2_MES(val1, val2) logger(0, 0,"set to %lu:%lu", val1, val2);
+ if (vswap)
+ return validate_vswap(param, recover, ask);
#define CHECK_BL(x, name) \
if (x != NULL) { \
3  src/vzcfgvalidate.c
View
@@ -94,7 +94,8 @@ int main(int argc, char **argv)
/* Merge configs (needed for DISK_QUOTA value, maybe others) */
merge_vps_param(gparam, param);
- if (!(ret = validate(&param->res, recover, ask))) {
+ if (!(ret = validate(&param->res, recover, ask,
+ is_vswap_config(&param->res.ub)))) {
if (recover || ask)
if (vps_save_config(0, infile, param, NULL, NULL))
goto err;
Please sign in to comment.
Something went wrong with that request. Please try again.