1 #include <linux/notifier.h>
3 #include <xen/xenbus.h>
5 #include <asm-x86/xen/hypervisor.h>
8 static void enable_hotplug_cpu(int cpu)
10 if (!cpu_present(cpu))
11 arch_register_cpu(cpu);
13 cpu_set(cpu, cpu_present_map);
16 static void disable_hotplug_cpu(int cpu)
19 arch_unregister_cpu(cpu);
21 cpu_clear(cpu, cpu_present_map);
24 static void vcpu_hotplug(unsigned int cpu)
27 char dir[32], state[32];
29 if (!cpu_possible(cpu))
32 sprintf(dir, "cpu/%u", cpu);
33 err = xenbus_scanf(XBT_NIL, dir, "availability", "%s", state);
35 printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
39 if (strcmp(state, "online") == 0) {
40 enable_hotplug_cpu(cpu);
41 } else if (strcmp(state, "offline") == 0) {
43 disable_hotplug_cpu(cpu);
45 printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n",
50 static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
51 const char **vec, unsigned int len)
55 const char *node = vec[XS_WATCH_PATH];
57 cpustr = strstr(node, "cpu/");
59 sscanf(cpustr, "cpu/%u", &cpu);
64 static int setup_cpu_watcher(struct notifier_block *notifier,
65 unsigned long event, void *data)
67 static struct xenbus_watch cpu_watch = {
69 .callback = handle_vcpu_hotplug_event};
71 (void)register_xenbus_watch(&cpu_watch);
76 static int __init setup_vcpu_hotplug_event(void)
78 static struct notifier_block xsn_cpu = {
79 .notifier_call = setup_cpu_watcher };
81 if (!is_running_on_xen())
84 register_xenstore_notifier(&xsn_cpu);
89 arch_initcall(setup_vcpu_hotplug_event);