147 lines
3.7 KiB
Diff
147 lines
3.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Tyler Smith <74526874+tylertms@users.noreply.github.com>
|
|
Date: Tue, 3 Nov 2026 04:20:02 +0000
|
|
Subject: [PATCH] refactor(fs): separate file flush and close
|
|
|
|
---
|
|
fs/Makefile | 2 +-
|
|
fs/filp_close.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
|
|
fs/filp_close.h | 9 +++++++++
|
|
fs/open.c | 36 +-----------------------------------
|
|
4 files changed, 55 insertions(+), 36 deletions(-)
|
|
create mode 100644 fs/filp_close.c
|
|
create mode 100644 fs/filp_close.h
|
|
|
|
diff --git a/fs/Makefile b/fs/Makefile
|
|
index 355e6b5cb30c2dab23aed52e41a9c8bea3d2fcd9..7f3dfe03afe8d6c77ecc22ae85a5475e0eb725e9 100644
|
|
--- a/fs/Makefile
|
|
+++ b/fs/Makefile
|
|
@@ -7,7 +7,7 @@
|
|
#
|
|
|
|
|
|
-obj-y := open.o read_write.o file_table.o super.o \
|
|
+obj-y := open.o filp_close.o read_write.o file_table.o super.o \
|
|
char_dev.o stat.o exec.o task_comm.o pipe.o namei.o fcntl.o \
|
|
ioctl.o readdir.o select.o dcache.o inode.o \
|
|
attr.o bad_inode.o file.o file_ref.o init_fdtable.o filesystems.o namespace.o \
|
|
diff --git a/fs/filp_close.c b/fs/filp_close.c
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..80a260a12a668592baf4ef426afe47163f26cbdc
|
|
--- /dev/null
|
|
+++ b/fs/filp_close.c
|
|
@@ -0,0 +1,44 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-only
|
|
+
|
|
+#include <linux/dnotify.h>
|
|
+#include <linux/export.h>
|
|
+#include <linux/file.h>
|
|
+#include <linux/filelock.h>
|
|
+
|
|
+#include "filp_close.h"
|
|
+#include "internal.h"
|
|
+
|
|
+/*
|
|
+ * "id" is the POSIX thread ID. We use the
|
|
+ * files pointer for this..
|
|
+ */
|
|
+int filp_flush(struct file *filp, fl_owner_t id)
|
|
+{
|
|
+ int retval = 0;
|
|
+
|
|
+ if (CHECK_DATA_CORRUPTION(file_count(filp) == 0, filp,
|
|
+ "VFS: Close: file count is 0 (f_op=%ps)",
|
|
+ filp->f_op)) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ if (filp->f_op->flush)
|
|
+ retval = filp->f_op->flush(filp, id);
|
|
+
|
|
+ if (likely(!(filp->f_mode & FMODE_PATH))) {
|
|
+ dnotify_flush(filp, id);
|
|
+ locks_remove_posix(filp, id);
|
|
+ }
|
|
+ return retval;
|
|
+}
|
|
+
|
|
+int filp_close(struct file *filp, fl_owner_t id)
|
|
+{
|
|
+ int retval;
|
|
+
|
|
+ retval = filp_flush(filp, id);
|
|
+ fput_close(filp);
|
|
+
|
|
+ return retval;
|
|
+}
|
|
+EXPORT_SYMBOL(filp_close);
|
|
diff --git a/fs/filp_close.h b/fs/filp_close.h
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..c773538257e22fdbdb3ffff11505e818c9b6e5a4
|
|
--- /dev/null
|
|
+++ b/fs/filp_close.h
|
|
@@ -0,0 +1,9 @@
|
|
+/* SPDX-License-Identifier: GPL-2.0-only */
|
|
+#ifndef _FS_FILP_CLOSE_H
|
|
+#define _FS_FILP_CLOSE_H
|
|
+
|
|
+#include <linux/fs.h>
|
|
+
|
|
+int filp_flush(struct file *filp, fl_owner_t id);
|
|
+
|
|
+#endif
|
|
diff --git a/fs/open.c b/fs/open.c
|
|
index 408925d7bd0b7702895fff07b5a94ba754d2c877..ef4a63acd9c0f88a172cd2ec4664f3ec478970b8 100644
|
|
--- a/fs/open.c
|
|
+++ b/fs/open.c
|
|
@@ -34,6 +34,7 @@
|
|
#include <linux/mnt_idmapping.h>
|
|
#include <linux/filelock.h>
|
|
|
|
+#include "filp_close.h"
|
|
#include "internal.h"
|
|
|
|
int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
|
|
@@ -1453,41 +1454,6 @@ SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
|
|
}
|
|
#endif
|
|
|
|
-/*
|
|
- * "id" is the POSIX thread ID. We use the
|
|
- * files pointer for this..
|
|
- */
|
|
-static int filp_flush(struct file *filp, fl_owner_t id)
|
|
-{
|
|
- int retval = 0;
|
|
-
|
|
- if (CHECK_DATA_CORRUPTION(file_count(filp) == 0, filp,
|
|
- "VFS: Close: file count is 0 (f_op=%ps)",
|
|
- filp->f_op)) {
|
|
- return 0;
|
|
- }
|
|
-
|
|
- if (filp->f_op->flush)
|
|
- retval = filp->f_op->flush(filp, id);
|
|
-
|
|
- if (likely(!(filp->f_mode & FMODE_PATH))) {
|
|
- dnotify_flush(filp, id);
|
|
- locks_remove_posix(filp, id);
|
|
- }
|
|
- return retval;
|
|
-}
|
|
-
|
|
-int filp_close(struct file *filp, fl_owner_t id)
|
|
-{
|
|
- int retval;
|
|
-
|
|
- retval = filp_flush(filp, id);
|
|
- fput_close(filp);
|
|
-
|
|
- return retval;
|
|
-}
|
|
-EXPORT_SYMBOL(filp_close);
|
|
-
|
|
/*
|
|
* Careful here! We test whether the file pointer is NULL before
|
|
* releasing the fd. This ensures that one clone task can't release
|