blob: 7be0ee2782cb6395c41eab8818935af27c1916ee [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>
David Howellsf7b422b2006-06-09 09:34:33 -040046#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#define NFSDBG_FACILITY NFSDBG_PROC
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/*
51 * Bare-bones access to getattr: this is for nfs_read_super.
52 */
53static int
54nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
55 struct nfs_fsinfo *info)
56{
57 struct nfs_fattr *fattr = info->fattr;
58 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -050059 struct rpc_message msg = {
60 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
61 .rpc_argp = fhandle,
62 .rpc_resp = fattr,
63 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int status;
65
66 dprintk("%s: call getattr\n", __FUNCTION__);
Trond Myklebust0e574af2005-10-27 22:12:38 -040067 nfs_fattr_init(fattr);
David Howells5006a762006-08-22 20:06:12 -040068 status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
70 if (status)
71 return status;
72 dprintk("%s: call statfs\n", __FUNCTION__);
Chuck Leverdead28d2006-03-20 13:44:23 -050073 msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
74 msg.rpc_resp = &fsinfo;
David Howells5006a762006-08-22 20:06:12 -040075 status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 dprintk("%s: reply statfs: %d\n", __FUNCTION__, status);
77 if (status)
78 return status;
79 info->rtmax = NFS_MAXDATA;
80 info->rtpref = fsinfo.tsize;
81 info->rtmult = fsinfo.bsize;
82 info->wtmax = NFS_MAXDATA;
83 info->wtpref = fsinfo.tsize;
84 info->wtmult = fsinfo.bsize;
85 info->dtpref = fsinfo.tsize;
86 info->maxfilesize = 0x7FFFFFFF;
87 info->lease_time = 0;
88 return 0;
89}
90
91/*
92 * One function for each procedure in the NFS protocol.
93 */
94static int
95nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
96 struct nfs_fattr *fattr)
97{
Chuck Leverdead28d2006-03-20 13:44:23 -050098 struct rpc_message msg = {
99 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
100 .rpc_argp = fhandle,
101 .rpc_resp = fattr,
102 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 int status;
104
105 dprintk("NFS call getattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400106 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500107 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 dprintk("NFS reply getattr: %d\n", status);
109 return status;
110}
111
112static int
113nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
114 struct iattr *sattr)
115{
116 struct inode *inode = dentry->d_inode;
117 struct nfs_sattrargs arg = {
118 .fh = NFS_FH(inode),
119 .sattr = sattr
120 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500121 struct rpc_message msg = {
122 .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
123 .rpc_argp = &arg,
124 .rpc_resp = fattr,
125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 int status;
127
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100128 /* Mask out the non-modebit related stuff from attr->ia_mode */
129 sattr->ia_mode &= S_IALLUGO;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 dprintk("NFS call setattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400132 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500133 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust65e43082005-08-16 11:49:44 -0400134 if (status == 0)
135 nfs_setattr_update_inode(inode, sattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 dprintk("NFS reply setattr: %d\n", status);
137 return status;
138}
139
140static int
141nfs_proc_lookup(struct inode *dir, struct qstr *name,
142 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
143{
144 struct nfs_diropargs arg = {
145 .fh = NFS_FH(dir),
146 .name = name->name,
147 .len = name->len
148 };
149 struct nfs_diropok res = {
150 .fh = fhandle,
151 .fattr = fattr
152 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500153 struct rpc_message msg = {
154 .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
155 .rpc_argp = &arg,
156 .rpc_resp = &res,
157 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int status;
159
160 dprintk("NFS call lookup %s\n", name->name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400161 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500162 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 dprintk("NFS reply lookup: %d\n", status);
164 return status;
165}
166
167static int nfs_proc_readlink(struct inode *inode, struct page *page,
168 unsigned int pgbase, unsigned int pglen)
169{
170 struct nfs_readlinkargs args = {
171 .fh = NFS_FH(inode),
172 .pgbase = pgbase,
173 .pglen = pglen,
174 .pages = &page
175 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500176 struct rpc_message msg = {
177 .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
178 .rpc_argp = &args,
179 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int status;
181
182 dprintk("NFS call readlink\n");
Chuck Leverdead28d2006-03-20 13:44:23 -0500183 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 dprintk("NFS reply readlink: %d\n", status);
185 return status;
186}
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static int
189nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -0700190 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 struct nfs_fh fhandle;
193 struct nfs_fattr fattr;
194 struct nfs_createargs arg = {
195 .fh = NFS_FH(dir),
196 .name = dentry->d_name.name,
197 .len = dentry->d_name.len,
198 .sattr = sattr
199 };
200 struct nfs_diropok res = {
201 .fh = &fhandle,
202 .fattr = &fattr
203 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500204 struct rpc_message msg = {
205 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
206 .rpc_argp = &arg,
207 .rpc_resp = &res,
208 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 int status;
210
Trond Myklebust0e574af2005-10-27 22:12:38 -0400211 nfs_fattr_init(&fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 dprintk("NFS call create %s\n", dentry->d_name.name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500213 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (status == 0)
215 status = nfs_instantiate(dentry, &fhandle, &fattr);
216 dprintk("NFS reply create: %d\n", status);
217 return status;
218}
219
220/*
221 * In NFSv2, mknod is grafted onto the create call.
222 */
223static int
224nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
225 dev_t rdev)
226{
227 struct nfs_fh fhandle;
228 struct nfs_fattr fattr;
229 struct nfs_createargs arg = {
230 .fh = NFS_FH(dir),
231 .name = dentry->d_name.name,
232 .len = dentry->d_name.len,
233 .sattr = sattr
234 };
235 struct nfs_diropok res = {
236 .fh = &fhandle,
237 .fattr = &fattr
238 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500239 struct rpc_message msg = {
240 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
241 .rpc_argp = &arg,
242 .rpc_resp = &res,
243 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 int status, mode;
245
246 dprintk("NFS call mknod %s\n", dentry->d_name.name);
247
248 mode = sattr->ia_mode;
249 if (S_ISFIFO(mode)) {
250 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
251 sattr->ia_valid &= ~ATTR_SIZE;
252 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
253 sattr->ia_valid |= ATTR_SIZE;
254 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
255 }
256
Trond Myklebust0e574af2005-10-27 22:12:38 -0400257 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500258 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400259 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 if (status == -EINVAL && S_ISFIFO(mode)) {
262 sattr->ia_mode = mode;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400263 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500264 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 }
266 if (status == 0)
267 status = nfs_instantiate(dentry, &fhandle, &fattr);
268 dprintk("NFS reply mknod: %d\n", status);
269 return status;
270}
271
272static int
273nfs_proc_remove(struct inode *dir, struct qstr *name)
274{
275 struct nfs_diropargs arg = {
276 .fh = NFS_FH(dir),
277 .name = name->name,
278 .len = name->len
279 };
280 struct rpc_message msg = {
281 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
282 .rpc_argp = &arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 };
284 int status;
285
286 dprintk("NFS call remove %s\n", name->name);
287 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400288 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 dprintk("NFS reply remove: %d\n", status);
291 return status;
292}
293
294static int
295nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
296{
297 struct nfs_diropargs *arg;
298
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700299 arg = kmalloc(sizeof(*arg), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (!arg)
301 return -ENOMEM;
302 arg->fh = NFS_FH(dir->d_inode);
303 arg->name = name->name;
304 arg->len = name->len;
305 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
306 msg->rpc_argp = arg;
307 return 0;
308}
309
310static int
311nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
312{
313 struct rpc_message *msg = &task->tk_msg;
314
Trond Myklebustdecf4912005-10-27 22:12:39 -0400315 if (msg->rpc_argp) {
316 nfs_mark_for_revalidate(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 kfree(msg->rpc_argp);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return 0;
320}
321
322static int
323nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
324 struct inode *new_dir, struct qstr *new_name)
325{
326 struct nfs_renameargs arg = {
327 .fromfh = NFS_FH(old_dir),
328 .fromname = old_name->name,
329 .fromlen = old_name->len,
330 .tofh = NFS_FH(new_dir),
331 .toname = new_name->name,
332 .tolen = new_name->len
333 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500334 struct rpc_message msg = {
335 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
336 .rpc_argp = &arg,
337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 int status;
339
340 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500341 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400342 nfs_mark_for_revalidate(old_dir);
343 nfs_mark_for_revalidate(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 dprintk("NFS reply rename: %d\n", status);
345 return status;
346}
347
348static int
349nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
350{
351 struct nfs_linkargs arg = {
352 .fromfh = NFS_FH(inode),
353 .tofh = NFS_FH(dir),
354 .toname = name->name,
355 .tolen = name->len
356 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500357 struct rpc_message msg = {
358 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
359 .rpc_argp = &arg,
360 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 int status;
362
363 dprintk("NFS call link %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500364 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust5ba7cc42005-12-03 15:20:17 -0500365 nfs_mark_for_revalidate(inode);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400366 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 dprintk("NFS reply link: %d\n", status);
368 return status;
369}
370
371static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400372nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
373 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Chuck Lever4f390c12006-08-22 20:06:22 -0400375 struct nfs_fh fhandle;
376 struct nfs_fattr fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 struct nfs_symlinkargs arg = {
378 .fromfh = NFS_FH(dir),
Chuck Lever4f390c12006-08-22 20:06:22 -0400379 .fromname = dentry->d_name.name,
380 .fromlen = dentry->d_name.len,
Chuck Lever94a6d752006-08-22 20:06:23 -0400381 .pages = &page,
382 .pathlen = len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 .sattr = sattr
384 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500385 struct rpc_message msg = {
386 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
387 .rpc_argp = &arg,
388 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 int status;
390
Chuck Lever94a6d752006-08-22 20:06:23 -0400391 if (len > NFS2_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400393
Chuck Lever94a6d752006-08-22 20:06:23 -0400394 dprintk("NFS call symlink %s\n", dentry->d_name.name);
395
Chuck Leverdead28d2006-03-20 13:44:23 -0500396 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400397 nfs_mark_for_revalidate(dir);
Chuck Lever4f390c12006-08-22 20:06:22 -0400398
399 /*
400 * V2 SYMLINK requests don't return any attributes. Setting the
401 * filehandle size to zero indicates to nfs_instantiate that it
402 * should fill in the data with a LOOKUP call on the wire.
403 */
404 if (status == 0) {
405 nfs_fattr_init(&fattr);
406 fhandle.size = 0;
407 status = nfs_instantiate(dentry, &fhandle, &fattr);
408 }
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 dprintk("NFS reply symlink: %d\n", status);
411 return status;
412}
413
414static int
415nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
416{
417 struct nfs_fh fhandle;
418 struct nfs_fattr fattr;
419 struct nfs_createargs arg = {
420 .fh = NFS_FH(dir),
421 .name = dentry->d_name.name,
422 .len = dentry->d_name.len,
423 .sattr = sattr
424 };
425 struct nfs_diropok res = {
426 .fh = &fhandle,
427 .fattr = &fattr
428 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500429 struct rpc_message msg = {
430 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
431 .rpc_argp = &arg,
432 .rpc_resp = &res,
433 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 int status;
435
436 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400437 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500438 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400439 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 if (status == 0)
441 status = nfs_instantiate(dentry, &fhandle, &fattr);
442 dprintk("NFS reply mkdir: %d\n", status);
443 return status;
444}
445
446static int
447nfs_proc_rmdir(struct inode *dir, struct qstr *name)
448{
449 struct nfs_diropargs arg = {
450 .fh = NFS_FH(dir),
451 .name = name->name,
452 .len = name->len
453 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500454 struct rpc_message msg = {
455 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
456 .rpc_argp = &arg,
457 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 int status;
459
460 dprintk("NFS call rmdir %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500461 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400462 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 dprintk("NFS reply rmdir: %d\n", status);
464 return status;
465}
466
467/*
468 * The READDIR implementation is somewhat hackish - we pass a temporary
469 * buffer to the encode function, which installs it in the receive
470 * the receive iovec. The decode function just parses the reply to make
471 * sure it is syntactically correct; the entries itself are decoded
472 * from nfs_readdir by calling the decode_entry function directly.
473 */
474static int
475nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
476 u64 cookie, struct page *page, unsigned int count, int plus)
477{
478 struct inode *dir = dentry->d_inode;
479 struct nfs_readdirargs arg = {
480 .fh = NFS_FH(dir),
481 .cookie = cookie,
482 .count = count,
Chuck Leverdead28d2006-03-20 13:44:23 -0500483 .pages = &page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 };
485 struct rpc_message msg = {
486 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
487 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500488 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 };
490 int status;
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
493 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
494
495 dprintk("NFS reply readdir: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return status;
497}
498
499static int
500nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
501 struct nfs_fsstat *stat)
502{
503 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500504 struct rpc_message msg = {
505 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
506 .rpc_argp = fhandle,
507 .rpc_resp = &fsinfo,
508 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 int status;
510
511 dprintk("NFS call statfs\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400512 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500513 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 dprintk("NFS reply statfs: %d\n", status);
515 if (status)
516 goto out;
517 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
518 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
519 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
520 stat->tfiles = 0;
521 stat->ffiles = 0;
522 stat->afiles = 0;
523out:
524 return status;
525}
526
527static int
528nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
529 struct nfs_fsinfo *info)
530{
531 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500532 struct rpc_message msg = {
533 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
534 .rpc_argp = fhandle,
535 .rpc_resp = &fsinfo,
536 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 int status;
538
539 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400540 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500541 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 dprintk("NFS reply fsinfo: %d\n", status);
543 if (status)
544 goto out;
545 info->rtmax = NFS_MAXDATA;
546 info->rtpref = fsinfo.tsize;
547 info->rtmult = fsinfo.bsize;
548 info->wtmax = NFS_MAXDATA;
549 info->wtpref = fsinfo.tsize;
550 info->wtmult = fsinfo.bsize;
551 info->dtpref = fsinfo.tsize;
552 info->maxfilesize = 0x7FFFFFFF;
553 info->lease_time = 0;
554out:
555 return status;
556}
557
558static int
559nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
560 struct nfs_pathconf *info)
561{
562 info->max_link = 0;
563 info->max_namelen = NFS2_MAXNAMLEN;
564 return 0;
565}
566
Trond Myklebustec06c092006-03-20 13:44:27 -0500567static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (task->tk_status >= 0) {
570 nfs_refresh_inode(data->inode, data->res.fattr);
571 /* Emulate the eof flag, which isn't normally needed in NFSv2
572 * as it is guaranteed to always return the file attributes
573 */
574 if (data->args.offset + data->args.count >= data->res.fattr->size)
575 data->res.eof = 1;
576 }
Trond Myklebustec06c092006-03-20 13:44:27 -0500577 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
Trond Myklebustec06c092006-03-20 13:44:27 -0500580static void nfs_proc_read_setup(struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 struct rpc_message msg = {
583 .rpc_proc = &nfs_procedures[NFSPROC_READ],
584 .rpc_argp = &data->args,
585 .rpc_resp = &data->res,
586 .rpc_cred = data->cred,
587 };
588
Trond Myklebustec06c092006-03-20 13:44:27 -0500589 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
Trond Myklebust788e7a82006-03-20 13:44:27 -0500592static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (task->tk_status >= 0)
Trond Myklebustdecf4912005-10-27 22:12:39 -0400595 nfs_post_op_update_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500596 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Trond Myklebust788e7a82006-03-20 13:44:27 -0500599static void nfs_proc_write_setup(struct nfs_write_data *data, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 struct rpc_message msg = {
602 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
603 .rpc_argp = &data->args,
604 .rpc_resp = &data->res,
605 .rpc_cred = data->cred,
606 };
607
608 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
609 data->args.stable = NFS_FILE_SYNC;
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 /* Finalize the task. */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500612 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613}
614
615static void
616nfs_proc_commit_setup(struct nfs_write_data *data, int how)
617{
618 BUG();
619}
620
621static int
622nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
623{
Josef "Jeff" Sipek01cce932006-12-08 02:36:40 -0800624 return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
627
David Howells509de812006-08-22 20:06:11 -0400628const struct nfs_rpc_ops nfs_v2_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .version = 2, /* protocol version */
630 .dentry_ops = &nfs_dentry_operations,
631 .dir_inode_ops = &nfs_dir_inode_operations,
J. Bruce Fields92cfc622005-06-22 17:16:22 +0000632 .file_inode_ops = &nfs_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .getroot = nfs_proc_get_root,
634 .getattr = nfs_proc_getattr,
635 .setattr = nfs_proc_setattr,
636 .lookup = nfs_proc_lookup,
637 .access = NULL, /* access */
638 .readlink = nfs_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .create = nfs_proc_create,
640 .remove = nfs_proc_remove,
641 .unlink_setup = nfs_proc_unlink_setup,
642 .unlink_done = nfs_proc_unlink_done,
643 .rename = nfs_proc_rename,
644 .link = nfs_proc_link,
645 .symlink = nfs_proc_symlink,
646 .mkdir = nfs_proc_mkdir,
647 .rmdir = nfs_proc_rmdir,
648 .readdir = nfs_proc_readdir,
649 .mknod = nfs_proc_mknod,
650 .statfs = nfs_proc_statfs,
651 .fsinfo = nfs_proc_fsinfo,
652 .pathconf = nfs_proc_pathconf,
653 .decode_dirent = nfs_decode_dirent,
654 .read_setup = nfs_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500655 .read_done = nfs_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .write_setup = nfs_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500657 .write_done = nfs_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .commit_setup = nfs_proc_commit_setup,
659 .file_open = nfs_open,
660 .file_release = nfs_release,
661 .lock = nfs_proc_lock,
662};