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

Re: [Xen-devel] [PATCH 3 of 9] libxl: remove libxl_button_press in favour of libxl_send_trigger



On Wed, 2012-01-25 at 17:24 +0000, Ian Campbell wrote:
> # HG changeset patch
> # User Ian Campbell <ian.campbell@xxxxxxxxxx>
> # Date 1327510508 0
> # Node ID a7776e38447d4e633a45b926295f7923c046fbc9
> # Parent  b9973edc7528e5233698fefd234be19dd6d6bcee
> libxl: remove libxl_button_press in favour of libxl_send_trigger.
> 
> send_trigger already included all the operations covered by button_press.
> 
> Rework send_trigger to take an enum instead of a string.
> 
> I stopped short at removing the xl "button-press" command but instead have
> marked it as deprecated.
> 
> Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

V2: update messages from xl destroy/reboot when no PV mechanism is
present.

8<-------------------------------------------------------------

# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1327510508 0
# Node ID a7776e38447d4e633a45b926295f7923c046fbc9
# Parent  b9973edc7528e5233698fefd234be19dd6d6bcee
libxl: remove libxl_button_press in favour of libxl_send_trigger.

send_trigger already included all the operations covered by button_press.

Rework send_trigger to take an enum instead of a string.

I stopped short at removing the xl "button-press" command but instead have
marked it as deprecated.

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

diff -r b9973edc7528 -r a7776e38447d docs/man/xl.pod.1
--- a/docs/man/xl.pod.1 Wed Jan 25 16:55:08 2012 +0000
+++ b/docs/man/xl.pod.1 Wed Jan 25 16:55:08 2012 +0000
@@ -86,6 +86,8 @@ previously, most commands take I<domain-
 
 =item B<button-press> I<domain-id> I<button>
 
+I<This command is deprecated. Please use C<xl trigger> in preference>
+
 Indicate an ACPI button press to the domain. I<button> is may be 'power' or
 'sleep'. This command is only available for HVM domains.
 
@@ -448,7 +450,7 @@ It can be used to send SysRq requests to
 your Linux Kernel sources for more information.
 It requires PV drivers to be installed in your guest OS.
 
-=item B<trigger> I<domain-id> I<nmi|reset|init|power|sleep> [I<VCPU>]
+=item B<trigger> I<domain-id> I<nmi|reset|init|power|sleep|s3resume> [I<VCPU>]
 
 Send a trigger to a domain, where the trigger can be: nmi, reset, init, power
 or sleep.  Optionally a specific vcpu number can be passed as an argument.
diff -r b9973edc7528 -r a7776e38447d tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py   Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/libxl/gentypes.py   Wed Jan 25 16:55:08 2012 +0000
@@ -32,6 +32,9 @@ def libxl_C_type_define(ty, indent = "")
             s += "} %s" % ty.typename
 
     elif isinstance(ty, idl.Aggregate):
+        if isinstance(ty, idl.KeyedUnion):
+            s += libxl_C_instance_of(ty.keyvar_type, ty.keyvar_name) + ";\n"
+            
         if ty.typename is None:
             s += "%s {\n" % ty.kind
         else:
diff -r b9973edc7528 -r a7776e38447d tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/libxl/libxl.c       Wed Jan 25 16:55:08 2012 +0000
@@ -2477,24 +2477,6 @@ out:
     return 0;
 }
 
