nfs4proc.c 54 KB

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