cpu/hotplug: Create a new function to shutdown nonboot cpus
[sfrench/cifs-2.6.git] / kernel / cpu.c
index 069802f7010f24e963e1e372bc44e86826906936..03c727195b65a233071af0d7418bd051e5c67343 100644 (file)
@@ -1069,6 +1069,48 @@ int remove_cpu(unsigned int cpu)
 }
 EXPORT_SYMBOL_GPL(remove_cpu);
 
+void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
+{
+       unsigned int cpu;
+       int error;
+
+       cpu_maps_update_begin();
+
+       /*
+        * Make certain the cpu I'm about to reboot on is online.
+        *
+        * This is inline to what migrate_to_reboot_cpu() already do.
+        */
+       if (!cpu_online(primary_cpu))
+               primary_cpu = cpumask_first(cpu_online_mask);
+
+       for_each_online_cpu(cpu) {
+               if (cpu == primary_cpu)
+                       continue;
+
+               error = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
+               if (error) {
+                       pr_err("Failed to offline CPU%d - error=%d",
+                               cpu, error);
+                       break;
+               }
+       }
+
+       /*
+        * Ensure all but the reboot CPU are offline.
+        */
+       BUG_ON(num_online_cpus() > 1);
+
+       /*
+        * Make sure the CPUs won't be enabled by someone else after this
+        * point. Kexec will reboot to a new kernel shortly resetting
+        * everything along the way.
+        */
+       cpu_hotplug_disabled++;
+
+       cpu_maps_update_done();
+}
+
 #else
 #define takedown_cpu           NULL
 #endif /*CONFIG_HOTPLUG_CPU*/