Skip to contentSkip to conversation

splice: report related fsnotify events

PATCH In review Chung-Chiang Cheng 5 participants 11 messages Mar 22, 2023 – Apr 4, 2023 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 splice: report related fsnotify events

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

---
 fs/splice.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/splice.c +8 -0
index 5969b7a1d353..9cadcaf52a3e 100644
@@ -30,6 +30,7 @@
 #include <linux/export.h>
 #include <linux/syscalls.h>
 #include <linux/uio.h>
+#include <linux/fsnotify.h>
 #include <linux/security.h>
 #include <linux/gfp.h>
 #include <linux/socket.h>
@@ -1074,6 +1075,9 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
 		ret = do_splice_from(ipipe, out, &offset, len, flags);
 		file_end_write(out);
 
+		if (ret > 0)
+			fsnotify_modify(out);
+
 		if (!off_out)
 			out->f_pos = offset;
 		else
@@ -1097,6 +1101,10 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
 			flags |= SPLICE_F_NONBLOCK;
 
 		ret = splice_file_to_pipe(in, opipe, &offset, len, flags);
+
+		if (ret > 0)
+			fsnotify_access(in);
+
 		if (!off_in)
 			in->f_pos = offset;
 		else
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Chung-Chiang Cheng

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

Looks good.

Quoted 40 lines
---
 fs/splice.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/splice.c +8 -1
index 5969b7a1d353..9cadcaf52a3e 100644
@@ -30,6 +30,7 @@
 #include <linux/export.h>
 #include <linux/syscalls.h>
 #include <linux/uio.h>
+#include <linux/fsnotify.h>
 #include <linux/security.h>
 #include <linux/gfp.h>
 #include <linux/socket.h>
@@ -1074,6 +1075,9 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
                ret = do_splice_from(ipipe, out, &offset, len, flags);
                file_end_write(out);
 
+               if (ret > 0)
+                       fsnotify_modify(out);
+
                if (!off_out)
                        out->f_pos = offset;
                else
@@ -1097,6 +1101,10 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out,
                        flags |= SPLICE_F_NONBLOCK;
 
                ret = splice_file_to_pipe(in, opipe, &offset, len, flags);
+
+               if (ret > 0)
+                       fsnotify_access(in);
+
                if (!off_in)
                        in->f_pos = offset;
                else
--

2.34.1

#2 lore raw
Quoted 6 lines · Amir Goldstein
Quoted 4 lines · Chung-Chiang Cheng

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

Jens, Jan,

FYI, I've audited aio routines and found that fsnotify_access()/modify() are also missing in aio_complete_rw() and in io_complete_rw_iopoll() (io_req_io_end() should be called?).

I am not using/testing aio/io_uring usually, so I wasn't planning on sending a patch any time soon. I'll get to it someday.
Just wanted to bring this to public attention in case someone is interested in testing/fixing.

Thanks,
Amir.

#3 lore raw
Quoted 10 lines · Amir Goldstein
Quoted 6 lines · On Wed, Mar 22, 2023 at 9:08?AM Amir Goldstein <[email protected]> wrote:
Quoted 4 lines · On Wed, Mar 22, 2023 at 8:51?AM Chung-Chiang Cheng <[email protected]> wrote:

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

Jens, Jan,

Quoted 8 lines

FYI, I've audited aio routines and found that fsnotify_access()/modify() are also missing in aio_complete_rw() and in io_complete_rw_iopoll() (io_req_io_end() should be called?).

I am not using/testing aio/io_uring usually, so I wasn't planning on sending a patch any time soon. I'll get to it someday.
Just wanted to bring this to public attention in case someone is interested in testing/fixing.

aio has never done fsnotify, but I think that's probably an oversight. io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 16 lines · Jens Axboe
Quoted 14 lines · Amir Goldstein
Quoted 6 lines · On Wed, Mar 22, 2023 at 9:08?AM Amir Goldstein <[email protected]> wrote:
Quoted 4 lines · On Wed, Mar 22, 2023 at 8:51?AM Chung-Chiang Cheng <[email protected]> wrote:

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

Jens, Jan,

FYI, I've audited aio routines and found that fsnotify_access()/modify() are also missing in aio_complete_rw() and in io_complete_rw_iopoll() (io_req_io_end() should be called?).

Quoted 6 lines
Quoted 4 lines

I am not using/testing aio/io_uring usually, so I wasn't planning on sending a patch any time soon. I'll get to it someday.
Just wanted to bring this to public attention in case someone is interested in testing/fixing.

aio has never done fsnotify, but I think that's probably an oversight.

I know. and I am not keen either on fixing something that nobody complained about.

Quoted 4 lines

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Again, not keep on fixing something nobody complained about. I'm asking out of curiosity.

Thanks,
Amir.

#5 lore raw
Quoted 20 lines · Amir Goldstein
Quoted 20 lines · Amir Goldstein
Quoted 18 lines · On Wed, Mar 22, 2023 at 9:08?AM Amir Goldstein <[email protected]> wrote:
Quoted 6 lines · On Wed, Mar 22, 2023 at 8:51?AM Chung-Chiang Cheng <[email protected]> wrote:
Quoted 4 lines

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

Jens, Jan,

FYI, I've audited aio routines and found that fsnotify_access()/modify() are also missing in aio_complete_rw() and in io_complete_rw_iopoll() (io_req_io_end() should be called?).

I am not using/testing aio/io_uring usually, so I wasn't planning on sending a patch any time soon. I'll get to it someday.
Just wanted to bring this to public attention in case someone is interested in testing/fixing.

Quoted 4 lines
Quoted 1 line

aio has never done fsnotify, but I think that's probably an oversight.

I know. and I am not keen either on fixing something that nobody complained about.

