nfs4proc.c 37 KB

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