Skip to contentSkip to conversation

Move to new notifier structure

PATCH In review Dan Smith 1 participant 1 message Aug 5, 2005

lore
Share & tools
lore

Dan Smith

author
#0 lore raw

PATCH 2/2 Move to new notifier structure

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.

linux-2.6-xen-sparse/arch/xen/kernel/reboot.c +6 -7
diff -r a94ff69a51a3 linux-2.6-xen-sparse/arch/xen/kernel/reboot.c
@@ -314,6 +314,9 @@
 
 static struct notifier_block xenstore_notifier;
 
+/* Setup our watcher
+   NB: Assumes xenbus_lock is held!
+*/
 static int setup_shutdown_watcher(struct notifier_block *notifier,
                                   unsigned long event,
                                   void *data)
@@ -323,12 +326,12 @@
     int err2 = 0;
 #endif
 
-    down(&xenbus_lock);
+    BUG_ON(down_trylock(&xenbus_lock) == 0);
+
     err1 = register_xenbus_watch(&shutdown_watch);
 #ifdef CONFIG_MAGIC_SYSRQ
     err2 = register_xenbus_watch(&sysrq_watch);
 #endif
-    up(&xenbus_lock);
 
     if (err1) {
         printk(KERN_ERR "Failed to set shutdown watcher\n");
@@ -348,11 +351,7 @@
     
     xenstore_notifier.notifier_call = setup_shutdown_watcher;
 
-    if (xen_start_info.store_evtchn) {
-        setup_shutdown_watcher(&xenstore_notifier, 0, NULL);
-    } else {
-        register_xenstore_notifier(&xenstore_notifier);
-    }
+    register_xenstore_notifier(&xenstore_notifier);
     
     return 0;
 }
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +28 -67

139 lines not on this page · raw message

linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +17 -14
diff -r a94ff69a51a3 linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
@@ -41,9 +41,6 @@
 
 #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. */
@@ -317,21 +314,27 @@
 
 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);
+	int ret = 0;
+
+	down(&xenbus_lock);
+
+	if (xen_start_info.store_evtchn) {
+		ret = nb->notifier_call(nb, 0, NULL);
+	} else {
+		notifier_chain_register(&xenstore_chain, nb);
+	}
+
+	up(&xenbus_lock);
+
 	return ret;
 }
 EXPORT_SYMBOL(register_xenstore_notifier);
 
 void unregister_xenstore_notifier(struct notifier_block *nb)
 {
-	down(&xenstore_control);
+	down(&xenbus_lock);
 	notifier_chain_unregister(&xenstore_chain, nb);
-	up(&xenstore_control);
+	up(&xenbus_lock);
 }
 EXPORT_SYMBOL(unregister_xenstore_notifier);
 
@@ -349,7 +352,10 @@
 		return err;
 	}
 
+	down(&xenbus_lock);
 	err = notifier_call_chain(&xenstore_chain, 0, 0);
+	up(&xenbus_lock);
+
 	if (err == NOTIFY_BAD) {
 		printk("%s: calling xenstore notify chain failed\n",
 		       __FUNCTION__);
@@ -358,9 +364,6 @@
 
 	err = 0;
 
-	/* Initialize non-xenbus drivers */
-	balloon_init_watcher();
-
 	down(&xenbus_lock);
 	/* Enumerate devices in xenstore. */
 	xenbus_probe_devices("device");
linux-2.6-xen-sparse/include/asm-xen/balloon.h +0 -3
diff -r a94ff69a51a3 linux-2.6-xen-sparse/include/asm-xen/balloon.h
@@ -48,7 +48,4 @@
 #define balloon_lock(__flags)   spin_lock_irqsave(&balloon_lock, __flags)
 #define balloon_unlock(__flags) spin_unlock_irqrestore(&balloon_lock, __flags)
 
-/* Init Function - Try to set up our watcher, if not already set. */
-void balloon_init_watcher(void);
-
 #endif /* __ASM_BALLOON_H__ */
Signature · 5 lines
-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [email protected]

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel