nfs4proc.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /*
  2. * Server-side procedures for NFSv4.
  3. *
  4. * Copyright (c) 2002 The Regents of the University of Michigan.
  5. * All rights reserved.
  6. *
  7. * Kendrick Smith <kmsmith@umich.edu>
  8. * Andy Adamson <andros@umich.edu>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <linux/file.h>
  36. #include <linux/slab.h>
  37. #include "idmap.h"
  38. #include "cache.h"
  39. #include "xdr4.h"
  40. #include "vfs.h"
  41. #define NFSDDBG_FACILITY NFSDDBG_PROC
  42. static u32 nfsd_attrmask[] = {
  43. NFSD_WRITEABLE_ATTRS_WORD0,
  44. NFSD_WRITEABLE_ATTRS_WORD1,
  45. NFSD_WRITEABLE_ATTRS_WORD2
  46. };
  47. static u32 nfsd41_ex_attrmask[] = {
  48. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  49. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  50. NFSD_SUPPATTR_EXCLCREAT_WORD2
  51. };
  52. static __be32
  53. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  54. u32 *bmval, u32 *writable)
  55. {
  56. struct dentry *dentry = cstate->current_fh.fh_dentry;
  57. /*
  58. * Check about attributes are supported by the NFSv4 server or not.
  59. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
  60. */
  61. if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
  62. (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
  63. (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
  64. return nfserr_attrnotsupp;
  65. /*
  66. * Check FATTR4_WORD0_ACL can be supported
  67. * in current environment or not.
  68. */
  69. if (bmval[0] & FATTR4_WORD0_ACL) {
  70. if (!IS_POSIXACL(dentry->d_inode))
  71. return nfserr_attrnotsupp;
  72. }
  73. /*
  74. * According to spec, read-only attributes return ERR_INVAL.
  75. */
  76. if (writable) {
  77. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  78. (bmval[2] & ~writable[2]))
  79. return nfserr_inval;
  80. }
  81. return nfs_ok;
  82. }
  83. static __be32
  84. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  85. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  86. {
  87. __be32 status = nfs_ok;
  88. if (open->op_create == NFS4_OPEN_CREATE) {
  89. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  90. || open->op_createmode == NFS4_CREATE_GUARDED)
  91. status = check_attr_support(rqstp, cstate,
  92. open->op_bmval, nfsd_attrmask);
  93. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  94. status = check_attr_support(rqstp, cstate,
  95. open->op_bmval, nfsd41_ex_attrmask);
  96. }
  97. return status;
  98. }
  99. static int
  100. is_create_with_attrs(struct nfsd4_open *open)
  101. {
  102. return open->op_create == NFS4_OPEN_CREATE
  103. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  104. || open->op_createmode == NFS4_CREATE_GUARDED
  105. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  106. }
  107. /*
  108. * if error occurs when setting the acl, just clear the acl bit
  109. * in the returned attr bitmap.
  110. */
  111. static void
  112. do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
  113. struct nfs4_acl *acl, u32 *bmval)
  114. {
  115. __be32 status;
  116. status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
  117. if (status)
  118. /*
  119. * We should probably fail the whole open at this point,
  120. * but we've already created the file, so it's too late;
  121. * So this seems the least of evils:
  122. */
  123. bmval[0] &= ~FATTR4_WORD0_ACL;
  124. }
  125. static inline void
  126. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  127. {
  128. fh_put(dst);
  129. dget(src->fh_dentry);
  130. if (src->fh_export)
  131. cache_get(&src->fh_export->h);
  132. *dst = *src;
  133. }
  134. static __be32
  135. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  136. {
  137. __be32 status;
  138. if (open->op_truncate &&
  139. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  140. return nfserr_inval;
  141. accmode |= NFSD_MAY_READ_IF_EXEC;
  142. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  143. accmode |= NFSD_MAY_READ;
  144. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  145. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  146. if (open->op_share_deny & NFS4_SHARE_DENY_READ)
  147. accmode |= NFSD_MAY_WRITE;
  148. status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
  149. return status;
  150. }
  151. static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
  152. {
  153. umode_t mode = fh->fh_dentry->d_inode->i_mode;
  154. if (S_ISREG(mode))
  155. return nfs_ok;
  156. if (S_ISDIR(mode))
  157. return nfserr_isdir;
  158. /*
  159. * Using err_symlink as our catch-all case may look odd; but
  160. * there's no other obvious error for this case in 4.0, and we
  161. * happen to know that it will cause the linux v4 client to do
  162. * the right thing on attempts to open something other than a
  163. * regular file.
  164. */
  165. return nfserr_symlink;
  166. }
  167. static __be32
  168. do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  169. {
  170. struct svc_fh resfh;
  171. __be32 status;
  172. fh_init(&resfh, NFS4_FHSIZE);
  173. open->op_truncate = 0;
  174. if (open->op_create) {
  175. /* FIXME: check session persistence and pnfs flags.
  176. * The nfsv4.1 spec requires the following semantics:
  177. *
  178. * Persistent | pNFS | Server REQUIRED | Client Allowed
  179. * Reply Cache | server | |
  180. * -------------+--------+-----------------+--------------------
  181. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  182. * | | | (SHOULD)
  183. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  184. * | | | (SHOULD NOT)
  185. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  186. * yes | no | GUARDED4 | GUARDED4
  187. * yes | yes | GUARDED4 | GUARDED4
  188. */
  189. /*
  190. * Note: create modes (UNCHECKED,GUARDED...) are the same
  191. * in NFSv4 as in v3 except EXCLUSIVE4_1.
  192. */
  193. status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
  194. open->op_fname.len, &open->op_iattr,
  195. &resfh, open->op_createmode,
  196. (u32 *)open->op_verf.data,
  197. &open->op_truncate, &open->op_created);
  198. /*
  199. * Following rfc 3530 14.2.16, use the returned bitmask
  200. * to indicate which attributes we used to store the
  201. * verifier:
  202. */
  203. if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
  204. open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
  205. FATTR4_WORD1_TIME_MODIFY);
  206. } else {
  207. status = nfsd_lookup(rqstp, current_fh,
  208. open->op_fname.data, open->op_fname.len, &resfh);
  209. fh_unlock(current_fh);
  210. if (status)
  211. goto out;
  212. status = nfsd_check_obj_isreg(&resfh);
  213. }
  214. if (status)
  215. goto out;
  216. if (is_create_with_attrs(open) && open->op_acl != NULL)
  217. do_set_nfs4_acl(rqstp, &resfh, open->op_acl, open->op_bmval);
  218. set_change_info(&open->op_cinfo, current_fh);
  219. fh_dup2(current_fh, &resfh);
  220. /* set reply cache */
  221. fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
  222. &resfh.fh_handle);
  223. if (!open->op_created)
  224. status = do_open_permission(rqstp, current_fh, open,
  225. NFSD_MAY_NOP);
  226. out:
  227. fh_put(&resfh);
  228. return status;
  229. }
  230. static __be32
  231. do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  232. {
  233. __be32 status;
  234. /* We don't know the target directory, and therefore can not
  235. * set the change info
  236. */
  237. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  238. /* set replay cache */
  239. fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
  240. &current_fh->fh_handle);
  241. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  242. (open->op_iattr.ia_size == 0);
  243. status = do_open_permission(rqstp, current_fh, open,
  244. NFSD_MAY_OWNER_OVERRIDE);
  245. return status;
  246. }
  247. static void
  248. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  249. {
  250. struct nfsd4_sessionid *sid =
  251. (struct nfsd4_sessionid *)session->se_sessionid.data;
  252. clid->cl_boot = sid->clientid.cl_boot;
  253. clid->cl_id = sid->clientid.cl_id;
  254. }
  255. static __be32
  256. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  257. struct nfsd4_open *open)
  258. {
  259. __be32 status;
  260. struct nfsd4_compoundres *resp;
  261. dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
  262. (int)open->op_fname.len, open->op_fname.data,
  263. open->op_openowner);
  264. /* This check required by spec. */
  265. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  266. return nfserr_inval;
  267. /* We don't yet support WANT bits: */
  268. open->op_share_access &= NFS4_SHARE_ACCESS_MASK;
  269. open->op_created = 0;
  270. /*
  271. * RFC5661 18.51.3
  272. * Before RECLAIM_COMPLETE done, server should deny new lock
  273. */
  274. if (nfsd4_has_session(cstate) &&
  275. !cstate->session->se_client->cl_firststate &&
  276. open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  277. return nfserr_grace;
  278. if (nfsd4_has_session(cstate))
  279. copy_clientid(&open->op_clientid, cstate->session);
  280. nfs4_lock_state();
  281. /* check seqid for replay. set nfs4_owner */
  282. resp = rqstp->rq_resp;
  283. status = nfsd4_process_open1(&resp->cstate, open);
  284. if (status == nfserr_replay_me) {
  285. struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
  286. fh_put(&cstate->current_fh);
  287. fh_copy_shallow(&cstate->current_fh.fh_handle,
  288. &rp->rp_openfh);
  289. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  290. if (status)
  291. dprintk("nfsd4_open: replay failed"
  292. " restoring previous filehandle\n");
  293. else
  294. status = nfserr_replay_me;
  295. }
  296. if (status)
  297. goto out;
  298. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  299. if (status)
  300. goto out;
  301. /* Openowner is now set, so sequence id will get bumped. Now we need
  302. * these checks before we do any creates: */
  303. status = nfserr_grace;
  304. if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  305. goto out;
  306. status = nfserr_no_grace;
  307. if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  308. goto out;
  309. switch (open->op_claim_type) {
  310. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  311. case NFS4_OPEN_CLAIM_NULL:
  312. status = do_open_lookup(rqstp, &cstate->current_fh,
  313. open);
  314. if (status)
  315. goto out;
  316. break;
  317. case NFS4_OPEN_CLAIM_PREVIOUS:
  318. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  319. status = nfs4_check_open_reclaim(&open->op_clientid);
  320. if (status)
  321. goto out;
  322. case NFS4_OPEN_CLAIM_FH:
  323. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  324. status = do_open_fhandle(rqstp, &cstate->current_fh,
  325. open);
  326. if (status)
  327. goto out;
  328. break;
  329. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  330. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  331. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  332. dprintk("NFSD: unsupported OPEN claim type %d\n",
  333. open->op_claim_type);
  334. status = nfserr_notsupp;
  335. goto out;
  336. default:
  337. dprintk("NFSD: Invalid OPEN claim type %d\n",
  338. open->op_claim_type);
  339. status = nfserr_inval;
  340. goto out;
  341. }
  342. /*
  343. * nfsd4_process_open2() does the actual opening of the file. If
  344. * successful, it (1) truncates the file if open->op_truncate was
  345. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  346. */
  347. status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
  348. WARN_ON(status && open->op_created);
  349. out:
  350. nfsd4_cleanup_open_state(open, status);
  351. if (open->op_openowner)
  352. cstate->replay_owner = &open->op_openowner->oo_owner;
  353. else
  354. nfs4_unlock_state();
  355. return status;
  356. }
  357. /*
  358. * filehandle-manipulating ops.
  359. */
  360. static __be32
  361. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  362. struct svc_fh **getfh)
  363. {
  364. if (!cstate->current_fh.fh_dentry)
  365. return nfserr_nofilehandle;
  366. *getfh = &cstate->current_fh;
  367. return nfs_ok;
  368. }
  369. static __be32
  370. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  371. struct nfsd4_putfh *putfh)
  372. {
  373. fh_put(&cstate->current_fh);
  374. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  375. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  376. putfh->pf_fhlen);
  377. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
  378. }
  379. static __be32
  380. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  381. void *arg)
  382. {
  383. __be32 status;
  384. fh_put(&cstate->current_fh);
  385. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  386. return status;
  387. }
  388. static __be32
  389. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  390. void *arg)
  391. {
  392. if (!cstate->save_fh.fh_dentry)
  393. return nfserr_restorefh;
  394. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  395. return nfs_ok;
  396. }
  397. static __be32
  398. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  399. void *arg)
  400. {
  401. if (!cstate->current_fh.fh_dentry)
  402. return nfserr_nofilehandle;
  403. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  404. return nfs_ok;
  405. }
  406. /*
  407. * misc nfsv4 ops
  408. */
  409. static __be32
  410. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  411. struct nfsd4_access *access)
  412. {
  413. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  414. return nfserr_inval;
  415. access->ac_resp_access = access->ac_req_access;
  416. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  417. &access->ac_supported);
  418. }
  419. static __be32
  420. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  421. struct nfsd4_commit *commit)
  422. {
  423. u32 *p = (u32 *)commit->co_verf.data;
  424. *p++ = nfssvc_boot.tv_sec;
  425. *p++ = nfssvc_boot.tv_usec;
  426. return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
  427. commit->co_count);
  428. }
  429. static __be32
  430. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  431. struct nfsd4_create *create)
  432. {
  433. struct svc_fh resfh;
  434. __be32 status;
  435. dev_t rdev;
  436. fh_init(&resfh, NFS4_FHSIZE);
  437. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
  438. NFSD_MAY_CREATE);
  439. if (status)
  440. return status;
  441. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  442. nfsd_attrmask);
  443. if (status)
  444. return status;
  445. switch (create->cr_type) {
  446. case NF4LNK:
  447. /* ugh! we have to null-terminate the linktext, or
  448. * vfs_symlink() will choke. it is always safe to
  449. * null-terminate by brute force, since at worst we
  450. * will overwrite the first byte of the create namelen
  451. * in the XDR buffer, which has already been extracted
  452. * during XDR decode.
  453. */
  454. create->cr_linkname[create->cr_linklen] = 0;
  455. status = nfsd_symlink(rqstp, &cstate->current_fh,
  456. create->cr_name, create->cr_namelen,
  457. create->cr_linkname, create->cr_linklen,
  458. &resfh, &create->cr_iattr);
  459. break;
  460. case NF4BLK:
  461. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  462. if (MAJOR(rdev) != create->cr_specdata1 ||
  463. MINOR(rdev) != create->cr_specdata2)
  464. return nfserr_inval;
  465. status = nfsd_create(rqstp, &cstate->current_fh,
  466. create->cr_name, create->cr_namelen,
  467. &create->cr_iattr, S_IFBLK, rdev, &resfh);
  468. break;
  469. case NF4CHR:
  470. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  471. if (MAJOR(rdev) != create->cr_specdata1 ||
  472. MINOR(rdev) != create->cr_specdata2)
  473. return nfserr_inval;
  474. status = nfsd_create(rqstp, &cstate->current_fh,
  475. create->cr_name, create->cr_namelen,
  476. &create->cr_iattr,S_IFCHR, rdev, &resfh);
  477. break;
  478. case NF4SOCK:
  479. status = nfsd_create(rqstp, &cstate->current_fh,
  480. create->cr_name, create->cr_namelen,
  481. &create->cr_iattr, S_IFSOCK, 0, &resfh);
  482. break;
  483. case NF4FIFO:
  484. status = nfsd_create(rqstp, &cstate->current_fh,
  485. create->cr_name, create->cr_namelen,
  486. &create->cr_iattr, S_IFIFO, 0, &resfh);
  487. break;
  488. case NF4DIR:
  489. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  490. status = nfsd_create(rqstp, &cstate->current_fh,
  491. create->cr_name, create->cr_namelen,
  492. &create->cr_iattr, S_IFDIR, 0, &resfh);
  493. break;
  494. default:
  495. status = nfserr_badtype;
  496. }
  497. if (status)
  498. goto out;
  499. if (create->cr_acl != NULL)
  500. do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
  501. create->cr_bmval);
  502. fh_unlock(&cstate->current_fh);
  503. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  504. fh_dup2(&cstate->current_fh, &resfh);
  505. out:
  506. fh_put(&resfh);
  507. return status;
  508. }
  509. static __be32
  510. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  511. struct nfsd4_getattr *getattr)
  512. {
  513. __be32 status;
  514. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  515. if (status)
  516. return status;
  517. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  518. return nfserr_inval;
  519. getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  520. getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  521. getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  522. getattr->ga_fhp = &cstate->current_fh;
  523. return nfs_ok;
  524. }
  525. static __be32
  526. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  527. struct nfsd4_link *link)
  528. {
  529. __be32 status = nfserr_nofilehandle;
  530. if (!cstate->save_fh.fh_dentry)
  531. return status;
  532. status = nfsd_link(rqstp, &cstate->current_fh,
  533. link->li_name, link->li_namelen, &cstate->save_fh);
  534. if (!status)
  535. set_change_info(&link->li_cinfo, &cstate->current_fh);
  536. return status;
  537. }
  538. static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
  539. {
  540. struct svc_fh tmp_fh;
  541. __be32 ret;
  542. fh_init(&tmp_fh, NFS4_FHSIZE);
  543. ret = exp_pseudoroot(rqstp, &tmp_fh);
  544. if (ret)
  545. return ret;
  546. if (tmp_fh.fh_dentry == fh->fh_dentry) {
  547. fh_put(&tmp_fh);
  548. return nfserr_noent;
  549. }
  550. fh_put(&tmp_fh);
  551. return nfsd_lookup(rqstp, fh, "..", 2, fh);
  552. }
  553. static __be32
  554. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  555. void *arg)
  556. {
  557. return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  558. }
  559. static __be32
  560. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  561. struct nfsd4_lookup *lookup)
  562. {
  563. return nfsd_lookup(rqstp, &cstate->current_fh,
  564. lookup->lo_name, lookup->lo_len,
  565. &cstate->current_fh);
  566. }
  567. static __be32
  568. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  569. struct nfsd4_read *read)
  570. {
  571. __be32 status;
  572. /* no need to check permission - this will be done in nfsd_read() */
  573. read->rd_filp = NULL;
  574. if (read->rd_offset >= OFFSET_MAX)
  575. return nfserr_inval;
  576. nfs4_lock_state();
  577. /* check stateid */
  578. if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid,
  579. RD_STATE, &read->rd_filp))) {
  580. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  581. goto out;
  582. }
  583. if (read->rd_filp)
  584. get_file(read->rd_filp);
  585. status = nfs_ok;
  586. out:
  587. nfs4_unlock_state();
  588. read->rd_rqstp = rqstp;
  589. read->rd_fhp = &cstate->current_fh;
  590. return status;
  591. }
  592. static __be32
  593. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  594. struct nfsd4_readdir *readdir)
  595. {
  596. u64 cookie = readdir->rd_cookie;
  597. static const nfs4_verifier zeroverf;
  598. /* no need to check permission - this will be done in nfsd_readdir() */
  599. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  600. return nfserr_inval;
  601. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  602. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  603. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  604. if ((cookie == 1) || (cookie == 2) ||
  605. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  606. return nfserr_bad_cookie;
  607. readdir->rd_rqstp = rqstp;
  608. readdir->rd_fhp = &cstate->current_fh;
  609. return nfs_ok;
  610. }
  611. static __be32
  612. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  613. struct nfsd4_readlink *readlink)
  614. {
  615. readlink->rl_rqstp = rqstp;
  616. readlink->rl_fhp = &cstate->current_fh;
  617. return nfs_ok;
  618. }
  619. static __be32
  620. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  621. struct nfsd4_remove *remove)
  622. {
  623. __be32 status;
  624. if (locks_in_grace())
  625. return nfserr_grace;
  626. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  627. remove->rm_name, remove->rm_namelen);
  628. if (!status) {
  629. fh_unlock(&cstate->current_fh);
  630. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  631. }
  632. return status;
  633. }
  634. static __be32
  635. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  636. struct nfsd4_rename *rename)
  637. {
  638. __be32 status = nfserr_nofilehandle;
  639. if (!cstate->save_fh.fh_dentry)
  640. return status;
  641. if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
  642. & NFSEXP_NOSUBTREECHECK))
  643. return nfserr_grace;
  644. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  645. rename->rn_snamelen, &cstate->current_fh,
  646. rename->rn_tname, rename->rn_tnamelen);
  647. /* the underlying filesystem returns different error's than required
  648. * by NFSv4. both save_fh and current_fh have been verified.. */
  649. if (status == nfserr_isdir)
  650. status = nfserr_exist;
  651. else if ((status == nfserr_notdir) &&
  652. (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) &&
  653. S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode)))
  654. status = nfserr_exist;
  655. if (!status) {
  656. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  657. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  658. }
  659. return status;
  660. }
  661. static __be32
  662. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  663. struct nfsd4_secinfo *secinfo)
  664. {
  665. struct svc_fh resfh;
  666. struct svc_export *exp;
  667. struct dentry *dentry;
  668. __be32 err;
  669. fh_init(&resfh, NFS4_FHSIZE);
  670. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  671. if (err)
  672. return err;
  673. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  674. secinfo->si_name, secinfo->si_namelen,
  675. &exp, &dentry);
  676. if (err)
  677. return err;
  678. if (dentry->d_inode == NULL) {
  679. exp_put(exp);
  680. err = nfserr_noent;
  681. } else
  682. secinfo->si_exp = exp;
  683. dput(dentry);
  684. if (cstate->minorversion)
  685. /* See rfc 5661 section 2.6.3.1.1.8 */
  686. fh_put(&cstate->current_fh);
  687. return err;
  688. }
  689. static __be32
  690. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  691. struct nfsd4_secinfo_no_name *sin)
  692. {
  693. __be32 err;
  694. switch (sin->sin_style) {
  695. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  696. break;
  697. case NFS4_SECINFO_STYLE4_PARENT:
  698. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  699. if (err)
  700. return err;
  701. break;
  702. default:
  703. return nfserr_inval;
  704. }
  705. exp_get(cstate->current_fh.fh_export);
  706. sin->sin_exp = cstate->current_fh.fh_export;
  707. fh_put(&cstate->current_fh);
  708. return nfs_ok;
  709. }
  710. static __be32
  711. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  712. struct nfsd4_setattr *setattr)
  713. {
  714. __be32 status = nfs_ok;
  715. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  716. nfs4_lock_state();
  717. status = nfs4_preprocess_stateid_op(cstate,
  718. &setattr->sa_stateid, WR_STATE, NULL);
  719. nfs4_unlock_state();
  720. if (status) {
  721. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  722. return status;
  723. }
  724. }
  725. status = fh_want_write(&cstate->current_fh);
  726. if (status)
  727. return status;
  728. status = nfs_ok;
  729. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  730. nfsd_attrmask);
  731. if (status)
  732. goto out;
  733. if (setattr->sa_acl != NULL)
  734. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  735. setattr->sa_acl);
  736. if (status)
  737. goto out;
  738. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  739. 0, (time_t)0);
  740. out:
  741. fh_drop_write(&cstate->current_fh);
  742. return status;
  743. }
  744. static __be32
  745. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  746. struct nfsd4_write *write)
  747. {
  748. stateid_t *stateid = &write->wr_stateid;
  749. struct file *filp = NULL;
  750. u32 *p;
  751. __be32 status = nfs_ok;
  752. unsigned long cnt;
  753. /* no need to check permission - this will be done in nfsd_write() */
  754. if (write->wr_offset >= OFFSET_MAX)
  755. return nfserr_inval;
  756. nfs4_lock_state();
  757. status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp);
  758. if (filp)
  759. get_file(filp);
  760. nfs4_unlock_state();
  761. if (status) {
  762. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  763. return status;
  764. }
  765. cnt = write->wr_buflen;
  766. write->wr_how_written = write->wr_stable_how;
  767. p = (u32 *)write->wr_verifier.data;
  768. *p++ = nfssvc_boot.tv_sec;
  769. *p++ = nfssvc_boot.tv_usec;
  770. status = nfsd_write(rqstp, &cstate->current_fh, filp,
  771. write->wr_offset, rqstp->rq_vec, write->wr_vlen,
  772. &cnt, &write->wr_how_written);
  773. if (filp)
  774. fput(filp);
  775. write->wr_bytes_written = cnt;
  776. return status;
  777. }
  778. /* This routine never returns NFS_OK! If there are no other errors, it
  779. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  780. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  781. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  782. */
  783. static __be32
  784. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  785. struct nfsd4_verify *verify)
  786. {
  787. __be32 *buf, *p;
  788. int count;
  789. __be32 status;
  790. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  791. if (status)
  792. return status;
  793. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  794. if (status)
  795. return status;
  796. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  797. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  798. return nfserr_inval;
  799. if (verify->ve_attrlen & 3)
  800. return nfserr_inval;
  801. /* count in words:
  802. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  803. */
  804. count = 4 + (verify->ve_attrlen >> 2);
  805. buf = kmalloc(count << 2, GFP_KERNEL);
  806. if (!buf)
  807. return nfserr_jukebox;
  808. status = nfsd4_encode_fattr(&cstate->current_fh,
  809. cstate->current_fh.fh_export,
  810. cstate->current_fh.fh_dentry, buf,
  811. &count, verify->ve_bmval,
  812. rqstp, 0);
  813. /* this means that nfsd4_encode_fattr() ran out of space */
  814. if (status == nfserr_resource && count == 0)
  815. status = nfserr_not_same;
  816. if (status)
  817. goto out_kfree;
  818. /* skip bitmap */
  819. p = buf + 1 + ntohl(buf[0]);
  820. status = nfserr_not_same;
  821. if (ntohl(*p++) != verify->ve_attrlen)
  822. goto out_kfree;
  823. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  824. status = nfserr_same;
  825. out_kfree:
  826. kfree(buf);
  827. return status;
  828. }
  829. static __be32
  830. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  831. struct nfsd4_verify *verify)
  832. {
  833. __be32 status;
  834. status = _nfsd4_verify(rqstp, cstate, verify);
  835. return status == nfserr_not_same ? nfs_ok : status;
  836. }
  837. static __be32
  838. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  839. struct nfsd4_verify *verify)
  840. {
  841. __be32 status;
  842. status = _nfsd4_verify(rqstp, cstate, verify);
  843. return status == nfserr_same ? nfs_ok : status;
  844. }
  845. /*
  846. * NULL call.
  847. */
  848. static __be32
  849. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  850. {
  851. return nfs_ok;
  852. }
  853. static inline void nfsd4_increment_op_stats(u32 opnum)
  854. {
  855. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  856. nfsdstats.nfs4_opcount[opnum]++;
  857. }
  858. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  859. void *);
  860. typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
  861. enum nfsd4_op_flags {
  862. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  863. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  864. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  865. /* For rfc 5661 section 2.6.3.1.1: */
  866. OP_HANDLES_WRONGSEC = 1 << 3,
  867. OP_IS_PUTFH_LIKE = 1 << 4,
  868. /*
  869. * These are the ops whose result size we estimate before
  870. * encoding, to avoid performing an op then not being able to
  871. * respond or cache a response. This includes writes and setattrs
  872. * as well as the operations usually called "nonidempotent":
  873. */
  874. OP_MODIFIES_SOMETHING = 1 << 5,
  875. /*
  876. * Cache compounds containing these ops in the xid-based drc:
  877. * We use the DRC for compounds containing non-idempotent
  878. * operations, *except* those that are 4.1-specific (since
  879. * sessions provide their own EOS), and except for stateful
  880. * operations other than setclientid and setclientid_confirm
  881. * (since sequence numbers provide EOS for open, lock, etc in
  882. * the v4.0 case).
  883. */
  884. OP_CACHEME = 1 << 6,
  885. };
  886. struct nfsd4_operation {
  887. nfsd4op_func op_func;
  888. u32 op_flags;
  889. char *op_name;
  890. /* Try to get response size before operation */
  891. nfsd4op_rsize op_rsize_bop;
  892. };
  893. static struct nfsd4_operation nfsd4_ops[];
  894. static const char *nfsd4_op_name(unsigned opnum);
  895. /*
  896. * Enforce NFSv4.1 COMPOUND ordering rules:
  897. *
  898. * Also note, enforced elsewhere:
  899. * - SEQUENCE other than as first op results in
  900. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  901. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  902. * (Enforced in nfsd4_bind_conn_to_session().)
  903. * - DESTROY_SESSION must be the final operation in a compound, if
  904. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  905. * (Enforced in nfsd4_destroy_session().)
  906. */
  907. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  908. {
  909. struct nfsd4_op *op = &args->ops[0];
  910. /* These ordering requirements don't apply to NFSv4.0: */
  911. if (args->minorversion == 0)
  912. return nfs_ok;
  913. /* This is weird, but OK, not our problem: */
  914. if (args->opcnt == 0)
  915. return nfs_ok;
  916. if (op->status == nfserr_op_illegal)
  917. return nfs_ok;
  918. if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  919. return nfserr_op_not_in_session;
  920. if (op->opnum == OP_SEQUENCE)
  921. return nfs_ok;
  922. if (args->opcnt != 1)
  923. return nfserr_not_only_op;
  924. return nfs_ok;
  925. }
  926. static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  927. {
  928. return &nfsd4_ops[op->opnum];
  929. }
  930. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  931. {
  932. return OPDESC(op)->op_flags & OP_CACHEME;
  933. }
  934. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  935. {
  936. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  937. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  938. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  939. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  940. struct nfsd4_operation *thisd;
  941. struct nfsd4_operation *nextd;
  942. thisd = OPDESC(this);
  943. /*
  944. * Most ops check wronsec on our own; only the putfh-like ops
  945. * have special rules.
  946. */
  947. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  948. return false;
  949. /*
  950. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  951. * put-filehandle operation if we're not going to use the
  952. * result:
  953. */
  954. if (argp->opcnt == resp->opcnt)
  955. return false;
  956. nextd = OPDESC(next);
  957. /*
  958. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  959. * errors themselves as necessary; others should check for them
  960. * now:
  961. */
  962. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  963. }
  964. /*
  965. * COMPOUND call.
  966. */
  967. static __be32
  968. nfsd4_proc_compound(struct svc_rqst *rqstp,
  969. struct nfsd4_compoundargs *args,
  970. struct nfsd4_compoundres *resp)
  971. {
  972. struct nfsd4_op *op;
  973. struct nfsd4_operation *opdesc;
  974. struct nfsd4_compound_state *cstate = &resp->cstate;
  975. int slack_bytes;
  976. u32 plen = 0;
  977. __be32 status;
  978. resp->xbuf = &rqstp->rq_res;
  979. resp->p = rqstp->rq_res.head[0].iov_base +
  980. rqstp->rq_res.head[0].iov_len;
  981. resp->tagp = resp->p;
  982. /* reserve space for: taglen, tag, and opcnt */
  983. resp->p += 2 + XDR_QUADLEN(args->taglen);
  984. resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
  985. resp->taglen = args->taglen;
  986. resp->tag = args->tag;
  987. resp->opcnt = 0;
  988. resp->rqstp = rqstp;
  989. resp->cstate.minorversion = args->minorversion;
  990. resp->cstate.replay_owner = NULL;
  991. resp->cstate.session = NULL;
  992. fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
  993. fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
  994. /*
  995. * Don't use the deferral mechanism for NFSv4; compounds make it
  996. * too hard to avoid non-idempotency problems.
  997. */
  998. rqstp->rq_usedeferral = 0;
  999. /*
  1000. * According to RFC3010, this takes precedence over all other errors.
  1001. */
  1002. status = nfserr_minor_vers_mismatch;
  1003. if (args->minorversion > nfsd_supported_minorversion)
  1004. goto out;
  1005. status = nfs41_check_op_ordering(args);
  1006. if (status) {
  1007. op = &args->ops[0];
  1008. op->status = status;
  1009. goto encode_op;
  1010. }
  1011. while (!status && resp->opcnt < args->opcnt) {
  1012. op = &args->ops[resp->opcnt++];
  1013. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  1014. resp->opcnt, args->opcnt, op->opnum,
  1015. nfsd4_op_name(op->opnum));
  1016. /*
  1017. * The XDR decode routines may have pre-set op->status;
  1018. * for example, if there is a miscellaneous XDR error
  1019. * it will be set to nfserr_bad_xdr.
  1020. */
  1021. if (op->status)
  1022. goto encode_op;
  1023. /* We must be able to encode a successful response to
  1024. * this operation, with enough room left over to encode a
  1025. * failed response to the next operation. If we don't
  1026. * have enough room, fail with ERR_RESOURCE.
  1027. */
  1028. slack_bytes = (char *)resp->end - (char *)resp->p;
  1029. if (slack_bytes < COMPOUND_SLACK_SPACE
  1030. + COMPOUND_ERR_SLACK_SPACE) {
  1031. BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
  1032. op->status = nfserr_resource;
  1033. goto encode_op;
  1034. }
  1035. opdesc = OPDESC(op);
  1036. if (!cstate->current_fh.fh_dentry) {
  1037. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  1038. op->status = nfserr_nofilehandle;
  1039. goto encode_op;
  1040. }
  1041. } else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
  1042. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  1043. op->status = nfserr_moved;
  1044. goto encode_op;
  1045. }
  1046. /* If op is non-idempotent */
  1047. if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  1048. plen = opdesc->op_rsize_bop(rqstp, op);
  1049. op->status = nfsd4_check_resp_size(resp, plen);
  1050. }
  1051. if (op->status)
  1052. goto encode_op;
  1053. if (opdesc->op_func)
  1054. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  1055. else
  1056. BUG_ON(op->status == nfs_ok);
  1057. if (!op->status && need_wrongsec_check(rqstp))
  1058. op->status = check_nfsd_access(cstate->current_fh.fh_export, rqstp);
  1059. encode_op:
  1060. /* Only from SEQUENCE */
  1061. if (resp->cstate.status == nfserr_replay_cache) {
  1062. dprintk("%s NFS4.1 replay from cache\n", __func__);
  1063. status = op->status;
  1064. goto out;
  1065. }
  1066. if (op->status == nfserr_replay_me) {
  1067. op->replay = &cstate->replay_owner->so_replay;
  1068. nfsd4_encode_replay(resp, op);
  1069. status = op->status = op->replay->rp_status;
  1070. } else {
  1071. nfsd4_encode_operation(resp, op);
  1072. status = op->status;
  1073. }
  1074. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  1075. args->ops, args->opcnt, resp->opcnt, op->opnum,
  1076. be32_to_cpu(status));
  1077. if (cstate->replay_owner) {
  1078. nfs4_unlock_state();
  1079. cstate->replay_owner = NULL;
  1080. }
  1081. /* XXX Ugh, we need to get rid of this kind of special case: */
  1082. if (op->opnum == OP_READ && op->u.read.rd_filp)
  1083. fput(op->u.read.rd_filp);
  1084. nfsd4_increment_op_stats(op->opnum);
  1085. }
  1086. resp->cstate.status = status;
  1087. fh_put(&resp->cstate.current_fh);
  1088. fh_put(&resp->cstate.save_fh);
  1089. BUG_ON(resp->cstate.replay_owner);
  1090. out:
  1091. /* Reset deferral mechanism for RPC deferrals */
  1092. rqstp->rq_usedeferral = 1;
  1093. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1094. return status;
  1095. }
  1096. #define op_encode_hdr_size (2)
  1097. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  1098. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  1099. #define op_encode_change_info_maxsz (5)
  1100. #define nfs4_fattr_bitmap_maxsz (4)
  1101. #define op_encode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1102. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  1103. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1104. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  1105. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  1106. op_encode_ace_maxsz)
  1107. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  1108. static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1109. {
  1110. return (op_encode_hdr_size) * sizeof(__be32);
  1111. }
  1112. static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1113. {
  1114. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  1115. }
  1116. static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1117. {
  1118. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1119. }
  1120. static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1121. {
  1122. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1123. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1124. }
  1125. static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1126. {
  1127. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1128. * sizeof(__be32);
  1129. }
  1130. static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1131. {
  1132. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  1133. * sizeof(__be32);
  1134. }
  1135. static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1136. {
  1137. return (op_encode_hdr_size + op_encode_stateid_maxsz
  1138. + op_encode_change_info_maxsz + 1
  1139. + nfs4_fattr_bitmap_maxsz
  1140. + op_encode_delegation_maxsz) * sizeof(__be32);
  1141. }
  1142. static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1143. {
  1144. u32 maxcount = 0, rlen = 0;
  1145. maxcount = svc_max_payload(rqstp);
  1146. rlen = op->u.read.rd_length;
  1147. if (rlen > maxcount)
  1148. rlen = maxcount;
  1149. return (op_encode_hdr_size + 2) * sizeof(__be32) + rlen;
  1150. }
  1151. static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1152. {
  1153. u32 rlen = op->u.readdir.rd_maxcount;
  1154. if (rlen > PAGE_SIZE)
  1155. rlen = PAGE_SIZE;
  1156. return (op_encode_hdr_size + op_encode_verifier_maxsz)
  1157. * sizeof(__be32) + rlen;
  1158. }
  1159. static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1160. {
  1161. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1162. * sizeof(__be32);
  1163. }
  1164. static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1165. {
  1166. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1167. + op_encode_change_info_maxsz) * sizeof(__be32);
  1168. }
  1169. static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1170. {
  1171. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1172. }
  1173. static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1174. {
  1175. return (op_encode_hdr_size + 2 + 1024) * sizeof(__be32);
  1176. }
  1177. static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1178. {
  1179. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1180. }
  1181. static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1182. {
  1183. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  1184. 1 + 1 + 0 + /* eir_flags, spr_how, SP4_NONE (for now) */\
  1185. 2 + /*eir_server_owner.so_minor_id */\
  1186. /* eir_server_owner.so_major_id<> */\
  1187. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1188. /* eir_server_scope<> */\
  1189. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1190. 1 + /* eir_server_impl_id array length */\
  1191. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  1192. }
  1193. static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1194. {
  1195. return (op_encode_hdr_size + \
  1196. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  1197. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  1198. }
  1199. static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1200. {
  1201. return (op_encode_hdr_size + \
  1202. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  1203. 2 + /* csr_sequence, csr_flags */\
  1204. op_encode_channel_attrs_maxsz + \
  1205. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  1206. }
  1207. static struct nfsd4_operation nfsd4_ops[] = {
  1208. [OP_ACCESS] = {
  1209. .op_func = (nfsd4op_func)nfsd4_access,
  1210. .op_name = "OP_ACCESS",
  1211. },
  1212. [OP_CLOSE] = {
  1213. .op_func = (nfsd4op_func)nfsd4_close,
  1214. .op_flags = OP_MODIFIES_SOMETHING,
  1215. .op_name = "OP_CLOSE",
  1216. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1217. },
  1218. [OP_COMMIT] = {
  1219. .op_func = (nfsd4op_func)nfsd4_commit,
  1220. .op_flags = OP_MODIFIES_SOMETHING,
  1221. .op_name = "OP_COMMIT",
  1222. .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
  1223. },
  1224. [OP_CREATE] = {
  1225. .op_func = (nfsd4op_func)nfsd4_create,
  1226. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1227. .op_name = "OP_CREATE",
  1228. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
  1229. },
  1230. [OP_DELEGRETURN] = {
  1231. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1232. .op_flags = OP_MODIFIES_SOMETHING,
  1233. .op_name = "OP_DELEGRETURN",
  1234. .op_rsize_bop = nfsd4_only_status_rsize,
  1235. },
  1236. [OP_GETATTR] = {
  1237. .op_func = (nfsd4op_func)nfsd4_getattr,
  1238. .op_flags = ALLOWED_ON_ABSENT_FS,
  1239. .op_name = "OP_GETATTR",
  1240. },
  1241. [OP_GETFH] = {
  1242. .op_func = (nfsd4op_func)nfsd4_getfh,
  1243. .op_name = "OP_GETFH",
  1244. },
  1245. [OP_LINK] = {
  1246. .op_func = (nfsd4op_func)nfsd4_link,
  1247. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  1248. | OP_CACHEME,
  1249. .op_name = "OP_LINK",
  1250. .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
  1251. },
  1252. [OP_LOCK] = {
  1253. .op_func = (nfsd4op_func)nfsd4_lock,
  1254. .op_flags = OP_MODIFIES_SOMETHING,
  1255. .op_name = "OP_LOCK",
  1256. .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
  1257. },
  1258. [OP_LOCKT] = {
  1259. .op_func = (nfsd4op_func)nfsd4_lockt,
  1260. .op_name = "OP_LOCKT",
  1261. },
  1262. [OP_LOCKU] = {
  1263. .op_func = (nfsd4op_func)nfsd4_locku,
  1264. .op_flags = OP_MODIFIES_SOMETHING,
  1265. .op_name = "OP_LOCKU",
  1266. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1267. },
  1268. [OP_LOOKUP] = {
  1269. .op_func = (nfsd4op_func)nfsd4_lookup,
  1270. .op_flags = OP_HANDLES_WRONGSEC,
  1271. .op_name = "OP_LOOKUP",
  1272. },
  1273. [OP_LOOKUPP] = {
  1274. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1275. .op_flags = OP_HANDLES_WRONGSEC,
  1276. .op_name = "OP_LOOKUPP",
  1277. },
  1278. [OP_NVERIFY] = {
  1279. .op_func = (nfsd4op_func)nfsd4_nverify,
  1280. .op_name = "OP_NVERIFY",
  1281. },
  1282. [OP_OPEN] = {
  1283. .op_func = (nfsd4op_func)nfsd4_open,
  1284. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1285. .op_name = "OP_OPEN",
  1286. .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
  1287. },
  1288. [OP_OPEN_CONFIRM] = {
  1289. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1290. .op_flags = OP_MODIFIES_SOMETHING,
  1291. .op_name = "OP_OPEN_CONFIRM",
  1292. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1293. },
  1294. [OP_OPEN_DOWNGRADE] = {
  1295. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1296. .op_flags = OP_MODIFIES_SOMETHING,
  1297. .op_name = "OP_OPEN_DOWNGRADE",
  1298. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1299. },
  1300. [OP_PUTFH] = {
  1301. .op_func = (nfsd4op_func)nfsd4_putfh,
  1302. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1303. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1304. .op_name = "OP_PUTFH",
  1305. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1306. },
  1307. [OP_PUTPUBFH] = {
  1308. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1309. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1310. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1311. .op_name = "OP_PUTPUBFH",
  1312. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1313. },
  1314. [OP_PUTROOTFH] = {
  1315. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1316. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1317. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1318. .op_name = "OP_PUTROOTFH",
  1319. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1320. },
  1321. [OP_READ] = {
  1322. .op_func = (nfsd4op_func)nfsd4_read,
  1323. .op_flags = OP_MODIFIES_SOMETHING,
  1324. .op_name = "OP_READ",
  1325. .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
  1326. },
  1327. [OP_READDIR] = {
  1328. .op_func = (nfsd4op_func)nfsd4_readdir,
  1329. .op_flags = OP_MODIFIES_SOMETHING,
  1330. .op_name = "OP_READDIR",
  1331. .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
  1332. },
  1333. [OP_READLINK] = {
  1334. .op_func = (nfsd4op_func)nfsd4_readlink,
  1335. .op_name = "OP_READLINK",
  1336. },
  1337. [OP_REMOVE] = {
  1338. .op_func = (nfsd4op_func)nfsd4_remove,
  1339. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1340. .op_name = "OP_REMOVE",
  1341. .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
  1342. },
  1343. [OP_RENAME] = {
  1344. .op_func = (nfsd4op_func)nfsd4_rename,
  1345. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1346. .op_name = "OP_RENAME",
  1347. .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
  1348. },
  1349. [OP_RENEW] = {
  1350. .op_func = (nfsd4op_func)nfsd4_renew,
  1351. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1352. | OP_MODIFIES_SOMETHING,
  1353. .op_name = "OP_RENEW",
  1354. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1355. },
  1356. [OP_RESTOREFH] = {
  1357. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1358. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1359. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1360. .op_name = "OP_RESTOREFH",
  1361. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1362. },
  1363. [OP_SAVEFH] = {
  1364. .op_func = (nfsd4op_func)nfsd4_savefh,
  1365. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1366. .op_name = "OP_SAVEFH",
  1367. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1368. },
  1369. [OP_SECINFO] = {
  1370. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1371. .op_flags = OP_HANDLES_WRONGSEC,
  1372. .op_name = "OP_SECINFO",
  1373. },
  1374. [OP_SETATTR] = {
  1375. .op_func = (nfsd4op_func)nfsd4_setattr,
  1376. .op_name = "OP_SETATTR",
  1377. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1378. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
  1379. },
  1380. [OP_SETCLIENTID] = {
  1381. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1382. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1383. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1384. .op_name = "OP_SETCLIENTID",
  1385. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
  1386. },
  1387. [OP_SETCLIENTID_CONFIRM] = {
  1388. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1389. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1390. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1391. .op_name = "OP_SETCLIENTID_CONFIRM",
  1392. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1393. },
  1394. [OP_VERIFY] = {
  1395. .op_func = (nfsd4op_func)nfsd4_verify,
  1396. .op_name = "OP_VERIFY",
  1397. },
  1398. [OP_WRITE] = {
  1399. .op_func = (nfsd4op_func)nfsd4_write,
  1400. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1401. .op_name = "OP_WRITE",
  1402. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  1403. },
  1404. [OP_RELEASE_LOCKOWNER] = {
  1405. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1406. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1407. | OP_MODIFIES_SOMETHING,
  1408. .op_name = "OP_RELEASE_LOCKOWNER",
  1409. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1410. },
  1411. /* NFSv4.1 operations */
  1412. [OP_EXCHANGE_ID] = {
  1413. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1414. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1415. | OP_MODIFIES_SOMETHING,
  1416. .op_name = "OP_EXCHANGE_ID",
  1417. .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
  1418. },
  1419. [OP_BIND_CONN_TO_SESSION] = {
  1420. .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
  1421. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1422. | OP_MODIFIES_SOMETHING,
  1423. .op_name = "OP_BIND_CONN_TO_SESSION",
  1424. .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
  1425. },
  1426. [OP_CREATE_SESSION] = {
  1427. .op_func = (nfsd4op_func)nfsd4_create_session,
  1428. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1429. | OP_MODIFIES_SOMETHING,
  1430. .op_name = "OP_CREATE_SESSION",
  1431. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
  1432. },
  1433. [OP_DESTROY_SESSION] = {
  1434. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1435. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1436. | OP_MODIFIES_SOMETHING,
  1437. .op_name = "OP_DESTROY_SESSION",
  1438. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1439. },
  1440. [OP_SEQUENCE] = {
  1441. .op_func = (nfsd4op_func)nfsd4_sequence,
  1442. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1443. .op_name = "OP_SEQUENCE",
  1444. },
  1445. [OP_DESTROY_CLIENTID] = {
  1446. .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
  1447. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1448. | OP_MODIFIES_SOMETHING,
  1449. .op_name = "OP_DESTROY_CLIENTID",
  1450. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1451. },
  1452. [OP_RECLAIM_COMPLETE] = {
  1453. .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
  1454. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1455. .op_name = "OP_RECLAIM_COMPLETE",
  1456. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1457. },
  1458. [OP_SECINFO_NO_NAME] = {
  1459. .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
  1460. .op_flags = OP_HANDLES_WRONGSEC,
  1461. .op_name = "OP_SECINFO_NO_NAME",
  1462. },
  1463. [OP_TEST_STATEID] = {
  1464. .op_func = (nfsd4op_func)nfsd4_test_stateid,
  1465. .op_flags = ALLOWED_WITHOUT_FH,
  1466. .op_name = "OP_TEST_STATEID",
  1467. },
  1468. [OP_FREE_STATEID] = {
  1469. .op_func = (nfsd4op_func)nfsd4_free_stateid,
  1470. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1471. .op_name = "OP_FREE_STATEID",
  1472. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1473. },
  1474. };
  1475. static const char *nfsd4_op_name(unsigned opnum)
  1476. {
  1477. if (opnum < ARRAY_SIZE(nfsd4_ops))
  1478. return nfsd4_ops[opnum].op_name;
  1479. return "unknown_operation";
  1480. }
  1481. #define nfsd4_voidres nfsd4_voidargs
  1482. struct nfsd4_voidargs { int dummy; };
  1483. static struct svc_procedure nfsd_procedures4[2] = {
  1484. [NFSPROC4_NULL] = {
  1485. .pc_func = (svc_procfunc) nfsd4_proc_null,
  1486. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  1487. .pc_argsize = sizeof(struct nfsd4_voidargs),
  1488. .pc_ressize = sizeof(struct nfsd4_voidres),
  1489. .pc_cachetype = RC_NOCACHE,
  1490. .pc_xdrressize = 1,
  1491. },
  1492. [NFSPROC4_COMPOUND] = {
  1493. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  1494. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  1495. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  1496. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  1497. .pc_ressize = sizeof(struct nfsd4_compoundres),
  1498. .pc_release = nfsd4_release_compoundargs,
  1499. .pc_cachetype = RC_NOCACHE,
  1500. .pc_xdrressize = NFSD_BUFSIZE/4,
  1501. },
  1502. };
  1503. struct svc_version nfsd_version4 = {
  1504. .vs_vers = 4,
  1505. .vs_nproc = 2,
  1506. .vs_proc = nfsd_procedures4,
  1507. .vs_dispatch = nfsd_dispatch,
  1508. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  1509. };
  1510. /*
  1511. * Local variables:
  1512. * c-basic-offset: 8
  1513. * End:
  1514. */