ctl_frontend_iscsi.c (268147) | ctl_frontend_iscsi.c (268257) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268147 2014-07-02 10:39:45Z mav $ | 29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268257 2014-07-04 16:06:56Z mav $ |
30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> | 30 */ 31 32/* 33 * CTL frontend for the iSCSI protocol. 34 */ 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268147 2014-07-02 10:39:45Z mav $"); | 37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268257 2014-07-04 16:06:56Z mav $"); |
38 39#include <sys/param.h> 40#include <sys/capability.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 1981 unchanged lines hidden (view full) --- 2027 return (0); 2028} 2029 2030static int 2031cfiscsi_devid(struct ctl_scsiio *ctsio, int alloc_len) 2032{ 2033 struct cfiscsi_session *cs; 2034 struct scsi_vpd_device_id *devid_ptr; | 38 39#include <sys/param.h> 40#include <sys/capability.h> 41#include <sys/condvar.h> 42#include <sys/file.h> 43#include <sys/kernel.h> 44#include <sys/kthread.h> 45#include <sys/lock.h> --- 1981 unchanged lines hidden (view full) --- 2027 return (0); 2028} 2029 2030static int 2031cfiscsi_devid(struct ctl_scsiio *ctsio, int alloc_len) 2032{ 2033 struct cfiscsi_session *cs; 2034 struct scsi_vpd_device_id *devid_ptr; |
2035 struct scsi_vpd_id_descriptor *desc, *desc1; 2036 struct scsi_vpd_id_descriptor *desc2, *desc3; /* for types 4h and 5h */ | 2035 struct scsi_vpd_id_descriptor *desc, *desc1, *desc2, *desc3, *desc4; |
2037 struct scsi_vpd_id_t10 *t10id; 2038 struct ctl_lun *lun; 2039 const struct icl_pdu *request; | 2036 struct scsi_vpd_id_t10 *t10id; 2037 struct ctl_lun *lun; 2038 const struct icl_pdu *request; |
2039 int i, ret; |
|
2040 char *val; | 2040 char *val; |
2041 size_t devid_len, wwpn_len; | 2041 size_t devid_len, wwpn_len, lun_name_len; |
2042 2043 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 2044 request = ctsio->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 2045 cs = PDU_SESSION(request); 2046 2047 wwpn_len = strlen(cs->cs_target->ct_name); 2048 wwpn_len += strlen(",t,0x0001"); 2049 wwpn_len += 1; /* '\0' */ 2050 if ((wwpn_len % 4) != 0) 2051 wwpn_len += (4 - (wwpn_len % 4)); 2052 | 2042 2043 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 2044 request = ctsio->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 2045 cs = PDU_SESSION(request); 2046 2047 wwpn_len = strlen(cs->cs_target->ct_name); 2048 wwpn_len += strlen(",t,0x0001"); 2049 wwpn_len += 1; /* '\0' */ 2050 if ((wwpn_len % 4) != 0) 2051 wwpn_len += (4 - (wwpn_len % 4)); 2052 |
2053 if (lun == NULL) { 2054 lun_name_len = 0; 2055 } else { 2056 lun_name_len = strlen(cs->cs_target->ct_name); 2057 lun_name_len += strlen(",lun,XXXXXXXX"); 2058 lun_name_len += 1; /* '\0' */ 2059 if ((lun_name_len % 4) != 0) 2060 lun_name_len += (4 - (lun_name_len % 4)); 2061 } 2062 |
|
2053 devid_len = sizeof(struct scsi_vpd_device_id) + 2054 sizeof(struct scsi_vpd_id_descriptor) + 2055 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN + | 2063 devid_len = sizeof(struct scsi_vpd_device_id) + 2064 sizeof(struct scsi_vpd_id_descriptor) + 2065 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN + |
2066 sizeof(struct scsi_vpd_id_descriptor) + lun_name_len + |
|
2056 sizeof(struct scsi_vpd_id_descriptor) + wwpn_len + 2057 sizeof(struct scsi_vpd_id_descriptor) + 2058 sizeof(struct scsi_vpd_id_rel_trgt_port_id) + 2059 sizeof(struct scsi_vpd_id_descriptor) + 2060 sizeof(struct scsi_vpd_id_trgt_port_grp_id); 2061 2062 ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO); 2063 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr; --- 12 unchanged lines hidden (view full) --- 2076 ctsio->kern_rel_offset = 0; 2077 ctsio->kern_sg_entries = 0; 2078 2079 desc = (struct scsi_vpd_id_descriptor *)devid_ptr->desc_list; 2080 t10id = (struct scsi_vpd_id_t10 *)&desc->identifier[0]; 2081 desc1 = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] + 2082 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN); 2083 desc2 = (struct scsi_vpd_id_descriptor *)(&desc1->identifier[0] + | 2067 sizeof(struct scsi_vpd_id_descriptor) + wwpn_len + 2068 sizeof(struct scsi_vpd_id_descriptor) + 2069 sizeof(struct scsi_vpd_id_rel_trgt_port_id) + 2070 sizeof(struct scsi_vpd_id_descriptor) + 2071 sizeof(struct scsi_vpd_id_trgt_port_grp_id); 2072 2073 ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO); 2074 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr; --- 12 unchanged lines hidden (view full) --- 2087 ctsio->kern_rel_offset = 0; 2088 ctsio->kern_sg_entries = 0; 2089 2090 desc = (struct scsi_vpd_id_descriptor *)devid_ptr->desc_list; 2091 t10id = (struct scsi_vpd_id_t10 *)&desc->identifier[0]; 2092 desc1 = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] + 2093 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN); 2094 desc2 = (struct scsi_vpd_id_descriptor *)(&desc1->identifier[0] + |
2084 wwpn_len); | 2095 lun_name_len); |
2085 desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] + | 2096 desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] + |
2097 wwpn_len); 2098 desc4 = (struct scsi_vpd_id_descriptor *)(&desc3->identifier[0] + |
|
2086 sizeof(struct scsi_vpd_id_rel_trgt_port_id)); 2087 2088 if (lun != NULL) 2089 devid_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 2090 lun->be_lun->lun_type; 2091 else 2092 devid_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 2093 --- 29 unchanged lines hidden (view full) --- 2123 } else { 2124 /* 2125 * No backend, set this to spaces. 2126 */ 2127 memset(t10id->vendor_spec_id, 0x20, CTL_DEVID_LEN); 2128 } 2129 2130 /* | 2099 sizeof(struct scsi_vpd_id_rel_trgt_port_id)); 2100 2101 if (lun != NULL) 2102 devid_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 2103 lun->be_lun->lun_type; 2104 else 2105 devid_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 2106 --- 29 unchanged lines hidden (view full) --- 2136 } else { 2137 /* 2138 * No backend, set this to spaces. 2139 */ 2140 memset(t10id->vendor_spec_id, 0x20, CTL_DEVID_LEN); 2141 } 2142 2143 /* |
2131 * desc1 is for the WWPN which is a port asscociation. | 2144 * desc1 is for the unique LUN name. 2145 * 2146 * XXX: According to SPC-3, LUN must report the same ID through 2147 * all the ports. The code below, however, reports the 2148 * ID only via iSCSI. |
2132 */ | 2149 */ |
2133 desc1->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8; 2134 desc1->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | 2135 SVPD_ID_TYPE_SCSI_NAME; 2136 desc1->length = wwpn_len; 2137 snprintf(desc1->identifier, wwpn_len, "%s,t,0x%4.4x", 2138 cs->cs_target->ct_name, cs->cs_portal_group_tag); | 2150 desc1->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8; 2151 desc1->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | 2152 SVPD_ID_TYPE_SCSI_NAME; 2153 desc1->length = lun_name_len; 2154 if (lun != NULL) { 2155 /* 2156 * Find the per-target LUN number. 2157 */ 2158 for (i = 0; i < CTL_MAX_LUNS; i++) { 2159 if (cs->cs_target->ct_luns[i] == lun->lun) 2160 break; 2161 } 2162 KASSERT(i < CTL_MAX_LUNS, 2163 ("lun %jd not found", (uintmax_t)lun->lun)); 2164 ret = snprintf(desc1->identifier, lun_name_len, "%s,lun,%d", 2165 cs->cs_target->ct_name, i); 2166 KASSERT(ret > 0 && ret <= lun_name_len, ("bad snprintf")); 2167 } else { 2168 KASSERT(lun_name_len == 0, ("no lun, but lun_name_len != 0")); 2169 } |
2139 2140 /* | 2170 2171 /* |
2141 * desc2 is for the Relative Target Port(type 4h) identifier | 2172 * desc2 is for the WWPN which is a port asscociation. |
2142 */ | 2173 */ |
2143 desc2->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY; | 2174 desc2->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8; |
2144 desc2->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | | 2175 desc2->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | |
2145 SVPD_ID_TYPE_RELTARG; 2146 desc2->length = 4; 2147 desc2->identifier[3] = 1; | 2176 SVPD_ID_TYPE_SCSI_NAME; 2177 desc2->length = wwpn_len; 2178 snprintf(desc2->identifier, wwpn_len, "%s,t,0x%4.4x", 2179 cs->cs_target->ct_name, cs->cs_portal_group_tag); |
2148 2149 /* | 2180 2181 /* |
2150 * desc3 is for the Target Port Group(type 5h) identifier | 2182 * desc3 is for the Relative Target Port(type 4h) identifier |
2151 */ 2152 desc3->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY; 2153 desc3->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | | 2183 */ 2184 desc3->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY; 2185 desc3->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | |
2154 SVPD_ID_TYPE_TPORTGRP; | 2186 SVPD_ID_TYPE_RELTARG; |
2155 desc3->length = 4; 2156 desc3->identifier[3] = 1; 2157 | 2187 desc3->length = 4; 2188 desc3->identifier[3] = 1; 2189 |
2190 /* 2191 * desc4 is for the Target Port Group(type 5h) identifier 2192 */ 2193 desc4->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY; 2194 desc4->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | 2195 SVPD_ID_TYPE_TPORTGRP; 2196 desc4->length = 4; 2197 desc4->identifier[3] = 1; 2198 |
|
2158 ctsio->scsi_status = SCSI_STATUS_OK; 2159 2160 ctsio->be_move_done = ctl_config_move_done; 2161 ctl_datamove((union ctl_io *)ctsio); 2162 2163 return (CTL_RETVAL_COMPLETE); 2164} 2165 --- 713 unchanged lines hidden --- | 2199 ctsio->scsi_status = SCSI_STATUS_OK; 2200 2201 ctsio->be_move_done = ctl_config_move_done; 2202 ctl_datamove((union ctl_io *)ctsio); 2203 2204 return (CTL_RETVAL_COMPLETE); 2205} 2206 --- 713 unchanged lines hidden --- |