xref: /openbmc/linux/fs/nfs/proc.c (revision dead28da)
1 /*
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 
50 extern struct rpc_procinfo nfs_procedures[];
51 
52 /*
53  * Bare-bones access to getattr: this is for nfs_read_super.
54  */
55 static int
56 nfs_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;
61 	struct rpc_message msg = {
62 		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],
63 		.rpc_argp	= fhandle,
64 		.rpc_resp	= fattr,
65 	};
66 	int status;
67 
68 	dprintk("%s: call getattr\n", __FUNCTION__);
69 	nfs_fattr_init(fattr);
70 	status = rpc_call_sync(server->client_sys, &msg, 0);
71 	dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
72 	if (status)
73 		return status;
74 	dprintk("%s: call statfs\n", __FUNCTION__);
75 	msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
76 	msg.rpc_resp = &fsinfo;
77 	status = rpc_call_sync(server->client_sys, &msg, 0);
78 	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  */
96 static int
97 nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
98 		struct nfs_fattr *fattr)
99 {
100 	struct rpc_message msg = {
101 		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],
102 		.rpc_argp	= fhandle,
103 		.rpc_resp	= fattr,
104 	};
105 	int	status;
106 
107 	dprintk("NFS call  getattr\n");
108 	nfs_fattr_init(fattr);
109 	status = rpc_call_sync(server->client, &msg, 0);
110 	dprintk("NFS reply getattr: %d\n", status);
111 	return status;
112 }
113 
114 static int
115 nfs_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 	};
123 	struct rpc_message msg = {
124 		.rpc_proc	= &nfs_procedures[NFSPROC_SETATTR],
125 		.rpc_argp	= &arg,
126 		.rpc_resp	= fattr,
127 	};
128 	int	status;
129 
130 	/* Mask out the non-modebit related stuff from attr->ia_mode */
131 	sattr->ia_mode &= S_IALLUGO;
132 
133 	dprintk("NFS call  setattr\n");
134 	nfs_fattr_init(fattr);
135 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
136 	if (status == 0)
137 		nfs_setattr_update_inode(inode, sattr);
138 	dprintk("NFS reply setattr: %d\n", status);
139 	return status;
140 }
141 
142 static int
143 nfs_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 	};
155 	struct rpc_message msg = {
156 		.rpc_proc	= &nfs_procedures[NFSPROC_LOOKUP],
157 		.rpc_argp	= &arg,
158 		.rpc_resp	= &res,
159 	};
160 	int			status;
161 
162 	dprintk("NFS call  lookup %s\n", name->name);
163 	nfs_fattr_init(fattr);
164 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
165 	dprintk("NFS reply lookup: %d\n", status);
166 	return status;
167 }
168 
169 static 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 	};
178 	struct rpc_message msg = {
179 		.rpc_proc	= &nfs_procedures[NFSPROC_READLINK],
180 		.rpc_argp	= &args,
181 	};
182 	int			status;
183 
184 	dprintk("NFS call  readlink\n");
185 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
186 	dprintk("NFS reply readlink: %d\n", status);
187 	return status;
188 }
189 
190 static 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);
205 	nfs_fattr_init(fattr);
206 	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 
219 static 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);
234 	nfs_fattr_init(fattr);
235 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
236 	if (status >= 0) {
237 		nfs_post_op_update_inode(inode, fattr);
238 		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 
245 static int
246 nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
247 		int flags, struct nameidata *nd)
248 {
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 	};
261 	struct rpc_message msg = {
262 		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],
263 		.rpc_argp	= &arg,
264 		.rpc_resp	= &res,
265 	};
266 	int			status;
267 
268 	nfs_fattr_init(&fattr);
269 	dprintk("NFS call  create %s\n", dentry->d_name.name);
270 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
271 	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  */
280 static int
281 nfs_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 	};
296 	struct rpc_message msg = {
297 		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],
298 		.rpc_argp	= &arg,
299 		.rpc_resp	= &res,
300 	};
301 	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 
314 	nfs_fattr_init(&fattr);
315 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
316 	nfs_mark_for_revalidate(dir);
317 
318 	if (status == -EINVAL && S_ISFIFO(mode)) {
319 		sattr->ia_mode = mode;
320 		nfs_fattr_init(&fattr);
321 		status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
322 	}
323 	if (status == 0)
324 		status = nfs_instantiate(dentry, &fhandle, &fattr);
325 	dprintk("NFS reply mknod: %d\n", status);
326 	return status;
327 }
328 
329 static int
330 nfs_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,
340 	};
341 	int			status;
342 
343 	dprintk("NFS call  remove %s\n", name->name);
344 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
345 	nfs_mark_for_revalidate(dir);
346 
347 	dprintk("NFS reply remove: %d\n", status);
348 	return status;
349 }
350 
351 static int
352 nfs_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 
367 static int
368 nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
369 {
370 	struct rpc_message *msg = &task->tk_msg;
371 
372 	if (msg->rpc_argp) {
373 		nfs_mark_for_revalidate(dir->d_inode);
374 		kfree(msg->rpc_argp);
375 	}
376 	return 0;
377 }
378 
379 static int
380 nfs_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 	};
391 	struct rpc_message msg = {
392 		.rpc_proc	= &nfs_procedures[NFSPROC_RENAME],
393 		.rpc_argp	= &arg,
394 	};
395 	int			status;
396 
397 	dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);
398 	status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
399 	nfs_mark_for_revalidate(old_dir);
400 	nfs_mark_for_revalidate(new_dir);
401 	dprintk("NFS reply rename: %d\n", status);
402 	return status;
403 }
404 
405 static int
406 nfs_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 	};
414 	struct rpc_message msg = {
415 		.rpc_proc	= &nfs_procedures[NFSPROC_LINK],
416 		.rpc_argp	= &arg,
417 	};
418 	int			status;
419 
420 	dprintk("NFS call  link %s\n", name->name);
421 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
422 	nfs_mark_for_revalidate(inode);
423 	nfs_mark_for_revalidate(dir);
424 	dprintk("NFS reply link: %d\n", status);
425 	return status;
426 }
427 
428 static int
429 nfs_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 	};
441 	struct rpc_message msg = {
442 		.rpc_proc	= &nfs_procedures[NFSPROC_SYMLINK],
443 		.rpc_argp	= &arg,
444 	};
445 	int			status;
446 
447 	if (path->len > NFS2_MAXPATHLEN)
448 		return -ENAMETOOLONG;
449 	dprintk("NFS call  symlink %s -> %s\n", name->name, path->name);
450 	nfs_fattr_init(fattr);
451 	fhandle->size = 0;
452 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
453 	nfs_mark_for_revalidate(dir);
454 	dprintk("NFS reply symlink: %d\n", status);
455 	return status;
456 }
457 
458 static int
459 nfs_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 	};
473 	struct rpc_message msg = {
474 		.rpc_proc	= &nfs_procedures[NFSPROC_MKDIR],
475 		.rpc_argp	= &arg,
476 		.rpc_resp	= &res,
477 	};
478 	int			status;
479 
480 	dprintk("NFS call  mkdir %s\n", dentry->d_name.name);
481 	nfs_fattr_init(&fattr);
482 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
483 	nfs_mark_for_revalidate(dir);
484 	if (status == 0)
485 		status = nfs_instantiate(dentry, &fhandle, &fattr);
486 	dprintk("NFS reply mkdir: %d\n", status);
487 	return status;
488 }
489 
490 static int
491 nfs_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 	};
498 	struct rpc_message msg = {
499 		.rpc_proc	= &nfs_procedures[NFSPROC_RMDIR],
500 		.rpc_argp	= &arg,
501 	};
502 	int			status;
503 
504 	dprintk("NFS call  rmdir %s\n", name->name);
505 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
506 	nfs_mark_for_revalidate(dir);
507 	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  */
518 static int
519 nfs_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,
527 		.pages		= &page,
528 	};
529 	struct rpc_message	msg = {
530 		.rpc_proc	= &nfs_procedures[NFSPROC_READDIR],
531 		.rpc_argp	= &arg,
532 		.rpc_cred	= cred,
533 	};
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 
546 static int
547 nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
548 			struct nfs_fsstat *stat)
549 {
550 	struct nfs2_fsstat fsinfo;
551 	struct rpc_message msg = {
552 		.rpc_proc	= &nfs_procedures[NFSPROC_STATFS],
553 		.rpc_argp	= fhandle,
554 		.rpc_resp	= &fsinfo,
555 	};
556 	int	status;
557 
558 	dprintk("NFS call  statfs\n");
559 	nfs_fattr_init(stat->fattr);
560 	status = rpc_call_sync(server->client, &msg, 0);
561 	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;
570 out:
571 	return status;
572 }
573 
574 static int
575 nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
576 			struct nfs_fsinfo *info)
577 {
578 	struct nfs2_fsstat fsinfo;
579 	struct rpc_message msg = {
580 		.rpc_proc	= &nfs_procedures[NFSPROC_STATFS],
581 		.rpc_argp	= fhandle,
582 		.rpc_resp	= &fsinfo,
583 	};
584 	int	status;
585 
586 	dprintk("NFS call  fsinfo\n");
587 	nfs_fattr_init(info->fattr);
588 	status = rpc_call_sync(server->client, &msg, 0);
589 	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;
601 out:
602 	return status;
603 }
604 
605 static int
606 nfs_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 
614 extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
615 
616 static void nfs_read_done(struct rpc_task *task, void *calldata)
617 {
618 	struct nfs_read_data *data = calldata;
619 
620 	if (task->tk_status >= 0) {
621 		nfs_refresh_inode(data->inode, data->res.fattr);
622 		/* Emulate the eof flag, which isn't normally needed in NFSv2
623 		 * as it is guaranteed to always return the file attributes
624 		 */
625 		if (data->args.offset + data->args.count >= data->res.fattr->size)
626 			data->res.eof = 1;
627 	}
628 	nfs_readpage_result(task, calldata);
629 }
630 
631 static const struct rpc_call_ops nfs_read_ops = {
632 	.rpc_call_done = nfs_read_done,
633 	.rpc_release = nfs_readdata_release,
634 };
635 
636 static void
637 nfs_proc_read_setup(struct nfs_read_data *data)
638 {
639 	struct rpc_task		*task = &data->task;
640 	struct inode		*inode = data->inode;
641 	int			flags;
642 	struct rpc_message	msg = {
643 		.rpc_proc	= &nfs_procedures[NFSPROC_READ],
644 		.rpc_argp	= &data->args,
645 		.rpc_resp	= &data->res,
646 		.rpc_cred	= data->cred,
647 	};
648 
649 	/* N.B. Do we need to test? Never called for swapfile inode */
650 	flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
651 
652 	/* Finalize the task. */
653 	rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs_read_ops, data);
654 	rpc_call_setup(task, &msg, 0);
655 }
656 
657 static void nfs_write_done(struct rpc_task *task, void *calldata)
658 {
659 	struct nfs_write_data *data = calldata;
660 
661 	if (task->tk_status >= 0)
662 		nfs_post_op_update_inode(data->inode, data->res.fattr);
663 	nfs_writeback_done(task, calldata);
664 }
665 
666 static const struct rpc_call_ops nfs_write_ops = {
667 	.rpc_call_done = nfs_write_done,
668 	.rpc_release = nfs_writedata_release,
669 };
670 
671 static void
672 nfs_proc_write_setup(struct nfs_write_data *data, int how)
673 {
674 	struct rpc_task		*task = &data->task;
675 	struct inode		*inode = data->inode;
676 	int			flags;
677 	struct rpc_message	msg = {
678 		.rpc_proc	= &nfs_procedures[NFSPROC_WRITE],
679 		.rpc_argp	= &data->args,
680 		.rpc_resp	= &data->res,
681 		.rpc_cred	= data->cred,
682 	};
683 
684 	/* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
685 	data->args.stable = NFS_FILE_SYNC;
686 
687 	/* Set the initial flags for the task.  */
688 	flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
689 
690 	/* Finalize the task. */
691 	rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs_write_ops, data);
692 	rpc_call_setup(task, &msg, 0);
693 }
694 
695 static void
696 nfs_proc_commit_setup(struct nfs_write_data *data, int how)
697 {
698 	BUG();
699 }
700 
701 static int
702 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
703 {
704 	return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
705 }
706 
707 
708 struct nfs_rpc_ops	nfs_v2_clientops = {
709 	.version	= 2,		       /* protocol version */
710 	.dentry_ops	= &nfs_dentry_operations,
711 	.dir_inode_ops	= &nfs_dir_inode_operations,
712 	.file_inode_ops	= &nfs_file_inode_operations,
713 	.getroot	= nfs_proc_get_root,
714 	.getattr	= nfs_proc_getattr,
715 	.setattr	= nfs_proc_setattr,
716 	.lookup		= nfs_proc_lookup,
717 	.access		= NULL,		       /* access */
718 	.readlink	= nfs_proc_readlink,
719 	.read		= nfs_proc_read,
720 	.write		= nfs_proc_write,
721 	.commit		= NULL,		       /* commit */
722 	.create		= nfs_proc_create,
723 	.remove		= nfs_proc_remove,
724 	.unlink_setup	= nfs_proc_unlink_setup,
725 	.unlink_done	= nfs_proc_unlink_done,
726 	.rename		= nfs_proc_rename,
727 	.link		= nfs_proc_link,
728 	.symlink	= nfs_proc_symlink,
729 	.mkdir		= nfs_proc_mkdir,
730 	.rmdir		= nfs_proc_rmdir,
731 	.readdir	= nfs_proc_readdir,
732 	.mknod		= nfs_proc_mknod,
733 	.statfs		= nfs_proc_statfs,
734 	.fsinfo		= nfs_proc_fsinfo,
735 	.pathconf	= nfs_proc_pathconf,
736 	.decode_dirent	= nfs_decode_dirent,
737 	.read_setup	= nfs_proc_read_setup,
738 	.write_setup	= nfs_proc_write_setup,
739 	.commit_setup	= nfs_proc_commit_setup,
740 	.file_open	= nfs_open,
741 	.file_release	= nfs_release,
742 	.lock		= nfs_proc_lock,
743 };
744