xref: /openbmc/linux/fs/notify/fsnotify.h (revision ac8f933664c3a0e2d42f6ee9a2a6d25f87cb23f6)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
290586523SEric Paris #ifndef __FS_NOTIFY_FSNOTIFY_H_
390586523SEric Paris #define __FS_NOTIFY_FSNOTIFY_H_
490586523SEric Paris 
590586523SEric Paris #include <linux/list.h>
690586523SEric Paris #include <linux/fsnotify.h>
790586523SEric Paris #include <linux/srcu.h>
890586523SEric Paris #include <linux/types.h>
990586523SEric Paris 
10925d1132SJan Kara #include "../mount.h"
11925d1132SJan Kara 
fsnotify_conn_inode(struct fsnotify_mark_connector * conn)1236f10f55SAmir Goldstein static inline struct inode *fsnotify_conn_inode(
1336f10f55SAmir Goldstein 				struct fsnotify_mark_connector *conn)
14b812a9f5SAmir Goldstein {
1536f10f55SAmir Goldstein 	return container_of(conn->obj, struct inode, i_fsnotify_marks);
16b812a9f5SAmir Goldstein }
17b812a9f5SAmir Goldstein 
fsnotify_conn_mount(struct fsnotify_mark_connector * conn)1836f10f55SAmir Goldstein static inline struct mount *fsnotify_conn_mount(
1936f10f55SAmir Goldstein 				struct fsnotify_mark_connector *conn)
20b812a9f5SAmir Goldstein {
2136f10f55SAmir Goldstein 	return container_of(conn->obj, struct mount, mnt_fsnotify_marks);
22b812a9f5SAmir Goldstein }
23b812a9f5SAmir Goldstein 
fsnotify_conn_sb(struct fsnotify_mark_connector * conn)241e6cb723SAmir Goldstein static inline struct super_block *fsnotify_conn_sb(
251e6cb723SAmir Goldstein 				struct fsnotify_mark_connector *conn)
261e6cb723SAmir Goldstein {
271e6cb723SAmir Goldstein 	return container_of(conn->obj, struct super_block, s_fsnotify_marks);
281e6cb723SAmir Goldstein }
291e6cb723SAmir Goldstein 
fsnotify_connector_sb(struct fsnotify_mark_connector * conn)30ec44610fSAmir Goldstein static inline struct super_block *fsnotify_connector_sb(
31ec44610fSAmir Goldstein 				struct fsnotify_mark_connector *conn)
32ec44610fSAmir Goldstein {
33ec44610fSAmir Goldstein 	switch (conn->type) {
34ec44610fSAmir Goldstein 	case FSNOTIFY_OBJ_TYPE_INODE:
35ec44610fSAmir Goldstein 		return fsnotify_conn_inode(conn)->i_sb;
36ec44610fSAmir Goldstein 	case FSNOTIFY_OBJ_TYPE_VFSMOUNT:
37ec44610fSAmir Goldstein 		return fsnotify_conn_mount(conn)->mnt.mnt_sb;
38ec44610fSAmir Goldstein 	case FSNOTIFY_OBJ_TYPE_SB:
39ec44610fSAmir Goldstein 		return fsnotify_conn_sb(conn);
40ec44610fSAmir Goldstein 	default:
41ec44610fSAmir Goldstein 		return NULL;
42ec44610fSAmir Goldstein 	}
43ec44610fSAmir Goldstein }
44ec44610fSAmir Goldstein 
45a2d8bc6cSEric Paris /* destroy all events sitting in this groups notification queue */
46a2d8bc6cSEric Paris extern void fsnotify_flush_notify(struct fsnotify_group *group);
47a2d8bc6cSEric Paris 
4875c1be48SEric Paris /* protects reads of inode and vfsmount marks list */
4975c1be48SEric Paris extern struct srcu_struct fsnotify_mark_srcu;
5075c1be48SEric Paris 
518edc6e16SJan Kara /* compare two groups for sorting of marks lists */
528edc6e16SJan Kara extern int fsnotify_compare_groups(struct fsnotify_group *a,
538edc6e16SJan Kara 				   struct fsnotify_group *b);
548edc6e16SJan Kara 
559b6e5434SAmir Goldstein /* Destroy all marks attached to an object via connector */
569b6e5434SAmir Goldstein extern void fsnotify_destroy_marks(fsnotify_connp_t *connp);
57925d1132SJan Kara /* run the list of all marks associated with inode and destroy them */
fsnotify_clear_marks_by_inode(struct inode * inode)58925d1132SJan Kara static inline void fsnotify_clear_marks_by_inode(struct inode *inode)
59925d1132SJan Kara {
6008991e83SJan Kara 	fsnotify_destroy_marks(&inode->i_fsnotify_marks);
61925d1132SJan Kara }
62925d1132SJan Kara /* run the list of all marks associated with vfsmount and destroy them */
fsnotify_clear_marks_by_mount(struct vfsmount * mnt)63925d1132SJan Kara static inline void fsnotify_clear_marks_by_mount(struct vfsmount *mnt)
64925d1132SJan Kara {
6508991e83SJan Kara 	fsnotify_destroy_marks(&real_mount(mnt)->mnt_fsnotify_marks);
66925d1132SJan Kara }
671e6cb723SAmir Goldstein /* run the list of all marks associated with sb and destroy them */
fsnotify_clear_marks_by_sb(struct super_block * sb)681e6cb723SAmir Goldstein static inline void fsnotify_clear_marks_by_sb(struct super_block *sb)
691e6cb723SAmir Goldstein {
701e6cb723SAmir Goldstein 	fsnotify_destroy_marks(&sb->s_fsnotify_marks);
711e6cb723SAmir Goldstein }
7235e48176SJan Kara 
73c28f7e56SEric Paris /*
74c28f7e56SEric Paris  * update the dentry->d_flags of all of inode's children to indicate if inode cares
75c28f7e56SEric Paris  * about events that happen to its children.
76c28f7e56SEric Paris  */
77*fc1b1e13SAmir Goldstein extern void fsnotify_set_children_dentry_flags(struct inode *inode);
78a2d8bc6cSEric Paris 
794a0b20beSBen Dooks extern struct kmem_cache *fsnotify_mark_connector_cachep;
804a0b20beSBen Dooks 
8190586523SEric Paris #endif	/* __FS_NOTIFY_FSNOTIFY_H_ */
82