nfs4proc.c 50 KB

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