[v2,resent,1/4] ipc/sysctl: c/r fs.mqueue.msg_default fs.mqueue.msgsize_default

Submitted by Pavel Tikhomirov on July 4, 2016, 7:47 a.m.

Details

Message ID 1467618428-1362-2-git-send-email-ptikhomirov@virtuozzo.com
State Rejected
Series "ipc/sysctls: add more sysctls to cr"
Headers show

Commit Message

Pavel Tikhomirov July 4, 2016, 7:47 a.m.
we already have 3/5 fs.mqueue.xxx sysctls so why not have all:

/proc/sys/fs/mqueue/msg_default is  a read/write  file for
setting/getting the default number of messages in a queue value
if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
the default value is initialized msg_max.

/proc/sys/fs/mqueue/msgsize_default is a read/write file for
setting/getting the default message size value if attr parameter
of mq_open(2) is NULL. If it exceed msgsize_max, the default
value is initialized msgsize_max.

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

v2: remove check if kernel has sysctls as we do not support such an
old kernel(v3.5)

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

Patch hide | download patch | download mbox

diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
index 19dfb72..02fb9a0 100644
--- a/criu/ipc_ns.c
+++ b/criu/ipc_ns.c
@@ -309,6 +309,8 @@  static int ipc_sysctl_req(IpcVarEntry *e, int op)
 		{ "fs/mqueue/queues_max",	&e->mq_queues_max,	CTL_U32 },
 		{ "fs/mqueue/msg_max",		&e->mq_msg_max,		CTL_U32 },
 		{ "fs/mqueue/msgsize_max",	&e->mq_msgsize_max,	CTL_U32 },
+		{ "fs/mqueue/msg_default",	&e->mq_msg_default,	CTL_U32 },
+		{ "fs/mqueue/msgsize_default",	&e->mq_msgsize_default,	CTL_U32 },
 	};
 
 	int ret;
@@ -322,7 +324,8 @@  static int ipc_sysctl_req(IpcVarEntry *e, int op)
 		return 0;
 	}
 
