ia64/xen-unstable

view tools/libxen/src/xen_vbd.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 0a422c8c3144
children bab07bed5c0a
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.h"
26 #include "xen_vbd_metrics.h"
27 #include "xen_vbd_mode_internal.h"
28 #include "xen_vbd_type_internal.h"
29 #include "xen_vdi.h"
30 #include "xen_vm.h"
33 XEN_FREE(xen_vbd)
34 XEN_SET_ALLOC_FREE(xen_vbd)
35 XEN_ALLOC(xen_vbd_record)
36 XEN_SET_ALLOC_FREE(xen_vbd_record)
37 XEN_ALLOC(xen_vbd_record_opt)
38 XEN_RECORD_OPT_FREE(xen_vbd)
39 XEN_SET_ALLOC_FREE(xen_vbd_record_opt)
42 static const struct_member xen_vbd_record_struct_members[] =
43 {
44 { .key = "uuid",
45 .type = &abstract_type_string,
46 .offset = offsetof(xen_vbd_record, uuid) },
47 { .key = "VM",
48 .type = &abstract_type_ref,
49 .offset = offsetof(xen_vbd_record, vm) },
50 { .key = "VDI",
51 .type = &abstract_type_ref,
52 .offset = offsetof(xen_vbd_record, vdi) },
53 { .key = "device",
54 .type = &abstract_type_string,
55 .offset = offsetof(xen_vbd_record, device) },
56 { .key = "image",
57 .type = &abstract_type_string,
58 .offset = offsetof(xen_vbd_record, image) },
59 { .key = "bootable",
60 .type = &abstract_type_bool,
61 .offset = offsetof(xen_vbd_record, bootable) },
62 { .key = "mode",
63 .type = &xen_vbd_mode_abstract_type_,
64 .offset = offsetof(xen_vbd_record, mode) },
65 { .key = "type",
66 .type = &xen_vbd_type_abstract_type_,
67 .offset = offsetof(xen_vbd_record, type) },
68 { .key = "metrics",
69 .type = &abstract_type_ref,
70 .offset = offsetof(xen_vbd_record, metrics) }
71 };
73 const abstract_type xen_vbd_record_abstract_type_ =
74 {
75 .typename = STRUCT,
76 .struct_size = sizeof(xen_vbd_record),
77 .member_count =
78 sizeof(xen_vbd_record_struct_members) / sizeof(struct_member),
79 .members = xen_vbd_record_struct_members
80 };
83 void
84 xen_vbd_record_free(xen_vbd_record *record)
85 {
86 if (record == NULL)
87 {
88 return;
89 }
90 free(record->handle);
91 free(record->uuid);
92 xen_vm_record_opt_free(record->vm);
93 xen_vdi_record_opt_free(record->vdi);
94 free(record->device);
95 xen_vbd_metrics_record_opt_free(record->metrics);
96 free(record);
97 }
100 bool
101 xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd)
102 {
103 abstract_value param_values[] =
104 {
105 { .type = &abstract_type_string,
106 .u.string_val = vbd }
107 };
109 abstract_type result_type = xen_vbd_record_abstract_type_;
111 *result = NULL;
112 XEN_CALL_("VBD.get_record");
114 if (session->ok)
115 {
116 (*result)->handle = xen_strdup_((*result)->uuid);
117 }
119 return session->ok;
120 }
123 bool
124 xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid)
125 {
126 abstract_value param_values[] =
127 {
128 { .type = &abstract_type_string,
129 .u.string_val = uuid }
130 };
132 abstract_type result_type = abstract_type_string;
134 *result = NULL;
135 XEN_CALL_("VBD.get_by_uuid");
136 return session->ok;
137 }
140 bool
141 xen_vbd_create(xen_session *session, xen_vbd *result, xen_vbd_record *record)
142 {
143 abstract_value param_values[] =
144 {
145 { .type = &xen_vbd_record_abstract_type_,
146 .u.struct_val = record }
147 };
149 abstract_type result_type = abstract_type_string;
151 *result = NULL;
152 XEN_CALL_("VBD.create");
153 return session->ok;
154 }
157 bool
158 xen_vbd_destroy(xen_session *session, xen_vbd vbd)
159 {
160 abstract_value param_values[] =
161 {
162 { .type = &abstract_type_string,
163 .u.string_val = vbd }
164 };
166 xen_call_(session, "VBD.destroy", param_values, 1, NULL, NULL);
167 return session->ok;
168 }
171 bool
172 xen_vbd_get_vm(xen_session *session, xen_vm *result, xen_vbd vbd)
173 {
174 abstract_value param_values[] =
175 {
176 { .type = &abstract_type_string,
177 .u.string_val = vbd }
178 };
180 abstract_type result_type = abstract_type_string;
182 *result = NULL;
183 XEN_CALL_("VBD.get_VM");
184 return session->ok;
185 }
188 bool
189 xen_vbd_get_vdi(xen_session *session, xen_vdi *result, xen_vbd vbd)
190 {
191 abstract_value param_values[] =
192 {
193 { .type = &abstract_type_string,
194 .u.string_val = vbd }
195 };
197 abstract_type result_type = abstract_type_string;
199 *result = NULL;
200 XEN_CALL_("VBD.get_VDI");
201 return session->ok;
202 }
205 bool
206 xen_vbd_get_device(xen_session *session, char **result, xen_vbd vbd)
207 {
208 abstract_value param_values[] =
209 {
210 { .type = &abstract_type_string,
211 .u.string_val = vbd }
212 };
214 abstract_type result_type = abstract_type_string;
216 *result = NULL;
217 XEN_CALL_("VBD.get_device");
218 return session->ok;
219 }
222 bool
223 xen_vbd_get_bootable(xen_session *session, bool *result, xen_vbd vbd)
224 {
225 abstract_value param_values[] =
226 {
227 { .type = &abstract_type_string,
228 .u.string_val = vbd }
229 };
231 abstract_type result_type = abstract_type_bool;
233 XEN_CALL_("VBD.get_bootable");
234 return session->ok;
235 }
238 bool
239 xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd)
240 {
241 abstract_value param_values[] =
242 {
243 { .type = &abstract_type_string,
244 .u.string_val = vbd }
245 };
247 abstract_type result_type = xen_vbd_mode_abstract_type_;
248 XEN_CALL_("VBD.get_mode");
249 return session->ok;
250 }
253 bool
254 xen_vbd_get_type(xen_session *session, enum xen_vbd_type *result, xen_vbd vbd)
255 {
256 abstract_value param_values[] =
257 {
258 { .type = &abstract_type_string,
259 .u.string_val = vbd }
260 };
262 abstract_type result_type = xen_vbd_type_abstract_type_;
263 XEN_CALL_("VBD.get_type");
264 return session->ok;
265 }
268 bool
269 xen_vbd_get_metrics(xen_session *session, xen_vbd_metrics *result, xen_vbd vbd)
270 {
271 abstract_value param_values[] =
272 {
273 { .type = &abstract_type_string,
274 .u.string_val = vbd }
275 };
277 abstract_type result_type = abstract_type_string;
279 *result = NULL;
280 XEN_CALL_("VBD.get_metrics");
281 return session->ok;
282 }
285 bool
286 xen_vbd_set_device(xen_session *session, xen_vbd vbd, char *device)
287 {
288 abstract_value param_values[] =
289 {
290 { .type = &abstract_type_string,
291 .u.string_val = vbd },
292 { .type = &abstract_type_string,
293 .u.string_val = device }
294 };
296 xen_call_(session, "VBD.set_device", param_values, 2, NULL, NULL);
297 return session->ok;
298 }
301 bool
302 xen_vbd_set_bootable(xen_session *session, xen_vbd vbd, bool bootable)
303 {
304 abstract_value param_values[] =
305 {
306 { .type = &abstract_type_string,
307 .u.string_val = vbd },
308 { .type = &abstract_type_bool,
309 .u.bool_val = bootable }
310 };
312 xen_call_(session, "VBD.set_bootable", param_values, 2, NULL, NULL);
313 return session->ok;
314 }
317 bool
318 xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode)
319 {
320 abstract_value param_values[] =
321 {
322 { .type = &abstract_type_string,
323 .u.string_val = vbd },
324 { .type = &xen_vbd_mode_abstract_type_,
325 .u.string_val = xen_vbd_mode_to_string(mode) }
326 };
328 xen_call_(session, "VBD.set_mode", param_values, 2, NULL, NULL);
329 return session->ok;
330 }
333 bool
334 xen_vbd_set_type(xen_session *session, xen_vbd vbd, enum xen_vbd_type type)
335 {
336 abstract_value param_values[] =
337 {
338 { .type = &abstract_type_string,
339 .u.string_val = vbd },
340 { .type = &xen_vbd_type_abstract_type_,
341 .u.string_val = xen_vbd_type_to_string(type) }
342 };
344 xen_call_(session, "VBD.set_type", param_values, 2, NULL, NULL);
345 return session->ok;
346 }
349 bool
350 xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi)
351 {
352 abstract_value param_values[] =
353 {
354 { .type = &abstract_type_string,
355 .u.string_val = vbd },
356 { .type = &abstract_type_string,
357 .u.string_val = vdi }
358 };
360 xen_call_(session, "VBD.media_change", param_values, 2, NULL, NULL);
361 return session->ok;
362 }
365 bool
366 xen_vbd_get_uuid(xen_session *session, char **result, xen_vbd vbd)
367 {
368 *result = session->ok ? xen_strdup_((char *)vbd) : NULL;
369 return session->ok;
370 }