nfs4xdr.c 195 KB

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