debuggers.hg

view tools/libxen/src/xen_host.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
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_internal.h"
24 #include <xen/api/xen_common.h>
25 #include <xen/api/xen_host.h>
26 #include <xen/api/xen_host_cpu.h>
27 #include <xen/api/xen_host_metrics.h>
28 #include <xen/api/xen_pbd.h>
29 #include <xen/api/xen_pif.h>
30 #include <xen/api/xen_sr.h>
31 #include <xen/api/xen_string_string_map.h>
32 #include <xen/api/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 = "API_version_major",
56 .type = &abstract_type_int,
57 .offset = offsetof(xen_host_record, api_version_major) },
58 { .key = "API_version_minor",
59 .type = &abstract_type_int,
60 .offset = offsetof(xen_host_record, api_version_minor) },
61 { .key = "API_version_vendor",
62 .type = &abstract_type_string,
63 .offset = offsetof(xen_host_record, api_version_vendor) },
64 { .key = "API_version_vendor_implementation",
65 .type = &abstract_type_string_string_map,
66 .offset = offsetof(xen_host_record, api_version_vendor_implementation) },
67 { .key = "enabled",
68 .type = &abstract_type_bool,
69 .offset = offsetof(xen_host_record, enabled) },
70 { .key = "software_version",
71 .type = &abstract_type_string_string_map,
72 .offset = offsetof(xen_host_record, software_version) },
73 { .key = "other_config",
74 .type = &abstract_type_string_string_map,
75 .offset = offsetof(xen_host_record, other_config) },
76 { .key = "capabilities",
77 .type = &abstract_type_string_set,
78 .offset = offsetof(xen_host_record, capabilities) },
79 { .key = "cpu_configuration",
80 .type = &abstract_type_string_string_map,
81 .offset = offsetof(xen_host_record, cpu_configuration) },
82 { .key = "sched_policy",
83 .type = &abstract_type_string,
84 .offset = offsetof(xen_host_record, sched_policy) },
85 { .key = "supported_bootloaders",
86 .type = &abstract_type_string_set,
87 .offset = offsetof(xen_host_record, supported_bootloaders) },
88 { .key = "resident_VMs",
89 .type = &abstract_type_ref_set,
90 .offset = offsetof(xen_host_record, resident_vms) },
91 { .key = "logging",
92 .type = &abstract_type_string_string_map,
93 .offset = offsetof(xen_host_record, logging) },
94 { .key = "PIFs",
95 .type = &abstract_type_ref_set,
96 .offset = offsetof(xen_host_record, pifs) },
97 { .key = "suspend_image_sr",
98 .type = &abstract_type_ref,
99 .offset = offsetof(xen_host_record, suspend_image_sr) },
100 { .key = "crash_dump_sr",
101 .type = &abstract_type_ref,
102 .offset = offsetof(xen_host_record, crash_dump_sr) },
103 { .key = "PBDs",
104 .type = &abstract_type_ref_set,
105 .offset = offsetof(xen_host_record, pbds) },
106 { .key = "host_CPUs",
107 .type = &abstract_type_ref_set,
108 .offset = offsetof(xen_host_record, host_cpus) },
109 { .key = "metrics",
110 .type = &abstract_type_ref,
111 .offset = offsetof(xen_host_record, metrics) }
112 };
114 const abstract_type xen_host_record_abstract_type_ =
115 {
116 .typename = STRUCT,
117 .struct_size = sizeof(xen_host_record),
118 .member_count =
119 sizeof(xen_host_record_struct_members) / sizeof(struct_member),
120 .members = xen_host_record_struct_members
121 };
124 void
125 xen_host_record_free(xen_host_record *record)
126 {
127 if (record == NULL)
128 {
129 return;
130 }
131 free(record->handle);
132 free(record->uuid);
133 free(record->name_label);
134 free(record->name_description);
135 free(record->api_version_vendor);
136 xen_string_string_map_free(record->api_version_vendor_implementation);
137 xen_string_string_map_free(record->software_version);
138 xen_string_string_map_free(record->other_config);
139 xen_string_set_free(record->capabilities);
140 xen_string_string_map_free(record->cpu_configuration);
141 free(record->sched_policy);
142 xen_string_set_free(record->supported_bootloaders);
143 xen_vm_record_opt_set_free(record->resident_vms);
144 xen_string_string_map_free(record->logging);
145 xen_pif_record_opt_set_free(record->pifs);
146 xen_sr_record_opt_free(record->suspend_image_sr);
147 xen_sr_record_opt_free(record->crash_dump_sr);
148 xen_pbd_record_opt_set_free(record->pbds);
149 xen_host_cpu_record_opt_set_free(record->host_cpus);
150 xen_host_metrics_record_opt_free(record->metrics);
151 free(record);
152 }
155 bool
156 xen_host_get_record(xen_session *session, xen_host_record **result, xen_host host)
157 {
158 abstract_value param_values[] =
159 {
160 { .type = &abstract_type_string,
161 .u.string_val = host }
162 };
164 abstract_type result_type = xen_host_record_abstract_type_;
166 *result = NULL;
167 XEN_CALL_("host.get_record");
169 if (session->ok)
170 {
171 (*result)->handle = xen_strdup_((*result)->uuid);
172 }
174 return session->ok;
175 }
178 bool
179 xen_host_get_by_uuid(xen_session *session, xen_host *result, char *uuid)
180 {
181 abstract_value param_values[] =
182 {
183 { .type = &abstract_type_string,
184 .u.string_val = uuid }
185 };
187 abstract_type result_type = abstract_type_string;
189 *result = NULL;
190 XEN_CALL_("host.get_by_uuid");
191 return session->ok;
192 }
195 bool
196 xen_host_get_by_name_label(xen_session *session, struct xen_host_set **result, char *label)
197 {
198 abstract_value param_values[] =
199 {
200 { .type = &abstract_type_string,
201 .u.string_val = label }
202 };
204 abstract_type result_type = abstract_type_string_set;
206 *result = NULL;
207 XEN_CALL_("host.get_by_name_label");
208 return session->ok;
209 }
212 bool
213 xen_host_get_name_label(xen_session *session, char **result, xen_host host)
214 {
215 abstract_value param_values[] =
216 {
217 { .type = &abstract_type_string,
218 .u.string_val = host }
219 };
221 abstract_type result_type = abstract_type_string;
223 *result = NULL;
224 XEN_CALL_("host.get_name_label");
225 return session->ok;
226 }
229 bool
230 xen_host_get_name_description(xen_session *session, char **result, xen_host host)
231 {
232 abstract_value param_values[] =
233 {
234 { .type = &abstract_type_string,
235 .u.string_val = host }
236 };
238 abstract_type result_type = abstract_type_string;
240 *result = NULL;
241 XEN_CALL_("host.get_name_description");
242 return session->ok;
243 }
246 bool
247 xen_host_get_api_version_major(xen_session *session, int64_t *result, xen_host host)
248 {
249 abstract_value param_values[] =
250 {
251 { .type = &abstract_type_string,
252 .u.string_val = host }
253 };
255 abstract_type result_type = abstract_type_int;
257 XEN_CALL_("host.get_API_version_major");
258 return session->ok;
259 }
262 bool
263 xen_host_get_api_version_minor(xen_session *session, int64_t *result, xen_host host)
264 {
265 abstract_value param_values[] =
266 {
267 { .type = &abstract_type_string,
268 .u.string_val = host }
269 };
271 abstract_type result_type = abstract_type_int;
273 XEN_CALL_("host.get_API_version_minor");
274 return session->ok;
275 }
278 bool
279 xen_host_get_api_version_vendor(xen_session *session, char **result, xen_host host)
280 {
281 abstract_value param_values[] =
282 {
283 { .type = &abstract_type_string,
284 .u.string_val = host }
285 };
287 abstract_type result_type = abstract_type_string;
289 *result = NULL;
290 XEN_CALL_("host.get_API_version_vendor");
291 return session->ok;
292 }
295 bool
296 xen_host_get_api_version_vendor_implementation(xen_session *session, xen_string_string_map **result, xen_host host)
297 {
298 abstract_value param_values[] =
299 {
300 { .type = &abstract_type_string,
301 .u.string_val = host }
302 };
304 abstract_type result_type = abstract_type_string_string_map;
306 *result = NULL;
307 XEN_CALL_("host.get_API_version_vendor_implementation");
308 return session->ok;
309 }
312 bool
313 xen_host_get_enabled(xen_session *session, bool *result, xen_host host)
314 {
315 abstract_value param_values[] =
316 {
317 { .type = &abstract_type_string,
318 .u.string_val = host }
319 };
321 abstract_type result_type = abstract_type_bool;
323 XEN_CALL_("host.get_enabled");
324 return session->ok;
325 }
328 bool
329 xen_host_get_software_version(xen_session *session, xen_string_string_map **result, xen_host host)
330 {
331 abstract_value param_values[] =
332 {
333 { .type = &abstract_type_string,
334 .u.string_val = host }
335 };
337 abstract_type result_type = abstract_type_string_string_map;
339 *result = NULL;
340 XEN_CALL_("host.get_software_version");
341 return session->ok;
342 }
345 bool
346 xen_host_get_other_config(xen_session *session, xen_string_string_map **result, xen_host host)
347 {
348 abstract_value param_values[] =
349 {
350 { .type = &abstract_type_string,
351 .u.string_val = host }
352 };
354 abstract_type result_type = abstract_type_string_string_map;
356 *result = NULL;
357 XEN_CALL_("host.get_other_config");
358 return session->ok;
359 }
362 bool
363 xen_host_get_capabilities(xen_session *session, struct xen_string_set **result, xen_host host)
364 {
365 abstract_value param_values[] =
366 {
367 { .type = &abstract_type_string,
368 .u.string_val = host }
369 };
371 abstract_type result_type = abstract_type_string_set;
373 *result = NULL;
374 XEN_CALL_("host.get_capabilities");
375 return session->ok;
376 }
379 bool
380 xen_host_get_cpu_configuration(xen_session *session, xen_string_string_map **result, xen_host host)
381 {
382 abstract_value param_values[] =
383 {
384 { .type = &abstract_type_string,
385 .u.string_val = host }
386 };
388 abstract_type result_type = abstract_type_string_string_map;
390 *result = NULL;
391 XEN_CALL_("host.get_cpu_configuration");
392 return session->ok;
393 }
396 bool
397 xen_host_get_sched_policy(xen_session *session, char **result, xen_host host)
398 {
399 abstract_value param_values[] =
400 {
401 { .type = &abstract_type_string,
402 .u.string_val = host }
403 };
405 abstract_type result_type = abstract_type_string;
407 *result = NULL;
408 XEN_CALL_("host.get_sched_policy");
409 return session->ok;
410 }
413 bool
414 xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host)
415 {
416 abstract_value param_values[] =
417 {
418 { .type = &abstract_type_string,
419 .u.string_val = host }
420 };
422 abstract_type result_type = abstract_type_string_set;
424 *result = NULL;
425 XEN_CALL_("host.get_supported_bootloaders");
426 return session->ok;
427 }
430 bool
431 xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host)
432 {
433 abstract_value param_values[] =
434 {
435 { .type = &abstract_type_string,
436 .u.string_val = host }
437 };
439 abstract_type result_type = abstract_type_string_set;
441 *result = NULL;
442 XEN_CALL_("host.get_resident_VMs");
443 return session->ok;
444 }
447 bool
448 xen_host_get_logging(xen_session *session, xen_string_string_map **result, xen_host host)
449 {
450 abstract_value param_values[] =
451 {
452 { .type = &abstract_type_string,
453 .u.string_val = host }
454 };
456 abstract_type result_type = abstract_type_string_string_map;
458 *result = NULL;
459 XEN_CALL_("host.get_logging");
460 return session->ok;
461 }
464 bool
465 xen_host_get_pifs(xen_session *session, struct xen_pif_set **result, xen_host host)
466 {
467 abstract_value param_values[] =
468 {
469 { .type = &abstract_type_string,
470 .u.string_val = host }
471 };
473 abstract_type result_type = abstract_type_string_set;
475 *result = NULL;
476 XEN_CALL_("host.get_PIFs");
477 return session->ok;
478 }
481 bool
482 xen_host_get_suspend_image_sr(xen_session *session, xen_sr *result, xen_host host)
483 {
484 abstract_value param_values[] =
485 {
486 { .type = &abstract_type_string,
487 .u.string_val = host }
488 };
490 abstract_type result_type = abstract_type_string;
492 *result = NULL;
493 XEN_CALL_("host.get_suspend_image_sr");
494 return session->ok;
495 }
498 bool
499 xen_host_get_crash_dump_sr(xen_session *session, xen_sr *result, xen_host host)
500 {
501 abstract_value param_values[] =
502 {
503 { .type = &abstract_type_string,
504 .u.string_val = host }
505 };
507 abstract_type result_type = abstract_type_string;
509 *result = NULL;
510 XEN_CALL_("host.get_crash_dump_sr");
511 return session->ok;
512 }
515 bool
516 xen_host_get_pbds(xen_session *session, struct xen_pbd_set **result, xen_host host)
517 {
518 abstract_value param_values[] =
519 {
520 { .type = &abstract_type_string,
521 .u.string_val = host }
522 };
524 abstract_type result_type = abstract_type_string_set;
526 *result = NULL;
527 XEN_CALL_("host.get_PBDs");
528 return session->ok;
529 }
532 bool
533 xen_host_get_host_cpus(xen_session *session, struct xen_host_cpu_set **result, xen_host host)
534 {
535 abstract_value param_values[] =
536 {
537 { .type = &abstract_type_string,
538 .u.string_val = host }
539 };
541 abstract_type result_type = abstract_type_string_set;
543 *result = NULL;
544 XEN_CALL_("host.get_host_CPUs");
545 return session->ok;
546 }
549 bool
550 xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host host)
551 {
552 abstract_value param_values[] =
553 {
554 { .type = &abstract_type_string,
555 .u.string_val = host }
556 };
558 abstract_type result_type = abstract_type_string;
560 *result = NULL;
561 XEN_CALL_("host.get_metrics");
562 return session->ok;
563 }
566 bool
567 xen_host_set_name_label(xen_session *session, xen_host host, char *label)
568 {
569 abstract_value param_values[] =
570 {
571 { .type = &abstract_type_string,
572 .u.string_val = host },
573 { .type = &abstract_type_string,
574 .u.string_val = label }
575 };
577 xen_call_(session, "host.set_name_label", param_values, 2, NULL, NULL);
578 return session->ok;
579 }
582 bool
583 xen_host_set_name_description(xen_session *session, xen_host host, char *description)
584 {
585 abstract_value param_values[] =
586 {
587 { .type = &abstract_type_string,
588 .u.string_val = host },
589 { .type = &abstract_type_string,
590 .u.string_val = description }
591 };
593 xen_call_(session, "host.set_name_description", param_values, 2, NULL, NULL);
594 return session->ok;
595 }
598 bool
599 xen_host_set_other_config(xen_session *session, xen_host host, xen_string_string_map *other_config)
600 {
601 abstract_value param_values[] =
602 {
603 { .type = &abstract_type_string,
604 .u.string_val = host },
605 { .type = &abstract_type_string_string_map,
606 .u.set_val = (arbitrary_set *)other_config }
607 };
609 xen_call_(session, "host.set_other_config", param_values, 2, NULL, NULL);
610 return session->ok;
611 }
614 bool
615 xen_host_add_to_other_config(xen_session *session, xen_host host, char *key, char *value)
616 {
617 abstract_value param_values[] =
618 {
619 { .type = &abstract_type_string,
620 .u.string_val = host },
621 { .type = &abstract_type_string,
622 .u.string_val = key },
623 { .type = &abstract_type_string,
624 .u.string_val = value }
625 };
627 xen_call_(session, "host.add_to_other_config", param_values, 3, NULL, NULL);
628 return session->ok;
629 }
632 bool
633 xen_host_remove_from_other_config(xen_session *session, xen_host host, char *key)
634 {
635 abstract_value param_values[] =
636 {
637 { .type = &abstract_type_string,
638 .u.string_val = host },
639 { .type = &abstract_type_string,
640 .u.string_val = key }
641 };
643 xen_call_(session, "host.remove_from_other_config", param_values, 2, NULL, NULL);
644 return session->ok;
645 }
648 bool
649 xen_host_set_logging(xen_session *session, xen_host host, xen_string_string_map *logging)
650 {
651 abstract_value param_values[] =
652 {
653 { .type = &abstract_type_string,
654 .u.string_val = host },
655 { .type = &abstract_type_string_string_map,
656 .u.set_val = (arbitrary_set *)logging }
657 };
659 xen_call_(session, "host.set_logging", param_values, 2, NULL, NULL);
660 return session->ok;
661 }
664 bool
665 xen_host_add_to_logging(xen_session *session, xen_host host, char *key, char *value)
666 {
667 abstract_value param_values[] =
668 {
669 { .type = &abstract_type_string,
670 .u.string_val = host },
671 { .type = &abstract_type_string,
672 .u.string_val = key },
673 { .type = &abstract_type_string,
674 .u.string_val = value }
675 };
677 xen_call_(session, "host.add_to_logging", param_values, 3, NULL, NULL);
678 return session->ok;
679 }
682 bool
683 xen_host_remove_from_logging(xen_session *session, xen_host host, char *key)
684 {
685 abstract_value param_values[] =
686 {
687 { .type = &abstract_type_string,
688 .u.string_val = host },
689 { .type = &abstract_type_string,
690 .u.string_val = key }
691 };
693 xen_call_(session, "host.remove_from_logging", param_values, 2, NULL, NULL);
694 return session->ok;
695 }
698 bool
699 xen_host_set_suspend_image_sr(xen_session *session, xen_host host, xen_sr suspend_image_sr)
700 {
701 abstract_value param_values[] =
702 {
703 { .type = &abstract_type_string,
704 .u.string_val = host },
705 { .type = &abstract_type_string,
706 .u.string_val = suspend_image_sr }
707 };
709 xen_call_(session, "host.set_suspend_image_sr", param_values, 2, NULL, NULL);
710 return session->ok;
711 }
714 bool
715 xen_host_set_crash_dump_sr(xen_session *session, xen_host host, xen_sr crash_dump_sr)
716 {
717 abstract_value param_values[] =
718 {
719 { .type = &abstract_type_string,
720 .u.string_val = host },
721 { .type = &abstract_type_string,
722 .u.string_val = crash_dump_sr }
723 };
725 xen_call_(session, "host.set_crash_dump_sr", param_values, 2, NULL, NULL);
726 return session->ok;
727 }
730 bool
731 xen_host_disable(xen_session *session, xen_host host)
732 {
733 abstract_value param_values[] =
734 {
735 { .type = &abstract_type_string,
736 .u.string_val = host }
737 };
739 xen_call_(session, "host.disable", param_values, 1, NULL, NULL);
740 return session->ok;
741 }
744 bool
745 xen_host_enable(xen_session *session, xen_host host)
746 {
747 abstract_value param_values[] =
748 {
749 { .type = &abstract_type_string,
750 .u.string_val = host }
751 };
753 xen_call_(session, "host.enable", param_values, 1, NULL, NULL);
754 return session->ok;
755 }
758 bool
759 xen_host_shutdown(xen_session *session, xen_host host)
760 {
761 abstract_value param_values[] =
762 {
763 { .type = &abstract_type_string,
764 .u.string_val = host }
765 };
767 xen_call_(session, "host.shutdown", param_values, 1, NULL, NULL);
768 return session->ok;
769 }
772 bool
773 xen_host_reboot(xen_session *session, xen_host host)
774 {
775 abstract_value param_values[] =
776 {
777 { .type = &abstract_type_string,
778 .u.string_val = host }
779 };
781 xen_call_(session, "host.reboot", param_values, 1, NULL, NULL);
782 return session->ok;
783 }
786 bool
787 xen_host_dmesg(xen_session *session, char **result, xen_host host)
788 {
789 abstract_value param_values[] =
790 {
791 { .type = &abstract_type_string,
792 .u.string_val = host }
793 };
795 abstract_type result_type = abstract_type_string;
797 *result = NULL;
798 XEN_CALL_("host.dmesg");
799 return session->ok;
800 }
803 bool
804 xen_host_dmesg_clear(xen_session *session, char **result, xen_host host)
805 {
806 abstract_value param_values[] =
807 {
808 { .type = &abstract_type_string,
809 .u.string_val = host }
810 };
812 abstract_type result_type = abstract_type_string;
814 *result = NULL;
815 XEN_CALL_("host.dmesg_clear");
816 return session->ok;
817 }
820 bool
821 xen_host_get_log(xen_session *session, char **result, xen_host host)
822 {
823 abstract_value param_values[] =
824 {
825 { .type = &abstract_type_string,
826 .u.string_val = host }
827 };
829 abstract_type result_type = abstract_type_string;
831 *result = NULL;
832 XEN_CALL_("host.get_log");
833 return session->ok;
834 }
837 bool
838 xen_host_send_debug_keys(xen_session *session, xen_host host, char *keys)
839 {
840 abstract_value param_values[] =
841 {
842 { .type = &abstract_type_string,
843 .u.string_val = host },
844 { .type = &abstract_type_string,
845 .u.string_val = keys }
846 };
848 xen_call_(session, "host.send_debug_keys", param_values, 2, NULL, NULL);
849 return session->ok;
850 }
853 bool
854 xen_host_list_methods(xen_session *session, struct xen_string_set **result)
855 {
857 abstract_type result_type = abstract_type_string_set;
859 *result = NULL;
860 xen_call_(session, "host.list_methods", NULL, 0, &result_type, result);
861 return session->ok;
862 }
865 bool
866 xen_host_get_all(xen_session *session, struct xen_host_set **result)
867 {
869 abstract_type result_type = abstract_type_string_set;
871 *result = NULL;
872 xen_call_(session, "host.get_all", NULL, 0, &result_type, result);
873 return session->ok;
874 }
877 bool
878 xen_host_get_uuid(xen_session *session, char **result, xen_host host)
879 {
880 abstract_value param_values[] =
881 {
882 { .type = &abstract_type_string,
883 .u.string_val = host }
884 };
886 abstract_type result_type = abstract_type_string;
888 *result = NULL;
889 XEN_CALL_("host.get_uuid");
890 return session->ok;
891 }