-	return sysctl_op(req_mq, ARRAY_SIZE(req_mq), op, CLONE_NEWIPC);
+	return sysctl_op(req_mq, ARRAY_SIZE(req_mq) - (e->has_mq_msg_default ? 0 : 2),
+	                 op, CLONE_NEWIPC);
 }
 
 /*
@@ -416,6 +419,8 @@  static int dump_ipc_var(struct cr_img *img)
 	var.sem_ctls	= xmalloc(pb_repeated_size(&var, sem_ctls));
 	if (!var.sem_ctls)
 		goto err;
+	var.has_mq_msg_default = true;
+	var.has_mq_msgsize_default = true;
 
 	ret = ipc_sysctl_req(&var, CTL_READ);
 	if (ret < 0) {
diff --git a/images/ipc-var.proto b/images/ipc-var.proto
index 4acda69..153b167 100644
--- a/images/ipc-var.proto
+++ b/images/ipc-var.proto
@@ -11,4 +11,6 @@  message ipc_var_entry {
 	required uint32			mq_queues_max		= 10;
 	required uint32			mq_msg_max		= 11;
 	required uint32			mq_msgsize_max		= 12;
+	optional uint32			mq_msg_default		= 13;
+	optional uint32			mq_msgsize_default	= 14;
 }

Comments

Pavel Emelianov July 13, 2016, 12:52 p.m.
On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
> we already have 3/5 fs.mqueue.xxx sysctls so why not have all:
> 
> /proc/sys/fs/mqueue/msg_default is  a read/write  file for
> setting/getting the default number of messages in a queue value
> if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
> the default value is initialized msg_max.
> 
> /proc/sys/fs/mqueue/msgsize_default is a read/write file for
> setting/getting the default message size value if attr parameter
> of mq_open(2) is NULL. If it exceed msgsize_max, the default
> value is initialized msgsize_max.
> 
> *We have these sysctls writable in VZ7 CT.

What about upstream kernel? Are these writable for it as well? If yes, how
has it happened that vzkernel DIDN'T have them as such at some point?

> https://jira.sw.ru/browse/PSBM-48397
> 
> v2: remove check if kernel has sysctls as we do not support such an
> old kernel(v3.5)
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> ---
>  criu/ipc_ns.c        | 7 ++++++-
>  images/ipc-var.proto | 2 ++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
> index 19dfb72..02fb9a0 100644
> --- a/criu/ipc_ns.c
> +++ b/criu/ipc_ns.c
> @@ -309,6 +309,8 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
>  		{ "fs/mqueue/queues_max",	&e->mq_queues_max,	CTL_U32 },
>  		{ "fs/mqueue/msg_max",		&e->mq_msg_max,		CTL_U32 },
>  		{ "fs/mqueue/msgsize_max",	&e->mq_msgsize_max,	CTL_U32 },
> +		{ "fs/mqueue/msg_default",	&e->mq_msg_default,	CTL_U32 },
> +		{ "fs/mqueue/msgsize_default",	&e->mq_msgsize_default,	CTL_U32 },
>  	};
>  
>  	int ret;
> @@ -322,7 +324,8 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
>  		return 0;
>  	}
>  
> -	return sysctl_op(req_mq, ARRAY_SIZE(req_mq), op, CLONE_NEWIPC);
> +	return sysctl_op(req_mq, ARRAY_SIZE(req_mq) - (e->has_mq_msg_default ? 0 : 2),
> +	                 op, CLONE_NEWIPC);
>  }
>  
>  /*
> @@ -416,6 +419,8 @@ static int dump_ipc_var(struct cr_img *img)
>  	var.sem_ctls	= xmalloc(pb_repeated_size(&var, sem_ctls));
>  	if (!var.sem_ctls)
>  		goto err;
> +	var.has_mq_msg_default = true;
> +	var.has_mq_msgsize_default = true;
>  
>  	ret = ipc_sysctl_req(&var, CTL_READ);
>  	if (ret < 0) {
> diff --git a/images/ipc-var.proto b/images/ipc-var.proto
> index 4acda69..153b167 100644
> --- a/images/ipc-var.proto
> +++ b/images/ipc-var.proto
> @@ -11,4 +11,6 @@ message ipc_var_entry {
>  	required uint32			mq_queues_max		= 10;
>  	required uint32			mq_msg_max		= 11;
>  	required uint32			mq_msgsize_max		= 12;
> +	optional uint32			mq_msg_default		= 13;
> +	optional uint32			mq_msgsize_default	= 14;
>  }
>
Pavel Tikhomirov July 13, 2016, 12:58 p.m.
On 07/13/2016 03:52 PM, Pavel Emelyanov wrote:
> On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
>> we already have 3/5 fs.mqueue.xxx sysctls so why not have all:
>>
>> /proc/sys/fs/mqueue/msg_default is  a read/write  file for
>> setting/getting the default number of messages in a queue value
>> if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
>> the default value is initialized msg_max.
>>
>> /proc/sys/fs/mqueue/msgsize_default is a read/write file for
>> setting/getting the default message size value if attr parameter
>> of mq_open(2) is NULL. If it exceed msgsize_max, the default
>> value is initialized msgsize_max.
>>
>> *We have these sysctls writable in VZ7 CT.
>
> What about upstream kernel? Are these writable for it as well? If yes, how
> has it happened that vzkernel DIDN'T have them as such at some point?

These sysctls also are writable in upstream net-namespace.

Sorry, but, I don't get the last question in VZ6 they are writable too:
[root@docker ~]# vzctl exec 131 "cat 
/proc/sys/net/ipv4/icmp_echo_ignore_all"0
[root@docker ~]# vzctl exec 131 "echo 1 > 
/proc/sys/net/ipv4/icmp_echo_ignore_all"
[root@docker ~]# vzctl exec 131 "cat 
/proc/sys/net/ipv4/icmp_echo_ignore_all"1

>
>> https://jira.sw.ru/browse/PSBM-48397
>>
>> v2: remove check if kernel has sysctls as we do not support such an
>> old kernel(v3.5)
>>
>> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
>> ---
>>  criu/ipc_ns.c        | 7 ++++++-
>>  images/ipc-var.proto | 2 ++
>>  2 files changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/criu/ipc_ns.c b/criu/ipc_ns.c
>> index 19dfb72..02fb9a0 100644
>> --- a/criu/ipc_ns.c
>> +++ b/criu/ipc_ns.c
>> @@ -309,6 +309,8 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
>>  		{ "fs/mqueue/queues_max",	&e->mq_queues_max,	CTL_U32 },
>>  		{ "fs/mqueue/msg_max",		&e->mq_msg_max,		CTL_U32 },
>>  		{ "fs/mqueue/msgsize_max",	&e->mq_msgsize_max,	CTL_U32 },
>> +		{ "fs/mqueue/msg_default",	&e->mq_msg_default,	CTL_U32 },
>> +		{ "fs/mqueue/msgsize_default",	&e->mq_msgsize_default,	CTL_U32 },
>>  	};
>>
>>  	int ret;
>> @@ -322,7 +324,8 @@ static int ipc_sysctl_req(IpcVarEntry *e, int op)
>>  		return 0;
>>  	}
>>
>> -	return sysctl_op(req_mq, ARRAY_SIZE(req_mq), op, CLONE_NEWIPC);
>> +	return sysctl_op(req_mq, ARRAY_SIZE(req_mq) - (e->has_mq_msg_default ? 0 : 2),
>> +	                 op, CLONE_NEWIPC);
>>  }
>>
>>  /*
>> @@ -416,6 +419,8 @@ static int dump_ipc_var(struct cr_img *img)
>>  	var.sem_ctls	= xmalloc(pb_repeated_size(&var, sem_ctls));
>>  	if (!var.sem_ctls)
>>  		goto err;
>> +	var.has_mq_msg_default = true;
>> +	var.has_mq_msgsize_default = true;
>>
>>  	ret = ipc_sysctl_req(&var, CTL_READ);
>>  	if (ret < 0) {
>> diff --git a/images/ipc-var.proto b/images/ipc-var.proto
>> index 4acda69..153b167 100644
>> --- a/images/ipc-var.proto
>> +++ b/images/ipc-var.proto
>> @@ -11,4 +11,6 @@ message ipc_var_entry {
>>  	required uint32			mq_queues_max		= 10;
>>  	required uint32			mq_msg_max		= 11;
>>  	required uint32			mq_msgsize_max		= 12;
>> +	optional uint32			mq_msg_default		= 13;
>> +	optional uint32			mq_msgsize_default	= 14;
>>  }
>>
>
Pavel Tikhomirov July 13, 2016, 2:12 p.m.
On 07/13/2016 03:58 PM, Pavel Tikhomirov wrote:
>
>
> On 07/13/2016 03:52 PM, Pavel Emelyanov wrote:
>> On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
>>> we already have 3/5 fs.mqueue.xxx sysctls so why not have all:
>>>
>>> /proc/sys/fs/mqueue/msg_default is  a read/write  file for
>>> setting/getting the default number of messages in a queue value
>>> if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
>>> the default value is initialized msg_max.
>>>
>>> /proc/sys/fs/mqueue/msgsize_default is a read/write file for
>>> setting/getting the default message size value if attr parameter
>>> of mq_open(2) is NULL. If it exceed msgsize_max, the default
>>> value is initialized msgsize_max.
>>>
>>> *We have these sysctls writable in VZ7 CT.
>>
>> What about upstream kernel? Are these writable for it as well? If yes,
>> how
>> has it happened that vzkernel DIDN'T have them as such at some point?
>

Sorry, I though it was about net sysctls but that is about ipc...

So, for ipc sysctls:

Sysctls are writable in sub-ipcns:
# unshare -ri
# cat /proc/sys/fs/mqueue/msgsize_default
8192
# echo 16384 > /proc/sys/fs/mqueue/msgsize_default
# cat /proc/sys/fs/mqueue/msgsize_default
16384

Sysctls msg(size)_default become writable in vzkernel in commit:

commit 42faae2077ff33775d612b0d4f17aedc000e0a37
Author: Andrew Vagin <avagin@openvz.org>
Date:   Thu Dec 19 13:28:27 2013 +0400

     ve/sysctl: allow to change mqueue sysctl-s

     All mqueue data are accounted into the kmem ubc.
     These sysctl belong to ipcns, so all changes doesn't affect other 
containers.

     https://jira.sw.ru/browse/PSBM-20102

     Signed-off-by: Andrew Vagin <avagin@openvz.org>
     Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Pavel Emelianov July 14, 2016, 10:52 a.m.
On 07/13/2016 05:12 PM, Pavel Tikhomirov wrote:
> 
> 
> On 07/13/2016 03:58 PM, Pavel Tikhomirov wrote:
>>
>>
>> On 07/13/2016 03:52 PM, Pavel Emelyanov wrote:
>>> On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
>>>> we already have 3/5 fs.mqueue.xxx sysctls so why not have all:
>>>>
>>>> /proc/sys/fs/mqueue/msg_default is  a read/write  file for
>>>> setting/getting the default number of messages in a queue value
>>>> if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
>>>> the default value is initialized msg_max.
>>>>
>>>> /proc/sys/fs/mqueue/msgsize_default is a read/write file for
>>>> setting/getting the default message size value if attr parameter
>>>> of mq_open(2) is NULL. If it exceed msgsize_max, the default
>>>> value is initialized msgsize_max.
>>>>
>>>> *We have these sysctls writable in VZ7 CT.
>>>
>>> What about upstream kernel? Are these writable for it as well? If yes,
>>> how
>>> has it happened that vzkernel DIDN'T have them as such at some point?
>>
> 
> Sorry, I though it was about net sysctls but that is about ipc...
> 
> So, for ipc sysctls:
> 
> Sysctls are writable in sub-ipcns:
> # unshare -ri
> # cat /proc/sys/fs/mqueue/msgsize_default
> 8192
> # echo 16384 > /proc/sys/fs/mqueue/msgsize_default
> # cat /proc/sys/fs/mqueue/msgsize_default
> 16384
> 
> Sysctls msg(size)_default become writable in vzkernel in commit:

No no no, my question was different. They are read-write in vanilla kernel, but
have been read-only for some time in vzkenrel. So when and why have they become 
read-only in vzkernel?

> commit 42faae2077ff33775d612b0d4f17aedc000e0a37
> Author: Andrew Vagin <avagin@openvz.org>
> Date:   Thu Dec 19 13:28:27 2013 +0400
> 
>      ve/sysctl: allow to change mqueue sysctl-s
> 
>      All mqueue data are accounted into the kmem ubc.
>      These sysctl belong to ipcns, so all changes doesn't affect other 
> containers.
> 
>      https://jira.sw.ru/browse/PSBM-20102
> 
>      Signed-off-by: Andrew Vagin <avagin@openvz.org>
>      Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
>
Pavel Tikhomirov July 14, 2016, 11:10 a.m.
On 07/14/2016 01:52 PM, Pavel Emelyanov wrote:
> On 07/13/2016 05:12 PM, Pavel Tikhomirov wrote:
>>
>>
>> On 07/13/2016 03:58 PM, Pavel Tikhomirov wrote:
>>>
>>>
>>> On 07/13/2016 03:52 PM, Pavel Emelyanov wrote:
>>>> On 07/04/2016 10:47 AM, Pavel Tikhomirov wrote:
>>>>> we already have 3/5 fs.mqueue.xxx sysctls so why not have all:
>>>>>
>>>>> /proc/sys/fs/mqueue/msg_default is  a read/write  file for
>>>>> setting/getting the default number of messages in a queue value
>>>>> if attr parameter of mq_open(2) is NULL. If it exceed msg_max,
>>>>> the default value is initialized msg_max.
>>>>>
>>>>> /proc/sys/fs/mqueue/msgsize_default is a read/write file for
>>>>> setting/getting the default message size value if attr parameter
>>>>> of mq_open(2) is NULL. If it exceed msgsize_max, the default
>>>>> value is initialized msgsize_max.
>>>>>
>>>>> *We have these sysctls writable in VZ7 CT.
>>>>
>>>> What about upstream kernel? Are these writable for it as well? If yes,
>>>> how
>>>> has it happened that vzkernel DIDN'T have them as such at some point?
>>>
>>
>> Sorry, I though it was about net sysctls but that is about ipc...
>>
>> So, for ipc sysctls:
>>
>> Sysctls are writable in sub-ipcns:
>> # unshare -ri
>> # cat /proc/sys/fs/mqueue/msgsize_default
>> 8192
>> # echo 16384 > /proc/sys/fs/mqueue/msgsize_default
>> # cat /proc/sys/fs/mqueue/msgsize_default
>> 16384
>>
>> Sysctls msg(size)_default become writable in vzkernel in commit:
>
> No no no, my question was different. They are read-write in vanilla kernel, but
> have been read-only for some time in vzkenrel. So when and why have they become
> read-only in vzkernel?

See vzkernel commit 44b7b87ec555 ("VE/SYSCTL: write permission 
restriction") and commit ad336c529a36 ("VE: use ve environtment for 
sysctl restrictions") here we add readonly restriction for inCT sysctls 
on sysctl_table_root, we had almost the same in VZ6.

>
>> commit 42faae2077ff33775d612b0d4f17aedc000e0a37
>> Author: Andrew Vagin <avagin@openvz.org>
>> Date:   Thu Dec 19 13:28:27 2013 +0400
>>
>>      ve/sysctl: allow to change mqueue sysctl-s
>>
>>      All mqueue data are accounted into the kmem ubc.
>>      These sysctl belong to ipcns, so all changes doesn't affect other
>> containers.
>>
>>      https://jira.sw.ru/browse/PSBM-20102
>>
>>      Signed-off-by: Andrew Vagin <avagin@openvz.org>
>>      Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
>>
>
Pavel Emelianov July 15, 2016, 5:49 p.m.
Applied