ipc_namespace.h 3.6 KB

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