nfs4proc.c 48 KB

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