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 | */ |
---|
18 | |
---|
19 | |
---|
20 | #include <stddef.h> |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "xen_internal.h" |
---|
24 | #include <xen/api/xen_common.h> |
---|
25 | #include <xen/api/xen_int_float_map.h> |
---|
26 | #include <xen/api/xen_int_int_map.h> |
---|
27 | #include <xen/api/xen_int_string_set_map.h> |
---|
28 | #include <xen/api/xen_string_string_map.h> |
---|
29 | #include <xen/api/xen_vm_metrics.h> |
---|
30 | |
---|
31 | |
---|
32 | XEN_FREE(xen_vm_metrics) |
---|
33 | XEN_SET_ALLOC_FREE(xen_vm_metrics) |
---|
34 | XEN_ALLOC(xen_vm_metrics_record) |
---|
35 | XEN_SET_ALLOC_FREE(xen_vm_metrics_record) |
---|
36 | XEN_ALLOC(xen_vm_metrics_record_opt) |
---|
37 | XEN_RECORD_OPT_FREE(xen_vm_metrics) |
---|
38 | XEN_SET_ALLOC_FREE(xen_vm_metrics_record_opt) |
---|
39 | |
---|
40 | |
---|
41 | static const struct_member xen_vm_metrics_record_struct_members[] = |
---|
42 | { |
---|
43 | { .key = "uuid", |
---|
44 | .type = &abstract_type_string, |
---|
45 | .offset = offsetof(xen_vm_metrics_record, uuid) }, |
---|
46 | { .key = "memory_actual", |
---|
47 | .type = &abstract_type_int, |
---|
48 | .offset = offsetof(xen_vm_metrics_record, memory_actual) }, |
---|
49 | { .key = "VCPUs_number", |
---|
50 | .type = &abstract_type_int, |
---|
51 | .offset = offsetof(xen_vm_metrics_record, vcpus_number) }, |
---|
52 | { .key = "VCPUs_utilisation", |
---|
53 | .type = &abstract_type_int_float_map, |
---|
54 | .offset = offsetof(xen_vm_metrics_record, vcpus_utilisation) }, |
---|
55 | { .key = "VCPUs_CPU", |
---|
56 | .type = &abstract_type_int_int_map, |
---|
57 | .offset = offsetof(xen_vm_metrics_record, vcpus_cpu) }, |
---|
58 | { .key = "VCPUs_params", |
---|
59 | .type = &abstract_type_string_string_map, |
---|
60 | .offset = offsetof(xen_vm_metrics_record, vcpus_params) }, |
---|
61 | { .key = "VCPUs_flags", |
---|
62 | .type = &abstract_type_int_string_set_map, |
---|
63 | .offset = offsetof(xen_vm_metrics_record, vcpus_flags) }, |
---|
64 | { .key = "state", |
---|
65 | .type = &abstract_type_string_set, |
---|
66 | .offset = offsetof(xen_vm_metrics_record, state) }, |
---|
67 | { .key = "start_time", |
---|
68 | .type = &abstract_type_datetime, |
---|
69 | .offset = offsetof(xen_vm_metrics_record, start_time) }, |
---|
70 | { .key = "last_updated", |
---|
71 | .type = &abstract_type_datetime, |
---|
72 | .offset = offsetof(xen_vm_metrics_record, last_updated) } |
---|
73 | }; |
---|
74 | |
---|
75 | const abstract_type xen_vm_metrics_record_abstract_type_ = |
---|
76 | { |
---|
77 | .typename = STRUCT, |
---|
78 | .struct_size = sizeof(xen_vm_metrics_record), |
---|
79 | .member_count = |
---|
80 | sizeof(xen_vm_metrics_record_struct_members) / sizeof(struct_member), |
---|
81 | .members = xen_vm_metrics_record_struct_members |
---|
82 | }; |
---|
83 | |
---|
84 | |
---|
85 | void |
---|
86 | xen_vm_metrics_record_free(xen_vm_metrics_record *record) |
---|
87 | { |
---|
88 | if (record == NULL) |
---|
89 | { |
---|
90 | return; |
---|
91 | } |
---|
92 | free(record->handle); |
---|
93 | free(record->uuid); |
---|
94 | xen_int_float_map_free(record->vcpus_utilisation); |
---|
95 | xen_int_int_map_free(record->vcpus_cpu); |
---|
96 | xen_string_string_map_free(record->vcpus_params); |
---|
97 | xen_int_string_set_map_free(record->vcpus_flags); |
---|
98 | xen_string_set_free(record->state); |
---|
99 | free(record); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | bool |
---|
104 | xen_vm_metrics_get_record(xen_session *session, xen_vm_metrics_record **result, xen_vm_metrics vm_metrics) |
---|
105 | { |
---|
106 | abstract_value param_values[] = |
---|
107 | { |
---|
108 | { .type = &abstract_type_string, |
---|
109 | .u.string_val = vm_metrics } |
---|
110 | }; |
---|
111 | |
---|
112 | abstract_type result_type = xen_vm_metrics_record_abstract_type_; |
---|
113 | |
---|
114 | *result = NULL; |
---|
115 | XEN_CALL_("VM_metrics.get_record"); |
---|
116 | |
---|
117 | if (session->ok) |
---|
118 | { |
---|
119 | (*result)->handle = xen_strdup_((*result)->uuid); |
---|
120 | } |
---|
121 | |
---|
122 | return session->ok; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | bool |
---|
127 | xen_vm_metrics_get_by_uuid(xen_session *session, xen_vm_metrics *result, char *uuid) |
---|
128 | { |
---|
129 | abstract_value param_values[] = |
---|
130 | { |
---|
131 | { .type = &abstract_type_string, |
---|
132 | .u.string_val = uuid } |
---|
133 | }; |
---|
134 | |
---|
135 | abstract_type result_type = abstract_type_string; |
---|
136 | |
---|
137 | *result = NULL; |
---|
138 | XEN_CALL_("VM_metrics.get_by_uuid"); |
---|
139 | return session->ok; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | bool |
---|
144 | xen_vm_metrics_get_memory_actual(xen_session *session, int64_t *result, xen_vm_metrics vm_metrics) |
---|
145 | { |
---|
146 | abstract_value param_values[] = |
---|
147 | { |
---|
148 | { .type = &abstract_type_string, |
---|
149 | .u.string_val = vm_metrics } |
---|
150 | }; |
---|
151 | |
---|
152 | abstract_type result_type = abstract_type_int; |
---|
153 | |
---|
154 | XEN_CALL_("VM_metrics.get_memory_actual"); |
---|
155 | return session->ok; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | bool |
---|
160 | xen_vm_metrics_get_vcpus_number(xen_session *session, int64_t *result, xen_vm_metrics vm_metrics) |
---|
161 | { |
---|
162 | abstract_value param_values[] = |
---|
163 | { |
---|
164 | { .type = &abstract_type_string, |
---|
165 | .u.string_val = vm_metrics } |
---|
166 | }; |
---|
167 | |
---|
168 | abstract_type result_type = abstract_type_int; |
---|
169 | |
---|
170 | XEN_CALL_("VM_metrics.get_VCPUs_number"); |
---|
171 | return session->ok; |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | bool |
---|
176 | xen_vm_metrics_get_vcpus_utilisation(xen_session *session, xen_int_float_map **result, xen_vm_metrics vm_metrics) |
---|
177 | { |
---|
178 | abstract_value param_values[] = |
---|
179 | { |
---|
180 | { .type = &abstract_type_string, |
---|
181 | .u.string_val = vm_metrics } |
---|
182 | }; |
---|
183 | |
---|
184 | abstract_type result_type = abstract_type_int_float_map; |
---|
185 | |
---|
186 | *result = NULL; |
---|
187 | XEN_CALL_("VM_metrics.get_VCPUs_utilisation"); |
---|
188 | return session->ok; |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | bool |
---|
193 | xen_vm_metrics_get_vcpus_cpu(xen_session *session, xen_int_int_map **result, xen_vm_metrics vm_metrics) |
---|
194 | { |
---|
195 | abstract_value param_values[] = |
---|
196 | { |
---|
197 | { .type = &abstract_type_string, |
---|
198 | .u.string_val = vm_metrics } |
---|
199 | }; |
---|
200 | |
---|
201 | abstract_type result_type = abstract_type_int_int_map; |
---|
202 | |
---|
203 | *result = NULL; |
---|
204 | XEN_CALL_("VM_metrics.get_VCPUs_CPU"); |
---|
205 | return session->ok; |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | bool |
---|
210 | xen_vm_metrics_get_vcpus_params(xen_session *session, xen_string_string_map **result, xen_vm_metrics vm_metrics) |
---|
211 | { |
---|
212 | abstract_value param_values[] = |
---|
213 | { |
---|
214 | { .type = &abstract_type_string, |
---|
215 | .u.string_val = vm_metrics } |
---|
216 | }; |
---|
217 | |
---|
218 | abstract_type result_type = abstract_type_string_string_map; |
---|
219 | |
---|
220 | *result = NULL; |
---|
221 | XEN_CALL_("VM_metrics.get_VCPUs_params"); |
---|
222 | return session->ok; |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | bool |
---|
227 | xen_vm_metrics_get_vcpus_flags(xen_session *session, xen_int_string_set_map **result, xen_vm_metrics vm_metrics) |
---|
228 | { |
---|
229 | abstract_value param_values[] = |
---|
230 | { |
---|
231 | { .type = &abstract_type_string, |
---|
232 | .u.string_val = vm_metrics } |
---|
233 | }; |
---|
234 | |
---|
235 | abstract_type result_type = abstract_type_int_string_set_map; |
---|
236 | |
---|
237 | *result = NULL; |
---|
238 | XEN_CALL_("VM_metrics.get_VCPUs_flags"); |
---|
239 | return session->ok; |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | bool |
---|
244 | xen_vm_metrics_get_state(xen_session *session, struct xen_string_set **result, xen_vm_metrics vm_metrics) |
---|
245 | { |
---|
246 | abstract_value param_values[] = |
---|
247 | { |
---|
248 | { .type = &abstract_type_string, |
---|
249 | .u.string_val = vm_metrics } |
---|
250 | }; |
---|
251 | |
---|
252 | abstract_type result_type = abstract_type_string_set; |
---|
253 | |
---|
254 | *result = NULL; |
---|
255 | XEN_CALL_("VM_metrics.get_state"); |
---|
256 | return session->ok; |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | bool |
---|
261 | xen_vm_metrics_get_start_time(xen_session *session, time_t *result, xen_vm_metrics vm_metrics) |
---|
262 | { |
---|
263 | abstract_value param_values[] = |
---|
264 | { |
---|
265 | { .type = &abstract_type_string, |
---|
266 | .u.string_val = vm_metrics } |
---|
267 | }; |
---|
268 | |
---|
269 | abstract_type result_type = abstract_type_datetime; |
---|
270 | |
---|
271 | XEN_CALL_("VM_metrics.get_start_time"); |
---|
272 | return session->ok; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | bool |
---|
277 | xen_vm_metrics_get_last_updated(xen_session *session, time_t *result, xen_vm_metrics vm_metrics) |
---|
278 | { |
---|
279 | abstract_value param_values[] = |
---|
280 | { |
---|
281 | { .type = &abstract_type_string, |
---|
282 | .u.string_val = vm_metrics } |
---|
283 | }; |
---|
284 | |
---|
285 | abstract_type result_type = abstract_type_datetime; |
---|
286 | |
---|
287 | XEN_CALL_("VM_metrics.get_last_updated"); |
---|
288 | return session->ok; |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | bool |
---|
293 | xen_vm_metrics_get_all(xen_session *session, struct xen_vm_metrics_set **result) |
---|
294 | { |
---|
295 | |
---|
296 | abstract_type result_type = abstract_type_string_set; |
---|
297 | |
---|
298 | *result = NULL; |
---|
299 | xen_call_(session, "VM_metrics.get_all", NULL, 0, &result_type, result); |
---|
300 | return session->ok; |
---|
301 | } |
---|
302 | |
---|
303 | |
---|
304 | bool |
---|
305 | xen_vm_metrics_get_uuid(xen_session *session, char **result, xen_vm_metrics vm_metrics) |
---|
306 | { |
---|
307 | abstract_value param_values[] = |
---|
308 | { |
---|
309 | { .type = &abstract_type_string, |
---|
310 | .u.string_val = vm_metrics } |
---|
311 | }; |
---|
312 | |
---|
313 | abstract_type result_type = abstract_type_string; |
---|
314 | |
---|
315 | *result = NULL; |
---|
316 | XEN_CALL_("VM_metrics.get_uuid"); |
---|
317 | return session->ok; |
---|
318 | } |
---|