nfs3proc.c 24 KB

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