nfsproc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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, rqstp->rq_arg.pages,
  190. &argp->first, cnt);
  191. if (!nvecs)
  192. return nfserr_io;
  193. nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
  194. argp->offset, rqstp->rq_vec, nvecs,
  195. &cnt, NFS_DATA_SYNC);
  196. return nfsd_return_attrs(nfserr, resp);
  197. }
  198. /*
  199. * CREATE processing is complicated. The keyword here is `overloaded.'
  200. * The parent directory is kept locked between the check for existence
  201. * and the actual create() call in compliance with VFS protocols.
  202. * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
  203. */
  204. static __be32
  205. nfsd_proc_create(struct svc_rqst *rqstp)
  206. {
  207. struct nfsd_createargs *argp = rqstp->rq_argp;
  208. struct nfsd_diropres *resp = rqstp->rq_resp;
  209. svc_fh *dirfhp = &argp->fh;
  210. svc_fh *newfhp = &resp->fh;
  211. struct iattr *attr = &argp->attrs;
  212. struct inode *inode;
  213. struct dentry *dchild;
  214. int type, mode;
  215. __be32 nfserr;
  216. int hosterr;
  217. dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
  218. dprintk("nfsd: CREATE %s %.*s\n",
  219. SVCFH_fmt(dirfhp), argp->len, argp->name);
  220. /* First verify the parent file handle */
  221. nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
  222. if (nfserr)
  223. goto done; /* must fh_put dirfhp even on error */
  224. /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
  225. nfserr = nfserr_exist;
  226. if (isdotent(argp->name, argp->len))
  227. goto done;
  228. hosterr = fh_want_write(dirfhp);
  229. if (hosterr) {
  230. nfserr = nfserrno(hosterr);
  231. goto done;
  232. }
  233. fh_lock_nested(dirfhp, I_MUTEX_PARENT);
  234. dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
  235. if (IS_ERR(dchild)) {
  236. nfserr = nfserrno(PTR_ERR(dchild));
  237. goto out_unlock;
  238. }
  239. fh_init(newfhp, NFS_FHSIZE);
  240. nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
  241. if (!nfserr && d_really_is_negative(dchild))
  242. nfserr = nfserr_noent;
  243. dput(dchild);
  244. if (nfserr) {
  245. if (nfserr != nfserr_noent)
  246. goto out_unlock;
  247. /*
  248. * If the new file handle wasn't verified, we can't tell
  249. * whether the file exists or not. Time to bail ...
  250. */
  251. nfserr = nfserr_acces;
  252. if (!newfhp->fh_dentry) {
  253. printk(KERN_WARNING
  254. "nfsd_proc_create: file handle not verified\n");
  255. goto out_unlock;
  256. }
  257. }
  258. inode = d_inode(newfhp->fh_dentry);
  259. /* Unfudge the mode bits */
  260. if (attr->ia_valid & ATTR_MODE) {
  261. type = attr->ia_mode & S_IFMT;
  262. mode = attr->ia_mode & ~S_IFMT;
  263. if (!type) {
  264. /* no type, so if target exists, assume same as that,
  265. * else assume a file */
  266. if (inode) {
  267. type = inode->i_mode & S_IFMT;
  268. switch(type) {
  269. case S_IFCHR:
  270. case S_IFBLK:
  271. /* reserve rdev for later checking */
  272. rdev = inode->i_rdev;
  273. attr->ia_valid |= ATTR_SIZE;
  274. /* FALLTHROUGH */
  275. case S_IFIFO:
  276. /* this is probably a permission check..
  277. * at least IRIX implements perm checking on
  278. * echo thing > device-special-file-or-pipe
  279. * by doing a CREATE with type==0
  280. */
  281. nfserr = nfsd_permission(rqstp,
  282. newfhp->fh_export,
  283. newfhp->fh_dentry,
  284. NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
  285. if (nfserr && nfserr != nfserr_rofs)
  286. goto out_unlock;
  287. }
  288. } else
  289. type = S_IFREG;
  290. }
  291. } else if (inode) {
  292. type = inode->i_mode & S_IFMT;
  293. mode = inode->i_mode & ~S_IFMT;
  294. } else {
  295. type = S_IFREG;
  296. mode = 0; /* ??? */
  297. }
  298. attr->ia_valid |= ATTR_MODE;
  299. attr->ia_mode = mode;
  300. /* Special treatment for non-regular files according to the
  301. * gospel of sun micro
  302. */
  303. if (type != S_IFREG) {
  304. if (type != S_IFBLK && type != S_IFCHR) {
  305. rdev = 0;
  306. } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
  307. /* If you think you've seen the worst, grok this. */
  308. type = S_IFIFO;
  309. } else {
  310. /* Okay, char or block special */
  311. if (!rdev)
  312. rdev = wanted;
  313. }
  314. /* we've used the SIZE information, so discard it */
  315. attr->ia_valid &= ~ATTR_SIZE;
  316. /* Make sure the type and device matches */
  317. nfserr = nfserr_exist;
  318. if (inode && type != (inode->i_mode & S_IFMT))
  319. goto out_unlock;
  320. }
  321. nfserr = 0;
  322. if (!inode) {
  323. /* File doesn't exist. Create it and set attrs */
  324. nfserr = nfsd_create_locked(rqstp, dirfhp, argp->name,
  325. argp->len, attr, type, rdev, newfhp);
  326. } else if (type == S_IFREG) {
  327. dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
  328. argp->name, attr->ia_valid, (long) attr->ia_size);
  329. /* File already exists. We ignore all attributes except
  330. * size, so that creat() behaves exactly like
  331. * open(..., O_CREAT|O_TRUNC|O_WRONLY).
  332. */
  333. attr->ia_valid &= ATTR_SIZE;
  334. if (attr->ia_valid)
  335. nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
  336. }
  337. out_unlock:
  338. /* We don't really need to unlock, as fh_put does it. */
  339. fh_unlock(dirfhp);
  340. fh_drop_write(dirfhp);
  341. done:
  342. fh_put(dirfhp);
  343. return nfsd_return_dirop(nfserr, resp);
  344. }
  345. static __be32
  346. nfsd_proc_remove(struct svc_rqst *rqstp)
  347. {
  348. struct nfsd_diropargs *argp = rqstp->rq_argp;
  349. __be32 nfserr;
  350. dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
  351. argp->len, argp->name);
  352. /* Unlink. -SIFDIR means file must not be a directory */
  353. nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
  354. fh_put(&argp->fh);
  355. return nfserr;
  356. }
  357. static __be32
  358. nfsd_proc_rename(struct svc_rqst *rqstp)
  359. {
  360. struct nfsd_renameargs *argp = rqstp->rq_argp;
  361. __be32 nfserr;
  362. dprintk("nfsd: RENAME %s %.*s -> \n",
  363. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
  364. dprintk("nfsd: -> %s %.*s\n",
  365. SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
  366. nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
  367. &argp->tfh, argp->tname, argp->tlen);
  368. fh_put(&argp->ffh);
  369. fh_put(&argp->tfh);
  370. return nfserr;
  371. }
  372. static __be32
  373. nfsd_proc_link(struct svc_rqst *rqstp)
  374. {
  375. struct nfsd_linkargs *argp = rqstp->rq_argp;
  376. __be32 nfserr;
  377. dprintk("nfsd: LINK %s ->\n",
  378. SVCFH_fmt(&argp->ffh));
  379. dprintk("nfsd: %s %.*s\n",
  380. SVCFH_fmt(&argp->tfh),
  381. argp->tlen,
  382. argp->tname);
  383. nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
  384. &argp->ffh);
  385. fh_put(&argp->ffh);
  386. fh_put(&argp->tfh);
  387. return nfserr;
  388. }
  389. static __be32
  390. nfsd_proc_symlink(struct svc_rqst *rqstp)
  391. {
  392. struct nfsd_symlinkargs *argp = rqstp->rq_argp;
  393. struct svc_fh newfh;
  394. __be32 nfserr;
  395. if (argp->tlen > NFS_MAXPATHLEN)
  396. return nfserr_nametoolong;
  397. argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
  398. page_address(rqstp->rq_arg.pages[0]),
  399. argp->tlen);
  400. if (IS_ERR(argp->tname))
  401. return nfserrno(PTR_ERR(argp->tname));
  402. dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
  403. SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
  404. argp->tlen, argp->tname);
  405. fh_init(&newfh, NFS_FHSIZE);
  406. nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
  407. argp->tname, &newfh);
  408. kfree(argp->tname);
  409. fh_put(&argp->ffh);
  410. fh_put(&newfh);
  411. return nfserr;
  412. }
  413. /*
  414. * Make directory. This operation is not idempotent.
  415. * N.B. After this call resp->fh needs an fh_put
  416. */
  417. static __be32
  418. nfsd_proc_mkdir(struct svc_rqst *rqstp)
  419. {
  420. struct nfsd_createargs *argp = rqstp->rq_argp;
  421. struct nfsd_diropres *resp = rqstp->rq_resp;
  422. __be32 nfserr;
  423. dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  424. if (resp->fh.fh_dentry) {
  425. printk(KERN_WARNING
  426. "nfsd_proc_mkdir: response already verified??\n");
  427. }
  428. argp->attrs.ia_valid &= ~ATTR_SIZE;
  429. fh_init(&resp->fh, NFS_FHSIZE);
  430. nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
  431. &argp->attrs, S_IFDIR, 0, &resp->fh);
  432. fh_put(&argp->fh);
  433. return nfsd_return_dirop(nfserr, resp);
  434. }
  435. /*
  436. * Remove a directory
  437. */
  438. static __be32
  439. nfsd_proc_rmdir(struct svc_rqst *rqstp)
  440. {
  441. struct nfsd_diropargs *argp = rqstp->rq_argp;
  442. __be32 nfserr;
  443. dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
  444. nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
  445. fh_put(&argp->fh);
  446. return nfserr;
  447. }
  448. /*
  449. * Read a portion of a directory.
  450. */
  451. static __be32
  452. nfsd_proc_readdir(struct svc_rqst *rqstp)
  453. {
  454. struct nfsd_readdirargs *argp = rqstp->rq_argp;
  455. struct nfsd_readdirres *resp = rqstp->rq_resp;
  456. int count;
  457. __be32 nfserr;
  458. loff_t offset;
  459. dprintk("nfsd: READDIR %s %d bytes at %d\n",
  460. SVCFH_fmt(&argp->fh),
  461. argp->count, argp->cookie);
  462. /* Shrink to the client read size */
  463. count = (argp->count >> 2) - 2;
  464. /* Make sure we've room for the NULL ptr & eof flag */
  465. count -= 2;
  466. if (count < 0)
  467. count = 0;
  468. resp->buffer = argp->buffer;
  469. resp->offset = NULL;
  470. resp->buflen = count;
  471. resp->common.err = nfs_ok;
  472. /* Read directory and encode entries on the fly */
  473. offset = argp->cookie;
  474. nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
  475. &resp->common, nfssvc_encode_entry);
  476. resp->count = resp->buffer - argp->buffer;
  477. if (resp->offset)
  478. *resp->offset = htonl(offset);
  479. fh_put(&argp->fh);
  480. return nfserr;
  481. }
  482. /*
  483. * Get file system info
  484. */
  485. static __be32
  486. nfsd_proc_statfs(struct svc_rqst *rqstp)
  487. {
  488. struct nfsd_fhandle *argp = rqstp->rq_argp;
  489. struct nfsd_statfsres *resp = rqstp->rq_resp;
  490. __be32 nfserr;
  491. dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
  492. nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
  493. NFSD_MAY_BYPASS_GSS_ON_ROOT);
  494. fh_put(&argp->fh);
  495. return nfserr;
  496. }
  497. /*
  498. * NFSv2 Server procedures.
  499. * Only the results of non-idempotent operations are cached.
  500. */
  501. struct nfsd_void { int dummy; };
  502. #define ST 1 /* status */
  503. #define FH 8 /* filehandle */
  504. #define AT 18 /* attributes */
  505. static const struct svc_procedure nfsd_procedures2[18] = {
  506. [NFSPROC_NULL] = {
  507. .pc_func = nfsd_proc_null,
  508. .pc_decode = nfssvc_decode_void,
  509. .pc_encode = nfssvc_encode_void,
  510. .pc_argsize = sizeof(struct nfsd_void),
  511. .pc_ressize = sizeof(struct nfsd_void),
  512. .pc_cachetype = RC_NOCACHE,
  513. .pc_xdrressize = ST,
  514. },
  515. [NFSPROC_GETATTR] = {
  516. .pc_func = nfsd_proc_getattr,
  517. .pc_decode = nfssvc_decode_fhandle,
  518. .pc_encode = nfssvc_encode_attrstat,
  519. .pc_release = nfssvc_release_fhandle,
  520. .pc_argsize = sizeof(struct nfsd_fhandle),
  521. .pc_ressize = sizeof(struct nfsd_attrstat),
  522. .pc_cachetype = RC_NOCACHE,
  523. .pc_xdrressize = ST+AT,
  524. },
  525. [NFSPROC_SETATTR] = {
  526. .pc_func = nfsd_proc_setattr,
  527. .pc_decode = nfssvc_decode_sattrargs,
  528. .pc_encode = nfssvc_encode_attrstat,
  529. .pc_release = nfssvc_release_fhandle,
  530. .pc_argsize = sizeof(struct nfsd_sattrargs),
  531. .pc_ressize = sizeof(struct nfsd_attrstat),
  532. .pc_cachetype = RC_REPLBUFF,
  533. .pc_xdrressize = ST+AT,
  534. },
  535. [NFSPROC_ROOT] = {
  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 = ST,
  542. },
  543. [NFSPROC_LOOKUP] = {
  544. .pc_func = nfsd_proc_lookup,
  545. .pc_decode = nfssvc_decode_diropargs,
  546. .pc_encode = nfssvc_encode_diropres,
  547. .pc_release = nfssvc_release_fhandle,
  548. .pc_argsize = sizeof(struct nfsd_diropargs),
  549. .pc_ressize = sizeof(struct nfsd_diropres),
  550. .pc_cachetype = RC_NOCACHE,
  551. .pc_xdrressize = ST+FH+AT,
  552. },
  553. [NFSPROC_READLINK] = {
  554. .pc_func = nfsd_proc_readlink,
  555. .pc_decode = nfssvc_decode_readlinkargs,
  556. .pc_encode = nfssvc_encode_readlinkres,
  557. .pc_argsize = sizeof(struct nfsd_readlinkargs),
  558. .pc_ressize = sizeof(struct nfsd_readlinkres),
  559. .pc_cachetype = RC_NOCACHE,
  560. .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
  561. },
  562. [NFSPROC_READ] = {
  563. .pc_func = nfsd_proc_read,
  564. .pc_decode = nfssvc_decode_readargs,
  565. .pc_encode = nfssvc_encode_readres,
  566. .pc_release = nfssvc_release_fhandle,
  567. .pc_argsize = sizeof(struct nfsd_readargs),
  568. .pc_ressize = sizeof(struct nfsd_readres),
  569. .pc_cachetype = RC_NOCACHE,
  570. .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
  571. },
  572. [NFSPROC_WRITECACHE] = {
  573. .pc_decode = nfssvc_decode_void,
  574. .pc_encode = nfssvc_encode_void,
  575. .pc_argsize = sizeof(struct nfsd_void),
  576. .pc_ressize = sizeof(struct nfsd_void),
  577. .pc_cachetype = RC_NOCACHE,
  578. .pc_xdrressize = ST,
  579. },
  580. [NFSPROC_WRITE] = {
  581. .pc_func = nfsd_proc_write,
  582. .pc_decode = nfssvc_decode_writeargs,
  583. .pc_encode = nfssvc_encode_attrstat,
  584. .pc_release = nfssvc_release_fhandle,
  585. .pc_argsize = sizeof(struct nfsd_writeargs),
  586. .pc_ressize = sizeof(struct nfsd_attrstat),
  587. .pc_cachetype = RC_REPLBUFF,
  588. .pc_xdrressize = ST+AT,
  589. },
  590. [NFSPROC_CREATE] = {
  591. .pc_func = nfsd_proc_create,
  592. .pc_decode = nfssvc_decode_createargs,
  593. .pc_encode = nfssvc_encode_diropres,
  594. .pc_release = nfssvc_release_fhandle,
  595. .pc_argsize = sizeof(struct nfsd_createargs),
  596. .pc_ressize = sizeof(struct nfsd_diropres),
  597. .pc_cachetype = RC_REPLBUFF,
  598. .pc_xdrressize = ST+FH+AT,
  599. },
  600. [NFSPROC_REMOVE] = {
  601. .pc_func = nfsd_proc_remove,
  602. .pc_decode = nfssvc_decode_diropargs,
  603. .pc_encode = nfssvc_encode_void,
  604. .pc_argsize = sizeof(struct nfsd_diropargs),
  605. .pc_ressize = sizeof(struct nfsd_void),
  606. .pc_cachetype = RC_REPLSTAT,
  607. .pc_xdrressize = ST,
  608. },
  609. [NFSPROC_RENAME] = {
  610. .pc_func = nfsd_proc_rename,
  611. .pc_decode = nfssvc_decode_renameargs,
  612. .pc_encode = nfssvc_encode_void,
  613. .pc_argsize = sizeof(struct nfsd_renameargs),
  614. .pc_ressize = sizeof(struct nfsd_void),
  615. .pc_cachetype = RC_REPLSTAT,
  616. .pc_xdrressize = ST,
  617. },
  618. [NFSPROC_LINK] = {
  619. .pc_func = nfsd_proc_link,
  620. .pc_decode = nfssvc_decode_linkargs,
  621. .pc_encode = nfssvc_encode_void,
  622. .pc_argsize = sizeof(struct nfsd_linkargs),
  623. .pc_ressize = sizeof(struct nfsd_void),
  624. .pc_cachetype = RC_REPLSTAT,
  625. .pc_xdrressize = ST,
  626. },
  627. [NFSPROC_SYMLINK] = {
  628. .pc_func = nfsd_proc_symlink,
  629. .pc_decode = nfssvc_decode_symlinkargs,
  630. .pc_encode = nfssvc_encode_void,
  631. .pc_argsize = sizeof(struct nfsd_symlinkargs),
  632. .pc_ressize = sizeof(struct nfsd_void),
  633. .pc_cachetype = RC_REPLSTAT,
  634. .pc_xdrressize = ST,
  635. },
  636. [NFSPROC_MKDIR] = {
  637. .pc_func = nfsd_proc_mkdir,
  638. .pc_decode = nfssvc_decode_createargs,
  639. .pc_encode = nfssvc_encode_diropres,
  640. .pc_release = nfssvc_release_fhandle,
  641. .pc_argsize = sizeof(struct nfsd_createargs),
  642. .pc_ressize = sizeof(struct nfsd_diropres),
  643. .pc_cachetype = RC_REPLBUFF,
  644. .pc_xdrressize = ST+FH+AT,
  645. },
  646. [NFSPROC_RMDIR] = {
  647. .pc_func = nfsd_proc_rmdir,
  648. .pc_decode = nfssvc_decode_diropargs,
  649. .pc_encode = nfssvc_encode_void,
  650. .pc_argsize = sizeof(struct nfsd_diropargs),
  651. .pc_ressize = sizeof(struct nfsd_void),
  652. .pc_cachetype = RC_REPLSTAT,
  653. .pc_xdrressize = ST,
  654. },
  655. [NFSPROC_READDIR] = {
  656. .pc_func = nfsd_proc_readdir,
  657. .pc_decode = nfssvc_decode_readdirargs,
  658. .pc_encode = nfssvc_encode_readdirres,
  659. .pc_argsize = sizeof(struct nfsd_readdirargs),
  660. .pc_ressize = sizeof(struct nfsd_readdirres),
  661. .pc_cachetype = RC_NOCACHE,
  662. },
  663. [NFSPROC_STATFS] = {
  664. .pc_func = nfsd_proc_statfs,
  665. .pc_decode = nfssvc_decode_fhandle,
  666. .pc_encode = nfssvc_encode_statfsres,
  667. .pc_argsize = sizeof(struct nfsd_fhandle),
  668. .pc_ressize = sizeof(struct nfsd_statfsres),
  669. .pc_cachetype = RC_NOCACHE,
  670. .pc_xdrressize = ST+5,
  671. },
  672. };
  673. static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)];
  674. const struct svc_version nfsd_version2 = {
  675. .vs_vers = 2,
  676. .vs_nproc = 18,
  677. .vs_proc = nfsd_procedures2,
  678. .vs_count = nfsd_count2,
  679. .vs_dispatch = nfsd_dispatch,
  680. .vs_xdrsize = NFS2_SVC_XDRSIZE,
  681. };
  682. /*
  683. * Map errnos to NFS errnos.
  684. */
  685. __be32
  686. nfserrno (int errno)
  687. {
  688. static struct {
  689. __be32 nfserr;
  690. int syserr;
  691. } nfs_errtbl[] = {
  692. { nfs_ok, 0 },
  693. { nfserr_perm, -EPERM },
  694. { nfserr_noent, -ENOENT },
  695. { nfserr_io, -EIO },
  696. { nfserr_nxio, -ENXIO },
  697. { nfserr_fbig, -E2BIG },
  698. { nfserr_acces, -EACCES },
  699. { nfserr_exist, -EEXIST },
  700. { nfserr_xdev, -EXDEV },
  701. { nfserr_mlink, -EMLINK },
  702. { nfserr_nodev, -ENODEV },
  703. { nfserr_notdir, -ENOTDIR },
  704. { nfserr_isdir, -EISDIR },
  705. { nfserr_inval, -EINVAL },
  706. { nfserr_fbig, -EFBIG },
  707. { nfserr_nospc, -ENOSPC },
  708. { nfserr_rofs, -EROFS },
  709. { nfserr_mlink, -EMLINK },
  710. { nfserr_nametoolong, -ENAMETOOLONG },
  711. { nfserr_notempty, -ENOTEMPTY },
  712. #ifdef EDQUOT
  713. { nfserr_dquot, -EDQUOT },
  714. #endif
  715. { nfserr_stale, -ESTALE },
  716. { nfserr_jukebox, -ETIMEDOUT },
  717. { nfserr_jukebox, -ERESTARTSYS },
  718. { nfserr_jukebox, -EAGAIN },
  719. { nfserr_jukebox, -EWOULDBLOCK },
  720. { nfserr_jukebox, -ENOMEM },
  721. { nfserr_io, -ETXTBSY },
  722. { nfserr_notsupp, -EOPNOTSUPP },
  723. { nfserr_toosmall, -ETOOSMALL },
  724. { nfserr_serverfault, -ESERVERFAULT },
  725. { nfserr_serverfault, -ENFILE },
  726. { nfserr_io, -EUCLEAN },
  727. { nfserr_perm, -ENOKEY },
  728. };
  729. int i;
  730. for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
  731. if (nfs_errtbl[i].syserr == errno)
  732. return nfs_errtbl[i].nfserr;
  733. }
  734. WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
  735. return nfserr_io;
  736. }