Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | drbd_state.c |
| 3 | |
| 4 | This file is part of DRBD by Philipp Reisner and Lars Ellenberg. |
| 5 | |
| 6 | Copyright (C) 2001-2008, LINBIT Information Technologies GmbH. |
| 7 | Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>. |
| 8 | Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>. |
| 9 | |
| 10 | Thanks to Carter Burden, Bart Grantham and Gennadiy Nerubayev |
| 11 | from Logicworks, Inc. for making SDP replication support possible. |
| 12 | |
| 13 | drbd is free software; you can redistribute it and/or modify |
| 14 | it under the terms of the GNU General Public License as published by |
| 15 | the Free Software Foundation; either version 2, or (at your option) |
| 16 | any later version. |
| 17 | |
| 18 | drbd is distributed in the hope that it will be useful, |
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | GNU General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with drbd; see the file COPYING. If not, write to |
| 25 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/drbd_limits.h> |
| 29 | #include "drbd_int.h" |
Andreas Gruenbacher | a3603a6 | 2011-05-30 11:47:37 +0200 | [diff] [blame] | 30 | #include "drbd_protocol.h" |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 31 | #include "drbd_req.h" |
| 32 | |
| 33 | struct after_state_chg_work { |
| 34 | struct drbd_work w; |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 35 | struct drbd_device *device; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 36 | union drbd_state os; |
| 37 | union drbd_state ns; |
| 38 | enum chg_state_flags flags; |
| 39 | struct completion *done; |
| 40 | }; |
| 41 | |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 42 | enum sanitize_state_warnings { |
| 43 | NO_WARNING, |
| 44 | ABORTED_ONLINE_VERIFY, |
| 45 | ABORTED_RESYNC, |
| 46 | CONNECTION_LOST_NEGOTIATING, |
| 47 | IMPLICITLY_UPGRADED_DISK, |
| 48 | IMPLICITLY_UPGRADED_PDSK, |
| 49 | }; |
| 50 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 51 | static int w_after_state_ch(struct drbd_work *w, int unused); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 52 | static void after_state_ch(struct drbd_device *device, union drbd_state os, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 53 | union drbd_state ns, enum chg_state_flags flags); |
Andreas Gruenbacher | 5476169 | 2011-05-30 16:15:21 +0200 | [diff] [blame] | 54 | static enum drbd_state_rv is_valid_state(struct drbd_device *, union drbd_state); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 55 | static enum drbd_state_rv is_valid_soft_transition(union drbd_state, union drbd_state, struct drbd_connection *); |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 56 | static enum drbd_state_rv is_valid_transition(union drbd_state os, union drbd_state ns); |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 57 | static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state os, |
| 58 | union drbd_state ns, enum sanitize_state_warnings *warn); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 59 | |
Philipp Reisner | 2aebfab | 2011-03-28 16:48:11 +0200 | [diff] [blame] | 60 | static inline bool is_susp(union drbd_state s) |
| 61 | { |
| 62 | return s.susp || s.susp_nod || s.susp_fen; |
| 63 | } |
| 64 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 65 | bool conn_all_vols_unconf(struct drbd_connection *connection) |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 66 | { |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 67 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 68 | bool rv = true; |
Philipp Reisner | e90285e | 2011-03-22 12:51:21 +0100 | [diff] [blame] | 69 | int vnr; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 70 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 71 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 72 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 73 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 74 | if (device->state.disk != D_DISKLESS || |
| 75 | device->state.conn != C_STANDALONE || |
| 76 | device->state.role != R_SECONDARY) { |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 77 | rv = false; |
| 78 | break; |
| 79 | } |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 80 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 81 | rcu_read_unlock(); |
| 82 | |
| 83 | return rv; |
Philipp Reisner | 0e29d16 | 2011-02-18 14:23:11 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 86 | /* Unfortunately the states where not correctly ordered, when |
| 87 | they where defined. therefore can not use max_t() here. */ |
| 88 | static enum drbd_role max_role(enum drbd_role role1, enum drbd_role role2) |
| 89 | { |
| 90 | if (role1 == R_PRIMARY || role2 == R_PRIMARY) |
| 91 | return R_PRIMARY; |
| 92 | if (role1 == R_SECONDARY || role2 == R_SECONDARY) |
| 93 | return R_SECONDARY; |
| 94 | return R_UNKNOWN; |
| 95 | } |
| 96 | static enum drbd_role min_role(enum drbd_role role1, enum drbd_role role2) |
| 97 | { |
| 98 | if (role1 == R_UNKNOWN || role2 == R_UNKNOWN) |
| 99 | return R_UNKNOWN; |
| 100 | if (role1 == R_SECONDARY || role2 == R_SECONDARY) |
| 101 | return R_SECONDARY; |
| 102 | return R_PRIMARY; |
| 103 | } |
| 104 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 105 | enum drbd_role conn_highest_role(struct drbd_connection *connection) |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 106 | { |
| 107 | enum drbd_role role = R_UNKNOWN; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 108 | struct drbd_peer_device *peer_device; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 109 | int vnr; |
| 110 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 111 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 112 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 113 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 114 | role = max_role(role, device->state.role); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 115 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 116 | rcu_read_unlock(); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 117 | |
| 118 | return role; |
| 119 | } |
| 120 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 121 | enum drbd_role conn_highest_peer(struct drbd_connection *connection) |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 122 | { |
| 123 | enum drbd_role peer = R_UNKNOWN; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 124 | struct drbd_peer_device *peer_device; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 125 | int vnr; |
| 126 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 127 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 128 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 129 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 130 | peer = max_role(peer, device->state.peer); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 131 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 132 | rcu_read_unlock(); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 133 | |
| 134 | return peer; |
| 135 | } |
| 136 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 137 | enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection) |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 138 | { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 139 | enum drbd_disk_state disk_state = D_DISKLESS; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 140 | struct drbd_peer_device *peer_device; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 141 | int vnr; |
| 142 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 143 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 144 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 145 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 146 | disk_state = max_t(enum drbd_disk_state, disk_state, device->state.disk); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 147 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 148 | rcu_read_unlock(); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 149 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 150 | return disk_state; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 153 | enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection) |
Philipp Reisner | 4669265 | 2011-03-29 18:15:49 +0200 | [diff] [blame] | 154 | { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 155 | enum drbd_disk_state disk_state = D_MASK; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 156 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 4669265 | 2011-03-29 18:15:49 +0200 | [diff] [blame] | 157 | int vnr; |
| 158 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 159 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 160 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 161 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 162 | disk_state = min_t(enum drbd_disk_state, disk_state, device->state.disk); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 163 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 164 | rcu_read_unlock(); |
Philipp Reisner | 4669265 | 2011-03-29 18:15:49 +0200 | [diff] [blame] | 165 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 166 | return disk_state; |
Philipp Reisner | 4669265 | 2011-03-29 18:15:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 169 | enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection) |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 170 | { |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 171 | enum drbd_disk_state disk_state = D_DISKLESS; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 172 | struct drbd_peer_device *peer_device; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 173 | int vnr; |
| 174 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 175 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 176 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 177 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 178 | disk_state = max_t(enum drbd_disk_state, disk_state, device->state.pdsk); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 179 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 180 | rcu_read_unlock(); |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 181 | |
Andreas Gruenbacher | 11f8b2b | 2014-09-11 14:29:05 +0200 | [diff] [blame] | 182 | return disk_state; |
Philipp Reisner | cb70345 | 2011-03-24 11:03:07 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 185 | enum drbd_conns conn_lowest_conn(struct drbd_connection *connection) |
Philipp Reisner | 19f83c7 | 2011-03-29 14:21:03 +0200 | [diff] [blame] | 186 | { |
| 187 | enum drbd_conns conn = C_MASK; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 188 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 19f83c7 | 2011-03-29 14:21:03 +0200 | [diff] [blame] | 189 | int vnr; |
| 190 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 191 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 192 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 193 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 194 | conn = min_t(enum drbd_conns, conn, device->state.conn); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 195 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 196 | rcu_read_unlock(); |
Philipp Reisner | 19f83c7 | 2011-03-29 14:21:03 +0200 | [diff] [blame] | 197 | |
| 198 | return conn; |
| 199 | } |
| 200 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 201 | static bool no_peer_wf_report_params(struct drbd_connection *connection) |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 202 | { |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 203 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 204 | int vnr; |
| 205 | bool rv = true; |
| 206 | |
| 207 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 208 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
| 209 | if (peer_device->device->state.conn == C_WF_REPORT_PARAMS) { |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 210 | rv = false; |
| 211 | break; |
| 212 | } |
| 213 | rcu_read_unlock(); |
| 214 | |
| 215 | return rv; |
| 216 | } |
| 217 | |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 218 | static void wake_up_all_devices(struct drbd_connection *connection) |
| 219 | { |
| 220 | struct drbd_peer_device *peer_device; |
| 221 | int vnr; |
| 222 | |
| 223 | rcu_read_lock(); |
| 224 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
| 225 | wake_up(&peer_device->device->state_wait); |
| 226 | rcu_read_unlock(); |
| 227 | |
| 228 | } |
| 229 | |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 230 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 231 | /** |
| 232 | * cl_wide_st_chg() - true if the state change is a cluster wide one |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 233 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 234 | * @os: old (current) state. |
| 235 | * @ns: new (wanted) state. |
| 236 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 237 | static int cl_wide_st_chg(struct drbd_device *device, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 238 | union drbd_state os, union drbd_state ns) |
| 239 | { |
| 240 | return (os.conn >= C_CONNECTED && ns.conn >= C_CONNECTED && |
| 241 | ((os.role != R_PRIMARY && ns.role == R_PRIMARY) || |
| 242 | (os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || |
| 243 | (os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S) || |
Lars Ellenberg | e8744f5 | 2012-03-26 15:57:00 +0200 | [diff] [blame] | 244 | (os.disk != D_FAILED && ns.disk == D_FAILED))) || |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 245 | (os.conn >= C_CONNECTED && ns.conn == C_DISCONNECTING) || |
Philipp Reisner | 369bea6 | 2011-07-06 23:04:44 +0200 | [diff] [blame] | 246 | (os.conn == C_CONNECTED && ns.conn == C_VERIFY_S) || |
| 247 | (os.conn == C_CONNECTED && ns.conn == C_WF_REPORT_PARAMS); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Philipp Reisner | 56707f9 | 2011-02-16 14:57:50 +0100 | [diff] [blame] | 250 | static union drbd_state |
| 251 | apply_mask_val(union drbd_state os, union drbd_state mask, union drbd_state val) |
| 252 | { |
| 253 | union drbd_state ns; |
| 254 | ns.i = (os.i & ~mask.i) | val.i; |
| 255 | return ns; |
| 256 | } |
| 257 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 258 | enum drbd_state_rv |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 259 | drbd_change_state(struct drbd_device *device, enum chg_state_flags f, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 260 | union drbd_state mask, union drbd_state val) |
| 261 | { |
| 262 | unsigned long flags; |
Philipp Reisner | 56707f9 | 2011-02-16 14:57:50 +0100 | [diff] [blame] | 263 | union drbd_state ns; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 264 | enum drbd_state_rv rv; |
| 265 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 266 | spin_lock_irqsave(&device->resource->req_lock, flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 267 | ns = apply_mask_val(drbd_read_state(device), mask, val); |
| 268 | rv = _drbd_set_state(device, ns, f, NULL); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 269 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 270 | |
| 271 | return rv; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * drbd_force_state() - Impose a change which happens outside our control on our state |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 276 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 277 | * @mask: mask of state bits to change. |
| 278 | * @val: value of new state bits. |
| 279 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 280 | void drbd_force_state(struct drbd_device *device, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 281 | union drbd_state mask, union drbd_state val) |
| 282 | { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 283 | drbd_change_state(device, CS_HARD, mask, val); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static enum drbd_state_rv |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 287 | _req_st_cond(struct drbd_device *device, union drbd_state mask, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 288 | union drbd_state val) |
| 289 | { |
| 290 | union drbd_state os, ns; |
| 291 | unsigned long flags; |
| 292 | enum drbd_state_rv rv; |
| 293 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 294 | if (test_and_clear_bit(CL_ST_CHG_SUCCESS, &device->flags)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 295 | return SS_CW_SUCCESS; |
| 296 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 297 | if (test_and_clear_bit(CL_ST_CHG_FAIL, &device->flags)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 298 | return SS_CW_FAILED_BY_PEER; |
| 299 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 300 | spin_lock_irqsave(&device->resource->req_lock, flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 301 | os = drbd_read_state(device); |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 302 | ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL); |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 303 | rv = is_valid_transition(os, ns); |
Philipp Reisner | a3025a2 | 2012-09-03 15:39:01 +0200 | [diff] [blame] | 304 | if (rv >= SS_SUCCESS) |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 305 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 306 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 307 | if (!cl_wide_st_chg(device, os, ns)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 308 | rv = SS_CW_NO_NEED; |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 309 | if (rv == SS_UNKNOWN_ERROR) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 310 | rv = is_valid_state(device, ns); |
Philipp Reisner | a3025a2 | 2012-09-03 15:39:01 +0200 | [diff] [blame] | 311 | if (rv >= SS_SUCCESS) { |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 312 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
Philipp Reisner | a3025a2 | 2012-09-03 15:39:01 +0200 | [diff] [blame] | 313 | if (rv >= SS_SUCCESS) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 314 | rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */ |
| 315 | } |
| 316 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 317 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 318 | |
| 319 | return rv; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * drbd_req_state() - Perform an eventually cluster wide state change |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 324 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 325 | * @mask: mask of state bits to change. |
| 326 | * @val: value of new state bits. |
| 327 | * @f: flags |
| 328 | * |
| 329 | * Should not be called directly, use drbd_request_state() or |
| 330 | * _drbd_request_state(). |
| 331 | */ |
| 332 | static enum drbd_state_rv |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 333 | drbd_req_state(struct drbd_device *device, union drbd_state mask, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 334 | union drbd_state val, enum chg_state_flags f) |
| 335 | { |
| 336 | struct completion done; |
| 337 | unsigned long flags; |
| 338 | union drbd_state os, ns; |
| 339 | enum drbd_state_rv rv; |
| 340 | |
| 341 | init_completion(&done); |
| 342 | |
| 343 | if (f & CS_SERIALIZE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 344 | mutex_lock(device->state_mutex); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 345 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 346 | spin_lock_irqsave(&device->resource->req_lock, flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 347 | os = drbd_read_state(device); |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 348 | ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL); |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 349 | rv = is_valid_transition(os, ns); |
Lars Ellenberg | 3c5e5f6 | 2011-03-15 16:04:09 +0100 | [diff] [blame] | 350 | if (rv < SS_SUCCESS) { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 351 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 352 | goto abort; |
Lars Ellenberg | 3c5e5f6 | 2011-03-15 16:04:09 +0100 | [diff] [blame] | 353 | } |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 354 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 355 | if (cl_wide_st_chg(device, os, ns)) { |
| 356 | rv = is_valid_state(device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 357 | if (rv == SS_SUCCESS) |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 358 | rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 359 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 360 | |
| 361 | if (rv < SS_SUCCESS) { |
| 362 | if (f & CS_VERBOSE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 363 | print_st_err(device, os, ns, rv); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 364 | goto abort; |
| 365 | } |
| 366 | |
Andreas Gruenbacher | 69a2277 | 2011-08-09 00:47:13 +0200 | [diff] [blame] | 367 | if (drbd_send_state_req(first_peer_device(device), mask, val)) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 368 | rv = SS_CW_FAILED_BY_PEER; |
| 369 | if (f & CS_VERBOSE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 370 | print_st_err(device, os, ns, rv); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 371 | goto abort; |
| 372 | } |
| 373 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 374 | wait_event(device->state_wait, |
| 375 | (rv = _req_st_cond(device, mask, val))); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 376 | |
| 377 | if (rv < SS_SUCCESS) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 378 | if (f & CS_VERBOSE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 379 | print_st_err(device, os, ns, rv); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 380 | goto abort; |
| 381 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 382 | spin_lock_irqsave(&device->resource->req_lock, flags); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 383 | ns = apply_mask_val(drbd_read_state(device), mask, val); |
| 384 | rv = _drbd_set_state(device, ns, f, &done); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 385 | } else { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 386 | rv = _drbd_set_state(device, ns, f, &done); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 389 | spin_unlock_irqrestore(&device->resource->req_lock, flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 390 | |
| 391 | if (f & CS_WAIT_COMPLETE && rv == SS_SUCCESS) { |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 392 | D_ASSERT(device, current != first_peer_device(device)->connection->worker.task); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 393 | wait_for_completion(&done); |
| 394 | } |
| 395 | |
| 396 | abort: |
| 397 | if (f & CS_SERIALIZE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 398 | mutex_unlock(device->state_mutex); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 399 | |
| 400 | return rv; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * _drbd_request_state() - Request a state change (with flags) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 405 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 406 | * @mask: mask of state bits to change. |
| 407 | * @val: value of new state bits. |
| 408 | * @f: flags |
| 409 | * |
| 410 | * Cousin of drbd_request_state(), useful with the CS_WAIT_COMPLETE |
| 411 | * flag, or when logging of failed state change requests is not desired. |
| 412 | */ |
| 413 | enum drbd_state_rv |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 414 | _drbd_request_state(struct drbd_device *device, union drbd_state mask, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 415 | union drbd_state val, enum chg_state_flags f) |
| 416 | { |
| 417 | enum drbd_state_rv rv; |
| 418 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 419 | wait_event(device->state_wait, |
| 420 | (rv = drbd_req_state(device, mask, val, f)) != SS_IN_TRANSIENT_STATE); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 421 | |
| 422 | return rv; |
| 423 | } |
| 424 | |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 425 | enum drbd_state_rv |
| 426 | _drbd_request_state_holding_state_mutex(struct drbd_device *device, union drbd_state mask, |
| 427 | union drbd_state val, enum chg_state_flags f) |
| 428 | { |
| 429 | enum drbd_state_rv rv; |
| 430 | |
| 431 | BUG_ON(f & CS_SERIALIZE); |
| 432 | |
| 433 | wait_event_cmd(device->state_wait, |
| 434 | (rv = drbd_req_state(device, mask, val, f)) != SS_IN_TRANSIENT_STATE, |
| 435 | mutex_unlock(device->state_mutex), |
| 436 | mutex_lock(device->state_mutex)); |
| 437 | |
| 438 | return rv; |
| 439 | } |
| 440 | |
Lars Ellenberg | 8ce953a | 2014-02-27 09:46:18 +0100 | [diff] [blame] | 441 | static void print_st(struct drbd_device *device, const char *name, union drbd_state ns) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 442 | { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 443 | drbd_err(device, " %s = { cs:%s ro:%s/%s ds:%s/%s %c%c%c%c%c%c }\n", |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 444 | name, |
| 445 | drbd_conn_str(ns.conn), |
| 446 | drbd_role_str(ns.role), |
| 447 | drbd_role_str(ns.peer), |
| 448 | drbd_disk_str(ns.disk), |
| 449 | drbd_disk_str(ns.pdsk), |
| 450 | is_susp(ns) ? 's' : 'r', |
| 451 | ns.aftr_isp ? 'a' : '-', |
| 452 | ns.peer_isp ? 'p' : '-', |
| 453 | ns.user_isp ? 'u' : '-', |
| 454 | ns.susp_fen ? 'F' : '-', |
| 455 | ns.susp_nod ? 'N' : '-' |
| 456 | ); |
| 457 | } |
| 458 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 459 | void print_st_err(struct drbd_device *device, union drbd_state os, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 460 | union drbd_state ns, enum drbd_state_rv err) |
| 461 | { |
| 462 | if (err == SS_IN_TRANSIENT_STATE) |
| 463 | return; |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 464 | drbd_err(device, "State change failed: %s\n", drbd_set_st_err_str(err)); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 465 | print_st(device, " state", os); |
| 466 | print_st(device, "wanted", ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 469 | static long print_state_change(char *pb, union drbd_state os, union drbd_state ns, |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 470 | enum chg_state_flags flags) |
| 471 | { |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 472 | char *pbp; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 473 | pbp = pb; |
| 474 | *pbp = 0; |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 475 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 476 | if (ns.role != os.role && flags & CS_DC_ROLE) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 477 | pbp += sprintf(pbp, "role( %s -> %s ) ", |
| 478 | drbd_role_str(os.role), |
| 479 | drbd_role_str(ns.role)); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 480 | if (ns.peer != os.peer && flags & CS_DC_PEER) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 481 | pbp += sprintf(pbp, "peer( %s -> %s ) ", |
| 482 | drbd_role_str(os.peer), |
| 483 | drbd_role_str(ns.peer)); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 484 | if (ns.conn != os.conn && flags & CS_DC_CONN) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 485 | pbp += sprintf(pbp, "conn( %s -> %s ) ", |
| 486 | drbd_conn_str(os.conn), |
| 487 | drbd_conn_str(ns.conn)); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 488 | if (ns.disk != os.disk && flags & CS_DC_DISK) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 489 | pbp += sprintf(pbp, "disk( %s -> %s ) ", |
| 490 | drbd_disk_str(os.disk), |
| 491 | drbd_disk_str(ns.disk)); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 492 | if (ns.pdsk != os.pdsk && flags & CS_DC_PDSK) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 493 | pbp += sprintf(pbp, "pdsk( %s -> %s ) ", |
| 494 | drbd_disk_str(os.pdsk), |
| 495 | drbd_disk_str(ns.pdsk)); |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 496 | |
| 497 | return pbp - pb; |
| 498 | } |
| 499 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 500 | static void drbd_pr_state_change(struct drbd_device *device, union drbd_state os, union drbd_state ns, |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 501 | enum chg_state_flags flags) |
| 502 | { |
| 503 | char pb[300]; |
| 504 | char *pbp = pb; |
| 505 | |
| 506 | pbp += print_state_change(pbp, os, ns, flags ^ CS_DC_MASK); |
| 507 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 508 | if (ns.aftr_isp != os.aftr_isp) |
| 509 | pbp += sprintf(pbp, "aftr_isp( %d -> %d ) ", |
| 510 | os.aftr_isp, |
| 511 | ns.aftr_isp); |
| 512 | if (ns.peer_isp != os.peer_isp) |
| 513 | pbp += sprintf(pbp, "peer_isp( %d -> %d ) ", |
| 514 | os.peer_isp, |
| 515 | ns.peer_isp); |
| 516 | if (ns.user_isp != os.user_isp) |
| 517 | pbp += sprintf(pbp, "user_isp( %d -> %d ) ", |
| 518 | os.user_isp, |
| 519 | ns.user_isp); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 520 | |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 521 | if (pbp != pb) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 522 | drbd_info(device, "%s\n", pb); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 523 | } |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 524 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 525 | static void conn_pr_state_change(struct drbd_connection *connection, union drbd_state os, union drbd_state ns, |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 526 | enum chg_state_flags flags) |
| 527 | { |
| 528 | char pb[300]; |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 529 | char *pbp = pb; |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 530 | |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 531 | pbp += print_state_change(pbp, os, ns, flags); |
| 532 | |
| 533 | if (is_susp(ns) != is_susp(os) && flags & CS_DC_SUSP) |
| 534 | pbp += sprintf(pbp, "susp( %d -> %d ) ", |
| 535 | is_susp(os), |
| 536 | is_susp(ns)); |
| 537 | |
| 538 | if (pbp != pb) |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 539 | drbd_info(connection, "%s\n", pb); |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 543 | /** |
| 544 | * is_valid_state() - Returns an SS_ error code if ns is not valid |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 545 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 546 | * @ns: State to consider. |
| 547 | */ |
| 548 | static enum drbd_state_rv |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 549 | is_valid_state(struct drbd_device *device, union drbd_state ns) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 550 | { |
| 551 | /* See drbd_state_sw_errors in drbd_strings.c */ |
| 552 | |
| 553 | enum drbd_fencing_p fp; |
| 554 | enum drbd_state_rv rv = SS_SUCCESS; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 555 | struct net_conf *nc; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 556 | |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 557 | rcu_read_lock(); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 558 | fp = FP_DONT_CARE; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 559 | if (get_ldev(device)) { |
| 560 | fp = rcu_dereference(device->ldev->disk_conf)->fencing; |
| 561 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 562 | } |
| 563 | |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 564 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 565 | if (nc) { |
| 566 | if (!nc->two_primaries && ns.role == R_PRIMARY) { |
Philipp Reisner | 047e95e2 | 2011-03-16 14:43:36 +0100 | [diff] [blame] | 567 | if (ns.peer == R_PRIMARY) |
| 568 | rv = SS_TWO_PRIMARIES; |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 569 | else if (conn_highest_peer(first_peer_device(device)->connection) == R_PRIMARY) |
Philipp Reisner | 047e95e2 | 2011-03-16 14:43:36 +0100 | [diff] [blame] | 570 | rv = SS_O_VOL_PEER_PRI; |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 571 | } |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | if (rv <= 0) |
| 575 | /* already found a reason to abort */; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 576 | else if (ns.role == R_SECONDARY && device->open_cnt) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 577 | rv = SS_DEVICE_IN_USE; |
| 578 | |
| 579 | else if (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.disk < D_UP_TO_DATE) |
| 580 | rv = SS_NO_UP_TO_DATE_DISK; |
| 581 | |
| 582 | else if (fp >= FP_RESOURCE && |
| 583 | ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk >= D_UNKNOWN) |
| 584 | rv = SS_PRIMARY_NOP; |
| 585 | |
| 586 | else if (ns.role == R_PRIMARY && ns.disk <= D_INCONSISTENT && ns.pdsk <= D_INCONSISTENT) |
| 587 | rv = SS_NO_UP_TO_DATE_DISK; |
| 588 | |
| 589 | else if (ns.conn > C_CONNECTED && ns.disk < D_INCONSISTENT) |
| 590 | rv = SS_NO_LOCAL_DISK; |
| 591 | |
| 592 | else if (ns.conn > C_CONNECTED && ns.pdsk < D_INCONSISTENT) |
| 593 | rv = SS_NO_REMOTE_DISK; |
| 594 | |
| 595 | else if (ns.conn > C_CONNECTED && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) |
| 596 | rv = SS_NO_UP_TO_DATE_DISK; |
| 597 | |
| 598 | else if ((ns.conn == C_CONNECTED || |
| 599 | ns.conn == C_WF_BITMAP_S || |
| 600 | ns.conn == C_SYNC_SOURCE || |
| 601 | ns.conn == C_PAUSED_SYNC_S) && |
| 602 | ns.disk == D_OUTDATED) |
| 603 | rv = SS_CONNECTED_OUTDATES; |
| 604 | |
| 605 | else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 606 | (nc->verify_alg[0] == 0)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 607 | rv = SS_NO_VERIFY_ALG; |
| 608 | |
| 609 | else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 610 | first_peer_device(device)->connection->agreed_pro_version < 88) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 611 | rv = SS_NOT_SUPPORTED; |
| 612 | |
Philipp Reisner | 5c4f13d | 2013-03-27 14:08:37 +0100 | [diff] [blame] | 613 | else if (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) |
| 614 | rv = SS_NO_UP_TO_DATE_DISK; |
| 615 | |
| 616 | else if ((ns.conn == C_STARTING_SYNC_S || ns.conn == C_STARTING_SYNC_T) && |
| 617 | ns.pdsk == D_UNKNOWN) |
| 618 | rv = SS_NEED_CONNECTION; |
| 619 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 620 | else if (ns.conn >= C_CONNECTED && ns.pdsk == D_UNKNOWN) |
| 621 | rv = SS_CONNECTED_OUTDATES; |
| 622 | |
Philipp Reisner | 44ed167 | 2011-04-19 17:10:19 +0200 | [diff] [blame] | 623 | rcu_read_unlock(); |
| 624 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 625 | return rv; |
| 626 | } |
| 627 | |
| 628 | /** |
Philipp Reisner | a75f34a | 2011-02-09 15:10:33 +0100 | [diff] [blame] | 629 | * is_valid_soft_transition() - Returns an SS_ error code if the state transition is not possible |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 630 | * This function limits state transitions that may be declined by DRBD. I.e. |
| 631 | * user requests (aka soft transitions). |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 632 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 633 | * @ns: new state. |
| 634 | * @os: old state. |
| 635 | */ |
| 636 | static enum drbd_state_rv |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 637 | is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_connection *connection) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 638 | { |
| 639 | enum drbd_state_rv rv = SS_SUCCESS; |
| 640 | |
| 641 | if ((ns.conn == C_STARTING_SYNC_T || ns.conn == C_STARTING_SYNC_S) && |
| 642 | os.conn > C_CONNECTED) |
| 643 | rv = SS_RESYNC_RUNNING; |
| 644 | |
| 645 | if (ns.conn == C_DISCONNECTING && os.conn == C_STANDALONE) |
| 646 | rv = SS_ALREADY_STANDALONE; |
| 647 | |
| 648 | if (ns.disk > D_ATTACHING && os.disk == D_DISKLESS) |
| 649 | rv = SS_IS_DISKLESS; |
| 650 | |
| 651 | if (ns.conn == C_WF_CONNECTION && os.conn < C_UNCONNECTED) |
| 652 | rv = SS_NO_NET_CONFIG; |
| 653 | |
| 654 | if (ns.disk == D_OUTDATED && os.disk < D_OUTDATED && os.disk != D_ATTACHING) |
| 655 | rv = SS_LOWER_THAN_OUTDATED; |
| 656 | |
| 657 | if (ns.conn == C_DISCONNECTING && os.conn == C_UNCONNECTED) |
| 658 | rv = SS_IN_TRANSIENT_STATE; |
| 659 | |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 660 | /* While establishing a connection only allow cstate to change. |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 661 | Delay/refuse role changes, detach attach etc... (they do not touch cstate) */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 662 | if (test_bit(STATE_SENT, &connection->flags) && |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 663 | !((ns.conn == C_WF_REPORT_PARAMS && os.conn == C_WF_CONNECTION) || |
| 664 | (ns.conn >= C_CONNECTED && os.conn == C_WF_REPORT_PARAMS))) |
Philipp Reisner | a1096a6 | 2012-04-06 12:07:34 +0200 | [diff] [blame] | 665 | rv = SS_IN_TRANSIENT_STATE; |
| 666 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 667 | if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && os.conn < C_CONNECTED) |
| 668 | rv = SS_NEED_CONNECTION; |
| 669 | |
| 670 | if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && |
| 671 | ns.conn != os.conn && os.conn > C_CONNECTED) |
| 672 | rv = SS_RESYNC_RUNNING; |
| 673 | |
| 674 | if ((ns.conn == C_STARTING_SYNC_S || ns.conn == C_STARTING_SYNC_T) && |
| 675 | os.conn < C_CONNECTED) |
| 676 | rv = SS_NEED_CONNECTION; |
| 677 | |
| 678 | if ((ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE) |
| 679 | && os.conn < C_WF_REPORT_PARAMS) |
| 680 | rv = SS_NEED_CONNECTION; /* No NetworkFailure -> SyncTarget etc... */ |
| 681 | |
Philipp Reisner | 2bd5ed5 | 2013-03-27 14:08:40 +0100 | [diff] [blame] | 682 | if (ns.conn == C_DISCONNECTING && ns.pdsk == D_OUTDATED && |
| 683 | os.conn < C_CONNECTED && os.pdsk > D_OUTDATED) |
| 684 | rv = SS_OUTDATE_WO_CONN; |
| 685 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 686 | return rv; |
| 687 | } |
| 688 | |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 689 | static enum drbd_state_rv |
| 690 | is_valid_conn_transition(enum drbd_conns oc, enum drbd_conns nc) |
| 691 | { |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 692 | /* no change -> nothing to do, at least for the connection part */ |
| 693 | if (oc == nc) |
| 694 | return SS_NOTHING_TO_DO; |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 695 | |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 696 | /* disconnect of an unconfigured connection does not make sense */ |
| 697 | if (oc == C_STANDALONE && nc == C_DISCONNECTING) |
| 698 | return SS_ALREADY_STANDALONE; |
| 699 | |
| 700 | /* from C_STANDALONE, we start with C_UNCONNECTED */ |
| 701 | if (oc == C_STANDALONE && nc != C_UNCONNECTED) |
| 702 | return SS_NEED_CONNECTION; |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 703 | |
Philipp Reisner | 25b0d6c | 2012-02-14 12:12:35 +0100 | [diff] [blame] | 704 | /* When establishing a connection we need to go through WF_REPORT_PARAMS! |
| 705 | Necessary to do the right thing upon invalidate-remote on a disconnected resource */ |
| 706 | if (oc < C_WF_REPORT_PARAMS && nc >= C_CONNECTED) |
| 707 | return SS_NEED_CONNECTION; |
| 708 | |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 709 | /* After a network error only C_UNCONNECTED or C_DISCONNECTING may follow. */ |
| 710 | if (oc >= C_TIMEOUT && oc <= C_TEAR_DOWN && nc != C_UNCONNECTED && nc != C_DISCONNECTING) |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 711 | return SS_IN_TRANSIENT_STATE; |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 712 | |
| 713 | /* After C_DISCONNECTING only C_STANDALONE may follow */ |
| 714 | if (oc == C_DISCONNECTING && nc != C_STANDALONE) |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 715 | return SS_IN_TRANSIENT_STATE; |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 716 | |
Lars Ellenberg | d9cc6e2 | 2011-04-27 10:25:28 +0200 | [diff] [blame] | 717 | return SS_SUCCESS; |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 721 | /** |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 722 | * is_valid_transition() - Returns an SS_ error code if the state transition is not possible |
| 723 | * This limits hard state transitions. Hard state transitions are facts there are |
| 724 | * imposed on DRBD by the environment. E.g. disk broke or network broke down. |
| 725 | * But those hard state transitions are still not allowed to do everything. |
| 726 | * @ns: new state. |
| 727 | * @os: old state. |
| 728 | */ |
| 729 | static enum drbd_state_rv |
| 730 | is_valid_transition(union drbd_state os, union drbd_state ns) |
| 731 | { |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 732 | enum drbd_state_rv rv; |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 733 | |
Philipp Reisner | fda7411 | 2011-02-10 10:38:06 +0100 | [diff] [blame] | 734 | rv = is_valid_conn_transition(os.conn, ns.conn); |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 735 | |
| 736 | /* we cannot fail (again) if we already detached */ |
| 737 | if (ns.disk == D_FAILED && os.disk == D_DISKLESS) |
| 738 | rv = SS_IS_DISKLESS; |
| 739 | |
| 740 | return rv; |
| 741 | } |
| 742 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 743 | static void print_sanitize_warnings(struct drbd_device *device, enum sanitize_state_warnings warn) |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 744 | { |
| 745 | static const char *msg_table[] = { |
| 746 | [NO_WARNING] = "", |
| 747 | [ABORTED_ONLINE_VERIFY] = "Online-verify aborted.", |
| 748 | [ABORTED_RESYNC] = "Resync aborted.", |
| 749 | [CONNECTION_LOST_NEGOTIATING] = "Connection lost while negotiating, no data!", |
| 750 | [IMPLICITLY_UPGRADED_DISK] = "Implicitly upgraded disk", |
| 751 | [IMPLICITLY_UPGRADED_PDSK] = "Implicitly upgraded pdsk", |
| 752 | }; |
| 753 | |
| 754 | if (warn != NO_WARNING) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 755 | drbd_warn(device, "%s\n", msg_table[warn]); |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 758 | /** |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 759 | * sanitize_state() - Resolves implicitly necessary additional changes to a state transition |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 760 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 761 | * @os: old state. |
| 762 | * @ns: new state. |
| 763 | * @warn_sync_abort: |
| 764 | * |
| 765 | * When we loose connection, we have to set the state of the peers disk (pdsk) |
| 766 | * to D_UNKNOWN. This rule and many more along those lines are in this function. |
| 767 | */ |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 768 | static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state os, |
| 769 | union drbd_state ns, enum sanitize_state_warnings *warn) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 770 | { |
| 771 | enum drbd_fencing_p fp; |
| 772 | enum drbd_disk_state disk_min, disk_max, pdsk_min, pdsk_max; |
| 773 | |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 774 | if (warn) |
| 775 | *warn = NO_WARNING; |
| 776 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 777 | fp = FP_DONT_CARE; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 778 | if (get_ldev(device)) { |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 779 | rcu_read_lock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 780 | fp = rcu_dereference(device->ldev->disk_conf)->fencing; |
Philipp Reisner | daeda1c | 2011-05-03 15:00:55 +0200 | [diff] [blame] | 781 | rcu_read_unlock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 782 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 783 | } |
| 784 | |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 785 | /* Implications from connection to peer and peer_isp */ |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 786 | if (ns.conn < C_CONNECTED) { |
| 787 | ns.peer_isp = 0; |
| 788 | ns.peer = R_UNKNOWN; |
| 789 | if (ns.pdsk > D_UNKNOWN || ns.pdsk < D_INCONSISTENT) |
| 790 | ns.pdsk = D_UNKNOWN; |
| 791 | } |
| 792 | |
| 793 | /* Clear the aftr_isp when becoming unconfigured */ |
| 794 | if (ns.conn == C_STANDALONE && ns.disk == D_DISKLESS && ns.role == R_SECONDARY) |
| 795 | ns.aftr_isp = 0; |
| 796 | |
Philipp Reisner | 4308a0a | 2011-02-10 11:24:38 +0100 | [diff] [blame] | 797 | /* An implication of the disk states onto the connection state */ |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 798 | /* Abort resync if a disk fails/detaches */ |
Philipp Reisner | 4308a0a | 2011-02-10 11:24:38 +0100 | [diff] [blame] | 799 | if (ns.conn > C_CONNECTED && (ns.disk <= D_FAILED || ns.pdsk <= D_FAILED)) { |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 800 | if (warn) |
| 801 | *warn = ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T ? |
| 802 | ABORTED_ONLINE_VERIFY : ABORTED_RESYNC; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 803 | ns.conn = C_CONNECTED; |
| 804 | } |
| 805 | |
| 806 | /* Connection breaks down before we finished "Negotiating" */ |
| 807 | if (ns.conn < C_CONNECTED && ns.disk == D_NEGOTIATING && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 808 | get_ldev_if_state(device, D_NEGOTIATING)) { |
| 809 | if (device->ed_uuid == device->ldev->md.uuid[UI_CURRENT]) { |
| 810 | ns.disk = device->new_state_tmp.disk; |
| 811 | ns.pdsk = device->new_state_tmp.pdsk; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 812 | } else { |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 813 | if (warn) |
| 814 | *warn = CONNECTION_LOST_NEGOTIATING; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 815 | ns.disk = D_DISKLESS; |
| 816 | ns.pdsk = D_UNKNOWN; |
| 817 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 818 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /* D_CONSISTENT and D_OUTDATED vanish when we get connected */ |
| 822 | if (ns.conn >= C_CONNECTED && ns.conn < C_AHEAD) { |
| 823 | if (ns.disk == D_CONSISTENT || ns.disk == D_OUTDATED) |
| 824 | ns.disk = D_UP_TO_DATE; |
| 825 | if (ns.pdsk == D_CONSISTENT || ns.pdsk == D_OUTDATED) |
| 826 | ns.pdsk = D_UP_TO_DATE; |
| 827 | } |
| 828 | |
| 829 | /* Implications of the connection stat on the disk states */ |
| 830 | disk_min = D_DISKLESS; |
| 831 | disk_max = D_UP_TO_DATE; |
| 832 | pdsk_min = D_INCONSISTENT; |
| 833 | pdsk_max = D_UNKNOWN; |
| 834 | switch ((enum drbd_conns)ns.conn) { |
| 835 | case C_WF_BITMAP_T: |
| 836 | case C_PAUSED_SYNC_T: |
| 837 | case C_STARTING_SYNC_T: |
| 838 | case C_WF_SYNC_UUID: |
| 839 | case C_BEHIND: |
| 840 | disk_min = D_INCONSISTENT; |
| 841 | disk_max = D_OUTDATED; |
| 842 | pdsk_min = D_UP_TO_DATE; |
| 843 | pdsk_max = D_UP_TO_DATE; |
| 844 | break; |
| 845 | case C_VERIFY_S: |
| 846 | case C_VERIFY_T: |
| 847 | disk_min = D_UP_TO_DATE; |
| 848 | disk_max = D_UP_TO_DATE; |
| 849 | pdsk_min = D_UP_TO_DATE; |
| 850 | pdsk_max = D_UP_TO_DATE; |
| 851 | break; |
| 852 | case C_CONNECTED: |
| 853 | disk_min = D_DISKLESS; |
| 854 | disk_max = D_UP_TO_DATE; |
| 855 | pdsk_min = D_DISKLESS; |
| 856 | pdsk_max = D_UP_TO_DATE; |
| 857 | break; |
| 858 | case C_WF_BITMAP_S: |
| 859 | case C_PAUSED_SYNC_S: |
| 860 | case C_STARTING_SYNC_S: |
| 861 | case C_AHEAD: |
| 862 | disk_min = D_UP_TO_DATE; |
| 863 | disk_max = D_UP_TO_DATE; |
| 864 | pdsk_min = D_INCONSISTENT; |
| 865 | pdsk_max = D_CONSISTENT; /* D_OUTDATED would be nice. But explicit outdate necessary*/ |
| 866 | break; |
| 867 | case C_SYNC_TARGET: |
| 868 | disk_min = D_INCONSISTENT; |
| 869 | disk_max = D_INCONSISTENT; |
| 870 | pdsk_min = D_UP_TO_DATE; |
| 871 | pdsk_max = D_UP_TO_DATE; |
| 872 | break; |
| 873 | case C_SYNC_SOURCE: |
| 874 | disk_min = D_UP_TO_DATE; |
| 875 | disk_max = D_UP_TO_DATE; |
| 876 | pdsk_min = D_INCONSISTENT; |
| 877 | pdsk_max = D_INCONSISTENT; |
| 878 | break; |
| 879 | case C_STANDALONE: |
| 880 | case C_DISCONNECTING: |
| 881 | case C_UNCONNECTED: |
| 882 | case C_TIMEOUT: |
| 883 | case C_BROKEN_PIPE: |
| 884 | case C_NETWORK_FAILURE: |
| 885 | case C_PROTOCOL_ERROR: |
| 886 | case C_TEAR_DOWN: |
| 887 | case C_WF_CONNECTION: |
| 888 | case C_WF_REPORT_PARAMS: |
| 889 | case C_MASK: |
| 890 | break; |
| 891 | } |
| 892 | if (ns.disk > disk_max) |
| 893 | ns.disk = disk_max; |
| 894 | |
| 895 | if (ns.disk < disk_min) { |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 896 | if (warn) |
| 897 | *warn = IMPLICITLY_UPGRADED_DISK; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 898 | ns.disk = disk_min; |
| 899 | } |
| 900 | if (ns.pdsk > pdsk_max) |
| 901 | ns.pdsk = pdsk_max; |
| 902 | |
| 903 | if (ns.pdsk < pdsk_min) { |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 904 | if (warn) |
| 905 | *warn = IMPLICITLY_UPGRADED_PDSK; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 906 | ns.pdsk = pdsk_min; |
| 907 | } |
| 908 | |
| 909 | if (fp == FP_STONITH && |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 910 | (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED) && |
| 911 | !(os.role == R_PRIMARY && os.conn < C_CONNECTED && os.pdsk > D_OUTDATED)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 912 | ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */ |
| 913 | |
Andreas Gruenbacher | eb6bea6 | 2011-06-21 16:11:28 +0200 | [diff] [blame] | 914 | if (device->resource->res_opts.on_no_data == OND_SUSPEND_IO && |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 915 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) && |
| 916 | !(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 917 | ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */ |
| 918 | |
| 919 | if (ns.aftr_isp || ns.peer_isp || ns.user_isp) { |
| 920 | if (ns.conn == C_SYNC_SOURCE) |
| 921 | ns.conn = C_PAUSED_SYNC_S; |
| 922 | if (ns.conn == C_SYNC_TARGET) |
| 923 | ns.conn = C_PAUSED_SYNC_T; |
| 924 | } else { |
| 925 | if (ns.conn == C_PAUSED_SYNC_S) |
| 926 | ns.conn = C_SYNC_SOURCE; |
| 927 | if (ns.conn == C_PAUSED_SYNC_T) |
| 928 | ns.conn = C_SYNC_TARGET; |
| 929 | } |
| 930 | |
| 931 | return ns; |
| 932 | } |
| 933 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 934 | void drbd_resume_al(struct drbd_device *device) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 935 | { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 936 | if (test_and_clear_bit(AL_SUSPENDED, &device->flags)) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 937 | drbd_info(device, "Resumed AL updates\n"); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 938 | } |
| 939 | |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 940 | /* helper for _drbd_set_state */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 941 | static void set_ov_position(struct drbd_device *device, enum drbd_conns cs) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 942 | { |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 943 | if (first_peer_device(device)->connection->agreed_pro_version < 90) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 944 | device->ov_start_sector = 0; |
| 945 | device->rs_total = drbd_bm_bits(device); |
| 946 | device->ov_position = 0; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 947 | if (cs == C_VERIFY_T) { |
| 948 | /* starting online verify from an arbitrary position |
| 949 | * does not fit well into the existing protocol. |
| 950 | * on C_VERIFY_T, we initialize ov_left and friends |
| 951 | * implicitly in receive_DataRequest once the |
| 952 | * first P_OV_REQUEST is received */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 953 | device->ov_start_sector = ~(sector_t)0; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 954 | } else { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 955 | unsigned long bit = BM_SECT_TO_BIT(device->ov_start_sector); |
| 956 | if (bit >= device->rs_total) { |
| 957 | device->ov_start_sector = |
| 958 | BM_BIT_TO_SECT(device->rs_total - 1); |
| 959 | device->rs_total = 1; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 960 | } else |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 961 | device->rs_total -= bit; |
| 962 | device->ov_position = device->ov_start_sector; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 963 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 964 | device->ov_left = device->rs_total; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /** |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 968 | * _drbd_set_state() - Set a new DRBD state |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 969 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 970 | * @ns: new state. |
| 971 | * @flags: Flags |
| 972 | * @done: Optional completion, that will get completed after the after_state_ch() finished |
| 973 | * |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 974 | * Caller needs to hold req_lock. Do not call directly. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 975 | */ |
| 976 | enum drbd_state_rv |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 977 | _drbd_set_state(struct drbd_device *device, union drbd_state ns, |
| 978 | enum chg_state_flags flags, struct completion *done) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 979 | { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 980 | struct drbd_peer_device *peer_device = first_peer_device(device); |
| 981 | struct drbd_connection *connection = peer_device ? peer_device->connection : NULL; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 982 | union drbd_state os; |
| 983 | enum drbd_state_rv rv = SS_SUCCESS; |
Philipp Reisner | d942ae4 | 2011-05-31 13:07:24 +0200 | [diff] [blame] | 984 | enum sanitize_state_warnings ssw; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 985 | struct after_state_chg_work *ascw; |
| 986 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 987 | os = drbd_read_state(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 988 | |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 989 | ns = sanitize_state(device, os, ns, &ssw); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 990 | if (ns.i == os.i) |
| 991 | return SS_NOTHING_TO_DO; |
| 992 | |
Philipp Reisner | 3509502 | 2011-02-09 16:29:33 +0100 | [diff] [blame] | 993 | rv = is_valid_transition(os, ns); |
| 994 | if (rv < SS_SUCCESS) |
| 995 | return rv; |
| 996 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 997 | if (!(flags & CS_HARD)) { |
| 998 | /* pre-state-change checks ; only look at ns */ |
| 999 | /* See drbd_state_sw_errors in drbd_strings.c */ |
| 1000 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1001 | rv = is_valid_state(device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1002 | if (rv < SS_SUCCESS) { |
| 1003 | /* If the old state was illegal as well, then let |
| 1004 | this happen...*/ |
| 1005 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1006 | if (is_valid_state(device, os) == rv) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1007 | rv = is_valid_soft_transition(os, ns, connection); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1008 | } else |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1009 | rv = is_valid_soft_transition(os, ns, connection); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | if (rv < SS_SUCCESS) { |
| 1013 | if (flags & CS_VERBOSE) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1014 | print_st_err(device, os, ns, rv); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1015 | return rv; |
| 1016 | } |
| 1017 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1018 | print_sanitize_warnings(device, ssw); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1019 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1020 | drbd_pr_state_change(device, os, ns, flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1021 | |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 1022 | /* Display changes to the susp* flags that where caused by the call to |
| 1023 | sanitize_state(). Only display it here if we where not called from |
| 1024 | _conn_request_state() */ |
| 1025 | if (!(flags & CS_DC_SUSP)) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1026 | conn_pr_state_change(connection, os, ns, |
Andreas Gruenbacher | a6b32bc | 2011-05-31 14:33:49 +0200 | [diff] [blame] | 1027 | (flags & ~CS_DC_MASK) | CS_DC_SUSP); |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 1028 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1029 | /* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference |
| 1030 | * on the ldev here, to be sure the transition -> D_DISKLESS resp. |
| 1031 | * drbd_ldev_destroy() won't happen before our corresponding |
| 1032 | * after_state_ch works run, where we put_ldev again. */ |
| 1033 | if ((os.disk != D_FAILED && ns.disk == D_FAILED) || |
| 1034 | (os.disk != D_DISKLESS && ns.disk == D_DISKLESS)) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1035 | atomic_inc(&device->local_cnt); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1036 | |
Lars Ellenberg | 5ab7d2c | 2014-01-27 15:58:22 +0100 | [diff] [blame] | 1037 | if (!is_sync_state(os.conn) && is_sync_state(ns.conn)) |
| 1038 | clear_bit(RS_DONE, &device->flags); |
| 1039 | |
Lars Ellenberg | ba3c6fb | 2014-02-11 08:57:18 +0100 | [diff] [blame] | 1040 | /* changes to local_cnt and device flags should be visible before |
| 1041 | * changes to state, which again should be visible before anything else |
| 1042 | * depending on that change happens. */ |
| 1043 | smp_wmb(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1044 | device->state.i = ns.i; |
Andreas Gruenbacher | 6bbf53c | 2011-07-08 01:19:44 +0200 | [diff] [blame] | 1045 | device->resource->susp = ns.susp; |
| 1046 | device->resource->susp_nod = ns.susp_nod; |
| 1047 | device->resource->susp_fen = ns.susp_fen; |
Lars Ellenberg | ba3c6fb | 2014-02-11 08:57:18 +0100 | [diff] [blame] | 1048 | smp_wmb(); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1049 | |
Lars Ellenberg | 2681f7f | 2013-01-21 15:43:41 +0100 | [diff] [blame] | 1050 | /* put replicated vs not-replicated requests in seperate epochs */ |
Lars Ellenberg | ba3c6fb | 2014-02-11 08:57:18 +0100 | [diff] [blame] | 1051 | if (drbd_should_do_remote((union drbd_dev_state)os.i) != |
| 1052 | drbd_should_do_remote((union drbd_dev_state)ns.i)) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1053 | start_new_tl_epoch(connection); |
Lars Ellenberg | 2681f7f | 2013-01-21 15:43:41 +0100 | [diff] [blame] | 1054 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1055 | if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1056 | drbd_print_uuids(device, "attached to UUIDs"); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1057 | |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 1058 | /* Wake up role changes, that were delayed because of connection establishing */ |
| 1059 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS && |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 1060 | no_peer_wf_report_params(connection)) { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1061 | clear_bit(STATE_SENT, &connection->flags); |
Philipp Reisner | a882153 | 2014-11-10 17:21:11 +0100 | [diff] [blame] | 1062 | wake_up_all_devices(connection); |
| 1063 | } |
Philipp Reisner | 7970201 | 2012-08-28 11:33:35 +0200 | [diff] [blame] | 1064 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1065 | wake_up(&device->misc_wait); |
| 1066 | wake_up(&device->state_wait); |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1067 | wake_up(&connection->ping_wait); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1068 | |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 1069 | /* Aborted verify run, or we reached the stop sector. |
| 1070 | * Log the last position, unless end-of-device. */ |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1071 | if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) && |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 1072 | ns.conn <= C_CONNECTED) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1073 | device->ov_start_sector = |
| 1074 | BM_BIT_TO_SECT(drbd_bm_bits(device) - device->ov_left); |
| 1075 | if (device->ov_left) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1076 | drbd_info(device, "Online Verify reached sector %llu\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1077 | (unsigned long long)device->ov_start_sector); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | if ((os.conn == C_PAUSED_SYNC_T || os.conn == C_PAUSED_SYNC_S) && |
| 1081 | (ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1082 | drbd_info(device, "Syncer continues.\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1083 | device->rs_paused += (long)jiffies |
| 1084 | -(long)device->rs_mark_time[device->rs_last_mark]; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1085 | if (ns.conn == C_SYNC_TARGET) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1086 | mod_timer(&device->resync_timer, jiffies); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | if ((os.conn == C_SYNC_TARGET || os.conn == C_SYNC_SOURCE) && |
| 1090 | (ns.conn == C_PAUSED_SYNC_T || ns.conn == C_PAUSED_SYNC_S)) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1091 | drbd_info(device, "Resync suspended\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1092 | device->rs_mark_time[device->rs_last_mark] = jiffies; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | if (os.conn == C_CONNECTED && |
| 1096 | (ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T)) { |
| 1097 | unsigned long now = jiffies; |
| 1098 | int i; |
| 1099 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1100 | set_ov_position(device, ns.conn); |
| 1101 | device->rs_start = now; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1102 | device->rs_last_sect_ev = 0; |
| 1103 | device->ov_last_oos_size = 0; |
| 1104 | device->ov_last_oos_start = 0; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1105 | |
| 1106 | for (i = 0; i < DRBD_SYNC_MARKS; i++) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1107 | device->rs_mark_left[i] = device->ov_left; |
| 1108 | device->rs_mark_time[i] = now; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1111 | drbd_rs_controller_reset(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1112 | |
| 1113 | if (ns.conn == C_VERIFY_S) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1114 | drbd_info(device, "Starting Online Verify from sector %llu\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1115 | (unsigned long long)device->ov_position); |
| 1116 | mod_timer(&device->resync_timer, jiffies); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1120 | if (get_ldev(device)) { |
| 1121 | u32 mdf = device->ldev->md.flags & ~(MDF_CONSISTENT|MDF_PRIMARY_IND| |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1122 | MDF_CONNECTED_IND|MDF_WAS_UP_TO_DATE| |
| 1123 | MDF_PEER_OUT_DATED|MDF_CRASHED_PRIMARY); |
| 1124 | |
Lars Ellenberg | d5d7ebd | 2011-07-05 20:59:26 +0200 | [diff] [blame] | 1125 | mdf &= ~MDF_AL_CLEAN; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1126 | if (test_bit(CRASHED_PRIMARY, &device->flags)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1127 | mdf |= MDF_CRASHED_PRIMARY; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1128 | if (device->state.role == R_PRIMARY || |
| 1129 | (device->state.pdsk < D_INCONSISTENT && device->state.peer == R_PRIMARY)) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1130 | mdf |= MDF_PRIMARY_IND; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1131 | if (device->state.conn > C_WF_REPORT_PARAMS) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1132 | mdf |= MDF_CONNECTED_IND; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1133 | if (device->state.disk > D_INCONSISTENT) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1134 | mdf |= MDF_CONSISTENT; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1135 | if (device->state.disk > D_OUTDATED) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1136 | mdf |= MDF_WAS_UP_TO_DATE; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1137 | if (device->state.pdsk <= D_OUTDATED && device->state.pdsk >= D_INCONSISTENT) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1138 | mdf |= MDF_PEER_OUT_DATED; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1139 | if (mdf != device->ldev->md.flags) { |
| 1140 | device->ldev->md.flags = mdf; |
| 1141 | drbd_md_mark_dirty(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1142 | } |
| 1143 | if (os.disk < D_CONSISTENT && ns.disk >= D_CONSISTENT) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1144 | drbd_set_ed_uuid(device, device->ldev->md.uuid[UI_CURRENT]); |
| 1145 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | /* Peer was forced D_UP_TO_DATE & R_PRIMARY, consider to resync */ |
| 1149 | if (os.disk == D_INCONSISTENT && os.pdsk == D_INCONSISTENT && |
| 1150 | os.peer == R_SECONDARY && ns.peer == R_PRIMARY) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1151 | set_bit(CONSIDER_RESYNC, &device->flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1152 | |
| 1153 | /* Receiver should clean up itself */ |
| 1154 | if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1155 | drbd_thread_stop_nowait(&connection->receiver); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1156 | |
| 1157 | /* Now the receiver finished cleaning up itself, it should die */ |
| 1158 | if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1159 | drbd_thread_stop_nowait(&connection->receiver); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1160 | |
| 1161 | /* Upon network failure, we need to restart the receiver. */ |
Philipp Reisner | 823bd83 | 2012-11-08 15:04:36 +0100 | [diff] [blame] | 1162 | if (os.conn > C_WF_CONNECTION && |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1163 | ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1164 | drbd_thread_restart_nowait(&connection->receiver); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1165 | |
| 1166 | /* Resume AL writing if we get a connection */ |
Philipp Reisner | 28e448b | 2013-06-25 16:50:06 +0200 | [diff] [blame] | 1167 | if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1168 | drbd_resume_al(device); |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1169 | connection->connect_cnt++; |
Philipp Reisner | 28e448b | 2013-06-25 16:50:06 +0200 | [diff] [blame] | 1170 | } |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1171 | |
Lars Ellenberg | 07be15b | 2012-05-07 11:53:08 +0200 | [diff] [blame] | 1172 | /* remember last attach time so request_timer_fn() won't |
| 1173 | * kill newly established sessions while we are still trying to thaw |
| 1174 | * previously frozen IO */ |
| 1175 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && |
| 1176 | ns.disk > D_NEGOTIATING) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1177 | device->last_reattach_jif = jiffies; |
Lars Ellenberg | 07be15b | 2012-05-07 11:53:08 +0200 | [diff] [blame] | 1178 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1179 | ascw = kmalloc(sizeof(*ascw), GFP_ATOMIC); |
| 1180 | if (ascw) { |
| 1181 | ascw->os = os; |
| 1182 | ascw->ns = ns; |
| 1183 | ascw->flags = flags; |
| 1184 | ascw->w.cb = w_after_state_ch; |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1185 | ascw->device = device; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1186 | ascw->done = done; |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1187 | drbd_queue_work(&connection->sender_work, |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1188 | &ascw->w); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1189 | } else { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1190 | drbd_err(device, "Could not kmalloc an ascw\n"); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | return rv; |
| 1194 | } |
| 1195 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1196 | static int w_after_state_ch(struct drbd_work *w, int unused) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1197 | { |
| 1198 | struct after_state_chg_work *ascw = |
| 1199 | container_of(w, struct after_state_chg_work, w); |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1200 | struct drbd_device *device = ascw->device; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1201 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1202 | after_state_ch(device, ascw->os, ascw->ns, ascw->flags); |
Andreas Gruenbacher | 137975c | 2011-08-24 08:19:41 +0200 | [diff] [blame] | 1203 | if (ascw->flags & CS_WAIT_COMPLETE) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1204 | complete(ascw->done); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1205 | kfree(ascw); |
| 1206 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1207 | return 0; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1210 | static void abw_start_sync(struct drbd_device *device, int rv) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1211 | { |
| 1212 | if (rv) { |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1213 | drbd_err(device, "Writing the bitmap failed not starting resync.\n"); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1214 | _drbd_request_state(device, NS(conn, C_CONNECTED), CS_VERBOSE); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1215 | return; |
| 1216 | } |
| 1217 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1218 | switch (device->state.conn) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1219 | case C_STARTING_SYNC_T: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1220 | _drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1221 | break; |
| 1222 | case C_STARTING_SYNC_S: |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1223 | drbd_start_resync(device, C_SYNC_SOURCE); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1224 | break; |
| 1225 | } |
| 1226 | } |
| 1227 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1228 | int drbd_bitmap_io_from_worker(struct drbd_device *device, |
Andreas Gruenbacher | 5476169 | 2011-05-30 16:15:21 +0200 | [diff] [blame] | 1229 | int (*io_fn)(struct drbd_device *), |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1230 | char *why, enum bm_flag flags) |
| 1231 | { |
| 1232 | int rv; |
| 1233 | |
Andreas Gruenbacher | 0b0ba1e | 2011-06-27 16:23:33 +0200 | [diff] [blame] | 1234 | D_ASSERT(device, current == first_peer_device(device)->connection->worker.task); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1235 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1236 | /* open coded non-blocking drbd_suspend_io(device); */ |
| 1237 | set_bit(SUSPEND_IO, &device->flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1238 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1239 | drbd_bm_lock(device, why, flags); |
| 1240 | rv = io_fn(device); |
| 1241 | drbd_bm_unlock(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1242 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1243 | drbd_resume_io(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1244 | |
| 1245 | return rv; |
| 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * after_state_ch() - Perform after state change actions that may sleep |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1250 | * @device: DRBD device. |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1251 | * @os: old state. |
| 1252 | * @ns: new state. |
| 1253 | * @flags: Flags |
| 1254 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1255 | static void after_state_ch(struct drbd_device *device, union drbd_state os, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1256 | union drbd_state ns, enum chg_state_flags flags) |
| 1257 | { |
Andreas Gruenbacher | 6bbf53c | 2011-07-08 01:19:44 +0200 | [diff] [blame] | 1258 | struct drbd_resource *resource = device->resource; |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1259 | struct drbd_peer_device *peer_device = first_peer_device(device); |
| 1260 | struct drbd_connection *connection = peer_device ? peer_device->connection : NULL; |
Lars Ellenberg | 3b98c0c | 2011-03-07 12:49:34 +0100 | [diff] [blame] | 1261 | struct sib_info sib; |
| 1262 | |
| 1263 | sib.sib_reason = SIB_STATE_CHANGE; |
| 1264 | sib.os = os; |
| 1265 | sib.ns = ns; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1266 | |
Lars Ellenberg | 2f2abea | 2014-03-27 10:34:13 +0100 | [diff] [blame] | 1267 | if ((os.disk != D_UP_TO_DATE || os.pdsk != D_UP_TO_DATE) |
| 1268 | && (ns.disk == D_UP_TO_DATE && ns.pdsk == D_UP_TO_DATE)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1269 | clear_bit(CRASHED_PRIMARY, &device->flags); |
| 1270 | if (device->p_uuid) |
| 1271 | device->p_uuid[UI_FLAGS] &= ~((u64)2); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1274 | /* Inform userspace about the change... */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1275 | drbd_bcast_event(device, &sib); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1276 | |
| 1277 | if (!(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE) && |
| 1278 | (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1279 | drbd_khelper(device, "pri-on-incon-degr"); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1280 | |
| 1281 | /* Here we have the actions that are performed after a |
| 1282 | state change. This function might sleep */ |
| 1283 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1284 | if (ns.susp_nod) { |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1285 | enum drbd_req_event what = NOTHING; |
| 1286 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1287 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1288 | if (os.conn < C_CONNECTED && conn_lowest_conn(connection) >= C_CONNECTED) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1289 | what = RESEND; |
| 1290 | |
Philipp Reisner | 3fb4746 | 2011-07-15 18:44:26 +0200 | [diff] [blame] | 1291 | if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) && |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1292 | conn_lowest_disk(connection) > D_NEGOTIATING) |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1293 | what = RESTART_FROZEN_DISK_IO; |
| 1294 | |
Andreas Gruenbacher | 6bbf53c | 2011-07-08 01:19:44 +0200 | [diff] [blame] | 1295 | if (resource->susp_nod && what != NOTHING) { |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1296 | _tl_restart(connection, what); |
| 1297 | _conn_request_state(connection, |
Philipp Reisner | 892fdd1 | 2012-08-27 17:20:12 +0200 | [diff] [blame] | 1298 | (union drbd_state) { { .susp_nod = 1 } }, |
| 1299 | (union drbd_state) { { .susp_nod = 0 } }, |
| 1300 | CS_VERBOSE); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1301 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1302 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1305 | if (ns.susp_fen) { |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1306 | spin_lock_irq(&device->resource->req_lock); |
Andreas Gruenbacher | 6bbf53c | 2011-07-08 01:19:44 +0200 | [diff] [blame] | 1307 | if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) { |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1308 | /* case2: The connection was established again: */ |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1309 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1310 | int vnr; |
| 1311 | |
| 1312 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1313 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) |
| 1314 | clear_bit(NEW_CUR_UUID, &peer_device->device->flags); |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1315 | rcu_read_unlock(); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1316 | _tl_restart(connection, RESEND); |
| 1317 | _conn_request_state(connection, |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1318 | (union drbd_state) { { .susp_fen = 1 } }, |
| 1319 | (union drbd_state) { { .susp_fen = 0 } }, |
| 1320 | CS_VERBOSE); |
| 1321 | } |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1322 | spin_unlock_irq(&device->resource->req_lock); |
Philipp Reisner | 88f79ec | 2012-08-27 17:16:21 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1325 | /* Became sync source. With protocol >= 96, we still need to send out |
| 1326 | * the sync uuid now. Need to do that before any drbd_send_state, or |
| 1327 | * the other side may go "paused sync" before receiving the sync uuids, |
| 1328 | * which is unexpected. */ |
| 1329 | if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) && |
| 1330 | (ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) && |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1331 | connection->agreed_pro_version >= 96 && get_ldev(device)) { |
| 1332 | drbd_gen_and_send_sync_uuid(peer_device); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1333 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /* Do not change the order of the if above and the two below... */ |
Philipp Reisner | 369bea6 | 2011-07-06 23:04:44 +0200 | [diff] [blame] | 1337 | if (os.pdsk == D_DISKLESS && |
| 1338 | ns.pdsk > D_DISKLESS && ns.pdsk != D_UNKNOWN) { /* attach on the peer */ |
Lars Ellenberg | a324896 | 2012-07-30 09:10:41 +0200 | [diff] [blame] | 1339 | /* we probably will start a resync soon. |
| 1340 | * make sure those things are properly reset. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1341 | device->rs_total = 0; |
| 1342 | device->rs_failed = 0; |
| 1343 | atomic_set(&device->rs_pending_cnt, 0); |
| 1344 | drbd_rs_cancel_all(device); |
Lars Ellenberg | a324896 | 2012-07-30 09:10:41 +0200 | [diff] [blame] | 1345 | |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1346 | drbd_send_uuids(peer_device); |
| 1347 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1348 | } |
| 1349 | /* No point in queuing send_bitmap if we don't have a connection |
| 1350 | * anymore, so check also the _current_ state, not only the new state |
| 1351 | * at the time this work was queued. */ |
| 1352 | if (os.conn != C_WF_BITMAP_S && ns.conn == C_WF_BITMAP_S && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1353 | device->state.conn == C_WF_BITMAP_S) |
| 1354 | drbd_queue_bitmap_io(device, &drbd_send_bitmap, NULL, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1355 | "send_bitmap (WFBitMapS)", |
| 1356 | BM_LOCKED_TEST_ALLOWED); |
| 1357 | |
| 1358 | /* Lost contact to peer's copy of the data */ |
| 1359 | if ((os.pdsk >= D_INCONSISTENT && |
| 1360 | os.pdsk != D_UNKNOWN && |
| 1361 | os.pdsk != D_OUTDATED) |
| 1362 | && (ns.pdsk < D_INCONSISTENT || |
| 1363 | ns.pdsk == D_UNKNOWN || |
| 1364 | ns.pdsk == D_OUTDATED)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1365 | if (get_ldev(device)) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1366 | if ((ns.role == R_PRIMARY || ns.peer == R_PRIMARY) && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1367 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { |
| 1368 | if (drbd_suspended(device)) { |
| 1369 | set_bit(NEW_CUR_UUID, &device->flags); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1370 | } else { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1371 | drbd_uuid_new_current(device); |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1372 | drbd_send_uuids(peer_device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1373 | } |
| 1374 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1375 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1379 | if (ns.pdsk < D_INCONSISTENT && get_ldev(device)) { |
Philipp Reisner | 0cfac5d | 2011-11-10 12:12:52 +0100 | [diff] [blame] | 1380 | if (os.peer == R_SECONDARY && ns.peer == R_PRIMARY && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1381 | device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { |
| 1382 | drbd_uuid_new_current(device); |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1383 | drbd_send_uuids(peer_device); |
Philipp Reisner | 0cfac5d | 2011-11-10 12:12:52 +0100 | [diff] [blame] | 1384 | } |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1385 | /* D_DISKLESS Peer becomes secondary */ |
| 1386 | if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY) |
| 1387 | /* We may still be Primary ourselves. |
| 1388 | * No harm done if the bitmap still changes, |
| 1389 | * redirtied pages will follow later. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1390 | drbd_bitmap_io_from_worker(device, &drbd_bm_write, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1391 | "demote diskless peer", BM_LOCKED_SET_ALLOWED); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1392 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /* Write out all changed bits on demote. |
| 1396 | * Though, no need to da that just yet |
| 1397 | * if there is a resync going on still */ |
| 1398 | if (os.role == R_PRIMARY && ns.role == R_SECONDARY && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1399 | device->state.conn <= C_CONNECTED && get_ldev(device)) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1400 | /* No changes to the bitmap expected this time, so assert that, |
| 1401 | * even though no harm was done if it did change. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1402 | drbd_bitmap_io_from_worker(device, &drbd_bm_write, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1403 | "demote", BM_LOCKED_TEST_ALLOWED); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1404 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /* Last part of the attaching process ... */ |
| 1408 | if (ns.conn >= C_CONNECTED && |
| 1409 | os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) { |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1410 | drbd_send_sizes(peer_device, 0, 0); /* to start sync... */ |
| 1411 | drbd_send_uuids(peer_device); |
| 1412 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /* We want to pause/continue resync, tell peer. */ |
| 1416 | if (ns.conn >= C_CONNECTED && |
| 1417 | ((os.aftr_isp != ns.aftr_isp) || |
| 1418 | (os.user_isp != ns.user_isp))) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1419 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1420 | |
| 1421 | /* In case one of the isp bits got set, suspend other devices. */ |
| 1422 | if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) && |
| 1423 | (ns.aftr_isp || ns.peer_isp || ns.user_isp)) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1424 | suspend_other_sg(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1425 | |
| 1426 | /* Make sure the peer gets informed about eventual state |
| 1427 | changes (ISP bits) while we were in WFReportParams. */ |
| 1428 | if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1429 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1430 | |
| 1431 | if (os.conn != C_AHEAD && ns.conn == C_AHEAD) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1432 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1433 | |
| 1434 | /* We are in the progress to start a full sync... */ |
| 1435 | if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) || |
| 1436 | (os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S)) |
| 1437 | /* no other bitmap changes expected during this phase */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1438 | drbd_queue_bitmap_io(device, |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1439 | &drbd_bmio_set_n_write, &abw_start_sync, |
| 1440 | "set_n_write from StartingSync", BM_LOCKED_TEST_ALLOWED); |
| 1441 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1442 | /* first half of local IO error, failure to attach, |
| 1443 | * or administrative detach */ |
| 1444 | if (os.disk != D_FAILED && ns.disk == D_FAILED) { |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1445 | enum drbd_io_error_p eh = EP_PASS_ON; |
| 1446 | int was_io_error = 0; |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 1447 | /* corresponding get_ldev was in _drbd_set_state, to serialize |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1448 | * our cleanup here with the transition to D_DISKLESS. |
| 1449 | * But is is still not save to dreference ldev here, since |
| 1450 | * we might come from an failed Attach before ldev was set. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1451 | if (device->ldev) { |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1452 | rcu_read_lock(); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1453 | eh = rcu_dereference(device->ldev->disk_conf)->on_io_error; |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1454 | rcu_read_unlock(); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1455 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1456 | was_io_error = test_and_clear_bit(WAS_IO_ERROR, &device->flags); |
Philipp Reisner | cdfda63 | 2011-07-05 15:38:59 +0200 | [diff] [blame] | 1457 | |
Lars Ellenberg | 6f1a656 | 2012-07-30 09:11:01 +0200 | [diff] [blame] | 1458 | if (was_io_error && eh == EP_CALL_HELPER) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1459 | drbd_khelper(device, "local-io-error"); |
Lars Ellenberg | 6f1a656 | 2012-07-30 09:11:01 +0200 | [diff] [blame] | 1460 | |
Lars Ellenberg | 0c84966 | 2012-07-30 09:07:28 +0200 | [diff] [blame] | 1461 | /* Immediately allow completion of all application IO, |
| 1462 | * that waits for completion from the local disk, |
| 1463 | * if this was a force-detach due to disk_timeout |
| 1464 | * or administrator request (drbdsetup detach --force). |
| 1465 | * Do NOT abort otherwise. |
| 1466 | * Aborting local requests may cause serious problems, |
| 1467 | * if requests are completed to upper layers already, |
| 1468 | * and then later the already submitted local bio completes. |
| 1469 | * This can cause DMA into former bio pages that meanwhile |
| 1470 | * have been re-used for other things. |
| 1471 | * So aborting local requests may cause crashes, |
| 1472 | * or even worse, silent data corruption. |
| 1473 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1474 | if (test_and_clear_bit(FORCE_DETACH, &device->flags)) |
| 1475 | tl_abort_disk_io(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1476 | |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1477 | /* current state still has to be D_FAILED, |
| 1478 | * there is only one way out: to D_DISKLESS, |
| 1479 | * and that may only happen after our put_ldev below. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1480 | if (device->state.disk != D_FAILED) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1481 | drbd_err(device, |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1482 | "ASSERT FAILED: disk is %s during detach\n", |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1483 | drbd_disk_str(device->state.disk)); |
Philipp Reisner | 6ab9b1b | 2011-12-13 18:32:18 +0100 | [diff] [blame] | 1484 | |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1485 | if (ns.conn >= C_CONNECTED) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1486 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1487 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1488 | drbd_rs_cancel_all(device); |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1489 | |
| 1490 | /* In case we want to get something to stable storage still, |
| 1491 | * this may be the last chance. |
| 1492 | * Following put_ldev may transition to D_DISKLESS. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1493 | drbd_md_sync(device); |
Philipp Reisner | 32db80f | 2012-02-22 11:51:57 +0100 | [diff] [blame] | 1494 | } |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1495 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1496 | } |
| 1497 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1498 | /* second half of local IO error, failure to attach, |
| 1499 | * or administrative detach, |
| 1500 | * after local_cnt references have reached zero again */ |
| 1501 | if (os.disk != D_DISKLESS && ns.disk == D_DISKLESS) { |
| 1502 | /* We must still be diskless, |
| 1503 | * re-attach has to be serialized with this! */ |
| 1504 | if (device->state.disk != D_DISKLESS) |
Andreas Gruenbacher | d018017 | 2011-07-03 17:53:52 +0200 | [diff] [blame] | 1505 | drbd_err(device, |
| 1506 | "ASSERT FAILED: disk is %s while going diskless\n", |
| 1507 | drbd_disk_str(device->state.disk)); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1508 | |
Philipp Reisner | 6ab9b1b | 2011-12-13 18:32:18 +0100 | [diff] [blame] | 1509 | if (ns.conn >= C_CONNECTED) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1510 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1511 | /* corresponding get_ldev in __drbd_set_state |
| 1512 | * this may finally trigger drbd_ldev_destroy. */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1513 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | /* Notify peer that I had a local IO error, and did not detached.. */ |
Philipp Reisner | 6ab9b1b | 2011-12-13 18:32:18 +0100 | [diff] [blame] | 1517 | if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1518 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1519 | |
| 1520 | /* Disks got bigger while they were detached */ |
| 1521 | if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING && |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1522 | test_and_clear_bit(RESYNC_AFTER_NEG, &device->flags)) { |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1523 | if (ns.conn == C_CONNECTED) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1524 | resync_after_online_grow(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /* A resync finished or aborted, wake paused devices... */ |
| 1528 | if ((os.conn > C_CONNECTED && ns.conn <= C_CONNECTED) || |
| 1529 | (os.peer_isp && !ns.peer_isp) || |
| 1530 | (os.user_isp && !ns.user_isp)) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1531 | resume_next_sg(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1532 | |
| 1533 | /* sync target done with resync. Explicitly notify peer, even though |
| 1534 | * it should (at least for non-empty resyncs) already know itself. */ |
| 1535 | if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1536 | drbd_send_state(peer_device, ns); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1537 | |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 1538 | /* Verify finished, or reached stop sector. Peer did not know about |
| 1539 | * the stop sector, and we may even have changed the stop sector during |
| 1540 | * verify to interrupt/stop early. Send the new state. */ |
| 1541 | if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1542 | && verify_can_do_stop_sector(device)) |
Lars Ellenberg | 44a4d55 | 2013-11-22 12:40:58 +0100 | [diff] [blame] | 1543 | drbd_send_state(peer_device, ns); |
Lars Ellenberg | 58ffa58 | 2012-07-26 14:09:49 +0200 | [diff] [blame] | 1544 | |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1545 | /* This triggers bitmap writeout of potentially still unwritten pages |
| 1546 | * if the resync finished cleanly, or aborted because of peer disk |
| 1547 | * failure, or because of connection loss. |
| 1548 | * For resync aborted because of local disk failure, we cannot do |
| 1549 | * any bitmap writeout anymore. |
| 1550 | * No harm done if some bits change during this phase. |
| 1551 | */ |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1552 | if (os.conn > C_CONNECTED && ns.conn <= C_CONNECTED && get_ldev(device)) { |
| 1553 | drbd_queue_bitmap_io(device, &drbd_bm_write_copy_pages, NULL, |
Lars Ellenberg | a220d29 | 2012-05-07 12:07:18 +0200 | [diff] [blame] | 1554 | "write from resync_finished", BM_LOCKED_CHANGE_ALLOWED); |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1555 | put_ldev(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | if (ns.disk == D_DISKLESS && |
| 1559 | ns.conn == C_STANDALONE && |
| 1560 | ns.role == R_SECONDARY) { |
| 1561 | if (os.aftr_isp != ns.aftr_isp) |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1562 | resume_next_sg(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1565 | drbd_md_sync(device); |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1568 | struct after_conn_state_chg_work { |
Andreas Gruenbacher | 4c00760 | 2011-08-25 15:14:48 +0200 | [diff] [blame] | 1569 | struct drbd_work w; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1570 | enum drbd_conns oc; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1571 | union drbd_state ns_min; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1572 | union drbd_state ns_max; /* new, max state, over all devices */ |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1573 | enum chg_state_flags flags; |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1574 | struct drbd_connection *connection; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1575 | }; |
Philipp Reisner | b890733 | 2011-01-27 14:07:51 +0100 | [diff] [blame] | 1576 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1577 | static int w_after_conn_state_ch(struct drbd_work *w, int unused) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1578 | { |
| 1579 | struct after_conn_state_chg_work *acscw = |
Andreas Gruenbacher | 4c00760 | 2011-08-25 15:14:48 +0200 | [diff] [blame] | 1580 | container_of(w, struct after_conn_state_chg_work, w); |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1581 | struct drbd_connection *connection = acscw->connection; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1582 | enum drbd_conns oc = acscw->oc; |
Philipp Reisner | 5f082f9 | 2011-03-29 13:20:58 +0200 | [diff] [blame] | 1583 | union drbd_state ns_max = acscw->ns_max; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1584 | struct drbd_peer_device *peer_device; |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1585 | int vnr; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1586 | |
| 1587 | kfree(acscw); |
| 1588 | |
| 1589 | /* Upon network configuration, we need to start the receiver */ |
Philipp Reisner | 5f082f9 | 2011-03-29 13:20:58 +0200 | [diff] [blame] | 1590 | if (oc == C_STANDALONE && ns_max.conn == C_UNCONNECTED) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1591 | drbd_thread_start(&connection->receiver); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1592 | |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 1593 | if (oc == C_DISCONNECTING && ns_max.conn == C_STANDALONE) { |
| 1594 | struct net_conf *old_conf; |
| 1595 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1596 | mutex_lock(&connection->resource->conf_update); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1597 | old_conf = connection->net_conf; |
| 1598 | connection->my_addr_len = 0; |
| 1599 | connection->peer_addr_len = 0; |
Monam Agarwal | ccdd6a9 | 2014-03-23 02:02:29 +0530 | [diff] [blame] | 1600 | RCU_INIT_POINTER(connection->net_conf, NULL); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1601 | conn_free_crypto(connection); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1602 | mutex_unlock(&connection->resource->conf_update); |
Lars Ellenberg | f3dfa40 | 2011-05-02 10:45:05 +0200 | [diff] [blame] | 1603 | |
| 1604 | synchronize_rcu(); |
| 1605 | kfree(old_conf); |
| 1606 | } |
| 1607 | |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1608 | if (ns_max.susp_fen) { |
| 1609 | /* case1: The outdate peer handler is successful: */ |
| 1610 | if (ns_max.pdsk <= D_OUTDATED) { |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1611 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1612 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1613 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1614 | if (test_bit(NEW_CUR_UUID, &device->flags)) { |
| 1615 | drbd_uuid_new_current(device); |
| 1616 | clear_bit(NEW_CUR_UUID, &device->flags); |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1617 | } |
| 1618 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1619 | rcu_read_unlock(); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1620 | spin_lock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1621 | _tl_restart(connection, CONNECTION_LOST_WHILE_PENDING); |
| 1622 | _conn_request_state(connection, |
Philipp Reisner | 8a0bab2 | 2012-08-07 13:28:00 +0200 | [diff] [blame] | 1623 | (union drbd_state) { { .susp_fen = 1 } }, |
| 1624 | (union drbd_state) { { .susp_fen = 0 } }, |
| 1625 | CS_VERBOSE); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1626 | spin_unlock_irq(&connection->resource->req_lock); |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1627 | } |
Philipp Reisner | a6d00c8 | 2011-03-29 18:16:11 +0200 | [diff] [blame] | 1628 | } |
Andreas Gruenbacher | 05a10ec | 2011-06-07 22:54:17 +0200 | [diff] [blame] | 1629 | kref_put(&connection->kref, drbd_destroy_connection); |
Philipp Reisner | 19fffd7 | 2012-08-28 16:48:03 +0200 | [diff] [blame] | 1630 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1631 | conn_md_sync(connection); |
Philipp Reisner | 19fffd7 | 2012-08-28 16:48:03 +0200 | [diff] [blame] | 1632 | |
Andreas Gruenbacher | 99920dc | 2011-03-16 15:31:39 +0100 | [diff] [blame] | 1633 | return 0; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Lars Ellenberg | 8ce953a | 2014-02-27 09:46:18 +0100 | [diff] [blame] | 1636 | static void conn_old_common_state(struct drbd_connection *connection, union drbd_state *pcs, enum chg_state_flags *pf) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1637 | { |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1638 | enum chg_state_flags flags = ~0; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1639 | struct drbd_peer_device *peer_device; |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1640 | int vnr, first_vol = 1; |
Philipp Reisner | e0e1665 | 2011-07-11 17:04:23 +0200 | [diff] [blame] | 1641 | union drbd_dev_state os, cs = { |
| 1642 | { .role = R_SECONDARY, |
| 1643 | .peer = R_UNKNOWN, |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1644 | .conn = connection->cstate, |
Philipp Reisner | e0e1665 | 2011-07-11 17:04:23 +0200 | [diff] [blame] | 1645 | .disk = D_DISKLESS, |
| 1646 | .pdsk = D_UNKNOWN, |
| 1647 | } }; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1648 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1649 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1650 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1651 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1652 | os = device->state; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1653 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1654 | if (first_vol) { |
| 1655 | cs = os; |
| 1656 | first_vol = 0; |
| 1657 | continue; |
| 1658 | } |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1659 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1660 | if (cs.role != os.role) |
| 1661 | flags &= ~CS_DC_ROLE; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1662 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1663 | if (cs.peer != os.peer) |
| 1664 | flags &= ~CS_DC_PEER; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1665 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1666 | if (cs.conn != os.conn) |
| 1667 | flags &= ~CS_DC_CONN; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1668 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1669 | if (cs.disk != os.disk) |
| 1670 | flags &= ~CS_DC_DISK; |
| 1671 | |
| 1672 | if (cs.pdsk != os.pdsk) |
| 1673 | flags &= ~CS_DC_PDSK; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1674 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1675 | rcu_read_unlock(); |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1676 | |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1677 | *pf |= CS_DC_MASK; |
| 1678 | *pf &= flags; |
Philipp Reisner | da9fbc2 | 2011-03-29 10:52:01 +0200 | [diff] [blame] | 1679 | (*pcs).i = cs.i; |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1680 | } |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1681 | |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1682 | static enum drbd_state_rv |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1683 | conn_is_valid_transition(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
Philipp Reisner | 88ef594 | 2011-03-25 14:31:11 +0100 | [diff] [blame] | 1684 | enum chg_state_flags flags) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1685 | { |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1686 | enum drbd_state_rv rv = SS_SUCCESS; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1687 | union drbd_state ns, os; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1688 | struct drbd_peer_device *peer_device; |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1689 | int vnr; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1690 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1691 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1692 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1693 | struct drbd_device *device = peer_device->device; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1694 | os = drbd_read_state(device); |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 1695 | ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1696 | |
Philipp Reisner | 778bcf2 | 2011-03-28 12:55:03 +0200 | [diff] [blame] | 1697 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) |
| 1698 | ns.disk = os.disk; |
| 1699 | |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1700 | if (ns.i == os.i) |
| 1701 | continue; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1702 | |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1703 | rv = is_valid_transition(os, ns); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1704 | |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1705 | if (rv >= SS_SUCCESS && !(flags & CS_HARD)) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1706 | rv = is_valid_state(device, ns); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1707 | if (rv < SS_SUCCESS) { |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1708 | if (is_valid_state(device, os) == rv) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1709 | rv = is_valid_soft_transition(os, ns, connection); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1710 | } else |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1711 | rv = is_valid_soft_transition(os, ns, connection); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1712 | } |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1713 | |
| 1714 | if (rv < SS_SUCCESS) { |
| 1715 | if (flags & CS_VERBOSE) |
| 1716 | print_st_err(device, os, ns, rv); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1717 | break; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1718 | } |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1719 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1720 | rcu_read_unlock(); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1721 | |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1722 | return rv; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
Lars Ellenberg | 8ce953a | 2014-02-27 09:46:18 +0100 | [diff] [blame] | 1725 | static void |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1726 | conn_set_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1727 | union drbd_state *pns_min, union drbd_state *pns_max, enum chg_state_flags flags) |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1728 | { |
Philipp Reisner | f132f55 | 2011-07-18 10:44:24 +0200 | [diff] [blame] | 1729 | union drbd_state ns, os, ns_max = { }; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1730 | union drbd_state ns_min = { |
| 1731 | { .role = R_MASK, |
| 1732 | .peer = R_MASK, |
Philipp Reisner | e0e1665 | 2011-07-11 17:04:23 +0200 | [diff] [blame] | 1733 | .conn = val.conn, |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1734 | .disk = D_MASK, |
| 1735 | .pdsk = D_MASK |
| 1736 | } }; |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1737 | struct drbd_peer_device *peer_device; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1738 | enum drbd_state_rv rv; |
Philipp Reisner | f132f55 | 2011-07-18 10:44:24 +0200 | [diff] [blame] | 1739 | int vnr, number_of_volumes = 0; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1740 | |
Lars Ellenberg | 07be15b | 2012-05-07 11:53:08 +0200 | [diff] [blame] | 1741 | if (mask.conn == C_MASK) { |
| 1742 | /* remember last connect time so request_timer_fn() won't |
| 1743 | * kill newly established sessions while we are still trying to thaw |
| 1744 | * previously frozen IO */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1745 | if (connection->cstate != C_WF_REPORT_PARAMS && val.conn == C_WF_REPORT_PARAMS) |
| 1746 | connection->last_reconnect_jif = jiffies; |
Lars Ellenberg | 07be15b | 2012-05-07 11:53:08 +0200 | [diff] [blame] | 1747 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1748 | connection->cstate = val.conn; |
Lars Ellenberg | 07be15b | 2012-05-07 11:53:08 +0200 | [diff] [blame] | 1749 | } |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1750 | |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1751 | rcu_read_lock(); |
Andreas Gruenbacher | c06ece6 | 2011-06-21 17:23:59 +0200 | [diff] [blame] | 1752 | idr_for_each_entry(&connection->peer_devices, peer_device, vnr) { |
| 1753 | struct drbd_device *device = peer_device->device; |
Philipp Reisner | f132f55 | 2011-07-18 10:44:24 +0200 | [diff] [blame] | 1754 | number_of_volumes++; |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1755 | os = drbd_read_state(device); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1756 | ns = apply_mask_val(os, mask, val); |
Philipp Reisner | d7fe69c | 2014-04-28 18:43:13 +0200 | [diff] [blame] | 1757 | ns = sanitize_state(device, os, ns, NULL); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1758 | |
Philipp Reisner | 778bcf2 | 2011-03-28 12:55:03 +0200 | [diff] [blame] | 1759 | if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED) |
| 1760 | ns.disk = os.disk; |
| 1761 | |
Andreas Gruenbacher | 28bc3b8 | 2014-08-14 18:33:30 +0200 | [diff] [blame^] | 1762 | rv = _drbd_set_state(device, ns, flags, NULL); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1763 | if (rv < SS_SUCCESS) |
| 1764 | BUG(); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1765 | |
Andreas Gruenbacher | b30ab79 | 2011-07-03 13:26:43 +0200 | [diff] [blame] | 1766 | ns.i = device->state.i; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1767 | ns_max.role = max_role(ns.role, ns_max.role); |
| 1768 | ns_max.peer = max_role(ns.peer, ns_max.peer); |
| 1769 | ns_max.conn = max_t(enum drbd_conns, ns.conn, ns_max.conn); |
| 1770 | ns_max.disk = max_t(enum drbd_disk_state, ns.disk, ns_max.disk); |
| 1771 | ns_max.pdsk = max_t(enum drbd_disk_state, ns.pdsk, ns_max.pdsk); |
| 1772 | |
| 1773 | ns_min.role = min_role(ns.role, ns_min.role); |
| 1774 | ns_min.peer = min_role(ns.peer, ns_min.peer); |
| 1775 | ns_min.conn = min_t(enum drbd_conns, ns.conn, ns_min.conn); |
| 1776 | ns_min.disk = min_t(enum drbd_disk_state, ns.disk, ns_min.disk); |
| 1777 | ns_min.pdsk = min_t(enum drbd_disk_state, ns.pdsk, ns_min.pdsk); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1778 | } |
Philipp Reisner | 695d08f | 2011-04-11 22:53:32 -0700 | [diff] [blame] | 1779 | rcu_read_unlock(); |
Philipp Reisner | bd0c824 | 2011-03-25 12:02:20 +0100 | [diff] [blame] | 1780 | |
Philipp Reisner | f132f55 | 2011-07-18 10:44:24 +0200 | [diff] [blame] | 1781 | if (number_of_volumes == 0) { |
| 1782 | ns_min = ns_max = (union drbd_state) { { |
| 1783 | .role = R_SECONDARY, |
| 1784 | .peer = R_UNKNOWN, |
| 1785 | .conn = val.conn, |
| 1786 | .disk = D_DISKLESS, |
| 1787 | .pdsk = D_UNKNOWN |
| 1788 | } }; |
| 1789 | } |
| 1790 | |
Andreas Gruenbacher | 6bbf53c | 2011-07-08 01:19:44 +0200 | [diff] [blame] | 1791 | ns_min.susp = ns_max.susp = connection->resource->susp; |
| 1792 | ns_min.susp_nod = ns_max.susp_nod = connection->resource->susp_nod; |
| 1793 | ns_min.susp_fen = ns_max.susp_fen = connection->resource->susp_fen; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1794 | |
| 1795 | *pns_min = ns_min; |
| 1796 | *pns_max = ns_max; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1799 | static enum drbd_state_rv |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1800 | _conn_rq_cond(struct drbd_connection *connection, union drbd_state mask, union drbd_state val) |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1801 | { |
Philipp Reisner | 88ea685 | 2014-04-28 18:43:20 +0200 | [diff] [blame] | 1802 | enum drbd_state_rv err, rv = SS_UNKNOWN_ERROR; /* continue waiting */; |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1803 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1804 | if (test_and_clear_bit(CONN_WD_ST_CHG_OKAY, &connection->flags)) |
Philipp Reisner | 88ea685 | 2014-04-28 18:43:20 +0200 | [diff] [blame] | 1805 | rv = SS_CW_SUCCESS; |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1806 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1807 | if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &connection->flags)) |
Philipp Reisner | 88ea685 | 2014-04-28 18:43:20 +0200 | [diff] [blame] | 1808 | rv = SS_CW_FAILED_BY_PEER; |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1809 | |
Philipp Reisner | 88ea685 | 2014-04-28 18:43:20 +0200 | [diff] [blame] | 1810 | err = conn_is_valid_transition(connection, mask, val, 0); |
| 1811 | if (err == SS_SUCCESS && connection->cstate == C_WF_REPORT_PARAMS) |
| 1812 | return rv; |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1813 | |
Philipp Reisner | 88ea685 | 2014-04-28 18:43:20 +0200 | [diff] [blame] | 1814 | return err; |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1815 | } |
| 1816 | |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1817 | enum drbd_state_rv |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1818 | _conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1819 | enum chg_state_flags flags) |
| 1820 | { |
| 1821 | enum drbd_state_rv rv = SS_SUCCESS; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1822 | struct after_conn_state_chg_work *acscw; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1823 | enum drbd_conns oc = connection->cstate; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1824 | union drbd_state ns_max, ns_min, os; |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1825 | bool have_mutex = false; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1826 | |
Philipp Reisner | 07fc961 | 2012-08-28 11:07:56 +0200 | [diff] [blame] | 1827 | if (mask.conn) { |
| 1828 | rv = is_valid_conn_transition(oc, val.conn); |
| 1829 | if (rv < SS_SUCCESS) |
| 1830 | goto abort; |
| 1831 | } |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1832 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1833 | rv = conn_is_valid_transition(connection, mask, val, flags); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1834 | if (rv < SS_SUCCESS) |
| 1835 | goto abort; |
| 1836 | |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1837 | if (oc == C_WF_REPORT_PARAMS && val.conn == C_DISCONNECTING && |
| 1838 | !(flags & (CS_LOCAL_ONLY | CS_HARD))) { |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1839 | |
| 1840 | /* This will be a cluster-wide state change. |
| 1841 | * Need to give up the spinlock, grab the mutex, |
| 1842 | * then send the state change request, ... */ |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1843 | spin_unlock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1844 | mutex_lock(&connection->cstate_mutex); |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1845 | have_mutex = true; |
| 1846 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1847 | set_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
| 1848 | if (conn_send_state_req(connection, mask, val)) { |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1849 | /* sending failed. */ |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1850 | clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1851 | rv = SS_CW_FAILED_BY_PEER; |
| 1852 | /* need to re-aquire the spin lock, though */ |
| 1853 | goto abort_unlocked; |
| 1854 | } |
| 1855 | |
| 1856 | if (val.conn == C_DISCONNECTING) |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1857 | set_bit(DISCONNECT_SENT, &connection->flags); |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1858 | |
| 1859 | /* ... and re-aquire the spinlock. |
| 1860 | * If _conn_rq_cond() returned >= SS_SUCCESS, we must call |
| 1861 | * conn_set_state() within the same spinlock. */ |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1862 | spin_lock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1863 | wait_event_lock_irq(connection->ping_wait, |
| 1864 | (rv = _conn_rq_cond(connection, mask, val)), |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1865 | connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1866 | clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags); |
Philipp Reisner | df24aa4 | 2011-02-15 11:14:44 +0100 | [diff] [blame] | 1867 | if (rv < SS_SUCCESS) |
| 1868 | goto abort; |
| 1869 | } |
| 1870 | |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1871 | conn_old_common_state(connection, &os, &flags); |
Philipp Reisner | 706cb24 | 2011-03-29 15:20:27 +0200 | [diff] [blame] | 1872 | flags |= CS_DC_SUSP; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1873 | conn_set_state(connection, mask, val, &ns_min, &ns_max, flags); |
| 1874 | conn_pr_state_change(connection, os, ns_max, flags); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1875 | |
| 1876 | acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC); |
| 1877 | if (acscw) { |
Philipp Reisner | 435693e | 2011-03-25 15:11:30 +0100 | [diff] [blame] | 1878 | acscw->oc = os.conn; |
Philipp Reisner | 8c7e16c | 2011-03-29 14:01:02 +0200 | [diff] [blame] | 1879 | acscw->ns_min = ns_min; |
Philipp Reisner | 5f082f9 | 2011-03-29 13:20:58 +0200 | [diff] [blame] | 1880 | acscw->ns_max = ns_max; |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1881 | acscw->flags = flags; |
Andreas Gruenbacher | 4c00760 | 2011-08-25 15:14:48 +0200 | [diff] [blame] | 1882 | acscw->w.cb = w_after_conn_state_ch; |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1883 | kref_get(&connection->kref); |
Andreas Gruenbacher | 84b8c06 | 2011-07-28 15:27:51 +0200 | [diff] [blame] | 1884 | acscw->connection = connection; |
Andreas Gruenbacher | 4c00760 | 2011-08-25 15:14:48 +0200 | [diff] [blame] | 1885 | drbd_queue_work(&connection->sender_work, &acscw->w); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1886 | } else { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1887 | drbd_err(connection, "Could not kmalloc an acscw\n"); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Philipp Reisner | a01842e | 2011-12-13 17:40:53 +0100 | [diff] [blame] | 1890 | abort: |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1891 | if (have_mutex) { |
| 1892 | /* mutex_unlock() "... must not be used in interrupt context.", |
| 1893 | * so give up the spinlock, then re-aquire it */ |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1894 | spin_unlock_irq(&connection->resource->req_lock); |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1895 | abort_unlocked: |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1896 | mutex_unlock(&connection->cstate_mutex); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1897 | spin_lock_irq(&connection->resource->req_lock); |
Lars Ellenberg | c02abda | 2012-08-22 16:15:26 +0200 | [diff] [blame] | 1898 | } |
| 1899 | if (rv < SS_SUCCESS && flags & CS_VERBOSE) { |
Andreas Gruenbacher | 1ec861e | 2011-07-06 11:01:44 +0200 | [diff] [blame] | 1900 | drbd_err(connection, "State change failed: %s\n", drbd_set_st_err_str(rv)); |
| 1901 | drbd_err(connection, " mask = 0x%x val = 0x%x\n", mask.i, val.i); |
| 1902 | drbd_err(connection, " old_conn:%s wanted_conn:%s\n", drbd_conn_str(oc), drbd_conn_str(val.conn)); |
Philipp Reisner | a01842e | 2011-12-13 17:40:53 +0100 | [diff] [blame] | 1903 | } |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1904 | return rv; |
| 1905 | } |
| 1906 | |
| 1907 | enum drbd_state_rv |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1908 | conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val, |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1909 | enum chg_state_flags flags) |
| 1910 | { |
| 1911 | enum drbd_state_rv rv; |
| 1912 | |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1913 | spin_lock_irq(&connection->resource->req_lock); |
Andreas Gruenbacher | bde89a9 | 2011-05-30 16:32:41 +0200 | [diff] [blame] | 1914 | rv = _conn_request_state(connection, mask, val, flags); |
Andreas Gruenbacher | 0500813 | 2011-07-07 14:19:42 +0200 | [diff] [blame] | 1915 | spin_unlock_irq(&connection->resource->req_lock); |
Philipp Reisner | bbeb641 | 2011-02-10 13:45:46 +0100 | [diff] [blame] | 1916 | |
| 1917 | return rv; |
| 1918 | } |