nfs4xdr.c 90 KB

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