ia64/xen-unstable

view tools/libxen/src/xen_vdi.c @ 12166:de31d79add5e

Implement VDI.resize message.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Oct 26 15:57:29 2006 +0100 (2006-10-26)
parents c75716820107
children 1697ee515e46
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_internal.h"
25 #include "xen_sr.h"
26 #include "xen_vbd.h"
27 #include "xen_vdi.h"
28 #include "xen_vdi_type_internal.h"
31 XEN_FREE(xen_vdi)
32 XEN_SET_ALLOC_FREE(xen_vdi)
33 XEN_ALLOC(xen_vdi_record)
34 XEN_SET_ALLOC_FREE(xen_vdi_record)
35 XEN_ALLOC(xen_vdi_record_opt)
36 XEN_RECORD_OPT_FREE(xen_vdi)
37 XEN_SET_ALLOC_FREE(xen_vdi_record_opt)
40 static const struct_member xen_vdi_record_struct_members[] =
41 {
42 { .key = "uuid",
43 .type = &abstract_type_string,
44 .offset = offsetof(xen_vdi_record, uuid) },
45 { .key = "name_label",
46 .type = &abstract_type_string,
47 .offset = offsetof(xen_vdi_record, name_label) },
48 { .key = "name_description",
49 .type = &abstract_type_string,
50 .offset = offsetof(xen_vdi_record, name_description) },
51 { .key = "sr",
52 .type = &abstract_type_ref,
53 .offset = offsetof(xen_vdi_record, sr) },
54 { .key = "vbds",
55 .type = &abstract_type_ref_set,
56 .offset = offsetof(xen_vdi_record, vbds) },
57 { .key = "virtual_size",
58 .type = &abstract_type_int,
59 .offset = offsetof(xen_vdi_record, virtual_size) },
60 { .key = "physical_utilisation",
61 .type = &abstract_type_int,
62 .offset = offsetof(xen_vdi_record, physical_utilisation) },
63 { .key = "sector_size",
64 .type = &abstract_type_int,
65 .offset = offsetof(xen_vdi_record, sector_size) },
66 { .key = "type",
67 .type = &xen_vdi_type_abstract_type_,
68 .offset = offsetof(xen_vdi_record, type) },
69 { .key = "parent",
70 .type = &abstract_type_ref,
71 .offset = offsetof(xen_vdi_record, parent) },
72 { .key = "children",
73 .type = &abstract_type_ref_set,
74 .offset = offsetof(xen_vdi_record, children) },
75 { .key = "sharable",
76 .type = &abstract_type_bool,
77 .offset = offsetof(xen_vdi_record, sharable) },
78 { .key = "read_only",
79 .type = &abstract_type_bool,
80 .offset = offsetof(xen_vdi_record, read_only) }
81 };
83 const abstract_type xen_vdi_record_abstract_type_ =
84 {
85 .typename = STRUCT,
86 .struct_size = sizeof(xen_vdi_record),
87 .member_count =
88 sizeof(xen_vdi_record_struct_members) / sizeof(struct_member),
89 .members = xen_vdi_record_struct_members
90 };
93 void
94 xen_vdi_record_free(xen_vdi_record *record)
95 {
96 free(record->handle);
97 free(record->uuid);
98 free(record->name_label);
99 free(record->name_description);
100 xen_sr_record_opt_free(record->sr);
101 xen_vbd_record_opt_set_free(record->vbds);
102 xen_vdi_record_opt_free(record->parent);
103 xen_vdi_record_opt_set_free(record->children);
104 free(record);
105 }
108 bool
109 xen_vdi_get_record(xen_session *session, xen_vdi_record **result, xen_vdi vdi)
110 {
111 abstract_value param_values[] =
112 {
113 { .type = &abstract_type_string,
114 .u.string_val = vdi }
115 };
117 abstract_type result_type = xen_vdi_record_abstract_type_;
119 *result = NULL;
120 XEN_CALL_("VDI.get_record");
122 if (session->ok)
123 {
124 (*result)->handle = xen_strdup_((*result)->uuid);
125 }
127 return session->ok;
128 }
131 bool
132 xen_vdi_get_by_uuid(xen_session *session, xen_vdi *result, char *uuid)
133 {
134 abstract_value param_values[] =
135 {
136 { .type = &abstract_type_string,
137 .u.string_val = uuid }
138 };
140 abstract_type result_type = abstract_type_string;
142 *result = NULL;
143 XEN_CALL_("VDI.get_by_uuid");
144 return session->ok;
145 }
148 bool
149 xen_vdi_create(xen_session *session, xen_vdi *result, xen_vdi_record *record)
150 {
151 abstract_value param_values[] =
152 {
153 { .type = &xen_vdi_record_abstract_type_,
154 .u.struct_val = record }
155 };
157 abstract_type result_type = abstract_type_string;
159 *result = NULL;
160 XEN_CALL_("VDI.create");
161 return session->ok;
162 }
165 bool
166 xen_vdi_get_by_name_label(xen_session *session, xen_vdi *result, char *label)
167 {
168 abstract_value param_values[] =
169 {
170 { .type = &abstract_type_string,
171 .u.string_val = label }
172 };
174 abstract_type result_type = abstract_type_string;
176 *result = NULL;
177 XEN_CALL_("VDI.get_by_name_label");
178 return session->ok;
179 }
182 bool
183 xen_vdi_get_name_label(xen_session *session, char **result, xen_vdi vdi)
184 {
185 abstract_value param_values[] =
186 {
187 { .type = &abstract_type_string,
188 .u.string_val = vdi }
189 };
191 abstract_type result_type = abstract_type_string;
193 *result = NULL;
194 XEN_CALL_("VDI.get_name_label");
195 return session->ok;
196 }
199 bool
200 xen_vdi_get_name_description(xen_session *session, char **result, xen_vdi vdi)
201 {
202 abstract_value param_values[] =
203 {
204 { .type = &abstract_type_string,
205 .u.string_val = vdi }
206 };
208 abstract_type result_type = abstract_type_string;
210 *result = NULL;
211 XEN_CALL_("VDI.get_name_description");
212 return session->ok;
213 }
216 bool
217 xen_vdi_get_sr(xen_session *session, xen_sr *result, xen_vdi vdi)
218 {
219 abstract_value param_values[] =
220 {
221 { .type = &abstract_type_string,
222 .u.string_val = vdi }
223 };
225 abstract_type result_type = abstract_type_string;
227 *result = NULL;
228 XEN_CALL_("VDI.get_sr");
229 return session->ok;
230 }
233 bool
234 xen_vdi_get_vbds(xen_session *session, xen_vbd *result, xen_vdi vdi)
235 {
236 abstract_value param_values[] =
237 {
238 { .type = &abstract_type_string,
239 .u.string_val = vdi }
240 };
242 abstract_type result_type = abstract_type_string_set;
244 *result = NULL;
245 XEN_CALL_("VDI.get_vbds");
246 return session->ok;
247 }
250 bool
251 xen_vdi_get_virtual_size(xen_session *session, uint64_t *result, xen_vdi vdi)
252 {
253 abstract_value param_values[] =
254 {
255 { .type = &abstract_type_string,
256 .u.string_val = vdi }
257 };
259 abstract_type result_type = abstract_type_int;
261 XEN_CALL_("VDI.get_virtual_size");
262 return session->ok;
263 }
266 bool
267 xen_vdi_get_physical_utilisation(xen_session *session, uint64_t *result, xen_vdi vdi)
268 {
269 abstract_value param_values[] =
270 {
271 { .type = &abstract_type_string,
272 .u.string_val = vdi }
273 };
275 abstract_type result_type = abstract_type_int;
277 XEN_CALL_("VDI.get_physical_utilisation");
278 return session->ok;
279 }
282 bool
283 xen_vdi_get_sector_size(xen_session *session, uint64_t *result, xen_vdi vdi)
284 {
285 abstract_value param_values[] =
286 {
287 { .type = &abstract_type_string,
288 .u.string_val = vdi }
289 };
291 abstract_type result_type = abstract_type_int;
293 XEN_CALL_("VDI.get_sector_size");
294 return session->ok;
295 }
298 bool
299 xen_vdi_get_type(xen_session *session, enum xen_vdi_type *result, xen_vdi vdi)
300 {
301 abstract_value param_values[] =
302 {
303 { .type = &abstract_type_string,
304 .u.string_val = vdi }
305 };
307 abstract_type result_type = xen_vdi_type_abstract_type_;
308 char *result_str = NULL;
309 XEN_CALL_("VDI.get_type");
310 *result = xen_vdi_type_from_string(session, result_str);
311 return session->ok;
312 }
315 bool
316 xen_vdi_get_parent(xen_session *session, xen_vdi *result, xen_vdi vdi)
317 {
318 abstract_value param_values[] =
319 {
320 { .type = &abstract_type_string,
321 .u.string_val = vdi }
322 };
324 abstract_type result_type = abstract_type_string;
326 *result = NULL;
327 XEN_CALL_("VDI.get_parent");
328 return session->ok;
329 }
332 bool
333 xen_vdi_get_children(xen_session *session, xen_vdi *result, xen_vdi vdi)
334 {
335 abstract_value param_values[] =
336 {
337 { .type = &abstract_type_string,
338 .u.string_val = vdi }
339 };
341 abstract_type result_type = abstract_type_string_set;
343 *result = NULL;
344 XEN_CALL_("VDI.get_children");
345 return session->ok;
346 }
349 bool
350 xen_vdi_get_sharable(xen_session *session, bool *result, xen_vdi vdi)
351 {
352 abstract_value param_values[] =
353 {
354 { .type = &abstract_type_string,
355 .u.string_val = vdi }
356 };
358 abstract_type result_type = abstract_type_bool;
360 XEN_CALL_("VDI.get_sharable");
361 return session->ok;
362 }
365 bool
366 xen_vdi_get_read_only(xen_session *session, bool *result, xen_vdi vdi)
367 {
368 abstract_value param_values[] =
369 {
370 { .type = &abstract_type_string,
371 .u.string_val = vdi }
372 };
374 abstract_type result_type = abstract_type_bool;
376 XEN_CALL_("VDI.get_read_only");
377 return session->ok;
378 }
381 bool
382 xen_vdi_set_name_label(xen_session *session, xen_vdi xen_vdi, char *label)
383 {
384 abstract_value param_values[] =
385 {
386 { .type = &abstract_type_string,
387 .u.string_val = xen_vdi },
388 { .type = &abstract_type_string,
389 .u.string_val = label }
390 };
392 xen_call_(session, "VDI.set_name_label", param_values, 2, NULL, NULL);
393 return session->ok;
394 }
397 bool
398 xen_vdi_set_name_description(xen_session *session, xen_vdi xen_vdi, char *description)
399 {
400 abstract_value param_values[] =
401 {
402 { .type = &abstract_type_string,
403 .u.string_val = xen_vdi },
404 { .type = &abstract_type_string,
405 .u.string_val = description }
406 };
408 xen_call_(session, "VDI.set_name_description", param_values, 2, NULL, NULL);
409 return session->ok;
410 }
413 bool
414 xen_vdi_set_sr(xen_session *session, xen_vdi xen_vdi, xen_sr sr)
415 {
416 abstract_value param_values[] =
417 {
418 { .type = &abstract_type_string,
419 .u.string_val = xen_vdi },
420 { .type = &abstract_type_string,
421 .u.string_val = sr }
422 };
424 xen_call_(session, "VDI.set_sr", param_values, 2, NULL, NULL);
425 return session->ok;
426 }
429 bool
430 xen_vdi_set_virtual_size(xen_session *session, xen_vdi xen_vdi, uint64_t virtual_size)
431 {
432 abstract_value param_values[] =
433 {
434 { .type = &abstract_type_string,
435 .u.string_val = xen_vdi },
436 { .type = &abstract_type_int,
437 .u.int_val = virtual_size }
438 };
440 xen_call_(session, "VDI.set_virtual_size", param_values, 2, NULL, NULL);
441 return session->ok;
442 }
445 bool
446 xen_vdi_set_sharable(xen_session *session, xen_vdi xen_vdi, bool sharable)
447 {
448 abstract_value param_values[] =
449 {
450 { .type = &abstract_type_string,
451 .u.string_val = xen_vdi },
452 { .type = &abstract_type_bool,
453 .u.bool_val = sharable }
454 };
456 xen_call_(session, "VDI.set_sharable", param_values, 2, NULL, NULL);
457 return session->ok;
458 }
461 bool
462 xen_vdi_set_read_only(xen_session *session, xen_vdi xen_vdi, bool read_only)
463 {
464 abstract_value param_values[] =
465 {
466 { .type = &abstract_type_string,
467 .u.string_val = xen_vdi },
468 { .type = &abstract_type_bool,
469 .u.bool_val = read_only }
470 };
472 xen_call_(session, "VDI.set_read_only", param_values, 2, NULL, NULL);
473 return session->ok;
474 }
477 bool
478 xen_vdi_snapshot(xen_session *session, xen_vdi *result, xen_vdi vdi)
479 {
480 abstract_value param_values[] =
481 {
482 { .type = &abstract_type_string,
483 .u.string_val = vdi }
484 };
486 abstract_type result_type = abstract_type_string;
488 *result = NULL;
489 XEN_CALL_("VDI.snapshot");
490 return session->ok;
491 }
494 bool
495 xen_vdi_resize(xen_session *session, xen_vdi vdi, uint64_t size)
496 {
497 abstract_value param_values[] =
498 {
499 { .type = &abstract_type_string,
500 .u.string_val = vdi },
501 { .type = &abstract_type_int,
502 .u.int_val = size }
503 };
505 xen_call_(session, "VDI.resize", param_values, 2, NULL, NULL);
506 return session->ok;
507 }
510 bool
511 xen_vdi_get_uuid(xen_session *session, char **result, xen_vdi vdi)
512 {
513 *result = session->ok ? xen_strdup_((char *)vdi) : NULL;
514 return session->ok;
515 }