[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 25 of 32 RFC] libxl: make boolean members of libxl_domain_create_info into libxl_defbool



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1326470400 0
# Node ID 87c469583499236e6a524f9c9271323ae91394fe
# Parent  7e9f3ce2cd1f05ae30727bed05f295c7fdfbb2ea
libxl: make boolean members of libxl_domain_create_info into libxl_defbool

All members of libxl_domain_create_info are now "0 == default".

It doesn't seem reasonble for the library to pick a default for the domain type
so reject as invalid.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/gentest.py
--- a/tools/libxl/gentest.py    Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/gentest.py    Fri Jan 13 16:00:00 2012 +0000
@@ -19,8 +19,7 @@ def randomize_case(s):
 def randomize_enum(e):
     return random.choice([v.name for v in e.values])
 
-handcoded = ["libxl_defbool", # Temp until a user appears in the next patch
-             "libxl_cpumap", "libxl_key_value_list",
+handcoded = ["libxl_cpumap", "libxl_key_value_list",
              "libxl_cpuid_policy_list", "libxl_file_reference",
              "libxl_string_list", "libxl_cpuarray"]
 
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/libxl_create.c        Fri Jan 13 16:00:00 2012 +0000
@@ -60,13 +60,20 @@ void libxl_domain_config_dispose(libxl_d
 int libxl_init_create_info(libxl_ctx *ctx, libxl_domain_create_info *c_info)
 {
     memset(c_info, '\0', sizeof(*c_info));
-    c_info->xsdata = NULL;
-    c_info->platformdata = NULL;
-    c_info->hap = 1;
-    c_info->type = LIBXL_DOMAIN_TYPE_HVM;
-    c_info->oos = 1;
-    c_info->ssidref = 0;
-    c_info->poolid = 0;
+    return 0;
+}
+
+int libxl__domain_create_info_setdefaults(libxl__gc *gc,
+                                          libxl_domain_create_info *c_info)
+{
+    if (!c_info->type)
+        return ERROR_INVAL;
+
+    if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) {
+        libxl_defbool_setdefault(&c_info->hap, true);
+        libxl_defbool_setdefault(&c_info->oos, true);
+    }
+
     return 0;
 }
 
@@ -325,8 +332,8 @@ int libxl__domain_make(libxl__gc *gc, li
     flags = 0;
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         flags |= XEN_DOMCTL_CDF_hvm_guest;
-        flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
-        flags |= info->oos ? 0 : XEN_DOMCTL_CDF_oos_off;
+        flags |= libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0;
+        flags |= libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off;
     }
     *domid = -1;
 
@@ -456,6 +463,9 @@ static int do_domain_create(libxl__gc *g
 
     domid = 0;
 
+    ret = libxl__domain_create_info_setdefaults(gc, &d_config->c_info);
+    if (ret) goto error_out;
+
     ret = libxl__domain_make(gc, &d_config->c_info, &domid);
     if (ret) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot make domain: %d", ret);
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/libxl_dm.c    Fri Jan 13 16:00:00 2012 +0000
@@ -749,6 +749,9 @@ static int libxl__create_stubdom(libxl__
     dm_config.vifs = guest_config->vifs;
     dm_config.num_vifs = guest_config->num_vifs;
 
+    ret = libxl__domain_create_info_setdefaults(gc, &dm_config.c_info);
+    if (ret) goto out;
+
     libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, &vfb, &vkb);
     dm_config.vfbs = &vfb;
     dm_config.num_vfbs = 1;
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/libxl_internal.h      Fri Jan 13 16:00:00 2012 +0000
@@ -224,6 +224,15 @@ typedef struct {
     char *saved_state;
 } libxl__domain_build_state;
 
+/*
+ * Idempotently set the defaults for various user provided data structures.
+ *
+ * All libxl API functions are expected to have arranged for this to
+ * be called before using any values within these structures.
+ */
+int libxl__domain_create_info_setdefaults(libxl__gc *gc,
+                                          libxl_domain_create_info *c_info);
+
 _hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,
               libxl_domain_build_info *info, libxl__domain_build_state *state);
 _hidden int libxl__build_post(libxl__gc *gc, uint32_t domid,
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/libxl_types.idl       Fri Jan 13 16:00:00 2012 +0000
@@ -180,8 +180,8 @@ libxl_version_info = Struct("version_inf
 
 libxl_domain_create_info = Struct("domain_create_info",[
     ("type",         libxl_domain_type),
-    ("hap",          bool),
-    ("oos",          bool),
+    ("hap",          libxl_defbool),
+    ("oos",          libxl_defbool),
     ("ssidref",      uint32),
     ("name",         string),
     ("uuid",         libxl_uuid),
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Fri Jan 13 16:00:00 2012 +0000
@@ -300,8 +300,8 @@ static void printf_info(int domid,
     printf("(domain\n\t(domid %d)\n", domid);
     printf("\t(create_info)\n");
     printf("\t(hvm %d)\n", c_info->type == LIBXL_DOMAIN_TYPE_HVM);
-    printf("\t(hap %d)\n", c_info->hap);
-    printf("\t(oos %d)\n", c_info->oos);
+    printf("\t(hap %s)\n", libxl_defbool_to_string(c_info->hap));
+    printf("\t(oos %s)\n", libxl_defbool_to_string(c_info->oos));
     printf("\t(ssidref %d)\n", c_info->ssidref);
     printf("\t(name %s)\n", c_info->name);
 
@@ -614,8 +614,7 @@ static void parse_config_data(const char
         !strncmp(buf, "hvm", strlen(buf)))
         c_info->type = LIBXL_DOMAIN_TYPE_HVM;
 
-    if (!xlu_cfg_get_long (config, "hap", &l, 0))
-        c_info->hap = l;
+    xlu_cfg_get_defbool(config, "hap", &c_info->hap, 0);
 
     if (xlu_cfg_replace_string (config, "name", &c_info->name, 0)) {
         fprintf(stderr, "Domain name must be specified.");
@@ -631,8 +630,7 @@ static void parse_config_data(const char
         libxl_uuid_generate(&c_info->uuid);
     }
 
-    if (!xlu_cfg_get_long(config, "oos", &l, 0))
-        c_info->oos = l;
+    xlu_cfg_get_defbool(config, "oos", &c_info->oos, 0);
 
     if (!xlu_cfg_get_string (config, "pool", &buf, 0)) {
         c_info->poolid = -1;
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/python/genwrap.py
--- a/tools/python/genwrap.py   Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/python/genwrap.py   Fri Jan 13 16:00:00 2012 +0000
@@ -4,11 +4,13 @@ import sys,os
 
 import libxltypes
 
-(TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = range(5)
+(TYPE_DEFBOOL, TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = 
range(6)
 
 def py_type(ty):
     if ty == libxltypes.bool:
         return TYPE_BOOL
+    if ty.typename == "libxl_defbool":
+        return TYPE_DEFBOOL
     if isinstance(ty, libxltypes.Enumeration):
         return TYPE_UINT
     if isinstance(ty, libxltypes.Number):
@@ -44,6 +46,8 @@ def py_decls(ty):
         for f in ty.fields:
             if py_type(f.type) is not None:
                 continue
+            if py_type(f.type) == TYPE_DEFBOOL:
+                continue
             if ty.marshal_out():
                 l.append('_hidden PyObject *attrib__%s_get(%s *%s);'%(\
                     fsanitize(f.type.typename), f.type.typename, f.name))
@@ -62,6 +66,8 @@ def py_attrib_get(ty, f):
         l.append('    ret = (self->obj.%s) ? Py_True : Py_False;'%f.name)
         l.append('    Py_INCREF(ret);')
         l.append('    return ret;')
+    elif t == TYPE_DEFBOOL:
+        l.append('    return genwrap__defbool_get(&self->obj.%s);'%f.name)
     elif t == TYPE_INT:
         l.append('    return genwrap__ll_get(self->obj.%s);'%f.name)
     elif t == TYPE_UINT:
@@ -85,6 +91,8 @@ def py_attrib_set(ty, f):
     if t == TYPE_BOOL:
         l.append('    self->obj.%s = (NULL == v || Py_None == v || Py_False == 
v) ? 0 : 1;'%f.name)
         l.append('    return 0;')
+    elif t == TYPE_DEFBOOL:
+        l.append('    return genwrap__defbool_set(v, &self->obj.%s);'%f.name)
     elif t == TYPE_UINT or t == TYPE_INT:
         l.append('    %slong long tmp;'%(t == TYPE_UINT and 'unsigned ' or ''))
         l.append('    int ret;')
@@ -276,6 +284,8 @@ _hidden PyObject *genwrap__ull_get(unsig
 _hidden int genwrap__ull_set(PyObject *v, unsigned long long *val, unsigned 
long long mask);
 _hidden PyObject *genwrap__ll_get(long long val);
 _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask);
+_hidden PyObject *genwrap__defbool_get(libxl_defbool *db);
+_hidden int genwrap__defbool_set(PyObject *v, libxl_defbool *db);
 
 """ % " ".join(sys.argv))
     for ty in [ty for ty in types if isinstance(ty, libxltypes.Aggregate)]:
diff -r 7e9f3ce2cd1f -r 87c469583499 tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c Fri Jan 13 15:59:59 2012 +0000
+++ b/tools/python/xen/lowlevel/xl/xl.c Fri Jan 13 16:00:00 2012 +0000
@@ -156,6 +156,21 @@ int genwrap__ll_set(PyObject *v, long lo
     return 0;
 }
 
+PyObject *genwrap__defbool_get(libxl_defbool *db)
+{
+    PyObject *ret;
+    ret = libxl_defbool_val(*db) ? Py_True : Py_False;
+    Py_INCREF(ret);
+    return ret;
+}
+
+int genwrap__defbool_set(PyObject *v, libxl_defbool *db)
+{
+    bool val = !(NULL == v || Py_None == v || Py_False == v);
+    libxl_defbool_set(db, val);
+    return 0;
+}
+
 static int fixed_bytearray_set(PyObject *v, uint8_t *ptr, size_t len)
 {
     char *tmp;

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.