ia64/xen-unstable

changeset 17424:64f81cd158d4

lsevtchn: Simple tool to list event channel states for a domain.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 09 16:11:34 2008 +0100 (2008-04-09)
parents 5ffd167d7772
children c99dee5e44d6
files .hgignore tools/libxc/xc_evtchn.c tools/libxc/xenctrl.h tools/xcutils/Makefile tools/xcutils/lsevtchn.c
line diff
     1.1 --- a/.hgignore	Wed Apr 09 16:04:10 2008 +0100
     1.2 +++ b/.hgignore	Wed Apr 09 16:11:34 2008 +0100
     1.3 @@ -199,6 +199,7 @@
     1.4  ^tools/vtpm/tpm_emulator/.*$
     1.5  ^tools/vtpm/vtpm/.*$
     1.6  ^tools/vtpm_manager/manager/vtpm_managerd$
     1.7 +^tools/xcutils/lsevtchn$
     1.8  ^tools/xcutils/xc_restore$
     1.9  ^tools/xcutils/xc_save$
    1.10  ^tools/xcutils/readnotes$
     2.1 --- a/tools/libxc/xc_evtchn.c	Wed Apr 09 16:04:10 2008 +0100
     2.2 +++ b/tools/libxc/xc_evtchn.c	Wed Apr 09 16:11:34 2008 +0100
     2.3 @@ -9,7 +9,8 @@
     2.4  #include "xc_private.h"
     2.5  
     2.6  
     2.7 -static int do_evtchn_op(int xc_handle, int cmd, void *arg, size_t arg_size)
     2.8 +static int do_evtchn_op(int xc_handle, int cmd, void *arg,
     2.9 +                        size_t arg_size, int silently_fail)
    2.10  {
    2.11      int ret = -1;
    2.12      DECLARE_HYPERCALL;
    2.13 @@ -24,7 +25,7 @@ static int do_evtchn_op(int xc_handle, i
    2.14          goto out;
    2.15      }
    2.16  
    2.17 -    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
    2.18 +    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 && !silently_fail)
    2.19          ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
    2.20  
    2.21      unlock_pages(arg, arg_size);
    2.22 @@ -44,7 +45,7 @@ xc_evtchn_alloc_unbound(int xc_handle,
    2.23          .remote_dom = (domid_t)remote_dom
    2.24      };
    2.25  
    2.26 -    rc = do_evtchn_op(xc_handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg));
    2.27 +    rc = do_evtchn_op(xc_handle, EVTCHNOP_alloc_unbound, &arg, sizeof(arg), 0);
    2.28      if ( rc == 0 )
    2.29          rc = arg.port;
    2.30  
    2.31 @@ -55,5 +56,20 @@ int xc_evtchn_reset(int xc_handle,
    2.32                      uint32_t dom)
    2.33  {
    2.34      struct evtchn_reset arg = { .dom = (domid_t)dom };
    2.35 -    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg));
    2.36 +    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg), 0);
    2.37  }
    2.38 +
    2.39 +int xc_evtchn_status(int xc_handle,
    2.40 +                     uint32_t dom,
    2.41 +                     uint32_t port)
    2.42 +{
    2.43 +    int rc;
    2.44 +    struct evtchn_status arg = { .dom = (domid_t)dom,
    2.45 +                                 .port = (evtchn_port_t)port };
    2.46 +
    2.47 +    rc = do_evtchn_op(xc_handle, EVTCHNOP_status, &arg, sizeof(arg), 1);
    2.48 +    if ( rc == 0 )
    2.49 +        rc = arg.status;
    2.50 +
    2.51 +    return rc;
    2.52 +}
     3.1 --- a/tools/libxc/xenctrl.h	Wed Apr 09 16:04:10 2008 +0100
     3.2 +++ b/tools/libxc/xenctrl.h	Wed Apr 09 16:11:34 2008 +0100
     3.3 @@ -470,6 +470,9 @@ xc_evtchn_alloc_unbound(int xc_handle,
     3.4  
     3.5  int xc_evtchn_reset(int xc_handle,
     3.6                      uint32_t dom);
     3.7 +int xc_evtchn_status(int xc_handle,
     3.8 +                     uint32_t dom,
     3.9 +                     uint32_t port);
    3.10  
    3.11  /*
    3.12   * Return a handle to the event channel driver, or -1 on failure, in which case
     4.1 --- a/tools/xcutils/Makefile	Wed Apr 09 16:04:10 2008 +0100
     4.2 +++ b/tools/xcutils/Makefile	Wed Apr 09 16:11:34 2008 +0100
     4.3 @@ -18,7 +18,7 @@ CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_
     4.4  CFLAGS += -Wp,-MD,.$(@F).d
     4.5  PROG_DEP = .*.d
     4.6  
     4.7 -PROGRAMS = xc_restore xc_save readnotes
     4.8 +PROGRAMS = xc_restore xc_save readnotes lsevtchn
     4.9  
    4.10  LDLIBS   = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
    4.11  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xcutils/lsevtchn.c	Wed Apr 09 16:11:34 2008 +0100
     5.3 @@ -0,0 +1,59 @@
     5.4 +#include <err.h>
     5.5 +#include <stdlib.h>
     5.6 +#include <stdint.h>
     5.7 +#include <string.h>
     5.8 +#include <stdio.h>
     5.9 +
    5.10 +#include <xs.h>
    5.11 +#include <xenctrl.h>
    5.12 +#include <xenguest.h>
    5.13 +
    5.14 +int
    5.15 +main(int argc, char **argv)
    5.16 +{
    5.17 +    int xc_fd;
    5.18 +    int domid = 0, port = 0, status;
    5.19 +    const char *msg;
    5.20 +
    5.21 +    if ( argc > 1 )
    5.22 +        domid = strtol(argv[1], NULL, 10);
    5.23 +
    5.24 +    xc_fd = xc_interface_open();
    5.25 +    if ( xc_fd < 0 )
    5.26 +        errx(1, "failed to open control interface");
    5.27 +
    5.28 +    while ( (status = xc_evtchn_status(xc_fd, domid, port)) >= 0 )
    5.29 +    {
    5.30 +        switch ( status )
    5.31 +        {
    5.32 +        case EVTCHNSTAT_closed:
    5.33 +            msg = "Channel is not in use.";
    5.34 +            break;
    5.35 +        case EVTCHNSTAT_unbound:
    5.36 +            msg = "Channel is waiting interdom connection.";
    5.37 +            break;
    5.38 +        case EVTCHNSTAT_interdomain:
    5.39 +            msg = "Channel is connected to remote domain.";
    5.40 +            break;
    5.41 +        case EVTCHNSTAT_pirq:
    5.42 +            msg = "Channel is bound to a phys IRQ line.";
    5.43 +            break;
    5.44 +        case EVTCHNSTAT_virq:
    5.45 +            msg = "Channel is bound to a virtual IRQ line.";
    5.46 +            break;
    5.47 +        case EVTCHNSTAT_ipi:
    5.48 +            msg = "Channel is bound to a virtual IPI line.";
    5.49 +            break;
    5.50 +        default:
    5.51 +            msg = "Unknown.";
    5.52 +            break;
    5.53 +
    5.54 +        }
    5.55 +        printf("%03d: %d: %s\n", port, status, msg);
    5.56 +        port++;
    5.57 +    }
    5.58 +
    5.59 +    xc_interface_close(xc_fd);
    5.60 +
    5.61 +    return 0;
    5.62 +}