nfs3proc.c 24 KB

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