ia64/xen-unstable

view tools/libxen/src/xen_vbd.c @ 12281:9febecbeaeb0

[XENAPI] Add 'image' field to xen_vbd_record, allowing an image to be
associated with the vbd. xend supports this field and the client
bindings need it to support existing images that are not under
control of an SR.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author kfraser@localhost.localdomain
date Tue Nov 07 10:46:03 2006 +0000 (2006-11-07)
parents de00775e39da
children 08b38d041269
line source
1 /*
2 * Copyright (c) 2006, 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_driver_type_internal.h"
25 #include "xen_internal.h"
26 #include "xen_vbd.h"
27 #include "xen_vbd_mode_internal.h"
28 #include "xen_vdi.h"
29 #include "xen_vm.h"
32 XEN_FREE(xen_vbd)
33 XEN_SET_ALLOC_FREE(xen_vbd)
34 XEN_ALLOC(xen_vbd_record)
35 XEN_SET_ALLOC_FREE(xen_vbd_record)
36 XEN_ALLOC(xen_vbd_record_opt)
37 XEN_RECORD_OPT_FREE(xen_vbd)
38 XEN_SET_ALLOC_FREE(xen_vbd_record_opt)
41 static const struct_member xen_vbd_record_struct_members[] =
42 {
43 { .key = "uuid",
44 .type = &abstract_type_string,
45 .offset = offsetof(xen_vbd_record, uuid) },
46 { .key = "VM",
47 .type = &abstract_type_ref,
48 .offset = offsetof(xen_vbd_record, vm) },
49 { .key = "VDI",
50 .type = &abstract_type_ref,
51 .offset = offsetof(xen_vbd_record, vdi) },
52 { .key = "device",
53 .type = &abstract_type_string,
54 .offset = offsetof(xen_vbd_record, device) },
55 { .key = "image",
56 .type = &abstract_type_string,
57 .offset = offsetof(xen_vbd_record, image) },
58 { .key = "mode",
59 .type = &xen_vbd_mode_abstract_type_,
60 .offset = offsetof(xen_vbd_record, mode) },
61 { .key = "driver",
62 .type = &xen_driver_type_abstract_type_,
63 .offset = offsetof(xen_vbd_record, driver) },
64 { .key = "io_read_kbs",
65 .type = &abstract_type_float,
66 .offset = offsetof(xen_vbd_record, io_read_kbs) },
67 { .key = "io_write_kbs",
68 .type = &abstract_type_float,
69 .offset = offsetof(xen_vbd_record, io_write_kbs) }
70 };
72 const abstract_type xen_vbd_record_abstract_type_ =
73 {
74 .typename = STRUCT,
75 .struct_size = sizeof(xen_vbd_record),
76 .member_count =
77 sizeof(xen_vbd_record_struct_members) / sizeof(struct_member),
78 .members = xen_vbd_record_struct_members
79 };
82 void
83 xen_vbd_record_free(xen_vbd_record *record)
84 {
85 if (record == NULL)
86 {
87 return;
88 }
89 free(record->handle);
90 free(record->uuid);
91 xen_vm_record_opt_free(record->vm);
92 xen_vdi_record_opt_free(record->vdi);
93 free(record->device);
94 free(record);
95 }
98 bool
99 xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd)
100 {
101 abstract_value param_values[] =
102 {
103 { .type = &abstract_type_string,
104 .u.string_val = vbd }
105 };
107 abstract_type result_type = xen_vbd_record_abstract_type_;
109 *result = NULL;
110 XEN_CALL_("VBD.get_record");
112 if (session->ok)
113 {
114 (*result)->handle = xen_strdup_((*result)->uuid);
115 }
117 return session->ok;
118 }
121 bool
122 xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid)
123 {
124 abstract_value param_values[] =
125 {
126 { .type = &abstract_type_string,
127 .u.string_val = uuid }
128 };
130 abstract_type result_type = abstract_type_string;
132 *result = NULL;
133 XEN_CALL_("VBD.get_by_uuid");
134 return session->ok;
135 }
138 bool
139 xen_vbd_create(xen_session *session, xen_vbd *result, xen_vbd_record *record)
140 {
141 abstract_value param_values[] =
142 {
143 { .type = &xen_vbd_record_abstract_type_,
144 .u.struct_val = record }
145 };
147 abstract_type result_type = abstract_type_string;
149 *result = NULL;
150 XEN_CALL_("VBD.create");
151 return session->ok;
152 }
155 bool
156 xen_vbd_get_vm(xen_session *session, xen_vm *result, xen_vbd vbd)
157 {
158 abstract_value param_values[] =
159 {
160 { .type = &abstract_type_string,
161 .u.string_val = vbd }
162 };
164 abstract_type result_type = abstract_type_string;
166 *result = NULL;
167 XEN_CALL_("VBD.get_vm");
168 return session->ok;
169 }
172 bool
173 xen_vbd_get_vdi(xen_session *session, xen_vdi *result, xen_vbd vbd)
174 {
175 abstract_value param_values[] =
176 {
177 { .type = &abstract_type_string,
178 .u.string_val = vbd }
179 };
181 abstract_type result_type = abstract_type_string;
183 *result = NULL;
184 XEN_CALL_("VBD.get_vdi");
185 return session->ok;
186 }
189 bool
190 xen_vbd_get_device(xen_session *session, char **result, xen_vbd vbd)
191 {
192 abstract_value param_values[] =
193 {
194 { .type = &abstract_type_string,
195 .u.string_val = vbd }
196 };
198 abstract_type result_type = abstract_type_string;
200 *result = NULL;
201 XEN_CALL_("VBD.get_device");
202 return session->ok;
203 }
206 bool
207 xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd)
208 {
209 abstract_value param_values[] =
210 {
211 { .type = &abstract_type_string,
212 .u.string_val = vbd }
213 };
215 abstract_type result_type = xen_vbd_mode_abstract_type_;
216 char *result_str = NULL;
217 XEN_CALL_("VBD.get_mode");
218 *result = xen_vbd_mode_from_string(session, result_str);
219 return session->ok;
220 }
223 bool
224 xen_vbd_get_driver(xen_session *session, enum xen_driver_type *result, xen_vbd vbd)
225 {
226 abstract_value param_values[] =
227 {
228 { .type = &abstract_type_string,
229 .u.string_val = vbd }
230 };
232 abstract_type result_type = xen_driver_type_abstract_type_;
233 char *result_str = NULL;
234 XEN_CALL_("VBD.get_driver");
235 *result = xen_driver_type_from_string(session, result_str);
236 return session->ok;
237 }
240 bool
241 xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd)
242 {
243 abstract_value param_values[] =
244 {
245 { .type = &abstract_type_string,
246 .u.string_val = vbd }
247 };
249 abstract_type result_type = abstract_type_float;
251 XEN_CALL_("VBD.get_io_read_kbs");
252 return session->ok;
253 }
256 bool
257 xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd)
258 {
259 abstract_value param_values[] =
260 {
261 { .type = &abstract_type_string,
262 .u.string_val = vbd }
263 };
265 abstract_type result_type = abstract_type_float;
267 XEN_CALL_("VBD.get_io_write_kbs");
268 return session->ok;
269 }
272 bool
273 xen_vbd_set_vm(xen_session *session, xen_vbd xen_vbd, xen_vm vm)
274 {
275 abstract_value param_values[] =
276 {
277 { .type = &abstract_type_string,
278 .u.string_val = xen_vbd },
279 { .type = &abstract_type_string,
280 .u.string_val = vm }
281 };
283 xen_call_(session, "VBD.set_vm", param_values, 2, NULL, NULL);
284 return session->ok;
285 }
288 bool
289 xen_vbd_set_vdi(xen_session *session, xen_vbd xen_vbd, xen_vdi vdi)
290 {
291 abstract_value param_values[] =
292 {
293 { .type = &abstract_type_string,
294 .u.string_val = xen_vbd },
295 { .type = &abstract_type_string,
296 .u.string_val = vdi }
297 };
299 xen_call_(session, "VBD.set_vdi", param_values, 2, NULL, NULL);
300 return session->ok;
301 }
304 bool
305 xen_vbd_set_device(xen_session *session, xen_vbd xen_vbd, char *device)
306 {
307 abstract_value param_values[] =
308 {
309 { .type = &abstract_type_string,
310 .u.string_val = xen_vbd },
311 { .type = &abstract_type_string,
312 .u.string_val = device }
313 };
315 xen_call_(session, "VBD.set_device", param_values, 2, NULL, NULL);
316 return session->ok;
317 }
320 bool
321 xen_vbd_set_mode(xen_session *session, xen_vbd xen_vbd, enum xen_vbd_mode mode)
322 {
323 abstract_value param_values[] =
324 {
325 { .type = &abstract_type_string,
326 .u.string_val = xen_vbd },
327 { .type = &xen_vbd_mode_abstract_type_,
328 .u.string_val = xen_vbd_mode_to_string(mode) }
329 };
331 xen_call_(session, "VBD.set_mode", param_values, 2, NULL, NULL);
332 return session->ok;
333 }
336 bool
337 xen_vbd_set_driver(xen_session *session, xen_vbd xen_vbd, enum xen_driver_type driver)
338 {
339 abstract_value param_values[] =
340 {
341 { .type = &abstract_type_string,
342 .u.string_val = xen_vbd },
343 { .type = &xen_driver_type_abstract_type_,
344 .u.string_val = xen_driver_type_to_string(driver) }
345 };
347 xen_call_(session, "VBD.set_driver", param_values, 2, NULL, NULL);
348 return session->ok;
349 }
352 bool
353 xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi)
354 {
355 abstract_value param_values[] =
356 {
357 { .type = &abstract_type_string,
358 .u.string_val = vbd },
359 { .type = &abstract_type_string,
360 .u.string_val = vdi }
361 };
363 xen_call_(session, "VBD.media_change", param_values, 2, NULL, NULL);
364 return session->ok;
365 }
368 bool
369 xen_vbd_get_uuid(xen_session *session, char **result, xen_vbd vbd)
370 {
371 *result = session->ok ? xen_strdup_((char *)vbd) : NULL;
372 return session->ok;
373 }