From 61063b2326662c93718720e2bb973aadf3a8d01a Mon Sep 17 00:00:00 2001 From: mav Date: Sat, 21 Jan 2017 08:30:10 +0000 Subject: [PATCH] MFC r310539: Remove CTL_MAX_LUNS from places where it is not required. git-svn-id: svn://svn.freebsd.org/base/stable/10@312571 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/cam/ctl/ctl.c | 47 +++++++++++++++++++------------------ sys/cam/ctl/ctl_frontend.c | 12 +++++----- sys/cam/ctl/ctl_tpc.c | 6 ++--- sys/cam/ctl/ctl_tpc_local.c | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 1a246412c..b0f736988 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -1220,7 +1220,7 @@ ctl_isc_port_sync(struct ctl_softc *softc, union ctl_ha_msg *msg, int len) } mtx_lock(&softc->ctl_lock); STAILQ_FOREACH(lun, &softc->lun_list, links) { - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; mtx_lock(&lun->lun_lock); ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); @@ -2897,18 +2897,18 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, break; } case CTL_DUMP_STRUCTS: { - int i, j, k; + int j, k; struct ctl_port *port; struct ctl_frontend *fe; mtx_lock(&softc->ctl_lock); printf("CTL Persistent Reservation information start:\n"); - for (i = 0; i < CTL_MAX_LUNS; i++) { - lun = softc->ctl_luns[i]; - - if ((lun == NULL) - || ((lun->flags & CTL_LUN_DISABLED) != 0)) + STAILQ_FOREACH(lun, &softc->lun_list, links) { + mtx_lock(&lun->lun_lock); + if ((lun->flags & CTL_LUN_DISABLED) != 0) { + mtx_unlock(&lun->lun_lock); continue; + } for (j = 0; j < CTL_MAX_PORTS; j++) { if (lun->pr_keys[j] == NULL) @@ -2916,11 +2916,12 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, for (k = 0; k < CTL_MAX_INIT_PER_PORT; k++){ if (lun->pr_keys[j][k] == 0) continue; - printf(" LUN %d port %d iid %d key " - "%#jx\n", i, j, k, + printf(" LUN %ju port %d iid %d key " + "%#jx\n", lun->lun, j, k, (uintmax_t)lun->pr_keys[j][k]); } } + mtx_unlock(&lun->lun_lock); } printf("CTL Persistent Reservation information end\n"); printf("CTL Ports:\n"); @@ -3303,7 +3304,7 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, sbuf_printf(sb, "\ton\n"); for (j = 0; j < CTL_MAX_LUNS; j++) { plun = ctl_lun_map_from_port(port, j); - if (plun >= CTL_MAX_LUNS) + if (plun == UINT32_MAX) continue; sbuf_printf(sb, "\t%u\n", @@ -3371,8 +3372,8 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, } if (port->status & CTL_PORT_STATUS_ONLINE) { STAILQ_FOREACH(lun, &softc->lun_list, links) { - if (ctl_lun_map_to_port(port, lun->lun) >= - CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == + UINT32_MAX) continue; mtx_lock(&lun->lun_lock); ctl_est_ua_port(lun, lm->port, -1, @@ -3500,7 +3501,7 @@ ctl_lun_map_set(struct ctl_port *port, uint32_t plun, uint32_t glun) } old = port->lun_map[plun]; port->lun_map[plun] = glun; - if ((port->status & CTL_PORT_STATUS_ONLINE) && old >= CTL_MAX_LUNS) { + if ((port->status & CTL_PORT_STATUS_ONLINE) && old == UINT32_MAX) { if (port->lun_enable != NULL) port->lun_enable(port->targ_lun_arg, plun); ctl_isc_announce_port(port); @@ -3517,7 +3518,7 @@ ctl_lun_map_unset(struct ctl_port *port, uint32_t plun) return (0); old = port->lun_map[plun]; port->lun_map[plun] = UINT32_MAX; - if ((port->status & CTL_PORT_STATUS_ONLINE) && old < CTL_MAX_LUNS) { + if ((port->status & CTL_PORT_STATUS_ONLINE) && old != UINT32_MAX) { if (port->lun_disable != NULL) port->lun_disable(port->targ_lun_arg, plun); ctl_isc_announce_port(port); @@ -3531,7 +3532,7 @@ ctl_lun_map_from_port(struct ctl_port *port, uint32_t lun_id) if (port == NULL) return (UINT32_MAX); - if (port->lun_map == NULL || lun_id >= CTL_MAX_LUNS) + if (port->lun_map == NULL || lun_id == UINT32_MAX) return (lun_id); return (port->lun_map[lun_id]); } @@ -7133,7 +7134,7 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio) STAILQ_FOREACH(port, &softc->port_list, links) { if ((port->status & CTL_PORT_STATUS_ONLINE) == 0) continue; - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; num_target_ports++; if (port->status & CTL_PORT_STATUS_HA_SHARED) @@ -7225,7 +7226,7 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio) if (!softc->is_single && (port->status & CTL_PORT_STATUS_HA_SHARED) == 0) continue; - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; scsi_ulto2b(port->targ_port, tpg_desc->descriptors[pc]. relative_target_port_identifier); @@ -7250,7 +7251,7 @@ ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio) continue; if (port->status & CTL_PORT_STATUS_HA_SHARED) continue; - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; scsi_ulto2b(port->targ_port, tpg_desc->descriptors[pc]. relative_target_port_identifier); @@ -9069,7 +9070,7 @@ ctl_report_luns(struct ctl_scsiio *ctsio) mtx_lock(&softc->ctl_lock); num_luns = 0; for (targ_lun_id = 0; targ_lun_id < CTL_MAX_LUNS; targ_lun_id++) { - if (ctl_lun_map_from_port(port, targ_lun_id) < CTL_MAX_LUNS) + if (ctl_lun_map_from_port(port, targ_lun_id) != UINT32_MAX) num_luns++; } mtx_unlock(&softc->ctl_lock); @@ -9129,7 +9130,7 @@ ctl_report_luns(struct ctl_scsiio *ctsio) mtx_lock(&softc->ctl_lock); for (targ_lun_id = 0, num_filled = 0; targ_lun_id < CTL_MAX_LUNS && num_filled < num_luns; targ_lun_id++) { lun_id = ctl_lun_map_from_port(port, targ_lun_id); - if (lun_id >= CTL_MAX_LUNS) + if (lun_id == UINT32_MAX) continue; lun = softc->ctl_luns[lun_id]; if (lun == NULL) @@ -9765,7 +9766,7 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_scsiio *ctsio, int alloc_len) if ((port->status & CTL_PORT_STATUS_ONLINE) == 0) continue; if (lun != NULL && - ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; num_target_ports++; if (port->init_devid) @@ -9816,7 +9817,7 @@ ctl_inquiry_evpd_scsi_ports(struct ctl_scsiio *ctsio, int alloc_len) if ((port->status & CTL_PORT_STATUS_ONLINE) == 0) continue; if (lun != NULL && - ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; scsi_ulto2b(port->targ_port, pd->relative_port_id); if (port->init_devid) { @@ -11873,7 +11874,7 @@ ctl_target_reset(struct ctl_softc *softc, union ctl_io *io, port = ctl_io_port(&io->io_hdr); STAILQ_FOREACH(lun, &softc->lun_list, links) { if (port != NULL && - ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; retval += ctl_do_lun_reset(lun, io, ua_type); } diff --git a/sys/cam/ctl/ctl_frontend.c b/sys/cam/ctl/ctl_frontend.c index 75837b51a..5c6fa05b6 100644 --- a/sys/cam/ctl/ctl_frontend.c +++ b/sys/cam/ctl/ctl_frontend.c @@ -316,8 +316,8 @@ ctl_port_online(struct ctl_port *port) if (port->lun_enable != NULL) { if (port->lun_map) { for (l = 0; l < CTL_MAX_LUNS; l++) { - if (ctl_lun_map_from_port(port, l) >= - CTL_MAX_LUNS) + if (ctl_lun_map_from_port(port, l) == + UINT32_MAX) continue; port->lun_enable(port->targ_lun_arg, l); } @@ -338,7 +338,7 @@ ctl_port_online(struct ctl_port *port) } port->status |= CTL_PORT_STATUS_ONLINE; STAILQ_FOREACH(lun, &softc->lun_list, links) { - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; mtx_lock(&lun->lun_lock); ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); @@ -360,8 +360,8 @@ ctl_port_offline(struct ctl_port *port) if (port->lun_disable != NULL) { if (port->lun_map) { for (l = 0; l < CTL_MAX_LUNS; l++) { - if (ctl_lun_map_from_port(port, l) >= - CTL_MAX_LUNS) + if (ctl_lun_map_from_port(port, l) == + UINT32_MAX) continue; port->lun_disable(port->targ_lun_arg, l); } @@ -373,7 +373,7 @@ ctl_port_offline(struct ctl_port *port) mtx_lock(&softc->ctl_lock); port->status &= ~CTL_PORT_STATUS_ONLINE; STAILQ_FOREACH(lun, &softc->lun_list, links) { - if (ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; mtx_lock(&lun->lun_lock); ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); diff --git a/sys/cam/ctl/ctl_tpc.c b/sys/cam/ctl/ctl_tpc.c index 484293b5b..960444aae 100644 --- a/sys/cam/ctl/ctl_tpc.c +++ b/sys/cam/ctl/ctl_tpc.c @@ -894,7 +894,7 @@ tpc_process_b2b(struct tpc_list *list) dcscd = scsi_2btoul(seg->dst_cscd); sl = tpc_resolve(list, scscd, &srcblock, NULL, NULL); dl = tpc_resolve(list, dcscd, &dstblock, &pb, &pbo); - if (sl >= CTL_MAX_LUNS || dl >= CTL_MAX_LUNS) { + if (sl == UINT64_MAX || dl == UINT64_MAX) { ctl_set_sense(list->ctsio, /*current_error*/ 1, /*sense_key*/ SSD_KEY_COPY_ABORTED, /*asc*/ 0x08, /*ascq*/ 0x04, @@ -1042,7 +1042,7 @@ tpc_process_verify(struct tpc_list *list) seg = (struct scsi_ec_segment_verify *)list->seg[list->curseg]; cscd = scsi_2btoul(seg->src_cscd); sl = tpc_resolve(list, cscd, NULL, NULL, NULL); - if (sl >= CTL_MAX_LUNS) { + if (sl == UINT64_MAX) { ctl_set_sense(list->ctsio, /*current_error*/ 1, /*sense_key*/ SSD_KEY_COPY_ABORTED, /*asc*/ 0x08, /*ascq*/ 0x04, @@ -1106,7 +1106,7 @@ tpc_process_register_key(struct tpc_list *list) seg = (struct scsi_ec_segment_register_key *)list->seg[list->curseg]; cscd = scsi_2btoul(seg->dst_cscd); dl = tpc_resolve(list, cscd, NULL, NULL, NULL); - if (dl >= CTL_MAX_LUNS) { + if (dl == UINT64_MAX) { ctl_set_sense(list->ctsio, /*current_error*/ 1, /*sense_key*/ SSD_KEY_COPY_ABORTED, /*asc*/ 0x08, /*ascq*/ 0x04, diff --git a/sys/cam/ctl/ctl_tpc_local.c b/sys/cam/ctl/ctl_tpc_local.c index 4f368f95f..f726aa59e 100644 --- a/sys/cam/ctl/ctl_tpc_local.c +++ b/sys/cam/ctl/ctl_tpc_local.c @@ -290,7 +290,7 @@ tpcl_resolve(struct ctl_softc *softc, int init_port, port = NULL; STAILQ_FOREACH(lun, &softc->lun_list, links) { if (port != NULL && - ctl_lun_map_to_port(port, lun->lun) >= CTL_MAX_LUNS) + ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) continue; if (lun->lun_devid == NULL) continue; -- 2.45.0