nfs3proc.c 22 KB

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