[PATCH 03/13] introduce FMODE_OPENED

From: Al Viro
Date: Fri Jun 08 2018 - 14:50:29 EST


From: Al Viro <viro@xxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxx>
---
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 8fb280e33114..ae4c762321d4 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 753b1a698fc4..0427ff3f575a 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))
goto err_dput;
file->f_flags = flags & (O_ACCMODE | O_NONBLOCK);
diff --git a/fs/aio.c b/fs/aio.c
index 49f53516eef0..bbc3fc0d0524 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -223,7 +223,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 96ab60d52303..b3b1dbf0227d 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 39d6f431da83..a03622bd3491 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -772,6 +772,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 8f0b4667ebf1..105f071d4732 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -147,12 +147,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 3cf48988d68c..2d0a6a9f2559 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1438,7 +1438,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 9d6c7e595415..80103281af8d 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -4239,7 +4239,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 f10f1d947c78..00934c3fa46a 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -407,7 +407,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