heartbeat.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * heartbeat.c
  4. *
  5. * Register ourselves with the heartbeat service, keep our node maps
  6. * up to date, and fire off recovery when needed.
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. */
  10. #include <linux/bitmap.h>
  11. #include <linux/fs.h>
  12. #include <linux/types.h>
  13. #include <linux/highmem.h>
  14. #include <cluster/masklog.h>
  15. #include "ocfs2.h"
  16. #include "alloc.h"
  17. #include "heartbeat.h"
  18. #include "inode.h"
  19. #include "journal.h"
  20. #include "ocfs2_trace.h"
  21. #include "buffer_head_io.h"
  22. /* special case -1 for now
  23. * TODO: should *really* make sure the calling func never passes -1!! */
  24. static void ocfs2_node_map_init(struct ocfs2_node_map *map)
  25. {
  26. map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
  27. bitmap_zero(map->map, OCFS2_NODE_MAP_MAX_NODES);
  28. }
  29. void ocfs2_init_node_maps(struct ocfs2_super *osb)
  30. {
  31. spin_lock_init(&osb->node_map_lock);
  32. ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
  33. }
  34. void ocfs2_do_node_down(int node_num, void *data)
  35. {
  36. struct ocfs2_super *osb = data;
  37. BUG_ON(osb->node_num == node_num);
  38. trace_ocfs2_do_node_down(node_num);
  39. if (!osb->cconn) {
  40. /*
  41. * No cluster connection means we're not even ready to
  42. * participate yet. We check the slots after the cluster
  43. * comes up, so we will notice the node death then. We
  44. * can safely ignore it here.
  45. */
  46. return;
  47. }
  48. ocfs2_recovery_thread(osb, node_num);
  49. }
  50. void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
  51. struct ocfs2_node_map *map,
  52. int bit)
  53. {
  54. if (bit==-1)
  55. return;
  56. BUG_ON(bit >= map->num_nodes);
  57. spin_lock(&osb->node_map_lock);
  58. set_bit(bit, map->map);
  59. spin_unlock(&osb->node_map_lock);
  60. }
  61. void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
  62. struct ocfs2_node_map *map,
  63. int bit)
  64. {
  65. if (bit==-1)
  66. return;
  67. BUG_ON(bit >= map->num_nodes);
  68. spin_lock(&osb->node_map_lock);
  69. clear_bit(bit, map->map);
  70. spin_unlock(&osb->node_map_lock);
  71. }
  72. int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
  73. struct ocfs2_node_map *map,
  74. int bit)
  75. {
  76. int ret;
  77. if (bit >= map->num_nodes) {
  78. mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
  79. BUG();
  80. }
  81. spin_lock(&osb->node_map_lock);
  82. ret = test_bit(bit, map->map);
  83. spin_unlock(&osb->node_map_lock);
  84. return ret;
  85. }