nfs4xdr.c 172 KB

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