diff options
author | Ewan Mellor <ewan@xensource.com> | 2007-02-20 21:55:11 +0000 |
---|---|---|
committer | Ewan Mellor <ewan@xensource.com> | 2007-02-20 21:55:11 +0000 |
commit | fa4627735b0d9117cda8c9f7cc96eefcf91db8e4 (patch) | |
tree | 2db18880244eae59cd0632f67e7de925bd6d0e7a /tools/libxen | |
parent | d8d0f7d08c6ee3e5c1c3ec5fe10d71cc9d727949 (diff) | |
download | xen-fa4627735b0d9117cda8c9f7cc96eefcf91db8e4.tar.gz xen-fa4627735b0d9117cda8c9f7cc96eefcf91db8e4.tar.bz2 xen-fa4627735b0d9117cda8c9f7cc96eefcf91db8e4.zip |
Split the VIF I/O statistics fields out into a VIF_metrics class. Implement
this in Xend, and fix the VBD_metrics implementation. Implement C bindings
also.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools/libxen')
-rw-r--r-- | tools/libxen/include/xen_vif.h | 17 | ||||
-rw-r--r-- | tools/libxen/include/xen_vif_metrics.h | 183 | ||||
-rw-r--r-- | tools/libxen/include/xen_vif_metrics_decl.h | 30 | ||||
-rw-r--r-- | tools/libxen/src/xen_vif.c | 36 | ||||
-rw-r--r-- | tools/libxen/src/xen_vif_metrics.c | 150 |
5 files changed, 378 insertions, 38 deletions
diff --git a/tools/libxen/include/xen_vif.h b/tools/libxen/include/xen_vif.h index 7141bf3197..160d8a02b3 100644 --- a/tools/libxen/include/xen_vif.h +++ b/tools/libxen/include/xen_vif.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, XenSource Inc. + * Copyright (c) 2006-2007, XenSource Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ #include "xen_common.h" #include "xen_network_decl.h" #include "xen_vif_decl.h" +#include "xen_vif_metrics_decl.h" #include "xen_vm_decl.h" @@ -69,8 +70,7 @@ typedef struct xen_vif_record struct xen_vm_record_opt *vm; char *mac; int64_t mtu; - double io_read_kbs; - double io_write_kbs; + struct xen_vif_metrics_record_opt *metrics; } xen_vif_record; /** @@ -223,17 +223,10 @@ xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif); /** - * Get the io/read_kbs field of the given VIF. + * Get the metrics field of the given VIF. */ extern bool -xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif); - - -/** - * Get the io/write_kbs field of the given VIF. - */ -extern bool -xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif); +xen_vif_get_metrics(xen_session *session, xen_vif_metrics *result, xen_vif vif); /** diff --git a/tools/libxen/include/xen_vif_metrics.h b/tools/libxen/include/xen_vif_metrics.h new file mode 100644 index 0000000000..2b150d0a68 --- /dev/null +++ b/tools/libxen/include/xen_vif_metrics.h @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef XEN_VIF_METRICS_H +#define XEN_VIF_METRICS_H + +#include "xen_common.h" +#include "xen_vif_metrics_decl.h" + + +/* + * The VIF_metrics class. + * + * The metrics associated with a virtual network device. + */ + + +/** + * Free the given xen_vif_metrics. The given handle must have been + * allocated by this library. + */ +extern void +xen_vif_metrics_free(xen_vif_metrics vif_metrics); + + +typedef struct xen_vif_metrics_set +{ + size_t size; + xen_vif_metrics *contents[]; +} xen_vif_metrics_set; + +/** + * Allocate a xen_vif_metrics_set of the given size. + */ +extern xen_vif_metrics_set * +xen_vif_metrics_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_set. The given set must have been + * allocated by this library. + */ +extern void +xen_vif_metrics_set_free(xen_vif_metrics_set *set); + + +typedef struct xen_vif_metrics_record +{ + xen_vif_metrics handle; + char *uuid; + double io_read_kbs; + double io_write_kbs; +} xen_vif_metrics_record; + +/** + * Allocate a xen_vif_metrics_record. + */ +extern xen_vif_metrics_record * +xen_vif_metrics_record_alloc(void); + +/** + * Free the given xen_vif_metrics_record, and all referenced values. + * The given record must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_free(xen_vif_metrics_record *record); + + +typedef struct xen_vif_metrics_record_opt +{ + bool is_record; + union + { + xen_vif_metrics handle; + xen_vif_metrics_record *record; + } u; +} xen_vif_metrics_record_opt; + +/** + * Allocate a xen_vif_metrics_record_opt. + */ +extern xen_vif_metrics_record_opt * +xen_vif_metrics_record_opt_alloc(void); + +/** + * Free the given xen_vif_metrics_record_opt, and all referenced + * values. The given record_opt must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_opt_free(xen_vif_metrics_record_opt *record_opt); + + +typedef struct xen_vif_metrics_record_set +{ + size_t size; + xen_vif_metrics_record *contents[]; +} xen_vif_metrics_record_set; + +/** + * Allocate a xen_vif_metrics_record_set of the given size. + */ +extern xen_vif_metrics_record_set * +xen_vif_metrics_record_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_record_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_set_free(xen_vif_metrics_record_set *set); + + + +typedef struct xen_vif_metrics_record_opt_set +{ + size_t size; + xen_vif_metrics_record_opt *contents[]; +} xen_vif_metrics_record_opt_set; + +/** + * Allocate a xen_vif_metrics_record_opt_set of the given size. + */ +extern xen_vif_metrics_record_opt_set * +xen_vif_metrics_record_opt_set_alloc(size_t size); + +/** + * Free the given xen_vif_metrics_record_opt_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vif_metrics_record_opt_set_free(xen_vif_metrics_record_opt_set *set); + + +/** + * Get a record containing the current state of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics); + + +/** + * Get a reference to the VIF_metrics instance with the specified UUID. + */ +extern bool +xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid); + + +/** + * Get the uuid field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics); + + +/** + * Get the io/read_kbs field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics); + + +/** + * Get the io/write_kbs field of the given VIF_metrics. + */ +extern bool +xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics); + + +#endif diff --git a/tools/libxen/include/xen_vif_metrics_decl.h b/tools/libxen/include/xen_vif_metrics_decl.h new file mode 100644 index 0000000000..5734723adf --- /dev/null +++ b/tools/libxen/include/xen_vif_metrics_decl.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef XEN_VIF_METRICS_DECL_H +#define XEN_VIF_METRICS_DECL_H + +typedef void *xen_vif_metrics; + +struct xen_vif_metrics_set; +struct xen_vif_metrics_record; +struct xen_vif_metrics_record_set; +struct xen_vif_metrics_record_opt; +struct xen_vif_metrics_record_opt_set; + +#endif diff --git a/tools/libxen/src/xen_vif.c b/tools/libxen/src/xen_vif.c index 47ef4730f6..3fc214b16e 100644 --- a/tools/libxen/src/xen_vif.c +++ b/tools/libxen/src/xen_vif.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, XenSource Inc. + * Copyright (c) 2006-2007, XenSource Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,6 +24,7 @@ #include "xen_internal.h" #include "xen_network.h" #include "xen_vif.h" +#include "xen_vif_metrics.h" #include "xen_vm.h" @@ -56,12 +57,9 @@ static const struct_member xen_vif_record_struct_members[] = { .key = "MTU", .type = &abstract_type_int, .offset = offsetof(xen_vif_record, mtu) }, - { .key = "io_read_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vif_record, io_read_kbs) }, - { .key = "io_write_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vif_record, io_write_kbs) } + { .key = "metrics", + .type = &abstract_type_ref, + .offset = offsetof(xen_vif_record, metrics) } }; const abstract_type xen_vif_record_abstract_type_ = @@ -87,6 +85,7 @@ xen_vif_record_free(xen_vif_record *record) xen_network_record_opt_free(record->network); xen_vm_record_opt_free(record->vm); free(record->mac); + xen_vif_metrics_record_opt_free(record->metrics); free(record); } @@ -247,23 +246,7 @@ xen_vif_get_mtu(xen_session *session, int64_t *result, xen_vif vif) bool -xen_vif_get_io_read_kbs(xen_session *session, double *result, xen_vif vif) -{ - abstract_value param_values[] = - { - { .type = &abstract_type_string, - .u.string_val = vif } - }; - - abstract_type result_type = abstract_type_float; - - XEN_CALL_("VIF.get_io_read_kbs"); - return session->ok; -} - - -bool -xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif) +xen_vif_get_metrics(xen_session *session, xen_vif_metrics *result, xen_vif vif) { abstract_value param_values[] = { @@ -271,9 +254,10 @@ xen_vif_get_io_write_kbs(xen_session *session, double *result, xen_vif vif) .u.string_val = vif } }; - abstract_type result_type = abstract_type_float; + abstract_type result_type = abstract_type_string; - XEN_CALL_("VIF.get_io_write_kbs"); + *result = NULL; + XEN_CALL_("VIF.get_metrics"); return session->ok; } diff --git a/tools/libxen/src/xen_vif_metrics.c b/tools/libxen/src/xen_vif_metrics.c new file mode 100644 index 0000000000..1f43993024 --- /dev/null +++ b/tools/libxen/src/xen_vif_metrics.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2006-2007, XenSource Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include <stddef.h> +#include <stdlib.h> + +#include "xen_common.h" +#include "xen_internal.h" +#include "xen_vif_metrics.h" + + +XEN_FREE(xen_vif_metrics) +XEN_SET_ALLOC_FREE(xen_vif_metrics) +XEN_ALLOC(xen_vif_metrics_record) +XEN_SET_ALLOC_FREE(xen_vif_metrics_record) +XEN_ALLOC(xen_vif_metrics_record_opt) +XEN_RECORD_OPT_FREE(xen_vif_metrics) +XEN_SET_ALLOC_FREE(xen_vif_metrics_record_opt) + + +static const struct_member xen_vif_metrics_record_struct_members[] = + { + { .key = "uuid", + .type = &abstract_type_string, + .offset = offsetof(xen_vif_metrics_record, uuid) }, + { .key = "io_read_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vif_metrics_record, io_read_kbs) }, + { .key = "io_write_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vif_metrics_record, io_write_kbs) } + }; + +const abstract_type xen_vif_metrics_record_abstract_type_ = + { + .typename = STRUCT, + .struct_size = sizeof(xen_vif_metrics_record), + .member_count = + sizeof(xen_vif_metrics_record_struct_members) / sizeof(struct_member), + .members = xen_vif_metrics_record_struct_members + }; + + +void +xen_vif_metrics_record_free(xen_vif_metrics_record *record) +{ + if (record == NULL) + { + return; + } + free(record->handle); + free(record->uuid); + free(record); +} + + +bool +xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = xen_vif_metrics_record_abstract_type_; + + *result = NULL; + XEN_CALL_("VIF_metrics.get_record"); + + if (session->ok) + { + (*result)->handle = xen_strdup_((*result)->uuid); + } + + return session->ok; +} + + +bool +xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = uuid } + }; + + abstract_type result_type = abstract_type_string; + + *result = NULL; + XEN_CALL_("VIF_metrics.get_by_uuid"); + return session->ok; +} + + +bool +xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VIF_metrics.get_io_read_kbs"); + return session->ok; +} + + +bool +xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vif_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VIF_metrics.get_io_write_kbs"); + return session->ok; +} + + +bool +xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics) +{ + *result = session->ok ? xen_strdup_((char *)vif_metrics) : NULL; + return session->ok; +} |