From owner-svn-src-all@FreeBSD.ORG Tue Nov 4 07:44:25 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 136F39F8; Tue, 4 Nov 2014 07:44:25 +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 E823EEFE; Tue, 4 Nov 2014 07:44:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sA47iOem025027; Tue, 4 Nov 2014 07:44:24 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sA47iOkn025026; Tue, 4 Nov 2014 07:44:24 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201411040744.sA47iOkn025026@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 4 Nov 2014 07:44:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274080 - head/sys/cam/ctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Nov 2014 07:44:25 -0000 Author: mav Date: Tue Nov 4 07:44:24 2014 New Revision: 274080 URL: https://svnweb.freebsd.org/changeset/base/274080 Log: Improve error handling around duplicate lun and port enable. This fixes kernel panic if port enabled twice and then disabled. MFC after: 1 week Modified: head/sys/cam/ctl/scsi_ctl.c Modified: head/sys/cam/ctl/scsi_ctl.c ============================================================================== --- head/sys/cam/ctl/scsi_ctl.c Tue Nov 4 05:02:22 2014 (r274079) +++ head/sys/cam/ctl/scsi_ctl.c Tue Nov 4 07:44:24 2014 (r274080) @@ -1796,6 +1796,7 @@ ctlfe_online(void *arg) struct cam_path *path; cam_status status; struct ctlfe_lun_softc *lun_softc; + struct cam_periph *periph; bus_softc = (struct ctlfe_softc *)arg; @@ -1821,13 +1822,17 @@ ctlfe_online(void *arg) } xpt_path_lock(path); + periph = cam_periph_find(path, "ctl"); + if (periph != NULL) { + /* We've already got a periph, no need to alloc a new one. */ + xpt_path_unlock(path); + xpt_free_path(path); + free(lun_softc, M_CTLFE); + return; + } lun_softc->parent_softc = bus_softc; lun_softc->flags |= CTLFE_LUN_WILDCARD; - mtx_lock(&bus_softc->lun_softc_mtx); - STAILQ_INSERT_TAIL(&bus_softc->lun_softc_list, lun_softc, links); - mtx_unlock(&bus_softc->lun_softc_mtx); - status = cam_periph_alloc(ctlferegister, ctlfeoninvalidate, ctlfecleanup, @@ -1843,14 +1848,17 @@ ctlfe_online(void *arg) const struct cam_status_entry *entry; entry = cam_fetch_status_entry(status); - printf("%s: CAM error %s (%#x) returned from " "cam_periph_alloc()\n", __func__, (entry != NULL) ? entry->status_text : "Unknown", status); + free(lun_softc, M_CTLFE); + } else { + mtx_lock(&bus_softc->lun_softc_mtx); + STAILQ_INSERT_TAIL(&bus_softc->lun_softc_list, lun_softc, links); + mtx_unlock(&bus_softc->lun_softc_mtx); + ctlfe_onoffline(arg, /*online*/ 1); } - ctlfe_onoffline(arg, /*online*/ 1); - xpt_path_unlock(path); xpt_free_path(path); } @@ -1924,11 +1932,7 @@ ctlfe_lun_enable(void *arg, struct ctl_i free(softc, M_CTLFE); return (0); } - softc->parent_softc = bus_softc; - mtx_lock(&bus_softc->lun_softc_mtx); - STAILQ_INSERT_TAIL(&bus_softc->lun_softc_list, softc, links); - mtx_unlock(&bus_softc->lun_softc_mtx); status = cam_periph_alloc(ctlferegister, ctlfeoninvalidate, @@ -1941,6 +1945,21 @@ ctlfe_lun_enable(void *arg, struct ctl_i 0, softc); + if ((status & CAM_STATUS_MASK) != CAM_REQ_CMP) { + const struct cam_status_entry *entry; + + entry = cam_fetch_status_entry(status); + printf("%s: CAM error %s (%#x) returned from " + "cam_periph_alloc()\n", __func__, (entry != NULL) ? + entry->status_text : "Unknown", status); + free(softc, M_CTLFE); + } else { + mtx_lock(&bus_softc->lun_softc_mtx); + STAILQ_INSERT_TAIL(&bus_softc->lun_softc_list, softc, links); + mtx_unlock(&bus_softc->lun_softc_mtx); + ctlfe_onoffline(arg, /*online*/ 1); + } + xpt_path_unlock(path); xpt_free_path(path); return (0);