1 | /* |
---|
2 | * Copyright (c) 2006, XenSource Inc. |
---|
3 | * Copyright (c) 2006, IBM Corp. |
---|
4 | * |
---|
5 | * This library is free software; you can redistribute it and/or |
---|
6 | * modify it under the terms of the GNU Lesser General Public |
---|
7 | * License as published by the Free Software Foundation; either |
---|
8 | * version 2.1 of the License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This library is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * Lesser General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Lesser General Public |
---|
16 | * License along with this library; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | */ |
---|
19 | |
---|
20 | |
---|
21 | #include <stddef.h> |
---|
22 | #include <stdlib.h> |
---|
23 | |
---|
24 | #include "xen_internal.h" |
---|
25 | #include <xen/api/xen_common.h> |
---|
26 | #include <xen/api/xen_vm.h> |
---|
27 | #include <xen/api/xen_vtpm.h> |
---|
28 | |
---|
29 | |
---|
30 | XEN_FREE(xen_vtpm) |
---|
31 | XEN_SET_ALLOC_FREE(xen_vtpm) |
---|
32 | XEN_ALLOC(xen_vtpm_record) |
---|
33 | XEN_SET_ALLOC_FREE(xen_vtpm_record) |
---|
34 | XEN_ALLOC(xen_vtpm_record_opt) |
---|
35 | XEN_RECORD_OPT_FREE(xen_vtpm) |
---|
36 | XEN_SET_ALLOC_FREE(xen_vtpm_record_opt) |
---|
37 | |
---|
38 | |
---|
39 | static const struct_member xen_vtpm_record_struct_members[] = |
---|
40 | { |
---|
41 | { .key = "uuid", |
---|
42 | .type = &abstract_type_string, |
---|
43 | .offset = offsetof(xen_vtpm_record, uuid) }, |
---|
44 | { .key = "VM", |
---|
45 | .type = &abstract_type_ref, |
---|
46 | .offset = offsetof(xen_vtpm_record, vm) }, |
---|
47 | { .key = "backend", |
---|
48 | .type = &abstract_type_ref, |
---|
49 | .offset = offsetof(xen_vtpm_record, backend) } |
---|
50 | }; |
---|
51 | |
---|
52 | const abstract_type xen_vtpm_record_abstract_type_ = |
---|
53 | { |
---|
54 | .typename = STRUCT, |
---|
55 | .struct_size = sizeof(xen_vtpm_record), |
---|
56 | .member_count = |
---|
57 | sizeof(xen_vtpm_record_struct_members) / sizeof(struct_member), |
---|
58 | .members = xen_vtpm_record_struct_members |
---|
59 | }; |
---|
60 | |
---|
61 | |
---|
62 | void |
---|
63 | xen_vtpm_record_free(xen_vtpm_record *record) |
---|
64 | { |
---|
65 | if (record == NULL) |
---|
66 | { |
---|
67 | return; |
---|
68 | } |
---|
69 | free(record->handle); |
---|
70 | free(record->uuid); |
---|
71 | xen_vm_record_opt_free(record->vm); |
---|
72 | xen_vm_record_opt_free(record->backend); |
---|
73 | free(record); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | bool |
---|
78 | xen_vtpm_get_record(xen_session *session, xen_vtpm_record **result, xen_vtpm vtpm) |
---|
79 | { |
---|
80 | abstract_value param_values[] = |
---|
81 | { |
---|
82 | { .type = &abstract_type_string, |
---|
83 | .u.string_val = vtpm } |
---|
84 | }; |
---|
85 | |
---|
86 | abstract_type result_type = xen_vtpm_record_abstract_type_; |
---|
87 | |
---|
88 | *result = NULL; |
---|
89 | XEN_CALL_("VTPM.get_record"); |
---|
90 | |
---|
91 | if (session->ok) |
---|
92 | { |
---|
93 | (*result)->handle = xen_strdup_((*result)->uuid); |
---|
94 | } |
---|
95 | |
---|
96 | return session->ok; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | bool |
---|
101 | xen_vtpm_get_by_uuid(xen_session *session, xen_vtpm *result, char *uuid) |
---|
102 | { |
---|
103 | abstract_value param_values[] = |
---|
104 | { |
---|
105 | { .type = &abstract_type_string, |
---|
106 | .u.string_val = uuid } |
---|
107 | }; |
---|
108 | |
---|
109 | abstract_type result_type = abstract_type_string; |
---|
110 | |
---|
111 | *result = NULL; |
---|
112 | XEN_CALL_("VTPM.get_by_uuid"); |
---|
113 | return session->ok; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | bool |
---|
118 | xen_vtpm_create(xen_session *session, xen_vtpm *result, xen_vtpm_record *record) |
---|
119 | { |
---|
120 | abstract_value param_values[] = |
---|
121 | { |
---|
122 | { .type = &xen_vtpm_record_abstract_type_, |
---|
123 | .u.struct_val = record } |
---|
124 | }; |
---|
125 | |
---|
126 | abstract_type result_type = abstract_type_string; |
---|
127 | |
---|
128 | *result = NULL; |
---|
129 | XEN_CALL_("VTPM.create"); |
---|
130 | return session->ok; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | bool |
---|
135 | xen_vtpm_destroy(xen_session *session, xen_vtpm vtpm) |
---|
136 | { |
---|
137 | abstract_value param_values[] = |
---|
138 | { |
---|
139 | { .type = &abstract_type_string, |
---|
140 | .u.string_val = vtpm } |
---|
141 | }; |
---|
142 | |
---|
143 | xen_call_(session, "VTPM.destroy", param_values, 1, NULL, NULL); |
---|
144 | return session->ok; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | bool |
---|
149 | xen_vtpm_get_vm(xen_session *session, xen_vm *result, xen_vtpm vtpm) |
---|
150 | { |
---|
151 | abstract_value param_values[] = |
---|
152 | { |
---|
153 | { .type = &abstract_type_string, |
---|
154 | .u.string_val = vtpm } |
---|
155 | }; |
---|
156 | |
---|
157 | abstract_type result_type = abstract_type_string; |
---|
158 | |
---|
159 | *result = NULL; |
---|
160 | XEN_CALL_("VTPM.get_VM"); |
---|
161 | return session->ok; |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | bool |
---|
166 | xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm) |
---|
167 | { |
---|
168 | abstract_value param_values[] = |
---|
169 | { |
---|
170 | { .type = &abstract_type_string, |
---|
171 | .u.string_val = vtpm } |
---|
172 | }; |
---|
173 | |
---|
174 | abstract_type result_type = abstract_type_string; |
---|
175 | |
---|
176 | *result = NULL; |
---|
177 | XEN_CALL_("VTPM.get_backend"); |
---|
178 | return session->ok; |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | bool |
---|
183 | xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm) |
---|
184 | { |
---|
185 | abstract_value param_values[] = |
---|
186 | { |
---|
187 | { .type = &abstract_type_string, |
---|
188 | .u.string_val = vtpm } |
---|
189 | }; |
---|
190 | |
---|
191 | abstract_type result_type = abstract_type_string; |
---|
192 | |
---|
193 | *result = NULL; |
---|
194 | XEN_CALL_("VTPM.get_uuid"); |
---|
195 | return session->ok; |
---|
196 | } |
---|