nfs4state.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. struct nfs_client *clp = session->clp;
  1321. set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
  1322. nfs4_schedule_lease_recovery(clp);
  1323. }
  1324. EXPORT_SYMBOL_GPL(nfs4_schedule_session_recovery);
  1325. void nfs41_handle_recall_slot(struct nfs_client *clp)
  1326. {
  1327. set_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
  1328. nfs4_schedule_state_manager(clp);
  1329. }
  1330. static void nfs4_reset_all_state(struct nfs_client *clp)
  1331. {
  1332. if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
  1333. clp->cl_boot_time = CURRENT_TIME;
  1334. nfs4_state_start_reclaim_nograce(clp);
  1335. nfs4_schedule_state_manager(clp);
  1336. }
  1337. }
  1338. static void nfs41_handle_server_reboot(struct nfs_client *clp)
  1339. {
  1340. if (test_and_set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) == 0) {
  1341. nfs4_state_start_reclaim_reboot(clp);
  1342. nfs4_schedule_state_manager(clp);
  1343. }
  1344. }
  1345. static void nfs41_handle_state_revoked(struct nfs_client *clp)
  1346. {
  1347. /* Temporary */
  1348. nfs4_reset_all_state(clp);
  1349. }
  1350. static void nfs41_handle_recallable_state_revoked(struct nfs_client *clp)
  1351. {
  1352. /* This will need to handle layouts too */
  1353. nfs_expire_all_delegations(clp);
  1354. }
  1355. static void nfs41_handle_cb_path_down(struct nfs_client *clp)
  1356. {
  1357. nfs_expire_all_delegations(clp);
  1358. if (test_and_set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) == 0)
  1359. nfs4_schedule_state_manager(clp);
  1360. }
  1361. void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags)
  1362. {
  1363. if (!flags)
  1364. return;
  1365. else if (flags & SEQ4_STATUS_RESTART_RECLAIM_NEEDED)
  1366. nfs41_handle_server_reboot(clp);
  1367. else if (flags & (SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED |
  1368. SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED |
  1369. SEQ4_STATUS_ADMIN_STATE_REVOKED |
  1370. SEQ4_STATUS_LEASE_MOVED))
  1371. nfs41_handle_state_revoked(clp);
  1372. else if (flags & SEQ4_STATUS_RECALLABLE_STATE_REVOKED)
  1373. nfs41_handle_recallable_state_revoked(clp);
  1374. else if (flags & (SEQ4_STATUS_CB_PATH_DOWN |
  1375. SEQ4_STATUS_BACKCHANNEL_FAULT |
  1376. SEQ4_STATUS_CB_PATH_DOWN_SESSION))
  1377. nfs41_handle_cb_path_down(clp);
  1378. }
  1379. static int nfs4_reset_session(struct nfs_client *clp)
  1380. {
  1381. int status;
  1382. nfs4_begin_drain_session(clp);
  1383. status = nfs4_proc_destroy_session(clp->cl_session);
  1384. if (status && status != -NFS4ERR_BADSESSION &&
  1385. status != -NFS4ERR_DEADSESSION) {
  1386. status = nfs4_recovery_handle_error(clp, status);
  1387. goto out;
  1388. }
  1389. memset(clp->cl_session->sess_id.data, 0, NFS4_MAX_SESSIONID_LEN);
  1390. status = nfs4_proc_create_session(clp);
  1391. if (status) {
  1392. status = nfs4_recovery_handle_error(clp, status);
  1393. goto out;
  1394. }
  1395. clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
  1396. /* create_session negotiated new slot table */
  1397. clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
  1398. /* Let the state manager reestablish state */
  1399. if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1400. nfs41_setup_state_renewal(clp);
  1401. out:
  1402. return status;
  1403. }
  1404. static int nfs4_recall_slot(struct nfs_client *clp)
  1405. {
  1406. struct nfs4_slot_table *fc_tbl = &clp->cl_session->fc_slot_table;
  1407. struct nfs4_channel_attrs *fc_attrs = &clp->cl_session->fc_attrs;
  1408. struct nfs4_slot *new, *old;
  1409. int i;
  1410. nfs4_begin_drain_session(clp);
  1411. new = kmalloc(fc_tbl->target_max_slots * sizeof(struct nfs4_slot),
  1412. GFP_NOFS);
  1413. if (!new)
  1414. return -ENOMEM;
  1415. spin_lock(&fc_tbl->slot_tbl_lock);
  1416. for (i = 0; i < fc_tbl->target_max_slots; i++)
  1417. new[i].seq_nr = fc_tbl->slots[i].seq_nr;
  1418. old = fc_tbl->slots;
  1419. fc_tbl->slots = new;
  1420. fc_tbl->max_slots = fc_tbl->target_max_slots;
  1421. fc_tbl->target_max_slots = 0;
  1422. fc_attrs->max_reqs = fc_tbl->max_slots;
  1423. spin_unlock(&fc_tbl->slot_tbl_lock);
  1424. kfree(old);
  1425. nfs4_end_drain_session(clp);
  1426. return 0;
  1427. }
  1428. #else /* CONFIG_NFS_V4_1 */
  1429. static int nfs4_reset_session(struct nfs_client *clp) { return 0; }
  1430. static int nfs4_end_drain_session(struct nfs_client *clp) { return 0; }
  1431. static int nfs4_recall_slot(struct nfs_client *clp) { return 0; }
  1432. #endif /* CONFIG_NFS_V4_1 */
  1433. /* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
  1434. * on EXCHANGE_ID for v4.1
  1435. */
  1436. static void nfs4_set_lease_expired(struct nfs_client *clp, int status)
  1437. {
  1438. switch (status) {
  1439. case -NFS4ERR_CLID_INUSE:
  1440. case -NFS4ERR_STALE_CLIENTID:
  1441. clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
  1442. break;
  1443. case -NFS4ERR_DELAY:
  1444. case -ETIMEDOUT:
  1445. case -EAGAIN:
  1446. ssleep(1);
  1447. break;
  1448. case -EKEYEXPIRED:
  1449. nfs4_warn_keyexpired(clp->cl_hostname);
  1450. case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
  1451. * in nfs4_exchange_id */
  1452. default:
  1453. return;
  1454. }
  1455. set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
  1456. }
  1457. static void nfs4_state_manager(struct nfs_client *clp)
  1458. {
  1459. int status = 0;
  1460. /* Ensure exclusive access to NFSv4 state */
  1461. do {
  1462. if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
  1463. /* We're going to have to re-establish a clientid */
  1464. status = nfs4_reclaim_lease(clp);
  1465. if (status) {
  1466. nfs4_set_lease_expired(clp, status);
  1467. if (test_bit(NFS4CLNT_LEASE_EXPIRED,
  1468. &clp->cl_state))
  1469. continue;
  1470. if (clp->cl_cons_state ==
  1471. NFS_CS_SESSION_INITING)
  1472. nfs_mark_client_ready(clp, status);
  1473. goto out_error;
  1474. }
  1475. clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
  1476. set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
  1477. pnfs_destroy_all_layouts(clp);
  1478. }
  1479. if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state)) {
  1480. status = nfs4_check_lease(clp);
  1481. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1482. continue;
  1483. if (status < 0 && status != -NFS4ERR_CB_PATH_DOWN)
  1484. goto out_error;
  1485. }
  1486. /* Initialize or reset the session */
  1487. if (test_and_clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state)
  1488. && nfs4_has_session(clp)) {
  1489. status = nfs4_reset_session(clp);
  1490. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
  1491. continue;
  1492. if (status < 0)
  1493. goto out_error;
  1494. }
  1495. /* First recover reboot state... */
  1496. if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
  1497. status = nfs4_do_reclaim(clp,
  1498. clp->cl_mvops->reboot_recovery_ops);
  1499. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
  1500. test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
  1501. continue;
  1502. nfs4_state_end_reclaim_reboot(clp);
  1503. if (test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
  1504. continue;
  1505. if (status < 0)
  1506. goto out_error;
  1507. }
  1508. /* Now recover expired state... */
  1509. if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
  1510. status = nfs4_do_reclaim(clp,
  1511. clp->cl_mvops->nograce_recovery_ops);
  1512. if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
  1513. test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
  1514. test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
  1515. continue;
  1516. if (status < 0)
  1517. goto out_error;
  1518. }
  1519. nfs4_end_drain_session(clp);
  1520. if (test_and_clear_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) {
  1521. nfs_client_return_marked_delegations(clp);
  1522. continue;
  1523. }
  1524. /* Recall session slots */
  1525. if (test_and_clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state)
  1526. && nfs4_has_session(clp)) {
  1527. status = nfs4_recall_slot(clp);
  1528. if (status < 0)
  1529. goto out_error;
  1530. continue;
  1531. }
  1532. nfs4_clear_state_manager_bit(clp);
  1533. /* Did we race with an attempt to give us more work? */
  1534. if (clp->cl_state == 0)
  1535. break;
  1536. if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
  1537. break;
  1538. } while (atomic_read(&clp->cl_count) > 1);
  1539. return;
  1540. out_error:
  1541. printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s"
  1542. " with error %d\n", clp->cl_hostname, -status);
  1543. nfs4_end_drain_session(clp);
  1544. nfs4_clear_state_manager_bit(clp);
  1545. }
  1546. static int nfs4_run_state_manager(void *ptr)
  1547. {
  1548. struct nfs_client *clp = ptr;
  1549. allow_signal(SIGKILL);
  1550. nfs4_state_manager(clp);
  1551. nfs_put_client(clp);
  1552. module_put_and_exit(0);
  1553. return 0;
  1554. }
  1555. /*
  1556. * Local variables:
  1557. * c-basic-offset: 8
  1558. * End:
  1559. */