blob: 630e50647bbbf02c90611f4ba7d63da613ebaccc [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
218static int nfs_proc_write(struct nfs_write_data *wdata)
219{
220 int flags = wdata->flags;
221 struct inode * inode = wdata->inode;
222 struct nfs_fattr * fattr = wdata->res.fattr;
223 struct rpc_message msg = {
224 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
225 .rpc_argp = &wdata->args,
226 .rpc_resp = &wdata->res,
227 .rpc_cred = wdata->cred,
228 };
229 int status;
230
231 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
232 (long long) wdata->args.offset);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400233 nfs_fattr_init(fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
235 if (status >= 0) {
Trond Myklebustdecf4912005-10-27 22:12:39 -0400236 nfs_post_op_update_inode(inode, fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 wdata->res.count = wdata->args.count;
238 wdata->verf.committed = NFS_FILE_SYNC;
239 }
240 dprintk("NFS reply write: %d\n", status);
241 return status < 0? status : wdata->res.count;
242}
243
244static int
245nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Trond Myklebust02a913a2005-10-18 14:20:17 -0700246 int flags, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 struct nfs_fh fhandle;
249 struct nfs_fattr fattr;
250 struct nfs_createargs arg = {
251 .fh = NFS_FH(dir),
252 .name = dentry->d_name.name,
253 .len = dentry->d_name.len,
254 .sattr = sattr
255 };
256 struct nfs_diropok res = {
257 .fh = &fhandle,
258 .fattr = &fattr
259 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500260 struct rpc_message msg = {
261 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
262 .rpc_argp = &arg,
263 .rpc_resp = &res,
264 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 int status;
266
Trond Myklebust0e574af2005-10-27 22:12:38 -0400267 nfs_fattr_init(&fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 dprintk("NFS call create %s\n", dentry->d_name.name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500269 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (status == 0)
271 status = nfs_instantiate(dentry, &fhandle, &fattr);
272 dprintk("NFS reply create: %d\n", status);
273 return status;
274}
275
276/*
277 * In NFSv2, mknod is grafted onto the create call.
278 */
279static int
280nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
281 dev_t rdev)
282{
283 struct nfs_fh fhandle;
284 struct nfs_fattr fattr;
285 struct nfs_createargs arg = {
286 .fh = NFS_FH(dir),
287 .name = dentry->d_name.name,
288 .len = dentry->d_name.len,
289 .sattr = sattr
290 };
291 struct nfs_diropok res = {
292 .fh = &fhandle,
293 .fattr = &fattr
294 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500295 struct rpc_message msg = {
296 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
297 .rpc_argp = &arg,
298 .rpc_resp = &res,
299 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 int status, mode;
301
302 dprintk("NFS call mknod %s\n", dentry->d_name.name);
303
304 mode = sattr->ia_mode;
305 if (S_ISFIFO(mode)) {
306 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
307 sattr->ia_valid &= ~ATTR_SIZE;
308 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
309 sattr->ia_valid |= ATTR_SIZE;
310 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
311 }
312
Trond Myklebust0e574af2005-10-27 22:12:38 -0400313 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500314 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400315 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 if (status == -EINVAL && S_ISFIFO(mode)) {
318 sattr->ia_mode = mode;
Trond Myklebust0e574af2005-10-27 22:12:38 -0400319 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500320 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322 if (status == 0)
323 status = nfs_instantiate(dentry, &fhandle, &fattr);
324 dprintk("NFS reply mknod: %d\n", status);
325 return status;
326}
327
328static int
329nfs_proc_remove(struct inode *dir, struct qstr *name)
330{
331 struct nfs_diropargs arg = {
332 .fh = NFS_FH(dir),
333 .name = name->name,
334 .len = name->len
335 };
336 struct rpc_message msg = {
337 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
338 .rpc_argp = &arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 };
340 int status;
341
342 dprintk("NFS call remove %s\n", name->name);
343 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400344 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 dprintk("NFS reply remove: %d\n", status);
347 return status;
348}
349
350static int
351nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
352{
353 struct nfs_diropargs *arg;
354
355 arg = (struct nfs_diropargs *)kmalloc(sizeof(*arg), GFP_KERNEL);
356 if (!arg)
357 return -ENOMEM;
358 arg->fh = NFS_FH(dir->d_inode);
359 arg->name = name->name;
360 arg->len = name->len;
361 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
362 msg->rpc_argp = arg;
363 return 0;
364}
365
366static int
367nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
368{
369 struct rpc_message *msg = &task->tk_msg;
370
Trond Myklebustdecf4912005-10-27 22:12:39 -0400371 if (msg->rpc_argp) {
372 nfs_mark_for_revalidate(dir->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 kfree(msg->rpc_argp);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return 0;
376}
377
378static int
379nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
380 struct inode *new_dir, struct qstr *new_name)
381{
382 struct nfs_renameargs arg = {
383 .fromfh = NFS_FH(old_dir),
384 .fromname = old_name->name,
385 .fromlen = old_name->len,
386 .tofh = NFS_FH(new_dir),
387 .toname = new_name->name,
388 .tolen = new_name->len
389 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500390 struct rpc_message msg = {
391 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
392 .rpc_argp = &arg,
393 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 int status;
395
396 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500397 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400398 nfs_mark_for_revalidate(old_dir);
399 nfs_mark_for_revalidate(new_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 dprintk("NFS reply rename: %d\n", status);
401 return status;
402}
403
404static int
405nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
406{
407 struct nfs_linkargs arg = {
408 .fromfh = NFS_FH(inode),
409 .tofh = NFS_FH(dir),
410 .toname = name->name,
411 .tolen = name->len
412 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500413 struct rpc_message msg = {
414 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
415 .rpc_argp = &arg,
416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 int status;
418
419 dprintk("NFS call link %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500420 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust5ba7cc42005-12-03 15:20:17 -0500421 nfs_mark_for_revalidate(inode);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400422 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 dprintk("NFS reply link: %d\n", status);
424 return status;
425}
426
427static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400428nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
429 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Chuck Lever4f390c12006-08-22 20:06:22 -0400431 struct nfs_fh fhandle;
432 struct nfs_fattr fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 struct nfs_symlinkargs arg = {
434 .fromfh = NFS_FH(dir),
Chuck Lever4f390c12006-08-22 20:06:22 -0400435 .fromname = dentry->d_name.name,
436 .fromlen = dentry->d_name.len,
Chuck Lever94a6d752006-08-22 20:06:23 -0400437 .pages = &page,
438 .pathlen = len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .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
Chuck Lever94a6d752006-08-22 20:06:23 -0400447 if (len > NFS2_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400449
Chuck Lever94a6d752006-08-22 20:06:23 -0400450 dprintk("NFS call symlink %s\n", dentry->d_name.name);
451
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);
Chuck Lever4f390c12006-08-22 20:06:22 -0400454
455 /*
456 * V2 SYMLINK requests don't return any attributes. Setting the
457 * filehandle size to zero indicates to nfs_instantiate that it
458 * should fill in the data with a LOOKUP call on the wire.
459 */
460 if (status == 0) {
461 nfs_fattr_init(&fattr);
462 fhandle.size = 0;
463 status = nfs_instantiate(dentry, &fhandle, &fattr);
464 }
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 dprintk("NFS reply symlink: %d\n", status);
467 return status;
468}
469
470static int
471nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
472{
473 struct nfs_fh fhandle;
474 struct nfs_fattr fattr;
475 struct nfs_createargs arg = {
476 .fh = NFS_FH(dir),
477 .name = dentry->d_name.name,
478 .len = dentry->d_name.len,
479 .sattr = sattr
480 };
481 struct nfs_diropok res = {
482 .fh = &fhandle,
483 .fattr = &fattr
484 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500485 struct rpc_message msg = {
486 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
487 .rpc_argp = &arg,
488 .rpc_resp = &res,
489 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 int status;
491
492 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400493 nfs_fattr_init(&fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500494 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400495 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (status == 0)
497 status = nfs_instantiate(dentry, &fhandle, &fattr);
498 dprintk("NFS reply mkdir: %d\n", status);
499 return status;
500}
501
502static int
503nfs_proc_rmdir(struct inode *dir, struct qstr *name)
504{
505 struct nfs_diropargs arg = {
506 .fh = NFS_FH(dir),
507 .name = name->name,
508 .len = name->len
509 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500510 struct rpc_message msg = {
511 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
512 .rpc_argp = &arg,
513 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 int status;
515
516 dprintk("NFS call rmdir %s\n", name->name);
Chuck Leverdead28d2006-03-20 13:44:23 -0500517 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustdecf4912005-10-27 22:12:39 -0400518 nfs_mark_for_revalidate(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 dprintk("NFS reply rmdir: %d\n", status);
520 return status;
521}
522
523/*
524 * The READDIR implementation is somewhat hackish - we pass a temporary
525 * buffer to the encode function, which installs it in the receive
526 * the receive iovec. The decode function just parses the reply to make
527 * sure it is syntactically correct; the entries itself are decoded
528 * from nfs_readdir by calling the decode_entry function directly.
529 */
530static int
531nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
532 u64 cookie, struct page *page, unsigned int count, int plus)
533{
534 struct inode *dir = dentry->d_inode;
535 struct nfs_readdirargs arg = {
536 .fh = NFS_FH(dir),
537 .cookie = cookie,
538 .count = count,
Chuck Leverdead28d2006-03-20 13:44:23 -0500539 .pages = &page,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 };
541 struct rpc_message msg = {
542 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
543 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500544 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 };
546 int status;
547
548 lock_kernel();
549
550 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
551 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
552
553 dprintk("NFS reply readdir: %d\n", status);
554 unlock_kernel();
555 return status;
556}
557
558static int
559nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
560 struct nfs_fsstat *stat)
561{
562 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500563 struct rpc_message msg = {
564 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
565 .rpc_argp = fhandle,
566 .rpc_resp = &fsinfo,
567 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 int status;
569
570 dprintk("NFS call statfs\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400571 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500572 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 dprintk("NFS reply statfs: %d\n", status);
574 if (status)
575 goto out;
576 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
577 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
578 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
579 stat->tfiles = 0;
580 stat->ffiles = 0;
581 stat->afiles = 0;
582out:
583 return status;
584}
585
586static int
587nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
588 struct nfs_fsinfo *info)
589{
590 struct nfs2_fsstat fsinfo;
Chuck Leverdead28d2006-03-20 13:44:23 -0500591 struct rpc_message msg = {
592 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
593 .rpc_argp = fhandle,
594 .rpc_resp = &fsinfo,
595 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 int status;
597
598 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400599 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500600 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 dprintk("NFS reply fsinfo: %d\n", status);
602 if (status)
603 goto out;
604 info->rtmax = NFS_MAXDATA;
605 info->rtpref = fsinfo.tsize;
606 info->rtmult = fsinfo.bsize;
607 info->wtmax = NFS_MAXDATA;
608 info->wtpref = fsinfo.tsize;
609 info->wtmult = fsinfo.bsize;
610 info->dtpref = fsinfo.tsize;
611 info->maxfilesize = 0x7FFFFFFF;
612 info->lease_time = 0;
613out:
614 return status;
615}
616
617static int
618nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
619 struct nfs_pathconf *info)
620{
621 info->max_link = 0;
622 info->max_namelen = NFS2_MAXNAMLEN;
623 return 0;
624}
625
Trond Myklebustec06c092006-03-20 13:44:27 -0500626static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (task->tk_status >= 0) {
629 nfs_refresh_inode(data->inode, data->res.fattr);
630 /* Emulate the eof flag, which isn't normally needed in NFSv2
631 * as it is guaranteed to always return the file attributes
632 */
633 if (data->args.offset + data->args.count >= data->res.fattr->size)
634 data->res.eof = 1;
635 }
Trond Myklebustec06c092006-03-20 13:44:27 -0500636 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637}
638
Trond Myklebustec06c092006-03-20 13:44:27 -0500639static void nfs_proc_read_setup(struct nfs_read_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct rpc_message msg = {
642 .rpc_proc = &nfs_procedures[NFSPROC_READ],
643 .rpc_argp = &data->args,
644 .rpc_resp = &data->res,
645 .rpc_cred = data->cred,
646 };
647
Trond Myklebustec06c092006-03-20 13:44:27 -0500648 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Trond Myklebust788e7a82006-03-20 13:44:27 -0500651static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (task->tk_status >= 0)
Trond Myklebustdecf4912005-10-27 22:12:39 -0400654 nfs_post_op_update_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500655 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
657
Trond Myklebust788e7a82006-03-20 13:44:27 -0500658static void nfs_proc_write_setup(struct nfs_write_data *data, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 struct rpc_message msg = {
661 .rpc_proc = &nfs_procedures[NFSPROC_WRITE],
662 .rpc_argp = &data->args,
663 .rpc_resp = &data->res,
664 .rpc_cred = data->cred,
665 };
666
667 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
668 data->args.stable = NFS_FILE_SYNC;
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* Finalize the task. */
Trond Myklebust788e7a82006-03-20 13:44:27 -0500671 rpc_call_setup(&data->task, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674static void
675nfs_proc_commit_setup(struct nfs_write_data *data, int how)
676{
677 BUG();
678}
679
680static int
681nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
682{
683 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
684}
685
686
David Howells509de812006-08-22 20:06:11 -0400687const struct nfs_rpc_ops nfs_v2_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .version = 2, /* protocol version */
689 .dentry_ops = &nfs_dentry_operations,
690 .dir_inode_ops = &nfs_dir_inode_operations,
J. Bruce Fields92cfc622005-06-22 17:16:22 +0000691 .file_inode_ops = &nfs_file_inode_operations,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 .getroot = nfs_proc_get_root,
693 .getattr = nfs_proc_getattr,
694 .setattr = nfs_proc_setattr,
695 .lookup = nfs_proc_lookup,
696 .access = NULL, /* access */
697 .readlink = nfs_proc_readlink,
698 .read = nfs_proc_read,
699 .write = nfs_proc_write,
700 .commit = NULL, /* commit */
701 .create = nfs_proc_create,
702 .remove = nfs_proc_remove,
703 .unlink_setup = nfs_proc_unlink_setup,
704 .unlink_done = nfs_proc_unlink_done,
705 .rename = nfs_proc_rename,
706 .link = nfs_proc_link,
707 .symlink = nfs_proc_symlink,
708 .mkdir = nfs_proc_mkdir,
709 .rmdir = nfs_proc_rmdir,
710 .readdir = nfs_proc_readdir,
711 .mknod = nfs_proc_mknod,
712 .statfs = nfs_proc_statfs,
713 .fsinfo = nfs_proc_fsinfo,
714 .pathconf = nfs_proc_pathconf,
715 .decode_dirent = nfs_decode_dirent,
716 .read_setup = nfs_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500717 .read_done = nfs_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .write_setup = nfs_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500719 .write_done = nfs_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .commit_setup = nfs_proc_commit_setup,
721 .file_open = nfs_open,
722 .file_release = nfs_release,
723 .lock = nfs_proc_lock,
724};