nfs4xdr.c 201 KB

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