/* 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;
/* Unfortunately the states where not correctly ordered, when
they where defined. therefore can not use max_t() here. */ staticenum 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;
}
/** * drbd_force_state() - Impose a change which happens outside our control on our state * @device: DRBD device. * @mask: mask of state bits to change. * @val: value of new state bits.
*/ void drbd_force_state(struct drbd_device *device, union drbd_state mask, union drbd_state val)
{
drbd_change_state(device, CS_HARD, mask, val);
}
staticenum drbd_state_rv
_req_st_cond(struct drbd_device *device, union drbd_state mask, union drbd_state val)
{ union drbd_state os, ns; unsignedlong flags; enum drbd_state_rv rv;
if (test_and_clear_bit(CL_ST_CHG_SUCCESS, &device->flags)) return SS_CW_SUCCESS;
if (test_and_clear_bit(CL_ST_CHG_FAIL, &device->flags)) return SS_CW_FAILED_BY_PEER;
/** * drbd_req_state() - Perform an eventually cluster wide state change * @device: DRBD device. * @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().
*/ staticenum drbd_state_rv
drbd_req_state(struct drbd_device *device, union drbd_state mask, union drbd_state val, enum chg_state_flags f)
{ struct completion done; unsignedlong flags; union drbd_state os, ns; enum drbd_state_rv rv; void *buffer = NULL;
init_completion(&done);
if (f & CS_SERIALIZE)
mutex_lock(device->state_mutex); if (f & CS_INHIBIT_MD_IO)
buffer = drbd_md_get_buffer(device, __func__);
if (f & CS_WAIT_COMPLETE && rv == SS_SUCCESS) {
D_ASSERT(device, current != first_peer_device(device)->connection->worker.task);
wait_for_completion(&done);
}
abort: if (buffer)
drbd_md_put_buffer(device); if (f & CS_SERIALIZE)
mutex_unlock(device->state_mutex);
return rv;
}
/** * _drbd_request_state() - Request a state change (with flags) * @device: DRBD device. * @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
_drbd_request_state(struct drbd_device *device, union drbd_state mask, union drbd_state val, enum chg_state_flags f)
{ enum drbd_state_rv rv;
/* * 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.
*/ staticenum 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);
}
int drbd_request_detach_interruptible(struct drbd_device *device)
{ int ret, rv;
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;
}
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;
if (pbp != pb)
drbd_info(connection, "%s\n", pb);
}
/** * is_valid_state() - Returns an SS_ error code if ns is not valid * @device: DRBD device. * @ns: State to consider.
*/ staticenum drbd_state_rv
is_valid_state(struct drbd_device *device, union drbd_state ns)
{ /* See drbd_state_sw_errors in drbd_strings.c */
/** * is_valid_soft_transition() - Returns an SS_ error code if the state transition is not possible * This function limits state transitions that may be declined by DRBD. I.e. * user requests (aka soft transitions). * @os: old state. * @ns: new state. * @connection: DRBD connection.
*/ staticenum drbd_state_rv
is_valid_soft_transition(union drbd_state os, union drbd_state ns, struct drbd_connection *connection)
{ enum drbd_state_rv rv = SS_SUCCESS;
/* While establishing a connection only allow cstate to change.
Delay/refuse role changes, detach attach etc... (they do not touch cstate) */ if (test_bit(STATE_SENT, &connection->flags) &&
!((ns.conn == C_WF_REPORT_PARAMS && os.conn == C_WF_CONNECTION) ||
(ns.conn >= C_CONNECTED && os.conn == C_WF_REPORT_PARAMS)))
rv = SS_IN_TRANSIENT_STATE;
/* 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;
staticenum drbd_state_rv
is_valid_conn_transition(enum drbd_conns oc, enum drbd_conns nc)
{ /* no change -> nothing to do, at least for the connection part */ if (oc == nc) return SS_NOTHING_TO_DO;
/* 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;
/* 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;
/* After a network error only C_UNCONNECTED or C_DISCONNECTING may follow. */ if (oc >= C_TIMEOUT && oc <= C_TEAR_DOWN && nc != C_UNCONNECTED && nc != C_DISCONNECTING) return SS_IN_TRANSIENT_STATE;
/* After C_DISCONNECTING only C_STANDALONE may follow */ if (oc == C_DISCONNECTING && nc != C_STANDALONE) return SS_IN_TRANSIENT_STATE;
return SS_SUCCESS;
}
/** * 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.
*/ staticenum 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);
/* we cannot fail (again) if we already detached */ if (ns.disk == D_FAILED && os.disk == D_DISKLESS)
rv = SS_IS_DISKLESS;
if (warn != NO_WARNING)
drbd_warn(device, "%s\n", msg_table[warn]);
}
/** * sanitize_state() - Resolves implicitly necessary additional changes to a state transition * @device: DRBD device. * @os: old state. * @ns: new state. * @warn: placeholder for returned state warning. * * 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.
*/ staticunion drbd_state sanitize_state(struct drbd_device *device, union drbd_state os, union drbd_state ns, enum sanitize_state_warnings *warn)
{ enum drbd_fencing_p fp; enum drbd_disk_state disk_min, disk_max, pdsk_min, pdsk_max;
/* Implications from connection to peer and peer_isp */ 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;
/* An implication of the disk states onto the connection state */ /* Abort resync if a disk fails/detaches */ if (ns.conn > C_CONNECTED && (ns.disk <= D_FAILED || ns.pdsk <= D_FAILED)) { if (warn)
*warn = ns.conn == C_VERIFY_S || ns.conn == C_VERIFY_T ?
ABORTED_ONLINE_VERIFY : ABORTED_RESYNC;
ns.conn = C_CONNECTED;
}
/* Connection breaks down before we finished "Negotiating" */ if (ns.conn < C_CONNECTED && ns.disk == D_NEGOTIATING &&
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;
} else { if (warn)
*warn = CONNECTION_LOST_NEGOTIATING;
ns.disk = D_DISKLESS;
ns.pdsk = D_UNKNOWN;
}
put_ldev(device);
}
/* 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 state 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) { if (warn)
*warn = IMPLICITLY_UPGRADED_DISK;
ns.disk = disk_min;
} if (ns.pdsk > pdsk_max)
ns.pdsk = pdsk_max;
if (ns.pdsk < pdsk_min) { if (warn)
*warn = IMPLICITLY_UPGRADED_PDSK;
ns.pdsk = pdsk_min;
}
if (peer_device->connection->agreed_pro_version < 90)
device->ov_start_sector = 0;
device->rs_total = drbd_bm_bits(device);
device->ov_position = 0; 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 */
device->ov_start_sector = ~(sector_t)0;
} else { unsignedlong 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;
} else
device->rs_total -= bit;
device->ov_position = device->ov_start_sector;
}
device->ov_left = device->rs_total;
}
/** * _drbd_set_state() - Set a new DRBD state * @device: DRBD device. * @ns: new state. * @flags: Flags * @done: Optional completion, that will get completed after the after_state_ch() finished * * Caller needs to hold req_lock. Do not call directly.
*/ enum drbd_state_rv
_drbd_set_state(struct drbd_device *device, union drbd_state ns, enum chg_state_flags flags, struct completion *done)
{ struct drbd_peer_device *peer_device = first_peer_device(device); struct drbd_connection *connection = peer_device ? peer_device->connection : NULL; union drbd_state os; enum drbd_state_rv rv = SS_SUCCESS; enum sanitize_state_warnings ssw; struct after_state_chg_work *ascw; struct drbd_state_change *state_change;
if (rv < SS_SUCCESS) { if (flags & CS_VERBOSE)
print_st_err(device, os, ns, rv); return rv;
}
print_sanitize_warnings(device, ssw);
drbd_pr_state_change(device, os, ns, flags);
/* 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))
conn_pr_state_change(connection, os, ns,
(flags & ~CS_DC_MASK) | CS_DC_SUSP);
/* 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))
atomic_inc(&device->local_cnt);
if (!is_sync_state(os.conn) && is_sync_state(ns.conn))
clear_bit(RS_DONE, &device->flags);
/* FIXME: Have any flags been set earlier in this function already? */
state_change = remember_old_state(device->resource, GFP_ATOMIC);
/* 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();
device->state.i = ns.i;
device->resource->susp = ns.susp;
device->resource->susp_nod = ns.susp_nod;
device->resource->susp_fen = ns.susp_fen;
smp_wmb();
remember_new_state(state_change);
/* put replicated vs not-replicated requests in seperate epochs */ if (drbd_should_do_remote((union drbd_dev_state)os.i) !=
drbd_should_do_remote((union drbd_dev_state)ns.i))
start_new_tl_epoch(connection);
if (os.disk == D_ATTACHING && ns.disk >= D_NEGOTIATING)
drbd_print_uuids(device, "attached to UUIDs");
/* Wake up role changes, that were delayed because of connection establishing */ if (os.conn == C_WF_REPORT_PARAMS && ns.conn != C_WF_REPORT_PARAMS &&
no_peer_wf_report_params(connection)) {
clear_bit(STATE_SENT, &connection->flags);
wake_up_all_devices(connection);
}
mdf &= ~MDF_AL_CLEAN; if (test_bit(CRASHED_PRIMARY, &device->flags))
mdf |= MDF_CRASHED_PRIMARY; if (device->state.role == R_PRIMARY ||
(device->state.pdsk < D_INCONSISTENT && device->state.peer == R_PRIMARY))
mdf |= MDF_PRIMARY_IND; if (device->state.conn > C_WF_REPORT_PARAMS)
mdf |= MDF_CONNECTED_IND; if (device->state.disk > D_INCONSISTENT)
mdf |= MDF_CONSISTENT; if (device->state.disk > D_OUTDATED)
mdf |= MDF_WAS_UP_TO_DATE; if (device->state.pdsk <= D_OUTDATED && device->state.pdsk >= D_INCONSISTENT)
mdf |= MDF_PEER_OUT_DATED; if (mdf != device->ldev->md.flags) {
device->ldev->md.flags = mdf;
drbd_md_mark_dirty(device);
} if (os.disk < D_CONSISTENT && ns.disk >= D_CONSISTENT)
drbd_set_ed_uuid(device, device->ldev->md.uuid[UI_CURRENT]);
put_ldev(device);
}
/* 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)
set_bit(CONSIDER_RESYNC, &device->flags);
/* Receiver should clean up itself */ if (os.conn != C_DISCONNECTING && ns.conn == C_DISCONNECTING)
drbd_thread_stop_nowait(&connection->receiver);
/* Now the receiver finished cleaning up itself, it should die */ if (os.conn != C_STANDALONE && ns.conn == C_STANDALONE)
drbd_thread_stop_nowait(&connection->receiver);
/* Upon network failure, we need to restart the receiver. */ if (os.conn > C_WF_CONNECTION &&
ns.conn <= C_TEAR_DOWN && ns.conn >= C_TIMEOUT)
drbd_thread_restart_nowait(&connection->receiver);
/* Resume AL writing if we get a connection */ if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED) {
drbd_resume_al(device);
connection->connect_cnt++;
}
/* 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)
device->last_reattach_jif = jiffies;
if (ns.susp_fen) {
spin_lock_irq(&device->resource->req_lock); if (resource->susp_fen && conn_lowest_conn(connection) >= C_CONNECTED) { /* case2: The connection was established again: */ struct drbd_peer_device *peer_device; int vnr;
/* 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() ...
*/
_tl_restart(connection, RESEND);
_conn_request_state(connection,
(union drbd_state) { { .susp_fen = 1 } },
(union drbd_state) { { .susp_fen = 0 } },
CS_VERBOSE);
}
spin_unlock_irq(&device->resource->req_lock);
}
/* 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) &&
connection->agreed_pro_version >= 96 && get_ldev(device)) {
drbd_gen_and_send_sync_uuid(peer_device);
put_ldev(device);
}
/* Do not change the order of the if above and the two below... */ if (os.pdsk == D_DISKLESS &&
ns.pdsk > D_DISKLESS && ns.pdsk != D_UNKNOWN) { /* attach on the peer */ /* we probably will start a resync soon.
* make sure those things are properly reset. */
device->rs_total = 0;
device->rs_failed = 0;
atomic_set(&device->rs_pending_cnt, 0);
drbd_rs_cancel_all(device);
drbd_send_uuids(peer_device);
drbd_send_state(peer_device, ns);
} /* 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 &&
device->state.conn == C_WF_BITMAP_S)
drbd_queue_bitmap_io(device, &drbd_send_bitmap, NULL, "send_bitmap (WFBitMapS)",
BM_LOCKED_TEST_ALLOWED, peer_device);
/* Lost contact to peer's copy of the data */ if (lost_contact_to_peer_data(os.pdsk, ns.pdsk)) { if (get_ldev(device)) { if ((ns.role == R_PRIMARY || ns.peer == R_PRIMARY) &&
device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) { if (drbd_suspended(device)) {
set_bit(NEW_CUR_UUID, &device->flags);
} else {
drbd_uuid_new_current(device);
drbd_send_uuids(peer_device);
}
}
put_ldev(device);
}
}
if (ns.pdsk < D_INCONSISTENT && get_ldev(device)) { if (os.peer != R_PRIMARY && ns.peer == R_PRIMARY &&
device->ldev->md.uuid[UI_BITMAP] == 0 && ns.disk >= D_UP_TO_DATE) {
drbd_uuid_new_current(device);
drbd_send_uuids(peer_device);
} /* 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. */
drbd_bitmap_io_from_worker(device, &drbd_bm_write, "demote diskless peer", BM_LOCKED_SET_ALLOWED, peer_device);
put_ldev(device);
}
/* 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 &&
device->state.conn <= C_CONNECTED && get_ldev(device)) { /* No changes to the bitmap expected this time, so assert that,
* even though no harm was done if it did change. */
drbd_bitmap_io_from_worker(device, &drbd_bm_write, "demote", BM_LOCKED_TEST_ALLOWED, peer_device);
put_ldev(device);
}
/* Last part of the attaching process ... */ if (ns.conn >= C_CONNECTED &&
os.disk == D_ATTACHING && ns.disk == D_NEGOTIATING) {
drbd_send_sizes(peer_device, 0, 0); /* to start sync... */
drbd_send_uuids(peer_device);
drbd_send_state(peer_device, ns);
}
/* 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)))
drbd_send_state(peer_device, ns);
/* 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))
suspend_other_sg(device);
/* 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)
drbd_send_state(peer_device, ns);
if (os.conn != C_AHEAD && ns.conn == C_AHEAD)
drbd_send_state(peer_device, ns);
/* 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 */
drbd_queue_bitmap_io(device,
&drbd_bmio_set_n_write, &abw_start_sync, "set_n_write from StartingSync", BM_LOCKED_TEST_ALLOWED,
peer_device);
/* first half of local IO error, failure to attach,
* or administrative detach */ if (os.disk != D_FAILED && ns.disk == D_FAILED) { enum drbd_io_error_p eh = EP_PASS_ON; int was_io_error = 0; /* corresponding get_ldev was in _drbd_set_state, to serialize * 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. */ if (device->ldev) {
rcu_read_lock();
eh = rcu_dereference(device->ldev->disk_conf)->on_io_error;
rcu_read_unlock();
/* 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". */ if (was_io_error && eh == EP_CALL_HELPER)
drbd_khelper(device, "local-io-error");
/* 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.
*/ if (test_and_clear_bit(FORCE_DETACH, &device->flags))
tl_abort_disk_io(device);
/* 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. */ if (device->state.disk != D_FAILED)
drbd_err(device, "ASSERT FAILED: disk is %s during detach\n",
drbd_disk_str(device->state.disk));
if (ns.conn >= C_CONNECTED)
drbd_send_state(peer_device, ns);
drbd_rs_cancel_all(device);
/* 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. */
drbd_md_sync(device);
}
put_ldev(device);
}
/* 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)
drbd_err(device, "ASSERT FAILED: disk is %s while going diskless\n",
drbd_disk_str(device->state.disk));
if (ns.conn >= C_CONNECTED)
drbd_send_state(peer_device, ns); /* corresponding get_ldev in __drbd_set_state
* this may finally trigger drbd_ldev_destroy. */
put_ldev(device);
}
/* Notify peer that I had a local IO error, and did not detached.. */ if (os.disk == D_UP_TO_DATE && ns.disk == D_INCONSISTENT && ns.conn >= C_CONNECTED)
drbd_send_state(peer_device, ns);
/* Disks got bigger while they were detached */ if (ns.disk > D_NEGOTIATING && ns.pdsk > D_NEGOTIATING &&
test_and_clear_bit(RESYNC_AFTER_NEG, &device->flags)) { if (ns.conn == C_CONNECTED)
resync_after_online_grow(device);
}
/* 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))
resume_next_sg(device);
/* 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)
drbd_send_state(peer_device, ns);
/* 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
&& verify_can_do_stop_sector(device))
drbd_send_state(peer_device, ns);
/* This triggers bitmap writeout of potentially still unwritten pages * if the resync finished cleanly, or aborted because of peer disk * failure, or on transition from resync back to AHEAD/BEHIND. * * Connection loss is handled in drbd_disconnected() by the receiver. * * For resync aborted because of local disk failure, we cannot do * any bitmap writeout anymore. * * No harm done if some bits change during this phase.
*/ if ((os.conn > C_CONNECTED && os.conn < C_AHEAD) &&
(ns.conn == C_CONNECTED || ns.conn >= C_AHEAD) && get_ldev(device)) {
drbd_queue_bitmap_io(device, &drbd_bm_write_copy_pages, NULL, "write from resync_finished", BM_LOCKED_CHANGE_ALLOWED,
peer_device);
put_ldev(device);
}
if (ns.disk == D_DISKLESS &&
ns.conn == C_STANDALONE &&
ns.role == R_SECONDARY) { if (os.aftr_isp != ns.aftr_isp)
resume_next_sg(device);
}
drbd_md_sync(device);
}
struct after_conn_state_chg_work { struct drbd_work w; enum drbd_conns oc; union drbd_state ns_min; union drbd_state ns_max; /* new, max state, over all devices */ enum chg_state_flags flags; struct drbd_connection *connection; struct drbd_state_change *state_change;
};
/* Upon network configuration, we need to start the receiver */ if (oc == C_STANDALONE && ns_max.conn == C_UNCONNECTED)
drbd_thread_start(&connection->receiver);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.