proc.c 19 KB

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