ipc_namespace.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifdef CONFIG_MEMORY_HOTPLUG
  7. #include <linux/notifier.h>
  8. #endif /* CONFIG_MEMORY_HOTPLUG */
  9. /*
  10. * ipc namespace events
  11. */
  12. #define IPCNS_MEMCHANGED 0x00000001 /* Notify lowmem size changed */
  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. struct kref kref;
  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. size_t shm_ctlmax;
  32. size_t shm_ctlall;
  33. int shm_ctlmni;
  34. int shm_tot;
  35. #ifdef CONFIG_MEMORY_HOTPLUG
  36. struct notifier_block ipcns_nb;
  37. #endif
  38. };
  39. extern struct ipc_namespace init_ipc_ns;
  40. extern atomic_t nr_ipc_ns;
  41. #ifdef CONFIG_SYSVIPC
  42. #define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
  43. #ifdef CONFIG_MEMORY_HOTPLUG
  44. extern int register_ipcns_notifier(struct ipc_namespace *);
  45. extern int unregister_ipcns_notifier(struct ipc_namespace *);
  46. extern int ipcns_notify(unsigned long);
  47. #else /* CONFIG_MEMORY_HOTPLUG */
  48. static inline int register_ipcns_notifier(struct ipc_namespace *ipcns)
  49. {
  50. return 0;
  51. }
  52. static inline int unregister_ipcns_notifier(struct ipc_namespace *ipcns)
  53. {
  54. return 0;
  55. }
  56. static inline int ipcns_notify(unsigned long ev)
  57. {
  58. return 0;
  59. }
  60. #endif /* CONFIG_MEMORY_HOTPLUG */
  61. #else /* CONFIG_SYSVIPC */
  62. #define INIT_IPC_NS(ns)
  63. #endif /* CONFIG_SYSVIPC */
  64. #if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
  65. extern void free_ipc_ns(struct kref *kref);
  66. extern struct ipc_namespace *copy_ipcs(unsigned long flags,
  67. struct ipc_namespace *ns);
  68. extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
  69. void (*free)(struct ipc_namespace *,
  70. struct kern_ipc_perm *));
  71. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  72. {
  73. if (ns)
  74. kref_get(&ns->kref);
  75. return ns;
  76. }
  77. static inline void put_ipc_ns(struct ipc_namespace *ns)
  78. {
  79. kref_put(&ns->kref, free_ipc_ns);
  80. }
  81. #else
  82. static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
  83. struct ipc_namespace *ns)
  84. {
  85. if (flags & CLONE_NEWIPC)
  86. return ERR_PTR(-EINVAL);
  87. return ns;
  88. }
  89. static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
  90. {
  91. return ns;
  92. }
  93. static inline void put_ipc_ns(struct ipc_namespace *ns)
  94. {
  95. }
  96. #endif
  97. #endif