nfs3proc.c 22 KB

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