nfs3proc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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 nfs_fattr dir_attr, fattr;
  419. struct nfs3_linkargs arg = {
  420. .fromfh = NFS_FH(inode),
  421. .tofh = NFS_FH(dir),
  422. .toname = name->name,
  423. .tolen = name->len
  424. };
  425. struct nfs3_linkres res = {
  426. .dir_attr = &dir_attr,
  427. .fattr = &fattr
  428. };
  429. struct rpc_message msg = {
  430. .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
  431. .rpc_argp = &arg,
  432. .rpc_resp = &res,
  433. };
  434. int status;
  435. dprintk("NFS call link %s\n", name->name);
  436. nfs_fattr_init(&dir_attr);
  437. nfs_fattr_init(&fattr);
  438. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  439. nfs_post_op_update_inode(dir, &dir_attr);
  440. nfs_post_op_update_inode(inode, &fattr);
  441. dprintk("NFS reply link: %d\n", status);
  442. return status;
  443. }
  444. static int
  445. nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  446. unsigned int len, struct iattr *sattr)
  447. {
  448. struct nfs3_createdata *data;
  449. int status = -ENOMEM;
  450. if (len > NFS3_MAXPATHLEN)
  451. return -ENAMETOOLONG;
  452. dprintk("NFS call symlink %s\n", dentry->d_name.name);
  453. data = nfs3_alloc_createdata();
  454. if (data == NULL)
  455. goto out;
  456. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
  457. data->arg.symlink.fromfh = NFS_FH(dir);
  458. data->arg.symlink.fromname = dentry->d_name.name;
  459. data->arg.symlink.fromlen = dentry->d_name.len;
  460. data->arg.symlink.pages = &page;
  461. data->arg.symlink.pathlen = len;
  462. data->arg.symlink.sattr = sattr;
  463. status = nfs3_do_create(dir, dentry, data);
  464. nfs3_free_createdata(data);
  465. out:
  466. dprintk("NFS reply symlink: %d\n", status);
  467. return status;
  468. }
  469. static int
  470. nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  471. {
  472. struct nfs3_createdata *data;
  473. int mode = sattr->ia_mode;
  474. int status = -ENOMEM;
  475. dprintk("NFS call mkdir %s\n", dentry->d_name.name);
  476. sattr->ia_mode &= ~current_umask();
  477. data = nfs3_alloc_createdata();
  478. if (data == NULL)
  479. goto out;
  480. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
  481. data->arg.mkdir.fh = NFS_FH(dir);
  482. data->arg.mkdir.name = dentry->d_name.name;
  483. data->arg.mkdir.len = dentry->d_name.len;
  484. data->arg.mkdir.sattr = sattr;
  485. status = nfs3_do_create(dir, dentry, data);
  486. if (status != 0)
  487. goto out;
  488. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  489. out:
  490. nfs3_free_createdata(data);
  491. dprintk("NFS reply mkdir: %d\n", status);
  492. return status;
  493. }
  494. static int
  495. nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
  496. {
  497. struct nfs_fattr dir_attr;
  498. struct nfs3_diropargs arg = {
  499. .fh = NFS_FH(dir),
  500. .name = name->name,
  501. .len = name->len
  502. };
  503. struct rpc_message msg = {
  504. .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
  505. .rpc_argp = &arg,
  506. .rpc_resp = &dir_attr,
  507. };
  508. int status;
  509. dprintk("NFS call rmdir %s\n", name->name);
  510. nfs_fattr_init(&dir_attr);
  511. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  512. nfs_post_op_update_inode(dir, &dir_attr);
  513. dprintk("NFS reply rmdir: %d\n", status);
  514. return status;
  515. }
  516. /*
  517. * The READDIR implementation is somewhat hackish - we pass the user buffer
  518. * to the encode function, which installs it in the receive iovec.
  519. * The decode function itself doesn't perform any decoding, it just makes
  520. * sure the reply is syntactically correct.
  521. *
  522. * Also note that this implementation handles both plain readdir and
  523. * readdirplus.
  524. */
  525. static int
  526. nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  527. u64 cookie, struct page *page, unsigned int count, int plus)
  528. {
  529. struct inode *dir = dentry->d_inode;
  530. __be32 *verf = NFS_COOKIEVERF(dir);
  531. struct nfs3_readdirargs arg = {
  532. .fh = NFS_FH(dir),
  533. .cookie = cookie,
  534. .verf = {verf[0], verf[1]},
  535. .plus = plus,
  536. .count = count,
  537. .pages = &page
  538. };
  539. struct nfs3_readdirres res = {
  540. .verf = verf,
  541. .plus = plus
  542. };
  543. struct rpc_message msg = {
  544. .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
  545. .rpc_argp = &arg,
  546. .rpc_resp = &res,
  547. .rpc_cred = cred
  548. };
  549. int status = -ENOMEM;
  550. if (plus)
  551. msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
  552. dprintk("NFS call readdir%s %d\n",
  553. plus? "plus" : "", (unsigned int) cookie);
  554. res.dir_attr = nfs_alloc_fattr();
  555. if (res.dir_attr == NULL)
  556. goto out;
  557. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  558. nfs_invalidate_atime(dir);
  559. nfs_refresh_inode(dir, res.dir_attr);
  560. nfs_free_fattr(res.dir_attr);
  561. out:
  562. dprintk("NFS reply readdir: %d\n", status);
  563. return status;
  564. }
  565. static int
  566. nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  567. dev_t rdev)
  568. {
  569. struct nfs3_createdata *data;
  570. mode_t mode = sattr->ia_mode;
  571. int status = -ENOMEM;
  572. dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
  573. MAJOR(rdev), MINOR(rdev));
  574. sattr->ia_mode &= ~current_umask();
  575. data = nfs3_alloc_createdata();
  576. if (data == NULL)
  577. goto out;
  578. data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
  579. data->arg.mknod.fh = NFS_FH(dir);
  580. data->arg.mknod.name = dentry->d_name.name;
  581. data->arg.mknod.len = dentry->d_name.len;
  582. data->arg.mknod.sattr = sattr;
  583. data->arg.mknod.rdev = rdev;
  584. switch (sattr->ia_mode & S_IFMT) {
  585. case S_IFBLK:
  586. data->arg.mknod.type = NF3BLK;
  587. break;
  588. case S_IFCHR:
  589. data->arg.mknod.type = NF3CHR;
  590. break;
  591. case S_IFIFO:
  592. data->arg.mknod.type = NF3FIFO;
  593. break;
  594. case S_IFSOCK:
  595. data->arg.mknod.type = NF3SOCK;
  596. break;
  597. default:
  598. status = -EINVAL;
  599. goto out;
  600. }
  601. status = nfs3_do_create(dir, dentry, data);
  602. if (status != 0)
  603. goto out;
  604. status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
  605. out:
  606. nfs3_free_createdata(data);
  607. dprintk("NFS reply mknod: %d\n", status);
  608. return status;
  609. }
  610. static int
  611. nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  612. struct nfs_fsstat *stat)
  613. {
  614. struct rpc_message msg = {
  615. .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
  616. .rpc_argp = fhandle,
  617. .rpc_resp = stat,
  618. };
  619. int status;
  620. dprintk("NFS call fsstat\n");
  621. nfs_fattr_init(stat->fattr);
  622. status = rpc_call_sync(server->client, &msg, 0);
  623. dprintk("NFS reply statfs: %d\n", status);
  624. return status;
  625. }
  626. static int
  627. do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
  628. struct nfs_fsinfo *info)
  629. {
  630. struct rpc_message msg = {
  631. .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
  632. .rpc_argp = fhandle,
  633. .rpc_resp = info,
  634. };
  635. int status;
  636. dprintk("NFS call fsinfo\n");
  637. nfs_fattr_init(info->fattr);
  638. status = rpc_call_sync(client, &msg, 0);
  639. dprintk("NFS reply fsinfo: %d\n", status);
  640. return status;
  641. }
  642. /*
  643. * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
  644. * nfs_create_server
  645. */
  646. static int
  647. nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  648. struct nfs_fsinfo *info)
  649. {
  650. int status;
  651. status = do_proc_fsinfo(server->client, fhandle, info);
  652. if (status && server->nfs_client->cl_rpcclient != server->client)
  653. status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
  654. return status;
  655. }
  656. static int
  657. nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  658. struct nfs_pathconf *info)
  659. {
  660. struct rpc_message msg = {
  661. .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
  662. .rpc_argp = fhandle,
  663. .rpc_resp = info,
  664. };
  665. int status;
  666. dprintk("NFS call pathconf\n");
  667. nfs_fattr_init(info->fattr);
  668. status = rpc_call_sync(server->client, &msg, 0);
  669. dprintk("NFS reply pathconf: %d\n", status);
  670. return status;
  671. }
  672. static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data)
  673. {
  674. if (nfs3_async_handle_jukebox(task, data->inode))
  675. return -EAGAIN;
  676. nfs_invalidate_atime(data->inode);
  677. nfs_refresh_inode(data->inode, &data->fattr);
  678. return 0;
  679. }
  680. static void nfs3_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  681. {
  682. msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
  683. }
  684. static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
  685. {
  686. if (nfs3_async_handle_jukebox(task, data->inode))
  687. return -EAGAIN;
  688. if (task->tk_status >= 0)
  689. nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr);
  690. return 0;
  691. }
  692. static void nfs3_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  693. {
  694. msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
  695. }
  696. static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  697. {
  698. if (nfs3_async_handle_jukebox(task, data->inode))
  699. return -EAGAIN;
  700. nfs_refresh_inode(data->inode, data->res.fattr);
  701. return 0;
  702. }
  703. static void nfs3_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  704. {
  705. msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
  706. }
  707. static int
  708. nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  709. {
  710. struct inode *inode = filp->f_path.dentry->d_inode;
  711. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  712. }
  713. const struct nfs_rpc_ops nfs_v3_clientops = {
  714. .version = 3, /* protocol version */
  715. .dentry_ops = &nfs_dentry_operations,
  716. .dir_inode_ops = &nfs3_dir_inode_operations,
  717. .file_inode_ops = &nfs3_file_inode_operations,
  718. .getroot = nfs3_proc_get_root,
  719. .getattr = nfs3_proc_getattr,
  720. .setattr = nfs3_proc_setattr,
  721. .lookup = nfs3_proc_lookup,
  722. .access = nfs3_proc_access,
  723. .readlink = nfs3_proc_readlink,
  724. .create = nfs3_proc_create,
  725. .remove = nfs3_proc_remove,
  726. .unlink_setup = nfs3_proc_unlink_setup,
  727. .unlink_done = nfs3_proc_unlink_done,
  728. .rename = nfs3_proc_rename,
  729. .link = nfs3_proc_link,
  730. .symlink = nfs3_proc_symlink,
  731. .mkdir = nfs3_proc_mkdir,
  732. .rmdir = nfs3_proc_rmdir,
  733. .readdir = nfs3_proc_readdir,
  734. .mknod = nfs3_proc_mknod,
  735. .statfs = nfs3_proc_statfs,
  736. .fsinfo = nfs3_proc_fsinfo,
  737. .pathconf = nfs3_proc_pathconf,
  738. .decode_dirent = nfs3_decode_dirent,
  739. .read_setup = nfs3_proc_read_setup,
  740. .read_done = nfs3_read_done,
  741. .write_setup = nfs3_proc_write_setup,
  742. .write_done = nfs3_write_done,
  743. .commit_setup = nfs3_proc_commit_setup,
  744. .commit_done = nfs3_commit_done,
  745. .lock = nfs3_proc_lock,
  746. .clear_acl_cache = nfs3_forget_cached_acls,
  747. .close_context = nfs_close_context,
  748. };