ia64/xen-unstable

changeset 14858:249de074617f

Added documentation, C bindings, and test for VM_metrics.VCPUs_flags.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Fri Apr 13 18:14:06 2007 +0100 (2007-04-13)
parents 456c611ada02
children 6a4c6d8a00f5
files docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_int_string_set_map.h tools/libxen/include/xen_internal.h tools/libxen/include/xen_vm_metrics.h tools/libxen/src/xen_common.c tools/libxen/src/xen_int_string_set_map.c tools/libxen/src/xen_vm_metrics.c tools/libxen/test/test_bindings.c
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Thu Apr 12 22:49:02 2007 +0100
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Fri Apr 13 18:14:06 2007 +0100
     1.3 @@ -4289,6 +4289,7 @@ Quals & Field & Type & Description \\
     1.4  $\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/utilisation} & (int $\rightarrow$ float) Map & Utilisation for all of guest's current VCPUs \\
     1.5  $\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/CPU} & (int $\rightarrow$ int) Map & VCPU to PCPU map \\
     1.6  $\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/params} & (string $\rightarrow$ string) Map & The live equivalent to VM.VCPUs\_params \\
     1.7 +$\mathit{RO}_\mathit{run}$ &  {\tt VCPUs/flags} & (int $\rightarrow$ string Set) Map & CPU flags (blocked,online,running) \\
     1.8  $\mathit{RO}_\mathit{run}$ &  {\tt state} & string Set & The state of the guest, eg blocked, dying etc \\
     1.9  $\mathit{RO}_\mathit{run}$ &  {\tt start\_time} & datetime & Time at which this VM was last booted \\
    1.10  $\mathit{RO}_\mathit{run}$ &  {\tt last\_updated} & datetime & Time at which this information was last updated \\
    1.11 @@ -4508,6 +4509,38 @@ value of the field
    1.12  \vspace{0.3cm}
    1.13  \vspace{0.3cm}
    1.14  \vspace{0.3cm}
    1.15 +\subsubsection{RPC name:~get\_VCPUs\_flags}
    1.16 +
    1.17 +{\bf Overview:} 
    1.18 +Get the VCPUs/flags field of the given VM\_metrics.
    1.19 +
    1.20 + \noindent {\bf Signature:} 
    1.21 +\begin{verbatim} ((int -> string Set) Map) get_VCPUs_flags (session_id s, VM_metrics ref self)\end{verbatim}
    1.22 +
    1.23 +
    1.24 +\noindent{\bf Arguments:}
    1.25 +
    1.26 + 
    1.27 +\vspace{0.3cm}
    1.28 +\begin{tabular}{|c|c|p{7cm}|}
    1.29 + \hline
    1.30 +{\bf type} & {\bf name} & {\bf description} \\ \hline
    1.31 +{\tt VM\_metrics ref } & self & reference to the object \\ \hline 
    1.32 +
    1.33 +\end{tabular}
    1.34 +
    1.35 +\vspace{0.3cm}
    1.36 +
    1.37 + \noindent {\bf Return Type:} 
    1.38 +{\tt 
    1.39 +(int $\rightarrow$ string Set) Map
    1.40 +}
    1.41 +
    1.42 +
    1.43 +value of the field
    1.44 +\vspace{0.3cm}
    1.45 +\vspace{0.3cm}
    1.46 +\vspace{0.3cm}
    1.47  \subsubsection{RPC name:~get\_state}
    1.48  
    1.49  {\bf Overview:} 
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/libxen/include/xen_int_string_set_map.h	Fri Apr 13 18:14:06 2007 +0100
     2.3 @@ -0,0 +1,53 @@
     2.4 +/*
     2.5 + * Copyright (c) 2006-2007, XenSource Inc.
     2.6 + *
     2.7 + * This library is free software; you can redistribute it and/or
     2.8 + * modify it under the terms of the GNU Lesser General Public
     2.9 + * License as published by the Free Software Foundation; either
    2.10 + * version 2.1 of the License, or (at your option) any later version.
    2.11 + *
    2.12 + * This library is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.15 + * Lesser General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU Lesser General Public
    2.18 + * License along with this library; if not, write to the Free Software
    2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    2.20 + */
    2.21 +
    2.22 +#ifndef XEN_INT_STRING_SET_MAP_H
    2.23 +#define XEN_INT_STRING_SET_MAP_H
    2.24 +
    2.25 +
    2.26 +#include "xen_common.h"
    2.27 +
    2.28 +
    2.29 +typedef struct xen_int_string_set_map_contents
    2.30 +{
    2.31 +  int64_t key;
    2.32 +  struct xen_string_set *val;
    2.33 +} xen_int_string_set_map_contents;
    2.34 +
    2.35 +
    2.36 +typedef struct xen_int_string_set_map
    2.37 +{
    2.38 +    size_t size;
    2.39 +    xen_int_string_set_map_contents contents[];
    2.40 +} xen_int_string_set_map;
    2.41 +
    2.42 +/**
    2.43 + * Allocate a xen_int_string_set_map of the given size.
    2.44 + */
    2.45 +extern xen_int_string_set_map *
    2.46 +xen_int_string_set_map_alloc(size_t size);
    2.47 +
    2.48 +/**
    2.49 + * Free the given xen_int_string_set_map, and all referenced values. 
    2.50 + * The given map must have been allocated by this library.
    2.51 + */
    2.52 +extern void
    2.53 +xen_int_string_set_map_free(xen_int_string_set_map *map);
    2.54 +
    2.55 +
    2.56 +#endif
     3.1 --- a/tools/libxen/include/xen_internal.h	Thu Apr 12 22:49:02 2007 +0100
     3.2 +++ b/tools/libxen/include/xen_internal.h	Fri Apr 13 18:14:06 2007 +0100
     3.3 @@ -87,6 +87,7 @@ extern const abstract_type abstract_type
     3.4  extern const abstract_type abstract_type_string_string_map;
     3.5  extern const abstract_type abstract_type_int_float_map;
     3.6  extern const abstract_type abstract_type_int_int_map;
     3.7 +extern const abstract_type abstract_type_int_string_set_map;
     3.8  
     3.9  
    3.10  typedef struct abstract_value
     4.1 --- a/tools/libxen/include/xen_vm_metrics.h	Thu Apr 12 22:49:02 2007 +0100
     4.2 +++ b/tools/libxen/include/xen_vm_metrics.h	Fri Apr 13 18:14:06 2007 +0100
     4.3 @@ -22,6 +22,7 @@
     4.4  #include "xen_common.h"
     4.5  #include "xen_int_float_map.h"
     4.6  #include "xen_int_int_map.h"
     4.7 +#include "xen_int_string_set_map.h"
     4.8  #include "xen_string_set.h"
     4.9  #include "xen_string_string_map.h"
    4.10  #include "xen_vm_metrics_decl.h"
    4.11 @@ -71,6 +72,7 @@ typedef struct xen_vm_metrics_record
    4.12      xen_int_float_map *vcpus_utilisation;
    4.13      xen_int_int_map *vcpus_cpu;
    4.14      xen_string_string_map *vcpus_params;
    4.15 +    xen_int_string_set_map *vcpus_flags;
    4.16      struct xen_string_set *state;
    4.17      time_t start_time;
    4.18      time_t last_updated;
    4.19 @@ -212,6 +214,13 @@ xen_vm_metrics_get_vcpus_params(xen_sess
    4.20  
    4.21  
    4.22  /**
    4.23 + * Get the VCPUs/flags field of the given VM_metrics.
    4.24 + */
    4.25 +extern bool
    4.26 +xen_vm_metrics_get_vcpus_flags(xen_session *session, xen_int_string_set_map **result, xen_vm_metrics vm_metrics);
    4.27 +
    4.28 +
    4.29 +/**
    4.30   * Get the state field of the given VM_metrics.
    4.31   */
    4.32  extern bool
     5.1 --- a/tools/libxen/src/xen_common.c	Thu Apr 12 22:49:02 2007 +0100
     5.2 +++ b/tools/libxen/src/xen_common.c	Fri Apr 13 18:14:06 2007 +0100
     5.3 @@ -36,6 +36,7 @@
     5.4  #include "xen_internal.h"
     5.5  #include "xen_int_float_map.h"
     5.6  #include "xen_int_int_map.h"
     5.7 +#include "xen_int_string_set_map.h"
     5.8  #include "xen_string_string_map.h"
     5.9  
    5.10  
    5.11 @@ -1716,3 +1717,21 @@ const abstract_type abstract_type_int_in
    5.12          .struct_size = sizeof(xen_int_int_map_contents),
    5.13          .members = int_int_members
    5.14      };
    5.15 +
    5.16 +static struct struct_member int_string_set_members[] =
    5.17 +{
    5.18 +    {
    5.19 +        .type = &abstract_type_int,
    5.20 +        .offset = offsetof(xen_int_string_set_map_contents, key)
    5.21 +    },
    5.22 +    {
    5.23 +        .type = &abstract_type_string_set,
    5.24 +        .offset = offsetof(xen_int_string_set_map_contents, val)
    5.25 +    }
    5.26 +};
    5.27 +const abstract_type abstract_type_int_string_set_map =
    5.28 +    {
    5.29 +        .typename = MAP,
    5.30 +        .struct_size = sizeof(xen_int_string_set_map_contents),
    5.31 +        .members = int_string_set_members
    5.32 +    };
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxen/src/xen_int_string_set_map.c	Fri Apr 13 18:14:06 2007 +0100
     6.3 @@ -0,0 +1,52 @@
     6.4 +/*
     6.5 + * Copyright (c) 2006-2007, XenSource Inc.
     6.6 + *
     6.7 + * This library is free software; you can redistribute it and/or
     6.8 + * modify it under the terms of the GNU Lesser General Public
     6.9 + * License as published by the Free Software Foundation; either
    6.10 + * version 2.1 of the License, or (at your option) any later version.
    6.11 + *
    6.12 + * This library is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.15 + * Lesser General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU Lesser General Public
    6.18 + * License along with this library; if not, write to the Free Software
    6.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    6.20 + */
    6.21 +
    6.22 +
    6.23 +#include "xen_common.h"
    6.24 +#include "xen_int_string_set_map.h"
    6.25 +#include "xen_internal.h"
    6.26 +#include "xen_string_set.h"
    6.27 +
    6.28 +
    6.29 +xen_int_string_set_map *
    6.30 +xen_int_string_set_map_alloc(size_t size)
    6.31 +{
    6.32 +    xen_int_string_set_map *result = calloc(1, sizeof(xen_int_string_set_map) +
    6.33 +                                            size * sizeof(struct xen_int_string_set_map_contents));
    6.34 +    result->size = size;
    6.35 +    return result;
    6.36 +}
    6.37 +
    6.38 +
    6.39 +void
    6.40 +xen_int_string_set_map_free(xen_int_string_set_map *map)
    6.41 +{
    6.42 +    if (map == NULL)
    6.43 +    {
    6.44 +        return;
    6.45 +    }
    6.46 +
    6.47 +    size_t n = map->size;
    6.48 +    for (size_t i = 0; i < n; i++)
    6.49 +    {
    6.50 +        
    6.51 +        xen_string_set_free(map->contents[i].val);
    6.52 +    }
    6.53 +
    6.54 +    free(map);
    6.55 +}
     7.1 --- a/tools/libxen/src/xen_vm_metrics.c	Thu Apr 12 22:49:02 2007 +0100
     7.2 +++ b/tools/libxen/src/xen_vm_metrics.c	Fri Apr 13 18:14:06 2007 +0100
     7.3 @@ -23,6 +23,7 @@
     7.4  #include "xen_common.h"
     7.5  #include "xen_int_float_map.h"
     7.6  #include "xen_int_int_map.h"
     7.7 +#include "xen_int_string_set_map.h"
     7.8  #include "xen_internal.h"
     7.9  #include "xen_string_string_map.h"
    7.10  #include "xen_vm_metrics.h"
    7.11 @@ -57,6 +58,9 @@ static const struct_member xen_vm_metric
    7.12          { .key = "VCPUs_params",
    7.13            .type = &abstract_type_string_string_map,
    7.14            .offset = offsetof(xen_vm_metrics_record, vcpus_params) },
    7.15 +        { .key = "VCPUs_flags",
    7.16 +          .type = &abstract_type_int_string_set_map,
    7.17 +          .offset = offsetof(xen_vm_metrics_record, vcpus_flags) },
    7.18          { .key = "state",
    7.19            .type = &abstract_type_string_set,
    7.20            .offset = offsetof(xen_vm_metrics_record, state) },
    7.21 @@ -90,6 +94,7 @@ xen_vm_metrics_record_free(xen_vm_metric
    7.22      xen_int_float_map_free(record->vcpus_utilisation);
    7.23      xen_int_int_map_free(record->vcpus_cpu);
    7.24      xen_string_string_map_free(record->vcpus_params);
    7.25 +    xen_int_string_set_map_free(record->vcpus_flags);
    7.26      xen_string_set_free(record->state);
    7.27      free(record);
    7.28  }
    7.29 @@ -219,6 +224,23 @@ xen_vm_metrics_get_vcpus_params(xen_sess
    7.30  
    7.31  
    7.32  bool
    7.33 +xen_vm_metrics_get_vcpus_flags(xen_session *session, xen_int_string_set_map **result, xen_vm_metrics vm_metrics)
    7.34 +{
    7.35 +    abstract_value param_values[] =
    7.36 +        {
    7.37 +            { .type = &abstract_type_string,
    7.38 +              .u.string_val = vm_metrics }
    7.39 +        };
    7.40 +
    7.41 +    abstract_type result_type = abstract_type_int_string_set_map;
    7.42 +
    7.43 +    *result = NULL;
    7.44 +    XEN_CALL_("VM_metrics.get_VCPUs_flags");
    7.45 +    return session->ok;
    7.46 +}
    7.47 +
    7.48 +
    7.49 +bool
    7.50  xen_vm_metrics_get_state(xen_session *session, struct xen_string_set **result, xen_vm_metrics vm_metrics)
    7.51  {
    7.52      abstract_value param_values[] =
     8.1 --- a/tools/libxen/test/test_bindings.c	Thu Apr 12 22:49:02 2007 +0100
     8.2 +++ b/tools/libxen/test/test_bindings.c	Fri Apr 13 18:14:06 2007 +0100
     8.3 @@ -684,6 +684,8 @@ static void print_session_info(xen_sessi
     8.4  
     8.5      if (!session->ok)
     8.6      {
     8.7 +        free(uuid);
     8.8 +        free(this_user);
     8.9          xen_session_record_free(record);
    8.10          print_error(session);
    8.11          return;
    8.12 @@ -692,6 +694,8 @@ static void print_session_info(xen_sessi
    8.13      assert(!strcmp(record->uuid, uuid));
    8.14      assert(!strcmp(record->this_user, this_user));
    8.15  
    8.16 +    free(uuid);
    8.17 +    free(this_user);
    8.18      xen_session_record_free(record);
    8.19  
    8.20      fflush(stdout);
    8.21 @@ -784,6 +788,22 @@ static void print_vm_metrics(xen_session
    8.22                 vm_metrics_record->vcpus_params->contents[i].val);
    8.23      }
    8.24  
    8.25 +    for (size_t i = 0; i < vm_metrics_record->vcpus_flags->size; i++)
    8.26 +    {
    8.27 +        printf("%"PRId64" -> ",
    8.28 +               vm_metrics_record->vcpus_flags->contents[i].key);
    8.29 +        xen_string_set *s = vm_metrics_record->vcpus_flags->contents[i].val;
    8.30 +        for (size_t j = 0; j < s->size; j++)
    8.31 +        {
    8.32 +            printf("%s", s->contents[j]);
    8.33 +            if (j + 1 != s->size)
    8.34 +            {
    8.35 +                printf(", ");
    8.36 +            }
    8.37 +        }
    8.38 +        printf("\n");
    8.39 +    }
    8.40 +
    8.41      xen_vm_metrics_record_free(vm_metrics_record);
    8.42      xen_vm_metrics_free(vm_metrics);
    8.43