nfs4xdr.c 186 KB

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