nfs4proc.c 50 KB

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