From owner-svn-src-stable@FreeBSD.ORG Mon Oct 20 07:38:37 2014 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 18730856; Mon, 20 Oct 2014 07:38:37 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 038788F4; Mon, 20 Oct 2014 07:38:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9K7caVT074671; Mon, 20 Oct 2014 07:38:36 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9K7caw8074669; Mon, 20 Oct 2014 07:38:36 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201410200738.s9K7caw8074669@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 20 Oct 2014 07:38:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r273314 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Oct 2014 07:38:37 -0000 Author: mav Date: Mon Oct 20 07:38:36 2014 New Revision: 273314 URL: https://svnweb.freebsd.org/changeset/base/273314 Log: MFC r272893: Store persistent reservation keys as uint64_t instead of uint8_t[8]. This allows to simplify the code and save 512KB of RAM per LUN (8%) by removing no longer needed "registered" keys flags. Modified: stable/10/sys/cam/ctl/ctl.c stable/10/sys/cam/ctl/ctl_private.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Mon Oct 20 07:35:46 2014 (r273313) +++ stable/10/sys/cam/ctl/ctl.c Mon Oct 20 07:38:36 2014 (r273314) @@ -2992,12 +2992,11 @@ ctl_ioctl(struct cdev *dev, u_long cmd, for (j = 0; j < (CTL_MAX_PORTS * 2); j++) { for (k = 0; k < CTL_MAX_INIT_PER_PORT; k++){ idx = j * CTL_MAX_INIT_PER_PORT + k; - if (lun->per_res[idx].registered == 0) + if (lun->pr_keys[idx] == 0) continue; printf(" LUN %d port %d iid %d key " "%#jx\n", i, j, k, - (uintmax_t)scsi_8btou64( - lun->per_res[idx].res_key.key)); + (uintmax_t)lun->pr_keys[idx]); } } } @@ -5538,7 +5537,7 @@ ctl_start_stop(struct ctl_scsiio *ctsio) uint32_t residx; residx = ctl_get_resindex(&ctsio->io_hdr.nexus); - if (!lun->per_res[residx].registered + if (lun->pr_keys[residx] == 0 || (lun->pr_res_idx!=residx && lun->res_type < 4)) { ctl_set_reservation_conflict(ctsio); @@ -5829,7 +5828,7 @@ ctl_read_buffer(struct ctl_scsiio *ctsio && residx != lun->pr_res_idx) || ((lun->res_type == SPR_TYPE_EX_AC_RO || lun->res_type == SPR_TYPE_EX_AC_AR) - && !lun->per_res[residx].registered)) { + && lun->pr_keys[residx] == 0)) { ctl_set_reservation_conflict(ctsio); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); @@ -6884,7 +6883,7 @@ ctl_mode_sense(struct ctl_scsiio *ctsio) && residx != lun->pr_res_idx) || ((lun->res_type == SPR_TYPE_EX_AC_RO || lun->res_type == SPR_TYPE_EX_AC_AR) - && !lun->per_res[residx].registered)) { + && lun->pr_keys[residx] == 0)) { ctl_set_reservation_conflict(ctsio); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); @@ -7827,7 +7826,7 @@ retry: lun->pr_key_count, res_keys->header.length); for (i = 0, key_count = 0; i < 2*CTL_MAX_INITIATORS; i++) { - if (!lun->per_res[i].registered) + if (lun->pr_keys[i] == 0) continue; /* @@ -7853,10 +7852,8 @@ retry: key_count++; continue; } - memcpy(res_keys->keys[key_count].key, - lun->per_res[i].res_key.key, - ctl_min(sizeof(res_keys->keys[key_count].key), - sizeof(lun->per_res[i].res_key))); + scsi_u64to8b(lun->pr_keys[i], + res_keys->keys[key_count].key); key_count++; } break; @@ -7907,9 +7904,8 @@ retry: * is 0, since it doesn't really matter. */ if (lun->pr_res_idx != CTL_PR_ALL_REGISTRANTS) { - memcpy(res->data.reservation, - &lun->per_res[lun->pr_res_idx].res_key, - sizeof(struct scsi_per_res_key)); + scsi_u64to8b(lun->pr_keys[lun->pr_res_idx], + res->data.reservation); } res->data.scopetype = lun->res_type; break; @@ -7960,11 +7956,10 @@ retry: res_desc = &res_status->desc[0]; for (i = 0; i < 2*CTL_MAX_INITIATORS; i++) { - if (!lun->per_res[i].registered) + if (lun->pr_keys[i] == 0) continue; - memcpy(&res_desc->res_key, &lun->per_res[i].res_key.key, - sizeof(res_desc->res_key)); + scsi_u64to8b(lun->pr_keys[i], res_desc->res_key.key); if ((lun->flags & CTL_LUN_PR_RESERVED) && (lun->pr_res_idx == i || lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS)) { @@ -8057,15 +8052,12 @@ ctl_pro_preempt(struct ctl_softc *softc, return (1); } - /* temporarily unregister this nexus */ - lun->per_res[residx].registered = 0; - /* * Unregister everybody else and build UA for * them */ for(i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered == 0) + if (i == residx || lun->pr_keys[i] == 0) continue; if (!persis_offset @@ -8076,11 +8068,8 @@ ctl_pro_preempt(struct ctl_softc *softc, && i >= persis_offset) lun->pending_ua[i-persis_offset] |= CTL_UA_REG_PREEMPT; - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + lun->pr_keys[i] = 0; } - lun->per_res[residx].registered = 1; lun->pr_key_count = 1; lun->res_type = type; if (lun->res_type != SPR_TYPE_WR_EX_AR @@ -8144,16 +8133,11 @@ ctl_pro_preempt(struct ctl_softc *softc, } for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered - && memcmp(param->serv_act_res_key, - lun->per_res[i].res_key.key, - sizeof(struct scsi_per_res_key)) != 0) + if (lun->pr_keys[i] != sa_res_key) continue; found = 1; - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + lun->pr_keys[i] = 0; lun->pr_key_count--; if (!persis_offset && i < CTL_MAX_INITIATORS) @@ -8187,9 +8171,7 @@ ctl_pro_preempt(struct ctl_softc *softc, } else { /* Reserved but not all registrants */ /* sa_res_key is res holder */ - if (memcmp(param->serv_act_res_key, - lun->per_res[lun->pr_res_idx].res_key.key, - sizeof(struct scsi_per_res_key)) == 0) { + if (sa_res_key == lun->pr_keys[lun->pr_res_idx]) { /* validate scope and type */ if ((cdb->scope_type & SPR_SCOPE_MASK) != SPR_LU_SCOPE) { @@ -8230,22 +8212,12 @@ ctl_pro_preempt(struct ctl_softc *softc, * except don't unregister the res holder. */ - /* - * Temporarily unregister so it won't get - * removed or UA generated - */ - lun->per_res[residx].registered = 0; for(i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered == 0) + if (i == residx || lun->pr_keys[i] == 0) continue; - if (memcmp(param->serv_act_res_key, - lun->per_res[i].res_key.key, - sizeof(struct scsi_per_res_key)) == 0) { - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, - 0, - sizeof(struct scsi_per_res_key)); + if (sa_res_key == lun->pr_keys[i]) { + lun->pr_keys[i] = 0; lun->pr_key_count--; if (!persis_offset @@ -8270,7 +8242,6 @@ ctl_pro_preempt(struct ctl_softc *softc, CTL_UA_RES_RELEASE; } } - lun->per_res[residx].registered = 1; lun->res_type = type; if (lun->res_type != SPR_TYPE_WR_EX_AR && lun->res_type != SPR_TYPE_EX_AC_AR) @@ -8301,15 +8272,11 @@ ctl_pro_preempt(struct ctl_softc *softc, int found=0; for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (memcmp(param->serv_act_res_key, - lun->per_res[i].res_key.key, - sizeof(struct scsi_per_res_key)) != 0) + if (sa_res_key != lun->pr_keys[i]) continue; found = 1; - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + lun->pr_keys[i] = 0; lun->pr_key_count--; if (!persis_offset @@ -8356,26 +8323,22 @@ ctl_pro_preempt(struct ctl_softc *softc, static void ctl_pro_preempt_other(struct ctl_lun *lun, union ctl_ha_msg *msg) { + uint64_t sa_res_key; int i; + sa_res_key = scsi_8btou64(msg->pr.pr_info.sa_res_key); + if (lun->pr_res_idx == CTL_PR_ALL_REGISTRANTS || lun->pr_res_idx == CTL_PR_NO_RESERVATION - || memcmp(&lun->per_res[lun->pr_res_idx].res_key, - msg->pr.pr_info.sa_res_key, - sizeof(struct scsi_per_res_key)) != 0) { - uint64_t sa_res_key; - sa_res_key = scsi_8btou64(msg->pr.pr_info.sa_res_key); - + || sa_res_key != lun->pr_keys[lun->pr_res_idx]) { if (sa_res_key == 0) { - /* temporarily unregister this nexus */ - lun->per_res[msg->pr.pr_info.residx].registered = 0; - /* * Unregister everybody else and build UA for * them */ for(i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered == 0) + if (i == msg->pr.pr_info.residx || + lun->pr_keys[i] == 0) continue; if (!persis_offset @@ -8385,12 +8348,9 @@ ctl_pro_preempt_other(struct ctl_lun *lu else if (persis_offset && i >= persis_offset) lun->pending_ua[i - persis_offset] |= CTL_UA_REG_PREEMPT; - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + lun->pr_keys[i] = 0; } - lun->per_res[msg->pr.pr_info.residx].registered = 1; lun->pr_key_count = 1; lun->res_type = msg->pr.pr_info.res_type; if (lun->res_type != SPR_TYPE_WR_EX_AR @@ -8398,14 +8358,10 @@ ctl_pro_preempt_other(struct ctl_lun *lu lun->pr_res_idx = msg->pr.pr_info.residx; } else { for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (memcmp(msg->pr.pr_info.sa_res_key, - lun->per_res[i].res_key.key, - sizeof(struct scsi_per_res_key)) != 0) + if (sa_res_key == lun->pr_keys[i]) continue; - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + lun->pr_keys[i] = 0; lun->pr_key_count--; if (!persis_offset @@ -8419,21 +8375,13 @@ ctl_pro_preempt_other(struct ctl_lun *lu } } } else { - /* - * Temporarily unregister so it won't get removed - * or UA generated - */ - lun->per_res[msg->pr.pr_info.residx].registered = 0; for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered == 0) + if (i == msg->pr.pr_info.residx || + lun->pr_keys[i] == 0) continue; - if (memcmp(msg->pr.pr_info.sa_res_key, - lun->per_res[i].res_key.key, - sizeof(struct scsi_per_res_key)) == 0) { - lun->per_res[i].registered = 0; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); + if (sa_res_key == lun->pr_keys[i]) { + lun->pr_keys[i] = 0; lun->pr_key_count--; if (!persis_offset && i < CTL_MAX_INITIATORS) @@ -8456,7 +8404,6 @@ ctl_pro_preempt_other(struct ctl_lun *lu CTL_UA_RES_RELEASE; } } - lun->per_res[msg->pr.pr_info.residx].registered = 1; lun->res_type = msg->pr.pr_info.res_type; if (lun->res_type != SPR_TYPE_WR_EX_AR && lun->res_type != SPR_TYPE_EX_AC_AR) @@ -8554,11 +8501,8 @@ ctl_persistent_reserve_out(struct ctl_sc */ if ((cdb->action & SPRO_ACTION_MASK) != SPRO_REG_IGNO) { mtx_lock(&lun->lun_lock); - if (lun->per_res[residx].registered) { - if (memcmp(param->res_key.key, - lun->per_res[residx].res_key.key, - ctl_min(sizeof(param->res_key), - sizeof(lun->per_res[residx].res_key))) != 0) { + if (lun->pr_keys[residx] != 0) { + if (res_key != lun->pr_keys[residx]) { /* * The current key passed in doesn't match * the one the initiator previously @@ -8639,14 +8583,12 @@ ctl_persistent_reserve_out(struct ctl_sc if ((res_key == 0 && (cdb->action & SPRO_ACTION_MASK) == SPRO_REGISTER) || ((cdb->action & SPRO_ACTION_MASK) == SPRO_REG_IGNO - && !lun->per_res[residx].registered)) { + && lun->pr_keys[residx] == 0)) { mtx_unlock(&lun->lun_lock); goto done; } - lun->per_res[residx].registered = 0; - memset(&lun->per_res[residx].res_key, - 0, sizeof(lun->per_res[residx].res_key)); + lun->pr_keys[residx] = 0; lun->pr_key_count--; if (residx == lun->pr_res_idx) { @@ -8665,9 +8607,8 @@ ctl_persistent_reserve_out(struct ctl_sc */ for (i = 0; i < CTL_MAX_INITIATORS;i++){ - if (lun->per_res[ - i+persis_offset].registered - == 0) + if (lun->pr_keys[ + i + persis_offset] == 0) continue; lun->pending_ua[i] |= CTL_UA_RES_RELEASE; @@ -8697,15 +8638,9 @@ ctl_persistent_reserve_out(struct ctl_sc * If we aren't registered currently then increment * the key count and set the registered flag. */ - if (!lun->per_res[residx].registered) { + if (lun->pr_keys[residx] == 0) lun->pr_key_count++; - lun->per_res[residx].registered = 1; - } - - memcpy(&lun->per_res[residx].res_key, - param->serv_act_res_key, - ctl_min(sizeof(param->serv_act_res_key), - sizeof(lun->per_res[residx].res_key))); + lun->pr_keys[residx] = sa_res_key; persis_io.hdr.nexus = ctsio->io_hdr.nexus; persis_io.hdr.msg_type = CTL_MSG_PERS_ACTION; @@ -8818,20 +8753,12 @@ ctl_persistent_reserve_out(struct ctl_sc */ if (type != SPR_TYPE_EX_AC && type != SPR_TYPE_WR_EX) { - /* - * temporarily unregister so we don't generate UA - */ - lun->per_res[residx].registered = 0; - for (i = 0; i < CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i+persis_offset].registered - == 0) + if (i == residx || + lun->pr_keys[i + persis_offset] == 0) continue; - lun->pending_ua[i] |= - CTL_UA_RES_RELEASE; + lun->pending_ua[i] |= CTL_UA_RES_RELEASE; } - - lun->per_res[residx].registered = 1; } mtx_unlock(&lun->lun_lock); /* Send msg to other side */ @@ -8854,13 +8781,10 @@ ctl_persistent_reserve_out(struct ctl_sc lun->pr_key_count = 0; lun->pr_res_idx = CTL_PR_NO_RESERVATION; - - memset(&lun->per_res[residx].res_key, - 0, sizeof(lun->per_res[residx].res_key)); - lun->per_res[residx].registered = 0; + lun->pr_keys[residx] = 0; for (i=0; i < 2*CTL_MAX_INITIATORS; i++) - if (lun->per_res[i].registered) { + if (lun->pr_keys[i] != 0) { if (!persis_offset && i < CTL_MAX_INITIATORS) lun->pending_ua[i] |= CTL_UA_RES_PREEMPT; @@ -8868,9 +8792,7 @@ ctl_persistent_reserve_out(struct ctl_sc lun->pending_ua[i-persis_offset] |= CTL_UA_RES_PREEMPT; - memset(&lun->per_res[i].res_key, - 0, sizeof(struct scsi_per_res_key)); - lun->per_res[i].registered = 0; + lun->pr_keys[i] = 0; } lun->PRGeneration++; mtx_unlock(&lun->lun_lock); @@ -8926,20 +8848,15 @@ ctl_hndl_per_res_out_on_other_sc(union c mtx_lock(&lun->lun_lock); switch(msg->pr.pr_info.action) { case CTL_PR_REG_KEY: - if (!lun->per_res[msg->pr.pr_info.residx].registered) { - lun->per_res[msg->pr.pr_info.residx].registered = 1; + if (lun->pr_keys[msg->pr.pr_info.residx] == 0) lun->pr_key_count++; - } + lun->pr_keys[msg->pr.pr_info.residx] = + scsi_8btou64(msg->pr.pr_info.sa_res_key); lun->PRGeneration++; - memcpy(&lun->per_res[msg->pr.pr_info.residx].res_key, - msg->pr.pr_info.sa_res_key, - sizeof(struct scsi_per_res_key)); break; case CTL_PR_UNREG_KEY: - lun->per_res[msg->pr.pr_info.residx].registered = 0; - memset(&lun->per_res[msg->pr.pr_info.residx].res_key, - 0, sizeof(struct scsi_per_res_key)); + lun->pr_keys[msg->pr.pr_info.residx] = 0; lun->pr_key_count--; /* XXX Need to see if the reservation has been released */ @@ -8960,8 +8877,8 @@ ctl_hndl_per_res_out_on_other_sc(union c */ for (i = 0; i < CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i+ - persis_offset].registered == 0) + if (lun->pr_keys[i+ + persis_offset] == 0) continue; lun->pending_ua[i] |= @@ -8994,7 +8911,7 @@ ctl_hndl_per_res_out_on_other_sc(union c if (lun->res_type != SPR_TYPE_EX_AC && lun->res_type != SPR_TYPE_WR_EX) { for (i = 0; i < CTL_MAX_INITIATORS; i++) - if (lun->per_res[i+persis_offset].registered) + if (lun->pr_keys[i+persis_offset] != 0) lun->pending_ua[i] |= CTL_UA_RES_RELEASE; } @@ -9014,7 +8931,7 @@ ctl_hndl_per_res_out_on_other_sc(union c lun->pr_res_idx = CTL_PR_NO_RESERVATION; for (i=0; i < 2*CTL_MAX_INITIATORS; i++) { - if (lun->per_res[i].registered == 0) + if (lun->pr_keys[i] == 0) continue; if (!persis_offset && i < CTL_MAX_INITIATORS) @@ -9023,9 +8940,7 @@ ctl_hndl_per_res_out_on_other_sc(union c && i >= persis_offset) lun->pending_ua[i-persis_offset] |= CTL_UA_RES_PREEMPT; - memset(&lun->per_res[i].res_key, 0, - sizeof(struct scsi_per_res_key)); - lun->per_res[i].registered = 0; + lun->pr_keys[i] = 0; } lun->PRGeneration++; break; @@ -9064,7 +8979,7 @@ ctl_read_write(struct ctl_scsiio *ctsio) && residx != lun->pr_res_idx) || ((lun->res_type == SPR_TYPE_EX_AC_RO || lun->res_type == SPR_TYPE_EX_AC_AR) - && !lun->per_res[residx].registered)) { + && lun->pr_keys[residx] == 0)) { ctl_set_reservation_conflict(ctsio); ctl_done((union ctl_io *)ctsio); return (CTL_RETVAL_COMPLETE); @@ -11381,7 +11296,7 @@ ctl_scsiio_lun_check(struct ctl_softc *c * type reservations are checked in the particular command * for a conflict. Read and SSU are the only ones. */ - if (!lun->per_res[residx].registered + if (lun->pr_keys[residx] == 0 || (residx != lun->pr_res_idx && lun->res_type < 4)) { ctsio->scsi_status = SCSI_STATUS_RESERV_CONFLICT; ctsio->io_hdr.status = CTL_SCSI_ERROR; Modified: stable/10/sys/cam/ctl/ctl_private.h ============================================================================== --- stable/10/sys/cam/ctl/ctl_private.h Mon Oct 20 07:35:46 2014 (r273313) +++ stable/10/sys/cam/ctl/ctl_private.h Mon Oct 20 07:38:36 2014 (r273314) @@ -353,11 +353,6 @@ typedef enum { CTL_PR_FLAG_ACTIVE_RES = 0x02 } ctl_per_res_flags; -struct ctl_per_res_info { - struct scsi_per_res_key res_key; - uint8_t registered; -}; - #define CTL_PR_ALL_REGISTRANTS 0xFFFFFFFF #define CTL_PR_NO_RESERVATION 0xFFFFFFF0 @@ -398,8 +393,8 @@ struct ctl_lun { struct ctl_mode_pages mode_pages; struct ctl_lun_io_stats stats; uint32_t res_idx; - struct ctl_per_res_info per_res[2*CTL_MAX_INITIATORS]; unsigned int PRGeneration; + uint64_t pr_keys[2*CTL_MAX_INITIATORS]; int pr_key_count; uint32_t pr_res_idx; uint8_t res_type;