nfs4xdr.c 115 KB

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