0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LINUX_WATCH_QUEUE_H
0011 #define _LINUX_WATCH_QUEUE_H
0012
0013 #include <uapi/linux/watch_queue.h>
0014 #include <linux/kref.h>
0015 #include <linux/rcupdate.h>
0016
0017 #ifdef CONFIG_WATCH_QUEUE
0018
0019 struct cred;
0020
0021 struct watch_type_filter {
0022 enum watch_notification_type type;
0023 __u32 subtype_filter[1];
0024 __u32 info_filter;
0025 __u32 info_mask;
0026 };
0027
0028 struct watch_filter {
0029 union {
0030 struct rcu_head rcu;
0031
0032 DECLARE_BITMAP(type_filter, WATCH_TYPE__NR);
0033 };
0034 u32 nr_filters;
0035 struct watch_type_filter filters[];
0036 };
0037
0038 struct watch_queue {
0039 struct rcu_head rcu;
0040 struct watch_filter __rcu *filter;
0041 struct pipe_inode_info *pipe;
0042 struct hlist_head watches;
0043 struct page **notes;
0044 unsigned long *notes_bitmap;
0045 struct kref usage;
0046 spinlock_t lock;
0047 unsigned int nr_notes;
0048 unsigned int nr_pages;
0049 bool defunct;
0050 };
0051
0052
0053
0054
0055 struct watch {
0056 union {
0057 struct rcu_head rcu;
0058 u32 info_id;
0059 };
0060 struct watch_queue __rcu *queue;
0061 struct hlist_node queue_node;
0062 struct watch_list __rcu *watch_list;
0063 struct hlist_node list_node;
0064 const struct cred *cred;
0065 void *private;
0066 u64 id;
0067 struct kref usage;
0068 };
0069
0070
0071
0072
0073 struct watch_list {
0074 struct rcu_head rcu;
0075 struct hlist_head watchers;
0076 void (*release_watch)(struct watch *);
0077 spinlock_t lock;
0078 };
0079
0080 extern void __post_watch_notification(struct watch_list *,
0081 struct watch_notification *,
0082 const struct cred *,
0083 u64);
0084 extern struct watch_queue *get_watch_queue(int);
0085 extern void put_watch_queue(struct watch_queue *);
0086 extern void init_watch(struct watch *, struct watch_queue *);
0087 extern int add_watch_to_object(struct watch *, struct watch_list *);
0088 extern int remove_watch_from_object(struct watch_list *, struct watch_queue *, u64, bool);
0089 extern long watch_queue_set_size(struct pipe_inode_info *, unsigned int);
0090 extern long watch_queue_set_filter(struct pipe_inode_info *,
0091 struct watch_notification_filter __user *);
0092 extern int watch_queue_init(struct pipe_inode_info *);
0093 extern void watch_queue_clear(struct watch_queue *);
0094
0095 static inline void init_watch_list(struct watch_list *wlist,
0096 void (*release_watch)(struct watch *))
0097 {
0098 INIT_HLIST_HEAD(&wlist->watchers);
0099 spin_lock_init(&wlist->lock);
0100 wlist->release_watch = release_watch;
0101 }
0102
0103 static inline void post_watch_notification(struct watch_list *wlist,
0104 struct watch_notification *n,
0105 const struct cred *cred,
0106 u64 id)
0107 {
0108 if (unlikely(wlist))
0109 __post_watch_notification(wlist, n, cred, id);
0110 }
0111
0112 static inline void remove_watch_list(struct watch_list *wlist, u64 id)
0113 {
0114 if (wlist) {
0115 remove_watch_from_object(wlist, NULL, id, true);
0116 kfree_rcu(wlist, rcu);
0117 }
0118 }
0119
0120
0121
0122
0123
0124 #define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT)
0125
0126 #else
0127 static inline int watch_queue_init(struct pipe_inode_info *pipe)
0128 {
0129 return -ENOPKG;
0130 }
0131
0132 #endif
0133
0134 #endif