nfs4proc.c 53 KB

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