Skip to content

Commit bb91c1a

Browse files
hreineckeNicholas Bellinger
authored andcommitted
target_core_alua: validate ALUA state transition
As we now can modify the list of supported states we need to validate the requested ALUA state when doing a state transition. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 340dbf7 commit bb91c1a

1 file changed

Lines changed: 45 additions & 10 deletions

File tree

‎drivers/target/target_core_alua.c‎

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@
4141
#include "target_core_alua.h"
4242
#include "target_core_ua.h"
4343

44-
static sense_reason_t core_alua_check_transition(int state, int *primary);
44+
static sense_reason_t core_alua_check_transition(int state, int valid,
45+
int *primary);
4546
static int core_alua_set_tg_pt_secondary_state(
4647
struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem,
4748
struct se_port *port, int explicit, int offline);
4849

50+
static char *core_alua_dump_state(int state);
51+
4952
static u16 alua_lu_gps_counter;
5053
static u32 alua_lu_gps_count;
5154

@@ -210,7 +213,7 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
210213
unsigned char *ptr;
211214
sense_reason_t rc = TCM_NO_SENSE;
212215
u32 len = 4; /* Skip over RESERVED area in header */
213-
int alua_access_state, primary = 0;
216+
int alua_access_state, primary = 0, valid_states;
214217
u16 tg_pt_id, rtpi;
215218

216219
if (!l_port)
@@ -252,6 +255,7 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
252255
rc = TCM_UNSUPPORTED_SCSI_OPCODE;
253256
goto out;
254257
}
258+
valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states;
255259

256260
ptr = &buf[4]; /* Skip over RESERVED area in header */
257261

@@ -263,7 +267,8 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
263267
* the state is a primary or secondary target port asymmetric
264268
* access state.
265269
*/
266-
rc = core_alua_check_transition(alua_access_state, &primary);
270+
rc = core_alua_check_transition(alua_access_state,
271+
valid_states, &primary);
267272
if (rc) {
268273
/*
269274
* If the SET TARGET PORT GROUPS attempts to establish
@@ -618,32 +623,59 @@ target_alua_state_check(struct se_cmd *cmd)
618623
* Check implicit and explicit ALUA state change request.
619624
*/
620625
static sense_reason_t
621-
core_alua_check_transition(int state, int *primary)
626+
core_alua_check_transition(int state, int valid, int *primary)
622627
{
628+
/*
629+
* OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
630+
* defined as primary target port asymmetric access states.
631+
*/
623632
switch (state) {
624633
case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED:
634+
if (!(valid & ALUA_AO_SUP))
635+
goto not_supported;
636+
*primary = 1;
637+
break;
625638
case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED:
639+
if (!(valid & ALUA_AN_SUP))
640+
goto not_supported;
641+
*primary = 1;
642+
break;
626643
case ALUA_ACCESS_STATE_STANDBY:
644+
if (!(valid & ALUA_S_SUP))
645+
goto not_supported;
646+
*primary = 1;
647+
break;
627648
case ALUA_ACCESS_STATE_UNAVAILABLE:
628-
/*
629-
* OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
630-
* defined as primary target port asymmetric access states.
631-
*/
649+
if (!(valid & ALUA_U_SUP))
650+
goto not_supported;
632651
*primary = 1;
633652
break;
634653
case ALUA_ACCESS_STATE_OFFLINE:
635654
/*
636655
* OFFLINE state is defined as a secondary target port
637656
* asymmetric access state.
638657
*/
658+
if (!(valid & ALUA_O_SUP))
659+
goto not_supported;
639660
*primary = 0;
640661
break;
662+
case ALUA_ACCESS_STATE_TRANSITION:
663+
/*
664+
* Transitioning is set internally, and
665+
* cannot be selected manually.
666+
*/
667+
goto not_supported;
641668
default:
642669
pr_err("Unknown ALUA access state: 0x%02x\n", state);
643670
return TCM_INVALID_PARAMETER_LIST;
644671
}
645672

646673
return 0;
674+
675+
not_supported:
676+
pr_err("ALUA access state %s not supported",
677+
core_alua_dump_state(state));
678+
return TCM_INVALID_PARAMETER_LIST;
647679
}
648680

649681
static char *core_alua_dump_state(int state)
@@ -659,6 +691,8 @@ static char *core_alua_dump_state(int state)
659691
return "Unavailable";
660692
case ALUA_ACCESS_STATE_OFFLINE:
661693
return "Offline";
694+
case ALUA_ACCESS_STATE_TRANSITION:
695+
return "Transitioning";
662696
default:
663697
return "Unknown";
664698
}
@@ -884,9 +918,10 @@ int core_alua_do_port_transition(
884918
struct t10_alua_lu_gp_member *lu_gp_mem, *local_lu_gp_mem;
885919
struct t10_alua_tg_pt_gp *tg_pt_gp;
886920
unsigned char *md_buf;
887-
int primary;
921+
int primary, valid_states;
888922

889-
if (core_alua_check_transition(new_state, &primary) != 0)
923+
valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states;
924+
if (core_alua_check_transition(new_state, valid_states, &primary) != 0)
890925
return -EINVAL;
891926

892927
md_buf = kzalloc(l_tg_pt_gp->tg_pt_gp_md_buf_len, GFP_KERNEL);

0 commit comments

Comments
 (0)