proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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, struct dentry *dentry)
  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,
  309. struct dentry *old_dentry,
  310. struct dentry *new_dentry)
  311. {
  312. msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
  313. }
  314. static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
  315. {
  316. rpc_call_start(task);
  317. }
  318. static int
  319. nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
  320. struct inode *new_dir)
  321. {
  322. nfs_mark_for_revalidate(old_dir);
  323. nfs_mark_for_revalidate(new_dir);
  324. return 1;
  325. }
  326. static int
  327. nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
  328. {
  329. struct nfs_linkargs arg = {
  330. .fromfh = NFS_FH(inode),
  331. .tofh = NFS_FH(dir),
  332. .toname = name->name,
  333. .tolen = name->len
  334. };
  335. struct rpc_message msg = {
  336. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  337. .rpc_argp = &arg,
  338. };
  339. int status;
  340. dprintk("NFS call link %s\n", name->name);
  341. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  342. nfs_mark_for_revalidate(inode);
  343. nfs_mark_for_revalidate(dir);
  344. dprintk("NFS reply link: %d\n", status);
  345. return status;
  346. }
  347. static int
  348. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  349. unsigned int len, struct iattr *sattr)
  350. {
  351. struct nfs_fh *fh;
  352. struct nfs_fattr *fattr;
  353. struct nfs_symlinkargs arg = {
  354. .fromfh = NFS_FH(dir),
  355. .fromname = dentry->d_name.name,
  356. .fromlen = dentry->d_name.len,
  357. .pages = &page,
  358. .pathlen = len,
  359. .sattr = sattr
  360. };
  361. struct rpc_message msg = {
  362. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  363. .rpc_argp = &arg,
  364. };
  365. int status = -ENAMETOOLONG;
  366. dprintk("NFS call symlink %pd\n", dentry);
  367. if (len > NFS2_MAXPATHLEN)
  368. goto out;
  369. fh = nfs_alloc_fhandle();
  370. fattr = nfs_alloc_fattr();
  371. status = -ENOMEM;
  372. if (fh == NULL || fattr == NULL)
  373. goto out_free;
  374. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  375. nfs_mark_for_revalidate(dir);
  376. /*
  377. * V2 SYMLINK requests don't return any attributes. Setting the
  378. * filehandle size to zero indicates to nfs_instantiate that it
  379. * should fill in the data with a LOOKUP call on the wire.
  380. */
  381. if (status == 0)
  382. status = nfs_instantiate(dentry, fh, fattr, NULL);
  383. out_free:
  384. nfs_free_fattr(fattr);
  385. nfs_free_fhandle(fh);
  386. out:
  387. dprintk("NFS reply symlink: %d\n", status);
  388. return status;
  389. }
  390. static int
  391. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  392. {
  393. struct nfs_createdata *data;
  394. struct rpc_message msg = {
  395. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  396. };
  397. int status = -ENOMEM;
  398. dprintk("NFS call mkdir %pd\n", dentry);
  399. data = nfs_alloc_createdata(dir, dentry, sattr);
  400. if (data == NULL)
  401. goto out;
  402. msg.rpc_argp = &data->arg;
  403. msg.rpc_resp = &data->res;
  404. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  405. nfs_mark_for_revalidate(dir);
  406. if (status == 0)
  407. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
  408. nfs_free_createdata(data);
  409. out:
  410. dprintk("NFS reply mkdir: %d\n", status);
  411. return status;
  412. }
  413. static int
  414. nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
  415. {
  416. struct nfs_diropargs arg = {
  417. .fh = NFS_FH(dir),
  418. .name = name->name,
  419. .len = name->len
  420. };
  421. struct rpc_message msg = {
  422. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  423. .rpc_argp = &arg,
  424. };
  425. int status;
  426. dprintk("NFS call rmdir %s\n", name->name);
  427. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  428. nfs_mark_for_revalidate(dir);
  429. dprintk("NFS reply rmdir: %d\n", status);
  430. return status;
  431. }
  432. /*
  433. * The READDIR implementation is somewhat hackish - we pass a temporary
  434. * buffer to the encode function, which installs it in the receive
  435. * the receive iovec. The decode function just parses the reply to make
  436. * sure it is syntactically correct; the entries itself are decoded
  437. * from nfs_readdir by calling the decode_entry function directly.
  438. */
  439. static int
  440. nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  441. u64 cookie, struct page **pages, unsigned int count, bool plus)
  442. {
  443. struct inode *dir = d_inode(dentry);
  444. struct nfs_readdirargs arg = {
  445. .fh = NFS_FH(dir),
  446. .cookie = cookie,
  447. .count = count,
  448. .pages = pages,
  449. };
  450. struct rpc_message msg = {
  451. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  452. .rpc_argp = &arg,
  453. .rpc_cred = cred,
  454. };
  455. int status;
  456. dprintk("NFS call readdir %d\n", (unsigned int)cookie);
  457. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  458. nfs_invalidate_atime(dir);
  459. dprintk("NFS reply readdir: %d\n", status);
  460. return status;
  461. }
  462. static int
  463. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  464. struct nfs_fsstat *stat)
  465. {
  466. struct nfs2_fsstat fsinfo;
  467. struct rpc_message msg = {
  468. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  469. .rpc_argp = fhandle,
  470. .rpc_resp = &fsinfo,
  471. };
  472. int status;
  473. dprintk("NFS call statfs\n");
  474. nfs_fattr_init(stat->fattr);
  475. status = rpc_call_sync(server->client, &msg, 0);
  476. dprintk("NFS reply statfs: %d\n", status);
  477. if (status)
  478. goto out;
  479. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  480. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  481. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  482. stat->tfiles = 0;
  483. stat->ffiles = 0;
  484. stat->afiles = 0;
  485. out:
  486. return status;
  487. }
  488. static int
  489. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  490. struct nfs_fsinfo *info)
  491. {
  492. struct nfs2_fsstat fsinfo;
  493. struct rpc_message msg = {
  494. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  495. .rpc_argp = fhandle,
  496. .rpc_resp = &fsinfo,
  497. };
  498. int status;
  499. dprintk("NFS call fsinfo\n");
  500. nfs_fattr_init(info->fattr);
  501. status = rpc_call_sync(server->client, &msg, 0);
  502. dprintk("NFS reply fsinfo: %d\n", status);
  503. if (status)
  504. goto out;
  505. info->rtmax = NFS_MAXDATA;
  506. info->rtpref = fsinfo.tsize;
  507. info->rtmult = fsinfo.bsize;
  508. info->wtmax = NFS_MAXDATA;
  509. info->wtpref = fsinfo.tsize;
  510. info->wtmult = fsinfo.bsize;
  511. info->dtpref = fsinfo.tsize;
  512. info->maxfilesize = 0x7FFFFFFF;
  513. info->lease_time = 0;
  514. out:
  515. return status;
  516. }
  517. static int
  518. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  519. struct nfs_pathconf *info)
  520. {
  521. info->max_link = 0;
  522. info->max_namelen = NFS2_MAXNAMLEN;
  523. return 0;
  524. }
  525. static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  526. {
  527. struct inode *inode = hdr->inode;
  528. nfs_invalidate_atime(inode);
  529. if (task->tk_status >= 0) {
  530. nfs_refresh_inode(inode, hdr->res.fattr);
  531. /* Emulate the eof flag, which isn't normally needed in NFSv2
  532. * as it is guaranteed to always return the file attributes
  533. */
  534. if (hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
  535. hdr->res.eof = 1;
  536. }
  537. return 0;
  538. }
  539. static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
  540. struct rpc_message *msg)
  541. {
  542. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  543. }
  544. static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
  545. struct nfs_pgio_header *hdr)
  546. {
  547. rpc_call_start(task);
  548. return 0;
  549. }
  550. static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  551. {
  552. if (task->tk_status >= 0)
  553. nfs_writeback_update_inode(hdr);
  554. return 0;
  555. }
  556. static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
  557. struct rpc_message *msg,
  558. struct rpc_clnt **clnt)
  559. {
  560. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  561. hdr->args.stable = NFS_FILE_SYNC;
  562. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  563. }
  564. static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
  565. {
  566. BUG();
  567. }
  568. static void
  569. nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
  570. struct rpc_clnt **clnt)
  571. {
  572. BUG();
  573. }
  574. static int
  575. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  576. {
  577. struct inode *inode = file_inode(filp);
  578. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, NULL);
  579. }
  580. /* Helper functions for NFS lock bounds checking */
  581. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  582. static int nfs_lock_check_bounds(const struct file_lock *fl)
  583. {
  584. __s32 start, end;
  585. start = (__s32)fl->fl_start;
  586. if ((loff_t)start != fl->fl_start)
  587. goto out_einval;
  588. if (fl->fl_end != OFFSET_MAX) {
  589. end = (__s32)fl->fl_end;
  590. if ((loff_t)end != fl->fl_end)
  591. goto out_einval;
  592. } else
  593. end = NFS_LOCK32_OFFSET_MAX;
  594. if (start < 0 || start > end)
  595. goto out_einval;
  596. return 0;
  597. out_einval:
  598. return -EINVAL;
  599. }
  600. static int nfs_have_delegation(struct inode *inode, fmode_t flags)
  601. {
  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. .alloc_client = nfs_alloc_client,
  667. .init_client = nfs_init_client,
  668. .free_client = nfs_free_client,
  669. .create_server = nfs_create_server,
  670. .clone_server = nfs_clone_server,
  671. };