[CRIU] [PATCH v3 3/4] ipc/sysctl: c/r kernel.{msg_next_id, sem_next_id, shm_next_id}

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Thu Jul 14 07:20:38 PDT 2016


These are only three left in ipc_kern_table which we haven't
checkpointed yet, I'm not sure if somebody really uses them
except criu, but to be consistent, beter not to change them
while c/r.

*We have these sysctls writable in VZ7 CT.
https://jira.sw.ru/browse/PSBM-48397

v3: do one sysctl_op for all xxx_next_id(as sysctl_op is quiet slow)

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/ipc_ns.c        | 38 +++++++++++++++++++++++++++++++++++++-
 images/ipc-var.proto |  3 +++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
index 02fb9a0..d2eda22 100644
--- a/criu/ipc_ns.c
+++ b/criu/ipc_ns.c
@@ -313,6 +313,15 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
 		{ "fs/mqueue/msgsize_default",	&e->mq_msgsize_default,	CTL_U32 },
 	};
 
+	struct sysctl_req req_next_tmp[] = {
+		{ "kernel/msg_next_id", &e->msg_next_id, CTL_U32 },
+		{ "kernel/sem_next_id", &e->sem_next_id, CTL_U32 },
+		{ "kernel/shm_next_id", &e->shm_next_id, CTL_U32 },
+	};
+
+	struct sysctl_req req_next[3];
+	int nr = 0;
+
 	int ret;
 
 	ret = sysctl_op(req, ARRAY_SIZE(req), op, CLONE_NEWIPC);
@@ -324,8 +333,21 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
 		return 0;
 	}
 
-	return sysctl_op(req_mq, ARRAY_SIZE(req_mq) - (e->has_mq_msg_default ? 0 : 2),
+	ret = sysctl_op(req_mq, ARRAY_SIZE(req_mq) - (e->has_mq_msg_default ? 0 : 2),
 	                 op, CLONE_NEWIPC);
+	if (ret)
+		return ret;
+
+	/* Skip xxx_next_id which were -1 or haven't existed on dump */
+	if (e->has_msg_next_id)
+		req_next[nr++] = req_next_tmp[0];
+	if (e->has_sem_next_id)
+		req_next[nr++] = req_next_tmp[1];
+	if (e->has_shm_next_id)
+		req_next[nr++] = req_next_tmp[2];
+	if (nr)
+		return sysctl_op(req_next, nr, op, CLONE_NEWIPC);
+	return 0;
 }
 
 /*
@@ -421,6 +443,9 @@ static int dump_ipc_var(struct cr_img *img)
 		goto err;
 	var.has_mq_msg_default = true;
 	var.has_mq_msgsize_default = true;
+	var.has_msg_next_id = true;
+	var.has_sem_next_id = true;
+	var.has_shm_next_id = true;
 
 	ret = ipc_sysctl_req(&var, CTL_READ);
 	if (ret < 0) {
@@ -428,6 +453,17 @@ static int dump_ipc_var(struct cr_img *img)
 		goto err;
 	}
 
+	/*
+	 * One can not write to msg_next_xxx sysctls -1,
+	 * which is their initial value
+	 */
+	if (var.msg_next_id == -1)
+		var.has_msg_next_id = false;
+	if (var.sem_next_id == -1)
+		var.has_sem_next_id = false;
+	if (var.shm_next_id == -1)
+		var.has_shm_next_id = false;
+
 	ret = pb_write_one(img, &var, PB_IPC_VAR);
 	if (ret < 0) {
 		pr_err("Failed to write IPC variables\n");
diff --git a/images/ipc-var.proto b/images/ipc-var.proto
index 153b167..4fd8362 100644
--- a/images/ipc-var.proto
+++ b/images/ipc-var.proto
@@ -13,4 +13,7 @@ message ipc_var_entry {
 	required uint32			mq_msgsize_max		= 12;
 	optional uint32			mq_msg_default		= 13;
 	optional uint32			mq_msgsize_default	= 14;
+	optional uint32			msg_next_id		= 15;
+	optional uint32			sem_next_id		= 16;
+	optional uint32			shm_next_id		= 17;
 }
-- 
2.5.5



More information about the CRIU mailing list