blob: 9dd85cac2df0130ebd1228f6681848794d3bd69d [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>
47
48#define NFSDBG_FACILITY NFSDBG_PROC
49
50extern struct rpc_procinfo nfs_procedures[];
51
52/*
53 * Bare-bones access to getattr: this is for nfs_read_super.
54 */
55static int
56nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
57 struct nfs_fsinfo *info)
58{
59 struct nfs_fattr *fattr = info->fattr;
60 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -050061 struct rpc_message msg = {
62 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
63 .rpc_argp = fhandle,
64 .rpc_resp = fattr,
65 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 int status;
67
68 dprintk("%s: call getattr\n", __FUNCTION__);
Trond Myklebust0e574af2005-10-27 22:12:38 -040069 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -050070 status = rpc_call_sync(server->client_sys, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
72 if (status)
73 return status;
74 dprintk("%s: call statfs\n", __FUNCTION__);
Chuck Leverdead28d2006-03-20 13:44:23 -050075 msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
76 msg.rpc_resp = &fsinfo;
77 status = rpc_call_sync(server->client_sys, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 dprintk("%s: reply statfs: %d\n", __FUNCTION__, status);
79 if (status)
80 return status;
81 info->rtmax = NFS_MAXDATA;
82 info->rtpref = fsinfo.tsize;
83 info->rtmult = fsinfo.bsize;
84 info->wtmax = NFS_MAXDATA;
85 info->wtpref = fsinfo.tsize;
86 info->wtmult = fsinfo.bsize;
87 info->dtpref = fsinfo.tsize;
88 info->maxfilesize = 0x7FFFFFFF;
89 info->lease_time = 0;
90 return 0;
91}
92
93/*
94 * One function for each procedure in the NFS protocol.
95 */
96static int
97nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
98 struct nfs_fattr *fattr)
99{
Chuck Leverdead28d2006-03-20 13:44:23 -0500100 struct rpc_message msg = {
101 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
102 .rpc_argp = fhandle,
103 .rpc_resp = fattr,
104 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 int status;
106
107 dprintk("NFS call getattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400108 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500109 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 dprintk("NFS reply getattr: %d\n", status);
111 return status;
112}
113
114static int
115nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
116 struct iattr *sattr)
117{
118 struct inode *inode = dentry->d_inode;
119 struct nfs_sattrargs arg = {
120 .fh = NFS_FH(inode),
121 .sattr = sattr
122 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500123 struct rpc_message msg = {
124 .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
125 .rpc_argp = &arg,
126 .rpc_resp = fattr,
127 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 int status;
129
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100130 /* Mask out the non-modebit related stuff from attr->ia_mode */
131 sattr->ia_mode &= S_IALLUGO;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 dprintk("NFS call setattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400134 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500135 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust65e43082005-08-16 11:49:44 -0400136 if (status == 0)
137 nfs_setattr_update_inode(inode, sattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 dprintk("NFS reply setattr: %d\n", status);
139 return status;
140}
141
142static int
143nfs_proc_lookup(struct inode *dir, struct qstr *name,
144 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
145{
146 struct nfs_diropargs arg = {
147 .fh = NFS_FH(dir),
148 .name = name->name,
149 .len = name->len
150 };
151 struct nfs_diropok res = {
152 .fh = fhandle,
153 .fattr = fattr
154 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500155 struct rpc_message msg = {
156 .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
157 .rpc_argp = &arg,
158 .rpc_resp = &res,
159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 int status;
161
162 dprintk("NFS call lookup %s\n", name->name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400163 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500164 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 dprintk("NFS reply lookup: %d\n", status);
166 return status;
167}
168
169static int nfs_proc_readlink(struct inode *inode, struct page *page,
170 unsigned int pgbase, unsigned int pglen)
171{
172 struct nfs_readlinkargs args = {
173 .fh = NFS_FH(inode),
174 .pgbase = pgbase,
175 .pglen = pglen,
176 .pages = &page
177 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500178 struct rpc_message msg = {
179 .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
180 .rpc_argp = &args,
181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 int status;
183
184 dprintk("NFS call readlink\n");
Chuck Leverdead28d2006-03-20 13:44:23 -0500185 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 dprintk("NFS reply readlink: %d\n", status);
187 return status;
188}
189
190static int nfs_proc_read(struct nfs_read_data *rdata)
191{
192 int flags = rdata->flags;
193 struct inode * inode = rdata->inode;
194 struct nfs_fattr * fattr = rdata->res.fattr;
195 struct rpc_message msg = {
196 .rpc_proc = &nfs_procedures[NFSPROC_READ],
197 .rpc_argp = &rdata->args,
198 .rpc_resp = &rdata->res,
199 .rpc_cred = rdata->cred,
200 };
201 int status;
202
203 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
204 (long long) rdata->args.offset);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400205 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
207 if (status >= 0) {
208 nfs_refresh_inode(inode, fattr);
209 /* Emulate the eof flag, which isn't normally needed in NFSv2
210 * as it is guaranteed to always return the file attributes
211 */
212 if (rdata->args.offset + rdata->args.count >= fattr->size)
213 rdata->res.eof = 1;
214 }
215 dprintk("NFS reply read: %d\n", status);
216 return status;
217}
218
219static int nfs_proc_write(struct nfs_write_data *wdata)
220{
221 int flags = wdata->flags;
222 struct inode * inode = wdata->inode;
223 struct nfs_fattr * fattr = wdata->res.fattr;
224 struct rpc_message msg = {
225 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
226 .rpc_argp = &wdata->args,
227 .rpc_resp = &wdata->res,
228 .rpc_cred = wdata->cred,
229 };
230 int status;
231
232 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
233 (long long) wdata->args.offset);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400234 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
236 if (status >= 0) {
Trond Myklebustdecf4912005-10-27 22:12:39 -0400237 nfs_post_op_update_inode(inode, fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 wdata->res.count = wdata->args.count;
239 wdata->verf.committed = NFS_FILE_SYNC;
240 }
241 dprintk("NFS reply write: %d\n", status);
242 return status < 0? status : wdata->res.count;
243}
244
245static int
246nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -0700247 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct nfs_fh fhandle;
250 struct nfs_fattr fattr;
251 struct nfs_createargs arg = {
252 .fh = NFS_FH(dir),
253 .name = dentry->d_name.name,
254 .len = dentry->d_name.len,
255 .sattr = sattr
256 };
257 struct nfs_diropok res = {
258 .fh = &fhandle,
259 .fattr = &fattr
260 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500261 struct rpc_message msg = {
262 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
263 .rpc_argp = &arg,
264 .rpc_resp = &res,
265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 int status;
267
Trond Myklebust0e574af2005-10-27 22:12:38 -0400268 nfs_fattr_init(&fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 dprintk("NFS call create %s\n", dentry->d_name.name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500270 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (status == 0)
272 status = nfs_instantiate(dentry, &fhandle, &fattr);
273 dprintk("NFS reply create: %d\n", status);
274 return status;
275}
276
277/*
278 * In NFSv2, mknod is grafted onto the create call.
279 */
280static int
281nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
282 dev_t rdev)
283{
284 struct nfs_fh fhandle;
285 struct nfs_fattr fattr;
286 struct nfs_createargs arg = {
287 .fh = NFS_FH(dir),
288 .name = dentry->d_name.name,
289 .len = dentry->d_name.len,
290 .sattr = sattr
291 };
292 struct nfs_diropok res = {
293 .fh = &fhandle,
294 .fattr = &fattr
295 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500296 struct rpc_message msg = {
297 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
298 .rpc_argp = &arg,
299 .rpc_resp = &res,
300 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 int status, mode;
302
303 dprintk("NFS call mknod %s\n", dentry->d_name.name);
304
305 mode = sattr->ia_mode;
306 if (S_ISFIFO(mode)) {
307 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
308 sattr->ia_valid &= ~ATTR_SIZE;
309 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
310 sattr->ia_valid |= ATTR_SIZE;
311 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
312 }
313
Trond Myklebust0e574af2005-10-27 22:12:38 -0400314 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500315 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400316 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 if (status == -EINVAL && S_ISFIFO(mode)) {
319 sattr->ia_mode = mode;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400320 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500321 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323 if (status == 0)
324 status = nfs_instantiate(dentry, &fhandle, &fattr);
325 dprintk("NFS reply mknod: %d\n", status);
326 return status;
327}
328
329static int
330nfs_proc_remove(struct inode *dir, struct qstr *name)
331{
332 struct nfs_diropargs arg = {
333 .fh = NFS_FH(dir),
334 .name = name->name,
335 .len = name->len
336 };
337 struct rpc_message msg = {
338 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
339 .rpc_argp = &arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 };
341 int status;
342
343 dprintk("NFS call remove %s\n", name->name);
344 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400345 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 dprintk("NFS reply remove: %d\n", status);
348 return status;
349}
350
351static int
352nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
353{
354 struct nfs_diropargs *arg;
355
356 arg = (struct nfs_diropargs *)kmalloc(sizeof(*arg), GFP_KERNEL);
357 if (!arg)
358 return -ENOMEM;
359 arg->fh = NFS_FH(dir->d_inode);
360 arg->name = name->name;
361 arg->len = name->len;
362 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
363 msg->rpc_argp = arg;
364 return 0;
365}
366
367static int
368nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
369{
370 struct rpc_message *msg = &task->tk_msg;
371
Trond Myklebustdecf4912005-10-27 22:12:39 -0400372 if (msg->rpc_argp) {
373 nfs_mark_for_revalidate(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 kfree(msg->rpc_argp);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return 0;
377}
378
379static int
380nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
381 struct inode *new_dir, struct qstr *new_name)
382{
383 struct nfs_renameargs arg = {
384 .fromfh = NFS_FH(old_dir),
385 .fromname = old_name->name,
386 .fromlen = old_name->len,
387 .tofh = NFS_FH(new_dir),
388 .toname = new_name->name,
389 .tolen = new_name->len
390 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500391 struct rpc_message msg = {
392 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
393 .rpc_argp = &arg,
394 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 int status;
396
397 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500398 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400399 nfs_mark_for_revalidate(old_dir);
400 nfs_mark_for_revalidate(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 dprintk("NFS reply rename: %d\n", status);
402 return status;
403}
404
405static int
406nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
407{
408 struct nfs_linkargs arg = {
409 .fromfh = NFS_FH(inode),
410 .tofh = NFS_FH(dir),
411 .toname = name->name,
412 .tolen = name->len
413 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500414 struct rpc_message msg = {
415 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
416 .rpc_argp = &arg,
417 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 int status;
419
420 dprintk("NFS call link %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500421 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust5ba7cc42005-12-03 15:20:17 -0500422 nfs_mark_for_revalidate(inode);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400423 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 dprintk("NFS reply link: %d\n", status);
425 return status;
426}
427
428static int
429nfs_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
430 struct iattr *sattr, struct nfs_fh *fhandle,
431 struct nfs_fattr *fattr)
432{
433 struct nfs_symlinkargs arg = {
434 .fromfh = NFS_FH(dir),
435 .fromname = name->name,
436 .fromlen = name->len,
437 .topath = path->name,
438 .tolen = path->len,
439 .sattr = sattr
440 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500441 struct rpc_message msg = {
442 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
443 .rpc_argp = &arg,
444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 int status;
446
447 if (path->len > NFS2_MAXPATHLEN)
448 return -ENAMETOOLONG;
449 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400450 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 fhandle->size = 0;
Chuck Leverdead28d2006-03-20 13:44:23 -0500452 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400453 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 dprintk("NFS reply symlink: %d\n", status);
455 return status;
456}
457
458static int
459nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
460{
461 struct nfs_fh fhandle;
462 struct nfs_fattr fattr;
463 struct nfs_createargs arg = {
464 .fh = NFS_FH(dir),
465 .name = dentry->d_name.name,
466 .len = dentry->d_name.len,
467 .sattr = sattr
468 };
469 struct nfs_diropok res = {
470 .fh = &fhandle,
471 .fattr = &fattr
472 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500473 struct rpc_message msg = {
474 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
475 .rpc_argp = &arg,
476 .rpc_resp = &res,
477 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 int status;
479
480 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400481 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500482 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400483 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (status == 0)
485 status = nfs_instantiate(dentry, &fhandle, &fattr);
486 dprintk("NFS reply mkdir: %d\n", status);
487 return status;
488}
489
490static int
491nfs_proc_rmdir(struct inode *dir, struct qstr *name)
492{
493 struct nfs_diropargs arg = {
494 .fh = NFS_FH(dir),
495 .name = name->name,
496 .len = name->len
497 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500498 struct rpc_message msg = {
499 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
500 .rpc_argp = &arg,
501 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 int status;
503
504 dprintk("NFS call rmdir %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500505 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400506 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 dprintk("NFS reply rmdir: %d\n", status);
508 return status;
509}
510
511/*
512 * The READDIR implementation is somewhat hackish - we pass a temporary
513 * buffer to the encode function, which installs it in the receive
514 * the receive iovec. The decode function just parses the reply to make
515 * sure it is syntactically correct; the entries itself are decoded
516 * from nfs_readdir by calling the decode_entry function directly.
517 */
518static int
519nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
520 u64 cookie, struct page *page, unsigned int count, int plus)
521{
522 struct inode *dir = dentry->d_inode;
523 struct nfs_readdirargs arg = {
524 .fh = NFS_FH(dir),
525 .cookie = cookie,
526 .count = count,
Chuck Leverdead28d2006-03-20 13:44:23 -0500527 .pages = &page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 };
529 struct rpc_message msg = {
530 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
531 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500532 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 };
534 int status;
535
536 lock_kernel();
537
538 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
539 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
540
541 dprintk("NFS reply readdir: %d\n", status);
542 unlock_kernel();
543 return status;
544}
545
546static int
547nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
548 struct nfs_fsstat *stat)
549{
550 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500551 struct rpc_message msg = {
552 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
553 .rpc_argp = fhandle,
554 .rpc_resp = &fsinfo,
555 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 int status;
557
558 dprintk("NFS call statfs\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400559 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500560 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 dprintk("NFS reply statfs: %d\n", status);
562 if (status)
563 goto out;
564 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
565 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
566 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
567 stat->tfiles = 0;
568 stat->ffiles = 0;
569 stat->afiles = 0;
570out:
571 return status;
572}
573
574static int
575nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
576 struct nfs_fsinfo *info)
577{
578 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500579 struct rpc_message msg = {
580 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
581 .rpc_argp = fhandle,
582 .rpc_resp = &fsinfo,
583 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 int status;
585
586 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400587 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500588 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 dprintk("NFS reply fsinfo: %d\n", status);
590 if (status)
591 goto out;
592 info->rtmax = NFS_MAXDATA;
593 info->rtpref = fsinfo.tsize;
594 info->rtmult = fsinfo.bsize;
595 info->wtmax = NFS_MAXDATA;
596 info->wtpref = fsinfo.tsize;
597 info->wtmult = fsinfo.bsize;
598 info->dtpref = fsinfo.tsize;
599 info->maxfilesize = 0x7FFFFFFF;
600 info->lease_time = 0;
601out:
602 return status;
603}
604
605static int
606nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
607 struct nfs_pathconf *info)
608{
609 info->max_link = 0;
610 info->max_namelen = NFS2_MAXNAMLEN;
611 return 0;
612}
613
614extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
615
Trond Myklebustec06c092006-03-20 13:44:27 -0500616static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 if (task->tk_status >= 0) {
619 nfs_refresh_inode(data->inode, data->res.fattr);
620 /* Emulate the eof flag, which isn't normally needed in NFSv2
621 * as it is guaranteed to always return the file attributes
622 */
623 if (data->args.offset + data->args.count >= data->res.fattr->size)
624 data->res.eof = 1;
625 }
Trond Myklebustec06c092006-03-20 13:44:27 -0500626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Trond Myklebustec06c092006-03-20 13:44:27 -0500629static void nfs_proc_read_setup(struct nfs_read_data *data)
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_READ],
633 .rpc_argp = &data->args,
634 .rpc_resp = &data->res,
635 .rpc_cred = data->cred,
636 };
637
Trond Myklebustec06c092006-03-20 13:44:27 -0500638 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
Trond Myklebust788e7a82006-03-20 13:44:27 -0500641static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (task->tk_status >= 0)
Trond Myklebustdecf4912005-10-27 22:12:39 -0400644 nfs_post_op_update_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
Trond Myklebust788e7a82006-03-20 13:44:27 -0500648static void nfs_proc_write_setup(struct nfs_write_data *data, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 struct rpc_message msg = {
651 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
652 .rpc_argp = &data->args,
653 .rpc_resp = &data->res,
654 .rpc_cred = data->cred,
655 };
656
657 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
658 data->args.stable = NFS_FILE_SYNC;
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 /* Finalize the task. */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500661 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
664static void
665nfs_proc_commit_setup(struct nfs_write_data *data, int how)
666{
667 BUG();
668}
669
670static int
671nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
672{
673 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
674}
675
676
677struct nfs_rpc_ops nfs_v2_clientops = {
678 .version = 2, /* protocol version */
679 .dentry_ops = &nfs_dentry_operations,
680 .dir_inode_ops = &nfs_dir_inode_operations,
J. Bruce Fields92cfc622005-06-22 17:16:22 +0000681 .file_inode_ops = &nfs_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .getroot = nfs_proc_get_root,
683 .getattr = nfs_proc_getattr,
684 .setattr = nfs_proc_setattr,
685 .lookup = nfs_proc_lookup,
686 .access = NULL, /* access */
687 .readlink = nfs_proc_readlink,
688 .read = nfs_proc_read,
689 .write = nfs_proc_write,
690 .commit = NULL, /* commit */
691 .create = nfs_proc_create,
692 .remove = nfs_proc_remove,
693 .unlink_setup = nfs_proc_unlink_setup,
694 .unlink_done = nfs_proc_unlink_done,
695 .rename = nfs_proc_rename,
696 .link = nfs_proc_link,
697 .symlink = nfs_proc_symlink,
698 .mkdir = nfs_proc_mkdir,
699 .rmdir = nfs_proc_rmdir,
700 .readdir = nfs_proc_readdir,
701 .mknod = nfs_proc_mknod,
702 .statfs = nfs_proc_statfs,
703 .fsinfo = nfs_proc_fsinfo,
704 .pathconf = nfs_proc_pathconf,
705 .decode_dirent = nfs_decode_dirent,
706 .read_setup = nfs_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500707 .read_done = nfs_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .write_setup = nfs_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500709 .write_done = nfs_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .commit_setup = nfs_proc_commit_setup,
711 .file_open = nfs_open,
712 .file_release = nfs_release,
713 .lock = nfs_proc_lock,
714};