nfs4xdr.c 184 KB

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