nfs3proc.c 23 KB

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