devctl (alike?) for devfs

Andriy Gapon avg at icyb.net.ua
Sun May 11 20:50:34 UTC 2008


Kostik, John, Warner,

thank you for your guidance and suggestions.
I am currently testing the patch attached and I am using a kernel with 
WITNESS and INVARIANTS enabled.
Scope of my testing is plugging/unplugging of UMASS devices.
I get CREATE notifications all right.
I do not get any panics/complaints from the kernel, good.
Unfortunately I do not get any DESTROY notifications either.

Could you please look through the patch? Is there any control flow path 
that I missed or something even more obvious?
I hope that we do not have any cdev leaks.

I am testing the patch with RELENG_7 as of May 6.

-- 
Andriy Gapon
-------------- next part --------------
diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c
index 1db25f8..0245253 100644
--- a/sys/kern/kern_conf.c
+++ b/sys/kern/kern_conf.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
+#include <sys/bus.h>
 #include <sys/bio.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
@@ -99,6 +100,9 @@ dev_unlock_and_free(void)
 	mtx_unlock(&devmtx);
 
 	while ((cdp = TAILQ_FIRST(&cdp_free)) != NULL) {
+		if (!cold)
+			devctl_notify("DEVFS", cdp->cdp_c.si_name, "DESTROY", NULL);
+
 		TAILQ_REMOVE(&cdp_free, cdp, cdp_list);
 		devfs_free(&cdp->cdp_c);
 	}
@@ -172,8 +176,12 @@ dev_rel(struct cdev *dev)
 		flag = 1;
 	}
 	dev_unlock();
-	if (flag)
+	if (flag) {
+		if (!cold)
+			devctl_notify("DEVFS", dev->si_name, "DESTROY", NULL);
+
 		devfs_free(dev);
+	}
 }
 
 struct cdevsw *
@@ -706,6 +714,10 @@ make_dev_credv(int flags, struct cdevsw *devsw, int minornr,
 	devfs_create(dev);
 	clean_unrhdrl(devfs_inos);
 	dev_unlock_and_free();
+
+	if (!cold)
+		devctl_notify("DEVFS", dev->si_name, "CREATE", NULL);
+
 	return (dev);
 }
 
@@ -794,6 +806,10 @@ make_dev_alias(struct cdev *pdev, const char *fmt, ...)
 	clean_unrhdrl(devfs_inos);
 	dev_unlock();
 	dev_depends(pdev, dev);
+
+	if (!cold)
+		devctl_notify("DEVFS", dev->si_name, "CREATE", NULL);
+
 	return (dev);
 }
 


More information about the freebsd-hackers mailing list