nfs3proc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. if (status == 0)
  307. nfs_setattr_update_inode(dentry->d_inode, sattr);
  308. nfs_refresh_inode(dentry->d_inode, &fattr);
  309. dprintk("NFS reply setattr (post-create): %d\n", status);
  310. }
  311. if (status != 0)
  312. goto out;
  313. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  314. out:
  315. dprintk("NFS reply create: %d\n", status);
  316. return status;
  317. }
  318. static int
  319. nfs3_proc_remove(struct inode *dir, struct qstr *name)
  320. {
  321. struct nfs_fattr dir_attr;
  322. struct nfs3_diropargs arg = {
  323. .fh = NFS_FH(dir),
  324. .name = name->name,
  325. .len = name->len
  326. };
  327. struct rpc_message msg = {
  328. .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
  329. .rpc_argp = &arg,
  330. .rpc_resp = &dir_attr,
  331. };
  332. int status;
  333. dprintk("NFS call remove %s\n", name->name);
  334. nfs_fattr_init(&dir_attr);
  335. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  336. nfs_post_op_update_inode(dir, &dir_attr);
  337. dprintk("NFS reply remove: %d\n", status);
  338. return status;
  339. }
  340. static int
  341. nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
  342. {
  343. struct unlinkxdr {
  344. struct nfs3_diropargs arg;
  345. struct nfs_fattr res;
  346. } *ptr;
  347. ptr = kmalloc(sizeof(*ptr), GFP_KERNEL);
  348. if (!ptr)
  349. return -ENOMEM;
  350. ptr->arg.fh = NFS_FH(dir->d_inode);
  351. ptr->arg.name = name->name;
  352. ptr->arg.len = name->len;
  353. nfs_fattr_init(&ptr->res);
  354. msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
  355. msg->rpc_argp = &ptr->arg;
  356. msg->rpc_resp = &ptr->res;
  357. return 0;
  358. }
  359. static int
  360. nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
  361. {
  362. struct rpc_message *msg = &task->tk_msg;
  363. struct nfs_fattr *dir_attr;
  364. if (nfs3_async_handle_jukebox(task, dir->d_inode))
  365. return 1;
  366. if (msg->rpc_argp) {
  367. dir_attr = (struct nfs_fattr*)msg->rpc_resp;
  368. nfs_post_op_update_inode(dir->d_inode, dir_attr);
  369. kfree(msg->rpc_argp);
  370. }
  371. return 0;
  372. }
  373. static int
  374. nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
  375. struct inode *new_dir, struct qstr *new_name)
  376. {
  377. struct nfs_fattr old_dir_attr, new_dir_attr;
  378. struct nfs3_renameargs arg = {
  379. .fromfh = NFS_FH(old_dir),
  380. .fromname = old_name->name,
  381. .fromlen = old_name->len,
  382. .tofh = NFS_FH(new_dir),
  383. .toname = new_name->name,
  384. .tolen = new_name->len
  385. };
  386. struct nfs3_renameres res = {
  387. .fromattr = &old_dir_attr,
  388. .toattr = &new_dir_attr
  389. };
  390. struct rpc_message msg = {
  391. .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME],
  392. .rpc_argp = &arg,
  393. .rpc_resp = &res,
  394. };
  395. int status;
  396. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  397. nfs_fattr_init(&old_dir_attr);
  398. nfs_fattr_init(&new_dir_attr);
  399. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  400. nfs_post_op_update_inode(old_dir, &old_dir_attr);
  401. nfs_post_op_update_inode(new_dir, &new_dir_attr);
  402. dprintk("NFS reply rename: %d\n", status);
  403. return status;
  404. }
  405. static int
  406. nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  407. {
  408. struct nfs_fattr dir_attr, fattr;
  409. struct nfs3_linkargs arg = {
  410. .fromfh = NFS_FH(inode),
  411. .tofh = NFS_FH(dir),
  412. .toname = name->name,
  413. .tolen = name->len
  414. };
  415. struct nfs3_linkres res = {
  416. .dir_attr = &dir_attr,
  417. .fattr = &fattr
  418. };
  419. struct rpc_message msg = {
  420. .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
  421. .rpc_argp = &arg,
  422. .rpc_resp = &res,
  423. };
  424. int status;
  425. dprintk("NFS call link %s\n", name->name);
  426. nfs_fattr_init(&dir_attr);
  427. nfs_fattr_init(&fattr);
  428. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  429. nfs_post_op_update_inode(dir, &dir_attr);
  430. nfs_post_op_update_inode(inode, &fattr);
  431. dprintk("NFS reply link: %d\n", status);
  432. return status;
  433. }
  434. static int
  435. nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  436. unsigned int len, struct iattr *sattr)
  437. {
  438. struct nfs_fh fhandle;
  439. struct nfs_fattr fattr, dir_attr;
  440. struct nfs3_symlinkargs arg = {
  441. .fromfh = NFS_FH(dir),
  442. .fromname = dentry->d_name.name,
  443. .fromlen = dentry->d_name.len,
  444. .pages = &page,
  445. .pathlen = len,
  446. .sattr = sattr
  447. };
  448. struct nfs3_diropres res = {
  449. .dir_attr = &dir_attr,
  450. .fh = &fhandle,
  451. .fattr = &fattr
  452. };
  453. struct rpc_message msg = {
  454. .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK],
  455. .rpc_argp = &arg,
  456. .rpc_resp = &res,
  457. };
  458. int status;
  459. if (len > NFS3_MAXPATHLEN)
  460. return -ENAMETOOLONG;
  461. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  462. nfs_fattr_init(&dir_attr);
  463. nfs_fattr_init(&fattr);
  464. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  465. nfs_post_op_update_inode(dir, &dir_attr);
  466. if (status != 0)
  467. goto out;
  468. status = nfs_instantiate(dentry, &fhandle, &fattr);
  469. out:
  470. dprintk("NFS reply symlink: %d\n", status);
  471. return status;
  472. }
  473. static int
  474. nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  475. {
  476. struct nfs_fh fhandle;
  477. struct nfs_fattr fattr, dir_attr;
  478. struct nfs3_mkdirargs arg = {
  479. .fh = NFS_FH(dir),
  480. .name = dentry->d_name.name,
  481. .len = dentry->d_name.len,
  482. .sattr = sattr
  483. };
  484. struct nfs3_diropres res = {
  485. .dir_attr = &dir_attr,
  486. .fh = &fhandle,
  487. .fattr = &fattr
  488. };
  489. struct rpc_message msg = {
  490. .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR],
  491. .rpc_argp = &arg,
  492. .rpc_resp = &res,
  493. };
  494. int mode = sattr->ia_mode;
  495. int status;
  496. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  497. sattr->ia_mode &= ~current->fs->umask;
  498. nfs_fattr_init(&dir_attr);
  499. nfs_fattr_init(&fattr);
  500. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  501. nfs_post_op_update_inode(dir, &dir_attr);
  502. if (status != 0)
  503. goto out;
  504. status = nfs_instantiate(dentry, &fhandle, &fattr);
  505. if (status != 0)
  506. goto out;
  507. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  508. out:
  509. dprintk("NFS reply mkdir: %d\n", status);
  510. return status;
  511. }
  512. static int
  513. nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
  514. {
  515. struct nfs_fattr dir_attr;
  516. struct nfs3_diropargs arg = {
  517. .fh = NFS_FH(dir),
  518. .name = name->name,
  519. .len = name->len
  520. };
  521. struct rpc_message msg = {
  522. .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
  523. .rpc_argp = &arg,
  524. .rpc_resp = &dir_attr,
  525. };
  526. int status;
  527. dprintk("NFS call rmdir %s\n", name->name);
  528. nfs_fattr_init(&dir_attr);
  529. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  530. nfs_post_op_update_inode(dir, &dir_attr);
  531. dprintk("NFS reply rmdir: %d\n", status);
  532. return status;
  533. }
  534. /*
  535. * The READDIR implementation is somewhat hackish - we pass the user buffer
  536. * to the encode function, which installs it in the receive iovec.
  537. * The decode function itself doesn't perform any decoding, it just makes
  538. * sure the reply is syntactically correct.
  539. *
  540. * Also note that this implementation handles both plain readdir and
  541. * readdirplus.
  542. */
  543. static int
  544. nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  545. u64 cookie, struct page *page, unsigned int count, int plus)
  546. {
  547. struct inode *dir = dentry->d_inode;
  548. struct nfs_fattr dir_attr;
  549. __be32 *verf = NFS_COOKIEVERF(dir);
  550. struct nfs3_readdirargs arg = {
  551. .fh = NFS_FH(dir),
  552. .cookie = cookie,
  553. .verf = {verf[0], verf[1]},
  554. .plus = plus,
  555. .count = count,
  556. .pages = &page
  557. };
  558. struct nfs3_readdirres res = {
  559. .dir_attr = &dir_attr,
  560. .verf = verf,
  561. .plus = plus
  562. };
  563. struct rpc_message msg = {
  564. .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
  565. .rpc_argp = &arg,
  566. .rpc_resp = &res,
  567. .rpc_cred = cred
  568. };
  569. int status;
  570. if (plus)
  571. msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
  572. dprintk("NFS call readdir%s %d\n",
  573. plus? "plus" : "", (unsigned int) cookie);
  574. nfs_fattr_init(&dir_attr);
  575. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  576. nfs_refresh_inode(dir, &dir_attr);
  577. dprintk("NFS reply readdir: %d\n", status);
  578. return status;
  579. }
  580. static int
  581. nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  582. dev_t rdev)
  583. {
  584. struct nfs_fh fh;
  585. struct nfs_fattr fattr, dir_attr;
  586. struct nfs3_mknodargs arg = {
  587. .fh = NFS_FH(dir),
  588. .name = dentry->d_name.name,
  589. .len = dentry->d_name.len,
  590. .sattr = sattr,
  591. .rdev = rdev
  592. };
  593. struct nfs3_diropres res = {
  594. .dir_attr = &dir_attr,
  595. .fh = &fh,
  596. .fattr = &fattr
  597. };
  598. struct rpc_message msg = {
  599. .rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD],
  600. .rpc_argp = &arg,
  601. .rpc_resp = &res,
  602. };
  603. mode_t mode = sattr->ia_mode;
  604. int status;
  605. switch (sattr->ia_mode & S_IFMT) {
  606. case S_IFBLK: arg.type = NF3BLK; break;
  607. case S_IFCHR: arg.type = NF3CHR; break;
  608. case S_IFIFO: arg.type = NF3FIFO; break;
  609. case S_IFSOCK: arg.type = NF3SOCK; break;
  610. default: return -EINVAL;
  611. }
  612. dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
  613. MAJOR(rdev), MINOR(rdev));
  614. sattr->ia_mode &= ~current->fs->umask;
  615. nfs_fattr_init(&dir_attr);
  616. nfs_fattr_init(&fattr);
  617. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  618. nfs_post_op_update_inode(dir, &dir_attr);
  619. if (status != 0)
  620. goto out;
  621. status = nfs_instantiate(dentry, &fh, &fattr);
  622. if (status != 0)
  623. goto out;
  624. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  625. out:
  626. dprintk("NFS reply mknod: %d\n", status);
  627. return status;
  628. }
  629. static int
  630. nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  631. struct nfs_fsstat *stat)
  632. {
  633. struct rpc_message msg = {
  634. .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
  635. .rpc_argp = fhandle,
  636. .rpc_resp = stat,
  637. };
  638. int status;
  639. dprintk("NFS call fsstat\n");
  640. nfs_fattr_init(stat->fattr);
  641. status = rpc_call_sync(server->client, &msg, 0);
  642. dprintk("NFS reply statfs: %d\n", status);
  643. return status;
  644. }
  645. static int
  646. nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  647. struct nfs_fsinfo *info)
  648. {
  649. struct rpc_message msg = {
  650. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  651. .rpc_argp = fhandle,
  652. .rpc_resp = info,
  653. };
  654. int status;
  655. dprintk("NFS call fsinfo\n");
  656. nfs_fattr_init(info->fattr);
  657. status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
  658. dprintk("NFS reply fsinfo: %d\n", status);
  659. return status;
  660. }
  661. static int
  662. nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  663. struct nfs_pathconf *info)
  664. {
  665. struct rpc_message msg = {
  666. .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
  667. .rpc_argp = fhandle,
  668. .rpc_resp = info,
  669. };
  670. int status;
  671. dprintk("NFS call pathconf\n");
  672. nfs_fattr_init(info->fattr);
  673. status = rpc_call_sync(server->client, &msg, 0);
  674. dprintk("NFS reply pathconf: %d\n", status);
  675. return status;
  676. }
  677. static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data)
  678. {
  679. if (nfs3_async_handle_jukebox(task, data->inode))
  680. return -EAGAIN;
  681. /* Call back common NFS readpage processing */
  682. if (task->tk_status >= 0)
  683. nfs_refresh_inode(data->inode, &data->fattr);
  684. return 0;
  685. }
  686. static void nfs3_proc_read_setup(struct nfs_read_data *data)
  687. {
  688. struct rpc_message msg = {
  689. .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
  690. .rpc_argp = &data->args,
  691. .rpc_resp = &data->res,
  692. .rpc_cred = data->cred,
  693. };
  694. rpc_call_setup(&data->task, &msg, 0);
  695. }
  696. static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
  697. {
  698. if (nfs3_async_handle_jukebox(task, data->inode))
  699. return -EAGAIN;
  700. if (task->tk_status >= 0)
  701. nfs_post_op_update_inode(data->inode, data->res.fattr);
  702. return 0;
  703. }
  704. static void nfs3_proc_write_setup(struct nfs_write_data *data, int how)
  705. {
  706. struct rpc_message msg = {
  707. .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
  708. .rpc_argp = &data->args,
  709. .rpc_resp = &data->res,
  710. .rpc_cred = data->cred,
  711. };
  712. data->args.stable = NFS_UNSTABLE;
  713. if (how & FLUSH_STABLE) {
  714. data->args.stable = NFS_FILE_SYNC;
  715. if (NFS_I(data->inode)->ncommit)
  716. data->args.stable = NFS_DATA_SYNC;
  717. }
  718. /* Finalize the task. */
  719. rpc_call_setup(&data->task, &msg, 0);
  720. }
  721. static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  722. {
  723. if (nfs3_async_handle_jukebox(task, data->inode))
  724. return -EAGAIN;
  725. if (task->tk_status >= 0)
  726. nfs_post_op_update_inode(data->inode, data->res.fattr);
  727. return 0;
  728. }
  729. static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
  730. {
  731. struct rpc_message msg = {
  732. .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
  733. .rpc_argp = &data->args,
  734. .rpc_resp = &data->res,
  735. .rpc_cred = data->cred,
  736. };
  737. rpc_call_setup(&data->task, &msg, 0);
  738. }
  739. static int
  740. nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  741. {
  742. return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
  743. }
  744. const struct nfs_rpc_ops nfs_v3_clientops = {
  745. .version = 3, /* protocol version */
  746. .dentry_ops = &nfs_dentry_operations,
  747. .dir_inode_ops = &nfs3_dir_inode_operations,
  748. .file_inode_ops = &nfs3_file_inode_operations,
  749. .getroot = nfs3_proc_get_root,
  750. .getattr = nfs3_proc_getattr,
  751. .setattr = nfs3_proc_setattr,
  752. .lookup = nfs3_proc_lookup,
  753. .access = nfs3_proc_access,
  754. .readlink = nfs3_proc_readlink,
  755. .create = nfs3_proc_create,
  756. .remove = nfs3_proc_remove,
  757. .unlink_setup = nfs3_proc_unlink_setup,
  758. .unlink_done = nfs3_proc_unlink_done,
  759. .rename = nfs3_proc_rename,
  760. .link = nfs3_proc_link,
  761. .symlink = nfs3_proc_symlink,
  762. .mkdir = nfs3_proc_mkdir,
  763. .rmdir = nfs3_proc_rmdir,
  764. .readdir = nfs3_proc_readdir,
  765. .mknod = nfs3_proc_mknod,
  766. .statfs = nfs3_proc_statfs,
  767. .fsinfo = nfs3_proc_fsinfo,
  768. .pathconf = nfs3_proc_pathconf,
  769. .decode_dirent = nfs3_decode_dirent,
  770. .read_setup = nfs3_proc_read_setup,
  771. .read_done = nfs3_read_done,
  772. .write_setup = nfs3_proc_write_setup,
  773. .write_done = nfs3_write_done,
  774. .commit_setup = nfs3_proc_commit_setup,
  775. .commit_done = nfs3_commit_done,
  776. .file_open = nfs_open,
  777. .file_release = nfs_release,
  778. .lock = nfs3_proc_lock,
  779. .clear_acl_cache = nfs3_forget_cached_acls,
  780. };