nfs4proc.c 55 KB

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