4 Server-side call dispatch
---------------------------
A qemud/remote.c
A qemud/remote_generate_stubs.pl
A qemud/remote_dispatch_localvars.h
A qemud/remote_dispatch_proc_switch.h
A qemud/remote_dispatch_prototypes.h
As with the client side, the server side dispatch consists mainly of a
long and rather tedious list of calls which deal with deserialising the
args, calling the appropriate function, and serialising the result back
to the client.
In remote.c we enter from the QEMU daemon at remoteDispatchClientRequest
with a full request which has been read in but not decoded yet. This
function deserialises the request header (remote_message_header defined
in remote_protocol.x) and dispatches the request to the correct
remoteDispatch* function. This function is arranged so that the
remoteDispatch* functions need to do as little as possible -- in
particular error handling is handled transparently as far as they are
concerned. The function then serialises the reply (or error) and
returns it up to the QEMU daemon to be sent out.
You may notice in remoteDispatchClientRequest that parts are generated
automatically, eg. the dispatch switch statement:
switch (req.proc) {
#include "remote_dispatch_proc_switch.h"
default:
remoteDispatchError (client, &req, "unknown procedure: %d",
req.proc);
xdr_destroy (&xdr);
return;
}
This is to remove the need to write this tedious and error-prone code by
hand.
Each remoteDispatch* function can be as small as possible and deals only
with deserialising the remote_foo_args (parameters), calling the
appropriate libvirt function, then serialising the remote_foo_ret
(return value). Error cases are handled entirely by
remoteDispatchClientRequest in order to remove duplicated code.
The remoteDispatch* functions may return one of the following values:
0 = OK
-1 = The libvirt function returned an error
(remoteDispatchClientRequest will pick up and serialise the error)
-2 = There was an error in the dispatch function itself, something to
do with the mechanics of RPC. In this case the function has already set
up an error buffer using remoteDispatchError directly.
The four other attached files are the script used to generate the
automatically generated code for remoteDispatchClientRequest, and the 3
files of generated code that it creates, which I suggest we put in
EXTRA_DIST.
Rich.
--
Emerging Technologies, Red Hat
http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.
Registered in England and Wales under Company Registration No. 3798903
Directors: Michael Cunningham (USA), Charlie Peters (USA) and David
Owens (Ireland)