nfs4xdr.c 195 KB

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