Skip to contentSkip to conversation

io_uring: ensure that fsnotify is always called

PATCH In review Jens Axboe 1 participant 2 messages Mar 20, 2022

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: ensure that fsnotify is always called

Ensure that we call fsnotify_modify() if we write a file, and that we do fsnotify_access() if we read it. This enables anyone using inotify on the file to get notified.

Ditto for fallocate, ensure that fsnotify_modify() is called.

---

fs/io_uring.c +4 -0
index 98949348ee02..7492f842025a 100644
@@ -2922,6 +2922,7 @@ static void kiocb_end_write(struct io_kiocb *req)
 		__sb_writers_acquired(sb, SB_FREEZE_WRITE);
 		sb_end_write(sb);
 	}
+	fsnotify_modify(req->file);
 }
 
 #ifdef CONFIG_BLOCK
@@ -2975,6 +2976,8 @@ static bool __io_complete_rw_common(struct io_kiocb *req, long res)
 {
 	if (req->rw.kiocb.ki_flags & IOCB_WRITE)
 		kiocb_end_write(req);
+	else
+		fsnotify_access(req->file);
 	if (unlikely(res != req->result)) {
 		if ((res == -EAGAIN || res == -EOPNOTSUPP) &&
 		    io_rw_should_reissue(req)) {
@@ -4538,6 +4541,7 @@ static int io_fallocate(struct io_kiocb *req, unsigned int issue_flags)
 	if (ret < 0)
 		req_set_fail(req);
 	io_req_complete(req, ret);
+	fsnotify_modify(req->file);
 	return 0;
 }
 
Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw
Quoted 5 lines · Jens Axboe

Ensure that we call fsnotify_modify() if we write a file, and that we do fsnotify_access() if we read it. This enables anyone using inotify on the file to get notified.

Ditto for fallocate, ensure that fsnotify_modify() is called.

Forgot to put in the patch notes - this is not new for io_uring, aio never called fsnotify either. But we do have a much broader scope that aio which is all db and dio. Would be nice to have this be opt-in or similar, though at least the per-op hit doesn't seem to be that large if nobody is has a notifier registered (which is 99.99% of the use cases...).

Signature · 1 line
Jens Axboe