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

[Xen-changelog] [xen-unstable] libxl: remove libxl_button_press in favour of libxl_send_trigger.



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1328027679 0
# Node ID 44ee4d37384faf3c7129545a5c4e067f28ec04e5
# Parent  a322bdbd43deaa67fbe1c4072fee38a797f51923
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>
Acked-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---


diff -r a322bdbd43de -r 44ee4d37384f docs/man/xl.pod.1
--- a/docs/man/xl.pod.1 Tue Jan 31 16:34:39 2012 +0000
+++ b/docs/man/xl.pod.1 Tue Jan 31 16:34:39 2012 +0000
@@ -86,6 +86,8 @@
 
 =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.
 
@@ -461,7 +463,7 @@
 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 a322bdbd43de -r 44ee4d37384f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/libxl/libxl.c       Tue Jan 31 16:34:39 2012 +0000
@@ -2728,24 +2728,6 @@
     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 };
@@ -3144,44 +3126,46 @@
     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 a322bdbd43de -r 44ee4d37384f tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/libxl/libxl.h       Tue Jan 31 16:34:39 2012 +0000
@@ -575,8 +575,6 @@
    * 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,
@@ -603,7 +601,7 @@
 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 a322bdbd43de -r 44ee4d37384f tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/libxl/libxl_types.idl       Tue Jan 31 16:34:39 2012 +0000
@@ -75,9 +75,14 @@
     (6, "COREDUMP_RESTART"),
     ])
 
-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", [
diff -r a322bdbd43de -r 44ee4d37384f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Tue Jan 31 16:34:39 2012 +0000
@@ -3465,26 +3465,29 @@
 
 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;
 
@@ -4512,10 +4515,11 @@
 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;
@@ -4525,6 +4529,10 @@
     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);
@@ -4533,7 +4541,7 @@
         }
     }
 
-    libxl_send_trigger(ctx, domid, trigger_name, vcpuid);
+    libxl_send_trigger(ctx, domid, trigger, vcpuid);
 
     return 0;
 }
diff -r a322bdbd43de -r 44ee4d37384f tools/ocaml/libs/xl/xenlight.ml.in
--- a/tools/ocaml/libs/xl/xenlight.ml.in        Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight.ml.in        Tue Jan 31 16:34:39 2012 +0000
@@ -29,10 +29,8 @@
        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 a322bdbd43de -r 44ee4d37384f tools/ocaml/libs/xl/xenlight.mli.in
--- a/tools/ocaml/libs/xl/xenlight.mli.in       Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight.mli.in       Tue Jan 31 16:34:39 2012 +0000
@@ -29,8 +29,6 @@
        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 a322bdbd43de -r 44ee4d37384f tools/ocaml/libs/xl/xenlight_stubs.c
--- a/tools/ocaml/libs/xl/xenlight_stubs.c      Tue Jan 31 16:34:39 2012 +0000
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c      Tue Jan 31 16:34:39 2012 +0000
@@ -432,21 +432,6 @@
        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 @@
 {
        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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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