nfs4xdr.c 143 KB

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