nfs4proc.c 34 KB

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