Date: Wed, 22 Feb 2006 19:09:22 +0000 (GMT) From: Nate Nielsen <nielsen-list@memberwebs.com> To: freebsd-hackers@freebsd.org Subject: devctl attach/detach notification for disks Message-ID: <20060222190919.C6B9FDCA99B@mail.npubs.com>
next in thread | raw e-mail | index | archive | help
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 <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
+#include <sys/bus.h>
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
@@ -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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060222190919.C6B9FDCA99B>
