]> xenbits.xensource.com Git - rumpuser-xen.git/commitdiff
mini-os/xenbus: Change type of xenbus_event_queue
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 20 Jun 2014 15:47:46 +0000 (16:47 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 24 Jun 2014 16:32:38 +0000 (17:32 +0100)
We change xenbus_event_queue from a pointer typedef to a struct, for
two reasons:

1. In a moment we are going to want to extend this struct to include
   a minios scheduler wait queue.

2. We can replace the open-coded list with a MINIOS_STAILQ.

All the xenbus users need to call the new initialisation function
instead of simply initialising the struct to NULL, and have their
parameter type changed.

There is a functional side-effect: now we are using a tail queue,
rather than a tailless queue, we insert events at the end rather than
the beginning.  So watch events now come out in chronological order,
rather than their order possibly being scrambled in the queue.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
include/mini-os/console.h
include/mini-os/xenbus.h
xen/blkfront.c
xen/console/xenbus.c
xen/netfront.c
xen/pcifront.c
xen/xenbus/xenbus.c

index 1b04b130c1e1c5712ead7ac1983a075d31ef7b33..49990b95178279c11c27cff761a2224d4bacf57c 100644 (file)
@@ -56,7 +56,7 @@ struct consfront_dev {
     char *nodename;
     char *backend;
 
-    xenbus_event_queue events;
+    struct xenbus_event_queue events;
 
 };
 
index f3594cb7082df490969470a06f18e137552d0457..4dad4c8444bc8a618a191266bde78d14c8793f40 100644 (file)
@@ -2,6 +2,7 @@
 #define MINIOS_XENBUS_H__
 
 #include <xen/io/xenbus.h>
+#include <mini-os/queue.h>
 
 typedef unsigned long xenbus_transaction_t;
 #define XBT_NIL ((xenbus_transaction_t)0)
@@ -25,22 +26,25 @@ struct xenbus_event {
     /* Keep these two as this for xs.c */
     char *path;
     char *token;
-    struct xenbus_event *next;
+    MINIOS_STAILQ_ENTRY(xenbus_event) entry;
 };
-typedef struct xenbus_event *xenbus_event_queue;
+struct xenbus_event_queue {
+    MINIOS_STAILQ_HEAD(, xenbus_event) events;
+};
+
+void xenbus_event_queue_init(struct xenbus_event_queue *queue);
 
-char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, xenbus_event_queue *events);
+char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, struct xenbus_event_queue *events);
 char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token);
-extern struct wait_queue_head xenbus_watch_queue;
-void xenbus_wait_for_watch(xenbus_event_queue *queue);
-char **xenbus_wait_for_watch_return(xenbus_event_queue *queue);
-char* xenbus_wait_for_value(const char *path, const char *value, xenbus_event_queue *queue);
-char *xenbus_wait_for_state_change(const char* path, XenbusState *state, xenbus_event_queue *queue);
+void xenbus_wait_for_watch(struct xenbus_event_queue *queue);
+char **xenbus_wait_for_watch_return(struct xenbus_event_queue *queue);
+char* xenbus_wait_for_value(const char *path, const char *value, struct xenbus_event_queue *queue);
+char *xenbus_wait_for_state_change(const char* path, XenbusState *state, struct xenbus_event_queue *queue);
 char *xenbus_switch_state(xenbus_transaction_t xbt, const char* path, XenbusState state);
 
 /* When no token is provided, use a global queue. */
 #define XENBUS_WATCH_PATH_TOKEN "xenbus_watch_path"
-extern xenbus_event_queue xenbus_events;
+extern struct xenbus_event_queue xenbus_events;
 #define xenbus_watch_path(xbt, path) xenbus_watch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN, NULL)
 #define xenbus_unwatch_path(xbt, path) xenbus_unwatch_path_token(xbt, path, XENBUS_WATCH_PATH_TOKEN)
 
