nfs4xdr.c 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608
  1. /*
  2. * fs/nfs/nfs4xdr.c
  3. *
  4. * Client-side XDR for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/param.h>
  38. #include <linux/time.h>
  39. #include <linux/mm.h>
  40. #include <linux/slab.h>
  41. #include <linux/utsname.h>
  42. #include <linux/errno.h>
  43. #include <linux/string.h>
  44. #include <linux/in.h>
  45. #include <linux/pagemap.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/nfs.h>
  50. #include <linux/nfs4.h>
  51. #include <linux/nfs_fs.h>
  52. #include <linux/nfs_idmap.h>
  53. #include "nfs4_fs.h"
  54. #define NFSDBG_FACILITY NFSDBG_XDR
  55. /* Mapping from NFS error code to "errno" error code. */
  56. #define errno_NFSERR_IO EIO
  57. static int nfs4_stat_to_errno(int);
  58. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  59. #ifdef DEBUG
  60. #define NFS4_MAXTAGLEN 20
  61. #else
  62. #define NFS4_MAXTAGLEN 0
  63. #endif
  64. /* lock,open owner id:
  65. * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
  66. */
  67. #define owner_id_maxsz (1 + 1)
  68. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  69. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  70. #define op_encode_hdr_maxsz (1)
  71. #define op_decode_hdr_maxsz (2)
  72. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  73. (NFS4_FHSIZE >> 2))
  74. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  75. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  76. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  77. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  78. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  79. ((3+NFS4_FHSIZE) >> 2))
  80. #define nfs4_fattr_bitmap_maxsz 3
  81. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  82. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  83. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  84. /* This is based on getfattr, which uses the most attributes: */
  85. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  86. 3 + 3 + 3 + 2 * nfs4_name_maxsz))
  87. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  88. nfs4_fattr_value_maxsz)
  89. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  90. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  91. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  92. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  93. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  94. #define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
  95. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
  96. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  97. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  98. #define encode_setclientid_maxsz \
  99. (op_encode_hdr_maxsz + \
  100. 4 /*server->ip_addr*/ + \
  101. 1 /*Netid*/ + \
  102. 6 /*uaddr*/ + \
  103. 6 + (NFS4_VERIFIER_SIZE >> 2))
  104. #define decode_setclientid_maxsz \
  105. (op_decode_hdr_maxsz + \
  106. 2 + \
  107. 1024) /* large value for CLID_INUSE */
  108. #define encode_setclientid_confirm_maxsz \
  109. (op_encode_hdr_maxsz + \
  110. 3 + (NFS4_VERIFIER_SIZE >> 2))
  111. #define decode_setclientid_confirm_maxsz \
  112. (op_decode_hdr_maxsz)
  113. #define encode_lookup_maxsz (op_encode_hdr_maxsz + \
  114. 1 + ((3 + NFS4_FHSIZE) >> 2))
  115. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  116. nfs4_name_maxsz)
  117. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  118. 2 * nfs4_name_maxsz)
  119. #define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
  120. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  121. nfs4_name_maxsz)
  122. #define decode_link_maxsz (op_decode_hdr_maxsz + 5)
  123. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  124. 1 + nfs4_name_maxsz + \
  125. 1 + \
  126. nfs4_fattr_maxsz)
  127. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  128. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  129. 2 + nfs4_name_maxsz + \
  130. nfs4_fattr_maxsz)
  131. #define decode_create_maxsz (op_decode_hdr_maxsz + 8)
  132. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  133. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  134. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  135. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  136. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  137. encode_putfh_maxsz + \
  138. op_encode_hdr_maxsz + 7)
  139. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  140. decode_putfh_maxsz + \
  141. op_decode_hdr_maxsz + 2)
  142. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  143. encode_putfh_maxsz + \
  144. op_encode_hdr_maxsz)
  145. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  146. decode_putfh_maxsz + \
  147. op_decode_hdr_maxsz)
  148. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  149. encode_putfh_maxsz + \
  150. op_encode_hdr_maxsz + 9)
  151. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  152. decode_putfh_maxsz + \
  153. op_decode_hdr_maxsz + 2)
  154. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  155. encode_putfh_maxsz + \
  156. op_encode_hdr_maxsz + 8 + \
  157. encode_getattr_maxsz)
  158. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  159. decode_putfh_maxsz + \
  160. op_decode_hdr_maxsz + 4 + \
  161. decode_getattr_maxsz)
  162. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  163. encode_putfh_maxsz + \
  164. op_encode_hdr_maxsz + 3 + \
  165. encode_getattr_maxsz)
  166. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  167. decode_putfh_maxsz + \
  168. op_decode_hdr_maxsz + 2 + \
  169. decode_getattr_maxsz)
  170. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  171. encode_putfh_maxsz + \
  172. op_encode_hdr_maxsz + \
  173. 13 + 3 + 2 + 64 + \
  174. encode_getattr_maxsz + \
  175. encode_getfh_maxsz)
  176. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  177. decode_putfh_maxsz + \
  178. op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
  179. decode_getattr_maxsz + \
  180. decode_getfh_maxsz)
  181. #define NFS4_enc_open_confirm_sz \
  182. (compound_encode_hdr_maxsz + \
  183. encode_putfh_maxsz + \
  184. op_encode_hdr_maxsz + 5)
  185. #define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
  186. decode_putfh_maxsz + \
  187. op_decode_hdr_maxsz + 4)
  188. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  189. encode_putfh_maxsz + \
  190. op_encode_hdr_maxsz + \
  191. 11)
  192. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  193. decode_putfh_maxsz + \
  194. op_decode_hdr_maxsz + \
  195. 4 + 5 + 2 + 3)
  196. #define NFS4_enc_open_downgrade_sz \
  197. (compound_encode_hdr_maxsz + \
  198. encode_putfh_maxsz + \
  199. op_encode_hdr_maxsz + 7 + \
  200. encode_getattr_maxsz)
  201. #define NFS4_dec_open_downgrade_sz \
  202. (compound_decode_hdr_maxsz + \
  203. decode_putfh_maxsz + \
  204. op_decode_hdr_maxsz + 4 + \
  205. decode_getattr_maxsz)
  206. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  207. encode_putfh_maxsz + \
  208. op_encode_hdr_maxsz + 5 + \
  209. encode_getattr_maxsz)
  210. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  211. decode_putfh_maxsz + \
  212. op_decode_hdr_maxsz + 4 + \
  213. decode_getattr_maxsz)
  214. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  215. encode_putfh_maxsz + \
  216. op_encode_hdr_maxsz + 4 + \
  217. nfs4_fattr_maxsz + \
  218. encode_getattr_maxsz)
  219. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  220. decode_putfh_maxsz + \
  221. op_decode_hdr_maxsz + 3)
  222. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  223. encode_putfh_maxsz + \
  224. encode_fsinfo_maxsz)
  225. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  226. decode_putfh_maxsz + \
  227. decode_fsinfo_maxsz)
  228. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  229. encode_renew_maxsz)
  230. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  231. decode_renew_maxsz)
  232. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  233. encode_setclientid_maxsz)
  234. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  235. decode_setclientid_maxsz)
  236. #define NFS4_enc_setclientid_confirm_sz \
  237. (compound_encode_hdr_maxsz + \
  238. encode_setclientid_confirm_maxsz + \
  239. encode_putrootfh_maxsz + \
  240. encode_fsinfo_maxsz)
  241. #define NFS4_dec_setclientid_confirm_sz \
  242. (compound_decode_hdr_maxsz + \
  243. decode_setclientid_confirm_maxsz + \
  244. decode_putrootfh_maxsz + \
  245. decode_fsinfo_maxsz)
  246. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  247. encode_putfh_maxsz + \
  248. encode_getattr_maxsz + \
  249. op_encode_hdr_maxsz + \
  250. 1 + 1 + 2 + 2 + \
  251. 1 + 4 + 1 + 2 + \
  252. owner_id_maxsz)
  253. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  254. decode_putfh_maxsz + \
  255. decode_getattr_maxsz + \
  256. op_decode_hdr_maxsz + \
  257. 2 + 2 + 1 + 2 + \
  258. owner_id_maxsz)
  259. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  260. encode_putfh_maxsz + \
  261. encode_getattr_maxsz + \
  262. op_encode_hdr_maxsz + \
  263. 1 + 2 + 2 + 2 + \
  264. owner_id_maxsz)
  265. #define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
  266. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  267. encode_putfh_maxsz + \
  268. encode_getattr_maxsz + \
  269. op_encode_hdr_maxsz + \
  270. 1 + 1 + 4 + 2 + 2)
  271. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  272. decode_putfh_maxsz + \
  273. decode_getattr_maxsz + \
  274. op_decode_hdr_maxsz + 4)
  275. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  276. encode_putfh_maxsz + \
  277. op_encode_hdr_maxsz + 1)
  278. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  279. decode_putfh_maxsz + \
  280. op_decode_hdr_maxsz + 2)
  281. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  282. encode_putfh_maxsz + \
  283. encode_getattr_maxsz)
  284. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  285. decode_putfh_maxsz + \
  286. decode_getattr_maxsz)
  287. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  288. encode_putfh_maxsz + \
  289. encode_lookup_maxsz + \
  290. encode_getattr_maxsz + \
  291. encode_getfh_maxsz)
  292. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  293. decode_putfh_maxsz + \
  294. op_decode_hdr_maxsz + \
  295. decode_getattr_maxsz + \
  296. decode_getfh_maxsz)
  297. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  298. encode_putrootfh_maxsz + \
  299. encode_getattr_maxsz + \
  300. encode_getfh_maxsz)
  301. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  302. decode_putrootfh_maxsz + \
  303. decode_getattr_maxsz + \
  304. decode_getfh_maxsz)
  305. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  306. encode_putfh_maxsz + \
  307. encode_remove_maxsz + \
  308. encode_getattr_maxsz)
  309. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  310. decode_putfh_maxsz + \
  311. op_decode_hdr_maxsz + 5 + \
  312. decode_getattr_maxsz)
  313. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  314. encode_putfh_maxsz + \
  315. encode_savefh_maxsz + \
  316. encode_putfh_maxsz + \
  317. encode_rename_maxsz + \
  318. encode_getattr_maxsz + \
  319. encode_restorefh_maxsz + \
  320. encode_getattr_maxsz)
  321. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  322. decode_putfh_maxsz + \
  323. decode_savefh_maxsz + \
  324. decode_putfh_maxsz + \
  325. decode_rename_maxsz + \
  326. decode_getattr_maxsz + \
  327. decode_restorefh_maxsz + \
  328. decode_getattr_maxsz)
  329. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  330. encode_putfh_maxsz + \
  331. encode_savefh_maxsz + \
  332. encode_putfh_maxsz + \
  333. encode_link_maxsz + \
  334. decode_getattr_maxsz + \
  335. encode_restorefh_maxsz + \
  336. decode_getattr_maxsz)
  337. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  338. decode_putfh_maxsz + \
  339. decode_savefh_maxsz + \
  340. decode_putfh_maxsz + \
  341. decode_link_maxsz + \
  342. decode_getattr_maxsz + \
  343. decode_restorefh_maxsz + \
  344. decode_getattr_maxsz)
  345. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  346. encode_putfh_maxsz + \
  347. encode_symlink_maxsz + \
  348. encode_getattr_maxsz + \
  349. encode_getfh_maxsz)
  350. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  351. decode_putfh_maxsz + \
  352. decode_symlink_maxsz + \
  353. decode_getattr_maxsz + \
  354. decode_getfh_maxsz)
  355. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  356. encode_putfh_maxsz + \
  357. encode_savefh_maxsz + \
  358. encode_create_maxsz + \
  359. encode_getfh_maxsz + \
  360. encode_getattr_maxsz + \
  361. encode_restorefh_maxsz + \
  362. encode_getattr_maxsz)
  363. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  364. decode_putfh_maxsz + \
  365. decode_savefh_maxsz + \
  366. decode_create_maxsz + \
  367. decode_getfh_maxsz + \
  368. decode_getattr_maxsz + \
  369. decode_restorefh_maxsz + \
  370. decode_getattr_maxsz)
  371. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  372. encode_putfh_maxsz + \
  373. encode_getattr_maxsz)
  374. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  375. decode_putfh_maxsz + \
  376. decode_getattr_maxsz)
  377. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  378. encode_putfh_maxsz + \
  379. encode_getattr_maxsz)
  380. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  381. decode_putfh_maxsz + \
  382. op_decode_hdr_maxsz + 12)
  383. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  384. encode_getattr_maxsz)
  385. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  386. decode_getattr_maxsz)
  387. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  388. encode_putfh_maxsz + \
  389. encode_delegreturn_maxsz + \
  390. encode_getattr_maxsz)
  391. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  392. decode_delegreturn_maxsz + \
  393. decode_getattr_maxsz)
  394. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  395. encode_putfh_maxsz + \
  396. encode_getattr_maxsz)
  397. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  398. decode_putfh_maxsz + \
  399. op_decode_hdr_maxsz + \
  400. nfs4_fattr_bitmap_maxsz + 1)
  401. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  402. encode_putfh_maxsz + \
  403. op_encode_hdr_maxsz + 4 + \
  404. nfs4_fattr_bitmap_maxsz + 1)
  405. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  406. decode_putfh_maxsz + \
  407. op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  408. #define NFS4_enc_fs_locations_sz \
  409. (compound_encode_hdr_maxsz + \
  410. encode_putfh_maxsz + \
  411. encode_getattr_maxsz)
  412. #define NFS4_dec_fs_locations_sz \
  413. (compound_decode_hdr_maxsz + \
  414. decode_putfh_maxsz + \
  415. op_decode_hdr_maxsz + \
  416. nfs4_fattr_bitmap_maxsz)
  417. static struct {
  418. unsigned int mode;
  419. unsigned int nfs2type;
  420. } nfs_type2fmt[] = {
  421. { 0, NFNON },
  422. { S_IFREG, NFREG },
  423. { S_IFDIR, NFDIR },
  424. { S_IFBLK, NFBLK },
  425. { S_IFCHR, NFCHR },
  426. { S_IFLNK, NFLNK },
  427. { S_IFSOCK, NFSOCK },
  428. { S_IFIFO, NFFIFO },
  429. { 0, NFNON },
  430. { 0, NFNON },
  431. };
  432. struct compound_hdr {
  433. int32_t status;
  434. uint32_t nops;
  435. uint32_t taglen;
  436. char * tag;
  437. };
  438. /*
  439. * START OF "GENERIC" ENCODE ROUTINES.
  440. * These may look a little ugly since they are imported from a "generic"
  441. * set of XDR encode/decode routines which are intended to be shared by
  442. * all of our NFSv4 implementations (OpenBSD, MacOS X...).
  443. *
  444. * If the pain of reading these is too great, it should be a straightforward
  445. * task to translate them into Linux-specific versions which are more
  446. * consistent with the style used in NFSv2/v3...
  447. */
  448. #define WRITE32(n) *p++ = htonl(n)
  449. #define WRITE64(n) do { \
  450. *p++ = htonl((uint32_t)((n) >> 32)); \
  451. *p++ = htonl((uint32_t)(n)); \
  452. } while (0)
  453. #define WRITEMEM(ptr,nbytes) do { \
  454. p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
  455. } while (0)
  456. #define RESERVE_SPACE(nbytes) do { \
  457. p = xdr_reserve_space(xdr, nbytes); \
  458. if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
  459. BUG_ON(!p); \
  460. } while (0)
  461. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  462. {
  463. __be32 *p;
  464. p = xdr_reserve_space(xdr, 4 + len);
  465. BUG_ON(p == NULL);
  466. xdr_encode_opaque(p, str, len);
  467. }
  468. static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  469. {
  470. __be32 *p;
  471. dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
  472. BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
  473. RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
  474. WRITE32(hdr->taglen);
  475. WRITEMEM(hdr->tag, hdr->taglen);
  476. WRITE32(NFS4_MINOR_VERSION);
  477. WRITE32(hdr->nops);
  478. return 0;
  479. }
  480. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  481. {
  482. __be32 *p;
  483. p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
  484. BUG_ON(p == NULL);
  485. xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
  486. }
  487. static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
  488. {
  489. char owner_name[IDMAP_NAMESZ];
  490. char owner_group[IDMAP_NAMESZ];
  491. int owner_namelen = 0;
  492. int owner_grouplen = 0;
  493. __be32 *p;
  494. __be32 *q;
  495. int len;
  496. uint32_t bmval0 = 0;
  497. uint32_t bmval1 = 0;
  498. int status;
  499. /*
  500. * We reserve enough space to write the entire attribute buffer at once.
  501. * In the worst-case, this would be
  502. * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
  503. * = 36 bytes, plus any contribution from variable-length fields
  504. * such as owner/group.
  505. */
  506. len = 16;
  507. /* Sigh */
  508. if (iap->ia_valid & ATTR_SIZE)
  509. len += 8;
  510. if (iap->ia_valid & ATTR_MODE)
  511. len += 4;
  512. if (iap->ia_valid & ATTR_UID) {
  513. owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
  514. if (owner_namelen < 0) {
  515. printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
  516. iap->ia_uid);
  517. /* XXX */
  518. strcpy(owner_name, "nobody");
  519. owner_namelen = sizeof("nobody") - 1;
  520. /* goto out; */
  521. }
  522. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  523. }
  524. if (iap->ia_valid & ATTR_GID) {
  525. owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
  526. if (owner_grouplen < 0) {
  527. printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
  528. iap->ia_gid);
  529. strcpy(owner_group, "nobody");
  530. owner_grouplen = sizeof("nobody") - 1;
  531. /* goto out; */
  532. }
  533. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  534. }
  535. if (iap->ia_valid & ATTR_ATIME_SET)
  536. len += 16;
  537. else if (iap->ia_valid & ATTR_ATIME)
  538. len += 4;
  539. if (iap->ia_valid & ATTR_MTIME_SET)
  540. len += 16;
  541. else if (iap->ia_valid & ATTR_MTIME)
  542. len += 4;
  543. RESERVE_SPACE(len);
  544. /*
  545. * We write the bitmap length now, but leave the bitmap and the attribute
  546. * buffer length to be backfilled at the end of this routine.
  547. */
  548. WRITE32(2);
  549. q = p;
  550. p += 3;
  551. if (iap->ia_valid & ATTR_SIZE) {
  552. bmval0 |= FATTR4_WORD0_SIZE;
  553. WRITE64(iap->ia_size);
  554. }
  555. if (iap->ia_valid & ATTR_MODE) {
  556. bmval1 |= FATTR4_WORD1_MODE;
  557. WRITE32(iap->ia_mode & S_IALLUGO);
  558. }
  559. if (iap->ia_valid & ATTR_UID) {
  560. bmval1 |= FATTR4_WORD1_OWNER;
  561. WRITE32(owner_namelen);
  562. WRITEMEM(owner_name, owner_namelen);
  563. }
  564. if (iap->ia_valid & ATTR_GID) {
  565. bmval1 |= FATTR4_WORD1_OWNER_GROUP;
  566. WRITE32(owner_grouplen);
  567. WRITEMEM(owner_group, owner_grouplen);
  568. }
  569. if (iap->ia_valid & ATTR_ATIME_SET) {
  570. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  571. WRITE32(NFS4_SET_TO_CLIENT_TIME);
  572. WRITE32(0);
  573. WRITE32(iap->ia_mtime.tv_sec);
  574. WRITE32(iap->ia_mtime.tv_nsec);
  575. }
  576. else if (iap->ia_valid & ATTR_ATIME) {
  577. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  578. WRITE32(NFS4_SET_TO_SERVER_TIME);
  579. }
  580. if (iap->ia_valid & ATTR_MTIME_SET) {
  581. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  582. WRITE32(NFS4_SET_TO_CLIENT_TIME);
  583. WRITE32(0);
  584. WRITE32(iap->ia_mtime.tv_sec);
  585. WRITE32(iap->ia_mtime.tv_nsec);
  586. }
  587. else if (iap->ia_valid & ATTR_MTIME) {
  588. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  589. WRITE32(NFS4_SET_TO_SERVER_TIME);
  590. }
  591. /*
  592. * Now we backfill the bitmap and the attribute buffer length.
  593. */
  594. if (len != ((char *)p - (char *)q) + 4) {
  595. printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
  596. len, ((char *)p - (char *)q) + 4);
  597. BUG();
  598. }
  599. len = (char *)p - (char *)q - 12;
  600. *q++ = htonl(bmval0);
  601. *q++ = htonl(bmval1);
  602. *q++ = htonl(len);
  603. status = 0;
  604. /* out: */
  605. return status;
  606. }
  607. static int encode_access(struct xdr_stream *xdr, u32 access)
  608. {
  609. __be32 *p;
  610. RESERVE_SPACE(8);
  611. WRITE32(OP_ACCESS);
  612. WRITE32(access);
  613. return 0;
  614. }
  615. static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
  616. {
  617. __be32 *p;
  618. RESERVE_SPACE(8+sizeof(arg->stateid->data));
  619. WRITE32(OP_CLOSE);
  620. WRITE32(arg->seqid->sequence->counter);
  621. WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
  622. return 0;
  623. }
  624. static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
  625. {
  626. __be32 *p;
  627. RESERVE_SPACE(16);
  628. WRITE32(OP_COMMIT);
  629. WRITE64(args->offset);
  630. WRITE32(args->count);
  631. return 0;
  632. }
  633. static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
  634. {
  635. __be32 *p;
  636. RESERVE_SPACE(8);
  637. WRITE32(OP_CREATE);
  638. WRITE32(create->ftype);
  639. switch (create->ftype) {
  640. case NF4LNK:
  641. RESERVE_SPACE(4);
  642. WRITE32(create->u.symlink.len);
  643. xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
  644. break;
  645. case NF4BLK: case NF4CHR:
  646. RESERVE_SPACE(8);
  647. WRITE32(create->u.device.specdata1);
  648. WRITE32(create->u.device.specdata2);
  649. break;
  650. default:
  651. break;
  652. }
  653. RESERVE_SPACE(4 + create->name->len);
  654. WRITE32(create->name->len);
  655. WRITEMEM(create->name->name, create->name->len);
  656. return encode_attrs(xdr, create->attrs, create->server);
  657. }
  658. static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
  659. {
  660. __be32 *p;
  661. RESERVE_SPACE(12);
  662. WRITE32(OP_GETATTR);
  663. WRITE32(1);
  664. WRITE32(bitmap);
  665. return 0;
  666. }
  667. static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
  668. {
  669. __be32 *p;
  670. RESERVE_SPACE(16);
  671. WRITE32(OP_GETATTR);
  672. WRITE32(2);
  673. WRITE32(bm0);
  674. WRITE32(bm1);
  675. return 0;
  676. }
  677. static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
  678. {
  679. return encode_getattr_two(xdr,
  680. bitmask[0] & nfs4_fattr_bitmap[0],
  681. bitmask[1] & nfs4_fattr_bitmap[1]);
  682. }
  683. static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
  684. {
  685. return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
  686. bitmask[1] & nfs4_fsinfo_bitmap[1]);
  687. }
  688. static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
  689. {
  690. return encode_getattr_two(xdr,
  691. bitmask[0] & nfs4_fs_locations_bitmap[0],
  692. bitmask[1] & nfs4_fs_locations_bitmap[1]);
  693. }
  694. static int encode_getfh(struct xdr_stream *xdr)
  695. {
  696. __be32 *p;
  697. RESERVE_SPACE(4);
  698. WRITE32(OP_GETFH);
  699. return 0;
  700. }
  701. static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
  702. {
  703. __be32 *p;
  704. RESERVE_SPACE(8 + name->len);
  705. WRITE32(OP_LINK);
  706. WRITE32(name->len);
  707. WRITEMEM(name->name, name->len);
  708. return 0;
  709. }
  710. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  711. {
  712. if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
  713. return block ? NFS4_READW_LT : NFS4_READ_LT;
  714. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  715. }
  716. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  717. {
  718. if (fl->fl_end == OFFSET_MAX)
  719. return ~(uint64_t)0;
  720. return fl->fl_end - fl->fl_start + 1;
  721. }
  722. /*
  723. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  724. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  725. */
  726. static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
  727. {
  728. __be32 *p;
  729. RESERVE_SPACE(32);
  730. WRITE32(OP_LOCK);
  731. WRITE32(nfs4_lock_type(args->fl, args->block));
  732. WRITE32(args->reclaim);
  733. WRITE64(args->fl->fl_start);
  734. WRITE64(nfs4_lock_length(args->fl));
  735. WRITE32(args->new_lock_owner);
  736. if (args->new_lock_owner){
  737. RESERVE_SPACE(40);
  738. WRITE32(args->open_seqid->sequence->counter);
  739. WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
  740. WRITE32(args->lock_seqid->sequence->counter);
  741. WRITE64(args->lock_owner.clientid);
  742. WRITE32(4);
  743. WRITE32(args->lock_owner.id);
  744. }
  745. else {
  746. RESERVE_SPACE(20);
  747. WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
  748. WRITE32(args->lock_seqid->sequence->counter);
  749. }
  750. return 0;
  751. }
  752. static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
  753. {
  754. __be32 *p;
  755. RESERVE_SPACE(40);
  756. WRITE32(OP_LOCKT);
  757. WRITE32(nfs4_lock_type(args->fl, 0));
  758. WRITE64(args->fl->fl_start);
  759. WRITE64(nfs4_lock_length(args->fl));
  760. WRITE64(args->lock_owner.clientid);
  761. WRITE32(4);
  762. WRITE32(args->lock_owner.id);
  763. return 0;
  764. }
  765. static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
  766. {
  767. __be32 *p;
  768. RESERVE_SPACE(44);
  769. WRITE32(OP_LOCKU);
  770. WRITE32(nfs4_lock_type(args->fl, 0));
  771. WRITE32(args->seqid->sequence->counter);
  772. WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
  773. WRITE64(args->fl->fl_start);
  774. WRITE64(nfs4_lock_length(args->fl));
  775. return 0;
  776. }
  777. static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
  778. {
  779. int len = name->len;
  780. __be32 *p;
  781. RESERVE_SPACE(8 + len);
  782. WRITE32(OP_LOOKUP);
  783. WRITE32(len);
  784. WRITEMEM(name->name, len);
  785. return 0;
  786. }
  787. static void encode_share_access(struct xdr_stream *xdr, int open_flags)
  788. {
  789. __be32 *p;
  790. RESERVE_SPACE(8);
  791. switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
  792. case FMODE_READ:
  793. WRITE32(NFS4_SHARE_ACCESS_READ);
  794. break;
  795. case FMODE_WRITE:
  796. WRITE32(NFS4_SHARE_ACCESS_WRITE);
  797. break;
  798. case FMODE_READ|FMODE_WRITE:
  799. WRITE32(NFS4_SHARE_ACCESS_BOTH);
  800. break;
  801. default:
  802. BUG();
  803. }
  804. WRITE32(0); /* for linux, share_deny = 0 always */
  805. }
  806. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  807. {
  808. __be32 *p;
  809. /*
  810. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  811. * owner 4 = 32
  812. */
  813. RESERVE_SPACE(8);
  814. WRITE32(OP_OPEN);
  815. WRITE32(arg->seqid->sequence->counter);
  816. encode_share_access(xdr, arg->open_flags);
  817. RESERVE_SPACE(16);
  818. WRITE64(arg->clientid);
  819. WRITE32(4);
  820. WRITE32(arg->id);
  821. }
  822. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  823. {
  824. __be32 *p;
  825. RESERVE_SPACE(4);
  826. switch(arg->open_flags & O_EXCL) {
  827. case 0:
  828. WRITE32(NFS4_CREATE_UNCHECKED);
  829. encode_attrs(xdr, arg->u.attrs, arg->server);
  830. break;
  831. default:
  832. WRITE32(NFS4_CREATE_EXCLUSIVE);
  833. encode_nfs4_verifier(xdr, &arg->u.verifier);
  834. }
  835. }
  836. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  837. {
  838. __be32 *p;
  839. RESERVE_SPACE(4);
  840. switch (arg->open_flags & O_CREAT) {
  841. case 0:
  842. WRITE32(NFS4_OPEN_NOCREATE);
  843. break;
  844. default:
  845. BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
  846. WRITE32(NFS4_OPEN_CREATE);
  847. encode_createmode(xdr, arg);
  848. }
  849. }
  850. static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
  851. {
  852. __be32 *p;
  853. RESERVE_SPACE(4);
  854. switch (delegation_type) {
  855. case 0:
  856. WRITE32(NFS4_OPEN_DELEGATE_NONE);
  857. break;
  858. case FMODE_READ:
  859. WRITE32(NFS4_OPEN_DELEGATE_READ);
  860. break;
  861. case FMODE_WRITE|FMODE_READ:
  862. WRITE32(NFS4_OPEN_DELEGATE_WRITE);
  863. break;
  864. default:
  865. BUG();
  866. }
  867. }
  868. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  869. {
  870. __be32 *p;
  871. RESERVE_SPACE(4);
  872. WRITE32(NFS4_OPEN_CLAIM_NULL);
  873. encode_string(xdr, name->len, name->name);
  874. }
  875. static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
  876. {
  877. __be32 *p;
  878. RESERVE_SPACE(4);
  879. WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
  880. encode_delegation_type(xdr, type);
  881. }
  882. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  883. {
  884. __be32 *p;
  885. RESERVE_SPACE(4+sizeof(stateid->data));
  886. WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  887. WRITEMEM(stateid->data, sizeof(stateid->data));
  888. encode_string(xdr, name->len, name->name);
  889. }
  890. static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  891. {
  892. encode_openhdr(xdr, arg);
  893. encode_opentype(xdr, arg);
  894. switch (arg->claim) {
  895. case NFS4_OPEN_CLAIM_NULL:
  896. encode_claim_null(xdr, arg->name);
  897. break;
  898. case NFS4_OPEN_CLAIM_PREVIOUS:
  899. encode_claim_previous(xdr, arg->u.delegation_type);
  900. break;
  901. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  902. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  903. break;
  904. default:
  905. BUG();
  906. }
  907. return 0;
  908. }
  909. static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
  910. {
  911. __be32 *p;
  912. RESERVE_SPACE(8+sizeof(arg->stateid->data));
  913. WRITE32(OP_OPEN_CONFIRM);
  914. WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
  915. WRITE32(arg->seqid->sequence->counter);
  916. return 0;
  917. }
  918. static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
  919. {
  920. __be32 *p;
  921. RESERVE_SPACE(8+sizeof(arg->stateid->data));
  922. WRITE32(OP_OPEN_DOWNGRADE);
  923. WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
  924. WRITE32(arg->seqid->sequence->counter);
  925. encode_share_access(xdr, arg->open_flags);
  926. return 0;
  927. }
  928. static int
  929. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
  930. {
  931. int len = fh->size;
  932. __be32 *p;
  933. RESERVE_SPACE(8 + len);
  934. WRITE32(OP_PUTFH);
  935. WRITE32(len);
  936. WRITEMEM(fh->data, len);
  937. return 0;
  938. }
  939. static int encode_putrootfh(struct xdr_stream *xdr)
  940. {
  941. __be32 *p;
  942. RESERVE_SPACE(4);
  943. WRITE32(OP_PUTROOTFH);
  944. return 0;
  945. }
  946. static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
  947. {
  948. nfs4_stateid stateid;
  949. __be32 *p;
  950. RESERVE_SPACE(16);
  951. if (ctx->state != NULL) {
  952. nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
  953. WRITEMEM(stateid.data, sizeof(stateid.data));
  954. } else
  955. WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
  956. }
  957. static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
  958. {
  959. __be32 *p;
  960. RESERVE_SPACE(4);
  961. WRITE32(OP_READ);
  962. encode_stateid(xdr, args->context);
  963. RESERVE_SPACE(12);
  964. WRITE64(args->offset);
  965. WRITE32(args->count);
  966. return 0;
  967. }
  968. static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
  969. {
  970. struct rpc_auth *auth = req->rq_task->tk_auth;
  971. uint32_t attrs[2] = {
  972. FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
  973. FATTR4_WORD1_MOUNTED_ON_FILEID,
  974. };
  975. int replen;
  976. __be32 *p;
  977. RESERVE_SPACE(32+sizeof(nfs4_verifier));
  978. WRITE32(OP_READDIR);
  979. WRITE64(readdir->cookie);
  980. WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
  981. WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
  982. WRITE32(readdir->count);
  983. WRITE32(2);
  984. /* Switch to mounted_on_fileid if the server supports it */
  985. if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
  986. attrs[0] &= ~FATTR4_WORD0_FILEID;
  987. else
  988. attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  989. WRITE32(attrs[0] & readdir->bitmask[0]);
  990. WRITE32(attrs[1] & readdir->bitmask[1]);
  991. dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
  992. __FUNCTION__,
  993. (unsigned long long)readdir->cookie,
  994. ((u32 *)readdir->verifier.data)[0],
  995. ((u32 *)readdir->verifier.data)[1],
  996. attrs[0] & readdir->bitmask[0],
  997. attrs[1] & readdir->bitmask[1]);
  998. /* set up reply kvec
  999. * toplevel_status + taglen + rescount + OP_PUTFH + status
  1000. * + OP_READDIR + status + verifer(2) = 9
  1001. */
  1002. replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
  1003. xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
  1004. readdir->pgbase, readdir->count);
  1005. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  1006. __FUNCTION__, replen, readdir->pages,
  1007. readdir->pgbase, readdir->count);
  1008. return 0;
  1009. }
  1010. static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
  1011. {
  1012. struct rpc_auth *auth = req->rq_task->tk_auth;
  1013. unsigned int replen;
  1014. __be32 *p;
  1015. RESERVE_SPACE(4);
  1016. WRITE32(OP_READLINK);
  1017. /* set up reply kvec
  1018. * toplevel_status + taglen + rescount + OP_PUTFH + status
  1019. * + OP_READLINK + status + string length = 8
  1020. */
  1021. replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
  1022. xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
  1023. readlink->pgbase, readlink->pglen);
  1024. return 0;
  1025. }
  1026. static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
  1027. {
  1028. __be32 *p;
  1029. RESERVE_SPACE(8 + name->len);
  1030. WRITE32(OP_REMOVE);
  1031. WRITE32(name->len);
  1032. WRITEMEM(name->name, name->len);
  1033. return 0;
  1034. }
  1035. static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
  1036. {
  1037. __be32 *p;
  1038. RESERVE_SPACE(8 + oldname->len);
  1039. WRITE32(OP_RENAME);
  1040. WRITE32(oldname->len);
  1041. WRITEMEM(oldname->name, oldname->len);
  1042. RESERVE_SPACE(4 + newname->len);
  1043. WRITE32(newname->len);
  1044. WRITEMEM(newname->name, newname->len);
  1045. return 0;
  1046. }
  1047. static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
  1048. {
  1049. __be32 *p;
  1050. RESERVE_SPACE(12);
  1051. WRITE32(OP_RENEW);
  1052. WRITE64(client_stateid->cl_clientid);
  1053. return 0;
  1054. }
  1055. static int
  1056. encode_restorefh(struct xdr_stream *xdr)
  1057. {
  1058. __be32 *p;
  1059. RESERVE_SPACE(4);
  1060. WRITE32(OP_RESTOREFH);
  1061. return 0;
  1062. }
  1063. static int
  1064. encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
  1065. {
  1066. __be32 *p;
  1067. RESERVE_SPACE(4+sizeof(zero_stateid.data));
  1068. WRITE32(OP_SETATTR);
  1069. WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
  1070. RESERVE_SPACE(2*4);
  1071. WRITE32(1);
  1072. WRITE32(FATTR4_WORD0_ACL);
  1073. if (arg->acl_len % 4)
  1074. return -EINVAL;
  1075. RESERVE_SPACE(4);
  1076. WRITE32(arg->acl_len);
  1077. xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
  1078. return 0;
  1079. }
  1080. static int
  1081. encode_savefh(struct xdr_stream *xdr)
  1082. {
  1083. __be32 *p;
  1084. RESERVE_SPACE(4);
  1085. WRITE32(OP_SAVEFH);
  1086. return 0;
  1087. }
  1088. static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
  1089. {
  1090. int status;
  1091. __be32 *p;
  1092. RESERVE_SPACE(4+sizeof(arg->stateid.data));
  1093. WRITE32(OP_SETATTR);
  1094. WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
  1095. if ((status = encode_attrs(xdr, arg->iap, server)))
  1096. return status;
  1097. return 0;
  1098. }
  1099. static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
  1100. {
  1101. __be32 *p;
  1102. RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
  1103. WRITE32(OP_SETCLIENTID);
  1104. WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
  1105. encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
  1106. RESERVE_SPACE(4);
  1107. WRITE32(setclientid->sc_prog);
  1108. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1109. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1110. RESERVE_SPACE(4);
  1111. WRITE32(setclientid->sc_cb_ident);
  1112. return 0;
  1113. }
  1114. static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
  1115. {
  1116. __be32 *p;
  1117. RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
  1118. WRITE32(OP_SETCLIENTID_CONFIRM);
  1119. WRITE64(client_state->cl_clientid);
  1120. WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
  1121. return 0;
  1122. }
  1123. static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
  1124. {
  1125. __be32 *p;
  1126. RESERVE_SPACE(4);
  1127. WRITE32(OP_WRITE);
  1128. encode_stateid(xdr, args->context);
  1129. RESERVE_SPACE(16);
  1130. WRITE64(args->offset);
  1131. WRITE32(args->stable);
  1132. WRITE32(args->count);
  1133. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1134. return 0;
  1135. }
  1136. static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1137. {
  1138. __be32 *p;
  1139. RESERVE_SPACE(20);
  1140. WRITE32(OP_DELEGRETURN);
  1141. WRITEMEM(stateid->data, sizeof(stateid->data));
  1142. return 0;
  1143. }
  1144. /*
  1145. * END OF "GENERIC" ENCODE ROUTINES.
  1146. */
  1147. /*
  1148. * Encode an ACCESS request
  1149. */
  1150. static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
  1151. {
  1152. struct xdr_stream xdr;
  1153. struct compound_hdr hdr = {
  1154. .nops = 2,
  1155. };
  1156. int status;
  1157. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1158. encode_compound_hdr(&xdr, &hdr);
  1159. if ((status = encode_putfh(&xdr, args->fh)) == 0)
  1160. status = encode_access(&xdr, args->access);
  1161. return status;
  1162. }
  1163. /*
  1164. * Encode LOOKUP request
  1165. */
  1166. static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
  1167. {
  1168. struct xdr_stream xdr;
  1169. struct compound_hdr hdr = {
  1170. .nops = 4,
  1171. };
  1172. int status;
  1173. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1174. encode_compound_hdr(&xdr, &hdr);
  1175. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1176. goto out;
  1177. if ((status = encode_lookup(&xdr, args->name)) != 0)
  1178. goto out;
  1179. if ((status = encode_getfh(&xdr)) != 0)
  1180. goto out;
  1181. status = encode_getfattr(&xdr, args->bitmask);
  1182. out:
  1183. return status;
  1184. }
  1185. /*
  1186. * Encode LOOKUP_ROOT request
  1187. */
  1188. static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
  1189. {
  1190. struct xdr_stream xdr;
  1191. struct compound_hdr hdr = {
  1192. .nops = 3,
  1193. };
  1194. int status;
  1195. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1196. encode_compound_hdr(&xdr, &hdr);
  1197. if ((status = encode_putrootfh(&xdr)) != 0)
  1198. goto out;
  1199. if ((status = encode_getfh(&xdr)) == 0)
  1200. status = encode_getfattr(&xdr, args->bitmask);
  1201. out:
  1202. return status;
  1203. }
  1204. /*
  1205. * Encode REMOVE request
  1206. */
  1207. static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
  1208. {
  1209. struct xdr_stream xdr;
  1210. struct compound_hdr hdr = {
  1211. .nops = 3,
  1212. };
  1213. int status;
  1214. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1215. encode_compound_hdr(&xdr, &hdr);
  1216. if ((status = encode_putfh(&xdr, args->fh)) != 0)
  1217. goto out;
  1218. if ((status = encode_remove(&xdr, args->name)) != 0)
  1219. goto out;
  1220. status = encode_getfattr(&xdr, args->bitmask);
  1221. out:
  1222. return status;
  1223. }
  1224. /*
  1225. * Encode RENAME request
  1226. */
  1227. static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
  1228. {
  1229. struct xdr_stream xdr;
  1230. struct compound_hdr hdr = {
  1231. .nops = 7,
  1232. };
  1233. int status;
  1234. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1235. encode_compound_hdr(&xdr, &hdr);
  1236. if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
  1237. goto out;
  1238. if ((status = encode_savefh(&xdr)) != 0)
  1239. goto out;
  1240. if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
  1241. goto out;
  1242. if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
  1243. goto out;
  1244. if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
  1245. goto out;
  1246. if ((status = encode_restorefh(&xdr)) != 0)
  1247. goto out;
  1248. status = encode_getfattr(&xdr, args->bitmask);
  1249. out:
  1250. return status;
  1251. }
  1252. /*
  1253. * Encode LINK request
  1254. */
  1255. static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
  1256. {
  1257. struct xdr_stream xdr;
  1258. struct compound_hdr hdr = {
  1259. .nops = 7,
  1260. };
  1261. int status;
  1262. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1263. encode_compound_hdr(&xdr, &hdr);
  1264. if ((status = encode_putfh(&xdr, args->fh)) != 0)
  1265. goto out;
  1266. if ((status = encode_savefh(&xdr)) != 0)
  1267. goto out;
  1268. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1269. goto out;
  1270. if ((status = encode_link(&xdr, args->name)) != 0)
  1271. goto out;
  1272. if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
  1273. goto out;
  1274. if ((status = encode_restorefh(&xdr)) != 0)
  1275. goto out;
  1276. status = encode_getfattr(&xdr, args->bitmask);
  1277. out:
  1278. return status;
  1279. }
  1280. /*
  1281. * Encode CREATE request
  1282. */
  1283. static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
  1284. {
  1285. struct xdr_stream xdr;
  1286. struct compound_hdr hdr = {
  1287. .nops = 7,
  1288. };
  1289. int status;
  1290. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1291. encode_compound_hdr(&xdr, &hdr);
  1292. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1293. goto out;
  1294. if ((status = encode_savefh(&xdr)) != 0)
  1295. goto out;
  1296. if ((status = encode_create(&xdr, args)) != 0)
  1297. goto out;
  1298. if ((status = encode_getfh(&xdr)) != 0)
  1299. goto out;
  1300. if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
  1301. goto out;
  1302. if ((status = encode_restorefh(&xdr)) != 0)
  1303. goto out;
  1304. status = encode_getfattr(&xdr, args->bitmask);
  1305. out:
  1306. return status;
  1307. }
  1308. /*
  1309. * Encode SYMLINK request
  1310. */
  1311. static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
  1312. {
  1313. return nfs4_xdr_enc_create(req, p, args);
  1314. }
  1315. /*
  1316. * Encode GETATTR request
  1317. */
  1318. static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
  1319. {
  1320. struct xdr_stream xdr;
  1321. struct compound_hdr hdr = {
  1322. .nops = 2,
  1323. };
  1324. int status;
  1325. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1326. encode_compound_hdr(&xdr, &hdr);
  1327. if ((status = encode_putfh(&xdr, args->fh)) == 0)
  1328. status = encode_getfattr(&xdr, args->bitmask);
  1329. return status;
  1330. }
  1331. /*
  1332. * Encode a CLOSE request
  1333. */
  1334. static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
  1335. {
  1336. struct xdr_stream xdr;
  1337. struct compound_hdr hdr = {
  1338. .nops = 3,
  1339. };
  1340. int status;
  1341. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1342. encode_compound_hdr(&xdr, &hdr);
  1343. status = encode_putfh(&xdr, args->fh);
  1344. if(status)
  1345. goto out;
  1346. status = encode_close(&xdr, args);
  1347. if (status != 0)
  1348. goto out;
  1349. status = encode_getfattr(&xdr, args->bitmask);
  1350. out:
  1351. return status;
  1352. }
  1353. /*
  1354. * Encode an OPEN request
  1355. */
  1356. static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
  1357. {
  1358. struct xdr_stream xdr;
  1359. struct compound_hdr hdr = {
  1360. .nops = 7,
  1361. };
  1362. int status;
  1363. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1364. encode_compound_hdr(&xdr, &hdr);
  1365. status = encode_putfh(&xdr, args->fh);
  1366. if (status)
  1367. goto out;
  1368. status = encode_savefh(&xdr);
  1369. if (status)
  1370. goto out;
  1371. status = encode_open(&xdr, args);
  1372. if (status)
  1373. goto out;
  1374. status = encode_getfh(&xdr);
  1375. if (status)
  1376. goto out;
  1377. status = encode_getfattr(&xdr, args->bitmask);
  1378. if (status)
  1379. goto out;
  1380. status = encode_restorefh(&xdr);
  1381. if (status)
  1382. goto out;
  1383. status = encode_getfattr(&xdr, args->bitmask);
  1384. out:
  1385. return status;
  1386. }
  1387. /*
  1388. * Encode an OPEN_CONFIRM request
  1389. */
  1390. static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
  1391. {
  1392. struct xdr_stream xdr;
  1393. struct compound_hdr hdr = {
  1394. .nops = 2,
  1395. };
  1396. int status;
  1397. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1398. encode_compound_hdr(&xdr, &hdr);
  1399. status = encode_putfh(&xdr, args->fh);
  1400. if(status)
  1401. goto out;
  1402. status = encode_open_confirm(&xdr, args);
  1403. out:
  1404. return status;
  1405. }
  1406. /*
  1407. * Encode an OPEN request with no attributes.
  1408. */
  1409. static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
  1410. {
  1411. struct xdr_stream xdr;
  1412. struct compound_hdr hdr = {
  1413. .nops = 3,
  1414. };
  1415. int status;
  1416. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1417. encode_compound_hdr(&xdr, &hdr);
  1418. status = encode_putfh(&xdr, args->fh);
  1419. if (status)
  1420. goto out;
  1421. status = encode_open(&xdr, args);
  1422. if (status)
  1423. goto out;
  1424. status = encode_getfattr(&xdr, args->bitmask);
  1425. out:
  1426. return status;
  1427. }
  1428. /*
  1429. * Encode an OPEN_DOWNGRADE request
  1430. */
  1431. static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
  1432. {
  1433. struct xdr_stream xdr;
  1434. struct compound_hdr hdr = {
  1435. .nops = 3,
  1436. };
  1437. int status;
  1438. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1439. encode_compound_hdr(&xdr, &hdr);
  1440. status = encode_putfh(&xdr, args->fh);
  1441. if (status)
  1442. goto out;
  1443. status = encode_open_downgrade(&xdr, args);
  1444. if (status != 0)
  1445. goto out;
  1446. status = encode_getfattr(&xdr, args->bitmask);
  1447. out:
  1448. return status;
  1449. }
  1450. /*
  1451. * Encode a LOCK request
  1452. */
  1453. static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
  1454. {
  1455. struct xdr_stream xdr;
  1456. struct compound_hdr hdr = {
  1457. .nops = 2,
  1458. };
  1459. int status;
  1460. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1461. encode_compound_hdr(&xdr, &hdr);
  1462. status = encode_putfh(&xdr, args->fh);
  1463. if(status)
  1464. goto out;
  1465. status = encode_lock(&xdr, args);
  1466. out:
  1467. return status;
  1468. }
  1469. /*
  1470. * Encode a LOCKT request
  1471. */
  1472. static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
  1473. {
  1474. struct xdr_stream xdr;
  1475. struct compound_hdr hdr = {
  1476. .nops = 2,
  1477. };
  1478. int status;
  1479. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1480. encode_compound_hdr(&xdr, &hdr);
  1481. status = encode_putfh(&xdr, args->fh);
  1482. if(status)
  1483. goto out;
  1484. status = encode_lockt(&xdr, args);
  1485. out:
  1486. return status;
  1487. }
  1488. /*
  1489. * Encode a LOCKU request
  1490. */
  1491. static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
  1492. {
  1493. struct xdr_stream xdr;
  1494. struct compound_hdr hdr = {
  1495. .nops = 2,
  1496. };
  1497. int status;
  1498. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1499. encode_compound_hdr(&xdr, &hdr);
  1500. status = encode_putfh(&xdr, args->fh);
  1501. if(status)
  1502. goto out;
  1503. status = encode_locku(&xdr, args);
  1504. out:
  1505. return status;
  1506. }
  1507. /*
  1508. * Encode a READLINK request
  1509. */
  1510. static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
  1511. {
  1512. struct xdr_stream xdr;
  1513. struct compound_hdr hdr = {
  1514. .nops = 2,
  1515. };
  1516. int status;
  1517. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1518. encode_compound_hdr(&xdr, &hdr);
  1519. status = encode_putfh(&xdr, args->fh);
  1520. if(status)
  1521. goto out;
  1522. status = encode_readlink(&xdr, args, req);
  1523. out:
  1524. return status;
  1525. }
  1526. /*
  1527. * Encode a READDIR request
  1528. */
  1529. static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
  1530. {
  1531. struct xdr_stream xdr;
  1532. struct compound_hdr hdr = {
  1533. .nops = 2,
  1534. };
  1535. int status;
  1536. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1537. encode_compound_hdr(&xdr, &hdr);
  1538. status = encode_putfh(&xdr, args->fh);
  1539. if(status)
  1540. goto out;
  1541. status = encode_readdir(&xdr, args, req);
  1542. out:
  1543. return status;
  1544. }
  1545. /*
  1546. * Encode a READ request
  1547. */
  1548. static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
  1549. {
  1550. struct rpc_auth *auth = req->rq_task->tk_auth;
  1551. struct xdr_stream xdr;
  1552. struct compound_hdr hdr = {
  1553. .nops = 2,
  1554. };
  1555. int replen, status;
  1556. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1557. encode_compound_hdr(&xdr, &hdr);
  1558. status = encode_putfh(&xdr, args->fh);
  1559. if (status)
  1560. goto out;
  1561. status = encode_read(&xdr, args);
  1562. if (status)
  1563. goto out;
  1564. /* set up reply kvec
  1565. * toplevel status + taglen=0 + rescount + OP_PUTFH + status
  1566. * + OP_READ + status + eof + datalen = 9
  1567. */
  1568. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
  1569. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1570. args->pages, args->pgbase, args->count);
  1571. out:
  1572. return status;
  1573. }
  1574. /*
  1575. * Encode an SETATTR request
  1576. */
  1577. static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
  1578. {
  1579. struct xdr_stream xdr;
  1580. struct compound_hdr hdr = {
  1581. .nops = 3,
  1582. };
  1583. int status;
  1584. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1585. encode_compound_hdr(&xdr, &hdr);
  1586. status = encode_putfh(&xdr, args->fh);
  1587. if(status)
  1588. goto out;
  1589. status = encode_setattr(&xdr, args, args->server);
  1590. if(status)
  1591. goto out;
  1592. status = encode_getfattr(&xdr, args->bitmask);
  1593. out:
  1594. return status;
  1595. }
  1596. /*
  1597. * Encode a GETACL request
  1598. */
  1599. static int
  1600. nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
  1601. struct nfs_getaclargs *args)
  1602. {
  1603. struct xdr_stream xdr;
  1604. struct rpc_auth *auth = req->rq_task->tk_auth;
  1605. struct compound_hdr hdr = {
  1606. .nops = 2,
  1607. };
  1608. int replen, status;
  1609. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1610. encode_compound_hdr(&xdr, &hdr);
  1611. status = encode_putfh(&xdr, args->fh);
  1612. if (status)
  1613. goto out;
  1614. status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
  1615. /* set up reply buffer: */
  1616. replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
  1617. xdr_inline_pages(&req->rq_rcv_buf, replen,
  1618. args->acl_pages, args->acl_pgbase, args->acl_len);
  1619. out:
  1620. return status;
  1621. }
  1622. /*
  1623. * Encode a WRITE request
  1624. */
  1625. static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
  1626. {
  1627. struct xdr_stream xdr;
  1628. struct compound_hdr hdr = {
  1629. .nops = 3,
  1630. };
  1631. int status;
  1632. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1633. encode_compound_hdr(&xdr, &hdr);
  1634. status = encode_putfh(&xdr, args->fh);
  1635. if (status)
  1636. goto out;
  1637. status = encode_write(&xdr, args);
  1638. if (status)
  1639. goto out;
  1640. status = encode_getfattr(&xdr, args->bitmask);
  1641. out:
  1642. return status;
  1643. }
  1644. /*
  1645. * a COMMIT request
  1646. */
  1647. static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
  1648. {
  1649. struct xdr_stream xdr;
  1650. struct compound_hdr hdr = {
  1651. .nops = 3,
  1652. };
  1653. int status;
  1654. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1655. encode_compound_hdr(&xdr, &hdr);
  1656. status = encode_putfh(&xdr, args->fh);
  1657. if (status)
  1658. goto out;
  1659. status = encode_commit(&xdr, args);
  1660. if (status)
  1661. goto out;
  1662. status = encode_getfattr(&xdr, args->bitmask);
  1663. out:
  1664. return status;
  1665. }
  1666. /*
  1667. * FSINFO request
  1668. */
  1669. static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
  1670. {
  1671. struct xdr_stream xdr;
  1672. struct compound_hdr hdr = {
  1673. .nops = 2,
  1674. };
  1675. int status;
  1676. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1677. encode_compound_hdr(&xdr, &hdr);
  1678. status = encode_putfh(&xdr, args->fh);
  1679. if (!status)
  1680. status = encode_fsinfo(&xdr, args->bitmask);
  1681. return status;
  1682. }
  1683. /*
  1684. * a PATHCONF request
  1685. */
  1686. static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
  1687. {
  1688. struct xdr_stream xdr;
  1689. struct compound_hdr hdr = {
  1690. .nops = 2,
  1691. };
  1692. int status;
  1693. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1694. encode_compound_hdr(&xdr, &hdr);
  1695. status = encode_putfh(&xdr, args->fh);
  1696. if (!status)
  1697. status = encode_getattr_one(&xdr,
  1698. args->bitmask[0] & nfs4_pathconf_bitmap[0]);
  1699. return status;
  1700. }
  1701. /*
  1702. * a STATFS request
  1703. */
  1704. static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
  1705. {
  1706. struct xdr_stream xdr;
  1707. struct compound_hdr hdr = {
  1708. .nops = 2,
  1709. };
  1710. int status;
  1711. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1712. encode_compound_hdr(&xdr, &hdr);
  1713. status = encode_putfh(&xdr, args->fh);
  1714. if (status == 0)
  1715. status = encode_getattr_two(&xdr,
  1716. args->bitmask[0] & nfs4_statfs_bitmap[0],
  1717. args->bitmask[1] & nfs4_statfs_bitmap[1]);
  1718. return status;
  1719. }
  1720. /*
  1721. * GETATTR_BITMAP request
  1722. */
  1723. static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
  1724. {
  1725. struct xdr_stream xdr;
  1726. struct compound_hdr hdr = {
  1727. .nops = 2,
  1728. };
  1729. int status;
  1730. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1731. encode_compound_hdr(&xdr, &hdr);
  1732. status = encode_putfh(&xdr, fhandle);
  1733. if (status == 0)
  1734. status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
  1735. FATTR4_WORD0_LINK_SUPPORT|
  1736. FATTR4_WORD0_SYMLINK_SUPPORT|
  1737. FATTR4_WORD0_ACLSUPPORT);
  1738. return status;
  1739. }
  1740. /*
  1741. * a RENEW request
  1742. */
  1743. static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
  1744. {
  1745. struct xdr_stream xdr;
  1746. struct compound_hdr hdr = {
  1747. .nops = 1,
  1748. };
  1749. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1750. encode_compound_hdr(&xdr, &hdr);
  1751. return encode_renew(&xdr, clp);
  1752. }
  1753. /*
  1754. * a SETCLIENTID request
  1755. */
  1756. static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
  1757. {
  1758. struct xdr_stream xdr;
  1759. struct compound_hdr hdr = {
  1760. .nops = 1,
  1761. };
  1762. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1763. encode_compound_hdr(&xdr, &hdr);
  1764. return encode_setclientid(&xdr, sc);
  1765. }
  1766. /*
  1767. * a SETCLIENTID_CONFIRM request
  1768. */
  1769. static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
  1770. {
  1771. struct xdr_stream xdr;
  1772. struct compound_hdr hdr = {
  1773. .nops = 3,
  1774. };
  1775. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  1776. int status;
  1777. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1778. encode_compound_hdr(&xdr, &hdr);
  1779. status = encode_setclientid_confirm(&xdr, clp);
  1780. if (!status)
  1781. status = encode_putrootfh(&xdr);
  1782. if (!status)
  1783. status = encode_fsinfo(&xdr, lease_bitmap);
  1784. return status;
  1785. }
  1786. /*
  1787. * DELEGRETURN request
  1788. */
  1789. static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
  1790. {
  1791. struct xdr_stream xdr;
  1792. struct compound_hdr hdr = {
  1793. .nops = 3,
  1794. };
  1795. int status;
  1796. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1797. encode_compound_hdr(&xdr, &hdr);
  1798. status = encode_putfh(&xdr, args->fhandle);
  1799. if (status != 0)
  1800. goto out;
  1801. status = encode_delegreturn(&xdr, args->stateid);
  1802. if (status != 0)
  1803. goto out;
  1804. status = encode_getfattr(&xdr, args->bitmask);
  1805. out:
  1806. return status;
  1807. }
  1808. /*
  1809. * Encode FS_LOCATIONS request
  1810. */
  1811. static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
  1812. {
  1813. struct xdr_stream xdr;
  1814. struct compound_hdr hdr = {
  1815. .nops = 3,
  1816. };
  1817. struct rpc_auth *auth = req->rq_task->tk_auth;
  1818. int replen;
  1819. int status;
  1820. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  1821. encode_compound_hdr(&xdr, &hdr);
  1822. if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
  1823. goto out;
  1824. if ((status = encode_lookup(&xdr, args->name)) != 0)
  1825. goto out;
  1826. if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
  1827. goto out;
  1828. /* set up reply
  1829. * toplevel_status + OP_PUTFH + status
  1830. * + OP_LOOKUP + status + OP_GETATTR + status = 7
  1831. */
  1832. replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
  1833. xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
  1834. 0, PAGE_SIZE);
  1835. out:
  1836. return status;
  1837. }
  1838. /*
  1839. * START OF "GENERIC" DECODE ROUTINES.
  1840. * These may look a little ugly since they are imported from a "generic"
  1841. * set of XDR encode/decode routines which are intended to be shared by
  1842. * all of our NFSv4 implementations (OpenBSD, MacOS X...).
  1843. *
  1844. * If the pain of reading these is too great, it should be a straightforward
  1845. * task to translate them into Linux-specific versions which are more
  1846. * consistent with the style used in NFSv2/v3...
  1847. */
  1848. #define READ32(x) (x) = ntohl(*p++)
  1849. #define READ64(x) do { \
  1850. (x) = (u64)ntohl(*p++) << 32; \
  1851. (x) |= ntohl(*p++); \
  1852. } while (0)
  1853. #define READTIME(x) do { \
  1854. p++; \
  1855. (x.tv_sec) = ntohl(*p++); \
  1856. (x.tv_nsec) = ntohl(*p++); \
  1857. } while (0)
  1858. #define COPYMEM(x,nbytes) do { \
  1859. memcpy((x), p, nbytes); \
  1860. p += XDR_QUADLEN(nbytes); \
  1861. } while (0)
  1862. #define READ_BUF(nbytes) do { \
  1863. p = xdr_inline_decode(xdr, nbytes); \
  1864. if (!p) { \
  1865. printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
  1866. __FUNCTION__, __LINE__); \
  1867. return -EIO; \
  1868. } \
  1869. } while (0)
  1870. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  1871. {
  1872. __be32 *p;
  1873. READ_BUF(4);
  1874. READ32(*len);
  1875. READ_BUF(*len);
  1876. *string = (char *)p;
  1877. return 0;
  1878. }
  1879. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1880. {
  1881. __be32 *p;
  1882. READ_BUF(8);
  1883. READ32(hdr->status);
  1884. READ32(hdr->taglen);
  1885. READ_BUF(hdr->taglen + 4);
  1886. hdr->tag = (char *)p;
  1887. p += XDR_QUADLEN(hdr->taglen);
  1888. READ32(hdr->nops);
  1889. return 0;
  1890. }
  1891. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  1892. {
  1893. __be32 *p;
  1894. uint32_t opnum;
  1895. int32_t nfserr;
  1896. READ_BUF(8);
  1897. READ32(opnum);
  1898. if (opnum != expected) {
  1899. printk(KERN_NOTICE
  1900. "nfs4_decode_op_hdr: Server returned operation"
  1901. " %d but we issued a request for %d\n",
  1902. opnum, expected);
  1903. return -EIO;
  1904. }
  1905. READ32(nfserr);
  1906. if (nfserr != NFS_OK)
  1907. return -nfs4_stat_to_errno(nfserr);
  1908. return 0;
  1909. }
  1910. /* Dummy routine */
  1911. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
  1912. {
  1913. __be32 *p;
  1914. unsigned int strlen;
  1915. char *str;
  1916. READ_BUF(12);
  1917. return decode_opaque_inline(xdr, &strlen, &str);
  1918. }
  1919. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  1920. {
  1921. uint32_t bmlen;
  1922. __be32 *p;
  1923. READ_BUF(4);
  1924. READ32(bmlen);
  1925. bitmap[0] = bitmap[1] = 0;
  1926. READ_BUF((bmlen << 2));
  1927. if (bmlen > 0) {
  1928. READ32(bitmap[0]);
  1929. if (bmlen > 1)
  1930. READ32(bitmap[1]);
  1931. }
  1932. return 0;
  1933. }
  1934. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
  1935. {
  1936. __be32 *p;
  1937. READ_BUF(4);
  1938. READ32(*attrlen);
  1939. *savep = xdr->p;
  1940. return 0;
  1941. }
  1942. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  1943. {
  1944. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1945. decode_attr_bitmap(xdr, bitmask);
  1946. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  1947. } else
  1948. bitmask[0] = bitmask[1] = 0;
  1949. dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
  1950. return 0;
  1951. }
  1952. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  1953. {
  1954. __be32 *p;
  1955. *type = 0;
  1956. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  1957. return -EIO;
  1958. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  1959. READ_BUF(4);
  1960. READ32(*type);
  1961. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  1962. dprintk("%s: bad type %d\n", __FUNCTION__, *type);
  1963. return -EIO;
  1964. }
  1965. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  1966. }
  1967. dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
  1968. return 0;
  1969. }
  1970. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  1971. {
  1972. __be32 *p;
  1973. *change = 0;
  1974. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  1975. return -EIO;
  1976. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  1977. READ_BUF(8);
  1978. READ64(*change);
  1979. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  1980. }
  1981. dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
  1982. (unsigned long long)*change);
  1983. return 0;
  1984. }
  1985. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  1986. {
  1987. __be32 *p;
  1988. *size = 0;
  1989. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  1990. return -EIO;
  1991. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  1992. READ_BUF(8);
  1993. READ64(*size);
  1994. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  1995. }
  1996. dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
  1997. return 0;
  1998. }
  1999. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2000. {
  2001. __be32 *p;
  2002. *res = 0;
  2003. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  2004. return -EIO;
  2005. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  2006. READ_BUF(4);
  2007. READ32(*res);
  2008. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  2009. }
  2010. dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  2011. return 0;
  2012. }
  2013. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2014. {
  2015. __be32 *p;
  2016. *res = 0;
  2017. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  2018. return -EIO;
  2019. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  2020. READ_BUF(4);
  2021. READ32(*res);
  2022. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  2023. }
  2024. dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
  2025. return 0;
  2026. }
  2027. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  2028. {
  2029. __be32 *p;
  2030. fsid->major = 0;
  2031. fsid->minor = 0;
  2032. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  2033. return -EIO;
  2034. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  2035. READ_BUF(16);
  2036. READ64(fsid->major);
  2037. READ64(fsid->minor);
  2038. bitmap[0] &= ~FATTR4_WORD0_FSID;
  2039. }
  2040. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
  2041. (unsigned long long)fsid->major,
  2042. (unsigned long long)fsid->minor);
  2043. return 0;
  2044. }
  2045. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2046. {
  2047. __be32 *p;
  2048. *res = 60;
  2049. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  2050. return -EIO;
  2051. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  2052. READ_BUF(4);
  2053. READ32(*res);
  2054. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  2055. }
  2056. dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
  2057. return 0;
  2058. }
  2059. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2060. {
  2061. __be32 *p;
  2062. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  2063. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  2064. return -EIO;
  2065. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  2066. READ_BUF(4);
  2067. READ32(*res);
  2068. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  2069. }
  2070. dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
  2071. return 0;
  2072. }
  2073. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2074. {
  2075. __be32 *p;
  2076. *fileid = 0;
  2077. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  2078. return -EIO;
  2079. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  2080. READ_BUF(8);
  2081. READ64(*fileid);
  2082. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  2083. }
  2084. dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
  2085. return 0;
  2086. }
  2087. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2088. {
  2089. __be32 *p;
  2090. *fileid = 0;
  2091. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  2092. return -EIO;
  2093. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  2094. READ_BUF(8);
  2095. READ64(*fileid);
  2096. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  2097. }
  2098. dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
  2099. return 0;
  2100. }
  2101. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2102. {
  2103. __be32 *p;
  2104. int status = 0;
  2105. *res = 0;
  2106. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  2107. return -EIO;
  2108. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  2109. READ_BUF(8);
  2110. READ64(*res);
  2111. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  2112. }
  2113. dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2114. return status;
  2115. }
  2116. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2117. {
  2118. __be32 *p;
  2119. int status = 0;
  2120. *res = 0;
  2121. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  2122. return -EIO;
  2123. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  2124. READ_BUF(8);
  2125. READ64(*res);
  2126. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  2127. }
  2128. dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2129. return status;
  2130. }
  2131. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2132. {
  2133. __be32 *p;
  2134. int status = 0;
  2135. *res = 0;
  2136. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  2137. return -EIO;
  2138. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  2139. READ_BUF(8);
  2140. READ64(*res);
  2141. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  2142. }
  2143. dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2144. return status;
  2145. }
  2146. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  2147. {
  2148. int n;
  2149. __be32 *p;
  2150. int status = 0;
  2151. READ_BUF(4);
  2152. READ32(n);
  2153. if (n < 0)
  2154. goto out_eio;
  2155. if (n == 0)
  2156. goto root_path;
  2157. dprintk("path ");
  2158. path->ncomponents = 0;
  2159. while (path->ncomponents < n) {
  2160. struct nfs4_string *component = &path->components[path->ncomponents];
  2161. status = decode_opaque_inline(xdr, &component->len, &component->data);
  2162. if (unlikely(status != 0))
  2163. goto out_eio;
  2164. if (path->ncomponents != n)
  2165. dprintk("/");
  2166. dprintk("%s", component->data);
  2167. if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
  2168. path->ncomponents++;
  2169. else {
  2170. dprintk("cannot parse %d components in path\n", n);
  2171. goto out_eio;
  2172. }
  2173. }
  2174. out:
  2175. dprintk("\n");
  2176. return status;
  2177. root_path:
  2178. /* a root pathname is sent as a zero component4 */
  2179. path->ncomponents = 1;
  2180. path->components[0].len=0;
  2181. path->components[0].data=NULL;
  2182. dprintk("path /\n");
  2183. goto out;
  2184. out_eio:
  2185. dprintk(" status %d", status);
  2186. status = -EIO;
  2187. goto out;
  2188. }
  2189. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  2190. {
  2191. int n;
  2192. __be32 *p;
  2193. int status = -EIO;
  2194. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  2195. goto out;
  2196. status = 0;
  2197. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  2198. goto out;
  2199. dprintk("%s: fsroot ", __FUNCTION__);
  2200. status = decode_pathname(xdr, &res->fs_path);
  2201. if (unlikely(status != 0))
  2202. goto out;
  2203. READ_BUF(4);
  2204. READ32(n);
  2205. if (n <= 0)
  2206. goto out_eio;
  2207. res->nlocations = 0;
  2208. while (res->nlocations < n) {
  2209. int m;
  2210. struct nfs4_fs_location *loc = &res->locations[res->nlocations];
  2211. READ_BUF(4);
  2212. READ32(m);
  2213. if (m <= 0)
  2214. goto out_eio;
  2215. loc->nservers = 0;
  2216. dprintk("%s: servers ", __FUNCTION__);
  2217. while (loc->nservers < m) {
  2218. struct nfs4_string *server = &loc->servers[loc->nservers];
  2219. status = decode_opaque_inline(xdr, &server->len, &server->data);
  2220. if (unlikely(status != 0))
  2221. goto out_eio;
  2222. dprintk("%s ", server->data);
  2223. if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
  2224. loc->nservers++;
  2225. else {
  2226. int i;
  2227. dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
  2228. for (i = loc->nservers; i < m; i++) {
  2229. int len;
  2230. char *data;
  2231. status = decode_opaque_inline(xdr, &len, &data);
  2232. if (unlikely(status != 0))
  2233. goto out_eio;
  2234. }
  2235. }
  2236. }
  2237. status = decode_pathname(xdr, &loc->rootpath);
  2238. if (unlikely(status != 0))
  2239. goto out_eio;
  2240. if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
  2241. res->nlocations++;
  2242. }
  2243. out:
  2244. dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
  2245. return status;
  2246. out_eio:
  2247. status = -EIO;
  2248. goto out;
  2249. }
  2250. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2251. {
  2252. __be32 *p;
  2253. int status = 0;
  2254. *res = 0;
  2255. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  2256. return -EIO;
  2257. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  2258. READ_BUF(8);
  2259. READ64(*res);
  2260. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  2261. }
  2262. dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2263. return status;
  2264. }
  2265. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2266. {
  2267. __be32 *p;
  2268. int status = 0;
  2269. *maxlink = 1;
  2270. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2271. return -EIO;
  2272. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2273. READ_BUF(4);
  2274. READ32(*maxlink);
  2275. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2276. }
  2277. dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
  2278. return status;
  2279. }
  2280. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2281. {
  2282. __be32 *p;
  2283. int status = 0;
  2284. *maxname = 1024;
  2285. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2286. return -EIO;
  2287. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2288. READ_BUF(4);
  2289. READ32(*maxname);
  2290. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2291. }
  2292. dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
  2293. return status;
  2294. }
  2295. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2296. {
  2297. __be32 *p;
  2298. int status = 0;
  2299. *res = 1024;
  2300. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2301. return -EIO;
  2302. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2303. uint64_t maxread;
  2304. READ_BUF(8);
  2305. READ64(maxread);
  2306. if (maxread > 0x7FFFFFFF)
  2307. maxread = 0x7FFFFFFF;
  2308. *res = (uint32_t)maxread;
  2309. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2310. }
  2311. dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
  2312. return status;
  2313. }
  2314. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2315. {
  2316. __be32 *p;
  2317. int status = 0;
  2318. *res = 1024;
  2319. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  2320. return -EIO;
  2321. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  2322. uint64_t maxwrite;
  2323. READ_BUF(8);
  2324. READ64(maxwrite);
  2325. if (maxwrite > 0x7FFFFFFF)
  2326. maxwrite = 0x7FFFFFFF;
  2327. *res = (uint32_t)maxwrite;
  2328. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  2329. }
  2330. dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
  2331. return status;
  2332. }
  2333. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
  2334. {
  2335. __be32 *p;
  2336. *mode = 0;
  2337. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  2338. return -EIO;
  2339. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  2340. READ_BUF(4);
  2341. READ32(*mode);
  2342. *mode &= ~S_IFMT;
  2343. bitmap[1] &= ~FATTR4_WORD1_MODE;
  2344. }
  2345. dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
  2346. return 0;
  2347. }
  2348. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  2349. {
  2350. __be32 *p;
  2351. *nlink = 1;
  2352. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  2353. return -EIO;
  2354. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  2355. READ_BUF(4);
  2356. READ32(*nlink);
  2357. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  2358. }
  2359. dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
  2360. return 0;
  2361. }
  2362. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *uid)
  2363. {
  2364. uint32_t len;
  2365. __be32 *p;
  2366. *uid = -2;
  2367. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  2368. return -EIO;
  2369. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  2370. READ_BUF(4);
  2371. READ32(len);
  2372. READ_BUF(len);
  2373. if (len < XDR_MAX_NETOBJ) {
  2374. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
  2375. dprintk("%s: nfs_map_name_to_uid failed!\n",
  2376. __FUNCTION__);
  2377. } else
  2378. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2379. __FUNCTION__, len);
  2380. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  2381. }
  2382. dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
  2383. return 0;
  2384. }
  2385. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *gid)
  2386. {
  2387. uint32_t len;
  2388. __be32 *p;
  2389. *gid = -2;
  2390. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  2391. return -EIO;
  2392. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  2393. READ_BUF(4);
  2394. READ32(len);
  2395. READ_BUF(len);
  2396. if (len < XDR_MAX_NETOBJ) {
  2397. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
  2398. dprintk("%s: nfs_map_group_to_gid failed!\n",
  2399. __FUNCTION__);
  2400. } else
  2401. printk(KERN_WARNING "%s: name too long (%u)!\n",
  2402. __FUNCTION__, len);
  2403. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  2404. }
  2405. dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
  2406. return 0;
  2407. }
  2408. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  2409. {
  2410. uint32_t major = 0, minor = 0;
  2411. __be32 *p;
  2412. *rdev = MKDEV(0,0);
  2413. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  2414. return -EIO;
  2415. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  2416. dev_t tmp;
  2417. READ_BUF(8);
  2418. READ32(major);
  2419. READ32(minor);
  2420. tmp = MKDEV(major, minor);
  2421. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  2422. *rdev = tmp;
  2423. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  2424. }
  2425. dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
  2426. return 0;
  2427. }
  2428. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2429. {
  2430. __be32 *p;
  2431. int status = 0;
  2432. *res = 0;
  2433. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  2434. return -EIO;
  2435. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  2436. READ_BUF(8);
  2437. READ64(*res);
  2438. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  2439. }
  2440. dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2441. return status;
  2442. }
  2443. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2444. {
  2445. __be32 *p;
  2446. int status = 0;
  2447. *res = 0;
  2448. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  2449. return -EIO;
  2450. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  2451. READ_BUF(8);
  2452. READ64(*res);
  2453. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  2454. }
  2455. dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2456. return status;
  2457. }
  2458. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2459. {
  2460. __be32 *p;
  2461. int status = 0;
  2462. *res = 0;
  2463. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  2464. return -EIO;
  2465. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  2466. READ_BUF(8);
  2467. READ64(*res);
  2468. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  2469. }
  2470. dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
  2471. return status;
  2472. }
  2473. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  2474. {
  2475. __be32 *p;
  2476. *used = 0;
  2477. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  2478. return -EIO;
  2479. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  2480. READ_BUF(8);
  2481. READ64(*used);
  2482. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  2483. }
  2484. dprintk("%s: space used=%Lu\n", __FUNCTION__,
  2485. (unsigned long long)*used);
  2486. return 0;
  2487. }
  2488. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  2489. {
  2490. __be32 *p;
  2491. uint64_t sec;
  2492. uint32_t nsec;
  2493. READ_BUF(12);
  2494. READ64(sec);
  2495. READ32(nsec);
  2496. time->tv_sec = (time_t)sec;
  2497. time->tv_nsec = (long)nsec;
  2498. return 0;
  2499. }
  2500. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2501. {
  2502. int status = 0;
  2503. time->tv_sec = 0;
  2504. time->tv_nsec = 0;
  2505. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  2506. return -EIO;
  2507. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  2508. status = decode_attr_time(xdr, time);
  2509. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  2510. }
  2511. dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2512. return status;
  2513. }
  2514. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2515. {
  2516. int status = 0;
  2517. time->tv_sec = 0;
  2518. time->tv_nsec = 0;
  2519. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  2520. return -EIO;
  2521. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  2522. status = decode_attr_time(xdr, time);
  2523. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  2524. }
  2525. dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2526. return status;
  2527. }
  2528. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2529. {
  2530. int status = 0;
  2531. time->tv_sec = 0;
  2532. time->tv_nsec = 0;
  2533. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  2534. return -EIO;
  2535. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  2536. status = decode_attr_time(xdr, time);
  2537. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  2538. }
  2539. dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
  2540. return status;
  2541. }
  2542. static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
  2543. {
  2544. unsigned int attrwords = XDR_QUADLEN(attrlen);
  2545. unsigned int nwords = xdr->p - savep;
  2546. if (unlikely(attrwords != nwords)) {
  2547. printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
  2548. __FUNCTION__,
  2549. attrwords << 2,
  2550. (attrwords < nwords) ? '<' : '>',
  2551. nwords << 2);
  2552. return -EIO;
  2553. }
  2554. return 0;
  2555. }
  2556. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2557. {
  2558. __be32 *p;
  2559. READ_BUF(20);
  2560. READ32(cinfo->atomic);
  2561. READ64(cinfo->before);
  2562. READ64(cinfo->after);
  2563. return 0;
  2564. }
  2565. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  2566. {
  2567. __be32 *p;
  2568. uint32_t supp, acc;
  2569. int status;
  2570. status = decode_op_hdr(xdr, OP_ACCESS);
  2571. if (status)
  2572. return status;
  2573. READ_BUF(8);
  2574. READ32(supp);
  2575. READ32(acc);
  2576. access->supported = supp;
  2577. access->access = acc;
  2578. return 0;
  2579. }
  2580. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  2581. {
  2582. __be32 *p;
  2583. int status;
  2584. status = decode_op_hdr(xdr, OP_CLOSE);
  2585. if (status)
  2586. return status;
  2587. READ_BUF(sizeof(res->stateid.data));
  2588. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2589. return 0;
  2590. }
  2591. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  2592. {
  2593. __be32 *p;
  2594. int status;
  2595. status = decode_op_hdr(xdr, OP_COMMIT);
  2596. if (status)
  2597. return status;
  2598. READ_BUF(8);
  2599. COPYMEM(res->verf->verifier, 8);
  2600. return 0;
  2601. }
  2602. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2603. {
  2604. __be32 *p;
  2605. uint32_t bmlen;
  2606. int status;
  2607. status = decode_op_hdr(xdr, OP_CREATE);
  2608. if (status)
  2609. return status;
  2610. if ((status = decode_change_info(xdr, cinfo)))
  2611. return status;
  2612. READ_BUF(4);
  2613. READ32(bmlen);
  2614. READ_BUF(bmlen << 2);
  2615. return 0;
  2616. }
  2617. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  2618. {
  2619. __be32 *savep;
  2620. uint32_t attrlen,
  2621. bitmap[2] = {0};
  2622. int status;
  2623. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2624. goto xdr_error;
  2625. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2626. goto xdr_error;
  2627. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2628. goto xdr_error;
  2629. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  2630. goto xdr_error;
  2631. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  2632. goto xdr_error;
  2633. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  2634. goto xdr_error;
  2635. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  2636. goto xdr_error;
  2637. status = verify_attr_len(xdr, savep, attrlen);
  2638. xdr_error:
  2639. dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
  2640. return status;
  2641. }
  2642. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  2643. {
  2644. __be32 *savep;
  2645. uint32_t attrlen,
  2646. bitmap[2] = {0};
  2647. int status;
  2648. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2649. goto xdr_error;
  2650. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2651. goto xdr_error;
  2652. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2653. goto xdr_error;
  2654. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  2655. goto xdr_error;
  2656. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  2657. goto xdr_error;
  2658. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  2659. goto xdr_error;
  2660. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  2661. goto xdr_error;
  2662. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  2663. goto xdr_error;
  2664. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  2665. goto xdr_error;
  2666. status = verify_attr_len(xdr, savep, attrlen);
  2667. xdr_error:
  2668. dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
  2669. return status;
  2670. }
  2671. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  2672. {
  2673. __be32 *savep;
  2674. uint32_t attrlen,
  2675. bitmap[2] = {0};
  2676. int status;
  2677. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2678. goto xdr_error;
  2679. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2680. goto xdr_error;
  2681. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2682. goto xdr_error;
  2683. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  2684. goto xdr_error;
  2685. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  2686. goto xdr_error;
  2687. status = verify_attr_len(xdr, savep, attrlen);
  2688. xdr_error:
  2689. dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
  2690. return status;
  2691. }
  2692. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
  2693. {
  2694. __be32 *savep;
  2695. uint32_t attrlen,
  2696. bitmap[2] = {0},
  2697. type;
  2698. int status, fmode = 0;
  2699. uint64_t fileid;
  2700. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2701. goto xdr_error;
  2702. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2703. goto xdr_error;
  2704. fattr->bitmap[0] = bitmap[0];
  2705. fattr->bitmap[1] = bitmap[1];
  2706. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2707. goto xdr_error;
  2708. if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
  2709. goto xdr_error;
  2710. fattr->type = nfs_type2fmt[type].nfs2type;
  2711. fmode = nfs_type2fmt[type].mode;
  2712. if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
  2713. goto xdr_error;
  2714. if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
  2715. goto xdr_error;
  2716. if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
  2717. goto xdr_error;
  2718. if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
  2719. goto xdr_error;
  2720. if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
  2721. struct nfs4_fs_locations,
  2722. fattr))) != 0)
  2723. goto xdr_error;
  2724. if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
  2725. goto xdr_error;
  2726. fattr->mode |= fmode;
  2727. if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
  2728. goto xdr_error;
  2729. if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
  2730. goto xdr_error;
  2731. if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
  2732. goto xdr_error;
  2733. if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
  2734. goto xdr_error;
  2735. if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
  2736. goto xdr_error;
  2737. if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
  2738. goto xdr_error;
  2739. if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
  2740. goto xdr_error;
  2741. if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
  2742. goto xdr_error;
  2743. if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
  2744. goto xdr_error;
  2745. if (fattr->fileid == 0 && fileid != 0)
  2746. fattr->fileid = fileid;
  2747. if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
  2748. fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
  2749. xdr_error:
  2750. dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
  2751. return status;
  2752. }
  2753. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  2754. {
  2755. __be32 *savep;
  2756. uint32_t attrlen, bitmap[2];
  2757. int status;
  2758. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  2759. goto xdr_error;
  2760. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  2761. goto xdr_error;
  2762. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  2763. goto xdr_error;
  2764. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  2765. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  2766. goto xdr_error;
  2767. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  2768. goto xdr_error;
  2769. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  2770. goto xdr_error;
  2771. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  2772. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  2773. goto xdr_error;
  2774. fsinfo->wtpref = fsinfo->wtmax;
  2775. status = verify_attr_len(xdr, savep, attrlen);
  2776. xdr_error:
  2777. dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
  2778. return status;
  2779. }
  2780. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  2781. {
  2782. __be32 *p;
  2783. uint32_t len;
  2784. int status;
  2785. status = decode_op_hdr(xdr, OP_GETFH);
  2786. if (status)
  2787. return status;
  2788. /* Zero handle first to allow comparisons */
  2789. memset(fh, 0, sizeof(*fh));
  2790. READ_BUF(4);
  2791. READ32(len);
  2792. if (len > NFS4_FHSIZE)
  2793. return -EIO;
  2794. fh->size = len;
  2795. READ_BUF(len);
  2796. COPYMEM(fh->data, len);
  2797. return 0;
  2798. }
  2799. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2800. {
  2801. int status;
  2802. status = decode_op_hdr(xdr, OP_LINK);
  2803. if (status)
  2804. return status;
  2805. return decode_change_info(xdr, cinfo);
  2806. }
  2807. /*
  2808. * We create the owner, so we know a proper owner.id length is 4.
  2809. */
  2810. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  2811. {
  2812. uint64_t offset, length, clientid;
  2813. __be32 *p;
  2814. uint32_t namelen, type;
  2815. READ_BUF(32);
  2816. READ64(offset);
  2817. READ64(length);
  2818. READ32(type);
  2819. if (fl != NULL) {
  2820. fl->fl_start = (loff_t)offset;
  2821. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  2822. if (length == ~(uint64_t)0)
  2823. fl->fl_end = OFFSET_MAX;
  2824. fl->fl_type = F_WRLCK;
  2825. if (type & 1)
  2826. fl->fl_type = F_RDLCK;
  2827. fl->fl_pid = 0;
  2828. }
  2829. READ64(clientid);
  2830. READ32(namelen);
  2831. READ_BUF(namelen);
  2832. return -NFS4ERR_DENIED;
  2833. }
  2834. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  2835. {
  2836. __be32 *p;
  2837. int status;
  2838. status = decode_op_hdr(xdr, OP_LOCK);
  2839. if (status == 0) {
  2840. READ_BUF(sizeof(res->stateid.data));
  2841. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2842. } else if (status == -NFS4ERR_DENIED)
  2843. return decode_lock_denied(xdr, NULL);
  2844. return status;
  2845. }
  2846. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  2847. {
  2848. int status;
  2849. status = decode_op_hdr(xdr, OP_LOCKT);
  2850. if (status == -NFS4ERR_DENIED)
  2851. return decode_lock_denied(xdr, res->denied);
  2852. return status;
  2853. }
  2854. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  2855. {
  2856. __be32 *p;
  2857. int status;
  2858. status = decode_op_hdr(xdr, OP_LOCKU);
  2859. if (status == 0) {
  2860. READ_BUF(sizeof(res->stateid.data));
  2861. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2862. }
  2863. return status;
  2864. }
  2865. static int decode_lookup(struct xdr_stream *xdr)
  2866. {
  2867. return decode_op_hdr(xdr, OP_LOOKUP);
  2868. }
  2869. /* This is too sick! */
  2870. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  2871. {
  2872. __be32 *p;
  2873. uint32_t limit_type, nblocks, blocksize;
  2874. READ_BUF(12);
  2875. READ32(limit_type);
  2876. switch (limit_type) {
  2877. case 1:
  2878. READ64(*maxsize);
  2879. break;
  2880. case 2:
  2881. READ32(nblocks);
  2882. READ32(blocksize);
  2883. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  2884. }
  2885. return 0;
  2886. }
  2887. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  2888. {
  2889. __be32 *p;
  2890. uint32_t delegation_type;
  2891. READ_BUF(4);
  2892. READ32(delegation_type);
  2893. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  2894. res->delegation_type = 0;
  2895. return 0;
  2896. }
  2897. READ_BUF(20);
  2898. COPYMEM(res->delegation.data, sizeof(res->delegation.data));
  2899. READ32(res->do_recall);
  2900. switch (delegation_type) {
  2901. case NFS4_OPEN_DELEGATE_READ:
  2902. res->delegation_type = FMODE_READ;
  2903. break;
  2904. case NFS4_OPEN_DELEGATE_WRITE:
  2905. res->delegation_type = FMODE_WRITE|FMODE_READ;
  2906. if (decode_space_limit(xdr, &res->maxsize) < 0)
  2907. return -EIO;
  2908. }
  2909. return decode_ace(xdr, NULL, res->server->nfs_client);
  2910. }
  2911. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  2912. {
  2913. __be32 *p;
  2914. uint32_t bmlen;
  2915. int status;
  2916. status = decode_op_hdr(xdr, OP_OPEN);
  2917. if (status)
  2918. return status;
  2919. READ_BUF(sizeof(res->stateid.data));
  2920. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2921. decode_change_info(xdr, &res->cinfo);
  2922. READ_BUF(8);
  2923. READ32(res->rflags);
  2924. READ32(bmlen);
  2925. if (bmlen > 10)
  2926. goto xdr_error;
  2927. READ_BUF(bmlen << 2);
  2928. p += bmlen;
  2929. return decode_delegation(xdr, res);
  2930. xdr_error:
  2931. dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
  2932. return -EIO;
  2933. }
  2934. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  2935. {
  2936. __be32 *p;
  2937. int status;
  2938. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  2939. if (status)
  2940. return status;
  2941. READ_BUF(sizeof(res->stateid.data));
  2942. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2943. return 0;
  2944. }
  2945. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  2946. {
  2947. __be32 *p;
  2948. int status;
  2949. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  2950. if (status)
  2951. return status;
  2952. READ_BUF(sizeof(res->stateid.data));
  2953. COPYMEM(res->stateid.data, sizeof(res->stateid.data));
  2954. return 0;
  2955. }
  2956. static int decode_putfh(struct xdr_stream *xdr)
  2957. {
  2958. return decode_op_hdr(xdr, OP_PUTFH);
  2959. }
  2960. static int decode_putrootfh(struct xdr_stream *xdr)
  2961. {
  2962. return decode_op_hdr(xdr, OP_PUTROOTFH);
  2963. }
  2964. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  2965. {
  2966. struct kvec *iov = req->rq_rcv_buf.head;
  2967. __be32 *p;
  2968. uint32_t count, eof, recvd, hdrlen;
  2969. int status;
  2970. status = decode_op_hdr(xdr, OP_READ);
  2971. if (status)
  2972. return status;
  2973. READ_BUF(8);
  2974. READ32(eof);
  2975. READ32(count);
  2976. hdrlen = (u8 *) p - (u8 *) iov->iov_base;
  2977. recvd = req->rq_rcv_buf.len - hdrlen;
  2978. if (count > recvd) {
  2979. printk(KERN_WARNING "NFS: server cheating in read reply: "
  2980. "count %u > recvd %u\n", count, recvd);
  2981. count = recvd;
  2982. eof = 0;
  2983. }
  2984. xdr_read_pages(xdr, count);
  2985. res->eof = eof;
  2986. res->count = count;
  2987. return 0;
  2988. }
  2989. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  2990. {
  2991. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  2992. struct page *page = *rcvbuf->pages;
  2993. struct kvec *iov = rcvbuf->head;
  2994. unsigned int nr, pglen = rcvbuf->page_len;
  2995. __be32 *end, *entry, *p, *kaddr;
  2996. uint32_t len, attrlen, xlen;
  2997. int hdrlen, recvd, status;
  2998. status = decode_op_hdr(xdr, OP_READDIR);
  2999. if (status)
  3000. return status;
  3001. READ_BUF(8);
  3002. COPYMEM(readdir->verifier.data, 8);
  3003. dprintk("%s: verifier = 0x%x%x\n",
  3004. __FUNCTION__,
  3005. ((u32 *)readdir->verifier.data)[0],
  3006. ((u32 *)readdir->verifier.data)[1]);
  3007. hdrlen = (char *) p - (char *) iov->iov_base;
  3008. recvd = rcvbuf->len - hdrlen;
  3009. if (pglen > recvd)
  3010. pglen = recvd;
  3011. xdr_read_pages(xdr, pglen);
  3012. BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
  3013. kaddr = p = kmap_atomic(page, KM_USER0);
  3014. end = p + ((pglen + readdir->pgbase) >> 2);
  3015. entry = p;
  3016. for (nr = 0; *p++; nr++) {
  3017. if (end - p < 3)
  3018. goto short_pkt;
  3019. dprintk("cookie = %Lu, ", *((unsigned long long *)p));
  3020. p += 2; /* cookie */
  3021. len = ntohl(*p++); /* filename length */
  3022. if (len > NFS4_MAXNAMLEN) {
  3023. printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
  3024. goto err_unmap;
  3025. }
  3026. xlen = XDR_QUADLEN(len);
  3027. if (end - p < xlen + 1)
  3028. goto short_pkt;
  3029. dprintk("filename = %*s\n", len, (char *)p);
  3030. p += xlen;
  3031. len = ntohl(*p++); /* bitmap length */
  3032. if (end - p < len + 1)
  3033. goto short_pkt;
  3034. p += len;
  3035. attrlen = XDR_QUADLEN(ntohl(*p++));
  3036. if (end - p < attrlen + 2)
  3037. goto short_pkt;
  3038. p += attrlen; /* attributes */
  3039. entry = p;
  3040. }
  3041. if (!nr && (entry[0] != 0 || entry[1] == 0))
  3042. goto short_pkt;
  3043. out:
  3044. kunmap_atomic(kaddr, KM_USER0);
  3045. return 0;
  3046. short_pkt:
  3047. dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
  3048. entry[0] = entry[1] = 0;
  3049. /* truncate listing ? */
  3050. if (!nr) {
  3051. printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
  3052. entry[1] = 1;
  3053. }
  3054. goto out;
  3055. err_unmap:
  3056. kunmap_atomic(kaddr, KM_USER0);
  3057. return -errno_NFSERR_IO;
  3058. }
  3059. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  3060. {
  3061. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  3062. struct kvec *iov = rcvbuf->head;
  3063. int hdrlen, len, recvd;
  3064. __be32 *p;
  3065. char *kaddr;
  3066. int status;
  3067. status = decode_op_hdr(xdr, OP_READLINK);
  3068. if (status)
  3069. return status;
  3070. /* Convert length of symlink */
  3071. READ_BUF(4);
  3072. READ32(len);
  3073. if (len >= rcvbuf->page_len || len <= 0) {
  3074. dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
  3075. return -ENAMETOOLONG;
  3076. }
  3077. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  3078. recvd = req->rq_rcv_buf.len - hdrlen;
  3079. if (recvd < len) {
  3080. printk(KERN_WARNING "NFS: server cheating in readlink reply: "
  3081. "count %u > recvd %u\n", len, recvd);
  3082. return -EIO;
  3083. }
  3084. xdr_read_pages(xdr, len);
  3085. /*
  3086. * The XDR encode routine has set things up so that
  3087. * the link text will be copied directly into the
  3088. * buffer. We just have to do overflow-checking,
  3089. * and and null-terminate the text (the VFS expects
  3090. * null-termination).
  3091. */
  3092. kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
  3093. kaddr[len+rcvbuf->page_base] = '\0';
  3094. kunmap_atomic(kaddr, KM_USER0);
  3095. return 0;
  3096. }
  3097. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3098. {
  3099. int status;
  3100. status = decode_op_hdr(xdr, OP_REMOVE);
  3101. if (status)
  3102. goto out;
  3103. status = decode_change_info(xdr, cinfo);
  3104. out:
  3105. return status;
  3106. }
  3107. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  3108. struct nfs4_change_info *new_cinfo)
  3109. {
  3110. int status;
  3111. status = decode_op_hdr(xdr, OP_RENAME);
  3112. if (status)
  3113. goto out;
  3114. if ((status = decode_change_info(xdr, old_cinfo)))
  3115. goto out;
  3116. status = decode_change_info(xdr, new_cinfo);
  3117. out:
  3118. return status;
  3119. }
  3120. static int decode_renew(struct xdr_stream *xdr)
  3121. {
  3122. return decode_op_hdr(xdr, OP_RENEW);
  3123. }
  3124. static int
  3125. decode_restorefh(struct xdr_stream *xdr)
  3126. {
  3127. return decode_op_hdr(xdr, OP_RESTOREFH);
  3128. }
  3129. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  3130. size_t *acl_len)
  3131. {
  3132. __be32 *savep;
  3133. uint32_t attrlen,
  3134. bitmap[2] = {0};
  3135. struct kvec *iov = req->rq_rcv_buf.head;
  3136. int status;
  3137. *acl_len = 0;
  3138. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3139. goto out;
  3140. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3141. goto out;
  3142. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3143. goto out;
  3144. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  3145. return -EIO;
  3146. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  3147. int hdrlen, recvd;
  3148. /* We ignore &savep and don't do consistency checks on
  3149. * the attr length. Let userspace figure it out.... */
  3150. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  3151. recvd = req->rq_rcv_buf.len - hdrlen;
  3152. if (attrlen > recvd) {
  3153. printk(KERN_WARNING "NFS: server cheating in getattr"
  3154. " acl reply: attrlen %u > recvd %u\n",
  3155. attrlen, recvd);
  3156. return -EINVAL;
  3157. }
  3158. xdr_read_pages(xdr, attrlen);
  3159. *acl_len = attrlen;
  3160. } else
  3161. status = -EOPNOTSUPP;
  3162. out:
  3163. return status;
  3164. }
  3165. static int
  3166. decode_savefh(struct xdr_stream *xdr)
  3167. {
  3168. return decode_op_hdr(xdr, OP_SAVEFH);
  3169. }
  3170. static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
  3171. {
  3172. __be32 *p;
  3173. uint32_t bmlen;
  3174. int status;
  3175. status = decode_op_hdr(xdr, OP_SETATTR);
  3176. if (status)
  3177. return status;
  3178. READ_BUF(4);
  3179. READ32(bmlen);
  3180. READ_BUF(bmlen << 2);
  3181. return 0;
  3182. }
  3183. static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
  3184. {
  3185. __be32 *p;
  3186. uint32_t opnum;
  3187. int32_t nfserr;
  3188. READ_BUF(8);
  3189. READ32(opnum);
  3190. if (opnum != OP_SETCLIENTID) {
  3191. printk(KERN_NOTICE
  3192. "nfs4_decode_setclientid: Server returned operation"
  3193. " %d\n", opnum);
  3194. return -EIO;
  3195. }
  3196. READ32(nfserr);
  3197. if (nfserr == NFS_OK) {
  3198. READ_BUF(8 + sizeof(clp->cl_confirm.data));
  3199. READ64(clp->cl_clientid);
  3200. COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
  3201. } else if (nfserr == NFSERR_CLID_INUSE) {
  3202. uint32_t len;
  3203. /* skip netid string */
  3204. READ_BUF(4);
  3205. READ32(len);
  3206. READ_BUF(len);
  3207. /* skip uaddr string */
  3208. READ_BUF(4);
  3209. READ32(len);
  3210. READ_BUF(len);
  3211. return -NFSERR_CLID_INUSE;
  3212. } else
  3213. return -nfs4_stat_to_errno(nfserr);
  3214. return 0;
  3215. }
  3216. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  3217. {
  3218. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  3219. }
  3220. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  3221. {
  3222. __be32 *p;
  3223. int status;
  3224. status = decode_op_hdr(xdr, OP_WRITE);
  3225. if (status)
  3226. return status;
  3227. READ_BUF(16);
  3228. READ32(res->count);
  3229. READ32(res->verf->committed);
  3230. COPYMEM(res->verf->verifier, 8);
  3231. return 0;
  3232. }
  3233. static int decode_delegreturn(struct xdr_stream *xdr)
  3234. {
  3235. return decode_op_hdr(xdr, OP_DELEGRETURN);
  3236. }
  3237. /*
  3238. * Decode OPEN_DOWNGRADE response
  3239. */
  3240. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
  3241. {
  3242. struct xdr_stream xdr;
  3243. struct compound_hdr hdr;
  3244. int status;
  3245. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3246. status = decode_compound_hdr(&xdr, &hdr);
  3247. if (status)
  3248. goto out;
  3249. status = decode_putfh(&xdr);
  3250. if (status)
  3251. goto out;
  3252. status = decode_open_downgrade(&xdr, res);
  3253. if (status != 0)
  3254. goto out;
  3255. decode_getfattr(&xdr, res->fattr, res->server);
  3256. out:
  3257. return status;
  3258. }
  3259. /*
  3260. * END OF "GENERIC" DECODE ROUTINES.
  3261. */
  3262. /*
  3263. * Decode ACCESS response
  3264. */
  3265. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
  3266. {
  3267. struct xdr_stream xdr;
  3268. struct compound_hdr hdr;
  3269. int status;
  3270. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3271. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3272. goto out;
  3273. if ((status = decode_putfh(&xdr)) == 0)
  3274. status = decode_access(&xdr, res);
  3275. out:
  3276. return status;
  3277. }
  3278. /*
  3279. * Decode LOOKUP response
  3280. */
  3281. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
  3282. {
  3283. struct xdr_stream xdr;
  3284. struct compound_hdr hdr;
  3285. int status;
  3286. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3287. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3288. goto out;
  3289. if ((status = decode_putfh(&xdr)) != 0)
  3290. goto out;
  3291. if ((status = decode_lookup(&xdr)) != 0)
  3292. goto out;
  3293. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3294. goto out;
  3295. status = decode_getfattr(&xdr, res->fattr, res->server);
  3296. out:
  3297. return status;
  3298. }
  3299. /*
  3300. * Decode LOOKUP_ROOT response
  3301. */
  3302. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
  3303. {
  3304. struct xdr_stream xdr;
  3305. struct compound_hdr hdr;
  3306. int status;
  3307. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3308. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3309. goto out;
  3310. if ((status = decode_putrootfh(&xdr)) != 0)
  3311. goto out;
  3312. if ((status = decode_getfh(&xdr, res->fh)) == 0)
  3313. status = decode_getfattr(&xdr, res->fattr, res->server);
  3314. out:
  3315. return status;
  3316. }
  3317. /*
  3318. * Decode REMOVE response
  3319. */
  3320. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
  3321. {
  3322. struct xdr_stream xdr;
  3323. struct compound_hdr hdr;
  3324. int status;
  3325. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3326. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3327. goto out;
  3328. if ((status = decode_putfh(&xdr)) != 0)
  3329. goto out;
  3330. if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
  3331. goto out;
  3332. decode_getfattr(&xdr, res->dir_attr, res->server);
  3333. out:
  3334. return status;
  3335. }
  3336. /*
  3337. * Decode RENAME response
  3338. */
  3339. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
  3340. {
  3341. struct xdr_stream xdr;
  3342. struct compound_hdr hdr;
  3343. int status;
  3344. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3345. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3346. goto out;
  3347. if ((status = decode_putfh(&xdr)) != 0)
  3348. goto out;
  3349. if ((status = decode_savefh(&xdr)) != 0)
  3350. goto out;
  3351. if ((status = decode_putfh(&xdr)) != 0)
  3352. goto out;
  3353. if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
  3354. goto out;
  3355. /* Current FH is target directory */
  3356. if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
  3357. goto out;
  3358. if ((status = decode_restorefh(&xdr)) != 0)
  3359. goto out;
  3360. decode_getfattr(&xdr, res->old_fattr, res->server);
  3361. out:
  3362. return status;
  3363. }
  3364. /*
  3365. * Decode LINK response
  3366. */
  3367. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
  3368. {
  3369. struct xdr_stream xdr;
  3370. struct compound_hdr hdr;
  3371. int status;
  3372. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3373. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3374. goto out;
  3375. if ((status = decode_putfh(&xdr)) != 0)
  3376. goto out;
  3377. if ((status = decode_savefh(&xdr)) != 0)
  3378. goto out;
  3379. if ((status = decode_putfh(&xdr)) != 0)
  3380. goto out;
  3381. if ((status = decode_link(&xdr, &res->cinfo)) != 0)
  3382. goto out;
  3383. /*
  3384. * Note order: OP_LINK leaves the directory as the current
  3385. * filehandle.
  3386. */
  3387. if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
  3388. goto out;
  3389. if ((status = decode_restorefh(&xdr)) != 0)
  3390. goto out;
  3391. decode_getfattr(&xdr, res->fattr, res->server);
  3392. out:
  3393. return status;
  3394. }
  3395. /*
  3396. * Decode CREATE response
  3397. */
  3398. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
  3399. {
  3400. struct xdr_stream xdr;
  3401. struct compound_hdr hdr;
  3402. int status;
  3403. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3404. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3405. goto out;
  3406. if ((status = decode_putfh(&xdr)) != 0)
  3407. goto out;
  3408. if ((status = decode_savefh(&xdr)) != 0)
  3409. goto out;
  3410. if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
  3411. goto out;
  3412. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3413. goto out;
  3414. if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
  3415. goto out;
  3416. if ((status = decode_restorefh(&xdr)) != 0)
  3417. goto out;
  3418. decode_getfattr(&xdr, res->dir_fattr, res->server);
  3419. out:
  3420. return status;
  3421. }
  3422. /*
  3423. * Decode SYMLINK response
  3424. */
  3425. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
  3426. {
  3427. return nfs4_xdr_dec_create(rqstp, p, res);
  3428. }
  3429. /*
  3430. * Decode GETATTR response
  3431. */
  3432. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
  3433. {
  3434. struct xdr_stream xdr;
  3435. struct compound_hdr hdr;
  3436. int status;
  3437. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3438. status = decode_compound_hdr(&xdr, &hdr);
  3439. if (status)
  3440. goto out;
  3441. status = decode_putfh(&xdr);
  3442. if (status)
  3443. goto out;
  3444. status = decode_getfattr(&xdr, res->fattr, res->server);
  3445. out:
  3446. return status;
  3447. }
  3448. /*
  3449. * Encode an SETACL request
  3450. */
  3451. static int
  3452. nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
  3453. {
  3454. struct xdr_stream xdr;
  3455. struct compound_hdr hdr = {
  3456. .nops = 2,
  3457. };
  3458. int status;
  3459. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  3460. encode_compound_hdr(&xdr, &hdr);
  3461. status = encode_putfh(&xdr, args->fh);
  3462. if (status)
  3463. goto out;
  3464. status = encode_setacl(&xdr, args);
  3465. out:
  3466. return status;
  3467. }
  3468. /*
  3469. * Decode SETACL response
  3470. */
  3471. static int
  3472. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
  3473. {
  3474. struct xdr_stream xdr;
  3475. struct compound_hdr hdr;
  3476. int status;
  3477. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3478. status = decode_compound_hdr(&xdr, &hdr);
  3479. if (status)
  3480. goto out;
  3481. status = decode_putfh(&xdr);
  3482. if (status)
  3483. goto out;
  3484. status = decode_setattr(&xdr, res);
  3485. out:
  3486. return status;
  3487. }
  3488. /*
  3489. * Decode GETACL response
  3490. */
  3491. static int
  3492. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
  3493. {
  3494. struct xdr_stream xdr;
  3495. struct compound_hdr hdr;
  3496. int status;
  3497. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3498. status = decode_compound_hdr(&xdr, &hdr);
  3499. if (status)
  3500. goto out;
  3501. status = decode_putfh(&xdr);
  3502. if (status)
  3503. goto out;
  3504. status = decode_getacl(&xdr, rqstp, acl_len);
  3505. out:
  3506. return status;
  3507. }
  3508. /*
  3509. * Decode CLOSE response
  3510. */
  3511. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
  3512. {
  3513. struct xdr_stream xdr;
  3514. struct compound_hdr hdr;
  3515. int status;
  3516. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3517. status = decode_compound_hdr(&xdr, &hdr);
  3518. if (status)
  3519. goto out;
  3520. status = decode_putfh(&xdr);
  3521. if (status)
  3522. goto out;
  3523. status = decode_close(&xdr, res);
  3524. if (status != 0)
  3525. goto out;
  3526. /*
  3527. * Note: Server may do delete on close for this file
  3528. * in which case the getattr call will fail with
  3529. * an ESTALE error. Shouldn't be a problem,
  3530. * though, since fattr->valid will remain unset.
  3531. */
  3532. decode_getfattr(&xdr, res->fattr, res->server);
  3533. out:
  3534. return status;
  3535. }
  3536. /*
  3537. * Decode OPEN response
  3538. */
  3539. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
  3540. {
  3541. struct xdr_stream xdr;
  3542. struct compound_hdr hdr;
  3543. int status;
  3544. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3545. status = decode_compound_hdr(&xdr, &hdr);
  3546. if (status)
  3547. goto out;
  3548. status = decode_putfh(&xdr);
  3549. if (status)
  3550. goto out;
  3551. status = decode_savefh(&xdr);
  3552. if (status)
  3553. goto out;
  3554. status = decode_open(&xdr, res);
  3555. if (status)
  3556. goto out;
  3557. status = decode_getfh(&xdr, &res->fh);
  3558. if (status)
  3559. goto out;
  3560. if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
  3561. goto out;
  3562. if ((status = decode_restorefh(&xdr)) != 0)
  3563. goto out;
  3564. decode_getfattr(&xdr, res->dir_attr, res->server);
  3565. out:
  3566. return status;
  3567. }
  3568. /*
  3569. * Decode OPEN_CONFIRM response
  3570. */
  3571. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
  3572. {
  3573. struct xdr_stream xdr;
  3574. struct compound_hdr hdr;
  3575. int status;
  3576. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3577. status = decode_compound_hdr(&xdr, &hdr);
  3578. if (status)
  3579. goto out;
  3580. status = decode_putfh(&xdr);
  3581. if (status)
  3582. goto out;
  3583. status = decode_open_confirm(&xdr, res);
  3584. out:
  3585. return status;
  3586. }
  3587. /*
  3588. * Decode OPEN response
  3589. */
  3590. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
  3591. {
  3592. struct xdr_stream xdr;
  3593. struct compound_hdr hdr;
  3594. int status;
  3595. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3596. status = decode_compound_hdr(&xdr, &hdr);
  3597. if (status)
  3598. goto out;
  3599. status = decode_putfh(&xdr);
  3600. if (status)
  3601. goto out;
  3602. status = decode_open(&xdr, res);
  3603. if (status)
  3604. goto out;
  3605. decode_getfattr(&xdr, res->f_attr, res->server);
  3606. out:
  3607. return status;
  3608. }
  3609. /*
  3610. * Decode SETATTR response
  3611. */
  3612. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
  3613. {
  3614. struct xdr_stream xdr;
  3615. struct compound_hdr hdr;
  3616. int status;
  3617. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3618. status = decode_compound_hdr(&xdr, &hdr);
  3619. if (status)
  3620. goto out;
  3621. status = decode_putfh(&xdr);
  3622. if (status)
  3623. goto out;
  3624. status = decode_setattr(&xdr, res);
  3625. if (status)
  3626. goto out;
  3627. status = decode_getfattr(&xdr, res->fattr, res->server);
  3628. if (status == NFS4ERR_DELAY)
  3629. status = 0;
  3630. out:
  3631. return status;
  3632. }
  3633. /*
  3634. * Decode LOCK response
  3635. */
  3636. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
  3637. {
  3638. struct xdr_stream xdr;
  3639. struct compound_hdr hdr;
  3640. int status;
  3641. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3642. status = decode_compound_hdr(&xdr, &hdr);
  3643. if (status)
  3644. goto out;
  3645. status = decode_putfh(&xdr);
  3646. if (status)
  3647. goto out;
  3648. status = decode_lock(&xdr, res);
  3649. out:
  3650. return status;
  3651. }
  3652. /*
  3653. * Decode LOCKT response
  3654. */
  3655. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
  3656. {
  3657. struct xdr_stream xdr;
  3658. struct compound_hdr hdr;
  3659. int status;
  3660. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3661. status = decode_compound_hdr(&xdr, &hdr);
  3662. if (status)
  3663. goto out;
  3664. status = decode_putfh(&xdr);
  3665. if (status)
  3666. goto out;
  3667. status = decode_lockt(&xdr, res);
  3668. out:
  3669. return status;
  3670. }
  3671. /*
  3672. * Decode LOCKU response
  3673. */
  3674. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
  3675. {
  3676. struct xdr_stream xdr;
  3677. struct compound_hdr hdr;
  3678. int status;
  3679. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3680. status = decode_compound_hdr(&xdr, &hdr);
  3681. if (status)
  3682. goto out;
  3683. status = decode_putfh(&xdr);
  3684. if (status)
  3685. goto out;
  3686. status = decode_locku(&xdr, res);
  3687. out:
  3688. return status;
  3689. }
  3690. /*
  3691. * Decode READLINK response
  3692. */
  3693. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
  3694. {
  3695. struct xdr_stream xdr;
  3696. struct compound_hdr hdr;
  3697. int status;
  3698. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3699. status = decode_compound_hdr(&xdr, &hdr);
  3700. if (status)
  3701. goto out;
  3702. status = decode_putfh(&xdr);
  3703. if (status)
  3704. goto out;
  3705. status = decode_readlink(&xdr, rqstp);
  3706. out:
  3707. return status;
  3708. }
  3709. /*
  3710. * Decode READDIR response
  3711. */
  3712. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
  3713. {
  3714. struct xdr_stream xdr;
  3715. struct compound_hdr hdr;
  3716. int status;
  3717. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3718. status = decode_compound_hdr(&xdr, &hdr);
  3719. if (status)
  3720. goto out;
  3721. status = decode_putfh(&xdr);
  3722. if (status)
  3723. goto out;
  3724. status = decode_readdir(&xdr, rqstp, res);
  3725. out:
  3726. return status;
  3727. }
  3728. /*
  3729. * Decode Read response
  3730. */
  3731. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
  3732. {
  3733. struct xdr_stream xdr;
  3734. struct compound_hdr hdr;
  3735. int status;
  3736. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3737. status = decode_compound_hdr(&xdr, &hdr);
  3738. if (status)
  3739. goto out;
  3740. status = decode_putfh(&xdr);
  3741. if (status)
  3742. goto out;
  3743. status = decode_read(&xdr, rqstp, res);
  3744. if (!status)
  3745. status = res->count;
  3746. out:
  3747. return status;
  3748. }
  3749. /*
  3750. * Decode WRITE response
  3751. */
  3752. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
  3753. {
  3754. struct xdr_stream xdr;
  3755. struct compound_hdr hdr;
  3756. int status;
  3757. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3758. status = decode_compound_hdr(&xdr, &hdr);
  3759. if (status)
  3760. goto out;
  3761. status = decode_putfh(&xdr);
  3762. if (status)
  3763. goto out;
  3764. status = decode_write(&xdr, res);
  3765. if (status)
  3766. goto out;
  3767. decode_getfattr(&xdr, res->fattr, res->server);
  3768. if (!status)
  3769. status = res->count;
  3770. out:
  3771. return status;
  3772. }
  3773. /*
  3774. * Decode COMMIT response
  3775. */
  3776. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
  3777. {
  3778. struct xdr_stream xdr;
  3779. struct compound_hdr hdr;
  3780. int status;
  3781. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3782. status = decode_compound_hdr(&xdr, &hdr);
  3783. if (status)
  3784. goto out;
  3785. status = decode_putfh(&xdr);
  3786. if (status)
  3787. goto out;
  3788. status = decode_commit(&xdr, res);
  3789. if (status)
  3790. goto out;
  3791. decode_getfattr(&xdr, res->fattr, res->server);
  3792. out:
  3793. return status;
  3794. }
  3795. /*
  3796. * FSINFO request
  3797. */
  3798. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
  3799. {
  3800. struct xdr_stream xdr;
  3801. struct compound_hdr hdr;
  3802. int status;
  3803. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3804. status = decode_compound_hdr(&xdr, &hdr);
  3805. if (!status)
  3806. status = decode_putfh(&xdr);
  3807. if (!status)
  3808. status = decode_fsinfo(&xdr, fsinfo);
  3809. if (!status)
  3810. status = -nfs4_stat_to_errno(hdr.status);
  3811. return status;
  3812. }
  3813. /*
  3814. * PATHCONF request
  3815. */
  3816. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
  3817. {
  3818. struct xdr_stream xdr;
  3819. struct compound_hdr hdr;
  3820. int status;
  3821. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3822. status = decode_compound_hdr(&xdr, &hdr);
  3823. if (!status)
  3824. status = decode_putfh(&xdr);
  3825. if (!status)
  3826. status = decode_pathconf(&xdr, pathconf);
  3827. return status;
  3828. }
  3829. /*
  3830. * STATFS request
  3831. */
  3832. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
  3833. {
  3834. struct xdr_stream xdr;
  3835. struct compound_hdr hdr;
  3836. int status;
  3837. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3838. status = decode_compound_hdr(&xdr, &hdr);
  3839. if (!status)
  3840. status = decode_putfh(&xdr);
  3841. if (!status)
  3842. status = decode_statfs(&xdr, fsstat);
  3843. return status;
  3844. }
  3845. /*
  3846. * GETATTR_BITMAP request
  3847. */
  3848. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
  3849. {
  3850. struct xdr_stream xdr;
  3851. struct compound_hdr hdr;
  3852. int status;
  3853. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3854. if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
  3855. goto out;
  3856. if ((status = decode_putfh(&xdr)) != 0)
  3857. goto out;
  3858. status = decode_server_caps(&xdr, res);
  3859. out:
  3860. return status;
  3861. }
  3862. /*
  3863. * Decode RENEW response
  3864. */
  3865. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
  3866. {
  3867. struct xdr_stream xdr;
  3868. struct compound_hdr hdr;
  3869. int status;
  3870. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3871. status = decode_compound_hdr(&xdr, &hdr);
  3872. if (!status)
  3873. status = decode_renew(&xdr);
  3874. return status;
  3875. }
  3876. /*
  3877. * a SETCLIENTID request
  3878. */
  3879. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
  3880. struct nfs_client *clp)
  3881. {
  3882. struct xdr_stream xdr;
  3883. struct compound_hdr hdr;
  3884. int status;
  3885. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3886. status = decode_compound_hdr(&xdr, &hdr);
  3887. if (!status)
  3888. status = decode_setclientid(&xdr, clp);
  3889. if (!status)
  3890. status = -nfs4_stat_to_errno(hdr.status);
  3891. return status;
  3892. }
  3893. /*
  3894. * a SETCLIENTID_CONFIRM request
  3895. */
  3896. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
  3897. {
  3898. struct xdr_stream xdr;
  3899. struct compound_hdr hdr;
  3900. int status;
  3901. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3902. status = decode_compound_hdr(&xdr, &hdr);
  3903. if (!status)
  3904. status = decode_setclientid_confirm(&xdr);
  3905. if (!status)
  3906. status = decode_putrootfh(&xdr);
  3907. if (!status)
  3908. status = decode_fsinfo(&xdr, fsinfo);
  3909. if (!status)
  3910. status = -nfs4_stat_to_errno(hdr.status);
  3911. return status;
  3912. }
  3913. /*
  3914. * DELEGRETURN request
  3915. */
  3916. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
  3917. {
  3918. struct xdr_stream xdr;
  3919. struct compound_hdr hdr;
  3920. int status;
  3921. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3922. status = decode_compound_hdr(&xdr, &hdr);
  3923. if (status != 0)
  3924. goto out;
  3925. status = decode_putfh(&xdr);
  3926. if (status != 0)
  3927. goto out;
  3928. status = decode_delegreturn(&xdr);
  3929. decode_getfattr(&xdr, res->fattr, res->server);
  3930. out:
  3931. return status;
  3932. }
  3933. /*
  3934. * FS_LOCATIONS request
  3935. */
  3936. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
  3937. {
  3938. struct xdr_stream xdr;
  3939. struct compound_hdr hdr;
  3940. int status;
  3941. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  3942. status = decode_compound_hdr(&xdr, &hdr);
  3943. if (status != 0)
  3944. goto out;
  3945. if ((status = decode_putfh(&xdr)) != 0)
  3946. goto out;
  3947. if ((status = decode_lookup(&xdr)) != 0)
  3948. goto out;
  3949. xdr_enter_page(&xdr, PAGE_SIZE);
  3950. status = decode_getfattr(&xdr, &res->fattr, res->server);
  3951. out:
  3952. return status;
  3953. }
  3954. __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
  3955. {
  3956. uint32_t bitmap[2] = {0};
  3957. uint32_t len;
  3958. if (!*p++) {
  3959. if (!*p)
  3960. return ERR_PTR(-EAGAIN);
  3961. entry->eof = 1;
  3962. return ERR_PTR(-EBADCOOKIE);
  3963. }
  3964. entry->prev_cookie = entry->cookie;
  3965. p = xdr_decode_hyper(p, &entry->cookie);
  3966. entry->len = ntohl(*p++);
  3967. entry->name = (const char *) p;
  3968. p += XDR_QUADLEN(entry->len);
  3969. /*
  3970. * In case the server doesn't return an inode number,
  3971. * we fake one here. (We don't use inode number 0,
  3972. * since glibc seems to choke on it...)
  3973. */
  3974. entry->ino = 1;
  3975. len = ntohl(*p++); /* bitmap length */
  3976. if (len-- > 0) {
  3977. bitmap[0] = ntohl(*p++);
  3978. if (len-- > 0) {
  3979. bitmap[1] = ntohl(*p++);
  3980. p += len;
  3981. }
  3982. }
  3983. len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
  3984. if (len > 0) {
  3985. if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
  3986. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3987. /* Ignore the return value of rdattr_error for now */
  3988. p++;
  3989. len--;
  3990. }
  3991. if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
  3992. xdr_decode_hyper(p, &entry->ino);
  3993. else if (bitmap[0] == FATTR4_WORD0_FILEID)
  3994. xdr_decode_hyper(p, &entry->ino);
  3995. p += len;
  3996. }
  3997. entry->eof = !p[0] && p[1];
  3998. return p;
  3999. }
  4000. /*
  4001. * We need to translate between nfs status return values and
  4002. * the local errno values which may not be the same.
  4003. */
  4004. static struct {
  4005. int stat;
  4006. int errno;
  4007. } nfs_errtbl[] = {
  4008. { NFS4_OK, 0 },
  4009. { NFS4ERR_PERM, EPERM },
  4010. { NFS4ERR_NOENT, ENOENT },
  4011. { NFS4ERR_IO, errno_NFSERR_IO },
  4012. { NFS4ERR_NXIO, ENXIO },
  4013. { NFS4ERR_ACCESS, EACCES },
  4014. { NFS4ERR_EXIST, EEXIST },
  4015. { NFS4ERR_XDEV, EXDEV },
  4016. { NFS4ERR_NOTDIR, ENOTDIR },
  4017. { NFS4ERR_ISDIR, EISDIR },
  4018. { NFS4ERR_INVAL, EINVAL },
  4019. { NFS4ERR_FBIG, EFBIG },
  4020. { NFS4ERR_NOSPC, ENOSPC },
  4021. { NFS4ERR_ROFS, EROFS },
  4022. { NFS4ERR_MLINK, EMLINK },
  4023. { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
  4024. { NFS4ERR_NOTEMPTY, ENOTEMPTY },
  4025. { NFS4ERR_DQUOT, EDQUOT },
  4026. { NFS4ERR_STALE, ESTALE },
  4027. { NFS4ERR_BADHANDLE, EBADHANDLE },
  4028. { NFS4ERR_BADOWNER, EINVAL },
  4029. { NFS4ERR_BADNAME, EINVAL },
  4030. { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
  4031. { NFS4ERR_NOTSUPP, ENOTSUPP },
  4032. { NFS4ERR_TOOSMALL, ETOOSMALL },
  4033. { NFS4ERR_SERVERFAULT, ESERVERFAULT },
  4034. { NFS4ERR_BADTYPE, EBADTYPE },
  4035. { NFS4ERR_LOCKED, EAGAIN },
  4036. { NFS4ERR_RESOURCE, EREMOTEIO },
  4037. { NFS4ERR_SYMLINK, ELOOP },
  4038. { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
  4039. { NFS4ERR_DEADLOCK, EDEADLK },
  4040. { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
  4041. * to be handled by a
  4042. * middle-layer.
  4043. */
  4044. { -1, EIO }
  4045. };
  4046. /*
  4047. * Convert an NFS error code to a local one.
  4048. * This one is used jointly by NFSv2 and NFSv3.
  4049. */
  4050. static int
  4051. nfs4_stat_to_errno(int stat)
  4052. {
  4053. int i;
  4054. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  4055. if (nfs_errtbl[i].stat == stat)
  4056. return nfs_errtbl[i].errno;
  4057. }
  4058. if (stat <= 10000 || stat > 10100) {
  4059. /* The server is looney tunes. */
  4060. return ESERVERFAULT;
  4061. }
  4062. /* If we cannot translate the error, the recovery routines should
  4063. * handle it.
  4064. * Note: remaining NFSv4 error codes have values > 10000, so should
  4065. * not conflict with native Linux error codes.
  4066. */
  4067. return stat;
  4068. }
  4069. #ifndef MAX
  4070. # define MAX(a, b) (((a) > (b))? (a) : (b))
  4071. #endif
  4072. #define PROC(proc, argtype, restype) \
  4073. [NFSPROC4_CLNT_##proc] = { \
  4074. .p_proc = NFSPROC4_COMPOUND, \
  4075. .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
  4076. .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
  4077. .p_bufsiz = MAX(NFS4_##argtype##_sz,NFS4_##restype##_sz) << 2, \
  4078. .p_statidx = NFSPROC4_CLNT_##proc, \
  4079. .p_name = #proc, \
  4080. }
  4081. struct rpc_procinfo nfs4_procedures[] = {
  4082. PROC(READ, enc_read, dec_read),
  4083. PROC(WRITE, enc_write, dec_write),
  4084. PROC(COMMIT, enc_commit, dec_commit),
  4085. PROC(OPEN, enc_open, dec_open),
  4086. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  4087. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  4088. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  4089. PROC(CLOSE, enc_close, dec_close),
  4090. PROC(SETATTR, enc_setattr, dec_setattr),
  4091. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  4092. PROC(RENEW, enc_renew, dec_renew),
  4093. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  4094. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  4095. PROC(LOCK, enc_lock, dec_lock),
  4096. PROC(LOCKT, enc_lockt, dec_lockt),
  4097. PROC(LOCKU, enc_locku, dec_locku),
  4098. PROC(ACCESS, enc_access, dec_access),
  4099. PROC(GETATTR, enc_getattr, dec_getattr),
  4100. PROC(LOOKUP, enc_lookup, dec_lookup),
  4101. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  4102. PROC(REMOVE, enc_remove, dec_remove),
  4103. PROC(RENAME, enc_rename, dec_rename),
  4104. PROC(LINK, enc_link, dec_link),
  4105. PROC(SYMLINK, enc_symlink, dec_symlink),
  4106. PROC(CREATE, enc_create, dec_create),
  4107. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  4108. PROC(STATFS, enc_statfs, dec_statfs),
  4109. PROC(READLINK, enc_readlink, dec_readlink),
  4110. PROC(READDIR, enc_readdir, dec_readdir),
  4111. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  4112. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  4113. PROC(GETACL, enc_getacl, dec_getacl),
  4114. PROC(SETACL, enc_setacl, dec_setacl),
  4115. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  4116. };
  4117. struct rpc_version nfs_version4 = {
  4118. .number = 4,
  4119. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  4120. .procs = nfs4_procedures
  4121. };
  4122. /*
  4123. * Local variables:
  4124. * c-basic-offset: 8
  4125. * End:
  4126. */