nfs4xdr.c 197 KB

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