Commit 4e593930 authored by Trond Myklebust's avatar Trond Myklebust

NFS: mknod() cleanup

Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent a1593520
...@@ -955,7 +955,7 @@ static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc) ...@@ -955,7 +955,7 @@ static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc)
/* /*
* Code common to create, mkdir, and mknod. * Code common to create, mkdir, and mknod.
*/ */
static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
struct nfs_fattr *fattr) struct nfs_fattr *fattr)
{ {
struct inode *inode; struct inode *inode;
...@@ -976,14 +976,12 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, ...@@ -976,14 +976,12 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
if (error < 0) if (error < 0)
goto out_err; goto out_err;
} }
error = -ENOMEM;
inode = nfs_fhget(dentry->d_sb, fhandle, fattr); inode = nfs_fhget(dentry->d_sb, fhandle, fattr);
if (inode) { if (inode == NULL)
goto out_err;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
nfs_renew_times(dentry);
nfs_set_verifier(dentry, nfs_save_change_attribute(dentry->d_parent->d_inode));
return 0; return 0;
}
error = -ENOMEM;
out_err: out_err:
d_drop(dentry); d_drop(dentry);
return error; return error;
...@@ -1036,9 +1034,7 @@ static int ...@@ -1036,9 +1034,7 @@ static int
nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
{ {
struct iattr attr; struct iattr attr;
struct nfs_fattr fattr; int status;
struct nfs_fh fhandle;
int error;
dfprintk(VFS, "NFS: mknod(%s/%ld, %s\n", dir->i_sb->s_id, dfprintk(VFS, "NFS: mknod(%s/%ld, %s\n", dir->i_sb->s_id,
dir->i_ino, dentry->d_name.name); dir->i_ino, dentry->d_name.name);
...@@ -1051,15 +1047,18 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) ...@@ -1051,15 +1047,18 @@ nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
lock_kernel(); lock_kernel();
nfs_begin_data_update(dir); nfs_begin_data_update(dir);
error = NFS_PROTO(dir)->mknod(dir, &dentry->d_name, &attr, rdev, status = NFS_PROTO(dir)->mknod(dir, dentry, &attr, rdev);
&fhandle, &fattr);
nfs_end_data_update(dir); nfs_end_data_update(dir);
if (!error) if (status != 0)
error = nfs_instantiate(dentry, &fhandle, &fattr); goto out_err;
else nfs_renew_times(dentry);
d_drop(dentry); nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
unlock_kernel(); unlock_kernel();
return error; return 0;
out_err:
unlock_kernel();
d_drop(dentry);
return status;
} }
/* /*
...@@ -1094,7 +1093,13 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -1094,7 +1093,13 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
nfs_end_data_update(dir); nfs_end_data_update(dir);
if (!error) if (!error)
error = nfs_instantiate(dentry, &fhandle, &fattr); error = nfs_instantiate(dentry, &fhandle, &fattr);
else if (error != 0)
goto out_err;
nfs_renew_times(dentry);
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
unlock_kernel();
return 0;
out_err:
d_drop(dentry); d_drop(dentry);
unlock_kernel(); unlock_kernel();
return error; return error;
......
...@@ -639,21 +639,22 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, ...@@ -639,21 +639,22 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
} }
static int static int
nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr, nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
dev_t rdev, struct nfs_fh *fh, struct nfs_fattr *fattr) dev_t rdev)
{ {
struct nfs_fattr dir_attr; struct nfs_fh fh;
struct nfs_fattr fattr, dir_attr;
struct nfs3_mknodargs arg = { struct nfs3_mknodargs arg = {
.fh = NFS_FH(dir), .fh = NFS_FH(dir),
.name = name->name, .name = dentry->d_name.name,
.len = name->len, .len = dentry->d_name.len,
.sattr = sattr, .sattr = sattr,
.rdev = rdev .rdev = rdev
}; };
struct nfs3_diropres res = { struct nfs3_diropres res = {
.dir_attr = &dir_attr, .dir_attr = &dir_attr,
.fh = fh, .fh = &fh,
.fattr = fattr .fattr = &fattr
}; };
int status; int status;
...@@ -665,12 +666,14 @@ nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr, ...@@ -665,12 +666,14 @@ nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
default: return -EINVAL; default: return -EINVAL;
} }
dprintk("NFS call mknod %s %u:%u\n", name->name, dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
MAJOR(rdev), MINOR(rdev)); MAJOR(rdev), MINOR(rdev));
dir_attr.valid = 0; dir_attr.valid = 0;
fattr->valid = 0; fattr.valid = 0;
status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0); status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
nfs_refresh_inode(dir, &dir_attr); nfs_refresh_inode(dir, &dir_attr);
if (status == 0)
status = nfs_instantiate(dentry, &fh, &fattr);
dprintk("NFS reply mknod: %d\n", status); dprintk("NFS reply mknod: %d\n", status);
return status; return status;
} }
......
...@@ -1755,22 +1755,23 @@ static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, ...@@ -1755,22 +1755,23 @@ static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
return err; return err;
} }
static int _nfs4_proc_mknod(struct inode *dir, struct qstr *name, static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
struct iattr *sattr, dev_t rdev, struct nfs_fh *fh, struct iattr *sattr, dev_t rdev)
struct nfs_fattr *fattr)
{ {
struct nfs_server *server = NFS_SERVER(dir); struct nfs_server *server = NFS_SERVER(dir);
struct nfs_fh fh;
struct nfs_fattr fattr;
struct nfs4_create_arg arg = { struct nfs4_create_arg arg = {
.dir_fh = NFS_FH(dir), .dir_fh = NFS_FH(dir),
.server = server, .server = server,
.name = name, .name = &dentry->d_name,
.attrs = sattr, .attrs = sattr,
.bitmask = server->attr_bitmask, .bitmask = server->attr_bitmask,
}; };
struct nfs4_create_res res = { struct nfs4_create_res res = {
.server = server, .server = server,
.fh = fh, .fh = &fh,
.fattr = fattr, .fattr = &fattr,
}; };
struct rpc_message msg = { struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE], .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
...@@ -1780,7 +1781,7 @@ static int _nfs4_proc_mknod(struct inode *dir, struct qstr *name, ...@@ -1780,7 +1781,7 @@ static int _nfs4_proc_mknod(struct inode *dir, struct qstr *name,
int status; int status;
int mode = sattr->ia_mode; int mode = sattr->ia_mode;
fattr->valid = 0; fattr.valid = 0;
BUG_ON(!(sattr->ia_valid & ATTR_MODE)); BUG_ON(!(sattr->ia_valid & ATTR_MODE));
BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
...@@ -1800,21 +1801,21 @@ static int _nfs4_proc_mknod(struct inode *dir, struct qstr *name, ...@@ -1800,21 +1801,21 @@ static int _nfs4_proc_mknod(struct inode *dir, struct qstr *name,
arg.ftype = NF4SOCK; arg.ftype = NF4SOCK;
status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
if (!status) if (status == 0) {
update_changeattr(dir, &res.dir_cinfo); update_changeattr(dir, &res.dir_cinfo);
status = nfs_instantiate(dentry, &fh, &fattr);
}
return status; return status;
} }
static int nfs4_proc_mknod(struct inode *dir, struct qstr *name, static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
struct iattr *sattr, dev_t rdev, struct nfs_fh *fh, struct iattr *sattr, dev_t rdev)
struct nfs_fattr *fattr)
{ {
struct nfs4_exception exception = { }; struct nfs4_exception exception = { };
int err; int err;
do { do {
err = nfs4_handle_exception(NFS_SERVER(dir), err = nfs4_handle_exception(NFS_SERVER(dir),
_nfs4_proc_mknod(dir, name, sattr, rdev, _nfs4_proc_mknod(dir, dentry, sattr, rdev),
fh, fattr),
&exception); &exception);
} while (exception.retry); } while (exception.retry);
return err; return err;
......
...@@ -248,22 +248,24 @@ nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, ...@@ -248,22 +248,24 @@ nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
* In NFSv2, mknod is grafted onto the create call. * In NFSv2, mknod is grafted onto the create call.
*/ */
static int static int
nfs_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr, nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
dev_t rdev, struct nfs_fh *fhandle, struct nfs_fattr *fattr) dev_t rdev)
{ {
struct nfs_fh fhandle;
struct nfs_fattr fattr;
struct nfs_createargs arg = { struct nfs_createargs arg = {
.fh = NFS_FH(dir), .fh = NFS_FH(dir),
.name = name->name, .name = dentry->d_name.name,
.len = name->len, .len = dentry->d_name.len,
.sattr = sattr .sattr = sattr
}; };
struct nfs_diropok res = { struct nfs_diropok res = {
.fh = fhandle, .fh = &fhandle,
.fattr = fattr .fattr = &fattr
}; };
int status, mode; int status, mode;
dprintk("NFS call mknod %s\n", name->name); dprintk("NFS call mknod %s\n", dentry->d_name.name);
mode = sattr->ia_mode; mode = sattr->ia_mode;
if (S_ISFIFO(mode)) { if (S_ISFIFO(mode)) {
...@@ -274,14 +276,16 @@ nfs_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr, ...@@ -274,14 +276,16 @@ nfs_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */ sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
} }
fattr->valid = 0; fattr.valid = 0;
status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0); status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
if (status == -EINVAL && S_ISFIFO(mode)) { if (status == -EINVAL && S_ISFIFO(mode)) {
sattr->ia_mode = mode; sattr->ia_mode = mode;
fattr->valid = 0; fattr.valid = 0;
status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0); status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
} }
if (status == 0)
status = nfs_instantiate(dentry, &fhandle, &fattr);
dprintk("NFS reply mknod: %d\n", status); dprintk("NFS reply mknod: %d\n", status);
return status; return status;
} }
......
...@@ -345,6 +345,8 @@ extern struct inode_operations nfs_dir_inode_operations; ...@@ -345,6 +345,8 @@ extern struct inode_operations nfs_dir_inode_operations;
extern struct file_operations nfs_dir_operations; extern struct file_operations nfs_dir_operations;
extern struct dentry_operations nfs_dentry_operations; extern struct dentry_operations nfs_dentry_operations;
extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr);
/* /*
* linux/fs/nfs/symlink.c * linux/fs/nfs/symlink.c
*/ */
......
...@@ -699,8 +699,8 @@ struct nfs_rpc_ops { ...@@ -699,8 +699,8 @@ struct nfs_rpc_ops {
int (*rmdir) (struct inode *, struct qstr *); int (*rmdir) (struct inode *, struct qstr *);
int (*readdir) (struct dentry *, struct rpc_cred *, int (*readdir) (struct dentry *, struct rpc_cred *,
u64, struct page *, unsigned int, int); u64, struct page *, unsigned int, int);
int (*mknod) (struct inode *, struct qstr *, struct iattr *, int (*mknod) (struct inode *, struct dentry *, struct iattr *,
dev_t, struct nfs_fh *, struct nfs_fattr *); dev_t);
int (*statfs) (struct nfs_server *, struct nfs_fh *, int (*statfs) (struct nfs_server *, struct nfs_fh *,
struct nfs_fsstat *); struct nfs_fsstat *);
int (*fsinfo) (struct nfs_server *, struct nfs_fh *, int (*fsinfo) (struct nfs_server *, struct nfs_fh *,
......
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