From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH] Convert balloon driver to xenstore Date: Tue, 02 Aug 2005 21:13:37 -0500 Message-ID: <42F02851.4050905@us.ibm.com> References: <9cde8bff0508020311157b4463@mail.gmail.com> <1123031513.7228.6.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030407070703020308090006" Return-path: In-Reply-To: <1123031513.7228.6.camel@localhost.localdomain> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Rusty Russell Cc: Dan Smith , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------030407070703020308090006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------030407070703020308090006 Content-Type: text/x-patch; name="xenbus_notifier.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xenbus_notifier.diff" 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 #include #include +#include #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 +#include #include /* 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); --------------030407070703020308090006 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------030407070703020308090006--