nfsproc.c 22 KB

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