1 // SPDX-License-Identifier: GPL-2.0
2 /* User-mappable watch queue
4 * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
7 * See Documentation/core-api/watch_queue.rst
10 #ifndef _LINUX_WATCH_QUEUE_H
11 #define _LINUX_WATCH_QUEUE_H
13 #include <uapi/linux/watch_queue.h>
14 #include <linux/kref.h>
15 #include <linux/rcupdate.h>
17 #ifdef CONFIG_WATCH_QUEUE
21 struct watch_type_filter
{
22 enum watch_notification_type type
;
23 __u32 subtype_filter
[1]; /* Bitmask of subtypes to filter on */
24 __u32 info_filter
; /* Filter on watch_notification::info */
25 __u32 info_mask
; /* Mask of relevant bits in info_filter */
31 /* Bitmask of accepted types */
32 DECLARE_BITMAP(type_filter
, WATCH_TYPE__NR
);
34 u32 nr_filters
; /* Number of filters */
35 struct watch_type_filter filters
[] __counted_by(nr_filters
);
40 struct watch_filter __rcu
*filter
;
41 struct pipe_inode_info
*pipe
; /* Pipe we use as a buffer, NULL if queue closed */
42 struct hlist_head watches
; /* Contributory watches */
43 struct page
**notes
; /* Preallocated notifications */
44 unsigned long *notes_bitmap
; /* Allocation bitmap for notes */
45 struct kref usage
; /* Object usage count */
47 unsigned int nr_notes
; /* Number of notes */
48 unsigned int nr_pages
; /* Number of pages in notes[] */
52 * Representation of a watch on an object.
57 u32 info_id
; /* ID to be OR'd in to info field */
59 struct watch_queue __rcu
*queue
; /* Queue to post events to */
60 struct hlist_node queue_node
; /* Link in queue->watches */
61 struct watch_list __rcu
*watch_list
;
62 struct hlist_node list_node
; /* Link in watch_list->watchers */
63 const struct cred
*cred
; /* Creds of the owner of the watch */
64 void *private; /* Private data for the watched object */
65 u64 id
; /* Internal identifier */
66 struct kref usage
; /* Object usage count */
70 * List of watches on an object.
74 struct hlist_head watchers
;
75 void (*release_watch
)(struct watch
*);
79 extern void __post_watch_notification(struct watch_list
*,
80 struct watch_notification
*,
83 extern struct watch_queue
*get_watch_queue(int);
84 extern void put_watch_queue(struct watch_queue
*);
85 extern void init_watch(struct watch
*, struct watch_queue
*);
86 extern int add_watch_to_object(struct watch
*, struct watch_list
*);
87 extern int remove_watch_from_object(struct watch_list
*, struct watch_queue
*, u64
, bool);
88 extern long watch_queue_set_size(struct pipe_inode_info
*, unsigned int);
89 extern long watch_queue_set_filter(struct pipe_inode_info
*,
90 struct watch_notification_filter __user
*);
91 extern int watch_queue_init(struct pipe_inode_info
*);
92 extern void watch_queue_clear(struct watch_queue
*);
94 static inline void init_watch_list(struct watch_list
*wlist
,
95 void (*release_watch
)(struct watch
*))
97 INIT_HLIST_HEAD(&wlist
->watchers
);
98 spin_lock_init(&wlist
->lock
);
99 wlist
->release_watch
= release_watch
;
102 static inline void post_watch_notification(struct watch_list
*wlist
,
103 struct watch_notification
*n
,
104 const struct cred
*cred
,
108 __post_watch_notification(wlist
, n
, cred
, id
);
111 static inline void remove_watch_list(struct watch_list
*wlist
, u64 id
)
114 remove_watch_from_object(wlist
, NULL
, id
, true);
115 kfree_rcu(wlist
, rcu
);
120 * watch_sizeof - Calculate the information part of the size of a watch record,
121 * given the structure size.
123 #define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT)
126 static inline int watch_queue_init(struct pipe_inode_info
*pipe
)
133 #endif /* _LINUX_WATCH_QUEUE_H */