nfs4proc.c 54 KB

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