Deleted Added
full compact
ctl_frontend_iscsi.c (268259) ctl_frontend_iscsi.c (268260)
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 268259 2014-07-04 16:09:09Z mav $
29 * $FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268260 2014-07-04 16:10:14Z 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 268259 2014-07-04 16:09:09Z mav $");
37__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend_iscsi.c 268260 2014-07-04 16:10:14Z 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>

--- 2002 unchanged lines hidden (view full) ---

2048}
2049
2050static int
2051cfiscsi_devid(struct ctl_scsiio *ctsio, int alloc_len)
2052{
2053 struct cfiscsi_session *cs;
2054 struct scsi_vpd_device_id *devid_ptr;
2055 struct scsi_vpd_id_descriptor *desc, *desc1, *desc2, *desc3, *desc4;
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>

--- 2002 unchanged lines hidden (view full) ---

2048}
2049
2050static int
2051cfiscsi_devid(struct ctl_scsiio *ctsio, int alloc_len)
2052{
2053 struct cfiscsi_session *cs;
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;
2056 struct scsi_vpd_id_t10 *t10id;
2057 struct ctl_lun *lun;
2058 const struct icl_pdu *request;
2059 int i, ret;
2060 char *val;
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;
2061 size_t devid_len, wwpn_len, lun_name_len;
2062 size_t devid_len, wwnn_len, wwpn_len, lun_name_len;
2062
2063 lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
2064 request = ctsio->io_hdr.ctl_private[CTL_PRIV_FRONTEND].ptr;
2065 cs = PDU_SESSION(request);
2066
2067 wwpn_len = strlen(cs->cs_target->ct_name);
2068 wwpn_len += strlen(",t,0x0001");
2069 wwpn_len += 1; /* '\0' */
2070 if ((wwpn_len % 4) != 0)
2071 wwpn_len += (4 - (wwpn_len % 4));
2072
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
2073 if (lun == NULL) {
2074 lun_name_len = 0;
2075 } else {
2076 lun_name_len = strlen(cs->cs_target->ct_name);
2077 lun_name_len += strlen(",lun,XXXXXXXX");
2078 lun_name_len += 1; /* '\0' */
2079 if ((lun_name_len % 4) != 0)
2080 lun_name_len += (4 - (lun_name_len % 4));
2081 }
2082
2083 devid_len = sizeof(struct scsi_vpd_device_id) +
2084 sizeof(struct scsi_vpd_id_descriptor) +
2085 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN +
2086 sizeof(struct scsi_vpd_id_descriptor) + lun_name_len +
2079 if (lun == NULL) {
2080 lun_name_len = 0;
2081 } else {
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
2089 devid_len = sizeof(struct scsi_vpd_device_id) +
2090 sizeof(struct scsi_vpd_id_descriptor) +
2091 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN +
2092 sizeof(struct scsi_vpd_id_descriptor) + lun_name_len +
2093 sizeof(struct scsi_vpd_id_descriptor) + wwnn_len +
2087 sizeof(struct scsi_vpd_id_descriptor) + wwpn_len +
2088 sizeof(struct scsi_vpd_id_descriptor) +
2089 sizeof(struct scsi_vpd_id_rel_trgt_port_id) +
2090 sizeof(struct scsi_vpd_id_descriptor) +
2091 sizeof(struct scsi_vpd_id_trgt_port_grp_id);
2092
2093 ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO);
2094 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr;

--- 14 unchanged lines hidden (view full) ---

2109
2110 desc = (struct scsi_vpd_id_descriptor *)devid_ptr->desc_list;
2111 t10id = (struct scsi_vpd_id_t10 *)&desc->identifier[0];
2112 desc1 = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] +
2113 sizeof(struct scsi_vpd_id_t10) + CTL_DEVID_LEN);
2114 desc2 = (struct scsi_vpd_id_descriptor *)(&desc1->identifier[0] +
2115 lun_name_len);
2116 desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] +
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
2100 ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO);
2101 devid_ptr = (struct scsi_vpd_device_id *)ctsio->kern_data_ptr;

