proc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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 nfs_open_context *ctx)
  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. .old_dir = NFS_FH(old_dir),
  339. .old_name = old_name,
  340. .new_dir = NFS_FH(new_dir),
  341. .new_name = new_name,
  342. };
  343. struct rpc_message msg = {
  344. .rpc_proc = &nfs_procedures[NFSPROC_RENAME],
  345. .rpc_argp = &arg,
  346. };
  347. int status;
  348. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  349. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  350. nfs_mark_for_revalidate(old_dir);
  351. nfs_mark_for_revalidate(new_dir);
  352. dprintk("NFS reply rename: %d\n", status);
  353. return status;
  354. }
  355. static int
  356. nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  357. {
  358. struct nfs_linkargs arg = {
  359. .fromfh = NFS_FH(inode),
  360. .tofh = NFS_FH(dir),
  361. .toname = name->name,
  362. .tolen = name->len
  363. };
  364. struct rpc_message msg = {
  365. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  366. .rpc_argp = &arg,
  367. };
  368. int status;
  369. dprintk("NFS call link %s\n", name->name);
  370. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  371. nfs_mark_for_revalidate(inode);
  372. nfs_mark_for_revalidate(dir);
  373. dprintk("NFS reply link: %d\n", status);
  374. return status;
  375. }
  376. static int
  377. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  378. unsigned int len, struct iattr *sattr)
  379. {
  380. struct nfs_fh *fh;
  381. struct nfs_fattr *fattr;
  382. struct nfs_symlinkargs arg = {
  383. .fromfh = NFS_FH(dir),
  384. .fromname = dentry->d_name.name,
  385. .fromlen = dentry->d_name.len,
  386. .pages = &page,
  387. .pathlen = len,
  388. .sattr = sattr
  389. };
  390. struct rpc_message msg = {
  391. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  392. .rpc_argp = &arg,
  393. };
  394. int status = -ENAMETOOLONG;
  395. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  396. if (len > NFS2_MAXPATHLEN)
  397. goto out;
  398. fh = nfs_alloc_fhandle();
  399. fattr = nfs_alloc_fattr();
  400. status = -ENOMEM;
  401. if (fh == NULL || fattr == NULL)
  402. goto out;
  403. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  404. nfs_mark_for_revalidate(dir);
  405. /*
  406. * V2 SYMLINK requests don't return any attributes. Setting the
  407. * filehandle size to zero indicates to nfs_instantiate that it
  408. * should fill in the data with a LOOKUP call on the wire.
  409. */
  410. if (status == 0)
  411. status = nfs_instantiate(dentry, fh, fattr);
  412. nfs_free_fattr(fattr);
  413. nfs_free_fhandle(fh);
  414. out:
  415. dprintk("NFS reply symlink: %d\n", status);
  416. return status;
  417. }
  418. static int
  419. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  420. {
  421. struct nfs_createdata *data;
  422. struct rpc_message msg = {
  423. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  424. };
  425. int status = -ENOMEM;
  426. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  427. data = nfs_alloc_createdata(dir, dentry, sattr);
  428. if (data == NULL)
  429. goto out;
  430. msg.rpc_argp = &data->arg;
  431. msg.rpc_resp = &data->res;
  432. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  433. nfs_mark_for_revalidate(dir);
  434. if (status == 0)
  435. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  436. nfs_free_createdata(data);
  437. out:
  438. dprintk("NFS reply mkdir: %d\n", status);
  439. return status;
  440. }
  441. static int
  442. nfs_proc_rmdir(struct inode *dir, struct qstr *name)
  443. {
  444. struct nfs_diropargs arg = {
  445. .fh = NFS_FH(dir),
  446. .name = name->name,
  447. .len = name->len
  448. };
  449. struct rpc_message msg = {
  450. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  451. .rpc_argp = &arg,
  452. };
  453. int status;
  454. dprintk("NFS call rmdir %s\n", name->name);
  455. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  456. nfs_mark_for_revalidate(dir);
  457. dprintk("NFS reply rmdir: %d\n", status);
  458. return status;
  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. */
  467. static int
  468. nfs_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,
  476. .pages = &page,
  477. };
  478. struct rpc_message msg = {
  479. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  480. .rpc_argp = &arg,
  481. .rpc_cred = cred,
  482. };
  483. int status;
  484. dprintk("NFS call readdir %d\n", (unsigned int)cookie);
  485. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  486. nfs_invalidate_atime(dir);
  487. dprintk("NFS reply readdir: %d\n", status);
  488. return status;
  489. }
  490. static int
  491. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  492. struct nfs_fsstat *stat)
  493. {
  494. struct nfs2_fsstat fsinfo;
  495. struct rpc_message msg = {
  496. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  497. .rpc_argp = fhandle,
  498. .rpc_resp = &fsinfo,
  499. };
  500. int status;
  501. dprintk("NFS call statfs\n");
  502. nfs_fattr_init(stat->fattr);
  503. status = rpc_call_sync(server->client, &msg, 0);
  504. dprintk("NFS reply statfs: %d\n", status);
  505. if (status)
  506. goto out;
  507. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  508. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  509. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  510. stat->tfiles = 0;
  511. stat->ffiles = 0;
  512. stat->afiles = 0;
  513. out:
  514. return status;
  515. }
  516. static int
  517. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  518. struct nfs_fsinfo *info)
  519. {
  520. struct nfs2_fsstat fsinfo;
  521. struct rpc_message msg = {
  522. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  523. .rpc_argp = fhandle,
  524. .rpc_resp = &fsinfo,
  525. };
  526. int status;
  527. dprintk("NFS call fsinfo\n");
  528. nfs_fattr_init(info->fattr);
  529. status = rpc_call_sync(server->client, &msg, 0);
  530. dprintk("NFS reply fsinfo: %d\n", status);
  531. if (status)
  532. goto out;
  533. info->rtmax = NFS_MAXDATA;
  534. info->rtpref = fsinfo.tsize;
  535. info->rtmult = fsinfo.bsize;
  536. info->wtmax = NFS_MAXDATA;
  537. info->wtpref = fsinfo.tsize;
  538. info->wtmult = fsinfo.bsize;
  539. info->dtpref = fsinfo.tsize;
  540. info->maxfilesize = 0x7FFFFFFF;
  541. info->lease_time = 0;
  542. out:
  543. return status;
  544. }
  545. static int
  546. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  547. struct nfs_pathconf *info)
  548. {
  549. info->max_link = 0;
  550. info->max_namelen = NFS2_MAXNAMLEN;
  551. return 0;
  552. }
  553. static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data)
  554. {
  555. if (nfs_async_handle_expired_key(task))
  556. return -EAGAIN;
  557. nfs_invalidate_atime(data->inode);
  558. if (task->tk_status >= 0) {
  559. nfs_refresh_inode(data->inode, data->res.fattr);
  560. /* Emulate the eof flag, which isn't normally needed in NFSv2
  561. * as it is guaranteed to always return the file attributes
  562. */
  563. if (data->args.offset + data->args.count >= data->res.fattr->size)
  564. data->res.eof = 1;
  565. }
  566. return 0;
  567. }
  568. static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  569. {
  570. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  571. }
  572. static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
  573. {
  574. if (nfs_async_handle_expired_key(task))
  575. return -EAGAIN;
  576. if (task->tk_status >= 0)
  577. nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
  578. return 0;
  579. }
  580. static void nfs_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  581. {
  582. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  583. data->args.stable = NFS_FILE_SYNC;
  584. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  585. }
  586. static void
  587. nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  588. {
  589. BUG();
  590. }
  591. static int
  592. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  593. {
  594. struct inode *inode = filp->f_path.dentry->d_inode;
  595. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  596. }
  597. /* Helper functions for NFS lock bounds checking */
  598. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  599. static int nfs_lock_check_bounds(const struct file_lock *fl)
  600. {
  601. __s32 start, end;
  602. start = (__s32)fl->fl_start;
  603. if ((loff_t)start != fl->fl_start)
  604. goto out_einval;
  605. if (fl->fl_end != OFFSET_MAX) {
  606. end = (__s32)fl->fl_end;
  607. if ((loff_t)end != fl->fl_end)
  608. goto out_einval;
  609. } else
  610. end = NFS_LOCK32_OFFSET_MAX;
  611. if (start < 0 || start > end)
  612. goto out_einval;
  613. return 0;
  614. out_einval:
  615. return -EINVAL;
  616. }
  617. const struct nfs_rpc_ops nfs_v2_clientops = {
  618. .version = 2, /* protocol version */
  619. .dentry_ops = &nfs_dentry_operations,
  620. .dir_inode_ops = &nfs_dir_inode_operations,
  621. .file_inode_ops = &nfs_file_inode_operations,
  622. .getroot = nfs_proc_get_root,
  623. .getattr = nfs_proc_getattr,
  624. .setattr = nfs_proc_setattr,
  625. .lookup = nfs_proc_lookup,
  626. .access = NULL, /* access */
  627. .readlink = nfs_proc_readlink,
  628. .create = nfs_proc_create,
  629. .remove = nfs_proc_remove,
  630. .unlink_setup = nfs_proc_unlink_setup,
  631. .unlink_done = nfs_proc_unlink_done,
  632. .rename = nfs_proc_rename,
  633. .link = nfs_proc_link,
  634. .symlink = nfs_proc_symlink,
  635. .mkdir = nfs_proc_mkdir,
  636. .rmdir = nfs_proc_rmdir,
  637. .readdir = nfs_proc_readdir,
  638. .mknod = nfs_proc_mknod,
  639. .statfs = nfs_proc_statfs,
  640. .fsinfo = nfs_proc_fsinfo,
  641. .pathconf = nfs_proc_pathconf,
  642. .decode_dirent = nfs_decode_dirent,
  643. .read_setup = nfs_proc_read_setup,
  644. .read_done = nfs_read_done,
  645. .write_setup = nfs_proc_write_setup,
  646. .write_done = nfs_write_done,
  647. .commit_setup = nfs_proc_commit_setup,
  648. .lock = nfs_proc_lock,
  649. .lock_check_bounds = nfs_lock_check_bounds,
  650. .close_context = nfs_close_context,
  651. };