Skip to contentSkip to conversation

delay xenbus init if xenbus master is a separate domain

PATCH In review Alex Zeffertt 1 participant 1 message Mar 23, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 delay xenbus init if xenbus master is a separate domain

This patch modifies xenbus to lazily initialize. This is necessary when xenstored is running in a seperate minios domain, since it can't connect as a slave just yet.

Ian Campbell has looked at an earlier version of this patch, and seems to generally approve.

Here's an explanation of the states:

It starts out in XENBUS_XSD_UNCOMMITTED.

As the master xenbus (the one local to xenstored), it will receive an mmap from xenstore, putting it in XENBUS_XSD_LOCAL_INIT. This enables the wake_waiting IRQ, which will put it in XENBUS_XSD_LOCAL_READY.

Alternatively, as a slave xenbus, it will receive an ioctl from the xenstore domain builder, putting it in XENBUS_XSD_FOREIGN_INIT. This enables the wake_waiting IRQ, which will put it in XENBUS_XSD_FOREIGN_READY.

DomU's are immediately initialized to XENBUS_XSD_FOREIGN_READY.

TODO: The types in the IOCTL might not be correct.

---

drivers/xen/core/xen_sysfs.c +2 -2
diff -r e68a58170585 drivers/xen/core/xen_sysfs.c
@@ -16,6 +16,7 @@
 #include <xen/hypervisor_sysfs.h>
 #include <xen/xenbus.h>
 #include <xen/interface/kexec.h>
+#include "../xenbus/xenbus_comms.h"
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Mike D. Day <[email protected]>");
@@ -105,9 +106,8 @@
 {
 	char *vm, *val;
 	int ret;
-	extern int xenstored_ready;
 
-	if (!xenstored_ready)
+	if (!is_xenstored_ready())
 		return -EBUSY;
 
 	vm = xenbus_read(XBT_NIL, "vm", "", NULL);
drivers/xen/xenbus/xenbus_comms.c +25 -4
diff -r e68a58170585 drivers/xen/xenbus/xenbus_comms.c
@@ -50,18 +50,39 @@
 static int xenbus_irq;
 
 extern void xenbus_probe(void *);
-extern int xenstored_ready;
 static DECLARE_WORK(probe_work, xenbus_probe, NULL);
 
 static DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
 
 static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs)
 {
-	if (unlikely(xenstored_ready == 0)) {
-		xenstored_ready = 1;
-		schedule_work(&probe_work);
+	int old, new;
+
+	old = atomic_read(&xenbus_xsd_state);
+	switch (old) {
+		case XENBUS_XSD_UNCOMMITTED:
+			BUG();
+			return IRQ_HANDLED;
+
+		case XENBUS_XSD_FOREIGN_INIT:
+			new = XENBUS_XSD_FOREIGN_READY;
+			break;
+		
+		case XENBUS_XSD_LOCAL_INIT:
+			new = XENBUS_XSD_LOCAL_READY;
+			break;
+
+		case XENBUS_XSD_FOREIGN_READY:
+		case XENBUS_XSD_LOCAL_READY:
+		default:
+			goto wake;
 	}
 
+	old = atomic_cmpxchg(&xenbus_xsd_state, old, new);
+	if (old != new)
+		schedule_work(&probe_work);
+
+wake:
 	wake_up(&xb_waitq);
 	return IRQ_HANDLED;
 }
drivers/xen/xenbus/xenbus_comms.h +16 -0
diff -r e68a58170585 drivers/xen/xenbus/xenbus_comms.h
@@ -43,4 +43,20 @@
 extern struct xenstore_domain_interface *xen_store_interface;
 extern int xen_store_evtchn;
 
+/* For xenbus internal use. */
+enum {
+	XENBUS_XSD_UNCOMMITTED = 0,
+	XENBUS_XSD_FOREIGN_INIT,
+	XENBUS_XSD_FOREIGN_READY,
+	XENBUS_XSD_LOCAL_INIT,
+	XENBUS_XSD_LOCAL_READY,
+};
+extern atomic_t xenbus_xsd_state;
+
+static inline int is_xenstored_ready(void)
+{
+	int s = atomic_read(&xenbus_xsd_state);
+	return s == XENBUS_XSD_FOREIGN_READY || s == XENBUS_XSD_LOCAL_READY;
+}
+
 #endif /* _XENBUS_COMMS_H */
drivers/xen/xenbus/xenbus_dev.c +62 -0

96 lines not on this page · raw message

drivers/xen/xenbus/xenbus_probe.c +92 -6

153 lines not on this page · raw message

drivers/xen/xenbus/xenbus_xs.c +0 -6
diff -r e68a58170585 drivers/xen/xenbus/xenbus_xs.c
@@ -872,7 +872,6 @@
 
 int xs_init(void)
 {
-	int err;
 	struct task_struct *task;
 
 	INIT_LIST_HEAD(&xs_state.reply_list);
@@ -883,11 +882,6 @@
 	mutex_init(&xs_state.response_mutex);
 	init_rwsem(&xs_state.transaction_mutex);
 	init_rwsem(&xs_state.watch_mutex);
-
-	/* Initialize the shared memory rings to talk to xenstored */
-	err = xb_init_comms();
-	if (err)
-		return err;
 
 	task = kthread_run(xenwatch_thread, NULL, "xenwatch");
 	if (IS_ERR(task))
include/xen/public/xenbus.h new file +56 -0

56 lines not on this page · raw message

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