nfs4xdr.c 195 KB

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