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