nfs3proc.c 22 KB

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