proc.c 17 KB

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