index a9d43a2a305a23c9a8342a675e389e1f46a115ac..c85809d852b2bdde3c6f703c7525a9f1bbfd32f5 100644 (file)
@@ -45,7 +45,7 @@ struct blkfront_dev {
     char *backend;
     struct blkfront_info info;
 
-    xenbus_event_queue events;
+    struct xenbus_event_queue events;
 
 };
 
@@ -101,7 +101,7 @@ struct blkfront_dev *init_blkfront(char *_nodename, struct blkfront_info *info)
 
     dev->ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(s),0);
 
-    dev->events = NULL;
+    xenbus_event_queue_init(&dev->events);
 
 again:
     err = xenbus_transaction_start(&xbt);
index d848af880e5519a64121d6a420906d2664af0a83..a164314ca68fe1dcfc54be6b5220b5f9aee8f419 100644 (file)
@@ -96,7 +96,7 @@ struct consfront_dev *init_consfront(char *_nodename)
     memset(dev->ring, 0, PAGE_SIZE);
     dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->ring), 0);
 
-    dev->events = NULL;
+    xenbus_event_queue_init(&dev->events);
 
 again:
     err = xenbus_transaction_start(&xbt);
index 9e17a862132ac04cab020a3b284538820fe2df74..a89a0ddd9faddf44457bed4705da058d9dc84f0b 100644 (file)
@@ -51,7 +51,7 @@ struct netfront_dev {
     char *backend;
     char *mac;
 
-    xenbus_event_queue events;
+    struct xenbus_event_queue events;
 
 
     void (*netif_rx)(struct netfront_dev *, unsigned char* data, int len);
@@ -313,7 +313,7 @@ struct netfront_dev *init_netfront(char *_nodename, void (*thenetif_rx)(struct n
 
     dev->netif_rx = thenetif_rx;
 
-    dev->events = NULL;
+    xenbus_event_queue_init(&dev->events);
 
 again:
     err = xenbus_transaction_start(&xbt);
index 6f52b7788871b23a9848efca0d3f229b04b3df44..7bd3788adc338c24ece80c1d89f78cecaa35508d 100644 (file)
@@ -31,7 +31,7 @@ struct pcifront_dev {
     char *nodename;
     char *backend;
 
-    xenbus_event_queue events;
+    struct xenbus_event_queue events;
 };
 
 void pcifront_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
@@ -64,7 +64,8 @@ void pcifront_watches(void *opaque)
     char* nodename = opaque ? opaque : "device/pci/0";
     char path[strlen(nodename) + 9];
     char fe_state[strlen(nodename) + 7];
-    xenbus_event_queue events = NULL;
+    struct xenbus_event_queue events;
+    xenbus_event_queue_init(&events);
 
     snprintf(path, sizeof(path), "%s/backend", nodename);
     snprintf(fe_state, sizeof(fe_state), "%s/state", nodename);
@@ -174,7 +175,7 @@ struct pcifront_dev *init_pcifront(char *_nodename)
 
     dev->info_ref = gnttab_grant_access(dev->dom,virt_to_mfn(dev->info),0);
 
-    dev->events = NULL;
+    xenbus_event_queue_init(&dev->events);
 
 again:
     err = xenbus_transaction_start(&xbt);
index a06dc30c1c753462be30a7ed6c24eb2a4ed21da5..8a14c3b0805f24bbe6ae426e6c1b71a40b324449 100644 (file)
@@ -48,10 +48,10 @@ static DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
 static spinlock_t xb_lock = SPIN_LOCK_UNLOCKED; /* protects xenbus req ring */
 DECLARE_WAIT_QUEUE_HEAD(xenbus_watch_queue);
 
-xenbus_event_queue xenbus_events;
+struct xenbus_event_queue xenbus_events;
 static struct watch {
     char *token;
-    xenbus_event_queue *events;
+    struct xenbus_event_queue *events;
     struct watch *next;
 } *watches;
 struct xenbus_req_info 
@@ -61,6 +61,13 @@ struct xenbus_req_info
     void *reply;
 };
 
+
+void xenbus_event_queue_init(struct xenbus_event_queue *queue)
+{
+    MINIOS_STAILQ_INIT(&queue->events);
+}
+
+
 #define NR_REQS 32
 static struct xenbus_req_info req_info[NR_REQS];
 
@@ -78,22 +85,22 @@ static void memcpy_from_ring(const void *Ring,
     memcpy(dest + c1, ring, c2);
 }
 
-char **xenbus_wait_for_watch_return(xenbus_event_queue *queue)
+char **xenbus_wait_for_watch_return(struct xenbus_event_queue *queue)
 {
     struct xenbus_event *event;
     DEFINE_WAIT(w);
     if (!queue)
         queue = &xenbus_events;
-    while (!(event = *queue)) {
+    while (!(event = MINIOS_STAILQ_FIRST(&queue->events))) {
         add_waiter(w, xenbus_watch_queue);
         schedule();
     }
     remove_waiter(w, xenbus_watch_queue);
-    *queue = event->next;
+    MINIOS_STAILQ_REMOVE_HEAD(&queue->events, entry);
     return &event->path;
 }
 
-void xenbus_wait_for_watch(xenbus_event_queue *queue)
+void xenbus_wait_for_watch(struct xenbus_event_queue *queue)
 {
     char **ret;
     if (!queue)
@@ -105,7 +112,7 @@ void xenbus_wait_for_watch(xenbus_event_queue *queue)
         printk("unexpected path returned by watch\n");
 }
 
-char* xenbus_wait_for_value(const char* path, const char* value, xenbus_event_queue *queue)
+char* xenbus_wait_for_value(const char* path, const char* value, struct xenbus_event_queue *queue)
 {
     if (!queue)
         queue = &xenbus_events;
@@ -168,7 +175,7 @@ exit:
     return msg;
 }
 
-char *xenbus_wait_for_state_change(const char* path, XenbusState *state, xenbus_event_queue *queue)
+char *xenbus_wait_for_state_change(const char* path, XenbusState *state, struct xenbus_event_queue *queue)
 {
     if (!queue)
         queue = &xenbus_events;
@@ -227,7 +234,7 @@ static void xenbus_thread_func(void *ign)
             if(msg.type == XS_WATCH_EVENT)
             {
                struct xenbus_event *event = malloc(sizeof(*event) + msg.len);
-                xenbus_event_queue *events = NULL;
+                struct xenbus_event_queue *events = NULL;
                char *data = (char*)event + sizeof(*event);
                 struct watch *watch;
 
@@ -248,8 +255,7 @@ static void xenbus_thread_func(void *ign)
                     }
 
                 if (events) {
-                    event->next = *events;
-                    *events = event;
+                    MINIOS_STAILQ_INSERT_TAIL(&events->events, event, entry);
                     wake_up(&xenbus_watch_queue);
                 } else {
                     printk("unexpected watch token %s\n", event->token);
@@ -332,6 +338,7 @@ void init_xenbus(void)
 {
     int err;
     DEBUG("init_xenbus called.\n");
+    xenbus_event_queue_init(&xenbus_events);
     xenstore_buf = mfn_to_virt(start_info.store_mfn);
     create_thread("xenstore", xenbus_thread_func, NULL);
     DEBUG("buf at %p.\n", xenstore_buf);
@@ -561,7 +568,7 @@ char *xenbus_write(xenbus_transaction_t xbt, const char *path, const char *value
     return NULL;
 }
 
-char* xenbus_watch_path_token( xenbus_transaction_t xbt, const char *path, const char *token, xenbus_event_queue *events)
+char* xenbus_watch_path_token( xenbus_transaction_t xbt, const char *path, const char *token, struct xenbus_event_queue *events)
 {
     struct xsd_sockmsg *rep;