proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * linux/fs/nfs/proc.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994 Rick Sladkey
  5. *
  6. * OS-independent nfs remote procedure call functions
  7. *
  8. * Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers
  9. * so at last we can have decent(ish) throughput off a
  10. * Sun server.
  11. *
  12. * Coding optimized and cleaned up by Florian La Roche.
  13. * Note: Error returns are optimized for NFS_OK, which isn't translated via
  14. * nfs_stat_to_errno(), but happens to be already the right return code.
  15. *
  16. * Also, the code currently doesn't check the size of the packet, when
  17. * it decodes the packet.
  18. *
  19. * Feel free to fix it and mail me the diffs if it worries you.
  20. *
  21. * Completely rewritten to support the new RPC call interface;
  22. * rewrote and moved the entire XDR stuff to xdr.c
  23. * --Olaf Kirch June 1996
  24. *
  25. * The code below initializes all auto variables explicitly, otherwise
  26. * it will fail to work as a module (gcc generates a memset call for an
  27. * incomplete struct).
  28. */
  29. #include <linux/types.h>
  30. #include <linux/param.h>
  31. #include <linux/time.h>
  32. #include <linux/mm.h>
  33. #include <linux/errno.h>
  34. #include <linux/string.h>
  35. #include <linux/in.h>
  36. #include <linux/pagemap.h>
  37. #include <linux/sunrpc/clnt.h>
  38. #include <linux/nfs.h>
  39. #include <linux/nfs2.h>
  40. #include <linux/nfs_fs.h>
  41. #include <linux/nfs_page.h>
  42. #include <linux/lockd/bind.h>
  43. #include <linux/freezer.h>
  44. #include "internal.h"
  45. #define NFSDBG_FACILITY NFSDBG_PROC
  46. /*
  47. * Bare-bones access to getattr: this is for nfs_read_super.
  48. */
  49. static int
  50. nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  51. struct nfs_fsinfo *info)
  52. {
  53. struct nfs_fattr *fattr = info->fattr;
  54. struct nfs2_fsstat fsinfo;
  55. struct rpc_message msg = {
  56. .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
  57. .rpc_argp = fhandle,
  58. .rpc_resp = fattr,
  59. };
  60. int status;
  61. dprintk("%s: call getattr\n", __func__);
  62. nfs_fattr_init(fattr);
  63. status = rpc_call_sync(server->client, &msg, 0);
  64. /* Retry with default authentication if different */
  65. if (status && server->nfs_client->cl_rpcclient != server->client)
  66. status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
  67. dprintk("%s: reply getattr: %d\n", __func__, status);
  68. if (status)
  69. return status;
  70. dprintk("%s: call statfs\n", __func__);
  71. msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
  72. msg.rpc_resp = &fsinfo;
  73. status = rpc_call_sync(server->client, &msg, 0);
  74. /* Retry with default authentication if different */
  75. if (status && server->nfs_client->cl_rpcclient != server->client)
  76. status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
  77. dprintk("%s: reply statfs: %d\n", __func__, status);
  78. if (status)
  79. return status;
  80. info->rtmax = NFS_MAXDATA;
  81. info->rtpref = fsinfo.tsize;
  82. info->rtmult = fsinfo.bsize;
  83. info->wtmax = NFS_MAXDATA;
  84. info->wtpref = fsinfo.tsize;
  85. info->wtmult = fsinfo.bsize;
  86. info->dtpref = fsinfo.tsize;
  87. info->maxfilesize = 0x7FFFFFFF;
  88. info->lease_time = 0;
  89. return 0;
  90. }
  91. /*
  92. * One function for each procedure in the NFS protocol.
  93. */
  94. static int
  95. nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
  96. struct nfs_fattr *fattr, struct nfs4_label *label)
  97. {
  98. struct rpc_message msg = {
  99. .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
  100. .rpc_argp = fhandle,
  101. .rpc_resp = fattr,
  102. };
  103. int status;
  104. dprintk("NFS call getattr\n");
  105. nfs_fattr_init(fattr);
  106. status = rpc_call_sync(server->client, &msg, 0);
  107. dprintk("NFS reply getattr: %d\n", status);
  108. return status;
  109. }
  110. static int
  111. nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  112. struct iattr *sattr)
  113. {
  114. struct inode *inode = d_inode(dentry);
  115. struct nfs_sattrargs arg = {
  116. .fh = NFS_FH(inode),
  117. .sattr = sattr
  118. };
  119. struct rpc_message msg = {
  120. .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
  121. .rpc_argp = &arg,
  122. .rpc_resp = fattr,
  123. };
  124. int status;
  125. /* Mask out the non-modebit related stuff from attr->ia_mode */
  126. sattr->ia_mode &= S_IALLUGO;
  127. dprintk("NFS call setattr\n");
  128. if (sattr->ia_valid & ATTR_FILE)
  129. msg.rpc_cred = nfs_file_cred(sattr->ia_file);
  130. nfs_fattr_init(fattr);
  131. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  132. if (status == 0)
  133. nfs_setattr_update_inode(inode, sattr, fattr);
  134. dprintk("NFS reply setattr: %d\n", status);
  135. return status;
  136. }
  137. static int
  138. nfs_proc_lookup(struct inode *dir, struct qstr *name,
  139. struct nfs_fh *fhandle, struct nfs_fattr *fattr,
  140. struct nfs4_label *label)
  141. {
  142. struct nfs_diropargs arg = {
  143. .fh = NFS_FH(dir),
  144. .name = name->name,
  145. .len = name->len
  146. };
  147. struct nfs_diropok res = {
  148. .fh = fhandle,
  149. .fattr = fattr
  150. };
  151. struct rpc_message msg = {
  152. .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
  153. .rpc_argp = &arg,
  154. .rpc_resp = &res,
  155. };
  156. int status;
  157. dprintk("NFS call lookup %s\n", name->name);
  158. nfs_fattr_init(fattr);
  159. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  160. dprintk("NFS reply lookup: %d\n", status);
  161. return status;
  162. }
  163. static int nfs_proc_readlink(struct inode *inode, struct page *page,
  164. unsigned int pgbase, unsigned int pglen)
  165. {
  166. struct nfs_readlinkargs args = {
  167. .fh = NFS_FH(inode),
  168. .pgbase = pgbase,
  169. .pglen = pglen,
  170. .pages = &page
  171. };
  172. struct rpc_message msg = {
  173. .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
  174. .rpc_argp = &args,
  175. };
  176. int status;
  177. dprintk("NFS call readlink\n");
  178. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  179. dprintk("NFS reply readlink: %d\n", status);
  180. return status;
  181. }
  182. struct nfs_createdata {
  183. struct nfs_createargs arg;
  184. struct nfs_diropok res;
  185. struct nfs_fh fhandle;
  186. struct nfs_fattr fattr;
  187. };
  188. static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
  189. struct dentry *dentry, struct iattr *sattr)
  190. {
  191. struct nfs_createdata *data;
  192. data = kmalloc(sizeof(*data), GFP_KERNEL);
  193. if (data != NULL) {
  194. data->arg.fh = NFS_FH(dir);
  195. data->arg.name = dentry->d_name.name;
  196. data->arg.len = dentry->d_name.len;
  197. data->arg.sattr = sattr;
  198. nfs_fattr_init(&data->fattr);
  199. data->fhandle.size = 0;
  200. data->res.fh = &data->fhandle;
  201. data->res.fattr = &data->fattr;
  202. }
  203. return data;
  204. };
  205. static void nfs_free_createdata(const struct nfs_createdata *data)
  206. {
  207. kfree(data);
  208. }
  209. static int
  210. nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  211. int flags)
  212. {
  213. struct nfs_createdata *data;
  214. struct rpc_message msg = {
  215. .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
  216. };
  217. int status = -ENOMEM;
  218. dprintk("NFS call create %pd\n", dentry);
  219. data = nfs_alloc_createdata(dir, dentry, sattr);
  220. if (data == NULL)
  221. goto out;
  222. msg.rpc_argp = &data->arg;
  223. msg.rpc_resp = &data->res;
  224. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  225. nfs_mark_for_revalidate(dir);
  226. if (status == 0)
  227. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
  228. nfs_free_createdata(data);
  229. out:
  230. dprintk("NFS reply create: %d\n", status);
  231. return status;
  232. }
  233. /*
  234. * In NFSv2, mknod is grafted onto the create call.
  235. */
  236. static int
  237. nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  238. dev_t rdev)
  239. {
  240. struct nfs_createdata *data;
  241. struct rpc_message msg = {
  242. .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
  243. };
  244. umode_t mode;
  245. int status = -ENOMEM;
  246. dprintk("NFS call mknod %pd\n", dentry);
  247. mode = sattr->ia_mode;
  248. if (S_ISFIFO(mode)) {
  249. sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
  250. sattr->ia_valid &= ~ATTR_SIZE;
  251. } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
  252. sattr->ia_valid |= ATTR_SIZE;
  253. sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
  254. }
  255. data = nfs_alloc_createdata(dir, dentry, sattr);
  256. if (data == NULL)
  257. goto out;
  258. msg.rpc_argp = &data->arg;
  259. msg.rpc_resp = &data->res;
  260. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  261. nfs_mark_for_revalidate(dir);
  262. if (status == -EINVAL && S_ISFIFO(mode)) {
  263. sattr->ia_mode = mode;
  264. nfs_fattr_init(data->res.fattr);
  265. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  266. }
  267. if (status == 0)
  268. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
  269. nfs_free_createdata(data);
  270. out:
  271. dprintk("NFS reply mknod: %d\n", status);
  272. return status;
  273. }
  274. static int
  275. nfs_proc_remove(struct inode *dir, struct qstr *name)
  276. {
  277. struct nfs_removeargs arg = {
  278. .fh = NFS_FH(dir),
  279. .name = *name,
  280. };
  281. struct rpc_message msg = {
  282. .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
  283. .rpc_argp = &arg,
  284. };
  285. int status;
  286. dprintk("NFS call remove %s\n", name->name);
  287. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  288. nfs_mark_for_revalidate(dir);
  289. dprintk("NFS reply remove: %d\n", status);
  290. return status;
  291. }
  292. static void
  293. nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  294. {
  295. msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
  296. }
  297. static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
  298. {
  299. rpc_call_start(task);
  300. }
  301. static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  302. {
  303. nfs_mark_for_revalidate(dir);
  304. return 1;
  305. }
  306. static void
  307. nfs_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
  308. {
  309. msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
  310. }
  311. static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
  312. {
  313. rpc_call_start(task);
  314. }
  315. static int
  316. nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
  317. struct inode *new_dir)
  318. {
  319. nfs_mark_for_revalidate(old_dir);
  320. nfs_mark_for_revalidate(new_dir);
  321. return 1;
  322. }
  323. static int
  324. nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  325. {
  326. struct nfs_linkargs arg = {
  327. .fromfh = NFS_FH(inode),
  328. .tofh = NFS_FH(dir),
  329. .toname = name->name,
  330. .tolen = name->len
  331. };
  332. struct rpc_message msg = {
  333. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  334. .rpc_argp = &arg,
  335. };
  336. int status;
  337. dprintk("NFS call link %s\n", name->name);
  338. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  339. nfs_mark_for_revalidate(inode);
  340. nfs_mark_for_revalidate(dir);
  341. dprintk("NFS reply link: %d\n", status);
  342. return status;
  343. }
  344. static int
  345. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  346. unsigned int len, struct iattr *sattr)
  347. {
  348. struct nfs_fh *fh;
  349. struct nfs_fattr *fattr;
  350. struct nfs_symlinkargs arg = {
  351. .fromfh = NFS_FH(dir),
  352. .fromname = dentry->d_name.name,
  353. .fromlen = dentry->d_name.len,
  354. .pages = &page,
  355. .pathlen = len,
  356. .sattr = sattr
  357. };
  358. struct rpc_message msg = {
  359. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  360. .rpc_argp = &arg,
  361. };
  362. int status = -ENAMETOOLONG;
  363. dprintk("NFS call symlink %pd\n", dentry);
  364. if (len > NFS2_MAXPATHLEN)
  365. goto out;
  366. fh = nfs_alloc_fhandle();
  367. fattr = nfs_alloc_fattr();
  368. status = -ENOMEM;
  369. if (fh == NULL || fattr == NULL)
  370. goto out_free;
  371. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  372. nfs_mark_for_revalidate(dir);
  373. /*
  374. * V2 SYMLINK requests don't return any attributes. Setting the
  375. * filehandle size to zero indicates to nfs_instantiate that it
  376. * should fill in the data with a LOOKUP call on the wire.
  377. */
  378. if (status == 0)
  379. status = nfs_instantiate(dentry, fh, fattr, NULL);
  380. out_free:
  381. nfs_free_fattr(fattr);
  382. nfs_free_fhandle(fh);
  383. out:
  384. dprintk("NFS reply symlink: %d\n", status);
  385. return status;
  386. }
  387. static int
  388. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  389. {
  390. struct nfs_createdata *data;
  391. struct rpc_message msg = {
  392. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  393. };
  394. int status = -ENOMEM;
  395. dprintk("NFS call mkdir %pd\n", dentry);
  396. data = nfs_alloc_createdata(dir, dentry, sattr);
  397. if (data == NULL)
  398. goto out;
  399. msg.rpc_argp = &data->arg;
  400. msg.rpc_resp = &data->res;
  401. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  402. nfs_mark_for_revalidate(dir);
  403. if (status == 0)
  404. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
  405. nfs_free_createdata(data);
  406. out:
  407. dprintk("NFS reply mkdir: %d\n", status);
  408. return status;
  409. }
  410. static int
  411. nfs_proc_rmdir(struct inode *dir, struct qstr *name)
  412. {
  413. struct nfs_diropargs arg = {
  414. .fh = NFS_FH(dir),
  415. .name = name->name,
  416. .len = name->len
  417. };
  418. struct rpc_message msg = {
  419. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  420. .rpc_argp = &arg,
  421. };
  422. int status;
  423. dprintk("NFS call rmdir %s\n", name->name);
  424. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  425. nfs_mark_for_revalidate(dir);
  426. dprintk("NFS reply rmdir: %d\n", status);
  427. return status;
  428. }
  429. /*
  430. * The READDIR implementation is somewhat hackish - we pass a temporary
  431. * buffer to the encode function, which installs it in the receive
  432. * the receive iovec. The decode function just parses the reply to make
  433. * sure it is syntactically correct; the entries itself are decoded
  434. * from nfs_readdir by calling the decode_entry function directly.
  435. */
  436. static int
  437. nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  438. u64 cookie, struct page **pages, unsigned int count, int plus)
  439. {
  440. struct inode *dir = d_inode(dentry);
  441. struct nfs_readdirargs arg = {
  442. .fh = NFS_FH(dir),
  443. .cookie = cookie,
  444. .count = count,
  445. .pages = pages,
  446. };
  447. struct rpc_message msg = {
  448. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  449. .rpc_argp = &arg,
  450. .rpc_cred = cred,
  451. };
  452. int status;
  453. dprintk("NFS call readdir %d\n", (unsigned int)cookie);
  454. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  455. nfs_invalidate_atime(dir);
  456. dprintk("NFS reply readdir: %d\n", status);
  457. return status;
  458. }
  459. static int
  460. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  461. struct nfs_fsstat *stat)
  462. {
  463. struct nfs2_fsstat fsinfo;
  464. struct rpc_message msg = {
  465. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  466. .rpc_argp = fhandle,
  467. .rpc_resp = &fsinfo,
  468. };
  469. int status;
  470. dprintk("NFS call statfs\n");
  471. nfs_fattr_init(stat->fattr);
  472. status = rpc_call_sync(server->client, &msg, 0);
  473. dprintk("NFS reply statfs: %d\n", status);
  474. if (status)
  475. goto out;
  476. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  477. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  478. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  479. stat->tfiles = 0;
  480. stat->ffiles = 0;
  481. stat->afiles = 0;
  482. out:
  483. return status;
  484. }
  485. static int
  486. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  487. struct nfs_fsinfo *info)
  488. {
  489. struct nfs2_fsstat fsinfo;
  490. struct rpc_message msg = {
  491. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  492. .rpc_argp = fhandle,
  493. .rpc_resp = &fsinfo,
  494. };
  495. int status;
  496. dprintk("NFS call fsinfo\n");
  497. nfs_fattr_init(info->fattr);
  498. status = rpc_call_sync(server->client, &msg, 0);
  499. dprintk("NFS reply fsinfo: %d\n", status);
  500. if (status)
  501. goto out;
  502. info->rtmax = NFS_MAXDATA;
  503. info->rtpref = fsinfo.tsize;
  504. info->rtmult = fsinfo.bsize;
  505. info->wtmax = NFS_MAXDATA;
  506. info->wtpref = fsinfo.tsize;
  507. info->wtmult = fsinfo.bsize;
  508. info->dtpref = fsinfo.tsize;
  509. info->maxfilesize = 0x7FFFFFFF;
  510. info->lease_time = 0;
  511. out:
  512. return status;
  513. }
  514. static int
  515. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  516. struct nfs_pathconf *info)
  517. {
  518. info->max_link = 0;
  519. info->max_namelen = NFS2_MAXNAMLEN;
  520. return 0;
  521. }
  522. static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  523. {
  524. struct inode *inode = hdr->inode;
  525. nfs_invalidate_atime(inode);
  526. if (task->tk_status >= 0) {
  527. nfs_refresh_inode(inode, hdr->res.fattr);
  528. /* Emulate the eof flag, which isn't normally needed in NFSv2
  529. * as it is guaranteed to always return the file attributes
  530. */
  531. if (hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
  532. hdr->res.eof = 1;
  533. }
  534. return 0;
  535. }
  536. static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
  537. struct rpc_message *msg)
  538. {
  539. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  540. }
  541. static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
  542. struct nfs_pgio_header *hdr)
  543. {
  544. rpc_call_start(task);
  545. return 0;
  546. }
  547. static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  548. {
  549. if (task->tk_status >= 0)
  550. nfs_writeback_update_inode(hdr);
  551. return 0;
  552. }
  553. static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
  554. struct rpc_message *msg)
  555. {
  556. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  557. hdr->args.stable = NFS_FILE_SYNC;
  558. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  559. }
  560. static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
  561. {
  562. BUG();
  563. }
  564. static void
  565. nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
  566. {
  567. BUG();
  568. }
  569. static int
  570. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  571. {
  572. struct inode *inode = file_inode(filp);
  573. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl);
  574. }
  575. /* Helper functions for NFS lock bounds checking */
  576. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  577. static int nfs_lock_check_bounds(const struct file_lock *fl)
  578. {
  579. __s32 start, end;
  580. start = (__s32)fl->fl_start;
  581. if ((loff_t)start != fl->fl_start)
  582. goto out_einval;
  583. if (fl->fl_end != OFFSET_MAX) {
  584. end = (__s32)fl->fl_end;
  585. if ((loff_t)end != fl->fl_end)
  586. goto out_einval;
  587. } else
  588. end = NFS_LOCK32_OFFSET_MAX;
  589. if (start < 0 || start > end)
  590. goto out_einval;
  591. return 0;
  592. out_einval:
  593. return -EINVAL;
  594. }
  595. static int nfs_have_delegation(struct inode *inode, fmode_t flags)
  596. {
  597. return 0;
  598. }
  599. static int nfs_return_delegation(struct inode *inode)
  600. {
  601. nfs_wb_all(inode);
  602. return 0;
  603. }
  604. static const struct inode_operations nfs_dir_inode_operations = {
  605. .create = nfs_create,
  606. .lookup = nfs_lookup,
  607. .link = nfs_link,
  608. .unlink = nfs_unlink,
  609. .symlink = nfs_symlink,
  610. .mkdir = nfs_mkdir,
  611. .rmdir = nfs_rmdir,
  612. .mknod = nfs_mknod,
  613. .rename = nfs_rename,
  614. .permission = nfs_permission,
  615. .getattr = nfs_getattr,
  616. .setattr = nfs_setattr,
  617. };
  618. static const struct inode_operations nfs_file_inode_operations = {
  619. .permission = nfs_permission,
  620. .getattr = nfs_getattr,
  621. .setattr = nfs_setattr,
  622. };
  623. const struct nfs_rpc_ops nfs_v2_clientops = {
  624. .version = 2, /* protocol version */
  625. .dentry_ops = &nfs_dentry_operations,
  626. .dir_inode_ops = &nfs_dir_inode_operations,
  627. .file_inode_ops = &nfs_file_inode_operations,
  628. .file_ops = &nfs_file_operations,
  629. .getroot = nfs_proc_get_root,
  630. .submount = nfs_submount,
  631. .try_mount = nfs_try_mount,
  632. .getattr = nfs_proc_getattr,
  633. .setattr = nfs_proc_setattr,
  634. .lookup = nfs_proc_lookup,
  635. .access = NULL, /* access */
  636. .readlink = nfs_proc_readlink,
  637. .create = nfs_proc_create,
  638. .remove = nfs_proc_remove,
  639. .unlink_setup = nfs_proc_unlink_setup,
  640. .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
  641. .unlink_done = nfs_proc_unlink_done,
  642. .rename_setup = nfs_proc_rename_setup,
  643. .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
  644. .rename_done = nfs_proc_rename_done,
  645. .link = nfs_proc_link,
  646. .symlink = nfs_proc_symlink,
  647. .mkdir = nfs_proc_mkdir,
  648. .rmdir = nfs_proc_rmdir,
  649. .readdir = nfs_proc_readdir,
  650. .mknod = nfs_proc_mknod,
  651. .statfs = nfs_proc_statfs,
  652. .fsinfo = nfs_proc_fsinfo,
  653. .pathconf = nfs_proc_pathconf,
  654. .decode_dirent = nfs2_decode_dirent,
  655. .pgio_rpc_prepare = nfs_proc_pgio_rpc_prepare,
  656. .read_setup = nfs_proc_read_setup,
  657. .read_done = nfs_read_done,
  658. .write_setup = nfs_proc_write_setup,
  659. .write_done = nfs_write_done,
  660. .commit_setup = nfs_proc_commit_setup,
  661. .commit_rpc_prepare = nfs_proc_commit_rpc_prepare,
  662. .lock = nfs_proc_lock,
  663. .lock_check_bounds = nfs_lock_check_bounds,
  664. .close_context = nfs_close_context,
  665. .have_delegation = nfs_have_delegation,
  666. .return_delegation = nfs_return_delegation,
  667. .alloc_client = nfs_alloc_client,
  668. .init_client = nfs_init_client,
  669. .free_client = nfs_free_client,
  670. .create_server = nfs_create_server,
  671. .clone_server = nfs_clone_server,
  672. };