ia64/xen-unstable

changeset 6044:968829eb1783

This patch changes the probe notifier, per Rusty's suggestion. It
also converts the balloon driver to use the notifier structure, and
removes the root-watch workaround.

Signed-off-by: Dan Smith <danms@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Aug 06 09:49:22 2005 +0000 (2005-08-06)
parents 0538ec1fe5b2
children 5f6787c5c71f
files linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/include/asm-xen/balloon.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Sat Aug 06 09:48:47 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Sat Aug 06 09:49:22 2005 +0000
     1.3 @@ -314,6 +314,9 @@ static struct xenbus_watch sysrq_watch =
     1.4  
     1.5  static struct notifier_block xenstore_notifier;
     1.6  
     1.7 +/* Setup our watcher
     1.8 +   NB: Assumes xenbus_lock is held!
     1.9 +*/
    1.10  static int setup_shutdown_watcher(struct notifier_block *notifier,
    1.11                                    unsigned long event,
    1.12                                    void *data)
    1.13 @@ -323,12 +326,12 @@ static int setup_shutdown_watcher(struct
    1.14      int err2 = 0;
    1.15  #endif
    1.16  
    1.17 -    down(&xenbus_lock);
    1.18 +    BUG_ON(down_trylock(&xenbus_lock) == 0);
    1.19 +
    1.20      err1 = register_xenbus_watch(&shutdown_watch);
    1.21  #ifdef CONFIG_MAGIC_SYSRQ
    1.22      err2 = register_xenbus_watch(&sysrq_watch);
    1.23  #endif
    1.24 -    up(&xenbus_lock);
    1.25  
    1.26      if (err1) {
    1.27          printk(KERN_ERR "Failed to set shutdown watcher\n");
    1.28 @@ -348,11 +351,7 @@ static int __init setup_shutdown_event(v
    1.29      
    1.30      xenstore_notifier.notifier_call = setup_shutdown_watcher;
    1.31  
    1.32 -    if (xen_start_info.store_evtchn) {
    1.33 -        setup_shutdown_watcher(&xenstore_notifier, 0, NULL);
    1.34 -    } else {
    1.35 -        register_xenstore_notifier(&xenstore_notifier);
    1.36 -    }
    1.37 +    register_xenstore_notifier(&xenstore_notifier);
    1.38      
    1.39      return 0;
    1.40  }
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Sat Aug 06 09:48:47 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Sat Aug 06 09:49:22 2005 +0000
     2.3 @@ -81,9 +81,6 @@ static void balloon_process(void *unused
     2.4  static DECLARE_WORK(balloon_worker, balloon_process, NULL);
     2.5  static struct timer_list balloon_timer;
     2.6  
     2.7 -/* Flag for dom0 xenstore workaround */
     2.8 -static int balloon_xenbus_init=0;
     2.9 -
    2.10  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    2.11  /* Use the private and mapping fields of struct page as a list. */
    2.12  #define PAGE_TO_LIST(p) ( (struct list_head *)&p->private )
    2.13 @@ -304,15 +301,9 @@ static void set_new_target(unsigned long
    2.14      schedule_work(&balloon_worker);
    2.15  }
    2.16  
    2.17 -static struct xenbus_watch xb_watch =
    2.18 +static struct xenbus_watch target_watch =
    2.19  {
    2.20 -    .node = "memory"
    2.21 -};
    2.22 -
    2.23 -/* FIXME: This is part of a dom0 sequencing workaround */
    2.24 -static struct xenbus_watch root_watch =
    2.25 -{
    2.26 -    .node = "/"
    2.27 +    .node = "memory/target"
    2.28  };
    2.29  
    2.30  /* React to a change in the target key */
    2.31 @@ -321,29 +312,11 @@ static void watch_target(struct xenbus_w
    2.32      unsigned long new_target;
    2.33      int err;
    2.34  
    2.35 -    if(watch == &root_watch)
    2.36 -    {
    2.37 -        /* FIXME: This is part of a dom0 sequencing workaround */
    2.38 -        if(register_xenbus_watch(&xb_watch) == 0)
    2.39 -        {
    2.40 -            /* 
    2.41 -               We successfully set a watch on memory/target:
    2.42 -               now we can stop watching root 
    2.43 -            */
    2.44 -            unregister_xenbus_watch(&root_watch);
    2.45 -            balloon_xenbus_init=1;
    2.46 -        } 
    2.47 -        else 
    2.48 -        {
    2.49 -            return;
    2.50 -        }
    2.51 -    }
    2.52 -
    2.53      err = xenbus_scanf("memory", "target", "%lu", &new_target);
    2.54          
    2.55      if(err != 1) 
    2.56      {
    2.57 -        IPRINTK("Unable to read memory/target\n");
    2.58 +        printk(KERN_ERR "Unable to read memory/target\n");
    2.59          return;
    2.60      } 
    2.61          
    2.62 @@ -351,41 +324,27 @@ static void watch_target(struct xenbus_w
    2.63      
    2.64  }
    2.65  
    2.66 -/* Init Function - Try to set up our watcher, if not already set. */
    2.67 -void balloon_init_watcher(void)
    2.68 +/* Setup our watcher
    2.69 +   NB: Assumes xenbus_lock is held!
    2.70 +*/
    2.71 +int balloon_init_watcher(struct notifier_block *notifier,
    2.72 +                         unsigned long event,
    2.73 +                         void *data)
    2.74  {
    2.75      int err;
    2.76  
    2.77 -    if (!xen_start_info.store_evtchn) {
    2.78 -        IPRINTK("Delaying watcher init until xenstore is available\n");
    2.79 -        return;
    2.80 +    BUG_ON(down_trylock(&xenbus_lock) == 0);
    2.81 +
    2.82 +    err = register_xenbus_watch(&target_watch);
    2.83 +
    2.84 +    if (err) {
    2.85 +        printk(KERN_ERR "Failed to set balloon watcher\n");
    2.86      }
    2.87  
    2.88 -    down(&xenbus_lock);
    2.89 -
    2.90 -    if (!balloon_xenbus_init) {
    2.91 -        err = register_xenbus_watch(&xb_watch);
    2.92 -        if (err) {
    2.93 -            /* BIG FAT FIXME: dom0 sequencing workaround
    2.94 -             * dom0 can't set a watch on memory/target until
    2.95 -             * after the tools create it.  So, we have to watch
    2.96 -             * the whole store until that happens.
    2.97 -             *
    2.98 -             * This will go away when we have the ability to watch
    2.99 -             * non-existant keys
   2.100 -             */
   2.101 -            register_xenbus_watch(&root_watch);
   2.102 -        } else {
   2.103 -            IPRINTK("Balloon xenbus watcher initialized\n");
   2.104 -            balloon_xenbus_init = 1;
   2.105 -        }
   2.106 -    }
   2.107 -
   2.108 -    up(&xenbus_lock);
   2.109 +    return NOTIFY_DONE;
   2.110 +    
   2.111  }
   2.112  
   2.113 -EXPORT_SYMBOL(balloon_init_watcher);
   2.114 -
   2.115  static int balloon_write(struct file *file, const char __user *buffer,
   2.116                           unsigned long count, void *data)
   2.117  {
   2.118 @@ -439,6 +398,8 @@ static int balloon_read(char *page, char
   2.119      return len;
   2.120  }
   2.121  
   2.122 +static struct notifier_block xenstore_notifier;
   2.123 +
   2.124  static int __init balloon_init(void)
   2.125  {
   2.126      unsigned long pfn;
   2.127 @@ -474,11 +435,11 @@ static int __init balloon_init(void)
   2.128              balloon_append(page);
   2.129      }
   2.130  
   2.131 -    xb_watch.callback = watch_target;
   2.132 -    root_watch.callback = watch_target;
   2.133 +    target_watch.callback = watch_target;
   2.134 +    xenstore_notifier.notifier_call = balloon_init_watcher;
   2.135  
   2.136 -    balloon_init_watcher();
   2.137 -
   2.138 +    register_xenstore_notifier(&xenstore_notifier);
   2.139 +    
   2.140      return 0;
   2.141  }
   2.142  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sat Aug 06 09:48:47 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sat Aug 06 09:49:22 2005 +0000
     3.3 @@ -41,9 +41,6 @@
     3.4  
     3.5  #define streq(a, b) (strcmp((a), (b)) == 0)
     3.6  
     3.7 -/* Protects notifier chain */
     3.8 -DECLARE_MUTEX(xenstore_control);
     3.9 -
    3.10  static struct notifier_block *xenstore_chain;
    3.11  
    3.12  /* If something in array of ids matches this device, return it. */
    3.13 @@ -317,21 +314,27 @@ void xenbus_resume(void)
    3.14  
    3.15  int register_xenstore_notifier(struct notifier_block *nb)
    3.16  {
    3.17 -	int ret;
    3.18 +	int ret = 0;
    3.19 +
    3.20 +	down(&xenbus_lock);
    3.21  
    3.22 -	if ((ret = down_interruptible(&xenstore_control)) != 0) 
    3.23 -		return ret;
    3.24 -	ret = notifier_chain_register(&xenstore_chain, nb);
    3.25 -	up(&xenstore_control);
    3.26 +	if (xen_start_info.store_evtchn) {
    3.27 +		ret = nb->notifier_call(nb, 0, NULL);
    3.28 +	} else {
    3.29 +		notifier_chain_register(&xenstore_chain, nb);
    3.30 +	}
    3.31 +
    3.32 +	up(&xenbus_lock);
    3.33 +
    3.34  	return ret;
    3.35  }
    3.36  EXPORT_SYMBOL(register_xenstore_notifier);
    3.37  
    3.38  void unregister_xenstore_notifier(struct notifier_block *nb)
    3.39  {
    3.40 -	down(&xenstore_control);
    3.41 +	down(&xenbus_lock);
    3.42  	notifier_chain_unregister(&xenstore_chain, nb);
    3.43 -	up(&xenstore_control);
    3.44 +	up(&xenbus_lock);
    3.45  }
    3.46  EXPORT_SYMBOL(unregister_xenstore_notifier);
    3.47  
    3.48 @@ -349,7 +352,10 @@ int do_xenbus_probe(void *unused)
    3.49  		return err;
    3.50  	}
    3.51  
    3.52 +	down(&xenbus_lock);
    3.53  	err = notifier_call_chain(&xenstore_chain, 0, 0);
    3.54 +	up(&xenbus_lock);
    3.55 +
    3.56  	if (err == NOTIFY_BAD) {
    3.57  		printk("%s: calling xenstore notify chain failed\n",
    3.58  		       __FUNCTION__);
    3.59 @@ -358,9 +364,6 @@ int do_xenbus_probe(void *unused)
    3.60  
    3.61  	err = 0;
    3.62  
    3.63 -	/* Initialize non-xenbus drivers */
    3.64 -	balloon_init_watcher();
    3.65 -
    3.66  	down(&xenbus_lock);
    3.67  	/* Enumerate devices in xenstore. */
    3.68  	xenbus_probe_devices("device");
     4.1 --- a/linux-2.6-xen-sparse/include/asm-xen/balloon.h	Sat Aug 06 09:48:47 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/balloon.h	Sat Aug 06 09:49:22 2005 +0000
     4.3 @@ -48,7 +48,4 @@ extern spinlock_t balloon_lock;
     4.4  #define balloon_lock(__flags)   spin_lock_irqsave(&balloon_lock, __flags)
     4.5  #define balloon_unlock(__flags) spin_unlock_irqrestore(&balloon_lock, __flags)
     4.6  
     4.7 -/* Init Function - Try to set up our watcher, if not already set. */
     4.8 -void balloon_init_watcher(void);
     4.9 -
    4.10  #endif /* __ASM_BALLOON_H__ */