From owner-svn-src-projects@FreeBSD.ORG Tue Apr 16 08:49:28 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C85B75DB; Tue, 16 Apr 2013 08:49:28 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id A1B738B1; Tue, 16 Apr 2013 08:49:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3G8nStR073333; Tue, 16 Apr 2013 08:49:28 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3G8nSGn073332; Tue, 16 Apr 2013 08:49:28 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201304160849.r3G8nSGn073332@svn.freebsd.org> From: Alexander Motin Date: Tue, 16 Apr 2013 08:49:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r249541 - projects/camlock/sys/cam X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Apr 2013 08:49:28 -0000 Author: mav Date: Tue Apr 16 08:49:27 2013 New Revision: 249541 URL: http://svnweb.freebsd.org/changeset/base/249541 Log: Give periph validity flag own periph reference. That slightly simplifies the release logic and covers hypothetical case if lock is dropped inside the periph_oninval() method. Modified: projects/camlock/sys/cam/cam_periph.c Modified: projects/camlock/sys/cam/cam_periph.c ============================================================================== --- projects/camlock/sys/cam/cam_periph.c Tue Apr 16 07:48:49 2013 (r249540) +++ projects/camlock/sys/cam/cam_periph.c Tue Apr 16 08:49:27 2013 (r249541) @@ -202,7 +202,7 @@ cam_periph_alloc(periph_ctor_t *periph_c periph->periph_oninval = periph_oninvalidate; periph->type = type; periph->periph_name = name; - periph->refcount = 0; + periph->refcount = 1; /* Dropped by invalidation. */ periph->sim = sim; mtx_init(&periph->periph_mtx, "CAM periph lock", NULL, MTX_DEF); status = xpt_create_path(&path, periph, path_id, target_id, lun_id); @@ -380,10 +380,8 @@ cam_periph_release_locked_buses(struct c mtx_assert(periph->sim->mtx, MA_OWNED); KASSERT(periph->refcount >= 1, ("periph->refcount >= 1")); - if (--periph->refcount == 0 - && (periph->flags & CAM_PERIPH_INVALID)) { + if (--periph->refcount == 0) camperiphfree(periph); - } } void @@ -578,23 +576,20 @@ void cam_periph_invalidate(struct cam_periph *periph) { - CAM_DEBUG(periph->path, CAM_DEBUG_INFO, ("Periph invalidated\n")); mtx_assert(periph->sim->mtx, MA_OWNED); /* * We only call this routine the first time a peripheral is * invalidated. */ - if (((periph->flags & CAM_PERIPH_INVALID) == 0) - && (periph->periph_oninval != NULL)) - periph->periph_oninval(periph); + if ((periph->flags & CAM_PERIPH_INVALID) != 0) + return; + CAM_DEBUG(periph->path, CAM_DEBUG_INFO, ("Periph invalidated\n")); periph->flags |= CAM_PERIPH_INVALID; periph->flags &= ~CAM_PERIPH_NEW_DEV_FOUND; - - xpt_lock_buses(); - if (periph->refcount == 0) - camperiphfree(periph); - xpt_unlock_buses(); + if (periph->periph_oninval != NULL) + periph->periph_oninval(periph); + cam_periph_release_locked(periph); } static void