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

[Xen-devel] [PATCH v2 02/21] libxl: introduce a way to mark fields as deprecated in the idl



The deprecation involves generating a function that copies the
deprecated fields into it's new location if the new location has not
been set.

The fields that are going to be shared between PVH and HVM or between
PVH and PV are moved to the top level of libxl_domain_build_info, and
the old locations are marked as deprecated.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Changes since v1:
 - New in this version.
---
 tools/libxl/gentypes.py     | 56 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/idl.py          |  2 ++
 tools/libxl/libxl_types.idl | 17 +++++++++-----
 3 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 4ea7091e6b..c2d34bcd30 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -261,6 +261,47 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""):
         s = indent + s
     return s.replace("\n", "\n%s" % indent).rstrip(indent)
 
+def libxl_C_type_copy_deprecated(field, v, indent = "    ", vparent = None):
+    s = ""
+
+    if isinstance(field.type, idl.KeyedUnion):
+        if vparent is None:
+            raise Exception("KeyedUnion type must have a parent")
+        s += "switch (%s) {\n" % (vparent + field.type.keyvar.name)
+        for f in [f for f in field.type.fields if not f.const]:
+            (vnparent,vfexpr) = ty.member(v, f, vparent is None)
+            s += "case %s:\n" % f.enumname
+            if f.type is not None:
+                s += libxl_C_type_copy_deprecated(f, vfexpr, indent, vnparent)
+            s+= "    break;\n"
+        s+="}\n";
+    elif isinstance(field.type, idl.Array) and field.deprecated_by:
+        raise Exception("Array type is not supported for deprecation")
+    elif isinstance(field.type, idl.Struct) and field.type.copy_fn is None:
+        for f in [f for f in field.type.fields if not f.const]:
+            (vnparent,vfexpr) = ty.member(v, f, vparent is None)
+            s += libxl_C_type_copy_deprecated(f, vfexpr, "", vnparent)
+    elif field.deprecated_by is not None:
+        if field.type.check_default_fn is None:
+            raise Exception("Deprecated field %s type doesn't have a default 
value checker" % field.name)
+        field_val = field.type.pass_arg(v, vparent is None,
+                                        passby=idl.PASS_BY_VALUE)
+        field_ptr = field.type.pass_arg(v, vparent is None,
+                                        passby=idl.PASS_BY_REFERENCE)
+
+        s+= "if (%s(&p->%s))\n" % (field.type.check_default_fn,
+                                   field.deprecated_by)
+        s+= "    "
+        if field.type.copy_fn is not None:
+            s += "%s(ctx, &p->%s, %s);\n" % (field.type.copy_fn,
+                                             field.deprecated_by, field_ptr)
+        else:
+            s += "p->%s = %s;\n" % (field.deprecated_by, field_val)
+
+    if s != "":
+        s = indent + s
+    return s.replace("\n", "\n%s" % indent).rstrip(indent)
+
 def get_init_val(f):
     if f.init_val is not None:
         return f.init_val
@@ -543,6 +584,10 @@ if __name__ == '__main__':
         f.write(libxl_C_type_define(ty) + ";\n")
         if ty.dispose_fn is not None:
             f.write("%svoid %s(%s);\n" % (ty.hidden(), ty.dispose_fn, 
ty.make_arg("p")))
+        if ty.copy_deprecated_fn is not None:
+            f.write("%sint %s(libxl_ctx *ctx, %s);\n" % (ty.hidden(),
+                                                         ty.copy_deprecated_fn,
+                                                         ty.make_arg("p")))
         if ty.copy_fn is not None:
             f.write("%svoid %s(libxl_ctx *ctx, %s, const %s);\n" % 
(ty.hidden(), ty.copy_fn,
                                               ty.make_arg("dst"), 
ty.make_arg("src")))
@@ -657,6 +702,17 @@ if __name__ == '__main__':
         f.write("}\n")
         f.write("\n")
         
+    for ty in [t for t in types if t.copy_deprecated_fn]:
+        f.write("int %s(libxl_ctx *ctx, %s)\n" % (ty.copy_deprecated_fn,
+            ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)))
+        f.write("{\n")
+        for field in [field for field in ty.fields if not field.const]:
+            (vnparent,vfexpr) = ty.member("p", field, True)
+            f.write(libxl_C_type_copy_deprecated(field, vfexpr, vparent = 
vnparent))
+        f.write("    return 0;\n")
+        f.write("}\n")
+        f.write("\n")
+
     for ty in [t for t in types if t.init_fn is not None and 
t.autogenerate_init_fn]:
         f.write(libxl_C_type_init(ty))
         for field in libxl_init_members(ty):
