aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:07 +0100
committerIan Campbell <ian.campbell@citrix.com>2011-04-20 17:13:07 +0100
commit8b403a1dfdbd5bb06abbfca927097037a9ef8280 (patch)
treed0b377d65ee8923f617c7b2dd88e2d9ebf260b12 /tools/libxl
parent2da839263c4dd02b1433115583b8771b6d0fff36 (diff)
downloadxen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.tar.gz
xen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.tar.bz2
xen-8b403a1dfdbd5bb06abbfca927097037a9ef8280.zip
tools: libxl: add an Enumeration type to the IDL
The IDL requires a specific value for each enumerate, this make it much easier to avoid (or at least track) ABI changes since they must now be explicit. I believe I have used the same values as would have been chosen previoulsy but have not confirmed. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/gentypes.py23
-rw-r--r--tools/libxl/idl.txt24
-rw-r--r--tools/libxl/libxl.h65
-rw-r--r--tools/libxl/libxl.idl74
-rw-r--r--tools/libxl/libxltypes.py29
-rw-r--r--tools/libxl/xl_cmdimpl.c2
6 files changed, 144 insertions, 73 deletions
diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 20d403079a..099a3919f2 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -34,7 +34,28 @@ def libxl_C_instance_of(ty, instancename):
def libxl_C_type_define(ty, indent = ""):
s = ""
- if isinstance(ty, libxltypes.Aggregate):
+
+ if isinstance(ty, libxltypes.Enumeration):
+ if ty.comment is not None:
+ s += format_comment(0, ty.comment)
+
+ if ty.typename is None:
+ s += "enum {\n"
+ else:
+ s += "typedef enum %s {\n" % ty.typename
+
+ for v in ty.values:
+ if v.comment is not None:
+ s += format_comment(4, v.comment)
+ x = "%s = %d" % (v.name, v.value)
+ x = x.replace("\n", "\n ")
+ s += " " + x + ",\n"
+ if ty.typename is None:
+ s += "}"
+ else:
+ s += "} %s" % ty.typename
+
+ elif isinstance(ty, libxltypes.Aggregate):
if ty.comment is not None:
s += format_comment(0, ty.comment)
diff --git a/tools/libxl/idl.txt b/tools/libxl/idl.txt
index c691051393..9048828e77 100644
--- a/tools/libxl/idl.txt
+++ b/tools/libxl/idl.txt
@@ -82,6 +82,30 @@ libxltype.Reference
Complex type-Classes
--------------------
+libxltype.Enumeration
+
+ A class representing an enumeration (named integer values).
+
+ The values are available in the list Enumeration.values. Each
+ element in the list is of type libxltype.EnumerationValue.
+
+ Each EnumerationValue has the following properties:
+
+ EnumerationValue.enum Reference to containing Enumeration
+ EnumerationValue.name The C name of this value, including
+ the namespace and typename of the
+ containing Enumeration (e.g.
+ "LIBXL_FOOENUM_VALUE")
+ EnumerationValue.rawname The C name of this value, excluding
+ the namespace but including the
+ typename of the containing
+ Enumeration (e.g. "FOOENUM_VALUE")
+ EnumerationValue.valuename The name of this value, excluding the
+ name of the containing Enumeration
+ and any namespace (e.g. "VALUE")
+ EnumerationValue.value The integer value associated with this name.
+ EnumerationValue.comment A free text comment which describes the member.
+
libxltype.Aggregate
Base class for type-Classes which contain a number of other types
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 464527411c..f4f7faa2c2 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -161,49 +161,6 @@ typedef struct {
#define LIBXL_CPUARRAY_INVALID_ENTRY ~0
void libxl_cpuarray_destroy(libxl_cpuarray *array);
-typedef enum {
- LIBXL_DOMAIN_TYPE_FV = 1,
- LIBXL_DOMAIN_TYPE_PV,
-} libxl_domain_type;
-
-typedef enum libxl_device_model_version {
- /* Historical qemu-xen device model (qemu-dm) */
- LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL = 1,
- /* Upstream based qemu-xen device model */
- LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN = 2,
-} libxl_device_model_version;
-
-typedef enum {
- LIBXL_CONSOLE_TYPE_SERIAL = 1,
- LIBXL_CONSOLE_TYPE_PV,
-} libxl_console_type;
-
-typedef enum {
- LIBXL_CONSOLE_BACKEND_XENCONSOLED,
- LIBXL_CONSOLE_BACKEND_IOEMU,
-} libxl_console_backend;
-
-typedef enum {
- LIBXL_DISK_FORMAT_UNKNOWN = 0,
- LIBXL_DISK_FORMAT_QCOW,
- LIBXL_DISK_FORMAT_QCOW2,
- LIBXL_DISK_FORMAT_VHD,
- LIBXL_DISK_FORMAT_RAW,
- LIBXL_DISK_FORMAT_EMPTY,
-} libxl_disk_format;
-
-typedef enum {
- LIBXL_DISK_BACKEND_UNKNOWN = 0,
- LIBXL_DISK_BACKEND_PHY,
- LIBXL_DISK_BACKEND_TAP,
- LIBXL_DISK_BACKEND_QDISK,
-} libxl_disk_backend;
-
-typedef enum {
- LIBXL_NIC_TYPE_IOEMU = 1,
- LIBXL_NIC_TYPE_VIF,
-} libxl_nic_type;
-
typedef struct {
/*
* Path is always set if the file reference is valid. However if
@@ -252,18 +209,6 @@ enum {
#define LIBXL_VERSION 0
-typedef enum libxl_action_on_shutdown {
- LIBXL_ACTION_ON_SHUTDOWN_DESTROY,
-
- LIBXL_ACTION_ON_SHUTDOWN_RESTART,
- LIBXL_ACTION_ON_SHUTDOWN_RESTART_RENAME,
-
- LIBXL_ACTION_ON_SHUTDOWN_PRESERVE,
-
- LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY,
- LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_RESTART,
-} libxl_action_on_shutdown;
-
typedef struct {
libxl_domain_create_info c_info;
libxl_domain_build_info b_info;
@@ -327,11 +272,6 @@ int libxl_run_bootloader(libxl_ctx *ctx,
/* events handling */
-typedef enum {
- LIBXL_EVENT_TYPE_DOMAIN_DEATH,
- LIBXL_EVENT_TYPE_DISK_EJECT,
-} libxl_event_type;
-
typedef struct {
/* event type */
libxl_event_type type;
@@ -494,11 +434,6 @@ int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
* On error return, *data_r and *datalen_r are undefined.
*/
-typedef enum {
- LIBXL_BUTTON_POWER,
- LIBXL_BUTTON_SLEEP
-} libxl_button;
-
int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button);
int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
diff --git a/tools/libxl/libxl.idl b/tools/libxl/libxl.idl
index 8186c2a400..1ccddfc1ba 100644
--- a/tools/libxl/libxl.idl
+++ b/tools/libxl/libxl.idl
@@ -8,13 +8,6 @@ libxl_uuid = Builtin("uuid")
libxl_mac = Builtin("mac")
libxl_cpumap = Builtin("cpumap", destructor_fn="libxl_cpumap_destroy", passby=PASS_BY_REFERENCE)
libxl_cpuarray = Builtin("cpuarray", destructor_fn="libxl_cpuarray_destroy", passby=PASS_BY_REFERENCE)
-libxl_domain_type = Number("domain_type", namespace="libxl_")
-libxl_device_model_version = Number("device_model_version", namespace="libxl_")
-libxl_console_backend = Number("console_backend", namespace="libxl_")
-libxl_console_type = Number("console_type", namespace="libxl_")
-libxl_disk_format = Number("disk_format", namespace="libxl_")
-libxl_disk_backend = Number("disk_backend", namespace="libxl_")
-libxl_nic_type = Number("nic_type", namespace="libxl_")
libxl_cpuid_policy_list = Builtin("cpuid_policy_list", destructor_fn="libxl_cpuid_destroy", passby=PASS_BY_REFERENCE)
libxl_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy", passby=PASS_BY_REFERENCE)
@@ -24,6 +17,73 @@ libxl_file_reference = Builtin("file_reference", destructor_fn="libxl_file_refer
libxl_hwcap = Builtin("hwcap")
#
+# Constants / Enumerations
+#
+
+libxl_domain_type = Enumeration("domain_type", [
+ (1, "FV"),
+ (2, "PV"),
+ ])
+
+libxl_device_model_version = Enumeration("device_model_version", [
+ (1, "QEMU_XEN_TRADITIONAL", "Historical qemu-xen device model (qemu-dm)"),
+ (2, "QEMU_XEN", "Upstream based qemu-xen device model"),
+ ])
+
+libxl_console_type = Enumeration("console_type", [
+ (1, "SERIAL"),
+ (2, "PV"),
+ ])
+
+libxl_console_backend = Enumeration("console_backend", [
+ (1, "XENCONSOLED"),
+ (2, "IOEMU"),
+ ])
+
+libxl_disk_format = Enumeration("disk_format", [
+ (0, "UNKNOWN"),
+ (1, "QCOW"),
+ (2, "QCOW2"),
+ (3, "VHD"),
+ (4, "RAW"),
+ (5, "EMPTY"),
+ ])
+
+libxl_disk_backend = Enumeration("disk_backend", [
+ (0, "UNKNOWN"),
+ (1, "PHY"),
+ (2, "TAP"),
+ (3, "QDISK"),
+ ])
+
+libxl_nic_type = Enumeration("nic_type", [
+ (1, "IOEMU"),
+ (2, "VIF"),
+ ])
+
+libxl_action_on_shutdown = Enumeration("action_on_shutdown", [
+ (1, "DESTROY"),
+
+ (2, "RESTART"),
+ (3, "RESTART_RENAME"),
+
+ (4, "PRESERVE"),
+
+ (5, "COREDUMP_DESTROY"),
+ (6, "COREDUMP_RESTART"),
+ ])
+
+libxl_event_type = Enumeration("event_type", [
+ (1, "DOMAIN_DEATH"),
+ (2, "DISK_EJECT"),
+ ])
+
+libxl_button = Enumeration("button", [
+ (1, "POWER"),
+ (2, "SLEEP"),
+ ])
+
+#
# Complex libxl types
#
libxl_dominfo = Struct("dominfo",[
diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py
index 9c9e6427e7..a00711fe1e 100644
--- a/tools/libxl/libxltypes.py
+++ b/tools/libxl/libxltypes.py
@@ -52,6 +52,35 @@ class UInt(Number):
self.width = w
+class EnumerationValue(object):
+ def __init__(self, enum, value, name, **kwargs):
+ self.enum = enum
+
+ self.valuename = str.upper(name)
+ self.rawname = str.upper(enum.rawname) + "_" + self.valuename
+ self.name = str.upper(enum.namespace) + self.rawname
+ self.value = value
+ self.comment = kwargs.setdefault("comment", None)
+
+class Enumeration(Type):
+ def __init__(self, typename, values, **kwargs):
+ kwargs.setdefault('destructor_fn', None)
+ Type.__init__(self, typename, **kwargs)
+
+ self.values = []
+ for v in values:
+ # (value, name[, comment=None])
+ if len(v) == 2:
+ (num,name) = v
+ comment = None
+ elif len(v) == 3:
+ num,name,comment = v
+ else:
+ raise ""
+ self.values.append(EnumerationValue(self, num, name,
+ comment=comment,
+ typename=self.rawname))
+
class BitField(Type):
def __init__(self, ty, w, **kwargs):
kwargs.setdefault('namespace', None)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index f92b6e2777..48d89f97e3 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -451,6 +451,8 @@ static int parse_action_on_shutdown(const char *buf, libxl_action_on_shutdown *a
for (i = 0; i < sizeof(action_on_shutdown_names) / sizeof(action_on_shutdown_names[0]); i++) {
n = action_on_shutdown_names[i];
+ if (!n) continue;
+
if (strcmp(buf, n) == 0) {
*a = i;
return 1;