[34] | 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 | */ |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #include <stddef.h> |
---|
| 21 | #include <stdlib.h> |
---|
| 22 | |
---|
| 23 | #include "xen_internal.h" |
---|
| 24 | #include <xen/api/xen_common.h> |
---|
| 25 | #include <xen/api/xen_host.h> |
---|
| 26 | #include <xen/api/xen_pbd.h> |
---|
| 27 | #include <xen/api/xen_sr.h> |
---|
| 28 | #include <xen/api/xen_string_string_map.h> |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | XEN_FREE(xen_pbd) |
---|
| 32 | XEN_SET_ALLOC_FREE(xen_pbd) |
---|
| 33 | XEN_ALLOC(xen_pbd_record) |
---|
| 34 | XEN_SET_ALLOC_FREE(xen_pbd_record) |
---|
| 35 | XEN_ALLOC(xen_pbd_record_opt) |
---|
| 36 | XEN_RECORD_OPT_FREE(xen_pbd) |
---|
| 37 | XEN_SET_ALLOC_FREE(xen_pbd_record_opt) |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | static const struct_member xen_pbd_record_struct_members[] = |
---|
| 41 | { |
---|
| 42 | { .key = "uuid", |
---|
| 43 | .type = &abstract_type_string, |
---|
| 44 | .offset = offsetof(xen_pbd_record, uuid) }, |
---|
| 45 | { .key = "host", |
---|
| 46 | .type = &abstract_type_ref, |
---|
| 47 | .offset = offsetof(xen_pbd_record, host) }, |
---|
| 48 | { .key = "SR", |
---|
| 49 | .type = &abstract_type_ref, |
---|
| 50 | .offset = offsetof(xen_pbd_record, sr) }, |
---|
| 51 | { .key = "device_config", |
---|
| 52 | .type = &abstract_type_string_string_map, |
---|
| 53 | .offset = offsetof(xen_pbd_record, device_config) }, |
---|
| 54 | { .key = "currently_attached", |
---|
| 55 | .type = &abstract_type_bool, |
---|
| 56 | .offset = offsetof(xen_pbd_record, currently_attached) } |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | const abstract_type xen_pbd_record_abstract_type_ = |
---|
| 60 | { |
---|
| 61 | .typename = STRUCT, |
---|
| 62 | .struct_size = sizeof(xen_pbd_record), |
---|
| 63 | .member_count = |
---|
| 64 | sizeof(xen_pbd_record_struct_members) / sizeof(struct_member), |
---|
| 65 | .members = xen_pbd_record_struct_members |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | void |
---|
| 70 | xen_pbd_record_free(xen_pbd_record *record) |
---|
| 71 | { |
---|
| 72 | if (record == NULL) |
---|
| 73 | { |
---|
| 74 | return; |
---|
| 75 | } |
---|
| 76 | free(record->handle); |
---|
| 77 | free(record->uuid); |
---|
| 78 | xen_host_record_opt_free(record->host); |
---|
| 79 | xen_sr_record_opt_free(record->sr); |
---|
| 80 | xen_string_string_map_free(record->device_config); |
---|
| 81 | free(record); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | bool |
---|
| 86 | xen_pbd_get_record(xen_session *session, xen_pbd_record **result, xen_pbd pbd) |
---|
| 87 | { |
---|
| 88 | abstract_value param_values[] = |
---|
| 89 | { |
---|
| 90 | { .type = &abstract_type_string, |
---|
| 91 | .u.string_val = pbd } |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | abstract_type result_type = xen_pbd_record_abstract_type_; |
---|
| 95 | |
---|
| 96 | *result = NULL; |
---|
| 97 | XEN_CALL_("PBD.get_record"); |
---|
| 98 | |
---|
| 99 | if (session->ok) |
---|
| 100 | { |
---|
| 101 | (*result)->handle = xen_strdup_((*result)->uuid); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | return session->ok; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | bool |
---|
| 109 | xen_pbd_get_by_uuid(xen_session *session, xen_pbd *result, char *uuid) |
---|
| 110 | { |
---|
| 111 | abstract_value param_values[] = |
---|
| 112 | { |
---|
| 113 | { .type = &abstract_type_string, |
---|
| 114 | .u.string_val = uuid } |
---|
| 115 | }; |
---|
| 116 | |
---|
| 117 | abstract_type result_type = abstract_type_string; |
---|
| 118 | |
---|
| 119 | *result = NULL; |
---|
| 120 | XEN_CALL_("PBD.get_by_uuid"); |
---|
| 121 | return session->ok; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | bool |
---|
| 126 | xen_pbd_create(xen_session *session, xen_pbd *result, xen_pbd_record *record) |
---|
| 127 | { |
---|
| 128 | abstract_value param_values[] = |
---|
| 129 | { |
---|
| 130 | { .type = &xen_pbd_record_abstract_type_, |
---|
| 131 | .u.struct_val = record } |
---|
| 132 | }; |
---|
| 133 | |
---|
| 134 | abstract_type result_type = abstract_type_string; |
---|
| 135 | |
---|
| 136 | *result = NULL; |
---|
| 137 | XEN_CALL_("PBD.create"); |
---|
| 138 | return session->ok; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | bool |
---|
| 143 | xen_pbd_destroy(xen_session *session, xen_pbd pbd) |
---|
| 144 | { |
---|
| 145 | abstract_value param_values[] = |
---|
| 146 | { |
---|
| 147 | { .type = &abstract_type_string, |
---|
| 148 | .u.string_val = pbd } |
---|
| 149 | }; |
---|
| 150 | |
---|
| 151 | xen_call_(session, "PBD.destroy", param_values, 1, NULL, NULL); |
---|
| 152 | return session->ok; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | bool |
---|
| 157 | xen_pbd_get_host(xen_session *session, xen_host *result, xen_pbd pbd) |
---|
| 158 | { |
---|
| 159 | abstract_value param_values[] = |
---|
| 160 | { |
---|
| 161 | { .type = &abstract_type_string, |
---|
| 162 | .u.string_val = pbd } |
---|
| 163 | }; |
---|
| 164 | |
---|
| 165 | abstract_type result_type = abstract_type_string; |
---|
| 166 | |
---|
| 167 | *result = NULL; |
---|
| 168 | XEN_CALL_("PBD.get_host"); |
---|
| 169 | return session->ok; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | bool |
---|
| 174 | xen_pbd_get_sr(xen_session *session, xen_sr *result, xen_pbd pbd) |
---|
| 175 | { |
---|
| 176 | abstract_value param_values[] = |
---|
| 177 | { |
---|
| 178 | { .type = &abstract_type_string, |
---|
| 179 | .u.string_val = pbd } |
---|
| 180 | }; |
---|
| 181 | |
---|
| 182 | abstract_type result_type = abstract_type_string; |
---|
| 183 | |
---|
| 184 | *result = NULL; |
---|
| 185 | XEN_CALL_("PBD.get_SR"); |
---|
| 186 | return session->ok; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | bool |
---|
| 191 | xen_pbd_get_device_config(xen_session *session, xen_string_string_map **result, xen_pbd pbd) |
---|
| 192 | { |
---|
| 193 | abstract_value param_values[] = |
---|
| 194 | { |
---|
| 195 | { .type = &abstract_type_string, |
---|
| 196 | .u.string_val = pbd } |
---|
| 197 | }; |
---|
| 198 | |
---|
| 199 | abstract_type result_type = abstract_type_string_string_map; |
---|
| 200 | |
---|
| 201 | *result = NULL; |
---|
| 202 | XEN_CALL_("PBD.get_device_config"); |
---|
| 203 | return session->ok; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | bool |
---|
| 208 | xen_pbd_get_currently_attached(xen_session *session, bool *result, xen_pbd pbd) |
---|
| 209 | { |
---|
| 210 | abstract_value param_values[] = |
---|
| 211 | { |
---|
| 212 | { .type = &abstract_type_string, |
---|
| 213 | .u.string_val = pbd } |
---|
| 214 | }; |
---|
| 215 | |
---|
| 216 | abstract_type result_type = abstract_type_bool; |
---|
| 217 | |
---|
| 218 | XEN_CALL_("PBD.get_currently_attached"); |
---|
| 219 | return session->ok; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | bool |
---|
| 224 | xen_pbd_get_all(xen_session *session, struct xen_pbd_set **result) |
---|
| 225 | { |
---|
| 226 | |
---|
| 227 | abstract_type result_type = abstract_type_string_set; |
---|
| 228 | |
---|
| 229 | *result = NULL; |
---|
| 230 | xen_call_(session, "PBD.get_all", NULL, 0, &result_type, result); |
---|
| 231 | return session->ok; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | bool |
---|
| 236 | xen_pbd_get_uuid(xen_session *session, char **result, xen_pbd pbd) |
---|
| 237 | { |
---|
| 238 | abstract_value param_values[] = |
---|
| 239 | { |
---|
| 240 | { .type = &abstract_type_string, |
---|
| 241 | .u.string_val = pbd } |
---|
| 242 | }; |
---|
| 243 | |
---|
| 244 | abstract_type result_type = abstract_type_string; |
---|
| 245 | |
---|
| 246 | *result = NULL; |
---|
| 247 | XEN_CALL_("PBD.get_uuid"); |
---|
| 248 | return session->ok; |
---|
| 249 | } |
---|