Rusty Russell wrote:
On Tue, 2005-08-02 at 06:51 -0700, Dan Smith wrote:
Generally, you will want to do a module_init() and initialize your
driver. If it's in domain 0, it needs to be initialized later (the
store isn't up yet): the standard way of doing this is a notifier chain.
Something like the following:
static struct notifier_block store_notify =
{
.notifier_call = balloon_setup,
};
static int balloon_init()
{
if (!xen_start_info.store_evtchn)
register_xenstore_notifier(&store_notify);
else
balloon_setup(&store_notify, 0, NULL);
return 0;
}
How does this look?
Regards,
Anthony Liguori
Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx>
diff -r dcdcec634c2d linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Tue Aug 2
16:11:31 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Tue Aug 2
21:09:03 2005
@@ -35,9 +35,15 @@
#include <linux/ctype.h>
#include <linux/fcntl.h>
#include <stdarg.h>
+#include <linux/notifier.h>
#include "xenbus_comms.h"
#define streq(a, b) (strcmp((a), (b)) == 0)
+
+/* Protects notifier chain */
+DECLARE_MUTEX(xenstore_control);
+
+static struct notifier_block *xenstore_chain;
/* If something in array of ids matches this device, return it. */
static const struct xenbus_device_id *
@@ -295,6 +301,26 @@
.callback = dev_changed,
};
+int register_xenstore_notifier(struct notifier_block *nb)
+{
+ int ret;
+
+ if ((ret = down_interruptible(&xenstore_control)) != 0)
+ return ret;
+ ret = notifier_chain_register(&xenstore_chain, nb);
+ up(&xenstore_control);
+ return ret;
+}
+EXPORT_SYMBOL(register_xenstore_notifier);
+
+void unregister_xenstore_notifier(struct notifier_block *nb)
+{
+ down(&xenstore_control);
+ notifier_chain_unregister(&xenstore_chain, nb);
+ up(&xenstore_control);
+}
+EXPORT_SYMBOL(unregister_xenstore_notifier);
+
/* called from a thread in privcmd/privcmd.c */
int do_xenbus_probe(void *unused)
{
@@ -309,6 +335,15 @@
return err;
}
+ err = notifier_call_chain(&xenstore_chain, 0, 0);
+ if (err == NOTIFY_BAD) {
+ printk("%s: calling xenstore notify chain failed\n",
+ __FUNCTION__);
+ return -EINVAL;
+ }
+
+ err = 0;
+
/* Initialize non-xenbus drivers */
balloon_init_watcher();
diff -r dcdcec634c2d linux-2.6-xen-sparse/include/asm-xen/xenbus.h
--- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Tue Aug 2 16:11:31 2005
+++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Tue Aug 2 21:09:03 2005
@@ -29,6 +29,7 @@
* IN THE SOFTWARE.
*/
#include <linux/device.h>
+#include <linux/notifier.h>
#include <asm/semaphore.h>
/* A xenbus device. */
@@ -112,6 +113,10 @@
void (*callback)(struct xenbus_watch *, const char *node);
};
+/* notifer routines for when the xenstore comes up */
+int register_xenstore_notifier(struct notifier_block *nb);
+void unregister_xenstore_notifier(struct notifier_block *nb);
+
int register_xenbus_watch(struct xenbus_watch *watch);
void unregister_xenbus_watch(struct xenbus_watch *watch);
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|