nfs4xdr.c 116 KB

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