[CRIU] [PATCH 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 04:17:26 PDT 2016



On 07/14/2016 01:54 PM, Pavel Emelyanov wrote:
> On 07/13/2016 04:06 PM, Pavel Tikhomirov wrote:
>>
>>
>> On 07/13/2016 03:53 PM, Pavel Emelyanov wrote:
>>> On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
>>>> 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
>>>>
>>>> Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
>>>> ---
>>>>  criu/ipc_ns.c        | 33 ++++++++++++++++++++++++++++++++-
>>>>  images/ipc-var.proto |  3 +++
>>>>  2 files changed, 35 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
>>>> index 02fb9a0..c75cfb5 100644
>>>> --- a/criu/ipc_ns.c
>>>> +++ b/criu/ipc_ns.c
>>>> @@ -313,6 +313,12 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
>>>>  		{ "fs/mqueue/msgsize_default",	&e->mq_msgsize_default,	CTL_U32 },
>>>>  	};
>>>>
>>>> +	struct sysctl_req req_next[] = {
>>>> +		{ "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 },
>>>> +	};
>>>> +
>>>>  	int ret;
>>>>
>>>>  	ret = sysctl_op(req, ARRAY_SIZE(req), op, CLONE_NEWIPC);
>>>> @@ -324,8 +330,19 @@ 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 && (ret = sysctl_op(&req_next[0], 1, op, CLONE_NEWIPC)))
>>>> +		return ret;
>>>> +	if (e->has_sem_next_id && (ret = sysctl_op(&req_next[1], 1, op, CLONE_NEWIPC)))
>>>> +		return ret;
>>>> +	if (e->has_shm_next_id && (ret = sysctl_op(&req_next[2], 1, op, CLONE_NEWIPC)))
>>>
>>> Can we do it in one call to sysctl_op?
>>
>> We will have to create proper req array for all possible combinations of
>> has_xxx_next_id, for (1,0,1) that don't look good from my POV.
>
> Just declare the op-s array big enough and
>
> if (e->has_foo_next)
> 	ops[i++] = { "kernel/foo_next", &e->foo_next, CTL_U32 };
>
> or smth like this.

We can do something like this only in declaration AFAIK, we will need to 
set each structure value one by one or copy from req_next to some 
secondary req.

>
>>>
>>>> +		return ret;
>>>> +	return 0;
>>>>  }
>>>>
>>>>  /*
>>>> @@ -421,6 +438,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 +448,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;
>>>>  }
>>>>
>>>
>>
>

-- 
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.


More information about the CRIU mailing list