heartbeat.c 3.5 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/slab.h>
  29. #include <linux/highmem.h>
  30. #define MLOG_MASK_PREFIX ML_SUPER
  31. #include <cluster/masklog.h>
  32. #include "ocfs2.h"
  33. #include "alloc.h"
  34. #include "heartbeat.h"
  35. #include "inode.h"
  36. #include "journal.h"
  37. #include "buffer_head_io.h"
  38. static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
  39. int bit);
  40. static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
  41. int bit);
  42. /* special case -1 for now
  43. * TODO: should *really* make sure the calling func never passes -1!! */
  44. static void ocfs2_node_map_init(struct ocfs2_node_map *map)
  45. {
  46. map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
  47. memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
  48. sizeof(unsigned long));
  49. }
  50. void ocfs2_init_node_maps(struct ocfs2_super *osb)
  51. {
  52. spin_lock_init(&osb->node_map_lock);
  53. ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
  54. }
  55. void ocfs2_do_node_down(int node_num, void *data)
  56. {
  57. struct ocfs2_super *osb = data;
  58. BUG_ON(osb->node_num == node_num);
  59. mlog(0, "ocfs2: node down event for %d\n", node_num);
  60. if (!osb->cconn) {
  61. /*
  62. * No cluster connection means we're not even ready to
  63. * participate yet. We check the slots after the cluster
  64. * comes up, so we will notice the node death then. We
  65. * can safely ignore it here.
  66. */
  67. return;
  68. }
  69. ocfs2_recovery_thread(osb, node_num);
  70. }
  71. static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
  72. int bit)
  73. {
  74. set_bit(bit, map->map);
  75. }
  76. void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
  77. struct ocfs2_node_map *map,
  78. int bit)
  79. {
  80. if (bit==-1)
  81. return;
  82. BUG_ON(bit >= map->num_nodes);
  83. spin_lock(&osb->node_map_lock);
  84. __ocfs2_node_map_set_bit(map, bit);
  85. spin_unlock(&osb->node_map_lock);
  86. }
  87. static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
  88. int bit)
  89. {
  90. clear_bit(bit, map->map);
  91. }
  92. void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
  93. struct ocfs2_node_map *map,
  94. int bit)
  95. {
  96. if (bit==-1)
  97. return;
  98. BUG_ON(bit >= map->num_nodes);
  99. spin_lock(&osb->node_map_lock);
  100. __ocfs2_node_map_clear_bit(map, bit);
  101. spin_unlock(&osb->node_map_lock);
  102. }
  103. int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
  104. struct ocfs2_node_map *map,
  105. int bit)
  106. {
  107. int ret;
  108. if (bit >= map->num_nodes) {
  109. mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
  110. BUG();
  111. }
  112. spin_lock(&osb->node_map_lock);
  113. ret = test_bit(bit, map->map);
  114. spin_unlock(&osb->node_map_lock);
  115. return ret;
  116. }