nfs4xdr.c 170 KB

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