nfs4state.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. /*
  2. * fs/nfs/nfs4state.c
  3. *
  4. * Client-side XDR for NFSv4.
  5. *
  6. * Copyright (c) 2002 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Kendrick Smith <kmsmith@umich.edu>
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the University nor the names of its
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * Implementation of the NFSv4 state model. For the time being,
  37. * this is minimal, but will be made much more complex in a
  38. * subsequent patch.
  39. */
  40. #include <linux/kernel.h>
  41. #include <linux/slab.h>
  42. #include <linux/fs.h>
  43. #include <linux/nfs_fs.h>
  44. #include <linux/nfs_idmap.h>
  45. #include <linux/kthread.h>
  46. #include <linux/module.h>
  47. #include <linux/random.h>
  48. #include <linux/ratelimit.h>
  49. #include <linux/workqueue.h>
  50. #include <linux/bitops.h>
  51. #include "nfs4_fs.h"
  52. #include "callback.h"
  53. #include "delegation.h"
  54. #include "internal.h"
  55. #include "pnfs.h"
  56. #define OPENOWNER_POOL_SIZE 8
  57. const nfs4_stateid zero_stateid;
  58. static LIST_HEAD(nfs4_clientid_list);
  59. int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
  60. {
  61. struct nfs4_setclientid_res clid = {
  62. .clientid = clp->cl_clientid,
  63. .confirm = clp->cl_confirm,
  64. };
  65. unsigned short port;
  66. int status;
  67. if (test_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state))
  68. goto do_confirm;
  69. port = nfs_callback_tcpport;
  70. if (clp->cl_addr.ss_family == AF_INET6)
  71. port = nfs_callback_tcpport6;
  72. status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred, &clid);
  73. if (status != 0)
  74. goto out;
  75. clp->cl_clientid = clid.clientid;
  76. clp->cl_confirm = clid.confirm;
  77. set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  78. do_confirm:
  79. status = nfs4_proc_setclientid_confirm(clp, &clid, cred);
  80. if (status != 0)
  81. goto out;
  82. clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  83. nfs4_schedule_state_renewal(clp);
  84. out:
  85. return status;
  86. }
  87. struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp)
  88. {
  89. struct rpc_cred *cred = NULL;
  90. if (clp->cl_machine_cred != NULL)
  91. cred = get_rpccred(clp->cl_machine_cred);
  92. return cred;
  93. }
  94. static void nfs4_clear_machine_cred(struct nfs_client *clp)
  95. {
  96. struct rpc_cred *cred;
  97. spin_lock(&clp->cl_lock);
  98. cred = clp->cl_machine_cred;
  99. clp->cl_machine_cred = NULL;
  100. spin_unlock(&clp->cl_lock);
  101. if (cred != NULL)
  102. put_rpccred(cred);
  103. }
  104. static struct rpc_cred *
  105. nfs4_get_renew_cred_server_locked(struct nfs_server *server)
  106. {
  107. struct rpc_cred *cred = NULL;
  108. struct nfs4_state_owner *sp;
  109. struct rb_node *pos;
  110. for (pos = rb_first(&server->state_owners);
  111. pos != NULL;
  112. pos = rb_next(pos)) {
  113. sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
  114. if (list_empty(&sp->so_states))
  115. continue;
  116. cred = get_rpccred(sp->so_cred);
  117. break;
  118. }
  119. return cred;
  120. }
  121. /**
  122. * nfs4_get_renew_cred_locked - Acquire credential for a renew operation
  123. * @clp: client state handle
  124. *
  125. * Returns an rpc_cred with reference count bumped, or NULL.
  126. * Caller must hold clp->cl_lock.
  127. */
  128. struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
  129. {
  130. struct rpc_cred *cred = NULL;
  131. struct nfs_server *server;
  132. rcu_read_lock();
  133. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  134. cred = nfs4_get_renew_cred_server_locked(server);
  135. if (cred != NULL)
  136. break;
  137. }
  138. rcu_read_unlock();
  139. return cred;
  140. }
  141. #if defined(CONFIG_NFS_V4_1)
  142. static int nfs41_setup_state_renewal(struct nfs_client *clp)
  143. {
  144. int status;
  145. struct nfs_fsinfo fsinfo;
  146. if (!test_bit(NFS_CS_CHECK_LEASE_TIME, &clp->cl_res_state)) {
  147. nfs4_schedule_state_renewal(clp);
  148. return 0;
  149. }
  150. status = nfs4_proc_get_lease_time(clp, &fsinfo);
  151. if (status == 0) {
  152. /* Update lease time and schedule renewal */
  153. spin_lock(&clp->cl_lock);
  154. clp->cl_lease_time = fsinfo.lease_time * HZ;
  155. clp->cl_last_renewal = jiffies;
  156. spin_unlock(&clp->cl_lock);
  157. nfs4_schedule_state_renewal(clp);
  158. }
  159. return status;
  160. }
  161. /*
  162. * Back channel returns NFS4ERR_DELAY for new requests when
  163. * NFS4_SESSION_DRAINING is set so there is no work to be done when draining
  164. * is ended.
  165. */
  166. static void nfs4_end_drain_session(struct nfs_client *clp)
  167. {
  168. struct nfs4_session *ses = clp->cl_session;
  169. int max_slots;
  170. if (ses == NULL)
  171. return;
  172. if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
  173. spin_lock(&ses->fc_slot_table.slot_tbl_lock);
  174. max_slots = ses->fc_slot_table.max_slots;
  175. while (max_slots--) {
  176. struct rpc_task *task;
  177. task = rpc_wake_up_next(&ses->fc_slot_table.
  178. slot_tbl_waitq);
  179. if (!task)
  180. break;
  181. rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
  182. }
  183. spin_unlock(&ses->fc_slot_table.slot_tbl_lock);
  184. }
  185. }
  186. static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl)
  187. {
  188. spin_lock(&tbl->slot_tbl_lock);
  189. if (tbl->highest_used_slotid != -1) {
  190. INIT_COMPLETION(tbl->complete);
  191. spin_unlock(&tbl->slot_tbl_lock);
  192. return wait_for_completion_interruptible(&tbl->complete);
  193. }
  194. spin_unlock(&tbl->slot_tbl_lock);
  195. return 0;
  196. }
  197. static int nfs4_begin_drain_session(struct nfs_client *clp)
  198. {
  199. struct nfs4_session *ses = clp->cl_session;
  200. int ret = 0;
  201. set_bit(NFS4_SESSION_DRAINING, &ses->session_state);
  202. /* back channel */
  203. ret = nfs4_wait_on_slot_tbl(&ses->bc_slot_table);
  204. if (ret)
  205. return ret;
  206. /* fore channel */
  207. return nfs4_wait_on_slot_tbl(&ses->fc_slot_table);
  208. }
  209. int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
  210. {
  211. int status;
  212. if (test_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state))
  213. goto do_confirm;
  214. nfs4_begin_drain_session(clp);
  215. status = nfs4_proc_exchange_id(clp, cred);
  216. if (status != 0)
  217. goto out;
  218. set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  219. do_confirm:
  220. status = nfs4_proc_create_session(clp);
  221. if (status != 0)
  222. goto out;
  223. clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  224. nfs41_setup_state_renewal(clp);
  225. nfs_mark_client_ready(clp, NFS_CS_READY);
  226. out:
  227. return status;
  228. }
  229. struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp)
  230. {
  231. struct rpc_cred *cred;
  232. spin_lock(&clp->cl_lock);
  233. cred = nfs4_get_machine_cred_locked(clp);
  234. spin_unlock(&clp->cl_lock);
  235. return cred;
  236. }
  237. #endif /* CONFIG_NFS_V4_1 */
  238. static struct rpc_cred *
  239. nfs4_get_setclientid_cred_server(struct nfs_server *server)
  240. {
  241. struct nfs_client *clp = server->nfs_client;
  242. struct rpc_cred *cred = NULL;
  243. struct nfs4_state_owner *sp;
  244. struct rb_node *pos;
  245. spin_lock(&clp->cl_lock);
  246. pos = rb_first(&server->state_owners);
  247. if (pos != NULL) {
  248. sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
  249. cred = get_rpccred(sp->so_cred);
  250. }
  251. spin_unlock(&clp->cl_lock);
  252. return cred;
  253. }
  254. /**
  255. * nfs4_get_setclientid_cred - Acquire credential for a setclientid operation
  256. * @clp: client state handle
  257. *
  258. * Returns an rpc_cred with reference count bumped, or NULL.
  259. */
  260. struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp)
  261. {
  262. struct nfs_server *server;
  263. struct rpc_cred *cred;
  264. spin_lock(&clp->cl_lock);
  265. cred = nfs4_get_machine_cred_locked(clp);
  266. spin_unlock(&clp->cl_lock);
  267. if (cred != NULL)
  268. goto out;
  269. rcu_read_lock();
  270. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  271. cred = nfs4_get_setclientid_cred_server(server);
  272. if (cred != NULL)
  273. break;
  274. }
  275. rcu_read_unlock();
  276. out:
  277. return cred;
  278. }
  279. static void nfs_alloc_unique_id_locked(struct rb_root *root,
  280. struct nfs_unique_id *new,
  281. __u64 minval, int maxbits)
  282. {
  283. struct rb_node **p, *parent;
  284. struct nfs_unique_id *pos;
  285. __u64 mask = ~0ULL;
  286. if (maxbits < 64)
  287. mask = (1ULL << maxbits) - 1ULL;
  288. /* Ensure distribution is more or less flat */
  289. get_random_bytes(&new->id, sizeof(new->id));
  290. new->id &= mask;
  291. if (new->id < minval)
  292. new->id += minval;
  293. retry:
  294. p = &root->rb_node;
  295. parent = NULL;
  296. while (*p != NULL) {
  297. parent = *p;
  298. pos = rb_entry(parent, struct nfs_unique_id, rb_node);
  299. if (new->id < pos->id)
  300. p = &(*p)->rb_left;
  301. else if (new->id > pos->id)
  302. p = &(*p)->rb_right;
  303. else
  304. goto id_exists;
  305. }
  306. rb_link_node(&new->rb_node, parent, p);
  307. rb_insert_color(&new->rb_node, root);
  308. return;
  309. id_exists:
  310. for (;;) {
  311. new->id++;
  312. if (new->id < minval || (new->id & mask) != new->id) {
  313. new->id = minval;
  314. break;
  315. }
  316. parent = rb_next(parent);
  317. if (parent == NULL)
  318. break;
  319. pos = rb_entry(parent, struct nfs_unique_id, rb_node);
  320. if (new->id < pos->id)
  321. break;
  322. }
  323. goto retry;
  324. }
  325. static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
  326. {
  327. rb_erase(&id->rb_node, root);
  328. }
  329. static struct nfs4_state_owner *
  330. nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred)
  331. {
  332. struct rb_node **p = &server->state_owners.rb_node,
  333. *parent = NULL;
  334. struct nfs4_state_owner *sp, *res = NULL;
  335. while (*p != NULL) {
  336. parent = *p;
  337. sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
  338. if (server < sp->so_server) {
  339. p = &parent->rb_left;
  340. continue;
  341. }
  342. if (server > sp->so_server) {
  343. p = &parent->rb_right;
  344. continue;
  345. }
  346. if (cred < sp->so_cred)
  347. p = &parent->rb_left;
  348. else if (cred > sp->so_cred)
  349. p = &parent->rb_right;
  350. else {
  351. atomic_inc(&sp->so_count);
  352. res = sp;
  353. break;
  354. }
  355. }
  356. return res;
  357. }
  358. static struct nfs4_state_owner *
  359. nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
  360. {
  361. struct nfs_server *server = new->so_server;
  362. struct rb_node **p = &server->state_owners.rb_node,
  363. *parent = NULL;
  364. struct nfs4_state_owner *sp;
  365. while (*p != NULL) {
  366. parent = *p;
  367. sp = rb_entry(parent, struct nfs4_state_owner, so_server_node);
  368. if (new->so_cred < sp->so_cred)
  369. p = &parent->rb_left;
  370. else if (new->so_cred > sp->so_cred)
  371. p = &parent->rb_right;
  372. else {
  373. atomic_inc(&sp->so_count);
  374. return sp;
  375. }
  376. }
  377. nfs_alloc_unique_id_locked(&server->openowner_id,
  378. &new->so_owner_id, 1, 64);
  379. rb_link_node(&new->so_server_node, parent, p);
  380. rb_insert_color(&new->so_server_node, &server->state_owners);
  381. return new;
  382. }
  383. static void
  384. nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
  385. {
  386. struct nfs_server *server = sp->so_server;
  387. if (!RB_EMPTY_NODE(&sp->so_server_node))
  388. rb_erase(&sp->so_server_node, &server->state_owners);
  389. nfs_free_unique_id(&server->openowner_id, &sp->so_owner_id);
  390. }
  391. /*
  392. * nfs4_alloc_state_owner(): this is called on the OPEN or CREATE path to
  393. * create a new state_owner.
  394. *
  395. */
  396. static struct nfs4_state_owner *
  397. nfs4_alloc_state_owner(void)
  398. {
  399. struct nfs4_state_owner *sp;
  400. sp = kzalloc(sizeof(*sp),GFP_NOFS);
  401. if (!sp)
  402. return NULL;
  403. spin_lock_init(&sp->so_lock);
  404. INIT_LIST_HEAD(&sp->so_states);
  405. rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
  406. sp->so_seqid.sequence = &sp->so_sequence;
  407. spin_lock_init(&sp->so_sequence.lock);
  408. INIT_LIST_HEAD(&sp->so_sequence.list);
  409. atomic_set(&sp->so_count, 1);
  410. return sp;
  411. }
  412. static void
  413. nfs4_drop_state_owner(struct nfs4_state_owner *sp)
  414. {
  415. if (!RB_EMPTY_NODE(&sp->so_server_node)) {
  416. struct nfs_server *server = sp->so_server;
  417. struct nfs_client *clp = server->nfs_client;
  418. spin_lock(&clp->cl_lock);
  419. rb_erase(&sp->so_server_node, &server->state_owners);
  420. RB_CLEAR_NODE(&sp->so_server_node);
  421. spin_unlock(&clp->cl_lock);
  422. }
  423. }
  424. /**
  425. * nfs4_get_state_owner - Look up a state owner given a credential
  426. * @server: nfs_server to search
  427. * @cred: RPC credential to match
  428. *
  429. * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
  430. */
  431. struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
  432. struct rpc_cred *cred)
  433. {
  434. struct nfs_client *clp = server->nfs_client;
  435. struct nfs4_state_owner *sp, *new;
  436. spin_lock(&clp->cl_lock);
  437. sp = nfs4_find_state_owner_locked(server, cred);
  438. spin_unlock(&clp->cl_lock);
  439. if (sp != NULL)
  440. return sp;
  441. new = nfs4_alloc_state_owner();
  442. if (new == NULL)
  443. return NULL;
  444. new->so_server = server;
  445. new->so_cred = cred;
  446. spin_lock(&clp->cl_lock);
  447. sp = nfs4_insert_state_owner_locked(new);
  448. spin_unlock(&clp->cl_lock);
  449. if (sp == new)
  450. get_rpccred(cred);
  451. else {
  452. rpc_destroy_wait_queue(&new->so_sequence.wait);
  453. kfree(new);
  454. }
  455. return sp;
  456. }
  457. /**
  458. * nfs4_put_state_owner - Release a nfs4_state_owner
  459. * @sp: state owner data to release
  460. *
  461. */
  462. void nfs4_put_state_owner(struct nfs4_state_owner *sp)
  463. {
  464. struct nfs_client *clp = sp->so_server->nfs_client;
  465. struct rpc_cred *cred = sp->so_cred;
  466. if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock))
  467. return;
  468. nfs4_remove_state_owner_locked(sp);
  469. spin_unlock(&clp->cl_lock);
  470. rpc_destroy_wait_queue(&sp->so_sequence.wait);
  471. put_rpccred(cred);
  472. kfree(sp);
  473. }
  474. static struct nfs4_state *
  475. nfs4_alloc_open_state(void)
  476. {
  477. struct nfs4_state *state;
  478. state = kzalloc(sizeof(*state), GFP_NOFS);
  479. if (!state)
  480. return NULL;
  481. atomic_set(&state->count, 1);
  482. INIT_LIST_HEAD(&state->lock_states);
  483. spin_lock_init(&state->state_lock);
  484. seqlock_init(&state->seqlock);
  485. return state;
  486. }
  487. void
  488. nfs4_state_set_mode_locked(struct nfs4_state *state, fmode_t fmode)
  489. {
  490. if (state->state == fmode)
  491. return;
  492. /* NB! List reordering - see the reclaim code for why. */
  493. if ((fmode & FMODE_WRITE) != (state->state & FMODE_WRITE)) {
  494. if (fmode & FMODE_WRITE)
  495. list_move(&state->open_states, &state->owner->so_states);
  496. else
  497. list_move_tail(&state->open_states, &state->owner->so_states);
  498. }
  499. state->state = fmode;
  500. }
  501. static struct nfs4_state *
  502. __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
  503. {
  504. struct nfs_inode *nfsi = NFS_I(inode);
  505. struct nfs4_state *state;
  506. list_for_each_entry(state, &nfsi->open_states, inode_states) {
  507. if (state->owner != owner)
  508. continue;
  509. if (atomic_inc_not_zero(&state->count))
  510. return state;
  511. }
  512. return NULL;
  513. }
  514. static void
  515. nfs4_free_open_state(struct nfs4_state *state)
  516. {
  517. kfree(state);
  518. }
  519. struct nfs4_state *
  520. nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
  521. {
  522. struct nfs4_state *state, *new;
  523. struct nfs_inode *nfsi = NFS_I(inode);
  524. spin_lock(&inode->i_lock);
  525. state = __nfs4_find_state_byowner(inode, owner);
  526. spin_unlock(&inode->i_lock);
  527. if (state)
  528. goto out;
  529. new = nfs4_alloc_open_state();
  530. spin_lock(&owner->so_lock);
  531. spin_lock(&inode->i_lock);
  532. state = __nfs4_find_state_byowner(inode, owner);
  533. if (state == NULL && new != NULL) {
  534. state = new;
  535. state->owner = owner;
  536. atomic_inc(&owner->so_count);
  537. list_add(&state->inode_states, &nfsi->open_states);
  538. ihold(inode);
  539. state->inode = inode;
  540. spin_unlock(&inode->i_lock);
  541. /* Note: The reclaim code dictates that we add stateless
  542. * and read-only stateids to the end of the list */
  543. list_add_tail(&state->open_states, &owner->so_states);
  544. spin_unlock(&owner->so_lock);
  545. } else {
  546. spin_unlock(&inode->i_lock);
  547. spin_unlock(&owner->so_lock);
  548. if (new)
  549. nfs4_free_open_state(new);
  550. }
  551. out:
  552. return state;
  553. }
  554. void nfs4_put_open_state(struct nfs4_state *state)
  555. {
  556. struct inode *inode = state->inode;
  557. struct nfs4_state_owner *owner = state->owner;
  558. if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
  559. return;
  560. spin_lock(&inode->i_lock);
  561. list_del(&state->inode_states);
  562. list_del(&state->open_states);
  563. spin_unlock(&inode->i_lock);
  564. spin_unlock(&owner->so_lock);
  565. iput(inode);
  566. nfs4_free_open_state(state);
  567. nfs4_put_state_owner(owner);
  568. }
  569. /*
  570. * Close the current file.
  571. */
  572. static void __nfs4_close(struct path *path, struct nfs4_state *state,
  573. fmode_t fmode, gfp_t gfp_mask, int wait)
  574. {
  575. struct nfs4_state_owner *owner = state->owner;
  576. int call_close = 0;
  577. fmode_t newstate;
  578. atomic_inc(&owner->so_count);
  579. /* Protect against nfs4_find_state() */
  580. spin_lock(&owner->so_lock);
  581. switch (fmode & (FMODE_READ | FMODE_WRITE)) {
  582. case FMODE_READ:
  583. state->n_rdonly--;
  584. break;
  585. case FMODE_WRITE:
  586. state->n_wronly--;
  587. break;
  588. case FMODE_READ|FMODE_WRITE:
  589. state->n_rdwr--;
  590. }
  591. newstate = FMODE_READ|FMODE_WRITE;
  592. if (state->n_rdwr == 0) {
  593. if (state->n_rdonly == 0) {
  594. newstate &= ~FMODE_READ;
  595. call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
  596. call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
  597. }
  598. if (state->n_wronly == 0) {
  599. newstate &= ~FMODE_WRITE;
  600. call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
  601. call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
  602. }
  603. if (newstate == 0)
  604. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  605. }
  606. nfs4_state_set_mode_locked(state, newstate);
  607. spin_unlock(&owner->so_lock);
  608. if (!call_close) {
  609. nfs4_put_open_state(state);
  610. nfs4_put_state_owner(owner);
  611. } else {
  612. bool roc = pnfs_roc(state->inode);
  613. nfs4_do_close(path, state, gfp_mask, wait, roc);
  614. }
  615. }
  616. void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode)
  617. {
  618. __nfs4_close(path, state, fmode, GFP_NOFS, 0);
  619. }
  620. void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
  621. {
  622. __nfs4_close(path, state, fmode, GFP_KERNEL, 1);
  623. }
  624. /*
  625. * Search the state->lock_states for an existing lock_owner
  626. * that is compatible with current->files
  627. */
  628. static struct nfs4_lock_state *
  629. __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
  630. {
  631. struct nfs4_lock_state *pos;
  632. list_for_each_entry(pos, &state->lock_states, ls_locks) {
  633. if (type != NFS4_ANY_LOCK_TYPE && pos->ls_owner.lo_type != type)
  634. continue;
  635. switch (pos->ls_owner.lo_type) {
  636. case NFS4_POSIX_LOCK_TYPE:
  637. if (pos->ls_owner.lo_u.posix_owner != fl_owner)
  638. continue;
  639. break;
  640. case NFS4_FLOCK_LOCK_TYPE:
  641. if (pos->ls_owner.lo_u.flock_owner != fl_pid)
  642. continue;
  643. }
  644. atomic_inc(&pos->ls_count);
  645. return pos;
  646. }
  647. return NULL;
  648. }
  649. /*
  650. * Return a compatible lock_state. If no initialized lock_state structure
  651. * exists, return an uninitialized one.
  652. *
  653. */
  654. static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
  655. {
  656. struct nfs4_lock_state *lsp;
  657. struct nfs_server *server = state->owner->so_server;
  658. struct nfs_client *clp = server->nfs_client;
  659. lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
  660. if (lsp == NULL)
  661. return NULL;
  662. rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue");
  663. spin_lock_init(&lsp->ls_sequence.lock);
  664. INIT_LIST_HEAD(&lsp->ls_sequence.list);
  665. lsp->ls_seqid.sequence = &lsp->ls_sequence;
  666. atomic_set(&lsp->ls_count, 1);
  667. lsp->ls_state = state;
  668. lsp->ls_owner.lo_type = type;
  669. switch (lsp->ls_owner.lo_type) {
  670. case NFS4_FLOCK_LOCK_TYPE:
  671. lsp->ls_owner.lo_u.flock_owner = fl_pid;
  672. break;
  673. case NFS4_POSIX_LOCK_TYPE:
  674. lsp->ls_owner.lo_u.posix_owner = fl_owner;
  675. break;
  676. default:
  677. kfree(lsp);
  678. return NULL;
  679. }
  680. spin_lock(&clp->cl_lock);
  681. nfs_alloc_unique_id_locked(&server->lockowner_id, &lsp->ls_id, 1, 64);
  682. spin_unlock(&clp->cl_lock);
  683. INIT_LIST_HEAD(&lsp->ls_locks);
  684. return lsp;
  685. }
  686. static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
  687. {
  688. struct nfs_server *server = lsp->ls_state->owner->so_server;
  689. struct nfs_client *clp = server->nfs_client;
  690. spin_lock(&clp->cl_lock);
  691. nfs_free_unique_id(&server->lockowner_id, &lsp->ls_id);
  692. spin_unlock(&clp->cl_lock);
  693. rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
  694. kfree(lsp);
  695. }
  696. /*
  697. * Return a compatible lock_state. If no initialized lock_state structure
  698. * exists, return an uninitialized one.
  699. *
  700. */
  701. static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner, pid_t pid, unsigned int type)
  702. {
  703. struct nfs4_lock_state *lsp, *new = NULL;
  704. for(;;) {
  705. spin_lock(&state->state_lock);
  706. lsp = __nfs4_find_lock_state(state, owner, pid, type);
  707. if (lsp != NULL)
  708. break;
  709. if (new != NULL) {
  710. list_add(&new->ls_locks, &state->lock_states);
  711. set_bit(LK_STATE_IN_USE, &state->flags);
  712. lsp = new;
  713. new = NULL;
  714. break;
  715. }
  716. spin_unlock(&state->state_lock);
  717. new = nfs4_alloc_lock_state(state, owner, pid, type);
  718. if (new == NULL)
  719. return NULL;
  720. }
  721. spin_unlock(&state->state_lock);
  722. if (new != NULL)
  723. nfs4_free_lock_state(new);
  724. return lsp;
  725. }
  726. /*
  727. * Release reference to lock_state, and free it if we see that
  728. * it is no longer in use
  729. */
  730. void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
  731. {
  732. struct nfs4_state *state;
  733. if (lsp == NULL)
  734. return;
  735. state = lsp->ls_state;
  736. if (!atomic_dec_and_lock(&lsp->ls_count, &state->state_lock))
  737. return;
  738. list_del(&lsp->ls_locks);
  739. if (list_empty(&state->lock_states))
  740. clear_bit(LK_STATE_IN_USE, &state->flags);
  741. spin_unlock(&state->state_lock);
  742. if (lsp->ls_flags & NFS_LOCK_INITIALIZED)
  743. nfs4_release_lockowner(lsp);
  744. nfs4_free_lock_state(lsp);
  745. }
  746. static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
  747. {
  748. struct nfs4_lock_state *lsp = src->fl_u.nfs4_fl.owner;
  749. dst->fl_u.nfs4_fl.owner = lsp;
  750. atomic_inc(&lsp->ls_count);
  751. }
  752. static void nfs4_fl_release_lock(struct file_lock *fl)
  753. {
  754. nfs4_put_lock_state(fl->fl_u.nfs4_fl.owner);
  755. }
  756. static const struct file_lock_operations nfs4_fl_lock_ops = {
  757. .fl_copy_lock = nfs4_fl_copy_lock,
  758. .fl_release_private = nfs4_fl_release_lock,
  759. };
  760. int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
  761. {
  762. struct nfs4_lock_state *lsp;
  763. if (fl->fl_ops != NULL)
  764. return 0;
  765. if (fl->fl_flags & FL_POSIX)
  766. lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
  767. else if (fl->fl_flags & FL_FLOCK)
  768. lsp = nfs4_get_lock_state(state, 0, fl->fl_pid, NFS4_FLOCK_LOCK_TYPE);
  769. else
  770. return -EINVAL;
  771. if (lsp == NULL)
  772. return -ENOMEM;
  773. fl->fl_u.nfs4_fl.owner = lsp;
  774. fl->fl_ops = &nfs4_fl_lock_ops;
  775. return 0;
  776. }
  777. /*
  778. * Byte-range lock aware utility to initialize the stateid of read/write
  779. * requests.
  780. */
  781. void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
  782. {
  783. struct nfs4_lock_state *lsp;
  784. int seq;
  785. do {
  786. seq = read_seqbegin(&state->seqlock);
  787. memcpy(dst, &state->stateid, sizeof(*dst));
  788. } while (read_seqretry(&state->seqlock, seq));
  789. if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
  790. return;
  791. spin_lock(&state->state_lock);
  792. lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
  793. if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
  794. memcpy(dst, &lsp->ls_stateid, sizeof(*dst));
  795. spin_unlock(&state->state_lock);
  796. nfs4_put_lock_state(lsp);
  797. }
  798. struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask)
  799. {
  800. struct nfs_seqid *new;
  801. new = kmalloc(sizeof(*new), gfp_mask);
  802. if (new != NULL) {
  803. new->sequence = counter;
  804. INIT_LIST_HEAD(&new->list);
  805. }
  806. return new;
  807. }
  808. void nfs_release_seqid(struct nfs_seqid *seqid)
  809. {
  810. if (!list_empty(&seqid->list)) {
  811. struct rpc_sequence *sequence = seqid->sequence->sequence;
  812. spin_lock(&sequence->lock);
  813. list_del_init(&seqid->list);
  814. spin_unlock(&sequence->lock);
  815. rpc_wake_up(&sequence->wait);
  816. }
  817. }
  818. void nfs_free_seqid(struct nfs_seqid *seqid)
  819. {
  820. nfs_release_seqid(seqid);
  821. kfree(seqid);
  822. }
  823. /*
  824. * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
  825. * failed with a seqid incrementing error -
  826. * see comments nfs_fs.h:seqid_mutating_error()
  827. */
  828. static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
  829. {
  830. BUG_ON(list_first_entry(&seqid->sequence->sequence->list, struct nfs_seqid, list) != seqid);
  831. switch (status) {
  832. case 0:
  833. break;
  834. case -NFS4ERR_BAD_SEQID:
  835. if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
  836. return;
  837. printk(KERN_WARNING "NFS: v4 server returned a bad"
  838. " sequence-id error on an"
  839. " unconfirmed sequence %p!\n",
  840. seqid->sequence);
  841. case -NFS4ERR_STALE_CLIENTID:
  842. case -NFS4ERR_STALE_STATEID:
  843. case -NFS4ERR_BAD_STATEID:
  844. case -NFS4ERR_BADXDR:
  845. case -NFS4ERR_RESOURCE:
  846. case -NFS4ERR_NOFILEHANDLE:
  847. /* Non-seqid mutating errors */
  848. return;
  849. };
  850. /*
  851. * Note: no locking needed as we are guaranteed to be first
  852. * on the sequence list
  853. */
  854. seqid->sequence->counter++;
  855. }
  856. void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid)
  857. {
  858. struct nfs4_state_owner *sp = container_of(seqid->sequence,
  859. struct nfs4_state_owner, so_seqid);
  860. struct nfs_server *server = sp->so_server;
  861. if (status == -NFS4ERR_BAD_SEQID)
  862. nfs4_drop_state_owner(sp);
  863. if (!nfs4_has_session(server->nfs_client))
  864. nfs_increment_seqid(status, seqid);
  865. }
  866. /*
  867. * Increment the seqid if the LOCK/LOCKU succeeded, or
  868. * failed with a seqid incrementing error -
  869. * see comments nfs_fs.h:seqid_mutating_error()
  870. */
  871. void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
  872. {
  873. nfs_increment_seqid(status, seqid);
  874. }
  875. int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
  876. {
  877. struct rpc_sequence *sequence = seqid->sequence->sequence;
  878. int status = 0;
  879. spin_lock(&sequence->lock);
  880. if (list_empty(&seqid->list))
  881. list_add_tail(&seqid->list, &sequence->list);
  882. if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid)
  883. goto unlock;
  884. rpc_sleep_on(&sequence->wait, task, NULL);
  885. status = -EAGAIN;
  886. unlock:
  887. spin_unlock(&sequence->lock);
  888. return status;
  889. }
  890. static int nfs4_run_state_manager(void *);
  891. static void nfs4_clear_state_manager_bit(struct nfs_client *clp)
  892. {
  893. smp_mb__before_clear_bit();
  894. clear_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state);
  895. smp_mb__after_clear_bit();
  896. wake_up_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING);
  897. rpc_wake_up(&clp->cl_rpcwaitq);
  898. }
  899. /*
  900. * Schedule the nfs_client asynchronous state management routine
  901. */
  902. void nfs4_schedule_state_manager(struct nfs_client *clp)
  903. {
  904. struct task_struct *task;
  905. if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
  906. return;
  907. __module_get(THIS_MODULE);
  908. atomic_inc(&clp->cl_count);
  909. task = kthread_run(nfs4_run_state_manager, clp, "%s-manager",
  910. rpc_peeraddr2str(clp->cl_rpcclient,
  911. RPC_DISPLAY_ADDR));
  912. if (!IS_ERR(task))
  913. return;
  914. nfs4_clear_state_manager_bit(clp);
  915. nfs_put_client(clp);
  916. module_put(THIS_MODULE);
  917. }
  918. /*
  919. * Schedule a lease recovery attempt
  920. */
  921. void nfs4_schedule_lease_recovery(struct nfs_client *clp)
  922. {
  923. if (!clp)
  924. return;
  925. if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  926. set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
  927. nfs4_schedule_state_manager(clp);
  928. }
  929. static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_state *state)
  930. {
  931. set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  932. /* Don't recover state that expired before the reboot */
  933. if (test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) {
  934. clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  935. return 0;
  936. }
  937. set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
  938. set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
  939. return 1;
  940. }
  941. static int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state)
  942. {
  943. set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
  944. clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
  945. set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
  946. set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
  947. return 1;
  948. }
  949. void nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state)
  950. {
  951. struct nfs_client *clp = server->nfs_client;
  952. nfs4_state_mark_reclaim_nograce(clp, state);
  953. nfs4_schedule_state_manager(clp);
  954. }
  955. static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
  956. {
  957. struct inode *inode = state->inode;
  958. struct nfs_inode *nfsi = NFS_I(inode);
  959. struct file_lock *fl;
  960. int status = 0;
  961. if (inode->i_flock == NULL)
  962. return 0;
  963. /* Guard against delegation returns and new lock/unlock calls */
  964. down_write(&nfsi->rwsem);
  965. /* Protect inode->i_flock using the BKL */
  966. lock_flocks();
  967. for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
  968. if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
  969. continue;
  970. if (nfs_file_open_context(fl->fl_file)->state != state)
  971. continue;
  972. unlock_flocks();
  973. status = ops->recover_lock(state, fl);
  974. switch (status) {
  975. case 0:
  976. break;
  977. case -ESTALE:
  978. case -NFS4ERR_ADMIN_REVOKED:
  979. case -NFS4ERR_STALE_STATEID:
  980. case -NFS4ERR_BAD_STATEID:
  981. case -NFS4ERR_EXPIRED:
  982. case -NFS4ERR_NO_GRACE:
  983. case -NFS4ERR_STALE_CLIENTID:
  984. case -NFS4ERR_BADSESSION:
  985. case -NFS4ERR_BADSLOT:
  986. case -NFS4ERR_BAD_HIGH_SLOT:
  987. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  988. goto out;
  989. default:
  990. printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
  991. __func__, status);
  992. case -ENOMEM:
  993. case -NFS4ERR_DENIED:
  994. case -NFS4ERR_RECLAIM_BAD:
  995. case -NFS4ERR_RECLAIM_CONFLICT:
  996. /* kill_proc(fl->fl_pid, SIGLOST, 1); */
  997. status = 0;
  998. }
  999. lock_flocks();
  1000. }
  1001. unlock_flocks();
  1002. out:
  1003. up_write(&nfsi->rwsem);
  1004. return status;
  1005. }
  1006. static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
  1007. {
  1008. struct nfs4_state *state;
  1009. struct nfs4_lock_state *lock;
  1010. int status = 0;
  1011. /* Note: we rely on the sp->so_states list being ordered
  1012. * so that we always reclaim open(O_RDWR) and/or open(O_WRITE)
  1013. * states first.
  1014. * This is needed to ensure that the server won't give us any
  1015. * read delegations that we have to return if, say, we are
  1016. * recovering after a network partition or a reboot from a
  1017. * server that doesn't support a grace period.
  1018. */
  1019. restart:
  1020. spin_lock(&sp->so_lock);
  1021. list_for_each_entry(state, &sp->so_states, open_states) {
  1022. if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
  1023. continue;
  1024. if (state->state == 0)
  1025. continue;
  1026. atomic_inc(&state->count);
  1027. spin_unlock(&sp->so_lock);
  1028. status = ops->recover_open(sp, state);
  1029. if (status >= 0) {
  1030. status = nfs4_reclaim_locks(state, ops);
  1031. if (status >= 0) {
  1032. list_for_each_entry(lock, &state->lock_states, ls_locks) {
  1033. if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
  1034. printk("%s: Lock reclaim failed!\n",
  1035. __func__);
  1036. }
  1037. nfs4_put_open_state(state);
  1038. goto restart;
  1039. }
  1040. }
  1041. switch (status) {
  1042. default:
  1043. printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n",
  1044. __func__, status);
  1045. case -ENOENT:
  1046. case -ENOMEM:
  1047. case -ESTALE:
  1048. /*
  1049. * Open state on this file cannot be recovered
  1050. * All we can do is revert to using the zero stateid.
  1051. */
  1052. memset(state->stateid.data, 0,
  1053. sizeof(state->stateid.data));
  1054. /* Mark the file as being 'closed' */
  1055. state->state = 0;
  1056. break;
  1057. case -EKEYEXPIRED:
  1058. /*
  1059. * User RPCSEC_GSS context has expired.
  1060. * We cannot recover this stateid now, so
  1061. * skip it and allow recovery thread to
  1062. * proceed.
  1063. */
  1064. break;
  1065. case -NFS4ERR_ADMIN_REVOKED:
  1066. case -NFS4ERR_STALE_STATEID:
  1067. case -NFS4ERR_BAD_STATEID:
  1068. case -NFS4ERR_RECLAIM_BAD:
  1069. case -NFS4ERR_RECLAIM_CONFLICT:
  1070. nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
  1071. break;
  1072. case -NFS4ERR_EXPIRED:
  1073. case -NFS4ERR_NO_GRACE:
  1074. nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
  1075. case -NFS4ERR_STALE_CLIENTID:
  1076. case -NFS4ERR_BADSESSION:
  1077. case -NFS4ERR_BADSLOT:
  1078. case -NFS4ERR_BAD_HIGH_SLOT:
  1079. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  1080. goto out_err;
  1081. }
  1082. nfs4_put_open_state(state);
  1083. goto restart;
  1084. }
  1085. spin_unlock(&sp->so_lock);
  1086. return 0;
  1087. out_err:
  1088. nfs4_put_open_state(state);
  1089. return status;
  1090. }
  1091. static void nfs4_clear_open_state(struct nfs4_state *state)
  1092. {
  1093. struct nfs4_lock_state *lock;
  1094. clear_bit(NFS_DELEGATED_STATE, &state->flags);
  1095. clear_bit(NFS_O_RDONLY_STATE, &state->flags);
  1096. clear_bit(NFS_O_WRONLY_STATE, &state->flags);
  1097. clear_bit(NFS_O_RDWR_STATE, &state->flags);
  1098. list_for_each_entry(lock, &state->lock_states, ls_locks) {
  1099. lock->ls_seqid.flags = 0;
  1100. lock->ls_flags &= ~NFS_LOCK_INITIALIZED;
  1101. }
  1102. }
  1103. static void nfs4_reset_seqids(struct nfs_server *server,
  1104. int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
  1105. {
  1106. struct nfs_client *clp = server->nfs_client;
  1107. struct nfs4_state_owner *sp;
  1108. struct rb_node *pos;
  1109. struct nfs4_state *state;
  1110. spin_lock(&clp->cl_lock);
  1111. for (pos = rb_first(&server->state_owners);
  1112. pos != NULL;
  1113. pos = rb_next(pos)) {
  1114. sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
  1115. sp->so_seqid.flags = 0;
  1116. spin_lock(&sp->so_lock);
  1117. list_for_each_entry(state, &sp->so_states, open_states) {
  1118. if (mark_reclaim(clp, state))
  1119. nfs4_clear_open_state(state);
  1120. }
  1121. spin_unlock(&sp->so_lock);
  1122. }
  1123. spin_unlock(&clp->cl_lock);
  1124. }
  1125. static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp,
  1126. int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state))
  1127. {
  1128. struct nfs_server *server;
  1129. rcu_read_lock();
  1130. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  1131. nfs4_reset_seqids(server, mark_reclaim);
  1132. rcu_read_unlock();
  1133. }
  1134. static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp)
  1135. {
  1136. /* Mark all delegations for reclaim */
  1137. nfs_delegation_mark_reclaim(clp);
  1138. nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
  1139. }
  1140. static void nfs4_reclaim_complete(struct nfs_client *clp,
  1141. const struct nfs4_state_recovery_ops *ops)
  1142. {
  1143. /* Notify the server we're done reclaiming our state */
  1144. if (ops->reclaim_complete)
  1145. (void)ops->reclaim_complete(clp);
  1146. }
  1147. static void nfs4_clear_reclaim_server(struct nfs_server *server)
  1148. {
  1149. struct nfs_client *clp = server->nfs_client;
  1150. struct nfs4_state_owner *sp;
  1151. struct rb_node *pos;
  1152. struct nfs4_state *state;
  1153. spin_lock(&clp->cl_lock);
  1154. for (pos = rb_first(&server->state_owners);
  1155. pos != NULL;
  1156. pos = rb_next(pos)) {
  1157. sp = rb_entry(pos, struct nfs4_state_owner, so_server_node);
  1158. spin_lock(&sp->so_lock);
  1159. list_for_each_entry(state, &sp->so_states, open_states) {
  1160. if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT,
  1161. &state->flags))
  1162. continue;
  1163. nfs4_state_mark_reclaim_nograce(clp, state);
  1164. }
  1165. spin_unlock(&sp->so_lock);
  1166. }
  1167. spin_unlock(&clp->cl_lock);
  1168. }
  1169. static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp)
  1170. {
  1171. struct nfs_server *server;
  1172. if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
  1173. return 0;
  1174. rcu_read_lock();
  1175. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
  1176. nfs4_clear_reclaim_server(server);
  1177. rcu_read_unlock();
  1178. nfs_delegation_reap_unclaimed(clp);
  1179. return 1;
  1180. }
  1181. static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
  1182. {
  1183. if (!nfs4_state_clear_reclaim_reboot(clp))
  1184. return;
  1185. nfs4_reclaim_complete(clp, clp->cl_mvops->reboot_recovery_ops);
  1186. }
  1187. static void nfs_delegation_clear_all(struct nfs_client *clp)
  1188. {
  1189. nfs_delegation_mark_reclaim(clp);
  1190. nfs_delegation_reap_unclaimed(clp);
  1191. }
  1192. static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
  1193. {
  1194. nfs_delegation_clear_all(clp);
  1195. nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
  1196. }
  1197. static void nfs4_warn_keyexpired(const char *s)
  1198. {
  1199. printk_ratelimited(KERN_WARNING "Error: state manager"
  1200. " encountered RPCSEC_GSS session"
  1201. " expired against NFSv4 server %s.\n",
  1202. s);
  1203. }
  1204. static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
  1205. {
  1206. switch (error) {
  1207. case -NFS4ERR_CB_PATH_DOWN:
  1208. nfs_handle_cb_pathdown(clp);
  1209. return 0;
  1210. case -NFS4ERR_NO_GRACE:
  1211. nfs4_state_end_reclaim_reboot(clp);
  1212. return 0;
  1213. case -NFS4ERR_STALE_CLIENTID:
  1214. case -NFS4ERR_LEASE_MOVED:
  1215. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  1216. nfs4_state_clear_reclaim_reboot(clp);
  1217. nfs4_state_start_reclaim_reboot(clp);
  1218. break;
  1219. case -NFS4ERR_EXPIRED:
  1220. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  1221. nfs4_state_start_reclaim_nograce(clp);
  1222. break;
  1223. case -NFS4ERR_BADSESSION:
  1224. case -NFS4ERR_BADSLOT:
  1225. case -NFS4ERR_BAD_HIGH_SLOT:
  1226. case -NFS4ERR_DEADSESSION:
  1227. case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
  1228. case -NFS4ERR_SEQ_FALSE_RETRY:
  1229. case -NFS4ERR_SEQ_MISORDERED:
  1230. set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
  1231. /* Zero session reset errors */
  1232. return 0;
  1233. case -EKEYEXPIRED:
  1234. /* Nothing we can do */
  1235. nfs4_warn_keyexpired(clp->cl_hostname);
  1236. return 0;
  1237. }
  1238. return error;
  1239. }
  1240. static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
  1241. {
  1242. struct nfs4_state_owner *sp;
  1243. struct nfs_server *server;
  1244. struct rb_node *pos;
  1245. int status = 0;
  1246. restart:
  1247. rcu_read_lock();
  1248. list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
  1249. spin_lock(&clp->cl_lock);
  1250. for (pos = rb_first(&server->state_owners);
  1251. pos != NULL;
  1252. pos = rb_next(pos)) {
  1253. sp = rb_entry(pos,
  1254. struct nfs4_state_owner, so_server_node);
  1255. if (!test_and_clear_bit(ops->owner_flag_bit,
  1256. &sp->so_flags))
  1257. continue;
  1258. atomic_inc(&sp->so_count);
  1259. spin_unlock(&clp->cl_lock);
  1260. rcu_read_unlock();
  1261. status = nfs4_reclaim_open_state(sp, ops);
  1262. if (status < 0) {
  1263. set_bit(ops->owner_flag_bit, &sp->so_flags);
  1264. nfs4_put_state_owner(sp);
  1265. return nfs4_recovery_handle_error(clp, status);
  1266. }
  1267. nfs4_put_state_owner(sp);
  1268. goto restart;
  1269. }
  1270. spin_unlock(&clp->cl_lock);
  1271. }
  1272. rcu_read_unlock();
  1273. return status;
  1274. }
  1275. static int nfs4_check_lease(struct nfs_client *clp)
  1276. {
  1277. struct rpc_cred *cred;
  1278. const struct nfs4_state_maintenance_ops *ops =
  1279. clp->cl_mvops->state_renewal_ops;
  1280. int status = -NFS4ERR_EXPIRED;
  1281. /* Is the client already known to have an expired lease? */
  1282. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1283. return 0;
  1284. spin_lock(&clp->cl_lock);
  1285. cred = ops->get_state_renewal_cred_locked(clp);
  1286. spin_unlock(&clp->cl_lock);
  1287. if (cred == NULL) {
  1288. cred = nfs4_get_setclientid_cred(clp);
  1289. if (cred == NULL)
  1290. goto out;
  1291. }
  1292. status = ops->renew_lease(clp, cred);
  1293. put_rpccred(cred);
  1294. out:
  1295. return nfs4_recovery_handle_error(clp, status);
  1296. }
  1297. static int nfs4_reclaim_lease(struct nfs_client *clp)
  1298. {
  1299. struct rpc_cred *cred;
  1300. const struct nfs4_state_recovery_ops *ops =
  1301. clp->cl_mvops->reboot_recovery_ops;
  1302. int status = -ENOENT;
  1303. cred = ops->get_clid_cred(clp);
  1304. if (cred != NULL) {
  1305. status = ops->establish_clid(clp, cred);
  1306. put_rpccred(cred);
  1307. /* Handle case where the user hasn't set up machine creds */
  1308. if (status == -EACCES && cred == clp->cl_machine_cred) {
  1309. nfs4_clear_machine_cred(clp);
  1310. status = -EAGAIN;
  1311. }
  1312. if (status == -NFS4ERR_MINOR_VERS_MISMATCH)
  1313. status = -EPROTONOSUPPORT;
  1314. }
  1315. return status;
  1316. }
  1317. #ifdef CONFIG_NFS_V4_1
  1318. void nfs4_schedule_session_recovery(struct nfs4_session *session)
  1319. {
  1320. nfs4_schedule_lease_recovery(session->clp);
  1321. }
  1322. EXPORT_SYMBOL_GPL(nfs4_schedule_session_recovery);
  1323. void nfs41_handle_recall_slot(struct nfs_client *clp)
  1324. {
  1325. set_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
  1326. nfs4_schedule_state_manager(clp);
  1327. }
  1328. static void nfs4_reset_all_state(struct nfs_client *clp)
  1329. {
  1330. if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
  1331. clp->cl_boot_time = CURRENT_TIME;
  1332. nfs4_state_start_reclaim_nograce(clp);
  1333. nfs4_schedule_state_manager(clp);
  1334. }
  1335. }
  1336. static void nfs41_handle_server_reboot(struct nfs_client *clp)
  1337. {
  1338. if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
  1339. nfs4_state_start_reclaim_reboot(clp);
  1340. nfs4_schedule_state_manager(clp);
  1341. }
  1342. }
  1343. static void nfs41_handle_state_revoked(struct nfs_client *clp)
  1344. {
  1345. /* Temporary */
  1346. nfs4_reset_all_state(clp);
  1347. }
  1348. static void nfs41_handle_recallable_state_revoked(struct nfs_client *clp)
  1349. {
  1350. /* This will need to handle layouts too */
  1351. nfs_expire_all_delegations(clp);
  1352. }
  1353. static void nfs41_handle_cb_path_down(struct nfs_client *clp)
  1354. {
  1355. nfs_expire_all_delegations(clp);
  1356. if (test_and_set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) == 0)
  1357. nfs4_schedule_state_manager(clp);
  1358. }
  1359. void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags)
  1360. {
  1361. if (!flags)
  1362. return;
  1363. else if (flags & SEQ4_STATUS_RESTART_RECLAIM_NEEDED)
  1364. nfs41_handle_server_reboot(clp);
  1365. else if (flags & (SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED |
  1366. SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED |
  1367. SEQ4_STATUS_ADMIN_STATE_REVOKED |
  1368. SEQ4_STATUS_LEASE_MOVED))
  1369. nfs41_handle_state_revoked(clp);
  1370. else if (flags & SEQ4_STATUS_RECALLABLE_STATE_REVOKED)
  1371. nfs41_handle_recallable_state_revoked(clp);
  1372. else if (flags & (SEQ4_STATUS_CB_PATH_DOWN |
  1373. SEQ4_STATUS_BACKCHANNEL_FAULT |
  1374. SEQ4_STATUS_CB_PATH_DOWN_SESSION))
  1375. nfs41_handle_cb_path_down(clp);
  1376. }
  1377. static int nfs4_reset_session(struct nfs_client *clp)
  1378. {
  1379. int status;
  1380. nfs4_begin_drain_session(clp);
  1381. status = nfs4_proc_destroy_session(clp->cl_session);
  1382. if (status && status != -NFS4ERR_BADSESSION &&
  1383. status != -NFS4ERR_DEADSESSION) {
  1384. status = nfs4_recovery_handle_error(clp, status);
  1385. goto out;
  1386. }
  1387. memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN);
  1388. status = nfs4_proc_create_session(clp);
  1389. if (status) {
  1390. status = nfs4_recovery_handle_error(clp, status);
  1391. goto out;
  1392. }
  1393. /* create_session negotiated new slot table */
  1394. clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
  1395. /* Let the state manager reestablish state */
  1396. if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1397. nfs41_setup_state_renewal(clp);
  1398. out:
  1399. return status;
  1400. }
  1401. static int nfs4_recall_slot(struct nfs_client *clp)
  1402. {
  1403. struct nfs4_slot_table *fc_tbl = &clp->cl_session->fc_slot_table;
  1404. struct nfs4_channel_attrs *fc_attrs = &clp->cl_session->fc_attrs;
  1405. struct nfs4_slot *new, *old;
  1406. int i;
  1407. nfs4_begin_drain_session(clp);
  1408. new = kmalloc(fc_tbl->target_max_slots * sizeof(struct nfs4_slot),
  1409. GFP_NOFS);
  1410. if (!new)
  1411. return -ENOMEM;
  1412. spin_lock(&fc_tbl->slot_tbl_lock);
  1413. for (i = 0; i < fc_tbl->target_max_slots; i++)
  1414. new[i].seq_nr = fc_tbl->slots[i].seq_nr;
  1415. old = fc_tbl->slots;
  1416. fc_tbl->slots = new;
  1417. fc_tbl->max_slots = fc_tbl->target_max_slots;
  1418. fc_tbl->target_max_slots = 0;
  1419. fc_attrs->max_reqs = fc_tbl->max_slots;
  1420. spin_unlock(&fc_tbl->slot_tbl_lock);
  1421. kfree(old);
  1422. nfs4_end_drain_session(clp);
  1423. return 0;
  1424. }
  1425. #else /* CONFIG_NFS_V4_1 */
  1426. static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
  1427. static int nfs4_end_drain_session(struct nfs_client *clp) { return 0; }
  1428. static int nfs4_recall_slot(struct nfs_client *clp) { return 0; }
  1429. #endif /* CONFIG_NFS_V4_1 */
  1430. /* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
  1431. * on EXCHANGE_ID for v4.1
  1432. */
  1433. static void nfs4_set_lease_expired(struct nfs_client *clp, int status)
  1434. {
  1435. switch (status) {
  1436. case -NFS4ERR_CLID_INUSE:
  1437. case -NFS4ERR_STALE_CLIENTID:
  1438. clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  1439. break;
  1440. case -NFS4ERR_DELAY:
  1441. case -ETIMEDOUT:
  1442. case -EAGAIN:
  1443. ssleep(1);
  1444. break;
  1445. case -EKEYEXPIRED:
  1446. nfs4_warn_keyexpired(clp->cl_hostname);
  1447. case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
  1448. * in nfs4_exchange_id */
  1449. default:
  1450. return;
  1451. }
  1452. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  1453. }
  1454. static void nfs4_state_manager(struct nfs_client *clp)
  1455. {
  1456. int status = 0;
  1457. /* Ensure exclusive access to NFSv4 state */
  1458. do {
  1459. if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
  1460. /* We're going to have to re-establish a clientid */
  1461. status = nfs4_reclaim_lease(clp);
  1462. if (status) {
  1463. nfs4_set_lease_expired(clp, status);
  1464. if (test_bit(NFS4CLNT_LEASE_EXPIRED,
  1465. &clp->cl_state))
  1466. continue;
  1467. if (clp->cl_cons_state ==
  1468. NFS_CS_SESSION_INITING)
  1469. nfs_mark_client_ready(clp, status);
  1470. goto out_error;
  1471. }
  1472. clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
  1473. set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
  1474. pnfs_destroy_all_layouts(clp);
  1475. }
  1476. if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) {
  1477. status = nfs4_check_lease(clp);
  1478. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1479. continue;
  1480. if (status < 0 && status != -NFS4ERR_CB_PATH_DOWN)
  1481. goto out_error;
  1482. }
  1483. /* Initialize or reset the session */
  1484. if (test_and_clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)
  1485. && nfs4_has_session(clp)) {
  1486. status = nfs4_reset_session(clp);
  1487. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1488. continue;
  1489. if (status < 0)
  1490. goto out_error;
  1491. }
  1492. /* First recover reboot state... */
  1493. if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
  1494. status = nfs4_do_reclaim(clp,
  1495. clp->cl_mvops->reboot_recovery_ops);
  1496. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
  1497. test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
  1498. continue;
  1499. nfs4_state_end_reclaim_reboot(clp);
  1500. if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
  1501. continue;
  1502. if (status < 0)
  1503. goto out_error;
  1504. }
  1505. /* Now recover expired state... */
  1506. if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
  1507. status = nfs4_do_reclaim(clp,
  1508. clp->cl_mvops->nograce_recovery_ops);
  1509. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
  1510. test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
  1511. test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
  1512. continue;
  1513. if (status < 0)
  1514. goto out_error;
  1515. }
  1516. nfs4_end_drain_session(clp);
  1517. if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
  1518. nfs_client_return_marked_delegations(clp);
  1519. continue;
  1520. }
  1521. /* Recall session slots */
  1522. if (test_and_clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state)
  1523. && nfs4_has_session(clp)) {
  1524. status = nfs4_recall_slot(clp);
  1525. if (status < 0)
  1526. goto out_error;
  1527. continue;
  1528. }
  1529. nfs4_clear_state_manager_bit(clp);
  1530. /* Did we race with an attempt to give us more work? */
  1531. if (clp->cl_state == 0)
  1532. break;
  1533. if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
  1534. break;
  1535. } while (atomic_read(&clp->cl_count) > 1);
  1536. return;
  1537. out_error:
  1538. printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s"
  1539. " with error %d\n", clp->cl_hostname, -status);
  1540. nfs4_end_drain_session(clp);
  1541. nfs4_clear_state_manager_bit(clp);
  1542. }
  1543. static int nfs4_run_state_manager(void *ptr)
  1544. {
  1545. struct nfs_client *clp = ptr;
  1546. allow_signal(SIGKILL);
  1547. nfs4_state_manager(clp);
  1548. nfs_put_client(clp);
  1549. module_put_and_exit(0);
  1550. return 0;
  1551. }
  1552. /*
  1553. * Local variables:
  1554. * c-basic-offset: 8
  1555. * End:
  1556. */