nfs4xdr.c 157 KB

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