1 /*******************************************************************************
2 * Filename: target_core_alua.c
4 * This file contains SPC-3 compliant asymmetric logical unit assigntment (ALUA)
6 * (c) Copyright 2009-2012 RisingTide Systems LLC.
8 * Nicholas A. Bellinger <nab@kernel.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ******************************************************************************/
26 #include <linux/slab.h>
27 #include <linux/spinlock.h>
28 #include <linux/configfs.h>
29 #include <linux/export.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <asm/unaligned.h>
34 #include <target/target_core_base.h>
35 #include <target/target_core_backend.h>
36 #include <target/target_core_fabric.h>
37 #include <target/target_core_configfs.h>
39 #include "target_core_internal.h"
40 #include "target_core_alua.h"
41 #include "target_core_ua.h"
43 static sense_reason_t
core_alua_check_transition(int state
, int *primary
);
44 static int core_alua_set_tg_pt_secondary_state(
45 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
46 struct se_port
*port
, int explict
, int offline
);
48 static u16 alua_lu_gps_counter
;
49 static u32 alua_lu_gps_count
;
51 static DEFINE_SPINLOCK(lu_gps_lock
);
52 static LIST_HEAD(lu_gps_list
);
54 struct t10_alua_lu_gp
*default_lu_gp
;
57 * REPORT_TARGET_PORT_GROUPS
59 * See spc4r17 section 6.27
62 target_emulate_report_target_port_groups(struct se_cmd
*cmd
)
64 struct se_device
*dev
= cmd
->se_dev
;
66 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
67 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
70 int ext_hdr
= (cmd
->t_task_cdb
[1] & 0x20);
73 * Skip over RESERVED area to first Target port group descriptor
74 * depending on the PARAMETER DATA FORMAT type..
81 if (cmd
->data_length
< off
) {
82 pr_warn("REPORT TARGET PORT GROUPS allocation length %u too"
83 " small for %s header\n", cmd
->data_length
,
84 (ext_hdr
) ? "extended" : "normal");
85 return TCM_INVALID_CDB_FIELD
;
87 buf
= transport_kmap_data_sg(cmd
);
89 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
91 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
92 list_for_each_entry(tg_pt_gp
, &dev
->t10_alua
.tg_pt_gps_list
,
95 * Check if the Target port group and Target port descriptor list
96 * based on tg_pt_gp_members count will fit into the response payload.
97 * Otherwise, bump rd_len to let the initiator know we have exceeded
98 * the allocation length and the response is truncated.
100 if ((off
+ 8 + (tg_pt_gp
->tg_pt_gp_members
* 4)) >
102 rd_len
+= 8 + (tg_pt_gp
->tg_pt_gp_members
* 4);
106 * PREF: Preferred target port bit, determine if this
107 * bit should be set for port group.
109 if (tg_pt_gp
->tg_pt_gp_pref
)
112 * Set the ASYMMETRIC ACCESS State
114 buf
[off
++] |= (atomic_read(
115 &tg_pt_gp
->tg_pt_gp_alua_access_state
) & 0xff);
117 * Set supported ASYMMETRIC ACCESS State bits
119 buf
[off
] = 0x80; /* T_SUP */
120 buf
[off
] |= 0x40; /* O_SUP */
121 buf
[off
] |= 0x8; /* U_SUP */
122 buf
[off
] |= 0x4; /* S_SUP */
123 buf
[off
] |= 0x2; /* AN_SUP */
124 buf
[off
++] |= 0x1; /* AO_SUP */
128 buf
[off
++] = ((tg_pt_gp
->tg_pt_gp_id
>> 8) & 0xff);
129 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_id
& 0xff);
131 off
++; /* Skip over Reserved */
135 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_alua_access_status
& 0xff);
137 * Vendor Specific field
143 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_members
& 0xff);
146 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
147 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
149 port
= tg_pt_gp_mem
->tg_pt
;
151 * Start Target Port descriptor format
153 * See spc4r17 section 6.2.7 Table 247
155 off
+= 2; /* Skip over Obsolete */
157 * Set RELATIVE TARGET PORT IDENTIFIER
159 buf
[off
++] = ((port
->sep_rtpi
>> 8) & 0xff);
160 buf
[off
++] = (port
->sep_rtpi
& 0xff);
163 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
165 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
167 * Set the RETURN DATA LENGTH set in the header of the DataIN Payload
169 put_unaligned_be32(rd_len
, &buf
[0]);
172 * Fill in the Extended header parameter data format if requested
177 * Set the implict transition time (in seconds) for the application
178 * client to use as a base for it's transition timeout value.
180 * Use the current tg_pt_gp_mem -> tg_pt_gp membership from the LUN
181 * this CDB was received upon to determine this value individually
182 * for ALUA target port group.
184 port
= cmd
->se_lun
->lun_sep
;
185 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
187 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
188 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
190 buf
[5] = tg_pt_gp
->tg_pt_gp_implict_trans_secs
;
191 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
194 transport_kunmap_data_sg(cmd
);
196 target_complete_cmd(cmd
, GOOD
);
201 * SET_TARGET_PORT_GROUPS for explict ALUA operation.
203 * See spc4r17 section 6.35
206 target_emulate_set_target_port_groups(struct se_cmd
*cmd
)
208 struct se_device
*dev
= cmd
->se_dev
;
209 struct se_port
*port
, *l_port
= cmd
->se_lun
->lun_sep
;
210 struct se_node_acl
*nacl
= cmd
->se_sess
->se_node_acl
;
211 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *l_tg_pt_gp
;
212 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *l_tg_pt_gp_mem
;
215 sense_reason_t rc
= TCM_NO_SENSE
;
216 u32 len
= 4; /* Skip over RESERVED area in header */
217 int alua_access_state
, primary
= 0;
221 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
223 if (cmd
->data_length
< 4) {
224 pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
225 " small\n", cmd
->data_length
);
226 return TCM_INVALID_PARAMETER_LIST
;
229 buf
= transport_kmap_data_sg(cmd
);
231 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
234 * Determine if explict ALUA via SET_TARGET_PORT_GROUPS is allowed
235 * for the local tg_pt_gp.
237 l_tg_pt_gp_mem
= l_port
->sep_alua_tg_pt_gp_mem
;
238 if (!l_tg_pt_gp_mem
) {
239 pr_err("Unable to access l_port->sep_alua_tg_pt_gp_mem\n");
240 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
243 spin_lock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
244 l_tg_pt_gp
= l_tg_pt_gp_mem
->tg_pt_gp
;
246 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
247 pr_err("Unable to access *l_tg_pt_gp_mem->tg_pt_gp\n");
248 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
251 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
253 if (!(l_tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
)) {
254 pr_debug("Unable to process SET_TARGET_PORT_GROUPS"
255 " while TPGS_EXPLICT_ALUA is disabled\n");
256 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
260 ptr
= &buf
[4]; /* Skip over RESERVED area in header */
262 while (len
< cmd
->data_length
) {
264 alua_access_state
= (ptr
[0] & 0x0f);
266 * Check the received ALUA access state, and determine if
267 * the state is a primary or secondary target port asymmetric
270 rc
= core_alua_check_transition(alua_access_state
, &primary
);
273 * If the SET TARGET PORT GROUPS attempts to establish
274 * an invalid combination of target port asymmetric
275 * access states or attempts to establish an
276 * unsupported target port asymmetric access state,
277 * then the command shall be terminated with CHECK
278 * CONDITION status, with the sense key set to ILLEGAL
279 * REQUEST, and the additional sense code set to INVALID
280 * FIELD IN PARAMETER LIST.
286 * If the ASYMMETRIC ACCESS STATE field (see table 267)
287 * specifies a primary target port asymmetric access state,
288 * then the TARGET PORT GROUP OR TARGET PORT field specifies
289 * a primary target port group for which the primary target
290 * port asymmetric access state shall be changed. If the
291 * ASYMMETRIC ACCESS STATE field specifies a secondary target
292 * port asymmetric access state, then the TARGET PORT GROUP OR
293 * TARGET PORT field specifies the relative target port
294 * identifier (see 3.1.120) of the target port for which the
295 * secondary target port asymmetric access state shall be
299 tg_pt_id
= get_unaligned_be16(ptr
+ 2);
301 * Locate the matching target port group ID from
302 * the global tg_pt_gp list
304 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
305 list_for_each_entry(tg_pt_gp
,
306 &dev
->t10_alua
.tg_pt_gps_list
,
308 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
311 if (tg_pt_id
!= tg_pt_gp
->tg_pt_gp_id
)
314 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
315 smp_mb__after_atomic_inc();
317 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
319 if (!core_alua_do_port_transition(tg_pt_gp
,
321 alua_access_state
, 1))
324 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
325 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
326 smp_mb__after_atomic_dec();
329 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
332 * Extact the RELATIVE TARGET PORT IDENTIFIER to identify
333 * the Target Port in question for the the incoming
334 * SET_TARGET_PORT_GROUPS op.
336 rtpi
= get_unaligned_be16(ptr
+ 2);
338 * Locate the matching relative target port identifier
339 * for the struct se_device storage object.
341 spin_lock(&dev
->se_port_lock
);
342 list_for_each_entry(port
, &dev
->dev_sep_list
,
344 if (port
->sep_rtpi
!= rtpi
)
347 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
349 spin_unlock(&dev
->se_port_lock
);
351 if (!core_alua_set_tg_pt_secondary_state(
352 tg_pt_gp_mem
, port
, 1, 1))
355 spin_lock(&dev
->se_port_lock
);
358 spin_unlock(&dev
->se_port_lock
);
362 rc
= TCM_INVALID_PARAMETER_LIST
;
371 transport_kunmap_data_sg(cmd
);
373 target_complete_cmd(cmd
, GOOD
);
377 static inline int core_alua_state_nonoptimized(
380 int nonop_delay_msecs
,
384 * Set SCF_ALUA_NON_OPTIMIZED here, this value will be checked
385 * later to determine if processing of this cmd needs to be
386 * temporarily delayed for the Active/NonOptimized primary access state.
388 cmd
->se_cmd_flags
|= SCF_ALUA_NON_OPTIMIZED
;
389 cmd
->alua_nonop_delay
= nonop_delay_msecs
;
393 static inline int core_alua_state_standby(
399 * Allowed CDBs for ALUA_ACCESS_STATE_STANDBY as defined by
400 * spc4r17 section 5.9.2.4.4
409 case RECEIVE_DIAGNOSTIC
:
410 case SEND_DIAGNOSTIC
:
412 switch (cdb
[1] & 0x1f) {
413 case MI_REPORT_TARGET_PGS
:
416 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
419 case MAINTENANCE_OUT
:
421 case MO_SET_TARGET_PGS
:
424 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
428 case PERSISTENT_RESERVE_IN
:
429 case PERSISTENT_RESERVE_OUT
:
434 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
441 static inline int core_alua_state_unavailable(
447 * Allowed CDBs for ALUA_ACCESS_STATE_UNAVAILABLE as defined by
448 * spc4r17 section 5.9.2.4.5
454 switch (cdb
[1] & 0x1f) {
455 case MI_REPORT_TARGET_PGS
:
458 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
461 case MAINTENANCE_OUT
:
463 case MO_SET_TARGET_PGS
:
466 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
474 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
481 static inline int core_alua_state_transition(
487 * Allowed CDBs for ALUA_ACCESS_STATE_TRANSITIO as defined by
488 * spc4r17 section 5.9.2.5
494 switch (cdb
[1] & 0x1f) {
495 case MI_REPORT_TARGET_PGS
:
498 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
506 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
514 * return 1: Is used to signal LUN not accecsable, and check condition/not ready
515 * return 0: Used to signal success
516 * reutrn -1: Used to signal failure, and invalid cdb field
519 target_alua_state_check(struct se_cmd
*cmd
)
521 struct se_device
*dev
= cmd
->se_dev
;
522 unsigned char *cdb
= cmd
->t_task_cdb
;
523 struct se_lun
*lun
= cmd
->se_lun
;
524 struct se_port
*port
= lun
->lun_sep
;
525 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
526 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
527 int out_alua_state
, nonop_delay_msecs
;
531 if (dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)
533 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
539 * First, check for a struct se_port specific secondary ALUA target port
540 * access state: OFFLINE
542 if (atomic_read(&port
->sep_tg_pt_secondary_offline
)) {
543 pr_debug("ALUA: Got secondary offline status for local"
545 alua_ascq
= ASCQ_04H_ALUA_OFFLINE
;
550 * Second, obtain the struct t10_alua_tg_pt_gp_member pointer to the
551 * ALUA target port group, to obtain current ALUA access state.
552 * Otherwise look for the underlying struct se_device association with
553 * a ALUA logical unit group.
555 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
556 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
557 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
558 out_alua_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
559 nonop_delay_msecs
= tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
;
560 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
562 * Process ALUA_ACCESS_STATE_ACTIVE_OPTMIZED in a separate conditional
563 * statement so the compiler knows explicitly to check this case first.
564 * For the Optimized ALUA access state case, we want to process the
565 * incoming fabric cmd ASAP..
567 if (out_alua_state
== ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
)
570 switch (out_alua_state
) {
571 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
572 ret
= core_alua_state_nonoptimized(cmd
, cdb
,
573 nonop_delay_msecs
, &alua_ascq
);
575 case ALUA_ACCESS_STATE_STANDBY
:
576 ret
= core_alua_state_standby(cmd
, cdb
, &alua_ascq
);
578 case ALUA_ACCESS_STATE_UNAVAILABLE
:
579 ret
= core_alua_state_unavailable(cmd
, cdb
, &alua_ascq
);
581 case ALUA_ACCESS_STATE_TRANSITION
:
582 ret
= core_alua_state_transition(cmd
, cdb
, &alua_ascq
);
585 * OFFLINE is a secondary ALUA target port group access state, that is
586 * handled above with struct se_port->sep_tg_pt_secondary_offline=1
588 case ALUA_ACCESS_STATE_OFFLINE
:
590 pr_err("Unknown ALUA access state: 0x%02x\n",
592 return TCM_INVALID_CDB_FIELD
;
598 * Set SCSI additional sense code (ASC) to 'LUN Not Accessible';
599 * The ALUA additional sense code qualifier (ASCQ) is determined
600 * by the ALUA primary or secondary access state..
602 pr_debug("[%s]: ALUA TG Port not available, "
603 "SenseKey: NOT_READY, ASC/ASCQ: "
605 cmd
->se_tfo
->get_fabric_name(), alua_ascq
);
607 cmd
->scsi_asc
= 0x04;
608 cmd
->scsi_ascq
= alua_ascq
;
609 return TCM_CHECK_CONDITION_NOT_READY
;
616 * Check implict and explict ALUA state change request.
618 static sense_reason_t
619 core_alua_check_transition(int state
, int *primary
)
622 case ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
:
623 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
624 case ALUA_ACCESS_STATE_STANDBY
:
625 case ALUA_ACCESS_STATE_UNAVAILABLE
:
627 * OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
628 * defined as primary target port asymmetric access states.
632 case ALUA_ACCESS_STATE_OFFLINE
:
634 * OFFLINE state is defined as a secondary target port
635 * asymmetric access state.
640 pr_err("Unknown ALUA access state: 0x%02x\n", state
);
641 return TCM_INVALID_PARAMETER_LIST
;
647 static char *core_alua_dump_state(int state
)
650 case ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
:
651 return "Active/Optimized";
652 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
653 return "Active/NonOptimized";
654 case ALUA_ACCESS_STATE_STANDBY
:
656 case ALUA_ACCESS_STATE_UNAVAILABLE
:
657 return "Unavailable";
658 case ALUA_ACCESS_STATE_OFFLINE
:
667 char *core_alua_dump_status(int status
)
670 case ALUA_STATUS_NONE
:
672 case ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
673 return "Altered by Explict STPG";
674 case ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
:
675 return "Altered by Implict ALUA";
684 * Used by fabric modules to determine when we need to delay processing
685 * for the Active/NonOptimized paths..
687 int core_alua_check_nonop_delay(
690 if (!(cmd
->se_cmd_flags
& SCF_ALUA_NON_OPTIMIZED
))
695 * The ALUA Active/NonOptimized access state delay can be disabled
696 * in via configfs with a value of zero
698 if (!cmd
->alua_nonop_delay
)
701 * struct se_cmd->alua_nonop_delay gets set by a target port group
702 * defined interval in core_alua_state_nonoptimized()
704 msleep_interruptible(cmd
->alua_nonop_delay
);
707 EXPORT_SYMBOL(core_alua_check_nonop_delay
);
710 * Called with tg_pt_gp->tg_pt_gp_md_mutex or tg_pt_gp_mem->sep_tg_pt_md_mutex
713 static int core_alua_write_tpg_metadata(
715 unsigned char *md_buf
,
721 int flags
= O_RDWR
| O_CREAT
| O_TRUNC
, ret
;
723 memset(iov
, 0, sizeof(struct iovec
));
725 file
= filp_open(path
, flags
, 0600);
726 if (IS_ERR(file
) || !file
|| !file
->f_dentry
) {
727 pr_err("filp_open(%s) for ALUA metadata failed\n",
732 iov
[0].iov_base
= &md_buf
[0];
733 iov
[0].iov_len
= md_buf_len
;
737 ret
= vfs_writev(file
, &iov
[0], 1, &file
->f_pos
);
741 pr_err("Error writing ALUA metadata file: %s\n", path
);
742 filp_close(file
, NULL
);
745 filp_close(file
, NULL
);
751 * Called with tg_pt_gp->tg_pt_gp_md_mutex held
753 static int core_alua_update_tpg_primary_metadata(
754 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
756 unsigned char *md_buf
)
758 struct t10_wwn
*wwn
= &tg_pt_gp
->tg_pt_gp_dev
->t10_wwn
;
759 char path
[ALUA_METADATA_PATH_LEN
];
762 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
764 len
= snprintf(md_buf
, tg_pt_gp
->tg_pt_gp_md_buf_len
,
766 "alua_access_state=0x%02x\n"
767 "alua_access_status=0x%02x\n",
768 tg_pt_gp
->tg_pt_gp_id
, primary_state
,
769 tg_pt_gp
->tg_pt_gp_alua_access_status
);
771 snprintf(path
, ALUA_METADATA_PATH_LEN
,
772 "/var/target/alua/tpgs_%s/%s", &wwn
->unit_serial
[0],
773 config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
));
775 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
778 static int core_alua_do_transition_tg_pt(
779 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
780 struct se_port
*l_port
,
781 struct se_node_acl
*nacl
,
782 unsigned char *md_buf
,
786 struct se_dev_entry
*se_deve
;
787 struct se_lun_acl
*lacl
;
788 struct se_port
*port
;
789 struct t10_alua_tg_pt_gp_member
*mem
;
792 * Save the old primary ALUA access state, and set the current state
793 * to ALUA_ACCESS_STATE_TRANSITION.
795 old_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
796 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
797 ALUA_ACCESS_STATE_TRANSITION
);
798 tg_pt_gp
->tg_pt_gp_alua_access_status
= (explict
) ?
799 ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
800 ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
;
802 * Check for the optional ALUA primary state transition delay
804 if (tg_pt_gp
->tg_pt_gp_trans_delay_msecs
!= 0)
805 msleep_interruptible(tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
807 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
808 list_for_each_entry(mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
812 * After an implicit target port asymmetric access state
813 * change, a device server shall establish a unit attention
814 * condition for the initiator port associated with every I_T
815 * nexus with the additional sense code set to ASYMMETRIC
816 * ACCESS STATE CHAGED.
818 * After an explicit target port asymmetric access state
819 * change, a device server shall establish a unit attention
820 * condition with the additional sense code set to ASYMMETRIC
821 * ACCESS STATE CHANGED for the initiator port associated with
822 * every I_T nexus other than the I_T nexus on which the SET
823 * TARGET PORT GROUPS command
825 atomic_inc(&mem
->tg_pt_gp_mem_ref_cnt
);
826 smp_mb__after_atomic_inc();
827 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
829 spin_lock_bh(&port
->sep_alua_lock
);
830 list_for_each_entry(se_deve
, &port
->sep_alua_list
,
832 lacl
= se_deve
->se_lun_acl
;
834 * se_deve->se_lun_acl pointer may be NULL for a
835 * entry created without explict Node+MappedLUN ACLs
841 (nacl
!= NULL
) && (nacl
== lacl
->se_lun_nacl
) &&
842 (l_port
!= NULL
) && (l_port
== port
))
845 core_scsi3_ua_allocate(lacl
->se_lun_nacl
,
846 se_deve
->mapped_lun
, 0x2A,
847 ASCQ_2AH_ASYMMETRIC_ACCESS_STATE_CHANGED
);
849 spin_unlock_bh(&port
->sep_alua_lock
);
851 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
852 atomic_dec(&mem
->tg_pt_gp_mem_ref_cnt
);
853 smp_mb__after_atomic_dec();
855 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
857 * Update the ALUA metadata buf that has been allocated in
858 * core_alua_do_port_transition(), this metadata will be written
861 * Note that there is the case where we do not want to update the
862 * metadata when the saved metadata is being parsed in userspace
863 * when setting the existing port access state and access status.
865 * Also note that the failure to write out the ALUA metadata to
866 * struct file does NOT affect the actual ALUA transition.
868 if (tg_pt_gp
->tg_pt_gp_write_metadata
) {
869 mutex_lock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
870 core_alua_update_tpg_primary_metadata(tg_pt_gp
,
872 mutex_unlock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
875 * Set the current primary ALUA access state to the requested new state
877 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
, new_state
);
879 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
880 " from primary access state %s to %s\n", (explict
) ? "explict" :
881 "implict", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
882 tg_pt_gp
->tg_pt_gp_id
, core_alua_dump_state(old_state
),
883 core_alua_dump_state(new_state
));
888 int core_alua_do_port_transition(
889 struct t10_alua_tg_pt_gp
*l_tg_pt_gp
,
890 struct se_device
*l_dev
,
891 struct se_port
*l_port
,
892 struct se_node_acl
*l_nacl
,
896 struct se_device
*dev
;
897 struct se_port
*port
;
898 struct se_node_acl
*nacl
;
899 struct t10_alua_lu_gp
*lu_gp
;
900 struct t10_alua_lu_gp_member
*lu_gp_mem
, *local_lu_gp_mem
;
901 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
902 unsigned char *md_buf
;
905 if (core_alua_check_transition(new_state
, &primary
) != 0)
908 md_buf
= kzalloc(l_tg_pt_gp
->tg_pt_gp_md_buf_len
, GFP_KERNEL
);
910 pr_err("Unable to allocate buf for ALUA metadata\n");
914 local_lu_gp_mem
= l_dev
->dev_alua_lu_gp_mem
;
915 spin_lock(&local_lu_gp_mem
->lu_gp_mem_lock
);
916 lu_gp
= local_lu_gp_mem
->lu_gp
;
917 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
918 smp_mb__after_atomic_inc();
919 spin_unlock(&local_lu_gp_mem
->lu_gp_mem_lock
);
921 * For storage objects that are members of the 'default_lu_gp',
922 * we only do transition on the passed *l_tp_pt_gp, and not
923 * on all of the matching target port groups IDs in default_lu_gp.
925 if (!lu_gp
->lu_gp_id
) {
927 * core_alua_do_transition_tg_pt() will always return
930 core_alua_do_transition_tg_pt(l_tg_pt_gp
, l_port
, l_nacl
,
931 md_buf
, new_state
, explict
);
932 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
933 smp_mb__after_atomic_dec();
938 * For all other LU groups aside from 'default_lu_gp', walk all of
939 * the associated storage objects looking for a matching target port
940 * group ID from the local target port group.
942 spin_lock(&lu_gp
->lu_gp_lock
);
943 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
,
946 dev
= lu_gp_mem
->lu_gp_mem_dev
;
947 atomic_inc(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
948 smp_mb__after_atomic_inc();
949 spin_unlock(&lu_gp
->lu_gp_lock
);
951 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
952 list_for_each_entry(tg_pt_gp
,
953 &dev
->t10_alua
.tg_pt_gps_list
,
956 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
959 * If the target behavior port asymmetric access state
960 * is changed for any target port group accessiable via
961 * a logical unit within a LU group, the target port
962 * behavior group asymmetric access states for the same
963 * target port group accessible via other logical units
964 * in that LU group will also change.
966 if (l_tg_pt_gp
->tg_pt_gp_id
!= tg_pt_gp
->tg_pt_gp_id
)
969 if (l_tg_pt_gp
== tg_pt_gp
) {
976 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
977 smp_mb__after_atomic_inc();
978 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
980 * core_alua_do_transition_tg_pt() will always return
983 core_alua_do_transition_tg_pt(tg_pt_gp
, port
,
984 nacl
, md_buf
, new_state
, explict
);
986 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
987 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
988 smp_mb__after_atomic_dec();
990 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
992 spin_lock(&lu_gp
->lu_gp_lock
);
993 atomic_dec(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
994 smp_mb__after_atomic_dec();
996 spin_unlock(&lu_gp
->lu_gp_lock
);
998 pr_debug("Successfully processed LU Group: %s all ALUA TG PT"
999 " Group IDs: %hu %s transition to primary state: %s\n",
1000 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1001 l_tg_pt_gp
->tg_pt_gp_id
, (explict
) ? "explict" : "implict",
1002 core_alua_dump_state(new_state
));
1004 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
1005 smp_mb__after_atomic_dec();
1011 * Called with tg_pt_gp_mem->sep_tg_pt_md_mutex held
1013 static int core_alua_update_tpg_secondary_metadata(
1014 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1015 struct se_port
*port
,
1016 unsigned char *md_buf
,
1019 struct se_portal_group
*se_tpg
= port
->sep_tpg
;
1020 char path
[ALUA_METADATA_PATH_LEN
], wwn
[ALUA_SECONDARY_METADATA_WWN_LEN
];
1023 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
1024 memset(wwn
, 0, ALUA_SECONDARY_METADATA_WWN_LEN
);
1026 len
= snprintf(wwn
, ALUA_SECONDARY_METADATA_WWN_LEN
, "%s",
1027 se_tpg
->se_tpg_tfo
->tpg_get_wwn(se_tpg
));
1029 if (se_tpg
->se_tpg_tfo
->tpg_get_tag
!= NULL
)
1030 snprintf(wwn
+len
, ALUA_SECONDARY_METADATA_WWN_LEN
-len
, "+%hu",
1031 se_tpg
->se_tpg_tfo
->tpg_get_tag(se_tpg
));
1033 len
= snprintf(md_buf
, md_buf_len
, "alua_tg_pt_offline=%d\n"
1034 "alua_tg_pt_status=0x%02x\n",
1035 atomic_read(&port
->sep_tg_pt_secondary_offline
),
1036 port
->sep_tg_pt_secondary_stat
);
1038 snprintf(path
, ALUA_METADATA_PATH_LEN
, "/var/target/alua/%s/%s/lun_%u",
1039 se_tpg
->se_tpg_tfo
->get_fabric_name(), wwn
,
1040 port
->sep_lun
->unpacked_lun
);
1042 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
1045 static int core_alua_set_tg_pt_secondary_state(
1046 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1047 struct se_port
*port
,
1051 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1052 unsigned char *md_buf
;
1054 int trans_delay_msecs
;
1056 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1057 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1059 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1060 pr_err("Unable to complete secondary state"
1064 trans_delay_msecs
= tg_pt_gp
->tg_pt_gp_trans_delay_msecs
;
1066 * Set the secondary ALUA target port access state to OFFLINE
1067 * or release the previously secondary state for struct se_port
1070 atomic_set(&port
->sep_tg_pt_secondary_offline
, 1);
1072 atomic_set(&port
->sep_tg_pt_secondary_offline
, 0);
1074 md_buf_len
= tg_pt_gp
->tg_pt_gp_md_buf_len
;
1075 port
->sep_tg_pt_secondary_stat
= (explict
) ?
1076 ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
1077 ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
;
1079 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
1080 " to secondary access state: %s\n", (explict
) ? "explict" :
1081 "implict", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1082 tg_pt_gp
->tg_pt_gp_id
, (offline
) ? "OFFLINE" : "ONLINE");
1084 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1086 * Do the optional transition delay after we set the secondary
1087 * ALUA access state.
1089 if (trans_delay_msecs
!= 0)
1090 msleep_interruptible(trans_delay_msecs
);
1092 * See if we need to update the ALUA fabric port metadata for
1093 * secondary state and status
1095 if (port
->sep_tg_pt_secondary_write_md
) {
1096 md_buf
= kzalloc(md_buf_len
, GFP_KERNEL
);
1098 pr_err("Unable to allocate md_buf for"
1099 " secondary ALUA access metadata\n");
1102 mutex_lock(&port
->sep_tg_pt_md_mutex
);
1103 core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem
, port
,
1104 md_buf
, md_buf_len
);
1105 mutex_unlock(&port
->sep_tg_pt_md_mutex
);
1113 struct t10_alua_lu_gp
*
1114 core_alua_allocate_lu_gp(const char *name
, int def_group
)
1116 struct t10_alua_lu_gp
*lu_gp
;
1118 lu_gp
= kmem_cache_zalloc(t10_alua_lu_gp_cache
, GFP_KERNEL
);
1120 pr_err("Unable to allocate struct t10_alua_lu_gp\n");
1121 return ERR_PTR(-ENOMEM
);
1123 INIT_LIST_HEAD(&lu_gp
->lu_gp_node
);
1124 INIT_LIST_HEAD(&lu_gp
->lu_gp_mem_list
);
1125 spin_lock_init(&lu_gp
->lu_gp_lock
);
1126 atomic_set(&lu_gp
->lu_gp_ref_cnt
, 0);
1129 lu_gp
->lu_gp_id
= alua_lu_gps_counter
++;
1130 lu_gp
->lu_gp_valid_id
= 1;
1131 alua_lu_gps_count
++;
1137 int core_alua_set_lu_gp_id(struct t10_alua_lu_gp
*lu_gp
, u16 lu_gp_id
)
1139 struct t10_alua_lu_gp
*lu_gp_tmp
;
1142 * The lu_gp->lu_gp_id may only be set once..
1144 if (lu_gp
->lu_gp_valid_id
) {
1145 pr_warn("ALUA LU Group already has a valid ID,"
1146 " ignoring request\n");
1150 spin_lock(&lu_gps_lock
);
1151 if (alua_lu_gps_count
== 0x0000ffff) {
1152 pr_err("Maximum ALUA alua_lu_gps_count:"
1153 " 0x0000ffff reached\n");
1154 spin_unlock(&lu_gps_lock
);
1155 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1159 lu_gp_id_tmp
= (lu_gp_id
!= 0) ? lu_gp_id
:
1160 alua_lu_gps_counter
++;
1162 list_for_each_entry(lu_gp_tmp
, &lu_gps_list
, lu_gp_node
) {
1163 if (lu_gp_tmp
->lu_gp_id
== lu_gp_id_tmp
) {
1167 pr_warn("ALUA Logical Unit Group ID: %hu"
1168 " already exists, ignoring request\n",
1170 spin_unlock(&lu_gps_lock
);
1175 lu_gp
->lu_gp_id
= lu_gp_id_tmp
;
1176 lu_gp
->lu_gp_valid_id
= 1;
1177 list_add_tail(&lu_gp
->lu_gp_node
, &lu_gps_list
);
1178 alua_lu_gps_count
++;
1179 spin_unlock(&lu_gps_lock
);
1184 static struct t10_alua_lu_gp_member
*
1185 core_alua_allocate_lu_gp_mem(struct se_device
*dev
)
1187 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1189 lu_gp_mem
= kmem_cache_zalloc(t10_alua_lu_gp_mem_cache
, GFP_KERNEL
);
1191 pr_err("Unable to allocate struct t10_alua_lu_gp_member\n");
1192 return ERR_PTR(-ENOMEM
);
1194 INIT_LIST_HEAD(&lu_gp_mem
->lu_gp_mem_list
);
1195 spin_lock_init(&lu_gp_mem
->lu_gp_mem_lock
);
1196 atomic_set(&lu_gp_mem
->lu_gp_mem_ref_cnt
, 0);
1198 lu_gp_mem
->lu_gp_mem_dev
= dev
;
1199 dev
->dev_alua_lu_gp_mem
= lu_gp_mem
;
1204 void core_alua_free_lu_gp(struct t10_alua_lu_gp
*lu_gp
)
1206 struct t10_alua_lu_gp_member
*lu_gp_mem
, *lu_gp_mem_tmp
;
1208 * Once we have reached this point, config_item_put() has
1209 * already been called from target_core_alua_drop_lu_gp().
1211 * Here, we remove the *lu_gp from the global list so that
1212 * no associations can be made while we are releasing
1213 * struct t10_alua_lu_gp.
1215 spin_lock(&lu_gps_lock
);
1216 list_del(&lu_gp
->lu_gp_node
);
1217 alua_lu_gps_count
--;
1218 spin_unlock(&lu_gps_lock
);
1220 * Allow struct t10_alua_lu_gp * referenced by core_alua_get_lu_gp_by_name()
1221 * in target_core_configfs.c:target_core_store_alua_lu_gp() to be
1222 * released with core_alua_put_lu_gp_from_name()
1224 while (atomic_read(&lu_gp
->lu_gp_ref_cnt
))
1227 * Release reference to struct t10_alua_lu_gp * from all associated
1230 spin_lock(&lu_gp
->lu_gp_lock
);
1231 list_for_each_entry_safe(lu_gp_mem
, lu_gp_mem_tmp
,
1232 &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1233 if (lu_gp_mem
->lu_gp_assoc
) {
1234 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1235 lu_gp
->lu_gp_members
--;
1236 lu_gp_mem
->lu_gp_assoc
= 0;
1238 spin_unlock(&lu_gp
->lu_gp_lock
);
1241 * lu_gp_mem is associated with a single
1242 * struct se_device->dev_alua_lu_gp_mem, and is released when
1243 * struct se_device is released via core_alua_free_lu_gp_mem().
1245 * If the passed lu_gp does NOT match the default_lu_gp, assume
1246 * we want to re-assocate a given lu_gp_mem with default_lu_gp.
1248 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1249 if (lu_gp
!= default_lu_gp
)
1250 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
1253 lu_gp_mem
->lu_gp
= NULL
;
1254 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1256 spin_lock(&lu_gp
->lu_gp_lock
);
1258 spin_unlock(&lu_gp
->lu_gp_lock
);
1260 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1263 void core_alua_free_lu_gp_mem(struct se_device
*dev
)
1265 struct t10_alua_lu_gp
*lu_gp
;
1266 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1268 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1272 while (atomic_read(&lu_gp_mem
->lu_gp_mem_ref_cnt
))
1275 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1276 lu_gp
= lu_gp_mem
->lu_gp
;
1278 spin_lock(&lu_gp
->lu_gp_lock
);
1279 if (lu_gp_mem
->lu_gp_assoc
) {
1280 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1281 lu_gp
->lu_gp_members
--;
1282 lu_gp_mem
->lu_gp_assoc
= 0;
1284 spin_unlock(&lu_gp
->lu_gp_lock
);
1285 lu_gp_mem
->lu_gp
= NULL
;
1287 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1289 kmem_cache_free(t10_alua_lu_gp_mem_cache
, lu_gp_mem
);
1292 struct t10_alua_lu_gp
*core_alua_get_lu_gp_by_name(const char *name
)
1294 struct t10_alua_lu_gp
*lu_gp
;
1295 struct config_item
*ci
;
1297 spin_lock(&lu_gps_lock
);
1298 list_for_each_entry(lu_gp
, &lu_gps_list
, lu_gp_node
) {
1299 if (!lu_gp
->lu_gp_valid_id
)
1301 ci
= &lu_gp
->lu_gp_group
.cg_item
;
1302 if (!strcmp(config_item_name(ci
), name
)) {
1303 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
1304 spin_unlock(&lu_gps_lock
);
1308 spin_unlock(&lu_gps_lock
);
1313 void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp
*lu_gp
)
1315 spin_lock(&lu_gps_lock
);
1316 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
1317 spin_unlock(&lu_gps_lock
);
1321 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1323 void __core_alua_attach_lu_gp_mem(
1324 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1325 struct t10_alua_lu_gp
*lu_gp
)
1327 spin_lock(&lu_gp
->lu_gp_lock
);
1328 lu_gp_mem
->lu_gp
= lu_gp
;
1329 lu_gp_mem
->lu_gp_assoc
= 1;
1330 list_add_tail(&lu_gp_mem
->lu_gp_mem_list
, &lu_gp
->lu_gp_mem_list
);
1331 lu_gp
->lu_gp_members
++;
1332 spin_unlock(&lu_gp
->lu_gp_lock
);
1336 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1338 void __core_alua_drop_lu_gp_mem(
1339 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1340 struct t10_alua_lu_gp
*lu_gp
)
1342 spin_lock(&lu_gp
->lu_gp_lock
);
1343 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1344 lu_gp_mem
->lu_gp
= NULL
;
1345 lu_gp_mem
->lu_gp_assoc
= 0;
1346 lu_gp
->lu_gp_members
--;
1347 spin_unlock(&lu_gp
->lu_gp_lock
);
1350 struct t10_alua_tg_pt_gp
*core_alua_allocate_tg_pt_gp(struct se_device
*dev
,
1351 const char *name
, int def_group
)
1353 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1355 tg_pt_gp
= kmem_cache_zalloc(t10_alua_tg_pt_gp_cache
, GFP_KERNEL
);
1357 pr_err("Unable to allocate struct t10_alua_tg_pt_gp\n");
1360 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_list
);
1361 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_mem_list
);
1362 mutex_init(&tg_pt_gp
->tg_pt_gp_md_mutex
);
1363 spin_lock_init(&tg_pt_gp
->tg_pt_gp_lock
);
1364 atomic_set(&tg_pt_gp
->tg_pt_gp_ref_cnt
, 0);
1365 tg_pt_gp
->tg_pt_gp_dev
= dev
;
1366 tg_pt_gp
->tg_pt_gp_md_buf_len
= ALUA_MD_BUF_LEN
;
1367 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
1368 ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
);
1370 * Enable both explict and implict ALUA support by default
1372 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1373 TPGS_EXPLICT_ALUA
| TPGS_IMPLICT_ALUA
;
1375 * Set the default Active/NonOptimized Delay in milliseconds
1377 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= ALUA_DEFAULT_NONOP_DELAY_MSECS
;
1378 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= ALUA_DEFAULT_TRANS_DELAY_MSECS
;
1379 tg_pt_gp
->tg_pt_gp_implict_trans_secs
= ALUA_DEFAULT_IMPLICT_TRANS_SECS
;
1382 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1383 tg_pt_gp
->tg_pt_gp_id
=
1384 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1385 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1386 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1387 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1388 &dev
->t10_alua
.tg_pt_gps_list
);
1389 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1395 int core_alua_set_tg_pt_gp_id(
1396 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1399 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1400 struct t10_alua_tg_pt_gp
*tg_pt_gp_tmp
;
1401 u16 tg_pt_gp_id_tmp
;
1404 * The tg_pt_gp->tg_pt_gp_id may only be set once..
1406 if (tg_pt_gp
->tg_pt_gp_valid_id
) {
1407 pr_warn("ALUA TG PT Group already has a valid ID,"
1408 " ignoring request\n");
1412 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1413 if (dev
->t10_alua
.alua_tg_pt_gps_count
== 0x0000ffff) {
1414 pr_err("Maximum ALUA alua_tg_pt_gps_count:"
1415 " 0x0000ffff reached\n");
1416 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1417 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1421 tg_pt_gp_id_tmp
= (tg_pt_gp_id
!= 0) ? tg_pt_gp_id
:
1422 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1424 list_for_each_entry(tg_pt_gp_tmp
, &dev
->t10_alua
.tg_pt_gps_list
,
1426 if (tg_pt_gp_tmp
->tg_pt_gp_id
== tg_pt_gp_id_tmp
) {
1430 pr_err("ALUA Target Port Group ID: %hu already"
1431 " exists, ignoring request\n", tg_pt_gp_id
);
1432 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1437 tg_pt_gp
->tg_pt_gp_id
= tg_pt_gp_id_tmp
;
1438 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1439 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1440 &dev
->t10_alua
.tg_pt_gps_list
);
1441 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1442 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1447 struct t10_alua_tg_pt_gp_member
*core_alua_allocate_tg_pt_gp_mem(
1448 struct se_port
*port
)
1450 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1452 tg_pt_gp_mem
= kmem_cache_zalloc(t10_alua_tg_pt_gp_mem_cache
,
1454 if (!tg_pt_gp_mem
) {
1455 pr_err("Unable to allocate struct t10_alua_tg_pt_gp_member\n");
1456 return ERR_PTR(-ENOMEM
);
1458 INIT_LIST_HEAD(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1459 spin_lock_init(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1460 atomic_set(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
, 0);
1462 tg_pt_gp_mem
->tg_pt
= port
;
1463 port
->sep_alua_tg_pt_gp_mem
= tg_pt_gp_mem
;
1465 return tg_pt_gp_mem
;
1468 void core_alua_free_tg_pt_gp(
1469 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1471 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1472 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *tg_pt_gp_mem_tmp
;
1475 * Once we have reached this point, config_item_put() has already
1476 * been called from target_core_alua_drop_tg_pt_gp().
1478 * Here we remove *tg_pt_gp from the global list so that
1479 * no assications *OR* explict ALUA via SET_TARGET_PORT_GROUPS
1480 * can be made while we are releasing struct t10_alua_tg_pt_gp.
1482 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1483 list_del(&tg_pt_gp
->tg_pt_gp_list
);
1484 dev
->t10_alua
.alua_tg_pt_gps_counter
--;
1485 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1488 * Allow a struct t10_alua_tg_pt_gp_member * referenced by
1489 * core_alua_get_tg_pt_gp_by_name() in
1490 * target_core_configfs.c:target_core_store_alua_tg_pt_gp()
1491 * to be released with core_alua_put_tg_pt_gp_from_name().
1493 while (atomic_read(&tg_pt_gp
->tg_pt_gp_ref_cnt
))
1497 * Release reference to struct t10_alua_tg_pt_gp from all associated
1500 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1501 list_for_each_entry_safe(tg_pt_gp_mem
, tg_pt_gp_mem_tmp
,
1502 &tg_pt_gp
->tg_pt_gp_mem_list
, tg_pt_gp_mem_list
) {
1503 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1504 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1505 tg_pt_gp
->tg_pt_gp_members
--;
1506 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1508 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1510 * tg_pt_gp_mem is associated with a single
1511 * se_port->sep_alua_tg_pt_gp_mem, and is released via
1512 * core_alua_free_tg_pt_gp_mem().
1514 * If the passed tg_pt_gp does NOT match the default_tg_pt_gp,
1515 * assume we want to re-assocate a given tg_pt_gp_mem with
1518 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1519 if (tg_pt_gp
!= dev
->t10_alua
.default_tg_pt_gp
) {
1520 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1521 dev
->t10_alua
.default_tg_pt_gp
);
1523 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1524 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1526 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1528 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1530 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1533 void core_alua_free_tg_pt_gp_mem(struct se_port
*port
)
1535 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1536 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1538 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1542 while (atomic_read(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
))
1545 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1546 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1548 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1549 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1550 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1551 tg_pt_gp
->tg_pt_gp_members
--;
1552 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1554 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1555 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1557 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1559 kmem_cache_free(t10_alua_tg_pt_gp_mem_cache
, tg_pt_gp_mem
);
1562 static struct t10_alua_tg_pt_gp
*core_alua_get_tg_pt_gp_by_name(
1563 struct se_device
*dev
, const char *name
)
1565 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1566 struct config_item
*ci
;
1568 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1569 list_for_each_entry(tg_pt_gp
, &dev
->t10_alua
.tg_pt_gps_list
,
1571 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
1573 ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1574 if (!strcmp(config_item_name(ci
), name
)) {
1575 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1576 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1580 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1585 static void core_alua_put_tg_pt_gp_from_name(
1586 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1588 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1590 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1591 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1592 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1596 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1598 void __core_alua_attach_tg_pt_gp_mem(
1599 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1600 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1602 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1603 tg_pt_gp_mem
->tg_pt_gp
= tg_pt_gp
;
1604 tg_pt_gp_mem
->tg_pt_gp_assoc
= 1;
1605 list_add_tail(&tg_pt_gp_mem
->tg_pt_gp_mem_list
,
1606 &tg_pt_gp
->tg_pt_gp_mem_list
);
1607 tg_pt_gp
->tg_pt_gp_members
++;
1608 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1612 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1614 static void __core_alua_drop_tg_pt_gp_mem(
1615 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1616 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1618 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1619 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1620 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1621 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1622 tg_pt_gp
->tg_pt_gp_members
--;
1623 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1626 ssize_t
core_alua_show_tg_pt_gp_info(struct se_port
*port
, char *page
)
1628 struct config_item
*tg_pt_ci
;
1629 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1630 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1633 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1637 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1638 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1640 tg_pt_ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1641 len
+= sprintf(page
, "TG Port Alias: %s\nTG Port Group ID:"
1642 " %hu\nTG Port Primary Access State: %s\nTG Port "
1643 "Primary Access Status: %s\nTG Port Secondary Access"
1644 " State: %s\nTG Port Secondary Access Status: %s\n",
1645 config_item_name(tg_pt_ci
), tg_pt_gp
->tg_pt_gp_id
,
1646 core_alua_dump_state(atomic_read(
1647 &tg_pt_gp
->tg_pt_gp_alua_access_state
)),
1648 core_alua_dump_status(
1649 tg_pt_gp
->tg_pt_gp_alua_access_status
),
1650 (atomic_read(&port
->sep_tg_pt_secondary_offline
)) ?
1652 core_alua_dump_status(port
->sep_tg_pt_secondary_stat
));
1654 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1659 ssize_t
core_alua_store_tg_pt_gp_info(
1660 struct se_port
*port
,
1664 struct se_portal_group
*tpg
;
1666 struct se_device
*dev
= port
->sep_lun
->lun_se_dev
;
1667 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *tg_pt_gp_new
= NULL
;
1668 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1669 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
1672 tpg
= port
->sep_tpg
;
1673 lun
= port
->sep_lun
;
1675 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1679 if (count
> TG_PT_GROUP_NAME_BUF
) {
1680 pr_err("ALUA Target Port Group alias too large!\n");
1683 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
1684 memcpy(buf
, page
, count
);
1686 * Any ALUA target port group alias besides "NULL" means we will be
1687 * making a new group association.
1689 if (strcmp(strstrip(buf
), "NULL")) {
1691 * core_alua_get_tg_pt_gp_by_name() will increment reference to
1692 * struct t10_alua_tg_pt_gp. This reference is released with
1693 * core_alua_put_tg_pt_gp_from_name() below.
1695 tg_pt_gp_new
= core_alua_get_tg_pt_gp_by_name(dev
,
1701 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1702 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1705 * Clearing an existing tg_pt_gp association, and replacing
1706 * with the default_tg_pt_gp.
1708 if (!tg_pt_gp_new
) {
1709 pr_debug("Target_Core_ConfigFS: Moving"
1710 " %s/tpgt_%hu/%s from ALUA Target Port Group:"
1711 " alua/%s, ID: %hu back to"
1712 " default_tg_pt_gp\n",
1713 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1714 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1715 config_item_name(&lun
->lun_group
.cg_item
),
1717 &tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1718 tg_pt_gp
->tg_pt_gp_id
);
1720 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1721 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1722 dev
->t10_alua
.default_tg_pt_gp
);
1723 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1728 * Removing existing association of tg_pt_gp_mem with tg_pt_gp
1730 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1734 * Associate tg_pt_gp_mem with tg_pt_gp_new.
1736 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp_new
);
1737 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1738 pr_debug("Target_Core_ConfigFS: %s %s/tpgt_%hu/%s to ALUA"
1739 " Target Port Group: alua/%s, ID: %hu\n", (move
) ?
1740 "Moving" : "Adding", tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1741 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1742 config_item_name(&lun
->lun_group
.cg_item
),
1743 config_item_name(&tg_pt_gp_new
->tg_pt_gp_group
.cg_item
),
1744 tg_pt_gp_new
->tg_pt_gp_id
);
1746 core_alua_put_tg_pt_gp_from_name(tg_pt_gp_new
);
1750 ssize_t
core_alua_show_access_type(
1751 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1754 if ((tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
) &&
1755 (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
))
1756 return sprintf(page
, "Implict and Explict\n");
1757 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)
1758 return sprintf(page
, "Implict\n");
1759 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
)
1760 return sprintf(page
, "Explict\n");
1762 return sprintf(page
, "None\n");
1765 ssize_t
core_alua_store_access_type(
1766 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1773 ret
= strict_strtoul(page
, 0, &tmp
);
1775 pr_err("Unable to extract alua_access_type\n");
1778 if ((tmp
!= 0) && (tmp
!= 1) && (tmp
!= 2) && (tmp
!= 3)) {
1779 pr_err("Illegal value for alua_access_type:"
1784 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1785 TPGS_IMPLICT_ALUA
| TPGS_EXPLICT_ALUA
;
1787 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_EXPLICT_ALUA
;
1789 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_IMPLICT_ALUA
;
1791 tg_pt_gp
->tg_pt_gp_alua_access_type
= 0;
1796 ssize_t
core_alua_show_nonop_delay_msecs(
1797 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1800 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
);
1803 ssize_t
core_alua_store_nonop_delay_msecs(
1804 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1811 ret
= strict_strtoul(page
, 0, &tmp
);
1813 pr_err("Unable to extract nonop_delay_msecs\n");
1816 if (tmp
> ALUA_MAX_NONOP_DELAY_MSECS
) {
1817 pr_err("Passed nonop_delay_msecs: %lu, exceeds"
1818 " ALUA_MAX_NONOP_DELAY_MSECS: %d\n", tmp
,
1819 ALUA_MAX_NONOP_DELAY_MSECS
);
1822 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= (int)tmp
;
1827 ssize_t
core_alua_show_trans_delay_msecs(
1828 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1831 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
1834 ssize_t
core_alua_store_trans_delay_msecs(
1835 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1842 ret
= strict_strtoul(page
, 0, &tmp
);
1844 pr_err("Unable to extract trans_delay_msecs\n");
1847 if (tmp
> ALUA_MAX_TRANS_DELAY_MSECS
) {
1848 pr_err("Passed trans_delay_msecs: %lu, exceeds"
1849 " ALUA_MAX_TRANS_DELAY_MSECS: %d\n", tmp
,
1850 ALUA_MAX_TRANS_DELAY_MSECS
);
1853 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= (int)tmp
;
1858 ssize_t
core_alua_show_implict_trans_secs(
1859 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1862 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_implict_trans_secs
);
1865 ssize_t
core_alua_store_implict_trans_secs(
1866 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1873 ret
= strict_strtoul(page
, 0, &tmp
);
1875 pr_err("Unable to extract implict_trans_secs\n");
1878 if (tmp
> ALUA_MAX_IMPLICT_TRANS_SECS
) {
1879 pr_err("Passed implict_trans_secs: %lu, exceeds"
1880 " ALUA_MAX_IMPLICT_TRANS_SECS: %d\n", tmp
,
1881 ALUA_MAX_IMPLICT_TRANS_SECS
);
1884 tg_pt_gp
->tg_pt_gp_implict_trans_secs
= (int)tmp
;
1889 ssize_t
core_alua_show_preferred_bit(
1890 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1893 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_pref
);
1896 ssize_t
core_alua_store_preferred_bit(
1897 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1904 ret
= strict_strtoul(page
, 0, &tmp
);
1906 pr_err("Unable to extract preferred ALUA value\n");
1909 if ((tmp
!= 0) && (tmp
!= 1)) {
1910 pr_err("Illegal value for preferred ALUA: %lu\n", tmp
);
1913 tg_pt_gp
->tg_pt_gp_pref
= (int)tmp
;
1918 ssize_t
core_alua_show_offline_bit(struct se_lun
*lun
, char *page
)
1923 return sprintf(page
, "%d\n",
1924 atomic_read(&lun
->lun_sep
->sep_tg_pt_secondary_offline
));
1927 ssize_t
core_alua_store_offline_bit(
1932 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1939 ret
= strict_strtoul(page
, 0, &tmp
);
1941 pr_err("Unable to extract alua_tg_pt_offline value\n");
1944 if ((tmp
!= 0) && (tmp
!= 1)) {
1945 pr_err("Illegal value for alua_tg_pt_offline: %lu\n",
1949 tg_pt_gp_mem
= lun
->lun_sep
->sep_alua_tg_pt_gp_mem
;
1950 if (!tg_pt_gp_mem
) {
1951 pr_err("Unable to locate *tg_pt_gp_mem\n");
1955 ret
= core_alua_set_tg_pt_secondary_state(tg_pt_gp_mem
,
1956 lun
->lun_sep
, 0, (int)tmp
);
1963 ssize_t
core_alua_show_secondary_status(
1967 return sprintf(page
, "%d\n", lun
->lun_sep
->sep_tg_pt_secondary_stat
);
1970 ssize_t
core_alua_store_secondary_status(
1978 ret
= strict_strtoul(page
, 0, &tmp
);
1980 pr_err("Unable to extract alua_tg_pt_status\n");
1983 if ((tmp
!= ALUA_STATUS_NONE
) &&
1984 (tmp
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
1985 (tmp
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
1986 pr_err("Illegal value for alua_tg_pt_status: %lu\n",
1990 lun
->lun_sep
->sep_tg_pt_secondary_stat
= (int)tmp
;
1995 ssize_t
core_alua_show_secondary_write_metadata(
1999 return sprintf(page
, "%d\n",
2000 lun
->lun_sep
->sep_tg_pt_secondary_write_md
);
2003 ssize_t
core_alua_store_secondary_write_metadata(
2011 ret
= strict_strtoul(page
, 0, &tmp
);
2013 pr_err("Unable to extract alua_tg_pt_write_md\n");
2016 if ((tmp
!= 0) && (tmp
!= 1)) {
2017 pr_err("Illegal value for alua_tg_pt_write_md:"
2021 lun
->lun_sep
->sep_tg_pt_secondary_write_md
= (int)tmp
;
2026 int core_setup_alua(struct se_device
*dev
)
2028 if (dev
->transport
->transport_type
!= TRANSPORT_PLUGIN_PHBA_PDEV
&&
2029 !(dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)) {
2030 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2033 * Associate this struct se_device with the default ALUA
2036 lu_gp_mem
= core_alua_allocate_lu_gp_mem(dev
);
2037 if (IS_ERR(lu_gp_mem
))
2038 return PTR_ERR(lu_gp_mem
);
2040 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
2041 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
2043 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2045 pr_debug("%s: Adding to default ALUA LU Group:"
2046 " core/alua/lu_gps/default_lu_gp\n",
2047 dev
->transport
->name
);