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