nfs4proc.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916
  1. /*
  2. * fs/nfs/nfs4proc.c
  3. *
  4. * Client-side procedure declarations for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. * Andy Adamson <andros@umich.edu>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of the University nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <linux/mm.h>
  38. #include <linux/utsname.h>
  39. #include <linux/delay.h>
  40. #include <linux/errno.h>
  41. #include <linux/string.h>
  42. #include <linux/sunrpc/clnt.h>
  43. #include <linux/nfs.h>
  44. #include <linux/nfs4.h>
  45. #include <linux/nfs_fs.h>
  46. #include <linux/nfs_page.h>
  47. #include <linux/smp_lock.h>
  48. #include <linux/namei.h>
  49. #include "nfs4_fs.h"
  50. #include "delegation.h"
  51. #define NFSDBG_FACILITY NFSDBG_PROC
  52. #define NFS4_POLL_RETRY_MIN (1*HZ)
  53. #define NFS4_POLL_RETRY_MAX (15*HZ)
  54. static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
  55. static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *);
  56. static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
  57. static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
  58. extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
  59. extern struct rpc_procinfo nfs4_procedures[];
  60. /* Prevent leaks of NFSv4 errors into userland */
  61. int nfs4_map_errors(int err)
  62. {
  63. if (err < -1000) {
  64. dprintk("%s could not handle NFSv4 error %d\n",
  65. __FUNCTION__, -err);
  66. return -EIO;
  67. }
  68. return err;
  69. }
  70. /*
  71. * This is our standard bitmap for GETATTR requests.
  72. */
  73. const u32 nfs4_fattr_bitmap[2] = {
  74. FATTR4_WORD0_TYPE
  75. | FATTR4_WORD0_CHANGE
  76. | FATTR4_WORD0_SIZE
  77. | FATTR4_WORD0_FSID
  78. | FATTR4_WORD0_FILEID,
  79. FATTR4_WORD1_MODE
  80. | FATTR4_WORD1_NUMLINKS
  81. | FATTR4_WORD1_OWNER
  82. | FATTR4_WORD1_OWNER_GROUP
  83. | FATTR4_WORD1_RAWDEV
  84. | FATTR4_WORD1_SPACE_USED
  85. | FATTR4_WORD1_TIME_ACCESS
  86. | FATTR4_WORD1_TIME_METADATA
  87. | FATTR4_WORD1_TIME_MODIFY
  88. };
  89. const u32 nfs4_statfs_bitmap[2] = {
  90. FATTR4_WORD0_FILES_AVAIL
  91. | FATTR4_WORD0_FILES_FREE
  92. | FATTR4_WORD0_FILES_TOTAL,
  93. FATTR4_WORD1_SPACE_AVAIL
  94. | FATTR4_WORD1_SPACE_FREE
  95. | FATTR4_WORD1_SPACE_TOTAL
  96. };
  97. const u32 nfs4_pathconf_bitmap[2] = {
  98. FATTR4_WORD0_MAXLINK
  99. | FATTR4_WORD0_MAXNAME,
  100. 0
  101. };
  102. const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
  103. | FATTR4_WORD0_MAXREAD
  104. | FATTR4_WORD0_MAXWRITE
  105. | FATTR4_WORD0_LEASE_TIME,
  106. 0
  107. };
  108. static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
  109. struct nfs4_readdir_arg *readdir)
  110. {
  111. u32 *start, *p;
  112. BUG_ON(readdir->count < 80);
  113. if (cookie > 2) {
  114. readdir->cookie = (cookie > 2) ? cookie : 0;
  115. memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
  116. return;
  117. }
  118. readdir->cookie = 0;
  119. memset(&readdir->verifier, 0, sizeof(readdir->verifier));
  120. if (cookie == 2)
  121. return;
  122. /*
  123. * NFSv4 servers do not return entries for '.' and '..'
  124. * Therefore, we fake these entries here. We let '.'
  125. * have cookie 0 and '..' have cookie 1. Note that
  126. * when talking to the server, we always send cookie 0
  127. * instead of 1 or 2.
  128. */
  129. start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0);
  130. if (cookie == 0) {
  131. *p++ = xdr_one; /* next */
  132. *p++ = xdr_zero; /* cookie, first word */
  133. *p++ = xdr_one; /* cookie, second word */
  134. *p++ = xdr_one; /* entry len */
  135. memcpy(p, ".\0\0\0", 4); /* entry */
  136. p++;
  137. *p++ = xdr_one; /* bitmap length */
  138. *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
  139. *p++ = htonl(8); /* attribute buffer length */
  140. p = xdr_encode_hyper(p, dentry->d_inode->i_ino);
  141. }
  142. *p++ = xdr_one; /* next */
  143. *p++ = xdr_zero; /* cookie, first word */
  144. *p++ = xdr_two; /* cookie, second word */
  145. *p++ = xdr_two; /* entry len */
  146. memcpy(p, "..\0\0", 4); /* entry */
  147. p++;
  148. *p++ = xdr_one; /* bitmap length */
  149. *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
  150. *p++ = htonl(8); /* attribute buffer length */
  151. p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino);
  152. readdir->pgbase = (char *)p - (char *)start;
  153. readdir->count -= readdir->pgbase;
  154. kunmap_atomic(start, KM_USER0);
  155. }
  156. static void
  157. renew_lease(struct nfs_server *server, unsigned long timestamp)
  158. {
  159. struct nfs4_client *clp = server->nfs4_state;
  160. spin_lock(&clp->cl_lock);
  161. if (time_before(clp->cl_last_renewal,timestamp))
  162. clp->cl_last_renewal = timestamp;
  163. spin_unlock(&clp->cl_lock);
  164. }
  165. static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo)
  166. {
  167. struct nfs_inode *nfsi = NFS_I(inode);
  168. if (cinfo->before == nfsi->change_attr && cinfo->atomic)
  169. nfsi->change_attr = cinfo->after;
  170. }
  171. static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
  172. {
  173. struct inode *inode = state->inode;
  174. open_flags &= (FMODE_READ|FMODE_WRITE);
  175. /* Protect against nfs4_find_state() */
  176. spin_lock(&inode->i_lock);
  177. state->state |= open_flags;
  178. /* NB! List reordering - see the reclaim code for why. */
  179. if ((open_flags & FMODE_WRITE) && 0 == state->nwriters++)
  180. list_move(&state->open_states, &state->owner->so_states);
  181. if (open_flags & FMODE_READ)
  182. state->nreaders++;
  183. memcpy(&state->stateid, stateid, sizeof(state->stateid));
  184. spin_unlock(&inode->i_lock);
  185. }
  186. /*
  187. * OPEN_RECLAIM:
  188. * reclaim state on the server after a reboot.
  189. * Assumes caller is holding the sp->so_sem
  190. */
  191. static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
  192. {
  193. struct inode *inode = state->inode;
  194. struct nfs_server *server = NFS_SERVER(inode);
  195. struct nfs_delegation *delegation = NFS_I(inode)->delegation;
  196. struct nfs_openargs o_arg = {
  197. .fh = NFS_FH(inode),
  198. .seqid = sp->so_seqid,
  199. .id = sp->so_id,
  200. .open_flags = state->state,
  201. .clientid = server->nfs4_state->cl_clientid,
  202. .claim = NFS4_OPEN_CLAIM_PREVIOUS,
  203. .bitmask = server->attr_bitmask,
  204. };
  205. struct nfs_openres o_res = {
  206. .server = server, /* Grrr */
  207. };
  208. struct rpc_message msg = {
  209. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
  210. .rpc_argp = &o_arg,
  211. .rpc_resp = &o_res,
  212. .rpc_cred = sp->so_cred,
  213. };
  214. int status;
  215. if (delegation != NULL) {
  216. if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
  217. memcpy(&state->stateid, &delegation->stateid,
  218. sizeof(state->stateid));
  219. set_bit(NFS_DELEGATED_STATE, &state->flags);
  220. return 0;
  221. }
  222. o_arg.u.delegation_type = delegation->type;
  223. }
  224. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  225. nfs4_increment_seqid(status, sp);
  226. if (status == 0) {
  227. memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
  228. if (o_res.delegation_type != 0) {
  229. nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
  230. /* Did the server issue an immediate delegation recall? */
  231. if (o_res.do_recall)
  232. nfs_async_inode_return_delegation(inode, &o_res.stateid);
  233. }
  234. }
  235. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  236. /* Ensure we update the inode attributes */
  237. NFS_CACHEINV(inode);
  238. return status;
  239. }
  240. static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
  241. {
  242. struct nfs_server *server = NFS_SERVER(state->inode);
  243. struct nfs4_exception exception = { };
  244. int err;
  245. do {
  246. err = _nfs4_open_reclaim(sp, state);
  247. switch (err) {
  248. case 0:
  249. case -NFS4ERR_STALE_CLIENTID:
  250. case -NFS4ERR_STALE_STATEID:
  251. case -NFS4ERR_EXPIRED:
  252. return err;
  253. }
  254. err = nfs4_handle_exception(server, err, &exception);
  255. } while (exception.retry);
  256. return err;
  257. }
  258. static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
  259. {
  260. struct nfs4_state_owner *sp = state->owner;
  261. struct inode *inode = dentry->d_inode;
  262. struct nfs_server *server = NFS_SERVER(inode);
  263. struct dentry *parent = dget_parent(dentry);
  264. struct nfs_openargs arg = {
  265. .fh = NFS_FH(parent->d_inode),
  266. .clientid = server->nfs4_state->cl_clientid,
  267. .name = &dentry->d_name,
  268. .id = sp->so_id,
  269. .server = server,
  270. .bitmask = server->attr_bitmask,
  271. .claim = NFS4_OPEN_CLAIM_DELEGATE_CUR,
  272. };
  273. struct nfs_openres res = {
  274. .server = server,
  275. };
  276. struct rpc_message msg = {
  277. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
  278. .rpc_argp = &arg,
  279. .rpc_resp = &res,
  280. .rpc_cred = sp->so_cred,
  281. };
  282. int status = 0;
  283. down(&sp->so_sema);
  284. if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
  285. goto out;
  286. if (state->state == 0)
  287. goto out;
  288. arg.seqid = sp->so_seqid;
  289. arg.open_flags = state->state;
  290. memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data));
  291. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  292. nfs4_increment_seqid(status, sp);
  293. if (status >= 0) {
  294. memcpy(state->stateid.data, res.stateid.data,
  295. sizeof(state->stateid.data));
  296. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  297. }
  298. out:
  299. up(&sp->so_sema);
  300. dput(parent);
  301. return status;
  302. }
  303. int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
  304. {
  305. struct nfs4_exception exception = { };
  306. struct nfs_server *server = NFS_SERVER(dentry->d_inode);
  307. int err;
  308. do {
  309. err = _nfs4_open_delegation_recall(dentry, state);
  310. switch (err) {
  311. case 0:
  312. return err;
  313. case -NFS4ERR_STALE_CLIENTID:
  314. case -NFS4ERR_STALE_STATEID:
  315. case -NFS4ERR_EXPIRED:
  316. /* Don't recall a delegation if it was lost */
  317. nfs4_schedule_state_recovery(server->nfs4_state);
  318. return err;
  319. }
  320. err = nfs4_handle_exception(server, err, &exception);
  321. } while (exception.retry);
  322. return err;
  323. }
  324. static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid)
  325. {
  326. struct nfs_open_confirmargs arg = {
  327. .fh = fh,
  328. .seqid = sp->so_seqid,
  329. .stateid = *stateid,
  330. };
  331. struct nfs_open_confirmres res;
  332. struct rpc_message msg = {
  333. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
  334. .rpc_argp = &arg,
  335. .rpc_resp = &res,
  336. .rpc_cred = sp->so_cred,
  337. };
  338. int status;
  339. status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR);
  340. nfs4_increment_seqid(status, sp);
  341. if (status >= 0)
  342. memcpy(stateid, &res.stateid, sizeof(*stateid));
  343. return status;
  344. }
  345. static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner *sp, struct nfs_openargs *o_arg, struct nfs_openres *o_res)
  346. {
  347. struct nfs_server *server = NFS_SERVER(dir);
  348. struct rpc_message msg = {
  349. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
  350. .rpc_argp = o_arg,
  351. .rpc_resp = o_res,
  352. .rpc_cred = sp->so_cred,
  353. };
  354. int status;
  355. /* Update sequence id. The caller must serialize! */
  356. o_arg->seqid = sp->so_seqid;
  357. o_arg->id = sp->so_id;
  358. o_arg->clientid = sp->so_client->cl_clientid;
  359. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  360. nfs4_increment_seqid(status, sp);
  361. if (status != 0)
  362. goto out;
  363. update_changeattr(dir, &o_res->cinfo);
  364. if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
  365. status = _nfs4_proc_open_confirm(server->client, &o_res->fh,
  366. sp, &o_res->stateid);
  367. if (status != 0)
  368. goto out;
  369. }
  370. if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
  371. status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
  372. out:
  373. return status;
  374. }
  375. static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
  376. {
  377. struct nfs_access_entry cache;
  378. int mask = 0;
  379. int status;
  380. if (openflags & FMODE_READ)
  381. mask |= MAY_READ;
  382. if (openflags & FMODE_WRITE)
  383. mask |= MAY_WRITE;
  384. status = nfs_access_get_cached(inode, cred, &cache);
  385. if (status == 0)
  386. goto out;
  387. /* Be clever: ask server to check for all possible rights */
  388. cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
  389. cache.cred = cred;
  390. cache.jiffies = jiffies;
  391. status = _nfs4_proc_access(inode, &cache);
  392. if (status != 0)
  393. return status;
  394. nfs_access_add_cache(inode, &cache);
  395. out:
  396. if ((cache.mask & mask) == mask)
  397. return 0;
  398. return -EACCES;
  399. }
  400. /*
  401. * OPEN_EXPIRED:
  402. * reclaim state on the server after a network partition.
  403. * Assumes caller holds the appropriate lock
  404. */
  405. static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
  406. {
  407. struct dentry *parent = dget_parent(dentry);
  408. struct inode *dir = parent->d_inode;
  409. struct inode *inode = state->inode;
  410. struct nfs_server *server = NFS_SERVER(dir);
  411. struct nfs_delegation *delegation = NFS_I(inode)->delegation;
  412. struct nfs_fattr f_attr = {
  413. .valid = 0,
  414. };
  415. struct nfs_openargs o_arg = {
  416. .fh = NFS_FH(dir),
  417. .open_flags = state->state,
  418. .name = &dentry->d_name,
  419. .bitmask = server->attr_bitmask,
  420. .claim = NFS4_OPEN_CLAIM_NULL,
  421. };
  422. struct nfs_openres o_res = {
  423. .f_attr = &f_attr,
  424. .server = server,
  425. };
  426. int status = 0;
  427. if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
  428. status = _nfs4_do_access(inode, sp->so_cred, state->state);
  429. if (status < 0)
  430. goto out;
  431. memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid));
  432. set_bit(NFS_DELEGATED_STATE, &state->flags);
  433. goto out;
  434. }
  435. status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
  436. if (status != 0)
  437. goto out_nodeleg;
  438. /* Check if files differ */
  439. if ((f_attr.mode & S_IFMT) != (inode->i_mode & S_IFMT))
  440. goto out_stale;
  441. /* Has the file handle changed? */
  442. if (nfs_compare_fh(&o_res.fh, NFS_FH(inode)) != 0) {
  443. /* Verify if the change attributes are the same */
  444. if (f_attr.change_attr != NFS_I(inode)->change_attr)
  445. goto out_stale;
  446. if (nfs_size_to_loff_t(f_attr.size) != inode->i_size)
  447. goto out_stale;
  448. /* Lets just pretend that this is the same file */
  449. nfs_copy_fh(NFS_FH(inode), &o_res.fh);
  450. NFS_I(inode)->fileid = f_attr.fileid;
  451. }
  452. memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
  453. if (o_res.delegation_type != 0) {
  454. if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM))
  455. nfs_inode_set_delegation(inode, sp->so_cred, &o_res);
  456. else
  457. nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
  458. }
  459. out_nodeleg:
  460. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  461. out:
  462. dput(parent);
  463. return status;
  464. out_stale:
  465. status = -ESTALE;
  466. /* Invalidate the state owner so we don't ever use it again */
  467. nfs4_drop_state_owner(sp);
  468. d_drop(dentry);
  469. /* Should we be trying to close that stateid? */
  470. goto out_nodeleg;
  471. }
  472. static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
  473. {
  474. struct nfs_inode *nfsi = NFS_I(state->inode);
  475. struct nfs_open_context *ctx;
  476. int status;
  477. spin_lock(&state->inode->i_lock);
  478. list_for_each_entry(ctx, &nfsi->open_files, list) {
  479. if (ctx->state != state)
  480. continue;
  481. get_nfs_open_context(ctx);
  482. spin_unlock(&state->inode->i_lock);
  483. status = _nfs4_open_expired(sp, state, ctx->dentry);
  484. put_nfs_open_context(ctx);
  485. return status;
  486. }
  487. spin_unlock(&state->inode->i_lock);
  488. return -ENOENT;
  489. }
  490. /*
  491. * Returns an nfs4_state + an extra reference to the inode
  492. */
  493. static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res)
  494. {
  495. struct nfs_delegation *delegation;
  496. struct nfs_server *server = NFS_SERVER(inode);
  497. struct nfs4_client *clp = server->nfs4_state;
  498. struct nfs_inode *nfsi = NFS_I(inode);
  499. struct nfs4_state_owner *sp = NULL;
  500. struct nfs4_state *state = NULL;
  501. int open_flags = flags & (FMODE_READ|FMODE_WRITE);
  502. int err;
  503. /* Protect against reboot recovery - NOTE ORDER! */
  504. down_read(&clp->cl_sem);
  505. /* Protect against delegation recall */
  506. down_read(&nfsi->rwsem);
  507. delegation = NFS_I(inode)->delegation;
  508. err = -ENOENT;
  509. if (delegation == NULL || (delegation->type & open_flags) != open_flags)
  510. goto out_err;
  511. err = -ENOMEM;
  512. if (!(sp = nfs4_get_state_owner(server, cred))) {
  513. dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
  514. goto out_err;
  515. }
  516. down(&sp->so_sema);
  517. state = nfs4_get_open_state(inode, sp);
  518. if (state == NULL)
  519. goto out_err;
  520. err = -ENOENT;
  521. if ((state->state & open_flags) == open_flags) {
  522. spin_lock(&inode->i_lock);
  523. if (open_flags & FMODE_READ)
  524. state->nreaders++;
  525. if (open_flags & FMODE_WRITE)
  526. state->nwriters++;
  527. spin_unlock(&inode->i_lock);
  528. goto out_ok;
  529. } else if (state->state != 0)
  530. goto out_err;
  531. lock_kernel();
  532. err = _nfs4_do_access(inode, cred, open_flags);
  533. unlock_kernel();
  534. if (err != 0)
  535. goto out_err;
  536. set_bit(NFS_DELEGATED_STATE, &state->flags);
  537. update_open_stateid(state, &delegation->stateid, open_flags);
  538. out_ok:
  539. up(&sp->so_sema);
  540. nfs4_put_state_owner(sp);
  541. up_read(&nfsi->rwsem);
  542. up_read(&clp->cl_sem);
  543. igrab(inode);
  544. *res = state;
  545. return 0;
  546. out_err:
  547. if (sp != NULL) {
  548. if (state != NULL)
  549. nfs4_put_open_state(state);
  550. up(&sp->so_sema);
  551. nfs4_put_state_owner(sp);
  552. }
  553. up_read(&nfsi->rwsem);
  554. up_read(&clp->cl_sem);
  555. return err;
  556. }
  557. static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred)
  558. {
  559. struct nfs4_exception exception = { };
  560. struct nfs4_state *res;
  561. int err;
  562. do {
  563. err = _nfs4_open_delegated(inode, flags, cred, &res);
  564. if (err == 0)
  565. break;
  566. res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode),
  567. err, &exception));
  568. } while (exception.retry);
  569. return res;
  570. }
  571. /*
  572. * Returns an nfs4_state + an referenced inode
  573. */
  574. static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
  575. {
  576. struct nfs4_state_owner *sp;
  577. struct nfs4_state *state = NULL;
  578. struct nfs_server *server = NFS_SERVER(dir);
  579. struct nfs4_client *clp = server->nfs4_state;
  580. struct inode *inode = NULL;
  581. int status;
  582. struct nfs_fattr f_attr = {
  583. .valid = 0,
  584. };
  585. struct nfs_openargs o_arg = {
  586. .fh = NFS_FH(dir),
  587. .open_flags = flags,
  588. .name = &dentry->d_name,
  589. .server = server,
  590. .bitmask = server->attr_bitmask,
  591. .claim = NFS4_OPEN_CLAIM_NULL,
  592. };
  593. struct nfs_openres o_res = {
  594. .f_attr = &f_attr,
  595. .server = server,
  596. };
  597. /* Protect against reboot recovery conflicts */
  598. down_read(&clp->cl_sem);
  599. status = -ENOMEM;
  600. if (!(sp = nfs4_get_state_owner(server, cred))) {
  601. dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
  602. goto out_err;
  603. }
  604. if (flags & O_EXCL) {
  605. u32 *p = (u32 *) o_arg.u.verifier.data;
  606. p[0] = jiffies;
  607. p[1] = current->pid;
  608. } else
  609. o_arg.u.attrs = sattr;
  610. /* Serialization for the sequence id */
  611. down(&sp->so_sema);
  612. status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
  613. if (status != 0)
  614. goto out_err;
  615. status = -ENOMEM;
  616. inode = nfs_fhget(dir->i_sb, &o_res.fh, &f_attr);
  617. if (!inode)
  618. goto out_err;
  619. state = nfs4_get_open_state(inode, sp);
  620. if (!state)
  621. goto out_err;
  622. update_open_stateid(state, &o_res.stateid, flags);
  623. if (o_res.delegation_type != 0)
  624. nfs_inode_set_delegation(inode, cred, &o_res);
  625. up(&sp->so_sema);
  626. nfs4_put_state_owner(sp);
  627. up_read(&clp->cl_sem);
  628. *res = state;
  629. return 0;
  630. out_err:
  631. if (sp != NULL) {
  632. if (state != NULL)
  633. nfs4_put_open_state(state);
  634. up(&sp->so_sema);
  635. nfs4_put_state_owner(sp);
  636. }
  637. /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
  638. up_read(&clp->cl_sem);
  639. if (inode != NULL)
  640. iput(inode);
  641. *res = NULL;
  642. return status;
  643. }
  644. static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred)
  645. {
  646. struct nfs4_exception exception = { };
  647. struct nfs4_state *res;
  648. int status;
  649. do {
  650. status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res);
  651. if (status == 0)
  652. break;
  653. /* NOTE: BAD_SEQID means the server and client disagree about the
  654. * book-keeping w.r.t. state-changing operations
  655. * (OPEN/CLOSE/LOCK/LOCKU...)
  656. * It is actually a sign of a bug on the client or on the server.
  657. *
  658. * If we receive a BAD_SEQID error in the particular case of
  659. * doing an OPEN, we assume that nfs4_increment_seqid() will
  660. * have unhashed the old state_owner for us, and that we can
  661. * therefore safely retry using a new one. We should still warn
  662. * the user though...
  663. */
  664. if (status == -NFS4ERR_BAD_SEQID) {
  665. printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n");
  666. exception.retry = 1;
  667. continue;
  668. }
  669. res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
  670. status, &exception));
  671. } while (exception.retry);
  672. return res;
  673. }
  674. static int _nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
  675. struct nfs_fh *fhandle, struct iattr *sattr,
  676. struct nfs4_state *state)
  677. {
  678. struct nfs_setattrargs arg = {
  679. .fh = fhandle,
  680. .iap = sattr,
  681. .server = server,
  682. .bitmask = server->attr_bitmask,
  683. };
  684. struct nfs_setattrres res = {
  685. .fattr = fattr,
  686. .server = server,
  687. };
  688. struct rpc_message msg = {
  689. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
  690. .rpc_argp = &arg,
  691. .rpc_resp = &res,
  692. };
  693. fattr->valid = 0;
  694. if (state != NULL)
  695. msg.rpc_cred = state->owner->so_cred;
  696. if (sattr->ia_valid & ATTR_SIZE)
  697. nfs4_copy_stateid(&arg.stateid, state, NULL);
  698. else
  699. memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
  700. return rpc_call_sync(server->client, &msg, 0);
  701. }
  702. static int nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
  703. struct nfs_fh *fhandle, struct iattr *sattr,
  704. struct nfs4_state *state)
  705. {
  706. struct nfs4_exception exception = { };
  707. int err;
  708. do {
  709. err = nfs4_handle_exception(server,
  710. _nfs4_do_setattr(server, fattr, fhandle, sattr,
  711. state),
  712. &exception);
  713. } while (exception.retry);
  714. return err;
  715. }
  716. struct nfs4_closedata {
  717. struct inode *inode;
  718. struct nfs4_state *state;
  719. struct nfs_closeargs arg;
  720. struct nfs_closeres res;
  721. };
  722. static void nfs4_close_done(struct rpc_task *task)
  723. {
  724. struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
  725. struct nfs4_state *state = calldata->state;
  726. struct nfs4_state_owner *sp = state->owner;
  727. struct nfs_server *server = NFS_SERVER(calldata->inode);
  728. /* hmm. we are done with the inode, and in the process of freeing
  729. * the state_owner. we keep this around to process errors
  730. */
  731. nfs4_increment_seqid(task->tk_status, sp);
  732. switch (task->tk_status) {
  733. case 0:
  734. memcpy(&state->stateid, &calldata->res.stateid,
  735. sizeof(state->stateid));
  736. break;
  737. case -NFS4ERR_STALE_STATEID:
  738. case -NFS4ERR_EXPIRED:
  739. state->state = calldata->arg.open_flags;
  740. nfs4_schedule_state_recovery(server->nfs4_state);
  741. break;
  742. default:
  743. if (nfs4_async_handle_error(task, server) == -EAGAIN) {
  744. rpc_restart_call(task);
  745. return;
  746. }
  747. }
  748. state->state = calldata->arg.open_flags;
  749. nfs4_put_open_state(state);
  750. up(&sp->so_sema);
  751. nfs4_put_state_owner(sp);
  752. up_read(&server->nfs4_state->cl_sem);
  753. kfree(calldata);
  754. }
  755. static inline int nfs4_close_call(struct rpc_clnt *clnt, struct nfs4_closedata *calldata)
  756. {
  757. struct rpc_message msg = {
  758. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
  759. .rpc_argp = &calldata->arg,
  760. .rpc_resp = &calldata->res,
  761. .rpc_cred = calldata->state->owner->so_cred,
  762. };
  763. if (calldata->arg.open_flags != 0)
  764. msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
  765. return rpc_call_async(clnt, &msg, 0, nfs4_close_done, calldata);
  766. }
  767. /*
  768. * It is possible for data to be read/written from a mem-mapped file
  769. * after the sys_close call (which hits the vfs layer as a flush).
  770. * This means that we can't safely call nfsv4 close on a file until
  771. * the inode is cleared. This in turn means that we are not good
  772. * NFSv4 citizens - we do not indicate to the server to update the file's
  773. * share state even when we are done with one of the three share
  774. * stateid's in the inode.
  775. *
  776. * NOTE: Caller must be holding the sp->so_owner semaphore!
  777. */
  778. int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode)
  779. {
  780. struct nfs4_closedata *calldata;
  781. int status;
  782. /* Tell caller we're done */
  783. if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
  784. state->state = mode;
  785. return 0;
  786. }
  787. calldata = (struct nfs4_closedata *)kmalloc(sizeof(*calldata), GFP_KERNEL);
  788. if (calldata == NULL)
  789. return -ENOMEM;
  790. calldata->inode = inode;
  791. calldata->state = state;
  792. calldata->arg.fh = NFS_FH(inode);
  793. /* Serialization for the sequence id */
  794. calldata->arg.seqid = state->owner->so_seqid;
  795. calldata->arg.open_flags = mode;
  796. memcpy(&calldata->arg.stateid, &state->stateid,
  797. sizeof(calldata->arg.stateid));
  798. status = nfs4_close_call(NFS_SERVER(inode)->client, calldata);
  799. /*
  800. * Return -EINPROGRESS on success in order to indicate to the
  801. * caller that an asynchronous RPC call has been launched, and
  802. * that it will release the semaphores on completion.
  803. */
  804. return (status == 0) ? -EINPROGRESS : status;
  805. }
  806. struct inode *
  807. nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
  808. {
  809. struct iattr attr;
  810. struct rpc_cred *cred;
  811. struct nfs4_state *state;
  812. if (nd->flags & LOOKUP_CREATE) {
  813. attr.ia_mode = nd->intent.open.create_mode;
  814. attr.ia_valid = ATTR_MODE;
  815. if (!IS_POSIXACL(dir))
  816. attr.ia_mode &= ~current->fs->umask;
  817. } else {
  818. attr.ia_valid = 0;
  819. BUG_ON(nd->intent.open.flags & O_CREAT);
  820. }
  821. cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
  822. if (IS_ERR(cred))
  823. return (struct inode *)cred;
  824. state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
  825. put_rpccred(cred);
  826. if (IS_ERR(state))
  827. return (struct inode *)state;
  828. return state->inode;
  829. }
  830. int
  831. nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags)
  832. {
  833. struct rpc_cred *cred;
  834. struct nfs4_state *state;
  835. struct inode *inode;
  836. cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
  837. if (IS_ERR(cred))
  838. return PTR_ERR(cred);
  839. state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
  840. if (IS_ERR(state))
  841. state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
  842. put_rpccred(cred);
  843. if (state == ERR_PTR(-ENOENT) && dentry->d_inode == 0)
  844. return 1;
  845. if (IS_ERR(state))
  846. return 0;
  847. inode = state->inode;
  848. if (inode == dentry->d_inode) {
  849. iput(inode);
  850. return 1;
  851. }
  852. d_drop(dentry);
  853. nfs4_close_state(state, openflags);
  854. iput(inode);
  855. return 0;
  856. }
  857. static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
  858. {
  859. struct nfs4_server_caps_res res = {};
  860. struct rpc_message msg = {
  861. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
  862. .rpc_argp = fhandle,
  863. .rpc_resp = &res,
  864. };
  865. int status;
  866. status = rpc_call_sync(server->client, &msg, 0);
  867. if (status == 0) {
  868. memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
  869. if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
  870. server->caps |= NFS_CAP_ACLS;
  871. if (res.has_links != 0)
  872. server->caps |= NFS_CAP_HARDLINKS;
  873. if (res.has_symlinks != 0)
  874. server->caps |= NFS_CAP_SYMLINKS;
  875. server->acl_bitmask = res.acl_bitmask;
  876. }
  877. return status;
  878. }
  879. static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
  880. {
  881. struct nfs4_exception exception = { };
  882. int err;
  883. do {
  884. err = nfs4_handle_exception(server,
  885. _nfs4_server_capabilities(server, fhandle),
  886. &exception);
  887. } while (exception.retry);
  888. return err;
  889. }
  890. static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
  891. struct nfs_fsinfo *info)
  892. {
  893. struct nfs_fattr * fattr = info->fattr;
  894. struct nfs4_lookup_root_arg args = {
  895. .bitmask = nfs4_fattr_bitmap,
  896. };
  897. struct nfs4_lookup_res res = {
  898. .server = server,
  899. .fattr = fattr,
  900. .fh = fhandle,
  901. };
  902. struct rpc_message msg = {
  903. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
  904. .rpc_argp = &args,
  905. .rpc_resp = &res,
  906. };
  907. fattr->valid = 0;
  908. return rpc_call_sync(server->client, &msg, 0);
  909. }
  910. static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
  911. struct nfs_fsinfo *info)
  912. {
  913. struct nfs4_exception exception = { };
  914. int err;
  915. do {
  916. err = nfs4_handle_exception(server,
  917. _nfs4_lookup_root(server, fhandle, info),
  918. &exception);
  919. } while (exception.retry);
  920. return err;
  921. }
  922. static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  923. struct nfs_fsinfo *info)
  924. {
  925. struct nfs_fattr * fattr = info->fattr;
  926. unsigned char * p;
  927. struct qstr q;
  928. struct nfs4_lookup_arg args = {
  929. .dir_fh = fhandle,
  930. .name = &q,
  931. .bitmask = nfs4_fattr_bitmap,
  932. };
  933. struct nfs4_lookup_res res = {
  934. .server = server,
  935. .fattr = fattr,
  936. .fh = fhandle,
  937. };
  938. struct rpc_message msg = {
  939. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
  940. .rpc_argp = &args,
  941. .rpc_resp = &res,
  942. };
  943. int status;
  944. /*
  945. * Now we do a separate LOOKUP for each component of the mount path.
  946. * The LOOKUPs are done separately so that we can conveniently
  947. * catch an ERR_WRONGSEC if it occurs along the way...
  948. */
  949. status = nfs4_lookup_root(server, fhandle, info);
  950. if (status)
  951. goto out;
  952. p = server->mnt_path;
  953. for (;;) {
  954. struct nfs4_exception exception = { };
  955. while (*p == '/')
  956. p++;
  957. if (!*p)
  958. break;
  959. q.name = p;
  960. while (*p && (*p != '/'))
  961. p++;
  962. q.len = p - q.name;
  963. do {
  964. fattr->valid = 0;
  965. status = nfs4_handle_exception(server,
  966. rpc_call_sync(server->client, &msg, 0),
  967. &exception);
  968. } while (exception.retry);
  969. if (status == 0)
  970. continue;
  971. if (status == -ENOENT) {
  972. printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path);
  973. printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n");
  974. }
  975. break;
  976. }
  977. if (status == 0)
  978. status = nfs4_server_capabilities(server, fhandle);
  979. if (status == 0)
  980. status = nfs4_do_fsinfo(server, fhandle, info);
  981. out:
  982. return status;
  983. }
  984. static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  985. {
  986. struct nfs4_getattr_arg args = {
  987. .fh = fhandle,
  988. .bitmask = server->attr_bitmask,
  989. };
  990. struct nfs4_getattr_res res = {
  991. .fattr = fattr,
  992. .server = server,
  993. };
  994. struct rpc_message msg = {
  995. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
  996. .rpc_argp = &args,
  997. .rpc_resp = &res,
  998. };
  999. fattr->valid = 0;
  1000. return rpc_call_sync(server->client, &msg, 0);
  1001. }
  1002. static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  1003. {
  1004. struct nfs4_exception exception = { };
  1005. int err;
  1006. do {
  1007. err = nfs4_handle_exception(server,
  1008. _nfs4_proc_getattr(server, fhandle, fattr),
  1009. &exception);
  1010. } while (exception.retry);
  1011. return err;
  1012. }
  1013. /*
  1014. * The file is not closed if it is opened due to the a request to change
  1015. * the size of the file. The open call will not be needed once the
  1016. * VFS layer lookup-intents are implemented.
  1017. *
  1018. * Close is called when the inode is destroyed.
  1019. * If we haven't opened the file for O_WRONLY, we
  1020. * need to in the size_change case to obtain a stateid.
  1021. *
  1022. * Got race?
  1023. * Because OPEN is always done by name in nfsv4, it is
  1024. * possible that we opened a different file by the same
  1025. * name. We can recognize this race condition, but we
  1026. * can't do anything about it besides returning an error.
  1027. *
  1028. * This will be fixed with VFS changes (lookup-intent).
  1029. */
  1030. static int
  1031. nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
  1032. struct iattr *sattr)
  1033. {
  1034. struct inode * inode = dentry->d_inode;
  1035. int size_change = sattr->ia_valid & ATTR_SIZE;
  1036. struct nfs4_state *state = NULL;
  1037. int need_iput = 0;
  1038. int status;
  1039. fattr->valid = 0;
  1040. if (size_change) {
  1041. struct rpc_cred *cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
  1042. if (IS_ERR(cred))
  1043. return PTR_ERR(cred);
  1044. state = nfs4_find_state(inode, cred, FMODE_WRITE);
  1045. if (state == NULL) {
  1046. state = nfs4_open_delegated(dentry->d_inode,
  1047. FMODE_WRITE, cred);
  1048. if (IS_ERR(state))
  1049. state = nfs4_do_open(dentry->d_parent->d_inode,
  1050. dentry, FMODE_WRITE,
  1051. NULL, cred);
  1052. need_iput = 1;
  1053. }
  1054. put_rpccred(cred);
  1055. if (IS_ERR(state))
  1056. return PTR_ERR(state);
  1057. if (state->inode != inode) {
  1058. printk(KERN_WARNING "nfs: raced in setattr (%p != %p), returning -EIO\n", inode, state->inode);
  1059. status = -EIO;
  1060. goto out;
  1061. }
  1062. }
  1063. status = nfs4_do_setattr(NFS_SERVER(inode), fattr,
  1064. NFS_FH(inode), sattr, state);
  1065. out:
  1066. if (state) {
  1067. inode = state->inode;
  1068. nfs4_close_state(state, FMODE_WRITE);
  1069. if (need_iput)
  1070. iput(inode);
  1071. }
  1072. return status;
  1073. }
  1074. static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
  1075. struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  1076. {
  1077. int status;
  1078. struct nfs_server *server = NFS_SERVER(dir);
  1079. struct nfs4_lookup_arg args = {
  1080. .bitmask = server->attr_bitmask,
  1081. .dir_fh = NFS_FH(dir),
  1082. .name = name,
  1083. };
  1084. struct nfs4_lookup_res res = {
  1085. .server = server,
  1086. .fattr = fattr,
  1087. .fh = fhandle,
  1088. };
  1089. struct rpc_message msg = {
  1090. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
  1091. .rpc_argp = &args,
  1092. .rpc_resp = &res,
  1093. };
  1094. fattr->valid = 0;
  1095. dprintk("NFS call lookup %s\n", name->name);
  1096. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1097. dprintk("NFS reply lookup: %d\n", status);
  1098. return status;
  1099. }
  1100. static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
  1101. {
  1102. struct nfs4_exception exception = { };
  1103. int err;
  1104. do {
  1105. err = nfs4_handle_exception(NFS_SERVER(dir),
  1106. _nfs4_proc_lookup(dir, name, fhandle, fattr),
  1107. &exception);
  1108. } while (exception.retry);
  1109. return err;
  1110. }
  1111. static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  1112. {
  1113. struct nfs4_accessargs args = {
  1114. .fh = NFS_FH(inode),
  1115. };
  1116. struct nfs4_accessres res = { 0 };
  1117. struct rpc_message msg = {
  1118. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
  1119. .rpc_argp = &args,
  1120. .rpc_resp = &res,
  1121. .rpc_cred = entry->cred,
  1122. };
  1123. int mode = entry->mask;
  1124. int status;
  1125. /*
  1126. * Determine which access bits we want to ask for...
  1127. */
  1128. if (mode & MAY_READ)
  1129. args.access |= NFS4_ACCESS_READ;
  1130. if (S_ISDIR(inode->i_mode)) {
  1131. if (mode & MAY_WRITE)
  1132. args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
  1133. if (mode & MAY_EXEC)
  1134. args.access |= NFS4_ACCESS_LOOKUP;
  1135. } else {
  1136. if (mode & MAY_WRITE)
  1137. args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
  1138. if (mode & MAY_EXEC)
  1139. args.access |= NFS4_ACCESS_EXECUTE;
  1140. }
  1141. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  1142. if (!status) {
  1143. entry->mask = 0;
  1144. if (res.access & NFS4_ACCESS_READ)
  1145. entry->mask |= MAY_READ;
  1146. if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
  1147. entry->mask |= MAY_WRITE;
  1148. if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
  1149. entry->mask |= MAY_EXEC;
  1150. }
  1151. return status;
  1152. }
  1153. static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
  1154. {
  1155. struct nfs4_exception exception = { };
  1156. int err;
  1157. do {
  1158. err = nfs4_handle_exception(NFS_SERVER(inode),
  1159. _nfs4_proc_access(inode, entry),
  1160. &exception);
  1161. } while (exception.retry);
  1162. return err;
  1163. }
  1164. /*
  1165. * TODO: For the time being, we don't try to get any attributes
  1166. * along with any of the zero-copy operations READ, READDIR,
  1167. * READLINK, WRITE.
  1168. *
  1169. * In the case of the first three, we want to put the GETATTR
  1170. * after the read-type operation -- this is because it is hard
  1171. * to predict the length of a GETATTR response in v4, and thus
  1172. * align the READ data correctly. This means that the GETATTR
  1173. * may end up partially falling into the page cache, and we should
  1174. * shift it into the 'tail' of the xdr_buf before processing.
  1175. * To do this efficiently, we need to know the total length
  1176. * of data received, which doesn't seem to be available outside
  1177. * of the RPC layer.
  1178. *
  1179. * In the case of WRITE, we also want to put the GETATTR after
  1180. * the operation -- in this case because we want to make sure
  1181. * we get the post-operation mtime and size. This means that
  1182. * we can't use xdr_encode_pages() as written: we need a variant
  1183. * of it which would leave room in the 'tail' iovec.
  1184. *
  1185. * Both of these changes to the XDR layer would in fact be quite
  1186. * minor, but I decided to leave them for a subsequent patch.
  1187. */
  1188. static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
  1189. unsigned int pgbase, unsigned int pglen)
  1190. {
  1191. struct nfs4_readlink args = {
  1192. .fh = NFS_FH(inode),
  1193. .pgbase = pgbase,
  1194. .pglen = pglen,
  1195. .pages = &page,
  1196. };
  1197. struct rpc_message msg = {
  1198. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
  1199. .rpc_argp = &args,
  1200. .rpc_resp = NULL,
  1201. };
  1202. return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  1203. }
  1204. static int nfs4_proc_readlink(struct inode *inode, struct page *page,
  1205. unsigned int pgbase, unsigned int pglen)
  1206. {
  1207. struct nfs4_exception exception = { };
  1208. int err;
  1209. do {
  1210. err = nfs4_handle_exception(NFS_SERVER(inode),
  1211. _nfs4_proc_readlink(inode, page, pgbase, pglen),
  1212. &exception);
  1213. } while (exception.retry);
  1214. return err;
  1215. }
  1216. static int _nfs4_proc_read(struct nfs_read_data *rdata)
  1217. {
  1218. int flags = rdata->flags;
  1219. struct inode *inode = rdata->inode;
  1220. struct nfs_fattr *fattr = rdata->res.fattr;
  1221. struct nfs_server *server = NFS_SERVER(inode);
  1222. struct rpc_message msg = {
  1223. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
  1224. .rpc_argp = &rdata->args,
  1225. .rpc_resp = &rdata->res,
  1226. .rpc_cred = rdata->cred,
  1227. };
  1228. unsigned long timestamp = jiffies;
  1229. int status;
  1230. dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
  1231. (long long) rdata->args.offset);
  1232. fattr->valid = 0;
  1233. status = rpc_call_sync(server->client, &msg, flags);
  1234. if (!status)
  1235. renew_lease(server, timestamp);
  1236. dprintk("NFS reply read: %d\n", status);
  1237. return status;
  1238. }
  1239. static int nfs4_proc_read(struct nfs_read_data *rdata)
  1240. {
  1241. struct nfs4_exception exception = { };
  1242. int err;
  1243. do {
  1244. err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
  1245. _nfs4_proc_read(rdata),
  1246. &exception);
  1247. } while (exception.retry);
  1248. return err;
  1249. }
  1250. static int _nfs4_proc_write(struct nfs_write_data *wdata)
  1251. {
  1252. int rpcflags = wdata->flags;
  1253. struct inode *inode = wdata->inode;
  1254. struct nfs_fattr *fattr = wdata->res.fattr;
  1255. struct nfs_server *server = NFS_SERVER(inode);
  1256. struct rpc_message msg = {
  1257. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
  1258. .rpc_argp = &wdata->args,
  1259. .rpc_resp = &wdata->res,
  1260. .rpc_cred = wdata->cred,
  1261. };
  1262. int status;
  1263. dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
  1264. (long long) wdata->args.offset);
  1265. fattr->valid = 0;
  1266. status = rpc_call_sync(server->client, &msg, rpcflags);
  1267. dprintk("NFS reply write: %d\n", status);
  1268. return status;
  1269. }
  1270. static int nfs4_proc_write(struct nfs_write_data *wdata)
  1271. {
  1272. struct nfs4_exception exception = { };
  1273. int err;
  1274. do {
  1275. err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
  1276. _nfs4_proc_write(wdata),
  1277. &exception);
  1278. } while (exception.retry);
  1279. return err;
  1280. }
  1281. static int _nfs4_proc_commit(struct nfs_write_data *cdata)
  1282. {
  1283. struct inode *inode = cdata->inode;
  1284. struct nfs_fattr *fattr = cdata->res.fattr;
  1285. struct nfs_server *server = NFS_SERVER(inode);
  1286. struct rpc_message msg = {
  1287. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
  1288. .rpc_argp = &cdata->args,
  1289. .rpc_resp = &cdata->res,
  1290. .rpc_cred = cdata->cred,
  1291. };
  1292. int status;
  1293. dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
  1294. (long long) cdata->args.offset);
  1295. fattr->valid = 0;
  1296. status = rpc_call_sync(server->client, &msg, 0);
  1297. dprintk("NFS reply commit: %d\n", status);
  1298. return status;
  1299. }
  1300. static int nfs4_proc_commit(struct nfs_write_data *cdata)
  1301. {
  1302. struct nfs4_exception exception = { };
  1303. int err;
  1304. do {
  1305. err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
  1306. _nfs4_proc_commit(cdata),
  1307. &exception);
  1308. } while (exception.retry);
  1309. return err;
  1310. }
  1311. /*
  1312. * Got race?
  1313. * We will need to arrange for the VFS layer to provide an atomic open.
  1314. * Until then, this create/open method is prone to inefficiency and race
  1315. * conditions due to the lookup, create, and open VFS calls from sys_open()
  1316. * placed on the wire.
  1317. *
  1318. * Given the above sorry state of affairs, I'm simply sending an OPEN.
  1319. * The file will be opened again in the subsequent VFS open call
  1320. * (nfs4_proc_file_open).
  1321. *
  1322. * The open for read will just hang around to be used by any process that
  1323. * opens the file O_RDONLY. This will all be resolved with the VFS changes.
  1324. */
  1325. static int
  1326. nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
  1327. int flags)
  1328. {
  1329. struct nfs4_state *state;
  1330. struct rpc_cred *cred;
  1331. int status = 0;
  1332. cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
  1333. if (IS_ERR(cred)) {
  1334. status = PTR_ERR(cred);
  1335. goto out;
  1336. }
  1337. state = nfs4_do_open(dir, dentry, flags, sattr, cred);
  1338. put_rpccred(cred);
  1339. if (IS_ERR(state)) {
  1340. status = PTR_ERR(state);
  1341. goto out;
  1342. }
  1343. d_instantiate(dentry, state->inode);
  1344. if (flags & O_EXCL) {
  1345. struct nfs_fattr fattr;
  1346. status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
  1347. NFS_FH(state->inode), sattr, state);
  1348. if (status == 0)
  1349. goto out;
  1350. } else if (flags != 0)
  1351. goto out;
  1352. nfs4_close_state(state, flags);
  1353. out:
  1354. return status;
  1355. }
  1356. static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
  1357. {
  1358. struct nfs4_remove_arg args = {
  1359. .fh = NFS_FH(dir),
  1360. .name = name,
  1361. };
  1362. struct nfs4_change_info res;
  1363. struct rpc_message msg = {
  1364. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
  1365. .rpc_argp = &args,
  1366. .rpc_resp = &res,
  1367. };
  1368. int status;
  1369. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1370. if (status == 0)
  1371. update_changeattr(dir, &res);
  1372. return status;
  1373. }
  1374. static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
  1375. {
  1376. struct nfs4_exception exception = { };
  1377. int err;
  1378. do {
  1379. err = nfs4_handle_exception(NFS_SERVER(dir),
  1380. _nfs4_proc_remove(dir, name),
  1381. &exception);
  1382. } while (exception.retry);
  1383. return err;
  1384. }
  1385. struct unlink_desc {
  1386. struct nfs4_remove_arg args;
  1387. struct nfs4_change_info res;
  1388. };
  1389. static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,
  1390. struct qstr *name)
  1391. {
  1392. struct unlink_desc *up;
  1393. up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);
  1394. if (!up)
  1395. return -ENOMEM;
  1396. up->args.fh = NFS_FH(dir->d_inode);
  1397. up->args.name = name;
  1398. msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
  1399. msg->rpc_argp = &up->args;
  1400. msg->rpc_resp = &up->res;
  1401. return 0;
  1402. }
  1403. static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
  1404. {
  1405. struct rpc_message *msg = &task->tk_msg;
  1406. struct unlink_desc *up;
  1407. if (msg->rpc_resp != NULL) {
  1408. up = container_of(msg->rpc_resp, struct unlink_desc, res);
  1409. update_changeattr(dir->d_inode, &up->res);
  1410. kfree(up);
  1411. msg->rpc_resp = NULL;
  1412. msg->rpc_argp = NULL;
  1413. }
  1414. return 0;
  1415. }
  1416. static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
  1417. struct inode *new_dir, struct qstr *new_name)
  1418. {
  1419. struct nfs4_rename_arg arg = {
  1420. .old_dir = NFS_FH(old_dir),
  1421. .new_dir = NFS_FH(new_dir),
  1422. .old_name = old_name,
  1423. .new_name = new_name,
  1424. };
  1425. struct nfs4_rename_res res = { };
  1426. struct rpc_message msg = {
  1427. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
  1428. .rpc_argp = &arg,
  1429. .rpc_resp = &res,
  1430. };
  1431. int status;
  1432. status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
  1433. if (!status) {
  1434. update_changeattr(old_dir, &res.old_cinfo);
  1435. update_changeattr(new_dir, &res.new_cinfo);
  1436. }
  1437. return status;
  1438. }
  1439. static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
  1440. struct inode *new_dir, struct qstr *new_name)
  1441. {
  1442. struct nfs4_exception exception = { };
  1443. int err;
  1444. do {
  1445. err = nfs4_handle_exception(NFS_SERVER(old_dir),
  1446. _nfs4_proc_rename(old_dir, old_name,
  1447. new_dir, new_name),
  1448. &exception);
  1449. } while (exception.retry);
  1450. return err;
  1451. }
  1452. static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  1453. {
  1454. struct nfs4_link_arg arg = {
  1455. .fh = NFS_FH(inode),
  1456. .dir_fh = NFS_FH(dir),
  1457. .name = name,
  1458. };
  1459. struct nfs4_change_info cinfo = { };
  1460. struct rpc_message msg = {
  1461. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
  1462. .rpc_argp = &arg,
  1463. .rpc_resp = &cinfo,
  1464. };
  1465. int status;
  1466. status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  1467. if (!status)
  1468. update_changeattr(dir, &cinfo);
  1469. return status;
  1470. }
  1471. static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
  1472. {
  1473. struct nfs4_exception exception = { };
  1474. int err;
  1475. do {
  1476. err = nfs4_handle_exception(NFS_SERVER(inode),
  1477. _nfs4_proc_link(inode, dir, name),
  1478. &exception);
  1479. } while (exception.retry);
  1480. return err;
  1481. }
  1482. static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name,
  1483. struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
  1484. struct nfs_fattr *fattr)
  1485. {
  1486. struct nfs_server *server = NFS_SERVER(dir);
  1487. struct nfs4_create_arg arg = {
  1488. .dir_fh = NFS_FH(dir),
  1489. .server = server,
  1490. .name = name,
  1491. .attrs = sattr,
  1492. .ftype = NF4LNK,
  1493. .bitmask = server->attr_bitmask,
  1494. };
  1495. struct nfs4_create_res res = {
  1496. .server = server,
  1497. .fh = fhandle,
  1498. .fattr = fattr,
  1499. };
  1500. struct rpc_message msg = {
  1501. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
  1502. .rpc_argp = &arg,
  1503. .rpc_resp = &res,
  1504. };
  1505. int status;
  1506. if (path->len > NFS4_MAXPATHLEN)
  1507. return -ENAMETOOLONG;
  1508. arg.u.symlink = path;
  1509. fattr->valid = 0;
  1510. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1511. if (!status)
  1512. update_changeattr(dir, &res.dir_cinfo);
  1513. return status;
  1514. }
  1515. static int nfs4_proc_symlink(struct inode *dir, struct qstr *name,
  1516. struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
  1517. struct nfs_fattr *fattr)
  1518. {
  1519. struct nfs4_exception exception = { };
  1520. int err;
  1521. do {
  1522. err = nfs4_handle_exception(NFS_SERVER(dir),
  1523. _nfs4_proc_symlink(dir, name, path, sattr,
  1524. fhandle, fattr),
  1525. &exception);
  1526. } while (exception.retry);
  1527. return err;
  1528. }
  1529. static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
  1530. struct iattr *sattr)
  1531. {
  1532. struct nfs_server *server = NFS_SERVER(dir);
  1533. struct nfs_fh fhandle;
  1534. struct nfs_fattr fattr;
  1535. struct nfs4_create_arg arg = {
  1536. .dir_fh = NFS_FH(dir),
  1537. .server = server,
  1538. .name = &dentry->d_name,
  1539. .attrs = sattr,
  1540. .ftype = NF4DIR,
  1541. .bitmask = server->attr_bitmask,
  1542. };
  1543. struct nfs4_create_res res = {
  1544. .server = server,
  1545. .fh = &fhandle,
  1546. .fattr = &fattr,
  1547. };
  1548. struct rpc_message msg = {
  1549. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
  1550. .rpc_argp = &arg,
  1551. .rpc_resp = &res,
  1552. };
  1553. int status;
  1554. fattr.valid = 0;
  1555. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1556. if (!status) {
  1557. update_changeattr(dir, &res.dir_cinfo);
  1558. status = nfs_instantiate(dentry, &fhandle, &fattr);
  1559. }
  1560. return status;
  1561. }
  1562. static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
  1563. struct iattr *sattr)
  1564. {
  1565. struct nfs4_exception exception = { };
  1566. int err;
  1567. do {
  1568. err = nfs4_handle_exception(NFS_SERVER(dir),
  1569. _nfs4_proc_mkdir(dir, dentry, sattr),
  1570. &exception);
  1571. } while (exception.retry);
  1572. return err;
  1573. }
  1574. static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  1575. u64 cookie, struct page *page, unsigned int count, int plus)
  1576. {
  1577. struct inode *dir = dentry->d_inode;
  1578. struct nfs4_readdir_arg args = {
  1579. .fh = NFS_FH(dir),
  1580. .pages = &page,
  1581. .pgbase = 0,
  1582. .count = count,
  1583. .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
  1584. };
  1585. struct nfs4_readdir_res res;
  1586. struct rpc_message msg = {
  1587. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
  1588. .rpc_argp = &args,
  1589. .rpc_resp = &res,
  1590. .rpc_cred = cred,
  1591. };
  1592. int status;
  1593. lock_kernel();
  1594. nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
  1595. res.pgbase = args.pgbase;
  1596. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1597. if (status == 0)
  1598. memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
  1599. unlock_kernel();
  1600. return status;
  1601. }
  1602. static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
  1603. u64 cookie, struct page *page, unsigned int count, int plus)
  1604. {
  1605. struct nfs4_exception exception = { };
  1606. int err;
  1607. do {
  1608. err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
  1609. _nfs4_proc_readdir(dentry, cred, cookie,
  1610. page, count, plus),
  1611. &exception);
  1612. } while (exception.retry);
  1613. return err;
  1614. }
  1615. static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
  1616. struct iattr *sattr, dev_t rdev)
  1617. {
  1618. struct nfs_server *server = NFS_SERVER(dir);
  1619. struct nfs_fh fh;
  1620. struct nfs_fattr fattr;
  1621. struct nfs4_create_arg arg = {
  1622. .dir_fh = NFS_FH(dir),
  1623. .server = server,
  1624. .name = &dentry->d_name,
  1625. .attrs = sattr,
  1626. .bitmask = server->attr_bitmask,
  1627. };
  1628. struct nfs4_create_res res = {
  1629. .server = server,
  1630. .fh = &fh,
  1631. .fattr = &fattr,
  1632. };
  1633. struct rpc_message msg = {
  1634. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
  1635. .rpc_argp = &arg,
  1636. .rpc_resp = &res,
  1637. };
  1638. int status;
  1639. int mode = sattr->ia_mode;
  1640. fattr.valid = 0;
  1641. BUG_ON(!(sattr->ia_valid & ATTR_MODE));
  1642. BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
  1643. if (S_ISFIFO(mode))
  1644. arg.ftype = NF4FIFO;
  1645. else if (S_ISBLK(mode)) {
  1646. arg.ftype = NF4BLK;
  1647. arg.u.device.specdata1 = MAJOR(rdev);
  1648. arg.u.device.specdata2 = MINOR(rdev);
  1649. }
  1650. else if (S_ISCHR(mode)) {
  1651. arg.ftype = NF4CHR;
  1652. arg.u.device.specdata1 = MAJOR(rdev);
  1653. arg.u.device.specdata2 = MINOR(rdev);
  1654. }
  1655. else
  1656. arg.ftype = NF4SOCK;
  1657. status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
  1658. if (status == 0) {
  1659. update_changeattr(dir, &res.dir_cinfo);
  1660. status = nfs_instantiate(dentry, &fh, &fattr);
  1661. }
  1662. return status;
  1663. }
  1664. static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
  1665. struct iattr *sattr, dev_t rdev)
  1666. {
  1667. struct nfs4_exception exception = { };
  1668. int err;
  1669. do {
  1670. err = nfs4_handle_exception(NFS_SERVER(dir),
  1671. _nfs4_proc_mknod(dir, dentry, sattr, rdev),
  1672. &exception);
  1673. } while (exception.retry);
  1674. return err;
  1675. }
  1676. static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
  1677. struct nfs_fsstat *fsstat)
  1678. {
  1679. struct nfs4_statfs_arg args = {
  1680. .fh = fhandle,
  1681. .bitmask = server->attr_bitmask,
  1682. };
  1683. struct rpc_message msg = {
  1684. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
  1685. .rpc_argp = &args,
  1686. .rpc_resp = fsstat,
  1687. };
  1688. fsstat->fattr->valid = 0;
  1689. return rpc_call_sync(server->client, &msg, 0);
  1690. }
  1691. static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
  1692. {
  1693. struct nfs4_exception exception = { };
  1694. int err;
  1695. do {
  1696. err = nfs4_handle_exception(server,
  1697. _nfs4_proc_statfs(server, fhandle, fsstat),
  1698. &exception);
  1699. } while (exception.retry);
  1700. return err;
  1701. }
  1702. static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
  1703. struct nfs_fsinfo *fsinfo)
  1704. {
  1705. struct nfs4_fsinfo_arg args = {
  1706. .fh = fhandle,
  1707. .bitmask = server->attr_bitmask,
  1708. };
  1709. struct rpc_message msg = {
  1710. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
  1711. .rpc_argp = &args,
  1712. .rpc_resp = fsinfo,
  1713. };
  1714. return rpc_call_sync(server->client, &msg, 0);
  1715. }
  1716. static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
  1717. {
  1718. struct nfs4_exception exception = { };
  1719. int err;
  1720. do {
  1721. err = nfs4_handle_exception(server,
  1722. _nfs4_do_fsinfo(server, fhandle, fsinfo),
  1723. &exception);
  1724. } while (exception.retry);
  1725. return err;
  1726. }
  1727. static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
  1728. {
  1729. fsinfo->fattr->valid = 0;
  1730. return nfs4_do_fsinfo(server, fhandle, fsinfo);
  1731. }
  1732. static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  1733. struct nfs_pathconf *pathconf)
  1734. {
  1735. struct nfs4_pathconf_arg args = {
  1736. .fh = fhandle,
  1737. .bitmask = server->attr_bitmask,
  1738. };
  1739. struct rpc_message msg = {
  1740. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
  1741. .rpc_argp = &args,
  1742. .rpc_resp = pathconf,
  1743. };
  1744. /* None of the pathconf attributes are mandatory to implement */
  1745. if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
  1746. memset(pathconf, 0, sizeof(*pathconf));
  1747. return 0;
  1748. }
  1749. pathconf->fattr->valid = 0;
  1750. return rpc_call_sync(server->client, &msg, 0);
  1751. }
  1752. static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
  1753. struct nfs_pathconf *pathconf)
  1754. {
  1755. struct nfs4_exception exception = { };
  1756. int err;
  1757. do {
  1758. err = nfs4_handle_exception(server,
  1759. _nfs4_proc_pathconf(server, fhandle, pathconf),
  1760. &exception);
  1761. } while (exception.retry);
  1762. return err;
  1763. }
  1764. static void
  1765. nfs4_read_done(struct rpc_task *task)
  1766. {
  1767. struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
  1768. struct inode *inode = data->inode;
  1769. if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
  1770. rpc_restart_call(task);
  1771. return;
  1772. }
  1773. if (task->tk_status > 0)
  1774. renew_lease(NFS_SERVER(inode), data->timestamp);
  1775. /* Call back common NFS readpage processing */
  1776. nfs_readpage_result(task);
  1777. }
  1778. static void
  1779. nfs4_proc_read_setup(struct nfs_read_data *data)
  1780. {
  1781. struct rpc_task *task = &data->task;
  1782. struct rpc_message msg = {
  1783. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
  1784. .rpc_argp = &data->args,
  1785. .rpc_resp = &data->res,
  1786. .rpc_cred = data->cred,
  1787. };
  1788. struct inode *inode = data->inode;
  1789. int flags;
  1790. data->timestamp = jiffies;
  1791. /* N.B. Do we need to test? Never called for swapfile inode */
  1792. flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
  1793. /* Finalize the task. */
  1794. rpc_init_task(task, NFS_CLIENT(inode), nfs4_read_done, flags);
  1795. rpc_call_setup(task, &msg, 0);
  1796. }
  1797. static void
  1798. nfs4_write_done(struct rpc_task *task)
  1799. {
  1800. struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
  1801. struct inode *inode = data->inode;
  1802. if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
  1803. rpc_restart_call(task);
  1804. return;
  1805. }
  1806. if (task->tk_status >= 0)
  1807. renew_lease(NFS_SERVER(inode), data->timestamp);
  1808. /* Call back common NFS writeback processing */
  1809. nfs_writeback_done(task);
  1810. }
  1811. static void
  1812. nfs4_proc_write_setup(struct nfs_write_data *data, int how)
  1813. {
  1814. struct rpc_task *task = &data->task;
  1815. struct rpc_message msg = {
  1816. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
  1817. .rpc_argp = &data->args,
  1818. .rpc_resp = &data->res,
  1819. .rpc_cred = data->cred,
  1820. };
  1821. struct inode *inode = data->inode;
  1822. int stable;
  1823. int flags;
  1824. if (how & FLUSH_STABLE) {
  1825. if (!NFS_I(inode)->ncommit)
  1826. stable = NFS_FILE_SYNC;
  1827. else
  1828. stable = NFS_DATA_SYNC;
  1829. } else
  1830. stable = NFS_UNSTABLE;
  1831. data->args.stable = stable;
  1832. data->timestamp = jiffies;
  1833. /* Set the initial flags for the task. */
  1834. flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
  1835. /* Finalize the task. */
  1836. rpc_init_task(task, NFS_CLIENT(inode), nfs4_write_done, flags);
  1837. rpc_call_setup(task, &msg, 0);
  1838. }
  1839. static void
  1840. nfs4_commit_done(struct rpc_task *task)
  1841. {
  1842. struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
  1843. struct inode *inode = data->inode;
  1844. if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
  1845. rpc_restart_call(task);
  1846. return;
  1847. }
  1848. /* Call back common NFS writeback processing */
  1849. nfs_commit_done(task);
  1850. }
  1851. static void
  1852. nfs4_proc_commit_setup(struct nfs_write_data *data, int how)
  1853. {
  1854. struct rpc_task *task = &data->task;
  1855. struct rpc_message msg = {
  1856. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
  1857. .rpc_argp = &data->args,
  1858. .rpc_resp = &data->res,
  1859. .rpc_cred = data->cred,
  1860. };
  1861. struct inode *inode = data->inode;
  1862. int flags;
  1863. /* Set the initial flags for the task. */
  1864. flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
  1865. /* Finalize the task. */
  1866. rpc_init_task(task, NFS_CLIENT(inode), nfs4_commit_done, flags);
  1867. rpc_call_setup(task, &msg, 0);
  1868. }
  1869. /*
  1870. * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
  1871. * standalone procedure for queueing an asynchronous RENEW.
  1872. */
  1873. static void
  1874. renew_done(struct rpc_task *task)
  1875. {
  1876. struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp;
  1877. unsigned long timestamp = (unsigned long)task->tk_calldata;
  1878. if (task->tk_status < 0) {
  1879. switch (task->tk_status) {
  1880. case -NFS4ERR_STALE_CLIENTID:
  1881. case -NFS4ERR_EXPIRED:
  1882. case -NFS4ERR_CB_PATH_DOWN:
  1883. nfs4_schedule_state_recovery(clp);
  1884. }
  1885. return;
  1886. }
  1887. spin_lock(&clp->cl_lock);
  1888. if (time_before(clp->cl_last_renewal,timestamp))
  1889. clp->cl_last_renewal = timestamp;
  1890. spin_unlock(&clp->cl_lock);
  1891. }
  1892. int
  1893. nfs4_proc_async_renew(struct nfs4_client *clp)
  1894. {
  1895. struct rpc_message msg = {
  1896. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
  1897. .rpc_argp = clp,
  1898. .rpc_cred = clp->cl_cred,
  1899. };
  1900. return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
  1901. renew_done, (void *)jiffies);
  1902. }
  1903. int
  1904. nfs4_proc_renew(struct nfs4_client *clp)
  1905. {
  1906. struct rpc_message msg = {
  1907. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
  1908. .rpc_argp = clp,
  1909. .rpc_cred = clp->cl_cred,
  1910. };
  1911. unsigned long now = jiffies;
  1912. int status;
  1913. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  1914. if (status < 0)
  1915. return status;
  1916. spin_lock(&clp->cl_lock);
  1917. if (time_before(clp->cl_last_renewal,now))
  1918. clp->cl_last_renewal = now;
  1919. spin_unlock(&clp->cl_lock);
  1920. return 0;
  1921. }
  1922. /*
  1923. * We will need to arrange for the VFS layer to provide an atomic open.
  1924. * Until then, this open method is prone to inefficiency and race conditions
  1925. * due to the lookup, potential create, and open VFS calls from sys_open()
  1926. * placed on the wire.
  1927. */
  1928. static int
  1929. nfs4_proc_file_open(struct inode *inode, struct file *filp)
  1930. {
  1931. struct dentry *dentry = filp->f_dentry;
  1932. struct nfs_open_context *ctx;
  1933. struct nfs4_state *state = NULL;
  1934. struct rpc_cred *cred;
  1935. int status = -ENOMEM;
  1936. dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n",
  1937. (int)dentry->d_parent->d_name.len,
  1938. dentry->d_parent->d_name.name,
  1939. (int)dentry->d_name.len, dentry->d_name.name);
  1940. /* Find our open stateid */
  1941. cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
  1942. if (IS_ERR(cred))
  1943. return PTR_ERR(cred);
  1944. ctx = alloc_nfs_open_context(dentry, cred);
  1945. put_rpccred(cred);
  1946. if (unlikely(ctx == NULL))
  1947. return -ENOMEM;
  1948. status = -EIO; /* ERACE actually */
  1949. state = nfs4_find_state(inode, cred, filp->f_mode);
  1950. if (unlikely(state == NULL))
  1951. goto no_state;
  1952. ctx->state = state;
  1953. nfs4_close_state(state, filp->f_mode);
  1954. ctx->mode = filp->f_mode;
  1955. nfs_file_set_open_context(filp, ctx);
  1956. put_nfs_open_context(ctx);
  1957. if (filp->f_mode & FMODE_WRITE)
  1958. nfs_begin_data_update(inode);
  1959. return 0;
  1960. no_state:
  1961. printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__);
  1962. put_nfs_open_context(ctx);
  1963. return status;
  1964. }
  1965. /*
  1966. * Release our state
  1967. */
  1968. static int
  1969. nfs4_proc_file_release(struct inode *inode, struct file *filp)
  1970. {
  1971. if (filp->f_mode & FMODE_WRITE)
  1972. nfs_end_data_update(inode);
  1973. nfs_file_clear_open_context(filp);
  1974. return 0;
  1975. }
  1976. static inline int nfs4_server_supports_acls(struct nfs_server *server)
  1977. {
  1978. return (server->caps & NFS_CAP_ACLS)
  1979. && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
  1980. && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
  1981. }
  1982. /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
  1983. * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
  1984. * the stack.
  1985. */
  1986. #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
  1987. static void buf_to_pages(const void *buf, size_t buflen,
  1988. struct page **pages, unsigned int *pgbase)
  1989. {
  1990. const void *p = buf;
  1991. *pgbase = offset_in_page(buf);
  1992. p -= *pgbase;
  1993. while (p < buf + buflen) {
  1994. *(pages++) = virt_to_page(p);
  1995. p += PAGE_CACHE_SIZE;
  1996. }
  1997. }
  1998. static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
  1999. {
  2000. struct nfs_server *server = NFS_SERVER(inode);
  2001. struct page *pages[NFS4ACL_MAXPAGES];
  2002. struct nfs_getaclargs args = {
  2003. .fh = NFS_FH(inode),
  2004. .acl_pages = pages,
  2005. .acl_len = buflen,
  2006. };
  2007. size_t resp_len = buflen;
  2008. struct rpc_message msg = {
  2009. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
  2010. .rpc_argp = &args,
  2011. .rpc_resp = &resp_len,
  2012. };
  2013. int ret;
  2014. if (!nfs4_server_supports_acls(server))
  2015. return -EOPNOTSUPP;
  2016. buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
  2017. ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  2018. if (buflen && resp_len > buflen)
  2019. return -ERANGE;
  2020. if (ret == 0)
  2021. ret = resp_len;
  2022. return ret;
  2023. }
  2024. static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
  2025. {
  2026. struct nfs_server *server = NFS_SERVER(inode);
  2027. struct page *pages[NFS4ACL_MAXPAGES];
  2028. struct nfs_setaclargs arg = {
  2029. .fh = NFS_FH(inode),
  2030. .acl_pages = pages,
  2031. .acl_len = buflen,
  2032. };
  2033. struct rpc_message msg = {
  2034. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
  2035. .rpc_argp = &arg,
  2036. .rpc_resp = NULL,
  2037. };
  2038. int ret;
  2039. if (!nfs4_server_supports_acls(server))
  2040. return -EOPNOTSUPP;
  2041. buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
  2042. ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
  2043. return ret;
  2044. }
  2045. static int
  2046. nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server)
  2047. {
  2048. struct nfs4_client *clp = server->nfs4_state;
  2049. if (!clp || task->tk_status >= 0)
  2050. return 0;
  2051. switch(task->tk_status) {
  2052. case -NFS4ERR_STALE_CLIENTID:
  2053. case -NFS4ERR_STALE_STATEID:
  2054. case -NFS4ERR_EXPIRED:
  2055. rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL);
  2056. nfs4_schedule_state_recovery(clp);
  2057. if (test_bit(NFS4CLNT_OK, &clp->cl_state))
  2058. rpc_wake_up_task(task);
  2059. task->tk_status = 0;
  2060. return -EAGAIN;
  2061. case -NFS4ERR_GRACE:
  2062. case -NFS4ERR_DELAY:
  2063. rpc_delay(task, NFS4_POLL_RETRY_MAX);
  2064. task->tk_status = 0;
  2065. return -EAGAIN;
  2066. case -NFS4ERR_OLD_STATEID:
  2067. task->tk_status = 0;
  2068. return -EAGAIN;
  2069. }
  2070. task->tk_status = nfs4_map_errors(task->tk_status);
  2071. return 0;
  2072. }
  2073. static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp)
  2074. {
  2075. DEFINE_WAIT(wait);
  2076. sigset_t oldset;
  2077. int interruptible, res = 0;
  2078. might_sleep();
  2079. rpc_clnt_sigmask(clnt, &oldset);
  2080. interruptible = TASK_UNINTERRUPTIBLE;
  2081. if (clnt->cl_intr)
  2082. interruptible = TASK_INTERRUPTIBLE;
  2083. prepare_to_wait(&clp->cl_waitq, &wait, interruptible);
  2084. nfs4_schedule_state_recovery(clp);
  2085. if (clnt->cl_intr && signalled())
  2086. res = -ERESTARTSYS;
  2087. else if (!test_bit(NFS4CLNT_OK, &clp->cl_state))
  2088. schedule();
  2089. finish_wait(&clp->cl_waitq, &wait);
  2090. rpc_clnt_sigunmask(clnt, &oldset);
  2091. return res;
  2092. }
  2093. static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
  2094. {
  2095. sigset_t oldset;
  2096. int res = 0;
  2097. might_sleep();
  2098. if (*timeout <= 0)
  2099. *timeout = NFS4_POLL_RETRY_MIN;
  2100. if (*timeout > NFS4_POLL_RETRY_MAX)
  2101. *timeout = NFS4_POLL_RETRY_MAX;
  2102. rpc_clnt_sigmask(clnt, &oldset);
  2103. if (clnt->cl_intr) {
  2104. set_current_state(TASK_INTERRUPTIBLE);
  2105. schedule_timeout(*timeout);
  2106. if (signalled())
  2107. res = -ERESTARTSYS;
  2108. } else {
  2109. set_current_state(TASK_UNINTERRUPTIBLE);
  2110. schedule_timeout(*timeout);
  2111. }
  2112. rpc_clnt_sigunmask(clnt, &oldset);
  2113. *timeout <<= 1;
  2114. return res;
  2115. }
  2116. /* This is the error handling routine for processes that are allowed
  2117. * to sleep.
  2118. */
  2119. int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
  2120. {
  2121. struct nfs4_client *clp = server->nfs4_state;
  2122. int ret = errorcode;
  2123. exception->retry = 0;
  2124. switch(errorcode) {
  2125. case 0:
  2126. return 0;
  2127. case -NFS4ERR_STALE_CLIENTID:
  2128. case -NFS4ERR_STALE_STATEID:
  2129. case -NFS4ERR_EXPIRED:
  2130. ret = nfs4_wait_clnt_recover(server->client, clp);
  2131. if (ret == 0)
  2132. exception->retry = 1;
  2133. break;
  2134. case -NFS4ERR_GRACE:
  2135. case -NFS4ERR_DELAY:
  2136. ret = nfs4_delay(server->client, &exception->timeout);
  2137. if (ret == 0)
  2138. exception->retry = 1;
  2139. break;
  2140. case -NFS4ERR_OLD_STATEID:
  2141. if (ret == 0)
  2142. exception->retry = 1;
  2143. }
  2144. /* We failed to handle the error */
  2145. return nfs4_map_errors(ret);
  2146. }
  2147. int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
  2148. {
  2149. nfs4_verifier sc_verifier;
  2150. struct nfs4_setclientid setclientid = {
  2151. .sc_verifier = &sc_verifier,
  2152. .sc_prog = program,
  2153. };
  2154. struct rpc_message msg = {
  2155. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
  2156. .rpc_argp = &setclientid,
  2157. .rpc_resp = clp,
  2158. .rpc_cred = clp->cl_cred,
  2159. };
  2160. u32 *p;
  2161. int loop = 0;
  2162. int status;
  2163. p = (u32*)sc_verifier.data;
  2164. *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
  2165. *p = htonl((u32)clp->cl_boot_time.tv_nsec);
  2166. for(;;) {
  2167. setclientid.sc_name_len = scnprintf(setclientid.sc_name,
  2168. sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
  2169. clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
  2170. clp->cl_cred->cr_ops->cr_name,
  2171. clp->cl_id_uniquifier);
  2172. setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
  2173. sizeof(setclientid.sc_netid), "tcp");
  2174. setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
  2175. sizeof(setclientid.sc_uaddr), "%s.%d.%d",
  2176. clp->cl_ipaddr, port >> 8, port & 255);
  2177. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  2178. if (status != -NFS4ERR_CLID_INUSE)
  2179. break;
  2180. if (signalled())
  2181. break;
  2182. if (loop++ & 1)
  2183. ssleep(clp->cl_lease_time + 1);
  2184. else
  2185. if (++clp->cl_id_uniquifier == 0)
  2186. break;
  2187. }
  2188. return status;
  2189. }
  2190. int
  2191. nfs4_proc_setclientid_confirm(struct nfs4_client *clp)
  2192. {
  2193. struct nfs_fsinfo fsinfo;
  2194. struct rpc_message msg = {
  2195. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
  2196. .rpc_argp = clp,
  2197. .rpc_resp = &fsinfo,
  2198. .rpc_cred = clp->cl_cred,
  2199. };
  2200. unsigned long now;
  2201. int status;
  2202. now = jiffies;
  2203. status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
  2204. if (status == 0) {
  2205. spin_lock(&clp->cl_lock);
  2206. clp->cl_lease_time = fsinfo.lease_time * HZ;
  2207. clp->cl_last_renewal = now;
  2208. spin_unlock(&clp->cl_lock);
  2209. }
  2210. return status;
  2211. }
  2212. static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
  2213. {
  2214. struct nfs4_delegreturnargs args = {
  2215. .fhandle = NFS_FH(inode),
  2216. .stateid = stateid,
  2217. };
  2218. struct rpc_message msg = {
  2219. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
  2220. .rpc_argp = &args,
  2221. .rpc_cred = cred,
  2222. };
  2223. return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
  2224. }
  2225. int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
  2226. {
  2227. struct nfs_server *server = NFS_SERVER(inode);
  2228. struct nfs4_exception exception = { };
  2229. int err;
  2230. do {
  2231. err = _nfs4_proc_delegreturn(inode, cred, stateid);
  2232. switch (err) {
  2233. case -NFS4ERR_STALE_STATEID:
  2234. case -NFS4ERR_EXPIRED:
  2235. nfs4_schedule_state_recovery(server->nfs4_state);
  2236. case 0:
  2237. return 0;
  2238. }
  2239. err = nfs4_handle_exception(server, err, &exception);
  2240. } while (exception.retry);
  2241. return err;
  2242. }
  2243. #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
  2244. #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
  2245. /*
  2246. * sleep, with exponential backoff, and retry the LOCK operation.
  2247. */
  2248. static unsigned long
  2249. nfs4_set_lock_task_retry(unsigned long timeout)
  2250. {
  2251. current->state = TASK_INTERRUPTIBLE;
  2252. schedule_timeout(timeout);
  2253. timeout <<= 1;
  2254. if (timeout > NFS4_LOCK_MAXTIMEOUT)
  2255. return NFS4_LOCK_MAXTIMEOUT;
  2256. return timeout;
  2257. }
  2258. static inline int
  2259. nfs4_lck_type(int cmd, struct file_lock *request)
  2260. {
  2261. /* set lock type */
  2262. switch (request->fl_type) {
  2263. case F_RDLCK:
  2264. return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
  2265. case F_WRLCK:
  2266. return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
  2267. case F_UNLCK:
  2268. return NFS4_WRITE_LT;
  2269. }
  2270. BUG();
  2271. return 0;
  2272. }
  2273. static inline uint64_t
  2274. nfs4_lck_length(struct file_lock *request)
  2275. {
  2276. if (request->fl_end == OFFSET_MAX)
  2277. return ~(uint64_t)0;
  2278. return request->fl_end - request->fl_start + 1;
  2279. }
  2280. static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  2281. {
  2282. struct inode *inode = state->inode;
  2283. struct nfs_server *server = NFS_SERVER(inode);
  2284. struct nfs4_client *clp = server->nfs4_state;
  2285. struct nfs_lockargs arg = {
  2286. .fh = NFS_FH(inode),
  2287. .type = nfs4_lck_type(cmd, request),
  2288. .offset = request->fl_start,
  2289. .length = nfs4_lck_length(request),
  2290. };
  2291. struct nfs_lockres res = {
  2292. .server = server,
  2293. };
  2294. struct rpc_message msg = {
  2295. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
  2296. .rpc_argp = &arg,
  2297. .rpc_resp = &res,
  2298. .rpc_cred = state->owner->so_cred,
  2299. };
  2300. struct nfs_lowner nlo;
  2301. struct nfs4_lock_state *lsp;
  2302. int status;
  2303. down_read(&clp->cl_sem);
  2304. nlo.clientid = clp->cl_clientid;
  2305. down(&state->lock_sema);
  2306. lsp = nfs4_find_lock_state(state, request->fl_owner);
  2307. if (lsp)
  2308. nlo.id = lsp->ls_id;
  2309. else {
  2310. spin_lock(&clp->cl_lock);
  2311. nlo.id = nfs4_alloc_lockowner_id(clp);
  2312. spin_unlock(&clp->cl_lock);
  2313. }
  2314. arg.u.lockt = &nlo;
  2315. status = rpc_call_sync(server->client, &msg, 0);
  2316. if (!status) {
  2317. request->fl_type = F_UNLCK;
  2318. } else if (status == -NFS4ERR_DENIED) {
  2319. int64_t len, start, end;
  2320. start = res.u.denied.offset;
  2321. len = res.u.denied.length;
  2322. end = start + len - 1;
  2323. if (end < 0 || len == 0)
  2324. request->fl_end = OFFSET_MAX;
  2325. else
  2326. request->fl_end = (loff_t)end;
  2327. request->fl_start = (loff_t)start;
  2328. request->fl_type = F_WRLCK;
  2329. if (res.u.denied.type & 1)
  2330. request->fl_type = F_RDLCK;
  2331. request->fl_pid = 0;
  2332. status = 0;
  2333. }
  2334. if (lsp)
  2335. nfs4_put_lock_state(lsp);
  2336. up(&state->lock_sema);
  2337. up_read(&clp->cl_sem);
  2338. return status;
  2339. }
  2340. static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  2341. {
  2342. struct nfs4_exception exception = { };
  2343. int err;
  2344. do {
  2345. err = nfs4_handle_exception(NFS_SERVER(state->inode),
  2346. _nfs4_proc_getlk(state, cmd, request),
  2347. &exception);
  2348. } while (exception.retry);
  2349. return err;
  2350. }
  2351. static int do_vfs_lock(struct file *file, struct file_lock *fl)
  2352. {
  2353. int res = 0;
  2354. switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
  2355. case FL_POSIX:
  2356. res = posix_lock_file_wait(file, fl);
  2357. break;
  2358. case FL_FLOCK:
  2359. res = flock_lock_file_wait(file, fl);
  2360. break;
  2361. default:
  2362. BUG();
  2363. }
  2364. if (res < 0)
  2365. printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
  2366. __FUNCTION__);
  2367. return res;
  2368. }
  2369. static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
  2370. {
  2371. struct inode *inode = state->inode;
  2372. struct nfs_server *server = NFS_SERVER(inode);
  2373. struct nfs4_client *clp = server->nfs4_state;
  2374. struct nfs_lockargs arg = {
  2375. .fh = NFS_FH(inode),
  2376. .type = nfs4_lck_type(cmd, request),
  2377. .offset = request->fl_start,
  2378. .length = nfs4_lck_length(request),
  2379. };
  2380. struct nfs_lockres res = {
  2381. .server = server,
  2382. };
  2383. struct rpc_message msg = {
  2384. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
  2385. .rpc_argp = &arg,
  2386. .rpc_resp = &res,
  2387. .rpc_cred = state->owner->so_cred,
  2388. };
  2389. struct nfs4_lock_state *lsp;
  2390. struct nfs_locku_opargs luargs;
  2391. int status = 0;
  2392. down_read(&clp->cl_sem);
  2393. down(&state->lock_sema);
  2394. lsp = nfs4_find_lock_state(state, request->fl_owner);
  2395. if (!lsp)
  2396. goto out;
  2397. /* We might have lost the locks! */
  2398. if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) {
  2399. luargs.seqid = lsp->ls_seqid;
  2400. memcpy(&luargs.stateid, &lsp->ls_stateid, sizeof(luargs.stateid));
  2401. arg.u.locku = &luargs;
  2402. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  2403. nfs4_increment_lock_seqid(status, lsp);
  2404. }
  2405. if (status == 0) {
  2406. memcpy(&lsp->ls_stateid, &res.u.stateid,
  2407. sizeof(lsp->ls_stateid));
  2408. nfs4_notify_unlck(state, request, lsp);
  2409. }
  2410. nfs4_put_lock_state(lsp);
  2411. out:
  2412. up(&state->lock_sema);
  2413. if (status == 0)
  2414. do_vfs_lock(request->fl_file, request);
  2415. up_read(&clp->cl_sem);
  2416. return status;
  2417. }
  2418. static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
  2419. {
  2420. struct nfs4_exception exception = { };
  2421. int err;
  2422. do {
  2423. err = nfs4_handle_exception(NFS_SERVER(state->inode),
  2424. _nfs4_proc_unlck(state, cmd, request),
  2425. &exception);
  2426. } while (exception.retry);
  2427. return err;
  2428. }
  2429. static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
  2430. {
  2431. struct inode *inode = state->inode;
  2432. struct nfs_server *server = NFS_SERVER(inode);
  2433. struct nfs4_lock_state *lsp;
  2434. struct nfs_lockargs arg = {
  2435. .fh = NFS_FH(inode),
  2436. .type = nfs4_lck_type(cmd, request),
  2437. .offset = request->fl_start,
  2438. .length = nfs4_lck_length(request),
  2439. };
  2440. struct nfs_lockres res = {
  2441. .server = server,
  2442. };
  2443. struct rpc_message msg = {
  2444. .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
  2445. .rpc_argp = &arg,
  2446. .rpc_resp = &res,
  2447. .rpc_cred = state->owner->so_cred,
  2448. };
  2449. struct nfs_lock_opargs largs = {
  2450. .reclaim = reclaim,
  2451. .new_lock_owner = 0,
  2452. };
  2453. int status;
  2454. lsp = nfs4_get_lock_state(state, request->fl_owner);
  2455. if (lsp == NULL)
  2456. return -ENOMEM;
  2457. if (!(lsp->ls_flags & NFS_LOCK_INITIALIZED)) {
  2458. struct nfs4_state_owner *owner = state->owner;
  2459. struct nfs_open_to_lock otl = {
  2460. .lock_owner = {
  2461. .clientid = server->nfs4_state->cl_clientid,
  2462. },
  2463. };
  2464. otl.lock_seqid = lsp->ls_seqid;
  2465. otl.lock_owner.id = lsp->ls_id;
  2466. memcpy(&otl.open_stateid, &state->stateid, sizeof(otl.open_stateid));
  2467. largs.u.open_lock = &otl;
  2468. largs.new_lock_owner = 1;
  2469. arg.u.lock = &largs;
  2470. down(&owner->so_sema);
  2471. otl.open_seqid = owner->so_seqid;
  2472. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  2473. /* increment open_owner seqid on success, and
  2474. * seqid mutating errors */
  2475. nfs4_increment_seqid(status, owner);
  2476. up(&owner->so_sema);
  2477. } else {
  2478. struct nfs_exist_lock el = {
  2479. .seqid = lsp->ls_seqid,
  2480. };
  2481. memcpy(&el.stateid, &lsp->ls_stateid, sizeof(el.stateid));
  2482. largs.u.exist_lock = &el;
  2483. largs.new_lock_owner = 0;
  2484. arg.u.lock = &largs;
  2485. status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
  2486. }
  2487. /* increment seqid on success, and * seqid mutating errors*/
  2488. nfs4_increment_lock_seqid(status, lsp);
  2489. /* save the returned stateid. */
  2490. if (status == 0) {
  2491. memcpy(&lsp->ls_stateid, &res.u.stateid, sizeof(nfs4_stateid));
  2492. lsp->ls_flags |= NFS_LOCK_INITIALIZED;
  2493. if (!reclaim)
  2494. nfs4_notify_setlk(state, request, lsp);
  2495. } else if (status == -NFS4ERR_DENIED)
  2496. status = -EAGAIN;
  2497. nfs4_put_lock_state(lsp);
  2498. return status;
  2499. }
  2500. static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
  2501. {
  2502. return _nfs4_do_setlk(state, F_SETLK, request, 1);
  2503. }
  2504. static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
  2505. {
  2506. return _nfs4_do_setlk(state, F_SETLK, request, 0);
  2507. }
  2508. static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  2509. {
  2510. struct nfs4_client *clp = state->owner->so_client;
  2511. int status;
  2512. down_read(&clp->cl_sem);
  2513. down(&state->lock_sema);
  2514. status = _nfs4_do_setlk(state, cmd, request, 0);
  2515. up(&state->lock_sema);
  2516. if (status == 0) {
  2517. /* Note: we always want to sleep here! */
  2518. request->fl_flags |= FL_SLEEP;
  2519. if (do_vfs_lock(request->fl_file, request) < 0)
  2520. printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
  2521. }
  2522. up_read(&clp->cl_sem);
  2523. return status;
  2524. }
  2525. static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
  2526. {
  2527. struct nfs4_exception exception = { };
  2528. int err;
  2529. do {
  2530. err = nfs4_handle_exception(NFS_SERVER(state->inode),
  2531. _nfs4_proc_setlk(state, cmd, request),
  2532. &exception);
  2533. } while (exception.retry);
  2534. return err;
  2535. }
  2536. static int
  2537. nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
  2538. {
  2539. struct nfs_open_context *ctx;
  2540. struct nfs4_state *state;
  2541. unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
  2542. int status;
  2543. /* verify open state */
  2544. ctx = (struct nfs_open_context *)filp->private_data;
  2545. state = ctx->state;
  2546. if (request->fl_start < 0 || request->fl_end < 0)
  2547. return -EINVAL;
  2548. if (IS_GETLK(cmd))
  2549. return nfs4_proc_getlk(state, F_GETLK, request);
  2550. if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
  2551. return -EINVAL;
  2552. if (request->fl_type == F_UNLCK)
  2553. return nfs4_proc_unlck(state, cmd, request);
  2554. do {
  2555. status = nfs4_proc_setlk(state, cmd, request);
  2556. if ((status != -EAGAIN) || IS_SETLK(cmd))
  2557. break;
  2558. timeout = nfs4_set_lock_task_retry(timeout);
  2559. status = -ERESTARTSYS;
  2560. if (signalled())
  2561. break;
  2562. } while(status < 0);
  2563. return status;
  2564. }
  2565. #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
  2566. int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
  2567. size_t buflen, int flags)
  2568. {
  2569. struct inode *inode = dentry->d_inode;
  2570. if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
  2571. return -EOPNOTSUPP;
  2572. if (!S_ISREG(inode->i_mode) &&
  2573. (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
  2574. return -EPERM;
  2575. return nfs4_proc_set_acl(inode, buf, buflen);
  2576. }
  2577. /* The getxattr man page suggests returning -ENODATA for unknown attributes,
  2578. * and that's what we'll do for e.g. user attributes that haven't been set.
  2579. * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
  2580. * attributes in kernel-managed attribute namespaces. */
  2581. ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
  2582. size_t buflen)
  2583. {
  2584. struct inode *inode = dentry->d_inode;
  2585. if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
  2586. return -EOPNOTSUPP;
  2587. return nfs4_proc_get_acl(inode, buf, buflen);
  2588. }
  2589. ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
  2590. {
  2591. size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
  2592. if (buf && buflen < len)
  2593. return -ERANGE;
  2594. if (buf)
  2595. memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
  2596. return len;
  2597. }
  2598. struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
  2599. .recover_open = nfs4_open_reclaim,
  2600. .recover_lock = nfs4_lock_reclaim,
  2601. };
  2602. struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = {
  2603. .recover_open = nfs4_open_expired,
  2604. .recover_lock = nfs4_lock_expired,
  2605. };
  2606. static struct inode_operations nfs4_file_inode_operations = {
  2607. .permission = nfs_permission,
  2608. .getattr = nfs_getattr,
  2609. .setattr = nfs_setattr,
  2610. .getxattr = nfs4_getxattr,
  2611. .setxattr = nfs4_setxattr,
  2612. .listxattr = nfs4_listxattr,
  2613. };
  2614. struct nfs_rpc_ops nfs_v4_clientops = {
  2615. .version = 4, /* protocol version */
  2616. .dentry_ops = &nfs4_dentry_operations,
  2617. .dir_inode_ops = &nfs4_dir_inode_operations,
  2618. .file_inode_ops = &nfs4_file_inode_operations,
  2619. .getroot = nfs4_proc_get_root,
  2620. .getattr = nfs4_proc_getattr,
  2621. .setattr = nfs4_proc_setattr,
  2622. .lookup = nfs4_proc_lookup,
  2623. .access = nfs4_proc_access,
  2624. .readlink = nfs4_proc_readlink,
  2625. .read = nfs4_proc_read,
  2626. .write = nfs4_proc_write,
  2627. .commit = nfs4_proc_commit,
  2628. .create = nfs4_proc_create,
  2629. .remove = nfs4_proc_remove,
  2630. .unlink_setup = nfs4_proc_unlink_setup,
  2631. .unlink_done = nfs4_proc_unlink_done,
  2632. .rename = nfs4_proc_rename,
  2633. .link = nfs4_proc_link,
  2634. .symlink = nfs4_proc_symlink,
  2635. .mkdir = nfs4_proc_mkdir,
  2636. .rmdir = nfs4_proc_remove,
  2637. .readdir = nfs4_proc_readdir,
  2638. .mknod = nfs4_proc_mknod,
  2639. .statfs = nfs4_proc_statfs,
  2640. .fsinfo = nfs4_proc_fsinfo,
  2641. .pathconf = nfs4_proc_pathconf,
  2642. .decode_dirent = nfs4_decode_dirent,
  2643. .read_setup = nfs4_proc_read_setup,
  2644. .write_setup = nfs4_proc_write_setup,
  2645. .commit_setup = nfs4_proc_commit_setup,
  2646. .file_open = nfs4_proc_file_open,
  2647. .file_release = nfs4_proc_file_release,
  2648. .lock = nfs4_proc_lock,
  2649. };
  2650. /*
  2651. * Local variables:
  2652. * c-basic-offset: 8
  2653. * End:
  2654. */