nfsproc.c 21 KB

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