proc.c 19 KB

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