ia64/xen-unstable

view tools/libxen/src/xen_host.c @ 14052:2840b5e7f585

Added C bindings for host.supported_bootloaders.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Feb 21 00:04:59 2007 +0000 (2007-02-21)
parents e0e300fda3f0
children f3aa6e34aeb1
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_host.h"
25 #include "xen_host_cpu.h"
26 #include "xen_host_metrics.h"
27 #include "xen_internal.h"
28 #include "xen_pbd.h"
29 #include "xen_pif.h"
30 #include "xen_sr.h"
31 #include "xen_string_string_map.h"
32 #include "xen_vm.h"
35 XEN_FREE(xen_host)
36 XEN_SET_ALLOC_FREE(xen_host)
37 XEN_ALLOC(xen_host_record)
38 XEN_SET_ALLOC_FREE(xen_host_record)
39 XEN_ALLOC(xen_host_record_opt)
40 XEN_RECORD_OPT_FREE(xen_host)
41 XEN_SET_ALLOC_FREE(xen_host_record_opt)
44 static const struct_member xen_host_record_struct_members[] =
45 {
46 { .key = "uuid",
47 .type = &abstract_type_string,
48 .offset = offsetof(xen_host_record, uuid) },
49 { .key = "name_label",
50 .type = &abstract_type_string,
51 .offset = offsetof(xen_host_record, name_label) },
52 { .key = "name_description",
53 .type = &abstract_type_string,
54 .offset = offsetof(xen_host_record, name_description) },
55 { .key = "software_version",
56 .type = &abstract_type_string_string_map,
57 .offset = offsetof(xen_host_record, software_version) },
58 { .key = "other_config",
59 .type = &abstract_type_string_string_map,
60 .offset = offsetof(xen_host_record, other_config) },
61 { .key = "supported_bootloaders",
62 .type = &abstract_type_string_set,
63 .offset = offsetof(xen_host_record, supported_bootloaders) },
64 { .key = "resident_VMs",
65 .type = &abstract_type_ref_set,
66 .offset = offsetof(xen_host_record, resident_vms) },
67 { .key = "logging",
68 .type = &abstract_type_string_string_map,
69 .offset = offsetof(xen_host_record, logging) },
70 { .key = "PIFs",
71 .type = &abstract_type_ref_set,
72 .offset = offsetof(xen_host_record, pifs) },
73 { .key = "suspend_image_sr",
74 .type = &abstract_type_ref,
75 .offset = offsetof(xen_host_record, suspend_image_sr) },
76 { .key = "crash_dump_sr",
77 .type = &abstract_type_ref,
78 .offset = offsetof(xen_host_record, crash_dump_sr) },
79 { .key = "PBDs",
80 .type = &abstract_type_ref_set,
81 .offset = offsetof(xen_host_record, pbds) },
82 { .key = "host_CPUs",
83 .type = &abstract_type_ref_set,
84 .offset = offsetof(xen_host_record, host_cpus) },
85 { .key = "metrics",
86 .type = &abstract_type_ref,
87 .offset = offsetof(xen_host_record, metrics) }
88 };
90 const abstract_type xen_host_record_abstract_type_ =
91 {
92 .typename = STRUCT,
93 .struct_size = sizeof(xen_host_record),
94 .member_count =
95 sizeof(xen_host_record_struct_members) / sizeof(struct_member),
96 .members = xen_host_record_struct_members
97 };
100 void
101 xen_host_record_free(xen_host_record *record)
102 {
103 if (record == NULL)
104 {
105 return;
106 }
107 free(record->handle);
108 free(record->uuid);
109 free(record->name_label);
110 free(record->name_description);
111 xen_string_string_map_free(record->software_version);
112 xen_string_string_map_free(record->other_config);
113 xen_string_set_free(record->supported_bootloaders);
114 xen_vm_record_opt_set_free(record->resident_vms);
115 xen_string_string_map_free(record->logging);
116 xen_pif_record_opt_set_free(record->pifs);
117 xen_sr_record_opt_free(record->suspend_image_sr);
118 xen_sr_record_opt_free(record->crash_dump_sr);
119 xen_pbd_record_opt_set_free(record->pbds);
120 xen_host_cpu_record_opt_set_free(record->host_cpus);
121 xen_host_metrics_record_opt_free(record->metrics);
122 free(record);
123 }
126 bool
127 xen_host_get_record(xen_session *session, xen_host_record **result, xen_host host)
128 {
129 abstract_value param_values[] =
130 {
131 { .type = &abstract_type_string,
132 .u.string_val = host }
133 };
135 abstract_type result_type = xen_host_record_abstract_type_;
137 *result = NULL;
138 XEN_CALL_("host.get_record");
140 if (session->ok)
141 {
142 (*result)->handle = xen_strdup_((*result)->uuid);
143 }
145 return session->ok;
146 }
149 bool
150 xen_host_get_by_uuid(xen_session *session, xen_host *result, char *uuid)
151 {
152 abstract_value param_values[] =
153 {
154 { .type = &abstract_type_string,
155 .u.string_val = uuid }
156 };
158 abstract_type result_type = abstract_type_string;
160 *result = NULL;
161 XEN_CALL_("host.get_by_uuid");
162 return session->ok;
163 }
166 bool
167 xen_host_get_by_name_label(xen_session *session, struct xen_host_set **result, char *label)
168 {
169 abstract_value param_values[] =
170 {
171 { .type = &abstract_type_string,
172 .u.string_val = label }
173 };
175 abstract_type result_type = abstract_type_string_set;
177 *result = NULL;
178 XEN_CALL_("host.get_by_name_label");
179 return session->ok;
180 }
183 bool
184 xen_host_get_name_label(xen_session *session, char **result, xen_host host)
185 {
186 abstract_value param_values[] =
187 {
188 { .type = &abstract_type_string,
189 .u.string_val = host }
190 };
192 abstract_type result_type = abstract_type_string;
194 *result = NULL;
195 XEN_CALL_("host.get_name_label");
196 return session->ok;
197 }
200 bool
201 xen_host_get_name_description(xen_session *session, char **result, xen_host host)
202 {
203 abstract_value param_values[] =
204 {
205 { .type = &abstract_type_string,
206 .u.string_val = host }
207 };
209 abstract_type result_type = abstract_type_string;
211 *result = NULL;
212 XEN_CALL_("host.get_name_description");
213 return session->ok;
214 }
217 bool
218 xen_host_get_software_version(xen_session *session, xen_string_string_map **result, xen_host host)
219 {
220 abstract_value param_values[] =
221 {
222 { .type = &abstract_type_string,
223 .u.string_val = host }
224 };
226 abstract_type result_type = abstract_type_string_string_map;
228 *result = NULL;
229 XEN_CALL_("host.get_software_version");
230 return session->ok;
231 }
234 bool
235 xen_host_get_other_config(xen_session *session, xen_string_string_map **result, xen_host host)
236 {
237 abstract_value param_values[] =
238 {
239 { .type = &abstract_type_string,
240 .u.string_val = host }
241 };
243 abstract_type result_type = abstract_type_string_string_map;
245 *result = NULL;
246 XEN_CALL_("host.get_other_config");
247 return session->ok;
248 }
251 bool
252 xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host)
253 {
254 abstract_value param_values[] =
255 {
256 { .type = &abstract_type_string,
257 .u.string_val = host }
258 };
260 abstract_type result_type = abstract_type_string_set;
262 *result = NULL;
263 XEN_CALL_("host.get_supported_bootloaders");
264 return session->ok;
265 }
268 bool
269 xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host)
270 {
271 abstract_value param_values[] =
272 {
273 { .type = &abstract_type_string,
274 .u.string_val = host }
275 };
277 abstract_type result_type = abstract_type_string_set;
279 *result = NULL;
280 XEN_CALL_("host.get_resident_VMs");
281 return session->ok;
282 }
285 bool
286 xen_host_get_logging(xen_session *session, xen_string_string_map **result, xen_host host)
287 {
288 abstract_value param_values[] =
289 {
290 { .type = &abstract_type_string,
291 .u.string_val = host }
292 };
294 abstract_type result_type = abstract_type_string_string_map;
296 *result = NULL;
297 XEN_CALL_("host.get_logging");
298 return session->ok;
299 }
302 bool
303 xen_host_get_pifs(xen_session *session, struct xen_pif_set **result, xen_host host)
304 {
305 abstract_value param_values[] =
306 {
307 { .type = &abstract_type_string,
308 .u.string_val = host }
309 };
311 abstract_type result_type = abstract_type_string_set;
313 *result = NULL;
314 XEN_CALL_("host.get_PIFs");
315 return session->ok;
316 }
319 bool
320 xen_host_get_suspend_image_sr(xen_session *session, xen_sr *result, xen_host host)
321 {
322 abstract_value param_values[] =
323 {
324 { .type = &abstract_type_string,
325 .u.string_val = host }
326 };
328 abstract_type result_type = abstract_type_string;
330 *result = NULL;
331 XEN_CALL_("host.get_suspend_image_sr");
332 return session->ok;
333 }
336 bool
337 xen_host_get_crash_dump_sr(xen_session *session, xen_sr *result, xen_host host)
338 {
339 abstract_value param_values[] =
340 {
341 { .type = &abstract_type_string,
342 .u.string_val = host }
343 };
345 abstract_type result_type = abstract_type_string;
347 *result = NULL;
348 XEN_CALL_("host.get_crash_dump_sr");
349 return session->ok;
350 }
353 bool
354 xen_host_get_pbds(xen_session *session, struct xen_pbd_set **result, xen_host host)
355 {
356 abstract_value param_values[] =
357 {
358 { .type = &abstract_type_string,
359 .u.string_val = host }
360 };
362 abstract_type result_type = abstract_type_string_set;
364 *result = NULL;
365 XEN_CALL_("host.get_PBDs");
366 return session->ok;
367 }
370 bool
371 xen_host_get_host_cpus(xen_session *session, struct xen_host_cpu_set **result, xen_host host)
372 {
373 abstract_value param_values[] =
374 {
375 { .type = &abstract_type_string,
376 .u.string_val = host }
377 };
379 abstract_type result_type = abstract_type_string_set;
381 *result = NULL;
382 XEN_CALL_("host.get_host_CPUs");
383 return session->ok;
384 }
387 bool
388 xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host host)
389 {
390 abstract_value param_values[] =
391 {
392 { .type = &abstract_type_string,
393 .u.string_val = host }
394 };
396 abstract_type result_type = abstract_type_string;
398 *result = NULL;
399 XEN_CALL_("host.get_metrics");
400 return session->ok;
401 }
404 bool
405 xen_host_set_name_label(xen_session *session, xen_host host, char *label)
406 {
407 abstract_value param_values[] =
408 {
409 { .type = &abstract_type_string,
410 .u.string_val = host },
411 { .type = &abstract_type_string,
412 .u.string_val = label }
413 };
415 xen_call_(session, "host.set_name_label", param_values, 2, NULL, NULL);
416 return session->ok;
417 }
420 bool
421 xen_host_set_name_description(xen_session *session, xen_host host, char *description)
422 {
423 abstract_value param_values[] =
424 {
425 { .type = &abstract_type_string,
426 .u.string_val = host },
427 { .type = &abstract_type_string,
428 .u.string_val = description }
429 };
431 xen_call_(session, "host.set_name_description", param_values, 2, NULL, NULL);
432 return session->ok;
433 }
436 bool
437 xen_host_set_other_config(xen_session *session, xen_host host, xen_string_string_map *other_config)
438 {
439 abstract_value param_values[] =
440 {
441 { .type = &abstract_type_string,
442 .u.string_val = host },
443 { .type = &abstract_type_string_string_map,
444 .u.set_val = (arbitrary_set *)other_config }
445 };
447 xen_call_(session, "host.set_other_config", param_values, 2, NULL, NULL);
448 return session->ok;
449 }
452 bool
453 xen_host_add_to_other_config(xen_session *session, xen_host host, char *key, char *value)
454 {
455 abstract_value param_values[] =
456 {
457 { .type = &abstract_type_string,
458 .u.string_val = host },
459 { .type = &abstract_type_string,
460 .u.string_val = key },
461 { .type = &abstract_type_string,
462 .u.string_val = value }
463 };
465 xen_call_(session, "host.add_to_other_config", param_values, 3, NULL, NULL);
466 return session->ok;
467 }
470 bool
471 xen_host_remove_from_other_config(xen_session *session, xen_host host, char *key)
472 {
473 abstract_value param_values[] =
474 {
475 { .type = &abstract_type_string,
476 .u.string_val = host },
477 { .type = &abstract_type_string,
478 .u.string_val = key }
479 };
481 xen_call_(session, "host.remove_from_other_config", param_values, 2, NULL, NULL);
482 return session->ok;
483 }
486 bool
487 xen_host_set_logging(xen_session *session, xen_host host, xen_string_string_map *logging)
488 {
489 abstract_value param_values[] =
490 {
491 { .type = &abstract_type_string,
492 .u.string_val = host },
493 { .type = &abstract_type_string_string_map,
494 .u.set_val = (arbitrary_set *)logging }
495 };
497 xen_call_(session, "host.set_logging", param_values, 2, NULL, NULL);
498 return session->ok;
499 }
502 bool
503 xen_host_add_to_logging(xen_session *session, xen_host host, char *key, char *value)
504 {
505 abstract_value param_values[] =
506 {
507 { .type = &abstract_type_string,
508 .u.string_val = host },
509 { .type = &abstract_type_string,
510 .u.string_val = key },
511 { .type = &abstract_type_string,
512 .u.string_val = value }
513 };
515 xen_call_(session, "host.add_to_logging", param_values, 3, NULL, NULL);
516 return session->ok;
517 }
520 bool
521 xen_host_remove_from_logging(xen_session *session, xen_host host, char *key)
522 {
523 abstract_value param_values[] =
524 {
525 { .type = &abstract_type_string,
526 .u.string_val = host },
527 { .type = &abstract_type_string,
528 .u.string_val = key }
529 };
531 xen_call_(session, "host.remove_from_logging", param_values, 2, NULL, NULL);
532 return session->ok;
533 }
536 bool
537 xen_host_set_suspend_image_sr(xen_session *session, xen_host host, xen_sr suspend_image_sr)
538 {
539 abstract_value param_values[] =
540 {
541 { .type = &abstract_type_string,
542 .u.string_val = host },
543 { .type = &abstract_type_string,
544 .u.string_val = suspend_image_sr }
545 };
547 xen_call_(session, "host.set_suspend_image_sr", param_values, 2, NULL, NULL);
548 return session->ok;
549 }
552 bool
553 xen_host_set_crash_dump_sr(xen_session *session, xen_host host, xen_sr crash_dump_sr)
554 {
555 abstract_value param_values[] =
556 {
557 { .type = &abstract_type_string,
558 .u.string_val = host },
559 { .type = &abstract_type_string,
560 .u.string_val = crash_dump_sr }
561 };
563 xen_call_(session, "host.set_crash_dump_sr", param_values, 2, NULL, NULL);
564 return session->ok;
565 }
568 bool
569 xen_host_disable(xen_session *session, xen_host host)
570 {
571 abstract_value param_values[] =
572 {
573 { .type = &abstract_type_string,
574 .u.string_val = host }
575 };
577 xen_call_(session, "host.disable", param_values, 1, NULL, NULL);
578 return session->ok;
579 }
582 bool
583 xen_host_enable(xen_session *session, xen_host host)
584 {
585 abstract_value param_values[] =
586 {
587 { .type = &abstract_type_string,
588 .u.string_val = host }
589 };
591 xen_call_(session, "host.enable", param_values, 1, NULL, NULL);
592 return session->ok;
593 }
596 bool
597 xen_host_shutdown(xen_session *session, xen_host host)
598 {
599 abstract_value param_values[] =
600 {
601 { .type = &abstract_type_string,
602 .u.string_val = host }
603 };
605 xen_call_(session, "host.shutdown", param_values, 1, NULL, NULL);
606 return session->ok;
607 }
610 bool
611 xen_host_reboot(xen_session *session, xen_host host)
612 {
613 abstract_value param_values[] =
614 {
615 { .type = &abstract_type_string,
616 .u.string_val = host }
617 };
619 xen_call_(session, "host.reboot", param_values, 1, NULL, NULL);
620 return session->ok;
621 }
624 bool
625 xen_host_dmesg(xen_session *session, char **result, xen_host host)
626 {
627 abstract_value param_values[] =
628 {
629 { .type = &abstract_type_string,
630 .u.string_val = host }
631 };
633 abstract_type result_type = abstract_type_string;
635 *result = NULL;
636 XEN_CALL_("host.dmesg");
637 return session->ok;
638 }
641 bool
642 xen_host_get_all(xen_session *session, struct xen_host_set **result)
643 {
645 abstract_type result_type = abstract_type_string_set;
647 *result = NULL;
648 xen_call_(session, "host.get_all", NULL, 0, &result_type, result);
649 return session->ok;
650 }
653 bool
654 xen_host_get_uuid(xen_session *session, char **result, xen_host host)
655 {
656 *result = session->ok ? xen_strdup_((char *)host) : NULL;
657 return session->ok;
658 }