nfs4xdr.c 120 KB

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