From owner-svn-src-stable@freebsd.org Thu Jan 26 21:01:39 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CD061CC17C7; Thu, 26 Jan 2017 21:01:39 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 8006A1D80; Thu, 26 Jan 2017 21:01:39 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0QL1cpG006457; Thu, 26 Jan 2017 21:01:38 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0QL1cKb006456; Thu, 26 Jan 2017 21:01:38 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201701262101.v0QL1cKb006456@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 26 Jan 2017 21:01:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r312842 - stable/11/sys/cam/ctl X-SVN-Group: stable-11 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.23 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: Thu, 26 Jan 2017 21:01:39 -0000 Author: mav Date: Thu Jan 26 21:01:38 2017 New Revision: 312842 URL: https://svnweb.freebsd.org/changeset/base/312842 Log: MFC r311873: Fix malloc(M_WAITOK) under mutex, introduced at r311787. Modified: stable/11/sys/cam/ctl/ctl.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cam/ctl/ctl.c ============================================================================== --- stable/11/sys/cam/ctl/ctl.c Thu Jan 26 21:00:49 2017 (r312841) +++ stable/11/sys/cam/ctl/ctl.c Thu Jan 26 21:01:38 2017 (r312842) @@ -4593,6 +4593,8 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft printf("ctl: requested LUN ID %d is already " "in use\n", be_lun->req_lun_id); } +fail: + free(lun->lun_devid, M_CTL); if (lun->flags & CTL_LUN_MALLOCED) free(lun, M_CTL); be_lun->lun_config_status(be_lun->be_lun, @@ -4605,14 +4607,11 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft if (lun_number == -1) { mtx_unlock(&ctl_softc->ctl_lock); printf("ctl: can't allocate LUN, out of LUNs\n"); - if (lun->flags & CTL_LUN_MALLOCED) - free(lun, M_CTL); - be_lun->lun_config_status(be_lun->be_lun, - CTL_LUN_CONFIG_FAILURE); - return (ENOSPC); + goto fail; } } ctl_set_mask(ctl_softc->ctl_lun_mask, lun_number); + mtx_unlock(&ctl_softc->ctl_lock); mtx_init(&lun->lun_lock, "CTL LUN", NULL, MTX_DEF); lun->lun = lun_number; @@ -4664,22 +4663,6 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft ctl_init_page_index(lun); ctl_init_log_page_index(lun); - /* - * Now, before we insert this lun on the lun list, set the lun - * inventory changed UA for all other luns. - */ - STAILQ_FOREACH(nlun, &ctl_softc->lun_list, links) { - mtx_lock(&nlun->lun_lock); - ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE); - mtx_unlock(&nlun->lun_lock); - } - - STAILQ_INSERT_TAIL(&ctl_softc->lun_list, lun, links); - - ctl_softc->ctl_luns[lun_number] = lun; - - ctl_softc->num_luns++; - /* Setup statistics gathering */ #ifdef CTL_LEGACY_STATS lun->legacy_stats.device_type = be_lun->lun_type; @@ -4692,6 +4675,19 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft #endif /* CTL_LEGACY_STATS */ lun->stats.item = lun_number; + /* + * Now, before we insert this lun on the lun list, set the lun + * inventory changed UA for all other luns. + */ + mtx_lock(&ctl_softc->ctl_lock); + STAILQ_FOREACH(nlun, &ctl_softc->lun_list, links) { + mtx_lock(&nlun->lun_lock); + ctl_est_ua_all(nlun, -1, CTL_UA_LUN_CHANGE); + mtx_unlock(&nlun->lun_lock); + } + STAILQ_INSERT_TAIL(&ctl_softc->lun_list, lun, links); + ctl_softc->ctl_luns[lun_number] = lun; + ctl_softc->num_luns++; mtx_unlock(&ctl_softc->ctl_lock); lun->be_lun->lun_config_status(lun->be_lun->be_lun, CTL_LUN_CONFIG_OK);