nfs4proc.c 52 KB

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