diff options
author | Ewan Mellor <ewan@xensource.com> | 2007-02-20 21:28:19 +0000 |
---|---|---|
committer | Ewan Mellor <ewan@xensource.com> | 2007-02-20 21:28:19 +0000 |
commit | d8d0f7d08c6ee3e5c1c3ec5fe10d71cc9d727949 (patch) | |
tree | b9a075d3a6913f275cd51a1c4b0dc6e4e0670940 /tools/libxen | |
parent | c2592685ffff80eee0091e8c8ac45da6137c2cd3 (diff) | |
download | xen-d8d0f7d08c6ee3e5c1c3ec5fe10d71cc9d727949.tar.gz xen-d8d0f7d08c6ee3e5c1c3ec5fe10d71cc9d727949.tar.bz2 xen-d8d0f7d08c6ee3e5c1c3ec5fe10d71cc9d727949.zip |
Split the VBD I/O statistics out into a VBD_metrics class. Document the
VBD.type field, and add it to the C bindings (this was already in Xend).
Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools/libxen')
-rw-r--r-- | tools/libxen/include/xen_vbd.h | 27 | ||||
-rw-r--r-- | tools/libxen/include/xen_vbd_metrics.h | 183 | ||||
-rw-r--r-- | tools/libxen/include/xen_vbd_metrics_decl.h | 30 | ||||
-rw-r--r-- | tools/libxen/include/xen_vbd_type.h | 77 | ||||
-rw-r--r-- | tools/libxen/include/xen_vbd_type_internal.h | 37 | ||||
-rw-r--r-- | tools/libxen/src/xen_vbd.c | 49 | ||||
-rw-r--r-- | tools/libxen/src/xen_vbd_metrics.c | 150 | ||||
-rw-r--r-- | tools/libxen/src/xen_vbd_type.c | 81 |
8 files changed, 609 insertions, 25 deletions
diff --git a/tools/libxen/include/xen_vbd.h b/tools/libxen/include/xen_vbd.h index 880449f3c1..d86ef6d3cd 100644 --- a/tools/libxen/include/xen_vbd.h +++ b/tools/libxen/include/xen_vbd.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 @@ -21,7 +21,9 @@ #include "xen_common.h" #include "xen_vbd_decl.h" +#include "xen_vbd_metrics_decl.h" #include "xen_vbd_mode.h" +#include "xen_vbd_type.h" #include "xen_vdi_decl.h" #include "xen_vm_decl.h" @@ -71,8 +73,8 @@ typedef struct xen_vbd_record char *image; bool bootable; enum xen_vbd_mode mode; - double io_read_kbs; - double io_write_kbs; + enum xen_vbd_type type; + struct xen_vbd_metrics_record_opt *metrics; } xen_vbd_record; /** @@ -155,14 +157,14 @@ xen_vbd_record_opt_set_free(xen_vbd_record_opt_set *set); /** - * Get the current state of the given VBD. !!! + * Get a record containing the current state of the given VBD. */ extern bool xen_vbd_get_record(xen_session *session, xen_vbd_record **result, xen_vbd vbd); /** - * Get a reference to the object with the specified UUID. !!! + * Get a reference to the VBD instance with the specified UUID. */ extern bool xen_vbd_get_by_uuid(xen_session *session, xen_vbd *result, char *uuid); @@ -225,17 +227,17 @@ xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd); /** - * Get the io/read_kbs field of the given VBD. + * Get the type field of the given VBD. */ extern bool -xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd); +xen_vbd_get_type(xen_session *session, enum xen_vbd_type *result, xen_vbd vbd); /** - * Get the io/write_kbs field of the given VBD. + * Get the metrics field of the given VBD. */ extern bool -xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd); +xen_vbd_get_metrics(xen_session *session, xen_vbd_metrics *result, xen_vbd vbd); /** @@ -260,6 +262,13 @@ xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode); /** + * Set the type field of the given VBD. + */ +extern bool +xen_vbd_set_type(xen_session *session, xen_vbd vbd, enum xen_vbd_type type); + + +/** * Change the media in the device for CDROM-like devices only. For * other devices, detach the VBD and attach a new one */ diff --git a/tools/libxen/include/xen_vbd_metrics.h b/tools/libxen/include/xen_vbd_metrics.h new file mode 100644 index 0000000000..8b3c1429d4 --- /dev/null +++ b/tools/libxen/include/xen_vbd_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_VBD_METRICS_H +#define XEN_VBD_METRICS_H + +#include "xen_common.h" +#include "xen_vbd_metrics_decl.h" + + +/* + * The VBD_metrics class. + * + * The metrics associated with a virtual block device. + */ + + +/** + * Free the given xen_vbd_metrics. The given handle must have been + * allocated by this library. + */ +extern void +xen_vbd_metrics_free(xen_vbd_metrics vbd_metrics); + + +typedef struct xen_vbd_metrics_set +{ + size_t size; + xen_vbd_metrics *contents[]; +} xen_vbd_metrics_set; + +/** + * Allocate a xen_vbd_metrics_set of the given size. + */ +extern xen_vbd_metrics_set * +xen_vbd_metrics_set_alloc(size_t size); + +/** + * Free the given xen_vbd_metrics_set. The given set must have been + * allocated by this library. + */ +extern void +xen_vbd_metrics_set_free(xen_vbd_metrics_set *set); + + +typedef struct xen_vbd_metrics_record +{ + xen_vbd_metrics handle; + char *uuid; + double io_read_kbs; + double io_write_kbs; +} xen_vbd_metrics_record; + +/** + * Allocate a xen_vbd_metrics_record. + */ +extern xen_vbd_metrics_record * +xen_vbd_metrics_record_alloc(void); + +/** + * Free the given xen_vbd_metrics_record, and all referenced values. + * The given record must have been allocated by this library. + */ +extern void +xen_vbd_metrics_record_free(xen_vbd_metrics_record *record); + + +typedef struct xen_vbd_metrics_record_opt +{ + bool is_record; + union + { + xen_vbd_metrics handle; + xen_vbd_metrics_record *record; + } u; +} xen_vbd_metrics_record_opt; + +/** + * Allocate a xen_vbd_metrics_record_opt. + */ +extern xen_vbd_metrics_record_opt * +xen_vbd_metrics_record_opt_alloc(void); + +/** + * Free the given xen_vbd_metrics_record_opt, and all referenced + * values. The given record_opt must have been allocated by this library. + */ +extern void +xen_vbd_metrics_record_opt_free(xen_vbd_metrics_record_opt *record_opt); + + +typedef struct xen_vbd_metrics_record_set +{ + size_t size; + xen_vbd_metrics_record *contents[]; +} xen_vbd_metrics_record_set; + +/** + * Allocate a xen_vbd_metrics_record_set of the given size. + */ +extern xen_vbd_metrics_record_set * +xen_vbd_metrics_record_set_alloc(size_t size); + +/** + * Free the given xen_vbd_metrics_record_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vbd_metrics_record_set_free(xen_vbd_metrics_record_set *set); + + + +typedef struct xen_vbd_metrics_record_opt_set +{ + size_t size; + xen_vbd_metrics_record_opt *contents[]; +} xen_vbd_metrics_record_opt_set; + +/** + * Allocate a xen_vbd_metrics_record_opt_set of the given size. + */ +extern xen_vbd_metrics_record_opt_set * +xen_vbd_metrics_record_opt_set_alloc(size_t size); + +/** + * Free the given xen_vbd_metrics_record_opt_set, and all referenced + * values. The given set must have been allocated by this library. + */ +extern void +xen_vbd_metrics_record_opt_set_free(xen_vbd_metrics_record_opt_set *set); + + +/** + * Get a record containing the current state of the given VBD_metrics. + */ +extern bool +xen_vbd_metrics_get_record(xen_session *session, xen_vbd_metrics_record **result, xen_vbd_metrics vbd_metrics); + + +/** + * Get a reference to the VBD_metrics instance with the specified UUID. + */ +extern bool +xen_vbd_metrics_get_by_uuid(xen_session *session, xen_vbd_metrics *result, char *uuid); + + +/** + * Get the uuid field of the given VBD_metrics. + */ +extern bool +xen_vbd_metrics_get_uuid(xen_session *session, char **result, xen_vbd_metrics vbd_metrics); + + +/** + * Get the io/read_kbs field of the given VBD_metrics. + */ +extern bool +xen_vbd_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics); + + +/** + * Get the io/write_kbs field of the given VBD_metrics. + */ +extern bool +xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics); + + +#endif diff --git a/tools/libxen/include/xen_vbd_metrics_decl.h b/tools/libxen/include/xen_vbd_metrics_decl.h new file mode 100644 index 0000000000..501aa8f60c --- /dev/null +++ b/tools/libxen/include/xen_vbd_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_VBD_METRICS_DECL_H +#define XEN_VBD_METRICS_DECL_H + +typedef void *xen_vbd_metrics; + +struct xen_vbd_metrics_set; +struct xen_vbd_metrics_record; +struct xen_vbd_metrics_record_set; +struct xen_vbd_metrics_record_opt; +struct xen_vbd_metrics_record_opt_set; + +#endif diff --git a/tools/libxen/include/xen_vbd_type.h b/tools/libxen/include/xen_vbd_type.h new file mode 100644 index 0000000000..656fa16316 --- /dev/null +++ b/tools/libxen/include/xen_vbd_type.h @@ -0,0 +1,77 @@ +/* + * 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_VBD_TYPE_H +#define XEN_VBD_TYPE_H + + +#include "xen_common.h" + + +enum xen_vbd_type +{ + /** + * VBD will appear to guest as CD + */ + XEN_VBD_TYPE_CD, + + /** + * VBD will appear to guest as disk + */ + XEN_VBD_TYPE_DISK +}; + + +typedef struct xen_vbd_type_set +{ + size_t size; + enum xen_vbd_type contents[]; +} xen_vbd_type_set; + +/** + * Allocate a xen_vbd_type_set of the given size. + */ +extern xen_vbd_type_set * +xen_vbd_type_set_alloc(size_t size); + +/** + * Free the given xen_vbd_type_set. The given set must have been + * allocated by this library. + */ +extern void +xen_vbd_type_set_free(xen_vbd_type_set *set); + + +/** + * Return the name corresponding to the given code. This string must + * not be modified or freed. + */ +extern const char * +xen_vbd_type_to_string(enum xen_vbd_type val); + + +/** + * Return the correct code for the given string, or set the session + * object to failure and return an undefined value if the given string does + * not match a known code. + */ +extern enum xen_vbd_type +xen_vbd_type_from_string(xen_session *session, const char *str); + + +#endif diff --git a/tools/libxen/include/xen_vbd_type_internal.h b/tools/libxen/include/xen_vbd_type_internal.h new file mode 100644 index 0000000000..5f027cf94e --- /dev/null +++ b/tools/libxen/include/xen_vbd_type_internal.h @@ -0,0 +1,37 @@ +/* + * 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 + */ + + +/* + * Declarations of the abstract types used during demarshalling of enum + * xen_vbd_type. Internal to this library -- do not use from outside. + */ + + +#ifndef XEN_VBD_TYPE_INTERNAL_H +#define XEN_VBD_TYPE_INTERNAL_H + + +#include "xen_internal.h" + + +extern const abstract_type xen_vbd_type_abstract_type_; +extern const abstract_type xen_vbd_type_set_abstract_type_; + + +#endif diff --git a/tools/libxen/src/xen_vbd.c b/tools/libxen/src/xen_vbd.c index 786c7ea896..d3c5709952 100644 --- a/tools/libxen/src/xen_vbd.c +++ b/tools/libxen/src/xen_vbd.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 @@ -23,7 +23,9 @@ #include "xen_common.h" #include "xen_internal.h" #include "xen_vbd.h" +#include "xen_vbd_metrics.h" #include "xen_vbd_mode_internal.h" +#include "xen_vbd_type_internal.h" #include "xen_vdi.h" #include "xen_vm.h" @@ -60,12 +62,12 @@ static const struct_member xen_vbd_record_struct_members[] = { .key = "mode", .type = &xen_vbd_mode_abstract_type_, .offset = offsetof(xen_vbd_record, mode) }, - { .key = "io_read_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vbd_record, io_read_kbs) }, - { .key = "io_write_kbs", - .type = &abstract_type_float, - .offset = offsetof(xen_vbd_record, io_write_kbs) } + { .key = "type", + .type = &xen_vbd_type_abstract_type_, + .offset = offsetof(xen_vbd_record, type) }, + { .key = "metrics", + .type = &abstract_type_ref, + .offset = offsetof(xen_vbd_record, metrics) } }; const abstract_type xen_vbd_record_abstract_type_ = @@ -90,6 +92,7 @@ xen_vbd_record_free(xen_vbd_record *record) xen_vm_record_opt_free(record->vm); xen_vdi_record_opt_free(record->vdi); free(record->device); + xen_vbd_metrics_record_opt_free(record->metrics); free(record); } @@ -242,15 +245,13 @@ xen_vbd_get_mode(xen_session *session, enum xen_vbd_mode *result, xen_vbd vbd) }; abstract_type result_type = xen_vbd_mode_abstract_type_; - char *result_str = NULL; XEN_CALL_("VBD.get_mode"); - *result = xen_vbd_mode_from_string(session, result_str); return session->ok; } bool -xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd) +xen_vbd_get_type(xen_session *session, enum xen_vbd_type *result, xen_vbd vbd) { abstract_value param_values[] = { @@ -258,15 +259,14 @@ xen_vbd_get_io_read_kbs(xen_session *session, double *result, xen_vbd vbd) .u.string_val = vbd } }; - abstract_type result_type = abstract_type_float; - - XEN_CALL_("VBD.get_io_read_kbs"); + abstract_type result_type = xen_vbd_type_abstract_type_; + XEN_CALL_("VBD.get_type"); return session->ok; } bool -xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd) +xen_vbd_get_metrics(xen_session *session, xen_vbd_metrics *result, xen_vbd vbd) { abstract_value param_values[] = { @@ -274,9 +274,10 @@ xen_vbd_get_io_write_kbs(xen_session *session, double *result, xen_vbd vbd) .u.string_val = vbd } }; - abstract_type result_type = abstract_type_float; + abstract_type result_type = abstract_type_string; - XEN_CALL_("VBD.get_io_write_kbs"); + *result = NULL; + XEN_CALL_("VBD.get_metrics"); return session->ok; } @@ -330,6 +331,22 @@ xen_vbd_set_mode(xen_session *session, xen_vbd vbd, enum xen_vbd_mode mode) bool +xen_vbd_set_type(xen_session *session, xen_vbd vbd, enum xen_vbd_type type) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vbd }, + { .type = &xen_vbd_type_abstract_type_, + .u.string_val = xen_vbd_type_to_string(type) } + }; + + xen_call_(session, "VBD.set_type", param_values, 2, NULL, NULL); + return session->ok; +} + + +bool xen_vbd_media_change(xen_session *session, xen_vbd vbd, xen_vdi vdi) { abstract_value param_values[] = diff --git a/tools/libxen/src/xen_vbd_metrics.c b/tools/libxen/src/xen_vbd_metrics.c new file mode 100644 index 0000000000..f2f51506df --- /dev/null +++ b/tools/libxen/src/xen_vbd_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_vbd_metrics.h" + + +XEN_FREE(xen_vbd_metrics) +XEN_SET_ALLOC_FREE(xen_vbd_metrics) +XEN_ALLOC(xen_vbd_metrics_record) +XEN_SET_ALLOC_FREE(xen_vbd_metrics_record) +XEN_ALLOC(xen_vbd_metrics_record_opt) +XEN_RECORD_OPT_FREE(xen_vbd_metrics) +XEN_SET_ALLOC_FREE(xen_vbd_metrics_record_opt) + + +static const struct_member xen_vbd_metrics_record_struct_members[] = + { + { .key = "uuid", + .type = &abstract_type_string, + .offset = offsetof(xen_vbd_metrics_record, uuid) }, + { .key = "io_read_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vbd_metrics_record, io_read_kbs) }, + { .key = "io_write_kbs", + .type = &abstract_type_float, + .offset = offsetof(xen_vbd_metrics_record, io_write_kbs) } + }; + +const abstract_type xen_vbd_metrics_record_abstract_type_ = + { + .typename = STRUCT, + .struct_size = sizeof(xen_vbd_metrics_record), + .member_count = + sizeof(xen_vbd_metrics_record_struct_members) / sizeof(struct_member), + .members = xen_vbd_metrics_record_struct_members + }; + + +void +xen_vbd_metrics_record_free(xen_vbd_metrics_record *record) +{ + if (record == NULL) + { + return; + } + free(record->handle); + free(record->uuid); + free(record); +} + + +bool +xen_vbd_metrics_get_record(xen_session *session, xen_vbd_metrics_record **result, xen_vbd_metrics vbd_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vbd_metrics } + }; + + abstract_type result_type = xen_vbd_metrics_record_abstract_type_; + + *result = NULL; + XEN_CALL_("VBD_metrics.get_record"); + + if (session->ok) + { + (*result)->handle = xen_strdup_((*result)->uuid); + } + + return session->ok; +} + + +bool +xen_vbd_metrics_get_by_uuid(xen_session *session, xen_vbd_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_("VBD_metrics.get_by_uuid"); + return session->ok; +} + + +bool +xen_vbd_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vbd_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VBD_metrics.get_io_read_kbs"); + return session->ok; +} + + +bool +xen_vbd_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vbd_metrics vbd_metrics) +{ + abstract_value param_values[] = + { + { .type = &abstract_type_string, + .u.string_val = vbd_metrics } + }; + + abstract_type result_type = abstract_type_float; + + XEN_CALL_("VBD_metrics.get_io_write_kbs"); + return session->ok; +} + + +bool +xen_vbd_metrics_get_uuid(xen_session *session, char **result, xen_vbd_metrics vbd_metrics) +{ + *result = session->ok ? xen_strdup_((char *)vbd_metrics) : NULL; + return session->ok; +} diff --git a/tools/libxen/src/xen_vbd_type.c b/tools/libxen/src/xen_vbd_type.c new file mode 100644 index 0000000000..874eb096ef --- /dev/null +++ b/tools/libxen/src/xen_vbd_type.c @@ -0,0 +1,81 @@ +/* + * 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 <string.h> + +#include "xen_internal.h" +#include "xen_vbd_type.h" +#include "xen_vbd_type_internal.h" + + +/* + * Maintain this in the same order as the enum declaration! + */ +static const char *lookup_table[] = +{ + "CD", + "Disk" +}; + + +extern xen_vbd_type_set * +xen_vbd_type_set_alloc(size_t size) +{ + return calloc(1, sizeof(xen_vbd_type_set) + + size * sizeof(enum xen_vbd_type)); +} + + +extern void +xen_vbd_type_set_free(xen_vbd_type_set *set) +{ + free(set); +} + + +const char * +xen_vbd_type_to_string(enum xen_vbd_type val) +{ + return lookup_table[val]; +} + + +extern enum xen_vbd_type +xen_vbd_type_from_string(xen_session *session, const char *str) +{ + return ENUM_LOOKUP(session, str, lookup_table); +} + + +const abstract_type xen_vbd_type_abstract_type_ = + { + .typename = ENUM, + .enum_marshaller = + (const char *(*)(int))&xen_vbd_type_to_string, + .enum_demarshaller = + (int (*)(xen_session *, const char *))&xen_vbd_type_from_string + }; + + +const abstract_type xen_vbd_type_set_abstract_type_ = + { + .typename = SET, + .child = &xen_vbd_type_abstract_type_ + }; + + |