Skip to contentSkip to conversation

network fs notification

RFC PATCH In review Miklos Szeredi 4 participants 7 messages May 1, 2019 – May 7, 2019

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 network fs notification

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +5 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
 		else if (mark_type == FAN_MARK_FILESYSTEM)
 			ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
 						   flags, fsid);
-		else
+		else {
 			ret = fanotify_add_inode_mark(group, inode, mask,
 						      flags, fsid);
+
+			if (!ret && inode->i_op->notify_update)
+				inode->i_op->notify_update(inode);
+		}
 		break;
 	case FAN_MARK_REMOVE:
 		if (mark_type == FAN_MARK_MOUNT)
fs/notify/inotify/inotify_user.c +2 -0
@@ -754,6 +754,8 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 
 	/* create/update an inode mark */
 	ret = inotify_update_watch(group, inode, mask);
+	if (!ret && inode->i_op->notify_update)
+		inode->i_op->notify_update(inode);
 	path_put(&path);
 fput_and_out:
 	fdput(f);
include/linux/fs.h +1 -0
@@ -1852,6 +1852,7 @@ struct inode_operations {
 			   umode_t create_mode);
 	int (*tmpfile) (struct inode *, struct dentry *, umode_t);
 	int (*set_acl)(struct inode *, struct posix_acl *, int);
+	void (*notify_update)(struct inode *inode);
 } ____cacheline_aligned;
 
 static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
maintainer
#1 lore raw
Quoted 15 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +0 -0
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
 		else if (mark_type == FAN_MARK_FILESYSTEM)

fs/notify/fanotify/fanotify_user.c static int do_fanotify_mark(int fanotify · line 1050

Quoted 10 lines
fs/notify/fanotify/fanotify_user.c +5 -1
 			ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
 						   flags, fsid);
-		else
+		else {
 			ret = fanotify_add_inode_mark(group, inode, mask,
 						      flags, fsid);
+
+			if (!ret && inode->i_op->notify_update)
+				inode->i_op->notify_update(inode);
+		}

Yeah, so I had something like this in mind but I wanted to inform the filesystem about superblock and mountpoint marks as well. And I'd pass the 'mask' as well as presumably filesystem could behave differently depending on whether we are looking for create vs unlink vs file change events etc...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 24 lines · Jan Kara
Quoted 22 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +2 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
              else if (mark_type == FAN_MARK_FILESYSTEM)
                      ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
                                                 flags, fsid);
-             else
+             else {
                      ret = fanotify_add_inode_mark(group, inode, mask,
                                                    flags, fsid);
+
Quoted 9 lines

fs/notify/fanotify/fanotify_user.c static int do_fanotify_mark(int fanotify · line 1050

Quoted 3 lines
fs/notify/fanotify/fanotify_user.c +3 -0
+                     if (!ret && inode->i_op->notify_update)
+                             inode->i_op->notify_update(inode);
+             }

Yeah, so I had something like this in mind but I wanted to inform the filesystem about superblock and mountpoint marks as well. And I'd pass the 'mask' as well as presumably filesystem could behave differently depending on whether we are looking for create vs unlink vs file change events etc...

It probably wouldn't hurt to update fs about mount marks, but in the context of "remote" fs, the changes are most certainly being done on a different mount, a different machine most likely...

Thanks,
Amir.

maintainer
#3 lore raw
Quoted 35 lines · Amir Goldstein
Quoted 24 lines · Jan Kara
Quoted 22 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +2 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
              else if (mark_type == FAN_MARK_FILESYSTEM)
                      ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
                                                 flags, fsid);
-             else
+             else {
                      ret = fanotify_add_inode_mark(group, inode, mask,
                                                    flags, fsid);
+
Quoted 9 lines

fs/notify/fanotify/fanotify_user.c static int do_fanotify_mark(int fanotify · line 1050

Quoted 3 lines
fs/notify/fanotify/fanotify_user.c +3 -0
+                     if (!ret && inode->i_op->notify_update)
+                             inode->i_op->notify_update(inode);
+             }

Yeah, so I had something like this in mind but I wanted to inform the filesystem about superblock and mountpoint marks as well. And I'd pass the 'mask' as well as presumably filesystem could behave differently depending on whether we are looking for create vs unlink vs file change events etc...

Quoted 3 lines

It probably wouldn't hurt to update fs about mount marks, but in the context of "remote" fs, the changes are most certainly being done on a different mount, a different machine most likely...

I agree. I guess I'm missing your point :) What I understood from Steve is that e.g. cifs could ask the server to provide the notifications. E.g. FUSE could propagate this information to userspace daemon which could place appropriate fsnotify marks on underlying objects and then transform the events to events on the FUSE filesystem? At least that's what I was imagining, didn't think too much about it.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw
Quoted 27 lines · Jan Kara
Quoted 25 lines · Amir Goldstein
Quoted 24 lines · Jan Kara
Quoted 22 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +2 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
              else if (mark_type == FAN_MARK_FILESYSTEM)
                      ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
                                                 flags, fsid);
