os-cmpi-xen

view src/xen_utils.h @ 121:4868ace2726b

Add initial consistence checks in test suite for Xen_MemoryPool, Xen_ProcessorPool and Xen_VirtualSystemManagementService.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri Jun 08 10:22:05 2007 -0600 (2007-06-08)
parents 8ecc856bd445
children 28e8c94e92de
line source
1 // Copyright (C) 2006 Novell, Inc.
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 // ============================================================================
17 // Authors: Jim Fehlig, <jfehlig@novell.com>
18 // Contributors:
19 // Description: Utilitiy functions built on top of libxen for use in all
20 // providers.
21 // ============================================================================
23 #if !defined(__XEN_UTILS_H__)
24 #define __XEN_UTILS_H__
26 #include <string.h>
28 #include <xen_common.h>
29 #include <xen_vm.h>
30 #include <xen_vdi.h>
31 #include <xen_vbd.h>
32 #include <xen_vif.h>
35 #include <cmpidt.h>
38 /*
39 * A structure for encapsulating a Xen session. Providers should
40 * retrieve an instance of this object using xen_utils_xen_init() when
41 * first loaded into the cimom. xen_utils_xen_close() should be called
42 * when cimom invokes the provider's Cleanup() method.
43 */
44 typedef struct
45 {
46 xen_session *xen;
47 int socket;
48 xen_host host;
49 } xen_utils_session;
52 /*
53 * A structure for encapsulating domain resources.
54 */
55 typedef struct {
56 xen_vm_set *domains; /* List of domains */
57 unsigned int numdomains; /* Totoal number of domains */
58 unsigned int currentdomain; /* Current domain in the list */
59 } xen_domain_resources;
62 #define XEN_UTILS_ERROR_BUF_LEN 512
65 /*
66 * Macro for populating a char buffer with error messages contained
67 * in xen session object.
68 * buf is expected to be of length XEN_UTILS_ERROR_BUF_LEN
69 */
70 #define XEN_UTILS_GET_ERROR_STRING(buf, session) \
71 { \
72 memset(buf, 0, XEN_UTILS_ERROR_BUF_LEN); \
73 int ndx; \
74 for (ndx = 0; ndx < session->error_description_count; ndx++) \
75 { \
76 strncat(buf, session->error_description[ndx], \
77 XEN_UTILS_ERROR_BUF_LEN - (strlen(buf) + 1)); \
78 } \
79 } \
81 /*
82 * Macro for determining if there are more domain resources
83 * in the list.
84 */
85 #define XEN_UTILS_MORE_DOMAIN_RESOURCES(resources) \
86 (resources->currentdomain < resources->numdomains)
88 /*
89 * Macro for incrementing the current resource counter.
90 */
91 #define XEN_UTILS_INC_DOMAIN_RESOURCE_COUNT(resources) \
92 (resources->currentdomain++)
95 /*
96 * This macro can be used to generate functions for concatenating lists of
97 * Xen API reference objects (UUIDs). This macro is used in xen_utils.c to
98 * generate the xen_*_set_concat() functions declared below.
99 */
100 #define XEN_UTILS_REF_LIST_CONCAT(type__) \
101 int type__ ## _set_concat(type__ ## _set **target, type__ ## _set *source) \
102 { \
103 int total_size; \
104 int i, j; \
105 /* Nothing to concatenate if source is empty */ \
106 if (source == NULL || source->size == 0) \
107 return 1; \
108 /* If targe is empty, assign source to target */ \
109 if (*target == NULL) { \
110 *target = source; \
111 return 1; \
112 } \
113 /* realloc memory and append source to target */ \
114 total_size = (*target)->size + source->size; \
115 *target = realloc(*target, sizeof(type__ ## _set) + \
116 (total_size * sizeof(type__))); \
117 if (*target == NULL) \
118 return 0; \
119 for (j = (*target)->size, i = 0; i < source->size; i++) { \
120 (*target)->contents[j + i] = source->contents[i]; \
121 source->contents[i] = NULL; \
122 } \
123 (*target)->size = total_size; \
124 /* Free source list - it has been copied to target */ \
125 type__ ## _set_free(source); \
126 return 1; \
127 }
130 int xen_vm_set_concat(xen_vm_set **target, xen_vm_set *source);
131 int xen_vdi_set_concat(xen_vdi_set **target, xen_vdi_set *source);
132 int xen_vbd_set_concat(xen_vbd_set **target, xen_vbd_set *source);
133 int xen_vif_set_concat(xen_vif_set **target, xen_vif_set *source);
136 /*
137 * This macro can be used to generate functions for adding a Xen API
138 * reference objects (UUIDs) to a list of UUIDs. Currently, libxenapi
139 * does not support growing lists. For now, the macro is used in xen_utils.c to
140 * generate the xen_*_set_add() functions declared below.
141 *
142 * TODO:
143 * Submit this upstream so xen_*_set_add functions are available in
144 * the c-bindings?
145 */
146 #define XEN_UTILS_REF_LIST_ADD(type__) \
147 int type__ ## _set_add(type__ ## _set *list, type__ device) \
148 { \
149 if (list == NULL) { \
150 list = type__ ## _set_alloc(1); \
151 if (list == NULL) \
152 return 0; \
153 list->size = 1; \
154 list->contents[0] = device; \
155 return 1; \
156 } \
157 \
158 /* List is not empty. Grow the list and add the new device */ \
159 int new_len = sizeof(type__ ## _set) + ((list->size + 1) * sizeof(type__)); \
160 list = realloc(list, new_len); \
161 if (list == NULL) \
162 return 0; \
163 list->contents[list->size] = device; \
164 list->size++; \
165 return 1; \
166 }
169 int xen_vm_set_add(xen_vm_set *list, xen_vm vm);
170 int xen_vdi_set_add(xen_vdi_set *list, xen_vdi vdi);
171 int xen_vbd_set_add(xen_vbd_set *list, xen_vbd vbd);
172 int xen_vif_set_add(xen_vif_set *list, xen_vif vif);
175 /*
176 * This macro can be used to generate functions for adding a Xen API
177 * object to a list of such objects. Currently, libxenapi does not
178 * support growing lists. For now, the macro is used in xen_utils.c to
179 * generate the xen_*_set_add() functions declared below.
180 *
181 * TODO:
182 * 1. It is very similar to above :-). I can't figure out a clean way to
183 * handle slight difference (second parameter of the generated function).
184 *
185 * 2. Submit this upstream so xen_*_set_add functions are available in
186 * the c-bindings?
187 */
188 #define XEN_UTILS_DEV_LIST_ADD(type__) \
189 int type__ ## _set_add(type__ ## _set *list, type__ *device) \
190 { \
191 if (list == NULL) { \
192 list = type__ ## _set_alloc(1); \
193 if (list == NULL) \
194 return 0; \
195 list->size = 1; \
196 list->contents[0] = device; \
197 return 1; \
198 } \
199 \
200 /* List is not empty. Grow the list and add the new device */ \
201 int new_len = sizeof(type__ ## _set) + ((list->size + 1) * sizeof(type__)); \
202 list = realloc(list, new_len); \
203 if (list == NULL) \
204 return 0; \
205 list->contents[list->size] = device; \
206 list->size++; \
207 return 1; \
208 }
211 int xen_vdi_record_set_add(xen_vdi_record_set *list, xen_vdi_record *device);
212 int xen_vbd_record_set_add(xen_vbd_record_set *list, xen_vbd_record *device);
213 int xen_vif_record_set_add(xen_vif_record_set *list, xen_vif_record *device);
216 /*
217 * Initialize a session with Xen. Providers should acquire a Xen
218 * Session when loaded into the cimom, i.e. when the provider's
219 * Initialize() method is invoked by the cimom.
220 *
221 * On success a xen_utils_session object is placed in parameter
222 * session. The object is connected and logged-in to the Xen Daemon
223 * and ready for use.
224 *
225 * Returns non-zero on success, 0 on failure.
226 */
227 int xen_utils_xen_init(xen_utils_session **session);
230 /*
231 * Close Xen session. Connection to Xen Daemon is closed and the
232 * session handle is freed. Providers should invoke this function
233 * when their Cleanup() method is invoked by the cimom.
234 */
235 void xen_utils_xen_close(xen_utils_session *session);
238 /*
239 * Validate xend session. If sesssion is null, create one.
240 * Session is ready for use on success.
241 *
242 * Returns a non-zero on success, 0 on failure.
243 */
244 int xen_utils_validate_session(xen_utils_session **session);
247 /*
248 * Retrieve the domain resources (a list of VMs) using the provided
249 * session.
250 *
251 * Returns non-zero on success, 0 on failure.
252 */
253 int xen_utils_get_domain_resources(xen_utils_session *session,
254 xen_domain_resources **resources);
257 /*
258 * Free the list of domain resources.
259 * Returns non-zero on success, 0 on failure.
260 */
261 int xen_utils_free_domain_resources(xen_domain_resources *resources);
264 /*
265 * Retrieve the current domain from the list of domain resources.
266 * Returns non-zero on success, 0 on failure.
267 */
268 int xen_utils_get_current_domain_resource(xen_utils_session *session,
269 xen_domain_resources *resources,
270 xen_vm_record **resource);
273 /*
274 * Retrieve the next domain from the list of domain resources.
275 * Returns non-zero on success, 0 on failure.
276 */
277 int xen_utils_get_next_domain_resource(xen_utils_session *session,
278 xen_domain_resources *resources,
279 xen_vm_record **resource);
282 /*
283 * Free the domain resource specified by resource.
284 * Returns non-zero on success, 0 on failure.
285 */
286 int xen_utils_free_domain_resource(xen_vm_record *resource);
289 /*
290 * Retrieve a domain resource given a CIM_SettingData object path.
291 * Domain record will be placed in out param "domain".
292 * Returns non-zero on success, 0 on failure.
293 */
294 int xen_utils_get_domain_from_sd_OP(xen_utils_session *session,
295 xen_vm_record **domain,
296 const CMPIObjectPath *domOP);
299 /*
300 * Determine if the domain specified by name active.
301 * If active, isActive will be set to 1, otherwise 0.
302 * Returns non-zero on success, 0 on failure.
303 */
304 int xen_utils_is_domain_active(xen_utils_session *session,
305 const char *name,
306 int *isActive);
309 /*
310 * Extract a value with given key.
311 * Returns pointer to value on success, NULL on failure.
312 */
313 char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key);
316 /*
317 * Trace the error descriptions found in xen session object.
318 * This routine uses _sblim_trace function in cmpitrace interface
319 * for actual tracing. Output is to a location specified in the
320 * cmpitrace module.
321 */
322 void xen_utils_trace_error(xen_session *session);
327 #endif /* __XEN_UTILS_H__ */