nfsproc.c 23 KB

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