From owner-freebsd-hackers@FreeBSD.ORG Wed May 14 13:19:10 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88645106564A; Wed, 14 May 2008 13:19:10 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from falcon.cybervisiontech.com (falcon.cybervisiontech.com [217.20.163.9]) by mx1.freebsd.org (Postfix) with ESMTP id EE90D8FC14; Wed, 14 May 2008 13:19:09 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from localhost (localhost [127.0.0.1]) by falcon.cybervisiontech.com (Postfix) with ESMTP id 6D4D243F80C; Wed, 14 May 2008 16:19:07 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at falcon.cybervisiontech.com Received: from falcon.cybervisiontech.com ([127.0.0.1]) by localhost (falcon.cybervisiontech.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id un0XGVnckL8X; Wed, 14 May 2008 16:19:07 +0300 (EEST) Received: from [10.2.1.87] (gateway.cybervisiontech.com.ua [88.81.251.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by falcon.cybervisiontech.com (Postfix) with ESMTP id 8874143E725; Wed, 14 May 2008 16:19:06 +0300 (EEST) Message-ID: <482AE6C9.7090505@icyb.net.ua> Date: Wed, 14 May 2008 16:19:05 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.12 (X11/20080311) MIME-Version: 1.0 To: Kostik Belousov 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> <20080514121920.GR18958@deviant.kiev.zoral.com.ua> In-Reply-To: <20080514121920.GR18958@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=KOI8-U Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: devctl (alike?) for devfs X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 May 2008 13:19:10 -0000 on 14/05/2008 15:19 Kostik Belousov said the following: > 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 >>> >>> while (dev->si_threadcount != 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); >> Thank you again! This is simply perfect. >> >> >> -- >> 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: Kostik, I do not have a strong opinion on the exact format of notification. Your code definitely looks cleaner and friendlier, so I am all for it. P.S. the only non-obvious thing in "strcat-ing" is that space for '\0' is accounted for in sizeof(prefix) whereas actual '\0' is copied from si_name. > 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 > #include > #include > +#include > #include > #include > #include > @@ -526,6 +527,37 @@ unit2minor(int unit) > return ((unit & 0xff) | ((unit << 8) & ~0xffff)); > } > > +static void > +notify(struct cdev *dev, const char *ev) > +{ > + static const char prefix[] = "cdev="; > + char *data; > + int namelen; > + > + if (cold) > + return; > + namelen = strlen(dev->si_name); > + data = 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 minornr, > devfs_create(dev); > clean_unrhdrl(devfs_inos); > dev_unlock_and_free(); > + > + notify_create(dev); > + > return (dev); > } > > @@ -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); > } > > @@ -842,6 +880,10 @@ destroy_devl(struct cdev *dev) > msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10); > } > > + mtx_unlock(&devmtx); > + notify_destroy(dev); > + mtx_lock(&devmtx); > + > dev->si_drv1 = 0; > dev->si_drv2 = 0; > bzero(&dev->__si_u, sizeof(dev->__si_u)); -- Andriy Gapon