nfs3proc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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/errno.h>
  10. #include <linux/string.h>
  11. #include <linux/sunrpc/clnt.h>
  12. #include <linux/slab.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/nfs_mount.h>
  19. #include "iostat.h"
  20. #include "internal.h"
  21. #define NFSDBG_FACILITY NFSDBG_PROC
  22. /* A wrapper to handle the EJUKEBOX and EKEYEXPIRED error messages */
  23. static int
  24. nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
  25. {
  26. int res;
  27. do {
  28. res = rpc_call_sync(clnt, msg, flags);
  29. if (res != -EJUKEBOX && res != -EKEYEXPIRED)
  30. break;
  31. schedule_timeout_killable(NFS_JUKEBOX_RETRY_TIME);
  32. res = -ERESTARTSYS;
  33. } while (!fatal_signal_pending(current));
  34. return res;
  35. }
  36. #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags)
  37. static int
  38. nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
  39. {
  40. if (task->tk_status != -EJUKEBOX && task->tk_status != -EKEYEXPIRED)
  41. return 0;
  42. if (task->tk_status == -EJUKEBOX)
  43. nfs_inc_stats(inode, NFSIOS_DELAY);
  44. task->tk_status = 0;
  45. rpc_restart_call(task);
  46. rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
  47. return 1;
  48. }
  49. static int
  50. do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
  51. struct nfs_fsinfo *info)
  52. {
  53. struct rpc_message msg = {
  54. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  55. .rpc_argp = fhandle,
  56. .rpc_resp = info,
  57. };
  58. int status;
  59. dprintk("%s: call fsinfo\n", __func__);
  60. nfs_fattr_init(info->fattr);
  61. status = rpc_call_sync(client, &msg, 0);
  62. dprintk("%s: reply fsinfo: %d\n", __func__, status);
  63. if (!(info->fattr->valid & NFS_ATTR_FATTR)) {
  64. msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
  65. msg.rpc_resp = info->fattr;
  66. status = rpc_call_sync(client, &msg, 0);
  67. dprintk("%s: reply getattr: %d\n", __func__, status);
  68. }
  69. return status;
  70. }
  71. /*
  72. * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
  73. */
  74. static int
  75. nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  76. struct nfs_fsinfo *info)
  77. {
  78. int status;
  79. status = do_proc_get_root(server->client, fhandle, info);
  80. if (status && server->nfs_client->cl_rpcclient != server->client)
  81. status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
  82. return status;
  83. }
  84. /*
  85. * One function for each procedure in the NFS protocol.
  86. */
  87. static int
  88. nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
  89. struct nfs_fattr *fattr)
  90. {
  91. struct rpc_message msg = {
  92. .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
  93. .rpc_argp = fhandle,
  94. .rpc_resp = fattr,
  95. };
  96. int status;
  97. dprintk("NFS call getattr\n");
  98. nfs_fattr_init(fattr);
  99. status = rpc_call_sync(server->client, &msg, 0);
  100. dprintk("NFS reply getattr: %d\n", status);
  101. return status;
  102. }
  103. static int
  104. nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  105. struct iattr *sattr)
  106. {
  107. struct inode *inode = dentry->d_inode;
  108. struct nfs3_sattrargs arg = {
  109. .fh = NFS_FH(inode),
  110. .sattr = sattr,
  111. };
  112. struct rpc_message msg = {
  113. .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
  114. .rpc_argp = &arg,
  115. .rpc_resp = fattr,
  116. };
  117. int status;
  118. dprintk("NFS call setattr\n");
  119. if (sattr->ia_valid & ATTR_FILE)
  120. msg.rpc_cred = nfs_file_cred(sattr->ia_file);
  121. nfs_fattr_init(fattr);
  122. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  123. if (status == 0)
  124. nfs_setattr_update_inode(inode, sattr);
  125. dprintk("NFS reply setattr: %d\n", status);
  126. return status;
  127. }
  128. static int
  129. nfs3_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name,
  130. struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  131. {
  132. struct nfs3_diropargs arg = {
  133. .fh = NFS_FH(dir),
  134. .name = name->name,
  135. .len = name->len
  136. };
  137. struct nfs3_diropres res = {
  138. .fh = fhandle,
  139. .fattr = fattr
  140. };
  141. struct rpc_message msg = {
  142. .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
  143. .rpc_argp = &arg,
  144. .rpc_resp = &res,
  145. };
  146. int status;
  147. dprintk("NFS call lookup %s\n", name->name);
  148. res.dir_attr = nfs_alloc_fattr();
  149. if (res.dir_attr == NULL)
  150. return -ENOMEM;
  151. nfs_fattr_init(fattr);
  152. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  153. nfs_refresh_inode(dir, res.dir_attr);
  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. nfs_free_fattr(res.dir_attr);
  161. dprintk("NFS reply lookup: %d\n", status);
  162. return status;
  163. }
  164. static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  165. {
  166. struct nfs3_accessargs arg = {
  167. .fh = NFS_FH(inode),
  168. };
  169. struct nfs3_accessres res;
  170. struct rpc_message msg = {
  171. .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
  172. .rpc_argp = &arg,
  173. .rpc_resp = &res,
  174. .rpc_cred = entry->cred,
  175. };
  176. int mode = entry->mask;
  177. int status = -ENOMEM;
  178. dprintk("NFS call access\n");
  179. if (mode & MAY_READ)
  180. arg.access |= NFS3_ACCESS_READ;
  181. if (S_ISDIR(inode->i_mode)) {
  182. if (mode & MAY_WRITE)
  183. arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
  184. if (mode & MAY_EXEC)
  185. arg.access |= NFS3_ACCESS_LOOKUP;
  186. } else {
  187. if (mode & MAY_WRITE)
  188. arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
  189. if (mode & MAY_EXEC)
  190. arg.access |= NFS3_ACCESS_EXECUTE;
  191. }
  192. res.fattr = nfs_alloc_fattr();
  193. if (res.fattr == NULL)
  194. goto out;
  195. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  196. nfs_refresh_inode(inode, res.fattr);
  197. if (status == 0) {
  198. entry->mask = 0;
  199. if (res.access & NFS3_ACCESS_READ)
  200. entry->mask |= MAY_READ;
  201. if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
  202. entry->mask |= MAY_WRITE;
  203. if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
  204. entry->mask |= MAY_EXEC;
  205. }
  206. nfs_free_fattr(res.fattr);
  207. out:
  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. };
  225. int status = -ENOMEM;
  226. dprintk("NFS call readlink\n");
  227. fattr = nfs_alloc_fattr();
  228. if (fattr == NULL)
  229. goto out;
  230. msg.rpc_resp = fattr;
  231. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  232. nfs_refresh_inode(inode, fattr);
  233. nfs_free_fattr(fattr);
  234. out:
  235. dprintk("NFS reply readlink: %d\n", status);
  236. return status;
  237. }
  238. struct nfs3_createdata {
  239. struct rpc_message msg;
  240. union {
  241. struct nfs3_createargs create;
  242. struct nfs3_mkdirargs mkdir;
  243. struct nfs3_symlinkargs symlink;
  244. struct nfs3_mknodargs mknod;
  245. } arg;
  246. struct nfs3_diropres res;
  247. struct nfs_fh fh;
  248. struct nfs_fattr fattr;
  249. struct nfs_fattr dir_attr;
  250. };
  251. static struct nfs3_createdata *nfs3_alloc_createdata(void)
  252. {
  253. struct nfs3_createdata *data;
  254. data = kzalloc(sizeof(*data), GFP_KERNEL);
  255. if (data != NULL) {
  256. data->msg.rpc_argp = &data->arg;
  257. data->msg.rpc_resp = &data->res;
  258. data->res.fh = &data->fh;
  259. data->res.fattr = &data->fattr;
  260. data->res.dir_attr = &data->dir_attr;
  261. nfs_fattr_init(data->res.fattr);
  262. nfs_fattr_init(data->res.dir_attr);
  263. }
  264. return data;
  265. }
  266. static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
  267. {
  268. int status;
  269. status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
  270. nfs_post_op_update_inode(dir, data->res.dir_attr);
  271. if (status == 0)
  272. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  273. return status;
  274. }
  275. static void nfs3_free_createdata(struct nfs3_createdata *data)
  276. {
  277. kfree(data);
  278. }
  279. /*
  280. * Create a regular file.
  281. */
  282. static int
  283. nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  284. int flags, struct nfs_open_context *ctx)
  285. {
  286. struct nfs3_createdata *data;
  287. mode_t mode = sattr->ia_mode;
  288. int status = -ENOMEM;
  289. dprintk("NFS call create %s\n", dentry->d_name.name);
  290. data = nfs3_alloc_createdata();
  291. if (data == NULL)
  292. goto out;
  293. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
  294. data->arg.create.fh = NFS_FH(dir);
  295. data->arg.create.name = dentry->d_name.name;
  296. data->arg.create.len = dentry->d_name.len;
  297. data->arg.create.sattr = sattr;
  298. data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
  299. if (flags & O_EXCL) {
  300. data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
  301. data->arg.create.verifier[0] = jiffies;
  302. data->arg.create.verifier[1] = current->pid;
  303. }
  304. sattr->ia_mode &= ~current_umask();
  305. for (;;) {
  306. status = nfs3_do_create(dir, dentry, data);
  307. if (status != -ENOTSUPP)
  308. break;
  309. /* If the server doesn't support the exclusive creation
  310. * semantics, try again with simple 'guarded' mode. */
  311. switch (data->arg.create.createmode) {
  312. case NFS3_CREATE_EXCLUSIVE:
  313. data->arg.create.createmode = NFS3_CREATE_GUARDED;
  314. break;
  315. case NFS3_CREATE_GUARDED:
  316. data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
  317. break;
  318. case NFS3_CREATE_UNCHECKED:
  319. goto out;
  320. }
  321. nfs_fattr_init(data->res.dir_attr);
  322. nfs_fattr_init(data->res.fattr);
  323. }
  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 (data->arg.create.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, data->res.fattr, sattr);
  338. nfs_post_op_update_inode(dentry->d_inode, data->res.fattr);
  339. dprintk("NFS reply setattr (post-create): %d\n", status);
  340. if (status != 0)
  341. goto out;
  342. }
  343. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  344. out:
  345. nfs3_free_createdata(data);
  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_removeargs arg = {
  353. .fh = NFS_FH(dir),
  354. .name.len = name->len,
  355. .name.name = name->name,
  356. };
  357. struct nfs_removeres res;
  358. struct rpc_message msg = {
  359. .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
  360. .rpc_argp = &arg,
  361. .rpc_resp = &res,
  362. };
  363. int status = -ENOMEM;
  364. dprintk("NFS call remove %s\n", name->name);
  365. res.dir_attr = nfs_alloc_fattr();
  366. if (res.dir_attr == NULL)
  367. goto out;
  368. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  369. nfs_post_op_update_inode(dir, res.dir_attr);
  370. nfs_free_fattr(res.dir_attr);
  371. out:
  372. dprintk("NFS reply remove: %d\n", status);
  373. return status;
  374. }
  375. static void
  376. nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  377. {
  378. msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
  379. }
  380. static int
  381. nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  382. {
  383. struct nfs_removeres *res;
  384. if (nfs3_async_handle_jukebox(task, dir))
  385. return 0;
  386. res = task->tk_msg.rpc_resp;
  387. nfs_post_op_update_inode(dir, res->dir_attr);
  388. return 1;
  389. }
  390. static void
  391. nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
  392. {
  393. msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
  394. }
  395. static int
  396. nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
  397. struct inode *new_dir)
  398. {
  399. struct nfs_renameres *res;
  400. if (nfs3_async_handle_jukebox(task, old_dir))
  401. return 0;
  402. res = task->tk_msg.rpc_resp;
  403. nfs_post_op_update_inode(old_dir, res->old_fattr);
  404. nfs_post_op_update_inode(new_dir, res->new_fattr);
  405. return 1;
  406. }
  407. static int
  408. nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
  409. struct inode *new_dir, struct qstr *new_name)
  410. {
  411. struct nfs_renameargs arg = {
  412. .old_dir = NFS_FH(old_dir),
  413. .old_name = old_name,
  414. .new_dir = NFS_FH(new_dir),
  415. .new_name = new_name,
  416. };
  417. struct nfs_renameres res;
  418. struct rpc_message msg = {
  419. .rpc_proc = &nfs3_procedures[NFS3PROC_RENAME],
  420. .rpc_argp = &arg,
  421. .rpc_resp = &res,
  422. };
  423. int status = -ENOMEM;
  424. dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
  425. res.old_fattr = nfs_alloc_fattr();
  426. res.new_fattr = nfs_alloc_fattr();
  427. if (res.old_fattr == NULL || res.new_fattr == NULL)
  428. goto out;
  429. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  430. nfs_post_op_update_inode(old_dir, res.old_fattr);
  431. nfs_post_op_update_inode(new_dir, res.new_fattr);
  432. out:
  433. nfs_free_fattr(res.old_fattr);
  434. nfs_free_fattr(res.new_fattr);
  435. dprintk("NFS reply rename: %d\n", status);
  436. return status;
  437. }
  438. static int
  439. nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  440. {
  441. struct nfs3_linkargs arg = {
  442. .fromfh = NFS_FH(inode),
  443. .tofh = NFS_FH(dir),
  444. .toname = name->name,
  445. .tolen = name->len
  446. };
  447. struct nfs3_linkres res;
  448. struct rpc_message msg = {
  449. .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
  450. .rpc_argp = &arg,
  451. .rpc_resp = &res,
  452. };
  453. int status = -ENOMEM;
  454. dprintk("NFS call link %s\n", name->name);
  455. res.fattr = nfs_alloc_fattr();
  456. res.dir_attr = nfs_alloc_fattr();
  457. if (res.fattr == NULL || res.dir_attr == NULL)
  458. goto out;
  459. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  460. nfs_post_op_update_inode(dir, res.dir_attr);
  461. nfs_post_op_update_inode(inode, res.fattr);
  462. out:
  463. nfs_free_fattr(res.dir_attr);
  464. nfs_free_fattr(res.fattr);
  465. dprintk("NFS reply link: %d\n", status);
  466. return status;
  467. }
  468. static int
  469. nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  470. unsigned int len, struct iattr *sattr)
  471. {
  472. struct nfs3_createdata *data;
  473. int status = -ENOMEM;
  474. if (len > NFS3_MAXPATHLEN)
  475. return -ENAMETOOLONG;
  476. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  477. data = nfs3_alloc_createdata();
  478. if (data == NULL)
  479. goto out;
  480. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
  481. data->arg.symlink.fromfh = NFS_FH(dir);
  482. data->arg.symlink.fromname = dentry->d_name.name;
  483. data->arg.symlink.fromlen = dentry->d_name.len;
  484. data->arg.symlink.pages = &page;
  485. data->arg.symlink.pathlen = len;
  486. data->arg.symlink.sattr = sattr;
  487. status = nfs3_do_create(dir, dentry, data);
  488. nfs3_free_createdata(data);
  489. out:
  490. dprintk("NFS reply symlink: %d\n", status);
  491. return status;
  492. }
  493. static int
  494. nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  495. {
  496. struct nfs3_createdata *data;
  497. int mode = sattr->ia_mode;
  498. int status = -ENOMEM;
  499. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  500. sattr->ia_mode &= ~current_umask();
  501. data = nfs3_alloc_createdata();
  502. if (data == NULL)
  503. goto out;
  504. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
  505. data->arg.mkdir.fh = NFS_FH(dir);
  506. data->arg.mkdir.name = dentry->d_name.name;
  507. data->arg.mkdir.len = dentry->d_name.len;
  508. data->arg.mkdir.sattr = sattr;
  509. status = nfs3_do_create(dir, dentry, data);
  510. if (status != 0)
  511. goto out;
  512. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  513. out:
  514. nfs3_free_createdata(data);
  515. dprintk("NFS reply mkdir: %d\n", status);
  516. return status;
  517. }
  518. static int
  519. nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
  520. {
  521. struct nfs_fattr *dir_attr;
  522. struct nfs3_diropargs arg = {
  523. .fh = NFS_FH(dir),
  524. .name = name->name,
  525. .len = name->len
  526. };
  527. struct rpc_message msg = {
  528. .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
  529. .rpc_argp = &arg,
  530. };
  531. int status = -ENOMEM;
  532. dprintk("NFS call rmdir %s\n", name->name);
  533. dir_attr = nfs_alloc_fattr();
  534. if (dir_attr == NULL)
  535. goto out;
  536. msg.rpc_resp = dir_attr;
  537. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  538. nfs_post_op_update_inode(dir, dir_attr);
  539. nfs_free_fattr(dir_attr);
  540. out:
  541. dprintk("NFS reply rmdir: %d\n", status);
  542. return status;
  543. }
  544. /*
  545. * The READDIR implementation is somewhat hackish - we pass the user buffer
  546. * to the encode function, which installs it in the receive iovec.
  547. * The decode function itself doesn't perform any decoding, it just makes
  548. * sure the reply is syntactically correct.
  549. *
  550. * Also note that this implementation handles both plain readdir and
  551. * readdirplus.
  552. */
  553. static int
  554. nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  555. u64 cookie, struct page **pages, unsigned int count, int plus)
  556. {
  557. struct inode *dir = dentry->d_inode;
  558. __be32 *verf = NFS_COOKIEVERF(dir);
  559. struct nfs3_readdirargs arg = {
  560. .fh = NFS_FH(dir),
  561. .cookie = cookie,
  562. .verf = {verf[0], verf[1]},
  563. .plus = plus,
  564. .count = count,
  565. .pages = pages
  566. };
  567. struct nfs3_readdirres res = {
  568. .verf = verf,
  569. .plus = plus
  570. };
  571. struct rpc_message msg = {
  572. .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
  573. .rpc_argp = &arg,
  574. .rpc_resp = &res,
  575. .rpc_cred = cred
  576. };
  577. int status = -ENOMEM;
  578. if (plus)
  579. msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
  580. dprintk("NFS call readdir%s %d\n",
  581. plus? "plus" : "", (unsigned int) cookie);
  582. res.dir_attr = nfs_alloc_fattr();
  583. if (res.dir_attr == NULL)
  584. goto out;
  585. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  586. nfs_invalidate_atime(dir);
  587. nfs_refresh_inode(dir, res.dir_attr);
  588. nfs_free_fattr(res.dir_attr);
  589. out:
  590. dprintk("NFS reply readdir%s: %d\n",
  591. plus? "plus" : "", status);
  592. return status;
  593. }
  594. static int
  595. nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  596. dev_t rdev)
  597. {
  598. struct nfs3_createdata *data;
  599. mode_t mode = sattr->ia_mode;
  600. int status = -ENOMEM;
  601. dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
  602. MAJOR(rdev), MINOR(rdev));
  603. sattr->ia_mode &= ~current_umask();
  604. data = nfs3_alloc_createdata();
  605. if (data == NULL)
  606. goto out;
  607. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
  608. data->arg.mknod.fh = NFS_FH(dir);
  609. data->arg.mknod.name = dentry->d_name.name;
  610. data->arg.mknod.len = dentry->d_name.len;
  611. data->arg.mknod.sattr = sattr;
  612. data->arg.mknod.rdev = rdev;
  613. switch (sattr->ia_mode & S_IFMT) {
  614. case S_IFBLK:
  615. data->arg.mknod.type = NF3BLK;
  616. break;
  617. case S_IFCHR:
  618. data->arg.mknod.type = NF3CHR;
  619. break;
  620. case S_IFIFO:
  621. data->arg.mknod.type = NF3FIFO;
  622. break;
  623. case S_IFSOCK:
  624. data->arg.mknod.type = NF3SOCK;
  625. break;
  626. default:
  627. status = -EINVAL;
  628. goto out;
  629. }
  630. status = nfs3_do_create(dir, dentry, data);
  631. if (status != 0)
  632. goto out;
  633. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  634. out:
  635. nfs3_free_createdata(data);
  636. dprintk("NFS reply mknod: %d\n", status);
  637. return status;
  638. }
  639. static int
  640. nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  641. struct nfs_fsstat *stat)
  642. {
  643. struct rpc_message msg = {
  644. .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
  645. .rpc_argp = fhandle,
  646. .rpc_resp = stat,
  647. };
  648. int status;
  649. dprintk("NFS call fsstat\n");
  650. nfs_fattr_init(stat->fattr);
  651. status = rpc_call_sync(server->client, &msg, 0);
  652. dprintk("NFS reply fsstat: %d\n", status);
  653. return status;
  654. }
  655. static int
  656. do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
  657. struct nfs_fsinfo *info)
  658. {
  659. struct rpc_message msg = {
  660. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  661. .rpc_argp = fhandle,
  662. .rpc_resp = info,
  663. };
  664. int status;
  665. dprintk("NFS call fsinfo\n");
  666. nfs_fattr_init(info->fattr);
  667. status = rpc_call_sync(client, &msg, 0);
  668. dprintk("NFS reply fsinfo: %d\n", status);
  669. return status;
  670. }
  671. /*
  672. * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
  673. * nfs_create_server
  674. */
  675. static int
  676. nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  677. struct nfs_fsinfo *info)
  678. {
  679. int status;
  680. status = do_proc_fsinfo(server->client, fhandle, info);
  681. if (status && server->nfs_client->cl_rpcclient != server->client)
  682. status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
  683. return status;
  684. }
  685. static int
  686. nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  687. struct nfs_pathconf *info)
  688. {
  689. struct rpc_message msg = {
  690. .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
  691. .rpc_argp = fhandle,
  692. .rpc_resp = info,
  693. };
  694. int status;
  695. dprintk("NFS call pathconf\n");
  696. nfs_fattr_init(info->fattr);
  697. status = rpc_call_sync(server->client, &msg, 0);
  698. dprintk("NFS reply pathconf: %d\n", status);
  699. return status;
  700. }
  701. static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data)
  702. {
  703. if (nfs3_async_handle_jukebox(task, data->inode))
  704. return -EAGAIN;
  705. nfs_invalidate_atime(data->inode);
  706. nfs_refresh_inode(data->inode, &data->fattr);
  707. return 0;
  708. }
  709. static void nfs3_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  710. {
  711. msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
  712. }
  713. static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
  714. {
  715. if (nfs3_async_handle_jukebox(task, data->inode))
  716. return -EAGAIN;
  717. if (task->tk_status >= 0)
  718. nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
  719. return 0;
  720. }
  721. static void nfs3_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  722. {
  723. msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
  724. }
  725. static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  726. {
  727. if (nfs3_async_handle_jukebox(task, data->inode))
  728. return -EAGAIN;
  729. nfs_refresh_inode(data->inode, data->res.fattr);
  730. return 0;
  731. }
  732. static void nfs3_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  733. {
  734. msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
  735. }
  736. static int
  737. nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  738. {
  739. struct inode *inode = filp->f_path.dentry->d_inode;
  740. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  741. }
  742. const struct nfs_rpc_ops nfs_v3_clientops = {
  743. .version = 3, /* protocol version */
  744. .dentry_ops = &nfs_dentry_operations,
  745. .dir_inode_ops = &nfs3_dir_inode_operations,
  746. .file_inode_ops = &nfs3_file_inode_operations,
  747. .file_ops = &nfs_file_operations,
  748. .getroot = nfs3_proc_get_root,
  749. .getattr = nfs3_proc_getattr,
  750. .setattr = nfs3_proc_setattr,
  751. .lookup = nfs3_proc_lookup,
  752. .access = nfs3_proc_access,
  753. .readlink = nfs3_proc_readlink,
  754. .create = nfs3_proc_create,
  755. .remove = nfs3_proc_remove,
  756. .unlink_setup = nfs3_proc_unlink_setup,
  757. .unlink_done = nfs3_proc_unlink_done,
  758. .rename = nfs3_proc_rename,
  759. .rename_setup = nfs3_proc_rename_setup,
  760. .rename_done = nfs3_proc_rename_done,
  761. .link = nfs3_proc_link,
  762. .symlink = nfs3_proc_symlink,
  763. .mkdir = nfs3_proc_mkdir,
  764. .rmdir = nfs3_proc_rmdir,
  765. .readdir = nfs3_proc_readdir,
  766. .mknod = nfs3_proc_mknod,
  767. .statfs = nfs3_proc_statfs,
  768. .fsinfo = nfs3_proc_fsinfo,
  769. .pathconf = nfs3_proc_pathconf,
  770. .decode_dirent = nfs3_decode_dirent,
  771. .read_setup = nfs3_proc_read_setup,
  772. .read_done = nfs3_read_done,
  773. .write_setup = nfs3_proc_write_setup,
  774. .write_done = nfs3_write_done,
  775. .commit_setup = nfs3_proc_commit_setup,
  776. .commit_done = nfs3_commit_done,
  777. .lock = nfs3_proc_lock,
  778. .clear_acl_cache = nfs3_forget_cached_acls,
  779. .close_context = nfs_close_context,
  780. .init_client = nfs_init_client,
  781. };