nfs4proc.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  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. inode_lock(inode);
  55. status = security_inode_setsecctx(resfh->fh_dentry,
  56. label->data, label->len);
  57. inode_unlock(inode);
  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, &cstate->current_fh,
  676. &read->rd_stateid, RD_STATE,
  677. &read->rd_filp, &read->rd_tmp_file);
  678. if (status) {
  679. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  680. goto out;
  681. }
  682. status = nfs_ok;
  683. out:
  684. read->rd_rqstp = rqstp;
  685. read->rd_fhp = &cstate->current_fh;
  686. return status;
  687. }
  688. static __be32
  689. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  690. struct nfsd4_readdir *readdir)
  691. {
  692. u64 cookie = readdir->rd_cookie;
  693. static const nfs4_verifier zeroverf;
  694. /* no need to check permission - this will be done in nfsd_readdir() */
  695. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  696. return nfserr_inval;
  697. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  698. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  699. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  700. if ((cookie == 1) || (cookie == 2) ||
  701. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  702. return nfserr_bad_cookie;
  703. readdir->rd_rqstp = rqstp;
  704. readdir->rd_fhp = &cstate->current_fh;
  705. return nfs_ok;
  706. }
  707. static __be32
  708. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  709. struct nfsd4_readlink *readlink)
  710. {
  711. readlink->rl_rqstp = rqstp;
  712. readlink->rl_fhp = &cstate->current_fh;
  713. return nfs_ok;
  714. }
  715. static __be32
  716. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  717. struct nfsd4_remove *remove)
  718. {
  719. __be32 status;
  720. if (opens_in_grace(SVC_NET(rqstp)))
  721. return nfserr_grace;
  722. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  723. remove->rm_name, remove->rm_namelen);
  724. if (!status) {
  725. fh_unlock(&cstate->current_fh);
  726. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  727. }
  728. return status;
  729. }
  730. static __be32
  731. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  732. struct nfsd4_rename *rename)
  733. {
  734. __be32 status = nfserr_nofilehandle;
  735. if (!cstate->save_fh.fh_dentry)
  736. return status;
  737. if (opens_in_grace(SVC_NET(rqstp)) &&
  738. !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
  739. return nfserr_grace;
  740. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  741. rename->rn_snamelen, &cstate->current_fh,
  742. rename->rn_tname, rename->rn_tnamelen);
  743. if (status)
  744. return status;
  745. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  746. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  747. return nfs_ok;
  748. }
  749. static __be32
  750. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  751. struct nfsd4_secinfo *secinfo)
  752. {
  753. struct svc_export *exp;
  754. struct dentry *dentry;
  755. __be32 err;
  756. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  757. if (err)
  758. return err;
  759. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  760. secinfo->si_name, secinfo->si_namelen,
  761. &exp, &dentry);
  762. if (err)
  763. return err;
  764. fh_unlock(&cstate->current_fh);
  765. if (d_really_is_negative(dentry)) {
  766. exp_put(exp);
  767. err = nfserr_noent;
  768. } else
  769. secinfo->si_exp = exp;
  770. dput(dentry);
  771. if (cstate->minorversion)
  772. /* See rfc 5661 section 2.6.3.1.1.8 */
  773. fh_put(&cstate->current_fh);
  774. return err;
  775. }
  776. static __be32
  777. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  778. struct nfsd4_secinfo_no_name *sin)
  779. {
  780. __be32 err;
  781. switch (sin->sin_style) {
  782. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  783. break;
  784. case NFS4_SECINFO_STYLE4_PARENT:
  785. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  786. if (err)
  787. return err;
  788. break;
  789. default:
  790. return nfserr_inval;
  791. }
  792. sin->sin_exp = exp_get(cstate->current_fh.fh_export);
  793. fh_put(&cstate->current_fh);
  794. return nfs_ok;
  795. }
  796. static __be32
  797. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  798. struct nfsd4_setattr *setattr)
  799. {
  800. __be32 status = nfs_ok;
  801. int err;
  802. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  803. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  804. &cstate->current_fh, &setattr->sa_stateid,
  805. 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, &cstate->current_fh,
  862. stateid, WR_STATE, &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_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  881. struct nfsd4_clone *clone)
  882. {
  883. struct file *src, *dst;
  884. __be32 status;
  885. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
  886. &clone->cl_src_stateid, RD_STATE,
  887. &src, NULL);
  888. if (status) {
  889. dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
  890. goto out;
  891. }
  892. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  893. &clone->cl_dst_stateid, WR_STATE,
  894. &dst, NULL);
  895. if (status) {
  896. dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
  897. goto out_put_src;
  898. }
  899. /* fix up for NFS-specific error code */
  900. if (!S_ISREG(file_inode(src)->i_mode) ||
  901. !S_ISREG(file_inode(dst)->i_mode)) {
  902. status = nfserr_wrong_type;
  903. goto out_put_dst;
  904. }
  905. status = nfsd4_clone_file_range(src, clone->cl_src_pos,
  906. dst, clone->cl_dst_pos, clone->cl_count);
  907. out_put_dst:
  908. fput(dst);
  909. out_put_src:
  910. fput(src);
  911. out:
  912. return status;
  913. }
  914. static __be32
  915. nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  916. struct nfsd4_fallocate *fallocate, int flags)
  917. {
  918. __be32 status = nfserr_notsupp;
  919. struct file *file;
  920. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  921. &fallocate->falloc_stateid,
  922. WR_STATE, &file, NULL);
  923. if (status != nfs_ok) {
  924. dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
  925. return status;
  926. }
  927. status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
  928. fallocate->falloc_offset,
  929. fallocate->falloc_length,
  930. flags);
  931. fput(file);
  932. return status;
  933. }
  934. static __be32
  935. nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  936. struct nfsd4_fallocate *fallocate)
  937. {
  938. return nfsd4_fallocate(rqstp, cstate, fallocate, 0);
  939. }
  940. static __be32
  941. nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  942. struct nfsd4_fallocate *fallocate)
  943. {
  944. return nfsd4_fallocate(rqstp, cstate, fallocate,
  945. FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
  946. }
  947. static __be32
  948. nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  949. struct nfsd4_seek *seek)
  950. {
  951. int whence;
  952. __be32 status;
  953. struct file *file;
  954. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  955. &seek->seek_stateid,
  956. RD_STATE, &file, NULL);
  957. if (status) {
  958. dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
  959. return status;
  960. }
  961. switch (seek->seek_whence) {
  962. case NFS4_CONTENT_DATA:
  963. whence = SEEK_DATA;
  964. break;
  965. case NFS4_CONTENT_HOLE:
  966. whence = SEEK_HOLE;
  967. break;
  968. default:
  969. status = nfserr_union_notsupp;
  970. goto out;
  971. }
  972. /*
  973. * Note: This call does change file->f_pos, but nothing in NFSD
  974. * should ever file->f_pos.
  975. */
  976. seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
  977. if (seek->seek_pos < 0)
  978. status = nfserrno(seek->seek_pos);
  979. else if (seek->seek_pos >= i_size_read(file_inode(file)))
  980. seek->seek_eof = true;
  981. out:
  982. fput(file);
  983. return status;
  984. }
  985. /* This routine never returns NFS_OK! If there are no other errors, it
  986. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  987. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  988. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  989. */
  990. static __be32
  991. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  992. struct nfsd4_verify *verify)
  993. {
  994. __be32 *buf, *p;
  995. int count;
  996. __be32 status;
  997. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  998. if (status)
  999. return status;
  1000. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  1001. if (status)
  1002. return status;
  1003. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  1004. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  1005. return nfserr_inval;
  1006. if (verify->ve_attrlen & 3)
  1007. return nfserr_inval;
  1008. /* count in words:
  1009. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  1010. */
  1011. count = 4 + (verify->ve_attrlen >> 2);
  1012. buf = kmalloc(count << 2, GFP_KERNEL);
  1013. if (!buf)
  1014. return nfserr_jukebox;
  1015. p = buf;
  1016. status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
  1017. cstate->current_fh.fh_export,
  1018. cstate->current_fh.fh_dentry,
  1019. verify->ve_bmval,
  1020. rqstp, 0);
  1021. /*
  1022. * If nfsd4_encode_fattr() ran out of space, assume that's because
  1023. * the attributes are longer (hence different) than those given:
  1024. */
  1025. if (status == nfserr_resource)
  1026. status = nfserr_not_same;
  1027. if (status)
  1028. goto out_kfree;
  1029. /* skip bitmap */
  1030. p = buf + 1 + ntohl(buf[0]);
  1031. status = nfserr_not_same;
  1032. if (ntohl(*p++) != verify->ve_attrlen)
  1033. goto out_kfree;
  1034. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  1035. status = nfserr_same;
  1036. out_kfree:
  1037. kfree(buf);
  1038. return status;
  1039. }
  1040. static __be32
  1041. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1042. struct nfsd4_verify *verify)
  1043. {
  1044. __be32 status;
  1045. status = _nfsd4_verify(rqstp, cstate, verify);
  1046. return status == nfserr_not_same ? nfs_ok : status;
  1047. }
  1048. static __be32
  1049. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1050. struct nfsd4_verify *verify)
  1051. {
  1052. __be32 status;
  1053. status = _nfsd4_verify(rqstp, cstate, verify);
  1054. return status == nfserr_same ? nfs_ok : status;
  1055. }
  1056. #ifdef CONFIG_NFSD_PNFS
  1057. static const struct nfsd4_layout_ops *
  1058. nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
  1059. {
  1060. if (!exp->ex_layout_type) {
  1061. dprintk("%s: export does not support pNFS\n", __func__);
  1062. return NULL;
  1063. }
  1064. if (exp->ex_layout_type != layout_type) {
  1065. dprintk("%s: layout type %d not supported\n",
  1066. __func__, layout_type);
  1067. return NULL;
  1068. }
  1069. return nfsd4_layout_ops[layout_type];
  1070. }
  1071. static __be32
  1072. nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
  1073. struct nfsd4_compound_state *cstate,
  1074. struct nfsd4_getdeviceinfo *gdp)
  1075. {
  1076. const struct nfsd4_layout_ops *ops;
  1077. struct nfsd4_deviceid_map *map;
  1078. struct svc_export *exp;
  1079. __be32 nfserr;
  1080. dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
  1081. __func__,
  1082. gdp->gd_layout_type,
  1083. gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
  1084. gdp->gd_maxcount);
  1085. map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
  1086. if (!map) {
  1087. dprintk("%s: couldn't find device ID to export mapping!\n",
  1088. __func__);
  1089. return nfserr_noent;
  1090. }
  1091. exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
  1092. if (IS_ERR(exp)) {
  1093. dprintk("%s: could not find device id\n", __func__);
  1094. return nfserr_noent;
  1095. }
  1096. nfserr = nfserr_layoutunavailable;
  1097. ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
  1098. if (!ops)
  1099. goto out;
  1100. nfserr = nfs_ok;
  1101. if (gdp->gd_maxcount != 0) {
  1102. nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
  1103. cstate->session->se_client, gdp);
  1104. }
  1105. gdp->gd_notify_types &= ops->notify_types;
  1106. out:
  1107. exp_put(exp);
  1108. return nfserr;
  1109. }
  1110. static __be32
  1111. nfsd4_layoutget(struct svc_rqst *rqstp,
  1112. struct nfsd4_compound_state *cstate,
  1113. struct nfsd4_layoutget *lgp)
  1114. {
  1115. struct svc_fh *current_fh = &cstate->current_fh;
  1116. const struct nfsd4_layout_ops *ops;
  1117. struct nfs4_layout_stateid *ls;
  1118. __be32 nfserr;
  1119. int accmode;
  1120. switch (lgp->lg_seg.iomode) {
  1121. case IOMODE_READ:
  1122. accmode = NFSD_MAY_READ;
  1123. break;
  1124. case IOMODE_RW:
  1125. accmode = NFSD_MAY_READ | NFSD_MAY_WRITE;
  1126. break;
  1127. default:
  1128. dprintk("%s: invalid iomode %d\n",
  1129. __func__, lgp->lg_seg.iomode);
  1130. nfserr = nfserr_badiomode;
  1131. goto out;
  1132. }
  1133. nfserr = fh_verify(rqstp, current_fh, 0, accmode);
  1134. if (nfserr)
  1135. goto out;
  1136. nfserr = nfserr_layoutunavailable;
  1137. ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
  1138. if (!ops)
  1139. goto out;
  1140. /*
  1141. * Verify minlength and range as per RFC5661:
  1142. * o If loga_length is less than loga_minlength,
  1143. * the metadata server MUST return NFS4ERR_INVAL.
  1144. * o If the sum of loga_offset and loga_minlength exceeds
  1145. * NFS4_UINT64_MAX, and loga_minlength is not
  1146. * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
  1147. * o If the sum of loga_offset and loga_length exceeds
  1148. * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
  1149. * the error NFS4ERR_INVAL MUST result.
  1150. */
  1151. nfserr = nfserr_inval;
  1152. if (lgp->lg_seg.length < lgp->lg_minlength ||
  1153. (lgp->lg_minlength != NFS4_MAX_UINT64 &&
  1154. lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
  1155. (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
  1156. lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
  1157. goto out;
  1158. if (lgp->lg_seg.length == 0)
  1159. goto out;
  1160. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
  1161. true, lgp->lg_layout_type, &ls);
  1162. if (nfserr) {
  1163. trace_layout_get_lookup_fail(&lgp->lg_sid);
  1164. goto out;
  1165. }
  1166. nfserr = nfserr_recallconflict;
  1167. if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
  1168. goto out_put_stid;
  1169. nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
  1170. current_fh, lgp);
  1171. if (nfserr)
  1172. goto out_put_stid;
  1173. nfserr = nfsd4_insert_layout(lgp, ls);
  1174. out_put_stid:
  1175. mutex_unlock(&ls->ls_mutex);
  1176. nfs4_put_stid(&ls->ls_stid);
  1177. out:
  1178. return nfserr;
  1179. }
  1180. static __be32
  1181. nfsd4_layoutcommit(struct svc_rqst *rqstp,
  1182. struct nfsd4_compound_state *cstate,
  1183. struct nfsd4_layoutcommit *lcp)
  1184. {
  1185. const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
  1186. struct svc_fh *current_fh = &cstate->current_fh;
  1187. const struct nfsd4_layout_ops *ops;
  1188. loff_t new_size = lcp->lc_last_wr + 1;
  1189. struct inode *inode;
  1190. struct nfs4_layout_stateid *ls;
  1191. __be32 nfserr;
  1192. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
  1193. if (nfserr)
  1194. goto out;
  1195. nfserr = nfserr_layoutunavailable;
  1196. ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
  1197. if (!ops)
  1198. goto out;
  1199. inode = d_inode(current_fh->fh_dentry);
  1200. nfserr = nfserr_inval;
  1201. if (new_size <= seg->offset) {
  1202. dprintk("pnfsd: last write before layout segment\n");
  1203. goto out;
  1204. }
  1205. if (new_size > seg->offset + seg->length) {
  1206. dprintk("pnfsd: last write beyond layout segment\n");
  1207. goto out;
  1208. }
  1209. if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
  1210. dprintk("pnfsd: layoutcommit beyond EOF\n");
  1211. goto out;
  1212. }
  1213. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
  1214. false, lcp->lc_layout_type,
  1215. &ls);
  1216. if (nfserr) {
  1217. trace_layout_commit_lookup_fail(&lcp->lc_sid);
  1218. /* fixup error code as per RFC5661 */
  1219. if (nfserr == nfserr_bad_stateid)
  1220. nfserr = nfserr_badlayout;
  1221. goto out;
  1222. }
  1223. /* LAYOUTCOMMIT does not require any serialization */
  1224. mutex_unlock(&ls->ls_mutex);
  1225. if (new_size > i_size_read(inode)) {
  1226. lcp->lc_size_chg = 1;
  1227. lcp->lc_newsize = new_size;
  1228. } else {
  1229. lcp->lc_size_chg = 0;
  1230. }
  1231. nfserr = ops->proc_layoutcommit(inode, lcp);
  1232. nfs4_put_stid(&ls->ls_stid);
  1233. out:
  1234. return nfserr;
  1235. }
  1236. static __be32
  1237. nfsd4_layoutreturn(struct svc_rqst *rqstp,
  1238. struct nfsd4_compound_state *cstate,
  1239. struct nfsd4_layoutreturn *lrp)
  1240. {
  1241. struct svc_fh *current_fh = &cstate->current_fh;
  1242. __be32 nfserr;
  1243. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
  1244. if (nfserr)
  1245. goto out;
  1246. nfserr = nfserr_layoutunavailable;
  1247. if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
  1248. goto out;
  1249. switch (lrp->lr_seg.iomode) {
  1250. case IOMODE_READ:
  1251. case IOMODE_RW:
  1252. case IOMODE_ANY:
  1253. break;
  1254. default:
  1255. dprintk("%s: invalid iomode %d\n", __func__,
  1256. lrp->lr_seg.iomode);
  1257. nfserr = nfserr_inval;
  1258. goto out;
  1259. }
  1260. switch (lrp->lr_return_type) {
  1261. case RETURN_FILE:
  1262. nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
  1263. break;
  1264. case RETURN_FSID:
  1265. case RETURN_ALL:
  1266. nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
  1267. break;
  1268. default:
  1269. dprintk("%s: invalid return_type %d\n", __func__,
  1270. lrp->lr_return_type);
  1271. nfserr = nfserr_inval;
  1272. break;
  1273. }
  1274. out:
  1275. return nfserr;
  1276. }
  1277. #endif /* CONFIG_NFSD_PNFS */
  1278. /*
  1279. * NULL call.
  1280. */
  1281. static __be32
  1282. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  1283. {
  1284. return nfs_ok;
  1285. }
  1286. static inline void nfsd4_increment_op_stats(u32 opnum)
  1287. {
  1288. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  1289. nfsdstats.nfs4_opcount[opnum]++;
  1290. }
  1291. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  1292. void *);
  1293. typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
  1294. typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
  1295. typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
  1296. enum nfsd4_op_flags {
  1297. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  1298. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  1299. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  1300. /* For rfc 5661 section 2.6.3.1.1: */
  1301. OP_HANDLES_WRONGSEC = 1 << 3,
  1302. OP_IS_PUTFH_LIKE = 1 << 4,
  1303. /*
  1304. * These are the ops whose result size we estimate before
  1305. * encoding, to avoid performing an op then not being able to
  1306. * respond or cache a response. This includes writes and setattrs
  1307. * as well as the operations usually called "nonidempotent":
  1308. */
  1309. OP_MODIFIES_SOMETHING = 1 << 5,
  1310. /*
  1311. * Cache compounds containing these ops in the xid-based drc:
  1312. * We use the DRC for compounds containing non-idempotent
  1313. * operations, *except* those that are 4.1-specific (since
  1314. * sessions provide their own EOS), and except for stateful
  1315. * operations other than setclientid and setclientid_confirm
  1316. * (since sequence numbers provide EOS for open, lock, etc in
  1317. * the v4.0 case).
  1318. */
  1319. OP_CACHEME = 1 << 6,
  1320. /*
  1321. * These are ops which clear current state id.
  1322. */
  1323. OP_CLEAR_STATEID = 1 << 7,
  1324. };
  1325. struct nfsd4_operation {
  1326. nfsd4op_func op_func;
  1327. u32 op_flags;
  1328. char *op_name;
  1329. /* Try to get response size before operation */
  1330. nfsd4op_rsize op_rsize_bop;
  1331. stateid_getter op_get_currentstateid;
  1332. stateid_setter op_set_currentstateid;
  1333. };
  1334. static struct nfsd4_operation nfsd4_ops[];
  1335. static const char *nfsd4_op_name(unsigned opnum);
  1336. /*
  1337. * Enforce NFSv4.1 COMPOUND ordering rules:
  1338. *
  1339. * Also note, enforced elsewhere:
  1340. * - SEQUENCE other than as first op results in
  1341. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  1342. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  1343. * (Enforced in nfsd4_bind_conn_to_session().)
  1344. * - DESTROY_SESSION must be the final operation in a compound, if
  1345. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  1346. * (Enforced in nfsd4_destroy_session().)
  1347. */
  1348. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  1349. {
  1350. struct nfsd4_op *op = &args->ops[0];
  1351. /* These ordering requirements don't apply to NFSv4.0: */
  1352. if (args->minorversion == 0)
  1353. return nfs_ok;
  1354. /* This is weird, but OK, not our problem: */
  1355. if (args->opcnt == 0)
  1356. return nfs_ok;
  1357. if (op->status == nfserr_op_illegal)
  1358. return nfs_ok;
  1359. if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  1360. return nfserr_op_not_in_session;
  1361. if (op->opnum == OP_SEQUENCE)
  1362. return nfs_ok;
  1363. if (args->opcnt != 1)
  1364. return nfserr_not_only_op;
  1365. return nfs_ok;
  1366. }
  1367. static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  1368. {
  1369. return &nfsd4_ops[op->opnum];
  1370. }
  1371. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  1372. {
  1373. if (op->opnum == OP_ILLEGAL)
  1374. return false;
  1375. return OPDESC(op)->op_flags & OP_CACHEME;
  1376. }
  1377. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  1378. {
  1379. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1380. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  1381. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  1382. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  1383. struct nfsd4_operation *thisd;
  1384. struct nfsd4_operation *nextd;
  1385. thisd = OPDESC(this);
  1386. /*
  1387. * Most ops check wronsec on our own; only the putfh-like ops
  1388. * have special rules.
  1389. */
  1390. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  1391. return false;
  1392. /*
  1393. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  1394. * put-filehandle operation if we're not going to use the
  1395. * result:
  1396. */
  1397. if (argp->opcnt == resp->opcnt)
  1398. return false;
  1399. if (next->opnum == OP_ILLEGAL)
  1400. return false;
  1401. nextd = OPDESC(next);
  1402. /*
  1403. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  1404. * errors themselves as necessary; others should check for them
  1405. * now:
  1406. */
  1407. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  1408. }
  1409. static void svcxdr_init_encode(struct svc_rqst *rqstp,
  1410. struct nfsd4_compoundres *resp)
  1411. {
  1412. struct xdr_stream *xdr = &resp->xdr;
  1413. struct xdr_buf *buf = &rqstp->rq_res;
  1414. struct kvec *head = buf->head;
  1415. xdr->buf = buf;
  1416. xdr->iov = head;
  1417. xdr->p = head->iov_base + head->iov_len;
  1418. xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
  1419. /* Tail and page_len should be zero at this point: */
  1420. buf->len = buf->head[0].iov_len;
  1421. xdr->scratch.iov_len = 0;
  1422. xdr->page_ptr = buf->pages - 1;
  1423. buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
  1424. - rqstp->rq_auth_slack;
  1425. }
  1426. /*
  1427. * COMPOUND call.
  1428. */
  1429. static __be32
  1430. nfsd4_proc_compound(struct svc_rqst *rqstp,
  1431. struct nfsd4_compoundargs *args,
  1432. struct nfsd4_compoundres *resp)
  1433. {
  1434. struct nfsd4_op *op;
  1435. struct nfsd4_operation *opdesc;
  1436. struct nfsd4_compound_state *cstate = &resp->cstate;
  1437. struct svc_fh *current_fh = &cstate->current_fh;
  1438. struct svc_fh *save_fh = &cstate->save_fh;
  1439. __be32 status;
  1440. svcxdr_init_encode(rqstp, resp);
  1441. resp->tagp = resp->xdr.p;
  1442. /* reserve space for: taglen, tag, and opcnt */
  1443. xdr_reserve_space(&resp->xdr, 8 + args->taglen);
  1444. resp->taglen = args->taglen;
  1445. resp->tag = args->tag;
  1446. resp->rqstp = rqstp;
  1447. cstate->minorversion = args->minorversion;
  1448. fh_init(current_fh, NFS4_FHSIZE);
  1449. fh_init(save_fh, NFS4_FHSIZE);
  1450. /*
  1451. * Don't use the deferral mechanism for NFSv4; compounds make it
  1452. * too hard to avoid non-idempotency problems.
  1453. */
  1454. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1455. /*
  1456. * According to RFC3010, this takes precedence over all other errors.
  1457. */
  1458. status = nfserr_minor_vers_mismatch;
  1459. if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0)
  1460. goto out;
  1461. status = nfs41_check_op_ordering(args);
  1462. if (status) {
  1463. op = &args->ops[0];
  1464. op->status = status;
  1465. goto encode_op;
  1466. }
  1467. while (!status && resp->opcnt < args->opcnt) {
  1468. op = &args->ops[resp->opcnt++];
  1469. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  1470. resp->opcnt, args->opcnt, op->opnum,
  1471. nfsd4_op_name(op->opnum));
  1472. /*
  1473. * The XDR decode routines may have pre-set op->status;
  1474. * for example, if there is a miscellaneous XDR error
  1475. * it will be set to nfserr_bad_xdr.
  1476. */
  1477. if (op->status) {
  1478. if (op->opnum == OP_OPEN)
  1479. op->status = nfsd4_open_omfg(rqstp, cstate, op);
  1480. goto encode_op;
  1481. }
  1482. opdesc = OPDESC(op);
  1483. if (!current_fh->fh_dentry) {
  1484. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  1485. op->status = nfserr_nofilehandle;
  1486. goto encode_op;
  1487. }
  1488. } else if (current_fh->fh_export->ex_fslocs.migrated &&
  1489. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  1490. op->status = nfserr_moved;
  1491. goto encode_op;
  1492. }
  1493. fh_clear_wcc(current_fh);
  1494. /* If op is non-idempotent */
  1495. if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  1496. /*
  1497. * Don't execute this op if we couldn't encode a
  1498. * succesful reply:
  1499. */
  1500. u32 plen = opdesc->op_rsize_bop(rqstp, op);
  1501. /*
  1502. * Plus if there's another operation, make sure
  1503. * we'll have space to at least encode an error:
  1504. */
  1505. if (resp->opcnt < args->opcnt)
  1506. plen += COMPOUND_ERR_SLACK_SPACE;
  1507. op->status = nfsd4_check_resp_size(resp, plen);
  1508. }
  1509. if (op->status)
  1510. goto encode_op;
  1511. if (opdesc->op_get_currentstateid)
  1512. opdesc->op_get_currentstateid(cstate, &op->u);
  1513. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  1514. if (!op->status) {
  1515. if (opdesc->op_set_currentstateid)
  1516. opdesc->op_set_currentstateid(cstate, &op->u);
  1517. if (opdesc->op_flags & OP_CLEAR_STATEID)
  1518. clear_current_stateid(cstate);
  1519. if (need_wrongsec_check(rqstp))
  1520. op->status = check_nfsd_access(current_fh->fh_export, rqstp);
  1521. }
  1522. encode_op:
  1523. /* Only from SEQUENCE */
  1524. if (cstate->status == nfserr_replay_cache) {
  1525. dprintk("%s NFS4.1 replay from cache\n", __func__);
  1526. status = op->status;
  1527. goto out;
  1528. }
  1529. if (op->status == nfserr_replay_me) {
  1530. op->replay = &cstate->replay_owner->so_replay;
  1531. nfsd4_encode_replay(&resp->xdr, op);
  1532. status = op->status = op->replay->rp_status;
  1533. } else {
  1534. nfsd4_encode_operation(resp, op);
  1535. status = op->status;
  1536. }
  1537. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  1538. args->ops, args->opcnt, resp->opcnt, op->opnum,
  1539. be32_to_cpu(status));
  1540. nfsd4_cstate_clear_replay(cstate);
  1541. nfsd4_increment_op_stats(op->opnum);
  1542. }
  1543. cstate->status = status;
  1544. fh_put(current_fh);
  1545. fh_put(save_fh);
  1546. BUG_ON(cstate->replay_owner);
  1547. out:
  1548. /* Reset deferral mechanism for RPC deferrals */
  1549. set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1550. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1551. return status;
  1552. }
  1553. #define op_encode_hdr_size (2)
  1554. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  1555. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  1556. #define op_encode_change_info_maxsz (5)
  1557. #define nfs4_fattr_bitmap_maxsz (4)
  1558. /* We'll fall back on returning no lockowner if run out of space: */
  1559. #define op_encode_lockowner_maxsz (0)
  1560. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  1561. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1562. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  1563. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  1564. op_encode_ace_maxsz)
  1565. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  1566. static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1567. {
  1568. return (op_encode_hdr_size) * sizeof(__be32);
  1569. }
  1570. static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1571. {
  1572. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  1573. }
  1574. static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1575. {
  1576. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1577. }
  1578. static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1579. {
  1580. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1581. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1582. }
  1583. /*
  1584. * Note since this is an idempotent operation we won't insist on failing
  1585. * the op prematurely if the estimate is too large. We may turn off splice
  1586. * reads unnecessarily.
  1587. */
  1588. static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
  1589. struct nfsd4_op *op)
  1590. {
  1591. u32 *bmap = op->u.getattr.ga_bmval;
  1592. u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
  1593. u32 ret = 0;
  1594. if (bmap0 & FATTR4_WORD0_ACL)
  1595. return svc_max_payload(rqstp);
  1596. if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
  1597. return svc_max_payload(rqstp);
  1598. if (bmap1 & FATTR4_WORD1_OWNER) {
  1599. ret += IDMAP_NAMESZ + 4;
  1600. bmap1 &= ~FATTR4_WORD1_OWNER;
  1601. }
  1602. if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
  1603. ret += IDMAP_NAMESZ + 4;
  1604. bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
  1605. }
  1606. if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
  1607. ret += NFS4_FHSIZE + 4;
  1608. bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
  1609. }
  1610. if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
  1611. ret += NFS4_MAXLABELLEN + 12;
  1612. bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
  1613. }
  1614. /*
  1615. * Largest of remaining attributes are 16 bytes (e.g.,
  1616. * supported_attributes)
  1617. */
  1618. ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
  1619. /* bitmask, length */
  1620. ret += 20;
  1621. return ret;
  1622. }
  1623. static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1624. {
  1625. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1626. * sizeof(__be32);
  1627. }
  1628. static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1629. {
  1630. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  1631. * sizeof(__be32);
  1632. }
  1633. static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1634. {
  1635. return (op_encode_hdr_size + op_encode_stateid_maxsz
  1636. + op_encode_change_info_maxsz + 1
  1637. + nfs4_fattr_bitmap_maxsz
  1638. + op_encode_delegation_maxsz) * sizeof(__be32);
  1639. }
  1640. static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1641. {
  1642. u32 maxcount = 0, rlen = 0;
  1643. maxcount = svc_max_payload(rqstp);
  1644. rlen = min(op->u.read.rd_length, maxcount);
  1645. return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  1646. }
  1647. static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1648. {
  1649. u32 maxcount = 0, rlen = 0;
  1650. maxcount = svc_max_payload(rqstp);
  1651. rlen = min(op->u.readdir.rd_maxcount, maxcount);
  1652. return (op_encode_hdr_size + op_encode_verifier_maxsz +
  1653. XDR_QUADLEN(rlen)) * sizeof(__be32);
  1654. }
  1655. static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1656. {
  1657. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1658. * sizeof(__be32);
  1659. }
  1660. static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1661. {
  1662. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1663. + op_encode_change_info_maxsz) * sizeof(__be32);
  1664. }
  1665. static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
  1666. struct nfsd4_op *op)
  1667. {
  1668. return (op_encode_hdr_size
  1669. + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
  1670. }
  1671. static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1672. {
  1673. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1674. }
  1675. static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1676. {
  1677. return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
  1678. sizeof(__be32);
  1679. }
  1680. static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1681. {
  1682. return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
  1683. }
  1684. static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1685. {
  1686. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  1687. 1 + 1 + /* eir_flags, spr_how */\
  1688. 4 + /* spo_must_enforce & _allow with bitmap */\
  1689. 2 + /*eir_server_owner.so_minor_id */\
  1690. /* eir_server_owner.so_major_id<> */\
  1691. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1692. /* eir_server_scope<> */\
  1693. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1694. 1 + /* eir_server_impl_id array length */\
  1695. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  1696. }
  1697. static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1698. {
  1699. return (op_encode_hdr_size + \
  1700. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  1701. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  1702. }
  1703. static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1704. {
  1705. return (op_encode_hdr_size + \
  1706. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  1707. 2 + /* csr_sequence, csr_flags */\
  1708. op_encode_channel_attrs_maxsz + \
  1709. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  1710. }
  1711. #ifdef CONFIG_NFSD_PNFS
  1712. /*
  1713. * At this stage we don't really know what layout driver will handle the request,
  1714. * so we need to define an arbitrary upper bound here.
  1715. */
  1716. #define MAX_LAYOUT_SIZE 128
  1717. static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1718. {
  1719. return (op_encode_hdr_size +
  1720. 1 /* logr_return_on_close */ +
  1721. op_encode_stateid_maxsz +
  1722. 1 /* nr of layouts */ +
  1723. MAX_LAYOUT_SIZE) * sizeof(__be32);
  1724. }
  1725. static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1726. {
  1727. return (op_encode_hdr_size +
  1728. 1 /* locr_newsize */ +
  1729. 2 /* ns_size */) * sizeof(__be32);
  1730. }
  1731. static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1732. {
  1733. return (op_encode_hdr_size +
  1734. 1 /* lrs_stateid */ +
  1735. op_encode_stateid_maxsz) * sizeof(__be32);
  1736. }
  1737. #endif /* CONFIG_NFSD_PNFS */
  1738. static struct nfsd4_operation nfsd4_ops[] = {
  1739. [OP_ACCESS] = {
  1740. .op_func = (nfsd4op_func)nfsd4_access,
  1741. .op_name = "OP_ACCESS",
  1742. },
  1743. [OP_CLOSE] = {
  1744. .op_func = (nfsd4op_func)nfsd4_close,
  1745. .op_flags = OP_MODIFIES_SOMETHING,
  1746. .op_name = "OP_CLOSE",
  1747. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1748. .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
  1749. .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
  1750. },
  1751. [OP_COMMIT] = {
  1752. .op_func = (nfsd4op_func)nfsd4_commit,
  1753. .op_flags = OP_MODIFIES_SOMETHING,
  1754. .op_name = "OP_COMMIT",
  1755. .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
  1756. },
  1757. [OP_CREATE] = {
  1758. .op_func = (nfsd4op_func)nfsd4_create,
  1759. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
  1760. .op_name = "OP_CREATE",
  1761. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
  1762. },
  1763. [OP_DELEGRETURN] = {
  1764. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1765. .op_flags = OP_MODIFIES_SOMETHING,
  1766. .op_name = "OP_DELEGRETURN",
  1767. .op_rsize_bop = nfsd4_only_status_rsize,
  1768. .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
  1769. },
  1770. [OP_GETATTR] = {
  1771. .op_func = (nfsd4op_func)nfsd4_getattr,
  1772. .op_flags = ALLOWED_ON_ABSENT_FS,
  1773. .op_rsize_bop = nfsd4_getattr_rsize,
  1774. .op_name = "OP_GETATTR",
  1775. },
  1776. [OP_GETFH] = {
  1777. .op_func = (nfsd4op_func)nfsd4_getfh,
  1778. .op_name = "OP_GETFH",
  1779. },
  1780. [OP_LINK] = {
  1781. .op_func = (nfsd4op_func)nfsd4_link,
  1782. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  1783. | OP_CACHEME,
  1784. .op_name = "OP_LINK",
  1785. .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
  1786. },
  1787. [OP_LOCK] = {
  1788. .op_func = (nfsd4op_func)nfsd4_lock,
  1789. .op_flags = OP_MODIFIES_SOMETHING,
  1790. .op_name = "OP_LOCK",
  1791. .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
  1792. .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
  1793. },
  1794. [OP_LOCKT] = {
  1795. .op_func = (nfsd4op_func)nfsd4_lockt,
  1796. .op_name = "OP_LOCKT",
  1797. },
  1798. [OP_LOCKU] = {
  1799. .op_func = (nfsd4op_func)nfsd4_locku,
  1800. .op_flags = OP_MODIFIES_SOMETHING,
  1801. .op_name = "OP_LOCKU",
  1802. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1803. .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
  1804. },
  1805. [OP_LOOKUP] = {
  1806. .op_func = (nfsd4op_func)nfsd4_lookup,
  1807. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1808. .op_name = "OP_LOOKUP",
  1809. },
  1810. [OP_LOOKUPP] = {
  1811. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1812. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1813. .op_name = "OP_LOOKUPP",
  1814. },
  1815. [OP_NVERIFY] = {
  1816. .op_func = (nfsd4op_func)nfsd4_nverify,
  1817. .op_name = "OP_NVERIFY",
  1818. },
  1819. [OP_OPEN] = {
  1820. .op_func = (nfsd4op_func)nfsd4_open,
  1821. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1822. .op_name = "OP_OPEN",
  1823. .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
  1824. .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
  1825. },
  1826. [OP_OPEN_CONFIRM] = {
  1827. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1828. .op_flags = OP_MODIFIES_SOMETHING,
  1829. .op_name = "OP_OPEN_CONFIRM",
  1830. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1831. },
  1832. [OP_OPEN_DOWNGRADE] = {
  1833. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1834. .op_flags = OP_MODIFIES_SOMETHING,
  1835. .op_name = "OP_OPEN_DOWNGRADE",
  1836. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1837. .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
  1838. .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
  1839. },
  1840. [OP_PUTFH] = {
  1841. .op_func = (nfsd4op_func)nfsd4_putfh,
  1842. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1843. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1844. .op_name = "OP_PUTFH",
  1845. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1846. },
  1847. [OP_PUTPUBFH] = {
  1848. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1849. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1850. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1851. .op_name = "OP_PUTPUBFH",
  1852. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1853. },
  1854. [OP_PUTROOTFH] = {
  1855. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1856. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1857. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1858. .op_name = "OP_PUTROOTFH",
  1859. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1860. },
  1861. [OP_READ] = {
  1862. .op_func = (nfsd4op_func)nfsd4_read,
  1863. .op_name = "OP_READ",
  1864. .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
  1865. .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
  1866. },
  1867. [OP_READDIR] = {
  1868. .op_func = (nfsd4op_func)nfsd4_readdir,
  1869. .op_name = "OP_READDIR",
  1870. .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
  1871. },
  1872. [OP_READLINK] = {
  1873. .op_func = (nfsd4op_func)nfsd4_readlink,
  1874. .op_name = "OP_READLINK",
  1875. },
  1876. [OP_REMOVE] = {
  1877. .op_func = (nfsd4op_func)nfsd4_remove,
  1878. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1879. .op_name = "OP_REMOVE",
  1880. .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
  1881. },
  1882. [OP_RENAME] = {
  1883. .op_func = (nfsd4op_func)nfsd4_rename,
  1884. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1885. .op_name = "OP_RENAME",
  1886. .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
  1887. },
  1888. [OP_RENEW] = {
  1889. .op_func = (nfsd4op_func)nfsd4_renew,
  1890. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1891. | OP_MODIFIES_SOMETHING,
  1892. .op_name = "OP_RENEW",
  1893. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1894. },
  1895. [OP_RESTOREFH] = {
  1896. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1897. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1898. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1899. .op_name = "OP_RESTOREFH",
  1900. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1901. },
  1902. [OP_SAVEFH] = {
  1903. .op_func = (nfsd4op_func)nfsd4_savefh,
  1904. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1905. .op_name = "OP_SAVEFH",
  1906. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1907. },
  1908. [OP_SECINFO] = {
  1909. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1910. .op_flags = OP_HANDLES_WRONGSEC,
  1911. .op_name = "OP_SECINFO",
  1912. },
  1913. [OP_SETATTR] = {
  1914. .op_func = (nfsd4op_func)nfsd4_setattr,
  1915. .op_name = "OP_SETATTR",
  1916. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1917. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
  1918. .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
  1919. },
  1920. [OP_SETCLIENTID] = {
  1921. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1922. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1923. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1924. .op_name = "OP_SETCLIENTID",
  1925. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
  1926. },
  1927. [OP_SETCLIENTID_CONFIRM] = {
  1928. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1929. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1930. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1931. .op_name = "OP_SETCLIENTID_CONFIRM",
  1932. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1933. },
  1934. [OP_VERIFY] = {
  1935. .op_func = (nfsd4op_func)nfsd4_verify,
  1936. .op_name = "OP_VERIFY",
  1937. },
  1938. [OP_WRITE] = {
  1939. .op_func = (nfsd4op_func)nfsd4_write,
  1940. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1941. .op_name = "OP_WRITE",
  1942. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  1943. .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
  1944. },
  1945. [OP_RELEASE_LOCKOWNER] = {
  1946. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1947. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1948. | OP_MODIFIES_SOMETHING,
  1949. .op_name = "OP_RELEASE_LOCKOWNER",
  1950. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1951. },
  1952. /* NFSv4.1 operations */
  1953. [OP_EXCHANGE_ID] = {
  1954. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1955. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1956. | OP_MODIFIES_SOMETHING,
  1957. .op_name = "OP_EXCHANGE_ID",
  1958. .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
  1959. },
  1960. [OP_BACKCHANNEL_CTL] = {
  1961. .op_func = (nfsd4op_func)nfsd4_backchannel_ctl,
  1962. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1963. .op_name = "OP_BACKCHANNEL_CTL",
  1964. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1965. },
  1966. [OP_BIND_CONN_TO_SESSION] = {
  1967. .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
  1968. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1969. | OP_MODIFIES_SOMETHING,
  1970. .op_name = "OP_BIND_CONN_TO_SESSION",
  1971. .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
  1972. },
  1973. [OP_CREATE_SESSION] = {
  1974. .op_func = (nfsd4op_func)nfsd4_create_session,
  1975. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1976. | OP_MODIFIES_SOMETHING,
  1977. .op_name = "OP_CREATE_SESSION",
  1978. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
  1979. },
  1980. [OP_DESTROY_SESSION] = {
  1981. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1982. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1983. | OP_MODIFIES_SOMETHING,
  1984. .op_name = "OP_DESTROY_SESSION",
  1985. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1986. },
  1987. [OP_SEQUENCE] = {
  1988. .op_func = (nfsd4op_func)nfsd4_sequence,
  1989. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1990. .op_name = "OP_SEQUENCE",
  1991. .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize,
  1992. },
  1993. [OP_DESTROY_CLIENTID] = {
  1994. .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
  1995. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1996. | OP_MODIFIES_SOMETHING,
  1997. .op_name = "OP_DESTROY_CLIENTID",
  1998. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1999. },
  2000. [OP_RECLAIM_COMPLETE] = {
  2001. .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
  2002. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  2003. .op_name = "OP_RECLAIM_COMPLETE",
  2004. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2005. },
  2006. [OP_SECINFO_NO_NAME] = {
  2007. .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
  2008. .op_flags = OP_HANDLES_WRONGSEC,
  2009. .op_name = "OP_SECINFO_NO_NAME",
  2010. },
  2011. [OP_TEST_STATEID] = {
  2012. .op_func = (nfsd4op_func)nfsd4_test_stateid,
  2013. .op_flags = ALLOWED_WITHOUT_FH,
  2014. .op_name = "OP_TEST_STATEID",
  2015. },
  2016. [OP_FREE_STATEID] = {
  2017. .op_func = (nfsd4op_func)nfsd4_free_stateid,
  2018. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  2019. .op_name = "OP_FREE_STATEID",
  2020. .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid,
  2021. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2022. },
  2023. #ifdef CONFIG_NFSD_PNFS
  2024. [OP_GETDEVICEINFO] = {
  2025. .op_func = (nfsd4op_func)nfsd4_getdeviceinfo,
  2026. .op_flags = ALLOWED_WITHOUT_FH,
  2027. .op_name = "OP_GETDEVICEINFO",
  2028. },
  2029. [OP_LAYOUTGET] = {
  2030. .op_func = (nfsd4op_func)nfsd4_layoutget,
  2031. .op_flags = OP_MODIFIES_SOMETHING,
  2032. .op_name = "OP_LAYOUTGET",
  2033. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize,
  2034. },
  2035. [OP_LAYOUTCOMMIT] = {
  2036. .op_func = (nfsd4op_func)nfsd4_layoutcommit,
  2037. .op_flags = OP_MODIFIES_SOMETHING,
  2038. .op_name = "OP_LAYOUTCOMMIT",
  2039. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize,
  2040. },
  2041. [OP_LAYOUTRETURN] = {
  2042. .op_func = (nfsd4op_func)nfsd4_layoutreturn,
  2043. .op_flags = OP_MODIFIES_SOMETHING,
  2044. .op_name = "OP_LAYOUTRETURN",
  2045. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize,
  2046. },
  2047. #endif /* CONFIG_NFSD_PNFS */
  2048. /* NFSv4.2 operations */
  2049. [OP_ALLOCATE] = {
  2050. .op_func = (nfsd4op_func)nfsd4_allocate,
  2051. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2052. .op_name = "OP_ALLOCATE",
  2053. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2054. },
  2055. [OP_DEALLOCATE] = {
  2056. .op_func = (nfsd4op_func)nfsd4_deallocate,
  2057. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2058. .op_name = "OP_DEALLOCATE",
  2059. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2060. },
  2061. [OP_CLONE] = {
  2062. .op_func = (nfsd4op_func)nfsd4_clone,
  2063. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2064. .op_name = "OP_CLONE",
  2065. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2066. },
  2067. [OP_SEEK] = {
  2068. .op_func = (nfsd4op_func)nfsd4_seek,
  2069. .op_name = "OP_SEEK",
  2070. },
  2071. };
  2072. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
  2073. {
  2074. struct nfsd4_operation *opdesc;
  2075. nfsd4op_rsize estimator;
  2076. if (op->opnum == OP_ILLEGAL)
  2077. return op_encode_hdr_size * sizeof(__be32);
  2078. opdesc = OPDESC(op);
  2079. estimator = opdesc->op_rsize_bop;
  2080. return estimator ? estimator(rqstp, op) : PAGE_SIZE;
  2081. }
  2082. void warn_on_nonidempotent_op(struct nfsd4_op *op)
  2083. {
  2084. if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
  2085. pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
  2086. op->opnum, nfsd4_op_name(op->opnum));
  2087. WARN_ON_ONCE(1);
  2088. }
  2089. }
  2090. static const char *nfsd4_op_name(unsigned opnum)
  2091. {
  2092. if (opnum < ARRAY_SIZE(nfsd4_ops))
  2093. return nfsd4_ops[opnum].op_name;
  2094. return "unknown_operation";
  2095. }
  2096. #define nfsd4_voidres nfsd4_voidargs
  2097. struct nfsd4_voidargs { int dummy; };
  2098. static struct svc_procedure nfsd_procedures4[2] = {
  2099. [NFSPROC4_NULL] = {
  2100. .pc_func = (svc_procfunc) nfsd4_proc_null,
  2101. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  2102. .pc_argsize = sizeof(struct nfsd4_voidargs),
  2103. .pc_ressize = sizeof(struct nfsd4_voidres),
  2104. .pc_cachetype = RC_NOCACHE,
  2105. .pc_xdrressize = 1,
  2106. },
  2107. [NFSPROC4_COMPOUND] = {
  2108. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  2109. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  2110. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  2111. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  2112. .pc_ressize = sizeof(struct nfsd4_compoundres),
  2113. .pc_release = nfsd4_release_compoundargs,
  2114. .pc_cachetype = RC_NOCACHE,
  2115. .pc_xdrressize = NFSD_BUFSIZE/4,
  2116. },
  2117. };
  2118. struct svc_version nfsd_version4 = {
  2119. .vs_vers = 4,
  2120. .vs_nproc = 2,
  2121. .vs_proc = nfsd_procedures4,
  2122. .vs_dispatch = nfsd_dispatch,
  2123. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  2124. .vs_rpcb_optnl = 1,
  2125. };
  2126. /*
  2127. * Local variables:
  2128. * c-basic-offset: 8
  2129. * End:
  2130. */