heartbeat.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * heartbeat.c
  5. *
  6. * Register ourselves with the heartbaet service, keep our node maps
  7. * up to date, and fire off recovery when needed.
  8. *
  9. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public
  22. * License along with this program; if not, write to the
  23. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. * Boston, MA 021110-1307, USA.
  25. */
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/highmem.h>
  29. #include <cluster/masklog.h>
  30. #include "ocfs2.h"
  31. #include "alloc.h"
  32. #include "heartbeat.h"
  33. #include "inode.h"
  34. #include "journal.h"
  35. #include "ocfs2_trace.h"
  36. #include "buffer_head_io.h"
  37. static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
  38. int bit);
  39. static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
  40. int bit);
  41. /* special case -1 for now
  42. * TODO: should *really* make sure the calling func never passes -1!! */
  43. static void ocfs2_node_map_init(struct ocfs2_node_map *map)
  44. {
  45. map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
  46. memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
  47. sizeof(unsigned long));
  48. }
  49. void ocfs2_init_node_maps(struct ocfs2_super *osb)
  50. {
  51. spin_lock_init(&osb->node_map_lock);
  52. ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
  53. }
  54. void ocfs2_do_node_down(int node_num, void *data)
  55. {
  56. struct ocfs2_super *osb = data;
  57. BUG_ON(osb->node_num == node_num);
  58. trace_ocfs2_do_node_down(node_num);
  59. if (!osb->cconn) {
  60. /*
  61. * No cluster connection means we're not even ready to
  62. * participate yet. We check the slots after the cluster
  63. * comes up, so we will notice the node death then. We
  64. * can safely ignore it here.
  65. */
  66. return;
  67. }
  68. ocfs2_recovery_thread(osb, node_num);
  69. }
  70. static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
  71. int bit)
  72. {
  73. set_bit(bit, map->map);
  74. }
  75. void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
  76. struct ocfs2_node_map *map,
  77. int bit)
  78. {
  79. if (bit==-1)
  80. return;
  81. BUG_ON(bit >= map->num_nodes);
  82. spin_lock(&osb->node_map_lock);
  83. __ocfs2_node_map_set_bit(map, bit);
  84. spin_unlock(&osb->node_map_lock);
  85. }
  86. static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
  87. int bit)
  88. {
  89. clear_bit(bit, map->map);
  90. }
  91. void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
  92. struct ocfs2_node_map *map,
  93. int bit)
  94. {
  95. if (bit==-1)
  96. return;
  97. BUG_ON(bit >= map->num_nodes);
  98. spin_lock(&osb->node_map_lock);
  99. __ocfs2_node_map_clear_bit(map, bit);
  100. spin_unlock(&osb->node_map_lock);
  101. }
  102. int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
  103. struct ocfs2_node_map *map,
  104. int bit)
  105. {
  106. int ret;
  107. if (bit >= map->num_nodes) {
  108. mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
  109. BUG();
  110. }
  111. spin_lock(&osb->node_map_lock);
  112. ret = test_bit(bit, map->map);
  113. spin_unlock(&osb->node_map_lock);
  114. return ret;
  115. }