nfs3proc.c 21 KB

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