nfs4xdr.c 118 KB

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