ia64/xen-unstable

diff tools/libxen/src/xen_vbd_metrics.c @ 14045:7819d9332fba

Split the VBD I/O statistics out into a VBD_metrics class. Document the
VBD.type field, and add it to the C bindings (this was already in Xend).

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 20 21:28:19 2007 +0000 (2007-02-20)
parents
children 42dd9055ee1f
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/libxen/src/xen_vbd_metrics.c	Tue Feb 20 21:28:19 2007 +0000
     1.3 @@ -0,0 +1,150 @@
     1.4 +/*
     1.5 + * Copyright (c) 2006-2007, XenSource Inc.
     1.6 + *
     1.7 + * This library is free software; you can redistribute it and/or
     1.8 + * modify it under the terms of the GNU Lesser General Public
     1.9 + * License as published by the Free Software Foundation; either
    1.10 + * version 2.1 of the License, or (at your option) any later version.
    1.11 + *
    1.12 + * This library is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.15 + * Lesser General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU Lesser General Public
    1.18 + * License along with this library; if not, write to the Free Software
    1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    1.20 + */
    1.21 +
    1.22 +
    1.23 +#include <stddef.h>
    1.24 +#include <stdlib.h>
    1.25 +
    1.26 +#include "xen_common.h"
    1.27 +#include "xen_internal.h"
    1.28 +#include "xen_vbd_metrics.h"
    1.29 +
    1.30 +
    1.31 +XEN_FREE(xen_vbd_metrics)
    1.32 +XEN_SET_ALLOC_FREE(xen_vbd_metrics)
    1.33 +XEN_ALLOC(xen_vbd_metrics_record)
    1.34 +XEN_SET_ALLOC_FREE(xen_vbd_metrics_record)
    1.35 +XEN_ALLOC(xen_vbd_metrics_record_opt)
    1.36 +XEN_RECORD_OPT_FREE(xen_vbd_metrics)
    1.37 +XEN_SET_ALLOC_FREE(xen_vbd_metrics_record_opt)
    1.38 +
    1.39 +
    1.40 +static const struct_member xen_vbd_metrics_record_struct_members[] =
    1.41 +    {
    1.42 +        { .key = "uuid",
    1.43 +          .type = &abstract_type_string,
    1.44 +          .offset = offsetof(xen_vbd_metrics_record, uuid) },
    1.45 +        { .key = "io_read_kbs",
    1.46 +          .type = &abstract_type_float,
    1.47 +          .offset = offsetof(xen_vbd_metrics_record, io_read_kbs) },
    1.48 +        { .key = "io_write_kbs",
    1.49 +          .type = &abstract_type_float,
    1.50 +          .offset = offsetof(xen_vbd_metrics_record, io_write_kbs) }
    1.51 +    };
    1.52 +
    1.53 +const abstract_type xen_vbd_metrics_record_abstract_type_ =
    1.54 +    {
    1.55 +       .typename = STRUCT,
    1.56 +       .struct_size = sizeof(xen_vbd_metrics_record),
    1.57 +       .member_count =
    1.58 +           sizeof(xen_vbd_metrics_record_struct_members) / sizeof(struct_member),
    1.59 +       .members = xen_vbd_metrics_record_struct_members
    1.60 +    };
    1.61 +
    1.62 +
    1.63 +void
    1.64 +xen_vbd_metrics_record_free(xen_vbd_metrics_record *record)
    1.65 +{
    1.66 +    if (record == NULL)
    1.67 +    {
    1.68 +        return;
    1.69 +    }
    1.70 +    free(record->handle);
    1.71 +    free(record->uuid);
    1.72 +    free(record);
    1.73 +}
    1.74 +
    1.75 +
    1.76 +bool
    1.77 +xen_vbd_metrics_get_record(xen_session *session, xen_vbd_metrics_record **result, xen_vbd_metrics vbd_metrics)
    1.78 +{
    1.79 +    abstract_value param_values[] =
    1.80 +        {
    1.81 +            { .type = &abstract_type_string,
    1.82 +              .u.string_val = vbd_metrics }
    1.83 +        };
    1.84 +
    1.85 +    abstract_type result_type = xen_vbd_metrics_record_abstract_type_;
    1.86 +
    1.87 +    *result = NULL;
    1.88 +    XEN_CALL_("VBD_metrics.get_record");
    1.89 +
    1.90 +    if (session->ok)
    1.91 +    {
    1.92 +       (*result)->handle = xen_strdup_((*result)->uuid);
    1.93 +    }
    1.94 +
    1.95 +    return session->ok;
    1.96 +}
    1.97 +
    1.98 +
    1.99 +bool
   1.100 +xen_vbd_metrics_get_by_uuid(xen_session *session, xen_vbd_metrics *result, char *uuid)
   1.101 +{
   1.102 +    abstract_value param_values[] =
   1.103 +        {
   1.104 +            { .type = &abstract_type_string,
   1.105 +              .u.string_val = uuid }
   1.106 +        };
   1.107 +
   1.108 +    abstract_type result_type = abstract_type_string;
   1.109 +
   1.110 +    *result = NULL;
   1.111 +    XEN_CALL_("VBD_metrics.get_by_uuid");
   1.112 +    return session->ok;
   1.113 +}
   1.114 +
   1.115 +
   1.116 +bool
   1.117 +xen_vbd_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics)
   1.118 +{
   1.119 +    abstract_value param_values[] =
   1.120 +        {
   1.121 +            { .type = &abstract_type_string,
   1.122 +              .u.string_val = vbd_metrics }
   1.123 +        };
   1.124 +
   1.125 +    abstract_type result_type = abstract_type_float;
   1.126 +
   1.127 +    XEN_CALL_("VBD_metrics.get_io_read_kbs");
   1.128 +    return session->ok;
   1.129 +}
   1.130 +
   1.131 +
   1.132 +bool
   1.133 +xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics)
   1.134 +{
   1.135 +    abstract_value param_values[] =
   1.136 +        {
   1.137 +            { .type = &abstract_type_string,
   1.138 +              .u.string_val = vbd_metrics }
   1.139 +        };
   1.140 +
   1.141 +    abstract_type result_type = abstract_type_float;
   1.142 +
   1.143 +    XEN_CALL_("VBD_metrics.get_io_write_kbs");
   1.144 +    return session->ok;
   1.145 +}
   1.146 +
   1.147 +
   1.148 +bool
   1.149 +xen_vbd_metrics_get_uuid(xen_session *session, char **result, xen_vbd_metrics vbd_metrics)
   1.150 +{
   1.151 +    *result = session->ok ? xen_strdup_((char *)vbd_metrics) : NULL;
   1.152 +    return session->ok;
   1.153 +}