tools/ocaml: Pass a full domctl_create_config into stub_xc_domain_create()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 12 Mar 2018 10:40:33 +0000 (10:40 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 15 Aug 2018 18:40:28 +0000 (19:40 +0100)
The underlying C function is about to make the same change, and the structure
is going to gain extra fields.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/libs/xc/xenctrl.ml
tools/ocaml/libs/xc/xenctrl.mli
tools/ocaml/libs/xc/xenctrl_stubs.c

index b3b33bb327d42b5fecd68214d70a1c32d2977ddc..3b7526e4ae8f9cafa7796afe6fa72bdbd70cf756 100644 (file)
@@ -56,6 +56,16 @@ type arch_domainconfig =
        | ARM of xen_arm_arch_domainconfig
        | X86 of xen_x86_arch_domainconfig
 
+type domain_create_flag = CDF_HVM | CDF_HAP
+
+type domctl_create_config =
+{
+       ssidref: int32;
+       handle: string;
+       flags: domain_create_flag list;
+       arch: arch_domainconfig;
+}
+
 type domaininfo =
 {
        domid             : domid;
@@ -120,8 +130,6 @@ type compile_info =
 
 type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
 
-type domain_create_flag = CDF_HVM | CDF_HAP
-
 exception Error of string
 
 type handle
@@ -135,7 +143,7 @@ let with_intf f =
        interface_close xc;
        r
 
-external domain_create: handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
+external domain_create: handle -> domctl_create_config -> domid
        = "stub_xc_domain_create"
 
 external domain_sethandle: handle -> domid -> string -> unit
index 35303ab61a11f322c2fe92b1866c1d114d77df31..d103a33ee8b79c28796ab4dd95ae193bdae9b9ef 100644 (file)
@@ -49,6 +49,15 @@ type arch_domainconfig =
   | ARM of xen_arm_arch_domainconfig
   | X86 of xen_x86_arch_domainconfig
 
+type domain_create_flag = CDF_HVM | CDF_HAP
+
+type domctl_create_config = {
+  ssidref: int32;
+  handle: string;
+  flags: domain_create_flag list;
+  arch: arch_domainconfig;
+}
+
 type domaininfo = {
   domid : domid;
   dying : bool;
@@ -91,14 +100,12 @@ type compile_info = {
 }
 type shutdown_reason = Poweroff | Reboot | Suspend | Crash | Watchdog | Soft_reset
 
-type domain_create_flag = CDF_HVM | CDF_HAP
-
 exception Error of string
 type handle
 external interface_open : unit -> handle = "stub_xc_interface_open"
 external interface_close : handle -> unit = "stub_xc_interface_close"
 val with_intf : (handle -> 'a) -> 'a
-external domain_create : handle -> int32 -> domain_create_flag list -> string -> arch_domainconfig -> domid
+external domain_create : handle -> domctl_create_config -> domid
   = "stub_xc_domain_create"
 external domain_sethandle : handle -> domid -> string -> unit = "stub_xc_domain_sethandle"
 external domain_max_vcpus : handle -> domid -> int -> unit
index 5274e56bce2f602700fbf8ddf566a484b8e06ed4..b8ec2393025ece9e3cb6d9f5ec1a2b9f3fd5f567 100644 (file)
@@ -119,36 +119,46 @@ static void domain_handle_of_uuid_string(xen_domain_handle_t h,
 #undef X
 }
 
-CAMLprim value stub_xc_domain_create(value xch, value ssidref,
-                                     value flags, value handle,
-                                     value domconfig)
+CAMLprim value stub_xc_domain_create(value xch, value config)
 {
-       CAMLparam4(xch, ssidref, flags, handle);
+       CAMLparam2(xch, config);
+       CAMLlocal2(l, arch_domconfig);
+
+       /* Mnemonics for the named fields inside domctl_create_config */
+#define VAL_SSIDREF             Field(config, 0)
+#define VAL_HANDLE              Field(config, 1)
+#define VAL_FLAGS               Field(config, 2)
+#define VAL_ARCH                Field(config, 3)
 
        uint32_t domid = 0;
-       xen_domain_handle_t h;
        int result;
-       uint32_t c_ssidref = Int32_val(ssidref);
-       unsigned int c_flags = 0;
-       value l;
-       xc_domain_configuration_t config = {};
+       struct xen_domctl_createdomain cfg = {
+               .ssidref = Int32_val(VAL_SSIDREF),
+       };
 
-       domain_handle_of_uuid_string(h, String_val(handle));
+       domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
 
-       for (l = flags; l != Val_none; l = Field(l, 1))
-               c_flags |= 1u << Int_val(Field(l, 0));
+       for ( l = VAL_FLAGS; l != Val_none; l = Field(l, 1) )
+               cfg.flags |= 1u << Int_val(Field(l, 0));
 
-       switch(Tag_val(domconfig)) {
+       arch_domconfig = Field(VAL_ARCH, 0);
+       switch ( Tag_val(VAL_ARCH) )
+       {
        case 0: /* ARM - nothing to do */
                caml_failwith("Unhandled: ARM");
                break;
 
        case 1: /* X86 - emulation flags in the block */
 #if defined(__i386__) || defined(__x86_64__)
-               for (l = Field(Field(domconfig, 0), 0);
-                    l != Val_none;
-                    l = Field(l, 1))
-                       config.emulation_flags |= 1u << Int_val(Field(l, 0));
+
+        /* Mnemonics for the named fields inside xen_x86_arch_domainconfig */
+#define VAL_EMUL_FLAGS          Field(arch_domconfig, 0)
+
+               for ( l = VAL_EMUL_FLAGS; l != Val_none; l = Field(l, 1) )
+                       cfg.arch.emulation_flags |= 1u << Int_val(Field(l, 0));
+
+#undef VAL_EMUL_FLAGS
+
 #else
                caml_failwith("Unhandled: x86");
 #endif
@@ -158,8 +168,14 @@ CAMLprim value stub_xc_domain_create(value xch, value ssidref,
                caml_failwith("Unhandled domconfig type");
        }
 
+#undef VAL_ARCH
+#undef VAL_FLAGS
+#undef VAL_HANDLE
+#undef VAL_SSIDREF
+
        caml_enter_blocking_section();
-       result = xc_domain_create(_H(xch), c_ssidref, h, c_flags, &domid, &config);
+       result = xc_domain_create(_H(xch), cfg.ssidref, cfg.handle, cfg.flags,
+                                 &domid, &cfg.arch);
        caml_leave_blocking_section();
 
        if (result < 0)