nfsproc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Process version 2 NFS requests.
  4. *
  5. * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
  6. */
  7. #include <linux/namei.h>
  8. #include "cache.h"
  9. #include "xdr.h"
  10. #include "vfs.h"
  11. #define NFSDDBG_FACILITY NFSDDBG_PROC
  12. static __be32
  13. nfsd_proc_null(struct svc_rqst *rqstp)
  14. {
  15. return rpc_success;
  16. }
  17. /*
  18. * Get a file's attributes
  19. * N.B. After this call resp->fh needs an fh_put
  20. */
  21. static __be32
  22. nfsd_proc_getattr(struct svc_rqst *rqstp)
  23. {
  24. struct nfsd_fhandle *argp = rqstp->rq_argp;
  25. struct nfsd_attrstat *resp = rqstp->rq_resp;
  26. dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
  27. fh_copy(&resp->fh, &argp->fh);
  28. resp->status = fh_verify(rqstp, &resp->fh, 0,
  29. NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
  30. if (resp->status != nfs_ok)
  31. goto out;
  32. resp->status = fh_getattr(&resp->fh, &resp->stat);
  33. out:
  34. return rpc_success;
  35. }
  36. /*
  37. * Set a file's attributes
  38. * N.B. After this call resp->fh needs an fh_put
  39. */
  40. static __be32
  41. nfsd_proc_setattr(struct svc_rqst *rqstp)
  42. {
  43. struct nfsd_sattrargs *argp = rqstp->rq_argp;
  44. struct nfsd_attrstat *resp = rqstp->rq_resp;
  45. struct iattr *iap = &argp->attrs;
  46. struct svc_fh *fhp;
  47. dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
  48. SVCFH_fmt(&argp->fh),
  49. argp->attrs.ia_valid, (long) argp->attrs.ia_size);
  50. fhp = fh_copy(&resp->fh, &argp->fh);
  51. /*
  52. * NFSv2 does not differentiate between "set-[ac]time-to-now"
  53. * which only requires access, and "set-[ac]time-to-X" which
  54. * requires ownership.
  55. * So if it looks like it might be "set both to the same time which
  56. * is close to now", and if setattr_prepare fails, then we
  57. * convert to "set to now" instead of "set to explicit time"
  58. *
  59. * We only call setattr_prepare as the last test as technically
  60. * it is not an interface that we should be using.
  61. */
  62. #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
  63. #define MAX_TOUCH_TIME_ERROR (30*60)
  64. if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
  65. iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
  66. /*
  67. * Looks probable.
  68. *
  69. * Now just make sure time is in the right ballpark.
  70. * Solaris, at least, doesn't seem to care what the time
  71. * request is. We require it be within 30 minutes of now.
  72. */
  73. time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds();
  74. resp->status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
  75. if (resp->status != nfs_ok)
  76. goto out;
  77. if (delta < 0)
  78. delta = -delta;
  79. if (delta < MAX_TOUCH_TIME_ERROR &&
  80. setattr_prepare(fhp->fh_dentry, iap) != 0) {
  81. /*
  82. * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
  83. * This will cause notify_change to set these times
  84. * to "now"
  85. */
  86. iap->ia_valid &= ~BOTH_TIME_SET;
  87. }
  88. }
  89. resp->status = nfsd_setattr(rqstp, fhp, iap, 0, (time64_t)0);
  90. if (resp->status != nfs_ok)
  91. goto out;
  92. resp->status = fh_getattr(&resp->fh, &resp->stat);
  93. out:
  94. return rpc_success;
  95. }
  96. /* Obsolete, replaced by MNTPROC_MNT. */
  97. static __be32
  98. nfsd_proc_root(struct svc_rqst *rqstp)
  99. {
  100. return rpc_success;
  101. }
  102. /*
  103. * Look up a path name component
  104. * Note: the dentry in the resp->fh may be negative if the file
  105. * doesn't exist yet.
  106. * N.B. After this call resp->fh needs an fh_put
  107. */
  108. static __be32
  109. nfsd_proc_lookup(struct svc_rqst *rqstp)
  110. {
  111. struct nfsd_diropargs *argp = rqstp->rq_argp;
  112. struct nfsd_diropres *resp = rqstp->rq_resp;
  113. dprintk("nfsd: LOOKUP %s %.*s\n",
  114. SVCFH_fmt(&argp->fh), argp->len, argp->name);
  115. fh_init(&resp->fh, NFS_FHSIZE);
  116. resp->status = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
  117. &resp->fh);
  118. fh_put(&argp->fh);
  119. if (resp->status != nfs_ok)
  120. goto out;
  121. resp->status = fh_getattr(&resp->fh, &resp->stat);
  122. out:
  123. return rpc_success;
  124. }
  125. /*
  126. * Read a symlink.
  127. */
  128. static __be32
  129. nfsd_proc_readlink(struct svc_rqst *rqstp)
  130. {
  131. struct nfsd_readlinkargs *argp = rqstp->rq_argp;
  132. struct nfsd_readlinkres *resp = rqstp->rq_resp;
  133. dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
  134. /* Read the symlink. */
  135. resp->len = NFS_MAXPATHLEN;
  136. resp->status = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
  137. fh_put(&argp->fh);
  138. return rpc_success;
  139. }
  140. /*
  141. * Read a portion of a file.
  142. * N.B. After this call resp->fh needs an fh_put
  143. */
  144. static __be32
  145. nfsd_proc_read(struct svc_rqst *rqstp)
  146. {
  147. struct nfsd_readargs *argp = rqstp->rq_argp;
  148. struct nfsd_readres *resp = rqstp->rq_resp;
  149. u32 eof;
  150. dprintk("nfsd: READ %s %d bytes at %d\n",
  151. SVCFH_fmt(&argp->fh),
  152. argp->count, argp->offset);
  153. /* Obtain buffer pointer for payload. 19 is 1 word for
  154. * status, 17 words for fattr, and 1 word for the byte count.
  155. */
  156. if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
  157. char buf[RPC_MAX_ADDRBUFLEN];
  158. printk(KERN_NOTICE
  159. "oversized read request from %s (%d bytes)\n",
  160. svc_print_addr(rqstp, buf, sizeof(buf)),
  161. argp->count);
  162. argp->count = NFSSVC_MAXBLKSIZE_V2;
  163. }
  164. svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
  165. resp->count = argp->count;
  166. resp->status = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
  167. argp->offset,
  168. rqstp->rq_vec, argp->vlen,
  169. &resp->count,
  170. &eof);
  171. if (resp->status == nfs_ok)
  172. resp->status = fh_getattr(&resp->fh, &resp->stat);
  173. else if (resp->status == nfserr_jukebox)
  174. return rpc_drop_reply;
  175. return rpc_success;
  176. }
  177. /* Reserved */
  178. static __be32
  179. nfsd_proc_writecache(struct svc_rqst *rqstp)
  180. {
  181. return rpc_success;
  182. }
  183. /*
  184. * Write data to a file
  185. * N.B. After this call resp->fh needs an fh_put
  186. */
  187. static __be32
  188. nfsd_proc_write(struct svc_rqst *rqstp)
  189. {
  190. struct nfsd_writeargs *argp = rqstp->rq_argp;
  191. struct nfsd_attrstat *resp = rqstp->rq_resp;
  192. unsigned long cnt = argp->len;
  193. unsigned int nvecs;
  194. dprintk("nfsd: WRITE %s %u bytes at %d\n",
  195. SVCFH_fmt(&argp->fh),
  196. argp->len, argp->offset);
  197. nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
  198. &argp->first, cnt);
  199. if (!nvecs) {
  200. resp->status = nfserr_io;
  201. goto out;
  202. }
  203. resp->status = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
  204. argp->offset, rqstp->rq_vec, nvecs,
  205. &cnt, NFS_DATA_SYNC, NULL);
  206. if (resp->status == nfs_ok)
  207. resp->status = fh_getattr(&resp->fh, &resp->stat);
  208. else if (resp->status == nfserr_jukebox)
  209. return rpc_drop_reply;
  210. out:
  211. return rpc_success;
  212. }
  213. /*
  214. * CREATE processing is complicated. The keyword here is `overloaded.'
  215. * The parent directory is kept locked between the check for existence
  216. * and the actual create() call in compliance with VFS protocols.
  217. * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
  218. */
  219. static __be32
  220. nfsd_proc_create(struct svc_rqst *rqstp)
  221. {
  222. struct nfsd_createargs *argp = rqstp->rq_argp;
  223. struct nfsd_diropres *resp = rqstp->rq_resp;
  224. svc_fh *dirfhp = &argp->fh;
  225. svc_fh *newfhp = &resp->fh;
  226. struct iattr *attr = &argp->attrs;
  227. struct inode *inode;
  228. struct dentry *dchild;
  229. int type, mode;
  230. int hosterr;
  231. dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
  232. dprintk("nfsd: CREATE %s %.*s\n",
  233. SVCFH_fmt(dirfhp), argp->len, argp->name);
  234. /* First verify the parent file handle */
  235. resp->status = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
  236. if (resp->status != nfs_ok)
  237. goto done; /* must fh_put dirfhp even on error */
  238. /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
  239. resp->status = nfserr_exist;
  240. if (isdotent(argp->name, argp->len))
  241. goto done;
  242. hosterr = fh_want_write(dirfhp);
  243. if (hosterr) {
  244. resp->status = nfserrno(hosterr);
  245. goto done;
  246. }
  247. fh_lock_nested(dirfhp, I_MUTEX_PARENT);
  248. dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
  249. if (IS_ERR(dchild)) {
  250. resp->status = nfserrno(PTR_ERR(dchild));
  251. goto out_unlock;
  252. }
  253. fh_init(newfhp, NFS_FHSIZE);
  254. resp->status = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
  255. if (!resp->status && d_really_is_negative(dchild))
  256. resp->status = nfserr_noent;
  257. dput(dchild);
  258. if (resp->status) {
  259. if (resp->status != nfserr_noent)
  260. goto out_unlock;
  261. /*
  262. * If the new file handle wasn't verified, we can't tell
  263. * whether the file exists or not. Time to bail ...
  264. */
  265. resp->status = nfserr_acces;
  266. if (!newfhp->fh_dentry) {
  267. printk(KERN_WARNING
  268. "nfsd_proc_create: file handle not verified\n");
  269. goto out_unlock;
  270. }
  271. }
  272. inode = d_inode(newfhp->fh_dentry);
  273. /* Unfudge the mode bits */
  274. if (attr->ia_valid & ATTR_MODE) {
  275. type = attr->ia_mode & S_IFMT;
  276. mode = attr->ia_mode & ~S_IFMT;
  277. if (!type) {
  278. /* no type, so if target exists, assume same as that,
  279. * else assume a file */
  280. if (inode) {
  281. type = inode->i_mode & S_IFMT;
  282. switch(type) {
  283. case S_IFCHR:
  284. case S_IFBLK:
  285. /* reserve rdev for later checking */
  286. rdev = inode->i_rdev;
  287. attr->ia_valid |= ATTR_SIZE;
  288. fallthrough;
  289. case S_IFIFO:
  290. /* this is probably a permission check..
  291. * at least IRIX implements perm checking on
  292. * echo thing > device-special-file-or-pipe
  293. * by doing a CREATE with type==0
  294. */
  295. resp->status = nfsd_permission(rqstp,
  296. newfhp->fh_export,
  297. newfhp->fh_dentry,
  298. NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
  299. if (resp->status && resp->status != nfserr_rofs)
  300. goto out_unlock;
  301. }
  302. } else
  303. type = S_IFREG;
  304. }
  305. } else if (inode) {
  306. type = inode->i_mode & S_IFMT;
  307. mode = inode->i_mode & ~S_IFMT;
  308. } else {
  309. type = S_IFREG;
  310. mode = 0; /* ??? */
  311. }
  312. attr->ia_valid |= ATTR_MODE;
  313. attr->ia_mode = mode;
  314. /* Special treatment for non-regular files according to the
  315. * gospel of sun micro
  316. */
  317. if (type != S_IFREG) {
  318. if (type != S_IFBLK && type != S_IFCHR) {
  319. rdev = 0;
  320. } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
  321. /* If you think you've seen the worst, grok this. */
  322. type = S_IFIFO;
  323. } else {
  324. /* Okay, char or block special */
  325. if (!rdev)
  326. rdev = wanted;
  327. }
  328. /* we've used the SIZE information, so discard it */
  329. attr->ia_valid &= ~ATTR_SIZE;
  330. /* Make sure the type and device matches */
  331. resp->status = nfserr_exist;
  332. if (inode && inode_wrong_type(inode, type))
  333. goto out_unlock;
  334. }
  335. resp->status = nfs_ok;
  336. if (!inode) {
  337. /* File doesn't exist. Create it and set attrs */
  338. resp->status = nfsd_create_locked(rqstp, dirfhp, argp->name,
  339. argp->len, attr, type, rdev,
  340. newfhp);
  341. } else if (type == S_IFREG) {
  342. dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
  343. argp->name, attr->ia_valid, (long) attr->ia_size);
  344. /* File already exists. We ignore all attributes except
  345. * size, so that creat() behaves exactly like
  346. * open(..., O_CREAT|O_TRUNC|O_WRONLY).
  347. */
  348. attr->ia_valid &= ATTR_SIZE;
  349. if (attr->ia_valid)
  350. resp->status = nfsd_setattr(rqstp, newfhp, attr, 0,
  351. (time64_t)0);
  352. }
  353. out_unlock:
  354. /* We don't really need to unlock, as fh_put does it. */
  355. fh_unlock(dirfhp);
  356. fh_drop_write(dirfhp);
  357. done:
  358. fh_put(dirfhp);
  359. if (resp->status != nfs_ok)
  360. goto out;
  361. resp->status = fh_getattr(&resp->fh, &resp->stat);
  362. out:
  363. return rpc_success;
  364. }
  365. static __be32
  366. nfsd_proc_remove(struct svc_rqst *rqstp)
  367. {
  368. struct nfsd_diropargs *argp = rqstp->rq_argp;
  369. struct nfsd_stat *resp = rqstp->rq_resp;
  370. dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
  371. argp->len, argp->name);
  372. /* Unlink. -SIFDIR means file must not be a directory */
  373. resp->status = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR,
  374. argp->name, argp->len);
  375. fh_put(&argp->fh);
  376. return rpc_success;
  377. }
  378. static __be32
  379. nfsd_proc_rename(struct svc_rqst *rqstp)
  380. {
  381. struct nfsd_renameargs *argp = rqstp->rq_argp;
  382. struct nfsd_stat *resp = rqstp->rq_resp;
  383. dprintk("nfsd: RENAME %s %.*s -> \n",
  384. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
  385. dprintk("nfsd: -> %s %.*s\n",
  386. SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
  387. resp->status = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
  388. &argp->tfh, argp->tname, argp->tlen);
  389. fh_put(&argp->ffh);
  390. fh_put(&argp->tfh);
  391. return rpc_success;
  392. }
  393. static __be32
  394. nfsd_proc_link(struct svc_rqst *rqstp)
  395. {
  396. struct nfsd_linkargs *argp = rqstp->rq_argp;
  397. struct nfsd_stat *resp = rqstp->rq_resp;
  398. dprintk("nfsd: LINK %s ->\n",
  399. SVCFH_fmt(&argp->ffh));
  400. dprintk("nfsd: %s %.*s\n",
  401. SVCFH_fmt(&argp->tfh),
  402. argp->tlen,
  403. argp->tname);
  404. resp->status = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
  405. &argp->ffh);
  406. fh_put(&argp->ffh);
  407. fh_put(&argp->tfh);
  408. return rpc_success;
  409. }
  410. static __be32
  411. nfsd_proc_symlink(struct svc_rqst *rqstp)
  412. {
  413. struct nfsd_symlinkargs *argp = rqstp->rq_argp;
  414. struct nfsd_stat *resp = rqstp->rq_resp;
  415. struct svc_fh newfh;
  416. if (argp->tlen > NFS_MAXPATHLEN) {
  417. resp->status = nfserr_nametoolong;
  418. goto out;
  419. }
  420. argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
  421. page_address(rqstp->rq_arg.pages[0]),
  422. argp->tlen);
  423. if (IS_ERR(argp->tname)) {
  424. resp->status = nfserrno(PTR_ERR(argp->tname));
  425. goto out;
  426. }
  427. dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
  428. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
  429. argp->tlen, argp->tname);
  430. fh_init(&newfh, NFS_FHSIZE);
  431. resp->status = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  432. argp->tname, &newfh);
  433. kfree(argp->tname);
  434. fh_put(&argp->ffh);
  435. fh_put(&newfh);
  436. out:
  437. return rpc_success;
  438. }
  439. /*
  440. * Make directory. This operation is not idempotent.
  441. * N.B. After this call resp->fh needs an fh_put
  442. */
  443. static __be32
  444. nfsd_proc_mkdir(struct svc_rqst *rqstp)
  445. {
  446. struct nfsd_createargs *argp = rqstp->rq_argp;
  447. struct nfsd_diropres *resp = rqstp->rq_resp;
  448. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  449. if (resp->fh.fh_dentry) {
  450. printk(KERN_WARNING
  451. "nfsd_proc_mkdir: response already verified??\n");
  452. }
  453. argp->attrs.ia_valid &= ~ATTR_SIZE;
  454. fh_init(&resp->fh, NFS_FHSIZE);
  455. resp->status = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  456. &argp->attrs, S_IFDIR, 0, &resp->fh);
  457. fh_put(&argp->fh);
  458. if (resp->status != nfs_ok)
  459. goto out;
  460. resp->status = fh_getattr(&resp->fh, &resp->stat);
  461. out:
  462. return rpc_success;
  463. }
  464. /*
  465. * Remove a directory
  466. */
  467. static __be32
  468. nfsd_proc_rmdir(struct svc_rqst *rqstp)
  469. {
  470. struct nfsd_diropargs *argp = rqstp->rq_argp;
  471. struct nfsd_stat *resp = rqstp->rq_resp;
  472. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  473. resp->status = nfsd_unlink(rqstp, &argp->fh, S_IFDIR,
  474. argp->name, argp->len);
  475. fh_put(&argp->fh);
  476. return rpc_success;
  477. }
  478. /*
  479. * Read a portion of a directory.
  480. */
  481. static __be32
  482. nfsd_proc_readdir(struct svc_rqst *rqstp)
  483. {
  484. struct nfsd_readdirargs *argp = rqstp->rq_argp;
  485. struct nfsd_readdirres *resp = rqstp->rq_resp;
  486. int count;
  487. loff_t offset;
  488. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  489. SVCFH_fmt(&argp->fh),
  490. argp->count, argp->cookie);
  491. /* Shrink to the client read size */
  492. count = (argp->count >> 2) - 2;
  493. /* Make sure we've room for the NULL ptr & eof flag */
  494. count -= 2;
  495. if (count < 0)
  496. count = 0;
  497. resp->buffer = argp->buffer;
  498. resp->offset = NULL;
  499. resp->buflen = count;
  500. resp->common.err = nfs_ok;
  501. /* Read directory and encode entries on the fly */
  502. offset = argp->cookie;
  503. resp->status = nfsd_readdir(rqstp, &argp->fh, &offset,
  504. &resp->common, nfssvc_encode_entry);
  505. resp->count = resp->buffer - argp->buffer;
  506. if (resp->offset)
  507. *resp->offset = htonl(offset);
  508. fh_put(&argp->fh);
  509. return rpc_success;
  510. }
  511. /*
  512. * Get file system info
  513. */
  514. static __be32
  515. nfsd_proc_statfs(struct svc_rqst *rqstp)
  516. {
  517. struct nfsd_fhandle *argp = rqstp->rq_argp;
  518. struct nfsd_statfsres *resp = rqstp->rq_resp;
  519. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  520. resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
  521. NFSD_MAY_BYPASS_GSS_ON_ROOT);
  522. fh_put(&argp->fh);
  523. return rpc_success;
  524. }
  525. /*
  526. * NFSv2 Server procedures.
  527. * Only the results of non-idempotent operations are cached.
  528. */
  529. struct nfsd_void { int dummy; };
  530. #define ST 1 /* status */
  531. #define FH 8 /* filehandle */
  532. #define AT 18 /* attributes */
  533. static const struct svc_procedure nfsd_procedures2[18] = {
  534. [NFSPROC_NULL] = {
  535. .pc_func = nfsd_proc_null,
  536. .pc_decode = nfssvc_decode_void,
  537. .pc_encode = nfssvc_encode_void,
  538. .pc_argsize = sizeof(struct nfsd_void),
  539. .pc_ressize = sizeof(struct nfsd_void),
  540. .pc_cachetype = RC_NOCACHE,
  541. .pc_xdrressize = 0,
  542. },
  543. [NFSPROC_GETATTR] = {
  544. .pc_func = nfsd_proc_getattr,
  545. .pc_decode = nfssvc_decode_fhandle,
  546. .pc_encode = nfssvc_encode_attrstat,
  547. .pc_release = nfssvc_release_attrstat,
  548. .pc_argsize = sizeof(struct nfsd_fhandle),
  549. .pc_ressize = sizeof(struct nfsd_attrstat),
  550. .pc_cachetype = RC_NOCACHE,
  551. .pc_xdrressize = ST+AT,
  552. },
  553. [NFSPROC_SETATTR] = {
  554. .pc_func = nfsd_proc_setattr,
  555. .pc_decode = nfssvc_decode_sattrargs,
  556. .pc_encode = nfssvc_encode_attrstat,
  557. .pc_release = nfssvc_release_attrstat,
  558. .pc_argsize = sizeof(struct nfsd_sattrargs),
  559. .pc_ressize = sizeof(struct nfsd_attrstat),
  560. .pc_cachetype = RC_REPLBUFF,
  561. .pc_xdrressize = ST+AT,
  562. },
  563. [NFSPROC_ROOT] = {
  564. .pc_func = nfsd_proc_root,
  565. .pc_decode = nfssvc_decode_void,
  566. .pc_encode = nfssvc_encode_void,
  567. .pc_argsize = sizeof(struct nfsd_void),
  568. .pc_ressize = sizeof(struct nfsd_void),
  569. .pc_cachetype = RC_NOCACHE,
  570. .pc_xdrressize = 0,
  571. },
  572. [NFSPROC_LOOKUP] = {
  573. .pc_func = nfsd_proc_lookup,
  574. .pc_decode = nfssvc_decode_diropargs,
  575. .pc_encode = nfssvc_encode_diropres,
  576. .pc_release = nfssvc_release_diropres,
  577. .pc_argsize = sizeof(struct nfsd_diropargs),
  578. .pc_ressize = sizeof(struct nfsd_diropres),
  579. .pc_cachetype = RC_NOCACHE,
  580. .pc_xdrressize = ST+FH+AT,
  581. },
  582. [NFSPROC_READLINK] = {
  583. .pc_func = nfsd_proc_readlink,
  584. .pc_decode = nfssvc_decode_readlinkargs,
  585. .pc_encode = nfssvc_encode_readlinkres,
  586. .pc_argsize = sizeof(struct nfsd_readlinkargs),
  587. .pc_ressize = sizeof(struct nfsd_readlinkres),
  588. .pc_cachetype = RC_NOCACHE,
  589. .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
  590. },
  591. [NFSPROC_READ] = {
  592. .pc_func = nfsd_proc_read,
  593. .pc_decode = nfssvc_decode_readargs,
  594. .pc_encode = nfssvc_encode_readres,
  595. .pc_release = nfssvc_release_readres,
  596. .pc_argsize = sizeof(struct nfsd_readargs),
  597. .pc_ressize = sizeof(struct nfsd_readres),
  598. .pc_cachetype = RC_NOCACHE,
  599. .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
  600. },
  601. [NFSPROC_WRITECACHE] = {
  602. .pc_func = nfsd_proc_writecache,
  603. .pc_decode = nfssvc_decode_void,
  604. .pc_encode = nfssvc_encode_void,
  605. .pc_argsize = sizeof(struct nfsd_void),
  606. .pc_ressize = sizeof(struct nfsd_void),
  607. .pc_cachetype = RC_NOCACHE,
  608. .pc_xdrressize = 0,
  609. },
  610. [NFSPROC_WRITE] = {
  611. .pc_func = nfsd_proc_write,
  612. .pc_decode = nfssvc_decode_writeargs,
  613. .pc_encode = nfssvc_encode_attrstat,
  614. .pc_release = nfssvc_release_attrstat,
  615. .pc_argsize = sizeof(struct nfsd_writeargs),
  616. .pc_ressize = sizeof(struct nfsd_attrstat),
  617. .pc_cachetype = RC_REPLBUFF,
  618. .pc_xdrressize = ST+AT,
  619. },
  620. [NFSPROC_CREATE] = {
  621. .pc_func = nfsd_proc_create,
  622. .pc_decode = nfssvc_decode_createargs,
  623. .pc_encode = nfssvc_encode_diropres,
  624. .pc_release = nfssvc_release_diropres,
  625. .pc_argsize = sizeof(struct nfsd_createargs),
  626. .pc_ressize = sizeof(struct nfsd_diropres),
  627. .pc_cachetype = RC_REPLBUFF,
  628. .pc_xdrressize = ST+FH+AT,
  629. },
  630. [NFSPROC_REMOVE] = {
  631. .pc_func = nfsd_proc_remove,
  632. .pc_decode = nfssvc_decode_diropargs,
  633. .pc_encode = nfssvc_encode_stat,
  634. .pc_argsize = sizeof(struct nfsd_diropargs),
  635. .pc_ressize = sizeof(struct nfsd_stat),
  636. .pc_cachetype = RC_REPLSTAT,
  637. .pc_xdrressize = ST,
  638. },
  639. [NFSPROC_RENAME] = {
  640. .pc_func = nfsd_proc_rename,
  641. .pc_decode = nfssvc_decode_renameargs,
  642. .pc_encode = nfssvc_encode_stat,
  643. .pc_argsize = sizeof(struct nfsd_renameargs),
  644. .pc_ressize = sizeof(struct nfsd_stat),
  645. .pc_cachetype = RC_REPLSTAT,
  646. .pc_xdrressize = ST,
  647. },
  648. [NFSPROC_LINK] = {
  649. .pc_func = nfsd_proc_link,
  650. .pc_decode = nfssvc_decode_linkargs,
  651. .pc_encode = nfssvc_encode_stat,
  652. .pc_argsize = sizeof(struct nfsd_linkargs),
  653. .pc_ressize = sizeof(struct nfsd_stat),
  654. .pc_cachetype = RC_REPLSTAT,
  655. .pc_xdrressize = ST,
  656. },
  657. [NFSPROC_SYMLINK] = {
  658. .pc_func = nfsd_proc_symlink,
  659. .pc_decode = nfssvc_decode_symlinkargs,
  660. .pc_encode = nfssvc_encode_stat,
  661. .pc_argsize = sizeof(struct nfsd_symlinkargs),
  662. .pc_ressize = sizeof(struct nfsd_stat),
  663. .pc_cachetype = RC_REPLSTAT,
  664. .pc_xdrressize = ST,
  665. },
  666. [NFSPROC_MKDIR] = {
  667. .pc_func = nfsd_proc_mkdir,
  668. .pc_decode = nfssvc_decode_createargs,
  669. .pc_encode = nfssvc_encode_diropres,
  670. .pc_release = nfssvc_release_diropres,
  671. .pc_argsize = sizeof(struct nfsd_createargs),
  672. .pc_ressize = sizeof(struct nfsd_diropres),
  673. .pc_cachetype = RC_REPLBUFF,
  674. .pc_xdrressize = ST+FH+AT,
  675. },
  676. [NFSPROC_RMDIR] = {
  677. .pc_func = nfsd_proc_rmdir,
  678. .pc_decode = nfssvc_decode_diropargs,
  679. .pc_encode = nfssvc_encode_stat,
  680. .pc_argsize = sizeof(struct nfsd_diropargs),
  681. .pc_ressize = sizeof(struct nfsd_stat),
  682. .pc_cachetype = RC_REPLSTAT,
  683. .pc_xdrressize = ST,
  684. },
  685. [NFSPROC_READDIR] = {
  686. .pc_func = nfsd_proc_readdir,
  687. .pc_decode = nfssvc_decode_readdirargs,
  688. .pc_encode = nfssvc_encode_readdirres,
  689. .pc_argsize = sizeof(struct nfsd_readdirargs),
  690. .pc_ressize = sizeof(struct nfsd_readdirres),
  691. .pc_cachetype = RC_NOCACHE,
  692. },
  693. [NFSPROC_STATFS] = {
  694. .pc_func = nfsd_proc_statfs,
  695. .pc_decode = nfssvc_decode_fhandle,
  696. .pc_encode = nfssvc_encode_statfsres,
  697. .pc_argsize = sizeof(struct nfsd_fhandle),
  698. .pc_ressize = sizeof(struct nfsd_statfsres),
  699. .pc_cachetype = RC_NOCACHE,
  700. .pc_xdrressize = ST+5,
  701. },
  702. };
  703. static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)];
  704. const struct svc_version nfsd_version2 = {
  705. .vs_vers = 2,
  706. .vs_nproc = 18,
  707. .vs_proc = nfsd_procedures2,
  708. .vs_count = nfsd_count2,
  709. .vs_dispatch = nfsd_dispatch,
  710. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  711. };
  712. /*
  713. * Map errnos to NFS errnos.
  714. */
  715. __be32
  716. nfserrno (int errno)
  717. {
  718. static struct {
  719. __be32 nfserr;
  720. int syserr;
  721. } nfs_errtbl[] = {
  722. { nfs_ok, 0 },
  723. { nfserr_perm, -EPERM },
  724. { nfserr_noent, -ENOENT },
  725. { nfserr_io, -EIO },
  726. { nfserr_nxio, -ENXIO },
  727. { nfserr_fbig, -E2BIG },
  728. { nfserr_acces, -EACCES },
  729. { nfserr_exist, -EEXIST },
  730. { nfserr_xdev, -EXDEV },
  731. { nfserr_mlink, -EMLINK },
  732. { nfserr_nodev, -ENODEV },
  733. { nfserr_notdir, -ENOTDIR },
  734. { nfserr_isdir, -EISDIR },
  735. { nfserr_inval, -EINVAL },
  736. { nfserr_fbig, -EFBIG },
  737. { nfserr_nospc, -ENOSPC },
  738. { nfserr_rofs, -EROFS },
  739. { nfserr_mlink, -EMLINK },
  740. { nfserr_nametoolong, -ENAMETOOLONG },
  741. { nfserr_notempty, -ENOTEMPTY },
  742. #ifdef EDQUOT
  743. { nfserr_dquot, -EDQUOT },
  744. #endif
  745. { nfserr_stale, -ESTALE },
  746. { nfserr_jukebox, -ETIMEDOUT },
  747. { nfserr_jukebox, -ERESTARTSYS },
  748. { nfserr_jukebox, -EAGAIN },
  749. { nfserr_jukebox, -EWOULDBLOCK },
  750. { nfserr_jukebox, -ENOMEM },
  751. { nfserr_io, -ETXTBSY },
  752. { nfserr_notsupp, -EOPNOTSUPP },
  753. { nfserr_toosmall, -ETOOSMALL },
  754. { nfserr_serverfault, -ESERVERFAULT },
  755. { nfserr_serverfault, -ENFILE },
  756. { nfserr_io, -EUCLEAN },
  757. { nfserr_perm, -ENOKEY },
  758. };
  759. int i;
  760. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  761. if (nfs_errtbl[i].syserr == errno)
  762. return nfs_errtbl[i].nfserr;
  763. }
  764. WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
  765. return nfserr_io;
  766. }