mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-17 22:05:08 +00:00
drbd: Use the idr_for_each_entry() iterator instead of idr_for_each()
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
This commit is contained in:
parent
4a76b1612f
commit
bd0c824a9d
@ -1378,9 +1378,6 @@ static void print_conn_state_change(struct drbd_tconn *tconn, enum drbd_conns oc
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct _is_valid_itr_params {
|
struct _is_valid_itr_params {
|
||||||
enum chg_state_flags flags;
|
|
||||||
union drbd_state mask, val;
|
|
||||||
union drbd_state ms; /* maximal state, over all mdevs */
|
|
||||||
enum drbd_conns oc;
|
enum drbd_conns oc;
|
||||||
enum {
|
enum {
|
||||||
OC_UNINITIALIZED,
|
OC_UNINITIALIZED,
|
||||||
@ -1389,69 +1386,86 @@ struct _is_valid_itr_params {
|
|||||||
} oc_state;
|
} oc_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int _is_valid_itr_fn(int vnr, void *p, void *data)
|
static enum drbd_state_rv
|
||||||
|
conn_is_valid_transition(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
|
||||||
|
enum chg_state_flags flags, struct _is_valid_itr_params *params)
|
||||||
{
|
{
|
||||||
struct drbd_conf *mdev = (struct drbd_conf *)p;
|
enum drbd_state_rv rv = SS_SUCCESS;
|
||||||
struct _is_valid_itr_params *params = (struct _is_valid_itr_params *)data;
|
|
||||||
enum chg_state_flags flags = params->flags;
|
|
||||||
union drbd_state ns, os;
|
union drbd_state ns, os;
|
||||||
enum drbd_state_rv rv;
|
struct drbd_conf *mdev;
|
||||||
|
int vnr;
|
||||||
|
|
||||||
os = mdev->state;
|
params->oc_state = OC_UNINITIALIZED;
|
||||||
ns = apply_mask_val(os, params->mask, params->val);
|
idr_for_each_entry(&tconn->volumes, mdev, vnr) {
|
||||||
ns = sanitize_state(mdev, ns, NULL);
|
os = mdev->state;
|
||||||
rv = is_valid_state(mdev, ns);
|
ns = sanitize_state(mdev, apply_mask_val(os, mask, val), NULL);
|
||||||
|
|
||||||
if (rv < SS_SUCCESS) {
|
switch (params->oc_state) {
|
||||||
/* If the old state was illegal as well, then let this happen...*/
|
case OC_UNINITIALIZED:
|
||||||
|
params->oc = os.conn;
|
||||||
|
params->oc_state = OC_CONSISTENT;
|
||||||
|
break;
|
||||||
|
case OC_CONSISTENT:
|
||||||
|
if (params->oc != os.conn)
|
||||||
|
params->oc_state = OC_INCONSISTENT;
|
||||||
|
break;
|
||||||
|
case OC_INCONSISTENT:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_valid_state(mdev, os) == rv)
|
if (ns.i == os.i)
|
||||||
rv = is_valid_soft_transition(os, ns);
|
continue;
|
||||||
} else
|
|
||||||
rv = is_valid_soft_transition(os, ns);
|
|
||||||
|
|
||||||
switch (params->oc_state) {
|
rv = is_valid_transition(os, ns);
|
||||||
case OC_UNINITIALIZED:
|
if (rv < SS_SUCCESS)
|
||||||
params->oc = os.conn;
|
break;
|
||||||
params->oc_state = OC_CONSISTENT;
|
|
||||||
break;
|
if (!(flags & CS_HARD)) {
|
||||||
case OC_CONSISTENT:
|
rv = is_valid_state(mdev, ns);
|
||||||
if (params->oc != os.conn)
|
if (rv < SS_SUCCESS) {
|
||||||
params->oc_state = OC_INCONSISTENT;
|
if (is_valid_state(mdev, os) == rv)
|
||||||
break;
|
rv = is_valid_soft_transition(os, ns);
|
||||||
case OC_INCONSISTENT:
|
} else
|
||||||
break;
|
rv = is_valid_soft_transition(os, ns);
|
||||||
|
}
|
||||||
|
if (rv < SS_SUCCESS)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv < SS_SUCCESS) {
|
if (rv < SS_SUCCESS && flags & CS_VERBOSE)
|
||||||
if (flags & CS_VERBOSE)
|
print_st_err(mdev, os, ns, rv);
|
||||||
print_st_err(mdev, os, ns, rv);
|
|
||||||
return rv;
|
return rv;
|
||||||
} else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _set_state_itr_fn(int vnr, void *p, void *data)
|
static union drbd_state
|
||||||
|
conn_set_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state val,
|
||||||
|
enum chg_state_flags flags)
|
||||||
{
|
{
|
||||||
struct drbd_conf *mdev = (struct drbd_conf *)p;
|
union drbd_state ns, os, ms = { };
|
||||||
struct _is_valid_itr_params *params = (struct _is_valid_itr_params *)data;
|
struct drbd_conf *mdev;
|
||||||
enum chg_state_flags flags = params->flags;
|
|
||||||
union drbd_state os, ns, ms = params->ms;
|
|
||||||
enum drbd_state_rv rv;
|
enum drbd_state_rv rv;
|
||||||
|
int vnr;
|
||||||
|
|
||||||
os = mdev->state;
|
if (mask.conn == C_MASK)
|
||||||
ns = apply_mask_val(os, params->mask, params->val);
|
tconn->cstate = val.conn;
|
||||||
ns = sanitize_state(mdev, ns, NULL);
|
|
||||||
|
|
||||||
rv = __drbd_set_state(mdev, ns, flags, NULL);
|
idr_for_each_entry(&tconn->volumes, mdev, vnr) {
|
||||||
|
os = mdev->state;
|
||||||
|
ns = apply_mask_val(os, mask, val);
|
||||||
|
ns = sanitize_state(mdev, ns, NULL);
|
||||||
|
|
||||||
ms.role = max_role(ns.role, ms.role);
|
rv = __drbd_set_state(mdev, ns, flags, NULL);
|
||||||
ms.peer = max_role(ns.peer, ms.peer);
|
if (rv < SS_SUCCESS)
|
||||||
ms.disk = max_t(enum drbd_role, mdev->state.disk, ms.disk);
|
BUG();
|
||||||
ms.pdsk = max_t(enum drbd_role, mdev->state.pdsk, ms.pdsk);
|
|
||||||
params->ms = ms;
|
|
||||||
|
|
||||||
return 0;
|
ms.role = max_role(mdev->state.role, ms.role);
|
||||||
|
ms.peer = max_role(mdev->state.peer, ms.peer);
|
||||||
|
ms.disk = max_t(enum drbd_disk_state, mdev->state.disk, ms.disk);
|
||||||
|
ms.pdsk = max_t(enum drbd_disk_state, mdev->state.pdsk, ms.pdsk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum drbd_state_rv
|
static enum drbd_state_rv
|
||||||
@ -1466,18 +1480,14 @@ _conn_rq_cond(struct drbd_tconn *tconn, union drbd_state mask, union drbd_state
|
|||||||
if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags))
|
if (test_and_clear_bit(CONN_WD_ST_CHG_FAIL, &tconn->flags))
|
||||||
return SS_CW_FAILED_BY_PEER;
|
return SS_CW_FAILED_BY_PEER;
|
||||||
|
|
||||||
params.flags = CS_NO_CSTATE_CHG; /* öö think */
|
|
||||||
params.mask = mask;
|
|
||||||
params.val = val;
|
|
||||||
|
|
||||||
spin_lock_irq(&tconn->req_lock);
|
spin_lock_irq(&tconn->req_lock);
|
||||||
rv = tconn->cstate != C_WF_REPORT_PARAMS ? SS_CW_NO_NEED : SS_UNKNOWN_ERROR;
|
rv = tconn->cstate != C_WF_REPORT_PARAMS ? SS_CW_NO_NEED : SS_UNKNOWN_ERROR;
|
||||||
|
|
||||||
if (rv == SS_UNKNOWN_ERROR)
|
if (rv == SS_UNKNOWN_ERROR)
|
||||||
rv = idr_for_each(&tconn->volumes, _is_valid_itr_fn, ¶ms);
|
rv = conn_is_valid_transition(tconn, mask, val, CS_NO_CSTATE_CHG, ¶ms);
|
||||||
|
|
||||||
if (rv == 0) /* idr_for_each semantics */
|
if (rv == SS_SUCCESS)
|
||||||
rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
|
rv = SS_UNKNOWN_ERROR; /* cont waiting, otherwise fail. */
|
||||||
|
|
||||||
spin_unlock_irq(&tconn->req_lock);
|
spin_unlock_irq(&tconn->req_lock);
|
||||||
|
|
||||||
@ -1517,22 +1527,13 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_
|
|||||||
struct _is_valid_itr_params params;
|
struct _is_valid_itr_params params;
|
||||||
struct after_conn_state_chg_work *acscw;
|
struct after_conn_state_chg_work *acscw;
|
||||||
enum drbd_conns oc = tconn->cstate;
|
enum drbd_conns oc = tconn->cstate;
|
||||||
|
union drbd_state ms;
|
||||||
|
|
||||||
rv = is_valid_conn_transition(oc, val.conn);
|
rv = is_valid_conn_transition(oc, val.conn);
|
||||||
if (rv < SS_SUCCESS)
|
if (rv < SS_SUCCESS)
|
||||||
goto abort;
|
goto abort;
|
||||||
|
|
||||||
params.flags = flags;
|
rv = conn_is_valid_transition(tconn, mask, val, flags, ¶ms);
|
||||||
params.mask = mask;
|
|
||||||
params.val = val;
|
|
||||||
params.oc_state = OC_UNINITIALIZED;
|
|
||||||
|
|
||||||
if (!(flags & CS_HARD))
|
|
||||||
rv = idr_for_each(&tconn->volumes, _is_valid_itr_fn, ¶ms);
|
|
||||||
|
|
||||||
if (rv == 0) /* idr_for_each semantics */
|
|
||||||
rv = SS_SUCCESS;
|
|
||||||
|
|
||||||
if (rv < SS_SUCCESS)
|
if (rv < SS_SUCCESS)
|
||||||
goto abort;
|
goto abort;
|
||||||
|
|
||||||
@ -1546,17 +1547,16 @@ _conn_request_state(struct drbd_tconn *tconn, union drbd_state mask, union drbd_
|
|||||||
if (params.oc_state == OC_CONSISTENT) {
|
if (params.oc_state == OC_CONSISTENT) {
|
||||||
oc = params.oc;
|
oc = params.oc;
|
||||||
print_conn_state_change(tconn, oc, val.conn);
|
print_conn_state_change(tconn, oc, val.conn);
|
||||||
params.flags |= CS_NO_CSTATE_CHG;
|
flags |= CS_NO_CSTATE_CHG;
|
||||||
}
|
}
|
||||||
tconn->cstate = val.conn;
|
|
||||||
params.ms.i = 0;
|
ms = conn_set_state(tconn, mask, val, flags);
|
||||||
params.ms.conn = val.conn;
|
ms.conn = val.conn;
|
||||||
idr_for_each(&tconn->volumes, _set_state_itr_fn, ¶ms);
|
|
||||||
|
|
||||||
acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC);
|
acscw = kmalloc(sizeof(*acscw), GFP_ATOMIC);
|
||||||
if (acscw) {
|
if (acscw) {
|
||||||
acscw->oc = oc;
|
acscw->oc = oc;
|
||||||
acscw->nms = params.ms;
|
acscw->nms = ms;
|
||||||
acscw->flags = flags;
|
acscw->flags = flags;
|
||||||
acscw->w.cb = w_after_conn_state_ch;
|
acscw->w.cb = w_after_conn_state_ch;
|
||||||
acscw->w.tconn = tconn;
|
acscw->w.tconn = tconn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user