-             else
+             else {
                      ret = fanotify_add_inode_mark(group, inode, mask,
                                                    flags, fsid);
+
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/notify/fanotify/fanotify_user.c static int do_fanotify_mark(int fanotify · line 1050

Quoted 3 lines
fs/notify/fanotify/fanotify_user.c +3 -0
+                     if (!ret && inode->i_op->notify_update)
+                             inode->i_op->notify_update(inode);
+             }

Yeah, so I had something like this in mind but I wanted to inform the filesystem about superblock and mountpoint marks as well. And I'd pass the 'mask' as well as presumably filesystem could behave differently depending on whether we are looking for create vs unlink vs file change events etc...

Hmm. I'm not sure we need to pass the mask, since it's in the inode filesystem can read it. But this code is completely racy in this respect and doesn't even include hooks in the delete notification. So it's basically just to try it out.

Quoted 11 lines
Quoted 4 lines

It probably wouldn't hurt to update fs about mount marks, but in the context of "remote" fs, the changes are most certainly being done on a different mount, a different machine most likely...

I agree. I guess I'm missing your point :) What I understood from Steve is that e.g. cifs could ask the server to provide the notifications. E.g. FUSE could propagate this information to userspace daemon which could place appropriate fsnotify marks on underlying objects and then transform the events to events on the FUSE filesystem? At least that's what I was imagining, didn't think too much about it.

Exactly. For inode and superblock notification that's clear (don't know if CIFS can do superblock notifications or not). However, mount notification is something that possibly means: notify me of any changes made through this mount only. I.e. if there's a bind mount and the filesystem is modified through that, then we don't get the mount notification for the original mount. So I guess it makes sense to say: if you want remote notifications, just use the superblock notification.

Thanks,
Miklos

#5 lore raw
In reply to Miklos Szeredi

Adding linux-cifs

Will take a look today - looks promising

Quoted 50 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +5 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
                else if (mark_type == FAN_MARK_FILESYSTEM)
                        ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
                                                   flags, fsid);
-               else
+               else {
                        ret = fanotify_add_inode_mark(group, inode, mask,
                                                      flags, fsid);
+
+                       if (!ret && inode->i_op->notify_update)
+                               inode->i_op->notify_update(inode);
+               }
                break;
        case FAN_MARK_REMOVE:
                if (mark_type == FAN_MARK_MOUNT)
fs/notify/inotify/inotify_user.c +2 -0
@@ -754,6 +754,8 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 
        /* create/update an inode mark */
        ret = inotify_update_watch(group, inode, mask);
+       if (!ret && inode->i_op->notify_update)
+               inode->i_op->notify_update(inode);
        path_put(&path);
 fput_and_out:
        fdput(f);
include/linux/fs.h +1 -0
@@ -1852,6 +1852,7 @@ struct inode_operations {
                           umode_t create_mode);
        int (*tmpfile) (struct inode *, struct dentry *, umode_t);
        int (*set_acl)(struct inode *, struct posix_acl *, int);
+       void (*notify_update)(struct inode *inode);
 } ____cacheline_aligned;
 
 static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
Signature · 3 lines
Thanks,

Steve
#6 lore raw
In reply to Miklos Szeredi
Quoted 3 lines · Miklos Szeredi

This is a really really trivial first iteration, but I think it's enough to try out CIFS notification support. Doesn't deal with mark deletion, but that's best effort anyway: fsnotify() will filter out unneeded events.

And this one actually does something for inotify. I haven't tested fanotify yet, but that one looks okay.

Note: FAN_MARK_MOUNT doesn't work yet, and we are not sure if it should work or
not. FAN_MARK_FILESYSTEM would be a better candidate for remote notification,
since remote accesses are not associated with any particular local mount of the
filesystem. But perhaps we need to turn on whole file notification for remote
due to the fact that applications rely on FAN_MARK_MOUNT already... Btw, does the smb protocol support whole filesystem (or subtree) notifications?

Thanks,
Miklos

---
 fs/notify/fanotify/fanotify_user.c |    6 +++++-
 fs/notify/inotify/inotify_user.c   |    2 ++
 include/linux/fs.h                 |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +5 -1
@@ -1041,9 +1041,13 @@ static int do_fanotify_mark(int fanotify
 		else if (mark_type == FAN_MARK_FILESYSTEM)
 			ret = fanotify_add_sb_mark(group, mnt->mnt_sb, mask,
 						   flags, fsid);
-		else
+		else {
 			ret = fanotify_add_inode_mark(group, inode, mask,
 						      flags, fsid);
+
+			if (!ret && inode->i_op->notify_update)
+				inode->i_op->notify_update(inode);
+		}
 		break;
 	case FAN_MARK_REMOVE:
 		if (mark_type == FAN_MARK_MOUNT)
fs/notify/inotify/inotify_user.c +2 -0
@@ -754,6 +754,8 @@ SYSCALL_DEFINE3(inotify_add_watch, int,
 
 	/* create/update an inode mark */
 	ret = inotify_update_watch(group, inode, mask);
+	if (ret >= 0 && inode->i_op->notify_update)
+		inode->i_op->notify_update(inode);
 	path_put(&path);
 fput_and_out:
 	fdput(f);
include/linux/fs.h +1 -0
@@ -1852,6 +1852,7 @@ struct inode_operations {
 			   umode_t create_mode);
 	int (*tmpfile) (struct inode *, struct dentry *, umode_t);
 	int (*set_acl)(struct inode *, struct posix_acl *, int);
+	void (*notify_update)(struct inode *inode);
 } ____cacheline_aligned;
 
 static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,