proc.c 17 KB

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