xref: /openbmc/linux/fs/nfs/proc.c (revision c74dfe97)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/fs/nfs/proc.c
4  *
5  *  Copyright (C) 1992, 1993, 1994  Rick Sladkey
6  *
7  *  OS-independent nfs remote procedure call functions
8  *
9  *  Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers
10  *  so at last we can have decent(ish) throughput off a
11  *  Sun server.
12  *
13  *  Coding optimized and cleaned up by Florian La Roche.
14  *  Note: Error returns are optimized for NFS_OK, which isn't translated via
15  *  nfs_stat_to_errno(), but happens to be already the right return code.
16  *
17  *  Also, the code currently doesn't check the size of the packet, when
18  *  it decodes the packet.
19  *
20  *  Feel free to fix it and mail me the diffs if it worries you.
21  *
22  *  Completely rewritten to support the new RPC call interface;
23  *  rewrote and moved the entire XDR stuff to xdr.c
24  *  --Olaf Kirch June 1996
25  *
26  *  The code below initializes all auto variables explicitly, otherwise
27  *  it will fail to work as a module (gcc generates a memset call for an
28  *  incomplete struct).
29  */
30 
31 #include <linux/types.h>
32 #include <linux/param.h>
33 #include <linux/time.h>
34 #include <linux/mm.h>
35 #include <linux/errno.h>
36 #include <linux/string.h>
37 #include <linux/in.h>
38 #include <linux/pagemap.h>
39 #include <linux/sunrpc/clnt.h>
40 #include <linux/nfs.h>
41 #include <linux/nfs2.h>
42 #include <linux/nfs_fs.h>
43 #include <linux/nfs_page.h>
44 #include <linux/lockd/bind.h>
45 #include <linux/freezer.h>
46 #include "internal.h"
47 
48 #define NFSDBG_FACILITY		NFSDBG_PROC
49 
50 /*
51  * Bare-bones access to getattr: this is for nfs_read_super.
52  */
53 static int
54 nfs_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;
59 	struct rpc_message msg = {
60 		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],
61 		.rpc_argp	= fhandle,
62 		.rpc_resp	= fattr,
63 	};
64 	int status;
65 
66 	dprintk("%s: call getattr\n", __func__);
67 	nfs_fattr_init(fattr);
68 	status = rpc_call_sync(server->client, &msg, 0);
69 	/* Retry with default authentication if different */
70 	if (status && server->nfs_client->cl_rpcclient != server->client)
71 		status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
72 	dprintk("%s: reply getattr: %d\n", __func__, status);
73 	if (status)
74 		return status;
75 	dprintk("%s: call statfs\n", __func__);
76 	msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
77 	msg.rpc_resp = &fsinfo;
78 	status = rpc_call_sync(server->client, &msg, 0);
79 	/* Retry with default authentication if different */
80 	if (status && server->nfs_client->cl_rpcclient != server->client)
81 		status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
82 	dprintk("%s: reply statfs: %d\n", __func__, status);
83 	if (status)
84 		return status;
85 	info->rtmax  = NFS_MAXDATA;
86 	info->rtpref = fsinfo.tsize;
87 	info->rtmult = fsinfo.bsize;
88 	info->wtmax  = NFS_MAXDATA;
89 	info->wtpref = fsinfo.tsize;
90 	info->wtmult = fsinfo.bsize;
91 	info->dtpref = fsinfo.tsize;
92 	info->maxfilesize = 0x7FFFFFFF;
93 	info->lease_time = 0;
94 	return 0;
95 }
96 
97 /*
98  * One function for each procedure in the NFS protocol.
99  */
100 static int
101 nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
102 		struct nfs_fattr *fattr, struct nfs4_label *label,
103 		struct inode *inode)
104 {
105 	struct rpc_message msg = {
106 		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],
107 		.rpc_argp	= fhandle,
108 		.rpc_resp	= fattr,
109 	};
110 	int	status;
111 	unsigned short task_flags = 0;
112 
113 	/* Is this is an attribute revalidation, subject to softreval? */
114 	if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
115 		task_flags |= RPC_TASK_TIMEOUT;
116 
117 	dprintk("NFS call  getattr\n");
118 	nfs_fattr_init(fattr);
119 	status = rpc_call_sync(server->client, &msg, task_flags);
120 	dprintk("NFS reply getattr: %d\n", status);
121 	return status;
122 }
123 
124 static int
125 nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
126 		 struct iattr *sattr)
127 {
128 	struct inode *inode = d_inode(dentry);
129 	struct nfs_sattrargs	arg = {
130 		.fh	= NFS_FH(inode),
131 		.sattr	= sattr
132 	};
133 	struct rpc_message msg = {
134 		.rpc_proc	= &nfs_procedures[NFSPROC_SETATTR],
135 		.rpc_argp	= &arg,
136 		.rpc_resp	= fattr,
137 	};
138 	int	status;
139 
140 	/* Mask out the non-modebit related stuff from attr->ia_mode */
141 	sattr->ia_mode &= S_IALLUGO;
142 
143 	dprintk("NFS call  setattr\n");
144 	if (sattr->ia_valid & ATTR_FILE)
145 		msg.rpc_cred = nfs_file_cred(sattr->ia_file);
146 	nfs_fattr_init(fattr);
147 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
148 	if (status == 0)
149 		nfs_setattr_update_inode(inode, sattr, fattr);
150 	dprintk("NFS reply setattr: %d\n", status);
151 	return status;
152 }
153 
154 static int
155 nfs_proc_lookup(struct inode *dir, const struct qstr *name,
156 		struct nfs_fh *fhandle, struct nfs_fattr *fattr,
157 		struct nfs4_label *label)
158 {
159 	struct nfs_diropargs	arg = {
160 		.fh		= NFS_FH(dir),
161 		.name		= name->name,
162 		.len		= name->len
163 	};
164 	struct nfs_diropok	res = {
165 		.fh		= fhandle,
166 		.fattr		= fattr
167 	};
168 	struct rpc_message msg = {
169 		.rpc_proc	= &nfs_procedures[NFSPROC_LOOKUP],
170 		.rpc_argp	= &arg,
171 		.rpc_resp	= &res,
172 	};
173 	int			status;
174 
175 	dprintk("NFS call  lookup %s\n", name->name);
176 	nfs_fattr_init(fattr);
177 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
178 	dprintk("NFS reply lookup: %d\n", status);
179 	return status;
180 }
181 
182 static int nfs_proc_readlink(struct inode *inode, struct page *page,
183 		unsigned int pgbase, unsigned int pglen)
184 {
185 	struct nfs_readlinkargs	args = {
186 		.fh		= NFS_FH(inode),
187 		.pgbase		= pgbase,
188 		.pglen		= pglen,
189 		.pages		= &page
190 	};
191 	struct rpc_message msg = {
192 		.rpc_proc	= &nfs_procedures[NFSPROC_READLINK],
193 		.rpc_argp	= &args,
194 	};
195 	int			status;
196 
197 	dprintk("NFS call  readlink\n");
198 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
199 	dprintk("NFS reply readlink: %d\n", status);
200 	return status;
201 }
202 
203 struct nfs_createdata {
204 	struct nfs_createargs arg;
205 	struct nfs_diropok res;
206 	struct nfs_fh fhandle;
207 	struct nfs_fattr fattr;
208 };
209 
210 static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
211 		struct dentry *dentry, struct iattr *sattr)
212 {
213 	struct nfs_createdata *data;
214 
215 	data = kmalloc(sizeof(*data), GFP_KERNEL);
216 
217 	if (data != NULL) {
218 		data->arg.fh = NFS_FH(dir);
219 		data->arg.name = dentry->d_name.name;
220 		data->arg.len = dentry->d_name.len;
221 		data->arg.sattr = sattr;
222 		nfs_fattr_init(&data->fattr);
223 		data->fhandle.size = 0;
224 		data->res.fh = &data->fhandle;
225 		data->res.fattr = &data->fattr;
226 	}
227 	return data;
228 };
229 
230 static void nfs_free_createdata(const struct nfs_createdata *data)
231 {
232 	kfree(data);
233 }
234 
235 static int
236 nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
237 		int flags)
238 {
239 	struct nfs_createdata *data;
240 	struct rpc_message msg = {
241 		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],
242 	};
243 	int status = -ENOMEM;
244 
245 	dprintk("NFS call  create %pd\n", dentry);
246 	data = nfs_alloc_createdata(dir, dentry, sattr);
247 	if (data == NULL)
248 		goto out;
249 	msg.rpc_argp = &data->arg;
250 	msg.rpc_resp = &data->res;
251 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
252 	nfs_mark_for_revalidate(dir);
253 	if (status == 0)
254 		status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
255 	nfs_free_createdata(data);
256 out:
257 	dprintk("NFS reply create: %d\n", status);
258 	return status;
259 }
260 
261 /*
262  * In NFSv2, mknod is grafted onto the create call.
263  */
264 static int
265 nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
266 	       dev_t rdev)
267 {
268 	struct nfs_createdata *data;
269 	struct rpc_message msg = {
270 		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],
271 	};
272 	umode_t mode;
273 	int status = -ENOMEM;
274 
275 	dprintk("NFS call  mknod %pd\n", dentry);
276 
277 	mode = sattr->ia_mode;
278 	if (S_ISFIFO(mode)) {
279 		sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
280 		sattr->ia_valid &= ~ATTR_SIZE;
281 	} else if (S_ISCHR(mode) || S_ISBLK(mode)) {
282 		sattr->ia_valid |= ATTR_SIZE;
283 		sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
284 	}
285 
286 	data = nfs_alloc_createdata(dir, dentry, sattr);
287 	if (data == NULL)
288 		goto out;
289 	msg.rpc_argp = &data->arg;
290 	msg.rpc_resp = &data->res;
291 
292 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
293 	nfs_mark_for_revalidate(dir);
294 
295 	if (status == -EINVAL && S_ISFIFO(mode)) {
296 		sattr->ia_mode = mode;
297 		nfs_fattr_init(data->res.fattr);
298 		status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
299 	}
300 	if (status == 0)
301 		status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
302 	nfs_free_createdata(data);
303 out:
304 	dprintk("NFS reply mknod: %d\n", status);
305 	return status;
306 }
307 
308 static int
309 nfs_proc_remove(struct inode *dir, struct dentry *dentry)
310 {
311 	struct nfs_removeargs arg = {
312 		.fh = NFS_FH(dir),
313 		.name = dentry->d_name,
314 	};
315 	struct rpc_message msg = {
316 		.rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
317 		.rpc_argp = &arg,
318 	};
319 	int			status;
320 
321 	dprintk("NFS call  remove %pd2\n",dentry);
322 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
323 	nfs_mark_for_revalidate(dir);
324 
325 	dprintk("NFS reply remove: %d\n", status);
326 	return status;
327 }
328 
329 static void
330 nfs_proc_unlink_setup(struct rpc_message *msg,
331 		struct dentry *dentry,
332 		struct inode *inode)
333 {
334 	msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
335 }
336 
337 static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
338 {
339 	rpc_call_start(task);
340 }
341 
342 static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
343 {
344 	nfs_mark_for_revalidate(dir);
345 	return 1;
346 }
347 
348 static void
349 nfs_proc_rename_setup(struct rpc_message *msg,
350 		struct dentry *old_dentry,
351 		struct dentry *new_dentry)
352 {
353 	msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
354 }
355 
356 static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
357 {
358 	rpc_call_start(task);
359 }
360 
361 static int
362 nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
363 		     struct inode *new_dir)
364 {
365 	nfs_mark_for_revalidate(old_dir);
366 	nfs_mark_for_revalidate(new_dir);
367 	return 1;
368 }
369 
370 static int
371 nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
372 {
373 	struct nfs_linkargs	arg = {
374 		.fromfh		= NFS_FH(inode),
375 		.tofh		= NFS_FH(dir),
376 		.toname		= name->name,
377 		.tolen		= name->len
378 	};
379 	struct rpc_message msg = {
380 		.rpc_proc	= &nfs_procedures[NFSPROC_LINK],
381 		.rpc_argp	= &arg,
382 	};
383 	int			status;
384 
385 	dprintk("NFS call  link %s\n", name->name);
386 	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
387 	nfs_mark_for_revalidate(inode);
388 	nfs_mark_for_revalidate(dir);
389 	dprintk("NFS reply link: %d\n", status);
390 	return status;
391 }
392 
393 static int
394 nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
395 		 unsigned int len, struct iattr *sattr)
396 {
397 	struct nfs_fh *fh;
398 	struct nfs_fattr *fattr;
399 	struct nfs_symlinkargs	arg = {
400 		.fromfh		= NFS_FH(dir),
401 		.fromname	= dentry->d_name.name,
402 		.fromlen	= dentry->d_name.len,
403 		.pages		= &page,
404 		.pathlen	= len,
405 		.sattr		= sattr
406 	};
407 	struct rpc_message msg = {
408 		.rpc_proc	= &nfs_procedures[NFSPROC_SYMLINK],
409 		.rpc_argp	= &arg,
410 	};
411 	int status = -ENAMETOOLONG;
412 
413 	dprintk("NFS call  symlink %pd\n", dentry);
414 
415 	if (len > NFS2_MAXPATHLEN)
416 		goto out;
417 
418 	fh = nfs_alloc_fhandle();
419 	fattr = nfs_alloc_fattr();
420 	status = -ENOMEM;
421 	if (fh == NULL || fattr == NULL)
422 		goto out_free;
423 
424 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
425 	nfs_mark_for_revalidate(dir);
426 
427 	/*
428 	 * V2 SYMLINK requests don't return any attributes.  Setting the
429 	 * filehandle size to zero indicates to nfs_instantiate that it
430 	 * should fill in the data with a LOOKUP call on the wire.
431 	 */
432 	if (status == 0)
433 		status = nfs_instantiate(dentry, fh, fattr, NULL);
434 
435 out_free:
436 	nfs_free_fattr(fattr);
437 	nfs_free_fhandle(fh);
438 out:
439 	dprintk("NFS reply symlink: %d\n", status);
440 	return status;
441 }
442 
443 static int
444 nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
445 {
446 	struct nfs_createdata *data;
447 	struct rpc_message msg = {
448 		.rpc_proc	= &nfs_procedures[NFSPROC_MKDIR],
449 	};
450 	int status = -ENOMEM;
451 
452 	dprintk("NFS call  mkdir %pd\n", dentry);
453 	data = nfs_alloc_createdata(dir, dentry, sattr);
454 	if (data == NULL)
455 		goto out;
456 	msg.rpc_argp = &data->arg;
457 	msg.rpc_resp = &data->res;
458 
459 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
460 	nfs_mark_for_revalidate(dir);
461 	if (status == 0)
462 		status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
463 	nfs_free_createdata(data);
464 out:
465 	dprintk("NFS reply mkdir: %d\n", status);
466 	return status;
467 }
468 
469 static int
470 nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
471 {
472 	struct nfs_diropargs	arg = {
473 		.fh		= NFS_FH(dir),
474 		.name		= name->name,
475 		.len		= name->len
476 	};
477 	struct rpc_message msg = {
478 		.rpc_proc	= &nfs_procedures[NFSPROC_RMDIR],
479 		.rpc_argp	= &arg,
480 	};
481 	int			status;
482 
483 	dprintk("NFS call  rmdir %s\n", name->name);
484 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
485 	nfs_mark_for_revalidate(dir);
486 	dprintk("NFS reply rmdir: %d\n", status);
487 	return status;
488 }
489 
490 /*
491  * The READDIR implementation is somewhat hackish - we pass a temporary
492  * buffer to the encode function, which installs it in the receive
493  * the receive iovec. The decode function just parses the reply to make
494  * sure it is syntactically correct; the entries itself are decoded
495  * from nfs_readdir by calling the decode_entry function directly.
496  */
497 static int
498 nfs_proc_readdir(struct dentry *dentry, const struct cred *cred,
499 		 u64 cookie, struct page **pages, unsigned int count, bool plus)
500 {
501 	struct inode		*dir = d_inode(dentry);
502 	struct nfs_readdirargs	arg = {
503 		.fh		= NFS_FH(dir),
504 		.cookie		= cookie,
505 		.count		= count,
506 		.pages		= pages,
507 	};
508 	struct rpc_message	msg = {
509 		.rpc_proc	= &nfs_procedures[NFSPROC_READDIR],
510 		.rpc_argp	= &arg,
511 		.rpc_cred	= cred,
512 	};
513 	int			status;
514 
515 	dprintk("NFS call  readdir %d\n", (unsigned int)cookie);
516 	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
517 
518 	nfs_invalidate_atime(dir);
519 
520 	dprintk("NFS reply readdir: %d\n", status);
521 	return status;
522 }
523 
524 static int
525 nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
526 			struct nfs_fsstat *stat)
527 {
528 	struct nfs2_fsstat fsinfo;
529 	struct rpc_message msg = {
530 		.rpc_proc	= &nfs_procedures[NFSPROC_STATFS],
531 		.rpc_argp	= fhandle,
532 		.rpc_resp	= &fsinfo,
533 	};
534 	int	status;
535 
536 	dprintk("NFS call  statfs\n");
537 	nfs_fattr_init(stat->fattr);
538 	status = rpc_call_sync(server->client, &msg, 0);
539 	dprintk("NFS reply statfs: %d\n", status);
540 	if (status)
541 		goto out;
542 	stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
543 	stat->fbytes = (u64)fsinfo.bfree  * fsinfo.bsize;
544 	stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
545 	stat->tfiles = 0;
546 	stat->ffiles = 0;
547 	stat->afiles = 0;
548 out:
549 	return status;
550 }
551 
552 static int
553 nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
554 			struct nfs_fsinfo *info)
555 {
556 	struct nfs2_fsstat fsinfo;
557 	struct rpc_message msg = {
558 		.rpc_proc	= &nfs_procedures[NFSPROC_STATFS],
559 		.rpc_argp	= fhandle,
560 		.rpc_resp	= &fsinfo,
561 	};
562 	int	status;
563 
564 	dprintk("NFS call  fsinfo\n");
565 	nfs_fattr_init(info->fattr);
566 	status = rpc_call_sync(server->client, &msg, 0);
567 	dprintk("NFS reply fsinfo: %d\n", status);
568 	if (status)
569 		goto out;
570 	info->rtmax  = NFS_MAXDATA;
571 	info->rtpref = fsinfo.tsize;
572 	info->rtmult = fsinfo.bsize;
573 	info->wtmax  = NFS_MAXDATA;
574 	info->wtpref = fsinfo.tsize;
575 	info->wtmult = fsinfo.bsize;
576 	info->dtpref = fsinfo.tsize;
577 	info->maxfilesize = 0x7FFFFFFF;
578 	info->lease_time = 0;
579 out:
580 	return status;
581 }
582 
583 static int
584 nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
585 		  struct nfs_pathconf *info)
586 {
587 	info->max_link = 0;
588 	info->max_namelen = NFS2_MAXNAMLEN;
589 	return 0;
590 }
591 
592 static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
593 {
594 	struct inode *inode = hdr->inode;
595 
596 	nfs_invalidate_atime(inode);
597 	if (task->tk_status >= 0) {
598 		nfs_refresh_inode(inode, hdr->res.fattr);
599 		/* Emulate the eof flag, which isn't normally needed in NFSv2
600 		 * as it is guaranteed to always return the file attributes
601 		 */
602 		if ((hdr->res.count == 0 && hdr->args.count > 0) ||
603 		    hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
604 			hdr->res.eof = 1;
605 	}
606 	return 0;
607 }
608 
609 static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
610 				struct rpc_message *msg)
611 {
612 	msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
613 }
614 
615 static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
616 				     struct nfs_pgio_header *hdr)
617 {
618 	rpc_call_start(task);
619 	return 0;
620 }
621 
622 static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
623 {
624 	if (task->tk_status >= 0) {
625 		hdr->res.count = hdr->args.count;
626 		nfs_writeback_update_inode(hdr);
627 	}
628 	return 0;
629 }
630 
631 static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
632 				 struct rpc_message *msg,
633 				 struct rpc_clnt **clnt)
634 {
635 	/* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
636 	hdr->args.stable = NFS_FILE_SYNC;
637 	msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
638 }
639 
640 static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
641 {
642 	BUG();
643 }
644 
645 static void
646 nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
647 			struct rpc_clnt **clnt)
648 {
649 	BUG();
650 }
651 
652 static int
653 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
654 {
655 	struct inode *inode = file_inode(filp);
656 
657 	return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, NULL);
658 }
659 
660 /* Helper functions for NFS lock bounds checking */
661 #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
662 static int nfs_lock_check_bounds(const struct file_lock *fl)
663 {
664 	__s32 start, end;
665 
666 	start = (__s32)fl->fl_start;
667 	if ((loff_t)start != fl->fl_start)
668 		goto out_einval;
669 
670 	if (fl->fl_end != OFFSET_MAX) {
671 		end = (__s32)fl->fl_end;
672 		if ((loff_t)end != fl->fl_end)
673 			goto out_einval;
674 	} else
675 		end = NFS_LOCK32_OFFSET_MAX;
676 
677 	if (start < 0 || start > end)
678 		goto out_einval;
679 	return 0;
680 out_einval:
681 	return -EINVAL;
682 }
683 
684 static int nfs_have_delegation(struct inode *inode, fmode_t flags)
685 {
686 	return 0;
687 }
688 
689 static const struct inode_operations nfs_dir_inode_operations = {
690 	.create		= nfs_create,
691 	.lookup		= nfs_lookup,
692 	.link		= nfs_link,
693 	.unlink		= nfs_unlink,
694 	.symlink	= nfs_symlink,
695 	.mkdir		= nfs_mkdir,
696 	.rmdir		= nfs_rmdir,
697 	.mknod		= nfs_mknod,
698 	.rename		= nfs_rename,
699 	.permission	= nfs_permission,
700 	.getattr	= nfs_getattr,
701 	.setattr	= nfs_setattr,
702 };
703 
704 static const struct inode_operations nfs_file_inode_operations = {
705 	.permission	= nfs_permission,
706 	.getattr	= nfs_getattr,
707 	.setattr	= nfs_setattr,
708 };
709 
710 const struct nfs_rpc_ops nfs_v2_clientops = {
711 	.version	= 2,		       /* protocol version */
712 	.dentry_ops	= &nfs_dentry_operations,
713 	.dir_inode_ops	= &nfs_dir_inode_operations,
714 	.file_inode_ops	= &nfs_file_inode_operations,
715 	.file_ops	= &nfs_file_operations,
716 	.getroot	= nfs_proc_get_root,
717 	.submount	= nfs_submount,
718 	.try_get_tree	= nfs_try_get_tree,
719 	.getattr	= nfs_proc_getattr,
720 	.setattr	= nfs_proc_setattr,
721 	.lookup		= nfs_proc_lookup,
722 	.access		= NULL,		       /* access */
723 	.readlink	= nfs_proc_readlink,
724 	.create		= nfs_proc_create,
725 	.remove		= nfs_proc_remove,
726 	.unlink_setup	= nfs_proc_unlink_setup,
727 	.unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
728 	.unlink_done	= nfs_proc_unlink_done,
729 	.rename_setup	= nfs_proc_rename_setup,
730 	.rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
731 	.rename_done	= nfs_proc_rename_done,
732 	.link		= nfs_proc_link,
733 	.symlink	= nfs_proc_symlink,
734 	.mkdir		= nfs_proc_mkdir,
735 	.rmdir		= nfs_proc_rmdir,
736 	.readdir	= nfs_proc_readdir,
737 	.mknod		= nfs_proc_mknod,
738 	.statfs		= nfs_proc_statfs,
739 	.fsinfo		= nfs_proc_fsinfo,
740 	.pathconf	= nfs_proc_pathconf,
741 	.decode_dirent	= nfs2_decode_dirent,
742 	.pgio_rpc_prepare = nfs_proc_pgio_rpc_prepare,
743 	.read_setup	= nfs_proc_read_setup,
744 	.read_done	= nfs_read_done,
745 	.write_setup	= nfs_proc_write_setup,
746 	.write_done	= nfs_write_done,
747 	.commit_setup	= nfs_proc_commit_setup,
748 	.commit_rpc_prepare = nfs_proc_commit_rpc_prepare,
749 	.lock		= nfs_proc_lock,
750 	.lock_check_bounds = nfs_lock_check_bounds,
751 	.close_context	= nfs_close_context,
752 	.have_delegation = nfs_have_delegation,
753 	.alloc_client	= nfs_alloc_client,
754 	.init_client	= nfs_init_client,
755 	.free_client	= nfs_free_client,
756 	.create_server	= nfs_create_server,
757 	.clone_server	= nfs_clone_server,
758 };
759