| 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_vif_metrics.h> |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | XEN_FREE(xen_vif_metrics) |
|---|
| 29 | XEN_SET_ALLOC_FREE(xen_vif_metrics) |
|---|
| 30 | XEN_ALLOC(xen_vif_metrics_record) |
|---|
| 31 | XEN_SET_ALLOC_FREE(xen_vif_metrics_record) |
|---|
| 32 | XEN_ALLOC(xen_vif_metrics_record_opt) |
|---|
| 33 | XEN_RECORD_OPT_FREE(xen_vif_metrics) |
|---|
| 34 | XEN_SET_ALLOC_FREE(xen_vif_metrics_record_opt) |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | static const struct_member xen_vif_metrics_record_struct_members[] = |
|---|
| 38 | { |
|---|
| 39 | { .key = "uuid", |
|---|
| 40 | .type = &abstract_type_string, |
|---|
| 41 | .offset = offsetof(xen_vif_metrics_record, uuid) }, |
|---|
| 42 | { .key = "io_read_kbs", |
|---|
| 43 | .type = &abstract_type_float, |
|---|
| 44 | .offset = offsetof(xen_vif_metrics_record, io_read_kbs) }, |
|---|
| 45 | { .key = "io_write_kbs", |
|---|
| 46 | .type = &abstract_type_float, |
|---|
| 47 | .offset = offsetof(xen_vif_metrics_record, io_write_kbs) }, |
|---|
| 48 | { .key = "last_updated", |
|---|
| 49 | .type = &abstract_type_datetime, |
|---|
| 50 | .offset = offsetof(xen_vif_metrics_record, last_updated) } |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | const abstract_type xen_vif_metrics_record_abstract_type_ = |
|---|
| 54 | { |
|---|
| 55 | .typename = STRUCT, |
|---|
| 56 | .struct_size = sizeof(xen_vif_metrics_record), |
|---|
| 57 | .member_count = |
|---|
| 58 | sizeof(xen_vif_metrics_record_struct_members) / sizeof(struct_member), |
|---|
| 59 | .members = xen_vif_metrics_record_struct_members |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | void |
|---|
| 64 | xen_vif_metrics_record_free(xen_vif_metrics_record *record) |
|---|
| 65 | { |
|---|
| 66 | if (record == NULL) |
|---|
| 67 | { |
|---|
| 68 | return; |
|---|
| 69 | } |
|---|
| 70 | free(record->handle); |
|---|
| 71 | free(record->uuid); |
|---|
| 72 | free(record); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | bool |
|---|
| 77 | xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics) |
|---|
| 78 | { |
|---|
| 79 | abstract_value param_values[] = |
|---|
| 80 | { |
|---|
| 81 | { .type = &abstract_type_string, |
|---|
| 82 | .u.string_val = vif_metrics } |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | abstract_type result_type = xen_vif_metrics_record_abstract_type_; |
|---|
| 86 | |
|---|
| 87 | *result = NULL; |
|---|
| 88 | XEN_CALL_("VIF_metrics.get_record"); |
|---|
| 89 | |
|---|
| 90 | if (session->ok) |
|---|
| 91 | { |
|---|
| 92 | (*result)->handle = xen_strdup_((*result)->uuid); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return session->ok; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | bool |
|---|
| 100 | xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid) |
|---|
| 101 | { |
|---|
| 102 | abstract_value param_values[] = |
|---|
| 103 | { |
|---|
| 104 | { .type = &abstract_type_string, |
|---|
| 105 | .u.string_val = uuid } |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | abstract_type result_type = abstract_type_string; |
|---|
| 109 | |
|---|
| 110 | *result = NULL; |
|---|
| 111 | XEN_CALL_("VIF_metrics.get_by_uuid"); |
|---|
| 112 | return session->ok; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | bool |
|---|
| 117 | xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) |
|---|
| 118 | { |
|---|
| 119 | abstract_value param_values[] = |
|---|
| 120 | { |
|---|
| 121 | { .type = &abstract_type_string, |
|---|
| 122 | .u.string_val = vif_metrics } |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | abstract_type result_type = abstract_type_float; |
|---|
| 126 | |
|---|
| 127 | XEN_CALL_("VIF_metrics.get_io_read_kbs"); |
|---|
| 128 | return session->ok; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | bool |
|---|
| 133 | xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) |
|---|
| 134 | { |
|---|
| 135 | abstract_value param_values[] = |
|---|
| 136 | { |
|---|
| 137 | { .type = &abstract_type_string, |
|---|
| 138 | .u.string_val = vif_metrics } |
|---|
| 139 | }; |
|---|
| 140 | |
|---|
| 141 | abstract_type result_type = abstract_type_float; |
|---|
| 142 | |
|---|
| 143 | XEN_CALL_("VIF_metrics.get_io_write_kbs"); |
|---|
| 144 | return session->ok; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | bool |
|---|
| 149 | xen_vif_metrics_get_last_updated(xen_session *session, time_t *result, xen_vif_metrics vif_metrics) |
|---|
| 150 | { |
|---|
| 151 | abstract_value param_values[] = |
|---|
| 152 | { |
|---|
| 153 | { .type = &abstract_type_string, |
|---|
| 154 | .u.string_val = vif_metrics } |
|---|
| 155 | }; |
|---|
| 156 | |
|---|
| 157 | abstract_type result_type = abstract_type_datetime; |
|---|
| 158 | |
|---|
| 159 | XEN_CALL_("VIF_metrics.get_last_updated"); |
|---|
| 160 | return session->ok; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | bool |
|---|
| 165 | xen_vif_metrics_get_all(xen_session *session, struct xen_vif_metrics_set **result) |
|---|
| 166 | { |
|---|
| 167 | |
|---|
| 168 | abstract_type result_type = abstract_type_string_set; |
|---|
| 169 | |
|---|
| 170 | *result = NULL; |
|---|
| 171 | xen_call_(session, "VIF_metrics.get_all", NULL, 0, &result_type, result); |
|---|
| 172 | return session->ok; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | bool |
|---|
| 177 | xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics) |
|---|
| 178 | { |
|---|
| 179 | abstract_value param_values[] = |
|---|
| 180 | { |
|---|
| 181 | { .type = &abstract_type_string, |
|---|
| 182 | .u.string_val = vif_metrics } |
|---|
| 183 | }; |
|---|
| 184 | |
|---|
| 185 | abstract_type result_type = abstract_type_string; |
|---|
| 186 | |
|---|
| 187 | *result = NULL; |
|---|
| 188 | XEN_CALL_("VIF_metrics.get_uuid"); |
|---|
| 189 | return session->ok; |
|---|
| 190 | } |
|---|