From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 22 18:59:44 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A475916A423 for ; Wed, 22 Feb 2006 18:59:44 +0000 (GMT) (envelope-from nielsen-list@memberwebs.com) Received: from mail.npubs.com (mail.zoneseven.net [209.66.100.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6CB6E43D45 for ; Wed, 22 Feb 2006 18:59:44 +0000 (GMT) (envelope-from nielsen-list@memberwebs.com) From: Nate Nielsen User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: multipart/mixed; boundary="------------040201030309000709050800" Message-Id: <20060222190919.C6B9FDCA99B@mail.npubs.com> X-Virus-Scanned: ClamAV using ClamSMTP Date: Wed, 22 Feb 2006 19:09:22 +0000 (GMT) Subject: devctl attach/detach notification for disks X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: nielsen@memberwebs.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Feb 2006 18:59:44 -0000 This is a multi-part message in MIME format. --------------040201030309000709050800 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I'm working on a bit of code to get devctl notifications for attaching and removing of disks. This would allow actions to be taken via devd when a disk is attached or removed from the system. Currently I have the attach and detach notifications hooked into disk_create() and disk_destroy() in geom_disk.c. See attached (rough) patch. However at these points the disks are not yet present in the /dev/ filesystem. Anyone have any clues or tips for a better place to hook these notifications into the system? Cheers, Nate --------------040201030309000709050800 Content-Type: text/x-patch; name="devctl-disk.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="devctl-disk.patch" Index: sys/geom/geom_disk.c =================================================================== RCS file: /home/ncvs/src/sys/geom/geom_disk.c,v retrieving revision 1.96.2.1 diff -U3 -r1.96.2.1 geom_disk.c --- sys/geom/geom_disk.c 26 Nov 2005 22:55:20 -0000 1.96.2.1 +++ sys/geom/geom_disk.c 22 Feb 2006 17:55:18 -0000 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -340,6 +341,7 @@ struct g_geom *gp; struct g_provider *pp; struct disk *dp; + char *devctl; if (flag == EV_CANCEL) return; @@ -358,6 +360,16 @@ printf("GEOM: new disk %s\n", gp->name); dp->d_geom = gp; g_error_provider(pp, 0); + + /* Send a 'added' message to devctl */ + devctl = g_malloc(512, M_NOWAIT); + if (devctl != NULL) { + snprintf(devctl, 512, + "+%s%d media-type=\"disk\" sectorsize=0x%04x mediasize=0x%04llx sectors=0x%04x heads=0x%02x\n", + dp->d_name, dp->d_unit, dp->d_sectorsize, dp->d_mediasize, dp->d_fwsectors, dp->d_fwheads); + devctl_queue_data(devctl); + g_free(devctl); + } } static void @@ -365,6 +377,7 @@ { struct disk *dp; struct g_geom *gp; + char *devctl; g_topology_assert(); dp = ptr; @@ -373,6 +386,15 @@ gp->softc = NULL; g_wither_geom(gp, ENXIO); } + + /* Send a 'removed' message to devctl */ + devctl = g_malloc(128, M_NOWAIT); + if (devctl != NULL) { + snprintf(devctl, 128, "-%s%d media-type=\"disk\"", dp->d_name, dp->d_unit); + devctl_queue_data(devctl); + g_free(devctl); + } + g_free(dp); } Index: sys/sys/bus.h =================================================================== RCS file: /home/ncvs/src/sys/sys/bus.h,v retrieving revision 1.70 diff -U3 -r1.70 bus.h --- sys/sys/bus.h 12 Apr 2005 15:20:36 -0000 1.70 +++ sys/sys/bus.h 22 Feb 2006 17:55:19 -0000 @@ -83,7 +83,7 @@ */ void devctl_notify(const char *__system, const char *__subsystem, const char *__type, const char *__data); -void devctl_queue_data(char *__data); +void devctl_queue_data(const char *__data); /* * Forward declarations Index: sys/kern/subr_bus.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_bus.c,v retrieving revision 1.184.2.1 diff -U3 -r1.184.2.1 subr_bus.c --- sys/kern/subr_bus.c 6 Oct 2005 23:15:18 -0000 1.184.2.1 +++ sys/kern/subr_bus.c 22 Feb 2006 17:55:22 -0000 @@ -497,15 +497,8 @@ return (revents); } -/** - * @brief Queue data to be read from the devctl device - * - * Generic interface to queue data to the devctl device. It is - * assumed that @p data is properly formatted. It is further assumed - * that @p data is allocated using the M_BUS malloc type. - */ -void -devctl_queue_data(char *data) +static void +devqdata(char *data) { struct dev_event_info *n1 = NULL; struct proc *p; @@ -528,6 +521,26 @@ } /** + * @brief Queue data to be read from the devctl device + * + * Generic interface to queue data to the devctl device. It is + * assumed that @p data is properly formatted. + */ +void +devctl_queue_data(const char *data) +{ + int len; + char *msg; + + len = strlen(data) + 1; + msg = malloc(len, M_BUS, M_NOWAIT); + if (msg == NULL) + return; + strcpy(msg, data); + devqdata(msg); +} + +/** * @brief Send a 'notification' to userland, using standard ways */ void --------------040201030309000709050800--