nfsproc.c 22 KB

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