Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

namespaces: mqueue namespace: adapt sysctl

Largely inspired from ipc/ipc_sysctl.c. This patch isolates the mqueue
sysctl stuff in its own file.

[akpm@linux-foundation.org: build fix]
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net>
Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Serge E. Hallyn and committed by
Linus Torvalds
bdc8e5f8 7eafd7c7

+138 -64
+14
include/linux/ipc_namespace.h
··· 128 128 { 129 129 } 130 130 #endif 131 + 132 + #ifdef CONFIG_POSIX_MQUEUE_SYSCTL 133 + 134 + struct ctl_table_header; 135 + extern struct ctl_table_header *mq_register_sysctl_table(void); 136 + 137 + #else /* CONFIG_POSIX_MQUEUE_SYSCTL */ 138 + 139 + static inline struct ctl_table_header *mq_register_sysctl_table(void) 140 + { 141 + return NULL; 142 + } 143 + 144 + #endif /* CONFIG_POSIX_MQUEUE_SYSCTL */ 131 145 #endif
+6
init/Kconfig
··· 208 208 209 209 If unsure, say Y. 210 210 211 + config POSIX_MQUEUE_SYSCTL 212 + bool 213 + depends on POSIX_MQUEUE 214 + depends on SYSCTL 215 + default y 216 + 211 217 config BSD_PROCESS_ACCT 212 218 bool "BSD Process Accounting" 213 219 help
+1
ipc/Makefile
··· 8 8 obj_mq-$(CONFIG_COMPAT) += compat_mq.o 9 9 obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y) 10 10 obj-$(CONFIG_IPC_NS) += namespace.o 11 + obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o 11 12
+116
ipc/mq_sysctl.c
··· 1 + /* 2 + * Copyright (C) 2007 IBM Corporation 3 + * 4 + * Author: Cedric Le Goater <clg@fr.ibm.com> 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License as 8 + * published by the Free Software Foundation, version 2 of the 9 + * License. 10 + */ 11 + 12 + #include <linux/nsproxy.h> 13 + #include <linux/ipc_namespace.h> 14 + #include <linux/sysctl.h> 15 + 16 + /* 17 + * Define the ranges various user-specified maximum values can 18 + * be set to. 19 + */ 20 + #define MIN_MSGMAX 1 /* min value for msg_max */ 21 + #define MAX_MSGMAX HARD_MSGMAX /* max value for msg_max */ 22 + #define MIN_MSGSIZEMAX 128 /* min value for msgsize_max */ 23 + #define MAX_MSGSIZEMAX (8192*128) /* max value for msgsize_max */ 24 + 25 + static void *get_mq(ctl_table *table) 26 + { 27 + char *which = table->data; 28 + struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; 29 + which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns; 30 + return which; 31 + } 32 + 33 + #ifdef CONFIG_PROC_SYSCTL 34 + static int proc_mq_dointvec(ctl_table *table, int write, struct file *filp, 35 + void __user *buffer, size_t *lenp, loff_t *ppos) 36 + { 37 + struct ctl_table mq_table; 38 + memcpy(&mq_table, table, sizeof(mq_table)); 39 + mq_table.data = get_mq(table); 40 + 41 + return proc_dointvec(&mq_table, write, filp, buffer, lenp, ppos); 42 + } 43 + 44 + static int proc_mq_dointvec_minmax(ctl_table *table, int write, 45 + struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos) 46 + { 47 + struct ctl_table mq_table; 48 + memcpy(&mq_table, table, sizeof(mq_table)); 49 + mq_table.data = get_mq(table); 50 + 51 + return proc_dointvec_minmax(&mq_table, write, filp, buffer, 52 + lenp, ppos); 53 + } 54 + #else 55 + #define proc_mq_dointvec NULL 56 + #define proc_mq_dointvec_minmax NULL 57 + #endif 58 + 59 + static int msg_max_limit_min = MIN_MSGMAX; 60 + static int msg_max_limit_max = MAX_MSGMAX; 61 + 62 + static int msg_maxsize_limit_min = MIN_MSGSIZEMAX; 63 + static int msg_maxsize_limit_max = MAX_MSGSIZEMAX; 64 + 65 + static ctl_table mq_sysctls[] = { 66 + { 67 + .procname = "queues_max", 68 + .data = &init_ipc_ns.mq_queues_max, 69 + .maxlen = sizeof(int), 70 + .mode = 0644, 71 + .proc_handler = proc_mq_dointvec, 72 + }, 73 + { 74 + .procname = "msg_max", 75 + .data = &init_ipc_ns.mq_msg_max, 76 + .maxlen = sizeof(int), 77 + .mode = 0644, 78 + .proc_handler = proc_mq_dointvec_minmax, 79 + .extra1 = &msg_max_limit_min, 80 + .extra2 = &msg_max_limit_max, 81 + }, 82 + { 83 + .procname = "msgsize_max", 84 + .data = &init_ipc_ns.mq_msgsize_max, 85 + .maxlen = sizeof(int), 86 + .mode = 0644, 87 + .proc_handler = proc_mq_dointvec_minmax, 88 + .extra1 = &msg_maxsize_limit_min, 89 + .extra2 = &msg_maxsize_limit_max, 90 + }, 91 + { .ctl_name = 0 } 92 + }; 93 + 94 + static ctl_table mq_sysctl_dir[] = { 95 + { 96 + .procname = "mqueue", 97 + .mode = 0555, 98 + .child = mq_sysctls, 99 + }, 100 + { .ctl_name = 0 } 101 + }; 102 + 103 + static ctl_table mq_sysctl_root[] = { 104 + { 105 + .ctl_name = CTL_FS, 106 + .procname = "fs", 107 + .mode = 0555, 108 + .child = mq_sysctl_dir, 109 + }, 110 + { .ctl_name = 0 } 111 + }; 112 + 113 + struct ctl_table_header *mq_register_sysctl_table(void) 114 + { 115 + return register_sysctl_table(mq_sysctl_root); 116 + }
+1 -64
ipc/mqueue.c
··· 47 47 #define STATE_PENDING 1 48 48 #define STATE_READY 2 49 49 50 - /* 51 - * Define the ranges various user-specified maximum values can 52 - * be set to. 53 - */ 54 - #define MIN_MSGMAX 1 /* min value for msg_max */ 55 - #define MAX_MSGMAX HARD_MSGMAX /* max value for msg_max */ 56 - #define MIN_MSGSIZEMAX 128 /* min value for msgsize_max */ 57 - #define MAX_MSGSIZEMAX (8192*128) /* max value for msgsize_max */ 58 - 59 50 struct ext_wait_queue { /* queue of sleeping tasks */ 60 51 struct task_struct *task; 61 52 struct list_head list; ··· 1262 1271 mntput(ns->mq_mnt); 1263 1272 } 1264 1273 1265 - static int msg_max_limit_min = MIN_MSGMAX; 1266 - static int msg_max_limit_max = MAX_MSGMAX; 1267 - 1268 - static int msg_maxsize_limit_min = MIN_MSGSIZEMAX; 1269 - static int msg_maxsize_limit_max = MAX_MSGSIZEMAX; 1270 - 1271 - static ctl_table mq_sysctls[] = { 1272 - { 1273 - .procname = "queues_max", 1274 - .data = &init_ipc_ns.mq_queues_max, 1275 - .maxlen = sizeof(int), 1276 - .mode = 0644, 1277 - .proc_handler = &proc_dointvec, 1278 - }, 1279 - { 1280 - .procname = "msg_max", 1281 - .data = &init_ipc_ns.mq_msg_max, 1282 - .maxlen = sizeof(int), 1283 - .mode = 0644, 1284 - .proc_handler = &proc_dointvec_minmax, 1285 - .extra1 = &msg_max_limit_min, 1286 - .extra2 = &msg_max_limit_max, 1287 - }, 1288 - { 1289 - .procname = "msgsize_max", 1290 - .data = &init_ipc_ns.mq_msgsize_max, 1291 - .maxlen = sizeof(int), 1292 - .mode = 0644, 1293 - .proc_handler = &proc_dointvec_minmax, 1294 - .extra1 = &msg_maxsize_limit_min, 1295 - .extra2 = &msg_maxsize_limit_max, 1296 - }, 1297 - { .ctl_name = 0 } 1298 - }; 1299 - 1300 - static ctl_table mq_sysctl_dir[] = { 1301 - { 1302 - .procname = "mqueue", 1303 - .mode = 0555, 1304 - .child = mq_sysctls, 1305 - }, 1306 - { .ctl_name = 0 } 1307 - }; 1308 - 1309 - static ctl_table mq_sysctl_root[] = { 1310 - { 1311 - .ctl_name = CTL_FS, 1312 - .procname = "fs", 1313 - .mode = 0555, 1314 - .child = mq_sysctl_dir, 1315 - }, 1316 - { .ctl_name = 0 } 1317 - }; 1318 - 1319 1274 static int __init init_mqueue_fs(void) 1320 1275 { 1321 1276 int error; ··· 1273 1336 return -ENOMEM; 1274 1337 1275 1338 /* ignore failues - they are not fatal */ 1276 - mq_sysctl_table = register_sysctl_table(mq_sysctl_root); 1339 + mq_sysctl_table = mq_register_sysctl_table(); 1277 1340 1278 1341 error = register_filesystem(&mqueue_fs_type); 1279 1342 if (error)