[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] PATCH: 1/2: Make the event loop & RPC dispatch threaded



This patch does the bulk of the work for thread support in the daemon

The first part deals with the event loop, making all its functions
thread-safe by adding mutex locking in appropriate places. There's a
interesting problem in that one thread may want to add/remove FDs to
the event loop, while another thread is sleeping in poll(). Thus we
utilize the self-pipe trick, adding the 'read' end of the pipe to the
FDs that are monitored. When one thread needs to break another out
of the poll() wait, it writes a single byte to the pipe.

The second part deals with the RPC call dispatch process. THe model
is that one thread is responsible for all network I/O, accepting new
clients, doing the poll(), and reading/writing the data for the RPC
messages. When a complete message has been read off the wire, the
correspondig  struct qemud_client is marked as having a pending RPC
call to dispatch. A pool of worker threads wait on a condition variable
for available RPC calls to dispatch. We avoid a fixed 1-to-1 worker
to client  model since that's needlessly wasteful of resources when
most clients are idle most of the time. This patch hardcodes the worker
pool size to 10, but the next patch makes it configurable. When a
worker thread has finished dispatching a RPC call, the reply data is
placed in the client outbound buffer, and its marked ready for 
transmit, at which point the main thread performs the I/O op.

There is also one final round of tweaking the contract of the RPC
handler methods. We explicitly pass in the virConnectPtr object to
the RPC handlers. This means that 99% of them never need directly
access the 'struct qemud_client' object, and thus the client object
can be left unlocked for the duration of the libvirt API call.
This is an important point for getting good parallelization.

NB, yes there are lots of fprintf() calls in this patch still. They
will be removed next time I post it when we're in a position to
actually commit.

 THREADING.txt                |   63 ++
 event.c                      |  147 ++++-
 event.h                      |   15 
 qemud.c                      |  227 ++++++--
 qemud.h                      |   25 
 remote.c                     | 1148 ++++++++++++++++++++++---------------------
 remote_dispatch_prototypes.h |  832 +++++++++++++++++++++++++++----
 remote_generate_stubs.pl     |    8 
 8 files changed, 1746 insertions(+), 719 deletions(-)


Daniel

diff --git a/qemud/THREADING.txt b/qemud/THREADING.txt
new file mode 100644
--- /dev/null
+++ b/qemud/THREADING.txt
@@ -0,0 +1,63 @@
+
+     Threading: the RULES.
+     ====================
+
+If you don't understand this, don't touch the code. Ask for
+further advice / explanation on the mailing list first.
+
+ - the top level lock is on 'struct qemud_server'. This must be
+   held before acquiring any other lock
+
+ - Each 'struct qemud_client' object has a lock. The server lock
+   must be held before acquiring it. Once the client lock is acquired
+   the server lock can (optionally) be dropped.
+
+ - The event loop has its own self-contained lock. You can ignore
+   this as a caller of virEvent APIs.
+
+
+The server lock is only needed / used once the daemon has entered
+its main loop, which is the qemudRunLoop() . The initial thread
+acquires the lock upon entering this method.
+
+It immediatelty spawns 'n' worker threads, whose main loop is
+the qemudWorker() method. The workers will immediately try to
+acquire the server lock, and thus block since its held by the
+initial thread.
+
+When the initial thread enters the poll() call, it drops the
+server lock. The worker locks now each wakeup, acquire the
+server lock and go into a condition wait on the 'job' condition
+variable. The workers are now all 'primed' for incoming RPC
+calls.
+
+
+
+A file descriptor event now occurrs, causing the initial thread
+to exit poll(). It invokes the registered callback associated
+with the file descriptors on which the event occurrs. The callbacks
+are required to immediately acquire the server lock.
+
+If the callback is dealing with a client event, it will then
+acquire the client lock, and drop the server lock.
+
+The callback will now handle the I/O event, reading or writing
+a RPC message. Once a complete RPC message has been read the
+client is marked as being in state QEMUD_MODE_WAIT_DISPATCH,
+and the 'job' condition variable is signaled. The callback
+now drops the client lock and goes back into the poll() loop
+waiting for more I/O events.
+
+Meanwhile one of the worker threads wakes up from its condition
+variable sleep, holding the server lock. It now searches for a
+client in state QEMUD_MODE_WAIT_DISPATCH. If it doesn't find
+one, it goes back to sleep. If it does find one, then it calls
+into the remoteDispatchClientRequest() method de-serialize the
+incoming message into an XDR object and invoke the helper method
+for the associated RPC call.
+
+While the helper method is executing, no locks are held on either
+the client or server, but the ref count on the 'struct qemud_client'
+object is incremented to ensure its not deleted. The helper can
+now safely invoke the neccessary libvirt API call.
+
diff --git a/qemud/event.c b/qemud/event.c
--- a/qemud/event.c
+++ b/qemud/event.c
@@ -28,12 +28,16 @@
 #include <poll.h>
 #include <sys/time.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include "qemud.h"
 #include "event.h"
 #include "memory.h"
+#include "util-lib.h"
 
 #define EVENT_DEBUG(fmt, ...) qemudDebug("EVENT: " fmt, __VA_ARGS__)
+
+static int virEventInterruptLocked(void);
 
 /* State for a single file handle being monitored */
 struct virEventHandle {
@@ -60,6 +64,9 @@ struct virEventTimeout {
 
 /* State for the main event loop */
 struct virEventLoop {
+    pthread_mutex_t lock;
+    pthread_t leader;
+    int wakeupfd[2];
     int handlesCount;
     int handlesAlloc;
     struct virEventHandle *handles;
@@ -68,6 +75,12 @@ struct virEventLoop {
     struct virEventTimeout *timeouts;
 };
 
+#define EVENT_LOCK(ret) do { if (pthread_mutex_lock(&eventLoop.lock) != 0) return (ret); } while (0)
+#define EVENT_UNLOCK(ret) do { if (pthread_mutex_unlock(&eventLoop.lock) != 0) return (ret); } while (0)
+
+#define EVENT_LOCK0() do { if (pthread_mutex_lock(&eventLoop.lock) != 0) return; } while (0)
+#define EVENT_UNLOCK0() do { if (pthread_mutex_unlock(&eventLoop.lock) != 0) return; } while (0)
+
 /* Only have one event loop */
 static struct virEventLoop eventLoop;
 
@@ -82,12 +95,15 @@ static int nextTimer = 0;
  */
 int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque) {
     EVENT_DEBUG("Add handle %d %d %p %p", fd, events, cb, opaque);
+    EVENT_LOCK(-1);
     if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
         EVENT_DEBUG("Used %d handle slots, adding %d more",
                     eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
         if (VIR_REALLOC_N(eventLoop.handles,
-                          (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT)) < 0)
+                          (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT)) < 0) {
+            EVENT_UNLOCK(-1);
             return -1;
+        }
         eventLoop.handlesAlloc += EVENT_ALLOC_EXTENT;
     }
 
@@ -99,17 +115,22 @@ int virEventAddHandleImpl(int fd, int ev
 
     eventLoop.handlesCount++;
 
+    virEventInterruptLocked();
+    EVENT_UNLOCK(-1);
     return 0;
 }
 
 void virEventUpdateHandleImpl(int fd, int events) {
     int i;
+    EVENT_LOCK0();
     for (i = 0 ; i < eventLoop.handlesCount ; i++) {
         if (eventLoop.handles[i].fd == fd) {
             eventLoop.handles[i].events = events;
             break;
         }
     }
+    virEventInterruptLocked();
+    EVENT_UNLOCK0();
 }
 
 /*
@@ -121,6 +142,7 @@ int virEventRemoveHandleImpl(int fd) {
 int virEventRemoveHandleImpl(int fd) {
     int i;
     EVENT_DEBUG("Remove handle %d", fd);
+    EVENT_LOCK(-1);
     for (i = 0 ; i < eventLoop.handlesCount ; i++) {
         if (eventLoop.handles[i].deleted)
             continue;
@@ -128,9 +150,12 @@ int virEventRemoveHandleImpl(int fd) {
         if (eventLoop.handles[i].fd == fd) {
             EVENT_DEBUG("mark delete %d", i);
             eventLoop.handles[i].deleted = 1;
+            EVENT_UNLOCK(-1);
             return 0;
         }
     }
+    virEventInterruptLocked();
+    EVENT_UNLOCK(-1);
     return -1;
 }
 
@@ -142,17 +167,21 @@ int virEventRemoveHandleImpl(int fd) {
  */
 int virEventAddTimeoutImpl(int frequency, virEventTimeoutCallback cb, void *opaque) {
     struct timeval now;
+    int ret;
     EVENT_DEBUG("Adding timer %d with %d ms freq", nextTimer, frequency);
     if (gettimeofday(&now, NULL) < 0) {
         return -1;
     }
 
+    EVENT_LOCK(-1);
     if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) {
         EVENT_DEBUG("Used %d timeout slots, adding %d more",
                     eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
         if (VIR_REALLOC_N(eventLoop.timeouts,
-                          (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT)) < 0)
+                          (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT)) < 0) {
+            EVENT_UNLOCK(-1);
             return -1;
+        }
         eventLoop.timeoutsAlloc += EVENT_ALLOC_EXTENT;
     }
 
