nfs4proc.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354
  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/falloc.h>
  37. #include <linux/slab.h>
  38. #include "idmap.h"
  39. #include "cache.h"
  40. #include "xdr4.h"
  41. #include "vfs.h"
  42. #include "current_stateid.h"
  43. #include "netns.h"
  44. #include "acl.h"
  45. #include "pnfs.h"
  46. #include "trace.h"
  47. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  48. #include <linux/security.h>
  49. static inline void
  50. nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
  51. {
  52. struct inode *inode = d_inode(resfh->fh_dentry);
  53. int status;
  54. mutex_lock(&inode->i_mutex);
  55. status = security_inode_setsecctx(resfh->fh_dentry,
  56. label->data, label->len);
  57. mutex_unlock(&inode->i_mutex);
  58. if (status)
  59. /*
  60. * XXX: We should really fail the whole open, but we may
  61. * already have created a new file, so it may be too
  62. * late. For now this seems the least of evils:
  63. */
  64. bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  65. return;
  66. }
  67. #else
  68. static inline void
  69. nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
  70. { }
  71. #endif
  72. #define NFSDDBG_FACILITY NFSDDBG_PROC
  73. static u32 nfsd_attrmask[] = {
  74. NFSD_WRITEABLE_ATTRS_WORD0,
  75. NFSD_WRITEABLE_ATTRS_WORD1,
  76. NFSD_WRITEABLE_ATTRS_WORD2
  77. };
  78. static u32 nfsd41_ex_attrmask[] = {
  79. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  80. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  81. NFSD_SUPPATTR_EXCLCREAT_WORD2
  82. };
  83. static __be32
  84. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  85. u32 *bmval, u32 *writable)
  86. {
  87. struct dentry *dentry = cstate->current_fh.fh_dentry;
  88. /*
  89. * Check about attributes are supported by the NFSv4 server or not.
  90. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
  91. */
  92. if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
  93. (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
  94. (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
  95. return nfserr_attrnotsupp;
  96. /*
  97. * Check FATTR4_WORD0_ACL can be supported
  98. * in current environment or not.
  99. */
  100. if (bmval[0] & FATTR4_WORD0_ACL) {
  101. if (!IS_POSIXACL(d_inode(dentry)))
  102. return nfserr_attrnotsupp;
  103. }
  104. /*
  105. * According to spec, read-only attributes return ERR_INVAL.
  106. */
  107. if (writable) {
  108. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  109. (bmval[2] & ~writable[2]))
  110. return nfserr_inval;
  111. }
  112. return nfs_ok;
  113. }
  114. static __be32
  115. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  116. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  117. {
  118. __be32 status = nfs_ok;
  119. if (open->op_create == NFS4_OPEN_CREATE) {
  120. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  121. || open->op_createmode == NFS4_CREATE_GUARDED)
  122. status = check_attr_support(rqstp, cstate,
  123. open->op_bmval, nfsd_attrmask);
  124. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  125. status = check_attr_support(rqstp, cstate,
  126. open->op_bmval, nfsd41_ex_attrmask);
  127. }
  128. return status;
  129. }
  130. static int
  131. is_create_with_attrs(struct nfsd4_open *open)
  132. {
  133. return open->op_create == NFS4_OPEN_CREATE
  134. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  135. || open->op_createmode == NFS4_CREATE_GUARDED
  136. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  137. }
  138. /*
  139. * if error occurs when setting the acl, just clear the acl bit
  140. * in the returned attr bitmap.
  141. */
  142. static void
  143. do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
  144. struct nfs4_acl *acl, u32 *bmval)
  145. {
  146. __be32 status;
  147. status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
  148. if (status)
  149. /*
  150. * We should probably fail the whole open at this point,
  151. * but we've already created the file, so it's too late;
  152. * So this seems the least of evils:
  153. */
  154. bmval[0] &= ~FATTR4_WORD0_ACL;
  155. }
  156. static inline void
  157. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  158. {
  159. fh_put(dst);
  160. dget(src->fh_dentry);
  161. if (src->fh_export)
  162. exp_get(src->fh_export);
  163. *dst = *src;
  164. }
  165. static __be32
  166. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  167. {
  168. __be32 status;
  169. if (open->op_truncate &&
  170. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  171. return nfserr_inval;
  172. accmode |= NFSD_MAY_READ_IF_EXEC;
  173. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  174. accmode |= NFSD_MAY_READ;
  175. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  176. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  177. if (open->op_share_deny & NFS4_SHARE_DENY_READ)
  178. accmode |= NFSD_MAY_WRITE;
  179. status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
  180. return status;
  181. }
  182. static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
  183. {
  184. umode_t mode = d_inode(fh->fh_dentry)->i_mode;
  185. if (S_ISREG(mode))
  186. return nfs_ok;
  187. if (S_ISDIR(mode))
  188. return nfserr_isdir;
  189. /*
  190. * Using err_symlink as our catch-all case may look odd; but
  191. * there's no other obvious error for this case in 4.0, and we
  192. * happen to know that it will cause the linux v4 client to do
  193. * the right thing on attempts to open something other than a
  194. * regular file.
  195. */
  196. return nfserr_symlink;
  197. }
  198. static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
  199. {
  200. if (nfsd4_has_session(cstate))
  201. return;
  202. fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
  203. &resfh->fh_handle);
  204. }
  205. static __be32
  206. do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
  207. {
  208. struct svc_fh *current_fh = &cstate->current_fh;
  209. int accmode;
  210. __be32 status;
  211. *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
  212. if (!*resfh)
  213. return nfserr_jukebox;
  214. fh_init(*resfh, NFS4_FHSIZE);
  215. open->op_truncate = 0;
  216. if (open->op_create) {
  217. /* FIXME: check session persistence and pnfs flags.
  218. * The nfsv4.1 spec requires the following semantics:
  219. *
  220. * Persistent | pNFS | Server REQUIRED | Client Allowed
  221. * Reply Cache | server | |
  222. * -------------+--------+-----------------+--------------------
  223. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  224. * | | | (SHOULD)
  225. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  226. * | | | (SHOULD NOT)
  227. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  228. * yes | no | GUARDED4 | GUARDED4
  229. * yes | yes | GUARDED4 | GUARDED4
  230. */
  231. /*
  232. * Note: create modes (UNCHECKED,GUARDED...) are the same
  233. * in NFSv4 as in v3 except EXCLUSIVE4_1.
  234. */
  235. status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
  236. open->op_fname.len, &open->op_iattr,
  237. *resfh, open->op_createmode,
  238. (u32 *)open->op_verf.data,
  239. &open->op_truncate, &open->op_created);
  240. if (!status && open->op_label.len)
  241. nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
  242. /*
  243. * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
  244. * use the returned bitmask to indicate which attributes
  245. * we used to store the verifier:
  246. */
  247. if (nfsd_create_is_exclusive(open->op_createmode) && status == 0)
  248. open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
  249. FATTR4_WORD1_TIME_MODIFY);
  250. } else
  251. /*
  252. * Note this may exit with the parent still locked.
  253. * We will hold the lock until nfsd4_open's final
  254. * lookup, to prevent renames or unlinks until we've had
  255. * a chance to an acquire a delegation if appropriate.
  256. */
  257. status = nfsd_lookup(rqstp, current_fh,
  258. open->op_fname.data, open->op_fname.len, *resfh);
  259. if (status)
  260. goto out;
  261. status = nfsd_check_obj_isreg(*resfh);
  262. if (status)
  263. goto out;
  264. if (is_create_with_attrs(open) && open->op_acl != NULL)
  265. do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
  266. nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
  267. accmode = NFSD_MAY_NOP;
  268. if (open->op_created ||
  269. open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
  270. accmode |= NFSD_MAY_OWNER_OVERRIDE;
  271. status = do_open_permission(rqstp, *resfh, open, accmode);
  272. set_change_info(&open->op_cinfo, current_fh);
  273. out:
  274. return status;
  275. }
  276. static __be32
  277. do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  278. {
  279. struct svc_fh *current_fh = &cstate->current_fh;
  280. __be32 status;
  281. int accmode = 0;
  282. /* We don't know the target directory, and therefore can not
  283. * set the change info
  284. */
  285. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  286. nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
  287. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  288. (open->op_iattr.ia_size == 0);
  289. /*
  290. * In the delegation case, the client is telling us about an
  291. * open that it *already* performed locally, some time ago. We
  292. * should let it succeed now if possible.
  293. *
  294. * In the case of a CLAIM_FH open, on the other hand, the client
  295. * may be counting on us to enforce permissions (the Linux 4.1
  296. * client uses this for normal opens, for example).
  297. */
  298. if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
  299. accmode = NFSD_MAY_OWNER_OVERRIDE;
  300. status = do_open_permission(rqstp, current_fh, open, accmode);
  301. return status;
  302. }
  303. static void
  304. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  305. {
  306. struct nfsd4_sessionid *sid =
  307. (struct nfsd4_sessionid *)session->se_sessionid.data;
  308. clid->cl_boot = sid->clientid.cl_boot;
  309. clid->cl_id = sid->clientid.cl_id;
  310. }
  311. static __be32
  312. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  313. struct nfsd4_open *open)
  314. {
  315. __be32 status;
  316. struct svc_fh *resfh = NULL;
  317. struct net *net = SVC_NET(rqstp);
  318. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  319. dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
  320. (int)open->op_fname.len, open->op_fname.data,
  321. open->op_openowner);
  322. /* This check required by spec. */
  323. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  324. return nfserr_inval;
  325. open->op_created = 0;
  326. /*
  327. * RFC5661 18.51.3
  328. * Before RECLAIM_COMPLETE done, server should deny new lock
  329. */
  330. if (nfsd4_has_session(cstate) &&
  331. !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
  332. &cstate->session->se_client->cl_flags) &&
  333. open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  334. return nfserr_grace;
  335. if (nfsd4_has_session(cstate))
  336. copy_clientid(&open->op_clientid, cstate->session);
  337. /* check seqid for replay. set nfs4_owner */
  338. status = nfsd4_process_open1(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 (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  364. goto out;
  365. status = nfserr_no_grace;
  366. if (!opens_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. status = nfs4_check_open_reclaim(&open->op_clientid,
  377. cstate, nn);
  378. if (status)
  379. goto out;
  380. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  381. case NFS4_OPEN_CLAIM_FH:
  382. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  383. status = do_open_fhandle(rqstp, cstate, open);
  384. if (status)
  385. goto out;
  386. resfh = &cstate->current_fh;
  387. break;
  388. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  389. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  390. dprintk("NFSD: unsupported OPEN claim type %d\n",
  391. open->op_claim_type);
  392. status = nfserr_notsupp;
  393. goto out;
  394. default:
  395. dprintk("NFSD: Invalid OPEN claim type %d\n",
  396. open->op_claim_type);
  397. status = nfserr_inval;
  398. goto out;
  399. }
  400. /*
  401. * nfsd4_process_open2() does the actual opening of the file. If
  402. * successful, it (1) truncates the file if open->op_truncate was
  403. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  404. */
  405. status = nfsd4_process_open2(rqstp, resfh, open);
  406. WARN(status && open->op_created,
  407. "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
  408. be32_to_cpu(status));
  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(cstate, open);
  416. nfsd4_bump_seqid(cstate, status);
  417. return status;
  418. }
  419. /*
  420. * OPEN is the only seqid-mutating operation whose decoding can fail
  421. * with a seqid-mutating error (specifically, decoding of user names in
  422. * the attributes). Therefore we have to do some processing to look up
  423. * the stateowner so that we can bump the seqid.
  424. */
  425. static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
  426. {
  427. struct nfsd4_open *open = (struct nfsd4_open *)&op->u;
  428. if (!seqid_mutating_err(ntohl(op->status)))
  429. return op->status;
  430. if (nfsd4_has_session(cstate))
  431. return op->status;
  432. open->op_xdr_error = op->status;
  433. return nfsd4_open(rqstp, cstate, open);
  434. }
  435. /*
  436. * filehandle-manipulating ops.
  437. */
  438. static __be32
  439. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  440. struct svc_fh **getfh)
  441. {
  442. if (!cstate->current_fh.fh_dentry)
  443. return nfserr_nofilehandle;
  444. *getfh = &cstate->current_fh;
  445. return nfs_ok;
  446. }
  447. static __be32
  448. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  449. struct nfsd4_putfh *putfh)
  450. {
  451. fh_put(&cstate->current_fh);
  452. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  453. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  454. putfh->pf_fhlen);
  455. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
  456. }
  457. static __be32
  458. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  459. void *arg)
  460. {
  461. __be32 status;
  462. fh_put(&cstate->current_fh);
  463. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  464. return status;
  465. }
  466. static __be32
  467. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  468. void *arg)
  469. {
  470. if (!cstate->save_fh.fh_dentry)
  471. return nfserr_restorefh;
  472. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  473. if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
  474. memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
  475. SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
  476. }
  477. return nfs_ok;
  478. }
  479. static __be32
  480. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  481. void *arg)
  482. {
  483. if (!cstate->current_fh.fh_dentry)
  484. return nfserr_nofilehandle;
  485. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  486. if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
  487. memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
  488. SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
  489. }
  490. return nfs_ok;
  491. }
  492. /*
  493. * misc nfsv4 ops
  494. */
  495. static __be32
  496. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  497. struct nfsd4_access *access)
  498. {
  499. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  500. return nfserr_inval;
  501. access->ac_resp_access = access->ac_req_access;
  502. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  503. &access->ac_supported);
  504. }
  505. static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
  506. {
  507. __be32 verf[2];
  508. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  509. /*
  510. * This is opaque to client, so no need to byte-swap. Use
  511. * __force to keep sparse happy
  512. */
  513. verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
  514. verf[1] = (__force __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. status = nfsd_symlink(rqstp, &cstate->current_fh,
  544. create->cr_name, create->cr_namelen,
  545. create->cr_data, &resfh);
  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. read->rd_filp = NULL;
  662. if (read->rd_offset >= OFFSET_MAX)
  663. return nfserr_inval;
  664. /*
  665. * If we do a zero copy read, then a client will see read data
  666. * that reflects the state of the file *after* performing the
  667. * following compound.
  668. *
  669. * To ensure proper ordering, we therefore turn off zero copy if
  670. * the client wants us to do more in this compound:
  671. */
  672. if (!nfsd4_last_compound_op(rqstp))
  673. clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
  674. /* check stateid */
  675. status = nfs4_preprocess_stateid_op(rqstp, cstate, &read->rd_stateid,
  676. RD_STATE, &read->rd_filp, &read->rd_tmp_file);
  677. if (status) {
  678. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  679. goto out;
  680. }
  681. status = nfs_ok;
  682. out:
  683. read->rd_rqstp = rqstp;
  684. read->rd_fhp = &cstate->current_fh;
  685. return status;
  686. }
  687. static __be32
  688. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  689. struct nfsd4_readdir *readdir)
  690. {
  691. u64 cookie = readdir->rd_cookie;
  692. static const nfs4_verifier zeroverf;
  693. /* no need to check permission - this will be done in nfsd_readdir() */
  694. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  695. return nfserr_inval;
  696. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  697. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  698. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  699. if ((cookie == 1) || (cookie == 2) ||
  700. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  701. return nfserr_bad_cookie;
  702. readdir->rd_rqstp = rqstp;
  703. readdir->rd_fhp = &cstate->current_fh;
  704. return nfs_ok;
  705. }
  706. static __be32
  707. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  708. struct nfsd4_readlink *readlink)
  709. {
  710. readlink->rl_rqstp = rqstp;
  711. readlink->rl_fhp = &cstate->current_fh;
  712. return nfs_ok;
  713. }
  714. static __be32
  715. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  716. struct nfsd4_remove *remove)
  717. {
  718. __be32 status;
  719. if (opens_in_grace(SVC_NET(rqstp)))
  720. return nfserr_grace;
  721. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  722. remove->rm_name, remove->rm_namelen);
  723. if (!status) {
  724. fh_unlock(&cstate->current_fh);
  725. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  726. }
  727. return status;
  728. }
  729. static __be32
  730. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  731. struct nfsd4_rename *rename)
  732. {
  733. __be32 status = nfserr_nofilehandle;
  734. if (!cstate->save_fh.fh_dentry)
  735. return status;
  736. if (opens_in_grace(SVC_NET(rqstp)) &&
  737. !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
  738. return nfserr_grace;
  739. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  740. rename->rn_snamelen, &cstate->current_fh,
  741. rename->rn_tname, rename->rn_tnamelen);
  742. if (status)
  743. return status;
  744. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  745. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  746. return nfs_ok;
  747. }
  748. static __be32
  749. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  750. struct nfsd4_secinfo *secinfo)
  751. {
  752. struct svc_fh resfh;
  753. struct svc_export *exp;
  754. struct dentry *dentry;
  755. __be32 err;
  756. fh_init(&resfh, NFS4_FHSIZE);
  757. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  758. if (err)
  759. return err;
  760. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  761. secinfo->si_name, secinfo->si_namelen,
  762. &exp, &dentry);
  763. if (err)
  764. return err;
  765. fh_unlock(&cstate->current_fh);
  766. if (d_really_is_negative(dentry)) {
  767. exp_put(exp);
  768. err = nfserr_noent;
  769. } else
  770. secinfo->si_exp = exp;
  771. dput(dentry);
  772. if (cstate->minorversion)
  773. /* See rfc 5661 section 2.6.3.1.1.8 */
  774. fh_put(&cstate->current_fh);
  775. return err;
  776. }
  777. static __be32
  778. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  779. struct nfsd4_secinfo_no_name *sin)
  780. {
  781. __be32 err;
  782. switch (sin->sin_style) {
  783. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  784. break;
  785. case NFS4_SECINFO_STYLE4_PARENT:
  786. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  787. if (err)
  788. return err;
  789. break;
  790. default:
  791. return nfserr_inval;
  792. }
  793. sin->sin_exp = exp_get(cstate->current_fh.fh_export);
  794. fh_put(&cstate->current_fh);
  795. return nfs_ok;
  796. }
  797. static __be32
  798. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  799. struct nfsd4_setattr *setattr)
  800. {
  801. __be32 status = nfs_ok;
  802. int err;
  803. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  804. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  805. &setattr->sa_stateid, WR_STATE, NULL, NULL);
  806. if (status) {
  807. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  808. return status;
  809. }
  810. }
  811. err = fh_want_write(&cstate->current_fh);
  812. if (err)
  813. return nfserrno(err);
  814. status = nfs_ok;
  815. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  816. nfsd_attrmask);
  817. if (status)
  818. goto out;
  819. if (setattr->sa_acl != NULL)
  820. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  821. setattr->sa_acl);
  822. if (status)
  823. goto out;
  824. if (setattr->sa_label.len)
  825. status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
  826. &setattr->sa_label);
  827. if (status)
  828. goto out;
  829. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  830. 0, (time_t)0);
  831. out:
  832. fh_drop_write(&cstate->current_fh);
  833. return status;
  834. }
  835. static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
  836. {
  837. int i = 1;
  838. int buflen = write->wr_buflen;
  839. vec[0].iov_base = write->wr_head.iov_base;
  840. vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len);
  841. buflen -= vec[0].iov_len;
  842. while (buflen) {
  843. vec[i].iov_base = page_address(write->wr_pagelist[i - 1]);
  844. vec[i].iov_len = min_t(int, PAGE_SIZE, buflen);
  845. buflen -= vec[i].iov_len;
  846. i++;
  847. }
  848. return i;
  849. }
  850. static __be32
  851. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  852. struct nfsd4_write *write)
  853. {
  854. stateid_t *stateid = &write->wr_stateid;
  855. struct file *filp = NULL;
  856. __be32 status = nfs_ok;
  857. unsigned long cnt;
  858. int nvecs;
  859. if (write->wr_offset >= OFFSET_MAX)
  860. return nfserr_inval;
  861. status = nfs4_preprocess_stateid_op(rqstp, cstate, stateid, WR_STATE,
  862. &filp, NULL);
  863. if (status) {
  864. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  865. return status;
  866. }
  867. cnt = write->wr_buflen;
  868. write->wr_how_written = write->wr_stable_how;
  869. gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp));
  870. nvecs = fill_in_write_vector(rqstp->rq_vec, write);
  871. WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
  872. status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp,
  873. write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
  874. &write->wr_how_written);
  875. fput(filp);
  876. write->wr_bytes_written = cnt;
  877. return status;
  878. }
  879. static __be32
  880. nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  881. struct nfsd4_fallocate *fallocate, int flags)
  882. {
  883. __be32 status = nfserr_notsupp;
  884. struct file *file;
  885. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  886. &fallocate->falloc_stateid,
  887. WR_STATE, &file, NULL);
  888. if (status != nfs_ok) {
  889. dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
  890. return status;
  891. }
  892. status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
  893. fallocate->falloc_offset,
  894. fallocate->falloc_length,
  895. flags);
  896. fput(file);
  897. return status;
  898. }
  899. static __be32
  900. nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  901. struct nfsd4_fallocate *fallocate)
  902. {
  903. return nfsd4_fallocate(rqstp, cstate, fallocate, 0);
  904. }
  905. static __be32
  906. nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  907. struct nfsd4_fallocate *fallocate)
  908. {
  909. return nfsd4_fallocate(rqstp, cstate, fallocate,
  910. FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
  911. }
  912. static __be32
  913. nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  914. struct nfsd4_seek *seek)
  915. {
  916. int whence;
  917. __be32 status;
  918. struct file *file;
  919. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  920. &seek->seek_stateid,
  921. RD_STATE, &file, NULL);
  922. if (status) {
  923. dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
  924. return status;
  925. }
  926. switch (seek->seek_whence) {
  927. case NFS4_CONTENT_DATA:
  928. whence = SEEK_DATA;
  929. break;
  930. case NFS4_CONTENT_HOLE:
  931. whence = SEEK_HOLE;
  932. break;
  933. default:
  934. status = nfserr_union_notsupp;
  935. goto out;
  936. }
  937. /*
  938. * Note: This call does change file->f_pos, but nothing in NFSD
  939. * should ever file->f_pos.
  940. */
  941. seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
  942. if (seek->seek_pos < 0)
  943. status = nfserrno(seek->seek_pos);
  944. else if (seek->seek_pos >= i_size_read(file_inode(file)))
  945. seek->seek_eof = true;
  946. out:
  947. fput(file);
  948. return status;
  949. }
  950. /* This routine never returns NFS_OK! If there are no other errors, it
  951. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  952. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  953. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  954. */
  955. static __be32
  956. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  957. struct nfsd4_verify *verify)
  958. {
  959. __be32 *buf, *p;
  960. int count;
  961. __be32 status;
  962. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  963. if (status)
  964. return status;
  965. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  966. if (status)
  967. return status;
  968. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  969. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  970. return nfserr_inval;
  971. if (verify->ve_attrlen & 3)
  972. return nfserr_inval;
  973. /* count in words:
  974. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  975. */
  976. count = 4 + (verify->ve_attrlen >> 2);
  977. buf = kmalloc(count << 2, GFP_KERNEL);
  978. if (!buf)
  979. return nfserr_jukebox;
  980. p = buf;
  981. status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
  982. cstate->current_fh.fh_export,
  983. cstate->current_fh.fh_dentry,
  984. verify->ve_bmval,
  985. rqstp, 0);
  986. /*
  987. * If nfsd4_encode_fattr() ran out of space, assume that's because
  988. * the attributes are longer (hence different) than those given:
  989. */
  990. if (status == nfserr_resource)
  991. status = nfserr_not_same;
  992. if (status)
  993. goto out_kfree;
  994. /* skip bitmap */
  995. p = buf + 1 + ntohl(buf[0]);
  996. status = nfserr_not_same;
  997. if (ntohl(*p++) != verify->ve_attrlen)
  998. goto out_kfree;
  999. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  1000. status = nfserr_same;
  1001. out_kfree:
  1002. kfree(buf);
  1003. return status;
  1004. }
  1005. static __be32
  1006. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1007. struct nfsd4_verify *verify)
  1008. {
  1009. __be32 status;
  1010. status = _nfsd4_verify(rqstp, cstate, verify);
  1011. return status == nfserr_not_same ? nfs_ok : status;
  1012. }
  1013. static __be32
  1014. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1015. struct nfsd4_verify *verify)
  1016. {
  1017. __be32 status;
  1018. status = _nfsd4_verify(rqstp, cstate, verify);
  1019. return status == nfserr_same ? nfs_ok : status;
  1020. }
  1021. #ifdef CONFIG_NFSD_PNFS
  1022. static const struct nfsd4_layout_ops *
  1023. nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
  1024. {
  1025. if (!exp->ex_layout_type) {
  1026. dprintk("%s: export does not support pNFS\n", __func__);
  1027. return NULL;
  1028. }
  1029. if (exp->ex_layout_type != layout_type) {
  1030. dprintk("%s: layout type %d not supported\n",
  1031. __func__, layout_type);
  1032. return NULL;
  1033. }
  1034. return nfsd4_layout_ops[layout_type];
  1035. }
  1036. static __be32
  1037. nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
  1038. struct nfsd4_compound_state *cstate,
  1039. struct nfsd4_getdeviceinfo *gdp)
  1040. {
  1041. const struct nfsd4_layout_ops *ops;
  1042. struct nfsd4_deviceid_map *map;
  1043. struct svc_export *exp;
  1044. __be32 nfserr;
  1045. dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
  1046. __func__,
  1047. gdp->gd_layout_type,
  1048. gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
  1049. gdp->gd_maxcount);
  1050. map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
  1051. if (!map) {
  1052. dprintk("%s: couldn't find device ID to export mapping!\n",
  1053. __func__);
  1054. return nfserr_noent;
  1055. }
  1056. exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
  1057. if (IS_ERR(exp)) {
  1058. dprintk("%s: could not find device id\n", __func__);
  1059. return nfserr_noent;
  1060. }
  1061. nfserr = nfserr_layoutunavailable;
  1062. ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
  1063. if (!ops)
  1064. goto out;
  1065. nfserr = nfs_ok;
  1066. if (gdp->gd_maxcount != 0)
  1067. nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, gdp);
  1068. gdp->gd_notify_types &= ops->notify_types;
  1069. out:
  1070. exp_put(exp);
  1071. return nfserr;
  1072. }
  1073. static __be32
  1074. nfsd4_layoutget(struct svc_rqst *rqstp,
  1075. struct nfsd4_compound_state *cstate,
  1076. struct nfsd4_layoutget *lgp)
  1077. {
  1078. struct svc_fh *current_fh = &cstate->current_fh;
  1079. const struct nfsd4_layout_ops *ops;
  1080. struct nfs4_layout_stateid *ls;
  1081. __be32 nfserr;
  1082. int accmode = NFSD_MAY_READ_IF_EXEC;
  1083. switch (lgp->lg_seg.iomode) {
  1084. case IOMODE_READ:
  1085. accmode |= NFSD_MAY_READ;
  1086. break;
  1087. case IOMODE_RW:
  1088. accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
  1089. break;
  1090. default:
  1091. dprintk("%s: invalid iomode %d\n",
  1092. __func__, lgp->lg_seg.iomode);
  1093. nfserr = nfserr_badiomode;
  1094. goto out;
  1095. }
  1096. nfserr = fh_verify(rqstp, current_fh, 0, accmode);
  1097. if (nfserr)
  1098. goto out;
  1099. nfserr = nfserr_layoutunavailable;
  1100. ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
  1101. if (!ops)
  1102. goto out;
  1103. /*
  1104. * Verify minlength and range as per RFC5661:
  1105. * o If loga_length is less than loga_minlength,
  1106. * the metadata server MUST return NFS4ERR_INVAL.
  1107. * o If the sum of loga_offset and loga_minlength exceeds
  1108. * NFS4_UINT64_MAX, and loga_minlength is not
  1109. * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
  1110. * o If the sum of loga_offset and loga_length exceeds
  1111. * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
  1112. * the error NFS4ERR_INVAL MUST result.
  1113. */
  1114. nfserr = nfserr_inval;
  1115. if (lgp->lg_seg.length < lgp->lg_minlength ||
  1116. (lgp->lg_minlength != NFS4_MAX_UINT64 &&
  1117. lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
  1118. (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
  1119. lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
  1120. goto out;
  1121. if (lgp->lg_seg.length == 0)
  1122. goto out;
  1123. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
  1124. true, lgp->lg_layout_type, &ls);
  1125. if (nfserr) {
  1126. trace_layout_get_lookup_fail(&lgp->lg_sid);
  1127. goto out;
  1128. }
  1129. nfserr = nfserr_recallconflict;
  1130. if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
  1131. goto out_put_stid;
  1132. nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
  1133. current_fh, lgp);
  1134. if (nfserr)
  1135. goto out_put_stid;
  1136. nfserr = nfsd4_insert_layout(lgp, ls);
  1137. out_put_stid:
  1138. mutex_unlock(&ls->ls_mutex);
  1139. nfs4_put_stid(&ls->ls_stid);
  1140. out:
  1141. return nfserr;
  1142. }
  1143. static __be32
  1144. nfsd4_layoutcommit(struct svc_rqst *rqstp,
  1145. struct nfsd4_compound_state *cstate,
  1146. struct nfsd4_layoutcommit *lcp)
  1147. {
  1148. const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
  1149. struct svc_fh *current_fh = &cstate->current_fh;
  1150. const struct nfsd4_layout_ops *ops;
  1151. loff_t new_size = lcp->lc_last_wr + 1;
  1152. struct inode *inode;
  1153. struct nfs4_layout_stateid *ls;
  1154. __be32 nfserr;
  1155. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
  1156. if (nfserr)
  1157. goto out;
  1158. nfserr = nfserr_layoutunavailable;
  1159. ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
  1160. if (!ops)
  1161. goto out;
  1162. inode = d_inode(current_fh->fh_dentry);
  1163. nfserr = nfserr_inval;
  1164. if (new_size <= seg->offset) {
  1165. dprintk("pnfsd: last write before layout segment\n");
  1166. goto out;
  1167. }
  1168. if (new_size > seg->offset + seg->length) {
  1169. dprintk("pnfsd: last write beyond layout segment\n");
  1170. goto out;
  1171. }
  1172. if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
  1173. dprintk("pnfsd: layoutcommit beyond EOF\n");
  1174. goto out;
  1175. }
  1176. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
  1177. false, lcp->lc_layout_type,
  1178. &ls);
  1179. if (nfserr) {
  1180. trace_layout_commit_lookup_fail(&lcp->lc_sid);
  1181. /* fixup error code as per RFC5661 */
  1182. if (nfserr == nfserr_bad_stateid)
  1183. nfserr = nfserr_badlayout;
  1184. goto out;
  1185. }
  1186. /* LAYOUTCOMMIT does not require any serialization */
  1187. mutex_unlock(&ls->ls_mutex);
  1188. if (new_size > i_size_read(inode)) {
  1189. lcp->lc_size_chg = 1;
  1190. lcp->lc_newsize = new_size;
  1191. } else {
  1192. lcp->lc_size_chg = 0;
  1193. }
  1194. nfserr = ops->proc_layoutcommit(inode, lcp);
  1195. nfs4_put_stid(&ls->ls_stid);
  1196. out:
  1197. return nfserr;
  1198. }
  1199. static __be32
  1200. nfsd4_layoutreturn(struct svc_rqst *rqstp,
  1201. struct nfsd4_compound_state *cstate,
  1202. struct nfsd4_layoutreturn *lrp)
  1203. {
  1204. struct svc_fh *current_fh = &cstate->current_fh;
  1205. __be32 nfserr;
  1206. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
  1207. if (nfserr)
  1208. goto out;
  1209. nfserr = nfserr_layoutunavailable;
  1210. if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
  1211. goto out;
  1212. switch (lrp->lr_seg.iomode) {
  1213. case IOMODE_READ:
  1214. case IOMODE_RW:
  1215. case IOMODE_ANY:
  1216. break;
  1217. default:
  1218. dprintk("%s: invalid iomode %d\n", __func__,
  1219. lrp->lr_seg.iomode);
  1220. nfserr = nfserr_inval;
  1221. goto out;
  1222. }
  1223. switch (lrp->lr_return_type) {
  1224. case RETURN_FILE:
  1225. nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
  1226. break;
  1227. case RETURN_FSID:
  1228. case RETURN_ALL:
  1229. nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
  1230. break;
  1231. default:
  1232. dprintk("%s: invalid return_type %d\n", __func__,
  1233. lrp->lr_return_type);
  1234. nfserr = nfserr_inval;
  1235. break;
  1236. }
  1237. out:
  1238. return nfserr;
  1239. }
  1240. #endif /* CONFIG_NFSD_PNFS */
  1241. /*
  1242. * NULL call.
  1243. */
  1244. static __be32
  1245. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  1246. {
  1247. return nfs_ok;
  1248. }
  1249. static inline void nfsd4_increment_op_stats(u32 opnum)
  1250. {
  1251. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  1252. nfsdstats.nfs4_opcount[opnum]++;
  1253. }
  1254. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  1255. void *);
  1256. typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
  1257. typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
  1258. typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
  1259. enum nfsd4_op_flags {
  1260. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  1261. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  1262. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  1263. /* For rfc 5661 section 2.6.3.1.1: */
  1264. OP_HANDLES_WRONGSEC = 1 << 3,
  1265. OP_IS_PUTFH_LIKE = 1 << 4,
  1266. /*
  1267. * These are the ops whose result size we estimate before
  1268. * encoding, to avoid performing an op then not being able to
  1269. * respond or cache a response. This includes writes and setattrs
  1270. * as well as the operations usually called "nonidempotent":
  1271. */
  1272. OP_MODIFIES_SOMETHING = 1 << 5,
  1273. /*
  1274. * Cache compounds containing these ops in the xid-based drc:
  1275. * We use the DRC for compounds containing non-idempotent
  1276. * operations, *except* those that are 4.1-specific (since
  1277. * sessions provide their own EOS), and except for stateful
  1278. * operations other than setclientid and setclientid_confirm
  1279. * (since sequence numbers provide EOS for open, lock, etc in
  1280. * the v4.0 case).
  1281. */
  1282. OP_CACHEME = 1 << 6,
  1283. /*
  1284. * These are ops which clear current state id.
  1285. */
  1286. OP_CLEAR_STATEID = 1 << 7,
  1287. };
  1288. struct nfsd4_operation {
  1289. nfsd4op_func op_func;
  1290. u32 op_flags;
  1291. char *op_name;
  1292. /* Try to get response size before operation */
  1293. nfsd4op_rsize op_rsize_bop;
  1294. stateid_getter op_get_currentstateid;
  1295. stateid_setter op_set_currentstateid;
  1296. };
  1297. static struct nfsd4_operation nfsd4_ops[];
  1298. static const char *nfsd4_op_name(unsigned opnum);
  1299. /*
  1300. * Enforce NFSv4.1 COMPOUND ordering rules:
  1301. *
  1302. * Also note, enforced elsewhere:
  1303. * - SEQUENCE other than as first op results in
  1304. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  1305. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  1306. * (Enforced in nfsd4_bind_conn_to_session().)
  1307. * - DESTROY_SESSION must be the final operation in a compound, if
  1308. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  1309. * (Enforced in nfsd4_destroy_session().)
  1310. */
  1311. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  1312. {
  1313. struct nfsd4_op *op = &args->ops[0];
  1314. /* These ordering requirements don't apply to NFSv4.0: */
  1315. if (args->minorversion == 0)
  1316. return nfs_ok;
  1317. /* This is weird, but OK, not our problem: */
  1318. if (args->opcnt == 0)
  1319. return nfs_ok;
  1320. if (op->status == nfserr_op_illegal)
  1321. return nfs_ok;
  1322. if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  1323. return nfserr_op_not_in_session;
  1324. if (op->opnum == OP_SEQUENCE)
  1325. return nfs_ok;
  1326. if (args->opcnt != 1)
  1327. return nfserr_not_only_op;
  1328. return nfs_ok;
  1329. }
  1330. static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  1331. {
  1332. return &nfsd4_ops[op->opnum];
  1333. }
  1334. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  1335. {
  1336. if (op->opnum == OP_ILLEGAL)
  1337. return false;
  1338. return OPDESC(op)->op_flags & OP_CACHEME;
  1339. }
  1340. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  1341. {
  1342. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1343. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  1344. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  1345. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  1346. struct nfsd4_operation *thisd;
  1347. struct nfsd4_operation *nextd;
  1348. thisd = OPDESC(this);
  1349. /*
  1350. * Most ops check wronsec on our own; only the putfh-like ops
  1351. * have special rules.
  1352. */
  1353. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  1354. return false;
  1355. /*
  1356. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  1357. * put-filehandle operation if we're not going to use the
  1358. * result:
  1359. */
  1360. if (argp->opcnt == resp->opcnt)
  1361. return false;
  1362. if (next->opnum == OP_ILLEGAL)
  1363. return false;
  1364. nextd = OPDESC(next);
  1365. /*
  1366. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  1367. * errors themselves as necessary; others should check for them
  1368. * now:
  1369. */
  1370. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  1371. }
  1372. static void svcxdr_init_encode(struct svc_rqst *rqstp,
  1373. struct nfsd4_compoundres *resp)
  1374. {
  1375. struct xdr_stream *xdr = &resp->xdr;
  1376. struct xdr_buf *buf = &rqstp->rq_res;
  1377. struct kvec *head = buf->head;
  1378. xdr->buf = buf;
  1379. xdr->iov = head;
  1380. xdr->p = head->iov_base + head->iov_len;
  1381. xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
  1382. /* Tail and page_len should be zero at this point: */
  1383. buf->len = buf->head[0].iov_len;
  1384. xdr->scratch.iov_len = 0;
  1385. xdr->page_ptr = buf->pages - 1;
  1386. buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
  1387. - rqstp->rq_auth_slack;
  1388. }
  1389. /*
  1390. * COMPOUND call.
  1391. */
  1392. static __be32
  1393. nfsd4_proc_compound(struct svc_rqst *rqstp,
  1394. struct nfsd4_compoundargs *args,
  1395. struct nfsd4_compoundres *resp)
  1396. {
  1397. struct nfsd4_op *op;
  1398. struct nfsd4_operation *opdesc;
  1399. struct nfsd4_compound_state *cstate = &resp->cstate;
  1400. struct svc_fh *current_fh = &cstate->current_fh;
  1401. struct svc_fh *save_fh = &cstate->save_fh;
  1402. __be32 status;
  1403. svcxdr_init_encode(rqstp, resp);
  1404. resp->tagp = resp->xdr.p;
  1405. /* reserve space for: taglen, tag, and opcnt */
  1406. xdr_reserve_space(&resp->xdr, 8 + args->taglen);
  1407. resp->taglen = args->taglen;
  1408. resp->tag = args->tag;
  1409. resp->rqstp = rqstp;
  1410. cstate->minorversion = args->minorversion;
  1411. fh_init(current_fh, NFS4_FHSIZE);
  1412. fh_init(save_fh, NFS4_FHSIZE);
  1413. /*
  1414. * Don't use the deferral mechanism for NFSv4; compounds make it
  1415. * too hard to avoid non-idempotency problems.
  1416. */
  1417. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1418. /*
  1419. * According to RFC3010, this takes precedence over all other errors.
  1420. */
  1421. status = nfserr_minor_vers_mismatch;
  1422. if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0)
  1423. goto out;
  1424. status = nfs41_check_op_ordering(args);
  1425. if (status) {
  1426. op = &args->ops[0];
  1427. op->status = status;
  1428. resp->opcnt = 1;
  1429. goto encode_op;
  1430. }
  1431. while (!status && resp->opcnt < args->opcnt) {
  1432. op = &args->ops[resp->opcnt++];
  1433. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  1434. resp->opcnt, args->opcnt, op->opnum,
  1435. nfsd4_op_name(op->opnum));
  1436. /*
  1437. * The XDR decode routines may have pre-set op->status;
  1438. * for example, if there is a miscellaneous XDR error
  1439. * it will be set to nfserr_bad_xdr.
  1440. */
  1441. if (op->status) {
  1442. if (op->opnum == OP_OPEN)
  1443. op->status = nfsd4_open_omfg(rqstp, cstate, op);
  1444. goto encode_op;
  1445. }
  1446. opdesc = OPDESC(op);
  1447. if (!current_fh->fh_dentry) {
  1448. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  1449. op->status = nfserr_nofilehandle;
  1450. goto encode_op;
  1451. }
  1452. } else if (current_fh->fh_export->ex_fslocs.migrated &&
  1453. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  1454. op->status = nfserr_moved;
  1455. goto encode_op;
  1456. }
  1457. fh_clear_wcc(current_fh);
  1458. /* If op is non-idempotent */
  1459. if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  1460. /*
  1461. * Don't execute this op if we couldn't encode a
  1462. * succesful reply:
  1463. */
  1464. u32 plen = opdesc->op_rsize_bop(rqstp, op);
  1465. /*
  1466. * Plus if there's another operation, make sure
  1467. * we'll have space to at least encode an error:
  1468. */
  1469. if (resp->opcnt < args->opcnt)
  1470. plen += COMPOUND_ERR_SLACK_SPACE;
  1471. op->status = nfsd4_check_resp_size(resp, plen);
  1472. }
  1473. if (op->status)
  1474. goto encode_op;
  1475. if (opdesc->op_get_currentstateid)
  1476. opdesc->op_get_currentstateid(cstate, &op->u);
  1477. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  1478. /* Only from SEQUENCE */
  1479. if (cstate->status == nfserr_replay_cache) {
  1480. dprintk("%s NFS4.1 replay from cache\n", __func__);
  1481. status = op->status;
  1482. goto out;
  1483. }
  1484. if (!op->status) {
  1485. if (opdesc->op_set_currentstateid)
  1486. opdesc->op_set_currentstateid(cstate, &op->u);
  1487. if (opdesc->op_flags & OP_CLEAR_STATEID)
  1488. clear_current_stateid(cstate);
  1489. if (need_wrongsec_check(rqstp))
  1490. op->status = check_nfsd_access(current_fh->fh_export, rqstp);
  1491. }
  1492. encode_op:
  1493. if (op->status == nfserr_replay_me) {
  1494. op->replay = &cstate->replay_owner->so_replay;
  1495. nfsd4_encode_replay(&resp->xdr, op);
  1496. status = op->status = op->replay->rp_status;
  1497. } else {
  1498. nfsd4_encode_operation(resp, op);
  1499. status = op->status;
  1500. }
  1501. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  1502. args->ops, args->opcnt, resp->opcnt, op->opnum,
  1503. be32_to_cpu(status));
  1504. nfsd4_cstate_clear_replay(cstate);
  1505. nfsd4_increment_op_stats(op->opnum);
  1506. }
  1507. cstate->status = status;
  1508. fh_put(current_fh);
  1509. fh_put(save_fh);
  1510. BUG_ON(cstate->replay_owner);
  1511. out:
  1512. /* Reset deferral mechanism for RPC deferrals */
  1513. set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1514. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1515. return status;
  1516. }
  1517. #define op_encode_hdr_size (2)
  1518. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  1519. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  1520. #define op_encode_change_info_maxsz (5)
  1521. #define nfs4_fattr_bitmap_maxsz (4)
  1522. /* We'll fall back on returning no lockowner if run out of space: */
  1523. #define op_encode_lockowner_maxsz (0)
  1524. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  1525. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1526. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  1527. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  1528. op_encode_ace_maxsz)
  1529. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  1530. static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1531. {
  1532. return (op_encode_hdr_size) * sizeof(__be32);
  1533. }
  1534. static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1535. {
  1536. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  1537. }
  1538. static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1539. {
  1540. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1541. }
  1542. static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1543. {
  1544. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1545. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1546. }
  1547. /*
  1548. * Note since this is an idempotent operation we won't insist on failing
  1549. * the op prematurely if the estimate is too large. We may turn off splice
  1550. * reads unnecessarily.
  1551. */
  1552. static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
  1553. struct nfsd4_op *op)
  1554. {
  1555. u32 *bmap = op->u.getattr.ga_bmval;
  1556. u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
  1557. u32 ret = 0;
  1558. if (bmap0 & FATTR4_WORD0_ACL)
  1559. return svc_max_payload(rqstp);
  1560. if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
  1561. return svc_max_payload(rqstp);
  1562. if (bmap1 & FATTR4_WORD1_OWNER) {
  1563. ret += IDMAP_NAMESZ + 4;
  1564. bmap1 &= ~FATTR4_WORD1_OWNER;
  1565. }
  1566. if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
  1567. ret += IDMAP_NAMESZ + 4;
  1568. bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
  1569. }
  1570. if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
  1571. ret += NFS4_FHSIZE + 4;
  1572. bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
  1573. }
  1574. if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
  1575. ret += NFS4_MAXLABELLEN + 12;
  1576. bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
  1577. }
  1578. /*
  1579. * Largest of remaining attributes are 16 bytes (e.g.,
  1580. * supported_attributes)
  1581. */
  1582. ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
  1583. /* bitmask, length */
  1584. ret += 20;
  1585. return ret;
  1586. }
  1587. static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1588. {
  1589. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1590. * sizeof(__be32);
  1591. }
  1592. static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1593. {
  1594. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  1595. * sizeof(__be32);
  1596. }
  1597. static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1598. {
  1599. return (op_encode_hdr_size + op_encode_stateid_maxsz
  1600. + op_encode_change_info_maxsz + 1
  1601. + nfs4_fattr_bitmap_maxsz
  1602. + op_encode_delegation_maxsz) * sizeof(__be32);
  1603. }
  1604. static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1605. {
  1606. u32 maxcount = 0, rlen = 0;
  1607. maxcount = svc_max_payload(rqstp);
  1608. rlen = min(op->u.read.rd_length, maxcount);
  1609. return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  1610. }
  1611. static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1612. {
  1613. u32 maxcount = 0, rlen = 0;
  1614. maxcount = svc_max_payload(rqstp);
  1615. rlen = min(op->u.readdir.rd_maxcount, maxcount);
  1616. return (op_encode_hdr_size + op_encode_verifier_maxsz +
  1617. XDR_QUADLEN(rlen)) * sizeof(__be32);
  1618. }
  1619. static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1620. {
  1621. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1622. * sizeof(__be32);
  1623. }
  1624. static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1625. {
  1626. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1627. + op_encode_change_info_maxsz) * sizeof(__be32);
  1628. }
  1629. static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
  1630. struct nfsd4_op *op)
  1631. {
  1632. return (op_encode_hdr_size
  1633. + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
  1634. }
  1635. static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1636. {
  1637. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1638. }
  1639. static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1640. {
  1641. return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
  1642. sizeof(__be32);
  1643. }
  1644. static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1645. {
  1646. return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
  1647. }
  1648. static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1649. {
  1650. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  1651. 1 + 1 + /* eir_flags, spr_how */\
  1652. 4 + /* spo_must_enforce & _allow with bitmap */\
  1653. 2 + /*eir_server_owner.so_minor_id */\
  1654. /* eir_server_owner.so_major_id<> */\
  1655. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1656. /* eir_server_scope<> */\
  1657. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1658. 1 + /* eir_server_impl_id array length */\
  1659. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  1660. }
  1661. static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1662. {
  1663. return (op_encode_hdr_size + \
  1664. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  1665. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  1666. }
  1667. static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1668. {
  1669. return (op_encode_hdr_size + \
  1670. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  1671. 2 + /* csr_sequence, csr_flags */\
  1672. op_encode_channel_attrs_maxsz + \
  1673. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  1674. }
  1675. #ifdef CONFIG_NFSD_PNFS
  1676. /*
  1677. * At this stage we don't really know what layout driver will handle the request,
  1678. * so we need to define an arbitrary upper bound here.
  1679. */
  1680. #define MAX_LAYOUT_SIZE 128
  1681. static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1682. {
  1683. return (op_encode_hdr_size +
  1684. 1 /* logr_return_on_close */ +
  1685. op_encode_stateid_maxsz +
  1686. 1 /* nr of layouts */ +
  1687. MAX_LAYOUT_SIZE) * sizeof(__be32);
  1688. }
  1689. static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1690. {
  1691. return (op_encode_hdr_size +
  1692. 1 /* locr_newsize */ +
  1693. 2 /* ns_size */) * sizeof(__be32);
  1694. }
  1695. static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1696. {
  1697. return (op_encode_hdr_size +
  1698. 1 /* lrs_stateid */ +
  1699. op_encode_stateid_maxsz) * sizeof(__be32);
  1700. }
  1701. #endif /* CONFIG_NFSD_PNFS */
  1702. static struct nfsd4_operation nfsd4_ops[] = {
  1703. [OP_ACCESS] = {
  1704. .op_func = (nfsd4op_func)nfsd4_access,
  1705. .op_name = "OP_ACCESS",
  1706. },
  1707. [OP_CLOSE] = {
  1708. .op_func = (nfsd4op_func)nfsd4_close,
  1709. .op_flags = OP_MODIFIES_SOMETHING,
  1710. .op_name = "OP_CLOSE",
  1711. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1712. .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
  1713. .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
  1714. },
  1715. [OP_COMMIT] = {
  1716. .op_func = (nfsd4op_func)nfsd4_commit,
  1717. .op_flags = OP_MODIFIES_SOMETHING,
  1718. .op_name = "OP_COMMIT",
  1719. .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
  1720. },
  1721. [OP_CREATE] = {
  1722. .op_func = (nfsd4op_func)nfsd4_create,
  1723. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
  1724. .op_name = "OP_CREATE",
  1725. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
  1726. },
  1727. [OP_DELEGRETURN] = {
  1728. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1729. .op_flags = OP_MODIFIES_SOMETHING,
  1730. .op_name = "OP_DELEGRETURN",
  1731. .op_rsize_bop = nfsd4_only_status_rsize,
  1732. .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
  1733. },
  1734. [OP_GETATTR] = {
  1735. .op_func = (nfsd4op_func)nfsd4_getattr,
  1736. .op_flags = ALLOWED_ON_ABSENT_FS,
  1737. .op_rsize_bop = nfsd4_getattr_rsize,
  1738. .op_name = "OP_GETATTR",
  1739. },
  1740. [OP_GETFH] = {
  1741. .op_func = (nfsd4op_func)nfsd4_getfh,
  1742. .op_name = "OP_GETFH",
  1743. },
  1744. [OP_LINK] = {
  1745. .op_func = (nfsd4op_func)nfsd4_link,
  1746. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  1747. | OP_CACHEME,
  1748. .op_name = "OP_LINK",
  1749. .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
  1750. },
  1751. [OP_LOCK] = {
  1752. .op_func = (nfsd4op_func)nfsd4_lock,
  1753. .op_flags = OP_MODIFIES_SOMETHING,
  1754. .op_name = "OP_LOCK",
  1755. .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
  1756. .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
  1757. },
  1758. [OP_LOCKT] = {
  1759. .op_func = (nfsd4op_func)nfsd4_lockt,
  1760. .op_name = "OP_LOCKT",
  1761. },
  1762. [OP_LOCKU] = {
  1763. .op_func = (nfsd4op_func)nfsd4_locku,
  1764. .op_flags = OP_MODIFIES_SOMETHING,
  1765. .op_name = "OP_LOCKU",
  1766. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1767. .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
  1768. },
  1769. [OP_LOOKUP] = {
  1770. .op_func = (nfsd4op_func)nfsd4_lookup,
  1771. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1772. .op_name = "OP_LOOKUP",
  1773. },
  1774. [OP_LOOKUPP] = {
  1775. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1776. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1777. .op_name = "OP_LOOKUPP",
  1778. },
  1779. [OP_NVERIFY] = {
  1780. .op_func = (nfsd4op_func)nfsd4_nverify,
  1781. .op_name = "OP_NVERIFY",
  1782. },
  1783. [OP_OPEN] = {
  1784. .op_func = (nfsd4op_func)nfsd4_open,
  1785. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1786. .op_name = "OP_OPEN",
  1787. .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
  1788. .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
  1789. },
  1790. [OP_OPEN_CONFIRM] = {
  1791. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1792. .op_flags = OP_MODIFIES_SOMETHING,
  1793. .op_name = "OP_OPEN_CONFIRM",
  1794. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1795. },
  1796. [OP_OPEN_DOWNGRADE] = {
  1797. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1798. .op_flags = OP_MODIFIES_SOMETHING,
  1799. .op_name = "OP_OPEN_DOWNGRADE",
  1800. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1801. .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
  1802. .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
  1803. },
  1804. [OP_PUTFH] = {
  1805. .op_func = (nfsd4op_func)nfsd4_putfh,
  1806. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1807. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1808. .op_name = "OP_PUTFH",
  1809. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1810. },
  1811. [OP_PUTPUBFH] = {
  1812. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1813. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1814. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1815. .op_name = "OP_PUTPUBFH",
  1816. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1817. },
  1818. [OP_PUTROOTFH] = {
  1819. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1820. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1821. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1822. .op_name = "OP_PUTROOTFH",
  1823. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1824. },
  1825. [OP_READ] = {
  1826. .op_func = (nfsd4op_func)nfsd4_read,
  1827. .op_name = "OP_READ",
  1828. .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
  1829. .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
  1830. },
  1831. [OP_READDIR] = {
  1832. .op_func = (nfsd4op_func)nfsd4_readdir,
  1833. .op_name = "OP_READDIR",
  1834. .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
  1835. },
  1836. [OP_READLINK] = {
  1837. .op_func = (nfsd4op_func)nfsd4_readlink,
  1838. .op_name = "OP_READLINK",
  1839. },
  1840. [OP_REMOVE] = {
  1841. .op_func = (nfsd4op_func)nfsd4_remove,
  1842. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1843. .op_name = "OP_REMOVE",
  1844. .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
  1845. },
  1846. [OP_RENAME] = {
  1847. .op_func = (nfsd4op_func)nfsd4_rename,
  1848. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1849. .op_name = "OP_RENAME",
  1850. .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
  1851. },
  1852. [OP_RENEW] = {
  1853. .op_func = (nfsd4op_func)nfsd4_renew,
  1854. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1855. | OP_MODIFIES_SOMETHING,
  1856. .op_name = "OP_RENEW",
  1857. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1858. },
  1859. [OP_RESTOREFH] = {
  1860. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1861. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1862. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1863. .op_name = "OP_RESTOREFH",
  1864. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1865. },
  1866. [OP_SAVEFH] = {
  1867. .op_func = (nfsd4op_func)nfsd4_savefh,
  1868. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1869. .op_name = "OP_SAVEFH",
  1870. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1871. },
  1872. [OP_SECINFO] = {
  1873. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1874. .op_flags = OP_HANDLES_WRONGSEC,
  1875. .op_name = "OP_SECINFO",
  1876. },
  1877. [OP_SETATTR] = {
  1878. .op_func = (nfsd4op_func)nfsd4_setattr,
  1879. .op_name = "OP_SETATTR",
  1880. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1881. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
  1882. .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
  1883. },
  1884. [OP_SETCLIENTID] = {
  1885. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1886. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1887. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1888. .op_name = "OP_SETCLIENTID",
  1889. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
  1890. },
  1891. [OP_SETCLIENTID_CONFIRM] = {
  1892. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1893. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1894. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1895. .op_name = "OP_SETCLIENTID_CONFIRM",
  1896. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1897. },
  1898. [OP_VERIFY] = {
  1899. .op_func = (nfsd4op_func)nfsd4_verify,
  1900. .op_name = "OP_VERIFY",
  1901. },
  1902. [OP_WRITE] = {
  1903. .op_func = (nfsd4op_func)nfsd4_write,
  1904. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1905. .op_name = "OP_WRITE",
  1906. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  1907. .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
  1908. },
  1909. [OP_RELEASE_LOCKOWNER] = {
  1910. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1911. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1912. | OP_MODIFIES_SOMETHING,
  1913. .op_name = "OP_RELEASE_LOCKOWNER",
  1914. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1915. },
  1916. /* NFSv4.1 operations */
  1917. [OP_EXCHANGE_ID] = {
  1918. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1919. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1920. | OP_MODIFIES_SOMETHING,
  1921. .op_name = "OP_EXCHANGE_ID",
  1922. .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
  1923. },
  1924. [OP_BACKCHANNEL_CTL] = {
  1925. .op_func = (nfsd4op_func)nfsd4_backchannel_ctl,
  1926. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1927. .op_name = "OP_BACKCHANNEL_CTL",
  1928. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1929. },
  1930. [OP_BIND_CONN_TO_SESSION] = {
  1931. .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
  1932. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1933. | OP_MODIFIES_SOMETHING,
  1934. .op_name = "OP_BIND_CONN_TO_SESSION",
  1935. .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
  1936. },
  1937. [OP_CREATE_SESSION] = {
  1938. .op_func = (nfsd4op_func)nfsd4_create_session,
  1939. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1940. | OP_MODIFIES_SOMETHING,
  1941. .op_name = "OP_CREATE_SESSION",
  1942. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
  1943. },
  1944. [OP_DESTROY_SESSION] = {
  1945. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1946. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1947. | OP_MODIFIES_SOMETHING,
  1948. .op_name = "OP_DESTROY_SESSION",
  1949. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1950. },
  1951. [OP_SEQUENCE] = {
  1952. .op_func = (nfsd4op_func)nfsd4_sequence,
  1953. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1954. .op_name = "OP_SEQUENCE",
  1955. .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize,
  1956. },
  1957. [OP_DESTROY_CLIENTID] = {
  1958. .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
  1959. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1960. | OP_MODIFIES_SOMETHING,
  1961. .op_name = "OP_DESTROY_CLIENTID",
  1962. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1963. },
  1964. [OP_RECLAIM_COMPLETE] = {
  1965. .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
  1966. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1967. .op_name = "OP_RECLAIM_COMPLETE",
  1968. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1969. },
  1970. [OP_SECINFO_NO_NAME] = {
  1971. .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
  1972. .op_flags = OP_HANDLES_WRONGSEC,
  1973. .op_name = "OP_SECINFO_NO_NAME",
  1974. },
  1975. [OP_TEST_STATEID] = {
  1976. .op_func = (nfsd4op_func)nfsd4_test_stateid,
  1977. .op_flags = ALLOWED_WITHOUT_FH,
  1978. .op_name = "OP_TEST_STATEID",
  1979. },
  1980. [OP_FREE_STATEID] = {
  1981. .op_func = (nfsd4op_func)nfsd4_free_stateid,
  1982. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1983. .op_name = "OP_FREE_STATEID",
  1984. .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid,
  1985. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1986. },
  1987. #ifdef CONFIG_NFSD_PNFS
  1988. [OP_GETDEVICEINFO] = {
  1989. .op_func = (nfsd4op_func)nfsd4_getdeviceinfo,
  1990. .op_flags = ALLOWED_WITHOUT_FH,
  1991. .op_name = "OP_GETDEVICEINFO",
  1992. },
  1993. [OP_LAYOUTGET] = {
  1994. .op_func = (nfsd4op_func)nfsd4_layoutget,
  1995. .op_flags = OP_MODIFIES_SOMETHING,
  1996. .op_name = "OP_LAYOUTGET",
  1997. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize,
  1998. },
  1999. [OP_LAYOUTCOMMIT] = {
  2000. .op_func = (nfsd4op_func)nfsd4_layoutcommit,
  2001. .op_flags = OP_MODIFIES_SOMETHING,
  2002. .op_name = "OP_LAYOUTCOMMIT",
  2003. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize,
  2004. },
  2005. [OP_LAYOUTRETURN] = {
  2006. .op_func = (nfsd4op_func)nfsd4_layoutreturn,
  2007. .op_flags = OP_MODIFIES_SOMETHING,
  2008. .op_name = "OP_LAYOUTRETURN",
  2009. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize,
  2010. },
  2011. #endif /* CONFIG_NFSD_PNFS */
  2012. /* NFSv4.2 operations */
  2013. [OP_ALLOCATE] = {
  2014. .op_func = (nfsd4op_func)nfsd4_allocate,
  2015. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2016. .op_name = "OP_ALLOCATE",
  2017. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2018. },
  2019. [OP_DEALLOCATE] = {
  2020. .op_func = (nfsd4op_func)nfsd4_deallocate,
  2021. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2022. .op_name = "OP_DEALLOCATE",
  2023. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2024. },
  2025. [OP_SEEK] = {
  2026. .op_func = (nfsd4op_func)nfsd4_seek,
  2027. .op_name = "OP_SEEK",
  2028. },
  2029. };
  2030. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
  2031. {
  2032. struct nfsd4_operation *opdesc;
  2033. nfsd4op_rsize estimator;
  2034. if (op->opnum == OP_ILLEGAL)
  2035. return op_encode_hdr_size * sizeof(__be32);
  2036. opdesc = OPDESC(op);
  2037. estimator = opdesc->op_rsize_bop;
  2038. return estimator ? estimator(rqstp, op) : PAGE_SIZE;
  2039. }
  2040. void warn_on_nonidempotent_op(struct nfsd4_op *op)
  2041. {
  2042. if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
  2043. pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
  2044. op->opnum, nfsd4_op_name(op->opnum));
  2045. WARN_ON_ONCE(1);
  2046. }
  2047. }
  2048. static const char *nfsd4_op_name(unsigned opnum)
  2049. {
  2050. if (opnum < ARRAY_SIZE(nfsd4_ops))
  2051. return nfsd4_ops[opnum].op_name;
  2052. return "unknown_operation";
  2053. }
  2054. #define nfsd4_voidres nfsd4_voidargs
  2055. struct nfsd4_voidargs { int dummy; };
  2056. static struct svc_procedure nfsd_procedures4[2] = {
  2057. [NFSPROC4_NULL] = {
  2058. .pc_func = (svc_procfunc) nfsd4_proc_null,
  2059. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  2060. .pc_argsize = sizeof(struct nfsd4_voidargs),
  2061. .pc_ressize = sizeof(struct nfsd4_voidres),
  2062. .pc_cachetype = RC_NOCACHE,
  2063. .pc_xdrressize = 1,
  2064. },
  2065. [NFSPROC4_COMPOUND] = {
  2066. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  2067. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  2068. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  2069. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  2070. .pc_ressize = sizeof(struct nfsd4_compoundres),
  2071. .pc_release = nfsd4_release_compoundargs,
  2072. .pc_cachetype = RC_NOCACHE,
  2073. .pc_xdrressize = NFSD_BUFSIZE/4,
  2074. },
  2075. };
  2076. struct svc_version nfsd_version4 = {
  2077. .vs_vers = 4,
  2078. .vs_nproc = 2,
  2079. .vs_proc = nfsd_procedures4,
  2080. .vs_dispatch = nfsd_dispatch,
  2081. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  2082. .vs_rpcb_optnl = 1,
  2083. };
  2084. /*
  2085. * Local variables:
  2086. * c-basic-offset: 8
  2087. * End:
  2088. */