Nobody does buffered IO with aio (as it doesn't work), which is probably why nobody complained.

Quoted 8 lines
Quoted 4 lines

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Because it's a drastically different use case. If you're doing high performance polled IO, then you'd never rely on something as slow as fsnotify to tell you of any changes that happened to a device or file. That would be counter productive.

Signature · 1 line
Jens Axboe
reviewer
#6 lore raw
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Amir Goldstein

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Quoted 8 lines
Quoted 3 lines

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Because it's a drastically different use case. If you're doing high performance polled IO, then you'd never rely on something as slow as fsnotify to tell you of any changes that happened to a device or file. That would be counter productive.

Well, I guess Amir wanted to say that the application using fsnotify is not necessarily the one doing high performance polled IO. You could have e.g. data mirroring application A tracking files that need mirroring to another host using fsnotify and if some application B uses high performance polled IO to modify a file, application A could miss the modified file.

That being said if I look at exact details, currently I don't see a very realistic usecase that would have problems (people don't depend on FS_MODIFY or FS_ACCESS events too much, usually they just use FS_OPEN / FS_CLOSE), which is likely why nobody reported these issues yet :).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#7 lore raw
Quoted 24 lines · Jan Kara
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Amir Goldstein

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Quoted 8 lines
Quoted 3 lines

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Because it's a drastically different use case. If you're doing high performance polled IO, then you'd never rely on something as slow as fsnotify to tell you of any changes that happened to a device or file. That would be counter productive.

Well, I guess Amir wanted to say that the application using fsnotify is not necessarily the one doing high performance polled IO. You could have e.g. data mirroring application A tracking files that need mirroring to another host using fsnotify and if some application B uses high performance polled IO to modify a file, application A could miss the modified file.

Quoted 5 lines

That being said if I look at exact details, currently I don't see a very realistic usecase that would have problems (people don't depend on FS_MODIFY or FS_ACCESS events too much, usually they just use FS_OPEN / FS_CLOSE), which is likely why nobody reported these issues yet :).

I guess so.
Our monitoring application also does not rely on FS_MODIFY/FS_ACCESS as they could be too noisy.

The thing that I find missing is being able to tell if a file was *actually* accessed/modified in between open and close.
This information could be provided with FS_CLOSE event

Thanks,
Amir.

#8 lore raw
Quoted 31 lines · Amir Goldstein
Quoted 24 lines · On Tue, Apr 4, 2023 at 12:21?PM Jan Kara <[email protected]> wrote:
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Amir Goldstein

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Quoted 8 lines
Quoted 3 lines

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Because it's a drastically different use case. If you're doing high performance polled IO, then you'd never rely on something as slow as fsnotify to tell you of any changes that happened to a device or file. That would be counter productive.

Well, I guess Amir wanted to say that the application using fsnotify is not necessarily the one doing high performance polled IO. You could have e.g. data mirroring application A tracking files that need mirroring to another host using fsnotify and if some application B uses high performance polled IO to modify a file, application A could miss the modified file.

Quoted 5 lines

That being said if I look at exact details, currently I don't see a very realistic usecase that would have problems (people don't depend on FS_MODIFY or FS_ACCESS events too much, usually they just use FS_OPEN / FS_CLOSE), which is likely why nobody reported these issues yet :).

Quoted 7 lines

I guess so.
Our monitoring application also does not rely on FS_MODIFY/FS_ACCESS as they could be too noisy.

The thing that I find missing is being able to tell if a file was *actually* accessed/modified in between open and close.
This information could be provided with FS_CLOSE event

Agree, it's not a good fit for a lot of common use cases.

Signature · 1 line
Jens Axboe
#9 lore raw
In reply to Jan Kara
Quoted 17 lines · Jan Kara
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Amir Goldstein

io_uring does do it for non-polled IO, I don't think there's much point in adding it to IOPOLL however. Not really seeing any use cases where that would make sense.

Quoted 8 lines
Quoted 3 lines

Users subscribe to fsnotify because they want to be notified of changes/ access to a file.
Why do you think that polled IO should be exempt?

Because it's a drastically different use case. If you're doing high performance polled IO, then you'd never rely on something as slow as fsnotify to tell you of any changes that happened to a device or file. That would be counter productive.

Quoted 6 lines

Well, I guess Amir wanted to say that the application using fsnotify is not necessarily the one doing high performance polled IO. You could have e.g. data mirroring application A tracking files that need mirroring to another host using fsnotify and if some application B uses high performance polled IO to modify a file, application A could miss the modified file.

Sure, but what I'm trying to say is that if you're using polled IO, you're doing a custom setup anyway and the likelihood of needing fsnotify is slim to none. It'd certainly be in your best interesting to NOT rely on that, for performance reasons. And the latter is presumably why you'd using polled IO to begin with.

Quoted 5 lines

That being said if I look at exact details, currently I don't see a very realistic usecase that would have problems (people don't depend on FS_MODIFY or FS_ACCESS events too much, usually they just use FS_OPEN / FS_CLOSE), which is likely why nobody reported these issues yet :).

The only report I got on io_uring and fsnotify was someone writing a buffered log with it, and noticing that tail doesn't work if you don't have fsnotify access notifications. Open/close would not be enough there.

I'd much rather make fsnotify opt-in for io_uring than have it on by default, as it's quite the cycler consumer for IRQ based workloads right now. And that's without even having any watches on the file...

Signature · 1 line
Jens Axboe
#10 lore raw
In reply to Chung-Chiang Cheng
Quoted 4 lines · Chung-Chiang Cheng

The fsnotify ACCESS and MODIFY event are missing when manipulating a file with splice(2).

I've picked this up,

tree: git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping.git
branch: fs.misc
[1/1] splice: report related fsnotify events

      commit: 4f61a69edcf33a66269f65500434b584ee8d405e