nfs4xdr.c 115 KB

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