ia64/xen-unstable
changeset 14052:2840b5e7f585
Added C bindings for host.supported_bootloaders.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
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 | 2414007d92ba |
children | bca284f67702 |
files | tools/libxen/include/xen_host.h tools/libxen/include/xen_string_set.h tools/libxen/src/xen_host.c tools/libxen/src/xen_string_set.c tools/libxen/src/xen_string_set.h tools/libxen/test/test_bindings.c |
line diff
1.1 --- a/tools/libxen/include/xen_host.h Wed Feb 21 00:04:06 2007 +0000 1.2 +++ b/tools/libxen/include/xen_host.h Wed Feb 21 00:04:59 2007 +0000 1.3 @@ -26,6 +26,7 @@ 1.4 #include "xen_pbd_decl.h" 1.5 #include "xen_pif_decl.h" 1.6 #include "xen_sr_decl.h" 1.7 +#include "xen_string_set.h" 1.8 #include "xen_string_string_map.h" 1.9 #include "xen_vm_decl.h" 1.10 1.11 @@ -73,6 +74,7 @@ typedef struct xen_host_record 1.12 char *name_description; 1.13 xen_string_string_map *software_version; 1.14 xen_string_string_map *other_config; 1.15 + struct xen_string_set *supported_bootloaders; 1.16 struct xen_vm_record_opt_set *resident_vms; 1.17 xen_string_string_map *logging; 1.18 struct xen_pif_record_opt_set *pifs; 1.19 @@ -219,6 +221,13 @@ xen_host_get_other_config(xen_session *s 1.20 1.21 1.22 /** 1.23 + * Get the supported_bootloaders field of the given host. 1.24 + */ 1.25 +extern bool 1.26 +xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host); 1.27 + 1.28 + 1.29 +/** 1.30 * Get the resident_VMs field of the given host. 1.31 */ 1.32 extern bool
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tools/libxen/include/xen_string_set.h Wed Feb 21 00:04:59 2007 +0000 2.3 @@ -0,0 +1,47 @@ 2.4 +/* 2.5 + * Copyright (c) 2006-2007, XenSource Inc. 2.6 + * 2.7 + * This library is free software; you can redistribute it and/or 2.8 + * modify it under the terms of the GNU Lesser General Public 2.9 + * License as published by the Free Software Foundation; either 2.10 + * version 2.1 of the License, or (at your option) any later version. 2.11 + * 2.12 + * This library is distributed in the hope that it will be useful, 2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 2.15 + * Lesser General Public License for more details. 2.16 + * 2.17 + * You should have received a copy of the GNU Lesser General Public 2.18 + * License along with this library; if not, write to the Free Software 2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2.20 + */ 2.21 + 2.22 +#ifndef XEN_STRING_SET_H 2.23 +#define XEN_STRING_SET_H 2.24 + 2.25 + 2.26 +#include "xen_common.h" 2.27 + 2.28 + 2.29 +typedef struct xen_string_set 2.30 +{ 2.31 + size_t size; 2.32 + char *contents[]; 2.33 +} xen_string_set; 2.34 + 2.35 + 2.36 +/** 2.37 + * Allocate a xen_string_set of the given size. 2.38 + */ 2.39 +extern xen_string_set * 2.40 +xen_string_set_alloc(size_t size); 2.41 + 2.42 +/** 2.43 + * Free the given xen_string_set. The given set must have been allocated 2.44 + * by this library. 2.45 + */ 2.46 +extern void 2.47 +xen_string_set_free(xen_string_set *set); 2.48 + 2.49 + 2.50 +#endif
3.1 --- a/tools/libxen/src/xen_host.c Wed Feb 21 00:04:06 2007 +0000 3.2 +++ b/tools/libxen/src/xen_host.c Wed Feb 21 00:04:59 2007 +0000 3.3 @@ -58,6 +58,9 @@ static const struct_member xen_host_reco 3.4 { .key = "other_config", 3.5 .type = &abstract_type_string_string_map, 3.6 .offset = offsetof(xen_host_record, other_config) }, 3.7 + { .key = "supported_bootloaders", 3.8 + .type = &abstract_type_string_set, 3.9 + .offset = offsetof(xen_host_record, supported_bootloaders) }, 3.10 { .key = "resident_VMs", 3.11 .type = &abstract_type_ref_set, 3.12 .offset = offsetof(xen_host_record, resident_vms) }, 3.13 @@ -107,6 +110,7 @@ xen_host_record_free(xen_host_record *re 3.14 free(record->name_description); 3.15 xen_string_string_map_free(record->software_version); 3.16 xen_string_string_map_free(record->other_config); 3.17 + xen_string_set_free(record->supported_bootloaders); 3.18 xen_vm_record_opt_set_free(record->resident_vms); 3.19 xen_string_string_map_free(record->logging); 3.20 xen_pif_record_opt_set_free(record->pifs); 3.21 @@ -245,6 +249,23 @@ xen_host_get_other_config(xen_session *s 3.22 3.23 3.24 bool 3.25 +xen_host_get_supported_bootloaders(xen_session *session, struct xen_string_set **result, xen_host host) 3.26 +{ 3.27 + abstract_value param_values[] = 3.28 + { 3.29 + { .type = &abstract_type_string, 3.30 + .u.string_val = host } 3.31 + }; 3.32 + 3.33 + abstract_type result_type = abstract_type_string_set; 3.34 + 3.35 + *result = NULL; 3.36 + XEN_CALL_("host.get_supported_bootloaders"); 3.37 + return session->ok; 3.38 +} 3.39 + 3.40 + 3.41 +bool 3.42 xen_host_get_resident_vms(xen_session *session, struct xen_vm_set **result, xen_host host) 3.43 { 3.44 abstract_value param_values[] =
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tools/libxen/src/xen_string_set.c Wed Feb 21 00:04:59 2007 +0000 4.3 @@ -0,0 +1,47 @@ 4.4 +/* 4.5 + * Copyright (c) 2006-2007, XenSource Inc. 4.6 + * 4.7 + * This library is free software; you can redistribute it and/or 4.8 + * modify it under the terms of the GNU Lesser General Public 4.9 + * License as published by the Free Software Foundation; either 4.10 + * version 2.1 of the License, or (at your option) any later version. 4.11 + * 4.12 + * This library is distributed in the hope that it will be useful, 4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 4.15 + * Lesser General Public License for more details. 4.16 + * 4.17 + * You should have received a copy of the GNU Lesser General Public 4.18 + * License along with this library; if not, write to the Free Software 4.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4.20 + */ 4.21 + 4.22 + 4.23 +#include "xen_internal.h" 4.24 +#include "xen_string_set.h" 4.25 + 4.26 + 4.27 +xen_string_set * 4.28 +xen_string_set_alloc(size_t size) 4.29 +{ 4.30 + xen_string_set *result = calloc(1, sizeof(xen_string_set) + 4.31 + size * sizeof(char *)); 4.32 + result->size = size; 4.33 + return result; 4.34 +} 4.35 + 4.36 +void 4.37 +xen_string_set_free(xen_string_set *set) 4.38 +{ 4.39 + if (set == NULL) 4.40 + { 4.41 + return; 4.42 + } 4.43 + size_t n = set->size; 4.44 + for (size_t i = 0; i < n; i++) 4.45 + { 4.46 + free(set->contents[i]); 4.47 + } 4.48 + 4.49 + free(set); 4.50 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/tools/libxen/src/xen_string_set.h Wed Feb 21 00:04:59 2007 +0000 5.3 @@ -0,0 +1,47 @@ 5.4 +/* 5.5 + * Copyright (c) 2006-2007, XenSource Inc. 5.6 + * 5.7 + * This library is free software; you can redistribute it and/or 5.8 + * modify it under the terms of the GNU Lesser General Public 5.9 + * License as published by the Free Software Foundation; either 5.10 + * version 2.1 of the License, or (at your option) any later version. 5.11 + * 5.12 + * This library is distributed in the hope that it will be useful, 5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 5.15 + * Lesser General Public License for more details. 5.16 + * 5.17 + * You should have received a copy of the GNU Lesser General Public 5.18 + * License along with this library; if not, write to the Free Software 5.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 5.20 + */ 5.21 + 5.22 +#ifndef XEN_STRING_SET_H 5.23 +#define XEN_STRING_SET_H 5.24 + 5.25 + 5.26 +#include "xen_common.h" 5.27 + 5.28 + 5.29 +typedef struct xen_string_set 5.30 +{ 5.31 + size_t size; 5.32 + char *contents[]; 5.33 +} xen_string_set; 5.34 + 5.35 + 5.36 +/** 5.37 + * Allocate a xen_string_set of the given size. 5.38 + */ 5.39 +extern xen_string_set * 5.40 +xen_string_set_alloc(size_t size); 5.41 + 5.42 +/** 5.43 + * Free the given xen_string_set. The given set must have been allocated 5.44 + * by this library. 5.45 + */ 5.46 +extern void 5.47 +xen_string_set_free(xen_string_set *set); 5.48 + 5.49 + 5.50 +#endif
6.1 --- a/tools/libxen/test/test_bindings.c Wed Feb 21 00:04:06 2007 +0000 6.2 +++ b/tools/libxen/test/test_bindings.c Wed Feb 21 00:04:59 2007 +0000 6.3 @@ -222,6 +222,22 @@ int main(int argc, char **argv) 6.4 return 1; 6.5 } 6.6 6.7 + xen_string_set *supported_bootloaders; 6.8 + if (!xen_host_get_supported_bootloaders(session, &supported_bootloaders, 6.9 + host)) 6.10 + { 6.11 + print_error(session); 6.12 + free(dmesg); 6.13 + xen_string_string_map_free(versions); 6.14 + xen_host_free(host); 6.15 + xen_vm_record_free(vm_record); 6.16 + xen_uuid_bytes_free(vm_uuid_bytes); 6.17 + xen_uuid_free(vm_uuid); 6.18 + xen_vm_free(vm); 6.19 + CLEANUP; 6.20 + return 1; 6.21 + } 6.22 + 6.23 printf("%s.\n", vm_uuid); 6.24 6.25 fprintf(stderr, "In bytes, the VM UUID is "); 6.26 @@ -241,24 +257,39 @@ int main(int argc, char **argv) 6.27 6.28 printf("Host dmesg follows:\n%s\n\n", dmesg); 6.29 6.30 + printf("Host supports the following bootloaders:"); 6.31 + for (size_t i = 0; i < supported_bootloaders->size; i++) 6.32 + { 6.33 + printf(" %s", supported_bootloaders->contents[i]); 6.34 + } 6.35 + printf("\n"); 6.36 + 6.37 printf("%s.\n", vm_record->uuid); 6.38 6.39 printf("Resident on %s.\n", (char *)vm_record->resident_on->u.handle); 6.40 6.41 printf("%s.\n", xen_vm_power_state_to_string(vm_record->power_state)); 6.42 6.43 - print_vm_metrics(session, vm); 6.44 - 6.45 xen_uuid_bytes_free(vm_uuid_bytes); 6.46 xen_uuid_free(vm_uuid); 6.47 - xen_vm_free(vm); 6.48 6.49 xen_vm_record_free(vm_record); 6.50 6.51 xen_host_free(host); 6.52 xen_string_string_map_free(versions); 6.53 free(dmesg); 6.54 + xen_string_set_free(supported_bootloaders); 6.55 6.56 + print_vm_metrics(session, vm); 6.57 + if (!session->ok) 6.58 + { 6.59 + /* Error has been logged, just clean up. */ 6.60 + xen_vm_free(vm); 6.61 + CLEANUP; 6.62 + return 1; 6.63 + } 6.64 + 6.65 + xen_vm_free(vm); 6.66 6.67 xen_vm new_vm = create_new_vm(session, true); 6.68 if (!session->ok)