proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 <[email protected]> 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. info->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED;
  91. info->xattr_support = 0;
  92. return 0;
  93. }
  94. /*
  95. * One function for each procedure in the NFS protocol.
  96. */
  97. static int
  98. nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
  99. struct nfs_fattr *fattr, struct inode *inode)
  100. {
  101. struct rpc_message msg = {
  102. .rpc_proc = &nfs_procedures[NFSPROC_GETATTR],
  103. .rpc_argp = fhandle,
  104. .rpc_resp = fattr,
  105. };
  106. int status;
  107. unsigned short task_flags = 0;
  108. /* Is this is an attribute revalidation, subject to softreval? */
  109. if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
  110. task_flags |= RPC_TASK_TIMEOUT;
  111. dprintk("NFS call getattr\n");
  112. nfs_fattr_init(fattr);
  113. status = rpc_call_sync(server->client, &msg, task_flags);
  114. dprintk("NFS reply getattr: %d\n", status);
  115. return status;
  116. }
  117. static int
  118. nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  119. struct iattr *sattr)
  120. {
  121. struct inode *inode = d_inode(dentry);
  122. struct nfs_sattrargs arg = {
  123. .fh = NFS_FH(inode),
  124. .sattr = sattr
  125. };
  126. struct rpc_message msg = {
  127. .rpc_proc = &nfs_procedures[NFSPROC_SETATTR],
  128. .rpc_argp = &arg,
  129. .rpc_resp = fattr,
  130. };
  131. int status;
  132. /* Mask out the non-modebit related stuff from attr->ia_mode */
  133. sattr->ia_mode &= S_IALLUGO;
  134. dprintk("NFS call setattr\n");
  135. if (sattr->ia_valid & ATTR_FILE)
  136. msg.rpc_cred = nfs_file_cred(sattr->ia_file);
  137. nfs_fattr_init(fattr);
  138. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  139. if (status == 0)
  140. nfs_setattr_update_inode(inode, sattr, fattr);
  141. dprintk("NFS reply setattr: %d\n", status);
  142. return status;
  143. }
  144. static int
  145. nfs_proc_lookup(struct inode *dir, struct dentry *dentry,
  146. struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  147. {
  148. struct nfs_diropargs arg = {
  149. .fh = NFS_FH(dir),
  150. .name = dentry->d_name.name,
  151. .len = dentry->d_name.len
  152. };
  153. struct nfs_diropok res = {
  154. .fh = fhandle,
  155. .fattr = fattr
  156. };
  157. struct rpc_message msg = {
  158. .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP],
  159. .rpc_argp = &arg,
  160. .rpc_resp = &res,
  161. };
  162. int status;
  163. unsigned short task_flags = 0;
  164. /* Is this is an attribute revalidation, subject to softreval? */
  165. if (nfs_lookup_is_soft_revalidate(dentry))
  166. task_flags |= RPC_TASK_TIMEOUT;
  167. dprintk("NFS call lookup %pd2\n", dentry);
  168. nfs_fattr_init(fattr);
  169. status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
  170. dprintk("NFS reply lookup: %d\n", status);
  171. return status;
  172. }
  173. static int nfs_proc_readlink(struct inode *inode, struct page *page,
  174. unsigned int pgbase, unsigned int pglen)
  175. {
  176. struct nfs_readlinkargs args = {
  177. .fh = NFS_FH(inode),
  178. .pgbase = pgbase,
  179. .pglen = pglen,
  180. .pages = &page
  181. };
  182. struct rpc_message msg = {
  183. .rpc_proc = &nfs_procedures[NFSPROC_READLINK],
  184. .rpc_argp = &args,
  185. };
  186. int status;
  187. dprintk("NFS call readlink\n");
  188. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  189. dprintk("NFS reply readlink: %d\n", status);
  190. return status;
  191. }
  192. struct nfs_createdata {
  193. struct nfs_createargs arg;
  194. struct nfs_diropok res;
  195. struct nfs_fh fhandle;
  196. struct nfs_fattr fattr;
  197. };
  198. static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
  199. struct dentry *dentry, struct iattr *sattr)
  200. {
  201. struct nfs_createdata *data;
  202. data = kmalloc(sizeof(*data), GFP_KERNEL);
  203. if (data != NULL) {
  204. data->arg.fh = NFS_FH(dir);
  205. data->arg.name = dentry->d_name.name;
  206. data->arg.len = dentry->d_name.len;
  207. data->arg.sattr = sattr;
  208. nfs_fattr_init(&data->fattr);
  209. data->fhandle.size = 0;
  210. data->res.fh = &data->fhandle;
  211. data->res.fattr = &data->fattr;
  212. }
  213. return data;
  214. };
  215. static void nfs_free_createdata(const struct nfs_createdata *data)
  216. {
  217. kfree(data);
  218. }
  219. static int
  220. nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  221. int flags)
  222. {
  223. struct nfs_createdata *data;
  224. struct rpc_message msg = {
  225. .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
  226. };
  227. int status = -ENOMEM;
  228. dprintk("NFS call create %pd\n", dentry);
  229. data = nfs_alloc_createdata(dir, dentry, sattr);
  230. if (data == NULL)
  231. goto out;
  232. msg.rpc_argp = &data->arg;
  233. msg.rpc_resp = &data->res;
  234. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  235. nfs_mark_for_revalidate(dir);
  236. if (status == 0)
  237. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  238. nfs_free_createdata(data);
  239. out:
  240. dprintk("NFS reply create: %d\n", status);
  241. return status;
  242. }
  243. /*
  244. * In NFSv2, mknod is grafted onto the create call.
  245. */
  246. static int
  247. nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  248. dev_t rdev)
  249. {
  250. struct nfs_createdata *data;
  251. struct rpc_message msg = {
  252. .rpc_proc = &nfs_procedures[NFSPROC_CREATE],
  253. };
  254. umode_t mode;
  255. int status = -ENOMEM;
  256. dprintk("NFS call mknod %pd\n", dentry);
  257. mode = sattr->ia_mode;
  258. if (S_ISFIFO(mode)) {
  259. sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
  260. sattr->ia_valid &= ~ATTR_SIZE;
  261. } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
  262. sattr->ia_valid |= ATTR_SIZE;
  263. sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
  264. }
  265. data = nfs_alloc_createdata(dir, dentry, sattr);
  266. if (data == NULL)
  267. goto out;
  268. msg.rpc_argp = &data->arg;
  269. msg.rpc_resp = &data->res;
  270. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  271. nfs_mark_for_revalidate(dir);
  272. if (status == -EINVAL && S_ISFIFO(mode)) {
  273. sattr->ia_mode = mode;
  274. nfs_fattr_init(data->res.fattr);
  275. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  276. }
  277. if (status == 0)
  278. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  279. nfs_free_createdata(data);
  280. out:
  281. dprintk("NFS reply mknod: %d\n", status);
  282. return status;
  283. }
  284. static int
  285. nfs_proc_remove(struct inode *dir, struct dentry *dentry)
  286. {
  287. struct nfs_removeargs arg = {
  288. .fh = NFS_FH(dir),
  289. .name = dentry->d_name,
  290. };
  291. struct rpc_message msg = {
  292. .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
  293. .rpc_argp = &arg,
  294. };
  295. int status;
  296. dprintk("NFS call remove %pd2\n",dentry);
  297. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  298. nfs_mark_for_revalidate(dir);
  299. dprintk("NFS reply remove: %d\n", status);
  300. return status;
  301. }
  302. static void
  303. nfs_proc_unlink_setup(struct rpc_message *msg,
  304. struct dentry *dentry,
  305. struct inode *inode)
  306. {
  307. msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
  308. }
  309. static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
  310. {
  311. rpc_call_start(task);
  312. }
  313. static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  314. {
  315. nfs_mark_for_revalidate(dir);
  316. return 1;
  317. }
  318. static void
  319. nfs_proc_rename_setup(struct rpc_message *msg,
  320. struct dentry *old_dentry,
  321. struct dentry *new_dentry)
  322. {
  323. msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
  324. }
  325. static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
  326. {
  327. rpc_call_start(task);
  328. }
  329. static int
  330. nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
  331. struct inode *new_dir)
  332. {
  333. nfs_mark_for_revalidate(old_dir);
  334. nfs_mark_for_revalidate(new_dir);
  335. return 1;
  336. }
  337. static int
  338. nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
  339. {
  340. struct nfs_linkargs arg = {
  341. .fromfh = NFS_FH(inode),
  342. .tofh = NFS_FH(dir),
  343. .toname = name->name,
  344. .tolen = name->len
  345. };
  346. struct rpc_message msg = {
  347. .rpc_proc = &nfs_procedures[NFSPROC_LINK],
  348. .rpc_argp = &arg,
  349. };
  350. int status;
  351. dprintk("NFS call link %s\n", name->name);
  352. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  353. nfs_mark_for_revalidate(inode);
  354. nfs_mark_for_revalidate(dir);
  355. dprintk("NFS reply link: %d\n", status);
  356. return status;
  357. }
  358. static int
  359. nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
  360. unsigned int len, struct iattr *sattr)
  361. {
  362. struct nfs_fh *fh;
  363. struct nfs_fattr *fattr;
  364. struct nfs_symlinkargs arg = {
  365. .fromfh = NFS_FH(dir),
  366. .fromname = dentry->d_name.name,
  367. .fromlen = dentry->d_name.len,
  368. .pages = &page,
  369. .pathlen = len,
  370. .sattr = sattr
  371. };
  372. struct rpc_message msg = {
  373. .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK],
  374. .rpc_argp = &arg,
  375. };
  376. int status = -ENAMETOOLONG;
  377. dprintk("NFS call symlink %pd\n", dentry);
  378. if (len > NFS2_MAXPATHLEN)
  379. goto out;
  380. fh = nfs_alloc_fhandle();
  381. fattr = nfs_alloc_fattr();
  382. status = -ENOMEM;
  383. if (fh == NULL || fattr == NULL)
  384. goto out_free;
  385. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  386. nfs_mark_for_revalidate(dir);
  387. /*
  388. * V2 SYMLINK requests don't return any attributes. Setting the
  389. * filehandle size to zero indicates to nfs_instantiate that it
  390. * should fill in the data with a LOOKUP call on the wire.
  391. */
  392. if (status == 0)
  393. status = nfs_instantiate(dentry, fh, fattr);
  394. out_free:
  395. nfs_free_fattr(fattr);
  396. nfs_free_fhandle(fh);
  397. out:
  398. dprintk("NFS reply symlink: %d\n", status);
  399. return status;
  400. }
  401. static int
  402. nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
  403. {
  404. struct nfs_createdata *data;
  405. struct rpc_message msg = {
  406. .rpc_proc = &nfs_procedures[NFSPROC_MKDIR],
  407. };
  408. int status = -ENOMEM;
  409. dprintk("NFS call mkdir %pd\n", dentry);
  410. data = nfs_alloc_createdata(dir, dentry, sattr);
  411. if (data == NULL)
  412. goto out;
  413. msg.rpc_argp = &data->arg;
  414. msg.rpc_resp = &data->res;
  415. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  416. nfs_mark_for_revalidate(dir);
  417. if (status == 0)
  418. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  419. nfs_free_createdata(data);
  420. out:
  421. dprintk("NFS reply mkdir: %d\n", status);
  422. return status;
  423. }
  424. static int
  425. nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
  426. {
  427. struct nfs_diropargs arg = {
  428. .fh = NFS_FH(dir),
  429. .name = name->name,
  430. .len = name->len
  431. };
  432. struct rpc_message msg = {
  433. .rpc_proc = &nfs_procedures[NFSPROC_RMDIR],
  434. .rpc_argp = &arg,
  435. };
  436. int status;
  437. dprintk("NFS call rmdir %s\n", name->name);
  438. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  439. nfs_mark_for_revalidate(dir);
  440. dprintk("NFS reply rmdir: %d\n", status);
  441. return status;
  442. }
  443. /*
  444. * The READDIR implementation is somewhat hackish - we pass a temporary
  445. * buffer to the encode function, which installs it in the receive
  446. * the receive iovec. The decode function just parses the reply to make
  447. * sure it is syntactically correct; the entries itself are decoded
  448. * from nfs_readdir by calling the decode_entry function directly.
  449. */
  450. static int nfs_proc_readdir(struct nfs_readdir_arg *nr_arg,
  451. struct nfs_readdir_res *nr_res)
  452. {
  453. struct inode *dir = d_inode(nr_arg->dentry);
  454. struct nfs_readdirargs arg = {
  455. .fh = NFS_FH(dir),
  456. .cookie = nr_arg->cookie,
  457. .count = nr_arg->page_len,
  458. .pages = nr_arg->pages,
  459. };
  460. struct rpc_message msg = {
  461. .rpc_proc = &nfs_procedures[NFSPROC_READDIR],
  462. .rpc_argp = &arg,
  463. .rpc_cred = nr_arg->cred,
  464. };
  465. int status;
  466. dprintk("NFS call readdir %llu\n", (unsigned long long)nr_arg->cookie);
  467. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  468. nr_res->verf[0] = nr_res->verf[1] = 0;
  469. nfs_invalidate_atime(dir);
  470. dprintk("NFS reply readdir: %d\n", status);
  471. return status;
  472. }
  473. static int
  474. nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  475. struct nfs_fsstat *stat)
  476. {
  477. struct nfs2_fsstat fsinfo;
  478. struct rpc_message msg = {
  479. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  480. .rpc_argp = fhandle,
  481. .rpc_resp = &fsinfo,
  482. };
  483. int status;
  484. dprintk("NFS call statfs\n");
  485. nfs_fattr_init(stat->fattr);
  486. status = rpc_call_sync(server->client, &msg, 0);
  487. dprintk("NFS reply statfs: %d\n", status);
  488. if (status)
  489. goto out;
  490. stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
  491. stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize;
  492. stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
  493. stat->tfiles = 0;
  494. stat->ffiles = 0;
  495. stat->afiles = 0;
  496. out:
  497. return status;
  498. }
  499. static int
  500. nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  501. struct nfs_fsinfo *info)
  502. {
  503. struct nfs2_fsstat fsinfo;
  504. struct rpc_message msg = {
  505. .rpc_proc = &nfs_procedures[NFSPROC_STATFS],
  506. .rpc_argp = fhandle,
  507. .rpc_resp = &fsinfo,
  508. };
  509. int status;
  510. dprintk("NFS call fsinfo\n");
  511. nfs_fattr_init(info->fattr);
  512. status = rpc_call_sync(server->client, &msg, 0);
  513. dprintk("NFS reply fsinfo: %d\n", status);
  514. if (status)
  515. goto out;
  516. info->rtmax = NFS_MAXDATA;
  517. info->rtpref = fsinfo.tsize;
  518. info->rtmult = fsinfo.bsize;
  519. info->wtmax = NFS_MAXDATA;
  520. info->wtpref = fsinfo.tsize;
  521. info->wtmult = fsinfo.bsize;
  522. info->dtpref = fsinfo.tsize;
  523. info->maxfilesize = 0x7FFFFFFF;
  524. info->lease_time = 0;
  525. out:
  526. return status;
  527. }
  528. static int
  529. nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  530. struct nfs_pathconf *info)
  531. {
  532. info->max_link = 0;
  533. info->max_namelen = NFS2_MAXNAMLEN;
  534. return 0;
  535. }
  536. static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  537. {
  538. struct inode *inode = hdr->inode;
  539. nfs_invalidate_atime(inode);
  540. if (task->tk_status >= 0) {
  541. nfs_refresh_inode(inode, hdr->res.fattr);
  542. /* Emulate the eof flag, which isn't normally needed in NFSv2
  543. * as it is guaranteed to always return the file attributes
  544. */
  545. if ((hdr->res.count == 0 && hdr->args.count > 0) ||
  546. hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
  547. hdr->res.eof = 1;
  548. }
  549. return 0;
  550. }
  551. static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
  552. struct rpc_message *msg)
  553. {
  554. msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
  555. }
  556. static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
  557. struct nfs_pgio_header *hdr)
  558. {
  559. rpc_call_start(task);
  560. return 0;
  561. }
  562. static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
  563. {
  564. if (task->tk_status >= 0) {
  565. hdr->res.count = hdr->args.count;
  566. nfs_writeback_update_inode(hdr);
  567. }
  568. return 0;
  569. }
  570. static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
  571. struct rpc_message *msg,
  572. struct rpc_clnt **clnt)
  573. {
  574. /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
  575. hdr->args.stable = NFS_FILE_SYNC;
  576. msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
  577. }
  578. static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
  579. {
  580. BUG();
  581. }
  582. static void
  583. nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
  584. struct rpc_clnt **clnt)
  585. {
  586. BUG();
  587. }
  588. static int
  589. nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
  590. {
  591. struct inode *inode = file_inode(filp);
  592. return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, NULL);
  593. }
  594. /* Helper functions for NFS lock bounds checking */
  595. #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
  596. static int nfs_lock_check_bounds(const struct file_lock *fl)
  597. {
  598. __s32 start, end;
  599. start = (__s32)fl->fl_start;
  600. if ((loff_t)start != fl->fl_start)
  601. goto out_einval;
  602. if (fl->fl_end != OFFSET_MAX) {
  603. end = (__s32)fl->fl_end;
  604. if ((loff_t)end != fl->fl_end)
  605. goto out_einval;
  606. } else
  607. end = NFS_LOCK32_OFFSET_MAX;
  608. if (start < 0 || start > end)
  609. goto out_einval;
  610. return 0;
  611. out_einval:
  612. return -EINVAL;
  613. }
  614. static int nfs_have_delegation(struct inode *inode, fmode_t flags)
  615. {
  616. return 0;
  617. }
  618. static const struct inode_operations nfs_dir_inode_operations = {
  619. .create = nfs_create,
  620. .lookup = nfs_lookup,
  621. .link = nfs_link,
  622. .unlink = nfs_unlink,
  623. .symlink = nfs_symlink,
  624. .mkdir = nfs_mkdir,
  625. .rmdir = nfs_rmdir,
  626. .mknod = nfs_mknod,
  627. .rename = nfs_rename,
  628. .permission = nfs_permission,
  629. .getattr = nfs_getattr,
  630. .setattr = nfs_setattr,
  631. };
  632. static const struct inode_operations nfs_file_inode_operations = {
  633. .permission = nfs_permission,
  634. .getattr = nfs_getattr,
  635. .setattr = nfs_setattr,
  636. };
  637. const struct nfs_rpc_ops nfs_v2_clientops = {
  638. .version = 2, /* protocol version */
  639. .dentry_ops = &nfs_dentry_operations,
  640. .dir_inode_ops = &nfs_dir_inode_operations,
  641. .file_inode_ops = &nfs_file_inode_operations,
  642. .file_ops = &nfs_file_operations,
  643. .getroot = nfs_proc_get_root,
  644. .submount = nfs_submount,
  645. .try_get_tree = nfs_try_get_tree,
  646. .getattr = nfs_proc_getattr,
  647. .setattr = nfs_proc_setattr,
  648. .lookup = nfs_proc_lookup,
  649. .access = NULL, /* access */
  650. .readlink = nfs_proc_readlink,
  651. .create = nfs_proc_create,
  652. .remove = nfs_proc_remove,
  653. .unlink_setup = nfs_proc_unlink_setup,
  654. .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
  655. .unlink_done = nfs_proc_unlink_done,
  656. .rename_setup = nfs_proc_rename_setup,
  657. .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
  658. .rename_done = nfs_proc_rename_done,
  659. .link = nfs_proc_link,
  660. .symlink = nfs_proc_symlink,
  661. .mkdir = nfs_proc_mkdir,
  662. .rmdir = nfs_proc_rmdir,
  663. .readdir = nfs_proc_readdir,
  664. .mknod = nfs_proc_mknod,
  665. .statfs = nfs_proc_statfs,
  666. .fsinfo = nfs_proc_fsinfo,
  667. .pathconf = nfs_proc_pathconf,
  668. .decode_dirent = nfs2_decode_dirent,
  669. .pgio_rpc_prepare = nfs_proc_pgio_rpc_prepare,
  670. .read_setup = nfs_proc_read_setup,
  671. .read_done = nfs_read_done,
  672. .write_setup = nfs_proc_write_setup,
  673. .write_done = nfs_write_done,
  674. .commit_setup = nfs_proc_commit_setup,
  675. .commit_rpc_prepare = nfs_proc_commit_rpc_prepare,
  676. .lock = nfs_proc_lock,
  677. .lock_check_bounds = nfs_lock_check_bounds,
  678. .close_context = nfs_close_context,
  679. .have_delegation = nfs_have_delegation,
  680. .alloc_client = nfs_alloc_client,
  681. .init_client = nfs_init_client,
  682. .free_client = nfs_free_client,
  683. .create_server = nfs_create_server,
  684. .clone_server = nfs_clone_server,
  685. };