Skip to contentSkip to conversation

Refactor libxl domain creation, v2

PATCH New Gianni Tedesco 4 participants 15 messages Jan 5, 2011 – Jan 7, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Refactor libxl domain creation, v2

Introduce libxl_domain_create_new() and libxl_domain_create_restore() rendering redundant several other, more complex, API's and simplifying the xl create implementation.

Also included patch implementing flexarray_append(), it's kind of unrelated but it's in my queue and based on top of the prior patches in the series. :)

Changes since v1:
- fix re-base mixup wrt. libxl_need_xenpv_qemu()
- always return 0 on success from do_domain_create()
- add patch to move dm functions to libxl_dm.c
- add the flexarray_append() patcho

Gianni

#1 lore raw

PATCH 1/1 xl: idl: Abolish keyed union types

 tools/libxl/gentypes.py        |  10 +----
 tools/libxl/libxl.c            |  44 +++++++++++-----------
 tools/libxl/libxl.idl          |  42 ++++++++++-----------
 tools/libxl/libxl_bootloader.c |  30 +++++++-------
 tools/libxl/libxl_dom.c        |  32 ++++++++--------
 tools/libxl/libxltypes.py      |  15 -------
 tools/libxl/xl_cmdimpl.c       |  80 +++++++++++++++++++++---------------------
 tools/ocaml/libs/xl/xl_stubs.c |  26 ++++++------
 8 files changed, 127 insertions(+), 152 deletions(-)

# HG changeset patch
# User Gianni Tedesco <[email protected]> # Date 1294231757 0
# Node ID 5a8c843ab94a38df32e5f9dc042619a439c6f124 # Parent 39194f457534e07e5d5cc54376c4df28e0acb63c
xl: idl: Abolish keyed union types

Since the IDL file has become useful for generating language bindings it has become apparent that the KeyedUnion type has no straightforward translation to scripting languages which have no notion of unions.

Turns out this is only used in domain_build_info which is hardly a memory criticial structure.

This patch simply abolishes the notion replacing it in domain_build_info with hvm and pv structures and renaming the key to 'is_hvm'.

