Skip to content

Commit

Permalink
target: allow userspace to set state to transitioning
Browse files Browse the repository at this point in the history
Userspace target_core_user handlers like tcmu-runner may want to set the
ALUA state to transitioning while it does implicit transitions. This
patch allows that state when set from configfs.

Signed-off-by: Mike Christie <[email protected]>
Signed-off-by: Nicholas Bellinger <[email protected]>
  • Loading branch information
Mike Christie authored and Nicholas Bellinger committed Mar 18, 2017
1 parent d717537 commit 1ca4d4f
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions drivers/target/target_core_alua.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "target_core_ua.h"

static sense_reason_t core_alua_check_transition(int state, int valid,
int *primary);
int *primary, int explicit);
static int core_alua_set_tg_pt_secondary_state(
struct se_lun *lun, int explicit, int offline);

Expand Down Expand Up @@ -335,8 +335,8 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
* the state is a primary or secondary target port asymmetric
* access state.
*/
rc = core_alua_check_transition(alua_access_state,
valid_states, &primary);
rc = core_alua_check_transition(alua_access_state, valid_states,
&primary, 1);
if (rc) {
/*
* If the SET TARGET PORT GROUPS attempts to establish
Expand Down Expand Up @@ -762,7 +762,7 @@ target_alua_state_check(struct se_cmd *cmd)
* Check implicit and explicit ALUA state change request.
*/
static sense_reason_t
core_alua_check_transition(int state, int valid, int *primary)
core_alua_check_transition(int state, int valid, int *primary, int explicit)
{
/*
* OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
Expand Down Expand Up @@ -804,11 +804,14 @@ core_alua_check_transition(int state, int valid, int *primary)
*primary = 0;
break;
case ALUA_ACCESS_STATE_TRANSITION:
/*
* Transitioning is set internally, and
* cannot be selected manually.
*/
goto not_supported;
if (!(valid & ALUA_T_SUP) || explicit)
/*
* Transitioning is set internally and by tcmu daemon,
* and cannot be selected through a STPG.
*/
goto not_supported;
*primary = 0;
break;
default:
pr_err("Unknown ALUA access state: 0x%02x\n", state);
return TCM_INVALID_PARAMETER_LIST;
Expand Down Expand Up @@ -1070,7 +1073,7 @@ static int core_alua_do_transition_tg_pt(
if (atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state) == new_state)
return 0;

if (new_state == ALUA_ACCESS_STATE_TRANSITION)
if (explicit && new_state == ALUA_ACCESS_STATE_TRANSITION)
return -EAGAIN;

/*
Expand All @@ -1091,10 +1094,6 @@ static int core_alua_do_transition_tg_pt(
* Save the old primary ALUA access state, and set the current state
* to ALUA_ACCESS_STATE_TRANSITION.
*/
tg_pt_gp->tg_pt_gp_alua_previous_state =
atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state);
tg_pt_gp->tg_pt_gp_alua_pending_state = new_state;

atomic_set(&tg_pt_gp->tg_pt_gp_alua_access_state,
ALUA_ACCESS_STATE_TRANSITION);
tg_pt_gp->tg_pt_gp_alua_access_status = (explicit) ?
Expand All @@ -1103,6 +1102,13 @@ static int core_alua_do_transition_tg_pt(

core_alua_queue_state_change_ua(tg_pt_gp);

if (new_state == ALUA_ACCESS_STATE_TRANSITION)
return 0;

tg_pt_gp->tg_pt_gp_alua_previous_state =
atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state);
tg_pt_gp->tg_pt_gp_alua_pending_state = new_state;

/*
* Check for the optional ALUA primary state transition delay
*/
Expand Down Expand Up @@ -1144,7 +1150,8 @@ int core_alua_do_port_transition(
return -ENODEV;

valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states;
if (core_alua_check_transition(new_state, valid_states, &primary) != 0)
if (core_alua_check_transition(new_state, valid_states, &primary,
explicit) != 0)
return -EINVAL;

local_lu_gp_mem = l_dev->dev_alua_lu_gp_mem;
Expand Down

0 comments on commit 1ca4d4f

Please sign in to comment.