nfs4xdr.c 183 KB

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