nfs3proc.c 22 KB

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