linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC][PATCH 05/27] introduce FMODE_OPENED
Date: Mon,  9 Jul 2018 05:53:55 +0100	[thread overview]
Message-ID: <20180709045417.13988-5-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20180709045417.13988-1-viro@ZenIV.linux.org.uk>

From: Al Viro <viro@zeniv.linux.org.uk>

basically, "is that instance set up enough for regular fput(), or
do we want put_filp() for that one".

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 arch/ia64/kernel/perfmon.c | 1 +
 drivers/misc/cxl/api.c     | 2 +-
 fs/aio.c                   | 3 ++-
 fs/anon_inodes.c           | 2 +-
 fs/hugetlbfs/inode.c       | 2 +-
 fs/open.c                  | 3 ++-
 fs/pipe.c                  | 2 ++
 include/linux/fs.h         | 3 +++
 ipc/shm.c                  | 2 +-
 mm/shmem.c                 | 2 +-
 net/socket.c               | 2 +-
 11 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 3b38c717008a..017c568bb8a4 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -2684,6 +2684,7 @@ pfm_context_create(pfm_context_t *ctx, void *arg, int count, struct pt_regs *reg
 	 * initialize soft PMU state
 	 */
 	pfm_reset_pmu_state(ctx);
+	filp->f_mode |= FMODE_OPENED;
 
 	fd_install(fd, filp);
 
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index 6b16946f9b05..146a12fe6cb8 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -102,7 +102,7 @@ static struct file *cxl_getfile(const char *name,
 	path.mnt = mntget(cxl_vfs_mount);
 	d_instantiate(path.dentry, inode);
 
-	file = alloc_file(&path, OPEN_FMODE(flags), fops);
+	file = alloc_file(&path, OPEN_FMODE(flags) | FMODE_OPENED, fops);
 	if (IS_ERR(file)) {
 		path_put(&path);
 		goto err_fs;
diff --git a/fs/aio.c b/fs/aio.c
index e1d20124ec0e..4d63e8e4d1b5 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -234,7 +234,8 @@ static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages)
 	path.mnt = mntget(aio_mnt);
 
 	d_instantiate(path.dentry, inode);
-	file = alloc_file(&path, FMODE_READ | FMODE_WRITE, &aio_ring_fops);
+	file = alloc_file(&path, FMODE_READ | FMODE_WRITE | FMODE_OPENED,
+			  &aio_ring_fops);
 	if (IS_ERR(file)) {
 		path_put(&path);
 		return file;
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 3168ee4e77f4..bf952939a1d3 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -102,7 +102,7 @@ struct file *anon_inode_getfile(const char *name,
 
 	d_instantiate(path.dentry, anon_inode_inode);
 
-	file = alloc_file(&path, OPEN_FMODE(flags), fops);
+	file = alloc_file(&path, OPEN_FMODE(flags) | FMODE_OPENED, fops);
 	if (IS_ERR(file))
 		goto err_dput;
 	file->f_mapping = anon_inode_inode->i_mapping;
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index d508c7844681..e0b8cc89169c 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -1375,7 +1375,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
 	inode->i_size = size;
 	clear_nlink(inode);
 
-	file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
+	file = alloc_file(&path, FMODE_WRITE | FMODE_READ | FMODE_OPENED,
 			&hugetlbfs_file_operations);
 	if (IS_ERR(file))
 		goto out_dentry; /* inode is already attached */
diff --git a/fs/open.c b/fs/open.c
index 40658ef912d2..aec2686130b1 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -753,7 +753,7 @@ static int do_dentry_open(struct file *f,
 	f->f_wb_err = filemap_sample_wb_err(f->f_mapping);
 
 	if (unlikely(f->f_flags & O_PATH)) {
-		f->f_mode = FMODE_PATH;
+		f->f_mode = FMODE_PATH | FMODE_OPENED;
 		f->f_op = &empty_fops;
 		return 0;
 	}
@@ -795,6 +795,7 @@ static int do_dentry_open(struct file *f,
 		if (error)
 			goto cleanup_all;
 	}
+	f->f_mode |= FMODE_OPENED;
 	if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
 		i_readcount_inc(inode);
 	if ((f->f_mode & FMODE_READ) &&
diff --git a/fs/pipe.c b/fs/pipe.c
index bb0840e234f3..4d62c935f675 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -775,6 +775,8 @@ int create_pipe_files(struct file **res, int flags)
 		goto err_file;
 	}
 
+	res[0]->f_mode |= FMODE_OPENED;
+	f->f_mode |= FMODE_OPENED;
 	path_get(&path);
 	res[0]->private_data = inode->i_pipe;
 	res[0]->f_flags = O_RDONLY | (flags & O_NONBLOCK);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index aa9b4c169ed2..d1ce90634d8b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -148,12 +148,15 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 /* Has write method(s) */
 #define FMODE_CAN_WRITE         ((__force fmode_t)0x40000)
 
+#define FMODE_OPENED		((__force fmode_t)0x80000)
+
 /* File was opened by fanotify and shouldn't generate fanotify events */
 #define FMODE_NONOTIFY		((__force fmode_t)0x4000000)
 
 /* File is capable of returning -EAGAIN if I/O will block */
 #define FMODE_NOWAIT	((__force fmode_t)0x8000000)
 
+
 /*
  * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
  * that indicates that they should check the contents of the iovec are
diff --git a/ipc/shm.c b/ipc/shm.c
index 051a3e1fb8df..e37931121070 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1449,7 +1449,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg,
 		goto out_nattch;
 	}
 
-	file = alloc_file(&path, f_mode,
+	file = alloc_file(&path, f_mode | FMODE_OPENED,
 			  is_file_hugepages(shp->shm_file) ?
 				&shm_file_operations_huge :
 				&shm_file_operations);
diff --git a/mm/shmem.c b/mm/shmem.c
index 2cab84403055..a76adc3802d1 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3942,7 +3942,7 @@ static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, l
 	if (IS_ERR(res))
 		goto put_path;
 
-	res = alloc_file(&path, FMODE_WRITE | FMODE_READ,
+	res = alloc_file(&path, FMODE_WRITE | FMODE_READ | FMODE_OPENED,
 		  &shmem_file_operations);
 	if (IS_ERR(res))
 		goto put_path;
diff --git a/net/socket.c b/net/socket.c
index 8a109012608a..eff9db5fd99f 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -411,7 +411,7 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
 
 	d_instantiate(path.dentry, SOCK_INODE(sock));
 
-	file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
+	file = alloc_file(&path, FMODE_READ | FMODE_WRITE | FMODE_OPENED,
 		  &socket_file_ops);
 	if (IS_ERR(file)) {
 		/* drop dentry, keep inode for a bit */
-- 
2.11.0

  parent reply	other threads:[~2018-07-09  4:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-09  4:53 [RFC][PATCHES] open()-related cleanups Al Viro
2018-07-09  4:53 ` [RFC][PATCH 01/27] drm_mode_create_lease_ioctl(): fix open-coded filp_clone_open() Al Viro
2018-07-09  4:53   ` [RFC][PATCH 02/27] cxl_getfile(): fix double-iput() on alloc_file() failures Al Viro
2018-07-09  4:53   ` [RFC][PATCH 03/27] ocxlflash_getfile(): " Al Viro
2018-07-09  4:53   ` [RFC][PATCH 04/27] make sure do_dentry_open() won't return positive as an error Al Viro
2018-07-09  4:53   ` Al Viro [this message]
2018-07-09  4:53   ` [RFC][PATCH 06/27] get rid of 'opened' argument of finish_open() Al Viro
2018-07-09  4:53   ` [RFC][PATCH 07/27] lift fput() on late failures into path_openat() Al Viro
2018-07-09  4:53   ` [RFC][PATCH 08/27] switch all remaining checks for FILE_OPENED to FMODE_OPENED Al Viro
2018-07-09  4:53   ` [RFC][PATCH 09/27] now we can fold open_check_o_direct() into do_dentry_open() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 10/27] introduce FMODE_CREATED and switch to it Al Viro
2018-07-09  4:54   ` [RFC][PATCH 11/27] IMA: don't propagate opened through the entire thing Al Viro
2018-07-09  4:54   ` [RFC][PATCH 12/27] Preparation to killing ->atomic_open() 'opened' argument Al Viro
2018-07-09  4:54   ` [RFC][PATCH 13/27] get rid of 'opened' argument of ->atomic_open() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 14/27] get rid of 'opened' in path_openat() and the helpers downstream Al Viro
2018-07-09  4:54   ` [RFC][PATCH 15/27] kill FILE_{CREATED,OPENED} Al Viro
2018-07-09  4:54   ` [RFC][PATCH 16/27] new wrapper: alloc_file_pseudo() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 17/27] __shmem_file_setup(): reorder allocations Al Viro
2018-07-09  4:54   ` [RFC][PATCH 18/27] ... and switch shmem_file_setup() to alloc_file_pseudo() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 19/27] cxl_getfile(): switch " Al Viro
2018-07-09  4:54   ` [RFC][PATCH 20/27] ocxlflash_getfile(): " Al Viro
2018-07-09  4:54   ` [RFC][PATCH 21/27] hugetlb_file_setup(): " Al Viro
2018-07-09  4:54   ` [RFC][PATCH 22/27] anon_inode_getfile(): " Al Viro
2018-07-09  4:54   ` [RFC][PATCH 23/27] create_pipe_files(): switch the first allocation " Al Viro
2018-07-09  4:54   ` [RFC][PATCH 24/27] new helper: alloc_file_clone() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 25/27] do_shmat(): grab shp->shm_file earlier, switch to alloc_file_clone() Al Viro
2018-07-09  4:54   ` [RFC][PATCH 26/27] make alloc_file() static Al Viro
2018-07-09  4:54   ` [RFC][PATCH 27/27] turn filp_clone_open() into inline wrapper for dentry_open() Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180709045417.13988-5-viro@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).