Skip to content

Commit

Permalink
introduce FMODE_CREATED and switch to it
Browse files Browse the repository at this point in the history
Parallel to FILE_CREATED, goes into ->f_mode instead of *opened.
NFS is a bit of a wart here - it doesn't have file at the point
where FILE_CREATED used to be set, so we need to propagate it
there (for now).  IMA is another one (here and everywhere)...

Note that this needs do_dentry_open() to leave old bits in ->f_mode
alone - we want it to preserve FMODE_CREATED if it had been already
set (no other bit can be there).

Acked-by: Linus Torvalds <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jul 12, 2018
1 parent aad888f commit 73a09dd
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
v9fs_cache_inode_set_cookie(d_inode(dentry), file);

*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;
out:
dput(res);
return err;
Expand Down
2 changes: 1 addition & 1 deletion fs/9p/vfs_inode_dotl.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
file->private_data = ofid;
if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
v9fs_cache_inode_set_cookie(inode, file);
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;
out:
v9fs_put_acl(dacl, pacl);
dput(res);
Expand Down
2 changes: 1 addition & 1 deletion fs/ceph/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
dout("atomic_open finish_open on dn %p\n", dn);
if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
ceph_init_inode_acls(d_inode(dentry), &acls);
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;
}
err = finish_open(file, dentry, ceph_open, opened);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
}

if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;

rc = finish_open(file, direntry, generic_file_open, opened);
if (rc) {
Expand Down
2 changes: 1 addition & 1 deletion fs/fuse/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
goto no_open;

/* Only creates */
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;

if (fc->no_create)
goto mknod;
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
mark_inode_dirty(inode);
d_instantiate(dentry, inode);
if (file) {
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;
error = finish_open(file, dentry, gfs2_open_common, opened);
}
gfs2_glock_dq_uninit(ghs);
Expand Down
15 changes: 8 additions & 7 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3061,7 +3061,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry,
* permission here.
*/
int acc_mode = op->acc_mode;
if (*opened & FILE_CREATED) {
if (file->f_mode & FMODE_CREATED) {
WARN_ON(!(open_flag & O_CREAT));
fsnotify_create(dir, dentry);
acc_mode = 0;
Expand All @@ -3077,7 +3077,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry,
dput(dentry);
dentry = file->f_path.dentry;
}
if (*opened & FILE_CREATED)
if (file->f_mode & FMODE_CREATED)
fsnotify_create(dir, dentry);
if (unlikely(d_is_negative(dentry))) {
error = -ENOENT;
Expand Down Expand Up @@ -3126,7 +3126,7 @@ static int lookup_open(struct nameidata *nd, struct path *path,
if (unlikely(IS_DEADDIR(dir_inode)))
return -ENOENT;

*opened &= ~FILE_CREATED;
file->f_mode &= ~FMODE_CREATED;
dentry = d_lookup(dir, &nd->last);
for (;;) {
if (!dentry) {
Expand Down Expand Up @@ -3211,7 +3211,7 @@ static int lookup_open(struct nameidata *nd, struct path *path,

/* Negative dentry, just create the file */
if (!dentry->d_inode && (open_flag & O_CREAT)) {
*opened |= FILE_CREATED;
file->f_mode |= FMODE_CREATED;
audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE);
if (!dir_inode->i_op->create) {
error = -EACCES;
Expand Down Expand Up @@ -3318,15 +3318,15 @@ static int do_last(struct nameidata *nd,
if (error)
goto out;

if ((*opened & FILE_CREATED) ||
if ((file->f_mode & FMODE_CREATED) ||
!S_ISREG(file_inode(file)->i_mode))
will_truncate = false;

audit_inode(nd->name, file->f_path.dentry, 0);
goto opened;
}

if (*opened & FILE_CREATED) {
if (file->f_mode & FMODE_CREATED) {
/* Don't check for write permission, don't truncate */
open_flag &= ~O_TRUNC;
will_truncate = false;
Expand Down Expand Up @@ -3400,7 +3400,8 @@ static int do_last(struct nameidata *nd,
if (error)
goto out;
opened:
error = ima_file_check(file, op->acc_mode, *opened);
error = ima_file_check(file, op->acc_mode,
file->f_mode & FMODE_CREATED ? FILE_CREATED : 0);
if (!error && will_truncate)
error = handle_truncate(file);
out:
Expand Down
5 changes: 4 additions & 1 deletion fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
struct inode *inode;
unsigned int lookup_flags = 0;
bool switched = false;
int created = 0;
int err;

/* Expect a negative dentry */
Expand Down Expand Up @@ -1521,7 +1522,9 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
goto out;

trace_nfs_atomic_open_enter(dir, ctx, open_flags);
inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr, opened);
inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr, &created);
if (created)
file->f_mode |= FMODE_CREATED;
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
trace_nfs_atomic_open_exit(dir, ctx, open_flags, err);
Expand Down
2 changes: 1 addition & 1 deletion fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,7 @@ static int _nfs4_do_open(struct inode *dir,
}
}
if (opened && opendata->file_created)
*opened |= FILE_CREATED;
*opened = 1;

if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
*ctx_th = opendata->f_attr.mdsthreshold;
Expand Down
1 change: 1 addition & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
#define FMODE_CAN_WRITE ((__force fmode_t)0x40000)

#define FMODE_OPENED ((__force fmode_t)0x80000)
#define FMODE_CREATED ((__force fmode_t)0x100000)

/* File was opened by fanotify and shouldn't generate fanotify events */
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
Expand Down

0 comments on commit 73a09dd

Please sign in to comment.