nfs4xdr.c 119 KB

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