nfs4proc.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. /*
  2. * fs/nfsd/nfs4proc.c
  3. *
  4. * Server-side procedures for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/param.h>
  38. #include <linux/major.h>
  39. #include <linux/slab.h>
  40. #include <linux/file.h>
  41. #include <linux/sunrpc/svc.h>
  42. #include <linux/nfsd/nfsd.h>
  43. #include <linux/nfsd/cache.h>
  44. #include <linux/nfs4.h>
  45. #include <linux/nfsd/state.h>
  46. #include <linux/nfsd/xdr4.h>
  47. #include <linux/nfs4_acl.h>
  48. #include <linux/sunrpc/gss_api.h>
  49. #define NFSDDBG_FACILITY NFSDDBG_PROC
  50. static u32 nfsd_attrmask[] = {
  51. NFSD_WRITEABLE_ATTRS_WORD0,
  52. NFSD_WRITEABLE_ATTRS_WORD1,
  53. NFSD_WRITEABLE_ATTRS_WORD2
  54. };
  55. static u32 nfsd41_ex_attrmask[] = {
  56. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  57. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  58. NFSD_SUPPATTR_EXCLCREAT_WORD2
  59. };
  60. static __be32
  61. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  62. u32 *bmval, u32 *writable)
  63. {
  64. struct dentry *dentry = cstate->current_fh.fh_dentry;
  65. struct svc_export *exp = cstate->current_fh.fh_export;
  66. /*
  67. * Check about attributes are supported by the NFSv4 server or not.
  68. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
  69. */
  70. if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
  71. (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
  72. (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
  73. return nfserr_attrnotsupp;
  74. /*
  75. * Check FATTR4_WORD0_ACL & FATTR4_WORD0_FS_LOCATIONS can be supported
  76. * in current environment or not.
  77. */
  78. if (bmval[0] & FATTR4_WORD0_ACL) {
  79. if (!IS_POSIXACL(dentry->d_inode))
  80. return nfserr_attrnotsupp;
  81. }
  82. if (bmval[0] & FATTR4_WORD0_FS_LOCATIONS) {
  83. if (exp->ex_fslocs.locations == NULL)
  84. return nfserr_attrnotsupp;
  85. }
  86. /*
  87. * According to spec, read-only attributes return ERR_INVAL.
  88. */
  89. if (writable) {
  90. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  91. (bmval[2] & ~writable[2]))
  92. return nfserr_inval;
  93. }
  94. return nfs_ok;
  95. }
  96. static __be32
  97. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  98. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  99. {
  100. __be32 status = nfs_ok;
  101. if (open->op_create == NFS4_OPEN_CREATE) {
  102. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  103. || open->op_createmode == NFS4_CREATE_GUARDED)
  104. status = check_attr_support(rqstp, cstate,
  105. open->op_bmval, nfsd_attrmask);
  106. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  107. status = check_attr_support(rqstp, cstate,
  108. open->op_bmval, nfsd41_ex_attrmask);
  109. }
  110. return status;
  111. }
  112. static int
  113. is_create_with_attrs(struct nfsd4_open *open)
  114. {
  115. return open->op_create == NFS4_OPEN_CREATE
  116. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  117. || open->op_createmode == NFS4_CREATE_GUARDED
  118. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  119. }
  120. /*
  121. * if error occurs when setting the acl, just clear the acl bit
  122. * in the returned attr bitmap.
  123. */
  124. static void
  125. do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
  126. struct nfs4_acl *acl, u32 *bmval)
  127. {
  128. __be32 status;
  129. status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
  130. if (status)
  131. /*
  132. * We should probably fail the whole open at this point,
  133. * but we've already created the file, so it's too late;
  134. * So this seems the least of evils:
  135. */
  136. bmval[0] &= ~FATTR4_WORD0_ACL;
  137. }
  138. static inline void
  139. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  140. {
  141. fh_put(dst);
  142. dget(src->fh_dentry);
  143. if (src->fh_export)
  144. cache_get(&src->fh_export->h);
  145. *dst = *src;
  146. }
  147. static __be32
  148. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  149. {
  150. __be32 status;
  151. if (open->op_truncate &&
  152. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  153. return nfserr_inval;
  154. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  155. accmode |= NFSD_MAY_READ;
  156. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  157. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  158. if (open->op_share_deny & NFS4_SHARE_DENY_WRITE)
  159. accmode |= NFSD_MAY_WRITE;
  160. status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
  161. return status;
  162. }
  163. static __be32
  164. do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  165. {
  166. struct svc_fh resfh;
  167. __be32 status;
  168. int created = 0;
  169. fh_init(&resfh, NFS4_FHSIZE);
  170. open->op_truncate = 0;
  171. if (open->op_create) {
  172. /* FIXME: check session persistence and pnfs flags.
  173. * The nfsv4.1 spec requires the following semantics:
  174. *
  175. * Persistent | pNFS | Server REQUIRED | Client Allowed
  176. * Reply Cache | server | |
  177. * -------------+--------+-----------------+--------------------
  178. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  179. * | | | (SHOULD)
  180. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  181. * | | | (SHOULD NOT)
  182. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  183. * yes | no | GUARDED4 | GUARDED4
  184. * yes | yes | GUARDED4 | GUARDED4
  185. */
  186. /*
  187. * Note: create modes (UNCHECKED,GUARDED...) are the same
  188. * in NFSv4 as in v3.
  189. */
  190. status = nfsd_create_v3(rqstp, current_fh, open->op_fname.data,
  191. open->op_fname.len, &open->op_iattr,
  192. &resfh, open->op_createmode,
  193. (u32 *)open->op_verf.data,
  194. &open->op_truncate, &created);
  195. /*
  196. * Following rfc 3530 14.2.16, use the returned bitmask
  197. * to indicate which attributes we used to store the
  198. * verifier:
  199. */
  200. if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
  201. open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
  202. FATTR4_WORD1_TIME_MODIFY);
  203. } else {
  204. status = nfsd_lookup(rqstp, current_fh,
  205. open->op_fname.data, open->op_fname.len, &resfh);
  206. fh_unlock(current_fh);
  207. }
  208. if (status)
  209. goto out;
  210. if (is_create_with_attrs(open) && open->op_acl != NULL)
  211. do_set_nfs4_acl(rqstp, &resfh, open->op_acl, open->op_bmval);
  212. set_change_info(&open->op_cinfo, current_fh);
  213. fh_dup2(current_fh, &resfh);
  214. /* set reply cache */
  215. fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
  216. &resfh.fh_handle);
  217. if (!created)
  218. status = do_open_permission(rqstp, current_fh, open,
  219. NFSD_MAY_NOP);
  220. out:
  221. fh_put(&resfh);
  222. return status;
  223. }
  224. static __be32
  225. do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
  226. {
  227. __be32 status;
  228. /* Only reclaims from previously confirmed clients are valid */
  229. if ((status = nfs4_check_open_reclaim(&open->op_clientid)))
  230. return status;
  231. /* We don't know the target directory, and therefore can not
  232. * set the change info
  233. */
  234. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  235. /* set replay cache */
  236. fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh,
  237. &current_fh->fh_handle);
  238. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  239. (open->op_iattr.ia_size == 0);
  240. status = do_open_permission(rqstp, current_fh, open,
  241. NFSD_MAY_OWNER_OVERRIDE);
  242. return status;
  243. }
  244. static void
  245. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  246. {
  247. struct nfsd4_sessionid *sid =
  248. (struct nfsd4_sessionid *)session->se_sessionid.data;
  249. clid->cl_boot = sid->clientid.cl_boot;
  250. clid->cl_id = sid->clientid.cl_id;
  251. }
  252. static __be32
  253. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  254. struct nfsd4_open *open)
  255. {
  256. __be32 status;
  257. struct nfsd4_compoundres *resp;
  258. dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n",
  259. (int)open->op_fname.len, open->op_fname.data,
  260. open->op_stateowner);
  261. /* This check required by spec. */
  262. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  263. return nfserr_inval;
  264. if (nfsd4_has_session(cstate))
  265. copy_clientid(&open->op_clientid, cstate->session);
  266. nfs4_lock_state();
  267. /* check seqid for replay. set nfs4_owner */
  268. resp = rqstp->rq_resp;
  269. status = nfsd4_process_open1(&resp->cstate, open);
  270. if (status == nfserr_replay_me) {
  271. struct nfs4_replay *rp = &open->op_stateowner->so_replay;
  272. fh_put(&cstate->current_fh);
  273. fh_copy_shallow(&cstate->current_fh.fh_handle,
  274. &rp->rp_openfh);
  275. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  276. if (status)
  277. dprintk("nfsd4_open: replay failed"
  278. " restoring previous filehandle\n");
  279. else
  280. status = nfserr_replay_me;
  281. }
  282. if (status)
  283. goto out;
  284. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  285. if (status)
  286. goto out;
  287. /* Openowner is now set, so sequence id will get bumped. Now we need
  288. * these checks before we do any creates: */
  289. status = nfserr_grace;
  290. if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  291. goto out;
  292. status = nfserr_no_grace;
  293. if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  294. goto out;
  295. switch (open->op_claim_type) {
  296. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  297. case NFS4_OPEN_CLAIM_NULL:
  298. /*
  299. * (1) set CURRENT_FH to the file being opened,
  300. * creating it if necessary, (2) set open->op_cinfo,
  301. * (3) set open->op_truncate if the file is to be
  302. * truncated after opening, (4) do permission checking.
  303. */
  304. status = do_open_lookup(rqstp, &cstate->current_fh,
  305. open);
  306. if (status)
  307. goto out;
  308. break;
  309. case NFS4_OPEN_CLAIM_PREVIOUS:
  310. open->op_stateowner->so_confirmed = 1;
  311. /*
  312. * The CURRENT_FH is already set to the file being
  313. * opened. (1) set open->op_cinfo, (2) set
  314. * open->op_truncate if the file is to be truncated
  315. * after opening, (3) do permission checking.
  316. */
  317. status = do_open_fhandle(rqstp, &cstate->current_fh,
  318. open);
  319. if (status)
  320. goto out;
  321. break;
  322. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  323. open->op_stateowner->so_confirmed = 1;
  324. dprintk("NFSD: unsupported OPEN claim type %d\n",
  325. open->op_claim_type);
  326. status = nfserr_notsupp;
  327. goto out;
  328. default:
  329. dprintk("NFSD: Invalid OPEN claim type %d\n",
  330. open->op_claim_type);
  331. status = nfserr_inval;
  332. goto out;
  333. }
  334. /*
  335. * nfsd4_process_open2() does the actual opening of the file. If
  336. * successful, it (1) truncates the file if open->op_truncate was
  337. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  338. */
  339. status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
  340. out:
  341. if (open->op_stateowner) {
  342. nfs4_get_stateowner(open->op_stateowner);
  343. cstate->replay_owner = open->op_stateowner;
  344. }
  345. nfs4_unlock_state();
  346. return status;
  347. }
  348. /*
  349. * filehandle-manipulating ops.
  350. */
  351. static __be32
  352. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  353. struct svc_fh **getfh)
  354. {
  355. if (!cstate->current_fh.fh_dentry)
  356. return nfserr_nofilehandle;
  357. *getfh = &cstate->current_fh;
  358. return nfs_ok;
  359. }
  360. static __be32
  361. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  362. struct nfsd4_putfh *putfh)
  363. {
  364. fh_put(&cstate->current_fh);
  365. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  366. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  367. putfh->pf_fhlen);
  368. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  369. }
  370. static __be32
  371. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  372. void *arg)
  373. {
  374. __be32 status;
  375. fh_put(&cstate->current_fh);
  376. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  377. return status;
  378. }
  379. static __be32
  380. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  381. void *arg)
  382. {
  383. if (!cstate->save_fh.fh_dentry)
  384. return nfserr_restorefh;
  385. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  386. return nfs_ok;
  387. }
  388. static __be32
  389. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  390. void *arg)
  391. {
  392. if (!cstate->current_fh.fh_dentry)
  393. return nfserr_nofilehandle;
  394. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  395. return nfs_ok;
  396. }
  397. /*
  398. * misc nfsv4 ops
  399. */
  400. static __be32
  401. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  402. struct nfsd4_access *access)
  403. {
  404. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  405. return nfserr_inval;
  406. access->ac_resp_access = access->ac_req_access;
  407. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  408. &access->ac_supported);
  409. }
  410. static __be32
  411. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  412. struct nfsd4_commit *commit)
  413. {
  414. __be32 status;
  415. u32 *p = (u32 *)commit->co_verf.data;
  416. *p++ = nfssvc_boot.tv_sec;
  417. *p++ = nfssvc_boot.tv_usec;
  418. status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
  419. commit->co_count);
  420. if (status == nfserr_symlink)
  421. status = nfserr_inval;
  422. return status;
  423. }
  424. static __be32
  425. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  426. struct nfsd4_create *create)
  427. {
  428. struct svc_fh resfh;
  429. __be32 status;
  430. dev_t rdev;
  431. fh_init(&resfh, NFS4_FHSIZE);
  432. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
  433. NFSD_MAY_CREATE);
  434. if (status == nfserr_symlink)
  435. status = nfserr_notdir;
  436. if (status)
  437. return status;
  438. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  439. nfsd_attrmask);
  440. if (status)
  441. return status;
  442. switch (create->cr_type) {
  443. case NF4LNK:
  444. /* ugh! we have to null-terminate the linktext, or
  445. * vfs_symlink() will choke. it is always safe to
  446. * null-terminate by brute force, since at worst we
  447. * will overwrite the first byte of the create namelen
  448. * in the XDR buffer, which has already been extracted
  449. * during XDR decode.
  450. */
  451. create->cr_linkname[create->cr_linklen] = 0;
  452. status = nfsd_symlink(rqstp, &cstate->current_fh,
  453. create->cr_name, create->cr_namelen,
  454. create->cr_linkname, create->cr_linklen,
  455. &resfh, &create->cr_iattr);
  456. break;
  457. case NF4BLK:
  458. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  459. if (MAJOR(rdev) != create->cr_specdata1 ||
  460. MINOR(rdev) != create->cr_specdata2)
  461. return nfserr_inval;
  462. status = nfsd_create(rqstp, &cstate->current_fh,
  463. create->cr_name, create->cr_namelen,
  464. &create->cr_iattr, S_IFBLK, rdev, &resfh);
  465. break;
  466. case NF4CHR:
  467. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  468. if (MAJOR(rdev) != create->cr_specdata1 ||
  469. MINOR(rdev) != create->cr_specdata2)
  470. return nfserr_inval;
  471. status = nfsd_create(rqstp, &cstate->current_fh,
  472. create->cr_name, create->cr_namelen,
  473. &create->cr_iattr,S_IFCHR, rdev, &resfh);
  474. break;
  475. case NF4SOCK:
  476. status = nfsd_create(rqstp, &cstate->current_fh,
  477. create->cr_name, create->cr_namelen,
  478. &create->cr_iattr, S_IFSOCK, 0, &resfh);
  479. break;
  480. case NF4FIFO:
  481. status = nfsd_create(rqstp, &cstate->current_fh,
  482. create->cr_name, create->cr_namelen,
  483. &create->cr_iattr, S_IFIFO, 0, &resfh);
  484. break;
  485. case NF4DIR:
  486. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  487. status = nfsd_create(rqstp, &cstate->current_fh,
  488. create->cr_name, create->cr_namelen,
  489. &create->cr_iattr, S_IFDIR, 0, &resfh);
  490. break;
  491. default:
  492. status = nfserr_badtype;
  493. }
  494. if (status)
  495. goto out;
  496. if (create->cr_acl != NULL)
  497. do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
  498. create->cr_bmval);
  499. fh_unlock(&cstate->current_fh);
  500. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  501. fh_dup2(&cstate->current_fh, &resfh);
  502. out:
  503. fh_put(&resfh);
  504. return status;
  505. }
  506. static __be32
  507. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  508. struct nfsd4_getattr *getattr)
  509. {
  510. __be32 status;
  511. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  512. if (status)
  513. return status;
  514. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  515. return nfserr_inval;
  516. getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  517. getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  518. getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  519. getattr->ga_fhp = &cstate->current_fh;
  520. return nfs_ok;
  521. }
  522. static __be32
  523. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  524. struct nfsd4_link *link)
  525. {
  526. __be32 status = nfserr_nofilehandle;
  527. if (!cstate->save_fh.fh_dentry)
  528. return status;
  529. status = nfsd_link(rqstp, &cstate->current_fh,
  530. link->li_name, link->li_namelen, &cstate->save_fh);
  531. if (!status)
  532. set_change_info(&link->li_cinfo, &cstate->current_fh);
  533. return status;
  534. }
  535. static __be32
  536. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  537. void *arg)
  538. {
  539. struct svc_fh tmp_fh;
  540. __be32 ret;
  541. fh_init(&tmp_fh, NFS4_FHSIZE);
  542. ret = exp_pseudoroot(rqstp, &tmp_fh);
  543. if (ret)
  544. return ret;
  545. if (tmp_fh.fh_dentry == cstate->current_fh.fh_dentry) {
  546. fh_put(&tmp_fh);
  547. return nfserr_noent;
  548. }
  549. fh_put(&tmp_fh);
  550. return nfsd_lookup(rqstp, &cstate->current_fh,
  551. "..", 2, &cstate->current_fh);
  552. }
  553. static __be32
  554. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  555. struct nfsd4_lookup *lookup)
  556. {
  557. return nfsd_lookup(rqstp, &cstate->current_fh,
  558. lookup->lo_name, lookup->lo_len,
  559. &cstate->current_fh);
  560. }
  561. static __be32
  562. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  563. struct nfsd4_read *read)
  564. {
  565. __be32 status;
  566. /* no need to check permission - this will be done in nfsd_read() */
  567. read->rd_filp = NULL;
  568. if (read->rd_offset >= OFFSET_MAX)
  569. return nfserr_inval;
  570. nfs4_lock_state();
  571. /* check stateid */
  572. if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid,
  573. RD_STATE, &read->rd_filp))) {
  574. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  575. goto out;
  576. }
  577. if (read->rd_filp)
  578. get_file(read->rd_filp);
  579. status = nfs_ok;
  580. out:
  581. nfs4_unlock_state();
  582. read->rd_rqstp = rqstp;
  583. read->rd_fhp = &cstate->current_fh;
  584. return status;
  585. }
  586. static __be32
  587. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  588. struct nfsd4_readdir *readdir)
  589. {
  590. u64 cookie = readdir->rd_cookie;
  591. static const nfs4_verifier zeroverf;
  592. /* no need to check permission - this will be done in nfsd_readdir() */
  593. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  594. return nfserr_inval;
  595. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  596. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  597. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  598. if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) ||
  599. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  600. return nfserr_bad_cookie;
  601. readdir->rd_rqstp = rqstp;
  602. readdir->rd_fhp = &cstate->current_fh;
  603. return nfs_ok;
  604. }
  605. static __be32
  606. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  607. struct nfsd4_readlink *readlink)
  608. {
  609. readlink->rl_rqstp = rqstp;
  610. readlink->rl_fhp = &cstate->current_fh;
  611. return nfs_ok;
  612. }
  613. static __be32
  614. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  615. struct nfsd4_remove *remove)
  616. {
  617. __be32 status;
  618. if (locks_in_grace())
  619. return nfserr_grace;
  620. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  621. remove->rm_name, remove->rm_namelen);
  622. if (status == nfserr_symlink)
  623. return nfserr_notdir;
  624. if (!status) {
  625. fh_unlock(&cstate->current_fh);
  626. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  627. }
  628. return status;
  629. }
  630. static __be32
  631. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  632. struct nfsd4_rename *rename)
  633. {
  634. __be32 status = nfserr_nofilehandle;
  635. if (!cstate->save_fh.fh_dentry)
  636. return status;
  637. if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
  638. & NFSEXP_NOSUBTREECHECK))
  639. return nfserr_grace;
  640. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  641. rename->rn_snamelen, &cstate->current_fh,
  642. rename->rn_tname, rename->rn_tnamelen);
  643. /* the underlying filesystem returns different error's than required
  644. * by NFSv4. both save_fh and current_fh have been verified.. */
  645. if (status == nfserr_isdir)
  646. status = nfserr_exist;
  647. else if ((status == nfserr_notdir) &&
  648. (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) &&
  649. S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode)))
  650. status = nfserr_exist;
  651. else if (status == nfserr_symlink)
  652. status = nfserr_notdir;
  653. if (!status) {
  654. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  655. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  656. }
  657. return status;
  658. }
  659. static __be32
  660. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  661. struct nfsd4_secinfo *secinfo)
  662. {
  663. struct svc_fh resfh;
  664. struct svc_export *exp;
  665. struct dentry *dentry;
  666. __be32 err;
  667. fh_init(&resfh, NFS4_FHSIZE);
  668. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  669. secinfo->si_name, secinfo->si_namelen,
  670. &exp, &dentry);
  671. if (err)
  672. return err;
  673. if (dentry->d_inode == NULL) {
  674. exp_put(exp);
  675. err = nfserr_noent;
  676. } else
  677. secinfo->si_exp = exp;
  678. dput(dentry);
  679. return err;
  680. }
  681. static __be32
  682. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  683. struct nfsd4_setattr *setattr)
  684. {
  685. __be32 status = nfs_ok;
  686. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  687. nfs4_lock_state();
  688. status = nfs4_preprocess_stateid_op(cstate,
  689. &setattr->sa_stateid, WR_STATE, NULL);
  690. nfs4_unlock_state();
  691. if (status) {
  692. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  693. return status;
  694. }
  695. }
  696. status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt);
  697. if (status)
  698. return status;
  699. status = nfs_ok;
  700. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  701. nfsd_attrmask);
  702. if (status)
  703. goto out;
  704. if (setattr->sa_acl != NULL)
  705. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  706. setattr->sa_acl);
  707. if (status)
  708. goto out;
  709. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  710. 0, (time_t)0);
  711. out:
  712. mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt);
  713. return status;
  714. }
  715. static __be32
  716. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  717. struct nfsd4_write *write)
  718. {
  719. stateid_t *stateid = &write->wr_stateid;
  720. struct file *filp = NULL;
  721. u32 *p;
  722. __be32 status = nfs_ok;
  723. unsigned long cnt;
  724. /* no need to check permission - this will be done in nfsd_write() */
  725. if (write->wr_offset >= OFFSET_MAX)
  726. return nfserr_inval;
  727. nfs4_lock_state();
  728. status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp);
  729. if (filp)
  730. get_file(filp);
  731. nfs4_unlock_state();
  732. if (status) {
  733. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  734. return status;
  735. }
  736. cnt = write->wr_buflen;
  737. write->wr_how_written = write->wr_stable_how;
  738. p = (u32 *)write->wr_verifier.data;
  739. *p++ = nfssvc_boot.tv_sec;
  740. *p++ = nfssvc_boot.tv_usec;
  741. status = nfsd_write(rqstp, &cstate->current_fh, filp,
  742. write->wr_offset, rqstp->rq_vec, write->wr_vlen,
  743. &cnt, &write->wr_how_written);
  744. if (filp)
  745. fput(filp);
  746. write->wr_bytes_written = cnt;
  747. if (status == nfserr_symlink)
  748. status = nfserr_inval;
  749. return status;
  750. }
  751. /* This routine never returns NFS_OK! If there are no other errors, it
  752. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  753. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  754. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  755. */
  756. static __be32
  757. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  758. struct nfsd4_verify *verify)
  759. {
  760. __be32 *buf, *p;
  761. int count;
  762. __be32 status;
  763. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  764. if (status)
  765. return status;
  766. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  767. if (status)
  768. return status;
  769. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  770. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  771. return nfserr_inval;
  772. if (verify->ve_attrlen & 3)
  773. return nfserr_inval;
  774. /* count in words:
  775. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  776. */
  777. count = 4 + (verify->ve_attrlen >> 2);
  778. buf = kmalloc(count << 2, GFP_KERNEL);
  779. if (!buf)
  780. return nfserr_resource;
  781. status = nfsd4_encode_fattr(&cstate->current_fh,
  782. cstate->current_fh.fh_export,
  783. cstate->current_fh.fh_dentry, buf,
  784. &count, verify->ve_bmval,
  785. rqstp, 0);
  786. /* this means that nfsd4_encode_fattr() ran out of space */
  787. if (status == nfserr_resource && count == 0)
  788. status = nfserr_not_same;
  789. if (status)
  790. goto out_kfree;
  791. /* skip bitmap */
  792. p = buf + 1 + ntohl(buf[0]);
  793. status = nfserr_not_same;
  794. if (ntohl(*p++) != verify->ve_attrlen)
  795. goto out_kfree;
  796. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  797. status = nfserr_same;
  798. out_kfree:
  799. kfree(buf);
  800. return status;
  801. }
  802. static __be32
  803. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  804. struct nfsd4_verify *verify)
  805. {
  806. __be32 status;
  807. status = _nfsd4_verify(rqstp, cstate, verify);
  808. return status == nfserr_not_same ? nfs_ok : status;
  809. }
  810. static __be32
  811. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  812. struct nfsd4_verify *verify)
  813. {
  814. __be32 status;
  815. status = _nfsd4_verify(rqstp, cstate, verify);
  816. return status == nfserr_same ? nfs_ok : status;
  817. }
  818. /*
  819. * NULL call.
  820. */
  821. static __be32
  822. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  823. {
  824. return nfs_ok;
  825. }
  826. static inline void nfsd4_increment_op_stats(u32 opnum)
  827. {
  828. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  829. nfsdstats.nfs4_opcount[opnum]++;
  830. }
  831. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  832. void *);
  833. enum nfsd4_op_flags {
  834. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  835. ALLOWED_ON_ABSENT_FS = 2 << 0, /* ops processed on absent fs */
  836. ALLOWED_AS_FIRST_OP = 3 << 0, /* ops reqired first in compound */
  837. };
  838. struct nfsd4_operation {
  839. nfsd4op_func op_func;
  840. u32 op_flags;
  841. char *op_name;
  842. };
  843. static struct nfsd4_operation nfsd4_ops[];
  844. static const char *nfsd4_op_name(unsigned opnum);
  845. /*
  846. * This is a replay of a compound for which no cache entry pages
  847. * were used. Encode the sequence operation, and if cachethis is FALSE
  848. * encode the uncache rep error on the next operation.
  849. */
  850. static __be32
  851. nfsd4_enc_uncached_replay(struct nfsd4_compoundargs *args,
  852. struct nfsd4_compoundres *resp)
  853. {
  854. struct nfsd4_op *op;
  855. dprintk("--> %s resp->opcnt %d ce_cachethis %u \n", __func__,
  856. resp->opcnt, resp->cstate.slot->sl_cache_entry.ce_cachethis);
  857. /* Encode the replayed sequence operation */
  858. BUG_ON(resp->opcnt != 1);
  859. op = &args->ops[resp->opcnt - 1];
  860. nfsd4_encode_operation(resp, op);
  861. /*return nfserr_retry_uncached_rep in next operation. */
  862. if (resp->cstate.slot->sl_cache_entry.ce_cachethis == 0) {
  863. op = &args->ops[resp->opcnt++];
  864. op->status = nfserr_retry_uncached_rep;
  865. nfsd4_encode_operation(resp, op);
  866. }
  867. return op->status;
  868. }
  869. /*
  870. * Enforce NFSv4.1 COMPOUND ordering rules.
  871. *
  872. * TODO:
  873. * - enforce NFS4ERR_NOT_ONLY_OP,
  874. * - DESTROY_SESSION MUST be the final operation in the COMPOUND request.
  875. */
  876. static bool nfs41_op_ordering_ok(struct nfsd4_compoundargs *args)
  877. {
  878. if (args->minorversion && args->opcnt > 0) {
  879. struct nfsd4_op *op = &args->ops[0];
  880. return (op->status == nfserr_op_illegal) ||
  881. (nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP);
  882. }
  883. return true;
  884. }
  885. /*
  886. * COMPOUND call.
  887. */
  888. static __be32
  889. nfsd4_proc_compound(struct svc_rqst *rqstp,
  890. struct nfsd4_compoundargs *args,
  891. struct nfsd4_compoundres *resp)
  892. {
  893. struct nfsd4_op *op;
  894. struct nfsd4_operation *opdesc;
  895. struct nfsd4_compound_state *cstate = &resp->cstate;
  896. int slack_bytes;
  897. __be32 status;
  898. resp->xbuf = &rqstp->rq_res;
  899. resp->p = rqstp->rq_res.head[0].iov_base +
  900. rqstp->rq_res.head[0].iov_len;
  901. resp->tagp = resp->p;
  902. /* reserve space for: taglen, tag, and opcnt */
  903. resp->p += 2 + XDR_QUADLEN(args->taglen);
  904. resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
  905. resp->taglen = args->taglen;
  906. resp->tag = args->tag;
  907. resp->opcnt = 0;
  908. resp->rqstp = rqstp;
  909. resp->cstate.minorversion = args->minorversion;
  910. resp->cstate.replay_owner = NULL;
  911. fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
  912. fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
  913. /* Use the deferral mechanism only for NFSv4.0 compounds */
  914. rqstp->rq_usedeferral = (args->minorversion == 0);
  915. /*
  916. * According to RFC3010, this takes precedence over all other errors.
  917. */
  918. status = nfserr_minor_vers_mismatch;
  919. if (args->minorversion > nfsd_supported_minorversion)
  920. goto out;
  921. if (!nfs41_op_ordering_ok(args)) {
  922. op = &args->ops[0];
  923. op->status = nfserr_sequence_pos;
  924. goto encode_op;
  925. }
  926. status = nfs_ok;
  927. while (!status && resp->opcnt < args->opcnt) {
  928. op = &args->ops[resp->opcnt++];
  929. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  930. resp->opcnt, args->opcnt, op->opnum,
  931. nfsd4_op_name(op->opnum));
  932. /*
  933. * The XDR decode routines may have pre-set op->status;
  934. * for example, if there is a miscellaneous XDR error
  935. * it will be set to nfserr_bad_xdr.
  936. */
  937. if (op->status)
  938. goto encode_op;
  939. /* We must be able to encode a successful response to
  940. * this operation, with enough room left over to encode a
  941. * failed response to the next operation. If we don't
  942. * have enough room, fail with ERR_RESOURCE.
  943. */
  944. slack_bytes = (char *)resp->end - (char *)resp->p;
  945. if (slack_bytes < COMPOUND_SLACK_SPACE
  946. + COMPOUND_ERR_SLACK_SPACE) {
  947. BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
  948. op->status = nfserr_resource;
  949. goto encode_op;
  950. }
  951. opdesc = &nfsd4_ops[op->opnum];
  952. if (!cstate->current_fh.fh_dentry) {
  953. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  954. op->status = nfserr_nofilehandle;
  955. goto encode_op;
  956. }
  957. } else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
  958. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  959. op->status = nfserr_moved;
  960. goto encode_op;
  961. }
  962. if (opdesc->op_func)
  963. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  964. else
  965. BUG_ON(op->status == nfs_ok);
  966. encode_op:
  967. /* Only from SEQUENCE */
  968. if (resp->cstate.status == nfserr_replay_cache) {
  969. dprintk("%s NFS4.1 replay from cache\n", __func__);
  970. if (nfsd4_not_cached(resp))
  971. status = nfsd4_enc_uncached_replay(args, resp);
  972. else
  973. status = op->status;
  974. goto out;
  975. }
  976. if (op->status == nfserr_replay_me) {
  977. op->replay = &cstate->replay_owner->so_replay;
  978. nfsd4_encode_replay(resp, op);
  979. status = op->status = op->replay->rp_status;
  980. } else {
  981. nfsd4_encode_operation(resp, op);
  982. status = op->status;
  983. }
  984. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  985. args->ops, args->opcnt, resp->opcnt, op->opnum,
  986. be32_to_cpu(status));
  987. if (cstate->replay_owner) {
  988. nfs4_put_stateowner(cstate->replay_owner);
  989. cstate->replay_owner = NULL;
  990. }
  991. /* XXX Ugh, we need to get rid of this kind of special case: */
  992. if (op->opnum == OP_READ && op->u.read.rd_filp)
  993. fput(op->u.read.rd_filp);
  994. nfsd4_increment_op_stats(op->opnum);
  995. }
  996. if (!rqstp->rq_usedeferral && status == nfserr_dropit) {
  997. dprintk("%s Dropit - send NFS4ERR_DELAY\n", __func__);
  998. status = nfserr_jukebox;
  999. }
  1000. resp->cstate.status = status;
  1001. fh_put(&resp->cstate.current_fh);
  1002. fh_put(&resp->cstate.save_fh);
  1003. BUG_ON(resp->cstate.replay_owner);
  1004. out:
  1005. nfsd4_release_compoundargs(args);
  1006. /* Reset deferral mechanism for RPC deferrals */
  1007. rqstp->rq_usedeferral = 1;
  1008. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1009. return status;
  1010. }
  1011. static struct nfsd4_operation nfsd4_ops[] = {
  1012. [OP_ACCESS] = {
  1013. .op_func = (nfsd4op_func)nfsd4_access,
  1014. .op_name = "OP_ACCESS",
  1015. },
  1016. [OP_CLOSE] = {
  1017. .op_func = (nfsd4op_func)nfsd4_close,
  1018. .op_name = "OP_CLOSE",
  1019. },
  1020. [OP_COMMIT] = {
  1021. .op_func = (nfsd4op_func)nfsd4_commit,
  1022. .op_name = "OP_COMMIT",
  1023. },
  1024. [OP_CREATE] = {
  1025. .op_func = (nfsd4op_func)nfsd4_create,
  1026. .op_name = "OP_CREATE",
  1027. },
  1028. [OP_DELEGRETURN] = {
  1029. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1030. .op_name = "OP_DELEGRETURN",
  1031. },
  1032. [OP_GETATTR] = {
  1033. .op_func = (nfsd4op_func)nfsd4_getattr,
  1034. .op_flags = ALLOWED_ON_ABSENT_FS,
  1035. .op_name = "OP_GETATTR",
  1036. },
  1037. [OP_GETFH] = {
  1038. .op_func = (nfsd4op_func)nfsd4_getfh,
  1039. .op_name = "OP_GETFH",
  1040. },
  1041. [OP_LINK] = {
  1042. .op_func = (nfsd4op_func)nfsd4_link,
  1043. .op_name = "OP_LINK",
  1044. },
  1045. [OP_LOCK] = {
  1046. .op_func = (nfsd4op_func)nfsd4_lock,
  1047. .op_name = "OP_LOCK",
  1048. },
  1049. [OP_LOCKT] = {
  1050. .op_func = (nfsd4op_func)nfsd4_lockt,
  1051. .op_name = "OP_LOCKT",
  1052. },
  1053. [OP_LOCKU] = {
  1054. .op_func = (nfsd4op_func)nfsd4_locku,
  1055. .op_name = "OP_LOCKU",
  1056. },
  1057. [OP_LOOKUP] = {
  1058. .op_func = (nfsd4op_func)nfsd4_lookup,
  1059. .op_name = "OP_LOOKUP",
  1060. },
  1061. [OP_LOOKUPP] = {
  1062. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1063. .op_name = "OP_LOOKUPP",
  1064. },
  1065. [OP_NVERIFY] = {
  1066. .op_func = (nfsd4op_func)nfsd4_nverify,
  1067. .op_name = "OP_NVERIFY",
  1068. },
  1069. [OP_OPEN] = {
  1070. .op_func = (nfsd4op_func)nfsd4_open,
  1071. .op_name = "OP_OPEN",
  1072. },
  1073. [OP_OPEN_CONFIRM] = {
  1074. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1075. .op_name = "OP_OPEN_CONFIRM",
  1076. },
  1077. [OP_OPEN_DOWNGRADE] = {
  1078. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1079. .op_name = "OP_OPEN_DOWNGRADE",
  1080. },
  1081. [OP_PUTFH] = {
  1082. .op_func = (nfsd4op_func)nfsd4_putfh,
  1083. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1084. .op_name = "OP_PUTFH",
  1085. },
  1086. [OP_PUTPUBFH] = {
  1087. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1088. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1089. .op_name = "OP_PUTPUBFH",
  1090. },
  1091. [OP_PUTROOTFH] = {
  1092. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1093. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1094. .op_name = "OP_PUTROOTFH",
  1095. },
  1096. [OP_READ] = {
  1097. .op_func = (nfsd4op_func)nfsd4_read,
  1098. .op_name = "OP_READ",
  1099. },
  1100. [OP_READDIR] = {
  1101. .op_func = (nfsd4op_func)nfsd4_readdir,
  1102. .op_name = "OP_READDIR",
  1103. },
  1104. [OP_READLINK] = {
  1105. .op_func = (nfsd4op_func)nfsd4_readlink,
  1106. .op_name = "OP_READLINK",
  1107. },
  1108. [OP_REMOVE] = {
  1109. .op_func = (nfsd4op_func)nfsd4_remove,
  1110. .op_name = "OP_REMOVE",
  1111. },
  1112. [OP_RENAME] = {
  1113. .op_name = "OP_RENAME",
  1114. .op_func = (nfsd4op_func)nfsd4_rename,
  1115. },
  1116. [OP_RENEW] = {
  1117. .op_func = (nfsd4op_func)nfsd4_renew,
  1118. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1119. .op_name = "OP_RENEW",
  1120. },
  1121. [OP_RESTOREFH] = {
  1122. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1123. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1124. .op_name = "OP_RESTOREFH",
  1125. },
  1126. [OP_SAVEFH] = {
  1127. .op_func = (nfsd4op_func)nfsd4_savefh,
  1128. .op_name = "OP_SAVEFH",
  1129. },
  1130. [OP_SECINFO] = {
  1131. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1132. .op_name = "OP_SECINFO",
  1133. },
  1134. [OP_SETATTR] = {
  1135. .op_func = (nfsd4op_func)nfsd4_setattr,
  1136. .op_name = "OP_SETATTR",
  1137. },
  1138. [OP_SETCLIENTID] = {
  1139. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1140. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1141. .op_name = "OP_SETCLIENTID",
  1142. },
  1143. [OP_SETCLIENTID_CONFIRM] = {
  1144. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1145. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1146. .op_name = "OP_SETCLIENTID_CONFIRM",
  1147. },
  1148. [OP_VERIFY] = {
  1149. .op_func = (nfsd4op_func)nfsd4_verify,
  1150. .op_name = "OP_VERIFY",
  1151. },
  1152. [OP_WRITE] = {
  1153. .op_func = (nfsd4op_func)nfsd4_write,
  1154. .op_name = "OP_WRITE",
  1155. },
  1156. [OP_RELEASE_LOCKOWNER] = {
  1157. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1158. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS,
  1159. .op_name = "OP_RELEASE_LOCKOWNER",
  1160. },
  1161. /* NFSv4.1 operations */
  1162. [OP_EXCHANGE_ID] = {
  1163. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1164. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1165. .op_name = "OP_EXCHANGE_ID",
  1166. },
  1167. [OP_CREATE_SESSION] = {
  1168. .op_func = (nfsd4op_func)nfsd4_create_session,
  1169. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1170. .op_name = "OP_CREATE_SESSION",
  1171. },
  1172. [OP_DESTROY_SESSION] = {
  1173. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1174. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1175. .op_name = "OP_DESTROY_SESSION",
  1176. },
  1177. [OP_SEQUENCE] = {
  1178. .op_func = (nfsd4op_func)nfsd4_sequence,
  1179. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1180. .op_name = "OP_SEQUENCE",
  1181. },
  1182. };
  1183. static const char *nfsd4_op_name(unsigned opnum)
  1184. {
  1185. if (opnum < ARRAY_SIZE(nfsd4_ops))
  1186. return nfsd4_ops[opnum].op_name;
  1187. return "unknown_operation";
  1188. }
  1189. #define nfsd4_voidres nfsd4_voidargs
  1190. struct nfsd4_voidargs { int dummy; };
  1191. /*
  1192. * TODO: At the present time, the NFSv4 server does not do XID caching
  1193. * of requests. Implementing XID caching would not be a serious problem,
  1194. * although it would require a mild change in interfaces since one
  1195. * doesn't know whether an NFSv4 request is idempotent until after the
  1196. * XDR decode. However, XID caching totally confuses pynfs (Peter
  1197. * Astrand's regression testsuite for NFSv4 servers), which reuses
  1198. * XID's liberally, so I've left it unimplemented until pynfs generates
  1199. * better XID's.
  1200. */
  1201. static struct svc_procedure nfsd_procedures4[2] = {
  1202. [NFSPROC4_NULL] = {
  1203. .pc_func = (svc_procfunc) nfsd4_proc_null,
  1204. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  1205. .pc_argsize = sizeof(struct nfsd4_voidargs),
  1206. .pc_ressize = sizeof(struct nfsd4_voidres),
  1207. .pc_cachetype = RC_NOCACHE,
  1208. .pc_xdrressize = 1,
  1209. },
  1210. [NFSPROC4_COMPOUND] = {
  1211. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  1212. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  1213. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  1214. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  1215. .pc_ressize = sizeof(struct nfsd4_compoundres),
  1216. .pc_cachetype = RC_NOCACHE,
  1217. .pc_xdrressize = NFSD_BUFSIZE/4,
  1218. },
  1219. };
  1220. struct svc_version nfsd_version4 = {
  1221. .vs_vers = 4,
  1222. .vs_nproc = 2,
  1223. .vs_proc = nfsd_procedures4,
  1224. .vs_dispatch = nfsd_dispatch,
  1225. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  1226. };
  1227. /*
  1228. * Local variables:
  1229. * c-basic-offset: 8
  1230. * End:
  1231. */