]> xenbits.xensource.com Git - xen.git/commitdiff
lsevtchn: Simple tool to list event channel states for a domain.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 9 Apr 2008 15:11:34 +0000 (16:11 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 9 Apr 2008 15:11:34 +0000 (16:11 +0100)
Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
.hgignore
tools/libxc/xc_evtchn.c
tools/libxc/xenctrl.h
tools/xcutils/Makefile
tools/xcutils/lsevtchn.c [new file with mode: 0644]

index 4f4b84aa923832aa703413a052d763ec098e15d5..591347187109204144df5d291b98c6743883edb1 100644 (file)
--- a/.hgignore
+++ b/.hgignore
 ^tools/vtpm/tpm_emulator/.*$
 ^tools/vtpm/vtpm/.*$
 ^tools/vtpm_manager/manager/vtpm_managerd$
+^tools/xcutils/lsevtchn$
 ^tools/xcutils/xc_restore$
 ^tools/xcutils/xc_save$
 ^tools/xcutils/readnotes$
index 0992a7bdbb66bcc0abbc1b82c51fe85ad52d9ccc..5e1ca265025aad665820a022b1417c9c7162dcde 100644 (file)
@@ -9,7 +9,8 @@
 #include "xc_private.h"
 
 
-static int do_evtchn_op(int xc_handle, int cmd, void *arg, size_t arg_size)
+static int do_evtchn_op(int xc_handle, int cmd, void *arg,
+                        size_t arg_size, int silently_fail)
 {
     int ret = -1;
     DECLARE_HYPERCALL;
@@ -24,7 +25,7 @@ static int do_evtchn_op(int xc_handle, int cmd, void *arg, size_t arg_size)
         goto out;
     }
 
-    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
+    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 && !silently_fail)
         ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
 
     unlock_pages(arg, arg_size);
@@ -44,7 +45,7 @@ xc_evtchn_alloc_unbound(int xc_handle,
         .remote_dom = (domid_t)remote_dom
     };
 
-    rc = do_evtchn_op(xc_handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg));
+    rc = do_evtchn_op(xc_handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg), 0);
     if ( rc == 0 )
         rc = arg.port;
 
@@ -55,5 +56,20 @@ int xc_evtchn_reset(int xc_handle,
                     uint32_t dom)
 {
     struct evtchn_reset arg = { .dom = (domid_t)dom };
-    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg));
+    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg), 0);
+}
+
+int xc_evtchn_status(int xc_handle,
+                     uint32_t dom,
+                     uint32_t port)
+{
+    int rc;
+    struct evtchn_status arg = { .dom = (domid_t)dom,
+                                 .port = (evtchn_port_t)port };
+
+    rc = do_evtchn_op(xc_handle, EVTCHNOP_status, &arg, sizeof(arg), 1);
+    if ( rc == 0 )
+        rc = arg.status;
+
+    return rc;
 }
index 8eb3f5ef6fa5f5930782251e092a8ddfed7fbdad..8bd5fb4fb82690893286fefad8fc5d96be489427 100644 (file)
@@ -470,6 +470,9 @@ xc_evtchn_alloc_unbound(int xc_handle,
 
 int xc_evtchn_reset(int xc_handle,
                     uint32_t dom);
+int xc_evtchn_status(int xc_handle,
+                     uint32_t dom,
+                     uint32_t port);
 
 /*
  * Return a handle to the event channel driver, or -1 on failure, in which case
index d38e8ac07da3c9f668d14d472da4d91207eed100..15c0c9758ef698a160edef05257fd4647a4951e3 100644 (file)
@@ -18,7 +18,7 @@ CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
 CFLAGS += -Wp,-MD,.$(@F).d
 PROG_DEP = .*.d
 
-PROGRAMS = xc_restore xc_save readnotes
+PROGRAMS = xc_restore xc_save readnotes lsevtchn
 
 LDLIBS   = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
 
diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c
new file mode 100644 (file)
index 0000000..3dc3cb3
--- /dev/null
@@ -0,0 +1,59 @@
+#include <err.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <xs.h>
+#include <xenctrl.h>
+#include <xenguest.h>
+
+int
+main(int argc, char **argv)
+{
+    int xc_fd;
+    int domid = 0, port = 0, status;
+    const char *msg;
+
+    if ( argc > 1 )
+        domid = strtol(argv[1], NULL, 10);
+
+    xc_fd = xc_interface_open();
+    if ( xc_fd < 0 )
+        errx(1, "failed to open control interface");
+
+    while ( (status = xc_evtchn_status(xc_fd, domid, port)) >= 0 )
+    {
+        switch ( status )
+        {
+        case EVTCHNSTAT_closed:
+            msg = "Channel is not in use.";
+            break;
+        case EVTCHNSTAT_unbound:
+            msg = "Channel is waiting interdom connection.";
+            break;
+        case EVTCHNSTAT_interdomain:
+            msg = "Channel is connected to remote domain.";
+            break;
+        case EVTCHNSTAT_pirq:
+            msg = "Channel is bound to a phys IRQ line.";
+            break;
+        case EVTCHNSTAT_virq:
+            msg = "Channel is bound to a virtual IRQ line.";
+            break;
+        case EVTCHNSTAT_ipi:
+            msg = "Channel is bound to a virtual IPI line.";
+            break;
+        default:
+            msg = "Unknown.";
+            break;
+
+        }
+        printf("%03d: %d: %s\n", port, status, msg);
+        port++;
+    }
+
+    xc_interface_close(xc_fd);
+
+    return 0;
+}