nfs3proc.c 21 KB

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