ia64/xen-unstable

view tools/libxen/src/xen_vbd.c @ 14116:fd7f23e44b11

Added VBD. and VIF.qos_supported_algorithms fields, with C bindings, Xend
implementation to follow.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Feb 21 23:03:00 2007 +0000 (2007-02-21)
parents bab07bed5c0a
children cfd23ac1b32a
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_string_string_map.h"
26 #include "xen_vbd.h"
27 #include "xen_vbd_metrics.h"
28 #include "xen_vbd_mode_internal.h"
29 #include "xen_vbd_type_internal.h"
30 #include "xen_vdi.h"
31 #include "xen_vm.h"
34 XEN_FREE(xen_vbd)
35 XEN_SET_ALLOC_FREE(xen_vbd)
36 XEN_ALLOC(xen_vbd_record)
37 XEN_SET_ALLOC_FREE(xen_vbd_record)
38 XEN_ALLOC(xen_vbd_record_opt)
39 XEN_RECORD_OPT_FREE(xen_vbd)
40 XEN_SET_ALLOC_FREE(xen_vbd_record_opt)
43 static const struct_member xen_vbd_record_struct_members[] =
44 {
45 { .key = "uuid",
46 .type = &abstract_type_string,
47 .offset = offsetof(xen_vbd_record, uuid) },
48 { .key = "VM",
49 .type = &abstract_type_ref,
50 .offset = offsetof(xen_vbd_record, vm) },
51 { .key = "VDI",
52 .type = &abstract_type_ref,
53 .offset = offsetof(xen_vbd_record, vdi) },
54 { .key = "device",
55 .type = &abstract_type_string,
56 .offset = offsetof(xen_vbd_record, device) },
57 { .key = "image",
58 .type = &abstract_type_string,
59 .offset = offsetof(xen_vbd_record, image) },
60 { .key = "bootable",
61 .type = &abstract_type_bool,
62 .offset = offsetof(xen_vbd_record, bootable) },
63 { .key = "mode",
64 .type = &xen_vbd_mode_abstract_type_,
65 .offset = offsetof(xen_vbd_record, mode) },
66 { .key = "type",
67 .type = &xen_vbd_type_abstract_type_,
68 .offset = offsetof(xen_vbd_record, type) },
69 { .key = "qos_algorithm_type",
70 .type = &abstract_type_string,
71 .offset = offsetof(xen_vbd_record, qos_algorithm_type) },
72 { .key = "qos_algorithm_params",
73 .type = &abstract_type_string_string_map,
74 .offset = offsetof(xen_vbd_record, qos_algorithm_params) },
75 { .key = "qos_supported_algorithms",
76 .type = &abstract_type_string_set,
77 .offset = offsetof(xen_vbd_record, qos_supported_algorithms) },
78 { .key = "metrics",
79 .type = &abstract_type_ref,
80 .offset = offsetof(xen_vbd_record, metrics) }
81 };
83 const abstract_type xen_vbd_record_abstract_type_ =
84 {
85 .typename = STRUCT,
86 .struct_size = sizeof(xen_vbd_record),
87 .member_count =
88 sizeof(xen_vbd_record_struct_members) / sizeof(struct_member),
89 .members = xen_vbd_record_struct_members
90 };
93 void
94 xen_vbd_record_free(xen_vbd_record *record)
95 {
96 if (record == NULL)
97 {
98 return;
99 }
100 free(record->handle);
101 free(record->uuid);
102 xen_vm_record_opt_free(record->vm);
103 xen_vdi_record_opt_free(record->vdi);
104 free(record->device);
105 free(record->qos_algorithm_type);
106 xen_string_string_map_free(record->qos_algorithm_params);
107 xen_string_set_free(record->qos_supported_algorithms);
108 xen_vbd_metrics_record_opt_free(record->metrics);
109 free(record);
110 }
113 bool
114 xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd)
115 {
116 abstract_value param_values[] =
117 {
118 { .type = &abstract_type_string,
119 .u.string_val = vbd }
120 };
122 abstract_type result_type = xen_vbd_record_abstract_type_;
124 *result = NULL;
125 XEN_CALL_("VBD.get_record");
127 if (session->ok)
128 {
129 (*result)->handle = xen_strdup_((*result)->uuid);
130 }
132 return session->ok;
133 }
136 bool
137 xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid)
138 {
139 abstract_value param_values[] =
140 {
141 { .type = &abstract_type_string,
142 .u.string_val = uuid }
143 };
145 abstract_type result_type = abstract_type_string;
147 *result = NULL;
148 XEN_CALL_("VBD.get_by_uuid");
149 return session->ok;
150 }
153 bool
154 xen_vbd_create(xen_session *session, xen_vbd *result, xen_vbd_record *record)
155 {
156 abstract_value param_values[] =
157 {
158 { .type = &xen_vbd_record_abstract_type_,
159 .u.struct_val = record }
160 };
162 abstract_type result_type = abstract_type_string;
164 *result = NULL;
165 XEN_CALL_("VBD.create");
166 return session->ok;
167 }
170 bool
171 xen_vbd_destroy(xen_session *session, xen_vbd vbd)
172 {
173 abstract_value param_values[] =
174 {
175 { .type = &abstract_type_string,
176 .u.string_val = vbd }
177 };
179 xen_call_(session, "VBD.destroy", param_values, 1, NULL, NULL);
180 return session->ok;
181 }
184 bool
185 xen_vbd_get_vm(xen_session *session, xen_vm *result, xen_vbd vbd)
186 {
187 abstract_value param_values[] =
188 {
189 { .type = &abstract_type_string,
190 .u.string_val = vbd }
191 };
193 abstract_type result_type = abstract_type_string;
195 *result = NULL;
196 XEN_CALL_("VBD.get_VM");
197 return session->ok;
198 }
201 bool
202 xen_vbd_get_vdi(xen_session *session, xen_vdi *result, xen_vbd vbd)
203 {
204 abstract_value param_values[] =
205 {
206 { .type = &abstract_type_string,
207 .u.string_val = vbd }
208 };
210 abstract_type result_type = abstract_type_string;
212 *result = NULL;
213 XEN_CALL_("VBD.get_VDI");
214 return session->ok;
215 }
218 bool
219 xen_vbd_get_device(xen_session *session, char **result, xen_vbd vbd)
220 {
221 abstract_value param_values[] =
222 {
223 { .type = &abstract_type_string,
224 .u.string_val = vbd }
225 };
227 abstract_type result_type = abstract_type_string;
229 *result = NULL;
230 XEN_CALL_("VBD.get_device");
231 return session->ok;
232 }
235 bool
236 xen_vbd_get_bootable(xen_session *session, bool *result, xen_vbd vbd)
237 {
238 abstract_value param_values[] =
239 {
240 { .type = &abstract_type_string,
241 .u.string_val = vbd }
242 };
244 abstract_type result_type = abstract_type_bool;
246 XEN_CALL_("VBD.get_bootable");
247 return session->ok;
248 }
251 bool
252 xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd)
253 {
254 abstract_value param_values[] =
255 {
256 { .type = &abstract_type_string,
257 .u.string_val = vbd }
258 };
260 abstract_type result_type = xen_vbd_mode_abstract_type_;
261 XEN_CALL_("VBD.get_mode");
262 return session->ok;
263 }
266 bool
267 xen_vbd_get_type(xen_session *session, enum xen_vbd_type *result, xen_vbd vbd)
268 {
269 abstract_value param_values[] =
270 {
271 { .type = &abstract_type_string,
272 .u.string_val = vbd }
273 };
275 abstract_type result_type = xen_vbd_type_abstract_type_;
276 XEN_CALL_("VBD.get_type");
277 return session->ok;
278 }
281 bool
282 xen_vbd_get_qos_algorithm_type(xen_session *session, char **result, xen_vbd vbd)
283 {
284 abstract_value param_values[] =
285 {
286 { .type = &abstract_type_string,
287 .u.string_val = vbd }
288 };
290 abstract_type result_type = abstract_type_string;
292 *result = NULL;
293 XEN_CALL_("VBD.get_qos_algorithm_type");
294 return session->ok;
295 }
298 bool
299 xen_vbd_get_qos_algorithm_params(xen_session *session, xen_string_string_map **result, xen_vbd vbd)
300 {
301 abstract_value param_values[] =
302 {
303 { .type = &abstract_type_string,
304 .u.string_val = vbd }
305 };
307 abstract_type result_type = abstract_type_string_string_map;
309 *result = NULL;
310 XEN_CALL_("VBD.get_qos_algorithm_params");
311 return session->ok;
312 }
315 bool
316 xen_vbd_get_qos_supported_algorithms(xen_session *session, struct xen_string_set **result, xen_vbd vbd)
317 {
318 abstract_value param_values[] =
319 {
320 { .type = &abstract_type_string,
321 .u.string_val = vbd }
322 };
324 abstract_type result_type = abstract_type_string_set;
326 *result = NULL;
327 XEN_CALL_("VBD.get_qos_supported_algorithms");
328 return session->ok;
329 }
332 bool
333 xen_vbd_get_metrics(xen_session *session, xen_vbd_metrics *result, xen_vbd vbd)
334 {
335 abstract_value param_values[] =
336 {
337 { .type = &abstract_type_string,
338 .u.string_val = vbd }
339 };
341 abstract_type result_type = abstract_type_string;
343 *result = NULL;
344 XEN_CALL_("VBD.get_metrics");
345 return session->ok;
346 }
349 bool
350 xen_vbd_set_device(xen_session *session, xen_vbd vbd, char *device)
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 = device }
358 };
360 xen_call_(session, "VBD.set_device", param_values, 2, NULL, NULL);
361 return session->ok;
362 }
365 bool
366 xen_vbd_set_bootable(xen_session *session, xen_vbd vbd, bool bootable)
367 {
368 abstract_value param_values[] =
369 {
370 { .type = &abstract_type_string,
371 .u.string_val = vbd },
372 { .type = &abstract_type_bool,
373 .u.bool_val = bootable }
374 };
376 xen_call_(session, "VBD.set_bootable", param_values, 2, NULL, NULL);
377 return session->ok;
378 }
381 bool
382 xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode)
383 {
384 abstract_value param_values[] =
385 {
386 { .type = &abstract_type_string,
387 .u.string_val = vbd },
388 { .type = &xen_vbd_mode_abstract_type_,
389 .u.string_val = xen_vbd_mode_to_string(mode) }
390 };
392 xen_call_(session, "VBD.set_mode", param_values, 2, NULL, NULL);
393 return session->ok;
394 }
397 bool
398 xen_vbd_set_type(xen_session *session, xen_vbd vbd, enum xen_vbd_type type)
399 {
400 abstract_value param_values[] =
401 {
402 { .type = &abstract_type_string,
403 .u.string_val = vbd },
404 { .type = &xen_vbd_type_abstract_type_,
405 .u.string_val = xen_vbd_type_to_string(type) }
406 };
408 xen_call_(session, "VBD.set_type", param_values, 2, NULL, NULL);
409 return session->ok;
410 }
413 bool
414 xen_vbd_set_qos_algorithm_type(xen_session *session, xen_vbd vbd, char *algorithm_type)
415 {
416 abstract_value param_values[] =
417 {
418 { .type = &abstract_type_string,
419 .u.string_val = vbd },
420 { .type = &abstract_type_string,
421 .u.string_val = algorithm_type }
422 };
424 xen_call_(session, "VBD.set_qos_algorithm_type", param_values, 2, NULL, NULL);
425 return session->ok;
426 }
429 bool
430 xen_vbd_set_qos_algorithm_params(xen_session *session, xen_vbd vbd, xen_string_string_map *algorithm_params)
431 {
432 abstract_value param_values[] =
433 {
434 { .type = &abstract_type_string,
435 .u.string_val = vbd },
436 { .type = &abstract_type_string_string_map,
437 .u.set_val = (arbitrary_set *)algorithm_params }
438 };
440 xen_call_(session, "VBD.set_qos_algorithm_params", param_values, 2, NULL, NULL);
441 return session->ok;
442 }
445 bool
446 xen_vbd_add_to_qos_algorithm_params(xen_session *session, xen_vbd vbd, char *key, char *value)
447 {
448 abstract_value param_values[] =
449 {
450 { .type = &abstract_type_string,
451 .u.string_val = vbd },
452 { .type = &abstract_type_string,
453 .u.string_val = key },
454 { .type = &abstract_type_string,
455 .u.string_val = value }
456 };
458 xen_call_(session, "VBD.add_to_qos_algorithm_params", param_values, 3, NULL, NULL);
459 return session->ok;
460 }
463 bool
464 xen_vbd_remove_from_qos_algorithm_params(xen_session *session, xen_vbd vbd, char *key)
465 {
466 abstract_value param_values[] =
467 {
468 { .type = &abstract_type_string,
469 .u.string_val = vbd },
470 { .type = &abstract_type_string,
471 .u.string_val = key }
472 };
474 xen_call_(session, "VBD.remove_from_qos_algorithm_params", param_values, 2, NULL, NULL);
475 return session->ok;
476 }
479 bool
480 xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi)
481 {
482 abstract_value param_values[] =
483 {
484 { .type = &abstract_type_string,
485 .u.string_val = vbd },
486 { .type = &abstract_type_string,
487 .u.string_val = vdi }
488 };
490 xen_call_(session, "VBD.media_change", param_values, 2, NULL, NULL);
491 return session->ok;
492 }
495 bool
496 xen_vbd_get_uuid(xen_session *session, char **result, xen_vbd vbd)
497 {
498 *result = session->ok ? xen_strdup_((char *)vbd) : NULL;
499 return session->ok;
500 }