xref: /openbmc/linux/fs/nfs/nfs3proc.c (revision beffb8fe)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  linux/fs/nfs/nfs3proc.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Client-side NFSv3 procedures stubs.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *  Copyright (C) 1997, Olaf Kirch
71da177e4SLinus Torvalds  */
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds #include <linux/mm.h>
101da177e4SLinus Torvalds #include <linux/errno.h>
111da177e4SLinus Torvalds #include <linux/string.h>
121da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h>
135a0e3ad6STejun Heo #include <linux/slab.h>
141da177e4SLinus Torvalds #include <linux/nfs.h>
151da177e4SLinus Torvalds #include <linux/nfs3.h>
161da177e4SLinus Torvalds #include <linux/nfs_fs.h>
171da177e4SLinus Torvalds #include <linux/nfs_page.h>
181da177e4SLinus Torvalds #include <linux/lockd/bind.h>
19b7fa0554SAndreas Gruenbacher #include <linux/nfs_mount.h>
20d310310cSJeff Layton #include <linux/freezer.h>
210a6be655STejun Heo #include <linux/xattr.h>
221da177e4SLinus Torvalds 
23006ea73eSChuck Lever #include "iostat.h"
24f7b422b1SDavid Howells #include "internal.h"
2500a36a10SAnna Schumaker #include "nfs3_fs.h"
26006ea73eSChuck Lever 
271da177e4SLinus Torvalds #define NFSDBG_FACILITY		NFSDBG_PROC
281da177e4SLinus Torvalds 
29eb96d5c9SAndy Adamson /* A wrapper to handle the EJUKEBOX error messages */
301da177e4SLinus Torvalds static int
311da177e4SLinus Torvalds nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
321da177e4SLinus Torvalds {
331da177e4SLinus Torvalds 	int res;
341da177e4SLinus Torvalds 	do {
351da177e4SLinus Torvalds 		res = rpc_call_sync(clnt, msg, flags);
36eb96d5c9SAndy Adamson 		if (res != -EJUKEBOX)
371da177e4SLinus Torvalds 			break;
38416ad3c9SColin Cross 		freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME);
391da177e4SLinus Torvalds 		res = -ERESTARTSYS;
40150030b7SMatthew Wilcox 	} while (!fatal_signal_pending(current));
411da177e4SLinus Torvalds 	return res;
421da177e4SLinus Torvalds }
431da177e4SLinus Torvalds 
44dead28daSChuck Lever #define rpc_call_sync(clnt, msg, flags)	nfs3_rpc_wrapper(clnt, msg, flags)
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds static int
47006ea73eSChuck Lever nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
481da177e4SLinus Torvalds {
49eb96d5c9SAndy Adamson 	if (task->tk_status != -EJUKEBOX)
501da177e4SLinus Torvalds 		return 0;
51b68d69b8SJeff Layton 	if (task->tk_status == -EJUKEBOX)
52006ea73eSChuck Lever 		nfs_inc_stats(inode, NFSIOS_DELAY);
531da177e4SLinus Torvalds 	task->tk_status = 0;
541da177e4SLinus Torvalds 	rpc_restart_call(task);
551da177e4SLinus Torvalds 	rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
561da177e4SLinus Torvalds 	return 1;
571da177e4SLinus Torvalds }
581da177e4SLinus Torvalds 
5903c21733SJ. Bruce Fields static int
6003c21733SJ. Bruce Fields do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
6103c21733SJ. Bruce Fields 		 struct nfs_fsinfo *info)
6203c21733SJ. Bruce Fields {
63dead28daSChuck Lever 	struct rpc_message msg = {
64dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_FSINFO],
65dead28daSChuck Lever 		.rpc_argp	= fhandle,
66dead28daSChuck Lever 		.rpc_resp	= info,
67dead28daSChuck Lever 	};
6803c21733SJ. Bruce Fields 	int	status;
6903c21733SJ. Bruce Fields 
703110ff80SHarvey Harrison 	dprintk("%s: call  fsinfo\n", __func__);
7103c21733SJ. Bruce Fields 	nfs_fattr_init(info->fattr);
72dead28daSChuck Lever 	status = rpc_call_sync(client, &msg, 0);
733110ff80SHarvey Harrison 	dprintk("%s: reply fsinfo: %d\n", __func__, status);
7408660043STrond Myklebust 	if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) {
75dead28daSChuck Lever 		msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
76dead28daSChuck Lever 		msg.rpc_resp = info->fattr;
77dead28daSChuck Lever 		status = rpc_call_sync(client, &msg, 0);
783110ff80SHarvey Harrison 		dprintk("%s: reply getattr: %d\n", __func__, status);
7903c21733SJ. Bruce Fields 	}
8003c21733SJ. Bruce Fields 	return status;
8103c21733SJ. Bruce Fields }
8203c21733SJ. Bruce Fields 
831da177e4SLinus Torvalds /*
8454ceac45SDavid Howells  * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
851da177e4SLinus Torvalds  */
861da177e4SLinus Torvalds static int
871da177e4SLinus Torvalds nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
881da177e4SLinus Torvalds 		   struct nfs_fsinfo *info)
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds 	int	status;
911da177e4SLinus Torvalds 
9203c21733SJ. Bruce Fields 	status = do_proc_get_root(server->client, fhandle, info);
935006a76cSDavid Howells 	if (status && server->nfs_client->cl_rpcclient != server->client)
945006a76cSDavid Howells 		status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
951da177e4SLinus Torvalds 	return status;
961da177e4SLinus Torvalds }
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds /*
991da177e4SLinus Torvalds  * One function for each procedure in the NFS protocol.
1001da177e4SLinus Torvalds  */
1011da177e4SLinus Torvalds static int
1021da177e4SLinus Torvalds nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
1031775fd3eSDavid Quigley 		struct nfs_fattr *fattr, struct nfs4_label *label)
1041da177e4SLinus Torvalds {
105dead28daSChuck Lever 	struct rpc_message msg = {
106dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_GETATTR],
107dead28daSChuck Lever 		.rpc_argp	= fhandle,
108dead28daSChuck Lever 		.rpc_resp	= fattr,
109dead28daSChuck Lever 	};
1101da177e4SLinus Torvalds 	int	status;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	dprintk("NFS call  getattr\n");
1130e574af1STrond Myklebust 	nfs_fattr_init(fattr);
114dead28daSChuck Lever 	status = rpc_call_sync(server->client, &msg, 0);
1151da177e4SLinus Torvalds 	dprintk("NFS reply getattr: %d\n", status);
1161da177e4SLinus Torvalds 	return status;
1171da177e4SLinus Torvalds }
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds static int
1201da177e4SLinus Torvalds nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1211da177e4SLinus Torvalds 			struct iattr *sattr)
1221da177e4SLinus Torvalds {
1232b0143b5SDavid Howells 	struct inode *inode = d_inode(dentry);
1241da177e4SLinus Torvalds 	struct nfs3_sattrargs	arg = {
1251da177e4SLinus Torvalds 		.fh		= NFS_FH(inode),
1261da177e4SLinus Torvalds 		.sattr		= sattr,
1271da177e4SLinus Torvalds 	};
128dead28daSChuck Lever 	struct rpc_message msg = {
129dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_SETATTR],
130dead28daSChuck Lever 		.rpc_argp	= &arg,
131dead28daSChuck Lever 		.rpc_resp	= fattr,
132dead28daSChuck Lever 	};
1331da177e4SLinus Torvalds 	int	status;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds 	dprintk("NFS call  setattr\n");
136659bfcd6STrond Myklebust 	if (sattr->ia_valid & ATTR_FILE)
137659bfcd6STrond Myklebust 		msg.rpc_cred = nfs_file_cred(sattr->ia_file);
1380e574af1STrond Myklebust 	nfs_fattr_init(fattr);
139dead28daSChuck Lever 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
14065e4308dSTrond Myklebust 	if (status == 0)
141f044636dSTrond Myklebust 		nfs_setattr_update_inode(inode, sattr, fattr);
1421da177e4SLinus Torvalds 	dprintk("NFS reply setattr: %d\n", status);
1431da177e4SLinus Torvalds 	return status;
1441da177e4SLinus Torvalds }
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds static int
147beffb8feSAl Viro nfs3_proc_lookup(struct inode *dir, const struct qstr *name,
1481775fd3eSDavid Quigley 		 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
1491775fd3eSDavid Quigley 		 struct nfs4_label *label)
1501da177e4SLinus Torvalds {
1511da177e4SLinus Torvalds 	struct nfs3_diropargs	arg = {
1521da177e4SLinus Torvalds 		.fh		= NFS_FH(dir),
1531da177e4SLinus Torvalds 		.name		= name->name,
1541da177e4SLinus Torvalds 		.len		= name->len
1551da177e4SLinus Torvalds 	};
1561da177e4SLinus Torvalds 	struct nfs3_diropres	res = {
1571da177e4SLinus Torvalds 		.fh		= fhandle,
1581da177e4SLinus Torvalds 		.fattr		= fattr
1591da177e4SLinus Torvalds 	};
160dead28daSChuck Lever 	struct rpc_message msg = {
161dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_LOOKUP],
162dead28daSChuck Lever 		.rpc_argp	= &arg,
163dead28daSChuck Lever 		.rpc_resp	= &res,
164dead28daSChuck Lever 	};
1651da177e4SLinus Torvalds 	int			status;
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	dprintk("NFS call  lookup %s\n", name->name);
168e1fb4d05STrond Myklebust 	res.dir_attr = nfs_alloc_fattr();
169e1fb4d05STrond Myklebust 	if (res.dir_attr == NULL)
170e1fb4d05STrond Myklebust 		return -ENOMEM;
171e1fb4d05STrond Myklebust 
1720e574af1STrond Myklebust 	nfs_fattr_init(fattr);
173dead28daSChuck Lever 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
174e1fb4d05STrond Myklebust 	nfs_refresh_inode(dir, res.dir_attr);
175dead28daSChuck Lever 	if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
176dead28daSChuck Lever 		msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
177dead28daSChuck Lever 		msg.rpc_argp = fhandle;
178dead28daSChuck Lever 		msg.rpc_resp = fattr;
179dead28daSChuck Lever 		status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
180dead28daSChuck Lever 	}
181e1fb4d05STrond Myklebust 	nfs_free_fattr(res.dir_attr);
1821da177e4SLinus Torvalds 	dprintk("NFS reply lookup: %d\n", status);
1831da177e4SLinus Torvalds 	return status;
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1871da177e4SLinus Torvalds {
1881da177e4SLinus Torvalds 	struct nfs3_accessargs	arg = {
1891da177e4SLinus Torvalds 		.fh		= NFS_FH(inode),
1901da177e4SLinus Torvalds 	};
191c407d41aSTrond Myklebust 	struct nfs3_accessres	res;
1921da177e4SLinus Torvalds 	struct rpc_message msg = {
1931da177e4SLinus Torvalds 		.rpc_proc	= &nfs3_procedures[NFS3PROC_ACCESS],
1941da177e4SLinus Torvalds 		.rpc_argp	= &arg,
1951da177e4SLinus Torvalds 		.rpc_resp	= &res,
196dead28daSChuck Lever 		.rpc_cred	= entry->cred,
1971da177e4SLinus Torvalds 	};
1981da177e4SLinus Torvalds 	int mode = entry->mask;
199c407d41aSTrond Myklebust 	int status = -ENOMEM;
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds 	dprintk("NFS call  access\n");
2021da177e4SLinus Torvalds 
2031da177e4SLinus Torvalds 	if (mode & MAY_READ)
2041da177e4SLinus Torvalds 		arg.access |= NFS3_ACCESS_READ;
2051da177e4SLinus Torvalds 	if (S_ISDIR(inode->i_mode)) {
2061da177e4SLinus Torvalds 		if (mode & MAY_WRITE)
2071da177e4SLinus Torvalds 			arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
2081da177e4SLinus Torvalds 		if (mode & MAY_EXEC)
2091da177e4SLinus Torvalds 			arg.access |= NFS3_ACCESS_LOOKUP;
2101da177e4SLinus Torvalds 	} else {
2111da177e4SLinus Torvalds 		if (mode & MAY_WRITE)
2121da177e4SLinus Torvalds 			arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
2131da177e4SLinus Torvalds 		if (mode & MAY_EXEC)
2141da177e4SLinus Torvalds 			arg.access |= NFS3_ACCESS_EXECUTE;
2151da177e4SLinus Torvalds 	}
216c407d41aSTrond Myklebust 
217c407d41aSTrond Myklebust 	res.fattr = nfs_alloc_fattr();
218c407d41aSTrond Myklebust 	if (res.fattr == NULL)
219c407d41aSTrond Myklebust 		goto out;
220c407d41aSTrond Myklebust 
2211da177e4SLinus Torvalds 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
222c407d41aSTrond Myklebust 	nfs_refresh_inode(inode, res.fattr);
2231da177e4SLinus Torvalds 	if (status == 0) {
2241da177e4SLinus Torvalds 		entry->mask = 0;
2251da177e4SLinus Torvalds 		if (res.access & NFS3_ACCESS_READ)
2261da177e4SLinus Torvalds 			entry->mask |= MAY_READ;
2271da177e4SLinus Torvalds 		if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
2281da177e4SLinus Torvalds 			entry->mask |= MAY_WRITE;
2291da177e4SLinus Torvalds 		if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
2301da177e4SLinus Torvalds 			entry->mask |= MAY_EXEC;
2311da177e4SLinus Torvalds 	}
232c407d41aSTrond Myklebust 	nfs_free_fattr(res.fattr);
233c407d41aSTrond Myklebust out:
2341da177e4SLinus Torvalds 	dprintk("NFS reply access: %d\n", status);
2351da177e4SLinus Torvalds 	return status;
2361da177e4SLinus Torvalds }
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds static int nfs3_proc_readlink(struct inode *inode, struct page *page,
2391da177e4SLinus Torvalds 		unsigned int pgbase, unsigned int pglen)
2401da177e4SLinus Torvalds {
2413b14d654STrond Myklebust 	struct nfs_fattr	*fattr;
2421da177e4SLinus Torvalds 	struct nfs3_readlinkargs args = {
2431da177e4SLinus Torvalds 		.fh		= NFS_FH(inode),
2441da177e4SLinus Torvalds 		.pgbase		= pgbase,
2451da177e4SLinus Torvalds 		.pglen		= pglen,
2461da177e4SLinus Torvalds 		.pages		= &page
2471da177e4SLinus Torvalds 	};
248dead28daSChuck Lever 	struct rpc_message msg = {
249dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_READLINK],
250dead28daSChuck Lever 		.rpc_argp	= &args,
251dead28daSChuck Lever 	};
2523b14d654STrond Myklebust 	int status = -ENOMEM;
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds 	dprintk("NFS call  readlink\n");
2553b14d654STrond Myklebust 	fattr = nfs_alloc_fattr();
2563b14d654STrond Myklebust 	if (fattr == NULL)
2573b14d654STrond Myklebust 		goto out;
2583b14d654STrond Myklebust 	msg.rpc_resp = fattr;
2593b14d654STrond Myklebust 
260dead28daSChuck Lever 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2613b14d654STrond Myklebust 	nfs_refresh_inode(inode, fattr);
2623b14d654STrond Myklebust 	nfs_free_fattr(fattr);
2633b14d654STrond Myklebust out:
2641da177e4SLinus Torvalds 	dprintk("NFS reply readlink: %d\n", status);
2651da177e4SLinus Torvalds 	return status;
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds 
2680b4aae7aSTrond Myklebust struct nfs3_createdata {
2690b4aae7aSTrond Myklebust 	struct rpc_message msg;
2700b4aae7aSTrond Myklebust 	union {
2710b4aae7aSTrond Myklebust 		struct nfs3_createargs create;
2720b4aae7aSTrond Myklebust 		struct nfs3_mkdirargs mkdir;
2730b4aae7aSTrond Myklebust 		struct nfs3_symlinkargs symlink;
2740b4aae7aSTrond Myklebust 		struct nfs3_mknodargs mknod;
2750b4aae7aSTrond Myklebust 	} arg;
2760b4aae7aSTrond Myklebust 	struct nfs3_diropres res;
2770b4aae7aSTrond Myklebust 	struct nfs_fh fh;
2780b4aae7aSTrond Myklebust 	struct nfs_fattr fattr;
2790b4aae7aSTrond Myklebust 	struct nfs_fattr dir_attr;
2800b4aae7aSTrond Myklebust };
2810b4aae7aSTrond Myklebust 
2820b4aae7aSTrond Myklebust static struct nfs3_createdata *nfs3_alloc_createdata(void)
2830b4aae7aSTrond Myklebust {
2840b4aae7aSTrond Myklebust 	struct nfs3_createdata *data;
2850b4aae7aSTrond Myklebust 
2860b4aae7aSTrond Myklebust 	data = kzalloc(sizeof(*data), GFP_KERNEL);
2870b4aae7aSTrond Myklebust 	if (data != NULL) {
2880b4aae7aSTrond Myklebust 		data->msg.rpc_argp = &data->arg;
2890b4aae7aSTrond Myklebust 		data->msg.rpc_resp = &data->res;
2900b4aae7aSTrond Myklebust 		data->res.fh = &data->fh;
2910b4aae7aSTrond Myklebust 		data->res.fattr = &data->fattr;
2920b4aae7aSTrond Myklebust 		data->res.dir_attr = &data->dir_attr;
2930b4aae7aSTrond Myklebust 		nfs_fattr_init(data->res.fattr);
2940b4aae7aSTrond Myklebust 		nfs_fattr_init(data->res.dir_attr);
2950b4aae7aSTrond Myklebust 	}
2960b4aae7aSTrond Myklebust 	return data;
2970b4aae7aSTrond Myklebust }
2980b4aae7aSTrond Myklebust 
2990b4aae7aSTrond Myklebust static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
3000b4aae7aSTrond Myklebust {
3010b4aae7aSTrond Myklebust 	int status;
3020b4aae7aSTrond Myklebust 
3030b4aae7aSTrond Myklebust 	status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
3040b4aae7aSTrond Myklebust 	nfs_post_op_update_inode(dir, data->res.dir_attr);
3050b4aae7aSTrond Myklebust 	if (status == 0)
3061775fd3eSDavid Quigley 		status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
3070b4aae7aSTrond Myklebust 	return status;
3080b4aae7aSTrond Myklebust }
3090b4aae7aSTrond Myklebust 
3100b4aae7aSTrond Myklebust static void nfs3_free_createdata(struct nfs3_createdata *data)
3110b4aae7aSTrond Myklebust {
3120b4aae7aSTrond Myklebust 	kfree(data);
3130b4aae7aSTrond Myklebust }
3140b4aae7aSTrond Myklebust 
3151da177e4SLinus Torvalds /*
3161da177e4SLinus Torvalds  * Create a regular file.
3171da177e4SLinus Torvalds  */
3181da177e4SLinus Torvalds static int
3191da177e4SLinus Torvalds nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
3208867fe58SMiklos Szeredi 		 int flags)
3211da177e4SLinus Torvalds {
322013cdf10SChristoph Hellwig 	struct posix_acl *default_acl, *acl;
3230b4aae7aSTrond Myklebust 	struct nfs3_createdata *data;
3240b4aae7aSTrond Myklebust 	int status = -ENOMEM;
3251da177e4SLinus Torvalds 
3266de1472fSAl Viro 	dprintk("NFS call  create %pd\n", dentry);
3270b4aae7aSTrond Myklebust 
3280b4aae7aSTrond Myklebust 	data = nfs3_alloc_createdata();
3290b4aae7aSTrond Myklebust 	if (data == NULL)
3300b4aae7aSTrond Myklebust 		goto out;
3310b4aae7aSTrond Myklebust 
3320b4aae7aSTrond Myklebust 	data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
3330b4aae7aSTrond Myklebust 	data->arg.create.fh = NFS_FH(dir);
3340b4aae7aSTrond Myklebust 	data->arg.create.name = dentry->d_name.name;
3350b4aae7aSTrond Myklebust 	data->arg.create.len = dentry->d_name.len;
3360b4aae7aSTrond Myklebust 	data->arg.create.sattr = sattr;
3370b4aae7aSTrond Myklebust 
3380b4aae7aSTrond Myklebust 	data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
3391da177e4SLinus Torvalds 	if (flags & O_EXCL) {
3400b4aae7aSTrond Myklebust 		data->arg.create.createmode  = NFS3_CREATE_EXCLUSIVE;
341a9943d11STrond Myklebust 		data->arg.create.verifier[0] = cpu_to_be32(jiffies);
342a9943d11STrond Myklebust 		data->arg.create.verifier[1] = cpu_to_be32(current->pid);
3431da177e4SLinus Torvalds 	}
3441da177e4SLinus Torvalds 
345013cdf10SChristoph Hellwig 	status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
346013cdf10SChristoph Hellwig 	if (status)
347013cdf10SChristoph Hellwig 		goto out;
348055ffbeaSAndreas Gruenbacher 
3490b4aae7aSTrond Myklebust 	for (;;) {
3500b4aae7aSTrond Myklebust 		status = nfs3_do_create(dir, dentry, data);
3511da177e4SLinus Torvalds 
3520b4aae7aSTrond Myklebust 		if (status != -ENOTSUPP)
3530b4aae7aSTrond Myklebust 			break;
3540b4aae7aSTrond Myklebust 		/* If the server doesn't support the exclusive creation
3550b4aae7aSTrond Myklebust 		 * semantics, try again with simple 'guarded' mode. */
3560b4aae7aSTrond Myklebust 		switch (data->arg.create.createmode) {
3571da177e4SLinus Torvalds 			case NFS3_CREATE_EXCLUSIVE:
3580b4aae7aSTrond Myklebust 				data->arg.create.createmode = NFS3_CREATE_GUARDED;
3591da177e4SLinus Torvalds 				break;
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 			case NFS3_CREATE_GUARDED:
3620b4aae7aSTrond Myklebust 				data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
3631da177e4SLinus Torvalds 				break;
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds 			case NFS3_CREATE_UNCHECKED:
3661da177e4SLinus Torvalds 				goto out;
3671da177e4SLinus Torvalds 		}
3680b4aae7aSTrond Myklebust 		nfs_fattr_init(data->res.dir_attr);
3690b4aae7aSTrond Myklebust 		nfs_fattr_init(data->res.fattr);
3701da177e4SLinus Torvalds 	}
3711da177e4SLinus Torvalds 
3721da177e4SLinus Torvalds 	if (status != 0)
373013cdf10SChristoph Hellwig 		goto out_release_acls;
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds 	/* When we created the file with exclusive semantics, make
3761da177e4SLinus Torvalds 	 * sure we set the attributes afterwards. */
3770b4aae7aSTrond Myklebust 	if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
3781da177e4SLinus Torvalds 		dprintk("NFS call  setattr (post-create)\n");
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 		if (!(sattr->ia_valid & ATTR_ATIME_SET))
3811da177e4SLinus Torvalds 			sattr->ia_valid |= ATTR_ATIME;
3821da177e4SLinus Torvalds 		if (!(sattr->ia_valid & ATTR_MTIME_SET))
3831da177e4SLinus Torvalds 			sattr->ia_valid |= ATTR_MTIME;
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds 		/* Note: we could use a guarded setattr here, but I'm
3861da177e4SLinus Torvalds 		 * not sure this buys us anything (and I'd have
3871da177e4SLinus Torvalds 		 * to revamp the NFSv3 XDR code) */
3880b4aae7aSTrond Myklebust 		status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
3892b0143b5SDavid Howells 		nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
3901da177e4SLinus Torvalds 		dprintk("NFS reply setattr (post-create): %d\n", status);
391055ffbeaSAndreas Gruenbacher 		if (status != 0)
392013cdf10SChristoph Hellwig 			goto out_release_acls;
3930b4aae7aSTrond Myklebust 	}
394013cdf10SChristoph Hellwig 
3952b0143b5SDavid Howells 	status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
396013cdf10SChristoph Hellwig 
397013cdf10SChristoph Hellwig out_release_acls:
398013cdf10SChristoph Hellwig 	posix_acl_release(acl);
399013cdf10SChristoph Hellwig 	posix_acl_release(default_acl);
4001da177e4SLinus Torvalds out:
4010b4aae7aSTrond Myklebust 	nfs3_free_createdata(data);
4021da177e4SLinus Torvalds 	dprintk("NFS reply create: %d\n", status);
4031da177e4SLinus Torvalds 	return status;
4041da177e4SLinus Torvalds }
4051da177e4SLinus Torvalds 
4061da177e4SLinus Torvalds static int
407beffb8feSAl Viro nfs3_proc_remove(struct inode *dir, const struct qstr *name)
4081da177e4SLinus Torvalds {
4094fdc17b2STrond Myklebust 	struct nfs_removeargs arg = {
4101da177e4SLinus Torvalds 		.fh = NFS_FH(dir),
41126fe5750SLinus Torvalds 		.name = *name,
4121da177e4SLinus Torvalds 	};
4134fdc17b2STrond Myklebust 	struct nfs_removeres res;
4141da177e4SLinus Torvalds 	struct rpc_message msg = {
4151da177e4SLinus Torvalds 		.rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
4161da177e4SLinus Torvalds 		.rpc_argp = &arg,
4174fdc17b2STrond Myklebust 		.rpc_resp = &res,
4181da177e4SLinus Torvalds 	};
419d346890bSTrond Myklebust 	int status = -ENOMEM;
4201da177e4SLinus Torvalds 
4211da177e4SLinus Torvalds 	dprintk("NFS call  remove %s\n", name->name);
422d346890bSTrond Myklebust 	res.dir_attr = nfs_alloc_fattr();
423d346890bSTrond Myklebust 	if (res.dir_attr == NULL)
424d346890bSTrond Myklebust 		goto out;
425d346890bSTrond Myklebust 
4261da177e4SLinus Torvalds 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
427d346890bSTrond Myklebust 	nfs_post_op_update_inode(dir, res.dir_attr);
428d346890bSTrond Myklebust 	nfs_free_fattr(res.dir_attr);
429d346890bSTrond Myklebust out:
4301da177e4SLinus Torvalds 	dprintk("NFS reply remove: %d\n", status);
4311da177e4SLinus Torvalds 	return status;
4321da177e4SLinus Torvalds }
4331da177e4SLinus Torvalds 
434e4eff1a6STrond Myklebust static void
435e4eff1a6STrond Myklebust nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
4361da177e4SLinus Torvalds {
4371da177e4SLinus Torvalds 	msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
4381da177e4SLinus Torvalds }
4391da177e4SLinus Torvalds 
44034e137ccSBryan Schumaker static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
44134e137ccSBryan Schumaker {
44234e137ccSBryan Schumaker 	rpc_call_start(task);
44334e137ccSBryan Schumaker }
44434e137ccSBryan Schumaker 
4451da177e4SLinus Torvalds static int
446e4eff1a6STrond Myklebust nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
4471da177e4SLinus Torvalds {
448e4eff1a6STrond Myklebust 	struct nfs_removeres *res;
449e4eff1a6STrond Myklebust 	if (nfs3_async_handle_jukebox(task, dir))
4501da177e4SLinus Torvalds 		return 0;
451e4eff1a6STrond Myklebust 	res = task->tk_msg.rpc_resp;
452d346890bSTrond Myklebust 	nfs_post_op_update_inode(dir, res->dir_attr);
453e4eff1a6STrond Myklebust 	return 1;
4541da177e4SLinus Torvalds }
4551da177e4SLinus Torvalds 
456d3d4152aSJeff Layton static void
457d3d4152aSJeff Layton nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
458d3d4152aSJeff Layton {
459d3d4152aSJeff Layton 	msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
460d3d4152aSJeff Layton }
461d3d4152aSJeff Layton 
462c6bfa1a1SBryan Schumaker static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
463c6bfa1a1SBryan Schumaker {
464c6bfa1a1SBryan Schumaker 	rpc_call_start(task);
465c6bfa1a1SBryan Schumaker }
466c6bfa1a1SBryan Schumaker 
467d3d4152aSJeff Layton static int
468d3d4152aSJeff Layton nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
469d3d4152aSJeff Layton 		      struct inode *new_dir)
470d3d4152aSJeff Layton {
471d3d4152aSJeff Layton 	struct nfs_renameres *res;
472d3d4152aSJeff Layton 
473d3d4152aSJeff Layton 	if (nfs3_async_handle_jukebox(task, old_dir))
474d3d4152aSJeff Layton 		return 0;
475d3d4152aSJeff Layton 	res = task->tk_msg.rpc_resp;
476d3d4152aSJeff Layton 
477d3d4152aSJeff Layton 	nfs_post_op_update_inode(old_dir, res->old_fattr);
478d3d4152aSJeff Layton 	nfs_post_op_update_inode(new_dir, res->new_fattr);
479d3d4152aSJeff Layton 	return 1;
480d3d4152aSJeff Layton }
481d3d4152aSJeff Layton 
4821da177e4SLinus Torvalds static int
483beffb8feSAl Viro nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
4841da177e4SLinus Torvalds {
4851da177e4SLinus Torvalds 	struct nfs3_linkargs	arg = {
4861da177e4SLinus Torvalds 		.fromfh		= NFS_FH(inode),
4871da177e4SLinus Torvalds 		.tofh		= NFS_FH(dir),
4881da177e4SLinus Torvalds 		.toname		= name->name,
4891da177e4SLinus Torvalds 		.tolen		= name->len
4901da177e4SLinus Torvalds 	};
491136f2627STrond Myklebust 	struct nfs3_linkres	res;
492dead28daSChuck Lever 	struct rpc_message msg = {
493dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_LINK],
494dead28daSChuck Lever 		.rpc_argp	= &arg,
495dead28daSChuck Lever 		.rpc_resp	= &res,
496dead28daSChuck Lever 	};
497136f2627STrond Myklebust 	int status = -ENOMEM;
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds 	dprintk("NFS call  link %s\n", name->name);
500136f2627STrond Myklebust 	res.fattr = nfs_alloc_fattr();
501136f2627STrond Myklebust 	res.dir_attr = nfs_alloc_fattr();
502136f2627STrond Myklebust 	if (res.fattr == NULL || res.dir_attr == NULL)
503136f2627STrond Myklebust 		goto out;
504136f2627STrond Myklebust 
505dead28daSChuck Lever 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
506136f2627STrond Myklebust 	nfs_post_op_update_inode(dir, res.dir_attr);
507136f2627STrond Myklebust 	nfs_post_op_update_inode(inode, res.fattr);
508136f2627STrond Myklebust out:
509136f2627STrond Myklebust 	nfs_free_fattr(res.dir_attr);
510136f2627STrond Myklebust 	nfs_free_fattr(res.fattr);
5111da177e4SLinus Torvalds 	dprintk("NFS reply link: %d\n", status);
5121da177e4SLinus Torvalds 	return status;
5131da177e4SLinus Torvalds }
5141da177e4SLinus Torvalds 
5151da177e4SLinus Torvalds static int
51694a6d753SChuck Lever nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
51794a6d753SChuck Lever 		  unsigned int len, struct iattr *sattr)
5181da177e4SLinus Torvalds {
5190b4aae7aSTrond Myklebust 	struct nfs3_createdata *data;
5200b4aae7aSTrond Myklebust 	int status = -ENOMEM;
5211da177e4SLinus Torvalds 
52294a6d753SChuck Lever 	if (len > NFS3_MAXPATHLEN)
5231da177e4SLinus Torvalds 		return -ENAMETOOLONG;
5244f390c15SChuck Lever 
5256de1472fSAl Viro 	dprintk("NFS call  symlink %pd\n", dentry);
52694a6d753SChuck Lever 
5270b4aae7aSTrond Myklebust 	data = nfs3_alloc_createdata();
5280b4aae7aSTrond Myklebust 	if (data == NULL)
5294f390c15SChuck Lever 		goto out;
5300b4aae7aSTrond Myklebust 	data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
5310b4aae7aSTrond Myklebust 	data->arg.symlink.fromfh = NFS_FH(dir);
5320b4aae7aSTrond Myklebust 	data->arg.symlink.fromname = dentry->d_name.name;
5330b4aae7aSTrond Myklebust 	data->arg.symlink.fromlen = dentry->d_name.len;
5340b4aae7aSTrond Myklebust 	data->arg.symlink.pages = &page;
5350b4aae7aSTrond Myklebust 	data->arg.symlink.pathlen = len;
5360b4aae7aSTrond Myklebust 	data->arg.symlink.sattr = sattr;
5370b4aae7aSTrond Myklebust 
5380b4aae7aSTrond Myklebust 	status = nfs3_do_create(dir, dentry, data);
5390b4aae7aSTrond Myklebust 
5400b4aae7aSTrond Myklebust 	nfs3_free_createdata(data);
5414f390c15SChuck Lever out:
5421da177e4SLinus Torvalds 	dprintk("NFS reply symlink: %d\n", status);
5431da177e4SLinus Torvalds 	return status;
5441da177e4SLinus Torvalds }
5451da177e4SLinus Torvalds 
5461da177e4SLinus Torvalds static int
5471da177e4SLinus Torvalds nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
5481da177e4SLinus Torvalds {
549013cdf10SChristoph Hellwig 	struct posix_acl *default_acl, *acl;
5500b4aae7aSTrond Myklebust 	struct nfs3_createdata *data;
5510b4aae7aSTrond Myklebust 	int status = -ENOMEM;
5521da177e4SLinus Torvalds 
5536de1472fSAl Viro 	dprintk("NFS call  mkdir %pd\n", dentry);
554055ffbeaSAndreas Gruenbacher 
5550b4aae7aSTrond Myklebust 	data = nfs3_alloc_createdata();
5560b4aae7aSTrond Myklebust 	if (data == NULL)
5570b4aae7aSTrond Myklebust 		goto out;
5580b4aae7aSTrond Myklebust 
559013cdf10SChristoph Hellwig 	status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
560013cdf10SChristoph Hellwig 	if (status)
561013cdf10SChristoph Hellwig 		goto out;
562013cdf10SChristoph Hellwig 
5630b4aae7aSTrond Myklebust 	data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
5640b4aae7aSTrond Myklebust 	data->arg.mkdir.fh = NFS_FH(dir);
5650b4aae7aSTrond Myklebust 	data->arg.mkdir.name = dentry->d_name.name;
5660b4aae7aSTrond Myklebust 	data->arg.mkdir.len = dentry->d_name.len;
5670b4aae7aSTrond Myklebust 	data->arg.mkdir.sattr = sattr;
5680b4aae7aSTrond Myklebust 
5690b4aae7aSTrond Myklebust 	status = nfs3_do_create(dir, dentry, data);
570055ffbeaSAndreas Gruenbacher 	if (status != 0)
571013cdf10SChristoph Hellwig 		goto out_release_acls;
5720b4aae7aSTrond Myklebust 
5732b0143b5SDavid Howells 	status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
574013cdf10SChristoph Hellwig 
575013cdf10SChristoph Hellwig out_release_acls:
576013cdf10SChristoph Hellwig 	posix_acl_release(acl);
577013cdf10SChristoph Hellwig 	posix_acl_release(default_acl);
578055ffbeaSAndreas Gruenbacher out:
5790b4aae7aSTrond Myklebust 	nfs3_free_createdata(data);
5801da177e4SLinus Torvalds 	dprintk("NFS reply mkdir: %d\n", status);
5811da177e4SLinus Torvalds 	return status;
5821da177e4SLinus Torvalds }
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds static int
585beffb8feSAl Viro nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
5861da177e4SLinus Torvalds {
58739967ddfSTrond Myklebust 	struct nfs_fattr	*dir_attr;
5881da177e4SLinus Torvalds 	struct nfs3_diropargs	arg = {
5891da177e4SLinus Torvalds 		.fh		= NFS_FH(dir),
5901da177e4SLinus Torvalds 		.name		= name->name,
5911da177e4SLinus Torvalds 		.len		= name->len
5921da177e4SLinus Torvalds 	};
593dead28daSChuck Lever 	struct rpc_message msg = {
594dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_RMDIR],
595dead28daSChuck Lever 		.rpc_argp	= &arg,
596dead28daSChuck Lever 	};
59739967ddfSTrond Myklebust 	int status = -ENOMEM;
5981da177e4SLinus Torvalds 
5991da177e4SLinus Torvalds 	dprintk("NFS call  rmdir %s\n", name->name);
60039967ddfSTrond Myklebust 	dir_attr = nfs_alloc_fattr();
60139967ddfSTrond Myklebust 	if (dir_attr == NULL)
60239967ddfSTrond Myklebust 		goto out;
60339967ddfSTrond Myklebust 
60439967ddfSTrond Myklebust 	msg.rpc_resp = dir_attr;
605dead28daSChuck Lever 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
60639967ddfSTrond Myklebust 	nfs_post_op_update_inode(dir, dir_attr);
60739967ddfSTrond Myklebust 	nfs_free_fattr(dir_attr);
60839967ddfSTrond Myklebust out:
6091da177e4SLinus Torvalds 	dprintk("NFS reply rmdir: %d\n", status);
6101da177e4SLinus Torvalds 	return status;
6111da177e4SLinus Torvalds }
6121da177e4SLinus Torvalds 
6131da177e4SLinus Torvalds /*
6141da177e4SLinus Torvalds  * The READDIR implementation is somewhat hackish - we pass the user buffer
6151da177e4SLinus Torvalds  * to the encode function, which installs it in the receive iovec.
6161da177e4SLinus Torvalds  * The decode function itself doesn't perform any decoding, it just makes
6171da177e4SLinus Torvalds  * sure the reply is syntactically correct.
6181da177e4SLinus Torvalds  *
6191da177e4SLinus Torvalds  * Also note that this implementation handles both plain readdir and
6201da177e4SLinus Torvalds  * readdirplus.
6211da177e4SLinus Torvalds  */
6221da177e4SLinus Torvalds static int
6231da177e4SLinus Torvalds nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
62456e4ebf8SBryan Schumaker 		  u64 cookie, struct page **pages, unsigned int count, int plus)
6251da177e4SLinus Torvalds {
6262b0143b5SDavid Howells 	struct inode		*dir = d_inode(dentry);
627c3f52af3STrond Myklebust 	__be32			*verf = NFS_I(dir)->cookieverf;
6281da177e4SLinus Torvalds 	struct nfs3_readdirargs	arg = {
6291da177e4SLinus Torvalds 		.fh		= NFS_FH(dir),
6301da177e4SLinus Torvalds 		.cookie		= cookie,
6311da177e4SLinus Torvalds 		.verf		= {verf[0], verf[1]},
6321da177e4SLinus Torvalds 		.plus		= plus,
6331da177e4SLinus Torvalds 		.count		= count,
63456e4ebf8SBryan Schumaker 		.pages		= pages
6351da177e4SLinus Torvalds 	};
6361da177e4SLinus Torvalds 	struct nfs3_readdirres	res = {
6371da177e4SLinus Torvalds 		.verf		= verf,
6381da177e4SLinus Torvalds 		.plus		= plus
6391da177e4SLinus Torvalds 	};
6401da177e4SLinus Torvalds 	struct rpc_message	msg = {
6411da177e4SLinus Torvalds 		.rpc_proc	= &nfs3_procedures[NFS3PROC_READDIR],
6421da177e4SLinus Torvalds 		.rpc_argp	= &arg,
6431da177e4SLinus Torvalds 		.rpc_resp	= &res,
6441da177e4SLinus Torvalds 		.rpc_cred	= cred
6451da177e4SLinus Torvalds 	};
646aa49b4cfSTrond Myklebust 	int status = -ENOMEM;
6471da177e4SLinus Torvalds 
6481da177e4SLinus Torvalds 	if (plus)
6491da177e4SLinus Torvalds 		msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
6501da177e4SLinus Torvalds 
6511da177e4SLinus Torvalds 	dprintk("NFS call  readdir%s %d\n",
6521da177e4SLinus Torvalds 			plus? "plus" : "", (unsigned int) cookie);
6531da177e4SLinus Torvalds 
654aa49b4cfSTrond Myklebust 	res.dir_attr = nfs_alloc_fattr();
655aa49b4cfSTrond Myklebust 	if (res.dir_attr == NULL)
656aa49b4cfSTrond Myklebust 		goto out;
657aa49b4cfSTrond Myklebust 
6581da177e4SLinus Torvalds 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
659c4812998STrond Myklebust 
660c4812998STrond Myklebust 	nfs_invalidate_atime(dir);
661aa49b4cfSTrond Myklebust 	nfs_refresh_inode(dir, res.dir_attr);
662c4812998STrond Myklebust 
663aa49b4cfSTrond Myklebust 	nfs_free_fattr(res.dir_attr);
664aa49b4cfSTrond Myklebust out:
665d141d974SChuck Lever 	dprintk("NFS reply readdir%s: %d\n",
666d141d974SChuck Lever 			plus? "plus" : "", status);
6671da177e4SLinus Torvalds 	return status;
6681da177e4SLinus Torvalds }
6691da177e4SLinus Torvalds 
6701da177e4SLinus Torvalds static int
6711da177e4SLinus Torvalds nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
6721da177e4SLinus Torvalds 		dev_t rdev)
6731da177e4SLinus Torvalds {
674013cdf10SChristoph Hellwig 	struct posix_acl *default_acl, *acl;
6750b4aae7aSTrond Myklebust 	struct nfs3_createdata *data;
6760b4aae7aSTrond Myklebust 	int status = -ENOMEM;
6771da177e4SLinus Torvalds 
6786de1472fSAl Viro 	dprintk("NFS call  mknod %pd %u:%u\n", dentry,
6791da177e4SLinus Torvalds 			MAJOR(rdev), MINOR(rdev));
680055ffbeaSAndreas Gruenbacher 
6810b4aae7aSTrond Myklebust 	data = nfs3_alloc_createdata();
6820b4aae7aSTrond Myklebust 	if (data == NULL)
683055ffbeaSAndreas Gruenbacher 		goto out;
6840b4aae7aSTrond Myklebust 
685013cdf10SChristoph Hellwig 	status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
686013cdf10SChristoph Hellwig 	if (status)
687013cdf10SChristoph Hellwig 		goto out;
688013cdf10SChristoph Hellwig 
6890b4aae7aSTrond Myklebust 	data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
6900b4aae7aSTrond Myklebust 	data->arg.mknod.fh = NFS_FH(dir);
6910b4aae7aSTrond Myklebust 	data->arg.mknod.name = dentry->d_name.name;
6920b4aae7aSTrond Myklebust 	data->arg.mknod.len = dentry->d_name.len;
6930b4aae7aSTrond Myklebust 	data->arg.mknod.sattr = sattr;
6940b4aae7aSTrond Myklebust 	data->arg.mknod.rdev = rdev;
6950b4aae7aSTrond Myklebust 
6960b4aae7aSTrond Myklebust 	switch (sattr->ia_mode & S_IFMT) {
6970b4aae7aSTrond Myklebust 	case S_IFBLK:
6980b4aae7aSTrond Myklebust 		data->arg.mknod.type = NF3BLK;
6990b4aae7aSTrond Myklebust 		break;
7000b4aae7aSTrond Myklebust 	case S_IFCHR:
7010b4aae7aSTrond Myklebust 		data->arg.mknod.type = NF3CHR;
7020b4aae7aSTrond Myklebust 		break;
7030b4aae7aSTrond Myklebust 	case S_IFIFO:
7040b4aae7aSTrond Myklebust 		data->arg.mknod.type = NF3FIFO;
7050b4aae7aSTrond Myklebust 		break;
7060b4aae7aSTrond Myklebust 	case S_IFSOCK:
7070b4aae7aSTrond Myklebust 		data->arg.mknod.type = NF3SOCK;
7080b4aae7aSTrond Myklebust 		break;
7090b4aae7aSTrond Myklebust 	default:
7100b4aae7aSTrond Myklebust 		status = -EINVAL;
7110b4aae7aSTrond Myklebust 		goto out;
7120b4aae7aSTrond Myklebust 	}
7130b4aae7aSTrond Myklebust 
7140b4aae7aSTrond Myklebust 	status = nfs3_do_create(dir, dentry, data);
715055ffbeaSAndreas Gruenbacher 	if (status != 0)
716013cdf10SChristoph Hellwig 		goto out_release_acls;
717013cdf10SChristoph Hellwig 
7182b0143b5SDavid Howells 	status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
719013cdf10SChristoph Hellwig 
720013cdf10SChristoph Hellwig out_release_acls:
721013cdf10SChristoph Hellwig 	posix_acl_release(acl);
722013cdf10SChristoph Hellwig 	posix_acl_release(default_acl);
723055ffbeaSAndreas Gruenbacher out:
7240b4aae7aSTrond Myklebust 	nfs3_free_createdata(data);
7251da177e4SLinus Torvalds 	dprintk("NFS reply mknod: %d\n", status);
7261da177e4SLinus Torvalds 	return status;
7271da177e4SLinus Torvalds }
7281da177e4SLinus Torvalds 
7291da177e4SLinus Torvalds static int
7301da177e4SLinus Torvalds nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
7311da177e4SLinus Torvalds 		 struct nfs_fsstat *stat)
7321da177e4SLinus Torvalds {
733dead28daSChuck Lever 	struct rpc_message msg = {
734dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_FSSTAT],
735dead28daSChuck Lever 		.rpc_argp	= fhandle,
736dead28daSChuck Lever 		.rpc_resp	= stat,
737dead28daSChuck Lever 	};
7381da177e4SLinus Torvalds 	int	status;
7391da177e4SLinus Torvalds 
7401da177e4SLinus Torvalds 	dprintk("NFS call  fsstat\n");
7410e574af1STrond Myklebust 	nfs_fattr_init(stat->fattr);
742dead28daSChuck Lever 	status = rpc_call_sync(server->client, &msg, 0);
743d141d974SChuck Lever 	dprintk("NFS reply fsstat: %d\n", status);
7441da177e4SLinus Torvalds 	return status;
7451da177e4SLinus Torvalds }
7461da177e4SLinus Torvalds 
7471da177e4SLinus Torvalds static int
74837ca8f5cSEG Keizer do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
7491da177e4SLinus Torvalds 		 struct nfs_fsinfo *info)
7501da177e4SLinus Torvalds {
751dead28daSChuck Lever 	struct rpc_message msg = {
752dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_FSINFO],
753dead28daSChuck Lever 		.rpc_argp	= fhandle,
754dead28daSChuck Lever 		.rpc_resp	= info,
755dead28daSChuck Lever 	};
7561da177e4SLinus Torvalds 	int	status;
7571da177e4SLinus Torvalds 
7581da177e4SLinus Torvalds 	dprintk("NFS call  fsinfo\n");
7590e574af1STrond Myklebust 	nfs_fattr_init(info->fattr);
76037ca8f5cSEG Keizer 	status = rpc_call_sync(client, &msg, 0);
7611da177e4SLinus Torvalds 	dprintk("NFS reply fsinfo: %d\n", status);
7621da177e4SLinus Torvalds 	return status;
7631da177e4SLinus Torvalds }
7641da177e4SLinus Torvalds 
76537ca8f5cSEG Keizer /*
76637ca8f5cSEG Keizer  * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
76737ca8f5cSEG Keizer  * nfs_create_server
76837ca8f5cSEG Keizer  */
76937ca8f5cSEG Keizer static int
77037ca8f5cSEG Keizer nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
77137ca8f5cSEG Keizer 		   struct nfs_fsinfo *info)
77237ca8f5cSEG Keizer {
77337ca8f5cSEG Keizer 	int	status;
77437ca8f5cSEG Keizer 
77537ca8f5cSEG Keizer 	status = do_proc_fsinfo(server->client, fhandle, info);
77637ca8f5cSEG Keizer 	if (status && server->nfs_client->cl_rpcclient != server->client)
77737ca8f5cSEG Keizer 		status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
77837ca8f5cSEG Keizer 	return status;
77937ca8f5cSEG Keizer }
78037ca8f5cSEG Keizer 
7811da177e4SLinus Torvalds static int
7821da177e4SLinus Torvalds nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
7831da177e4SLinus Torvalds 		   struct nfs_pathconf *info)
7841da177e4SLinus Torvalds {
785dead28daSChuck Lever 	struct rpc_message msg = {
786dead28daSChuck Lever 		.rpc_proc	= &nfs3_procedures[NFS3PROC_PATHCONF],
787dead28daSChuck Lever 		.rpc_argp	= fhandle,
788dead28daSChuck Lever 		.rpc_resp	= info,
789dead28daSChuck Lever 	};
7901da177e4SLinus Torvalds 	int	status;
7911da177e4SLinus Torvalds 
7921da177e4SLinus Torvalds 	dprintk("NFS call  pathconf\n");
7930e574af1STrond Myklebust 	nfs_fattr_init(info->fattr);
794dead28daSChuck Lever 	status = rpc_call_sync(server->client, &msg, 0);
7951da177e4SLinus Torvalds 	dprintk("NFS reply pathconf: %d\n", status);
7961da177e4SLinus Torvalds 	return status;
7971da177e4SLinus Torvalds }
7981da177e4SLinus Torvalds 
799d45f60c6SWeston Andros Adamson static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
8001da177e4SLinus Torvalds {
801d45f60c6SWeston Andros Adamson 	struct inode *inode = hdr->inode;
802cd841605SFred Isaman 
80316cecdf6STrond Myklebust 	if (hdr->pgio_done_cb != NULL)
80416cecdf6STrond Myklebust 		return hdr->pgio_done_cb(task, hdr);
80516cecdf6STrond Myklebust 
806cd841605SFred Isaman 	if (nfs3_async_handle_jukebox(task, inode))
807ec06c096STrond Myklebust 		return -EAGAIN;
8088850df99STrond Myklebust 
809cd841605SFred Isaman 	nfs_invalidate_atime(inode);
810d45f60c6SWeston Andros Adamson 	nfs_refresh_inode(inode, &hdr->fattr);
811ec06c096STrond Myklebust 	return 0;
8121da177e4SLinus Torvalds }
8131da177e4SLinus Torvalds 
814d45f60c6SWeston Andros Adamson static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
815d45f60c6SWeston Andros Adamson 				 struct rpc_message *msg)
8161da177e4SLinus Torvalds {
817bdc7f021STrond Myklebust 	msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
8181da177e4SLinus Torvalds }
8191da177e4SLinus Torvalds 
820d45f60c6SWeston Andros Adamson static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
821d45f60c6SWeston Andros Adamson 				      struct nfs_pgio_header *hdr)
822ea7c3303SBryan Schumaker {
823ea7c3303SBryan Schumaker 	rpc_call_start(task);
824ef1820f9SNeilBrown 	return 0;
825ea7c3303SBryan Schumaker }
826ea7c3303SBryan Schumaker 
827d45f60c6SWeston Andros Adamson static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
8281da177e4SLinus Torvalds {
829d45f60c6SWeston Andros Adamson 	struct inode *inode = hdr->inode;
830cd841605SFred Isaman 
83116cecdf6STrond Myklebust 	if (hdr->pgio_done_cb != NULL)
83216cecdf6STrond Myklebust 		return hdr->pgio_done_cb(task, hdr);
83316cecdf6STrond Myklebust 
834cd841605SFred Isaman 	if (nfs3_async_handle_jukebox(task, inode))
835788e7a89STrond Myklebust 		return -EAGAIN;
8361da177e4SLinus Torvalds 	if (task->tk_status >= 0)
837a08a8cd3STrond Myklebust 		nfs_writeback_update_inode(hdr);
838788e7a89STrond Myklebust 	return 0;
8391da177e4SLinus Torvalds }
8401da177e4SLinus Torvalds 
841d45f60c6SWeston Andros Adamson static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
842d45f60c6SWeston Andros Adamson 				  struct rpc_message *msg)
8431da177e4SLinus Torvalds {
844bdc7f021STrond Myklebust 	msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
8451da177e4SLinus Torvalds }
8461da177e4SLinus Torvalds 
8470b7c0153SFred Isaman static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
8480b7c0153SFred Isaman {
8490b7c0153SFred Isaman 	rpc_call_start(task);
8500b7c0153SFred Isaman }
8510b7c0153SFred Isaman 
8520b7c0153SFred Isaman static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
8531da177e4SLinus Torvalds {
85416cecdf6STrond Myklebust 	if (data->commit_done_cb != NULL)
85516cecdf6STrond Myklebust 		return data->commit_done_cb(task, data);
85616cecdf6STrond Myklebust 
857006ea73eSChuck Lever 	if (nfs3_async_handle_jukebox(task, data->inode))
858788e7a89STrond Myklebust 		return -EAGAIN;
8599e08a3c5STrond Myklebust 	nfs_refresh_inode(data->inode, data->res.fattr);
860788e7a89STrond Myklebust 	return 0;
8611da177e4SLinus Torvalds }
8621da177e4SLinus Torvalds 
8630b7c0153SFred Isaman static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
8641da177e4SLinus Torvalds {
865bdc7f021STrond Myklebust 	msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
8661da177e4SLinus Torvalds }
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds static int
8691da177e4SLinus Torvalds nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
8701da177e4SLinus Torvalds {
871496ad9aaSAl Viro 	struct inode *inode = file_inode(filp);
8721093a60eSChuck Lever 
8731093a60eSChuck Lever 	return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
8741da177e4SLinus Torvalds }
8751da177e4SLinus Torvalds 
876011e2a7fSBryan Schumaker static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
877011e2a7fSBryan Schumaker {
878011e2a7fSBryan Schumaker 	return 0;
879011e2a7fSBryan Schumaker }
880011e2a7fSBryan Schumaker 
88157ec14c5SBryan Schumaker static int nfs3_return_delegation(struct inode *inode)
88257ec14c5SBryan Schumaker {
88357ec14c5SBryan Schumaker 	nfs_wb_all(inode);
88457ec14c5SBryan Schumaker 	return 0;
88557ec14c5SBryan Schumaker }
88657ec14c5SBryan Schumaker 
887ab96291eSBryan Schumaker static const struct inode_operations nfs3_dir_inode_operations = {
888ab96291eSBryan Schumaker 	.create		= nfs_create,
889ab96291eSBryan Schumaker 	.lookup		= nfs_lookup,
890ab96291eSBryan Schumaker 	.link		= nfs_link,
891ab96291eSBryan Schumaker 	.unlink		= nfs_unlink,
892ab96291eSBryan Schumaker 	.symlink	= nfs_symlink,
893ab96291eSBryan Schumaker 	.mkdir		= nfs_mkdir,
894ab96291eSBryan Schumaker 	.rmdir		= nfs_rmdir,
895ab96291eSBryan Schumaker 	.mknod		= nfs_mknod,
896ab96291eSBryan Schumaker 	.rename		= nfs_rename,
897ab96291eSBryan Schumaker 	.permission	= nfs_permission,
898ab96291eSBryan Schumaker 	.getattr	= nfs_getattr,
899ab96291eSBryan Schumaker 	.setattr	= nfs_setattr,
9005f13ee9cSChristoph Hellwig #ifdef CONFIG_NFS_V3_ACL
90174adf83fSChristoph Hellwig 	.listxattr	= nfs3_listxattr,
902013cdf10SChristoph Hellwig 	.getxattr	= generic_getxattr,
903013cdf10SChristoph Hellwig 	.setxattr	= generic_setxattr,
904013cdf10SChristoph Hellwig 	.removexattr	= generic_removexattr,
905013cdf10SChristoph Hellwig 	.get_acl	= nfs3_get_acl,
906013cdf10SChristoph Hellwig 	.set_acl	= nfs3_set_acl,
907013cdf10SChristoph Hellwig #endif
908ab96291eSBryan Schumaker };
909ab96291eSBryan Schumaker 
910ab96291eSBryan Schumaker static const struct inode_operations nfs3_file_inode_operations = {
911ab96291eSBryan Schumaker 	.permission	= nfs_permission,
912ab96291eSBryan Schumaker 	.getattr	= nfs_getattr,
913ab96291eSBryan Schumaker 	.setattr	= nfs_setattr,
9145f13ee9cSChristoph Hellwig #ifdef CONFIG_NFS_V3_ACL
91574adf83fSChristoph Hellwig 	.listxattr	= nfs3_listxattr,
916013cdf10SChristoph Hellwig 	.getxattr	= generic_getxattr,
917013cdf10SChristoph Hellwig 	.setxattr	= generic_setxattr,
918013cdf10SChristoph Hellwig 	.removexattr	= generic_removexattr,
919013cdf10SChristoph Hellwig 	.get_acl	= nfs3_get_acl,
920013cdf10SChristoph Hellwig 	.set_acl	= nfs3_set_acl,
921013cdf10SChristoph Hellwig #endif
922ab96291eSBryan Schumaker };
923ab96291eSBryan Schumaker 
924509de811SDavid Howells const struct nfs_rpc_ops nfs_v3_clientops = {
9251da177e4SLinus Torvalds 	.version	= 3,			/* protocol version */
9261da177e4SLinus Torvalds 	.dentry_ops	= &nfs_dentry_operations,
927b7fa0554SAndreas Gruenbacher 	.dir_inode_ops	= &nfs3_dir_inode_operations,
928b7fa0554SAndreas Gruenbacher 	.file_inode_ops	= &nfs3_file_inode_operations,
9291788ea6eSJeff Layton 	.file_ops	= &nfs_file_operations,
9301da177e4SLinus Torvalds 	.getroot	= nfs3_proc_get_root,
931281cad46SBryan Schumaker 	.submount	= nfs_submount,
932ff9099f2SBryan Schumaker 	.try_mount	= nfs_try_mount,
9331da177e4SLinus Torvalds 	.getattr	= nfs3_proc_getattr,
9341da177e4SLinus Torvalds 	.setattr	= nfs3_proc_setattr,
9351da177e4SLinus Torvalds 	.lookup		= nfs3_proc_lookup,
9361da177e4SLinus Torvalds 	.access		= nfs3_proc_access,
9371da177e4SLinus Torvalds 	.readlink	= nfs3_proc_readlink,
9381da177e4SLinus Torvalds 	.create		= nfs3_proc_create,
9391da177e4SLinus Torvalds 	.remove		= nfs3_proc_remove,
9401da177e4SLinus Torvalds 	.unlink_setup	= nfs3_proc_unlink_setup,
94134e137ccSBryan Schumaker 	.unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
9421da177e4SLinus Torvalds 	.unlink_done	= nfs3_proc_unlink_done,
943d3d4152aSJeff Layton 	.rename_setup	= nfs3_proc_rename_setup,
944c6bfa1a1SBryan Schumaker 	.rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
945d3d4152aSJeff Layton 	.rename_done	= nfs3_proc_rename_done,
9461da177e4SLinus Torvalds 	.link		= nfs3_proc_link,
9471da177e4SLinus Torvalds 	.symlink	= nfs3_proc_symlink,
9481da177e4SLinus Torvalds 	.mkdir		= nfs3_proc_mkdir,
9491da177e4SLinus Torvalds 	.rmdir		= nfs3_proc_rmdir,
9501da177e4SLinus Torvalds 	.readdir	= nfs3_proc_readdir,
9511da177e4SLinus Torvalds 	.mknod		= nfs3_proc_mknod,
9521da177e4SLinus Torvalds 	.statfs		= nfs3_proc_statfs,
9531da177e4SLinus Torvalds 	.fsinfo		= nfs3_proc_fsinfo,
9541da177e4SLinus Torvalds 	.pathconf	= nfs3_proc_pathconf,
9551da177e4SLinus Torvalds 	.decode_dirent	= nfs3_decode_dirent,
956a4cdda59SAnna Schumaker 	.pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
9571da177e4SLinus Torvalds 	.read_setup	= nfs3_proc_read_setup,
958ec06c096STrond Myklebust 	.read_done	= nfs3_read_done,
9591da177e4SLinus Torvalds 	.write_setup	= nfs3_proc_write_setup,
960788e7a89STrond Myklebust 	.write_done	= nfs3_write_done,
9611da177e4SLinus Torvalds 	.commit_setup	= nfs3_proc_commit_setup,
9620b7c0153SFred Isaman 	.commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
963788e7a89STrond Myklebust 	.commit_done	= nfs3_commit_done,
9641da177e4SLinus Torvalds 	.lock		= nfs3_proc_lock,
965013cdf10SChristoph Hellwig 	.clear_acl_cache = forget_all_cached_acls,
9667fe5c398STrond Myklebust 	.close_context	= nfs_close_context,
967011e2a7fSBryan Schumaker 	.have_delegation = nfs3_have_delegation,
96857ec14c5SBryan Schumaker 	.return_delegation = nfs3_return_delegation,
9696663ee7fSBryan Schumaker 	.alloc_client	= nfs_alloc_client,
97045a52a02SAndy Adamson 	.init_client	= nfs_init_client,
971cdb7ecedSBryan Schumaker 	.free_client	= nfs_free_client,
9721179acc6SBryan Schumaker 	.create_server	= nfs3_create_server,
9731179acc6SBryan Schumaker 	.clone_server	= nfs3_clone_server,
9741da177e4SLinus Torvalds };
975