nfs4proc.c 37 KB

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