proc.c 17 KB

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