nfs4proc.c 49 KB

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