nfs4xdr.c 151 KB

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