nfs3proc.c 21 KB

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