proc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. struct nfs_createdata {
  211. struct nfs_createargs arg;
  212. struct nfs_diropok res;
  213. struct nfs_fh fhandle;
  214. struct nfs_fattr fattr;
  215. };
  216. static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
  217. struct dentry *dentry, struct iattr *sattr)
  218. {
  219. struct nfs_createdata *data;
  220. data = kmalloc(sizeof(*data), GFP_KERNEL);
  221. if (data != NULL) {
  222. data->arg.fh = NFS_FH(dir);
  223. data->arg.name = dentry->d_name.name;
  224. data->arg.len = dentry->d_name.len;
  225. data->arg.sattr = sattr;
  226. nfs_fattr_init(&data->fattr);
  227. data->fhandle.size = 0;
  228. data->res.fh = &data->fhandle;
  229. data->res.fattr = &data->fattr;
  230. }
  231. return data;
  232. };
  233. static void nfs_free_createdata(const struct nfs_createdata *data)
  234. {
  235. kfree(data);
  236. }
  237. static int
  238. nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  239. int flags, struct nameidata *nd)
  240. {
  241. struct nfs_createdata *data;
  242. struct rpc_message msg = {
  243. .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
  244. };
  245. int status = -ENOMEM;
  246. dprintk("NFS call create %s\n", dentry->d_name.name);
  247. data = nfs_alloc_createdata(dir, dentry, sattr);
  248. if (data == NULL)
  249. goto out;
  250. msg.rpc_argp = &data->arg;
  251. msg.rpc_resp = &data->res;
  252. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  253. nfs_mark_for_revalidate(dir);
  254. if (status == 0)
  255. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  256. nfs_free_createdata(data);
  257. out:
  258. dprintk("NFS reply create: %d\n", status);
  259. return status;
  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. dprintk("NFS call mknod %s\n", dentry->d_name.name);
  275. mode = sattr->ia_mode;
  276. if (S_ISFIFO(mode)) {
  277. sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
  278. sattr->ia_valid &= ~ATTR_SIZE;
  279. } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
  280. sattr->ia_valid |= ATTR_SIZE;
  281. sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
  282. }
  283. data = nfs_alloc_createdata(dir, dentry, sattr);
  284. if (data == NULL)
  285. goto out;
  286. msg.rpc_argp = &data->arg;
  287. msg.rpc_resp = &data->res;
  288. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  289. nfs_mark_for_revalidate(dir);
  290. if (status == -EINVAL && S_ISFIFO(mode)) {
  291. sattr->ia_mode = mode;
  292. nfs_fattr_init(data->res.fattr);
  293. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  294. }
  295. if (status == 0)
  296. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  297. nfs_free_createdata(data);
  298. out:
  299. dprintk("NFS reply mknod: %d\n", status);
  300. return status;
  301. }
  302. static int
  303. nfs_proc_remove(struct inode *dir, struct qstr *name)
  304. {
  305. struct nfs_removeargs arg = {
  306. .fh = NFS_FH(dir),
  307. .name.len = name->len,
  308. .name.name = name->name,
  309. };
  310. struct rpc_message msg = {
  311. .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
  312. .rpc_argp = &arg,
  313. };
  314. int status;
  315. dprintk("NFS call remove %s\n", name->name);
  316. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  317. nfs_mark_for_revalidate(dir);
  318. dprintk("NFS reply remove: %d\n", status);
  319. return status;
  320. }
  321. static void
  322. nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  323. {
  324. msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
  325. }
  326. static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  327. {
  328. if (nfs_async_handle_expired_key(task))
  329. return 0;
  330. nfs_mark_for_revalidate(dir);
  331. return 1;
  332. }
  333. static int
  334. nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
  335. struct inode *new_dir, struct qstr *new_name)
  336. {
  337. struct nfs_renameargs arg = {
  338. .fromfh = NFS_FH(old_dir),
  339. .fromname = old_name->name,
  340. .fromlen = old_name->len,
  341. .tofh = NFS_FH(new_dir),
  342. .toname = new_name->name,
  343. .tolen = new_name->len
  344. };
  345. struct rpc_message msg = {
  346. .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
  347. .rpc_argp = &arg,
  348. };
  349. int status;
  350. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  351. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  352. nfs_mark_for_revalidate(old_dir);
  353. nfs_mark_for_revalidate(new_dir);
  354. dprintk("NFS reply rename: %d\n", status);
  355. return status;
  356. }
  357. static int
  358. nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  359. {
  360. struct nfs_linkargs arg = {
  361. .fromfh = NFS_FH(inode),
  362. .tofh = NFS_FH(dir),
  363. .toname = name->name,
  364. .tolen = name->len
  365. };
  366. struct rpc_message msg = {
  367. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  368. .rpc_argp = &arg,
  369. };
  370. int status;
  371. dprintk("NFS call link %s\n", name->name);
  372. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  373. nfs_mark_for_revalidate(inode);
  374. nfs_mark_for_revalidate(dir);
  375. dprintk("NFS reply link: %d\n", status);
  376. return status;
  377. }
  378. static int
  379. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  380. unsigned int len, struct iattr *sattr)
  381. {
  382. struct nfs_fh fhandle;
  383. struct nfs_fattr fattr;
  384. struct nfs_symlinkargs arg = {
  385. .fromfh = NFS_FH(dir),
  386. .fromname = dentry->d_name.name,
  387. .fromlen = dentry->d_name.len,
  388. .pages = &page,
  389. .pathlen = len,
  390. .sattr = sattr
  391. };
  392. struct rpc_message msg = {
  393. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  394. .rpc_argp = &arg,
  395. };
  396. int status;
  397. if (len > NFS2_MAXPATHLEN)
  398. return -ENAMETOOLONG;
  399. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  400. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  401. nfs_mark_for_revalidate(dir);
  402. /*
  403. * V2 SYMLINK requests don't return any attributes. Setting the
  404. * filehandle size to zero indicates to nfs_instantiate that it
  405. * should fill in the data with a LOOKUP call on the wire.
  406. */
  407. if (status == 0) {
  408. nfs_fattr_init(&fattr);
  409. fhandle.size = 0;
  410. status = nfs_instantiate(dentry, &fhandle, &fattr);
  411. }
  412. dprintk("NFS reply symlink: %d\n", status);
  413. return status;
  414. }
  415. static int
  416. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  417. {
  418. struct nfs_createdata *data;
  419. struct rpc_message msg = {
  420. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  421. };
  422. int status = -ENOMEM;
  423. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  424. data = nfs_alloc_createdata(dir, dentry, sattr);
  425. if (data == NULL)
  426. goto out;
  427. msg.rpc_argp = &data->arg;
  428. msg.rpc_resp = &data->res;
  429. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  430. nfs_mark_for_revalidate(dir);
  431. if (status == 0)
  432. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  433. nfs_free_createdata(data);
  434. out:
  435. dprintk("NFS reply mkdir: %d\n", status);
  436. return status;
  437. }
  438. static int
  439. nfs_proc_rmdir(struct inode *dir, struct qstr *name)
  440. {
  441. struct nfs_diropargs arg = {
  442. .fh = NFS_FH(dir),
  443. .name = name->name,
  444. .len = name->len
  445. };
  446. struct rpc_message msg = {
  447. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  448. .rpc_argp = &arg,
  449. };
  450. int status;
  451. dprintk("NFS call rmdir %s\n", name->name);
  452. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  453. nfs_mark_for_revalidate(dir);
  454. dprintk("NFS reply rmdir: %d\n", status);
  455. return status;
  456. }
  457. /*
  458. * The READDIR implementation is somewhat hackish - we pass a temporary
  459. * buffer to the encode function, which installs it in the receive
  460. * the receive iovec. The decode function just parses the reply to make
  461. * sure it is syntactically correct; the entries itself are decoded
  462. * from nfs_readdir by calling the decode_entry function directly.
  463. */
  464. static int
  465. nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  466. u64 cookie, struct page *page, unsigned int count, int plus)
  467. {
  468. struct inode *dir = dentry->d_inode;
  469. struct nfs_readdirargs arg = {
  470. .fh = NFS_FH(dir),
  471. .cookie = cookie,
  472. .count = count,
  473. .pages = &page,
  474. };
  475. struct rpc_message msg = {
  476. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  477. .rpc_argp = &arg,
  478. .rpc_cred = cred,
  479. };
  480. int status;
  481. dprintk("NFS call readdir %d\n", (unsigned int)cookie);
  482. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  483. nfs_invalidate_atime(dir);
  484. dprintk("NFS reply readdir: %d\n", status);
  485. return status;
  486. }
  487. static int
  488. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  489. struct nfs_fsstat *stat)
  490. {
  491. struct nfs2_fsstat fsinfo;
  492. struct rpc_message msg = {
  493. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  494. .rpc_argp = fhandle,
  495. .rpc_resp = &fsinfo,
  496. };
  497. int status;
  498. dprintk("NFS call statfs\n");
  499. nfs_fattr_init(stat->fattr);
  500. status = rpc_call_sync(server->client, &msg, 0);
  501. dprintk("NFS reply statfs: %d\n", status);
  502. if (status)
  503. goto out;
  504. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  505. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  506. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  507. stat->tfiles = 0;
  508. stat->ffiles = 0;
  509. stat->afiles = 0;
  510. out:
  511. return status;
  512. }
  513. static int
  514. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  515. struct nfs_fsinfo *info)
  516. {
  517. struct nfs2_fsstat fsinfo;
  518. struct rpc_message msg = {
  519. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  520. .rpc_argp = fhandle,
  521. .rpc_resp = &fsinfo,
  522. };
  523. int status;
  524. dprintk("NFS call fsinfo\n");
  525. nfs_fattr_init(info->fattr);
  526. status = rpc_call_sync(server->client, &msg, 0);
  527. dprintk("NFS reply fsinfo: %d\n", status);
  528. if (status)
  529. goto out;
  530. info->rtmax = NFS_MAXDATA;
  531. info->rtpref = fsinfo.tsize;
  532. info->rtmult = fsinfo.bsize;
  533. info->wtmax = NFS_MAXDATA;
  534. info->wtpref = fsinfo.tsize;
  535. info->wtmult = fsinfo.bsize;
  536. info->dtpref = fsinfo.tsize;
  537. info->maxfilesize = 0x7FFFFFFF;
  538. info->lease_time = 0;
  539. out:
  540. return status;
  541. }
  542. static int
  543. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  544. struct nfs_pathconf *info)
  545. {
  546. info->max_link = 0;
  547. info->max_namelen = NFS2_MAXNAMLEN;
  548. return 0;
  549. }
  550. static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
  551. {
  552. if (nfs_async_handle_expired_key(task))
  553. return -EAGAIN;
  554. nfs_invalidate_atime(data->inode);
  555. if (task->tk_status >= 0) {
  556. nfs_refresh_inode(data->inode, data->res.fattr);
  557. /* Emulate the eof flag, which isn't normally needed in NFSv2
  558. * as it is guaranteed to always return the file attributes
  559. */
  560. if (data->args.offset + data->args.count >= data->res.fattr->size)
  561. data->res.eof = 1;
  562. }
  563. return 0;
  564. }
  565. static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  566. {
  567. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  568. }
  569. static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
  570. {
  571. if (nfs_async_handle_expired_key(task))
  572. return -EAGAIN;
  573. if (task->tk_status >= 0)
  574. nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
  575. return 0;
  576. }
  577. static void nfs_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  578. {
  579. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  580. data->args.stable = NFS_FILE_SYNC;
  581. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  582. }
  583. static void
  584. nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  585. {
  586. BUG();
  587. }
  588. static int
  589. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  590. {
  591. struct inode *inode = filp->f_path.dentry->d_inode;
  592. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  593. }
  594. /* Helper functions for NFS lock bounds checking */
  595. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  596. static int nfs_lock_check_bounds(const struct file_lock *fl)
  597. {
  598. __s32 start, end;
  599. start = (__s32)fl->fl_start;
  600. if ((loff_t)start != fl->fl_start)
  601. goto out_einval;
  602. if (fl->fl_end != OFFSET_MAX) {
  603. end = (__s32)fl->fl_end;
  604. if ((loff_t)end != fl->fl_end)
  605. goto out_einval;
  606. } else
  607. end = NFS_LOCK32_OFFSET_MAX;
  608. if (start < 0 || start > end)
  609. goto out_einval;
  610. return 0;
  611. out_einval:
  612. return -EINVAL;
  613. }
  614. const struct nfs_rpc_ops nfs_v2_clientops = {
  615. .version = 2, /* protocol version */
  616. .dentry_ops = &nfs_dentry_operations,
  617. .dir_inode_ops = &nfs_dir_inode_operations,
  618. .file_inode_ops = &nfs_file_inode_operations,
  619. .getroot = nfs_proc_get_root,
  620. .getattr = nfs_proc_getattr,
  621. .setattr = nfs_proc_setattr,
  622. .lookup = nfs_proc_lookup,
  623. .access = NULL, /* access */
  624. .readlink = nfs_proc_readlink,
  625. .create = nfs_proc_create,
  626. .remove = nfs_proc_remove,
  627. .unlink_setup = nfs_proc_unlink_setup,
  628. .unlink_done = nfs_proc_unlink_done,
  629. .rename = nfs_proc_rename,
  630. .link = nfs_proc_link,
  631. .symlink = nfs_proc_symlink,
  632. .mkdir = nfs_proc_mkdir,
  633. .rmdir = nfs_proc_rmdir,
  634. .readdir = nfs_proc_readdir,
  635. .mknod = nfs_proc_mknod,
  636. .statfs = nfs_proc_statfs,
  637. .fsinfo = nfs_proc_fsinfo,
  638. .pathconf = nfs_proc_pathconf,
  639. .decode_dirent = nfs_decode_dirent,
  640. .read_setup = nfs_proc_read_setup,
  641. .read_done = nfs_read_done,
  642. .write_setup = nfs_proc_write_setup,
  643. .write_done = nfs_write_done,
  644. .commit_setup = nfs_proc_commit_setup,
  645. .lock = nfs_proc_lock,
  646. .lock_check_bounds = nfs_lock_check_bounds,
  647. .close_context = nfs_close_context,
  648. };