nfs4xdr.c 202 KB

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