nfs3proc.c 23 KB

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