[libvirt] [PATCHv2 4/6] virNodeGetCPUTime: Implement remote protocol

Daniel P. Berrange berrange at redhat.com
Tue Apr 19 10:58:00 UTC 2011


On Fri, Apr 08, 2011 at 08:36:02PM +0900, Minoru Usui wrote:
> virNodeGetCPUTime: Implement remote protocol
> 
> Signed-off-by: Minoru Usui <usui at mxm.nes.nec.co.jp>
> ---
>  daemon/remote.c                     |   48 +++++++++++++++++++++++++++++++++++
>  daemon/remote_dispatch_args.h       |    1 +
>  daemon/remote_dispatch_prototypes.h |    8 ++++++
>  daemon/remote_dispatch_ret.h        |    1 +
>  daemon/remote_dispatch_table.h      |    5 +++
>  src/remote/remote_driver.c          |   37 +++++++++++++++++++++++++++
>  src/remote/remote_protocol.c        |   33 ++++++++++++++++++++++++
>  src/remote/remote_protocol.h        |   28 ++++++++++++++++++++
>  src/remote/remote_protocol.x        |   20 ++++++++++++++-
>  src/remote_protocol-structs         |   14 ++++++++++
>  10 files changed, 194 insertions(+), 1 deletions(-)
> 
> diff --git a/daemon/remote.c b/daemon/remote.c
> index 1700c2d..a6c21eb 100644
> --- a/daemon/remote.c
> +++ b/daemon/remote.c
> @@ -679,6 +679,54 @@ remoteDispatchGetCapabilities (struct qemud_server *server ATTRIBUTE_UNUSED,
>  }
>  
>  static int
> +remoteDispatchNodeGetCpuTime (struct qemud_server *server ATTRIBUTE_UNUSED,
> +                                      struct qemud_client *client ATTRIBUTE_UNUSED,
> +                                      virConnectPtr conn,
> +                                      remote_message_header *hdr ATTRIBUTE_UNUSED,
> +                                      remote_error *rerr,
> +                                      remote_node_get_cpu_time_args *args,
> +                                      remote_node_get_cpu_time_ret *ret)
> +{
> +    struct _virNodeCpuTime *stats;
> +    unsigned int nr_stats, i;
> +
> +    if (args->maxStats > REMOTE_NODE_CPU_TIME_MAX) {
> +        remoteDispatchFormatError (rerr, "%s",
> +                               _("maxStats > REMOTE_NODE_CPU_TIME_MAX"));
> +        return -1;
> +    }
> +
> +    /* Allocate stats array for making dispatch call */
> +    if (VIR_ALLOC_N(stats, args->maxStats) < 0) {
> +        remoteDispatchOOMError(rerr);
> +        return -1;
> +    }
> +
> +    nr_stats = virNodeGetCpuTime (conn, stats, args->maxStats, 0);
> +    if (nr_stats == -1) {
> +        VIR_FREE(stats);
> +        remoteDispatchConnError(rerr, conn);
> +        return -1;
> +    }
> +
> +    /* Allocate return buffer */
> +    if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0) {
> +        VIR_FREE(stats);
> +        remoteDispatchOOMError(rerr);
> +        return -1;
> +    }
> +
> +    /* Copy the stats into the xdr return structure */
> +    for (i = 0; i < nr_stats; i++) {
> +        ret->stats.stats_val[i].tag = stats[i].tag;
> +        ret->stats.stats_val[i].val = stats[i].val;
> +    }
> +    ret->stats.stats_len = nr_stats;
> +    VIR_FREE(stats);
> +    return 0;
> +}

I recently re-structured all the APIs in this file, to follow a
new coding style. This method would need to be updated to match.


    {
        virNodeCpuTime *stats = NULL;
        int nr_stats, i;
        int rv = -1;
    
        if (args->maxStats > REMOTE_NODE_CPU_TIME_MAX) {
            virNetError (VIR_ERR_INTERNAL_ERROR, "%s",
                         _("maxStats > REMOTE_NODE_CPU_TIME_MAX"));
            goto cleanup;
        }
    
        /* Allocate stats array for making dispatch call */
        if (VIR_ALLOC_N(stats, args->maxStats) < 0) {
            virReportOOMError();
            goto cleanup;
        }
    
        if ((nr_stats = virNodeGetCpuTime (conn, stats, args->maxStats, 0)) < 0)
            goto cleanup;
    
        /* Allocate return buffer */
        if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0) {
            virReportOOMError();
            goto cleanup;
        }
    
        /* Copy the stats into the xdr return structure */
        for (i = 0; i < nr_stats; i++) {
            ret->stats.stats_val[i].tag = stats[i].tag;
            ret->stats.stats_val[i].val = stats[i].val;
        }
        ret->stats.stats_len = nr_stats;
        rv = 0;

     cleanup:
        if (rv < 0)
           remoteDispatchError(rerr);
        VIR_FREE(stats);
        return rv;
    }


Of course, if we change the public API as I suggest, it'll need a couple
more changes too.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list