nfs4xdr.c 117 KB

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