nfs4xdr.c 182 KB

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