Skip to content

Commit b7dbaac

Browse files
amir73iljankara
authored andcommitted
fsnotify: Add fsnotify_sb_has_watchers() helper
Instead of opencoded checks for number of fsnotify connectors add a helper fsnotify_sb_has_watchers(). Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 082fd1e commit b7dbaac

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

include/linux/fsnotify.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#include <linux/slab.h>
1818
#include <linux/bug.h>
1919

20+
/* Are there any inode/mount/sb objects that are being watched at all? */
21+
static inline bool fsnotify_sb_has_watchers(struct super_block *sb)
22+
{
23+
return atomic_long_read(&sb->s_fsnotify_connectors);
24+
}
25+
2026
/*
2127
* Notify this @dir inode about a change in a child directory entry.
2228
* The directory entry may have turned positive or negative or its inode may
@@ -30,7 +36,7 @@ static inline int fsnotify_name(__u32 mask, const void *data, int data_type,
3036
struct inode *dir, const struct qstr *name,
3137
u32 cookie)
3238
{
33-
if (atomic_long_read(&dir->i_sb->s_fsnotify_connectors) == 0)
39+
if (!fsnotify_sb_has_watchers(dir->i_sb))
3440
return 0;
3541

3642
return fsnotify(mask, data, data_type, dir, name, NULL, cookie);
@@ -44,7 +50,7 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
4450

4551
static inline void fsnotify_inode(struct inode *inode, __u32 mask)
4652
{
47-
if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0)
53+
if (!fsnotify_sb_has_watchers(inode->i_sb))
4854
return;
4955

5056
if (S_ISDIR(inode->i_mode))
@@ -59,7 +65,7 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
5965
{
6066
struct inode *inode = d_inode(dentry);
6167

62-
if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0)
68+
if (!fsnotify_sb_has_watchers(inode->i_sb))
6369
return 0;
6470

6571
if (S_ISDIR(inode->i_mode)) {

0 commit comments

Comments
 (0)