nfs4xdr.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334
  1. /*
  2. * Server-side XDR 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. * TODO: Neil Brown made the following observation: We currently
  36. * initially reserve NFSD_BUFSIZE space on the transmit queue and
  37. * never release any of that until the request is complete.
  38. * It would be good to calculate a new maximum response size while
  39. * decoding the COMPOUND, and call svc_reserve with this number
  40. * at the end of nfs4svc_decode_compoundargs.
  41. */
  42. #include <linux/param.h>
  43. #include <linux/smp.h>
  44. #include <linux/fs.h>
  45. #include <linux/namei.h>
  46. #include <linux/vfs.h>
  47. #include <linux/utsname.h>
  48. #include <linux/sunrpc/xdr.h>
  49. #include <linux/sunrpc/svc.h>
  50. #include <linux/sunrpc/clnt.h>
  51. #include <linux/nfsd/nfsd.h>
  52. #include <linux/nfsd/state.h>
  53. #include <linux/nfsd/xdr4.h>
  54. #include <linux/nfsd_idmap.h>
  55. #include <linux/nfs4.h>
  56. #include <linux/nfs4_acl.h>
  57. #include <linux/sunrpc/gss_api.h>
  58. #include <linux/sunrpc/svcauth_gss.h>
  59. #define NFSDDBG_FACILITY NFSDDBG_XDR
  60. /*
  61. * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
  62. * directory in order to indicate to the client that a filesystem boundary is present
  63. * We use a fixed fsid for a referral
  64. */
  65. #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
  66. #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
  67. static __be32
  68. check_filename(char *str, int len, __be32 err)
  69. {
  70. int i;
  71. if (len == 0)
  72. return nfserr_inval;
  73. if (isdotent(str, len))
  74. return err;
  75. for (i = 0; i < len; i++)
  76. if (str[i] == '/')
  77. return err;
  78. return 0;
  79. }
  80. #define DECODE_HEAD \
  81. __be32 *p; \
  82. __be32 status
  83. #define DECODE_TAIL \
  84. status = 0; \
  85. out: \
  86. return status; \
  87. xdr_error: \
  88. dprintk("NFSD: xdr error (%s:%d)\n", \
  89. __FILE__, __LINE__); \
  90. status = nfserr_bad_xdr; \
  91. goto out
  92. #define READ32(x) (x) = ntohl(*p++)
  93. #define READ64(x) do { \
  94. (x) = (u64)ntohl(*p++) << 32; \
  95. (x) |= ntohl(*p++); \
  96. } while (0)
  97. #define READTIME(x) do { \
  98. p++; \
  99. (x) = ntohl(*p++); \
  100. p++; \
  101. } while (0)
  102. #define READMEM(x,nbytes) do { \
  103. x = (char *)p; \
  104. p += XDR_QUADLEN(nbytes); \
  105. } while (0)
  106. #define SAVEMEM(x,nbytes) do { \
  107. if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
  108. savemem(argp, p, nbytes) : \
  109. (char *)p)) { \
  110. dprintk("NFSD: xdr error (%s:%d)\n", \
  111. __FILE__, __LINE__); \
  112. goto xdr_error; \
  113. } \
  114. p += XDR_QUADLEN(nbytes); \
  115. } while (0)
  116. #define COPYMEM(x,nbytes) do { \
  117. memcpy((x), p, nbytes); \
  118. p += XDR_QUADLEN(nbytes); \
  119. } while (0)
  120. /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
  121. #define READ_BUF(nbytes) do { \
  122. if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
  123. p = argp->p; \
  124. argp->p += XDR_QUADLEN(nbytes); \
  125. } else if (!(p = read_buf(argp, nbytes))) { \
  126. dprintk("NFSD: xdr error (%s:%d)\n", \
  127. __FILE__, __LINE__); \
  128. goto xdr_error; \
  129. } \
  130. } while (0)
  131. static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
  132. {
  133. /* We want more bytes than seem to be available.
  134. * Maybe we need a new page, maybe we have just run out
  135. */
  136. unsigned int avail = (char *)argp->end - (char *)argp->p;
  137. __be32 *p;
  138. if (avail + argp->pagelen < nbytes)
  139. return NULL;
  140. if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */
  141. return NULL;
  142. /* ok, we can do it with the current plus the next page */
  143. if (nbytes <= sizeof(argp->tmp))
  144. p = argp->tmp;
  145. else {
  146. kfree(argp->tmpp);
  147. p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
  148. if (!p)
  149. return NULL;
  150. }
  151. /*
  152. * The following memcpy is safe because read_buf is always
  153. * called with nbytes > avail, and the two cases above both
  154. * guarantee p points to at least nbytes bytes.
  155. */
  156. memcpy(p, argp->p, avail);
  157. /* step to next page */
  158. argp->p = page_address(argp->pagelist[0]);
  159. argp->pagelist++;
  160. if (argp->pagelen < PAGE_SIZE) {
  161. argp->end = p + (argp->pagelen>>2);
  162. argp->pagelen = 0;
  163. } else {
  164. argp->end = p + (PAGE_SIZE>>2);
  165. argp->pagelen -= PAGE_SIZE;
  166. }
  167. memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
  168. argp->p += XDR_QUADLEN(nbytes - avail);
  169. return p;
  170. }
  171. static int zero_clientid(clientid_t *clid)
  172. {
  173. return (clid->cl_boot == 0) && (clid->cl_id == 0);
  174. }
  175. static int
  176. defer_free(struct nfsd4_compoundargs *argp,
  177. void (*release)(const void *), void *p)
  178. {
  179. struct tmpbuf *tb;
  180. tb = kmalloc(sizeof(*tb), GFP_KERNEL);
  181. if (!tb)
  182. return -ENOMEM;
  183. tb->buf = p;
  184. tb->release = release;
  185. tb->next = argp->to_free;
  186. argp->to_free = tb;
  187. return 0;
  188. }
  189. static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
  190. {
  191. if (p == argp->tmp) {
  192. p = kmalloc(nbytes, GFP_KERNEL);
  193. if (!p)
  194. return NULL;
  195. memcpy(p, argp->tmp, nbytes);
  196. } else {
  197. BUG_ON(p != argp->tmpp);
  198. argp->tmpp = NULL;
  199. }
  200. if (defer_free(argp, kfree, p)) {
  201. kfree(p);
  202. return NULL;
  203. } else
  204. return (char *)p;
  205. }
  206. static __be32
  207. nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
  208. {
  209. u32 bmlen;
  210. DECODE_HEAD;
  211. bmval[0] = 0;
  212. bmval[1] = 0;
  213. bmval[2] = 0;
  214. READ_BUF(4);
  215. READ32(bmlen);
  216. if (bmlen > 1000)
  217. goto xdr_error;
  218. READ_BUF(bmlen << 2);
  219. if (bmlen > 0)
  220. READ32(bmval[0]);
  221. if (bmlen > 1)
  222. READ32(bmval[1]);
  223. if (bmlen > 2)
  224. READ32(bmval[2]);
  225. DECODE_TAIL;
  226. }
  227. static u32 nfsd_attrmask[] = {
  228. NFSD_WRITEABLE_ATTRS_WORD0,
  229. NFSD_WRITEABLE_ATTRS_WORD1,
  230. NFSD_WRITEABLE_ATTRS_WORD2
  231. };
  232. static u32 nfsd41_ex_attrmask[] = {
  233. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  234. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  235. NFSD_SUPPATTR_EXCLCREAT_WORD2
  236. };
  237. static __be32
  238. nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, u32 *writable,
  239. struct iattr *iattr, struct nfs4_acl **acl)
  240. {
  241. int expected_len, len = 0;
  242. u32 dummy32;
  243. char *buf;
  244. int host_err;
  245. DECODE_HEAD;
  246. iattr->ia_valid = 0;
  247. if ((status = nfsd4_decode_bitmap(argp, bmval)))
  248. return status;
  249. /*
  250. * According to spec, unsupported attributes return ERR_ATTRNOTSUPP;
  251. * read-only attributes return ERR_INVAL.
  252. */
  253. if ((bmval[0] & ~nfsd_suppattrs0(argp->minorversion)) ||
  254. (bmval[1] & ~nfsd_suppattrs1(argp->minorversion)) ||
  255. (bmval[2] & ~nfsd_suppattrs2(argp->minorversion)))
  256. return nfserr_attrnotsupp;
  257. if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
  258. (bmval[2] & ~writable[2]))
  259. return nfserr_inval;
  260. READ_BUF(4);
  261. READ32(expected_len);
  262. if (bmval[0] & FATTR4_WORD0_SIZE) {
  263. READ_BUF(8);
  264. len += 8;
  265. READ64(iattr->ia_size);
  266. iattr->ia_valid |= ATTR_SIZE;
  267. }
  268. if (bmval[0] & FATTR4_WORD0_ACL) {
  269. int nace;
  270. struct nfs4_ace *ace;
  271. READ_BUF(4); len += 4;
  272. READ32(nace);
  273. if (nace > NFS4_ACL_MAX)
  274. return nfserr_resource;
  275. *acl = nfs4_acl_new(nace);
  276. if (*acl == NULL) {
  277. host_err = -ENOMEM;
  278. goto out_nfserr;
  279. }
  280. defer_free(argp, kfree, *acl);
  281. (*acl)->naces = nace;
  282. for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
  283. READ_BUF(16); len += 16;
  284. READ32(ace->type);
  285. READ32(ace->flag);
  286. READ32(ace->access_mask);
  287. READ32(dummy32);
  288. READ_BUF(dummy32);
  289. len += XDR_QUADLEN(dummy32) << 2;
  290. READMEM(buf, dummy32);
  291. ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
  292. host_err = 0;
  293. if (ace->whotype != NFS4_ACL_WHO_NAMED)
  294. ace->who = 0;
  295. else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
  296. host_err = nfsd_map_name_to_gid(argp->rqstp,
  297. buf, dummy32, &ace->who);
  298. else
  299. host_err = nfsd_map_name_to_uid(argp->rqstp,
  300. buf, dummy32, &ace->who);
  301. if (host_err)
  302. goto out_nfserr;
  303. }
  304. } else
  305. *acl = NULL;
  306. if (bmval[1] & FATTR4_WORD1_MODE) {
  307. READ_BUF(4);
  308. len += 4;
  309. READ32(iattr->ia_mode);
  310. iattr->ia_mode &= (S_IFMT | S_IALLUGO);
  311. iattr->ia_valid |= ATTR_MODE;
  312. }
  313. if (bmval[1] & FATTR4_WORD1_OWNER) {
  314. READ_BUF(4);
  315. len += 4;
  316. READ32(dummy32);
  317. READ_BUF(dummy32);
  318. len += (XDR_QUADLEN(dummy32) << 2);
  319. READMEM(buf, dummy32);
  320. if ((host_err = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
  321. goto out_nfserr;
  322. iattr->ia_valid |= ATTR_UID;
  323. }
  324. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
  325. READ_BUF(4);
  326. len += 4;
  327. READ32(dummy32);
  328. READ_BUF(dummy32);
  329. len += (XDR_QUADLEN(dummy32) << 2);
  330. READMEM(buf, dummy32);
  331. if ((host_err = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
  332. goto out_nfserr;
  333. iattr->ia_valid |= ATTR_GID;
  334. }
  335. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  336. READ_BUF(4);
  337. len += 4;
  338. READ32(dummy32);
  339. switch (dummy32) {
  340. case NFS4_SET_TO_CLIENT_TIME:
  341. /* We require the high 32 bits of 'seconds' to be 0, and we ignore
  342. all 32 bits of 'nseconds'. */
  343. READ_BUF(12);
  344. len += 12;
  345. READ32(dummy32);
  346. if (dummy32)
  347. return nfserr_inval;
  348. READ32(iattr->ia_atime.tv_sec);
  349. READ32(iattr->ia_atime.tv_nsec);
  350. if (iattr->ia_atime.tv_nsec >= (u32)1000000000)
  351. return nfserr_inval;
  352. iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
  353. break;
  354. case NFS4_SET_TO_SERVER_TIME:
  355. iattr->ia_valid |= ATTR_ATIME;
  356. break;
  357. default:
  358. goto xdr_error;
  359. }
  360. }
  361. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  362. READ_BUF(4);
  363. len += 4;
  364. READ32(dummy32);
  365. switch (dummy32) {
  366. case NFS4_SET_TO_CLIENT_TIME:
  367. /* We require the high 32 bits of 'seconds' to be 0, and we ignore
  368. all 32 bits of 'nseconds'. */
  369. READ_BUF(12);
  370. len += 12;
  371. READ32(dummy32);
  372. if (dummy32)
  373. return nfserr_inval;
  374. READ32(iattr->ia_mtime.tv_sec);
  375. READ32(iattr->ia_mtime.tv_nsec);
  376. if (iattr->ia_mtime.tv_nsec >= (u32)1000000000)
  377. return nfserr_inval;
  378. iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
  379. break;
  380. case NFS4_SET_TO_SERVER_TIME:
  381. iattr->ia_valid |= ATTR_MTIME;
  382. break;
  383. default:
  384. goto xdr_error;
  385. }
  386. }
  387. BUG_ON(bmval[2]); /* no such writeable attr supported yet */
  388. if (len != expected_len)
  389. goto xdr_error;
  390. DECODE_TAIL;
  391. out_nfserr:
  392. status = nfserrno(host_err);
  393. goto out;
  394. }
  395. static __be32
  396. nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
  397. {
  398. DECODE_HEAD;
  399. READ_BUF(sizeof(stateid_t));
  400. READ32(sid->si_generation);
  401. COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
  402. DECODE_TAIL;
  403. }
  404. static __be32
  405. nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
  406. {
  407. DECODE_HEAD;
  408. READ_BUF(4);
  409. READ32(access->ac_req_access);
  410. DECODE_TAIL;
  411. }
  412. static __be32
  413. nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
  414. {
  415. DECODE_HEAD;
  416. close->cl_stateowner = NULL;
  417. READ_BUF(4);
  418. READ32(close->cl_seqid);
  419. return nfsd4_decode_stateid(argp, &close->cl_stateid);
  420. DECODE_TAIL;
  421. }
  422. static __be32
  423. nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
  424. {
  425. DECODE_HEAD;
  426. READ_BUF(12);
  427. READ64(commit->co_offset);
  428. READ32(commit->co_count);
  429. DECODE_TAIL;
  430. }
  431. static __be32
  432. nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
  433. {
  434. DECODE_HEAD;
  435. READ_BUF(4);
  436. READ32(create->cr_type);
  437. switch (create->cr_type) {
  438. case NF4LNK:
  439. READ_BUF(4);
  440. READ32(create->cr_linklen);
  441. READ_BUF(create->cr_linklen);
  442. SAVEMEM(create->cr_linkname, create->cr_linklen);
  443. break;
  444. case NF4BLK:
  445. case NF4CHR:
  446. READ_BUF(8);
  447. READ32(create->cr_specdata1);
  448. READ32(create->cr_specdata2);
  449. break;
  450. case NF4SOCK:
  451. case NF4FIFO:
  452. case NF4DIR:
  453. default:
  454. break;
  455. }
  456. READ_BUF(4);
  457. READ32(create->cr_namelen);
  458. READ_BUF(create->cr_namelen);
  459. SAVEMEM(create->cr_name, create->cr_namelen);
  460. if ((status = check_filename(create->cr_name, create->cr_namelen, nfserr_inval)))
  461. return status;
  462. status = nfsd4_decode_fattr(argp, create->cr_bmval, nfsd_attrmask,
  463. &create->cr_iattr, &create->cr_acl);
  464. if (status)
  465. goto out;
  466. DECODE_TAIL;
  467. }
  468. static inline __be32
  469. nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
  470. {
  471. return nfsd4_decode_stateid(argp, &dr->dr_stateid);
  472. }
  473. static inline __be32
  474. nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
  475. {
  476. return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
  477. }
  478. static __be32
  479. nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
  480. {
  481. DECODE_HEAD;
  482. READ_BUF(4);
  483. READ32(link->li_namelen);
  484. READ_BUF(link->li_namelen);
  485. SAVEMEM(link->li_name, link->li_namelen);
  486. if ((status = check_filename(link->li_name, link->li_namelen, nfserr_inval)))
  487. return status;
  488. DECODE_TAIL;
  489. }
  490. static __be32
  491. nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
  492. {
  493. DECODE_HEAD;
  494. lock->lk_replay_owner = NULL;
  495. /*
  496. * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
  497. */
  498. READ_BUF(28);
  499. READ32(lock->lk_type);
  500. if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
  501. goto xdr_error;
  502. READ32(lock->lk_reclaim);
  503. READ64(lock->lk_offset);
  504. READ64(lock->lk_length);
  505. READ32(lock->lk_is_new);
  506. if (lock->lk_is_new) {
  507. READ_BUF(4);
  508. READ32(lock->lk_new_open_seqid);
  509. status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
  510. if (status)
  511. return status;
  512. READ_BUF(8 + sizeof(clientid_t));
  513. READ32(lock->lk_new_lock_seqid);
  514. COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
  515. READ32(lock->lk_new_owner.len);
  516. READ_BUF(lock->lk_new_owner.len);
  517. READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
  518. } else {
  519. status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
  520. if (status)
  521. return status;
  522. READ_BUF(4);
  523. READ32(lock->lk_old_lock_seqid);
  524. }
  525. DECODE_TAIL;
  526. }
  527. static __be32
  528. nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
  529. {
  530. DECODE_HEAD;
  531. READ_BUF(32);
  532. READ32(lockt->lt_type);
  533. if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
  534. goto xdr_error;
  535. READ64(lockt->lt_offset);
  536. READ64(lockt->lt_length);
  537. COPYMEM(&lockt->lt_clientid, 8);
  538. READ32(lockt->lt_owner.len);
  539. READ_BUF(lockt->lt_owner.len);
  540. READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
  541. if (argp->minorversion && !zero_clientid(&lockt->lt_clientid))
  542. return nfserr_inval;
  543. DECODE_TAIL;
  544. }
  545. static __be32
  546. nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
  547. {
  548. DECODE_HEAD;
  549. locku->lu_stateowner = NULL;
  550. READ_BUF(8);
  551. READ32(locku->lu_type);
  552. if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
  553. goto xdr_error;
  554. READ32(locku->lu_seqid);
  555. status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
  556. if (status)
  557. return status;
  558. READ_BUF(16);
  559. READ64(locku->lu_offset);
  560. READ64(locku->lu_length);
  561. DECODE_TAIL;
  562. }
  563. static __be32
  564. nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
  565. {
  566. DECODE_HEAD;
  567. READ_BUF(4);
  568. READ32(lookup->lo_len);
  569. READ_BUF(lookup->lo_len);
  570. SAVEMEM(lookup->lo_name, lookup->lo_len);
  571. if ((status = check_filename(lookup->lo_name, lookup->lo_len, nfserr_noent)))
  572. return status;
  573. DECODE_TAIL;
  574. }
  575. static __be32
  576. nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
  577. {
  578. DECODE_HEAD;
  579. memset(open->op_bmval, 0, sizeof(open->op_bmval));
  580. open->op_iattr.ia_valid = 0;
  581. open->op_stateowner = NULL;
  582. /* seqid, share_access, share_deny, clientid, ownerlen */
  583. READ_BUF(16 + sizeof(clientid_t));
  584. READ32(open->op_seqid);
  585. READ32(open->op_share_access);
  586. READ32(open->op_share_deny);
  587. COPYMEM(&open->op_clientid, sizeof(clientid_t));
  588. READ32(open->op_owner.len);
  589. /* owner, open_flag */
  590. READ_BUF(open->op_owner.len + 4);
  591. SAVEMEM(open->op_owner.data, open->op_owner.len);
  592. READ32(open->op_create);
  593. switch (open->op_create) {
  594. case NFS4_OPEN_NOCREATE:
  595. break;
  596. case NFS4_OPEN_CREATE:
  597. READ_BUF(4);
  598. READ32(open->op_createmode);
  599. switch (open->op_createmode) {
  600. case NFS4_CREATE_UNCHECKED:
  601. case NFS4_CREATE_GUARDED:
  602. status = nfsd4_decode_fattr(argp, open->op_bmval,
  603. nfsd_attrmask, &open->op_iattr, &open->op_acl);
  604. if (status)
  605. goto out;
  606. break;
  607. case NFS4_CREATE_EXCLUSIVE:
  608. READ_BUF(8);
  609. COPYMEM(open->op_verf.data, 8);
  610. break;
  611. case NFS4_CREATE_EXCLUSIVE4_1:
  612. if (argp->minorversion < 1)
  613. goto xdr_error;
  614. READ_BUF(8);
  615. COPYMEM(open->op_verf.data, 8);
  616. status = nfsd4_decode_fattr(argp, open->op_bmval,
  617. nfsd41_ex_attrmask, &open->op_iattr,
  618. &open->op_acl);
  619. if (status)
  620. goto out;
  621. break;
  622. default:
  623. goto xdr_error;
  624. }
  625. break;
  626. default:
  627. goto xdr_error;
  628. }
  629. /* open_claim */
  630. READ_BUF(4);
  631. READ32(open->op_claim_type);
  632. switch (open->op_claim_type) {
  633. case NFS4_OPEN_CLAIM_NULL:
  634. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  635. READ_BUF(4);
  636. READ32(open->op_fname.len);
  637. READ_BUF(open->op_fname.len);
  638. SAVEMEM(open->op_fname.data, open->op_fname.len);
  639. if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval)))
  640. return status;
  641. break;
  642. case NFS4_OPEN_CLAIM_PREVIOUS:
  643. READ_BUF(4);
  644. READ32(open->op_delegate_type);
  645. break;
  646. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  647. status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
  648. if (status)
  649. return status;
  650. READ_BUF(4);
  651. READ32(open->op_fname.len);
  652. READ_BUF(open->op_fname.len);
  653. SAVEMEM(open->op_fname.data, open->op_fname.len);
  654. if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval)))
  655. return status;
  656. break;
  657. default:
  658. goto xdr_error;
  659. }
  660. DECODE_TAIL;
  661. }
  662. static __be32
  663. nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
  664. {
  665. DECODE_HEAD;
  666. open_conf->oc_stateowner = NULL;
  667. status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
  668. if (status)
  669. return status;
  670. READ_BUF(4);
  671. READ32(open_conf->oc_seqid);
  672. DECODE_TAIL;
  673. }
  674. static __be32
  675. nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
  676. {
  677. DECODE_HEAD;
  678. open_down->od_stateowner = NULL;
  679. status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
  680. if (status)
  681. return status;
  682. READ_BUF(12);
  683. READ32(open_down->od_seqid);
  684. READ32(open_down->od_share_access);
  685. READ32(open_down->od_share_deny);
  686. DECODE_TAIL;
  687. }
  688. static __be32
  689. nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
  690. {
  691. DECODE_HEAD;
  692. READ_BUF(4);
  693. READ32(putfh->pf_fhlen);
  694. if (putfh->pf_fhlen > NFS4_FHSIZE)
  695. goto xdr_error;
  696. READ_BUF(putfh->pf_fhlen);
  697. SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
  698. DECODE_TAIL;
  699. }
  700. static __be32
  701. nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
  702. {
  703. DECODE_HEAD;
  704. status = nfsd4_decode_stateid(argp, &read->rd_stateid);
  705. if (status)
  706. return status;
  707. READ_BUF(12);
  708. READ64(read->rd_offset);
  709. READ32(read->rd_length);
  710. DECODE_TAIL;
  711. }
  712. static __be32
  713. nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
  714. {
  715. DECODE_HEAD;
  716. READ_BUF(24);
  717. READ64(readdir->rd_cookie);
  718. COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
  719. READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
  720. READ32(readdir->rd_maxcount);
  721. if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
  722. goto out;
  723. DECODE_TAIL;
  724. }
  725. static __be32
  726. nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
  727. {
  728. DECODE_HEAD;
  729. READ_BUF(4);
  730. READ32(remove->rm_namelen);
  731. READ_BUF(remove->rm_namelen);
  732. SAVEMEM(remove->rm_name, remove->rm_namelen);
  733. if ((status = check_filename(remove->rm_name, remove->rm_namelen, nfserr_noent)))
  734. return status;
  735. DECODE_TAIL;
  736. }
  737. static __be32
  738. nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
  739. {
  740. DECODE_HEAD;
  741. READ_BUF(4);
  742. READ32(rename->rn_snamelen);
  743. READ_BUF(rename->rn_snamelen + 4);
  744. SAVEMEM(rename->rn_sname, rename->rn_snamelen);
  745. READ32(rename->rn_tnamelen);
  746. READ_BUF(rename->rn_tnamelen);
  747. SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
  748. if ((status = check_filename(rename->rn_sname, rename->rn_snamelen, nfserr_noent)))
  749. return status;
  750. if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen, nfserr_inval)))
  751. return status;
  752. DECODE_TAIL;
  753. }
  754. static __be32
  755. nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
  756. {
  757. DECODE_HEAD;
  758. READ_BUF(sizeof(clientid_t));
  759. COPYMEM(clientid, sizeof(clientid_t));
  760. DECODE_TAIL;
  761. }
  762. static __be32
  763. nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
  764. struct nfsd4_secinfo *secinfo)
  765. {
  766. DECODE_HEAD;
  767. READ_BUF(4);
  768. READ32(secinfo->si_namelen);
  769. READ_BUF(secinfo->si_namelen);
  770. SAVEMEM(secinfo->si_name, secinfo->si_namelen);
  771. status = check_filename(secinfo->si_name, secinfo->si_namelen,
  772. nfserr_noent);
  773. if (status)
  774. return status;
  775. DECODE_TAIL;
  776. }
  777. static __be32
  778. nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
  779. {
  780. __be32 status;
  781. status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
  782. if (status)
  783. return status;
  784. return nfsd4_decode_fattr(argp, setattr->sa_bmval, nfsd_attrmask,
  785. &setattr->sa_iattr, &setattr->sa_acl);
  786. }
  787. static __be32
  788. nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
  789. {
  790. DECODE_HEAD;
  791. READ_BUF(12);
  792. COPYMEM(setclientid->se_verf.data, 8);
  793. READ32(setclientid->se_namelen);
  794. READ_BUF(setclientid->se_namelen + 8);
  795. SAVEMEM(setclientid->se_name, setclientid->se_namelen);
  796. READ32(setclientid->se_callback_prog);
  797. READ32(setclientid->se_callback_netid_len);
  798. READ_BUF(setclientid->se_callback_netid_len + 4);
  799. SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
  800. READ32(setclientid->se_callback_addr_len);
  801. READ_BUF(setclientid->se_callback_addr_len + 4);
  802. SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
  803. READ32(setclientid->se_callback_ident);
  804. DECODE_TAIL;
  805. }
  806. static __be32
  807. nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
  808. {
  809. DECODE_HEAD;
  810. READ_BUF(8 + sizeof(nfs4_verifier));
  811. COPYMEM(&scd_c->sc_clientid, 8);
  812. COPYMEM(&scd_c->sc_confirm, sizeof(nfs4_verifier));
  813. DECODE_TAIL;
  814. }
  815. /* Also used for NVERIFY */
  816. static __be32
  817. nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
  818. {
  819. #if 0
  820. struct nfsd4_compoundargs save = {
  821. .p = argp->p,
  822. .end = argp->end,
  823. .rqstp = argp->rqstp,
  824. };
  825. u32 ve_bmval[2];
  826. struct iattr ve_iattr; /* request */
  827. struct nfs4_acl *ve_acl; /* request */
  828. #endif
  829. DECODE_HEAD;
  830. if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
  831. goto out;
  832. /* For convenience's sake, we compare raw xdr'd attributes in
  833. * nfsd4_proc_verify; however we still decode here just to return
  834. * correct error in case of bad xdr. */
  835. #if 0
  836. status = nfsd4_decode_fattr(ve_bmval, &ve_iattr, &ve_acl);
  837. if (status == nfserr_inval) {
  838. status = nfserrno(status);
  839. goto out;
  840. }
  841. #endif
  842. READ_BUF(4);
  843. READ32(verify->ve_attrlen);
  844. READ_BUF(verify->ve_attrlen);
  845. SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
  846. DECODE_TAIL;
  847. }
  848. static __be32
  849. nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
  850. {
  851. int avail;
  852. int v;
  853. int len;
  854. DECODE_HEAD;
  855. status = nfsd4_decode_stateid(argp, &write->wr_stateid);
  856. if (status)
  857. return status;
  858. READ_BUF(16);
  859. READ64(write->wr_offset);
  860. READ32(write->wr_stable_how);
  861. if (write->wr_stable_how > 2)
  862. goto xdr_error;
  863. READ32(write->wr_buflen);
  864. /* Sorry .. no magic macros for this.. *
  865. * READ_BUF(write->wr_buflen);
  866. * SAVEMEM(write->wr_buf, write->wr_buflen);
  867. */
  868. avail = (char*)argp->end - (char*)argp->p;
  869. if (avail + argp->pagelen < write->wr_buflen) {
  870. dprintk("NFSD: xdr error (%s:%d)\n",
  871. __FILE__, __LINE__);
  872. goto xdr_error;
  873. }
  874. argp->rqstp->rq_vec[0].iov_base = p;
  875. argp->rqstp->rq_vec[0].iov_len = avail;
  876. v = 0;
  877. len = write->wr_buflen;
  878. while (len > argp->rqstp->rq_vec[v].iov_len) {
  879. len -= argp->rqstp->rq_vec[v].iov_len;
  880. v++;
  881. argp->rqstp->rq_vec[v].iov_base = page_address(argp->pagelist[0]);
  882. argp->pagelist++;
  883. if (argp->pagelen >= PAGE_SIZE) {
  884. argp->rqstp->rq_vec[v].iov_len = PAGE_SIZE;
  885. argp->pagelen -= PAGE_SIZE;
  886. } else {
  887. argp->rqstp->rq_vec[v].iov_len = argp->pagelen;
  888. argp->pagelen -= len;
  889. }
  890. }
  891. argp->end = (__be32*) (argp->rqstp->rq_vec[v].iov_base + argp->rqstp->rq_vec[v].iov_len);
  892. argp->p = (__be32*) (argp->rqstp->rq_vec[v].iov_base + (XDR_QUADLEN(len) << 2));
  893. argp->rqstp->rq_vec[v].iov_len = len;
  894. write->wr_vlen = v+1;
  895. DECODE_TAIL;
  896. }
  897. static __be32
  898. nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
  899. {
  900. DECODE_HEAD;
  901. READ_BUF(12);
  902. COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
  903. READ32(rlockowner->rl_owner.len);
  904. READ_BUF(rlockowner->rl_owner.len);
  905. READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
  906. if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
  907. return nfserr_inval;
  908. DECODE_TAIL;
  909. }
  910. static __be32
  911. nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
  912. struct nfsd4_exchange_id *exid)
  913. {
  914. int dummy;
  915. DECODE_HEAD;
  916. READ_BUF(NFS4_VERIFIER_SIZE);
  917. COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
  918. READ_BUF(4);
  919. READ32(exid->clname.len);
  920. READ_BUF(exid->clname.len);
  921. SAVEMEM(exid->clname.data, exid->clname.len);
  922. READ_BUF(4);
  923. READ32(exid->flags);
  924. /* Ignore state_protect4_a */
  925. READ_BUF(4);
  926. READ32(exid->spa_how);
  927. switch (exid->spa_how) {
  928. case SP4_NONE:
  929. break;
  930. case SP4_MACH_CRED:
  931. /* spo_must_enforce */
  932. READ_BUF(4);
  933. READ32(dummy);
  934. READ_BUF(dummy * 4);
  935. p += dummy;
  936. /* spo_must_allow */
  937. READ_BUF(4);
  938. READ32(dummy);
  939. READ_BUF(dummy * 4);
  940. p += dummy;
  941. break;
  942. case SP4_SSV:
  943. /* ssp_ops */
  944. READ_BUF(4);
  945. READ32(dummy);
  946. READ_BUF(dummy * 4);
  947. p += dummy;
  948. READ_BUF(4);
  949. READ32(dummy);
  950. READ_BUF(dummy * 4);
  951. p += dummy;
  952. /* ssp_hash_algs<> */
  953. READ_BUF(4);
  954. READ32(dummy);
  955. READ_BUF(dummy);
  956. p += XDR_QUADLEN(dummy);
  957. /* ssp_encr_algs<> */
  958. READ_BUF(4);
  959. READ32(dummy);
  960. READ_BUF(dummy);
  961. p += XDR_QUADLEN(dummy);
  962. /* ssp_window and ssp_num_gss_handles */
  963. READ_BUF(8);
  964. READ32(dummy);
  965. READ32(dummy);
  966. break;
  967. default:
  968. goto xdr_error;
  969. }
  970. /* Ignore Implementation ID */
  971. READ_BUF(4); /* nfs_impl_id4 array length */
  972. READ32(dummy);
  973. if (dummy > 1)
  974. goto xdr_error;
  975. if (dummy == 1) {
  976. /* nii_domain */
  977. READ_BUF(4);
  978. READ32(dummy);
  979. READ_BUF(dummy);
  980. p += XDR_QUADLEN(dummy);
  981. /* nii_name */
  982. READ_BUF(4);
  983. READ32(dummy);
  984. READ_BUF(dummy);
  985. p += XDR_QUADLEN(dummy);
  986. /* nii_date */
  987. READ_BUF(12);
  988. p += 3;
  989. }
  990. DECODE_TAIL;
  991. }
  992. static __be32
  993. nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
  994. struct nfsd4_create_session *sess)
  995. {
  996. DECODE_HEAD;
  997. u32 dummy;
  998. char *machine_name;
  999. int i;
  1000. int nr_secflavs;
  1001. READ_BUF(16);
  1002. COPYMEM(&sess->clientid, 8);
  1003. READ32(sess->seqid);
  1004. READ32(sess->flags);
  1005. /* Fore channel attrs */
  1006. READ_BUF(28);
  1007. READ32(dummy); /* headerpadsz is always 0 */
  1008. READ32(sess->fore_channel.maxreq_sz);
  1009. READ32(sess->fore_channel.maxresp_sz);
  1010. READ32(sess->fore_channel.maxresp_cached);
  1011. READ32(sess->fore_channel.maxops);
  1012. READ32(sess->fore_channel.maxreqs);
  1013. READ32(sess->fore_channel.nr_rdma_attrs);
  1014. if (sess->fore_channel.nr_rdma_attrs == 1) {
  1015. READ_BUF(4);
  1016. READ32(sess->fore_channel.rdma_attrs);
  1017. } else if (sess->fore_channel.nr_rdma_attrs > 1) {
  1018. dprintk("Too many fore channel attr bitmaps!\n");
  1019. goto xdr_error;
  1020. }
  1021. /* Back channel attrs */
  1022. READ_BUF(28);
  1023. READ32(dummy); /* headerpadsz is always 0 */
  1024. READ32(sess->back_channel.maxreq_sz);
  1025. READ32(sess->back_channel.maxresp_sz);
  1026. READ32(sess->back_channel.maxresp_cached);
  1027. READ32(sess->back_channel.maxops);
  1028. READ32(sess->back_channel.maxreqs);
  1029. READ32(sess->back_channel.nr_rdma_attrs);
  1030. if (sess->back_channel.nr_rdma_attrs == 1) {
  1031. READ_BUF(4);
  1032. READ32(sess->back_channel.rdma_attrs);
  1033. } else if (sess->back_channel.nr_rdma_attrs > 1) {
  1034. dprintk("Too many back channel attr bitmaps!\n");
  1035. goto xdr_error;
  1036. }
  1037. READ_BUF(8);
  1038. READ32(sess->callback_prog);
  1039. /* callback_sec_params4 */
  1040. READ32(nr_secflavs);
  1041. for (i = 0; i < nr_secflavs; ++i) {
  1042. READ_BUF(4);
  1043. READ32(dummy);
  1044. switch (dummy) {
  1045. case RPC_AUTH_NULL:
  1046. /* Nothing to read */
  1047. break;
  1048. case RPC_AUTH_UNIX:
  1049. READ_BUF(8);
  1050. /* stamp */
  1051. READ32(dummy);
  1052. /* machine name */
  1053. READ32(dummy);
  1054. READ_BUF(dummy);
  1055. SAVEMEM(machine_name, dummy);
  1056. /* uid, gid */
  1057. READ_BUF(8);
  1058. READ32(sess->uid);
  1059. READ32(sess->gid);
  1060. /* more gids */
  1061. READ_BUF(4);
  1062. READ32(dummy);
  1063. READ_BUF(dummy * 4);
  1064. for (i = 0; i < dummy; ++i)
  1065. READ32(dummy);
  1066. break;
  1067. case RPC_AUTH_GSS:
  1068. dprintk("RPC_AUTH_GSS callback secflavor "
  1069. "not supported!\n");
  1070. READ_BUF(8);
  1071. /* gcbp_service */
  1072. READ32(dummy);
  1073. /* gcbp_handle_from_server */
  1074. READ32(dummy);
  1075. READ_BUF(dummy);
  1076. p += XDR_QUADLEN(dummy);
  1077. /* gcbp_handle_from_client */
  1078. READ_BUF(4);
  1079. READ32(dummy);
  1080. READ_BUF(dummy);
  1081. p += XDR_QUADLEN(dummy);
  1082. break;
  1083. default:
  1084. dprintk("Illegal callback secflavor\n");
  1085. return nfserr_inval;
  1086. }
  1087. }
  1088. DECODE_TAIL;
  1089. }
  1090. static __be32
  1091. nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
  1092. struct nfsd4_destroy_session *destroy_session)
  1093. {
  1094. DECODE_HEAD;
  1095. READ_BUF(NFS4_MAX_SESSIONID_LEN);
  1096. COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1097. DECODE_TAIL;
  1098. }
  1099. static __be32
  1100. nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
  1101. struct nfsd4_sequence *seq)
  1102. {
  1103. DECODE_HEAD;
  1104. READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
  1105. COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1106. READ32(seq->seqid);
  1107. READ32(seq->slotid);
  1108. READ32(seq->maxslots);
  1109. READ32(seq->cachethis);
  1110. DECODE_TAIL;
  1111. }
  1112. static __be32
  1113. nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
  1114. {
  1115. return nfs_ok;
  1116. }
  1117. static __be32
  1118. nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
  1119. {
  1120. return nfserr_notsupp;
  1121. }
  1122. typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
  1123. static nfsd4_dec nfsd4_dec_ops[] = {
  1124. [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
  1125. [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
  1126. [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
  1127. [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
  1128. [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
  1129. [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
  1130. [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
  1131. [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
  1132. [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
  1133. [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
  1134. [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
  1135. [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
  1136. [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
  1137. [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
  1138. [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1139. [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
  1140. [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
  1141. [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
  1142. [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
  1143. [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
  1144. [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_noop,
  1145. [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
  1146. [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
  1147. [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
  1148. [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
  1149. [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
  1150. [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
  1151. [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
  1152. [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
  1153. [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
  1154. [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
  1155. [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
  1156. [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
  1157. [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
  1158. [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1159. [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
  1160. [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
  1161. };
  1162. static nfsd4_dec nfsd41_dec_ops[] = {
  1163. [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
  1164. [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
  1165. [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
  1166. [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
  1167. [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
  1168. [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
  1169. [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
  1170. [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
  1171. [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
  1172. [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
  1173. [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
  1174. [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
  1175. [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
  1176. [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
  1177. [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1178. [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
  1179. [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
  1180. [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_notsupp,
  1181. [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
  1182. [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
  1183. [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp,
  1184. [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
  1185. [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
  1186. [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
  1187. [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
  1188. [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
  1189. [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
  1190. [OP_RENEW] = (nfsd4_dec)nfsd4_decode_notsupp,
  1191. [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
  1192. [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
  1193. [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
  1194. [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
  1195. [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1196. [OP_SETCLIENTID_CONFIRM]= (nfsd4_dec)nfsd4_decode_notsupp,
  1197. [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1198. [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
  1199. [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_notsupp,
  1200. /* new operations for NFSv4.1 */
  1201. [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_notsupp,
  1202. [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_notsupp,
  1203. [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
  1204. [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
  1205. [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
  1206. [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1207. [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
  1208. [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
  1209. [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
  1210. [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
  1211. [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
  1212. [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
  1213. [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_notsupp,
  1214. [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
  1215. [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
  1216. [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1217. [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
  1218. [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1219. [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_notsupp,
  1220. };
  1221. struct nfsd4_minorversion_ops {
  1222. nfsd4_dec *decoders;
  1223. int nops;
  1224. };
  1225. static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
  1226. [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
  1227. [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
  1228. };
  1229. static __be32
  1230. nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
  1231. {
  1232. DECODE_HEAD;
  1233. struct nfsd4_op *op;
  1234. struct nfsd4_minorversion_ops *ops;
  1235. int i;
  1236. /*
  1237. * XXX: According to spec, we should check the tag
  1238. * for UTF-8 compliance. I'm postponing this for
  1239. * now because it seems that some clients do use
  1240. * binary tags.
  1241. */
  1242. READ_BUF(4);
  1243. READ32(argp->taglen);
  1244. READ_BUF(argp->taglen + 8);
  1245. SAVEMEM(argp->tag, argp->taglen);
  1246. READ32(argp->minorversion);
  1247. READ32(argp->opcnt);
  1248. if (argp->taglen > NFSD4_MAX_TAGLEN)
  1249. goto xdr_error;
  1250. if (argp->opcnt > 100)
  1251. goto xdr_error;
  1252. if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
  1253. argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
  1254. if (!argp->ops) {
  1255. argp->ops = argp->iops;
  1256. dprintk("nfsd: couldn't allocate room for COMPOUND\n");
  1257. goto xdr_error;
  1258. }
  1259. }
  1260. if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion))
  1261. argp->opcnt = 0;
  1262. ops = &nfsd4_minorversion[argp->minorversion];
  1263. for (i = 0; i < argp->opcnt; i++) {
  1264. op = &argp->ops[i];
  1265. op->replay = NULL;
  1266. /*
  1267. * We can't use READ_BUF() here because we need to handle
  1268. * a missing opcode as an OP_WRITE + 1. So we need to check
  1269. * to see if we're truly at the end of our buffer or if there
  1270. * is another page we need to flip to.
  1271. */
  1272. if (argp->p == argp->end) {
  1273. if (argp->pagelen < 4) {
  1274. /* There isn't an opcode still on the wire */
  1275. op->opnum = OP_WRITE + 1;
  1276. op->status = nfserr_bad_xdr;
  1277. argp->opcnt = i+1;
  1278. break;
  1279. }
  1280. /*
  1281. * False alarm. We just hit a page boundary, but there
  1282. * is still data available. Move pointer across page
  1283. * boundary. *snip from READ_BUF*
  1284. */
  1285. argp->p = page_address(argp->pagelist[0]);
  1286. argp->pagelist++;
  1287. if (argp->pagelen < PAGE_SIZE) {
  1288. argp->end = p + (argp->pagelen>>2);
  1289. argp->pagelen = 0;
  1290. } else {
  1291. argp->end = p + (PAGE_SIZE>>2);
  1292. argp->pagelen -= PAGE_SIZE;
  1293. }
  1294. }
  1295. op->opnum = ntohl(*argp->p++);
  1296. if (op->opnum >= OP_ACCESS && op->opnum < ops->nops)
  1297. op->status = ops->decoders[op->opnum](argp, &op->u);
  1298. else {
  1299. op->opnum = OP_ILLEGAL;
  1300. op->status = nfserr_op_illegal;
  1301. }
  1302. if (op->status) {
  1303. argp->opcnt = i+1;
  1304. break;
  1305. }
  1306. }
  1307. DECODE_TAIL;
  1308. }
  1309. #define WRITE32(n) *p++ = htonl(n)
  1310. #define WRITE64(n) do { \
  1311. *p++ = htonl((u32)((n) >> 32)); \
  1312. *p++ = htonl((u32)(n)); \
  1313. } while (0)
  1314. #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
  1315. *(p + XDR_QUADLEN(nbytes) -1) = 0; \
  1316. memcpy(p, ptr, nbytes); \
  1317. p += XDR_QUADLEN(nbytes); \
  1318. }} while (0)
  1319. static void write32(__be32 **p, u32 n)
  1320. {
  1321. *(*p)++ = n;
  1322. }
  1323. static void write64(__be32 **p, u64 n)
  1324. {
  1325. write32(p, (u32)(n >> 32));
  1326. write32(p, (u32)n);
  1327. }
  1328. static void write_change(__be32 **p, struct kstat *stat, struct inode *inode)
  1329. {
  1330. if (IS_I_VERSION(inode)) {
  1331. write64(p, inode->i_version);
  1332. } else {
  1333. write32(p, stat->ctime.tv_sec);
  1334. write32(p, stat->ctime.tv_nsec);
  1335. }
  1336. }
  1337. static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
  1338. {
  1339. write32(p, c->atomic);
  1340. if (c->change_supported) {
  1341. write64(p, c->before_change);
  1342. write64(p, c->after_change);
  1343. } else {
  1344. write32(p, c->before_ctime_sec);
  1345. write32(p, c->before_ctime_nsec);
  1346. write32(p, c->after_ctime_sec);
  1347. write32(p, c->after_ctime_nsec);
  1348. }
  1349. }
  1350. #define RESERVE_SPACE(nbytes) do { \
  1351. p = resp->p; \
  1352. BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
  1353. } while (0)
  1354. #define ADJUST_ARGS() resp->p = p
  1355. /*
  1356. * Header routine to setup seqid operation replay cache
  1357. */
  1358. #define ENCODE_SEQID_OP_HEAD \
  1359. __be32 *save; \
  1360. \
  1361. save = resp->p;
  1362. /*
  1363. * Routine for encoding the result of a "seqid-mutating" NFSv4 operation. This
  1364. * is where sequence id's are incremented, and the replay cache is filled.
  1365. * Note that we increment sequence id's here, at the last moment, so we're sure
  1366. * we know whether the error to be returned is a sequence id mutating error.
  1367. */
  1368. #define ENCODE_SEQID_OP_TAIL(stateowner) do { \
  1369. if (seqid_mutating_err(nfserr) && stateowner) { \
  1370. stateowner->so_seqid++; \
  1371. stateowner->so_replay.rp_status = nfserr; \
  1372. stateowner->so_replay.rp_buflen = \
  1373. (((char *)(resp)->p - (char *)save)); \
  1374. memcpy(stateowner->so_replay.rp_buf, save, \
  1375. stateowner->so_replay.rp_buflen); \
  1376. } } while (0);
  1377. /* Encode as an array of strings the string given with components
  1378. * seperated @sep.
  1379. */
  1380. static __be32 nfsd4_encode_components(char sep, char *components,
  1381. __be32 **pp, int *buflen)
  1382. {
  1383. __be32 *p = *pp;
  1384. __be32 *countp = p;
  1385. int strlen, count=0;
  1386. char *str, *end;
  1387. dprintk("nfsd4_encode_components(%s)\n", components);
  1388. if ((*buflen -= 4) < 0)
  1389. return nfserr_resource;
  1390. WRITE32(0); /* We will fill this in with @count later */
  1391. end = str = components;
  1392. while (*end) {
  1393. for (; *end && (*end != sep); end++)
  1394. ; /* Point to end of component */
  1395. strlen = end - str;
  1396. if (strlen) {
  1397. if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
  1398. return nfserr_resource;
  1399. WRITE32(strlen);
  1400. WRITEMEM(str, strlen);
  1401. count++;
  1402. }
  1403. else
  1404. end++;
  1405. str = end;
  1406. }
  1407. *pp = p;
  1408. p = countp;
  1409. WRITE32(count);
  1410. return 0;
  1411. }
  1412. /*
  1413. * encode a location element of a fs_locations structure
  1414. */
  1415. static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
  1416. __be32 **pp, int *buflen)
  1417. {
  1418. __be32 status;
  1419. __be32 *p = *pp;
  1420. status = nfsd4_encode_components(':', location->hosts, &p, buflen);
  1421. if (status)
  1422. return status;
  1423. status = nfsd4_encode_components('/', location->path, &p, buflen);
  1424. if (status)
  1425. return status;
  1426. *pp = p;
  1427. return 0;
  1428. }
  1429. /*
  1430. * Return the path to an export point in the pseudo filesystem namespace
  1431. * Returned string is safe to use as long as the caller holds a reference
  1432. * to @exp.
  1433. */
  1434. static char *nfsd4_path(struct svc_rqst *rqstp, struct svc_export *exp, __be32 *stat)
  1435. {
  1436. struct svc_fh tmp_fh;
  1437. char *path, *rootpath;
  1438. fh_init(&tmp_fh, NFS4_FHSIZE);
  1439. *stat = exp_pseudoroot(rqstp, &tmp_fh);
  1440. if (*stat)
  1441. return NULL;
  1442. rootpath = tmp_fh.fh_export->ex_pathname;
  1443. path = exp->ex_pathname;
  1444. if (strncmp(path, rootpath, strlen(rootpath))) {
  1445. dprintk("nfsd: fs_locations failed;"
  1446. "%s is not contained in %s\n", path, rootpath);
  1447. *stat = nfserr_notsupp;
  1448. return NULL;
  1449. }
  1450. return path + strlen(rootpath);
  1451. }
  1452. /*
  1453. * encode a fs_locations structure
  1454. */
  1455. static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
  1456. struct svc_export *exp,
  1457. __be32 **pp, int *buflen)
  1458. {
  1459. __be32 status;
  1460. int i;
  1461. __be32 *p = *pp;
  1462. struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
  1463. char *root = nfsd4_path(rqstp, exp, &status);
  1464. if (status)
  1465. return status;
  1466. status = nfsd4_encode_components('/', root, &p, buflen);
  1467. if (status)
  1468. return status;
  1469. if ((*buflen -= 4) < 0)
  1470. return nfserr_resource;
  1471. WRITE32(fslocs->locations_count);
  1472. for (i=0; i<fslocs->locations_count; i++) {
  1473. status = nfsd4_encode_fs_location4(&fslocs->locations[i],
  1474. &p, buflen);
  1475. if (status)
  1476. return status;
  1477. }
  1478. *pp = p;
  1479. return 0;
  1480. }
  1481. static u32 nfs4_ftypes[16] = {
  1482. NF4BAD, NF4FIFO, NF4CHR, NF4BAD,
  1483. NF4DIR, NF4BAD, NF4BLK, NF4BAD,
  1484. NF4REG, NF4BAD, NF4LNK, NF4BAD,
  1485. NF4SOCK, NF4BAD, NF4LNK, NF4BAD,
  1486. };
  1487. static __be32
  1488. nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1489. __be32 **p, int *buflen)
  1490. {
  1491. int status;
  1492. if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
  1493. return nfserr_resource;
  1494. if (whotype != NFS4_ACL_WHO_NAMED)
  1495. status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
  1496. else if (group)
  1497. status = nfsd_map_gid_to_name(rqstp, id, (u8 *)(*p + 1));
  1498. else
  1499. status = nfsd_map_uid_to_name(rqstp, id, (u8 *)(*p + 1));
  1500. if (status < 0)
  1501. return nfserrno(status);
  1502. *p = xdr_encode_opaque(*p, NULL, status);
  1503. *buflen -= (XDR_QUADLEN(status) << 2) + 4;
  1504. BUG_ON(*buflen < 0);
  1505. return 0;
  1506. }
  1507. static inline __be32
  1508. nfsd4_encode_user(struct svc_rqst *rqstp, uid_t uid, __be32 **p, int *buflen)
  1509. {
  1510. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, uid, 0, p, buflen);
  1511. }
  1512. static inline __be32
  1513. nfsd4_encode_group(struct svc_rqst *rqstp, uid_t gid, __be32 **p, int *buflen)
  1514. {
  1515. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, gid, 1, p, buflen);
  1516. }
  1517. static inline __be32
  1518. nfsd4_encode_aclname(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1519. __be32 **p, int *buflen)
  1520. {
  1521. return nfsd4_encode_name(rqstp, whotype, id, group, p, buflen);
  1522. }
  1523. #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
  1524. FATTR4_WORD0_RDATTR_ERROR)
  1525. #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
  1526. static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
  1527. {
  1528. /* As per referral draft: */
  1529. if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
  1530. *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
  1531. if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
  1532. *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
  1533. *rdattr_err = NFSERR_MOVED;
  1534. else
  1535. return nfserr_moved;
  1536. }
  1537. *bmval0 &= WORD0_ABSENT_FS_ATTRS;
  1538. *bmval1 &= WORD1_ABSENT_FS_ATTRS;
  1539. return 0;
  1540. }
  1541. /*
  1542. * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  1543. * ourselves.
  1544. *
  1545. * @countp is the buffer size in _words_; upon successful return this becomes
  1546. * replaced with the number of words written.
  1547. */
  1548. __be32
  1549. nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
  1550. struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval,
  1551. struct svc_rqst *rqstp, int ignore_crossmnt)
  1552. {
  1553. u32 bmval0 = bmval[0];
  1554. u32 bmval1 = bmval[1];
  1555. u32 bmval2 = bmval[2];
  1556. struct kstat stat;
  1557. struct svc_fh tempfh;
  1558. struct kstatfs statfs;
  1559. int buflen = *countp << 2;
  1560. __be32 *attrlenp;
  1561. u32 dummy;
  1562. u64 dummy64;
  1563. u32 rdattr_err = 0;
  1564. __be32 *p = buffer;
  1565. __be32 status;
  1566. int err;
  1567. int aclsupport = 0;
  1568. struct nfs4_acl *acl = NULL;
  1569. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1570. u32 minorversion = resp->cstate.minorversion;
  1571. BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
  1572. BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
  1573. BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
  1574. BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
  1575. if (exp->ex_fslocs.migrated) {
  1576. BUG_ON(bmval[2]);
  1577. status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
  1578. if (status)
  1579. goto out;
  1580. }
  1581. err = vfs_getattr(exp->ex_path.mnt, dentry, &stat);
  1582. if (err)
  1583. goto out_nfserr;
  1584. if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
  1585. FATTR4_WORD0_MAXNAME)) ||
  1586. (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
  1587. FATTR4_WORD1_SPACE_TOTAL))) {
  1588. err = vfs_statfs(dentry, &statfs);
  1589. if (err)
  1590. goto out_nfserr;
  1591. }
  1592. if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
  1593. fh_init(&tempfh, NFS4_FHSIZE);
  1594. status = fh_compose(&tempfh, exp, dentry, NULL);
  1595. if (status)
  1596. goto out;
  1597. fhp = &tempfh;
  1598. }
  1599. if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
  1600. | FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1601. err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
  1602. aclsupport = (err == 0);
  1603. if (bmval0 & FATTR4_WORD0_ACL) {
  1604. if (err == -EOPNOTSUPP)
  1605. bmval0 &= ~FATTR4_WORD0_ACL;
  1606. else if (err == -EINVAL) {
  1607. status = nfserr_attrnotsupp;
  1608. goto out;
  1609. } else if (err != 0)
  1610. goto out_nfserr;
  1611. }
  1612. }
  1613. if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
  1614. if (exp->ex_fslocs.locations == NULL) {
  1615. bmval0 &= ~FATTR4_WORD0_FS_LOCATIONS;
  1616. }
  1617. }
  1618. if ((buflen -= 16) < 0)
  1619. goto out_resource;
  1620. if (unlikely(bmval2)) {
  1621. WRITE32(3);
  1622. WRITE32(bmval0);
  1623. WRITE32(bmval1);
  1624. WRITE32(bmval2);
  1625. } else if (likely(bmval1)) {
  1626. WRITE32(2);
  1627. WRITE32(bmval0);
  1628. WRITE32(bmval1);
  1629. } else {
  1630. WRITE32(1);
  1631. WRITE32(bmval0);
  1632. }
  1633. attrlenp = p++; /* to be backfilled later */
  1634. if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
  1635. u32 word0 = nfsd_suppattrs0(minorversion);
  1636. u32 word1 = nfsd_suppattrs1(minorversion);
  1637. u32 word2 = nfsd_suppattrs2(minorversion);
  1638. if ((buflen -= 12) < 0)
  1639. goto out_resource;
  1640. if (!aclsupport)
  1641. word0 &= ~FATTR4_WORD0_ACL;
  1642. if (!exp->ex_fslocs.locations)
  1643. word0 &= ~FATTR4_WORD0_FS_LOCATIONS;
  1644. if (!word2) {
  1645. WRITE32(2);
  1646. WRITE32(word0);
  1647. WRITE32(word1);
  1648. } else {
  1649. WRITE32(3);
  1650. WRITE32(word0);
  1651. WRITE32(word1);
  1652. WRITE32(word2);
  1653. }
  1654. }
  1655. if (bmval0 & FATTR4_WORD0_TYPE) {
  1656. if ((buflen -= 4) < 0)
  1657. goto out_resource;
  1658. dummy = nfs4_ftypes[(stat.mode & S_IFMT) >> 12];
  1659. if (dummy == NF4BAD)
  1660. goto out_serverfault;
  1661. WRITE32(dummy);
  1662. }
  1663. if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
  1664. if ((buflen -= 4) < 0)
  1665. goto out_resource;
  1666. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
  1667. WRITE32(NFS4_FH_PERSISTENT);
  1668. else
  1669. WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
  1670. }
  1671. if (bmval0 & FATTR4_WORD0_CHANGE) {
  1672. if ((buflen -= 8) < 0)
  1673. goto out_resource;
  1674. write_change(&p, &stat, dentry->d_inode);
  1675. }
  1676. if (bmval0 & FATTR4_WORD0_SIZE) {
  1677. if ((buflen -= 8) < 0)
  1678. goto out_resource;
  1679. WRITE64(stat.size);
  1680. }
  1681. if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
  1682. if ((buflen -= 4) < 0)
  1683. goto out_resource;
  1684. WRITE32(1);
  1685. }
  1686. if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
  1687. if ((buflen -= 4) < 0)
  1688. goto out_resource;
  1689. WRITE32(1);
  1690. }
  1691. if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
  1692. if ((buflen -= 4) < 0)
  1693. goto out_resource;
  1694. WRITE32(0);
  1695. }
  1696. if (bmval0 & FATTR4_WORD0_FSID) {
  1697. if ((buflen -= 16) < 0)
  1698. goto out_resource;
  1699. if (exp->ex_fslocs.migrated) {
  1700. WRITE64(NFS4_REFERRAL_FSID_MAJOR);
  1701. WRITE64(NFS4_REFERRAL_FSID_MINOR);
  1702. } else switch(fsid_source(fhp)) {
  1703. case FSIDSOURCE_FSID:
  1704. WRITE64((u64)exp->ex_fsid);
  1705. WRITE64((u64)0);
  1706. break;
  1707. case FSIDSOURCE_DEV:
  1708. WRITE32(0);
  1709. WRITE32(MAJOR(stat.dev));
  1710. WRITE32(0);
  1711. WRITE32(MINOR(stat.dev));
  1712. break;
  1713. case FSIDSOURCE_UUID:
  1714. WRITEMEM(exp->ex_uuid, 16);
  1715. break;
  1716. }
  1717. }
  1718. if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
  1719. if ((buflen -= 4) < 0)
  1720. goto out_resource;
  1721. WRITE32(0);
  1722. }
  1723. if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
  1724. if ((buflen -= 4) < 0)
  1725. goto out_resource;
  1726. WRITE32(NFSD_LEASE_TIME);
  1727. }
  1728. if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
  1729. if ((buflen -= 4) < 0)
  1730. goto out_resource;
  1731. WRITE32(rdattr_err);
  1732. }
  1733. if (bmval0 & FATTR4_WORD0_ACL) {
  1734. struct nfs4_ace *ace;
  1735. if (acl == NULL) {
  1736. if ((buflen -= 4) < 0)
  1737. goto out_resource;
  1738. WRITE32(0);
  1739. goto out_acl;
  1740. }
  1741. if ((buflen -= 4) < 0)
  1742. goto out_resource;
  1743. WRITE32(acl->naces);
  1744. for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
  1745. if ((buflen -= 4*3) < 0)
  1746. goto out_resource;
  1747. WRITE32(ace->type);
  1748. WRITE32(ace->flag);
  1749. WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
  1750. status = nfsd4_encode_aclname(rqstp, ace->whotype,
  1751. ace->who, ace->flag & NFS4_ACE_IDENTIFIER_GROUP,
  1752. &p, &buflen);
  1753. if (status == nfserr_resource)
  1754. goto out_resource;
  1755. if (status)
  1756. goto out;
  1757. }
  1758. }
  1759. out_acl:
  1760. if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
  1761. if ((buflen -= 4) < 0)
  1762. goto out_resource;
  1763. WRITE32(aclsupport ?
  1764. ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
  1765. }
  1766. if (bmval0 & FATTR4_WORD0_CANSETTIME) {
  1767. if ((buflen -= 4) < 0)
  1768. goto out_resource;
  1769. WRITE32(1);
  1770. }
  1771. if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
  1772. if ((buflen -= 4) < 0)
  1773. goto out_resource;
  1774. WRITE32(1);
  1775. }
  1776. if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
  1777. if ((buflen -= 4) < 0)
  1778. goto out_resource;
  1779. WRITE32(1);
  1780. }
  1781. if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
  1782. if ((buflen -= 4) < 0)
  1783. goto out_resource;
  1784. WRITE32(1);
  1785. }
  1786. if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
  1787. buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
  1788. if (buflen < 0)
  1789. goto out_resource;
  1790. WRITE32(fhp->fh_handle.fh_size);
  1791. WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
  1792. }
  1793. if (bmval0 & FATTR4_WORD0_FILEID) {
  1794. if ((buflen -= 8) < 0)
  1795. goto out_resource;
  1796. WRITE64(stat.ino);
  1797. }
  1798. if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
  1799. if ((buflen -= 8) < 0)
  1800. goto out_resource;
  1801. WRITE64((u64) statfs.f_ffree);
  1802. }
  1803. if (bmval0 & FATTR4_WORD0_FILES_FREE) {
  1804. if ((buflen -= 8) < 0)
  1805. goto out_resource;
  1806. WRITE64((u64) statfs.f_ffree);
  1807. }
  1808. if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
  1809. if ((buflen -= 8) < 0)
  1810. goto out_resource;
  1811. WRITE64((u64) statfs.f_files);
  1812. }
  1813. if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
  1814. status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
  1815. if (status == nfserr_resource)
  1816. goto out_resource;
  1817. if (status)
  1818. goto out;
  1819. }
  1820. if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
  1821. if ((buflen -= 4) < 0)
  1822. goto out_resource;
  1823. WRITE32(1);
  1824. }
  1825. if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
  1826. if ((buflen -= 8) < 0)
  1827. goto out_resource;
  1828. WRITE64(~(u64)0);
  1829. }
  1830. if (bmval0 & FATTR4_WORD0_MAXLINK) {
  1831. if ((buflen -= 4) < 0)
  1832. goto out_resource;
  1833. WRITE32(255);
  1834. }
  1835. if (bmval0 & FATTR4_WORD0_MAXNAME) {
  1836. if ((buflen -= 4) < 0)
  1837. goto out_resource;
  1838. WRITE32(statfs.f_namelen);
  1839. }
  1840. if (bmval0 & FATTR4_WORD0_MAXREAD) {
  1841. if ((buflen -= 8) < 0)
  1842. goto out_resource;
  1843. WRITE64((u64) svc_max_payload(rqstp));
  1844. }
  1845. if (bmval0 & FATTR4_WORD0_MAXWRITE) {
  1846. if ((buflen -= 8) < 0)
  1847. goto out_resource;
  1848. WRITE64((u64) svc_max_payload(rqstp));
  1849. }
  1850. if (bmval1 & FATTR4_WORD1_MODE) {
  1851. if ((buflen -= 4) < 0)
  1852. goto out_resource;
  1853. WRITE32(stat.mode & S_IALLUGO);
  1854. }
  1855. if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
  1856. if ((buflen -= 4) < 0)
  1857. goto out_resource;
  1858. WRITE32(1);
  1859. }
  1860. if (bmval1 & FATTR4_WORD1_NUMLINKS) {
  1861. if ((buflen -= 4) < 0)
  1862. goto out_resource;
  1863. WRITE32(stat.nlink);
  1864. }
  1865. if (bmval1 & FATTR4_WORD1_OWNER) {
  1866. status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
  1867. if (status == nfserr_resource)
  1868. goto out_resource;
  1869. if (status)
  1870. goto out;
  1871. }
  1872. if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
  1873. status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
  1874. if (status == nfserr_resource)
  1875. goto out_resource;
  1876. if (status)
  1877. goto out;
  1878. }
  1879. if (bmval1 & FATTR4_WORD1_RAWDEV) {
  1880. if ((buflen -= 8) < 0)
  1881. goto out_resource;
  1882. WRITE32((u32) MAJOR(stat.rdev));
  1883. WRITE32((u32) MINOR(stat.rdev));
  1884. }
  1885. if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
  1886. if ((buflen -= 8) < 0)
  1887. goto out_resource;
  1888. dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
  1889. WRITE64(dummy64);
  1890. }
  1891. if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
  1892. if ((buflen -= 8) < 0)
  1893. goto out_resource;
  1894. dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
  1895. WRITE64(dummy64);
  1896. }
  1897. if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
  1898. if ((buflen -= 8) < 0)
  1899. goto out_resource;
  1900. dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
  1901. WRITE64(dummy64);
  1902. }
  1903. if (bmval1 & FATTR4_WORD1_SPACE_USED) {
  1904. if ((buflen -= 8) < 0)
  1905. goto out_resource;
  1906. dummy64 = (u64)stat.blocks << 9;
  1907. WRITE64(dummy64);
  1908. }
  1909. if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
  1910. if ((buflen -= 12) < 0)
  1911. goto out_resource;
  1912. WRITE32(0);
  1913. WRITE32(stat.atime.tv_sec);
  1914. WRITE32(stat.atime.tv_nsec);
  1915. }
  1916. if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
  1917. if ((buflen -= 12) < 0)
  1918. goto out_resource;
  1919. WRITE32(0);
  1920. WRITE32(1);
  1921. WRITE32(0);
  1922. }
  1923. if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
  1924. if ((buflen -= 12) < 0)
  1925. goto out_resource;
  1926. WRITE32(0);
  1927. WRITE32(stat.ctime.tv_sec);
  1928. WRITE32(stat.ctime.tv_nsec);
  1929. }
  1930. if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
  1931. if ((buflen -= 12) < 0)
  1932. goto out_resource;
  1933. WRITE32(0);
  1934. WRITE32(stat.mtime.tv_sec);
  1935. WRITE32(stat.mtime.tv_nsec);
  1936. }
  1937. if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
  1938. if ((buflen -= 8) < 0)
  1939. goto out_resource;
  1940. /*
  1941. * Get parent's attributes if not ignoring crossmount
  1942. * and this is the root of a cross-mounted filesystem.
  1943. */
  1944. if (ignore_crossmnt == 0 &&
  1945. exp->ex_path.mnt->mnt_root->d_inode == dentry->d_inode) {
  1946. err = vfs_getattr(exp->ex_path.mnt->mnt_parent,
  1947. exp->ex_path.mnt->mnt_mountpoint, &stat);
  1948. if (err)
  1949. goto out_nfserr;
  1950. }
  1951. WRITE64(stat.ino);
  1952. }
  1953. if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
  1954. WRITE32(3);
  1955. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
  1956. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
  1957. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
  1958. }
  1959. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  1960. *countp = p - buffer;
  1961. status = nfs_ok;
  1962. out:
  1963. kfree(acl);
  1964. if (fhp == &tempfh)
  1965. fh_put(&tempfh);
  1966. return status;
  1967. out_nfserr:
  1968. status = nfserrno(err);
  1969. goto out;
  1970. out_resource:
  1971. *countp = 0;
  1972. status = nfserr_resource;
  1973. goto out;
  1974. out_serverfault:
  1975. status = nfserr_serverfault;
  1976. goto out;
  1977. }
  1978. static inline int attributes_need_mount(u32 *bmval)
  1979. {
  1980. if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
  1981. return 1;
  1982. if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
  1983. return 1;
  1984. return 0;
  1985. }
  1986. static __be32
  1987. nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
  1988. const char *name, int namlen, __be32 *p, int *buflen)
  1989. {
  1990. struct svc_export *exp = cd->rd_fhp->fh_export;
  1991. struct dentry *dentry;
  1992. __be32 nfserr;
  1993. int ignore_crossmnt = 0;
  1994. dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
  1995. if (IS_ERR(dentry))
  1996. return nfserrno(PTR_ERR(dentry));
  1997. exp_get(exp);
  1998. /*
  1999. * In the case of a mountpoint, the client may be asking for
  2000. * attributes that are only properties of the underlying filesystem
  2001. * as opposed to the cross-mounted file system. In such a case,
  2002. * we will not follow the cross mount and will fill the attribtutes
  2003. * directly from the mountpoint dentry.
  2004. */
  2005. if (d_mountpoint(dentry) && !attributes_need_mount(cd->rd_bmval))
  2006. ignore_crossmnt = 1;
  2007. else if (d_mountpoint(dentry)) {
  2008. int err;
  2009. /*
  2010. * Why the heck aren't we just using nfsd_lookup??
  2011. * Different "."/".." handling? Something else?
  2012. * At least, add a comment here to explain....
  2013. */
  2014. err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
  2015. if (err) {
  2016. nfserr = nfserrno(err);
  2017. goto out_put;
  2018. }
  2019. nfserr = check_nfsd_access(exp, cd->rd_rqstp);
  2020. if (nfserr)
  2021. goto out_put;
  2022. }
  2023. nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
  2024. cd->rd_rqstp, ignore_crossmnt);
  2025. out_put:
  2026. dput(dentry);
  2027. exp_put(exp);
  2028. return nfserr;
  2029. }
  2030. static __be32 *
  2031. nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
  2032. {
  2033. __be32 *attrlenp;
  2034. if (buflen < 6)
  2035. return NULL;
  2036. *p++ = htonl(2);
  2037. *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
  2038. *p++ = htonl(0); /* bmval1 */
  2039. attrlenp = p++;
  2040. *p++ = nfserr; /* no htonl */
  2041. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  2042. return p;
  2043. }
  2044. static int
  2045. nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
  2046. loff_t offset, u64 ino, unsigned int d_type)
  2047. {
  2048. struct readdir_cd *ccd = ccdv;
  2049. struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
  2050. int buflen;
  2051. __be32 *p = cd->buffer;
  2052. __be32 nfserr = nfserr_toosmall;
  2053. /* In nfsv4, "." and ".." never make it onto the wire.. */
  2054. if (name && isdotent(name, namlen)) {
  2055. cd->common.err = nfs_ok;
  2056. return 0;
  2057. }
  2058. if (cd->offset)
  2059. xdr_encode_hyper(cd->offset, (u64) offset);
  2060. buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
  2061. if (buflen < 0)
  2062. goto fail;
  2063. *p++ = xdr_one; /* mark entry present */
  2064. cd->offset = p; /* remember pointer */
  2065. p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
  2066. p = xdr_encode_array(p, name, namlen); /* name length & name */
  2067. nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, p, &buflen);
  2068. switch (nfserr) {
  2069. case nfs_ok:
  2070. p += buflen;
  2071. break;
  2072. case nfserr_resource:
  2073. nfserr = nfserr_toosmall;
  2074. goto fail;
  2075. case nfserr_dropit:
  2076. goto fail;
  2077. default:
  2078. /*
  2079. * If the client requested the RDATTR_ERROR attribute,
  2080. * we stuff the error code into this attribute
  2081. * and continue. If this attribute was not requested,
  2082. * then in accordance with the spec, we fail the
  2083. * entire READDIR operation(!)
  2084. */
  2085. if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
  2086. goto fail;
  2087. p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
  2088. if (p == NULL) {
  2089. nfserr = nfserr_toosmall;
  2090. goto fail;
  2091. }
  2092. }
  2093. cd->buflen -= (p - cd->buffer);
  2094. cd->buffer = p;
  2095. cd->common.err = nfs_ok;
  2096. return 0;
  2097. fail:
  2098. cd->common.err = nfserr;
  2099. return -EINVAL;
  2100. }
  2101. static void
  2102. nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
  2103. {
  2104. __be32 *p;
  2105. RESERVE_SPACE(sizeof(stateid_t));
  2106. WRITE32(sid->si_generation);
  2107. WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
  2108. ADJUST_ARGS();
  2109. }
  2110. static __be32
  2111. nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
  2112. {
  2113. __be32 *p;
  2114. if (!nfserr) {
  2115. RESERVE_SPACE(8);
  2116. WRITE32(access->ac_supported);
  2117. WRITE32(access->ac_resp_access);
  2118. ADJUST_ARGS();
  2119. }
  2120. return nfserr;
  2121. }
  2122. static __be32
  2123. nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
  2124. {
  2125. ENCODE_SEQID_OP_HEAD;
  2126. if (!nfserr)
  2127. nfsd4_encode_stateid(resp, &close->cl_stateid);
  2128. ENCODE_SEQID_OP_TAIL(close->cl_stateowner);
  2129. return nfserr;
  2130. }
  2131. static __be32
  2132. nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
  2133. {
  2134. __be32 *p;
  2135. if (!nfserr) {
  2136. RESERVE_SPACE(8);
  2137. WRITEMEM(commit->co_verf.data, 8);
  2138. ADJUST_ARGS();
  2139. }
  2140. return nfserr;
  2141. }
  2142. static __be32
  2143. nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
  2144. {
  2145. __be32 *p;
  2146. if (!nfserr) {
  2147. RESERVE_SPACE(32);
  2148. write_cinfo(&p, &create->cr_cinfo);
  2149. WRITE32(2);
  2150. WRITE32(create->cr_bmval[0]);
  2151. WRITE32(create->cr_bmval[1]);
  2152. ADJUST_ARGS();
  2153. }
  2154. return nfserr;
  2155. }
  2156. static __be32
  2157. nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
  2158. {
  2159. struct svc_fh *fhp = getattr->ga_fhp;
  2160. int buflen;
  2161. if (nfserr)
  2162. return nfserr;
  2163. buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
  2164. nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
  2165. resp->p, &buflen, getattr->ga_bmval,
  2166. resp->rqstp, 0);
  2167. if (!nfserr)
  2168. resp->p += buflen;
  2169. return nfserr;
  2170. }
  2171. static __be32
  2172. nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
  2173. {
  2174. struct svc_fh *fhp = *fhpp;
  2175. unsigned int len;
  2176. __be32 *p;
  2177. if (!nfserr) {
  2178. len = fhp->fh_handle.fh_size;
  2179. RESERVE_SPACE(len + 4);
  2180. WRITE32(len);
  2181. WRITEMEM(&fhp->fh_handle.fh_base, len);
  2182. ADJUST_ARGS();
  2183. }
  2184. return nfserr;
  2185. }
  2186. /*
  2187. * Including all fields other than the name, a LOCK4denied structure requires
  2188. * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
  2189. */
  2190. static void
  2191. nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
  2192. {
  2193. __be32 *p;
  2194. RESERVE_SPACE(32 + XDR_LEN(ld->ld_sop ? ld->ld_sop->so_owner.len : 0));
  2195. WRITE64(ld->ld_start);
  2196. WRITE64(ld->ld_length);
  2197. WRITE32(ld->ld_type);
  2198. if (ld->ld_sop) {
  2199. WRITEMEM(&ld->ld_clientid, 8);
  2200. WRITE32(ld->ld_sop->so_owner.len);
  2201. WRITEMEM(ld->ld_sop->so_owner.data, ld->ld_sop->so_owner.len);
  2202. kref_put(&ld->ld_sop->so_ref, nfs4_free_stateowner);
  2203. } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
  2204. WRITE64((u64)0); /* clientid */
  2205. WRITE32(0); /* length of owner name */
  2206. }
  2207. ADJUST_ARGS();
  2208. }
  2209. static __be32
  2210. nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
  2211. {
  2212. ENCODE_SEQID_OP_HEAD;
  2213. if (!nfserr)
  2214. nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
  2215. else if (nfserr == nfserr_denied)
  2216. nfsd4_encode_lock_denied(resp, &lock->lk_denied);
  2217. ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner);
  2218. return nfserr;
  2219. }
  2220. static __be32
  2221. nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
  2222. {
  2223. if (nfserr == nfserr_denied)
  2224. nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
  2225. return nfserr;
  2226. }
  2227. static __be32
  2228. nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
  2229. {
  2230. ENCODE_SEQID_OP_HEAD;
  2231. if (!nfserr)
  2232. nfsd4_encode_stateid(resp, &locku->lu_stateid);
  2233. ENCODE_SEQID_OP_TAIL(locku->lu_stateowner);
  2234. return nfserr;
  2235. }
  2236. static __be32
  2237. nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
  2238. {
  2239. __be32 *p;
  2240. if (!nfserr) {
  2241. RESERVE_SPACE(20);
  2242. write_cinfo(&p, &link->li_cinfo);
  2243. ADJUST_ARGS();
  2244. }
  2245. return nfserr;
  2246. }
  2247. static __be32
  2248. nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
  2249. {
  2250. __be32 *p;
  2251. ENCODE_SEQID_OP_HEAD;
  2252. if (nfserr)
  2253. goto out;
  2254. nfsd4_encode_stateid(resp, &open->op_stateid);
  2255. RESERVE_SPACE(40);
  2256. write_cinfo(&p, &open->op_cinfo);
  2257. WRITE32(open->op_rflags);
  2258. WRITE32(2);
  2259. WRITE32(open->op_bmval[0]);
  2260. WRITE32(open->op_bmval[1]);
  2261. WRITE32(open->op_delegate_type);
  2262. ADJUST_ARGS();
  2263. switch (open->op_delegate_type) {
  2264. case NFS4_OPEN_DELEGATE_NONE:
  2265. break;
  2266. case NFS4_OPEN_DELEGATE_READ:
  2267. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2268. RESERVE_SPACE(20);
  2269. WRITE32(open->op_recall);
  2270. /*
  2271. * TODO: ACE's in delegations
  2272. */
  2273. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2274. WRITE32(0);
  2275. WRITE32(0);
  2276. WRITE32(0); /* XXX: is NULL principal ok? */
  2277. ADJUST_ARGS();
  2278. break;
  2279. case NFS4_OPEN_DELEGATE_WRITE:
  2280. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2281. RESERVE_SPACE(32);
  2282. WRITE32(0);
  2283. /*
  2284. * TODO: space_limit's in delegations
  2285. */
  2286. WRITE32(NFS4_LIMIT_SIZE);
  2287. WRITE32(~(u32)0);
  2288. WRITE32(~(u32)0);
  2289. /*
  2290. * TODO: ACE's in delegations
  2291. */
  2292. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2293. WRITE32(0);
  2294. WRITE32(0);
  2295. WRITE32(0); /* XXX: is NULL principal ok? */
  2296. ADJUST_ARGS();
  2297. break;
  2298. default:
  2299. BUG();
  2300. }
  2301. /* XXX save filehandle here */
  2302. out:
  2303. ENCODE_SEQID_OP_TAIL(open->op_stateowner);
  2304. return nfserr;
  2305. }
  2306. static __be32
  2307. nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
  2308. {
  2309. ENCODE_SEQID_OP_HEAD;
  2310. if (!nfserr)
  2311. nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
  2312. ENCODE_SEQID_OP_TAIL(oc->oc_stateowner);
  2313. return nfserr;
  2314. }
  2315. static __be32
  2316. nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
  2317. {
  2318. ENCODE_SEQID_OP_HEAD;
  2319. if (!nfserr)
  2320. nfsd4_encode_stateid(resp, &od->od_stateid);
  2321. ENCODE_SEQID_OP_TAIL(od->od_stateowner);
  2322. return nfserr;
  2323. }
  2324. static __be32
  2325. nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
  2326. struct nfsd4_read *read)
  2327. {
  2328. u32 eof;
  2329. int v, pn;
  2330. unsigned long maxcount;
  2331. long len;
  2332. __be32 *p;
  2333. if (nfserr)
  2334. return nfserr;
  2335. if (resp->xbuf->page_len)
  2336. return nfserr_resource;
  2337. RESERVE_SPACE(8); /* eof flag and byte count */
  2338. maxcount = svc_max_payload(resp->rqstp);
  2339. if (maxcount > read->rd_length)
  2340. maxcount = read->rd_length;
  2341. len = maxcount;
  2342. v = 0;
  2343. while (len > 0) {
  2344. pn = resp->rqstp->rq_resused++;
  2345. resp->rqstp->rq_vec[v].iov_base =
  2346. page_address(resp->rqstp->rq_respages[pn]);
  2347. resp->rqstp->rq_vec[v].iov_len =
  2348. len < PAGE_SIZE ? len : PAGE_SIZE;
  2349. v++;
  2350. len -= PAGE_SIZE;
  2351. }
  2352. read->rd_vlen = v;
  2353. nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp,
  2354. read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
  2355. &maxcount);
  2356. if (nfserr == nfserr_symlink)
  2357. nfserr = nfserr_inval;
  2358. if (nfserr)
  2359. return nfserr;
  2360. eof = (read->rd_offset + maxcount >=
  2361. read->rd_fhp->fh_dentry->d_inode->i_size);
  2362. WRITE32(eof);
  2363. WRITE32(maxcount);
  2364. ADJUST_ARGS();
  2365. resp->xbuf->head[0].iov_len = (char*)p
  2366. - (char*)resp->xbuf->head[0].iov_base;
  2367. resp->xbuf->page_len = maxcount;
  2368. /* Use rest of head for padding and remaining ops: */
  2369. resp->xbuf->tail[0].iov_base = p;
  2370. resp->xbuf->tail[0].iov_len = 0;
  2371. if (maxcount&3) {
  2372. RESERVE_SPACE(4);
  2373. WRITE32(0);
  2374. resp->xbuf->tail[0].iov_base += maxcount&3;
  2375. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2376. ADJUST_ARGS();
  2377. }
  2378. return 0;
  2379. }
  2380. static __be32
  2381. nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
  2382. {
  2383. int maxcount;
  2384. char *page;
  2385. __be32 *p;
  2386. if (nfserr)
  2387. return nfserr;
  2388. if (resp->xbuf->page_len)
  2389. return nfserr_resource;
  2390. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2391. maxcount = PAGE_SIZE;
  2392. RESERVE_SPACE(4);
  2393. /*
  2394. * XXX: By default, the ->readlink() VFS op will truncate symlinks
  2395. * if they would overflow the buffer. Is this kosher in NFSv4? If
  2396. * not, one easy fix is: if ->readlink() precisely fills the buffer,
  2397. * assume that truncation occurred, and return NFS4ERR_RESOURCE.
  2398. */
  2399. nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
  2400. if (nfserr == nfserr_isdir)
  2401. return nfserr_inval;
  2402. if (nfserr)
  2403. return nfserr;
  2404. WRITE32(maxcount);
  2405. ADJUST_ARGS();
  2406. resp->xbuf->head[0].iov_len = (char*)p
  2407. - (char*)resp->xbuf->head[0].iov_base;
  2408. resp->xbuf->page_len = maxcount;
  2409. /* Use rest of head for padding and remaining ops: */
  2410. resp->xbuf->tail[0].iov_base = p;
  2411. resp->xbuf->tail[0].iov_len = 0;
  2412. if (maxcount&3) {
  2413. RESERVE_SPACE(4);
  2414. WRITE32(0);
  2415. resp->xbuf->tail[0].iov_base += maxcount&3;
  2416. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2417. ADJUST_ARGS();
  2418. }
  2419. return 0;
  2420. }
  2421. static __be32
  2422. nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
  2423. {
  2424. int maxcount;
  2425. loff_t offset;
  2426. __be32 *page, *savep, *tailbase;
  2427. __be32 *p;
  2428. if (nfserr)
  2429. return nfserr;
  2430. if (resp->xbuf->page_len)
  2431. return nfserr_resource;
  2432. RESERVE_SPACE(8); /* verifier */
  2433. savep = p;
  2434. /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
  2435. WRITE32(0);
  2436. WRITE32(0);
  2437. ADJUST_ARGS();
  2438. resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
  2439. tailbase = p;
  2440. maxcount = PAGE_SIZE;
  2441. if (maxcount > readdir->rd_maxcount)
  2442. maxcount = readdir->rd_maxcount;
  2443. /*
  2444. * Convert from bytes to words, account for the two words already
  2445. * written, make sure to leave two words at the end for the next
  2446. * pointer and eof field.
  2447. */
  2448. maxcount = (maxcount >> 2) - 4;
  2449. if (maxcount < 0) {
  2450. nfserr = nfserr_toosmall;
  2451. goto err_no_verf;
  2452. }
  2453. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2454. readdir->common.err = 0;
  2455. readdir->buflen = maxcount;
  2456. readdir->buffer = page;
  2457. readdir->offset = NULL;
  2458. offset = readdir->rd_cookie;
  2459. nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
  2460. &offset,
  2461. &readdir->common, nfsd4_encode_dirent);
  2462. if (nfserr == nfs_ok &&
  2463. readdir->common.err == nfserr_toosmall &&
  2464. readdir->buffer == page)
  2465. nfserr = nfserr_toosmall;
  2466. if (nfserr == nfserr_symlink)
  2467. nfserr = nfserr_notdir;
  2468. if (nfserr)
  2469. goto err_no_verf;
  2470. if (readdir->offset)
  2471. xdr_encode_hyper(readdir->offset, offset);
  2472. p = readdir->buffer;
  2473. *p++ = 0; /* no more entries */
  2474. *p++ = htonl(readdir->common.err == nfserr_eof);
  2475. resp->xbuf->page_len = ((char*)p) - (char*)page_address(
  2476. resp->rqstp->rq_respages[resp->rqstp->rq_resused-1]);
  2477. /* Use rest of head for padding and remaining ops: */
  2478. resp->xbuf->tail[0].iov_base = tailbase;
  2479. resp->xbuf->tail[0].iov_len = 0;
  2480. resp->p = resp->xbuf->tail[0].iov_base;
  2481. resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
  2482. return 0;
  2483. err_no_verf:
  2484. p = savep;
  2485. ADJUST_ARGS();
  2486. return nfserr;
  2487. }
  2488. static __be32
  2489. nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
  2490. {
  2491. __be32 *p;
  2492. if (!nfserr) {
  2493. RESERVE_SPACE(20);
  2494. write_cinfo(&p, &remove->rm_cinfo);
  2495. ADJUST_ARGS();
  2496. }
  2497. return nfserr;
  2498. }
  2499. static __be32
  2500. nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
  2501. {
  2502. __be32 *p;
  2503. if (!nfserr) {
  2504. RESERVE_SPACE(40);
  2505. write_cinfo(&p, &rename->rn_sinfo);
  2506. write_cinfo(&p, &rename->rn_tinfo);
  2507. ADJUST_ARGS();
  2508. }
  2509. return nfserr;
  2510. }
  2511. static __be32
  2512. nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
  2513. struct nfsd4_secinfo *secinfo)
  2514. {
  2515. int i = 0;
  2516. struct svc_export *exp = secinfo->si_exp;
  2517. u32 nflavs;
  2518. struct exp_flavor_info *flavs;
  2519. struct exp_flavor_info def_flavs[2];
  2520. __be32 *p;
  2521. if (nfserr)
  2522. goto out;
  2523. if (exp->ex_nflavors) {
  2524. flavs = exp->ex_flavors;
  2525. nflavs = exp->ex_nflavors;
  2526. } else { /* Handling of some defaults in absence of real secinfo: */
  2527. flavs = def_flavs;
  2528. if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
  2529. nflavs = 2;
  2530. flavs[0].pseudoflavor = RPC_AUTH_UNIX;
  2531. flavs[1].pseudoflavor = RPC_AUTH_NULL;
  2532. } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
  2533. nflavs = 1;
  2534. flavs[0].pseudoflavor
  2535. = svcauth_gss_flavor(exp->ex_client);
  2536. } else {
  2537. nflavs = 1;
  2538. flavs[0].pseudoflavor
  2539. = exp->ex_client->flavour->flavour;
  2540. }
  2541. }
  2542. RESERVE_SPACE(4);
  2543. WRITE32(nflavs);
  2544. ADJUST_ARGS();
  2545. for (i = 0; i < nflavs; i++) {
  2546. u32 flav = flavs[i].pseudoflavor;
  2547. struct gss_api_mech *gm = gss_mech_get_by_pseudoflavor(flav);
  2548. if (gm) {
  2549. RESERVE_SPACE(4);
  2550. WRITE32(RPC_AUTH_GSS);
  2551. ADJUST_ARGS();
  2552. RESERVE_SPACE(4 + gm->gm_oid.len);
  2553. WRITE32(gm->gm_oid.len);
  2554. WRITEMEM(gm->gm_oid.data, gm->gm_oid.len);
  2555. ADJUST_ARGS();
  2556. RESERVE_SPACE(4);
  2557. WRITE32(0); /* qop */
  2558. ADJUST_ARGS();
  2559. RESERVE_SPACE(4);
  2560. WRITE32(gss_pseudoflavor_to_service(gm, flav));
  2561. ADJUST_ARGS();
  2562. gss_mech_put(gm);
  2563. } else {
  2564. RESERVE_SPACE(4);
  2565. WRITE32(flav);
  2566. ADJUST_ARGS();
  2567. }
  2568. }
  2569. out:
  2570. if (exp)
  2571. exp_put(exp);
  2572. return nfserr;
  2573. }
  2574. /*
  2575. * The SETATTR encode routine is special -- it always encodes a bitmap,
  2576. * regardless of the error status.
  2577. */
  2578. static __be32
  2579. nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
  2580. {
  2581. __be32 *p;
  2582. RESERVE_SPACE(12);
  2583. if (nfserr) {
  2584. WRITE32(2);
  2585. WRITE32(0);
  2586. WRITE32(0);
  2587. }
  2588. else {
  2589. WRITE32(2);
  2590. WRITE32(setattr->sa_bmval[0]);
  2591. WRITE32(setattr->sa_bmval[1]);
  2592. }
  2593. ADJUST_ARGS();
  2594. return nfserr;
  2595. }
  2596. static __be32
  2597. nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
  2598. {
  2599. __be32 *p;
  2600. if (!nfserr) {
  2601. RESERVE_SPACE(8 + sizeof(nfs4_verifier));
  2602. WRITEMEM(&scd->se_clientid, 8);
  2603. WRITEMEM(&scd->se_confirm, sizeof(nfs4_verifier));
  2604. ADJUST_ARGS();
  2605. }
  2606. else if (nfserr == nfserr_clid_inuse) {
  2607. RESERVE_SPACE(8);
  2608. WRITE32(0);
  2609. WRITE32(0);
  2610. ADJUST_ARGS();
  2611. }
  2612. return nfserr;
  2613. }
  2614. static __be32
  2615. nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
  2616. {
  2617. __be32 *p;
  2618. if (!nfserr) {
  2619. RESERVE_SPACE(16);
  2620. WRITE32(write->wr_bytes_written);
  2621. WRITE32(write->wr_how_written);
  2622. WRITEMEM(write->wr_verifier.data, 8);
  2623. ADJUST_ARGS();
  2624. }
  2625. return nfserr;
  2626. }
  2627. static __be32
  2628. nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr,
  2629. struct nfsd4_exchange_id *exid)
  2630. {
  2631. __be32 *p;
  2632. char *major_id;
  2633. char *server_scope;
  2634. int major_id_sz;
  2635. int server_scope_sz;
  2636. uint64_t minor_id = 0;
  2637. if (nfserr)
  2638. return nfserr;
  2639. major_id = utsname()->nodename;
  2640. major_id_sz = strlen(major_id);
  2641. server_scope = utsname()->nodename;
  2642. server_scope_sz = strlen(server_scope);
  2643. RESERVE_SPACE(
  2644. 8 /* eir_clientid */ +
  2645. 4 /* eir_sequenceid */ +
  2646. 4 /* eir_flags */ +
  2647. 4 /* spr_how (SP4_NONE) */ +
  2648. 8 /* so_minor_id */ +
  2649. 4 /* so_major_id.len */ +
  2650. (XDR_QUADLEN(major_id_sz) * 4) +
  2651. 4 /* eir_server_scope.len */ +
  2652. (XDR_QUADLEN(server_scope_sz) * 4) +
  2653. 4 /* eir_server_impl_id.count (0) */);
  2654. WRITEMEM(&exid->clientid, 8);
  2655. WRITE32(exid->seqid);
  2656. WRITE32(exid->flags);
  2657. /* state_protect4_r. Currently only support SP4_NONE */
  2658. BUG_ON(exid->spa_how != SP4_NONE);
  2659. WRITE32(exid->spa_how);
  2660. /* The server_owner struct */
  2661. WRITE64(minor_id); /* Minor id */
  2662. /* major id */
  2663. WRITE32(major_id_sz);
  2664. WRITEMEM(major_id, major_id_sz);
  2665. /* Server scope */
  2666. WRITE32(server_scope_sz);
  2667. WRITEMEM(server_scope, server_scope_sz);
  2668. /* Implementation id */
  2669. WRITE32(0); /* zero length nfs_impl_id4 array */
  2670. ADJUST_ARGS();
  2671. return 0;
  2672. }
  2673. static __be32
  2674. nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr,
  2675. struct nfsd4_create_session *sess)
  2676. {
  2677. __be32 *p;
  2678. if (nfserr)
  2679. return nfserr;
  2680. RESERVE_SPACE(24);
  2681. WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2682. WRITE32(sess->seqid);
  2683. WRITE32(sess->flags);
  2684. ADJUST_ARGS();
  2685. RESERVE_SPACE(28);
  2686. WRITE32(0); /* headerpadsz */
  2687. WRITE32(sess->fore_channel.maxreq_sz);
  2688. WRITE32(sess->fore_channel.maxresp_sz);
  2689. WRITE32(sess->fore_channel.maxresp_cached);
  2690. WRITE32(sess->fore_channel.maxops);
  2691. WRITE32(sess->fore_channel.maxreqs);
  2692. WRITE32(sess->fore_channel.nr_rdma_attrs);
  2693. ADJUST_ARGS();
  2694. if (sess->fore_channel.nr_rdma_attrs) {
  2695. RESERVE_SPACE(4);
  2696. WRITE32(sess->fore_channel.rdma_attrs);
  2697. ADJUST_ARGS();
  2698. }
  2699. RESERVE_SPACE(28);
  2700. WRITE32(0); /* headerpadsz */
  2701. WRITE32(sess->back_channel.maxreq_sz);
  2702. WRITE32(sess->back_channel.maxresp_sz);
  2703. WRITE32(sess->back_channel.maxresp_cached);
  2704. WRITE32(sess->back_channel.maxops);
  2705. WRITE32(sess->back_channel.maxreqs);
  2706. WRITE32(sess->back_channel.nr_rdma_attrs);
  2707. ADJUST_ARGS();
  2708. if (sess->back_channel.nr_rdma_attrs) {
  2709. RESERVE_SPACE(4);
  2710. WRITE32(sess->back_channel.rdma_attrs);
  2711. ADJUST_ARGS();
  2712. }
  2713. return 0;
  2714. }
  2715. static __be32
  2716. nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr,
  2717. struct nfsd4_destroy_session *destroy_session)
  2718. {
  2719. return nfserr;
  2720. }
  2721. __be32
  2722. nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr,
  2723. struct nfsd4_sequence *seq)
  2724. {
  2725. __be32 *p;
  2726. if (nfserr)
  2727. return nfserr;
  2728. RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
  2729. WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2730. WRITE32(seq->seqid);
  2731. WRITE32(seq->slotid);
  2732. WRITE32(seq->maxslots);
  2733. /*
  2734. * FIXME: for now:
  2735. * target_maxslots = maxslots
  2736. * status_flags = 0
  2737. */
  2738. WRITE32(seq->maxslots);
  2739. WRITE32(0);
  2740. ADJUST_ARGS();
  2741. return 0;
  2742. }
  2743. static __be32
  2744. nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
  2745. {
  2746. return nfserr;
  2747. }
  2748. typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
  2749. /*
  2750. * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
  2751. * since we don't need to filter out obsolete ops as this is
  2752. * done in the decoding phase.
  2753. */
  2754. static nfsd4_enc nfsd4_enc_ops[] = {
  2755. [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
  2756. [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
  2757. [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
  2758. [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
  2759. [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
  2760. [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
  2761. [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
  2762. [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
  2763. [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
  2764. [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
  2765. [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
  2766. [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
  2767. [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
  2768. [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
  2769. [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
  2770. [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
  2771. [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
  2772. [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
  2773. [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
  2774. [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
  2775. [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
  2776. [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
  2777. [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
  2778. [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
  2779. [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
  2780. [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
  2781. [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
  2782. [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
  2783. [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
  2784. [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
  2785. [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
  2786. [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
  2787. [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
  2788. [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
  2789. [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
  2790. [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
  2791. [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
  2792. /* NFSv4.1 operations */
  2793. [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
  2794. [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_noop,
  2795. [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
  2796. [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
  2797. [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session,
  2798. [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop,
  2799. [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
  2800. [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
  2801. [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
  2802. [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
  2803. [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
  2804. [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
  2805. [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_noop,
  2806. [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
  2807. [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
  2808. [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_noop,
  2809. [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
  2810. [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
  2811. [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
  2812. };
  2813. /*
  2814. * Calculate the total amount of memory that the compound response has taken
  2815. * after encoding the current operation.
  2816. *
  2817. * pad: add on 8 bytes for the next operation's op_code and status so that
  2818. * there is room to cache a failure on the next operation.
  2819. *
  2820. * Compare this length to the session se_fmaxresp_cached.
  2821. *
  2822. * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
  2823. * will be at least a page and will therefore hold the xdr_buf head.
  2824. */
  2825. static int nfsd4_check_drc_limit(struct nfsd4_compoundres *resp)
  2826. {
  2827. int status = 0;
  2828. struct xdr_buf *xb = &resp->rqstp->rq_res;
  2829. struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
  2830. struct nfsd4_session *session = NULL;
  2831. struct nfsd4_slot *slot = resp->cstate.slot;
  2832. u32 length, tlen = 0, pad = 8;
  2833. if (!nfsd4_has_session(&resp->cstate))
  2834. return status;
  2835. session = resp->cstate.session;
  2836. if (session == NULL || slot->sl_cache_entry.ce_cachethis == 0)
  2837. return status;
  2838. if (resp->opcnt >= args->opcnt)
  2839. pad = 0; /* this is the last operation */
  2840. if (xb->page_len == 0) {
  2841. length = (char *)resp->p - (char *)xb->head[0].iov_base + pad;
  2842. } else {
  2843. if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
  2844. tlen = (char *)resp->p - (char *)xb->tail[0].iov_base;
  2845. length = xb->head[0].iov_len + xb->page_len + tlen + pad;
  2846. }
  2847. dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
  2848. length, xb->page_len, tlen, pad);
  2849. if (length <= session->se_fmaxresp_cached)
  2850. return status;
  2851. else
  2852. return nfserr_rep_too_big_to_cache;
  2853. }
  2854. void
  2855. nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
  2856. {
  2857. __be32 *statp;
  2858. __be32 *p;
  2859. RESERVE_SPACE(8);
  2860. WRITE32(op->opnum);
  2861. statp = p++; /* to be backfilled at the end */
  2862. ADJUST_ARGS();
  2863. if (op->opnum == OP_ILLEGAL)
  2864. goto status;
  2865. BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
  2866. !nfsd4_enc_ops[op->opnum]);
  2867. op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u);
  2868. /* nfsd4_check_drc_limit guarantees enough room for error status */
  2869. if (!op->status && nfsd4_check_drc_limit(resp))
  2870. op->status = nfserr_rep_too_big_to_cache;
  2871. status:
  2872. /*
  2873. * Note: We write the status directly, instead of using WRITE32(),
  2874. * since it is already in network byte order.
  2875. */
  2876. *statp = op->status;
  2877. }
  2878. /*
  2879. * Encode the reply stored in the stateowner reply cache
  2880. *
  2881. * XDR note: do not encode rp->rp_buflen: the buffer contains the
  2882. * previously sent already encoded operation.
  2883. *
  2884. * called with nfs4_lock_state() held
  2885. */
  2886. void
  2887. nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
  2888. {
  2889. __be32 *p;
  2890. struct nfs4_replay *rp = op->replay;
  2891. BUG_ON(!rp);
  2892. RESERVE_SPACE(8);
  2893. WRITE32(op->opnum);
  2894. *p++ = rp->rp_status; /* already xdr'ed */
  2895. ADJUST_ARGS();
  2896. RESERVE_SPACE(rp->rp_buflen);
  2897. WRITEMEM(rp->rp_buf, rp->rp_buflen);
  2898. ADJUST_ARGS();
  2899. }
  2900. int
  2901. nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  2902. {
  2903. return xdr_ressize_check(rqstp, p);
  2904. }
  2905. void nfsd4_release_compoundargs(struct nfsd4_compoundargs *args)
  2906. {
  2907. if (args->ops != args->iops) {
  2908. kfree(args->ops);
  2909. args->ops = args->iops;
  2910. }
  2911. kfree(args->tmpp);
  2912. args->tmpp = NULL;
  2913. while (args->to_free) {
  2914. struct tmpbuf *tb = args->to_free;
  2915. args->to_free = tb->next;
  2916. tb->release(tb->buf);
  2917. kfree(tb);
  2918. }
  2919. }
  2920. int
  2921. nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args)
  2922. {
  2923. __be32 status;
  2924. args->p = p;
  2925. args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
  2926. args->pagelist = rqstp->rq_arg.pages;
  2927. args->pagelen = rqstp->rq_arg.page_len;
  2928. args->tmpp = NULL;
  2929. args->to_free = NULL;
  2930. args->ops = args->iops;
  2931. args->rqstp = rqstp;
  2932. status = nfsd4_decode_compound(args);
  2933. if (status) {
  2934. nfsd4_release_compoundargs(args);
  2935. }
  2936. return !status;
  2937. }
  2938. int
  2939. nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp)
  2940. {
  2941. /*
  2942. * All that remains is to write the tag and operation count...
  2943. */
  2944. struct kvec *iov;
  2945. p = resp->tagp;
  2946. *p++ = htonl(resp->taglen);
  2947. memcpy(p, resp->tag, resp->taglen);
  2948. p += XDR_QUADLEN(resp->taglen);
  2949. *p++ = htonl(resp->opcnt);
  2950. if (rqstp->rq_res.page_len)
  2951. iov = &rqstp->rq_res.tail[0];
  2952. else
  2953. iov = &rqstp->rq_res.head[0];
  2954. iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
  2955. BUG_ON(iov->iov_len > PAGE_SIZE);
  2956. if (nfsd4_has_session(&resp->cstate)) {
  2957. if (resp->cstate.status == nfserr_replay_cache &&
  2958. !nfsd4_not_cached(resp)) {
  2959. iov->iov_len = resp->cstate.iovlen;
  2960. } else {
  2961. nfsd4_store_cache_entry(resp);
  2962. dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
  2963. resp->cstate.slot->sl_inuse = 0;
  2964. }
  2965. if (resp->cstate.session)
  2966. nfsd4_put_session(resp->cstate.session);
  2967. }
  2968. return 1;
  2969. }
  2970. /*
  2971. * Local variables:
  2972. * c-basic-offset: 8
  2973. * End:
  2974. */