ia64/err-inject: Convert to hotplug state machine
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 3 Nov 2016 14:50:10 +0000 (15:50 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 9 Nov 2016 22:45:29 +0000 (23:45 +0100)
Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

The removal of the files happens now in the prepare down stage as there is
no reason to keep them around until the cpu has actually died.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-ia64@vger.kernel.org
Cc: rt@linutronix.de
Link: http://lkml.kernel.org/r/20161103145021.28528-15-bigeasy@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/ia64/kernel/err_inject.c

index 5ed0ea92c5bfac3935b3b799607dca9b3b6086a9..85bba43e7d5dc7638138f90f1eb0dd56609c5807 100644 (file)
@@ -224,85 +224,45 @@ static struct attribute_group err_inject_attr_group = {
        .name = "err_inject"
 };
 /* Add/Remove err_inject interface for CPU device */
-static int err_inject_add_dev(struct device *sys_dev)
+static int err_inject_add_dev(unsigned int cpu)
 {
+       struct device *sys_dev = get_cpu_device(cpu);
+
        return sysfs_create_group(&sys_dev->kobj, &err_inject_attr_group);
 }
 
-static int err_inject_remove_dev(struct device *sys_dev)
+static int err_inject_remove_dev(unsigned int cpu)
 {
+       struct device *sys_dev = get_cpu_device(cpu);
+
        sysfs_remove_group(&sys_dev->kobj, &err_inject_attr_group);
        return 0;
 }
-static int err_inject_cpu_callback(struct notifier_block *nfb,
-               unsigned long action, void *hcpu)
-{
-       unsigned int cpu = (unsigned long)hcpu;
-       struct device *sys_dev;
-
-       sys_dev = get_cpu_device(cpu);
-       switch (action) {
-       case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
-               err_inject_add_dev(sys_dev);
-               break;
-       case CPU_DEAD:
-       case CPU_DEAD_FROZEN:
-               err_inject_remove_dev(sys_dev);
-               break;
-       }
-
-       return NOTIFY_OK;
-}
 
-static struct notifier_block err_inject_cpu_notifier =
-{
-       .notifier_call = err_inject_cpu_callback,
-};
+static enum cpuhp_state hp_online;
 
-static int __init
-err_inject_init(void)
+static int __init err_inject_init(void)
 {
-       int i;
-
+       int ret;
 #ifdef ERR_INJ_DEBUG
        printk(KERN_INFO "Enter error injection driver.\n");
 #endif
 
-       cpu_notifier_register_begin();
-
-       for_each_online_cpu(i) {
-               err_inject_cpu_callback(&err_inject_cpu_notifier, CPU_ONLINE,
-                               (void *)(long)i);
+       ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ia64/err_inj:online",
+                               err_inject_add_dev, err_inject_remove_dev);
+       if (ret >= 0) {
+               hp_online = ret;
+               ret = 0;
        }
-
-       __register_hotcpu_notifier(&err_inject_cpu_notifier);
-
-       cpu_notifier_register_done();
-
-       return 0;
+       return ret;
 }
 
-static void __exit
-err_inject_exit(void)
+static void __exit err_inject_exit(void)
 {
-       int i;
-       struct device *sys_dev;
-
 #ifdef ERR_INJ_DEBUG
        printk(KERN_INFO "Exit error injection driver.\n");
 #endif
-
-       cpu_notifier_register_begin();
-
-       for_each_online_cpu(i) {
-               sys_dev = get_cpu_device(i);
-               sysfs_remove_group(&sys_dev->kobj, &err_inject_attr_group);
-       }
-
-       __unregister_hotcpu_notifier(&err_inject_cpu_notifier);
-
-       cpu_notifier_register_done();
+       cpuhp_remove_state(hp_online);
 }
 
 module_init(err_inject_init);