nfs4xdr.c 126 KB

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