blob: 560536ad74a49fd500077882b211655c26424b85 [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
189static int nfs_proc_read(struct nfs_read_data *rdata)
190{
191 int flags = rdata->flags;
192 struct inode * inode = rdata->inode;
193 struct nfs_fattr * fattr = rdata->res.fattr;
194 struct rpc_message msg = {
195 .rpc_proc = &nfs_procedures[NFSPROC_READ],
196 .rpc_argp = &rdata->args,
197 .rpc_resp = &rdata->res,
198 .rpc_cred = rdata->cred,
199 };
200 int status;
201
202 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
203 (long long) rdata->args.offset);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400204 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
206 if (status >= 0) {
207 nfs_refresh_inode(inode, fattr);
208 /* Emulate the eof flag, which isn't normally needed in NFSv2
209 * as it is guaranteed to always return the file attributes
210 */
211 if (rdata->args.offset + rdata->args.count >= fattr->size)
212 rdata->res.eof = 1;
213 }
214 dprintk("NFS reply read: %d\n", status);
215 return status;
216}
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218static int
219nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -0700220 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 struct nfs_fh fhandle;
223 struct nfs_fattr fattr;
224 struct nfs_createargs arg = {
225 .fh = NFS_FH(dir),
226 .name = dentry->d_name.name,
227 .len = dentry->d_name.len,
228 .sattr = sattr
229 };
230 struct nfs_diropok res = {
231 .fh = &fhandle,
232 .fattr = &fattr
233 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500234 struct rpc_message msg = {
235 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
236 .rpc_argp = &arg,
237 .rpc_resp = &res,
238 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 int status;
240
Trond Myklebust0e574af2005-10-27 22:12:38 -0400241 nfs_fattr_init(&fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 dprintk("NFS call create %s\n", dentry->d_name.name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500243 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (status == 0)
245 status = nfs_instantiate(dentry, &fhandle, &fattr);
246 dprintk("NFS reply create: %d\n", status);
247 return status;
248}
249
250/*
251 * In NFSv2, mknod is grafted onto the create call.
252 */
253static int
254nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
255 dev_t rdev)
256{
257 struct nfs_fh fhandle;
258 struct nfs_fattr fattr;
259 struct nfs_createargs arg = {
260 .fh = NFS_FH(dir),
261 .name = dentry->d_name.name,
262 .len = dentry->d_name.len,
263 .sattr = sattr
264 };
265 struct nfs_diropok res = {
266 .fh = &fhandle,
267 .fattr = &fattr
268 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500269 struct rpc_message msg = {
270 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
271 .rpc_argp = &arg,
272 .rpc_resp = &res,
273 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 int status, mode;
275
276 dprintk("NFS call mknod %s\n", dentry->d_name.name);
277
278 mode = sattr->ia_mode;
279 if (S_ISFIFO(mode)) {
280 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
281 sattr->ia_valid &= ~ATTR_SIZE;
282 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
283 sattr->ia_valid |= ATTR_SIZE;
284 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
285 }
286
Trond Myklebust0e574af2005-10-27 22:12:38 -0400287 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500288 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 if (status == -EINVAL && S_ISFIFO(mode)) {
292 sattr->ia_mode = mode;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400293 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500294 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296 if (status == 0)
297 status = nfs_instantiate(dentry, &fhandle, &fattr);
298 dprintk("NFS reply mknod: %d\n", status);
299 return status;
300}
301
302static int
303nfs_proc_remove(struct inode *dir, struct qstr *name)
304{
305 struct nfs_diropargs arg = {
306 .fh = NFS_FH(dir),
307 .name = name->name,
308 .len = name->len
309 };
310 struct rpc_message msg = {
311 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
312 .rpc_argp = &arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 };
314 int status;
315
316 dprintk("NFS call remove %s\n", name->name);
317 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400318 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 dprintk("NFS reply remove: %d\n", status);
321 return status;
322}
323
324static int
325nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
326{
327 struct nfs_diropargs *arg;
328
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700329 arg = kmalloc(sizeof(*arg), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (!arg)
331 return -ENOMEM;
332 arg->fh = NFS_FH(dir->d_inode);
333 arg->name = name->name;
334 arg->len = name->len;
335 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
336 msg->rpc_argp = arg;
337 return 0;
338}
339
340static int
341nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
342{
343 struct rpc_message *msg = &task->tk_msg;
344
Trond Myklebustdecf4912005-10-27 22:12:39 -0400345 if (msg->rpc_argp) {
346 nfs_mark_for_revalidate(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 kfree(msg->rpc_argp);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return 0;
350}
351
352static int
353nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
354 struct inode *new_dir, struct qstr *new_name)
355{
356 struct nfs_renameargs arg = {
357 .fromfh = NFS_FH(old_dir),
358 .fromname = old_name->name,
359 .fromlen = old_name->len,
360 .tofh = NFS_FH(new_dir),
361 .toname = new_name->name,
362 .tolen = new_name->len
363 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500364 struct rpc_message msg = {
365 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
366 .rpc_argp = &arg,
367 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 int status;
369
370 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500371 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400372 nfs_mark_for_revalidate(old_dir);
373 nfs_mark_for_revalidate(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 dprintk("NFS reply rename: %d\n", status);
375 return status;
376}
377
378static int
379nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
380{
381 struct nfs_linkargs arg = {
382 .fromfh = NFS_FH(inode),
383 .tofh = NFS_FH(dir),
384 .toname = name->name,
385 .tolen = name->len
386 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500387 struct rpc_message msg = {
388 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
389 .rpc_argp = &arg,
390 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 int status;
392
393 dprintk("NFS call link %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500394 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust5ba7cc42005-12-03 15:20:17 -0500395 nfs_mark_for_revalidate(inode);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400396 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 dprintk("NFS reply link: %d\n", status);
398 return status;
399}
400
401static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400402nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
403 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Chuck Lever4f390c12006-08-22 20:06:22 -0400405 struct nfs_fh fhandle;
406 struct nfs_fattr fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 struct nfs_symlinkargs arg = {
408 .fromfh = NFS_FH(dir),
Chuck Lever4f390c12006-08-22 20:06:22 -0400409 .fromname = dentry->d_name.name,
410 .fromlen = dentry->d_name.len,
Chuck Lever94a6d752006-08-22 20:06:23 -0400411 .pages = &page,
412 .pathlen = len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .sattr = sattr
414 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500415 struct rpc_message msg = {
416 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
417 .rpc_argp = &arg,
418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 int status;
420
Chuck Lever94a6d752006-08-22 20:06:23 -0400421 if (len > NFS2_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400423
Chuck Lever94a6d752006-08-22 20:06:23 -0400424 dprintk("NFS call symlink %s\n", dentry->d_name.name);
425
Chuck Leverdead28d2006-03-20 13:44:23 -0500426 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400427 nfs_mark_for_revalidate(dir);
Chuck Lever4f390c12006-08-22 20:06:22 -0400428
429 /*
430 * V2 SYMLINK requests don't return any attributes. Setting the
431 * filehandle size to zero indicates to nfs_instantiate that it
432 * should fill in the data with a LOOKUP call on the wire.
433 */
434 if (status == 0) {
435 nfs_fattr_init(&fattr);
436 fhandle.size = 0;
437 status = nfs_instantiate(dentry, &fhandle, &fattr);
438 }
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 dprintk("NFS reply symlink: %d\n", status);
441 return status;
442}
443
444static int
445nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
446{
447 struct nfs_fh fhandle;
448 struct nfs_fattr fattr;
449 struct nfs_createargs arg = {
450 .fh = NFS_FH(dir),
451 .name = dentry->d_name.name,
452 .len = dentry->d_name.len,
453 .sattr = sattr
454 };
455 struct nfs_diropok res = {
456 .fh = &fhandle,
457 .fattr = &fattr
458 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500459 struct rpc_message msg = {
460 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
461 .rpc_argp = &arg,
462 .rpc_resp = &res,
463 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 int status;
465
466 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400467 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500468 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400469 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (status == 0)
471 status = nfs_instantiate(dentry, &fhandle, &fattr);
472 dprintk("NFS reply mkdir: %d\n", status);
473 return status;
474}
475
476static int
477nfs_proc_rmdir(struct inode *dir, struct qstr *name)
478{
479 struct nfs_diropargs arg = {
480 .fh = NFS_FH(dir),
481 .name = name->name,
482 .len = name->len
483 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500484 struct rpc_message msg = {
485 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
486 .rpc_argp = &arg,
487 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 int status;
489
490 dprintk("NFS call rmdir %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500491 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400492 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 dprintk("NFS reply rmdir: %d\n", status);
494 return status;
495}
496
497/*
498 * The READDIR implementation is somewhat hackish - we pass a temporary
499 * buffer to the encode function, which installs it in the receive
500 * the receive iovec. The decode function just parses the reply to make
501 * sure it is syntactically correct; the entries itself are decoded
502 * from nfs_readdir by calling the decode_entry function directly.
503 */
504static int
505nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
506 u64 cookie, struct page *page, unsigned int count, int plus)
507{
508 struct inode *dir = dentry->d_inode;
509 struct nfs_readdirargs arg = {
510 .fh = NFS_FH(dir),
511 .cookie = cookie,
512 .count = count,
Chuck Leverdead28d2006-03-20 13:44:23 -0500513 .pages = &page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 };
515 struct rpc_message msg = {
516 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
517 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500518 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 };
520 int status;
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
523 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
524
525 dprintk("NFS reply readdir: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 return status;
527}
528
529static int
530nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
531 struct nfs_fsstat *stat)
532{
533 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500534 struct rpc_message msg = {
535 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
536 .rpc_argp = fhandle,
537 .rpc_resp = &fsinfo,
538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 int status;
540
541 dprintk("NFS call statfs\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400542 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500543 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 dprintk("NFS reply statfs: %d\n", status);
545 if (status)
546 goto out;
547 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
548 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
549 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
550 stat->tfiles = 0;
551 stat->ffiles = 0;
552 stat->afiles = 0;
553out:
554 return status;
555}
556
557static int
558nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
559 struct nfs_fsinfo *info)
560{
561 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500562 struct rpc_message msg = {
563 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
564 .rpc_argp = fhandle,
565 .rpc_resp = &fsinfo,
566 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int status;
568
569 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400570 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500571 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 dprintk("NFS reply fsinfo: %d\n", status);
573 if (status)
574 goto out;
575 info->rtmax = NFS_MAXDATA;
576 info->rtpref = fsinfo.tsize;
577 info->rtmult = fsinfo.bsize;
578 info->wtmax = NFS_MAXDATA;
579 info->wtpref = fsinfo.tsize;
580 info->wtmult = fsinfo.bsize;
581 info->dtpref = fsinfo.tsize;
582 info->maxfilesize = 0x7FFFFFFF;
583 info->lease_time = 0;
584out:
585 return status;
586}
587
588static int
589nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
590 struct nfs_pathconf *info)
591{
592 info->max_link = 0;
593 info->max_namelen = NFS2_MAXNAMLEN;
594 return 0;
595}
596
Trond Myklebustec06c092006-03-20 13:44:27 -0500597static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if (task->tk_status >= 0) {
600 nfs_refresh_inode(data->inode, data->res.fattr);
601 /* Emulate the eof flag, which isn't normally needed in NFSv2
602 * as it is guaranteed to always return the file attributes
603 */
604 if (data->args.offset + data->args.count >= data->res.fattr->size)
605 data->res.eof = 1;
606 }
Trond Myklebustec06c092006-03-20 13:44:27 -0500607 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
Trond Myklebustec06c092006-03-20 13:44:27 -0500610static void nfs_proc_read_setup(struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 struct rpc_message msg = {
613 .rpc_proc = &nfs_procedures[NFSPROC_READ],
614 .rpc_argp = &data->args,
615 .rpc_resp = &data->res,
616 .rpc_cred = data->cred,
617 };
618
Trond Myklebustec06c092006-03-20 13:44:27 -0500619 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
Trond Myklebust788e7a82006-03-20 13:44:27 -0500622static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (task->tk_status >= 0)
Trond Myklebustdecf4912005-10-27 22:12:39 -0400625 nfs_post_op_update_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Trond Myklebust788e7a82006-03-20 13:44:27 -0500629static void nfs_proc_write_setup(struct nfs_write_data *data, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 struct rpc_message msg = {
632 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
633 .rpc_argp = &data->args,
634 .rpc_resp = &data->res,
635 .rpc_cred = data->cred,
636 };
637
638 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
639 data->args.stable = NFS_FILE_SYNC;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* Finalize the task. */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500642 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645static void
646nfs_proc_commit_setup(struct nfs_write_data *data, int how)
647{
648 BUG();
649}
650
651static int
652nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
653{
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800654 return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657
David Howells509de812006-08-22 20:06:11 -0400658const struct nfs_rpc_ops nfs_v2_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .version = 2, /* protocol version */
660 .dentry_ops = &nfs_dentry_operations,
661 .dir_inode_ops = &nfs_dir_inode_operations,
J. Bruce Fields92cfc622005-06-22 17:16:22 +0000662 .file_inode_ops = &nfs_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .getroot = nfs_proc_get_root,
664 .getattr = nfs_proc_getattr,
665 .setattr = nfs_proc_setattr,
666 .lookup = nfs_proc_lookup,
667 .access = NULL, /* access */
668 .readlink = nfs_proc_readlink,
669 .read = nfs_proc_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .create = nfs_proc_create,
671 .remove = nfs_proc_remove,
672 .unlink_setup = nfs_proc_unlink_setup,
673 .unlink_done = nfs_proc_unlink_done,
674 .rename = nfs_proc_rename,
675 .link = nfs_proc_link,
676 .symlink = nfs_proc_symlink,
677 .mkdir = nfs_proc_mkdir,
678 .rmdir = nfs_proc_rmdir,
679 .readdir = nfs_proc_readdir,
680 .mknod = nfs_proc_mknod,
681 .statfs = nfs_proc_statfs,
682 .fsinfo = nfs_proc_fsinfo,
683 .pathconf = nfs_proc_pathconf,
684 .decode_dirent = nfs_decode_dirent,
685 .read_setup = nfs_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500686 .read_done = nfs_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .write_setup = nfs_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500688 .write_done = nfs_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .commit_setup = nfs_proc_commit_setup,
690 .file_open = nfs_open,
691 .file_release = nfs_release,
692 .lock = nfs_proc_lock,
693};