nfsproc.c 21 KB

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