nfs4proc.c 50 KB

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