nfs4proc.c 66 KB

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