@@ -167,8 +196,10 @@ int virEventAddTimeoutImpl(int frequency
         (((unsigned long long)now.tv_usec)/1000) : 0;
 
     eventLoop.timeoutsCount++;
-
-    return nextTimer-1;
+    ret = nextTimer-1;
+    virEventInterruptLocked();
+    EVENT_UNLOCK(-1);
+    return ret;
 }
 
 void virEventUpdateTimeoutImpl(int timer, int frequency) {
@@ -179,6 +210,7 @@ void virEventUpdateTimeoutImpl(int timer
         return;
     }
 
+    EVENT_LOCK0();
     for (i = 0 ; i < eventLoop.timeoutsCount ; i++) {
         if (eventLoop.timeouts[i].timer == timer) {
             eventLoop.timeouts[i].frequency = frequency;
@@ -189,6 +221,8 @@ void virEventUpdateTimeoutImpl(int timer
             break;
         }
     }
+    virEventInterruptLocked();
+    EVENT_UNLOCK0();
 }
 
 /*
@@ -200,15 +234,19 @@ int virEventRemoveTimeoutImpl(int timer)
 int virEventRemoveTimeoutImpl(int timer) {
     int i;
     EVENT_DEBUG("Remove timer %d", timer);
+    EVENT_LOCK(-1);
     for (i = 0 ; i < eventLoop.timeoutsCount ; i++) {
         if (eventLoop.timeouts[i].deleted)
             continue;
 
         if (eventLoop.timeouts[i].timer == timer) {
             eventLoop.timeouts[i].deleted = 1;
+            EVENT_UNLOCK(-1);
             return 0;
         }
     }
+    virEventInterruptLocked();
+    EVENT_UNLOCK(-1);
     return -1;
 }
 
@@ -276,7 +314,8 @@ static int virEventMakePollFDs(struct po
         return -1;
 
     for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) {
-        if (eventLoop.handles[i].deleted)
+        if (eventLoop.handles[i].deleted ||
+            !eventLoop.handles[i].events)
             continue;
         fds[nfds].fd = eventLoop.handles[i].fd;
         fds[nfds].events = eventLoop.handles[i].events;
@@ -320,10 +359,15 @@ static int virEventDispatchTimeouts(void
             continue;
 
         if (eventLoop.timeouts[i].expiresAt <= now) {
-            (eventLoop.timeouts[i].cb)(eventLoop.timeouts[i].timer,
-                                       eventLoop.timeouts[i].opaque);
+            virEventTimeoutCallback cb = eventLoop.timeouts[i].cb;
+            int timer = eventLoop.timeouts[i].timer;
+            void *opaque = eventLoop.timeouts[i].opaque;
             eventLoop.timeouts[i].expiresAt =
                 now + eventLoop.timeouts[i].frequency;
+
+            EVENT_UNLOCK(-1);
+            (cb)(timer, opaque);
+            EVENT_LOCK(-1);
         }
     }
     return 0;
@@ -340,21 +384,23 @@ static int virEventDispatchTimeouts(void
  *
  * Returns 0 upon success, -1 if an error occurred
  */
-static int virEventDispatchHandles(struct pollfd *fds) {
+static int virEventDispatchHandles(int nfds, struct pollfd *fds) {
     int i;
-    /* Save this now - it may be changed during dispatch */
-    int nhandles = eventLoop.handlesCount;
 
-    for (i = 0 ; i < nhandles ; i++) {
+    for (i = 0 ; i < nfds ; i++) {
         if (eventLoop.handles[i].deleted) {
             EVENT_DEBUG("Skip deleted %d", eventLoop.handles[i].fd);
             continue;
         }
 
         if (fds[i].revents) {
-            EVENT_DEBUG("Dispatch %d %d %p", fds[i].fd, fds[i].revents, eventLoop.handles[i].opaque);
-            (eventLoop.handles[i].cb)(fds[i].fd, fds[i].revents,
-                                      eventLoop.handles[i].opaque);
+            virEventHandleCallback cb = eventLoop.handles[i].cb;
+            void *opaque = eventLoop.handles[i].opaque;
+            EVENT_DEBUG("Dispatch %d %d %p", fds[i].fd,
+                        fds[i].revents, eventLoop.handles[i].opaque);
+            EVENT_UNLOCK(-1);
+            (cb)(fds[i].fd, fds[i].revents, opaque);
+            EVENT_LOCK(-1);
         }
     }
 
@@ -443,13 +489,20 @@ int virEventRunOnce(void) {
     struct pollfd *fds;
     int ret, timeout, nfds;
 
-    if ((nfds = virEventMakePollFDs(&fds)) < 0)
+    EVENT_LOCK(-1);
+    eventLoop.leader = pthread_self();
+    if ((nfds = virEventMakePollFDs(&fds)) < 0) {
+        EVENT_UNLOCK(-1);
         return -1;
+    }
 
     if (virEventCalculateTimeout(&timeout) < 0) {
         VIR_FREE(fds);
+        EVENT_UNLOCK(-1);
         return -1;
     }
+
+    EVENT_UNLOCK(-1);
 
  retry:
     EVENT_DEBUG("Poll on %d handles %p timeout %d", nfds, fds, timeout);
@@ -462,23 +515,81 @@ int virEventRunOnce(void) {
         VIR_FREE(fds);
         return -1;
     }
+
+    EVENT_LOCK(-1);
     if (virEventDispatchTimeouts() < 0) {
         VIR_FREE(fds);
+        EVENT_UNLOCK(-1);
         return -1;
     }
 
     if (ret > 0 &&
-        virEventDispatchHandles(fds) < 0) {
+        virEventDispatchHandles(nfds, fds) < 0) {
         VIR_FREE(fds);
+        EVENT_UNLOCK(-1);
         return -1;
     }
     VIR_FREE(fds);
 
-    if (virEventCleanupTimeouts() < 0)
+    if (virEventCleanupTimeouts() < 0) {
+        EVENT_UNLOCK(-1);
+        return -1;
+    }
+
+    if (virEventCleanupHandles() < 0) {
+        EVENT_UNLOCK(-1);
+        return -1;
+    }
+
+    eventLoop.leader = 0;
+    EVENT_UNLOCK(-1);
+    return 0;
+}
+
+static void virEventHandleWakeup(int fd,
+                                 int events ATTRIBUTE_UNUSED,
+                                 void *opaque ATTRIBUTE_UNUSED)
+{
+    char c;
+    EVENT_LOCK0();
+    saferead(fd, &c, sizeof(c));
+    EVENT_UNLOCK0();
+}
+
+int virEventInit(void)
+{
+    if (pthread_mutex_init(&eventLoop.lock, NULL) != 0)
         return -1;
 
-    if (virEventCleanupHandles() < 0)
+    if (pipe(eventLoop.wakeupfd) < 0 ||
+        qemudSetNonBlock(eventLoop.wakeupfd[0]) < 0 ||
+        qemudSetNonBlock(eventLoop.wakeupfd[1]) < 0 ||
+        qemudSetCloseExec(eventLoop.wakeupfd[0]) < 0 ||
+        qemudSetCloseExec(eventLoop.wakeupfd[1]) < 0)
+        return -1;
+
+    if (virEventAddHandleImpl(eventLoop.wakeupfd[0], POLLIN, virEventHandleWakeup, NULL) < 0)
         return -1;
 
     return 0;
 }
+
+static int virEventInterruptLocked(void)
+{
+    char c = '\0';
+    if (pthread_self() == eventLoop.leader)
+        return 0;
+
+    if (safewrite(eventLoop.wakeupfd[1], &c, sizeof(c)) != sizeof(c))
+        return -1;
+    return 0;
+}
+
+int virEventInterrupt(void)
+{
+    int ret;
+    EVENT_LOCK(-1);
+    ret = virEventInterruptLocked();
+    EVENT_UNLOCK(-1);
+    return ret;
+}
diff --git a/qemud/event.h b/qemud/event.h
--- a/qemud/event.h
+++ b/qemud/event.h
@@ -95,6 +95,13 @@ int virEventRemoveTimeoutImpl(int timer)
 int virEventRemoveTimeoutImpl(int timer);
 
 /**
+ * virEventInit: Initialize the event loop
+ * 
+ * returns -1 if initialization failed
+ */
+int virEventInit(void);
+
+/**
  * virEventRunOnce: run a single iteration of the event loop.
  *
  * Blocks the caller until at least one file handle has an
@@ -104,4 +111,12 @@ int virEventRemoveTimeoutImpl(int timer)
  */
 int virEventRunOnce(void);
 
+
+/**
+ * virEventInterrupt: wakeup any thread waiting in poll()
+ *
+ * return -1 if wakup failed 
+ */
+int virEventInterrupt(void);
+
 #endif /* __VIRTD_EVENT_H__ */
diff --git a/qemud/qemud.c b/qemud/qemud.c
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -237,9 +237,12 @@ static void qemudDispatchSignalEvent(int
     siginfo_t siginfo;
     int ret;
 
+    pthread_mutex_lock(&server->lock);
+
     if (saferead(server->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
         qemudLog(QEMUD_ERR, _("Failed to read from signal pipe: %s"),
                  strerror(errno));
+        pthread_mutex_unlock(&server->lock);
         return;
     }
 
@@ -269,9 +272,11 @@ static void qemudDispatchSignalEvent(int
 
     if (ret != 0)
         server->shutdown = 1;
+
+    pthread_mutex_unlock(&server->lock);
 }
 
-static int qemudSetCloseExec(int fd) {
+int qemudSetCloseExec(int fd) {
     int flags;
     if ((flags = fcntl(fd, F_GETFD)) < 0)
         goto error;
@@ -286,7 +291,7 @@ static int qemudSetCloseExec(int fd) {
 }
 
 
-static int qemudSetNonBlock(int fd) {
+int qemudSetNonBlock(int fd) {
     int flags;
     if ((flags = fcntl(fd, F_GETFL)) < 0)
         goto error;
@@ -721,7 +726,18 @@ static struct qemud_server *qemudInitial
         return NULL;
     }
 
+    if (pthread_mutex_init(&server->lock, NULL) != 0) {
+        VIR_FREE(server);
+        return NULL;
+    }
+
     server->sigread = sigread;
+
+    if (virEventInit() < 0) {
+        qemudLog(QEMUD_ERR, "%s", _("Failed to initialize event system"));
+        VIR_FREE(server);
+        return NULL;
+    }
 
     __virEventRegisterImpl(virEventAddHandleImpl,
                            virEventUpdateHandleImpl,
@@ -1085,7 +1101,7 @@ static int qemudDispatchServer(struct qe
         qemudLog(QEMUD_ERR, _("Failed to accept connection: %s"), strerror(errno));
         return -1;
     }
-
+    fprintf(stderr, "New client %d\n", fd);
     if (VIR_REALLOC_N(server->clients, server->nclients+1) < 0) {
         qemudLog(QEMUD_ERR, "%s", _("Out of memory allocating clients"));
         close(fd);
@@ -1104,6 +1120,9 @@ static int qemudDispatchServer(struct qe
 
     if (VIR_ALLOC(client) < 0)
         goto cleanup;
+    if (pthread_mutex_init(&client->lock, NULL) != 0)
+        goto cleanup;
+
     client->magic = QEMUD_CLIENT_MAGIC;
     client->fd = fd;
     client->readonly = sock->readonly;
@@ -1176,35 +1195,18 @@ static int qemudDispatchServer(struct qe
     return 0;
 
  cleanup:
-    if (client->tlssession) gnutls_deinit (client->tlssession);
+    if (client &&
+        client->tlssession) gnutls_deinit (client->tlssession);
     close (fd);
     free (client);
     return -1;
 }
 
 
-
-
-static void qemudDispatchClientFailure(struct qemud_server *server, struct qemud_client *client) {
-    int i, n = -1;
-    for (i = 0 ; i < server->nclients ; i++) {
-        if (server->clients[i] == client) {
-            n = i;
-            break;
-        }
-    }
-    if (n != -1) {
-        if (n < (server->nclients-1))
-            memmove(server->clients + n,
-                    server->clients + n + 1,
-                    server->nclients - (n + 1));
-        server->nclients--;
-    }
-
+/* You must hold lock for at least the client */
+static void qemudDispatchClientFailure(struct qemud_server *server ATTRIBUTE_UNUSED,
+                                       struct qemud_client *client) {
     virEventRemoveHandleImpl(client->fd);
-
-    if (client->conn)
-        virConnectClose(client->conn);
 
 #if HAVE_SASL
     if (client->saslconn) sasl_dispose(&client->saslconn);
@@ -1212,9 +1214,59 @@ static void qemudDispatchClientFailure(s
 #endif
     if (client->tlssession) gnutls_deinit (client->tlssession);
     close(client->fd);
-    free(client);
+    client->fd = -1;
 }
 
+
+/* Caller must hold server lock */
+static struct qemud_client *qemudPendingJob(struct qemud_server *server)
+{
+    int i;
+    for (i = 0 ; i < server->nclients ; i++) {
+        pthread_mutex_lock(&server->clients[i]->lock);
+        if (server->clients[i]->mode == QEMUD_MODE_WAIT_DISPATCH) {
+            /* Delibrately don't unlock client - caller wants the lock */
+            return server->clients[i];
+        }
+        pthread_mutex_unlock(&server->clients[i]->lock);
+    }
+    return NULL;
+}
+
+static void *qemudWorker(void *data)
+{
+    struct qemud_server *server = data;
+    fprintf(stderr, "Hello from worker %d\n", (int)pthread_self());
+    while (1) {
+        struct qemud_client *client;
+        int len;
+        pthread_mutex_lock(&server->lock);
+        while ((client = qemudPendingJob(server)) == NULL)
+            pthread_cond_wait(&server->job, &server->lock);
+        pthread_mutex_unlock(&server->lock);
+
+        /* We own a locked client now... */
+        client->mode = QEMUD_MODE_IN_DISPATCH;
+        client->refs++;
+        fprintf(stderr, "Worker %d got a job %p %d\n", (int)pthread_self(), client, client->fd);
+
+        if ((len = remoteDispatchClientRequest (server, client)) == 0)
+            qemudDispatchClientFailure(server, client);
+
+        fprintf(stderr, "Worker %d finished job %p %d\n", (int)pthread_self(), client, client->fd);
+        /* Set up the output buffer. */
+        client->mode = QEMUD_MODE_TX_PACKET;
+        client->bufferLength = len;
+        client->bufferOffset = 0;
+
+        if (qemudRegisterClientEvent(server, client, 0) < 0)
+            qemudDispatchClientFailure(server, client);
+
+        client->refs--;
+        pthread_mutex_unlock(&client->lock);
+        pthread_mutex_unlock(&server->lock);
+    }
+}
 
 
 static int qemudClientReadBuf(struct qemud_server *server,
@@ -1380,16 +1432,12 @@ static void qemudDispatchClientRead(stru
         if (client->bufferOffset < client->bufferLength)
             return; /* Not read enough */
 
-        if ((len = remoteDispatchClientRequest (server, client)) == 0)
+        client->mode = QEMUD_MODE_WAIT_DISPATCH;
+        if (qemudRegisterClientEvent(server, client, 1) < 0)
             qemudDispatchClientFailure(server, client);
 
-        /* Set up the output buffer. */
-        client->mode = QEMUD_MODE_TX_PACKET;
-        client->bufferLength = len;
-        client->bufferOffset = 0;
-
-        if (qemudRegisterClientEvent(server, client, 1) < 0)
-            qemudDispatchClientFailure(server, client);
+        fprintf(stderr, "Waking up a worker for queued job %p\n", client);
+        pthread_cond_signal(&server->job);
 
         break;
     }
@@ -1520,13 +1568,17 @@ static void qemudDispatchClientWrite(str
             return;
 
         if (client->bufferOffset == client->bufferLength) {
-            /* Done writing, switch back to receive */
-            client->mode = QEMUD_MODE_RX_HEADER;
-            client->bufferLength = REMOTE_MESSAGE_HEADER_XDR_LEN;
-            client->bufferOffset = 0;
+            if (client->closing) {
+                qemudDispatchClientFailure (server, client);
+            } else {
+                /* Done writing, switch back to receive */
+                client->mode = QEMUD_MODE_RX_HEADER;
+                client->bufferLength = REMOTE_MESSAGE_HEADER_XDR_LEN;
+                client->bufferOffset = 0;
 
-            if (qemudRegisterClientEvent (server, client, 1) < 0)
-                qemudDispatchClientFailure (server, client);
+                if (qemudRegisterClientEvent (server, client, 1) < 0)
+                    qemudDispatchClientFailure (server, client);
+            }
         }
         /* Still writing */
         break;
@@ -1567,6 +1619,8 @@ static void qemudDispatchClientEvent(int
     struct qemud_client *client = NULL;
     int i;
 
+    pthread_mutex_lock(&server->lock);
+
     for (i = 0 ; i < server->nclients ; i++) {
         if (server->clients[i]->fd == fd) {
             client = server->clients[i];
@@ -1574,8 +1628,13 @@ static void qemudDispatchClientEvent(int
         }
     }
 
-    if (!client)
+    if (!client) {
+        pthread_mutex_unlock(&server->lock);
         return;
+    }
+
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
 
     if (events == POLLOUT)
         qemudDispatchClientWrite(server, client);
@@ -1583,6 +1642,7 @@ static void qemudDispatchClientEvent(int
         qemudDispatchClientRead(server, client);
     else
         qemudDispatchClientFailure(server, client);
+    pthread_mutex_unlock(&client->lock);
 }
 
 static int qemudRegisterClientEvent(struct qemud_server *server,
@@ -1606,6 +1666,10 @@ static int qemudRegisterClientEvent(stru
         mode = POLLOUT;
         break;
 
+    case QEMUD_MODE_WAIT_DISPATCH:
+        mode = 0;
+        break;
+
     default:
         return -1;
     }
@@ -1614,18 +1678,24 @@ static int qemudRegisterClientEvent(stru
         if (virEventRemoveHandleImpl(client->fd) < 0)
             return -1;
 
-    if (virEventAddHandleImpl(client->fd,
-                              mode | POLLERR | POLLHUP,
-                              qemudDispatchClientEvent,
-                              server) < 0)
+    if (mode) {
+        if (virEventAddHandleImpl(client->fd,
+                                  mode | POLLERR | POLLHUP,
+                                  qemudDispatchClientEvent,
+                                  server) < 0)
             return -1;
+    }
 
     return 0;
 }
 
 static void qemudDispatchServerEvent(int fd, int events, void *opaque) {
     struct qemud_server *server = (struct qemud_server *)opaque;
-    struct qemud_socket *sock = server->sockets;
+    struct qemud_socket *sock;
+
+    pthread_mutex_lock(&server->lock);
+
+    sock = server->sockets;
 
     while (sock) {
         if (sock->fd == fd)
@@ -1634,11 +1704,10 @@ static void qemudDispatchServerEvent(int
         sock = sock->next;
     }
 
-    if (!sock)
-        return;
+    if (sock && events)
+        qemudDispatchServer(server, sock);
 
-    if (events)
-        qemudDispatchServer(server, sock);
+    pthread_mutex_unlock(&server->lock);
 }
 
 
@@ -1672,6 +1741,26 @@ static void qemudInactiveTimer(int timer
 
 static int qemudRunLoop(struct qemud_server *server) {
     int timerid = -1;
+    int ret = -1, i;
+
+    pthread_mutex_lock(&server->lock);
+
+    server->nworkers = 10;
+    if (VIR_ALLOC_N(server->workers, server->nworkers) < 0) {
+        qemudLog(QEMUD_ERR, "%s", _("Failed to allocate workers"));
+        return -1;
+    }
+
+    for (i = 0 ; i < server->nworkers ; i++) {
+        pthread_attr_t attr;
+        pthread_attr_init(&attr);
+        pthread_attr_setdetachstate(&attr, 1);
+
+        pthread_create(&server->workers[i],
+                       &attr,
+                       qemudWorker,
+                       server);
+    }
 
     for (;;) {
         /* A shutdown timeout is specified, so check
@@ -1683,8 +1772,30 @@ static int qemudRunLoop(struct qemud_ser
             qemudDebug("Scheduling shutdown timer %d", timerid);
         }
 
+        pthread_mutex_unlock(&server->lock);
         if (qemudOneLoop() < 0)
             break;
+        pthread_mutex_lock(&server->lock);
+
+    reprocess:
+        for (i = 0 ; i < server->nclients ; i++) {
+            int inactive;
+            pthread_mutex_lock(&server->clients[i]->lock);
+            inactive = server->clients[i]->fd == -1;
+            pthread_mutex_unlock(&server->clients[i]->lock);
+            if (inactive) {
+                if (server->clients[i]->conn)
+                    virConnectClose(server->clients[i]->conn);
+                VIR_FREE(server->clients[i]);
+                server->nclients--;
+                if (i < server->nclients) {
+                    memmove(server->clients + i,
+                            server->clients + i + 1,
+                            server->nclients - i);
+                    goto reprocess;
+                }
+            }
+        }
 
         /* Unregister any timeout that's active, since we
          * just had an event processed
@@ -1695,11 +1806,21 @@ static int qemudRunLoop(struct qemud_ser
             timerid = -1;
         }
 
-        if (server->shutdown)
-            return 0;
+        if (server->shutdown) {
+            ret = 0;
+            break;
+        }
     }
 
-    return -1;
+    for (i = 0 ; i < server->nworkers ; i++) {
+        pthread_t thread = server->workers[i];
+        pthread_mutex_unlock(&server->lock);
+        pthread_join(thread, NULL);
+        pthread_mutex_lock(&server->lock);
+    }
+
+    pthread_mutex_unlock(&server->lock);
+    return ret;
 }
 
 static void qemudCleanup(struct qemud_server *server) {
diff --git a/qemud/qemud.h b/qemud/qemud.h
--- a/qemud/qemud.h
+++ b/qemud/qemud.h
@@ -74,10 +74,12 @@ typedef enum {
 
 
 enum qemud_mode {
-    QEMUD_MODE_RX_HEADER,
-    QEMUD_MODE_RX_PAYLOAD,
-    QEMUD_MODE_TX_PACKET,
-    QEMUD_MODE_TLS_HANDSHAKE,
+    QEMUD_MODE_RX_HEADER,       /* Receiving the fixed length RPC header data */
+    QEMUD_MODE_RX_PAYLOAD,      /* Receiving the variable length RPC payload data */
+    QEMUD_MODE_WAIT_DISPATCH,   /* Message received, waiting for worker to process */
+    QEMUD_MODE_IN_DISPATCH,     /* RPC call being processed */
+    QEMUD_MODE_TX_PACKET,       /* Transmitting reply to RPC call */
+    QEMUD_MODE_TLS_HANDSHAKE,   /* Performing TLS handshake */
 };
 
 /* Whether we're passing reads & writes through a sasl SSF */
@@ -95,10 +97,13 @@ enum qemud_sock_type {
 
 /* Stores the per-client connection state */
 struct qemud_client {
+    pthread_mutex_t lock; /* You must own  qemud_server's lock before acquiring this */
+
     int magic;
 
     int fd;
-    int readonly;
+    int readonly:1;
+    int closing:1;
     enum qemud_mode mode;
 
     struct sockaddr_storage addr;
@@ -131,6 +136,7 @@ struct qemud_client {
      * called, it will be set back to NULL if that succeeds.
      */
     virConnectPtr conn;
+    int refs;
 };
 
 #define QEMUD_CLIENT_MAGIC 0x7788aaee
@@ -147,10 +153,16 @@ struct qemud_socket {
 
 /* Main server state */
 struct qemud_server {
+    pthread_mutex_t lock;
+    pthread_cond_t job;
+
+    int nworkers;
+    pthread_t *workers;
     int nsockets;
     struct qemud_socket *sockets;
     int nclients;
     struct qemud_client **clients;
+
     int sigread;
     char logDir[PATH_MAX];
     unsigned int shutdown : 1;
@@ -174,6 +186,9 @@ void qemudLog(int priority, const char *
 #define qemudDebug(fmt, ...) do {} while(0)
 #endif
 
+int qemudSetCloseExec(int fd);
+int qemudSetNonBlock(int fd);
+
 unsigned int
 remoteDispatchClientRequest (struct qemud_server *server,
                              struct qemud_client *client);
diff --git a/qemud/remote.c b/qemud/remote.c
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -77,8 +77,22 @@ typedef union {
 } dispatch_ret;
 
 
+/**
+ * When the RPC handler is called:
+ *
+ *  - Server object is unlocked
+ *  - Client object is unlocked
+ * 
+ * Both must be locked before use. Server lock must
+ * be held before attempting to lock client.
+ *
+ * Without any locking, it is safe to use:
+ *
+ *   'conn', 'rerr', 'args and 'ret'
+ */
 typedef int (*dispatch_fn) (struct qemud_server *server,
                             struct qemud_client *client,
+                            virConnectPtr conn,
                             remote_error *err,
                             dispatch_args *args,
                             dispatch_ret *ret);
@@ -193,6 +207,9 @@ remoteDispatchConnError (remote_error *r
 /* This function gets called from qemud when it detects an incoming
  * remote protocol message.  At this point, client->buffer contains
  * the full call message (including length word which we skip).
+ *
+ * Server object is unlocked
+ * Client object is locked
  */
 unsigned int
 remoteDispatchClientRequest (struct qemud_server *server,
@@ -205,6 +222,7 @@ remoteDispatchClientRequest (struct qemu
     dispatch_ret ret;
     const dispatch_data *data = NULL;
     int rv = -1, len;
+    virConnectPtr conn = NULL;
 
     memset(&args, 0, sizeof args);
     memset(&ret, 0, sizeof ret);
@@ -274,7 +292,25 @@ remoteDispatchClientRequest (struct qemu
     }
 
     /* Call function. */
-    rv = (data->fn)(server, client, &rerr, &args, &ret);
+    conn = client->conn;
+    pthread_mutex_unlock(&client->lock);
+
+    /*
+     * When the RPC handler is called:
+     *
+     *  - Server object is unlocked
+     *  - Client object is unlocked
+     *
+     * Without locking, it is safe to use:
+     *
+     *   'conn', 'rerr', 'args and 'ret'
+     */
+    rv = (data->fn)(server, client, conn, &rerr, &args, &ret);
+
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
     xdr_free (data->args_filter, (char*)&args);
 
 rpc_error:
@@ -338,19 +374,24 @@ fatal_error:
 /*----- Functions. -----*/
 
 static int
-remoteDispatchOpen (struct qemud_server *server ATTRIBUTE_UNUSED,
+remoteDispatchOpen (struct qemud_server *server,
                     struct qemud_client *client,
+                    virConnectPtr conn,
                     remote_error *rerr,
                     struct remote_open_args *args, void *ret ATTRIBUTE_UNUSED)
 {
     const char *name;
-    int flags;
+    int flags, rc;
 
     /* Already opened? */
-    if (client->conn) {
+    if (conn) {
         remoteDispatchFormatError (rerr, "%s", _("connection already open"));
         return -1;
     }
+
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
 
     name = args->name ? *args->name : NULL;
 
@@ -365,49 +406,42 @@ remoteDispatchOpen (struct qemud_server 
         ? virConnectOpenReadOnly (name)
         : virConnectOpen (name);
 
-    if (client->conn == NULL) {
+    if (client->conn == NULL)
         remoteDispatchConnError(rerr, NULL);
-        return -1;
-    }
 
+    rc = client->conn ? 0 : -1;
+    pthread_mutex_unlock(&client->lock);
+    return rc;
+}
+
+static int
+remoteDispatchClose (struct qemud_server *server ATTRIBUTE_UNUSED,
+                     struct qemud_client *client ATTRIBUTE_UNUSED,
+                     virConnectPtr conn ATTRIBUTE_UNUSED,
+                     remote_error *rerr ATTRIBUTE_UNUSED,
+                     void *args ATTRIBUTE_UNUSED, void *ret ATTRIBUTE_UNUSED)
+{
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
+    client->closing = 1;
+
+    pthread_mutex_unlock(&client->lock);
     return 0;
 }
 
-#define CHECK_CONN(client)                      \
-    if (!client->conn) {                        \
-        remoteDispatchFormatError (rerr, "%s", _("connection not open"));   \
-        return -1;                                                  \
-    }
-
-static int
-remoteDispatchClose (struct qemud_server *server ATTRIBUTE_UNUSED,
-                     struct qemud_client *client,
-                     remote_error *rerr,
-                     void *args ATTRIBUTE_UNUSED, void *ret ATTRIBUTE_UNUSED)
-{
-    CHECK_CONN(client);
-
-    if (virConnectClose (client->conn) < 0) {
-        remoteDispatchConnError(rerr, NULL);
-        return -1;
-    }
-
-    client->conn = NULL;
-
-    return 0;
-}
 
 static int
 remoteDispatchSupportsFeature (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_supports_feature_args *args, remote_supports_feature_ret *ret)
 {
-    CHECK_CONN(client);
-
-    ret->supported = __virDrvSupportsFeature (client->conn, args->feature);
+    ret->supported = __virDrvSupportsFeature (conn, args->feature);
     if (ret->supported == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -416,16 +450,16 @@ remoteDispatchSupportsFeature (struct qe
 
 static int
 remoteDispatchGetType (struct qemud_server *server ATTRIBUTE_UNUSED,
-                       struct qemud_client *client,
+                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                       virConnectPtr conn,
                        remote_error *rerr,
                        void *args ATTRIBUTE_UNUSED, remote_get_type_ret *ret)
 {
     const char *type;
-    CHECK_CONN(client);
 
-    type = virConnectGetType (client->conn);
+    type = virConnectGetType (conn);
     if (type == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -443,16 +477,16 @@ remoteDispatchGetType (struct qemud_serv
 
 static int
 remoteDispatchGetVersion (struct qemud_server *server ATTRIBUTE_UNUSED,
-                          struct qemud_client *client,
+                          struct qemud_client *client ATTRIBUTE_UNUSED,
+                          virConnectPtr conn,
                           remote_error *rerr,
                           void *args ATTRIBUTE_UNUSED,
                           remote_get_version_ret *ret)
 {
     unsigned long hvVer;
-    CHECK_CONN(client);
 
-    if (virConnectGetVersion (client->conn, &hvVer) == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+    if (virConnectGetVersion (conn, &hvVer) == -1) {
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -462,17 +496,17 @@ remoteDispatchGetVersion (struct qemud_s
 
 static int
 remoteDispatchGetHostname (struct qemud_server *server ATTRIBUTE_UNUSED,
-                           struct qemud_client *client,
+                           struct qemud_client *client ATTRIBUTE_UNUSED,
+                           virConnectPtr conn,
                            remote_error *rerr,
                            void *args ATTRIBUTE_UNUSED,
                            remote_get_hostname_ret *ret)
 {
     char *hostname;
-    CHECK_CONN(client);
 
-    hostname = virConnectGetHostname (client->conn);
+    hostname = virConnectGetHostname (conn);
     if (hostname == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -482,18 +516,18 @@ remoteDispatchGetHostname (struct qemud_
 
 static int
 remoteDispatchGetMaxVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
-                           struct qemud_client *client,
+                           struct qemud_client *client ATTRIBUTE_UNUSED,
+                           virConnectPtr conn,
                            remote_error *rerr,
                            remote_get_max_vcpus_args *args,
                            remote_get_max_vcpus_ret *ret)
 {
     char *type;
-    CHECK_CONN(client);
 
     type = args->type ? *args->type : NULL;
-    ret->max_vcpus = virConnectGetMaxVcpus (client->conn, type);
+    ret->max_vcpus = virConnectGetMaxVcpus (conn, type);
     if (ret->max_vcpus == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -502,16 +536,16 @@ remoteDispatchGetMaxVcpus (struct qemud_
 
 static int
 remoteDispatchNodeGetInfo (struct qemud_server *server ATTRIBUTE_UNUSED,
-                           struct qemud_client *client,
+                           struct qemud_client *client ATTRIBUTE_UNUSED,
+                           virConnectPtr conn,
                            remote_error *rerr,
                            void *args ATTRIBUTE_UNUSED,
                            remote_node_get_info_ret *ret)
 {
     virNodeInfo info;
-    CHECK_CONN(client);
 
-    if (virNodeGetInfo (client->conn, &info) == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+    if (virNodeGetInfo (conn, &info) == -1) {
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -529,17 +563,17 @@ remoteDispatchNodeGetInfo (struct qemud_
 
 static int
 remoteDispatchGetCapabilities (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                void *args ATTRIBUTE_UNUSED,
                                remote_get_capabilities_ret *ret)
 {
     char *caps;
-    CHECK_CONN(client);
 
-    caps = virConnectGetCapabilities (client->conn);
+    caps = virConnectGetCapabilities (conn);
     if (caps == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -549,12 +583,12 @@ remoteDispatchGetCapabilities (struct qe
 
 static int
 remoteDispatchNodeGetCellsFreeMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_node_get_cells_free_memory_args *args,
                                       remote_node_get_cells_free_memory_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxCells > REMOTE_NODE_MAX_CELLS) {
         remoteDispatchFormatError (rerr,
@@ -568,13 +602,13 @@ remoteDispatchNodeGetCellsFreeMemory (st
         return -1;
     }
 
-    ret->freeMems.freeMems_len = virNodeGetCellsFreeMemory(client->conn,
+    ret->freeMems.freeMems_len = virNodeGetCellsFreeMemory(conn,
                                                            (unsigned long long *)ret->freeMems.freeMems_val,
                                                            args->startCell,
                                                            args->maxCells);
     if (ret->freeMems.freeMems_len == 0) {
         VIR_FREE(ret->freeMems.freeMems_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -584,17 +618,17 @@ remoteDispatchNodeGetCellsFreeMemory (st
 
 static int
 remoteDispatchNodeGetFreeMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  void *args ATTRIBUTE_UNUSED,
                                  remote_node_get_free_memory_ret *ret)
 {
     unsigned long long freeMem;
-    CHECK_CONN(client);
 
-    freeMem = virNodeGetFreeMemory(client->conn);
+    freeMem = virNodeGetFreeMemory(conn);
     if (freeMem == 0) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     ret->freeMem = freeMem;
@@ -604,7 +638,8 @@ remoteDispatchNodeGetFreeMemory (struct 
 
 static int
 remoteDispatchDomainGetSchedulerType (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_domain_get_scheduler_type_args *args,
                                       remote_domain_get_scheduler_type_ret *ret)
@@ -612,18 +647,17 @@ remoteDispatchDomainGetSchedulerType (st
     virDomainPtr dom;
     char *type;
     int nparams;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     type = virDomainGetSchedulerType (dom, &nparams);
     if (type == NULL) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -635,7 +669,8 @@ remoteDispatchDomainGetSchedulerType (st
 
 static int
 remoteDispatchDomainGetSchedulerParameters (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                            struct qemud_client *client,
+                                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                                            virConnectPtr conn,
                                             remote_error *rerr,
                                             remote_domain_get_scheduler_parameters_args *args,
                                             remote_domain_get_scheduler_parameters_ret *ret)
@@ -643,7 +678,6 @@ remoteDispatchDomainGetSchedulerParamete
     virDomainPtr dom;
     virSchedParameterPtr params;
     int i, r, nparams;
-    CHECK_CONN(client);
 
     nparams = args->nparams;
 
@@ -656,10 +690,10 @@ remoteDispatchDomainGetSchedulerParamete
         return -1;
     }
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
         VIR_FREE(params);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -667,7 +701,7 @@ remoteDispatchDomainGetSchedulerParamete
     if (r == -1) {
         virDomainFree(dom);
         VIR_FREE(params);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -718,7 +752,8 @@ cleanup:
 
 static int
 remoteDispatchDomainSetSchedulerParameters (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                            struct qemud_client *client,
+                                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                                            virConnectPtr conn,
                                             remote_error *rerr,
                                             remote_domain_set_scheduler_parameters_args *args,
                                             void *ret ATTRIBUTE_UNUSED)
@@ -726,7 +761,6 @@ remoteDispatchDomainSetSchedulerParamete
     virDomainPtr dom;
     int i, r, nparams;
     virSchedParameterPtr params;
-    CHECK_CONN(client);
 
     nparams = args->params.params_len;
 
@@ -761,10 +795,10 @@ remoteDispatchDomainSetSchedulerParamete
         }
     }
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
         VIR_FREE(params);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -772,7 +806,7 @@ remoteDispatchDomainSetSchedulerParamete
     virDomainFree(dom);
     VIR_FREE(params);
     if (r == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -781,7 +815,8 @@ remoteDispatchDomainSetSchedulerParamete
 
 static int
 remoteDispatchDomainBlockStats (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_domain_block_stats_args *args,
                                 remote_domain_block_stats_ret *ret)
@@ -789,18 +824,17 @@ remoteDispatchDomainBlockStats (struct q
     virDomainPtr dom;
     char *path;
     struct _virDomainBlockStats stats;
-    CHECK_CONN (client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     path = args->path;
 
     if (virDomainBlockStats (dom, path, &stats, sizeof stats) == -1) {
         virDomainFree (dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree (dom);
@@ -816,7 +850,8 @@ remoteDispatchDomainBlockStats (struct q
 
 static int
 remoteDispatchDomainInterfaceStats (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_domain_interface_stats_args *args,
                                     remote_domain_interface_stats_ret *ret)
@@ -824,18 +859,17 @@ remoteDispatchDomainInterfaceStats (stru
     virDomainPtr dom;
     char *path;
     struct _virDomainInterfaceStats stats;
-    CHECK_CONN (client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     path = args->path;
 
     if (virDomainInterfaceStats (dom, path, &stats, sizeof stats) == -1) {
         virDomainFree (dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree (dom);
@@ -854,7 +888,8 @@ remoteDispatchDomainInterfaceStats (stru
 
 static int
 remoteDispatchDomainBlockPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_domain_block_peek_args *args,
                                remote_domain_block_peek_ret *ret)
@@ -864,11 +899,10 @@ remoteDispatchDomainBlockPeek (struct qe
     unsigned long long offset;
     size_t size;
     unsigned int flags;
-    CHECK_CONN (client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     path = args->path;
@@ -894,7 +928,7 @@ remoteDispatchDomainBlockPeek (struct qe
                             ret->buffer.buffer_val, flags) == -1) {
         /* free (ret->buffer.buffer_val); - caller frees */
         virDomainFree (dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree (dom);
@@ -904,7 +938,8 @@ remoteDispatchDomainBlockPeek (struct qe
 
 static int
 remoteDispatchDomainMemoryPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_domain_memory_peek_args *args,
                                 remote_domain_memory_peek_ret *ret)
@@ -913,11 +948,10 @@ remoteDispatchDomainMemoryPeek (struct q
     unsigned long long offset;
     size_t size;
     unsigned int flags;
-    CHECK_CONN (client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     offset = args->offset;
@@ -942,7 +976,7 @@ remoteDispatchDomainMemoryPeek (struct q
                              ret->buffer.buffer_val, flags) == -1) {
         /* free (ret->buffer.buffer_val); - caller frees */
         virDomainFree (dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree (dom);
@@ -952,23 +986,23 @@ remoteDispatchDomainMemoryPeek (struct q
 
 static int
 remoteDispatchDomainAttachDevice (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_attach_device_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainAttachDevice (dom, args->xml) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -977,23 +1011,23 @@ remoteDispatchDomainAttachDevice (struct
 
 static int
 remoteDispatchDomainCreate (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn,
                             remote_error *rerr,
                             remote_domain_create_args *args,
                             void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainCreate (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1002,17 +1036,17 @@ remoteDispatchDomainCreate (struct qemud
 
 static int
 remoteDispatchDomainCreateXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
-                                 remote_error *rerr,
-                                 remote_domain_create_xml_args *args,
-                                 remote_domain_create_xml_ret *ret)
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
+                               remote_error *rerr,
+                               remote_domain_create_xml_args *args,
+                               remote_domain_create_xml_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = virDomainCreateXML (client->conn, args->xml_desc, args->flags);
+    dom = virDomainCreateXML (conn, args->xml_desc, args->flags);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1024,17 +1058,17 @@ remoteDispatchDomainCreateXml (struct qe
 
 static int
 remoteDispatchDomainDefineXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_domain_define_xml_args *args,
                                remote_domain_define_xml_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = virDomainDefineXML (client->conn, args->xml);
+    dom = virDomainDefineXML (conn, args->xml);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1046,23 +1080,23 @@ remoteDispatchDomainDefineXml (struct qe
 
 static int
 remoteDispatchDomainDestroy (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_destroy_args *args,
                              void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainDestroy (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1071,23 +1105,23 @@ remoteDispatchDomainDestroy (struct qemu
 
 static int
 remoteDispatchDomainDetachDevice (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_detach_device_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainDetachDevice (dom, args->xml) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1097,17 +1131,17 @@ remoteDispatchDomainDetachDevice (struct
 
 static int
 remoteDispatchDomainDumpXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_dump_xml_args *args,
                              remote_domain_dump_xml_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1115,7 +1149,7 @@ remoteDispatchDomainDumpXml (struct qemu
     ret->xml = virDomainGetXMLDesc (dom, args->flags);
     if (!ret->xml) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1124,23 +1158,23 @@ remoteDispatchDomainDumpXml (struct qemu
 
 static int
 remoteDispatchDomainGetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_get_autostart_args *args,
                                   remote_domain_get_autostart_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainGetAutostart (dom, &ret->autostart) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1149,24 +1183,24 @@ remoteDispatchDomainGetAutostart (struct
 
 static int
 remoteDispatchDomainGetInfo (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_get_info_args *args,
                              remote_domain_get_info_ret *ret)
 {
     virDomainPtr dom;
     virDomainInfo info;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainGetInfo (dom, &info) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1183,24 +1217,24 @@ remoteDispatchDomainGetInfo (struct qemu
 
 static int
 remoteDispatchDomainGetMaxMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_get_max_memory_args *args,
                                   remote_domain_get_max_memory_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     ret->memory = virDomainGetMaxMemory (dom);
     if (ret->memory == 0) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1209,24 +1243,24 @@ remoteDispatchDomainGetMaxMemory (struct
 
 static int
 remoteDispatchDomainGetMaxVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_domain_get_max_vcpus_args *args,
                                  remote_domain_get_max_vcpus_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     ret->num = virDomainGetMaxVcpus (dom);
     if (ret->num == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1235,17 +1269,17 @@ remoteDispatchDomainGetMaxVcpus (struct 
 
 static int
 remoteDispatchDomainGetOsType (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_domain_get_os_type_args *args,
                                remote_domain_get_os_type_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1253,7 +1287,7 @@ remoteDispatchDomainGetOsType (struct qe
     ret->type = virDomainGetOSType (dom);
     if (ret->type == NULL) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1262,7 +1296,8 @@ remoteDispatchDomainGetOsType (struct qe
 
 static int
 remoteDispatchDomainGetVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_domain_get_vcpus_args *args,
                               remote_domain_get_vcpus_ret *ret)
@@ -1271,11 +1306,10 @@ remoteDispatchDomainGetVcpus (struct qem
     virVcpuInfoPtr info = NULL;
     unsigned char *cpumaps = NULL;
     int info_len, i;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1304,7 +1338,7 @@ remoteDispatchDomainGetVcpus (struct qem
         VIR_FREE(info);
         VIR_FREE(cpumaps);
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1341,7 +1375,8 @@ oom:
 
 static int
 remoteDispatchDomainMigratePrepare (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_domain_migrate_prepare_args *args,
                                     remote_domain_migrate_prepare_ret *ret)
@@ -1352,7 +1387,6 @@ remoteDispatchDomainMigratePrepare (stru
     char *uri_in;
     char **uri_out;
     char *dname;
-    CHECK_CONN (client);
 
     uri_in = args->uri_in == NULL ? NULL : *args->uri_in;
     dname = args->dname == NULL ? NULL : *args->dname;
@@ -1363,12 +1397,12 @@ remoteDispatchDomainMigratePrepare (stru
         return -1;
     }
 
-    r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen,
+    r = __virDomainMigratePrepare (conn, &cookie, &cookielen,
                                    uri_in, uri_out,
                                    args->flags, dname, args->resource);
     if (r == -1) {
         VIR_FREE(uri_out);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1389,7 +1423,8 @@ remoteDispatchDomainMigratePrepare (stru
 
 static int
 remoteDispatchDomainMigratePerform (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_domain_migrate_perform_args *args,
                                     void *ret ATTRIBUTE_UNUSED)
@@ -1397,11 +1432,10 @@ remoteDispatchDomainMigratePerform (stru
     int r;
     virDomainPtr dom;
     char *dname;
-    CHECK_CONN (client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1414,7 +1448,7 @@ remoteDispatchDomainMigratePerform (stru
                                    args->flags, dname, args->resource);
     virDomainFree (dom);
     if (r == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1423,21 +1457,21 @@ remoteDispatchDomainMigratePerform (stru
 
 static int
 remoteDispatchDomainMigrateFinish (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_domain_migrate_finish_args *args,
                                    remote_domain_migrate_finish_ret *ret)
 {
     virDomainPtr ddom;
-    CHECK_CONN (client);
 
-    ddom = __virDomainMigrateFinish (client->conn, args->dname,
+    ddom = __virDomainMigrateFinish (conn, args->dname,
                                      args->cookie.cookie_val,
                                      args->cookie.cookie_len,
                                      args->uri,
                                      args->flags);
     if (ddom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1448,12 +1482,12 @@ remoteDispatchDomainMigrateFinish (struc
 
 static int
 remoteDispatchListDefinedDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_list_defined_domains_args *args,
                                   remote_list_defined_domains_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_DOMAIN_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -1468,11 +1502,11 @@ remoteDispatchListDefinedDomains (struct
     }
 
     ret->names.names_len =
-        virConnectListDefinedDomains (client->conn,
+        virConnectListDefinedDomains (conn,
                                       ret->names.names_val, args->maxnames);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1481,17 +1515,17 @@ remoteDispatchListDefinedDomains (struct
 
 static int
 remoteDispatchDomainLookupById (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_domain_lookup_by_id_args *args,
                                 remote_domain_lookup_by_id_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = virDomainLookupByID (client->conn, args->id);
+    dom = virDomainLookupByID (conn, args->id);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1502,17 +1536,17 @@ remoteDispatchDomainLookupById (struct q
 
 static int
 remoteDispatchDomainLookupByName (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_lookup_by_name_args *args,
                                   remote_domain_lookup_by_name_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = virDomainLookupByName (client->conn, args->name);
+    dom = virDomainLookupByName (conn, args->name);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1523,17 +1557,17 @@ remoteDispatchDomainLookupByName (struct
 
 static int
 remoteDispatchDomainLookupByUuid (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_lookup_by_uuid_args *args,
                                   remote_domain_lookup_by_uuid_ret *ret)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = virDomainLookupByUUID (client->conn, (unsigned char *) args->uuid);
+    dom = virDomainLookupByUUID (conn, (unsigned char *) args->uuid);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1544,16 +1578,16 @@ remoteDispatchDomainLookupByUuid (struct
 
 static int
 remoteDispatchNumOfDefinedDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    void *args ATTRIBUTE_UNUSED,
                                    remote_num_of_defined_domains_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfDefinedDomains (client->conn);
+    ret->num = virConnectNumOfDefinedDomains (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1562,18 +1596,18 @@ remoteDispatchNumOfDefinedDomains (struc
 
 static int
 remoteDispatchDomainPinVcpu (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_pin_vcpu_args *args,
                              void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
     int rv;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1588,7 +1622,7 @@ remoteDispatchDomainPinVcpu (struct qemu
                            args->cpumap.cpumap_len);
     if (rv == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1597,23 +1631,23 @@ remoteDispatchDomainPinVcpu (struct qemu
 
 static int
 remoteDispatchDomainReboot (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn,
                             remote_error *rerr,
                             remote_domain_reboot_args *args,
                             void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainReboot (dom, args->flags) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1622,15 +1656,15 @@ remoteDispatchDomainReboot (struct qemud
 
 static int
 remoteDispatchDomainRestore (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_restore_args *args,
                              void *ret ATTRIBUTE_UNUSED)
 {
-    CHECK_CONN(client);
 
-    if (virDomainRestore (client->conn, args->from) == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+    if (virDomainRestore (conn, args->from) == -1) {
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1639,23 +1673,23 @@ remoteDispatchDomainRestore (struct qemu
 
 static int
 remoteDispatchDomainResume (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn,
                             remote_error *rerr,
                             remote_domain_resume_args *args,
                             void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainResume (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1664,23 +1698,23 @@ remoteDispatchDomainResume (struct qemud
 
 static int
 remoteDispatchDomainSave (struct qemud_server *server ATTRIBUTE_UNUSED,
-                          struct qemud_client *client,
+                          struct qemud_client *client ATTRIBUTE_UNUSED,
+                          virConnectPtr conn,
                           remote_error *rerr,
                           remote_domain_save_args *args,
                           void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSave (dom, args->to) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1689,23 +1723,23 @@ remoteDispatchDomainSave (struct qemud_s
 
 static int
 remoteDispatchDomainCoreDump (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_domain_core_dump_args *args,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainCoreDump (dom, args->to, args->flags) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1714,23 +1748,23 @@ remoteDispatchDomainCoreDump (struct qem
 
 static int
 remoteDispatchDomainSetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_set_autostart_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSetAutostart (dom, args->autostart) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1739,23 +1773,23 @@ remoteDispatchDomainSetAutostart (struct
 
 static int
 remoteDispatchDomainSetMaxMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_domain_set_max_memory_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSetMaxMemory (dom, args->memory) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1764,23 +1798,23 @@ remoteDispatchDomainSetMaxMemory (struct
 
 static int
 remoteDispatchDomainSetMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_domain_set_memory_args *args,
                                void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSetMemory (dom, args->memory) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1789,23 +1823,23 @@ remoteDispatchDomainSetMemory (struct qe
 
 static int
 remoteDispatchDomainSetVcpus (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_domain_set_vcpus_args *args,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSetVcpus (dom, args->nvcpus) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1814,23 +1848,23 @@ remoteDispatchDomainSetVcpus (struct qem
 
 static int
 remoteDispatchDomainShutdown (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_domain_shutdown_args *args,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainShutdown (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1839,23 +1873,23 @@ remoteDispatchDomainShutdown (struct qem
 
 static int
 remoteDispatchDomainSuspend (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_domain_suspend_args *args,
                              void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainSuspend (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1864,23 +1898,23 @@ remoteDispatchDomainSuspend (struct qemu
 
 static int
 remoteDispatchDomainUndefine (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_domain_undefine_args *args,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virDomainPtr dom;
-    CHECK_CONN(client);
 
-    dom = get_nonnull_domain (client->conn, args->dom);
+    dom = get_nonnull_domain (conn, args->dom);
     if (dom == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virDomainUndefine (dom) == -1) {
         virDomainFree(dom);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virDomainFree(dom);
@@ -1889,12 +1923,12 @@ remoteDispatchDomainUndefine (struct qem
 
 static int
 remoteDispatchListDefinedNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_list_defined_networks_args *args,
                                    remote_list_defined_networks_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -1909,11 +1943,11 @@ remoteDispatchListDefinedNetworks (struc
     }
 
     ret->names.names_len =
-        virConnectListDefinedNetworks (client->conn,
+        virConnectListDefinedNetworks (conn,
                                        ret->names.names_val, args->maxnames);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1922,12 +1956,12 @@ remoteDispatchListDefinedNetworks (struc
 
 static int
 remoteDispatchListDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
-                           struct qemud_client *client,
+                           struct qemud_client *client ATTRIBUTE_UNUSED,
+                           virConnectPtr conn,
                            remote_error *rerr,
                            remote_list_domains_args *args,
                            remote_list_domains_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxids > REMOTE_DOMAIN_ID_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -1941,11 +1975,11 @@ remoteDispatchListDomains (struct qemud_
         return -1;
     }
 
-    ret->ids.ids_len = virConnectListDomains (client->conn,
+    ret->ids.ids_len = virConnectListDomains (conn,
                                               ret->ids.ids_val, args->maxids);
     if (ret->ids.ids_len == -1) {
         VIR_FREE(ret->ids.ids_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1954,12 +1988,12 @@ remoteDispatchListDomains (struct qemud_
 
 static int
 remoteDispatchListNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn,
                             remote_error *rerr,
                             remote_list_networks_args *args,
                             remote_list_networks_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -1974,11 +2008,11 @@ remoteDispatchListNetworks (struct qemud
     }
 
     ret->names.names_len =
-        virConnectListNetworks (client->conn,
+        virConnectListNetworks (conn,
                                 ret->names.names_val, args->maxnames);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_len);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -1987,23 +2021,23 @@ remoteDispatchListNetworks (struct qemud
 
 static int
 remoteDispatchNetworkCreate (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              remote_network_create_args *args,
                              void *ret ATTRIBUTE_UNUSED)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virNetworkCreate (net) == -1) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2012,17 +2046,17 @@ remoteDispatchNetworkCreate (struct qemu
 
 static int
 remoteDispatchNetworkCreateXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_network_create_xml_args *args,
                                 remote_network_create_xml_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = virNetworkCreateXML (client->conn, args->xml);
+    net = virNetworkCreateXML (conn, args->xml);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2033,17 +2067,17 @@ remoteDispatchNetworkCreateXml (struct q
 
 static int
 remoteDispatchNetworkDefineXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_network_define_xml_args *args,
                                 remote_network_define_xml_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = virNetworkDefineXML (client->conn, args->xml);
+    net = virNetworkDefineXML (conn, args->xml);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2054,23 +2088,23 @@ remoteDispatchNetworkDefineXml (struct q
 
 static int
 remoteDispatchNetworkDestroy (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_network_destroy_args *args,
                               void *ret ATTRIBUTE_UNUSED)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virNetworkDestroy (net) == -1) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2079,17 +2113,17 @@ remoteDispatchNetworkDestroy (struct qem
 
 static int
 remoteDispatchNetworkDumpXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                              struct qemud_client *client,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
                               remote_error *rerr,
                               remote_network_dump_xml_args *args,
                               remote_network_dump_xml_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2097,7 +2131,7 @@ remoteDispatchNetworkDumpXml (struct qem
     ret->xml = virNetworkGetXMLDesc (net, args->flags);
     if (!ret->xml) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2106,23 +2140,23 @@ remoteDispatchNetworkDumpXml (struct qem
 
 static int
 remoteDispatchNetworkGetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_network_get_autostart_args *args,
                                    remote_network_get_autostart_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virNetworkGetAutostart (net, &ret->autostart) == -1) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2131,17 +2165,17 @@ remoteDispatchNetworkGetAutostart (struc
 
 static int
 remoteDispatchNetworkGetBridgeName (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_network_get_bridge_name_args *args,
                                     remote_network_get_bridge_name_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2149,7 +2183,7 @@ remoteDispatchNetworkGetBridgeName (stru
     ret->name = virNetworkGetBridgeName (net);
     if (!ret->name) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2158,17 +2192,17 @@ remoteDispatchNetworkGetBridgeName (stru
 
 static int
 remoteDispatchNetworkLookupByName (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_network_lookup_by_name_args *args,
                                    remote_network_lookup_by_name_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = virNetworkLookupByName (client->conn, args->name);
+    net = virNetworkLookupByName (conn, args->name);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2179,17 +2213,17 @@ remoteDispatchNetworkLookupByName (struc
 
 static int
 remoteDispatchNetworkLookupByUuid (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_network_lookup_by_uuid_args *args,
                                    remote_network_lookup_by_uuid_ret *ret)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = virNetworkLookupByUUID (client->conn, (unsigned char *) args->uuid);
+    net = virNetworkLookupByUUID (conn, (unsigned char *) args->uuid);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2200,23 +2234,23 @@ remoteDispatchNetworkLookupByUuid (struc
 
 static int
 remoteDispatchNetworkSetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_network_set_autostart_args *args,
                                    void *ret ATTRIBUTE_UNUSED)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virNetworkSetAutostart (net, args->autostart) == -1) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2225,23 +2259,23 @@ remoteDispatchNetworkSetAutostart (struc
 
 static int
 remoteDispatchNetworkUndefine (struct qemud_server *server ATTRIBUTE_UNUSED,
-                               struct qemud_client *client,
+                               struct qemud_client *client ATTRIBUTE_UNUSED,
+                               virConnectPtr conn,
                                remote_error *rerr,
                                remote_network_undefine_args *args,
                                void *ret ATTRIBUTE_UNUSED)
 {
     virNetworkPtr net;
-    CHECK_CONN(client);
 
-    net = get_nonnull_network (client->conn, args->net);
+    net = get_nonnull_network (conn, args->net);
     if (net == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virNetworkUndefine (net) == -1) {
         virNetworkFree(net);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virNetworkFree(net);
@@ -2250,16 +2284,16 @@ remoteDispatchNetworkUndefine (struct qe
 
 static int
 remoteDispatchNumOfDefinedNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     void *args ATTRIBUTE_UNUSED,
                                     remote_num_of_defined_networks_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfDefinedNetworks (client->conn);
+    ret->num = virConnectNumOfDefinedNetworks (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2268,16 +2302,16 @@ remoteDispatchNumOfDefinedNetworks (stru
 
 static int
 remoteDispatchNumOfDomains (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn,
                             remote_error *rerr,
                             void *args ATTRIBUTE_UNUSED,
                             remote_num_of_domains_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfDomains (client->conn);
+    ret->num = virConnectNumOfDomains (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2286,16 +2320,16 @@ remoteDispatchNumOfDomains (struct qemud
 
 static int
 remoteDispatchNumOfNetworks (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn,
                              remote_error *rerr,
                              void *args ATTRIBUTE_UNUSED,
                              remote_num_of_networks_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfNetworks (client->conn);
+    ret->num = virConnectNumOfNetworks (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2304,8 +2338,9 @@ remoteDispatchNumOfNetworks (struct qemu
 
 
 static int
-remoteDispatchAuthList (struct qemud_server *server ATTRIBUTE_UNUSED,
+remoteDispatchAuthList (struct qemud_server *server,
                         struct qemud_client *client,
+                        virConnectPtr conn ATTRIBUTE_UNUSED,
                         remote_error *rerr,
                         void *args ATTRIBUTE_UNUSED,
                         remote_auth_list_ret *ret)
@@ -2315,7 +2350,12 @@ remoteDispatchAuthList (struct qemud_ser
         remoteDispatchOOMError(rerr);
         return -1;
     }
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
     ret->types.types_val[0] = client->auth;
+    pthread_mutex_unlock(&client->lock);
+
     return 0;
 }
 
@@ -2359,8 +2399,9 @@ static char *addrToString(remote_error *
  * XXX callbacks for stuff like password verification ?
  */
 static int
-remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
+remoteDispatchAuthSaslInit (struct qemud_server *server,
                             struct qemud_client *client,
+                            virConnectPtr conn ATTRIBUTE_UNUSED,
                             remote_error *rerr,
                             void *args ATTRIBUTE_UNUSED,
                             remote_auth_sasl_init_ret *ret)
@@ -2372,12 +2413,15 @@ remoteDispatchAuthSaslInit (struct qemud
     socklen_t salen;
     char *localAddr, *remoteAddr;
 
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
     REMOTE_DEBUG("Initialize SASL auth %d", client->fd);
     if (client->auth != REMOTE_AUTH_SASL ||
         client->saslconn != NULL) {
         qemudLog(QEMUD_ERR, "%s", _("client tried invalid SASL init request"));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     /* Get local address in form  IPADDR:PORT */
@@ -2386,10 +2430,10 @@ remoteDispatchAuthSaslInit (struct qemud
         remoteDispatchFormatError(rerr,
                                   _("failed to get sock address %d (%s)"),
                                   errno, strerror(errno));
-        return -1;
+        goto error;
     }
     if ((localAddr = addrToString(rerr, &sa, salen)) == NULL) {
-        return -1;
+        goto error;
     }
 
     /* Get remote address in form  IPADDR:PORT */
@@ -2398,11 +2442,11 @@ remoteDispatchAuthSaslInit (struct qemud
         remoteDispatchFormatError(rerr, _("failed to get peer address %d (%s)"),
                                   errno, strerror(errno));
         VIR_FREE(localAddr);
-        return -1;
+        goto error;
     }
     if ((remoteAddr = addrToString(rerr, &sa, salen)) == NULL) {
         VIR_FREE(localAddr);
-        return -1;
+        goto error;
     }
 
     err = sasl_server_new("libvirt",
@@ -2418,9 +2462,8 @@ remoteDispatchAuthSaslInit (struct qemud
     if (err != SASL_OK) {
         qemudLog(QEMUD_ERR, _("sasl context setup failed %d (%s)"),
                  err, sasl_errstring(err, NULL, NULL));
-        remoteDispatchAuthError(rerr);
         client->saslconn = NULL;
-        return -1;
+        goto authfail;
     }
 
     /* Inform SASL that we've got an external SSF layer from TLS */
@@ -2431,10 +2474,9 @@ remoteDispatchAuthSaslInit (struct qemud
         cipher = gnutls_cipher_get(client->tlssession);
         if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) {
             qemudLog(QEMUD_ERR, "%s", _("cannot TLS get cipher size"));
-            remoteDispatchAuthError(rerr);
             sasl_dispose(&client->saslconn);
             client->saslconn = NULL;
-            return -1;
+            goto authfail;
         }
         ssf *= 8; /* tls key size is bytes, sasl wants bits */
 
@@ -2442,10 +2484,9 @@ remoteDispatchAuthSaslInit (struct qemud
         if (err != SASL_OK) {
             qemudLog(QEMUD_ERR, _("cannot set SASL external SSF %d (%s)"),
                      err, sasl_errstring(err, NULL, NULL));
-            remoteDispatchAuthError(rerr);
             sasl_dispose(&client->saslconn);
             client->saslconn = NULL;
-            return -1;
+            goto authfail;
         }
     }
 
@@ -2471,10 +2512,9 @@ remoteDispatchAuthSaslInit (struct qemud
     if (err != SASL_OK) {
         qemudLog(QEMUD_ERR, _("cannot set SASL security props %d (%s)"),
                  err, sasl_errstring(err, NULL, NULL));
-        remoteDispatchAuthError(rerr);
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        return -1;
+        goto authfail;
     }
 
     err = sasl_listmech(client->saslconn,
@@ -2488,22 +2528,27 @@ remoteDispatchAuthSaslInit (struct qemud
     if (err != SASL_OK) {
         qemudLog(QEMUD_ERR, _("cannot list SASL mechanisms %d (%s)"),
                  err, sasl_errdetail(client->saslconn));
-        remoteDispatchAuthError(rerr);
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        return -1;
+        goto authfail;
     }
     REMOTE_DEBUG("Available mechanisms for client: '%s'", mechlist);
     ret->mechlist = strdup(mechlist);
     if (!ret->mechlist) {
         qemudLog(QEMUD_ERR, "%s", _("cannot allocate mechlist"));
-        remoteDispatchAuthError(rerr);
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        return -1;
+        goto authfail;
     }
 
+    pthread_mutex_unlock(&client->lock);
     return 0;
+
+authfail:
+    remoteDispatchAuthError(rerr);
+error:
+    pthread_mutex_unlock(&client->lock);
+    return -1;
 }
 
 
@@ -2613,6 +2658,7 @@ static int
 static int
 remoteDispatchAuthSaslStart (struct qemud_server *server,
                              struct qemud_client *client,
+                             virConnectPtr conn ATTRIBUTE_UNUSED,
                              remote_error *rerr,
                              remote_auth_sasl_start_args *args,
                              remote_auth_sasl_start_ret *ret)
@@ -2621,12 +2667,15 @@ remoteDispatchAuthSaslStart (struct qemu
     unsigned int serveroutlen;
     int err;
 
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
     REMOTE_DEBUG("Start SASL auth %d", client->fd);
     if (client->auth != REMOTE_AUTH_SASL ||
         client->saslconn == NULL) {
         qemudLog(QEMUD_ERR, "%s", _("client tried invalid SASL start request"));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     REMOTE_DEBUG("Using SASL mechanism %s. Data %d bytes, nil: %d",
@@ -2644,23 +2693,21 @@ remoteDispatchAuthSaslStart (struct qemu
                  err, sasl_errdetail(client->saslconn));
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
     if (serveroutlen > REMOTE_AUTH_SASL_DATA_MAX) {
         qemudLog(QEMUD_ERR, _("sasl start reply data too long %d"),
                  serveroutlen);
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     /* NB, distinction of NULL vs "" is *critical* in SASL */
     if (serverout) {
         if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
             remoteDispatchOOMError(rerr);
-            return -1;
+            goto error;
         }
         memcpy(ret->data.data_val, serverout, serveroutlen);
     } else {
@@ -2674,24 +2721,32 @@ remoteDispatchAuthSaslStart (struct qemu
         ret->complete = 0;
     } else {
         if (remoteSASLCheckSSF(client, rerr) < 0)
-            return -1;
+            goto error;
 
         /* Check username whitelist ACL */
         if (remoteSASLCheckAccess(server, client, rerr) < 0)
-            return -1;
+            goto error;
 
         REMOTE_DEBUG("Authentication successful %d", client->fd);
         ret->complete = 1;
         client->auth = REMOTE_AUTH_NONE;
     }
 
+    pthread_mutex_unlock(&client->lock);
     return 0;
+
+authfail:
+    remoteDispatchAuthError(rerr);
+error:
+    pthread_mutex_unlock(&client->lock);
+    return -1;
 }
 
 
 static int
 remoteDispatchAuthSaslStep (struct qemud_server *server,
                             struct qemud_client *client,
+                            virConnectPtr conn ATTRIBUTE_UNUSED,
                             remote_error *rerr,
                             remote_auth_sasl_step_args *args,
                             remote_auth_sasl_step_ret *ret)
@@ -2700,12 +2755,15 @@ remoteDispatchAuthSaslStep (struct qemud
     unsigned int serveroutlen;
     int err;
 
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
     REMOTE_DEBUG("Step SASL auth %d", client->fd);
     if (client->auth != REMOTE_AUTH_SASL ||
         client->saslconn == NULL) {
         qemudLog(QEMUD_ERR, "%s", _("client tried invalid SASL start request"));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     REMOTE_DEBUG("Using SASL Data %d bytes, nil: %d",
@@ -2722,8 +2780,7 @@ remoteDispatchAuthSaslStep (struct qemud
                  err, sasl_errdetail(client->saslconn));
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     if (serveroutlen > REMOTE_AUTH_SASL_DATA_MAX) {
@@ -2731,15 +2788,14 @@ remoteDispatchAuthSaslStep (struct qemud
                  serveroutlen);
         sasl_dispose(&client->saslconn);
         client->saslconn = NULL;
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     /* NB, distinction of NULL vs "" is *critical* in SASL */
     if (serverout) {
         if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
             remoteDispatchOOMError(rerr);
-            return -1;
+            goto error;
         }
         memcpy(ret->data.data_val, serverout, serveroutlen);
     } else {
@@ -2753,25 +2809,33 @@ remoteDispatchAuthSaslStep (struct qemud
         ret->complete = 0;
     } else {
         if (remoteSASLCheckSSF(client, rerr) < 0)
-            return -1;
+            goto error;
 
         /* Check username whitelist ACL */
         if (remoteSASLCheckAccess(server, client, rerr) < 0)
-            return -1;
+            goto error;
 
         REMOTE_DEBUG("Authentication successful %d", client->fd);
         ret->complete = 1;
         client->auth = REMOTE_AUTH_NONE;
     }
 
+    pthread_mutex_unlock(&client->lock);
     return 0;
+
+authfail:
+    remoteDispatchAuthError(rerr);
+error:
+    pthread_mutex_unlock(&client->lock);
+    return -1;
 }
 
 
 #else /* HAVE_SASL */
 static int
 remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn ATTRIBUTE_UNUSED,
                             remote_error *rerr,
                             void *args ATTRIBUTE_UNUSED,
                             remote_auth_sasl_init_ret *ret ATTRIBUTE_UNUSED)
@@ -2783,7 +2847,8 @@ remoteDispatchAuthSaslInit (struct qemud
 
 static int
 remoteDispatchAuthSaslStart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                             struct qemud_client *client,
+                             struct qemud_client *client ATTRIBUTE_UNUSED,
+                             virConnectPtr conn ATTRIBUTE_UNUSED,
                              remote_error *rerr,
                              remote_auth_sasl_start_args *args ATTRIBUTE_UNUSED,
                              remote_auth_sasl_start_ret *ret ATTRIBUTE_UNUSED)
@@ -2795,7 +2860,8 @@ remoteDispatchAuthSaslStart (struct qemu
 
 static int
 remoteDispatchAuthSaslStep (struct qemud_server *server ATTRIBUTE_UNUSED,
-                            struct qemud_client *client,
+                            struct qemud_client *client ATTRIBUTE_UNUSED,
+                            virConnectPtr conn ATTRIBUTE_UNUSED,
                             remote_error *rerr,
                             remote_auth_sasl_step_args *args ATTRIBUTE_UNUSED,
                             remote_auth_sasl_step_ret *ret ATTRIBUTE_UNUSED)
@@ -2809,8 +2875,9 @@ remoteDispatchAuthSaslStep (struct qemud
 
 #if HAVE_POLKIT
 static int
-remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
+remoteDispatchAuthPolkit (struct qemud_server *server,
                           struct qemud_client *client,
+                          virConnectPtr conn ATTRIBUTE_UNUSED,
                           remote_error *rerr,
                           void *args ATTRIBUTE_UNUSED,
                           remote_auth_polkit_ret *ret)
@@ -2823,7 +2890,13 @@ remoteDispatchAuthPolkit (struct qemud_s
     PolKitError *pkerr = NULL;
     PolKitResult pkresult;
     DBusError err;
-    const char *action = client->readonly ?
+    const char *action;
+
+    pthread_mutex_lock(&server->lock);
+    pthread_mutex_lock(&client->lock);
+    pthread_mutex_unlock(&server->lock);
+
+    action = client->readonly ?
         "org.libvirt.unix.monitor" :
         "org.libvirt.unix.manage";
 
@@ -2831,14 +2904,12 @@ remoteDispatchAuthPolkit (struct qemud_s
     if (client->auth != REMOTE_AUTH_POLKIT) {
         qemudLog(QEMUD_ERR,
                  "%s", _("client tried invalid PolicyKit init request"));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     if (qemudGetSocketIdentity(client->fd, &callerUid, &callerPid) < 0) {
         qemudLog(QEMUD_ERR, "%s", _("cannot get peer socket identity"));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     qemudLog(QEMUD_INFO, _("Checking PID %d running as %d"),
@@ -2849,16 +2920,14 @@ remoteDispatchAuthPolkit (struct qemud_s
         qemudLog(QEMUD_ERR, _("Failed to lookup policy kit caller: %s"),
                  err.message);
         dbus_error_free(&err);
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
     if (!(pkaction = polkit_action_new())) {
         qemudLog(QEMUD_ERR, _("Failed to create polkit action %s\n"),
                  strerror(errno));
         polkit_caller_unref(pkcaller);
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
     polkit_action_set_action_id(pkaction, action);
 
@@ -2872,8 +2941,7 @@ remoteDispatchAuthPolkit (struct qemud_s
         polkit_caller_unref(pkcaller);
         polkit_action_unref(pkaction);
         dbus_error_free(&err);
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 
 #if HAVE_POLKIT_CONTEXT_IS_CALLER_AUTHORIZED
@@ -2887,8 +2955,7 @@ remoteDispatchAuthPolkit (struct qemud_s
                  _("Policy kit failed to check authorization %d %s"),
                  polkit_error_get_error_code(pkerr),
                  polkit_error_get_error_message(pkerr));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
 #else
     pkresult = polkit_context_can_caller_do_action(pkcontext,
@@ -2904,8 +2971,7 @@ remoteDispatchAuthPolkit (struct qemud_s
                    " result: %s\n"),
                  action, callerPid, callerUid,
                  polkit_result_to_string_representation(pkresult));
-        remoteDispatchAuthError(rerr);
-        return -1;
+        goto authfail;
     }
     qemudLog(QEMUD_INFO,
              _("Policy allowed action %s from pid %d, uid %d, result %s"),
@@ -2914,14 +2980,21 @@ remoteDispatchAuthPolkit (struct qemud_s
     ret->complete = 1;
     client->auth = REMOTE_AUTH_NONE;
 
+    pthread_mutex_unlock(&client->lock);
     return 0;
+
+authfail:
+    remoteDispatchAuthError(rerr);
+    pthread_mutex_unlock(&client->lock);
+    return -1;
 }
 
 #else /* HAVE_POLKIT */
 
 static int
 remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
-                          struct qemud_client *client,
+                          struct qemud_client *client ATTRIBUTE_UNUSED,
+                          virConnectPtr conn,
                           remote_error *rerr,
                           void *args ATTRIBUTE_UNUSED,
                           remote_auth_polkit_ret *ret ATTRIBUTE_UNUSED)
@@ -2941,12 +3014,12 @@ remoteDispatchAuthPolkit (struct qemud_s
 
 static int
 remoteDispatchListDefinedStoragePools (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_list_defined_storage_pools_args *args,
                                        remote_list_defined_storage_pools_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_NETWORK_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -2961,11 +3034,11 @@ remoteDispatchListDefinedStoragePools (s
     }
 
     ret->names.names_len =
-        virConnectListDefinedStoragePools (client->conn,
+        virConnectListDefinedStoragePools (conn,
                                            ret->names.names_val, args->maxnames);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -2974,12 +3047,12 @@ remoteDispatchListDefinedStoragePools (s
 
 static int
 remoteDispatchListStoragePools (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_list_storage_pools_args *args,
                                 remote_list_storage_pools_ret *ret)
 {
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_STORAGE_POOL_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -2994,11 +3067,11 @@ remoteDispatchListStoragePools (struct q
     }
 
     ret->names.names_len =
-        virConnectListStoragePools (client->conn,
+        virConnectListStoragePools (conn,
                                 ret->names.names_val, args->maxnames);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3007,20 +3080,19 @@ remoteDispatchListStoragePools (struct q
 
 static int
 remoteDispatchFindStoragePoolSources (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_find_storage_pool_sources_args *args,
                                       remote_find_storage_pool_sources_ret *ret)
 {
-    CHECK_CONN(client);
-
     ret->xml =
-        virConnectFindStoragePoolSources (client->conn,
+        virConnectFindStoragePoolSources (conn,
                                           args->type,
                                           args->srcSpec ? *args->srcSpec : NULL,
                                           args->flags);
     if (ret->xml == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3030,23 +3102,23 @@ remoteDispatchFindStoragePoolSources (st
 
 static int
 remoteDispatchStoragePoolCreate (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_storage_pool_create_args *args,
                                  void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolCreate (pool, args->flags) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3055,17 +3127,17 @@ remoteDispatchStoragePoolCreate (struct 
 
 static int
 remoteDispatchStoragePoolCreateXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_storage_pool_create_xml_args *args,
                                     remote_storage_pool_create_xml_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = virStoragePoolCreateXML (client->conn, args->xml, args->flags);
+    pool = virStoragePoolCreateXML (conn, args->xml, args->flags);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3076,17 +3148,17 @@ remoteDispatchStoragePoolCreateXml (stru
 
 static int
 remoteDispatchStoragePoolDefineXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                    struct qemud_client *client,
+                                    struct qemud_client *client ATTRIBUTE_UNUSED,
+                                    virConnectPtr conn,
                                     remote_error *rerr,
                                     remote_storage_pool_define_xml_args *args,
                                     remote_storage_pool_define_xml_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = virStoragePoolDefineXML (client->conn, args->xml, args->flags);
+    pool = virStoragePoolDefineXML (conn, args->xml, args->flags);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3097,23 +3169,23 @@ remoteDispatchStoragePoolDefineXml (stru
 
 static int
 remoteDispatchStoragePoolBuild (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_storage_pool_build_args *args,
                                 void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolBuild (pool, args->flags) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3123,23 +3195,23 @@ remoteDispatchStoragePoolBuild (struct q
 
 static int
 remoteDispatchStoragePoolDestroy (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_storage_pool_destroy_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolDestroy (pool) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3148,23 +3220,23 @@ remoteDispatchStoragePoolDestroy (struct
 
 static int
 remoteDispatchStoragePoolDelete (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_storage_pool_delete_args *args,
                                  void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolDelete (pool, args->flags) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3173,23 +3245,23 @@ remoteDispatchStoragePoolDelete (struct 
 
 static int
 remoteDispatchStoragePoolRefresh (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_storage_pool_refresh_args *args,
                                   void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolRefresh (pool, args->flags) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3198,24 +3270,24 @@ remoteDispatchStoragePoolRefresh (struct
 
 static int
 remoteDispatchStoragePoolGetInfo (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_storage_pool_get_info_args *args,
                                   remote_storage_pool_get_info_ret *ret)
 {
     virStoragePoolPtr pool;
     virStoragePoolInfo info;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolGetInfo (pool, &info) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3231,17 +3303,17 @@ remoteDispatchStoragePoolGetInfo (struct
 
 static int
 remoteDispatchStoragePoolDumpXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                  struct qemud_client *client,
+                                  struct qemud_client *client ATTRIBUTE_UNUSED,
+                                  virConnectPtr conn,
                                   remote_error *rerr,
                                   remote_storage_pool_dump_xml_args *args,
                                   remote_storage_pool_dump_xml_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3249,7 +3321,7 @@ remoteDispatchStoragePoolDumpXml (struct
     ret->xml = virStoragePoolGetXMLDesc (pool, args->flags);
     if (!ret->xml) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3258,23 +3330,23 @@ remoteDispatchStoragePoolDumpXml (struct
 
 static int
 remoteDispatchStoragePoolGetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_storage_pool_get_autostart_args *args,
                                        remote_storage_pool_get_autostart_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolGetAutostart (pool, &ret->autostart) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3284,17 +3356,17 @@ remoteDispatchStoragePoolGetAutostart (s
 
 static int
 remoteDispatchStoragePoolLookupByName (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_storage_pool_lookup_by_name_args *args,
                                        remote_storage_pool_lookup_by_name_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = virStoragePoolLookupByName (client->conn, args->name);
+    pool = virStoragePoolLookupByName (conn, args->name);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3305,17 +3377,17 @@ remoteDispatchStoragePoolLookupByName (s
 
 static int
 remoteDispatchStoragePoolLookupByUuid (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_storage_pool_lookup_by_uuid_args *args,
                                        remote_storage_pool_lookup_by_uuid_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = virStoragePoolLookupByUUID (client->conn, (unsigned char *) args->uuid);
+    pool = virStoragePoolLookupByUUID (conn, (unsigned char *) args->uuid);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3326,25 +3398,25 @@ remoteDispatchStoragePoolLookupByUuid (s
 
 static int
 remoteDispatchStoragePoolLookupByVolume (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                         struct qemud_client *client,
+                                         struct qemud_client *client ATTRIBUTE_UNUSED,
+                                         virConnectPtr conn,
                                          remote_error *rerr,
                                          remote_storage_pool_lookup_by_volume_args *args,
                                          remote_storage_pool_lookup_by_volume_ret *ret)
 {
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = get_nonnull_storage_vol (client->conn, args->vol);
+    vol = get_nonnull_storage_vol (conn, args->vol);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     pool = virStoragePoolLookupByVolume (vol);
     virStorageVolFree(vol);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3355,23 +3427,23 @@ remoteDispatchStoragePoolLookupByVolume 
 
 static int
 remoteDispatchStoragePoolSetAutostart (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_storage_pool_set_autostart_args *args,
                                        void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolSetAutostart (pool, args->autostart) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3380,23 +3452,23 @@ remoteDispatchStoragePoolSetAutostart (s
 
 static int
 remoteDispatchStoragePoolUndefine (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_storage_pool_undefine_args *args,
                                    void *ret ATTRIBUTE_UNUSED)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStoragePoolUndefine (pool) == -1) {
         virStoragePoolFree(pool);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStoragePoolFree(pool);
@@ -3405,16 +3477,16 @@ remoteDispatchStoragePoolUndefine (struc
 
 static int
 remoteDispatchNumOfStoragePools (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  void *args ATTRIBUTE_UNUSED,
                                  remote_num_of_storage_pools_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfStoragePools (client->conn);
+    ret->num = virConnectNumOfStoragePools (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3423,16 +3495,16 @@ remoteDispatchNumOfStoragePools (struct 
 
 static int
 remoteDispatchNumOfDefinedStoragePools (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                        struct qemud_client *client,
+                                        struct qemud_client *client ATTRIBUTE_UNUSED,
+                                        virConnectPtr conn,
                                         remote_error *rerr,
                                         void *args ATTRIBUTE_UNUSED,
                                         remote_num_of_defined_storage_pools_ret *ret)
 {
-    CHECK_CONN(client);
 
-    ret->num = virConnectNumOfDefinedStoragePools (client->conn);
+    ret->num = virConnectNumOfDefinedStoragePools (conn);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3441,13 +3513,13 @@ remoteDispatchNumOfDefinedStoragePools (
 
 static int
 remoteDispatchStoragePoolListVolumes (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_storage_pool_list_volumes_args *args,
                                       remote_storage_pool_list_volumes_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
     if (args->maxnames > REMOTE_STORAGE_VOL_NAME_LIST_MAX) {
         remoteDispatchFormatError (rerr,
@@ -3455,9 +3527,9 @@ remoteDispatchStoragePoolListVolumes (st
         return -1;
     }
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3474,7 +3546,7 @@ remoteDispatchStoragePoolListVolumes (st
     virStoragePoolFree(pool);
     if (ret->names.names_len == -1) {
         VIR_FREE(ret->names.names_val);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3484,24 +3556,24 @@ remoteDispatchStoragePoolListVolumes (st
 
 static int
 remoteDispatchStoragePoolNumOfVolumes (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                       struct qemud_client *client,
+                                       struct qemud_client *client ATTRIBUTE_UNUSED,
+                                       virConnectPtr conn,
                                        remote_error *rerr,
                                        remote_storage_pool_num_of_volumes_args *args,
                                        remote_storage_pool_num_of_volumes_ret *ret)
 {
     virStoragePoolPtr pool;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     ret->num = virStoragePoolNumOfVolumes (pool);
     virStoragePoolFree(pool);
     if (ret->num == -1) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3517,25 +3589,25 @@ remoteDispatchStoragePoolNumOfVolumes (s
 
 static int
 remoteDispatchStorageVolCreateXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                   struct qemud_client *client,
+                                   struct qemud_client *client ATTRIBUTE_UNUSED,
+                                   virConnectPtr conn,
                                    remote_error *rerr,
                                    remote_storage_vol_create_xml_args *args,
                                    remote_storage_vol_create_xml_ret *ret)
 {
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     vol = virStorageVolCreateXML (pool, args->xml, args->flags);
     virStoragePoolFree(pool);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3547,23 +3619,23 @@ remoteDispatchStorageVolCreateXml (struc
 
 static int
 remoteDispatchStorageVolDelete (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                struct qemud_client *client,
+                                struct qemud_client *client ATTRIBUTE_UNUSED,
+                                virConnectPtr conn,
                                 remote_error *rerr,
                                 remote_storage_vol_delete_args *args,
                                 void *ret ATTRIBUTE_UNUSED)
 {
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = get_nonnull_storage_vol (client->conn, args->vol);
+    vol = get_nonnull_storage_vol (conn, args->vol);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStorageVolDelete (vol, args->flags) == -1) {
         virStorageVolFree(vol);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStorageVolFree(vol);
@@ -3572,24 +3644,24 @@ remoteDispatchStorageVolDelete (struct q
 
 static int
 remoteDispatchStorageVolGetInfo (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_storage_vol_get_info_args *args,
                                  remote_storage_vol_get_info_ret *ret)
 {
     virStorageVolPtr vol;
     virStorageVolInfo info;
-    CHECK_CONN(client);
 
-    vol = get_nonnull_storage_vol (client->conn, args->vol);
+    vol = get_nonnull_storage_vol (conn, args->vol);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     if (virStorageVolGetInfo (vol, &info) == -1) {
         virStorageVolFree(vol);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3604,17 +3676,17 @@ remoteDispatchStorageVolGetInfo (struct 
 
 static int
 remoteDispatchStorageVolDumpXml (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_storage_vol_dump_xml_args *args,
                                  remote_storage_vol_dump_xml_ret *ret)
 {
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = get_nonnull_storage_vol (client->conn, args->vol);
+    vol = get_nonnull_storage_vol (conn, args->vol);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3622,7 +3694,7 @@ remoteDispatchStorageVolDumpXml (struct 
     ret->xml = virStorageVolGetXMLDesc (vol, args->flags);
     if (!ret->xml) {
         virStorageVolFree(vol);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStorageVolFree(vol);
@@ -3632,17 +3704,17 @@ remoteDispatchStorageVolDumpXml (struct 
 
 static int
 remoteDispatchStorageVolGetPath (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                 struct qemud_client *client,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
                                  remote_error *rerr,
                                  remote_storage_vol_get_path_args *args,
                                  remote_storage_vol_get_path_ret *ret)
 {
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = get_nonnull_storage_vol (client->conn, args->vol);
+    vol = get_nonnull_storage_vol (conn, args->vol);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3650,7 +3722,7 @@ remoteDispatchStorageVolGetPath (struct 
     ret->name = virStorageVolGetPath (vol);
     if (!ret->name) {
         virStorageVolFree(vol);
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
     virStorageVolFree(vol);
@@ -3660,25 +3732,25 @@ remoteDispatchStorageVolGetPath (struct 
 
 static int
 remoteDispatchStorageVolLookupByName (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_storage_vol_lookup_by_name_args *args,
                                       remote_storage_vol_lookup_by_name_ret *ret)
 {
     virStoragePoolPtr pool;
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    pool = get_nonnull_storage_pool (client->conn, args->pool);
+    pool = get_nonnull_storage_pool (conn, args->pool);
     if (pool == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
     vol = virStorageVolLookupByName (pool, args->name);
     virStoragePoolFree(pool);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3689,17 +3761,17 @@ remoteDispatchStorageVolLookupByName (st
 
 static int
 remoteDispatchStorageVolLookupByKey (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                     struct qemud_client *client,
+                                     struct qemud_client *client ATTRIBUTE_UNUSED,
+                                     virConnectPtr conn,
                                      remote_error *rerr,
                                      remote_storage_vol_lookup_by_key_args *args,
                                      remote_storage_vol_lookup_by_key_ret *ret)
 {
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = virStorageVolLookupByKey (client->conn, args->key);
+    vol = virStorageVolLookupByKey (conn, args->key);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
@@ -3711,17 +3783,17 @@ remoteDispatchStorageVolLookupByKey (str
 
 static int
 remoteDispatchStorageVolLookupByPath (struct qemud_server *server ATTRIBUTE_UNUSED,
-                                      struct qemud_client *client,
+                                      struct qemud_client *client ATTRIBUTE_UNUSED,
+                                      virConnectPtr conn,
                                       remote_error *rerr,
                                       remote_storage_vol_lookup_by_path_args *args,
                                       remote_storage_vol_lookup_by_path_ret *ret)
 {
     virStorageVolPtr vol;
-    CHECK_CONN(client);
 
-    vol = virStorageVolLookupByPath (client->conn, args->path);
+    vol = virStorageVolLookupByPath (conn, args->path);
     if (vol == NULL) {
-        remoteDispatchConnError(rerr, client->conn);
+        remoteDispatchConnError(rerr, conn);
         return -1;
     }
 
diff --git a/qemud/remote_dispatch_prototypes.h b/qemud/remote_dispatch_prototypes.h
--- a/qemud/remote_dispatch_prototypes.h
+++ b/qemud/remote_dispatch_prototypes.h
@@ -2,107 +2,731 @@
  * Do not edit this file.  Any changes you make will be lost.
  */
 
-static int remoteDispatchAuthList (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_auth_list_ret *ret);
-static int remoteDispatchAuthPolkit (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_auth_polkit_ret *ret);
-static int remoteDispatchAuthSaslInit (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_auth_sasl_init_ret *ret);
-static int remoteDispatchAuthSaslStart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_auth_sasl_start_args *args, remote_auth_sasl_start_ret *ret);
-static int remoteDispatchAuthSaslStep (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_auth_sasl_step_args *args, remote_auth_sasl_step_ret *ret);
-static int remoteDispatchClose (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, void *ret);
-static int remoteDispatchDomainAttachDevice (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_attach_device_args *args, void *ret);
-static int remoteDispatchDomainBlockPeek (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_block_peek_args *args, remote_domain_block_peek_ret *ret);
-static int remoteDispatchDomainBlockStats (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_block_stats_args *args, remote_domain_block_stats_ret *ret);
-static int remoteDispatchDomainCoreDump (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_core_dump_args *args, void *ret);
-static int remoteDispatchDomainCreate (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_create_args *args, void *ret);
-static int remoteDispatchDomainCreateXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_create_xml_args *args, remote_domain_create_xml_ret *ret);
-static int remoteDispatchDomainDefineXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_define_xml_args *args, remote_domain_define_xml_ret *ret);
-static int remoteDispatchDomainDestroy (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_destroy_args *args, void *ret);
-static int remoteDispatchDomainDetachDevice (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_detach_device_args *args, void *ret);
-static int remoteDispatchDomainDumpXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_dump_xml_args *args, remote_domain_dump_xml_ret *ret);
-static int remoteDispatchDomainGetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_autostart_args *args, remote_domain_get_autostart_ret *ret);
-static int remoteDispatchDomainGetInfo (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_info_args *args, remote_domain_get_info_ret *ret);
-static int remoteDispatchDomainGetMaxMemory (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_max_memory_args *args, remote_domain_get_max_memory_ret *ret);
-static int remoteDispatchDomainGetMaxVcpus (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_max_vcpus_args *args, remote_domain_get_max_vcpus_ret *ret);
-static int remoteDispatchDomainGetOsType (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_os_type_args *args, remote_domain_get_os_type_ret *ret);
-static int remoteDispatchDomainGetSchedulerParameters (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_scheduler_parameters_args *args, remote_domain_get_scheduler_parameters_ret *ret);
-static int remoteDispatchDomainGetSchedulerType (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_scheduler_type_args *args, remote_domain_get_scheduler_type_ret *ret);
-static int remoteDispatchDomainGetVcpus (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_get_vcpus_args *args, remote_domain_get_vcpus_ret *ret);
-static int remoteDispatchDomainInterfaceStats (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_interface_stats_args *args, remote_domain_interface_stats_ret *ret);
-static int remoteDispatchDomainLookupById (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_lookup_by_id_args *args, remote_domain_lookup_by_id_ret *ret);
-static int remoteDispatchDomainLookupByName (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_lookup_by_name_args *args, remote_domain_lookup_by_name_ret *ret);
-static int remoteDispatchDomainLookupByUuid (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_lookup_by_uuid_args *args, remote_domain_lookup_by_uuid_ret *ret);
-static int remoteDispatchDomainMemoryPeek (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_memory_peek_args *args, remote_domain_memory_peek_ret *ret);
-static int remoteDispatchDomainMigrateFinish (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_migrate_finish_args *args, remote_domain_migrate_finish_ret *ret);
-static int remoteDispatchDomainMigratePerform (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_migrate_perform_args *args, void *ret);
-static int remoteDispatchDomainMigratePrepare (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_migrate_prepare_args *args, remote_domain_migrate_prepare_ret *ret);
-static int remoteDispatchDomainPinVcpu (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_pin_vcpu_args *args, void *ret);
-static int remoteDispatchDomainReboot (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_reboot_args *args, void *ret);
-static int remoteDispatchDomainRestore (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_restore_args *args, void *ret);
-static int remoteDispatchDomainResume (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_resume_args *args, void *ret);
-static int remoteDispatchDomainSave (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_save_args *args, void *ret);
-static int remoteDispatchDomainSetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_set_autostart_args *args, void *ret);
-static int remoteDispatchDomainSetMaxMemory (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_set_max_memory_args *args, void *ret);
-static int remoteDispatchDomainSetMemory (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_set_memory_args *args, void *ret);
-static int remoteDispatchDomainSetSchedulerParameters (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_set_scheduler_parameters_args *args, void *ret);
-static int remoteDispatchDomainSetVcpus (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_set_vcpus_args *args, void *ret);
-static int remoteDispatchDomainShutdown (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_shutdown_args *args, void *ret);
-static int remoteDispatchDomainSuspend (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_suspend_args *args, void *ret);
-static int remoteDispatchDomainUndefine (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_domain_undefine_args *args, void *ret);
-static int remoteDispatchFindStoragePoolSources (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_find_storage_pool_sources_args *args, remote_find_storage_pool_sources_ret *ret);
-static int remoteDispatchGetCapabilities (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_get_capabilities_ret *ret);
-static int remoteDispatchGetHostname (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_get_hostname_ret *ret);
-static int remoteDispatchGetMaxVcpus (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_get_max_vcpus_args *args, remote_get_max_vcpus_ret *ret);
-static int remoteDispatchGetType (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_get_type_ret *ret);
-static int remoteDispatchGetVersion (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_get_version_ret *ret);
-static int remoteDispatchListDefinedDomains (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_defined_domains_args *args, remote_list_defined_domains_ret *ret);
-static int remoteDispatchListDefinedNetworks (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_defined_networks_args *args, remote_list_defined_networks_ret *ret);
-static int remoteDispatchListDefinedStoragePools (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_defined_storage_pools_args *args, remote_list_defined_storage_pools_ret *ret);
-static int remoteDispatchListDomains (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_domains_args *args, remote_list_domains_ret *ret);
-static int remoteDispatchListNetworks (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_networks_args *args, remote_list_networks_ret *ret);
-static int remoteDispatchListStoragePools (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_list_storage_pools_args *args, remote_list_storage_pools_ret *ret);
-static int remoteDispatchNetworkCreate (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_create_args *args, void *ret);
-static int remoteDispatchNetworkCreateXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_create_xml_args *args, remote_network_create_xml_ret *ret);
-static int remoteDispatchNetworkDefineXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_define_xml_args *args, remote_network_define_xml_ret *ret);
-static int remoteDispatchNetworkDestroy (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_destroy_args *args, void *ret);
-static int remoteDispatchNetworkDumpXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_dump_xml_args *args, remote_network_dump_xml_ret *ret);
-static int remoteDispatchNetworkGetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_get_autostart_args *args, remote_network_get_autostart_ret *ret);
-static int remoteDispatchNetworkGetBridgeName (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_get_bridge_name_args *args, remote_network_get_bridge_name_ret *ret);
-static int remoteDispatchNetworkLookupByName (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_lookup_by_name_args *args, remote_network_lookup_by_name_ret *ret);
-static int remoteDispatchNetworkLookupByUuid (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_lookup_by_uuid_args *args, remote_network_lookup_by_uuid_ret *ret);
-static int remoteDispatchNetworkSetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_set_autostart_args *args, void *ret);
-static int remoteDispatchNetworkUndefine (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_network_undefine_args *args, void *ret);
-static int remoteDispatchNodeGetCellsFreeMemory (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_node_get_cells_free_memory_args *args, remote_node_get_cells_free_memory_ret *ret);
-static int remoteDispatchNodeGetFreeMemory (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_node_get_free_memory_ret *ret);
-static int remoteDispatchNodeGetInfo (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_node_get_info_ret *ret);
-static int remoteDispatchNumOfDefinedDomains (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_defined_domains_ret *ret);
-static int remoteDispatchNumOfDefinedNetworks (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_defined_networks_ret *ret);
-static int remoteDispatchNumOfDefinedStoragePools (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_defined_storage_pools_ret *ret);
-static int remoteDispatchNumOfDomains (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_domains_ret *ret);
-static int remoteDispatchNumOfNetworks (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_networks_ret *ret);
-static int remoteDispatchNumOfStoragePools (struct qemud_server *server, struct qemud_client *client, remote_error *err, void *args, remote_num_of_storage_pools_ret *ret);
-static int remoteDispatchOpen (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_open_args *args, void *ret);
-static int remoteDispatchStoragePoolBuild (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_build_args *args, void *ret);
-static int remoteDispatchStoragePoolCreate (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_create_args *args, void *ret);
-static int remoteDispatchStoragePoolCreateXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_create_xml_args *args, remote_storage_pool_create_xml_ret *ret);
-static int remoteDispatchStoragePoolDefineXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_define_xml_args *args, remote_storage_pool_define_xml_ret *ret);
-static int remoteDispatchStoragePoolDelete (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_delete_args *args, void *ret);
-static int remoteDispatchStoragePoolDestroy (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_destroy_args *args, void *ret);
-static int remoteDispatchStoragePoolDumpXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_dump_xml_args *args, remote_storage_pool_dump_xml_ret *ret);
-static int remoteDispatchStoragePoolGetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_get_autostart_args *args, remote_storage_pool_get_autostart_ret *ret);
-static int remoteDispatchStoragePoolGetInfo (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_get_info_args *args, remote_storage_pool_get_info_ret *ret);
-static int remoteDispatchStoragePoolListVolumes (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_list_volumes_args *args, remote_storage_pool_list_volumes_ret *ret);
-static int remoteDispatchStoragePoolLookupByName (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_lookup_by_name_args *args, remote_storage_pool_lookup_by_name_ret *ret);
-static int remoteDispatchStoragePoolLookupByUuid (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_lookup_by_uuid_args *args, remote_storage_pool_lookup_by_uuid_ret *ret);
-static int remoteDispatchStoragePoolLookupByVolume (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_lookup_by_volume_args *args, remote_storage_pool_lookup_by_volume_ret *ret);
-static int remoteDispatchStoragePoolNumOfVolumes (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_num_of_volumes_args *args, remote_storage_pool_num_of_volumes_ret *ret);
-static int remoteDispatchStoragePoolRefresh (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_refresh_args *args, void *ret);
-static int remoteDispatchStoragePoolSetAutostart (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_set_autostart_args *args, void *ret);
-static int remoteDispatchStoragePoolUndefine (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_pool_undefine_args *args, void *ret);
-static int remoteDispatchStorageVolCreateXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_create_xml_args *args, remote_storage_vol_create_xml_ret *ret);
-static int remoteDispatchStorageVolDelete (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_delete_args *args, void *ret);
-static int remoteDispatchStorageVolDumpXml (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_dump_xml_args *args, remote_storage_vol_dump_xml_ret *ret);
-static int remoteDispatchStorageVolGetInfo (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_get_info_args *args, remote_storage_vol_get_info_ret *ret);
-static int remoteDispatchStorageVolGetPath (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_get_path_args *args, remote_storage_vol_get_path_ret *ret);
-static int remoteDispatchStorageVolLookupByKey (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_lookup_by_key_args *args, remote_storage_vol_lookup_by_key_ret *ret);
-static int remoteDispatchStorageVolLookupByName (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_lookup_by_name_args *args, remote_storage_vol_lookup_by_name_ret *ret);
-static int remoteDispatchStorageVolLookupByPath (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_storage_vol_lookup_by_path_args *args, remote_storage_vol_lookup_by_path_ret *ret);
-static int remoteDispatchSupportsFeature (struct qemud_server *server, struct qemud_client *client, remote_error *err, remote_supports_feature_args *args, remote_supports_feature_ret *ret);
+static int remoteDispatchAuthList(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_auth_list_ret *ret);
+static int remoteDispatchAuthPolkit(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_auth_polkit_ret *ret);
+static int remoteDispatchAuthSaslInit(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_auth_sasl_init_ret *ret);
+static int remoteDispatchAuthSaslStart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_auth_sasl_start_args *args,
+    remote_auth_sasl_start_ret *ret);
+static int remoteDispatchAuthSaslStep(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_auth_sasl_step_args *args,
+    remote_auth_sasl_step_ret *ret);
+static int remoteDispatchClose(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    void *ret);
+static int remoteDispatchDomainAttachDevice(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_attach_device_args *args,
+    void *ret);
+static int remoteDispatchDomainBlockPeek(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_block_peek_args *args,
+    remote_domain_block_peek_ret *ret);
+static int remoteDispatchDomainBlockStats(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_block_stats_args *args,
+    remote_domain_block_stats_ret *ret);
+static int remoteDispatchDomainCoreDump(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_core_dump_args *args,
+    void *ret);
+static int remoteDispatchDomainCreate(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_create_args *args,
+    void *ret);
+static int remoteDispatchDomainCreateXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_create_xml_args *args,
+    remote_domain_create_xml_ret *ret);
+static int remoteDispatchDomainDefineXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_define_xml_args *args,
+    remote_domain_define_xml_ret *ret);
+static int remoteDispatchDomainDestroy(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_destroy_args *args,
+    void *ret);
+static int remoteDispatchDomainDetachDevice(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_detach_device_args *args,
+    void *ret);
+static int remoteDispatchDomainDumpXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_dump_xml_args *args,
+    remote_domain_dump_xml_ret *ret);
+static int remoteDispatchDomainGetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_autostart_args *args,
+    remote_domain_get_autostart_ret *ret);
+static int remoteDispatchDomainGetInfo(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_info_args *args,
+    remote_domain_get_info_ret *ret);
+static int remoteDispatchDomainGetMaxMemory(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_max_memory_args *args,
+    remote_domain_get_max_memory_ret *ret);
+static int remoteDispatchDomainGetMaxVcpus(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_max_vcpus_args *args,
+    remote_domain_get_max_vcpus_ret *ret);
+static int remoteDispatchDomainGetOsType(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_os_type_args *args,
+    remote_domain_get_os_type_ret *ret);
+static int remoteDispatchDomainGetSchedulerParameters(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_scheduler_parameters_args *args,
+    remote_domain_get_scheduler_parameters_ret *ret);
+static int remoteDispatchDomainGetSchedulerType(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_scheduler_type_args *args,
+    remote_domain_get_scheduler_type_ret *ret);
+static int remoteDispatchDomainGetVcpus(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_get_vcpus_args *args,
+    remote_domain_get_vcpus_ret *ret);
+static int remoteDispatchDomainInterfaceStats(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_interface_stats_args *args,
+    remote_domain_interface_stats_ret *ret);
+static int remoteDispatchDomainLookupById(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_lookup_by_id_args *args,
+    remote_domain_lookup_by_id_ret *ret);
+static int remoteDispatchDomainLookupByName(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_lookup_by_name_args *args,
+    remote_domain_lookup_by_name_ret *ret);
+static int remoteDispatchDomainLookupByUuid(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_lookup_by_uuid_args *args,
+    remote_domain_lookup_by_uuid_ret *ret);
+static int remoteDispatchDomainMemoryPeek(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_memory_peek_args *args,
+    remote_domain_memory_peek_ret *ret);
+static int remoteDispatchDomainMigrateFinish(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_migrate_finish_args *args,
+    remote_domain_migrate_finish_ret *ret);
+static int remoteDispatchDomainMigratePerform(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_migrate_perform_args *args,
+    void *ret);
+static int remoteDispatchDomainMigratePrepare(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_migrate_prepare_args *args,
+    remote_domain_migrate_prepare_ret *ret);
+static int remoteDispatchDomainPinVcpu(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_pin_vcpu_args *args,
+    void *ret);
+static int remoteDispatchDomainReboot(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_reboot_args *args,
+    void *ret);
+static int remoteDispatchDomainRestore(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_restore_args *args,
+    void *ret);
+static int remoteDispatchDomainResume(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_resume_args *args,
+    void *ret);
+static int remoteDispatchDomainSave(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_save_args *args,
+    void *ret);
+static int remoteDispatchDomainSetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_set_autostart_args *args,
+    void *ret);
+static int remoteDispatchDomainSetMaxMemory(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_set_max_memory_args *args,
+    void *ret);
+static int remoteDispatchDomainSetMemory(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_set_memory_args *args,
+    void *ret);
+static int remoteDispatchDomainSetSchedulerParameters(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_set_scheduler_parameters_args *args,
+    void *ret);
+static int remoteDispatchDomainSetVcpus(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_set_vcpus_args *args,
+    void *ret);
+static int remoteDispatchDomainShutdown(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_shutdown_args *args,
+    void *ret);
+static int remoteDispatchDomainSuspend(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_suspend_args *args,
+    void *ret);
+static int remoteDispatchDomainUndefine(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_domain_undefine_args *args,
+    void *ret);
+static int remoteDispatchFindStoragePoolSources(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_find_storage_pool_sources_args *args,
+    remote_find_storage_pool_sources_ret *ret);
+static int remoteDispatchGetCapabilities(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_get_capabilities_ret *ret);
+static int remoteDispatchGetHostname(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_get_hostname_ret *ret);
+static int remoteDispatchGetMaxVcpus(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_get_max_vcpus_args *args,
+    remote_get_max_vcpus_ret *ret);
+static int remoteDispatchGetType(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_get_type_ret *ret);
+static int remoteDispatchGetVersion(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_get_version_ret *ret);
+static int remoteDispatchListDefinedDomains(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_defined_domains_args *args,
+    remote_list_defined_domains_ret *ret);
+static int remoteDispatchListDefinedNetworks(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_defined_networks_args *args,
+    remote_list_defined_networks_ret *ret);
+static int remoteDispatchListDefinedStoragePools(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_defined_storage_pools_args *args,
+    remote_list_defined_storage_pools_ret *ret);
+static int remoteDispatchListDomains(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_domains_args *args,
+    remote_list_domains_ret *ret);
+static int remoteDispatchListNetworks(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_networks_args *args,
+    remote_list_networks_ret *ret);
+static int remoteDispatchListStoragePools(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_list_storage_pools_args *args,
+    remote_list_storage_pools_ret *ret);
+static int remoteDispatchNetworkCreate(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_create_args *args,
+    void *ret);
+static int remoteDispatchNetworkCreateXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_create_xml_args *args,
+    remote_network_create_xml_ret *ret);
+static int remoteDispatchNetworkDefineXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_define_xml_args *args,
+    remote_network_define_xml_ret *ret);
+static int remoteDispatchNetworkDestroy(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_destroy_args *args,
+    void *ret);
+static int remoteDispatchNetworkDumpXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_dump_xml_args *args,
+    remote_network_dump_xml_ret *ret);
+static int remoteDispatchNetworkGetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_get_autostart_args *args,
+    remote_network_get_autostart_ret *ret);
+static int remoteDispatchNetworkGetBridgeName(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_get_bridge_name_args *args,
+    remote_network_get_bridge_name_ret *ret);
+static int remoteDispatchNetworkLookupByName(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_lookup_by_name_args *args,
+    remote_network_lookup_by_name_ret *ret);
+static int remoteDispatchNetworkLookupByUuid(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_lookup_by_uuid_args *args,
+    remote_network_lookup_by_uuid_ret *ret);
+static int remoteDispatchNetworkSetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_set_autostart_args *args,
+    void *ret);
+static int remoteDispatchNetworkUndefine(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_network_undefine_args *args,
+    void *ret);
+static int remoteDispatchNodeGetCellsFreeMemory(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_node_get_cells_free_memory_args *args,
+    remote_node_get_cells_free_memory_ret *ret);
+static int remoteDispatchNodeGetFreeMemory(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_node_get_free_memory_ret *ret);
+static int remoteDispatchNodeGetInfo(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_node_get_info_ret *ret);
+static int remoteDispatchNumOfDefinedDomains(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_defined_domains_ret *ret);
+static int remoteDispatchNumOfDefinedNetworks(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_defined_networks_ret *ret);
+static int remoteDispatchNumOfDefinedStoragePools(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_defined_storage_pools_ret *ret);
+static int remoteDispatchNumOfDomains(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_domains_ret *ret);
+static int remoteDispatchNumOfNetworks(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_networks_ret *ret);
+static int remoteDispatchNumOfStoragePools(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    void *args,
+    remote_num_of_storage_pools_ret *ret);
+static int remoteDispatchOpen(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_open_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolBuild(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_build_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolCreate(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_create_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolCreateXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_create_xml_args *args,
+    remote_storage_pool_create_xml_ret *ret);
+static int remoteDispatchStoragePoolDefineXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_define_xml_args *args,
+    remote_storage_pool_define_xml_ret *ret);
+static int remoteDispatchStoragePoolDelete(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_delete_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolDestroy(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_destroy_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolDumpXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_dump_xml_args *args,
+    remote_storage_pool_dump_xml_ret *ret);
+static int remoteDispatchStoragePoolGetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_get_autostart_args *args,
+    remote_storage_pool_get_autostart_ret *ret);
+static int remoteDispatchStoragePoolGetInfo(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_get_info_args *args,
+    remote_storage_pool_get_info_ret *ret);
+static int remoteDispatchStoragePoolListVolumes(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_list_volumes_args *args,
+    remote_storage_pool_list_volumes_ret *ret);
+static int remoteDispatchStoragePoolLookupByName(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_lookup_by_name_args *args,
+    remote_storage_pool_lookup_by_name_ret *ret);
+static int remoteDispatchStoragePoolLookupByUuid(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_lookup_by_uuid_args *args,
+    remote_storage_pool_lookup_by_uuid_ret *ret);
+static int remoteDispatchStoragePoolLookupByVolume(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_lookup_by_volume_args *args,
+    remote_storage_pool_lookup_by_volume_ret *ret);
+static int remoteDispatchStoragePoolNumOfVolumes(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_num_of_volumes_args *args,
+    remote_storage_pool_num_of_volumes_ret *ret);
+static int remoteDispatchStoragePoolRefresh(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_refresh_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolSetAutostart(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_set_autostart_args *args,
+    void *ret);
+static int remoteDispatchStoragePoolUndefine(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_pool_undefine_args *args,
+    void *ret);
+static int remoteDispatchStorageVolCreateXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_create_xml_args *args,
+    remote_storage_vol_create_xml_ret *ret);
+static int remoteDispatchStorageVolDelete(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_delete_args *args,
+    void *ret);
+static int remoteDispatchStorageVolDumpXml(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_dump_xml_args *args,
+    remote_storage_vol_dump_xml_ret *ret);
+static int remoteDispatchStorageVolGetInfo(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_get_info_args *args,
+    remote_storage_vol_get_info_ret *ret);
+static int remoteDispatchStorageVolGetPath(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_get_path_args *args,
+    remote_storage_vol_get_path_ret *ret);
+static int remoteDispatchStorageVolLookupByKey(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_lookup_by_key_args *args,
+    remote_storage_vol_lookup_by_key_ret *ret);
+static int remoteDispatchStorageVolLookupByName(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_lookup_by_name_args *args,
+    remote_storage_vol_lookup_by_name_ret *ret);
+static int remoteDispatchStorageVolLookupByPath(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_storage_vol_lookup_by_path_args *args,
+    remote_storage_vol_lookup_by_path_ret *ret);
+static int remoteDispatchSupportsFeature(
+    struct qemud_server *server, 
+    struct qemud_client *client, 
+    virConnectPtr conn, 
+    remote_error *err, 
+    remote_supports_feature_args *args,
+    remote_supports_feature_ret *ret);
diff --git a/qemud/remote_generate_stubs.pl b/qemud/remote_generate_stubs.pl
--- a/qemud/remote_generate_stubs.pl
+++ b/qemud/remote_generate_stubs.pl
@@ -100,7 +100,13 @@ elsif ($opt_p) {
 elsif ($opt_p) {
     my @keys = sort (keys %calls);
     foreach (@keys) {
-	print "static int remoteDispatch$calls{$_}->{ProcName} (struct qemud_server *server, struct qemud_client *client, remote_error *err, $calls{$_}->{args} *args, $calls{$_}->{ret} *ret);\n";
+	print "static int remoteDispatch$calls{$_}->{ProcName}(\n";
+	print "    struct qemud_server *server, \n";
+	print "    struct qemud_client *client, \n";
+	print "    virConnectPtr conn, \n";
+	print "    remote_error *err, \n";
+	print "    $calls{$_}->{args} *args,\n";
+	print "    $calls{$_}->{ret} *ret);\n";
     }
 }
 

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]