nfs4xdr.c 115 KB

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