nfs4xdr.c 115 KB

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