nfs4xdr.c 194 KB

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