nfs3proc.c 23 KB

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