diff --git a/tools/libxl/idl.py b/tools/libxl/idl.py
index a4a084e1ce..687cb8c2ec 100644
--- a/tools/libxl/idl.py
+++ b/tools/libxl/idl.py
@@ -72,6 +72,7 @@ class Type(object):
         self.autogenerate_init_fn = kwargs.setdefault('autogenerate_init_fn', 
False)
 
         self.check_default_fn = kwargs.setdefault('check_default_fn', None)
+        self.copy_deprecated_fn = kwargs.setdefault('copy_deprecated_fn', None)
 
         if self.typename is not None and not self.private:
             self.json_gen_fn = kwargs.setdefault('json_gen_fn', self.typename 
+ "_gen_json")
@@ -193,6 +194,7 @@ class Field(object):
         self.const = kwargs.setdefault('const', False)
         self.enumname = kwargs.setdefault('enumname', None)
         self.init_val = kwargs.setdefault('init_val', None)
+        self.deprecated_by = kwargs.setdefault('deprecated_by', None)
 
 class Aggregate(Type):
     """A type containing a collection of other types"""
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 267c4f3804..fe82d683b4 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -507,11 +507,16 @@ libxl_domain_build_info = Struct("domain_build_info",[
     # 65000 which is reserved by the toolstack.
     ("device_tree",      string),
     ("acpi",             libxl_defbool),
+    ("bootloader",       string),
+    ("bootloader_args",  libxl_string_list),
+    ("timer_mode",       libxl_timer_mode),
+    ("nested_hvm",       libxl_defbool),
+    ("apic",             libxl_defbool),
     ("u", KeyedUnion(None, libxl_domain_type, "type",
                 [("hvm", Struct(None, [("firmware",         string),
                                        ("bios",             libxl_bios_type),
                                        ("pae",              libxl_defbool),
-                                       ("apic",             libxl_defbool),
+                                       ("apic",             libxl_defbool, 
{'deprecated_by': 'apic'}),
                                        # The following acpi field is 
deprecated.
                                        # Please use the unified acpi field 
above
                                        # which works for both x86 and ARM.
@@ -527,8 +532,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                        ("hpet",             libxl_defbool),
                                        ("vpt_align",        libxl_defbool),
                                        ("mmio_hole_memkb",  MemKB),
-                                       ("timer_mode",       libxl_timer_mode),
-                                       ("nested_hvm",       libxl_defbool),
+                                       ("timer_mode",       libxl_timer_mode, 
{'deprecated_by': 'timer_mode'}),
+                                       ("nested_hvm",       libxl_defbool, 
{'deprecated_by': 'nested_hvm'}),
                                        # The u.hvm.altp2m field is used solely
                                        # for x86 HVM guests and is maintained
                                        # for legacy purposes.
@@ -569,8 +574,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                        ])),
                  ("pv", Struct(None, [("kernel", string),
                                       ("slack_memkb", MemKB),
-                                      ("bootloader", string),
-                                      ("bootloader_args", libxl_string_list),
+                                      ("bootloader", string, {'deprecated_by': 
'bootloader'}),
+                                      ("bootloader_args", libxl_string_list, 
{'deprecated_by': 'bootloader_args'}),
                                       ("cmdline", string),
                                       ("ramdisk", string),
                                       ("features", string, {'const': True}),
@@ -587,7 +592,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
     # supported by x86 HVM and ARM support is planned.
     ("altp2m", libxl_altp2m_mode),
 
-    ], dir=DIR_IN
+    ], dir=DIR_IN, 
copy_deprecated_fn="libxl__domain_build_info_copy_deprecated"
 )
 
 libxl_device_vfb = Struct("device_vfb", [
-- 
2.11.0 (Apple Git-81)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

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