nfs4xdr.c 118 KB

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