Commit 47237687 authored by Al Viro's avatar Al Viro

->atomic_open() prototype change - pass int * instead of bool *

... and let finish_open() report having opened the file via that sucker.
Next step: don't modify od->filp at all.

[AV: FILE_CREATE was already used by cifs; Miklos' fix folded]
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a8277b9b
...@@ -64,7 +64,7 @@ ata *); ...@@ -64,7 +64,7 @@ ata *);
void (*update_time)(struct inode *, struct timespec *, int); void (*update_time)(struct inode *, struct timespec *, int);
struct file * (*atomic_open)(struct inode *, struct dentry *, struct file * (*atomic_open)(struct inode *, struct dentry *,
struct opendata *, unsigned open_flag, struct opendata *, unsigned open_flag,
umode_t create_mode, bool *created); umode_t create_mode, int *opened);
locking rules: locking rules:
all may block all may block
......
...@@ -366,7 +366,7 @@ struct inode_operations { ...@@ -366,7 +366,7 @@ struct inode_operations {
void (*update_time)(struct inode *, struct timespec *, int); void (*update_time)(struct inode *, struct timespec *, int);
struct file * (*atomic_open)(struct inode *, struct dentry *, struct file * (*atomic_open)(struct inode *, struct dentry *,
struct opendata *, unsigned open_flag, struct opendata *, unsigned open_flag,
umode_t create_mode, bool *created); umode_t create_mode, int *opened);
}; };
Again, all methods are called without any locks being held, unless Again, all methods are called without any locks being held, unless
......
...@@ -859,7 +859,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -859,7 +859,7 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
static struct file * static struct file *
v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned flags, umode_t mode, struct opendata *od, unsigned flags, umode_t mode,
bool *created) int *opened)
{ {
int err; int err;
u32 perm; u32 perm;
...@@ -918,7 +918,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -918,7 +918,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
v9inode->writeback_fid = (void *) inode_fid; v9inode->writeback_fid = (void *) inode_fid;
} }
mutex_unlock(&v9inode->v_mutex); mutex_unlock(&v9inode->v_mutex);
filp = finish_open(od, dentry, generic_file_open); filp = finish_open(od, dentry, generic_file_open, opened);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
err = PTR_ERR(filp); err = PTR_ERR(filp);
goto error; goto error;
...@@ -930,7 +930,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -930,7 +930,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
v9fs_cache_inode_set_cookie(dentry->d_inode, filp); v9fs_cache_inode_set_cookie(dentry->d_inode, filp);
#endif #endif
*created = true; *opened |= FILE_CREATED;
out: out:
dput(res); dput(res);
return filp; return filp;
......
...@@ -243,7 +243,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, umode_t omode, ...@@ -243,7 +243,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
static struct file * static struct file *
v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned flags, umode_t omode, struct opendata *od, unsigned flags, umode_t omode,
bool *created) int *opened)
{ {
int err = 0; int err = 0;
gid_t gid; gid_t gid;
...@@ -357,7 +357,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, ...@@ -357,7 +357,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
} }
mutex_unlock(&v9inode->v_mutex); mutex_unlock(&v9inode->v_mutex);
/* Since we are opening a file, assign the open fid to the file */ /* Since we are opening a file, assign the open fid to the file */
filp = finish_open(od, dentry, generic_file_open); filp = finish_open(od, dentry, generic_file_open, opened);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
err = PTR_ERR(filp); err = PTR_ERR(filp);
goto err_clunk_old_fid; goto err_clunk_old_fid;
...@@ -367,7 +367,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry, ...@@ -367,7 +367,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
if (v9ses->cache) if (v9ses->cache)
v9fs_cache_inode_set_cookie(inode, filp); v9fs_cache_inode_set_cookie(inode, filp);
#endif #endif
*created = true; *opened |= FILE_CREATED;
out: out:
dput(res); dput(res);
return filp; return filp;
......
...@@ -636,7 +636,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -636,7 +636,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry, struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned flags, umode_t mode, struct opendata *od, unsigned flags, umode_t mode,
bool *created) int *opened)
{ {
int err; int err;
struct dentry *res = NULL; struct dentry *res = NULL;
...@@ -650,7 +650,7 @@ struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -650,7 +650,7 @@ struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry,
if (err < 0) if (err < 0)
return ERR_PTR(err); return ERR_PTR(err);
return ceph_lookup_open(dir, dentry, od, flags, mode); return ceph_lookup_open(dir, dentry, od, flags, mode, opened);
} }
if (d_unhashed(dentry)) { if (d_unhashed(dentry)) {
...@@ -668,8 +668,8 @@ struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -668,8 +668,8 @@ struct file *ceph_atomic_open(struct inode *dir, struct dentry *dentry,
return NULL; return NULL;
} }
*created = true; *opened |= FILE_CREATED;
filp = ceph_lookup_open(dir, dentry, od, flags, mode); filp = ceph_lookup_open(dir, dentry, od, flags, mode, opened);
dput(res); dput(res);
return filp; return filp;
......
...@@ -214,7 +214,8 @@ int ceph_open(struct inode *inode, struct file *file) ...@@ -214,7 +214,8 @@ int ceph_open(struct inode *inode, struct file *file)
* ceph_release gets called). So fear not! * ceph_release gets called). So fear not!
*/ */
struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry, struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned flags, umode_t mode) struct opendata *od, unsigned flags, umode_t mode,
int *opened)
{ {
struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
struct ceph_mds_client *mdsc = fsc->mdsc; struct ceph_mds_client *mdsc = fsc->mdsc;
...@@ -247,7 +248,7 @@ struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry, ...@@ -247,7 +248,7 @@ struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry,
err = ceph_handle_notrace_create(dir, dentry); err = ceph_handle_notrace_create(dir, dentry);
if (err) if (err)
goto out; goto out;
file = finish_open(od, req->r_dentry, ceph_open); file = finish_open(od, req->r_dentry, ceph_open, opened);
if (IS_ERR(file)) if (IS_ERR(file))
err = PTR_ERR(file); err = PTR_ERR(file);
out: out:
......
...@@ -808,7 +808,7 @@ extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags); ...@@ -808,7 +808,7 @@ extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
extern int ceph_open(struct inode *inode, struct file *file); extern int ceph_open(struct inode *inode, struct file *file);
extern struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry, extern struct file *ceph_lookup_open(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned flags, struct opendata *od, unsigned flags,
umode_t mode); umode_t mode, int *opened);
extern int ceph_release(struct inode *inode, struct file *filp); extern int ceph_release(struct inode *inode, struct file *filp);
/* dir.c */ /* dir.c */
......
...@@ -48,7 +48,7 @@ extern int cifs_create(struct inode *, struct dentry *, umode_t, ...@@ -48,7 +48,7 @@ extern int cifs_create(struct inode *, struct dentry *, umode_t,
struct nameidata *); struct nameidata *);
extern struct file *cifs_atomic_open(struct inode *, struct dentry *, extern struct file *cifs_atomic_open(struct inode *, struct dentry *,
struct opendata *, unsigned, umode_t, struct opendata *, unsigned, umode_t,
bool *); int *);
extern struct dentry *cifs_lookup(struct inode *, struct dentry *, extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
struct nameidata *); struct nameidata *);
extern int cifs_unlink(struct inode *dir, struct dentry *dentry); extern int cifs_unlink(struct inode *dir, struct dentry *dentry);
......
...@@ -160,7 +160,7 @@ check_name(struct dentry *direntry) ...@@ -160,7 +160,7 @@ check_name(struct dentry *direntry)
static int cifs_do_create(struct inode *inode, struct dentry *direntry, static int cifs_do_create(struct inode *inode, struct dentry *direntry,
int xid, struct tcon_link *tlink, unsigned oflags, int xid, struct tcon_link *tlink, unsigned oflags,
umode_t mode, __u32 *oplock, __u16 *fileHandle, umode_t mode, __u32 *oplock, __u16 *fileHandle,
bool *created) int *created)
{ {
int rc = -ENOENT; int rc = -ENOENT;
int create_options = CREATE_NOT_DIR; int create_options = CREATE_NOT_DIR;
...@@ -311,7 +311,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, ...@@ -311,7 +311,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry,
.device = 0, .device = 0,
}; };
*created = true; *created |= FILE_CREATED;
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
args.uid = (__u64) current_fsuid(); args.uid = (__u64) current_fsuid();
if (inode->i_mode & S_ISGID) if (inode->i_mode & S_ISGID)
...@@ -379,7 +379,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, ...@@ -379,7 +379,7 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry,
struct file * struct file *
cifs_atomic_open(struct inode *inode, struct dentry *direntry, cifs_atomic_open(struct inode *inode, struct dentry *direntry,
struct opendata *od, unsigned oflags, umode_t mode, struct opendata *od, unsigned oflags, umode_t mode,
bool *created) int *opened)
{ {
int rc; int rc;
int xid; int xid;
...@@ -426,14 +426,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, ...@@ -426,14 +426,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
tcon = tlink_tcon(tlink); tcon = tlink_tcon(tlink);
rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
&oplock, &fileHandle, created); &oplock, &fileHandle, opened);
if (rc) { if (rc) {
filp = ERR_PTR(rc); filp = ERR_PTR(rc);
goto out; goto out;
} }
filp = finish_open(od, direntry, generic_file_open); filp = finish_open(od, direntry, generic_file_open, opened);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
CIFSSMBClose(xid, tcon, fileHandle); CIFSSMBClose(xid, tcon, fileHandle);
goto out; goto out;
...@@ -469,7 +469,7 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode, ...@@ -469,7 +469,7 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
struct tcon_link *tlink; struct tcon_link *tlink;
__u16 fileHandle; __u16 fileHandle;
__u32 oplock; __u32 oplock;
bool created = true; int created = FILE_CREATED;
cFYI(1, "cifs_create parent inode = 0x%p name is: %s and dentry = 0x%p", cFYI(1, "cifs_create parent inode = 0x%p name is: %s and dentry = 0x%p",
inode, direntry->d_name.name, direntry); inode, direntry->d_name.name, direntry);
......
...@@ -371,7 +371,7 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, ...@@ -371,7 +371,7 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
*/ */
static struct file *fuse_create_open(struct inode *dir, struct dentry *entry, static struct file *fuse_create_open(struct inode *dir, struct dentry *entry,
struct opendata *od, unsigned flags, struct opendata *od, unsigned flags,
umode_t mode) umode_t mode, int *opened)
{ {
int err; int err;
struct inode *inode; struct inode *inode;
...@@ -450,7 +450,7 @@ static struct file *fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -450,7 +450,7 @@ static struct file *fuse_create_open(struct inode *dir, struct dentry *entry,
d_instantiate(entry, inode); d_instantiate(entry, inode);
fuse_change_entry_timeout(entry, &outentry); fuse_change_entry_timeout(entry, &outentry);
fuse_invalidate_attr(dir); fuse_invalidate_attr(dir);
file = finish_open(od, entry, generic_file_open); file = finish_open(od, entry, generic_file_open, opened);
if (IS_ERR(file)) { if (IS_ERR(file)) {
fuse_sync_release(ff, flags); fuse_sync_release(ff, flags);
} else { } else {
...@@ -472,7 +472,7 @@ static struct file *fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -472,7 +472,7 @@ static struct file *fuse_create_open(struct inode *dir, struct dentry *entry,
static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t); static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
static struct file *fuse_atomic_open(struct inode *dir, struct dentry *entry, static struct file *fuse_atomic_open(struct inode *dir, struct dentry *entry,
struct opendata *od, unsigned flags, struct opendata *od, unsigned flags,
umode_t mode, bool *created) umode_t mode, int *opened)
{ {
int err; int err;
struct fuse_conn *fc = get_fuse_conn(dir); struct fuse_conn *fc = get_fuse_conn(dir);
...@@ -492,12 +492,12 @@ static struct file *fuse_atomic_open(struct inode *dir, struct dentry *entry, ...@@ -492,12 +492,12 @@ static struct file *fuse_atomic_open(struct inode *dir, struct dentry *entry,
goto no_open; goto no_open;
/* Only creates */ /* Only creates */
*created = true; *opened |= FILE_CREATED;
if (fc->no_create) if (fc->no_create)
goto mknod; goto mknod;
file = fuse_create_open(dir, entry, od, flags, mode); file = fuse_create_open(dir, entry, od, flags, mode, opened);
if (PTR_ERR(file) == -ENOSYS) { if (PTR_ERR(file) == -ENOSYS) {
fc->no_create = 1; fc->no_create = 1;
goto mknod; goto mknod;
......
...@@ -2197,7 +2197,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2197,7 +2197,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry,
struct path *path, struct opendata *od, struct path *path, struct opendata *od,
const struct open_flags *op, const struct open_flags *op,
bool *want_write, bool need_lookup, bool *want_write, bool need_lookup,
bool *created) int *opened)
{ {
struct inode *dir = nd->path.dentry->d_inode; struct inode *dir = nd->path.dentry->d_inode;
unsigned open_flag = open_to_namei_flags(op->open_flag); unsigned open_flag = open_to_namei_flags(op->open_flag);
...@@ -2222,7 +2222,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2222,7 +2222,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry,
if (open_flag & O_EXCL) { if (open_flag & O_EXCL) {
open_flag &= ~O_TRUNC; open_flag &= ~O_TRUNC;
*created = true; *opened |= FILE_CREATED;
} }
/* /*
...@@ -2272,7 +2272,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2272,7 +2272,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry,
od->dentry = DENTRY_NOT_SET; od->dentry = DENTRY_NOT_SET;
od->mnt = nd->path.mnt; od->mnt = nd->path.mnt;
filp = dir->i_op->atomic_open(dir, dentry, od, open_flag, mode, filp = dir->i_op->atomic_open(dir, dentry, od, open_flag, mode,
created); opened);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
if (WARN_ON(od->dentry != DENTRY_NOT_SET)) if (WARN_ON(od->dentry != DENTRY_NOT_SET))
dput(od->dentry); dput(od->dentry);
...@@ -2283,7 +2283,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2283,7 +2283,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry,
} }
acc_mode = op->acc_mode; acc_mode = op->acc_mode;
if (*created) { if (*opened & FILE_CREATED) {
fsnotify_create(dir, dentry); fsnotify_create(dir, dentry);
acc_mode = MAY_OPEN; acc_mode = MAY_OPEN;
} }
...@@ -2353,7 +2353,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry, ...@@ -2353,7 +2353,7 @@ static struct file *atomic_open(struct nameidata *nd, struct dentry *dentry,
static struct file *lookup_open(struct nameidata *nd, struct path *path, static struct file *lookup_open(struct nameidata *nd, struct path *path,
struct opendata *od, struct opendata *od,
const struct open_flags *op, const struct open_flags *op,
bool *want_write, bool *created) bool *want_write, int *opened)
{ {
struct dentry *dir = nd->path.dentry; struct dentry *dir = nd->path.dentry;
struct inode *dir_inode = dir->d_inode; struct inode *dir_inode = dir->d_inode;
...@@ -2361,7 +2361,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, ...@@ -2361,7 +2361,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path,
int error; int error;
bool need_lookup; bool need_lookup;
*created = false; *opened &= ~FILE_CREATED;
dentry = lookup_dcache(&nd->last, dir, nd, &need_lookup); dentry = lookup_dcache(&nd->last, dir, nd, &need_lookup);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return ERR_CAST(dentry); return ERR_CAST(dentry);
...@@ -2372,7 +2372,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, ...@@ -2372,7 +2372,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path,
if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) { if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) {
return atomic_open(nd, dentry, path, od, op, want_write, return atomic_open(nd, dentry, path, od, op, want_write,
need_lookup, created); need_lookup, opened);
} }
if (need_lookup) { if (need_lookup) {
...@@ -2399,7 +2399,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, ...@@ -2399,7 +2399,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path,
if (error) if (error)
goto out_dput; goto out_dput;
*want_write = true; *want_write = true;
*created = true; *opened |= FILE_CREATED;
error = security_path_mknod(&nd->path, dentry, mode, 0); error = security_path_mknod(&nd->path, dentry, mode, 0);
if (error) if (error)
goto out_dput; goto out_dput;
...@@ -2422,7 +2422,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path, ...@@ -2422,7 +2422,7 @@ static struct file *lookup_open(struct nameidata *nd, struct path *path,
*/ */
static struct file *do_last(struct nameidata *nd, struct path *path, static struct file *do_last(struct nameidata *nd, struct path *path,
struct opendata *od, const struct open_flags *op, struct opendata *od, const struct open_flags *op,
const char *pathname) int *opened, const char *pathname)
{ {
struct dentry *dir = nd->path.dentry; struct dentry *dir = nd->path.dentry;
int open_flag = op->open_flag; int open_flag = op->open_flag;
...@@ -2431,7 +2431,6 @@ static struct file *do_last(struct nameidata *nd, struct path *path, ...@@ -2431,7 +2431,6 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
int acc_mode = op->acc_mode; int acc_mode = op->acc_mode;
struct file *filp; struct file *filp;
struct inode *inode; struct inode *inode;
bool created;
bool symlink_ok = false; bool symlink_ok = false;
struct path save_parent = { .dentry = NULL, .mnt = NULL }; struct path save_parent = { .dentry = NULL, .mnt = NULL };
bool retried = false; bool retried = false;
...@@ -2499,21 +2498,22 @@ static struct file *do_last(struct nameidata *nd, struct path *path, ...@@ -2499,21 +2498,22 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
retry_lookup: retry_lookup:
mutex_lock(&dir->d_inode->i_mutex); mutex_lock(&dir->d_inode->i_mutex);
filp = lookup_open(nd, path, od, op, &want_write, &created); filp = lookup_open(nd, path, od, op, &want_write, opened);
mutex_unlock(&dir->d_inode->i_mutex); mutex_unlock(&dir->d_inode->i_mutex);
if (filp) { if (filp) {
if (IS_ERR(filp)) if (IS_ERR(filp))
goto out; goto out;
if (created || !S_ISREG(filp->f_path.dentry->d_inode->i_mode)) if ((*opened & FILE_CREATED) ||
!S_ISREG(filp->f_path.dentry->d_inode->i_mode))
will_truncate = false; will_truncate = false;
audit_inode(pathname, filp->f_path.dentry); audit_inode(pathname, filp->f_path.dentry);
goto opened; goto opened;
} }
if (created) { if (*opened & FILE_CREATED) {
/* Don't check for write permission, don't truncate */ /* Don't check for write permission, don't truncate */
open_flag &= ~O_TRUNC; open_flag &= ~O_TRUNC;
will_truncate = false; will_truncate = false;
...@@ -2606,7 +2606,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, ...@@ -2606,7 +2606,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
if (error) if (error)
goto exit; goto exit;
od->mnt = nd->path.mnt; od->mnt = nd->path.mnt;
filp = finish_open(od, nd->path.dentry, NULL); filp = finish_open(od, nd->path.dentry, NULL, opened);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
if (filp == ERR_PTR(-EOPENSTALE)) if (filp == ERR_PTR(-EOPENSTALE))
goto stale_open; goto stale_open;
...@@ -2667,6 +2667,7 @@ static struct file *path_openat(int dfd, const char *pathname, ...@@ -2667,6 +2667,7 @@ static struct file *path_openat(int dfd, const char *pathname,
struct opendata od; struct opendata od;
struct file *res; struct file *res;
struct path path; struct path path;
int opened = 0;
int error; int error;
od.filp = get_empty_filp(); od.filp = get_empty_filp();
...@@ -2684,7 +2685,7 @@ static struct file *path_openat(int dfd, const char *pathname, ...@@ -2684,7 +2685,7 @@ static struct file *path_openat(int dfd, const char *pathname,
if (unlikely(error)) if (unlikely(error))
goto out_filp; goto out_filp;
res = do_last(nd, &path, &od, op, pathname); res = do_last(nd, &path, &od, op, &opened, pathname);
while (unlikely(!res)) { /* trailing symlink */ while (unlikely(!res)) { /* trailing symlink */
struct path link = path; struct path link = path;
void *cookie; void *cookie;
...@@ -2699,7 +2700,7 @@ static struct file *path_openat(int dfd, const char *pathname, ...@@ -2699,7 +2700,7 @@ static struct file *path_openat(int dfd, const char *pathname,
error = follow_link(&link, nd, &cookie); error = follow_link(&link, nd, &cookie);
if (unlikely(error)) if (unlikely(error))
goto out_filp; goto out_filp;
res = do_last(nd, &path, &od, op, pathname); res = do_last(nd, &path, &od, op, &opened, pathname);
put_link(nd, &link, cookie); put_link(nd, &link, cookie);
} }
out: out:
......
...@@ -113,7 +113,7 @@ const struct inode_operations nfs3_dir_inode_operations = { ...@@ -113,7 +113,7 @@ const struct inode_operations nfs3_dir_inode_operations = {
static struct file *nfs_atomic_open(struct inode *, struct dentry *, static struct file *nfs_atomic_open(struct inode *, struct dentry *,
struct opendata *, unsigned, umode_t, struct opendata *, unsigned, umode_t,
bool *); int *);
const struct inode_operations nfs4_dir_inode_operations = { const struct inode_operations nfs4_dir_inode_operations = {
.create = nfs_create, .create = nfs_create,
.lookup = nfs_lookup, .lookup = nfs_lookup,
...@@ -1389,7 +1389,8 @@ static int do_open(struct inode *inode, struct file *filp) ...@@ -1389,7 +1389,8 @@ static int do_open(struct inode *inode, struct file *filp)
static struct file *nfs_finish_open(struct nfs_open_context *ctx, static struct file *nfs_finish_open(struct nfs_open_context *ctx,
struct dentry *dentry, struct dentry *dentry,
struct opendata *od, unsigned open_flags) struct opendata *od, unsigned open_flags,
int *opened)
{ {
struct file *filp; struct file *filp;
int err; int err;
...@@ -1408,7 +1409,7 @@ static struct file *nfs_finish_open(struct nfs_open_context *ctx, ...@@ -1408,7 +1409,7 @@ static struct file *nfs_finish_open(struct nfs_open_context *ctx,
} }
} }
filp = finish_open(od, dentry, do_open); filp = finish_open(od, dentry, do_open, opened);
if (!IS_ERR(filp)) if (!IS_ERR(filp))
nfs_file_set_open_context(filp, ctx); nfs_file_set_open_context(filp, ctx);
...@@ -1419,7 +1420,7 @@ static struct file *nfs_finish_open(struct nfs_open_context *ctx, ...@@ -1419,7 +1420,7 @@ static struct file *nfs_finish_open(struct nfs_open_context *ctx,
static struct file *nfs_atomic_open(struct inode *dir, struct dentry *dentry, static struct file *nfs_atomic_open(struct inode *dir, struct dentry *dentry,
struct opendata *od, unsigned open_flags, struct opendata *od, unsigned open_flags,
umode_t mode, bool *created) umode_t mode, int *opened)
{ {
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct dentry *res; struct dentry *res;
...@@ -1497,7 +1498,7 @@ static struct file *nfs_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -1497,7 +1498,7 @@ static struct file *nfs_atomic_open(struct inode *dir, struct dentry *dentry,
nfs_unblock_sillyrename(dentry->d_parent); nfs_unblock_sillyrename(dentry->d_parent);
nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
filp = nfs_finish_open(ctx, dentry, od, open_flags); filp = nfs_finish_open(ctx, dentry, od, open_flags, opened);
dput(res); dput(res);
return filp; return filp;
......
...@@ -782,7 +782,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, ...@@ -782,7 +782,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
* filesystem callback is substituted. * filesystem callback is substituted.
*/ */
struct file *finish_open(struct opendata *od, struct dentry *dentry, struct file *finish_open(struct opendata *od, struct dentry *dentry,
int (*open)(struct inode *, struct file *)) int (*open)(struct inode *, struct file *),
int *opened)
{ {
struct file *res; struct file *res;
...@@ -790,8 +791,10 @@ struct file *finish_open(struct opendata *od, struct dentry *dentry, ...@@ -790,8 +791,10 @@ struct file *finish_open(struct opendata *od, struct dentry *dentry,
dget(dentry); dget(dentry);
res = do_dentry_open(dentry, od->mnt, od->filp, open, current_cred()); res = do_dentry_open(dentry, od->mnt, od->filp, open, current_cred());
if (!IS_ERR(res)) if (!IS_ERR(res)) {
*opened |= FILE_OPENED;
od->filp = NULL; od->filp = NULL;
}
return res; return res;
} }
......
...@@ -1696,7 +1696,7 @@ struct inode_operations { ...@@ -1696,7 +1696,7 @@ struct inode_operations {
int (*update_time)(struct inode *, struct timespec *, int); int (*update_time)(struct inode *, struct timespec *, int);
struct file * (*atomic_open)(struct inode *, struct dentry *, struct file * (*atomic_open)(struct inode *, struct dentry *,
struct opendata *, unsigned open_flag, struct opendata *, unsigned open_flag,
umode_t create_mode, bool *created); umode_t create_mode, int *opened);
} ____cacheline_aligned; } ____cacheline_aligned;
struct seq_file; struct seq_file;
...@@ -2065,8 +2065,13 @@ extern struct file * dentry_open(struct dentry *, struct vfsmount *, int, ...@@ -2065,8 +2065,13 @@ extern struct file * dentry_open(struct dentry *, struct vfsmount *, int,
const struct cred *); const struct cred *);
extern int filp_close(struct file *, fl_owner_t id); extern int filp_close(struct file *, fl_owner_t id);
extern char * getname(const char __user *); extern char * getname(const char __user *);
enum {
FILE_CREATED = 1,
FILE_OPENED = 2
};
extern struct file *finish_open(struct opendata *od, struct dentry *dentry, extern struct file *finish_open(struct opendata *od, struct dentry *dentry,
int (*open)(struct inode *, struct file *)); int (*open)(struct inode *, struct file *),
int *opened);
extern void finish_no_open(struct opendata *od, struct dentry *dentry); extern void finish_no_open(struct opendata *od, struct dentry *dentry);
/* fs/ioctl.c */ /* fs/ioctl.c */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment