nfs4xdr.c 143 KB

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