nfs4xdr.c 116 KB

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