proc.c 21 KB

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