nfs4xdr.c 192 KB

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