Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tcm_loop: Implement transport offline

Add attribute 'transport_status' to simulate link failure.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Hannes Reinecke and committed by
Nicholas Bellinger
fb2b2844 1ec59fee

+56 -1
+52 -1
drivers/target/loopback/tcm_loop.c
··· 178 178 set_host_byte(sc, DID_NO_CONNECT); 179 179 goto out_done; 180 180 } 181 - 181 + if (tl_tpg->tl_transport_status == TCM_TRANSPORT_OFFLINE) { 182 + set_host_byte(sc, DID_TRANSPORT_DISRUPTED); 183 + goto out_done; 184 + } 182 185 tl_nexus = tl_hba->tl_nexus; 183 186 if (!tl_nexus) { 184 187 scmd_printk(KERN_ERR, sc, "TCM_Loop I_T Nexus" ··· 1067 1064 1068 1065 TF_TPG_BASE_ATTR(tcm_loop, nexus, S_IRUGO | S_IWUSR); 1069 1066 1067 + static ssize_t tcm_loop_tpg_show_transport_status( 1068 + struct se_portal_group *se_tpg, 1069 + char *page) 1070 + { 1071 + struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 1072 + struct tcm_loop_tpg, tl_se_tpg); 1073 + const char *status = NULL; 1074 + ssize_t ret = -EINVAL; 1075 + 1076 + switch (tl_tpg->tl_transport_status) { 1077 + case TCM_TRANSPORT_ONLINE: 1078 + status = "online"; 1079 + break; 1080 + case TCM_TRANSPORT_OFFLINE: 1081 + status = "offline"; 1082 + break; 1083 + default: 1084 + break; 1085 + } 1086 + 1087 + if (status) 1088 + ret = snprintf(page, PAGE_SIZE, "%s\n", status); 1089 + 1090 + return ret; 1091 + } 1092 + 1093 + static ssize_t tcm_loop_tpg_store_transport_status( 1094 + struct se_portal_group *se_tpg, 1095 + const char *page, 1096 + size_t count) 1097 + { 1098 + struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 1099 + struct tcm_loop_tpg, tl_se_tpg); 1100 + 1101 + if (!strncmp(page, "online", 6)) { 1102 + tl_tpg->tl_transport_status = TCM_TRANSPORT_ONLINE; 1103 + return count; 1104 + } 1105 + if (!strncmp(page, "offline", 7)) { 1106 + tl_tpg->tl_transport_status = TCM_TRANSPORT_OFFLINE; 1107 + return count; 1108 + } 1109 + return -EINVAL; 1110 + } 1111 + 1112 + TF_TPG_BASE_ATTR(tcm_loop, transport_status, S_IRUGO | S_IWUSR); 1113 + 1070 1114 static struct configfs_attribute *tcm_loop_tpg_attrs[] = { 1071 1115 &tcm_loop_tpg_nexus.attr, 1116 + &tcm_loop_tpg_transport_status.attr, 1072 1117 NULL, 1073 1118 }; 1074 1119
+4
drivers/target/loopback/tcm_loop.h
··· 40 40 struct se_node_acl se_node_acl; 41 41 }; 42 42 43 + #define TCM_TRANSPORT_ONLINE 0 44 + #define TCM_TRANSPORT_OFFLINE 1 45 + 43 46 struct tcm_loop_tpg { 44 47 unsigned short tl_tpgt; 48 + unsigned short tl_transport_status; 45 49 atomic_t tl_tpg_port_count; 46 50 struct se_portal_group tl_se_tpg; 47 51 struct tcm_loop_hba *tl_hba;