Date: Wed, 14 May 2008 15:19:20 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Andriy Gapon <avg@icyb.net.ua> Cc: freebsd-hackers@freebsd.org Subject: Re: devctl (alike?) for devfs Message-ID: <20080514121920.GR18958@deviant.kiev.zoral.com.ua> In-Reply-To: <4829FCB5.8030308@icyb.net.ua> References: <200804240811.26183.jhb@freebsd.org> <4810FD1E.70602@icyb.net.ua> <20080425095009.GD18958@deviant.kiev.zoral.com.ua> <4811E6BC.4060306@icyb.net.ua> <20080425143646.GF18958@deviant.kiev.zoral.com.ua> <48275C0C.2040601@icyb.net.ua> <20080511214833.GB18958@deviant.kiev.zoral.com.ua> <4829E658.3000605@icyb.net.ua> <20080513191610.GK18958@deviant.kiev.zoral.com.ua> <4829FCB5.8030308@icyb.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--XESQGuwklioZw9MS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 13, 2008 at 11:40:21PM +0300, Andriy Gapon wrote: > on 13/05/2008 22:16 Kostik Belousov said the following: > >I looked at your previous patch, and it seems it is much simpler to > >do drop the devmtx once more then to try to abuse free lists. > >In the destroy_devl(), after the=20 > > > > while (dev->si_threadcount !=3D 0) { > > /* Use unique dummy wait ident */ > > msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10); > > } > > > >loop, add > > > > mtx_unlock(&devmtx); > > if (!cold) > > devctl_notify("DEVFS", dev->si_name, "DESTROY", NULL); > > mtx_lock(&devmtx); >=20 > Thank you again! This is simply perfect. >=20 >=20 > --=20 > Andriy Gapon > diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c > index 1db25f8..f90e469 100644 I do not like abusing the subsystem to communicate the data. What about this instead ? The created/destroyed cdev name is available in the $cdev variable, example clause for devd.conf looks like this: notify 1000 { system "DEVFS"; subsystem "CDEV"; action "echo $type $cdev >/dev/console"; }; diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index e911913..a5ed25c 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD: src/sys/kern/kern_conf.c,v 1.211 2008= /04/02 11:11:58 kib Exp #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> @@ -526,6 +527,37 @@ unit2minor(int unit) return ((unit & 0xff) | ((unit << 8) & ~0xffff)); } =20 +static void +notify(struct cdev *dev, const char *ev) +{ + static const char prefix[] =3D "cdev=3D"; + char *data; + int namelen; + + if (cold) + return; + namelen =3D strlen(dev->si_name); + data =3D malloc(namelen + sizeof(prefix), M_TEMP, M_WAITOK); + memcpy(data, prefix, sizeof(prefix) - 1); + memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen + 1); + devctl_notify("DEVFS", "CDEV", ev, data); + free(data, M_TEMP); +} + +static void +notify_create(struct cdev *dev) +{ + + notify(dev, "CREATE"); +} + +static void +notify_destroy(struct cdev *dev) +{ + + notify(dev, "DESTROY"); +} + static struct cdev * newdev(struct cdevsw *csw, int y, struct cdev *si) { @@ -706,6 +738,9 @@ make_dev_credv(int flags, struct cdevsw *devsw, int min= ornr, devfs_create(dev); clean_unrhdrl(devfs_inos); dev_unlock_and_free(); + + notify_create(dev); + return (dev); } =20 @@ -794,6 +829,9 @@ make_dev_alias(struct cdev *pdev, const char *fmt, ...) clean_unrhdrl(devfs_inos); dev_unlock(); dev_depends(pdev, dev); + + notify_create(dev); + return (dev); } =20 @@ -842,6 +880,10 @@ destroy_devl(struct cdev *dev) msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10); } =20 + mtx_unlock(&devmtx); + notify_destroy(dev); + mtx_lock(&devmtx); + dev->si_drv1 =3D 0; dev->si_drv2 =3D 0; bzero(&dev->__si_u, sizeof(dev->__si_u)); --XESQGuwklioZw9MS Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkgq2McACgkQC3+MBN1Mb4jx6gCgvO+ewO5SxOPPRpObZaAMUnM6 xF8An0AMuUWcaK1acNS353GEqIv2KpMc =oGoZ -----END PGP SIGNATURE----- --XESQGuwklioZw9MS--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080514121920.GR18958>