ipc_namespace.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef __IPC_NAMESPACE_H__
  2. #define __IPC_NAMESPACE_H__
  3. #include <linux/err.h>
  4. #include <linux/idr.h>
  5. #include <linux/rwsem.h>
  6. #include <linux/notifier.h>
  7. /*
  8. * ipc namespace events
  9. */
  10. #define IPCNS_MEMCHANGED 0x00000001 /* Notify lowmem size changed */
  11. #define IPCNS_CREATED 0x00000002 /* Notify new ipc namespace created */
  12. #define IPCNS_REMOVED 0x00000003 /* Notify ipc namespace removed */
  13. #define IPCNS_CALLBACK_PRI 0
  14. struct user_namespace;
  15. struct ipc_ids {
  16. int in_use;
  17. unsigned short seq;
  18. unsigned short seq_max;
  19. struct rw_semaphore rw_mutex;
  20. struct idr ipcs_idr;
  21. };
  22. struct ipc_namespace {
  23. atomic_t count;
  24. struct ipc_ids ids[3];
  25. int sem_ctls[4];
  26. int used_sems;
  27. int msg_ctlmax;
  28. int msg_ctlmnb;
  29. int msg_ctlmni;
  30. atomic_t msg_bytes;
  31. atomic_t msg_hdrs;
  32. int auto_msgmni;
  33. size_t shm_ctlmax;
  34. size_t shm_ctlall;
  35. int shm_ctlmni;
  36. int shm_tot;
  37. struct notifier_block ipcns_nb;
  38. /* The kern_mount of the mqueuefs sb. We take a ref on it */
  39. struct vfsmount *mq_mnt;
  40. /* # queues in this ns, protected by mq_lock */
  41. unsigned int mq_queues_count;
  42. /* next fields are set through sysctl */
  43. unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */
  44. unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
  45. unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
  46. /* user_ns which owns the ipc ns */
  47. struct user_namespace *user_ns;
  48. };
  49. extern struct ipc_namespace init_ipc_ns;
  50. extern atomic_t nr_ipc_ns;
  51. extern spinlock_t mq_lock;
  52. #ifdef CONFIG_SYSVIPC
  53. extern int register_ipcns_notifier(struct ipc_namespace *);
  54. extern int cond_register_ipcns_notifier(struct ipc_namespace *);
  55. extern void unregister_ipcns_notifier(struct ipc_namespace *);
  56. extern int ipcns_notify(unsigned long);
  57. #else /* CONFIG_SYSVIPC */
  58. static inline int register_ipcns_notifier(struct ipc_namespace *ns)
  59. { return 0; }
  60. static inline int cond_register_ipcns_notifier(struct ipc_namespace *ns)
  61. { return 0; }
  62. static inline void unregister_ipcns_notifier(struct ipc_namespace *ns) { }
  63. static inline int ipcns_notify(unsigned long l) { return 0; }
  64. #endif /* CONFIG_SYSVIPC */
  65. #ifdef CONFIG_POSIX_MQUEUE
  66. extern int mq_init_ns(struct ipc_namespace *ns);
  67. /* default values */
  68. #define DFLT_QUEUESMAX 256 /* max number of message queues */
  69. #define DFLT_MSGMAX 10 /* max number of messages in each queue */
  70. #define HARD_MSGMAX (32768*sizeof(void *)/4)
  71. #define DFLT_MSGSIZEMAX 8192 /* max message size */
  72. #else
  73. static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
  74. #endif
  75. #if defined(CONFIG_IPC_NS)
  76. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  77. struct ipc_namespace *ns);
  78. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  79. {
  80. if (ns)
  81. atomic_inc(&ns->count);
  82. return ns;
  83. }
  84. extern void put_ipc_ns(struct ipc_namespace *ns);
  85. #else
  86. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  87. struct ipc_namespace *ns)
  88. {
  89. if (flags & CLONE_NEWIPC)
  90. return ERR_PTR(-EINVAL);
  91. return ns;
  92. }
  93. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  94. {
  95. return ns;
  96. }
  97. static inline void put_ipc_ns(struct ipc_namespace *ns)
  98. {
  99. }
  100. #endif
  101. #ifdef CONFIG_POSIX_MQUEUE_SYSCTL
  102. struct ctl_table_header;
  103. extern struct ctl_table_header *mq_register_sysctl_table(void);
  104. #else /* CONFIG_POSIX_MQUEUE_SYSCTL */
  105. static inline struct ctl_table_header *mq_register_sysctl_table(void)
  106. {
  107. return NULL;
  108. }
  109. #endif /* CONFIG_POSIX_MQUEUE_SYSCTL */
  110. #endif