mq_sysctl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #ifdef CONFIG_PROC_SYSCTL
  15. static void *get_mq(struct ctl_table *table)
  16. {
  17. char *which = table->data;
  18. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  19. which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
  20. return which;
  21. }
  22. static int proc_mq_dointvec(struct ctl_table *table, int write,
  23. void __user *buffer, size_t *lenp, loff_t *ppos)
  24. {
  25. struct ctl_table mq_table;
  26. memcpy(&mq_table, table, sizeof(mq_table));
  27. mq_table.data = get_mq(table);
  28. return proc_dointvec(&mq_table, write, buffer, lenp, ppos);
  29. }
  30. static int proc_mq_dointvec_minmax(struct 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_minmax(&mq_table, write, buffer,
  37. lenp, ppos);
  38. }
  39. #else
  40. #define proc_mq_dointvec NULL
  41. #define proc_mq_dointvec_minmax NULL
  42. #endif
  43. static int msg_max_limit_min = MIN_MSGMAX;
  44. static int msg_max_limit_max = HARD_MSGMAX;
  45. static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
  46. static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
  47. static struct ctl_table mq_sysctls[] = {
  48. {
  49. .procname = "queues_max",
  50. .data = &init_ipc_ns.mq_queues_max,
  51. .maxlen = sizeof(int),
  52. .mode = 0644,
  53. .proc_handler = proc_mq_dointvec,
  54. },
  55. {
  56. .procname = "msg_max",
  57. .data = &init_ipc_ns.mq_msg_max,
  58. .maxlen = sizeof(int),
  59. .mode = 0644,
  60. .proc_handler = proc_mq_dointvec_minmax,
  61. .extra1 = &msg_max_limit_min,
  62. .extra2 = &msg_max_limit_max,
  63. },
  64. {
  65. .procname = "msgsize_max",
  66. .data = &init_ipc_ns.mq_msgsize_max,
  67. .maxlen = sizeof(int),
  68. .mode = 0644,
  69. .proc_handler = proc_mq_dointvec_minmax,
  70. .extra1 = &msg_maxsize_limit_min,
  71. .extra2 = &msg_maxsize_limit_max,
  72. },
  73. {
  74. .procname = "msg_default",
  75. .data = &init_ipc_ns.mq_msg_default,
  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_default",
  84. .data = &init_ipc_ns.mq_msgsize_default,
  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. {}
  92. };
  93. static struct ctl_table mq_sysctl_dir[] = {
  94. {
  95. .procname = "mqueue",
  96. .mode = 0555,
  97. .child = mq_sysctls,
  98. },
  99. {}
  100. };
  101. static struct ctl_table mq_sysctl_root[] = {
  102. {
  103. .procname = "fs",
  104. .mode = 0555,
  105. .child = mq_sysctl_dir,
  106. },
  107. {}
  108. };
  109. struct ctl_table_header *mq_register_sysctl_table(void)
  110. {
  111. return register_sysctl_table(mq_sysctl_root);
  112. }