nfs4proc.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. /*
  2. * Server-side procedures for NFSv4.
  3. *
  4. * Copyright (c) 2002 The Regents of the University of Michigan.
  5. * All rights reserved.
  6. *
  7. * Kendrick Smith <kmsmith@umich.edu>
  8. * Andy Adamson <andros@umich.edu>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <linux/file.h>
  36. #include <linux/falloc.h>
  37. #include <linux/slab.h>
  38. #include "idmap.h"
  39. #include "cache.h"
  40. #include "xdr4.h"
  41. #include "vfs.h"
  42. #include "current_stateid.h"
  43. #include "netns.h"
  44. #include "acl.h"
  45. #include "pnfs.h"
  46. #include "trace.h"
  47. #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  48. #include <linux/security.h>
  49. static inline void
  50. nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
  51. {
  52. struct inode *inode = d_inode(resfh->fh_dentry);
  53. int status;
  54. mutex_lock(&inode->i_mutex);
  55. status = security_inode_setsecctx(resfh->fh_dentry,
  56. label->data, label->len);
  57. mutex_unlock(&inode->i_mutex);
  58. if (status)
  59. /*
  60. * XXX: We should really fail the whole open, but we may
  61. * already have created a new file, so it may be too
  62. * late. For now this seems the least of evils:
  63. */
  64. bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  65. return;
  66. }
  67. #else
  68. static inline void
  69. nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
  70. { }
  71. #endif
  72. #define NFSDDBG_FACILITY NFSDDBG_PROC
  73. static u32 nfsd_attrmask[] = {
  74. NFSD_WRITEABLE_ATTRS_WORD0,
  75. NFSD_WRITEABLE_ATTRS_WORD1,
  76. NFSD_WRITEABLE_ATTRS_WORD2
  77. };
  78. static u32 nfsd41_ex_attrmask[] = {
  79. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  80. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  81. NFSD_SUPPATTR_EXCLCREAT_WORD2
  82. };
  83. static __be32
  84. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  85. u32 *bmval, u32 *writable)
  86. {
  87. struct dentry *dentry = cstate->current_fh.fh_dentry;
  88. /*
  89. * Check about attributes are supported by the NFSv4 server or not.
  90. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
  91. */
  92. if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
  93. (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
  94. (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
  95. return nfserr_attrnotsupp;
  96. /*
  97. * Check FATTR4_WORD0_ACL can be supported
  98. * in current environment or not.
  99. */
  100. if (bmval[0] & FATTR4_WORD0_ACL) {
  101. if (!IS_POSIXACL(d_inode(dentry)))
  102. return nfserr_attrnotsupp;
  103. }
  104. /*
  105. * According to spec, read-only attributes return ERR_INVAL.
  106. */
  107. if (writable) {
  108. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  109. (bmval[2] & ~writable[2]))
  110. return nfserr_inval;
  111. }
  112. return nfs_ok;
  113. }
  114. static __be32
  115. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  116. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  117. {
  118. __be32 status = nfs_ok;
  119. if (open->op_create == NFS4_OPEN_CREATE) {
  120. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  121. || open->op_createmode == NFS4_CREATE_GUARDED)
  122. status = check_attr_support(rqstp, cstate,
  123. open->op_bmval, nfsd_attrmask);
  124. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  125. status = check_attr_support(rqstp, cstate,
  126. open->op_bmval, nfsd41_ex_attrmask);
  127. }
  128. return status;
  129. }
  130. static int
  131. is_create_with_attrs(struct nfsd4_open *open)
  132. {
  133. return open->op_create == NFS4_OPEN_CREATE
  134. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  135. || open->op_createmode == NFS4_CREATE_GUARDED
  136. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  137. }
  138. /*
  139. * if error occurs when setting the acl, just clear the acl bit
  140. * in the returned attr bitmap.
  141. */
  142. static void
  143. do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
  144. struct nfs4_acl *acl, u32 *bmval)
  145. {
  146. __be32 status;
  147. status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
  148. if (status)
  149. /*
  150. * We should probably fail the whole open at this point,
  151. * but we've already created the file, so it's too late;
  152. * So this seems the least of evils:
  153. */
  154. bmval[0] &= ~FATTR4_WORD0_ACL;
  155. }
  156. static inline void
  157. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  158. {
  159. fh_put(dst);
  160. dget(src->fh_dentry);
  161. if (src->fh_export)
  162. exp_get(src->fh_export);
  163. *dst = *src;
  164. }
  165. static __be32
  166. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  167. {
  168. __be32 status;
  169. if (open->op_truncate &&
  170. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  171. return nfserr_inval;
  172. accmode |= NFSD_MAY_READ_IF_EXEC;
  173. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  174. accmode |= NFSD_MAY_READ;
  175. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  176. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  177. if (open->op_share_deny & NFS4_SHARE_DENY_READ)
  178. accmode |= NFSD_MAY_WRITE;
  179. status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
  180. return status;
  181. }
  182. static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
  183. {
  184. umode_t mode = d_inode(fh->fh_dentry)->i_mode;
  185. if (S_ISREG(mode))
  186. return nfs_ok;
  187. if (S_ISDIR(mode))
  188. return nfserr_isdir;
  189. /*
  190. * Using err_symlink as our catch-all case may look odd; but
  191. * there's no other obvious error for this case in 4.0, and we
  192. * happen to know that it will cause the linux v4 client to do
  193. * the right thing on attempts to open something other than a
  194. * regular file.
  195. */
  196. return nfserr_symlink;
  197. }
  198. static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
  199. {
  200. if (nfsd4_has_session(cstate))
  201. return;
  202. fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
  203. &resfh->fh_handle);
  204. }
  205. static __be32
  206. do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
  207. {
  208. struct svc_fh *current_fh = &cstate->current_fh;
  209. int accmode;
  210. __be32 status;
  211. *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
  212. if (!*resfh)
  213. return nfserr_jukebox;
  214. fh_init(*resfh, NFS4_FHSIZE);
  215. open->op_truncate = 0;
  216. if (open->op_create) {
  217. /* FIXME: check session persistence and pnfs flags.
  218. * The nfsv4.1 spec requires the following semantics:
  219. *
  220. * Persistent | pNFS | Server REQUIRED | Client Allowed
  221. * Reply Cache | server | |
  222. * -------------+--------+-----------------+--------------------
  223. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  224. * | | | (SHOULD)
  225. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  226. * | | | (SHOULD NOT)
  227. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  228. * yes | no | GUARDED4 | GUARDED4
  229. * yes | yes | GUARDED4 | GUARDED4
  230. */
  231. /*
  232. * Note: create modes (UNCHECKED,GUARDED...) are the same
  233. * in NFSv4 as in v3 except EXCLUSIVE4_1.
  234. */
  235. status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
  236. open->op_fname.len, &open->op_iattr,
  237. *resfh, open->op_createmode,
  238. (u32 *)open->op_verf.data,
  239. &open->op_truncate, &open->op_created);
  240. if (!status && open->op_label.len)
  241. nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval);
  242. /*
  243. * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
  244. * use the returned bitmask to indicate which attributes
  245. * we used to store the verifier:
  246. */
  247. if (nfsd_create_is_exclusive(open->op_createmode) && status == 0)
  248. open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
  249. FATTR4_WORD1_TIME_MODIFY);
  250. } else
  251. /*
  252. * Note this may exit with the parent still locked.
  253. * We will hold the lock until nfsd4_open's final
  254. * lookup, to prevent renames or unlinks until we've had
  255. * a chance to an acquire a delegation if appropriate.
  256. */
  257. status = nfsd_lookup(rqstp, current_fh,
  258. open->op_fname.data, open->op_fname.len, *resfh);
  259. if (status)
  260. goto out;
  261. status = nfsd_check_obj_isreg(*resfh);
  262. if (status)
  263. goto out;
  264. if (is_create_with_attrs(open) && open->op_acl != NULL)
  265. do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval);
  266. nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
  267. accmode = NFSD_MAY_NOP;
  268. if (open->op_created ||
  269. open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
  270. accmode |= NFSD_MAY_OWNER_OVERRIDE;
  271. status = do_open_permission(rqstp, *resfh, open, accmode);
  272. set_change_info(&open->op_cinfo, current_fh);
  273. out:
  274. return status;
  275. }
  276. static __be32
  277. do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  278. {
  279. struct svc_fh *current_fh = &cstate->current_fh;
  280. __be32 status;
  281. int accmode = 0;
  282. /* We don't know the target directory, and therefore can not
  283. * set the change info
  284. */
  285. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  286. nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
  287. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  288. (open->op_iattr.ia_size == 0);
  289. /*
  290. * In the delegation case, the client is telling us about an
  291. * open that it *already* performed locally, some time ago. We
  292. * should let it succeed now if possible.
  293. *
  294. * In the case of a CLAIM_FH open, on the other hand, the client
  295. * may be counting on us to enforce permissions (the Linux 4.1
  296. * client uses this for normal opens, for example).
  297. */
  298. if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
  299. accmode = NFSD_MAY_OWNER_OVERRIDE;
  300. status = do_open_permission(rqstp, current_fh, open, accmode);
  301. return status;
  302. }
  303. static void
  304. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  305. {
  306. struct nfsd4_sessionid *sid =
  307. (struct nfsd4_sessionid *)session->se_sessionid.data;
  308. clid->cl_boot = sid->clientid.cl_boot;
  309. clid->cl_id = sid->clientid.cl_id;
  310. }
  311. static __be32
  312. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  313. struct nfsd4_open *open)
  314. {
  315. __be32 status;
  316. struct svc_fh *resfh = NULL;
  317. struct net *net = SVC_NET(rqstp);
  318. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  319. dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
  320. (int)open->op_fname.len, open->op_fname.data,
  321. open->op_openowner);
  322. /* This check required by spec. */
  323. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  324. return nfserr_inval;
  325. open->op_created = 0;
  326. /*
  327. * RFC5661 18.51.3
  328. * Before RECLAIM_COMPLETE done, server should deny new lock
  329. */
  330. if (nfsd4_has_session(cstate) &&
  331. !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
  332. &cstate->session->se_client->cl_flags) &&
  333. open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  334. return nfserr_grace;
  335. if (nfsd4_has_session(cstate))
  336. copy_clientid(&open->op_clientid, cstate->session);
  337. /* check seqid for replay. set nfs4_owner */
  338. status = nfsd4_process_open1(cstate, open, nn);
  339. if (status == nfserr_replay_me) {
  340. struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
  341. fh_put(&cstate->current_fh);
  342. fh_copy_shallow(&cstate->current_fh.fh_handle,
  343. &rp->rp_openfh);
  344. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  345. if (status)
  346. dprintk("nfsd4_open: replay failed"
  347. " restoring previous filehandle\n");
  348. else
  349. status = nfserr_replay_me;
  350. }
  351. if (status)
  352. goto out;
  353. if (open->op_xdr_error) {
  354. status = open->op_xdr_error;
  355. goto out;
  356. }
  357. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  358. if (status)
  359. goto out;
  360. /* Openowner is now set, so sequence id will get bumped. Now we need
  361. * these checks before we do any creates: */
  362. status = nfserr_grace;
  363. if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  364. goto out;
  365. status = nfserr_no_grace;
  366. if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  367. goto out;
  368. switch (open->op_claim_type) {
  369. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  370. case NFS4_OPEN_CLAIM_NULL:
  371. status = do_open_lookup(rqstp, cstate, open, &resfh);
  372. if (status)
  373. goto out;
  374. break;
  375. case NFS4_OPEN_CLAIM_PREVIOUS:
  376. status = nfs4_check_open_reclaim(&open->op_clientid,
  377. cstate, nn);
  378. if (status)
  379. goto out;
  380. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  381. case NFS4_OPEN_CLAIM_FH:
  382. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  383. status = do_open_fhandle(rqstp, cstate, open);
  384. if (status)
  385. goto out;
  386. resfh = &cstate->current_fh;
  387. break;
  388. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  389. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  390. dprintk("NFSD: unsupported OPEN claim type %d\n",
  391. open->op_claim_type);
  392. status = nfserr_notsupp;
  393. goto out;
  394. default:
  395. dprintk("NFSD: Invalid OPEN claim type %d\n",
  396. open->op_claim_type);
  397. status = nfserr_inval;
  398. goto out;
  399. }
  400. /*
  401. * nfsd4_process_open2() does the actual opening of the file. If
  402. * successful, it (1) truncates the file if open->op_truncate was
  403. * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
  404. */
  405. status = nfsd4_process_open2(rqstp, resfh, open);
  406. WARN(status && open->op_created,
  407. "nfsd4_process_open2 failed to open newly-created file! status=%u\n",
  408. be32_to_cpu(status));
  409. out:
  410. if (resfh && resfh != &cstate->current_fh) {
  411. fh_dup2(&cstate->current_fh, resfh);
  412. fh_put(resfh);
  413. kfree(resfh);
  414. }
  415. nfsd4_cleanup_open_state(cstate, open);
  416. nfsd4_bump_seqid(cstate, status);
  417. return status;
  418. }
  419. /*
  420. * OPEN is the only seqid-mutating operation whose decoding can fail
  421. * with a seqid-mutating error (specifically, decoding of user names in
  422. * the attributes). Therefore we have to do some processing to look up
  423. * the stateowner so that we can bump the seqid.
  424. */
  425. static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
  426. {
  427. struct nfsd4_open *open = (struct nfsd4_open *)&op->u;
  428. if (!seqid_mutating_err(ntohl(op->status)))
  429. return op->status;
  430. if (nfsd4_has_session(cstate))
  431. return op->status;
  432. open->op_xdr_error = op->status;
  433. return nfsd4_open(rqstp, cstate, open);
  434. }
  435. /*
  436. * filehandle-manipulating ops.
  437. */
  438. static __be32
  439. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  440. struct svc_fh **getfh)
  441. {
  442. if (!cstate->current_fh.fh_dentry)
  443. return nfserr_nofilehandle;
  444. *getfh = &cstate->current_fh;
  445. return nfs_ok;
  446. }
  447. static __be32
  448. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  449. struct nfsd4_putfh *putfh)
  450. {
  451. fh_put(&cstate->current_fh);
  452. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  453. memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
  454. putfh->pf_fhlen);
  455. return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
  456. }
  457. static __be32
  458. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  459. void *arg)
  460. {
  461. __be32 status;
  462. fh_put(&cstate->current_fh);
  463. status = exp_pseudoroot(rqstp, &cstate->current_fh);
  464. return status;
  465. }
  466. static __be32
  467. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  468. void *arg)
  469. {
  470. if (!cstate->save_fh.fh_dentry)
  471. return nfserr_restorefh;
  472. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  473. if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
  474. memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
  475. SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
  476. }
  477. return nfs_ok;
  478. }
  479. static __be32
  480. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  481. void *arg)
  482. {
  483. if (!cstate->current_fh.fh_dentry)
  484. return nfserr_nofilehandle;
  485. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  486. if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
  487. memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
  488. SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
  489. }
  490. return nfs_ok;
  491. }
  492. /*
  493. * misc nfsv4 ops
  494. */
  495. static __be32
  496. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  497. struct nfsd4_access *access)
  498. {
  499. if (access->ac_req_access & ~NFS3_ACCESS_FULL)
  500. return nfserr_inval;
  501. access->ac_resp_access = access->ac_req_access;
  502. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  503. &access->ac_supported);
  504. }
  505. static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
  506. {
  507. __be32 verf[2];
  508. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  509. /*
  510. * This is opaque to client, so no need to byte-swap. Use
  511. * __force to keep sparse happy
  512. */
  513. verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec;
  514. verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec;
  515. memcpy(verifier->data, verf, sizeof(verifier->data));
  516. }
  517. static __be32
  518. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  519. struct nfsd4_commit *commit)
  520. {
  521. gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp));
  522. return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
  523. commit->co_count);
  524. }
  525. static __be32
  526. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  527. struct nfsd4_create *create)
  528. {
  529. struct svc_fh resfh;
  530. __be32 status;
  531. dev_t rdev;
  532. fh_init(&resfh, NFS4_FHSIZE);
  533. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
  534. NFSD_MAY_CREATE);
  535. if (status)
  536. return status;
  537. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  538. nfsd_attrmask);
  539. if (status)
  540. return status;
  541. switch (create->cr_type) {
  542. case NF4LNK:
  543. status = nfsd_symlink(rqstp, &cstate->current_fh,
  544. create->cr_name, create->cr_namelen,
  545. create->cr_data, &resfh);
  546. break;
  547. case NF4BLK:
  548. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  549. if (MAJOR(rdev) != create->cr_specdata1 ||
  550. MINOR(rdev) != create->cr_specdata2)
  551. return nfserr_inval;
  552. status = nfsd_create(rqstp, &cstate->current_fh,
  553. create->cr_name, create->cr_namelen,
  554. &create->cr_iattr, S_IFBLK, rdev, &resfh);
  555. break;
  556. case NF4CHR:
  557. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  558. if (MAJOR(rdev) != create->cr_specdata1 ||
  559. MINOR(rdev) != create->cr_specdata2)
  560. return nfserr_inval;
  561. status = nfsd_create(rqstp, &cstate->current_fh,
  562. create->cr_name, create->cr_namelen,
  563. &create->cr_iattr,S_IFCHR, rdev, &resfh);
  564. break;
  565. case NF4SOCK:
  566. status = nfsd_create(rqstp, &cstate->current_fh,
  567. create->cr_name, create->cr_namelen,
  568. &create->cr_iattr, S_IFSOCK, 0, &resfh);
  569. break;
  570. case NF4FIFO:
  571. status = nfsd_create(rqstp, &cstate->current_fh,
  572. create->cr_name, create->cr_namelen,
  573. &create->cr_iattr, S_IFIFO, 0, &resfh);
  574. break;
  575. case NF4DIR:
  576. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  577. status = nfsd_create(rqstp, &cstate->current_fh,
  578. create->cr_name, create->cr_namelen,
  579. &create->cr_iattr, S_IFDIR, 0, &resfh);
  580. break;
  581. default:
  582. status = nfserr_badtype;
  583. }
  584. if (status)
  585. goto out;
  586. if (create->cr_label.len)
  587. nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
  588. if (create->cr_acl != NULL)
  589. do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
  590. create->cr_bmval);
  591. fh_unlock(&cstate->current_fh);
  592. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  593. fh_dup2(&cstate->current_fh, &resfh);
  594. out:
  595. fh_put(&resfh);
  596. return status;
  597. }
  598. static __be32
  599. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  600. struct nfsd4_getattr *getattr)
  601. {
  602. __be32 status;
  603. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  604. if (status)
  605. return status;
  606. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  607. return nfserr_inval;
  608. getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  609. getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  610. getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  611. getattr->ga_fhp = &cstate->current_fh;
  612. return nfs_ok;
  613. }
  614. static __be32
  615. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  616. struct nfsd4_link *link)
  617. {
  618. __be32 status = nfserr_nofilehandle;
  619. if (!cstate->save_fh.fh_dentry)
  620. return status;
  621. status = nfsd_link(rqstp, &cstate->current_fh,
  622. link->li_name, link->li_namelen, &cstate->save_fh);
  623. if (!status)
  624. set_change_info(&link->li_cinfo, &cstate->current_fh);
  625. return status;
  626. }
  627. static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
  628. {
  629. struct svc_fh tmp_fh;
  630. __be32 ret;
  631. fh_init(&tmp_fh, NFS4_FHSIZE);
  632. ret = exp_pseudoroot(rqstp, &tmp_fh);
  633. if (ret)
  634. return ret;
  635. if (tmp_fh.fh_dentry == fh->fh_dentry) {
  636. fh_put(&tmp_fh);
  637. return nfserr_noent;
  638. }
  639. fh_put(&tmp_fh);
  640. return nfsd_lookup(rqstp, fh, "..", 2, fh);
  641. }
  642. static __be32
  643. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  644. void *arg)
  645. {
  646. return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  647. }
  648. static __be32
  649. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  650. struct nfsd4_lookup *lookup)
  651. {
  652. return nfsd_lookup(rqstp, &cstate->current_fh,
  653. lookup->lo_name, lookup->lo_len,
  654. &cstate->current_fh);
  655. }
  656. static __be32
  657. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  658. struct nfsd4_read *read)
  659. {
  660. __be32 status;
  661. read->rd_filp = NULL;
  662. if (read->rd_offset >= OFFSET_MAX)
  663. return nfserr_inval;
  664. /*
  665. * If we do a zero copy read, then a client will see read data
  666. * that reflects the state of the file *after* performing the
  667. * following compound.
  668. *
  669. * To ensure proper ordering, we therefore turn off zero copy if
  670. * the client wants us to do more in this compound:
  671. */
  672. if (!nfsd4_last_compound_op(rqstp))
  673. clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
  674. /* check stateid */
  675. status = nfs4_preprocess_stateid_op(rqstp, cstate, &read->rd_stateid,
  676. RD_STATE, &read->rd_filp, &read->rd_tmp_file);
  677. if (status) {
  678. dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
  679. goto out;
  680. }
  681. status = nfs_ok;
  682. out:
  683. read->rd_rqstp = rqstp;
  684. read->rd_fhp = &cstate->current_fh;
  685. return status;
  686. }
  687. static __be32
  688. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  689. struct nfsd4_readdir *readdir)
  690. {
  691. u64 cookie = readdir->rd_cookie;
  692. static const nfs4_verifier zeroverf;
  693. /* no need to check permission - this will be done in nfsd_readdir() */
  694. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  695. return nfserr_inval;
  696. readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
  697. readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
  698. readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
  699. if ((cookie == 1) || (cookie == 2) ||
  700. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  701. return nfserr_bad_cookie;
  702. readdir->rd_rqstp = rqstp;
  703. readdir->rd_fhp = &cstate->current_fh;
  704. return nfs_ok;
  705. }
  706. static __be32
  707. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  708. struct nfsd4_readlink *readlink)
  709. {
  710. readlink->rl_rqstp = rqstp;
  711. readlink->rl_fhp = &cstate->current_fh;
  712. return nfs_ok;
  713. }
  714. static __be32
  715. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  716. struct nfsd4_remove *remove)
  717. {
  718. __be32 status;
  719. if (opens_in_grace(SVC_NET(rqstp)))
  720. return nfserr_grace;
  721. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  722. remove->rm_name, remove->rm_namelen);
  723. if (!status) {
  724. fh_unlock(&cstate->current_fh);
  725. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  726. }
  727. return status;
  728. }
  729. static __be32
  730. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  731. struct nfsd4_rename *rename)
  732. {
  733. __be32 status = nfserr_nofilehandle;
  734. if (!cstate->save_fh.fh_dentry)
  735. return status;
  736. if (opens_in_grace(SVC_NET(rqstp)) &&
  737. !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
  738. return nfserr_grace;
  739. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  740. rename->rn_snamelen, &cstate->current_fh,
  741. rename->rn_tname, rename->rn_tnamelen);
  742. if (status)
  743. return status;
  744. set_change_info(&rename->rn_sinfo, &cstate->current_fh);
  745. set_change_info(&rename->rn_tinfo, &cstate->save_fh);
  746. return nfs_ok;
  747. }
  748. static __be32
  749. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  750. struct nfsd4_secinfo *secinfo)
  751. {
  752. struct svc_fh resfh;
  753. struct svc_export *exp;
  754. struct dentry *dentry;
  755. __be32 err;
  756. fh_init(&resfh, NFS4_FHSIZE);
  757. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  758. if (err)
  759. return err;
  760. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  761. secinfo->si_name, secinfo->si_namelen,
  762. &exp, &dentry);
  763. if (err)
  764. return err;
  765. if (d_really_is_negative(dentry)) {
  766. exp_put(exp);
  767. err = nfserr_noent;
  768. } else
  769. secinfo->si_exp = exp;
  770. dput(dentry);
  771. if (cstate->minorversion)
  772. /* See rfc 5661 section 2.6.3.1.1.8 */
  773. fh_put(&cstate->current_fh);
  774. return err;
  775. }
  776. static __be32
  777. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  778. struct nfsd4_secinfo_no_name *sin)
  779. {
  780. __be32 err;
  781. switch (sin->sin_style) {
  782. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  783. break;
  784. case NFS4_SECINFO_STYLE4_PARENT:
  785. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  786. if (err)
  787. return err;
  788. break;
  789. default:
  790. return nfserr_inval;
  791. }
  792. sin->sin_exp = exp_get(cstate->current_fh.fh_export);
  793. fh_put(&cstate->current_fh);
  794. return nfs_ok;
  795. }
  796. static __be32
  797. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  798. struct nfsd4_setattr *setattr)
  799. {
  800. __be32 status = nfs_ok;
  801. int err;
  802. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  803. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  804. &setattr->sa_stateid, WR_STATE, NULL, NULL);
  805. if (status) {
  806. dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
  807. return status;
  808. }
  809. }
  810. err = fh_want_write(&cstate->current_fh);
  811. if (err)
  812. return nfserrno(err);
  813. status = nfs_ok;
  814. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  815. nfsd_attrmask);
  816. if (status)
  817. goto out;
  818. if (setattr->sa_acl != NULL)
  819. status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
  820. setattr->sa_acl);
  821. if (status)
  822. goto out;
  823. if (setattr->sa_label.len)
  824. status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
  825. &setattr->sa_label);
  826. if (status)
  827. goto out;
  828. status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
  829. 0, (time_t)0);
  830. out:
  831. fh_drop_write(&cstate->current_fh);
  832. return status;
  833. }
  834. static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
  835. {
  836. int i = 1;
  837. int buflen = write->wr_buflen;
  838. vec[0].iov_base = write->wr_head.iov_base;
  839. vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len);
  840. buflen -= vec[0].iov_len;
  841. while (buflen) {
  842. vec[i].iov_base = page_address(write->wr_pagelist[i - 1]);
  843. vec[i].iov_len = min_t(int, PAGE_SIZE, buflen);
  844. buflen -= vec[i].iov_len;
  845. i++;
  846. }
  847. return i;
  848. }
  849. static __be32
  850. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  851. struct nfsd4_write *write)
  852. {
  853. stateid_t *stateid = &write->wr_stateid;
  854. struct file *filp = NULL;
  855. __be32 status = nfs_ok;
  856. unsigned long cnt;
  857. int nvecs;
  858. if (write->wr_offset >= OFFSET_MAX)
  859. return nfserr_inval;
  860. status = nfs4_preprocess_stateid_op(rqstp, cstate, stateid, WR_STATE,
  861. &filp, NULL);
  862. if (status) {
  863. dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
  864. return status;
  865. }
  866. cnt = write->wr_buflen;
  867. write->wr_how_written = write->wr_stable_how;
  868. gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp));
  869. nvecs = fill_in_write_vector(rqstp->rq_vec, write);
  870. WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
  871. status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp,
  872. write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
  873. &write->wr_how_written);
  874. fput(filp);
  875. write->wr_bytes_written = cnt;
  876. return status;
  877. }
  878. static __be32
  879. nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  880. struct nfsd4_fallocate *fallocate, int flags)
  881. {
  882. __be32 status = nfserr_notsupp;
  883. struct file *file;
  884. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  885. &fallocate->falloc_stateid,
  886. WR_STATE, &file, NULL);
  887. if (status != nfs_ok) {
  888. dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n");
  889. return status;
  890. }
  891. status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file,
  892. fallocate->falloc_offset,
  893. fallocate->falloc_length,
  894. flags);
  895. fput(file);
  896. return status;
  897. }
  898. static __be32
  899. nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  900. struct nfsd4_fallocate *fallocate)
  901. {
  902. return nfsd4_fallocate(rqstp, cstate, fallocate, 0);
  903. }
  904. static __be32
  905. nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  906. struct nfsd4_fallocate *fallocate)
  907. {
  908. return nfsd4_fallocate(rqstp, cstate, fallocate,
  909. FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
  910. }
  911. static __be32
  912. nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  913. struct nfsd4_seek *seek)
  914. {
  915. int whence;
  916. __be32 status;
  917. struct file *file;
  918. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  919. &seek->seek_stateid,
  920. RD_STATE, &file, NULL);
  921. if (status) {
  922. dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n");
  923. return status;
  924. }
  925. switch (seek->seek_whence) {
  926. case NFS4_CONTENT_DATA:
  927. whence = SEEK_DATA;
  928. break;
  929. case NFS4_CONTENT_HOLE:
  930. whence = SEEK_HOLE;
  931. break;
  932. default:
  933. status = nfserr_union_notsupp;
  934. goto out;
  935. }
  936. /*
  937. * Note: This call does change file->f_pos, but nothing in NFSD
  938. * should ever file->f_pos.
  939. */
  940. seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence);
  941. if (seek->seek_pos < 0)
  942. status = nfserrno(seek->seek_pos);
  943. else if (seek->seek_pos >= i_size_read(file_inode(file)))
  944. seek->seek_eof = true;
  945. out:
  946. fput(file);
  947. return status;
  948. }
  949. /* This routine never returns NFS_OK! If there are no other errors, it
  950. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  951. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  952. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  953. */
  954. static __be32
  955. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  956. struct nfsd4_verify *verify)
  957. {
  958. __be32 *buf, *p;
  959. int count;
  960. __be32 status;
  961. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  962. if (status)
  963. return status;
  964. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  965. if (status)
  966. return status;
  967. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  968. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  969. return nfserr_inval;
  970. if (verify->ve_attrlen & 3)
  971. return nfserr_inval;
  972. /* count in words:
  973. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  974. */
  975. count = 4 + (verify->ve_attrlen >> 2);
  976. buf = kmalloc(count << 2, GFP_KERNEL);
  977. if (!buf)
  978. return nfserr_jukebox;
  979. p = buf;
  980. status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
  981. cstate->current_fh.fh_export,
  982. cstate->current_fh.fh_dentry,
  983. verify->ve_bmval,
  984. rqstp, 0);
  985. /*
  986. * If nfsd4_encode_fattr() ran out of space, assume that's because
  987. * the attributes are longer (hence different) than those given:
  988. */
  989. if (status == nfserr_resource)
  990. status = nfserr_not_same;
  991. if (status)
  992. goto out_kfree;
  993. /* skip bitmap */
  994. p = buf + 1 + ntohl(buf[0]);
  995. status = nfserr_not_same;
  996. if (ntohl(*p++) != verify->ve_attrlen)
  997. goto out_kfree;
  998. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  999. status = nfserr_same;
  1000. out_kfree:
  1001. kfree(buf);
  1002. return status;
  1003. }
  1004. static __be32
  1005. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1006. struct nfsd4_verify *verify)
  1007. {
  1008. __be32 status;
  1009. status = _nfsd4_verify(rqstp, cstate, verify);
  1010. return status == nfserr_not_same ? nfs_ok : status;
  1011. }
  1012. static __be32
  1013. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1014. struct nfsd4_verify *verify)
  1015. {
  1016. __be32 status;
  1017. status = _nfsd4_verify(rqstp, cstate, verify);
  1018. return status == nfserr_same ? nfs_ok : status;
  1019. }
  1020. #ifdef CONFIG_NFSD_PNFS
  1021. static const struct nfsd4_layout_ops *
  1022. nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
  1023. {
  1024. if (!exp->ex_layout_type) {
  1025. dprintk("%s: export does not support pNFS\n", __func__);
  1026. return NULL;
  1027. }
  1028. if (exp->ex_layout_type != layout_type) {
  1029. dprintk("%s: layout type %d not supported\n",
  1030. __func__, layout_type);
  1031. return NULL;
  1032. }
  1033. return nfsd4_layout_ops[layout_type];
  1034. }
  1035. static __be32
  1036. nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
  1037. struct nfsd4_compound_state *cstate,
  1038. struct nfsd4_getdeviceinfo *gdp)
  1039. {
  1040. const struct nfsd4_layout_ops *ops;
  1041. struct nfsd4_deviceid_map *map;
  1042. struct svc_export *exp;
  1043. __be32 nfserr;
  1044. dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
  1045. __func__,
  1046. gdp->gd_layout_type,
  1047. gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
  1048. gdp->gd_maxcount);
  1049. map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
  1050. if (!map) {
  1051. dprintk("%s: couldn't find device ID to export mapping!\n",
  1052. __func__);
  1053. return nfserr_noent;
  1054. }
  1055. exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid);
  1056. if (IS_ERR(exp)) {
  1057. dprintk("%s: could not find device id\n", __func__);
  1058. return nfserr_noent;
  1059. }
  1060. nfserr = nfserr_layoutunavailable;
  1061. ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
  1062. if (!ops)
  1063. goto out;
  1064. nfserr = nfs_ok;
  1065. if (gdp->gd_maxcount != 0)
  1066. nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, gdp);
  1067. gdp->gd_notify_types &= ops->notify_types;
  1068. out:
  1069. exp_put(exp);
  1070. return nfserr;
  1071. }
  1072. static __be32
  1073. nfsd4_layoutget(struct svc_rqst *rqstp,
  1074. struct nfsd4_compound_state *cstate,
  1075. struct nfsd4_layoutget *lgp)
  1076. {
  1077. struct svc_fh *current_fh = &cstate->current_fh;
  1078. const struct nfsd4_layout_ops *ops;
  1079. struct nfs4_layout_stateid *ls;
  1080. __be32 nfserr;
  1081. int accmode;
  1082. switch (lgp->lg_seg.iomode) {
  1083. case IOMODE_READ:
  1084. accmode = NFSD_MAY_READ;
  1085. break;
  1086. case IOMODE_RW:
  1087. accmode = NFSD_MAY_READ | NFSD_MAY_WRITE;
  1088. break;
  1089. default:
  1090. dprintk("%s: invalid iomode %d\n",
  1091. __func__, lgp->lg_seg.iomode);
  1092. nfserr = nfserr_badiomode;
  1093. goto out;
  1094. }
  1095. nfserr = fh_verify(rqstp, current_fh, 0, accmode);
  1096. if (nfserr)
  1097. goto out;
  1098. nfserr = nfserr_layoutunavailable;
  1099. ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
  1100. if (!ops)
  1101. goto out;
  1102. /*
  1103. * Verify minlength and range as per RFC5661:
  1104. * o If loga_length is less than loga_minlength,
  1105. * the metadata server MUST return NFS4ERR_INVAL.
  1106. * o If the sum of loga_offset and loga_minlength exceeds
  1107. * NFS4_UINT64_MAX, and loga_minlength is not
  1108. * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
  1109. * o If the sum of loga_offset and loga_length exceeds
  1110. * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
  1111. * the error NFS4ERR_INVAL MUST result.
  1112. */
  1113. nfserr = nfserr_inval;
  1114. if (lgp->lg_seg.length < lgp->lg_minlength ||
  1115. (lgp->lg_minlength != NFS4_MAX_UINT64 &&
  1116. lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
  1117. (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
  1118. lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
  1119. goto out;
  1120. if (lgp->lg_seg.length == 0)
  1121. goto out;
  1122. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
  1123. true, lgp->lg_layout_type, &ls);
  1124. if (nfserr) {
  1125. trace_layout_get_lookup_fail(&lgp->lg_sid);
  1126. goto out;
  1127. }
  1128. nfserr = nfserr_recallconflict;
  1129. if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
  1130. goto out_put_stid;
  1131. nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
  1132. current_fh, lgp);
  1133. if (nfserr)
  1134. goto out_put_stid;
  1135. nfserr = nfsd4_insert_layout(lgp, ls);
  1136. out_put_stid:
  1137. mutex_unlock(&ls->ls_mutex);
  1138. nfs4_put_stid(&ls->ls_stid);
  1139. out:
  1140. return nfserr;
  1141. }
  1142. static __be32
  1143. nfsd4_layoutcommit(struct svc_rqst *rqstp,
  1144. struct nfsd4_compound_state *cstate,
  1145. struct nfsd4_layoutcommit *lcp)
  1146. {
  1147. const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
  1148. struct svc_fh *current_fh = &cstate->current_fh;
  1149. const struct nfsd4_layout_ops *ops;
  1150. loff_t new_size = lcp->lc_last_wr + 1;
  1151. struct inode *inode;
  1152. struct nfs4_layout_stateid *ls;
  1153. __be32 nfserr;
  1154. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
  1155. if (nfserr)
  1156. goto out;
  1157. nfserr = nfserr_layoutunavailable;
  1158. ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
  1159. if (!ops)
  1160. goto out;
  1161. inode = d_inode(current_fh->fh_dentry);
  1162. nfserr = nfserr_inval;
  1163. if (new_size <= seg->offset) {
  1164. dprintk("pnfsd: last write before layout segment\n");
  1165. goto out;
  1166. }
  1167. if (new_size > seg->offset + seg->length) {
  1168. dprintk("pnfsd: last write beyond layout segment\n");
  1169. goto out;
  1170. }
  1171. if (!lcp->lc_newoffset && new_size > i_size_read(inode)) {
  1172. dprintk("pnfsd: layoutcommit beyond EOF\n");
  1173. goto out;
  1174. }
  1175. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
  1176. false, lcp->lc_layout_type,
  1177. &ls);
  1178. if (nfserr) {
  1179. trace_layout_commit_lookup_fail(&lcp->lc_sid);
  1180. /* fixup error code as per RFC5661 */
  1181. if (nfserr == nfserr_bad_stateid)
  1182. nfserr = nfserr_badlayout;
  1183. goto out;
  1184. }
  1185. /* LAYOUTCOMMIT does not require any serialization */
  1186. mutex_unlock(&ls->ls_mutex);
  1187. if (new_size > i_size_read(inode)) {
  1188. lcp->lc_size_chg = 1;
  1189. lcp->lc_newsize = new_size;
  1190. } else {
  1191. lcp->lc_size_chg = 0;
  1192. }
  1193. nfserr = ops->proc_layoutcommit(inode, lcp);
  1194. nfs4_put_stid(&ls->ls_stid);
  1195. out:
  1196. return nfserr;
  1197. }
  1198. static __be32
  1199. nfsd4_layoutreturn(struct svc_rqst *rqstp,
  1200. struct nfsd4_compound_state *cstate,
  1201. struct nfsd4_layoutreturn *lrp)
  1202. {
  1203. struct svc_fh *current_fh = &cstate->current_fh;
  1204. __be32 nfserr;
  1205. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
  1206. if (nfserr)
  1207. goto out;
  1208. nfserr = nfserr_layoutunavailable;
  1209. if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
  1210. goto out;
  1211. switch (lrp->lr_seg.iomode) {
  1212. case IOMODE_READ:
  1213. case IOMODE_RW:
  1214. case IOMODE_ANY:
  1215. break;
  1216. default:
  1217. dprintk("%s: invalid iomode %d\n", __func__,
  1218. lrp->lr_seg.iomode);
  1219. nfserr = nfserr_inval;
  1220. goto out;
  1221. }
  1222. switch (lrp->lr_return_type) {
  1223. case RETURN_FILE:
  1224. nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
  1225. break;
  1226. case RETURN_FSID:
  1227. case RETURN_ALL:
  1228. nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
  1229. break;
  1230. default:
  1231. dprintk("%s: invalid return_type %d\n", __func__,
  1232. lrp->lr_return_type);
  1233. nfserr = nfserr_inval;
  1234. break;
  1235. }
  1236. out:
  1237. return nfserr;
  1238. }
  1239. #endif /* CONFIG_NFSD_PNFS */
  1240. /*
  1241. * NULL call.
  1242. */
  1243. static __be32
  1244. nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
  1245. {
  1246. return nfs_ok;
  1247. }
  1248. static inline void nfsd4_increment_op_stats(u32 opnum)
  1249. {
  1250. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  1251. nfsdstats.nfs4_opcount[opnum]++;
  1252. }
  1253. typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
  1254. void *);
  1255. typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
  1256. typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
  1257. typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
  1258. enum nfsd4_op_flags {
  1259. ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
  1260. ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
  1261. ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
  1262. /* For rfc 5661 section 2.6.3.1.1: */
  1263. OP_HANDLES_WRONGSEC = 1 << 3,
  1264. OP_IS_PUTFH_LIKE = 1 << 4,
  1265. /*
  1266. * These are the ops whose result size we estimate before
  1267. * encoding, to avoid performing an op then not being able to
  1268. * respond or cache a response. This includes writes and setattrs
  1269. * as well as the operations usually called "nonidempotent":
  1270. */
  1271. OP_MODIFIES_SOMETHING = 1 << 5,
  1272. /*
  1273. * Cache compounds containing these ops in the xid-based drc:
  1274. * We use the DRC for compounds containing non-idempotent
  1275. * operations, *except* those that are 4.1-specific (since
  1276. * sessions provide their own EOS), and except for stateful
  1277. * operations other than setclientid and setclientid_confirm
  1278. * (since sequence numbers provide EOS for open, lock, etc in
  1279. * the v4.0 case).
  1280. */
  1281. OP_CACHEME = 1 << 6,
  1282. /*
  1283. * These are ops which clear current state id.
  1284. */
  1285. OP_CLEAR_STATEID = 1 << 7,
  1286. };
  1287. struct nfsd4_operation {
  1288. nfsd4op_func op_func;
  1289. u32 op_flags;
  1290. char *op_name;
  1291. /* Try to get response size before operation */
  1292. nfsd4op_rsize op_rsize_bop;
  1293. stateid_getter op_get_currentstateid;
  1294. stateid_setter op_set_currentstateid;
  1295. };
  1296. static struct nfsd4_operation nfsd4_ops[];
  1297. static const char *nfsd4_op_name(unsigned opnum);
  1298. /*
  1299. * Enforce NFSv4.1 COMPOUND ordering rules:
  1300. *
  1301. * Also note, enforced elsewhere:
  1302. * - SEQUENCE other than as first op results in
  1303. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  1304. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  1305. * (Enforced in nfsd4_bind_conn_to_session().)
  1306. * - DESTROY_SESSION must be the final operation in a compound, if
  1307. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  1308. * (Enforced in nfsd4_destroy_session().)
  1309. */
  1310. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  1311. {
  1312. struct nfsd4_op *op = &args->ops[0];
  1313. /* These ordering requirements don't apply to NFSv4.0: */
  1314. if (args->minorversion == 0)
  1315. return nfs_ok;
  1316. /* This is weird, but OK, not our problem: */
  1317. if (args->opcnt == 0)
  1318. return nfs_ok;
  1319. if (op->status == nfserr_op_illegal)
  1320. return nfs_ok;
  1321. if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  1322. return nfserr_op_not_in_session;
  1323. if (op->opnum == OP_SEQUENCE)
  1324. return nfs_ok;
  1325. if (args->opcnt != 1)
  1326. return nfserr_not_only_op;
  1327. return nfs_ok;
  1328. }
  1329. static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  1330. {
  1331. return &nfsd4_ops[op->opnum];
  1332. }
  1333. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  1334. {
  1335. if (op->opnum == OP_ILLEGAL)
  1336. return false;
  1337. return OPDESC(op)->op_flags & OP_CACHEME;
  1338. }
  1339. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  1340. {
  1341. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1342. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  1343. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  1344. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  1345. struct nfsd4_operation *thisd;
  1346. struct nfsd4_operation *nextd;
  1347. thisd = OPDESC(this);
  1348. /*
  1349. * Most ops check wronsec on our own; only the putfh-like ops
  1350. * have special rules.
  1351. */
  1352. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  1353. return false;
  1354. /*
  1355. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  1356. * put-filehandle operation if we're not going to use the
  1357. * result:
  1358. */
  1359. if (argp->opcnt == resp->opcnt)
  1360. return false;
  1361. if (next->opnum == OP_ILLEGAL)
  1362. return false;
  1363. nextd = OPDESC(next);
  1364. /*
  1365. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  1366. * errors themselves as necessary; others should check for them
  1367. * now:
  1368. */
  1369. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  1370. }
  1371. static void svcxdr_init_encode(struct svc_rqst *rqstp,
  1372. struct nfsd4_compoundres *resp)
  1373. {
  1374. struct xdr_stream *xdr = &resp->xdr;
  1375. struct xdr_buf *buf = &rqstp->rq_res;
  1376. struct kvec *head = buf->head;
  1377. xdr->buf = buf;
  1378. xdr->iov = head;
  1379. xdr->p = head->iov_base + head->iov_len;
  1380. xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
  1381. /* Tail and page_len should be zero at this point: */
  1382. buf->len = buf->head[0].iov_len;
  1383. xdr->scratch.iov_len = 0;
  1384. xdr->page_ptr = buf->pages - 1;
  1385. buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
  1386. - rqstp->rq_auth_slack;
  1387. }
  1388. /*
  1389. * COMPOUND call.
  1390. */
  1391. static __be32
  1392. nfsd4_proc_compound(struct svc_rqst *rqstp,
  1393. struct nfsd4_compoundargs *args,
  1394. struct nfsd4_compoundres *resp)
  1395. {
  1396. struct nfsd4_op *op;
  1397. struct nfsd4_operation *opdesc;
  1398. struct nfsd4_compound_state *cstate = &resp->cstate;
  1399. struct svc_fh *current_fh = &cstate->current_fh;
  1400. struct svc_fh *save_fh = &cstate->save_fh;
  1401. __be32 status;
  1402. svcxdr_init_encode(rqstp, resp);
  1403. resp->tagp = resp->xdr.p;
  1404. /* reserve space for: taglen, tag, and opcnt */
  1405. xdr_reserve_space(&resp->xdr, 8 + args->taglen);
  1406. resp->taglen = args->taglen;
  1407. resp->tag = args->tag;
  1408. resp->rqstp = rqstp;
  1409. cstate->minorversion = args->minorversion;
  1410. fh_init(current_fh, NFS4_FHSIZE);
  1411. fh_init(save_fh, NFS4_FHSIZE);
  1412. /*
  1413. * Don't use the deferral mechanism for NFSv4; compounds make it
  1414. * too hard to avoid non-idempotency problems.
  1415. */
  1416. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1417. /*
  1418. * According to RFC3010, this takes precedence over all other errors.
  1419. */
  1420. status = nfserr_minor_vers_mismatch;
  1421. if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0)
  1422. goto out;
  1423. status = nfs41_check_op_ordering(args);
  1424. if (status) {
  1425. op = &args->ops[0];
  1426. op->status = status;
  1427. goto encode_op;
  1428. }
  1429. while (!status && resp->opcnt < args->opcnt) {
  1430. op = &args->ops[resp->opcnt++];
  1431. dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
  1432. resp->opcnt, args->opcnt, op->opnum,
  1433. nfsd4_op_name(op->opnum));
  1434. /*
  1435. * The XDR decode routines may have pre-set op->status;
  1436. * for example, if there is a miscellaneous XDR error
  1437. * it will be set to nfserr_bad_xdr.
  1438. */
  1439. if (op->status) {
  1440. if (op->opnum == OP_OPEN)
  1441. op->status = nfsd4_open_omfg(rqstp, cstate, op);
  1442. goto encode_op;
  1443. }
  1444. opdesc = OPDESC(op);
  1445. if (!current_fh->fh_dentry) {
  1446. if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  1447. op->status = nfserr_nofilehandle;
  1448. goto encode_op;
  1449. }
  1450. } else if (current_fh->fh_export->ex_fslocs.migrated &&
  1451. !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  1452. op->status = nfserr_moved;
  1453. goto encode_op;
  1454. }
  1455. fh_clear_wcc(current_fh);
  1456. /* If op is non-idempotent */
  1457. if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  1458. /*
  1459. * Don't execute this op if we couldn't encode a
  1460. * succesful reply:
  1461. */
  1462. u32 plen = opdesc->op_rsize_bop(rqstp, op);
  1463. /*
  1464. * Plus if there's another operation, make sure
  1465. * we'll have space to at least encode an error:
  1466. */
  1467. if (resp->opcnt < args->opcnt)
  1468. plen += COMPOUND_ERR_SLACK_SPACE;
  1469. op->status = nfsd4_check_resp_size(resp, plen);
  1470. }
  1471. if (op->status)
  1472. goto encode_op;
  1473. if (opdesc->op_get_currentstateid)
  1474. opdesc->op_get_currentstateid(cstate, &op->u);
  1475. op->status = opdesc->op_func(rqstp, cstate, &op->u);
  1476. if (!op->status) {
  1477. if (opdesc->op_set_currentstateid)
  1478. opdesc->op_set_currentstateid(cstate, &op->u);
  1479. if (opdesc->op_flags & OP_CLEAR_STATEID)
  1480. clear_current_stateid(cstate);
  1481. if (need_wrongsec_check(rqstp))
  1482. op->status = check_nfsd_access(current_fh->fh_export, rqstp);
  1483. }
  1484. encode_op:
  1485. /* Only from SEQUENCE */
  1486. if (cstate->status == nfserr_replay_cache) {
  1487. dprintk("%s NFS4.1 replay from cache\n", __func__);
  1488. status = op->status;
  1489. goto out;
  1490. }
  1491. if (op->status == nfserr_replay_me) {
  1492. op->replay = &cstate->replay_owner->so_replay;
  1493. nfsd4_encode_replay(&resp->xdr, op);
  1494. status = op->status = op->replay->rp_status;
  1495. } else {
  1496. nfsd4_encode_operation(resp, op);
  1497. status = op->status;
  1498. }
  1499. dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
  1500. args->ops, args->opcnt, resp->opcnt, op->opnum,
  1501. be32_to_cpu(status));
  1502. nfsd4_cstate_clear_replay(cstate);
  1503. nfsd4_increment_op_stats(op->opnum);
  1504. }
  1505. cstate->status = status;
  1506. fh_put(current_fh);
  1507. fh_put(save_fh);
  1508. BUG_ON(cstate->replay_owner);
  1509. out:
  1510. /* Reset deferral mechanism for RPC deferrals */
  1511. set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  1512. dprintk("nfsv4 compound returned %d\n", ntohl(status));
  1513. return status;
  1514. }
  1515. #define op_encode_hdr_size (2)
  1516. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  1517. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  1518. #define op_encode_change_info_maxsz (5)
  1519. #define nfs4_fattr_bitmap_maxsz (4)
  1520. /* We'll fall back on returning no lockowner if run out of space: */
  1521. #define op_encode_lockowner_maxsz (0)
  1522. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  1523. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  1524. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  1525. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  1526. op_encode_ace_maxsz)
  1527. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  1528. static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1529. {
  1530. return (op_encode_hdr_size) * sizeof(__be32);
  1531. }
  1532. static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1533. {
  1534. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  1535. }
  1536. static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1537. {
  1538. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  1539. }
  1540. static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1541. {
  1542. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1543. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1544. }
  1545. /*
  1546. * Note since this is an idempotent operation we won't insist on failing
  1547. * the op prematurely if the estimate is too large. We may turn off splice
  1548. * reads unnecessarily.
  1549. */
  1550. static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp,
  1551. struct nfsd4_op *op)
  1552. {
  1553. u32 *bmap = op->u.getattr.ga_bmval;
  1554. u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
  1555. u32 ret = 0;
  1556. if (bmap0 & FATTR4_WORD0_ACL)
  1557. return svc_max_payload(rqstp);
  1558. if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
  1559. return svc_max_payload(rqstp);
  1560. if (bmap1 & FATTR4_WORD1_OWNER) {
  1561. ret += IDMAP_NAMESZ + 4;
  1562. bmap1 &= ~FATTR4_WORD1_OWNER;
  1563. }
  1564. if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
  1565. ret += IDMAP_NAMESZ + 4;
  1566. bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
  1567. }
  1568. if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
  1569. ret += NFS4_FHSIZE + 4;
  1570. bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
  1571. }
  1572. if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
  1573. ret += NFS4_MAXLABELLEN + 12;
  1574. bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
  1575. }
  1576. /*
  1577. * Largest of remaining attributes are 16 bytes (e.g.,
  1578. * supported_attributes)
  1579. */
  1580. ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
  1581. /* bitmask, length */
  1582. ret += 20;
  1583. return ret;
  1584. }
  1585. static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1586. {
  1587. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1588. * sizeof(__be32);
  1589. }
  1590. static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1591. {
  1592. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  1593. * sizeof(__be32);
  1594. }
  1595. static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1596. {
  1597. return (op_encode_hdr_size + op_encode_stateid_maxsz
  1598. + op_encode_change_info_maxsz + 1
  1599. + nfs4_fattr_bitmap_maxsz
  1600. + op_encode_delegation_maxsz) * sizeof(__be32);
  1601. }
  1602. static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1603. {
  1604. u32 maxcount = 0, rlen = 0;
  1605. maxcount = svc_max_payload(rqstp);
  1606. rlen = min(op->u.read.rd_length, maxcount);
  1607. return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  1608. }
  1609. static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1610. {
  1611. u32 maxcount = 0, rlen = 0;
  1612. maxcount = svc_max_payload(rqstp);
  1613. rlen = min(op->u.readdir.rd_maxcount, maxcount);
  1614. return (op_encode_hdr_size + op_encode_verifier_maxsz +
  1615. XDR_QUADLEN(rlen)) * sizeof(__be32);
  1616. }
  1617. static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1618. {
  1619. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  1620. * sizeof(__be32);
  1621. }
  1622. static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1623. {
  1624. return (op_encode_hdr_size + op_encode_change_info_maxsz
  1625. + op_encode_change_info_maxsz) * sizeof(__be32);
  1626. }
  1627. static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp,
  1628. struct nfsd4_op *op)
  1629. {
  1630. return (op_encode_hdr_size
  1631. + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
  1632. }
  1633. static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1634. {
  1635. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  1636. }
  1637. static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1638. {
  1639. return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
  1640. sizeof(__be32);
  1641. }
  1642. static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1643. {
  1644. return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
  1645. }
  1646. static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1647. {
  1648. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  1649. 1 + 1 + /* eir_flags, spr_how */\
  1650. 4 + /* spo_must_enforce & _allow with bitmap */\
  1651. 2 + /*eir_server_owner.so_minor_id */\
  1652. /* eir_server_owner.so_major_id<> */\
  1653. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1654. /* eir_server_scope<> */\
  1655. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  1656. 1 + /* eir_server_impl_id array length */\
  1657. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  1658. }
  1659. static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1660. {
  1661. return (op_encode_hdr_size + \
  1662. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  1663. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  1664. }
  1665. static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1666. {
  1667. return (op_encode_hdr_size + \
  1668. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  1669. 2 + /* csr_sequence, csr_flags */\
  1670. op_encode_channel_attrs_maxsz + \
  1671. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  1672. }
  1673. #ifdef CONFIG_NFSD_PNFS
  1674. /*
  1675. * At this stage we don't really know what layout driver will handle the request,
  1676. * so we need to define an arbitrary upper bound here.
  1677. */
  1678. #define MAX_LAYOUT_SIZE 128
  1679. static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1680. {
  1681. return (op_encode_hdr_size +
  1682. 1 /* logr_return_on_close */ +
  1683. op_encode_stateid_maxsz +
  1684. 1 /* nr of layouts */ +
  1685. MAX_LAYOUT_SIZE) * sizeof(__be32);
  1686. }
  1687. static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1688. {
  1689. return (op_encode_hdr_size +
  1690. 1 /* locr_newsize */ +
  1691. 2 /* ns_size */) * sizeof(__be32);
  1692. }
  1693. static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
  1694. {
  1695. return (op_encode_hdr_size +
  1696. 1 /* lrs_stateid */ +
  1697. op_encode_stateid_maxsz) * sizeof(__be32);
  1698. }
  1699. #endif /* CONFIG_NFSD_PNFS */
  1700. static struct nfsd4_operation nfsd4_ops[] = {
  1701. [OP_ACCESS] = {
  1702. .op_func = (nfsd4op_func)nfsd4_access,
  1703. .op_name = "OP_ACCESS",
  1704. },
  1705. [OP_CLOSE] = {
  1706. .op_func = (nfsd4op_func)nfsd4_close,
  1707. .op_flags = OP_MODIFIES_SOMETHING,
  1708. .op_name = "OP_CLOSE",
  1709. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1710. .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
  1711. .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
  1712. },
  1713. [OP_COMMIT] = {
  1714. .op_func = (nfsd4op_func)nfsd4_commit,
  1715. .op_flags = OP_MODIFIES_SOMETHING,
  1716. .op_name = "OP_COMMIT",
  1717. .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
  1718. },
  1719. [OP_CREATE] = {
  1720. .op_func = (nfsd4op_func)nfsd4_create,
  1721. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
  1722. .op_name = "OP_CREATE",
  1723. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
  1724. },
  1725. [OP_DELEGRETURN] = {
  1726. .op_func = (nfsd4op_func)nfsd4_delegreturn,
  1727. .op_flags = OP_MODIFIES_SOMETHING,
  1728. .op_name = "OP_DELEGRETURN",
  1729. .op_rsize_bop = nfsd4_only_status_rsize,
  1730. .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
  1731. },
  1732. [OP_GETATTR] = {
  1733. .op_func = (nfsd4op_func)nfsd4_getattr,
  1734. .op_flags = ALLOWED_ON_ABSENT_FS,
  1735. .op_rsize_bop = nfsd4_getattr_rsize,
  1736. .op_name = "OP_GETATTR",
  1737. },
  1738. [OP_GETFH] = {
  1739. .op_func = (nfsd4op_func)nfsd4_getfh,
  1740. .op_name = "OP_GETFH",
  1741. },
  1742. [OP_LINK] = {
  1743. .op_func = (nfsd4op_func)nfsd4_link,
  1744. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  1745. | OP_CACHEME,
  1746. .op_name = "OP_LINK",
  1747. .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
  1748. },
  1749. [OP_LOCK] = {
  1750. .op_func = (nfsd4op_func)nfsd4_lock,
  1751. .op_flags = OP_MODIFIES_SOMETHING,
  1752. .op_name = "OP_LOCK",
  1753. .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
  1754. .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
  1755. },
  1756. [OP_LOCKT] = {
  1757. .op_func = (nfsd4op_func)nfsd4_lockt,
  1758. .op_name = "OP_LOCKT",
  1759. },
  1760. [OP_LOCKU] = {
  1761. .op_func = (nfsd4op_func)nfsd4_locku,
  1762. .op_flags = OP_MODIFIES_SOMETHING,
  1763. .op_name = "OP_LOCKU",
  1764. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1765. .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
  1766. },
  1767. [OP_LOOKUP] = {
  1768. .op_func = (nfsd4op_func)nfsd4_lookup,
  1769. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1770. .op_name = "OP_LOOKUP",
  1771. },
  1772. [OP_LOOKUPP] = {
  1773. .op_func = (nfsd4op_func)nfsd4_lookupp,
  1774. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  1775. .op_name = "OP_LOOKUPP",
  1776. },
  1777. [OP_NVERIFY] = {
  1778. .op_func = (nfsd4op_func)nfsd4_nverify,
  1779. .op_name = "OP_NVERIFY",
  1780. },
  1781. [OP_OPEN] = {
  1782. .op_func = (nfsd4op_func)nfsd4_open,
  1783. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1784. .op_name = "OP_OPEN",
  1785. .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
  1786. .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
  1787. },
  1788. [OP_OPEN_CONFIRM] = {
  1789. .op_func = (nfsd4op_func)nfsd4_open_confirm,
  1790. .op_flags = OP_MODIFIES_SOMETHING,
  1791. .op_name = "OP_OPEN_CONFIRM",
  1792. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1793. },
  1794. [OP_OPEN_DOWNGRADE] = {
  1795. .op_func = (nfsd4op_func)nfsd4_open_downgrade,
  1796. .op_flags = OP_MODIFIES_SOMETHING,
  1797. .op_name = "OP_OPEN_DOWNGRADE",
  1798. .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
  1799. .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
  1800. .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
  1801. },
  1802. [OP_PUTFH] = {
  1803. .op_func = (nfsd4op_func)nfsd4_putfh,
  1804. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1805. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1806. .op_name = "OP_PUTFH",
  1807. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1808. },
  1809. [OP_PUTPUBFH] = {
  1810. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1811. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1812. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1813. .op_name = "OP_PUTPUBFH",
  1814. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1815. },
  1816. [OP_PUTROOTFH] = {
  1817. .op_func = (nfsd4op_func)nfsd4_putrootfh,
  1818. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1819. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  1820. .op_name = "OP_PUTROOTFH",
  1821. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1822. },
  1823. [OP_READ] = {
  1824. .op_func = (nfsd4op_func)nfsd4_read,
  1825. .op_name = "OP_READ",
  1826. .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
  1827. .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
  1828. },
  1829. [OP_READDIR] = {
  1830. .op_func = (nfsd4op_func)nfsd4_readdir,
  1831. .op_name = "OP_READDIR",
  1832. .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
  1833. },
  1834. [OP_READLINK] = {
  1835. .op_func = (nfsd4op_func)nfsd4_readlink,
  1836. .op_name = "OP_READLINK",
  1837. },
  1838. [OP_REMOVE] = {
  1839. .op_func = (nfsd4op_func)nfsd4_remove,
  1840. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1841. .op_name = "OP_REMOVE",
  1842. .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
  1843. },
  1844. [OP_RENAME] = {
  1845. .op_func = (nfsd4op_func)nfsd4_rename,
  1846. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1847. .op_name = "OP_RENAME",
  1848. .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
  1849. },
  1850. [OP_RENEW] = {
  1851. .op_func = (nfsd4op_func)nfsd4_renew,
  1852. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1853. | OP_MODIFIES_SOMETHING,
  1854. .op_name = "OP_RENEW",
  1855. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1856. },
  1857. [OP_RESTOREFH] = {
  1858. .op_func = (nfsd4op_func)nfsd4_restorefh,
  1859. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1860. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  1861. .op_name = "OP_RESTOREFH",
  1862. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1863. },
  1864. [OP_SAVEFH] = {
  1865. .op_func = (nfsd4op_func)nfsd4_savefh,
  1866. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  1867. .op_name = "OP_SAVEFH",
  1868. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1869. },
  1870. [OP_SECINFO] = {
  1871. .op_func = (nfsd4op_func)nfsd4_secinfo,
  1872. .op_flags = OP_HANDLES_WRONGSEC,
  1873. .op_name = "OP_SECINFO",
  1874. },
  1875. [OP_SETATTR] = {
  1876. .op_func = (nfsd4op_func)nfsd4_setattr,
  1877. .op_name = "OP_SETATTR",
  1878. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1879. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
  1880. .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
  1881. },
  1882. [OP_SETCLIENTID] = {
  1883. .op_func = (nfsd4op_func)nfsd4_setclientid,
  1884. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1885. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1886. .op_name = "OP_SETCLIENTID",
  1887. .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
  1888. },
  1889. [OP_SETCLIENTID_CONFIRM] = {
  1890. .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
  1891. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1892. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  1893. .op_name = "OP_SETCLIENTID_CONFIRM",
  1894. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1895. },
  1896. [OP_VERIFY] = {
  1897. .op_func = (nfsd4op_func)nfsd4_verify,
  1898. .op_name = "OP_VERIFY",
  1899. },
  1900. [OP_WRITE] = {
  1901. .op_func = (nfsd4op_func)nfsd4_write,
  1902. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  1903. .op_name = "OP_WRITE",
  1904. .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
  1905. .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
  1906. },
  1907. [OP_RELEASE_LOCKOWNER] = {
  1908. .op_func = (nfsd4op_func)nfsd4_release_lockowner,
  1909. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  1910. | OP_MODIFIES_SOMETHING,
  1911. .op_name = "OP_RELEASE_LOCKOWNER",
  1912. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1913. },
  1914. /* NFSv4.1 operations */
  1915. [OP_EXCHANGE_ID] = {
  1916. .op_func = (nfsd4op_func)nfsd4_exchange_id,
  1917. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1918. | OP_MODIFIES_SOMETHING,
  1919. .op_name = "OP_EXCHANGE_ID",
  1920. .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
  1921. },
  1922. [OP_BACKCHANNEL_CTL] = {
  1923. .op_func = (nfsd4op_func)nfsd4_backchannel_ctl,
  1924. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1925. .op_name = "OP_BACKCHANNEL_CTL",
  1926. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1927. },
  1928. [OP_BIND_CONN_TO_SESSION] = {
  1929. .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
  1930. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1931. | OP_MODIFIES_SOMETHING,
  1932. .op_name = "OP_BIND_CONN_TO_SESSION",
  1933. .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
  1934. },
  1935. [OP_CREATE_SESSION] = {
  1936. .op_func = (nfsd4op_func)nfsd4_create_session,
  1937. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1938. | OP_MODIFIES_SOMETHING,
  1939. .op_name = "OP_CREATE_SESSION",
  1940. .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
  1941. },
  1942. [OP_DESTROY_SESSION] = {
  1943. .op_func = (nfsd4op_func)nfsd4_destroy_session,
  1944. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1945. | OP_MODIFIES_SOMETHING,
  1946. .op_name = "OP_DESTROY_SESSION",
  1947. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1948. },
  1949. [OP_SEQUENCE] = {
  1950. .op_func = (nfsd4op_func)nfsd4_sequence,
  1951. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  1952. .op_name = "OP_SEQUENCE",
  1953. .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize,
  1954. },
  1955. [OP_DESTROY_CLIENTID] = {
  1956. .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
  1957. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  1958. | OP_MODIFIES_SOMETHING,
  1959. .op_name = "OP_DESTROY_CLIENTID",
  1960. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1961. },
  1962. [OP_RECLAIM_COMPLETE] = {
  1963. .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
  1964. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1965. .op_name = "OP_RECLAIM_COMPLETE",
  1966. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1967. },
  1968. [OP_SECINFO_NO_NAME] = {
  1969. .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
  1970. .op_flags = OP_HANDLES_WRONGSEC,
  1971. .op_name = "OP_SECINFO_NO_NAME",
  1972. },
  1973. [OP_TEST_STATEID] = {
  1974. .op_func = (nfsd4op_func)nfsd4_test_stateid,
  1975. .op_flags = ALLOWED_WITHOUT_FH,
  1976. .op_name = "OP_TEST_STATEID",
  1977. },
  1978. [OP_FREE_STATEID] = {
  1979. .op_func = (nfsd4op_func)nfsd4_free_stateid,
  1980. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  1981. .op_name = "OP_FREE_STATEID",
  1982. .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid,
  1983. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  1984. },
  1985. #ifdef CONFIG_NFSD_PNFS
  1986. [OP_GETDEVICEINFO] = {
  1987. .op_func = (nfsd4op_func)nfsd4_getdeviceinfo,
  1988. .op_flags = ALLOWED_WITHOUT_FH,
  1989. .op_name = "OP_GETDEVICEINFO",
  1990. },
  1991. [OP_LAYOUTGET] = {
  1992. .op_func = (nfsd4op_func)nfsd4_layoutget,
  1993. .op_flags = OP_MODIFIES_SOMETHING,
  1994. .op_name = "OP_LAYOUTGET",
  1995. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize,
  1996. },
  1997. [OP_LAYOUTCOMMIT] = {
  1998. .op_func = (nfsd4op_func)nfsd4_layoutcommit,
  1999. .op_flags = OP_MODIFIES_SOMETHING,
  2000. .op_name = "OP_LAYOUTCOMMIT",
  2001. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize,
  2002. },
  2003. [OP_LAYOUTRETURN] = {
  2004. .op_func = (nfsd4op_func)nfsd4_layoutreturn,
  2005. .op_flags = OP_MODIFIES_SOMETHING,
  2006. .op_name = "OP_LAYOUTRETURN",
  2007. .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize,
  2008. },
  2009. #endif /* CONFIG_NFSD_PNFS */
  2010. /* NFSv4.2 operations */
  2011. [OP_ALLOCATE] = {
  2012. .op_func = (nfsd4op_func)nfsd4_allocate,
  2013. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2014. .op_name = "OP_ALLOCATE",
  2015. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2016. },
  2017. [OP_DEALLOCATE] = {
  2018. .op_func = (nfsd4op_func)nfsd4_deallocate,
  2019. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2020. .op_name = "OP_DEALLOCATE",
  2021. .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
  2022. },
  2023. [OP_SEEK] = {
  2024. .op_func = (nfsd4op_func)nfsd4_seek,
  2025. .op_name = "OP_SEEK",
  2026. },
  2027. };
  2028. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
  2029. {
  2030. struct nfsd4_operation *opdesc;
  2031. nfsd4op_rsize estimator;
  2032. if (op->opnum == OP_ILLEGAL)
  2033. return op_encode_hdr_size * sizeof(__be32);
  2034. opdesc = OPDESC(op);
  2035. estimator = opdesc->op_rsize_bop;
  2036. return estimator ? estimator(rqstp, op) : PAGE_SIZE;
  2037. }
  2038. void warn_on_nonidempotent_op(struct nfsd4_op *op)
  2039. {
  2040. if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
  2041. pr_err("unable to encode reply to nonidempotent op %d (%s)\n",
  2042. op->opnum, nfsd4_op_name(op->opnum));
  2043. WARN_ON_ONCE(1);
  2044. }
  2045. }
  2046. static const char *nfsd4_op_name(unsigned opnum)
  2047. {
  2048. if (opnum < ARRAY_SIZE(nfsd4_ops))
  2049. return nfsd4_ops[opnum].op_name;
  2050. return "unknown_operation";
  2051. }
  2052. #define nfsd4_voidres nfsd4_voidargs
  2053. struct nfsd4_voidargs { int dummy; };
  2054. static struct svc_procedure nfsd_procedures4[2] = {
  2055. [NFSPROC4_NULL] = {
  2056. .pc_func = (svc_procfunc) nfsd4_proc_null,
  2057. .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
  2058. .pc_argsize = sizeof(struct nfsd4_voidargs),
  2059. .pc_ressize = sizeof(struct nfsd4_voidres),
  2060. .pc_cachetype = RC_NOCACHE,
  2061. .pc_xdrressize = 1,
  2062. },
  2063. [NFSPROC4_COMPOUND] = {
  2064. .pc_func = (svc_procfunc) nfsd4_proc_compound,
  2065. .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
  2066. .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
  2067. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  2068. .pc_ressize = sizeof(struct nfsd4_compoundres),
  2069. .pc_release = nfsd4_release_compoundargs,
  2070. .pc_cachetype = RC_NOCACHE,
  2071. .pc_xdrressize = NFSD_BUFSIZE/4,
  2072. },
  2073. };
  2074. struct svc_version nfsd_version4 = {
  2075. .vs_vers = 4,
  2076. .vs_nproc = 2,
  2077. .vs_proc = nfsd_procedures4,
  2078. .vs_dispatch = nfsd_dispatch,
  2079. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  2080. .vs_rpcb_optnl = 1,
  2081. };
  2082. /*
  2083. * Local variables:
  2084. * c-basic-offset: 8
  2085. * End:
  2086. */