nfs3proc.c 23 KB

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