ia64/xen-unstable

view tools/libxen/src/xen_vbd_metrics.c @ 14150:42dd9055ee1f

Implementation of host_metrics.get_all, PIF_metrics.get_all, and docs and
bindings for many of the get_all methods elsewhere that Xend already
implemented.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 27 01:05:32 2007 +0000 (2007-02-27)
parents 7819d9332fba
children 678b8838d361
line source
1 /*
2 * Copyright (c) 2006-2007, XenSource Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
20 #include <stddef.h>
21 #include <stdlib.h>
23 #include "xen_common.h"
24 #include "xen_internal.h"
25 #include "xen_vbd_metrics.h"
28 XEN_FREE(xen_vbd_metrics)
29 XEN_SET_ALLOC_FREE(xen_vbd_metrics)
30 XEN_ALLOC(xen_vbd_metrics_record)
31 XEN_SET_ALLOC_FREE(xen_vbd_metrics_record)
32 XEN_ALLOC(xen_vbd_metrics_record_opt)
33 XEN_RECORD_OPT_FREE(xen_vbd_metrics)
34 XEN_SET_ALLOC_FREE(xen_vbd_metrics_record_opt)
37 static const struct_member xen_vbd_metrics_record_struct_members[] =
38 {
39 { .key = "uuid",
40 .type = &abstract_type_string,
41 .offset = offsetof(xen_vbd_metrics_record, uuid) },
42 { .key = "io_read_kbs",
43 .type = &abstract_type_float,
44 .offset = offsetof(xen_vbd_metrics_record, io_read_kbs) },
45 { .key = "io_write_kbs",
46 .type = &abstract_type_float,
47 .offset = offsetof(xen_vbd_metrics_record, io_write_kbs) }
48 };
50 const abstract_type xen_vbd_metrics_record_abstract_type_ =
51 {
52 .typename = STRUCT,
53 .struct_size = sizeof(xen_vbd_metrics_record),
54 .member_count =
55 sizeof(xen_vbd_metrics_record_struct_members) / sizeof(struct_member),
56 .members = xen_vbd_metrics_record_struct_members
57 };
60 void
61 xen_vbd_metrics_record_free(xen_vbd_metrics_record *record)
62 {
63 if (record == NULL)
64 {
65 return;
66 }
67 free(record->handle);
68 free(record->uuid);
69 free(record);
70 }
73 bool
74 xen_vbd_metrics_get_record(xen_session *session, xen_vbd_metrics_record **result, xen_vbd_metrics vbd_metrics)
75 {
76 abstract_value param_values[] =
77 {
78 { .type = &abstract_type_string,
79 .u.string_val = vbd_metrics }
80 };
82 abstract_type result_type = xen_vbd_metrics_record_abstract_type_;
84 *result = NULL;
85 XEN_CALL_("VBD_metrics.get_record");
87 if (session->ok)
88 {
89 (*result)->handle = xen_strdup_((*result)->uuid);
90 }
92 return session->ok;
93 }
96 bool
97 xen_vbd_metrics_get_by_uuid(xen_session *session, xen_vbd_metrics *result, char *uuid)
98 {
99 abstract_value param_values[] =
100 {
101 { .type = &abstract_type_string,
102 .u.string_val = uuid }
103 };
105 abstract_type result_type = abstract_type_string;
107 *result = NULL;
108 XEN_CALL_("VBD_metrics.get_by_uuid");
109 return session->ok;
110 }
113 bool
114 xen_vbd_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics)
115 {
116 abstract_value param_values[] =
117 {
118 { .type = &abstract_type_string,
119 .u.string_val = vbd_metrics }
120 };
122 abstract_type result_type = abstract_type_float;
124 XEN_CALL_("VBD_metrics.get_io_read_kbs");
125 return session->ok;
126 }
129 bool
130 xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics)
131 {
132 abstract_value param_values[] =
133 {
134 { .type = &abstract_type_string,
135 .u.string_val = vbd_metrics }
136 };
138 abstract_type result_type = abstract_type_float;
140 XEN_CALL_("VBD_metrics.get_io_write_kbs");
141 return session->ok;
142 }
145 bool
146 xen_vbd_metrics_get_all(xen_session *session, struct xen_vbd_metrics_set **result)
147 {
149 abstract_type result_type = abstract_type_string_set;
151 *result = NULL;
152 xen_call_(session, "VBD_metrics.get_all", NULL, 0, &result_type, result);
153 return session->ok;
154 }
157 bool
158 xen_vbd_metrics_get_uuid(xen_session *session, char **result, xen_vbd_metrics vbd_metrics)
159 {
160 *result = session->ok ? xen_strdup_((char *)vbd_metrics) : NULL;
161 return session->ok;
162 }