nfs4xdr.c 189 KB

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