-int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button)
-{
-    int rc = -1;
-
-    switch (button) {
-    case LIBXL_BUTTON_POWER:
-        rc = xc_domain_send_trigger(ctx->xch, domid, 
XEN_DOMCTL_SENDTRIGGER_POWER, 0);
-        break;
-    case LIBXL_BUTTON_SLEEP:
-        rc = xc_domain_send_trigger(ctx->xch, domid, 
XEN_DOMCTL_SENDTRIGGER_SLEEP, 0);
-        break;
-    default:
-        break;
-    }
-
-    return rc;
-}
-
 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
 {
     xc_physinfo_t xcphysinfo = { 0 };
@@ -2876,44 +2858,46 @@ int libxl_sched_sedf_domain_set(libxl_ct
     return 0;
 }
 
-static int trigger_type_from_string(char *trigger_name)
+int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
+                       libxl_trigger trigger, uint32_t vcpuid)
 {
-    if (!strcmp(trigger_name, "nmi"))
-        return XEN_DOMCTL_SENDTRIGGER_NMI;
-    else if (!strcmp(trigger_name, "reset"))
-        return XEN_DOMCTL_SENDTRIGGER_RESET;
-    else if (!strcmp(trigger_name, "init"))
-        return XEN_DOMCTL_SENDTRIGGER_INIT;
-    else if (!strcmp(trigger_name, "power"))
-        return XEN_DOMCTL_SENDTRIGGER_POWER;
-    else if (!strcmp(trigger_name, "sleep"))
-        return XEN_DOMCTL_SENDTRIGGER_SLEEP;
-    else
-        return -1;
-}
-
-int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid, char *trigger_name, 
uint32_t vcpuid)
-{
-    int rc = -1;
-    int trigger_type = -1;
-
-    if (!strcmp(trigger_name, "s3resume")) {
+    int rc;
+
+    switch (trigger) {
+    case LIBXL_TRIGGER_POWER:
+        rc = xc_domain_send_trigger(ctx->xch, domid,
+                                    XEN_DOMCTL_SENDTRIGGER_POWER, vcpuid);
+        break;
+    case LIBXL_TRIGGER_SLEEP:
+        rc = xc_domain_send_trigger(ctx->xch, domid,
+                                    XEN_DOMCTL_SENDTRIGGER_SLEEP, vcpuid);
+        break;
+    case LIBXL_TRIGGER_NMI:
+        rc = xc_domain_send_trigger(ctx->xch, domid,
+                                    XEN_DOMCTL_SENDTRIGGER_NMI, vcpuid);
+        break;
+    case LIBXL_TRIGGER_INIT:
+        rc = xc_domain_send_trigger(ctx->xch, domid,
+                                    XEN_DOMCTL_SENDTRIGGER_INIT, vcpuid);
+        break;
+    case LIBXL_TRIGGER_RESET:
+        rc = xc_domain_send_trigger(ctx->xch, domid,
+                                    XEN_DOMCTL_SENDTRIGGER_RESET, vcpuid);
+        break;
+    case LIBXL_TRIGGER_S3RESUME:
         xc_set_hvm_param(ctx->xch, domid, HVM_PARAM_ACPI_S_STATE, 0);
-        return 0;
+        rc = 0;
+        break;
+    default:
+        rc = EINVAL;
+        break;
     }
 
-    trigger_type = trigger_type_from_string(trigger_name);
-    if (trigger_type == -1) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, -1,
-            "Invalid trigger, valid triggers are 
<nmi|reset|init|power|sleep>");
-        return ERROR_INVAL;
-    }
-
-    rc = xc_domain_send_trigger(ctx->xch, domid, trigger_type, vcpuid);
     if (rc != 0) {
         LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Send trigger '%s' failed", trigger_name);
-        return ERROR_FAIL;
+                            "Send trigger '%s' failed",
+                            libxl_trigger_to_string(trigger));
+        rc = ERROR_FAIL;
     }
 
     return 0;
diff -r b9973edc7528 -r a7776e38447d tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/libxl/libxl.h       Wed Jan 25 16:55:08 2012 +0000
@@ -547,8 +547,6 @@ int libxl_userdata_retrieve(libxl_ctx *c
    * On error return, *data_r and *datalen_r are undefined.
    */
 
-int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button);
-
 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
 int libxl_get_topologyinfo(libxl_ctx *ctx, libxl_topologyinfo *info);
 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
@@ -573,7 +571,7 @@ int libxl_sched_sedf_domain_get(libxl_ct
 int libxl_sched_sedf_domain_set(libxl_ctx *ctx, uint32_t domid,
                                 libxl_sched_sedf *scinfo);
 int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
-                       char *trigger_name, uint32_t vcpuid);
+                       libxl_trigger trigger, uint32_t vcpuid);
 int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq);
 int libxl_send_debug_keys(libxl_ctx *ctx, char *keys);
 
diff -r b9973edc7528 -r a7776e38447d tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/libxl/libxl_types.idl       Wed Jan 25 16:55:08 2012 +0000
@@ -80,9 +80,14 @@ libxl_event_type = Enumeration("event_ty
     (2, "DISK_EJECT"),
     ])
 
