nfs4proc.c 35 KB

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