ctl_frontend_iscsi.c (268554) | ctl_frontend_iscsi.c (268673) |
---|---|
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 268554 2014-07-12 02:33:03Z mav $ | 29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268673 2014-07-15 16:49:35Z 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 268554 2014-07-12 02:33:03Z mav $"); | 37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268673 2014-07-15 16:49:35Z 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> --- 2008 unchanged lines hidden (view full) --- 2054 struct scsi_vpd_device_id *devid_ptr; 2055 struct scsi_vpd_id_descriptor *desc, *desc1, *desc2, *desc3, *desc4; 2056 struct scsi_vpd_id_descriptor *desc5; 2057 struct scsi_vpd_id_t10 *t10id; 2058 struct ctl_lun *lun; 2059 const struct icl_pdu *request; 2060 int i, ret; 2061 char *val; | 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> --- 2008 unchanged lines hidden (view full) --- 2054 struct scsi_vpd_device_id *devid_ptr; 2055 struct scsi_vpd_id_descriptor *desc, *desc1, *desc2, *desc3, *desc4; 2056 struct scsi_vpd_id_descriptor *desc5; 2057 struct scsi_vpd_id_t10 *t10id; 2058 struct ctl_lun *lun; 2059 const struct icl_pdu *request; 2060 int i, ret; 2061 char *val; |
2062 size_t devid_len, wwnn_len, wwpn_len, lun_name_len; | 2062 size_t data_len, devid_len, wwnn_len, wwpn_len, lun_name_len; |
2063 2064 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 2065 request = ctsio->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 2066 cs = PDU_SESSION(request); 2067 2068 wwpn_len = strlen(cs->cs_target->ct_name); 2069 wwpn_len += strlen(",t,0x0001"); 2070 wwpn_len += 1; /* '\0' */ 2071 if ((wwpn_len % 4) != 0) 2072 wwpn_len += (4 - (wwpn_len % 4)); 2073 2074 wwnn_len = strlen(cs->cs_target->ct_name); 2075 wwnn_len += 1; /* '\0' */ 2076 if ((wwnn_len % 4) != 0) 2077 wwnn_len += (4 - (wwnn_len % 4)); 2078 2079 if (lun == NULL) { | 2063 2064 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; 2065 request = ctsio->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr; 2066 cs = PDU_SESSION(request); 2067 2068 wwpn_len = strlen(cs->cs_target->ct_name); 2069 wwpn_len += strlen(",t,0x0001"); 2070 wwpn_len += 1; /* '\0' */ 2071 if ((wwpn_len % 4) != 0) 2072 wwpn_len += (4 - (wwpn_len % 4)); 2073 2074 wwnn_len = strlen(cs->cs_target->ct_name); 2075 wwnn_len += 1; /* '\0' */ 2076 if ((wwnn_len % 4) != 0) 2077 wwnn_len += (4 - (wwnn_len % 4)); 2078 2079 if (lun == NULL) { |
2080 devid_len = CTL_DEVID_MIN_LEN; |
|
2080 lun_name_len = 0; 2081 } else { | 2081 lun_name_len = 0; 2082 } else { |
2083 devid_len = max(CTL_DEVID_MIN_LEN, 2084 strnlen(lun->be_lun->device_id, CTL_DEVID_LEN)); |
|
2082 lun_name_len = strlen(cs->cs_target->ct_name); 2083 lun_name_len += strlen(",lun,XXXXXXXX"); 2084 lun_name_len += 1; /* '\0' */ 2085 if ((lun_name_len % 4) != 0) 2086 lun_name_len += (4 - (lun_name_len % 4)); 2087 } 2088 | 2085 lun_name_len = strlen(cs->cs_target->ct_name); 2086 lun_name_len += strlen(",lun,XXXXXXXX"); 2087 lun_name_len += 1; /* '\0' */ 2088 if ((lun_name_len % 4) != 0) 2089 lun_name_len += (4 - (lun_name_len % 4)); 2090 } 2091 |
2089 devid_len = sizeof(struct scsi_vpd_device_id) + | 2092 data_len = sizeof(struct scsi_vpd_device_id) + |
2090 sizeof(struct scsi_vpd_id_descriptor) + | 2093 sizeof(struct scsi_vpd_id_descriptor) + |
2091 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN + | 2094 sizeof(struct scsi_vpd_id_t10) + devid_len + |
2092 sizeof(struct scsi_vpd_id_descriptor) + lun_name_len + 2093 sizeof(struct scsi_vpd_id_descriptor) + wwnn_len + 2094 sizeof(struct scsi_vpd_id_descriptor) + wwpn_len + 2095 sizeof(struct scsi_vpd_id_descriptor) + 2096 sizeof(struct scsi_vpd_id_rel_trgt_port_id) + 2097 sizeof(struct scsi_vpd_id_descriptor) + 2098 sizeof(struct scsi_vpd_id_trgt_port_grp_id); 2099 | 2095 sizeof(struct scsi_vpd_id_descriptor) + lun_name_len + 2096 sizeof(struct scsi_vpd_id_descriptor) + wwnn_len + 2097 sizeof(struct scsi_vpd_id_descriptor) + wwpn_len + 2098 sizeof(struct scsi_vpd_id_descriptor) + 2099 sizeof(struct scsi_vpd_id_rel_trgt_port_id) + 2100 sizeof(struct scsi_vpd_id_descriptor) + 2101 sizeof(struct scsi_vpd_id_trgt_port_grp_id); 2102 |
2100 ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO); | 2103 ctsio->kern_data_ptr = malloc(data_len, M_CTL, M_WAITOK | M_ZERO); |
2101 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr; 2102 ctsio->kern_sg_entries = 0; 2103 | 2104 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr; 2105 ctsio->kern_sg_entries = 0; 2106 |
2104 if (devid_len < alloc_len) { 2105 ctsio->residual = alloc_len - devid_len; 2106 ctsio->kern_data_len = devid_len; 2107 ctsio->kern_total_len = devid_len; | 2107 if (data_len < alloc_len) { 2108 ctsio->residual = alloc_len - data_len; 2109 ctsio->kern_data_len = data_len; 2110 ctsio->kern_total_len = data_len; |
2108 } else { 2109 ctsio->residual = 0; 2110 ctsio->kern_data_len = alloc_len; 2111 ctsio->kern_total_len = alloc_len; 2112 } 2113 ctsio->kern_data_resid = 0; 2114 ctsio->kern_rel_offset = 0; 2115 ctsio->kern_sg_entries = 0; 2116 2117 desc = (struct scsi_vpd_id_descriptor *)devid_ptr->desc_list; 2118 t10id = (struct scsi_vpd_id_t10 *)&desc->identifier[0]; 2119 desc1 = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] + | 2111 } else { 2112 ctsio->residual = 0; 2113 ctsio->kern_data_len = alloc_len; 2114 ctsio->kern_total_len = alloc_len; 2115 } 2116 ctsio->kern_data_resid = 0; 2117 ctsio->kern_rel_offset = 0; 2118 ctsio->kern_sg_entries = 0; 2119 2120 desc = (struct scsi_vpd_id_descriptor *)devid_ptr->desc_list; 2121 t10id = (struct scsi_vpd_id_t10 *)&desc->identifier[0]; 2122 desc1 = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] + |
2120 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN); | 2123 sizeof(struct scsi_vpd_id_t10) + devid_len); |
2121 desc2 = (struct scsi_vpd_id_descriptor *)(&desc1->identifier[0] + 2122 lun_name_len); 2123 desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] + 2124 wwnn_len); 2125 desc4 = (struct scsi_vpd_id_descriptor *)(&desc3->identifier[0] + 2126 wwpn_len); 2127 desc5 = (struct scsi_vpd_id_descriptor *)(&desc4->identifier[0] + 2128 sizeof(struct scsi_vpd_id_rel_trgt_port_id)); 2129 2130 if (lun != NULL) 2131 devid_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 2132 lun->be_lun->lun_type; 2133 else 2134 devid_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 2135 2136 devid_ptr->page_code = SVPD_DEVICE_ID; 2137 | 2124 desc2 = (struct scsi_vpd_id_descriptor *)(&desc1->identifier[0] + 2125 lun_name_len); 2126 desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] + 2127 wwnn_len); 2128 desc4 = (struct scsi_vpd_id_descriptor *)(&desc3->identifier[0] + 2129 wwpn_len); 2130 desc5 = (struct scsi_vpd_id_descriptor *)(&desc4->identifier[0] + 2131 sizeof(struct scsi_vpd_id_rel_trgt_port_id)); 2132 2133 if (lun != NULL) 2134 devid_ptr->device = (SID_QUAL_LU_CONNECTED << 5) | 2135 lun->be_lun->lun_type; 2136 else 2137 devid_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT; 2138 2139 devid_ptr->page_code = SVPD_DEVICE_ID; 2140 |
2138 scsi_ulto2b(devid_len - 4, devid_ptr->length); | 2141 scsi_ulto2b(data_len - 4, devid_ptr->length); |
2139 2140 /* 2141 * We're using a LUN association here. i.e., this device ID is a 2142 * per-LUN identifier. 2143 */ 2144 desc->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_ASCII; 2145 desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_T10; | 2142 2143 /* 2144 * We're using a LUN association here. i.e., this device ID is a 2145 * per-LUN identifier. 2146 */ 2147 desc->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_ASCII; 2148 desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_T10; |
2146 desc->length = sizeof(*t10id) + CTL_DEVID_LEN; | 2149 desc->length = sizeof(*t10id) + devid_len; |
2147 if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "vendor")) == NULL) { 2148 strncpy((char *)t10id->vendor, CTL_VENDOR, sizeof(t10id->vendor)); 2149 } else { 2150 memset(t10id->vendor, ' ', sizeof(t10id->vendor)); 2151 strncpy(t10id->vendor, val, 2152 min(sizeof(t10id->vendor), strlen(val))); 2153 } 2154 2155 /* 2156 * If we've actually got a backend, copy the device id from the 2157 * per-LUN data. Otherwise, set it to all spaces. 2158 */ 2159 if (lun != NULL) { 2160 /* 2161 * Copy the backend's LUN ID. 2162 */ 2163 strncpy((char *)t10id->vendor_spec_id, | 2150 if (lun == NULL || (val = ctl_get_opt(lun->be_lun, "vendor")) == NULL) { 2151 strncpy((char *)t10id->vendor, CTL_VENDOR, sizeof(t10id->vendor)); 2152 } else { 2153 memset(t10id->vendor, ' ', sizeof(t10id->vendor)); 2154 strncpy(t10id->vendor, val, 2155 min(sizeof(t10id->vendor), strlen(val))); 2156 } 2157 2158 /* 2159 * If we've actually got a backend, copy the device id from the 2160 * per-LUN data. Otherwise, set it to all spaces. 2161 */ 2162 if (lun != NULL) { 2163 /* 2164 * Copy the backend's LUN ID. 2165 */ 2166 strncpy((char *)t10id->vendor_spec_id, |
2164 (char *)lun->be_lun->device_id, CTL_DEVID_LEN); | 2167 (char *)lun->be_lun->device_id, devid_len); |
2165 } else { 2166 /* 2167 * No backend, set this to spaces. 2168 */ | 2168 } else { 2169 /* 2170 * No backend, set this to spaces. 2171 */ |
2169 memset(t10id->vendor_spec_id, 0x20, CTL_DEVID_LEN); | 2172 memset(t10id->vendor_spec_id, 0x20, devid_len); |
2170 } 2171 2172 /* 2173 * desc1 is for the unique LUN name. 2174 * 2175 * XXX: According to SPC-3, LUN must report the same ID through 2176 * all the ports. The code below, however, reports the 2177 * ID only via iSCSI. --- 791 unchanged lines hidden --- | 2173 } 2174 2175 /* 2176 * desc1 is for the unique LUN name. 2177 * 2178 * XXX: According to SPC-3, LUN must report the same ID through 2179 * all the ports. The code below, however, reports the 2180 * ID only via iSCSI. --- 791 unchanged lines hidden --- |