vote.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * vote.c
  5. *
  6. * description here
  7. *
  8. * Copyright (C) 2003, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/types.h>
  26. #include <linux/slab.h>
  27. #include <linux/highmem.h>
  28. #include <linux/kthread.h>
  29. #include <cluster/heartbeat.h>
  30. #include <cluster/nodemanager.h>
  31. #include <cluster/tcp.h>
  32. #include <dlm/dlmapi.h>
  33. #define MLOG_MASK_PREFIX ML_VOTE
  34. #include <cluster/masklog.h>
  35. #include "ocfs2.h"
  36. #include "alloc.h"
  37. #include "dlmglue.h"
  38. #include "extent_map.h"
  39. #include "heartbeat.h"
  40. #include "inode.h"
  41. #include "journal.h"
  42. #include "slot_map.h"
  43. #include "vote.h"
  44. #include "buffer_head_io.h"
  45. #define OCFS2_MESSAGE_TYPE_VOTE (0x1)
  46. #define OCFS2_MESSAGE_TYPE_RESPONSE (0x2)
  47. struct ocfs2_msg_hdr
  48. {
  49. __be32 h_response_id; /* used to lookup message handle on sending
  50. * node. */
  51. __be32 h_request;
  52. __be64 h_blkno;
  53. __be32 h_generation;
  54. __be32 h_node_num; /* node sending this particular message. */
  55. };
  56. struct ocfs2_vote_msg
  57. {
  58. struct ocfs2_msg_hdr v_hdr;
  59. __be32 v_reserved1;
  60. } __attribute__ ((packed));
  61. /* Responses are given these values to maintain backwards
  62. * compatibility with older ocfs2 versions */
  63. #define OCFS2_RESPONSE_OK (0)
  64. #define OCFS2_RESPONSE_BUSY (-16)
  65. #define OCFS2_RESPONSE_BAD_MSG (-22)
  66. struct ocfs2_response_msg
  67. {
  68. struct ocfs2_msg_hdr r_hdr;
  69. __be32 r_response;
  70. } __attribute__ ((packed));
  71. struct ocfs2_vote_work {
  72. struct list_head w_list;
  73. struct ocfs2_vote_msg w_msg;
  74. };
  75. enum ocfs2_vote_request {
  76. OCFS2_VOTE_REQ_INVALID = 0,
  77. OCFS2_VOTE_REQ_MOUNT,
  78. OCFS2_VOTE_REQ_UMOUNT,
  79. OCFS2_VOTE_REQ_LAST
  80. };
  81. static inline int ocfs2_is_valid_vote_request(int request)
  82. {
  83. return OCFS2_VOTE_REQ_INVALID < request &&
  84. request < OCFS2_VOTE_REQ_LAST;
  85. }
  86. typedef void (*ocfs2_net_response_callback)(void *priv,
  87. struct ocfs2_response_msg *resp);
  88. struct ocfs2_net_response_cb {
  89. ocfs2_net_response_callback rc_cb;
  90. void *rc_priv;
  91. };
  92. struct ocfs2_net_wait_ctxt {
  93. struct list_head n_list;
  94. u32 n_response_id;
  95. wait_queue_head_t n_event;
  96. struct ocfs2_node_map n_node_map;
  97. int n_response; /* an agreggate response. 0 if
  98. * all nodes are go, < 0 on any
  99. * negative response from any
  100. * node or network error. */
  101. struct ocfs2_net_response_cb *n_callback;
  102. };
  103. static void ocfs2_process_mount_request(struct ocfs2_super *osb,
  104. unsigned int node_num)
  105. {
  106. mlog(0, "MOUNT vote from node %u\n", node_num);
  107. /* The other node only sends us this message when he has an EX
  108. * on the superblock, so our recovery threads (if having been
  109. * launched) are waiting on it.*/
  110. ocfs2_recovery_map_clear(osb, node_num);
  111. ocfs2_node_map_set_bit(osb, &osb->mounted_map, node_num);
  112. /* We clear the umount map here because a node may have been
  113. * previously mounted, safely unmounted but never stopped
  114. * heartbeating - in which case we'd have a stale entry. */
  115. ocfs2_node_map_clear_bit(osb, &osb->umount_map, node_num);
  116. }
  117. static void ocfs2_process_umount_request(struct ocfs2_super *osb,
  118. unsigned int node_num)
  119. {
  120. mlog(0, "UMOUNT vote from node %u\n", node_num);
  121. ocfs2_node_map_clear_bit(osb, &osb->mounted_map, node_num);
  122. ocfs2_node_map_set_bit(osb, &osb->umount_map, node_num);
  123. }
  124. static void ocfs2_process_vote(struct ocfs2_super *osb,
  125. struct ocfs2_vote_msg *msg)
  126. {
  127. int net_status, vote_response;
  128. unsigned int node_num;
  129. u64 blkno;
  130. enum ocfs2_vote_request request;
  131. struct ocfs2_msg_hdr *hdr = &msg->v_hdr;
  132. struct ocfs2_response_msg response;
  133. /* decode the network mumbo jumbo into local variables. */
  134. request = be32_to_cpu(hdr->h_request);
  135. blkno = be64_to_cpu(hdr->h_blkno);
  136. node_num = be32_to_cpu(hdr->h_node_num);
  137. mlog(0, "processing vote: request = %u, blkno = %llu, node_num = %u\n",
  138. request, (unsigned long long)blkno, node_num);
  139. if (!ocfs2_is_valid_vote_request(request)) {
  140. mlog(ML_ERROR, "Invalid vote request %d from node %u\n",
  141. request, node_num);
  142. vote_response = OCFS2_RESPONSE_BAD_MSG;
  143. goto respond;
  144. }
  145. vote_response = OCFS2_RESPONSE_OK;
  146. switch (request) {
  147. case OCFS2_VOTE_REQ_UMOUNT:
  148. ocfs2_process_umount_request(osb, node_num);
  149. goto respond;
  150. case OCFS2_VOTE_REQ_MOUNT:
  151. ocfs2_process_mount_request(osb, node_num);
  152. goto respond;
  153. default:
  154. /* avoids a gcc warning */
  155. break;
  156. }
  157. respond:
  158. /* Response struture is small so we just put it on the stack
  159. * and stuff it inline. */
  160. memset(&response, 0, sizeof(struct ocfs2_response_msg));
  161. response.r_hdr.h_response_id = hdr->h_response_id;
  162. response.r_hdr.h_blkno = hdr->h_blkno;
  163. response.r_hdr.h_generation = hdr->h_generation;
  164. response.r_hdr.h_node_num = cpu_to_be32(osb->node_num);
  165. response.r_response = cpu_to_be32(vote_response);
  166. net_status = o2net_send_message(OCFS2_MESSAGE_TYPE_RESPONSE,
  167. osb->net_key,
  168. &response,
  169. sizeof(struct ocfs2_response_msg),
  170. node_num,
  171. NULL);
  172. /* We still want to error print for ENOPROTOOPT here. The
  173. * sending node shouldn't have unregistered his net handler
  174. * without sending an unmount vote 1st */
  175. if (net_status < 0
  176. && net_status != -ETIMEDOUT
  177. && net_status != -ENOTCONN)
  178. mlog(ML_ERROR, "message to node %u fails with error %d!\n",
  179. node_num, net_status);
  180. }
  181. static void ocfs2_vote_thread_do_work(struct ocfs2_super *osb)
  182. {
  183. unsigned long processed;
  184. struct ocfs2_lock_res *lockres;
  185. struct ocfs2_vote_work *work;
  186. mlog_entry_void();
  187. spin_lock(&osb->vote_task_lock);
  188. /* grab this early so we know to try again if a state change and
  189. * wake happens part-way through our work */
  190. osb->vote_work_sequence = osb->vote_wake_sequence;
  191. processed = osb->blocked_lock_count;
  192. while (processed) {
  193. BUG_ON(list_empty(&osb->blocked_lock_list));
  194. lockres = list_entry(osb->blocked_lock_list.next,
  195. struct ocfs2_lock_res, l_blocked_list);
  196. list_del_init(&lockres->l_blocked_list);
  197. osb->blocked_lock_count--;
  198. spin_unlock(&osb->vote_task_lock);
  199. BUG_ON(!processed);
  200. processed--;
  201. ocfs2_process_blocked_lock(osb, lockres);
  202. spin_lock(&osb->vote_task_lock);
  203. }
  204. while (osb->vote_count) {
  205. BUG_ON(list_empty(&osb->vote_list));
  206. work = list_entry(osb->vote_list.next,
  207. struct ocfs2_vote_work, w_list);
  208. list_del(&work->w_list);
  209. osb->vote_count--;
  210. spin_unlock(&osb->vote_task_lock);
  211. ocfs2_process_vote(osb, &work->w_msg);
  212. kfree(work);
  213. spin_lock(&osb->vote_task_lock);
  214. }
  215. spin_unlock(&osb->vote_task_lock);
  216. mlog_exit_void();
  217. }
  218. static int ocfs2_vote_thread_lists_empty(struct ocfs2_super *osb)
  219. {
  220. int empty = 0;
  221. spin_lock(&osb->vote_task_lock);
  222. if (list_empty(&osb->blocked_lock_list) &&
  223. list_empty(&osb->vote_list))
  224. empty = 1;
  225. spin_unlock(&osb->vote_task_lock);
  226. return empty;
  227. }
  228. static int ocfs2_vote_thread_should_wake(struct ocfs2_super *osb)
  229. {
  230. int should_wake = 0;
  231. spin_lock(&osb->vote_task_lock);
  232. if (osb->vote_work_sequence != osb->vote_wake_sequence)
  233. should_wake = 1;
  234. spin_unlock(&osb->vote_task_lock);
  235. return should_wake;
  236. }
  237. int ocfs2_vote_thread(void *arg)
  238. {
  239. int status = 0;
  240. struct ocfs2_super *osb = arg;
  241. /* only quit once we've been asked to stop and there is no more
  242. * work available */
  243. while (!(kthread_should_stop() &&
  244. ocfs2_vote_thread_lists_empty(osb))) {
  245. wait_event_interruptible(osb->vote_event,
  246. ocfs2_vote_thread_should_wake(osb) ||
  247. kthread_should_stop());
  248. mlog(0, "vote_thread: awoken\n");
  249. ocfs2_vote_thread_do_work(osb);
  250. }
  251. osb->vote_task = NULL;
  252. return status;
  253. }
  254. static struct ocfs2_net_wait_ctxt *ocfs2_new_net_wait_ctxt(unsigned int response_id)
  255. {
  256. struct ocfs2_net_wait_ctxt *w;
  257. w = kzalloc(sizeof(*w), GFP_NOFS);
  258. if (!w) {
  259. mlog_errno(-ENOMEM);
  260. goto bail;
  261. }
  262. INIT_LIST_HEAD(&w->n_list);
  263. init_waitqueue_head(&w->n_event);
  264. ocfs2_node_map_init(&w->n_node_map);
  265. w->n_response_id = response_id;
  266. w->n_callback = NULL;
  267. bail:
  268. return w;
  269. }
  270. static unsigned int ocfs2_new_response_id(struct ocfs2_super *osb)
  271. {
  272. unsigned int ret;
  273. spin_lock(&osb->net_response_lock);
  274. ret = ++osb->net_response_ids;
  275. spin_unlock(&osb->net_response_lock);
  276. return ret;
  277. }
  278. static void ocfs2_dequeue_net_wait_ctxt(struct ocfs2_super *osb,
  279. struct ocfs2_net_wait_ctxt *w)
  280. {
  281. spin_lock(&osb->net_response_lock);
  282. list_del(&w->n_list);
  283. spin_unlock(&osb->net_response_lock);
  284. }
  285. static void ocfs2_queue_net_wait_ctxt(struct ocfs2_super *osb,
  286. struct ocfs2_net_wait_ctxt *w)
  287. {
  288. spin_lock(&osb->net_response_lock);
  289. list_add_tail(&w->n_list,
  290. &osb->net_response_list);
  291. spin_unlock(&osb->net_response_lock);
  292. }
  293. static void __ocfs2_mark_node_responded(struct ocfs2_super *osb,
  294. struct ocfs2_net_wait_ctxt *w,
  295. int node_num)
  296. {
  297. assert_spin_locked(&osb->net_response_lock);
  298. ocfs2_node_map_clear_bit(osb, &w->n_node_map, node_num);
  299. if (ocfs2_node_map_is_empty(osb, &w->n_node_map))
  300. wake_up(&w->n_event);
  301. }
  302. /* Intended to be called from the node down callback, we fake remove
  303. * the node from all our response contexts */
  304. void ocfs2_remove_node_from_vote_queues(struct ocfs2_super *osb,
  305. int node_num)
  306. {
  307. struct list_head *p;
  308. struct ocfs2_net_wait_ctxt *w = NULL;
  309. spin_lock(&osb->net_response_lock);
  310. list_for_each(p, &osb->net_response_list) {
  311. w = list_entry(p, struct ocfs2_net_wait_ctxt, n_list);
  312. __ocfs2_mark_node_responded(osb, w, node_num);
  313. }
  314. spin_unlock(&osb->net_response_lock);
  315. }
  316. static int ocfs2_broadcast_vote(struct ocfs2_super *osb,
  317. struct ocfs2_vote_msg *request,
  318. unsigned int response_id,
  319. int *response,
  320. struct ocfs2_net_response_cb *callback)
  321. {
  322. int status, i, remote_err;
  323. struct ocfs2_net_wait_ctxt *w = NULL;
  324. int dequeued = 0;
  325. mlog_entry_void();
  326. w = ocfs2_new_net_wait_ctxt(response_id);
  327. if (!w) {
  328. status = -ENOMEM;
  329. mlog_errno(status);
  330. goto bail;
  331. }
  332. w->n_callback = callback;
  333. /* we're pretty much ready to go at this point, and this fills
  334. * in n_response which we need anyway... */
  335. ocfs2_queue_net_wait_ctxt(osb, w);
  336. i = ocfs2_node_map_iterate(osb, &osb->mounted_map, 0);
  337. while (i != O2NM_INVALID_NODE_NUM) {
  338. if (i != osb->node_num) {
  339. mlog(0, "trying to send request to node %i\n", i);
  340. ocfs2_node_map_set_bit(osb, &w->n_node_map, i);
  341. remote_err = 0;
  342. status = o2net_send_message(OCFS2_MESSAGE_TYPE_VOTE,
  343. osb->net_key,
  344. request,
  345. sizeof(*request),
  346. i,
  347. &remote_err);
  348. if (status == -ETIMEDOUT) {
  349. mlog(0, "remote node %d timed out!\n", i);
  350. status = -EAGAIN;
  351. goto bail;
  352. }
  353. if (remote_err < 0) {
  354. status = remote_err;
  355. mlog(0, "remote error %d on node %d!\n",
  356. remote_err, i);
  357. mlog_errno(status);
  358. goto bail;
  359. }
  360. if (status < 0) {
  361. mlog_errno(status);
  362. goto bail;
  363. }
  364. }
  365. i++;
  366. i = ocfs2_node_map_iterate(osb, &osb->mounted_map, i);
  367. mlog(0, "next is %d, i am %d\n", i, osb->node_num);
  368. }
  369. mlog(0, "done sending, now waiting on responses...\n");
  370. wait_event(w->n_event, ocfs2_node_map_is_empty(osb, &w->n_node_map));
  371. ocfs2_dequeue_net_wait_ctxt(osb, w);
  372. dequeued = 1;
  373. *response = w->n_response;
  374. status = 0;
  375. bail:
  376. if (w) {
  377. if (!dequeued)
  378. ocfs2_dequeue_net_wait_ctxt(osb, w);
  379. kfree(w);
  380. }
  381. mlog_exit(status);
  382. return status;
  383. }
  384. static struct ocfs2_vote_msg * ocfs2_new_vote_request(struct ocfs2_super *osb,
  385. u64 blkno,
  386. unsigned int generation,
  387. enum ocfs2_vote_request type)
  388. {
  389. struct ocfs2_vote_msg *request;
  390. struct ocfs2_msg_hdr *hdr;
  391. BUG_ON(!ocfs2_is_valid_vote_request(type));
  392. request = kzalloc(sizeof(*request), GFP_NOFS);
  393. if (!request) {
  394. mlog_errno(-ENOMEM);
  395. } else {
  396. hdr = &request->v_hdr;
  397. hdr->h_node_num = cpu_to_be32(osb->node_num);
  398. hdr->h_request = cpu_to_be32(type);
  399. hdr->h_blkno = cpu_to_be64(blkno);
  400. hdr->h_generation = cpu_to_be32(generation);
  401. }
  402. return request;
  403. }
  404. /* Complete the buildup of a new vote request and process the
  405. * broadcast return value. */
  406. static int ocfs2_do_request_vote(struct ocfs2_super *osb,
  407. struct ocfs2_vote_msg *request,
  408. struct ocfs2_net_response_cb *callback)
  409. {
  410. int status, response = -EBUSY;
  411. unsigned int response_id;
  412. struct ocfs2_msg_hdr *hdr;
  413. response_id = ocfs2_new_response_id(osb);
  414. hdr = &request->v_hdr;
  415. hdr->h_response_id = cpu_to_be32(response_id);
  416. status = ocfs2_broadcast_vote(osb, request, response_id, &response,
  417. callback);
  418. if (status < 0) {
  419. mlog_errno(status);
  420. goto bail;
  421. }
  422. status = response;
  423. bail:
  424. return status;
  425. }
  426. int ocfs2_request_mount_vote(struct ocfs2_super *osb)
  427. {
  428. int status;
  429. struct ocfs2_vote_msg *request = NULL;
  430. request = ocfs2_new_vote_request(osb, 0ULL, 0, OCFS2_VOTE_REQ_MOUNT);
  431. if (!request) {
  432. status = -ENOMEM;
  433. goto bail;
  434. }
  435. status = -EAGAIN;
  436. while (status == -EAGAIN) {
  437. if (!(osb->s_mount_opt & OCFS2_MOUNT_NOINTR) &&
  438. signal_pending(current)) {
  439. status = -ERESTARTSYS;
  440. goto bail;
  441. }
  442. if (ocfs2_node_map_is_only(osb, &osb->mounted_map,
  443. osb->node_num)) {
  444. status = 0;
  445. goto bail;
  446. }
  447. status = ocfs2_do_request_vote(osb, request, NULL);
  448. }
  449. bail:
  450. kfree(request);
  451. return status;
  452. }
  453. int ocfs2_request_umount_vote(struct ocfs2_super *osb)
  454. {
  455. int status;
  456. struct ocfs2_vote_msg *request = NULL;
  457. request = ocfs2_new_vote_request(osb, 0ULL, 0, OCFS2_VOTE_REQ_UMOUNT);
  458. if (!request) {
  459. status = -ENOMEM;
  460. goto bail;
  461. }
  462. status = -EAGAIN;
  463. while (status == -EAGAIN) {
  464. /* Do not check signals on this vote... We really want
  465. * this one to go all the way through. */
  466. if (ocfs2_node_map_is_only(osb, &osb->mounted_map,
  467. osb->node_num)) {
  468. status = 0;
  469. goto bail;
  470. }
  471. status = ocfs2_do_request_vote(osb, request, NULL);
  472. }
  473. bail:
  474. kfree(request);
  475. return status;
  476. }
  477. /* TODO: This should eventually be a hash table! */
  478. static struct ocfs2_net_wait_ctxt * __ocfs2_find_net_wait_ctxt(struct ocfs2_super *osb,
  479. u32 response_id)
  480. {
  481. struct list_head *p;
  482. struct ocfs2_net_wait_ctxt *w = NULL;
  483. list_for_each(p, &osb->net_response_list) {
  484. w = list_entry(p, struct ocfs2_net_wait_ctxt, n_list);
  485. if (response_id == w->n_response_id)
  486. break;
  487. w = NULL;
  488. }
  489. return w;
  490. }
  491. /* Translate response codes into local node errno values */
  492. static inline int ocfs2_translate_response(int response)
  493. {
  494. int ret;
  495. switch (response) {
  496. case OCFS2_RESPONSE_OK:
  497. ret = 0;
  498. break;
  499. case OCFS2_RESPONSE_BUSY:
  500. ret = -EBUSY;
  501. break;
  502. default:
  503. ret = -EINVAL;
  504. }
  505. return ret;
  506. }
  507. static int ocfs2_handle_response_message(struct o2net_msg *msg,
  508. u32 len,
  509. void *data, void **ret_data)
  510. {
  511. unsigned int response_id, node_num;
  512. int response_status;
  513. struct ocfs2_super *osb = data;
  514. struct ocfs2_response_msg *resp;
  515. struct ocfs2_net_wait_ctxt * w;
  516. struct ocfs2_net_response_cb *resp_cb;
  517. resp = (struct ocfs2_response_msg *) msg->buf;
  518. response_id = be32_to_cpu(resp->r_hdr.h_response_id);
  519. node_num = be32_to_cpu(resp->r_hdr.h_node_num);
  520. response_status =
  521. ocfs2_translate_response(be32_to_cpu(resp->r_response));
  522. mlog(0, "received response message:\n");
  523. mlog(0, "h_response_id = %u\n", response_id);
  524. mlog(0, "h_request = %u\n", be32_to_cpu(resp->r_hdr.h_request));
  525. mlog(0, "h_blkno = %llu\n",
  526. (unsigned long long)be64_to_cpu(resp->r_hdr.h_blkno));
  527. mlog(0, "h_generation = %u\n", be32_to_cpu(resp->r_hdr.h_generation));
  528. mlog(0, "h_node_num = %u\n", node_num);
  529. mlog(0, "r_response = %d\n", response_status);
  530. spin_lock(&osb->net_response_lock);
  531. w = __ocfs2_find_net_wait_ctxt(osb, response_id);
  532. if (!w) {
  533. mlog(0, "request not found!\n");
  534. goto bail;
  535. }
  536. resp_cb = w->n_callback;
  537. if (response_status && (!w->n_response)) {
  538. /* we only really need one negative response so don't
  539. * set it twice. */
  540. w->n_response = response_status;
  541. }
  542. if (resp_cb) {
  543. spin_unlock(&osb->net_response_lock);
  544. resp_cb->rc_cb(resp_cb->rc_priv, resp);
  545. spin_lock(&osb->net_response_lock);
  546. }
  547. __ocfs2_mark_node_responded(osb, w, node_num);
  548. bail:
  549. spin_unlock(&osb->net_response_lock);
  550. return 0;
  551. }
  552. static int ocfs2_handle_vote_message(struct o2net_msg *msg,
  553. u32 len,
  554. void *data, void **ret_data)
  555. {
  556. int status;
  557. struct ocfs2_super *osb = data;
  558. struct ocfs2_vote_work *work;
  559. work = kmalloc(sizeof(struct ocfs2_vote_work), GFP_NOFS);
  560. if (!work) {
  561. status = -ENOMEM;
  562. mlog_errno(status);
  563. goto bail;
  564. }
  565. INIT_LIST_HEAD(&work->w_list);
  566. memcpy(&work->w_msg, msg->buf, sizeof(struct ocfs2_vote_msg));
  567. mlog(0, "scheduling vote request:\n");
  568. mlog(0, "h_response_id = %u\n",
  569. be32_to_cpu(work->w_msg.v_hdr.h_response_id));
  570. mlog(0, "h_request = %u\n", be32_to_cpu(work->w_msg.v_hdr.h_request));
  571. mlog(0, "h_blkno = %llu\n",
  572. (unsigned long long)be64_to_cpu(work->w_msg.v_hdr.h_blkno));
  573. mlog(0, "h_generation = %u\n",
  574. be32_to_cpu(work->w_msg.v_hdr.h_generation));
  575. mlog(0, "h_node_num = %u\n",
  576. be32_to_cpu(work->w_msg.v_hdr.h_node_num));
  577. spin_lock(&osb->vote_task_lock);
  578. list_add_tail(&work->w_list, &osb->vote_list);
  579. osb->vote_count++;
  580. spin_unlock(&osb->vote_task_lock);
  581. ocfs2_kick_vote_thread(osb);
  582. status = 0;
  583. bail:
  584. return status;
  585. }
  586. void ocfs2_unregister_net_handlers(struct ocfs2_super *osb)
  587. {
  588. if (!osb->net_key)
  589. return;
  590. o2net_unregister_handler_list(&osb->osb_net_handlers);
  591. if (!list_empty(&osb->net_response_list))
  592. mlog(ML_ERROR, "net response list not empty!\n");
  593. osb->net_key = 0;
  594. }
  595. int ocfs2_register_net_handlers(struct ocfs2_super *osb)
  596. {
  597. int status = 0;
  598. if (ocfs2_mount_local(osb))
  599. return 0;
  600. status = o2net_register_handler(OCFS2_MESSAGE_TYPE_RESPONSE,
  601. osb->net_key,
  602. sizeof(struct ocfs2_response_msg),
  603. ocfs2_handle_response_message,
  604. osb, NULL, &osb->osb_net_handlers);
  605. if (status) {
  606. mlog_errno(status);
  607. goto bail;
  608. }
  609. status = o2net_register_handler(OCFS2_MESSAGE_TYPE_VOTE,
  610. osb->net_key,
  611. sizeof(struct ocfs2_vote_msg),
  612. ocfs2_handle_vote_message,
  613. osb, NULL, &osb->osb_net_handlers);
  614. if (status) {
  615. mlog_errno(status);
  616. goto bail;
  617. }
  618. bail:
  619. if (status < 0)
  620. ocfs2_unregister_net_handlers(osb);
  621. return status;
  622. }