nfs4proc.c 135 KB

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