Commit f46e0bd3 authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Further minor cleanups for nfs4_atomic_open()

Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent cd9a1c0e
...@@ -1084,8 +1084,8 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry ...@@ -1084,8 +1084,8 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
struct nfs_open_context *ctx; struct nfs_open_context *ctx;
struct iattr attr; struct iattr attr;
struct dentry *res = NULL; struct dentry *res = NULL;
struct inode *inode;
int open_flags; int open_flags;
int error;
dfprintk(VFS, "NFS: atomic_lookup(%s/%ld), %s\n", dfprintk(VFS, "NFS: atomic_lookup(%s/%ld), %s\n",
dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); dir->i_sb->s_id, dir->i_ino, dentry->d_name.name);
...@@ -1125,13 +1125,15 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry ...@@ -1125,13 +1125,15 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
} }
/* Open the file on the server */ /* Open the file on the server */
res = nfs4_atomic_open(dir, ctx, open_flags, &attr); nfs_block_sillyrename(dentry->d_parent);
if (IS_ERR(res)) { inode = nfs4_atomic_open(dir, ctx, open_flags, &attr);
if (IS_ERR(inode)) {
nfs_unblock_sillyrename(dentry->d_parent);
put_nfs_open_context(ctx); put_nfs_open_context(ctx);
error = PTR_ERR(res); switch (PTR_ERR(inode)) {
switch (error) {
/* Make a negative dentry */ /* Make a negative dentry */
case -ENOENT: case -ENOENT:
d_add(dentry, NULL);
res = NULL; res = NULL;
goto out; goto out;
/* This turned out not to be a regular file */ /* This turned out not to be a regular file */
...@@ -1143,13 +1145,20 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry ...@@ -1143,13 +1145,20 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
goto no_open; goto no_open;
/* case -EINVAL: */ /* case -EINVAL: */
default: default:
res = ERR_CAST(inode);
goto out; goto out;
} }
} }
if (res != NULL) res = d_add_unique(dentry, inode);
if (res != NULL) {
dput(ctx->path.dentry);
ctx->path.dentry = dget(res);
dentry = res; dentry = res;
}
nfs_intent_set_file(nd, ctx); nfs_intent_set_file(nd, ctx);
nfs_unblock_sillyrename(dentry->d_parent);
out: out:
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
return res; return res;
no_open: no_open:
return nfs_lookup(dir, dentry, nd); return nfs_lookup(dir, dentry, nd);
......
...@@ -242,7 +242,7 @@ extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); ...@@ -242,7 +242,7 @@ extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *);
extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait); extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait);
extern struct dentry *nfs4_atomic_open(struct inode *, struct nfs_open_context *, int, struct iattr *); extern struct inode *nfs4_atomic_open(struct inode *, struct nfs_open_context *, int, struct iattr *);
extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *); extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
......
...@@ -2024,37 +2024,17 @@ static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct ...@@ -2024,37 +2024,17 @@ static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct
return ret; return ret;
} }
struct dentry * struct inode *
nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
{ {
struct dentry *dentry = ctx->path.dentry;
struct dentry *parent;
struct nfs4_state *state; struct nfs4_state *state;
struct dentry *res;
parent = dentry->d_parent;
/* Protect against concurrent sillydeletes */ /* Protect against concurrent sillydeletes */
nfs_block_sillyrename(parent);
state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred); state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred);
if (IS_ERR(state)) { if (IS_ERR(state))
if (PTR_ERR(state) == -ENOENT) { return ERR_CAST(state);
d_add(dentry, NULL);
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
}
nfs_unblock_sillyrename(parent);
return (struct dentry *)state;
}
res = d_add_unique(dentry, igrab(state->inode));
if (res != NULL) {
struct dentry *dummy = ctx->path.dentry;
ctx->path.dentry = dget(res);
dput(dummy);
}
ctx->state = state; ctx->state = state;
nfs_set_verifier(ctx->path.dentry, nfs_save_change_attribute(dir)); return igrab(state->inode);
nfs_unblock_sillyrename(parent);
return res;
} }
int int
......
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