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