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