mq_sysctl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #include <linux/nsproxy.h>
  12. #include <linux/ipc_namespace.h>
  13. #include <linux/sysctl.h>
  14. /*
  15. * Define the ranges various user-specified maximum values can
  16. * be set to.
  17. */
  18. #define MIN_MSGMAX 1 /* min value for msg_max */
  19. #define MAX_MSGMAX HARD_MSGMAX /* max value for msg_max */
  20. #define MIN_MSGSIZEMAX 128 /* min value for msgsize_max */
  21. #define MAX_MSGSIZEMAX (8192*128) /* max value for msgsize_max */
  22. #ifdef CONFIG_PROC_SYSCTL
  23. static void *get_mq(ctl_table *table)
  24. {
  25. char *which = table->data;
  26. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  27. which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
  28. return which;
  29. }
  30. static int proc_mq_dointvec(ctl_table *table, int write,
  31. void __user *buffer, size_t *lenp, loff_t *ppos)
  32. {
  33. struct ctl_table mq_table;
  34. memcpy(&mq_table, table, sizeof(mq_table));
  35. mq_table.data = get_mq(table);
  36. return proc_dointvec(&mq_table, write, buffer, lenp, ppos);
  37. }
  38. static int proc_mq_dointvec_minmax(ctl_table *table, int write,
  39. void __user *buffer, size_t *lenp, loff_t *ppos)
  40. {
  41. struct ctl_table mq_table;
  42. memcpy(&mq_table, table, sizeof(mq_table));
  43. mq_table.data = get_mq(table);
  44. return proc_dointvec_minmax(&mq_table, write, buffer,
  45. lenp, ppos);
  46. }
  47. #else
  48. #define proc_mq_dointvec NULL
  49. #define proc_mq_dointvec_minmax NULL
  50. #endif
  51. static int msg_max_limit_min = MIN_MSGMAX;
  52. static int msg_max_limit_max = MAX_MSGMAX;
  53. static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
  54. static int msg_maxsize_limit_max = MAX_MSGSIZEMAX;
  55. static ctl_table mq_sysctls[] = {
  56. {
  57. .procname = "queues_max",
  58. .data = &init_ipc_ns.mq_queues_max,
  59. .maxlen = sizeof(int),
  60. .mode = 0644,
  61. .proc_handler = proc_mq_dointvec,
  62. },
  63. {
  64. .procname = "msg_max",
  65. .data = &init_ipc_ns.mq_msg_max,
  66. .maxlen = sizeof(int),
  67. .mode = 0644,
  68. .proc_handler = proc_mq_dointvec_minmax,
  69. .extra1 = &msg_max_limit_min,
  70. .extra2 = &msg_max_limit_max,
  71. },
  72. {
  73. .procname = "msgsize_max",
  74. .data = &init_ipc_ns.mq_msgsize_max,
  75. .maxlen = sizeof(int),
  76. .mode = 0644,
  77. .proc_handler = proc_mq_dointvec_minmax,
  78. .extra1 = &msg_maxsize_limit_min,
  79. .extra2 = &msg_maxsize_limit_max,
  80. },
  81. {}
  82. };
  83. static ctl_table mq_sysctl_dir[] = {
  84. {
  85. .procname = "mqueue",
  86. .mode = 0555,
  87. .child = mq_sysctls,
  88. },
  89. {}
  90. };
  91. static ctl_table mq_sysctl_root[] = {
  92. {
  93. .procname = "fs",
  94. .mode = 0555,
  95. .child = mq_sysctl_dir,
  96. },
  97. {}
  98. };
  99. struct ctl_table_header *mq_register_sysctl_table(void)
  100. {
  101. return register_sysctl_table(mq_sysctl_root);
  102. }