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