nfs4xdr.c 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465
  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 READ64(x) do { \
  2214. (x) = (u64)ntohl(*p++) << 32; \
  2215. (x) |= ntohl(*p++); \
  2216. } while (0)
  2217. #define READTIME(x) do { \
  2218. p++; \
  2219. (x.tv_sec) = ntohl(*p++); \
  2220. (x.tv_nsec) = ntohl(*p++); \
  2221. } while (0)
  2222. #define COPYMEM(x,nbytes) do { \
  2223. memcpy((x), p, nbytes); \
  2224. p += XDR_QUADLEN(nbytes); \
  2225. } while (0)
  2226. #define READ_BUF(nbytes) do { \
  2227. p = xdr_inline_decode(xdr, nbytes); \
  2228. if (unlikely(!p)) { \
  2229. dprintk("nfs: %s: prematurely hit end of receive" \
  2230. " buffer\n", __func__); \
  2231. dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
  2232. __func__, xdr->p, nbytes, xdr->end); \
  2233. return -EIO; \
  2234. } \
  2235. } while (0)
  2236. static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
  2237. {
  2238. __be32 *p;
  2239. READ_BUF(4);
  2240. *len = be32_to_cpup(p++);
  2241. READ_BUF(*len);
  2242. *string = (char *)p;
  2243. return 0;
  2244. }
  2245. static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
  2246. {
  2247. __be32 *p;
  2248. READ_BUF(8);
  2249. hdr->status = be32_to_cpup(p++);
  2250. hdr->taglen = be32_to_cpup(p++);
  2251. READ_BUF(hdr->taglen + 4);
  2252. hdr->tag = (char *)p;
  2253. p += XDR_QUADLEN(hdr->taglen);
  2254. hdr->nops = be32_to_cpup(p++);
  2255. if (unlikely(hdr->nops < 1))
  2256. return nfs4_stat_to_errno(hdr->status);
  2257. return 0;
  2258. }
  2259. static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
  2260. {
  2261. __be32 *p;
  2262. uint32_t opnum;
  2263. int32_t nfserr;
  2264. READ_BUF(8);
  2265. opnum = be32_to_cpup(p++);
  2266. if (opnum != expected) {
  2267. dprintk("nfs: Server returned operation"
  2268. " %d but we issued a request for %d\n",
  2269. opnum, expected);
  2270. return -EIO;
  2271. }
  2272. nfserr = be32_to_cpup(p++);
  2273. if (nfserr != NFS_OK)
  2274. return nfs4_stat_to_errno(nfserr);
  2275. return 0;
  2276. }
  2277. /* Dummy routine */
  2278. static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
  2279. {
  2280. __be32 *p;
  2281. unsigned int strlen;
  2282. char *str;
  2283. READ_BUF(12);
  2284. return decode_opaque_inline(xdr, &strlen, &str);
  2285. }
  2286. static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
  2287. {
  2288. uint32_t bmlen;
  2289. __be32 *p;
  2290. READ_BUF(4);
  2291. bmlen = be32_to_cpup(p++);
  2292. bitmap[0] = bitmap[1] = 0;
  2293. READ_BUF((bmlen << 2));
  2294. if (bmlen > 0) {
  2295. bitmap[0] = be32_to_cpup(p++);
  2296. if (bmlen > 1)
  2297. bitmap[1] = be32_to_cpup(p++);
  2298. }
  2299. return 0;
  2300. }
  2301. static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
  2302. {
  2303. __be32 *p;
  2304. READ_BUF(4);
  2305. *attrlen = be32_to_cpup(p++);
  2306. *savep = xdr->p;
  2307. return 0;
  2308. }
  2309. static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
  2310. {
  2311. if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
  2312. decode_attr_bitmap(xdr, bitmask);
  2313. bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
  2314. } else
  2315. bitmask[0] = bitmask[1] = 0;
  2316. dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
  2317. return 0;
  2318. }
  2319. static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
  2320. {
  2321. __be32 *p;
  2322. int ret = 0;
  2323. *type = 0;
  2324. if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
  2325. return -EIO;
  2326. if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
  2327. READ_BUF(4);
  2328. *type = be32_to_cpup(p++);
  2329. if (*type < NF4REG || *type > NF4NAMEDATTR) {
  2330. dprintk("%s: bad type %d\n", __func__, *type);
  2331. return -EIO;
  2332. }
  2333. bitmap[0] &= ~FATTR4_WORD0_TYPE;
  2334. ret = NFS_ATTR_FATTR_TYPE;
  2335. }
  2336. dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
  2337. return ret;
  2338. }
  2339. static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
  2340. {
  2341. __be32 *p;
  2342. int ret = 0;
  2343. *change = 0;
  2344. if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
  2345. return -EIO;
  2346. if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
  2347. READ_BUF(8);
  2348. READ64(*change);
  2349. bitmap[0] &= ~FATTR4_WORD0_CHANGE;
  2350. ret = NFS_ATTR_FATTR_CHANGE;
  2351. }
  2352. dprintk("%s: change attribute=%Lu\n", __func__,
  2353. (unsigned long long)*change);
  2354. return ret;
  2355. }
  2356. static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
  2357. {
  2358. __be32 *p;
  2359. int ret = 0;
  2360. *size = 0;
  2361. if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
  2362. return -EIO;
  2363. if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
  2364. READ_BUF(8);
  2365. READ64(*size);
  2366. bitmap[0] &= ~FATTR4_WORD0_SIZE;
  2367. ret = NFS_ATTR_FATTR_SIZE;
  2368. }
  2369. dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
  2370. return ret;
  2371. }
  2372. static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2373. {
  2374. __be32 *p;
  2375. *res = 0;
  2376. if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
  2377. return -EIO;
  2378. if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
  2379. READ_BUF(4);
  2380. *res = be32_to_cpup(p++);
  2381. bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
  2382. }
  2383. dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
  2384. return 0;
  2385. }
  2386. static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2387. {
  2388. __be32 *p;
  2389. *res = 0;
  2390. if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
  2391. return -EIO;
  2392. if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
  2393. READ_BUF(4);
  2394. *res = be32_to_cpup(p++);
  2395. bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
  2396. }
  2397. dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
  2398. return 0;
  2399. }
  2400. static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
  2401. {
  2402. __be32 *p;
  2403. int ret = 0;
  2404. fsid->major = 0;
  2405. fsid->minor = 0;
  2406. if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
  2407. return -EIO;
  2408. if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
  2409. READ_BUF(16);
  2410. READ64(fsid->major);
  2411. READ64(fsid->minor);
  2412. bitmap[0] &= ~FATTR4_WORD0_FSID;
  2413. ret = NFS_ATTR_FATTR_FSID;
  2414. }
  2415. dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
  2416. (unsigned long long)fsid->major,
  2417. (unsigned long long)fsid->minor);
  2418. return ret;
  2419. }
  2420. static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2421. {
  2422. __be32 *p;
  2423. *res = 60;
  2424. if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
  2425. return -EIO;
  2426. if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
  2427. READ_BUF(4);
  2428. *res = be32_to_cpup(p++);
  2429. bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
  2430. }
  2431. dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
  2432. return 0;
  2433. }
  2434. static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2435. {
  2436. __be32 *p;
  2437. *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
  2438. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
  2439. return -EIO;
  2440. if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
  2441. READ_BUF(4);
  2442. *res = be32_to_cpup(p++);
  2443. bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
  2444. }
  2445. dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
  2446. return 0;
  2447. }
  2448. static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2449. {
  2450. __be32 *p;
  2451. int ret = 0;
  2452. *fileid = 0;
  2453. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
  2454. return -EIO;
  2455. if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
  2456. READ_BUF(8);
  2457. READ64(*fileid);
  2458. bitmap[0] &= ~FATTR4_WORD0_FILEID;
  2459. ret = NFS_ATTR_FATTR_FILEID;
  2460. }
  2461. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2462. return ret;
  2463. }
  2464. static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
  2465. {
  2466. __be32 *p;
  2467. int ret = 0;
  2468. *fileid = 0;
  2469. if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
  2470. return -EIO;
  2471. if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
  2472. READ_BUF(8);
  2473. READ64(*fileid);
  2474. bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
  2475. ret = NFS_ATTR_FATTR_FILEID;
  2476. }
  2477. dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
  2478. return ret;
  2479. }
  2480. static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2481. {
  2482. __be32 *p;
  2483. int status = 0;
  2484. *res = 0;
  2485. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
  2486. return -EIO;
  2487. if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
  2488. READ_BUF(8);
  2489. READ64(*res);
  2490. bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
  2491. }
  2492. dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
  2493. return status;
  2494. }
  2495. static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2496. {
  2497. __be32 *p;
  2498. int status = 0;
  2499. *res = 0;
  2500. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
  2501. return -EIO;
  2502. if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
  2503. READ_BUF(8);
  2504. READ64(*res);
  2505. bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
  2506. }
  2507. dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
  2508. return status;
  2509. }
  2510. static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2511. {
  2512. __be32 *p;
  2513. int status = 0;
  2514. *res = 0;
  2515. if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
  2516. return -EIO;
  2517. if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
  2518. READ_BUF(8);
  2519. READ64(*res);
  2520. bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
  2521. }
  2522. dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
  2523. return status;
  2524. }
  2525. static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
  2526. {
  2527. u32 n;
  2528. __be32 *p;
  2529. int status = 0;
  2530. READ_BUF(4);
  2531. n = be32_to_cpup(p++);
  2532. if (n == 0)
  2533. goto root_path;
  2534. dprintk("path ");
  2535. path->ncomponents = 0;
  2536. while (path->ncomponents < n) {
  2537. struct nfs4_string *component = &path->components[path->ncomponents];
  2538. status = decode_opaque_inline(xdr, &component->len, &component->data);
  2539. if (unlikely(status != 0))
  2540. goto out_eio;
  2541. if (path->ncomponents != n)
  2542. dprintk("/");
  2543. dprintk("%s", component->data);
  2544. if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
  2545. path->ncomponents++;
  2546. else {
  2547. dprintk("cannot parse %d components in path\n", n);
  2548. goto out_eio;
  2549. }
  2550. }
  2551. out:
  2552. dprintk("\n");
  2553. return status;
  2554. root_path:
  2555. /* a root pathname is sent as a zero component4 */
  2556. path->ncomponents = 1;
  2557. path->components[0].len=0;
  2558. path->components[0].data=NULL;
  2559. dprintk("path /\n");
  2560. goto out;
  2561. out_eio:
  2562. dprintk(" status %d", status);
  2563. status = -EIO;
  2564. goto out;
  2565. }
  2566. static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
  2567. {
  2568. int n;
  2569. __be32 *p;
  2570. int status = -EIO;
  2571. if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
  2572. goto out;
  2573. status = 0;
  2574. if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
  2575. goto out;
  2576. dprintk("%s: fsroot ", __func__);
  2577. status = decode_pathname(xdr, &res->fs_path);
  2578. if (unlikely(status != 0))
  2579. goto out;
  2580. READ_BUF(4);
  2581. n = be32_to_cpup(p++);
  2582. if (n <= 0)
  2583. goto out_eio;
  2584. res->nlocations = 0;
  2585. while (res->nlocations < n) {
  2586. u32 m;
  2587. struct nfs4_fs_location *loc = &res->locations[res->nlocations];
  2588. READ_BUF(4);
  2589. m = be32_to_cpup(p++);
  2590. loc->nservers = 0;
  2591. dprintk("%s: servers ", __func__);
  2592. while (loc->nservers < m) {
  2593. struct nfs4_string *server = &loc->servers[loc->nservers];
  2594. status = decode_opaque_inline(xdr, &server->len, &server->data);
  2595. if (unlikely(status != 0))
  2596. goto out_eio;
  2597. dprintk("%s ", server->data);
  2598. if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
  2599. loc->nservers++;
  2600. else {
  2601. unsigned int i;
  2602. dprintk("%s: using first %u of %u servers "
  2603. "returned for location %u\n",
  2604. __func__,
  2605. NFS4_FS_LOCATION_MAXSERVERS,
  2606. m, res->nlocations);
  2607. for (i = loc->nservers; i < m; i++) {
  2608. unsigned int len;
  2609. char *data;
  2610. status = decode_opaque_inline(xdr, &len, &data);
  2611. if (unlikely(status != 0))
  2612. goto out_eio;
  2613. }
  2614. }
  2615. }
  2616. status = decode_pathname(xdr, &loc->rootpath);
  2617. if (unlikely(status != 0))
  2618. goto out_eio;
  2619. if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
  2620. res->nlocations++;
  2621. }
  2622. if (res->nlocations != 0)
  2623. status = NFS_ATTR_FATTR_V4_REFERRAL;
  2624. out:
  2625. dprintk("%s: fs_locations done, error = %d\n", __func__, status);
  2626. return status;
  2627. out_eio:
  2628. status = -EIO;
  2629. goto out;
  2630. }
  2631. static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2632. {
  2633. __be32 *p;
  2634. int status = 0;
  2635. *res = 0;
  2636. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
  2637. return -EIO;
  2638. if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
  2639. READ_BUF(8);
  2640. READ64(*res);
  2641. bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
  2642. }
  2643. dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
  2644. return status;
  2645. }
  2646. static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
  2647. {
  2648. __be32 *p;
  2649. int status = 0;
  2650. *maxlink = 1;
  2651. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
  2652. return -EIO;
  2653. if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
  2654. READ_BUF(4);
  2655. *maxlink = be32_to_cpup(p++);
  2656. bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
  2657. }
  2658. dprintk("%s: maxlink=%u\n", __func__, *maxlink);
  2659. return status;
  2660. }
  2661. static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
  2662. {
  2663. __be32 *p;
  2664. int status = 0;
  2665. *maxname = 1024;
  2666. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
  2667. return -EIO;
  2668. if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
  2669. READ_BUF(4);
  2670. *maxname = be32_to_cpup(p++);
  2671. bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
  2672. }
  2673. dprintk("%s: maxname=%u\n", __func__, *maxname);
  2674. return status;
  2675. }
  2676. static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2677. {
  2678. __be32 *p;
  2679. int status = 0;
  2680. *res = 1024;
  2681. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
  2682. return -EIO;
  2683. if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
  2684. uint64_t maxread;
  2685. READ_BUF(8);
  2686. READ64(maxread);
  2687. if (maxread > 0x7FFFFFFF)
  2688. maxread = 0x7FFFFFFF;
  2689. *res = (uint32_t)maxread;
  2690. bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
  2691. }
  2692. dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
  2693. return status;
  2694. }
  2695. static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
  2696. {
  2697. __be32 *p;
  2698. int status = 0;
  2699. *res = 1024;
  2700. if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
  2701. return -EIO;
  2702. if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
  2703. uint64_t maxwrite;
  2704. READ_BUF(8);
  2705. READ64(maxwrite);
  2706. if (maxwrite > 0x7FFFFFFF)
  2707. maxwrite = 0x7FFFFFFF;
  2708. *res = (uint32_t)maxwrite;
  2709. bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
  2710. }
  2711. dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
  2712. return status;
  2713. }
  2714. static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
  2715. {
  2716. uint32_t tmp;
  2717. __be32 *p;
  2718. int ret = 0;
  2719. *mode = 0;
  2720. if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
  2721. return -EIO;
  2722. if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
  2723. READ_BUF(4);
  2724. tmp = be32_to_cpup(p++);
  2725. *mode = tmp & ~S_IFMT;
  2726. bitmap[1] &= ~FATTR4_WORD1_MODE;
  2727. ret = NFS_ATTR_FATTR_MODE;
  2728. }
  2729. dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
  2730. return ret;
  2731. }
  2732. static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
  2733. {
  2734. __be32 *p;
  2735. int ret = 0;
  2736. *nlink = 1;
  2737. if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
  2738. return -EIO;
  2739. if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
  2740. READ_BUF(4);
  2741. *nlink = be32_to_cpup(p++);
  2742. bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
  2743. ret = NFS_ATTR_FATTR_NLINK;
  2744. }
  2745. dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
  2746. return ret;
  2747. }
  2748. static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
  2749. {
  2750. uint32_t len;
  2751. __be32 *p;
  2752. int ret = 0;
  2753. *uid = -2;
  2754. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
  2755. return -EIO;
  2756. if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
  2757. READ_BUF(4);
  2758. len = be32_to_cpup(p++);
  2759. READ_BUF(len);
  2760. if (len < XDR_MAX_NETOBJ) {
  2761. if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
  2762. ret = NFS_ATTR_FATTR_OWNER;
  2763. else
  2764. dprintk("%s: nfs_map_name_to_uid failed!\n",
  2765. __func__);
  2766. } else
  2767. dprintk("%s: name too long (%u)!\n",
  2768. __func__, len);
  2769. bitmap[1] &= ~FATTR4_WORD1_OWNER;
  2770. }
  2771. dprintk("%s: uid=%d\n", __func__, (int)*uid);
  2772. return ret;
  2773. }
  2774. static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
  2775. {
  2776. uint32_t len;
  2777. __be32 *p;
  2778. int ret = 0;
  2779. *gid = -2;
  2780. if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
  2781. return -EIO;
  2782. if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
  2783. READ_BUF(4);
  2784. len = be32_to_cpup(p++);
  2785. READ_BUF(len);
  2786. if (len < XDR_MAX_NETOBJ) {
  2787. if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
  2788. ret = NFS_ATTR_FATTR_GROUP;
  2789. else
  2790. dprintk("%s: nfs_map_group_to_gid failed!\n",
  2791. __func__);
  2792. } else
  2793. dprintk("%s: name too long (%u)!\n",
  2794. __func__, len);
  2795. bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
  2796. }
  2797. dprintk("%s: gid=%d\n", __func__, (int)*gid);
  2798. return ret;
  2799. }
  2800. static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
  2801. {
  2802. uint32_t major = 0, minor = 0;
  2803. __be32 *p;
  2804. int ret = 0;
  2805. *rdev = MKDEV(0,0);
  2806. if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
  2807. return -EIO;
  2808. if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
  2809. dev_t tmp;
  2810. READ_BUF(8);
  2811. major = be32_to_cpup(p++);
  2812. minor = be32_to_cpup(p++);
  2813. tmp = MKDEV(major, minor);
  2814. if (MAJOR(tmp) == major && MINOR(tmp) == minor)
  2815. *rdev = tmp;
  2816. bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
  2817. ret = NFS_ATTR_FATTR_RDEV;
  2818. }
  2819. dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
  2820. return ret;
  2821. }
  2822. static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2823. {
  2824. __be32 *p;
  2825. int status = 0;
  2826. *res = 0;
  2827. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
  2828. return -EIO;
  2829. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
  2830. READ_BUF(8);
  2831. READ64(*res);
  2832. bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
  2833. }
  2834. dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
  2835. return status;
  2836. }
  2837. static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2838. {
  2839. __be32 *p;
  2840. int status = 0;
  2841. *res = 0;
  2842. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
  2843. return -EIO;
  2844. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
  2845. READ_BUF(8);
  2846. READ64(*res);
  2847. bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
  2848. }
  2849. dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
  2850. return status;
  2851. }
  2852. static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
  2853. {
  2854. __be32 *p;
  2855. int status = 0;
  2856. *res = 0;
  2857. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
  2858. return -EIO;
  2859. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
  2860. READ_BUF(8);
  2861. READ64(*res);
  2862. bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
  2863. }
  2864. dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
  2865. return status;
  2866. }
  2867. static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
  2868. {
  2869. __be32 *p;
  2870. int ret = 0;
  2871. *used = 0;
  2872. if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
  2873. return -EIO;
  2874. if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
  2875. READ_BUF(8);
  2876. READ64(*used);
  2877. bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
  2878. ret = NFS_ATTR_FATTR_SPACE_USED;
  2879. }
  2880. dprintk("%s: space used=%Lu\n", __func__,
  2881. (unsigned long long)*used);
  2882. return ret;
  2883. }
  2884. static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
  2885. {
  2886. __be32 *p;
  2887. uint64_t sec;
  2888. uint32_t nsec;
  2889. READ_BUF(12);
  2890. READ64(sec);
  2891. nsec = be32_to_cpup(p++);
  2892. time->tv_sec = (time_t)sec;
  2893. time->tv_nsec = (long)nsec;
  2894. return 0;
  2895. }
  2896. static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2897. {
  2898. int status = 0;
  2899. time->tv_sec = 0;
  2900. time->tv_nsec = 0;
  2901. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
  2902. return -EIO;
  2903. if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
  2904. status = decode_attr_time(xdr, time);
  2905. if (status == 0)
  2906. status = NFS_ATTR_FATTR_ATIME;
  2907. bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
  2908. }
  2909. dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
  2910. return status;
  2911. }
  2912. static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2913. {
  2914. int status = 0;
  2915. time->tv_sec = 0;
  2916. time->tv_nsec = 0;
  2917. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
  2918. return -EIO;
  2919. if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
  2920. status = decode_attr_time(xdr, time);
  2921. if (status == 0)
  2922. status = NFS_ATTR_FATTR_CTIME;
  2923. bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
  2924. }
  2925. dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
  2926. return status;
  2927. }
  2928. static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
  2929. {
  2930. int status = 0;
  2931. time->tv_sec = 0;
  2932. time->tv_nsec = 0;
  2933. if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
  2934. return -EIO;
  2935. if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
  2936. status = decode_attr_time(xdr, time);
  2937. if (status == 0)
  2938. status = NFS_ATTR_FATTR_MTIME;
  2939. bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
  2940. }
  2941. dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
  2942. return status;
  2943. }
  2944. static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
  2945. {
  2946. unsigned int attrwords = XDR_QUADLEN(attrlen);
  2947. unsigned int nwords = xdr->p - savep;
  2948. if (unlikely(attrwords != nwords)) {
  2949. dprintk("%s: server returned incorrect attribute length: "
  2950. "%u %c %u\n",
  2951. __func__,
  2952. attrwords << 2,
  2953. (attrwords < nwords) ? '<' : '>',
  2954. nwords << 2);
  2955. return -EIO;
  2956. }
  2957. return 0;
  2958. }
  2959. static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  2960. {
  2961. __be32 *p;
  2962. READ_BUF(20);
  2963. cinfo->atomic = be32_to_cpup(p++);
  2964. READ64(cinfo->before);
  2965. READ64(cinfo->after);
  2966. return 0;
  2967. }
  2968. static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
  2969. {
  2970. __be32 *p;
  2971. uint32_t supp, acc;
  2972. int status;
  2973. status = decode_op_hdr(xdr, OP_ACCESS);
  2974. if (status)
  2975. return status;
  2976. READ_BUF(8);
  2977. supp = be32_to_cpup(p++);
  2978. acc = be32_to_cpup(p++);
  2979. access->supported = supp;
  2980. access->access = acc;
  2981. return 0;
  2982. }
  2983. static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
  2984. {
  2985. __be32 *p;
  2986. int status;
  2987. status = decode_op_hdr(xdr, OP_CLOSE);
  2988. if (status != -EIO)
  2989. nfs_increment_open_seqid(status, res->seqid);
  2990. if (status)
  2991. return status;
  2992. READ_BUF(NFS4_STATEID_SIZE);
  2993. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  2994. return 0;
  2995. }
  2996. static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
  2997. {
  2998. __be32 *p;
  2999. int status;
  3000. status = decode_op_hdr(xdr, OP_COMMIT);
  3001. if (status)
  3002. return status;
  3003. READ_BUF(8);
  3004. COPYMEM(res->verf->verifier, 8);
  3005. return 0;
  3006. }
  3007. static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3008. {
  3009. __be32 *p;
  3010. uint32_t bmlen;
  3011. int status;
  3012. status = decode_op_hdr(xdr, OP_CREATE);
  3013. if (status)
  3014. return status;
  3015. if ((status = decode_change_info(xdr, cinfo)))
  3016. return status;
  3017. READ_BUF(4);
  3018. bmlen = be32_to_cpup(p++);
  3019. READ_BUF(bmlen << 2);
  3020. return 0;
  3021. }
  3022. static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
  3023. {
  3024. __be32 *savep;
  3025. uint32_t attrlen, bitmap[2] = {0};
  3026. int status;
  3027. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3028. goto xdr_error;
  3029. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3030. goto xdr_error;
  3031. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3032. goto xdr_error;
  3033. if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
  3034. goto xdr_error;
  3035. if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
  3036. goto xdr_error;
  3037. if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
  3038. goto xdr_error;
  3039. if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
  3040. goto xdr_error;
  3041. status = verify_attr_len(xdr, savep, attrlen);
  3042. xdr_error:
  3043. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3044. return status;
  3045. }
  3046. static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
  3047. {
  3048. __be32 *savep;
  3049. uint32_t attrlen, bitmap[2] = {0};
  3050. int status;
  3051. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3052. goto xdr_error;
  3053. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3054. goto xdr_error;
  3055. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3056. goto xdr_error;
  3057. if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
  3058. goto xdr_error;
  3059. if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
  3060. goto xdr_error;
  3061. if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
  3062. goto xdr_error;
  3063. if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
  3064. goto xdr_error;
  3065. if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
  3066. goto xdr_error;
  3067. if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
  3068. goto xdr_error;
  3069. status = verify_attr_len(xdr, savep, attrlen);
  3070. xdr_error:
  3071. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3072. return status;
  3073. }
  3074. static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
  3075. {
  3076. __be32 *savep;
  3077. uint32_t attrlen, bitmap[2] = {0};
  3078. int status;
  3079. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3080. goto xdr_error;
  3081. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3082. goto xdr_error;
  3083. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3084. goto xdr_error;
  3085. if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
  3086. goto xdr_error;
  3087. if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
  3088. goto xdr_error;
  3089. status = verify_attr_len(xdr, savep, attrlen);
  3090. xdr_error:
  3091. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3092. return status;
  3093. }
  3094. static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
  3095. {
  3096. __be32 *savep;
  3097. uint32_t attrlen,
  3098. bitmap[2] = {0},
  3099. type;
  3100. int status;
  3101. umode_t fmode = 0;
  3102. uint64_t fileid;
  3103. status = decode_op_hdr(xdr, OP_GETATTR);
  3104. if (status < 0)
  3105. goto xdr_error;
  3106. status = decode_attr_bitmap(xdr, bitmap);
  3107. if (status < 0)
  3108. goto xdr_error;
  3109. status = decode_attr_length(xdr, &attrlen, &savep);
  3110. if (status < 0)
  3111. goto xdr_error;
  3112. status = decode_attr_type(xdr, bitmap, &type);
  3113. if (status < 0)
  3114. goto xdr_error;
  3115. fattr->mode = 0;
  3116. if (status != 0) {
  3117. fattr->mode |= nfs_type2fmt[type];
  3118. fattr->valid |= status;
  3119. }
  3120. status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
  3121. if (status < 0)
  3122. goto xdr_error;
  3123. fattr->valid |= status;
  3124. status = decode_attr_size(xdr, bitmap, &fattr->size);
  3125. if (status < 0)
  3126. goto xdr_error;
  3127. fattr->valid |= status;
  3128. status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
  3129. if (status < 0)
  3130. goto xdr_error;
  3131. fattr->valid |= status;
  3132. status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
  3133. if (status < 0)
  3134. goto xdr_error;
  3135. fattr->valid |= status;
  3136. status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
  3137. struct nfs4_fs_locations,
  3138. fattr));
  3139. if (status < 0)
  3140. goto xdr_error;
  3141. fattr->valid |= status;
  3142. status = decode_attr_mode(xdr, bitmap, &fmode);
  3143. if (status < 0)
  3144. goto xdr_error;
  3145. if (status != 0) {
  3146. fattr->mode |= fmode;
  3147. fattr->valid |= status;
  3148. }
  3149. status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
  3150. if (status < 0)
  3151. goto xdr_error;
  3152. fattr->valid |= status;
  3153. status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
  3154. if (status < 0)
  3155. goto xdr_error;
  3156. fattr->valid |= status;
  3157. status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
  3158. if (status < 0)
  3159. goto xdr_error;
  3160. fattr->valid |= status;
  3161. status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
  3162. if (status < 0)
  3163. goto xdr_error;
  3164. fattr->valid |= status;
  3165. status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
  3166. if (status < 0)
  3167. goto xdr_error;
  3168. fattr->valid |= status;
  3169. status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
  3170. if (status < 0)
  3171. goto xdr_error;
  3172. fattr->valid |= status;
  3173. status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
  3174. if (status < 0)
  3175. goto xdr_error;
  3176. fattr->valid |= status;
  3177. status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
  3178. if (status < 0)
  3179. goto xdr_error;
  3180. fattr->valid |= status;
  3181. status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
  3182. if (status < 0)
  3183. goto xdr_error;
  3184. if (status != 0 && !(fattr->valid & status)) {
  3185. fattr->fileid = fileid;
  3186. fattr->valid |= status;
  3187. }
  3188. status = verify_attr_len(xdr, savep, attrlen);
  3189. xdr_error:
  3190. dprintk("%s: xdr returned %d\n", __func__, -status);
  3191. return status;
  3192. }
  3193. static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
  3194. {
  3195. __be32 *savep;
  3196. uint32_t attrlen, bitmap[2];
  3197. int status;
  3198. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3199. goto xdr_error;
  3200. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3201. goto xdr_error;
  3202. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3203. goto xdr_error;
  3204. fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
  3205. if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
  3206. goto xdr_error;
  3207. if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
  3208. goto xdr_error;
  3209. if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
  3210. goto xdr_error;
  3211. fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
  3212. if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
  3213. goto xdr_error;
  3214. fsinfo->wtpref = fsinfo->wtmax;
  3215. status = verify_attr_len(xdr, savep, attrlen);
  3216. xdr_error:
  3217. dprintk("%s: xdr returned %d!\n", __func__, -status);
  3218. return status;
  3219. }
  3220. static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
  3221. {
  3222. __be32 *p;
  3223. uint32_t len;
  3224. int status;
  3225. /* Zero handle first to allow comparisons */
  3226. memset(fh, 0, sizeof(*fh));
  3227. status = decode_op_hdr(xdr, OP_GETFH);
  3228. if (status)
  3229. return status;
  3230. READ_BUF(4);
  3231. len = be32_to_cpup(p++);
  3232. if (len > NFS4_FHSIZE)
  3233. return -EIO;
  3234. fh->size = len;
  3235. READ_BUF(len);
  3236. COPYMEM(fh->data, len);
  3237. return 0;
  3238. }
  3239. static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3240. {
  3241. int status;
  3242. status = decode_op_hdr(xdr, OP_LINK);
  3243. if (status)
  3244. return status;
  3245. return decode_change_info(xdr, cinfo);
  3246. }
  3247. /*
  3248. * We create the owner, so we know a proper owner.id length is 4.
  3249. */
  3250. static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
  3251. {
  3252. uint64_t offset, length, clientid;
  3253. __be32 *p;
  3254. uint32_t namelen, type;
  3255. READ_BUF(32);
  3256. READ64(offset);
  3257. READ64(length);
  3258. type = be32_to_cpup(p++);
  3259. if (fl != NULL) {
  3260. fl->fl_start = (loff_t)offset;
  3261. fl->fl_end = fl->fl_start + (loff_t)length - 1;
  3262. if (length == ~(uint64_t)0)
  3263. fl->fl_end = OFFSET_MAX;
  3264. fl->fl_type = F_WRLCK;
  3265. if (type & 1)
  3266. fl->fl_type = F_RDLCK;
  3267. fl->fl_pid = 0;
  3268. }
  3269. READ64(clientid);
  3270. namelen = be32_to_cpup(p++);
  3271. READ_BUF(namelen);
  3272. return -NFS4ERR_DENIED;
  3273. }
  3274. static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
  3275. {
  3276. __be32 *p;
  3277. int status;
  3278. status = decode_op_hdr(xdr, OP_LOCK);
  3279. if (status == -EIO)
  3280. goto out;
  3281. if (status == 0) {
  3282. READ_BUF(NFS4_STATEID_SIZE);
  3283. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  3284. } else if (status == -NFS4ERR_DENIED)
  3285. status = decode_lock_denied(xdr, NULL);
  3286. if (res->open_seqid != NULL)
  3287. nfs_increment_open_seqid(status, res->open_seqid);
  3288. nfs_increment_lock_seqid(status, res->lock_seqid);
  3289. out:
  3290. return status;
  3291. }
  3292. static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
  3293. {
  3294. int status;
  3295. status = decode_op_hdr(xdr, OP_LOCKT);
  3296. if (status == -NFS4ERR_DENIED)
  3297. return decode_lock_denied(xdr, res->denied);
  3298. return status;
  3299. }
  3300. static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
  3301. {
  3302. __be32 *p;
  3303. int status;
  3304. status = decode_op_hdr(xdr, OP_LOCKU);
  3305. if (status != -EIO)
  3306. nfs_increment_lock_seqid(status, res->seqid);
  3307. if (status == 0) {
  3308. READ_BUF(NFS4_STATEID_SIZE);
  3309. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  3310. }
  3311. return status;
  3312. }
  3313. static int decode_lookup(struct xdr_stream *xdr)
  3314. {
  3315. return decode_op_hdr(xdr, OP_LOOKUP);
  3316. }
  3317. /* This is too sick! */
  3318. static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
  3319. {
  3320. __be32 *p;
  3321. uint32_t limit_type, nblocks, blocksize;
  3322. READ_BUF(12);
  3323. limit_type = be32_to_cpup(p++);
  3324. switch (limit_type) {
  3325. case 1:
  3326. READ64(*maxsize);
  3327. break;
  3328. case 2:
  3329. nblocks = be32_to_cpup(p++);
  3330. blocksize = be32_to_cpup(p++);
  3331. *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
  3332. }
  3333. return 0;
  3334. }
  3335. static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
  3336. {
  3337. __be32 *p;
  3338. uint32_t delegation_type;
  3339. READ_BUF(4);
  3340. delegation_type = be32_to_cpup(p++);
  3341. if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
  3342. res->delegation_type = 0;
  3343. return 0;
  3344. }
  3345. READ_BUF(NFS4_STATEID_SIZE+4);
  3346. COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
  3347. res->do_recall = be32_to_cpup(p++);
  3348. switch (delegation_type) {
  3349. case NFS4_OPEN_DELEGATE_READ:
  3350. res->delegation_type = FMODE_READ;
  3351. break;
  3352. case NFS4_OPEN_DELEGATE_WRITE:
  3353. res->delegation_type = FMODE_WRITE|FMODE_READ;
  3354. if (decode_space_limit(xdr, &res->maxsize) < 0)
  3355. return -EIO;
  3356. }
  3357. return decode_ace(xdr, NULL, res->server->nfs_client);
  3358. }
  3359. static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
  3360. {
  3361. __be32 *p;
  3362. uint32_t savewords, bmlen, i;
  3363. int status;
  3364. status = decode_op_hdr(xdr, OP_OPEN);
  3365. if (status != -EIO)
  3366. nfs_increment_open_seqid(status, res->seqid);
  3367. if (status)
  3368. return status;
  3369. READ_BUF(NFS4_STATEID_SIZE);
  3370. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  3371. decode_change_info(xdr, &res->cinfo);
  3372. READ_BUF(8);
  3373. res->rflags = be32_to_cpup(p++);
  3374. bmlen = be32_to_cpup(p++);
  3375. if (bmlen > 10)
  3376. goto xdr_error;
  3377. READ_BUF(bmlen << 2);
  3378. savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
  3379. for (i = 0; i < savewords; ++i)
  3380. res->attrset[i] = be32_to_cpup(p++);
  3381. for (; i < NFS4_BITMAP_SIZE; i++)
  3382. res->attrset[i] = 0;
  3383. return decode_delegation(xdr, res);
  3384. xdr_error:
  3385. dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
  3386. return -EIO;
  3387. }
  3388. static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
  3389. {
  3390. __be32 *p;
  3391. int status;
  3392. status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
  3393. if (status != -EIO)
  3394. nfs_increment_open_seqid(status, res->seqid);
  3395. if (status)
  3396. return status;
  3397. READ_BUF(NFS4_STATEID_SIZE);
  3398. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  3399. return 0;
  3400. }
  3401. static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
  3402. {
  3403. __be32 *p;
  3404. int status;
  3405. status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
  3406. if (status != -EIO)
  3407. nfs_increment_open_seqid(status, res->seqid);
  3408. if (status)
  3409. return status;
  3410. READ_BUF(NFS4_STATEID_SIZE);
  3411. COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
  3412. return 0;
  3413. }
  3414. static int decode_putfh(struct xdr_stream *xdr)
  3415. {
  3416. return decode_op_hdr(xdr, OP_PUTFH);
  3417. }
  3418. static int decode_putrootfh(struct xdr_stream *xdr)
  3419. {
  3420. return decode_op_hdr(xdr, OP_PUTROOTFH);
  3421. }
  3422. static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
  3423. {
  3424. struct kvec *iov = req->rq_rcv_buf.head;
  3425. __be32 *p;
  3426. uint32_t count, eof, recvd, hdrlen;
  3427. int status;
  3428. status = decode_op_hdr(xdr, OP_READ);
  3429. if (status)
  3430. return status;
  3431. READ_BUF(8);
  3432. eof = be32_to_cpup(p++);
  3433. count = be32_to_cpup(p++);
  3434. hdrlen = (u8 *) p - (u8 *) iov->iov_base;
  3435. recvd = req->rq_rcv_buf.len - hdrlen;
  3436. if (count > recvd) {
  3437. dprintk("NFS: server cheating in read reply: "
  3438. "count %u > recvd %u\n", count, recvd);
  3439. count = recvd;
  3440. eof = 0;
  3441. }
  3442. xdr_read_pages(xdr, count);
  3443. res->eof = eof;
  3444. res->count = count;
  3445. return 0;
  3446. }
  3447. static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
  3448. {
  3449. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  3450. struct page *page = *rcvbuf->pages;
  3451. struct kvec *iov = rcvbuf->head;
  3452. size_t hdrlen;
  3453. u32 recvd, pglen = rcvbuf->page_len;
  3454. __be32 *end, *entry, *p, *kaddr;
  3455. unsigned int nr = 0;
  3456. int status;
  3457. status = decode_op_hdr(xdr, OP_READDIR);
  3458. if (status)
  3459. return status;
  3460. READ_BUF(8);
  3461. COPYMEM(readdir->verifier.data, 8);
  3462. dprintk("%s: verifier = %08x:%08x\n",
  3463. __func__,
  3464. ((u32 *)readdir->verifier.data)[0],
  3465. ((u32 *)readdir->verifier.data)[1]);
  3466. hdrlen = (char *) p - (char *) iov->iov_base;
  3467. recvd = rcvbuf->len - hdrlen;
  3468. if (pglen > recvd)
  3469. pglen = recvd;
  3470. xdr_read_pages(xdr, pglen);
  3471. BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
  3472. kaddr = p = kmap_atomic(page, KM_USER0);
  3473. end = p + ((pglen + readdir->pgbase) >> 2);
  3474. entry = p;
  3475. /* Make sure the packet actually has a value_follows and EOF entry */
  3476. if ((entry + 1) > end)
  3477. goto short_pkt;
  3478. for (; *p++; nr++) {
  3479. u32 len, attrlen, xlen;
  3480. if (end - p < 3)
  3481. goto short_pkt;
  3482. dprintk("cookie = %Lu, ", *((unsigned long long *)p));
  3483. p += 2; /* cookie */
  3484. len = ntohl(*p++); /* filename length */
  3485. if (len > NFS4_MAXNAMLEN) {
  3486. dprintk("NFS: giant filename in readdir (len 0x%x)\n",
  3487. len);
  3488. goto err_unmap;
  3489. }
  3490. xlen = XDR_QUADLEN(len);
  3491. if (end - p < xlen + 1)
  3492. goto short_pkt;
  3493. dprintk("filename = %*s\n", len, (char *)p);
  3494. p += xlen;
  3495. len = ntohl(*p++); /* bitmap length */
  3496. if (end - p < len + 1)
  3497. goto short_pkt;
  3498. p += len;
  3499. attrlen = XDR_QUADLEN(ntohl(*p++));
  3500. if (end - p < attrlen + 2)
  3501. goto short_pkt;
  3502. p += attrlen; /* attributes */
  3503. entry = p;
  3504. }
  3505. /*
  3506. * Apparently some server sends responses that are a valid size, but
  3507. * contain no entries, and have value_follows==0 and EOF==0. For
  3508. * those, just set the EOF marker.
  3509. */
  3510. if (!nr && entry[1] == 0) {
  3511. dprintk("NFS: readdir reply truncated!\n");
  3512. entry[1] = 1;
  3513. }
  3514. out:
  3515. kunmap_atomic(kaddr, KM_USER0);
  3516. return 0;
  3517. short_pkt:
  3518. /*
  3519. * When we get a short packet there are 2 possibilities. We can
  3520. * return an error, or fix up the response to look like a valid
  3521. * response and return what we have so far. If there are no
  3522. * entries and the packet was short, then return -EIO. If there
  3523. * are valid entries in the response, return them and pretend that
  3524. * the call was successful, but incomplete. The caller can retry the
  3525. * readdir starting at the last cookie.
  3526. */
  3527. dprintk("%s: short packet at entry %d\n", __func__, nr);
  3528. entry[0] = entry[1] = 0;
  3529. if (nr)
  3530. goto out;
  3531. err_unmap:
  3532. kunmap_atomic(kaddr, KM_USER0);
  3533. return -errno_NFSERR_IO;
  3534. }
  3535. static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
  3536. {
  3537. struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
  3538. struct kvec *iov = rcvbuf->head;
  3539. size_t hdrlen;
  3540. u32 len, recvd;
  3541. __be32 *p;
  3542. char *kaddr;
  3543. int status;
  3544. status = decode_op_hdr(xdr, OP_READLINK);
  3545. if (status)
  3546. return status;
  3547. /* Convert length of symlink */
  3548. READ_BUF(4);
  3549. len = be32_to_cpup(p++);
  3550. if (len >= rcvbuf->page_len || len <= 0) {
  3551. dprintk("nfs: server returned giant symlink!\n");
  3552. return -ENAMETOOLONG;
  3553. }
  3554. hdrlen = (char *) xdr->p - (char *) iov->iov_base;
  3555. recvd = req->rq_rcv_buf.len - hdrlen;
  3556. if (recvd < len) {
  3557. dprintk("NFS: server cheating in readlink reply: "
  3558. "count %u > recvd %u\n", len, recvd);
  3559. return -EIO;
  3560. }
  3561. xdr_read_pages(xdr, len);
  3562. /*
  3563. * The XDR encode routine has set things up so that
  3564. * the link text will be copied directly into the
  3565. * buffer. We just have to do overflow-checking,
  3566. * and and null-terminate the text (the VFS expects
  3567. * null-termination).
  3568. */
  3569. kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
  3570. kaddr[len+rcvbuf->page_base] = '\0';
  3571. kunmap_atomic(kaddr, KM_USER0);
  3572. return 0;
  3573. }
  3574. static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
  3575. {
  3576. int status;
  3577. status = decode_op_hdr(xdr, OP_REMOVE);
  3578. if (status)
  3579. goto out;
  3580. status = decode_change_info(xdr, cinfo);
  3581. out:
  3582. return status;
  3583. }
  3584. static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
  3585. struct nfs4_change_info *new_cinfo)
  3586. {
  3587. int status;
  3588. status = decode_op_hdr(xdr, OP_RENAME);
  3589. if (status)
  3590. goto out;
  3591. if ((status = decode_change_info(xdr, old_cinfo)))
  3592. goto out;
  3593. status = decode_change_info(xdr, new_cinfo);
  3594. out:
  3595. return status;
  3596. }
  3597. static int decode_renew(struct xdr_stream *xdr)
  3598. {
  3599. return decode_op_hdr(xdr, OP_RENEW);
  3600. }
  3601. static int
  3602. decode_restorefh(struct xdr_stream *xdr)
  3603. {
  3604. return decode_op_hdr(xdr, OP_RESTOREFH);
  3605. }
  3606. static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
  3607. size_t *acl_len)
  3608. {
  3609. __be32 *savep;
  3610. uint32_t attrlen,
  3611. bitmap[2] = {0};
  3612. struct kvec *iov = req->rq_rcv_buf.head;
  3613. int status;
  3614. *acl_len = 0;
  3615. if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
  3616. goto out;
  3617. if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
  3618. goto out;
  3619. if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
  3620. goto out;
  3621. if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
  3622. return -EIO;
  3623. if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
  3624. size_t hdrlen;
  3625. u32 recvd;
  3626. /* We ignore &savep and don't do consistency checks on
  3627. * the attr length. Let userspace figure it out.... */
  3628. hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
  3629. recvd = req->rq_rcv_buf.len - hdrlen;
  3630. if (attrlen > recvd) {
  3631. dprintk("NFS: server cheating in getattr"
  3632. " acl reply: attrlen %u > recvd %u\n",
  3633. attrlen, recvd);
  3634. return -EINVAL;
  3635. }
  3636. xdr_read_pages(xdr, attrlen);
  3637. *acl_len = attrlen;
  3638. } else
  3639. status = -EOPNOTSUPP;
  3640. out:
  3641. return status;
  3642. }
  3643. static int
  3644. decode_savefh(struct xdr_stream *xdr)
  3645. {
  3646. return decode_op_hdr(xdr, OP_SAVEFH);
  3647. }
  3648. static int decode_setattr(struct xdr_stream *xdr)
  3649. {
  3650. __be32 *p;
  3651. uint32_t bmlen;
  3652. int status;
  3653. status = decode_op_hdr(xdr, OP_SETATTR);
  3654. if (status)
  3655. return status;
  3656. READ_BUF(4);
  3657. bmlen = be32_to_cpup(p++);
  3658. READ_BUF(bmlen << 2);
  3659. return 0;
  3660. }
  3661. static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
  3662. {
  3663. __be32 *p;
  3664. uint32_t opnum;
  3665. int32_t nfserr;
  3666. READ_BUF(8);
  3667. opnum = be32_to_cpup(p++);
  3668. if (opnum != OP_SETCLIENTID) {
  3669. dprintk("nfs: decode_setclientid: Server returned operation"
  3670. " %d\n", opnum);
  3671. return -EIO;
  3672. }
  3673. nfserr = be32_to_cpup(p++);
  3674. if (nfserr == NFS_OK) {
  3675. READ_BUF(8 + NFS4_VERIFIER_SIZE);
  3676. READ64(clp->cl_clientid);
  3677. COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
  3678. } else if (nfserr == NFSERR_CLID_INUSE) {
  3679. uint32_t len;
  3680. /* skip netid string */
  3681. READ_BUF(4);
  3682. len = be32_to_cpup(p++);
  3683. READ_BUF(len);
  3684. /* skip uaddr string */
  3685. READ_BUF(4);
  3686. len = be32_to_cpup(p++);
  3687. READ_BUF(len);
  3688. return -NFSERR_CLID_INUSE;
  3689. } else
  3690. return nfs4_stat_to_errno(nfserr);
  3691. return 0;
  3692. }
  3693. static int decode_setclientid_confirm(struct xdr_stream *xdr)
  3694. {
  3695. return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
  3696. }
  3697. static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
  3698. {
  3699. __be32 *p;
  3700. int status;
  3701. status = decode_op_hdr(xdr, OP_WRITE);
  3702. if (status)
  3703. return status;
  3704. READ_BUF(16);
  3705. res->count = be32_to_cpup(p++);
  3706. res->verf->committed = be32_to_cpup(p++);
  3707. COPYMEM(res->verf->verifier, 8);
  3708. return 0;
  3709. }
  3710. static int decode_delegreturn(struct xdr_stream *xdr)
  3711. {
  3712. return decode_op_hdr(xdr, OP_DELEGRETURN);
  3713. }
  3714. #if defined(CONFIG_NFS_V4_1)
  3715. static int decode_exchange_id(struct xdr_stream *xdr,
  3716. struct nfs41_exchange_id_res *res)
  3717. {
  3718. __be32 *p;
  3719. uint32_t dummy;
  3720. int status;
  3721. struct nfs_client *clp = res->client;
  3722. status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
  3723. if (status)
  3724. return status;
  3725. READ_BUF(8);
  3726. READ64(clp->cl_ex_clid);
  3727. READ_BUF(12);
  3728. clp->cl_seqid = be32_to_cpup(p++);
  3729. clp->cl_exchange_flags = be32_to_cpup(p++);
  3730. /* We ask for SP4_NONE */
  3731. dummy = be32_to_cpup(p++);
  3732. if (dummy != SP4_NONE)
  3733. return -EIO;
  3734. /* Throw away minor_id */
  3735. READ_BUF(8);
  3736. /* Throw away Major id */
  3737. READ_BUF(4);
  3738. dummy = be32_to_cpup(p++);
  3739. READ_BUF(dummy);
  3740. /* Throw away server_scope */
  3741. READ_BUF(4);
  3742. dummy = be32_to_cpup(p++);
  3743. READ_BUF(dummy);
  3744. /* Throw away Implementation id array */
  3745. READ_BUF(4);
  3746. dummy = be32_to_cpup(p++);
  3747. READ_BUF(dummy);
  3748. return 0;
  3749. }
  3750. static int decode_chan_attrs(struct xdr_stream *xdr,
  3751. struct nfs4_channel_attrs *attrs)
  3752. {
  3753. __be32 *p;
  3754. u32 nr_attrs;
  3755. READ_BUF(28);
  3756. attrs->headerpadsz = be32_to_cpup(p++);
  3757. attrs->max_rqst_sz = be32_to_cpup(p++);
  3758. attrs->max_resp_sz = be32_to_cpup(p++);
  3759. attrs->max_resp_sz_cached = be32_to_cpup(p++);
  3760. attrs->max_ops = be32_to_cpup(p++);
  3761. attrs->max_reqs = be32_to_cpup(p++);
  3762. nr_attrs = be32_to_cpup(p++);
  3763. if (unlikely(nr_attrs > 1)) {
  3764. printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
  3765. __func__, nr_attrs);
  3766. return -EINVAL;
  3767. }
  3768. if (nr_attrs == 1)
  3769. READ_BUF(4); /* skip rdma_attrs */
  3770. return 0;
  3771. }
  3772. static int decode_create_session(struct xdr_stream *xdr,
  3773. struct nfs41_create_session_res *res)
  3774. {
  3775. __be32 *p;
  3776. int status;
  3777. struct nfs_client *clp = res->client;
  3778. struct nfs4_session *session = clp->cl_session;
  3779. status = decode_op_hdr(xdr, OP_CREATE_SESSION);
  3780. if (status)
  3781. return status;
  3782. /* sessionid */
  3783. READ_BUF(NFS4_MAX_SESSIONID_LEN);
  3784. COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
  3785. /* seqid, flags */
  3786. READ_BUF(8);
  3787. clp->cl_seqid = be32_to_cpup(p++);
  3788. session->flags = be32_to_cpup(p++);
  3789. /* Channel attributes */
  3790. status = decode_chan_attrs(xdr, &session->fc_attrs);
  3791. if (!status)
  3792. status = decode_chan_attrs(xdr, &session->bc_attrs);
  3793. return status;
  3794. }
  3795. static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
  3796. {
  3797. return decode_op_hdr(xdr, OP_DESTROY_SESSION);
  3798. }
  3799. #endif /* CONFIG_NFS_V4_1 */
  3800. static int decode_sequence(struct xdr_stream *xdr,
  3801. struct nfs4_sequence_res *res,
  3802. struct rpc_rqst *rqstp)
  3803. {
  3804. #if defined(CONFIG_NFS_V4_1)
  3805. struct nfs4_slot *slot;
  3806. struct nfs4_sessionid id;
  3807. u32 dummy;
  3808. int status;
  3809. __be32 *p;
  3810. if (!res->sr_session)
  3811. return 0;
  3812. status = decode_op_hdr(xdr, OP_SEQUENCE);
  3813. if (status)
  3814. goto out_err;
  3815. /*
  3816. * If the server returns different values for sessionID, slotID or
  3817. * sequence number, the server is looney tunes.
  3818. */
  3819. status = -ESERVERFAULT;
  3820. slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
  3821. READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
  3822. COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
  3823. if (memcmp(id.data, res->sr_session->sess_id.data,
  3824. NFS4_MAX_SESSIONID_LEN)) {
  3825. dprintk("%s Invalid session id\n", __func__);
  3826. goto out_err;
  3827. }
  3828. /* seqid */
  3829. dummy = be32_to_cpup(p++);
  3830. if (dummy != slot->seq_nr) {
  3831. dprintk("%s Invalid sequence number\n", __func__);
  3832. goto out_err;
  3833. }
  3834. /* slot id */
  3835. dummy = be32_to_cpup(p++);
  3836. if (dummy != res->sr_slotid) {
  3837. dprintk("%s Invalid slot id\n", __func__);
  3838. goto out_err;
  3839. }
  3840. /* highest slot id - currently not processed */
  3841. dummy = be32_to_cpup(p++);
  3842. /* target highest slot id - currently not processed */
  3843. dummy = be32_to_cpup(p++);
  3844. /* result flags - currently not processed */
  3845. dummy = be32_to_cpup(p++);
  3846. status = 0;
  3847. out_err:
  3848. res->sr_status = status;
  3849. return status;
  3850. #else /* CONFIG_NFS_V4_1 */
  3851. return 0;
  3852. #endif /* CONFIG_NFS_V4_1 */
  3853. }
  3854. /*
  3855. * END OF "GENERIC" DECODE ROUTINES.
  3856. */
  3857. /*
  3858. * Decode OPEN_DOWNGRADE response
  3859. */
  3860. static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
  3861. {
  3862. struct xdr_stream xdr;
  3863. struct compound_hdr hdr;
  3864. int status;
  3865. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3866. status = decode_compound_hdr(&xdr, &hdr);
  3867. if (status)
  3868. goto out;
  3869. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3870. if (status)
  3871. goto out;
  3872. status = decode_putfh(&xdr);
  3873. if (status)
  3874. goto out;
  3875. status = decode_open_downgrade(&xdr, res);
  3876. if (status != 0)
  3877. goto out;
  3878. decode_getfattr(&xdr, res->fattr, res->server);
  3879. out:
  3880. return status;
  3881. }
  3882. /*
  3883. * Decode ACCESS response
  3884. */
  3885. static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
  3886. {
  3887. struct xdr_stream xdr;
  3888. struct compound_hdr hdr;
  3889. int status;
  3890. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3891. status = decode_compound_hdr(&xdr, &hdr);
  3892. if (status)
  3893. goto out;
  3894. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3895. if (status)
  3896. goto out;
  3897. status = decode_putfh(&xdr);
  3898. if (status != 0)
  3899. goto out;
  3900. status = decode_access(&xdr, res);
  3901. if (status != 0)
  3902. goto out;
  3903. decode_getfattr(&xdr, res->fattr, res->server);
  3904. out:
  3905. return status;
  3906. }
  3907. /*
  3908. * Decode LOOKUP response
  3909. */
  3910. static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
  3911. {
  3912. struct xdr_stream xdr;
  3913. struct compound_hdr hdr;
  3914. int status;
  3915. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3916. status = decode_compound_hdr(&xdr, &hdr);
  3917. if (status)
  3918. goto out;
  3919. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3920. if (status)
  3921. goto out;
  3922. if ((status = decode_putfh(&xdr)) != 0)
  3923. goto out;
  3924. if ((status = decode_lookup(&xdr)) != 0)
  3925. goto out;
  3926. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  3927. goto out;
  3928. status = decode_getfattr(&xdr, res->fattr, res->server);
  3929. out:
  3930. return status;
  3931. }
  3932. /*
  3933. * Decode LOOKUP_ROOT response
  3934. */
  3935. static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
  3936. {
  3937. struct xdr_stream xdr;
  3938. struct compound_hdr hdr;
  3939. int status;
  3940. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3941. status = decode_compound_hdr(&xdr, &hdr);
  3942. if (status)
  3943. goto out;
  3944. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3945. if (status)
  3946. goto out;
  3947. if ((status = decode_putrootfh(&xdr)) != 0)
  3948. goto out;
  3949. if ((status = decode_getfh(&xdr, res->fh)) == 0)
  3950. status = decode_getfattr(&xdr, res->fattr, res->server);
  3951. out:
  3952. return status;
  3953. }
  3954. /*
  3955. * Decode REMOVE response
  3956. */
  3957. static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
  3958. {
  3959. struct xdr_stream xdr;
  3960. struct compound_hdr hdr;
  3961. int status;
  3962. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3963. status = decode_compound_hdr(&xdr, &hdr);
  3964. if (status)
  3965. goto out;
  3966. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3967. if (status)
  3968. goto out;
  3969. if ((status = decode_putfh(&xdr)) != 0)
  3970. goto out;
  3971. if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
  3972. goto out;
  3973. decode_getfattr(&xdr, &res->dir_attr, res->server);
  3974. out:
  3975. return status;
  3976. }
  3977. /*
  3978. * Decode RENAME response
  3979. */
  3980. static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
  3981. {
  3982. struct xdr_stream xdr;
  3983. struct compound_hdr hdr;
  3984. int status;
  3985. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  3986. status = decode_compound_hdr(&xdr, &hdr);
  3987. if (status)
  3988. goto out;
  3989. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  3990. if (status)
  3991. goto out;
  3992. if ((status = decode_putfh(&xdr)) != 0)
  3993. goto out;
  3994. if ((status = decode_savefh(&xdr)) != 0)
  3995. goto out;
  3996. if ((status = decode_putfh(&xdr)) != 0)
  3997. goto out;
  3998. if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
  3999. goto out;
  4000. /* Current FH is target directory */
  4001. if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
  4002. goto out;
  4003. if ((status = decode_restorefh(&xdr)) != 0)
  4004. goto out;
  4005. decode_getfattr(&xdr, res->old_fattr, res->server);
  4006. out:
  4007. return status;
  4008. }
  4009. /*
  4010. * Decode LINK response
  4011. */
  4012. static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
  4013. {
  4014. struct xdr_stream xdr;
  4015. struct compound_hdr hdr;
  4016. int status;
  4017. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4018. status = decode_compound_hdr(&xdr, &hdr);
  4019. if (status)
  4020. goto out;
  4021. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4022. if (status)
  4023. goto out;
  4024. if ((status = decode_putfh(&xdr)) != 0)
  4025. goto out;
  4026. if ((status = decode_savefh(&xdr)) != 0)
  4027. goto out;
  4028. if ((status = decode_putfh(&xdr)) != 0)
  4029. goto out;
  4030. if ((status = decode_link(&xdr, &res->cinfo)) != 0)
  4031. goto out;
  4032. /*
  4033. * Note order: OP_LINK leaves the directory as the current
  4034. * filehandle.
  4035. */
  4036. if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
  4037. goto out;
  4038. if ((status = decode_restorefh(&xdr)) != 0)
  4039. goto out;
  4040. decode_getfattr(&xdr, res->fattr, res->server);
  4041. out:
  4042. return status;
  4043. }
  4044. /*
  4045. * Decode CREATE response
  4046. */
  4047. static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
  4048. {
  4049. struct xdr_stream xdr;
  4050. struct compound_hdr hdr;
  4051. int status;
  4052. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4053. status = decode_compound_hdr(&xdr, &hdr);
  4054. if (status)
  4055. goto out;
  4056. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4057. if (status)
  4058. goto out;
  4059. if ((status = decode_putfh(&xdr)) != 0)
  4060. goto out;
  4061. if ((status = decode_savefh(&xdr)) != 0)
  4062. goto out;
  4063. if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
  4064. goto out;
  4065. if ((status = decode_getfh(&xdr, res->fh)) != 0)
  4066. goto out;
  4067. if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
  4068. goto out;
  4069. if ((status = decode_restorefh(&xdr)) != 0)
  4070. goto out;
  4071. decode_getfattr(&xdr, res->dir_fattr, res->server);
  4072. out:
  4073. return status;
  4074. }
  4075. /*
  4076. * Decode SYMLINK response
  4077. */
  4078. static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
  4079. {
  4080. return nfs4_xdr_dec_create(rqstp, p, res);
  4081. }
  4082. /*
  4083. * Decode GETATTR response
  4084. */
  4085. static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
  4086. {
  4087. struct xdr_stream xdr;
  4088. struct compound_hdr hdr;
  4089. int status;
  4090. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4091. status = decode_compound_hdr(&xdr, &hdr);
  4092. if (status)
  4093. goto out;
  4094. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4095. if (status)
  4096. goto out;
  4097. status = decode_putfh(&xdr);
  4098. if (status)
  4099. goto out;
  4100. status = decode_getfattr(&xdr, res->fattr, res->server);
  4101. out:
  4102. return status;
  4103. }
  4104. /*
  4105. * Encode an SETACL request
  4106. */
  4107. static int
  4108. nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
  4109. {
  4110. struct xdr_stream xdr;
  4111. struct compound_hdr hdr = {
  4112. .minorversion = nfs4_xdr_minorversion(&args->seq_args),
  4113. };
  4114. int status;
  4115. xdr_init_encode(&xdr, &req->rq_snd_buf, p);
  4116. encode_compound_hdr(&xdr, req, &hdr);
  4117. encode_sequence(&xdr, &args->seq_args, &hdr);
  4118. encode_putfh(&xdr, args->fh, &hdr);
  4119. status = encode_setacl(&xdr, args, &hdr);
  4120. encode_nops(&hdr);
  4121. return status;
  4122. }
  4123. /*
  4124. * Decode SETACL response
  4125. */
  4126. static int
  4127. nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
  4128. struct nfs_setaclres *res)
  4129. {
  4130. struct xdr_stream xdr;
  4131. struct compound_hdr hdr;
  4132. int status;
  4133. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4134. status = decode_compound_hdr(&xdr, &hdr);
  4135. if (status)
  4136. goto out;
  4137. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4138. if (status)
  4139. goto out;
  4140. status = decode_putfh(&xdr);
  4141. if (status)
  4142. goto out;
  4143. status = decode_setattr(&xdr);
  4144. out:
  4145. return status;
  4146. }
  4147. /*
  4148. * Decode GETACL response
  4149. */
  4150. static int
  4151. nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
  4152. struct nfs_getaclres *res)
  4153. {
  4154. struct xdr_stream xdr;
  4155. struct compound_hdr hdr;
  4156. int status;
  4157. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4158. status = decode_compound_hdr(&xdr, &hdr);
  4159. if (status)
  4160. goto out;
  4161. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4162. if (status)
  4163. goto out;
  4164. status = decode_putfh(&xdr);
  4165. if (status)
  4166. goto out;
  4167. status = decode_getacl(&xdr, rqstp, &res->acl_len);
  4168. out:
  4169. return status;
  4170. }
  4171. /*
  4172. * Decode CLOSE response
  4173. */
  4174. static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
  4175. {
  4176. struct xdr_stream xdr;
  4177. struct compound_hdr hdr;
  4178. int status;
  4179. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4180. status = decode_compound_hdr(&xdr, &hdr);
  4181. if (status)
  4182. goto out;
  4183. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4184. if (status)
  4185. goto out;
  4186. status = decode_putfh(&xdr);
  4187. if (status)
  4188. goto out;
  4189. status = decode_close(&xdr, res);
  4190. if (status != 0)
  4191. goto out;
  4192. /*
  4193. * Note: Server may do delete on close for this file
  4194. * in which case the getattr call will fail with
  4195. * an ESTALE error. Shouldn't be a problem,
  4196. * though, since fattr->valid will remain unset.
  4197. */
  4198. decode_getfattr(&xdr, res->fattr, res->server);
  4199. out:
  4200. return status;
  4201. }
  4202. /*
  4203. * Decode OPEN response
  4204. */
  4205. static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
  4206. {
  4207. struct xdr_stream xdr;
  4208. struct compound_hdr hdr;
  4209. int status;
  4210. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4211. status = decode_compound_hdr(&xdr, &hdr);
  4212. if (status)
  4213. goto out;
  4214. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4215. if (status)
  4216. goto out;
  4217. status = decode_putfh(&xdr);
  4218. if (status)
  4219. goto out;
  4220. status = decode_savefh(&xdr);
  4221. if (status)
  4222. goto out;
  4223. status = decode_open(&xdr, res);
  4224. if (status)
  4225. goto out;
  4226. if (decode_getfh(&xdr, &res->fh) != 0)
  4227. goto out;
  4228. if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
  4229. goto out;
  4230. if (decode_restorefh(&xdr) != 0)
  4231. goto out;
  4232. decode_getfattr(&xdr, res->dir_attr, res->server);
  4233. out:
  4234. return status;
  4235. }
  4236. /*
  4237. * Decode OPEN_CONFIRM response
  4238. */
  4239. static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
  4240. {
  4241. struct xdr_stream xdr;
  4242. struct compound_hdr hdr;
  4243. int status;
  4244. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4245. status = decode_compound_hdr(&xdr, &hdr);
  4246. if (status)
  4247. goto out;
  4248. status = decode_putfh(&xdr);
  4249. if (status)
  4250. goto out;
  4251. status = decode_open_confirm(&xdr, res);
  4252. out:
  4253. return status;
  4254. }
  4255. /*
  4256. * Decode OPEN response
  4257. */
  4258. static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
  4259. {
  4260. struct xdr_stream xdr;
  4261. struct compound_hdr hdr;
  4262. int status;
  4263. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4264. status = decode_compound_hdr(&xdr, &hdr);
  4265. if (status)
  4266. goto out;
  4267. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4268. if (status)
  4269. goto out;
  4270. status = decode_putfh(&xdr);
  4271. if (status)
  4272. goto out;
  4273. status = decode_open(&xdr, res);
  4274. if (status)
  4275. goto out;
  4276. decode_getfattr(&xdr, res->f_attr, res->server);
  4277. out:
  4278. return status;
  4279. }
  4280. /*
  4281. * Decode SETATTR response
  4282. */
  4283. static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
  4284. {
  4285. struct xdr_stream xdr;
  4286. struct compound_hdr hdr;
  4287. int status;
  4288. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4289. status = decode_compound_hdr(&xdr, &hdr);
  4290. if (status)
  4291. goto out;
  4292. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4293. if (status)
  4294. goto out;
  4295. status = decode_putfh(&xdr);
  4296. if (status)
  4297. goto out;
  4298. status = decode_setattr(&xdr);
  4299. if (status)
  4300. goto out;
  4301. decode_getfattr(&xdr, res->fattr, res->server);
  4302. out:
  4303. return status;
  4304. }
  4305. /*
  4306. * Decode LOCK response
  4307. */
  4308. static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
  4309. {
  4310. struct xdr_stream xdr;
  4311. struct compound_hdr hdr;
  4312. int status;
  4313. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4314. status = decode_compound_hdr(&xdr, &hdr);
  4315. if (status)
  4316. goto out;
  4317. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4318. if (status)
  4319. goto out;
  4320. status = decode_putfh(&xdr);
  4321. if (status)
  4322. goto out;
  4323. status = decode_lock(&xdr, res);
  4324. out:
  4325. return status;
  4326. }
  4327. /*
  4328. * Decode LOCKT response
  4329. */
  4330. static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
  4331. {
  4332. struct xdr_stream xdr;
  4333. struct compound_hdr hdr;
  4334. int status;
  4335. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4336. status = decode_compound_hdr(&xdr, &hdr);
  4337. if (status)
  4338. goto out;
  4339. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4340. if (status)
  4341. goto out;
  4342. status = decode_putfh(&xdr);
  4343. if (status)
  4344. goto out;
  4345. status = decode_lockt(&xdr, res);
  4346. out:
  4347. return status;
  4348. }
  4349. /*
  4350. * Decode LOCKU response
  4351. */
  4352. static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
  4353. {
  4354. struct xdr_stream xdr;
  4355. struct compound_hdr hdr;
  4356. int status;
  4357. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4358. status = decode_compound_hdr(&xdr, &hdr);
  4359. if (status)
  4360. goto out;
  4361. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4362. if (status)
  4363. goto out;
  4364. status = decode_putfh(&xdr);
  4365. if (status)
  4366. goto out;
  4367. status = decode_locku(&xdr, res);
  4368. out:
  4369. return status;
  4370. }
  4371. /*
  4372. * Decode READLINK response
  4373. */
  4374. static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
  4375. struct nfs4_readlink_res *res)
  4376. {
  4377. struct xdr_stream xdr;
  4378. struct compound_hdr hdr;
  4379. int status;
  4380. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4381. status = decode_compound_hdr(&xdr, &hdr);
  4382. if (status)
  4383. goto out;
  4384. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4385. if (status)
  4386. goto out;
  4387. status = decode_putfh(&xdr);
  4388. if (status)
  4389. goto out;
  4390. status = decode_readlink(&xdr, rqstp);
  4391. out:
  4392. return status;
  4393. }
  4394. /*
  4395. * Decode READDIR response
  4396. */
  4397. static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
  4398. {
  4399. struct xdr_stream xdr;
  4400. struct compound_hdr hdr;
  4401. int status;
  4402. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4403. status = decode_compound_hdr(&xdr, &hdr);
  4404. if (status)
  4405. goto out;
  4406. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4407. if (status)
  4408. goto out;
  4409. status = decode_putfh(&xdr);
  4410. if (status)
  4411. goto out;
  4412. status = decode_readdir(&xdr, rqstp, res);
  4413. out:
  4414. return status;
  4415. }
  4416. /*
  4417. * Decode Read response
  4418. */
  4419. static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
  4420. {
  4421. struct xdr_stream xdr;
  4422. struct compound_hdr hdr;
  4423. int status;
  4424. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4425. status = decode_compound_hdr(&xdr, &hdr);
  4426. if (status)
  4427. goto out;
  4428. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4429. if (status)
  4430. goto out;
  4431. status = decode_putfh(&xdr);
  4432. if (status)
  4433. goto out;
  4434. status = decode_read(&xdr, rqstp, res);
  4435. if (!status)
  4436. status = res->count;
  4437. out:
  4438. return status;
  4439. }
  4440. /*
  4441. * Decode WRITE response
  4442. */
  4443. static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
  4444. {
  4445. struct xdr_stream xdr;
  4446. struct compound_hdr hdr;
  4447. int status;
  4448. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4449. status = decode_compound_hdr(&xdr, &hdr);
  4450. if (status)
  4451. goto out;
  4452. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4453. if (status)
  4454. goto out;
  4455. status = decode_putfh(&xdr);
  4456. if (status)
  4457. goto out;
  4458. status = decode_write(&xdr, res);
  4459. if (status)
  4460. goto out;
  4461. decode_getfattr(&xdr, res->fattr, res->server);
  4462. if (!status)
  4463. status = res->count;
  4464. out:
  4465. return status;
  4466. }
  4467. /*
  4468. * Decode COMMIT response
  4469. */
  4470. static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
  4471. {
  4472. struct xdr_stream xdr;
  4473. struct compound_hdr hdr;
  4474. int status;
  4475. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4476. status = decode_compound_hdr(&xdr, &hdr);
  4477. if (status)
  4478. goto out;
  4479. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4480. if (status)
  4481. goto out;
  4482. status = decode_putfh(&xdr);
  4483. if (status)
  4484. goto out;
  4485. status = decode_commit(&xdr, res);
  4486. if (status)
  4487. goto out;
  4488. decode_getfattr(&xdr, res->fattr, res->server);
  4489. out:
  4490. return status;
  4491. }
  4492. /*
  4493. * FSINFO request
  4494. */
  4495. static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
  4496. struct nfs4_fsinfo_res *res)
  4497. {
  4498. struct xdr_stream xdr;
  4499. struct compound_hdr hdr;
  4500. int status;
  4501. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4502. status = decode_compound_hdr(&xdr, &hdr);
  4503. if (!status)
  4504. status = decode_sequence(&xdr, &res->seq_res, req);
  4505. if (!status)
  4506. status = decode_putfh(&xdr);
  4507. if (!status)
  4508. status = decode_fsinfo(&xdr, res->fsinfo);
  4509. return status;
  4510. }
  4511. /*
  4512. * PATHCONF request
  4513. */
  4514. static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
  4515. struct nfs4_pathconf_res *res)
  4516. {
  4517. struct xdr_stream xdr;
  4518. struct compound_hdr hdr;
  4519. int status;
  4520. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4521. status = decode_compound_hdr(&xdr, &hdr);
  4522. if (!status)
  4523. status = decode_sequence(&xdr, &res->seq_res, req);
  4524. if (!status)
  4525. status = decode_putfh(&xdr);
  4526. if (!status)
  4527. status = decode_pathconf(&xdr, res->pathconf);
  4528. return status;
  4529. }
  4530. /*
  4531. * STATFS request
  4532. */
  4533. static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
  4534. struct nfs4_statfs_res *res)
  4535. {
  4536. struct xdr_stream xdr;
  4537. struct compound_hdr hdr;
  4538. int status;
  4539. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4540. status = decode_compound_hdr(&xdr, &hdr);
  4541. if (!status)
  4542. status = decode_sequence(&xdr, &res->seq_res, req);
  4543. if (!status)
  4544. status = decode_putfh(&xdr);
  4545. if (!status)
  4546. status = decode_statfs(&xdr, res->fsstat);
  4547. return status;
  4548. }
  4549. /*
  4550. * GETATTR_BITMAP request
  4551. */
  4552. static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
  4553. {
  4554. struct xdr_stream xdr;
  4555. struct compound_hdr hdr;
  4556. int status;
  4557. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4558. status = decode_compound_hdr(&xdr, &hdr);
  4559. if (status)
  4560. goto out;
  4561. status = decode_sequence(&xdr, &res->seq_res, req);
  4562. if (status)
  4563. goto out;
  4564. if ((status = decode_putfh(&xdr)) != 0)
  4565. goto out;
  4566. status = decode_server_caps(&xdr, res);
  4567. out:
  4568. return status;
  4569. }
  4570. /*
  4571. * Decode RENEW response
  4572. */
  4573. static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
  4574. {
  4575. struct xdr_stream xdr;
  4576. struct compound_hdr hdr;
  4577. int status;
  4578. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4579. status = decode_compound_hdr(&xdr, &hdr);
  4580. if (!status)
  4581. status = decode_renew(&xdr);
  4582. return status;
  4583. }
  4584. /*
  4585. * a SETCLIENTID request
  4586. */
  4587. static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
  4588. struct nfs_client *clp)
  4589. {
  4590. struct xdr_stream xdr;
  4591. struct compound_hdr hdr;
  4592. int status;
  4593. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4594. status = decode_compound_hdr(&xdr, &hdr);
  4595. if (!status)
  4596. status = decode_setclientid(&xdr, clp);
  4597. return status;
  4598. }
  4599. /*
  4600. * a SETCLIENTID_CONFIRM request
  4601. */
  4602. static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
  4603. {
  4604. struct xdr_stream xdr;
  4605. struct compound_hdr hdr;
  4606. int status;
  4607. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4608. status = decode_compound_hdr(&xdr, &hdr);
  4609. if (!status)
  4610. status = decode_setclientid_confirm(&xdr);
  4611. if (!status)
  4612. status = decode_putrootfh(&xdr);
  4613. if (!status)
  4614. status = decode_fsinfo(&xdr, fsinfo);
  4615. return status;
  4616. }
  4617. /*
  4618. * DELEGRETURN request
  4619. */
  4620. static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
  4621. {
  4622. struct xdr_stream xdr;
  4623. struct compound_hdr hdr;
  4624. int status;
  4625. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4626. status = decode_compound_hdr(&xdr, &hdr);
  4627. if (status)
  4628. goto out;
  4629. status = decode_sequence(&xdr, &res->seq_res, rqstp);
  4630. if (status)
  4631. goto out;
  4632. status = decode_putfh(&xdr);
  4633. if (status != 0)
  4634. goto out;
  4635. status = decode_delegreturn(&xdr);
  4636. decode_getfattr(&xdr, res->fattr, res->server);
  4637. out:
  4638. return status;
  4639. }
  4640. /*
  4641. * FS_LOCATIONS request
  4642. */
  4643. static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
  4644. struct nfs4_fs_locations_res *res)
  4645. {
  4646. struct xdr_stream xdr;
  4647. struct compound_hdr hdr;
  4648. int status;
  4649. xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
  4650. status = decode_compound_hdr(&xdr, &hdr);
  4651. if (status)
  4652. goto out;
  4653. status = decode_sequence(&xdr, &res->seq_res, req);
  4654. if (status)
  4655. goto out;
  4656. if ((status = decode_putfh(&xdr)) != 0)
  4657. goto out;
  4658. if ((status = decode_lookup(&xdr)) != 0)
  4659. goto out;
  4660. xdr_enter_page(&xdr, PAGE_SIZE);
  4661. status = decode_getfattr(&xdr, &res->fs_locations->fattr,
  4662. res->fs_locations->server);
  4663. out:
  4664. return status;
  4665. }
  4666. #if defined(CONFIG_NFS_V4_1)
  4667. /*
  4668. * EXCHANGE_ID request
  4669. */
  4670. static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p,
  4671. void *res)
  4672. {
  4673. struct xdr_stream xdr;
  4674. struct compound_hdr hdr;
  4675. int status;
  4676. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4677. status = decode_compound_hdr(&xdr, &hdr);
  4678. if (!status)
  4679. status = decode_exchange_id(&xdr, res);
  4680. return status;
  4681. }
  4682. /*
  4683. * a CREATE_SESSION request
  4684. */
  4685. static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p,
  4686. struct nfs41_create_session_res *res)
  4687. {
  4688. struct xdr_stream xdr;
  4689. struct compound_hdr hdr;
  4690. int status;
  4691. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4692. status = decode_compound_hdr(&xdr, &hdr);
  4693. if (!status)
  4694. status = decode_create_session(&xdr, res);
  4695. return status;
  4696. }
  4697. /*
  4698. * a DESTROY_SESSION request
  4699. */
  4700. static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p,
  4701. void *dummy)
  4702. {
  4703. struct xdr_stream xdr;
  4704. struct compound_hdr hdr;
  4705. int status;
  4706. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4707. status = decode_compound_hdr(&xdr, &hdr);
  4708. if (!status)
  4709. status = decode_destroy_session(&xdr, dummy);
  4710. return status;
  4711. }
  4712. /*
  4713. * a SEQUENCE request
  4714. */
  4715. static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p,
  4716. struct nfs4_sequence_res *res)
  4717. {
  4718. struct xdr_stream xdr;
  4719. struct compound_hdr hdr;
  4720. int status;
  4721. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4722. status = decode_compound_hdr(&xdr, &hdr);
  4723. if (!status)
  4724. status = decode_sequence(&xdr, res, rqstp);
  4725. return status;
  4726. }
  4727. /*
  4728. * a GET_LEASE_TIME request
  4729. */
  4730. static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p,
  4731. struct nfs4_get_lease_time_res *res)
  4732. {
  4733. struct xdr_stream xdr;
  4734. struct compound_hdr hdr;
  4735. int status;
  4736. xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
  4737. status = decode_compound_hdr(&xdr, &hdr);
  4738. if (!status)
  4739. status = decode_sequence(&xdr, &res->lr_seq_res, rqstp);
  4740. if (!status)
  4741. status = decode_putrootfh(&xdr);
  4742. if (!status)
  4743. status = decode_fsinfo(&xdr, res->lr_fsinfo);
  4744. return status;
  4745. }
  4746. #endif /* CONFIG_NFS_V4_1 */
  4747. __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
  4748. {
  4749. uint32_t bitmap[2] = {0};
  4750. uint32_t len;
  4751. if (!*p++) {
  4752. if (!*p)
  4753. return ERR_PTR(-EAGAIN);
  4754. entry->eof = 1;
  4755. return ERR_PTR(-EBADCOOKIE);
  4756. }
  4757. entry->prev_cookie = entry->cookie;
  4758. p = xdr_decode_hyper(p, &entry->cookie);
  4759. entry->len = ntohl(*p++);
  4760. entry->name = (const char *) p;
  4761. p += XDR_QUADLEN(entry->len);
  4762. /*
  4763. * In case the server doesn't return an inode number,
  4764. * we fake one here. (We don't use inode number 0,
  4765. * since glibc seems to choke on it...)
  4766. */
  4767. entry->ino = 1;
  4768. len = ntohl(*p++); /* bitmap length */
  4769. if (len-- > 0) {
  4770. bitmap[0] = ntohl(*p++);
  4771. if (len-- > 0) {
  4772. bitmap[1] = ntohl(*p++);
  4773. p += len;
  4774. }
  4775. }
  4776. len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
  4777. if (len > 0) {
  4778. if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
  4779. bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
  4780. /* Ignore the return value of rdattr_error for now */
  4781. p++;
  4782. len--;
  4783. }
  4784. if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
  4785. xdr_decode_hyper(p, &entry->ino);
  4786. else if (bitmap[0] == FATTR4_WORD0_FILEID)
  4787. xdr_decode_hyper(p, &entry->ino);
  4788. p += len;
  4789. }
  4790. entry->eof = !p[0] && p[1];
  4791. return p;
  4792. }
  4793. /*
  4794. * We need to translate between nfs status return values and
  4795. * the local errno values which may not be the same.
  4796. */
  4797. static struct {
  4798. int stat;
  4799. int errno;
  4800. } nfs_errtbl[] = {
  4801. { NFS4_OK, 0 },
  4802. { NFS4ERR_PERM, -EPERM },
  4803. { NFS4ERR_NOENT, -ENOENT },
  4804. { NFS4ERR_IO, -errno_NFSERR_IO},
  4805. { NFS4ERR_NXIO, -ENXIO },
  4806. { NFS4ERR_ACCESS, -EACCES },
  4807. { NFS4ERR_EXIST, -EEXIST },
  4808. { NFS4ERR_XDEV, -EXDEV },
  4809. { NFS4ERR_NOTDIR, -ENOTDIR },
  4810. { NFS4ERR_ISDIR, -EISDIR },
  4811. { NFS4ERR_INVAL, -EINVAL },
  4812. { NFS4ERR_FBIG, -EFBIG },
  4813. { NFS4ERR_NOSPC, -ENOSPC },
  4814. { NFS4ERR_ROFS, -EROFS },
  4815. { NFS4ERR_MLINK, -EMLINK },
  4816. { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
  4817. { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
  4818. { NFS4ERR_DQUOT, -EDQUOT },
  4819. { NFS4ERR_STALE, -ESTALE },
  4820. { NFS4ERR_BADHANDLE, -EBADHANDLE },
  4821. { NFS4ERR_BADOWNER, -EINVAL },
  4822. { NFS4ERR_BADNAME, -EINVAL },
  4823. { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
  4824. { NFS4ERR_NOTSUPP, -ENOTSUPP },
  4825. { NFS4ERR_TOOSMALL, -ETOOSMALL },
  4826. { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
  4827. { NFS4ERR_BADTYPE, -EBADTYPE },
  4828. { NFS4ERR_LOCKED, -EAGAIN },
  4829. { NFS4ERR_RESOURCE, -EREMOTEIO },
  4830. { NFS4ERR_SYMLINK, -ELOOP },
  4831. { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
  4832. { NFS4ERR_DEADLOCK, -EDEADLK },
  4833. { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
  4834. * to be handled by a
  4835. * middle-layer.
  4836. */
  4837. { -1, -EIO }
  4838. };
  4839. /*
  4840. * Convert an NFS error code to a local one.
  4841. * This one is used jointly by NFSv2 and NFSv3.
  4842. */
  4843. static int
  4844. nfs4_stat_to_errno(int stat)
  4845. {
  4846. int i;
  4847. for (i = 0; nfs_errtbl[i].stat != -1; i++) {
  4848. if (nfs_errtbl[i].stat == stat)
  4849. return nfs_errtbl[i].errno;
  4850. }
  4851. if (stat <= 10000 || stat > 10100) {
  4852. /* The server is looney tunes. */
  4853. return -ESERVERFAULT;
  4854. }
  4855. /* If we cannot translate the error, the recovery routines should
  4856. * handle it.
  4857. * Note: remaining NFSv4 error codes have values > 10000, so should
  4858. * not conflict with native Linux error codes.
  4859. */
  4860. return -stat;
  4861. }
  4862. #define PROC(proc, argtype, restype) \
  4863. [NFSPROC4_CLNT_##proc] = { \
  4864. .p_proc = NFSPROC4_COMPOUND, \
  4865. .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
  4866. .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
  4867. .p_arglen = NFS4_##argtype##_sz, \
  4868. .p_replen = NFS4_##restype##_sz, \
  4869. .p_statidx = NFSPROC4_CLNT_##proc, \
  4870. .p_name = #proc, \
  4871. }
  4872. struct rpc_procinfo nfs4_procedures[] = {
  4873. PROC(READ, enc_read, dec_read),
  4874. PROC(WRITE, enc_write, dec_write),
  4875. PROC(COMMIT, enc_commit, dec_commit),
  4876. PROC(OPEN, enc_open, dec_open),
  4877. PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
  4878. PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
  4879. PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
  4880. PROC(CLOSE, enc_close, dec_close),
  4881. PROC(SETATTR, enc_setattr, dec_setattr),
  4882. PROC(FSINFO, enc_fsinfo, dec_fsinfo),
  4883. PROC(RENEW, enc_renew, dec_renew),
  4884. PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
  4885. PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
  4886. PROC(LOCK, enc_lock, dec_lock),
  4887. PROC(LOCKT, enc_lockt, dec_lockt),
  4888. PROC(LOCKU, enc_locku, dec_locku),
  4889. PROC(ACCESS, enc_access, dec_access),
  4890. PROC(GETATTR, enc_getattr, dec_getattr),
  4891. PROC(LOOKUP, enc_lookup, dec_lookup),
  4892. PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
  4893. PROC(REMOVE, enc_remove, dec_remove),
  4894. PROC(RENAME, enc_rename, dec_rename),
  4895. PROC(LINK, enc_link, dec_link),
  4896. PROC(SYMLINK, enc_symlink, dec_symlink),
  4897. PROC(CREATE, enc_create, dec_create),
  4898. PROC(PATHCONF, enc_pathconf, dec_pathconf),
  4899. PROC(STATFS, enc_statfs, dec_statfs),
  4900. PROC(READLINK, enc_readlink, dec_readlink),
  4901. PROC(READDIR, enc_readdir, dec_readdir),
  4902. PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
  4903. PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
  4904. PROC(GETACL, enc_getacl, dec_getacl),
  4905. PROC(SETACL, enc_setacl, dec_setacl),
  4906. PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
  4907. #if defined(CONFIG_NFS_V4_1)
  4908. PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
  4909. PROC(CREATE_SESSION, enc_create_session, dec_create_session),
  4910. PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
  4911. PROC(SEQUENCE, enc_sequence, dec_sequence),
  4912. PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
  4913. #endif /* CONFIG_NFS_V4_1 */
  4914. };
  4915. struct rpc_version nfs_version4 = {
  4916. .number = 4,
  4917. .nrprocs = ARRAY_SIZE(nfs4_procedures),
  4918. .procs = nfs4_procedures
  4919. };
  4920. /*
  4921. * Local variables:
  4922. * c-basic-offset: 8
  4923. * End:
  4924. */