nfs3proc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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_removeargs arg = {
  320. .fh = NFS_FH(dir),
  321. .name.len = name->len,
  322. .name.name = name->name,
  323. };
  324. struct nfs_removeres res;
  325. struct rpc_message msg = {
  326. .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
  327. .rpc_argp = &arg,
  328. .rpc_resp = &res,
  329. };
  330. int status;
  331. dprintk("NFS call remove %s\n", name->name);
  332. nfs_fattr_init(&res.dir_attr);
  333. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  334. nfs_post_op_update_inode(dir, &res.dir_attr);
  335. dprintk("NFS reply remove: %d\n", status);
  336. return status;
  337. }
  338. static void
  339. nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  340. {
  341. msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
  342. }
  343. static int
  344. nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  345. {
  346. struct nfs_removeres *res;
  347. if (nfs3_async_handle_jukebox(task, dir))
  348. return 0;
  349. res = task->tk_msg.rpc_resp;
  350. nfs_post_op_update_inode(dir, &res->dir_attr);
  351. return 1;
  352. }
  353. static int
  354. nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
  355. struct inode *new_dir, struct qstr *new_name)
  356. {
  357. struct nfs_fattr old_dir_attr, new_dir_attr;
  358. struct nfs3_renameargs arg = {
  359. .fromfh = NFS_FH(old_dir),
  360. .fromname = old_name->name,
  361. .fromlen = old_name->len,
  362. .tofh = NFS_FH(new_dir),
  363. .toname = new_name->name,
  364. .tolen = new_name->len
  365. };
  366. struct nfs3_renameres res = {
  367. .fromattr = &old_dir_attr,
  368. .toattr = &new_dir_attr
  369. };
  370. struct rpc_message msg = {
  371. .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME],
  372. .rpc_argp = &arg,
  373. .rpc_resp = &res,
  374. };
  375. int status;
  376. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  377. nfs_fattr_init(&old_dir_attr);
  378. nfs_fattr_init(&new_dir_attr);
  379. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  380. nfs_post_op_update_inode(old_dir, &old_dir_attr);
  381. nfs_post_op_update_inode(new_dir, &new_dir_attr);
  382. dprintk("NFS reply rename: %d\n", status);
  383. return status;
  384. }
  385. static int
  386. nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  387. {
  388. struct nfs_fattr dir_attr, fattr;
  389. struct nfs3_linkargs arg = {
  390. .fromfh = NFS_FH(inode),
  391. .tofh = NFS_FH(dir),
  392. .toname = name->name,
  393. .tolen = name->len
  394. };
  395. struct nfs3_linkres res = {
  396. .dir_attr = &dir_attr,
  397. .fattr = &fattr
  398. };
  399. struct rpc_message msg = {
  400. .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
  401. .rpc_argp = &arg,
  402. .rpc_resp = &res,
  403. };
  404. int status;
  405. dprintk("NFS call link %s\n", name->name);
  406. nfs_fattr_init(&dir_attr);
  407. nfs_fattr_init(&fattr);
  408. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  409. nfs_post_op_update_inode(dir, &dir_attr);
  410. nfs_post_op_update_inode(inode, &fattr);
  411. dprintk("NFS reply link: %d\n", status);
  412. return status;
  413. }
  414. static int
  415. nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  416. unsigned int len, struct iattr *sattr)
  417. {
  418. struct nfs_fh fhandle;
  419. struct nfs_fattr fattr, dir_attr;
  420. struct nfs3_symlinkargs arg = {
  421. .fromfh = NFS_FH(dir),
  422. .fromname = dentry->d_name.name,
  423. .fromlen = dentry->d_name.len,
  424. .pages = &page,
  425. .pathlen = len,
  426. .sattr = sattr
  427. };
  428. struct nfs3_diropres res = {
  429. .dir_attr = &dir_attr,
  430. .fh = &fhandle,
  431. .fattr = &fattr
  432. };
  433. struct rpc_message msg = {
  434. .rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK],
  435. .rpc_argp = &arg,
  436. .rpc_resp = &res,
  437. };
  438. int status;
  439. if (len > NFS3_MAXPATHLEN)
  440. return -ENAMETOOLONG;
  441. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  442. nfs_fattr_init(&dir_attr);
  443. nfs_fattr_init(&fattr);
  444. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  445. nfs_post_op_update_inode(dir, &dir_attr);
  446. if (status != 0)
  447. goto out;
  448. status = nfs_instantiate(dentry, &fhandle, &fattr);
  449. out:
  450. dprintk("NFS reply symlink: %d\n", status);
  451. return status;
  452. }
  453. static int
  454. nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  455. {
  456. struct nfs_fh fhandle;
  457. struct nfs_fattr fattr, dir_attr;
  458. struct nfs3_mkdirargs arg = {
  459. .fh = NFS_FH(dir),
  460. .name = dentry->d_name.name,
  461. .len = dentry->d_name.len,
  462. .sattr = sattr
  463. };
  464. struct nfs3_diropres res = {
  465. .dir_attr = &dir_attr,
  466. .fh = &fhandle,
  467. .fattr = &fattr
  468. };
  469. struct rpc_message msg = {
  470. .rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR],
  471. .rpc_argp = &arg,
  472. .rpc_resp = &res,
  473. };
  474. int mode = sattr->ia_mode;
  475. int status;
  476. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  477. sattr->ia_mode &= ~current->fs->umask;
  478. nfs_fattr_init(&dir_attr);
  479. nfs_fattr_init(&fattr);
  480. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  481. nfs_post_op_update_inode(dir, &dir_attr);
  482. if (status != 0)
  483. goto out;
  484. status = nfs_instantiate(dentry, &fhandle, &fattr);
  485. if (status != 0)
  486. goto out;
  487. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  488. out:
  489. dprintk("NFS reply mkdir: %d\n", status);
  490. return status;
  491. }
  492. static int
  493. nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
  494. {
  495. struct nfs_fattr dir_attr;
  496. struct nfs3_diropargs arg = {
  497. .fh = NFS_FH(dir),
  498. .name = name->name,
  499. .len = name->len
  500. };
  501. struct rpc_message msg = {
  502. .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
  503. .rpc_argp = &arg,
  504. .rpc_resp = &dir_attr,
  505. };
  506. int status;
  507. dprintk("NFS call rmdir %s\n", name->name);
  508. nfs_fattr_init(&dir_attr);
  509. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  510. nfs_post_op_update_inode(dir, &dir_attr);
  511. dprintk("NFS reply rmdir: %d\n", status);
  512. return status;
  513. }
  514. /*
  515. * The READDIR implementation is somewhat hackish - we pass the user buffer
  516. * to the encode function, which installs it in the receive iovec.
  517. * The decode function itself doesn't perform any decoding, it just makes
  518. * sure the reply is syntactically correct.
  519. *
  520. * Also note that this implementation handles both plain readdir and
  521. * readdirplus.
  522. */
  523. static int
  524. nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  525. u64 cookie, struct page *page, unsigned int count, int plus)
  526. {
  527. struct inode *dir = dentry->d_inode;
  528. struct nfs_fattr dir_attr;
  529. __be32 *verf = NFS_COOKIEVERF(dir);
  530. struct nfs3_readdirargs arg = {
  531. .fh = NFS_FH(dir),
  532. .cookie = cookie,
  533. .verf = {verf[0], verf[1]},
  534. .plus = plus,
  535. .count = count,
  536. .pages = &page
  537. };
  538. struct nfs3_readdirres res = {
  539. .dir_attr = &dir_attr,
  540. .verf = verf,
  541. .plus = plus
  542. };
  543. struct rpc_message msg = {
  544. .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
  545. .rpc_argp = &arg,
  546. .rpc_resp = &res,
  547. .rpc_cred = cred
  548. };
  549. int status;
  550. if (plus)
  551. msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
  552. dprintk("NFS call readdir%s %d\n",
  553. plus? "plus" : "", (unsigned int) cookie);
  554. nfs_fattr_init(&dir_attr);
  555. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  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. /* Call back common NFS readpage processing */
  662. if (task->tk_status >= 0)
  663. nfs_refresh_inode(data->inode, &data->fattr);
  664. return 0;
  665. }
  666. static void nfs3_proc_read_setup(struct nfs_read_data *data)
  667. {
  668. struct rpc_message msg = {
  669. .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
  670. .rpc_argp = &data->args,
  671. .rpc_resp = &data->res,
  672. .rpc_cred = data->cred,
  673. };
  674. rpc_call_setup(&data->task, &msg, 0);
  675. }
  676. static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
  677. {
  678. if (nfs3_async_handle_jukebox(task, data->inode))
  679. return -EAGAIN;
  680. if (task->tk_status >= 0)
  681. nfs_post_op_update_inode(data->inode, data->res.fattr);
  682. return 0;
  683. }
  684. static void nfs3_proc_write_setup(struct nfs_write_data *data, int how)
  685. {
  686. struct rpc_message msg = {
  687. .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
  688. .rpc_argp = &data->args,
  689. .rpc_resp = &data->res,
  690. .rpc_cred = data->cred,
  691. };
  692. data->args.stable = NFS_UNSTABLE;
  693. if (how & FLUSH_STABLE) {
  694. data->args.stable = NFS_FILE_SYNC;
  695. if (NFS_I(data->inode)->ncommit)
  696. data->args.stable = NFS_DATA_SYNC;
  697. }
  698. /* Finalize the task. */
  699. rpc_call_setup(&data->task, &msg, 0);
  700. }
  701. static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  702. {
  703. if (nfs3_async_handle_jukebox(task, data->inode))
  704. return -EAGAIN;
  705. if (task->tk_status >= 0)
  706. nfs_post_op_update_inode(data->inode, data->res.fattr);
  707. return 0;
  708. }
  709. static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
  710. {
  711. struct rpc_message msg = {
  712. .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
  713. .rpc_argp = &data->args,
  714. .rpc_resp = &data->res,
  715. .rpc_cred = data->cred,
  716. };
  717. rpc_call_setup(&data->task, &msg, 0);
  718. }
  719. static int
  720. nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  721. {
  722. return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
  723. }
  724. const struct nfs_rpc_ops nfs_v3_clientops = {
  725. .version = 3, /* protocol version */
  726. .dentry_ops = &nfs_dentry_operations,
  727. .dir_inode_ops = &nfs3_dir_inode_operations,
  728. .file_inode_ops = &nfs3_file_inode_operations,
  729. .getroot = nfs3_proc_get_root,
  730. .getattr = nfs3_proc_getattr,
  731. .setattr = nfs3_proc_setattr,
  732. .lookup = nfs3_proc_lookup,
  733. .access = nfs3_proc_access,
  734. .readlink = nfs3_proc_readlink,
  735. .create = nfs3_proc_create,
  736. .remove = nfs3_proc_remove,
  737. .unlink_setup = nfs3_proc_unlink_setup,
  738. .unlink_done = nfs3_proc_unlink_done,
  739. .rename = nfs3_proc_rename,
  740. .link = nfs3_proc_link,
  741. .symlink = nfs3_proc_symlink,
  742. .mkdir = nfs3_proc_mkdir,
  743. .rmdir = nfs3_proc_rmdir,
  744. .readdir = nfs3_proc_readdir,
  745. .mknod = nfs3_proc_mknod,
  746. .statfs = nfs3_proc_statfs,
  747. .fsinfo = nfs3_proc_fsinfo,
  748. .pathconf = nfs3_proc_pathconf,
  749. .decode_dirent = nfs3_decode_dirent,
  750. .read_setup = nfs3_proc_read_setup,
  751. .read_done = nfs3_read_done,
  752. .write_setup = nfs3_proc_write_setup,
  753. .write_done = nfs3_write_done,
  754. .commit_setup = nfs3_proc_commit_setup,
  755. .commit_done = nfs3_commit_done,
  756. .file_open = nfs_open,
  757. .file_release = nfs_release,
  758. .lock = nfs3_proc_lock,
  759. .clear_acl_cache = nfs3_forget_cached_acls,
  760. };