2011-01-27 06:07:51 -07:00
|
|
|
/*
|
|
|
|
drbd_state.c
|
|
|
|
|
|
|
|
This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
|
|
|
|
|
|
|
|
Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
|
|
|
|
Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
|
|
|
|
Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
|
|
|
|
|
|
|
|
Thanks to Carter Burden, Bart Grantham and Gennadiy Nerubayev
|
|
|
|
from Logicworks, Inc. for making SDP replication support possible.
|
|
|
|
|
|
|
|
drbd is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
drbd is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with drbd; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/drbd_limits.h>
|
|
|
|
#include "drbd_int.h"
|
2011-05-30 03:47:37 -06:00
|
|
|
#include "drbd_protocol.h"
|
2011-01-27 06:07:51 -07:00
|
|
|
#include "drbd_req.h"
|
2014-07-31 09:41:33 -06:00
|
|
|
#include "drbd_state_change.h"
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
struct after_state_chg_work {
|
|
|
|
struct drbd_work w;
|
2011-07-28 07:27:51 -06:00
|
|
|
struct drbd_device *device;
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state os;
|
|
|
|
union drbd_state ns;
|
|
|
|
enum chg_state_flags flags;
|
|
|
|
struct completion *done;
|
2014-07-31 09:41:33 -06:00
|
|
|
struct drbd_state_change *state_change;
|
2011-01-27 06:07:51 -07:00
|
|
|
};
|
|
|
|
|
2011-05-31 05:07:24 -06:00
|
|
|
enum sanitize_state_warnings {
|
|
|
|
NO_WARNING,
|
|
|
|
ABORTED_ONLINE_VERIFY,
|
|
|
|
ABORTED_RESYNC,
|
|
|
|
CONNECTION_LOST_NEGOTIATING,
|
|
|
|
IMPLICITLY_UPGRADED_DISK,
|
|
|
|
IMPLICITLY_UPGRADED_PDSK,
|
|
|
|
};
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
static void count_objects(struct drbd_resource *resource,
|
|
|
|
unsigned int *n_devices,
|
|
|
|
unsigned int *n_connections)
|
|
|
|
{
|
|
|
|
struct drbd_device *device;
|
|
|
|
struct drbd_connection *connection;
|
|
|
|
int vnr;
|
|
|
|
|
|
|
|
*n_devices = 0;
|
|
|
|
*n_connections = 0;
|
|
|
|
|
|
|
|
idr_for_each_entry(&resource->devices, device, vnr)
|
|
|
|
(*n_devices)++;
|
2015-02-25 05:53:28 -07:00
|
|
|
for_each_connection(connection, resource)
|
2014-07-31 09:41:33 -06:00
|
|
|
(*n_connections)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct drbd_state_change *alloc_state_change(unsigned int n_devices, unsigned int n_connections, gfp_t gfp)
|
|
|
|
{
|
|
|
|
struct drbd_state_change *state_change;
|
|
|
|
unsigned int size, n;
|
|
|
|
|
|
|
|
size = sizeof(struct drbd_state_change) +
|
|
|
|
n_devices * sizeof(struct drbd_device_state_change) +
|
|
|
|
n_connections * sizeof(struct drbd_connection_state_change) +
|
|
|
|
n_devices * n_connections * sizeof(struct drbd_peer_device_state_change);
|
|
|
|
state_change = kmalloc(size, gfp);
|
|
|
|
if (!state_change)
|
|
|
|
return NULL;
|
|
|
|
state_change->n_devices = n_devices;
|
|
|
|
state_change->n_connections = n_connections;
|
|
|
|
state_change->devices = (void *)(state_change + 1);
|
|
|
|
state_change->connections = (void *)&state_change->devices[n_devices];
|
|
|
|
state_change->peer_devices = (void *)&state_change->connections[n_connections];
|
|
|
|
state_change->resource->resource = NULL;
|
|
|
|
for (n = 0; n < n_devices; n++)
|
|
|
|
state_change->devices[n].device = NULL;
|
|
|
|
for (n = 0; n < n_connections; n++)
|
|
|
|
state_change->connections[n].connection = NULL;
|
|
|
|
return state_change;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct drbd_state_change *remember_old_state(struct drbd_resource *resource, gfp_t gfp)
|
|
|
|
{
|
|
|
|
struct drbd_state_change *state_change;
|
|
|
|
struct drbd_device *device;
|
|
|
|
unsigned int n_devices;
|
|
|
|
struct drbd_connection *connection;
|
|
|
|
unsigned int n_connections;
|
|
|
|
int vnr;
|
|
|
|
|
|
|
|
struct drbd_device_state_change *device_state_change;
|
|
|
|
struct drbd_peer_device_state_change *peer_device_state_change;
|
|
|
|
struct drbd_connection_state_change *connection_state_change;
|
|
|
|
|
2015-02-25 05:53:28 -07:00
|
|
|
/* Caller holds req_lock spinlock.
|
|
|
|
* No state, no device IDR, no connections lists can change. */
|
2014-07-31 09:41:33 -06:00
|
|
|
count_objects(resource, &n_devices, &n_connections);
|
|
|
|
state_change = alloc_state_change(n_devices, n_connections, gfp);
|
|
|
|
if (!state_change)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
kref_get(&resource->kref);
|
|
|
|
state_change->resource->resource = resource;
|
|
|
|
state_change->resource->role[OLD] =
|
|
|
|
conn_highest_role(first_connection(resource));
|
|
|
|
state_change->resource->susp[OLD] = resource->susp;
|
|
|
|
state_change->resource->susp_nod[OLD] = resource->susp_nod;
|
|
|
|
state_change->resource->susp_fen[OLD] = resource->susp_fen;
|
|
|
|
|
2015-02-25 05:53:28 -07:00
|
|
|
connection_state_change = state_change->connections;
|
|
|
|
for_each_connection(connection, resource) {
|
|
|
|
kref_get(&connection->kref);
|
|
|
|
connection_state_change->connection = connection;
|
|
|
|
connection_state_change->cstate[OLD] =
|
|
|
|
connection->cstate;
|
|
|
|
connection_state_change->peer_role[OLD] =
|
|
|
|
conn_highest_peer(connection);
|
|
|
|
connection_state_change++;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
device_state_change = state_change->devices;
|
|
|
|
peer_device_state_change = state_change->peer_devices;
|
|
|
|
idr_for_each_entry(&resource->devices, device, vnr) {
|
|
|
|
kref_get(&device->kref);
|
|
|
|
device_state_change->device = device;
|
|
|
|
device_state_change->disk_state[OLD] = device->state.disk;
|
|
|
|
|
|
|
|
/* The peer_devices for each device have to be enumerated in
|
|
|
|
the order of the connections. We may not use for_each_peer_device() here. */
|
|
|
|
for_each_connection(connection, resource) {
|
|
|
|
struct drbd_peer_device *peer_device;
|
|
|
|
|
|
|
|
peer_device = conn_peer_device(connection, device->vnr);
|
|
|
|
peer_device_state_change->peer_device = peer_device;
|
|
|
|
peer_device_state_change->disk_state[OLD] =
|
|
|
|
device->state.pdsk;
|
|
|
|
peer_device_state_change->repl_state[OLD] =
|
|
|
|
max_t(enum drbd_conns,
|
|
|
|
C_WF_REPORT_PARAMS, device->state.conn);
|
|
|
|
peer_device_state_change->resync_susp_user[OLD] =
|
|
|
|
device->state.user_isp;
|
|
|
|
peer_device_state_change->resync_susp_peer[OLD] =
|
|
|
|
device->state.peer_isp;
|
|
|
|
peer_device_state_change->resync_susp_dependency[OLD] =
|
|
|
|
device->state.aftr_isp;
|
|
|
|
peer_device_state_change++;
|
|
|
|
}
|
|
|
|
device_state_change++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state_change;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remember_new_state(struct drbd_state_change *state_change)
|
|
|
|
{
|
|
|
|
struct drbd_resource_state_change *resource_state_change;
|
|
|
|
struct drbd_resource *resource;
|
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
if (!state_change)
|
|
|
|
return;
|
|
|
|
|
|
|
|
resource_state_change = &state_change->resource[0];
|
|
|
|
resource = resource_state_change->resource;
|
|
|
|
|
|
|
|
resource_state_change->role[NEW] =
|
|
|
|
conn_highest_role(first_connection(resource));
|
|
|
|
resource_state_change->susp[NEW] = resource->susp;
|
|
|
|
resource_state_change->susp_nod[NEW] = resource->susp_nod;
|
|
|
|
resource_state_change->susp_fen[NEW] = resource->susp_fen;
|
|
|
|
|
|
|
|
for (n = 0; n < state_change->n_devices; n++) {
|
|
|
|
struct drbd_device_state_change *device_state_change =
|
|
|
|
&state_change->devices[n];
|
|
|
|
struct drbd_device *device = device_state_change->device;
|
|
|
|
|
|
|
|
device_state_change->disk_state[NEW] = device->state.disk;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < state_change->n_connections; n++) {
|
|
|
|
struct drbd_connection_state_change *connection_state_change =
|
|
|
|
&state_change->connections[n];
|
|
|
|
struct drbd_connection *connection =
|
|
|
|
connection_state_change->connection;
|
|
|
|
|
|
|
|
connection_state_change->cstate[NEW] = connection->cstate;
|
|
|
|
connection_state_change->peer_role[NEW] =
|
|
|
|
conn_highest_peer(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < state_change->n_devices * state_change->n_connections; n++) {
|
|
|
|
struct drbd_peer_device_state_change *peer_device_state_change =
|
|
|
|
&state_change->peer_devices[n];
|
|
|
|
struct drbd_device *device =
|
|
|
|
peer_device_state_change->peer_device->device;
|
|
|
|
union drbd_dev_state state = device->state;
|
|
|
|
|
|
|
|
peer_device_state_change->disk_state[NEW] = state.pdsk;
|
|
|
|
peer_device_state_change->repl_state[NEW] =
|
|
|
|
max_t(enum drbd_conns, C_WF_REPORT_PARAMS, state.conn);
|
|
|
|
peer_device_state_change->resync_susp_user[NEW] =
|
|
|
|
state.user_isp;
|
|
|
|
peer_device_state_change->resync_susp_peer[NEW] =
|
|
|
|
state.peer_isp;
|
|
|
|
peer_device_state_change->resync_susp_dependency[NEW] =
|
|
|
|
state.aftr_isp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy_old_to_new_state_change(struct drbd_state_change *state_change)
|
|
|
|
{
|
|
|
|
struct drbd_resource_state_change *resource_state_change = &state_change->resource[0];
|
|
|
|
unsigned int n_device, n_connection, n_peer_device, n_peer_devices;
|
|
|
|
|
|
|
|
#define OLD_TO_NEW(x) \
|
|
|
|
(x[NEW] = x[OLD])
|
|
|
|
|
|
|
|
OLD_TO_NEW(resource_state_change->role);
|
|
|
|
OLD_TO_NEW(resource_state_change->susp);
|
|
|
|
OLD_TO_NEW(resource_state_change->susp_nod);
|
|
|
|
OLD_TO_NEW(resource_state_change->susp_fen);
|
|
|
|
|
|
|
|
for (n_connection = 0; n_connection < state_change->n_connections; n_connection++) {
|
|
|
|
struct drbd_connection_state_change *connection_state_change =
|
|
|
|
&state_change->connections[n_connection];
|
|
|
|
|
|
|
|
OLD_TO_NEW(connection_state_change->peer_role);
|
|
|
|
OLD_TO_NEW(connection_state_change->cstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n_device = 0; n_device < state_change->n_devices; n_device++) {
|
|
|
|
struct drbd_device_state_change *device_state_change =
|
|
|
|
&state_change->devices[n_device];
|
|
|
|
|
|
|
|
OLD_TO_NEW(device_state_change->disk_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
n_peer_devices = state_change->n_devices * state_change->n_connections;
|
|
|
|
for (n_peer_device = 0; n_peer_device < n_peer_devices; n_peer_device++) {
|
|
|
|
struct drbd_peer_device_state_change *p =
|
|
|
|
&state_change->peer_devices[n_peer_device];
|
|
|
|
|
|
|
|
OLD_TO_NEW(p->disk_state);
|
|
|
|
OLD_TO_NEW(p->repl_state);
|
|
|
|
OLD_TO_NEW(p->resync_susp_user);
|
|
|
|
OLD_TO_NEW(p->resync_susp_peer);
|
|
|
|
OLD_TO_NEW(p->resync_susp_dependency);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef OLD_TO_NEW
|
|
|
|
}
|
|
|
|
|
|
|
|
void forget_state_change(struct drbd_state_change *state_change)
|
|
|
|
{
|
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
if (!state_change)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state_change->resource->resource)
|
|
|
|
kref_put(&state_change->resource->resource->kref, drbd_destroy_resource);
|
|
|
|
for (n = 0; n < state_change->n_devices; n++) {
|
|
|
|
struct drbd_device *device = state_change->devices[n].device;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
kref_put(&device->kref, drbd_destroy_device);
|
|
|
|
}
|
|
|
|
for (n = 0; n < state_change->n_connections; n++) {
|
|
|
|
struct drbd_connection *connection =
|
|
|
|
state_change->connections[n].connection;
|
|
|
|
|
|
|
|
if (connection)
|
|
|
|
kref_put(&connection->kref, drbd_destroy_connection);
|
|
|
|
}
|
|
|
|
kfree(state_change);
|
|
|
|
}
|
|
|
|
|
2011-03-16 08:31:39 -06:00
|
|
|
static int w_after_state_ch(struct drbd_work *w, int unused);
|
2011-07-03 05:26:43 -06:00
|
|
|
static void after_state_ch(struct drbd_device *device, union drbd_state os,
|
2014-07-31 09:41:33 -06:00
|
|
|
union drbd_state ns, enum chg_state_flags flags,
|
|
|
|
struct drbd_state_change *);
|
2011-05-30 08:15:21 -06:00
|
|
|
static enum drbd_state_rv is_valid_state(struct drbd_device *, union drbd_state);
|
2011-05-30 08:32:41 -06:00
|
|
|
static enum drbd_state_rv is_valid_soft_transition(union drbd_state, union drbd_state, struct drbd_connection *);
|
2011-02-09 08:29:33 -07:00
|
|
|
static enum drbd_state_rv is_valid_transition(union drbd_state os, union drbd_state ns);
|
2014-04-28 10:43:13 -06:00
|
|
|
static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state os,
|
|
|
|
union drbd_state ns, enum sanitize_state_warnings *warn);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-03-28 08:48:11 -06:00
|
|
|
static inline bool is_susp(union drbd_state s)
|
|
|
|
{
|
|
|
|
return s.susp || s.susp_nod || s.susp_fen;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
bool conn_all_vols_unconf(struct drbd_connection *connection)
|
2011-02-18 06:23:11 -07:00
|
|
|
{
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-04-11 23:53:32 -06:00
|
|
|
bool rv = true;
|
2011-03-22 05:51:21 -06:00
|
|
|
int vnr;
|
2011-02-18 06:23:11 -07:00
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.disk != D_DISKLESS ||
|
|
|
|
device->state.conn != C_STANDALONE ||
|
|
|
|
device->state.role != R_SECONDARY) {
|
2011-04-11 23:53:32 -06:00
|
|
|
rv = false;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-18 06:23:11 -07:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return rv;
|
2011-02-18 06:23:11 -07:00
|
|
|
}
|
|
|
|
|
2011-03-24 04:03:07 -06:00
|
|
|
/* Unfortunately the states where not correctly ordered, when
|
|
|
|
they where defined. therefore can not use max_t() here. */
|
|
|
|
static enum drbd_role max_role(enum drbd_role role1, enum drbd_role role2)
|
|
|
|
{
|
|
|
|
if (role1 == R_PRIMARY || role2 == R_PRIMARY)
|
|
|
|
return R_PRIMARY;
|
|
|
|
if (role1 == R_SECONDARY || role2 == R_SECONDARY)
|
|
|
|
return R_SECONDARY;
|
|
|
|
return R_UNKNOWN;
|
|
|
|
}
|
2014-07-31 09:41:33 -06:00
|
|
|
|
2011-03-24 04:03:07 -06:00
|
|
|
static enum drbd_role min_role(enum drbd_role role1, enum drbd_role role2)
|
|
|
|
{
|
|
|
|
if (role1 == R_UNKNOWN || role2 == R_UNKNOWN)
|
|
|
|
return R_UNKNOWN;
|
|
|
|
if (role1 == R_SECONDARY || role2 == R_SECONDARY)
|
|
|
|
return R_SECONDARY;
|
|
|
|
return R_PRIMARY;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_role conn_highest_role(struct drbd_connection *connection)
|
2011-03-24 04:03:07 -06:00
|
|
|
{
|
2017-08-29 02:20:37 -06:00
|
|
|
enum drbd_role role = R_SECONDARY;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-24 04:03:07 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
role = max_role(role, device->state.role);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-24 04:03:07 -06:00
|
|
|
|
|
|
|
return role;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_role conn_highest_peer(struct drbd_connection *connection)
|
2011-03-24 04:03:07 -06:00
|
|
|
{
|
|
|
|
enum drbd_role peer = R_UNKNOWN;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-24 04:03:07 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
peer = max_role(peer, device->state.peer);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-24 04:03:07 -06:00
|
|
|
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_disk_state conn_highest_disk(struct drbd_connection *connection)
|
2011-03-24 04:03:07 -06:00
|
|
|
{
|
2014-09-11 06:29:05 -06:00
|
|
|
enum drbd_disk_state disk_state = D_DISKLESS;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-24 04:03:07 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2014-09-11 06:29:05 -06:00
|
|
|
disk_state = max_t(enum drbd_disk_state, disk_state, device->state.disk);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-24 04:03:07 -06:00
|
|
|
|
2014-09-11 06:29:05 -06:00
|
|
|
return disk_state;
|
2011-03-24 04:03:07 -06:00
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_disk_state conn_lowest_disk(struct drbd_connection *connection)
|
2011-03-29 10:15:49 -06:00
|
|
|
{
|
2014-09-11 06:29:05 -06:00
|
|
|
enum drbd_disk_state disk_state = D_MASK;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-29 10:15:49 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2014-09-11 06:29:05 -06:00
|
|
|
disk_state = min_t(enum drbd_disk_state, disk_state, device->state.disk);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-29 10:15:49 -06:00
|
|
|
|
2014-09-11 06:29:05 -06:00
|
|
|
return disk_state;
|
2011-03-29 10:15:49 -06:00
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_disk_state conn_highest_pdsk(struct drbd_connection *connection)
|
2011-03-24 04:03:07 -06:00
|
|
|
{
|
2014-09-11 06:29:05 -06:00
|
|
|
enum drbd_disk_state disk_state = D_DISKLESS;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-24 04:03:07 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2014-09-11 06:29:05 -06:00
|
|
|
disk_state = max_t(enum drbd_disk_state, disk_state, device->state.pdsk);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-24 04:03:07 -06:00
|
|
|
|
2014-09-11 06:29:05 -06:00
|
|
|
return disk_state;
|
2011-03-24 04:03:07 -06:00
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_conns conn_lowest_conn(struct drbd_connection *connection)
|
2011-03-29 06:21:03 -06:00
|
|
|
{
|
|
|
|
enum drbd_conns conn = C_MASK;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-29 06:21:03 -06:00
|
|
|
int vnr;
|
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
conn = min_t(enum drbd_conns, conn, device->state.conn);
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-29 06:21:03 -06:00
|
|
|
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
static bool no_peer_wf_report_params(struct drbd_connection *connection)
|
2012-08-28 03:33:35 -06:00
|
|
|
{
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2012-08-28 03:33:35 -06:00
|
|
|
int vnr;
|
|
|
|
bool rv = true;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
|
|
|
|
if (peer_device->device->state.conn == C_WF_REPORT_PARAMS) {
|
2012-08-28 03:33:35 -06:00
|
|
|
rv = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-11-10 09:21:11 -07:00
|
|
|
static void wake_up_all_devices(struct drbd_connection *connection)
|
|
|
|
{
|
|
|
|
struct drbd_peer_device *peer_device;
|
|
|
|
int vnr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
|
|
|
|
wake_up(&peer_device->device->state_wait);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-28 03:33:35 -06:00
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/**
|
|
|
|
* cl_wide_st_chg() - true if the state change is a cluster wide one
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @os: old (current) state.
|
|
|
|
* @ns: new (wanted) state.
|
|
|
|
*/
|
2011-07-03 05:26:43 -06:00
|
|
|
static int cl_wide_st_chg(struct drbd_device *device,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state os, union drbd_state ns)
|
|
|
|
{
|
|
|
|
return (os.conn >= C_CONNECTED && ns.conn >= C_CONNECTED &&
|
|
|
|
((os.role != R_PRIMARY && ns.role == R_PRIMARY) ||
|
|
|
|
(os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) ||
|
|
|
|
(os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S) ||
|
2012-03-26 07:57:00 -06:00
|
|
|
(os.disk != D_FAILED && ns.disk == D_FAILED))) ||
|
2011-01-27 06:07:51 -07:00
|
|
|
(os.conn >= C_CONNECTED && ns.conn == C_DISCONNECTING) ||
|
2011-07-06 15:04:44 -06:00
|
|
|
(os.conn == C_CONNECTED && ns.conn == C_VERIFY_S) ||
|
|
|
|
(os.conn == C_CONNECTED && ns.conn == C_WF_REPORT_PARAMS);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-02-16 06:57:50 -07:00
|
|
|
static union drbd_state
|
|
|
|
apply_mask_val(union drbd_state os, union drbd_state mask, union drbd_state val)
|
|
|
|
{
|
|
|
|
union drbd_state ns;
|
|
|
|
ns.i = (os.i & ~mask.i) | val.i;
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
enum drbd_state_rv
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_change_state(struct drbd_device *device, enum chg_state_flags f,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state mask, union drbd_state val)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2011-02-16 06:57:50 -07:00
|
|
|
union drbd_state ns;
|
2011-01-27 06:07:51 -07:00
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irqsave(&device->resource->req_lock, flags);
|
2011-07-03 05:26:43 -06:00
|
|
|
ns = apply_mask_val(drbd_read_state(device), mask, val);
|
|
|
|
rv = _drbd_set_state(device, ns, f, NULL);
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irqrestore(&device->resource->req_lock, flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_force_state() - Impose a change which happens outside our control on our state
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @mask: mask of state bits to change.
|
|
|
|
* @val: value of new state bits.
|
|
|
|
*/
|
2011-07-03 05:26:43 -06:00
|
|
|
void drbd_force_state(struct drbd_device *device,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state mask, union drbd_state val)
|
|
|
|
{
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_change_state(device, CS_HARD, mask, val);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum drbd_state_rv
|
2011-07-03 05:26:43 -06:00
|
|
|
_req_st_cond(struct drbd_device *device, union drbd_state mask,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state val)
|
|
|
|
{
|
|
|
|
union drbd_state os, ns;
|
|
|
|
unsigned long flags;
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_and_clear_bit(CL_ST_CHG_SUCCESS, &device->flags))
|
2011-01-27 06:07:51 -07:00
|
|
|
return SS_CW_SUCCESS;
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_and_clear_bit(CL_ST_CHG_FAIL, &device->flags))
|
2011-01-27 06:07:51 -07:00
|
|
|
return SS_CW_FAILED_BY_PEER;
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irqsave(&device->resource->req_lock, flags);
|
2011-07-03 05:26:43 -06:00
|
|
|
os = drbd_read_state(device);
|
2014-04-28 10:43:13 -06:00
|
|
|
ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL);
|
2011-02-09 08:29:33 -07:00
|
|
|
rv = is_valid_transition(os, ns);
|
2012-09-03 07:39:01 -06:00
|
|
|
if (rv >= SS_SUCCESS)
|
2011-02-09 08:29:33 -07:00
|
|
|
rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (!cl_wide_st_chg(device, os, ns))
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_CW_NO_NEED;
|
2011-02-09 08:29:33 -07:00
|
|
|
if (rv == SS_UNKNOWN_ERROR) {
|
2011-07-03 05:26:43 -06:00
|
|
|
rv = is_valid_state(device, ns);
|
2012-09-03 07:39:01 -06:00
|
|
|
if (rv >= SS_SUCCESS) {
|
2011-05-31 06:33:49 -06:00
|
|
|
rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection);
|
2012-09-03 07:39:01 -06:00
|
|
|
if (rv >= SS_SUCCESS)
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irqrestore(&device->resource->req_lock, flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drbd_req_state() - Perform an eventually cluster wide state change
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @mask: mask of state bits to change.
|
|
|
|
* @val: value of new state bits.
|
|
|
|
* @f: flags
|
|
|
|
*
|
|
|
|
* Should not be called directly, use drbd_request_state() or
|
|
|
|
* _drbd_request_state().
|
|
|
|
*/
|
|
|
|
static enum drbd_state_rv
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_req_state(struct drbd_device *device, union drbd_state mask,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state val, enum chg_state_flags f)
|
|
|
|
{
|
|
|
|
struct completion done;
|
|
|
|
unsigned long flags;
|
|
|
|
union drbd_state os, ns;
|
|
|
|
enum drbd_state_rv rv;
|
2017-08-29 02:20:43 -06:00
|
|
|
void *buffer = NULL;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
init_completion(&done);
|
|
|
|
|
|
|
|
if (f & CS_SERIALIZE)
|
2011-07-03 05:26:43 -06:00
|
|
|
mutex_lock(device->state_mutex);
|
2017-08-29 02:20:43 -06:00
|
|
|
if (f & CS_INHIBIT_MD_IO)
|
|
|
|
buffer = drbd_md_get_buffer(device, __func__);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irqsave(&device->resource->req_lock, flags);
|
2011-07-03 05:26:43 -06:00
|
|
|
os = drbd_read_state(device);
|
2014-04-28 10:43:13 -06:00
|
|
|
ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL);
|
2011-02-09 08:29:33 -07:00
|
|
|
rv = is_valid_transition(os, ns);
|
2011-03-15 09:04:09 -06:00
|
|
|
if (rv < SS_SUCCESS) {
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irqrestore(&device->resource->req_lock, flags);
|
2011-02-09 08:29:33 -07:00
|
|
|
goto abort;
|
2011-03-15 09:04:09 -06:00
|
|
|
}
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (cl_wide_st_chg(device, os, ns)) {
|
|
|
|
rv = is_valid_state(device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
if (rv == SS_SUCCESS)
|
2011-05-31 06:33:49 -06:00
|
|
|
rv = is_valid_soft_transition(os, ns, first_peer_device(device)->connection);
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irqrestore(&device->resource->req_lock, flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (rv < SS_SUCCESS) {
|
|
|
|
if (f & CS_VERBOSE)
|
2011-07-03 05:26:43 -06:00
|
|
|
print_st_err(device, os, ns, rv);
|
2011-01-27 06:07:51 -07:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
drbd: Pass a peer device to a number of fuctions
These functions actually operate on a peer device, or
need a peer device.
drbd_prepare_command(), drbd_send_command(), drbd_send_sync_param()
drbd_send_uuids(), drbd_gen_and_send_sync_uuid(), drbd_send_sizes()
drbd_send_state(), drbd_send_current_state(), and drbd_send_state_req()
drbd_send_sr_reply(), drbd_send_ack(), drbd_send_drequest(),
drbd_send_drequest_csum(), drbd_send_ov_request(), drbd_send_dblock()
drbd_send_block(), drbd_send_out_of_sync(), recv_dless_read()
drbd_drain_block(), receive_bitmap_plain(), recv_resync_read()
read_in_block(), read_for_csum(), drbd_alloc_pages(), drbd_alloc_peer_req()
need_peer_seq(), update_peer_seq(), wait_for_and_update_peer_seq()
drbd_sync_handshake(), drbd_asb_recover_{0,1,2}p(), drbd_connected()
drbd_disconnected(), decode_bitmap_c() and recv_bm_rle_bits()
Signed-off-by: Andreas Gruenbacher <agruen@linbit.com>
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
2011-08-08 16:47:13 -06:00
|
|
|
if (drbd_send_state_req(first_peer_device(device), mask, val)) {
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_CW_FAILED_BY_PEER;
|
|
|
|
if (f & CS_VERBOSE)
|
2011-07-03 05:26:43 -06:00
|
|
|
print_st_err(device, os, ns, rv);
|
2011-01-27 06:07:51 -07:00
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
wait_event(device->state_wait,
|
|
|
|
(rv = _req_st_cond(device, mask, val)));
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (rv < SS_SUCCESS) {
|
|
|
|
if (f & CS_VERBOSE)
|
2011-07-03 05:26:43 -06:00
|
|
|
print_st_err(device, os, ns, rv);
|
2011-01-27 06:07:51 -07:00
|
|
|
goto abort;
|
|
|
|
}
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irqsave(&device->resource->req_lock, flags);
|
2011-07-03 05:26:43 -06:00
|
|
|
ns = apply_mask_val(drbd_read_state(device), mask, val);
|
|
|
|
rv = _drbd_set_state(device, ns, f, &done);
|
2011-01-27 06:07:51 -07:00
|
|
|
} else {
|
2011-07-03 05:26:43 -06:00
|
|
|
rv = _drbd_set_state(device, ns, f, &done);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irqrestore(&device->resource->req_lock, flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (f & CS_WAIT_COMPLETE && rv == SS_SUCCESS) {
|
2011-06-27 08:23:33 -06:00
|
|
|
D_ASSERT(device, current != first_peer_device(device)->connection->worker.task);
|
2011-01-27 06:07:51 -07:00
|
|
|
wait_for_completion(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
abort:
|
2017-08-29 02:20:43 -06:00
|
|
|
if (buffer)
|
|
|
|
drbd_md_put_buffer(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
if (f & CS_SERIALIZE)
|
2011-07-03 05:26:43 -06:00
|
|
|
mutex_unlock(device->state_mutex);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _drbd_request_state() - Request a state change (with flags)
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @mask: mask of state bits to change.
|
|
|
|
* @val: value of new state bits.
|
|
|
|
* @f: flags
|
|
|
|
*
|
|
|
|
* Cousin of drbd_request_state(), useful with the CS_WAIT_COMPLETE
|
|
|
|
* flag, or when logging of failed state change requests is not desired.
|
|
|
|
*/
|
|
|
|
enum drbd_state_rv
|
2011-07-03 05:26:43 -06:00
|
|
|
_drbd_request_state(struct drbd_device *device, union drbd_state mask,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state val, enum chg_state_flags f)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
wait_event(device->state_wait,
|
|
|
|
(rv = drbd_req_state(device, mask, val, f)) != SS_IN_TRANSIENT_STATE);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:20:43 -06:00
|
|
|
/*
|
|
|
|
* We grab drbd_md_get_buffer(), because we don't want to "fail" the disk while
|
|
|
|
* there is IO in-flight: the transition into D_FAILED for detach purposes
|
|
|
|
* may get misinterpreted as actual IO error in a confused endio function.
|
|
|
|
*
|
|
|
|
* We wrap it all into wait_event(), to retry in case the drbd_req_state()
|
|
|
|
* returns SS_IN_TRANSIENT_STATE.
|
|
|
|
*
|
|
|
|
* To avoid potential deadlock with e.g. the receiver thread trying to grab
|
|
|
|
* drbd_md_get_buffer() while trying to get out of the "transient state", we
|
|
|
|
* need to grab and release the meta data buffer inside of that wait_event loop.
|
|
|
|
*/
|
|
|
|
static enum drbd_state_rv
|
|
|
|
request_detach(struct drbd_device *device)
|
|
|
|
{
|
|
|
|
return drbd_req_state(device, NS(disk, D_FAILED),
|
|
|
|
CS_VERBOSE | CS_ORDERED | CS_INHIBIT_MD_IO);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum drbd_state_rv
|
|
|
|
drbd_request_detach_interruptible(struct drbd_device *device)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drbd_suspend_io(device); /* so no-one is stuck in drbd_al_begin_io */
|
|
|
|
wait_event_interruptible(device->state_wait,
|
|
|
|
(rv = request_detach(device)) != SS_IN_TRANSIENT_STATE);
|
|
|
|
drbd_resume_io(device);
|
|
|
|
|
|
|
|
ret = wait_event_interruptible(device->misc_wait,
|
|
|
|
device->state.disk != D_FAILED);
|
|
|
|
|
|
|
|
if (rv == SS_IS_DISKLESS)
|
|
|
|
rv = SS_NOTHING_TO_DO;
|
|
|
|
if (ret)
|
|
|
|
rv = ERR_INTR;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-11-10 09:21:11 -07:00
|
|
|
enum drbd_state_rv
|
|
|
|
_drbd_request_state_holding_state_mutex(struct drbd_device *device, union drbd_state mask,
|
|
|
|
union drbd_state val, enum chg_state_flags f)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
|
|
|
BUG_ON(f & CS_SERIALIZE);
|
|
|
|
|
|
|
|
wait_event_cmd(device->state_wait,
|
|
|
|
(rv = drbd_req_state(device, mask, val, f)) != SS_IN_TRANSIENT_STATE,
|
|
|
|
mutex_unlock(device->state_mutex),
|
|
|
|
mutex_lock(device->state_mutex));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-27 01:46:18 -07:00
|
|
|
static void print_st(struct drbd_device *device, const char *name, union drbd_state ns)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device, " %s = { cs:%s ro:%s/%s ds:%s/%s %c%c%c%c%c%c }\n",
|
2011-01-27 06:07:51 -07:00
|
|
|
name,
|
|
|
|
drbd_conn_str(ns.conn),
|
|
|
|
drbd_role_str(ns.role),
|
|
|
|
drbd_role_str(ns.peer),
|
|
|
|
drbd_disk_str(ns.disk),
|
|
|
|
drbd_disk_str(ns.pdsk),
|
|
|
|
is_susp(ns) ? 's' : 'r',
|
|
|
|
ns.aftr_isp ? 'a' : '-',
|
|
|
|
ns.peer_isp ? 'p' : '-',
|
|
|
|
ns.user_isp ? 'u' : '-',
|
|
|
|
ns.susp_fen ? 'F' : '-',
|
|
|
|
ns.susp_nod ? 'N' : '-'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
void print_st_err(struct drbd_device *device, union drbd_state os,
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state ns, enum drbd_state_rv err)
|
|
|
|
{
|
|
|
|
if (err == SS_IN_TRANSIENT_STATE)
|
|
|
|
return;
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device, "State change failed: %s\n", drbd_set_st_err_str(err));
|
2011-07-03 05:26:43 -06:00
|
|
|
print_st(device, " state", os);
|
|
|
|
print_st(device, "wanted", ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-03-25 08:11:30 -06:00
|
|
|
static long print_state_change(char *pb, union drbd_state os, union drbd_state ns,
|
2011-02-10 05:45:46 -07:00
|
|
|
enum chg_state_flags flags)
|
|
|
|
{
|
2011-03-25 08:11:30 -06:00
|
|
|
char *pbp;
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp = pb;
|
|
|
|
*pbp = 0;
|
2011-03-29 07:20:27 -06:00
|
|
|
|
2011-03-25 08:11:30 -06:00
|
|
|
if (ns.role != os.role && flags & CS_DC_ROLE)
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp += sprintf(pbp, "role( %s -> %s ) ",
|
|
|
|
drbd_role_str(os.role),
|
|
|
|
drbd_role_str(ns.role));
|
2011-03-25 08:11:30 -06:00
|
|
|
if (ns.peer != os.peer && flags & CS_DC_PEER)
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp += sprintf(pbp, "peer( %s -> %s ) ",
|
|
|
|
drbd_role_str(os.peer),
|
|
|
|
drbd_role_str(ns.peer));
|
2011-03-25 08:11:30 -06:00
|
|
|
if (ns.conn != os.conn && flags & CS_DC_CONN)
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp += sprintf(pbp, "conn( %s -> %s ) ",
|
|
|
|
drbd_conn_str(os.conn),
|
|
|
|
drbd_conn_str(ns.conn));
|
2011-03-25 08:11:30 -06:00
|
|
|
if (ns.disk != os.disk && flags & CS_DC_DISK)
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp += sprintf(pbp, "disk( %s -> %s ) ",
|
|
|
|
drbd_disk_str(os.disk),
|
|
|
|
drbd_disk_str(ns.disk));
|
2011-03-25 08:11:30 -06:00
|
|
|
if (ns.pdsk != os.pdsk && flags & CS_DC_PDSK)
|
2011-02-10 05:45:46 -07:00
|
|
|
pbp += sprintf(pbp, "pdsk( %s -> %s ) ",
|
|
|
|
drbd_disk_str(os.pdsk),
|
|
|
|
drbd_disk_str(ns.pdsk));
|
2011-03-29 07:20:27 -06:00
|
|
|
|
|
|
|
return pbp - pb;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
static void drbd_pr_state_change(struct drbd_device *device, union drbd_state os, union drbd_state ns,
|
2011-03-29 07:20:27 -06:00
|
|
|
enum chg_state_flags flags)
|
|
|
|
{
|
|
|
|
char pb[300];
|
|
|
|
char *pbp = pb;
|
|
|
|
|
|
|
|
pbp += print_state_change(pbp, os, ns, flags ^ CS_DC_MASK);
|
|
|
|
|
2011-02-10 05:45:46 -07:00
|
|
|
if (ns.aftr_isp != os.aftr_isp)
|
|
|
|
pbp += sprintf(pbp, "aftr_isp( %d -> %d ) ",
|
|
|
|
os.aftr_isp,
|
|
|
|
ns.aftr_isp);
|
|
|
|
if (ns.peer_isp != os.peer_isp)
|
|
|
|
pbp += sprintf(pbp, "peer_isp( %d -> %d ) ",
|
|
|
|
os.peer_isp,
|
|
|
|
ns.peer_isp);
|
|
|
|
if (ns.user_isp != os.user_isp)
|
|
|
|
pbp += sprintf(pbp, "user_isp( %d -> %d ) ",
|
|
|
|
os.user_isp,
|
|
|
|
ns.user_isp);
|
2011-03-25 08:11:30 -06:00
|
|
|
|
2011-03-29 07:20:27 -06:00
|
|
|
if (pbp != pb)
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "%s\n", pb);
|
2011-02-10 05:45:46 -07:00
|
|
|
}
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
static void conn_pr_state_change(struct drbd_connection *connection, union drbd_state os, union drbd_state ns,
|
2011-03-25 08:11:30 -06:00
|
|
|
enum chg_state_flags flags)
|
|
|
|
{
|
|
|
|
char pb[300];
|
2011-03-29 07:20:27 -06:00
|
|
|
char *pbp = pb;
|
|
|
|
|
|
|
|
pbp += print_state_change(pbp, os, ns, flags);
|
2011-03-25 08:11:30 -06:00
|
|
|
|
2011-03-29 07:20:27 -06:00
|
|
|
if (is_susp(ns) != is_susp(os) && flags & CS_DC_SUSP)
|
|
|
|
pbp += sprintf(pbp, "susp( %d -> %d ) ",
|
|
|
|
is_susp(os),
|
|
|
|
is_susp(ns));
|
|
|
|
|
|
|
|
if (pbp != pb)
|
2011-07-06 03:01:44 -06:00
|
|
|
drbd_info(connection, "%s\n", pb);
|
2011-03-25 08:11:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/**
|
|
|
|
* is_valid_state() - Returns an SS_ error code if ns is not valid
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @ns: State to consider.
|
|
|
|
*/
|
|
|
|
static enum drbd_state_rv
|
2011-07-03 05:26:43 -06:00
|
|
|
is_valid_state(struct drbd_device *device, union drbd_state ns)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
|
|
|
/* See drbd_state_sw_errors in drbd_strings.c */
|
|
|
|
|
|
|
|
enum drbd_fencing_p fp;
|
|
|
|
enum drbd_state_rv rv = SS_SUCCESS;
|
2011-04-19 09:10:19 -06:00
|
|
|
struct net_conf *nc;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-05-03 07:00:55 -06:00
|
|
|
rcu_read_lock();
|
2011-01-27 06:07:51 -07:00
|
|
|
fp = FP_DONT_CARE;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (get_ldev(device)) {
|
|
|
|
fp = rcu_dereference(device->ldev->disk_conf)->fencing;
|
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-05-31 06:33:49 -06:00
|
|
|
nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
|
2011-04-19 09:10:19 -06:00
|
|
|
if (nc) {
|
|
|
|
if (!nc->two_primaries && ns.role == R_PRIMARY) {
|
2011-03-16 07:43:36 -06:00
|
|
|
if (ns.peer == R_PRIMARY)
|
|
|
|
rv = SS_TWO_PRIMARIES;
|
2011-05-31 06:33:49 -06:00
|
|
|
else if (conn_highest_peer(first_peer_device(device)->connection) == R_PRIMARY)
|
2011-03-16 07:43:36 -06:00
|
|
|
rv = SS_O_VOL_PEER_PRI;
|
2011-04-19 09:10:19 -06:00
|
|
|
}
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv <= 0)
|
2016-06-13 16:26:36 -06:00
|
|
|
goto out; /* already found a reason to abort */
|
2011-07-03 05:26:43 -06:00
|
|
|
else if (ns.role == R_SECONDARY && device->open_cnt)
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_DEVICE_IN_USE;
|
|
|
|
|
|
|
|
else if (ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.disk < D_UP_TO_DATE)
|
|
|
|
rv = SS_NO_UP_TO_DATE_DISK;
|
|
|
|
|
|
|
|
else if (fp >= FP_RESOURCE &&
|
|
|
|
ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk >= D_UNKNOWN)
|
|
|
|
rv = SS_PRIMARY_NOP;
|
|
|
|
|
|
|
|
else if (ns.role == R_PRIMARY && ns.disk <= D_INCONSISTENT && ns.pdsk <= D_INCONSISTENT)
|
|
|
|
rv = SS_NO_UP_TO_DATE_DISK;
|
|
|
|
|
|
|
|
else if (ns.conn > C_CONNECTED && ns.disk < D_INCONSISTENT)
|
|
|
|
rv = SS_NO_LOCAL_DISK;
|
|
|
|
|
|
|
|
else if (ns.conn > C_CONNECTED && ns.pdsk < D_INCONSISTENT)
|
|
|
|
rv = SS_NO_REMOTE_DISK;
|
|
|
|
|
|
|
|
else if (ns.conn > C_CONNECTED && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)
|
|
|
|
rv = SS_NO_UP_TO_DATE_DISK;
|
|
|
|
|
|
|
|
else if ((ns.conn == C_CONNECTED ||
|
|
|
|
ns.conn == C_WF_BITMAP_S ||
|
|
|
|
ns.conn == C_SYNC_SOURCE ||
|
|
|
|
ns.conn == C_PAUSED_SYNC_S) &&
|
|
|
|
ns.disk == D_OUTDATED)
|
|
|
|
rv = SS_CONNECTED_OUTDATES;
|
|
|
|
|
|
|
|
else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
|
2011-04-19 09:10:19 -06:00
|
|
|
(nc->verify_alg[0] == 0))
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_NO_VERIFY_ALG;
|
|
|
|
|
|
|
|
else if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
|
2011-05-31 06:33:49 -06:00
|
|
|
first_peer_device(device)->connection->agreed_pro_version < 88)
|
2011-01-27 06:07:51 -07:00
|
|
|
rv = SS_NOT_SUPPORTED;
|
|
|
|
|
2013-03-27 07:08:37 -06:00
|
|
|
else if (ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE)
|
|
|
|
rv = SS_NO_UP_TO_DATE_DISK;
|
|
|
|
|
|
|
|
else if ((ns.conn == C_STARTING_SYNC_S || ns.conn == C_STARTING_SYNC_T) &&
|
|
|
|
ns.pdsk == D_UNKNOWN)
|
|
|
|
rv = SS_NEED_CONNECTION;
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
else if (ns.conn >= C_CONNECTED && ns.pdsk == D_UNKNOWN)
|
|
|
|
rv = SS_CONNECTED_OUTDATES;
|
|
|
|
|
2016-06-13 16:26:36 -06:00
|
|
|
out:
|
2011-04-19 09:10:19 -06:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-09 07:10:33 -07:00
|
|
|
* is_valid_soft_transition() - Returns an SS_ error code if the state transition is not possible
|
2011-02-09 08:29:33 -07:00
|
|
|
* This function limits state transitions that may be declined by DRBD. I.e.
|
|
|
|
* user requests (aka soft transitions).
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @ns: new state.
|
|
|
|
* @os: old state.
|
|
|
|
*/
|
|
|
|
static enum drbd_state_rv
|
2011-05-30 08:32:41 -06:00
|
|
|
is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_connection *connection)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
|
|
|
enum drbd_state_rv rv = SS_SUCCESS;
|
|
|
|
|
|
|
|
if ((ns.conn == C_STARTING_SYNC_T || ns.conn == C_STARTING_SYNC_S) &&
|
|
|
|
os.conn > C_CONNECTED)
|
|
|
|
rv = SS_RESYNC_RUNNING;
|
|
|
|
|
|
|
|
if (ns.conn == C_DISCONNECTING && os.conn == C_STANDALONE)
|
|
|
|
rv = SS_ALREADY_STANDALONE;
|
|
|
|
|
|
|
|
if (ns.disk > D_ATTACHING && os.disk == D_DISKLESS)
|
|
|
|
rv = SS_IS_DISKLESS;
|
|
|
|
|
|
|
|
if (ns.conn == C_WF_CONNECTION && os.conn < C_UNCONNECTED)
|
|
|
|
rv = SS_NO_NET_CONFIG;
|
|
|
|
|
|
|
|
if (ns.disk == D_OUTDATED && os.disk < D_OUTDATED && os.disk != D_ATTACHING)
|
|
|
|
rv = SS_LOWER_THAN_OUTDATED;
|
|
|
|
|
|
|
|
if (ns.conn == C_DISCONNECTING && os.conn == C_UNCONNECTED)
|
|
|
|
rv = SS_IN_TRANSIENT_STATE;
|
|
|
|
|
2012-04-06 04:07:34 -06:00
|
|
|
/* While establishing a connection only allow cstate to change.
|
2014-11-10 09:21:11 -07:00
|
|
|
Delay/refuse role changes, detach attach etc... (they do not touch cstate) */
|
2011-05-30 08:32:41 -06:00
|
|
|
if (test_bit(STATE_SENT, &connection->flags) &&
|
2014-11-10 09:21:11 -07:00
|
|
|
!((ns.conn == C_WF_REPORT_PARAMS && os.conn == C_WF_CONNECTION) ||
|
|
|
|
(ns.conn >= C_CONNECTED && os.conn == C_WF_REPORT_PARAMS)))
|
2012-04-06 04:07:34 -06:00
|
|
|
rv = SS_IN_TRANSIENT_STATE;
|
|
|
|
|
drbd: disallow promotion during resync handshake, avoid deadlock and hard reset
We already serialize connection state changes,
and other, non-connection state changes (role changes)
while we are establishing a connection.
But if we have an established connection,
then trigger a resync handshake (by primary --force or similar),
until now we just had to be "lucky".
Consider this sequence (e.g. deployment scenario):
create-md; up;
-> Connected Secondary/Secondary Inconsistent/Inconsistent
then do a racy primary --force on both peers.
block drbd0: drbd_sync_handshake:
block drbd0: self 0000000000000004:0000000000000000:0000000000000000:0000000000000000 bits:25590 flags:0
block drbd0: peer 0000000000000004:0000000000000000:0000000000000000:0000000000000000 bits:25590 flags:0
block drbd0: peer( Unknown -> Secondary ) conn( WFReportParams -> Connected ) pdsk( DUnknown -> Inconsistent )
block drbd0: peer( Secondary -> Primary ) pdsk( Inconsistent -> UpToDate )
*** HERE things go wrong. ***
block drbd0: role( Secondary -> Primary )
block drbd0: drbd_sync_handshake:
block drbd0: self 0000000000000005:0000000000000000:0000000000000000:0000000000000000 bits:25590 flags:0
block drbd0: peer C90D2FC716D232AB:0000000000000004:0000000000000000:0000000000000000 bits:25590 flags:0
block drbd0: Becoming sync target due to disk states.
block drbd0: Writing the whole bitmap, full sync required after drbd_sync_handshake.
block drbd0: Remote failed to finish a request within 6007ms > ko-count (2) * timeout (30 * 0.1s)
drbd s0: peer( Primary -> Unknown ) conn( Connected -> Timeout ) pdsk( UpToDate -> DUnknown )
The problem here is that the local promotion happens before the sync handshake
triggered by the remote promotion was completed. Some assumptions elsewhere
become wrong, and when the expected resync handshake is then received and
processed, we get stuck in a deadlock, which can only be recovered by reboot :-(
Fix: if we know the peer has good data,
and our own disk is present, but NOT good,
and there is no resync going on yet,
we expect a sync handshake to happen "soon".
So reject a racy promotion with SS_IN_TRANSIENT_STATE.
Result:
... as above ...
block drbd0: peer( Secondary -> Primary ) pdsk( Inconsistent -> UpToDate )
*** local promotion being postponed until ... ***
block drbd0: drbd_sync_handshake:
block drbd0: self 0000000000000004:0000000000000000:0000000000000000:0000000000000000 bits:25590 flags:0
block drbd0: peer 77868BDA836E12A5:0000000000000004:0000000000000000:0000000000000000 bits:25590 flags:0
...
block drbd0: conn( WFBitMapT -> WFSyncUUID )
block drbd0: updated sync uuid 85D06D0E8887AD44:0000000000000000:0000000000000000:0000000000000000
block drbd0: conn( WFSyncUUID -> SyncTarget )
*** ... after the resync handshake ***
block drbd0: role( Secondary -> Primary )
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-06-13 16:26:33 -06:00
|
|
|
/* Do not promote during resync handshake triggered by "force primary".
|
|
|
|
* This is a hack. It should really be rejected by the peer during the
|
|
|
|
* cluster wide state change request. */
|
|
|
|
if (os.role != R_PRIMARY && ns.role == R_PRIMARY
|
|
|
|
&& ns.pdsk == D_UP_TO_DATE
|
|
|
|
&& ns.disk != D_UP_TO_DATE && ns.disk != D_DISKLESS
|
|
|
|
&& (ns.conn <= C_WF_SYNC_UUID || ns.conn != os.conn))
|
|
|
|
rv = SS_IN_TRANSIENT_STATE;
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) && os.conn < C_CONNECTED)
|
|
|
|
rv = SS_NEED_CONNECTION;
|
|
|
|
|
|
|
|
if ((ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T) &&
|
|
|
|
ns.conn != os.conn && os.conn > C_CONNECTED)
|
|
|
|
rv = SS_RESYNC_RUNNING;
|
|
|
|
|
|
|
|
if ((ns.conn == C_STARTING_SYNC_S || ns.conn == C_STARTING_SYNC_T) &&
|
|
|
|
os.conn < C_CONNECTED)
|
|
|
|
rv = SS_NEED_CONNECTION;
|
|
|
|
|
|
|
|
if ((ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE)
|
|
|
|
&& os.conn < C_WF_REPORT_PARAMS)
|
|
|
|
rv = SS_NEED_CONNECTION; /* No NetworkFailure -> SyncTarget etc... */
|
|
|
|
|
2013-03-27 07:08:40 -06:00
|
|
|
if (ns.conn == C_DISCONNECTING && ns.pdsk == D_OUTDATED &&
|
|
|
|
os.conn < C_CONNECTED && os.pdsk > D_OUTDATED)
|
|
|
|
rv = SS_OUTDATE_WO_CONN;
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-02-09 08:29:33 -07:00
|
|
|
static enum drbd_state_rv
|
2011-02-10 02:38:06 -07:00
|
|
|
is_valid_conn_transition(enum drbd_conns oc, enum drbd_conns nc)
|
2011-02-09 08:29:33 -07:00
|
|
|
{
|
2011-04-27 02:25:28 -06:00
|
|
|
/* no change -> nothing to do, at least for the connection part */
|
|
|
|
if (oc == nc)
|
|
|
|
return SS_NOTHING_TO_DO;
|
2011-02-09 08:29:33 -07:00
|
|
|
|
2011-04-27 02:25:28 -06:00
|
|
|
/* disconnect of an unconfigured connection does not make sense */
|
|
|
|
if (oc == C_STANDALONE && nc == C_DISCONNECTING)
|
|
|
|
return SS_ALREADY_STANDALONE;
|
|
|
|
|
|
|
|
/* from C_STANDALONE, we start with C_UNCONNECTED */
|
|
|
|
if (oc == C_STANDALONE && nc != C_UNCONNECTED)
|
|
|
|
return SS_NEED_CONNECTION;
|
2011-02-09 08:29:33 -07:00
|
|
|
|
2012-02-14 04:12:35 -07:00
|
|
|
/* When establishing a connection we need to go through WF_REPORT_PARAMS!
|
|
|
|
Necessary to do the right thing upon invalidate-remote on a disconnected resource */
|
|
|
|
if (oc < C_WF_REPORT_PARAMS && nc >= C_CONNECTED)
|
|
|
|
return SS_NEED_CONNECTION;
|
|
|
|
|
2011-02-09 08:29:33 -07:00
|
|
|
/* After a network error only C_UNCONNECTED or C_DISCONNECTING may follow. */
|
2011-02-10 02:38:06 -07:00
|
|
|
if (oc >= C_TIMEOUT && oc <= C_TEAR_DOWN && nc != C_UNCONNECTED && nc != C_DISCONNECTING)
|
2011-04-27 02:25:28 -06:00
|
|
|
return SS_IN_TRANSIENT_STATE;
|
2011-02-09 08:29:33 -07:00
|
|
|
|
|
|
|
/* After C_DISCONNECTING only C_STANDALONE may follow */
|
2011-02-10 02:38:06 -07:00
|
|
|
if (oc == C_DISCONNECTING && nc != C_STANDALONE)
|
2011-04-27 02:25:28 -06:00
|
|
|
return SS_IN_TRANSIENT_STATE;
|
2011-02-09 08:29:33 -07:00
|
|
|
|
2011-04-27 02:25:28 -06:00
|
|
|
return SS_SUCCESS;
|
2011-02-10 02:38:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* is_valid_transition() - Returns an SS_ error code if the state transition is not possible
|
|
|
|
* This limits hard state transitions. Hard state transitions are facts there are
|
|
|
|
* imposed on DRBD by the environment. E.g. disk broke or network broke down.
|
|
|
|
* But those hard state transitions are still not allowed to do everything.
|
|
|
|
* @ns: new state.
|
|
|
|
* @os: old state.
|
|
|
|
*/
|
|
|
|
static enum drbd_state_rv
|
|
|
|
is_valid_transition(union drbd_state os, union drbd_state ns)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
|
|
|
rv = is_valid_conn_transition(os.conn, ns.conn);
|
|
|
|
|
2011-02-09 08:29:33 -07:00
|
|
|
/* we cannot fail (again) if we already detached */
|
|
|
|
if (ns.disk == D_FAILED && os.disk == D_DISKLESS)
|
|
|
|
rv = SS_IS_DISKLESS;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
static void print_sanitize_warnings(struct drbd_device *device, enum sanitize_state_warnings warn)
|
2011-05-31 05:07:24 -06:00
|
|
|
{
|
|
|
|
static const char *msg_table[] = {
|
|
|
|
[NO_WARNING] = "",
|
|
|
|
[ABORTED_ONLINE_VERIFY] = "Online-verify aborted.",
|
|
|
|
[ABORTED_RESYNC] = "Resync aborted.",
|
|
|
|
[CONNECTION_LOST_NEGOTIATING] = "Connection lost while negotiating, no data!",
|
|
|
|
[IMPLICITLY_UPGRADED_DISK] = "Implicitly upgraded disk",
|
|
|
|
[IMPLICITLY_UPGRADED_PDSK] = "Implicitly upgraded pdsk",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (warn != NO_WARNING)
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_warn(device, "%s\n", msg_table[warn]);
|
2011-05-31 05:07:24 -06:00
|
|
|
}
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/**
|
|
|
|
* sanitize_state() - Resolves implicitly necessary additional changes to a state transition
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @os: old state.
|
|
|
|
* @ns: new state.
|
|
|
|
* @warn_sync_abort:
|
|
|
|
*
|
|
|
|
* When we loose connection, we have to set the state of the peers disk (pdsk)
|
|
|
|
* to D_UNKNOWN. This rule and many more along those lines are in this function.
|
|
|
|
*/
|
2014-04-28 10:43:13 -06:00
|
|
|
static union drbd_state sanitize_state(struct drbd_device *device, union drbd_state os,
|
|
|
|
union drbd_state ns, enum sanitize_state_warnings *warn)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
|
|
|
enum drbd_fencing_p fp;
|
|
|
|
enum drbd_disk_state disk_min, disk_max, pdsk_min, pdsk_max;
|
|
|
|
|
2011-05-31 05:07:24 -06:00
|
|
|
if (warn)
|
|
|
|
*warn = NO_WARNING;
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
fp = FP_DONT_CARE;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (get_ldev(device)) {
|
2011-05-03 07:00:55 -06:00
|
|
|
rcu_read_lock();
|
2011-07-03 05:26:43 -06:00
|
|
|
fp = rcu_dereference(device->ldev->disk_conf)->fencing;
|
2011-05-03 07:00:55 -06:00
|
|
|
rcu_read_unlock();
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-02-09 08:29:33 -07:00
|
|
|
/* Implications from connection to peer and peer_isp */
|
2011-01-27 06:07:51 -07:00
|
|
|
if (ns.conn < C_CONNECTED) {
|
|
|
|
ns.peer_isp = 0;
|
|
|
|
ns.peer = R_UNKNOWN;
|
|
|
|
if (ns.pdsk > D_UNKNOWN || ns.pdsk < D_INCONSISTENT)
|
|
|
|
ns.pdsk = D_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the aftr_isp when becoming unconfigured */
|
|
|
|
if (ns.conn == C_STANDALONE && ns.disk == D_DISKLESS && ns.role == R_SECONDARY)
|
|
|
|
ns.aftr_isp = 0;
|
|
|
|
|
2011-02-10 03:24:38 -07:00
|
|
|
/* An implication of the disk states onto the connection state */
|
2011-01-27 06:07:51 -07:00
|
|
|
/* Abort resync if a disk fails/detaches */
|
2011-02-10 03:24:38 -07:00
|
|
|
if (ns.conn > C_CONNECTED && (ns.disk <= D_FAILED || ns.pdsk <= D_FAILED)) {
|
2011-05-31 05:07:24 -06:00
|
|
|
if (warn)
|
|
|
|
*warn = ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T ?
|
|
|
|
ABORTED_ONLINE_VERIFY : ABORTED_RESYNC;
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.conn = C_CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connection breaks down before we finished "Negotiating" */
|
|
|
|
if (ns.conn < C_CONNECTED && ns.disk == D_NEGOTIATING &&
|
2011-07-03 05:26:43 -06:00
|
|
|
get_ldev_if_state(device, D_NEGOTIATING)) {
|
|
|
|
if (device->ed_uuid == device->ldev->md.uuid[UI_CURRENT]) {
|
|
|
|
ns.disk = device->new_state_tmp.disk;
|
|
|
|
ns.pdsk = device->new_state_tmp.pdsk;
|
2011-01-27 06:07:51 -07:00
|
|
|
} else {
|
2011-05-31 05:07:24 -06:00
|
|
|
if (warn)
|
|
|
|
*warn = CONNECTION_LOST_NEGOTIATING;
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.disk = D_DISKLESS;
|
|
|
|
ns.pdsk = D_UNKNOWN;
|
|
|
|
}
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* D_CONSISTENT and D_OUTDATED vanish when we get connected */
|
|
|
|
if (ns.conn >= C_CONNECTED && ns.conn < C_AHEAD) {
|
|
|
|
if (ns.disk == D_CONSISTENT || ns.disk == D_OUTDATED)
|
|
|
|
ns.disk = D_UP_TO_DATE;
|
|
|
|
if (ns.pdsk == D_CONSISTENT || ns.pdsk == D_OUTDATED)
|
|
|
|
ns.pdsk = D_UP_TO_DATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implications of the connection stat on the disk states */
|
|
|
|
disk_min = D_DISKLESS;
|
|
|
|
disk_max = D_UP_TO_DATE;
|
|
|
|
pdsk_min = D_INCONSISTENT;
|
|
|
|
pdsk_max = D_UNKNOWN;
|
|
|
|
switch ((enum drbd_conns)ns.conn) {
|
|
|
|
case C_WF_BITMAP_T:
|
|
|
|
case C_PAUSED_SYNC_T:
|
|
|
|
case C_STARTING_SYNC_T:
|
|
|
|
case C_WF_SYNC_UUID:
|
|
|
|
case C_BEHIND:
|
|
|
|
disk_min = D_INCONSISTENT;
|
|
|
|
disk_max = D_OUTDATED;
|
|
|
|
pdsk_min = D_UP_TO_DATE;
|
|
|
|
pdsk_max = D_UP_TO_DATE;
|
|
|
|
break;
|
|
|
|
case C_VERIFY_S:
|
|
|
|
case C_VERIFY_T:
|
|
|
|
disk_min = D_UP_TO_DATE;
|
|
|
|
disk_max = D_UP_TO_DATE;
|
|
|
|
pdsk_min = D_UP_TO_DATE;
|
|
|
|
pdsk_max = D_UP_TO_DATE;
|
|
|
|
break;
|
|
|
|
case C_CONNECTED:
|
|
|
|
disk_min = D_DISKLESS;
|
|
|
|
disk_max = D_UP_TO_DATE;
|
|
|
|
pdsk_min = D_DISKLESS;
|
|
|
|
pdsk_max = D_UP_TO_DATE;
|
|
|
|
break;
|
|
|
|
case C_WF_BITMAP_S:
|
|
|
|
case C_PAUSED_SYNC_S:
|
|
|
|
case C_STARTING_SYNC_S:
|
|
|
|
case C_AHEAD:
|
|
|
|
disk_min = D_UP_TO_DATE;
|
|
|
|
disk_max = D_UP_TO_DATE;
|
|
|
|
pdsk_min = D_INCONSISTENT;
|
|
|
|
pdsk_max = D_CONSISTENT; /* D_OUTDATED would be nice. But explicit outdate necessary*/
|
|
|
|
break;
|
|
|
|
case C_SYNC_TARGET:
|
|
|
|
disk_min = D_INCONSISTENT;
|
|
|
|
disk_max = D_INCONSISTENT;
|
|
|
|
pdsk_min = D_UP_TO_DATE;
|
|
|
|
pdsk_max = D_UP_TO_DATE;
|
|
|
|
break;
|
|
|
|
case C_SYNC_SOURCE:
|
|
|
|
disk_min = D_UP_TO_DATE;
|
|
|
|
disk_max = D_UP_TO_DATE;
|
|
|
|
pdsk_min = D_INCONSISTENT;
|
|
|
|
pdsk_max = D_INCONSISTENT;
|
|
|
|
break;
|
|
|
|
case C_STANDALONE:
|
|
|
|
case C_DISCONNECTING:
|
|
|
|
case C_UNCONNECTED:
|
|
|
|
case C_TIMEOUT:
|
|
|
|
case C_BROKEN_PIPE:
|
|
|
|
case C_NETWORK_FAILURE:
|
|
|
|
case C_PROTOCOL_ERROR:
|
|
|
|
case C_TEAR_DOWN:
|
|
|
|
case C_WF_CONNECTION:
|
|
|
|
case C_WF_REPORT_PARAMS:
|
|
|
|
case C_MASK:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ns.disk > disk_max)
|
|
|
|
ns.disk = disk_max;
|
|
|
|
|
|
|
|
if (ns.disk < disk_min) {
|
2011-05-31 05:07:24 -06:00
|
|
|
if (warn)
|
|
|
|
*warn = IMPLICITLY_UPGRADED_DISK;
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.disk = disk_min;
|
|
|
|
}
|
|
|
|
if (ns.pdsk > pdsk_max)
|
|
|
|
ns.pdsk = pdsk_max;
|
|
|
|
|
|
|
|
if (ns.pdsk < pdsk_min) {
|
2011-05-31 05:07:24 -06:00
|
|
|
if (warn)
|
|
|
|
*warn = IMPLICITLY_UPGRADED_PDSK;
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.pdsk = pdsk_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp == FP_STONITH &&
|
2014-04-28 10:43:13 -06:00
|
|
|
(ns.role == R_PRIMARY && ns.conn < C_CONNECTED && ns.pdsk > D_OUTDATED) &&
|
|
|
|
!(os.role == R_PRIMARY && os.conn < C_CONNECTED && os.pdsk > D_OUTDATED))
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.susp_fen = 1; /* Suspend IO while fence-peer handler runs (peer lost) */
|
|
|
|
|
2011-06-21 08:11:28 -06:00
|
|
|
if (device->resource->res_opts.on_no_data == OND_SUSPEND_IO &&
|
2014-04-28 10:43:13 -06:00
|
|
|
(ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE) &&
|
|
|
|
!(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE))
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.susp_nod = 1; /* Suspend IO while no data available (no accessible data available) */
|
|
|
|
|
|
|
|
if (ns.aftr_isp || ns.peer_isp || ns.user_isp) {
|
|
|
|
if (ns.conn == C_SYNC_SOURCE)
|
|
|
|
ns.conn = C_PAUSED_SYNC_S;
|
|
|
|
if (ns.conn == C_SYNC_TARGET)
|
|
|
|
ns.conn = C_PAUSED_SYNC_T;
|
|
|
|
} else {
|
|
|
|
if (ns.conn == C_PAUSED_SYNC_S)
|
|
|
|
ns.conn = C_SYNC_SOURCE;
|
|
|
|
if (ns.conn == C_PAUSED_SYNC_T)
|
|
|
|
ns.conn = C_SYNC_TARGET;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
void drbd_resume_al(struct drbd_device *device)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_and_clear_bit(AL_SUSPENDED, &device->flags))
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "Resumed AL updates\n");
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2014-08-14 10:33:30 -06:00
|
|
|
/* helper for _drbd_set_state */
|
2011-07-03 05:26:43 -06:00
|
|
|
static void set_ov_position(struct drbd_device *device, enum drbd_conns cs)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
2011-05-31 06:33:49 -06:00
|
|
|
if (first_peer_device(device)->connection->agreed_pro_version < 90)
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ov_start_sector = 0;
|
|
|
|
device->rs_total = drbd_bm_bits(device);
|
|
|
|
device->ov_position = 0;
|
2011-01-27 06:07:51 -07:00
|
|
|
if (cs == C_VERIFY_T) {
|
|
|
|
/* starting online verify from an arbitrary position
|
|
|
|
* does not fit well into the existing protocol.
|
|
|
|
* on C_VERIFY_T, we initialize ov_left and friends
|
|
|
|
* implicitly in receive_DataRequest once the
|
|
|
|
* first P_OV_REQUEST is received */
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ov_start_sector = ~(sector_t)0;
|
2011-01-27 06:07:51 -07:00
|
|
|
} else {
|
2011-07-03 05:26:43 -06:00
|
|
|
unsigned long bit = BM_SECT_TO_BIT(device->ov_start_sector);
|
|
|
|
if (bit >= device->rs_total) {
|
|
|
|
device->ov_start_sector =
|
|
|
|
BM_BIT_TO_SECT(device->rs_total - 1);
|
|
|
|
device->rs_total = 1;
|
2011-01-27 06:07:51 -07:00
|
|
|
} else
|
2011-07-03 05:26:43 -06:00
|
|
|
device->rs_total -= bit;
|
|
|
|
device->ov_position = device->ov_start_sector;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ov_left = device->rs_total;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-14 10:33:30 -06:00
|
|
|
* _drbd_set_state() - Set a new DRBD state
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @ns: new state.
|
|
|
|
* @flags: Flags
|
|
|
|
* @done: Optional completion, that will get completed after the after_state_ch() finished
|
|
|
|
*
|
2014-08-14 10:33:30 -06:00
|
|
|
* Caller needs to hold req_lock. Do not call directly.
|
2011-01-27 06:07:51 -07:00
|
|
|
*/
|
|
|
|
enum drbd_state_rv
|
2014-08-14 10:33:30 -06:00
|
|
|
_drbd_set_state(struct drbd_device *device, union drbd_state ns,
|
|
|
|
enum chg_state_flags flags, struct completion *done)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
2013-11-22 04:40:58 -07:00
|
|
|
struct drbd_peer_device *peer_device = first_peer_device(device);
|
|
|
|
struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
|
2011-01-27 06:07:51 -07:00
|
|
|
union drbd_state os;
|
|
|
|
enum drbd_state_rv rv = SS_SUCCESS;
|
2011-05-31 05:07:24 -06:00
|
|
|
enum sanitize_state_warnings ssw;
|
2011-01-27 06:07:51 -07:00
|
|
|
struct after_state_chg_work *ascw;
|
2014-07-31 09:41:33 -06:00
|
|
|
struct drbd_state_change *state_change;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
os = drbd_read_state(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2014-04-28 10:43:13 -06:00
|
|
|
ns = sanitize_state(device, os, ns, &ssw);
|
2011-01-27 06:07:51 -07:00
|
|
|
if (ns.i == os.i)
|
|
|
|
return SS_NOTHING_TO_DO;
|
|
|
|
|
2011-02-09 08:29:33 -07:00
|
|
|
rv = is_valid_transition(os, ns);
|
|
|
|
if (rv < SS_SUCCESS)
|
|
|
|
return rv;
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
if (!(flags & CS_HARD)) {
|
|
|
|
/* pre-state-change checks ; only look at ns */
|
|
|
|
/* See drbd_state_sw_errors in drbd_strings.c */
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
rv = is_valid_state(device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
if (rv < SS_SUCCESS) {
|
|
|
|
/* If the old state was illegal as well, then let
|
|
|
|
this happen...*/
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (is_valid_state(device, os) == rv)
|
2013-11-22 04:40:58 -07:00
|
|
|
rv = is_valid_soft_transition(os, ns, connection);
|
2011-01-27 06:07:51 -07:00
|
|
|
} else
|
2013-11-22 04:40:58 -07:00
|
|
|
rv = is_valid_soft_transition(os, ns, connection);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv < SS_SUCCESS) {
|
|
|
|
if (flags & CS_VERBOSE)
|
2011-07-03 05:26:43 -06:00
|
|
|
print_st_err(device, os, ns, rv);
|
2011-01-27 06:07:51 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
print_sanitize_warnings(device, ssw);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_pr_state_change(device, os, ns, flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-03-29 07:20:27 -06:00
|
|
|
/* Display changes to the susp* flags that where caused by the call to
|
|
|
|
sanitize_state(). Only display it here if we where not called from
|
|
|
|
_conn_request_state() */
|
|
|
|
if (!(flags & CS_DC_SUSP))
|
2013-11-22 04:40:58 -07:00
|
|
|
conn_pr_state_change(connection, os, ns,
|
2011-05-31 06:33:49 -06:00
|
|
|
(flags & ~CS_DC_MASK) | CS_DC_SUSP);
|
2011-03-29 07:20:27 -06:00
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/* if we are going -> D_FAILED or D_DISKLESS, grab one extra reference
|
|
|
|
* on the ldev here, to be sure the transition -> D_DISKLESS resp.
|
|
|
|
* drbd_ldev_destroy() won't happen before our corresponding
|
|
|
|
* after_state_ch works run, where we put_ldev again. */
|
|
|
|
if ((os.disk != D_FAILED && ns.disk == D_FAILED) ||
|
|
|
|
(os.disk != D_DISKLESS && ns.disk == D_DISKLESS))
|
2011-07-03 05:26:43 -06:00
|
|
|
atomic_inc(&device->local_cnt);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
drbd: fix resync finished detection
This fixes one recent regresion,
and one long existing bug.
The bug:
drbd_try_clear_on_disk_bm() assumed that all "count" bits have to be
accounted in the resync extent corresponding to the start sector.
Since we allow application requests to cross our "extent" boundaries,
this assumption is no longer true, resulting in possible misaccounting,
scary messages
("BAD! sector=12345s enr=6 rs_left=-7 rs_failed=0 count=58 cstate=..."),
and potentially, if the last bit to be cleared during resync would
reside in previously misaccounted resync extent, the resync would never
be recognized as finished, but would be "stalled" forever, even though
all blocks are in sync again and all bits have been cleared...
The regression was introduced by
drbd: get rid of atomic update on disk bitmap works
For an "empty" resync (rs_total == 0), we must not "finish" the
resync on the SyncSource before the SyncTarget knows all relevant
information (sync uuid). We need to wait for the full round-trip,
the SyncTarget will then explicitly notify us.
Also for normal, non-empty resyncs (rs_total > 0), the resync-finished
condition needs to be tested before the schedule() in wait_for_work, or
it is likely to be missed.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2014-01-27 07:58:22 -07:00
|
|
|
if (!is_sync_state(os.conn) && is_sync_state(ns.conn))
|
|
|
|
clear_bit(RS_DONE, &device->flags);
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
/* FIXME: Have any flags been set earlier in this function already? */
|
|
|
|
state_change = remember_old_state(device->resource, GFP_ATOMIC);
|
|
|
|
|
2014-02-11 00:57:18 -07:00
|
|
|
/* changes to local_cnt and device flags should be visible before
|
|
|
|
* changes to state, which again should be visible before anything else
|
|
|
|
* depending on that change happens. */
|
|
|
|
smp_wmb();
|
2011-07-03 05:26:43 -06:00
|
|
|
device->state.i = ns.i;
|
2011-07-07 17:19:44 -06:00
|
|
|
device->resource->susp = ns.susp;
|
|
|
|
device->resource->susp_nod = ns.susp_nod;
|
|
|
|
device->resource->susp_fen = ns.susp_fen;
|
2014-02-11 00:57:18 -07:00
|
|
|
smp_wmb();
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
remember_new_state(state_change);
|
|
|
|
|
drbd: fix potential protocol error and resulting disconnect/reconnect
When we notice a disk failure on the receiving side,
we stop sending it new incoming writes.
Depending on exact timing of various events, the same transfer log epoch
could end up containing both replicated (before we noticed the failure)
and local-only requests (after we noticed the failure).
The sanity checks in tl_release(), called when receiving a
P_BARRIER_ACK, check that the ack'ed transfer log epoch matches
the expected epoch, and the number of contained writes matches
the number of ack'ed writes.
In this case, they counted both replicated and local-only writes,
but the peer only acknowledges those it has seen. We get a mismatch,
resulting in a protocol error and disconnect/reconnect cycle.
Messages logged are
"BAD! BarrierAck #%u received with n_writes=%u, expected n_writes=%u!\n"
A similar issue can also be triggered when starting a resync while
having a healthy replication link, by invalidating one side, forcing a
full sync, or attaching to a diskless node.
Fix this by closing the current epoch if the state changes in a way
that would cause the replication intent of the next write.
Epochs now contain either only non-replicated,
or only replicated writes.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2013-01-21 07:43:41 -07:00
|
|
|
/* put replicated vs not-replicated requests in seperate epochs */
|
2014-02-11 00:57:18 -07:00
|
|
|
if (drbd_should_do_remote((union drbd_dev_state)os.i) !=
|
|
|
|
drbd_should_do_remote((union drbd_dev_state)ns.i))
|
2013-11-22 04:40:58 -07:00
|
|
|
start_new_tl_epoch(connection);
|
drbd: fix potential protocol error and resulting disconnect/reconnect
When we notice a disk failure on the receiving side,
we stop sending it new incoming writes.
Depending on exact timing of various events, the same transfer log epoch
could end up containing both replicated (before we noticed the failure)
and local-only requests (after we noticed the failure).
The sanity checks in tl_release(), called when receiving a
P_BARRIER_ACK, check that the ack'ed transfer log epoch matches
the expected epoch, and the number of contained writes matches
the number of ack'ed writes.
In this case, they counted both replicated and local-only writes,
but the peer only acknowledges those it has seen. We get a mismatch,
resulting in a protocol error and disconnect/reconnect cycle.
Messages logged are
"BAD! BarrierAck #%u received with n_writes=%u, expected n_writes=%u!\n"
A similar issue can also be triggered when starting a resync while
having a healthy replication link, by invalidating one side, forcing a
full sync, or attaching to a diskless node.
Fix this by closing the current epoch if the state changes in a way
that would cause the replication intent of the next write.
Epochs now contain either only non-replicated,
or only replicated writes.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2013-01-21 07:43:41 -07:00
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING)
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_print_uuids(device, "attached to UUIDs");
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2012-08-28 03:33:35 -06:00
|
|
|
/* Wake up role changes, that were delayed because of connection establishing */
|
|
|
|
if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS &&
|
2014-11-10 09:21:11 -07:00
|
|
|
no_peer_wf_report_params(connection)) {
|
2013-11-22 04:40:58 -07:00
|
|
|
clear_bit(STATE_SENT, &connection->flags);
|
2014-11-10 09:21:11 -07:00
|
|
|
wake_up_all_devices(connection);
|
|
|
|
}
|
2012-08-28 03:33:35 -06:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
wake_up(&device->misc_wait);
|
|
|
|
wake_up(&device->state_wait);
|
2013-11-22 04:40:58 -07:00
|
|
|
wake_up(&connection->ping_wait);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2012-07-26 06:09:49 -06:00
|
|
|
/* Aborted verify run, or we reached the stop sector.
|
|
|
|
* Log the last position, unless end-of-device. */
|
2011-01-27 06:07:51 -07:00
|
|
|
if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) &&
|
2012-07-26 06:09:49 -06:00
|
|
|
ns.conn <= C_CONNECTED) {
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ov_start_sector =
|
|
|
|
BM_BIT_TO_SECT(drbd_bm_bits(device) - device->ov_left);
|
|
|
|
if (device->ov_left)
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "Online Verify reached sector %llu\n",
|
2011-07-03 05:26:43 -06:00
|
|
|
(unsigned long long)device->ov_start_sector);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((os.conn == C_PAUSED_SYNC_T || os.conn == C_PAUSED_SYNC_S) &&
|
|
|
|
(ns.conn == C_SYNC_TARGET || ns.conn == C_SYNC_SOURCE)) {
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "Syncer continues.\n");
|
2011-07-03 05:26:43 -06:00
|
|
|
device->rs_paused += (long)jiffies
|
|
|
|
-(long)device->rs_mark_time[device->rs_last_mark];
|
2011-01-27 06:07:51 -07:00
|
|
|
if (ns.conn == C_SYNC_TARGET)
|
2011-07-03 05:26:43 -06:00
|
|
|
mod_timer(&device->resync_timer, jiffies);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((os.conn == C_SYNC_TARGET || os.conn == C_SYNC_SOURCE) &&
|
|
|
|
(ns.conn == C_PAUSED_SYNC_T || ns.conn == C_PAUSED_SYNC_S)) {
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "Resync suspended\n");
|
2011-07-03 05:26:43 -06:00
|
|
|
device->rs_mark_time[device->rs_last_mark] = jiffies;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (os.conn == C_CONNECTED &&
|
|
|
|
(ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T)) {
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
int i;
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
set_ov_position(device, ns.conn);
|
|
|
|
device->rs_start = now;
|
|
|
|
device->rs_last_sect_ev = 0;
|
|
|
|
device->ov_last_oos_size = 0;
|
|
|
|
device->ov_last_oos_start = 0;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
for (i = 0; i < DRBD_SYNC_MARKS; i++) {
|
2011-07-03 05:26:43 -06:00
|
|
|
device->rs_mark_left[i] = device->ov_left;
|
|
|
|
device->rs_mark_time[i] = now;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_rs_controller_reset(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (ns.conn == C_VERIFY_S) {
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_info(device, "Starting Online Verify from sector %llu\n",
|
2011-07-03 05:26:43 -06:00
|
|
|
(unsigned long long)device->ov_position);
|
|
|
|
mod_timer(&device->resync_timer, jiffies);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (get_ldev(device)) {
|
|
|
|
u32 mdf = device->ldev->md.flags & ~(MDF_CONSISTENT|MDF_PRIMARY_IND|
|
2011-01-27 06:07:51 -07:00
|
|
|
MDF_CONNECTED_IND|MDF_WAS_UP_TO_DATE|
|
|
|
|
MDF_PEER_OUT_DATED|MDF_CRASHED_PRIMARY);
|
|
|
|
|
drbd: on attach, enforce clean meta data
Detection of unclean shutdown has moved into user space.
The kernel code will, whenever it updates the meta data, mark it as
"unclean", and will refuse to attach to such unclean meta data.
"drbdadm up" now schedules "drbdmeta apply-al", which will apply
the activity log to the bitmap, and/or reinitialize it, if necessary,
as well as set a "clean" indicator flag.
This moves a bit code out of kernel space.
As a side effect, it also prevents some 8.3 module from accidentally
ignoring the 8.4 style activity log, if someone should downgrade,
whether on purpose, or accidentally because he changed kernel versions
without providing an 8.4 for the new kernel, and the new kernel comes
with in-tree 8.3.
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
2011-07-05 12:59:26 -06:00
|
|
|
mdf &= ~MDF_AL_CLEAN;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_bit(CRASHED_PRIMARY, &device->flags))
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_CRASHED_PRIMARY;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.role == R_PRIMARY ||
|
|
|
|
(device->state.pdsk < D_INCONSISTENT && device->state.peer == R_PRIMARY))
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_PRIMARY_IND;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.conn > C_WF_REPORT_PARAMS)
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_CONNECTED_IND;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.disk > D_INCONSISTENT)
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_CONSISTENT;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.disk > D_OUTDATED)
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_WAS_UP_TO_DATE;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.pdsk <= D_OUTDATED && device->state.pdsk >= D_INCONSISTENT)
|
2011-01-27 06:07:51 -07:00
|
|
|
mdf |= MDF_PEER_OUT_DATED;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (mdf != device->ldev->md.flags) {
|
|
|
|
device->ldev->md.flags = mdf;
|
|
|
|
drbd_md_mark_dirty(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
if (os.disk < D_CONSISTENT && ns.disk >= D_CONSISTENT)
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_set_ed_uuid(device, device->ldev->md.uuid[UI_CURRENT]);
|
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Peer was forced D_UP_TO_DATE & R_PRIMARY, consider to resync */
|
|
|
|
if (os.disk == D_INCONSISTENT && os.pdsk == D_INCONSISTENT &&
|
|
|
|
os.peer == R_SECONDARY && ns.peer == R_PRIMARY)
|
2011-07-03 05:26:43 -06:00
|
|
|
set_bit(CONSIDER_RESYNC, &device->flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Receiver should clean up itself */
|
|
|
|
if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_thread_stop_nowait(&connection->receiver);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Now the receiver finished cleaning up itself, it should die */
|
|
|
|
if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_thread_stop_nowait(&connection->receiver);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Upon network failure, we need to restart the receiver. */
|
2012-11-08 07:04:36 -07:00
|
|
|
if (os.conn > C_WF_CONNECTION &&
|
2011-01-27 06:07:51 -07:00
|
|
|
ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_thread_restart_nowait(&connection->receiver);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Resume AL writing if we get a connection */
|
2013-06-25 08:50:06 -06:00
|
|
|
if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) {
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_resume_al(device);
|
2013-11-22 04:40:58 -07:00
|
|
|
connection->connect_cnt++;
|
2013-06-25 08:50:06 -06:00
|
|
|
}
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2012-05-07 03:53:08 -06:00
|
|
|
/* remember last attach time so request_timer_fn() won't
|
|
|
|
* kill newly established sessions while we are still trying to thaw
|
|
|
|
* previously frozen IO */
|
|
|
|
if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) &&
|
|
|
|
ns.disk > D_NEGOTIATING)
|
2011-07-03 05:26:43 -06:00
|
|
|
device->last_reattach_jif = jiffies;
|
2012-05-07 03:53:08 -06:00
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
ascw = kmalloc(sizeof(*ascw), GFP_ATOMIC);
|
|
|
|
if (ascw) {
|
|
|
|
ascw->os = os;
|
|
|
|
ascw->ns = ns;
|
|
|
|
ascw->flags = flags;
|
|
|
|
ascw->w.cb = w_after_state_ch;
|
2011-07-28 07:27:51 -06:00
|
|
|
ascw->device = device;
|
2011-01-27 06:07:51 -07:00
|
|
|
ascw->done = done;
|
2014-07-31 09:41:33 -06:00
|
|
|
ascw->state_change = state_change;
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_queue_work(&connection->sender_work,
|
2011-07-28 07:27:51 -06:00
|
|
|
&ascw->w);
|
2011-01-27 06:07:51 -07:00
|
|
|
} else {
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device, "Could not kmalloc an ascw\n");
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-03-16 08:31:39 -06:00
|
|
|
static int w_after_state_ch(struct drbd_work *w, int unused)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
|
|
|
struct after_state_chg_work *ascw =
|
|
|
|
container_of(w, struct after_state_chg_work, w);
|
2011-07-28 07:27:51 -06:00
|
|
|
struct drbd_device *device = ascw->device;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
after_state_ch(device, ascw->os, ascw->ns, ascw->flags, ascw->state_change);
|
|
|
|
forget_state_change(ascw->state_change);
|
2011-08-24 00:19:41 -06:00
|
|
|
if (ascw->flags & CS_WAIT_COMPLETE)
|
2011-01-27 06:07:51 -07:00
|
|
|
complete(ascw->done);
|
|
|
|
kfree(ascw);
|
|
|
|
|
2011-03-16 08:31:39 -06:00
|
|
|
return 0;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
static void abw_start_sync(struct drbd_device *device, int rv)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
|
|
|
if (rv) {
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device, "Writing the bitmap failed not starting resync.\n");
|
2011-07-03 05:26:43 -06:00
|
|
|
_drbd_request_state(device, NS(conn, C_CONNECTED), CS_VERBOSE);
|
2011-01-27 06:07:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
switch (device->state.conn) {
|
2011-01-27 06:07:51 -07:00
|
|
|
case C_STARTING_SYNC_T:
|
2011-07-03 05:26:43 -06:00
|
|
|
_drbd_request_state(device, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE);
|
2011-01-27 06:07:51 -07:00
|
|
|
break;
|
|
|
|
case C_STARTING_SYNC_S:
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_start_resync(device, C_SYNC_SOURCE);
|
2011-01-27 06:07:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
int drbd_bitmap_io_from_worker(struct drbd_device *device,
|
2011-05-30 08:15:21 -06:00
|
|
|
int (*io_fn)(struct drbd_device *),
|
2011-01-27 06:07:51 -07:00
|
|
|
char *why, enum bm_flag flags)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2011-06-27 08:23:33 -06:00
|
|
|
D_ASSERT(device, current == first_peer_device(device)->connection->worker.task);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
/* open coded non-blocking drbd_suspend_io(device); */
|
2013-02-28 02:30:19 -07:00
|
|
|
atomic_inc(&device->suspend_cnt);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_bm_lock(device, why, flags);
|
|
|
|
rv = io_fn(device);
|
|
|
|
drbd_bm_unlock(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_resume_io(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
void notify_resource_state_change(struct sk_buff *skb,
|
|
|
|
unsigned int seq,
|
|
|
|
struct drbd_resource_state_change *resource_state_change,
|
|
|
|
enum drbd_notification_type type)
|
|
|
|
{
|
|
|
|
struct drbd_resource *resource = resource_state_change->resource;
|
|
|
|
struct resource_info resource_info = {
|
|
|
|
.res_role = resource_state_change->role[NEW],
|
|
|
|
.res_susp = resource_state_change->susp[NEW],
|
|
|
|
.res_susp_nod = resource_state_change->susp_nod[NEW],
|
|
|
|
.res_susp_fen = resource_state_change->susp_fen[NEW],
|
|
|
|
};
|
|
|
|
|
|
|
|
notify_resource_state(skb, seq, resource, &resource_info, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_connection_state_change(struct sk_buff *skb,
|
|
|
|
unsigned int seq,
|
|
|
|
struct drbd_connection_state_change *connection_state_change,
|
|
|
|
enum drbd_notification_type type)
|
|
|
|
{
|
|
|
|
struct drbd_connection *connection = connection_state_change->connection;
|
|
|
|
struct connection_info connection_info = {
|
|
|
|
.conn_connection_state = connection_state_change->cstate[NEW],
|
|
|
|
.conn_role = connection_state_change->peer_role[NEW],
|
|
|
|
};
|
|
|
|
|
|
|
|
notify_connection_state(skb, seq, connection, &connection_info, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_device_state_change(struct sk_buff *skb,
|
|
|
|
unsigned int seq,
|
|
|
|
struct drbd_device_state_change *device_state_change,
|
|
|
|
enum drbd_notification_type type)
|
|
|
|
{
|
|
|
|
struct drbd_device *device = device_state_change->device;
|
|
|
|
struct device_info device_info = {
|
|
|
|
.dev_disk_state = device_state_change->disk_state[NEW],
|
|
|
|
};
|
|
|
|
|
|
|
|
notify_device_state(skb, seq, device, &device_info, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notify_peer_device_state_change(struct sk_buff *skb,
|
|
|
|
unsigned int seq,
|
|
|
|
struct drbd_peer_device_state_change *p,
|
|
|
|
enum drbd_notification_type type)
|
|
|
|
{
|
|
|
|
struct drbd_peer_device *peer_device = p->peer_device;
|
|
|
|
struct peer_device_info peer_device_info = {
|
|
|
|
.peer_repl_state = p->repl_state[NEW],
|
|
|
|
.peer_disk_state = p->disk_state[NEW],
|
|
|
|
.peer_resync_susp_user = p->resync_susp_user[NEW],
|
|
|
|
.peer_resync_susp_peer = p->resync_susp_peer[NEW],
|
|
|
|
.peer_resync_susp_dependency = p->resync_susp_dependency[NEW],
|
|
|
|
};
|
|
|
|
|
|
|
|
notify_peer_device_state(skb, seq, peer_device, &peer_device_info, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void broadcast_state_change(struct drbd_state_change *state_change)
|
|
|
|
{
|
|
|
|
struct drbd_resource_state_change *resource_state_change = &state_change->resource[0];
|
|
|
|
bool resource_state_has_changed;
|
|
|
|
unsigned int n_device, n_connection, n_peer_device, n_peer_devices;
|
|
|
|
void (*last_func)(struct sk_buff *, unsigned int, void *,
|
|
|
|
enum drbd_notification_type) = NULL;
|
|
|
|
void *uninitialized_var(last_arg);
|
|
|
|
|
|
|
|
#define HAS_CHANGED(state) ((state)[OLD] != (state)[NEW])
|
|
|
|
#define FINAL_STATE_CHANGE(type) \
|
|
|
|
({ if (last_func) \
|
|
|
|
last_func(NULL, 0, last_arg, type); \
|
|
|
|
})
|
|
|
|
#define REMEMBER_STATE_CHANGE(func, arg, type) \
|
|
|
|
({ FINAL_STATE_CHANGE(type | NOTIFY_CONTINUES); \
|
|
|
|
last_func = (typeof(last_func))func; \
|
|
|
|
last_arg = arg; \
|
|
|
|
})
|
|
|
|
|
|
|
|
mutex_lock(¬ification_mutex);
|
|
|
|
|
|
|
|
resource_state_has_changed =
|
|
|
|
HAS_CHANGED(resource_state_change->role) ||
|
|
|
|
HAS_CHANGED(resource_state_change->susp) ||
|
|
|
|
HAS_CHANGED(resource_state_change->susp_nod) ||
|
|
|
|
HAS_CHANGED(resource_state_change->susp_fen);
|
|
|
|
|
|
|
|
if (resource_state_has_changed)
|
|
|
|
REMEMBER_STATE_CHANGE(notify_resource_state_change,
|
|
|
|
resource_state_change, NOTIFY_CHANGE);
|
|
|
|
|
|
|
|
for (n_connection = 0; n_connection < state_change->n_connections; n_connection++) {
|
|
|
|
struct drbd_connection_state_change *connection_state_change =
|
|
|
|
&state_change->connections[n_connection];
|
|
|
|
|
|
|
|
if (HAS_CHANGED(connection_state_change->peer_role) ||
|
|
|
|
HAS_CHANGED(connection_state_change->cstate))
|
|
|
|
REMEMBER_STATE_CHANGE(notify_connection_state_change,
|
|
|
|
connection_state_change, NOTIFY_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n_device = 0; n_device < state_change->n_devices; n_device++) {
|
|
|
|
struct drbd_device_state_change *device_state_change =
|
|
|
|
&state_change->devices[n_device];
|
|
|
|
|
|
|
|
if (HAS_CHANGED(device_state_change->disk_state))
|
|
|
|
REMEMBER_STATE_CHANGE(notify_device_state_change,
|
|
|
|
device_state_change, NOTIFY_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
n_peer_devices = state_change->n_devices * state_change->n_connections;
|
|
|
|
for (n_peer_device = 0; n_peer_device < n_peer_devices; n_peer_device++) {
|
|
|
|
struct drbd_peer_device_state_change *p =
|
|
|
|
&state_change->peer_devices[n_peer_device];
|
|
|
|
|
|
|
|
if (HAS_CHANGED(p->disk_state) ||
|
|
|
|
HAS_CHANGED(p->repl_state) ||
|
|
|
|
HAS_CHANGED(p->resync_susp_user) ||
|
|
|
|
HAS_CHANGED(p->resync_susp_peer) ||
|
|
|
|
HAS_CHANGED(p->resync_susp_dependency))
|
|
|
|
REMEMBER_STATE_CHANGE(notify_peer_device_state_change,
|
|
|
|
p, NOTIFY_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
FINAL_STATE_CHANGE(NOTIFY_CHANGE);
|
|
|
|
mutex_unlock(¬ification_mutex);
|
|
|
|
|
|
|
|
#undef HAS_CHANGED
|
|
|
|
#undef FINAL_STATE_CHANGE
|
|
|
|
#undef REMEMBER_STATE_CHANGE
|
|
|
|
}
|
|
|
|
|
2016-06-13 16:26:34 -06:00
|
|
|
/* takes old and new peer disk state */
|
|
|
|
static bool lost_contact_to_peer_data(enum drbd_disk_state os, enum drbd_disk_state ns)
|
|
|
|
{
|
|
|
|
if ((os >= D_INCONSISTENT && os != D_UNKNOWN && os != D_OUTDATED)
|
|
|
|
&& (ns < D_INCONSISTENT || ns == D_UNKNOWN || ns == D_OUTDATED))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Scenario, starting with normal operation
|
|
|
|
* Connected Primary/Secondary UpToDate/UpToDate
|
|
|
|
* NetworkFailure Primary/Unknown UpToDate/DUnknown (frozen)
|
|
|
|
* ...
|
|
|
|
* Connected Primary/Secondary UpToDate/Diskless (resumed; needs to bump uuid!)
|
|
|
|
*/
|
|
|
|
if (os == D_UNKNOWN
|
|
|
|
&& (ns == D_DISKLESS || ns == D_FAILED || ns == D_OUTDATED))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/**
|
|
|
|
* after_state_ch() - Perform after state change actions that may sleep
|
2011-07-03 05:26:43 -06:00
|
|
|
* @device: DRBD device.
|
2011-01-27 06:07:51 -07:00
|
|
|
* @os: old state.
|
|
|
|
* @ns: new state.
|
|
|
|
* @flags: Flags
|
|
|
|
*/
|
2011-07-03 05:26:43 -06:00
|
|
|
static void after_state_ch(struct drbd_device *device, union drbd_state os,
|
2014-07-31 09:41:33 -06:00
|
|
|
union drbd_state ns, enum chg_state_flags flags,
|
|
|
|
struct drbd_state_change *state_change)
|
2011-01-27 06:07:51 -07:00
|
|
|
{
|
2011-07-07 17:19:44 -06:00
|
|
|
struct drbd_resource *resource = device->resource;
|
2013-11-22 04:40:58 -07:00
|
|
|
struct drbd_peer_device *peer_device = first_peer_device(device);
|
|
|
|
struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
|
2011-03-07 04:49:34 -07:00
|
|
|
struct sib_info sib;
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
broadcast_state_change(state_change);
|
|
|
|
|
2011-03-07 04:49:34 -07:00
|
|
|
sib.sib_reason = SIB_STATE_CHANGE;
|
|
|
|
sib.os = os;
|
|
|
|
sib.ns = ns;
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2014-03-27 03:34:13 -06:00
|
|
|
if ((os.disk != D_UP_TO_DATE || os.pdsk != D_UP_TO_DATE)
|
|
|
|
&& (ns.disk == D_UP_TO_DATE && ns.pdsk == D_UP_TO_DATE)) {
|
2011-07-03 05:26:43 -06:00
|
|
|
clear_bit(CRASHED_PRIMARY, &device->flags);
|
|
|
|
if (device->p_uuid)
|
|
|
|
device->p_uuid[UI_FLAGS] &= ~((u64)2);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Inform userspace about the change... */
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_bcast_event(device, &sib);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (!(os.role == R_PRIMARY && os.disk < D_UP_TO_DATE && os.pdsk < D_UP_TO_DATE) &&
|
|
|
|
(ns.role == R_PRIMARY && ns.disk < D_UP_TO_DATE && ns.pdsk < D_UP_TO_DATE))
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_khelper(device, "pri-on-incon-degr");
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Here we have the actions that are performed after a
|
|
|
|
state change. This function might sleep */
|
|
|
|
|
|
|
|
if (ns.susp_nod) {
|
2011-03-29 10:16:11 -06:00
|
|
|
enum drbd_req_event what = NOTHING;
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&device->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
if (os.conn < C_CONNECTED && conn_lowest_conn(connection) >= C_CONNECTED)
|
2011-01-27 06:07:51 -07:00
|
|
|
what = RESEND;
|
|
|
|
|
2011-07-15 10:44:26 -06:00
|
|
|
if ((os.disk == D_ATTACHING || os.disk == D_NEGOTIATING) &&
|
2016-06-13 16:26:28 -06:00
|
|
|
conn_lowest_disk(connection) == D_UP_TO_DATE)
|
2011-01-27 06:07:51 -07:00
|
|
|
what = RESTART_FROZEN_DISK_IO;
|
|
|
|
|
2011-07-07 17:19:44 -06:00
|
|
|
if (resource->susp_nod && what != NOTHING) {
|
2011-05-30 08:32:41 -06:00
|
|
|
_tl_restart(connection, what);
|
|
|
|
_conn_request_state(connection,
|
2012-08-27 09:20:12 -06:00
|
|
|
(union drbd_state) { { .susp_nod = 1 } },
|
|
|
|
(union drbd_state) { { .susp_nod = 0 } },
|
|
|
|
CS_VERBOSE);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&device->resource->req_lock);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-27 09:16:21 -06:00
|
|
|
if (ns.susp_fen) {
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&device->resource->req_lock);
|
2011-07-07 17:19:44 -06:00
|
|
|
if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) {
|
2012-08-27 09:16:21 -06:00
|
|
|
/* case2: The connection was established again: */
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2012-08-27 09:16:21 -06:00
|
|
|
int vnr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
|
|
|
|
clear_bit(NEW_CUR_UUID, &peer_device->device->flags);
|
2012-08-27 09:16:21 -06:00
|
|
|
rcu_read_unlock();
|
2016-06-13 16:26:34 -06:00
|
|
|
|
|
|
|
/* We should actively create a new uuid, _before_
|
|
|
|
* we resume/resent, if the peer is diskless
|
|
|
|
* (recovery from a multiple error scenario).
|
|
|
|
* Currently, this happens with a slight delay
|
|
|
|
* below when checking lost_contact_to_peer_data() ...
|
|
|
|
*/
|
2011-05-30 08:32:41 -06:00
|
|
|
_tl_restart(connection, RESEND);
|
|
|
|
_conn_request_state(connection,
|
2012-08-27 09:16:21 -06:00
|
|
|
(union drbd_state) { { .susp_fen = 1 } },
|
|
|
|
(union drbd_state) { { .susp_fen = 0 } },
|
|
|
|
CS_VERBOSE);
|
|
|
|
}
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&device->resource->req_lock);
|
2012-08-27 09:16:21 -06:00
|
|
|
}
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/* Became sync source. With protocol >= 96, we still need to send out
|
|
|
|
* the sync uuid now. Need to do that before any drbd_send_state, or
|
|
|
|
* the other side may go "paused sync" before receiving the sync uuids,
|
|
|
|
* which is unexpected. */
|
|
|
|
if ((os.conn != C_SYNC_SOURCE && os.conn != C_PAUSED_SYNC_S) &&
|
|
|
|
(ns.conn == C_SYNC_SOURCE || ns.conn == C_PAUSED_SYNC_S) &&
|
2013-11-22 04:40:58 -07:00
|
|
|
connection->agreed_pro_version >= 96 && get_ldev(device)) {
|
|
|
|
drbd_gen_and_send_sync_uuid(peer_device);
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not change the order of the if above and the two below... */
|
2011-07-06 15:04:44 -06:00
|
|
|
if (os.pdsk == D_DISKLESS &&
|
|
|
|
ns.pdsk > D_DISKLESS && ns.pdsk != D_UNKNOWN) { /* attach on the peer */
|
2012-07-30 01:10:41 -06:00
|
|
|
/* we probably will start a resync soon.
|
|
|
|
* make sure those things are properly reset. */
|
2011-07-03 05:26:43 -06:00
|
|
|
device->rs_total = 0;
|
|
|
|
device->rs_failed = 0;
|
|
|
|
atomic_set(&device->rs_pending_cnt, 0);
|
|
|
|
drbd_rs_cancel_all(device);
|
2012-07-30 01:10:41 -06:00
|
|
|
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_uuids(peer_device);
|
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
/* No point in queuing send_bitmap if we don't have a connection
|
|
|
|
* anymore, so check also the _current_ state, not only the new state
|
|
|
|
* at the time this work was queued. */
|
|
|
|
if (os.conn != C_WF_BITMAP_S && ns.conn == C_WF_BITMAP_S &&
|
2011-07-03 05:26:43 -06:00
|
|
|
device->state.conn == C_WF_BITMAP_S)
|
|
|
|
drbd_queue_bitmap_io(device, &drbd_send_bitmap, NULL,
|
2011-01-27 06:07:51 -07:00
|
|
|
"send_bitmap (WFBitMapS)",
|
|
|
|
BM_LOCKED_TEST_ALLOWED);
|
|
|
|
|
|
|
|
/* Lost contact to peer's copy of the data */
|
2016-06-13 16:26:34 -06:00
|
|
|
if (lost_contact_to_peer_data(os.pdsk, ns.pdsk)) {
|
2011-07-03 05:26:43 -06:00
|
|
|
if (get_ldev(device)) {
|
2011-01-27 06:07:51 -07:00
|
|
|
if ((ns.role == R_PRIMARY || ns.peer == R_PRIMARY) &&
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) {
|
|
|
|
if (drbd_suspended(device)) {
|
|
|
|
set_bit(NEW_CUR_UUID, &device->flags);
|
2011-01-27 06:07:51 -07:00
|
|
|
} else {
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_uuid_new_current(device);
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_uuids(peer_device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
if (ns.pdsk < D_INCONSISTENT && get_ldev(device)) {
|
2015-02-19 06:01:50 -07:00
|
|
|
if (os.peer != R_PRIMARY && ns.peer == R_PRIMARY &&
|
2011-07-03 05:26:43 -06:00
|
|
|
device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) {
|
|
|
|
drbd_uuid_new_current(device);
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_uuids(peer_device);
|
2011-11-10 04:12:52 -07:00
|
|
|
}
|
2011-01-27 06:07:51 -07:00
|
|
|
/* D_DISKLESS Peer becomes secondary */
|
|
|
|
if (os.peer == R_PRIMARY && ns.peer == R_SECONDARY)
|
|
|
|
/* We may still be Primary ourselves.
|
|
|
|
* No harm done if the bitmap still changes,
|
|
|
|
* redirtied pages will follow later. */
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_bitmap_io_from_worker(device, &drbd_bm_write,
|
2011-01-27 06:07:51 -07:00
|
|
|
"demote diskless peer", BM_LOCKED_SET_ALLOWED);
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out all changed bits on demote.
|
|
|
|
* Though, no need to da that just yet
|
|
|
|
* if there is a resync going on still */
|
|
|
|
if (os.role == R_PRIMARY && ns.role == R_SECONDARY &&
|
2011-07-03 05:26:43 -06:00
|
|
|
device->state.conn <= C_CONNECTED && get_ldev(device)) {
|
2011-01-27 06:07:51 -07:00
|
|
|
/* No changes to the bitmap expected this time, so assert that,
|
|
|
|
* even though no harm was done if it did change. */
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_bitmap_io_from_worker(device, &drbd_bm_write,
|
2011-01-27 06:07:51 -07:00
|
|
|
"demote", BM_LOCKED_TEST_ALLOWED);
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Last part of the attaching process ... */
|
|
|
|
if (ns.conn >= C_CONNECTED &&
|
|
|
|
os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) {
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_sizes(peer_device, 0, 0); /* to start sync... */
|
|
|
|
drbd_send_uuids(peer_device);
|
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to pause/continue resync, tell peer. */
|
|
|
|
if (ns.conn >= C_CONNECTED &&
|
|
|
|
((os.aftr_isp != ns.aftr_isp) ||
|
|
|
|
(os.user_isp != ns.user_isp)))
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* In case one of the isp bits got set, suspend other devices. */
|
|
|
|
if ((!os.aftr_isp && !os.peer_isp && !os.user_isp) &&
|
|
|
|
(ns.aftr_isp || ns.peer_isp || ns.user_isp))
|
2011-07-03 05:26:43 -06:00
|
|
|
suspend_other_sg(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Make sure the peer gets informed about eventual state
|
|
|
|
changes (ISP bits) while we were in WFReportParams. */
|
|
|
|
if (os.conn == C_WF_REPORT_PARAMS && ns.conn >= C_CONNECTED)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
if (os.conn != C_AHEAD && ns.conn == C_AHEAD)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* We are in the progress to start a full sync... */
|
|
|
|
if ((os.conn != C_STARTING_SYNC_T && ns.conn == C_STARTING_SYNC_T) ||
|
|
|
|
(os.conn != C_STARTING_SYNC_S && ns.conn == C_STARTING_SYNC_S))
|
|
|
|
/* no other bitmap changes expected during this phase */
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_queue_bitmap_io(device,
|
2011-01-27 06:07:51 -07:00
|
|
|
&drbd_bmio_set_n_write, &abw_start_sync,
|
|
|
|
"set_n_write from StartingSync", BM_LOCKED_TEST_ALLOWED);
|
|
|
|
|
|
|
|
/* first half of local IO error, failure to attach,
|
|
|
|
* or administrative detach */
|
|
|
|
if (os.disk != D_FAILED && ns.disk == D_FAILED) {
|
2012-02-22 03:51:57 -07:00
|
|
|
enum drbd_io_error_p eh = EP_PASS_ON;
|
|
|
|
int was_io_error = 0;
|
2014-08-14 10:33:30 -06:00
|
|
|
/* corresponding get_ldev was in _drbd_set_state, to serialize
|
2012-02-22 03:51:57 -07:00
|
|
|
* our cleanup here with the transition to D_DISKLESS.
|
|
|
|
* But is is still not save to dreference ldev here, since
|
|
|
|
* we might come from an failed Attach before ldev was set. */
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->ldev) {
|
2012-02-22 03:51:57 -07:00
|
|
|
rcu_read_lock();
|
2011-07-03 05:26:43 -06:00
|
|
|
eh = rcu_dereference(device->ldev->disk_conf)->on_io_error;
|
2012-02-22 03:51:57 -07:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
was_io_error = test_and_clear_bit(WAS_IO_ERROR, &device->flags);
|
2012-02-22 03:51:57 -07:00
|
|
|
|
2015-02-19 05:43:55 -07:00
|
|
|
/* Intentionally call this handler first, before drbd_send_state().
|
|
|
|
* See: 2932204 drbd: call local-io-error handler early
|
|
|
|
* People may chose to hard-reset the box from this handler.
|
|
|
|
* It is useful if this looks like a "regular node crash". */
|
2012-07-30 01:11:01 -06:00
|
|
|
if (was_io_error && eh == EP_CALL_HELPER)
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_khelper(device, "local-io-error");
|
2012-07-30 01:11:01 -06:00
|
|
|
|
2012-07-30 01:07:28 -06:00
|
|
|
/* Immediately allow completion of all application IO,
|
|
|
|
* that waits for completion from the local disk,
|
|
|
|
* if this was a force-detach due to disk_timeout
|
|
|
|
* or administrator request (drbdsetup detach --force).
|
|
|
|
* Do NOT abort otherwise.
|
|
|
|
* Aborting local requests may cause serious problems,
|
|
|
|
* if requests are completed to upper layers already,
|
|
|
|
* and then later the already submitted local bio completes.
|
|
|
|
* This can cause DMA into former bio pages that meanwhile
|
|
|
|
* have been re-used for other things.
|
|
|
|
* So aborting local requests may cause crashes,
|
|
|
|
* or even worse, silent data corruption.
|
|
|
|
*/
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_and_clear_bit(FORCE_DETACH, &device->flags))
|
|
|
|
tl_abort_disk_io(device);
|
2012-02-22 03:51:57 -07:00
|
|
|
|
|
|
|
/* current state still has to be D_FAILED,
|
|
|
|
* there is only one way out: to D_DISKLESS,
|
|
|
|
* and that may only happen after our put_ldev below. */
|
2011-07-03 05:26:43 -06:00
|
|
|
if (device->state.disk != D_FAILED)
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device,
|
2012-02-22 03:51:57 -07:00
|
|
|
"ASSERT FAILED: disk is %s during detach\n",
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_disk_str(device->state.disk));
|
2012-02-22 03:51:57 -07:00
|
|
|
|
|
|
|
if (ns.conn >= C_CONNECTED)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2012-02-22 03:51:57 -07:00
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_rs_cancel_all(device);
|
2012-02-22 03:51:57 -07:00
|
|
|
|
|
|
|
/* In case we want to get something to stable storage still,
|
|
|
|
* this may be the last chance.
|
|
|
|
* Following put_ldev may transition to D_DISKLESS. */
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_md_sync(device);
|
2012-02-22 03:51:57 -07:00
|
|
|
}
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
/* second half of local IO error, failure to attach,
|
|
|
|
* or administrative detach,
|
|
|
|
* after local_cnt references have reached zero again */
|
|
|
|
if (os.disk != D_DISKLESS && ns.disk == D_DISKLESS) {
|
|
|
|
/* We must still be diskless,
|
|
|
|
* re-attach has to be serialized with this! */
|
|
|
|
if (device->state.disk != D_DISKLESS)
|
2011-07-03 09:53:52 -06:00
|
|
|
drbd_err(device,
|
|
|
|
"ASSERT FAILED: disk is %s while going diskless\n",
|
|
|
|
drbd_disk_str(device->state.disk));
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-12-13 10:32:18 -07:00
|
|
|
if (ns.conn >= C_CONNECTED)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
/* corresponding get_ldev in __drbd_set_state
|
|
|
|
* this may finally trigger drbd_ldev_destroy. */
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify peer that I had a local IO error, and did not detached.. */
|
2011-12-13 10:32:18 -07:00
|
|
|
if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* Disks got bigger while they were detached */
|
|
|
|
if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING &&
|
2011-07-03 05:26:43 -06:00
|
|
|
test_and_clear_bit(RESYNC_AFTER_NEG, &device->flags)) {
|
2011-01-27 06:07:51 -07:00
|
|
|
if (ns.conn == C_CONNECTED)
|
2011-07-03 05:26:43 -06:00
|
|
|
resync_after_online_grow(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A resync finished or aborted, wake paused devices... */
|
|
|
|
if ((os.conn > C_CONNECTED && ns.conn <= C_CONNECTED) ||
|
|
|
|
(os.peer_isp && !ns.peer_isp) ||
|
|
|
|
(os.user_isp && !ns.user_isp))
|
2011-07-03 05:26:43 -06:00
|
|
|
resume_next_sg(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
|
|
|
/* sync target done with resync. Explicitly notify peer, even though
|
|
|
|
* it should (at least for non-empty resyncs) already know itself. */
|
|
|
|
if (os.disk < D_UP_TO_DATE && os.conn >= C_SYNC_SOURCE && ns.conn == C_CONNECTED)
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2012-07-26 06:09:49 -06:00
|
|
|
/* Verify finished, or reached stop sector. Peer did not know about
|
|
|
|
* the stop sector, and we may even have changed the stop sector during
|
|
|
|
* verify to interrupt/stop early. Send the new state. */
|
|
|
|
if (os.conn == C_VERIFY_S && ns.conn == C_CONNECTED
|
2011-07-03 05:26:43 -06:00
|
|
|
&& verify_can_do_stop_sector(device))
|
2013-11-22 04:40:58 -07:00
|
|
|
drbd_send_state(peer_device, ns);
|
2012-07-26 06:09:49 -06:00
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/* This triggers bitmap writeout of potentially still unwritten pages
|
|
|
|
* if the resync finished cleanly, or aborted because of peer disk
|
2016-06-13 16:26:11 -06:00
|
|
|
* failure, or on transition from resync back to AHEAD/BEHIND.
|
|
|
|
*
|
|
|
|
* Connection loss is handled in drbd_disconnected() by the receiver.
|
|
|
|
*
|
2011-01-27 06:07:51 -07:00
|
|
|
* For resync aborted because of local disk failure, we cannot do
|
|
|
|
* any bitmap writeout anymore.
|
2016-06-13 16:26:11 -06:00
|
|
|
*
|
2011-01-27 06:07:51 -07:00
|
|
|
* No harm done if some bits change during this phase.
|
|
|
|
*/
|
2016-06-13 16:26:11 -06:00
|
|
|
if ((os.conn > C_CONNECTED && os.conn < C_AHEAD) &&
|
|
|
|
(ns.conn == C_CONNECTED || ns.conn >= C_AHEAD) && get_ldev(device)) {
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_queue_bitmap_io(device, &drbd_bm_write_copy_pages, NULL,
|
2012-05-07 04:07:18 -06:00
|
|
|
"write from resync_finished", BM_LOCKED_CHANGE_ALLOWED);
|
2011-07-03 05:26:43 -06:00
|
|
|
put_ldev(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ns.disk == D_DISKLESS &&
|
|
|
|
ns.conn == C_STANDALONE &&
|
|
|
|
ns.role == R_SECONDARY) {
|
|
|
|
if (os.aftr_isp != ns.aftr_isp)
|
2011-07-03 05:26:43 -06:00
|
|
|
resume_next_sg(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-07-03 05:26:43 -06:00
|
|
|
drbd_md_sync(device);
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-02-10 05:45:46 -07:00
|
|
|
struct after_conn_state_chg_work {
|
2011-08-25 07:14:48 -06:00
|
|
|
struct drbd_work w;
|
2011-02-10 05:45:46 -07:00
|
|
|
enum drbd_conns oc;
|
2011-03-29 06:01:02 -06:00
|
|
|
union drbd_state ns_min;
|
2011-07-03 05:26:43 -06:00
|
|
|
union drbd_state ns_max; /* new, max state, over all devices */
|
2011-02-10 05:45:46 -07:00
|
|
|
enum chg_state_flags flags;
|
2011-07-28 07:27:51 -06:00
|
|
|
struct drbd_connection *connection;
|
2014-07-31 09:41:33 -06:00
|
|
|
struct drbd_state_change *state_change;
|
2011-02-10 05:45:46 -07:00
|
|
|
};
|
|
|
|
|
2011-03-16 08:31:39 -06:00
|
|
|
static int w_after_conn_state_ch(struct drbd_work *w, int unused)
|
2011-02-10 05:45:46 -07:00
|
|
|
{
|
|
|
|
struct after_conn_state_chg_work *acscw =
|
2011-08-25 07:14:48 -06:00
|
|
|
container_of(w, struct after_conn_state_chg_work, w);
|
2011-07-28 07:27:51 -06:00
|
|
|
struct drbd_connection *connection = acscw->connection;
|
2011-02-10 05:45:46 -07:00
|
|
|
enum drbd_conns oc = acscw->oc;
|
2011-03-29 05:20:58 -06:00
|
|
|
union drbd_state ns_max = acscw->ns_max;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-29 10:16:11 -06:00
|
|
|
int vnr;
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
broadcast_state_change(acscw->state_change);
|
|
|
|
forget_state_change(acscw->state_change);
|
2011-02-10 05:45:46 -07:00
|
|
|
kfree(acscw);
|
|
|
|
|
2011-01-27 06:07:51 -07:00
|
|
|
/* Upon network configuration, we need to start the receiver */
|
2011-03-29 05:20:58 -06:00
|
|
|
if (oc == C_STANDALONE && ns_max.conn == C_UNCONNECTED)
|
2011-05-30 08:32:41 -06:00
|
|
|
drbd_thread_start(&connection->receiver);
|
2011-01-27 06:07:51 -07:00
|
|
|
|
2011-05-02 02:45:05 -06:00
|
|
|
if (oc == C_DISCONNECTING && ns_max.conn == C_STANDALONE) {
|
|
|
|
struct net_conf *old_conf;
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
mutex_lock(¬ification_mutex);
|
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr)
|
|
|
|
notify_peer_device_state(NULL, 0, peer_device, NULL,
|
|
|
|
NOTIFY_DESTROY | NOTIFY_CONTINUES);
|
|
|
|
notify_connection_state(NULL, 0, connection, NULL, NOTIFY_DESTROY);
|
|
|
|
mutex_unlock(¬ification_mutex);
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
mutex_lock(&connection->resource->conf_update);
|
2011-05-30 08:32:41 -06:00
|
|
|
old_conf = connection->net_conf;
|
|
|
|
connection->my_addr_len = 0;
|
|
|
|
connection->peer_addr_len = 0;
|
2014-03-22 14:32:29 -06:00
|
|
|
RCU_INIT_POINTER(connection->net_conf, NULL);
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_free_crypto(connection);
|
2011-07-07 06:19:42 -06:00
|
|
|
mutex_unlock(&connection->resource->conf_update);
|
2011-05-02 02:45:05 -06:00
|
|
|
|
|
|
|
synchronize_rcu();
|
|
|
|
kfree(old_conf);
|
|
|
|
}
|
|
|
|
|
2011-03-29 10:16:11 -06:00
|
|
|
if (ns_max.susp_fen) {
|
|
|
|
/* case1: The outdate peer handler is successful: */
|
|
|
|
if (ns_max.pdsk <= D_OUTDATED) {
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
if (test_bit(NEW_CUR_UUID, &device->flags)) {
|
|
|
|
drbd_uuid_new_current(device);
|
|
|
|
clear_bit(NEW_CUR_UUID, &device->flags);
|
2011-03-29 10:16:11 -06:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
_tl_restart(connection, CONNECTION_LOST_WHILE_PENDING);
|
|
|
|
_conn_request_state(connection,
|
2012-08-07 05:28:00 -06:00
|
|
|
(union drbd_state) { { .susp_fen = 1 } },
|
|
|
|
(union drbd_state) { { .susp_fen = 0 } },
|
|
|
|
CS_VERBOSE);
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2011-03-29 10:16:11 -06:00
|
|
|
}
|
|
|
|
}
|
2011-06-07 14:54:17 -06:00
|
|
|
kref_put(&connection->kref, drbd_destroy_connection);
|
2012-08-28 08:48:03 -06:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_md_sync(connection);
|
2012-08-28 08:48:03 -06:00
|
|
|
|
2011-03-16 08:31:39 -06:00
|
|
|
return 0;
|
2011-02-10 05:45:46 -07:00
|
|
|
}
|
|
|
|
|
2014-02-27 01:46:18 -07:00
|
|
|
static void conn_old_common_state(struct drbd_connection *connection, union drbd_state *pcs, enum chg_state_flags *pf)
|
2011-03-25 07:31:11 -06:00
|
|
|
{
|
2011-03-25 08:11:30 -06:00
|
|
|
enum chg_state_flags flags = ~0;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-25 08:11:30 -06:00
|
|
|
int vnr, first_vol = 1;
|
2011-07-11 09:04:23 -06:00
|
|
|
union drbd_dev_state os, cs = {
|
|
|
|
{ .role = R_SECONDARY,
|
|
|
|
.peer = R_UNKNOWN,
|
2011-05-30 08:32:41 -06:00
|
|
|
.conn = connection->cstate,
|
2011-07-11 09:04:23 -06:00
|
|
|
.disk = D_DISKLESS,
|
|
|
|
.pdsk = D_UNKNOWN,
|
|
|
|
} };
|
2011-03-25 07:31:11 -06:00
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
os = device->state;
|
2011-03-25 07:31:11 -06:00
|
|
|
|
2011-03-25 08:11:30 -06:00
|
|
|
if (first_vol) {
|
|
|
|
cs = os;
|
|
|
|
first_vol = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cs.role != os.role)
|
|
|
|
flags &= ~CS_DC_ROLE;
|
|
|
|
|
|
|
|
if (cs.peer != os.peer)
|
|
|
|
flags &= ~CS_DC_PEER;
|
|
|
|
|
|
|
|
if (cs.conn != os.conn)
|
|
|
|
flags &= ~CS_DC_CONN;
|
2011-03-25 07:31:11 -06:00
|
|
|
|
2011-03-25 08:11:30 -06:00
|
|
|
if (cs.disk != os.disk)
|
|
|
|
flags &= ~CS_DC_DISK;
|
2011-03-25 07:31:11 -06:00
|
|
|
|
2011-03-25 08:11:30 -06:00
|
|
|
if (cs.pdsk != os.pdsk)
|
|
|
|
flags &= ~CS_DC_PDSK;
|
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-03-25 08:11:30 -06:00
|
|
|
|
|
|
|
*pf |= CS_DC_MASK;
|
|
|
|
*pf &= flags;
|
2011-03-29 02:52:01 -06:00
|
|
|
(*pcs).i = cs.i;
|
2011-03-25 07:31:11 -06:00
|
|
|
}
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-03-25 05:02:20 -06:00
|
|
|
static enum drbd_state_rv
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_is_valid_transition(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
|
2011-03-25 07:31:11 -06:00
|
|
|
enum chg_state_flags flags)
|
2011-02-10 05:45:46 -07:00
|
|
|
{
|
2011-03-25 05:02:20 -06:00
|
|
|
enum drbd_state_rv rv = SS_SUCCESS;
|
2011-02-10 05:45:46 -07:00
|
|
|
union drbd_state ns, os;
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-03-25 05:02:20 -06:00
|
|
|
int vnr;
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-03 05:26:43 -06:00
|
|
|
os = drbd_read_state(device);
|
2014-04-28 10:43:13 -06:00
|
|
|
ns = sanitize_state(device, os, apply_mask_val(os, mask, val), NULL);
|
2011-03-25 05:02:20 -06:00
|
|
|
|
2011-03-28 04:55:03 -06:00
|
|
|
if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED)
|
|
|
|
ns.disk = os.disk;
|
|
|
|
|
2011-03-25 05:02:20 -06:00
|
|
|
if (ns.i == os.i)
|
|
|
|
continue;
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-03-25 05:02:20 -06:00
|
|
|
rv = is_valid_transition(os, ns);
|
|
|
|
|
2011-06-21 09:23:59 -06:00
|
|
|
if (rv >= SS_SUCCESS && !(flags & CS_HARD)) {
|
2011-07-03 05:26:43 -06:00
|
|
|
rv = is_valid_state(device, ns);
|
2011-03-25 05:02:20 -06:00
|
|
|
if (rv < SS_SUCCESS) {
|
2011-07-03 05:26:43 -06:00
|
|
|
if (is_valid_state(device, os) == rv)
|
2011-05-30 08:32:41 -06:00
|
|
|
rv = is_valid_soft_transition(os, ns, connection);
|
2011-03-25 05:02:20 -06:00
|
|
|
} else
|
2011-05-30 08:32:41 -06:00
|
|
|
rv = is_valid_soft_transition(os, ns, connection);
|
2011-03-25 05:02:20 -06:00
|
|
|
}
|
2011-06-21 09:23:59 -06:00
|
|
|
|
|
|
|
if (rv < SS_SUCCESS) {
|
|
|
|
if (flags & CS_VERBOSE)
|
|
|
|
print_st_err(device, os, ns, rv);
|
2011-03-25 05:02:20 -06:00
|
|
|
break;
|
2011-06-21 09:23:59 -06:00
|
|
|
}
|
2011-02-10 05:45:46 -07:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-03-25 05:02:20 -06:00
|
|
|
return rv;
|
2011-02-10 05:45:46 -07:00
|
|
|
}
|
|
|
|
|
2014-02-27 01:46:18 -07:00
|
|
|
static void
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_set_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
|
2011-03-29 06:01:02 -06:00
|
|
|
union drbd_state *pns_min, union drbd_state *pns_max, enum chg_state_flags flags)
|
2011-02-10 05:45:46 -07:00
|
|
|
{
|
2011-07-18 02:44:24 -06:00
|
|
|
union drbd_state ns, os, ns_max = { };
|
2011-03-29 06:01:02 -06:00
|
|
|
union drbd_state ns_min = {
|
|
|
|
{ .role = R_MASK,
|
|
|
|
.peer = R_MASK,
|
2011-07-11 09:04:23 -06:00
|
|
|
.conn = val.conn,
|
2011-03-29 06:01:02 -06:00
|
|
|
.disk = D_MASK,
|
|
|
|
.pdsk = D_MASK
|
|
|
|
} };
|
2011-06-21 09:23:59 -06:00
|
|
|
struct drbd_peer_device *peer_device;
|
2011-02-10 05:45:46 -07:00
|
|
|
enum drbd_state_rv rv;
|
2011-07-18 02:44:24 -06:00
|
|
|
int vnr, number_of_volumes = 0;
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2012-05-07 03:53:08 -06:00
|
|
|
if (mask.conn == C_MASK) {
|
|
|
|
/* remember last connect time so request_timer_fn() won't
|
|
|
|
* kill newly established sessions while we are still trying to thaw
|
|
|
|
* previously frozen IO */
|
2011-05-30 08:32:41 -06:00
|
|
|
if (connection->cstate != C_WF_REPORT_PARAMS && val.conn == C_WF_REPORT_PARAMS)
|
|
|
|
connection->last_reconnect_jif = jiffies;
|
2012-05-07 03:53:08 -06:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
connection->cstate = val.conn;
|
2012-05-07 03:53:08 -06:00
|
|
|
}
|
2011-03-25 05:02:20 -06:00
|
|
|
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_lock();
|
2011-06-21 09:23:59 -06:00
|
|
|
idr_for_each_entry(&connection->peer_devices, peer_device, vnr) {
|
|
|
|
struct drbd_device *device = peer_device->device;
|
2011-07-18 02:44:24 -06:00
|
|
|
number_of_volumes++;
|
2011-07-03 05:26:43 -06:00
|
|
|
os = drbd_read_state(device);
|
2011-03-25 05:02:20 -06:00
|
|
|
ns = apply_mask_val(os, mask, val);
|
2014-04-28 10:43:13 -06:00
|
|
|
ns = sanitize_state(device, os, ns, NULL);
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-03-28 04:55:03 -06:00
|
|
|
if (flags & CS_IGN_OUTD_FAIL && ns.disk == D_OUTDATED && os.disk < D_OUTDATED)
|
|
|
|
ns.disk = os.disk;
|
|
|
|
|
2014-08-14 10:33:30 -06:00
|
|
|
rv = _drbd_set_state(device, ns, flags, NULL);
|
2016-06-13 16:26:35 -06:00
|
|
|
BUG_ON(rv < SS_SUCCESS);
|
2011-07-03 05:26:43 -06:00
|
|
|
ns.i = device->state.i;
|
2011-03-29 06:01:02 -06:00
|
|
|
ns_max.role = max_role(ns.role, ns_max.role);
|
|
|
|
ns_max.peer = max_role(ns.peer, ns_max.peer);
|
|
|
|
ns_max.conn = max_t(enum drbd_conns, ns.conn, ns_max.conn);
|
|
|
|
ns_max.disk = max_t(enum drbd_disk_state, ns.disk, ns_max.disk);
|
|
|
|
ns_max.pdsk = max_t(enum drbd_disk_state, ns.pdsk, ns_max.pdsk);
|
|
|
|
|
|
|
|
ns_min.role = min_role(ns.role, ns_min.role);
|
|
|
|
ns_min.peer = min_role(ns.peer, ns_min.peer);
|
|
|
|
ns_min.conn = min_t(enum drbd_conns, ns.conn, ns_min.conn);
|
|
|
|
ns_min.disk = min_t(enum drbd_disk_state, ns.disk, ns_min.disk);
|
|
|
|
ns_min.pdsk = min_t(enum drbd_disk_state, ns.pdsk, ns_min.pdsk);
|
2011-03-25 05:02:20 -06:00
|
|
|
}
|
2011-04-11 23:53:32 -06:00
|
|
|
rcu_read_unlock();
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-07-18 02:44:24 -06:00
|
|
|
if (number_of_volumes == 0) {
|
|
|
|
ns_min = ns_max = (union drbd_state) { {
|
|
|
|
.role = R_SECONDARY,
|
|
|
|
.peer = R_UNKNOWN,
|
|
|
|
.conn = val.conn,
|
|
|
|
.disk = D_DISKLESS,
|
|
|
|
.pdsk = D_UNKNOWN
|
|
|
|
} };
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:19:44 -06:00
|
|
|
ns_min.susp = ns_max.susp = connection->resource->susp;
|
|
|
|
ns_min.susp_nod = ns_max.susp_nod = connection->resource->susp_nod;
|
|
|
|
ns_min.susp_fen = ns_max.susp_fen = connection->resource->susp_fen;
|
2011-03-29 06:01:02 -06:00
|
|
|
|
|
|
|
*pns_min = ns_min;
|
|
|
|
*pns_max = ns_max;
|
2011-02-10 05:45:46 -07:00
|
|
|
}
|
|
|
|
|
2011-02-15 03:14:44 -07:00
|
|
|
static enum drbd_state_rv
|
2011-05-30 08:32:41 -06:00
|
|
|
_conn_rq_cond(struct drbd_connection *connection, union drbd_state mask, union drbd_state val)
|
2011-02-15 03:14:44 -07:00
|
|
|
{
|
2014-04-28 10:43:20 -06:00
|
|
|
enum drbd_state_rv err, rv = SS_UNKNOWN_ERROR; /* continue waiting */;
|
2011-02-15 03:14:44 -07:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
if (test_and_clear_bit(CONN_WD_ST_CHG_OKAY, &connection->flags))
|
2014-04-28 10:43:20 -06:00
|
|
|
rv = SS_CW_SUCCESS;
|
2011-02-15 03:14:44 -07:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &connection->flags))
|
2014-04-28 10:43:20 -06:00
|
|
|
rv = SS_CW_FAILED_BY_PEER;
|
2011-02-15 03:14:44 -07:00
|
|
|
|
2014-04-28 10:43:20 -06:00
|
|
|
err = conn_is_valid_transition(connection, mask, val, 0);
|
|
|
|
if (err == SS_SUCCESS && connection->cstate == C_WF_REPORT_PARAMS)
|
|
|
|
return rv;
|
2011-02-15 03:14:44 -07:00
|
|
|
|
2014-04-28 10:43:20 -06:00
|
|
|
return err;
|
2011-02-15 03:14:44 -07:00
|
|
|
}
|
|
|
|
|
2011-02-10 05:45:46 -07:00
|
|
|
enum drbd_state_rv
|
2011-05-30 08:32:41 -06:00
|
|
|
_conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
|
2011-02-10 05:45:46 -07:00
|
|
|
enum chg_state_flags flags)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv = SS_SUCCESS;
|
|
|
|
struct after_conn_state_chg_work *acscw;
|
2011-05-30 08:32:41 -06:00
|
|
|
enum drbd_conns oc = connection->cstate;
|
2011-03-29 06:01:02 -06:00
|
|
|
union drbd_state ns_max, ns_min, os;
|
2012-08-22 08:15:26 -06:00
|
|
|
bool have_mutex = false;
|
2014-07-31 09:41:33 -06:00
|
|
|
struct drbd_state_change *state_change;
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2012-08-28 03:07:56 -06:00
|
|
|
if (mask.conn) {
|
|
|
|
rv = is_valid_conn_transition(oc, val.conn);
|
|
|
|
if (rv < SS_SUCCESS)
|
|
|
|
goto abort;
|
|
|
|
}
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
rv = conn_is_valid_transition(connection, mask, val, flags);
|
2011-02-10 05:45:46 -07:00
|
|
|
if (rv < SS_SUCCESS)
|
|
|
|
goto abort;
|
|
|
|
|
2011-02-15 03:14:44 -07:00
|
|
|
if (oc == C_WF_REPORT_PARAMS && val.conn == C_DISCONNECTING &&
|
|
|
|
!(flags & (CS_LOCAL_ONLY | CS_HARD))) {
|
2012-08-22 08:15:26 -06:00
|
|
|
|
|
|
|
/* This will be a cluster-wide state change.
|
|
|
|
* Need to give up the spinlock, grab the mutex,
|
|
|
|
* then send the state change request, ... */
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
mutex_lock(&connection->cstate_mutex);
|
2012-08-22 08:15:26 -06:00
|
|
|
have_mutex = true;
|
|
|
|
|
2011-05-30 08:32:41 -06:00
|
|
|
set_bit(CONN_WD_ST_CHG_REQ, &connection->flags);
|
|
|
|
if (conn_send_state_req(connection, mask, val)) {
|
2012-08-22 08:15:26 -06:00
|
|
|
/* sending failed. */
|
2011-05-30 08:32:41 -06:00
|
|
|
clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags);
|
2012-08-22 08:15:26 -06:00
|
|
|
rv = SS_CW_FAILED_BY_PEER;
|
|
|
|
/* need to re-aquire the spin lock, though */
|
|
|
|
goto abort_unlocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val.conn == C_DISCONNECTING)
|
2011-05-30 08:32:41 -06:00
|
|
|
set_bit(DISCONNECT_SENT, &connection->flags);
|
2012-08-22 08:15:26 -06:00
|
|
|
|
|
|
|
/* ... and re-aquire the spinlock.
|
|
|
|
* If _conn_rq_cond() returned >= SS_SUCCESS, we must call
|
|
|
|
* conn_set_state() within the same spinlock. */
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
wait_event_lock_irq(connection->ping_wait,
|
|
|
|
(rv = _conn_rq_cond(connection, mask, val)),
|
2011-07-07 06:19:42 -06:00
|
|
|
connection->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
clear_bit(CONN_WD_ST_CHG_REQ, &connection->flags);
|
2011-02-15 03:14:44 -07:00
|
|
|
if (rv < SS_SUCCESS)
|
|
|
|
goto abort;
|
|
|
|
}
|
|
|
|
|
2014-07-31 09:41:33 -06:00
|
|
|
state_change = remember_old_state(connection->resource, GFP_ATOMIC);
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_old_common_state(connection, &os, &flags);
|
2011-03-29 07:20:27 -06:00
|
|
|
flags |= CS_DC_SUSP;
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_set_state(connection, mask, val, &ns_min, &ns_max, flags);
|
|
|
|
conn_pr_state_change(connection, os, ns_max, flags);
|
2014-07-31 09:41:33 -06:00
|
|
|
remember_new_state(state_change);
|
2011-02-10 05:45:46 -07:00
|
|
|
|
|
|
|
acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC);
|
|
|
|
if (acscw) {
|
2011-03-25 08:11:30 -06:00
|
|
|
acscw->oc = os.conn;
|
2011-03-29 06:01:02 -06:00
|
|
|
acscw->ns_min = ns_min;
|
2011-03-29 05:20:58 -06:00
|
|
|
acscw->ns_max = ns_max;
|
2011-02-10 05:45:46 -07:00
|
|
|
acscw->flags = flags;
|
2011-08-25 07:14:48 -06:00
|
|
|
acscw->w.cb = w_after_conn_state_ch;
|
2011-05-30 08:32:41 -06:00
|
|
|
kref_get(&connection->kref);
|
2011-07-28 07:27:51 -06:00
|
|
|
acscw->connection = connection;
|
2014-07-31 09:41:33 -06:00
|
|
|
acscw->state_change = state_change;
|
2011-08-25 07:14:48 -06:00
|
|
|
drbd_queue_work(&connection->sender_work, &acscw->w);
|
2011-02-10 05:45:46 -07:00
|
|
|
} else {
|
2011-07-06 03:01:44 -06:00
|
|
|
drbd_err(connection, "Could not kmalloc an acscw\n");
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|
2011-02-10 05:45:46 -07:00
|
|
|
|
2011-12-13 09:40:53 -07:00
|
|
|
abort:
|
2012-08-22 08:15:26 -06:00
|
|
|
if (have_mutex) {
|
|
|
|
/* mutex_unlock() "... must not be used in interrupt context.",
|
|
|
|
* so give up the spinlock, then re-aquire it */
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2012-08-22 08:15:26 -06:00
|
|
|
abort_unlocked:
|
2011-05-30 08:32:41 -06:00
|
|
|
mutex_unlock(&connection->cstate_mutex);
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2012-08-22 08:15:26 -06:00
|
|
|
}
|
|
|
|
if (rv < SS_SUCCESS && flags & CS_VERBOSE) {
|
2011-07-06 03:01:44 -06:00
|
|
|
drbd_err(connection, "State change failed: %s\n", drbd_set_st_err_str(rv));
|
|
|
|
drbd_err(connection, " mask = 0x%x val = 0x%x\n", mask.i, val.i);
|
|
|
|
drbd_err(connection, " old_conn:%s wanted_conn:%s\n", drbd_conn_str(oc), drbd_conn_str(val.conn));
|
2011-12-13 09:40:53 -07:00
|
|
|
}
|
2011-02-10 05:45:46 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum drbd_state_rv
|
2011-05-30 08:32:41 -06:00
|
|
|
conn_request_state(struct drbd_connection *connection, union drbd_state mask, union drbd_state val,
|
2011-02-10 05:45:46 -07:00
|
|
|
enum chg_state_flags flags)
|
|
|
|
{
|
|
|
|
enum drbd_state_rv rv;
|
|
|
|
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_lock_irq(&connection->resource->req_lock);
|
2011-05-30 08:32:41 -06:00
|
|
|
rv = _conn_request_state(connection, mask, val, flags);
|
2011-07-07 06:19:42 -06:00
|
|
|
spin_unlock_irq(&connection->resource->req_lock);
|
2011-02-10 05:45:46 -07:00
|
|
|
|
|
|
|
return rv;
|
2011-01-27 06:07:51 -07:00
|
|
|
}
|