nfs4proc.c 51 KB

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