blob: 1dcf56de948276c5bef2c62ff91303c30c652611 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/proc.c
3 *
4 * Copyright (C) 1992, 1993, 1994 Rick Sladkey
5 *
6 * OS-independent nfs remote procedure call functions
7 *
8 * Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers
9 * so at last we can have decent(ish) throughput off a
10 * Sun server.
11 *
12 * Coding optimized and cleaned up by Florian La Roche.
13 * Note: Error returns are optimized for NFS_OK, which isn't translated via
14 * nfs_stat_to_errno(), but happens to be already the right return code.
15 *
16 * Also, the code currently doesn't check the size of the packet, when
17 * it decodes the packet.
18 *
19 * Feel free to fix it and mail me the diffs if it worries you.
20 *
21 * Completely rewritten to support the new RPC call interface;
22 * rewrote and moved the entire XDR stuff to xdr.c
23 * --Olaf Kirch June 1996
24 *
25 * The code below initializes all auto variables explicitly, otherwise
26 * it will fail to work as a module (gcc generates a memset call for an
27 * incomplete struct).
28 */
29
30#include <linux/types.h>
31#include <linux/param.h>
32#include <linux/slab.h>
33#include <linux/time.h>
34#include <linux/mm.h>
35#include <linux/utsname.h>
36#include <linux/errno.h>
37#include <linux/string.h>
38#include <linux/in.h>
39#include <linux/pagemap.h>
40#include <linux/sunrpc/clnt.h>
41#include <linux/nfs.h>
42#include <linux/nfs2.h>
43#include <linux/nfs_fs.h>
44#include <linux/nfs_page.h>
45#include <linux/lockd/bind.h>
46#include <linux/smp_lock.h>
David Howellsf7b422b2006-06-09 09:34:33 -040047#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define NFSDBG_FACILITY NFSDBG_PROC
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * Bare-bones access to getattr: this is for nfs_read_super.
53 */
54static int
55nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
56 struct nfs_fsinfo *info)
57{
58 struct nfs_fattr *fattr = info->fattr;
59 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -050060 struct rpc_message msg = {
61 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
62 .rpc_argp = fhandle,
63 .rpc_resp = fattr,
64 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 int status;
66
67 dprintk("%s: call getattr\n", __FUNCTION__);
Trond Myklebust0e574af2005-10-27 22:12:38 -040068 nfs_fattr_init(fattr);
David Howells5006a762006-08-22 20:06:12 -040069 status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
71 if (status)
72 return status;
73 dprintk("%s: call statfs\n", __FUNCTION__);
Chuck Leverdead28d2006-03-20 13:44:23 -050074 msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
75 msg.rpc_resp = &fsinfo;
David Howells5006a762006-08-22 20:06:12 -040076 status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 dprintk("%s: reply statfs: %d\n", __FUNCTION__, status);
78 if (status)
79 return status;
80 info->rtmax = NFS_MAXDATA;
81 info->rtpref = fsinfo.tsize;
82 info->rtmult = fsinfo.bsize;
83 info->wtmax = NFS_MAXDATA;
84 info->wtpref = fsinfo.tsize;
85 info->wtmult = fsinfo.bsize;
86 info->dtpref = fsinfo.tsize;
87 info->maxfilesize = 0x7FFFFFFF;
88 info->lease_time = 0;
89 return 0;
90}
91
92/*
93 * One function for each procedure in the NFS protocol.
94 */
95static int
96nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
97 struct nfs_fattr *fattr)
98{
Chuck Leverdead28d2006-03-20 13:44:23 -050099 struct rpc_message msg = {
100 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
101 .rpc_argp = fhandle,
102 .rpc_resp = fattr,
103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 int status;
105
106 dprintk("NFS call getattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400107 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500108 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 dprintk("NFS reply getattr: %d\n", status);
110 return status;
111}
112
113static int
114nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
115 struct iattr *sattr)
116{
117 struct inode *inode = dentry->d_inode;
118 struct nfs_sattrargs arg = {
119 .fh = NFS_FH(inode),
120 .sattr = sattr
121 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500122 struct rpc_message msg = {
123 .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
124 .rpc_argp = &arg,
125 .rpc_resp = fattr,
126 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int status;
128
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100129 /* Mask out the non-modebit related stuff from attr->ia_mode */
130 sattr->ia_mode &= S_IALLUGO;
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 dprintk("NFS call setattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400133 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500134 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust65e43082005-08-16 11:49:44 -0400135 if (status == 0)
136 nfs_setattr_update_inode(inode, sattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 dprintk("NFS reply setattr: %d\n", status);
138 return status;
139}
140
141static int
142nfs_proc_lookup(struct inode *dir, struct qstr *name,
143 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
144{
145 struct nfs_diropargs arg = {
146 .fh = NFS_FH(dir),
147 .name = name->name,
148 .len = name->len
149 };
150 struct nfs_diropok res = {
151 .fh = fhandle,
152 .fattr = fattr
153 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500154 struct rpc_message msg = {
155 .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
156 .rpc_argp = &arg,
157 .rpc_resp = &res,
158 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 int status;
160
161 dprintk("NFS call lookup %s\n", name->name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400162 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500163 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 dprintk("NFS reply lookup: %d\n", status);
165 return status;
166}
167
168static int nfs_proc_readlink(struct inode *inode, struct page *page,
169 unsigned int pgbase, unsigned int pglen)
170{
171 struct nfs_readlinkargs args = {
172 .fh = NFS_FH(inode),
173 .pgbase = pgbase,
174 .pglen = pglen,
175 .pages = &page
176 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500177 struct rpc_message msg = {
178 .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
179 .rpc_argp = &args,
180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 int status;
182
183 dprintk("NFS call readlink\n");
Chuck Leverdead28d2006-03-20 13:44:23 -0500184 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 dprintk("NFS reply readlink: %d\n", status);
186 return status;
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static int
190nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -0700191 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 struct nfs_fh fhandle;
194 struct nfs_fattr fattr;
195 struct nfs_createargs arg = {
196 .fh = NFS_FH(dir),
197 .name = dentry->d_name.name,
198 .len = dentry->d_name.len,
199 .sattr = sattr
200 };
201 struct nfs_diropok res = {
202 .fh = &fhandle,
203 .fattr = &fattr
204 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500205 struct rpc_message msg = {
206 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
207 .rpc_argp = &arg,
208 .rpc_resp = &res,
209 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 int status;
211
Trond Myklebust0e574af2005-10-27 22:12:38 -0400212 nfs_fattr_init(&fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 dprintk("NFS call create %s\n", dentry->d_name.name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500214 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (status == 0)
216 status = nfs_instantiate(dentry, &fhandle, &fattr);
217 dprintk("NFS reply create: %d\n", status);
218 return status;
219}
220
221/*
222 * In NFSv2, mknod is grafted onto the create call.
223 */
224static int
225nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
226 dev_t rdev)
227{
228 struct nfs_fh fhandle;
229 struct nfs_fattr fattr;
230 struct nfs_createargs arg = {
231 .fh = NFS_FH(dir),
232 .name = dentry->d_name.name,
233 .len = dentry->d_name.len,
234 .sattr = sattr
235 };
236 struct nfs_diropok res = {
237 .fh = &fhandle,
238 .fattr = &fattr
239 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500240 struct rpc_message msg = {
241 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
242 .rpc_argp = &arg,
243 .rpc_resp = &res,
244 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 int status, mode;
246
247 dprintk("NFS call mknod %s\n", dentry->d_name.name);
248
249 mode = sattr->ia_mode;
250 if (S_ISFIFO(mode)) {
251 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
252 sattr->ia_valid &= ~ATTR_SIZE;
253 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
254 sattr->ia_valid |= ATTR_SIZE;
255 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
256 }
257
Trond Myklebust0e574af2005-10-27 22:12:38 -0400258 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500259 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400260 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 if (status == -EINVAL && S_ISFIFO(mode)) {
263 sattr->ia_mode = mode;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400264 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500265 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267 if (status == 0)
268 status = nfs_instantiate(dentry, &fhandle, &fattr);
269 dprintk("NFS reply mknod: %d\n", status);
270 return status;
271}
272
273static int
274nfs_proc_remove(struct inode *dir, struct qstr *name)
275{
276 struct nfs_diropargs arg = {
277 .fh = NFS_FH(dir),
278 .name = name->name,
279 .len = name->len
280 };
281 struct rpc_message msg = {
282 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
283 .rpc_argp = &arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 };
285 int status;
286
287 dprintk("NFS call remove %s\n", name->name);
288 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400289 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 dprintk("NFS reply remove: %d\n", status);
292 return status;
293}
294
295static int
296nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
297{
298 struct nfs_diropargs *arg;
299
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700300 arg = kmalloc(sizeof(*arg), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (!arg)
302 return -ENOMEM;
303 arg->fh = NFS_FH(dir->d_inode);
304 arg->name = name->name;
305 arg->len = name->len;
306 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
307 msg->rpc_argp = arg;
308 return 0;
309}
310
311static int
312nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
313{
314 struct rpc_message *msg = &task->tk_msg;
315
Trond Myklebustdecf4912005-10-27 22:12:39 -0400316 if (msg->rpc_argp) {
317 nfs_mark_for_revalidate(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 kfree(msg->rpc_argp);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return 0;
321}
322
323static int
324nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
325 struct inode *new_dir, struct qstr *new_name)
326{
327 struct nfs_renameargs arg = {
328 .fromfh = NFS_FH(old_dir),
329 .fromname = old_name->name,
330 .fromlen = old_name->len,
331 .tofh = NFS_FH(new_dir),
332 .toname = new_name->name,
333 .tolen = new_name->len
334 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500335 struct rpc_message msg = {
336 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
337 .rpc_argp = &arg,
338 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 int status;
340
341 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500342 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400343 nfs_mark_for_revalidate(old_dir);
344 nfs_mark_for_revalidate(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 dprintk("NFS reply rename: %d\n", status);
346 return status;
347}
348
349static int
350nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
351{
352 struct nfs_linkargs arg = {
353 .fromfh = NFS_FH(inode),
354 .tofh = NFS_FH(dir),
355 .toname = name->name,
356 .tolen = name->len
357 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500358 struct rpc_message msg = {
359 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
360 .rpc_argp = &arg,
361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int status;
363
364 dprintk("NFS call link %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500365 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust5ba7cc42005-12-03 15:20:17 -0500366 nfs_mark_for_revalidate(inode);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400367 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 dprintk("NFS reply link: %d\n", status);
369 return status;
370}
371
372static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400373nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
374 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Chuck Lever4f390c12006-08-22 20:06:22 -0400376 struct nfs_fh fhandle;
377 struct nfs_fattr fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 struct nfs_symlinkargs arg = {
379 .fromfh = NFS_FH(dir),
Chuck Lever4f390c12006-08-22 20:06:22 -0400380 .fromname = dentry->d_name.name,
381 .fromlen = dentry->d_name.len,
Chuck Lever94a6d752006-08-22 20:06:23 -0400382 .pages = &page,
383 .pathlen = len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 .sattr = sattr
385 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500386 struct rpc_message msg = {
387 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
388 .rpc_argp = &arg,
389 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 int status;
391
Chuck Lever94a6d752006-08-22 20:06:23 -0400392 if (len > NFS2_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400394
Chuck Lever94a6d752006-08-22 20:06:23 -0400395 dprintk("NFS call symlink %s\n", dentry->d_name.name);
396
Chuck Leverdead28d2006-03-20 13:44:23 -0500397 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400398 nfs_mark_for_revalidate(dir);
Chuck Lever4f390c12006-08-22 20:06:22 -0400399
400 /*
401 * V2 SYMLINK requests don't return any attributes. Setting the
402 * filehandle size to zero indicates to nfs_instantiate that it
403 * should fill in the data with a LOOKUP call on the wire.
404 */
405 if (status == 0) {
406 nfs_fattr_init(&fattr);
407 fhandle.size = 0;
408 status = nfs_instantiate(dentry, &fhandle, &fattr);
409 }
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 dprintk("NFS reply symlink: %d\n", status);
412 return status;
413}
414
415static int
416nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
417{
418 struct nfs_fh fhandle;
419 struct nfs_fattr fattr;
420 struct nfs_createargs arg = {
421 .fh = NFS_FH(dir),
422 .name = dentry->d_name.name,
423 .len = dentry->d_name.len,
424 .sattr = sattr
425 };
426 struct nfs_diropok res = {
427 .fh = &fhandle,
428 .fattr = &fattr
429 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500430 struct rpc_message msg = {
431 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
432 .rpc_argp = &arg,
433 .rpc_resp = &res,
434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 int status;
436
437 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400438 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500439 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400440 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (status == 0)
442 status = nfs_instantiate(dentry, &fhandle, &fattr);
443 dprintk("NFS reply mkdir: %d\n", status);
444 return status;
445}
446
447static int
448nfs_proc_rmdir(struct inode *dir, struct qstr *name)
449{
450 struct nfs_diropargs arg = {
451 .fh = NFS_FH(dir),
452 .name = name->name,
453 .len = name->len
454 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500455 struct rpc_message msg = {
456 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
457 .rpc_argp = &arg,
458 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 int status;
460
461 dprintk("NFS call rmdir %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500462 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400463 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 dprintk("NFS reply rmdir: %d\n", status);
465 return status;
466}
467
468/*
469 * The READDIR implementation is somewhat hackish - we pass a temporary
470 * buffer to the encode function, which installs it in the receive
471 * the receive iovec. The decode function just parses the reply to make
472 * sure it is syntactically correct; the entries itself are decoded
473 * from nfs_readdir by calling the decode_entry function directly.
474 */
475static int
476nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
477 u64 cookie, struct page *page, unsigned int count, int plus)
478{
479 struct inode *dir = dentry->d_inode;
480 struct nfs_readdirargs arg = {
481 .fh = NFS_FH(dir),
482 .cookie = cookie,
483 .count = count,
Chuck Leverdead28d2006-03-20 13:44:23 -0500484 .pages = &page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 };
486 struct rpc_message msg = {
487 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
488 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500489 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 };
491 int status;
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
494 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
495
496 dprintk("NFS reply readdir: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 return status;
498}
499
500static int
501nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
502 struct nfs_fsstat *stat)
503{
504 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500505 struct rpc_message msg = {
506 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
507 .rpc_argp = fhandle,
508 .rpc_resp = &fsinfo,
509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 int status;
511
512 dprintk("NFS call statfs\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400513 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500514 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 dprintk("NFS reply statfs: %d\n", status);
516 if (status)
517 goto out;
518 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
519 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
520 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
521 stat->tfiles = 0;
522 stat->ffiles = 0;
523 stat->afiles = 0;
524out:
525 return status;
526}
527
528static int
529nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
530 struct nfs_fsinfo *info)
531{
532 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500533 struct rpc_message msg = {
534 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
535 .rpc_argp = fhandle,
536 .rpc_resp = &fsinfo,
537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 int status;
539
540 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400541 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500542 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 dprintk("NFS reply fsinfo: %d\n", status);
544 if (status)
545 goto out;
546 info->rtmax = NFS_MAXDATA;
547 info->rtpref = fsinfo.tsize;
548 info->rtmult = fsinfo.bsize;
549 info->wtmax = NFS_MAXDATA;
550 info->wtpref = fsinfo.tsize;
551 info->wtmult = fsinfo.bsize;
552 info->dtpref = fsinfo.tsize;
553 info->maxfilesize = 0x7FFFFFFF;
554 info->lease_time = 0;
555out:
556 return status;
557}
558
559static int
560nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
561 struct nfs_pathconf *info)
562{
563 info->max_link = 0;
564 info->max_namelen = NFS2_MAXNAMLEN;
565 return 0;
566}
567
Trond Myklebustec06c092006-03-20 13:44:27 -0500568static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (task->tk_status >= 0) {
571 nfs_refresh_inode(data->inode, data->res.fattr);
572 /* Emulate the eof flag, which isn't normally needed in NFSv2
573 * as it is guaranteed to always return the file attributes
574 */
575 if (data->args.offset + data->args.count >= data->res.fattr->size)
576 data->res.eof = 1;
577 }
Trond Myklebustec06c092006-03-20 13:44:27 -0500578 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
Trond Myklebustec06c092006-03-20 13:44:27 -0500581static void nfs_proc_read_setup(struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 struct rpc_message msg = {
584 .rpc_proc = &nfs_procedures[NFSPROC_READ],
585 .rpc_argp = &data->args,
586 .rpc_resp = &data->res,
587 .rpc_cred = data->cred,
588 };
589
Trond Myklebustec06c092006-03-20 13:44:27 -0500590 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Trond Myklebust788e7a82006-03-20 13:44:27 -0500593static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 if (task->tk_status >= 0)
Trond Myklebustdecf4912005-10-27 22:12:39 -0400596 nfs_post_op_update_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
Trond Myklebust788e7a82006-03-20 13:44:27 -0500600static void nfs_proc_write_setup(struct nfs_write_data *data, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 struct rpc_message msg = {
603 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
604 .rpc_argp = &data->args,
605 .rpc_resp = &data->res,
606 .rpc_cred = data->cred,
607 };
608
609 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
610 data->args.stable = NFS_FILE_SYNC;
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /* Finalize the task. */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500613 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614}
615
616static void
617nfs_proc_commit_setup(struct nfs_write_data *data, int how)
618{
619 BUG();
620}
621
622static int
623nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
624{
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800625 return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
628
David Howells509de812006-08-22 20:06:11 -0400629const struct nfs_rpc_ops nfs_v2_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .version = 2, /* protocol version */
631 .dentry_ops = &nfs_dentry_operations,
632 .dir_inode_ops = &nfs_dir_inode_operations,
J. Bruce Fields92cfc622005-06-22 17:16:22 +0000633 .file_inode_ops = &nfs_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .getroot = nfs_proc_get_root,
635 .getattr = nfs_proc_getattr,
636 .setattr = nfs_proc_setattr,
637 .lookup = nfs_proc_lookup,
638 .access = NULL, /* access */
639 .readlink = nfs_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .create = nfs_proc_create,
641 .remove = nfs_proc_remove,
642 .unlink_setup = nfs_proc_unlink_setup,
643 .unlink_done = nfs_proc_unlink_done,
644 .rename = nfs_proc_rename,
645 .link = nfs_proc_link,
646 .symlink = nfs_proc_symlink,
647 .mkdir = nfs_proc_mkdir,
648 .rmdir = nfs_proc_rmdir,
649 .readdir = nfs_proc_readdir,
650 .mknod = nfs_proc_mknod,
651 .statfs = nfs_proc_statfs,
652 .fsinfo = nfs_proc_fsinfo,
653 .pathconf = nfs_proc_pathconf,
654 .decode_dirent = nfs_decode_dirent,
655 .read_setup = nfs_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500656 .read_done = nfs_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .write_setup = nfs_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500658 .write_done = nfs_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .commit_setup = nfs_proc_commit_setup,
660 .file_open = nfs_open,
661 .file_release = nfs_release,
662 .lock = nfs_proc_lock,
663};