nfs4xdr.c 117 KB

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