--- 14 unchanged lines hidden (view full) ---

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] +
2120 sizeof(struct scsi_vpd_id_t10) + CTL_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] +
2117 wwpn_len);
2124 wwnn_len);
2118 desc4 = (struct scsi_vpd_id_descriptor *)(&desc3->identifier[0] +
2125 desc4 = (struct scsi_vpd_id_descriptor *)(&desc3->identifier[0] +
2126 wwpn_len);
2127 desc5 = (struct scsi_vpd_id_descriptor *)(&desc4->identifier[0] +
2119 sizeof(struct scsi_vpd_id_rel_trgt_port_id));
2120
2121 if (lun != NULL)
2122 devid_ptr->device = (SID_QUAL_LU_CONNECTED << 5) |
2123 lun->be_lun->lun_type;
2124 else
2125 devid_ptr->device = (SID_QUAL_LU_OFFLINE << 5) | T_DIRECT;
2126

--- 57 unchanged lines hidden (view full) ---

2184 ret = snprintf(desc1->identifier, lun_name_len, "%s,lun,%d",
2185 cs->cs_target->ct_name, i);
2186 KASSERT(ret > 0 && ret <= lun_name_len, ("bad snprintf"));
2187 } else {
2188 KASSERT(lun_name_len == 0, ("no lun, but lun_name_len != 0"));
2189 }
2190
2191 /*
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

--- 57 unchanged lines hidden (view full) ---

2193 ret = snprintf(desc1->identifier, lun_name_len, "%s,lun,%d",
2194 cs->cs_target->ct_name, i);
2195 KASSERT(ret > 0 && ret <= lun_name_len, ("bad snprintf"));
2196 } else {
2197 KASSERT(lun_name_len == 0, ("no lun, but lun_name_len != 0"));
2198 }
2199
2200 /*
2192 * desc2 is for the WWPN which is a port asscociation.
2201 * desc2 is for the Target Name.
2193 */
2202 */
2194 desc2->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8;
2195 desc2->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2203 desc2->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8;
2204 desc2->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_TARGET |
2196 SVPD_ID_TYPE_SCSI_NAME;
2205 SVPD_ID_TYPE_SCSI_NAME;
2197 desc2->length = wwpn_len;
2198 snprintf(desc2->identifier, wwpn_len, "%s,t,0x%4.4x",
2206 desc2->length = wwnn_len;
2207 snprintf(desc2->identifier, wwnn_len, "%s", cs->cs_target->ct_name);
2208
2209 /*
2210 * desc3 is for the WWPN which is a port asscociation.
2211 */
2212 desc3->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_UTF8;
2213 desc3->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2214 SVPD_ID_TYPE_SCSI_NAME;
2215 desc3->length = wwpn_len;
2216 snprintf(desc3->identifier, wwpn_len, "%s,t,0x%4.4x",
2199 cs->cs_target->ct_name, cs->cs_portal_group_tag);
2200
2201 /*
2202 * desc3 is for the Relative Target Port(type 4h) identifier
2203 */
2217 cs->cs_target->ct_name, cs->cs_portal_group_tag);
2218
2219 /*
2220 * desc3 is for the Relative Target Port(type 4h) identifier
2221 */
2204 desc3->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY;
2205 desc3->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2222 desc4->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY;
2223 desc4->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2206 SVPD_ID_TYPE_RELTARG;
2224 SVPD_ID_TYPE_RELTARG;
2207 desc3->length = 4;
2208 desc3->identifier[3] = 1;
2225 desc4->length = 4;
2226 desc4->identifier[3] = 1;
2209
2210 /*
2211 * desc4 is for the Target Port Group(type 5h) identifier
2212 */
2227
2228 /*
2229 * desc4 is for the Target Port Group(type 5h) identifier
2230 */
2213 desc4->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY;
2214 desc4->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2231 desc5->proto_codeset = (SCSI_PROTO_ISCSI << 4) | SVPD_ID_CODESET_BINARY;
2232 desc5->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT |
2215 SVPD_ID_TYPE_TPORTGRP;
2233 SVPD_ID_TYPE_TPORTGRP;
2216 desc4->length = 4;
2217 desc4->identifier[3] = 1;
2234 desc5->length = 4;
2235 desc5->identifier[3] = 1;
2218
2219 ctsio->scsi_status = SCSI_STATUS_OK;
2220
2221 ctsio->be_move_done = ctl_config_move_done;
2222 ctl_datamove((union ctl_io *)ctsio);
2223
2224 return (CTL_RETVAL_COMPLETE);
2225}

--- 714 unchanged lines hidden ---
2236
2237 ctsio->scsi_status = SCSI_STATUS_OK;
2238
2239 ctsio->be_move_done = ctl_config_move_done;
2240 ctl_datamove((union ctl_io *)ctsio);
2241
2242 return (CTL_RETVAL_COMPLETE);
2243}

--- 714 unchanged lines hidden ---