update buildrump.sh for new rumpsrc revison
.gitignore: Ignore things generated by build

Including the subtrees cloned adhoc.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
callmain: Provide a default app_main which calls main()

This allows the linking of programs which expect a conventional main().
For now we pass the command line as a single argument.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
callmain: Split up command line into separate arguments for main()

We understand '' and "" quoting, with \-escapes for ' and ", like a
shell would.  (Of course we don't interpolate ` or $ in "".)

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
mini-os: Make some headers more rumpkernel-friendly

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os: Provide <mini-os/queue.h>

Upstream (xen.git) minios has MINIOS_{,S}{LIST,TAILQ}_* (eg,
MINIOS_LIST_INSERT).  rumpuser-xen has {,S}{LIST,TAILQ}_* (eg,
LIST_INSERT) because it can #include <sys/queue.h>.

We want to try to make this code upstreamable (or at least no less
upstreamable than it already is).

So provide <mini-os/queue.h> which provides MINIOS_* in terms of
<sys/queue.h>.  That allows us to use MINIOS_* in the bulk of minios.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Add missing locks to xb_write

xb_write was missing any locking against concurrent calls.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Change type of xenbus_event_queue

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>
mini-os/xenbus: Use MINIOS_LIST for the list of watches

Remove the open-coded singly-linked list manipulation.

We replace it with a doubly-linked list because in forthcoming patches
we are going to want the ability to remove a watch from the middle of
the list without hunting for it first.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Rename xenbus_events to xenbus_default_watch_queue

This is only used for watch events, and only if xenbus's caller
doesn't specify a queue of their own.

Rename the variable because future patches are going to make the
current name confusing, because "event" is going to mean not just
watch events.

perl -i~ -pe 's/\bxenbus_events\b/xenbus_default_watch_queue/' xen/xenbus/xenbus.c include/mini-os/xenbus.h

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Unify watch and reply queues

We are going to want to provide an interface to xenbus which does not
reorder messages for a particular user.  In particular, the reply to a
watch or unwatch should not be reordered with respect to watch events.

To this end we arrange that both replies and watches use the same kind
of queue inside the xenbus driver.  Currently this queue type is only
exposed outside the xenbus driver for use with watches, as before.

Important functional changes in this patch include:

* There is a separate scheduler wait queue for each reply queue,
  rather than one for all watches and one for each outstanding reply.
  This wait queue lives in the reply queue struct.

* There are abstracted-away internal functions for removing (and,
  indeed, awaiting) events.  xenbus_wait_for_watch_return becomes a
  trivial wrapper around await_event.

* Handling of the replies to requests is formalised, using the new
  queues.  Now a single reply queue might be used for multiple
  requests (although there are no callers that do this).

Other changes are:

* The latent bug in xenbus_msg_reply, which assumed no spurious
  wakeups, is gone.

* The "in_use" flag in the request array can be done away with, since
  we can use the reply_queue pointer value instead.

* The callers of allocate_xenbus_id (currently, only
  xenbus_msg_reply), have to initialise a xenbus_event_queue and
  provide it to allocate_xenbus_id.

* Abolished the xenbus_watch_queue waitq in favour of the waitq inside
  the xenbus_default_watch_events event queue.

* Abolished a duplicate assignment to in_use in release_xenbus_id.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Expose lower-level interface

Provide an interface that allows a xenbus user to explicitly allocate
ids, deal with responses asynchronously, specify the queues to be used
for responses and watches, etc.

More specifically:

* Enhance xenbus_event to be capable of dealing with both watches and
  command replies.  In particular, arrange that it will contain a
  pointer to the watch.  We leave the old fields undisturbed because
  of the way that this struct is already used in various places.

* Provide that a xenbus_event for a command response contains a copy
  of the pointer to the reply message, rather than putting it in the
  req_info (which is visible only internally).

* Rename `struct watch' to `struct xenbus_watch' because it needs
  to be in the public interface.

* allocate_xenbus_id becomes xenbus_id_allocate; same for release.

* Make xb_write into a public function, xenbus_xb_write.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Sort out request and watch locking

Make the xenbus_req_lock public, and lock it everywhere it is needed.
It needs to protect not just the xenbus request ring itself, but also
a number of internal data structures.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
mini-os/xenbus: Provide queue->wakeup hook

This allows xenbus's caller to get called back when an item is put on
the queue, rather than simply having the waitq signaled.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
mini-os/xenbus: Provide xenbus_free

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
rumpxendev: Provide /dev/xen/xenbus

This is a new rumpkernel component which provides an interface to the
minios xenbus driver.  It presents as /dev/xen/xenbus which speaks the
standard xenstore protocol and can be used in the normal way by all
the tools (including with poll or select).

Internally, it arranges to use the xenbus driver's ability to
multiplex requests, responses and watch events from multiple users.
So it can be used in parallel with all existing rump kernel
functionality.  The device can also perhaps be opened more than once.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>