tools/libxl/gentypes.py +1 -9
diff -r 39194f457534 -r 5a8c843ab94a tools/libxl/gentypes.py
@@ -71,15 +71,7 @@ def libxl_C_type_destroy(ty, v, referenc
         makeref = ""
 
     s = ""
-    if isinstance(ty, libxltypes.KeyedUnion):
-        if parent is None:
-            raise Exception("KeyedUnion type must have a parent")
-        for f in ty.fields:
-            keyvar_expr = f.keyvar_expr % (parent + ty.keyvar_name)
-            s += "if (" + keyvar_expr + ") {\n"
-            s += libxl_C_type_destroy(f.type, deref + f.name, False, indent + "    ", deref)
-            s += "}\n"
-    elif isinstance(ty, libxltypes.Reference):
+    if isinstance(ty, libxltypes.Reference):
         s += libxl_C_type_destroy(ty.ref_type, v, True, indent, v)
         if ty.destructor_fn is not None:
             s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
tools/libxl/libxl.c +22 -22

111 lines not on this page · raw message

tools/libxl/libxl.idl +20 -22

48 lines not on this page · raw message

tools/libxl/libxl_bootloader.c +15 -15
diff -r 39194f457534 -r 5a8c843ab94a tools/libxl/libxl_bootloader.c
@@ -42,23 +42,23 @@ static char **make_bootloader_args(libxl
     if (!args)
         return NULL;
 
-    flexarray_set(args, nr++, (char *)info->u.pv.bootloader);
+    flexarray_set(args, nr++, (char *)info->pv.bootloader);
 
     if (info->kernel.path)
         flexarray_set(args, nr++, libxl__sprintf(gc, "--kernel=%s", info->kernel.path));
-    if (info->u.pv.ramdisk.path)
-        flexarray_set(args, nr++, libxl__sprintf(gc, "--ramdisk=%s", info->u.pv.ramdisk.path));
-    if (info->u.pv.cmdline && *info->u.pv.cmdline != '\0')
-        flexarray_set(args, nr++, libxl__sprintf(gc, "--args=%s", info->u.pv.cmdline));
+    if (info->pv.ramdisk.path)
+        flexarray_set(args, nr++, libxl__sprintf(gc, "--ramdisk=%s", info->pv.ramdisk.path));
+    if (info->pv.cmdline && *info->pv.cmdline != '\0')
+        flexarray_set(args, nr++, libxl__sprintf(gc, "--args=%s", info->pv.cmdline));
 
     flexarray_set(args, nr++, libxl__sprintf(gc, "--output=%s", fifo));
     flexarray_set(args, nr++, "--output-format=simple0");
     flexarray_set(args, nr++, libxl__sprintf(gc, "--output-directory=%s", "/var/run/libxl/"));
 
-    if (info->u.pv.bootloader_args) {
+    if (info->pv.bootloader_args) {
         char *saveptr;
         /* Operate on a duplicate since strtok modifes the argument */
-        char *dup = libxl__strdup(gc, info->u.pv.bootloader_args);
+        char *dup = libxl__strdup(gc, info->pv.bootloader_args);
         char *t = strtok_r(dup, " \t\n", &saveptr);
         do {
             flexarray_set(args, nr++, t);
@@ -282,13 +282,13 @@ static void parse_bootloader_result(libx
             libxl__file_reference_map(&info->kernel);
             unlink(info->kernel.path);
         } else if (strncmp("ramdisk ", o, strlen("ramdisk ")) == 0) {
-            free(info->u.pv.ramdisk.path);
-            info->u.pv.ramdisk.path = strdup(o + strlen("ramdisk "));
-            libxl__file_reference_map(&info->u.pv.ramdisk);
-            unlink(info->u.pv.ramdisk.path);
+            free(info->pv.ramdisk.path);
+            info->pv.ramdisk.path = strdup(o + strlen("ramdisk "));
+            libxl__file_reference_map(&info->pv.ramdisk);
+            unlink(info->pv.ramdisk.path);
         } else if (strncmp("args ", o, strlen("args ")) == 0) {
-            free(info->u.pv.cmdline);
-            info->u.pv.cmdline = strdup(o + strlen("args "));
+            free(info->pv.cmdline);
+            info->pv.cmdline = strdup(o + strlen("args "));
         }
 
         o = o + strlen(o) + 1;
@@ -321,7 +321,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
 
     struct stat st_buf;
 
-    if (info->hvm || !info->u.pv.bootloader)
+    if (info->is_hvm || !info->pv.bootloader)
         goto out;
 
     rc = ERROR_INVAL;
@@ -386,7 +386,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
     dom_console_xs_path = libxl__sprintf(&gc, "%s/console/tty", libxl__xs_get_dompath(&gc, domid));
     libxl__xs_write(&gc, XBT_NULL, dom_console_xs_path, "%s", dom_console_slave_tty_path);
 
-    pid = fork_exec_bootloader(&bootloader_fd, info->u.pv.bootloader, args);
+    pid = fork_exec_bootloader(&bootloader_fd, info->pv.bootloader, args);
     if (pid < 0) {
         goto out_close;
     }
tools/libxl/libxl_dom.c +16 -16
diff -r 39194f457534 -r 5a8c843ab94a tools/libxl/libxl_dom.c
@@ -70,13 +70,13 @@ int libxl__build_pre(libxl_ctx *ctx, uin
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
     xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
     xc_domain_set_memmap_limit(ctx->xch, domid, 
-            (info->hvm) ? info->max_memkb : 
-            (info->max_memkb + info->u.pv.slack_memkb));
+            (info->is_hvm) ? info->max_memkb : 
+            (info->max_memkb + info->pv.slack_memkb));
     xc_domain_set_tsc_info(ctx->xch, domid, info->tsc_mode, 0, 0, 0);
     if ( info->disable_migrate )
         xc_domain_disable_migrate(ctx->xch, domid);
 
-    if (info->hvm) {
+    if (info->is_hvm) {
         unsigned long shadow;
         shadow = (info->shadow_memkb + 1023) / 1024;
         xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow, 0, NULL);
@@ -152,7 +152,7 @@ int libxl__build_pv(libxl_ctx *ctx, uint
 
     xc_dom_loginit(ctx->xch);
 
-    dom = xc_dom_allocate(ctx->xch, info->u.pv.cmdline, info->u.pv.features);
+    dom = xc_dom_allocate(ctx->xch, info->pv.cmdline, info->pv.features);
     if (!dom) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_allocate failed");
         return ERROR_FAIL;
@@ -170,14 +170,14 @@ int libxl__build_pv(libxl_ctx *ctx, uint
         }
     }
 
-    if ( info->u.pv.ramdisk.path && strlen(info->u.pv.ramdisk.path) ) {
-        if (info->u.pv.ramdisk.mapped) {
-            if ( (ret = xc_dom_ramdisk_mem(dom, info->u.pv.ramdisk.data, info->u.pv.ramdisk.size)) != 0 ) {
+    if ( info->pv.ramdisk.path && strlen(info->pv.ramdisk.path) ) {
+        if (info->pv.ramdisk.mapped) {
+            if ( (ret = xc_dom_ramdisk_mem(dom, info->pv.ramdisk.data, info->pv.ramdisk.size)) != 0 ) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_ramdisk_mem failed");
                 goto out;
             }
         } else {
-            if ( (ret = xc_dom_ramdisk_file(dom, info->u.pv.ramdisk.path)) != 0 ) {
+            if ( (ret = xc_dom_ramdisk_file(dom, info->pv.ramdisk.path)) != 0 ) {
                 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_ramdisk_file failed");
                 goto out;
             }
@@ -238,8 +238,8 @@ static int hvm_build_set_params(xc_inter
         return -1;
 
     va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
-    va_hvm->acpi_enabled = info->u.hvm.acpi;
-    va_hvm->apic_mode = info->u.hvm.apic;
+    va_hvm->acpi_enabled = info->hvm.acpi;
+    va_hvm->apic_mode = info->hvm.apic;
     va_hvm->nr_vcpus = info->max_vcpus;
     memcpy(va_hvm->vcpu_online, &info->cur_vcpus, sizeof(info->cur_vcpus));
     for (i = 0, sum = 0; i < va_hvm->length; i++)
@@ -249,13 +249,13 @@ static int hvm_build_set_params(xc_inter
 
     xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn);
     xc_get_hvm_param(handle, domid, HVM_PARAM_CONSOLE_PFN, console_mfn);
-    xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, info->u.hvm.pae);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, info->hvm.pae);
 #if defined(__i386__) || defined(__x86_64__)
-    xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, info->u.hvm.viridian);
-    xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) info->u.hvm.hpet);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, info->hvm.viridian);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) info->hvm.hpet);
 #endif
-    xc_set_hvm_param(handle, domid, HVM_PARAM_TIMER_MODE, (unsigned long) info->u.hvm.timer_mode);
-    xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, (unsigned long) info->u.hvm.vpt_align);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_TIMER_MODE, (unsigned long) info->hvm.timer_mode);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, (unsigned long) info->hvm.vpt_align);
     xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
     xc_set_hvm_param(handle, domid, HVM_PARAM_CONSOLE_EVTCHN, console_evtchn);
     return 0;
@@ -305,7 +305,7 @@ int libxl__domain_restore_common(libxl_c
     rc = xc_domain_restore(ctx->xch, fd, domid,
                              state->store_port, &state->store_mfn,
                              state->console_port, &state->console_mfn,
-                             info->hvm, info->u.hvm.pae, 0);
+                             info->is_hvm, info->hvm.pae, 0);
     if ( rc ) {
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "restoring domain");
         return ERROR_FAIL;
tools/libxl/libxltypes.py +0 -15
diff -r 39194f457534 -r 5a8c843ab94a tools/libxl/libxltypes.py
@@ -104,21 +104,6 @@ class Union(Aggregate):
         kwargs.setdefault('destructor_fn', None)
         Aggregate.__init__(self, "union", name, fields, **kwargs)
 
-class KeyedUnion(Aggregate):
-    """A union which is keyed of another variable in the parent structure"""
-    def __init__(self, name, keyvar_name, fields, **kwargs):
-        Aggregate.__init__(self, "union", name, [], **kwargs)
-
-        self.keyvar_name = keyvar_name
-
-        for f in fields:
-            # (name, keyvar_expr, type)
-
-            # keyvar_expr must contain exactly one %s which will be replaced with the keyvar_name
-
-            n, kve, ty = f
-            self.fields.append(Field(ty, n, keyvar_expr=kve))
-
 class Reference(Type):
     """A reference to another type"""
     def __init__(self, ty, **kwargs):
tools/libxl/xl_cmdimpl.c +40 -40

135 lines not on this page · raw message

tools/ocaml/libs/xl/xl_stubs.c +13 -13
diff -r 39194f457534 -r 5a8c843ab94a tools/ocaml/libs/xl/xl_stubs.c
@@ -166,20 +166,20 @@ static int domain_build_info_val (caml_g
 	c_val->hvm = Tag_val(Field(v, 7)) == 0;
 	infopriv = Field(Field(v, 7), 0);
 	if (c_val->hvm) {
-		c_val->u.hvm.pae = Bool_val(Field(infopriv, 0));
-		c_val->u.hvm.apic = Bool_val(Field(infopriv, 1));
-		c_val->u.hvm.acpi = Bool_val(Field(infopriv, 2));
-		c_val->u.hvm.nx = Bool_val(Field(infopriv, 3));
-		c_val->u.hvm.viridian = Bool_val(Field(infopriv, 4));
-		c_val->u.hvm.timeoffset = dup_String_val(gc, Field(infopriv, 5));
-		c_val->u.hvm.timer_mode = Int_val(Field(infopriv, 6));
-		c_val->u.hvm.hpet = Int_val(Field(infopriv, 7));
-		c_val->u.hvm.vpt_align = Int_val(Field(infopriv, 8));
+		c_val->hvm.pae = Bool_val(Field(infopriv, 0));
+		c_val->hvm.apic = Bool_val(Field(infopriv, 1));
+		c_val->hvm.acpi = Bool_val(Field(infopriv, 2));
+		c_val->hvm.nx = Bool_val(Field(infopriv, 3));
+		c_val->hvm.viridian = Bool_val(Field(infopriv, 4));
+		c_val->hvm.timeoffset = dup_String_val(gc, Field(infopriv, 5));
+		c_val->hvm.timer_mode = Int_val(Field(infopriv, 6));
+		c_val->hvm.hpet = Int_val(Field(infopriv, 7));
+		c_val->hvm.vpt_align = Int_val(Field(infopriv, 8));
 	} else {
-		c_val->u.pv.slack_memkb = Int64_val(Field(infopriv, 0));
-		c_val->u.pv.cmdline = dup_String_val(gc, Field(infopriv, 1));
-		c_val->u.pv.ramdisk.path = dup_String_val(gc, Field(infopriv, 2));
-		c_val->u.pv.features = dup_String_val(gc, Field(infopriv, 3));
+		c_val->pv.slack_memkb = Int64_val(Field(infopriv, 0));
+		c_val->pv.cmdline = dup_String_val(gc, Field(infopriv, 1));
+		c_val->pv.ramdisk.path = dup_String_val(gc, Field(infopriv, 2));
+		c_val->pv.features = dup_String_val(gc, Field(infopriv, 3));
 	}
 
 	CAMLreturn(0);
#2 lore raw

Re: [PATCH 1 of 4] xl: idl: Abolish keyed union types

Gianni Tedesco writes ("[Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed union types"):

Quoted 6 lines

xl: idl: Abolish keyed union types

Since the IDL file has become useful for generating language bindings it has become apparent that the KeyedUnion type has no straightforward translation to scripting languages which have no notion of unions.

Uhh? Most scripting languages' aggregate types are practically nothing _but_ unions!

The correct translation of a keyed union would probably be an aggregate (eg, in Python, a dictionary) containing an entry for the key and entries for whatever version of the union it involved.

Quoted 2 lines

Turns out this is only used in domain_build_info which is hardly a memory criticial structure.

However I don't have a strong opinion about the desirability of using a tagged union for this particular structure.

Ian.

#3 lore raw

Re: [PATCH 1 of 4] xl: idl: Abolish keyed union types

Quoted 8 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed union types"):

Quoted 6 lines

xl: idl: Abolish keyed union types

Since the IDL file has become useful for generating language bindings it has become apparent that the KeyedUnion type has no straightforward translation to scripting languages which have no notion of unions.

Quoted 6 lines

Uhh? Most scripting languages' aggregate types are practically nothing _but_ unions!

The correct translation of a keyed union would probably be an aggregate (eg, in Python, a dictionary) containing an entry for the key and entries for whatever version of the union it involved.

The union type ends up looking quite nice in the ocaml bindings too:

type build_spec = BuildHVM of build_hvm_info | BuildPV of build_pv_info

which allows nice ocaml idiomatic stuff like

        match build with
        | BuildHVM hvm -> do_some_hvm_stuff hvm
        | BuildPV pv -> do_some_pv_stuff pv
Quoted 5 lines
Quoted 2 lines

Turns out this is only used in domain_build_info which is hardly a memory criticial structure.

However I don't have a strong opinion about the desirability of using a tagged union for this particular structure.

Me neither.

That ocaml stuff currently hand coded (and no one is imminently working on changing that to my knowledge) so I don't think the libxl API change arising from this IDL change prevents retaining this interface but it does suggest why having the notion of a key which selects between alternative fields could be a semantically useful concept in the interface.

If having KeyedStruct instead of KeyedUnion simplifies things that could be an alternative. Or go the whole hog and define a Dict type (turns into an enum + the relevant number of fields)? Or just nuke it and cross the bridge when we come to it ;-).

Ian.

#4 lore raw

Re: [PATCH 1 of 4] xl: idl: Abolish keyed union types

In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed union types"):

Quoted 6 lines

xl: idl: Abolish keyed union types

Since the IDL file has become useful for generating language bindings it has become apparent that the KeyedUnion type has no straightforward translation to scripting languages which have no notion of unions.

Uhh? Most scripting languages' aggregate types are practically nothing _but_ unions!

Not really sure I follow this.

Quoted 3 lines

The correct translation of a keyed union would probably be an aggregate (eg, in Python, a dictionary) containing an entry for the key and entries for whatever version of the union it involved.

Hrm, I don't think we can easily do it this way. We create full fledged python types to correspond to the C types currently. Probably the more natural construction for unions would be basically the C equivalent of:

class Foo:

	def __init__(self):
		self.__hidden = xl.thing_pv()
	def __getattr__(self, k):
		return self.__hidden.__getattr__(k)
	def __setattr__(self, k, v):
		if k == 'hvm':
			if v:
				self.__hidden = xl.thing_hvm()
				# copy all attributes from before
			elif v:
				self.__hidden = xl.thing_pv()
				# copy all attributes from before
		return self.__hidden.__setattr__(k, v)

so that:
x = Foo()
x.pv_thing = True
x.pv_thing
>>> True
x.hvm = True
x.pv_thing
>>> Exception: AttributeError
x.hvm_thing = 'thing'

In other words, frob the getter/setter table whenever the key is set. I could probably implement this if required as a pre-requisite for the rest of the series but it may take a day or two.

Alternatively, I have some further patches to do with the Python binding which does some more sophisticated stuff and I could re-introduce the KeyedUnion later?

Quoted 5 lines
Quoted 2 lines

Turns out this is only used in domain_build_info which is hardly a memory criticial structure.

However I don't have a strong opinion about the desirability of using a tagged union for this particular structure.

Hence my casualness in abolishing it.

Gianni

#5 lore raw

PATCH 1/1 xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

In reply to Gianni Tedesco
 tools/libxl/Makefile           |    4 +-
 tools/libxl/libxl.c            |  286 +----------------------
 tools/libxl/libxl.h            |   62 +++--
 tools/libxl/libxl_create.c     |  482 +++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_exec.c       |    2 +-
 tools/libxl/libxl_internal.h   |   29 ++-
 tools/libxl/xl_cmdimpl.c       |  328 ++++++---------------------
 tools/ocaml/libs/xl/xl_stubs.c |   85 +------
 8 files changed, 657 insertions(+), 621 deletions(-)

# HG changeset patch
# User Gianni Tedesco <[email protected]>
# Date 1294231811 0
# Node ID c6e3c9a8029db76295c5a3c2c4abc77ce9da5cae
# Parent 5a8c843ab94a38df32e5f9dc042619a439c6f124
xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

These functions are introduced as the new way to create domains with libxl they prevent the callers from needing to know about low-level implementation details such as:
- libxl_domain_make()
- libxl_domain_build()
- libxl_domain_restore()
- when to attach the console
- how to start the device model

Above mentioned functions and all API's for the device model, which are now redundant, have been made internal to libxl and no longer accessible.

The ocaml binding for libxl has not been properly updated to reflect the changes, wrappers for the old functions have been removed but the code to wrap the new functions has not been added.

tools/libxl/Makefile +2 -2
diff -r 5a8c843ab94a -r c6e3c9a8029d tools/libxl/Makefile
@@ -20,7 +20,7 @@ ifeq ($(CONFIG_Linux),y)
 LIBS += -luuid
 endif
 
-LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
+LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o
 ifeq ($(LIBXL_BLKTAP),y)
 LIBXL_OBJS-y += libxl_blktap2.o
 else
@@ -29,7 +29,7 @@ endif
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o
 LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o
 
-LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
+LIBXL_OBJS = libxl.o libxl_create.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
tools/libxl/libxl.c +22 -264

394 lines not on this page · raw message

tools/libxl/libxl.h +36 -26

80 lines not on this page · raw message

tools/libxl/libxl_create.c new file +482 -0

482 lines not on this page · raw message

tools/libxl/libxl_exec.c +1 -1
diff -r 5a8c843ab94a -r c6e3c9a8029d tools/libxl/libxl_exec.c
@@ -90,7 +90,7 @@ void libxl_report_child_exitstatus(libxl
 }
 
 int libxl__spawn_spawn(libxl_ctx *ctx,
-                      libxl_device_model_starting *starting,
+                      libxl__device_model_starting *starting,
                       const char *what,
                       void (*intermediate_hook)(void *for_spawn,
                                                 pid_t innerchild))
tools/libxl/libxl_internal.h +26 -3
diff -r 5a8c843ab94a -r c6e3c9a8029d tools/libxl/libxl_internal.h
@@ -194,14 +194,37 @@ typedef struct {
     char *what; /* malloc'd in spawn_spawn */
 } libxl__spawn_starting;
 
-struct libxl__device_model_starting {
+typedef struct {
     libxl__spawn_starting *for_spawn; /* first! */
     char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
     int domid;
-};
+} libxl__device_model_starting;
+
+/* from xl_create */
+_hidden int libxl__domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
+_hidden int libxl__domain_build(libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
+
+/* for device model creation */
+_hidden int libxl__create_device_model(libxl_ctx *ctx,
+                              libxl_device_model_info *info,
+                              libxl_device_disk *disk, int num_disks,
+                              libxl_device_nic *vifs, int num_vifs,
+                              libxl__device_model_starting **starting_r);
+_hidden int libxl__create_xenpv_qemu(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
+                            libxl__device_model_starting **starting_r);
+_hidden int libxl__need_xenpv_qemu(libxl_ctx *ctx,
+        int nr_consoles, libxl_device_console *consoles,
+        int nr_vfbs, libxl_device_vfb *vfbs,
+        int nr_disks, libxl_device_disk *disks);
+
+  /* Caller must either: pass starting_r==0, or on successful
+   * return pass *starting_r (which will be non-0) to
+   * libxl_confirm_device_model or libxl_detach_device_model. */
+_hidden int libxl__confirm_device_model_startup(libxl_ctx *ctx,
+                              libxl__device_model_starting *starting);
 
 _hidden int libxl__spawn_spawn(libxl_ctx *ctx,
-                      libxl_device_model_starting *starting,
+                      libxl__device_model_starting *starting,
                       const char *what,
                       void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
   /* Logs errors.  A copy of "what" is taken.  Return values:
tools/libxl/xl_cmdimpl.c +75 -253

480 lines not on this page · raw message

tools/ocaml/libs/xl/xl_stubs.c +13 -72

121 lines not on this page · raw message

#6 lore raw

Re: [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

Gianni Tedesco writes ("[Xen-devel] [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()"):

Quoted 1 line

xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

This patch looks reasonable to me - at least, the API seems sensible to me. I didn't diff all of the shuffled-about code :-).

I'll wait for an ack from Stefano too though.

Ian.

#7 lore raw

Re: [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

Quoted 7 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()"):

Quoted 1 line

xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

This patch looks reasonable to me - at least, the API seems sensible to me. I didn't diff all of the shuffled-about code :-).

I'll wait for an ack from Stefano too though.

Thanks.

I think the patch is overall correct but please make sure to test it with stubdoms at least once.
Also I think we need to move all the init_*_info functions to libxl too, in order to provide sensible defaults for libxl_domain_config *d_config.

#8 lore raw

Re: [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 2 of 4] xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()"):

Quoted 1 line

xl: Introduce libxl_domain_create_new() and libxl_domain_create_restore()

This patch looks reasonable to me - at least, the API seems sensible to me. I didn't diff all of the shuffled-about code :-).

Quoted 6 lines
Quoted 1 line

I'll wait for an ack from Stefano too though.

Thanks.

I think the patch is overall correct but please make sure to test it with stubdoms at least once.

OK, I'll do a thorough round of testing before submitting next version. I may have found an error in there anyway but I need to chase that one down to be sure.

Quoted 2 lines

Also I think we need to move all the init_*_info functions to libxl too, in order to provide sensible defaults for libxl_domain_config *d_config.

Yeah, I just realised that last night. To be honest there's a lot of duplicated fields in those structures so that they may be better off being re-organised somehow anyway. I'll see what I can come up with.

Gianni

#9 lore raw

PATCH 1/1 xl: Move device model functions in to a separate file

In reply to Gianni Tedesco
 tools/libxl/Makefile         |    2 +-
 tools/libxl/libxl.c          |  807 +-----------------------------------------
 tools/libxl/libxl_dm.c       |  831 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |    2 +
 4 files changed, 836 insertions(+), 806 deletions(-)

# HG changeset patch
# User Gianni Tedesco <[email protected]> # Date 1294231842 0
# Node ID 2f8749c5e015463317f4c81e71d23be52bec4e06 # Parent c6e3c9a8029db76295c5a3c2c4abc77ce9da5cae
xl: Move device model functions in to a separate file

No functional changes.

tools/libxl/Makefile +1 -1
diff -r c6e3c9a8029d -r 2f8749c5e015 tools/libxl/Makefile
@@ -29,7 +29,7 @@ endif
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o
 LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o
 
-LIBXL_OBJS = libxl.o libxl_create.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
+LIBXL_OBJS = libxl.o libxl_create.o libxl_dm.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
tools/libxl/libxl.c +2 -805

831 lines not on this page · raw message

tools/libxl/libxl_dm.c new file +831 -0

831 lines not on this page · raw message

tools/libxl/libxl_internal.h +2 -0
diff -r c6e3c9a8029d -r 2f8749c5e015 tools/libxl/libxl_internal.h
@@ -227,6 +227,8 @@ _hidden int libxl__spawn_spawn(libxl_ctx
                       libxl__device_model_starting *starting,
                       const char *what,
                       void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
+_hidden int libxl__destroy_device_model(libxl_ctx *ctx, uint32_t domid);
+
   /* Logs errors.  A copy of "what" is taken.  Return values:
    *  < 0   error, for_spawn need not be detached
    *   +1   caller is the parent, must call detach on *for_spawn eventually
#10 lore raw

Re: [PATCH 3 of 4] xl: Move device model functions in to a separate file [and 1 more messages]

Gianni Tedesco writes ("[Xen-devel] [PATCH 3 of 4] xl: Move device model functions in to a separate file"):

Quoted 1 line

xl: Move device model functions in to a separate file

Gianni Tedesco writes ("[Xen-devel] [PATCH 4 of 4] xl: Implement flexarray_append() and flexarray_vappend()"):

Quoted 1 line

xl: Implement flexarray_append() and flexarray_vappend()

These are very sensible rearrangements, well done. I'll apply them as soon as the earlier parts of the series go in, or if you prefer you can repost versions of 3 and 4 as a new 2-part series to go in right away.

Thanks,
Ian.

#11 lore raw

Re: [PATCH 3 of 4] xl: Move device model functions in to a separate file [and 1 more messages]

Quoted 10 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 3 of 4] xl: Move device model functions in to a separate file"):

Quoted 1 line

xl: Move device model functions in to a separate file

Gianni Tedesco writes ("[Xen-devel] [PATCH 4 of 4] xl: Implement flexarray_append() and flexarray_vappend()"):

Quoted 1 line

xl: Implement flexarray_append() and flexarray_vappend()

These are very sensible rearrangements, well done. I'll apply them as soon as the earlier parts of the series go in, or if you prefer you can repost versions of 3 and 4 as a new 2-part series to go in right away.

OK, I'll wait on your response to other questions but maybe it should be re-orderd anyway:

1. move dm functions around
2. flexarray append
3. create_domain()

--

Other python-binding and idl stuff to follow in a future series.

Gianni

#12 lore raw

Re: [PATCH 3 of 4] xl: Move device model functions in to a separate file [and 1 more messages]

Gianni Tedesco writes ("Re: [Xen-devel] [PATCH 3 of 4] xl: Move device model functions in to a separate file [and 1 more messages]"):

Quoted 6 lines · Ian Jackson
Quoted 4 lines

These are very sensible rearrangements, well done. I'll apply them as soon as the earlier parts of the series go in, or if you prefer you can repost versions of 3 and 4 as a new 2-part series to go in right away.

Quoted 6 lines

OK, I'll wait on your response to other questions but maybe it should be re-orderd anyway:

1. move dm functions around
2. flexarray append
3. create_domain()

That would be fine by me.

Ian.

#13 lore raw

PATCH 1/1 xl: Implement flexarray_append() and flexarray_vappend()

In reply to Gianni Tedesco
 tools/libxl/flexarray.c |   24 +++
 tools/libxl/flexarray.h |    3 +
 tools/libxl/libxl.c     |  341 ++++++++++++++++++++++-------------------------
 tools/libxl/libxl_dm.c  |  180 ++++++++++--------------
 tools/libxl/libxl_pci.c |   73 +++------
 5 files changed, 292 insertions(+), 329 deletions(-)

# HG changeset patch
# User Gianni Tedesco <[email protected]> # Date 1294231910 0
# Node ID 3feb91094abba05f5fd735717de7316101ea6c27 # Parent 2f8749c5e015463317f4c81e71d23be52bec4e06
xl: Implement flexarray_append() and flexarray_vappend()

Makes a lot of code simpler and nice and saves a fair amount of screen real-estate

tools/libxl/flexarray.c +24 -0
diff -r 2f8749c5e015 -r 3feb91094abb tools/libxl/flexarray.c
@@ -14,6 +14,7 @@
  */
 
 #include "libxl_internal.h"
+#include <stdarg.h>
 
 flexarray_t *flexarray_make(int size, int autogrow)
 {
@@ -21,6 +22,7 @@ flexarray_t *flexarray_make(int size, in
     if (array) {
         array->size = size;
         array->autogrow = autogrow;
+        array->count = 0;
         array->data = calloc(size, sizeof(void *));
     }
     return array;
@@ -56,10 +58,32 @@ int flexarray_set(flexarray_t *array, un
         if (flexarray_grow(array, newsize - array->size))
             return 2;
     }
+    if ( index + 1 > array->count )
+        array->count = index + 1;
     array->data[index] = ptr;
     return 0;
 }
 
+int flexarray_append(flexarray_t *array, void *ptr)
+{
+    return flexarray_set(array, array->count, ptr);
+}
+
+int flexarray_vappend(flexarray_t *array, ...)
+{
+    va_list va;
+    void *ptr;
+    int ret;
+
+    va_start(va, array);
+    for(ret = 0; (ptr = va_arg(va, void *)); ret++) {
+        if ( flexarray_append(array, ptr) )
+            break;
+    }
+    va_end(va);
+    return ret;
+}
+
 int flexarray_get(flexarray_t *array, int index, void **ptr)
 {
     if (index >= array->size)
tools/libxl/flexarray.h +3 -0
diff -r 2f8749c5e015 -r 3feb91094abb tools/libxl/flexarray.h
@@ -19,6 +19,7 @@
 typedef struct flexarray {
     int size;
     int autogrow;
+    unsigned int count;
     void **data; /* array of pointer */
 } flexarray_t;
 
@@ -26,6 +27,8 @@ _hidden flexarray_t *flexarray_make(int 
 _hidden void flexarray_free(flexarray_t *array);
 _hidden int flexarray_grow(flexarray_t *array, int extents);
 _hidden int flexarray_set(flexarray_t *array, unsigned int index, void *ptr);
+_hidden int flexarray_append(flexarray_t *array, void *ptr);
+_hidden int flexarray_vappend(flexarray_t *array, ...);
 _hidden int flexarray_get(flexarray_t *array, int index, void **ptr);
 
 _hidden void **flexarray_contents(flexarray_t *array);
tools/libxl/libxl.c +162 -179

440 lines not on this page · raw message

tools/libxl/libxl_dm.c +75 -105

356 lines not on this page · raw message

tools/libxl/libxl_pci.c +28 -45

109 lines not on this page · raw message

#14 lore raw

Re: [PATCH 4 of 4] xl: Implement flexarray_append() and flexarray_vappend()

tools/libxl/libxl.c int libxl_device_disk_add(libxl_ctx *ctx · line 922

Quoted 5 lines · Gianni Tedesco
tools/libxl/libxl.c +0 -1
@@ -919,35 +919,35 @@ int libxl_device_disk_add(libxl_ctx *ctx
             goto out_free;
     }
 
-    flexarray_set(back, boffset++, "frontend-id");

This stuff is erroneous because boffset needs removing!

Will fix this for next go around.

Gianni