Lines Matching refs:lun

399 static void ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,
404 static int ctl_enable_lun(struct ctl_lun *lun);
405 static int ctl_disable_lun(struct ctl_lun *lun);
406 static int ctl_free_lun(struct ctl_lun *lun);
409 static int ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun,
415 static void ctl_pro_preempt_other(struct ctl_lun *lun,
436 static ctl_action ctl_check_for_blockage(struct ctl_lun *lun,
439 static ctl_action ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io,
441 static void ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io,
443 static void ctl_try_unblock_others(struct ctl_lun *lun, union ctl_io *io,
445 static int ctl_scsiio_lun_check(struct ctl_lun *lun,
455 static void ctl_do_lun_reset(struct ctl_lun *lun, uint32_t initidx,
498 static uint64_t ctl_get_prkey(struct ctl_lun *lun, uint32_t residx);
499 static void ctl_clr_prkey(struct ctl_lun *lun, uint32_t residx);
500 static void ctl_alloc_prkey(struct ctl_lun *lun, uint32_t residx);
501 static void ctl_set_prkey(struct ctl_lun *lun, uint32_t residx, uint64_t key);
617 struct ctl_lun *lun = CTL_LUN(io); in ctl_ha_datamove() local
719 if (lun) in ctl_ha_datamove()
720 mtx_lock(&lun->lun_lock); in ctl_ha_datamove()
722 if (lun) in ctl_ha_datamove()
723 mtx_unlock(&lun->lun_lock); in ctl_ha_datamove()
730 if (lun) in ctl_ha_datamove()
731 mtx_unlock(&lun->lun_lock); in ctl_ha_datamove()
800 ctl_isc_announce_lun(struct ctl_lun *lun) in ctl_isc_announce_lun() argument
802 struct ctl_softc *softc = lun->ctl_softc; in ctl_isc_announce_lun()
809 mtx_lock(&lun->lun_lock); in ctl_isc_announce_lun()
810 i = sizeof(msg->lun); in ctl_isc_announce_lun()
811 if (lun->lun_devid) in ctl_isc_announce_lun()
812 i += lun->lun_devid->len; in ctl_isc_announce_lun()
813 i += sizeof(pr_key) * lun->pr_key_count; in ctl_isc_announce_lun()
815 mtx_unlock(&lun->lun_lock); in ctl_isc_announce_lun()
817 mtx_lock(&lun->lun_lock); in ctl_isc_announce_lun()
818 k = sizeof(msg->lun); in ctl_isc_announce_lun()
819 if (lun->lun_devid) in ctl_isc_announce_lun()
820 k += lun->lun_devid->len; in ctl_isc_announce_lun()
821 k += sizeof(pr_key) * lun->pr_key_count; in ctl_isc_announce_lun()
827 bzero(&msg->lun, sizeof(msg->lun)); in ctl_isc_announce_lun()
829 msg->hdr.nexus.targ_lun = lun->lun; in ctl_isc_announce_lun()
830 msg->hdr.nexus.targ_mapped_lun = lun->lun; in ctl_isc_announce_lun()
831 msg->lun.flags = lun->flags; in ctl_isc_announce_lun()
832 msg->lun.pr_generation = lun->pr_generation; in ctl_isc_announce_lun()
833 msg->lun.pr_res_idx = lun->pr_res_idx; in ctl_isc_announce_lun()
834 msg->lun.pr_res_type = lun->pr_res_type; in ctl_isc_announce_lun()
835 msg->lun.pr_key_count = lun->pr_key_count; in ctl_isc_announce_lun()
837 if (lun->lun_devid) { in ctl_isc_announce_lun()
838 msg->lun.lun_devid_len = lun->lun_devid->len; in ctl_isc_announce_lun()
839 memcpy(&msg->lun.data[i], lun->lun_devid->data, in ctl_isc_announce_lun()
840 msg->lun.lun_devid_len); in ctl_isc_announce_lun()
841 i += msg->lun.lun_devid_len; in ctl_isc_announce_lun()
844 if ((pr_key.pr_key = ctl_get_prkey(lun, k)) == 0) in ctl_isc_announce_lun()
847 memcpy(&msg->lun.data[i], &pr_key, sizeof(pr_key)); in ctl_isc_announce_lun()
850 mtx_unlock(&lun->lun_lock); in ctl_isc_announce_lun()
851 ctl_ha_msg_send(CTL_HA_CHAN_CTL, &msg->lun, sizeof(msg->lun) + i, in ctl_isc_announce_lun()
855 if (lun->flags & CTL_LUN_PRIMARY_SC) { in ctl_isc_announce_lun()
857 ctl_isc_announce_mode(lun, -1, in ctl_isc_announce_lun()
858 lun->mode_pages.index[i].page_code & SMPH_PC_MASK, in ctl_isc_announce_lun()
859 lun->mode_pages.index[i].subpage); in ctl_isc_announce_lun()
962 ctl_isc_announce_mode(struct ctl_lun *lun, uint32_t initidx, in ctl_isc_announce_mode() argument
965 struct ctl_softc *softc = lun->ctl_softc; in ctl_isc_announce_mode()
972 if ((lun->mode_pages.index[i].page_code & SMPH_PC_MASK) == in ctl_isc_announce_mode()
973 page && lun->mode_pages.index[i].subpage == subpage) in ctl_isc_announce_mode()
980 if (lun->mode_pages.index[i].page_data == NULL) in ctl_isc_announce_mode()
983 l = sizeof(msg->mode) + lun->mode_pages.index[i].page_len; in ctl_isc_announce_mode()
988 msg->hdr.nexus.targ_lun = lun->lun; in ctl_isc_announce_mode()
989 msg->hdr.nexus.targ_mapped_lun = lun->lun; in ctl_isc_announce_mode()
992 msg->mode.page_len = lun->mode_pages.index[i].page_len; in ctl_isc_announce_mode()
993 memcpy(msg->mode.data, lun->mode_pages.index[i].page_data, in ctl_isc_announce_mode()
1003 struct ctl_lun *lun; in ctl_isc_ha_link_up() local
1025 STAILQ_FOREACH(lun, &softc->lun_list, links) in ctl_isc_ha_link_up()
1026 ctl_isc_announce_lun(lun); in ctl_isc_ha_link_up()
1033 struct ctl_lun *lun; in ctl_isc_ha_link_down() local
1038 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_isc_ha_link_down()
1039 mtx_lock(&lun->lun_lock); in ctl_isc_ha_link_down()
1040 if (lun->flags & CTL_LUN_PEER_SC_PRIMARY) { in ctl_isc_ha_link_down()
1041 lun->flags &= ~CTL_LUN_PEER_SC_PRIMARY; in ctl_isc_ha_link_down()
1042 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE); in ctl_isc_ha_link_down()
1044 mtx_unlock(&lun->lun_lock); in ctl_isc_ha_link_down()
1051 io->io_hdr.nexus.targ_mapped_lun = lun->lun; in ctl_isc_ha_link_down()
1072 struct ctl_lun *lun; in ctl_isc_ua() local
1084 (lun = softc->ctl_luns[msg->hdr.nexus.targ_mapped_lun]) == NULL) { in ctl_isc_ua()
1088 mtx_lock(&lun->lun_lock); in ctl_isc_ua()
1091 memcpy(lun->ua_tpt_info, msg->ua.ua_info, 8); in ctl_isc_ua()
1095 ctl_est_ua_all(lun, iid, msg->ua.ua_type); in ctl_isc_ua()
1097 ctl_clr_ua_all(lun, iid, msg->ua.ua_type); in ctl_isc_ua()
1100 ctl_est_ua(lun, iid, msg->ua.ua_type); in ctl_isc_ua()
1102 ctl_clr_ua(lun, iid, msg->ua.ua_type); in ctl_isc_ua()
1104 mtx_unlock(&lun->lun_lock); in ctl_isc_ua()
1110 struct ctl_lun *lun; in ctl_isc_lun_sync() local
1122 i = msg->lun.lun_devid_len + msg->lun.pr_key_count * sizeof(pr_key); in ctl_isc_lun_sync()
1133 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_isc_lun_sync()
1137 mtx_lock(&lun->lun_lock); in ctl_isc_lun_sync()
1139 if (lun->flags & CTL_LUN_DISABLED) { in ctl_isc_lun_sync()
1140 mtx_unlock(&lun->lun_lock); in ctl_isc_lun_sync()
1143 i = (lun->lun_devid != NULL) ? lun->lun_devid->len : 0; in ctl_isc_lun_sync()
1144 if (msg->lun.lun_devid_len != i || (i > 0 && in ctl_isc_lun_sync()
1145 memcmp(&msg->lun.data[0], lun->lun_devid->data, i) != 0)) { in ctl_isc_lun_sync()
1146 mtx_unlock(&lun->lun_lock); in ctl_isc_lun_sync()
1152 oflags = lun->flags; in ctl_isc_lun_sync()
1153 if ((msg->lun.flags & CTL_LUN_PRIMARY_SC) && in ctl_isc_lun_sync()
1154 (msg->lun.flags & CTL_LUN_DISABLED) == 0) in ctl_isc_lun_sync()
1155 lun->flags |= CTL_LUN_PEER_SC_PRIMARY; in ctl_isc_lun_sync()
1157 lun->flags &= ~CTL_LUN_PEER_SC_PRIMARY; in ctl_isc_lun_sync()
1158 if (oflags != lun->flags) in ctl_isc_lun_sync()
1159 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE); in ctl_isc_lun_sync()
1162 if ((lun->flags & CTL_LUN_PRIMARY_SC) == 0 && in ctl_isc_lun_sync()
1163 (lun->flags & CTL_LUN_PEER_SC_PRIMARY)) { in ctl_isc_lun_sync()
1164 lun->pr_generation = msg->lun.pr_generation; in ctl_isc_lun_sync()
1165 lun->pr_res_idx = msg->lun.pr_res_idx; in ctl_isc_lun_sync()
1166 lun->pr_res_type = msg->lun.pr_res_type; in ctl_isc_lun_sync()
1167 lun->pr_key_count = msg->lun.pr_key_count; in ctl_isc_lun_sync()
1169 ctl_clr_prkey(lun, k); in ctl_isc_lun_sync()
1170 for (k = 0; k < msg->lun.pr_key_count; k++) { in ctl_isc_lun_sync()
1171 memcpy(&pr_key, &msg->lun.data[i], in ctl_isc_lun_sync()
1173 ctl_alloc_prkey(lun, pr_key.pr_iid); in ctl_isc_lun_sync()
1174 ctl_set_prkey(lun, pr_key.pr_iid, in ctl_isc_lun_sync()
1180 mtx_unlock(&lun->lun_lock); in ctl_isc_lun_sync()
1183 (msg->lun.flags & CTL_LUN_PRIMARY_SC) ? in ctl_isc_lun_sync()
1187 if ((lun->flags & CTL_LUN_PRIMARY_SC) && in ctl_isc_lun_sync()
1188 (msg->lun.flags & CTL_LUN_PEER_SC_PRIMARY) == 0) in ctl_isc_lun_sync()
1189 ctl_isc_announce_lun(lun); in ctl_isc_lun_sync()
1197 struct ctl_lun *lun; in ctl_isc_port_sync() local
1313 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_isc_port_sync()
1314 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_isc_port_sync()
1316 mtx_lock(&lun->lun_lock); in ctl_isc_port_sync()
1317 ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); in ctl_isc_port_sync()
1318 mtx_unlock(&lun->lun_lock); in ctl_isc_port_sync()
1403 struct ctl_lun *lun; in ctl_isc_mode_sync() local
1424 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_isc_mode_sync()
1428 mtx_lock(&lun->lun_lock); in ctl_isc_mode_sync()
1430 if (lun->flags & CTL_LUN_DISABLED) { in ctl_isc_mode_sync()
1431 mtx_unlock(&lun->lun_lock); in ctl_isc_mode_sync()
1435 if ((lun->mode_pages.index[i].page_code & SMPH_PC_MASK) == in ctl_isc_mode_sync()
1437 lun->mode_pages.index[i].subpage == msg->mode.subpage) in ctl_isc_mode_sync()
1441 mtx_unlock(&lun->lun_lock); in ctl_isc_mode_sync()
1444 memcpy(lun->mode_pages.index[i].page_data, msg->mode.data, in ctl_isc_mode_sync()
1445 min(lun->mode_pages.index[i].page_len, msg->mode.page_len)); in ctl_isc_mode_sync()
1448 ctl_est_ua_all(lun, initidx, CTL_UA_MODE_CHANGE); in ctl_isc_mode_sync()
1449 mtx_unlock(&lun->lun_lock); in ctl_isc_mode_sync()
1780 ctl_est_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua) in ctl_est_ua() argument
1782 struct ctl_softc *softc = lun->ctl_softc; in ctl_est_ua()
1787 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_est_ua()
1788 pu = lun->pending_ua[initidx / CTL_MAX_INIT_PER_PORT]; in ctl_est_ua()
1795 ctl_est_ua_port(struct ctl_lun *lun, int port, uint32_t except, ctl_ua_type ua) in ctl_est_ua_port() argument
1799 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_est_ua_port()
1800 if (lun->pending_ua[port] == NULL) in ctl_est_ua_port()
1805 lun->pending_ua[port][i] |= ua; in ctl_est_ua_port()
1810 ctl_est_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua) in ctl_est_ua_all() argument
1812 struct ctl_softc *softc = lun->ctl_softc; in ctl_est_ua_all()
1815 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_est_ua_all()
1817 ctl_est_ua_port(lun, i, except, ua); in ctl_est_ua_all()
1821 ctl_clr_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua) in ctl_clr_ua() argument
1823 struct ctl_softc *softc = lun->ctl_softc; in ctl_clr_ua()
1828 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_clr_ua()
1829 pu = lun->pending_ua[initidx / CTL_MAX_INIT_PER_PORT]; in ctl_clr_ua()
1836 ctl_clr_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua) in ctl_clr_ua_all() argument
1838 struct ctl_softc *softc = lun->ctl_softc; in ctl_clr_ua_all()
1841 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_clr_ua_all()
1843 if (lun->pending_ua[i] == NULL) in ctl_clr_ua_all()
1848 lun->pending_ua[i][j] &= ~ua; in ctl_clr_ua_all()
1857 struct ctl_lun *lun; in ctl_clr_ua_allluns() local
1860 STAILQ_FOREACH(lun, &ctl_softc->lun_list, links) { in ctl_clr_ua_allluns()
1861 mtx_lock(&lun->lun_lock); in ctl_clr_ua_allluns()
1862 ctl_clr_ua(lun, initidx, ua_type); in ctl_clr_ua_allluns()
1863 mtx_unlock(&lun->lun_lock); in ctl_clr_ua_allluns()
1871 struct ctl_lun *lun; in ctl_ha_role_sysctl() local
1885 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ha_role_sysctl()
1889 ireq.reqdata.modify.lun_id = lun->lun; in ctl_ha_role_sysctl()
1890 lun->backend->ioctl(NULL, CTL_LUN_REQ, (caddr_t)&ireq, 0, in ctl_ha_role_sysctl()
2322 struct ctl_lun *lun; in ctl_serialize_other_sc_cmd() local
2339 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_serialize_other_sc_cmd()
2351 mtx_lock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2358 if (lun->flags & CTL_LUN_DISABLED) { in ctl_serialize_other_sc_cmd()
2359 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2366 if (ctl_scsiio_lun_check(lun, entry, ctsio) != 0) { in ctl_serialize_other_sc_cmd()
2367 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2371 CTL_LUN(ctsio) = lun; in ctl_serialize_other_sc_cmd()
2372 CTL_BACKEND_LUN(ctsio) = lun->be_lun; in ctl_serialize_other_sc_cmd()
2379 if (LIST_EMPTY(&lun->ooa_queue)) in ctl_serialize_other_sc_cmd()
2380 lun->idle_time += getsbinuptime() - lun->last_busy; in ctl_serialize_other_sc_cmd()
2382 LIST_INSERT_HEAD(&lun->ooa_queue, &ctsio->io_hdr, ooa_links); in ctl_serialize_other_sc_cmd()
2385 switch (ctl_check_ooa(lun, (union ctl_io *)ctsio, &bio)) { in ctl_serialize_other_sc_cmd()
2391 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2394 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2408 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2412 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2417 mtx_unlock(&lun->lun_lock); in ctl_serialize_other_sc_cmd()
2437 ctl_ioctl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num, in ctl_ioctl_fill_ooa() argument
2442 mtx_lock(&lun->lun_lock); in ctl_ioctl_fill_ooa()
2443 ioh = LIST_FIRST(&lun->ooa_queue); in ctl_ioctl_fill_ooa()
2445 mtx_unlock(&lun->lun_lock); in ctl_ioctl_fill_ooa()
2450 for ( ; ioh; ioh = LIST_PREV(ioh, &lun->ooa_queue, ctl_io_hdr, ooa_links)) { in ctl_ioctl_fill_ooa()
2469 entry->lun_num = lun->lun; in ctl_ioctl_fill_ooa()
2497 mtx_unlock(&lun->lun_lock); in ctl_ioctl_fill_ooa()
2577 struct ctl_lun *lun; in ctl_ioctl() local
2706 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ioctl()
2707 ctl_ioctl_fill_ooa(lun, &cur_fill_num, in ctl_ioctl()
2711 lun = softc->ctl_luns[ooa_hdr->lun_num]; in ctl_ioctl()
2712 ctl_ioctl_fill_ooa(lun, &cur_fill_num, ooa_hdr, in ctl_ioctl()
2747 (lun = softc->ctl_luns[delay_info->lun_id]) == NULL) { in ctl_ioctl()
2752 mtx_lock(&lun->lun_lock); in ctl_ioctl()
2765 lun->delay_info.datamove_type = delay_info->delay_type; in ctl_ioctl()
2766 lun->delay_info.datamove_delay = delay_info->delay_secs; in ctl_ioctl()
2769 lun->delay_info.done_type = delay_info->delay_type; in ctl_ioctl()
2770 lun->delay_info.done_delay = delay_info->delay_secs; in ctl_ioctl()
2776 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
2793 (lun = softc->ctl_luns[err_desc->lun_id]) == NULL) { in ctl_ioctl()
2801 mtx_lock(&lun->lun_lock); in ctl_ioctl()
2813 STAILQ_INSERT_TAIL(&lun->error_list, new_err_desc, links); in ctl_ioctl()
2821 new_err_desc->serial = lun->error_serial; in ctl_ioctl()
2822 err_desc->serial = lun->error_serial; in ctl_ioctl()
2823 lun->error_serial++; in ctl_ioctl()
2825 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
2837 (lun = softc->ctl_luns[delete_desc->lun_id]) == NULL) { in ctl_ioctl()
2844 mtx_lock(&lun->lun_lock); in ctl_ioctl()
2846 STAILQ_FOREACH_SAFE(desc, &lun->error_list, links, desc2) { in ctl_ioctl()
2850 STAILQ_REMOVE(&lun->error_list, desc, ctl_error_desc, in ctl_ioctl()
2855 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
2872 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ioctl()
2873 mtx_lock(&lun->lun_lock); in ctl_ioctl()
2874 if ((lun->flags & CTL_LUN_DISABLED) != 0) { in ctl_ioctl()
2875 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
2880 if (lun->pr_keys[j] == NULL) in ctl_ioctl()
2883 if (lun->pr_keys[j][k] == 0) in ctl_ioctl()
2886 "%#jx\n", lun->lun, j, k, in ctl_ioctl()
2887 (uintmax_t)lun->pr_keys[j][k]); in ctl_ioctl()
2890 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
3065 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ioctl()
3066 mtx_lock(&lun->lun_lock); in ctl_ioctl()
3068 (uintmax_t)lun->lun); in ctl_ioctl()
3079 (lun->backend == NULL) ? "none" : in ctl_ioctl()
3080 lun->backend->name); in ctl_ioctl()
3086 lun->be_lun->lun_type); in ctl_ioctl()
3091 if (lun->backend == NULL) { in ctl_ioctl()
3099 (lun->be_lun->maxlba > 0) ? in ctl_ioctl()
3100 lun->be_lun->maxlba + 1 : 0); in ctl_ioctl()
3106 lun->be_lun->blocksize); in ctl_ioctl()
3117 lun->be_lun->serial_num, in ctl_ioctl()
3118 sizeof(lun->be_lun->serial_num)); in ctl_ioctl()
3134 lun->be_lun->device_id, in ctl_ioctl()
3135 sizeof(lun->be_lun->device_id)); in ctl_ioctl()
3145 if (lun->backend->lun_info != NULL) { in ctl_ioctl()
3146 retval = lun->backend->lun_info(lun->be_lun, sb); in ctl_ioctl()
3152 while ((name = nvlist_next(lun->be_lun->options, &type, in ctl_ioctl()
3158 lun->be_lun->options, name, NULL); in ctl_ioctl()
3170 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
3172 if (lun != NULL) in ctl_ioctl()
3173 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
3492 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ioctl()
3493 if (ctl_lun_map_to_port(port, lun->lun) == in ctl_ioctl()
3496 mtx_lock(&lun->lun_lock); in ctl_ioctl()
3497 ctl_est_ua_port(lun, lm->port, -1, in ctl_ioctl()
3499 mtx_unlock(&lun->lun_lock); in ctl_ioctl()
3504 if (lm->lun == UINT32_MAX) in ctl_ioctl()
3506 else if (lm->lun < ctl_max_luns && in ctl_ioctl()
3507 softc->ctl_luns[lm->lun] != NULL) in ctl_ioctl()
3508 retval = ctl_lun_map_set(port, lm->plun, lm->lun); in ctl_ioctl()
3512 if (lm->lun == UINT32_MAX) in ctl_ioctl()
3532 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_ioctl()
3533 if (lun->lun < stats->first_item) in ctl_ioctl()
3535 if (stats->fill_len + sizeof(lun->stats) > in ctl_ioctl()
3540 retval = copyout(&lun->stats, &stats->stats[i++], in ctl_ioctl()
3541 sizeof(lun->stats)); in ctl_ioctl()
3544 stats->fill_len += sizeof(lun->stats); in ctl_ioctl()
3634 struct ctl_lun *lun; in ctl_lun_map_init() local
3651 STAILQ_FOREACH(lun, &softc->lun_list, links) in ctl_lun_map_init()
3652 port->lun_disable(port->targ_lun_arg, lun->lun); in ctl_lun_map_init()
3663 struct ctl_lun *lun; in ctl_lun_map_deinit() local
3672 STAILQ_FOREACH(lun, &softc->lun_list, links) in ctl_lun_map_deinit()
3673 port->lun_enable(port->targ_lun_arg, lun->lun); in ctl_lun_map_deinit()
3752 uint8_t lun[8]; in ctl_decode_lun() local
3755 be64enc(lun, encoded); in ctl_decode_lun()
3756 switch (lun[0] & RPL_LUNDATA_ATYP_MASK) { in ctl_decode_lun()
3758 if ((lun[0] & 0x3f) == 0 && lun[2] == 0 && lun[3] == 0 && in ctl_decode_lun()
3759 lun[4] == 0 && lun[5] == 0 && lun[6] == 0 && lun[7] == 0) in ctl_decode_lun()
3760 result = lun[1]; in ctl_decode_lun()
3763 if (lun[2] == 0 && lun[3] == 0 && lun[4] == 0 && lun[5] == 0 && in ctl_decode_lun()
3764 lun[6] == 0 && lun[7] == 0) in ctl_decode_lun()
3765 result = ((lun[0] & 0x3f) << 8) + lun[1]; in ctl_decode_lun()
3768 switch (lun[0] & RPL_LUNDATA_EXT_EAM_MASK) { in ctl_decode_lun()
3770 switch (lun[0] & RPL_LUNDATA_EXT_LEN_MASK) { in ctl_decode_lun()
3772 result = lun[1]; in ctl_decode_lun()
3775 result = (lun[1] << 16) + (lun[2] << 8) + in ctl_decode_lun()
3776 lun[3]; in ctl_decode_lun()
3779 if (lun[1] == 0 && lun[6] == 0 && lun[7] == 0) in ctl_decode_lun()
3780 result = (lun[2] << 24) + in ctl_decode_lun()
3781 (lun[3] << 16) + (lun[4] << 8) + in ctl_decode_lun()
3782 lun[5]; in ctl_decode_lun()
3869 ctl_get_prkey(struct ctl_lun *lun, uint32_t residx) in ctl_get_prkey() argument
3873 t = lun->pr_keys[residx/CTL_MAX_INIT_PER_PORT]; in ctl_get_prkey()
3880 ctl_clr_prkey(struct ctl_lun *lun, uint32_t residx) in ctl_clr_prkey() argument
3884 t = lun->pr_keys[residx/CTL_MAX_INIT_PER_PORT]; in ctl_clr_prkey()
3891 ctl_alloc_prkey(struct ctl_lun *lun, uint32_t residx) in ctl_alloc_prkey() argument
3897 if (lun->pr_keys[i] != NULL) in ctl_alloc_prkey()
3899 mtx_unlock(&lun->lun_lock); in ctl_alloc_prkey()
3902 mtx_lock(&lun->lun_lock); in ctl_alloc_prkey()
3903 if (lun->pr_keys[i] == NULL) in ctl_alloc_prkey()
3904 lun->pr_keys[i] = p; in ctl_alloc_prkey()
3910 ctl_set_prkey(struct ctl_lun *lun, uint32_t residx, uint64_t key) in ctl_set_prkey() argument
3914 t = lun->pr_keys[residx/CTL_MAX_INIT_PER_PORT]; in ctl_set_prkey()
4071 ctl_init_page_index(struct ctl_lun *lun) in ctl_init_page_index() argument
4078 memcpy(&lun->mode_pages.index, page_index_template, in ctl_init_page_index()
4082 page_index = &lun->mode_pages.index[i]; in ctl_init_page_index()
4083 if (lun->be_lun->lun_type == T_DIRECT && in ctl_init_page_index()
4086 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_init_page_index()
4089 if (lun->be_lun->lun_type == T_CDROM && in ctl_init_page_index()
4099 memcpy(&lun->mode_pages.rw_er_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4102 memcpy(&lun->mode_pages.rw_er_page[CTL_PAGE_CHANGEABLE], in ctl_init_page_index()
4105 memcpy(&lun->mode_pages.rw_er_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4108 memcpy(&lun->mode_pages.rw_er_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4112 (uint8_t *)lun->mode_pages.rw_er_page; in ctl_init_page_index()
4119 memcpy(&lun->mode_pages.verify_er_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4122 memcpy(&lun->mode_pages.verify_er_page[CTL_PAGE_CHANGEABLE], in ctl_init_page_index()
4125 memcpy(&lun->mode_pages.verify_er_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4128 memcpy(&lun->mode_pages.verify_er_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4132 (uint8_t *)lun->mode_pages.verify_er_page; in ctl_init_page_index()
4141 memcpy(&lun->mode_pages.caching_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4144 memcpy(&lun->mode_pages.caching_page[ in ctl_init_page_index()
4147 memcpy(&lun->mode_pages.caching_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4150 caching_page = &lun->mode_pages.caching_page[ in ctl_init_page_index()
4152 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4156 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4160 memcpy(&lun->mode_pages.caching_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4161 &lun->mode_pages.caching_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4164 (uint8_t *)lun->mode_pages.caching_page; in ctl_init_page_index()
4172 memcpy(&lun->mode_pages.control_page[ in ctl_init_page_index()
4176 memcpy(&lun->mode_pages.control_page[ in ctl_init_page_index()
4180 memcpy(&lun->mode_pages.control_page[ in ctl_init_page_index()
4184 control_page = &lun->mode_pages.control_page[ in ctl_init_page_index()
4186 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4195 memcpy(&lun->mode_pages.control_page[ in ctl_init_page_index()
4197 &lun->mode_pages.control_page[ in ctl_init_page_index()
4201 (uint8_t *)lun->mode_pages.control_page; in ctl_init_page_index()
4205 memcpy(&lun->mode_pages.control_ext_page[ in ctl_init_page_index()
4209 memcpy(&lun->mode_pages.control_ext_page[ in ctl_init_page_index()
4213 memcpy(&lun->mode_pages.control_ext_page[ in ctl_init_page_index()
4217 memcpy(&lun->mode_pages.control_ext_page[ in ctl_init_page_index()
4219 &lun->mode_pages.control_ext_page[ in ctl_init_page_index()
4223 (uint8_t *)lun->mode_pages.control_ext_page; in ctl_init_page_index()
4234 memcpy(&lun->mode_pages.ie_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4237 memcpy(&lun->mode_pages.ie_page[ in ctl_init_page_index()
4240 memcpy(&lun->mode_pages.ie_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4243 memcpy(&lun->mode_pages.ie_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4247 (uint8_t *)lun->mode_pages.ie_page; in ctl_init_page_index()
4252 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4255 memcpy(&lun->mode_pages.lbp_page[ in ctl_init_page_index()
4258 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4261 page = &lun->mode_pages.lbp_page[CTL_PAGE_SAVED]; in ctl_init_page_index()
4262 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4268 if (lun->be_lun->blocksize) in ctl_init_page_index()
4269 ival /= lun->be_lun->blocksize; in ctl_init_page_index()
4275 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4281 if (lun->be_lun->blocksize) in ctl_init_page_index()
4282 ival /= lun->be_lun->blocksize; in ctl_init_page_index()
4288 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4294 if (lun->be_lun->blocksize) in ctl_init_page_index()
4295 ival /= lun->be_lun->blocksize; in ctl_init_page_index()
4301 value = dnvlist_get_string(lun->be_lun->options, in ctl_init_page_index()
4307 if (lun->be_lun->blocksize) in ctl_init_page_index()
4308 ival /= lun->be_lun->blocksize; in ctl_init_page_index()
4314 memcpy(&lun->mode_pages.lbp_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4315 &lun->mode_pages.lbp_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4318 (uint8_t *)lun->mode_pages.lbp_page; in ctl_init_page_index()
4331 memcpy(&lun->mode_pages.cddvd_page[CTL_PAGE_DEFAULT], in ctl_init_page_index()
4334 memcpy(&lun->mode_pages.cddvd_page[ in ctl_init_page_index()
4337 memcpy(&lun->mode_pages.cddvd_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4340 memcpy(&lun->mode_pages.cddvd_page[CTL_PAGE_CURRENT], in ctl_init_page_index()
4341 &lun->mode_pages.cddvd_page[CTL_PAGE_SAVED], in ctl_init_page_index()
4344 (uint8_t *)lun->mode_pages.cddvd_page; in ctl_init_page_index()
4356 ctl_init_log_page_index(struct ctl_lun *lun) in ctl_init_log_page_index() argument
4361 memcpy(&lun->log_pages.index, log_page_index_template, in ctl_init_log_page_index()
4366 page_index = &lun->log_pages.index[i]; in ctl_init_log_page_index()
4367 if (lun->be_lun->lun_type == T_DIRECT && in ctl_init_log_page_index()
4370 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_init_log_page_index()
4373 if (lun->be_lun->lun_type == T_CDROM && in ctl_init_log_page_index()
4378 lun->backend->lun_attr == NULL) in ctl_init_log_page_index()
4382 lun->log_pages.pages_page[j] = page_index->page_code; in ctl_init_log_page_index()
4386 lun->log_pages.subpages_page[k*2] = page_index->page_code; in ctl_init_log_page_index()
4387 lun->log_pages.subpages_page[k*2+1] = page_index->subpage; in ctl_init_log_page_index()
4390 lun->log_pages.index[0].page_data = &lun->log_pages.pages_page[0]; in ctl_init_log_page_index()
4391 lun->log_pages.index[0].page_len = j; in ctl_init_log_page_index()
4392 lun->log_pages.index[1].page_data = &lun->log_pages.subpages_page[0]; in ctl_init_log_page_index()
4393 lun->log_pages.index[1].page_len = k * 2; in ctl_init_log_page_index()
4394 lun->log_pages.index[2].page_data = (uint8_t *)&lun->log_pages.temp_page; in ctl_init_log_page_index()
4395 lun->log_pages.index[2].page_len = sizeof(lun->log_pages.temp_page); in ctl_init_log_page_index()
4396 lun->log_pages.index[3].page_data = &lun->log_pages.lbp_page[0]; in ctl_init_log_page_index()
4397 lun->log_pages.index[3].page_len = 12*CTL_NUM_LBP_PARAMS; in ctl_init_log_page_index()
4398 lun->log_pages.index[4].page_data = (uint8_t *)&lun->log_pages.stat_page; in ctl_init_log_page_index()
4399 lun->log_pages.index[4].page_len = sizeof(lun->log_pages.stat_page); in ctl_init_log_page_index()
4400 lun->log_pages.index[5].page_data = (uint8_t *)&lun->log_pages.ie_page; in ctl_init_log_page_index()
4401 lun->log_pages.index[5].page_len = sizeof(lun->log_pages.ie_page); in ctl_init_log_page_index()
4447 struct ctl_lun *nlun, *lun; in ctl_add_lun() local
4467 lun = malloc(sizeof(*lun), M_CTL, M_WAITOK | M_ZERO); in ctl_add_lun()
4469 lun->pending_sense = malloc(sizeof(struct scsi_sense_data *) * in ctl_add_lun()
4471 lun->pending_ua = malloc(sizeof(ctl_ua_type *) * ctl_max_ports, in ctl_add_lun()
4473 lun->pr_keys = malloc(sizeof(uint64_t *) * ctl_max_ports, in ctl_add_lun()
4498 lun->lun_devid = malloc(sizeof(struct ctl_devid) + len, in ctl_add_lun()
4500 desc = (struct scsi_vpd_id_descriptor *)lun->lun_devid->data; in ctl_add_lun()
4554 lun->lun_devid->len = len; in ctl_add_lun()
4578 free(lun->lun_devid, M_CTL); in ctl_add_lun()
4579 free(lun, M_CTL); in ctl_add_lun()
4594 mtx_init(&lun->lun_lock, "CTL LUN", NULL, MTX_DEF); in ctl_add_lun()
4595 lun->lun = lun_number; in ctl_add_lun()
4596 lun->be_lun = be_lun; in ctl_add_lun()
4601 lun->flags |= CTL_LUN_DISABLED; in ctl_add_lun()
4602 lun->backend = be_lun->be; in ctl_add_lun()
4603 be_lun->ctl_lun = lun; in ctl_add_lun()
4606 lun->flags |= CTL_LUN_EJECTED; in ctl_add_lun()
4608 lun->flags |= CTL_LUN_NO_MEDIA; in ctl_add_lun()
4610 lun->flags |= CTL_LUN_STOPPED; in ctl_add_lun()
4613 lun->flags |= CTL_LUN_PRIMARY_SC; in ctl_add_lun()
4618 lun->flags |= CTL_LUN_REMOVABLE; in ctl_add_lun()
4620 lun->flags |= CTL_LUN_REMOVABLE; in ctl_add_lun()
4622 lun->ctl_softc = ctl_softc; in ctl_add_lun()
4624 lun->last_busy = getsbinuptime(); in ctl_add_lun()
4626 LIST_INIT(&lun->ooa_queue); in ctl_add_lun()
4627 STAILQ_INIT(&lun->error_list); in ctl_add_lun()
4628 lun->ie_reported = 1; in ctl_add_lun()
4629 callout_init_mtx(&lun->ie_callout, &lun->lun_lock, 0); in ctl_add_lun()
4630 ctl_tpc_lun_init(lun); in ctl_add_lun()
4631 if (lun->flags & CTL_LUN_REMOVABLE) { in ctl_add_lun()
4632 lun->prevent = malloc((CTL_MAX_INITIATORS + 31) / 32 * 4, in ctl_add_lun()
4639 ctl_init_page_index(lun); in ctl_add_lun()
4640 ctl_init_log_page_index(lun); in ctl_add_lun()
4643 lun->stats.item = lun_number; in ctl_add_lun()
4655 STAILQ_INSERT_TAIL(&ctl_softc->lun_list, lun, links); in ctl_add_lun()
4656 ctl_softc->ctl_luns[lun_number] = lun; in ctl_add_lun()
4663 if (ctl_enable_lun(lun) != 0) { in ctl_add_lun()
4666 STAILQ_REMOVE(&ctl_softc->lun_list, lun, ctl_lun, links); in ctl_add_lun()
4671 free(lun->lun_devid, M_CTL); in ctl_add_lun()
4672 free(lun, M_CTL); in ctl_add_lun()
4683 ctl_free_lun(struct ctl_lun *lun) in ctl_free_lun() argument
4685 struct ctl_softc *softc = lun->ctl_softc; in ctl_free_lun()
4689 KASSERT(LIST_EMPTY(&lun->ooa_queue), in ctl_free_lun()
4690 ("Freeing a LUN %p with outstanding I/O!\n", lun)); in ctl_free_lun()
4693 STAILQ_REMOVE(&softc->lun_list, lun, ctl_lun, links); in ctl_free_lun()
4694 ctl_clear_mask(softc->ctl_lun_mask, lun->lun); in ctl_free_lun()
4695 softc->ctl_luns[lun->lun] = NULL; in ctl_free_lun()
4707 lun->be_lun->lun_shutdown(lun->be_lun); in ctl_free_lun()
4709 lun->ie_reportcnt = UINT32_MAX; in ctl_free_lun()
4710 callout_drain(&lun->ie_callout); in ctl_free_lun()
4711 ctl_tpc_lun_shutdown(lun); in ctl_free_lun()
4712 mtx_destroy(&lun->lun_lock); in ctl_free_lun()
4713 free(lun->lun_devid, M_CTL); in ctl_free_lun()
4715 free(lun->pending_ua[i], M_CTL); in ctl_free_lun()
4716 free(lun->pending_ua, M_DEVBUF); in ctl_free_lun()
4718 free(lun->pr_keys[i], M_CTL); in ctl_free_lun()
4719 free(lun->pr_keys, M_DEVBUF); in ctl_free_lun()
4720 free(lun->write_buffer, M_CTL); in ctl_free_lun()
4721 free(lun->prevent, M_CTL); in ctl_free_lun()
4722 free(lun, M_CTL); in ctl_free_lun()
4728 ctl_enable_lun(struct ctl_lun *lun) in ctl_enable_lun() argument
4734 softc = lun->ctl_softc; in ctl_enable_lun()
4737 mtx_lock(&lun->lun_lock); in ctl_enable_lun()
4738 KASSERT((lun->flags & CTL_LUN_DISABLED) != 0, in ctl_enable_lun()
4740 lun->flags &= ~CTL_LUN_DISABLED; in ctl_enable_lun()
4741 mtx_unlock(&lun->lun_lock); in ctl_enable_lun()
4754 retval = port->lun_enable(port->targ_lun_arg, lun->lun); in ctl_enable_lun()
4760 retval, (intmax_t)lun->lun); in ctl_enable_lun()
4765 ctl_isc_announce_lun(lun); in ctl_enable_lun()
4771 ctl_disable_lun(struct ctl_lun *lun) in ctl_disable_lun() argument
4777 softc = lun->ctl_softc; in ctl_disable_lun()
4780 mtx_lock(&lun->lun_lock); in ctl_disable_lun()
4781 KASSERT((lun->flags & CTL_LUN_DISABLED) == 0, in ctl_disable_lun()
4783 lun->flags |= CTL_LUN_DISABLED; in ctl_disable_lun()
4784 mtx_unlock(&lun->lun_lock); in ctl_disable_lun()
4799 retval = port->lun_disable(port->targ_lun_arg, lun->lun); in ctl_disable_lun()
4805 retval, (intmax_t)lun->lun); in ctl_disable_lun()
4810 ctl_isc_announce_lun(lun); in ctl_disable_lun()
4818 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_start_lun() local
4820 mtx_lock(&lun->lun_lock); in ctl_start_lun()
4821 lun->flags &= ~CTL_LUN_STOPPED; in ctl_start_lun()
4822 mtx_unlock(&lun->lun_lock); in ctl_start_lun()
4829 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_stop_lun() local
4831 mtx_lock(&lun->lun_lock); in ctl_stop_lun()
4832 lun->flags |= CTL_LUN_STOPPED; in ctl_stop_lun()
4833 mtx_unlock(&lun->lun_lock); in ctl_stop_lun()
4840 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_no_media() local
4842 mtx_lock(&lun->lun_lock); in ctl_lun_no_media()
4843 lun->flags |= CTL_LUN_NO_MEDIA; in ctl_lun_no_media()
4844 mtx_unlock(&lun->lun_lock); in ctl_lun_no_media()
4851 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_has_media() local
4854 mtx_lock(&lun->lun_lock); in ctl_lun_has_media()
4855 lun->flags &= ~(CTL_LUN_NO_MEDIA | CTL_LUN_EJECTED); in ctl_lun_has_media()
4856 if (lun->flags & CTL_LUN_REMOVABLE) in ctl_lun_has_media()
4857 ctl_est_ua_all(lun, -1, CTL_UA_MEDIUM_CHANGE); in ctl_lun_has_media()
4858 mtx_unlock(&lun->lun_lock); in ctl_lun_has_media()
4859 if ((lun->flags & CTL_LUN_REMOVABLE) && in ctl_lun_has_media()
4860 lun->ctl_softc->ha_mode == CTL_HA_MODE_XFER) { in ctl_lun_has_media()
4865 msg.hdr.nexus.targ_lun = lun->lun; in ctl_lun_has_media()
4866 msg.hdr.nexus.targ_mapped_lun = lun->lun; in ctl_lun_has_media()
4879 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_ejected() local
4881 mtx_lock(&lun->lun_lock); in ctl_lun_ejected()
4882 lun->flags |= CTL_LUN_EJECTED; in ctl_lun_ejected()
4883 mtx_unlock(&lun->lun_lock); in ctl_lun_ejected()
4890 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_primary() local
4892 mtx_lock(&lun->lun_lock); in ctl_lun_primary()
4893 lun->flags |= CTL_LUN_PRIMARY_SC; in ctl_lun_primary()
4894 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE); in ctl_lun_primary()
4895 mtx_unlock(&lun->lun_lock); in ctl_lun_primary()
4896 ctl_isc_announce_lun(lun); in ctl_lun_primary()
4903 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_secondary() local
4905 mtx_lock(&lun->lun_lock); in ctl_lun_secondary()
4906 lun->flags &= ~CTL_LUN_PRIMARY_SC; in ctl_lun_secondary()
4907 ctl_est_ua_all(lun, -1, CTL_UA_ASYM_ACC_CHANGE); in ctl_lun_secondary()
4908 mtx_unlock(&lun->lun_lock); in ctl_lun_secondary()
4909 ctl_isc_announce_lun(lun); in ctl_lun_secondary()
4922 struct ctl_lun *lun; in ctl_remove_lun() local
4924 lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_remove_lun()
4926 ctl_disable_lun(lun); in ctl_remove_lun()
4928 mtx_lock(&lun->lun_lock); in ctl_remove_lun()
4929 lun->flags |= CTL_LUN_INVALID; in ctl_remove_lun()
4936 if (LIST_EMPTY(&lun->ooa_queue)) { in ctl_remove_lun()
4937 mtx_unlock(&lun->lun_lock); in ctl_remove_lun()
4938 ctl_free_lun(lun); in ctl_remove_lun()
4940 mtx_unlock(&lun->lun_lock); in ctl_remove_lun()
4948 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_capacity_changed() local
4951 mtx_lock(&lun->lun_lock); in ctl_lun_capacity_changed()
4952 ctl_est_ua_all(lun, -1, CTL_UA_CAPACITY_CHANGE); in ctl_lun_capacity_changed()
4953 mtx_unlock(&lun->lun_lock); in ctl_lun_capacity_changed()
4954 if (lun->ctl_softc->ha_mode == CTL_HA_MODE_XFER) { in ctl_lun_capacity_changed()
4960 msg.hdr.nexus.targ_lun = lun->lun; in ctl_lun_capacity_changed()
4961 msg.hdr.nexus.targ_mapped_lun = lun->lun; in ctl_lun_capacity_changed()
4974 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_nsdata_ids() local
4977 if (lun->lun_devid == NULL) in ctl_lun_nsdata_ids()
4981 lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_naa); in ctl_lun_nsdata_ids()
4994 lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_eui64); in ctl_lun_nsdata_ids()
5006 struct ctl_lun *lun = (struct ctl_lun *)be_lun->ctl_lun; in ctl_lun_nvme_ids() local
5012 if (lun->lun_devid == NULL) in ctl_lun_nvme_ids()
5016 lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_naa); in ctl_lun_nvme_ids()
5018 lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_eui64); in ctl_lun_nvme_ids()
5020 lun->lun_devid->data, lun->lun_devid->len, scsi_devid_is_lun_uuid); in ctl_lun_nvme_ids()
5217 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_scsi_release() local
5232 mtx_lock(&lun->lun_lock); in ctl_scsi_release()
5241 if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == residx)) in ctl_scsi_release()
5242 lun->flags &= ~CTL_LUN_RESERVED; in ctl_scsi_release()
5244 mtx_unlock(&lun->lun_lock); in ctl_scsi_release()
5254 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_scsi_reserve() local
5269 mtx_lock(&lun->lun_lock); in ctl_scsi_reserve()
5270 if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx != residx)) { in ctl_scsi_reserve()
5276 if (lun->flags & CTL_LUN_PR_RESERVED) { in ctl_scsi_reserve()
5281 lun->flags |= CTL_LUN_RESERVED; in ctl_scsi_reserve()
5282 lun->res_idx = residx; in ctl_scsi_reserve()
5286 mtx_unlock(&lun->lun_lock); in ctl_scsi_reserve()
5294 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_start_stop() local
5303 if ((lun->flags & CTL_LUN_PR_RESERVED) && in ctl_start_stop()
5308 if (ctl_get_prkey(lun, residx) == 0 || in ctl_start_stop()
5309 (lun->pr_res_idx != residx && lun->pr_res_type < 4)) { in ctl_start_stop()
5317 (lun->flags & CTL_LUN_REMOVABLE) == 0) { in ctl_start_stop()
5329 lun->prevent_count > 0) { in ctl_start_stop()
5332 /*sense_key*/(lun->flags & CTL_LUN_NO_MEDIA) ? in ctl_start_stop()
5340 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_start_stop()
5347 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_prevent_allow() local
5356 if ((lun->flags & CTL_LUN_REMOVABLE) == 0 || lun->prevent == NULL) { in ctl_prevent_allow()
5363 mtx_lock(&lun->lun_lock); in ctl_prevent_allow()
5365 ctl_is_set(lun->prevent, initidx) == 0) { in ctl_prevent_allow()
5366 ctl_set_mask(lun->prevent, initidx); in ctl_prevent_allow()
5367 lun->prevent_count++; in ctl_prevent_allow()
5369 ctl_is_set(lun->prevent, initidx)) { in ctl_prevent_allow()
5370 ctl_clear_mask(lun->prevent, initidx); in ctl_prevent_allow()
5371 lun->prevent_count--; in ctl_prevent_allow()
5373 mtx_unlock(&lun->lun_lock); in ctl_prevent_allow()
5374 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_prevent_allow()
5387 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_sync_cache() local
5430 if ((starting_lba + block_count) > (lun->be_lun->maxlba + 1)) { in ctl_sync_cache()
5432 MAX(starting_lba, lun->be_lun->maxlba + 1)); in ctl_sync_cache()
5441 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_sync_cache()
5532 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_read_buffer() local
5587 if (lun->write_buffer == NULL) { in ctl_read_buffer()
5588 lun->write_buffer = malloc(CTL_WRITE_BUFFER_SIZE, in ctl_read_buffer()
5591 ctsio->kern_data_ptr = lun->write_buffer + buffer_offset; in ctl_read_buffer()
5606 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_write_buffer() local
5628 if (lun->write_buffer == NULL) { in ctl_write_buffer()
5629 lun->write_buffer = malloc(CTL_WRITE_BUFFER_SIZE, in ctl_write_buffer()
5641 ctsio->kern_data_ptr = lun->write_buffer + buffer_offset; in ctl_write_buffer()
5660 struct ctl_lun *lun = CTL_LUN(io); in ctl_write_same_cont() local
5672 if ((lun->be_lun->maxlba + 1) - lbalen->lba <= UINT32_MAX) { in ctl_write_same_cont()
5674 lbalen->len = (lun->be_lun->maxlba + 1) - lbalen->lba; in ctl_write_same_cont()
5678 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_write_same_cont()
5685 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_write_same() local
5742 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_write_same()
5745 MAX(lba, lun->be_lun->maxlba + 1)); in ctl_write_same()
5753 val = dnvlist_get_string(lun->be_lun->options, in ctl_write_same()
5757 if ((lun->be_lun->maxlba + 1) - lba > ival) { in ctl_write_same()
5765 if ((lun->be_lun->maxlba + 1) - lba > UINT32_MAX) { in ctl_write_same()
5770 num_blocks = (lun->be_lun->maxlba + 1) - lba; in ctl_write_same()
5773 len = lun->be_lun->blocksize; in ctl_write_same()
5797 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_write_same()
5805 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_unmap() local
5860 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_unmap()
5863 MAX(lba, lun->be_lun->maxlba + 1)); in ctl_unmap()
5881 mtx_lock(&lun->lun_lock); in ctl_unmap()
5887 ctl_try_unblock_others(lun, (union ctl_io *)ctsio, FALSE); in ctl_unmap()
5888 mtx_unlock(&lun->lun_lock); in ctl_unmap()
5890 retval = lun->backend->config_write((union ctl_io *)ctsio); in ctl_unmap()
5906 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_default_page_handler() local
5917 mtx_lock(&lun->lun_lock); in ctl_default_page_handler()
5923 ctl_est_ua_all(lun, initidx, CTL_UA_MODE_CHANGE); in ctl_default_page_handler()
5924 mtx_unlock(&lun->lun_lock); in ctl_default_page_handler()
5926 ctl_isc_announce_mode(lun, in ctl_default_page_handler()
5936 struct ctl_lun *lun = arg; in ctl_ie_timer() local
5939 if (lun->ie_asc == 0) in ctl_ie_timer()
5942 if (lun->MODE_IE.mrie == SIEP_MRIE_UA) in ctl_ie_timer()
5943 ctl_est_ua_all(lun, -1, CTL_UA_IE); in ctl_ie_timer()
5945 lun->ie_reported = 0; in ctl_ie_timer()
5947 if (lun->ie_reportcnt < scsi_4btoul(lun->MODE_IE.report_count)) { in ctl_ie_timer()
5948 lun->ie_reportcnt++; in ctl_ie_timer()
5949 t = scsi_4btoul(lun->MODE_IE.interval_timer); in ctl_ie_timer()
5952 callout_schedule_sbt(&lun->ie_callout, SBT_1S / 10 * t, in ctl_ie_timer()
5961 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_ie_page_handler() local
5968 mtx_lock(&lun->lun_lock); in ctl_ie_page_handler()
5970 lun->ie_asc = 0x5d; in ctl_ie_page_handler()
5971 lun->ie_ascq = 0xff; in ctl_ie_page_handler()
5973 ctl_est_ua_all(lun, -1, CTL_UA_IE); in ctl_ie_page_handler()
5974 lun->ie_reported = 1; in ctl_ie_page_handler()
5976 ctl_clr_ua_all(lun, -1, CTL_UA_IE); in ctl_ie_page_handler()
5977 lun->ie_reported = -1; in ctl_ie_page_handler()
5979 lun->ie_reportcnt = 1; in ctl_ie_page_handler()
5980 if (lun->ie_reportcnt < scsi_4btoul(pg->report_count)) { in ctl_ie_page_handler()
5981 lun->ie_reportcnt++; in ctl_ie_page_handler()
5985 callout_reset_sbt(&lun->ie_callout, SBT_1S / 10 * t, in ctl_ie_page_handler()
5986 SBT_1S / 10, ctl_ie_timer, lun, 0); in ctl_ie_page_handler()
5989 lun->ie_asc = 0; in ctl_ie_page_handler()
5990 lun->ie_ascq = 0; in ctl_ie_page_handler()
5991 lun->ie_reported = 1; in ctl_ie_page_handler()
5992 ctl_clr_ua_all(lun, -1, CTL_UA_IE); in ctl_ie_page_handler()
5993 lun->ie_reportcnt = UINT32_MAX; in ctl_ie_page_handler()
5994 callout_stop(&lun->ie_callout); in ctl_ie_page_handler()
5996 mtx_unlock(&lun->lun_lock); in ctl_ie_page_handler()
6003 struct ctl_lun *lun = CTL_LUN(io); in ctl_do_mode_select() local
6051 page_index = &lun->mode_pages.index[i]; in ctl_do_mode_select()
6052 if (lun->be_lun->lun_type == T_DIRECT && in ctl_do_mode_select()
6055 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_do_mode_select()
6058 if (lun->be_lun->lun_type == T_CDROM && in ctl_do_mode_select()
6226 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_mode_select() local
6269 ctl_init_page_index(lun); in ctl_mode_select()
6270 mtx_lock(&lun->lun_lock); in ctl_mode_select()
6271 ctl_est_ua_all(lun, initidx, CTL_UA_MODE_CHANGE); in ctl_mode_select()
6272 mtx_unlock(&lun->lun_lock); in ctl_mode_select()
6274 ctl_isc_announce_mode(lun, -1, in ctl_mode_select()
6275 lun->mode_pages.index[i].page_code & SMPH_PC_MASK, in ctl_mode_select()
6276 lun->mode_pages.index[i].subpage); in ctl_mode_select()
6370 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_mode_sense() local
6407 } else if (lun->be_lun->lun_type == T_DIRECT) { in ctl_mode_sense()
6458 page_index = &lun->mode_pages.index[i]; in ctl_mode_sense()
6461 if (lun->be_lun->lun_type == T_DIRECT && in ctl_mode_sense()
6464 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_mode_sense()
6467 if (lun->be_lun->lun_type == T_CDROM && in ctl_mode_sense()
6489 page_index = &lun->mode_pages.index[i]; in ctl_mode_sense()
6492 if (lun->be_lun->lun_type == T_DIRECT && in ctl_mode_sense()
6495 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_mode_sense()
6498 if (lun->be_lun->lun_type == T_CDROM && in ctl_mode_sense()
6543 if (lun->be_lun->lun_type == T_DIRECT) { in ctl_mode_sense()
6545 if ((lun->be_lun->flags & CTL_LUN_FLAG_READONLY) || in ctl_mode_sense()
6546 (lun->MODE_CTRL.eca_and_aen & SCP_SWP) != 0) in ctl_mode_sense()
6561 if (lun->be_lun->lun_type == T_DIRECT) { in ctl_mode_sense()
6563 if ((lun->be_lun->flags & CTL_LUN_FLAG_READONLY) || in ctl_mode_sense()
6564 (lun->MODE_CTRL.eca_and_aen & SCP_SWP) != 0) in ctl_mode_sense()
6582 if (lun->be_lun->lun_type == T_DIRECT) { in ctl_mode_sense()
6585 if (lun->be_lun->maxlba != 0) in ctl_mode_sense()
6586 scsi_u64to8b(lun->be_lun->maxlba + 1, in ctl_mode_sense()
6588 scsi_ulto4b(lun->be_lun->blocksize, in ctl_mode_sense()
6592 if (lun->be_lun->maxlba != 0) in ctl_mode_sense()
6593 scsi_ulto4b(MIN(lun->be_lun->maxlba+1, in ctl_mode_sense()
6595 scsi_ulto3b(lun->be_lun->blocksize, in ctl_mode_sense()
6612 page_index = &lun->mode_pages.index[i]; in ctl_mode_sense()
6613 if (lun->be_lun->lun_type == T_DIRECT && in ctl_mode_sense()
6616 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_mode_sense()
6619 if (lun->be_lun->lun_type == T_CDROM && in ctl_mode_sense()
6656 page_index = &lun->mode_pages.index[i]; in ctl_mode_sense()
6668 if (lun->be_lun->lun_type == T_DIRECT && in ctl_mode_sense()
6671 if (lun->be_lun->lun_type == T_PROCESSOR && in ctl_mode_sense()
6674 if (lun->be_lun->lun_type == T_CDROM && in ctl_mode_sense()
6707 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_temp_log_sense_handler() local
6717 if ((value = dnvlist_get_string(lun->be_lun->options, "temperature", in ctl_temp_log_sense_handler()
6728 if ((value = dnvlist_get_string(lun->be_lun->options, "reftemperature", in ctl_temp_log_sense_handler()
6741 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_lbp_log_sense_handler() local
6748 if (lun->backend->lun_attr != NULL && in ctl_lbp_log_sense_handler()
6749 (val = lun->backend->lun_attr(lun->be_lun, "blocksavail")) in ctl_lbp_log_sense_handler()
6761 if (lun->backend->lun_attr != NULL && in ctl_lbp_log_sense_handler()
6762 (val = lun->backend->lun_attr(lun->be_lun, "blocksused")) in ctl_lbp_log_sense_handler()
6774 if (lun->backend->lun_attr != NULL && in ctl_lbp_log_sense_handler()
6775 (val = lun->backend->lun_attr(lun->be_lun, "poolblocksavail")) in ctl_lbp_log_sense_handler()
6787 if (lun->backend->lun_attr != NULL && in ctl_lbp_log_sense_handler()
6788 (val = lun->backend->lun_attr(lun->be_lun, "poolblocksused")) in ctl_lbp_log_sense_handler()
6809 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_sap_log_sense_handler() local
6819 scsi_u64to8b(lun->stats.operations[CTL_STATS_READ], in ctl_sap_log_sense_handler()
6821 scsi_u64to8b(lun->stats.operations[CTL_STATS_WRITE], in ctl_sap_log_sense_handler()
6823 if (lun->be_lun->blocksize > 0) { in ctl_sap_log_sense_handler()
6824 scsi_u64to8b(lun->stats.bytes[CTL_STATS_WRITE] / in ctl_sap_log_sense_handler()
6825 lun->be_lun->blocksize, data->sap.recvieved_lba); in ctl_sap_log_sense_handler()
6826 scsi_u64to8b(lun->stats.bytes[CTL_STATS_READ] / in ctl_sap_log_sense_handler()
6827 lun->be_lun->blocksize, data->sap.transmitted_lba); in ctl_sap_log_sense_handler()
6829 t = &lun->stats.time[CTL_STATS_READ]; in ctl_sap_log_sense_handler()
6832 t = &lun->stats.time[CTL_STATS_WRITE]; in ctl_sap_log_sense_handler()
6842 scsi_u64to8b(lun->idle_time / SBT_1MS, data->it.idle_int); in ctl_sap_log_sense_handler()
6858 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_ie_log_sense_handler() local
6868 data->ie_asc = lun->ie_asc; in ctl_ie_log_sense_handler()
6869 data->ie_ascq = lun->ie_ascq; in ctl_ie_log_sense_handler()
6870 if ((value = dnvlist_get_string(lun->be_lun->options, "temperature", in ctl_ie_log_sense_handler()
6881 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_log_sense() local
6898 page_index = &lun->log_pages.index[i]; in ctl_log_sense()
6958 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_read_capacity() local
6992 if (lun->be_lun->maxlba > 0xfffffffe) in ctl_read_capacity()
6995 scsi_ulto4b(lun->be_lun->maxlba, data->addr); in ctl_read_capacity()
7000 scsi_ulto4b(lun->be_lun->blocksize, data->length); in ctl_read_capacity()
7012 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_read_capacity_16() local
7044 scsi_u64to8b(lun->be_lun->maxlba, data->addr); in ctl_read_capacity_16()
7046 scsi_ulto4b(lun->be_lun->blocksize, data->length); in ctl_read_capacity_16()
7047 data->prot_lbppbe = lun->be_lun->pblockexp & SRC16_LBPPBE; in ctl_read_capacity_16()
7048 scsi_ulto2b(lun->be_lun->pblockoff & SRC16_LALBA_A, data->lalba_lbp); in ctl_read_capacity_16()
7049 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) in ctl_read_capacity_16()
7062 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_get_lba_status() local
7076 if (lba > lun->be_lun->maxlba) { in ctl_get_lba_status()
7093 scsi_ulto4b(MIN(UINT32_MAX, lun->be_lun->maxlba + 1 - lba), in ctl_get_lba_status()
7105 retval = lun->backend->config_read((union ctl_io *)ctsio); in ctl_get_lba_status()
7167 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_report_ident_info() local
7182 oii = dnvlist_get_string(lun->be_lun->options, in ctl_report_ident_info()
7188 otii = dnvlist_get_string(lun->be_lun->options, in ctl_report_ident_info()
7250 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_report_tagret_port_groups() local
7289 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_report_tagret_port_groups()
7330 if (lun->flags & (CTL_LUN_PRIMARY_SC | CTL_LUN_PEER_SC_PRIMARY)) { in ctl_report_tagret_port_groups()
7340 if (lun->flags & CTL_LUN_PRIMARY_SC) { in ctl_report_tagret_port_groups()
7371 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_report_tagret_port_groups()
7396 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_report_tagret_port_groups()
7418 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_report_supported_opcodes() local
7445 lun->be_lun->lun_type, sentry)) in ctl_report_supported_opcodes()
7449 if (ctl_cmd_applicable(lun->be_lun->lun_type, in ctl_report_supported_opcodes()
7513 lun->be_lun->lun_type, sentry)) in ctl_report_supported_opcodes()
7523 if (!ctl_cmd_applicable(lun->be_lun->lun_type, in ctl_report_supported_opcodes()
7549 if (ctl_cmd_applicable(lun->be_lun->lun_type, entry)) { in ctl_report_supported_opcodes()
7662 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_persistent_reserve_in() local
7675 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_in()
7679 lun->pr_key_count * in ctl_persistent_reserve_in()
7683 if (lun->flags & CTL_LUN_PR_RESERVED) in ctl_persistent_reserve_in()
7694 lun->pr_key_count; in ctl_persistent_reserve_in()
7699 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_in()
7707 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_in()
7723 (lun->pr_key_count * in ctl_persistent_reserve_in()
7725 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_in()
7732 scsi_ulto4b(lun->pr_generation, res_keys->header.generation); in ctl_persistent_reserve_in()
7735 lun->pr_key_count, res_keys->header.length); in ctl_persistent_reserve_in()
7738 if ((key = ctl_get_prkey(lun, i)) == 0) in ctl_persistent_reserve_in()
7748 if (key_count >= lun->pr_key_count) { in ctl_persistent_reserve_in()
7763 scsi_ulto4b(lun->pr_generation, res->header.generation); in ctl_persistent_reserve_in()
7765 if (lun->flags & CTL_LUN_PR_RESERVED) in ctl_persistent_reserve_in()
7785 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_in()
7802 if (lun->pr_res_idx != CTL_PR_ALL_REGISTRANTS) { in ctl_persistent_reserve_in()
7803 scsi_u64to8b(ctl_get_prkey(lun, lun->pr_res_idx), in ctl_persistent_reserve_in()
7806 res->data.scopetype = lun->pr_res_type; in ctl_persistent_reserve_in()
7844 lun->pr_key_count)){ in ctl_persistent_reserve_in()
7845 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_in()
7852 scsi_ulto4b(lun->pr_generation, res_status->header.generation); in ctl_persistent_reserve_in()
7856 if ((key = ctl_get_prkey(lun, i)) == 0) in ctl_persistent_reserve_in()
7860 if ((lun->flags & CTL_LUN_PR_RESERVED) && in ctl_persistent_reserve_in()
7861 (lun->pr_res_idx == i || in ctl_persistent_reserve_in()
7862 lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS)) { in ctl_persistent_reserve_in()
7864 res_desc->scopetype = lun->pr_res_type; in ctl_persistent_reserve_in()
7885 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_in()
7899 ctl_pro_preempt(struct ctl_softc *softc, struct ctl_lun *lun, uint64_t res_key, in ctl_pro_preempt() argument
7907 mtx_lock(&lun->lun_lock); in ctl_pro_preempt()
7909 if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS) { in ctl_pro_preempt()
7913 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
7925 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
7941 if (i == residx || ctl_get_prkey(lun, i) == 0) in ctl_pro_preempt()
7944 ctl_clr_prkey(lun, i); in ctl_pro_preempt()
7945 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt()
7947 lun->pr_key_count = 1; in ctl_pro_preempt()
7948 lun->pr_res_type = type; in ctl_pro_preempt()
7949 if (lun->pr_res_type != SPR_TYPE_WR_EX_AR && in ctl_pro_preempt()
7950 lun->pr_res_type != SPR_TYPE_EX_AC_AR) in ctl_pro_preempt()
7951 lun->pr_res_idx = residx; in ctl_pro_preempt()
7952 lun->pr_generation++; in ctl_pro_preempt()
7953 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
7959 persis_io.pr.pr_info.residx = lun->pr_res_idx; in ctl_pro_preempt()
7968 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
7979 } else if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS in ctl_pro_preempt()
7980 || !(lun->flags & CTL_LUN_PR_RESERVED)) { in ctl_pro_preempt()
7994 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8007 if (ctl_get_prkey(lun, i) != sa_res_key) in ctl_pro_preempt()
8011 ctl_clr_prkey(lun, i); in ctl_pro_preempt()
8012 lun->pr_key_count--; in ctl_pro_preempt()
8013 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt()
8016 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8022 lun->pr_generation++; in ctl_pro_preempt()
8023 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8029 persis_io.pr.pr_info.residx = lun->pr_res_idx; in ctl_pro_preempt()
8039 if (sa_res_key == ctl_get_prkey(lun, lun->pr_res_idx)) { in ctl_pro_preempt()
8043 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8055 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8081 if (i == residx || ctl_get_prkey(lun, i) == 0) in ctl_pro_preempt()
8084 if (sa_res_key == ctl_get_prkey(lun, i)) { in ctl_pro_preempt()
8085 ctl_clr_prkey(lun, i); in ctl_pro_preempt()
8086 lun->pr_key_count--; in ctl_pro_preempt()
8087 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt()
8088 } else if (type != lun->pr_res_type && in ctl_pro_preempt()
8089 (lun->pr_res_type == SPR_TYPE_WR_EX_RO || in ctl_pro_preempt()
8090 lun->pr_res_type == SPR_TYPE_EX_AC_RO)) { in ctl_pro_preempt()
8091 ctl_est_ua(lun, i, CTL_UA_RES_RELEASE); in ctl_pro_preempt()
8094 lun->pr_res_type = type; in ctl_pro_preempt()
8095 if (lun->pr_res_type != SPR_TYPE_WR_EX_AR && in ctl_pro_preempt()
8096 lun->pr_res_type != SPR_TYPE_EX_AC_AR) in ctl_pro_preempt()
8097 lun->pr_res_idx = residx; in ctl_pro_preempt()
8099 lun->pr_res_idx = CTL_PR_ALL_REGISTRANTS; in ctl_pro_preempt()
8100 lun->pr_generation++; in ctl_pro_preempt()
8101 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8106 persis_io.pr.pr_info.residx = lun->pr_res_idx; in ctl_pro_preempt()
8121 if (sa_res_key != ctl_get_prkey(lun, i)) in ctl_pro_preempt()
8125 ctl_clr_prkey(lun, i); in ctl_pro_preempt()
8126 lun->pr_key_count--; in ctl_pro_preempt()
8127 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt()
8131 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8137 lun->pr_generation++; in ctl_pro_preempt()
8138 mtx_unlock(&lun->lun_lock); in ctl_pro_preempt()
8143 persis_io.pr.pr_info.residx = lun->pr_res_idx; in ctl_pro_preempt()
8156 ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg) in ctl_pro_preempt_other() argument
8163 if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS in ctl_pro_preempt_other()
8164 || lun->pr_res_idx == CTL_PR_NO_RESERVATION in ctl_pro_preempt_other()
8165 || sa_res_key != ctl_get_prkey(lun, lun->pr_res_idx)) { in ctl_pro_preempt_other()
8173 ctl_get_prkey(lun, i) == 0) in ctl_pro_preempt_other()
8176 ctl_clr_prkey(lun, i); in ctl_pro_preempt_other()
8177 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt_other()
8180 lun->pr_key_count = 1; in ctl_pro_preempt_other()
8181 lun->pr_res_type = msg->pr.pr_info.res_type; in ctl_pro_preempt_other()
8182 if (lun->pr_res_type != SPR_TYPE_WR_EX_AR && in ctl_pro_preempt_other()
8183 lun->pr_res_type != SPR_TYPE_EX_AC_AR) in ctl_pro_preempt_other()
8184 lun->pr_res_idx = msg->pr.pr_info.residx; in ctl_pro_preempt_other()
8187 if (sa_res_key == ctl_get_prkey(lun, i)) in ctl_pro_preempt_other()
8190 ctl_clr_prkey(lun, i); in ctl_pro_preempt_other()
8191 lun->pr_key_count--; in ctl_pro_preempt_other()
8192 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt_other()
8198 ctl_get_prkey(lun, i) == 0) in ctl_pro_preempt_other()
8201 if (sa_res_key == ctl_get_prkey(lun, i)) { in ctl_pro_preempt_other()
8202 ctl_clr_prkey(lun, i); in ctl_pro_preempt_other()
8203 lun->pr_key_count--; in ctl_pro_preempt_other()
8204 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_pro_preempt_other()
8205 } else if (msg->pr.pr_info.res_type != lun->pr_res_type in ctl_pro_preempt_other()
8206 && (lun->pr_res_type == SPR_TYPE_WR_EX_RO || in ctl_pro_preempt_other()
8207 lun->pr_res_type == SPR_TYPE_EX_AC_RO)) { in ctl_pro_preempt_other()
8208 ctl_est_ua(lun, i, CTL_UA_RES_RELEASE); in ctl_pro_preempt_other()
8211 lun->pr_res_type = msg->pr.pr_info.res_type; in ctl_pro_preempt_other()
8212 if (lun->pr_res_type != SPR_TYPE_WR_EX_AR && in ctl_pro_preempt_other()
8213 lun->pr_res_type != SPR_TYPE_EX_AC_AR) in ctl_pro_preempt_other()
8214 lun->pr_res_idx = msg->pr.pr_info.residx; in ctl_pro_preempt_other()
8216 lun->pr_res_idx = CTL_PR_ALL_REGISTRANTS; in ctl_pro_preempt_other()
8218 lun->pr_generation++; in ctl_pro_preempt_other()
8226 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_persistent_reserve_out() local
8312 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_out()
8313 if ((key = ctl_get_prkey(lun, residx)) != 0) { in ctl_persistent_reserve_out()
8320 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8330 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8340 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8346 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8380 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_out()
8390 && ctl_get_prkey(lun, residx) == 0)) { in ctl_persistent_reserve_out()
8391 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8395 ctl_clr_prkey(lun, residx); in ctl_persistent_reserve_out()
8396 lun->pr_key_count--; in ctl_persistent_reserve_out()
8398 if (residx == lun->pr_res_idx) { in ctl_persistent_reserve_out()
8399 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_persistent_reserve_out()
8400 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_persistent_reserve_out()
8402 if ((lun->pr_res_type == SPR_TYPE_WR_EX_RO || in ctl_persistent_reserve_out()
8403 lun->pr_res_type == SPR_TYPE_EX_AC_RO) && in ctl_persistent_reserve_out()
8404 lun->pr_key_count) { in ctl_persistent_reserve_out()
8414 if (ctl_get_prkey(lun, i) == 0) in ctl_persistent_reserve_out()
8416 ctl_est_ua(lun, i, in ctl_persistent_reserve_out()
8420 lun->pr_res_type = 0; in ctl_persistent_reserve_out()
8421 } else if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS) { in ctl_persistent_reserve_out()
8422 if (lun->pr_key_count==0) { in ctl_persistent_reserve_out()
8423 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_persistent_reserve_out()
8424 lun->pr_res_type = 0; in ctl_persistent_reserve_out()
8425 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_persistent_reserve_out()
8428 lun->pr_generation++; in ctl_persistent_reserve_out()
8429 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8442 ctl_alloc_prkey(lun, residx); in ctl_persistent_reserve_out()
8443 if (ctl_get_prkey(lun, residx) == 0) in ctl_persistent_reserve_out()
8444 lun->pr_key_count++; in ctl_persistent_reserve_out()
8445 ctl_set_prkey(lun, residx, sa_res_key); in ctl_persistent_reserve_out()
8446 lun->pr_generation++; in ctl_persistent_reserve_out()
8447 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8463 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_out()
8464 if (lun->flags & CTL_LUN_PR_RESERVED) { in ctl_persistent_reserve_out()
8470 if ((lun->pr_res_idx != residx in ctl_persistent_reserve_out()
8471 && lun->pr_res_idx != CTL_PR_ALL_REGISTRANTS) in ctl_persistent_reserve_out()
8472 || lun->pr_res_type != type) { in ctl_persistent_reserve_out()
8473 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8479 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8487 lun->pr_res_idx = residx; /* Res holder */ in ctl_persistent_reserve_out()
8489 lun->pr_res_idx = CTL_PR_ALL_REGISTRANTS; in ctl_persistent_reserve_out()
8491 lun->flags |= CTL_LUN_PR_RESERVED; in ctl_persistent_reserve_out()
8492 lun->pr_res_type = type; in ctl_persistent_reserve_out()
8494 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8500 persis_io.pr.pr_info.residx = lun->pr_res_idx; in ctl_persistent_reserve_out()
8508 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_out()
8509 if ((lun->flags & CTL_LUN_PR_RESERVED) == 0) { in ctl_persistent_reserve_out()
8511 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8517 if (lun->pr_res_idx != residx in ctl_persistent_reserve_out()
8518 && lun->pr_res_idx != CTL_PR_ALL_REGISTRANTS) { in ctl_persistent_reserve_out()
8523 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8527 if (lun->pr_res_type != type) { in ctl_persistent_reserve_out()
8528 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8536 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_persistent_reserve_out()
8537 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_persistent_reserve_out()
8538 lun->pr_res_type = 0; in ctl_persistent_reserve_out()
8545 (lun->MODE_CTRL.queue_flags & SCP_NUAR) == 0) { in ctl_persistent_reserve_out()
8547 if (i == residx || ctl_get_prkey(lun, i) == 0) in ctl_persistent_reserve_out()
8549 ctl_est_ua(lun, i, CTL_UA_RES_RELEASE); in ctl_persistent_reserve_out()
8552 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8565 mtx_lock(&lun->lun_lock); in ctl_persistent_reserve_out()
8566 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_persistent_reserve_out()
8567 lun->pr_res_type = 0; in ctl_persistent_reserve_out()
8568 lun->pr_key_count = 0; in ctl_persistent_reserve_out()
8569 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_persistent_reserve_out()
8571 ctl_clr_prkey(lun, residx); in ctl_persistent_reserve_out()
8573 if (ctl_get_prkey(lun, i) != 0) { in ctl_persistent_reserve_out()
8574 ctl_clr_prkey(lun, i); in ctl_persistent_reserve_out()
8575 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_persistent_reserve_out()
8577 lun->pr_generation++; in ctl_persistent_reserve_out()
8578 mtx_unlock(&lun->lun_lock); in ctl_persistent_reserve_out()
8591 nretval = ctl_pro_preempt(softc, lun, res_key, sa_res_key, type, in ctl_persistent_reserve_out()
8620 struct ctl_lun *lun; in ctl_hndl_per_res_out_on_other_sc() local
8627 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_hndl_per_res_out_on_other_sc()
8631 mtx_lock(&lun->lun_lock); in ctl_hndl_per_res_out_on_other_sc()
8633 if (lun->flags & CTL_LUN_DISABLED) { in ctl_hndl_per_res_out_on_other_sc()
8634 mtx_unlock(&lun->lun_lock); in ctl_hndl_per_res_out_on_other_sc()
8640 ctl_alloc_prkey(lun, msg->pr.pr_info.residx); in ctl_hndl_per_res_out_on_other_sc()
8641 if (ctl_get_prkey(lun, msg->pr.pr_info.residx) == 0) in ctl_hndl_per_res_out_on_other_sc()
8642 lun->pr_key_count++; in ctl_hndl_per_res_out_on_other_sc()
8643 ctl_set_prkey(lun, msg->pr.pr_info.residx, in ctl_hndl_per_res_out_on_other_sc()
8645 lun->pr_generation++; in ctl_hndl_per_res_out_on_other_sc()
8649 ctl_clr_prkey(lun, msg->pr.pr_info.residx); in ctl_hndl_per_res_out_on_other_sc()
8650 lun->pr_key_count--; in ctl_hndl_per_res_out_on_other_sc()
8654 if (msg->pr.pr_info.residx == lun->pr_res_idx) { in ctl_hndl_per_res_out_on_other_sc()
8655 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_hndl_per_res_out_on_other_sc()
8656 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_hndl_per_res_out_on_other_sc()
8658 if ((lun->pr_res_type == SPR_TYPE_WR_EX_RO || in ctl_hndl_per_res_out_on_other_sc()
8659 lun->pr_res_type == SPR_TYPE_EX_AC_RO) && in ctl_hndl_per_res_out_on_other_sc()
8660 lun->pr_key_count) { in ctl_hndl_per_res_out_on_other_sc()
8670 if (ctl_get_prkey(lun, i) == 0) in ctl_hndl_per_res_out_on_other_sc()
8673 ctl_est_ua(lun, i, CTL_UA_RES_RELEASE); in ctl_hndl_per_res_out_on_other_sc()
8676 lun->pr_res_type = 0; in ctl_hndl_per_res_out_on_other_sc()
8677 } else if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS) { in ctl_hndl_per_res_out_on_other_sc()
8678 if (lun->pr_key_count==0) { in ctl_hndl_per_res_out_on_other_sc()
8679 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_hndl_per_res_out_on_other_sc()
8680 lun->pr_res_type = 0; in ctl_hndl_per_res_out_on_other_sc()
8681 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_hndl_per_res_out_on_other_sc()
8684 lun->pr_generation++; in ctl_hndl_per_res_out_on_other_sc()
8688 lun->flags |= CTL_LUN_PR_RESERVED; in ctl_hndl_per_res_out_on_other_sc()
8689 lun->pr_res_type = msg->pr.pr_info.res_type; in ctl_hndl_per_res_out_on_other_sc()
8690 lun->pr_res_idx = msg->pr.pr_info.residx; in ctl_hndl_per_res_out_on_other_sc()
8699 if (lun->pr_res_type != SPR_TYPE_EX_AC && in ctl_hndl_per_res_out_on_other_sc()
8700 lun->pr_res_type != SPR_TYPE_WR_EX && in ctl_hndl_per_res_out_on_other_sc()
8701 (lun->MODE_CTRL.queue_flags & SCP_NUAR) == 0) { in ctl_hndl_per_res_out_on_other_sc()
8703 if (i == residx || ctl_get_prkey(lun, i) == 0) in ctl_hndl_per_res_out_on_other_sc()
8705 ctl_est_ua(lun, i, CTL_UA_RES_RELEASE); in ctl_hndl_per_res_out_on_other_sc()
8709 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_hndl_per_res_out_on_other_sc()
8710 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_hndl_per_res_out_on_other_sc()
8711 lun->pr_res_type = 0; in ctl_hndl_per_res_out_on_other_sc()
8715 ctl_pro_preempt_other(lun, msg); in ctl_hndl_per_res_out_on_other_sc()
8718 lun->flags &= ~CTL_LUN_PR_RESERVED; in ctl_hndl_per_res_out_on_other_sc()
8719 lun->pr_res_type = 0; in ctl_hndl_per_res_out_on_other_sc()
8720 lun->pr_key_count = 0; in ctl_hndl_per_res_out_on_other_sc()
8721 lun->pr_res_idx = CTL_PR_NO_RESERVATION; in ctl_hndl_per_res_out_on_other_sc()
8724 if (ctl_get_prkey(lun, i) == 0) in ctl_hndl_per_res_out_on_other_sc()
8726 ctl_clr_prkey(lun, i); in ctl_hndl_per_res_out_on_other_sc()
8727 ctl_est_ua(lun, i, CTL_UA_REG_PREEMPT); in ctl_hndl_per_res_out_on_other_sc()
8729 lun->pr_generation++; in ctl_hndl_per_res_out_on_other_sc()
8733 mtx_unlock(&lun->lun_lock); in ctl_hndl_per_res_out_on_other_sc()
8739 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_read_write() local
8833 if (lun->be_lun->atomicblock == 0) { in ctl_read_write()
8846 if (num_blocks > lun->be_lun->atomicblock) { in ctl_read_write()
8884 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_read_write()
8887 MAX(lba, lun->be_lun->maxlba + 1)); in ctl_read_write()
8905 if ((lun->MODE_CACHING.flags1 & SCP_RCD) != 0) in ctl_read_write()
8908 if ((lun->MODE_CACHING.flags1 & SCP_WCE) == 0) in ctl_read_write()
8918 ctsio->kern_total_len = num_blocks * lun->be_lun->blocksize; in ctl_read_write()
8923 retval = lun->backend->data_submit((union ctl_io *)ctsio); in ctl_read_write()
8930 struct ctl_lun *lun = CTL_LUN(io); in ctl_cnw_cont() local
8946 retval = lun->backend->data_submit((union ctl_io *)ctsio); in ctl_cnw_cont()
8953 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_cnw() local
8993 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_cnw()
8996 MAX(lba, lun->be_lun->maxlba + 1)); in ctl_cnw()
9011 if ((lun->MODE_CACHING.flags1 & SCP_WCE) == 0) in ctl_cnw()
9014 ctsio->kern_total_len = 2 * num_blocks * lun->be_lun->blocksize; in ctl_cnw()
9032 retval = lun->backend->data_submit((union ctl_io *)ctsio); in ctl_cnw()
9039 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_verify() local
9103 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_verify()
9106 MAX(lba, lun->be_lun->maxlba + 1)); in ctl_verify()
9126 ctsio->kern_total_len = num_blocks * lun->be_lun->blocksize; in ctl_verify()
9134 retval = lun->backend->data_submit((union ctl_io *)ctsio); in ctl_verify()
9143 struct ctl_lun *lun, *request_lun = CTL_LUN(ctsio); in ctl_report_luns() local
9220 lun = softc->ctl_luns[lun_id]; in ctl_report_luns()
9221 if (lun == NULL) in ctl_report_luns()
9244 mtx_lock(&lun->lun_lock); in ctl_report_luns()
9245 ctl_clr_ua(lun, initidx, CTL_UA_LUN_CHANGE); in ctl_report_luns()
9246 mtx_unlock(&lun->lun_lock); in ctl_report_luns()
9286 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_request_sense() local
9318 if (lun == NULL || in ctl_request_sense()
9319 ((lun->flags & CTL_LUN_PRIMARY_SC) == 0 && in ctl_request_sense()
9337 mtx_lock(&lun->lun_lock); in ctl_request_sense()
9338 ps = lun->pending_sense[initidx / CTL_MAX_INIT_PER_PORT]; in ctl_request_sense()
9374 ua_type = ctl_build_ua(lun, initidx, sense_ptr, &sense_len, in ctl_request_sense()
9383 if (lun->MODE_IE.mrie != SIEP_MRIE_NO) { in ctl_request_sense()
9384 asc = lun->ie_asc; in ctl_request_sense()
9385 ascq = lun->ie_ascq; in ctl_request_sense()
9387 ctl_set_sense_data(sense_ptr, &sense_len, lun, sense_format, in ctl_request_sense()
9394 mtx_unlock(&lun->lun_lock); in ctl_request_sense()
9426 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_supported() local
9445 if (lun != NULL) in ctl_inquiry_evpd_supported()
9447 lun->be_lun->lun_type; in ctl_inquiry_evpd_supported()
9468 if (lun != NULL && lun->be_lun->lun_type == T_DIRECT) { in ctl_inquiry_evpd_supported()
9491 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_serial() local
9508 if (lun != NULL) in ctl_inquiry_evpd_serial()
9510 lun->be_lun->lun_type; in ctl_inquiry_evpd_serial()
9520 if (lun != NULL) { in ctl_inquiry_evpd_serial()
9522 (char *)lun->be_lun->serial_num, CTL_SN_LEN); in ctl_inquiry_evpd_serial()
9539 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_eid() local
9555 if (lun != NULL) in ctl_inquiry_evpd_eid()
9557 lun->be_lun->lun_type; in ctl_inquiry_evpd_eid()
9603 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_mpp() local
9621 if (lun != NULL) in ctl_inquiry_evpd_mpp()
9623 lun->be_lun->lun_type; in ctl_inquiry_evpd_mpp()
9647 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_devid() local
9658 if (lun && lun->lun_devid) in ctl_inquiry_evpd_devid()
9659 data_len += lun->lun_devid->len; in ctl_inquiry_evpd_devid()
9677 if (lun != NULL) in ctl_inquiry_evpd_devid()
9679 lun->be_lun->lun_type; in ctl_inquiry_evpd_devid()
9699 if (lun && lun->lun_devid) { in ctl_inquiry_evpd_devid()
9700 memcpy(desc, lun->lun_devid->data, lun->lun_devid->len); in ctl_inquiry_evpd_devid()
9702 lun->lun_devid->len); in ctl_inquiry_evpd_devid()
9759 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_scsi_ports() local
9773 if (lun != NULL && in ctl_inquiry_evpd_scsi_ports()
9774 ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_inquiry_evpd_scsi_ports()
9800 if (lun != NULL) in ctl_inquiry_evpd_scsi_ports()
9802 lun->be_lun->lun_type; in ctl_inquiry_evpd_scsi_ports()
9815 if (lun != NULL && in ctl_inquiry_evpd_scsi_ports()
9816 ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_inquiry_evpd_scsi_ports()
9850 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_sfs() local
9868 if (lun != NULL) in ctl_inquiry_evpd_sfs()
9870 lun->be_lun->lun_type; in ctl_inquiry_evpd_sfs()
9878 if (lun != NULL && lun->be_lun->lun_type == T_DIRECT) { in ctl_inquiry_evpd_sfs()
9883 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) { in ctl_inquiry_evpd_sfs()
9902 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_block_limits() local
9920 if (lun != NULL) in ctl_inquiry_evpd_block_limits()
9922 lun->be_lun->lun_type; in ctl_inquiry_evpd_block_limits()
9930 if (lun != NULL) { in ctl_inquiry_evpd_block_limits()
9931 scsi_ulto4b(lun->be_lun->opttxferlen, bl_ptr->opt_txfer_len); in ctl_inquiry_evpd_block_limits()
9932 if (lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) { in ctl_inquiry_evpd_block_limits()
9934 val = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_evpd_block_limits()
9940 val = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_evpd_block_limits()
9945 if (lun->be_lun->ublockexp != 0) { in ctl_inquiry_evpd_block_limits()
9946 scsi_ulto4b((1 << lun->be_lun->ublockexp), in ctl_inquiry_evpd_block_limits()
9948 scsi_ulto4b(0x80000000 | lun->be_lun->ublockoff, in ctl_inquiry_evpd_block_limits()
9952 scsi_ulto4b(lun->be_lun->atomicblock, in ctl_inquiry_evpd_block_limits()
9959 val = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_evpd_block_limits()
9964 if (lun->be_lun->maxlba + 1 > ival) in ctl_inquiry_evpd_block_limits()
9978 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_bdc() local
9995 if (lun != NULL) in ctl_inquiry_evpd_bdc()
9997 lun->be_lun->lun_type; in ctl_inquiry_evpd_bdc()
10002 if (lun != NULL && in ctl_inquiry_evpd_bdc()
10003 (value = dnvlist_get_string(lun->be_lun->options, "rpm", NULL)) != NULL) in ctl_inquiry_evpd_bdc()
10008 if (lun != NULL && in ctl_inquiry_evpd_bdc()
10009 (value = dnvlist_get_string(lun->be_lun->options, "formfactor", NULL)) != NULL) in ctl_inquiry_evpd_bdc()
10026 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd_lbp() local
10042 if (lun != NULL) in ctl_inquiry_evpd_lbp()
10044 lun->be_lun->lun_type; in ctl_inquiry_evpd_lbp()
10051 if (lun != NULL && lun->be_lun->flags & CTL_LUN_FLAG_UNMAP) { in ctl_inquiry_evpd_lbp()
10054 value = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_evpd_lbp()
10078 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_evpd() local
10111 if (lun == NULL || lun->be_lun->lun_type != T_DIRECT) in ctl_inquiry_evpd()
10116 if (lun == NULL || lun->be_lun->lun_type != T_DIRECT) in ctl_inquiry_evpd()
10121 if (lun == NULL || lun->be_lun->lun_type != T_DIRECT) in ctl_inquiry_evpd()
10149 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_inquiry_std() local
10176 if (lun != NULL) { in ctl_inquiry_std()
10177 if ((lun->flags & CTL_LUN_PRIMARY_SC) || in ctl_inquiry_std()
10180 lun->be_lun->lun_type; in ctl_inquiry_std()
10183 lun->be_lun->lun_type; in ctl_inquiry_std()
10185 if (lun->flags & CTL_LUN_REMOVABLE) in ctl_inquiry_std()
10230 if (lun == NULL || (val = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_std()
10238 if (lun == NULL) { in ctl_inquiry_std()
10241 } else if ((val = dnvlist_get_string(lun->be_lun->options, "product", in ctl_inquiry_std()
10243 switch (lun->be_lun->lun_type) { in ctl_inquiry_std()
10271 if (lun == NULL || (val = dnvlist_get_string(lun->be_lun->options, in ctl_inquiry_std()
10311 if (lun == NULL) { in ctl_inquiry_std()
10315 switch (lun->be_lun->lun_type) { in ctl_inquiry_std()
10368 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_get_config() local
10398 if (lun->flags & CTL_LUN_NO_MEDIA) in ctl_get_config()
10465 if (rt == SGC_RT_CURRENT && (lun->flags & CTL_LUN_NO_MEDIA)) in ctl_get_config()
10471 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10474 scsi_ulto4b(lun->be_lun->blocksize, &feature->feature_data[0]); in ctl_get_config()
10483 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10492 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10502 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10513 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10524 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10534 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10545 if ((lun->flags & CTL_LUN_NO_MEDIA) == 0) in ctl_get_config()
10652 struct ctl_lun *lun = CTL_LUN(ctsio); in ctl_read_toc() local
10691 ctl_ultomsf(lun->be_lun->maxlba+1, descr->track_start); in ctl_read_toc()
10693 scsi_ulto4b(lun->be_lun->maxlba+1, descr->track_start); in ctl_read_toc()
10749 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_identify() local
10778 if (lun == NULL) { in ctl_nvme_identify()
10792 retval = lun->backend->config_read((union ctl_io *)ctnio); in ctl_nvme_identify()
10799 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_flush() local
10811 retval = lun->backend->config_write((union ctl_io *)ctnio); in ctl_nvme_flush()
10819 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_read_write() local
10843 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_read_write()
10869 ctnio->kern_total_len = num_blocks * lun->be_lun->blocksize; in ctl_nvme_read_write()
10874 retval = lun->backend->data_submit((union ctl_io *)ctnio); in ctl_nvme_read_write()
10881 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_write_uncorrectable() local
10900 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_write_uncorrectable()
10912 retval = lun->backend->config_write((union ctl_io *)ctnio); in ctl_nvme_write_uncorrectable()
10920 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_compare() local
10943 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_compare()
10955 ctnio->kern_total_len = num_blocks * lun->be_lun->blocksize; in ctl_nvme_compare()
10959 retval = lun->backend->data_submit((union ctl_io *)ctnio); in ctl_nvme_compare()
10966 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_write_zeroes() local
10985 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_write_zeroes()
10997 retval = lun->backend->config_write((union ctl_io *)ctnio); in ctl_nvme_write_zeroes()
11005 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_dataset_management() local
11051 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_dataset_management()
11060 retval = lun->backend->config_write((union ctl_io *)ctnio); in ctl_nvme_dataset_management()
11067 struct ctl_lun *lun = CTL_LUN(ctnio); in ctl_nvme_verify() local
11090 if (((lba + num_blocks) > (lun->be_lun->maxlba + 1)) in ctl_nvme_verify()
11106 retval = lun->backend->data_submit((union ctl_io *)ctnio); in ctl_nvme_verify()
11176 ctl_nvmeio_lun_check(struct ctl_lun *lun, in ctl_nvmeio_lun_check() argument
11179 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_nvmeio_lun_check()
11182 if ((lun->flags & (CTL_LUN_EJECTED | CTL_LUN_NO_MEDIA | in ctl_nvmeio_lun_check()
11199 ctl_nvme_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, in ctl_nvme_check_ooa() argument
11206 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_nvme_check_ooa()
11290 struct ctl_lun *lun; in ctl_nvmeio_precheck() local
11295 lun = NULL; in ctl_nvmeio_precheck()
11298 lun = softc->ctl_luns[targ_lun]; in ctl_nvmeio_precheck()
11299 if (lun != NULL) { in ctl_nvmeio_precheck()
11305 mtx_lock(&lun->lun_lock); in ctl_nvmeio_precheck()
11306 if (lun->flags & CTL_LUN_DISABLED) { in ctl_nvmeio_precheck()
11307 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11308 lun = NULL; in ctl_nvmeio_precheck()
11311 CTL_LUN(ctnio) = lun; in ctl_nvmeio_precheck()
11312 if (lun != NULL) { in ctl_nvmeio_precheck()
11313 CTL_BACKEND_LUN(ctnio) = lun->be_lun; in ctl_nvmeio_precheck()
11320 if (LIST_EMPTY(&lun->ooa_queue)) in ctl_nvmeio_precheck()
11321 lun->idle_time += getsbinuptime() - lun->last_busy; in ctl_nvmeio_precheck()
11323 LIST_INSERT_HEAD(&lun->ooa_queue, &ctnio->io_hdr, ooa_links); in ctl_nvmeio_precheck()
11329 if (lun) in ctl_nvmeio_precheck()
11330 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11338 if (lun == NULL) { in ctl_nvmeio_precheck()
11353 if (lun->be_lun->lun_type != T_DIRECT) { in ctl_nvmeio_precheck()
11354 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11361 if (ctl_nvmeio_lun_check(lun, entry, ctnio) != 0) { in ctl_nvmeio_precheck()
11362 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11368 switch (ctl_nvme_check_ooa(lun, (union ctl_io *)ctnio, &bio, in ctl_nvmeio_precheck()
11372 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11383 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11387 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11393 mtx_unlock(&lun->lun_lock); in ctl_nvmeio_precheck()
11687 ctl_check_for_blockage(struct ctl_lun *lun, union ctl_io *pending_io, in ctl_check_for_blockage() argument
11761 if (lun->be_lun->serseq != CTL_LUN_SERSEQ_OFF) in ctl_check_for_blockage()
11767 if ((lun->MODE_CTRL.queue_flags & SCP_QUEUE_ALG_MASK) == in ctl_check_for_blockage()
11773 (lun->be_lun->serseq == CTL_LUN_SERSEQ_ON))); in ctl_check_for_blockage()
11775 if ((lun->MODE_CTRL.queue_flags & SCP_QUEUE_ALG_MASK) == in ctl_check_for_blockage()
11793 ctl_check_ooa(struct ctl_lun *lun, union ctl_io *pending_io, in ctl_check_ooa() argument
11802 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_check_ooa()
11831 action = ctl_check_for_blockage(lun, pending_io, serialize_row, in ctl_check_ooa()
11851 ctl_scsi_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) in ctl_scsi_try_unblock_io() argument
11853 struct ctl_softc *softc = lun->ctl_softc; in ctl_scsi_try_unblock_io()
11861 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_scsi_try_unblock_io()
11869 action = ctl_check_ooa(lun, io, &bio); in ctl_scsi_try_unblock_io()
11908 if (ctl_scsiio_lun_check(lun, entry, &io->scsiio) != 0) { in ctl_scsi_try_unblock_io()
11928 ctl_try_unblock_others(lun, io, TRUE); in ctl_scsi_try_unblock_io()
11947 ctl_nvme_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) in ctl_nvme_try_unblock_io() argument
11954 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_nvme_try_unblock_io()
11989 if (ctl_nvmeio_lun_check(lun, entry, &io->nvmeio) != 0) { in ctl_nvme_try_unblock_io()
11999 ctl_try_unblock_io(struct ctl_lun *lun, union ctl_io *io, bool skip) in ctl_try_unblock_io() argument
12003 return (ctl_scsi_try_unblock_io(lun, io, skip)); in ctl_try_unblock_io()
12006 return (ctl_nvme_try_unblock_io(lun, io, skip)); in ctl_try_unblock_io()
12021 ctl_try_unblock_others(struct ctl_lun *lun, union ctl_io *bio, bool skip) in ctl_try_unblock_others() argument
12025 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_try_unblock_others()
12033 ctl_try_unblock_io(lun, io, skip); in ctl_try_unblock_others()
12052 ctl_scsiio_lun_check(struct ctl_lun *lun, in ctl_scsiio_lun_check() argument
12055 struct ctl_softc *softc = lun->ctl_softc; in ctl_scsiio_lun_check()
12061 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_scsiio_lun_check()
12067 if ((lun->flags & CTL_LUN_PRIMARY_SC) == 0) { in ctl_scsiio_lun_check()
12074 if ((lun->flags & CTL_LUN_PEER_SC_PRIMARY) == 0 && in ctl_scsiio_lun_check()
12093 if (lun->be_lun->flags & CTL_LUN_FLAG_READONLY) { in ctl_scsiio_lun_check()
12098 if ((lun->MODE_CTRL.eca_and_aen & SCP_SWP) != 0) { in ctl_scsiio_lun_check()
12113 if ((lun->flags & CTL_LUN_RESERVED) in ctl_scsiio_lun_check()
12115 if (lun->res_idx != residx) { in ctl_scsiio_lun_check()
12122 if ((lun->flags & CTL_LUN_PR_RESERVED) == 0 || in ctl_scsiio_lun_check()
12126 (lun->pr_res_type == SPR_TYPE_WR_EX || in ctl_scsiio_lun_check()
12127 lun->pr_res_type == SPR_TYPE_WR_EX_RO || in ctl_scsiio_lun_check()
12128 lun->pr_res_type == SPR_TYPE_WR_EX_AR)) { in ctl_scsiio_lun_check()
12136 if (ctl_get_prkey(lun, residx) == 0 || in ctl_scsiio_lun_check()
12137 (residx != lun->pr_res_idx && lun->pr_res_type < 4)) { in ctl_scsiio_lun_check()
12145 if (lun->flags & CTL_LUN_EJECTED) in ctl_scsiio_lun_check()
12147 else if (lun->flags & CTL_LUN_NO_MEDIA) { in ctl_scsiio_lun_check()
12148 if (lun->flags & CTL_LUN_REMOVABLE) in ctl_scsiio_lun_check()
12152 } else if (lun->flags & CTL_LUN_STOPPED) in ctl_scsiio_lun_check()
12177 struct ctl_lun *lun; in ctl_failover_lun() local
12187 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_failover_lun()
12191 mtx_lock(&lun->lun_lock); in ctl_failover_lun()
12193 if (lun->flags & CTL_LUN_DISABLED) { in ctl_failover_lun()
12194 mtx_unlock(&lun->lun_lock); in ctl_failover_lun()
12199 LIST_FOREACH_SAFE(io, &lun->ooa_queue, ooa_links, next_io) { in ctl_failover_lun()
12205 ctl_try_unblock_io(lun, in ctl_failover_lun()
12228 LIST_FOREACH_SAFE(io, &lun->ooa_queue, ooa_links, next_io) { in ctl_failover_lun()
12236 ctl_try_unblock_others(lun, (union ctl_io *)io, in ctl_failover_lun()
12252 mtx_unlock(&lun->lun_lock); in ctl_failover_lun()
12259 struct ctl_lun *lun; in ctl_scsiio_precheck() local
12264 lun = NULL; in ctl_scsiio_precheck()
12267 lun = softc->ctl_luns[targ_lun]; in ctl_scsiio_precheck()
12268 if (lun) { in ctl_scsiio_precheck()
12274 mtx_lock(&lun->lun_lock); in ctl_scsiio_precheck()
12275 if (lun->flags & CTL_LUN_DISABLED) { in ctl_scsiio_precheck()
12276 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12277 lun = NULL; in ctl_scsiio_precheck()
12280 CTL_LUN(ctsio) = lun; in ctl_scsiio_precheck()
12281 if (lun) { in ctl_scsiio_precheck()
12282 CTL_BACKEND_LUN(ctsio) = lun->be_lun; in ctl_scsiio_precheck()
12289 if (LIST_EMPTY(&lun->ooa_queue)) in ctl_scsiio_precheck()
12290 lun->idle_time += getsbinuptime() - lun->last_busy; in ctl_scsiio_precheck()
12292 LIST_INSERT_HEAD(&lun->ooa_queue, &ctsio->io_hdr, ooa_links); in ctl_scsiio_precheck()
12298 if (lun) in ctl_scsiio_precheck()
12299 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12313 if (lun == NULL) { in ctl_scsiio_precheck()
12329 if (!ctl_cmd_applicable(lun->be_lun->lun_type, entry)) { in ctl_scsiio_precheck()
12330 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12348 ps = lun->pending_sense[initidx / CTL_MAX_INIT_PER_PORT]; in ctl_scsiio_precheck()
12379 ua_type = ctl_build_ua(lun, initidx, &ctsio->sense_data, in ctl_scsiio_precheck()
12382 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12391 if (ctl_scsiio_lun_check(lun, entry, ctsio) != 0) { in ctl_scsiio_precheck()
12392 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12406 if ((lun->flags & CTL_LUN_PRIMARY_SC) == 0 && in ctl_scsiio_precheck()
12407 (lun->flags & CTL_LUN_PEER_SC_PRIMARY) != 0 && in ctl_scsiio_precheck()
12414 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12439 switch (ctl_check_ooa(lun, (union ctl_io *)ctsio, &bio)) { in ctl_scsiio_precheck()
12443 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12450 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12453 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12458 mtx_unlock(&lun->lun_lock); in ctl_scsiio_precheck()
12584 struct ctl_lun *lun; in ctl_target_reset() local
12606 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_target_reset()
12608 ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_target_reset()
12610 ctl_do_lun_reset(lun, initidx, ua_type); in ctl_target_reset()
12639 ctl_do_lun_reset(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua_type) in ctl_do_lun_reset() argument
12644 mtx_lock(&lun->lun_lock); in ctl_do_lun_reset()
12646 LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { in ctl_do_lun_reset()
12648 ctl_try_unblock_io(lun, (union ctl_io *)xioh, FALSE); in ctl_do_lun_reset()
12652 free(lun->pending_sense[i], M_CTL); in ctl_do_lun_reset()
12653 lun->pending_sense[i] = NULL; in ctl_do_lun_reset()
12656 lun->flags &= ~CTL_LUN_RESERVED; in ctl_do_lun_reset()
12658 if (lun->prevent) { in ctl_do_lun_reset()
12660 ctl_clear_mask(lun->prevent, i); in ctl_do_lun_reset()
12661 lun->prevent_count = 0; in ctl_do_lun_reset()
12664 ctl_tpc_lun_clear(lun, -1); in ctl_do_lun_reset()
12667 ctl_est_ua_all(lun, initidx, ua_type); in ctl_do_lun_reset()
12669 ctl_est_ua_all(lun, -1, ua_type); in ctl_do_lun_reset()
12671 mtx_unlock(&lun->lun_lock); in ctl_do_lun_reset()
12678 struct ctl_lun *lun; in ctl_lun_reset() local
12685 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_lun_reset()
12690 ctl_do_lun_reset(lun, initidx, CTL_UA_LUN_RESET); in ctl_lun_reset()
12709 ctl_abort_tasks_lun(struct ctl_lun *lun, uint32_t targ_port, uint32_t init_id, in ctl_abort_tasks_lun() argument
12714 mtx_assert(&lun->lun_lock, MA_OWNED); in ctl_abort_tasks_lun()
12723 LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) { in ctl_abort_tasks_lun()
12734 if (!other_sc && !(lun->flags & CTL_LUN_PRIMARY_SC)) { in ctl_abort_tasks_lun()
12748 ctl_try_unblock_io(lun, xio, FALSE); in ctl_abort_tasks_lun()
12757 struct ctl_lun *lun; in ctl_abort_task_set() local
12766 (lun = softc->ctl_luns[targ_lun]) == NULL) { in ctl_abort_task_set()
12772 mtx_lock(&lun->lun_lock); in ctl_abort_task_set()
12775 ctl_abort_tasks_lun(lun, io->io_hdr.nexus.targ_port, in ctl_abort_task_set()
12779 ctl_abort_tasks_lun(lun, UINT32_MAX, UINT32_MAX, in ctl_abort_task_set()
12782 mtx_unlock(&lun->lun_lock); in ctl_abort_task_set()
12791 struct ctl_lun *lun; in ctl_i_t_nexus_loss() local
12798 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_i_t_nexus_loss()
12799 mtx_lock(&lun->lun_lock); in ctl_i_t_nexus_loss()
12801 ctl_abort_tasks_lun(lun, p, i, 1); in ctl_i_t_nexus_loss()
12803 ps = lun->pending_sense[p]; in ctl_i_t_nexus_loss()
12807 if ((lun->flags & CTL_LUN_RESERVED) && (lun->res_idx == initidx)) in ctl_i_t_nexus_loss()
12808 lun->flags &= ~CTL_LUN_RESERVED; in ctl_i_t_nexus_loss()
12810 if (lun->prevent && ctl_is_set(lun->prevent, initidx)) { in ctl_i_t_nexus_loss()
12811 ctl_clear_mask(lun->prevent, initidx); in ctl_i_t_nexus_loss()
12812 lun->prevent_count--; in ctl_i_t_nexus_loss()
12815 ctl_tpc_lun_clear(lun, initidx); in ctl_i_t_nexus_loss()
12817 ctl_est_ua(lun, initidx, ua_type); in ctl_i_t_nexus_loss()
12818 mtx_unlock(&lun->lun_lock); in ctl_i_t_nexus_loss()
12852 struct ctl_lun *lun; local
12861 (lun = softc->ctl_luns[targ_lun]) == NULL) {
12867 mtx_lock(&lun->lun_lock);
12876 LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) {
12909 !(lun->flags & CTL_LUN_PRIMARY_SC)) {
12922 ctl_try_unblock_io(lun, xio, FALSE);
12925 mtx_unlock(&lun->lun_lock);
12935 struct ctl_lun *lun; local
12942 (lun = softc->ctl_luns[targ_lun]) == NULL) {
12947 mtx_lock(&lun->lun_lock);
12949 LIST_FOREACH(xioh, &lun->ooa_queue, ooa_links) {
12963 mtx_unlock(&lun->lun_lock);
12975 struct ctl_lun *lun; local
12982 (lun = softc->ctl_luns[targ_lun]) == NULL) {
12987 mtx_lock(&lun->lun_lock);
12990 ua = ctl_build_qae(lun, initidx, io->taskio.task_resp);
12991 mtx_unlock(&lun->lun_lock);
13062 struct ctl_lun *lun; local
13076 (lun = softc->ctl_luns[targ_lun]) == NULL) {
13080 mtx_lock(&lun->lun_lock);
13081 if (ctl_scsiio_lun_check(lun, entry, &io->scsiio) != 0) {
13082 mtx_unlock(&lun->lun_lock);
13087 mtx_unlock(&lun->lun_lock);
13096 (lun = softc->ctl_luns[targ_lun]) == NULL) {
13100 mtx_lock(&lun->lun_lock);
13101 ctl_try_unblock_others(lun, io, TRUE);
13103 mtx_unlock(&lun->lun_lock);
13199 ctl_inject_error(struct ctl_lun *lun, union ctl_io *io) argument
13205 mtx_assert(&lun->lun_lock, MA_OWNED);
13207 STAILQ_FOREACH_SAFE(desc, &lun->error_list, links, desc2) {
13260 STAILQ_REMOVE(&lun->error_list, desc, ctl_error_desc, links);
13355 struct ctl_lun *lun; local
13357 lun = CTL_LUN(io);
13358 if ((lun != NULL)
13359 && (lun->delay_info.datamove_delay > 0)) {
13363 lun->delay_info.datamove_delay * hz,
13365 if (lun->delay_info.datamove_type ==
13367 lun->delay_info.datamove_delay = 0;
13830 struct ctl_lun *lun = CTL_LUN(io); local
13870 if (lun == NULL) {
13876 mtx_lock(&lun->lun_lock);
13883 if (lun->ie_reported == 0 && lun->ie_asc != 0 &&
13886 uint8_t mrie = lun->MODE_IE.mrie;
13887 uint8_t per = ((lun->MODE_RWER.byte3 & SMS_RWER_PER) ||
13888 (lun->MODE_VER.byte3 & SMS_VER_PER));
13900 /*asc*/ lun->ie_asc,
13901 /*ascq*/ lun->ie_ascq,
13903 lun->ie_reported = 1;
13905 } else if (lun->ie_reported < 0)
13906 lun->ie_reported = 0;
13912 if (!STAILQ_EMPTY(&lun->error_list) &&
13915 ctl_inject_error(lun, io);
13943 lun->stats.bytes[type] += ctl_kern_total_len(io);
13944 lun->stats.operations[type] ++;
13945 lun->stats.dmas[type] += io->io_hdr.num_dmas;
13947 bintime_add(&lun->stats.dma_time[type], &io->io_hdr.dma_bt);
13948 bintime_add(&lun->stats.time[type], &bt);
13967 ctl_try_unblock_others(lun, io, TRUE);
13974 if (LIST_EMPTY(&lun->ooa_queue))
13975 lun->last_busy = getsbinuptime();
13982 if ((lun->flags & CTL_LUN_INVALID)
13983 && LIST_EMPTY(&lun->ooa_queue)) {
13984 mtx_unlock(&lun->lun_lock);
13985 ctl_free_lun(lun);
13987 mtx_unlock(&lun->lun_lock);
14045 struct ctl_lun *lun; local
14064 (lun = softc->ctl_luns[targ_lun]) == NULL) {
14068 mtx_lock(&lun->lun_lock);
14073 if (lun->pending_sense[p] == NULL) {
14074 lun->pending_sense[p] = malloc(sizeof(*ps) * CTL_MAX_INIT_PER_PORT,
14077 if ((ps = lun->pending_sense[p]) != NULL) {
14082 mtx_unlock(&lun->lun_lock);
14196 struct ctl_lun *lun = CTL_LUN(io); local
14200 mtx_lock(&lun->lun_lock);
14202 ctl_try_unblock_others(lun, io, FALSE);
14203 mtx_unlock(&lun->lun_lock);
14280 struct ctl_lun *lun = CTL_LUN(io); local
14282 if ((lun != NULL)
14283 && (lun->delay_info.done_delay > 0)) {
14287 lun->delay_info.done_delay * hz,
14289 if (lun->delay_info.done_type == CTL_DELAY_TYPE_ONESHOT)
14290 lun->delay_info.done_delay = 0;
14392 struct ctl_lun *lun; local
14406 STAILQ_FOREACH(lun, &softc->lun_list, links) {
14407 if ((lun->flags & CTL_LUN_DISABLED) ||
14408 (lun->flags & CTL_LUN_NO_MEDIA) ||
14409 lun->backend->lun_attr == NULL)
14411 if ((lun->flags & CTL_LUN_PRIMARY_SC) == 0 &&
14414 if ((lun->MODE_RWER.byte8 & SMS_RWER_LBPERE) == 0)
14417 page = &lun->MODE_LBP;
14440 val = lun->backend->lun_attr(lun->be_lun, attr);
14452 mtx_lock(&lun->lun_lock);
14455 (uint8_t *)page, lun->ua_tpt_info);
14456 if (lun->lasttpt == 0 ||
14457 time_uptime - lun->lasttpt >= CTL_LBP_UA_PERIOD) {
14458 lun->lasttpt = time_uptime;
14459 ctl_est_ua_all(lun, -1, CTL_UA_THIN_PROV_THRES);
14464 lun->lasttpt = 0;
14465 ctl_clr_ua_all(lun, -1, CTL_UA_THIN_PROV_THRES);
14468 mtx_unlock(&lun->lun_lock);
14470 lun->ctl_softc->ha_mode == CTL_HA_MODE_XFER) {
14476 msg.hdr.nexus.targ_lun = lun->lun;
14477 msg.hdr.nexus.targ_mapped_lun = lun->lun;
14481 memcpy(msg.ua.ua_info, lun->ua_tpt_info, 8);