nfs3proc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /*
  2. * linux/fs/nfs/nfs3proc.c
  3. *
  4. * Client-side NFSv3 procedures stubs.
  5. *
  6. * Copyright (C) 1997, Olaf Kirch
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/utsname.h>
  10. #include <linux/errno.h>
  11. #include <linux/string.h>
  12. #include <linux/sunrpc/clnt.h>
  13. #include <linux/nfs.h>
  14. #include <linux/nfs3.h>
  15. #include <linux/nfs_fs.h>
  16. #include <linux/nfs_page.h>
  17. #include <linux/lockd/bind.h>
  18. #include <linux/nfs_mount.h>
  19. #include "iostat.h"
  20. #include "internal.h"
  21. #define NFSDBG_FACILITY NFSDBG_PROC
  22. /* A wrapper to handle the EJUKEBOX error message */
  23. static int
  24. nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
  25. {
  26. int res;
  27. do {
  28. res = rpc_call_sync(clnt, msg, flags);
  29. if (res != -EJUKEBOX)
  30. break;
  31. schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME);
  32. res = -ERESTARTSYS;
  33. } while (!fatal_signal_pending(current));
  34. return res;
  35. }
  36. #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags)
  37. static int
  38. nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
  39. {
  40. if (task->tk_status != -EJUKEBOX)
  41. return 0;
  42. nfs_inc_stats(inode, NFSIOS_DELAY);
  43. task->tk_status = 0;
  44. rpc_restart_call(task);
  45. rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
  46. return 1;
  47. }
  48. static int
  49. do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
  50. struct nfs_fsinfo *info)
  51. {
  52. struct rpc_message msg = {
  53. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  54. .rpc_argp = fhandle,
  55. .rpc_resp = info,
  56. };
  57. int status;
  58. dprintk("%s: call fsinfo\n", __FUNCTION__);
  59. nfs_fattr_init(info->fattr);
  60. status = rpc_call_sync(client, &msg, 0);
  61. dprintk("%s: reply fsinfo: %d\n", __FUNCTION__, status);
  62. if (!(info->fattr->valid & NFS_ATTR_FATTR)) {
  63. msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
  64. msg.rpc_resp = info->fattr;
  65. status = rpc_call_sync(client, &msg, 0);
  66. dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
  67. }
  68. return status;
  69. }
  70. /*
  71. * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
  72. */
  73. static int
  74. nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  75. struct nfs_fsinfo *info)
  76. {
  77. int status;
  78. status = do_proc_get_root(server->client, fhandle, info);
  79. if (status && server->nfs_client->cl_rpcclient != server->client)
  80. status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
  81. return status;
  82. }
  83. /*
  84. * One function for each procedure in the NFS protocol.
  85. */
  86. static int
  87. nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
  88. struct nfs_fattr *fattr)
  89. {
  90. struct rpc_message msg = {
  91. .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
  92. .rpc_argp = fhandle,
  93. .rpc_resp = fattr,
  94. };
  95. int status;
  96. dprintk("NFS call getattr\n");
  97. nfs_fattr_init(fattr);
  98. status = rpc_call_sync(server->client, &msg, 0);
  99. dprintk("NFS reply getattr: %d\n", status);
  100. return status;
  101. }
  102. static int
  103. nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  104. struct iattr *sattr)
  105. {
  106. struct inode *inode = dentry->d_inode;
  107. struct nfs3_sattrargs arg = {
  108. .fh = NFS_FH(inode),
  109. .sattr = sattr,
  110. };
  111. struct rpc_message msg = {
  112. .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
  113. .rpc_argp = &arg,
  114. .rpc_resp = fattr,
  115. };
  116. int status;
  117. dprintk("NFS call setattr\n");
  118. nfs_fattr_init(fattr);
  119. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  120. if (status == 0)
  121. nfs_setattr_update_inode(inode, sattr);
  122. dprintk("NFS reply setattr: %d\n", status);
  123. return status;
  124. }
  125. static int
  126. nfs3_proc_lookup(struct inode *dir, struct qstr *name,
  127. struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  128. {
  129. struct nfs_fattr dir_attr;
  130. struct nfs3_diropargs arg = {
  131. .fh = NFS_FH(dir),
  132. .name = name->name,
  133. .len = name->len
  134. };
  135. struct nfs3_diropres res = {
  136. .dir_attr = &dir_attr,
  137. .fh = fhandle,
  138. .fattr = fattr
  139. };
  140. struct rpc_message msg = {
  141. .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
  142. .rpc_argp = &arg,
  143. .rpc_resp = &res,
  144. };
  145. int status;
  146. dprintk("NFS call lookup %s\n", name->name);
  147. nfs_fattr_init(&dir_attr);
  148. nfs_fattr_init(fattr);
  149. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  150. nfs_refresh_inode(dir, &dir_attr);
  151. if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
  152. msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
  153. msg.rpc_argp = fhandle;
  154. msg.rpc_resp = fattr;
  155. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  156. }
  157. dprintk("NFS reply lookup: %d\n", status);
  158. return status;
  159. }
  160. static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  161. {
  162. struct nfs_fattr fattr;
  163. struct nfs3_accessargs arg = {
  164. .fh = NFS_FH(inode),
  165. };
  166. struct nfs3_accessres res = {
  167. .fattr = &fattr,
  168. };
  169. struct rpc_message msg = {
  170. .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
  171. .rpc_argp = &arg,
  172. .rpc_resp = &res,
  173. .rpc_cred = entry->cred,
  174. };
  175. int mode = entry->mask;
  176. int status;
  177. dprintk("NFS call access\n");
  178. if (mode & MAY_READ)
  179. arg.access |= NFS3_ACCESS_READ;
  180. if (S_ISDIR(inode->i_mode)) {
  181. if (mode & MAY_WRITE)
  182. arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
  183. if (mode & MAY_EXEC)
  184. arg.access |= NFS3_ACCESS_LOOKUP;
  185. } else {
  186. if (mode & MAY_WRITE)
  187. arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
  188. if (mode & MAY_EXEC)
  189. arg.access |= NFS3_ACCESS_EXECUTE;
  190. }
  191. nfs_fattr_init(&fattr);
  192. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  193. nfs_refresh_inode(inode, &fattr);
  194. if (status == 0) {
  195. entry->mask = 0;
  196. if (res.access & NFS3_ACCESS_READ)
  197. entry->mask |= MAY_READ;
  198. if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
  199. entry->mask |= MAY_WRITE;
  200. if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
  201. entry->mask |= MAY_EXEC;
  202. }
  203. dprintk("NFS reply access: %d\n", status);
  204. return status;
  205. }
  206. static int nfs3_proc_readlink(struct inode *inode, struct page *page,
  207. unsigned int pgbase, unsigned int pglen)
  208. {
  209. struct nfs_fattr fattr;
  210. struct nfs3_readlinkargs args = {
  211. .fh = NFS_FH(inode),
  212. .pgbase = pgbase,
  213. .pglen = pglen,
  214. .pages = &page
  215. };
  216. struct rpc_message msg = {
  217. .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
  218. .rpc_argp = &args,
  219. .rpc_resp = &fattr,
  220. };
  221. int status;
  222. dprintk("NFS call readlink\n");
  223. nfs_fattr_init(&fattr);
  224. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  225. nfs_refresh_inode(inode, &fattr);
  226. dprintk("NFS reply readlink: %d\n", status);
  227. return status;
  228. }
  229. /*
  230. * Create a regular file.
  231. * For now, we don't implement O_EXCL.
  232. */
  233. static int
  234. nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  235. int flags, struct nameidata *nd)
  236. {
  237. struct nfs_fh fhandle;
  238. struct nfs_fattr fattr;
  239. struct nfs_fattr dir_attr;
  240. struct nfs3_createargs arg = {
  241. .fh = NFS_FH(dir),
  242. .name = dentry->d_name.name,
  243. .len = dentry->d_name.len,
  244. .sattr = sattr,
  245. };
  246. struct nfs3_diropres res = {
  247. .dir_attr = &dir_attr,
  248. .fh = &fhandle,
  249. .fattr = &fattr
  250. };
  251. struct rpc_message msg = {
  252. .rpc_proc = &nfs3_procedures[NFS3PROC_CREATE],
  253. .rpc_argp = &arg,
  254. .rpc_resp = &res,
  255. };
  256. mode_t mode = sattr->ia_mode;
  257. int status;
  258. dprintk("NFS call create %s\n", dentry->d_name.name);
  259. arg.createmode = NFS3_CREATE_UNCHECKED;
  260. if (flags & O_EXCL) {
  261. arg.createmode = NFS3_CREATE_EXCLUSIVE;
  262. arg.verifier[0] = jiffies;
  263. arg.verifier[1] = current->pid;
  264. }
  265. sattr->ia_mode &= ~current->fs->umask;
  266. again:
  267. nfs_fattr_init(&dir_attr);
  268. nfs_fattr_init(&fattr);
  269. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  270. nfs_refresh_inode(dir, &dir_attr);
  271. /* If the server doesn't support the exclusive creation semantics,
  272. * try again with simple 'guarded' mode. */
  273. if (status == -ENOTSUPP) {
  274. switch (arg.createmode) {
  275. case NFS3_CREATE_EXCLUSIVE:
  276. arg.createmode = NFS3_CREATE_GUARDED;
  277. break;
  278. case NFS3_CREATE_GUARDED:
  279. arg.createmode = NFS3_CREATE_UNCHECKED;
  280. break;
  281. case NFS3_CREATE_UNCHECKED:
  282. goto out;
  283. }
  284. goto again;
  285. }
  286. if (status == 0)
  287. status = nfs_instantiate(dentry, &fhandle, &fattr);
  288. if (status != 0)
  289. goto out;
  290. /* When we created the file with exclusive semantics, make
  291. * sure we set the attributes afterwards. */
  292. if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
  293. dprintk("NFS call setattr (post-create)\n");
  294. if (!(sattr->ia_valid & ATTR_ATIME_SET))
  295. sattr->ia_valid |= ATTR_ATIME;
  296. if (!(sattr->ia_valid & ATTR_MTIME_SET))
  297. sattr->ia_valid |= ATTR_MTIME;
  298. /* Note: we could use a guarded setattr here, but I'm
  299. * not sure this buys us anything (and I'd have
  300. * to revamp the NFSv3 XDR code) */
  301. status = nfs3_proc_setattr(dentry, &fattr, sattr);
  302. nfs_post_op_update_inode(dentry->d_inode, &fattr);
  303. dprintk("NFS reply setattr (post-create): %d\n", status);
  304. }
  305. if (status != 0)
  306. goto out;
  307. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  308. out:
  309. dprintk("NFS reply create: %d\n", status);
  310. return status;
  311. }
  312. static int
  313. nfs3_proc_remove(struct inode *dir, struct qstr *name)
  314. {
  315. struct nfs_removeargs arg = {
  316. .fh = NFS_FH(dir),
  317. .name.len = name->len,
  318. .name.name = name->name,
  319. };
  320. struct nfs_removeres res;
  321. struct rpc_message msg = {
  322. .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
  323. .rpc_argp = &arg,
  324. .rpc_resp = &res,
  325. };
  326. int status;
  327. dprintk("NFS call remove %s\n", name->name);
  328. nfs_fattr_init(&res.dir_attr);
  329. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  330. nfs_post_op_update_inode(dir, &res.dir_attr);
  331. dprintk("NFS reply remove: %d\n", status);
  332. return status;
  333. }
  334. static void
  335. nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  336. {
  337. msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
  338. }
  339. static int
  340. nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  341. {
  342. struct nfs_removeres *res;
  343. if (nfs3_async_handle_jukebox(task, dir))
  344. return 0;
  345. res = task->tk_msg.rpc_resp;
  346. nfs_post_op_update_inode(dir, &res->dir_attr);
  347. return 1;
  348. }
  349. static int
  350. nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
  351. struct inode *new_dir, struct qstr *new_name)
  352. {
  353. struct nfs_fattr old_dir_attr, new_dir_attr;
  354. struct nfs3_renameargs arg = {
  355. .fromfh = NFS_FH(old_dir),
  356. .fromname = old_name->name,
  357. .fromlen = old_name->len,
  358. .tofh = NFS_FH(new_dir),
  359. .toname = new_name->name,
  360. .tolen = new_name->len
  361. };
  362. struct nfs3_renameres res = {
  363. .fromattr = &old_dir_attr,
  364. .toattr = &new_dir_attr
  365. };
  366. struct rpc_message msg = {
  367. .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME],
  368. .rpc_argp = &arg,
  369. .rpc_resp = &res,
  370. };
  371. int status;
  372. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  373. nfs_fattr_init(&old_dir_attr);
  374. nfs_fattr_init(&new_dir_attr);
  375. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  376. nfs_post_op_update_inode(old_dir, &old_dir_attr);
  377. nfs_post_op_update_inode(new_dir, &new_dir_attr);
  378. dprintk("NFS reply rename: %d\n", status);
  379. return status;
  380. }
  381. static int
  382. nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  383. {
  384. struct nfs_fattr dir_attr, fattr;
  385. struct nfs3_linkargs arg = {
  386. .fromfh = NFS_FH(inode),
  387. .tofh = NFS_FH(dir),
  388. .toname = name->name,
  389. .tolen = name->len
  390. };
  391. struct nfs3_linkres res = {
  392. .dir_attr = &dir_attr,
  393. .fattr = &fattr
  394. };
  395. struct rpc_message msg = {
  396. .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
  397. .rpc_argp = &arg,
  398. .rpc_resp = &res,
  399. };
  400. int status;
  401. dprintk("NFS call link %s\n", name->name);
  402. nfs_fattr_init(&dir_attr);
  403. nfs_fattr_init(&fattr);
  404. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  405. nfs_post_op_update_inode(dir, &dir_attr);
  406. nfs_post_op_update_inode(inode, &fattr);
  407. dprintk("NFS reply link: %d\n", status);
  408. return status;
  409. }
  410. static int
  411. nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  412. unsigned int len, struct iattr *sattr)
  413. {
  414. struct nfs_fh fhandle;
  415. struct nfs_fattr fattr, dir_attr;
  416. struct nfs3_symlinkargs arg = {
  417. .fromfh = NFS_FH(dir),
  418. .fromname = dentry->d_name.name,
  419. .fromlen = dentry->d_name.len,
  420. .pages = &page,
  421. .pathlen = len,
  422. .sattr = sattr
  423. };
  424. struct nfs3_diropres res = {
  425. .dir_attr = &dir_attr,
  426. .fh = &fhandle,
  427. .fattr = &fattr
  428. };
  429. struct rpc_message msg = {
  430. .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK],
  431. .rpc_argp = &arg,
  432. .rpc_resp = &res,
  433. };
  434. int status;
  435. if (len > NFS3_MAXPATHLEN)
  436. return -ENAMETOOLONG;
  437. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  438. nfs_fattr_init(&dir_attr);
  439. nfs_fattr_init(&fattr);
  440. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  441. nfs_post_op_update_inode(dir, &dir_attr);
  442. if (status != 0)
  443. goto out;
  444. status = nfs_instantiate(dentry, &fhandle, &fattr);
  445. out:
  446. dprintk("NFS reply symlink: %d\n", status);
  447. return status;
  448. }
  449. static int
  450. nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  451. {
  452. struct nfs_fh fhandle;
  453. struct nfs_fattr fattr, dir_attr;
  454. struct nfs3_mkdirargs arg = {
  455. .fh = NFS_FH(dir),
  456. .name = dentry->d_name.name,
  457. .len = dentry->d_name.len,
  458. .sattr = sattr
  459. };
  460. struct nfs3_diropres res = {
  461. .dir_attr = &dir_attr,
  462. .fh = &fhandle,
  463. .fattr = &fattr
  464. };
  465. struct rpc_message msg = {
  466. .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR],
  467. .rpc_argp = &arg,
  468. .rpc_resp = &res,
  469. };
  470. int mode = sattr->ia_mode;
  471. int status;
  472. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  473. sattr->ia_mode &= ~current->fs->umask;
  474. nfs_fattr_init(&dir_attr);
  475. nfs_fattr_init(&fattr);
  476. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  477. nfs_post_op_update_inode(dir, &dir_attr);
  478. if (status != 0)
  479. goto out;
  480. status = nfs_instantiate(dentry, &fhandle, &fattr);
  481. if (status != 0)
  482. goto out;
  483. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  484. out:
  485. dprintk("NFS reply mkdir: %d\n", status);
  486. return status;
  487. }
  488. static int
  489. nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
  490. {
  491. struct nfs_fattr dir_attr;
  492. struct nfs3_diropargs arg = {
  493. .fh = NFS_FH(dir),
  494. .name = name->name,
  495. .len = name->len
  496. };
  497. struct rpc_message msg = {
  498. .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
  499. .rpc_argp = &arg,
  500. .rpc_resp = &dir_attr,
  501. };
  502. int status;
  503. dprintk("NFS call rmdir %s\n", name->name);
  504. nfs_fattr_init(&dir_attr);
  505. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  506. nfs_post_op_update_inode(dir, &dir_attr);
  507. dprintk("NFS reply rmdir: %d\n", status);
  508. return status;
  509. }
  510. /*
  511. * The READDIR implementation is somewhat hackish - we pass the user buffer
  512. * to the encode function, which installs it in the receive iovec.
  513. * The decode function itself doesn't perform any decoding, it just makes
  514. * sure the reply is syntactically correct.
  515. *
  516. * Also note that this implementation handles both plain readdir and
  517. * readdirplus.
  518. */
  519. static int
  520. nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  521. u64 cookie, struct page *page, unsigned int count, int plus)
  522. {
  523. struct inode *dir = dentry->d_inode;
  524. struct nfs_fattr dir_attr;
  525. __be32 *verf = NFS_COOKIEVERF(dir);
  526. struct nfs3_readdirargs arg = {
  527. .fh = NFS_FH(dir),
  528. .cookie = cookie,
  529. .verf = {verf[0], verf[1]},
  530. .plus = plus,
  531. .count = count,
  532. .pages = &page
  533. };
  534. struct nfs3_readdirres res = {
  535. .dir_attr = &dir_attr,
  536. .verf = verf,
  537. .plus = plus
  538. };
  539. struct rpc_message msg = {
  540. .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
  541. .rpc_argp = &arg,
  542. .rpc_resp = &res,
  543. .rpc_cred = cred
  544. };
  545. int status;
  546. if (plus)
  547. msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
  548. dprintk("NFS call readdir%s %d\n",
  549. plus? "plus" : "", (unsigned int) cookie);
  550. nfs_fattr_init(&dir_attr);
  551. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  552. nfs_invalidate_atime(dir);
  553. nfs_refresh_inode(dir, &dir_attr);
  554. dprintk("NFS reply readdir: %d\n", status);
  555. return status;
  556. }
  557. static int
  558. nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  559. dev_t rdev)
  560. {
  561. struct nfs_fh fh;
  562. struct nfs_fattr fattr, dir_attr;
  563. struct nfs3_mknodargs arg = {
  564. .fh = NFS_FH(dir),
  565. .name = dentry->d_name.name,
  566. .len = dentry->d_name.len,
  567. .sattr = sattr,
  568. .rdev = rdev
  569. };
  570. struct nfs3_diropres res = {
  571. .dir_attr = &dir_attr,
  572. .fh = &fh,
  573. .fattr = &fattr
  574. };
  575. struct rpc_message msg = {
  576. .rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD],
  577. .rpc_argp = &arg,
  578. .rpc_resp = &res,
  579. };
  580. mode_t mode = sattr->ia_mode;
  581. int status;
  582. switch (sattr->ia_mode & S_IFMT) {
  583. case S_IFBLK: arg.type = NF3BLK; break;
  584. case S_IFCHR: arg.type = NF3CHR; break;
  585. case S_IFIFO: arg.type = NF3FIFO; break;
  586. case S_IFSOCK: arg.type = NF3SOCK; break;
  587. default: return -EINVAL;
  588. }
  589. dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
  590. MAJOR(rdev), MINOR(rdev));
  591. sattr->ia_mode &= ~current->fs->umask;
  592. nfs_fattr_init(&dir_attr);
  593. nfs_fattr_init(&fattr);
  594. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  595. nfs_post_op_update_inode(dir, &dir_attr);
  596. if (status != 0)
  597. goto out;
  598. status = nfs_instantiate(dentry, &fh, &fattr);
  599. if (status != 0)
  600. goto out;
  601. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  602. out:
  603. dprintk("NFS reply mknod: %d\n", status);
  604. return status;
  605. }
  606. static int
  607. nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  608. struct nfs_fsstat *stat)
  609. {
  610. struct rpc_message msg = {
  611. .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
  612. .rpc_argp = fhandle,
  613. .rpc_resp = stat,
  614. };
  615. int status;
  616. dprintk("NFS call fsstat\n");
  617. nfs_fattr_init(stat->fattr);
  618. status = rpc_call_sync(server->client, &msg, 0);
  619. dprintk("NFS reply statfs: %d\n", status);
  620. return status;
  621. }
  622. static int
  623. nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  624. struct nfs_fsinfo *info)
  625. {
  626. struct rpc_message msg = {
  627. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  628. .rpc_argp = fhandle,
  629. .rpc_resp = info,
  630. };
  631. int status;
  632. dprintk("NFS call fsinfo\n");
  633. nfs_fattr_init(info->fattr);
  634. status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
  635. dprintk("NFS reply fsinfo: %d\n", status);
  636. return status;
  637. }
  638. static int
  639. nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  640. struct nfs_pathconf *info)
  641. {
  642. struct rpc_message msg = {
  643. .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
  644. .rpc_argp = fhandle,
  645. .rpc_resp = info,
  646. };
  647. int status;
  648. dprintk("NFS call pathconf\n");
  649. nfs_fattr_init(info->fattr);
  650. status = rpc_call_sync(server->client, &msg, 0);
  651. dprintk("NFS reply pathconf: %d\n", status);
  652. return status;
  653. }
  654. static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data)
  655. {
  656. if (nfs3_async_handle_jukebox(task, data->inode))
  657. return -EAGAIN;
  658. nfs_invalidate_atime(data->inode);
  659. nfs_refresh_inode(data->inode, &data->fattr);
  660. return 0;
  661. }
  662. static void nfs3_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  663. {
  664. msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
  665. }
  666. static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
  667. {
  668. if (nfs3_async_handle_jukebox(task, data->inode))
  669. return -EAGAIN;
  670. if (task->tk_status >= 0)
  671. nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
  672. return 0;
  673. }
  674. static void nfs3_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  675. {
  676. msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
  677. }
  678. static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  679. {
  680. if (nfs3_async_handle_jukebox(task, data->inode))
  681. return -EAGAIN;
  682. nfs_refresh_inode(data->inode, data->res.fattr);
  683. return 0;
  684. }
  685. static void nfs3_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  686. {
  687. msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
  688. }
  689. static int
  690. nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  691. {
  692. struct inode *inode = filp->f_path.dentry->d_inode;
  693. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  694. }
  695. const struct nfs_rpc_ops nfs_v3_clientops = {
  696. .version = 3, /* protocol version */
  697. .dentry_ops = &nfs_dentry_operations,
  698. .dir_inode_ops = &nfs3_dir_inode_operations,
  699. .file_inode_ops = &nfs3_file_inode_operations,
  700. .getroot = nfs3_proc_get_root,
  701. .getattr = nfs3_proc_getattr,
  702. .setattr = nfs3_proc_setattr,
  703. .lookup = nfs3_proc_lookup,
  704. .access = nfs3_proc_access,
  705. .readlink = nfs3_proc_readlink,
  706. .create = nfs3_proc_create,
  707. .remove = nfs3_proc_remove,
  708. .unlink_setup = nfs3_proc_unlink_setup,
  709. .unlink_done = nfs3_proc_unlink_done,
  710. .rename = nfs3_proc_rename,
  711. .link = nfs3_proc_link,
  712. .symlink = nfs3_proc_symlink,
  713. .mkdir = nfs3_proc_mkdir,
  714. .rmdir = nfs3_proc_rmdir,
  715. .readdir = nfs3_proc_readdir,
  716. .mknod = nfs3_proc_mknod,
  717. .statfs = nfs3_proc_statfs,
  718. .fsinfo = nfs3_proc_fsinfo,
  719. .pathconf = nfs3_proc_pathconf,
  720. .decode_dirent = nfs3_decode_dirent,
  721. .read_setup = nfs3_proc_read_setup,
  722. .read_done = nfs3_read_done,
  723. .write_setup = nfs3_proc_write_setup,
  724. .write_done = nfs3_write_done,
  725. .commit_setup = nfs3_proc_commit_setup,
  726. .commit_done = nfs3_commit_done,
  727. .file_open = nfs_open,
  728. .file_release = nfs_release,
  729. .lock = nfs3_proc_lock,
  730. .clear_acl_cache = nfs3_forget_cached_acls,
  731. };