nfs4xdr.c 200 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676
  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/module.h>
  47. #include <linux/utsname.h>
  48. #include <linux/sunrpc/clnt.h>
  49. #include <linux/sunrpc/msg_prot.h>
  50. #include <linux/sunrpc/gss_api.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs4.h>
  53. #include <linux/nfs_fs.h>
  54. #include <linux/fs_struct.h>
  55. #include "nfs4_fs.h"
  56. #include "internal.h"
  57. #include "nfs4idmap.h"
  58. #include "nfs4session.h"
  59. #include "pnfs.h"
  60. #include "netns.h"
  61. #define NFSDBG_FACILITY NFSDBG_XDR
  62. /* Mapping from NFS error code to "errno" error code. */
  63. #define errno_NFSERR_IO EIO
  64. static int nfs4_stat_to_errno(int);
  65. /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
  66. #ifdef DEBUG
  67. #define NFS4_MAXTAGLEN 20
  68. #else
  69. #define NFS4_MAXTAGLEN 0
  70. #endif
  71. /* lock,open owner id:
  72. * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
  73. */
  74. #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
  75. #define lock_owner_id_maxsz (1 + 1 + 4)
  76. #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  77. #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  78. #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
  79. #define op_encode_hdr_maxsz (1)
  80. #define op_decode_hdr_maxsz (2)
  81. #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  82. #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  83. #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  84. #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  85. #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
  86. (NFS4_FHSIZE >> 2))
  87. #define decode_putfh_maxsz (op_decode_hdr_maxsz)
  88. #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
  89. #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
  90. #define encode_getfh_maxsz (op_encode_hdr_maxsz)
  91. #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
  92. ((3+NFS4_FHSIZE) >> 2))
  93. #define nfs4_fattr_bitmap_maxsz 4
  94. #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
  95. #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
  96. #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
  97. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  98. #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  99. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  100. /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
  101. #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
  102. #else
  103. #define nfs4_label_maxsz 0
  104. #endif
  105. /* We support only one layout type per file system */
  106. #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
  107. /* This is based on getfattr, which uses the most attributes: */
  108. #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
  109. 3 + 3 + 3 + nfs4_owner_maxsz + \
  110. nfs4_group_maxsz + nfs4_label_maxsz + \
  111. decode_mdsthreshold_maxsz))
  112. #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
  113. nfs4_fattr_value_maxsz)
  114. #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
  115. #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
  116. 1 + 2 + 1 + \
  117. nfs4_owner_maxsz + \
  118. nfs4_group_maxsz + \
  119. nfs4_label_maxsz + \
  120. 4 + 4)
  121. #define encode_savefh_maxsz (op_encode_hdr_maxsz)
  122. #define decode_savefh_maxsz (op_decode_hdr_maxsz)
  123. #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
  124. #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
  125. #define encode_fsinfo_maxsz (encode_getattr_maxsz)
  126. /* The 5 accounts for the PNFS attributes, and assumes that at most three
  127. * layout types will be returned.
  128. */
  129. #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
  130. nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
  131. #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
  132. #define decode_renew_maxsz (op_decode_hdr_maxsz)
  133. #define encode_setclientid_maxsz \
  134. (op_encode_hdr_maxsz + \
  135. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  136. /* client name */ \
  137. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  138. 1 /* sc_prog */ + \
  139. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  140. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
  141. 1) /* sc_cb_ident */
  142. #define decode_setclientid_maxsz \
  143. (op_decode_hdr_maxsz + \
  144. 2 /* clientid */ + \
  145. XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
  146. 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
  147. 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
  148. #define encode_setclientid_confirm_maxsz \
  149. (op_encode_hdr_maxsz + \
  150. 3 + (NFS4_VERIFIER_SIZE >> 2))
  151. #define decode_setclientid_confirm_maxsz \
  152. (op_decode_hdr_maxsz)
  153. #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  154. #define decode_lookup_maxsz (op_decode_hdr_maxsz)
  155. #define encode_share_access_maxsz \
  156. (2)
  157. #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
  158. #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
  159. #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
  160. #define encode_open_maxsz (op_encode_hdr_maxsz + \
  161. 2 + encode_share_access_maxsz + 2 + \
  162. open_owner_id_maxsz + \
  163. encode_opentype_maxsz + \
  164. encode_claim_null_maxsz)
  165. #define decode_space_limit_maxsz (3)
  166. #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
  167. #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
  168. decode_space_limit_maxsz + \
  169. decode_ace_maxsz)
  170. #define decode_change_info_maxsz (5)
  171. #define decode_open_maxsz (op_decode_hdr_maxsz + \
  172. decode_stateid_maxsz + \
  173. decode_change_info_maxsz + 1 + \
  174. nfs4_fattr_bitmap_maxsz + \
  175. decode_delegation_maxsz)
  176. #define encode_open_confirm_maxsz \
  177. (op_encode_hdr_maxsz + \
  178. encode_stateid_maxsz + 1)
  179. #define decode_open_confirm_maxsz \
  180. (op_decode_hdr_maxsz + \
  181. decode_stateid_maxsz)
  182. #define encode_open_downgrade_maxsz \
  183. (op_encode_hdr_maxsz + \
  184. encode_stateid_maxsz + 1 + \
  185. encode_share_access_maxsz)
  186. #define decode_open_downgrade_maxsz \
  187. (op_decode_hdr_maxsz + \
  188. decode_stateid_maxsz)
  189. #define encode_close_maxsz (op_encode_hdr_maxsz + \
  190. 1 + encode_stateid_maxsz)
  191. #define decode_close_maxsz (op_decode_hdr_maxsz + \
  192. decode_stateid_maxsz)
  193. #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
  194. encode_stateid_maxsz + \
  195. encode_attrs_maxsz)
  196. #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
  197. nfs4_fattr_bitmap_maxsz)
  198. #define encode_read_maxsz (op_encode_hdr_maxsz + \
  199. encode_stateid_maxsz + 3)
  200. #define decode_read_maxsz (op_decode_hdr_maxsz + 2)
  201. #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
  202. 2 + encode_verifier_maxsz + 5 + \
  203. nfs4_label_maxsz)
  204. #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
  205. decode_verifier_maxsz)
  206. #define encode_readlink_maxsz (op_encode_hdr_maxsz)
  207. #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
  208. #define encode_write_maxsz (op_encode_hdr_maxsz + \
  209. encode_stateid_maxsz + 4)
  210. #define decode_write_maxsz (op_decode_hdr_maxsz + \
  211. 2 + decode_verifier_maxsz)
  212. #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
  213. #define decode_commit_maxsz (op_decode_hdr_maxsz + \
  214. decode_verifier_maxsz)
  215. #define encode_remove_maxsz (op_encode_hdr_maxsz + \
  216. nfs4_name_maxsz)
  217. #define decode_remove_maxsz (op_decode_hdr_maxsz + \
  218. decode_change_info_maxsz)
  219. #define encode_rename_maxsz (op_encode_hdr_maxsz + \
  220. 2 * nfs4_name_maxsz)
  221. #define decode_rename_maxsz (op_decode_hdr_maxsz + \
  222. decode_change_info_maxsz + \
  223. decode_change_info_maxsz)
  224. #define encode_link_maxsz (op_encode_hdr_maxsz + \
  225. nfs4_name_maxsz)
  226. #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
  227. #define encode_lockowner_maxsz (7)
  228. #define encode_lock_maxsz (op_encode_hdr_maxsz + \
  229. 7 + \
  230. 1 + encode_stateid_maxsz + 1 + \
  231. encode_lockowner_maxsz)
  232. #define decode_lock_denied_maxsz \
  233. (8 + decode_lockowner_maxsz)
  234. #define decode_lock_maxsz (op_decode_hdr_maxsz + \
  235. decode_lock_denied_maxsz)
  236. #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
  237. encode_lockowner_maxsz)
  238. #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
  239. decode_lock_denied_maxsz)
  240. #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
  241. encode_stateid_maxsz + \
  242. 4)
  243. #define decode_locku_maxsz (op_decode_hdr_maxsz + \
  244. decode_stateid_maxsz)
  245. #define encode_release_lockowner_maxsz \
  246. (op_encode_hdr_maxsz + \
  247. encode_lockowner_maxsz)
  248. #define decode_release_lockowner_maxsz \
  249. (op_decode_hdr_maxsz)
  250. #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
  251. #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
  252. #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
  253. 1 + nfs4_name_maxsz + \
  254. 1 + \
  255. nfs4_fattr_maxsz)
  256. #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
  257. #define encode_create_maxsz (op_encode_hdr_maxsz + \
  258. 1 + 2 + nfs4_name_maxsz + \
  259. encode_attrs_maxsz)
  260. #define decode_create_maxsz (op_decode_hdr_maxsz + \
  261. decode_change_info_maxsz + \
  262. nfs4_fattr_bitmap_maxsz)
  263. #define encode_statfs_maxsz (encode_getattr_maxsz)
  264. #define decode_statfs_maxsz (decode_getattr_maxsz)
  265. #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
  266. #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
  267. #define encode_getacl_maxsz (encode_getattr_maxsz)
  268. #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
  269. nfs4_fattr_bitmap_maxsz + 1)
  270. #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
  271. encode_stateid_maxsz + 3)
  272. #define decode_setacl_maxsz (decode_setattr_maxsz)
  273. #define encode_fs_locations_maxsz \
  274. (encode_getattr_maxsz)
  275. #define decode_fs_locations_maxsz \
  276. (0)
  277. #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
  278. #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
  279. #if defined(CONFIG_NFS_V4_1)
  280. #define NFS4_MAX_MACHINE_NAME_LEN (64)
  281. #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
  282. sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
  283. #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
  284. encode_verifier_maxsz + \
  285. 1 /* co_ownerid.len */ + \
  286. /* eia_clientowner */ \
  287. 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  288. 1 /* flags */ + \
  289. 1 /* spa_how */ + \
  290. /* max is SP4_MACH_CRED (for now) */ + \
  291. 1 + NFS4_OP_MAP_NUM_WORDS + \
  292. 1 + NFS4_OP_MAP_NUM_WORDS + \
  293. 1 /* implementation id array of size 1 */ + \
  294. 1 /* nii_domain */ + \
  295. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  296. 1 /* nii_name */ + \
  297. XDR_QUADLEN(IMPL_NAME_LIMIT) + \
  298. 3 /* nii_date */)
  299. #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
  300. 2 /* eir_clientid */ + \
  301. 1 /* eir_sequenceid */ + \
  302. 1 /* eir_flags */ + \
  303. 1 /* spr_how */ + \
  304. /* max is SP4_MACH_CRED (for now) */ + \
  305. 1 + NFS4_OP_MAP_NUM_WORDS + \
  306. 1 + NFS4_OP_MAP_NUM_WORDS + \
  307. 2 /* eir_server_owner.so_minor_id */ + \
  308. /* eir_server_owner.so_major_id<> */ \
  309. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  310. /* eir_server_scope<> */ \
  311. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
  312. 1 /* eir_server_impl_id array length */ + \
  313. 1 /* nii_domain */ + \
  314. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  315. 1 /* nii_name */ + \
  316. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
  317. 3 /* nii_date */)
  318. #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
  319. #define decode_channel_attrs_maxsz (6 + \
  320. 1 /* ca_rdma_ird.len */ + \
  321. 1 /* ca_rdma_ird */)
  322. #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
  323. 2 /* csa_clientid */ + \
  324. 1 /* csa_sequence */ + \
  325. 1 /* csa_flags */ + \
  326. encode_channel_attrs_maxsz + \
  327. encode_channel_attrs_maxsz + \
  328. 1 /* csa_cb_program */ + \
  329. 1 /* csa_sec_parms.len (1) */ + \
  330. 1 /* cb_secflavor (AUTH_SYS) */ + \
  331. 1 /* stamp */ + \
  332. 1 /* machinename.len */ + \
  333. XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
  334. 1 /* uid */ + \
  335. 1 /* gid */ + \
  336. 1 /* gids.len (0) */)
  337. #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
  338. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  339. 1 /* csr_sequence */ + \
  340. 1 /* csr_flags */ + \
  341. decode_channel_attrs_maxsz + \
  342. decode_channel_attrs_maxsz)
  343. #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
  344. /* bctsa_sessid */ \
  345. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  346. 1 /* bctsa_dir */ + \
  347. 1 /* bctsa_use_conn_in_rdma_mode */)
  348. #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
  349. /* bctsr_sessid */ \
  350. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
  351. 1 /* bctsr_dir */ + \
  352. 1 /* bctsr_use_conn_in_rdma_mode */)
  353. #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
  354. #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
  355. #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
  356. #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
  357. #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
  358. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
  359. #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
  360. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
  361. #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
  362. #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
  363. #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
  364. XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
  365. 1 /* layout type */ + \
  366. 1 /* maxcount */ + \
  367. 1 /* bitmap size */ + \
  368. 1 /* notification bitmap length */ + \
  369. 1 /* notification bitmap, word 0 */)
  370. #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
  371. 1 /* layout type */ + \
  372. 1 /* opaque devaddr4 length */ + \
  373. /* devaddr4 payload is read into page */ \
  374. 1 /* notification bitmap length */ + \
  375. 1 /* notification bitmap, word 0 */)
  376. #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
  377. encode_stateid_maxsz)
  378. #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
  379. decode_stateid_maxsz + \
  380. XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
  381. #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
  382. 2 /* offset */ + \
  383. 2 /* length */ + \
  384. 1 /* reclaim */ + \
  385. encode_stateid_maxsz + \
  386. 1 /* new offset (true) */ + \
  387. 2 /* last byte written */ + \
  388. 1 /* nt_timechanged (false) */ + \
  389. 1 /* layoutupdate4 layout type */ + \
  390. 1 /* layoutupdate4 opaqueue len */)
  391. /* the actual content of layoutupdate4 should
  392. be allocated by drivers and spliced in
  393. using xdr_write_pages */
  394. #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
  395. #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
  396. encode_stateid_maxsz + \
  397. 1 + \
  398. XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
  399. #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
  400. 1 + decode_stateid_maxsz)
  401. #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
  402. #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
  403. #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
  404. XDR_QUADLEN(NFS4_STATEID_SIZE))
  405. #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
  406. #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
  407. XDR_QUADLEN(NFS4_STATEID_SIZE))
  408. #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
  409. #else /* CONFIG_NFS_V4_1 */
  410. #define encode_sequence_maxsz 0
  411. #define decode_sequence_maxsz 0
  412. #define encode_layoutreturn_maxsz 0
  413. #define decode_layoutreturn_maxsz 0
  414. #endif /* CONFIG_NFS_V4_1 */
  415. #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
  416. #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
  417. #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
  418. encode_sequence_maxsz + \
  419. encode_putfh_maxsz + \
  420. encode_read_maxsz)
  421. #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
  422. decode_sequence_maxsz + \
  423. decode_putfh_maxsz + \
  424. decode_read_maxsz)
  425. #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
  426. encode_sequence_maxsz + \
  427. encode_putfh_maxsz + \
  428. encode_readlink_maxsz)
  429. #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
  430. decode_sequence_maxsz + \
  431. decode_putfh_maxsz + \
  432. decode_readlink_maxsz)
  433. #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
  434. encode_sequence_maxsz + \
  435. encode_putfh_maxsz + \
  436. encode_readdir_maxsz)
  437. #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
  438. decode_sequence_maxsz + \
  439. decode_putfh_maxsz + \
  440. decode_readdir_maxsz)
  441. #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
  442. encode_sequence_maxsz + \
  443. encode_putfh_maxsz + \
  444. encode_write_maxsz + \
  445. encode_getattr_maxsz)
  446. #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
  447. decode_sequence_maxsz + \
  448. decode_putfh_maxsz + \
  449. decode_write_maxsz + \
  450. decode_getattr_maxsz)
  451. #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
  452. encode_sequence_maxsz + \
  453. encode_putfh_maxsz + \
  454. encode_commit_maxsz)
  455. #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
  456. decode_sequence_maxsz + \
  457. decode_putfh_maxsz + \
  458. decode_commit_maxsz)
  459. #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
  460. encode_sequence_maxsz + \
  461. encode_putfh_maxsz + \
  462. encode_open_maxsz + \
  463. encode_access_maxsz + \
  464. encode_getfh_maxsz + \
  465. encode_getattr_maxsz)
  466. #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
  467. decode_sequence_maxsz + \
  468. decode_putfh_maxsz + \
  469. decode_open_maxsz + \
  470. decode_access_maxsz + \
  471. decode_getfh_maxsz + \
  472. decode_getattr_maxsz)
  473. #define NFS4_enc_open_confirm_sz \
  474. (compound_encode_hdr_maxsz + \
  475. encode_putfh_maxsz + \
  476. encode_open_confirm_maxsz)
  477. #define NFS4_dec_open_confirm_sz \
  478. (compound_decode_hdr_maxsz + \
  479. decode_putfh_maxsz + \
  480. decode_open_confirm_maxsz)
  481. #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
  482. encode_sequence_maxsz + \
  483. encode_putfh_maxsz + \
  484. encode_open_maxsz + \
  485. encode_access_maxsz + \
  486. encode_getattr_maxsz)
  487. #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
  488. decode_sequence_maxsz + \
  489. decode_putfh_maxsz + \
  490. decode_open_maxsz + \
  491. decode_access_maxsz + \
  492. decode_getattr_maxsz)
  493. #define NFS4_enc_open_downgrade_sz \
  494. (compound_encode_hdr_maxsz + \
  495. encode_sequence_maxsz + \
  496. encode_putfh_maxsz + \
  497. encode_layoutreturn_maxsz + \
  498. encode_open_downgrade_maxsz)
  499. #define NFS4_dec_open_downgrade_sz \
  500. (compound_decode_hdr_maxsz + \
  501. decode_sequence_maxsz + \
  502. decode_putfh_maxsz + \
  503. decode_layoutreturn_maxsz + \
  504. decode_open_downgrade_maxsz)
  505. #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
  506. encode_sequence_maxsz + \
  507. encode_putfh_maxsz + \
  508. encode_layoutreturn_maxsz + \
  509. encode_close_maxsz + \
  510. encode_getattr_maxsz)
  511. #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
  512. decode_sequence_maxsz + \
  513. decode_putfh_maxsz + \
  514. decode_layoutreturn_maxsz + \
  515. decode_close_maxsz + \
  516. decode_getattr_maxsz)
  517. #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
  518. encode_sequence_maxsz + \
  519. encode_putfh_maxsz + \
  520. encode_setattr_maxsz + \
  521. encode_getattr_maxsz)
  522. #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
  523. decode_sequence_maxsz + \
  524. decode_putfh_maxsz + \
  525. decode_setattr_maxsz + \
  526. decode_getattr_maxsz)
  527. #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
  528. encode_sequence_maxsz + \
  529. encode_putfh_maxsz + \
  530. encode_fsinfo_maxsz)
  531. #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
  532. decode_sequence_maxsz + \
  533. decode_putfh_maxsz + \
  534. decode_fsinfo_maxsz)
  535. #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
  536. encode_renew_maxsz)
  537. #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
  538. decode_renew_maxsz)
  539. #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
  540. encode_setclientid_maxsz)
  541. #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
  542. decode_setclientid_maxsz)
  543. #define NFS4_enc_setclientid_confirm_sz \
  544. (compound_encode_hdr_maxsz + \
  545. encode_setclientid_confirm_maxsz)
  546. #define NFS4_dec_setclientid_confirm_sz \
  547. (compound_decode_hdr_maxsz + \
  548. decode_setclientid_confirm_maxsz)
  549. #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
  550. encode_sequence_maxsz + \
  551. encode_putfh_maxsz + \
  552. encode_lock_maxsz)
  553. #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
  554. decode_sequence_maxsz + \
  555. decode_putfh_maxsz + \
  556. decode_lock_maxsz)
  557. #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
  558. encode_sequence_maxsz + \
  559. encode_putfh_maxsz + \
  560. encode_lockt_maxsz)
  561. #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
  562. decode_sequence_maxsz + \
  563. decode_putfh_maxsz + \
  564. decode_lockt_maxsz)
  565. #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
  566. encode_sequence_maxsz + \
  567. encode_putfh_maxsz + \
  568. encode_locku_maxsz)
  569. #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
  570. decode_sequence_maxsz + \
  571. decode_putfh_maxsz + \
  572. decode_locku_maxsz)
  573. #define NFS4_enc_release_lockowner_sz \
  574. (compound_encode_hdr_maxsz + \
  575. encode_lockowner_maxsz)
  576. #define NFS4_dec_release_lockowner_sz \
  577. (compound_decode_hdr_maxsz + \
  578. decode_lockowner_maxsz)
  579. #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
  580. encode_sequence_maxsz + \
  581. encode_putfh_maxsz + \
  582. encode_access_maxsz + \
  583. encode_getattr_maxsz)
  584. #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
  585. decode_sequence_maxsz + \
  586. decode_putfh_maxsz + \
  587. decode_access_maxsz + \
  588. decode_getattr_maxsz)
  589. #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
  590. encode_sequence_maxsz + \
  591. encode_putfh_maxsz + \
  592. encode_getattr_maxsz + \
  593. encode_renew_maxsz)
  594. #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
  595. decode_sequence_maxsz + \
  596. decode_putfh_maxsz + \
  597. decode_getattr_maxsz + \
  598. decode_renew_maxsz)
  599. #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
  600. encode_sequence_maxsz + \
  601. encode_putfh_maxsz + \
  602. encode_lookup_maxsz + \
  603. encode_getattr_maxsz + \
  604. encode_getfh_maxsz)
  605. #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
  606. decode_sequence_maxsz + \
  607. decode_putfh_maxsz + \
  608. decode_lookup_maxsz + \
  609. decode_getattr_maxsz + \
  610. decode_getfh_maxsz)
  611. #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
  612. encode_sequence_maxsz + \
  613. encode_putrootfh_maxsz + \
  614. encode_getattr_maxsz + \
  615. encode_getfh_maxsz)
  616. #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
  617. decode_sequence_maxsz + \
  618. decode_putrootfh_maxsz + \
  619. decode_getattr_maxsz + \
  620. decode_getfh_maxsz)
  621. #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
  622. encode_sequence_maxsz + \
  623. encode_putfh_maxsz + \
  624. encode_remove_maxsz)
  625. #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
  626. decode_sequence_maxsz + \
  627. decode_putfh_maxsz + \
  628. decode_remove_maxsz)
  629. #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
  630. encode_sequence_maxsz + \
  631. encode_putfh_maxsz + \
  632. encode_savefh_maxsz + \
  633. encode_putfh_maxsz + \
  634. encode_rename_maxsz)
  635. #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
  636. decode_sequence_maxsz + \
  637. decode_putfh_maxsz + \
  638. decode_savefh_maxsz + \
  639. decode_putfh_maxsz + \
  640. decode_rename_maxsz)
  641. #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
  642. encode_sequence_maxsz + \
  643. encode_putfh_maxsz + \
  644. encode_savefh_maxsz + \
  645. encode_putfh_maxsz + \
  646. encode_link_maxsz + \
  647. encode_restorefh_maxsz + \
  648. encode_getattr_maxsz)
  649. #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
  650. decode_sequence_maxsz + \
  651. decode_putfh_maxsz + \
  652. decode_savefh_maxsz + \
  653. decode_putfh_maxsz + \
  654. decode_link_maxsz + \
  655. decode_restorefh_maxsz + \
  656. decode_getattr_maxsz)
  657. #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
  658. encode_sequence_maxsz + \
  659. encode_putfh_maxsz + \
  660. encode_symlink_maxsz + \
  661. encode_getattr_maxsz + \
  662. encode_getfh_maxsz)
  663. #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
  664. decode_sequence_maxsz + \
  665. decode_putfh_maxsz + \
  666. decode_symlink_maxsz + \
  667. decode_getattr_maxsz + \
  668. decode_getfh_maxsz)
  669. #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
  670. encode_sequence_maxsz + \
  671. encode_putfh_maxsz + \
  672. encode_create_maxsz + \
  673. encode_getfh_maxsz + \
  674. encode_getattr_maxsz)
  675. #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
  676. decode_sequence_maxsz + \
  677. decode_putfh_maxsz + \
  678. decode_create_maxsz + \
  679. decode_getfh_maxsz + \
  680. decode_getattr_maxsz)
  681. #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
  682. encode_sequence_maxsz + \
  683. encode_putfh_maxsz + \
  684. encode_getattr_maxsz)
  685. #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
  686. decode_sequence_maxsz + \
  687. decode_putfh_maxsz + \
  688. decode_getattr_maxsz)
  689. #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
  690. encode_sequence_maxsz + \
  691. encode_putfh_maxsz + \
  692. encode_statfs_maxsz)
  693. #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
  694. decode_sequence_maxsz + \
  695. decode_putfh_maxsz + \
  696. decode_statfs_maxsz)
  697. #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
  698. encode_sequence_maxsz + \
  699. encode_putfh_maxsz + \
  700. encode_getattr_maxsz)
  701. #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
  702. decode_sequence_maxsz + \
  703. decode_putfh_maxsz + \
  704. decode_getattr_maxsz)
  705. #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
  706. encode_sequence_maxsz + \
  707. encode_putfh_maxsz + \
  708. encode_layoutreturn_maxsz + \
  709. encode_delegreturn_maxsz + \
  710. encode_getattr_maxsz)
  711. #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
  712. decode_sequence_maxsz + \
  713. decode_putfh_maxsz + \
  714. decode_layoutreturn_maxsz + \
  715. decode_delegreturn_maxsz + \
  716. decode_getattr_maxsz)
  717. #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
  718. encode_sequence_maxsz + \
  719. encode_putfh_maxsz + \
  720. encode_getacl_maxsz)
  721. #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
  722. decode_sequence_maxsz + \
  723. decode_putfh_maxsz + \
  724. decode_getacl_maxsz)
  725. #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
  726. encode_sequence_maxsz + \
  727. encode_putfh_maxsz + \
  728. encode_setacl_maxsz)
  729. #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
  730. decode_sequence_maxsz + \
  731. decode_putfh_maxsz + \
  732. decode_setacl_maxsz)
  733. #define NFS4_enc_fs_locations_sz \
  734. (compound_encode_hdr_maxsz + \
  735. encode_sequence_maxsz + \
  736. encode_putfh_maxsz + \
  737. encode_lookup_maxsz + \
  738. encode_fs_locations_maxsz + \
  739. encode_renew_maxsz)
  740. #define NFS4_dec_fs_locations_sz \
  741. (compound_decode_hdr_maxsz + \
  742. decode_sequence_maxsz + \
  743. decode_putfh_maxsz + \
  744. decode_lookup_maxsz + \
  745. decode_fs_locations_maxsz + \
  746. decode_renew_maxsz)
  747. #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
  748. encode_sequence_maxsz + \
  749. encode_putfh_maxsz + \
  750. encode_secinfo_maxsz)
  751. #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
  752. decode_sequence_maxsz + \
  753. decode_putfh_maxsz + \
  754. decode_secinfo_maxsz)
  755. #define NFS4_enc_fsid_present_sz \
  756. (compound_encode_hdr_maxsz + \
  757. encode_sequence_maxsz + \
  758. encode_putfh_maxsz + \
  759. encode_getfh_maxsz + \
  760. encode_renew_maxsz)
  761. #define NFS4_dec_fsid_present_sz \
  762. (compound_decode_hdr_maxsz + \
  763. decode_sequence_maxsz + \
  764. decode_putfh_maxsz + \
  765. decode_getfh_maxsz + \
  766. decode_renew_maxsz)
  767. #if defined(CONFIG_NFS_V4_1)
  768. #define NFS4_enc_bind_conn_to_session_sz \
  769. (compound_encode_hdr_maxsz + \
  770. encode_bind_conn_to_session_maxsz)
  771. #define NFS4_dec_bind_conn_to_session_sz \
  772. (compound_decode_hdr_maxsz + \
  773. decode_bind_conn_to_session_maxsz)
  774. #define NFS4_enc_exchange_id_sz \
  775. (compound_encode_hdr_maxsz + \
  776. encode_exchange_id_maxsz)
  777. #define NFS4_dec_exchange_id_sz \
  778. (compound_decode_hdr_maxsz + \
  779. decode_exchange_id_maxsz)
  780. #define NFS4_enc_create_session_sz \
  781. (compound_encode_hdr_maxsz + \
  782. encode_create_session_maxsz)
  783. #define NFS4_dec_create_session_sz \
  784. (compound_decode_hdr_maxsz + \
  785. decode_create_session_maxsz)
  786. #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
  787. encode_destroy_session_maxsz)
  788. #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
  789. decode_destroy_session_maxsz)
  790. #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
  791. encode_destroy_clientid_maxsz)
  792. #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
  793. decode_destroy_clientid_maxsz)
  794. #define NFS4_enc_sequence_sz \
  795. (compound_decode_hdr_maxsz + \
  796. encode_sequence_maxsz)
  797. #define NFS4_dec_sequence_sz \
  798. (compound_decode_hdr_maxsz + \
  799. decode_sequence_maxsz)
  800. #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
  801. encode_sequence_maxsz + \
  802. encode_putrootfh_maxsz + \
  803. encode_fsinfo_maxsz)
  804. #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
  805. decode_sequence_maxsz + \
  806. decode_putrootfh_maxsz + \
  807. decode_fsinfo_maxsz)
  808. #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
  809. encode_sequence_maxsz + \
  810. encode_reclaim_complete_maxsz)
  811. #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
  812. decode_sequence_maxsz + \
  813. decode_reclaim_complete_maxsz)
  814. #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
  815. encode_sequence_maxsz +\
  816. encode_getdeviceinfo_maxsz)
  817. #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
  818. decode_sequence_maxsz + \
  819. decode_getdeviceinfo_maxsz)
  820. #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
  821. encode_sequence_maxsz + \
  822. encode_putfh_maxsz + \
  823. encode_layoutget_maxsz)
  824. #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
  825. decode_sequence_maxsz + \
  826. decode_putfh_maxsz + \
  827. decode_layoutget_maxsz)
  828. #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
  829. encode_sequence_maxsz +\
  830. encode_putfh_maxsz + \
  831. encode_layoutcommit_maxsz + \
  832. encode_getattr_maxsz)
  833. #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
  834. decode_sequence_maxsz + \
  835. decode_putfh_maxsz + \
  836. decode_layoutcommit_maxsz + \
  837. decode_getattr_maxsz)
  838. #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
  839. encode_sequence_maxsz + \
  840. encode_putfh_maxsz + \
  841. encode_layoutreturn_maxsz)
  842. #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
  843. decode_sequence_maxsz + \
  844. decode_putfh_maxsz + \
  845. decode_layoutreturn_maxsz)
  846. #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
  847. encode_sequence_maxsz + \
  848. encode_putrootfh_maxsz +\
  849. encode_secinfo_no_name_maxsz)
  850. #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
  851. decode_sequence_maxsz + \
  852. decode_putrootfh_maxsz + \
  853. decode_secinfo_no_name_maxsz)
  854. #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
  855. encode_sequence_maxsz + \
  856. encode_test_stateid_maxsz)
  857. #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
  858. decode_sequence_maxsz + \
  859. decode_test_stateid_maxsz)
  860. #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
  861. encode_sequence_maxsz + \
  862. encode_free_stateid_maxsz)
  863. #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
  864. decode_sequence_maxsz + \
  865. decode_free_stateid_maxsz)
  866. const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  867. compound_encode_hdr_maxsz +
  868. encode_sequence_maxsz +
  869. encode_putfh_maxsz +
  870. encode_getattr_maxsz) *
  871. XDR_UNIT);
  872. const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
  873. compound_decode_hdr_maxsz +
  874. decode_sequence_maxsz +
  875. decode_putfh_maxsz) *
  876. XDR_UNIT);
  877. const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
  878. compound_decode_hdr_maxsz +
  879. decode_sequence_maxsz) *
  880. XDR_UNIT);
  881. EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
  882. #endif /* CONFIG_NFS_V4_1 */
  883. static const umode_t nfs_type2fmt[] = {
  884. [NF4BAD] = 0,
  885. [NF4REG] = S_IFREG,
  886. [NF4DIR] = S_IFDIR,
  887. [NF4BLK] = S_IFBLK,
  888. [NF4CHR] = S_IFCHR,
  889. [NF4LNK] = S_IFLNK,
  890. [NF4SOCK] = S_IFSOCK,
  891. [NF4FIFO] = S_IFIFO,
  892. [NF4ATTRDIR] = 0,
  893. [NF4NAMEDATTR] = 0,
  894. };
  895. struct compound_hdr {
  896. int32_t status;
  897. uint32_t nops;
  898. __be32 * nops_p;
  899. uint32_t taglen;
  900. char * tag;
  901. uint32_t replen; /* expected reply words */
  902. u32 minorversion;
  903. };
  904. static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
  905. {
  906. __be32 *p = xdr_reserve_space(xdr, nbytes);
  907. BUG_ON(!p);
  908. return p;
  909. }
  910. static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
  911. {
  912. WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
  913. }
  914. static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
  915. {
  916. WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
  917. }
  918. static void encode_uint32(struct xdr_stream *xdr, u32 n)
  919. {
  920. WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
  921. }
  922. static void encode_uint64(struct xdr_stream *xdr, u64 n)
  923. {
  924. WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
  925. }
  926. static void encode_nfs4_seqid(struct xdr_stream *xdr,
  927. const struct nfs_seqid *seqid)
  928. {
  929. if (seqid != NULL)
  930. encode_uint32(xdr, seqid->sequence->counter);
  931. else
  932. encode_uint32(xdr, 0);
  933. }
  934. static void encode_compound_hdr(struct xdr_stream *xdr,
  935. struct rpc_rqst *req,
  936. struct compound_hdr *hdr)
  937. {
  938. __be32 *p;
  939. struct rpc_auth *auth = req->rq_cred->cr_auth;
  940. /* initialize running count of expected bytes in reply.
  941. * NOTE: the replied tag SHOULD be the same is the one sent,
  942. * but this is not required as a MUST for the server to do so. */
  943. hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
  944. WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
  945. encode_string(xdr, hdr->taglen, hdr->tag);
  946. p = reserve_space(xdr, 8);
  947. *p++ = cpu_to_be32(hdr->minorversion);
  948. hdr->nops_p = p;
  949. *p = cpu_to_be32(hdr->nops);
  950. }
  951. static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
  952. uint32_t replen,
  953. struct compound_hdr *hdr)
  954. {
  955. encode_uint32(xdr, op);
  956. hdr->nops++;
  957. hdr->replen += replen;
  958. }
  959. static void encode_nops(struct compound_hdr *hdr)
  960. {
  961. WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
  962. *hdr->nops_p = htonl(hdr->nops);
  963. }
  964. static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  965. {
  966. encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  967. }
  968. static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
  969. {
  970. encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
  971. }
  972. static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
  973. const struct nfs4_label *label,
  974. const umode_t *umask,
  975. const struct nfs_server *server,
  976. const uint32_t attrmask[])
  977. {
  978. char owner_name[IDMAP_NAMESZ];
  979. char owner_group[IDMAP_NAMESZ];
  980. int owner_namelen = 0;
  981. int owner_grouplen = 0;
  982. __be32 *p;
  983. unsigned i;
  984. uint32_t len = 0;
  985. uint32_t bmval_len;
  986. uint32_t bmval[3] = { 0 };
  987. /*
  988. * We reserve enough space to write the entire attribute buffer at once.
  989. */
  990. if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
  991. bmval[0] |= FATTR4_WORD0_SIZE;
  992. len += 8;
  993. }
  994. if (iap->ia_valid & ATTR_MODE) {
  995. if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
  996. bmval[2] |= FATTR4_WORD2_MODE_UMASK;
  997. len += 8;
  998. } else if (attrmask[1] & FATTR4_WORD1_MODE) {
  999. bmval[1] |= FATTR4_WORD1_MODE;
  1000. len += 4;
  1001. }
  1002. }
  1003. if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
  1004. owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
  1005. if (owner_namelen < 0) {
  1006. dprintk("nfs: couldn't resolve uid %d to string\n",
  1007. from_kuid(&init_user_ns, iap->ia_uid));
  1008. /* XXX */
  1009. strcpy(owner_name, "nobody");
  1010. owner_namelen = sizeof("nobody") - 1;
  1011. /* goto out; */
  1012. }
  1013. bmval[1] |= FATTR4_WORD1_OWNER;
  1014. len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
  1015. }
  1016. if ((iap->ia_valid & ATTR_GID) &&
  1017. (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
  1018. owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
  1019. if (owner_grouplen < 0) {
  1020. dprintk("nfs: couldn't resolve gid %d to string\n",
  1021. from_kgid(&init_user_ns, iap->ia_gid));
  1022. strcpy(owner_group, "nobody");
  1023. owner_grouplen = sizeof("nobody") - 1;
  1024. /* goto out; */
  1025. }
  1026. bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
  1027. len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
  1028. }
  1029. if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1030. if (iap->ia_valid & ATTR_ATIME_SET) {
  1031. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1032. len += 16;
  1033. } else if (iap->ia_valid & ATTR_ATIME) {
  1034. bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  1035. len += 4;
  1036. }
  1037. }
  1038. if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1039. if (iap->ia_valid & ATTR_MTIME_SET) {
  1040. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1041. len += 16;
  1042. } else if (iap->ia_valid & ATTR_MTIME) {
  1043. bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  1044. len += 4;
  1045. }
  1046. }
  1047. if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  1048. len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
  1049. bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1050. }
  1051. if (bmval[2] != 0)
  1052. bmval_len = 3;
  1053. else if (bmval[1] != 0)
  1054. bmval_len = 2;
  1055. else
  1056. bmval_len = 1;
  1057. p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
  1058. *p++ = cpu_to_be32(bmval_len);
  1059. for (i = 0; i < bmval_len; i++)
  1060. *p++ = cpu_to_be32(bmval[i]);
  1061. *p++ = cpu_to_be32(len);
  1062. if (bmval[0] & FATTR4_WORD0_SIZE)
  1063. p = xdr_encode_hyper(p, iap->ia_size);
  1064. if (bmval[1] & FATTR4_WORD1_MODE)
  1065. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1066. if (bmval[1] & FATTR4_WORD1_OWNER)
  1067. p = xdr_encode_opaque(p, owner_name, owner_namelen);
  1068. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
  1069. p = xdr_encode_opaque(p, owner_group, owner_grouplen);
  1070. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  1071. if (iap->ia_valid & ATTR_ATIME_SET) {
  1072. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1073. p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
  1074. *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
  1075. } else
  1076. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1077. }
  1078. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  1079. if (iap->ia_valid & ATTR_MTIME_SET) {
  1080. *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
  1081. p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
  1082. *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
  1083. } else
  1084. *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
  1085. }
  1086. if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
  1087. *p++ = cpu_to_be32(label->lfs);
  1088. *p++ = cpu_to_be32(label->pi);
  1089. *p++ = cpu_to_be32(label->len);
  1090. p = xdr_encode_opaque_fixed(p, label->label, label->len);
  1091. }
  1092. if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
  1093. *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
  1094. *p++ = cpu_to_be32(*umask);
  1095. }
  1096. /* out: */
  1097. }
  1098. static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
  1099. {
  1100. encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
  1101. encode_uint32(xdr, access);
  1102. }
  1103. static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1104. {
  1105. encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
  1106. encode_nfs4_seqid(xdr, arg->seqid);
  1107. encode_nfs4_stateid(xdr, &arg->stateid);
  1108. }
  1109. static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
  1110. {
  1111. __be32 *p;
  1112. encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
  1113. p = reserve_space(xdr, 12);
  1114. p = xdr_encode_hyper(p, args->offset);
  1115. *p = cpu_to_be32(args->count);
  1116. }
  1117. static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
  1118. {
  1119. __be32 *p;
  1120. encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
  1121. encode_uint32(xdr, create->ftype);
  1122. switch (create->ftype) {
  1123. case NF4LNK:
  1124. p = reserve_space(xdr, 4);
  1125. *p = cpu_to_be32(create->u.symlink.len);
  1126. xdr_write_pages(xdr, create->u.symlink.pages, 0,
  1127. create->u.symlink.len);
  1128. xdr->buf->flags |= XDRBUF_WRITE;
  1129. break;
  1130. case NF4BLK: case NF4CHR:
  1131. p = reserve_space(xdr, 8);
  1132. *p++ = cpu_to_be32(create->u.device.specdata1);
  1133. *p = cpu_to_be32(create->u.device.specdata2);
  1134. break;
  1135. default:
  1136. break;
  1137. }
  1138. encode_string(xdr, create->name->len, create->name->name);
  1139. encode_attrs(xdr, create->attrs, create->label, &create->umask,
  1140. create->server, create->server->attr_bitmask);
  1141. }
  1142. static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
  1143. {
  1144. __be32 *p;
  1145. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1146. p = reserve_space(xdr, 8);
  1147. *p++ = cpu_to_be32(1);
  1148. *p = cpu_to_be32(bitmap);
  1149. }
  1150. static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
  1151. {
  1152. __be32 *p;
  1153. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1154. p = reserve_space(xdr, 12);
  1155. *p++ = cpu_to_be32(2);
  1156. *p++ = cpu_to_be32(bm0);
  1157. *p = cpu_to_be32(bm1);
  1158. }
  1159. static void
  1160. encode_getattr_three(struct xdr_stream *xdr,
  1161. uint32_t bm0, uint32_t bm1, uint32_t bm2,
  1162. struct compound_hdr *hdr)
  1163. {
  1164. __be32 *p;
  1165. encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
  1166. if (bm2) {
  1167. p = reserve_space(xdr, 16);
  1168. *p++ = cpu_to_be32(3);
  1169. *p++ = cpu_to_be32(bm0);
  1170. *p++ = cpu_to_be32(bm1);
  1171. *p = cpu_to_be32(bm2);
  1172. } else if (bm1) {
  1173. p = reserve_space(xdr, 12);
  1174. *p++ = cpu_to_be32(2);
  1175. *p++ = cpu_to_be32(bm0);
  1176. *p = cpu_to_be32(bm1);
  1177. } else {
  1178. p = reserve_space(xdr, 8);
  1179. *p++ = cpu_to_be32(1);
  1180. *p = cpu_to_be32(bm0);
  1181. }
  1182. }
  1183. static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1184. {
  1185. encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
  1186. bitmask[1] & nfs4_fattr_bitmap[1],
  1187. bitmask[2] & nfs4_fattr_bitmap[2],
  1188. hdr);
  1189. }
  1190. static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
  1191. const u32 *open_bitmap,
  1192. struct compound_hdr *hdr)
  1193. {
  1194. encode_getattr_three(xdr,
  1195. bitmask[0] & open_bitmap[0],
  1196. bitmask[1] & open_bitmap[1],
  1197. bitmask[2] & open_bitmap[2],
  1198. hdr);
  1199. }
  1200. static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1201. {
  1202. encode_getattr_three(xdr,
  1203. bitmask[0] & nfs4_fsinfo_bitmap[0],
  1204. bitmask[1] & nfs4_fsinfo_bitmap[1],
  1205. bitmask[2] & nfs4_fsinfo_bitmap[2],
  1206. hdr);
  1207. }
  1208. static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
  1209. {
  1210. encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
  1211. bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
  1212. }
  1213. static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1214. {
  1215. encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
  1216. }
  1217. static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1218. {
  1219. encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
  1220. encode_string(xdr, name->len, name->name);
  1221. }
  1222. static inline int nfs4_lock_type(struct file_lock *fl, int block)
  1223. {
  1224. if (fl->fl_type == F_RDLCK)
  1225. return block ? NFS4_READW_LT : NFS4_READ_LT;
  1226. return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  1227. }
  1228. static inline uint64_t nfs4_lock_length(struct file_lock *fl)
  1229. {
  1230. if (fl->fl_end == OFFSET_MAX)
  1231. return ~(uint64_t)0;
  1232. return fl->fl_end - fl->fl_start + 1;
  1233. }
  1234. static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
  1235. {
  1236. __be32 *p;
  1237. p = reserve_space(xdr, 32);
  1238. p = xdr_encode_hyper(p, lowner->clientid);
  1239. *p++ = cpu_to_be32(20);
  1240. p = xdr_encode_opaque_fixed(p, "lock id:", 8);
  1241. *p++ = cpu_to_be32(lowner->s_dev);
  1242. xdr_encode_hyper(p, lowner->id);
  1243. }
  1244. /*
  1245. * opcode,type,reclaim,offset,length,new_lock_owner = 32
  1246. * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
  1247. */
  1248. static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
  1249. {
  1250. __be32 *p;
  1251. encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
  1252. p = reserve_space(xdr, 28);
  1253. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
  1254. *p++ = cpu_to_be32(args->reclaim);
  1255. p = xdr_encode_hyper(p, args->fl->fl_start);
  1256. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1257. *p = cpu_to_be32(args->new_lock_owner);
  1258. if (args->new_lock_owner){
  1259. encode_nfs4_seqid(xdr, args->open_seqid);
  1260. encode_nfs4_stateid(xdr, &args->open_stateid);
  1261. encode_nfs4_seqid(xdr, args->lock_seqid);
  1262. encode_lockowner(xdr, &args->lock_owner);
  1263. }
  1264. else {
  1265. encode_nfs4_stateid(xdr, &args->lock_stateid);
  1266. encode_nfs4_seqid(xdr, args->lock_seqid);
  1267. }
  1268. }
  1269. static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
  1270. {
  1271. __be32 *p;
  1272. encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
  1273. p = reserve_space(xdr, 20);
  1274. *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
  1275. p = xdr_encode_hyper(p, args->fl->fl_start);
  1276. p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1277. encode_lockowner(xdr, &args->lock_owner);
  1278. }
  1279. static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
  1280. {
  1281. __be32 *p;
  1282. encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
  1283. encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
  1284. encode_nfs4_seqid(xdr, args->seqid);
  1285. encode_nfs4_stateid(xdr, &args->stateid);
  1286. p = reserve_space(xdr, 16);
  1287. p = xdr_encode_hyper(p, args->fl->fl_start);
  1288. xdr_encode_hyper(p, nfs4_lock_length(args->fl));
  1289. }
  1290. static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
  1291. {
  1292. encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
  1293. encode_lockowner(xdr, lowner);
  1294. }
  1295. static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1296. {
  1297. encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
  1298. encode_string(xdr, name->len, name->name);
  1299. }
  1300. static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
  1301. {
  1302. __be32 *p;
  1303. p = reserve_space(xdr, 8);
  1304. *p++ = cpu_to_be32(share_access);
  1305. *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
  1306. }
  1307. static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1308. {
  1309. __be32 *p;
  1310. /*
  1311. * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
  1312. * owner 4 = 32
  1313. */
  1314. encode_nfs4_seqid(xdr, arg->seqid);
  1315. encode_share_access(xdr, arg->share_access);
  1316. p = reserve_space(xdr, 36);
  1317. p = xdr_encode_hyper(p, arg->clientid);
  1318. *p++ = cpu_to_be32(24);
  1319. p = xdr_encode_opaque_fixed(p, "open id:", 8);
  1320. *p++ = cpu_to_be32(arg->server->s_dev);
  1321. *p++ = cpu_to_be32(arg->id.uniquifier);
  1322. xdr_encode_hyper(p, arg->id.create_time);
  1323. }
  1324. static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1325. {
  1326. __be32 *p;
  1327. p = reserve_space(xdr, 4);
  1328. switch(arg->createmode) {
  1329. case NFS4_CREATE_UNCHECKED:
  1330. *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
  1331. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1332. arg->server, arg->server->attr_bitmask);
  1333. break;
  1334. case NFS4_CREATE_GUARDED:
  1335. *p = cpu_to_be32(NFS4_CREATE_GUARDED);
  1336. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1337. arg->server, arg->server->attr_bitmask);
  1338. break;
  1339. case NFS4_CREATE_EXCLUSIVE:
  1340. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
  1341. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1342. break;
  1343. case NFS4_CREATE_EXCLUSIVE4_1:
  1344. *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
  1345. encode_nfs4_verifier(xdr, &arg->u.verifier);
  1346. encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
  1347. arg->server, arg->server->exclcreat_bitmask);
  1348. }
  1349. }
  1350. static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
  1351. {
  1352. __be32 *p;
  1353. p = reserve_space(xdr, 4);
  1354. switch (arg->open_flags & O_CREAT) {
  1355. case 0:
  1356. *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
  1357. break;
  1358. default:
  1359. *p = cpu_to_be32(NFS4_OPEN_CREATE);
  1360. encode_createmode(xdr, arg);
  1361. }
  1362. }
  1363. static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
  1364. {
  1365. __be32 *p;
  1366. p = reserve_space(xdr, 4);
  1367. switch (delegation_type) {
  1368. case 0:
  1369. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
  1370. break;
  1371. case FMODE_READ:
  1372. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
  1373. break;
  1374. case FMODE_WRITE|FMODE_READ:
  1375. *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
  1376. break;
  1377. default:
  1378. BUG();
  1379. }
  1380. }
  1381. static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
  1382. {
  1383. __be32 *p;
  1384. p = reserve_space(xdr, 4);
  1385. *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
  1386. encode_string(xdr, name->len, name->name);
  1387. }
  1388. static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
  1389. {
  1390. __be32 *p;
  1391. p = reserve_space(xdr, 4);
  1392. *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
  1393. encode_delegation_type(xdr, type);
  1394. }
  1395. static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
  1396. {
  1397. __be32 *p;
  1398. p = reserve_space(xdr, 4);
  1399. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
  1400. encode_nfs4_stateid(xdr, stateid);
  1401. encode_string(xdr, name->len, name->name);
  1402. }
  1403. static inline void encode_claim_fh(struct xdr_stream *xdr)
  1404. {
  1405. __be32 *p;
  1406. p = reserve_space(xdr, 4);
  1407. *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
  1408. }
  1409. static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
  1410. {
  1411. __be32 *p;
  1412. p = reserve_space(xdr, 4);
  1413. *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
  1414. encode_nfs4_stateid(xdr, stateid);
  1415. }
  1416. static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
  1417. {
  1418. encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
  1419. encode_openhdr(xdr, arg);
  1420. encode_opentype(xdr, arg);
  1421. switch (arg->claim) {
  1422. case NFS4_OPEN_CLAIM_NULL:
  1423. encode_claim_null(xdr, arg->name);
  1424. break;
  1425. case NFS4_OPEN_CLAIM_PREVIOUS:
  1426. encode_claim_previous(xdr, arg->u.delegation_type);
  1427. break;
  1428. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  1429. encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
  1430. break;
  1431. case NFS4_OPEN_CLAIM_FH:
  1432. encode_claim_fh(xdr);
  1433. break;
  1434. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  1435. encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
  1436. break;
  1437. default:
  1438. BUG();
  1439. }
  1440. }
  1441. static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
  1442. {
  1443. encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
  1444. encode_nfs4_stateid(xdr, arg->stateid);
  1445. encode_nfs4_seqid(xdr, arg->seqid);
  1446. }
  1447. static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
  1448. {
  1449. encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
  1450. encode_nfs4_stateid(xdr, &arg->stateid);
  1451. encode_nfs4_seqid(xdr, arg->seqid);
  1452. encode_share_access(xdr, arg->share_access);
  1453. }
  1454. static void
  1455. encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
  1456. {
  1457. encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
  1458. encode_string(xdr, fh->size, fh->data);
  1459. }
  1460. static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1461. {
  1462. encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
  1463. }
  1464. static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1465. struct compound_hdr *hdr)
  1466. {
  1467. __be32 *p;
  1468. encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
  1469. encode_nfs4_stateid(xdr, &args->stateid);
  1470. p = reserve_space(xdr, 12);
  1471. p = xdr_encode_hyper(p, args->offset);
  1472. *p = cpu_to_be32(args->count);
  1473. }
  1474. static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
  1475. {
  1476. uint32_t attrs[3] = {
  1477. FATTR4_WORD0_RDATTR_ERROR,
  1478. FATTR4_WORD1_MOUNTED_ON_FILEID,
  1479. };
  1480. uint32_t dircount = readdir->count >> 1;
  1481. __be32 *p, verf[2];
  1482. uint32_t attrlen = 0;
  1483. unsigned int i;
  1484. if (readdir->plus) {
  1485. attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
  1486. FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
  1487. attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
  1488. FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
  1489. FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
  1490. FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
  1491. attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
  1492. dircount >>= 1;
  1493. }
  1494. /* Use mounted_on_fileid only if the server supports it */
  1495. if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
  1496. attrs[0] |= FATTR4_WORD0_FILEID;
  1497. for (i = 0; i < ARRAY_SIZE(attrs); i++) {
  1498. attrs[i] &= readdir->bitmask[i];
  1499. if (attrs[i] != 0)
  1500. attrlen = i+1;
  1501. }
  1502. encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
  1503. encode_uint64(xdr, readdir->cookie);
  1504. encode_nfs4_verifier(xdr, &readdir->verifier);
  1505. p = reserve_space(xdr, 12 + (attrlen << 2));
  1506. *p++ = cpu_to_be32(dircount);
  1507. *p++ = cpu_to_be32(readdir->count);
  1508. *p++ = cpu_to_be32(attrlen);
  1509. for (i = 0; i < attrlen; i++)
  1510. *p++ = cpu_to_be32(attrs[i]);
  1511. memcpy(verf, readdir->verifier.data, sizeof(verf));
  1512. dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
  1513. __func__,
  1514. (unsigned long long)readdir->cookie,
  1515. verf[0], verf[1],
  1516. attrs[0] & readdir->bitmask[0],
  1517. attrs[1] & readdir->bitmask[1],
  1518. attrs[2] & readdir->bitmask[2]);
  1519. }
  1520. static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
  1521. {
  1522. encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
  1523. }
  1524. static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1525. {
  1526. encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
  1527. encode_string(xdr, name->len, name->name);
  1528. }
  1529. static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
  1530. {
  1531. encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
  1532. encode_string(xdr, oldname->len, oldname->name);
  1533. encode_string(xdr, newname->len, newname->name);
  1534. }
  1535. static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
  1536. struct compound_hdr *hdr)
  1537. {
  1538. encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
  1539. encode_uint64(xdr, clid);
  1540. }
  1541. static void
  1542. encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1543. {
  1544. encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
  1545. }
  1546. static void
  1547. encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
  1548. struct compound_hdr *hdr)
  1549. {
  1550. __be32 *p;
  1551. encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
  1552. encode_nfs4_stateid(xdr, &zero_stateid);
  1553. p = reserve_space(xdr, 2*4);
  1554. *p++ = cpu_to_be32(1);
  1555. *p = cpu_to_be32(FATTR4_WORD0_ACL);
  1556. p = reserve_space(xdr, 4);
  1557. *p = cpu_to_be32(arg->acl_len);
  1558. xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
  1559. }
  1560. static void
  1561. encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
  1562. {
  1563. encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
  1564. }
  1565. static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
  1566. {
  1567. encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
  1568. encode_nfs4_stateid(xdr, &arg->stateid);
  1569. encode_attrs(xdr, arg->iap, arg->label, NULL, server,
  1570. server->attr_bitmask);
  1571. }
  1572. static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
  1573. {
  1574. __be32 *p;
  1575. encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
  1576. encode_nfs4_verifier(xdr, setclientid->sc_verifier);
  1577. encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
  1578. setclientid->sc_clnt->cl_owner_id);
  1579. p = reserve_space(xdr, 4);
  1580. *p = cpu_to_be32(setclientid->sc_prog);
  1581. encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
  1582. encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
  1583. p = reserve_space(xdr, 4);
  1584. *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
  1585. }
  1586. static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
  1587. {
  1588. encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
  1589. decode_setclientid_confirm_maxsz, hdr);
  1590. encode_uint64(xdr, arg->clientid);
  1591. encode_nfs4_verifier(xdr, &arg->confirm);
  1592. }
  1593. static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
  1594. struct compound_hdr *hdr)
  1595. {
  1596. __be32 *p;
  1597. encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
  1598. encode_nfs4_stateid(xdr, &args->stateid);
  1599. p = reserve_space(xdr, 16);
  1600. p = xdr_encode_hyper(p, args->offset);
  1601. *p++ = cpu_to_be32(args->stable);
  1602. *p = cpu_to_be32(args->count);
  1603. xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
  1604. }
  1605. static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
  1606. {
  1607. encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
  1608. encode_nfs4_stateid(xdr, stateid);
  1609. }
  1610. static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
  1611. {
  1612. encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
  1613. encode_string(xdr, name->len, name->name);
  1614. }
  1615. #if defined(CONFIG_NFS_V4_1)
  1616. /* NFSv4.1 operations */
  1617. static void encode_bind_conn_to_session(struct xdr_stream *xdr,
  1618. const struct nfs41_bind_conn_to_session_args *args,
  1619. struct compound_hdr *hdr)
  1620. {
  1621. __be32 *p;
  1622. encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
  1623. decode_bind_conn_to_session_maxsz, hdr);
  1624. encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1625. p = xdr_reserve_space(xdr, 8);
  1626. *p++ = cpu_to_be32(args->dir);
  1627. *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
  1628. }
  1629. static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
  1630. {
  1631. unsigned int i;
  1632. encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
  1633. for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
  1634. encode_uint32(xdr, op_map->u.words[i]);
  1635. }
  1636. static void encode_exchange_id(struct xdr_stream *xdr,
  1637. const struct nfs41_exchange_id_args *args,
  1638. struct compound_hdr *hdr)
  1639. {
  1640. __be32 *p;
  1641. char impl_name[IMPL_NAME_LIMIT];
  1642. int len = 0;
  1643. encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
  1644. encode_nfs4_verifier(xdr, args->verifier);
  1645. encode_string(xdr, strlen(args->client->cl_owner_id),
  1646. args->client->cl_owner_id);
  1647. encode_uint32(xdr, args->flags);
  1648. encode_uint32(xdr, args->state_protect.how);
  1649. switch (args->state_protect.how) {
  1650. case SP4_NONE:
  1651. break;
  1652. case SP4_MACH_CRED:
  1653. encode_op_map(xdr, &args->state_protect.enforce);
  1654. encode_op_map(xdr, &args->state_protect.allow);
  1655. break;
  1656. default:
  1657. WARN_ON_ONCE(1);
  1658. break;
  1659. }
  1660. if (send_implementation_id &&
  1661. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
  1662. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
  1663. <= sizeof(impl_name) + 1)
  1664. len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
  1665. utsname()->sysname, utsname()->release,
  1666. utsname()->version, utsname()->machine);
  1667. if (len > 0) {
  1668. encode_uint32(xdr, 1); /* implementation id array length=1 */
  1669. encode_string(xdr,
  1670. sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
  1671. CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
  1672. encode_string(xdr, len, impl_name);
  1673. /* just send zeros for nii_date - the date is in nii_name */
  1674. p = reserve_space(xdr, 12);
  1675. p = xdr_encode_hyper(p, 0);
  1676. *p = cpu_to_be32(0);
  1677. } else
  1678. encode_uint32(xdr, 0); /* implementation id array length=0 */
  1679. }
  1680. static void encode_create_session(struct xdr_stream *xdr,
  1681. const struct nfs41_create_session_args *args,
  1682. struct compound_hdr *hdr)
  1683. {
  1684. __be32 *p;
  1685. struct nfs_client *clp = args->client;
  1686. struct rpc_clnt *clnt = clp->cl_rpcclient;
  1687. struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
  1688. u32 max_resp_sz_cached;
  1689. /*
  1690. * Assumes OPEN is the biggest non-idempotent compound.
  1691. * 2 is the verifier.
  1692. */
  1693. max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
  1694. RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
  1695. encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
  1696. p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
  1697. p = xdr_encode_hyper(p, args->clientid);
  1698. *p++ = cpu_to_be32(args->seqid); /*Sequence id */
  1699. *p++ = cpu_to_be32(args->flags); /*flags */
  1700. /* Fore Channel */
  1701. *p++ = cpu_to_be32(0); /* header padding size */
  1702. *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
  1703. *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
  1704. *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
  1705. *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
  1706. *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
  1707. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1708. /* Back Channel */
  1709. *p++ = cpu_to_be32(0); /* header padding size */
  1710. *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
  1711. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
  1712. *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
  1713. *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
  1714. *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
  1715. *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
  1716. *p++ = cpu_to_be32(args->cb_program); /* cb_program */
  1717. *p++ = cpu_to_be32(1);
  1718. *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
  1719. /* authsys_parms rfc1831 */
  1720. *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
  1721. p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
  1722. *p++ = cpu_to_be32(0); /* UID */
  1723. *p++ = cpu_to_be32(0); /* GID */
  1724. *p = cpu_to_be32(0); /* No more gids */
  1725. }
  1726. static void encode_destroy_session(struct xdr_stream *xdr,
  1727. const struct nfs4_session *session,
  1728. struct compound_hdr *hdr)
  1729. {
  1730. encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
  1731. encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1732. }
  1733. static void encode_destroy_clientid(struct xdr_stream *xdr,
  1734. uint64_t clientid,
  1735. struct compound_hdr *hdr)
  1736. {
  1737. encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
  1738. encode_uint64(xdr, clientid);
  1739. }
  1740. static void encode_reclaim_complete(struct xdr_stream *xdr,
  1741. const struct nfs41_reclaim_complete_args *args,
  1742. struct compound_hdr *hdr)
  1743. {
  1744. encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
  1745. encode_uint32(xdr, args->one_fs);
  1746. }
  1747. #endif /* CONFIG_NFS_V4_1 */
  1748. static void encode_sequence(struct xdr_stream *xdr,
  1749. const struct nfs4_sequence_args *args,
  1750. struct compound_hdr *hdr)
  1751. {
  1752. #if defined(CONFIG_NFS_V4_1)
  1753. struct nfs4_session *session;
  1754. struct nfs4_slot_table *tp;
  1755. struct nfs4_slot *slot = args->sa_slot;
  1756. __be32 *p;
  1757. tp = slot->table;
  1758. session = tp->session;
  1759. if (!session)
  1760. return;
  1761. encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
  1762. /*
  1763. * Sessionid + seqid + slotid + max slotid + cache_this
  1764. */
  1765. dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
  1766. "max_slotid=%d cache_this=%d\n",
  1767. __func__,
  1768. ((u32 *)session->sess_id.data)[0],
  1769. ((u32 *)session->sess_id.data)[1],
  1770. ((u32 *)session->sess_id.data)[2],
  1771. ((u32 *)session->sess_id.data)[3],
  1772. slot->seq_nr, slot->slot_nr,
  1773. tp->highest_used_slotid, args->sa_cache_this);
  1774. p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
  1775. p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
  1776. *p++ = cpu_to_be32(slot->seq_nr);
  1777. *p++ = cpu_to_be32(slot->slot_nr);
  1778. *p++ = cpu_to_be32(tp->highest_used_slotid);
  1779. *p = cpu_to_be32(args->sa_cache_this);
  1780. #endif /* CONFIG_NFS_V4_1 */
  1781. }
  1782. #ifdef CONFIG_NFS_V4_1
  1783. static void
  1784. encode_getdeviceinfo(struct xdr_stream *xdr,
  1785. const struct nfs4_getdeviceinfo_args *args,
  1786. struct compound_hdr *hdr)
  1787. {
  1788. __be32 *p;
  1789. encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
  1790. p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
  1791. p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
  1792. NFS4_DEVICEID4_SIZE);
  1793. *p++ = cpu_to_be32(args->pdev->layout_type);
  1794. *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
  1795. p = reserve_space(xdr, 4 + 4);
  1796. *p++ = cpu_to_be32(1); /* bitmap length */
  1797. *p++ = cpu_to_be32(args->notify_types);
  1798. }
  1799. static void
  1800. encode_layoutget(struct xdr_stream *xdr,
  1801. const struct nfs4_layoutget_args *args,
  1802. struct compound_hdr *hdr)
  1803. {
  1804. __be32 *p;
  1805. encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
  1806. p = reserve_space(xdr, 36);
  1807. *p++ = cpu_to_be32(0); /* Signal layout available */
  1808. *p++ = cpu_to_be32(args->type);
  1809. *p++ = cpu_to_be32(args->range.iomode);
  1810. p = xdr_encode_hyper(p, args->range.offset);
  1811. p = xdr_encode_hyper(p, args->range.length);
  1812. p = xdr_encode_hyper(p, args->minlength);
  1813. encode_nfs4_stateid(xdr, &args->stateid);
  1814. encode_uint32(xdr, args->maxcount);
  1815. dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
  1816. __func__,
  1817. args->type,
  1818. args->range.iomode,
  1819. (unsigned long)args->range.offset,
  1820. (unsigned long)args->range.length,
  1821. args->maxcount);
  1822. }
  1823. static int
  1824. encode_layoutcommit(struct xdr_stream *xdr,
  1825. struct inode *inode,
  1826. const struct nfs4_layoutcommit_args *args,
  1827. struct compound_hdr *hdr)
  1828. {
  1829. __be32 *p;
  1830. dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
  1831. NFS_SERVER(args->inode)->pnfs_curr_ld->id);
  1832. encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
  1833. p = reserve_space(xdr, 20);
  1834. /* Only whole file layouts */
  1835. p = xdr_encode_hyper(p, 0); /* offset */
  1836. p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
  1837. *p = cpu_to_be32(0); /* reclaim */
  1838. encode_nfs4_stateid(xdr, &args->stateid);
  1839. if (args->lastbytewritten != U64_MAX) {
  1840. p = reserve_space(xdr, 20);
  1841. *p++ = cpu_to_be32(1); /* newoffset = TRUE */
  1842. p = xdr_encode_hyper(p, args->lastbytewritten);
  1843. } else {
  1844. p = reserve_space(xdr, 12);
  1845. *p++ = cpu_to_be32(0); /* newoffset = FALSE */
  1846. }
  1847. *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
  1848. *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
  1849. encode_uint32(xdr, args->layoutupdate_len);
  1850. if (args->layoutupdate_pages)
  1851. xdr_write_pages(xdr, args->layoutupdate_pages, 0,
  1852. args->layoutupdate_len);
  1853. return 0;
  1854. }
  1855. static void
  1856. encode_layoutreturn(struct xdr_stream *xdr,
  1857. const struct nfs4_layoutreturn_args *args,
  1858. struct compound_hdr *hdr)
  1859. {
  1860. __be32 *p;
  1861. encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
  1862. p = reserve_space(xdr, 16);
  1863. *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
  1864. *p++ = cpu_to_be32(args->layout_type);
  1865. *p++ = cpu_to_be32(args->range.iomode);
  1866. *p = cpu_to_be32(RETURN_FILE);
  1867. p = reserve_space(xdr, 16);
  1868. p = xdr_encode_hyper(p, args->range.offset);
  1869. p = xdr_encode_hyper(p, args->range.length);
  1870. spin_lock(&args->inode->i_lock);
  1871. encode_nfs4_stateid(xdr, &args->stateid);
  1872. spin_unlock(&args->inode->i_lock);
  1873. if (args->ld_private->ops && args->ld_private->ops->encode)
  1874. args->ld_private->ops->encode(xdr, args, args->ld_private);
  1875. else
  1876. encode_uint32(xdr, 0);
  1877. }
  1878. static int
  1879. encode_secinfo_no_name(struct xdr_stream *xdr,
  1880. const struct nfs41_secinfo_no_name_args *args,
  1881. struct compound_hdr *hdr)
  1882. {
  1883. encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
  1884. encode_uint32(xdr, args->style);
  1885. return 0;
  1886. }
  1887. static void encode_test_stateid(struct xdr_stream *xdr,
  1888. const struct nfs41_test_stateid_args *args,
  1889. struct compound_hdr *hdr)
  1890. {
  1891. encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
  1892. encode_uint32(xdr, 1);
  1893. encode_nfs4_stateid(xdr, args->stateid);
  1894. }
  1895. static void encode_free_stateid(struct xdr_stream *xdr,
  1896. const struct nfs41_free_stateid_args *args,
  1897. struct compound_hdr *hdr)
  1898. {
  1899. encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
  1900. encode_nfs4_stateid(xdr, &args->stateid);
  1901. }
  1902. #else
  1903. static inline void
  1904. encode_layoutreturn(struct xdr_stream *xdr,
  1905. const struct nfs4_layoutreturn_args *args,
  1906. struct compound_hdr *hdr)
  1907. {
  1908. }
  1909. #endif /* CONFIG_NFS_V4_1 */
  1910. /*
  1911. * END OF "GENERIC" ENCODE ROUTINES.
  1912. */
  1913. static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
  1914. {
  1915. #if defined(CONFIG_NFS_V4_1)
  1916. struct nfs4_session *session = args->sa_slot->table->session;
  1917. if (session)
  1918. return session->clp->cl_mvops->minor_version;
  1919. #endif /* CONFIG_NFS_V4_1 */
  1920. return 0;
  1921. }
  1922. /*
  1923. * Encode an ACCESS request
  1924. */
  1925. static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
  1926. const void *data)
  1927. {
  1928. const struct nfs4_accessargs *args = data;
  1929. struct compound_hdr hdr = {
  1930. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1931. };
  1932. encode_compound_hdr(xdr, req, &hdr);
  1933. encode_sequence(xdr, &args->seq_args, &hdr);
  1934. encode_putfh(xdr, args->fh, &hdr);
  1935. encode_access(xdr, args->access, &hdr);
  1936. encode_getfattr(xdr, args->bitmask, &hdr);
  1937. encode_nops(&hdr);
  1938. }
  1939. /*
  1940. * Encode LOOKUP request
  1941. */
  1942. static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
  1943. const void *data)
  1944. {
  1945. const struct nfs4_lookup_arg *args = data;
  1946. struct compound_hdr hdr = {
  1947. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1948. };
  1949. encode_compound_hdr(xdr, req, &hdr);
  1950. encode_sequence(xdr, &args->seq_args, &hdr);
  1951. encode_putfh(xdr, args->dir_fh, &hdr);
  1952. encode_lookup(xdr, args->name, &hdr);
  1953. encode_getfh(xdr, &hdr);
  1954. encode_getfattr(xdr, args->bitmask, &hdr);
  1955. encode_nops(&hdr);
  1956. }
  1957. /*
  1958. * Encode LOOKUP_ROOT request
  1959. */
  1960. static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
  1961. struct xdr_stream *xdr,
  1962. const void *data)
  1963. {
  1964. const struct nfs4_lookup_root_arg *args = data;
  1965. struct compound_hdr hdr = {
  1966. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1967. };
  1968. encode_compound_hdr(xdr, req, &hdr);
  1969. encode_sequence(xdr, &args->seq_args, &hdr);
  1970. encode_putrootfh(xdr, &hdr);
  1971. encode_getfh(xdr, &hdr);
  1972. encode_getfattr(xdr, args->bitmask, &hdr);
  1973. encode_nops(&hdr);
  1974. }
  1975. /*
  1976. * Encode REMOVE request
  1977. */
  1978. static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
  1979. const void *data)
  1980. {
  1981. const struct nfs_removeargs *args = data;
  1982. struct compound_hdr hdr = {
  1983. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  1984. };
  1985. encode_compound_hdr(xdr, req, &hdr);
  1986. encode_sequence(xdr, &args->seq_args, &hdr);
  1987. encode_putfh(xdr, args->fh, &hdr);
  1988. encode_remove(xdr, &args->name, &hdr);
  1989. encode_nops(&hdr);
  1990. }
  1991. /*
  1992. * Encode RENAME request
  1993. */
  1994. static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
  1995. const void *data)
  1996. {
  1997. const struct nfs_renameargs *args = data;
  1998. struct compound_hdr hdr = {
  1999. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2000. };
  2001. encode_compound_hdr(xdr, req, &hdr);
  2002. encode_sequence(xdr, &args->seq_args, &hdr);
  2003. encode_putfh(xdr, args->old_dir, &hdr);
  2004. encode_savefh(xdr, &hdr);
  2005. encode_putfh(xdr, args->new_dir, &hdr);
  2006. encode_rename(xdr, args->old_name, args->new_name, &hdr);
  2007. encode_nops(&hdr);
  2008. }
  2009. /*
  2010. * Encode LINK request
  2011. */
  2012. static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
  2013. const void *data)
  2014. {
  2015. const struct nfs4_link_arg *args = data;
  2016. struct compound_hdr hdr = {
  2017. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2018. };
  2019. encode_compound_hdr(xdr, req, &hdr);
  2020. encode_sequence(xdr, &args->seq_args, &hdr);
  2021. encode_putfh(xdr, args->fh, &hdr);
  2022. encode_savefh(xdr, &hdr);
  2023. encode_putfh(xdr, args->dir_fh, &hdr);
  2024. encode_link(xdr, args->name, &hdr);
  2025. encode_restorefh(xdr, &hdr);
  2026. encode_getfattr(xdr, args->bitmask, &hdr);
  2027. encode_nops(&hdr);
  2028. }
  2029. /*
  2030. * Encode CREATE request
  2031. */
  2032. static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
  2033. const void *data)
  2034. {
  2035. const struct nfs4_create_arg *args = data;
  2036. struct compound_hdr hdr = {
  2037. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2038. };
  2039. encode_compound_hdr(xdr, req, &hdr);
  2040. encode_sequence(xdr, &args->seq_args, &hdr);
  2041. encode_putfh(xdr, args->dir_fh, &hdr);
  2042. encode_create(xdr, args, &hdr);
  2043. encode_getfh(xdr, &hdr);
  2044. encode_getfattr(xdr, args->bitmask, &hdr);
  2045. encode_nops(&hdr);
  2046. }
  2047. /*
  2048. * Encode SYMLINK request
  2049. */
  2050. static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2051. const void *data)
  2052. {
  2053. const struct nfs4_create_arg *args = data;
  2054. nfs4_xdr_enc_create(req, xdr, args);
  2055. }
  2056. /*
  2057. * Encode GETATTR request
  2058. */
  2059. static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2060. const void *data)
  2061. {
  2062. const struct nfs4_getattr_arg *args = data;
  2063. struct compound_hdr hdr = {
  2064. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2065. };
  2066. encode_compound_hdr(xdr, req, &hdr);
  2067. encode_sequence(xdr, &args->seq_args, &hdr);
  2068. encode_putfh(xdr, args->fh, &hdr);
  2069. encode_getfattr(xdr, args->bitmask, &hdr);
  2070. encode_nops(&hdr);
  2071. }
  2072. /*
  2073. * Encode a CLOSE request
  2074. */
  2075. static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
  2076. const void *data)
  2077. {
  2078. const struct nfs_closeargs *args = data;
  2079. struct compound_hdr hdr = {
  2080. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2081. };
  2082. encode_compound_hdr(xdr, req, &hdr);
  2083. encode_sequence(xdr, &args->seq_args, &hdr);
  2084. encode_putfh(xdr, args->fh, &hdr);
  2085. if (args->lr_args)
  2086. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2087. if (args->bitmask != NULL)
  2088. encode_getfattr(xdr, args->bitmask, &hdr);
  2089. encode_close(xdr, args, &hdr);
  2090. encode_nops(&hdr);
  2091. }
  2092. /*
  2093. * Encode an OPEN request
  2094. */
  2095. static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
  2096. const void *data)
  2097. {
  2098. const struct nfs_openargs *args = data;
  2099. struct compound_hdr hdr = {
  2100. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2101. };
  2102. encode_compound_hdr(xdr, req, &hdr);
  2103. encode_sequence(xdr, &args->seq_args, &hdr);
  2104. encode_putfh(xdr, args->fh, &hdr);
  2105. encode_open(xdr, args, &hdr);
  2106. encode_getfh(xdr, &hdr);
  2107. if (args->access)
  2108. encode_access(xdr, args->access, &hdr);
  2109. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2110. encode_nops(&hdr);
  2111. }
  2112. /*
  2113. * Encode an OPEN_CONFIRM request
  2114. */
  2115. static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
  2116. struct xdr_stream *xdr,
  2117. const void *data)
  2118. {
  2119. const struct nfs_open_confirmargs *args = data;
  2120. struct compound_hdr hdr = {
  2121. .nops = 0,
  2122. };
  2123. encode_compound_hdr(xdr, req, &hdr);
  2124. encode_putfh(xdr, args->fh, &hdr);
  2125. encode_open_confirm(xdr, args, &hdr);
  2126. encode_nops(&hdr);
  2127. }
  2128. /*
  2129. * Encode an OPEN request with no attributes.
  2130. */
  2131. static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
  2132. struct xdr_stream *xdr,
  2133. const void *data)
  2134. {
  2135. const struct nfs_openargs *args = data;
  2136. struct compound_hdr hdr = {
  2137. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2138. };
  2139. encode_compound_hdr(xdr, req, &hdr);
  2140. encode_sequence(xdr, &args->seq_args, &hdr);
  2141. encode_putfh(xdr, args->fh, &hdr);
  2142. encode_open(xdr, args, &hdr);
  2143. if (args->access)
  2144. encode_access(xdr, args->access, &hdr);
  2145. encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
  2146. encode_nops(&hdr);
  2147. }
  2148. /*
  2149. * Encode an OPEN_DOWNGRADE request
  2150. */
  2151. static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
  2152. struct xdr_stream *xdr,
  2153. const void *data)
  2154. {
  2155. const struct nfs_closeargs *args = data;
  2156. struct compound_hdr hdr = {
  2157. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2158. };
  2159. encode_compound_hdr(xdr, req, &hdr);
  2160. encode_sequence(xdr, &args->seq_args, &hdr);
  2161. encode_putfh(xdr, args->fh, &hdr);
  2162. if (args->lr_args)
  2163. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2164. encode_open_downgrade(xdr, args, &hdr);
  2165. encode_nops(&hdr);
  2166. }
  2167. /*
  2168. * Encode a LOCK request
  2169. */
  2170. static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
  2171. const void *data)
  2172. {
  2173. const struct nfs_lock_args *args = data;
  2174. struct compound_hdr hdr = {
  2175. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2176. };
  2177. encode_compound_hdr(xdr, req, &hdr);
  2178. encode_sequence(xdr, &args->seq_args, &hdr);
  2179. encode_putfh(xdr, args->fh, &hdr);
  2180. encode_lock(xdr, args, &hdr);
  2181. encode_nops(&hdr);
  2182. }
  2183. /*
  2184. * Encode a LOCKT request
  2185. */
  2186. static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
  2187. const void *data)
  2188. {
  2189. const struct nfs_lockt_args *args = data;
  2190. struct compound_hdr hdr = {
  2191. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2192. };
  2193. encode_compound_hdr(xdr, req, &hdr);
  2194. encode_sequence(xdr, &args->seq_args, &hdr);
  2195. encode_putfh(xdr, args->fh, &hdr);
  2196. encode_lockt(xdr, args, &hdr);
  2197. encode_nops(&hdr);
  2198. }
  2199. /*
  2200. * Encode a LOCKU request
  2201. */
  2202. static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
  2203. const void *data)
  2204. {
  2205. const struct nfs_locku_args *args = data;
  2206. struct compound_hdr hdr = {
  2207. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2208. };
  2209. encode_compound_hdr(xdr, req, &hdr);
  2210. encode_sequence(xdr, &args->seq_args, &hdr);
  2211. encode_putfh(xdr, args->fh, &hdr);
  2212. encode_locku(xdr, args, &hdr);
  2213. encode_nops(&hdr);
  2214. }
  2215. static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
  2216. struct xdr_stream *xdr,
  2217. const void *data)
  2218. {
  2219. const struct nfs_release_lockowner_args *args = data;
  2220. struct compound_hdr hdr = {
  2221. .minorversion = 0,
  2222. };
  2223. encode_compound_hdr(xdr, req, &hdr);
  2224. encode_release_lockowner(xdr, &args->lock_owner, &hdr);
  2225. encode_nops(&hdr);
  2226. }
  2227. /*
  2228. * Encode a READLINK request
  2229. */
  2230. static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
  2231. const void *data)
  2232. {
  2233. const struct nfs4_readlink *args = data;
  2234. struct compound_hdr hdr = {
  2235. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2236. };
  2237. encode_compound_hdr(xdr, req, &hdr);
  2238. encode_sequence(xdr, &args->seq_args, &hdr);
  2239. encode_putfh(xdr, args->fh, &hdr);
  2240. encode_readlink(xdr, args, req, &hdr);
  2241. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2242. args->pgbase, args->pglen);
  2243. encode_nops(&hdr);
  2244. }
  2245. /*
  2246. * Encode a READDIR request
  2247. */
  2248. static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
  2249. const void *data)
  2250. {
  2251. const struct nfs4_readdir_arg *args = data;
  2252. struct compound_hdr hdr = {
  2253. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2254. };
  2255. encode_compound_hdr(xdr, req, &hdr);
  2256. encode_sequence(xdr, &args->seq_args, &hdr);
  2257. encode_putfh(xdr, args->fh, &hdr);
  2258. encode_readdir(xdr, args, req, &hdr);
  2259. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
  2260. args->pgbase, args->count);
  2261. dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
  2262. __func__, hdr.replen << 2, args->pages,
  2263. args->pgbase, args->count);
  2264. encode_nops(&hdr);
  2265. }
  2266. /*
  2267. * Encode a READ request
  2268. */
  2269. static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
  2270. const void *data)
  2271. {
  2272. const struct nfs_pgio_args *args = data;
  2273. struct compound_hdr hdr = {
  2274. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2275. };
  2276. encode_compound_hdr(xdr, req, &hdr);
  2277. encode_sequence(xdr, &args->seq_args, &hdr);
  2278. encode_putfh(xdr, args->fh, &hdr);
  2279. encode_read(xdr, args, &hdr);
  2280. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2281. args->pages, args->pgbase, args->count);
  2282. req->rq_rcv_buf.flags |= XDRBUF_READ;
  2283. encode_nops(&hdr);
  2284. }
  2285. /*
  2286. * Encode an SETATTR request
  2287. */
  2288. static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
  2289. const void *data)
  2290. {
  2291. const struct nfs_setattrargs *args = data;
  2292. struct compound_hdr hdr = {
  2293. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2294. };
  2295. encode_compound_hdr(xdr, req, &hdr);
  2296. encode_sequence(xdr, &args->seq_args, &hdr);
  2297. encode_putfh(xdr, args->fh, &hdr);
  2298. encode_setattr(xdr, args, args->server, &hdr);
  2299. encode_getfattr(xdr, args->bitmask, &hdr);
  2300. encode_nops(&hdr);
  2301. }
  2302. /*
  2303. * Encode a GETACL request
  2304. */
  2305. static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  2306. const void *data)
  2307. {
  2308. const struct nfs_getaclargs *args = data;
  2309. struct compound_hdr hdr = {
  2310. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2311. };
  2312. uint32_t replen;
  2313. encode_compound_hdr(xdr, req, &hdr);
  2314. encode_sequence(xdr, &args->seq_args, &hdr);
  2315. encode_putfh(xdr, args->fh, &hdr);
  2316. replen = hdr.replen + op_decode_hdr_maxsz;
  2317. encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
  2318. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2319. args->acl_pages, 0, args->acl_len);
  2320. encode_nops(&hdr);
  2321. }
  2322. /*
  2323. * Encode a WRITE request
  2324. */
  2325. static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
  2326. const void *data)
  2327. {
  2328. const struct nfs_pgio_args *args = data;
  2329. struct compound_hdr hdr = {
  2330. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2331. };
  2332. encode_compound_hdr(xdr, req, &hdr);
  2333. encode_sequence(xdr, &args->seq_args, &hdr);
  2334. encode_putfh(xdr, args->fh, &hdr);
  2335. encode_write(xdr, args, &hdr);
  2336. req->rq_snd_buf.flags |= XDRBUF_WRITE;
  2337. if (args->bitmask)
  2338. encode_getfattr(xdr, args->bitmask, &hdr);
  2339. encode_nops(&hdr);
  2340. }
  2341. /*
  2342. * a COMMIT request
  2343. */
  2344. static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
  2345. const void *data)
  2346. {
  2347. const struct nfs_commitargs *args = data;
  2348. struct compound_hdr hdr = {
  2349. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2350. };
  2351. encode_compound_hdr(xdr, req, &hdr);
  2352. encode_sequence(xdr, &args->seq_args, &hdr);
  2353. encode_putfh(xdr, args->fh, &hdr);
  2354. encode_commit(xdr, args, &hdr);
  2355. encode_nops(&hdr);
  2356. }
  2357. /*
  2358. * FSINFO request
  2359. */
  2360. static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  2361. const void *data)
  2362. {
  2363. const struct nfs4_fsinfo_arg *args = data;
  2364. struct compound_hdr hdr = {
  2365. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2366. };
  2367. encode_compound_hdr(xdr, req, &hdr);
  2368. encode_sequence(xdr, &args->seq_args, &hdr);
  2369. encode_putfh(xdr, args->fh, &hdr);
  2370. encode_fsinfo(xdr, args->bitmask, &hdr);
  2371. encode_nops(&hdr);
  2372. }
  2373. /*
  2374. * a PATHCONF request
  2375. */
  2376. static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  2377. const void *data)
  2378. {
  2379. const struct nfs4_pathconf_arg *args = data;
  2380. struct compound_hdr hdr = {
  2381. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2382. };
  2383. encode_compound_hdr(xdr, req, &hdr);
  2384. encode_sequence(xdr, &args->seq_args, &hdr);
  2385. encode_putfh(xdr, args->fh, &hdr);
  2386. encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
  2387. &hdr);
  2388. encode_nops(&hdr);
  2389. }
  2390. /*
  2391. * a STATFS request
  2392. */
  2393. static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  2394. const void *data)
  2395. {
  2396. const struct nfs4_statfs_arg *args = data;
  2397. struct compound_hdr hdr = {
  2398. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2399. };
  2400. encode_compound_hdr(xdr, req, &hdr);
  2401. encode_sequence(xdr, &args->seq_args, &hdr);
  2402. encode_putfh(xdr, args->fh, &hdr);
  2403. encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
  2404. args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
  2405. encode_nops(&hdr);
  2406. }
  2407. /*
  2408. * GETATTR_BITMAP request
  2409. */
  2410. static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
  2411. struct xdr_stream *xdr,
  2412. const void *data)
  2413. {
  2414. const struct nfs4_server_caps_arg *args = data;
  2415. const u32 *bitmask = args->bitmask;
  2416. struct compound_hdr hdr = {
  2417. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2418. };
  2419. encode_compound_hdr(xdr, req, &hdr);
  2420. encode_sequence(xdr, &args->seq_args, &hdr);
  2421. encode_putfh(xdr, args->fhandle, &hdr);
  2422. encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
  2423. encode_nops(&hdr);
  2424. }
  2425. /*
  2426. * a RENEW request
  2427. */
  2428. static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
  2429. const void *data)
  2430. {
  2431. const struct nfs_client *clp = data;
  2432. struct compound_hdr hdr = {
  2433. .nops = 0,
  2434. };
  2435. encode_compound_hdr(xdr, req, &hdr);
  2436. encode_renew(xdr, clp->cl_clientid, &hdr);
  2437. encode_nops(&hdr);
  2438. }
  2439. /*
  2440. * a SETCLIENTID request
  2441. */
  2442. static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
  2443. struct xdr_stream *xdr,
  2444. const void *data)
  2445. {
  2446. const struct nfs4_setclientid *sc = data;
  2447. struct compound_hdr hdr = {
  2448. .nops = 0,
  2449. };
  2450. encode_compound_hdr(xdr, req, &hdr);
  2451. encode_setclientid(xdr, sc, &hdr);
  2452. encode_nops(&hdr);
  2453. }
  2454. /*
  2455. * a SETCLIENTID_CONFIRM request
  2456. */
  2457. static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
  2458. struct xdr_stream *xdr,
  2459. const void *data)
  2460. {
  2461. const struct nfs4_setclientid_res *arg = data;
  2462. struct compound_hdr hdr = {
  2463. .nops = 0,
  2464. };
  2465. encode_compound_hdr(xdr, req, &hdr);
  2466. encode_setclientid_confirm(xdr, arg, &hdr);
  2467. encode_nops(&hdr);
  2468. }
  2469. /*
  2470. * DELEGRETURN request
  2471. */
  2472. static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
  2473. struct xdr_stream *xdr,
  2474. const void *data)
  2475. {
  2476. const struct nfs4_delegreturnargs *args = data;
  2477. struct compound_hdr hdr = {
  2478. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2479. };
  2480. encode_compound_hdr(xdr, req, &hdr);
  2481. encode_sequence(xdr, &args->seq_args, &hdr);
  2482. encode_putfh(xdr, args->fhandle, &hdr);
  2483. if (args->lr_args)
  2484. encode_layoutreturn(xdr, args->lr_args, &hdr);
  2485. if (args->bitmask)
  2486. encode_getfattr(xdr, args->bitmask, &hdr);
  2487. encode_delegreturn(xdr, args->stateid, &hdr);
  2488. encode_nops(&hdr);
  2489. }
  2490. /*
  2491. * Encode FS_LOCATIONS request
  2492. */
  2493. static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
  2494. struct xdr_stream *xdr,
  2495. const void *data)
  2496. {
  2497. const struct nfs4_fs_locations_arg *args = data;
  2498. struct compound_hdr hdr = {
  2499. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2500. };
  2501. uint32_t replen;
  2502. encode_compound_hdr(xdr, req, &hdr);
  2503. encode_sequence(xdr, &args->seq_args, &hdr);
  2504. if (args->migration) {
  2505. encode_putfh(xdr, args->fh, &hdr);
  2506. replen = hdr.replen;
  2507. encode_fs_locations(xdr, args->bitmask, &hdr);
  2508. if (args->renew)
  2509. encode_renew(xdr, args->clientid, &hdr);
  2510. } else {
  2511. encode_putfh(xdr, args->dir_fh, &hdr);
  2512. encode_lookup(xdr, args->name, &hdr);
  2513. replen = hdr.replen;
  2514. encode_fs_locations(xdr, args->bitmask, &hdr);
  2515. }
  2516. /* Set up reply kvec to capture returned fs_locations array. */
  2517. xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
  2518. (struct page **)&args->page, 0, PAGE_SIZE);
  2519. encode_nops(&hdr);
  2520. }
  2521. /*
  2522. * Encode SECINFO request
  2523. */
  2524. static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
  2525. struct xdr_stream *xdr,
  2526. const void *data)
  2527. {
  2528. const struct nfs4_secinfo_arg *args = data;
  2529. struct compound_hdr hdr = {
  2530. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2531. };
  2532. encode_compound_hdr(xdr, req, &hdr);
  2533. encode_sequence(xdr, &args->seq_args, &hdr);
  2534. encode_putfh(xdr, args->dir_fh, &hdr);
  2535. encode_secinfo(xdr, args->name, &hdr);
  2536. encode_nops(&hdr);
  2537. }
  2538. /*
  2539. * Encode FSID_PRESENT request
  2540. */
  2541. static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
  2542. struct xdr_stream *xdr,
  2543. const void *data)
  2544. {
  2545. const struct nfs4_fsid_present_arg *args = data;
  2546. struct compound_hdr hdr = {
  2547. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2548. };
  2549. encode_compound_hdr(xdr, req, &hdr);
  2550. encode_sequence(xdr, &args->seq_args, &hdr);
  2551. encode_putfh(xdr, args->fh, &hdr);
  2552. encode_getfh(xdr, &hdr);
  2553. if (args->renew)
  2554. encode_renew(xdr, args->clientid, &hdr);
  2555. encode_nops(&hdr);
  2556. }
  2557. #if defined(CONFIG_NFS_V4_1)
  2558. /*
  2559. * BIND_CONN_TO_SESSION request
  2560. */
  2561. static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
  2562. struct xdr_stream *xdr,
  2563. const void *data)
  2564. {
  2565. const struct nfs41_bind_conn_to_session_args *args = data;
  2566. struct compound_hdr hdr = {
  2567. .minorversion = args->client->cl_mvops->minor_version,
  2568. };
  2569. encode_compound_hdr(xdr, req, &hdr);
  2570. encode_bind_conn_to_session(xdr, args, &hdr);
  2571. encode_nops(&hdr);
  2572. }
  2573. /*
  2574. * EXCHANGE_ID request
  2575. */
  2576. static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
  2577. struct xdr_stream *xdr,
  2578. const void *data)
  2579. {
  2580. const struct nfs41_exchange_id_args *args = data;
  2581. struct compound_hdr hdr = {
  2582. .minorversion = args->client->cl_mvops->minor_version,
  2583. };
  2584. encode_compound_hdr(xdr, req, &hdr);
  2585. encode_exchange_id(xdr, args, &hdr);
  2586. encode_nops(&hdr);
  2587. }
  2588. /*
  2589. * a CREATE_SESSION request
  2590. */
  2591. static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
  2592. struct xdr_stream *xdr,
  2593. const void *data)
  2594. {
  2595. const struct nfs41_create_session_args *args = data;
  2596. struct compound_hdr hdr = {
  2597. .minorversion = args->client->cl_mvops->minor_version,
  2598. };
  2599. encode_compound_hdr(xdr, req, &hdr);
  2600. encode_create_session(xdr, args, &hdr);
  2601. encode_nops(&hdr);
  2602. }
  2603. /*
  2604. * a DESTROY_SESSION request
  2605. */
  2606. static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
  2607. struct xdr_stream *xdr,
  2608. const void *data)
  2609. {
  2610. const struct nfs4_session *session = data;
  2611. struct compound_hdr hdr = {
  2612. .minorversion = session->clp->cl_mvops->minor_version,
  2613. };
  2614. encode_compound_hdr(xdr, req, &hdr);
  2615. encode_destroy_session(xdr, session, &hdr);
  2616. encode_nops(&hdr);
  2617. }
  2618. /*
  2619. * a DESTROY_CLIENTID request
  2620. */
  2621. static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
  2622. struct xdr_stream *xdr,
  2623. const void *data)
  2624. {
  2625. const struct nfs_client *clp = data;
  2626. struct compound_hdr hdr = {
  2627. .minorversion = clp->cl_mvops->minor_version,
  2628. };
  2629. encode_compound_hdr(xdr, req, &hdr);
  2630. encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
  2631. encode_nops(&hdr);
  2632. }
  2633. /*
  2634. * a SEQUENCE request
  2635. */
  2636. static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
  2637. const void *data)
  2638. {
  2639. const struct nfs4_sequence_args *args = data;
  2640. struct compound_hdr hdr = {
  2641. .minorversion = nfs4_xdr_minorversion(args),
  2642. };
  2643. encode_compound_hdr(xdr, req, &hdr);
  2644. encode_sequence(xdr, args, &hdr);
  2645. encode_nops(&hdr);
  2646. }
  2647. /*
  2648. * a GET_LEASE_TIME request
  2649. */
  2650. static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
  2651. struct xdr_stream *xdr,
  2652. const void *data)
  2653. {
  2654. const struct nfs4_get_lease_time_args *args = data;
  2655. struct compound_hdr hdr = {
  2656. .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
  2657. };
  2658. const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
  2659. encode_compound_hdr(xdr, req, &hdr);
  2660. encode_sequence(xdr, &args->la_seq_args, &hdr);
  2661. encode_putrootfh(xdr, &hdr);
  2662. encode_fsinfo(xdr, lease_bitmap, &hdr);
  2663. encode_nops(&hdr);
  2664. }
  2665. /*
  2666. * a RECLAIM_COMPLETE request
  2667. */
  2668. static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
  2669. struct xdr_stream *xdr,
  2670. const void *data)
  2671. {
  2672. const struct nfs41_reclaim_complete_args *args = data;
  2673. struct compound_hdr hdr = {
  2674. .minorversion = nfs4_xdr_minorversion(&args->seq_args)
  2675. };
  2676. encode_compound_hdr(xdr, req, &hdr);
  2677. encode_sequence(xdr, &args->seq_args, &hdr);
  2678. encode_reclaim_complete(xdr, args, &hdr);
  2679. encode_nops(&hdr);
  2680. }
  2681. /*
  2682. * Encode GETDEVICEINFO request
  2683. */
  2684. static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
  2685. struct xdr_stream *xdr,
  2686. const void *data)
  2687. {
  2688. const struct nfs4_getdeviceinfo_args *args = data;
  2689. struct compound_hdr hdr = {
  2690. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2691. };
  2692. encode_compound_hdr(xdr, req, &hdr);
  2693. encode_sequence(xdr, &args->seq_args, &hdr);
  2694. encode_getdeviceinfo(xdr, args, &hdr);
  2695. /* set up reply kvec. Subtract notification bitmap max size (2)
  2696. * so that notification bitmap is put in xdr_buf tail */
  2697. xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
  2698. args->pdev->pages, args->pdev->pgbase,
  2699. args->pdev->pglen);
  2700. encode_nops(&hdr);
  2701. }
  2702. /*
  2703. * Encode LAYOUTGET request
  2704. */
  2705. static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
  2706. struct xdr_stream *xdr,
  2707. const void *data)
  2708. {
  2709. const struct nfs4_layoutget_args *args = data;
  2710. struct compound_hdr hdr = {
  2711. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2712. };
  2713. encode_compound_hdr(xdr, req, &hdr);
  2714. encode_sequence(xdr, &args->seq_args, &hdr);
  2715. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2716. encode_layoutget(xdr, args, &hdr);
  2717. xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
  2718. args->layout.pages, 0, args->layout.pglen);
  2719. encode_nops(&hdr);
  2720. }
  2721. /*
  2722. * Encode LAYOUTCOMMIT request
  2723. */
  2724. static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
  2725. struct xdr_stream *xdr,
  2726. const void *priv)
  2727. {
  2728. const struct nfs4_layoutcommit_args *args = priv;
  2729. struct nfs4_layoutcommit_data *data =
  2730. container_of(args, struct nfs4_layoutcommit_data, args);
  2731. struct compound_hdr hdr = {
  2732. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2733. };
  2734. encode_compound_hdr(xdr, req, &hdr);
  2735. encode_sequence(xdr, &args->seq_args, &hdr);
  2736. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2737. encode_layoutcommit(xdr, data->args.inode, args, &hdr);
  2738. encode_getfattr(xdr, args->bitmask, &hdr);
  2739. encode_nops(&hdr);
  2740. }
  2741. /*
  2742. * Encode LAYOUTRETURN request
  2743. */
  2744. static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
  2745. struct xdr_stream *xdr,
  2746. const void *data)
  2747. {
  2748. const struct nfs4_layoutreturn_args *args = data;
  2749. struct compound_hdr hdr = {
  2750. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2751. };
  2752. encode_compound_hdr(xdr, req, &hdr);
  2753. encode_sequence(xdr, &args->seq_args, &hdr);
  2754. encode_putfh(xdr, NFS_FH(args->inode), &hdr);
  2755. encode_layoutreturn(xdr, args, &hdr);
  2756. encode_nops(&hdr);
  2757. }
  2758. /*
  2759. * Encode SECINFO_NO_NAME request
  2760. */
  2761. static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
  2762. struct xdr_stream *xdr,
  2763. const void *data)
  2764. {
  2765. const struct nfs41_secinfo_no_name_args *args = data;
  2766. struct compound_hdr hdr = {
  2767. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2768. };
  2769. encode_compound_hdr(xdr, req, &hdr);
  2770. encode_sequence(xdr, &args->seq_args, &hdr);
  2771. encode_putrootfh(xdr, &hdr);
  2772. encode_secinfo_no_name(xdr, args, &hdr);
  2773. encode_nops(&hdr);
  2774. }
  2775. /*
  2776. * Encode TEST_STATEID request
  2777. */
  2778. static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
  2779. struct xdr_stream *xdr,
  2780. const void *data)
  2781. {
  2782. const struct nfs41_test_stateid_args *args = data;
  2783. struct compound_hdr hdr = {
  2784. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2785. };
  2786. encode_compound_hdr(xdr, req, &hdr);
  2787. encode_sequence(xdr, &args->seq_args, &hdr);
  2788. encode_test_stateid(xdr, args, &hdr);
  2789. encode_nops(&hdr);
  2790. }
  2791. /*
  2792. * Encode FREE_STATEID request
  2793. */
  2794. static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
  2795. struct xdr_stream *xdr,
  2796. const void *data)
  2797. {
  2798. const struct nfs41_free_stateid_args *args = data;
  2799. struct compound_hdr hdr = {
  2800. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  2801. };
  2802. encode_compound_hdr(xdr, req, &hdr);
  2803. encode_sequence(xdr, &args->seq_args, &hdr);
  2804. encode_free_stateid(xdr, args, &hdr);
  2805. encode_nops(&hdr);
  2806. }
  2807. #endif /* CONFIG_NFS_V4_1 */
  2808. static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
  2809. {
  2810. dprintk("nfs: %s: prematurely hit end of receive buffer. "
  2811. "Remaining buffer length is %tu words.\n",
  2812. func, xdr->end - xdr->p);
  2813. }
  2814. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2815. {
  2816. ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
  2817. NFS4_OPAQUE_LIMIT);
  2818. if (unlikely(ret < 0)) {
  2819. if (ret == -EBADMSG)
  2820. print_overflow_msg(__func__, xdr);
  2821. return -EIO;
  2822. }
  2823. *len = ret;
  2824. return 0;
  2825. }
  2826. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2827. {
  2828. __be32 *p;
  2829. p = xdr_inline_decode(xdr, 8);
  2830. if (unlikely(!p))
  2831. goto out_overflow;
  2832. hdr->status = be32_to_cpup(p++);
  2833. hdr->taglen = be32_to_cpup(p);
  2834. p = xdr_inline_decode(xdr, hdr->taglen + 4);
  2835. if (unlikely(!p))
  2836. goto out_overflow;
  2837. hdr->tag = (char *)p;
  2838. p += XDR_QUADLEN(hdr->taglen);
  2839. hdr->nops = be32_to_cpup(p);
  2840. if (unlikely(hdr->nops < 1))
  2841. return nfs4_stat_to_errno(hdr->status);
  2842. return 0;
  2843. out_overflow:
  2844. print_overflow_msg(__func__, xdr);
  2845. return -EIO;
  2846. }
  2847. static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
  2848. int *nfs_retval)
  2849. {
  2850. __be32 *p;
  2851. uint32_t opnum;
  2852. int32_t nfserr;
  2853. p = xdr_inline_decode(xdr, 8);
  2854. if (unlikely(!p))
  2855. goto out_overflow;
  2856. opnum = be32_to_cpup(p++);
  2857. if (unlikely(opnum != expected))
  2858. goto out_bad_operation;
  2859. nfserr = be32_to_cpup(p);
  2860. if (nfserr == NFS_OK)
  2861. *nfs_retval = 0;
  2862. else
  2863. *nfs_retval = nfs4_stat_to_errno(nfserr);
  2864. return true;
  2865. out_bad_operation:
  2866. dprintk("nfs: Server returned operation"
  2867. " %d but we issued a request for %d\n",
  2868. opnum, expected);
  2869. *nfs_retval = -EREMOTEIO;
  2870. return false;
  2871. out_overflow:
  2872. print_overflow_msg(__func__, xdr);
  2873. *nfs_retval = -EIO;
  2874. return false;
  2875. }
  2876. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2877. {
  2878. int retval;
  2879. __decode_op_hdr(xdr, expected, &retval);
  2880. return retval;
  2881. }
  2882. /* Dummy routine */
  2883. static int decode_ace(struct xdr_stream *xdr, void *ace)
  2884. {
  2885. __be32 *p;
  2886. unsigned int strlen;
  2887. char *str;
  2888. p = xdr_inline_decode(xdr, 12);
  2889. if (likely(p))
  2890. return decode_opaque_inline(xdr, &strlen, &str);
  2891. print_overflow_msg(__func__, xdr);
  2892. return -EIO;
  2893. }
  2894. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2895. {
  2896. uint32_t bmlen;
  2897. __be32 *p;
  2898. p = xdr_inline_decode(xdr, 4);
  2899. if (unlikely(!p))
  2900. goto out_overflow;
  2901. bmlen = be32_to_cpup(p);
  2902. bitmap[0] = bitmap[1] = bitmap[2] = 0;
  2903. p = xdr_inline_decode(xdr, (bmlen << 2));
  2904. if (unlikely(!p))
  2905. goto out_overflow;
  2906. if (bmlen > 0) {
  2907. bitmap[0] = be32_to_cpup(p++);
  2908. if (bmlen > 1) {
  2909. bitmap[1] = be32_to_cpup(p++);
  2910. if (bmlen > 2)
  2911. bitmap[2] = be32_to_cpup(p);
  2912. }
  2913. }
  2914. return 0;
  2915. out_overflow:
  2916. print_overflow_msg(__func__, xdr);
  2917. return -EIO;
  2918. }
  2919. static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
  2920. {
  2921. __be32 *p;
  2922. p = xdr_inline_decode(xdr, 4);
  2923. if (unlikely(!p))
  2924. goto out_overflow;
  2925. *attrlen = be32_to_cpup(p);
  2926. *savep = xdr_stream_pos(xdr);
  2927. return 0;
  2928. out_overflow:
  2929. print_overflow_msg(__func__, xdr);
  2930. return -EIO;
  2931. }
  2932. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2933. {
  2934. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2935. int ret;
  2936. ret = decode_attr_bitmap(xdr, bitmask);
  2937. if (unlikely(ret < 0))
  2938. return ret;
  2939. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2940. } else
  2941. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  2942. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  2943. bitmask[0], bitmask[1], bitmask[2]);
  2944. return 0;
  2945. }
  2946. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2947. {
  2948. __be32 *p;
  2949. int ret = 0;
  2950. *type = 0;
  2951. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2952. return -EIO;
  2953. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2954. p = xdr_inline_decode(xdr, 4);
  2955. if (unlikely(!p))
  2956. goto out_overflow;
  2957. *type = be32_to_cpup(p);
  2958. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2959. dprintk("%s: bad type %d\n", __func__, *type);
  2960. return -EIO;
  2961. }
  2962. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2963. ret = NFS_ATTR_FATTR_TYPE;
  2964. }
  2965. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  2966. return ret;
  2967. out_overflow:
  2968. print_overflow_msg(__func__, xdr);
  2969. return -EIO;
  2970. }
  2971. static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
  2972. uint32_t *bitmap, uint32_t *type)
  2973. {
  2974. __be32 *p;
  2975. *type = 0;
  2976. if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
  2977. return -EIO;
  2978. if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
  2979. p = xdr_inline_decode(xdr, 4);
  2980. if (unlikely(!p))
  2981. goto out_overflow;
  2982. *type = be32_to_cpup(p);
  2983. bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
  2984. }
  2985. dprintk("%s: expire type=0x%x\n", __func__, *type);
  2986. return 0;
  2987. out_overflow:
  2988. print_overflow_msg(__func__, xdr);
  2989. return -EIO;
  2990. }
  2991. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  2992. {
  2993. __be32 *p;
  2994. int ret = 0;
  2995. *change = 0;
  2996. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  2997. return -EIO;
  2998. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  2999. p = xdr_inline_decode(xdr, 8);
  3000. if (unlikely(!p))
  3001. goto out_overflow;
  3002. xdr_decode_hyper(p, change);
  3003. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  3004. ret = NFS_ATTR_FATTR_CHANGE;
  3005. }
  3006. dprintk("%s: change attribute=%Lu\n", __func__,
  3007. (unsigned long long)*change);
  3008. return ret;
  3009. out_overflow:
  3010. print_overflow_msg(__func__, xdr);
  3011. return -EIO;
  3012. }
  3013. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  3014. {
  3015. __be32 *p;
  3016. int ret = 0;
  3017. *size = 0;
  3018. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  3019. return -EIO;
  3020. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  3021. p = xdr_inline_decode(xdr, 8);
  3022. if (unlikely(!p))
  3023. goto out_overflow;
  3024. xdr_decode_hyper(p, size);
  3025. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  3026. ret = NFS_ATTR_FATTR_SIZE;
  3027. }
  3028. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  3029. return ret;
  3030. out_overflow:
  3031. print_overflow_msg(__func__, xdr);
  3032. return -EIO;
  3033. }
  3034. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3035. {
  3036. __be32 *p;
  3037. *res = 0;
  3038. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  3039. return -EIO;
  3040. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  3041. p = xdr_inline_decode(xdr, 4);
  3042. if (unlikely(!p))
  3043. goto out_overflow;
  3044. *res = be32_to_cpup(p);
  3045. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  3046. }
  3047. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  3048. return 0;
  3049. out_overflow:
  3050. print_overflow_msg(__func__, xdr);
  3051. return -EIO;
  3052. }
  3053. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3054. {
  3055. __be32 *p;
  3056. *res = 0;
  3057. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  3058. return -EIO;
  3059. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  3060. p = xdr_inline_decode(xdr, 4);
  3061. if (unlikely(!p))
  3062. goto out_overflow;
  3063. *res = be32_to_cpup(p);
  3064. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  3065. }
  3066. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  3067. return 0;
  3068. out_overflow:
  3069. print_overflow_msg(__func__, xdr);
  3070. return -EIO;
  3071. }
  3072. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  3073. {
  3074. __be32 *p;
  3075. int ret = 0;
  3076. fsid->major = 0;
  3077. fsid->minor = 0;
  3078. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  3079. return -EIO;
  3080. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  3081. p = xdr_inline_decode(xdr, 16);
  3082. if (unlikely(!p))
  3083. goto out_overflow;
  3084. p = xdr_decode_hyper(p, &fsid->major);
  3085. xdr_decode_hyper(p, &fsid->minor);
  3086. bitmap[0] &= ~FATTR4_WORD0_FSID;
  3087. ret = NFS_ATTR_FATTR_FSID;
  3088. }
  3089. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  3090. (unsigned long long)fsid->major,
  3091. (unsigned long long)fsid->minor);
  3092. return ret;
  3093. out_overflow:
  3094. print_overflow_msg(__func__, xdr);
  3095. return -EIO;
  3096. }
  3097. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3098. {
  3099. __be32 *p;
  3100. *res = 60;
  3101. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  3102. return -EIO;
  3103. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  3104. p = xdr_inline_decode(xdr, 4);
  3105. if (unlikely(!p))
  3106. goto out_overflow;
  3107. *res = be32_to_cpup(p);
  3108. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  3109. }
  3110. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  3111. return 0;
  3112. out_overflow:
  3113. print_overflow_msg(__func__, xdr);
  3114. return -EIO;
  3115. }
  3116. static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
  3117. {
  3118. __be32 *p;
  3119. if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
  3120. return -EIO;
  3121. if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
  3122. p = xdr_inline_decode(xdr, 4);
  3123. if (unlikely(!p))
  3124. goto out_overflow;
  3125. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  3126. *res = -be32_to_cpup(p);
  3127. }
  3128. return 0;
  3129. out_overflow:
  3130. print_overflow_msg(__func__, xdr);
  3131. return -EIO;
  3132. }
  3133. static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
  3134. uint32_t *bitmap, uint32_t *bitmask)
  3135. {
  3136. if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
  3137. int ret;
  3138. ret = decode_attr_bitmap(xdr, bitmask);
  3139. if (unlikely(ret < 0))
  3140. return ret;
  3141. bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
  3142. } else
  3143. bitmask[0] = bitmask[1] = bitmask[2] = 0;
  3144. dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
  3145. bitmask[0], bitmask[1], bitmask[2]);
  3146. return 0;
  3147. }
  3148. static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
  3149. {
  3150. __be32 *p;
  3151. int len;
  3152. if (fh != NULL)
  3153. memset(fh, 0, sizeof(*fh));
  3154. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
  3155. return -EIO;
  3156. if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
  3157. p = xdr_inline_decode(xdr, 4);
  3158. if (unlikely(!p))
  3159. goto out_overflow;
  3160. len = be32_to_cpup(p);
  3161. if (len > NFS4_FHSIZE)
  3162. return -EIO;
  3163. p = xdr_inline_decode(xdr, len);
  3164. if (unlikely(!p))
  3165. goto out_overflow;
  3166. if (fh != NULL) {
  3167. memcpy(fh->data, p, len);
  3168. fh->size = len;
  3169. }
  3170. bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
  3171. }
  3172. return 0;
  3173. out_overflow:
  3174. print_overflow_msg(__func__, xdr);
  3175. return -EIO;
  3176. }
  3177. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3178. {
  3179. __be32 *p;
  3180. *res = 0;
  3181. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  3182. return -EIO;
  3183. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  3184. p = xdr_inline_decode(xdr, 4);
  3185. if (unlikely(!p))
  3186. goto out_overflow;
  3187. *res = be32_to_cpup(p);
  3188. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  3189. }
  3190. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  3191. return 0;
  3192. out_overflow:
  3193. print_overflow_msg(__func__, xdr);
  3194. return -EIO;
  3195. }
  3196. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3197. {
  3198. __be32 *p;
  3199. int ret = 0;
  3200. *fileid = 0;
  3201. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  3202. return -EIO;
  3203. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  3204. p = xdr_inline_decode(xdr, 8);
  3205. if (unlikely(!p))
  3206. goto out_overflow;
  3207. xdr_decode_hyper(p, fileid);
  3208. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  3209. ret = NFS_ATTR_FATTR_FILEID;
  3210. }
  3211. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3212. return ret;
  3213. out_overflow:
  3214. print_overflow_msg(__func__, xdr);
  3215. return -EIO;
  3216. }
  3217. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  3218. {
  3219. __be32 *p;
  3220. int ret = 0;
  3221. *fileid = 0;
  3222. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  3223. return -EIO;
  3224. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  3225. p = xdr_inline_decode(xdr, 8);
  3226. if (unlikely(!p))
  3227. goto out_overflow;
  3228. xdr_decode_hyper(p, fileid);
  3229. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  3230. ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
  3231. }
  3232. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  3233. return ret;
  3234. out_overflow:
  3235. print_overflow_msg(__func__, xdr);
  3236. return -EIO;
  3237. }
  3238. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3239. {
  3240. __be32 *p;
  3241. int status = 0;
  3242. *res = 0;
  3243. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  3244. return -EIO;
  3245. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  3246. p = xdr_inline_decode(xdr, 8);
  3247. if (unlikely(!p))
  3248. goto out_overflow;
  3249. xdr_decode_hyper(p, res);
  3250. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  3251. }
  3252. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  3253. return status;
  3254. out_overflow:
  3255. print_overflow_msg(__func__, xdr);
  3256. return -EIO;
  3257. }
  3258. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3259. {
  3260. __be32 *p;
  3261. int status = 0;
  3262. *res = 0;
  3263. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  3264. return -EIO;
  3265. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  3266. p = xdr_inline_decode(xdr, 8);
  3267. if (unlikely(!p))
  3268. goto out_overflow;
  3269. xdr_decode_hyper(p, res);
  3270. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  3271. }
  3272. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  3273. return status;
  3274. out_overflow:
  3275. print_overflow_msg(__func__, xdr);
  3276. return -EIO;
  3277. }
  3278. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3279. {
  3280. __be32 *p;
  3281. int status = 0;
  3282. *res = 0;
  3283. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  3284. return -EIO;
  3285. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  3286. p = xdr_inline_decode(xdr, 8);
  3287. if (unlikely(!p))
  3288. goto out_overflow;
  3289. xdr_decode_hyper(p, res);
  3290. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  3291. }
  3292. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  3293. return status;
  3294. out_overflow:
  3295. print_overflow_msg(__func__, xdr);
  3296. return -EIO;
  3297. }
  3298. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  3299. {
  3300. u32 n;
  3301. __be32 *p;
  3302. int status = 0;
  3303. p = xdr_inline_decode(xdr, 4);
  3304. if (unlikely(!p))
  3305. goto out_overflow;
  3306. n = be32_to_cpup(p);
  3307. if (n == 0)
  3308. goto root_path;
  3309. dprintk("pathname4: ");
  3310. if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
  3311. dprintk("cannot parse %d components in path\n", n);
  3312. goto out_eio;
  3313. }
  3314. for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
  3315. struct nfs4_string *component = &path->components[path->ncomponents];
  3316. status = decode_opaque_inline(xdr, &component->len, &component->data);
  3317. if (unlikely(status != 0))
  3318. goto out_eio;
  3319. ifdebug (XDR)
  3320. pr_cont("%s%.*s ",
  3321. (path->ncomponents != n ? "/ " : ""),
  3322. component->len, component->data);
  3323. }
  3324. out:
  3325. return status;
  3326. root_path:
  3327. /* a root pathname is sent as a zero component4 */
  3328. path->ncomponents = 1;
  3329. path->components[0].len=0;
  3330. path->components[0].data=NULL;
  3331. dprintk("pathname4: /\n");
  3332. goto out;
  3333. out_eio:
  3334. dprintk(" status %d", status);
  3335. status = -EIO;
  3336. goto out;
  3337. out_overflow:
  3338. print_overflow_msg(__func__, xdr);
  3339. return -EIO;
  3340. }
  3341. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  3342. {
  3343. int n;
  3344. __be32 *p;
  3345. int status = -EIO;
  3346. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  3347. goto out;
  3348. status = 0;
  3349. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  3350. goto out;
  3351. bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
  3352. status = -EIO;
  3353. /* Ignore borken servers that return unrequested attrs */
  3354. if (unlikely(res == NULL))
  3355. goto out;
  3356. dprintk("%s: fsroot:\n", __func__);
  3357. status = decode_pathname(xdr, &res->fs_path);
  3358. if (unlikely(status != 0))
  3359. goto out;
  3360. p = xdr_inline_decode(xdr, 4);
  3361. if (unlikely(!p))
  3362. goto out_overflow;
  3363. n = be32_to_cpup(p);
  3364. if (n <= 0)
  3365. goto out_eio;
  3366. for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
  3367. u32 m;
  3368. struct nfs4_fs_location *loc;
  3369. if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
  3370. break;
  3371. loc = &res->locations[res->nlocations];
  3372. p = xdr_inline_decode(xdr, 4);
  3373. if (unlikely(!p))
  3374. goto out_overflow;
  3375. m = be32_to_cpup(p);
  3376. dprintk("%s: servers:\n", __func__);
  3377. for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
  3378. struct nfs4_string *server;
  3379. if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
  3380. unsigned int i;
  3381. dprintk("%s: using first %u of %u servers "
  3382. "returned for location %u\n",
  3383. __func__,
  3384. NFS4_FS_LOCATION_MAXSERVERS,
  3385. m, res->nlocations);
  3386. for (i = loc->nservers; i < m; i++) {
  3387. unsigned int len;
  3388. char *data;
  3389. status = decode_opaque_inline(xdr, &len, &data);
  3390. if (unlikely(status != 0))
  3391. goto out_eio;
  3392. }
  3393. break;
  3394. }
  3395. server = &loc->servers[loc->nservers];
  3396. status = decode_opaque_inline(xdr, &server->len, &server->data);
  3397. if (unlikely(status != 0))
  3398. goto out_eio;
  3399. dprintk("%s ", server->data);
  3400. }
  3401. status = decode_pathname(xdr, &loc->rootpath);
  3402. if (unlikely(status != 0))
  3403. goto out_eio;
  3404. }
  3405. if (res->nlocations != 0)
  3406. status = NFS_ATTR_FATTR_V4_LOCATIONS;
  3407. out:
  3408. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  3409. return status;
  3410. out_overflow:
  3411. print_overflow_msg(__func__, xdr);
  3412. out_eio:
  3413. status = -EIO;
  3414. goto out;
  3415. }
  3416. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3417. {
  3418. __be32 *p;
  3419. int status = 0;
  3420. *res = 0;
  3421. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  3422. return -EIO;
  3423. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  3424. p = xdr_inline_decode(xdr, 8);
  3425. if (unlikely(!p))
  3426. goto out_overflow;
  3427. xdr_decode_hyper(p, res);
  3428. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  3429. }
  3430. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  3431. return status;
  3432. out_overflow:
  3433. print_overflow_msg(__func__, xdr);
  3434. return -EIO;
  3435. }
  3436. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  3437. {
  3438. __be32 *p;
  3439. int status = 0;
  3440. *maxlink = 1;
  3441. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  3442. return -EIO;
  3443. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  3444. p = xdr_inline_decode(xdr, 4);
  3445. if (unlikely(!p))
  3446. goto out_overflow;
  3447. *maxlink = be32_to_cpup(p);
  3448. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  3449. }
  3450. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  3451. return status;
  3452. out_overflow:
  3453. print_overflow_msg(__func__, xdr);
  3454. return -EIO;
  3455. }
  3456. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  3457. {
  3458. __be32 *p;
  3459. int status = 0;
  3460. *maxname = 1024;
  3461. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  3462. return -EIO;
  3463. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  3464. p = xdr_inline_decode(xdr, 4);
  3465. if (unlikely(!p))
  3466. goto out_overflow;
  3467. *maxname = be32_to_cpup(p);
  3468. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  3469. }
  3470. dprintk("%s: maxname=%u\n", __func__, *maxname);
  3471. return status;
  3472. out_overflow:
  3473. print_overflow_msg(__func__, xdr);
  3474. return -EIO;
  3475. }
  3476. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3477. {
  3478. __be32 *p;
  3479. int status = 0;
  3480. *res = 1024;
  3481. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  3482. return -EIO;
  3483. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  3484. uint64_t maxread;
  3485. p = xdr_inline_decode(xdr, 8);
  3486. if (unlikely(!p))
  3487. goto out_overflow;
  3488. xdr_decode_hyper(p, &maxread);
  3489. if (maxread > 0x7FFFFFFF)
  3490. maxread = 0x7FFFFFFF;
  3491. *res = (uint32_t)maxread;
  3492. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  3493. }
  3494. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  3495. return status;
  3496. out_overflow:
  3497. print_overflow_msg(__func__, xdr);
  3498. return -EIO;
  3499. }
  3500. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  3501. {
  3502. __be32 *p;
  3503. int status = 0;
  3504. *res = 1024;
  3505. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  3506. return -EIO;
  3507. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  3508. uint64_t maxwrite;
  3509. p = xdr_inline_decode(xdr, 8);
  3510. if (unlikely(!p))
  3511. goto out_overflow;
  3512. xdr_decode_hyper(p, &maxwrite);
  3513. if (maxwrite > 0x7FFFFFFF)
  3514. maxwrite = 0x7FFFFFFF;
  3515. *res = (uint32_t)maxwrite;
  3516. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  3517. }
  3518. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  3519. return status;
  3520. out_overflow:
  3521. print_overflow_msg(__func__, xdr);
  3522. return -EIO;
  3523. }
  3524. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  3525. {
  3526. uint32_t tmp;
  3527. __be32 *p;
  3528. int ret = 0;
  3529. *mode = 0;
  3530. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  3531. return -EIO;
  3532. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  3533. p = xdr_inline_decode(xdr, 4);
  3534. if (unlikely(!p))
  3535. goto out_overflow;
  3536. tmp = be32_to_cpup(p);
  3537. *mode = tmp & ~S_IFMT;
  3538. bitmap[1] &= ~FATTR4_WORD1_MODE;
  3539. ret = NFS_ATTR_FATTR_MODE;
  3540. }
  3541. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  3542. return ret;
  3543. out_overflow:
  3544. print_overflow_msg(__func__, xdr);
  3545. return -EIO;
  3546. }
  3547. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  3548. {
  3549. __be32 *p;
  3550. int ret = 0;
  3551. *nlink = 1;
  3552. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  3553. return -EIO;
  3554. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  3555. p = xdr_inline_decode(xdr, 4);
  3556. if (unlikely(!p))
  3557. goto out_overflow;
  3558. *nlink = be32_to_cpup(p);
  3559. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  3560. ret = NFS_ATTR_FATTR_NLINK;
  3561. }
  3562. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  3563. return ret;
  3564. out_overflow:
  3565. print_overflow_msg(__func__, xdr);
  3566. return -EIO;
  3567. }
  3568. static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
  3569. struct nfs4_string *name, gfp_t gfp_flags)
  3570. {
  3571. ssize_t ret;
  3572. ret = xdr_stream_decode_string_dup(xdr, &name->data,
  3573. XDR_MAX_NETOBJ, gfp_flags);
  3574. name->len = 0;
  3575. if (ret > 0)
  3576. name->len = ret;
  3577. return ret;
  3578. }
  3579. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
  3580. const struct nfs_server *server, kuid_t *uid,
  3581. struct nfs4_string *owner_name)
  3582. {
  3583. ssize_t len;
  3584. char *p;
  3585. *uid = make_kuid(&init_user_ns, -2);
  3586. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  3587. return -EIO;
  3588. if (!(bitmap[1] & FATTR4_WORD1_OWNER))
  3589. return 0;
  3590. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  3591. if (owner_name != NULL) {
  3592. len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
  3593. if (len <= 0)
  3594. goto out;
  3595. dprintk("%s: name=%s\n", __func__, owner_name->data);
  3596. return NFS_ATTR_FATTR_OWNER_NAME;
  3597. } else {
  3598. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3599. XDR_MAX_NETOBJ);
  3600. if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
  3601. goto out;
  3602. dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
  3603. return NFS_ATTR_FATTR_OWNER;
  3604. }
  3605. out:
  3606. if (len != -EBADMSG)
  3607. return 0;
  3608. print_overflow_msg(__func__, xdr);
  3609. return -EIO;
  3610. }
  3611. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
  3612. const struct nfs_server *server, kgid_t *gid,
  3613. struct nfs4_string *group_name)
  3614. {
  3615. ssize_t len;
  3616. char *p;
  3617. *gid = make_kgid(&init_user_ns, -2);
  3618. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  3619. return -EIO;
  3620. if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
  3621. return 0;
  3622. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  3623. if (group_name != NULL) {
  3624. len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
  3625. if (len <= 0)
  3626. goto out;
  3627. dprintk("%s: name=%s\n", __func__, group_name->data);
  3628. return NFS_ATTR_FATTR_GROUP_NAME;
  3629. } else {
  3630. len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
  3631. XDR_MAX_NETOBJ);
  3632. if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
  3633. goto out;
  3634. dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
  3635. return NFS_ATTR_FATTR_GROUP;
  3636. }
  3637. out:
  3638. if (len != -EBADMSG)
  3639. return 0;
  3640. print_overflow_msg(__func__, xdr);
  3641. return -EIO;
  3642. }
  3643. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  3644. {
  3645. uint32_t major = 0, minor = 0;
  3646. __be32 *p;
  3647. int ret = 0;
  3648. *rdev = MKDEV(0,0);
  3649. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  3650. return -EIO;
  3651. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  3652. dev_t tmp;
  3653. p = xdr_inline_decode(xdr, 8);
  3654. if (unlikely(!p))
  3655. goto out_overflow;
  3656. major = be32_to_cpup(p++);
  3657. minor = be32_to_cpup(p);
  3658. tmp = MKDEV(major, minor);
  3659. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  3660. *rdev = tmp;
  3661. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  3662. ret = NFS_ATTR_FATTR_RDEV;
  3663. }
  3664. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  3665. return ret;
  3666. out_overflow:
  3667. print_overflow_msg(__func__, xdr);
  3668. return -EIO;
  3669. }
  3670. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3671. {
  3672. __be32 *p;
  3673. int status = 0;
  3674. *res = 0;
  3675. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  3676. return -EIO;
  3677. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  3678. p = xdr_inline_decode(xdr, 8);
  3679. if (unlikely(!p))
  3680. goto out_overflow;
  3681. xdr_decode_hyper(p, res);
  3682. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  3683. }
  3684. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  3685. return status;
  3686. out_overflow:
  3687. print_overflow_msg(__func__, xdr);
  3688. return -EIO;
  3689. }
  3690. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3691. {
  3692. __be32 *p;
  3693. int status = 0;
  3694. *res = 0;
  3695. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  3696. return -EIO;
  3697. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  3698. p = xdr_inline_decode(xdr, 8);
  3699. if (unlikely(!p))
  3700. goto out_overflow;
  3701. xdr_decode_hyper(p, res);
  3702. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  3703. }
  3704. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  3705. return status;
  3706. out_overflow:
  3707. print_overflow_msg(__func__, xdr);
  3708. return -EIO;
  3709. }
  3710. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  3711. {
  3712. __be32 *p;
  3713. int status = 0;
  3714. *res = 0;
  3715. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  3716. return -EIO;
  3717. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  3718. p = xdr_inline_decode(xdr, 8);
  3719. if (unlikely(!p))
  3720. goto out_overflow;
  3721. xdr_decode_hyper(p, res);
  3722. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  3723. }
  3724. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  3725. return status;
  3726. out_overflow:
  3727. print_overflow_msg(__func__, xdr);
  3728. return -EIO;
  3729. }
  3730. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  3731. {
  3732. __be32 *p;
  3733. int ret = 0;
  3734. *used = 0;
  3735. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  3736. return -EIO;
  3737. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  3738. p = xdr_inline_decode(xdr, 8);
  3739. if (unlikely(!p))
  3740. goto out_overflow;
  3741. xdr_decode_hyper(p, used);
  3742. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  3743. ret = NFS_ATTR_FATTR_SPACE_USED;
  3744. }
  3745. dprintk("%s: space used=%Lu\n", __func__,
  3746. (unsigned long long)*used);
  3747. return ret;
  3748. out_overflow:
  3749. print_overflow_msg(__func__, xdr);
  3750. return -EIO;
  3751. }
  3752. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  3753. {
  3754. __be32 *p;
  3755. uint64_t sec;
  3756. uint32_t nsec;
  3757. p = xdr_inline_decode(xdr, 12);
  3758. if (unlikely(!p))
  3759. goto out_overflow;
  3760. p = xdr_decode_hyper(p, &sec);
  3761. nsec = be32_to_cpup(p);
  3762. time->tv_sec = (time_t)sec;
  3763. time->tv_nsec = (long)nsec;
  3764. return 0;
  3765. out_overflow:
  3766. print_overflow_msg(__func__, xdr);
  3767. return -EIO;
  3768. }
  3769. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3770. {
  3771. int status = 0;
  3772. time->tv_sec = 0;
  3773. time->tv_nsec = 0;
  3774. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  3775. return -EIO;
  3776. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  3777. status = decode_attr_time(xdr, time);
  3778. if (status == 0)
  3779. status = NFS_ATTR_FATTR_ATIME;
  3780. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  3781. }
  3782. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  3783. return status;
  3784. }
  3785. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3786. {
  3787. int status = 0;
  3788. time->tv_sec = 0;
  3789. time->tv_nsec = 0;
  3790. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  3791. return -EIO;
  3792. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  3793. status = decode_attr_time(xdr, time);
  3794. if (status == 0)
  3795. status = NFS_ATTR_FATTR_CTIME;
  3796. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  3797. }
  3798. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  3799. return status;
  3800. }
  3801. static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
  3802. struct timespec *time)
  3803. {
  3804. int status = 0;
  3805. time->tv_sec = 0;
  3806. time->tv_nsec = 0;
  3807. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
  3808. return -EIO;
  3809. if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
  3810. status = decode_attr_time(xdr, time);
  3811. bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
  3812. }
  3813. dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
  3814. (long)time->tv_nsec);
  3815. return status;
  3816. }
  3817. static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
  3818. struct nfs4_label *label)
  3819. {
  3820. uint32_t pi = 0;
  3821. uint32_t lfs = 0;
  3822. __u32 len;
  3823. __be32 *p;
  3824. int status = 0;
  3825. if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
  3826. return -EIO;
  3827. if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
  3828. p = xdr_inline_decode(xdr, 4);
  3829. if (unlikely(!p))
  3830. goto out_overflow;
  3831. lfs = be32_to_cpup(p++);
  3832. p = xdr_inline_decode(xdr, 4);
  3833. if (unlikely(!p))
  3834. goto out_overflow;
  3835. pi = be32_to_cpup(p++);
  3836. p = xdr_inline_decode(xdr, 4);
  3837. if (unlikely(!p))
  3838. goto out_overflow;
  3839. len = be32_to_cpup(p++);
  3840. p = xdr_inline_decode(xdr, len);
  3841. if (unlikely(!p))
  3842. goto out_overflow;
  3843. if (len < NFS4_MAXLABELLEN) {
  3844. if (label) {
  3845. memcpy(label->label, p, len);
  3846. label->len = len;
  3847. label->pi = pi;
  3848. label->lfs = lfs;
  3849. status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
  3850. }
  3851. bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  3852. } else
  3853. printk(KERN_WARNING "%s: label too long (%u)!\n",
  3854. __func__, len);
  3855. }
  3856. if (label && label->label)
  3857. dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
  3858. (char *)label->label, label->len, label->pi, label->lfs);
  3859. return status;
  3860. out_overflow:
  3861. print_overflow_msg(__func__, xdr);
  3862. return -EIO;
  3863. }
  3864. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  3865. {
  3866. int status = 0;
  3867. time->tv_sec = 0;
  3868. time->tv_nsec = 0;
  3869. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  3870. return -EIO;
  3871. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  3872. status = decode_attr_time(xdr, time);
  3873. if (status == 0)
  3874. status = NFS_ATTR_FATTR_MTIME;
  3875. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  3876. }
  3877. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  3878. return status;
  3879. }
  3880. static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
  3881. {
  3882. unsigned int attrwords = XDR_QUADLEN(attrlen);
  3883. unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
  3884. if (unlikely(attrwords != nwords)) {
  3885. dprintk("%s: server returned incorrect attribute length: "
  3886. "%u %c %u\n",
  3887. __func__,
  3888. attrwords << 2,
  3889. (attrwords < nwords) ? '<' : '>',
  3890. nwords << 2);
  3891. return -EIO;
  3892. }
  3893. return 0;
  3894. }
  3895. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3896. {
  3897. __be32 *p;
  3898. p = xdr_inline_decode(xdr, 20);
  3899. if (unlikely(!p))
  3900. goto out_overflow;
  3901. cinfo->atomic = be32_to_cpup(p++);
  3902. p = xdr_decode_hyper(p, &cinfo->before);
  3903. xdr_decode_hyper(p, &cinfo->after);
  3904. return 0;
  3905. out_overflow:
  3906. print_overflow_msg(__func__, xdr);
  3907. return -EIO;
  3908. }
  3909. static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
  3910. {
  3911. __be32 *p;
  3912. uint32_t supp, acc;
  3913. int status;
  3914. status = decode_op_hdr(xdr, OP_ACCESS);
  3915. if (status)
  3916. return status;
  3917. p = xdr_inline_decode(xdr, 8);
  3918. if (unlikely(!p))
  3919. goto out_overflow;
  3920. supp = be32_to_cpup(p++);
  3921. acc = be32_to_cpup(p);
  3922. *supported = supp;
  3923. *access = acc;
  3924. return 0;
  3925. out_overflow:
  3926. print_overflow_msg(__func__, xdr);
  3927. return -EIO;
  3928. }
  3929. static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
  3930. {
  3931. ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
  3932. if (unlikely(ret < 0)) {
  3933. print_overflow_msg(__func__, xdr);
  3934. return -EIO;
  3935. }
  3936. return 0;
  3937. }
  3938. static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3939. {
  3940. return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
  3941. }
  3942. static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3943. {
  3944. stateid->type = NFS4_OPEN_STATEID_TYPE;
  3945. return decode_stateid(xdr, stateid);
  3946. }
  3947. static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3948. {
  3949. stateid->type = NFS4_LOCK_STATEID_TYPE;
  3950. return decode_stateid(xdr, stateid);
  3951. }
  3952. static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  3953. {
  3954. stateid->type = NFS4_DELEGATION_STATEID_TYPE;
  3955. return decode_stateid(xdr, stateid);
  3956. }
  3957. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  3958. {
  3959. int status;
  3960. status = decode_op_hdr(xdr, OP_CLOSE);
  3961. if (status != -EIO)
  3962. nfs_increment_open_seqid(status, res->seqid);
  3963. if (!status)
  3964. status = decode_open_stateid(xdr, &res->stateid);
  3965. return status;
  3966. }
  3967. static int decode_verifier(struct xdr_stream *xdr, void *verifier)
  3968. {
  3969. return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
  3970. }
  3971. static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
  3972. {
  3973. return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
  3974. }
  3975. static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
  3976. {
  3977. int status;
  3978. status = decode_op_hdr(xdr, OP_COMMIT);
  3979. if (!status)
  3980. status = decode_write_verifier(xdr, &res->verf->verifier);
  3981. return status;
  3982. }
  3983. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3984. {
  3985. __be32 *p;
  3986. uint32_t bmlen;
  3987. int status;
  3988. status = decode_op_hdr(xdr, OP_CREATE);
  3989. if (status)
  3990. return status;
  3991. if ((status = decode_change_info(xdr, cinfo)))
  3992. return status;
  3993. p = xdr_inline_decode(xdr, 4);
  3994. if (unlikely(!p))
  3995. goto out_overflow;
  3996. bmlen = be32_to_cpup(p);
  3997. p = xdr_inline_decode(xdr, bmlen << 2);
  3998. if (likely(p))
  3999. return 0;
  4000. out_overflow:
  4001. print_overflow_msg(__func__, xdr);
  4002. return -EIO;
  4003. }
  4004. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  4005. {
  4006. unsigned int savep;
  4007. uint32_t attrlen, bitmap[3] = {0};
  4008. int status;
  4009. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4010. goto xdr_error;
  4011. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4012. goto xdr_error;
  4013. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4014. goto xdr_error;
  4015. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  4016. goto xdr_error;
  4017. if ((status = decode_attr_fh_expire_type(xdr, bitmap,
  4018. &res->fh_expire_type)) != 0)
  4019. goto xdr_error;
  4020. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  4021. goto xdr_error;
  4022. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  4023. goto xdr_error;
  4024. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  4025. goto xdr_error;
  4026. if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
  4027. res->exclcreat_bitmask)) != 0)
  4028. goto xdr_error;
  4029. status = verify_attr_len(xdr, savep, attrlen);
  4030. xdr_error:
  4031. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4032. return status;
  4033. }
  4034. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  4035. {
  4036. unsigned int savep;
  4037. uint32_t attrlen, bitmap[3] = {0};
  4038. int status;
  4039. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4040. goto xdr_error;
  4041. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4042. goto xdr_error;
  4043. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4044. goto xdr_error;
  4045. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  4046. goto xdr_error;
  4047. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  4048. goto xdr_error;
  4049. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  4050. goto xdr_error;
  4051. status = -EIO;
  4052. if (unlikely(bitmap[0]))
  4053. goto xdr_error;
  4054. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  4055. goto xdr_error;
  4056. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  4057. goto xdr_error;
  4058. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  4059. goto xdr_error;
  4060. status = verify_attr_len(xdr, savep, attrlen);
  4061. xdr_error:
  4062. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4063. return status;
  4064. }
  4065. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  4066. {
  4067. unsigned int savep;
  4068. uint32_t attrlen, bitmap[3] = {0};
  4069. int status;
  4070. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4071. goto xdr_error;
  4072. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4073. goto xdr_error;
  4074. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4075. goto xdr_error;
  4076. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  4077. goto xdr_error;
  4078. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  4079. goto xdr_error;
  4080. status = verify_attr_len(xdr, savep, attrlen);
  4081. xdr_error:
  4082. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4083. return status;
  4084. }
  4085. static int decode_threshold_hint(struct xdr_stream *xdr,
  4086. uint32_t *bitmap,
  4087. uint64_t *res,
  4088. uint32_t hint_bit)
  4089. {
  4090. __be32 *p;
  4091. *res = 0;
  4092. if (likely(bitmap[0] & hint_bit)) {
  4093. p = xdr_inline_decode(xdr, 8);
  4094. if (unlikely(!p))
  4095. goto out_overflow;
  4096. xdr_decode_hyper(p, res);
  4097. }
  4098. return 0;
  4099. out_overflow:
  4100. print_overflow_msg(__func__, xdr);
  4101. return -EIO;
  4102. }
  4103. static int decode_first_threshold_item4(struct xdr_stream *xdr,
  4104. struct nfs4_threshold *res)
  4105. {
  4106. __be32 *p;
  4107. unsigned int savep;
  4108. uint32_t bitmap[3] = {0,}, attrlen;
  4109. int status;
  4110. /* layout type */
  4111. p = xdr_inline_decode(xdr, 4);
  4112. if (unlikely(!p)) {
  4113. print_overflow_msg(__func__, xdr);
  4114. return -EIO;
  4115. }
  4116. res->l_type = be32_to_cpup(p);
  4117. /* thi_hintset bitmap */
  4118. status = decode_attr_bitmap(xdr, bitmap);
  4119. if (status < 0)
  4120. goto xdr_error;
  4121. /* thi_hintlist length */
  4122. status = decode_attr_length(xdr, &attrlen, &savep);
  4123. if (status < 0)
  4124. goto xdr_error;
  4125. /* thi_hintlist */
  4126. status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
  4127. if (status < 0)
  4128. goto xdr_error;
  4129. status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
  4130. if (status < 0)
  4131. goto xdr_error;
  4132. status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
  4133. THRESHOLD_RD_IO);
  4134. if (status < 0)
  4135. goto xdr_error;
  4136. status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
  4137. THRESHOLD_WR_IO);
  4138. if (status < 0)
  4139. goto xdr_error;
  4140. status = verify_attr_len(xdr, savep, attrlen);
  4141. res->bm = bitmap[0];
  4142. dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
  4143. __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
  4144. res->wr_io_sz);
  4145. xdr_error:
  4146. dprintk("%s ret=%d!\n", __func__, status);
  4147. return status;
  4148. }
  4149. /*
  4150. * Thresholds on pNFS direct I/O vrs MDS I/O
  4151. */
  4152. static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
  4153. uint32_t *bitmap,
  4154. struct nfs4_threshold *res)
  4155. {
  4156. __be32 *p;
  4157. int status = 0;
  4158. uint32_t num;
  4159. if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
  4160. return -EIO;
  4161. if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
  4162. /* Did the server return an unrequested attribute? */
  4163. if (unlikely(res == NULL))
  4164. return -EREMOTEIO;
  4165. p = xdr_inline_decode(xdr, 4);
  4166. if (unlikely(!p))
  4167. goto out_overflow;
  4168. num = be32_to_cpup(p);
  4169. if (num == 0)
  4170. return 0;
  4171. if (num > 1)
  4172. printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
  4173. "drivers per filesystem not supported\n",
  4174. __func__);
  4175. status = decode_first_threshold_item4(xdr, res);
  4176. bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
  4177. }
  4178. return status;
  4179. out_overflow:
  4180. print_overflow_msg(__func__, xdr);
  4181. return -EIO;
  4182. }
  4183. static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
  4184. struct nfs_fattr *fattr, struct nfs_fh *fh,
  4185. struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
  4186. const struct nfs_server *server)
  4187. {
  4188. int status;
  4189. umode_t fmode = 0;
  4190. uint32_t type;
  4191. int32_t err;
  4192. status = decode_attr_type(xdr, bitmap, &type);
  4193. if (status < 0)
  4194. goto xdr_error;
  4195. fattr->mode = 0;
  4196. if (status != 0) {
  4197. fattr->mode |= nfs_type2fmt[type];
  4198. fattr->valid |= status;
  4199. }
  4200. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  4201. if (status < 0)
  4202. goto xdr_error;
  4203. fattr->valid |= status;
  4204. status = decode_attr_size(xdr, bitmap, &fattr->size);
  4205. if (status < 0)
  4206. goto xdr_error;
  4207. fattr->valid |= status;
  4208. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  4209. if (status < 0)
  4210. goto xdr_error;
  4211. fattr->valid |= status;
  4212. err = 0;
  4213. status = decode_attr_error(xdr, bitmap, &err);
  4214. if (status < 0)
  4215. goto xdr_error;
  4216. status = decode_attr_filehandle(xdr, bitmap, fh);
  4217. if (status < 0)
  4218. goto xdr_error;
  4219. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  4220. if (status < 0)
  4221. goto xdr_error;
  4222. fattr->valid |= status;
  4223. status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
  4224. if (status < 0)
  4225. goto xdr_error;
  4226. fattr->valid |= status;
  4227. status = -EIO;
  4228. if (unlikely(bitmap[0]))
  4229. goto xdr_error;
  4230. status = decode_attr_mode(xdr, bitmap, &fmode);
  4231. if (status < 0)
  4232. goto xdr_error;
  4233. if (status != 0) {
  4234. fattr->mode |= fmode;
  4235. fattr->valid |= status;
  4236. }
  4237. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  4238. if (status < 0)
  4239. goto xdr_error;
  4240. fattr->valid |= status;
  4241. status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
  4242. if (status < 0)
  4243. goto xdr_error;
  4244. fattr->valid |= status;
  4245. status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
  4246. if (status < 0)
  4247. goto xdr_error;
  4248. fattr->valid |= status;
  4249. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  4250. if (status < 0)
  4251. goto xdr_error;
  4252. fattr->valid |= status;
  4253. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  4254. if (status < 0)
  4255. goto xdr_error;
  4256. fattr->valid |= status;
  4257. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  4258. if (status < 0)
  4259. goto xdr_error;
  4260. fattr->valid |= status;
  4261. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  4262. if (status < 0)
  4263. goto xdr_error;
  4264. fattr->valid |= status;
  4265. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  4266. if (status < 0)
  4267. goto xdr_error;
  4268. fattr->valid |= status;
  4269. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
  4270. if (status < 0)
  4271. goto xdr_error;
  4272. fattr->valid |= status;
  4273. status = -EIO;
  4274. if (unlikely(bitmap[1]))
  4275. goto xdr_error;
  4276. status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
  4277. if (status < 0)
  4278. goto xdr_error;
  4279. if (label) {
  4280. status = decode_attr_security_label(xdr, bitmap, label);
  4281. if (status < 0)
  4282. goto xdr_error;
  4283. fattr->valid |= status;
  4284. }
  4285. xdr_error:
  4286. dprintk("%s: xdr returned %d\n", __func__, -status);
  4287. return status;
  4288. }
  4289. static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4290. struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
  4291. struct nfs4_label *label, const struct nfs_server *server)
  4292. {
  4293. unsigned int savep;
  4294. uint32_t attrlen,
  4295. bitmap[3] = {0};
  4296. int status;
  4297. status = decode_op_hdr(xdr, OP_GETATTR);
  4298. if (status < 0)
  4299. goto xdr_error;
  4300. status = decode_attr_bitmap(xdr, bitmap);
  4301. if (status < 0)
  4302. goto xdr_error;
  4303. status = decode_attr_length(xdr, &attrlen, &savep);
  4304. if (status < 0)
  4305. goto xdr_error;
  4306. status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
  4307. label, server);
  4308. if (status < 0)
  4309. goto xdr_error;
  4310. status = verify_attr_len(xdr, savep, attrlen);
  4311. xdr_error:
  4312. dprintk("%s: xdr returned %d\n", __func__, -status);
  4313. return status;
  4314. }
  4315. static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4316. struct nfs4_label *label, const struct nfs_server *server)
  4317. {
  4318. return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
  4319. }
  4320. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
  4321. const struct nfs_server *server)
  4322. {
  4323. return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
  4324. }
  4325. /*
  4326. * Decode potentially multiple layout types.
  4327. */
  4328. static int decode_pnfs_layout_types(struct xdr_stream *xdr,
  4329. struct nfs_fsinfo *fsinfo)
  4330. {
  4331. __be32 *p;
  4332. uint32_t i;
  4333. p = xdr_inline_decode(xdr, 4);
  4334. if (unlikely(!p))
  4335. goto out_overflow;
  4336. fsinfo->nlayouttypes = be32_to_cpup(p);
  4337. /* pNFS is not supported by the underlying file system */
  4338. if (fsinfo->nlayouttypes == 0)
  4339. return 0;
  4340. /* Decode and set first layout type, move xdr->p past unused types */
  4341. p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
  4342. if (unlikely(!p))
  4343. goto out_overflow;
  4344. /* If we get too many, then just cap it at the max */
  4345. if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
  4346. printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
  4347. __func__, fsinfo->nlayouttypes);
  4348. fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
  4349. }
  4350. for(i = 0; i < fsinfo->nlayouttypes; ++i)
  4351. fsinfo->layouttype[i] = be32_to_cpup(p++);
  4352. return 0;
  4353. out_overflow:
  4354. print_overflow_msg(__func__, xdr);
  4355. return -EIO;
  4356. }
  4357. /*
  4358. * The type of file system exported.
  4359. * Note we must ensure that layouttype is set in any non-error case.
  4360. */
  4361. static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
  4362. struct nfs_fsinfo *fsinfo)
  4363. {
  4364. int status = 0;
  4365. dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
  4366. if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
  4367. return -EIO;
  4368. if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
  4369. status = decode_pnfs_layout_types(xdr, fsinfo);
  4370. bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
  4371. }
  4372. return status;
  4373. }
  4374. /*
  4375. * The prefered block size for layout directed io
  4376. */
  4377. static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4378. uint32_t *res)
  4379. {
  4380. __be32 *p;
  4381. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4382. *res = 0;
  4383. if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
  4384. p = xdr_inline_decode(xdr, 4);
  4385. if (unlikely(!p)) {
  4386. print_overflow_msg(__func__, xdr);
  4387. return -EIO;
  4388. }
  4389. *res = be32_to_cpup(p);
  4390. bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
  4391. }
  4392. return 0;
  4393. }
  4394. /*
  4395. * The granularity of a CLONE operation.
  4396. */
  4397. static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
  4398. uint32_t *res)
  4399. {
  4400. __be32 *p;
  4401. dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
  4402. *res = 0;
  4403. if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
  4404. p = xdr_inline_decode(xdr, 4);
  4405. if (unlikely(!p)) {
  4406. print_overflow_msg(__func__, xdr);
  4407. return -EIO;
  4408. }
  4409. *res = be32_to_cpup(p);
  4410. bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
  4411. }
  4412. return 0;
  4413. }
  4414. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  4415. {
  4416. unsigned int savep;
  4417. uint32_t attrlen, bitmap[3];
  4418. int status;
  4419. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4420. goto xdr_error;
  4421. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4422. goto xdr_error;
  4423. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4424. goto xdr_error;
  4425. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  4426. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  4427. goto xdr_error;
  4428. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  4429. goto xdr_error;
  4430. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  4431. goto xdr_error;
  4432. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  4433. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  4434. goto xdr_error;
  4435. fsinfo->wtpref = fsinfo->wtmax;
  4436. status = -EIO;
  4437. if (unlikely(bitmap[0]))
  4438. goto xdr_error;
  4439. status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
  4440. if (status != 0)
  4441. goto xdr_error;
  4442. status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
  4443. if (status != 0)
  4444. goto xdr_error;
  4445. status = -EIO;
  4446. if (unlikely(bitmap[1]))
  4447. goto xdr_error;
  4448. status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
  4449. if (status)
  4450. goto xdr_error;
  4451. status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
  4452. if (status)
  4453. goto xdr_error;
  4454. status = verify_attr_len(xdr, savep, attrlen);
  4455. xdr_error:
  4456. dprintk("%s: xdr returned %d!\n", __func__, -status);
  4457. return status;
  4458. }
  4459. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  4460. {
  4461. __be32 *p;
  4462. uint32_t len;
  4463. int status;
  4464. /* Zero handle first to allow comparisons */
  4465. memset(fh, 0, sizeof(*fh));
  4466. status = decode_op_hdr(xdr, OP_GETFH);
  4467. if (status)
  4468. return status;
  4469. p = xdr_inline_decode(xdr, 4);
  4470. if (unlikely(!p))
  4471. goto out_overflow;
  4472. len = be32_to_cpup(p);
  4473. if (len > NFS4_FHSIZE)
  4474. return -EIO;
  4475. fh->size = len;
  4476. p = xdr_inline_decode(xdr, len);
  4477. if (unlikely(!p))
  4478. goto out_overflow;
  4479. memcpy(fh->data, p, len);
  4480. return 0;
  4481. out_overflow:
  4482. print_overflow_msg(__func__, xdr);
  4483. return -EIO;
  4484. }
  4485. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4486. {
  4487. int status;
  4488. status = decode_op_hdr(xdr, OP_LINK);
  4489. if (status)
  4490. return status;
  4491. return decode_change_info(xdr, cinfo);
  4492. }
  4493. /*
  4494. * We create the owner, so we know a proper owner.id length is 4.
  4495. */
  4496. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  4497. {
  4498. uint64_t offset, length, clientid;
  4499. __be32 *p;
  4500. uint32_t namelen, type;
  4501. p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
  4502. if (unlikely(!p))
  4503. goto out_overflow;
  4504. p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
  4505. p = xdr_decode_hyper(p, &length);
  4506. type = be32_to_cpup(p++); /* 4 byte read */
  4507. if (fl != NULL) { /* manipulate file lock */
  4508. fl->fl_start = (loff_t)offset;
  4509. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  4510. if (length == ~(uint64_t)0)
  4511. fl->fl_end = OFFSET_MAX;
  4512. fl->fl_type = F_WRLCK;
  4513. if (type & 1)
  4514. fl->fl_type = F_RDLCK;
  4515. fl->fl_pid = 0;
  4516. }
  4517. p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
  4518. namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
  4519. p = xdr_inline_decode(xdr, namelen); /* variable size field */
  4520. if (likely(p))
  4521. return -NFS4ERR_DENIED;
  4522. out_overflow:
  4523. print_overflow_msg(__func__, xdr);
  4524. return -EIO;
  4525. }
  4526. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  4527. {
  4528. int status;
  4529. status = decode_op_hdr(xdr, OP_LOCK);
  4530. if (status == -EIO)
  4531. goto out;
  4532. if (status == 0) {
  4533. status = decode_lock_stateid(xdr, &res->stateid);
  4534. if (unlikely(status))
  4535. goto out;
  4536. } else if (status == -NFS4ERR_DENIED)
  4537. status = decode_lock_denied(xdr, NULL);
  4538. if (res->open_seqid != NULL)
  4539. nfs_increment_open_seqid(status, res->open_seqid);
  4540. nfs_increment_lock_seqid(status, res->lock_seqid);
  4541. out:
  4542. return status;
  4543. }
  4544. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  4545. {
  4546. int status;
  4547. status = decode_op_hdr(xdr, OP_LOCKT);
  4548. if (status == -NFS4ERR_DENIED)
  4549. return decode_lock_denied(xdr, res->denied);
  4550. return status;
  4551. }
  4552. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  4553. {
  4554. int status;
  4555. status = decode_op_hdr(xdr, OP_LOCKU);
  4556. if (status != -EIO)
  4557. nfs_increment_lock_seqid(status, res->seqid);
  4558. if (status == 0)
  4559. status = decode_lock_stateid(xdr, &res->stateid);
  4560. return status;
  4561. }
  4562. static int decode_release_lockowner(struct xdr_stream *xdr)
  4563. {
  4564. return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
  4565. }
  4566. static int decode_lookup(struct xdr_stream *xdr)
  4567. {
  4568. return decode_op_hdr(xdr, OP_LOOKUP);
  4569. }
  4570. /* This is too sick! */
  4571. static int decode_space_limit(struct xdr_stream *xdr,
  4572. unsigned long *pagemod_limit)
  4573. {
  4574. __be32 *p;
  4575. uint32_t limit_type, nblocks, blocksize;
  4576. u64 maxsize = 0;
  4577. p = xdr_inline_decode(xdr, 12);
  4578. if (unlikely(!p))
  4579. goto out_overflow;
  4580. limit_type = be32_to_cpup(p++);
  4581. switch (limit_type) {
  4582. case NFS4_LIMIT_SIZE:
  4583. xdr_decode_hyper(p, &maxsize);
  4584. break;
  4585. case NFS4_LIMIT_BLOCKS:
  4586. nblocks = be32_to_cpup(p++);
  4587. blocksize = be32_to_cpup(p);
  4588. maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  4589. }
  4590. maxsize >>= PAGE_SHIFT;
  4591. *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
  4592. return 0;
  4593. out_overflow:
  4594. print_overflow_msg(__func__, xdr);
  4595. return -EIO;
  4596. }
  4597. static int decode_rw_delegation(struct xdr_stream *xdr,
  4598. uint32_t delegation_type,
  4599. struct nfs_openres *res)
  4600. {
  4601. __be32 *p;
  4602. int status;
  4603. status = decode_delegation_stateid(xdr, &res->delegation);
  4604. if (unlikely(status))
  4605. return status;
  4606. p = xdr_inline_decode(xdr, 4);
  4607. if (unlikely(!p))
  4608. goto out_overflow;
  4609. res->do_recall = be32_to_cpup(p);
  4610. switch (delegation_type) {
  4611. case NFS4_OPEN_DELEGATE_READ:
  4612. res->delegation_type = FMODE_READ;
  4613. break;
  4614. case NFS4_OPEN_DELEGATE_WRITE:
  4615. res->delegation_type = FMODE_WRITE|FMODE_READ;
  4616. if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
  4617. return -EIO;
  4618. }
  4619. return decode_ace(xdr, NULL);
  4620. out_overflow:
  4621. print_overflow_msg(__func__, xdr);
  4622. return -EIO;
  4623. }
  4624. static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4625. {
  4626. __be32 *p;
  4627. uint32_t why_no_delegation;
  4628. p = xdr_inline_decode(xdr, 4);
  4629. if (unlikely(!p))
  4630. goto out_overflow;
  4631. why_no_delegation = be32_to_cpup(p);
  4632. switch (why_no_delegation) {
  4633. case WND4_CONTENTION:
  4634. case WND4_RESOURCE:
  4635. xdr_inline_decode(xdr, 4);
  4636. /* Ignore for now */
  4637. }
  4638. return 0;
  4639. out_overflow:
  4640. print_overflow_msg(__func__, xdr);
  4641. return -EIO;
  4642. }
  4643. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  4644. {
  4645. __be32 *p;
  4646. uint32_t delegation_type;
  4647. p = xdr_inline_decode(xdr, 4);
  4648. if (unlikely(!p))
  4649. goto out_overflow;
  4650. delegation_type = be32_to_cpup(p);
  4651. res->delegation_type = 0;
  4652. switch (delegation_type) {
  4653. case NFS4_OPEN_DELEGATE_NONE:
  4654. return 0;
  4655. case NFS4_OPEN_DELEGATE_READ:
  4656. case NFS4_OPEN_DELEGATE_WRITE:
  4657. return decode_rw_delegation(xdr, delegation_type, res);
  4658. case NFS4_OPEN_DELEGATE_NONE_EXT:
  4659. return decode_no_delegation(xdr, res);
  4660. }
  4661. return -EIO;
  4662. out_overflow:
  4663. print_overflow_msg(__func__, xdr);
  4664. return -EIO;
  4665. }
  4666. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  4667. {
  4668. __be32 *p;
  4669. uint32_t savewords, bmlen, i;
  4670. int status;
  4671. if (!__decode_op_hdr(xdr, OP_OPEN, &status))
  4672. return status;
  4673. nfs_increment_open_seqid(status, res->seqid);
  4674. if (status)
  4675. return status;
  4676. status = decode_open_stateid(xdr, &res->stateid);
  4677. if (unlikely(status))
  4678. return status;
  4679. decode_change_info(xdr, &res->cinfo);
  4680. p = xdr_inline_decode(xdr, 8);
  4681. if (unlikely(!p))
  4682. goto out_overflow;
  4683. res->rflags = be32_to_cpup(p++);
  4684. bmlen = be32_to_cpup(p);
  4685. if (bmlen > 10)
  4686. goto xdr_error;
  4687. p = xdr_inline_decode(xdr, bmlen << 2);
  4688. if (unlikely(!p))
  4689. goto out_overflow;
  4690. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  4691. for (i = 0; i < savewords; ++i)
  4692. res->attrset[i] = be32_to_cpup(p++);
  4693. for (; i < NFS4_BITMAP_SIZE; i++)
  4694. res->attrset[i] = 0;
  4695. return decode_delegation(xdr, res);
  4696. xdr_error:
  4697. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  4698. return -EIO;
  4699. out_overflow:
  4700. print_overflow_msg(__func__, xdr);
  4701. return -EIO;
  4702. }
  4703. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  4704. {
  4705. int status;
  4706. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  4707. if (status != -EIO)
  4708. nfs_increment_open_seqid(status, res->seqid);
  4709. if (!status)
  4710. status = decode_open_stateid(xdr, &res->stateid);
  4711. return status;
  4712. }
  4713. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  4714. {
  4715. int status;
  4716. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  4717. if (status != -EIO)
  4718. nfs_increment_open_seqid(status, res->seqid);
  4719. if (!status)
  4720. status = decode_open_stateid(xdr, &res->stateid);
  4721. return status;
  4722. }
  4723. static int decode_putfh(struct xdr_stream *xdr)
  4724. {
  4725. return decode_op_hdr(xdr, OP_PUTFH);
  4726. }
  4727. static int decode_putrootfh(struct xdr_stream *xdr)
  4728. {
  4729. return decode_op_hdr(xdr, OP_PUTROOTFH);
  4730. }
  4731. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
  4732. struct nfs_pgio_res *res)
  4733. {
  4734. __be32 *p;
  4735. uint32_t count, eof, recvd;
  4736. int status;
  4737. status = decode_op_hdr(xdr, OP_READ);
  4738. if (status)
  4739. return status;
  4740. p = xdr_inline_decode(xdr, 8);
  4741. if (unlikely(!p))
  4742. goto out_overflow;
  4743. eof = be32_to_cpup(p++);
  4744. count = be32_to_cpup(p);
  4745. recvd = xdr_read_pages(xdr, count);
  4746. if (count > recvd) {
  4747. dprintk("NFS: server cheating in read reply: "
  4748. "count %u > recvd %u\n", count, recvd);
  4749. count = recvd;
  4750. eof = 0;
  4751. }
  4752. res->eof = eof;
  4753. res->count = count;
  4754. return 0;
  4755. out_overflow:
  4756. print_overflow_msg(__func__, xdr);
  4757. return -EIO;
  4758. }
  4759. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  4760. {
  4761. int status;
  4762. __be32 verf[2];
  4763. status = decode_op_hdr(xdr, OP_READDIR);
  4764. if (!status)
  4765. status = decode_verifier(xdr, readdir->verifier.data);
  4766. if (unlikely(status))
  4767. return status;
  4768. memcpy(verf, readdir->verifier.data, sizeof(verf));
  4769. dprintk("%s: verifier = %08x:%08x\n",
  4770. __func__, verf[0], verf[1]);
  4771. return xdr_read_pages(xdr, xdr->buf->page_len);
  4772. }
  4773. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  4774. {
  4775. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  4776. u32 len, recvd;
  4777. __be32 *p;
  4778. int status;
  4779. status = decode_op_hdr(xdr, OP_READLINK);
  4780. if (status)
  4781. return status;
  4782. /* Convert length of symlink */
  4783. p = xdr_inline_decode(xdr, 4);
  4784. if (unlikely(!p))
  4785. goto out_overflow;
  4786. len = be32_to_cpup(p);
  4787. if (len >= rcvbuf->page_len || len <= 0) {
  4788. dprintk("nfs: server returned giant symlink!\n");
  4789. return -ENAMETOOLONG;
  4790. }
  4791. recvd = xdr_read_pages(xdr, len);
  4792. if (recvd < len) {
  4793. dprintk("NFS: server cheating in readlink reply: "
  4794. "count %u > recvd %u\n", len, recvd);
  4795. return -EIO;
  4796. }
  4797. /*
  4798. * The XDR encode routine has set things up so that
  4799. * the link text will be copied directly into the
  4800. * buffer. We just have to do overflow-checking,
  4801. * and and null-terminate the text (the VFS expects
  4802. * null-termination).
  4803. */
  4804. xdr_terminate_string(rcvbuf, len);
  4805. return 0;
  4806. out_overflow:
  4807. print_overflow_msg(__func__, xdr);
  4808. return -EIO;
  4809. }
  4810. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  4811. {
  4812. int status;
  4813. status = decode_op_hdr(xdr, OP_REMOVE);
  4814. if (status)
  4815. goto out;
  4816. status = decode_change_info(xdr, cinfo);
  4817. out:
  4818. return status;
  4819. }
  4820. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  4821. struct nfs4_change_info *new_cinfo)
  4822. {
  4823. int status;
  4824. status = decode_op_hdr(xdr, OP_RENAME);
  4825. if (status)
  4826. goto out;
  4827. if ((status = decode_change_info(xdr, old_cinfo)))
  4828. goto out;
  4829. status = decode_change_info(xdr, new_cinfo);
  4830. out:
  4831. return status;
  4832. }
  4833. static int decode_renew(struct xdr_stream *xdr)
  4834. {
  4835. return decode_op_hdr(xdr, OP_RENEW);
  4836. }
  4837. static int
  4838. decode_restorefh(struct xdr_stream *xdr)
  4839. {
  4840. return decode_op_hdr(xdr, OP_RESTOREFH);
  4841. }
  4842. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  4843. struct nfs_getaclres *res)
  4844. {
  4845. unsigned int savep;
  4846. uint32_t attrlen,
  4847. bitmap[3] = {0};
  4848. int status;
  4849. unsigned int pg_offset;
  4850. res->acl_len = 0;
  4851. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  4852. goto out;
  4853. xdr_enter_page(xdr, xdr->buf->page_len);
  4854. /* Calculate the offset of the page data */
  4855. pg_offset = xdr->buf->head[0].iov_len;
  4856. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  4857. goto out;
  4858. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  4859. goto out;
  4860. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  4861. return -EIO;
  4862. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  4863. /* The bitmap (xdr len + bitmaps) and the attr xdr len words
  4864. * are stored with the acl data to handle the problem of
  4865. * variable length bitmaps.*/
  4866. res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
  4867. res->acl_len = attrlen;
  4868. /* Check for receive buffer overflow */
  4869. if (res->acl_len > (xdr->nwords << 2) ||
  4870. res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
  4871. res->acl_flags |= NFS4_ACL_TRUNC;
  4872. dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
  4873. attrlen, xdr->nwords << 2);
  4874. }
  4875. } else
  4876. status = -EOPNOTSUPP;
  4877. out:
  4878. return status;
  4879. }
  4880. static int
  4881. decode_savefh(struct xdr_stream *xdr)
  4882. {
  4883. return decode_op_hdr(xdr, OP_SAVEFH);
  4884. }
  4885. static int decode_setattr(struct xdr_stream *xdr)
  4886. {
  4887. __be32 *p;
  4888. uint32_t bmlen;
  4889. int status;
  4890. status = decode_op_hdr(xdr, OP_SETATTR);
  4891. if (status)
  4892. return status;
  4893. p = xdr_inline_decode(xdr, 4);
  4894. if (unlikely(!p))
  4895. goto out_overflow;
  4896. bmlen = be32_to_cpup(p);
  4897. p = xdr_inline_decode(xdr, bmlen << 2);
  4898. if (likely(p))
  4899. return 0;
  4900. out_overflow:
  4901. print_overflow_msg(__func__, xdr);
  4902. return -EIO;
  4903. }
  4904. static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
  4905. {
  4906. __be32 *p;
  4907. uint32_t opnum;
  4908. int32_t nfserr;
  4909. p = xdr_inline_decode(xdr, 8);
  4910. if (unlikely(!p))
  4911. goto out_overflow;
  4912. opnum = be32_to_cpup(p++);
  4913. if (opnum != OP_SETCLIENTID) {
  4914. dprintk("nfs: decode_setclientid: Server returned operation"
  4915. " %d\n", opnum);
  4916. return -EIO;
  4917. }
  4918. nfserr = be32_to_cpup(p);
  4919. if (nfserr == NFS_OK) {
  4920. p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
  4921. if (unlikely(!p))
  4922. goto out_overflow;
  4923. p = xdr_decode_hyper(p, &res->clientid);
  4924. memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
  4925. } else if (nfserr == NFSERR_CLID_INUSE) {
  4926. uint32_t len;
  4927. /* skip netid string */
  4928. p = xdr_inline_decode(xdr, 4);
  4929. if (unlikely(!p))
  4930. goto out_overflow;
  4931. len = be32_to_cpup(p);
  4932. p = xdr_inline_decode(xdr, len);
  4933. if (unlikely(!p))
  4934. goto out_overflow;
  4935. /* skip uaddr string */
  4936. p = xdr_inline_decode(xdr, 4);
  4937. if (unlikely(!p))
  4938. goto out_overflow;
  4939. len = be32_to_cpup(p);
  4940. p = xdr_inline_decode(xdr, len);
  4941. if (unlikely(!p))
  4942. goto out_overflow;
  4943. return -NFSERR_CLID_INUSE;
  4944. } else
  4945. return nfs4_stat_to_errno(nfserr);
  4946. return 0;
  4947. out_overflow:
  4948. print_overflow_msg(__func__, xdr);
  4949. return -EIO;
  4950. }
  4951. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  4952. {
  4953. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  4954. }
  4955. static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
  4956. {
  4957. __be32 *p;
  4958. int status;
  4959. status = decode_op_hdr(xdr, OP_WRITE);
  4960. if (status)
  4961. return status;
  4962. p = xdr_inline_decode(xdr, 8);
  4963. if (unlikely(!p))
  4964. goto out_overflow;
  4965. res->count = be32_to_cpup(p++);
  4966. res->verf->committed = be32_to_cpup(p++);
  4967. return decode_write_verifier(xdr, &res->verf->verifier);
  4968. out_overflow:
  4969. print_overflow_msg(__func__, xdr);
  4970. return -EIO;
  4971. }
  4972. static int decode_delegreturn(struct xdr_stream *xdr)
  4973. {
  4974. return decode_op_hdr(xdr, OP_DELEGRETURN);
  4975. }
  4976. static int decode_secinfo_gss(struct xdr_stream *xdr,
  4977. struct nfs4_secinfo4 *flavor)
  4978. {
  4979. u32 oid_len;
  4980. __be32 *p;
  4981. p = xdr_inline_decode(xdr, 4);
  4982. if (unlikely(!p))
  4983. goto out_overflow;
  4984. oid_len = be32_to_cpup(p);
  4985. if (oid_len > GSS_OID_MAX_LEN)
  4986. goto out_err;
  4987. p = xdr_inline_decode(xdr, oid_len);
  4988. if (unlikely(!p))
  4989. goto out_overflow;
  4990. memcpy(flavor->flavor_info.oid.data, p, oid_len);
  4991. flavor->flavor_info.oid.len = oid_len;
  4992. p = xdr_inline_decode(xdr, 8);
  4993. if (unlikely(!p))
  4994. goto out_overflow;
  4995. flavor->flavor_info.qop = be32_to_cpup(p++);
  4996. flavor->flavor_info.service = be32_to_cpup(p);
  4997. return 0;
  4998. out_overflow:
  4999. print_overflow_msg(__func__, xdr);
  5000. return -EIO;
  5001. out_err:
  5002. return -EINVAL;
  5003. }
  5004. static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5005. {
  5006. struct nfs4_secinfo4 *sec_flavor;
  5007. unsigned int i, num_flavors;
  5008. int status;
  5009. __be32 *p;
  5010. p = xdr_inline_decode(xdr, 4);
  5011. if (unlikely(!p))
  5012. goto out_overflow;
  5013. res->flavors->num_flavors = 0;
  5014. num_flavors = be32_to_cpup(p);
  5015. for (i = 0; i < num_flavors; i++) {
  5016. sec_flavor = &res->flavors->flavors[i];
  5017. if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
  5018. break;
  5019. p = xdr_inline_decode(xdr, 4);
  5020. if (unlikely(!p))
  5021. goto out_overflow;
  5022. sec_flavor->flavor = be32_to_cpup(p);
  5023. if (sec_flavor->flavor == RPC_AUTH_GSS) {
  5024. status = decode_secinfo_gss(xdr, sec_flavor);
  5025. if (status)
  5026. goto out;
  5027. }
  5028. res->flavors->num_flavors++;
  5029. }
  5030. status = 0;
  5031. out:
  5032. return status;
  5033. out_overflow:
  5034. print_overflow_msg(__func__, xdr);
  5035. return -EIO;
  5036. }
  5037. static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5038. {
  5039. int status = decode_op_hdr(xdr, OP_SECINFO);
  5040. if (status)
  5041. return status;
  5042. return decode_secinfo_common(xdr, res);
  5043. }
  5044. #if defined(CONFIG_NFS_V4_1)
  5045. static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
  5046. {
  5047. int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
  5048. if (status)
  5049. return status;
  5050. return decode_secinfo_common(xdr, res);
  5051. }
  5052. static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
  5053. {
  5054. __be32 *p;
  5055. uint32_t bitmap_words;
  5056. unsigned int i;
  5057. p = xdr_inline_decode(xdr, 4);
  5058. if (!p)
  5059. return -EIO;
  5060. bitmap_words = be32_to_cpup(p++);
  5061. if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
  5062. return -EIO;
  5063. p = xdr_inline_decode(xdr, 4 * bitmap_words);
  5064. for (i = 0; i < bitmap_words; i++)
  5065. op_map->u.words[i] = be32_to_cpup(p++);
  5066. return 0;
  5067. }
  5068. static int decode_exchange_id(struct xdr_stream *xdr,
  5069. struct nfs41_exchange_id_res *res)
  5070. {
  5071. __be32 *p;
  5072. uint32_t dummy;
  5073. char *dummy_str;
  5074. int status;
  5075. uint32_t impl_id_count;
  5076. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  5077. if (status)
  5078. return status;
  5079. p = xdr_inline_decode(xdr, 8);
  5080. if (unlikely(!p))
  5081. goto out_overflow;
  5082. xdr_decode_hyper(p, &res->clientid);
  5083. p = xdr_inline_decode(xdr, 12);
  5084. if (unlikely(!p))
  5085. goto out_overflow;
  5086. res->seqid = be32_to_cpup(p++);
  5087. res->flags = be32_to_cpup(p++);
  5088. res->state_protect.how = be32_to_cpup(p);
  5089. switch (res->state_protect.how) {
  5090. case SP4_NONE:
  5091. break;
  5092. case SP4_MACH_CRED:
  5093. status = decode_op_map(xdr, &res->state_protect.enforce);
  5094. if (status)
  5095. return status;
  5096. status = decode_op_map(xdr, &res->state_protect.allow);
  5097. if (status)
  5098. return status;
  5099. break;
  5100. default:
  5101. WARN_ON_ONCE(1);
  5102. return -EIO;
  5103. }
  5104. /* server_owner4.so_minor_id */
  5105. p = xdr_inline_decode(xdr, 8);
  5106. if (unlikely(!p))
  5107. goto out_overflow;
  5108. p = xdr_decode_hyper(p, &res->server_owner->minor_id);
  5109. /* server_owner4.so_major_id */
  5110. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5111. if (unlikely(status))
  5112. return status;
  5113. memcpy(res->server_owner->major_id, dummy_str, dummy);
  5114. res->server_owner->major_id_sz = dummy;
  5115. /* server_scope4 */
  5116. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5117. if (unlikely(status))
  5118. return status;
  5119. memcpy(res->server_scope->server_scope, dummy_str, dummy);
  5120. res->server_scope->server_scope_sz = dummy;
  5121. /* Implementation Id */
  5122. p = xdr_inline_decode(xdr, 4);
  5123. if (unlikely(!p))
  5124. goto out_overflow;
  5125. impl_id_count = be32_to_cpup(p++);
  5126. if (impl_id_count) {
  5127. /* nii_domain */
  5128. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5129. if (unlikely(status))
  5130. return status;
  5131. memcpy(res->impl_id->domain, dummy_str, dummy);
  5132. /* nii_name */
  5133. status = decode_opaque_inline(xdr, &dummy, &dummy_str);
  5134. if (unlikely(status))
  5135. return status;
  5136. memcpy(res->impl_id->name, dummy_str, dummy);
  5137. /* nii_date */
  5138. p = xdr_inline_decode(xdr, 12);
  5139. if (unlikely(!p))
  5140. goto out_overflow;
  5141. p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
  5142. res->impl_id->date.nseconds = be32_to_cpup(p);
  5143. /* if there's more than one entry, ignore the rest */
  5144. }
  5145. return 0;
  5146. out_overflow:
  5147. print_overflow_msg(__func__, xdr);
  5148. return -EIO;
  5149. }
  5150. static int decode_chan_attrs(struct xdr_stream *xdr,
  5151. struct nfs4_channel_attrs *attrs)
  5152. {
  5153. __be32 *p;
  5154. u32 nr_attrs, val;
  5155. p = xdr_inline_decode(xdr, 28);
  5156. if (unlikely(!p))
  5157. goto out_overflow;
  5158. val = be32_to_cpup(p++); /* headerpadsz */
  5159. if (val)
  5160. return -EINVAL; /* no support for header padding yet */
  5161. attrs->max_rqst_sz = be32_to_cpup(p++);
  5162. attrs->max_resp_sz = be32_to_cpup(p++);
  5163. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  5164. attrs->max_ops = be32_to_cpup(p++);
  5165. attrs->max_reqs = be32_to_cpup(p++);
  5166. nr_attrs = be32_to_cpup(p);
  5167. if (unlikely(nr_attrs > 1)) {
  5168. printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
  5169. "count %u\n", __func__, nr_attrs);
  5170. return -EINVAL;
  5171. }
  5172. if (nr_attrs == 1) {
  5173. p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
  5174. if (unlikely(!p))
  5175. goto out_overflow;
  5176. }
  5177. return 0;
  5178. out_overflow:
  5179. print_overflow_msg(__func__, xdr);
  5180. return -EIO;
  5181. }
  5182. static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
  5183. {
  5184. return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
  5185. }
  5186. static int decode_bind_conn_to_session(struct xdr_stream *xdr,
  5187. struct nfs41_bind_conn_to_session_res *res)
  5188. {
  5189. __be32 *p;
  5190. int status;
  5191. status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
  5192. if (!status)
  5193. status = decode_sessionid(xdr, &res->sessionid);
  5194. if (unlikely(status))
  5195. return status;
  5196. /* dir flags, rdma mode bool */
  5197. p = xdr_inline_decode(xdr, 8);
  5198. if (unlikely(!p))
  5199. goto out_overflow;
  5200. res->dir = be32_to_cpup(p++);
  5201. if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
  5202. return -EIO;
  5203. if (be32_to_cpup(p) == 0)
  5204. res->use_conn_in_rdma_mode = false;
  5205. else
  5206. res->use_conn_in_rdma_mode = true;
  5207. return 0;
  5208. out_overflow:
  5209. print_overflow_msg(__func__, xdr);
  5210. return -EIO;
  5211. }
  5212. static int decode_create_session(struct xdr_stream *xdr,
  5213. struct nfs41_create_session_res *res)
  5214. {
  5215. __be32 *p;
  5216. int status;
  5217. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  5218. if (!status)
  5219. status = decode_sessionid(xdr, &res->sessionid);
  5220. if (unlikely(status))
  5221. return status;
  5222. /* seqid, flags */
  5223. p = xdr_inline_decode(xdr, 8);
  5224. if (unlikely(!p))
  5225. goto out_overflow;
  5226. res->seqid = be32_to_cpup(p++);
  5227. res->flags = be32_to_cpup(p);
  5228. /* Channel attributes */
  5229. status = decode_chan_attrs(xdr, &res->fc_attrs);
  5230. if (!status)
  5231. status = decode_chan_attrs(xdr, &res->bc_attrs);
  5232. return status;
  5233. out_overflow:
  5234. print_overflow_msg(__func__, xdr);
  5235. return -EIO;
  5236. }
  5237. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  5238. {
  5239. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  5240. }
  5241. static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
  5242. {
  5243. return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
  5244. }
  5245. static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
  5246. {
  5247. return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
  5248. }
  5249. #endif /* CONFIG_NFS_V4_1 */
  5250. static int decode_sequence(struct xdr_stream *xdr,
  5251. struct nfs4_sequence_res *res,
  5252. struct rpc_rqst *rqstp)
  5253. {
  5254. #if defined(CONFIG_NFS_V4_1)
  5255. struct nfs4_session *session;
  5256. struct nfs4_sessionid id;
  5257. u32 dummy;
  5258. int status;
  5259. __be32 *p;
  5260. if (res->sr_slot == NULL)
  5261. return 0;
  5262. if (!res->sr_slot->table->session)
  5263. return 0;
  5264. status = decode_op_hdr(xdr, OP_SEQUENCE);
  5265. if (!status)
  5266. status = decode_sessionid(xdr, &id);
  5267. if (unlikely(status))
  5268. goto out_err;
  5269. /*
  5270. * If the server returns different values for sessionID, slotID or
  5271. * sequence number, the server is looney tunes.
  5272. */
  5273. status = -EREMOTEIO;
  5274. session = res->sr_slot->table->session;
  5275. if (memcmp(id.data, session->sess_id.data,
  5276. NFS4_MAX_SESSIONID_LEN)) {
  5277. dprintk("%s Invalid session id\n", __func__);
  5278. goto out_err;
  5279. }
  5280. p = xdr_inline_decode(xdr, 20);
  5281. if (unlikely(!p))
  5282. goto out_overflow;
  5283. /* seqid */
  5284. dummy = be32_to_cpup(p++);
  5285. if (dummy != res->sr_slot->seq_nr) {
  5286. dprintk("%s Invalid sequence number\n", __func__);
  5287. goto out_err;
  5288. }
  5289. /* slot id */
  5290. dummy = be32_to_cpup(p++);
  5291. if (dummy != res->sr_slot->slot_nr) {
  5292. dprintk("%s Invalid slot id\n", __func__);
  5293. goto out_err;
  5294. }
  5295. /* highest slot id */
  5296. res->sr_highest_slotid = be32_to_cpup(p++);
  5297. /* target highest slot id */
  5298. res->sr_target_highest_slotid = be32_to_cpup(p++);
  5299. /* result flags */
  5300. res->sr_status_flags = be32_to_cpup(p);
  5301. status = 0;
  5302. out_err:
  5303. res->sr_status = status;
  5304. return status;
  5305. out_overflow:
  5306. print_overflow_msg(__func__, xdr);
  5307. status = -EIO;
  5308. goto out_err;
  5309. #else /* CONFIG_NFS_V4_1 */
  5310. return 0;
  5311. #endif /* CONFIG_NFS_V4_1 */
  5312. }
  5313. #if defined(CONFIG_NFS_V4_1)
  5314. static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
  5315. {
  5316. stateid->type = NFS4_LAYOUT_STATEID_TYPE;
  5317. return decode_stateid(xdr, stateid);
  5318. }
  5319. static int decode_getdeviceinfo(struct xdr_stream *xdr,
  5320. struct nfs4_getdeviceinfo_res *res)
  5321. {
  5322. struct pnfs_device *pdev = res->pdev;
  5323. __be32 *p;
  5324. uint32_t len, type;
  5325. int status;
  5326. status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
  5327. if (status) {
  5328. if (status == -ETOOSMALL) {
  5329. p = xdr_inline_decode(xdr, 4);
  5330. if (unlikely(!p))
  5331. goto out_overflow;
  5332. pdev->mincount = be32_to_cpup(p);
  5333. dprintk("%s: Min count too small. mincnt = %u\n",
  5334. __func__, pdev->mincount);
  5335. }
  5336. return status;
  5337. }
  5338. p = xdr_inline_decode(xdr, 8);
  5339. if (unlikely(!p))
  5340. goto out_overflow;
  5341. type = be32_to_cpup(p++);
  5342. if (type != pdev->layout_type) {
  5343. dprintk("%s: layout mismatch req: %u pdev: %u\n",
  5344. __func__, pdev->layout_type, type);
  5345. return -EINVAL;
  5346. }
  5347. /*
  5348. * Get the length of the opaque device_addr4. xdr_read_pages places
  5349. * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
  5350. * and places the remaining xdr data in xdr_buf->tail
  5351. */
  5352. pdev->mincount = be32_to_cpup(p);
  5353. if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
  5354. goto out_overflow;
  5355. /* Parse notification bitmap, verifying that it is zero. */
  5356. p = xdr_inline_decode(xdr, 4);
  5357. if (unlikely(!p))
  5358. goto out_overflow;
  5359. len = be32_to_cpup(p);
  5360. if (len) {
  5361. uint32_t i;
  5362. p = xdr_inline_decode(xdr, 4 * len);
  5363. if (unlikely(!p))
  5364. goto out_overflow;
  5365. res->notification = be32_to_cpup(p++);
  5366. for (i = 1; i < len; i++) {
  5367. if (be32_to_cpup(p++)) {
  5368. dprintk("%s: unsupported notification\n",
  5369. __func__);
  5370. return -EIO;
  5371. }
  5372. }
  5373. }
  5374. return 0;
  5375. out_overflow:
  5376. print_overflow_msg(__func__, xdr);
  5377. return -EIO;
  5378. }
  5379. static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  5380. struct nfs4_layoutget_res *res)
  5381. {
  5382. __be32 *p;
  5383. int status;
  5384. u32 layout_count;
  5385. u32 recvd;
  5386. status = decode_op_hdr(xdr, OP_LAYOUTGET);
  5387. if (status)
  5388. return status;
  5389. p = xdr_inline_decode(xdr, 4);
  5390. if (unlikely(!p))
  5391. goto out_overflow;
  5392. res->return_on_close = be32_to_cpup(p);
  5393. decode_layout_stateid(xdr, &res->stateid);
  5394. p = xdr_inline_decode(xdr, 4);
  5395. if (unlikely(!p))
  5396. goto out_overflow;
  5397. layout_count = be32_to_cpup(p);
  5398. if (!layout_count) {
  5399. dprintk("%s: server responded with empty layout array\n",
  5400. __func__);
  5401. return -EINVAL;
  5402. }
  5403. p = xdr_inline_decode(xdr, 28);
  5404. if (unlikely(!p))
  5405. goto out_overflow;
  5406. p = xdr_decode_hyper(p, &res->range.offset);
  5407. p = xdr_decode_hyper(p, &res->range.length);
  5408. res->range.iomode = be32_to_cpup(p++);
  5409. res->type = be32_to_cpup(p++);
  5410. res->layoutp->len = be32_to_cpup(p);
  5411. dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
  5412. __func__,
  5413. (unsigned long)res->range.offset,
  5414. (unsigned long)res->range.length,
  5415. res->range.iomode,
  5416. res->type,
  5417. res->layoutp->len);
  5418. recvd = xdr_read_pages(xdr, res->layoutp->len);
  5419. if (res->layoutp->len > recvd) {
  5420. dprintk("NFS: server cheating in layoutget reply: "
  5421. "layout len %u > recvd %u\n",
  5422. res->layoutp->len, recvd);
  5423. return -EINVAL;
  5424. }
  5425. if (layout_count > 1) {
  5426. /* We only handle a length one array at the moment. Any
  5427. * further entries are just ignored. Note that this means
  5428. * the client may see a response that is less than the
  5429. * minimum it requested.
  5430. */
  5431. dprintk("%s: server responded with %d layouts, dropping tail\n",
  5432. __func__, layout_count);
  5433. }
  5434. return 0;
  5435. out_overflow:
  5436. print_overflow_msg(__func__, xdr);
  5437. return -EIO;
  5438. }
  5439. static int decode_layoutreturn(struct xdr_stream *xdr,
  5440. struct nfs4_layoutreturn_res *res)
  5441. {
  5442. __be32 *p;
  5443. int status;
  5444. status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
  5445. if (status)
  5446. return status;
  5447. p = xdr_inline_decode(xdr, 4);
  5448. if (unlikely(!p))
  5449. goto out_overflow;
  5450. res->lrs_present = be32_to_cpup(p);
  5451. if (res->lrs_present)
  5452. status = decode_layout_stateid(xdr, &res->stateid);
  5453. return status;
  5454. out_overflow:
  5455. print_overflow_msg(__func__, xdr);
  5456. return -EIO;
  5457. }
  5458. static int decode_layoutcommit(struct xdr_stream *xdr,
  5459. struct rpc_rqst *req,
  5460. struct nfs4_layoutcommit_res *res)
  5461. {
  5462. __be32 *p;
  5463. __u32 sizechanged;
  5464. int status;
  5465. status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
  5466. res->status = status;
  5467. if (status)
  5468. return status;
  5469. p = xdr_inline_decode(xdr, 4);
  5470. if (unlikely(!p))
  5471. goto out_overflow;
  5472. sizechanged = be32_to_cpup(p);
  5473. if (sizechanged) {
  5474. /* throw away new size */
  5475. p = xdr_inline_decode(xdr, 8);
  5476. if (unlikely(!p))
  5477. goto out_overflow;
  5478. }
  5479. return 0;
  5480. out_overflow:
  5481. print_overflow_msg(__func__, xdr);
  5482. return -EIO;
  5483. }
  5484. static int decode_test_stateid(struct xdr_stream *xdr,
  5485. struct nfs41_test_stateid_res *res)
  5486. {
  5487. __be32 *p;
  5488. int status;
  5489. int num_res;
  5490. status = decode_op_hdr(xdr, OP_TEST_STATEID);
  5491. if (status)
  5492. return status;
  5493. p = xdr_inline_decode(xdr, 4);
  5494. if (unlikely(!p))
  5495. goto out_overflow;
  5496. num_res = be32_to_cpup(p++);
  5497. if (num_res != 1)
  5498. goto out;
  5499. p = xdr_inline_decode(xdr, 4);
  5500. if (unlikely(!p))
  5501. goto out_overflow;
  5502. res->status = be32_to_cpup(p++);
  5503. return status;
  5504. out_overflow:
  5505. print_overflow_msg(__func__, xdr);
  5506. out:
  5507. return -EIO;
  5508. }
  5509. static int decode_free_stateid(struct xdr_stream *xdr,
  5510. struct nfs41_free_stateid_res *res)
  5511. {
  5512. res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
  5513. return res->status;
  5514. }
  5515. #else
  5516. static inline
  5517. int decode_layoutreturn(struct xdr_stream *xdr,
  5518. struct nfs4_layoutreturn_res *res)
  5519. {
  5520. return 0;
  5521. }
  5522. #endif /* CONFIG_NFS_V4_1 */
  5523. /*
  5524. * END OF "GENERIC" DECODE ROUTINES.
  5525. */
  5526. /*
  5527. * Decode OPEN_DOWNGRADE response
  5528. */
  5529. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
  5530. struct xdr_stream *xdr,
  5531. void *data)
  5532. {
  5533. struct nfs_closeres *res = data;
  5534. struct compound_hdr hdr;
  5535. int status;
  5536. status = decode_compound_hdr(xdr, &hdr);
  5537. if (status)
  5538. goto out;
  5539. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5540. if (status)
  5541. goto out;
  5542. status = decode_putfh(xdr);
  5543. if (status)
  5544. goto out;
  5545. if (res->lr_res) {
  5546. status = decode_layoutreturn(xdr, res->lr_res);
  5547. res->lr_ret = status;
  5548. if (status)
  5549. goto out;
  5550. }
  5551. status = decode_open_downgrade(xdr, res);
  5552. out:
  5553. return status;
  5554. }
  5555. /*
  5556. * Decode ACCESS response
  5557. */
  5558. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5559. void *data)
  5560. {
  5561. struct nfs4_accessres *res = data;
  5562. struct compound_hdr hdr;
  5563. int status;
  5564. status = decode_compound_hdr(xdr, &hdr);
  5565. if (status)
  5566. goto out;
  5567. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5568. if (status)
  5569. goto out;
  5570. status = decode_putfh(xdr);
  5571. if (status != 0)
  5572. goto out;
  5573. status = decode_access(xdr, &res->supported, &res->access);
  5574. if (status != 0)
  5575. goto out;
  5576. decode_getfattr(xdr, res->fattr, res->server);
  5577. out:
  5578. return status;
  5579. }
  5580. /*
  5581. * Decode LOOKUP response
  5582. */
  5583. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5584. void *data)
  5585. {
  5586. struct nfs4_lookup_res *res = data;
  5587. struct compound_hdr hdr;
  5588. int status;
  5589. status = decode_compound_hdr(xdr, &hdr);
  5590. if (status)
  5591. goto out;
  5592. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5593. if (status)
  5594. goto out;
  5595. status = decode_putfh(xdr);
  5596. if (status)
  5597. goto out;
  5598. status = decode_lookup(xdr);
  5599. if (status)
  5600. goto out;
  5601. status = decode_getfh(xdr, res->fh);
  5602. if (status)
  5603. goto out;
  5604. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5605. out:
  5606. return status;
  5607. }
  5608. /*
  5609. * Decode LOOKUP_ROOT response
  5610. */
  5611. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
  5612. struct xdr_stream *xdr,
  5613. void *data)
  5614. {
  5615. struct nfs4_lookup_res *res = data;
  5616. struct compound_hdr hdr;
  5617. int status;
  5618. status = decode_compound_hdr(xdr, &hdr);
  5619. if (status)
  5620. goto out;
  5621. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5622. if (status)
  5623. goto out;
  5624. status = decode_putrootfh(xdr);
  5625. if (status)
  5626. goto out;
  5627. status = decode_getfh(xdr, res->fh);
  5628. if (status == 0)
  5629. status = decode_getfattr_label(xdr, res->fattr,
  5630. res->label, res->server);
  5631. out:
  5632. return status;
  5633. }
  5634. /*
  5635. * Decode REMOVE response
  5636. */
  5637. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5638. void *data)
  5639. {
  5640. struct nfs_removeres *res = data;
  5641. struct compound_hdr hdr;
  5642. int status;
  5643. status = decode_compound_hdr(xdr, &hdr);
  5644. if (status)
  5645. goto out;
  5646. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5647. if (status)
  5648. goto out;
  5649. status = decode_putfh(xdr);
  5650. if (status)
  5651. goto out;
  5652. status = decode_remove(xdr, &res->cinfo);
  5653. out:
  5654. return status;
  5655. }
  5656. /*
  5657. * Decode RENAME response
  5658. */
  5659. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5660. void *data)
  5661. {
  5662. struct nfs_renameres *res = data;
  5663. struct compound_hdr hdr;
  5664. int status;
  5665. status = decode_compound_hdr(xdr, &hdr);
  5666. if (status)
  5667. goto out;
  5668. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5669. if (status)
  5670. goto out;
  5671. status = decode_putfh(xdr);
  5672. if (status)
  5673. goto out;
  5674. status = decode_savefh(xdr);
  5675. if (status)
  5676. goto out;
  5677. status = decode_putfh(xdr);
  5678. if (status)
  5679. goto out;
  5680. status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
  5681. out:
  5682. return status;
  5683. }
  5684. /*
  5685. * Decode LINK response
  5686. */
  5687. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5688. void *data)
  5689. {
  5690. struct nfs4_link_res *res = data;
  5691. struct compound_hdr hdr;
  5692. int status;
  5693. status = decode_compound_hdr(xdr, &hdr);
  5694. if (status)
  5695. goto out;
  5696. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5697. if (status)
  5698. goto out;
  5699. status = decode_putfh(xdr);
  5700. if (status)
  5701. goto out;
  5702. status = decode_savefh(xdr);
  5703. if (status)
  5704. goto out;
  5705. status = decode_putfh(xdr);
  5706. if (status)
  5707. goto out;
  5708. status = decode_link(xdr, &res->cinfo);
  5709. if (status)
  5710. goto out;
  5711. /*
  5712. * Note order: OP_LINK leaves the directory as the current
  5713. * filehandle.
  5714. */
  5715. status = decode_restorefh(xdr);
  5716. if (status)
  5717. goto out;
  5718. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5719. out:
  5720. return status;
  5721. }
  5722. /*
  5723. * Decode CREATE response
  5724. */
  5725. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5726. void *data)
  5727. {
  5728. struct nfs4_create_res *res = data;
  5729. struct compound_hdr hdr;
  5730. int status;
  5731. status = decode_compound_hdr(xdr, &hdr);
  5732. if (status)
  5733. goto out;
  5734. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5735. if (status)
  5736. goto out;
  5737. status = decode_putfh(xdr);
  5738. if (status)
  5739. goto out;
  5740. status = decode_create(xdr, &res->dir_cinfo);
  5741. if (status)
  5742. goto out;
  5743. status = decode_getfh(xdr, res->fh);
  5744. if (status)
  5745. goto out;
  5746. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5747. out:
  5748. return status;
  5749. }
  5750. /*
  5751. * Decode SYMLINK response
  5752. */
  5753. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5754. void *res)
  5755. {
  5756. return nfs4_xdr_dec_create(rqstp, xdr, res);
  5757. }
  5758. /*
  5759. * Decode GETATTR response
  5760. */
  5761. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5762. void *data)
  5763. {
  5764. struct nfs4_getattr_res *res = data;
  5765. struct compound_hdr hdr;
  5766. int status;
  5767. status = decode_compound_hdr(xdr, &hdr);
  5768. if (status)
  5769. goto out;
  5770. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5771. if (status)
  5772. goto out;
  5773. status = decode_putfh(xdr);
  5774. if (status)
  5775. goto out;
  5776. status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5777. out:
  5778. return status;
  5779. }
  5780. /*
  5781. * Encode an SETACL request
  5782. */
  5783. static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
  5784. const void *data)
  5785. {
  5786. const struct nfs_setaclargs *args = data;
  5787. struct compound_hdr hdr = {
  5788. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  5789. };
  5790. encode_compound_hdr(xdr, req, &hdr);
  5791. encode_sequence(xdr, &args->seq_args, &hdr);
  5792. encode_putfh(xdr, args->fh, &hdr);
  5793. encode_setacl(xdr, args, &hdr);
  5794. encode_nops(&hdr);
  5795. }
  5796. /*
  5797. * Decode SETACL response
  5798. */
  5799. static int
  5800. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5801. void *data)
  5802. {
  5803. struct nfs_setaclres *res = data;
  5804. struct compound_hdr hdr;
  5805. int status;
  5806. status = decode_compound_hdr(xdr, &hdr);
  5807. if (status)
  5808. goto out;
  5809. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5810. if (status)
  5811. goto out;
  5812. status = decode_putfh(xdr);
  5813. if (status)
  5814. goto out;
  5815. status = decode_setattr(xdr);
  5816. out:
  5817. return status;
  5818. }
  5819. /*
  5820. * Decode GETACL response
  5821. */
  5822. static int
  5823. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5824. void *data)
  5825. {
  5826. struct nfs_getaclres *res = data;
  5827. struct compound_hdr hdr;
  5828. int status;
  5829. if (res->acl_scratch != NULL) {
  5830. void *p = page_address(res->acl_scratch);
  5831. xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
  5832. }
  5833. status = decode_compound_hdr(xdr, &hdr);
  5834. if (status)
  5835. goto out;
  5836. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5837. if (status)
  5838. goto out;
  5839. status = decode_putfh(xdr);
  5840. if (status)
  5841. goto out;
  5842. status = decode_getacl(xdr, rqstp, res);
  5843. out:
  5844. return status;
  5845. }
  5846. /*
  5847. * Decode CLOSE response
  5848. */
  5849. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5850. void *data)
  5851. {
  5852. struct nfs_closeres *res = data;
  5853. struct compound_hdr hdr;
  5854. int status;
  5855. status = decode_compound_hdr(xdr, &hdr);
  5856. if (status)
  5857. goto out;
  5858. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5859. if (status)
  5860. goto out;
  5861. status = decode_putfh(xdr);
  5862. if (status)
  5863. goto out;
  5864. if (res->lr_res) {
  5865. status = decode_layoutreturn(xdr, res->lr_res);
  5866. res->lr_ret = status;
  5867. if (status)
  5868. goto out;
  5869. }
  5870. if (res->fattr != NULL) {
  5871. status = decode_getfattr(xdr, res->fattr, res->server);
  5872. if (status != 0)
  5873. goto out;
  5874. }
  5875. status = decode_close(xdr, res);
  5876. out:
  5877. return status;
  5878. }
  5879. /*
  5880. * Decode OPEN response
  5881. */
  5882. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5883. void *data)
  5884. {
  5885. struct nfs_openres *res = data;
  5886. struct compound_hdr hdr;
  5887. int status;
  5888. status = decode_compound_hdr(xdr, &hdr);
  5889. if (status)
  5890. goto out;
  5891. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5892. if (status)
  5893. goto out;
  5894. status = decode_putfh(xdr);
  5895. if (status)
  5896. goto out;
  5897. status = decode_open(xdr, res);
  5898. if (status)
  5899. goto out;
  5900. status = decode_getfh(xdr, &res->fh);
  5901. if (status)
  5902. goto out;
  5903. if (res->access_request)
  5904. decode_access(xdr, &res->access_supported, &res->access_result);
  5905. decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
  5906. out:
  5907. return status;
  5908. }
  5909. /*
  5910. * Decode OPEN_CONFIRM response
  5911. */
  5912. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
  5913. struct xdr_stream *xdr,
  5914. void *data)
  5915. {
  5916. struct nfs_open_confirmres *res = data;
  5917. struct compound_hdr hdr;
  5918. int status;
  5919. status = decode_compound_hdr(xdr, &hdr);
  5920. if (status)
  5921. goto out;
  5922. status = decode_putfh(xdr);
  5923. if (status)
  5924. goto out;
  5925. status = decode_open_confirm(xdr, res);
  5926. out:
  5927. return status;
  5928. }
  5929. /*
  5930. * Decode OPEN response
  5931. */
  5932. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
  5933. struct xdr_stream *xdr,
  5934. void *data)
  5935. {
  5936. struct nfs_openres *res = data;
  5937. struct compound_hdr hdr;
  5938. int status;
  5939. status = decode_compound_hdr(xdr, &hdr);
  5940. if (status)
  5941. goto out;
  5942. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5943. if (status)
  5944. goto out;
  5945. status = decode_putfh(xdr);
  5946. if (status)
  5947. goto out;
  5948. status = decode_open(xdr, res);
  5949. if (status)
  5950. goto out;
  5951. if (res->access_request)
  5952. decode_access(xdr, &res->access_supported, &res->access_result);
  5953. decode_getfattr(xdr, res->f_attr, res->server);
  5954. out:
  5955. return status;
  5956. }
  5957. /*
  5958. * Decode SETATTR response
  5959. */
  5960. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
  5961. struct xdr_stream *xdr,
  5962. void *data)
  5963. {
  5964. struct nfs_setattrres *res = data;
  5965. struct compound_hdr hdr;
  5966. int status;
  5967. status = decode_compound_hdr(xdr, &hdr);
  5968. if (status)
  5969. goto out;
  5970. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5971. if (status)
  5972. goto out;
  5973. status = decode_putfh(xdr);
  5974. if (status)
  5975. goto out;
  5976. status = decode_setattr(xdr);
  5977. if (status)
  5978. goto out;
  5979. decode_getfattr_label(xdr, res->fattr, res->label, res->server);
  5980. out:
  5981. return status;
  5982. }
  5983. /*
  5984. * Decode LOCK response
  5985. */
  5986. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  5987. void *data)
  5988. {
  5989. struct nfs_lock_res *res = data;
  5990. struct compound_hdr hdr;
  5991. int status;
  5992. status = decode_compound_hdr(xdr, &hdr);
  5993. if (status)
  5994. goto out;
  5995. status = decode_sequence(xdr, &res->seq_res, rqstp);
  5996. if (status)
  5997. goto out;
  5998. status = decode_putfh(xdr);
  5999. if (status)
  6000. goto out;
  6001. status = decode_lock(xdr, res);
  6002. out:
  6003. return status;
  6004. }
  6005. /*
  6006. * Decode LOCKT response
  6007. */
  6008. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6009. void *data)
  6010. {
  6011. struct nfs_lockt_res *res = data;
  6012. struct compound_hdr hdr;
  6013. int status;
  6014. status = decode_compound_hdr(xdr, &hdr);
  6015. if (status)
  6016. goto out;
  6017. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6018. if (status)
  6019. goto out;
  6020. status = decode_putfh(xdr);
  6021. if (status)
  6022. goto out;
  6023. status = decode_lockt(xdr, res);
  6024. out:
  6025. return status;
  6026. }
  6027. /*
  6028. * Decode LOCKU response
  6029. */
  6030. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6031. void *data)
  6032. {
  6033. struct nfs_locku_res *res = data;
  6034. struct compound_hdr hdr;
  6035. int status;
  6036. status = decode_compound_hdr(xdr, &hdr);
  6037. if (status)
  6038. goto out;
  6039. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6040. if (status)
  6041. goto out;
  6042. status = decode_putfh(xdr);
  6043. if (status)
  6044. goto out;
  6045. status = decode_locku(xdr, res);
  6046. out:
  6047. return status;
  6048. }
  6049. static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
  6050. struct xdr_stream *xdr, void *dummy)
  6051. {
  6052. struct compound_hdr hdr;
  6053. int status;
  6054. status = decode_compound_hdr(xdr, &hdr);
  6055. if (!status)
  6056. status = decode_release_lockowner(xdr);
  6057. return status;
  6058. }
  6059. /*
  6060. * Decode READLINK response
  6061. */
  6062. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
  6063. struct xdr_stream *xdr,
  6064. void *data)
  6065. {
  6066. struct nfs4_readlink_res *res = data;
  6067. struct compound_hdr hdr;
  6068. int status;
  6069. status = decode_compound_hdr(xdr, &hdr);
  6070. if (status)
  6071. goto out;
  6072. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6073. if (status)
  6074. goto out;
  6075. status = decode_putfh(xdr);
  6076. if (status)
  6077. goto out;
  6078. status = decode_readlink(xdr, rqstp);
  6079. out:
  6080. return status;
  6081. }
  6082. /*
  6083. * Decode READDIR response
  6084. */
  6085. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6086. void *data)
  6087. {
  6088. struct nfs4_readdir_res *res = data;
  6089. struct compound_hdr hdr;
  6090. int status;
  6091. status = decode_compound_hdr(xdr, &hdr);
  6092. if (status)
  6093. goto out;
  6094. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6095. if (status)
  6096. goto out;
  6097. status = decode_putfh(xdr);
  6098. if (status)
  6099. goto out;
  6100. status = decode_readdir(xdr, rqstp, res);
  6101. out:
  6102. return status;
  6103. }
  6104. /*
  6105. * Decode Read response
  6106. */
  6107. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6108. void *data)
  6109. {
  6110. struct nfs_pgio_res *res = data;
  6111. struct compound_hdr hdr;
  6112. int status;
  6113. status = decode_compound_hdr(xdr, &hdr);
  6114. res->op_status = hdr.status;
  6115. if (status)
  6116. goto out;
  6117. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6118. if (status)
  6119. goto out;
  6120. status = decode_putfh(xdr);
  6121. if (status)
  6122. goto out;
  6123. status = decode_read(xdr, rqstp, res);
  6124. if (!status)
  6125. status = res->count;
  6126. out:
  6127. return status;
  6128. }
  6129. /*
  6130. * Decode WRITE response
  6131. */
  6132. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6133. void *data)
  6134. {
  6135. struct nfs_pgio_res *res = data;
  6136. struct compound_hdr hdr;
  6137. int status;
  6138. status = decode_compound_hdr(xdr, &hdr);
  6139. res->op_status = hdr.status;
  6140. if (status)
  6141. goto out;
  6142. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6143. if (status)
  6144. goto out;
  6145. status = decode_putfh(xdr);
  6146. if (status)
  6147. goto out;
  6148. status = decode_write(xdr, res);
  6149. if (status)
  6150. goto out;
  6151. if (res->fattr)
  6152. decode_getfattr(xdr, res->fattr, res->server);
  6153. if (!status)
  6154. status = res->count;
  6155. out:
  6156. return status;
  6157. }
  6158. /*
  6159. * Decode COMMIT response
  6160. */
  6161. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6162. void *data)
  6163. {
  6164. struct nfs_commitres *res = data;
  6165. struct compound_hdr hdr;
  6166. int status;
  6167. status = decode_compound_hdr(xdr, &hdr);
  6168. res->op_status = hdr.status;
  6169. if (status)
  6170. goto out;
  6171. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6172. if (status)
  6173. goto out;
  6174. status = decode_putfh(xdr);
  6175. if (status)
  6176. goto out;
  6177. status = decode_commit(xdr, res);
  6178. out:
  6179. return status;
  6180. }
  6181. /*
  6182. * Decode FSINFO response
  6183. */
  6184. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
  6185. void *data)
  6186. {
  6187. struct nfs4_fsinfo_res *res = data;
  6188. struct compound_hdr hdr;
  6189. int status;
  6190. status = decode_compound_hdr(xdr, &hdr);
  6191. if (!status)
  6192. status = decode_sequence(xdr, &res->seq_res, req);
  6193. if (!status)
  6194. status = decode_putfh(xdr);
  6195. if (!status)
  6196. status = decode_fsinfo(xdr, res->fsinfo);
  6197. return status;
  6198. }
  6199. /*
  6200. * Decode PATHCONF response
  6201. */
  6202. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
  6203. void *data)
  6204. {
  6205. struct nfs4_pathconf_res *res = data;
  6206. struct compound_hdr hdr;
  6207. int status;
  6208. status = decode_compound_hdr(xdr, &hdr);
  6209. if (!status)
  6210. status = decode_sequence(xdr, &res->seq_res, req);
  6211. if (!status)
  6212. status = decode_putfh(xdr);
  6213. if (!status)
  6214. status = decode_pathconf(xdr, res->pathconf);
  6215. return status;
  6216. }
  6217. /*
  6218. * Decode STATFS response
  6219. */
  6220. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
  6221. void *data)
  6222. {
  6223. struct nfs4_statfs_res *res = data;
  6224. struct compound_hdr hdr;
  6225. int status;
  6226. status = decode_compound_hdr(xdr, &hdr);
  6227. if (!status)
  6228. status = decode_sequence(xdr, &res->seq_res, req);
  6229. if (!status)
  6230. status = decode_putfh(xdr);
  6231. if (!status)
  6232. status = decode_statfs(xdr, res->fsstat);
  6233. return status;
  6234. }
  6235. /*
  6236. * Decode GETATTR_BITMAP response
  6237. */
  6238. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
  6239. struct xdr_stream *xdr,
  6240. void *data)
  6241. {
  6242. struct nfs4_server_caps_res *res = data;
  6243. struct compound_hdr hdr;
  6244. int status;
  6245. status = decode_compound_hdr(xdr, &hdr);
  6246. if (status)
  6247. goto out;
  6248. status = decode_sequence(xdr, &res->seq_res, req);
  6249. if (status)
  6250. goto out;
  6251. status = decode_putfh(xdr);
  6252. if (status)
  6253. goto out;
  6254. status = decode_server_caps(xdr, res);
  6255. out:
  6256. return status;
  6257. }
  6258. /*
  6259. * Decode RENEW response
  6260. */
  6261. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
  6262. void *__unused)
  6263. {
  6264. struct compound_hdr hdr;
  6265. int status;
  6266. status = decode_compound_hdr(xdr, &hdr);
  6267. if (!status)
  6268. status = decode_renew(xdr);
  6269. return status;
  6270. }
  6271. /*
  6272. * Decode SETCLIENTID response
  6273. */
  6274. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
  6275. struct xdr_stream *xdr,
  6276. void *data)
  6277. {
  6278. struct nfs4_setclientid_res *res = data;
  6279. struct compound_hdr hdr;
  6280. int status;
  6281. status = decode_compound_hdr(xdr, &hdr);
  6282. if (!status)
  6283. status = decode_setclientid(xdr, res);
  6284. return status;
  6285. }
  6286. /*
  6287. * Decode SETCLIENTID_CONFIRM response
  6288. */
  6289. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
  6290. struct xdr_stream *xdr,
  6291. void *data)
  6292. {
  6293. struct compound_hdr hdr;
  6294. int status;
  6295. status = decode_compound_hdr(xdr, &hdr);
  6296. if (!status)
  6297. status = decode_setclientid_confirm(xdr);
  6298. return status;
  6299. }
  6300. /*
  6301. * Decode DELEGRETURN response
  6302. */
  6303. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
  6304. struct xdr_stream *xdr,
  6305. void *data)
  6306. {
  6307. struct nfs4_delegreturnres *res = data;
  6308. struct compound_hdr hdr;
  6309. int status;
  6310. status = decode_compound_hdr(xdr, &hdr);
  6311. if (status)
  6312. goto out;
  6313. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6314. if (status)
  6315. goto out;
  6316. status = decode_putfh(xdr);
  6317. if (status != 0)
  6318. goto out;
  6319. if (res->lr_res) {
  6320. status = decode_layoutreturn(xdr, res->lr_res);
  6321. res->lr_ret = status;
  6322. if (status)
  6323. goto out;
  6324. }
  6325. if (res->fattr) {
  6326. status = decode_getfattr(xdr, res->fattr, res->server);
  6327. if (status != 0)
  6328. goto out;
  6329. }
  6330. status = decode_delegreturn(xdr);
  6331. out:
  6332. return status;
  6333. }
  6334. /*
  6335. * Decode FS_LOCATIONS response
  6336. */
  6337. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
  6338. struct xdr_stream *xdr,
  6339. void *data)
  6340. {
  6341. struct nfs4_fs_locations_res *res = data;
  6342. struct compound_hdr hdr;
  6343. int status;
  6344. status = decode_compound_hdr(xdr, &hdr);
  6345. if (status)
  6346. goto out;
  6347. status = decode_sequence(xdr, &res->seq_res, req);
  6348. if (status)
  6349. goto out;
  6350. status = decode_putfh(xdr);
  6351. if (status)
  6352. goto out;
  6353. if (res->migration) {
  6354. xdr_enter_page(xdr, PAGE_SIZE);
  6355. status = decode_getfattr_generic(xdr,
  6356. &res->fs_locations->fattr,
  6357. NULL, res->fs_locations,
  6358. NULL, res->fs_locations->server);
  6359. if (status)
  6360. goto out;
  6361. if (res->renew)
  6362. status = decode_renew(xdr);
  6363. } else {
  6364. status = decode_lookup(xdr);
  6365. if (status)
  6366. goto out;
  6367. xdr_enter_page(xdr, PAGE_SIZE);
  6368. status = decode_getfattr_generic(xdr,
  6369. &res->fs_locations->fattr,
  6370. NULL, res->fs_locations,
  6371. NULL, res->fs_locations->server);
  6372. }
  6373. out:
  6374. return status;
  6375. }
  6376. /*
  6377. * Decode SECINFO response
  6378. */
  6379. static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
  6380. struct xdr_stream *xdr,
  6381. void *data)
  6382. {
  6383. struct nfs4_secinfo_res *res = data;
  6384. struct compound_hdr hdr;
  6385. int status;
  6386. status = decode_compound_hdr(xdr, &hdr);
  6387. if (status)
  6388. goto out;
  6389. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6390. if (status)
  6391. goto out;
  6392. status = decode_putfh(xdr);
  6393. if (status)
  6394. goto out;
  6395. status = decode_secinfo(xdr, res);
  6396. out:
  6397. return status;
  6398. }
  6399. /*
  6400. * Decode FSID_PRESENT response
  6401. */
  6402. static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
  6403. struct xdr_stream *xdr,
  6404. void *data)
  6405. {
  6406. struct nfs4_fsid_present_res *res = data;
  6407. struct compound_hdr hdr;
  6408. int status;
  6409. status = decode_compound_hdr(xdr, &hdr);
  6410. if (status)
  6411. goto out;
  6412. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6413. if (status)
  6414. goto out;
  6415. status = decode_putfh(xdr);
  6416. if (status)
  6417. goto out;
  6418. status = decode_getfh(xdr, res->fh);
  6419. if (status)
  6420. goto out;
  6421. if (res->renew)
  6422. status = decode_renew(xdr);
  6423. out:
  6424. return status;
  6425. }
  6426. #if defined(CONFIG_NFS_V4_1)
  6427. /*
  6428. * Decode BIND_CONN_TO_SESSION response
  6429. */
  6430. static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
  6431. struct xdr_stream *xdr,
  6432. void *res)
  6433. {
  6434. struct compound_hdr hdr;
  6435. int status;
  6436. status = decode_compound_hdr(xdr, &hdr);
  6437. if (!status)
  6438. status = decode_bind_conn_to_session(xdr, res);
  6439. return status;
  6440. }
  6441. /*
  6442. * Decode EXCHANGE_ID response
  6443. */
  6444. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
  6445. struct xdr_stream *xdr,
  6446. void *res)
  6447. {
  6448. struct compound_hdr hdr;
  6449. int status;
  6450. status = decode_compound_hdr(xdr, &hdr);
  6451. if (!status)
  6452. status = decode_exchange_id(xdr, res);
  6453. return status;
  6454. }
  6455. /*
  6456. * Decode CREATE_SESSION response
  6457. */
  6458. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
  6459. struct xdr_stream *xdr,
  6460. void *res)
  6461. {
  6462. struct compound_hdr hdr;
  6463. int status;
  6464. status = decode_compound_hdr(xdr, &hdr);
  6465. if (!status)
  6466. status = decode_create_session(xdr, res);
  6467. return status;
  6468. }
  6469. /*
  6470. * Decode DESTROY_SESSION response
  6471. */
  6472. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
  6473. struct xdr_stream *xdr,
  6474. void *res)
  6475. {
  6476. struct compound_hdr hdr;
  6477. int status;
  6478. status = decode_compound_hdr(xdr, &hdr);
  6479. if (!status)
  6480. status = decode_destroy_session(xdr, res);
  6481. return status;
  6482. }
  6483. /*
  6484. * Decode DESTROY_CLIENTID response
  6485. */
  6486. static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
  6487. struct xdr_stream *xdr,
  6488. void *res)
  6489. {
  6490. struct compound_hdr hdr;
  6491. int status;
  6492. status = decode_compound_hdr(xdr, &hdr);
  6493. if (!status)
  6494. status = decode_destroy_clientid(xdr, res);
  6495. return status;
  6496. }
  6497. /*
  6498. * Decode SEQUENCE response
  6499. */
  6500. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
  6501. struct xdr_stream *xdr,
  6502. void *res)
  6503. {
  6504. struct compound_hdr hdr;
  6505. int status;
  6506. status = decode_compound_hdr(xdr, &hdr);
  6507. if (!status)
  6508. status = decode_sequence(xdr, res, rqstp);
  6509. return status;
  6510. }
  6511. /*
  6512. * Decode GET_LEASE_TIME response
  6513. */
  6514. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
  6515. struct xdr_stream *xdr,
  6516. void *data)
  6517. {
  6518. struct nfs4_get_lease_time_res *res = data;
  6519. struct compound_hdr hdr;
  6520. int status;
  6521. status = decode_compound_hdr(xdr, &hdr);
  6522. if (!status)
  6523. status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
  6524. if (!status)
  6525. status = decode_putrootfh(xdr);
  6526. if (!status)
  6527. status = decode_fsinfo(xdr, res->lr_fsinfo);
  6528. return status;
  6529. }
  6530. /*
  6531. * Decode RECLAIM_COMPLETE response
  6532. */
  6533. static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
  6534. struct xdr_stream *xdr,
  6535. void *data)
  6536. {
  6537. struct nfs41_reclaim_complete_res *res = data;
  6538. struct compound_hdr hdr;
  6539. int status;
  6540. status = decode_compound_hdr(xdr, &hdr);
  6541. if (!status)
  6542. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6543. if (!status)
  6544. status = decode_reclaim_complete(xdr, NULL);
  6545. return status;
  6546. }
  6547. /*
  6548. * Decode GETDEVINFO response
  6549. */
  6550. static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
  6551. struct xdr_stream *xdr,
  6552. void *data)
  6553. {
  6554. struct nfs4_getdeviceinfo_res *res = data;
  6555. struct compound_hdr hdr;
  6556. int status;
  6557. status = decode_compound_hdr(xdr, &hdr);
  6558. if (status != 0)
  6559. goto out;
  6560. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6561. if (status != 0)
  6562. goto out;
  6563. status = decode_getdeviceinfo(xdr, res);
  6564. out:
  6565. return status;
  6566. }
  6567. /*
  6568. * Decode LAYOUTGET response
  6569. */
  6570. static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
  6571. struct xdr_stream *xdr,
  6572. void *data)
  6573. {
  6574. struct nfs4_layoutget_res *res = data;
  6575. struct compound_hdr hdr;
  6576. int status;
  6577. status = decode_compound_hdr(xdr, &hdr);
  6578. if (status)
  6579. goto out;
  6580. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6581. if (status)
  6582. goto out;
  6583. status = decode_putfh(xdr);
  6584. if (status)
  6585. goto out;
  6586. status = decode_layoutget(xdr, rqstp, res);
  6587. out:
  6588. return status;
  6589. }
  6590. /*
  6591. * Decode LAYOUTRETURN response
  6592. */
  6593. static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
  6594. struct xdr_stream *xdr,
  6595. void *data)
  6596. {
  6597. struct nfs4_layoutreturn_res *res = data;
  6598. struct compound_hdr hdr;
  6599. int status;
  6600. status = decode_compound_hdr(xdr, &hdr);
  6601. if (status)
  6602. goto out;
  6603. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6604. if (status)
  6605. goto out;
  6606. status = decode_putfh(xdr);
  6607. if (status)
  6608. goto out;
  6609. status = decode_layoutreturn(xdr, res);
  6610. out:
  6611. return status;
  6612. }
  6613. /*
  6614. * Decode LAYOUTCOMMIT response
  6615. */
  6616. static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
  6617. struct xdr_stream *xdr,
  6618. void *data)
  6619. {
  6620. struct nfs4_layoutcommit_res *res = data;
  6621. struct compound_hdr hdr;
  6622. int status;
  6623. status = decode_compound_hdr(xdr, &hdr);
  6624. if (status)
  6625. goto out;
  6626. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6627. if (status)
  6628. goto out;
  6629. status = decode_putfh(xdr);
  6630. if (status)
  6631. goto out;
  6632. status = decode_layoutcommit(xdr, rqstp, res);
  6633. if (status)
  6634. goto out;
  6635. decode_getfattr(xdr, res->fattr, res->server);
  6636. out:
  6637. return status;
  6638. }
  6639. /*
  6640. * Decode SECINFO_NO_NAME response
  6641. */
  6642. static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
  6643. struct xdr_stream *xdr,
  6644. void *data)
  6645. {
  6646. struct nfs4_secinfo_res *res = data;
  6647. struct compound_hdr hdr;
  6648. int status;
  6649. status = decode_compound_hdr(xdr, &hdr);
  6650. if (status)
  6651. goto out;
  6652. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6653. if (status)
  6654. goto out;
  6655. status = decode_putrootfh(xdr);
  6656. if (status)
  6657. goto out;
  6658. status = decode_secinfo_no_name(xdr, res);
  6659. out:
  6660. return status;
  6661. }
  6662. /*
  6663. * Decode TEST_STATEID response
  6664. */
  6665. static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
  6666. struct xdr_stream *xdr,
  6667. void *data)
  6668. {
  6669. struct nfs41_test_stateid_res *res = data;
  6670. struct compound_hdr hdr;
  6671. int status;
  6672. status = decode_compound_hdr(xdr, &hdr);
  6673. if (status)
  6674. goto out;
  6675. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6676. if (status)
  6677. goto out;
  6678. status = decode_test_stateid(xdr, res);
  6679. out:
  6680. return status;
  6681. }
  6682. /*
  6683. * Decode FREE_STATEID response
  6684. */
  6685. static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
  6686. struct xdr_stream *xdr,
  6687. void *data)
  6688. {
  6689. struct nfs41_free_stateid_res *res = data;
  6690. struct compound_hdr hdr;
  6691. int status;
  6692. status = decode_compound_hdr(xdr, &hdr);
  6693. if (status)
  6694. goto out;
  6695. status = decode_sequence(xdr, &res->seq_res, rqstp);
  6696. if (status)
  6697. goto out;
  6698. status = decode_free_stateid(xdr, res);
  6699. out:
  6700. return status;
  6701. }
  6702. #endif /* CONFIG_NFS_V4_1 */
  6703. /**
  6704. * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
  6705. * the local page cache.
  6706. * @xdr: XDR stream where entry resides
  6707. * @entry: buffer to fill in with entry data
  6708. * @plus: boolean indicating whether this should be a readdirplus entry
  6709. *
  6710. * Returns zero if successful, otherwise a negative errno value is
  6711. * returned.
  6712. *
  6713. * This function is not invoked during READDIR reply decoding, but
  6714. * rather whenever an application invokes the getdents(2) system call
  6715. * on a directory already in our cache.
  6716. */
  6717. int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
  6718. bool plus)
  6719. {
  6720. unsigned int savep;
  6721. uint32_t bitmap[3] = {0};
  6722. uint32_t len;
  6723. __be32 *p = xdr_inline_decode(xdr, 4);
  6724. if (unlikely(!p))
  6725. goto out_overflow;
  6726. if (*p == xdr_zero) {
  6727. p = xdr_inline_decode(xdr, 4);
  6728. if (unlikely(!p))
  6729. goto out_overflow;
  6730. if (*p == xdr_zero)
  6731. return -EAGAIN;
  6732. entry->eof = 1;
  6733. return -EBADCOOKIE;
  6734. }
  6735. p = xdr_inline_decode(xdr, 12);
  6736. if (unlikely(!p))
  6737. goto out_overflow;
  6738. entry->prev_cookie = entry->cookie;
  6739. p = xdr_decode_hyper(p, &entry->cookie);
  6740. entry->len = be32_to_cpup(p);
  6741. p = xdr_inline_decode(xdr, entry->len);
  6742. if (unlikely(!p))
  6743. goto out_overflow;
  6744. entry->name = (const char *) p;
  6745. /*
  6746. * In case the server doesn't return an inode number,
  6747. * we fake one here. (We don't use inode number 0,
  6748. * since glibc seems to choke on it...)
  6749. */
  6750. entry->ino = 1;
  6751. entry->fattr->valid = 0;
  6752. if (decode_attr_bitmap(xdr, bitmap) < 0)
  6753. goto out_overflow;
  6754. if (decode_attr_length(xdr, &len, &savep) < 0)
  6755. goto out_overflow;
  6756. if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
  6757. NULL, entry->label, entry->server) < 0)
  6758. goto out_overflow;
  6759. if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
  6760. entry->ino = entry->fattr->mounted_on_fileid;
  6761. else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
  6762. entry->ino = entry->fattr->fileid;
  6763. entry->d_type = DT_UNKNOWN;
  6764. if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
  6765. entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
  6766. return 0;
  6767. out_overflow:
  6768. print_overflow_msg(__func__, xdr);
  6769. return -EAGAIN;
  6770. }
  6771. /*
  6772. * We need to translate between nfs status return values and
  6773. * the local errno values which may not be the same.
  6774. */
  6775. static struct {
  6776. int stat;
  6777. int errno;
  6778. } nfs_errtbl[] = {
  6779. { NFS4_OK, 0 },
  6780. { NFS4ERR_PERM, -EPERM },
  6781. { NFS4ERR_NOENT, -ENOENT },
  6782. { NFS4ERR_IO, -errno_NFSERR_IO},
  6783. { NFS4ERR_NXIO, -ENXIO },
  6784. { NFS4ERR_ACCESS, -EACCES },
  6785. { NFS4ERR_EXIST, -EEXIST },
  6786. { NFS4ERR_XDEV, -EXDEV },
  6787. { NFS4ERR_NOTDIR, -ENOTDIR },
  6788. { NFS4ERR_ISDIR, -EISDIR },
  6789. { NFS4ERR_INVAL, -EINVAL },
  6790. { NFS4ERR_FBIG, -EFBIG },
  6791. { NFS4ERR_NOSPC, -ENOSPC },
  6792. { NFS4ERR_ROFS, -EROFS },
  6793. { NFS4ERR_MLINK, -EMLINK },
  6794. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  6795. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  6796. { NFS4ERR_DQUOT, -EDQUOT },
  6797. { NFS4ERR_STALE, -ESTALE },
  6798. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  6799. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  6800. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  6801. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  6802. { NFS4ERR_SERVERFAULT, -EREMOTEIO },
  6803. { NFS4ERR_BADTYPE, -EBADTYPE },
  6804. { NFS4ERR_LOCKED, -EAGAIN },
  6805. { NFS4ERR_SYMLINK, -ELOOP },
  6806. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  6807. { NFS4ERR_DEADLOCK, -EDEADLK },
  6808. { -1, -EIO }
  6809. };
  6810. /*
  6811. * Convert an NFS error code to a local one.
  6812. * This one is used jointly by NFSv2 and NFSv3.
  6813. */
  6814. static int
  6815. nfs4_stat_to_errno(int stat)
  6816. {
  6817. int i;
  6818. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  6819. if (nfs_errtbl[i].stat == stat)
  6820. return nfs_errtbl[i].errno;
  6821. }
  6822. if (stat <= 10000 || stat > 10100) {
  6823. /* The server is looney tunes. */
  6824. return -EREMOTEIO;
  6825. }
  6826. /* If we cannot translate the error, the recovery routines should
  6827. * handle it.
  6828. * Note: remaining NFSv4 error codes have values > 10000, so should
  6829. * not conflict with native Linux error codes.
  6830. */
  6831. return -stat;
  6832. }
  6833. #ifdef CONFIG_NFS_V4_2
  6834. #include "nfs42xdr.c"
  6835. #endif /* CONFIG_NFS_V4_2 */
  6836. #define PROC(proc, argtype, restype) \
  6837. [NFSPROC4_CLNT_##proc] = { \
  6838. .p_proc = NFSPROC4_COMPOUND, \
  6839. .p_encode = nfs4_xdr_##argtype, \
  6840. .p_decode = nfs4_xdr_##restype, \
  6841. .p_arglen = NFS4_##argtype##_sz, \
  6842. .p_replen = NFS4_##restype##_sz, \
  6843. .p_statidx = NFSPROC4_CLNT_##proc, \
  6844. .p_name = #proc, \
  6845. }
  6846. #define STUB(proc) \
  6847. [NFSPROC4_CLNT_##proc] = { \
  6848. .p_name = #proc, \
  6849. }
  6850. const struct rpc_procinfo nfs4_procedures[] = {
  6851. PROC(READ, enc_read, dec_read),
  6852. PROC(WRITE, enc_write, dec_write),
  6853. PROC(COMMIT, enc_commit, dec_commit),
  6854. PROC(OPEN, enc_open, dec_open),
  6855. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  6856. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  6857. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  6858. PROC(CLOSE, enc_close, dec_close),
  6859. PROC(SETATTR, enc_setattr, dec_setattr),
  6860. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  6861. PROC(RENEW, enc_renew, dec_renew),
  6862. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  6863. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  6864. PROC(LOCK, enc_lock, dec_lock),
  6865. PROC(LOCKT, enc_lockt, dec_lockt),
  6866. PROC(LOCKU, enc_locku, dec_locku),
  6867. PROC(ACCESS, enc_access, dec_access),
  6868. PROC(GETATTR, enc_getattr, dec_getattr),
  6869. PROC(LOOKUP, enc_lookup, dec_lookup),
  6870. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  6871. PROC(REMOVE, enc_remove, dec_remove),
  6872. PROC(RENAME, enc_rename, dec_rename),
  6873. PROC(LINK, enc_link, dec_link),
  6874. PROC(SYMLINK, enc_symlink, dec_symlink),
  6875. PROC(CREATE, enc_create, dec_create),
  6876. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  6877. PROC(STATFS, enc_statfs, dec_statfs),
  6878. PROC(READLINK, enc_readlink, dec_readlink),
  6879. PROC(READDIR, enc_readdir, dec_readdir),
  6880. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  6881. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  6882. PROC(GETACL, enc_getacl, dec_getacl),
  6883. PROC(SETACL, enc_setacl, dec_setacl),
  6884. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  6885. PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
  6886. PROC(SECINFO, enc_secinfo, dec_secinfo),
  6887. PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
  6888. #if defined(CONFIG_NFS_V4_1)
  6889. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  6890. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  6891. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  6892. PROC(SEQUENCE, enc_sequence, dec_sequence),
  6893. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  6894. PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
  6895. PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
  6896. PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
  6897. PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
  6898. PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
  6899. PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
  6900. PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
  6901. PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
  6902. STUB(GETDEVICELIST),
  6903. PROC(BIND_CONN_TO_SESSION,
  6904. enc_bind_conn_to_session, dec_bind_conn_to_session),
  6905. PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
  6906. #endif /* CONFIG_NFS_V4_1 */
  6907. #ifdef CONFIG_NFS_V4_2
  6908. PROC(SEEK, enc_seek, dec_seek),
  6909. PROC(ALLOCATE, enc_allocate, dec_allocate),
  6910. PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
  6911. PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
  6912. PROC(CLONE, enc_clone, dec_clone),
  6913. PROC(COPY, enc_copy, dec_copy),
  6914. #endif /* CONFIG_NFS_V4_2 */
  6915. };
  6916. static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
  6917. const struct rpc_version nfs_version4 = {
  6918. .number = 4,
  6919. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  6920. .procs = nfs4_procedures,
  6921. .counts = nfs_version4_counts,
  6922. };
  6923. /*
  6924. * Local variables:
  6925. * c-basic-offset: 8
  6926. * End:
  6927. */