-libxl_button = Enumeration("button", [
+libxl_trigger = Enumeration("trigger", [
+    (0, "UNKNOWN"),
     (1, "POWER"),
     (2, "SLEEP"),
+    (3, "NMI"),
+    (4, "INIT"),
+    (5, "RESET"),
+    (6, "S3RESUME"),
     ])
 
 libxl_tsc_mode = Enumeration("tsc_mode", [
@@ -203,7 +208,6 @@ libxl_domain_build_info = Struct("domain
     ("shadow_memkb",    uint32),
     ("disable_migrate", bool),
     ("cpuid",           libxl_cpuid_policy_list),
-    ("type",            libxl_domain_type),
     
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", bool),
diff -r b9973edc7528 -r a7776e38447d tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Wed Jan 25 16:55:08 2012 +0000
@@ -3318,26 +3318,29 @@ int main_create(int argc, char **argv)
 
 static void button_press(const char *p, const char *b)
 {
-    libxl_button button;
+    libxl_trigger trigger;
 
     find_domain(p);
 
     if (!strcmp(b, "power")) {
-        button = LIBXL_BUTTON_POWER;
+        trigger = LIBXL_TRIGGER_POWER;
     } else if (!strcmp(b, "sleep")) {
-        button = LIBXL_BUTTON_SLEEP;
+        trigger = LIBXL_TRIGGER_SLEEP;
     } else {
         fprintf(stderr, "%s is an invalid button identifier\n", b);
         exit(2);
     }
 
-    libxl_button_press(ctx, domid, button);
+    libxl_send_trigger(ctx, domid, trigger, 0);
 }
 
 int main_button_press(int argc, char **argv)
 {
     int opt;
 
+    fprintf(stderr, "WARNING: \"button-press\" is deprecated. "
+            "Please use \"trigger\"\n");
+
     if ((opt = def_getopt(argc, argv, "", "button-press", 2)) != -1)
         return opt;
 
@@ -4322,10 +4325,11 @@ int main_rename(int argc, char **argv)
 int main_trigger(int argc, char **argv)
 {
     int opt;
-    char *trigger_name = NULL;
     char *endptr = NULL;
     const char *dom = NULL;
     int vcpuid = 0;
+    const char *trigger_name = NULL;
+    libxl_trigger trigger;
 
     if ((opt = def_getopt(argc, argv, "", "trigger", 2)) != -1)
         return opt;
@@ -4335,6 +4339,10 @@ int main_trigger(int argc, char **argv)
     find_domain(dom);
 
     trigger_name = argv[optind++];
+    if (libxl_trigger_from_string(trigger_name, &trigger)) {
+        fprintf(stderr, "Invalid trigger \"%s\"\n", trigger_name);
+        return -1;
+    }
 
     if (argv[optind]) {
         vcpuid = strtol(argv[optind], &endptr, 10);
@@ -4343,7 +4351,7 @@ int main_trigger(int argc, char **argv)
         }
     }
 
-    libxl_send_trigger(ctx, domid, trigger_name, vcpuid);
+    libxl_send_trigger(ctx, domid, trigger, vcpuid);
 
     return 0;
 }
diff -r b9973edc7528 -r a7776e38447d tools/ocaml/libs/xl/xenlight.ml.in
--- a/tools/ocaml/libs/xl/xenlight.ml.in        Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight.ml.in        Wed Jan 25 16:55:08 2012 +0000
@@ -29,10 +29,8 @@ module Topologyinfo = struct
        external get : unit -> t = "stub_xl_topologyinfo"
 end
 
-external button_press : domid -> button -> unit = "stub_xl_button_press"
 
-
-external send_trigger : domid -> string -> int -> unit = "stub_xl_send_trigger"
+external send_trigger : domid -> trigger -> int -> unit = 
"stub_xl_send_trigger"
 external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
 
diff -r b9973edc7528 -r a7776e38447d tools/ocaml/libs/xl/xenlight.mli.in
--- a/tools/ocaml/libs/xl/xenlight.mli.in       Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight.mli.in       Wed Jan 25 16:55:08 2012 +0000
@@ -29,8 +29,6 @@ module Topologyinfo : sig
        external get : unit -> t = "stub_xl_topologyinfo"
 end
 
-external button_press : domid -> button -> unit = "stub_xl_button_press"
-
-external send_trigger : domid -> string -> int -> unit = "stub_xl_send_trigger"
+external send_trigger : domid -> trigger -> int -> unit = 
"stub_xl_send_trigger"
 external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
diff -r b9973edc7528 -r a7776e38447d tools/ocaml/libs/xl/xenlight_stubs.c
--- a/tools/ocaml/libs/xl/xenlight_stubs.c      Wed Jan 25 16:55:08 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c      Wed Jan 25 16:55:08 2012 +0000
@@ -432,21 +432,6 @@ value stub_xl_device_pci_remove(value in
        CAMLreturn(Val_unit);
 }
 
-value stub_xl_button_press(value domid, value button)
-{
-       CAMLparam2(domid, button);
-       int ret;
-       INIT_STRUCT();
-
-       INIT_CTX();
-       ret = libxl_button_press(ctx, Int_val(domid), Int_val(button) + 
LIBXL_BUTTON_POWER);
-       if (ret != 0)
-               failwith_xl("button_press", &lg);
-       FREE_CTX();
-
-       CAMLreturn(Val_unit);
-}
-
 value stub_xl_physinfo_get(value unit)
 {
        CAMLparam1(unit);
@@ -523,10 +508,10 @@ value stub_xl_send_trigger(value domid, 
 {
        CAMLparam3(domid, trigger, vcpuid);
        int ret;
-       char *c_trigger;
+       libxl_trigger c_trigger = LIBXL_TRIGGER_UNKNOWN;
        INIT_STRUCT();
 
-       c_trigger = dup_String_val(&gc, trigger);
+       trigger_val(&gc, &lg, &c_trigger, trigger);
 
        INIT_CTX();
        ret = libxl_send_trigger(ctx, Int_val(domid), c_trigger, 
Int_val(vcpuid));



_______________________________________________
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®.