WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Convert balloon driver to xenstore

To: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] Convert balloon driver to xenstore
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Date: Tue, 02 Aug 2005 21:13:37 -0500
Cc: Dan Smith <danms@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 03 Aug 2005 02:12:15 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1123031513.7228.6.camel@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <m38xzllglg.fsf@xxxxxxxxxxxxxxxxxxxxxxxx> <9cde8bff0508020311157b4463@xxxxxxxxxxxxxx> <m3y87ka1l3.fsf@xxxxxxxxxxxxxxxxxxxxxxxx> <1123031513.7228.6.camel@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
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