]> git.hungrycats.org Git - linux/commitdiff
driver core: move the hotplug support for /sys/devices to use the kobject logic.
authorGreg Kroah-Hartman <greg@kroah.com>
Fri, 4 Apr 2003 09:13:54 +0000 (01:13 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Fri, 4 Apr 2003 09:13:54 +0000 (01:13 -0800)
We can't switch /sys/class or /sys/bus to use this because they are
not creating new kobjects, only linking to the kobjects in /sys/devices.

drivers/base/base.h
drivers/base/core.c
drivers/base/hotplug.c

index df62fb668cc4adc3699f09ccec03c48fbf45aae4..9180934e6c99de5af5deb1409758cdca8c11955b 100644 (file)
@@ -18,13 +18,8 @@ extern void interface_remove_dev(struct device *);
 
 
 #ifdef CONFIG_HOTPLUG
-extern int dev_hotplug(struct device *dev, const char *action);
 extern int class_hotplug(struct device *dev, const char *action);
 #else
-static inline int dev_hotplug(struct device *dev, const char *action)
-{
-       return 0;
-}
 static inline int class_hotplug(struct device *dev, const char *action)
 {
        return 0;
index 5f95879b80f211d493f88709fc0fb4fd5eac7ba1..0374b33562cd398b2af20db786a16a46975d7773 100644 (file)
@@ -23,13 +23,12 @@ int (*platform_notify_remove)(struct device * dev) = NULL;
 
 DECLARE_MUTEX(device_sem);
 
-#define to_dev(obj) container_of(obj,struct device,kobj)
-
 
 /*
  * sysfs bindings for devices.
  */
 
+#define to_dev(obj) container_of(obj,struct device,kobj)
 #define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr)
 
 extern struct attribute * dev_default_attrs[];
@@ -86,11 +85,55 @@ static struct kobj_type ktype_device = {
        .default_attrs  = dev_default_attrs,
 };
 
+
+static int dev_hotplug_filter(struct kset *kset, struct kobject *kobj)
+{
+       struct kobj_type *ktype = get_ktype(kobj);
+
+       if (ktype == &ktype_device) {
+               struct device *dev = to_dev(kobj);
+               if (dev->bus)
+                       return 1;
+       }
+       return 0;
+}
+
+static char *dev_hotplug_name(struct kset *kset, struct kobject *kobj)
+{
+       struct device *dev = to_dev(kobj);
+
+       return dev->bus->name;
+}
+
+static int dev_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
+                       int num_envp, char *buffer, int buffer_size)
+{
+       struct device *dev = to_dev(kobj);
+       int retval = 0;
+
+       if (dev->bus->hotplug) {
+               /* have the bus specific function add its stuff */
+               retval = dev->bus->hotplug (dev, envp, num_envp, buffer, buffer_size);
+                       if (retval) {
+                       pr_debug ("%s - hotplug() returned %d\n",
+                                 __FUNCTION__, retval);
+               }
+       }
+
+       return retval;
+}
+
+static struct kset_hotplug_ops device_hotplug_ops = {
+       .filter =       dev_hotplug_filter,
+       .name =         dev_hotplug_name,
+       .hotplug =      dev_hotplug,
+};
+
 /**
  *     device_subsys - structure to be registered with kobject core.
  */
 
-decl_subsys(devices,&ktype_device);
+decl_subsys(devices, &ktype_device, &device_hotplug_ops);
 
 
 /**
@@ -192,9 +235,6 @@ int device_add(struct device *dev)
        if (platform_notify)
                platform_notify(dev);
 
-       /* notify userspace of device entry */
-       dev_hotplug(dev, "add");
-
        devclass_add_device(dev);
  register_done:
        if (error && parent)
@@ -278,9 +318,6 @@ void device_del(struct device * dev)
        if (platform_notify_remove)
                platform_notify_remove(dev);
 
-       /* notify userspace that this device is about to disappear */
-       dev_hotplug (dev, "remove");
-
        bus_remove_device(dev);
 
        kobject_del(&dev->kobj);
index a9c977ddcfe2359db31f2c35a68c24646a286f18..9314aa43614e592b1ce81ab595c8141a06425baf 100644 (file)
@@ -2,8 +2,8 @@
  * drivers/base/hotplug.c - hotplug call code
  * 
  * Copyright (c) 2000-2001 David Brownell
- * Copyright (c) 2002 Greg Kroah-Hartman
- * Copyright (c) 2002 IBM Corp.
+ * Copyright (c) 2002-2003 Greg Kroah-Hartman
+ * Copyright (c) 2002-2003 IBM Corp.
  *
  * Based off of drivers/usb/core/usb.c:call_agent(), which was 
  * written by David Brownell.
@@ -53,17 +53,6 @@ static int do_hotplug (struct device *dev, char *argv1, const char *action,
        if (!hotplug_path [0])
                return -ENODEV;
 
-       if (in_interrupt ()) {
-               pr_debug ("%s - in_interrupt, not allowed!", __FUNCTION__);
-               return -EIO;
-       }
-
-       if (!current->fs->root) {
-               /* don't try to do anything unless we have a root partition */
-               pr_debug ("%s - %s -- no FS yet\n", __FUNCTION__, action);
-               return -EIO;
-       }
-
        envp = (char **) kmalloc (NUM_ENVP * sizeof (char *), GFP_KERNEL);
        if (!envp)
                return -ENOMEM;
@@ -128,23 +117,6 @@ exit:
        return retval;
 }
 
-
-/*
- * dev_hotplug - called when any device is added or removed from a bus
- */
-int dev_hotplug (struct device *dev, const char *action)
-{
-       pr_debug ("%s\n", __FUNCTION__);
-       if (!dev)
-               return -ENODEV;
-
-       if (!dev->bus)
-               return -ENODEV;
-
-       return do_hotplug (dev, dev->bus->name, action, dev->bus->hotplug);
-}
-
-
 /*
  * class_hotplug - called when a class is added or removed from a device
  */