nfs3proc.c 21 KB

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