[Libvir] [PATCH] Remote 4/8: Server-side call dispatch

Richard W.M. Jones rjones at redhat.com
Sat May 5 11:30:13 UTC 2007


> 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote.c
Type: text/x-csrc
Size: 44687 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote_generate_stubs.pl
Type: application/x-perl
Size: 5562 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0001.pl>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote_dispatch_localvars.h
Type: text/x-chdr
Size: 5081 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote_dispatch_proc_switch.h
Type: text/x-chdr
Size: 20999 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote_dispatch_prototypes.h
Type: text/x-chdr
Size: 8800 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070505/19a840bc/attachment-0009.bin>


More information about the libvir-list mailing list