Print this page
3866 panic in idm module
3867 stmfCreateLu failed: GUID_IN_USE
3868 iscsi target not accepting any new connections
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed by: Jeremy Jones <jeremy@delphix.com>
Reviewed by: Eric Diven <eric.diven@delphix.com>


6092 }
6093 
6094 static uint16_t stmf_lu_id_gen_number = 0;
6095 
6096 stmf_status_t
6097 stmf_scsilib_uniq_lu_id(uint32_t company_id, scsi_devid_desc_t *lu_id)
6098 {
6099         return (stmf_scsilib_uniq_lu_id2(company_id, 0, lu_id));
6100 }
6101 
6102 stmf_status_t
6103 stmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
6104     scsi_devid_desc_t *lu_id)
6105 {
6106         uint8_t *p;
6107         struct timeval32 timestamp32;
6108         uint32_t *t = (uint32_t *)&timestamp32;
6109         struct ether_addr mac;
6110         uint8_t *e = (uint8_t *)&mac;
6111         int hid = (int)host_id;

6112 
6113         if (company_id == COMPANY_ID_NONE)
6114                 company_id = COMPANY_ID_SUN;
6115 
6116         if (lu_id->ident_length != 0x10)
6117                 return (STMF_INVALID_ARG);
6118 
6119         p = (uint8_t *)lu_id;
6120 
6121         atomic_add_16(&stmf_lu_id_gen_number, 1);
6122 
6123         p[0] = 0xf1; p[1] = 3; p[2] = 0; p[3] = 0x10;
6124         p[4] = ((company_id >> 20) & 0xf) | 0x60;
6125         p[5] = (company_id >> 12) & 0xff;
6126         p[6] = (company_id >> 4) & 0xff;
6127         p[7] = (company_id << 4) & 0xf0;
6128         if (hid == 0 && !localetheraddr((struct ether_addr *)NULL, &mac)) {
6129                 hid = BE_32((int)zone_get_hostid(NULL));
6130         }
6131         if (hid != 0) {
6132                 e[0] = (hid >> 24) & 0xff;
6133                 e[1] = (hid >> 16) & 0xff;
6134                 e[2] = (hid >> 8) & 0xff;
6135                 e[3] = hid & 0xff;
6136                 e[4] = e[5] = 0;
6137         }
6138         bcopy(e, p+8, 6);
6139         uniqtime32(&timestamp32);
6140         *t = BE_32(*t);
6141         bcopy(t, p+14, 4);
6142         p[18] = (stmf_lu_id_gen_number >> 8) & 0xff;
6143         p[19] = stmf_lu_id_gen_number & 0xff;
6144 
6145         return (STMF_SUCCESS);
6146 }
6147 
6148 /*
6149  * saa is sense key, ASC, ASCQ
6150  */
6151 void
6152 stmf_scsilib_send_status(scsi_task_t *task, uint8_t st, uint32_t saa)
6153 {
6154         uint8_t sd[18];
6155         task->task_scsi_status = st;
6156         if (st == 2) {
6157                 bzero(sd, 18);
6158                 sd[0] = 0x70;
6159                 sd[2] = (saa >> 16) & 0xf;
6160                 sd[7] = 10;
6161                 sd[12] = (saa >> 8) & 0xff;
6162                 sd[13] = saa & 0xff;
6163                 task->task_sense_data = sd;




6092 }
6093 
6094 static uint16_t stmf_lu_id_gen_number = 0;
6095 
6096 stmf_status_t
6097 stmf_scsilib_uniq_lu_id(uint32_t company_id, scsi_devid_desc_t *lu_id)
6098 {
6099         return (stmf_scsilib_uniq_lu_id2(company_id, 0, lu_id));
6100 }
6101 
6102 stmf_status_t
6103 stmf_scsilib_uniq_lu_id2(uint32_t company_id, uint32_t host_id,
6104     scsi_devid_desc_t *lu_id)
6105 {
6106         uint8_t *p;
6107         struct timeval32 timestamp32;
6108         uint32_t *t = (uint32_t *)&timestamp32;
6109         struct ether_addr mac;
6110         uint8_t *e = (uint8_t *)&mac;
6111         int hid = (int)host_id;
6112         uint16_t gen_number;
6113 
6114         if (company_id == COMPANY_ID_NONE)
6115                 company_id = COMPANY_ID_SUN;
6116 
6117         if (lu_id->ident_length != 0x10)
6118                 return (STMF_INVALID_ARG);
6119 
6120         p = (uint8_t *)lu_id;
6121 
6122         gen_number = atomic_add_16_nv(&stmf_lu_id_gen_number, 1);
6123 
6124         p[0] = 0xf1; p[1] = 3; p[2] = 0; p[3] = 0x10;
6125         p[4] = ((company_id >> 20) & 0xf) | 0x60;
6126         p[5] = (company_id >> 12) & 0xff;
6127         p[6] = (company_id >> 4) & 0xff;
6128         p[7] = (company_id << 4) & 0xf0;
6129         if (hid == 0 && !localetheraddr((struct ether_addr *)NULL, &mac)) {
6130                 hid = BE_32((int)zone_get_hostid(NULL));
6131         }
6132         if (hid != 0) {
6133                 e[0] = (hid >> 24) & 0xff;
6134                 e[1] = (hid >> 16) & 0xff;
6135                 e[2] = (hid >> 8) & 0xff;
6136                 e[3] = hid & 0xff;
6137                 e[4] = e[5] = 0;
6138         }
6139         bcopy(e, p+8, 6);
6140         uniqtime32(&timestamp32);
6141         *t = BE_32(*t);
6142         bcopy(t, p+14, 4);
6143         p[18] = (gen_number >> 8) & 0xff;
6144         p[19] = gen_number & 0xff;
6145 
6146         return (STMF_SUCCESS);
6147 }
6148 
6149 /*
6150  * saa is sense key, ASC, ASCQ
6151  */
6152 void
6153 stmf_scsilib_send_status(scsi_task_t *task, uint8_t st, uint32_t saa)
6154 {
6155         uint8_t sd[18];
6156         task->task_scsi_status = st;
6157         if (st == 2) {
6158                 bzero(sd, 18);
6159                 sd[0] = 0x70;
6160                 sd[2] = (saa >> 16) & 0xf;
6161                 sd[7] = 10;
6162                 sd[12] = (saa >> 8) & 0xff;
6163                 sd[13] = saa & 0xff;
6164                 task->task_sense_data = sd;