nfs4xdr.c 116 KB

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