1 /*******************************************************************************
2 * Filename: target_core_alua.c
4 * This file contains SPC-3 compliant asymmetric logical unit assigntment (ALUA)
6 * (c) Copyright 2009-2013 Datera, Inc.
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 <linux/file.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_cmnd.h>
33 #include <asm/unaligned.h>
35 #include <target/target_core_base.h>
36 #include <target/target_core_backend.h>
37 #include <target/target_core_fabric.h>
38 #include <target/target_core_configfs.h>
40 #include "target_core_internal.h"
41 #include "target_core_alua.h"
42 #include "target_core_ua.h"
44 static sense_reason_t
core_alua_check_transition(int state
, int *primary
);
45 static int core_alua_set_tg_pt_secondary_state(
46 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
47 struct se_port
*port
, int explicit, int offline
);
49 static u16 alua_lu_gps_counter
;
50 static u32 alua_lu_gps_count
;
52 static DEFINE_SPINLOCK(lu_gps_lock
);
53 static LIST_HEAD(lu_gps_list
);
55 struct t10_alua_lu_gp
*default_lu_gp
;
58 * REPORT_TARGET_PORT_GROUPS
60 * See spc4r17 section 6.27
63 target_emulate_report_target_port_groups(struct se_cmd
*cmd
)
65 struct se_device
*dev
= cmd
->se_dev
;
67 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
68 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
71 int ext_hdr
= (cmd
->t_task_cdb
[1] & 0x20);
74 * Skip over RESERVED area to first Target port group descriptor
75 * depending on the PARAMETER DATA FORMAT type..
82 if (cmd
->data_length
< off
) {
83 pr_warn("REPORT TARGET PORT GROUPS allocation length %u too"
84 " small for %s header\n", cmd
->data_length
,
85 (ext_hdr
) ? "extended" : "normal");
86 return TCM_INVALID_CDB_FIELD
;
88 buf
= transport_kmap_data_sg(cmd
);
90 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
92 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
93 list_for_each_entry(tg_pt_gp
, &dev
->t10_alua
.tg_pt_gps_list
,
96 * Check if the Target port group and Target port descriptor list
97 * based on tg_pt_gp_members count will fit into the response payload.
98 * Otherwise, bump rd_len to let the initiator know we have exceeded
99 * the allocation length and the response is truncated.
101 if ((off
+ 8 + (tg_pt_gp
->tg_pt_gp_members
* 4)) >
103 rd_len
+= 8 + (tg_pt_gp
->tg_pt_gp_members
* 4);
107 * PREF: Preferred target port bit, determine if this
108 * bit should be set for port group.
110 if (tg_pt_gp
->tg_pt_gp_pref
)
113 * Set the ASYMMETRIC ACCESS State
115 buf
[off
++] |= (atomic_read(
116 &tg_pt_gp
->tg_pt_gp_alua_access_state
) & 0xff);
118 * Set supported ASYMMETRIC ACCESS State bits
120 buf
[off
++] |= tg_pt_gp
->tg_pt_gp_alua_supported_states
;
124 buf
[off
++] = ((tg_pt_gp
->tg_pt_gp_id
>> 8) & 0xff);
125 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_id
& 0xff);
127 off
++; /* Skip over Reserved */
131 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_alua_access_status
& 0xff);
133 * Vendor Specific field
139 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_members
& 0xff);
142 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
143 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
145 port
= tg_pt_gp_mem
->tg_pt
;
147 * Start Target Port descriptor format
149 * See spc4r17 section 6.2.7 Table 247
151 off
+= 2; /* Skip over Obsolete */
153 * Set RELATIVE TARGET PORT IDENTIFIER
155 buf
[off
++] = ((port
->sep_rtpi
>> 8) & 0xff);
156 buf
[off
++] = (port
->sep_rtpi
& 0xff);
159 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
161 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
163 * Set the RETURN DATA LENGTH set in the header of the DataIN Payload
165 put_unaligned_be32(rd_len
, &buf
[0]);
168 * Fill in the Extended header parameter data format if requested
173 * Set the implicit transition time (in seconds) for the application
174 * client to use as a base for it's transition timeout value.
176 * Use the current tg_pt_gp_mem -> tg_pt_gp membership from the LUN
177 * this CDB was received upon to determine this value individually
178 * for ALUA target port group.
180 port
= cmd
->se_lun
->lun_sep
;
181 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
183 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
184 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
186 buf
[5] = tg_pt_gp
->tg_pt_gp_implicit_trans_secs
;
187 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
190 transport_kunmap_data_sg(cmd
);
192 target_complete_cmd(cmd
, GOOD
);
197 * SET_TARGET_PORT_GROUPS for explicit ALUA operation.
199 * See spc4r17 section 6.35
202 target_emulate_set_target_port_groups(struct se_cmd
*cmd
)
204 struct se_device
*dev
= cmd
->se_dev
;
205 struct se_port
*port
, *l_port
= cmd
->se_lun
->lun_sep
;
206 struct se_node_acl
*nacl
= cmd
->se_sess
->se_node_acl
;
207 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *l_tg_pt_gp
;
208 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *l_tg_pt_gp_mem
;
211 sense_reason_t rc
= TCM_NO_SENSE
;
212 u32 len
= 4; /* Skip over RESERVED area in header */
213 int alua_access_state
, primary
= 0;
217 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
219 if (cmd
->data_length
< 4) {
220 pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
221 " small\n", cmd
->data_length
);
222 return TCM_INVALID_PARAMETER_LIST
;
225 buf
= transport_kmap_data_sg(cmd
);
227 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
230 * Determine if explicit ALUA via SET_TARGET_PORT_GROUPS is allowed
231 * for the local tg_pt_gp.
233 l_tg_pt_gp_mem
= l_port
->sep_alua_tg_pt_gp_mem
;
234 if (!l_tg_pt_gp_mem
) {
235 pr_err("Unable to access l_port->sep_alua_tg_pt_gp_mem\n");
236 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
239 spin_lock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
240 l_tg_pt_gp
= l_tg_pt_gp_mem
->tg_pt_gp
;
242 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
243 pr_err("Unable to access *l_tg_pt_gp_mem->tg_pt_gp\n");
244 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
247 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
249 if (!(l_tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
)) {
250 pr_debug("Unable to process SET_TARGET_PORT_GROUPS"
251 " while TPGS_EXPLICIT_ALUA is disabled\n");
252 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
256 ptr
= &buf
[4]; /* Skip over RESERVED area in header */
258 while (len
< cmd
->data_length
) {
260 alua_access_state
= (ptr
[0] & 0x0f);
262 * Check the received ALUA access state, and determine if
263 * the state is a primary or secondary target port asymmetric
266 rc
= core_alua_check_transition(alua_access_state
, &primary
);
269 * If the SET TARGET PORT GROUPS attempts to establish
270 * an invalid combination of target port asymmetric
271 * access states or attempts to establish an
272 * unsupported target port asymmetric access state,
273 * then the command shall be terminated with CHECK
274 * CONDITION status, with the sense key set to ILLEGAL
275 * REQUEST, and the additional sense code set to INVALID
276 * FIELD IN PARAMETER LIST.
282 * If the ASYMMETRIC ACCESS STATE field (see table 267)
283 * specifies a primary target port asymmetric access state,
284 * then the TARGET PORT GROUP OR TARGET PORT field specifies
285 * a primary target port group for which the primary target
286 * port asymmetric access state shall be changed. If the
287 * ASYMMETRIC ACCESS STATE field specifies a secondary target
288 * port asymmetric access state, then the TARGET PORT GROUP OR
289 * TARGET PORT field specifies the relative target port
290 * identifier (see 3.1.120) of the target port for which the
291 * secondary target port asymmetric access state shall be
295 tg_pt_id
= get_unaligned_be16(ptr
+ 2);
297 * Locate the matching target port group ID from
298 * the global tg_pt_gp list
300 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
301 list_for_each_entry(tg_pt_gp
,
302 &dev
->t10_alua
.tg_pt_gps_list
,
304 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
307 if (tg_pt_id
!= tg_pt_gp
->tg_pt_gp_id
)
310 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
311 smp_mb__after_atomic_inc();
313 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
315 if (!core_alua_do_port_transition(tg_pt_gp
,
317 alua_access_state
, 1))
320 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
321 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
322 smp_mb__after_atomic_dec();
325 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
328 * Extract the RELATIVE TARGET PORT IDENTIFIER to identify
329 * the Target Port in question for the the incoming
330 * SET_TARGET_PORT_GROUPS op.
332 rtpi
= get_unaligned_be16(ptr
+ 2);
334 * Locate the matching relative target port identifier
335 * for the struct se_device storage object.
337 spin_lock(&dev
->se_port_lock
);
338 list_for_each_entry(port
, &dev
->dev_sep_list
,
340 if (port
->sep_rtpi
!= rtpi
)
343 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
345 spin_unlock(&dev
->se_port_lock
);
347 if (!core_alua_set_tg_pt_secondary_state(
348 tg_pt_gp_mem
, port
, 1, 1))
351 spin_lock(&dev
->se_port_lock
);
354 spin_unlock(&dev
->se_port_lock
);
358 rc
= TCM_INVALID_PARAMETER_LIST
;
367 transport_kunmap_data_sg(cmd
);
369 target_complete_cmd(cmd
, GOOD
);
373 static inline int core_alua_state_nonoptimized(
376 int nonop_delay_msecs
,
380 * Set SCF_ALUA_NON_OPTIMIZED here, this value will be checked
381 * later to determine if processing of this cmd needs to be
382 * temporarily delayed for the Active/NonOptimized primary access state.
384 cmd
->se_cmd_flags
|= SCF_ALUA_NON_OPTIMIZED
;
385 cmd
->alua_nonop_delay
= nonop_delay_msecs
;
389 static inline int core_alua_state_standby(
395 * Allowed CDBs for ALUA_ACCESS_STATE_STANDBY as defined by
396 * spc4r17 section 5.9.2.4.4
405 case RECEIVE_DIAGNOSTIC
:
406 case SEND_DIAGNOSTIC
:
409 switch (cdb
[1] & 0x1f) {
410 case MI_REPORT_TARGET_PGS
:
413 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
416 case MAINTENANCE_OUT
:
418 case MO_SET_TARGET_PGS
:
421 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
425 case PERSISTENT_RESERVE_IN
:
426 case PERSISTENT_RESERVE_OUT
:
431 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
438 static inline int core_alua_state_unavailable(
444 * Allowed CDBs for ALUA_ACCESS_STATE_UNAVAILABLE as defined by
445 * spc4r17 section 5.9.2.4.5
452 switch (cdb
[1] & 0x1f) {
453 case MI_REPORT_TARGET_PGS
:
456 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
459 case MAINTENANCE_OUT
:
461 case MO_SET_TARGET_PGS
:
464 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
472 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
479 static inline int core_alua_state_transition(
485 * Allowed CDBs for ALUA_ACCESS_STATE_TRANSITION as defined by
486 * spc4r17 section 5.9.2.5
493 switch (cdb
[1] & 0x1f) {
494 case MI_REPORT_TARGET_PGS
:
497 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
505 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
513 * return 1: Is used to signal LUN not accessible, and check condition/not ready
514 * return 0: Used to signal success
515 * return -1: Used to signal failure, and invalid cdb field
518 target_alua_state_check(struct se_cmd
*cmd
)
520 struct se_device
*dev
= cmd
->se_dev
;
521 unsigned char *cdb
= cmd
->t_task_cdb
;
522 struct se_lun
*lun
= cmd
->se_lun
;
523 struct se_port
*port
= lun
->lun_sep
;
524 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
525 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
526 int out_alua_state
, nonop_delay_msecs
;
530 if (dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)
532 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
538 * First, check for a struct se_port specific secondary ALUA target port
539 * access state: OFFLINE
541 if (atomic_read(&port
->sep_tg_pt_secondary_offline
)) {
542 pr_debug("ALUA: Got secondary offline status for local"
544 alua_ascq
= ASCQ_04H_ALUA_OFFLINE
;
549 * Second, obtain the struct t10_alua_tg_pt_gp_member pointer to the
550 * ALUA target port group, to obtain current ALUA access state.
551 * Otherwise look for the underlying struct se_device association with
552 * a ALUA logical unit group.
554 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
558 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
559 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
560 out_alua_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
561 nonop_delay_msecs
= tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
;
562 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
564 * Process ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED in a separate conditional
565 * statement so the compiler knows explicitly to check this case first.
566 * For the Optimized ALUA access state case, we want to process the
567 * incoming fabric cmd ASAP..
569 if (out_alua_state
== ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
)
572 switch (out_alua_state
) {
573 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
574 ret
= core_alua_state_nonoptimized(cmd
, cdb
,
575 nonop_delay_msecs
, &alua_ascq
);
577 case ALUA_ACCESS_STATE_STANDBY
:
578 ret
= core_alua_state_standby(cmd
, cdb
, &alua_ascq
);
580 case ALUA_ACCESS_STATE_UNAVAILABLE
:
581 ret
= core_alua_state_unavailable(cmd
, cdb
, &alua_ascq
);
583 case ALUA_ACCESS_STATE_TRANSITION
:
584 ret
= core_alua_state_transition(cmd
, cdb
, &alua_ascq
);
587 * OFFLINE is a secondary ALUA target port group access state, that is
588 * handled above with struct se_port->sep_tg_pt_secondary_offline=1
590 case ALUA_ACCESS_STATE_OFFLINE
:
592 pr_err("Unknown ALUA access state: 0x%02x\n",
594 return TCM_INVALID_CDB_FIELD
;
600 * Set SCSI additional sense code (ASC) to 'LUN Not Accessible';
601 * The ALUA additional sense code qualifier (ASCQ) is determined
602 * by the ALUA primary or secondary access state..
604 pr_debug("[%s]: ALUA TG Port not available, "
605 "SenseKey: NOT_READY, ASC/ASCQ: "
607 cmd
->se_tfo
->get_fabric_name(), alua_ascq
);
609 cmd
->scsi_asc
= 0x04;
610 cmd
->scsi_ascq
= alua_ascq
;
611 return TCM_CHECK_CONDITION_NOT_READY
;
618 * Check implicit and explicit ALUA state change request.
620 static sense_reason_t
621 core_alua_check_transition(int state
, int *primary
)
624 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
625 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
626 case ALUA_ACCESS_STATE_STANDBY
:
627 case ALUA_ACCESS_STATE_UNAVAILABLE
:
629 * OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
630 * defined as primary target port asymmetric access states.
634 case ALUA_ACCESS_STATE_OFFLINE
:
636 * OFFLINE state is defined as a secondary target port
637 * asymmetric access state.
642 pr_err("Unknown ALUA access state: 0x%02x\n", state
);
643 return TCM_INVALID_PARAMETER_LIST
;
649 static char *core_alua_dump_state(int state
)
652 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
653 return "Active/Optimized";
654 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
655 return "Active/NonOptimized";
656 case ALUA_ACCESS_STATE_STANDBY
:
658 case ALUA_ACCESS_STATE_UNAVAILABLE
:
659 return "Unavailable";
660 case ALUA_ACCESS_STATE_OFFLINE
:
669 char *core_alua_dump_status(int status
)
672 case ALUA_STATUS_NONE
:
674 case ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
:
675 return "Altered by Explicit STPG";
676 case ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
:
677 return "Altered by Implicit ALUA";
686 * Used by fabric modules to determine when we need to delay processing
687 * for the Active/NonOptimized paths..
689 int core_alua_check_nonop_delay(
692 if (!(cmd
->se_cmd_flags
& SCF_ALUA_NON_OPTIMIZED
))
697 * The ALUA Active/NonOptimized access state delay can be disabled
698 * in via configfs with a value of zero
700 if (!cmd
->alua_nonop_delay
)
703 * struct se_cmd->alua_nonop_delay gets set by a target port group
704 * defined interval in core_alua_state_nonoptimized()
706 msleep_interruptible(cmd
->alua_nonop_delay
);
709 EXPORT_SYMBOL(core_alua_check_nonop_delay
);
712 * Called with tg_pt_gp->tg_pt_gp_md_mutex or tg_pt_gp_mem->sep_tg_pt_md_mutex
715 static int core_alua_write_tpg_metadata(
717 unsigned char *md_buf
,
720 struct file
*file
= filp_open(path
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
724 pr_err("filp_open(%s) for ALUA metadata failed\n", path
);
727 ret
= kernel_write(file
, md_buf
, md_buf_len
, 0);
729 pr_err("Error writing ALUA metadata file: %s\n", path
);
731 return (ret
< 0) ? -EIO
: 0;
735 * Called with tg_pt_gp->tg_pt_gp_md_mutex held
737 static int core_alua_update_tpg_primary_metadata(
738 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
740 unsigned char *md_buf
)
742 struct t10_wwn
*wwn
= &tg_pt_gp
->tg_pt_gp_dev
->t10_wwn
;
743 char path
[ALUA_METADATA_PATH_LEN
];
746 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
748 len
= snprintf(md_buf
, tg_pt_gp
->tg_pt_gp_md_buf_len
,
750 "alua_access_state=0x%02x\n"
751 "alua_access_status=0x%02x\n",
752 tg_pt_gp
->tg_pt_gp_id
, primary_state
,
753 tg_pt_gp
->tg_pt_gp_alua_access_status
);
755 snprintf(path
, ALUA_METADATA_PATH_LEN
,
756 "/var/target/alua/tpgs_%s/%s", &wwn
->unit_serial
[0],
757 config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
));
759 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
762 static int core_alua_do_transition_tg_pt(
763 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
764 struct se_port
*l_port
,
765 struct se_node_acl
*nacl
,
766 unsigned char *md_buf
,
770 struct se_dev_entry
*se_deve
;
771 struct se_lun_acl
*lacl
;
772 struct se_port
*port
;
773 struct t10_alua_tg_pt_gp_member
*mem
;
776 * Save the old primary ALUA access state, and set the current state
777 * to ALUA_ACCESS_STATE_TRANSITION.
779 old_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
780 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
781 ALUA_ACCESS_STATE_TRANSITION
);
782 tg_pt_gp
->tg_pt_gp_alua_access_status
= (explicit) ?
783 ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
:
784 ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
;
786 * Check for the optional ALUA primary state transition delay
788 if (tg_pt_gp
->tg_pt_gp_trans_delay_msecs
!= 0)
789 msleep_interruptible(tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
791 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
792 list_for_each_entry(mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
796 * After an implicit target port asymmetric access state
797 * change, a device server shall establish a unit attention
798 * condition for the initiator port associated with every I_T
799 * nexus with the additional sense code set to ASYMMETRIC
800 * ACCESS STATE CHANGED.
802 * After an explicit target port asymmetric access state
803 * change, a device server shall establish a unit attention
804 * condition with the additional sense code set to ASYMMETRIC
805 * ACCESS STATE CHANGED for the initiator port associated with
806 * every I_T nexus other than the I_T nexus on which the SET
807 * TARGET PORT GROUPS command
809 atomic_inc(&mem
->tg_pt_gp_mem_ref_cnt
);
810 smp_mb__after_atomic_inc();
811 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
813 spin_lock_bh(&port
->sep_alua_lock
);
814 list_for_each_entry(se_deve
, &port
->sep_alua_list
,
816 lacl
= se_deve
->se_lun_acl
;
818 * se_deve->se_lun_acl pointer may be NULL for a
819 * entry created without explicit Node+MappedLUN ACLs
825 (nacl
!= NULL
) && (nacl
== lacl
->se_lun_nacl
) &&
826 (l_port
!= NULL
) && (l_port
== port
))
829 core_scsi3_ua_allocate(lacl
->se_lun_nacl
,
830 se_deve
->mapped_lun
, 0x2A,
831 ASCQ_2AH_ASYMMETRIC_ACCESS_STATE_CHANGED
);
833 spin_unlock_bh(&port
->sep_alua_lock
);
835 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
836 atomic_dec(&mem
->tg_pt_gp_mem_ref_cnt
);
837 smp_mb__after_atomic_dec();
839 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
841 * Update the ALUA metadata buf that has been allocated in
842 * core_alua_do_port_transition(), this metadata will be written
845 * Note that there is the case where we do not want to update the
846 * metadata when the saved metadata is being parsed in userspace
847 * when setting the existing port access state and access status.
849 * Also note that the failure to write out the ALUA metadata to
850 * struct file does NOT affect the actual ALUA transition.
852 if (tg_pt_gp
->tg_pt_gp_write_metadata
) {
853 mutex_lock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
854 core_alua_update_tpg_primary_metadata(tg_pt_gp
,
856 mutex_unlock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
859 * Set the current primary ALUA access state to the requested new state
861 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
, new_state
);
863 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
864 " from primary access state %s to %s\n", (explicit) ? "explicit" :
865 "implicit", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
866 tg_pt_gp
->tg_pt_gp_id
, core_alua_dump_state(old_state
),
867 core_alua_dump_state(new_state
));
872 int core_alua_do_port_transition(
873 struct t10_alua_tg_pt_gp
*l_tg_pt_gp
,
874 struct se_device
*l_dev
,
875 struct se_port
*l_port
,
876 struct se_node_acl
*l_nacl
,
880 struct se_device
*dev
;
881 struct se_port
*port
;
882 struct se_node_acl
*nacl
;
883 struct t10_alua_lu_gp
*lu_gp
;
884 struct t10_alua_lu_gp_member
*lu_gp_mem
, *local_lu_gp_mem
;
885 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
886 unsigned char *md_buf
;
889 if (core_alua_check_transition(new_state
, &primary
) != 0)
892 md_buf
= kzalloc(l_tg_pt_gp
->tg_pt_gp_md_buf_len
, GFP_KERNEL
);
894 pr_err("Unable to allocate buf for ALUA metadata\n");
898 local_lu_gp_mem
= l_dev
->dev_alua_lu_gp_mem
;
899 spin_lock(&local_lu_gp_mem
->lu_gp_mem_lock
);
900 lu_gp
= local_lu_gp_mem
->lu_gp
;
901 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
902 smp_mb__after_atomic_inc();
903 spin_unlock(&local_lu_gp_mem
->lu_gp_mem_lock
);
905 * For storage objects that are members of the 'default_lu_gp',
906 * we only do transition on the passed *l_tp_pt_gp, and not
907 * on all of the matching target port groups IDs in default_lu_gp.
909 if (!lu_gp
->lu_gp_id
) {
911 * core_alua_do_transition_tg_pt() will always return
914 core_alua_do_transition_tg_pt(l_tg_pt_gp
, l_port
, l_nacl
,
915 md_buf
, new_state
, explicit);
916 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
917 smp_mb__after_atomic_dec();
922 * For all other LU groups aside from 'default_lu_gp', walk all of
923 * the associated storage objects looking for a matching target port
924 * group ID from the local target port group.
926 spin_lock(&lu_gp
->lu_gp_lock
);
927 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
,
930 dev
= lu_gp_mem
->lu_gp_mem_dev
;
931 atomic_inc(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
932 smp_mb__after_atomic_inc();
933 spin_unlock(&lu_gp
->lu_gp_lock
);
935 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
936 list_for_each_entry(tg_pt_gp
,
937 &dev
->t10_alua
.tg_pt_gps_list
,
940 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
943 * If the target behavior port asymmetric access state
944 * is changed for any target port group accessible via
945 * a logical unit within a LU group, the target port
946 * behavior group asymmetric access states for the same
947 * target port group accessible via other logical units
948 * in that LU group will also change.
950 if (l_tg_pt_gp
->tg_pt_gp_id
!= tg_pt_gp
->tg_pt_gp_id
)
953 if (l_tg_pt_gp
== tg_pt_gp
) {
960 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
961 smp_mb__after_atomic_inc();
962 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
964 * core_alua_do_transition_tg_pt() will always return
967 core_alua_do_transition_tg_pt(tg_pt_gp
, port
,
968 nacl
, md_buf
, new_state
, explicit);
970 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
971 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
972 smp_mb__after_atomic_dec();
974 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
976 spin_lock(&lu_gp
->lu_gp_lock
);
977 atomic_dec(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
978 smp_mb__after_atomic_dec();
980 spin_unlock(&lu_gp
->lu_gp_lock
);
982 pr_debug("Successfully processed LU Group: %s all ALUA TG PT"
983 " Group IDs: %hu %s transition to primary state: %s\n",
984 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
985 l_tg_pt_gp
->tg_pt_gp_id
, (explicit) ? "explicit" : "implicit",
986 core_alua_dump_state(new_state
));
988 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
989 smp_mb__after_atomic_dec();
995 * Called with tg_pt_gp_mem->sep_tg_pt_md_mutex held
997 static int core_alua_update_tpg_secondary_metadata(
998 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
999 struct se_port
*port
,
1000 unsigned char *md_buf
,
1003 struct se_portal_group
*se_tpg
= port
->sep_tpg
;
1004 char path
[ALUA_METADATA_PATH_LEN
], wwn
[ALUA_SECONDARY_METADATA_WWN_LEN
];
1007 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
1008 memset(wwn
, 0, ALUA_SECONDARY_METADATA_WWN_LEN
);
1010 len
= snprintf(wwn
, ALUA_SECONDARY_METADATA_WWN_LEN
, "%s",
1011 se_tpg
->se_tpg_tfo
->tpg_get_wwn(se_tpg
));
1013 if (se_tpg
->se_tpg_tfo
->tpg_get_tag
!= NULL
)
1014 snprintf(wwn
+len
, ALUA_SECONDARY_METADATA_WWN_LEN
-len
, "+%hu",
1015 se_tpg
->se_tpg_tfo
->tpg_get_tag(se_tpg
));
1017 len
= snprintf(md_buf
, md_buf_len
, "alua_tg_pt_offline=%d\n"
1018 "alua_tg_pt_status=0x%02x\n",
1019 atomic_read(&port
->sep_tg_pt_secondary_offline
),
1020 port
->sep_tg_pt_secondary_stat
);
1022 snprintf(path
, ALUA_METADATA_PATH_LEN
, "/var/target/alua/%s/%s/lun_%u",
1023 se_tpg
->se_tpg_tfo
->get_fabric_name(), wwn
,
1024 port
->sep_lun
->unpacked_lun
);
1026 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
1029 static int core_alua_set_tg_pt_secondary_state(
1030 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1031 struct se_port
*port
,
1035 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1036 unsigned char *md_buf
;
1038 int trans_delay_msecs
;
1040 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1041 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1043 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1044 pr_err("Unable to complete secondary state"
1048 trans_delay_msecs
= tg_pt_gp
->tg_pt_gp_trans_delay_msecs
;
1050 * Set the secondary ALUA target port access state to OFFLINE
1051 * or release the previously secondary state for struct se_port
1054 atomic_set(&port
->sep_tg_pt_secondary_offline
, 1);
1056 atomic_set(&port
->sep_tg_pt_secondary_offline
, 0);
1058 md_buf_len
= tg_pt_gp
->tg_pt_gp_md_buf_len
;
1059 port
->sep_tg_pt_secondary_stat
= (explicit) ?
1060 ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
:
1061 ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
;
1063 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
1064 " to secondary access state: %s\n", (explicit) ? "explicit" :
1065 "implicit", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1066 tg_pt_gp
->tg_pt_gp_id
, (offline
) ? "OFFLINE" : "ONLINE");
1068 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1070 * Do the optional transition delay after we set the secondary
1071 * ALUA access state.
1073 if (trans_delay_msecs
!= 0)
1074 msleep_interruptible(trans_delay_msecs
);
1076 * See if we need to update the ALUA fabric port metadata for
1077 * secondary state and status
1079 if (port
->sep_tg_pt_secondary_write_md
) {
1080 md_buf
= kzalloc(md_buf_len
, GFP_KERNEL
);
1082 pr_err("Unable to allocate md_buf for"
1083 " secondary ALUA access metadata\n");
1086 mutex_lock(&port
->sep_tg_pt_md_mutex
);
1087 core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem
, port
,
1088 md_buf
, md_buf_len
);
1089 mutex_unlock(&port
->sep_tg_pt_md_mutex
);
1097 struct t10_alua_lu_gp
*
1098 core_alua_allocate_lu_gp(const char *name
, int def_group
)
1100 struct t10_alua_lu_gp
*lu_gp
;
1102 lu_gp
= kmem_cache_zalloc(t10_alua_lu_gp_cache
, GFP_KERNEL
);
1104 pr_err("Unable to allocate struct t10_alua_lu_gp\n");
1105 return ERR_PTR(-ENOMEM
);
1107 INIT_LIST_HEAD(&lu_gp
->lu_gp_node
);
1108 INIT_LIST_HEAD(&lu_gp
->lu_gp_mem_list
);
1109 spin_lock_init(&lu_gp
->lu_gp_lock
);
1110 atomic_set(&lu_gp
->lu_gp_ref_cnt
, 0);
1113 lu_gp
->lu_gp_id
= alua_lu_gps_counter
++;
1114 lu_gp
->lu_gp_valid_id
= 1;
1115 alua_lu_gps_count
++;
1121 int core_alua_set_lu_gp_id(struct t10_alua_lu_gp
*lu_gp
, u16 lu_gp_id
)
1123 struct t10_alua_lu_gp
*lu_gp_tmp
;
1126 * The lu_gp->lu_gp_id may only be set once..
1128 if (lu_gp
->lu_gp_valid_id
) {
1129 pr_warn("ALUA LU Group already has a valid ID,"
1130 " ignoring request\n");
1134 spin_lock(&lu_gps_lock
);
1135 if (alua_lu_gps_count
== 0x0000ffff) {
1136 pr_err("Maximum ALUA alua_lu_gps_count:"
1137 " 0x0000ffff reached\n");
1138 spin_unlock(&lu_gps_lock
);
1139 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1143 lu_gp_id_tmp
= (lu_gp_id
!= 0) ? lu_gp_id
:
1144 alua_lu_gps_counter
++;
1146 list_for_each_entry(lu_gp_tmp
, &lu_gps_list
, lu_gp_node
) {
1147 if (lu_gp_tmp
->lu_gp_id
== lu_gp_id_tmp
) {
1151 pr_warn("ALUA Logical Unit Group ID: %hu"
1152 " already exists, ignoring request\n",
1154 spin_unlock(&lu_gps_lock
);
1159 lu_gp
->lu_gp_id
= lu_gp_id_tmp
;
1160 lu_gp
->lu_gp_valid_id
= 1;
1161 list_add_tail(&lu_gp
->lu_gp_node
, &lu_gps_list
);
1162 alua_lu_gps_count
++;
1163 spin_unlock(&lu_gps_lock
);
1168 static struct t10_alua_lu_gp_member
*
1169 core_alua_allocate_lu_gp_mem(struct se_device
*dev
)
1171 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1173 lu_gp_mem
= kmem_cache_zalloc(t10_alua_lu_gp_mem_cache
, GFP_KERNEL
);
1175 pr_err("Unable to allocate struct t10_alua_lu_gp_member\n");
1176 return ERR_PTR(-ENOMEM
);
1178 INIT_LIST_HEAD(&lu_gp_mem
->lu_gp_mem_list
);
1179 spin_lock_init(&lu_gp_mem
->lu_gp_mem_lock
);
1180 atomic_set(&lu_gp_mem
->lu_gp_mem_ref_cnt
, 0);
1182 lu_gp_mem
->lu_gp_mem_dev
= dev
;
1183 dev
->dev_alua_lu_gp_mem
= lu_gp_mem
;
1188 void core_alua_free_lu_gp(struct t10_alua_lu_gp
*lu_gp
)
1190 struct t10_alua_lu_gp_member
*lu_gp_mem
, *lu_gp_mem_tmp
;
1192 * Once we have reached this point, config_item_put() has
1193 * already been called from target_core_alua_drop_lu_gp().
1195 * Here, we remove the *lu_gp from the global list so that
1196 * no associations can be made while we are releasing
1197 * struct t10_alua_lu_gp.
1199 spin_lock(&lu_gps_lock
);
1200 list_del(&lu_gp
->lu_gp_node
);
1201 alua_lu_gps_count
--;
1202 spin_unlock(&lu_gps_lock
);
1204 * Allow struct t10_alua_lu_gp * referenced by core_alua_get_lu_gp_by_name()
1205 * in target_core_configfs.c:target_core_store_alua_lu_gp() to be
1206 * released with core_alua_put_lu_gp_from_name()
1208 while (atomic_read(&lu_gp
->lu_gp_ref_cnt
))
1211 * Release reference to struct t10_alua_lu_gp * from all associated
1214 spin_lock(&lu_gp
->lu_gp_lock
);
1215 list_for_each_entry_safe(lu_gp_mem
, lu_gp_mem_tmp
,
1216 &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1217 if (lu_gp_mem
->lu_gp_assoc
) {
1218 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1219 lu_gp
->lu_gp_members
--;
1220 lu_gp_mem
->lu_gp_assoc
= 0;
1222 spin_unlock(&lu_gp
->lu_gp_lock
);
1225 * lu_gp_mem is associated with a single
1226 * struct se_device->dev_alua_lu_gp_mem, and is released when
1227 * struct se_device is released via core_alua_free_lu_gp_mem().
1229 * If the passed lu_gp does NOT match the default_lu_gp, assume
1230 * we want to re-associate a given lu_gp_mem with default_lu_gp.
1232 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1233 if (lu_gp
!= default_lu_gp
)
1234 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
1237 lu_gp_mem
->lu_gp
= NULL
;
1238 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1240 spin_lock(&lu_gp
->lu_gp_lock
);
1242 spin_unlock(&lu_gp
->lu_gp_lock
);
1244 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1247 void core_alua_free_lu_gp_mem(struct se_device
*dev
)
1249 struct t10_alua_lu_gp
*lu_gp
;
1250 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1252 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1256 while (atomic_read(&lu_gp_mem
->lu_gp_mem_ref_cnt
))
1259 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1260 lu_gp
= lu_gp_mem
->lu_gp
;
1262 spin_lock(&lu_gp
->lu_gp_lock
);
1263 if (lu_gp_mem
->lu_gp_assoc
) {
1264 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1265 lu_gp
->lu_gp_members
--;
1266 lu_gp_mem
->lu_gp_assoc
= 0;
1268 spin_unlock(&lu_gp
->lu_gp_lock
);
1269 lu_gp_mem
->lu_gp
= NULL
;
1271 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1273 kmem_cache_free(t10_alua_lu_gp_mem_cache
, lu_gp_mem
);
1276 struct t10_alua_lu_gp
*core_alua_get_lu_gp_by_name(const char *name
)
1278 struct t10_alua_lu_gp
*lu_gp
;
1279 struct config_item
*ci
;
1281 spin_lock(&lu_gps_lock
);
1282 list_for_each_entry(lu_gp
, &lu_gps_list
, lu_gp_node
) {
1283 if (!lu_gp
->lu_gp_valid_id
)
1285 ci
= &lu_gp
->lu_gp_group
.cg_item
;
1286 if (!strcmp(config_item_name(ci
), name
)) {
1287 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
1288 spin_unlock(&lu_gps_lock
);
1292 spin_unlock(&lu_gps_lock
);
1297 void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp
*lu_gp
)
1299 spin_lock(&lu_gps_lock
);
1300 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
1301 spin_unlock(&lu_gps_lock
);
1305 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1307 void __core_alua_attach_lu_gp_mem(
1308 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1309 struct t10_alua_lu_gp
*lu_gp
)
1311 spin_lock(&lu_gp
->lu_gp_lock
);
1312 lu_gp_mem
->lu_gp
= lu_gp
;
1313 lu_gp_mem
->lu_gp_assoc
= 1;
1314 list_add_tail(&lu_gp_mem
->lu_gp_mem_list
, &lu_gp
->lu_gp_mem_list
);
1315 lu_gp
->lu_gp_members
++;
1316 spin_unlock(&lu_gp
->lu_gp_lock
);
1320 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1322 void __core_alua_drop_lu_gp_mem(
1323 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1324 struct t10_alua_lu_gp
*lu_gp
)
1326 spin_lock(&lu_gp
->lu_gp_lock
);
1327 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1328 lu_gp_mem
->lu_gp
= NULL
;
1329 lu_gp_mem
->lu_gp_assoc
= 0;
1330 lu_gp
->lu_gp_members
--;
1331 spin_unlock(&lu_gp
->lu_gp_lock
);
1334 struct t10_alua_tg_pt_gp
*core_alua_allocate_tg_pt_gp(struct se_device
*dev
,
1335 const char *name
, int def_group
)
1337 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1339 tg_pt_gp
= kmem_cache_zalloc(t10_alua_tg_pt_gp_cache
, GFP_KERNEL
);
1341 pr_err("Unable to allocate struct t10_alua_tg_pt_gp\n");
1344 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_list
);
1345 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_mem_list
);
1346 mutex_init(&tg_pt_gp
->tg_pt_gp_md_mutex
);
1347 spin_lock_init(&tg_pt_gp
->tg_pt_gp_lock
);
1348 atomic_set(&tg_pt_gp
->tg_pt_gp_ref_cnt
, 0);
1349 tg_pt_gp
->tg_pt_gp_dev
= dev
;
1350 tg_pt_gp
->tg_pt_gp_md_buf_len
= ALUA_MD_BUF_LEN
;
1351 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
1352 ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
);
1354 * Enable both explicit and implicit ALUA support by default
1356 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1357 TPGS_EXPLICIT_ALUA
| TPGS_IMPLICIT_ALUA
;
1359 * Set the default Active/NonOptimized Delay in milliseconds
1361 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= ALUA_DEFAULT_NONOP_DELAY_MSECS
;
1362 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= ALUA_DEFAULT_TRANS_DELAY_MSECS
;
1363 tg_pt_gp
->tg_pt_gp_implicit_trans_secs
= ALUA_DEFAULT_IMPLICIT_TRANS_SECS
;
1366 * Enable all supported states
1368 tg_pt_gp
->tg_pt_gp_alua_supported_states
=
1369 ALUA_T_SUP
| ALUA_O_SUP
|
1370 ALUA_U_SUP
| ALUA_S_SUP
| ALUA_AN_SUP
| ALUA_AO_SUP
;
1373 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1374 tg_pt_gp
->tg_pt_gp_id
=
1375 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1376 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1377 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1378 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1379 &dev
->t10_alua
.tg_pt_gps_list
);
1380 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1386 int core_alua_set_tg_pt_gp_id(
1387 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1390 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1391 struct t10_alua_tg_pt_gp
*tg_pt_gp_tmp
;
1392 u16 tg_pt_gp_id_tmp
;
1395 * The tg_pt_gp->tg_pt_gp_id may only be set once..
1397 if (tg_pt_gp
->tg_pt_gp_valid_id
) {
1398 pr_warn("ALUA TG PT Group already has a valid ID,"
1399 " ignoring request\n");
1403 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1404 if (dev
->t10_alua
.alua_tg_pt_gps_count
== 0x0000ffff) {
1405 pr_err("Maximum ALUA alua_tg_pt_gps_count:"
1406 " 0x0000ffff reached\n");
1407 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1408 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1412 tg_pt_gp_id_tmp
= (tg_pt_gp_id
!= 0) ? tg_pt_gp_id
:
1413 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1415 list_for_each_entry(tg_pt_gp_tmp
, &dev
->t10_alua
.tg_pt_gps_list
,
1417 if (tg_pt_gp_tmp
->tg_pt_gp_id
== tg_pt_gp_id_tmp
) {
1421 pr_err("ALUA Target Port Group ID: %hu already"
1422 " exists, ignoring request\n", tg_pt_gp_id
);
1423 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1428 tg_pt_gp
->tg_pt_gp_id
= tg_pt_gp_id_tmp
;
1429 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1430 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1431 &dev
->t10_alua
.tg_pt_gps_list
);
1432 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1433 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1438 struct t10_alua_tg_pt_gp_member
*core_alua_allocate_tg_pt_gp_mem(
1439 struct se_port
*port
)
1441 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1443 tg_pt_gp_mem
= kmem_cache_zalloc(t10_alua_tg_pt_gp_mem_cache
,
1445 if (!tg_pt_gp_mem
) {
1446 pr_err("Unable to allocate struct t10_alua_tg_pt_gp_member\n");
1447 return ERR_PTR(-ENOMEM
);
1449 INIT_LIST_HEAD(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1450 spin_lock_init(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1451 atomic_set(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
, 0);
1453 tg_pt_gp_mem
->tg_pt
= port
;
1454 port
->sep_alua_tg_pt_gp_mem
= tg_pt_gp_mem
;
1456 return tg_pt_gp_mem
;
1459 void core_alua_free_tg_pt_gp(
1460 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1462 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1463 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *tg_pt_gp_mem_tmp
;
1466 * Once we have reached this point, config_item_put() has already
1467 * been called from target_core_alua_drop_tg_pt_gp().
1469 * Here we remove *tg_pt_gp from the global list so that
1470 * no associations *OR* explicit ALUA via SET_TARGET_PORT_GROUPS
1471 * can be made while we are releasing struct t10_alua_tg_pt_gp.
1473 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1474 list_del(&tg_pt_gp
->tg_pt_gp_list
);
1475 dev
->t10_alua
.alua_tg_pt_gps_counter
--;
1476 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1479 * Allow a struct t10_alua_tg_pt_gp_member * referenced by
1480 * core_alua_get_tg_pt_gp_by_name() in
1481 * target_core_configfs.c:target_core_store_alua_tg_pt_gp()
1482 * to be released with core_alua_put_tg_pt_gp_from_name().
1484 while (atomic_read(&tg_pt_gp
->tg_pt_gp_ref_cnt
))
1488 * Release reference to struct t10_alua_tg_pt_gp from all associated
1491 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1492 list_for_each_entry_safe(tg_pt_gp_mem
, tg_pt_gp_mem_tmp
,
1493 &tg_pt_gp
->tg_pt_gp_mem_list
, tg_pt_gp_mem_list
) {
1494 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1495 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1496 tg_pt_gp
->tg_pt_gp_members
--;
1497 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1499 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1501 * tg_pt_gp_mem is associated with a single
1502 * se_port->sep_alua_tg_pt_gp_mem, and is released via
1503 * core_alua_free_tg_pt_gp_mem().
1505 * If the passed tg_pt_gp does NOT match the default_tg_pt_gp,
1506 * assume we want to re-associate a given tg_pt_gp_mem with
1509 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1510 if (tg_pt_gp
!= dev
->t10_alua
.default_tg_pt_gp
) {
1511 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1512 dev
->t10_alua
.default_tg_pt_gp
);
1514 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1515 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1517 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1519 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1521 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1524 void core_alua_free_tg_pt_gp_mem(struct se_port
*port
)
1526 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1527 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1529 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1533 while (atomic_read(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
))
1536 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1537 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1539 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1540 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1541 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1542 tg_pt_gp
->tg_pt_gp_members
--;
1543 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1545 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1546 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1548 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1550 kmem_cache_free(t10_alua_tg_pt_gp_mem_cache
, tg_pt_gp_mem
);
1553 static struct t10_alua_tg_pt_gp
*core_alua_get_tg_pt_gp_by_name(
1554 struct se_device
*dev
, const char *name
)
1556 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1557 struct config_item
*ci
;
1559 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1560 list_for_each_entry(tg_pt_gp
, &dev
->t10_alua
.tg_pt_gps_list
,
1562 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
1564 ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1565 if (!strcmp(config_item_name(ci
), name
)) {
1566 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1567 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1571 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1576 static void core_alua_put_tg_pt_gp_from_name(
1577 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1579 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1581 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1582 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1583 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1587 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1589 void __core_alua_attach_tg_pt_gp_mem(
1590 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1591 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1593 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1594 tg_pt_gp_mem
->tg_pt_gp
= tg_pt_gp
;
1595 tg_pt_gp_mem
->tg_pt_gp_assoc
= 1;
1596 list_add_tail(&tg_pt_gp_mem
->tg_pt_gp_mem_list
,
1597 &tg_pt_gp
->tg_pt_gp_mem_list
);
1598 tg_pt_gp
->tg_pt_gp_members
++;
1599 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1603 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1605 static void __core_alua_drop_tg_pt_gp_mem(
1606 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1607 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1609 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1610 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1611 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1612 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1613 tg_pt_gp
->tg_pt_gp_members
--;
1614 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1617 ssize_t
core_alua_show_tg_pt_gp_info(struct se_port
*port
, char *page
)
1619 struct config_item
*tg_pt_ci
;
1620 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1621 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1624 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1628 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1629 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1631 tg_pt_ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1632 len
+= sprintf(page
, "TG Port Alias: %s\nTG Port Group ID:"
1633 " %hu\nTG Port Primary Access State: %s\nTG Port "
1634 "Primary Access Status: %s\nTG Port Secondary Access"
1635 " State: %s\nTG Port Secondary Access Status: %s\n",
1636 config_item_name(tg_pt_ci
), tg_pt_gp
->tg_pt_gp_id
,
1637 core_alua_dump_state(atomic_read(
1638 &tg_pt_gp
->tg_pt_gp_alua_access_state
)),
1639 core_alua_dump_status(
1640 tg_pt_gp
->tg_pt_gp_alua_access_status
),
1641 (atomic_read(&port
->sep_tg_pt_secondary_offline
)) ?
1643 core_alua_dump_status(port
->sep_tg_pt_secondary_stat
));
1645 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1650 ssize_t
core_alua_store_tg_pt_gp_info(
1651 struct se_port
*port
,
1655 struct se_portal_group
*tpg
;
1657 struct se_device
*dev
= port
->sep_lun
->lun_se_dev
;
1658 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *tg_pt_gp_new
= NULL
;
1659 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1660 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
1663 tpg
= port
->sep_tpg
;
1664 lun
= port
->sep_lun
;
1666 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1670 if (count
> TG_PT_GROUP_NAME_BUF
) {
1671 pr_err("ALUA Target Port Group alias too large!\n");
1674 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
1675 memcpy(buf
, page
, count
);
1677 * Any ALUA target port group alias besides "NULL" means we will be
1678 * making a new group association.
1680 if (strcmp(strstrip(buf
), "NULL")) {
1682 * core_alua_get_tg_pt_gp_by_name() will increment reference to
1683 * struct t10_alua_tg_pt_gp. This reference is released with
1684 * core_alua_put_tg_pt_gp_from_name() below.
1686 tg_pt_gp_new
= core_alua_get_tg_pt_gp_by_name(dev
,
1692 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1693 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1696 * Clearing an existing tg_pt_gp association, and replacing
1697 * with the default_tg_pt_gp.
1699 if (!tg_pt_gp_new
) {
1700 pr_debug("Target_Core_ConfigFS: Moving"
1701 " %s/tpgt_%hu/%s from ALUA Target Port Group:"
1702 " alua/%s, ID: %hu back to"
1703 " default_tg_pt_gp\n",
1704 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1705 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1706 config_item_name(&lun
->lun_group
.cg_item
),
1708 &tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1709 tg_pt_gp
->tg_pt_gp_id
);
1711 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1712 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1713 dev
->t10_alua
.default_tg_pt_gp
);
1714 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1719 * Removing existing association of tg_pt_gp_mem with tg_pt_gp
1721 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1725 * Associate tg_pt_gp_mem with tg_pt_gp_new.
1727 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp_new
);
1728 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1729 pr_debug("Target_Core_ConfigFS: %s %s/tpgt_%hu/%s to ALUA"
1730 " Target Port Group: alua/%s, ID: %hu\n", (move
) ?
1731 "Moving" : "Adding", tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1732 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1733 config_item_name(&lun
->lun_group
.cg_item
),
1734 config_item_name(&tg_pt_gp_new
->tg_pt_gp_group
.cg_item
),
1735 tg_pt_gp_new
->tg_pt_gp_id
);
1737 core_alua_put_tg_pt_gp_from_name(tg_pt_gp_new
);
1741 ssize_t
core_alua_show_access_type(
1742 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1745 if ((tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
) &&
1746 (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
))
1747 return sprintf(page
, "Implicit and Explicit\n");
1748 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)
1749 return sprintf(page
, "Implicit\n");
1750 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
)
1751 return sprintf(page
, "Explicit\n");
1753 return sprintf(page
, "None\n");
1756 ssize_t
core_alua_store_access_type(
1757 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1764 ret
= kstrtoul(page
, 0, &tmp
);
1766 pr_err("Unable to extract alua_access_type\n");
1769 if ((tmp
!= 0) && (tmp
!= 1) && (tmp
!= 2) && (tmp
!= 3)) {
1770 pr_err("Illegal value for alua_access_type:"
1775 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1776 TPGS_IMPLICIT_ALUA
| TPGS_EXPLICIT_ALUA
;
1778 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_EXPLICIT_ALUA
;
1780 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_IMPLICIT_ALUA
;
1782 tg_pt_gp
->tg_pt_gp_alua_access_type
= 0;
1787 ssize_t
core_alua_show_nonop_delay_msecs(
1788 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1791 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
);
1794 ssize_t
core_alua_store_nonop_delay_msecs(
1795 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1802 ret
= kstrtoul(page
, 0, &tmp
);
1804 pr_err("Unable to extract nonop_delay_msecs\n");
1807 if (tmp
> ALUA_MAX_NONOP_DELAY_MSECS
) {
1808 pr_err("Passed nonop_delay_msecs: %lu, exceeds"
1809 " ALUA_MAX_NONOP_DELAY_MSECS: %d\n", tmp
,
1810 ALUA_MAX_NONOP_DELAY_MSECS
);
1813 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= (int)tmp
;
1818 ssize_t
core_alua_show_trans_delay_msecs(
1819 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1822 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
1825 ssize_t
core_alua_store_trans_delay_msecs(
1826 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1833 ret
= kstrtoul(page
, 0, &tmp
);
1835 pr_err("Unable to extract trans_delay_msecs\n");
1838 if (tmp
> ALUA_MAX_TRANS_DELAY_MSECS
) {
1839 pr_err("Passed trans_delay_msecs: %lu, exceeds"
1840 " ALUA_MAX_TRANS_DELAY_MSECS: %d\n", tmp
,
1841 ALUA_MAX_TRANS_DELAY_MSECS
);
1844 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= (int)tmp
;
1849 ssize_t
core_alua_show_implicit_trans_secs(
1850 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1853 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_implicit_trans_secs
);
1856 ssize_t
core_alua_store_implicit_trans_secs(
1857 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1864 ret
= kstrtoul(page
, 0, &tmp
);
1866 pr_err("Unable to extract implicit_trans_secs\n");
1869 if (tmp
> ALUA_MAX_IMPLICIT_TRANS_SECS
) {
1870 pr_err("Passed implicit_trans_secs: %lu, exceeds"
1871 " ALUA_MAX_IMPLICIT_TRANS_SECS: %d\n", tmp
,
1872 ALUA_MAX_IMPLICIT_TRANS_SECS
);
1875 tg_pt_gp
->tg_pt_gp_implicit_trans_secs
= (int)tmp
;
1880 ssize_t
core_alua_show_preferred_bit(
1881 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1884 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_pref
);
1887 ssize_t
core_alua_store_preferred_bit(
1888 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1895 ret
= kstrtoul(page
, 0, &tmp
);
1897 pr_err("Unable to extract preferred ALUA value\n");
1900 if ((tmp
!= 0) && (tmp
!= 1)) {
1901 pr_err("Illegal value for preferred ALUA: %lu\n", tmp
);
1904 tg_pt_gp
->tg_pt_gp_pref
= (int)tmp
;
1909 ssize_t
core_alua_show_offline_bit(struct se_lun
*lun
, char *page
)
1914 return sprintf(page
, "%d\n",
1915 atomic_read(&lun
->lun_sep
->sep_tg_pt_secondary_offline
));
1918 ssize_t
core_alua_store_offline_bit(
1923 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1930 ret
= kstrtoul(page
, 0, &tmp
);
1932 pr_err("Unable to extract alua_tg_pt_offline value\n");
1935 if ((tmp
!= 0) && (tmp
!= 1)) {
1936 pr_err("Illegal value for alua_tg_pt_offline: %lu\n",
1940 tg_pt_gp_mem
= lun
->lun_sep
->sep_alua_tg_pt_gp_mem
;
1941 if (!tg_pt_gp_mem
) {
1942 pr_err("Unable to locate *tg_pt_gp_mem\n");
1946 ret
= core_alua_set_tg_pt_secondary_state(tg_pt_gp_mem
,
1947 lun
->lun_sep
, 0, (int)tmp
);
1954 ssize_t
core_alua_show_secondary_status(
1958 return sprintf(page
, "%d\n", lun
->lun_sep
->sep_tg_pt_secondary_stat
);
1961 ssize_t
core_alua_store_secondary_status(
1969 ret
= kstrtoul(page
, 0, &tmp
);
1971 pr_err("Unable to extract alua_tg_pt_status\n");
1974 if ((tmp
!= ALUA_STATUS_NONE
) &&
1975 (tmp
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
1976 (tmp
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
1977 pr_err("Illegal value for alua_tg_pt_status: %lu\n",
1981 lun
->lun_sep
->sep_tg_pt_secondary_stat
= (int)tmp
;
1986 ssize_t
core_alua_show_secondary_write_metadata(
1990 return sprintf(page
, "%d\n",
1991 lun
->lun_sep
->sep_tg_pt_secondary_write_md
);
1994 ssize_t
core_alua_store_secondary_write_metadata(
2002 ret
= kstrtoul(page
, 0, &tmp
);
2004 pr_err("Unable to extract alua_tg_pt_write_md\n");
2007 if ((tmp
!= 0) && (tmp
!= 1)) {
2008 pr_err("Illegal value for alua_tg_pt_write_md:"
2012 lun
->lun_sep
->sep_tg_pt_secondary_write_md
= (int)tmp
;
2017 int core_setup_alua(struct se_device
*dev
)
2019 if (dev
->transport
->transport_type
!= TRANSPORT_PLUGIN_PHBA_PDEV
&&
2020 !(dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)) {
2021 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2024 * Associate this struct se_device with the default ALUA
2027 lu_gp_mem
= core_alua_allocate_lu_gp_mem(dev
);
2028 if (IS_ERR(lu_gp_mem
))
2029 return PTR_ERR(lu_gp_mem
);
2031 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
2032 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
2034 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2036 pr_debug("%s: Adding to default ALUA LU Group:"
2037 " core/alua/lu_gps/default_lu_gp\n",
2038 dev
->transport
->name
);