nfs4xdr.c 163 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284
  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/errno.h>
  41. #include <linux/string.h>
  42. #include <linux/in.h>
  43. #include <linux/pagemap.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/kdev_t.h>
  46. #include <linux/sunrpc/clnt.h>
  47. #include <linux/sunrpc/msg_prot.h>
  48. #include <linux/nfs.h>
  49. #include <linux/nfs4.h>
  50. #include <linux/nfs_fs.h>
  51. #include <linux/nfs_idmap.h>
  52. #include "nfs4_fs.h"
  53. #include "internal.h"
  54. #include "pnfs.h"
  55. #define NFSDBG_FACILITY NFSDBG_XDR
  56. /* Mapping from NFS error code to "errno" error code. */
  57. #define errno_NFSERR_IO EIO
  58. static int nfs4_stat_to_errno(int);
  59. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  60. #ifdef DEBUG
  61. #define NFS4_MAXTAGLEN 20
  62. #else
  63. #define NFS4_MAXTAGLEN 0
  64. #endif
  65. /* lock,open owner id:
  66. * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
  67. */
  68. #define open_owner_id_maxsz (1 + 1 + 4)
  69. #define lock_owner_id_maxsz (1 + 1 + 4)
  70. #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  71. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  72. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  73. #define op_encode_hdr_maxsz (1)
  74. #define op_decode_hdr_maxsz (2)
  75. #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  76. #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  77. #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  78. #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  79. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  80. (NFS4_FHSIZE >> 2))
  81. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  82. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  83. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  84. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  85. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  86. ((3+NFS4_FHSIZE) >> 2))
  87. #define nfs4_fattr_bitmap_maxsz 3
  88. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  89. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  90. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  91. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  92. #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  93. /* This is based on getfattr, which uses the most attributes: */
  94. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  95. 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
  96. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  97. nfs4_fattr_value_maxsz)
  98. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  99. #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
  100. 1 + 2 + 1 + \
  101. nfs4_owner_maxsz + \
  102. nfs4_group_maxsz + \
  103. 4 + 4)
  104. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  105. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  106. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  107. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  108. #define encode_fsinfo_maxsz (encode_getattr_maxsz)
  109. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
  110. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  111. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  112. #define encode_setclientid_maxsz \
  113. (op_encode_hdr_maxsz + \
  114. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  115. XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
  116. 1 /* sc_prog */ + \
  117. XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  118. XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
  119. 1) /* sc_cb_ident */
  120. #define decode_setclientid_maxsz \
  121. (op_decode_hdr_maxsz + \
  122. 2 + \
  123. 1024) /* large value for CLID_INUSE */
  124. #define encode_setclientid_confirm_maxsz \
  125. (op_encode_hdr_maxsz + \
  126. 3 + (NFS4_VERIFIER_SIZE >> 2))
  127. #define decode_setclientid_confirm_maxsz \
  128. (op_decode_hdr_maxsz)
  129. #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  130. #define decode_lookup_maxsz (op_decode_hdr_maxsz)
  131. #define encode_share_access_maxsz \
  132. (2)
  133. #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
  134. #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
  135. #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
  136. #define encode_open_maxsz (op_encode_hdr_maxsz + \
  137. 2 + encode_share_access_maxsz + 2 + \
  138. open_owner_id_maxsz + \
  139. encode_opentype_maxsz + \
  140. encode_claim_null_maxsz)
  141. #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
  142. #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
  143. decode_ace_maxsz)
  144. #define decode_change_info_maxsz (5)
  145. #define decode_open_maxsz (op_decode_hdr_maxsz + \
  146. decode_stateid_maxsz + \
  147. decode_change_info_maxsz + 1 + \
  148. nfs4_fattr_bitmap_maxsz + \
  149. decode_delegation_maxsz)
  150. #define encode_open_confirm_maxsz \
  151. (op_encode_hdr_maxsz + \
  152. encode_stateid_maxsz + 1)
  153. #define decode_open_confirm_maxsz \
  154. (op_decode_hdr_maxsz + \
  155. decode_stateid_maxsz)
  156. #define encode_open_downgrade_maxsz \
  157. (op_encode_hdr_maxsz + \
  158. encode_stateid_maxsz + 1 + \
  159. encode_share_access_maxsz)
  160. #define decode_open_downgrade_maxsz \
  161. (op_decode_hdr_maxsz + \
  162. decode_stateid_maxsz)
  163. #define encode_close_maxsz (op_encode_hdr_maxsz + \
  164. 1 + encode_stateid_maxsz)
  165. #define decode_close_maxsz (op_decode_hdr_maxsz + \
  166. decode_stateid_maxsz)
  167. #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
  168. encode_stateid_maxsz + \
  169. encode_attrs_maxsz)
  170. #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
  171. nfs4_fattr_bitmap_maxsz)
  172. #define encode_read_maxsz (op_encode_hdr_maxsz + \
  173. encode_stateid_maxsz + 3)
  174. #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
  175. #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
  176. 2 + encode_verifier_maxsz + 5)
  177. #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
  178. decode_verifier_maxsz)
  179. #define encode_readlink_maxsz (op_encode_hdr_maxsz)
  180. #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
  181. #define encode_write_maxsz (op_encode_hdr_maxsz + \
  182. encode_stateid_maxsz + 4)
  183. #define decode_write_maxsz (op_decode_hdr_maxsz + \
  184. 2 + decode_verifier_maxsz)
  185. #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
  186. #define decode_commit_maxsz (op_decode_hdr_maxsz + \
  187. decode_verifier_maxsz)
  188. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  189. nfs4_name_maxsz)
  190. #define decode_remove_maxsz (op_decode_hdr_maxsz + \
  191. decode_change_info_maxsz)
  192. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  193. 2 * nfs4_name_maxsz)
  194. #define decode_rename_maxsz (op_decode_hdr_maxsz + \
  195. decode_change_info_maxsz + \
  196. decode_change_info_maxsz)
  197. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  198. nfs4_name_maxsz)
  199. #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  200. #define encode_lockowner_maxsz (7)
  201. #define encode_lock_maxsz (op_encode_hdr_maxsz + \
  202. 7 + \
  203. 1 + encode_stateid_maxsz + 1 + \
  204. encode_lockowner_maxsz)
  205. #define decode_lock_denied_maxsz \
  206. (8 + decode_lockowner_maxsz)
  207. #define decode_lock_maxsz (op_decode_hdr_maxsz + \
  208. decode_lock_denied_maxsz)
  209. #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
  210. encode_lockowner_maxsz)
  211. #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
  212. decode_lock_denied_maxsz)
  213. #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
  214. encode_stateid_maxsz + \
  215. 4)
  216. #define decode_locku_maxsz (op_decode_hdr_maxsz + \
  217. decode_stateid_maxsz)
  218. #define encode_release_lockowner_maxsz \
  219. (op_encode_hdr_maxsz + \
  220. encode_lockowner_maxsz)
  221. #define decode_release_lockowner_maxsz \
  222. (op_decode_hdr_maxsz)
  223. #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
  224. #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
  225. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  226. 1 + nfs4_name_maxsz + \
  227. 1 + \
  228. nfs4_fattr_maxsz)
  229. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  230. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  231. 1 + 2 + nfs4_name_maxsz + \
  232. encode_attrs_maxsz)
  233. #define decode_create_maxsz (op_decode_hdr_maxsz + \
  234. decode_change_info_maxsz + \
  235. nfs4_fattr_bitmap_maxsz)
  236. #define encode_statfs_maxsz (encode_getattr_maxsz)
  237. #define decode_statfs_maxsz (decode_getattr_maxsz)
  238. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  239. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  240. #define encode_getacl_maxsz (encode_getattr_maxsz)
  241. #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
  242. nfs4_fattr_bitmap_maxsz + 1)
  243. #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
  244. encode_stateid_maxsz + 3)
  245. #define decode_setacl_maxsz (decode_setattr_maxsz)
  246. #define encode_fs_locations_maxsz \
  247. (encode_getattr_maxsz)
  248. #define decode_fs_locations_maxsz \
  249. (0)
  250. #if defined(CONFIG_NFS_V4_1)
  251. #define NFS4_MAX_MACHINE_NAME_LEN (64)
  252. #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
  253. encode_verifier_maxsz + \
  254. 1 /* co_ownerid.len */ + \
  255. XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
  256. 1 /* flags */ + \
  257. 1 /* spa_how */ + \
  258. 0 /* SP4_NONE (for now) */ + \
  259. 1 /* zero implemetation id array */)
  260. #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
  261. 2 /* eir_clientid */ + \
  262. 1 /* eir_sequenceid */ + \
  263. 1 /* eir_flags */ + \
  264. 1 /* spr_how */ + \
  265. 0 /* SP4_NONE (for now) */ + \
  266. 2 /* eir_server_owner.so_minor_id */ + \
  267. /* eir_server_owner.so_major_id<> */ \
  268. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  269. /* eir_server_scope<> */ \
  270. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  271. 1 /* eir_server_impl_id array length */ + \
  272. 0 /* ignored eir_server_impl_id contents */)
  273. #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
  274. #define decode_channel_attrs_maxsz (6 + \
  275. 1 /* ca_rdma_ird.len */ + \
  276. 1 /* ca_rdma_ird */)
  277. #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
  278. 2 /* csa_clientid */ + \
  279. 1 /* csa_sequence */ + \
  280. 1 /* csa_flags */ + \
  281. encode_channel_attrs_maxsz + \
  282. encode_channel_attrs_maxsz + \
  283. 1 /* csa_cb_program */ + \
  284. 1 /* csa_sec_parms.len (1) */ + \
  285. 1 /* cb_secflavor (AUTH_SYS) */ + \
  286. 1 /* stamp */ + \
  287. 1 /* machinename.len */ + \
  288. XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
  289. 1 /* uid */ + \
  290. 1 /* gid */ + \
  291. 1 /* gids.len (0) */)
  292. #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
  293. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  294. 1 /* csr_sequence */ + \
  295. 1 /* csr_flags */ + \
  296. decode_channel_attrs_maxsz + \
  297. decode_channel_attrs_maxsz)
  298. #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
  299. #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
  300. #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
  301. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
  302. #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
  303. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
  304. #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
  305. #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
  306. #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
  307. XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
  308. #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
  309. 1 /* layout type */ + \
  310. 1 /* opaque devaddr4 length */ + \
  311. /* devaddr4 payload is read into page */ \
  312. 1 /* notification bitmap length */ + \
  313. 1 /* notification bitmap */)
  314. #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
  315. encode_stateid_maxsz)
  316. #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
  317. decode_stateid_maxsz + \
  318. XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
  319. #else /* CONFIG_NFS_V4_1 */
  320. #define encode_sequence_maxsz 0
  321. #define decode_sequence_maxsz 0
  322. #endif /* CONFIG_NFS_V4_1 */
  323. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  324. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  325. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  326. encode_sequence_maxsz + \
  327. encode_putfh_maxsz + \
  328. encode_read_maxsz)
  329. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  330. decode_sequence_maxsz + \
  331. decode_putfh_maxsz + \
  332. decode_read_maxsz)
  333. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  334. encode_sequence_maxsz + \
  335. encode_putfh_maxsz + \
  336. encode_readlink_maxsz)
  337. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  338. decode_sequence_maxsz + \
  339. decode_putfh_maxsz + \
  340. decode_readlink_maxsz)
  341. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  342. encode_sequence_maxsz + \
  343. encode_putfh_maxsz + \
  344. encode_readdir_maxsz)
  345. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  346. decode_sequence_maxsz + \
  347. decode_putfh_maxsz + \
  348. decode_readdir_maxsz)
  349. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  350. encode_sequence_maxsz + \
  351. encode_putfh_maxsz + \
  352. encode_write_maxsz + \
  353. encode_getattr_maxsz)
  354. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  355. decode_sequence_maxsz + \
  356. decode_putfh_maxsz + \
  357. decode_write_maxsz + \
  358. decode_getattr_maxsz)
  359. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  360. encode_sequence_maxsz + \
  361. encode_putfh_maxsz + \
  362. encode_commit_maxsz + \
  363. encode_getattr_maxsz)
  364. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  365. decode_sequence_maxsz + \
  366. decode_putfh_maxsz + \
  367. decode_commit_maxsz + \
  368. decode_getattr_maxsz)
  369. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  370. encode_sequence_maxsz + \
  371. encode_putfh_maxsz + \
  372. encode_savefh_maxsz + \
  373. encode_open_maxsz + \
  374. encode_getfh_maxsz + \
  375. encode_getattr_maxsz + \
  376. encode_restorefh_maxsz + \
  377. encode_getattr_maxsz)
  378. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  379. decode_sequence_maxsz + \
  380. decode_putfh_maxsz + \
  381. decode_savefh_maxsz + \
  382. decode_open_maxsz + \
  383. decode_getfh_maxsz + \
  384. decode_getattr_maxsz + \
  385. decode_restorefh_maxsz + \
  386. decode_getattr_maxsz)
  387. #define NFS4_enc_open_confirm_sz \
  388. (compound_encode_hdr_maxsz + \
  389. encode_putfh_maxsz + \
  390. encode_open_confirm_maxsz)
  391. #define NFS4_dec_open_confirm_sz \
  392. (compound_decode_hdr_maxsz + \
  393. decode_putfh_maxsz + \
  394. decode_open_confirm_maxsz)
  395. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  396. encode_sequence_maxsz + \
  397. encode_putfh_maxsz + \
  398. encode_open_maxsz + \
  399. encode_getattr_maxsz)
  400. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  401. decode_sequence_maxsz + \
  402. decode_putfh_maxsz + \
  403. decode_open_maxsz + \
  404. decode_getattr_maxsz)
  405. #define NFS4_enc_open_downgrade_sz \
  406. (compound_encode_hdr_maxsz + \
  407. encode_sequence_maxsz + \
  408. encode_putfh_maxsz + \
  409. encode_open_downgrade_maxsz + \
  410. encode_getattr_maxsz)
  411. #define NFS4_dec_open_downgrade_sz \
  412. (compound_decode_hdr_maxsz + \
  413. decode_sequence_maxsz + \
  414. decode_putfh_maxsz + \
  415. decode_open_downgrade_maxsz + \
  416. decode_getattr_maxsz)
  417. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  418. encode_sequence_maxsz + \
  419. encode_putfh_maxsz + \
  420. encode_close_maxsz + \
  421. encode_getattr_maxsz)
  422. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  423. decode_sequence_maxsz + \
  424. decode_putfh_maxsz + \
  425. decode_close_maxsz + \
  426. decode_getattr_maxsz)
  427. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  428. encode_sequence_maxsz + \
  429. encode_putfh_maxsz + \
  430. encode_setattr_maxsz + \
  431. encode_getattr_maxsz)
  432. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  433. decode_sequence_maxsz + \
  434. decode_putfh_maxsz + \
  435. decode_setattr_maxsz + \
  436. decode_getattr_maxsz)
  437. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  438. encode_sequence_maxsz + \
  439. encode_putfh_maxsz + \
  440. encode_fsinfo_maxsz)
  441. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  442. decode_sequence_maxsz + \
  443. decode_putfh_maxsz + \
  444. decode_fsinfo_maxsz)
  445. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  446. encode_renew_maxsz)
  447. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  448. decode_renew_maxsz)
  449. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  450. encode_setclientid_maxsz)
  451. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  452. decode_setclientid_maxsz)
  453. #define NFS4_enc_setclientid_confirm_sz \
  454. (compound_encode_hdr_maxsz + \
  455. encode_setclientid_confirm_maxsz + \
  456. encode_putrootfh_maxsz + \
  457. encode_fsinfo_maxsz)
  458. #define NFS4_dec_setclientid_confirm_sz \
  459. (compound_decode_hdr_maxsz + \
  460. decode_setclientid_confirm_maxsz + \
  461. decode_putrootfh_maxsz + \
  462. decode_fsinfo_maxsz)
  463. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  464. encode_sequence_maxsz + \
  465. encode_putfh_maxsz + \
  466. encode_lock_maxsz)
  467. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  468. decode_sequence_maxsz + \
  469. decode_putfh_maxsz + \
  470. decode_lock_maxsz)
  471. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  472. encode_sequence_maxsz + \
  473. encode_putfh_maxsz + \
  474. encode_lockt_maxsz)
  475. #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
  476. decode_sequence_maxsz + \
  477. decode_putfh_maxsz + \
  478. decode_lockt_maxsz)
  479. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  480. encode_sequence_maxsz + \
  481. encode_putfh_maxsz + \
  482. encode_locku_maxsz)
  483. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  484. decode_sequence_maxsz + \
  485. decode_putfh_maxsz + \
  486. decode_locku_maxsz)
  487. #define NFS4_enc_release_lockowner_sz \
  488. (compound_encode_hdr_maxsz + \
  489. encode_lockowner_maxsz)
  490. #define NFS4_dec_release_lockowner_sz \
  491. (compound_decode_hdr_maxsz + \
  492. decode_lockowner_maxsz)
  493. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  494. encode_sequence_maxsz + \
  495. encode_putfh_maxsz + \
  496. encode_access_maxsz + \
  497. encode_getattr_maxsz)
  498. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  499. decode_sequence_maxsz + \
  500. decode_putfh_maxsz + \
  501. decode_access_maxsz + \
  502. decode_getattr_maxsz)
  503. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  504. encode_sequence_maxsz + \
  505. encode_putfh_maxsz + \
  506. encode_getattr_maxsz)
  507. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  508. decode_sequence_maxsz + \
  509. decode_putfh_maxsz + \
  510. decode_getattr_maxsz)
  511. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  512. encode_sequence_maxsz + \
  513. encode_putfh_maxsz + \
  514. encode_lookup_maxsz + \
  515. encode_getattr_maxsz + \
  516. encode_getfh_maxsz)
  517. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  518. decode_sequence_maxsz + \
  519. decode_putfh_maxsz + \
  520. decode_lookup_maxsz + \
  521. decode_getattr_maxsz + \
  522. decode_getfh_maxsz)
  523. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  524. encode_sequence_maxsz + \
  525. encode_putrootfh_maxsz + \
  526. encode_getattr_maxsz + \
  527. encode_getfh_maxsz)
  528. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  529. decode_sequence_maxsz + \
  530. decode_putrootfh_maxsz + \
  531. decode_getattr_maxsz + \
  532. decode_getfh_maxsz)
  533. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  534. encode_sequence_maxsz + \
  535. encode_putfh_maxsz + \
  536. encode_remove_maxsz + \
  537. encode_getattr_maxsz)
  538. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  539. decode_sequence_maxsz + \
  540. decode_putfh_maxsz + \
  541. decode_remove_maxsz + \
  542. decode_getattr_maxsz)
  543. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  544. encode_sequence_maxsz + \
  545. encode_putfh_maxsz + \
  546. encode_savefh_maxsz + \
  547. encode_putfh_maxsz + \
  548. encode_rename_maxsz + \
  549. encode_getattr_maxsz + \
  550. encode_restorefh_maxsz + \
  551. encode_getattr_maxsz)
  552. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  553. decode_sequence_maxsz + \
  554. decode_putfh_maxsz + \
  555. decode_savefh_maxsz + \
  556. decode_putfh_maxsz + \
  557. decode_rename_maxsz + \
  558. decode_getattr_maxsz + \
  559. decode_restorefh_maxsz + \
  560. decode_getattr_maxsz)
  561. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  562. encode_sequence_maxsz + \
  563. encode_putfh_maxsz + \
  564. encode_savefh_maxsz + \
  565. encode_putfh_maxsz + \
  566. encode_link_maxsz + \
  567. decode_getattr_maxsz + \
  568. encode_restorefh_maxsz + \
  569. decode_getattr_maxsz)
  570. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  571. decode_sequence_maxsz + \
  572. decode_putfh_maxsz + \
  573. decode_savefh_maxsz + \
  574. decode_putfh_maxsz + \
  575. decode_link_maxsz + \
  576. decode_getattr_maxsz + \
  577. decode_restorefh_maxsz + \
  578. decode_getattr_maxsz)
  579. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  580. encode_sequence_maxsz + \
  581. encode_putfh_maxsz + \
  582. encode_symlink_maxsz + \
  583. encode_getattr_maxsz + \
  584. encode_getfh_maxsz)
  585. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  586. decode_sequence_maxsz + \
  587. decode_putfh_maxsz + \
  588. decode_symlink_maxsz + \
  589. decode_getattr_maxsz + \
  590. decode_getfh_maxsz)
  591. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  592. encode_sequence_maxsz + \
  593. encode_putfh_maxsz + \
  594. encode_savefh_maxsz + \
  595. encode_create_maxsz + \
  596. encode_getfh_maxsz + \
  597. encode_getattr_maxsz + \
  598. encode_restorefh_maxsz + \
  599. encode_getattr_maxsz)
  600. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  601. decode_sequence_maxsz + \
  602. decode_putfh_maxsz + \
  603. decode_savefh_maxsz + \
  604. decode_create_maxsz + \
  605. decode_getfh_maxsz + \
  606. decode_getattr_maxsz + \
  607. decode_restorefh_maxsz + \
  608. decode_getattr_maxsz)
  609. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  610. encode_sequence_maxsz + \
  611. encode_putfh_maxsz + \
  612. encode_getattr_maxsz)
  613. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  614. decode_sequence_maxsz + \
  615. decode_putfh_maxsz + \
  616. decode_getattr_maxsz)
  617. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  618. encode_sequence_maxsz + \
  619. encode_putfh_maxsz + \
  620. encode_statfs_maxsz)
  621. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  622. decode_sequence_maxsz + \
  623. decode_putfh_maxsz + \
  624. decode_statfs_maxsz)
  625. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  626. encode_sequence_maxsz + \
  627. encode_putfh_maxsz + \
  628. encode_getattr_maxsz)
  629. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  630. decode_sequence_maxsz + \
  631. decode_putfh_maxsz + \
  632. decode_getattr_maxsz)
  633. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  634. encode_sequence_maxsz + \
  635. encode_putfh_maxsz + \
  636. encode_delegreturn_maxsz + \
  637. encode_getattr_maxsz)
  638. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  639. decode_sequence_maxsz + \
  640. decode_delegreturn_maxsz + \
  641. decode_getattr_maxsz)
  642. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  643. encode_sequence_maxsz + \
  644. encode_putfh_maxsz + \
  645. encode_getacl_maxsz)
  646. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  647. decode_sequence_maxsz + \
  648. decode_putfh_maxsz + \
  649. decode_getacl_maxsz)
  650. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  651. encode_sequence_maxsz + \
  652. encode_putfh_maxsz + \
  653. encode_setacl_maxsz)
  654. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  655. decode_sequence_maxsz + \
  656. decode_putfh_maxsz + \
  657. decode_setacl_maxsz)
  658. #define NFS4_enc_fs_locations_sz \
  659. (compound_encode_hdr_maxsz + \
  660. encode_sequence_maxsz + \
  661. encode_putfh_maxsz + \
  662. encode_lookup_maxsz + \
  663. encode_fs_locations_maxsz)
  664. #define NFS4_dec_fs_locations_sz \
  665. (compound_decode_hdr_maxsz + \
  666. decode_sequence_maxsz + \
  667. decode_putfh_maxsz + \
  668. decode_lookup_maxsz + \
  669. decode_fs_locations_maxsz)
  670. #if defined(CONFIG_NFS_V4_1)
  671. #define NFS4_enc_exchange_id_sz \
  672. (compound_encode_hdr_maxsz + \
  673. encode_exchange_id_maxsz)
  674. #define NFS4_dec_exchange_id_sz \
  675. (compound_decode_hdr_maxsz + \
  676. decode_exchange_id_maxsz)
  677. #define NFS4_enc_create_session_sz \
  678. (compound_encode_hdr_maxsz + \
  679. encode_create_session_maxsz)
  680. #define NFS4_dec_create_session_sz \
  681. (compound_decode_hdr_maxsz + \
  682. decode_create_session_maxsz)
  683. #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
  684. encode_destroy_session_maxsz)
  685. #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
  686. decode_destroy_session_maxsz)
  687. #define NFS4_enc_sequence_sz \
  688. (compound_decode_hdr_maxsz + \
  689. encode_sequence_maxsz)
  690. #define NFS4_dec_sequence_sz \
  691. (compound_decode_hdr_maxsz + \
  692. decode_sequence_maxsz)
  693. #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
  694. encode_sequence_maxsz + \
  695. encode_putrootfh_maxsz + \
  696. encode_fsinfo_maxsz)
  697. #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
  698. decode_sequence_maxsz + \
  699. decode_putrootfh_maxsz + \
  700. decode_fsinfo_maxsz)
  701. #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
  702. encode_sequence_maxsz + \
  703. encode_reclaim_complete_maxsz)
  704. #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
  705. decode_sequence_maxsz + \
  706. decode_reclaim_complete_maxsz)
  707. #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
  708. encode_sequence_maxsz +\
  709. encode_getdeviceinfo_maxsz)
  710. #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
  711. decode_sequence_maxsz + \
  712. decode_getdeviceinfo_maxsz)
  713. #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
  714. encode_sequence_maxsz + \
  715. encode_putfh_maxsz + \
  716. encode_layoutget_maxsz)
  717. #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
  718. decode_sequence_maxsz + \
  719. decode_putfh_maxsz + \
  720. decode_layoutget_maxsz)
  721. const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  722. compound_encode_hdr_maxsz +
  723. encode_sequence_maxsz +
  724. encode_putfh_maxsz +
  725. encode_getattr_maxsz) *
  726. XDR_UNIT);
  727. const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  728. compound_decode_hdr_maxsz +
  729. decode_sequence_maxsz +
  730. decode_putfh_maxsz) *
  731. XDR_UNIT);
  732. #endif /* CONFIG_NFS_V4_1 */
  733. static const umode_t nfs_type2fmt[] = {
  734. [NF4BAD] = 0,
  735. [NF4REG] = S_IFREG,
  736. [NF4DIR] = S_IFDIR,
  737. [NF4BLK] = S_IFBLK,
  738. [NF4CHR] = S_IFCHR,
  739. [NF4LNK] = S_IFLNK,
  740. [NF4SOCK] = S_IFSOCK,
  741. [NF4FIFO] = S_IFIFO,
  742. [NF4ATTRDIR] = 0,
  743. [NF4NAMEDATTR] = 0,
  744. };
  745. struct compound_hdr {
  746. int32_t status;
  747. uint32_t nops;
  748. __be32 * nops_p;
  749. uint32_t taglen;
  750. char * tag;
  751. uint32_t replen; /* expected reply words */
  752. u32 minorversion;
  753. };
  754. static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
  755. {
  756. __be32 *p = xdr_reserve_space(xdr, nbytes);
  757. BUG_ON(!p);
  758. return p;
  759. }
  760. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  761. {
  762. __be32 *p;
  763. p = xdr_reserve_space(xdr, 4 + len);
  764. BUG_ON(p == NULL);
  765. xdr_encode_opaque(p, str, len);
  766. }
  767. static void encode_compound_hdr(struct xdr_stream *xdr,
  768. struct rpc_rqst *req,
  769. struct compound_hdr *hdr)
  770. {
  771. __be32 *p;
  772. struct rpc_auth *auth = req->rq_cred->cr_auth;
  773. /* initialize running count of expected bytes in reply.
  774. * NOTE: the replied tag SHOULD be the same is the one sent,
  775. * but this is not required as a MUST for the server to do so. */
  776. hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
  777. dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
  778. BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
  779. p = reserve_space(xdr, 4 + hdr->taglen + 8);
  780. p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
  781. *p++ = cpu_to_be32(hdr->minorversion);
  782. hdr->nops_p = p;
  783. *p = cpu_to_be32(hdr->nops);
  784. }
  785. static void encode_nops(struct compound_hdr *hdr)
  786. {
  787. BUG_ON(hdr->nops > NFS4_MAX_OPS);
  788. *hdr->nops_p = htonl(hdr->nops);
  789. }
  790. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  791. {
  792. __be32 *p;
  793. p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
  794. BUG_ON(p == NULL);
  795. xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
  796. }
  797. static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
  798. {
  799. char owner_name[IDMAP_NAMESZ];
  800. char owner_group[IDMAP_NAMESZ];
  801. int owner_namelen = 0;
  802. int owner_grouplen = 0;
  803. __be32 *p;
  804. __be32 *q;
  805. int len;
  806. uint32_t bmval0 = 0;
  807. uint32_t bmval1 = 0;
  808. /*
  809. * We reserve enough space to write the entire attribute buffer at once.
  810. * In the worst-case, this would be
  811. * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
  812. * = 36 bytes, plus any contribution from variable-length fields
  813. * such as owner/group.
  814. */
  815. len = 16;
  816. /* Sigh */
  817. if (iap->ia_valid & ATTR_SIZE)
  818. len += 8;
  819. if (iap->ia_valid & ATTR_MODE)
  820. len += 4;
  821. if (iap->ia_valid & ATTR_UID) {
  822. owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
  823. if (owner_namelen < 0) {
  824. dprintk("nfs: couldn't resolve uid %d to string\n",
  825. iap->ia_uid);
  826. /* XXX */
  827. strcpy(owner_name, "nobody");
  828. owner_namelen = sizeof("nobody") - 1;
  829. /* goto out; */
  830. }
  831. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  832. }
  833. if (iap->ia_valid & ATTR_GID) {
  834. owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
  835. if (owner_grouplen < 0) {
  836. dprintk("nfs: couldn't resolve gid %d to string\n",
  837. iap->ia_gid);
  838. strcpy(owner_group, "nobody");
  839. owner_grouplen = sizeof("nobody") - 1;
  840. /* goto out; */
  841. }
  842. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  843. }
  844. if (iap->ia_valid & ATTR_ATIME_SET)
  845. len += 16;
  846. else if (iap->ia_valid & ATTR_ATIME)
  847. len += 4;
  848. if (iap->ia_valid & ATTR_MTIME_SET)
  849. len += 16;
  850. else if (iap->ia_valid & ATTR_MTIME)
  851. len += 4;
  852. p = reserve_space(xdr, len);
  853. /*
  854. * We write the bitmap length now, but leave the bitmap and the attribute
  855. * buffer length to be backfilled at the end of this routine.
  856. */
  857. *p++ = cpu_to_be32(2);
  858. q = p;
  859. p += 3;
  860. if (iap->ia_valid & ATTR_SIZE) {
  861. bmval0 |= FATTR4_WORD0_SIZE;
  862. p = xdr_encode_hyper(p, iap->ia_size);
  863. }
  864. if (iap->ia_valid & ATTR_MODE) {
  865. bmval1 |= FATTR4_WORD1_MODE;
  866. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  867. }
  868. if (iap->ia_valid & ATTR_UID) {
  869. bmval1 |= FATTR4_WORD1_OWNER;
  870. p = xdr_encode_opaque(p, owner_name, owner_namelen);
  871. }
  872. if (iap->ia_valid & ATTR_GID) {
  873. bmval1 |= FATTR4_WORD1_OWNER_GROUP;
  874. p = xdr_encode_opaque(p, owner_group, owner_grouplen);
  875. }
  876. if (iap->ia_valid & ATTR_ATIME_SET) {
  877. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  878. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  879. *p++ = cpu_to_be32(0);
  880. *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
  881. *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
  882. }
  883. else if (iap->ia_valid & ATTR_ATIME) {
  884. bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
  885. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  886. }
  887. if (iap->ia_valid & ATTR_MTIME_SET) {
  888. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  889. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  890. *p++ = cpu_to_be32(0);
  891. *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
  892. *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
  893. }
  894. else if (iap->ia_valid & ATTR_MTIME) {
  895. bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
  896. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  897. }
  898. /*
  899. * Now we backfill the bitmap and the attribute buffer length.
  900. */
  901. if (len != ((char *)p - (char *)q) + 4) {
  902. printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
  903. len, ((char *)p - (char *)q) + 4);
  904. BUG();
  905. }
  906. len = (char *)p - (char *)q - 12;
  907. *q++ = htonl(bmval0);
  908. *q++ = htonl(bmval1);
  909. *q = htonl(len);
  910. /* out: */
  911. }
  912. static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
  913. {
  914. __be32 *p;
  915. p = reserve_space(xdr, 8);
  916. *p++ = cpu_to_be32(OP_ACCESS);
  917. *p = cpu_to_be32(access);
  918. hdr->nops++;
  919. hdr->replen += decode_access_maxsz;
  920. }
  921. static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  922. {
  923. __be32 *p;
  924. p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
  925. *p++ = cpu_to_be32(OP_CLOSE);
  926. *p++ = cpu_to_be32(arg->seqid->sequence->counter);
  927. xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
  928. hdr->nops++;
  929. hdr->replen += decode_close_maxsz;
  930. }
  931. static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
  932. {
  933. __be32 *p;
  934. p = reserve_space(xdr, 16);
  935. *p++ = cpu_to_be32(OP_COMMIT);
  936. p = xdr_encode_hyper(p, args->offset);
  937. *p = cpu_to_be32(args->count);
  938. hdr->nops++;
  939. hdr->replen += decode_commit_maxsz;
  940. }
  941. static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
  942. {
  943. __be32 *p;
  944. p = reserve_space(xdr, 8);
  945. *p++ = cpu_to_be32(OP_CREATE);
  946. *p = cpu_to_be32(create->ftype);
  947. switch (create->ftype) {
  948. case NF4LNK:
  949. p = reserve_space(xdr, 4);
  950. *p = cpu_to_be32(create->u.symlink.len);
  951. xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
  952. break;
  953. case NF4BLK: case NF4CHR:
  954. p = reserve_space(xdr, 8);
  955. *p++ = cpu_to_be32(create->u.device.specdata1);
  956. *p = cpu_to_be32(create->u.device.specdata2);
  957. break;
  958. default:
  959. break;
  960. }
  961. encode_string(xdr, create->name->len, create->name->name);
  962. hdr->nops++;
  963. hdr->replen += decode_create_maxsz;
  964. encode_attrs(xdr, create->attrs, create->server);
  965. }
  966. static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
  967. {
  968. __be32 *p;
  969. p = reserve_space(xdr, 12);
  970. *p++ = cpu_to_be32(OP_GETATTR);
  971. *p++ = cpu_to_be32(1);
  972. *p = cpu_to_be32(bitmap);
  973. hdr->nops++;
  974. hdr->replen += decode_getattr_maxsz;
  975. }
  976. static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
  977. {
  978. __be32 *p;
  979. p = reserve_space(xdr, 16);
  980. *p++ = cpu_to_be32(OP_GETATTR);
  981. *p++ = cpu_to_be32(2);
  982. *p++ = cpu_to_be32(bm0);
  983. *p = cpu_to_be32(bm1);
  984. hdr->nops++;
  985. hdr->replen += decode_getattr_maxsz;
  986. }
  987. static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  988. {
  989. encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
  990. bitmask[1] & nfs4_fattr_bitmap[1], hdr);
  991. }
  992. static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  993. {
  994. encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
  995. bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
  996. }
  997. static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  998. {
  999. encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
  1000. bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
  1001. }
  1002. static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1003. {
  1004. __be32 *p;
  1005. p = reserve_space(xdr, 4);
  1006. *p = cpu_to_be32(OP_GETFH);
  1007. hdr->nops++;
  1008. hdr->replen += decode_getfh_maxsz;
  1009. }
  1010. static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1011. {
  1012. __be32 *p;
  1013. p = reserve_space(xdr, 8 + name->len);
  1014. *p++ = cpu_to_be32(OP_LINK);
  1015. xdr_encode_opaque(p, name->name, name->len);
  1016. hdr->nops++;
  1017. hdr->replen += decode_link_maxsz;
  1018. }
  1019. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  1020. {
  1021. if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
  1022. return block ? NFS4_READW_LT : NFS4_READ_LT;
  1023. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  1024. }
  1025. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  1026. {
  1027. if (fl->fl_end == OFFSET_MAX)
  1028. return ~(uint64_t)0;
  1029. return fl->fl_end - fl->fl_start + 1;
  1030. }
  1031. static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
  1032. {
  1033. __be32 *p;
  1034. p = reserve_space(xdr, 32);
  1035. p = xdr_encode_hyper(p, lowner->clientid);
  1036. *p++ = cpu_to_be32(20);
  1037. p = xdr_encode_opaque_fixed(p, "lock id:", 8);
  1038. *p++ = cpu_to_be32(lowner->s_dev);
  1039. xdr_encode_hyper(p, lowner->id);
  1040. }
  1041. /*
  1042. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  1043. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  1044. */
  1045. static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
  1046. {
  1047. __be32 *p;
  1048. p = reserve_space(xdr, 32);
  1049. *p++ = cpu_to_be32(OP_LOCK);
  1050. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
  1051. *p++ = cpu_to_be32(args->reclaim);
  1052. p = xdr_encode_hyper(p, args->fl->fl_start);
  1053. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1054. *p = cpu_to_be32(args->new_lock_owner);
  1055. if (args->new_lock_owner){
  1056. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
  1057. *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
  1058. p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
  1059. *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
  1060. encode_lockowner(xdr, &args->lock_owner);
  1061. }
  1062. else {
  1063. p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
  1064. p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
  1065. *p = cpu_to_be32(args->lock_seqid->sequence->counter);
  1066. }
  1067. hdr->nops++;
  1068. hdr->replen += decode_lock_maxsz;
  1069. }
  1070. static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
  1071. {
  1072. __be32 *p;
  1073. p = reserve_space(xdr, 24);
  1074. *p++ = cpu_to_be32(OP_LOCKT);
  1075. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1076. p = xdr_encode_hyper(p, args->fl->fl_start);
  1077. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1078. encode_lockowner(xdr, &args->lock_owner);
  1079. hdr->nops++;
  1080. hdr->replen += decode_lockt_maxsz;
  1081. }
  1082. static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
  1083. {
  1084. __be32 *p;
  1085. p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
  1086. *p++ = cpu_to_be32(OP_LOCKU);
  1087. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1088. *p++ = cpu_to_be32(args->seqid->sequence->counter);
  1089. p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
  1090. p = xdr_encode_hyper(p, args->fl->fl_start);
  1091. xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1092. hdr->nops++;
  1093. hdr->replen += decode_locku_maxsz;
  1094. }
  1095. static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
  1096. {
  1097. __be32 *p;
  1098. p = reserve_space(xdr, 4);
  1099. *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
  1100. encode_lockowner(xdr, lowner);
  1101. hdr->nops++;
  1102. hdr->replen += decode_release_lockowner_maxsz;
  1103. }
  1104. static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1105. {
  1106. int len = name->len;
  1107. __be32 *p;
  1108. p = reserve_space(xdr, 8 + len);
  1109. *p++ = cpu_to_be32(OP_LOOKUP);
  1110. xdr_encode_opaque(p, name->name, len);
  1111. hdr->nops++;
  1112. hdr->replen += decode_lookup_maxsz;
  1113. }
  1114. static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
  1115. {
  1116. __be32 *p;
  1117. p = reserve_space(xdr, 8);
  1118. switch (fmode & (FMODE_READ|FMODE_WRITE)) {
  1119. case FMODE_READ:
  1120. *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
  1121. break;
  1122. case FMODE_WRITE:
  1123. *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
  1124. break;
  1125. case FMODE_READ|FMODE_WRITE:
  1126. *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
  1127. break;
  1128. default:
  1129. *p++ = cpu_to_be32(0);
  1130. }
  1131. *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
  1132. }
  1133. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1134. {
  1135. __be32 *p;
  1136. /*
  1137. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  1138. * owner 4 = 32
  1139. */
  1140. p = reserve_space(xdr, 8);
  1141. *p++ = cpu_to_be32(OP_OPEN);
  1142. *p = cpu_to_be32(arg->seqid->sequence->counter);
  1143. encode_share_access(xdr, arg->fmode);
  1144. p = reserve_space(xdr, 32);
  1145. p = xdr_encode_hyper(p, arg->clientid);
  1146. *p++ = cpu_to_be32(20);
  1147. p = xdr_encode_opaque_fixed(p, "open id:", 8);
  1148. *p++ = cpu_to_be32(arg->server->s_dev);
  1149. xdr_encode_hyper(p, arg->id);
  1150. }
  1151. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1152. {
  1153. __be32 *p;
  1154. struct nfs_client *clp;
  1155. p = reserve_space(xdr, 4);
  1156. switch(arg->open_flags & O_EXCL) {
  1157. case 0:
  1158. *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
  1159. encode_attrs(xdr, arg->u.attrs, arg->server);
  1160. break;
  1161. default:
  1162. clp = arg->server->nfs_client;
  1163. if (clp->cl_mvops->minor_version > 0) {
  1164. if (nfs4_has_persistent_session(clp)) {
  1165. *p = cpu_to_be32(NFS4_CREATE_GUARDED);
  1166. encode_attrs(xdr, arg->u.attrs, arg->server);
  1167. } else {
  1168. struct iattr dummy;
  1169. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
  1170. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1171. dummy.ia_valid = 0;
  1172. encode_attrs(xdr, &dummy, arg->server);
  1173. }
  1174. } else {
  1175. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
  1176. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1177. }
  1178. }
  1179. }
  1180. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1181. {
  1182. __be32 *p;
  1183. p = reserve_space(xdr, 4);
  1184. switch (arg->open_flags & O_CREAT) {
  1185. case 0:
  1186. *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
  1187. break;
  1188. default:
  1189. BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
  1190. *p = cpu_to_be32(NFS4_OPEN_CREATE);
  1191. encode_createmode(xdr, arg);
  1192. }
  1193. }
  1194. static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
  1195. {
  1196. __be32 *p;
  1197. p = reserve_space(xdr, 4);
  1198. switch (delegation_type) {
  1199. case 0:
  1200. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
  1201. break;
  1202. case FMODE_READ:
  1203. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
  1204. break;
  1205. case FMODE_WRITE|FMODE_READ:
  1206. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
  1207. break;
  1208. default:
  1209. BUG();
  1210. }
  1211. }
  1212. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  1213. {
  1214. __be32 *p;
  1215. p = reserve_space(xdr, 4);
  1216. *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
  1217. encode_string(xdr, name->len, name->name);
  1218. }
  1219. static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
  1220. {
  1221. __be32 *p;
  1222. p = reserve_space(xdr, 4);
  1223. *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
  1224. encode_delegation_type(xdr, type);
  1225. }
  1226. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  1227. {
  1228. __be32 *p;
  1229. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
  1230. *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  1231. xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
  1232. encode_string(xdr, name->len, name->name);
  1233. }
  1234. static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
  1235. {
  1236. encode_openhdr(xdr, arg);
  1237. encode_opentype(xdr, arg);
  1238. switch (arg->claim) {
  1239. case NFS4_OPEN_CLAIM_NULL:
  1240. encode_claim_null(xdr, arg->name);
  1241. break;
  1242. case NFS4_OPEN_CLAIM_PREVIOUS:
  1243. encode_claim_previous(xdr, arg->u.delegation_type);
  1244. break;
  1245. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1246. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  1247. break;
  1248. default:
  1249. BUG();
  1250. }
  1251. hdr->nops++;
  1252. hdr->replen += decode_open_maxsz;
  1253. }
  1254. static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
  1255. {
  1256. __be32 *p;
  1257. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
  1258. *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
  1259. p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
  1260. *p = cpu_to_be32(arg->seqid->sequence->counter);
  1261. hdr->nops++;
  1262. hdr->replen += decode_open_confirm_maxsz;
  1263. }
  1264. static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1265. {
  1266. __be32 *p;
  1267. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
  1268. *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
  1269. p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
  1270. *p = cpu_to_be32(arg->seqid->sequence->counter);
  1271. encode_share_access(xdr, arg->fmode);
  1272. hdr->nops++;
  1273. hdr->replen += decode_open_downgrade_maxsz;
  1274. }
  1275. static void
  1276. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
  1277. {
  1278. int len = fh->size;
  1279. __be32 *p;
  1280. p = reserve_space(xdr, 8 + len);
  1281. *p++ = cpu_to_be32(OP_PUTFH);
  1282. xdr_encode_opaque(p, fh->data, len);
  1283. hdr->nops++;
  1284. hdr->replen += decode_putfh_maxsz;
  1285. }
  1286. static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1287. {
  1288. __be32 *p;
  1289. p = reserve_space(xdr, 4);
  1290. *p = cpu_to_be32(OP_PUTROOTFH);
  1291. hdr->nops++;
  1292. hdr->replen += decode_putrootfh_maxsz;
  1293. }
  1294. static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
  1295. {
  1296. nfs4_stateid stateid;
  1297. __be32 *p;
  1298. p = reserve_space(xdr, NFS4_STATEID_SIZE);
  1299. if (ctx->state != NULL) {
  1300. nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
  1301. xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
  1302. } else
  1303. xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
  1304. }
  1305. static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
  1306. {
  1307. __be32 *p;
  1308. p = reserve_space(xdr, 4);
  1309. *p = cpu_to_be32(OP_READ);
  1310. encode_stateid(xdr, args->context, args->lock_context);
  1311. p = reserve_space(xdr, 12);
  1312. p = xdr_encode_hyper(p, args->offset);
  1313. *p = cpu_to_be32(args->count);
  1314. hdr->nops++;
  1315. hdr->replen += decode_read_maxsz;
  1316. }
  1317. static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
  1318. {
  1319. uint32_t attrs[2] = {0, 0};
  1320. uint32_t dircount = readdir->count >> 1;
  1321. __be32 *p;
  1322. if (readdir->plus) {
  1323. attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
  1324. FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
  1325. attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
  1326. FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
  1327. FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
  1328. FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
  1329. dircount >>= 1;
  1330. }
  1331. attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
  1332. attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
  1333. /* Switch to mounted_on_fileid if the server supports it */
  1334. if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
  1335. attrs[0] &= ~FATTR4_WORD0_FILEID;
  1336. else
  1337. attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  1338. p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
  1339. *p++ = cpu_to_be32(OP_READDIR);
  1340. p = xdr_encode_hyper(p, readdir->cookie);
  1341. p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
  1342. *p++ = cpu_to_be32(dircount);
  1343. *p++ = cpu_to_be32(readdir->count);
  1344. *p++ = cpu_to_be32(2);
  1345. *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
  1346. *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
  1347. hdr->nops++;
  1348. hdr->replen += decode_readdir_maxsz;
  1349. dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
  1350. __func__,
  1351. (unsigned long long)readdir->cookie,
  1352. ((u32 *)readdir->verifier.data)[0],
  1353. ((u32 *)readdir->verifier.data)[1],
  1354. attrs[0] & readdir->bitmask[0],
  1355. attrs[1] & readdir->bitmask[1]);
  1356. }
  1357. static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
  1358. {
  1359. __be32 *p;
  1360. p = reserve_space(xdr, 4);
  1361. *p = cpu_to_be32(OP_READLINK);
  1362. hdr->nops++;
  1363. hdr->replen += decode_readlink_maxsz;
  1364. }
  1365. static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1366. {
  1367. __be32 *p;
  1368. p = reserve_space(xdr, 8 + name->len);
  1369. *p++ = cpu_to_be32(OP_REMOVE);
  1370. xdr_encode_opaque(p, name->name, name->len);
  1371. hdr->nops++;
  1372. hdr->replen += decode_remove_maxsz;
  1373. }
  1374. static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
  1375. {
  1376. __be32 *p;
  1377. p = reserve_space(xdr, 4);
  1378. *p = cpu_to_be32(OP_RENAME);
  1379. encode_string(xdr, oldname->len, oldname->name);
  1380. encode_string(xdr, newname->len, newname->name);
  1381. hdr->nops++;
  1382. hdr->replen += decode_rename_maxsz;
  1383. }
  1384. static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
  1385. {
  1386. __be32 *p;
  1387. p = reserve_space(xdr, 12);
  1388. *p++ = cpu_to_be32(OP_RENEW);
  1389. xdr_encode_hyper(p, client_stateid->cl_clientid);
  1390. hdr->nops++;
  1391. hdr->replen += decode_renew_maxsz;
  1392. }
  1393. static void
  1394. encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1395. {
  1396. __be32 *p;
  1397. p = reserve_space(xdr, 4);
  1398. *p = cpu_to_be32(OP_RESTOREFH);
  1399. hdr->nops++;
  1400. hdr->replen += decode_restorefh_maxsz;
  1401. }
  1402. static void
  1403. encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
  1404. {
  1405. __be32 *p;
  1406. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
  1407. *p++ = cpu_to_be32(OP_SETATTR);
  1408. xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
  1409. p = reserve_space(xdr, 2*4);
  1410. *p++ = cpu_to_be32(1);
  1411. *p = cpu_to_be32(FATTR4_WORD0_ACL);
  1412. BUG_ON(arg->acl_len % 4);
  1413. p = reserve_space(xdr, 4);
  1414. *p = cpu_to_be32(arg->acl_len);
  1415. xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
  1416. hdr->nops++;
  1417. hdr->replen += decode_setacl_maxsz;
  1418. }
  1419. static void
  1420. encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1421. {
  1422. __be32 *p;
  1423. p = reserve_space(xdr, 4);
  1424. *p = cpu_to_be32(OP_SAVEFH);
  1425. hdr->nops++;
  1426. hdr->replen += decode_savefh_maxsz;
  1427. }
  1428. static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
  1429. {
  1430. __be32 *p;
  1431. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
  1432. *p++ = cpu_to_be32(OP_SETATTR);
  1433. xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
  1434. hdr->nops++;
  1435. hdr->replen += decode_setattr_maxsz;
  1436. encode_attrs(xdr, arg->iap, server);
  1437. }
  1438. static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
  1439. {
  1440. __be32 *p;
  1441. p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
  1442. *p++ = cpu_to_be32(OP_SETCLIENTID);
  1443. xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
  1444. encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
  1445. p = reserve_space(xdr, 4);
  1446. *p = cpu_to_be32(setclientid->sc_prog);
  1447. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1448. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1449. p = reserve_space(xdr, 4);
  1450. *p = cpu_to_be32(setclientid->sc_cb_ident);
  1451. hdr->nops++;
  1452. hdr->replen += decode_setclientid_maxsz;
  1453. }
  1454. static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
  1455. {
  1456. __be32 *p;
  1457. p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
  1458. *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
  1459. p = xdr_encode_hyper(p, arg->clientid);
  1460. xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
  1461. hdr->nops++;
  1462. hdr->replen += decode_setclientid_confirm_maxsz;
  1463. }
  1464. static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
  1465. {
  1466. __be32 *p;
  1467. p = reserve_space(xdr, 4);
  1468. *p = cpu_to_be32(OP_WRITE);
  1469. encode_stateid(xdr, args->context, args->lock_context);
  1470. p = reserve_space(xdr, 16);
  1471. p = xdr_encode_hyper(p, args->offset);
  1472. *p++ = cpu_to_be32(args->stable);
  1473. *p = cpu_to_be32(args->count);
  1474. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1475. hdr->nops++;
  1476. hdr->replen += decode_write_maxsz;
  1477. }
  1478. static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
  1479. {
  1480. __be32 *p;
  1481. p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
  1482. *p++ = cpu_to_be32(OP_DELEGRETURN);
  1483. xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
  1484. hdr->nops++;
  1485. hdr->replen += decode_delegreturn_maxsz;
  1486. }
  1487. #if defined(CONFIG_NFS_V4_1)
  1488. /* NFSv4.1 operations */
  1489. static void encode_exchange_id(struct xdr_stream *xdr,
  1490. struct nfs41_exchange_id_args *args,
  1491. struct compound_hdr *hdr)
  1492. {
  1493. __be32 *p;
  1494. p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
  1495. *p++ = cpu_to_be32(OP_EXCHANGE_ID);
  1496. xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
  1497. encode_string(xdr, args->id_len, args->id);
  1498. p = reserve_space(xdr, 12);
  1499. *p++ = cpu_to_be32(args->flags);
  1500. *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
  1501. *p = cpu_to_be32(0); /* zero length implementation id array */
  1502. hdr->nops++;
  1503. hdr->replen += decode_exchange_id_maxsz;
  1504. }
  1505. static void encode_create_session(struct xdr_stream *xdr,
  1506. struct nfs41_create_session_args *args,
  1507. struct compound_hdr *hdr)
  1508. {
  1509. __be32 *p;
  1510. char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
  1511. uint32_t len;
  1512. struct nfs_client *clp = args->client;
  1513. u32 max_resp_sz_cached;
  1514. /*
  1515. * Assumes OPEN is the biggest non-idempotent compound.
  1516. * 2 is the verifier.
  1517. */
  1518. max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
  1519. RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
  1520. len = scnprintf(machine_name, sizeof(machine_name), "%s",
  1521. clp->cl_ipaddr);
  1522. p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
  1523. *p++ = cpu_to_be32(OP_CREATE_SESSION);
  1524. p = xdr_encode_hyper(p, clp->cl_ex_clid);
  1525. *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
  1526. *p++ = cpu_to_be32(args->flags); /*flags */
  1527. /* Fore Channel */
  1528. *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
  1529. *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
  1530. *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
  1531. *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
  1532. *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
  1533. *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
  1534. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1535. /* Back Channel */
  1536. *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
  1537. *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
  1538. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
  1539. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
  1540. *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
  1541. *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
  1542. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1543. *p++ = cpu_to_be32(args->cb_program); /* cb_program */
  1544. *p++ = cpu_to_be32(1);
  1545. *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
  1546. /* authsys_parms rfc1831 */
  1547. *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
  1548. p = xdr_encode_opaque(p, machine_name, len);
  1549. *p++ = cpu_to_be32(0); /* UID */
  1550. *p++ = cpu_to_be32(0); /* GID */
  1551. *p = cpu_to_be32(0); /* No more gids */
  1552. hdr->nops++;
  1553. hdr->replen += decode_create_session_maxsz;
  1554. }
  1555. static void encode_destroy_session(struct xdr_stream *xdr,
  1556. struct nfs4_session *session,
  1557. struct compound_hdr *hdr)
  1558. {
  1559. __be32 *p;
  1560. p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
  1561. *p++ = cpu_to_be32(OP_DESTROY_SESSION);
  1562. xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1563. hdr->nops++;
  1564. hdr->replen += decode_destroy_session_maxsz;
  1565. }
  1566. static void encode_reclaim_complete(struct xdr_stream *xdr,
  1567. struct nfs41_reclaim_complete_args *args,
  1568. struct compound_hdr *hdr)
  1569. {
  1570. __be32 *p;
  1571. p = reserve_space(xdr, 8);
  1572. *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
  1573. *p++ = cpu_to_be32(args->one_fs);
  1574. hdr->nops++;
  1575. hdr->replen += decode_reclaim_complete_maxsz;
  1576. }
  1577. #endif /* CONFIG_NFS_V4_1 */
  1578. static void encode_sequence(struct xdr_stream *xdr,
  1579. const struct nfs4_sequence_args *args,
  1580. struct compound_hdr *hdr)
  1581. {
  1582. #if defined(CONFIG_NFS_V4_1)
  1583. struct nfs4_session *session = args->sa_session;
  1584. struct nfs4_slot_table *tp;
  1585. struct nfs4_slot *slot;
  1586. __be32 *p;
  1587. if (!session)
  1588. return;
  1589. tp = &session->fc_slot_table;
  1590. WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
  1591. slot = tp->slots + args->sa_slotid;
  1592. p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
  1593. *p++ = cpu_to_be32(OP_SEQUENCE);
  1594. /*
  1595. * Sessionid + seqid + slotid + max slotid + cache_this
  1596. */
  1597. dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
  1598. "max_slotid=%d cache_this=%d\n",
  1599. __func__,
  1600. ((u32 *)session->sess_id.data)[0],
  1601. ((u32 *)session->sess_id.data)[1],
  1602. ((u32 *)session->sess_id.data)[2],
  1603. ((u32 *)session->sess_id.data)[3],
  1604. slot->seq_nr, args->sa_slotid,
  1605. tp->highest_used_slotid, args->sa_cache_this);
  1606. p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1607. *p++ = cpu_to_be32(slot->seq_nr);
  1608. *p++ = cpu_to_be32(args->sa_slotid);
  1609. *p++ = cpu_to_be32(tp->highest_used_slotid);
  1610. *p = cpu_to_be32(args->sa_cache_this);
  1611. hdr->nops++;
  1612. hdr->replen += decode_sequence_maxsz;
  1613. #endif /* CONFIG_NFS_V4_1 */
  1614. }
  1615. #ifdef CONFIG_NFS_V4_1
  1616. static void
  1617. encode_getdeviceinfo(struct xdr_stream *xdr,
  1618. const struct nfs4_getdeviceinfo_args *args,
  1619. struct compound_hdr *hdr)
  1620. {
  1621. __be32 *p;
  1622. p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
  1623. *p++ = cpu_to_be32(OP_GETDEVICEINFO);
  1624. p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
  1625. NFS4_DEVICEID4_SIZE);
  1626. *p++ = cpu_to_be32(args->pdev->layout_type);
  1627. *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
  1628. *p++ = cpu_to_be32(0); /* bitmap length 0 */
  1629. hdr->nops++;
  1630. hdr->replen += decode_getdeviceinfo_maxsz;
  1631. }
  1632. static void
  1633. encode_layoutget(struct xdr_stream *xdr,
  1634. const struct nfs4_layoutget_args *args,
  1635. struct compound_hdr *hdr)
  1636. {
  1637. __be32 *p;
  1638. p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
  1639. *p++ = cpu_to_be32(OP_LAYOUTGET);
  1640. *p++ = cpu_to_be32(0); /* Signal layout available */
  1641. *p++ = cpu_to_be32(args->type);
  1642. *p++ = cpu_to_be32(args->range.iomode);
  1643. p = xdr_encode_hyper(p, args->range.offset);
  1644. p = xdr_encode_hyper(p, args->range.length);
  1645. p = xdr_encode_hyper(p, args->minlength);
  1646. p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
  1647. *p = cpu_to_be32(args->maxcount);
  1648. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1649. __func__,
  1650. args->type,
  1651. args->range.iomode,
  1652. (unsigned long)args->range.offset,
  1653. (unsigned long)args->range.length,
  1654. args->maxcount);
  1655. hdr->nops++;
  1656. hdr->replen += decode_layoutget_maxsz;
  1657. }
  1658. #endif /* CONFIG_NFS_V4_1 */
  1659. /*
  1660. * END OF "GENERIC" ENCODE ROUTINES.
  1661. */
  1662. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1663. {
  1664. #if defined(CONFIG_NFS_V4_1)
  1665. if (args->sa_session)
  1666. return args->sa_session->clp->cl_mvops->minor_version;
  1667. #endif /* CONFIG_NFS_V4_1 */
  1668. return 0;
  1669. }
  1670. /*
  1671. * Encode an ACCESS request
  1672. */
  1673. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1674. const struct nfs4_accessargs *args)
  1675. {
  1676. struct compound_hdr hdr = {
  1677. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1678. };
  1679. encode_compound_hdr(xdr, req, &hdr);
  1680. encode_sequence(xdr, &args->seq_args, &hdr);
  1681. encode_putfh(xdr, args->fh, &hdr);
  1682. encode_access(xdr, args->access, &hdr);
  1683. encode_getfattr(xdr, args->bitmask, &hdr);
  1684. encode_nops(&hdr);
  1685. }
  1686. /*
  1687. * Encode LOOKUP request
  1688. */
  1689. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1690. const struct nfs4_lookup_arg *args)
  1691. {
  1692. struct compound_hdr hdr = {
  1693. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1694. };
  1695. encode_compound_hdr(xdr, req, &hdr);
  1696. encode_sequence(xdr, &args->seq_args, &hdr);
  1697. encode_putfh(xdr, args->dir_fh, &hdr);
  1698. encode_lookup(xdr, args->name, &hdr);
  1699. encode_getfh(xdr, &hdr);
  1700. encode_getfattr(xdr, args->bitmask, &hdr);
  1701. encode_nops(&hdr);
  1702. }
  1703. /*
  1704. * Encode LOOKUP_ROOT request
  1705. */
  1706. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  1707. struct xdr_stream *xdr,
  1708. const struct nfs4_lookup_root_arg *args)
  1709. {
  1710. struct compound_hdr hdr = {
  1711. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1712. };
  1713. encode_compound_hdr(xdr, req, &hdr);
  1714. encode_sequence(xdr, &args->seq_args, &hdr);
  1715. encode_putrootfh(xdr, &hdr);
  1716. encode_getfh(xdr, &hdr);
  1717. encode_getfattr(xdr, args->bitmask, &hdr);
  1718. encode_nops(&hdr);
  1719. }
  1720. /*
  1721. * Encode REMOVE request
  1722. */
  1723. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  1724. const struct nfs_removeargs *args)
  1725. {
  1726. struct compound_hdr hdr = {
  1727. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1728. };
  1729. encode_compound_hdr(xdr, req, &hdr);
  1730. encode_sequence(xdr, &args->seq_args, &hdr);
  1731. encode_putfh(xdr, args->fh, &hdr);
  1732. encode_remove(xdr, &args->name, &hdr);
  1733. encode_getfattr(xdr, args->bitmask, &hdr);
  1734. encode_nops(&hdr);
  1735. }
  1736. /*
  1737. * Encode RENAME request
  1738. */
  1739. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  1740. const struct nfs_renameargs *args)
  1741. {
  1742. struct compound_hdr hdr = {
  1743. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1744. };
  1745. encode_compound_hdr(xdr, req, &hdr);
  1746. encode_sequence(xdr, &args->seq_args, &hdr);
  1747. encode_putfh(xdr, args->old_dir, &hdr);
  1748. encode_savefh(xdr, &hdr);
  1749. encode_putfh(xdr, args->new_dir, &hdr);
  1750. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  1751. encode_getfattr(xdr, args->bitmask, &hdr);
  1752. encode_restorefh(xdr, &hdr);
  1753. encode_getfattr(xdr, args->bitmask, &hdr);
  1754. encode_nops(&hdr);
  1755. }
  1756. /*
  1757. * Encode LINK request
  1758. */
  1759. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  1760. const struct nfs4_link_arg *args)
  1761. {
  1762. struct compound_hdr hdr = {
  1763. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1764. };
  1765. encode_compound_hdr(xdr, req, &hdr);
  1766. encode_sequence(xdr, &args->seq_args, &hdr);
  1767. encode_putfh(xdr, args->fh, &hdr);
  1768. encode_savefh(xdr, &hdr);
  1769. encode_putfh(xdr, args->dir_fh, &hdr);
  1770. encode_link(xdr, args->name, &hdr);
  1771. encode_getfattr(xdr, args->bitmask, &hdr);
  1772. encode_restorefh(xdr, &hdr);
  1773. encode_getfattr(xdr, args->bitmask, &hdr);
  1774. encode_nops(&hdr);
  1775. }
  1776. /*
  1777. * Encode CREATE request
  1778. */
  1779. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  1780. const struct nfs4_create_arg *args)
  1781. {
  1782. struct compound_hdr hdr = {
  1783. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1784. };
  1785. encode_compound_hdr(xdr, req, &hdr);
  1786. encode_sequence(xdr, &args->seq_args, &hdr);
  1787. encode_putfh(xdr, args->dir_fh, &hdr);
  1788. encode_savefh(xdr, &hdr);
  1789. encode_create(xdr, args, &hdr);
  1790. encode_getfh(xdr, &hdr);
  1791. encode_getfattr(xdr, args->bitmask, &hdr);
  1792. encode_restorefh(xdr, &hdr);
  1793. encode_getfattr(xdr, args->bitmask, &hdr);
  1794. encode_nops(&hdr);
  1795. }
  1796. /*
  1797. * Encode SYMLINK request
  1798. */
  1799. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  1800. const struct nfs4_create_arg *args)
  1801. {
  1802. nfs4_xdr_enc_create(req, xdr, args);
  1803. }
  1804. /*
  1805. * Encode GETATTR request
  1806. */
  1807. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  1808. const struct nfs4_getattr_arg *args)
  1809. {
  1810. struct compound_hdr hdr = {
  1811. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1812. };
  1813. encode_compound_hdr(xdr, req, &hdr);
  1814. encode_sequence(xdr, &args->seq_args, &hdr);
  1815. encode_putfh(xdr, args->fh, &hdr);
  1816. encode_getfattr(xdr, args->bitmask, &hdr);
  1817. encode_nops(&hdr);
  1818. }
  1819. /*
  1820. * Encode a CLOSE request
  1821. */
  1822. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  1823. struct nfs_closeargs *args)
  1824. {
  1825. struct compound_hdr hdr = {
  1826. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1827. };
  1828. encode_compound_hdr(xdr, req, &hdr);
  1829. encode_sequence(xdr, &args->seq_args, &hdr);
  1830. encode_putfh(xdr, args->fh, &hdr);
  1831. encode_close(xdr, args, &hdr);
  1832. encode_getfattr(xdr, args->bitmask, &hdr);
  1833. encode_nops(&hdr);
  1834. }
  1835. /*
  1836. * Encode an OPEN request
  1837. */
  1838. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  1839. struct nfs_openargs *args)
  1840. {
  1841. struct compound_hdr hdr = {
  1842. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1843. };
  1844. encode_compound_hdr(xdr, req, &hdr);
  1845. encode_sequence(xdr, &args->seq_args, &hdr);
  1846. encode_putfh(xdr, args->fh, &hdr);
  1847. encode_savefh(xdr, &hdr);
  1848. encode_open(xdr, args, &hdr);
  1849. encode_getfh(xdr, &hdr);
  1850. encode_getfattr(xdr, args->bitmask, &hdr);
  1851. encode_restorefh(xdr, &hdr);
  1852. encode_getfattr(xdr, args->bitmask, &hdr);
  1853. encode_nops(&hdr);
  1854. }
  1855. /*
  1856. * Encode an OPEN_CONFIRM request
  1857. */
  1858. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  1859. struct xdr_stream *xdr,
  1860. struct nfs_open_confirmargs *args)
  1861. {
  1862. struct compound_hdr hdr = {
  1863. .nops = 0,
  1864. };
  1865. encode_compound_hdr(xdr, req, &hdr);
  1866. encode_putfh(xdr, args->fh, &hdr);
  1867. encode_open_confirm(xdr, args, &hdr);
  1868. encode_nops(&hdr);
  1869. }
  1870. /*
  1871. * Encode an OPEN request with no attributes.
  1872. */
  1873. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  1874. struct xdr_stream *xdr,
  1875. struct nfs_openargs *args)
  1876. {
  1877. struct compound_hdr hdr = {
  1878. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1879. };
  1880. encode_compound_hdr(xdr, req, &hdr);
  1881. encode_sequence(xdr, &args->seq_args, &hdr);
  1882. encode_putfh(xdr, args->fh, &hdr);
  1883. encode_open(xdr, args, &hdr);
  1884. encode_getfattr(xdr, args->bitmask, &hdr);
  1885. encode_nops(&hdr);
  1886. }
  1887. /*
  1888. * Encode an OPEN_DOWNGRADE request
  1889. */
  1890. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  1891. struct xdr_stream *xdr,
  1892. struct nfs_closeargs *args)
  1893. {
  1894. struct compound_hdr hdr = {
  1895. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1896. };
  1897. encode_compound_hdr(xdr, req, &hdr);
  1898. encode_sequence(xdr, &args->seq_args, &hdr);
  1899. encode_putfh(xdr, args->fh, &hdr);
  1900. encode_open_downgrade(xdr, args, &hdr);
  1901. encode_getfattr(xdr, args->bitmask, &hdr);
  1902. encode_nops(&hdr);
  1903. }
  1904. /*
  1905. * Encode a LOCK request
  1906. */
  1907. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  1908. struct nfs_lock_args *args)
  1909. {
  1910. struct compound_hdr hdr = {
  1911. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1912. };
  1913. encode_compound_hdr(xdr, req, &hdr);
  1914. encode_sequence(xdr, &args->seq_args, &hdr);
  1915. encode_putfh(xdr, args->fh, &hdr);
  1916. encode_lock(xdr, args, &hdr);
  1917. encode_nops(&hdr);
  1918. }
  1919. /*
  1920. * Encode a LOCKT request
  1921. */
  1922. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  1923. struct nfs_lockt_args *args)
  1924. {
  1925. struct compound_hdr hdr = {
  1926. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1927. };
  1928. encode_compound_hdr(xdr, req, &hdr);
  1929. encode_sequence(xdr, &args->seq_args, &hdr);
  1930. encode_putfh(xdr, args->fh, &hdr);
  1931. encode_lockt(xdr, args, &hdr);
  1932. encode_nops(&hdr);
  1933. }
  1934. /*
  1935. * Encode a LOCKU request
  1936. */
  1937. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  1938. struct nfs_locku_args *args)
  1939. {
  1940. struct compound_hdr hdr = {
  1941. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1942. };
  1943. encode_compound_hdr(xdr, req, &hdr);
  1944. encode_sequence(xdr, &args->seq_args, &hdr);
  1945. encode_putfh(xdr, args->fh, &hdr);
  1946. encode_locku(xdr, args, &hdr);
  1947. encode_nops(&hdr);
  1948. }
  1949. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  1950. struct xdr_stream *xdr,
  1951. struct nfs_release_lockowner_args *args)
  1952. {
  1953. struct compound_hdr hdr = {
  1954. .minorversion = 0,
  1955. };
  1956. encode_compound_hdr(xdr, req, &hdr);
  1957. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  1958. encode_nops(&hdr);
  1959. }
  1960. /*
  1961. * Encode a READLINK request
  1962. */
  1963. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  1964. const struct nfs4_readlink *args)
  1965. {
  1966. struct compound_hdr hdr = {
  1967. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1968. };
  1969. encode_compound_hdr(xdr, req, &hdr);
  1970. encode_sequence(xdr, &args->seq_args, &hdr);
  1971. encode_putfh(xdr, args->fh, &hdr);
  1972. encode_readlink(xdr, args, req, &hdr);
  1973. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  1974. args->pgbase, args->pglen);
  1975. encode_nops(&hdr);
  1976. }
  1977. /*
  1978. * Encode a READDIR request
  1979. */
  1980. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  1981. const struct nfs4_readdir_arg *args)
  1982. {
  1983. struct compound_hdr hdr = {
  1984. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1985. };
  1986. encode_compound_hdr(xdr, req, &hdr);
  1987. encode_sequence(xdr, &args->seq_args, &hdr);
  1988. encode_putfh(xdr, args->fh, &hdr);
  1989. encode_readdir(xdr, args, req, &hdr);
  1990. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  1991. args->pgbase, args->count);
  1992. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  1993. __func__, hdr.replen << 2, args->pages,
  1994. args->pgbase, args->count);
  1995. encode_nops(&hdr);
  1996. }
  1997. /*
  1998. * Encode a READ request
  1999. */
  2000. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2001. struct nfs_readargs *args)
  2002. {
  2003. struct compound_hdr hdr = {
  2004. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2005. };
  2006. encode_compound_hdr(xdr, req, &hdr);
  2007. encode_sequence(xdr, &args->seq_args, &hdr);
  2008. encode_putfh(xdr, args->fh, &hdr);
  2009. encode_read(xdr, args, &hdr);
  2010. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2011. args->pages, args->pgbase, args->count);
  2012. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2013. encode_nops(&hdr);
  2014. }
  2015. /*
  2016. * Encode an SETATTR request
  2017. */
  2018. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2019. struct nfs_setattrargs *args)
  2020. {
  2021. struct compound_hdr hdr = {
  2022. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2023. };
  2024. encode_compound_hdr(xdr, req, &hdr);
  2025. encode_sequence(xdr, &args->seq_args, &hdr);
  2026. encode_putfh(xdr, args->fh, &hdr);
  2027. encode_setattr(xdr, args, args->server, &hdr);
  2028. encode_getfattr(xdr, args->bitmask, &hdr);
  2029. encode_nops(&hdr);
  2030. }
  2031. /*
  2032. * Encode a GETACL request
  2033. */
  2034. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2035. struct nfs_getaclargs *args)
  2036. {
  2037. struct compound_hdr hdr = {
  2038. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2039. };
  2040. uint32_t replen;
  2041. encode_compound_hdr(xdr, req, &hdr);
  2042. encode_sequence(xdr, &args->seq_args, &hdr);
  2043. encode_putfh(xdr, args->fh, &hdr);
  2044. replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
  2045. encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
  2046. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2047. args->acl_pages, args->acl_pgbase, args->acl_len);
  2048. encode_nops(&hdr);
  2049. }
  2050. /*
  2051. * Encode a WRITE request
  2052. */
  2053. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2054. struct nfs_writeargs *args)
  2055. {
  2056. struct compound_hdr hdr = {
  2057. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2058. };
  2059. encode_compound_hdr(xdr, req, &hdr);
  2060. encode_sequence(xdr, &args->seq_args, &hdr);
  2061. encode_putfh(xdr, args->fh, &hdr);
  2062. encode_write(xdr, args, &hdr);
  2063. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2064. encode_getfattr(xdr, args->bitmask, &hdr);
  2065. encode_nops(&hdr);
  2066. }
  2067. /*
  2068. * a COMMIT request
  2069. */
  2070. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2071. struct nfs_writeargs *args)
  2072. {
  2073. struct compound_hdr hdr = {
  2074. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2075. };
  2076. encode_compound_hdr(xdr, req, &hdr);
  2077. encode_sequence(xdr, &args->seq_args, &hdr);
  2078. encode_putfh(xdr, args->fh, &hdr);
  2079. encode_commit(xdr, args, &hdr);
  2080. encode_getfattr(xdr, args->bitmask, &hdr);
  2081. encode_nops(&hdr);
  2082. }
  2083. /*
  2084. * FSINFO request
  2085. */
  2086. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2087. struct nfs4_fsinfo_arg *args)
  2088. {
  2089. struct compound_hdr hdr = {
  2090. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2091. };
  2092. encode_compound_hdr(xdr, req, &hdr);
  2093. encode_sequence(xdr, &args->seq_args, &hdr);
  2094. encode_putfh(xdr, args->fh, &hdr);
  2095. encode_fsinfo(xdr, args->bitmask, &hdr);
  2096. encode_nops(&hdr);
  2097. }
  2098. /*
  2099. * a PATHCONF request
  2100. */
  2101. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2102. const struct nfs4_pathconf_arg *args)
  2103. {
  2104. struct compound_hdr hdr = {
  2105. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2106. };
  2107. encode_compound_hdr(xdr, req, &hdr);
  2108. encode_sequence(xdr, &args->seq_args, &hdr);
  2109. encode_putfh(xdr, args->fh, &hdr);
  2110. encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
  2111. &hdr);
  2112. encode_nops(&hdr);
  2113. }
  2114. /*
  2115. * a STATFS request
  2116. */
  2117. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2118. const struct nfs4_statfs_arg *args)
  2119. {
  2120. struct compound_hdr hdr = {
  2121. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2122. };
  2123. encode_compound_hdr(xdr, req, &hdr);
  2124. encode_sequence(xdr, &args->seq_args, &hdr);
  2125. encode_putfh(xdr, args->fh, &hdr);
  2126. encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
  2127. args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
  2128. encode_nops(&hdr);
  2129. }
  2130. /*
  2131. * GETATTR_BITMAP request
  2132. */
  2133. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2134. struct xdr_stream *xdr,
  2135. struct nfs4_server_caps_arg *args)
  2136. {
  2137. struct compound_hdr hdr = {
  2138. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2139. };
  2140. encode_compound_hdr(xdr, req, &hdr);
  2141. encode_sequence(xdr, &args->seq_args, &hdr);
  2142. encode_putfh(xdr, args->fhandle, &hdr);
  2143. encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
  2144. FATTR4_WORD0_LINK_SUPPORT|
  2145. FATTR4_WORD0_SYMLINK_SUPPORT|
  2146. FATTR4_WORD0_ACLSUPPORT, &hdr);
  2147. encode_nops(&hdr);
  2148. }
  2149. /*
  2150. * a RENEW request
  2151. */
  2152. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2153. struct nfs_client *clp)
  2154. {
  2155. struct compound_hdr hdr = {
  2156. .nops = 0,
  2157. };
  2158. encode_compound_hdr(xdr, req, &hdr);
  2159. encode_renew(xdr, clp, &hdr);
  2160. encode_nops(&hdr);
  2161. }
  2162. /*
  2163. * a SETCLIENTID request
  2164. */
  2165. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2166. struct xdr_stream *xdr,
  2167. struct nfs4_setclientid *sc)
  2168. {
  2169. struct compound_hdr hdr = {
  2170. .nops = 0,
  2171. };
  2172. encode_compound_hdr(xdr, req, &hdr);
  2173. encode_setclientid(xdr, sc, &hdr);
  2174. encode_nops(&hdr);
  2175. }
  2176. /*
  2177. * a SETCLIENTID_CONFIRM request
  2178. */
  2179. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2180. struct xdr_stream *xdr,
  2181. struct nfs4_setclientid_res *arg)
  2182. {
  2183. struct compound_hdr hdr = {
  2184. .nops = 0,
  2185. };
  2186. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  2187. encode_compound_hdr(xdr, req, &hdr);
  2188. encode_setclientid_confirm(xdr, arg, &hdr);
  2189. encode_putrootfh(xdr, &hdr);
  2190. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2191. encode_nops(&hdr);
  2192. }
  2193. /*
  2194. * DELEGRETURN request
  2195. */
  2196. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2197. struct xdr_stream *xdr,
  2198. const struct nfs4_delegreturnargs *args)
  2199. {
  2200. struct compound_hdr hdr = {
  2201. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2202. };
  2203. encode_compound_hdr(xdr, req, &hdr);
  2204. encode_sequence(xdr, &args->seq_args, &hdr);
  2205. encode_putfh(xdr, args->fhandle, &hdr);
  2206. encode_delegreturn(xdr, args->stateid, &hdr);
  2207. encode_getfattr(xdr, args->bitmask, &hdr);
  2208. encode_nops(&hdr);
  2209. }
  2210. /*
  2211. * Encode FS_LOCATIONS request
  2212. */
  2213. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2214. struct xdr_stream *xdr,
  2215. struct nfs4_fs_locations_arg *args)
  2216. {
  2217. struct compound_hdr hdr = {
  2218. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2219. };
  2220. uint32_t replen;
  2221. encode_compound_hdr(xdr, req, &hdr);
  2222. encode_sequence(xdr, &args->seq_args, &hdr);
  2223. encode_putfh(xdr, args->dir_fh, &hdr);
  2224. encode_lookup(xdr, args->name, &hdr);
  2225. replen = hdr.replen; /* get the attribute into args->page */
  2226. encode_fs_locations(xdr, args->bitmask, &hdr);
  2227. xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
  2228. 0, PAGE_SIZE);
  2229. encode_nops(&hdr);
  2230. }
  2231. #if defined(CONFIG_NFS_V4_1)
  2232. /*
  2233. * EXCHANGE_ID request
  2234. */
  2235. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2236. struct xdr_stream *xdr,
  2237. struct nfs41_exchange_id_args *args)
  2238. {
  2239. struct compound_hdr hdr = {
  2240. .minorversion = args->client->cl_mvops->minor_version,
  2241. };
  2242. encode_compound_hdr(xdr, req, &hdr);
  2243. encode_exchange_id(xdr, args, &hdr);
  2244. encode_nops(&hdr);
  2245. }
  2246. /*
  2247. * a CREATE_SESSION request
  2248. */
  2249. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2250. struct xdr_stream *xdr,
  2251. struct nfs41_create_session_args *args)
  2252. {
  2253. struct compound_hdr hdr = {
  2254. .minorversion = args->client->cl_mvops->minor_version,
  2255. };
  2256. encode_compound_hdr(xdr, req, &hdr);
  2257. encode_create_session(xdr, args, &hdr);
  2258. encode_nops(&hdr);
  2259. }
  2260. /*
  2261. * a DESTROY_SESSION request
  2262. */
  2263. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2264. struct xdr_stream *xdr,
  2265. struct nfs4_session *session)
  2266. {
  2267. struct compound_hdr hdr = {
  2268. .minorversion = session->clp->cl_mvops->minor_version,
  2269. };
  2270. encode_compound_hdr(xdr, req, &hdr);
  2271. encode_destroy_session(xdr, session, &hdr);
  2272. encode_nops(&hdr);
  2273. }
  2274. /*
  2275. * a SEQUENCE request
  2276. */
  2277. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2278. struct nfs4_sequence_args *args)
  2279. {
  2280. struct compound_hdr hdr = {
  2281. .minorversion = nfs4_xdr_minorversion(args),
  2282. };
  2283. encode_compound_hdr(xdr, req, &hdr);
  2284. encode_sequence(xdr, args, &hdr);
  2285. encode_nops(&hdr);
  2286. }
  2287. /*
  2288. * a GET_LEASE_TIME request
  2289. */
  2290. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2291. struct xdr_stream *xdr,
  2292. struct nfs4_get_lease_time_args *args)
  2293. {
  2294. struct compound_hdr hdr = {
  2295. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2296. };
  2297. const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
  2298. encode_compound_hdr(xdr, req, &hdr);
  2299. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2300. encode_putrootfh(xdr, &hdr);
  2301. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2302. encode_nops(&hdr);
  2303. }
  2304. /*
  2305. * a RECLAIM_COMPLETE request
  2306. */
  2307. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2308. struct xdr_stream *xdr,
  2309. struct nfs41_reclaim_complete_args *args)
  2310. {
  2311. struct compound_hdr hdr = {
  2312. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2313. };
  2314. encode_compound_hdr(xdr, req, &hdr);
  2315. encode_sequence(xdr, &args->seq_args, &hdr);
  2316. encode_reclaim_complete(xdr, args, &hdr);
  2317. encode_nops(&hdr);
  2318. }
  2319. /*
  2320. * Encode GETDEVICEINFO request
  2321. */
  2322. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2323. struct xdr_stream *xdr,
  2324. struct nfs4_getdeviceinfo_args *args)
  2325. {
  2326. struct compound_hdr hdr = {
  2327. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2328. };
  2329. encode_compound_hdr(xdr, req, &hdr);
  2330. encode_sequence(xdr, &args->seq_args, &hdr);
  2331. encode_getdeviceinfo(xdr, args, &hdr);
  2332. /* set up reply kvec. Subtract notification bitmap max size (2)
  2333. * so that notification bitmap is put in xdr_buf tail */
  2334. xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
  2335. args->pdev->pages, args->pdev->pgbase,
  2336. args->pdev->pglen);
  2337. encode_nops(&hdr);
  2338. }
  2339. /*
  2340. * Encode LAYOUTGET request
  2341. */
  2342. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2343. struct xdr_stream *xdr,
  2344. struct nfs4_layoutget_args *args)
  2345. {
  2346. struct compound_hdr hdr = {
  2347. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2348. };
  2349. encode_compound_hdr(xdr, req, &hdr);
  2350. encode_sequence(xdr, &args->seq_args, &hdr);
  2351. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2352. encode_layoutget(xdr, args, &hdr);
  2353. encode_nops(&hdr);
  2354. }
  2355. #endif /* CONFIG_NFS_V4_1 */
  2356. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  2357. {
  2358. dprintk("nfs: %s: prematurely hit end of receive buffer. "
  2359. "Remaining buffer length is %tu words.\n",
  2360. func, xdr->end - xdr->p);
  2361. }
  2362. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2363. {
  2364. __be32 *p;
  2365. p = xdr_inline_decode(xdr, 4);
  2366. if (unlikely(!p))
  2367. goto out_overflow;
  2368. *len = be32_to_cpup(p);
  2369. p = xdr_inline_decode(xdr, *len);
  2370. if (unlikely(!p))
  2371. goto out_overflow;
  2372. *string = (char *)p;
  2373. return 0;
  2374. out_overflow:
  2375. print_overflow_msg(__func__, xdr);
  2376. return -EIO;
  2377. }
  2378. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2379. {
  2380. __be32 *p;
  2381. p = xdr_inline_decode(xdr, 8);
  2382. if (unlikely(!p))
  2383. goto out_overflow;
  2384. hdr->status = be32_to_cpup(p++);
  2385. hdr->taglen = be32_to_cpup(p);
  2386. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2387. if (unlikely(!p))
  2388. goto out_overflow;
  2389. hdr->tag = (char *)p;
  2390. p += XDR_QUADLEN(hdr->taglen);
  2391. hdr->nops = be32_to_cpup(p);
  2392. if (unlikely(hdr->nops < 1))
  2393. return nfs4_stat_to_errno(hdr->status);
  2394. return 0;
  2395. out_overflow:
  2396. print_overflow_msg(__func__, xdr);
  2397. return -EIO;
  2398. }
  2399. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2400. {
  2401. __be32 *p;
  2402. uint32_t opnum;
  2403. int32_t nfserr;
  2404. p = xdr_inline_decode(xdr, 8);
  2405. if (unlikely(!p))
  2406. goto out_overflow;
  2407. opnum = be32_to_cpup(p++);
  2408. if (opnum != expected) {
  2409. dprintk("nfs: Server returned operation"
  2410. " %d but we issued a request for %d\n",
  2411. opnum, expected);
  2412. return -EIO;
  2413. }
  2414. nfserr = be32_to_cpup(p);
  2415. if (nfserr != NFS_OK)
  2416. return nfs4_stat_to_errno(nfserr);
  2417. return 0;
  2418. out_overflow:
  2419. print_overflow_msg(__func__, xdr);
  2420. return -EIO;
  2421. }
  2422. /* Dummy routine */
  2423. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
  2424. {
  2425. __be32 *p;
  2426. unsigned int strlen;
  2427. char *str;
  2428. p = xdr_inline_decode(xdr, 12);
  2429. if (likely(p))
  2430. return decode_opaque_inline(xdr, &strlen, &str);
  2431. print_overflow_msg(__func__, xdr);
  2432. return -EIO;
  2433. }
  2434. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2435. {
  2436. uint32_t bmlen;
  2437. __be32 *p;
  2438. p = xdr_inline_decode(xdr, 4);
  2439. if (unlikely(!p))
  2440. goto out_overflow;
  2441. bmlen = be32_to_cpup(p);
  2442. bitmap[0] = bitmap[1] = 0;
  2443. p = xdr_inline_decode(xdr, (bmlen << 2));
  2444. if (unlikely(!p))
  2445. goto out_overflow;
  2446. if (bmlen > 0) {
  2447. bitmap[0] = be32_to_cpup(p++);
  2448. if (bmlen > 1)
  2449. bitmap[1] = be32_to_cpup(p);
  2450. }
  2451. return 0;
  2452. out_overflow:
  2453. print_overflow_msg(__func__, xdr);
  2454. return -EIO;
  2455. }
  2456. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
  2457. {
  2458. __be32 *p;
  2459. p = xdr_inline_decode(xdr, 4);
  2460. if (unlikely(!p))
  2461. goto out_overflow;
  2462. *attrlen = be32_to_cpup(p);
  2463. *savep = xdr->p;
  2464. return 0;
  2465. out_overflow:
  2466. print_overflow_msg(__func__, xdr);
  2467. return -EIO;
  2468. }
  2469. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2470. {
  2471. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2472. int ret;
  2473. ret = decode_attr_bitmap(xdr, bitmask);
  2474. if (unlikely(ret < 0))
  2475. return ret;
  2476. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2477. } else
  2478. bitmask[0] = bitmask[1] = 0;
  2479. dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
  2480. return 0;
  2481. }
  2482. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2483. {
  2484. __be32 *p;
  2485. int ret = 0;
  2486. *type = 0;
  2487. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2488. return -EIO;
  2489. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2490. p = xdr_inline_decode(xdr, 4);
  2491. if (unlikely(!p))
  2492. goto out_overflow;
  2493. *type = be32_to_cpup(p);
  2494. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2495. dprintk("%s: bad type %d\n", __func__, *type);
  2496. return -EIO;
  2497. }
  2498. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2499. ret = NFS_ATTR_FATTR_TYPE;
  2500. }
  2501. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  2502. return ret;
  2503. out_overflow:
  2504. print_overflow_msg(__func__, xdr);
  2505. return -EIO;
  2506. }
  2507. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  2508. {
  2509. __be32 *p;
  2510. int ret = 0;
  2511. *change = 0;
  2512. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  2513. return -EIO;
  2514. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  2515. p = xdr_inline_decode(xdr, 8);
  2516. if (unlikely(!p))
  2517. goto out_overflow;
  2518. xdr_decode_hyper(p, change);
  2519. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  2520. ret = NFS_ATTR_FATTR_CHANGE;
  2521. }
  2522. dprintk("%s: change attribute=%Lu\n", __func__,
  2523. (unsigned long long)*change);
  2524. return ret;
  2525. out_overflow:
  2526. print_overflow_msg(__func__, xdr);
  2527. return -EIO;
  2528. }
  2529. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  2530. {
  2531. __be32 *p;
  2532. int ret = 0;
  2533. *size = 0;
  2534. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  2535. return -EIO;
  2536. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  2537. p = xdr_inline_decode(xdr, 8);
  2538. if (unlikely(!p))
  2539. goto out_overflow;
  2540. xdr_decode_hyper(p, size);
  2541. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  2542. ret = NFS_ATTR_FATTR_SIZE;
  2543. }
  2544. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  2545. return ret;
  2546. out_overflow:
  2547. print_overflow_msg(__func__, xdr);
  2548. return -EIO;
  2549. }
  2550. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2551. {
  2552. __be32 *p;
  2553. *res = 0;
  2554. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  2555. return -EIO;
  2556. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  2557. p = xdr_inline_decode(xdr, 4);
  2558. if (unlikely(!p))
  2559. goto out_overflow;
  2560. *res = be32_to_cpup(p);
  2561. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  2562. }
  2563. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  2564. return 0;
  2565. out_overflow:
  2566. print_overflow_msg(__func__, xdr);
  2567. return -EIO;
  2568. }
  2569. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2570. {
  2571. __be32 *p;
  2572. *res = 0;
  2573. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  2574. return -EIO;
  2575. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  2576. p = xdr_inline_decode(xdr, 4);
  2577. if (unlikely(!p))
  2578. goto out_overflow;
  2579. *res = be32_to_cpup(p);
  2580. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  2581. }
  2582. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  2583. return 0;
  2584. out_overflow:
  2585. print_overflow_msg(__func__, xdr);
  2586. return -EIO;
  2587. }
  2588. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  2589. {
  2590. __be32 *p;
  2591. int ret = 0;
  2592. fsid->major = 0;
  2593. fsid->minor = 0;
  2594. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  2595. return -EIO;
  2596. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  2597. p = xdr_inline_decode(xdr, 16);
  2598. if (unlikely(!p))
  2599. goto out_overflow;
  2600. p = xdr_decode_hyper(p, &fsid->major);
  2601. xdr_decode_hyper(p, &fsid->minor);
  2602. bitmap[0] &= ~FATTR4_WORD0_FSID;
  2603. ret = NFS_ATTR_FATTR_FSID;
  2604. }
  2605. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  2606. (unsigned long long)fsid->major,
  2607. (unsigned long long)fsid->minor);
  2608. return ret;
  2609. out_overflow:
  2610. print_overflow_msg(__func__, xdr);
  2611. return -EIO;
  2612. }
  2613. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2614. {
  2615. __be32 *p;
  2616. *res = 60;
  2617. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  2618. return -EIO;
  2619. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  2620. p = xdr_inline_decode(xdr, 4);
  2621. if (unlikely(!p))
  2622. goto out_overflow;
  2623. *res = be32_to_cpup(p);
  2624. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  2625. }
  2626. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  2627. return 0;
  2628. out_overflow:
  2629. print_overflow_msg(__func__, xdr);
  2630. return -EIO;
  2631. }
  2632. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
  2633. {
  2634. __be32 *p;
  2635. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  2636. return -EIO;
  2637. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  2638. p = xdr_inline_decode(xdr, 4);
  2639. if (unlikely(!p))
  2640. goto out_overflow;
  2641. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  2642. }
  2643. return 0;
  2644. out_overflow:
  2645. print_overflow_msg(__func__, xdr);
  2646. return -EIO;
  2647. }
  2648. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  2649. {
  2650. __be32 *p;
  2651. int len;
  2652. if (fh != NULL)
  2653. memset(fh, 0, sizeof(*fh));
  2654. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  2655. return -EIO;
  2656. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  2657. p = xdr_inline_decode(xdr, 4);
  2658. if (unlikely(!p))
  2659. goto out_overflow;
  2660. len = be32_to_cpup(p);
  2661. if (len > NFS4_FHSIZE)
  2662. return -EIO;
  2663. p = xdr_inline_decode(xdr, len);
  2664. if (unlikely(!p))
  2665. goto out_overflow;
  2666. if (fh != NULL) {
  2667. memcpy(fh->data, p, len);
  2668. fh->size = len;
  2669. }
  2670. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  2671. }
  2672. return 0;
  2673. out_overflow:
  2674. print_overflow_msg(__func__, xdr);
  2675. return -EIO;
  2676. }
  2677. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2678. {
  2679. __be32 *p;
  2680. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  2681. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  2682. return -EIO;
  2683. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  2684. p = xdr_inline_decode(xdr, 4);
  2685. if (unlikely(!p))
  2686. goto out_overflow;
  2687. *res = be32_to_cpup(p);
  2688. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  2689. }
  2690. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  2691. return 0;
  2692. out_overflow:
  2693. print_overflow_msg(__func__, xdr);
  2694. return -EIO;
  2695. }
  2696. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2697. {
  2698. __be32 *p;
  2699. int ret = 0;
  2700. *fileid = 0;
  2701. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  2702. return -EIO;
  2703. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  2704. p = xdr_inline_decode(xdr, 8);
  2705. if (unlikely(!p))
  2706. goto out_overflow;
  2707. xdr_decode_hyper(p, fileid);
  2708. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  2709. ret = NFS_ATTR_FATTR_FILEID;
  2710. }
  2711. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2712. return ret;
  2713. out_overflow:
  2714. print_overflow_msg(__func__, xdr);
  2715. return -EIO;
  2716. }
  2717. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2718. {
  2719. __be32 *p;
  2720. int ret = 0;
  2721. *fileid = 0;
  2722. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  2723. return -EIO;
  2724. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  2725. p = xdr_inline_decode(xdr, 8);
  2726. if (unlikely(!p))
  2727. goto out_overflow;
  2728. xdr_decode_hyper(p, fileid);
  2729. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  2730. ret = NFS_ATTR_FATTR_FILEID;
  2731. }
  2732. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2733. return ret;
  2734. out_overflow:
  2735. print_overflow_msg(__func__, xdr);
  2736. return -EIO;
  2737. }
  2738. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2739. {
  2740. __be32 *p;
  2741. int status = 0;
  2742. *res = 0;
  2743. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  2744. return -EIO;
  2745. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  2746. p = xdr_inline_decode(xdr, 8);
  2747. if (unlikely(!p))
  2748. goto out_overflow;
  2749. xdr_decode_hyper(p, res);
  2750. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  2751. }
  2752. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  2753. return status;
  2754. out_overflow:
  2755. print_overflow_msg(__func__, xdr);
  2756. return -EIO;
  2757. }
  2758. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2759. {
  2760. __be32 *p;
  2761. int status = 0;
  2762. *res = 0;
  2763. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  2764. return -EIO;
  2765. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  2766. p = xdr_inline_decode(xdr, 8);
  2767. if (unlikely(!p))
  2768. goto out_overflow;
  2769. xdr_decode_hyper(p, res);
  2770. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  2771. }
  2772. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  2773. return status;
  2774. out_overflow:
  2775. print_overflow_msg(__func__, xdr);
  2776. return -EIO;
  2777. }
  2778. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2779. {
  2780. __be32 *p;
  2781. int status = 0;
  2782. *res = 0;
  2783. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  2784. return -EIO;
  2785. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  2786. p = xdr_inline_decode(xdr, 8);
  2787. if (unlikely(!p))
  2788. goto out_overflow;
  2789. xdr_decode_hyper(p, res);
  2790. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  2791. }
  2792. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  2793. return status;
  2794. out_overflow:
  2795. print_overflow_msg(__func__, xdr);
  2796. return -EIO;
  2797. }
  2798. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  2799. {
  2800. u32 n;
  2801. __be32 *p;
  2802. int status = 0;
  2803. p = xdr_inline_decode(xdr, 4);
  2804. if (unlikely(!p))
  2805. goto out_overflow;
  2806. n = be32_to_cpup(p);
  2807. if (n == 0)
  2808. goto root_path;
  2809. dprintk("path ");
  2810. path->ncomponents = 0;
  2811. while (path->ncomponents < n) {
  2812. struct nfs4_string *component = &path->components[path->ncomponents];
  2813. status = decode_opaque_inline(xdr, &component->len, &component->data);
  2814. if (unlikely(status != 0))
  2815. goto out_eio;
  2816. if (path->ncomponents != n)
  2817. dprintk("/");
  2818. dprintk("%s", component->data);
  2819. if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
  2820. path->ncomponents++;
  2821. else {
  2822. dprintk("cannot parse %d components in path\n", n);
  2823. goto out_eio;
  2824. }
  2825. }
  2826. out:
  2827. dprintk("\n");
  2828. return status;
  2829. root_path:
  2830. /* a root pathname is sent as a zero component4 */
  2831. path->ncomponents = 1;
  2832. path->components[0].len=0;
  2833. path->components[0].data=NULL;
  2834. dprintk("path /\n");
  2835. goto out;
  2836. out_eio:
  2837. dprintk(" status %d", status);
  2838. status = -EIO;
  2839. goto out;
  2840. out_overflow:
  2841. print_overflow_msg(__func__, xdr);
  2842. return -EIO;
  2843. }
  2844. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  2845. {
  2846. int n;
  2847. __be32 *p;
  2848. int status = -EIO;
  2849. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  2850. goto out;
  2851. status = 0;
  2852. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  2853. goto out;
  2854. dprintk("%s: fsroot ", __func__);
  2855. status = decode_pathname(xdr, &res->fs_path);
  2856. if (unlikely(status != 0))
  2857. goto out;
  2858. p = xdr_inline_decode(xdr, 4);
  2859. if (unlikely(!p))
  2860. goto out_overflow;
  2861. n = be32_to_cpup(p);
  2862. if (n <= 0)
  2863. goto out_eio;
  2864. res->nlocations = 0;
  2865. while (res->nlocations < n) {
  2866. u32 m;
  2867. struct nfs4_fs_location *loc = &res->locations[res->nlocations];
  2868. p = xdr_inline_decode(xdr, 4);
  2869. if (unlikely(!p))
  2870. goto out_overflow;
  2871. m = be32_to_cpup(p);
  2872. loc->nservers = 0;
  2873. dprintk("%s: servers ", __func__);
  2874. while (loc->nservers < m) {
  2875. struct nfs4_string *server = &loc->servers[loc->nservers];
  2876. status = decode_opaque_inline(xdr, &server->len, &server->data);
  2877. if (unlikely(status != 0))
  2878. goto out_eio;
  2879. dprintk("%s ", server->data);
  2880. if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
  2881. loc->nservers++;
  2882. else {
  2883. unsigned int i;
  2884. dprintk("%s: using first %u of %u servers "
  2885. "returned for location %u\n",
  2886. __func__,
  2887. NFS4_FS_LOCATION_MAXSERVERS,
  2888. m, res->nlocations);
  2889. for (i = loc->nservers; i < m; i++) {
  2890. unsigned int len;
  2891. char *data;
  2892. status = decode_opaque_inline(xdr, &len, &data);
  2893. if (unlikely(status != 0))
  2894. goto out_eio;
  2895. }
  2896. }
  2897. }
  2898. status = decode_pathname(xdr, &loc->rootpath);
  2899. if (unlikely(status != 0))
  2900. goto out_eio;
  2901. if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
  2902. res->nlocations++;
  2903. }
  2904. if (res->nlocations != 0)
  2905. status = NFS_ATTR_FATTR_V4_REFERRAL;
  2906. out:
  2907. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  2908. return status;
  2909. out_overflow:
  2910. print_overflow_msg(__func__, xdr);
  2911. out_eio:
  2912. status = -EIO;
  2913. goto out;
  2914. }
  2915. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2916. {
  2917. __be32 *p;
  2918. int status = 0;
  2919. *res = 0;
  2920. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  2921. return -EIO;
  2922. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  2923. p = xdr_inline_decode(xdr, 8);
  2924. if (unlikely(!p))
  2925. goto out_overflow;
  2926. xdr_decode_hyper(p, res);
  2927. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  2928. }
  2929. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  2930. return status;
  2931. out_overflow:
  2932. print_overflow_msg(__func__, xdr);
  2933. return -EIO;
  2934. }
  2935. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2936. {
  2937. __be32 *p;
  2938. int status = 0;
  2939. *maxlink = 1;
  2940. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2941. return -EIO;
  2942. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2943. p = xdr_inline_decode(xdr, 4);
  2944. if (unlikely(!p))
  2945. goto out_overflow;
  2946. *maxlink = be32_to_cpup(p);
  2947. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2948. }
  2949. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  2950. return status;
  2951. out_overflow:
  2952. print_overflow_msg(__func__, xdr);
  2953. return -EIO;
  2954. }
  2955. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2956. {
  2957. __be32 *p;
  2958. int status = 0;
  2959. *maxname = 1024;
  2960. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2961. return -EIO;
  2962. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2963. p = xdr_inline_decode(xdr, 4);
  2964. if (unlikely(!p))
  2965. goto out_overflow;
  2966. *maxname = be32_to_cpup(p);
  2967. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2968. }
  2969. dprintk("%s: maxname=%u\n", __func__, *maxname);
  2970. return status;
  2971. out_overflow:
  2972. print_overflow_msg(__func__, xdr);
  2973. return -EIO;
  2974. }
  2975. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2976. {
  2977. __be32 *p;
  2978. int status = 0;
  2979. *res = 1024;
  2980. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2981. return -EIO;
  2982. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2983. uint64_t maxread;
  2984. p = xdr_inline_decode(xdr, 8);
  2985. if (unlikely(!p))
  2986. goto out_overflow;
  2987. xdr_decode_hyper(p, &maxread);
  2988. if (maxread > 0x7FFFFFFF)
  2989. maxread = 0x7FFFFFFF;
  2990. *res = (uint32_t)maxread;
  2991. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2992. }
  2993. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  2994. return status;
  2995. out_overflow:
  2996. print_overflow_msg(__func__, xdr);
  2997. return -EIO;
  2998. }
  2999. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3000. {
  3001. __be32 *p;
  3002. int status = 0;
  3003. *res = 1024;
  3004. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3005. return -EIO;
  3006. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3007. uint64_t maxwrite;
  3008. p = xdr_inline_decode(xdr, 8);
  3009. if (unlikely(!p))
  3010. goto out_overflow;
  3011. xdr_decode_hyper(p, &maxwrite);
  3012. if (maxwrite > 0x7FFFFFFF)
  3013. maxwrite = 0x7FFFFFFF;
  3014. *res = (uint32_t)maxwrite;
  3015. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3016. }
  3017. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3018. return status;
  3019. out_overflow:
  3020. print_overflow_msg(__func__, xdr);
  3021. return -EIO;
  3022. }
  3023. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3024. {
  3025. uint32_t tmp;
  3026. __be32 *p;
  3027. int ret = 0;
  3028. *mode = 0;
  3029. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3030. return -EIO;
  3031. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3032. p = xdr_inline_decode(xdr, 4);
  3033. if (unlikely(!p))
  3034. goto out_overflow;
  3035. tmp = be32_to_cpup(p);
  3036. *mode = tmp & ~S_IFMT;
  3037. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3038. ret = NFS_ATTR_FATTR_MODE;
  3039. }
  3040. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3041. return ret;
  3042. out_overflow:
  3043. print_overflow_msg(__func__, xdr);
  3044. return -EIO;
  3045. }
  3046. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3047. {
  3048. __be32 *p;
  3049. int ret = 0;
  3050. *nlink = 1;
  3051. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3052. return -EIO;
  3053. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3054. p = xdr_inline_decode(xdr, 4);
  3055. if (unlikely(!p))
  3056. goto out_overflow;
  3057. *nlink = be32_to_cpup(p);
  3058. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3059. ret = NFS_ATTR_FATTR_NLINK;
  3060. }
  3061. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3062. return ret;
  3063. out_overflow:
  3064. print_overflow_msg(__func__, xdr);
  3065. return -EIO;
  3066. }
  3067. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3068. struct nfs_client *clp, uint32_t *uid, int may_sleep)
  3069. {
  3070. uint32_t len;
  3071. __be32 *p;
  3072. int ret = 0;
  3073. *uid = -2;
  3074. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3075. return -EIO;
  3076. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  3077. p = xdr_inline_decode(xdr, 4);
  3078. if (unlikely(!p))
  3079. goto out_overflow;
  3080. len = be32_to_cpup(p);
  3081. p = xdr_inline_decode(xdr, len);
  3082. if (unlikely(!p))
  3083. goto out_overflow;
  3084. if (!may_sleep) {
  3085. /* do nothing */
  3086. } else if (len < XDR_MAX_NETOBJ) {
  3087. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
  3088. ret = NFS_ATTR_FATTR_OWNER;
  3089. else
  3090. dprintk("%s: nfs_map_name_to_uid failed!\n",
  3091. __func__);
  3092. } else
  3093. dprintk("%s: name too long (%u)!\n",
  3094. __func__, len);
  3095. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3096. }
  3097. dprintk("%s: uid=%d\n", __func__, (int)*uid);
  3098. return ret;
  3099. out_overflow:
  3100. print_overflow_msg(__func__, xdr);
  3101. return -EIO;
  3102. }
  3103. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3104. struct nfs_client *clp, uint32_t *gid, int may_sleep)
  3105. {
  3106. uint32_t len;
  3107. __be32 *p;
  3108. int ret = 0;
  3109. *gid = -2;
  3110. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3111. return -EIO;
  3112. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  3113. p = xdr_inline_decode(xdr, 4);
  3114. if (unlikely(!p))
  3115. goto out_overflow;
  3116. len = be32_to_cpup(p);
  3117. p = xdr_inline_decode(xdr, len);
  3118. if (unlikely(!p))
  3119. goto out_overflow;
  3120. if (!may_sleep) {
  3121. /* do nothing */
  3122. } else if (len < XDR_MAX_NETOBJ) {
  3123. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
  3124. ret = NFS_ATTR_FATTR_GROUP;
  3125. else
  3126. dprintk("%s: nfs_map_group_to_gid failed!\n",
  3127. __func__);
  3128. } else
  3129. dprintk("%s: name too long (%u)!\n",
  3130. __func__, len);
  3131. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3132. }
  3133. dprintk("%s: gid=%d\n", __func__, (int)*gid);
  3134. return ret;
  3135. out_overflow:
  3136. print_overflow_msg(__func__, xdr);
  3137. return -EIO;
  3138. }
  3139. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3140. {
  3141. uint32_t major = 0, minor = 0;
  3142. __be32 *p;
  3143. int ret = 0;
  3144. *rdev = MKDEV(0,0);
  3145. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3146. return -EIO;
  3147. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3148. dev_t tmp;
  3149. p = xdr_inline_decode(xdr, 8);
  3150. if (unlikely(!p))
  3151. goto out_overflow;
  3152. major = be32_to_cpup(p++);
  3153. minor = be32_to_cpup(p);
  3154. tmp = MKDEV(major, minor);
  3155. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3156. *rdev = tmp;
  3157. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3158. ret = NFS_ATTR_FATTR_RDEV;
  3159. }
  3160. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3161. return ret;
  3162. out_overflow:
  3163. print_overflow_msg(__func__, xdr);
  3164. return -EIO;
  3165. }
  3166. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3167. {
  3168. __be32 *p;
  3169. int status = 0;
  3170. *res = 0;
  3171. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3172. return -EIO;
  3173. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3174. p = xdr_inline_decode(xdr, 8);
  3175. if (unlikely(!p))
  3176. goto out_overflow;
  3177. xdr_decode_hyper(p, res);
  3178. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3179. }
  3180. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3181. return status;
  3182. out_overflow:
  3183. print_overflow_msg(__func__, xdr);
  3184. return -EIO;
  3185. }
  3186. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3187. {
  3188. __be32 *p;
  3189. int status = 0;
  3190. *res = 0;
  3191. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3192. return -EIO;
  3193. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3194. p = xdr_inline_decode(xdr, 8);
  3195. if (unlikely(!p))
  3196. goto out_overflow;
  3197. xdr_decode_hyper(p, res);
  3198. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3199. }
  3200. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3201. return status;
  3202. out_overflow:
  3203. print_overflow_msg(__func__, xdr);
  3204. return -EIO;
  3205. }
  3206. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3207. {
  3208. __be32 *p;
  3209. int status = 0;
  3210. *res = 0;
  3211. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3212. return -EIO;
  3213. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3214. p = xdr_inline_decode(xdr, 8);
  3215. if (unlikely(!p))
  3216. goto out_overflow;
  3217. xdr_decode_hyper(p, res);
  3218. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3219. }
  3220. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3221. return status;
  3222. out_overflow:
  3223. print_overflow_msg(__func__, xdr);
  3224. return -EIO;
  3225. }
  3226. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3227. {
  3228. __be32 *p;
  3229. int ret = 0;
  3230. *used = 0;
  3231. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3232. return -EIO;
  3233. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3234. p = xdr_inline_decode(xdr, 8);
  3235. if (unlikely(!p))
  3236. goto out_overflow;
  3237. xdr_decode_hyper(p, used);
  3238. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3239. ret = NFS_ATTR_FATTR_SPACE_USED;
  3240. }
  3241. dprintk("%s: space used=%Lu\n", __func__,
  3242. (unsigned long long)*used);
  3243. return ret;
  3244. out_overflow:
  3245. print_overflow_msg(__func__, xdr);
  3246. return -EIO;
  3247. }
  3248. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  3249. {
  3250. __be32 *p;
  3251. uint64_t sec;
  3252. uint32_t nsec;
  3253. p = xdr_inline_decode(xdr, 12);
  3254. if (unlikely(!p))
  3255. goto out_overflow;
  3256. p = xdr_decode_hyper(p, &sec);
  3257. nsec = be32_to_cpup(p);
  3258. time->tv_sec = (time_t)sec;
  3259. time->tv_nsec = (long)nsec;
  3260. return 0;
  3261. out_overflow:
  3262. print_overflow_msg(__func__, xdr);
  3263. return -EIO;
  3264. }
  3265. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3266. {
  3267. int status = 0;
  3268. time->tv_sec = 0;
  3269. time->tv_nsec = 0;
  3270. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3271. return -EIO;
  3272. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3273. status = decode_attr_time(xdr, time);
  3274. if (status == 0)
  3275. status = NFS_ATTR_FATTR_ATIME;
  3276. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3277. }
  3278. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  3279. return status;
  3280. }
  3281. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3282. {
  3283. int status = 0;
  3284. time->tv_sec = 0;
  3285. time->tv_nsec = 0;
  3286. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3287. return -EIO;
  3288. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3289. status = decode_attr_time(xdr, time);
  3290. if (status == 0)
  3291. status = NFS_ATTR_FATTR_CTIME;
  3292. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3293. }
  3294. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  3295. return status;
  3296. }
  3297. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3298. struct timespec *time)
  3299. {
  3300. int status = 0;
  3301. time->tv_sec = 0;
  3302. time->tv_nsec = 0;
  3303. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3304. return -EIO;
  3305. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3306. status = decode_attr_time(xdr, time);
  3307. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3308. }
  3309. dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
  3310. (long)time->tv_nsec);
  3311. return status;
  3312. }
  3313. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3314. {
  3315. int status = 0;
  3316. time->tv_sec = 0;
  3317. time->tv_nsec = 0;
  3318. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3319. return -EIO;
  3320. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3321. status = decode_attr_time(xdr, time);
  3322. if (status == 0)
  3323. status = NFS_ATTR_FATTR_MTIME;
  3324. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3325. }
  3326. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  3327. return status;
  3328. }
  3329. static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
  3330. {
  3331. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3332. unsigned int nwords = xdr->p - savep;
  3333. if (unlikely(attrwords != nwords)) {
  3334. dprintk("%s: server returned incorrect attribute length: "
  3335. "%u %c %u\n",
  3336. __func__,
  3337. attrwords << 2,
  3338. (attrwords < nwords) ? '<' : '>',
  3339. nwords << 2);
  3340. return -EIO;
  3341. }
  3342. return 0;
  3343. }
  3344. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3345. {
  3346. __be32 *p;
  3347. p = xdr_inline_decode(xdr, 20);
  3348. if (unlikely(!p))
  3349. goto out_overflow;
  3350. cinfo->atomic = be32_to_cpup(p++);
  3351. p = xdr_decode_hyper(p, &cinfo->before);
  3352. xdr_decode_hyper(p, &cinfo->after);
  3353. return 0;
  3354. out_overflow:
  3355. print_overflow_msg(__func__, xdr);
  3356. return -EIO;
  3357. }
  3358. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  3359. {
  3360. __be32 *p;
  3361. uint32_t supp, acc;
  3362. int status;
  3363. status = decode_op_hdr(xdr, OP_ACCESS);
  3364. if (status)
  3365. return status;
  3366. p = xdr_inline_decode(xdr, 8);
  3367. if (unlikely(!p))
  3368. goto out_overflow;
  3369. supp = be32_to_cpup(p++);
  3370. acc = be32_to_cpup(p);
  3371. access->supported = supp;
  3372. access->access = acc;
  3373. return 0;
  3374. out_overflow:
  3375. print_overflow_msg(__func__, xdr);
  3376. return -EIO;
  3377. }
  3378. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3379. {
  3380. __be32 *p;
  3381. p = xdr_inline_decode(xdr, len);
  3382. if (likely(p)) {
  3383. memcpy(buf, p, len);
  3384. return 0;
  3385. }
  3386. print_overflow_msg(__func__, xdr);
  3387. return -EIO;
  3388. }
  3389. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3390. {
  3391. return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
  3392. }
  3393. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  3394. {
  3395. int status;
  3396. status = decode_op_hdr(xdr, OP_CLOSE);
  3397. if (status != -EIO)
  3398. nfs_increment_open_seqid(status, res->seqid);
  3399. if (!status)
  3400. status = decode_stateid(xdr, &res->stateid);
  3401. return status;
  3402. }
  3403. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  3404. {
  3405. return decode_opaque_fixed(xdr, verifier, 8);
  3406. }
  3407. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  3408. {
  3409. int status;
  3410. status = decode_op_hdr(xdr, OP_COMMIT);
  3411. if (!status)
  3412. status = decode_verifier(xdr, res->verf->verifier);
  3413. return status;
  3414. }
  3415. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3416. {
  3417. __be32 *p;
  3418. uint32_t bmlen;
  3419. int status;
  3420. status = decode_op_hdr(xdr, OP_CREATE);
  3421. if (status)
  3422. return status;
  3423. if ((status = decode_change_info(xdr, cinfo)))
  3424. return status;
  3425. p = xdr_inline_decode(xdr, 4);
  3426. if (unlikely(!p))
  3427. goto out_overflow;
  3428. bmlen = be32_to_cpup(p);
  3429. p = xdr_inline_decode(xdr, bmlen << 2);
  3430. if (likely(p))
  3431. return 0;
  3432. out_overflow:
  3433. print_overflow_msg(__func__, xdr);
  3434. return -EIO;
  3435. }
  3436. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  3437. {
  3438. __be32 *savep;
  3439. uint32_t attrlen, bitmap[2] = {0};
  3440. int status;
  3441. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3442. goto xdr_error;
  3443. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3444. goto xdr_error;
  3445. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3446. goto xdr_error;
  3447. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  3448. goto xdr_error;
  3449. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  3450. goto xdr_error;
  3451. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  3452. goto xdr_error;
  3453. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  3454. goto xdr_error;
  3455. status = verify_attr_len(xdr, savep, attrlen);
  3456. xdr_error:
  3457. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3458. return status;
  3459. }
  3460. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  3461. {
  3462. __be32 *savep;
  3463. uint32_t attrlen, bitmap[2] = {0};
  3464. int status;
  3465. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3466. goto xdr_error;
  3467. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3468. goto xdr_error;
  3469. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3470. goto xdr_error;
  3471. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  3472. goto xdr_error;
  3473. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  3474. goto xdr_error;
  3475. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  3476. goto xdr_error;
  3477. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  3478. goto xdr_error;
  3479. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  3480. goto xdr_error;
  3481. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  3482. goto xdr_error;
  3483. status = verify_attr_len(xdr, savep, attrlen);
  3484. xdr_error:
  3485. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3486. return status;
  3487. }
  3488. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  3489. {
  3490. __be32 *savep;
  3491. uint32_t attrlen, bitmap[2] = {0};
  3492. int status;
  3493. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3494. goto xdr_error;
  3495. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3496. goto xdr_error;
  3497. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3498. goto xdr_error;
  3499. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  3500. goto xdr_error;
  3501. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  3502. goto xdr_error;
  3503. status = verify_attr_len(xdr, savep, attrlen);
  3504. xdr_error:
  3505. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3506. return status;
  3507. }
  3508. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  3509. struct nfs_fattr *fattr, struct nfs_fh *fh,
  3510. const struct nfs_server *server, int may_sleep)
  3511. {
  3512. int status;
  3513. umode_t fmode = 0;
  3514. uint64_t fileid;
  3515. uint32_t type;
  3516. status = decode_attr_type(xdr, bitmap, &type);
  3517. if (status < 0)
  3518. goto xdr_error;
  3519. fattr->mode = 0;
  3520. if (status != 0) {
  3521. fattr->mode |= nfs_type2fmt[type];
  3522. fattr->valid |= status;
  3523. }
  3524. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  3525. if (status < 0)
  3526. goto xdr_error;
  3527. fattr->valid |= status;
  3528. status = decode_attr_size(xdr, bitmap, &fattr->size);
  3529. if (status < 0)
  3530. goto xdr_error;
  3531. fattr->valid |= status;
  3532. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  3533. if (status < 0)
  3534. goto xdr_error;
  3535. fattr->valid |= status;
  3536. status = decode_attr_error(xdr, bitmap);
  3537. if (status < 0)
  3538. goto xdr_error;
  3539. status = decode_attr_filehandle(xdr, bitmap, fh);
  3540. if (status < 0)
  3541. goto xdr_error;
  3542. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  3543. if (status < 0)
  3544. goto xdr_error;
  3545. fattr->valid |= status;
  3546. status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
  3547. struct nfs4_fs_locations,
  3548. fattr));
  3549. if (status < 0)
  3550. goto xdr_error;
  3551. fattr->valid |= status;
  3552. status = decode_attr_mode(xdr, bitmap, &fmode);
  3553. if (status < 0)
  3554. goto xdr_error;
  3555. if (status != 0) {
  3556. fattr->mode |= fmode;
  3557. fattr->valid |= status;
  3558. }
  3559. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  3560. if (status < 0)
  3561. goto xdr_error;
  3562. fattr->valid |= status;
  3563. status = decode_attr_owner(xdr, bitmap, server->nfs_client,
  3564. &fattr->uid, may_sleep);
  3565. if (status < 0)
  3566. goto xdr_error;
  3567. fattr->valid |= status;
  3568. status = decode_attr_group(xdr, bitmap, server->nfs_client,
  3569. &fattr->gid, may_sleep);
  3570. if (status < 0)
  3571. goto xdr_error;
  3572. fattr->valid |= status;
  3573. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  3574. if (status < 0)
  3575. goto xdr_error;
  3576. fattr->valid |= status;
  3577. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  3578. if (status < 0)
  3579. goto xdr_error;
  3580. fattr->valid |= status;
  3581. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  3582. if (status < 0)
  3583. goto xdr_error;
  3584. fattr->valid |= status;
  3585. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  3586. if (status < 0)
  3587. goto xdr_error;
  3588. fattr->valid |= status;
  3589. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  3590. if (status < 0)
  3591. goto xdr_error;
  3592. fattr->valid |= status;
  3593. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
  3594. if (status < 0)
  3595. goto xdr_error;
  3596. if (status != 0 && !(fattr->valid & status)) {
  3597. fattr->fileid = fileid;
  3598. fattr->valid |= status;
  3599. }
  3600. xdr_error:
  3601. dprintk("%s: xdr returned %d\n", __func__, -status);
  3602. return status;
  3603. }
  3604. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  3605. struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
  3606. {
  3607. __be32 *savep;
  3608. uint32_t attrlen,
  3609. bitmap[2] = {0};
  3610. int status;
  3611. status = decode_op_hdr(xdr, OP_GETATTR);
  3612. if (status < 0)
  3613. goto xdr_error;
  3614. status = decode_attr_bitmap(xdr, bitmap);
  3615. if (status < 0)
  3616. goto xdr_error;
  3617. status = decode_attr_length(xdr, &attrlen, &savep);
  3618. if (status < 0)
  3619. goto xdr_error;
  3620. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
  3621. if (status < 0)
  3622. goto xdr_error;
  3623. status = verify_attr_len(xdr, savep, attrlen);
  3624. xdr_error:
  3625. dprintk("%s: xdr returned %d\n", __func__, -status);
  3626. return status;
  3627. }
  3628. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  3629. const struct nfs_server *server, int may_sleep)
  3630. {
  3631. return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
  3632. }
  3633. /*
  3634. * Decode potentially multiple layout types. Currently we only support
  3635. * one layout driver per file system.
  3636. */
  3637. static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
  3638. uint32_t *layouttype)
  3639. {
  3640. uint32_t *p;
  3641. int num;
  3642. p = xdr_inline_decode(xdr, 4);
  3643. if (unlikely(!p))
  3644. goto out_overflow;
  3645. num = be32_to_cpup(p);
  3646. /* pNFS is not supported by the underlying file system */
  3647. if (num == 0) {
  3648. *layouttype = 0;
  3649. return 0;
  3650. }
  3651. if (num > 1)
  3652. printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
  3653. "per filesystem not supported\n", __func__);
  3654. /* Decode and set first layout type, move xdr->p past unused types */
  3655. p = xdr_inline_decode(xdr, num * 4);
  3656. if (unlikely(!p))
  3657. goto out_overflow;
  3658. *layouttype = be32_to_cpup(p);
  3659. return 0;
  3660. out_overflow:
  3661. print_overflow_msg(__func__, xdr);
  3662. return -EIO;
  3663. }
  3664. /*
  3665. * The type of file system exported.
  3666. * Note we must ensure that layouttype is set in any non-error case.
  3667. */
  3668. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  3669. uint32_t *layouttype)
  3670. {
  3671. int status = 0;
  3672. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  3673. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  3674. return -EIO;
  3675. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  3676. status = decode_first_pnfs_layout_type(xdr, layouttype);
  3677. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  3678. } else
  3679. *layouttype = 0;
  3680. return status;
  3681. }
  3682. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  3683. {
  3684. __be32 *savep;
  3685. uint32_t attrlen, bitmap[2];
  3686. int status;
  3687. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3688. goto xdr_error;
  3689. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3690. goto xdr_error;
  3691. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3692. goto xdr_error;
  3693. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  3694. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  3695. goto xdr_error;
  3696. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  3697. goto xdr_error;
  3698. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  3699. goto xdr_error;
  3700. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  3701. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  3702. goto xdr_error;
  3703. fsinfo->wtpref = fsinfo->wtmax;
  3704. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  3705. if (status != 0)
  3706. goto xdr_error;
  3707. status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
  3708. if (status != 0)
  3709. goto xdr_error;
  3710. status = verify_attr_len(xdr, savep, attrlen);
  3711. xdr_error:
  3712. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3713. return status;
  3714. }
  3715. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  3716. {
  3717. __be32 *p;
  3718. uint32_t len;
  3719. int status;
  3720. /* Zero handle first to allow comparisons */
  3721. memset(fh, 0, sizeof(*fh));
  3722. status = decode_op_hdr(xdr, OP_GETFH);
  3723. if (status)
  3724. return status;
  3725. p = xdr_inline_decode(xdr, 4);
  3726. if (unlikely(!p))
  3727. goto out_overflow;
  3728. len = be32_to_cpup(p);
  3729. if (len > NFS4_FHSIZE)
  3730. return -EIO;
  3731. fh->size = len;
  3732. p = xdr_inline_decode(xdr, len);
  3733. if (unlikely(!p))
  3734. goto out_overflow;
  3735. memcpy(fh->data, p, len);
  3736. return 0;
  3737. out_overflow:
  3738. print_overflow_msg(__func__, xdr);
  3739. return -EIO;
  3740. }
  3741. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3742. {
  3743. int status;
  3744. status = decode_op_hdr(xdr, OP_LINK);
  3745. if (status)
  3746. return status;
  3747. return decode_change_info(xdr, cinfo);
  3748. }
  3749. /*
  3750. * We create the owner, so we know a proper owner.id length is 4.
  3751. */
  3752. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  3753. {
  3754. uint64_t offset, length, clientid;
  3755. __be32 *p;
  3756. uint32_t namelen, type;
  3757. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  3758. if (unlikely(!p))
  3759. goto out_overflow;
  3760. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  3761. p = xdr_decode_hyper(p, &length);
  3762. type = be32_to_cpup(p++); /* 4 byte read */
  3763. if (fl != NULL) { /* manipulate file lock */
  3764. fl->fl_start = (loff_t)offset;
  3765. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  3766. if (length == ~(uint64_t)0)
  3767. fl->fl_end = OFFSET_MAX;
  3768. fl->fl_type = F_WRLCK;
  3769. if (type & 1)
  3770. fl->fl_type = F_RDLCK;
  3771. fl->fl_pid = 0;
  3772. }
  3773. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  3774. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  3775. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  3776. if (likely(p))
  3777. return -NFS4ERR_DENIED;
  3778. out_overflow:
  3779. print_overflow_msg(__func__, xdr);
  3780. return -EIO;
  3781. }
  3782. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  3783. {
  3784. int status;
  3785. status = decode_op_hdr(xdr, OP_LOCK);
  3786. if (status == -EIO)
  3787. goto out;
  3788. if (status == 0) {
  3789. status = decode_stateid(xdr, &res->stateid);
  3790. if (unlikely(status))
  3791. goto out;
  3792. } else if (status == -NFS4ERR_DENIED)
  3793. status = decode_lock_denied(xdr, NULL);
  3794. if (res->open_seqid != NULL)
  3795. nfs_increment_open_seqid(status, res->open_seqid);
  3796. nfs_increment_lock_seqid(status, res->lock_seqid);
  3797. out:
  3798. return status;
  3799. }
  3800. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  3801. {
  3802. int status;
  3803. status = decode_op_hdr(xdr, OP_LOCKT);
  3804. if (status == -NFS4ERR_DENIED)
  3805. return decode_lock_denied(xdr, res->denied);
  3806. return status;
  3807. }
  3808. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  3809. {
  3810. int status;
  3811. status = decode_op_hdr(xdr, OP_LOCKU);
  3812. if (status != -EIO)
  3813. nfs_increment_lock_seqid(status, res->seqid);
  3814. if (status == 0)
  3815. status = decode_stateid(xdr, &res->stateid);
  3816. return status;
  3817. }
  3818. static int decode_release_lockowner(struct xdr_stream *xdr)
  3819. {
  3820. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  3821. }
  3822. static int decode_lookup(struct xdr_stream *xdr)
  3823. {
  3824. return decode_op_hdr(xdr, OP_LOOKUP);
  3825. }
  3826. /* This is too sick! */
  3827. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  3828. {
  3829. __be32 *p;
  3830. uint32_t limit_type, nblocks, blocksize;
  3831. p = xdr_inline_decode(xdr, 12);
  3832. if (unlikely(!p))
  3833. goto out_overflow;
  3834. limit_type = be32_to_cpup(p++);
  3835. switch (limit_type) {
  3836. case 1:
  3837. xdr_decode_hyper(p, maxsize);
  3838. break;
  3839. case 2:
  3840. nblocks = be32_to_cpup(p++);
  3841. blocksize = be32_to_cpup(p);
  3842. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  3843. }
  3844. return 0;
  3845. out_overflow:
  3846. print_overflow_msg(__func__, xdr);
  3847. return -EIO;
  3848. }
  3849. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  3850. {
  3851. __be32 *p;
  3852. uint32_t delegation_type;
  3853. int status;
  3854. p = xdr_inline_decode(xdr, 4);
  3855. if (unlikely(!p))
  3856. goto out_overflow;
  3857. delegation_type = be32_to_cpup(p);
  3858. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  3859. res->delegation_type = 0;
  3860. return 0;
  3861. }
  3862. status = decode_stateid(xdr, &res->delegation);
  3863. if (unlikely(status))
  3864. return status;
  3865. p = xdr_inline_decode(xdr, 4);
  3866. if (unlikely(!p))
  3867. goto out_overflow;
  3868. res->do_recall = be32_to_cpup(p);
  3869. switch (delegation_type) {
  3870. case NFS4_OPEN_DELEGATE_READ:
  3871. res->delegation_type = FMODE_READ;
  3872. break;
  3873. case NFS4_OPEN_DELEGATE_WRITE:
  3874. res->delegation_type = FMODE_WRITE|FMODE_READ;
  3875. if (decode_space_limit(xdr, &res->maxsize) < 0)
  3876. return -EIO;
  3877. }
  3878. return decode_ace(xdr, NULL, res->server->nfs_client);
  3879. out_overflow:
  3880. print_overflow_msg(__func__, xdr);
  3881. return -EIO;
  3882. }
  3883. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  3884. {
  3885. __be32 *p;
  3886. uint32_t savewords, bmlen, i;
  3887. int status;
  3888. status = decode_op_hdr(xdr, OP_OPEN);
  3889. if (status != -EIO)
  3890. nfs_increment_open_seqid(status, res->seqid);
  3891. if (!status)
  3892. status = decode_stateid(xdr, &res->stateid);
  3893. if (unlikely(status))
  3894. return status;
  3895. decode_change_info(xdr, &res->cinfo);
  3896. p = xdr_inline_decode(xdr, 8);
  3897. if (unlikely(!p))
  3898. goto out_overflow;
  3899. res->rflags = be32_to_cpup(p++);
  3900. bmlen = be32_to_cpup(p);
  3901. if (bmlen > 10)
  3902. goto xdr_error;
  3903. p = xdr_inline_decode(xdr, bmlen << 2);
  3904. if (unlikely(!p))
  3905. goto out_overflow;
  3906. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  3907. for (i = 0; i < savewords; ++i)
  3908. res->attrset[i] = be32_to_cpup(p++);
  3909. for (; i < NFS4_BITMAP_SIZE; i++)
  3910. res->attrset[i] = 0;
  3911. return decode_delegation(xdr, res);
  3912. xdr_error:
  3913. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  3914. return -EIO;
  3915. out_overflow:
  3916. print_overflow_msg(__func__, xdr);
  3917. return -EIO;
  3918. }
  3919. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  3920. {
  3921. int status;
  3922. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  3923. if (status != -EIO)
  3924. nfs_increment_open_seqid(status, res->seqid);
  3925. if (!status)
  3926. status = decode_stateid(xdr, &res->stateid);
  3927. return status;
  3928. }
  3929. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  3930. {
  3931. int status;
  3932. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  3933. if (status != -EIO)
  3934. nfs_increment_open_seqid(status, res->seqid);
  3935. if (!status)
  3936. status = decode_stateid(xdr, &res->stateid);
  3937. return status;
  3938. }
  3939. static int decode_putfh(struct xdr_stream *xdr)
  3940. {
  3941. return decode_op_hdr(xdr, OP_PUTFH);
  3942. }
  3943. static int decode_putrootfh(struct xdr_stream *xdr)
  3944. {
  3945. return decode_op_hdr(xdr, OP_PUTROOTFH);
  3946. }
  3947. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  3948. {
  3949. struct kvec *iov = req->rq_rcv_buf.head;
  3950. __be32 *p;
  3951. uint32_t count, eof, recvd, hdrlen;
  3952. int status;
  3953. status = decode_op_hdr(xdr, OP_READ);
  3954. if (status)
  3955. return status;
  3956. p = xdr_inline_decode(xdr, 8);
  3957. if (unlikely(!p))
  3958. goto out_overflow;
  3959. eof = be32_to_cpup(p++);
  3960. count = be32_to_cpup(p);
  3961. hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
  3962. recvd = req->rq_rcv_buf.len - hdrlen;
  3963. if (count > recvd) {
  3964. dprintk("NFS: server cheating in read reply: "
  3965. "count %u > recvd %u\n", count, recvd);
  3966. count = recvd;
  3967. eof = 0;
  3968. }
  3969. xdr_read_pages(xdr, count);
  3970. res->eof = eof;
  3971. res->count = count;
  3972. return 0;
  3973. out_overflow:
  3974. print_overflow_msg(__func__, xdr);
  3975. return -EIO;
  3976. }
  3977. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  3978. {
  3979. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  3980. struct kvec *iov = rcvbuf->head;
  3981. size_t hdrlen;
  3982. u32 recvd, pglen = rcvbuf->page_len;
  3983. int status;
  3984. status = decode_op_hdr(xdr, OP_READDIR);
  3985. if (!status)
  3986. status = decode_verifier(xdr, readdir->verifier.data);
  3987. if (unlikely(status))
  3988. return status;
  3989. dprintk("%s: verifier = %08x:%08x\n",
  3990. __func__,
  3991. ((u32 *)readdir->verifier.data)[0],
  3992. ((u32 *)readdir->verifier.data)[1]);
  3993. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  3994. recvd = rcvbuf->len - hdrlen;
  3995. if (pglen > recvd)
  3996. pglen = recvd;
  3997. xdr_read_pages(xdr, pglen);
  3998. return pglen;
  3999. }
  4000. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4001. {
  4002. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4003. struct kvec *iov = rcvbuf->head;
  4004. size_t hdrlen;
  4005. u32 len, recvd;
  4006. __be32 *p;
  4007. int status;
  4008. status = decode_op_hdr(xdr, OP_READLINK);
  4009. if (status)
  4010. return status;
  4011. /* Convert length of symlink */
  4012. p = xdr_inline_decode(xdr, 4);
  4013. if (unlikely(!p))
  4014. goto out_overflow;
  4015. len = be32_to_cpup(p);
  4016. if (len >= rcvbuf->page_len || len <= 0) {
  4017. dprintk("nfs: server returned giant symlink!\n");
  4018. return -ENAMETOOLONG;
  4019. }
  4020. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  4021. recvd = req->rq_rcv_buf.len - hdrlen;
  4022. if (recvd < len) {
  4023. dprintk("NFS: server cheating in readlink reply: "
  4024. "count %u > recvd %u\n", len, recvd);
  4025. return -EIO;
  4026. }
  4027. xdr_read_pages(xdr, len);
  4028. /*
  4029. * The XDR encode routine has set things up so that
  4030. * the link text will be copied directly into the
  4031. * buffer. We just have to do overflow-checking,
  4032. * and and null-terminate the text (the VFS expects
  4033. * null-termination).
  4034. */
  4035. xdr_terminate_string(rcvbuf, len);
  4036. return 0;
  4037. out_overflow:
  4038. print_overflow_msg(__func__, xdr);
  4039. return -EIO;
  4040. }
  4041. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4042. {
  4043. int status;
  4044. status = decode_op_hdr(xdr, OP_REMOVE);
  4045. if (status)
  4046. goto out;
  4047. status = decode_change_info(xdr, cinfo);
  4048. out:
  4049. return status;
  4050. }
  4051. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4052. struct nfs4_change_info *new_cinfo)
  4053. {
  4054. int status;
  4055. status = decode_op_hdr(xdr, OP_RENAME);
  4056. if (status)
  4057. goto out;
  4058. if ((status = decode_change_info(xdr, old_cinfo)))
  4059. goto out;
  4060. status = decode_change_info(xdr, new_cinfo);
  4061. out:
  4062. return status;
  4063. }
  4064. static int decode_renew(struct xdr_stream *xdr)
  4065. {
  4066. return decode_op_hdr(xdr, OP_RENEW);
  4067. }
  4068. static int
  4069. decode_restorefh(struct xdr_stream *xdr)
  4070. {
  4071. return decode_op_hdr(xdr, OP_RESTOREFH);
  4072. }
  4073. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4074. size_t *acl_len)
  4075. {
  4076. __be32 *savep;
  4077. uint32_t attrlen,
  4078. bitmap[2] = {0};
  4079. struct kvec *iov = req->rq_rcv_buf.head;
  4080. int status;
  4081. *acl_len = 0;
  4082. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4083. goto out;
  4084. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4085. goto out;
  4086. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4087. goto out;
  4088. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4089. return -EIO;
  4090. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4091. size_t hdrlen;
  4092. u32 recvd;
  4093. /* We ignore &savep and don't do consistency checks on
  4094. * the attr length. Let userspace figure it out.... */
  4095. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  4096. recvd = req->rq_rcv_buf.len - hdrlen;
  4097. if (attrlen > recvd) {
  4098. dprintk("NFS: server cheating in getattr"
  4099. " acl reply: attrlen %u > recvd %u\n",
  4100. attrlen, recvd);
  4101. return -EINVAL;
  4102. }
  4103. xdr_read_pages(xdr, attrlen);
  4104. *acl_len = attrlen;
  4105. } else
  4106. status = -EOPNOTSUPP;
  4107. out:
  4108. return status;
  4109. }
  4110. static int
  4111. decode_savefh(struct xdr_stream *xdr)
  4112. {
  4113. return decode_op_hdr(xdr, OP_SAVEFH);
  4114. }
  4115. static int decode_setattr(struct xdr_stream *xdr)
  4116. {
  4117. __be32 *p;
  4118. uint32_t bmlen;
  4119. int status;
  4120. status = decode_op_hdr(xdr, OP_SETATTR);
  4121. if (status)
  4122. return status;
  4123. p = xdr_inline_decode(xdr, 4);
  4124. if (unlikely(!p))
  4125. goto out_overflow;
  4126. bmlen = be32_to_cpup(p);
  4127. p = xdr_inline_decode(xdr, bmlen << 2);
  4128. if (likely(p))
  4129. return 0;
  4130. out_overflow:
  4131. print_overflow_msg(__func__, xdr);
  4132. return -EIO;
  4133. }
  4134. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4135. {
  4136. __be32 *p;
  4137. uint32_t opnum;
  4138. int32_t nfserr;
  4139. p = xdr_inline_decode(xdr, 8);
  4140. if (unlikely(!p))
  4141. goto out_overflow;
  4142. opnum = be32_to_cpup(p++);
  4143. if (opnum != OP_SETCLIENTID) {
  4144. dprintk("nfs: decode_setclientid: Server returned operation"
  4145. " %d\n", opnum);
  4146. return -EIO;
  4147. }
  4148. nfserr = be32_to_cpup(p);
  4149. if (nfserr == NFS_OK) {
  4150. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4151. if (unlikely(!p))
  4152. goto out_overflow;
  4153. p = xdr_decode_hyper(p, &res->clientid);
  4154. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4155. } else if (nfserr == NFSERR_CLID_INUSE) {
  4156. uint32_t len;
  4157. /* skip netid string */
  4158. p = xdr_inline_decode(xdr, 4);
  4159. if (unlikely(!p))
  4160. goto out_overflow;
  4161. len = be32_to_cpup(p);
  4162. p = xdr_inline_decode(xdr, len);
  4163. if (unlikely(!p))
  4164. goto out_overflow;
  4165. /* skip uaddr string */
  4166. p = xdr_inline_decode(xdr, 4);
  4167. if (unlikely(!p))
  4168. goto out_overflow;
  4169. len = be32_to_cpup(p);
  4170. p = xdr_inline_decode(xdr, len);
  4171. if (unlikely(!p))
  4172. goto out_overflow;
  4173. return -NFSERR_CLID_INUSE;
  4174. } else
  4175. return nfs4_stat_to_errno(nfserr);
  4176. return 0;
  4177. out_overflow:
  4178. print_overflow_msg(__func__, xdr);
  4179. return -EIO;
  4180. }
  4181. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4182. {
  4183. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  4184. }
  4185. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  4186. {
  4187. __be32 *p;
  4188. int status;
  4189. status = decode_op_hdr(xdr, OP_WRITE);
  4190. if (status)
  4191. return status;
  4192. p = xdr_inline_decode(xdr, 16);
  4193. if (unlikely(!p))
  4194. goto out_overflow;
  4195. res->count = be32_to_cpup(p++);
  4196. res->verf->committed = be32_to_cpup(p++);
  4197. memcpy(res->verf->verifier, p, 8);
  4198. return 0;
  4199. out_overflow:
  4200. print_overflow_msg(__func__, xdr);
  4201. return -EIO;
  4202. }
  4203. static int decode_delegreturn(struct xdr_stream *xdr)
  4204. {
  4205. return decode_op_hdr(xdr, OP_DELEGRETURN);
  4206. }
  4207. #if defined(CONFIG_NFS_V4_1)
  4208. static int decode_exchange_id(struct xdr_stream *xdr,
  4209. struct nfs41_exchange_id_res *res)
  4210. {
  4211. __be32 *p;
  4212. uint32_t dummy;
  4213. char *dummy_str;
  4214. int status;
  4215. struct nfs_client *clp = res->client;
  4216. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  4217. if (status)
  4218. return status;
  4219. p = xdr_inline_decode(xdr, 8);
  4220. if (unlikely(!p))
  4221. goto out_overflow;
  4222. xdr_decode_hyper(p, &clp->cl_ex_clid);
  4223. p = xdr_inline_decode(xdr, 12);
  4224. if (unlikely(!p))
  4225. goto out_overflow;
  4226. clp->cl_seqid = be32_to_cpup(p++);
  4227. clp->cl_exchange_flags = be32_to_cpup(p++);
  4228. /* We ask for SP4_NONE */
  4229. dummy = be32_to_cpup(p);
  4230. if (dummy != SP4_NONE)
  4231. return -EIO;
  4232. /* Throw away minor_id */
  4233. p = xdr_inline_decode(xdr, 8);
  4234. if (unlikely(!p))
  4235. goto out_overflow;
  4236. /* Throw away Major id */
  4237. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4238. if (unlikely(status))
  4239. return status;
  4240. /* Throw away server_scope */
  4241. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4242. if (unlikely(status))
  4243. return status;
  4244. /* Throw away Implementation id array */
  4245. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  4246. if (unlikely(status))
  4247. return status;
  4248. return 0;
  4249. out_overflow:
  4250. print_overflow_msg(__func__, xdr);
  4251. return -EIO;
  4252. }
  4253. static int decode_chan_attrs(struct xdr_stream *xdr,
  4254. struct nfs4_channel_attrs *attrs)
  4255. {
  4256. __be32 *p;
  4257. u32 nr_attrs;
  4258. p = xdr_inline_decode(xdr, 28);
  4259. if (unlikely(!p))
  4260. goto out_overflow;
  4261. attrs->headerpadsz = be32_to_cpup(p++);
  4262. attrs->max_rqst_sz = be32_to_cpup(p++);
  4263. attrs->max_resp_sz = be32_to_cpup(p++);
  4264. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  4265. attrs->max_ops = be32_to_cpup(p++);
  4266. attrs->max_reqs = be32_to_cpup(p++);
  4267. nr_attrs = be32_to_cpup(p);
  4268. if (unlikely(nr_attrs > 1)) {
  4269. printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
  4270. __func__, nr_attrs);
  4271. return -EINVAL;
  4272. }
  4273. if (nr_attrs == 1) {
  4274. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  4275. if (unlikely(!p))
  4276. goto out_overflow;
  4277. }
  4278. return 0;
  4279. out_overflow:
  4280. print_overflow_msg(__func__, xdr);
  4281. return -EIO;
  4282. }
  4283. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  4284. {
  4285. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  4286. }
  4287. static int decode_create_session(struct xdr_stream *xdr,
  4288. struct nfs41_create_session_res *res)
  4289. {
  4290. __be32 *p;
  4291. int status;
  4292. struct nfs_client *clp = res->client;
  4293. struct nfs4_session *session = clp->cl_session;
  4294. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  4295. if (!status)
  4296. status = decode_sessionid(xdr, &session->sess_id);
  4297. if (unlikely(status))
  4298. return status;
  4299. /* seqid, flags */
  4300. p = xdr_inline_decode(xdr, 8);
  4301. if (unlikely(!p))
  4302. goto out_overflow;
  4303. clp->cl_seqid = be32_to_cpup(p++);
  4304. session->flags = be32_to_cpup(p);
  4305. /* Channel attributes */
  4306. status = decode_chan_attrs(xdr, &session->fc_attrs);
  4307. if (!status)
  4308. status = decode_chan_attrs(xdr, &session->bc_attrs);
  4309. return status;
  4310. out_overflow:
  4311. print_overflow_msg(__func__, xdr);
  4312. return -EIO;
  4313. }
  4314. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  4315. {
  4316. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  4317. }
  4318. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  4319. {
  4320. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  4321. }
  4322. #endif /* CONFIG_NFS_V4_1 */
  4323. static int decode_sequence(struct xdr_stream *xdr,
  4324. struct nfs4_sequence_res *res,
  4325. struct rpc_rqst *rqstp)
  4326. {
  4327. #if defined(CONFIG_NFS_V4_1)
  4328. struct nfs4_sessionid id;
  4329. u32 dummy;
  4330. int status;
  4331. __be32 *p;
  4332. if (!res->sr_session)
  4333. return 0;
  4334. status = decode_op_hdr(xdr, OP_SEQUENCE);
  4335. if (!status)
  4336. status = decode_sessionid(xdr, &id);
  4337. if (unlikely(status))
  4338. goto out_err;
  4339. /*
  4340. * If the server returns different values for sessionID, slotID or
  4341. * sequence number, the server is looney tunes.
  4342. */
  4343. status = -EREMOTEIO;
  4344. if (memcmp(id.data, res->sr_session->sess_id.data,
  4345. NFS4_MAX_SESSIONID_LEN)) {
  4346. dprintk("%s Invalid session id\n", __func__);
  4347. goto out_err;
  4348. }
  4349. p = xdr_inline_decode(xdr, 20);
  4350. if (unlikely(!p))
  4351. goto out_overflow;
  4352. /* seqid */
  4353. dummy = be32_to_cpup(p++);
  4354. if (dummy != res->sr_slot->seq_nr) {
  4355. dprintk("%s Invalid sequence number\n", __func__);
  4356. goto out_err;
  4357. }
  4358. /* slot id */
  4359. dummy = be32_to_cpup(p++);
  4360. if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
  4361. dprintk("%s Invalid slot id\n", __func__);
  4362. goto out_err;
  4363. }
  4364. /* highest slot id - currently not processed */
  4365. dummy = be32_to_cpup(p++);
  4366. /* target highest slot id - currently not processed */
  4367. dummy = be32_to_cpup(p++);
  4368. /* result flags */
  4369. res->sr_status_flags = be32_to_cpup(p);
  4370. status = 0;
  4371. out_err:
  4372. res->sr_status = status;
  4373. return status;
  4374. out_overflow:
  4375. print_overflow_msg(__func__, xdr);
  4376. status = -EIO;
  4377. goto out_err;
  4378. #else /* CONFIG_NFS_V4_1 */
  4379. return 0;
  4380. #endif /* CONFIG_NFS_V4_1 */
  4381. }
  4382. #if defined(CONFIG_NFS_V4_1)
  4383. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  4384. struct pnfs_device *pdev)
  4385. {
  4386. __be32 *p;
  4387. uint32_t len, type;
  4388. int status;
  4389. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  4390. if (status) {
  4391. if (status == -ETOOSMALL) {
  4392. p = xdr_inline_decode(xdr, 4);
  4393. if (unlikely(!p))
  4394. goto out_overflow;
  4395. pdev->mincount = be32_to_cpup(p);
  4396. dprintk("%s: Min count too small. mincnt = %u\n",
  4397. __func__, pdev->mincount);
  4398. }
  4399. return status;
  4400. }
  4401. p = xdr_inline_decode(xdr, 8);
  4402. if (unlikely(!p))
  4403. goto out_overflow;
  4404. type = be32_to_cpup(p++);
  4405. if (type != pdev->layout_type) {
  4406. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  4407. __func__, pdev->layout_type, type);
  4408. return -EINVAL;
  4409. }
  4410. /*
  4411. * Get the length of the opaque device_addr4. xdr_read_pages places
  4412. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  4413. * and places the remaining xdr data in xdr_buf->tail
  4414. */
  4415. pdev->mincount = be32_to_cpup(p);
  4416. xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
  4417. /* Parse notification bitmap, verifying that it is zero. */
  4418. p = xdr_inline_decode(xdr, 4);
  4419. if (unlikely(!p))
  4420. goto out_overflow;
  4421. len = be32_to_cpup(p);
  4422. if (len) {
  4423. uint32_t i;
  4424. p = xdr_inline_decode(xdr, 4 * len);
  4425. if (unlikely(!p))
  4426. goto out_overflow;
  4427. for (i = 0; i < len; i++, p++) {
  4428. if (be32_to_cpup(p)) {
  4429. dprintk("%s: notifications not supported\n",
  4430. __func__);
  4431. return -EIO;
  4432. }
  4433. }
  4434. }
  4435. return 0;
  4436. out_overflow:
  4437. print_overflow_msg(__func__, xdr);
  4438. return -EIO;
  4439. }
  4440. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  4441. struct nfs4_layoutget_res *res)
  4442. {
  4443. __be32 *p;
  4444. int status;
  4445. u32 layout_count;
  4446. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  4447. if (status)
  4448. return status;
  4449. p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
  4450. if (unlikely(!p))
  4451. goto out_overflow;
  4452. res->return_on_close = be32_to_cpup(p++);
  4453. p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
  4454. layout_count = be32_to_cpup(p);
  4455. if (!layout_count) {
  4456. dprintk("%s: server responded with empty layout array\n",
  4457. __func__);
  4458. return -EINVAL;
  4459. }
  4460. p = xdr_inline_decode(xdr, 24);
  4461. if (unlikely(!p))
  4462. goto out_overflow;
  4463. p = xdr_decode_hyper(p, &res->range.offset);
  4464. p = xdr_decode_hyper(p, &res->range.length);
  4465. res->range.iomode = be32_to_cpup(p++);
  4466. res->type = be32_to_cpup(p++);
  4467. status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
  4468. if (unlikely(status))
  4469. return status;
  4470. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  4471. __func__,
  4472. (unsigned long)res->range.offset,
  4473. (unsigned long)res->range.length,
  4474. res->range.iomode,
  4475. res->type,
  4476. res->layout.len);
  4477. /* nfs4_proc_layoutget allocated a single page */
  4478. if (res->layout.len > PAGE_SIZE)
  4479. return -ENOMEM;
  4480. memcpy(res->layout.buf, p, res->layout.len);
  4481. if (layout_count > 1) {
  4482. /* We only handle a length one array at the moment. Any
  4483. * further entries are just ignored. Note that this means
  4484. * the client may see a response that is less than the
  4485. * minimum it requested.
  4486. */
  4487. dprintk("%s: server responded with %d layouts, dropping tail\n",
  4488. __func__, layout_count);
  4489. }
  4490. return 0;
  4491. out_overflow:
  4492. print_overflow_msg(__func__, xdr);
  4493. return -EIO;
  4494. }
  4495. #endif /* CONFIG_NFS_V4_1 */
  4496. /*
  4497. * END OF "GENERIC" DECODE ROUTINES.
  4498. */
  4499. /*
  4500. * Decode OPEN_DOWNGRADE response
  4501. */
  4502. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  4503. struct xdr_stream *xdr,
  4504. struct nfs_closeres *res)
  4505. {
  4506. struct compound_hdr hdr;
  4507. int status;
  4508. status = decode_compound_hdr(xdr, &hdr);
  4509. if (status)
  4510. goto out;
  4511. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4512. if (status)
  4513. goto out;
  4514. status = decode_putfh(xdr);
  4515. if (status)
  4516. goto out;
  4517. status = decode_open_downgrade(xdr, res);
  4518. if (status != 0)
  4519. goto out;
  4520. decode_getfattr(xdr, res->fattr, res->server,
  4521. !RPC_IS_ASYNC(rqstp->rq_task));
  4522. out:
  4523. return status;
  4524. }
  4525. /*
  4526. * Decode ACCESS response
  4527. */
  4528. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4529. struct nfs4_accessres *res)
  4530. {
  4531. struct compound_hdr hdr;
  4532. int status;
  4533. status = decode_compound_hdr(xdr, &hdr);
  4534. if (status)
  4535. goto out;
  4536. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4537. if (status)
  4538. goto out;
  4539. status = decode_putfh(xdr);
  4540. if (status != 0)
  4541. goto out;
  4542. status = decode_access(xdr, res);
  4543. if (status != 0)
  4544. goto out;
  4545. decode_getfattr(xdr, res->fattr, res->server,
  4546. !RPC_IS_ASYNC(rqstp->rq_task));
  4547. out:
  4548. return status;
  4549. }
  4550. /*
  4551. * Decode LOOKUP response
  4552. */
  4553. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4554. struct nfs4_lookup_res *res)
  4555. {
  4556. struct compound_hdr hdr;
  4557. int status;
  4558. status = decode_compound_hdr(xdr, &hdr);
  4559. if (status)
  4560. goto out;
  4561. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4562. if (status)
  4563. goto out;
  4564. status = decode_putfh(xdr);
  4565. if (status)
  4566. goto out;
  4567. status = decode_lookup(xdr);
  4568. if (status)
  4569. goto out;
  4570. status = decode_getfh(xdr, res->fh);
  4571. if (status)
  4572. goto out;
  4573. status = decode_getfattr(xdr, res->fattr, res->server
  4574. ,!RPC_IS_ASYNC(rqstp->rq_task));
  4575. out:
  4576. return status;
  4577. }
  4578. /*
  4579. * Decode LOOKUP_ROOT response
  4580. */
  4581. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  4582. struct xdr_stream *xdr,
  4583. struct nfs4_lookup_res *res)
  4584. {
  4585. struct compound_hdr hdr;
  4586. int status;
  4587. status = decode_compound_hdr(xdr, &hdr);
  4588. if (status)
  4589. goto out;
  4590. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4591. if (status)
  4592. goto out;
  4593. status = decode_putrootfh(xdr);
  4594. if (status)
  4595. goto out;
  4596. status = decode_getfh(xdr, res->fh);
  4597. if (status == 0)
  4598. status = decode_getfattr(xdr, res->fattr, res->server,
  4599. !RPC_IS_ASYNC(rqstp->rq_task));
  4600. out:
  4601. return status;
  4602. }
  4603. /*
  4604. * Decode REMOVE response
  4605. */
  4606. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4607. struct nfs_removeres *res)
  4608. {
  4609. struct compound_hdr hdr;
  4610. int status;
  4611. status = decode_compound_hdr(xdr, &hdr);
  4612. if (status)
  4613. goto out;
  4614. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4615. if (status)
  4616. goto out;
  4617. status = decode_putfh(xdr);
  4618. if (status)
  4619. goto out;
  4620. status = decode_remove(xdr, &res->cinfo);
  4621. if (status)
  4622. goto out;
  4623. decode_getfattr(xdr, res->dir_attr, res->server,
  4624. !RPC_IS_ASYNC(rqstp->rq_task));
  4625. out:
  4626. return status;
  4627. }
  4628. /*
  4629. * Decode RENAME response
  4630. */
  4631. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4632. struct nfs_renameres *res)
  4633. {
  4634. struct compound_hdr hdr;
  4635. int status;
  4636. status = decode_compound_hdr(xdr, &hdr);
  4637. if (status)
  4638. goto out;
  4639. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4640. if (status)
  4641. goto out;
  4642. status = decode_putfh(xdr);
  4643. if (status)
  4644. goto out;
  4645. status = decode_savefh(xdr);
  4646. if (status)
  4647. goto out;
  4648. status = decode_putfh(xdr);
  4649. if (status)
  4650. goto out;
  4651. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  4652. if (status)
  4653. goto out;
  4654. /* Current FH is target directory */
  4655. if (decode_getfattr(xdr, res->new_fattr, res->server,
  4656. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4657. goto out;
  4658. status = decode_restorefh(xdr);
  4659. if (status)
  4660. goto out;
  4661. decode_getfattr(xdr, res->old_fattr, res->server,
  4662. !RPC_IS_ASYNC(rqstp->rq_task));
  4663. out:
  4664. return status;
  4665. }
  4666. /*
  4667. * Decode LINK response
  4668. */
  4669. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4670. struct nfs4_link_res *res)
  4671. {
  4672. struct compound_hdr hdr;
  4673. int status;
  4674. status = decode_compound_hdr(xdr, &hdr);
  4675. if (status)
  4676. goto out;
  4677. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4678. if (status)
  4679. goto out;
  4680. status = decode_putfh(xdr);
  4681. if (status)
  4682. goto out;
  4683. status = decode_savefh(xdr);
  4684. if (status)
  4685. goto out;
  4686. status = decode_putfh(xdr);
  4687. if (status)
  4688. goto out;
  4689. status = decode_link(xdr, &res->cinfo);
  4690. if (status)
  4691. goto out;
  4692. /*
  4693. * Note order: OP_LINK leaves the directory as the current
  4694. * filehandle.
  4695. */
  4696. if (decode_getfattr(xdr, res->dir_attr, res->server,
  4697. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4698. goto out;
  4699. status = decode_restorefh(xdr);
  4700. if (status)
  4701. goto out;
  4702. decode_getfattr(xdr, res->fattr, res->server,
  4703. !RPC_IS_ASYNC(rqstp->rq_task));
  4704. out:
  4705. return status;
  4706. }
  4707. /*
  4708. * Decode CREATE response
  4709. */
  4710. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4711. struct nfs4_create_res *res)
  4712. {
  4713. struct compound_hdr hdr;
  4714. int status;
  4715. status = decode_compound_hdr(xdr, &hdr);
  4716. if (status)
  4717. goto out;
  4718. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4719. if (status)
  4720. goto out;
  4721. status = decode_putfh(xdr);
  4722. if (status)
  4723. goto out;
  4724. status = decode_savefh(xdr);
  4725. if (status)
  4726. goto out;
  4727. status = decode_create(xdr, &res->dir_cinfo);
  4728. if (status)
  4729. goto out;
  4730. status = decode_getfh(xdr, res->fh);
  4731. if (status)
  4732. goto out;
  4733. if (decode_getfattr(xdr, res->fattr, res->server,
  4734. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4735. goto out;
  4736. status = decode_restorefh(xdr);
  4737. if (status)
  4738. goto out;
  4739. decode_getfattr(xdr, res->dir_fattr, res->server,
  4740. !RPC_IS_ASYNC(rqstp->rq_task));
  4741. out:
  4742. return status;
  4743. }
  4744. /*
  4745. * Decode SYMLINK response
  4746. */
  4747. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4748. struct nfs4_create_res *res)
  4749. {
  4750. return nfs4_xdr_dec_create(rqstp, xdr, res);
  4751. }
  4752. /*
  4753. * Decode GETATTR response
  4754. */
  4755. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4756. struct nfs4_getattr_res *res)
  4757. {
  4758. struct compound_hdr hdr;
  4759. int status;
  4760. status = decode_compound_hdr(xdr, &hdr);
  4761. if (status)
  4762. goto out;
  4763. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4764. if (status)
  4765. goto out;
  4766. status = decode_putfh(xdr);
  4767. if (status)
  4768. goto out;
  4769. status = decode_getfattr(xdr, res->fattr, res->server,
  4770. !RPC_IS_ASYNC(rqstp->rq_task));
  4771. out:
  4772. return status;
  4773. }
  4774. /*
  4775. * Encode an SETACL request
  4776. */
  4777. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  4778. struct nfs_setaclargs *args)
  4779. {
  4780. struct compound_hdr hdr = {
  4781. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  4782. };
  4783. encode_compound_hdr(xdr, req, &hdr);
  4784. encode_sequence(xdr, &args->seq_args, &hdr);
  4785. encode_putfh(xdr, args->fh, &hdr);
  4786. encode_setacl(xdr, args, &hdr);
  4787. encode_nops(&hdr);
  4788. }
  4789. /*
  4790. * Decode SETACL response
  4791. */
  4792. static int
  4793. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4794. struct nfs_setaclres *res)
  4795. {
  4796. struct compound_hdr hdr;
  4797. int status;
  4798. status = decode_compound_hdr(xdr, &hdr);
  4799. if (status)
  4800. goto out;
  4801. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4802. if (status)
  4803. goto out;
  4804. status = decode_putfh(xdr);
  4805. if (status)
  4806. goto out;
  4807. status = decode_setattr(xdr);
  4808. out:
  4809. return status;
  4810. }
  4811. /*
  4812. * Decode GETACL response
  4813. */
  4814. static int
  4815. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4816. struct nfs_getaclres *res)
  4817. {
  4818. struct compound_hdr hdr;
  4819. int status;
  4820. status = decode_compound_hdr(xdr, &hdr);
  4821. if (status)
  4822. goto out;
  4823. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4824. if (status)
  4825. goto out;
  4826. status = decode_putfh(xdr);
  4827. if (status)
  4828. goto out;
  4829. status = decode_getacl(xdr, rqstp, &res->acl_len);
  4830. out:
  4831. return status;
  4832. }
  4833. /*
  4834. * Decode CLOSE response
  4835. */
  4836. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4837. struct nfs_closeres *res)
  4838. {
  4839. struct compound_hdr hdr;
  4840. int status;
  4841. status = decode_compound_hdr(xdr, &hdr);
  4842. if (status)
  4843. goto out;
  4844. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4845. if (status)
  4846. goto out;
  4847. status = decode_putfh(xdr);
  4848. if (status)
  4849. goto out;
  4850. status = decode_close(xdr, res);
  4851. if (status != 0)
  4852. goto out;
  4853. /*
  4854. * Note: Server may do delete on close for this file
  4855. * in which case the getattr call will fail with
  4856. * an ESTALE error. Shouldn't be a problem,
  4857. * though, since fattr->valid will remain unset.
  4858. */
  4859. decode_getfattr(xdr, res->fattr, res->server,
  4860. !RPC_IS_ASYNC(rqstp->rq_task));
  4861. out:
  4862. return status;
  4863. }
  4864. /*
  4865. * Decode OPEN response
  4866. */
  4867. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4868. struct nfs_openres *res)
  4869. {
  4870. struct compound_hdr hdr;
  4871. int status;
  4872. status = decode_compound_hdr(xdr, &hdr);
  4873. if (status)
  4874. goto out;
  4875. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4876. if (status)
  4877. goto out;
  4878. status = decode_putfh(xdr);
  4879. if (status)
  4880. goto out;
  4881. status = decode_savefh(xdr);
  4882. if (status)
  4883. goto out;
  4884. status = decode_open(xdr, res);
  4885. if (status)
  4886. goto out;
  4887. if (decode_getfh(xdr, &res->fh) != 0)
  4888. goto out;
  4889. if (decode_getfattr(xdr, res->f_attr, res->server,
  4890. !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
  4891. goto out;
  4892. if (decode_restorefh(xdr) != 0)
  4893. goto out;
  4894. decode_getfattr(xdr, res->dir_attr, res->server,
  4895. !RPC_IS_ASYNC(rqstp->rq_task));
  4896. out:
  4897. return status;
  4898. }
  4899. /*
  4900. * Decode OPEN_CONFIRM response
  4901. */
  4902. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  4903. struct xdr_stream *xdr,
  4904. struct nfs_open_confirmres *res)
  4905. {
  4906. struct compound_hdr hdr;
  4907. int status;
  4908. status = decode_compound_hdr(xdr, &hdr);
  4909. if (status)
  4910. goto out;
  4911. status = decode_putfh(xdr);
  4912. if (status)
  4913. goto out;
  4914. status = decode_open_confirm(xdr, res);
  4915. out:
  4916. return status;
  4917. }
  4918. /*
  4919. * Decode OPEN response
  4920. */
  4921. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  4922. struct xdr_stream *xdr,
  4923. struct nfs_openres *res)
  4924. {
  4925. struct compound_hdr hdr;
  4926. int status;
  4927. status = decode_compound_hdr(xdr, &hdr);
  4928. if (status)
  4929. goto out;
  4930. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4931. if (status)
  4932. goto out;
  4933. status = decode_putfh(xdr);
  4934. if (status)
  4935. goto out;
  4936. status = decode_open(xdr, res);
  4937. if (status)
  4938. goto out;
  4939. decode_getfattr(xdr, res->f_attr, res->server,
  4940. !RPC_IS_ASYNC(rqstp->rq_task));
  4941. out:
  4942. return status;
  4943. }
  4944. /*
  4945. * Decode SETATTR response
  4946. */
  4947. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  4948. struct xdr_stream *xdr,
  4949. struct nfs_setattrres *res)
  4950. {
  4951. struct compound_hdr hdr;
  4952. int status;
  4953. status = decode_compound_hdr(xdr, &hdr);
  4954. if (status)
  4955. goto out;
  4956. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4957. if (status)
  4958. goto out;
  4959. status = decode_putfh(xdr);
  4960. if (status)
  4961. goto out;
  4962. status = decode_setattr(xdr);
  4963. if (status)
  4964. goto out;
  4965. decode_getfattr(xdr, res->fattr, res->server,
  4966. !RPC_IS_ASYNC(rqstp->rq_task));
  4967. out:
  4968. return status;
  4969. }
  4970. /*
  4971. * Decode LOCK response
  4972. */
  4973. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4974. struct nfs_lock_res *res)
  4975. {
  4976. struct compound_hdr hdr;
  4977. int status;
  4978. status = decode_compound_hdr(xdr, &hdr);
  4979. if (status)
  4980. goto out;
  4981. status = decode_sequence(xdr, &res->seq_res, rqstp);
  4982. if (status)
  4983. goto out;
  4984. status = decode_putfh(xdr);
  4985. if (status)
  4986. goto out;
  4987. status = decode_lock(xdr, res);
  4988. out:
  4989. return status;
  4990. }
  4991. /*
  4992. * Decode LOCKT response
  4993. */
  4994. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  4995. struct nfs_lockt_res *res)
  4996. {
  4997. struct compound_hdr hdr;
  4998. int status;
  4999. status = decode_compound_hdr(xdr, &hdr);
  5000. if (status)
  5001. goto out;
  5002. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5003. if (status)
  5004. goto out;
  5005. status = decode_putfh(xdr);
  5006. if (status)
  5007. goto out;
  5008. status = decode_lockt(xdr, res);
  5009. out:
  5010. return status;
  5011. }
  5012. /*
  5013. * Decode LOCKU response
  5014. */
  5015. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5016. struct nfs_locku_res *res)
  5017. {
  5018. struct compound_hdr hdr;
  5019. int status;
  5020. status = decode_compound_hdr(xdr, &hdr);
  5021. if (status)
  5022. goto out;
  5023. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5024. if (status)
  5025. goto out;
  5026. status = decode_putfh(xdr);
  5027. if (status)
  5028. goto out;
  5029. status = decode_locku(xdr, res);
  5030. out:
  5031. return status;
  5032. }
  5033. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  5034. struct xdr_stream *xdr, void *dummy)
  5035. {
  5036. struct compound_hdr hdr;
  5037. int status;
  5038. status = decode_compound_hdr(xdr, &hdr);
  5039. if (!status)
  5040. status = decode_release_lockowner(xdr);
  5041. return status;
  5042. }
  5043. /*
  5044. * Decode READLINK response
  5045. */
  5046. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  5047. struct xdr_stream *xdr,
  5048. struct nfs4_readlink_res *res)
  5049. {
  5050. struct compound_hdr hdr;
  5051. int status;
  5052. status = decode_compound_hdr(xdr, &hdr);
  5053. if (status)
  5054. goto out;
  5055. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5056. if (status)
  5057. goto out;
  5058. status = decode_putfh(xdr);
  5059. if (status)
  5060. goto out;
  5061. status = decode_readlink(xdr, rqstp);
  5062. out:
  5063. return status;
  5064. }
  5065. /*
  5066. * Decode READDIR response
  5067. */
  5068. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5069. struct nfs4_readdir_res *res)
  5070. {
  5071. struct compound_hdr hdr;
  5072. int status;
  5073. status = decode_compound_hdr(xdr, &hdr);
  5074. if (status)
  5075. goto out;
  5076. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5077. if (status)
  5078. goto out;
  5079. status = decode_putfh(xdr);
  5080. if (status)
  5081. goto out;
  5082. status = decode_readdir(xdr, rqstp, res);
  5083. out:
  5084. return status;
  5085. }
  5086. /*
  5087. * Decode Read response
  5088. */
  5089. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5090. struct nfs_readres *res)
  5091. {
  5092. struct compound_hdr hdr;
  5093. int status;
  5094. status = decode_compound_hdr(xdr, &hdr);
  5095. if (status)
  5096. goto out;
  5097. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5098. if (status)
  5099. goto out;
  5100. status = decode_putfh(xdr);
  5101. if (status)
  5102. goto out;
  5103. status = decode_read(xdr, rqstp, res);
  5104. if (!status)
  5105. status = res->count;
  5106. out:
  5107. return status;
  5108. }
  5109. /*
  5110. * Decode WRITE response
  5111. */
  5112. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5113. struct nfs_writeres *res)
  5114. {
  5115. struct compound_hdr hdr;
  5116. int status;
  5117. status = decode_compound_hdr(xdr, &hdr);
  5118. if (status)
  5119. goto out;
  5120. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5121. if (status)
  5122. goto out;
  5123. status = decode_putfh(xdr);
  5124. if (status)
  5125. goto out;
  5126. status = decode_write(xdr, res);
  5127. if (status)
  5128. goto out;
  5129. decode_getfattr(xdr, res->fattr, res->server,
  5130. !RPC_IS_ASYNC(rqstp->rq_task));
  5131. if (!status)
  5132. status = res->count;
  5133. out:
  5134. return status;
  5135. }
  5136. /*
  5137. * Decode COMMIT response
  5138. */
  5139. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5140. struct nfs_writeres *res)
  5141. {
  5142. struct compound_hdr hdr;
  5143. int status;
  5144. status = decode_compound_hdr(xdr, &hdr);
  5145. if (status)
  5146. goto out;
  5147. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5148. if (status)
  5149. goto out;
  5150. status = decode_putfh(xdr);
  5151. if (status)
  5152. goto out;
  5153. status = decode_commit(xdr, res);
  5154. if (status)
  5155. goto out;
  5156. decode_getfattr(xdr, res->fattr, res->server,
  5157. !RPC_IS_ASYNC(rqstp->rq_task));
  5158. out:
  5159. return status;
  5160. }
  5161. /*
  5162. * Decode FSINFO response
  5163. */
  5164. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  5165. struct nfs4_fsinfo_res *res)
  5166. {
  5167. struct compound_hdr hdr;
  5168. int status;
  5169. status = decode_compound_hdr(xdr, &hdr);
  5170. if (!status)
  5171. status = decode_sequence(xdr, &res->seq_res, req);
  5172. if (!status)
  5173. status = decode_putfh(xdr);
  5174. if (!status)
  5175. status = decode_fsinfo(xdr, res->fsinfo);
  5176. return status;
  5177. }
  5178. /*
  5179. * Decode PATHCONF response
  5180. */
  5181. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  5182. struct nfs4_pathconf_res *res)
  5183. {
  5184. struct compound_hdr hdr;
  5185. int status;
  5186. status = decode_compound_hdr(xdr, &hdr);
  5187. if (!status)
  5188. status = decode_sequence(xdr, &res->seq_res, req);
  5189. if (!status)
  5190. status = decode_putfh(xdr);
  5191. if (!status)
  5192. status = decode_pathconf(xdr, res->pathconf);
  5193. return status;
  5194. }
  5195. /*
  5196. * Decode STATFS response
  5197. */
  5198. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  5199. struct nfs4_statfs_res *res)
  5200. {
  5201. struct compound_hdr hdr;
  5202. int status;
  5203. status = decode_compound_hdr(xdr, &hdr);
  5204. if (!status)
  5205. status = decode_sequence(xdr, &res->seq_res, req);
  5206. if (!status)
  5207. status = decode_putfh(xdr);
  5208. if (!status)
  5209. status = decode_statfs(xdr, res->fsstat);
  5210. return status;
  5211. }
  5212. /*
  5213. * Decode GETATTR_BITMAP response
  5214. */
  5215. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  5216. struct xdr_stream *xdr,
  5217. struct nfs4_server_caps_res *res)
  5218. {
  5219. struct compound_hdr hdr;
  5220. int status;
  5221. status = decode_compound_hdr(xdr, &hdr);
  5222. if (status)
  5223. goto out;
  5224. status = decode_sequence(xdr, &res->seq_res, req);
  5225. if (status)
  5226. goto out;
  5227. status = decode_putfh(xdr);
  5228. if (status)
  5229. goto out;
  5230. status = decode_server_caps(xdr, res);
  5231. out:
  5232. return status;
  5233. }
  5234. /*
  5235. * Decode RENEW response
  5236. */
  5237. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5238. void *__unused)
  5239. {
  5240. struct compound_hdr hdr;
  5241. int status;
  5242. status = decode_compound_hdr(xdr, &hdr);
  5243. if (!status)
  5244. status = decode_renew(xdr);
  5245. return status;
  5246. }
  5247. /*
  5248. * Decode SETCLIENTID response
  5249. */
  5250. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  5251. struct xdr_stream *xdr,
  5252. struct nfs4_setclientid_res *res)
  5253. {
  5254. struct compound_hdr hdr;
  5255. int status;
  5256. status = decode_compound_hdr(xdr, &hdr);
  5257. if (!status)
  5258. status = decode_setclientid(xdr, res);
  5259. return status;
  5260. }
  5261. /*
  5262. * Decode SETCLIENTID_CONFIRM response
  5263. */
  5264. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  5265. struct xdr_stream *xdr,
  5266. struct nfs_fsinfo *fsinfo)
  5267. {
  5268. struct compound_hdr hdr;
  5269. int status;
  5270. status = decode_compound_hdr(xdr, &hdr);
  5271. if (!status)
  5272. status = decode_setclientid_confirm(xdr);
  5273. if (!status)
  5274. status = decode_putrootfh(xdr);
  5275. if (!status)
  5276. status = decode_fsinfo(xdr, fsinfo);
  5277. return status;
  5278. }
  5279. /*
  5280. * Decode DELEGRETURN response
  5281. */
  5282. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  5283. struct xdr_stream *xdr,
  5284. struct nfs4_delegreturnres *res)
  5285. {
  5286. struct compound_hdr hdr;
  5287. int status;
  5288. status = decode_compound_hdr(xdr, &hdr);
  5289. if (status)
  5290. goto out;
  5291. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5292. if (status)
  5293. goto out;
  5294. status = decode_putfh(xdr);
  5295. if (status != 0)
  5296. goto out;
  5297. status = decode_delegreturn(xdr);
  5298. if (status != 0)
  5299. goto out;
  5300. decode_getfattr(xdr, res->fattr, res->server,
  5301. !RPC_IS_ASYNC(rqstp->rq_task));
  5302. out:
  5303. return status;
  5304. }
  5305. /*
  5306. * Decode FS_LOCATIONS response
  5307. */
  5308. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  5309. struct xdr_stream *xdr,
  5310. struct nfs4_fs_locations_res *res)
  5311. {
  5312. struct compound_hdr hdr;
  5313. int status;
  5314. status = decode_compound_hdr(xdr, &hdr);
  5315. if (status)
  5316. goto out;
  5317. status = decode_sequence(xdr, &res->seq_res, req);
  5318. if (status)
  5319. goto out;
  5320. status = decode_putfh(xdr);
  5321. if (status)
  5322. goto out;
  5323. status = decode_lookup(xdr);
  5324. if (status)
  5325. goto out;
  5326. xdr_enter_page(xdr, PAGE_SIZE);
  5327. status = decode_getfattr(xdr, &res->fs_locations->fattr,
  5328. res->fs_locations->server,
  5329. !RPC_IS_ASYNC(req->rq_task));
  5330. out:
  5331. return status;
  5332. }
  5333. #if defined(CONFIG_NFS_V4_1)
  5334. /*
  5335. * Decode EXCHANGE_ID response
  5336. */
  5337. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  5338. struct xdr_stream *xdr,
  5339. void *res)
  5340. {
  5341. struct compound_hdr hdr;
  5342. int status;
  5343. status = decode_compound_hdr(xdr, &hdr);
  5344. if (!status)
  5345. status = decode_exchange_id(xdr, res);
  5346. return status;
  5347. }
  5348. /*
  5349. * Decode CREATE_SESSION response
  5350. */
  5351. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  5352. struct xdr_stream *xdr,
  5353. struct nfs41_create_session_res *res)
  5354. {
  5355. struct compound_hdr hdr;
  5356. int status;
  5357. status = decode_compound_hdr(xdr, &hdr);
  5358. if (!status)
  5359. status = decode_create_session(xdr, res);
  5360. return status;
  5361. }
  5362. /*
  5363. * Decode DESTROY_SESSION response
  5364. */
  5365. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  5366. struct xdr_stream *xdr,
  5367. void *res)
  5368. {
  5369. struct compound_hdr hdr;
  5370. int status;
  5371. status = decode_compound_hdr(xdr, &hdr);
  5372. if (!status)
  5373. status = decode_destroy_session(xdr, res);
  5374. return status;
  5375. }
  5376. /*
  5377. * Decode SEQUENCE response
  5378. */
  5379. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  5380. struct xdr_stream *xdr,
  5381. struct nfs4_sequence_res *res)
  5382. {
  5383. struct compound_hdr hdr;
  5384. int status;
  5385. status = decode_compound_hdr(xdr, &hdr);
  5386. if (!status)
  5387. status = decode_sequence(xdr, res, rqstp);
  5388. return status;
  5389. }
  5390. /*
  5391. * Decode GET_LEASE_TIME response
  5392. */
  5393. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  5394. struct xdr_stream *xdr,
  5395. struct nfs4_get_lease_time_res *res)
  5396. {
  5397. struct compound_hdr hdr;
  5398. int status;
  5399. status = decode_compound_hdr(xdr, &hdr);
  5400. if (!status)
  5401. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  5402. if (!status)
  5403. status = decode_putrootfh(xdr);
  5404. if (!status)
  5405. status = decode_fsinfo(xdr, res->lr_fsinfo);
  5406. return status;
  5407. }
  5408. /*
  5409. * Decode RECLAIM_COMPLETE response
  5410. */
  5411. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  5412. struct xdr_stream *xdr,
  5413. struct nfs41_reclaim_complete_res *res)
  5414. {
  5415. struct compound_hdr hdr;
  5416. int status;
  5417. status = decode_compound_hdr(xdr, &hdr);
  5418. if (!status)
  5419. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5420. if (!status)
  5421. status = decode_reclaim_complete(xdr, (void *)NULL);
  5422. return status;
  5423. }
  5424. /*
  5425. * Decode GETDEVINFO response
  5426. */
  5427. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  5428. struct xdr_stream *xdr,
  5429. struct nfs4_getdeviceinfo_res *res)
  5430. {
  5431. struct compound_hdr hdr;
  5432. int status;
  5433. status = decode_compound_hdr(xdr, &hdr);
  5434. if (status != 0)
  5435. goto out;
  5436. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5437. if (status != 0)
  5438. goto out;
  5439. status = decode_getdeviceinfo(xdr, res->pdev);
  5440. out:
  5441. return status;
  5442. }
  5443. /*
  5444. * Decode LAYOUTGET response
  5445. */
  5446. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  5447. struct xdr_stream *xdr,
  5448. struct nfs4_layoutget_res *res)
  5449. {
  5450. struct compound_hdr hdr;
  5451. int status;
  5452. status = decode_compound_hdr(xdr, &hdr);
  5453. if (status)
  5454. goto out;
  5455. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5456. if (status)
  5457. goto out;
  5458. status = decode_putfh(xdr);
  5459. if (status)
  5460. goto out;
  5461. status = decode_layoutget(xdr, rqstp, res);
  5462. out:
  5463. return status;
  5464. }
  5465. #endif /* CONFIG_NFS_V4_1 */
  5466. /**
  5467. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  5468. * the local page cache.
  5469. * @xdr: XDR stream where entry resides
  5470. * @entry: buffer to fill in with entry data
  5471. * @plus: boolean indicating whether this should be a readdirplus entry
  5472. *
  5473. * Returns zero if successful, otherwise a negative errno value is
  5474. * returned.
  5475. *
  5476. * This function is not invoked during READDIR reply decoding, but
  5477. * rather whenever an application invokes the getdents(2) system call
  5478. * on a directory already in our cache.
  5479. */
  5480. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  5481. int plus)
  5482. {
  5483. uint32_t bitmap[2] = {0};
  5484. uint32_t len;
  5485. __be32 *p = xdr_inline_decode(xdr, 4);
  5486. if (unlikely(!p))
  5487. goto out_overflow;
  5488. if (!ntohl(*p++)) {
  5489. p = xdr_inline_decode(xdr, 4);
  5490. if (unlikely(!p))
  5491. goto out_overflow;
  5492. if (!ntohl(*p++))
  5493. return -EAGAIN;
  5494. entry->eof = 1;
  5495. return -EBADCOOKIE;
  5496. }
  5497. p = xdr_inline_decode(xdr, 12);
  5498. if (unlikely(!p))
  5499. goto out_overflow;
  5500. entry->prev_cookie = entry->cookie;
  5501. p = xdr_decode_hyper(p, &entry->cookie);
  5502. entry->len = ntohl(*p++);
  5503. p = xdr_inline_decode(xdr, entry->len);
  5504. if (unlikely(!p))
  5505. goto out_overflow;
  5506. entry->name = (const char *) p;
  5507. /*
  5508. * In case the server doesn't return an inode number,
  5509. * we fake one here. (We don't use inode number 0,
  5510. * since glibc seems to choke on it...)
  5511. */
  5512. entry->ino = 1;
  5513. entry->fattr->valid = 0;
  5514. if (decode_attr_bitmap(xdr, bitmap) < 0)
  5515. goto out_overflow;
  5516. if (decode_attr_length(xdr, &len, &p) < 0)
  5517. goto out_overflow;
  5518. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  5519. entry->server, 1) < 0)
  5520. goto out_overflow;
  5521. if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  5522. entry->ino = entry->fattr->fileid;
  5523. entry->d_type = DT_UNKNOWN;
  5524. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  5525. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  5526. if (verify_attr_len(xdr, p, len) < 0)
  5527. goto out_overflow;
  5528. return 0;
  5529. out_overflow:
  5530. print_overflow_msg(__func__, xdr);
  5531. return -EAGAIN;
  5532. }
  5533. /*
  5534. * We need to translate between nfs status return values and
  5535. * the local errno values which may not be the same.
  5536. */
  5537. static struct {
  5538. int stat;
  5539. int errno;
  5540. } nfs_errtbl[] = {
  5541. { NFS4_OK, 0 },
  5542. { NFS4ERR_PERM, -EPERM },
  5543. { NFS4ERR_NOENT, -ENOENT },
  5544. { NFS4ERR_IO, -errno_NFSERR_IO},
  5545. { NFS4ERR_NXIO, -ENXIO },
  5546. { NFS4ERR_ACCESS, -EACCES },
  5547. { NFS4ERR_EXIST, -EEXIST },
  5548. { NFS4ERR_XDEV, -EXDEV },
  5549. { NFS4ERR_NOTDIR, -ENOTDIR },
  5550. { NFS4ERR_ISDIR, -EISDIR },
  5551. { NFS4ERR_INVAL, -EINVAL },
  5552. { NFS4ERR_FBIG, -EFBIG },
  5553. { NFS4ERR_NOSPC, -ENOSPC },
  5554. { NFS4ERR_ROFS, -EROFS },
  5555. { NFS4ERR_MLINK, -EMLINK },
  5556. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  5557. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  5558. { NFS4ERR_DQUOT, -EDQUOT },
  5559. { NFS4ERR_STALE, -ESTALE },
  5560. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  5561. { NFS4ERR_BADOWNER, -EINVAL },
  5562. { NFS4ERR_BADNAME, -EINVAL },
  5563. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  5564. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  5565. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  5566. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  5567. { NFS4ERR_BADTYPE, -EBADTYPE },
  5568. { NFS4ERR_LOCKED, -EAGAIN },
  5569. { NFS4ERR_SYMLINK, -ELOOP },
  5570. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  5571. { NFS4ERR_DEADLOCK, -EDEADLK },
  5572. { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
  5573. * to be handled by a
  5574. * middle-layer.
  5575. */
  5576. { -1, -EIO }
  5577. };
  5578. /*
  5579. * Convert an NFS error code to a local one.
  5580. * This one is used jointly by NFSv2 and NFSv3.
  5581. */
  5582. static int
  5583. nfs4_stat_to_errno(int stat)
  5584. {
  5585. int i;
  5586. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  5587. if (nfs_errtbl[i].stat == stat)
  5588. return nfs_errtbl[i].errno;
  5589. }
  5590. if (stat <= 10000 || stat > 10100) {
  5591. /* The server is looney tunes. */
  5592. return -EREMOTEIO;
  5593. }
  5594. /* If we cannot translate the error, the recovery routines should
  5595. * handle it.
  5596. * Note: remaining NFSv4 error codes have values > 10000, so should
  5597. * not conflict with native Linux error codes.
  5598. */
  5599. return -stat;
  5600. }
  5601. #define PROC(proc, argtype, restype) \
  5602. [NFSPROC4_CLNT_##proc] = { \
  5603. .p_proc = NFSPROC4_COMPOUND, \
  5604. .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
  5605. .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
  5606. .p_arglen = NFS4_##argtype##_sz, \
  5607. .p_replen = NFS4_##restype##_sz, \
  5608. .p_statidx = NFSPROC4_CLNT_##proc, \
  5609. .p_name = #proc, \
  5610. }
  5611. struct rpc_procinfo nfs4_procedures[] = {
  5612. PROC(READ, enc_read, dec_read),
  5613. PROC(WRITE, enc_write, dec_write),
  5614. PROC(COMMIT, enc_commit, dec_commit),
  5615. PROC(OPEN, enc_open, dec_open),
  5616. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  5617. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  5618. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  5619. PROC(CLOSE, enc_close, dec_close),
  5620. PROC(SETATTR, enc_setattr, dec_setattr),
  5621. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  5622. PROC(RENEW, enc_renew, dec_renew),
  5623. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  5624. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  5625. PROC(LOCK, enc_lock, dec_lock),
  5626. PROC(LOCKT, enc_lockt, dec_lockt),
  5627. PROC(LOCKU, enc_locku, dec_locku),
  5628. PROC(ACCESS, enc_access, dec_access),
  5629. PROC(GETATTR, enc_getattr, dec_getattr),
  5630. PROC(LOOKUP, enc_lookup, dec_lookup),
  5631. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  5632. PROC(REMOVE, enc_remove, dec_remove),
  5633. PROC(RENAME, enc_rename, dec_rename),
  5634. PROC(LINK, enc_link, dec_link),
  5635. PROC(SYMLINK, enc_symlink, dec_symlink),
  5636. PROC(CREATE, enc_create, dec_create),
  5637. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  5638. PROC(STATFS, enc_statfs, dec_statfs),
  5639. PROC(READLINK, enc_readlink, dec_readlink),
  5640. PROC(READDIR, enc_readdir, dec_readdir),
  5641. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  5642. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  5643. PROC(GETACL, enc_getacl, dec_getacl),
  5644. PROC(SETACL, enc_setacl, dec_setacl),
  5645. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  5646. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  5647. #if defined(CONFIG_NFS_V4_1)
  5648. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  5649. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  5650. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  5651. PROC(SEQUENCE, enc_sequence, dec_sequence),
  5652. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  5653. PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
  5654. PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  5655. PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
  5656. #endif /* CONFIG_NFS_V4_1 */
  5657. };
  5658. struct rpc_version nfs_version4 = {
  5659. .number = 4,
  5660. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  5661. .procs = nfs4_procedures
  5662. };
  5663. /*
  5664. * Local variables:
  5665. * c-basic-offset: 8
  5666. * End:
  5667. */