| 1 | |
| 2 | |
| 3 | *
|
| 4 | * Copyright (C) 2020 Red Hat, Inc. All Rights Reserved.
|
| 5 | * Written by David Howells ([email protected])
|
| 6 | *
|
| 7 | * See Documentation/core-api/watch_queue.rst
|
| 8 |
|
| 9 |
|
| 10 | #ifndef _LINUX_WATCH_QUEUE_H
|
| 11 | #define _LINUX_WATCH_QUEUE_H
|
| 12 |
|
| 13 | #include <uapi/linux/watch_queue.h>
|
| 14 | #include <linux/kref.h>
|
| 15 | #include <linux/rcupdate.h>
|
| 16 |
|
| 17 | #ifdef CONFIG_WATCH_QUEUE
|
| 18 |
|
| 19 | struct cred;
|
| 20 |
|
| 21 | struct watch_type_filter {
|
| 22 | enum watch_notification_type type;
|
| 23 | __u32 subtype_filter[1];
|
| 24 | __u32 info_filter;
|
| 25 | __u32 info_mask;
|
| 26 | };
|
| 27 |
|
| 28 | struct watch_filter {
|
| 29 | union {
|
| 30 | struct rcu_head rcu;
|
| 31 |
|
| 32 | DECLARE_BITMAP(type_filter, WATCH_TYPE__NR);
|
| 33 | };
|
| 34 | u32 nr_filters;
|
| 35 | struct watch_type_filter filters[] __counted_by(nr_filters);
|
| 36 | };
|
| 37 |
|
| 38 | struct watch_queue {
|
| 39 | struct rcu_head rcu;
|
| 40 | struct watch_filter __rcu *filter;
|
| 41 | struct pipe_inode_info *pipe;
|
| 42 | struct hlist_head watches;
|
| 43 | struct page **notes;
|
| 44 | unsigned long *notes_bitmap;
|
| 45 | struct kref usage;
|
| 46 | spinlock_t lock;
|
| 47 | unsigned int nr_notes;
|
| 48 | unsigned int nr_pages;
|
| 49 | };
|
| 50 |
|
| 51 | |
| 52 | * Representation of a watch on an object.
|
| 53 |
|
| 54 | struct watch {
|
| 55 | union {
|
| 56 | struct rcu_head rcu;
|
| 57 | u32 info_id;
|
| 58 | };
|
| 59 | struct watch_queue __rcu *queue;
|
| 60 | struct hlist_node queue_node;
|
| 61 | struct watch_list __rcu *watch_list;
|
| 62 | struct hlist_node list_node;
|
| 63 | const struct cred *cred;
|
| 64 | void *private;
|
| 65 | u64 id;
|
| 66 | struct kref usage;
|
| 67 | };
|
| 68 |
|
| 69 | |
| 70 | * List of watches on an object.
|
| 71 |
|
| 72 | struct watch_list {
|
| 73 | struct rcu_head rcu;
|
| 74 | struct hlist_head watchers;
|
| 75 | void (*release_watch)(struct watch *);
|
| 76 | spinlock_t lock;
|
| 77 | };
|
| 78 |
|
| 79 | extern void __post_watch_notification(struct watch_list *,
|
| 80 | struct watch_notification *,
|
| 81 | const struct cred *,
|
| 82 | u64);
|
| 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 *);
|
| 93 |
|
| 94 | static inline void init_watch_list(struct watch_list *wlist,
|
| 95 | void (*release_watch)(struct watch *))
|
| 96 | {
|
| 97 | INIT_HLIST_HEAD(&wlist->watchers);
|
| 98 | spin_lock_init(&wlist->lock);
|
| 99 | wlist->release_watch = release_watch;
|
| 100 | }
|
| 101 |
|
| 102 | static inline void post_watch_notification(struct watch_list *wlist,
|
| 103 | struct watch_notification *n,
|
| 104 | const struct cred *cred,
|
| 105 | u64 id)
|
| 106 | {
|
| 107 | if (unlikely(wlist))
|
| 108 | __post_watch_notification(wlist, n, cred, id);
|
| 109 | }
|
| 110 |
|
| 111 | static inline void remove_watch_list(struct watch_list *wlist, u64 id)
|
| 112 | {
|
| 113 | if (wlist) {
|
| 114 | remove_watch_from_object(wlist, NULL, id, true);
|
| 115 | kfree_rcu(wlist, rcu);
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | |
| 120 | * watch_sizeof - Calculate the information part of the size of a watch record,
|
| 121 | * given the structure size.
|
| 122 |
|
| 123 | #define watch_sizeof(STRUCT) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT)
|
| 124 |
|
| 125 | #else
|
| 126 | static inline int watch_queue_init(struct pipe_inode_info *pipe)
|
| 127 | {
|
| 128 | return -ENOPKG;
|
| 129 | }
|
| 130 |
|
| 131 | #endif
|
| 132 |
|
| 133 | #endif
|