debuggers.hg
changeset 13734:66c2a4085863
Added missing PBD-related C bindings.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | Ewan Mellor <ewan@xensource.com> |
---|---|
date | Mon Jan 29 13:18:20 2007 +0000 (2007-01-29) |
parents | 049d9022653c |
children | 0a422c8c3144 |
files | tools/libxen/include/xen_pbd.h tools/libxen/include/xen_pbd_decl.h tools/libxen/src/xen_pbd.c |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/libxen/include/xen_pbd.h Mon Jan 29 13:18:20 2007 +0000 1.3 @@ -0,0 +1,216 @@ 1.4 +/* 1.5 + * Copyright (c) 2006, XenSource Inc. 1.6 + * 1.7 + * This library is free software; you can redistribute it and/or 1.8 + * modify it under the terms of the GNU Lesser General Public 1.9 + * License as published by the Free Software Foundation; either 1.10 + * version 2.1 of the License, or (at your option) any later version. 1.11 + * 1.12 + * This library is distributed in the hope that it will be useful, 1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.15 + * Lesser General Public License for more details. 1.16 + * 1.17 + * You should have received a copy of the GNU Lesser General Public 1.18 + * License along with this library; if not, write to the Free Software 1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1.20 + */ 1.21 + 1.22 +#ifndef XEN_PBD_H 1.23 +#define XEN_PBD_H 1.24 + 1.25 +#include "xen_common.h" 1.26 +#include "xen_host_decl.h" 1.27 +#include "xen_pbd_decl.h" 1.28 +#include "xen_sr_decl.h" 1.29 +#include "xen_string_string_map.h" 1.30 + 1.31 + 1.32 +/* 1.33 + * The PBD class. 1.34 + * 1.35 + * The physical block devices through which hosts access SRs. 1.36 + */ 1.37 + 1.38 + 1.39 +/** 1.40 + * Free the given xen_pbd. The given handle must have been allocated 1.41 + * by this library. 1.42 + */ 1.43 +extern void 1.44 +xen_pbd_free(xen_pbd pbd); 1.45 + 1.46 + 1.47 +typedef struct xen_pbd_set 1.48 +{ 1.49 + size_t size; 1.50 + xen_pbd *contents[]; 1.51 +} xen_pbd_set; 1.52 + 1.53 +/** 1.54 + * Allocate a xen_pbd_set of the given size. 1.55 + */ 1.56 +extern xen_pbd_set * 1.57 +xen_pbd_set_alloc(size_t size); 1.58 + 1.59 +/** 1.60 + * Free the given xen_pbd_set. The given set must have been allocated 1.61 + * by this library. 1.62 + */ 1.63 +extern void 1.64 +xen_pbd_set_free(xen_pbd_set *set); 1.65 + 1.66 + 1.67 +typedef struct xen_pbd_record 1.68 +{ 1.69 + xen_pbd handle; 1.70 + char *uuid; 1.71 + struct xen_host_record_opt *host; 1.72 + struct xen_sr_record_opt *sr; 1.73 + xen_string_string_map *device_config; 1.74 + bool currently_attached; 1.75 +} xen_pbd_record; 1.76 + 1.77 +/** 1.78 + * Allocate a xen_pbd_record. 1.79 + */ 1.80 +extern xen_pbd_record * 1.81 +xen_pbd_record_alloc(void); 1.82 + 1.83 +/** 1.84 + * Free the given xen_pbd_record, and all referenced values. The given 1.85 + * record must have been allocated by this library. 1.86 + */ 1.87 +extern void 1.88 +xen_pbd_record_free(xen_pbd_record *record); 1.89 + 1.90 + 1.91 +typedef struct xen_pbd_record_opt 1.92 +{ 1.93 + bool is_record; 1.94 + union 1.95 + { 1.96 + xen_pbd handle; 1.97 + xen_pbd_record *record; 1.98 + } u; 1.99 +} xen_pbd_record_opt; 1.100 + 1.101 +/** 1.102 + * Allocate a xen_pbd_record_opt. 1.103 + */ 1.104 +extern xen_pbd_record_opt * 1.105 +xen_pbd_record_opt_alloc(void); 1.106 + 1.107 +/** 1.108 + * Free the given xen_pbd_record_opt, and all referenced values. The 1.109 + * given record_opt must have been allocated by this library. 1.110 + */ 1.111 +extern void 1.112 +xen_pbd_record_opt_free(xen_pbd_record_opt *record_opt); 1.113 + 1.114 + 1.115 +typedef struct xen_pbd_record_set 1.116 +{ 1.117 + size_t size; 1.118 + xen_pbd_record *contents[]; 1.119 +} xen_pbd_record_set; 1.120 + 1.121 +/** 1.122 + * Allocate a xen_pbd_record_set of the given size. 1.123 + */ 1.124 +extern xen_pbd_record_set * 1.125 +xen_pbd_record_set_alloc(size_t size); 1.126 + 1.127 +/** 1.128 + * Free the given xen_pbd_record_set, and all referenced values. The 1.129 + * given set must have been allocated by this library. 1.130 + */ 1.131 +extern void 1.132 +xen_pbd_record_set_free(xen_pbd_record_set *set); 1.133 + 1.134 + 1.135 + 1.136 +typedef struct xen_pbd_record_opt_set 1.137 +{ 1.138 + size_t size; 1.139 + xen_pbd_record_opt *contents[]; 1.140 +} xen_pbd_record_opt_set; 1.141 + 1.142 +/** 1.143 + * Allocate a xen_pbd_record_opt_set of the given size. 1.144 + */ 1.145 +extern xen_pbd_record_opt_set * 1.146 +xen_pbd_record_opt_set_alloc(size_t size); 1.147 + 1.148 +/** 1.149 + * Free the given xen_pbd_record_opt_set, and all referenced values. 1.150 + * The given set must have been allocated by this library. 1.151 + */ 1.152 +extern void 1.153 +xen_pbd_record_opt_set_free(xen_pbd_record_opt_set *set); 1.154 + 1.155 + 1.156 +/** 1.157 + * Get a record containing the current state of the given PBD. 1.158 + */ 1.159 +extern bool 1.160 +xen_pbd_get_record(xen_session *session, xen_pbd_record **result, xen_pbd pbd); 1.161 + 1.162 + 1.163 +/** 1.164 + * Get a reference to the PBD instance with the specified UUID. 1.165 + */ 1.166 +extern bool 1.167 +xen_pbd_get_by_uuid(xen_session *session, xen_pbd *result, char *uuid); 1.168 + 1.169 + 1.170 +/** 1.171 + * Create a new PBD instance, and return its handle. 1.172 + */ 1.173 +extern bool 1.174 +xen_pbd_create(xen_session *session, xen_pbd *result, xen_pbd_record *record); 1.175 + 1.176 + 1.177 +/** 1.178 + * Destroy the specified PBD instance. 1.179 + */ 1.180 +extern bool 1.181 +xen_pbd_destroy(xen_session *session, xen_pbd pbd); 1.182 + 1.183 + 1.184 +/** 1.185 + * Get the uuid field of the given PBD. 1.186 + */ 1.187 +extern bool 1.188 +xen_pbd_get_uuid(xen_session *session, char **result, xen_pbd pbd); 1.189 + 1.190 + 1.191 +/** 1.192 + * Get the host field of the given PBD. 1.193 + */ 1.194 +extern bool 1.195 +xen_pbd_get_host(xen_session *session, xen_host *result, xen_pbd pbd); 1.196 + 1.197 + 1.198 +/** 1.199 + * Get the SR field of the given PBD. 1.200 + */ 1.201 +extern bool 1.202 +xen_pbd_get_sr(xen_session *session, xen_sr *result, xen_pbd pbd); 1.203 + 1.204 + 1.205 +/** 1.206 + * Get the device_config field of the given PBD. 1.207 + */ 1.208 +extern bool 1.209 +xen_pbd_get_device_config(xen_session *session, xen_string_string_map **result, xen_pbd pbd); 1.210 + 1.211 + 1.212 +/** 1.213 + * Get the currently_attached field of the given PBD. 1.214 + */ 1.215 +extern bool 1.216 +xen_pbd_get_currently_attached(xen_session *session, bool *result, xen_pbd pbd); 1.217 + 1.218 + 1.219 +#endif
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tools/libxen/include/xen_pbd_decl.h Mon Jan 29 13:18:20 2007 +0000 2.3 @@ -0,0 +1,30 @@ 2.4 +/* 2.5 + * Copyright (c) 2006, 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_PBD_DECL_H 2.23 +#define XEN_PBD_DECL_H 2.24 + 2.25 +typedef void *xen_pbd; 2.26 + 2.27 +struct xen_pbd_set; 2.28 +struct xen_pbd_record; 2.29 +struct xen_pbd_record_set; 2.30 +struct xen_pbd_record_opt; 2.31 +struct xen_pbd_record_opt_set; 2.32 + 2.33 +#endif
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tools/libxen/src/xen_pbd.c Mon Jan 29 13:18:20 2007 +0000 3.3 @@ -0,0 +1,228 @@ 3.4 +/* 3.5 + * Copyright (c) 2006, XenSource Inc. 3.6 + * 3.7 + * This library is free software; you can redistribute it and/or 3.8 + * modify it under the terms of the GNU Lesser General Public 3.9 + * License as published by the Free Software Foundation; either 3.10 + * version 2.1 of the License, or (at your option) any later version. 3.11 + * 3.12 + * This library is distributed in the hope that it will be useful, 3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 3.15 + * Lesser General Public License for more details. 3.16 + * 3.17 + * You should have received a copy of the GNU Lesser General Public 3.18 + * License along with this library; if not, write to the Free Software 3.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 3.20 + */ 3.21 + 3.22 + 3.23 +#include <stddef.h> 3.24 +#include <stdlib.h> 3.25 + 3.26 +#include "xen_common.h" 3.27 +#include "xen_host.h" 3.28 +#include "xen_internal.h" 3.29 +#include "xen_pbd.h" 3.30 +#include "xen_sr.h" 3.31 +#include "xen_string_string_map.h" 3.32 + 3.33 + 3.34 +XEN_FREE(xen_pbd) 3.35 +XEN_SET_ALLOC_FREE(xen_pbd) 3.36 +XEN_ALLOC(xen_pbd_record) 3.37 +XEN_SET_ALLOC_FREE(xen_pbd_record) 3.38 +XEN_ALLOC(xen_pbd_record_opt) 3.39 +XEN_RECORD_OPT_FREE(xen_pbd) 3.40 +XEN_SET_ALLOC_FREE(xen_pbd_record_opt) 3.41 + 3.42 + 3.43 +static const struct_member xen_pbd_record_struct_members[] = 3.44 + { 3.45 + { .key = "uuid", 3.46 + .type = &abstract_type_string, 3.47 + .offset = offsetof(xen_pbd_record, uuid) }, 3.48 + { .key = "host", 3.49 + .type = &abstract_type_ref, 3.50 + .offset = offsetof(xen_pbd_record, host) }, 3.51 + { .key = "SR", 3.52 + .type = &abstract_type_ref, 3.53 + .offset = offsetof(xen_pbd_record, sr) }, 3.54 + { .key = "device_config", 3.55 + .type = &abstract_type_string_string_map, 3.56 + .offset = offsetof(xen_pbd_record, device_config) }, 3.57 + { .key = "currently_attached", 3.58 + .type = &abstract_type_bool, 3.59 + .offset = offsetof(xen_pbd_record, currently_attached) } 3.60 + }; 3.61 + 3.62 +const abstract_type xen_pbd_record_abstract_type_ = 3.63 + { 3.64 + .typename = STRUCT, 3.65 + .struct_size = sizeof(xen_pbd_record), 3.66 + .member_count = 3.67 + sizeof(xen_pbd_record_struct_members) / sizeof(struct_member), 3.68 + .members = xen_pbd_record_struct_members 3.69 + }; 3.70 + 3.71 + 3.72 +void 3.73 +xen_pbd_record_free(xen_pbd_record *record) 3.74 +{ 3.75 + if (record == NULL) 3.76 + { 3.77 + return; 3.78 + } 3.79 + free(record->handle); 3.80 + free(record->uuid); 3.81 + xen_host_record_opt_free(record->host); 3.82 + xen_sr_record_opt_free(record->sr); 3.83 + xen_string_string_map_free(record->device_config); 3.84 + free(record); 3.85 +} 3.86 + 3.87 + 3.88 +bool 3.89 +xen_pbd_get_record(xen_session *session, xen_pbd_record **result, xen_pbd pbd) 3.90 +{ 3.91 + abstract_value param_values[] = 3.92 + { 3.93 + { .type = &abstract_type_string, 3.94 + .u.string_val = pbd } 3.95 + }; 3.96 + 3.97 + abstract_type result_type = xen_pbd_record_abstract_type_; 3.98 + 3.99 + *result = NULL; 3.100 + XEN_CALL_("PBD.get_record"); 3.101 + 3.102 + if (session->ok) 3.103 + { 3.104 + (*result)->handle = xen_strdup_((*result)->uuid); 3.105 + } 3.106 + 3.107 + return session->ok; 3.108 +} 3.109 + 3.110 + 3.111 +bool 3.112 +xen_pbd_get_by_uuid(xen_session *session, xen_pbd *result, char *uuid) 3.113 +{ 3.114 + abstract_value param_values[] = 3.115 + { 3.116 + { .type = &abstract_type_string, 3.117 + .u.string_val = uuid } 3.118 + }; 3.119 + 3.120 + abstract_type result_type = abstract_type_string; 3.121 + 3.122 + *result = NULL; 3.123 + XEN_CALL_("PBD.get_by_uuid"); 3.124 + return session->ok; 3.125 +} 3.126 + 3.127 + 3.128 +bool 3.129 +xen_pbd_create(xen_session *session, xen_pbd *result, xen_pbd_record *record) 3.130 +{ 3.131 + abstract_value param_values[] = 3.132 + { 3.133 + { .type = &xen_pbd_record_abstract_type_, 3.134 + .u.struct_val = record } 3.135 + }; 3.136 + 3.137 + abstract_type result_type = abstract_type_string; 3.138 + 3.139 + *result = NULL; 3.140 + XEN_CALL_("PBD.create"); 3.141 + return session->ok; 3.142 +} 3.143 + 3.144 + 3.145 +bool 3.146 +xen_pbd_destroy(xen_session *session, xen_pbd pbd) 3.147 +{ 3.148 + abstract_value param_values[] = 3.149 + { 3.150 + { .type = &abstract_type_string, 3.151 + .u.string_val = pbd } 3.152 + }; 3.153 + 3.154 + xen_call_(session, "PBD.destroy", param_values, 1, NULL, NULL); 3.155 + return session->ok; 3.156 +} 3.157 + 3.158 + 3.159 +bool 3.160 +xen_pbd_get_host(xen_session *session, xen_host *result, xen_pbd pbd) 3.161 +{ 3.162 + abstract_value param_values[] = 3.163 + { 3.164 + { .type = &abstract_type_string, 3.165 + .u.string_val = pbd } 3.166 + }; 3.167 + 3.168 + abstract_type result_type = abstract_type_string; 3.169 + 3.170 + *result = NULL; 3.171 + XEN_CALL_("PBD.get_host"); 3.172 + return session->ok; 3.173 +} 3.174 + 3.175 + 3.176 +bool 3.177 +xen_pbd_get_sr(xen_session *session, xen_sr *result, xen_pbd pbd) 3.178 +{ 3.179 + abstract_value param_values[] = 3.180 + { 3.181 + { .type = &abstract_type_string, 3.182 + .u.string_val = pbd } 3.183 + }; 3.184 + 3.185 + abstract_type result_type = abstract_type_string; 3.186 + 3.187 + *result = NULL; 3.188 + XEN_CALL_("PBD.get_SR"); 3.189 + return session->ok; 3.190 +} 3.191 + 3.192 + 3.193 +bool 3.194 +xen_pbd_get_device_config(xen_session *session, xen_string_string_map **result, xen_pbd pbd) 3.195 +{ 3.196 + abstract_value param_values[] = 3.197 + { 3.198 + { .type = &abstract_type_string, 3.199 + .u.string_val = pbd } 3.200 + }; 3.201 + 3.202 + abstract_type result_type = abstract_type_string_string_map; 3.203 + 3.204 + *result = NULL; 3.205 + XEN_CALL_("PBD.get_device_config"); 3.206 + return session->ok; 3.207 +} 3.208 + 3.209 + 3.210 +bool 3.211 +xen_pbd_get_currently_attached(xen_session *session, bool *result, xen_pbd pbd) 3.212 +{ 3.213 + abstract_value param_values[] = 3.214 + { 3.215 + { .type = &abstract_type_string, 3.216 + .u.string_val = pbd } 3.217 + }; 3.218 + 3.219 + abstract_type result_type = abstract_type_bool; 3.220 + 3.221 + XEN_CALL_("PBD.get_currently_attached"); 3.222 + return session->ok; 3.223 +} 3.224 + 3.225 + 3.226 +bool 3.227 +xen_pbd_get_uuid(xen_session *session, char **result, xen_pbd pbd) 3.228 +{ 3.229 + *result = session->ok ? xen_strdup_((char *)pbd) : NULL; 3.230 + return session->ok; 3.231 +}