nfs4xdr.c 118 KB

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