nfs4proc.c 48 KB

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