nfs4proc.c 37 KB

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