nfs4proc.c 52 KB

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