nfs4proc.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /*
  2. * fs/nfsd/nfs4proc.c
  3. *
  4. * Server-side procedures for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/param.h>
  38. #include <linux/major.h>
  39. #include <linux/slab.h>
  40. #include <linux/file.h>
  41. #include <linux/sunrpc/svc.h>
  42. #include <linux/nfsd/nfsd.h>
  43. #include <linux/nfsd/cache.h>
  44. #include <linux/nfs4.h>
  45. #include <linux/nfsd/state.h>
  46. #include <linux/nfsd/xdr4.h>
  47. #include <linux/nfs4_acl.h>
  48. #include <linux/sunrpc/gss_api.h>
  49. #include "vfs.h"
  50. #define NFSDDBG_FACILITY NFSDDBG_PROC
  51. static u32 nfsd_attrmask[] = {
  52. NFSD_WRITEABLE_ATTRS_WORD0,
  53. NFSD_WRITEABLE_ATTRS_WORD1,
  54. NFSD_WRITEABLE_ATTRS_WORD2
  55. };
  56. static u32 nfsd41_ex_attrmask[] = {
  57. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  58. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  59. NFSD_SUPPATTR_EXCLCREAT_WORD2
  60. };
  61. static __be32
  62. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  63. u32 *bmval, u32 *writable)
  64. {
  65. struct dentry *dentry = cstate->current_fh.fh_dentry;
  66. /*
  67. * Check about attributes are supported by the NFSv4 server or not.
  68. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
  69. */
  70. if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
  71. (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
  72. (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
  73. return nfserr_attrnotsupp;
  74. /*
  75. * Check FATTR4_WORD0_ACL can be supported
  76. * in current environment or not.
  77. */
  78. if (bmval[0] & FATTR4_WORD0_ACL) {
  79. if (!IS_POSIXACL(dentry->d_inode))
  80. return nfserr_attrnotsupp;
  81. }
  82. /*
  83. * According to spec, read-only attributes return ERR_INVAL.
  84. */
  85. if (writable) {
  86. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  87. (bmval[2] & ~writable[2]))
  88. return nfserr_inval;
  89. }
  90. return nfs_ok;
  91. }
  92. static __be32
  93. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  94. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  95. {
  96. __be32 status = nfs_ok;
  97. if (open->op_create == NFS4_OPEN_CREATE) {
  98. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  99. || open->op_createmode == NFS4_CREATE_GUARDED)
  100. status = check_attr_support(rqstp, cstate,
  101. open->op_bmval, nfsd_attrmask);
  102. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  103. status = check_attr_support(rqstp, cstate,
  104. open->op_bmval, nfsd41_ex_attrmask);
  105. }
  106. return status;
  107. }
  108. static int
  109. is_create_with_attrs(struct nfsd4_open *open)
  110. {
  111. return open->op_create == NFS4_OPEN_CREATE
  112. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  113. || open->op_createmode == NFS4_CREATE_GUARDED
  114. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  115. }
  116. /*
  117. * if error occurs when setting the acl, just clear the acl bit
  118. * in the returned attr bitmap.
  119. */
  120. static void
  121. do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
  122. struct nfs4_acl *acl, u32 *bmval)
  123. {
  124. __be32 status;
  125. status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
  126. if (status)
  127. /*
  128. * We should probably fail the whole open at this point,
  129. * but we've already created the file, so it's too late;
  130. * So this seems the least of evils:
  131. */
  132. bmval[0] &= ~FATTR4_WORD0_ACL;
  133. }
  134. static inline void
  135. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  136. {
  137. fh_put(dst);
  138. dget(src->fh_dentry);
  139. if (src->fh_export)
  140. cache_get(&src->fh_export->h);
  141. *dst = *src;
  142. }
  143. static __be32
  144. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  145. {
  146. __be32 status;
  147. if (open->op_truncate &&
  148. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  149. return nfserr_inval;
  150. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  151. accmode |= NFSD_MAY_READ;
  152. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  153. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  154. if (open->op_share_deny & NFS4_SHARE_DENY_WRITE)
  155. accmode |= NFSD_MAY_WRITE;
  156. status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
  157. return status;
  158. }
  159. static __be32
  160. do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  161. {
  162. struct svc_fh resfh;
  163. __be32 status;
  164. int created = 0;
  165. fh_init(&resfh, NFS4_FHSIZE);
  166. open->op_truncate = 0;
  167. if (open->op_create) {
  168. /* FIXME: check session persistence and pnfs flags.
  169. * The nfsv4.1 spec requires the following semantics:
  170. *
  171. * Persistent | pNFS | Server REQUIRED | Client Allowed
  172. * Reply Cache | server | |
  173. * -------------+--------+-----------------+--------------------
  174. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  175. * | | | (SHOULD)
  176. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  177. * | | | (SHOULD NOT)
  178. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  179. * yes | no | GUARDED4 | GUARDED4
  180. * yes | yes | GUARDED4 | GUARDED4
  181. */
  182. /*
  183. * Note: create modes (UNCHECKED,GUARDED...) are the same
  184. * in NFSv4 as in v3.
  185. */
  186. status = nfsd_create_v3(rqstp, current_fh, open->op_fname.data,
  187. open->op_fname.len, &open->op_iattr,
  188. &resfh, open->op_createmode,
  189. (u32 *)open->op_verf.data,
  190. &open->op_truncate, &created);
  191. /*
  192. * Following rfc 3530 14.2.16, use the returned bitmask
  193. * to indicate which attributes we used to store the
  194. * verifier:
  195. */
  196. if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
  197. open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
  198. FATTR4_WORD1_TIME_MODIFY);
  199. } else {
  200. status = nfsd_lookup(rqstp, current_fh,
  201. open->op_fname.data, open->op_fname.len, &resfh);
  202. fh_unlock(current_fh);
  203. }
  204. if (status)
  205. goto out;
  206. if (is_create_with_attrs(open) && open->op_acl != NULL)
  207. do_set_nfs4_acl(rqstp, &resfh, open->op_acl, open->op_bmval);
  208. set_change_info(&open->op_cinfo, current_fh);
  209. fh_dup2(current_fh, &resfh);
  210. /* set reply cache */
  211. fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
  212. &resfh.fh_handle);
  213. if (!created)
  214. status = do_open_permission(rqstp, current_fh, open,
  215. NFSD_MAY_NOP);
  216. out:
  217. fh_put(&resfh);
  218. return status;
  219. }
  220. static __be32
  221. do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  222. {
  223. __be32 status;
  224. /* Only reclaims from previously confirmed clients are valid */
  225. if ((status = nfs4_check_open_reclaim(&open->op_clientid)))
  226. return status;
  227. /* We don't know the target directory, and therefore can not
  228. * set the change info
  229. */
  230. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  231. /* set replay cache */
  232. fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
  233. &current_fh->fh_handle);
  234. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  235. (open->op_iattr.ia_size == 0);
  236. status = do_open_permission(rqstp, current_fh, open,
  237. NFSD_MAY_OWNER_OVERRIDE);
  238. return status;
  239. }
  240. static void
  241. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  242. {
  243. struct nfsd4_sessionid *sid =
  244. (struct nfsd4_sessionid *)session->se_sessionid.data;
  245. clid->cl_boot = sid->clientid.cl_boot;
  246. clid->cl_id = sid->clientid.cl_id;
  247. }
  248. static __be32
  249. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  250. struct nfsd4_open *open)
  251. {
  252. __be32 status;
  253. struct nfsd4_compoundres *resp;
  254. dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n",
  255. (int)open->op_fname.len, open->op_fname.data,
  256. open->op_stateowner);
  257. /* This check required by spec. */
  258. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  259. return nfserr_inval;
  260. if (nfsd4_has_session(cstate))
  261. copy_clientid(&open->op_clientid, cstate->session);
  262. nfs4_lock_state();
  263. /* check seqid for replay. set nfs4_owner */
  264. resp = rqstp->rq_resp;
  265. status = nfsd4_process_open1(&resp->cstate, open);
  266. if (status == nfserr_replay_me) {
  267. struct nfs4_replay *rp = &open->op_stateowner->so_replay;
  268. fh_put(&cstate->current_fh);
  269. fh_copy_shallow(&cstate->current_fh.fh_handle,
  270. &rp->rp_openfh);
  271. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  272. if (status)
  273. dprintk("nfsd4_open: replay failed"
  274. " restoring previous filehandle\n");
  275. else
  276. status = nfserr_replay_me;
  277. }
  278. if (status)
  279. goto out;
  280. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  281. if (status)
  282. goto out;
  283. /* Openowner is now set, so sequence id will get bumped. Now we need
  284. * these checks before we do any creates: */
  285. status = nfserr_grace;
  286. if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  287. goto out;
  288. status = nfserr_no_grace;
  289. if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  290. goto out;
  291. switch (open->op_claim_type) {
  292. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  293. case NFS4_OPEN_CLAIM_NULL:
  294. /*
  295. * (1) set CURRENT_FH to the file being opened,
  296. * creating it if necessary, (2) set open->op_cinfo,
  297. * (3) set open->op_truncate if the file is to be
  298. * truncated after opening, (4) do permission checking.
  299. */
  300. status = do_open_lookup(rqstp, &cstate->current_fh,
  301. open);
  302. if (status)
  303. goto out;
  304. break;
  305. case NFS4_OPEN_CLAIM_PREVIOUS:
  306. open->op_stateowner->so_confirmed = 1;
  307. /*
  308. * The CURRENT_FH is already set to the file being
  309. * opened. (1) set open->op_cinfo, (2) set
  310. * open->op_truncate if the file is to be truncated
  311. * after opening, (3) do permission checking.
  312. */
  313. status = do_open_fhandle(rqstp, &cstate->current_fh,
  314. open);
  315. if (status)
  316. goto out;
  317. break;
  318. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  319. open->op_stateowner->so_confirmed = 1;
  320. dprintk("NFSD: unsupported OPEN claim type %d\n",
  321. open->op_claim_type);
  322. status = nfserr_notsupp;
  323. goto out;
  324. default:
  325. dprintk("NFSD: Invalid OPEN claim type %d\n",
  326. open->op_claim_type);
  327. status = nfserr_inval;
  328. goto out;
  329. }
  330. /*
  331. * nfsd4_process_open2() does the actual opening of the file. If
  332. * successful, it (1) truncates the file if open->op_truncate was
  333. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  334. */
  335. status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
  336. out:
  337. if (open->op_stateowner) {
  338. nfs4_get_stateowner(open->op_stateowner);
  339. cstate->replay_owner = open->op_stateowner;
  340. }
  341. nfs4_unlock_state();
  342. return status;
  343. }
  344. /*
  345. * filehandle-manipulating ops.
  346. */
  347. static __be32
  348. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  349. struct svc_fh **getfh)
  350. {
  351. if (!cstate->current_fh.fh_dentry)
  352. return nfserr_nofilehandle;
  353. *getfh = &cstate->current_fh;
  354. return nfs_ok;
  355. }
  356. static __be32
  357. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  358. struct nfsd4_putfh *putfh)
  359. {
  360. fh_put(&cstate->current_fh);
  361. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  362. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  363. putfh->pf_fhlen);
  364. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  365. }
  366. static __be32
  367. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  368. void *arg)
  369. {
  370. __be32 status;
  371. fh_put(&cstate->current_fh);
  372. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  373. return status;
  374. }
  375. static __be32
  376. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  377. void *arg)
  378. {
  379. if (!cstate->save_fh.fh_dentry)
  380. return nfserr_restorefh;
  381. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  382. return nfs_ok;
  383. }
  384. static __be32
  385. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  386. void *arg)
  387. {
  388. if (!cstate->current_fh.fh_dentry)
  389. return nfserr_nofilehandle;
  390. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  391. return nfs_ok;
  392. }
  393. /*
  394. * misc nfsv4 ops
  395. */
  396. static __be32
  397. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  398. struct nfsd4_access *access)
  399. {
  400. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  401. return nfserr_inval;
  402. access->ac_resp_access = access->ac_req_access;
  403. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  404. &access->ac_supported);
  405. }
  406. static __be32
  407. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  408. struct nfsd4_commit *commit)
  409. {
  410. __be32 status;
  411. u32 *p = (u32 *)commit->co_verf.data;
  412. *p++ = nfssvc_boot.tv_sec;
  413. *p++ = nfssvc_boot.tv_usec;
  414. status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
  415. commit->co_count);
  416. if (status == nfserr_symlink)
  417. status = nfserr_inval;
  418. return status;
  419. }
  420. static __be32
  421. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  422. struct nfsd4_create *create)
  423. {
  424. struct svc_fh resfh;
  425. __be32 status;
  426. dev_t rdev;
  427. fh_init(&resfh, NFS4_FHSIZE);
  428. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
  429. NFSD_MAY_CREATE);
  430. if (status == nfserr_symlink)
  431. status = nfserr_notdir;
  432. if (status)
  433. return status;
  434. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  435. nfsd_attrmask);
  436. if (status)
  437. return status;
  438. switch (create->cr_type) {
  439. case NF4LNK:
  440. /* ugh! we have to null-terminate the linktext, or
  441. * vfs_symlink() will choke. it is always safe to
  442. * null-terminate by brute force, since at worst we
  443. * will overwrite the first byte of the create namelen
  444. * in the XDR buffer, which has already been extracted
  445. * during XDR decode.
  446. */
  447. create->cr_linkname[create->cr_linklen] = 0;
  448. status = nfsd_symlink(rqstp, &cstate->current_fh,
  449. create->cr_name, create->cr_namelen,
  450. create->cr_linkname, create->cr_linklen,
  451. &resfh, &create->cr_iattr);
  452. break;
  453. case NF4BLK:
  454. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  455. if (MAJOR(rdev) != create->cr_specdata1 ||
  456. MINOR(rdev) != create->cr_specdata2)
  457. return nfserr_inval;
  458. status = nfsd_create(rqstp, &cstate->current_fh,
  459. create->cr_name, create->cr_namelen,
  460. &create->cr_iattr, S_IFBLK, rdev, &resfh);
  461. break;
  462. case NF4CHR:
  463. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  464. if (MAJOR(rdev) != create->cr_specdata1 ||
  465. MINOR(rdev) != create->cr_specdata2)
  466. return nfserr_inval;
  467. status = nfsd_create(rqstp, &cstate->current_fh,
  468. create->cr_name, create->cr_namelen,
  469. &create->cr_iattr,S_IFCHR, rdev, &resfh);
  470. break;
  471. case NF4SOCK:
  472. status = nfsd_create(rqstp, &cstate->current_fh,
  473. create->cr_name, create->cr_namelen,
  474. &create->cr_iattr, S_IFSOCK, 0, &resfh);
  475. break;
  476. case NF4FIFO:
  477. status = nfsd_create(rqstp, &cstate->current_fh,
  478. create->cr_name, create->cr_namelen,
  479. &create->cr_iattr, S_IFIFO, 0, &resfh);
  480. break;
  481. case NF4DIR:
  482. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  483. status = nfsd_create(rqstp, &cstate->current_fh,
  484. create->cr_name, create->cr_namelen,
  485. &create->cr_iattr, S_IFDIR, 0, &resfh);
  486. break;
  487. default:
  488. status = nfserr_badtype;
  489. }
  490. if (status)
  491. goto out;
  492. if (create->cr_acl != NULL)
  493. do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
  494. create->cr_bmval);
  495. fh_unlock(&cstate->current_fh);
  496. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  497. fh_dup2(&cstate->current_fh, &resfh);
  498. out:
  499. fh_put(&resfh);
  500. return status;
  501. }
  502. static __be32
  503. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  504. struct nfsd4_getattr *getattr)
  505. {
  506. __be32 status;
  507. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  508. if (status)
  509. return status;
  510. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  511. return nfserr_inval;
  512. getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  513. getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  514. getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  515. getattr->ga_fhp = &cstate->current_fh;
  516. return nfs_ok;
  517. }
  518. static __be32
  519. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  520. struct nfsd4_link *link)
  521. {
  522. __be32 status = nfserr_nofilehandle;
  523. if (!cstate->save_fh.fh_dentry)
  524. return status;
  525. status = nfsd_link(rqstp, &cstate->current_fh,
  526. link->li_name, link->li_namelen, &cstate->save_fh);
  527. if (!status)
  528. set_change_info(&link->li_cinfo, &cstate->current_fh);
  529. return status;
  530. }
  531. static __be32
  532. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  533. void *arg)
  534. {
  535. struct svc_fh tmp_fh;
  536. __be32 ret;
  537. fh_init(&tmp_fh, NFS4_FHSIZE);
  538. ret = exp_pseudoroot(rqstp, &tmp_fh);
  539. if (ret)
  540. return ret;
  541. if (tmp_fh.fh_dentry == cstate->current_fh.fh_dentry) {
  542. fh_put(&tmp_fh);
  543. return nfserr_noent;
  544. }
  545. fh_put(&tmp_fh);
  546. return nfsd_lookup(rqstp, &cstate->current_fh,
  547. "..", 2, &cstate->current_fh);
  548. }
  549. static __be32
  550. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  551. struct nfsd4_lookup *lookup)
  552. {
  553. return nfsd_lookup(rqstp, &cstate->current_fh,
  554. lookup->lo_name, lookup->lo_len,
  555. &cstate->current_fh);
  556. }
  557. static __be32
  558. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  559. struct nfsd4_read *read)
  560. {
  561. __be32 status;
  562. /* no need to check permission - this will be done in nfsd_read() */
  563. read->rd_filp = NULL;
  564. if (read->rd_offset >= OFFSET_MAX)
  565. return nfserr_inval;
  566. nfs4_lock_state();
  567. /* check stateid */
  568. if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid,
  569. RD_STATE, &read->rd_filp))) {
  570. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  571. goto out;
  572. }
  573. if (read->rd_filp)
  574. get_file(read->rd_filp);
  575. status = nfs_ok;
  576. out:
  577. nfs4_unlock_state();
  578. read->rd_rqstp = rqstp;
  579. read->rd_fhp = &cstate->current_fh;
  580. return status;
  581. }
  582. static __be32
  583. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  584. struct nfsd4_readdir *readdir)
  585. {
  586. u64 cookie = readdir->rd_cookie;
  587. static const nfs4_verifier zeroverf;
  588. /* no need to check permission - this will be done in nfsd_readdir() */
  589. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  590. return nfserr_inval;
  591. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  592. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  593. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  594. if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) ||
  595. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  596. return nfserr_bad_cookie;
  597. readdir->rd_rqstp = rqstp;
  598. readdir->rd_fhp = &cstate->current_fh;
  599. return nfs_ok;
  600. }
  601. static __be32
  602. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  603. struct nfsd4_readlink *readlink)
  604. {
  605. readlink->rl_rqstp = rqstp;
  606. readlink->rl_fhp = &cstate->current_fh;
  607. return nfs_ok;
  608. }
  609. static __be32
  610. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  611. struct nfsd4_remove *remove)
  612. {
  613. __be32 status;
  614. if (locks_in_grace())
  615. return nfserr_grace;
  616. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  617. remove->rm_name, remove->rm_namelen);
  618. if (status == nfserr_symlink)
  619. return nfserr_notdir;
  620. if (!status) {
  621. fh_unlock(&cstate->current_fh);
  622. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  623. }
  624. return status;
  625. }
  626. static __be32
  627. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  628. struct nfsd4_rename *rename)
  629. {
  630. __be32 status = nfserr_nofilehandle;
  631. if (!cstate->save_fh.fh_dentry)
  632. return status;
  633. if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
  634. & NFSEXP_NOSUBTREECHECK))
  635. return nfserr_grace;
  636. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  637. rename->rn_snamelen, &cstate->current_fh,
  638. rename->rn_tname, rename->rn_tnamelen);
  639. /* the underlying filesystem returns different error's than required
  640. * by NFSv4. both save_fh and current_fh have been verified.. */
  641. if (status == nfserr_isdir)
  642. status = nfserr_exist;
  643. else if ((status == nfserr_notdir) &&
  644. (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) &&
  645. S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode)))
  646. status = nfserr_exist;
  647. else if (status == nfserr_symlink)
  648. status = nfserr_notdir;
  649. if (!status) {
  650. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  651. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  652. }
  653. return status;
  654. }
  655. static __be32
  656. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  657. struct nfsd4_secinfo *secinfo)
  658. {
  659. struct svc_fh resfh;
  660. struct svc_export *exp;
  661. struct dentry *dentry;
  662. __be32 err;
  663. fh_init(&resfh, NFS4_FHSIZE);
  664. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  665. secinfo->si_name, secinfo->si_namelen,
  666. &exp, &dentry);
  667. if (err)
  668. return err;
  669. if (dentry->d_inode == NULL) {
  670. exp_put(exp);
  671. err = nfserr_noent;
  672. } else
  673. secinfo->si_exp = exp;
  674. dput(dentry);
  675. return err;
  676. }
  677. static __be32
  678. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  679. struct nfsd4_setattr *setattr)
  680. {
  681. __be32 status = nfs_ok;
  682. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  683. nfs4_lock_state();
  684. status = nfs4_preprocess_stateid_op(cstate,
  685. &setattr->sa_stateid, WR_STATE, NULL);
  686. nfs4_unlock_state();
  687. if (status) {
  688. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  689. return status;
  690. }
  691. }
  692. status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt);
  693. if (status)
  694. return status;
  695. status = nfs_ok;
  696. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  697. nfsd_attrmask);
  698. if (status)
  699. goto out;
  700. if (setattr->sa_acl != NULL)
  701. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  702. setattr->sa_acl);
  703. if (status)
  704. goto out;
  705. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  706. 0, (time_t)0);
  707. out:
  708. mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt);
  709. return status;
  710. }
  711. static __be32
  712. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  713. struct nfsd4_write *write)
  714. {
  715. stateid_t *stateid = &write->wr_stateid;
  716. struct file *filp = NULL;
  717. u32 *p;
  718. __be32 status = nfs_ok;
  719. unsigned long cnt;
  720. /* no need to check permission - this will be done in nfsd_write() */
  721. if (write->wr_offset >= OFFSET_MAX)
  722. return nfserr_inval;
  723. nfs4_lock_state();
  724. status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp);
  725. if (filp)
  726. get_file(filp);
  727. nfs4_unlock_state();
  728. if (status) {
  729. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  730. return status;
  731. }
  732. cnt = write->wr_buflen;
  733. write->wr_how_written = write->wr_stable_how;
  734. p = (u32 *)write->wr_verifier.data;
  735. *p++ = nfssvc_boot.tv_sec;
  736. *p++ = nfssvc_boot.tv_usec;
  737. status = nfsd_write(rqstp, &cstate->current_fh, filp,
  738. write->wr_offset, rqstp->rq_vec, write->wr_vlen,
  739. &cnt, &write->wr_how_written);
  740. if (filp)
  741. fput(filp);
  742. write->wr_bytes_written = cnt;
  743. if (status == nfserr_symlink)
  744. status = nfserr_inval;
  745. return status;
  746. }
  747. /* This routine never returns NFS_OK! If there are no other errors, it
  748. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  749. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  750. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  751. */
  752. static __be32
  753. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  754. struct nfsd4_verify *verify)
  755. {
  756. __be32 *buf, *p;
  757. int count;
  758. __be32 status;
  759. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  760. if (status)
  761. return status;
  762. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  763. if (status)
  764. return status;
  765. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  766. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  767. return nfserr_inval;
  768. if (verify->ve_attrlen & 3)
  769. return nfserr_inval;
  770. /* count in words:
  771. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  772. */
  773. count = 4 + (verify->ve_attrlen >> 2);
  774. buf = kmalloc(count << 2, GFP_KERNEL);
  775. if (!buf)
  776. return nfserr_resource;
  777. status = nfsd4_encode_fattr(&cstate->current_fh,
  778. cstate->current_fh.fh_export,
  779. cstate->current_fh.fh_dentry, buf,
  780. &count, verify->ve_bmval,
  781. rqstp, 0);
  782. /* this means that nfsd4_encode_fattr() ran out of space */
  783. if (status == nfserr_resource && count == 0)
  784. status = nfserr_not_same;
  785. if (status)
  786. goto out_kfree;
  787. /* skip bitmap */
  788. p = buf + 1 + ntohl(buf[0]);
  789. status = nfserr_not_same;
  790. if (ntohl(*p++) != verify->ve_attrlen)
  791. goto out_kfree;
  792. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  793. status = nfserr_same;
  794. out_kfree:
  795. kfree(buf);
  796. return status;
  797. }
  798. static __be32
  799. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  800. struct nfsd4_verify *verify)
  801. {
  802. __be32 status;
  803. status = _nfsd4_verify(rqstp, cstate, verify);
  804. return status == nfserr_not_same ? nfs_ok : status;
  805. }
  806. static __be32
  807. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  808. struct nfsd4_verify *verify)
  809. {
  810. __be32 status;
  811. status = _nfsd4_verify(rqstp, cstate, verify);
  812. return status == nfserr_same ? nfs_ok : status;
  813. }
  814. /*
  815. * NULL call.
  816. */
  817. static __be32
  818. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  819. {
  820. return nfs_ok;
  821. }
  822. static inline void nfsd4_increment_op_stats(u32 opnum)
  823. {
  824. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  825. nfsdstats.nfs4_opcount[opnum]++;
  826. }
  827. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  828. void *);
  829. enum nfsd4_op_flags {
  830. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  831. ALLOWED_ON_ABSENT_FS = 2 << 0, /* ops processed on absent fs */
  832. ALLOWED_AS_FIRST_OP = 3 << 0, /* ops reqired first in compound */
  833. };
  834. struct nfsd4_operation {
  835. nfsd4op_func op_func;
  836. u32 op_flags;
  837. char *op_name;
  838. };
  839. static struct nfsd4_operation nfsd4_ops[];
  840. static const char *nfsd4_op_name(unsigned opnum);
  841. /*
  842. * Enforce NFSv4.1 COMPOUND ordering rules.
  843. *
  844. * TODO:
  845. * - enforce NFS4ERR_NOT_ONLY_OP,
  846. * - DESTROY_SESSION MUST be the final operation in the COMPOUND request.
  847. */
  848. static bool nfs41_op_ordering_ok(struct nfsd4_compoundargs *args)
  849. {
  850. if (args->minorversion && args->opcnt > 0) {
  851. struct nfsd4_op *op = &args->ops[0];
  852. return (op->status == nfserr_op_illegal) ||
  853. (nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP);
  854. }
  855. return true;
  856. }
  857. /*
  858. * COMPOUND call.
  859. */
  860. static __be32
  861. nfsd4_proc_compound(struct svc_rqst *rqstp,
  862. struct nfsd4_compoundargs *args,
  863. struct nfsd4_compoundres *resp)
  864. {
  865. struct nfsd4_op *op;
  866. struct nfsd4_operation *opdesc;
  867. struct nfsd4_compound_state *cstate = &resp->cstate;
  868. int slack_bytes;
  869. __be32 status;
  870. resp->xbuf = &rqstp->rq_res;
  871. resp->p = rqstp->rq_res.head[0].iov_base +
  872. rqstp->rq_res.head[0].iov_len;
  873. resp->tagp = resp->p;
  874. /* reserve space for: taglen, tag, and opcnt */
  875. resp->p += 2 + XDR_QUADLEN(args->taglen);
  876. resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
  877. resp->taglen = args->taglen;
  878. resp->tag = args->tag;
  879. resp->opcnt = 0;
  880. resp->rqstp = rqstp;
  881. resp->cstate.minorversion = args->minorversion;
  882. resp->cstate.replay_owner = NULL;
  883. fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
  884. fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
  885. /* Use the deferral mechanism only for NFSv4.0 compounds */
  886. rqstp->rq_usedeferral = (args->minorversion == 0);
  887. /*
  888. * According to RFC3010, this takes precedence over all other errors.
  889. */
  890. status = nfserr_minor_vers_mismatch;
  891. if (args->minorversion > nfsd_supported_minorversion)
  892. goto out;
  893. if (!nfs41_op_ordering_ok(args)) {
  894. op = &args->ops[0];
  895. op->status = nfserr_sequence_pos;
  896. goto encode_op;
  897. }
  898. status = nfs_ok;
  899. while (!status && resp->opcnt < args->opcnt) {
  900. op = &args->ops[resp->opcnt++];
  901. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  902. resp->opcnt, args->opcnt, op->opnum,
  903. nfsd4_op_name(op->opnum));
  904. /*
  905. * The XDR decode routines may have pre-set op->status;
  906. * for example, if there is a miscellaneous XDR error
  907. * it will be set to nfserr_bad_xdr.
  908. */
  909. if (op->status)
  910. goto encode_op;
  911. /* We must be able to encode a successful response to
  912. * this operation, with enough room left over to encode a
  913. * failed response to the next operation. If we don't
  914. * have enough room, fail with ERR_RESOURCE.
  915. */
  916. slack_bytes = (char *)resp->end - (char *)resp->p;
  917. if (slack_bytes < COMPOUND_SLACK_SPACE
  918. + COMPOUND_ERR_SLACK_SPACE) {
  919. BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
  920. op->status = nfserr_resource;
  921. goto encode_op;
  922. }
  923. opdesc = &nfsd4_ops[op->opnum];
  924. if (!cstate->current_fh.fh_dentry) {
  925. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  926. op->status = nfserr_nofilehandle;
  927. goto encode_op;
  928. }
  929. } else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
  930. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  931. op->status = nfserr_moved;
  932. goto encode_op;
  933. }
  934. if (opdesc->op_func)
  935. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  936. else
  937. BUG_ON(op->status == nfs_ok);
  938. encode_op:
  939. /* Only from SEQUENCE */
  940. if (resp->cstate.status == nfserr_replay_cache) {
  941. dprintk("%s NFS4.1 replay from cache\n", __func__);
  942. status = op->status;
  943. goto out;
  944. }
  945. if (op->status == nfserr_replay_me) {
  946. op->replay = &cstate->replay_owner->so_replay;
  947. nfsd4_encode_replay(resp, op);
  948. status = op->status = op->replay->rp_status;
  949. } else {
  950. nfsd4_encode_operation(resp, op);
  951. status = op->status;
  952. }
  953. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  954. args->ops, args->opcnt, resp->opcnt, op->opnum,
  955. be32_to_cpu(status));
  956. if (cstate->replay_owner) {
  957. nfs4_put_stateowner(cstate->replay_owner);
  958. cstate->replay_owner = NULL;
  959. }
  960. /* XXX Ugh, we need to get rid of this kind of special case: */
  961. if (op->opnum == OP_READ && op->u.read.rd_filp)
  962. fput(op->u.read.rd_filp);
  963. nfsd4_increment_op_stats(op->opnum);
  964. }
  965. if (!rqstp->rq_usedeferral && status == nfserr_dropit) {
  966. dprintk("%s Dropit - send NFS4ERR_DELAY\n", __func__);
  967. status = nfserr_jukebox;
  968. }
  969. resp->cstate.status = status;
  970. fh_put(&resp->cstate.current_fh);
  971. fh_put(&resp->cstate.save_fh);
  972. BUG_ON(resp->cstate.replay_owner);
  973. out:
  974. nfsd4_release_compoundargs(args);
  975. /* Reset deferral mechanism for RPC deferrals */
  976. rqstp->rq_usedeferral = 1;
  977. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  978. return status;
  979. }
  980. static struct nfsd4_operation nfsd4_ops[] = {
  981. [OP_ACCESS] = {
  982. .op_func = (nfsd4op_func)nfsd4_access,
  983. .op_name = "OP_ACCESS",
  984. },
  985. [OP_CLOSE] = {
  986. .op_func = (nfsd4op_func)nfsd4_close,
  987. .op_name = "OP_CLOSE",
  988. },
  989. [OP_COMMIT] = {
  990. .op_func = (nfsd4op_func)nfsd4_commit,
  991. .op_name = "OP_COMMIT",
  992. },
  993. [OP_CREATE] = {
  994. .op_func = (nfsd4op_func)nfsd4_create,
  995. .op_name = "OP_CREATE",
  996. },
  997. [OP_DELEGRETURN] = {
  998. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  999. .op_name = "OP_DELEGRETURN",
  1000. },
  1001. [OP_GETATTR] = {
  1002. .op_func = (nfsd4op_func)nfsd4_getattr,
  1003. .op_flags = ALLOWED_ON_ABSENT_FS,
  1004. .op_name = "OP_GETATTR",
  1005. },
  1006. [OP_GETFH] = {
  1007. .op_func = (nfsd4op_func)nfsd4_getfh,
  1008. .op_name = "OP_GETFH",
  1009. },
  1010. [OP_LINK] = {
  1011. .op_func = (nfsd4op_func)nfsd4_link,
  1012. .op_name = "OP_LINK",
  1013. },
  1014. [OP_LOCK] = {
  1015. .op_func = (nfsd4op_func)nfsd4_lock,
  1016. .op_name = "OP_LOCK",
  1017. },
  1018. [OP_LOCKT] = {
  1019. .op_func = (nfsd4op_func)nfsd4_lockt,
  1020. .op_name = "OP_LOCKT",
  1021. },
  1022. [OP_LOCKU] = {
  1023. .op_func = (nfsd4op_func)nfsd4_locku,
  1024. .op_name = "OP_LOCKU",
  1025. },
  1026. [OP_LOOKUP] = {
  1027. .op_func = (nfsd4op_func)nfsd4_lookup,
  1028. .op_name = "OP_LOOKUP",
  1029. },
  1030. [OP_LOOKUPP] = {
  1031. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1032. .op_name = "OP_LOOKUPP",
  1033. },
  1034. [OP_NVERIFY] = {
  1035. .op_func = (nfsd4op_func)nfsd4_nverify,
  1036. .op_name = "OP_NVERIFY",
  1037. },
  1038. [OP_OPEN] = {
  1039. .op_func = (nfsd4op_func)nfsd4_open,
  1040. .op_name = "OP_OPEN",
  1041. },
  1042. [OP_OPEN_CONFIRM] = {
  1043. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1044. .op_name = "OP_OPEN_CONFIRM",
  1045. },
  1046. [OP_OPEN_DOWNGRADE] = {
  1047. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1048. .op_name = "OP_OPEN_DOWNGRADE",
  1049. },
  1050. [OP_PUTFH] = {
  1051. .op_func = (nfsd4op_func)nfsd4_putfh,
  1052. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1053. .op_name = "OP_PUTFH",
  1054. },
  1055. [OP_PUTPUBFH] = {
  1056. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1057. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1058. .op_name = "OP_PUTPUBFH",
  1059. },
  1060. [OP_PUTROOTFH] = {
  1061. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1062. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1063. .op_name = "OP_PUTROOTFH",
  1064. },
  1065. [OP_READ] = {
  1066. .op_func = (nfsd4op_func)nfsd4_read,
  1067. .op_name = "OP_READ",
  1068. },
  1069. [OP_READDIR] = {
  1070. .op_func = (nfsd4op_func)nfsd4_readdir,
  1071. .op_name = "OP_READDIR",
  1072. },
  1073. [OP_READLINK] = {
  1074. .op_func = (nfsd4op_func)nfsd4_readlink,
  1075. .op_name = "OP_READLINK",
  1076. },
  1077. [OP_REMOVE] = {
  1078. .op_func = (nfsd4op_func)nfsd4_remove,
  1079. .op_name = "OP_REMOVE",
  1080. },
  1081. [OP_RENAME] = {
  1082. .op_name = "OP_RENAME",
  1083. .op_func = (nfsd4op_func)nfsd4_rename,
  1084. },
  1085. [OP_RENEW] = {
  1086. .op_func = (nfsd4op_func)nfsd4_renew,
  1087. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1088. .op_name = "OP_RENEW",
  1089. },
  1090. [OP_RESTOREFH] = {
  1091. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1092. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1093. .op_name = "OP_RESTOREFH",
  1094. },
  1095. [OP_SAVEFH] = {
  1096. .op_func = (nfsd4op_func)nfsd4_savefh,
  1097. .op_name = "OP_SAVEFH",
  1098. },
  1099. [OP_SECINFO] = {
  1100. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1101. .op_name = "OP_SECINFO",
  1102. },
  1103. [OP_SETATTR] = {
  1104. .op_func = (nfsd4op_func)nfsd4_setattr,
  1105. .op_name = "OP_SETATTR",
  1106. },
  1107. [OP_SETCLIENTID] = {
  1108. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1109. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1110. .op_name = "OP_SETCLIENTID",
  1111. },
  1112. [OP_SETCLIENTID_CONFIRM] = {
  1113. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1114. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1115. .op_name = "OP_SETCLIENTID_CONFIRM",
  1116. },
  1117. [OP_VERIFY] = {
  1118. .op_func = (nfsd4op_func)nfsd4_verify,
  1119. .op_name = "OP_VERIFY",
  1120. },
  1121. [OP_WRITE] = {
  1122. .op_func = (nfsd4op_func)nfsd4_write,
  1123. .op_name = "OP_WRITE",
  1124. },
  1125. [OP_RELEASE_LOCKOWNER] = {
  1126. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1127. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1128. .op_name = "OP_RELEASE_LOCKOWNER",
  1129. },
  1130. /* NFSv4.1 operations */
  1131. [OP_EXCHANGE_ID] = {
  1132. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1133. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1134. .op_name = "OP_EXCHANGE_ID",
  1135. },
  1136. [OP_CREATE_SESSION] = {
  1137. .op_func = (nfsd4op_func)nfsd4_create_session,
  1138. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1139. .op_name = "OP_CREATE_SESSION",
  1140. },
  1141. [OP_DESTROY_SESSION] = {
  1142. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1143. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1144. .op_name = "OP_DESTROY_SESSION",
  1145. },
  1146. [OP_SEQUENCE] = {
  1147. .op_func = (nfsd4op_func)nfsd4_sequence,
  1148. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1149. .op_name = "OP_SEQUENCE",
  1150. },
  1151. };
  1152. static const char *nfsd4_op_name(unsigned opnum)
  1153. {
  1154. if (opnum < ARRAY_SIZE(nfsd4_ops))
  1155. return nfsd4_ops[opnum].op_name;
  1156. return "unknown_operation";
  1157. }
  1158. #define nfsd4_voidres nfsd4_voidargs
  1159. struct nfsd4_voidargs { int dummy; };
  1160. /*
  1161. * TODO: At the present time, the NFSv4 server does not do XID caching
  1162. * of requests. Implementing XID caching would not be a serious problem,
  1163. * although it would require a mild change in interfaces since one
  1164. * doesn't know whether an NFSv4 request is idempotent until after the
  1165. * XDR decode. However, XID caching totally confuses pynfs (Peter
  1166. * Astrand's regression testsuite for NFSv4 servers), which reuses
  1167. * XID's liberally, so I've left it unimplemented until pynfs generates
  1168. * better XID's.
  1169. */
  1170. static struct svc_procedure nfsd_procedures4[2] = {
  1171. [NFSPROC4_NULL] = {
  1172. .pc_func = (svc_procfunc) nfsd4_proc_null,
  1173. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  1174. .pc_argsize = sizeof(struct nfsd4_voidargs),
  1175. .pc_ressize = sizeof(struct nfsd4_voidres),
  1176. .pc_cachetype = RC_NOCACHE,
  1177. .pc_xdrressize = 1,
  1178. },
  1179. [NFSPROC4_COMPOUND] = {
  1180. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  1181. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  1182. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  1183. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  1184. .pc_ressize = sizeof(struct nfsd4_compoundres),
  1185. .pc_cachetype = RC_NOCACHE,
  1186. .pc_xdrressize = NFSD_BUFSIZE/4,
  1187. },
  1188. };
  1189. struct svc_version nfsd_version4 = {
  1190. .vs_vers = 4,
  1191. .vs_nproc = 2,
  1192. .vs_proc = nfsd_procedures4,
  1193. .vs_dispatch = nfsd_dispatch,
  1194. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  1195. };
  1196. /*
  1197. * Local variables:
  1198. * c-basic-offset: 8
  1199. * End:
  1200. */