nfs4xdr.c 190 KB

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