ia64/xen-unstable

changeset 6112:a5994e258f77

This patch addresses Rustys' [1]suggestions. Most visibly:

Entries in the store:
/cpus/cpuX/online -> /cpu/X/availability

Values:
0|1 -> online|offline

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 11 20:57:09 2005 +0000 (2005-08-11)
parents 2f75dac09365
children c9bbfb42ba84
files linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c	Thu Aug 11 18:03:22 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c	Thu Aug 11 20:57:09 2005 +0000
     1.3 @@ -1353,83 +1353,82 @@ static void __vcpu_hotplug_handler(void 
     1.4  		printk(KERN_ALERT "Error creating hotplug_cpu process!\n");
     1.5  }
     1.6  
     1.7 -static void handle_cpus_watch(struct xenbus_watch *, const char *);
     1.8 -static struct notifier_block xsn_cpus;
     1.9 +static void handle_vcpu_hotplug_event(struct xenbus_watch *, const char *);
    1.10 +static struct notifier_block xsn_cpu;
    1.11  
    1.12  /* xenbus watch struct */
    1.13 -static struct xenbus_watch cpus_watch = {
    1.14 -	.node = "cpus",
    1.15 -	.callback = handle_cpus_watch,
    1.16 +static struct xenbus_watch cpu_watch = {
    1.17 +	.node = "cpu",
    1.18 +	.callback = handle_vcpu_hotplug_event
    1.19  };
    1.20  
    1.21 -static int setup_cpus_watcher(struct notifier_block *notifier,
    1.22 +/* NB: Assumes xenbus_lock is held! */
    1.23 +static int setup_cpu_watcher(struct notifier_block *notifier,
    1.24  			      unsigned long event, void *data)
    1.25  {
    1.26  	int err = 0;
    1.27  
    1.28 -	down(&xenbus_lock);
    1.29 -	err = register_xenbus_watch(&cpus_watch);
    1.30 -	up(&xenbus_lock);
    1.31 +	BUG_ON(down_trylock(&xenbus_lock) == 0);
    1.32 +	err = register_xenbus_watch(&cpu_watch);
    1.33  
    1.34  	if (err) {
    1.35 -		printk("Failed to set cpus watcher\n");
    1.36 +		printk("Failed to register watch on /cpu\n");
    1.37  	}
    1.38 +
    1.39  	return NOTIFY_DONE;
    1.40  }
    1.41  
    1.42 -static void handle_cpus_watch(struct xenbus_watch *watch, const char *node)
    1.43 +static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, const char *node)
    1.44  {
    1.45  	static DECLARE_WORK(vcpu_hotplug_work, __vcpu_hotplug_handler, NULL);
    1.46  	struct vcpu_hotplug_handler_t *handler = &vcpu_hotplug_handler;
    1.47  	ssize_t ret;
    1.48 -	int err, cpu, state;
    1.49 +	int err, cpu;
    1.50 +	char state[8];
    1.51  	char dir[32];
    1.52  	char *cpustr;
    1.53  
    1.54 -	/* get a pointer to start of cpus/cpu string */
    1.55 -	if ((cpustr = strstr(node, "cpus/cpu")) != NULL) {
    1.56 +	/* get a pointer to start of cpu string */
    1.57 +	if ((cpustr = strstr(node, "cpu/")) != NULL) {
    1.58  
    1.59  		/* find which cpu state changed, note vcpu for handler */
    1.60 -		sscanf(cpustr, "cpus/cpu%d", &cpu);
    1.61 +		sscanf(cpustr, "cpu/%d", &cpu);
    1.62  		handler->vcpu = cpu;
    1.63  
    1.64  		/* calc the dir for xenbus read */
    1.65 -		sprintf(dir, "cpus/cpu%d", cpu);
    1.66 +		sprintf(dir, "cpu/%d", cpu);
    1.67  
    1.68 -		/* make sure watch that was triggered is changes to the online key */
    1.69 -		if ((strcmp(node + strlen(dir), "/online")) != 0)
    1.70 +		/* make sure watch that was triggered is changes to the correct key */
    1.71 +		if ((strcmp(node + strlen(dir), "/availability")) != 0)
    1.72  			return;
    1.73  
    1.74  		/* get the state value */
    1.75 -		xenbus_transaction_start("cpus");
    1.76 -		err = xenbus_scanf(dir, "online", "%d", &state);
    1.77 +		xenbus_transaction_start("cpu");
    1.78 +		err = xenbus_scanf(dir, "availability", "%s", state);
    1.79  		xenbus_transaction_end(0);
    1.80  
    1.81  		if (err != 1) {
    1.82  			printk(KERN_ERR
    1.83 -			       "XENBUS: Unable to read cpu online state\n");
    1.84 +			       "XENBUS: Unable to read cpu state\n");
    1.85  			return;
    1.86  		}
    1.87  
    1.88  		/* if we detect a state change, take action */
    1.89 -		switch (state) {
    1.90 +		if (strcmp(state, "online") == 0) {
    1.91  			/* offline -> online */
    1.92 -		case 1:
    1.93  			if (!cpu_isset(cpu, cpu_online_map)) {
    1.94  				handler->fn = (void *)&cpu_up;
    1.95  				ret = schedule_work(&vcpu_hotplug_work);
    1.96 -			}
    1.97 -			break;
    1.98 +			} 
    1.99 +		} else if (strcmp(state, "offline") == 0) {
   1.100  			/* online -> offline */
   1.101 -		case 0:
   1.102  			if (cpu_isset(cpu, cpu_online_map)) {
   1.103  				handler->fn = (void *)&cpu_down;
   1.104  				ret = schedule_work(&vcpu_hotplug_work);
   1.105 -			}
   1.106 -			break;
   1.107 -		default:
   1.108 +			} 
   1.109 +		} else {
   1.110  			printk(KERN_ERR
   1.111 -			       "XENBUS: unknown state(%d) on node(%s)\n", state,
   1.112 +			       "XENBUS: unknown state(%s) on node(%s)\n", state,
   1.113  			       node);
   1.114  		}
   1.115  	}
   1.116 @@ -1438,13 +1437,9 @@ static void handle_cpus_watch(struct xen
   1.117  
   1.118  static int __init setup_vcpu_hotplug_event(void)
   1.119  {
   1.120 -	xsn_cpus.notifier_call = setup_cpus_watcher;
   1.121 +	xsn_cpu.notifier_call = setup_cpu_watcher;
   1.122  
   1.123 -	if (xen_start_info.store_evtchn) {
   1.124 -		setup_cpus_watcher(&xsn_cpus, 0, NULL);
   1.125 -	} else {
   1.126 -		register_xenstore_notifier(&xsn_cpus);
   1.127 -	}
   1.128 +	register_xenstore_notifier(&xsn_cpu);
   1.129  
   1.130  	return 0;
   1.131  }
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 11 18:03:22 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 11 20:57:09 2005 +0000
     2.3 @@ -557,12 +557,12 @@ class XendDomainInfo:
     2.4  
     2.5      def exportVCPUSToDB(self, vcpus):
     2.6          for v in range(0,vcpus):
     2.7 -            path = "/cpus/cpu%d"%(v)
     2.8 +            path = "/cpu/%d"%(v)
     2.9              if not self.vcpusdb.has_key(path):
    2.10                  self.vcpusdb[path] = self.db.addChild(path)
    2.11              db = self.vcpusdb[path]
    2.12 -            log.debug("writing key online=1 to path %s in store"%(path))
    2.13 -            db['online'] = "1"
    2.14 +            log.debug("writing key availability=online to path %s in store"%(path))
    2.15 +            db['availability'] = "online"
    2.16              db.saveDB(save=True)
    2.17  
    2.18      def init_image(self):
    2.19 @@ -951,16 +951,16 @@ class XendDomainInfo:
    2.20          """
    2.21          db = ""
    2.22          try:
    2.23 -            db = self.vcpusdb['/cpus/cpu%d'%(vcpu)]
    2.24 +            db = self.vcpusdb['/cpu/%d'%(vcpu)]
    2.25          except:
    2.26              log.error("Invalid VCPU")
    2.27              return
    2.28  
    2.29          if self.store_channel:
    2.30              if int(state) == 0:
    2.31 -                db['online'] = "0"
    2.32 +                db['availability'] = "offline"
    2.33              else:
    2.34 -                db['online'] = "1"
    2.35 +                db['availability'] = "online"
    2.36  
    2.37          db.saveDB(save=True)
    2.38