nfs4xdr.c 82 KB

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