ia64/xen-unstable

view tools/libxen/src/xen_vif.c @ 14116:fd7f23e44b11

Added VBD. and VIF.qos_supported_algorithms fields, with C bindings, Xend
implementation to follow.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Feb 21 23:03:00 2007 +0000 (2007-02-21)
parents bab07bed5c0a
children cfd23ac1b32a
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_internal.h"
25 #include "xen_network.h"
26 #include "xen_string_string_map.h"
27 #include "xen_vif.h"
28 #include "xen_vif_metrics.h"
29 #include "xen_vm.h"
32 XEN_FREE(xen_vif)
33 XEN_SET_ALLOC_FREE(xen_vif)
34 XEN_ALLOC(xen_vif_record)
35 XEN_SET_ALLOC_FREE(xen_vif_record)
36 XEN_ALLOC(xen_vif_record_opt)
37 XEN_RECORD_OPT_FREE(xen_vif)
38 XEN_SET_ALLOC_FREE(xen_vif_record_opt)
41 static const struct_member xen_vif_record_struct_members[] =
42 {
43 { .key = "uuid",
44 .type = &abstract_type_string,
45 .offset = offsetof(xen_vif_record, uuid) },
46 { .key = "device",
47 .type = &abstract_type_string,
48 .offset = offsetof(xen_vif_record, device) },
49 { .key = "network",
50 .type = &abstract_type_ref,
51 .offset = offsetof(xen_vif_record, network) },
52 { .key = "VM",
53 .type = &abstract_type_ref,
54 .offset = offsetof(xen_vif_record, vm) },
55 { .key = "MAC",
56 .type = &abstract_type_string,
57 .offset = offsetof(xen_vif_record, mac) },
58 { .key = "MTU",
59 .type = &abstract_type_int,
60 .offset = offsetof(xen_vif_record, mtu) },
61 { .key = "qos_algorithm_type",
62 .type = &abstract_type_string,
63 .offset = offsetof(xen_vif_record, qos_algorithm_type) },
64 { .key = "qos_algorithm_params",
65 .type = &abstract_type_string_string_map,
66 .offset = offsetof(xen_vif_record, qos_algorithm_params) },
67 { .key = "qos_supported_algorithms",
68 .type = &abstract_type_string_set,
69 .offset = offsetof(xen_vif_record, qos_supported_algorithms) },
70 { .key = "metrics",
71 .type = &abstract_type_ref,
72 .offset = offsetof(xen_vif_record, metrics) }
73 };
75 const abstract_type xen_vif_record_abstract_type_ =
76 {
77 .typename = STRUCT,
78 .struct_size = sizeof(xen_vif_record),
79 .member_count =
80 sizeof(xen_vif_record_struct_members) / sizeof(struct_member),
81 .members = xen_vif_record_struct_members
82 };
85 void
86 xen_vif_record_free(xen_vif_record *record)
87 {
88 if (record == NULL)
89 {
90 return;
91 }
92 free(record->handle);
93 free(record->uuid);
94 free(record->device);
95 xen_network_record_opt_free(record->network);
96 xen_vm_record_opt_free(record->vm);
97 free(record->mac);
98 free(record->qos_algorithm_type);
99 xen_string_string_map_free(record->qos_algorithm_params);
100 xen_string_set_free(record->qos_supported_algorithms);
101 xen_vif_metrics_record_opt_free(record->metrics);
102 free(record);
103 }
106 bool
107 xen_vif_get_record(xen_session *session, xen_vif_record **result, xen_vif vif)
108 {
109 abstract_value param_values[] =
110 {
111 { .type = &abstract_type_string,
112 .u.string_val = vif }
113 };
115 abstract_type result_type = xen_vif_record_abstract_type_;
117 *result = NULL;
118 XEN_CALL_("VIF.get_record");
120 if (session->ok)
121 {
122 (*result)->handle = xen_strdup_((*result)->uuid);
123 }
125 return session->ok;
126 }
129 bool
130 xen_vif_get_by_uuid(xen_session *session, xen_vif *result, char *uuid)
131 {
132 abstract_value param_values[] =
133 {
134 { .type = &abstract_type_string,
135 .u.string_val = uuid }
136 };
138 abstract_type result_type = abstract_type_string;
140 *result = NULL;
141 XEN_CALL_("VIF.get_by_uuid");
142 return session->ok;
143 }
146 bool
147 xen_vif_create(xen_session *session, xen_vif *result, xen_vif_record *record)
148 {
149 abstract_value param_values[] =
150 {
151 { .type = &xen_vif_record_abstract_type_,
152 .u.struct_val = record }
153 };
155 abstract_type result_type = abstract_type_string;
157 *result = NULL;
158 XEN_CALL_("VIF.create");
159 return session->ok;
160 }
163 bool
164 xen_vif_destroy(xen_session *session, xen_vif vif)
165 {
166 abstract_value param_values[] =
167 {
168 { .type = &abstract_type_string,
169 .u.string_val = vif }
170 };
172 xen_call_(session, "VIF.destroy", param_values, 1, NULL, NULL);
173 return session->ok;
174 }
177 bool
178 xen_vif_get_device(xen_session *session, char **result, xen_vif vif)
179 {
180 abstract_value param_values[] =
181 {
182 { .type = &abstract_type_string,
183 .u.string_val = vif }
184 };
186 abstract_type result_type = abstract_type_string;
188 *result = NULL;
189 XEN_CALL_("VIF.get_device");
190 return session->ok;
191 }
194 bool
195 xen_vif_get_network(xen_session *session, xen_network *result, xen_vif vif)
196 {
197 abstract_value param_values[] =
198 {
199 { .type = &abstract_type_string,
200 .u.string_val = vif }
201 };
203 abstract_type result_type = abstract_type_string;
205 *result = NULL;
206 XEN_CALL_("VIF.get_network");
207 return session->ok;
208 }
211 bool
212 xen_vif_get_vm(xen_session *session, xen_vm *result, xen_vif vif)
213 {
214 abstract_value param_values[] =
215 {
216 { .type = &abstract_type_string,
217 .u.string_val = vif }
218 };
220 abstract_type result_type = abstract_type_string;
222 *result = NULL;
223 XEN_CALL_("VIF.get_VM");
224 return session->ok;
225 }
228 bool
229 xen_vif_get_mac(xen_session *session, char **result, xen_vif vif)
230 {
231 abstract_value param_values[] =
232 {
233 { .type = &abstract_type_string,
234 .u.string_val = vif }
235 };
237 abstract_type result_type = abstract_type_string;
239 *result = NULL;
240 XEN_CALL_("VIF.get_MAC");
241 return session->ok;
242 }
245 bool
246 xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif)
247 {
248 abstract_value param_values[] =
249 {
250 { .type = &abstract_type_string,
251 .u.string_val = vif }
252 };
254 abstract_type result_type = abstract_type_int;
256 XEN_CALL_("VIF.get_MTU");
257 return session->ok;
258 }
261 bool
262 xen_vif_get_qos_algorithm_type(xen_session *session, char **result, xen_vif vif)
263 {
264 abstract_value param_values[] =
265 {
266 { .type = &abstract_type_string,
267 .u.string_val = vif }
268 };
270 abstract_type result_type = abstract_type_string;
272 *result = NULL;
273 XEN_CALL_("VIF.get_qos_algorithm_type");
274 return session->ok;
275 }
278 bool
279 xen_vif_get_qos_algorithm_params(xen_session *session, xen_string_string_map **result, xen_vif vif)
280 {
281 abstract_value param_values[] =
282 {
283 { .type = &abstract_type_string,
284 .u.string_val = vif }
285 };
287 abstract_type result_type = abstract_type_string_string_map;
289 *result = NULL;
290 XEN_CALL_("VIF.get_qos_algorithm_params");
291 return session->ok;
292 }
295 bool
296 xen_vif_get_qos_supported_algorithms(xen_session *session, struct xen_string_set **result, xen_vif vif)
297 {
298 abstract_value param_values[] =
299 {
300 { .type = &abstract_type_string,
301 .u.string_val = vif }
302 };
304 abstract_type result_type = abstract_type_string_set;
306 *result = NULL;
307 XEN_CALL_("VIF.get_qos_supported_algorithms");
308 return session->ok;
309 }
312 bool
313 xen_vif_get_metrics(xen_session *session, xen_vif_metrics *result, xen_vif vif)
314 {
315 abstract_value param_values[] =
316 {
317 { .type = &abstract_type_string,
318 .u.string_val = vif }
319 };
321 abstract_type result_type = abstract_type_string;
323 *result = NULL;
324 XEN_CALL_("VIF.get_metrics");
325 return session->ok;
326 }
329 bool
330 xen_vif_set_device(xen_session *session, xen_vif vif, char *device)
331 {
332 abstract_value param_values[] =
333 {
334 { .type = &abstract_type_string,
335 .u.string_val = vif },
336 { .type = &abstract_type_string,
337 .u.string_val = device }
338 };
340 xen_call_(session, "VIF.set_device", param_values, 2, NULL, NULL);
341 return session->ok;
342 }
345 bool
346 xen_vif_set_mac(xen_session *session, xen_vif vif, char *mac)
347 {
348 abstract_value param_values[] =
349 {
350 { .type = &abstract_type_string,
351 .u.string_val = vif },
352 { .type = &abstract_type_string,
353 .u.string_val = mac }
354 };
356 xen_call_(session, "VIF.set_MAC", param_values, 2, NULL, NULL);
357 return session->ok;
358 }
361 bool
362 xen_vif_set_mtu(xen_session *session, xen_vif vif, int64_t mtu)
363 {
364 abstract_value param_values[] =
365 {
366 { .type = &abstract_type_string,
367 .u.string_val = vif },
368 { .type = &abstract_type_int,
369 .u.int_val = mtu }
370 };
372 xen_call_(session, "VIF.set_MTU", param_values, 2, NULL, NULL);
373 return session->ok;
374 }
377 bool
378 xen_vif_set_qos_algorithm_type(xen_session *session, xen_vif vif, char *algorithm_type)
379 {
380 abstract_value param_values[] =
381 {
382 { .type = &abstract_type_string,
383 .u.string_val = vif },
384 { .type = &abstract_type_string,
385 .u.string_val = algorithm_type }
386 };
388 xen_call_(session, "VIF.set_qos_algorithm_type", param_values, 2, NULL, NULL);
389 return session->ok;
390 }
393 bool
394 xen_vif_set_qos_algorithm_params(xen_session *session, xen_vif vif, xen_string_string_map *algorithm_params)
395 {
396 abstract_value param_values[] =
397 {
398 { .type = &abstract_type_string,
399 .u.string_val = vif },
400 { .type = &abstract_type_string_string_map,
401 .u.set_val = (arbitrary_set *)algorithm_params }
402 };
404 xen_call_(session, "VIF.set_qos_algorithm_params", param_values, 2, NULL, NULL);
405 return session->ok;
406 }
409 bool
410 xen_vif_add_to_qos_algorithm_params(xen_session *session, xen_vif vif, char *key, char *value)
411 {
412 abstract_value param_values[] =
413 {
414 { .type = &abstract_type_string,
415 .u.string_val = vif },
416 { .type = &abstract_type_string,
417 .u.string_val = key },
418 { .type = &abstract_type_string,
419 .u.string_val = value }
420 };
422 xen_call_(session, "VIF.add_to_qos_algorithm_params", param_values, 3, NULL, NULL);
423 return session->ok;
424 }
427 bool
428 xen_vif_remove_from_qos_algorithm_params(xen_session *session, xen_vif vif, char *key)
429 {
430 abstract_value param_values[] =
431 {
432 { .type = &abstract_type_string,
433 .u.string_val = vif },
434 { .type = &abstract_type_string,
435 .u.string_val = key }
436 };
438 xen_call_(session, "VIF.remove_from_qos_algorithm_params", param_values, 2, NULL, NULL);
439 return session->ok;
440 }
443 bool
444 xen_vif_get_uuid(xen_session *session, char **result, xen_vif vif)
445 {
446 *result = session->ok ? xen_strdup_((char *)vif) : NULL;
447 return session->ok;
448 }