nfs4proc.c 52 KB

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