ia64/xen-unstable

view tools/libxen/src/xen_host.c @ 14048:e0e300fda3f0

Remove host.create and host.destroy -- these never made any sense.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Feb 20 22:46:21 2007 +0000 (2007-02-20)
parents c804da44b06c
children 2840b5e7f585
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 = "resident_VMs",
62 .type = &abstract_type_ref_set,
63 .offset = offsetof(xen_host_record, resident_vms) },
64 { .key = "logging",
65 .type = &abstract_type_string_string_map,
66 .offset = offsetof(xen_host_record, logging) },
67 { .key = "PIFs",
68 .type = &abstract_type_ref_set,
69 .offset = offsetof(xen_host_record, pifs) },
70 { .key = "suspend_image_sr",
71 .type = &abstract_type_ref,
72 .offset = offsetof(xen_host_record, suspend_image_sr) },
73 { .key = "crash_dump_sr",
74 .type = &abstract_type_ref,
75 .offset = offsetof(xen_host_record, crash_dump_sr) },
76 { .key = "PBDs",
77 .type = &abstract_type_ref_set,
78 .offset = offsetof(xen_host_record, pbds) },
79 { .key = "host_CPUs",
80 .type = &abstract_type_ref_set,
81 .offset = offsetof(xen_host_record, host_cpus) },
82 { .key = "metrics",
83 .type = &abstract_type_ref,
84 .offset = offsetof(xen_host_record, metrics) }
85 };
87 const abstract_type xen_host_record_abstract_type_ =
88 {
89 .typename = STRUCT,
90 .struct_size = sizeof(xen_host_record),
91 .member_count =
92 sizeof(xen_host_record_struct_members) / sizeof(struct_member),
93 .members = xen_host_record_struct_members
94 };
97 void
98 xen_host_record_free(xen_host_record *record)
99 {
100 if (record == NULL)
101 {
102 return;
103 }
104 free(record->handle);
105 free(record->uuid);
106 free(record->name_label);
107 free(record->name_description);
108 xen_string_string_map_free(record->software_version);
109 xen_string_string_map_free(record->other_config);
110 xen_vm_record_opt_set_free(record->resident_vms);
111 xen_string_string_map_free(record->logging);
112 xen_pif_record_opt_set_free(record->pifs);
113 xen_sr_record_opt_free(record->suspend_image_sr);
114 xen_sr_record_opt_free(record->crash_dump_sr);
115 xen_pbd_record_opt_set_free(record->pbds);
116 xen_host_cpu_record_opt_set_free(record->host_cpus);
117 xen_host_metrics_record_opt_free(record->metrics);
118 free(record);
119 }
122 bool
123 xen_host_get_record(xen_session *session, xen_host_record **result, xen_host host)
124 {
125 abstract_value param_values[] =
126 {
127 { .type = &abstract_type_string,
128 .u.string_val = host }
129 };
131 abstract_type result_type = xen_host_record_abstract_type_;
133 *result = NULL;
134 XEN_CALL_("host.get_record");
136 if (session->ok)
137 {
138 (*result)->handle = xen_strdup_((*result)->uuid);
139 }
141 return session->ok;
142 }
145 bool
146 xen_host_get_by_uuid(xen_session *session, xen_host *result, char *uuid)
147 {
148 abstract_value param_values[] =
149 {
150 { .type = &abstract_type_string,
151 .u.string_val = uuid }
152 };
154 abstract_type result_type = abstract_type_string;
156 *result = NULL;
157 XEN_CALL_("host.get_by_uuid");
158 return session->ok;
159 }
162 bool
163 xen_host_get_by_name_label(xen_session *session, struct xen_host_set **result, char *label)
164 {
165 abstract_value param_values[] =
166 {
167 { .type = &abstract_type_string,
168 .u.string_val = label }
169 };
171 abstract_type result_type = abstract_type_string_set;
173 *result = NULL;
174 XEN_CALL_("host.get_by_name_label");
175 return session->ok;
176 }
179 bool
180 xen_host_get_name_label(xen_session *session, char **result, xen_host host)
181 {
182 abstract_value param_values[] =
183 {
184 { .type = &abstract_type_string,
185 .u.string_val = host }
186 };
188 abstract_type result_type = abstract_type_string;
190 *result = NULL;
191 XEN_CALL_("host.get_name_label");
192 return session->ok;
193 }
196 bool
197 xen_host_get_name_description(xen_session *session, char **result, xen_host host)
198 {
199 abstract_value param_values[] =
200 {
201 { .type = &abstract_type_string,
202 .u.string_val = host }
203 };
205 abstract_type result_type = abstract_type_string;
207 *result = NULL;
208 XEN_CALL_("host.get_name_description");
209 return session->ok;
210 }
213 bool
214 xen_host_get_software_version(xen_session *session, xen_string_string_map **result, xen_host host)
215 {
216 abstract_value param_values[] =
217 {
218 { .type = &abstract_type_string,
219 .u.string_val = host }
220 };
222 abstract_type result_type = abstract_type_string_string_map;
224 *result = NULL;
225 XEN_CALL_("host.get_software_version");
226 return session->ok;
227 }
230 bool
231 xen_host_get_other_config(xen_session *session, xen_string_string_map **result, xen_host host)
232 {
233 abstract_value param_values[] =
234 {
235 { .type = &abstract_type_string,
236 .u.string_val = host }
237 };
239 abstract_type result_type = abstract_type_string_string_map;
241 *result = NULL;
242 XEN_CALL_("host.get_other_config");
243 return session->ok;
244 }
247 bool
248 xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host)
249 {
250 abstract_value param_values[] =
251 {
252 { .type = &abstract_type_string,
253 .u.string_val = host }
254 };
256 abstract_type result_type = abstract_type_string_set;
258 *result = NULL;
259 XEN_CALL_("host.get_resident_VMs");
260 return session->ok;
261 }
264 bool
265 xen_host_get_logging(xen_session *session, xen_string_string_map **result, xen_host host)
266 {
267 abstract_value param_values[] =
268 {
269 { .type = &abstract_type_string,
270 .u.string_val = host }
271 };
273 abstract_type result_type = abstract_type_string_string_map;
275 *result = NULL;
276 XEN_CALL_("host.get_logging");
277 return session->ok;
278 }
281 bool
282 xen_host_get_pifs(xen_session *session, struct xen_pif_set **result, xen_host host)
283 {
284 abstract_value param_values[] =
285 {
286 { .type = &abstract_type_string,
287 .u.string_val = host }
288 };
290 abstract_type result_type = abstract_type_string_set;
292 *result = NULL;
293 XEN_CALL_("host.get_PIFs");
294 return session->ok;
295 }
298 bool
299 xen_host_get_suspend_image_sr(xen_session *session, xen_sr *result, xen_host host)
300 {
301 abstract_value param_values[] =
302 {
303 { .type = &abstract_type_string,
304 .u.string_val = host }
305 };
307 abstract_type result_type = abstract_type_string;
309 *result = NULL;
310 XEN_CALL_("host.get_suspend_image_sr");
311 return session->ok;
312 }
315 bool
316 xen_host_get_crash_dump_sr(xen_session *session, xen_sr *result, xen_host host)
317 {
318 abstract_value param_values[] =
319 {
320 { .type = &abstract_type_string,
321 .u.string_val = host }
322 };
324 abstract_type result_type = abstract_type_string;
326 *result = NULL;
327 XEN_CALL_("host.get_crash_dump_sr");
328 return session->ok;
329 }
332 bool
333 xen_host_get_pbds(xen_session *session, struct xen_pbd_set **result, xen_host host)
334 {
335 abstract_value param_values[] =
336 {
337 { .type = &abstract_type_string,
338 .u.string_val = host }
339 };
341 abstract_type result_type = abstract_type_string_set;
343 *result = NULL;
344 XEN_CALL_("host.get_PBDs");
345 return session->ok;
346 }
349 bool
350 xen_host_get_host_cpus(xen_session *session, struct xen_host_cpu_set **result, xen_host host)
351 {
352 abstract_value param_values[] =
353 {
354 { .type = &abstract_type_string,
355 .u.string_val = host }
356 };
358 abstract_type result_type = abstract_type_string_set;
360 *result = NULL;
361 XEN_CALL_("host.get_host_CPUs");
362 return session->ok;
363 }
366 bool
367 xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host host)
368 {
369 abstract_value param_values[] =
370 {
371 { .type = &abstract_type_string,
372 .u.string_val = host }
373 };
375 abstract_type result_type = abstract_type_string;
377 *result = NULL;
378 XEN_CALL_("host.get_metrics");
379 return session->ok;
380 }
383 bool
384 xen_host_set_name_label(xen_session *session, xen_host host, char *label)
385 {
386 abstract_value param_values[] =
387 {
388 { .type = &abstract_type_string,
389 .u.string_val = host },
390 { .type = &abstract_type_string,
391 .u.string_val = label }
392 };
394 xen_call_(session, "host.set_name_label", param_values, 2, NULL, NULL);
395 return session->ok;
396 }
399 bool
400 xen_host_set_name_description(xen_session *session, xen_host host, char *description)
401 {
402 abstract_value param_values[] =
403 {
404 { .type = &abstract_type_string,
405 .u.string_val = host },
406 { .type = &abstract_type_string,
407 .u.string_val = description }
408 };
410 xen_call_(session, "host.set_name_description", param_values, 2, NULL, NULL);
411 return session->ok;
412 }
415 bool
416 xen_host_set_other_config(xen_session *session, xen_host host, xen_string_string_map *other_config)
417 {
418 abstract_value param_values[] =
419 {
420 { .type = &abstract_type_string,
421 .u.string_val = host },
422 { .type = &abstract_type_string_string_map,
423 .u.set_val = (arbitrary_set *)other_config }
424 };
426 xen_call_(session, "host.set_other_config", param_values, 2, NULL, NULL);
427 return session->ok;
428 }
431 bool
432 xen_host_add_to_other_config(xen_session *session, xen_host host, char *key, char *value)
433 {
434 abstract_value param_values[] =
435 {
436 { .type = &abstract_type_string,
437 .u.string_val = host },
438 { .type = &abstract_type_string,
439 .u.string_val = key },
440 { .type = &abstract_type_string,
441 .u.string_val = value }
442 };
444 xen_call_(session, "host.add_to_other_config", param_values, 3, NULL, NULL);
445 return session->ok;
446 }
449 bool
450 xen_host_remove_from_other_config(xen_session *session, xen_host host, char *key)
451 {
452 abstract_value param_values[] =
453 {
454 { .type = &abstract_type_string,
455 .u.string_val = host },
456 { .type = &abstract_type_string,
457 .u.string_val = key }
458 };
460 xen_call_(session, "host.remove_from_other_config", param_values, 2, NULL, NULL);
461 return session->ok;
462 }
465 bool
466 xen_host_set_logging(xen_session *session, xen_host host, xen_string_string_map *logging)
467 {
468 abstract_value param_values[] =
469 {
470 { .type = &abstract_type_string,
471 .u.string_val = host },
472 { .type = &abstract_type_string_string_map,
473 .u.set_val = (arbitrary_set *)logging }
474 };
476 xen_call_(session, "host.set_logging", param_values, 2, NULL, NULL);
477 return session->ok;
478 }
481 bool
482 xen_host_add_to_logging(xen_session *session, xen_host host, char *key, char *value)
483 {
484 abstract_value param_values[] =
485 {
486 { .type = &abstract_type_string,
487 .u.string_val = host },
488 { .type = &abstract_type_string,
489 .u.string_val = key },
490 { .type = &abstract_type_string,
491 .u.string_val = value }
492 };
494 xen_call_(session, "host.add_to_logging", param_values, 3, NULL, NULL);
495 return session->ok;
496 }
499 bool
500 xen_host_remove_from_logging(xen_session *session, xen_host host, char *key)
501 {
502 abstract_value param_values[] =
503 {
504 { .type = &abstract_type_string,
505 .u.string_val = host },
506 { .type = &abstract_type_string,
507 .u.string_val = key }
508 };
510 xen_call_(session, "host.remove_from_logging", param_values, 2, NULL, NULL);
511 return session->ok;
512 }
515 bool
516 xen_host_set_suspend_image_sr(xen_session *session, xen_host host, xen_sr suspend_image_sr)
517 {
518 abstract_value param_values[] =
519 {
520 { .type = &abstract_type_string,
521 .u.string_val = host },
522 { .type = &abstract_type_string,
523 .u.string_val = suspend_image_sr }
524 };
526 xen_call_(session, "host.set_suspend_image_sr", param_values, 2, NULL, NULL);
527 return session->ok;
528 }
531 bool
532 xen_host_set_crash_dump_sr(xen_session *session, xen_host host, xen_sr crash_dump_sr)
533 {
534 abstract_value param_values[] =
535 {
536 { .type = &abstract_type_string,
537 .u.string_val = host },
538 { .type = &abstract_type_string,
539 .u.string_val = crash_dump_sr }
540 };
542 xen_call_(session, "host.set_crash_dump_sr", param_values, 2, NULL, NULL);
543 return session->ok;
544 }
547 bool
548 xen_host_disable(xen_session *session, xen_host host)
549 {
550 abstract_value param_values[] =
551 {
552 { .type = &abstract_type_string,
553 .u.string_val = host }
554 };
556 xen_call_(session, "host.disable", param_values, 1, NULL, NULL);
557 return session->ok;
558 }
561 bool
562 xen_host_enable(xen_session *session, xen_host host)
563 {
564 abstract_value param_values[] =
565 {
566 { .type = &abstract_type_string,
567 .u.string_val = host }
568 };
570 xen_call_(session, "host.enable", param_values, 1, NULL, NULL);
571 return session->ok;
572 }
575 bool
576 xen_host_shutdown(xen_session *session, xen_host host)
577 {
578 abstract_value param_values[] =
579 {
580 { .type = &abstract_type_string,
581 .u.string_val = host }
582 };
584 xen_call_(session, "host.shutdown", param_values, 1, NULL, NULL);
585 return session->ok;
586 }
589 bool
590 xen_host_reboot(xen_session *session, xen_host host)
591 {
592 abstract_value param_values[] =
593 {
594 { .type = &abstract_type_string,
595 .u.string_val = host }
596 };
598 xen_call_(session, "host.reboot", param_values, 1, NULL, NULL);
599 return session->ok;
600 }
603 bool
604 xen_host_dmesg(xen_session *session, char **result, xen_host host)
605 {
606 abstract_value param_values[] =
607 {
608 { .type = &abstract_type_string,
609 .u.string_val = host }
610 };
612 abstract_type result_type = abstract_type_string;
614 *result = NULL;
615 XEN_CALL_("host.dmesg");
616 return session->ok;
617 }
620 bool
621 xen_host_get_all(xen_session *session, struct xen_host_set **result)
622 {
624 abstract_type result_type = abstract_type_string_set;
626 *result = NULL;
627 xen_call_(session, "host.get_all", NULL, 0, &result_type, result);
628 return session->ok;
629 }
632 bool
633 xen_host_get_uuid(xen_session *session, char **result, xen_host host)
634 {
635 *result = session->ok ? xen_strdup_((char *)host) : NULL;
636 return session->ok;
637 }