1 #include <linux/notifier.h>
4 #include <xen/xenbus.h>
6 #include <asm/xen/hypervisor.h>
9 static void enable_hotplug_cpu(int cpu)
11 if (!cpu_present(cpu))
12 arch_register_cpu(cpu);
14 set_cpu_present(cpu, true);
17 static void disable_hotplug_cpu(int cpu)
20 arch_unregister_cpu(cpu);
22 set_cpu_present(cpu, false);
25 static int vcpu_online(unsigned int cpu)
28 char dir[32], state[32];
30 sprintf(dir, "cpu/%u", cpu);
31 err = xenbus_scanf(XBT_NIL, dir, "availability", "%s", state);
33 printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
37 if (strcmp(state, "online") == 0)
39 else if (strcmp(state, "offline") == 0)
42 printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n", state, cpu);
45 static void vcpu_hotplug(unsigned int cpu)
47 if (!cpu_possible(cpu))
50 switch (vcpu_online(cpu)) {
52 enable_hotplug_cpu(cpu);
56 disable_hotplug_cpu(cpu);
63 static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
64 const char **vec, unsigned int len)
68 const char *node = vec[XS_WATCH_PATH];
70 cpustr = strstr(node, "cpu/");
72 sscanf(cpustr, "cpu/%u", &cpu);
77 static int setup_cpu_watcher(struct notifier_block *notifier,
78 unsigned long event, void *data)
81 static struct xenbus_watch cpu_watch = {
83 .callback = handle_vcpu_hotplug_event};
85 (void)register_xenbus_watch(&cpu_watch);
87 for_each_possible_cpu(cpu) {
88 if (vcpu_online(cpu) == 0) {
90 cpu_clear(cpu, cpu_present_map);
97 static int __init setup_vcpu_hotplug_event(void)
99 static struct notifier_block xsn_cpu = {
100 .notifier_call = setup_cpu_watcher };
102 if (!xen_pv_domain())
105 register_xenstore_notifier(&xsn_cpu);
110 arch_initcall(setup_vcpu_hotplug_event);