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