nfs3proc.c 21 KB

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