nfs4proc.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  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 = resfh->fh_dentry->d_inode;
  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(dentry->d_inode))
  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 = fh->fh_dentry->d_inode->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, use the returned bitmask
  244. * to indicate which attributes we used to store the
  245. * verifier:
  246. */
  247. if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && 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 nfsd4_compoundres *resp;
  318. struct net *net = SVC_NET(rqstp);
  319. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  320. dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
  321. (int)open->op_fname.len, open->op_fname.data,
  322. open->op_openowner);
  323. /* This check required by spec. */
  324. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  325. return nfserr_inval;
  326. open->op_created = 0;
  327. /*
  328. * RFC5661 18.51.3
  329. * Before RECLAIM_COMPLETE done, server should deny new lock
  330. */
  331. if (nfsd4_has_session(cstate) &&
  332. !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
  333. &cstate->session->se_client->cl_flags) &&
  334. open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  335. return nfserr_grace;
  336. if (nfsd4_has_session(cstate))
  337. copy_clientid(&open->op_clientid, cstate->session);
  338. /* check seqid for replay. set nfs4_owner */
  339. resp = rqstp->rq_resp;
  340. status = nfsd4_process_open1(&resp->cstate, open, nn);
  341. if (status == nfserr_replay_me) {
  342. struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
  343. fh_put(&cstate->current_fh);
  344. fh_copy_shallow(&cstate->current_fh.fh_handle,
  345. &rp->rp_openfh);
  346. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  347. if (status)
  348. dprintk("nfsd4_open: replay failed"
  349. " restoring previous filehandle\n");
  350. else
  351. status = nfserr_replay_me;
  352. }
  353. if (status)
  354. goto out;
  355. if (open->op_xdr_error) {
  356. status = open->op_xdr_error;
  357. goto out;
  358. }
  359. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  360. if (status)
  361. goto out;
  362. /* Openowner is now set, so sequence id will get bumped. Now we need
  363. * these checks before we do any creates: */
  364. status = nfserr_grace;
  365. if (locks_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  366. goto out;
  367. status = nfserr_no_grace;
  368. if (!locks_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  369. goto out;
  370. switch (open->op_claim_type) {
  371. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  372. case NFS4_OPEN_CLAIM_NULL:
  373. status = do_open_lookup(rqstp, cstate, open, &resfh);
  374. if (status)
  375. goto out;
  376. break;
  377. case NFS4_OPEN_CLAIM_PREVIOUS:
  378. status = nfs4_check_open_reclaim(&open->op_clientid,
  379. cstate, nn);
  380. if (status)
  381. goto out;
  382. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  383. case NFS4_OPEN_CLAIM_FH:
  384. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  385. status = do_open_fhandle(rqstp, cstate, open);
  386. if (status)
  387. goto out;
  388. resfh = &cstate->current_fh;
  389. break;
  390. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  391. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  392. dprintk("NFSD: unsupported OPEN claim type %d\n",
  393. open->op_claim_type);
  394. status = nfserr_notsupp;
  395. goto out;
  396. default:
  397. dprintk("NFSD: Invalid OPEN claim type %d\n",
  398. open->op_claim_type);
  399. status = nfserr_inval;
  400. goto out;
  401. }
  402. /*
  403. * nfsd4_process_open2() does the actual opening of the file. If
  404. * successful, it (1) truncates the file if open->op_truncate was
  405. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  406. */
  407. status = nfsd4_process_open2(rqstp, resfh, open);
  408. WARN(status && open->op_created,
  409. "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
  410. be32_to_cpu(status));
  411. out:
  412. if (resfh && resfh != &cstate->current_fh) {
  413. fh_dup2(&cstate->current_fh, resfh);
  414. fh_put(resfh);
  415. kfree(resfh);
  416. }
  417. nfsd4_cleanup_open_state(cstate, open, status);
  418. nfsd4_bump_seqid(cstate, status);
  419. return status;
  420. }
  421. /*
  422. * OPEN is the only seqid-mutating operation whose decoding can fail
  423. * with a seqid-mutating error (specifically, decoding of user names in
  424. * the attributes). Therefore we have to do some processing to look up
  425. * the stateowner so that we can bump the seqid.
  426. */
  427. static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
  428. {
  429. struct nfsd4_open *open = (struct nfsd4_open *)&op->u;
  430. if (!seqid_mutating_err(ntohl(op->status)))
  431. return op->status;
  432. if (nfsd4_has_session(cstate))
  433. return op->status;
  434. open->op_xdr_error = op->status;
  435. return nfsd4_open(rqstp, cstate, open);
  436. }
  437. /*
  438. * filehandle-manipulating ops.
  439. */
  440. static __be32
  441. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  442. struct svc_fh **getfh)
  443. {
  444. if (!cstate->current_fh.fh_dentry)
  445. return nfserr_nofilehandle;
  446. *getfh = &cstate->current_fh;
  447. return nfs_ok;
  448. }
  449. static __be32
  450. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  451. struct nfsd4_putfh *putfh)
  452. {
  453. fh_put(&cstate->current_fh);
  454. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  455. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  456. putfh->pf_fhlen);
  457. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
  458. }
  459. static __be32
  460. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  461. void *arg)
  462. {
  463. __be32 status;
  464. fh_put(&cstate->current_fh);
  465. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  466. return status;
  467. }
  468. static __be32
  469. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  470. void *arg)
  471. {
  472. if (!cstate->save_fh.fh_dentry)
  473. return nfserr_restorefh;
  474. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  475. if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
  476. memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
  477. SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
  478. }
  479. return nfs_ok;
  480. }
  481. static __be32
  482. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  483. void *arg)
  484. {
  485. if (!cstate->current_fh.fh_dentry)
  486. return nfserr_nofilehandle;
  487. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  488. if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
  489. memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
  490. SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
  491. }
  492. return nfs_ok;
  493. }
  494. /*
  495. * misc nfsv4 ops
  496. */
  497. static __be32
  498. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  499. struct nfsd4_access *access)
  500. {
  501. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  502. return nfserr_inval;
  503. access->ac_resp_access = access->ac_req_access;
  504. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  505. &access->ac_supported);
  506. }
  507. static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
  508. {
  509. __be32 verf[2];
  510. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  511. /*
  512. * This is opaque to client, so no need to byte-swap. Use
  513. * __force to keep sparse happy
  514. */
  515. verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
  516. verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec;
  517. memcpy(verifier->data, verf, sizeof(verifier->data));
  518. }
  519. static __be32
  520. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  521. struct nfsd4_commit *commit)
  522. {
  523. gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp));
  524. return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
  525. commit->co_count);
  526. }
  527. static __be32
  528. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  529. struct nfsd4_create *create)
  530. {
  531. struct svc_fh resfh;
  532. __be32 status;
  533. dev_t rdev;
  534. fh_init(&resfh, NFS4_FHSIZE);
  535. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
  536. NFSD_MAY_CREATE);
  537. if (status)
  538. return status;
  539. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  540. nfsd_attrmask);
  541. if (status)
  542. return status;
  543. switch (create->cr_type) {
  544. case NF4LNK:
  545. status = nfsd_symlink(rqstp, &cstate->current_fh,
  546. create->cr_name, create->cr_namelen,
  547. create->cr_data, &resfh);
  548. break;
  549. case NF4BLK:
  550. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  551. if (MAJOR(rdev) != create->cr_specdata1 ||
  552. MINOR(rdev) != create->cr_specdata2)
  553. return nfserr_inval;
  554. status = nfsd_create(rqstp, &cstate->current_fh,
  555. create->cr_name, create->cr_namelen,
  556. &create->cr_iattr, S_IFBLK, rdev, &resfh);
  557. break;
  558. case NF4CHR:
  559. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  560. if (MAJOR(rdev) != create->cr_specdata1 ||
  561. MINOR(rdev) != create->cr_specdata2)
  562. return nfserr_inval;
  563. status = nfsd_create(rqstp, &cstate->current_fh,
  564. create->cr_name, create->cr_namelen,
  565. &create->cr_iattr,S_IFCHR, rdev, &resfh);
  566. break;
  567. case NF4SOCK:
  568. status = nfsd_create(rqstp, &cstate->current_fh,
  569. create->cr_name, create->cr_namelen,
  570. &create->cr_iattr, S_IFSOCK, 0, &resfh);
  571. break;
  572. case NF4FIFO:
  573. status = nfsd_create(rqstp, &cstate->current_fh,
  574. create->cr_name, create->cr_namelen,
  575. &create->cr_iattr, S_IFIFO, 0, &resfh);
  576. break;
  577. case NF4DIR:
  578. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  579. status = nfsd_create(rqstp, &cstate->current_fh,
  580. create->cr_name, create->cr_namelen,
  581. &create->cr_iattr, S_IFDIR, 0, &resfh);
  582. break;
  583. default:
  584. status = nfserr_badtype;
  585. }
  586. if (status)
  587. goto out;
  588. if (create->cr_label.len)
  589. nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
  590. if (create->cr_acl != NULL)
  591. do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
  592. create->cr_bmval);
  593. fh_unlock(&cstate->current_fh);
  594. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  595. fh_dup2(&cstate->current_fh, &resfh);
  596. out:
  597. fh_put(&resfh);
  598. return status;
  599. }
  600. static __be32
  601. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  602. struct nfsd4_getattr *getattr)
  603. {
  604. __be32 status;
  605. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  606. if (status)
  607. return status;
  608. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  609. return nfserr_inval;
  610. getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  611. getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  612. getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  613. getattr->ga_fhp = &cstate->current_fh;
  614. return nfs_ok;
  615. }
  616. static __be32
  617. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  618. struct nfsd4_link *link)
  619. {
  620. __be32 status = nfserr_nofilehandle;
  621. if (!cstate->save_fh.fh_dentry)
  622. return status;
  623. status = nfsd_link(rqstp, &cstate->current_fh,
  624. link->li_name, link->li_namelen, &cstate->save_fh);
  625. if (!status)
  626. set_change_info(&link->li_cinfo, &cstate->current_fh);
  627. return status;
  628. }
  629. static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
  630. {
  631. struct svc_fh tmp_fh;
  632. __be32 ret;
  633. fh_init(&tmp_fh, NFS4_FHSIZE);
  634. ret = exp_pseudoroot(rqstp, &tmp_fh);
  635. if (ret)
  636. return ret;
  637. if (tmp_fh.fh_dentry == fh->fh_dentry) {
  638. fh_put(&tmp_fh);
  639. return nfserr_noent;
  640. }
  641. fh_put(&tmp_fh);
  642. return nfsd_lookup(rqstp, fh, "..", 2, fh);
  643. }
  644. static __be32
  645. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  646. void *arg)
  647. {
  648. return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  649. }
  650. static __be32
  651. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  652. struct nfsd4_lookup *lookup)
  653. {
  654. return nfsd_lookup(rqstp, &cstate->current_fh,
  655. lookup->lo_name, lookup->lo_len,
  656. &cstate->current_fh);
  657. }
  658. static __be32
  659. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  660. struct nfsd4_read *read)
  661. {
  662. __be32 status;
  663. /* no need to check permission - this will be done in nfsd_read() */
  664. read->rd_filp = NULL;
  665. if (read->rd_offset >= OFFSET_MAX)
  666. return nfserr_inval;
  667. /*
  668. * If we do a zero copy read, then a client will see read data
  669. * that reflects the state of the file *after* performing the
  670. * following compound.
  671. *
  672. * To ensure proper ordering, we therefore turn off zero copy if
  673. * the client wants us to do more in this compound:
  674. */
  675. if (!nfsd4_last_compound_op(rqstp))
  676. clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
  677. /* check stateid */
  678. if ((status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
  679. cstate, &read->rd_stateid,
  680. RD_STATE, &read->rd_filp))) {
  681. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  682. goto out;
  683. }
  684. status = nfs_ok;
  685. out:
  686. read->rd_rqstp = rqstp;
  687. read->rd_fhp = &cstate->current_fh;
  688. return status;
  689. }
  690. static __be32
  691. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  692. struct nfsd4_readdir *readdir)
  693. {
  694. u64 cookie = readdir->rd_cookie;
  695. static const nfs4_verifier zeroverf;
  696. /* no need to check permission - this will be done in nfsd_readdir() */
  697. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  698. return nfserr_inval;
  699. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  700. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  701. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  702. if ((cookie == 1) || (cookie == 2) ||
  703. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  704. return nfserr_bad_cookie;
  705. readdir->rd_rqstp = rqstp;
  706. readdir->rd_fhp = &cstate->current_fh;
  707. return nfs_ok;
  708. }
  709. static __be32
  710. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  711. struct nfsd4_readlink *readlink)
  712. {
  713. readlink->rl_rqstp = rqstp;
  714. readlink->rl_fhp = &cstate->current_fh;
  715. return nfs_ok;
  716. }
  717. static __be32
  718. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  719. struct nfsd4_remove *remove)
  720. {
  721. __be32 status;
  722. if (locks_in_grace(SVC_NET(rqstp)))
  723. return nfserr_grace;
  724. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  725. remove->rm_name, remove->rm_namelen);
  726. if (!status) {
  727. fh_unlock(&cstate->current_fh);
  728. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  729. }
  730. return status;
  731. }
  732. static __be32
  733. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  734. struct nfsd4_rename *rename)
  735. {
  736. __be32 status = nfserr_nofilehandle;
  737. if (!cstate->save_fh.fh_dentry)
  738. return status;
  739. if (locks_in_grace(SVC_NET(rqstp)) &&
  740. !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
  741. return nfserr_grace;
  742. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  743. rename->rn_snamelen, &cstate->current_fh,
  744. rename->rn_tname, rename->rn_tnamelen);
  745. if (status)
  746. return status;
  747. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  748. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  749. return nfs_ok;
  750. }
  751. static __be32
  752. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  753. struct nfsd4_secinfo *secinfo)
  754. {
  755. struct svc_fh resfh;
  756. struct svc_export *exp;
  757. struct dentry *dentry;
  758. __be32 err;
  759. fh_init(&resfh, NFS4_FHSIZE);
  760. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  761. if (err)
  762. return err;
  763. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  764. secinfo->si_name, secinfo->si_namelen,
  765. &exp, &dentry);
  766. if (err)
  767. return err;
  768. if (dentry->d_inode == NULL) {
  769. exp_put(exp);
  770. err = nfserr_noent;
  771. } else
  772. secinfo->si_exp = exp;
  773. dput(dentry);
  774. if (cstate->minorversion)
  775. /* See rfc 5661 section 2.6.3.1.1.8 */
  776. fh_put(&cstate->current_fh);
  777. return err;
  778. }
  779. static __be32
  780. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  781. struct nfsd4_secinfo_no_name *sin)
  782. {
  783. __be32 err;
  784. switch (sin->sin_style) {
  785. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  786. break;
  787. case NFS4_SECINFO_STYLE4_PARENT:
  788. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  789. if (err)
  790. return err;
  791. break;
  792. default:
  793. return nfserr_inval;
  794. }
  795. sin->sin_exp = exp_get(cstate->current_fh.fh_export);
  796. fh_put(&cstate->current_fh);
  797. return nfs_ok;
  798. }
  799. static __be32
  800. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  801. struct nfsd4_setattr *setattr)
  802. {
  803. __be32 status = nfs_ok;
  804. int err;
  805. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  806. status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
  807. &setattr->sa_stateid, WR_STATE, NULL);
  808. if (status) {
  809. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  810. return status;
  811. }
  812. }
  813. err = fh_want_write(&cstate->current_fh);
  814. if (err)
  815. return nfserrno(err);
  816. status = nfs_ok;
  817. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  818. nfsd_attrmask);
  819. if (status)
  820. goto out;
  821. if (setattr->sa_acl != NULL)
  822. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  823. setattr->sa_acl);
  824. if (status)
  825. goto out;
  826. if (setattr->sa_label.len)
  827. status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
  828. &setattr->sa_label);
  829. if (status)
  830. goto out;
  831. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  832. 0, (time_t)0);
  833. out:
  834. fh_drop_write(&cstate->current_fh);
  835. return status;
  836. }
  837. static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
  838. {
  839. int i = 1;
  840. int buflen = write->wr_buflen;
  841. vec[0].iov_base = write->wr_head.iov_base;
  842. vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len);
  843. buflen -= vec[0].iov_len;
  844. while (buflen) {
  845. vec[i].iov_base = page_address(write->wr_pagelist[i - 1]);
  846. vec[i].iov_len = min_t(int, PAGE_SIZE, buflen);
  847. buflen -= vec[i].iov_len;
  848. i++;
  849. }
  850. return i;
  851. }
  852. static __be32
  853. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  854. struct nfsd4_write *write)
  855. {
  856. stateid_t *stateid = &write->wr_stateid;
  857. struct file *filp = NULL;
  858. __be32 status = nfs_ok;
  859. unsigned long cnt;
  860. int nvecs;
  861. /* no need to check permission - this will be done in nfsd_write() */
  862. if (write->wr_offset >= OFFSET_MAX)
  863. return nfserr_inval;
  864. status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
  865. cstate, stateid, WR_STATE, &filp);
  866. if (status) {
  867. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  868. return status;
  869. }
  870. cnt = write->wr_buflen;
  871. write->wr_how_written = write->wr_stable_how;
  872. gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp));
  873. nvecs = fill_in_write_vector(rqstp->rq_vec, write);
  874. WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
  875. status = nfsd_write(rqstp, &cstate->current_fh, filp,
  876. write->wr_offset, rqstp->rq_vec, nvecs,
  877. &cnt, &write->wr_how_written);
  878. if (filp)
  879. fput(filp);
  880. write->wr_bytes_written = cnt;
  881. return status;
  882. }
  883. static __be32
  884. nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  885. struct nfsd4_fallocate *fallocate, int flags)
  886. {
  887. __be32 status = nfserr_notsupp;
  888. struct file *file;
  889. status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
  890. &fallocate->falloc_stateid,
  891. WR_STATE, &file);
  892. if (status != nfs_ok) {
  893. dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
  894. return status;
  895. }
  896. status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
  897. fallocate->falloc_offset,
  898. fallocate->falloc_length,
  899. flags);
  900. fput(file);
  901. return status;
  902. }
  903. static __be32
  904. nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  905. struct nfsd4_fallocate *fallocate)
  906. {
  907. return nfsd4_fallocate(rqstp, cstate, fallocate, 0);
  908. }
  909. static __be32
  910. nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  911. struct nfsd4_fallocate *fallocate)
  912. {
  913. return nfsd4_fallocate(rqstp, cstate, fallocate,
  914. FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
  915. }
  916. static __be32
  917. nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  918. struct nfsd4_seek *seek)
  919. {
  920. int whence;
  921. __be32 status;
  922. struct file *file;
  923. status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
  924. &seek->seek_stateid,
  925. RD_STATE, &file);
  926. if (status) {
  927. dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
  928. return status;
  929. }
  930. switch (seek->seek_whence) {
  931. case NFS4_CONTENT_DATA:
  932. whence = SEEK_DATA;
  933. break;
  934. case NFS4_CONTENT_HOLE:
  935. whence = SEEK_HOLE;
  936. break;
  937. default:
  938. status = nfserr_union_notsupp;
  939. goto out;
  940. }
  941. /*
  942. * Note: This call does change file->f_pos, but nothing in NFSD
  943. * should ever file->f_pos.
  944. */
  945. seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
  946. if (seek->seek_pos < 0)
  947. status = nfserrno(seek->seek_pos);
  948. else if (seek->seek_pos >= i_size_read(file_inode(file)))
  949. seek->seek_eof = true;
  950. out:
  951. fput(file);
  952. return status;
  953. }
  954. /* This routine never returns NFS_OK! If there are no other errors, it
  955. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  956. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  957. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  958. */
  959. static __be32
  960. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  961. struct nfsd4_verify *verify)
  962. {
  963. __be32 *buf, *p;
  964. int count;
  965. __be32 status;
  966. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  967. if (status)
  968. return status;
  969. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  970. if (status)
  971. return status;
  972. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  973. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  974. return nfserr_inval;
  975. if (verify->ve_attrlen & 3)
  976. return nfserr_inval;
  977. /* count in words:
  978. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  979. */
  980. count = 4 + (verify->ve_attrlen >> 2);
  981. buf = kmalloc(count << 2, GFP_KERNEL);
  982. if (!buf)
  983. return nfserr_jukebox;
  984. p = buf;
  985. status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
  986. cstate->current_fh.fh_export,
  987. cstate->current_fh.fh_dentry,
  988. verify->ve_bmval,
  989. rqstp, 0);
  990. /*
  991. * If nfsd4_encode_fattr() ran out of space, assume that's because
  992. * the attributes are longer (hence different) than those given:
  993. */
  994. if (status == nfserr_resource)
  995. status = nfserr_not_same;
  996. if (status)
  997. goto out_kfree;
  998. /* skip bitmap */
  999. p = buf + 1 + ntohl(buf[0]);
  1000. status = nfserr_not_same;
  1001. if (ntohl(*p++) != verify->ve_attrlen)
  1002. goto out_kfree;
  1003. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  1004. status = nfserr_same;
  1005. out_kfree:
  1006. kfree(buf);
  1007. return status;
  1008. }
  1009. static __be32
  1010. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1011. struct nfsd4_verify *verify)
  1012. {
  1013. __be32 status;
  1014. status = _nfsd4_verify(rqstp, cstate, verify);
  1015. return status == nfserr_not_same ? nfs_ok : status;
  1016. }
  1017. static __be32
  1018. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1019. struct nfsd4_verify *verify)
  1020. {
  1021. __be32 status;
  1022. status = _nfsd4_verify(rqstp, cstate, verify);
  1023. return status == nfserr_same ? nfs_ok : status;
  1024. }
  1025. #ifdef CONFIG_NFSD_PNFS
  1026. static const struct nfsd4_layout_ops *
  1027. nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
  1028. {
  1029. if (!exp->ex_layout_type) {
  1030. dprintk("%s: export does not support pNFS\n", __func__);
  1031. return NULL;
  1032. }
  1033. if (exp->ex_layout_type != layout_type) {
  1034. dprintk("%s: layout type %d not supported\n",
  1035. __func__, layout_type);
  1036. return NULL;
  1037. }
  1038. return nfsd4_layout_ops[layout_type];
  1039. }
  1040. static __be32
  1041. nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
  1042. struct nfsd4_compound_state *cstate,
  1043. struct nfsd4_getdeviceinfo *gdp)
  1044. {
  1045. const struct nfsd4_layout_ops *ops;
  1046. struct nfsd4_deviceid_map *map;
  1047. struct svc_export *exp;
  1048. __be32 nfserr;
  1049. dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
  1050. __func__,
  1051. gdp->gd_layout_type,
  1052. gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
  1053. gdp->gd_maxcount);
  1054. map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
  1055. if (!map) {
  1056. dprintk("%s: couldn't find device ID to export mapping!\n",
  1057. __func__);
  1058. return nfserr_noent;
  1059. }
  1060. exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
  1061. if (IS_ERR(exp)) {
  1062. dprintk("%s: could not find device id\n", __func__);
  1063. return nfserr_noent;
  1064. }
  1065. nfserr = nfserr_layoutunavailable;
  1066. ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
  1067. if (!ops)
  1068. goto out;
  1069. nfserr = nfs_ok;
  1070. if (gdp->gd_maxcount != 0)
  1071. nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, gdp);
  1072. gdp->gd_notify_types &= ops->notify_types;
  1073. exp_put(exp);
  1074. out:
  1075. return nfserr;
  1076. }
  1077. static __be32
  1078. nfsd4_layoutget(struct svc_rqst *rqstp,
  1079. struct nfsd4_compound_state *cstate,
  1080. struct nfsd4_layoutget *lgp)
  1081. {
  1082. struct svc_fh *current_fh = &cstate->current_fh;
  1083. const struct nfsd4_layout_ops *ops;
  1084. struct nfs4_layout_stateid *ls;
  1085. __be32 nfserr;
  1086. int accmode;
  1087. switch (lgp->lg_seg.iomode) {
  1088. case IOMODE_READ:
  1089. accmode = NFSD_MAY_READ;
  1090. break;
  1091. case IOMODE_RW:
  1092. accmode = NFSD_MAY_READ | NFSD_MAY_WRITE;
  1093. break;
  1094. default:
  1095. dprintk("%s: invalid iomode %d\n",
  1096. __func__, lgp->lg_seg.iomode);
  1097. nfserr = nfserr_badiomode;
  1098. goto out;
  1099. }
  1100. nfserr = fh_verify(rqstp, current_fh, 0, accmode);
  1101. if (nfserr)
  1102. goto out;
  1103. nfserr = nfserr_layoutunavailable;
  1104. ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
  1105. if (!ops)
  1106. goto out;
  1107. /*
  1108. * Verify minlength and range as per RFC5661:
  1109. * o If loga_length is less than loga_minlength,
  1110. * the metadata server MUST return NFS4ERR_INVAL.
  1111. * o If the sum of loga_offset and loga_minlength exceeds
  1112. * NFS4_UINT64_MAX, and loga_minlength is not
  1113. * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
  1114. * o If the sum of loga_offset and loga_length exceeds
  1115. * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
  1116. * the error NFS4ERR_INVAL MUST result.
  1117. */
  1118. nfserr = nfserr_inval;
  1119. if (lgp->lg_seg.length < lgp->lg_minlength ||
  1120. (lgp->lg_minlength != NFS4_MAX_UINT64 &&
  1121. lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
  1122. (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
  1123. lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
  1124. goto out;
  1125. if (lgp->lg_seg.length == 0)
  1126. goto out;
  1127. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
  1128. true, lgp->lg_layout_type, &ls);
  1129. if (nfserr) {
  1130. trace_layout_get_lookup_fail(&lgp->lg_sid);
  1131. goto out;
  1132. }
  1133. nfserr = nfserr_recallconflict;
  1134. if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
  1135. goto out_put_stid;
  1136. nfserr = ops->proc_layoutget(current_fh->fh_dentry->d_inode,
  1137. current_fh, lgp);
  1138. if (nfserr)
  1139. goto out_put_stid;
  1140. nfserr = nfsd4_insert_layout(lgp, ls);
  1141. out_put_stid:
  1142. nfs4_put_stid(&ls->ls_stid);
  1143. out:
  1144. return nfserr;
  1145. }
  1146. static __be32
  1147. nfsd4_layoutcommit(struct svc_rqst *rqstp,
  1148. struct nfsd4_compound_state *cstate,
  1149. struct nfsd4_layoutcommit *lcp)
  1150. {
  1151. const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
  1152. struct svc_fh *current_fh = &cstate->current_fh;
  1153. const struct nfsd4_layout_ops *ops;
  1154. loff_t new_size = lcp->lc_last_wr + 1;
  1155. struct inode *inode;
  1156. struct nfs4_layout_stateid *ls;
  1157. __be32 nfserr;
  1158. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
  1159. if (nfserr)
  1160. goto out;
  1161. nfserr = nfserr_layoutunavailable;
  1162. ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
  1163. if (!ops)
  1164. goto out;
  1165. inode = current_fh->fh_dentry->d_inode;
  1166. nfserr = nfserr_inval;
  1167. if (new_size <= seg->offset) {
  1168. dprintk("pnfsd: last write before layout segment\n");
  1169. goto out;
  1170. }
  1171. if (new_size > seg->offset + seg->length) {
  1172. dprintk("pnfsd: last write beyond layout segment\n");
  1173. goto out;
  1174. }
  1175. if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
  1176. dprintk("pnfsd: layoutcommit beyond EOF\n");
  1177. goto out;
  1178. }
  1179. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
  1180. false, lcp->lc_layout_type,
  1181. &ls);
  1182. if (nfserr) {
  1183. trace_layout_commit_lookup_fail(&lcp->lc_sid);
  1184. /* fixup error code as per RFC5661 */
  1185. if (nfserr == nfserr_bad_stateid)
  1186. nfserr = nfserr_badlayout;
  1187. goto out;
  1188. }
  1189. nfserr = ops->proc_layoutcommit(inode, lcp);
  1190. if (nfserr)
  1191. goto out_put_stid;
  1192. if (new_size > i_size_read(inode)) {
  1193. lcp->lc_size_chg = 1;
  1194. lcp->lc_newsize = new_size;
  1195. } else {
  1196. lcp->lc_size_chg = 0;
  1197. }
  1198. out_put_stid:
  1199. nfs4_put_stid(&ls->ls_stid);
  1200. out:
  1201. return nfserr;
  1202. }
  1203. static __be32
  1204. nfsd4_layoutreturn(struct svc_rqst *rqstp,
  1205. struct nfsd4_compound_state *cstate,
  1206. struct nfsd4_layoutreturn *lrp)
  1207. {
  1208. struct svc_fh *current_fh = &cstate->current_fh;
  1209. __be32 nfserr;
  1210. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
  1211. if (nfserr)
  1212. goto out;
  1213. nfserr = nfserr_layoutunavailable;
  1214. if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
  1215. goto out;
  1216. switch (lrp->lr_seg.iomode) {
  1217. case IOMODE_READ:
  1218. case IOMODE_RW:
  1219. case IOMODE_ANY:
  1220. break;
  1221. default:
  1222. dprintk("%s: invalid iomode %d\n", __func__,
  1223. lrp->lr_seg.iomode);
  1224. nfserr = nfserr_inval;
  1225. goto out;
  1226. }
  1227. switch (lrp->lr_return_type) {
  1228. case RETURN_FILE:
  1229. nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
  1230. break;
  1231. case RETURN_FSID:
  1232. case RETURN_ALL:
  1233. nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
  1234. break;
  1235. default:
  1236. dprintk("%s: invalid return_type %d\n", __func__,
  1237. lrp->lr_return_type);
  1238. nfserr = nfserr_inval;
  1239. break;
  1240. }
  1241. out:
  1242. return nfserr;
  1243. }
  1244. #endif /* CONFIG_NFSD_PNFS */
  1245. /*
  1246. * NULL call.
  1247. */
  1248. static __be32
  1249. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  1250. {
  1251. return nfs_ok;
  1252. }
  1253. static inline void nfsd4_increment_op_stats(u32 opnum)
  1254. {
  1255. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  1256. nfsdstats.nfs4_opcount[opnum]++;
  1257. }
  1258. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  1259. void *);
  1260. typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
  1261. typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
  1262. typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
  1263. enum nfsd4_op_flags {
  1264. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  1265. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  1266. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  1267. /* For rfc 5661 section 2.6.3.1.1: */
  1268. OP_HANDLES_WRONGSEC = 1 << 3,
  1269. OP_IS_PUTFH_LIKE = 1 << 4,
  1270. /*
  1271. * These are the ops whose result size we estimate before
  1272. * encoding, to avoid performing an op then not being able to
  1273. * respond or cache a response. This includes writes and setattrs
  1274. * as well as the operations usually called "nonidempotent":
  1275. */
  1276. OP_MODIFIES_SOMETHING = 1 << 5,
  1277. /*
  1278. * Cache compounds containing these ops in the xid-based drc:
  1279. * We use the DRC for compounds containing non-idempotent
  1280. * operations, *except* those that are 4.1-specific (since
  1281. * sessions provide their own EOS), and except for stateful
  1282. * operations other than setclientid and setclientid_confirm
  1283. * (since sequence numbers provide EOS for open, lock, etc in
  1284. * the v4.0 case).
  1285. */
  1286. OP_CACHEME = 1 << 6,
  1287. /*
  1288. * These are ops which clear current state id.
  1289. */
  1290. OP_CLEAR_STATEID = 1 << 7,
  1291. };
  1292. struct nfsd4_operation {
  1293. nfsd4op_func op_func;
  1294. u32 op_flags;
  1295. char *op_name;
  1296. /* Try to get response size before operation */
  1297. nfsd4op_rsize op_rsize_bop;
  1298. stateid_getter op_get_currentstateid;
  1299. stateid_setter op_set_currentstateid;
  1300. };
  1301. static struct nfsd4_operation nfsd4_ops[];
  1302. static const char *nfsd4_op_name(unsigned opnum);
  1303. /*
  1304. * Enforce NFSv4.1 COMPOUND ordering rules:
  1305. *
  1306. * Also note, enforced elsewhere:
  1307. * - SEQUENCE other than as first op results in
  1308. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  1309. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  1310. * (Enforced in nfsd4_bind_conn_to_session().)
  1311. * - DESTROY_SESSION must be the final operation in a compound, if
  1312. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  1313. * (Enforced in nfsd4_destroy_session().)
  1314. */
  1315. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  1316. {
  1317. struct nfsd4_op *op = &args->ops[0];
  1318. /* These ordering requirements don't apply to NFSv4.0: */
  1319. if (args->minorversion == 0)
  1320. return nfs_ok;
  1321. /* This is weird, but OK, not our problem: */
  1322. if (args->opcnt == 0)
  1323. return nfs_ok;
  1324. if (op->status == nfserr_op_illegal)
  1325. return nfs_ok;
  1326. if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  1327. return nfserr_op_not_in_session;
  1328. if (op->opnum == OP_SEQUENCE)
  1329. return nfs_ok;
  1330. if (args->opcnt != 1)
  1331. return nfserr_not_only_op;
  1332. return nfs_ok;
  1333. }
  1334. static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  1335. {
  1336. return &nfsd4_ops[op->opnum];
  1337. }
  1338. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  1339. {
  1340. if (op->opnum == OP_ILLEGAL)
  1341. return false;
  1342. return OPDESC(op)->op_flags & OP_CACHEME;
  1343. }
  1344. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  1345. {
  1346. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1347. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  1348. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  1349. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  1350. struct nfsd4_operation *thisd;
  1351. struct nfsd4_operation *nextd;
  1352. thisd = OPDESC(this);
  1353. /*
  1354. * Most ops check wronsec on our own; only the putfh-like ops
  1355. * have special rules.
  1356. */
  1357. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  1358. return false;
  1359. /*
  1360. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  1361. * put-filehandle operation if we're not going to use the
  1362. * result:
  1363. */
  1364. if (argp->opcnt == resp->opcnt)
  1365. return false;
  1366. if (next->opnum == OP_ILLEGAL)
  1367. return false;
  1368. nextd = OPDESC(next);
  1369. /*
  1370. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  1371. * errors themselves as necessary; others should check for them
  1372. * now:
  1373. */
  1374. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  1375. }
  1376. static void svcxdr_init_encode(struct svc_rqst *rqstp,
  1377. struct nfsd4_compoundres *resp)
  1378. {
  1379. struct xdr_stream *xdr = &resp->xdr;
  1380. struct xdr_buf *buf = &rqstp->rq_res;
  1381. struct kvec *head = buf->head;
  1382. xdr->buf = buf;
  1383. xdr->iov = head;
  1384. xdr->p = head->iov_base + head->iov_len;
  1385. xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
  1386. /* Tail and page_len should be zero at this point: */
  1387. buf->len = buf->head[0].iov_len;
  1388. xdr->scratch.iov_len = 0;
  1389. xdr->page_ptr = buf->pages - 1;
  1390. buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
  1391. - rqstp->rq_auth_slack;
  1392. }
  1393. /*
  1394. * COMPOUND call.
  1395. */
  1396. static __be32
  1397. nfsd4_proc_compound(struct svc_rqst *rqstp,
  1398. struct nfsd4_compoundargs *args,
  1399. struct nfsd4_compoundres *resp)
  1400. {
  1401. struct nfsd4_op *op;
  1402. struct nfsd4_operation *opdesc;
  1403. struct nfsd4_compound_state *cstate = &resp->cstate;
  1404. struct svc_fh *current_fh = &cstate->current_fh;
  1405. struct svc_fh *save_fh = &cstate->save_fh;
  1406. __be32 status;
  1407. svcxdr_init_encode(rqstp, resp);
  1408. resp->tagp = resp->xdr.p;
  1409. /* reserve space for: taglen, tag, and opcnt */
  1410. xdr_reserve_space(&resp->xdr, 8 + args->taglen);
  1411. resp->taglen = args->taglen;
  1412. resp->tag = args->tag;
  1413. resp->rqstp = rqstp;
  1414. cstate->minorversion = args->minorversion;
  1415. fh_init(current_fh, NFS4_FHSIZE);
  1416. fh_init(save_fh, NFS4_FHSIZE);
  1417. /*
  1418. * Don't use the deferral mechanism for NFSv4; compounds make it
  1419. * too hard to avoid non-idempotency problems.
  1420. */
  1421. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1422. /*
  1423. * According to RFC3010, this takes precedence over all other errors.
  1424. */
  1425. status = nfserr_minor_vers_mismatch;
  1426. if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0)
  1427. goto out;
  1428. status = nfs41_check_op_ordering(args);
  1429. if (status) {
  1430. op = &args->ops[0];
  1431. op->status = status;
  1432. goto encode_op;
  1433. }
  1434. while (!status && resp->opcnt < args->opcnt) {
  1435. op = &args->ops[resp->opcnt++];
  1436. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  1437. resp->opcnt, args->opcnt, op->opnum,
  1438. nfsd4_op_name(op->opnum));
  1439. /*
  1440. * The XDR decode routines may have pre-set op->status;
  1441. * for example, if there is a miscellaneous XDR error
  1442. * it will be set to nfserr_bad_xdr.
  1443. */
  1444. if (op->status) {
  1445. if (op->opnum == OP_OPEN)
  1446. op->status = nfsd4_open_omfg(rqstp, cstate, op);
  1447. goto encode_op;
  1448. }
  1449. opdesc = OPDESC(op);
  1450. if (!current_fh->fh_dentry) {
  1451. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  1452. op->status = nfserr_nofilehandle;
  1453. goto encode_op;
  1454. }
  1455. } else if (current_fh->fh_export->ex_fslocs.migrated &&
  1456. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  1457. op->status = nfserr_moved;
  1458. goto encode_op;
  1459. }
  1460. fh_clear_wcc(current_fh);
  1461. /* If op is non-idempotent */
  1462. if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  1463. /*
  1464. * Don't execute this op if we couldn't encode a
  1465. * succesful reply:
  1466. */
  1467. u32 plen = opdesc->op_rsize_bop(rqstp, op);
  1468. /*
  1469. * Plus if there's another operation, make sure
  1470. * we'll have space to at least encode an error:
  1471. */
  1472. if (resp->opcnt < args->opcnt)
  1473. plen += COMPOUND_ERR_SLACK_SPACE;
  1474. op->status = nfsd4_check_resp_size(resp, plen);
  1475. }
  1476. if (op->status)
  1477. goto encode_op;
  1478. if (opdesc->op_get_currentstateid)
  1479. opdesc->op_get_currentstateid(cstate, &op->u);
  1480. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  1481. if (!op->status) {
  1482. if (opdesc->op_set_currentstateid)
  1483. opdesc->op_set_currentstateid(cstate, &op->u);
  1484. if (opdesc->op_flags & OP_CLEAR_STATEID)
  1485. clear_current_stateid(cstate);
  1486. if (need_wrongsec_check(rqstp))
  1487. op->status = check_nfsd_access(current_fh->fh_export, rqstp);
  1488. }
  1489. encode_op:
  1490. /* Only from SEQUENCE */
  1491. if (cstate->status == nfserr_replay_cache) {
  1492. dprintk("%s NFS4.1 replay from cache\n", __func__);
  1493. status = op->status;
  1494. goto out;
  1495. }
  1496. if (op->status == nfserr_replay_me) {
  1497. op->replay = &cstate->replay_owner->so_replay;
  1498. nfsd4_encode_replay(&resp->xdr, op);
  1499. status = op->status = op->replay->rp_status;
  1500. } else {
  1501. nfsd4_encode_operation(resp, op);
  1502. status = op->status;
  1503. }
  1504. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  1505. args->ops, args->opcnt, resp->opcnt, op->opnum,
  1506. be32_to_cpu(status));
  1507. nfsd4_cstate_clear_replay(cstate);
  1508. /* XXX Ugh, we need to get rid of this kind of special case: */
  1509. if (op->opnum == OP_READ && op->u.read.rd_filp)
  1510. fput(op->u.read.rd_filp);
  1511. nfsd4_increment_op_stats(op->opnum);
  1512. }
  1513. cstate->status = status;
  1514. fh_put(current_fh);
  1515. fh_put(save_fh);
  1516. BUG_ON(cstate->replay_owner);
  1517. out:
  1518. /* Reset deferral mechanism for RPC deferrals */
  1519. set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1520. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1521. return status;
  1522. }
  1523. #define op_encode_hdr_size (2)
  1524. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  1525. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  1526. #define op_encode_change_info_maxsz (5)
  1527. #define nfs4_fattr_bitmap_maxsz (4)
  1528. /* We'll fall back on returning no lockowner if run out of space: */
  1529. #define op_encode_lockowner_maxsz (0)
  1530. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  1531. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1532. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  1533. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  1534. op_encode_ace_maxsz)
  1535. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  1536. static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1537. {
  1538. return (op_encode_hdr_size) * sizeof(__be32);
  1539. }
  1540. static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1541. {
  1542. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  1543. }
  1544. static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1545. {
  1546. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1547. }
  1548. static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1549. {
  1550. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1551. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1552. }
  1553. /*
  1554. * Note since this is an idempotent operation we won't insist on failing
  1555. * the op prematurely if the estimate is too large. We may turn off splice
  1556. * reads unnecessarily.
  1557. */
  1558. static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
  1559. struct nfsd4_op *op)
  1560. {
  1561. u32 *bmap = op->u.getattr.ga_bmval;
  1562. u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
  1563. u32 ret = 0;
  1564. if (bmap0 & FATTR4_WORD0_ACL)
  1565. return svc_max_payload(rqstp);
  1566. if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
  1567. return svc_max_payload(rqstp);
  1568. if (bmap1 & FATTR4_WORD1_OWNER) {
  1569. ret += IDMAP_NAMESZ + 4;
  1570. bmap1 &= ~FATTR4_WORD1_OWNER;
  1571. }
  1572. if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
  1573. ret += IDMAP_NAMESZ + 4;
  1574. bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
  1575. }
  1576. if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
  1577. ret += NFS4_FHSIZE + 4;
  1578. bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
  1579. }
  1580. if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
  1581. ret += NFSD4_MAX_SEC_LABEL_LEN + 12;
  1582. bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
  1583. }
  1584. /*
  1585. * Largest of remaining attributes are 16 bytes (e.g.,
  1586. * supported_attributes)
  1587. */
  1588. ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
  1589. /* bitmask, length */
  1590. ret += 20;
  1591. return ret;
  1592. }
  1593. static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1594. {
  1595. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1596. * sizeof(__be32);
  1597. }
  1598. static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1599. {
  1600. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  1601. * sizeof(__be32);
  1602. }
  1603. static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1604. {
  1605. return (op_encode_hdr_size + op_encode_stateid_maxsz
  1606. + op_encode_change_info_maxsz + 1
  1607. + nfs4_fattr_bitmap_maxsz
  1608. + op_encode_delegation_maxsz) * sizeof(__be32);
  1609. }
  1610. static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1611. {
  1612. u32 maxcount = 0, rlen = 0;
  1613. maxcount = svc_max_payload(rqstp);
  1614. rlen = min(op->u.read.rd_length, maxcount);
  1615. return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  1616. }
  1617. static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1618. {
  1619. u32 maxcount = 0, rlen = 0;
  1620. maxcount = svc_max_payload(rqstp);
  1621. rlen = min(op->u.readdir.rd_maxcount, maxcount);
  1622. return (op_encode_hdr_size + op_encode_verifier_maxsz +
  1623. XDR_QUADLEN(rlen)) * sizeof(__be32);
  1624. }
  1625. static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1626. {
  1627. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1628. * sizeof(__be32);
  1629. }
  1630. static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1631. {
  1632. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1633. + op_encode_change_info_maxsz) * sizeof(__be32);
  1634. }
  1635. static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
  1636. struct nfsd4_op *op)
  1637. {
  1638. return (op_encode_hdr_size
  1639. + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
  1640. }
  1641. static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1642. {
  1643. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1644. }
  1645. static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1646. {
  1647. return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
  1648. sizeof(__be32);
  1649. }
  1650. static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1651. {
  1652. return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
  1653. }
  1654. static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1655. {
  1656. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  1657. 1 + 1 + /* eir_flags, spr_how */\
  1658. 4 + /* spo_must_enforce & _allow with bitmap */\
  1659. 2 + /*eir_server_owner.so_minor_id */\
  1660. /* eir_server_owner.so_major_id<> */\
  1661. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1662. /* eir_server_scope<> */\
  1663. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1664. 1 + /* eir_server_impl_id array length */\
  1665. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  1666. }
  1667. static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1668. {
  1669. return (op_encode_hdr_size + \
  1670. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  1671. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  1672. }
  1673. static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1674. {
  1675. return (op_encode_hdr_size + \
  1676. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  1677. 2 + /* csr_sequence, csr_flags */\
  1678. op_encode_channel_attrs_maxsz + \
  1679. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  1680. }
  1681. #ifdef CONFIG_NFSD_PNFS
  1682. /*
  1683. * At this stage we don't really know what layout driver will handle the request,
  1684. * so we need to define an arbitrary upper bound here.
  1685. */
  1686. #define MAX_LAYOUT_SIZE 128
  1687. static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1688. {
  1689. return (op_encode_hdr_size +
  1690. 1 /* logr_return_on_close */ +
  1691. op_encode_stateid_maxsz +
  1692. 1 /* nr of layouts */ +
  1693. MAX_LAYOUT_SIZE) * sizeof(__be32);
  1694. }
  1695. static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1696. {
  1697. return (op_encode_hdr_size +
  1698. 1 /* locr_newsize */ +
  1699. 2 /* ns_size */) * sizeof(__be32);
  1700. }
  1701. static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1702. {
  1703. return (op_encode_hdr_size +
  1704. 1 /* lrs_stateid */ +
  1705. op_encode_stateid_maxsz) * sizeof(__be32);
  1706. }
  1707. #endif /* CONFIG_NFSD_PNFS */
  1708. static struct nfsd4_operation nfsd4_ops[] = {
  1709. [OP_ACCESS] = {
  1710. .op_func = (nfsd4op_func)nfsd4_access,
  1711. .op_name = "OP_ACCESS",
  1712. },
  1713. [OP_CLOSE] = {
  1714. .op_func = (nfsd4op_func)nfsd4_close,
  1715. .op_flags = OP_MODIFIES_SOMETHING,
  1716. .op_name = "OP_CLOSE",
  1717. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1718. .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
  1719. .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
  1720. },
  1721. [OP_COMMIT] = {
  1722. .op_func = (nfsd4op_func)nfsd4_commit,
  1723. .op_flags = OP_MODIFIES_SOMETHING,
  1724. .op_name = "OP_COMMIT",
  1725. .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
  1726. },
  1727. [OP_CREATE] = {
  1728. .op_func = (nfsd4op_func)nfsd4_create,
  1729. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
  1730. .op_name = "OP_CREATE",
  1731. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
  1732. },
  1733. [OP_DELEGRETURN] = {
  1734. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1735. .op_flags = OP_MODIFIES_SOMETHING,
  1736. .op_name = "OP_DELEGRETURN",
  1737. .op_rsize_bop = nfsd4_only_status_rsize,
  1738. .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
  1739. },
  1740. [OP_GETATTR] = {
  1741. .op_func = (nfsd4op_func)nfsd4_getattr,
  1742. .op_flags = ALLOWED_ON_ABSENT_FS,
  1743. .op_rsize_bop = nfsd4_getattr_rsize,
  1744. .op_name = "OP_GETATTR",
  1745. },
  1746. [OP_GETFH] = {
  1747. .op_func = (nfsd4op_func)nfsd4_getfh,
  1748. .op_name = "OP_GETFH",
  1749. },
  1750. [OP_LINK] = {
  1751. .op_func = (nfsd4op_func)nfsd4_link,
  1752. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  1753. | OP_CACHEME,
  1754. .op_name = "OP_LINK",
  1755. .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
  1756. },
  1757. [OP_LOCK] = {
  1758. .op_func = (nfsd4op_func)nfsd4_lock,
  1759. .op_flags = OP_MODIFIES_SOMETHING,
  1760. .op_name = "OP_LOCK",
  1761. .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
  1762. .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
  1763. },
  1764. [OP_LOCKT] = {
  1765. .op_func = (nfsd4op_func)nfsd4_lockt,
  1766. .op_name = "OP_LOCKT",
  1767. },
  1768. [OP_LOCKU] = {
  1769. .op_func = (nfsd4op_func)nfsd4_locku,
  1770. .op_flags = OP_MODIFIES_SOMETHING,
  1771. .op_name = "OP_LOCKU",
  1772. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1773. .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
  1774. },
  1775. [OP_LOOKUP] = {
  1776. .op_func = (nfsd4op_func)nfsd4_lookup,
  1777. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1778. .op_name = "OP_LOOKUP",
  1779. },
  1780. [OP_LOOKUPP] = {
  1781. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1782. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1783. .op_name = "OP_LOOKUPP",
  1784. },
  1785. [OP_NVERIFY] = {
  1786. .op_func = (nfsd4op_func)nfsd4_nverify,
  1787. .op_name = "OP_NVERIFY",
  1788. },
  1789. [OP_OPEN] = {
  1790. .op_func = (nfsd4op_func)nfsd4_open,
  1791. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1792. .op_name = "OP_OPEN",
  1793. .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
  1794. .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
  1795. },
  1796. [OP_OPEN_CONFIRM] = {
  1797. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1798. .op_flags = OP_MODIFIES_SOMETHING,
  1799. .op_name = "OP_OPEN_CONFIRM",
  1800. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1801. },
  1802. [OP_OPEN_DOWNGRADE] = {
  1803. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1804. .op_flags = OP_MODIFIES_SOMETHING,
  1805. .op_name = "OP_OPEN_DOWNGRADE",
  1806. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1807. .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
  1808. .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
  1809. },
  1810. [OP_PUTFH] = {
  1811. .op_func = (nfsd4op_func)nfsd4_putfh,
  1812. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1813. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1814. .op_name = "OP_PUTFH",
  1815. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1816. },
  1817. [OP_PUTPUBFH] = {
  1818. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1819. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1820. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1821. .op_name = "OP_PUTPUBFH",
  1822. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1823. },
  1824. [OP_PUTROOTFH] = {
  1825. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1826. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1827. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1828. .op_name = "OP_PUTROOTFH",
  1829. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1830. },
  1831. [OP_READ] = {
  1832. .op_func = (nfsd4op_func)nfsd4_read,
  1833. .op_name = "OP_READ",
  1834. .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
  1835. .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
  1836. },
  1837. [OP_READDIR] = {
  1838. .op_func = (nfsd4op_func)nfsd4_readdir,
  1839. .op_name = "OP_READDIR",
  1840. .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
  1841. },
  1842. [OP_READLINK] = {
  1843. .op_func = (nfsd4op_func)nfsd4_readlink,
  1844. .op_name = "OP_READLINK",
  1845. },
  1846. [OP_REMOVE] = {
  1847. .op_func = (nfsd4op_func)nfsd4_remove,
  1848. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1849. .op_name = "OP_REMOVE",
  1850. .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
  1851. },
  1852. [OP_RENAME] = {
  1853. .op_func = (nfsd4op_func)nfsd4_rename,
  1854. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1855. .op_name = "OP_RENAME",
  1856. .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
  1857. },
  1858. [OP_RENEW] = {
  1859. .op_func = (nfsd4op_func)nfsd4_renew,
  1860. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1861. | OP_MODIFIES_SOMETHING,
  1862. .op_name = "OP_RENEW",
  1863. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1864. },
  1865. [OP_RESTOREFH] = {
  1866. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1867. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1868. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1869. .op_name = "OP_RESTOREFH",
  1870. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1871. },
  1872. [OP_SAVEFH] = {
  1873. .op_func = (nfsd4op_func)nfsd4_savefh,
  1874. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1875. .op_name = "OP_SAVEFH",
  1876. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1877. },
  1878. [OP_SECINFO] = {
  1879. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1880. .op_flags = OP_HANDLES_WRONGSEC,
  1881. .op_name = "OP_SECINFO",
  1882. },
  1883. [OP_SETATTR] = {
  1884. .op_func = (nfsd4op_func)nfsd4_setattr,
  1885. .op_name = "OP_SETATTR",
  1886. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1887. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
  1888. .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
  1889. },
  1890. [OP_SETCLIENTID] = {
  1891. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1892. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1893. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1894. .op_name = "OP_SETCLIENTID",
  1895. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
  1896. },
  1897. [OP_SETCLIENTID_CONFIRM] = {
  1898. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1899. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1900. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1901. .op_name = "OP_SETCLIENTID_CONFIRM",
  1902. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1903. },
  1904. [OP_VERIFY] = {
  1905. .op_func = (nfsd4op_func)nfsd4_verify,
  1906. .op_name = "OP_VERIFY",
  1907. },
  1908. [OP_WRITE] = {
  1909. .op_func = (nfsd4op_func)nfsd4_write,
  1910. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1911. .op_name = "OP_WRITE",
  1912. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  1913. .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
  1914. },
  1915. [OP_RELEASE_LOCKOWNER] = {
  1916. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1917. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1918. | OP_MODIFIES_SOMETHING,
  1919. .op_name = "OP_RELEASE_LOCKOWNER",
  1920. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1921. },
  1922. /* NFSv4.1 operations */
  1923. [OP_EXCHANGE_ID] = {
  1924. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1925. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1926. | OP_MODIFIES_SOMETHING,
  1927. .op_name = "OP_EXCHANGE_ID",
  1928. .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
  1929. },
  1930. [OP_BACKCHANNEL_CTL] = {
  1931. .op_func = (nfsd4op_func)nfsd4_backchannel_ctl,
  1932. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1933. .op_name = "OP_BACKCHANNEL_CTL",
  1934. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1935. },
  1936. [OP_BIND_CONN_TO_SESSION] = {
  1937. .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
  1938. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1939. | OP_MODIFIES_SOMETHING,
  1940. .op_name = "OP_BIND_CONN_TO_SESSION",
  1941. .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
  1942. },
  1943. [OP_CREATE_SESSION] = {
  1944. .op_func = (nfsd4op_func)nfsd4_create_session,
  1945. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1946. | OP_MODIFIES_SOMETHING,
  1947. .op_name = "OP_CREATE_SESSION",
  1948. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
  1949. },
  1950. [OP_DESTROY_SESSION] = {
  1951. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1952. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1953. | OP_MODIFIES_SOMETHING,
  1954. .op_name = "OP_DESTROY_SESSION",
  1955. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1956. },
  1957. [OP_SEQUENCE] = {
  1958. .op_func = (nfsd4op_func)nfsd4_sequence,
  1959. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1960. .op_name = "OP_SEQUENCE",
  1961. .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize,
  1962. },
  1963. [OP_DESTROY_CLIENTID] = {
  1964. .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
  1965. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1966. | OP_MODIFIES_SOMETHING,
  1967. .op_name = "OP_DESTROY_CLIENTID",
  1968. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1969. },
  1970. [OP_RECLAIM_COMPLETE] = {
  1971. .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
  1972. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1973. .op_name = "OP_RECLAIM_COMPLETE",
  1974. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1975. },
  1976. [OP_SECINFO_NO_NAME] = {
  1977. .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
  1978. .op_flags = OP_HANDLES_WRONGSEC,
  1979. .op_name = "OP_SECINFO_NO_NAME",
  1980. },
  1981. [OP_TEST_STATEID] = {
  1982. .op_func = (nfsd4op_func)nfsd4_test_stateid,
  1983. .op_flags = ALLOWED_WITHOUT_FH,
  1984. .op_name = "OP_TEST_STATEID",
  1985. },
  1986. [OP_FREE_STATEID] = {
  1987. .op_func = (nfsd4op_func)nfsd4_free_stateid,
  1988. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1989. .op_name = "OP_FREE_STATEID",
  1990. .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid,
  1991. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1992. },
  1993. #ifdef CONFIG_NFSD_PNFS
  1994. [OP_GETDEVICEINFO] = {
  1995. .op_func = (nfsd4op_func)nfsd4_getdeviceinfo,
  1996. .op_flags = ALLOWED_WITHOUT_FH,
  1997. .op_name = "OP_GETDEVICEINFO",
  1998. },
  1999. [OP_LAYOUTGET] = {
  2000. .op_func = (nfsd4op_func)nfsd4_layoutget,
  2001. .op_flags = OP_MODIFIES_SOMETHING,
  2002. .op_name = "OP_LAYOUTGET",
  2003. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize,
  2004. },
  2005. [OP_LAYOUTCOMMIT] = {
  2006. .op_func = (nfsd4op_func)nfsd4_layoutcommit,
  2007. .op_flags = OP_MODIFIES_SOMETHING,
  2008. .op_name = "OP_LAYOUTCOMMIT",
  2009. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize,
  2010. },
  2011. [OP_LAYOUTRETURN] = {
  2012. .op_func = (nfsd4op_func)nfsd4_layoutreturn,
  2013. .op_flags = OP_MODIFIES_SOMETHING,
  2014. .op_name = "OP_LAYOUTRETURN",
  2015. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize,
  2016. },
  2017. #endif /* CONFIG_NFSD_PNFS */
  2018. /* NFSv4.2 operations */
  2019. [OP_ALLOCATE] = {
  2020. .op_func = (nfsd4op_func)nfsd4_allocate,
  2021. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2022. .op_name = "OP_ALLOCATE",
  2023. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  2024. },
  2025. [OP_DEALLOCATE] = {
  2026. .op_func = (nfsd4op_func)nfsd4_deallocate,
  2027. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2028. .op_name = "OP_DEALLOCATE",
  2029. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  2030. },
  2031. [OP_SEEK] = {
  2032. .op_func = (nfsd4op_func)nfsd4_seek,
  2033. .op_name = "OP_SEEK",
  2034. },
  2035. };
  2036. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
  2037. {
  2038. struct nfsd4_operation *opdesc;
  2039. nfsd4op_rsize estimator;
  2040. if (op->opnum == OP_ILLEGAL)
  2041. return op_encode_hdr_size * sizeof(__be32);
  2042. opdesc = OPDESC(op);
  2043. estimator = opdesc->op_rsize_bop;
  2044. return estimator ? estimator(rqstp, op) : PAGE_SIZE;
  2045. }
  2046. void warn_on_nonidempotent_op(struct nfsd4_op *op)
  2047. {
  2048. if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
  2049. pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
  2050. op->opnum, nfsd4_op_name(op->opnum));
  2051. WARN_ON_ONCE(1);
  2052. }
  2053. }
  2054. static const char *nfsd4_op_name(unsigned opnum)
  2055. {
  2056. if (opnum < ARRAY_SIZE(nfsd4_ops))
  2057. return nfsd4_ops[opnum].op_name;
  2058. return "unknown_operation";
  2059. }
  2060. #define nfsd4_voidres nfsd4_voidargs
  2061. struct nfsd4_voidargs { int dummy; };
  2062. static struct svc_procedure nfsd_procedures4[2] = {
  2063. [NFSPROC4_NULL] = {
  2064. .pc_func = (svc_procfunc) nfsd4_proc_null,
  2065. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  2066. .pc_argsize = sizeof(struct nfsd4_voidargs),
  2067. .pc_ressize = sizeof(struct nfsd4_voidres),
  2068. .pc_cachetype = RC_NOCACHE,
  2069. .pc_xdrressize = 1,
  2070. },
  2071. [NFSPROC4_COMPOUND] = {
  2072. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  2073. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  2074. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  2075. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  2076. .pc_ressize = sizeof(struct nfsd4_compoundres),
  2077. .pc_release = nfsd4_release_compoundargs,
  2078. .pc_cachetype = RC_NOCACHE,
  2079. .pc_xdrressize = NFSD_BUFSIZE/4,
  2080. },
  2081. };
  2082. struct svc_version nfsd_version4 = {
  2083. .vs_vers = 4,
  2084. .vs_nproc = 2,
  2085. .vs_proc = nfsd_procedures4,
  2086. .vs_dispatch = nfsd_dispatch,
  2087. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  2088. .vs_rpcb_optnl = 1,
  2089. };
  2090. /*
  2091. * Local variables:
  2092. * c-basic-offset: 8
  2093. * End:
  2094. */