Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 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 | |
| 27 | #include <linux/fs.h> |
| 28 | #include <linux/types.h> |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 29 | #include <linux/highmem.h> |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 30 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 31 | #include <cluster/masklog.h> |
| 32 | |
| 33 | #include "ocfs2.h" |
| 34 | |
| 35 | #include "alloc.h" |
| 36 | #include "heartbeat.h" |
| 37 | #include "inode.h" |
| 38 | #include "journal.h" |
Tao Ma | b5770f9 | 2011-02-23 21:17:39 +0800 | [diff] [blame] | 39 | #include "ocfs2_trace.h" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 40 | |
| 41 | #include "buffer_head_io.h" |
| 42 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 43 | static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map, |
| 44 | int bit); |
| 45 | static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map, |
| 46 | int bit); |
Adrian Bunk | 0060005 | 2008-01-29 00:11:41 +0200 | [diff] [blame] | 47 | |
| 48 | /* special case -1 for now |
| 49 | * TODO: should *really* make sure the calling func never passes -1!! */ |
| 50 | static void ocfs2_node_map_init(struct ocfs2_node_map *map) |
| 51 | { |
| 52 | map->num_nodes = OCFS2_NODE_MAP_MAX_NODES; |
| 53 | memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) * |
| 54 | sizeof(unsigned long)); |
| 55 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 56 | |
| 57 | void ocfs2_init_node_maps(struct ocfs2_super *osb) |
| 58 | { |
| 59 | spin_lock_init(&osb->node_map_lock); |
Mark Fasheh | b4df6ed | 2006-02-22 17:35:08 -0800 | [diff] [blame] | 60 | ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 63 | void ocfs2_do_node_down(int node_num, void *data) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 64 | { |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 65 | struct ocfs2_super *osb = data; |
| 66 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 67 | BUG_ON(osb->node_num == node_num); |
| 68 | |
Tao Ma | b5770f9 | 2011-02-23 21:17:39 +0800 | [diff] [blame] | 69 | trace_ocfs2_do_node_down(node_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 70 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 71 | if (!osb->cconn) { |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 72 | /* |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 73 | * No cluster connection means we're not even ready to |
| 74 | * participate yet. We check the slots after the cluster |
| 75 | * comes up, so we will notice the node death then. We |
| 76 | * can safely ignore it here. |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 77 | */ |
| 78 | return; |
| 79 | } |
| 80 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 81 | ocfs2_recovery_thread(osb, node_num); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 82 | } |
| 83 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 84 | static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map, |
| 85 | int bit) |
| 86 | { |
| 87 | set_bit(bit, map->map); |
| 88 | } |
| 89 | |
| 90 | void ocfs2_node_map_set_bit(struct ocfs2_super *osb, |
| 91 | struct ocfs2_node_map *map, |
| 92 | int bit) |
| 93 | { |
| 94 | if (bit==-1) |
| 95 | return; |
| 96 | BUG_ON(bit >= map->num_nodes); |
| 97 | spin_lock(&osb->node_map_lock); |
| 98 | __ocfs2_node_map_set_bit(map, bit); |
| 99 | spin_unlock(&osb->node_map_lock); |
| 100 | } |
| 101 | |
| 102 | static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map, |
| 103 | int bit) |
| 104 | { |
| 105 | clear_bit(bit, map->map); |
| 106 | } |
| 107 | |
| 108 | void ocfs2_node_map_clear_bit(struct ocfs2_super *osb, |
| 109 | struct ocfs2_node_map *map, |
| 110 | int bit) |
| 111 | { |
| 112 | if (bit==-1) |
| 113 | return; |
| 114 | BUG_ON(bit >= map->num_nodes); |
| 115 | spin_lock(&osb->node_map_lock); |
| 116 | __ocfs2_node_map_clear_bit(map, bit); |
| 117 | spin_unlock(&osb->node_map_lock); |
| 118 | } |
| 119 | |
| 120 | int ocfs2_node_map_test_bit(struct ocfs2_super *osb, |
| 121 | struct ocfs2_node_map *map, |
| 122 | int bit) |
| 123 | { |
| 124 | int ret; |
| 125 | if (bit >= map->num_nodes) { |
| 126 | mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes); |
| 127 | BUG(); |
| 128 | } |
| 129 | spin_lock(&osb->node_map_lock); |
| 130 | ret = test_bit(bit, map->map); |
| 131 | spin_unlock(&osb->node_map_lock); |
| 132 | return ret; |
| 133 | } |
| 134 | |