nfs3proc.c 21 KB

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