nfs4proc.c 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022
  1. /*
  2. * fs/nfs/nfs4proc.c
  3. *
  4. * Client-side procedure declarations 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/mm.h>
  38. #include <linux/utsname.h>
  39. #include <linux/delay.h>
  40. #include <linux/errno.h>
  41. #include <linux/string.h>
  42. #include <linux/sunrpc/clnt.h>
  43. #include <linux/nfs.h>
  44. #include <linux/nfs4.h>
  45. #include <linux/nfs_fs.h>
  46. #include <linux/nfs_page.h>
  47. #include <linux/smp_lock.h>
  48. #include <linux/namei.h>
  49. #include <linux/mount.h>
  50. #include <linux/module.h>
  51. #include <linux/sunrpc/bc_xprt.h>
  52. #include "nfs4_fs.h"
  53. #include "delegation.h"
  54. #include "internal.h"
  55. #include "iostat.h"
  56. #include "callback.h"
  57. #define NFSDBG_FACILITY NFSDBG_PROC
  58. #define NFS4_POLL_RETRY_MIN (HZ/10)
  59. #define NFS4_POLL_RETRY_MAX (15*HZ)
  60. struct nfs4_opendata;
  61. static int _nfs4_proc_open(struct nfs4_opendata *data);
  62. static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
  63. static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
  64. static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
  65. static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
  66. /* Prevent leaks of NFSv4 errors into userland */
  67. static int nfs4_map_errors(int err)
  68. {
  69. if (err < -1000) {
  70. dprintk("%s could not handle NFSv4 error %d\n",
  71. __func__, -err);
  72. return -EIO;
  73. }
  74. return err;
  75. }
  76. /*
  77. * This is our standard bitmap for GETATTR requests.
  78. */
  79. const u32 nfs4_fattr_bitmap[2] = {
  80. FATTR4_WORD0_TYPE
  81. | FATTR4_WORD0_CHANGE
  82. | FATTR4_WORD0_SIZE
  83. | FATTR4_WORD0_FSID
  84. | FATTR4_WORD0_FILEID,
  85. FATTR4_WORD1_MODE
  86. | FATTR4_WORD1_NUMLINKS
  87. | FATTR4_WORD1_OWNER
  88. | FATTR4_WORD1_OWNER_GROUP
  89. | FATTR4_WORD1_RAWDEV
  90. | FATTR4_WORD1_SPACE_USED
  91. | FATTR4_WORD1_TIME_ACCESS
  92. | FATTR4_WORD1_TIME_METADATA
  93. | FATTR4_WORD1_TIME_MODIFY
  94. };
  95. const u32 nfs4_statfs_bitmap[2] = {
  96. FATTR4_WORD0_FILES_AVAIL
  97. | FATTR4_WORD0_FILES_FREE
  98. | FATTR4_WORD0_FILES_TOTAL,
  99. FATTR4_WORD1_SPACE_AVAIL
  100. | FATTR4_WORD1_SPACE_FREE
  101. | FATTR4_WORD1_SPACE_TOTAL
  102. };
  103. const u32 nfs4_pathconf_bitmap[2] = {
  104. FATTR4_WORD0_MAXLINK
  105. | FATTR4_WORD0_MAXNAME,
  106. 0
  107. };
  108. const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
  109. | FATTR4_WORD0_MAXREAD
  110. | FATTR4_WORD0_MAXWRITE
  111. | FATTR4_WORD0_LEASE_TIME,
  112. 0
  113. };
  114. const u32 nfs4_fs_locations_bitmap[2] = {
  115. FATTR4_WORD0_TYPE
  116. | FATTR4_WORD0_CHANGE
  117. | FATTR4_WORD0_SIZE
  118. | FATTR4_WORD0_FSID
  119. | FATTR4_WORD0_FILEID
  120. | FATTR4_WORD0_FS_LOCATIONS,
  121. FATTR4_WORD1_MODE
  122. | FATTR4_WORD1_NUMLINKS
  123. | FATTR4_WORD1_OWNER
  124. | FATTR4_WORD1_OWNER_GROUP
  125. | FATTR4_WORD1_RAWDEV
  126. | FATTR4_WORD1_SPACE_USED
  127. | FATTR4_WORD1_TIME_ACCESS
  128. | FATTR4_WORD1_TIME_METADATA
  129. | FATTR4_WORD1_TIME_MODIFY
  130. | FATTR4_WORD1_MOUNTED_ON_FILEID
  131. };
  132. static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
  133. struct nfs4_readdir_arg *readdir)
  134. {
  135. __be32 *start, *p;
  136. BUG_ON(readdir->count < 80);
  137. if (cookie > 2) {
  138. readdir->cookie = cookie;
  139. memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
  140. return;
  141. }
  142. readdir->cookie = 0;
  143. memset(&readdir->verifier, 0, sizeof(readdir->verifier));
  144. if (cookie == 2)
  145. return;
  146. /*
  147. * NFSv4 servers do not return entries for '.' and '..'
  148. * Therefore, we fake these entries here. We let '.'
  149. * have cookie 0 and '..' have cookie 1. Note that
  150. * when talking to the server, we always send cookie 0
  151. * instead of 1 or 2.
  152. */
  153. start = p = kmap_atomic(*readdir->pages, KM_USER0);
  154. if (cookie == 0) {
  155. *p++ = xdr_one; /* next */
  156. *p++ = xdr_zero; /* cookie, first word */
  157. *p++ = xdr_one; /* cookie, second word */
  158. *p++ = xdr_one; /* entry len */
  159. memcpy(p, ".\0\0\0", 4); /* entry */
  160. p++;
  161. *p++ = xdr_one; /* bitmap length */
  162. *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
  163. *p++ = htonl(8); /* attribute buffer length */
  164. p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
  165. }
  166. *p++ = xdr_one; /* next */
  167. *p++ = xdr_zero; /* cookie, first word */
  168. *p++ = xdr_two; /* cookie, second word */
  169. *p++ = xdr_two; /* entry len */
  170. memcpy(p, "..\0\0", 4); /* entry */
  171. p++;
  172. *p++ = xdr_one; /* bitmap length */
  173. *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
  174. *p++ = htonl(8); /* attribute buffer length */
  175. p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
  176. readdir->pgbase = (char *)p - (char *)start;
  177. readdir->count -= readdir->pgbase;
  178. kunmap_atomic(start, KM_USER0);
  179. }
  180. static int nfs4_wait_clnt_recover(struct nfs_client *clp)
  181. {
  182. int res;
  183. might_sleep();
  184. res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
  185. nfs_wait_bit_killable, TASK_KILLABLE);
  186. return res;
  187. }
  188. static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
  189. {
  190. int res = 0;
  191. might_sleep();
  192. if (*timeout <= 0)
  193. *timeout = NFS4_POLL_RETRY_MIN;
  194. if (*timeout > NFS4_POLL_RETRY_MAX)
  195. *timeout = NFS4_POLL_RETRY_MAX;
  196. schedule_timeout_killable(*timeout);
  197. if (fatal_signal_pending(current))
  198. res = -ERESTARTSYS;
  199. *timeout <<= 1;
  200. return res;
  201. }
  202. /* This is the error handling routine for processes that are allowed
  203. * to sleep.
  204. */
  205. static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
  206. {
  207. struct nfs_client *clp = server->nfs_client;
  208. struct nfs4_state *state = exception->state;
  209. int ret = errorcode;
  210. exception->retry = 0;
  211. switch(errorcode) {
  212. case 0:
  213. return 0;
  214. case -NFS4ERR_ADMIN_REVOKED:
  215. case -NFS4ERR_BAD_STATEID:
  216. case -NFS4ERR_OPENMODE:
  217. if (state == NULL)
  218. break;
  219. nfs4_state_mark_reclaim_nograce(clp, state);
  220. case -NFS4ERR_STALE_CLIENTID:
  221. case -NFS4ERR_STALE_STATEID:
  222. case -NFS4ERR_EXPIRED:
  223. nfs4_schedule_state_recovery(clp);
  224. ret = nfs4_wait_clnt_recover(clp);
  225. if (ret == 0)
  226. exception->retry = 1;
  227. #if !defined(CONFIG_NFS_V4_1)
  228. break;
  229. #else /* !defined(CONFIG_NFS_V4_1) */
  230. if (!nfs4_has_session(server->nfs_client))
  231. break;
  232. /* FALLTHROUGH */
  233. case -NFS4ERR_BADSESSION:
  234. case -NFS4ERR_BADSLOT:
  235. case -NFS4ERR_BAD_HIGH_SLOT:
  236. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  237. case -NFS4ERR_DEADSESSION:
  238. case -NFS4ERR_SEQ_FALSE_RETRY:
  239. case -NFS4ERR_SEQ_MISORDERED:
  240. dprintk("%s ERROR: %d Reset session\n", __func__,
  241. errorcode);
  242. set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
  243. exception->retry = 1;
  244. /* FALLTHROUGH */
  245. #endif /* !defined(CONFIG_NFS_V4_1) */
  246. case -NFS4ERR_FILE_OPEN:
  247. case -NFS4ERR_GRACE:
  248. case -NFS4ERR_DELAY:
  249. ret = nfs4_delay(server->client, &exception->timeout);
  250. if (ret != 0)
  251. break;
  252. case -NFS4ERR_OLD_STATEID:
  253. exception->retry = 1;
  254. }
  255. /* We failed to handle the error */
  256. return nfs4_map_errors(ret);
  257. }
  258. static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
  259. {
  260. struct nfs_client *clp = server->nfs_client;
  261. spin_lock(&clp->cl_lock);
  262. if (time_before(clp->cl_last_renewal,timestamp))
  263. clp->cl_last_renewal = timestamp;
  264. spin_unlock(&clp->cl_lock);
  265. }
  266. #if defined(CONFIG_NFS_V4_1)
  267. /*
  268. * nfs4_free_slot - free a slot and efficiently update slot table.
  269. *
  270. * freeing a slot is trivially done by clearing its respective bit
  271. * in the bitmap.
  272. * If the freed slotid equals highest_used_slotid we want to update it
  273. * so that the server would be able to size down the slot table if needed,
  274. * otherwise we know that the highest_used_slotid is still in use.
  275. * When updating highest_used_slotid there may be "holes" in the bitmap
  276. * so we need to scan down from highest_used_slotid to 0 looking for the now
  277. * highest slotid in use.
  278. * If none found, highest_used_slotid is set to -1.
  279. */
  280. static void
  281. nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
  282. {
  283. int slotid = free_slotid;
  284. spin_lock(&tbl->slot_tbl_lock);
  285. /* clear used bit in bitmap */
  286. __clear_bit(slotid, tbl->used_slots);
  287. /* update highest_used_slotid when it is freed */
  288. if (slotid == tbl->highest_used_slotid) {
  289. slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
  290. if (slotid >= 0 && slotid < tbl->max_slots)
  291. tbl->highest_used_slotid = slotid;
  292. else
  293. tbl->highest_used_slotid = -1;
  294. }
  295. rpc_wake_up_next(&tbl->slot_tbl_waitq);
  296. spin_unlock(&tbl->slot_tbl_lock);
  297. dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__,
  298. free_slotid, tbl->highest_used_slotid);
  299. }
  300. void nfs41_sequence_free_slot(const struct nfs_client *clp,
  301. struct nfs4_sequence_res *res)
  302. {
  303. struct nfs4_slot_table *tbl;
  304. if (!nfs4_has_session(clp)) {
  305. dprintk("%s: No session\n", __func__);
  306. return;
  307. }
  308. tbl = &clp->cl_session->fc_slot_table;
  309. if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) {
  310. dprintk("%s: No slot\n", __func__);
  311. /* just wake up the next guy waiting since
  312. * we may have not consumed a slot after all */
  313. rpc_wake_up_next(&tbl->slot_tbl_waitq);
  314. return;
  315. }
  316. nfs4_free_slot(tbl, res->sr_slotid);
  317. res->sr_slotid = NFS4_MAX_SLOT_TABLE;
  318. }
  319. static void nfs41_sequence_done(struct nfs_client *clp,
  320. struct nfs4_sequence_res *res,
  321. int rpc_status)
  322. {
  323. unsigned long timestamp;
  324. struct nfs4_slot_table *tbl;
  325. struct nfs4_slot *slot;
  326. /*
  327. * sr_status remains 1 if an RPC level error occurred. The server
  328. * may or may not have processed the sequence operation..
  329. * Proceed as if the server received and processed the sequence
  330. * operation.
  331. */
  332. if (res->sr_status == 1)
  333. res->sr_status = NFS_OK;
  334. /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
  335. if (res->sr_slotid == NFS4_MAX_SLOT_TABLE)
  336. goto out;
  337. tbl = &clp->cl_session->fc_slot_table;
  338. slot = tbl->slots + res->sr_slotid;
  339. if (res->sr_status == 0) {
  340. /* Update the slot's sequence and clientid lease timer */
  341. ++slot->seq_nr;
  342. timestamp = res->sr_renewal_time;
  343. spin_lock(&clp->cl_lock);
  344. if (time_before(clp->cl_last_renewal, timestamp))
  345. clp->cl_last_renewal = timestamp;
  346. spin_unlock(&clp->cl_lock);
  347. return;
  348. }
  349. out:
  350. /* The session may be reset by one of the error handlers. */
  351. dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
  352. nfs41_sequence_free_slot(clp, res);
  353. }
  354. /*
  355. * nfs4_find_slot - efficiently look for a free slot
  356. *
  357. * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
  358. * If found, we mark the slot as used, update the highest_used_slotid,
  359. * and respectively set up the sequence operation args.
  360. * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
  361. *
  362. * Note: must be called with under the slot_tbl_lock.
  363. */
  364. static u8
  365. nfs4_find_slot(struct nfs4_slot_table *tbl, struct rpc_task *task)
  366. {
  367. int slotid;
  368. u8 ret_id = NFS4_MAX_SLOT_TABLE;
  369. BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
  370. dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
  371. __func__, tbl->used_slots[0], tbl->highest_used_slotid,
  372. tbl->max_slots);
  373. slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
  374. if (slotid >= tbl->max_slots)
  375. goto out;
  376. __set_bit(slotid, tbl->used_slots);
  377. if (slotid > tbl->highest_used_slotid)
  378. tbl->highest_used_slotid = slotid;
  379. ret_id = slotid;
  380. out:
  381. dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
  382. __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
  383. return ret_id;
  384. }
  385. static int nfs4_recover_session(struct nfs4_session *session)
  386. {
  387. struct nfs_client *clp = session->clp;
  388. int ret;
  389. for (;;) {
  390. ret = nfs4_wait_clnt_recover(clp);
  391. if (ret != 0)
  392. return ret;
  393. if (!test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state))
  394. break;
  395. nfs4_schedule_state_manager(clp);
  396. }
  397. return 0;
  398. }
  399. static int nfs41_setup_sequence(struct nfs4_session *session,
  400. struct nfs4_sequence_args *args,
  401. struct nfs4_sequence_res *res,
  402. int cache_reply,
  403. struct rpc_task *task)
  404. {
  405. struct nfs4_slot *slot;
  406. struct nfs4_slot_table *tbl;
  407. int status = 0;
  408. u8 slotid;
  409. dprintk("--> %s\n", __func__);
  410. /* slot already allocated? */
  411. if (res->sr_slotid != NFS4_MAX_SLOT_TABLE)
  412. return 0;
  413. memset(res, 0, sizeof(*res));
  414. res->sr_slotid = NFS4_MAX_SLOT_TABLE;
  415. tbl = &session->fc_slot_table;
  416. spin_lock(&tbl->slot_tbl_lock);
  417. if (test_bit(NFS4CLNT_SESSION_SETUP, &session->clp->cl_state)) {
  418. if (tbl->highest_used_slotid != -1) {
  419. rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
  420. spin_unlock(&tbl->slot_tbl_lock);
  421. dprintk("<-- %s: Session reset: draining\n", __func__);
  422. return -EAGAIN;
  423. }
  424. /* The slot table is empty; start the reset thread */
  425. dprintk("%s Session Reset\n", __func__);
  426. spin_unlock(&tbl->slot_tbl_lock);
  427. status = nfs4_recover_session(session);
  428. if (status)
  429. return status;
  430. spin_lock(&tbl->slot_tbl_lock);
  431. }
  432. slotid = nfs4_find_slot(tbl, task);
  433. if (slotid == NFS4_MAX_SLOT_TABLE) {
  434. rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
  435. spin_unlock(&tbl->slot_tbl_lock);
  436. dprintk("<-- %s: no free slots\n", __func__);
  437. return -EAGAIN;
  438. }
  439. spin_unlock(&tbl->slot_tbl_lock);
  440. slot = tbl->slots + slotid;
  441. args->sa_session = session;
  442. args->sa_slotid = slotid;
  443. args->sa_cache_this = cache_reply;
  444. dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
  445. res->sr_session = session;
  446. res->sr_slotid = slotid;
  447. res->sr_renewal_time = jiffies;
  448. /*
  449. * sr_status is only set in decode_sequence, and so will remain
  450. * set to 1 if an rpc level failure occurs.
  451. */
  452. res->sr_status = 1;
  453. return 0;
  454. }
  455. int nfs4_setup_sequence(struct nfs_client *clp,
  456. struct nfs4_sequence_args *args,
  457. struct nfs4_sequence_res *res,
  458. int cache_reply,
  459. struct rpc_task *task)
  460. {
  461. int ret = 0;
  462. dprintk("--> %s clp %p session %p sr_slotid %d\n",
  463. __func__, clp, clp->cl_session, res->sr_slotid);
  464. if (!nfs4_has_session(clp))
  465. goto out;
  466. ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply,
  467. task);
  468. if (ret != -EAGAIN) {
  469. /* terminate rpc task */
  470. task->tk_status = ret;
  471. task->tk_action = NULL;
  472. }
  473. out:
  474. dprintk("<-- %s status=%d\n", __func__, ret);
  475. return ret;
  476. }
  477. struct nfs41_call_sync_data {
  478. struct nfs_client *clp;
  479. struct nfs4_sequence_args *seq_args;
  480. struct nfs4_sequence_res *seq_res;
  481. int cache_reply;
  482. };
  483. static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
  484. {
  485. struct nfs41_call_sync_data *data = calldata;
  486. dprintk("--> %s data->clp->cl_session %p\n", __func__,
  487. data->clp->cl_session);
  488. if (nfs4_setup_sequence(data->clp, data->seq_args,
  489. data->seq_res, data->cache_reply, task))
  490. return;
  491. rpc_call_start(task);
  492. }
  493. static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
  494. {
  495. struct nfs41_call_sync_data *data = calldata;
  496. nfs41_sequence_done(data->clp, data->seq_res, task->tk_status);
  497. nfs41_sequence_free_slot(data->clp, data->seq_res);
  498. }
  499. struct rpc_call_ops nfs41_call_sync_ops = {
  500. .rpc_call_prepare = nfs41_call_sync_prepare,
  501. .rpc_call_done = nfs41_call_sync_done,
  502. };
  503. static int nfs4_call_sync_sequence(struct nfs_client *clp,
  504. struct rpc_clnt *clnt,
  505. struct rpc_message *msg,
  506. struct nfs4_sequence_args *args,
  507. struct nfs4_sequence_res *res,
  508. int cache_reply)
  509. {
  510. int ret;
  511. struct rpc_task *task;
  512. struct nfs41_call_sync_data data = {
  513. .clp = clp,
  514. .seq_args = args,
  515. .seq_res = res,
  516. .cache_reply = cache_reply,
  517. };
  518. struct rpc_task_setup task_setup = {
  519. .rpc_client = clnt,
  520. .rpc_message = msg,
  521. .callback_ops = &nfs41_call_sync_ops,
  522. .callback_data = &data
  523. };
  524. res->sr_slotid = NFS4_MAX_SLOT_TABLE;
  525. task = rpc_run_task(&task_setup);
  526. if (IS_ERR(task))
  527. ret = PTR_ERR(task);
  528. else {
  529. ret = task->tk_status;
  530. rpc_put_task(task);
  531. }
  532. return ret;
  533. }
  534. int _nfs4_call_sync_session(struct nfs_server *server,
  535. struct rpc_message *msg,
  536. struct nfs4_sequence_args *args,
  537. struct nfs4_sequence_res *res,
  538. int cache_reply)
  539. {
  540. return nfs4_call_sync_sequence(server->nfs_client, server->client,
  541. msg, args, res, cache_reply);
  542. }
  543. #endif /* CONFIG_NFS_V4_1 */
  544. int _nfs4_call_sync(struct nfs_server *server,
  545. struct rpc_message *msg,
  546. struct nfs4_sequence_args *args,
  547. struct nfs4_sequence_res *res,
  548. int cache_reply)
  549. {
  550. args->sa_session = res->sr_session = NULL;
  551. return rpc_call_sync(server->client, msg, 0);
  552. }
  553. #define nfs4_call_sync(server, msg, args, res, cache_reply) \
  554. (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
  555. &(res)->seq_res, (cache_reply))
  556. static void nfs4_sequence_done(const struct nfs_server *server,
  557. struct nfs4_sequence_res *res, int rpc_status)
  558. {
  559. #ifdef CONFIG_NFS_V4_1
  560. if (nfs4_has_session(server->nfs_client))
  561. nfs41_sequence_done(server->nfs_client, res, rpc_status);
  562. #endif /* CONFIG_NFS_V4_1 */
  563. }
  564. /* no restart, therefore free slot here */
  565. static void nfs4_sequence_done_free_slot(const struct nfs_server *server,
  566. struct nfs4_sequence_res *res,
  567. int rpc_status)
  568. {
  569. nfs4_sequence_done(server, res, rpc_status);
  570. nfs4_sequence_free_slot(server->nfs_client, res);
  571. }
  572. static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
  573. {
  574. struct nfs_inode *nfsi = NFS_I(dir);
  575. spin_lock(&dir->i_lock);
  576. nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
  577. if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
  578. nfs_force_lookup_revalidate(dir);
  579. nfsi->change_attr = cinfo->after;
  580. spin_unlock(&dir->i_lock);
  581. }
  582. struct nfs4_opendata {
  583. struct kref kref;
  584. struct nfs_openargs o_arg;
  585. struct nfs_openres o_res;
  586. struct nfs_open_confirmargs c_arg;
  587. struct nfs_open_confirmres c_res;
  588. struct nfs_fattr f_attr;
  589. struct nfs_fattr dir_attr;
  590. struct path path;
  591. struct dentry *dir;
  592. struct nfs4_state_owner *owner;
  593. struct nfs4_state *state;
  594. struct iattr attrs;
  595. unsigned long timestamp;
  596. unsigned int rpc_done : 1;
  597. int rpc_status;
  598. int cancelled;
  599. };
  600. static void nfs4_init_opendata_res(struct nfs4_opendata *p)
  601. {
  602. p->o_res.f_attr = &p->f_attr;
  603. p->o_res.dir_attr = &p->dir_attr;
  604. p->o_res.seqid = p->o_arg.seqid;
  605. p->c_res.seqid = p->c_arg.seqid;
  606. p->o_res.server = p->o_arg.server;
  607. nfs_fattr_init(&p->f_attr);
  608. nfs_fattr_init(&p->dir_attr);
  609. p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  610. }
  611. static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
  612. struct nfs4_state_owner *sp, fmode_t fmode, int flags,
  613. const struct iattr *attrs)
  614. {
  615. struct dentry *parent = dget_parent(path->dentry);
  616. struct inode *dir = parent->d_inode;
  617. struct nfs_server *server = NFS_SERVER(dir);
  618. struct nfs4_opendata *p;
  619. p = kzalloc(sizeof(*p), GFP_KERNEL);
  620. if (p == NULL)
  621. goto err;
  622. p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
  623. if (p->o_arg.seqid == NULL)
  624. goto err_free;
  625. p->path.mnt = mntget(path->mnt);
  626. p->path.dentry = dget(path->dentry);
  627. p->dir = parent;
  628. p->owner = sp;
  629. atomic_inc(&sp->so_count);
  630. p->o_arg.fh = NFS_FH(dir);
  631. p->o_arg.open_flags = flags;
  632. p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
  633. p->o_arg.clientid = server->nfs_client->cl_clientid;
  634. p->o_arg.id = sp->so_owner_id.id;
  635. p->o_arg.name = &p->path.dentry->d_name;
  636. p->o_arg.server = server;
  637. p->o_arg.bitmask = server->attr_bitmask;
  638. p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
  639. if (flags & O_EXCL) {
  640. u32 *s = (u32 *) p->o_arg.u.verifier.data;
  641. s[0] = jiffies;
  642. s[1] = current->pid;
  643. } else if (flags & O_CREAT) {
  644. p->o_arg.u.attrs = &p->attrs;
  645. memcpy(&p->attrs, attrs, sizeof(p->attrs));
  646. }
  647. p->c_arg.fh = &p->o_res.fh;
  648. p->c_arg.stateid = &p->o_res.stateid;
  649. p->c_arg.seqid = p->o_arg.seqid;
  650. nfs4_init_opendata_res(p);
  651. kref_init(&p->kref);
  652. return p;
  653. err_free:
  654. kfree(p);
  655. err:
  656. dput(parent);
  657. return NULL;
  658. }
  659. static void nfs4_opendata_free(struct kref *kref)
  660. {
  661. struct nfs4_opendata *p = container_of(kref,
  662. struct nfs4_opendata, kref);
  663. nfs_free_seqid(p->o_arg.seqid);
  664. if (p->state != NULL)
  665. nfs4_put_open_state(p->state);
  666. nfs4_put_state_owner(p->owner);
  667. dput(p->dir);
  668. path_put(&p->path);
  669. kfree(p);
  670. }
  671. static void nfs4_opendata_put(struct nfs4_opendata *p)
  672. {
  673. if (p != NULL)
  674. kref_put(&p->kref, nfs4_opendata_free);
  675. }
  676. static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
  677. {
  678. int ret;
  679. ret = rpc_wait_for_completion_task(task);
  680. return ret;
  681. }
  682. static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
  683. {
  684. int ret = 0;
  685. if (open_mode & O_EXCL)
  686. goto out;
  687. switch (mode & (FMODE_READ|FMODE_WRITE)) {
  688. case FMODE_READ:
  689. ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0;
  690. break;
  691. case FMODE_WRITE:
  692. ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0;
  693. break;
  694. case FMODE_READ|FMODE_WRITE:
  695. ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0;
  696. }
  697. out:
  698. return ret;
  699. }
  700. static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
  701. {
  702. if ((delegation->type & fmode) != fmode)
  703. return 0;
  704. if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
  705. return 0;
  706. nfs_mark_delegation_referenced(delegation);
  707. return 1;
  708. }
  709. static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
  710. {
  711. switch (fmode) {
  712. case FMODE_WRITE:
  713. state->n_wronly++;
  714. break;
  715. case FMODE_READ:
  716. state->n_rdonly++;
  717. break;
  718. case FMODE_READ|FMODE_WRITE:
  719. state->n_rdwr++;
  720. }
  721. nfs4_state_set_mode_locked(state, state->state | fmode);
  722. }
  723. static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
  724. {
  725. if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
  726. memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
  727. memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
  728. switch (fmode) {
  729. case FMODE_READ:
  730. set_bit(NFS_O_RDONLY_STATE, &state->flags);
  731. break;
  732. case FMODE_WRITE:
  733. set_bit(NFS_O_WRONLY_STATE, &state->flags);
  734. break;
  735. case FMODE_READ|FMODE_WRITE:
  736. set_bit(NFS_O_RDWR_STATE, &state->flags);
  737. }
  738. }
  739. static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
  740. {
  741. write_seqlock(&state->seqlock);
  742. nfs_set_open_stateid_locked(state, stateid, fmode);
  743. write_sequnlock(&state->seqlock);
  744. }
  745. static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
  746. {
  747. /*
  748. * Protect the call to nfs4_state_set_mode_locked and
  749. * serialise the stateid update
  750. */
  751. write_seqlock(&state->seqlock);
  752. if (deleg_stateid != NULL) {
  753. memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
  754. set_bit(NFS_DELEGATED_STATE, &state->flags);
  755. }
  756. if (open_stateid != NULL)
  757. nfs_set_open_stateid_locked(state, open_stateid, fmode);
  758. write_sequnlock(&state->seqlock);
  759. spin_lock(&state->owner->so_lock);
  760. update_open_stateflags(state, fmode);
  761. spin_unlock(&state->owner->so_lock);
  762. }
  763. static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
  764. {
  765. struct nfs_inode *nfsi = NFS_I(state->inode);
  766. struct nfs_delegation *deleg_cur;
  767. int ret = 0;
  768. fmode &= (FMODE_READ|FMODE_WRITE);
  769. rcu_read_lock();
  770. deleg_cur = rcu_dereference(nfsi->delegation);
  771. if (deleg_cur == NULL)
  772. goto no_delegation;
  773. spin_lock(&deleg_cur->lock);
  774. if (nfsi->delegation != deleg_cur ||
  775. (deleg_cur->type & fmode) != fmode)
  776. goto no_delegation_unlock;
  777. if (delegation == NULL)
  778. delegation = &deleg_cur->stateid;
  779. else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
  780. goto no_delegation_unlock;
  781. nfs_mark_delegation_referenced(deleg_cur);
  782. __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
  783. ret = 1;
  784. no_delegation_unlock:
  785. spin_unlock(&deleg_cur->lock);
  786. no_delegation:
  787. rcu_read_unlock();
  788. if (!ret && open_stateid != NULL) {
  789. __update_open_stateid(state, open_stateid, NULL, fmode);
  790. ret = 1;
  791. }
  792. return ret;
  793. }
  794. static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
  795. {
  796. struct nfs_delegation *delegation;
  797. rcu_read_lock();
  798. delegation = rcu_dereference(NFS_I(inode)->delegation);
  799. if (delegation == NULL || (delegation->type & fmode) == fmode) {
  800. rcu_read_unlock();
  801. return;
  802. }
  803. rcu_read_unlock();
  804. nfs_inode_return_delegation(inode);
  805. }
  806. static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
  807. {
  808. struct nfs4_state *state = opendata->state;
  809. struct nfs_inode *nfsi = NFS_I(state->inode);
  810. struct nfs_delegation *delegation;
  811. int open_mode = opendata->o_arg.open_flags & O_EXCL;
  812. fmode_t fmode = opendata->o_arg.fmode;
  813. nfs4_stateid stateid;
  814. int ret = -EAGAIN;
  815. for (;;) {
  816. if (can_open_cached(state, fmode, open_mode)) {
  817. spin_lock(&state->owner->so_lock);
  818. if (can_open_cached(state, fmode, open_mode)) {
  819. update_open_stateflags(state, fmode);
  820. spin_unlock(&state->owner->so_lock);
  821. goto out_return_state;
  822. }
  823. spin_unlock(&state->owner->so_lock);
  824. }
  825. rcu_read_lock();
  826. delegation = rcu_dereference(nfsi->delegation);
  827. if (delegation == NULL ||
  828. !can_open_delegated(delegation, fmode)) {
  829. rcu_read_unlock();
  830. break;
  831. }
  832. /* Save the delegation */
  833. memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
  834. rcu_read_unlock();
  835. ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
  836. if (ret != 0)
  837. goto out;
  838. ret = -EAGAIN;
  839. /* Try to update the stateid using the delegation */
  840. if (update_open_stateid(state, NULL, &stateid, fmode))
  841. goto out_return_state;
  842. }
  843. out:
  844. return ERR_PTR(ret);
  845. out_return_state:
  846. atomic_inc(&state->count);
  847. return state;
  848. }
  849. static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
  850. {
  851. struct inode *inode;
  852. struct nfs4_state *state = NULL;
  853. struct nfs_delegation *delegation;
  854. int ret;
  855. if (!data->rpc_done) {
  856. state = nfs4_try_open_cached(data);
  857. goto out;
  858. }
  859. ret = -EAGAIN;
  860. if (!(data->f_attr.valid & NFS_ATTR_FATTR))
  861. goto err;
  862. inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
  863. ret = PTR_ERR(inode);
  864. if (IS_ERR(inode))
  865. goto err;
  866. ret = -ENOMEM;
  867. state = nfs4_get_open_state(inode, data->owner);
  868. if (state == NULL)
  869. goto err_put_inode;
  870. if (data->o_res.delegation_type != 0) {
  871. int delegation_flags = 0;
  872. rcu_read_lock();
  873. delegation = rcu_dereference(NFS_I(inode)->delegation);
  874. if (delegation)
  875. delegation_flags = delegation->flags;
  876. rcu_read_unlock();
  877. if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
  878. nfs_inode_set_delegation(state->inode,
  879. data->owner->so_cred,
  880. &data->o_res);
  881. else
  882. nfs_inode_reclaim_delegation(state->inode,
  883. data->owner->so_cred,
  884. &data->o_res);
  885. }
  886. update_open_stateid(state, &data->o_res.stateid, NULL,
  887. data->o_arg.fmode);
  888. iput(inode);
  889. out:
  890. return state;
  891. err_put_inode:
  892. iput(inode);
  893. err:
  894. return ERR_PTR(ret);
  895. }
  896. static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
  897. {
  898. struct nfs_inode *nfsi = NFS_I(state->inode);
  899. struct nfs_open_context *ctx;
  900. spin_lock(&state->inode->i_lock);
  901. list_for_each_entry(ctx, &nfsi->open_files, list) {
  902. if (ctx->state != state)
  903. continue;
  904. get_nfs_open_context(ctx);
  905. spin_unlock(&state->inode->i_lock);
  906. return ctx;
  907. }
  908. spin_unlock(&state->inode->i_lock);
  909. return ERR_PTR(-ENOENT);
  910. }
  911. static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
  912. {
  913. struct nfs4_opendata *opendata;
  914. opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL);
  915. if (opendata == NULL)
  916. return ERR_PTR(-ENOMEM);
  917. opendata->state = state;
  918. atomic_inc(&state->count);
  919. return opendata;
  920. }
  921. static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
  922. {
  923. struct nfs4_state *newstate;
  924. int ret;
  925. opendata->o_arg.open_flags = 0;
  926. opendata->o_arg.fmode = fmode;
  927. memset(&opendata->o_res, 0, sizeof(opendata->o_res));
  928. memset(&opendata->c_res, 0, sizeof(opendata->c_res));
  929. nfs4_init_opendata_res(opendata);
  930. ret = _nfs4_proc_open(opendata);
  931. if (ret != 0)
  932. return ret;
  933. newstate = nfs4_opendata_to_nfs4_state(opendata);
  934. if (IS_ERR(newstate))
  935. return PTR_ERR(newstate);
  936. nfs4_close_state(&opendata->path, newstate, fmode);
  937. *res = newstate;
  938. return 0;
  939. }
  940. static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
  941. {
  942. struct nfs4_state *newstate;
  943. int ret;
  944. /* memory barrier prior to reading state->n_* */
  945. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  946. smp_rmb();
  947. if (state->n_rdwr != 0) {
  948. ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
  949. if (ret != 0)
  950. return ret;
  951. if (newstate != state)
  952. return -ESTALE;
  953. }
  954. if (state->n_wronly != 0) {
  955. ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
  956. if (ret != 0)
  957. return ret;
  958. if (newstate != state)
  959. return -ESTALE;
  960. }
  961. if (state->n_rdonly != 0) {
  962. ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
  963. if (ret != 0)
  964. return ret;
  965. if (newstate != state)
  966. return -ESTALE;
  967. }
  968. /*
  969. * We may have performed cached opens for all three recoveries.
  970. * Check if we need to update the current stateid.
  971. */
  972. if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
  973. memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
  974. write_seqlock(&state->seqlock);
  975. if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
  976. memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
  977. write_sequnlock(&state->seqlock);
  978. }
  979. return 0;
  980. }
  981. /*
  982. * OPEN_RECLAIM:
  983. * reclaim state on the server after a reboot.
  984. */
  985. static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
  986. {
  987. struct nfs_delegation *delegation;
  988. struct nfs4_opendata *opendata;
  989. fmode_t delegation_type = 0;
  990. int status;
  991. opendata = nfs4_open_recoverdata_alloc(ctx, state);
  992. if (IS_ERR(opendata))
  993. return PTR_ERR(opendata);
  994. opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
  995. opendata->o_arg.fh = NFS_FH(state->inode);
  996. rcu_read_lock();
  997. delegation = rcu_dereference(NFS_I(state->inode)->delegation);
  998. if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
  999. delegation_type = delegation->type;
  1000. rcu_read_unlock();
  1001. opendata->o_arg.u.delegation_type = delegation_type;
  1002. status = nfs4_open_recover(opendata, state);
  1003. nfs4_opendata_put(opendata);
  1004. return status;
  1005. }
  1006. static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
  1007. {
  1008. struct nfs_server *server = NFS_SERVER(state->inode);
  1009. struct nfs4_exception exception = { };
  1010. int err;
  1011. do {
  1012. err = _nfs4_do_open_reclaim(ctx, state);
  1013. if (err != -NFS4ERR_DELAY)
  1014. break;
  1015. nfs4_handle_exception(server, err, &exception);
  1016. } while (exception.retry);
  1017. return err;
  1018. }
  1019. static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
  1020. {
  1021. struct nfs_open_context *ctx;
  1022. int ret;
  1023. ctx = nfs4_state_find_open_context(state);
  1024. if (IS_ERR(ctx))
  1025. return PTR_ERR(ctx);
  1026. ret = nfs4_do_open_reclaim(ctx, state);
  1027. put_nfs_open_context(ctx);
  1028. return ret;
  1029. }
  1030. static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
  1031. {
  1032. struct nfs4_opendata *opendata;
  1033. int ret;
  1034. opendata = nfs4_open_recoverdata_alloc(ctx, state);
  1035. if (IS_ERR(opendata))
  1036. return PTR_ERR(opendata);
  1037. opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
  1038. memcpy(opendata->o_arg.u.delegation.data, stateid->data,
  1039. sizeof(opendata->o_arg.u.delegation.data));
  1040. ret = nfs4_open_recover(opendata, state);
  1041. nfs4_opendata_put(opendata);
  1042. return ret;
  1043. }
  1044. int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
  1045. {
  1046. struct nfs4_exception exception = { };
  1047. struct nfs_server *server = NFS_SERVER(state->inode);
  1048. int err;
  1049. do {
  1050. err = _nfs4_open_delegation_recall(ctx, state, stateid);
  1051. switch (err) {
  1052. case 0:
  1053. case -ENOENT:
  1054. case -ESTALE:
  1055. goto out;
  1056. case -NFS4ERR_STALE_CLIENTID:
  1057. case -NFS4ERR_STALE_STATEID:
  1058. case -NFS4ERR_EXPIRED:
  1059. /* Don't recall a delegation if it was lost */
  1060. nfs4_schedule_state_recovery(server->nfs_client);
  1061. goto out;
  1062. case -ERESTARTSYS:
  1063. /*
  1064. * The show must go on: exit, but mark the
  1065. * stateid as needing recovery.
  1066. */
  1067. case -NFS4ERR_ADMIN_REVOKED:
  1068. case -NFS4ERR_BAD_STATEID:
  1069. nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
  1070. case -ENOMEM:
  1071. err = 0;
  1072. goto out;
  1073. }
  1074. err = nfs4_handle_exception(server, err, &exception);
  1075. } while (exception.retry);
  1076. out:
  1077. return err;
  1078. }
  1079. static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
  1080. {
  1081. struct nfs4_opendata *data = calldata;
  1082. data->rpc_status = task->tk_status;
  1083. if (RPC_ASSASSINATED(task))
  1084. return;
  1085. if (data->rpc_status == 0) {
  1086. memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
  1087. sizeof(data->o_res.stateid.data));
  1088. nfs_confirm_seqid(&data->owner->so_seqid, 0);
  1089. renew_lease(data->o_res.server, data->timestamp);
  1090. data->rpc_done = 1;
  1091. }
  1092. }
  1093. static void nfs4_open_confirm_release(void *calldata)
  1094. {
  1095. struct nfs4_opendata *data = calldata;
  1096. struct nfs4_state *state = NULL;
  1097. /* If this request hasn't been cancelled, do nothing */
  1098. if (data->cancelled == 0)
  1099. goto out_free;
  1100. /* In case of error, no cleanup! */
  1101. if (!data->rpc_done)
  1102. goto out_free;
  1103. state = nfs4_opendata_to_nfs4_state(data);
  1104. if (!IS_ERR(state))
  1105. nfs4_close_state(&data->path, state, data->o_arg.fmode);
  1106. out_free:
  1107. nfs4_opendata_put(data);
  1108. }
  1109. static const struct rpc_call_ops nfs4_open_confirm_ops = {
  1110. .rpc_call_done = nfs4_open_confirm_done,
  1111. .rpc_release = nfs4_open_confirm_release,
  1112. };
  1113. /*
  1114. * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
  1115. */
  1116. static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
  1117. {
  1118. struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
  1119. struct rpc_task *task;
  1120. struct rpc_message msg = {
  1121. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
  1122. .rpc_argp = &data->c_arg,
  1123. .rpc_resp = &data->c_res,
  1124. .rpc_cred = data->owner->so_cred,
  1125. };
  1126. struct rpc_task_setup task_setup_data = {
  1127. .rpc_client = server->client,
  1128. .rpc_message = &msg,
  1129. .callback_ops = &nfs4_open_confirm_ops,
  1130. .callback_data = data,
  1131. .workqueue = nfsiod_workqueue,
  1132. .flags = RPC_TASK_ASYNC,
  1133. };
  1134. int status;
  1135. kref_get(&data->kref);
  1136. data->rpc_done = 0;
  1137. data->rpc_status = 0;
  1138. data->timestamp = jiffies;
  1139. task = rpc_run_task(&task_setup_data);
  1140. if (IS_ERR(task))
  1141. return PTR_ERR(task);
  1142. status = nfs4_wait_for_completion_rpc_task(task);
  1143. if (status != 0) {
  1144. data->cancelled = 1;
  1145. smp_wmb();
  1146. } else
  1147. status = data->rpc_status;
  1148. rpc_put_task(task);
  1149. return status;
  1150. }
  1151. static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
  1152. {
  1153. struct nfs4_opendata *data = calldata;
  1154. struct nfs4_state_owner *sp = data->owner;
  1155. if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
  1156. return;
  1157. /*
  1158. * Check if we still need to send an OPEN call, or if we can use
  1159. * a delegation instead.
  1160. */
  1161. if (data->state != NULL) {
  1162. struct nfs_delegation *delegation;
  1163. if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
  1164. goto out_no_action;
  1165. rcu_read_lock();
  1166. delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
  1167. if (delegation != NULL &&
  1168. test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
  1169. rcu_read_unlock();
  1170. goto out_no_action;
  1171. }
  1172. rcu_read_unlock();
  1173. }
  1174. /* Update sequence id. */
  1175. data->o_arg.id = sp->so_owner_id.id;
  1176. data->o_arg.clientid = sp->so_client->cl_clientid;
  1177. if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
  1178. task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
  1179. nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
  1180. }
  1181. data->timestamp = jiffies;
  1182. if (nfs4_setup_sequence(data->o_arg.server->nfs_client,
  1183. &data->o_arg.seq_args,
  1184. &data->o_res.seq_res, 1, task))
  1185. return;
  1186. rpc_call_start(task);
  1187. return;
  1188. out_no_action:
  1189. task->tk_action = NULL;
  1190. }
  1191. static void nfs4_open_done(struct rpc_task *task, void *calldata)
  1192. {
  1193. struct nfs4_opendata *data = calldata;
  1194. data->rpc_status = task->tk_status;
  1195. nfs4_sequence_done_free_slot(data->o_arg.server, &data->o_res.seq_res,
  1196. task->tk_status);
  1197. if (RPC_ASSASSINATED(task))
  1198. return;
  1199. if (task->tk_status == 0) {
  1200. switch (data->o_res.f_attr->mode & S_IFMT) {
  1201. case S_IFREG:
  1202. break;
  1203. case S_IFLNK:
  1204. data->rpc_status = -ELOOP;
  1205. break;
  1206. case S_IFDIR:
  1207. data->rpc_status = -EISDIR;
  1208. break;
  1209. default:
  1210. data->rpc_status = -ENOTDIR;
  1211. }
  1212. renew_lease(data->o_res.server, data->timestamp);
  1213. if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
  1214. nfs_confirm_seqid(&data->owner->so_seqid, 0);
  1215. }
  1216. data->rpc_done = 1;
  1217. }
  1218. static void nfs4_open_release(void *calldata)
  1219. {
  1220. struct nfs4_opendata *data = calldata;
  1221. struct nfs4_state *state = NULL;
  1222. /* If this request hasn't been cancelled, do nothing */
  1223. if (data->cancelled == 0)
  1224. goto out_free;
  1225. /* In case of error, no cleanup! */
  1226. if (data->rpc_status != 0 || !data->rpc_done)
  1227. goto out_free;
  1228. /* In case we need an open_confirm, no cleanup! */
  1229. if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
  1230. goto out_free;
  1231. state = nfs4_opendata_to_nfs4_state(data);
  1232. if (!IS_ERR(state))
  1233. nfs4_close_state(&data->path, state, data->o_arg.fmode);
  1234. out_free:
  1235. nfs4_opendata_put(data);
  1236. }
  1237. static const struct rpc_call_ops nfs4_open_ops = {
  1238. .rpc_call_prepare = nfs4_open_prepare,
  1239. .rpc_call_done = nfs4_open_done,
  1240. .rpc_release = nfs4_open_release,
  1241. };
  1242. /*
  1243. * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
  1244. */
  1245. static int _nfs4_proc_open(struct nfs4_opendata *data)
  1246. {
  1247. struct inode *dir = data->dir->d_inode;
  1248. struct nfs_server *server = NFS_SERVER(dir);
  1249. struct nfs_openargs *o_arg = &data->o_arg;
  1250. struct nfs_openres *o_res = &data->o_res;
  1251. struct rpc_task *task;
  1252. struct rpc_message msg = {
  1253. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
  1254. .rpc_argp = o_arg,
  1255. .rpc_resp = o_res,
  1256. .rpc_cred = data->owner->so_cred,
  1257. };
  1258. struct rpc_task_setup task_setup_data = {
  1259. .rpc_client = server->client,
  1260. .rpc_message = &msg,
  1261. .callback_ops = &nfs4_open_ops,
  1262. .callback_data = data,
  1263. .workqueue = nfsiod_workqueue,
  1264. .flags = RPC_TASK_ASYNC,
  1265. };
  1266. int status;
  1267. kref_get(&data->kref);
  1268. data->rpc_done = 0;
  1269. data->rpc_status = 0;
  1270. data->cancelled = 0;
  1271. task = rpc_run_task(&task_setup_data);
  1272. if (IS_ERR(task))
  1273. return PTR_ERR(task);
  1274. status = nfs4_wait_for_completion_rpc_task(task);
  1275. if (status != 0) {
  1276. data->cancelled = 1;
  1277. smp_wmb();
  1278. } else
  1279. status = data->rpc_status;
  1280. rpc_put_task(task);
  1281. if (status != 0 || !data->rpc_done)
  1282. return status;
  1283. if (o_res->fh.size == 0)
  1284. _nfs4_proc_lookup(dir, o_arg->name, &o_res->fh, o_res->f_attr);
  1285. if (o_arg->open_flags & O_CREAT) {
  1286. update_changeattr(dir, &o_res->cinfo);
  1287. nfs_post_op_update_inode(dir, o_res->dir_attr);
  1288. } else
  1289. nfs_refresh_inode(dir, o_res->dir_attr);
  1290. if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
  1291. status = _nfs4_proc_open_confirm(data);
  1292. if (status != 0)
  1293. return status;
  1294. }
  1295. if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
  1296. _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
  1297. return 0;
  1298. }
  1299. static int nfs4_recover_expired_lease(struct nfs_server *server)
  1300. {
  1301. struct nfs_client *clp = server->nfs_client;
  1302. int ret;
  1303. for (;;) {
  1304. ret = nfs4_wait_clnt_recover(clp);
  1305. if (ret != 0)
  1306. return ret;
  1307. if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
  1308. !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
  1309. break;
  1310. nfs4_schedule_state_recovery(clp);
  1311. }
  1312. return 0;
  1313. }
  1314. /*
  1315. * OPEN_EXPIRED:
  1316. * reclaim state on the server after a network partition.
  1317. * Assumes caller holds the appropriate lock
  1318. */
  1319. static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
  1320. {
  1321. struct nfs4_opendata *opendata;
  1322. int ret;
  1323. opendata = nfs4_open_recoverdata_alloc(ctx, state);
  1324. if (IS_ERR(opendata))
  1325. return PTR_ERR(opendata);
  1326. ret = nfs4_open_recover(opendata, state);
  1327. if (ret == -ESTALE)
  1328. d_drop(ctx->path.dentry);
  1329. nfs4_opendata_put(opendata);
  1330. return ret;
  1331. }
  1332. static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
  1333. {
  1334. struct nfs_server *server = NFS_SERVER(state->inode);
  1335. struct nfs4_exception exception = { };
  1336. int err;
  1337. do {
  1338. err = _nfs4_open_expired(ctx, state);
  1339. if (err != -NFS4ERR_DELAY)
  1340. break;
  1341. nfs4_handle_exception(server, err, &exception);
  1342. } while (exception.retry);
  1343. return err;
  1344. }
  1345. static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
  1346. {
  1347. struct nfs_open_context *ctx;
  1348. int ret;
  1349. ctx = nfs4_state_find_open_context(state);
  1350. if (IS_ERR(ctx))
  1351. return PTR_ERR(ctx);
  1352. ret = nfs4_do_open_expired(ctx, state);
  1353. put_nfs_open_context(ctx);
  1354. return ret;
  1355. }
  1356. /*
  1357. * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
  1358. * fields corresponding to attributes that were used to store the verifier.
  1359. * Make sure we clobber those fields in the later setattr call
  1360. */
  1361. static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
  1362. {
  1363. if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
  1364. !(sattr->ia_valid & ATTR_ATIME_SET))
  1365. sattr->ia_valid |= ATTR_ATIME;
  1366. if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
  1367. !(sattr->ia_valid & ATTR_MTIME_SET))
  1368. sattr->ia_valid |= ATTR_MTIME;
  1369. }
  1370. /*
  1371. * Returns a referenced nfs4_state
  1372. */
  1373. static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
  1374. {
  1375. struct nfs4_state_owner *sp;
  1376. struct nfs4_state *state = NULL;
  1377. struct nfs_server *server = NFS_SERVER(dir);
  1378. struct nfs4_opendata *opendata;
  1379. int status;
  1380. /* Protect against reboot recovery conflicts */
  1381. status = -ENOMEM;
  1382. if (!(sp = nfs4_get_state_owner(server, cred))) {
  1383. dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
  1384. goto out_err;
  1385. }
  1386. status = nfs4_recover_expired_lease(server);
  1387. if (status != 0)
  1388. goto err_put_state_owner;
  1389. if (path->dentry->d_inode != NULL)
  1390. nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
  1391. status = -ENOMEM;
  1392. opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr);
  1393. if (opendata == NULL)
  1394. goto err_put_state_owner;
  1395. if (path->dentry->d_inode != NULL)
  1396. opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
  1397. status = _nfs4_proc_open(opendata);
  1398. if (status != 0)
  1399. goto err_opendata_put;
  1400. if (opendata->o_arg.open_flags & O_EXCL)
  1401. nfs4_exclusive_attrset(opendata, sattr);
  1402. state = nfs4_opendata_to_nfs4_state(opendata);
  1403. status = PTR_ERR(state);
  1404. if (IS_ERR(state))
  1405. goto err_opendata_put;
  1406. nfs4_opendata_put(opendata);
  1407. nfs4_put_state_owner(sp);
  1408. *res = state;
  1409. return 0;
  1410. err_opendata_put:
  1411. nfs4_opendata_put(opendata);
  1412. err_put_state_owner:
  1413. nfs4_put_state_owner(sp);
  1414. out_err:
  1415. *res = NULL;
  1416. return status;
  1417. }
  1418. static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred)
  1419. {
  1420. struct nfs4_exception exception = { };
  1421. struct nfs4_state *res;
  1422. int status;
  1423. do {
  1424. status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
  1425. if (status == 0)
  1426. break;
  1427. /* NOTE: BAD_SEQID means the server and client disagree about the
  1428. * book-keeping w.r.t. state-changing operations
  1429. * (OPEN/CLOSE/LOCK/LOCKU...)
  1430. * It is actually a sign of a bug on the client or on the server.
  1431. *
  1432. * If we receive a BAD_SEQID error in the particular case of
  1433. * doing an OPEN, we assume that nfs_increment_open_seqid() will
  1434. * have unhashed the old state_owner for us, and that we can
  1435. * therefore safely retry using a new one. We should still warn
  1436. * the user though...
  1437. */
  1438. if (status == -NFS4ERR_BAD_SEQID) {
  1439. printk(KERN_WARNING "NFS: v4 server %s "
  1440. " returned a bad sequence-id error!\n",
  1441. NFS_SERVER(dir)->nfs_client->cl_hostname);
  1442. exception.retry = 1;
  1443. continue;
  1444. }
  1445. /*
  1446. * BAD_STATEID on OPEN means that the server cancelled our
  1447. * state before it received the OPEN_CONFIRM.
  1448. * Recover by retrying the request as per the discussion
  1449. * on Page 181 of RFC3530.
  1450. */
  1451. if (status == -NFS4ERR_BAD_STATEID) {
  1452. exception.retry = 1;
  1453. continue;
  1454. }
  1455. if (status == -EAGAIN) {
  1456. /* We must have found a delegation */
  1457. exception.retry = 1;
  1458. continue;
  1459. }
  1460. res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
  1461. status, &exception));
  1462. } while (exception.retry);
  1463. return res;
  1464. }
  1465. static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
  1466. struct nfs_fattr *fattr, struct iattr *sattr,
  1467. struct nfs4_state *state)
  1468. {
  1469. struct nfs_server *server = NFS_SERVER(inode);
  1470. struct nfs_setattrargs arg = {
  1471. .fh = NFS_FH(inode),
  1472. .iap = sattr,
  1473. .server = server,
  1474. .bitmask = server->attr_bitmask,
  1475. };
  1476. struct nfs_setattrres res = {
  1477. .fattr = fattr,
  1478. .server = server,
  1479. };
  1480. struct rpc_message msg = {
  1481. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
  1482. .rpc_argp = &arg,
  1483. .rpc_resp = &res,
  1484. .rpc_cred = cred,
  1485. };
  1486. unsigned long timestamp = jiffies;
  1487. int status;
  1488. nfs_fattr_init(fattr);
  1489. if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
  1490. /* Use that stateid */
  1491. } else if (state != NULL) {
  1492. nfs4_copy_stateid(&arg.stateid, state, current->files);
  1493. } else
  1494. memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
  1495. status = nfs4_call_sync(server, &msg, &arg, &res, 1);
  1496. if (status == 0 && state != NULL)
  1497. renew_lease(server, timestamp);
  1498. return status;
  1499. }
  1500. static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
  1501. struct nfs_fattr *fattr, struct iattr *sattr,
  1502. struct nfs4_state *state)
  1503. {
  1504. struct nfs_server *server = NFS_SERVER(inode);
  1505. struct nfs4_exception exception = { };
  1506. int err;
  1507. do {
  1508. err = nfs4_handle_exception(server,
  1509. _nfs4_do_setattr(inode, cred, fattr, sattr, state),
  1510. &exception);
  1511. } while (exception.retry);
  1512. return err;
  1513. }
  1514. struct nfs4_closedata {
  1515. struct path path;
  1516. struct inode *inode;
  1517. struct nfs4_state *state;
  1518. struct nfs_closeargs arg;
  1519. struct nfs_closeres res;
  1520. struct nfs_fattr fattr;
  1521. unsigned long timestamp;
  1522. };
  1523. static void nfs4_free_closedata(void *data)
  1524. {
  1525. struct nfs4_closedata *calldata = data;
  1526. struct nfs4_state_owner *sp = calldata->state->owner;
  1527. nfs4_put_open_state(calldata->state);
  1528. nfs_free_seqid(calldata->arg.seqid);
  1529. nfs4_put_state_owner(sp);
  1530. path_put(&calldata->path);
  1531. kfree(calldata);
  1532. }
  1533. static void nfs4_close_done(struct rpc_task *task, void *data)
  1534. {
  1535. struct nfs4_closedata *calldata = data;
  1536. struct nfs4_state *state = calldata->state;
  1537. struct nfs_server *server = NFS_SERVER(calldata->inode);
  1538. nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status);
  1539. if (RPC_ASSASSINATED(task))
  1540. return;
  1541. /* hmm. we are done with the inode, and in the process of freeing
  1542. * the state_owner. we keep this around to process errors
  1543. */
  1544. switch (task->tk_status) {
  1545. case 0:
  1546. nfs_set_open_stateid(state, &calldata->res.stateid, 0);
  1547. renew_lease(server, calldata->timestamp);
  1548. break;
  1549. case -NFS4ERR_STALE_STATEID:
  1550. case -NFS4ERR_OLD_STATEID:
  1551. case -NFS4ERR_BAD_STATEID:
  1552. case -NFS4ERR_EXPIRED:
  1553. if (calldata->arg.fmode == 0)
  1554. break;
  1555. default:
  1556. if (nfs4_async_handle_error(task, server, state) == -EAGAIN) {
  1557. nfs4_restart_rpc(task, server->nfs_client);
  1558. return;
  1559. }
  1560. }
  1561. nfs4_sequence_free_slot(server->nfs_client, &calldata->res.seq_res);
  1562. nfs_refresh_inode(calldata->inode, calldata->res.fattr);
  1563. }
  1564. static void nfs4_close_prepare(struct rpc_task *task, void *data)
  1565. {
  1566. struct nfs4_closedata *calldata = data;
  1567. struct nfs4_state *state = calldata->state;
  1568. int clear_rd, clear_wr, clear_rdwr;
  1569. if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
  1570. return;
  1571. clear_rd = clear_wr = clear_rdwr = 0;
  1572. spin_lock(&state->owner->so_lock);
  1573. /* Calculate the change in open mode */
  1574. if (state->n_rdwr == 0) {
  1575. if (state->n_rdonly == 0) {
  1576. clear_rd |= test_and_clear_bit(NFS_O_RDONLY_STATE, &state->flags);
  1577. clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags);
  1578. }
  1579. if (state->n_wronly == 0) {
  1580. clear_wr |= test_and_clear_bit(NFS_O_WRONLY_STATE, &state->flags);
  1581. clear_rdwr |= test_and_clear_bit(NFS_O_RDWR_STATE, &state->flags);
  1582. }
  1583. }
  1584. spin_unlock(&state->owner->so_lock);
  1585. if (!clear_rd && !clear_wr && !clear_rdwr) {
  1586. /* Note: exit _without_ calling nfs4_close_done */
  1587. task->tk_action = NULL;
  1588. return;
  1589. }
  1590. nfs_fattr_init(calldata->res.fattr);
  1591. if (test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0) {
  1592. task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
  1593. calldata->arg.fmode = FMODE_READ;
  1594. } else if (test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0) {
  1595. task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
  1596. calldata->arg.fmode = FMODE_WRITE;
  1597. }
  1598. calldata->timestamp = jiffies;
  1599. if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client,
  1600. &calldata->arg.seq_args, &calldata->res.seq_res,
  1601. 1, task))
  1602. return;
  1603. rpc_call_start(task);
  1604. }
  1605. static const struct rpc_call_ops nfs4_close_ops = {
  1606. .rpc_call_prepare = nfs4_close_prepare,
  1607. .rpc_call_done = nfs4_close_done,
  1608. .rpc_release = nfs4_free_closedata,
  1609. };
  1610. /*
  1611. * It is possible for data to be read/written from a mem-mapped file
  1612. * after the sys_close call (which hits the vfs layer as a flush).
  1613. * This means that we can't safely call nfsv4 close on a file until
  1614. * the inode is cleared. This in turn means that we are not good
  1615. * NFSv4 citizens - we do not indicate to the server to update the file's
  1616. * share state even when we are done with one of the three share
  1617. * stateid's in the inode.
  1618. *
  1619. * NOTE: Caller must be holding the sp->so_owner semaphore!
  1620. */
  1621. int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
  1622. {
  1623. struct nfs_server *server = NFS_SERVER(state->inode);
  1624. struct nfs4_closedata *calldata;
  1625. struct nfs4_state_owner *sp = state->owner;
  1626. struct rpc_task *task;
  1627. struct rpc_message msg = {
  1628. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
  1629. .rpc_cred = state->owner->so_cred,
  1630. };
  1631. struct rpc_task_setup task_setup_data = {
  1632. .rpc_client = server->client,
  1633. .rpc_message = &msg,
  1634. .callback_ops = &nfs4_close_ops,
  1635. .workqueue = nfsiod_workqueue,
  1636. .flags = RPC_TASK_ASYNC,
  1637. };
  1638. int status = -ENOMEM;
  1639. calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
  1640. if (calldata == NULL)
  1641. goto out;
  1642. calldata->inode = state->inode;
  1643. calldata->state = state;
  1644. calldata->arg.fh = NFS_FH(state->inode);
  1645. calldata->arg.stateid = &state->open_stateid;
  1646. if (nfs4_has_session(server->nfs_client))
  1647. memset(calldata->arg.stateid->data, 0, 4); /* clear seqid */
  1648. /* Serialization for the sequence id */
  1649. calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
  1650. if (calldata->arg.seqid == NULL)
  1651. goto out_free_calldata;
  1652. calldata->arg.fmode = 0;
  1653. calldata->arg.bitmask = server->cache_consistency_bitmask;
  1654. calldata->res.fattr = &calldata->fattr;
  1655. calldata->res.seqid = calldata->arg.seqid;
  1656. calldata->res.server = server;
  1657. calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  1658. calldata->path.mnt = mntget(path->mnt);
  1659. calldata->path.dentry = dget(path->dentry);
  1660. msg.rpc_argp = &calldata->arg,
  1661. msg.rpc_resp = &calldata->res,
  1662. task_setup_data.callback_data = calldata;
  1663. task = rpc_run_task(&task_setup_data);
  1664. if (IS_ERR(task))
  1665. return PTR_ERR(task);
  1666. status = 0;
  1667. if (wait)
  1668. status = rpc_wait_for_completion_task(task);
  1669. rpc_put_task(task);
  1670. return status;
  1671. out_free_calldata:
  1672. kfree(calldata);
  1673. out:
  1674. nfs4_put_open_state(state);
  1675. nfs4_put_state_owner(sp);
  1676. return status;
  1677. }
  1678. static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode)
  1679. {
  1680. struct file *filp;
  1681. int ret;
  1682. /* If the open_intent is for execute, we have an extra check to make */
  1683. if (fmode & FMODE_EXEC) {
  1684. ret = nfs_may_open(state->inode,
  1685. state->owner->so_cred,
  1686. nd->intent.open.flags);
  1687. if (ret < 0)
  1688. goto out_close;
  1689. }
  1690. filp = lookup_instantiate_filp(nd, path->dentry, NULL);
  1691. if (!IS_ERR(filp)) {
  1692. struct nfs_open_context *ctx;
  1693. ctx = nfs_file_open_context(filp);
  1694. ctx->state = state;
  1695. return 0;
  1696. }
  1697. ret = PTR_ERR(filp);
  1698. out_close:
  1699. nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
  1700. return ret;
  1701. }
  1702. struct dentry *
  1703. nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
  1704. {
  1705. struct path path = {
  1706. .mnt = nd->path.mnt,
  1707. .dentry = dentry,
  1708. };
  1709. struct dentry *parent;
  1710. struct iattr attr;
  1711. struct rpc_cred *cred;
  1712. struct nfs4_state *state;
  1713. struct dentry *res;
  1714. fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
  1715. if (nd->flags & LOOKUP_CREATE) {
  1716. attr.ia_mode = nd->intent.open.create_mode;
  1717. attr.ia_valid = ATTR_MODE;
  1718. if (!IS_POSIXACL(dir))
  1719. attr.ia_mode &= ~current_umask();
  1720. } else {
  1721. attr.ia_valid = 0;
  1722. BUG_ON(nd->intent.open.flags & O_CREAT);
  1723. }
  1724. cred = rpc_lookup_cred();
  1725. if (IS_ERR(cred))
  1726. return (struct dentry *)cred;
  1727. parent = dentry->d_parent;
  1728. /* Protect against concurrent sillydeletes */
  1729. nfs_block_sillyrename(parent);
  1730. state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred);
  1731. put_rpccred(cred);
  1732. if (IS_ERR(state)) {
  1733. if (PTR_ERR(state) == -ENOENT) {
  1734. d_add(dentry, NULL);
  1735. nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
  1736. }
  1737. nfs_unblock_sillyrename(parent);
  1738. return (struct dentry *)state;
  1739. }
  1740. res = d_add_unique(dentry, igrab(state->inode));
  1741. if (res != NULL)
  1742. path.dentry = res;
  1743. nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
  1744. nfs_unblock_sillyrename(parent);
  1745. nfs4_intent_set_file(nd, &path, state, fmode);
  1746. return res;
  1747. }
  1748. int
  1749. nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
  1750. {
  1751. struct path path = {
  1752. .mnt = nd->path.mnt,
  1753. .dentry = dentry,
  1754. };
  1755. struct rpc_cred *cred;
  1756. struct nfs4_state *state;
  1757. fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
  1758. cred = rpc_lookup_cred();
  1759. if (IS_ERR(cred))
  1760. return PTR_ERR(cred);
  1761. state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
  1762. put_rpccred(cred);
  1763. if (IS_ERR(state)) {
  1764. switch (PTR_ERR(state)) {
  1765. case -EPERM:
  1766. case -EACCES:
  1767. case -EDQUOT:
  1768. case -ENOSPC:
  1769. case -EROFS:
  1770. lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
  1771. return 1;
  1772. default:
  1773. goto out_drop;
  1774. }
  1775. }
  1776. if (state->inode == dentry->d_inode) {
  1777. nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
  1778. nfs4_intent_set_file(nd, &path, state, fmode);
  1779. return 1;
  1780. }
  1781. nfs4_close_sync(&path, state, fmode);
  1782. out_drop:
  1783. d_drop(dentry);
  1784. return 0;
  1785. }
  1786. void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
  1787. {
  1788. if (ctx->state == NULL)
  1789. return;
  1790. if (is_sync)
  1791. nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
  1792. else
  1793. nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
  1794. }
  1795. static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
  1796. {
  1797. struct nfs4_server_caps_arg args = {
  1798. .fhandle = fhandle,
  1799. };
  1800. struct nfs4_server_caps_res res = {};
  1801. struct rpc_message msg = {
  1802. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
  1803. .rpc_argp = &args,
  1804. .rpc_resp = &res,
  1805. };
  1806. int status;
  1807. status = nfs4_call_sync(server, &msg, &args, &res, 0);
  1808. if (status == 0) {
  1809. memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
  1810. if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
  1811. server->caps |= NFS_CAP_ACLS;
  1812. if (res.has_links != 0)
  1813. server->caps |= NFS_CAP_HARDLINKS;
  1814. if (res.has_symlinks != 0)
  1815. server->caps |= NFS_CAP_SYMLINKS;
  1816. memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
  1817. server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
  1818. server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
  1819. server->acl_bitmask = res.acl_bitmask;
  1820. }
  1821. return status;
  1822. }
  1823. int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
  1824. {
  1825. struct nfs4_exception exception = { };
  1826. int err;
  1827. do {
  1828. err = nfs4_handle_exception(server,
  1829. _nfs4_server_capabilities(server, fhandle),
  1830. &exception);
  1831. } while (exception.retry);
  1832. return err;
  1833. }
  1834. static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
  1835. struct nfs_fsinfo *info)
  1836. {
  1837. struct nfs4_lookup_root_arg args = {
  1838. .bitmask = nfs4_fattr_bitmap,
  1839. };
  1840. struct nfs4_lookup_res res = {
  1841. .server = server,
  1842. .fattr = info->fattr,
  1843. .fh = fhandle,
  1844. };
  1845. struct rpc_message msg = {
  1846. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
  1847. .rpc_argp = &args,
  1848. .rpc_resp = &res,
  1849. };
  1850. int status;
  1851. nfs_fattr_init(info->fattr);
  1852. status = nfs4_recover_expired_lease(server);
  1853. if (!status)
  1854. status = nfs4_check_client_ready(server->nfs_client);
  1855. if (!status)
  1856. status = nfs4_call_sync(server, &msg, &args, &res, 0);
  1857. return status;
  1858. }
  1859. static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
  1860. struct nfs_fsinfo *info)
  1861. {
  1862. struct nfs4_exception exception = { };
  1863. int err;
  1864. do {
  1865. err = nfs4_handle_exception(server,
  1866. _nfs4_lookup_root(server, fhandle, info),
  1867. &exception);
  1868. } while (exception.retry);
  1869. return err;
  1870. }
  1871. /*
  1872. * get the file handle for the "/" directory on the server
  1873. */
  1874. static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  1875. struct nfs_fsinfo *info)
  1876. {
  1877. int status;
  1878. status = nfs4_lookup_root(server, fhandle, info);
  1879. if (status == 0)
  1880. status = nfs4_server_capabilities(server, fhandle);
  1881. if (status == 0)
  1882. status = nfs4_do_fsinfo(server, fhandle, info);
  1883. return nfs4_map_errors(status);
  1884. }
  1885. /*
  1886. * Get locations and (maybe) other attributes of a referral.
  1887. * Note that we'll actually follow the referral later when
  1888. * we detect fsid mismatch in inode revalidation
  1889. */
  1890. static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
  1891. {
  1892. int status = -ENOMEM;
  1893. struct page *page = NULL;
  1894. struct nfs4_fs_locations *locations = NULL;
  1895. page = alloc_page(GFP_KERNEL);
  1896. if (page == NULL)
  1897. goto out;
  1898. locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
  1899. if (locations == NULL)
  1900. goto out;
  1901. status = nfs4_proc_fs_locations(dir, name, locations, page);
  1902. if (status != 0)
  1903. goto out;
  1904. /* Make sure server returned a different fsid for the referral */
  1905. if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
  1906. dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
  1907. status = -EIO;
  1908. goto out;
  1909. }
  1910. memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
  1911. fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
  1912. if (!fattr->mode)
  1913. fattr->mode = S_IFDIR;
  1914. memset(fhandle, 0, sizeof(struct nfs_fh));
  1915. out:
  1916. if (page)
  1917. __free_page(page);
  1918. if (locations)
  1919. kfree(locations);
  1920. return status;
  1921. }
  1922. static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  1923. {
  1924. struct nfs4_getattr_arg args = {
  1925. .fh = fhandle,
  1926. .bitmask = server->attr_bitmask,
  1927. };
  1928. struct nfs4_getattr_res res = {
  1929. .fattr = fattr,
  1930. .server = server,
  1931. };
  1932. struct rpc_message msg = {
  1933. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
  1934. .rpc_argp = &args,
  1935. .rpc_resp = &res,
  1936. };
  1937. nfs_fattr_init(fattr);
  1938. return nfs4_call_sync(server, &msg, &args, &res, 0);
  1939. }
  1940. static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  1941. {
  1942. struct nfs4_exception exception = { };
  1943. int err;
  1944. do {
  1945. err = nfs4_handle_exception(server,
  1946. _nfs4_proc_getattr(server, fhandle, fattr),
  1947. &exception);
  1948. } while (exception.retry);
  1949. return err;
  1950. }
  1951. /*
  1952. * The file is not closed if it is opened due to the a request to change
  1953. * the size of the file. The open call will not be needed once the
  1954. * VFS layer lookup-intents are implemented.
  1955. *
  1956. * Close is called when the inode is destroyed.
  1957. * If we haven't opened the file for O_WRONLY, we
  1958. * need to in the size_change case to obtain a stateid.
  1959. *
  1960. * Got race?
  1961. * Because OPEN is always done by name in nfsv4, it is
  1962. * possible that we opened a different file by the same
  1963. * name. We can recognize this race condition, but we
  1964. * can't do anything about it besides returning an error.
  1965. *
  1966. * This will be fixed with VFS changes (lookup-intent).
  1967. */
  1968. static int
  1969. nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  1970. struct iattr *sattr)
  1971. {
  1972. struct inode *inode = dentry->d_inode;
  1973. struct rpc_cred *cred = NULL;
  1974. struct nfs4_state *state = NULL;
  1975. int status;
  1976. nfs_fattr_init(fattr);
  1977. /* Search for an existing open(O_WRITE) file */
  1978. if (sattr->ia_valid & ATTR_FILE) {
  1979. struct nfs_open_context *ctx;
  1980. ctx = nfs_file_open_context(sattr->ia_file);
  1981. if (ctx) {
  1982. cred = ctx->cred;
  1983. state = ctx->state;
  1984. }
  1985. }
  1986. status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
  1987. if (status == 0)
  1988. nfs_setattr_update_inode(inode, sattr);
  1989. return status;
  1990. }
  1991. static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh,
  1992. const struct qstr *name, struct nfs_fh *fhandle,
  1993. struct nfs_fattr *fattr)
  1994. {
  1995. int status;
  1996. struct nfs4_lookup_arg args = {
  1997. .bitmask = server->attr_bitmask,
  1998. .dir_fh = dirfh,
  1999. .name = name,
  2000. };
  2001. struct nfs4_lookup_res res = {
  2002. .server = server,
  2003. .fattr = fattr,
  2004. .fh = fhandle,
  2005. };
  2006. struct rpc_message msg = {
  2007. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
  2008. .rpc_argp = &args,
  2009. .rpc_resp = &res,
  2010. };
  2011. nfs_fattr_init(fattr);
  2012. dprintk("NFS call lookupfh %s\n", name->name);
  2013. status = nfs4_call_sync(server, &msg, &args, &res, 0);
  2014. dprintk("NFS reply lookupfh: %d\n", status);
  2015. return status;
  2016. }
  2017. static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
  2018. struct qstr *name, struct nfs_fh *fhandle,
  2019. struct nfs_fattr *fattr)
  2020. {
  2021. struct nfs4_exception exception = { };
  2022. int err;
  2023. do {
  2024. err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
  2025. /* FIXME: !!!! */
  2026. if (err == -NFS4ERR_MOVED) {
  2027. err = -EREMOTE;
  2028. break;
  2029. }
  2030. err = nfs4_handle_exception(server, err, &exception);
  2031. } while (exception.retry);
  2032. return err;
  2033. }
  2034. static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name,
  2035. struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  2036. {
  2037. int status;
  2038. dprintk("NFS call lookup %s\n", name->name);
  2039. status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
  2040. if (status == -NFS4ERR_MOVED)
  2041. status = nfs4_get_referral(dir, name, fattr, fhandle);
  2042. dprintk("NFS reply lookup: %d\n", status);
  2043. return status;
  2044. }
  2045. static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  2046. {
  2047. struct nfs4_exception exception = { };
  2048. int err;
  2049. do {
  2050. err = nfs4_handle_exception(NFS_SERVER(dir),
  2051. _nfs4_proc_lookup(dir, name, fhandle, fattr),
  2052. &exception);
  2053. } while (exception.retry);
  2054. return err;
  2055. }
  2056. static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  2057. {
  2058. struct nfs_server *server = NFS_SERVER(inode);
  2059. struct nfs_fattr fattr;
  2060. struct nfs4_accessargs args = {
  2061. .fh = NFS_FH(inode),
  2062. .bitmask = server->attr_bitmask,
  2063. };
  2064. struct nfs4_accessres res = {
  2065. .server = server,
  2066. .fattr = &fattr,
  2067. };
  2068. struct rpc_message msg = {
  2069. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
  2070. .rpc_argp = &args,
  2071. .rpc_resp = &res,
  2072. .rpc_cred = entry->cred,
  2073. };
  2074. int mode = entry->mask;
  2075. int status;
  2076. /*
  2077. * Determine which access bits we want to ask for...
  2078. */
  2079. if (mode & MAY_READ)
  2080. args.access |= NFS4_ACCESS_READ;
  2081. if (S_ISDIR(inode->i_mode)) {
  2082. if (mode & MAY_WRITE)
  2083. args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
  2084. if (mode & MAY_EXEC)
  2085. args.access |= NFS4_ACCESS_LOOKUP;
  2086. } else {
  2087. if (mode & MAY_WRITE)
  2088. args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
  2089. if (mode & MAY_EXEC)
  2090. args.access |= NFS4_ACCESS_EXECUTE;
  2091. }
  2092. nfs_fattr_init(&fattr);
  2093. status = nfs4_call_sync(server, &msg, &args, &res, 0);
  2094. if (!status) {
  2095. entry->mask = 0;
  2096. if (res.access & NFS4_ACCESS_READ)
  2097. entry->mask |= MAY_READ;
  2098. if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
  2099. entry->mask |= MAY_WRITE;
  2100. if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
  2101. entry->mask |= MAY_EXEC;
  2102. nfs_refresh_inode(inode, &fattr);
  2103. }
  2104. return status;
  2105. }
  2106. static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  2107. {
  2108. struct nfs4_exception exception = { };
  2109. int err;
  2110. do {
  2111. err = nfs4_handle_exception(NFS_SERVER(inode),
  2112. _nfs4_proc_access(inode, entry),
  2113. &exception);
  2114. } while (exception.retry);
  2115. return err;
  2116. }
  2117. /*
  2118. * TODO: For the time being, we don't try to get any attributes
  2119. * along with any of the zero-copy operations READ, READDIR,
  2120. * READLINK, WRITE.
  2121. *
  2122. * In the case of the first three, we want to put the GETATTR
  2123. * after the read-type operation -- this is because it is hard
  2124. * to predict the length of a GETATTR response in v4, and thus
  2125. * align the READ data correctly. This means that the GETATTR
  2126. * may end up partially falling into the page cache, and we should
  2127. * shift it into the 'tail' of the xdr_buf before processing.
  2128. * To do this efficiently, we need to know the total length
  2129. * of data received, which doesn't seem to be available outside
  2130. * of the RPC layer.
  2131. *
  2132. * In the case of WRITE, we also want to put the GETATTR after
  2133. * the operation -- in this case because we want to make sure
  2134. * we get the post-operation mtime and size. This means that
  2135. * we can't use xdr_encode_pages() as written: we need a variant
  2136. * of it which would leave room in the 'tail' iovec.
  2137. *
  2138. * Both of these changes to the XDR layer would in fact be quite
  2139. * minor, but I decided to leave them for a subsequent patch.
  2140. */
  2141. static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
  2142. unsigned int pgbase, unsigned int pglen)
  2143. {
  2144. struct nfs4_readlink args = {
  2145. .fh = NFS_FH(inode),
  2146. .pgbase = pgbase,
  2147. .pglen = pglen,
  2148. .pages = &page,
  2149. };
  2150. struct nfs4_readlink_res res;
  2151. struct rpc_message msg = {
  2152. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
  2153. .rpc_argp = &args,
  2154. .rpc_resp = &res,
  2155. };
  2156. return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
  2157. }
  2158. static int nfs4_proc_readlink(struct inode *inode, struct page *page,
  2159. unsigned int pgbase, unsigned int pglen)
  2160. {
  2161. struct nfs4_exception exception = { };
  2162. int err;
  2163. do {
  2164. err = nfs4_handle_exception(NFS_SERVER(inode),
  2165. _nfs4_proc_readlink(inode, page, pgbase, pglen),
  2166. &exception);
  2167. } while (exception.retry);
  2168. return err;
  2169. }
  2170. /*
  2171. * Got race?
  2172. * We will need to arrange for the VFS layer to provide an atomic open.
  2173. * Until then, this create/open method is prone to inefficiency and race
  2174. * conditions due to the lookup, create, and open VFS calls from sys_open()
  2175. * placed on the wire.
  2176. *
  2177. * Given the above sorry state of affairs, I'm simply sending an OPEN.
  2178. * The file will be opened again in the subsequent VFS open call
  2179. * (nfs4_proc_file_open).
  2180. *
  2181. * The open for read will just hang around to be used by any process that
  2182. * opens the file O_RDONLY. This will all be resolved with the VFS changes.
  2183. */
  2184. static int
  2185. nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  2186. int flags, struct nameidata *nd)
  2187. {
  2188. struct path path = {
  2189. .mnt = nd->path.mnt,
  2190. .dentry = dentry,
  2191. };
  2192. struct nfs4_state *state;
  2193. struct rpc_cred *cred;
  2194. fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE);
  2195. int status = 0;
  2196. cred = rpc_lookup_cred();
  2197. if (IS_ERR(cred)) {
  2198. status = PTR_ERR(cred);
  2199. goto out;
  2200. }
  2201. state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred);
  2202. d_drop(dentry);
  2203. if (IS_ERR(state)) {
  2204. status = PTR_ERR(state);
  2205. goto out_putcred;
  2206. }
  2207. d_add(dentry, igrab(state->inode));
  2208. nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
  2209. if (flags & O_EXCL) {
  2210. struct nfs_fattr fattr;
  2211. status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state);
  2212. if (status == 0)
  2213. nfs_setattr_update_inode(state->inode, sattr);
  2214. nfs_post_op_update_inode(state->inode, &fattr);
  2215. }
  2216. if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
  2217. status = nfs4_intent_set_file(nd, &path, state, fmode);
  2218. else
  2219. nfs4_close_sync(&path, state, fmode);
  2220. out_putcred:
  2221. put_rpccred(cred);
  2222. out:
  2223. return status;
  2224. }
  2225. static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
  2226. {
  2227. struct nfs_server *server = NFS_SERVER(dir);
  2228. struct nfs_removeargs args = {
  2229. .fh = NFS_FH(dir),
  2230. .name.len = name->len,
  2231. .name.name = name->name,
  2232. .bitmask = server->attr_bitmask,
  2233. };
  2234. struct nfs_removeres res = {
  2235. .server = server,
  2236. };
  2237. struct rpc_message msg = {
  2238. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
  2239. .rpc_argp = &args,
  2240. .rpc_resp = &res,
  2241. };
  2242. int status;
  2243. nfs_fattr_init(&res.dir_attr);
  2244. status = nfs4_call_sync(server, &msg, &args, &res, 1);
  2245. if (status == 0) {
  2246. update_changeattr(dir, &res.cinfo);
  2247. nfs_post_op_update_inode(dir, &res.dir_attr);
  2248. }
  2249. return status;
  2250. }
  2251. static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
  2252. {
  2253. struct nfs4_exception exception = { };
  2254. int err;
  2255. do {
  2256. err = nfs4_handle_exception(NFS_SERVER(dir),
  2257. _nfs4_proc_remove(dir, name),
  2258. &exception);
  2259. } while (exception.retry);
  2260. return err;
  2261. }
  2262. static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
  2263. {
  2264. struct nfs_server *server = NFS_SERVER(dir);
  2265. struct nfs_removeargs *args = msg->rpc_argp;
  2266. struct nfs_removeres *res = msg->rpc_resp;
  2267. args->bitmask = server->cache_consistency_bitmask;
  2268. res->server = server;
  2269. msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
  2270. }
  2271. static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
  2272. {
  2273. struct nfs_removeres *res = task->tk_msg.rpc_resp;
  2274. nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
  2275. if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
  2276. return 0;
  2277. nfs4_sequence_free_slot(res->server->nfs_client, &res->seq_res);
  2278. update_changeattr(dir, &res->cinfo);
  2279. nfs_post_op_update_inode(dir, &res->dir_attr);
  2280. return 1;
  2281. }
  2282. static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
  2283. struct inode *new_dir, struct qstr *new_name)
  2284. {
  2285. struct nfs_server *server = NFS_SERVER(old_dir);
  2286. struct nfs4_rename_arg arg = {
  2287. .old_dir = NFS_FH(old_dir),
  2288. .new_dir = NFS_FH(new_dir),
  2289. .old_name = old_name,
  2290. .new_name = new_name,
  2291. .bitmask = server->attr_bitmask,
  2292. };
  2293. struct nfs_fattr old_fattr, new_fattr;
  2294. struct nfs4_rename_res res = {
  2295. .server = server,
  2296. .old_fattr = &old_fattr,
  2297. .new_fattr = &new_fattr,
  2298. };
  2299. struct rpc_message msg = {
  2300. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
  2301. .rpc_argp = &arg,
  2302. .rpc_resp = &res,
  2303. };
  2304. int status;
  2305. nfs_fattr_init(res.old_fattr);
  2306. nfs_fattr_init(res.new_fattr);
  2307. status = nfs4_call_sync(server, &msg, &arg, &res, 1);
  2308. if (!status) {
  2309. update_changeattr(old_dir, &res.old_cinfo);
  2310. nfs_post_op_update_inode(old_dir, res.old_fattr);
  2311. update_changeattr(new_dir, &res.new_cinfo);
  2312. nfs_post_op_update_inode(new_dir, res.new_fattr);
  2313. }
  2314. return status;
  2315. }
  2316. static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
  2317. struct inode *new_dir, struct qstr *new_name)
  2318. {
  2319. struct nfs4_exception exception = { };
  2320. int err;
  2321. do {
  2322. err = nfs4_handle_exception(NFS_SERVER(old_dir),
  2323. _nfs4_proc_rename(old_dir, old_name,
  2324. new_dir, new_name),
  2325. &exception);
  2326. } while (exception.retry);
  2327. return err;
  2328. }
  2329. static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  2330. {
  2331. struct nfs_server *server = NFS_SERVER(inode);
  2332. struct nfs4_link_arg arg = {
  2333. .fh = NFS_FH(inode),
  2334. .dir_fh = NFS_FH(dir),
  2335. .name = name,
  2336. .bitmask = server->attr_bitmask,
  2337. };
  2338. struct nfs_fattr fattr, dir_attr;
  2339. struct nfs4_link_res res = {
  2340. .server = server,
  2341. .fattr = &fattr,
  2342. .dir_attr = &dir_attr,
  2343. };
  2344. struct rpc_message msg = {
  2345. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
  2346. .rpc_argp = &arg,
  2347. .rpc_resp = &res,
  2348. };
  2349. int status;
  2350. nfs_fattr_init(res.fattr);
  2351. nfs_fattr_init(res.dir_attr);
  2352. status = nfs4_call_sync(server, &msg, &arg, &res, 1);
  2353. if (!status) {
  2354. update_changeattr(dir, &res.cinfo);
  2355. nfs_post_op_update_inode(dir, res.dir_attr);
  2356. nfs_post_op_update_inode(inode, res.fattr);
  2357. }
  2358. return status;
  2359. }
  2360. static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  2361. {
  2362. struct nfs4_exception exception = { };
  2363. int err;
  2364. do {
  2365. err = nfs4_handle_exception(NFS_SERVER(inode),
  2366. _nfs4_proc_link(inode, dir, name),
  2367. &exception);
  2368. } while (exception.retry);
  2369. return err;
  2370. }
  2371. struct nfs4_createdata {
  2372. struct rpc_message msg;
  2373. struct nfs4_create_arg arg;
  2374. struct nfs4_create_res res;
  2375. struct nfs_fh fh;
  2376. struct nfs_fattr fattr;
  2377. struct nfs_fattr dir_fattr;
  2378. };
  2379. static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
  2380. struct qstr *name, struct iattr *sattr, u32 ftype)
  2381. {
  2382. struct nfs4_createdata *data;
  2383. data = kzalloc(sizeof(*data), GFP_KERNEL);
  2384. if (data != NULL) {
  2385. struct nfs_server *server = NFS_SERVER(dir);
  2386. data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
  2387. data->msg.rpc_argp = &data->arg;
  2388. data->msg.rpc_resp = &data->res;
  2389. data->arg.dir_fh = NFS_FH(dir);
  2390. data->arg.server = server;
  2391. data->arg.name = name;
  2392. data->arg.attrs = sattr;
  2393. data->arg.ftype = ftype;
  2394. data->arg.bitmask = server->attr_bitmask;
  2395. data->res.server = server;
  2396. data->res.fh = &data->fh;
  2397. data->res.fattr = &data->fattr;
  2398. data->res.dir_fattr = &data->dir_fattr;
  2399. nfs_fattr_init(data->res.fattr);
  2400. nfs_fattr_init(data->res.dir_fattr);
  2401. }
  2402. return data;
  2403. }
  2404. static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
  2405. {
  2406. int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg,
  2407. &data->arg, &data->res, 1);
  2408. if (status == 0) {
  2409. update_changeattr(dir, &data->res.dir_cinfo);
  2410. nfs_post_op_update_inode(dir, data->res.dir_fattr);
  2411. status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
  2412. }
  2413. return status;
  2414. }
  2415. static void nfs4_free_createdata(struct nfs4_createdata *data)
  2416. {
  2417. kfree(data);
  2418. }
  2419. static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
  2420. struct page *page, unsigned int len, struct iattr *sattr)
  2421. {
  2422. struct nfs4_createdata *data;
  2423. int status = -ENAMETOOLONG;
  2424. if (len > NFS4_MAXPATHLEN)
  2425. goto out;
  2426. status = -ENOMEM;
  2427. data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
  2428. if (data == NULL)
  2429. goto out;
  2430. data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
  2431. data->arg.u.symlink.pages = &page;
  2432. data->arg.u.symlink.len = len;
  2433. status = nfs4_do_create(dir, dentry, data);
  2434. nfs4_free_createdata(data);
  2435. out:
  2436. return status;
  2437. }
  2438. static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
  2439. struct page *page, unsigned int len, struct iattr *sattr)
  2440. {
  2441. struct nfs4_exception exception = { };
  2442. int err;
  2443. do {
  2444. err = nfs4_handle_exception(NFS_SERVER(dir),
  2445. _nfs4_proc_symlink(dir, dentry, page,
  2446. len, sattr),
  2447. &exception);
  2448. } while (exception.retry);
  2449. return err;
  2450. }
  2451. static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
  2452. struct iattr *sattr)
  2453. {
  2454. struct nfs4_createdata *data;
  2455. int status = -ENOMEM;
  2456. data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
  2457. if (data == NULL)
  2458. goto out;
  2459. status = nfs4_do_create(dir, dentry, data);
  2460. nfs4_free_createdata(data);
  2461. out:
  2462. return status;
  2463. }
  2464. static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
  2465. struct iattr *sattr)
  2466. {
  2467. struct nfs4_exception exception = { };
  2468. int err;
  2469. do {
  2470. err = nfs4_handle_exception(NFS_SERVER(dir),
  2471. _nfs4_proc_mkdir(dir, dentry, sattr),
  2472. &exception);
  2473. } while (exception.retry);
  2474. return err;
  2475. }
  2476. static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  2477. u64 cookie, struct page *page, unsigned int count, int plus)
  2478. {
  2479. struct inode *dir = dentry->d_inode;
  2480. struct nfs4_readdir_arg args = {
  2481. .fh = NFS_FH(dir),
  2482. .pages = &page,
  2483. .pgbase = 0,
  2484. .count = count,
  2485. .bitmask = NFS_SERVER(dentry->d_inode)->cache_consistency_bitmask,
  2486. };
  2487. struct nfs4_readdir_res res;
  2488. struct rpc_message msg = {
  2489. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
  2490. .rpc_argp = &args,
  2491. .rpc_resp = &res,
  2492. .rpc_cred = cred,
  2493. };
  2494. int status;
  2495. dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
  2496. dentry->d_parent->d_name.name,
  2497. dentry->d_name.name,
  2498. (unsigned long long)cookie);
  2499. nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
  2500. res.pgbase = args.pgbase;
  2501. status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
  2502. if (status == 0)
  2503. memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
  2504. nfs_invalidate_atime(dir);
  2505. dprintk("%s: returns %d\n", __func__, status);
  2506. return status;
  2507. }
  2508. static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  2509. u64 cookie, struct page *page, unsigned int count, int plus)
  2510. {
  2511. struct nfs4_exception exception = { };
  2512. int err;
  2513. do {
  2514. err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
  2515. _nfs4_proc_readdir(dentry, cred, cookie,
  2516. page, count, plus),
  2517. &exception);
  2518. } while (exception.retry);
  2519. return err;
  2520. }
  2521. static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
  2522. struct iattr *sattr, dev_t rdev)
  2523. {
  2524. struct nfs4_createdata *data;
  2525. int mode = sattr->ia_mode;
  2526. int status = -ENOMEM;
  2527. BUG_ON(!(sattr->ia_valid & ATTR_MODE));
  2528. BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
  2529. data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
  2530. if (data == NULL)
  2531. goto out;
  2532. if (S_ISFIFO(mode))
  2533. data->arg.ftype = NF4FIFO;
  2534. else if (S_ISBLK(mode)) {
  2535. data->arg.ftype = NF4BLK;
  2536. data->arg.u.device.specdata1 = MAJOR(rdev);
  2537. data->arg.u.device.specdata2 = MINOR(rdev);
  2538. }
  2539. else if (S_ISCHR(mode)) {
  2540. data->arg.ftype = NF4CHR;
  2541. data->arg.u.device.specdata1 = MAJOR(rdev);
  2542. data->arg.u.device.specdata2 = MINOR(rdev);
  2543. }
  2544. status = nfs4_do_create(dir, dentry, data);
  2545. nfs4_free_createdata(data);
  2546. out:
  2547. return status;
  2548. }
  2549. static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
  2550. struct iattr *sattr, dev_t rdev)
  2551. {
  2552. struct nfs4_exception exception = { };
  2553. int err;
  2554. do {
  2555. err = nfs4_handle_exception(NFS_SERVER(dir),
  2556. _nfs4_proc_mknod(dir, dentry, sattr, rdev),
  2557. &exception);
  2558. } while (exception.retry);
  2559. return err;
  2560. }
  2561. static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  2562. struct nfs_fsstat *fsstat)
  2563. {
  2564. struct nfs4_statfs_arg args = {
  2565. .fh = fhandle,
  2566. .bitmask = server->attr_bitmask,
  2567. };
  2568. struct nfs4_statfs_res res = {
  2569. .fsstat = fsstat,
  2570. };
  2571. struct rpc_message msg = {
  2572. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
  2573. .rpc_argp = &args,
  2574. .rpc_resp = &res,
  2575. };
  2576. nfs_fattr_init(fsstat->fattr);
  2577. return nfs4_call_sync(server, &msg, &args, &res, 0);
  2578. }
  2579. static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
  2580. {
  2581. struct nfs4_exception exception = { };
  2582. int err;
  2583. do {
  2584. err = nfs4_handle_exception(server,
  2585. _nfs4_proc_statfs(server, fhandle, fsstat),
  2586. &exception);
  2587. } while (exception.retry);
  2588. return err;
  2589. }
  2590. static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  2591. struct nfs_fsinfo *fsinfo)
  2592. {
  2593. struct nfs4_fsinfo_arg args = {
  2594. .fh = fhandle,
  2595. .bitmask = server->attr_bitmask,
  2596. };
  2597. struct nfs4_fsinfo_res res = {
  2598. .fsinfo = fsinfo,
  2599. };
  2600. struct rpc_message msg = {
  2601. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
  2602. .rpc_argp = &args,
  2603. .rpc_resp = &res,
  2604. };
  2605. return nfs4_call_sync(server, &msg, &args, &res, 0);
  2606. }
  2607. static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
  2608. {
  2609. struct nfs4_exception exception = { };
  2610. int err;
  2611. do {
  2612. err = nfs4_handle_exception(server,
  2613. _nfs4_do_fsinfo(server, fhandle, fsinfo),
  2614. &exception);
  2615. } while (exception.retry);
  2616. return err;
  2617. }
  2618. static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
  2619. {
  2620. nfs_fattr_init(fsinfo->fattr);
  2621. return nfs4_do_fsinfo(server, fhandle, fsinfo);
  2622. }
  2623. static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  2624. struct nfs_pathconf *pathconf)
  2625. {
  2626. struct nfs4_pathconf_arg args = {
  2627. .fh = fhandle,
  2628. .bitmask = server->attr_bitmask,
  2629. };
  2630. struct nfs4_pathconf_res res = {
  2631. .pathconf = pathconf,
  2632. };
  2633. struct rpc_message msg = {
  2634. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
  2635. .rpc_argp = &args,
  2636. .rpc_resp = &res,
  2637. };
  2638. /* None of the pathconf attributes are mandatory to implement */
  2639. if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
  2640. memset(pathconf, 0, sizeof(*pathconf));
  2641. return 0;
  2642. }
  2643. nfs_fattr_init(pathconf->fattr);
  2644. return nfs4_call_sync(server, &msg, &args, &res, 0);
  2645. }
  2646. static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  2647. struct nfs_pathconf *pathconf)
  2648. {
  2649. struct nfs4_exception exception = { };
  2650. int err;
  2651. do {
  2652. err = nfs4_handle_exception(server,
  2653. _nfs4_proc_pathconf(server, fhandle, pathconf),
  2654. &exception);
  2655. } while (exception.retry);
  2656. return err;
  2657. }
  2658. static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
  2659. {
  2660. struct nfs_server *server = NFS_SERVER(data->inode);
  2661. dprintk("--> %s\n", __func__);
  2662. /* nfs4_sequence_free_slot called in the read rpc_call_done */
  2663. nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
  2664. if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
  2665. nfs4_restart_rpc(task, server->nfs_client);
  2666. return -EAGAIN;
  2667. }
  2668. nfs_invalidate_atime(data->inode);
  2669. if (task->tk_status > 0)
  2670. renew_lease(server, data->timestamp);
  2671. return 0;
  2672. }
  2673. static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
  2674. {
  2675. data->timestamp = jiffies;
  2676. msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
  2677. }
  2678. static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
  2679. {
  2680. struct inode *inode = data->inode;
  2681. /* slot is freed in nfs_writeback_done */
  2682. nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
  2683. task->tk_status);
  2684. if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
  2685. nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
  2686. return -EAGAIN;
  2687. }
  2688. if (task->tk_status >= 0) {
  2689. renew_lease(NFS_SERVER(inode), data->timestamp);
  2690. nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
  2691. }
  2692. return 0;
  2693. }
  2694. static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
  2695. {
  2696. struct nfs_server *server = NFS_SERVER(data->inode);
  2697. data->args.bitmask = server->cache_consistency_bitmask;
  2698. data->res.server = server;
  2699. data->timestamp = jiffies;
  2700. msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
  2701. }
  2702. static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
  2703. {
  2704. struct inode *inode = data->inode;
  2705. nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
  2706. task->tk_status);
  2707. if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
  2708. nfs4_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
  2709. return -EAGAIN;
  2710. }
  2711. nfs4_sequence_free_slot(NFS_SERVER(inode)->nfs_client,
  2712. &data->res.seq_res);
  2713. nfs_refresh_inode(inode, data->res.fattr);
  2714. return 0;
  2715. }
  2716. static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
  2717. {
  2718. struct nfs_server *server = NFS_SERVER(data->inode);
  2719. data->args.bitmask = server->cache_consistency_bitmask;
  2720. data->res.server = server;
  2721. msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
  2722. }
  2723. /*
  2724. * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
  2725. * standalone procedure for queueing an asynchronous RENEW.
  2726. */
  2727. static void nfs4_renew_done(struct rpc_task *task, void *data)
  2728. {
  2729. struct nfs_client *clp = (struct nfs_client *)task->tk_msg.rpc_argp;
  2730. unsigned long timestamp = (unsigned long)data;
  2731. if (task->tk_status < 0) {
  2732. /* Unless we're shutting down, schedule state recovery! */
  2733. if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
  2734. nfs4_schedule_state_recovery(clp);
  2735. return;
  2736. }
  2737. spin_lock(&clp->cl_lock);
  2738. if (time_before(clp->cl_last_renewal,timestamp))
  2739. clp->cl_last_renewal = timestamp;
  2740. spin_unlock(&clp->cl_lock);
  2741. dprintk("%s calling put_rpccred on rpc_cred %p\n", __func__,
  2742. task->tk_msg.rpc_cred);
  2743. put_rpccred(task->tk_msg.rpc_cred);
  2744. }
  2745. static const struct rpc_call_ops nfs4_renew_ops = {
  2746. .rpc_call_done = nfs4_renew_done,
  2747. };
  2748. int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
  2749. {
  2750. struct rpc_message msg = {
  2751. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
  2752. .rpc_argp = clp,
  2753. .rpc_cred = cred,
  2754. };
  2755. return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
  2756. &nfs4_renew_ops, (void *)jiffies);
  2757. }
  2758. int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
  2759. {
  2760. struct rpc_message msg = {
  2761. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
  2762. .rpc_argp = clp,
  2763. .rpc_cred = cred,
  2764. };
  2765. unsigned long now = jiffies;
  2766. int status;
  2767. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  2768. if (status < 0)
  2769. return status;
  2770. spin_lock(&clp->cl_lock);
  2771. if (time_before(clp->cl_last_renewal,now))
  2772. clp->cl_last_renewal = now;
  2773. spin_unlock(&clp->cl_lock);
  2774. return 0;
  2775. }
  2776. static inline int nfs4_server_supports_acls(struct nfs_server *server)
  2777. {
  2778. return (server->caps & NFS_CAP_ACLS)
  2779. && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
  2780. && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
  2781. }
  2782. /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
  2783. * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
  2784. * the stack.
  2785. */
  2786. #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
  2787. static void buf_to_pages(const void *buf, size_t buflen,
  2788. struct page **pages, unsigned int *pgbase)
  2789. {
  2790. const void *p = buf;
  2791. *pgbase = offset_in_page(buf);
  2792. p -= *pgbase;
  2793. while (p < buf + buflen) {
  2794. *(pages++) = virt_to_page(p);
  2795. p += PAGE_CACHE_SIZE;
  2796. }
  2797. }
  2798. struct nfs4_cached_acl {
  2799. int cached;
  2800. size_t len;
  2801. char data[0];
  2802. };
  2803. static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
  2804. {
  2805. struct nfs_inode *nfsi = NFS_I(inode);
  2806. spin_lock(&inode->i_lock);
  2807. kfree(nfsi->nfs4_acl);
  2808. nfsi->nfs4_acl = acl;
  2809. spin_unlock(&inode->i_lock);
  2810. }
  2811. static void nfs4_zap_acl_attr(struct inode *inode)
  2812. {
  2813. nfs4_set_cached_acl(inode, NULL);
  2814. }
  2815. static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
  2816. {
  2817. struct nfs_inode *nfsi = NFS_I(inode);
  2818. struct nfs4_cached_acl *acl;
  2819. int ret = -ENOENT;
  2820. spin_lock(&inode->i_lock);
  2821. acl = nfsi->nfs4_acl;
  2822. if (acl == NULL)
  2823. goto out;
  2824. if (buf == NULL) /* user is just asking for length */
  2825. goto out_len;
  2826. if (acl->cached == 0)
  2827. goto out;
  2828. ret = -ERANGE; /* see getxattr(2) man page */
  2829. if (acl->len > buflen)
  2830. goto out;
  2831. memcpy(buf, acl->data, acl->len);
  2832. out_len:
  2833. ret = acl->len;
  2834. out:
  2835. spin_unlock(&inode->i_lock);
  2836. return ret;
  2837. }
  2838. static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
  2839. {
  2840. struct nfs4_cached_acl *acl;
  2841. if (buf && acl_len <= PAGE_SIZE) {
  2842. acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
  2843. if (acl == NULL)
  2844. goto out;
  2845. acl->cached = 1;
  2846. memcpy(acl->data, buf, acl_len);
  2847. } else {
  2848. acl = kmalloc(sizeof(*acl), GFP_KERNEL);
  2849. if (acl == NULL)
  2850. goto out;
  2851. acl->cached = 0;
  2852. }
  2853. acl->len = acl_len;
  2854. out:
  2855. nfs4_set_cached_acl(inode, acl);
  2856. }
  2857. static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
  2858. {
  2859. struct page *pages[NFS4ACL_MAXPAGES];
  2860. struct nfs_getaclargs args = {
  2861. .fh = NFS_FH(inode),
  2862. .acl_pages = pages,
  2863. .acl_len = buflen,
  2864. };
  2865. struct nfs_getaclres res = {
  2866. .acl_len = buflen,
  2867. };
  2868. void *resp_buf;
  2869. struct rpc_message msg = {
  2870. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
  2871. .rpc_argp = &args,
  2872. .rpc_resp = &res,
  2873. };
  2874. struct page *localpage = NULL;
  2875. int ret;
  2876. if (buflen < PAGE_SIZE) {
  2877. /* As long as we're doing a round trip to the server anyway,
  2878. * let's be prepared for a page of acl data. */
  2879. localpage = alloc_page(GFP_KERNEL);
  2880. resp_buf = page_address(localpage);
  2881. if (localpage == NULL)
  2882. return -ENOMEM;
  2883. args.acl_pages[0] = localpage;
  2884. args.acl_pgbase = 0;
  2885. args.acl_len = PAGE_SIZE;
  2886. } else {
  2887. resp_buf = buf;
  2888. buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
  2889. }
  2890. ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
  2891. if (ret)
  2892. goto out_free;
  2893. if (res.acl_len > args.acl_len)
  2894. nfs4_write_cached_acl(inode, NULL, res.acl_len);
  2895. else
  2896. nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
  2897. if (buf) {
  2898. ret = -ERANGE;
  2899. if (res.acl_len > buflen)
  2900. goto out_free;
  2901. if (localpage)
  2902. memcpy(buf, resp_buf, res.acl_len);
  2903. }
  2904. ret = res.acl_len;
  2905. out_free:
  2906. if (localpage)
  2907. __free_page(localpage);
  2908. return ret;
  2909. }
  2910. static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
  2911. {
  2912. struct nfs4_exception exception = { };
  2913. ssize_t ret;
  2914. do {
  2915. ret = __nfs4_get_acl_uncached(inode, buf, buflen);
  2916. if (ret >= 0)
  2917. break;
  2918. ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
  2919. } while (exception.retry);
  2920. return ret;
  2921. }
  2922. static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
  2923. {
  2924. struct nfs_server *server = NFS_SERVER(inode);
  2925. int ret;
  2926. if (!nfs4_server_supports_acls(server))
  2927. return -EOPNOTSUPP;
  2928. ret = nfs_revalidate_inode(server, inode);
  2929. if (ret < 0)
  2930. return ret;
  2931. ret = nfs4_read_cached_acl(inode, buf, buflen);
  2932. if (ret != -ENOENT)
  2933. return ret;
  2934. return nfs4_get_acl_uncached(inode, buf, buflen);
  2935. }
  2936. static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
  2937. {
  2938. struct nfs_server *server = NFS_SERVER(inode);
  2939. struct page *pages[NFS4ACL_MAXPAGES];
  2940. struct nfs_setaclargs arg = {
  2941. .fh = NFS_FH(inode),
  2942. .acl_pages = pages,
  2943. .acl_len = buflen,
  2944. };
  2945. struct nfs_setaclres res;
  2946. struct rpc_message msg = {
  2947. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
  2948. .rpc_argp = &arg,
  2949. .rpc_resp = &res,
  2950. };
  2951. int ret;
  2952. if (!nfs4_server_supports_acls(server))
  2953. return -EOPNOTSUPP;
  2954. nfs_inode_return_delegation(inode);
  2955. buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
  2956. ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
  2957. nfs_access_zap_cache(inode);
  2958. nfs_zap_acl_cache(inode);
  2959. return ret;
  2960. }
  2961. static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
  2962. {
  2963. struct nfs4_exception exception = { };
  2964. int err;
  2965. do {
  2966. err = nfs4_handle_exception(NFS_SERVER(inode),
  2967. __nfs4_proc_set_acl(inode, buf, buflen),
  2968. &exception);
  2969. } while (exception.retry);
  2970. return err;
  2971. }
  2972. static int
  2973. _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state)
  2974. {
  2975. if (!clp || task->tk_status >= 0)
  2976. return 0;
  2977. switch(task->tk_status) {
  2978. case -NFS4ERR_ADMIN_REVOKED:
  2979. case -NFS4ERR_BAD_STATEID:
  2980. case -NFS4ERR_OPENMODE:
  2981. if (state == NULL)
  2982. break;
  2983. nfs4_state_mark_reclaim_nograce(clp, state);
  2984. case -NFS4ERR_STALE_CLIENTID:
  2985. case -NFS4ERR_STALE_STATEID:
  2986. case -NFS4ERR_EXPIRED:
  2987. rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
  2988. nfs4_schedule_state_recovery(clp);
  2989. if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
  2990. rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
  2991. task->tk_status = 0;
  2992. return -EAGAIN;
  2993. #if defined(CONFIG_NFS_V4_1)
  2994. case -NFS4ERR_BADSESSION:
  2995. case -NFS4ERR_BADSLOT:
  2996. case -NFS4ERR_BAD_HIGH_SLOT:
  2997. case -NFS4ERR_DEADSESSION:
  2998. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  2999. case -NFS4ERR_SEQ_FALSE_RETRY:
  3000. case -NFS4ERR_SEQ_MISORDERED:
  3001. dprintk("%s ERROR %d, Reset session\n", __func__,
  3002. task->tk_status);
  3003. set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
  3004. task->tk_status = 0;
  3005. return -EAGAIN;
  3006. #endif /* CONFIG_NFS_V4_1 */
  3007. case -NFS4ERR_DELAY:
  3008. if (server)
  3009. nfs_inc_server_stats(server, NFSIOS_DELAY);
  3010. case -NFS4ERR_GRACE:
  3011. rpc_delay(task, NFS4_POLL_RETRY_MAX);
  3012. task->tk_status = 0;
  3013. return -EAGAIN;
  3014. case -NFS4ERR_OLD_STATEID:
  3015. task->tk_status = 0;
  3016. return -EAGAIN;
  3017. }
  3018. task->tk_status = nfs4_map_errors(task->tk_status);
  3019. return 0;
  3020. }
  3021. static int
  3022. nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
  3023. {
  3024. return _nfs4_async_handle_error(task, server, server->nfs_client, state);
  3025. }
  3026. int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
  3027. {
  3028. nfs4_verifier sc_verifier;
  3029. struct nfs4_setclientid setclientid = {
  3030. .sc_verifier = &sc_verifier,
  3031. .sc_prog = program,
  3032. };
  3033. struct rpc_message msg = {
  3034. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
  3035. .rpc_argp = &setclientid,
  3036. .rpc_resp = clp,
  3037. .rpc_cred = cred,
  3038. };
  3039. __be32 *p;
  3040. int loop = 0;
  3041. int status;
  3042. p = (__be32*)sc_verifier.data;
  3043. *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
  3044. *p = htonl((u32)clp->cl_boot_time.tv_nsec);
  3045. for(;;) {
  3046. setclientid.sc_name_len = scnprintf(setclientid.sc_name,
  3047. sizeof(setclientid.sc_name), "%s/%s %s %s %u",
  3048. clp->cl_ipaddr,
  3049. rpc_peeraddr2str(clp->cl_rpcclient,
  3050. RPC_DISPLAY_ADDR),
  3051. rpc_peeraddr2str(clp->cl_rpcclient,
  3052. RPC_DISPLAY_PROTO),
  3053. clp->cl_rpcclient->cl_auth->au_ops->au_name,
  3054. clp->cl_id_uniquifier);
  3055. setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
  3056. sizeof(setclientid.sc_netid),
  3057. rpc_peeraddr2str(clp->cl_rpcclient,
  3058. RPC_DISPLAY_NETID));
  3059. setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
  3060. sizeof(setclientid.sc_uaddr), "%s.%u.%u",
  3061. clp->cl_ipaddr, port >> 8, port & 255);
  3062. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  3063. if (status != -NFS4ERR_CLID_INUSE)
  3064. break;
  3065. if (signalled())
  3066. break;
  3067. if (loop++ & 1)
  3068. ssleep(clp->cl_lease_time + 1);
  3069. else
  3070. if (++clp->cl_id_uniquifier == 0)
  3071. break;
  3072. }
  3073. return status;
  3074. }
  3075. static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
  3076. {
  3077. struct nfs_fsinfo fsinfo;
  3078. struct rpc_message msg = {
  3079. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
  3080. .rpc_argp = clp,
  3081. .rpc_resp = &fsinfo,
  3082. .rpc_cred = cred,
  3083. };
  3084. unsigned long now;
  3085. int status;
  3086. now = jiffies;
  3087. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  3088. if (status == 0) {
  3089. spin_lock(&clp->cl_lock);
  3090. clp->cl_lease_time = fsinfo.lease_time * HZ;
  3091. clp->cl_last_renewal = now;
  3092. spin_unlock(&clp->cl_lock);
  3093. }
  3094. return status;
  3095. }
  3096. int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
  3097. {
  3098. long timeout = 0;
  3099. int err;
  3100. do {
  3101. err = _nfs4_proc_setclientid_confirm(clp, cred);
  3102. switch (err) {
  3103. case 0:
  3104. return err;
  3105. case -NFS4ERR_RESOURCE:
  3106. /* The IBM lawyers misread another document! */
  3107. case -NFS4ERR_DELAY:
  3108. err = nfs4_delay(clp->cl_rpcclient, &timeout);
  3109. }
  3110. } while (err == 0);
  3111. return err;
  3112. }
  3113. struct nfs4_delegreturndata {
  3114. struct nfs4_delegreturnargs args;
  3115. struct nfs4_delegreturnres res;
  3116. struct nfs_fh fh;
  3117. nfs4_stateid stateid;
  3118. unsigned long timestamp;
  3119. struct nfs_fattr fattr;
  3120. int rpc_status;
  3121. };
  3122. static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
  3123. {
  3124. struct nfs4_delegreturndata *data = calldata;
  3125. nfs4_sequence_done_free_slot(data->res.server, &data->res.seq_res,
  3126. task->tk_status);
  3127. data->rpc_status = task->tk_status;
  3128. if (data->rpc_status == 0)
  3129. renew_lease(data->res.server, data->timestamp);
  3130. }
  3131. static void nfs4_delegreturn_release(void *calldata)
  3132. {
  3133. kfree(calldata);
  3134. }
  3135. #if defined(CONFIG_NFS_V4_1)
  3136. static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
  3137. {
  3138. struct nfs4_delegreturndata *d_data;
  3139. d_data = (struct nfs4_delegreturndata *)data;
  3140. if (nfs4_setup_sequence(d_data->res.server->nfs_client,
  3141. &d_data->args.seq_args,
  3142. &d_data->res.seq_res, 1, task))
  3143. return;
  3144. rpc_call_start(task);
  3145. }
  3146. #endif /* CONFIG_NFS_V4_1 */
  3147. static const struct rpc_call_ops nfs4_delegreturn_ops = {
  3148. #if defined(CONFIG_NFS_V4_1)
  3149. .rpc_call_prepare = nfs4_delegreturn_prepare,
  3150. #endif /* CONFIG_NFS_V4_1 */
  3151. .rpc_call_done = nfs4_delegreturn_done,
  3152. .rpc_release = nfs4_delegreturn_release,
  3153. };
  3154. static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
  3155. {
  3156. struct nfs4_delegreturndata *data;
  3157. struct nfs_server *server = NFS_SERVER(inode);
  3158. struct rpc_task *task;
  3159. struct rpc_message msg = {
  3160. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
  3161. .rpc_cred = cred,
  3162. };
  3163. struct rpc_task_setup task_setup_data = {
  3164. .rpc_client = server->client,
  3165. .rpc_message = &msg,
  3166. .callback_ops = &nfs4_delegreturn_ops,
  3167. .flags = RPC_TASK_ASYNC,
  3168. };
  3169. int status = 0;
  3170. data = kzalloc(sizeof(*data), GFP_KERNEL);
  3171. if (data == NULL)
  3172. return -ENOMEM;
  3173. data->args.fhandle = &data->fh;
  3174. data->args.stateid = &data->stateid;
  3175. data->args.bitmask = server->attr_bitmask;
  3176. nfs_copy_fh(&data->fh, NFS_FH(inode));
  3177. memcpy(&data->stateid, stateid, sizeof(data->stateid));
  3178. data->res.fattr = &data->fattr;
  3179. data->res.server = server;
  3180. data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  3181. nfs_fattr_init(data->res.fattr);
  3182. data->timestamp = jiffies;
  3183. data->rpc_status = 0;
  3184. task_setup_data.callback_data = data;
  3185. msg.rpc_argp = &data->args,
  3186. msg.rpc_resp = &data->res,
  3187. task = rpc_run_task(&task_setup_data);
  3188. if (IS_ERR(task))
  3189. return PTR_ERR(task);
  3190. if (!issync)
  3191. goto out;
  3192. status = nfs4_wait_for_completion_rpc_task(task);
  3193. if (status != 0)
  3194. goto out;
  3195. status = data->rpc_status;
  3196. if (status != 0)
  3197. goto out;
  3198. nfs_refresh_inode(inode, &data->fattr);
  3199. out:
  3200. rpc_put_task(task);
  3201. return status;
  3202. }
  3203. int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
  3204. {
  3205. struct nfs_server *server = NFS_SERVER(inode);
  3206. struct nfs4_exception exception = { };
  3207. int err;
  3208. do {
  3209. err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
  3210. switch (err) {
  3211. case -NFS4ERR_STALE_STATEID:
  3212. case -NFS4ERR_EXPIRED:
  3213. case 0:
  3214. return 0;
  3215. }
  3216. err = nfs4_handle_exception(server, err, &exception);
  3217. } while (exception.retry);
  3218. return err;
  3219. }
  3220. #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
  3221. #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
  3222. /*
  3223. * sleep, with exponential backoff, and retry the LOCK operation.
  3224. */
  3225. static unsigned long
  3226. nfs4_set_lock_task_retry(unsigned long timeout)
  3227. {
  3228. schedule_timeout_killable(timeout);
  3229. timeout <<= 1;
  3230. if (timeout > NFS4_LOCK_MAXTIMEOUT)
  3231. return NFS4_LOCK_MAXTIMEOUT;
  3232. return timeout;
  3233. }
  3234. static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  3235. {
  3236. struct inode *inode = state->inode;
  3237. struct nfs_server *server = NFS_SERVER(inode);
  3238. struct nfs_client *clp = server->nfs_client;
  3239. struct nfs_lockt_args arg = {
  3240. .fh = NFS_FH(inode),
  3241. .fl = request,
  3242. };
  3243. struct nfs_lockt_res res = {
  3244. .denied = request,
  3245. };
  3246. struct rpc_message msg = {
  3247. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
  3248. .rpc_argp = &arg,
  3249. .rpc_resp = &res,
  3250. .rpc_cred = state->owner->so_cred,
  3251. };
  3252. struct nfs4_lock_state *lsp;
  3253. int status;
  3254. arg.lock_owner.clientid = clp->cl_clientid;
  3255. status = nfs4_set_lock_state(state, request);
  3256. if (status != 0)
  3257. goto out;
  3258. lsp = request->fl_u.nfs4_fl.owner;
  3259. arg.lock_owner.id = lsp->ls_id.id;
  3260. status = nfs4_call_sync(server, &msg, &arg, &res, 1);
  3261. switch (status) {
  3262. case 0:
  3263. request->fl_type = F_UNLCK;
  3264. break;
  3265. case -NFS4ERR_DENIED:
  3266. status = 0;
  3267. }
  3268. request->fl_ops->fl_release_private(request);
  3269. out:
  3270. return status;
  3271. }
  3272. static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  3273. {
  3274. struct nfs4_exception exception = { };
  3275. int err;
  3276. do {
  3277. err = nfs4_handle_exception(NFS_SERVER(state->inode),
  3278. _nfs4_proc_getlk(state, cmd, request),
  3279. &exception);
  3280. } while (exception.retry);
  3281. return err;
  3282. }
  3283. static int do_vfs_lock(struct file *file, struct file_lock *fl)
  3284. {
  3285. int res = 0;
  3286. switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
  3287. case FL_POSIX:
  3288. res = posix_lock_file_wait(file, fl);
  3289. break;
  3290. case FL_FLOCK:
  3291. res = flock_lock_file_wait(file, fl);
  3292. break;
  3293. default:
  3294. BUG();
  3295. }
  3296. return res;
  3297. }
  3298. struct nfs4_unlockdata {
  3299. struct nfs_locku_args arg;
  3300. struct nfs_locku_res res;
  3301. struct nfs4_lock_state *lsp;
  3302. struct nfs_open_context *ctx;
  3303. struct file_lock fl;
  3304. const struct nfs_server *server;
  3305. unsigned long timestamp;
  3306. };
  3307. static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
  3308. struct nfs_open_context *ctx,
  3309. struct nfs4_lock_state *lsp,
  3310. struct nfs_seqid *seqid)
  3311. {
  3312. struct nfs4_unlockdata *p;
  3313. struct inode *inode = lsp->ls_state->inode;
  3314. p = kzalloc(sizeof(*p), GFP_KERNEL);
  3315. if (p == NULL)
  3316. return NULL;
  3317. p->arg.fh = NFS_FH(inode);
  3318. p->arg.fl = &p->fl;
  3319. p->arg.seqid = seqid;
  3320. p->res.seqid = seqid;
  3321. p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  3322. p->arg.stateid = &lsp->ls_stateid;
  3323. p->lsp = lsp;
  3324. atomic_inc(&lsp->ls_count);
  3325. /* Ensure we don't close file until we're done freeing locks! */
  3326. p->ctx = get_nfs_open_context(ctx);
  3327. memcpy(&p->fl, fl, sizeof(p->fl));
  3328. p->server = NFS_SERVER(inode);
  3329. return p;
  3330. }
  3331. static void nfs4_locku_release_calldata(void *data)
  3332. {
  3333. struct nfs4_unlockdata *calldata = data;
  3334. nfs_free_seqid(calldata->arg.seqid);
  3335. nfs4_put_lock_state(calldata->lsp);
  3336. put_nfs_open_context(calldata->ctx);
  3337. kfree(calldata);
  3338. }
  3339. static void nfs4_locku_done(struct rpc_task *task, void *data)
  3340. {
  3341. struct nfs4_unlockdata *calldata = data;
  3342. nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
  3343. task->tk_status);
  3344. if (RPC_ASSASSINATED(task))
  3345. return;
  3346. switch (task->tk_status) {
  3347. case 0:
  3348. memcpy(calldata->lsp->ls_stateid.data,
  3349. calldata->res.stateid.data,
  3350. sizeof(calldata->lsp->ls_stateid.data));
  3351. renew_lease(calldata->server, calldata->timestamp);
  3352. break;
  3353. case -NFS4ERR_BAD_STATEID:
  3354. case -NFS4ERR_OLD_STATEID:
  3355. case -NFS4ERR_STALE_STATEID:
  3356. case -NFS4ERR_EXPIRED:
  3357. break;
  3358. default:
  3359. if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
  3360. nfs4_restart_rpc(task,
  3361. calldata->server->nfs_client);
  3362. }
  3363. nfs4_sequence_free_slot(calldata->server->nfs_client,
  3364. &calldata->res.seq_res);
  3365. }
  3366. static void nfs4_locku_prepare(struct rpc_task *task, void *data)
  3367. {
  3368. struct nfs4_unlockdata *calldata = data;
  3369. if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
  3370. return;
  3371. if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
  3372. /* Note: exit _without_ running nfs4_locku_done */
  3373. task->tk_action = NULL;
  3374. return;
  3375. }
  3376. calldata->timestamp = jiffies;
  3377. if (nfs4_setup_sequence(calldata->server->nfs_client,
  3378. &calldata->arg.seq_args,
  3379. &calldata->res.seq_res, 1, task))
  3380. return;
  3381. rpc_call_start(task);
  3382. }
  3383. static const struct rpc_call_ops nfs4_locku_ops = {
  3384. .rpc_call_prepare = nfs4_locku_prepare,
  3385. .rpc_call_done = nfs4_locku_done,
  3386. .rpc_release = nfs4_locku_release_calldata,
  3387. };
  3388. static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
  3389. struct nfs_open_context *ctx,
  3390. struct nfs4_lock_state *lsp,
  3391. struct nfs_seqid *seqid)
  3392. {
  3393. struct nfs4_unlockdata *data;
  3394. struct rpc_message msg = {
  3395. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
  3396. .rpc_cred = ctx->cred,
  3397. };
  3398. struct rpc_task_setup task_setup_data = {
  3399. .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
  3400. .rpc_message = &msg,
  3401. .callback_ops = &nfs4_locku_ops,
  3402. .workqueue = nfsiod_workqueue,
  3403. .flags = RPC_TASK_ASYNC,
  3404. };
  3405. /* Ensure this is an unlock - when canceling a lock, the
  3406. * canceled lock is passed in, and it won't be an unlock.
  3407. */
  3408. fl->fl_type = F_UNLCK;
  3409. data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
  3410. if (data == NULL) {
  3411. nfs_free_seqid(seqid);
  3412. return ERR_PTR(-ENOMEM);
  3413. }
  3414. msg.rpc_argp = &data->arg,
  3415. msg.rpc_resp = &data->res,
  3416. task_setup_data.callback_data = data;
  3417. return rpc_run_task(&task_setup_data);
  3418. }
  3419. static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
  3420. {
  3421. struct nfs_inode *nfsi = NFS_I(state->inode);
  3422. struct nfs_seqid *seqid;
  3423. struct nfs4_lock_state *lsp;
  3424. struct rpc_task *task;
  3425. int status = 0;
  3426. unsigned char fl_flags = request->fl_flags;
  3427. status = nfs4_set_lock_state(state, request);
  3428. /* Unlock _before_ we do the RPC call */
  3429. request->fl_flags |= FL_EXISTS;
  3430. down_read(&nfsi->rwsem);
  3431. if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
  3432. up_read(&nfsi->rwsem);
  3433. goto out;
  3434. }
  3435. up_read(&nfsi->rwsem);
  3436. if (status != 0)
  3437. goto out;
  3438. /* Is this a delegated lock? */
  3439. if (test_bit(NFS_DELEGATED_STATE, &state->flags))
  3440. goto out;
  3441. lsp = request->fl_u.nfs4_fl.owner;
  3442. seqid = nfs_alloc_seqid(&lsp->ls_seqid);
  3443. status = -ENOMEM;
  3444. if (seqid == NULL)
  3445. goto out;
  3446. task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
  3447. status = PTR_ERR(task);
  3448. if (IS_ERR(task))
  3449. goto out;
  3450. status = nfs4_wait_for_completion_rpc_task(task);
  3451. rpc_put_task(task);
  3452. out:
  3453. request->fl_flags = fl_flags;
  3454. return status;
  3455. }
  3456. struct nfs4_lockdata {
  3457. struct nfs_lock_args arg;
  3458. struct nfs_lock_res res;
  3459. struct nfs4_lock_state *lsp;
  3460. struct nfs_open_context *ctx;
  3461. struct file_lock fl;
  3462. unsigned long timestamp;
  3463. int rpc_status;
  3464. int cancelled;
  3465. struct nfs_server *server;
  3466. };
  3467. static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
  3468. struct nfs_open_context *ctx, struct nfs4_lock_state *lsp)
  3469. {
  3470. struct nfs4_lockdata *p;
  3471. struct inode *inode = lsp->ls_state->inode;
  3472. struct nfs_server *server = NFS_SERVER(inode);
  3473. p = kzalloc(sizeof(*p), GFP_KERNEL);
  3474. if (p == NULL)
  3475. return NULL;
  3476. p->arg.fh = NFS_FH(inode);
  3477. p->arg.fl = &p->fl;
  3478. p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid);
  3479. if (p->arg.open_seqid == NULL)
  3480. goto out_free;
  3481. p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
  3482. if (p->arg.lock_seqid == NULL)
  3483. goto out_free_seqid;
  3484. p->arg.lock_stateid = &lsp->ls_stateid;
  3485. p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
  3486. p->arg.lock_owner.id = lsp->ls_id.id;
  3487. p->res.lock_seqid = p->arg.lock_seqid;
  3488. p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  3489. p->lsp = lsp;
  3490. p->server = server;
  3491. atomic_inc(&lsp->ls_count);
  3492. p->ctx = get_nfs_open_context(ctx);
  3493. memcpy(&p->fl, fl, sizeof(p->fl));
  3494. return p;
  3495. out_free_seqid:
  3496. nfs_free_seqid(p->arg.open_seqid);
  3497. out_free:
  3498. kfree(p);
  3499. return NULL;
  3500. }
  3501. static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
  3502. {
  3503. struct nfs4_lockdata *data = calldata;
  3504. struct nfs4_state *state = data->lsp->ls_state;
  3505. dprintk("%s: begin!\n", __func__);
  3506. if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
  3507. return;
  3508. /* Do we need to do an open_to_lock_owner? */
  3509. if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
  3510. if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
  3511. return;
  3512. data->arg.open_stateid = &state->stateid;
  3513. data->arg.new_lock_owner = 1;
  3514. data->res.open_seqid = data->arg.open_seqid;
  3515. } else
  3516. data->arg.new_lock_owner = 0;
  3517. data->timestamp = jiffies;
  3518. if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args,
  3519. &data->res.seq_res, 1, task))
  3520. return;
  3521. rpc_call_start(task);
  3522. dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
  3523. }
  3524. static void nfs4_lock_done(struct rpc_task *task, void *calldata)
  3525. {
  3526. struct nfs4_lockdata *data = calldata;
  3527. dprintk("%s: begin!\n", __func__);
  3528. nfs4_sequence_done_free_slot(data->server, &data->res.seq_res,
  3529. task->tk_status);
  3530. data->rpc_status = task->tk_status;
  3531. if (RPC_ASSASSINATED(task))
  3532. goto out;
  3533. if (data->arg.new_lock_owner != 0) {
  3534. if (data->rpc_status == 0)
  3535. nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
  3536. else
  3537. goto out;
  3538. }
  3539. if (data->rpc_status == 0) {
  3540. memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
  3541. sizeof(data->lsp->ls_stateid.data));
  3542. data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
  3543. renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
  3544. }
  3545. out:
  3546. dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
  3547. }
  3548. static void nfs4_lock_release(void *calldata)
  3549. {
  3550. struct nfs4_lockdata *data = calldata;
  3551. dprintk("%s: begin!\n", __func__);
  3552. nfs_free_seqid(data->arg.open_seqid);
  3553. if (data->cancelled != 0) {
  3554. struct rpc_task *task;
  3555. task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
  3556. data->arg.lock_seqid);
  3557. if (!IS_ERR(task))
  3558. rpc_put_task(task);
  3559. dprintk("%s: cancelling lock!\n", __func__);
  3560. } else
  3561. nfs_free_seqid(data->arg.lock_seqid);
  3562. nfs4_put_lock_state(data->lsp);
  3563. put_nfs_open_context(data->ctx);
  3564. kfree(data);
  3565. dprintk("%s: done!\n", __func__);
  3566. }
  3567. static const struct rpc_call_ops nfs4_lock_ops = {
  3568. .rpc_call_prepare = nfs4_lock_prepare,
  3569. .rpc_call_done = nfs4_lock_done,
  3570. .rpc_release = nfs4_lock_release,
  3571. };
  3572. static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int reclaim)
  3573. {
  3574. struct nfs4_lockdata *data;
  3575. struct rpc_task *task;
  3576. struct rpc_message msg = {
  3577. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
  3578. .rpc_cred = state->owner->so_cred,
  3579. };
  3580. struct rpc_task_setup task_setup_data = {
  3581. .rpc_client = NFS_CLIENT(state->inode),
  3582. .rpc_message = &msg,
  3583. .callback_ops = &nfs4_lock_ops,
  3584. .workqueue = nfsiod_workqueue,
  3585. .flags = RPC_TASK_ASYNC,
  3586. };
  3587. int ret;
  3588. dprintk("%s: begin!\n", __func__);
  3589. data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
  3590. fl->fl_u.nfs4_fl.owner);
  3591. if (data == NULL)
  3592. return -ENOMEM;
  3593. if (IS_SETLKW(cmd))
  3594. data->arg.block = 1;
  3595. if (reclaim != 0)
  3596. data->arg.reclaim = 1;
  3597. msg.rpc_argp = &data->arg,
  3598. msg.rpc_resp = &data->res,
  3599. task_setup_data.callback_data = data;
  3600. task = rpc_run_task(&task_setup_data);
  3601. if (IS_ERR(task))
  3602. return PTR_ERR(task);
  3603. ret = nfs4_wait_for_completion_rpc_task(task);
  3604. if (ret == 0) {
  3605. ret = data->rpc_status;
  3606. } else
  3607. data->cancelled = 1;
  3608. rpc_put_task(task);
  3609. dprintk("%s: done, ret = %d!\n", __func__, ret);
  3610. return ret;
  3611. }
  3612. static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
  3613. {
  3614. struct nfs_server *server = NFS_SERVER(state->inode);
  3615. struct nfs4_exception exception = { };
  3616. int err;
  3617. do {
  3618. /* Cache the lock if possible... */
  3619. if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
  3620. return 0;
  3621. err = _nfs4_do_setlk(state, F_SETLK, request, 1);
  3622. if (err != -NFS4ERR_DELAY)
  3623. break;
  3624. nfs4_handle_exception(server, err, &exception);
  3625. } while (exception.retry);
  3626. return err;
  3627. }
  3628. static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
  3629. {
  3630. struct nfs_server *server = NFS_SERVER(state->inode);
  3631. struct nfs4_exception exception = { };
  3632. int err;
  3633. err = nfs4_set_lock_state(state, request);
  3634. if (err != 0)
  3635. return err;
  3636. do {
  3637. if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
  3638. return 0;
  3639. err = _nfs4_do_setlk(state, F_SETLK, request, 0);
  3640. if (err != -NFS4ERR_DELAY)
  3641. break;
  3642. nfs4_handle_exception(server, err, &exception);
  3643. } while (exception.retry);
  3644. return err;
  3645. }
  3646. static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  3647. {
  3648. struct nfs_inode *nfsi = NFS_I(state->inode);
  3649. unsigned char fl_flags = request->fl_flags;
  3650. int status;
  3651. /* Is this a delegated open? */
  3652. status = nfs4_set_lock_state(state, request);
  3653. if (status != 0)
  3654. goto out;
  3655. request->fl_flags |= FL_ACCESS;
  3656. status = do_vfs_lock(request->fl_file, request);
  3657. if (status < 0)
  3658. goto out;
  3659. down_read(&nfsi->rwsem);
  3660. if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
  3661. /* Yes: cache locks! */
  3662. /* ...but avoid races with delegation recall... */
  3663. request->fl_flags = fl_flags & ~FL_SLEEP;
  3664. status = do_vfs_lock(request->fl_file, request);
  3665. goto out_unlock;
  3666. }
  3667. status = _nfs4_do_setlk(state, cmd, request, 0);
  3668. if (status != 0)
  3669. goto out_unlock;
  3670. /* Note: we always want to sleep here! */
  3671. request->fl_flags = fl_flags | FL_SLEEP;
  3672. if (do_vfs_lock(request->fl_file, request) < 0)
  3673. printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
  3674. out_unlock:
  3675. up_read(&nfsi->rwsem);
  3676. out:
  3677. request->fl_flags = fl_flags;
  3678. return status;
  3679. }
  3680. static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  3681. {
  3682. struct nfs4_exception exception = { };
  3683. int err;
  3684. do {
  3685. err = _nfs4_proc_setlk(state, cmd, request);
  3686. if (err == -NFS4ERR_DENIED)
  3687. err = -EAGAIN;
  3688. err = nfs4_handle_exception(NFS_SERVER(state->inode),
  3689. err, &exception);
  3690. } while (exception.retry);
  3691. return err;
  3692. }
  3693. static int
  3694. nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
  3695. {
  3696. struct nfs_open_context *ctx;
  3697. struct nfs4_state *state;
  3698. unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
  3699. int status;
  3700. /* verify open state */
  3701. ctx = nfs_file_open_context(filp);
  3702. state = ctx->state;
  3703. if (request->fl_start < 0 || request->fl_end < 0)
  3704. return -EINVAL;
  3705. if (IS_GETLK(cmd))
  3706. return nfs4_proc_getlk(state, F_GETLK, request);
  3707. if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
  3708. return -EINVAL;
  3709. if (request->fl_type == F_UNLCK)
  3710. return nfs4_proc_unlck(state, cmd, request);
  3711. do {
  3712. status = nfs4_proc_setlk(state, cmd, request);
  3713. if ((status != -EAGAIN) || IS_SETLK(cmd))
  3714. break;
  3715. timeout = nfs4_set_lock_task_retry(timeout);
  3716. status = -ERESTARTSYS;
  3717. if (signalled())
  3718. break;
  3719. } while(status < 0);
  3720. return status;
  3721. }
  3722. int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
  3723. {
  3724. struct nfs_server *server = NFS_SERVER(state->inode);
  3725. struct nfs4_exception exception = { };
  3726. int err;
  3727. err = nfs4_set_lock_state(state, fl);
  3728. if (err != 0)
  3729. goto out;
  3730. do {
  3731. err = _nfs4_do_setlk(state, F_SETLK, fl, 0);
  3732. switch (err) {
  3733. default:
  3734. printk(KERN_ERR "%s: unhandled error %d.\n",
  3735. __func__, err);
  3736. case 0:
  3737. case -ESTALE:
  3738. goto out;
  3739. case -NFS4ERR_EXPIRED:
  3740. case -NFS4ERR_STALE_CLIENTID:
  3741. case -NFS4ERR_STALE_STATEID:
  3742. nfs4_schedule_state_recovery(server->nfs_client);
  3743. goto out;
  3744. case -ERESTARTSYS:
  3745. /*
  3746. * The show must go on: exit, but mark the
  3747. * stateid as needing recovery.
  3748. */
  3749. case -NFS4ERR_ADMIN_REVOKED:
  3750. case -NFS4ERR_BAD_STATEID:
  3751. case -NFS4ERR_OPENMODE:
  3752. nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
  3753. err = 0;
  3754. goto out;
  3755. case -ENOMEM:
  3756. case -NFS4ERR_DENIED:
  3757. /* kill_proc(fl->fl_pid, SIGLOST, 1); */
  3758. err = 0;
  3759. goto out;
  3760. case -NFS4ERR_DELAY:
  3761. break;
  3762. }
  3763. err = nfs4_handle_exception(server, err, &exception);
  3764. } while (exception.retry);
  3765. out:
  3766. return err;
  3767. }
  3768. #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
  3769. int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
  3770. size_t buflen, int flags)
  3771. {
  3772. struct inode *inode = dentry->d_inode;
  3773. if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
  3774. return -EOPNOTSUPP;
  3775. return nfs4_proc_set_acl(inode, buf, buflen);
  3776. }
  3777. /* The getxattr man page suggests returning -ENODATA for unknown attributes,
  3778. * and that's what we'll do for e.g. user attributes that haven't been set.
  3779. * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
  3780. * attributes in kernel-managed attribute namespaces. */
  3781. ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
  3782. size_t buflen)
  3783. {
  3784. struct inode *inode = dentry->d_inode;
  3785. if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
  3786. return -EOPNOTSUPP;
  3787. return nfs4_proc_get_acl(inode, buf, buflen);
  3788. }
  3789. ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
  3790. {
  3791. size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
  3792. if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
  3793. return 0;
  3794. if (buf && buflen < len)
  3795. return -ERANGE;
  3796. if (buf)
  3797. memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
  3798. return len;
  3799. }
  3800. static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
  3801. {
  3802. if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
  3803. (fattr->valid & NFS_ATTR_FATTR_FSID) &&
  3804. (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
  3805. return;
  3806. fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
  3807. NFS_ATTR_FATTR_NLINK;
  3808. fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  3809. fattr->nlink = 2;
  3810. }
  3811. int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
  3812. struct nfs4_fs_locations *fs_locations, struct page *page)
  3813. {
  3814. struct nfs_server *server = NFS_SERVER(dir);
  3815. u32 bitmask[2] = {
  3816. [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
  3817. [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
  3818. };
  3819. struct nfs4_fs_locations_arg args = {
  3820. .dir_fh = NFS_FH(dir),
  3821. .name = name,
  3822. .page = page,
  3823. .bitmask = bitmask,
  3824. };
  3825. struct nfs4_fs_locations_res res = {
  3826. .fs_locations = fs_locations,
  3827. };
  3828. struct rpc_message msg = {
  3829. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
  3830. .rpc_argp = &args,
  3831. .rpc_resp = &res,
  3832. };
  3833. int status;
  3834. dprintk("%s: start\n", __func__);
  3835. nfs_fattr_init(&fs_locations->fattr);
  3836. fs_locations->server = server;
  3837. fs_locations->nlocations = 0;
  3838. status = nfs4_call_sync(server, &msg, &args, &res, 0);
  3839. nfs_fixup_referral_attributes(&fs_locations->fattr);
  3840. dprintk("%s: returned status = %d\n", __func__, status);
  3841. return status;
  3842. }
  3843. #ifdef CONFIG_NFS_V4_1
  3844. /*
  3845. * nfs4_proc_exchange_id()
  3846. *
  3847. * Since the clientid has expired, all compounds using sessions
  3848. * associated with the stale clientid will be returning
  3849. * NFS4ERR_BADSESSION in the sequence operation, and will therefore
  3850. * be in some phase of session reset.
  3851. */
  3852. static int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
  3853. {
  3854. nfs4_verifier verifier;
  3855. struct nfs41_exchange_id_args args = {
  3856. .client = clp,
  3857. .flags = clp->cl_exchange_flags,
  3858. };
  3859. struct nfs41_exchange_id_res res = {
  3860. .client = clp,
  3861. };
  3862. int status;
  3863. struct rpc_message msg = {
  3864. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
  3865. .rpc_argp = &args,
  3866. .rpc_resp = &res,
  3867. .rpc_cred = cred,
  3868. };
  3869. __be32 *p;
  3870. dprintk("--> %s\n", __func__);
  3871. BUG_ON(clp == NULL);
  3872. p = (u32 *)verifier.data;
  3873. *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
  3874. *p = htonl((u32)clp->cl_boot_time.tv_nsec);
  3875. args.verifier = &verifier;
  3876. while (1) {
  3877. args.id_len = scnprintf(args.id, sizeof(args.id),
  3878. "%s/%s %u",
  3879. clp->cl_ipaddr,
  3880. rpc_peeraddr2str(clp->cl_rpcclient,
  3881. RPC_DISPLAY_ADDR),
  3882. clp->cl_id_uniquifier);
  3883. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  3884. if (status != NFS4ERR_CLID_INUSE)
  3885. break;
  3886. if (signalled())
  3887. break;
  3888. if (++clp->cl_id_uniquifier == 0)
  3889. break;
  3890. }
  3891. dprintk("<-- %s status= %d\n", __func__, status);
  3892. return status;
  3893. }
  3894. struct nfs4_get_lease_time_data {
  3895. struct nfs4_get_lease_time_args *args;
  3896. struct nfs4_get_lease_time_res *res;
  3897. struct nfs_client *clp;
  3898. };
  3899. static void nfs4_get_lease_time_prepare(struct rpc_task *task,
  3900. void *calldata)
  3901. {
  3902. int ret;
  3903. struct nfs4_get_lease_time_data *data =
  3904. (struct nfs4_get_lease_time_data *)calldata;
  3905. dprintk("--> %s\n", __func__);
  3906. /* just setup sequence, do not trigger session recovery
  3907. since we're invoked within one */
  3908. ret = nfs41_setup_sequence(data->clp->cl_session,
  3909. &data->args->la_seq_args,
  3910. &data->res->lr_seq_res, 0, task);
  3911. BUG_ON(ret == -EAGAIN);
  3912. rpc_call_start(task);
  3913. dprintk("<-- %s\n", __func__);
  3914. }
  3915. /*
  3916. * Called from nfs4_state_manager thread for session setup, so don't recover
  3917. * from sequence operation or clientid errors.
  3918. */
  3919. static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
  3920. {
  3921. struct nfs4_get_lease_time_data *data =
  3922. (struct nfs4_get_lease_time_data *)calldata;
  3923. dprintk("--> %s\n", __func__);
  3924. nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status);
  3925. switch (task->tk_status) {
  3926. case -NFS4ERR_DELAY:
  3927. case -NFS4ERR_GRACE:
  3928. dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
  3929. rpc_delay(task, NFS4_POLL_RETRY_MIN);
  3930. task->tk_status = 0;
  3931. nfs4_restart_rpc(task, data->clp);
  3932. return;
  3933. }
  3934. nfs41_sequence_free_slot(data->clp, &data->res->lr_seq_res);
  3935. dprintk("<-- %s\n", __func__);
  3936. }
  3937. struct rpc_call_ops nfs4_get_lease_time_ops = {
  3938. .rpc_call_prepare = nfs4_get_lease_time_prepare,
  3939. .rpc_call_done = nfs4_get_lease_time_done,
  3940. };
  3941. int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
  3942. {
  3943. struct rpc_task *task;
  3944. struct nfs4_get_lease_time_args args;
  3945. struct nfs4_get_lease_time_res res = {
  3946. .lr_fsinfo = fsinfo,
  3947. };
  3948. struct nfs4_get_lease_time_data data = {
  3949. .args = &args,
  3950. .res = &res,
  3951. .clp = clp,
  3952. };
  3953. struct rpc_message msg = {
  3954. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
  3955. .rpc_argp = &args,
  3956. .rpc_resp = &res,
  3957. };
  3958. struct rpc_task_setup task_setup = {
  3959. .rpc_client = clp->cl_rpcclient,
  3960. .rpc_message = &msg,
  3961. .callback_ops = &nfs4_get_lease_time_ops,
  3962. .callback_data = &data
  3963. };
  3964. int status;
  3965. res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
  3966. dprintk("--> %s\n", __func__);
  3967. task = rpc_run_task(&task_setup);
  3968. if (IS_ERR(task))
  3969. status = PTR_ERR(task);
  3970. else {
  3971. status = task->tk_status;
  3972. rpc_put_task(task);
  3973. }
  3974. dprintk("<-- %s return %d\n", __func__, status);
  3975. return status;
  3976. }
  3977. /*
  3978. * Reset a slot table
  3979. */
  3980. static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, int max_slots,
  3981. int old_max_slots, int ivalue)
  3982. {
  3983. int i;
  3984. int ret = 0;
  3985. dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__, max_slots, tbl);
  3986. /*
  3987. * Until we have dynamic slot table adjustment, insist
  3988. * upon the same slot table size
  3989. */
  3990. if (max_slots != old_max_slots) {
  3991. dprintk("%s reset slot table does't match old\n",
  3992. __func__);
  3993. ret = -EINVAL; /*XXX NFS4ERR_REQ_TOO_BIG ? */
  3994. goto out;
  3995. }
  3996. spin_lock(&tbl->slot_tbl_lock);
  3997. for (i = 0; i < max_slots; ++i)
  3998. tbl->slots[i].seq_nr = ivalue;
  3999. tbl->highest_used_slotid = -1;
  4000. spin_unlock(&tbl->slot_tbl_lock);
  4001. dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
  4002. tbl, tbl->slots, tbl->max_slots);
  4003. out:
  4004. dprintk("<-- %s: return %d\n", __func__, ret);
  4005. return ret;
  4006. }
  4007. /*
  4008. * Reset the forechannel and backchannel slot tables
  4009. */
  4010. static int nfs4_reset_slot_tables(struct nfs4_session *session)
  4011. {
  4012. int status;
  4013. status = nfs4_reset_slot_table(&session->fc_slot_table,
  4014. session->fc_attrs.max_reqs,
  4015. session->fc_slot_table.max_slots,
  4016. 1);
  4017. if (status)
  4018. return status;
  4019. status = nfs4_reset_slot_table(&session->bc_slot_table,
  4020. session->bc_attrs.max_reqs,
  4021. session->bc_slot_table.max_slots,
  4022. 0);
  4023. return status;
  4024. }
  4025. /* Destroy the slot table */
  4026. static void nfs4_destroy_slot_tables(struct nfs4_session *session)
  4027. {
  4028. if (session->fc_slot_table.slots != NULL) {
  4029. kfree(session->fc_slot_table.slots);
  4030. session->fc_slot_table.slots = NULL;
  4031. }
  4032. if (session->bc_slot_table.slots != NULL) {
  4033. kfree(session->bc_slot_table.slots);
  4034. session->bc_slot_table.slots = NULL;
  4035. }
  4036. return;
  4037. }
  4038. /*
  4039. * Initialize slot table
  4040. */
  4041. static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
  4042. int max_slots, int ivalue)
  4043. {
  4044. int i;
  4045. struct nfs4_slot *slot;
  4046. int ret = -ENOMEM;
  4047. BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
  4048. dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
  4049. slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL);
  4050. if (!slot)
  4051. goto out;
  4052. for (i = 0; i < max_slots; ++i)
  4053. slot[i].seq_nr = ivalue;
  4054. ret = 0;
  4055. spin_lock(&tbl->slot_tbl_lock);
  4056. if (tbl->slots != NULL) {
  4057. spin_unlock(&tbl->slot_tbl_lock);
  4058. dprintk("%s: slot table already initialized. tbl=%p slots=%p\n",
  4059. __func__, tbl, tbl->slots);
  4060. WARN_ON(1);
  4061. goto out_free;
  4062. }
  4063. tbl->max_slots = max_slots;
  4064. tbl->slots = slot;
  4065. tbl->highest_used_slotid = -1; /* no slot is currently used */
  4066. spin_unlock(&tbl->slot_tbl_lock);
  4067. dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
  4068. tbl, tbl->slots, tbl->max_slots);
  4069. out:
  4070. dprintk("<-- %s: return %d\n", __func__, ret);
  4071. return ret;
  4072. out_free:
  4073. kfree(slot);
  4074. goto out;
  4075. }
  4076. /*
  4077. * Initialize the forechannel and backchannel tables
  4078. */
  4079. static int nfs4_init_slot_tables(struct nfs4_session *session)
  4080. {
  4081. int status;
  4082. status = nfs4_init_slot_table(&session->fc_slot_table,
  4083. session->fc_attrs.max_reqs, 1);
  4084. if (status)
  4085. return status;
  4086. status = nfs4_init_slot_table(&session->bc_slot_table,
  4087. session->bc_attrs.max_reqs, 0);
  4088. if (status)
  4089. nfs4_destroy_slot_tables(session);
  4090. return status;
  4091. }
  4092. struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
  4093. {
  4094. struct nfs4_session *session;
  4095. struct nfs4_slot_table *tbl;
  4096. session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL);
  4097. if (!session)
  4098. return NULL;
  4099. set_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state);
  4100. /*
  4101. * The create session reply races with the server back
  4102. * channel probe. Mark the client NFS_CS_SESSION_INITING
  4103. * so that the client back channel can find the
  4104. * nfs_client struct
  4105. */
  4106. clp->cl_cons_state = NFS_CS_SESSION_INITING;
  4107. tbl = &session->fc_slot_table;
  4108. spin_lock_init(&tbl->slot_tbl_lock);
  4109. rpc_init_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
  4110. tbl = &session->bc_slot_table;
  4111. spin_lock_init(&tbl->slot_tbl_lock);
  4112. rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
  4113. session->clp = clp;
  4114. return session;
  4115. }
  4116. void nfs4_destroy_session(struct nfs4_session *session)
  4117. {
  4118. nfs4_proc_destroy_session(session);
  4119. dprintk("%s Destroy backchannel for xprt %p\n",
  4120. __func__, session->clp->cl_rpcclient->cl_xprt);
  4121. xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
  4122. NFS41_BC_MIN_CALLBACKS);
  4123. nfs4_destroy_slot_tables(session);
  4124. kfree(session);
  4125. }
  4126. /*
  4127. * Initialize the values to be used by the client in CREATE_SESSION
  4128. * If nfs4_init_session set the fore channel request and response sizes,
  4129. * use them.
  4130. *
  4131. * Set the back channel max_resp_sz_cached to zero to force the client to
  4132. * always set csa_cachethis to FALSE because the current implementation
  4133. * of the back channel DRC only supports caching the CB_SEQUENCE operation.
  4134. */
  4135. static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
  4136. {
  4137. struct nfs4_session *session = args->client->cl_session;
  4138. unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
  4139. mxresp_sz = session->fc_attrs.max_resp_sz;
  4140. if (mxrqst_sz == 0)
  4141. mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
  4142. if (mxresp_sz == 0)
  4143. mxresp_sz = NFS_MAX_FILE_IO_SIZE;
  4144. /* Fore channel attributes */
  4145. args->fc_attrs.headerpadsz = 0;
  4146. args->fc_attrs.max_rqst_sz = mxrqst_sz;
  4147. args->fc_attrs.max_resp_sz = mxresp_sz;
  4148. args->fc_attrs.max_resp_sz_cached = mxresp_sz;
  4149. args->fc_attrs.max_ops = NFS4_MAX_OPS;
  4150. args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
  4151. dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
  4152. "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
  4153. __func__,
  4154. args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
  4155. args->fc_attrs.max_resp_sz_cached, args->fc_attrs.max_ops,
  4156. args->fc_attrs.max_reqs);
  4157. /* Back channel attributes */
  4158. args->bc_attrs.headerpadsz = 0;
  4159. args->bc_attrs.max_rqst_sz = PAGE_SIZE;
  4160. args->bc_attrs.max_resp_sz = PAGE_SIZE;
  4161. args->bc_attrs.max_resp_sz_cached = 0;
  4162. args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
  4163. args->bc_attrs.max_reqs = 1;
  4164. dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
  4165. "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
  4166. __func__,
  4167. args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
  4168. args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
  4169. args->bc_attrs.max_reqs);
  4170. }
  4171. static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd)
  4172. {
  4173. if (rcvd <= sent)
  4174. return 0;
  4175. printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. "
  4176. "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd);
  4177. return -EINVAL;
  4178. }
  4179. #define _verify_fore_channel_attr(_name_) \
  4180. _verify_channel_attr("fore", #_name_, \
  4181. args->fc_attrs._name_, \
  4182. session->fc_attrs._name_)
  4183. #define _verify_back_channel_attr(_name_) \
  4184. _verify_channel_attr("back", #_name_, \
  4185. args->bc_attrs._name_, \
  4186. session->bc_attrs._name_)
  4187. /*
  4188. * The server is not allowed to increase the fore channel header pad size,
  4189. * maximum response size, or maximum number of operations.
  4190. *
  4191. * The back channel attributes are only negotiatied down: We send what the
  4192. * (back channel) server insists upon.
  4193. */
  4194. static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
  4195. struct nfs4_session *session)
  4196. {
  4197. int ret = 0;
  4198. ret |= _verify_fore_channel_attr(headerpadsz);
  4199. ret |= _verify_fore_channel_attr(max_resp_sz);
  4200. ret |= _verify_fore_channel_attr(max_ops);
  4201. ret |= _verify_back_channel_attr(headerpadsz);
  4202. ret |= _verify_back_channel_attr(max_rqst_sz);
  4203. ret |= _verify_back_channel_attr(max_resp_sz);
  4204. ret |= _verify_back_channel_attr(max_resp_sz_cached);
  4205. ret |= _verify_back_channel_attr(max_ops);
  4206. ret |= _verify_back_channel_attr(max_reqs);
  4207. return ret;
  4208. }
  4209. static int _nfs4_proc_create_session(struct nfs_client *clp)
  4210. {
  4211. struct nfs4_session *session = clp->cl_session;
  4212. struct nfs41_create_session_args args = {
  4213. .client = clp,
  4214. .cb_program = NFS4_CALLBACK,
  4215. };
  4216. struct nfs41_create_session_res res = {
  4217. .client = clp,
  4218. };
  4219. struct rpc_message msg = {
  4220. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
  4221. .rpc_argp = &args,
  4222. .rpc_resp = &res,
  4223. };
  4224. int status;
  4225. nfs4_init_channel_attrs(&args);
  4226. args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
  4227. status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
  4228. if (!status)
  4229. /* Verify the session's negotiated channel_attrs values */
  4230. status = nfs4_verify_channel_attrs(&args, session);
  4231. if (!status) {
  4232. /* Increment the clientid slot sequence id */
  4233. clp->cl_seqid++;
  4234. }
  4235. return status;
  4236. }
  4237. /*
  4238. * Issues a CREATE_SESSION operation to the server.
  4239. * It is the responsibility of the caller to verify the session is
  4240. * expired before calling this routine.
  4241. */
  4242. int nfs4_proc_create_session(struct nfs_client *clp, int reset)
  4243. {
  4244. int status;
  4245. unsigned *ptr;
  4246. struct nfs_fsinfo fsinfo;
  4247. struct nfs4_session *session = clp->cl_session;
  4248. dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
  4249. status = _nfs4_proc_create_session(clp);
  4250. if (status)
  4251. goto out;
  4252. /* Init or reset the fore channel */
  4253. if (reset)
  4254. status = nfs4_reset_slot_tables(session);
  4255. else
  4256. status = nfs4_init_slot_tables(session);
  4257. dprintk("fore channel slot table initialization returned %d\n", status);
  4258. if (status)
  4259. goto out;
  4260. ptr = (unsigned *)&session->sess_id.data[0];
  4261. dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
  4262. clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
  4263. if (reset)
  4264. /* Lease time is aleady set */
  4265. goto out;
  4266. /* Get the lease time */
  4267. status = nfs4_proc_get_lease_time(clp, &fsinfo);
  4268. if (status == 0) {
  4269. /* Update lease time and schedule renewal */
  4270. spin_lock(&clp->cl_lock);
  4271. clp->cl_lease_time = fsinfo.lease_time * HZ;
  4272. clp->cl_last_renewal = jiffies;
  4273. clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  4274. spin_unlock(&clp->cl_lock);
  4275. nfs4_schedule_state_renewal(clp);
  4276. }
  4277. out:
  4278. dprintk("<-- %s\n", __func__);
  4279. return status;
  4280. }
  4281. /*
  4282. * Issue the over-the-wire RPC DESTROY_SESSION.
  4283. * The caller must serialize access to this routine.
  4284. */
  4285. int nfs4_proc_destroy_session(struct nfs4_session *session)
  4286. {
  4287. int status = 0;
  4288. struct rpc_message msg;
  4289. dprintk("--> nfs4_proc_destroy_session\n");
  4290. /* session is still being setup */
  4291. if (session->clp->cl_cons_state != NFS_CS_READY)
  4292. return status;
  4293. msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
  4294. msg.rpc_argp = session;
  4295. msg.rpc_resp = NULL;
  4296. msg.rpc_cred = NULL;
  4297. status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
  4298. if (status)
  4299. printk(KERN_WARNING
  4300. "Got error %d from the server on DESTROY_SESSION. "
  4301. "Session has been destroyed regardless...\n", status);
  4302. dprintk("<-- nfs4_proc_destroy_session\n");
  4303. return status;
  4304. }
  4305. /*
  4306. * Renew the cl_session lease.
  4307. */
  4308. static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
  4309. {
  4310. struct nfs4_sequence_args args;
  4311. struct nfs4_sequence_res res;
  4312. struct rpc_message msg = {
  4313. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
  4314. .rpc_argp = &args,
  4315. .rpc_resp = &res,
  4316. .rpc_cred = cred,
  4317. };
  4318. args.sa_cache_this = 0;
  4319. return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args,
  4320. &res, 0);
  4321. }
  4322. void nfs41_sequence_call_done(struct rpc_task *task, void *data)
  4323. {
  4324. struct nfs_client *clp = (struct nfs_client *)data;
  4325. nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status);
  4326. if (task->tk_status < 0) {
  4327. dprintk("%s ERROR %d\n", __func__, task->tk_status);
  4328. if (_nfs4_async_handle_error(task, NULL, clp, NULL)
  4329. == -EAGAIN) {
  4330. nfs4_restart_rpc(task, clp);
  4331. return;
  4332. }
  4333. }
  4334. nfs41_sequence_free_slot(clp, task->tk_msg.rpc_resp);
  4335. dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
  4336. put_rpccred(task->tk_msg.rpc_cred);
  4337. kfree(task->tk_msg.rpc_argp);
  4338. kfree(task->tk_msg.rpc_resp);
  4339. dprintk("<-- %s\n", __func__);
  4340. }
  4341. static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
  4342. {
  4343. struct nfs_client *clp;
  4344. struct nfs4_sequence_args *args;
  4345. struct nfs4_sequence_res *res;
  4346. clp = (struct nfs_client *)data;
  4347. args = task->tk_msg.rpc_argp;
  4348. res = task->tk_msg.rpc_resp;
  4349. if (nfs4_setup_sequence(clp, args, res, 0, task))
  4350. return;
  4351. rpc_call_start(task);
  4352. }
  4353. static const struct rpc_call_ops nfs41_sequence_ops = {
  4354. .rpc_call_done = nfs41_sequence_call_done,
  4355. .rpc_call_prepare = nfs41_sequence_prepare,
  4356. };
  4357. static int nfs41_proc_async_sequence(struct nfs_client *clp,
  4358. struct rpc_cred *cred)
  4359. {
  4360. struct nfs4_sequence_args *args;
  4361. struct nfs4_sequence_res *res;
  4362. struct rpc_message msg = {
  4363. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
  4364. .rpc_cred = cred,
  4365. };
  4366. args = kzalloc(sizeof(*args), GFP_KERNEL);
  4367. if (!args)
  4368. return -ENOMEM;
  4369. res = kzalloc(sizeof(*res), GFP_KERNEL);
  4370. if (!res) {
  4371. kfree(args);
  4372. return -ENOMEM;
  4373. }
  4374. res->sr_slotid = NFS4_MAX_SLOT_TABLE;
  4375. msg.rpc_argp = args;
  4376. msg.rpc_resp = res;
  4377. return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
  4378. &nfs41_sequence_ops, (void *)clp);
  4379. }
  4380. #endif /* CONFIG_NFS_V4_1 */
  4381. struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
  4382. .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
  4383. .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
  4384. .recover_open = nfs4_open_reclaim,
  4385. .recover_lock = nfs4_lock_reclaim,
  4386. .establish_clid = nfs4_init_clientid,
  4387. .get_clid_cred = nfs4_get_setclientid_cred,
  4388. };
  4389. #if defined(CONFIG_NFS_V4_1)
  4390. struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
  4391. .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
  4392. .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
  4393. .recover_open = nfs4_open_reclaim,
  4394. .recover_lock = nfs4_lock_reclaim,
  4395. .establish_clid = nfs4_proc_exchange_id,
  4396. .get_clid_cred = nfs4_get_exchange_id_cred,
  4397. };
  4398. #endif /* CONFIG_NFS_V4_1 */
  4399. struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
  4400. .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
  4401. .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
  4402. .recover_open = nfs4_open_expired,
  4403. .recover_lock = nfs4_lock_expired,
  4404. .establish_clid = nfs4_init_clientid,
  4405. .get_clid_cred = nfs4_get_setclientid_cred,
  4406. };
  4407. #if defined(CONFIG_NFS_V4_1)
  4408. struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
  4409. .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
  4410. .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
  4411. .recover_open = nfs4_open_expired,
  4412. .recover_lock = nfs4_lock_expired,
  4413. .establish_clid = nfs4_proc_exchange_id,
  4414. .get_clid_cred = nfs4_get_exchange_id_cred,
  4415. };
  4416. #endif /* CONFIG_NFS_V4_1 */
  4417. struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
  4418. .sched_state_renewal = nfs4_proc_async_renew,
  4419. .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
  4420. .renew_lease = nfs4_proc_renew,
  4421. };
  4422. #if defined(CONFIG_NFS_V4_1)
  4423. struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
  4424. .sched_state_renewal = nfs41_proc_async_sequence,
  4425. .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
  4426. .renew_lease = nfs4_proc_sequence,
  4427. };
  4428. #endif
  4429. /*
  4430. * Per minor version reboot and network partition recovery ops
  4431. */
  4432. struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = {
  4433. &nfs40_reboot_recovery_ops,
  4434. #if defined(CONFIG_NFS_V4_1)
  4435. &nfs41_reboot_recovery_ops,
  4436. #endif
  4437. };
  4438. struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = {
  4439. &nfs40_nograce_recovery_ops,
  4440. #if defined(CONFIG_NFS_V4_1)
  4441. &nfs41_nograce_recovery_ops,
  4442. #endif
  4443. };
  4444. struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = {
  4445. &nfs40_state_renewal_ops,
  4446. #if defined(CONFIG_NFS_V4_1)
  4447. &nfs41_state_renewal_ops,
  4448. #endif
  4449. };
  4450. static const struct inode_operations nfs4_file_inode_operations = {
  4451. .permission = nfs_permission,
  4452. .getattr = nfs_getattr,
  4453. .setattr = nfs_setattr,
  4454. .getxattr = nfs4_getxattr,
  4455. .setxattr = nfs4_setxattr,
  4456. .listxattr = nfs4_listxattr,
  4457. };
  4458. const struct nfs_rpc_ops nfs_v4_clientops = {
  4459. .version = 4, /* protocol version */
  4460. .dentry_ops = &nfs4_dentry_operations,
  4461. .dir_inode_ops = &nfs4_dir_inode_operations,
  4462. .file_inode_ops = &nfs4_file_inode_operations,
  4463. .getroot = nfs4_proc_get_root,
  4464. .getattr = nfs4_proc_getattr,
  4465. .setattr = nfs4_proc_setattr,
  4466. .lookupfh = nfs4_proc_lookupfh,
  4467. .lookup = nfs4_proc_lookup,
  4468. .access = nfs4_proc_access,
  4469. .readlink = nfs4_proc_readlink,
  4470. .create = nfs4_proc_create,
  4471. .remove = nfs4_proc_remove,
  4472. .unlink_setup = nfs4_proc_unlink_setup,
  4473. .unlink_done = nfs4_proc_unlink_done,
  4474. .rename = nfs4_proc_rename,
  4475. .link = nfs4_proc_link,
  4476. .symlink = nfs4_proc_symlink,
  4477. .mkdir = nfs4_proc_mkdir,
  4478. .rmdir = nfs4_proc_remove,
  4479. .readdir = nfs4_proc_readdir,
  4480. .mknod = nfs4_proc_mknod,
  4481. .statfs = nfs4_proc_statfs,
  4482. .fsinfo = nfs4_proc_fsinfo,
  4483. .pathconf = nfs4_proc_pathconf,
  4484. .set_capabilities = nfs4_server_capabilities,
  4485. .decode_dirent = nfs4_decode_dirent,
  4486. .read_setup = nfs4_proc_read_setup,
  4487. .read_done = nfs4_read_done,
  4488. .write_setup = nfs4_proc_write_setup,
  4489. .write_done = nfs4_write_done,
  4490. .commit_setup = nfs4_proc_commit_setup,
  4491. .commit_done = nfs4_commit_done,
  4492. .lock = nfs4_proc_lock,
  4493. .clear_acl_cache = nfs4_zap_acl_attr,
  4494. .close_context = nfs4_close_context,
  4495. };
  4496. /*
  4497. * Local variables:
  4498. * c-basic-offset: 8
  4499. * End:
  4500. */