proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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, struct dentry *dentry)
  277. {
  278. struct nfs_removeargs arg = {
  279. .fh = NFS_FH(dir),
  280. .name = dentry->d_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 %pd2\n",dentry);
  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,
  295. struct dentry *dentry,
  296. struct inode *inode)
  297. {
  298. msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
  299. }
  300. static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
  301. {
  302. rpc_call_start(task);
  303. }
  304. static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  305. {
  306. nfs_mark_for_revalidate(dir);
  307. return 1;
  308. }
  309. static void
  310. nfs_proc_rename_setup(struct rpc_message *msg,
  311. struct dentry *old_dentry,
  312. struct dentry *new_dentry)
  313. {
  314. msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
  315. }
  316. static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
  317. {
  318. rpc_call_start(task);
  319. }
  320. static int
  321. nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
  322. struct inode *new_dir)
  323. {
  324. nfs_mark_for_revalidate(old_dir);
  325. nfs_mark_for_revalidate(new_dir);
  326. return 1;
  327. }
  328. static int
  329. nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
  330. {
  331. struct nfs_linkargs arg = {
  332. .fromfh = NFS_FH(inode),
  333. .tofh = NFS_FH(dir),
  334. .toname = name->name,
  335. .tolen = name->len
  336. };
  337. struct rpc_message msg = {
  338. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  339. .rpc_argp = &arg,
  340. };
  341. int status;
  342. dprintk("NFS call link %s\n", name->name);
  343. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  344. nfs_mark_for_revalidate(inode);
  345. nfs_mark_for_revalidate(dir);
  346. dprintk("NFS reply link: %d\n", status);
  347. return status;
  348. }
  349. static int
  350. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  351. unsigned int len, struct iattr *sattr)
  352. {
  353. struct nfs_fh *fh;
  354. struct nfs_fattr *fattr;
  355. struct nfs_symlinkargs arg = {
  356. .fromfh = NFS_FH(dir),
  357. .fromname = dentry->d_name.name,
  358. .fromlen = dentry->d_name.len,
  359. .pages = &page,
  360. .pathlen = len,
  361. .sattr = sattr
  362. };
  363. struct rpc_message msg = {
  364. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  365. .rpc_argp = &arg,
  366. };
  367. int status = -ENAMETOOLONG;
  368. dprintk("NFS call symlink %pd\n", dentry);
  369. if (len > NFS2_MAXPATHLEN)
  370. goto out;
  371. fh = nfs_alloc_fhandle();
  372. fattr = nfs_alloc_fattr();
  373. status = -ENOMEM;
  374. if (fh == NULL || fattr == NULL)
  375. goto out_free;
  376. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  377. nfs_mark_for_revalidate(dir);
  378. /*
  379. * V2 SYMLINK requests don't return any attributes. Setting the
  380. * filehandle size to zero indicates to nfs_instantiate that it
  381. * should fill in the data with a LOOKUP call on the wire.
  382. */
  383. if (status == 0)
  384. status = nfs_instantiate(dentry, fh, fattr, NULL);
  385. out_free:
  386. nfs_free_fattr(fattr);
  387. nfs_free_fhandle(fh);
  388. out:
  389. dprintk("NFS reply symlink: %d\n", status);
  390. return status;
  391. }
  392. static int
  393. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  394. {
  395. struct nfs_createdata *data;
  396. struct rpc_message msg = {
  397. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  398. };
  399. int status = -ENOMEM;
  400. dprintk("NFS call mkdir %pd\n", dentry);
  401. data = nfs_alloc_createdata(dir, dentry, sattr);
  402. if (data == NULL)
  403. goto out;
  404. msg.rpc_argp = &data->arg;
  405. msg.rpc_resp = &data->res;
  406. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  407. nfs_mark_for_revalidate(dir);
  408. if (status == 0)
  409. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
  410. nfs_free_createdata(data);
  411. out:
  412. dprintk("NFS reply mkdir: %d\n", status);
  413. return status;
  414. }
  415. static int
  416. nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
  417. {
  418. struct nfs_diropargs arg = {
  419. .fh = NFS_FH(dir),
  420. .name = name->name,
  421. .len = name->len
  422. };
  423. struct rpc_message msg = {
  424. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  425. .rpc_argp = &arg,
  426. };
  427. int status;
  428. dprintk("NFS call rmdir %s\n", name->name);
  429. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  430. nfs_mark_for_revalidate(dir);
  431. dprintk("NFS reply rmdir: %d\n", status);
  432. return status;
  433. }
  434. /*
  435. * The READDIR implementation is somewhat hackish - we pass a temporary
  436. * buffer to the encode function, which installs it in the receive
  437. * the receive iovec. The decode function just parses the reply to make
  438. * sure it is syntactically correct; the entries itself are decoded
  439. * from nfs_readdir by calling the decode_entry function directly.
  440. */
  441. static int
  442. nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  443. u64 cookie, struct page **pages, unsigned int count, bool plus)
  444. {
  445. struct inode *dir = d_inode(dentry);
  446. struct nfs_readdirargs arg = {
  447. .fh = NFS_FH(dir),
  448. .cookie = cookie,
  449. .count = count,
  450. .pages = pages,
  451. };
  452. struct rpc_message msg = {
  453. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  454. .rpc_argp = &arg,
  455. .rpc_cred = cred,
  456. };
  457. int status;
  458. dprintk("NFS call readdir %d\n", (unsigned int)cookie);
  459. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  460. nfs_invalidate_atime(dir);
  461. dprintk("NFS reply readdir: %d\n", status);
  462. return status;
  463. }
  464. static int
  465. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  466. struct nfs_fsstat *stat)
  467. {
  468. struct nfs2_fsstat fsinfo;
  469. struct rpc_message msg = {
  470. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  471. .rpc_argp = fhandle,
  472. .rpc_resp = &fsinfo,
  473. };
  474. int status;
  475. dprintk("NFS call statfs\n");
  476. nfs_fattr_init(stat->fattr);
  477. status = rpc_call_sync(server->client, &msg, 0);
  478. dprintk("NFS reply statfs: %d\n", status);
  479. if (status)
  480. goto out;
  481. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  482. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  483. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  484. stat->tfiles = 0;
  485. stat->ffiles = 0;
  486. stat->afiles = 0;
  487. out:
  488. return status;
  489. }
  490. static int
  491. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  492. struct nfs_fsinfo *info)
  493. {
  494. struct nfs2_fsstat fsinfo;
  495. struct rpc_message msg = {
  496. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  497. .rpc_argp = fhandle,
  498. .rpc_resp = &fsinfo,
  499. };
  500. int status;
  501. dprintk("NFS call fsinfo\n");
  502. nfs_fattr_init(info->fattr);
  503. status = rpc_call_sync(server->client, &msg, 0);
  504. dprintk("NFS reply fsinfo: %d\n", status);
  505. if (status)
  506. goto out;
  507. info->rtmax = NFS_MAXDATA;
  508. info->rtpref = fsinfo.tsize;
  509. info->rtmult = fsinfo.bsize;
  510. info->wtmax = NFS_MAXDATA;
  511. info->wtpref = fsinfo.tsize;
  512. info->wtmult = fsinfo.bsize;
  513. info->dtpref = fsinfo.tsize;
  514. info->maxfilesize = 0x7FFFFFFF;
  515. info->lease_time = 0;
  516. out:
  517. return status;
  518. }
  519. static int
  520. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  521. struct nfs_pathconf *info)
  522. {
  523. info->max_link = 0;
  524. info->max_namelen = NFS2_MAXNAMLEN;
  525. return 0;
  526. }
  527. static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  528. {
  529. struct inode *inode = hdr->inode;
  530. nfs_invalidate_atime(inode);
  531. if (task->tk_status >= 0) {
  532. nfs_refresh_inode(inode, hdr->res.fattr);
  533. /* Emulate the eof flag, which isn't normally needed in NFSv2
  534. * as it is guaranteed to always return the file attributes
  535. */
  536. if (hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
  537. hdr->res.eof = 1;
  538. }
  539. return 0;
  540. }
  541. static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
  542. struct rpc_message *msg)
  543. {
  544. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  545. }
  546. static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
  547. struct nfs_pgio_header *hdr)
  548. {
  549. rpc_call_start(task);
  550. return 0;
  551. }
  552. static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  553. {
  554. if (task->tk_status >= 0)
  555. nfs_writeback_update_inode(hdr);
  556. return 0;
  557. }
  558. static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
  559. struct rpc_message *msg,
  560. struct rpc_clnt **clnt)
  561. {
  562. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  563. hdr->args.stable = NFS_FILE_SYNC;
  564. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  565. }
  566. static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
  567. {
  568. BUG();
  569. }
  570. static void
  571. nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
  572. struct rpc_clnt **clnt)
  573. {
  574. BUG();
  575. }
  576. static int
  577. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  578. {
  579. struct inode *inode = file_inode(filp);
  580. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, NULL);
  581. }
  582. /* Helper functions for NFS lock bounds checking */
  583. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  584. static int nfs_lock_check_bounds(const struct file_lock *fl)
  585. {
  586. __s32 start, end;
  587. start = (__s32)fl->fl_start;
  588. if ((loff_t)start != fl->fl_start)
  589. goto out_einval;
  590. if (fl->fl_end != OFFSET_MAX) {
  591. end = (__s32)fl->fl_end;
  592. if ((loff_t)end != fl->fl_end)
  593. goto out_einval;
  594. } else
  595. end = NFS_LOCK32_OFFSET_MAX;
  596. if (start < 0 || start > end)
  597. goto out_einval;
  598. return 0;
  599. out_einval:
  600. return -EINVAL;
  601. }
  602. static int nfs_have_delegation(struct inode *inode, fmode_t flags)
  603. {
  604. return 0;
  605. }
  606. static const struct inode_operations nfs_dir_inode_operations = {
  607. .create = nfs_create,
  608. .lookup = nfs_lookup,
  609. .link = nfs_link,
  610. .unlink = nfs_unlink,
  611. .symlink = nfs_symlink,
  612. .mkdir = nfs_mkdir,
  613. .rmdir = nfs_rmdir,
  614. .mknod = nfs_mknod,
  615. .rename = nfs_rename,
  616. .permission = nfs_permission,
  617. .getattr = nfs_getattr,
  618. .setattr = nfs_setattr,
  619. };
  620. static const struct inode_operations nfs_file_inode_operations = {
  621. .permission = nfs_permission,
  622. .getattr = nfs_getattr,
  623. .setattr = nfs_setattr,
  624. };
  625. const struct nfs_rpc_ops nfs_v2_clientops = {
  626. .version = 2, /* protocol version */
  627. .dentry_ops = &nfs_dentry_operations,
  628. .dir_inode_ops = &nfs_dir_inode_operations,
  629. .file_inode_ops = &nfs_file_inode_operations,
  630. .file_ops = &nfs_file_operations,
  631. .getroot = nfs_proc_get_root,
  632. .submount = nfs_submount,
  633. .try_mount = nfs_try_mount,
  634. .getattr = nfs_proc_getattr,
  635. .setattr = nfs_proc_setattr,
  636. .lookup = nfs_proc_lookup,
  637. .access = NULL, /* access */
  638. .readlink = nfs_proc_readlink,
  639. .create = nfs_proc_create,
  640. .remove = nfs_proc_remove,
  641. .unlink_setup = nfs_proc_unlink_setup,
  642. .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
  643. .unlink_done = nfs_proc_unlink_done,
  644. .rename_setup = nfs_proc_rename_setup,
  645. .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
  646. .rename_done = nfs_proc_rename_done,
  647. .link = nfs_proc_link,
  648. .symlink = nfs_proc_symlink,
  649. .mkdir = nfs_proc_mkdir,
  650. .rmdir = nfs_proc_rmdir,
  651. .readdir = nfs_proc_readdir,
  652. .mknod = nfs_proc_mknod,
  653. .statfs = nfs_proc_statfs,
  654. .fsinfo = nfs_proc_fsinfo,
  655. .pathconf = nfs_proc_pathconf,
  656. .decode_dirent = nfs2_decode_dirent,
  657. .pgio_rpc_prepare = nfs_proc_pgio_rpc_prepare,
  658. .read_setup = nfs_proc_read_setup,
  659. .read_done = nfs_read_done,
  660. .write_setup = nfs_proc_write_setup,
  661. .write_done = nfs_write_done,
  662. .commit_setup = nfs_proc_commit_setup,
  663. .commit_rpc_prepare = nfs_proc_commit_rpc_prepare,
  664. .lock = nfs_proc_lock,
  665. .lock_check_bounds = nfs_lock_check_bounds,
  666. .close_context = nfs_close_context,
  667. .have_delegation = nfs_have_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. };