proc.c 18 KB

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