^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * heartbeat.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Register ourselves with the heartbaet service, keep our node maps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * up to date, and fire off recovery when needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2002, 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <cluster/masklog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "ocfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "heartbeat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "journal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "ocfs2_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "buffer_head_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* special case -1 for now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * TODO: should *really* make sure the calling func never passes -1!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void ocfs2_node_map_init(struct ocfs2_node_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) sizeof(unsigned long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) void ocfs2_init_node_maps(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) spin_lock_init(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void ocfs2_do_node_down(int node_num, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct ocfs2_super *osb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) BUG_ON(osb->node_num == node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) trace_ocfs2_do_node_down(node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (!osb->cconn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * No cluster connection means we're not even ready to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * participate yet. We check the slots after the cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * comes up, so we will notice the node death then. We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * can safely ignore it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ocfs2_recovery_thread(osb, node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) set_bit(bit, map->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (bit==-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) BUG_ON(bit >= map->num_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) spin_lock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __ocfs2_node_map_set_bit(map, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_unlock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) clear_bit(bit, map->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (bit==-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) BUG_ON(bit >= map->num_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) spin_lock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __ocfs2_node_map_clear_bit(map, bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) spin_unlock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct ocfs2_node_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (bit >= map->num_nodes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) spin_lock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ret = test_bit(bit, map->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) spin_unlock(&osb->node_map_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)