Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Mar 2015 13:08:58 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r280586 - stable/8/sys/kern
Message-ID:  <201503251308.t2PD8wEm065217@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Mar 25 13:08:57 2015
New Revision: 280586
URL: https://svnweb.freebsd.org/changeset/base/280586

Log:
  MFC r280345:
  Fix for out of order device destruction notifications when using the
  delist_dev() function. In addition to this change:
  - add a proper description of this function
  - add a proper witness assert inside this function
  - switch a nearby line to use the "cdp" pointer instead of cdev2priv()

Modified:
  stable/8/sys/kern/kern_conf.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/kern/   (props changed)

Modified: stable/8/sys/kern/kern_conf.c
==============================================================================
--- stable/8/sys/kern/kern_conf.c	Wed Mar 25 13:06:37 2015	(r280585)
+++ stable/8/sys/kern/kern_conf.c	Wed Mar 25 13:08:57 2015	(r280586)
@@ -929,9 +929,12 @@ destroy_devl(struct cdev *dev)
 	}
 
 	dev_unlock();
-	notify_destroy(dev);
+	if ((cdp->cdp_flags & CDP_UNREF_DTR) == 0) {
+		/* avoid out of order notify events */
+		notify_destroy(dev);
+	}
 	mtx_lock(&cdevpriv_mtx);
-	while ((p = LIST_FIRST(&cdev2priv(dev)->cdp_fdpriv)) != NULL) {
+	while ((p = LIST_FIRST(&cdp->cdp_fdpriv)) != NULL) {
 		devfs_destroy_cdevpriv(p);
 		mtx_lock(&cdevpriv_mtx);
 	}
@@ -977,12 +980,25 @@ delist_dev_locked(struct cdev *dev)
 	devfs_destroy(dev);
 	LIST_FOREACH(child, &dev->si_children, si_siblings)
 		delist_dev_locked(child);
+	dev_unlock();	
+	/* ensure the destroy event is queued in order */
+	notify_destroy(dev);
+	dev_lock();
 }
 
+/*
+ * This function will delist a character device and its children from
+ * the directory listing and create a destroy event without waiting
+ * for all character device references to go away. At some later point
+ * destroy_dev() must be called to complete the character device
+ * destruction. After calling this function the character device name
+ * can instantly be re-used.
+ */
 void
 delist_dev(struct cdev *dev)
 {
 
+	WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "delist_dev");
 	dev_lock();
 	delist_dev_locked(dev);
 	dev_unlock();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503251308.t2PD8wEm065217>