Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvar...
[linux-block.git] / fs / nfs / proc.c
CommitLineData
1da177e4
LT
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>
f7b422b1 46#include "internal.h"
1da177e4
LT
47
48#define NFSDBG_FACILITY NFSDBG_PROC
49
1da177e4
LT
50/*
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;
dead28da
CL
59 struct rpc_message msg = {
60 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
61 .rpc_argp = fhandle,
62 .rpc_resp = fattr,
63 };
1da177e4
LT
64 int status;
65
3110ff80 66 dprintk("%s: call getattr\n", __func__);
0e574af1 67 nfs_fattr_init(fattr);
37ca8f5c
EK
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);
3110ff80 72 dprintk("%s: reply getattr: %d\n", __func__, status);
1da177e4
LT
73 if (status)
74 return status;
3110ff80 75 dprintk("%s: call statfs\n", __func__);
dead28da
CL
76 msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
77 msg.rpc_resp = &fsinfo;
37ca8f5c
EK
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);
3110ff80 82 dprintk("%s: reply statfs: %d\n", __func__, status);
1da177e4
LT
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 */
100static int
101nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
102 struct nfs_fattr *fattr)
103{
dead28da
CL
104 struct rpc_message msg = {
105 .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
106 .rpc_argp = fhandle,
107 .rpc_resp = fattr,
108 };
1da177e4
LT
109 int status;
110
111 dprintk("NFS call getattr\n");
0e574af1 112 nfs_fattr_init(fattr);
dead28da 113 status = rpc_call_sync(server->client, &msg, 0);
1da177e4
LT
114 dprintk("NFS reply getattr: %d\n", status);
115 return status;
116}
117
118static int
119nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
120 struct iattr *sattr)
121{
122 struct inode *inode = dentry->d_inode;
123 struct nfs_sattrargs arg = {
124 .fh = NFS_FH(inode),
125 .sattr = sattr
126 };
dead28da
CL
127 struct rpc_message msg = {
128 .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
129 .rpc_argp = &arg,
130 .rpc_resp = fattr,
131 };
1da177e4
LT
132 int status;
133
cf3fff54
TM
134 /* Mask out the non-modebit related stuff from attr->ia_mode */
135 sattr->ia_mode &= S_IALLUGO;
136
1da177e4 137 dprintk("NFS call setattr\n");
659bfcd6
TM
138 if (sattr->ia_valid & ATTR_FILE)
139 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
0e574af1 140 nfs_fattr_init(fattr);
dead28da 141 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
65e4308d
TM
142 if (status == 0)
143 nfs_setattr_update_inode(inode, sattr);
1da177e4
LT
144 dprintk("NFS reply setattr: %d\n", status);
145 return status;
146}
147
148static int
149nfs_proc_lookup(struct inode *dir, struct qstr *name,
150 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
151{
152 struct nfs_diropargs arg = {
153 .fh = NFS_FH(dir),
154 .name = name->name,
155 .len = name->len
156 };
157 struct nfs_diropok res = {
158 .fh = fhandle,
159 .fattr = fattr
160 };
dead28da
CL
161 struct rpc_message msg = {
162 .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
163 .rpc_argp = &arg,
164 .rpc_resp = &res,
165 };
1da177e4
LT
166 int status;
167
168 dprintk("NFS call lookup %s\n", name->name);
0e574af1 169 nfs_fattr_init(fattr);
dead28da 170 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1da177e4
LT
171 dprintk("NFS reply lookup: %d\n", status);
172 return status;
173}
174
175static int nfs_proc_readlink(struct inode *inode, struct page *page,
176 unsigned int pgbase, unsigned int pglen)
177{
178 struct nfs_readlinkargs args = {
179 .fh = NFS_FH(inode),
180 .pgbase = pgbase,
181 .pglen = pglen,
182 .pages = &page
183 };
dead28da
CL
184 struct rpc_message msg = {
185 .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
186 .rpc_argp = &args,
187 };
1da177e4
LT
188 int status;
189
190 dprintk("NFS call readlink\n");
dead28da 191 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1da177e4
LT
192 dprintk("NFS reply readlink: %d\n", status);
193 return status;
194}
195
1da177e4
LT
196static int
197nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
02a913a7 198 int flags, struct nameidata *nd)
1da177e4
LT
199{
200 struct nfs_fh fhandle;
201 struct nfs_fattr fattr;
202 struct nfs_createargs arg = {
203 .fh = NFS_FH(dir),
204 .name = dentry->d_name.name,
205 .len = dentry->d_name.len,
206 .sattr = sattr
207 };
208 struct nfs_diropok res = {
209 .fh = &fhandle,
210 .fattr = &fattr
211 };
dead28da
CL
212 struct rpc_message msg = {
213 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
214 .rpc_argp = &arg,
215 .rpc_resp = &res,
216 };
1da177e4
LT
217 int status;
218
0e574af1 219 nfs_fattr_init(&fattr);
1da177e4 220 dprintk("NFS call create %s\n", dentry->d_name.name);
dead28da 221 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
bad2a524 222 nfs_mark_for_revalidate(dir);
1da177e4
LT
223 if (status == 0)
224 status = nfs_instantiate(dentry, &fhandle, &fattr);
225 dprintk("NFS reply create: %d\n", status);
226 return status;
227}
228
229/*
230 * In NFSv2, mknod is grafted onto the create call.
231 */
232static int
233nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
234 dev_t rdev)
235{
236 struct nfs_fh fhandle;
237 struct nfs_fattr fattr;
238 struct nfs_createargs arg = {
239 .fh = NFS_FH(dir),
240 .name = dentry->d_name.name,
241 .len = dentry->d_name.len,
242 .sattr = sattr
243 };
244 struct nfs_diropok res = {
245 .fh = &fhandle,
246 .fattr = &fattr
247 };
dead28da
CL
248 struct rpc_message msg = {
249 .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
250 .rpc_argp = &arg,
251 .rpc_resp = &res,
252 };
1da177e4
LT
253 int status, mode;
254
255 dprintk("NFS call mknod %s\n", dentry->d_name.name);
256
257 mode = sattr->ia_mode;
258 if (S_ISFIFO(mode)) {
259 sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
260 sattr->ia_valid &= ~ATTR_SIZE;
261 } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
262 sattr->ia_valid |= ATTR_SIZE;
263 sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
264 }
265
0e574af1 266 nfs_fattr_init(&fattr);
dead28da 267 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 268 nfs_mark_for_revalidate(dir);
1da177e4
LT
269
270 if (status == -EINVAL && S_ISFIFO(mode)) {
271 sattr->ia_mode = mode;
0e574af1 272 nfs_fattr_init(&fattr);
dead28da 273 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1da177e4
LT
274 }
275 if (status == 0)
276 status = nfs_instantiate(dentry, &fhandle, &fattr);
277 dprintk("NFS reply mknod: %d\n", status);
278 return status;
279}
280
281static int
282nfs_proc_remove(struct inode *dir, struct qstr *name)
283{
4fdc17b2
TM
284 struct nfs_removeargs arg = {
285 .fh = NFS_FH(dir),
286 .name.len = name->len,
287 .name.name = name->name,
1da177e4 288 };
4fdc17b2
TM
289 struct rpc_message msg = {
290 .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
291 .rpc_argp = &arg,
1da177e4
LT
292 };
293 int status;
294
295 dprintk("NFS call remove %s\n", name->name);
296 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 297 nfs_mark_for_revalidate(dir);
1da177e4
LT
298
299 dprintk("NFS reply remove: %d\n", status);
300 return status;
301}
302
e4eff1a6
TM
303static void
304nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
1da177e4 305{
1da177e4 306 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
1da177e4
LT
307}
308
e4eff1a6 309static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
1da177e4 310{
e4eff1a6
TM
311 nfs_mark_for_revalidate(dir);
312 return 1;
1da177e4
LT
313}
314
315static int
316nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
317 struct inode *new_dir, struct qstr *new_name)
318{
319 struct nfs_renameargs arg = {
320 .fromfh = NFS_FH(old_dir),
321 .fromname = old_name->name,
322 .fromlen = old_name->len,
323 .tofh = NFS_FH(new_dir),
324 .toname = new_name->name,
325 .tolen = new_name->len
326 };
dead28da
CL
327 struct rpc_message msg = {
328 .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
329 .rpc_argp = &arg,
330 };
1da177e4
LT
331 int status;
332
333 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
dead28da 334 status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
decf491f
TM
335 nfs_mark_for_revalidate(old_dir);
336 nfs_mark_for_revalidate(new_dir);
1da177e4
LT
337 dprintk("NFS reply rename: %d\n", status);
338 return status;
339}
340
341static int
342nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
343{
344 struct nfs_linkargs arg = {
345 .fromfh = NFS_FH(inode),
346 .tofh = NFS_FH(dir),
347 .toname = name->name,
348 .tolen = name->len
349 };
dead28da
CL
350 struct rpc_message msg = {
351 .rpc_proc = &nfs_procedures[NFSPROC_LINK],
352 .rpc_argp = &arg,
353 };
1da177e4
LT
354 int status;
355
356 dprintk("NFS call link %s\n", name->name);
dead28da 357 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
5ba7cc48 358 nfs_mark_for_revalidate(inode);
decf491f 359 nfs_mark_for_revalidate(dir);
1da177e4
LT
360 dprintk("NFS reply link: %d\n", status);
361 return status;
362}
363
364static int
94a6d753
CL
365nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
366 unsigned int len, struct iattr *sattr)
1da177e4 367{
4f390c15
CL
368 struct nfs_fh fhandle;
369 struct nfs_fattr fattr;
1da177e4
LT
370 struct nfs_symlinkargs arg = {
371 .fromfh = NFS_FH(dir),
4f390c15
CL
372 .fromname = dentry->d_name.name,
373 .fromlen = dentry->d_name.len,
94a6d753
CL
374 .pages = &page,
375 .pathlen = len,
1da177e4
LT
376 .sattr = sattr
377 };
dead28da
CL
378 struct rpc_message msg = {
379 .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
380 .rpc_argp = &arg,
381 };
1da177e4
LT
382 int status;
383
94a6d753 384 if (len > NFS2_MAXPATHLEN)
1da177e4 385 return -ENAMETOOLONG;
4f390c15 386
94a6d753
CL
387 dprintk("NFS call symlink %s\n", dentry->d_name.name);
388
dead28da 389 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 390 nfs_mark_for_revalidate(dir);
4f390c15
CL
391
392 /*
393 * V2 SYMLINK requests don't return any attributes. Setting the
394 * filehandle size to zero indicates to nfs_instantiate that it
395 * should fill in the data with a LOOKUP call on the wire.
396 */
397 if (status == 0) {
398 nfs_fattr_init(&fattr);
399 fhandle.size = 0;
400 status = nfs_instantiate(dentry, &fhandle, &fattr);
401 }
402
1da177e4
LT
403 dprintk("NFS reply symlink: %d\n", status);
404 return status;
405}
406
407static int
408nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
409{
410 struct nfs_fh fhandle;
411 struct nfs_fattr fattr;
412 struct nfs_createargs arg = {
413 .fh = NFS_FH(dir),
414 .name = dentry->d_name.name,
415 .len = dentry->d_name.len,
416 .sattr = sattr
417 };
418 struct nfs_diropok res = {
419 .fh = &fhandle,
420 .fattr = &fattr
421 };
dead28da
CL
422 struct rpc_message msg = {
423 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
424 .rpc_argp = &arg,
425 .rpc_resp = &res,
426 };
1da177e4
LT
427 int status;
428
429 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
0e574af1 430 nfs_fattr_init(&fattr);
dead28da 431 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 432 nfs_mark_for_revalidate(dir);
1da177e4
LT
433 if (status == 0)
434 status = nfs_instantiate(dentry, &fhandle, &fattr);
435 dprintk("NFS reply mkdir: %d\n", status);
436 return status;
437}
438
439static int
440nfs_proc_rmdir(struct inode *dir, struct qstr *name)
441{
442 struct nfs_diropargs arg = {
443 .fh = NFS_FH(dir),
444 .name = name->name,
445 .len = name->len
446 };
dead28da
CL
447 struct rpc_message msg = {
448 .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
449 .rpc_argp = &arg,
450 };
1da177e4
LT
451 int status;
452
453 dprintk("NFS call rmdir %s\n", name->name);
dead28da 454 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 455 nfs_mark_for_revalidate(dir);
1da177e4
LT
456 dprintk("NFS reply rmdir: %d\n", status);
457 return status;
458}
459
460/*
461 * The READDIR implementation is somewhat hackish - we pass a temporary
462 * buffer to the encode function, which installs it in the receive
463 * the receive iovec. The decode function just parses the reply to make
464 * sure it is syntactically correct; the entries itself are decoded
465 * from nfs_readdir by calling the decode_entry function directly.
466 */
467static int
468nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
469 u64 cookie, struct page *page, unsigned int count, int plus)
470{
471 struct inode *dir = dentry->d_inode;
472 struct nfs_readdirargs arg = {
473 .fh = NFS_FH(dir),
474 .cookie = cookie,
475 .count = count,
dead28da 476 .pages = &page,
1da177e4
LT
477 };
478 struct rpc_message msg = {
479 .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
480 .rpc_argp = &arg,
dead28da 481 .rpc_cred = cred,
1da177e4
LT
482 };
483 int status;
484
1da177e4
LT
485 dprintk("NFS call readdir %d\n", (unsigned int)cookie);
486 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
487
c4812998
TM
488 nfs_invalidate_atime(dir);
489
1da177e4 490 dprintk("NFS reply readdir: %d\n", status);
1da177e4
LT
491 return status;
492}
493
494static int
495nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
496 struct nfs_fsstat *stat)
497{
498 struct nfs2_fsstat fsinfo;
dead28da
CL
499 struct rpc_message msg = {
500 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
501 .rpc_argp = fhandle,
502 .rpc_resp = &fsinfo,
503 };
1da177e4
LT
504 int status;
505
506 dprintk("NFS call statfs\n");
0e574af1 507 nfs_fattr_init(stat->fattr);
dead28da 508 status = rpc_call_sync(server->client, &msg, 0);
1da177e4
LT
509 dprintk("NFS reply statfs: %d\n", status);
510 if (status)
511 goto out;
512 stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
513 stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
514 stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
515 stat->tfiles = 0;
516 stat->ffiles = 0;
517 stat->afiles = 0;
518out:
519 return status;
520}
521
522static int
523nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
524 struct nfs_fsinfo *info)
525{
526 struct nfs2_fsstat fsinfo;
dead28da
CL
527 struct rpc_message msg = {
528 .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
529 .rpc_argp = fhandle,
530 .rpc_resp = &fsinfo,
531 };
1da177e4
LT
532 int status;
533
534 dprintk("NFS call fsinfo\n");
0e574af1 535 nfs_fattr_init(info->fattr);
dead28da 536 status = rpc_call_sync(server->client, &msg, 0);
1da177e4
LT
537 dprintk("NFS reply fsinfo: %d\n", status);
538 if (status)
539 goto out;
540 info->rtmax = NFS_MAXDATA;
541 info->rtpref = fsinfo.tsize;
542 info->rtmult = fsinfo.bsize;
543 info->wtmax = NFS_MAXDATA;
544 info->wtpref = fsinfo.tsize;
545 info->wtmult = fsinfo.bsize;
546 info->dtpref = fsinfo.tsize;
547 info->maxfilesize = 0x7FFFFFFF;
548 info->lease_time = 0;
549out:
550 return status;
551}
552
553static int
554nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
555 struct nfs_pathconf *info)
556{
557 info->max_link = 0;
558 info->max_namelen = NFS2_MAXNAMLEN;
559 return 0;
560}
561
ec06c096 562static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
1da177e4 563{
8850df99 564 nfs_invalidate_atime(data->inode);
1da177e4
LT
565 if (task->tk_status >= 0) {
566 nfs_refresh_inode(data->inode, data->res.fattr);
567 /* Emulate the eof flag, which isn't normally needed in NFSv2
568 * as it is guaranteed to always return the file attributes
569 */
570 if (data->args.offset + data->args.count >= data->res.fattr->size)
571 data->res.eof = 1;
572 }
ec06c096 573 return 0;
1da177e4
LT
574}
575
bdc7f021 576static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
1da177e4 577{
bdc7f021 578 msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
1da177e4
LT
579}
580
788e7a89 581static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
1da177e4 582{
1da177e4 583 if (task->tk_status >= 0)
70ca8852 584 nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
788e7a89 585 return 0;
1da177e4
LT
586}
587
bdc7f021 588static void nfs_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
1da177e4 589{
1da177e4
LT
590 /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
591 data->args.stable = NFS_FILE_SYNC;
bdc7f021 592 msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
1da177e4
LT
593}
594
595static void
bdc7f021 596nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
1da177e4
LT
597{
598 BUG();
599}
600
601static int
602nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
603{
1093a60e
CL
604 struct inode *inode = filp->f_path.dentry->d_inode;
605
606 return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
1da177e4
LT
607}
608
2116271a
TM
609/* Helper functions for NFS lock bounds checking */
610#define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
611static int nfs_lock_check_bounds(const struct file_lock *fl)
612{
613 __s32 start, end;
614
615 start = (__s32)fl->fl_start;
616 if ((loff_t)start != fl->fl_start)
617 goto out_einval;
618
619 if (fl->fl_end != OFFSET_MAX) {
620 end = (__s32)fl->fl_end;
621 if ((loff_t)end != fl->fl_end)
622 goto out_einval;
623 } else
624 end = NFS_LOCK32_OFFSET_MAX;
625
626 if (start < 0 || start > end)
627 goto out_einval;
628 return 0;
629out_einval:
630 return -EINVAL;
631}
1da177e4 632
509de811 633const struct nfs_rpc_ops nfs_v2_clientops = {
1da177e4
LT
634 .version = 2, /* protocol version */
635 .dentry_ops = &nfs_dentry_operations,
636 .dir_inode_ops = &nfs_dir_inode_operations,
92cfc62c 637 .file_inode_ops = &nfs_file_inode_operations,
1da177e4
LT
638 .getroot = nfs_proc_get_root,
639 .getattr = nfs_proc_getattr,
640 .setattr = nfs_proc_setattr,
641 .lookup = nfs_proc_lookup,
642 .access = NULL, /* access */
643 .readlink = nfs_proc_readlink,
1da177e4
LT
644 .create = nfs_proc_create,
645 .remove = nfs_proc_remove,
646 .unlink_setup = nfs_proc_unlink_setup,
647 .unlink_done = nfs_proc_unlink_done,
648 .rename = nfs_proc_rename,
649 .link = nfs_proc_link,
650 .symlink = nfs_proc_symlink,
651 .mkdir = nfs_proc_mkdir,
652 .rmdir = nfs_proc_rmdir,
653 .readdir = nfs_proc_readdir,
654 .mknod = nfs_proc_mknod,
655 .statfs = nfs_proc_statfs,
656 .fsinfo = nfs_proc_fsinfo,
657 .pathconf = nfs_proc_pathconf,
658 .decode_dirent = nfs_decode_dirent,
659 .read_setup = nfs_proc_read_setup,
ec06c096 660 .read_done = nfs_read_done,
1da177e4 661 .write_setup = nfs_proc_write_setup,
788e7a89 662 .write_done = nfs_write_done,
1da177e4 663 .commit_setup = nfs_proc_commit_setup,
1da177e4 664 .lock = nfs_proc_lock,
2116271a 665 .lock_check_bounds = nfs_lock_check_bounds,
7fe5c398 666 .close_context = nfs_close_context,
1da177e4 667};