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 <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 explict
, 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
] = 0x80; /* T_SUP */
121 buf
[off
] |= 0x40; /* O_SUP */
122 buf
[off
] |= 0x8; /* U_SUP */
123 buf
[off
] |= 0x4; /* S_SUP */
124 buf
[off
] |= 0x2; /* AN_SUP */
125 buf
[off
++] |= 0x1; /* AO_SUP */
129 buf
[off
++] = ((tg_pt_gp
->tg_pt_gp_id
>> 8) & 0xff);
130 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_id
& 0xff);
132 off
++; /* Skip over Reserved */
136 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_alua_access_status
& 0xff);
138 * Vendor Specific field
144 buf
[off
++] = (tg_pt_gp
->tg_pt_gp_members
& 0xff);
147 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
148 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
150 port
= tg_pt_gp_mem
->tg_pt
;
152 * Start Target Port descriptor format
154 * See spc4r17 section 6.2.7 Table 247
156 off
+= 2; /* Skip over Obsolete */
158 * Set RELATIVE TARGET PORT IDENTIFIER
160 buf
[off
++] = ((port
->sep_rtpi
>> 8) & 0xff);
161 buf
[off
++] = (port
->sep_rtpi
& 0xff);
164 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
166 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
168 * Set the RETURN DATA LENGTH set in the header of the DataIN Payload
170 put_unaligned_be32(rd_len
, &buf
[0]);
173 * Fill in the Extended header parameter data format if requested
178 * Set the implict transition time (in seconds) for the application
179 * client to use as a base for it's transition timeout value.
181 * Use the current tg_pt_gp_mem -> tg_pt_gp membership from the LUN
182 * this CDB was received upon to determine this value individually
183 * for ALUA target port group.
185 port
= cmd
->se_lun
->lun_sep
;
186 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
188 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
189 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
191 buf
[5] = tg_pt_gp
->tg_pt_gp_implict_trans_secs
;
192 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
195 transport_kunmap_data_sg(cmd
);
197 target_complete_cmd(cmd
, GOOD
);
202 * SET_TARGET_PORT_GROUPS for explict ALUA operation.
204 * See spc4r17 section 6.35
207 target_emulate_set_target_port_groups(struct se_cmd
*cmd
)
209 struct se_device
*dev
= cmd
->se_dev
;
210 struct se_port
*port
, *l_port
= cmd
->se_lun
->lun_sep
;
211 struct se_node_acl
*nacl
= cmd
->se_sess
->se_node_acl
;
212 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *l_tg_pt_gp
;
213 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *l_tg_pt_gp_mem
;
216 sense_reason_t rc
= TCM_NO_SENSE
;
217 u32 len
= 4; /* Skip over RESERVED area in header */
218 int alua_access_state
, primary
= 0;
222 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
224 if (cmd
->data_length
< 4) {
225 pr_warn("SET TARGET PORT GROUPS parameter list length %u too"
226 " small\n", cmd
->data_length
);
227 return TCM_INVALID_PARAMETER_LIST
;
230 buf
= transport_kmap_data_sg(cmd
);
232 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
235 * Determine if explict ALUA via SET_TARGET_PORT_GROUPS is allowed
236 * for the local tg_pt_gp.
238 l_tg_pt_gp_mem
= l_port
->sep_alua_tg_pt_gp_mem
;
239 if (!l_tg_pt_gp_mem
) {
240 pr_err("Unable to access l_port->sep_alua_tg_pt_gp_mem\n");
241 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
244 spin_lock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
245 l_tg_pt_gp
= l_tg_pt_gp_mem
->tg_pt_gp
;
247 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
248 pr_err("Unable to access *l_tg_pt_gp_mem->tg_pt_gp\n");
249 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
252 spin_unlock(&l_tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
254 if (!(l_tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
)) {
255 pr_debug("Unable to process SET_TARGET_PORT_GROUPS"
256 " while TPGS_EXPLICT_ALUA is disabled\n");
257 rc
= TCM_UNSUPPORTED_SCSI_OPCODE
;
261 ptr
= &buf
[4]; /* Skip over RESERVED area in header */
263 while (len
< cmd
->data_length
) {
265 alua_access_state
= (ptr
[0] & 0x0f);
267 * Check the received ALUA access state, and determine if
268 * the state is a primary or secondary target port asymmetric
271 rc
= core_alua_check_transition(alua_access_state
, &primary
);
274 * If the SET TARGET PORT GROUPS attempts to establish
275 * an invalid combination of target port asymmetric
276 * access states or attempts to establish an
277 * unsupported target port asymmetric access state,
278 * then the command shall be terminated with CHECK
279 * CONDITION status, with the sense key set to ILLEGAL
280 * REQUEST, and the additional sense code set to INVALID
281 * FIELD IN PARAMETER LIST.
287 * If the ASYMMETRIC ACCESS STATE field (see table 267)
288 * specifies a primary target port asymmetric access state,
289 * then the TARGET PORT GROUP OR TARGET PORT field specifies
290 * a primary target port group for which the primary target
291 * port asymmetric access state shall be changed. If the
292 * ASYMMETRIC ACCESS STATE field specifies a secondary target
293 * port asymmetric access state, then the TARGET PORT GROUP OR
294 * TARGET PORT field specifies the relative target port
295 * identifier (see 3.1.120) of the target port for which the
296 * secondary target port asymmetric access state shall be
300 tg_pt_id
= get_unaligned_be16(ptr
+ 2);
302 * Locate the matching target port group ID from
303 * the global tg_pt_gp list
305 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
306 list_for_each_entry(tg_pt_gp
,
307 &dev
->t10_alua
.tg_pt_gps_list
,
309 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
312 if (tg_pt_id
!= tg_pt_gp
->tg_pt_gp_id
)
315 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
316 smp_mb__after_atomic_inc();
318 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
320 if (!core_alua_do_port_transition(tg_pt_gp
,
322 alua_access_state
, 1))
325 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
326 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
327 smp_mb__after_atomic_dec();
330 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
333 * Extact the RELATIVE TARGET PORT IDENTIFIER to identify
334 * the Target Port in question for the the incoming
335 * SET_TARGET_PORT_GROUPS op.
337 rtpi
= get_unaligned_be16(ptr
+ 2);
339 * Locate the matching relative target port identifier
340 * for the struct se_device storage object.
342 spin_lock(&dev
->se_port_lock
);
343 list_for_each_entry(port
, &dev
->dev_sep_list
,
345 if (port
->sep_rtpi
!= rtpi
)
348 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
350 spin_unlock(&dev
->se_port_lock
);
352 if (!core_alua_set_tg_pt_secondary_state(
353 tg_pt_gp_mem
, port
, 1, 1))
356 spin_lock(&dev
->se_port_lock
);
359 spin_unlock(&dev
->se_port_lock
);
363 rc
= TCM_INVALID_PARAMETER_LIST
;
372 transport_kunmap_data_sg(cmd
);
374 target_complete_cmd(cmd
, GOOD
);
378 static inline int core_alua_state_nonoptimized(
381 int nonop_delay_msecs
,
385 * Set SCF_ALUA_NON_OPTIMIZED here, this value will be checked
386 * later to determine if processing of this cmd needs to be
387 * temporarily delayed for the Active/NonOptimized primary access state.
389 cmd
->se_cmd_flags
|= SCF_ALUA_NON_OPTIMIZED
;
390 cmd
->alua_nonop_delay
= nonop_delay_msecs
;
394 static inline int core_alua_state_standby(
400 * Allowed CDBs for ALUA_ACCESS_STATE_STANDBY as defined by
401 * spc4r17 section 5.9.2.4.4
410 case RECEIVE_DIAGNOSTIC
:
411 case SEND_DIAGNOSTIC
:
414 switch (cdb
[1] & 0x1f) {
415 case MI_REPORT_TARGET_PGS
:
418 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
421 case MAINTENANCE_OUT
:
423 case MO_SET_TARGET_PGS
:
426 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
430 case PERSISTENT_RESERVE_IN
:
431 case PERSISTENT_RESERVE_OUT
:
436 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_STANDBY
;
443 static inline int core_alua_state_unavailable(
449 * Allowed CDBs for ALUA_ACCESS_STATE_UNAVAILABLE as defined by
450 * spc4r17 section 5.9.2.4.5
457 switch (cdb
[1] & 0x1f) {
458 case MI_REPORT_TARGET_PGS
:
461 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
464 case MAINTENANCE_OUT
:
466 case MO_SET_TARGET_PGS
:
469 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
477 *alua_ascq
= ASCQ_04H_ALUA_TG_PT_UNAVAILABLE
;
484 static inline int core_alua_state_transition(
490 * Allowed CDBs for ALUA_ACCESS_STATE_TRANSITIO as defined by
491 * spc4r17 section 5.9.2.5
498 switch (cdb
[1] & 0x1f) {
499 case MI_REPORT_TARGET_PGS
:
502 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
510 *alua_ascq
= ASCQ_04H_ALUA_STATE_TRANSITION
;
518 * return 1: Is used to signal LUN not accecsable, and check condition/not ready
519 * return 0: Used to signal success
520 * reutrn -1: Used to signal failure, and invalid cdb field
523 target_alua_state_check(struct se_cmd
*cmd
)
525 struct se_device
*dev
= cmd
->se_dev
;
526 unsigned char *cdb
= cmd
->t_task_cdb
;
527 struct se_lun
*lun
= cmd
->se_lun
;
528 struct se_port
*port
= lun
->lun_sep
;
529 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
530 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
531 int out_alua_state
, nonop_delay_msecs
;
535 if (dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)
537 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
543 * First, check for a struct se_port specific secondary ALUA target port
544 * access state: OFFLINE
546 if (atomic_read(&port
->sep_tg_pt_secondary_offline
)) {
547 pr_debug("ALUA: Got secondary offline status for local"
549 alua_ascq
= ASCQ_04H_ALUA_OFFLINE
;
554 * Second, obtain the struct t10_alua_tg_pt_gp_member pointer to the
555 * ALUA target port group, to obtain current ALUA access state.
556 * Otherwise look for the underlying struct se_device association with
557 * a ALUA logical unit group.
559 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
560 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
561 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
562 out_alua_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
563 nonop_delay_msecs
= tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
;
564 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
566 * Process ALUA_ACCESS_STATE_ACTIVE_OPTMIZED in a separate conditional
567 * statement so the compiler knows explicitly to check this case first.
568 * For the Optimized ALUA access state case, we want to process the
569 * incoming fabric cmd ASAP..
571 if (out_alua_state
== ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
)
574 switch (out_alua_state
) {
575 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
576 ret
= core_alua_state_nonoptimized(cmd
, cdb
,
577 nonop_delay_msecs
, &alua_ascq
);
579 case ALUA_ACCESS_STATE_STANDBY
:
580 ret
= core_alua_state_standby(cmd
, cdb
, &alua_ascq
);
582 case ALUA_ACCESS_STATE_UNAVAILABLE
:
583 ret
= core_alua_state_unavailable(cmd
, cdb
, &alua_ascq
);
585 case ALUA_ACCESS_STATE_TRANSITION
:
586 ret
= core_alua_state_transition(cmd
, cdb
, &alua_ascq
);
589 * OFFLINE is a secondary ALUA target port group access state, that is
590 * handled above with struct se_port->sep_tg_pt_secondary_offline=1
592 case ALUA_ACCESS_STATE_OFFLINE
:
594 pr_err("Unknown ALUA access state: 0x%02x\n",
596 return TCM_INVALID_CDB_FIELD
;
602 * Set SCSI additional sense code (ASC) to 'LUN Not Accessible';
603 * The ALUA additional sense code qualifier (ASCQ) is determined
604 * by the ALUA primary or secondary access state..
606 pr_debug("[%s]: ALUA TG Port not available, "
607 "SenseKey: NOT_READY, ASC/ASCQ: "
609 cmd
->se_tfo
->get_fabric_name(), alua_ascq
);
611 cmd
->scsi_asc
= 0x04;
612 cmd
->scsi_ascq
= alua_ascq
;
613 return TCM_CHECK_CONDITION_NOT_READY
;
620 * Check implict and explict ALUA state change request.
622 static sense_reason_t
623 core_alua_check_transition(int state
, int *primary
)
626 case ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
:
627 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
628 case ALUA_ACCESS_STATE_STANDBY
:
629 case ALUA_ACCESS_STATE_UNAVAILABLE
:
631 * OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are
632 * defined as primary target port asymmetric access states.
636 case ALUA_ACCESS_STATE_OFFLINE
:
638 * OFFLINE state is defined as a secondary target port
639 * asymmetric access state.
644 pr_err("Unknown ALUA access state: 0x%02x\n", state
);
645 return TCM_INVALID_PARAMETER_LIST
;
651 static char *core_alua_dump_state(int state
)
654 case ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
:
655 return "Active/Optimized";
656 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
657 return "Active/NonOptimized";
658 case ALUA_ACCESS_STATE_STANDBY
:
660 case ALUA_ACCESS_STATE_UNAVAILABLE
:
661 return "Unavailable";
662 case ALUA_ACCESS_STATE_OFFLINE
:
671 char *core_alua_dump_status(int status
)
674 case ALUA_STATUS_NONE
:
676 case ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
677 return "Altered by Explict STPG";
678 case ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
:
679 return "Altered by Implict ALUA";
688 * Used by fabric modules to determine when we need to delay processing
689 * for the Active/NonOptimized paths..
691 int core_alua_check_nonop_delay(
694 if (!(cmd
->se_cmd_flags
& SCF_ALUA_NON_OPTIMIZED
))
699 * The ALUA Active/NonOptimized access state delay can be disabled
700 * in via configfs with a value of zero
702 if (!cmd
->alua_nonop_delay
)
705 * struct se_cmd->alua_nonop_delay gets set by a target port group
706 * defined interval in core_alua_state_nonoptimized()
708 msleep_interruptible(cmd
->alua_nonop_delay
);
711 EXPORT_SYMBOL(core_alua_check_nonop_delay
);
714 * Called with tg_pt_gp->tg_pt_gp_md_mutex or tg_pt_gp_mem->sep_tg_pt_md_mutex
717 static int core_alua_write_tpg_metadata(
719 unsigned char *md_buf
,
722 struct file
*file
= filp_open(path
, O_RDWR
| O_CREAT
| O_TRUNC
, 0600);
726 pr_err("filp_open(%s) for ALUA metadata failed\n", path
);
729 ret
= kernel_write(file
, md_buf
, md_buf_len
, 0);
731 pr_err("Error writing ALUA metadata file: %s\n", path
);
733 return ret
? -EIO
: 0;
737 * Called with tg_pt_gp->tg_pt_gp_md_mutex held
739 static int core_alua_update_tpg_primary_metadata(
740 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
742 unsigned char *md_buf
)
744 struct t10_wwn
*wwn
= &tg_pt_gp
->tg_pt_gp_dev
->t10_wwn
;
745 char path
[ALUA_METADATA_PATH_LEN
];
748 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
750 len
= snprintf(md_buf
, tg_pt_gp
->tg_pt_gp_md_buf_len
,
752 "alua_access_state=0x%02x\n"
753 "alua_access_status=0x%02x\n",
754 tg_pt_gp
->tg_pt_gp_id
, primary_state
,
755 tg_pt_gp
->tg_pt_gp_alua_access_status
);
757 snprintf(path
, ALUA_METADATA_PATH_LEN
,
758 "/var/target/alua/tpgs_%s/%s", &wwn
->unit_serial
[0],
759 config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
));
761 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
764 static int core_alua_do_transition_tg_pt(
765 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
766 struct se_port
*l_port
,
767 struct se_node_acl
*nacl
,
768 unsigned char *md_buf
,
772 struct se_dev_entry
*se_deve
;
773 struct se_lun_acl
*lacl
;
774 struct se_port
*port
;
775 struct t10_alua_tg_pt_gp_member
*mem
;
778 * Save the old primary ALUA access state, and set the current state
779 * to ALUA_ACCESS_STATE_TRANSITION.
781 old_state
= atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
);
782 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
783 ALUA_ACCESS_STATE_TRANSITION
);
784 tg_pt_gp
->tg_pt_gp_alua_access_status
= (explict
) ?
785 ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
786 ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
;
788 * Check for the optional ALUA primary state transition delay
790 if (tg_pt_gp
->tg_pt_gp_trans_delay_msecs
!= 0)
791 msleep_interruptible(tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
793 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
794 list_for_each_entry(mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
798 * After an implicit target port asymmetric access state
799 * change, a device server shall establish a unit attention
800 * condition for the initiator port associated with every I_T
801 * nexus with the additional sense code set to ASYMMETRIC
802 * ACCESS STATE CHAGED.
804 * After an explicit target port asymmetric access state
805 * change, a device server shall establish a unit attention
806 * condition with the additional sense code set to ASYMMETRIC
807 * ACCESS STATE CHANGED for the initiator port associated with
808 * every I_T nexus other than the I_T nexus on which the SET
809 * TARGET PORT GROUPS command
811 atomic_inc(&mem
->tg_pt_gp_mem_ref_cnt
);
812 smp_mb__after_atomic_inc();
813 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
815 spin_lock_bh(&port
->sep_alua_lock
);
816 list_for_each_entry(se_deve
, &port
->sep_alua_list
,
818 lacl
= se_deve
->se_lun_acl
;
820 * se_deve->se_lun_acl pointer may be NULL for a
821 * entry created without explict Node+MappedLUN ACLs
827 (nacl
!= NULL
) && (nacl
== lacl
->se_lun_nacl
) &&
828 (l_port
!= NULL
) && (l_port
== port
))
831 core_scsi3_ua_allocate(lacl
->se_lun_nacl
,
832 se_deve
->mapped_lun
, 0x2A,
833 ASCQ_2AH_ASYMMETRIC_ACCESS_STATE_CHANGED
);
835 spin_unlock_bh(&port
->sep_alua_lock
);
837 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
838 atomic_dec(&mem
->tg_pt_gp_mem_ref_cnt
);
839 smp_mb__after_atomic_dec();
841 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
843 * Update the ALUA metadata buf that has been allocated in
844 * core_alua_do_port_transition(), this metadata will be written
847 * Note that there is the case where we do not want to update the
848 * metadata when the saved metadata is being parsed in userspace
849 * when setting the existing port access state and access status.
851 * Also note that the failure to write out the ALUA metadata to
852 * struct file does NOT affect the actual ALUA transition.
854 if (tg_pt_gp
->tg_pt_gp_write_metadata
) {
855 mutex_lock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
856 core_alua_update_tpg_primary_metadata(tg_pt_gp
,
858 mutex_unlock(&tg_pt_gp
->tg_pt_gp_md_mutex
);
861 * Set the current primary ALUA access state to the requested new state
863 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
, new_state
);
865 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
866 " from primary access state %s to %s\n", (explict
) ? "explict" :
867 "implict", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
868 tg_pt_gp
->tg_pt_gp_id
, core_alua_dump_state(old_state
),
869 core_alua_dump_state(new_state
));
874 int core_alua_do_port_transition(
875 struct t10_alua_tg_pt_gp
*l_tg_pt_gp
,
876 struct se_device
*l_dev
,
877 struct se_port
*l_port
,
878 struct se_node_acl
*l_nacl
,
882 struct se_device
*dev
;
883 struct se_port
*port
;
884 struct se_node_acl
*nacl
;
885 struct t10_alua_lu_gp
*lu_gp
;
886 struct t10_alua_lu_gp_member
*lu_gp_mem
, *local_lu_gp_mem
;
887 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
888 unsigned char *md_buf
;
891 if (core_alua_check_transition(new_state
, &primary
) != 0)
894 md_buf
= kzalloc(l_tg_pt_gp
->tg_pt_gp_md_buf_len
, GFP_KERNEL
);
896 pr_err("Unable to allocate buf for ALUA metadata\n");
900 local_lu_gp_mem
= l_dev
->dev_alua_lu_gp_mem
;
901 spin_lock(&local_lu_gp_mem
->lu_gp_mem_lock
);
902 lu_gp
= local_lu_gp_mem
->lu_gp
;
903 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
904 smp_mb__after_atomic_inc();
905 spin_unlock(&local_lu_gp_mem
->lu_gp_mem_lock
);
907 * For storage objects that are members of the 'default_lu_gp',
908 * we only do transition on the passed *l_tp_pt_gp, and not
909 * on all of the matching target port groups IDs in default_lu_gp.
911 if (!lu_gp
->lu_gp_id
) {
913 * core_alua_do_transition_tg_pt() will always return
916 core_alua_do_transition_tg_pt(l_tg_pt_gp
, l_port
, l_nacl
,
917 md_buf
, new_state
, explict
);
918 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
919 smp_mb__after_atomic_dec();
924 * For all other LU groups aside from 'default_lu_gp', walk all of
925 * the associated storage objects looking for a matching target port
926 * group ID from the local target port group.
928 spin_lock(&lu_gp
->lu_gp_lock
);
929 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
,
932 dev
= lu_gp_mem
->lu_gp_mem_dev
;
933 atomic_inc(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
934 smp_mb__after_atomic_inc();
935 spin_unlock(&lu_gp
->lu_gp_lock
);
937 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
938 list_for_each_entry(tg_pt_gp
,
939 &dev
->t10_alua
.tg_pt_gps_list
,
942 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
945 * If the target behavior port asymmetric access state
946 * is changed for any target port group accessiable via
947 * a logical unit within a LU group, the target port
948 * behavior group asymmetric access states for the same
949 * target port group accessible via other logical units
950 * in that LU group will also change.
952 if (l_tg_pt_gp
->tg_pt_gp_id
!= tg_pt_gp
->tg_pt_gp_id
)
955 if (l_tg_pt_gp
== tg_pt_gp
) {
962 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
963 smp_mb__after_atomic_inc();
964 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
966 * core_alua_do_transition_tg_pt() will always return
969 core_alua_do_transition_tg_pt(tg_pt_gp
, port
,
970 nacl
, md_buf
, new_state
, explict
);
972 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
973 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
974 smp_mb__after_atomic_dec();
976 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
978 spin_lock(&lu_gp
->lu_gp_lock
);
979 atomic_dec(&lu_gp_mem
->lu_gp_mem_ref_cnt
);
980 smp_mb__after_atomic_dec();
982 spin_unlock(&lu_gp
->lu_gp_lock
);
984 pr_debug("Successfully processed LU Group: %s all ALUA TG PT"
985 " Group IDs: %hu %s transition to primary state: %s\n",
986 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
987 l_tg_pt_gp
->tg_pt_gp_id
, (explict
) ? "explict" : "implict",
988 core_alua_dump_state(new_state
));
990 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
991 smp_mb__after_atomic_dec();
997 * Called with tg_pt_gp_mem->sep_tg_pt_md_mutex held
999 static int core_alua_update_tpg_secondary_metadata(
1000 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1001 struct se_port
*port
,
1002 unsigned char *md_buf
,
1005 struct se_portal_group
*se_tpg
= port
->sep_tpg
;
1006 char path
[ALUA_METADATA_PATH_LEN
], wwn
[ALUA_SECONDARY_METADATA_WWN_LEN
];
1009 memset(path
, 0, ALUA_METADATA_PATH_LEN
);
1010 memset(wwn
, 0, ALUA_SECONDARY_METADATA_WWN_LEN
);
1012 len
= snprintf(wwn
, ALUA_SECONDARY_METADATA_WWN_LEN
, "%s",
1013 se_tpg
->se_tpg_tfo
->tpg_get_wwn(se_tpg
));
1015 if (se_tpg
->se_tpg_tfo
->tpg_get_tag
!= NULL
)
1016 snprintf(wwn
+len
, ALUA_SECONDARY_METADATA_WWN_LEN
-len
, "+%hu",
1017 se_tpg
->se_tpg_tfo
->tpg_get_tag(se_tpg
));
1019 len
= snprintf(md_buf
, md_buf_len
, "alua_tg_pt_offline=%d\n"
1020 "alua_tg_pt_status=0x%02x\n",
1021 atomic_read(&port
->sep_tg_pt_secondary_offline
),
1022 port
->sep_tg_pt_secondary_stat
);
1024 snprintf(path
, ALUA_METADATA_PATH_LEN
, "/var/target/alua/%s/%s/lun_%u",
1025 se_tpg
->se_tpg_tfo
->get_fabric_name(), wwn
,
1026 port
->sep_lun
->unpacked_lun
);
1028 return core_alua_write_tpg_metadata(path
, md_buf
, len
);
1031 static int core_alua_set_tg_pt_secondary_state(
1032 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1033 struct se_port
*port
,
1037 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1038 unsigned char *md_buf
;
1040 int trans_delay_msecs
;
1042 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1043 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1045 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1046 pr_err("Unable to complete secondary state"
1050 trans_delay_msecs
= tg_pt_gp
->tg_pt_gp_trans_delay_msecs
;
1052 * Set the secondary ALUA target port access state to OFFLINE
1053 * or release the previously secondary state for struct se_port
1056 atomic_set(&port
->sep_tg_pt_secondary_offline
, 1);
1058 atomic_set(&port
->sep_tg_pt_secondary_offline
, 0);
1060 md_buf_len
= tg_pt_gp
->tg_pt_gp_md_buf_len
;
1061 port
->sep_tg_pt_secondary_stat
= (explict
) ?
1062 ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
:
1063 ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
;
1065 pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu"
1066 " to secondary access state: %s\n", (explict
) ? "explict" :
1067 "implict", config_item_name(&tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1068 tg_pt_gp
->tg_pt_gp_id
, (offline
) ? "OFFLINE" : "ONLINE");
1070 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1072 * Do the optional transition delay after we set the secondary
1073 * ALUA access state.
1075 if (trans_delay_msecs
!= 0)
1076 msleep_interruptible(trans_delay_msecs
);
1078 * See if we need to update the ALUA fabric port metadata for
1079 * secondary state and status
1081 if (port
->sep_tg_pt_secondary_write_md
) {
1082 md_buf
= kzalloc(md_buf_len
, GFP_KERNEL
);
1084 pr_err("Unable to allocate md_buf for"
1085 " secondary ALUA access metadata\n");
1088 mutex_lock(&port
->sep_tg_pt_md_mutex
);
1089 core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem
, port
,
1090 md_buf
, md_buf_len
);
1091 mutex_unlock(&port
->sep_tg_pt_md_mutex
);
1099 struct t10_alua_lu_gp
*
1100 core_alua_allocate_lu_gp(const char *name
, int def_group
)
1102 struct t10_alua_lu_gp
*lu_gp
;
1104 lu_gp
= kmem_cache_zalloc(t10_alua_lu_gp_cache
, GFP_KERNEL
);
1106 pr_err("Unable to allocate struct t10_alua_lu_gp\n");
1107 return ERR_PTR(-ENOMEM
);
1109 INIT_LIST_HEAD(&lu_gp
->lu_gp_node
);
1110 INIT_LIST_HEAD(&lu_gp
->lu_gp_mem_list
);
1111 spin_lock_init(&lu_gp
->lu_gp_lock
);
1112 atomic_set(&lu_gp
->lu_gp_ref_cnt
, 0);
1115 lu_gp
->lu_gp_id
= alua_lu_gps_counter
++;
1116 lu_gp
->lu_gp_valid_id
= 1;
1117 alua_lu_gps_count
++;
1123 int core_alua_set_lu_gp_id(struct t10_alua_lu_gp
*lu_gp
, u16 lu_gp_id
)
1125 struct t10_alua_lu_gp
*lu_gp_tmp
;
1128 * The lu_gp->lu_gp_id may only be set once..
1130 if (lu_gp
->lu_gp_valid_id
) {
1131 pr_warn("ALUA LU Group already has a valid ID,"
1132 " ignoring request\n");
1136 spin_lock(&lu_gps_lock
);
1137 if (alua_lu_gps_count
== 0x0000ffff) {
1138 pr_err("Maximum ALUA alua_lu_gps_count:"
1139 " 0x0000ffff reached\n");
1140 spin_unlock(&lu_gps_lock
);
1141 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1145 lu_gp_id_tmp
= (lu_gp_id
!= 0) ? lu_gp_id
:
1146 alua_lu_gps_counter
++;
1148 list_for_each_entry(lu_gp_tmp
, &lu_gps_list
, lu_gp_node
) {
1149 if (lu_gp_tmp
->lu_gp_id
== lu_gp_id_tmp
) {
1153 pr_warn("ALUA Logical Unit Group ID: %hu"
1154 " already exists, ignoring request\n",
1156 spin_unlock(&lu_gps_lock
);
1161 lu_gp
->lu_gp_id
= lu_gp_id_tmp
;
1162 lu_gp
->lu_gp_valid_id
= 1;
1163 list_add_tail(&lu_gp
->lu_gp_node
, &lu_gps_list
);
1164 alua_lu_gps_count
++;
1165 spin_unlock(&lu_gps_lock
);
1170 static struct t10_alua_lu_gp_member
*
1171 core_alua_allocate_lu_gp_mem(struct se_device
*dev
)
1173 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1175 lu_gp_mem
= kmem_cache_zalloc(t10_alua_lu_gp_mem_cache
, GFP_KERNEL
);
1177 pr_err("Unable to allocate struct t10_alua_lu_gp_member\n");
1178 return ERR_PTR(-ENOMEM
);
1180 INIT_LIST_HEAD(&lu_gp_mem
->lu_gp_mem_list
);
1181 spin_lock_init(&lu_gp_mem
->lu_gp_mem_lock
);
1182 atomic_set(&lu_gp_mem
->lu_gp_mem_ref_cnt
, 0);
1184 lu_gp_mem
->lu_gp_mem_dev
= dev
;
1185 dev
->dev_alua_lu_gp_mem
= lu_gp_mem
;
1190 void core_alua_free_lu_gp(struct t10_alua_lu_gp
*lu_gp
)
1192 struct t10_alua_lu_gp_member
*lu_gp_mem
, *lu_gp_mem_tmp
;
1194 * Once we have reached this point, config_item_put() has
1195 * already been called from target_core_alua_drop_lu_gp().
1197 * Here, we remove the *lu_gp from the global list so that
1198 * no associations can be made while we are releasing
1199 * struct t10_alua_lu_gp.
1201 spin_lock(&lu_gps_lock
);
1202 list_del(&lu_gp
->lu_gp_node
);
1203 alua_lu_gps_count
--;
1204 spin_unlock(&lu_gps_lock
);
1206 * Allow struct t10_alua_lu_gp * referenced by core_alua_get_lu_gp_by_name()
1207 * in target_core_configfs.c:target_core_store_alua_lu_gp() to be
1208 * released with core_alua_put_lu_gp_from_name()
1210 while (atomic_read(&lu_gp
->lu_gp_ref_cnt
))
1213 * Release reference to struct t10_alua_lu_gp * from all associated
1216 spin_lock(&lu_gp
->lu_gp_lock
);
1217 list_for_each_entry_safe(lu_gp_mem
, lu_gp_mem_tmp
,
1218 &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1219 if (lu_gp_mem
->lu_gp_assoc
) {
1220 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1221 lu_gp
->lu_gp_members
--;
1222 lu_gp_mem
->lu_gp_assoc
= 0;
1224 spin_unlock(&lu_gp
->lu_gp_lock
);
1227 * lu_gp_mem is associated with a single
1228 * struct se_device->dev_alua_lu_gp_mem, and is released when
1229 * struct se_device is released via core_alua_free_lu_gp_mem().
1231 * If the passed lu_gp does NOT match the default_lu_gp, assume
1232 * we want to re-assocate a given lu_gp_mem with default_lu_gp.
1234 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1235 if (lu_gp
!= default_lu_gp
)
1236 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
1239 lu_gp_mem
->lu_gp
= NULL
;
1240 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1242 spin_lock(&lu_gp
->lu_gp_lock
);
1244 spin_unlock(&lu_gp
->lu_gp_lock
);
1246 kmem_cache_free(t10_alua_lu_gp_cache
, lu_gp
);
1249 void core_alua_free_lu_gp_mem(struct se_device
*dev
)
1251 struct t10_alua_lu_gp
*lu_gp
;
1252 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1254 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1258 while (atomic_read(&lu_gp_mem
->lu_gp_mem_ref_cnt
))
1261 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1262 lu_gp
= lu_gp_mem
->lu_gp
;
1264 spin_lock(&lu_gp
->lu_gp_lock
);
1265 if (lu_gp_mem
->lu_gp_assoc
) {
1266 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1267 lu_gp
->lu_gp_members
--;
1268 lu_gp_mem
->lu_gp_assoc
= 0;
1270 spin_unlock(&lu_gp
->lu_gp_lock
);
1271 lu_gp_mem
->lu_gp
= NULL
;
1273 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1275 kmem_cache_free(t10_alua_lu_gp_mem_cache
, lu_gp_mem
);
1278 struct t10_alua_lu_gp
*core_alua_get_lu_gp_by_name(const char *name
)
1280 struct t10_alua_lu_gp
*lu_gp
;
1281 struct config_item
*ci
;
1283 spin_lock(&lu_gps_lock
);
1284 list_for_each_entry(lu_gp
, &lu_gps_list
, lu_gp_node
) {
1285 if (!lu_gp
->lu_gp_valid_id
)
1287 ci
= &lu_gp
->lu_gp_group
.cg_item
;
1288 if (!strcmp(config_item_name(ci
), name
)) {
1289 atomic_inc(&lu_gp
->lu_gp_ref_cnt
);
1290 spin_unlock(&lu_gps_lock
);
1294 spin_unlock(&lu_gps_lock
);
1299 void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp
*lu_gp
)
1301 spin_lock(&lu_gps_lock
);
1302 atomic_dec(&lu_gp
->lu_gp_ref_cnt
);
1303 spin_unlock(&lu_gps_lock
);
1307 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1309 void __core_alua_attach_lu_gp_mem(
1310 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1311 struct t10_alua_lu_gp
*lu_gp
)
1313 spin_lock(&lu_gp
->lu_gp_lock
);
1314 lu_gp_mem
->lu_gp
= lu_gp
;
1315 lu_gp_mem
->lu_gp_assoc
= 1;
1316 list_add_tail(&lu_gp_mem
->lu_gp_mem_list
, &lu_gp
->lu_gp_mem_list
);
1317 lu_gp
->lu_gp_members
++;
1318 spin_unlock(&lu_gp
->lu_gp_lock
);
1322 * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock
1324 void __core_alua_drop_lu_gp_mem(
1325 struct t10_alua_lu_gp_member
*lu_gp_mem
,
1326 struct t10_alua_lu_gp
*lu_gp
)
1328 spin_lock(&lu_gp
->lu_gp_lock
);
1329 list_del(&lu_gp_mem
->lu_gp_mem_list
);
1330 lu_gp_mem
->lu_gp
= NULL
;
1331 lu_gp_mem
->lu_gp_assoc
= 0;
1332 lu_gp
->lu_gp_members
--;
1333 spin_unlock(&lu_gp
->lu_gp_lock
);
1336 struct t10_alua_tg_pt_gp
*core_alua_allocate_tg_pt_gp(struct se_device
*dev
,
1337 const char *name
, int def_group
)
1339 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1341 tg_pt_gp
= kmem_cache_zalloc(t10_alua_tg_pt_gp_cache
, GFP_KERNEL
);
1343 pr_err("Unable to allocate struct t10_alua_tg_pt_gp\n");
1346 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_list
);
1347 INIT_LIST_HEAD(&tg_pt_gp
->tg_pt_gp_mem_list
);
1348 mutex_init(&tg_pt_gp
->tg_pt_gp_md_mutex
);
1349 spin_lock_init(&tg_pt_gp
->tg_pt_gp_lock
);
1350 atomic_set(&tg_pt_gp
->tg_pt_gp_ref_cnt
, 0);
1351 tg_pt_gp
->tg_pt_gp_dev
= dev
;
1352 tg_pt_gp
->tg_pt_gp_md_buf_len
= ALUA_MD_BUF_LEN
;
1353 atomic_set(&tg_pt_gp
->tg_pt_gp_alua_access_state
,
1354 ALUA_ACCESS_STATE_ACTIVE_OPTMIZED
);
1356 * Enable both explict and implict ALUA support by default
1358 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1359 TPGS_EXPLICT_ALUA
| TPGS_IMPLICT_ALUA
;
1361 * Set the default Active/NonOptimized Delay in milliseconds
1363 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= ALUA_DEFAULT_NONOP_DELAY_MSECS
;
1364 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= ALUA_DEFAULT_TRANS_DELAY_MSECS
;
1365 tg_pt_gp
->tg_pt_gp_implict_trans_secs
= ALUA_DEFAULT_IMPLICT_TRANS_SECS
;
1368 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1369 tg_pt_gp
->tg_pt_gp_id
=
1370 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1371 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1372 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1373 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1374 &dev
->t10_alua
.tg_pt_gps_list
);
1375 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1381 int core_alua_set_tg_pt_gp_id(
1382 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1385 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1386 struct t10_alua_tg_pt_gp
*tg_pt_gp_tmp
;
1387 u16 tg_pt_gp_id_tmp
;
1390 * The tg_pt_gp->tg_pt_gp_id may only be set once..
1392 if (tg_pt_gp
->tg_pt_gp_valid_id
) {
1393 pr_warn("ALUA TG PT Group already has a valid ID,"
1394 " ignoring request\n");
1398 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1399 if (dev
->t10_alua
.alua_tg_pt_gps_count
== 0x0000ffff) {
1400 pr_err("Maximum ALUA alua_tg_pt_gps_count:"
1401 " 0x0000ffff reached\n");
1402 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1403 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1407 tg_pt_gp_id_tmp
= (tg_pt_gp_id
!= 0) ? tg_pt_gp_id
:
1408 dev
->t10_alua
.alua_tg_pt_gps_counter
++;
1410 list_for_each_entry(tg_pt_gp_tmp
, &dev
->t10_alua
.tg_pt_gps_list
,
1412 if (tg_pt_gp_tmp
->tg_pt_gp_id
== tg_pt_gp_id_tmp
) {
1416 pr_err("ALUA Target Port Group ID: %hu already"
1417 " exists, ignoring request\n", tg_pt_gp_id
);
1418 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1423 tg_pt_gp
->tg_pt_gp_id
= tg_pt_gp_id_tmp
;
1424 tg_pt_gp
->tg_pt_gp_valid_id
= 1;
1425 list_add_tail(&tg_pt_gp
->tg_pt_gp_list
,
1426 &dev
->t10_alua
.tg_pt_gps_list
);
1427 dev
->t10_alua
.alua_tg_pt_gps_count
++;
1428 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1433 struct t10_alua_tg_pt_gp_member
*core_alua_allocate_tg_pt_gp_mem(
1434 struct se_port
*port
)
1436 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1438 tg_pt_gp_mem
= kmem_cache_zalloc(t10_alua_tg_pt_gp_mem_cache
,
1440 if (!tg_pt_gp_mem
) {
1441 pr_err("Unable to allocate struct t10_alua_tg_pt_gp_member\n");
1442 return ERR_PTR(-ENOMEM
);
1444 INIT_LIST_HEAD(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1445 spin_lock_init(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1446 atomic_set(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
, 0);
1448 tg_pt_gp_mem
->tg_pt
= port
;
1449 port
->sep_alua_tg_pt_gp_mem
= tg_pt_gp_mem
;
1451 return tg_pt_gp_mem
;
1454 void core_alua_free_tg_pt_gp(
1455 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1457 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1458 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
, *tg_pt_gp_mem_tmp
;
1461 * Once we have reached this point, config_item_put() has already
1462 * been called from target_core_alua_drop_tg_pt_gp().
1464 * Here we remove *tg_pt_gp from the global list so that
1465 * no assications *OR* explict ALUA via SET_TARGET_PORT_GROUPS
1466 * can be made while we are releasing struct t10_alua_tg_pt_gp.
1468 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1469 list_del(&tg_pt_gp
->tg_pt_gp_list
);
1470 dev
->t10_alua
.alua_tg_pt_gps_counter
--;
1471 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1474 * Allow a struct t10_alua_tg_pt_gp_member * referenced by
1475 * core_alua_get_tg_pt_gp_by_name() in
1476 * target_core_configfs.c:target_core_store_alua_tg_pt_gp()
1477 * to be released with core_alua_put_tg_pt_gp_from_name().
1479 while (atomic_read(&tg_pt_gp
->tg_pt_gp_ref_cnt
))
1483 * Release reference to struct t10_alua_tg_pt_gp from all associated
1486 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1487 list_for_each_entry_safe(tg_pt_gp_mem
, tg_pt_gp_mem_tmp
,
1488 &tg_pt_gp
->tg_pt_gp_mem_list
, tg_pt_gp_mem_list
) {
1489 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1490 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1491 tg_pt_gp
->tg_pt_gp_members
--;
1492 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1494 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1496 * tg_pt_gp_mem is associated with a single
1497 * se_port->sep_alua_tg_pt_gp_mem, and is released via
1498 * core_alua_free_tg_pt_gp_mem().
1500 * If the passed tg_pt_gp does NOT match the default_tg_pt_gp,
1501 * assume we want to re-assocate a given tg_pt_gp_mem with
1504 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1505 if (tg_pt_gp
!= dev
->t10_alua
.default_tg_pt_gp
) {
1506 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1507 dev
->t10_alua
.default_tg_pt_gp
);
1509 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1510 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1512 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1514 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1516 kmem_cache_free(t10_alua_tg_pt_gp_cache
, tg_pt_gp
);
1519 void core_alua_free_tg_pt_gp_mem(struct se_port
*port
)
1521 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1522 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1524 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1528 while (atomic_read(&tg_pt_gp_mem
->tg_pt_gp_mem_ref_cnt
))
1531 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1532 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1534 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1535 if (tg_pt_gp_mem
->tg_pt_gp_assoc
) {
1536 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1537 tg_pt_gp
->tg_pt_gp_members
--;
1538 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1540 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1541 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1543 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1545 kmem_cache_free(t10_alua_tg_pt_gp_mem_cache
, tg_pt_gp_mem
);
1548 static struct t10_alua_tg_pt_gp
*core_alua_get_tg_pt_gp_by_name(
1549 struct se_device
*dev
, const char *name
)
1551 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1552 struct config_item
*ci
;
1554 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1555 list_for_each_entry(tg_pt_gp
, &dev
->t10_alua
.tg_pt_gps_list
,
1557 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
1559 ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1560 if (!strcmp(config_item_name(ci
), name
)) {
1561 atomic_inc(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1562 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1566 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1571 static void core_alua_put_tg_pt_gp_from_name(
1572 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1574 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1576 spin_lock(&dev
->t10_alua
.tg_pt_gps_lock
);
1577 atomic_dec(&tg_pt_gp
->tg_pt_gp_ref_cnt
);
1578 spin_unlock(&dev
->t10_alua
.tg_pt_gps_lock
);
1582 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1584 void __core_alua_attach_tg_pt_gp_mem(
1585 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1586 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1588 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1589 tg_pt_gp_mem
->tg_pt_gp
= tg_pt_gp
;
1590 tg_pt_gp_mem
->tg_pt_gp_assoc
= 1;
1591 list_add_tail(&tg_pt_gp_mem
->tg_pt_gp_mem_list
,
1592 &tg_pt_gp
->tg_pt_gp_mem_list
);
1593 tg_pt_gp
->tg_pt_gp_members
++;
1594 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1598 * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held
1600 static void __core_alua_drop_tg_pt_gp_mem(
1601 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
,
1602 struct t10_alua_tg_pt_gp
*tg_pt_gp
)
1604 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
1605 list_del(&tg_pt_gp_mem
->tg_pt_gp_mem_list
);
1606 tg_pt_gp_mem
->tg_pt_gp
= NULL
;
1607 tg_pt_gp_mem
->tg_pt_gp_assoc
= 0;
1608 tg_pt_gp
->tg_pt_gp_members
--;
1609 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
1612 ssize_t
core_alua_show_tg_pt_gp_info(struct se_port
*port
, char *page
)
1614 struct config_item
*tg_pt_ci
;
1615 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
1616 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1619 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1623 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1624 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1626 tg_pt_ci
= &tg_pt_gp
->tg_pt_gp_group
.cg_item
;
1627 len
+= sprintf(page
, "TG Port Alias: %s\nTG Port Group ID:"
1628 " %hu\nTG Port Primary Access State: %s\nTG Port "
1629 "Primary Access Status: %s\nTG Port Secondary Access"
1630 " State: %s\nTG Port Secondary Access Status: %s\n",
1631 config_item_name(tg_pt_ci
), tg_pt_gp
->tg_pt_gp_id
,
1632 core_alua_dump_state(atomic_read(
1633 &tg_pt_gp
->tg_pt_gp_alua_access_state
)),
1634 core_alua_dump_status(
1635 tg_pt_gp
->tg_pt_gp_alua_access_status
),
1636 (atomic_read(&port
->sep_tg_pt_secondary_offline
)) ?
1638 core_alua_dump_status(port
->sep_tg_pt_secondary_stat
));
1640 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1645 ssize_t
core_alua_store_tg_pt_gp_info(
1646 struct se_port
*port
,
1650 struct se_portal_group
*tpg
;
1652 struct se_device
*dev
= port
->sep_lun
->lun_se_dev
;
1653 struct t10_alua_tg_pt_gp
*tg_pt_gp
= NULL
, *tg_pt_gp_new
= NULL
;
1654 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1655 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
1658 tpg
= port
->sep_tpg
;
1659 lun
= port
->sep_lun
;
1661 tg_pt_gp_mem
= port
->sep_alua_tg_pt_gp_mem
;
1665 if (count
> TG_PT_GROUP_NAME_BUF
) {
1666 pr_err("ALUA Target Port Group alias too large!\n");
1669 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
1670 memcpy(buf
, page
, count
);
1672 * Any ALUA target port group alias besides "NULL" means we will be
1673 * making a new group association.
1675 if (strcmp(strstrip(buf
), "NULL")) {
1677 * core_alua_get_tg_pt_gp_by_name() will increment reference to
1678 * struct t10_alua_tg_pt_gp. This reference is released with
1679 * core_alua_put_tg_pt_gp_from_name() below.
1681 tg_pt_gp_new
= core_alua_get_tg_pt_gp_by_name(dev
,
1687 spin_lock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1688 tg_pt_gp
= tg_pt_gp_mem
->tg_pt_gp
;
1691 * Clearing an existing tg_pt_gp association, and replacing
1692 * with the default_tg_pt_gp.
1694 if (!tg_pt_gp_new
) {
1695 pr_debug("Target_Core_ConfigFS: Moving"
1696 " %s/tpgt_%hu/%s from ALUA Target Port Group:"
1697 " alua/%s, ID: %hu back to"
1698 " default_tg_pt_gp\n",
1699 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1700 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1701 config_item_name(&lun
->lun_group
.cg_item
),
1703 &tg_pt_gp
->tg_pt_gp_group
.cg_item
),
1704 tg_pt_gp
->tg_pt_gp_id
);
1706 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1707 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
,
1708 dev
->t10_alua
.default_tg_pt_gp
);
1709 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1714 * Removing existing association of tg_pt_gp_mem with tg_pt_gp
1716 __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp
);
1720 * Associate tg_pt_gp_mem with tg_pt_gp_new.
1722 __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem
, tg_pt_gp_new
);
1723 spin_unlock(&tg_pt_gp_mem
->tg_pt_gp_mem_lock
);
1724 pr_debug("Target_Core_ConfigFS: %s %s/tpgt_%hu/%s to ALUA"
1725 " Target Port Group: alua/%s, ID: %hu\n", (move
) ?
1726 "Moving" : "Adding", tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1727 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
1728 config_item_name(&lun
->lun_group
.cg_item
),
1729 config_item_name(&tg_pt_gp_new
->tg_pt_gp_group
.cg_item
),
1730 tg_pt_gp_new
->tg_pt_gp_id
);
1732 core_alua_put_tg_pt_gp_from_name(tg_pt_gp_new
);
1736 ssize_t
core_alua_show_access_type(
1737 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1740 if ((tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
) &&
1741 (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
))
1742 return sprintf(page
, "Implict and Explict\n");
1743 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)
1744 return sprintf(page
, "Implict\n");
1745 else if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICT_ALUA
)
1746 return sprintf(page
, "Explict\n");
1748 return sprintf(page
, "None\n");
1751 ssize_t
core_alua_store_access_type(
1752 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1759 ret
= strict_strtoul(page
, 0, &tmp
);
1761 pr_err("Unable to extract alua_access_type\n");
1764 if ((tmp
!= 0) && (tmp
!= 1) && (tmp
!= 2) && (tmp
!= 3)) {
1765 pr_err("Illegal value for alua_access_type:"
1770 tg_pt_gp
->tg_pt_gp_alua_access_type
=
1771 TPGS_IMPLICT_ALUA
| TPGS_EXPLICT_ALUA
;
1773 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_EXPLICT_ALUA
;
1775 tg_pt_gp
->tg_pt_gp_alua_access_type
= TPGS_IMPLICT_ALUA
;
1777 tg_pt_gp
->tg_pt_gp_alua_access_type
= 0;
1782 ssize_t
core_alua_show_nonop_delay_msecs(
1783 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1786 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
);
1789 ssize_t
core_alua_store_nonop_delay_msecs(
1790 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1797 ret
= strict_strtoul(page
, 0, &tmp
);
1799 pr_err("Unable to extract nonop_delay_msecs\n");
1802 if (tmp
> ALUA_MAX_NONOP_DELAY_MSECS
) {
1803 pr_err("Passed nonop_delay_msecs: %lu, exceeds"
1804 " ALUA_MAX_NONOP_DELAY_MSECS: %d\n", tmp
,
1805 ALUA_MAX_NONOP_DELAY_MSECS
);
1808 tg_pt_gp
->tg_pt_gp_nonop_delay_msecs
= (int)tmp
;
1813 ssize_t
core_alua_show_trans_delay_msecs(
1814 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1817 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_trans_delay_msecs
);
1820 ssize_t
core_alua_store_trans_delay_msecs(
1821 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1828 ret
= strict_strtoul(page
, 0, &tmp
);
1830 pr_err("Unable to extract trans_delay_msecs\n");
1833 if (tmp
> ALUA_MAX_TRANS_DELAY_MSECS
) {
1834 pr_err("Passed trans_delay_msecs: %lu, exceeds"
1835 " ALUA_MAX_TRANS_DELAY_MSECS: %d\n", tmp
,
1836 ALUA_MAX_TRANS_DELAY_MSECS
);
1839 tg_pt_gp
->tg_pt_gp_trans_delay_msecs
= (int)tmp
;
1844 ssize_t
core_alua_show_implict_trans_secs(
1845 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1848 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_implict_trans_secs
);
1851 ssize_t
core_alua_store_implict_trans_secs(
1852 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1859 ret
= strict_strtoul(page
, 0, &tmp
);
1861 pr_err("Unable to extract implict_trans_secs\n");
1864 if (tmp
> ALUA_MAX_IMPLICT_TRANS_SECS
) {
1865 pr_err("Passed implict_trans_secs: %lu, exceeds"
1866 " ALUA_MAX_IMPLICT_TRANS_SECS: %d\n", tmp
,
1867 ALUA_MAX_IMPLICT_TRANS_SECS
);
1870 tg_pt_gp
->tg_pt_gp_implict_trans_secs
= (int)tmp
;
1875 ssize_t
core_alua_show_preferred_bit(
1876 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1879 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_pref
);
1882 ssize_t
core_alua_store_preferred_bit(
1883 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1890 ret
= strict_strtoul(page
, 0, &tmp
);
1892 pr_err("Unable to extract preferred ALUA value\n");
1895 if ((tmp
!= 0) && (tmp
!= 1)) {
1896 pr_err("Illegal value for preferred ALUA: %lu\n", tmp
);
1899 tg_pt_gp
->tg_pt_gp_pref
= (int)tmp
;
1904 ssize_t
core_alua_show_offline_bit(struct se_lun
*lun
, char *page
)
1909 return sprintf(page
, "%d\n",
1910 atomic_read(&lun
->lun_sep
->sep_tg_pt_secondary_offline
));
1913 ssize_t
core_alua_store_offline_bit(
1918 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
1925 ret
= strict_strtoul(page
, 0, &tmp
);
1927 pr_err("Unable to extract alua_tg_pt_offline value\n");
1930 if ((tmp
!= 0) && (tmp
!= 1)) {
1931 pr_err("Illegal value for alua_tg_pt_offline: %lu\n",
1935 tg_pt_gp_mem
= lun
->lun_sep
->sep_alua_tg_pt_gp_mem
;
1936 if (!tg_pt_gp_mem
) {
1937 pr_err("Unable to locate *tg_pt_gp_mem\n");
1941 ret
= core_alua_set_tg_pt_secondary_state(tg_pt_gp_mem
,
1942 lun
->lun_sep
, 0, (int)tmp
);
1949 ssize_t
core_alua_show_secondary_status(
1953 return sprintf(page
, "%d\n", lun
->lun_sep
->sep_tg_pt_secondary_stat
);
1956 ssize_t
core_alua_store_secondary_status(
1964 ret
= strict_strtoul(page
, 0, &tmp
);
1966 pr_err("Unable to extract alua_tg_pt_status\n");
1969 if ((tmp
!= ALUA_STATUS_NONE
) &&
1970 (tmp
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
1971 (tmp
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
1972 pr_err("Illegal value for alua_tg_pt_status: %lu\n",
1976 lun
->lun_sep
->sep_tg_pt_secondary_stat
= (int)tmp
;
1981 ssize_t
core_alua_show_secondary_write_metadata(
1985 return sprintf(page
, "%d\n",
1986 lun
->lun_sep
->sep_tg_pt_secondary_write_md
);
1989 ssize_t
core_alua_store_secondary_write_metadata(
1997 ret
= strict_strtoul(page
, 0, &tmp
);
1999 pr_err("Unable to extract alua_tg_pt_write_md\n");
2002 if ((tmp
!= 0) && (tmp
!= 1)) {
2003 pr_err("Illegal value for alua_tg_pt_write_md:"
2007 lun
->lun_sep
->sep_tg_pt_secondary_write_md
= (int)tmp
;
2012 int core_setup_alua(struct se_device
*dev
)
2014 if (dev
->transport
->transport_type
!= TRANSPORT_PLUGIN_PHBA_PDEV
&&
2015 !(dev
->se_hba
->hba_flags
& HBA_FLAGS_INTERNAL_USE
)) {
2016 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2019 * Associate this struct se_device with the default ALUA
2022 lu_gp_mem
= core_alua_allocate_lu_gp_mem(dev
);
2023 if (IS_ERR(lu_gp_mem
))
2024 return PTR_ERR(lu_gp_mem
);
2026 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
2027 __core_alua_attach_lu_gp_mem(lu_gp_mem
,
2029 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2031 pr_debug("%s: Adding to default ALUA LU Group:"
2032 " core/alua/lu_gps/default_lu_gp\n",
2033 dev
->transport
->name
);