nfs4xdr.c 201 KB

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