From e3bf5370354c3268d7e4cdd77dd31c384f8a7e10 Mon Sep 17 00:00:00 2001 From: Alexander Polakov Date: Thu, 3 Dec 2009 00:46:16 +0300 Subject: [PATCH] Pass hotplug_device, not cdev_t. Suggested-by: alexh@ --- sys/dev/misc/hotplug/hotplug.c | 28 +++++++++++++------------- sys/sys/hotplug.h | 4 ++++ sys/vfs/devfs/devfs_core.c | 36 ++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/sys/dev/misc/hotplug/hotplug.c b/sys/dev/misc/hotplug/hotplug.c index 1c789e1eef..23b0905907 100644 --- a/sys/dev/misc/hotplug/hotplug.c +++ b/sys/dev/misc/hotplug/hotplug.c @@ -46,15 +46,15 @@ static struct hotplug_softc int qcount; struct hpq queue; struct selinfo sel; - void (*old_devfs_node_added)(cdev_t dev); - void (*old_devfs_node_removed)(cdev_t dev); + void (*old_devfs_node_added)(struct hotplug_device *hpdev); + void (*old_devfs_node_removed)(struct hotplug_device *hpdev); } hpsc; -extern void (*devfs_node_added)(cdev_t dev); -extern void (*devfs_node_removed)(cdev_t dev); +extern void (*devfs_node_added)(struct hotplug_device *hpdev); +extern void (*devfs_node_removed)(struct hotplug_device *hpdev); -void hotplug_devfs_node_added(cdev_t dev); -void hotplug_devfs_node_removed(cdev_t dev); +void hotplug_devfs_node_added(struct hotplug_device *hpdev); +void hotplug_devfs_node_removed(struct hotplug_device *hpdev); static int hotplug_get_event(struct hotplug_event *he); static int hotplug_put_event(struct hotplug_event *he); @@ -165,15 +165,15 @@ hotplug_put_event(struct hotplug_event *he) } void -hotplug_devfs_node_added(cdev_t dev) { +hotplug_devfs_node_added(struct hotplug_device *hpdev) { struct hotplug_event he; u_int class; char *name; - if(!dev || !hpsc.opened) + if(!hpdev->dev || !hpsc.opened) return; - class = dev->si_ops->head.flags; - name = dev->si_name; + class = hpdev->dev->si_ops->head.flags; + name = hpdev->name; he.he_type = HOTPLUG_DEVAT; he.he_devclass = ((class == D_TTY) ? DV_TTY : ((class == D_TAPE) ? DV_TAPE : ((class == D_DISK) ? DV_DISK : DV_DULL))); strlcpy(he.he_devname, name, sizeof(he.he_devname)); @@ -181,15 +181,15 @@ hotplug_devfs_node_added(cdev_t dev) { } void -hotplug_devfs_node_removed(cdev_t dev) { +hotplug_devfs_node_removed(struct hotplug_device *hpdev) { struct hotplug_event he; u_int class; char *name; - if(!dev || !hpsc.opened) + if(!hpdev->dev || !hpsc.opened) return; - class = dev->si_ops->head.flags; - name = dev->si_name; + class = hpdev->dev->si_ops->head.flags; + name = hpdev->name; he.he_type = HOTPLUG_DEVDT; he.he_devclass = ((class == D_TTY) ? DV_TTY : ((class == D_TAPE) ? DV_TAPE : ((class == D_DISK) ? DV_DISK : DV_DULL))); strlcpy(he.he_devname, name, sizeof(he.he_devname)); diff --git a/sys/sys/hotplug.h b/sys/sys/hotplug.h index 490b54e82d..deb56223c1 100644 --- a/sys/sys/hotplug.h +++ b/sys/sys/hotplug.h @@ -48,6 +48,10 @@ struct hotplug_event { }; #ifdef _KERNEL +struct hotplug_device { + cdev_t dev; + char *name; +}; void hotplug_device_attach(device_t dev); void hotplug_device_detach(device_t dev); #endif diff --git a/sys/vfs/devfs/devfs_core.c b/sys/vfs/devfs/devfs_core.c index 8bb9eabf6e..5703c4fff2 100644 --- a/sys/vfs/devfs/devfs_core.c +++ b/sys/vfs/devfs/devfs_core.c @@ -48,6 +48,7 @@ #include #include #include +#include MALLOC_DEFINE(M_DEVFS, "devfs", "Device File System (devfs) allocations"); DEVFS_DECLARE_CLONE_BITMAP(ops_id); @@ -144,8 +145,8 @@ static void * devfs_inode_to_vnode_worker_callback(struct devfs_node *, ino_t *); /* hotplug */ -void (*devfs_node_added)(cdev_t) = NULL; -void (*devfs_node_removed)(cdev_t) = NULL; +void (*devfs_node_added)(struct hotplug_device*) = NULL; +void (*devfs_node_removed)(struct hotplug_device*) = NULL; /* * devfs_debug() is a SYSCTL and TUNABLE controlled debug output function @@ -437,6 +438,7 @@ int devfs_unlinkp(struct devfs_node *node) { struct devfs_node *parent; + struct hotplug_device *hpdev; KKASSERT(node); /* @@ -457,8 +459,14 @@ devfs_unlinkp(struct devfs_node *node) node->flags &= ~DEVFS_NODE_LINKED; } /* hotplug handler */ - if(devfs_node_removed) - devfs_node_removed(node->d_dev); + if(devfs_node_removed) { + hpdev = kmalloc(sizeof(struct hotplug_device), M_TEMP, M_WAITOK); + hpdev->dev = node->d_dev; + if(hpdev->dev) + hpdev->name = node->d_dev->si_name; + devfs_node_removed(hpdev); + kfree(hpdev, M_TEMP); + } node->parent = NULL; return 0; } @@ -1547,6 +1555,7 @@ devfs_alias_create(char *name_orig, struct devfs_node *target, int rule_based) struct mount *mp = target->mp; struct devfs_node *parent = DEVFS_MNTDATA(mp)->root_node; struct devfs_node *linknode; + struct hotplug_device *hpdev; char *create_path = NULL; char *name; char *name_buf; @@ -1584,8 +1593,13 @@ devfs_alias_create(char *name_orig, struct devfs_node *target, int rule_based) done: /* hotplug handler */ - if(devfs_node_added) - devfs_node_added(target->d_dev); + if(devfs_node_added) { + hpdev = kmalloc(sizeof(struct hotplug_device), M_TEMP, M_WAITOK); + hpdev->dev = target->d_dev; + hpdev->name = name_orig; + devfs_node_added(hpdev); + kfree(hpdev, M_TEMP); + } kfree(name_buf, M_TEMP); return (result); } @@ -1753,6 +1767,7 @@ devfs_create_device_node(struct devfs_node *root, cdev_t dev, char *dev_name, char *path_fmt, ...) { struct devfs_node *parent, *node = NULL; + struct hotplug_device *hpdev; char *path = NULL; char *name; char *name_buf; @@ -1817,8 +1832,13 @@ devfs_create_device_node(struct devfs_node *root, cdev_t dev, node->flags |= (DEVFS_PTY | DEVFS_INVISIBLE); } /* hotplug handler */ - if(devfs_node_added) - devfs_node_added(node->d_dev); + if(devfs_node_added) { + hpdev = kmalloc(sizeof(struct hotplug_device), M_TEMP, M_WAITOK); + hpdev->dev = node->d_dev; + hpdev->name = node->d_dev->si_name; + devfs_node_added(hpdev); + kfree(hpdev, M_TEMP); + } out: kfree(name_buf, M_TEMP); -- 2.41.0