nfs4xdr.c 114 KB

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