nfs3proc.c 21 KB

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