ia64/xen-unstable

changeset 6688:38c5199155fc

g/c unused xcs.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 07 19:01:05 2005 +0000 (2005-09-07)
parents 4e4aac33809f
children 7d0fb56b4a91
files .hgignore tools/Makefile tools/Rules.mk tools/examples/init.d/xend tools/misc/xend tools/xenstore/Makefile
line diff
     1.1 --- a/.hgignore	Wed Sep 07 18:37:55 2005 +0000
     1.2 +++ b/.hgignore	Wed Sep 07 19:01:05 2005 +0000
     1.3 @@ -147,8 +147,6 @@
     1.4  ^tools/vtpm_manager/manager/vtpm_managerd
     1.5  ^tools/web-shutdown\.tap$
     1.6  ^tools/x2d2/minixend$
     1.7 -^tools/xcs/xcs$
     1.8 -^tools/xcs/xcsdump$
     1.9  ^tools/xcutils/xc_restore$
    1.10  ^tools/xcutils/xc_save$
    1.11  ^tools/xenstat/xentop/xentop$
    1.12 @@ -166,7 +164,6 @@
    1.13  ^tools/xenstore/xs_test$
    1.14  ^tools/xenstore/xs_watch_stress$
    1.15  ^tools/xentrace/xentrace$
    1.16 -^tools/xfrd/xfrd$
    1.17  ^xen/BLOG$
    1.18  ^xen/TAGS$
    1.19  ^xen/arch/x86/asm-offsets\.s$
     2.1 --- a/tools/Makefile	Wed Sep 07 18:37:55 2005 +0000
     2.2 +++ b/tools/Makefile	Wed Sep 07 19:01:05 2005 +0000
     2.3 @@ -7,7 +7,6 @@ SUBDIRS += xenstore
     2.4  SUBDIRS += misc
     2.5  SUBDIRS += examples
     2.6  SUBDIRS += xentrace
     2.7 -SUBDIRS += xcs
     2.8  SUBDIRS += xcutils
     2.9  SUBDIRS += firmware
    2.10  SUBDIRS += security
     3.1 --- a/tools/Rules.mk	Wed Sep 07 18:37:55 2005 +0000
     3.2 +++ b/tools/Rules.mk	Wed Sep 07 19:01:05 2005 +0000
     3.3 @@ -4,7 +4,6 @@ include $(XEN_ROOT)/Config.mk
     3.4  
     3.5  XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
     3.6  XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
     3.7 -XEN_XCS            = $(XEN_ROOT)/tools/xcs
     3.8  XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
     3.9  XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
    3.10  
     4.1 --- a/tools/examples/init.d/xend	Wed Sep 07 18:37:55 2005 +0000
     4.2 +++ b/tools/examples/init.d/xend	Wed Sep 07 19:01:05 2005 +0000
     4.3 @@ -11,7 +11,7 @@ if ! [ -e /proc/xen/privcmd ]; then
     4.4  	exit 0
     4.5  fi
     4.6  
     4.7 -# Wait for Xend and xcs to be up
     4.8 +# Wait for Xend to be up
     4.9  function await_daemons_up
    4.10  {
    4.11  	i=1
     5.1 --- a/tools/misc/xend	Wed Sep 07 18:37:55 2005 +0000
     5.2 +++ b/tools/misc/xend	Wed Sep 07 19:01:05 2005 +0000
     5.3 @@ -26,11 +26,6 @@ import signal
     5.4  import time
     5.5  import commands
     5.6  
     5.7 -XCS_PATH    = "/var/lib/xen/xcs_socket"
     5.8 -XCS_EXEC    = "/usr/sbin/xcs"
     5.9 -XCS_PIDFILE = "/var/run/xcs.pid"
    5.10 -XCS_ARGS    = (XCS_EXEC, "-p", XCS_PIDFILE)
    5.11 -
    5.12  # add fallback path for non-native python path installs if needed
    5.13  sys.path.append('/usr/lib/python')
    5.14  sys.path.append('/usr/lib64/python')
    5.15 @@ -70,52 +65,6 @@ def check_user():
    5.16          hline()
    5.17          raise CheckError("invalid user")
    5.18  
    5.19 -def xcs_running():
    5.20 -    """ See if the control switch is running.
    5.21 -    """	
    5.22 -    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    5.23 -    try:
    5.24 -        s.connect( (XCS_PATH) )
    5.25 -        s.close()
    5.26 -    except:
    5.27 -        try:
    5.28 -            os.remove(XCS_PIDFILE)
    5.29 -        except:
    5.30 -            pass
    5.31 -	return 0
    5.32 -    return 1
    5.33 -    
    5.34 -def start_xcs():
    5.35 -    if (not xcs_running()):
    5.36 -        if os.fork() == 0 :
    5.37 -            if not os.path.isdir(os.path.dirname(XCS_PATH)):
    5.38 -                os.makedirs(os.path.dirname(XCS_PATH))
    5.39 -            try:
    5.40 -                os.execvp(XCS_EXEC, XCS_ARGS)
    5.41 -            except:
    5.42 -                hline()
    5.43 -                msg("Tried to start xcs, but failed. Is it installed?")
    5.44 -                hline()
    5.45 -                raise CheckError("couldn't start xcs")
    5.46 -        for n in range(10) :
    5.47 -            if (xcs_running()):
    5.48 -                break
    5.49 -            time.sleep(0.1)
    5.50 -        else :
    5.51 -                hline()
    5.52 -                msg("Failed to start the control interface switch.")
    5.53 -                hline()
    5.54 -                raise CheckError("xcs not running")
    5.55 -            
    5.56 -def stop_xcs():
    5.57 -    try:
    5.58 -	xcs_pidfile = open(XCS_PIDFILE)
    5.59 -        xcs_pid = int(xcs_pidfile.read().strip())
    5.60 -        os.kill(xcs_pid, signal.SIGTERM)
    5.61 -        xcs_pidfile.close()
    5.62 -    except:
    5.63 -	return    
    5.64 -
    5.65  def start_xenstored():
    5.66      XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
    5.67      cmd = "/usr/sbin/xenstored --pid-file=/var/run/xenstore.pid"
    5.68 @@ -141,19 +90,16 @@ def main():
    5.69          pid, status = os.wait()
    5.70          return status >> 8
    5.71      elif sys.argv[1] == 'start':
    5.72 -        start_xcs()
    5.73          start_xenstored()
    5.74          start_consoled()
    5.75          return daemon.start()
    5.76      elif sys.argv[1] == 'trace_start':
    5.77 -        start_xcs()
    5.78          start_xenstored()
    5.79          start_consoled()
    5.80          return daemon.start(trace=1)
    5.81      elif sys.argv[1] == 'stop':
    5.82          return daemon.stop()
    5.83      elif sys.argv[1] == 'restart':
    5.84 -        start_xcs()
    5.85          start_xenstored()
    5.86          start_consoled()
    5.87          return daemon.stop() or daemon.start()
     6.1 --- a/tools/xcs/Makefile	Wed Sep 07 18:37:55 2005 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,48 +0,0 @@
     6.4 -# Makefile for XCS
     6.5 -# Andrew Warfield, 2004
     6.6 -
     6.7 -XEN_ROOT=../..
     6.8 -include $(XEN_ROOT)/tools/Rules.mk
     6.9 -
    6.10 -XCS_INSTALL_DIR = /usr/sbin
    6.11 -
    6.12 -INSTALL         = install
    6.13 -INSTALL_PROG    = $(INSTALL) -m0755
    6.14 -INSTALL_DIR     = $(INSTALL) -d -m0755
    6.15 -
    6.16 -CFLAGS   += -Wall -Werror -g3 -D _XOPEN_SOURCE=600
    6.17 -
    6.18 -CFLAGS  += -I $(XEN_XC)
    6.19 -CFLAGS  += -I $(XEN_LIBXC)
    6.20 -
    6.21 -SRCS    :=
    6.22 -SRCS    += ctrl_interface.c
    6.23 -SRCS    += bindings.c
    6.24 -SRCS    += connection.c
    6.25 -SRCS    += evtchn.c
    6.26 -SRCS    += xcs.c
    6.27 -
    6.28 -HDRS     = $(wildcard *.h)
    6.29 -OBJS     = $(patsubst %.c,%.o,$(SRCS))
    6.30 -BIN      = xcs
    6.31 -
    6.32 -all: $(BIN) xcsdump
    6.33 -
    6.34 -clean:
    6.35 -	$(RM) *.a *.so *.o *.rpm $(BIN) xcsdump
    6.36 -
    6.37 -xcsdump: xcsdump.c dump.c
    6.38 -	$(CC) $(CFLAGS) -o xcsdump xcsdump.c -L$(XEN_LIBXC) \
    6.39 -              ctrl_interface.c evtchn.c dump.c -lxenctrl
    6.40 -
    6.41 -$(BIN): $(OBJS)
    6.42 -	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -lxenctrl 
    6.43 -
    6.44 -$(OBJS): $(HDRS)
    6.45 -
    6.46 -install: xcs xcsdump
    6.47 -	$(INSTALL_DIR) -p $(DESTDIR)/$(XCS_INSTALL_DIR)
    6.48 -	$(INSTALL_DIR) -p $(DESTDIR)/usr/include
    6.49 -	$(INSTALL_PROG) xcs $(DESTDIR)/$(XCS_INSTALL_DIR)
    6.50 -	$(INSTALL_PROG) xcsdump $(DESTDIR)/$(XCS_INSTALL_DIR)
    6.51 -	$(INSTALL_PROG) xcs_proto.h $(DESTDIR)/usr/include
     7.1 --- a/tools/xcs/bindings.c	Wed Sep 07 18:37:55 2005 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,179 +0,0 @@
     7.4 -/* bindings.c
     7.5 - *
     7.6 - * Manage subscriptions for the control interface switch.
     7.7 - *
     7.8 - * (c) 2004, Andrew Warfield
     7.9 - *
    7.10 - */
    7.11 -
    7.12 -/* Interfaces:
    7.13 - *
    7.14 - * xcs_bind   (port, type, connection)
    7.15 - *   - Register connection to receive messages of this type.
    7.16 - * xcs_unbind (port, type, connection)
    7.17 - *   - Remove an existing registration. (Must be an exact match)
    7.18 - * xcs_lookup (port, type)
    7.19 - *   - Return a list of connections matching a registration.
    7.20 - * 
    7.21 - * - All connections have a connection.bindings list of current bindings.
    7.22 - * - (port, type) pairs may be wildcarded with -1.
    7.23 - */
    7.24 - 
    7.25 -#include <stdio.h>
    7.26 -#include <stdlib.h> 
    7.27 -#include <errno.h>
    7.28 -#include <string.h>
    7.29 -#include "xcs.h"
    7.30 -
    7.31 -
    7.32 -typedef struct binding_ent_st {
    7.33 -    connection_t          *con;
    7.34 -    struct binding_ent_st *next;
    7.35 -} binding_ent_t;
    7.36 -
    7.37 -#define BINDING_TABLE_SIZE       1024
    7.38 -
    7.39 -static binding_ent_t *binding_table[BINDING_TABLE_SIZE];
    7.40 -        
    7.41 -#define PORT_WILD(_ent) ((_ent)->port == PORT_WILDCARD)
    7.42 -#define TYPE_WILD(_ent) ((_ent)->type == TYPE_WILDCARD)
    7.43 -#define FULLY_WILD(_ent) (PORT_WILD(_ent) && TYPE_WILD(_ent))
    7.44 -
    7.45 -#define BINDING_HASH(_key) \
    7.46 -    ((((_key)->port * 11) ^ (_key)->type) % BINDING_TABLE_SIZE)
    7.47 -    
    7.48 -    
    7.49 -void init_bindings(void)
    7.50 -{
    7.51 -    memset(binding_table, 0, sizeof(binding_table));
    7.52 -}
    7.53 -
    7.54 -static int table_add(binding_ent_t *table[],
    7.55 -                            connection_t *con, 
    7.56 -                            binding_key_t *key)
    7.57 -{
    7.58 -    binding_ent_t **curs, *ent;
    7.59 -        
    7.60 -    curs = &table[BINDING_HASH(key)];
    7.61 -    
    7.62 -    while (*curs != NULL) {
    7.63 -        if ((*curs)->con == con) {
    7.64 -            DPRINTF("Tried to add an ent that already existed.\n");
    7.65 -            goto done;
    7.66 -        }
    7.67 -        curs = &(*curs)->next;
    7.68 -    }
    7.69 -    
    7.70 -    if (connection_add_binding(con, key) != 0)
    7.71 -    {
    7.72 -       DPRINTF("couldn't add binding on connection (%lu)\n", con->id);
    7.73 -       goto fail;
    7.74 -    }
    7.75 -    ent = (binding_ent_t *)malloc(sizeof(binding_ent_t));
    7.76 -    if (ent == 0) {
    7.77 -       DPRINTF("couldn't alloc binding ent!\n");
    7.78 -       goto fail;
    7.79 -    }
    7.80 -    ent->con = con;
    7.81 -    ent->next = NULL;
    7.82 -    *curs = ent;
    7.83 -    
    7.84 -done:
    7.85 -    return 0;
    7.86 -
    7.87 -fail:
    7.88 -    return -1;
    7.89 -}
    7.90 -
    7.91 -
    7.92 -static inline int binding_has_colliding_hashes(connection_t *con, 
    7.93 -                                               binding_key_t *key)
    7.94 -{
    7.95 -    int hash, count = 0;
    7.96 -    binding_key_ent_t *ent;
    7.97 -    
    7.98 -    ent = con->bindings; 
    7.99 -    hash = BINDING_HASH(key);
   7.100 -    
   7.101 -    while (ent != NULL) {
   7.102 -        if (BINDING_HASH(&ent->key) == hash) count ++;
   7.103 -        ent = ent->next;
   7.104 -    }
   7.105 -    
   7.106 -    return (count > 1);
   7.107 -}
   7.108 -static int table_remove(binding_ent_t *table[],
   7.109 -                            connection_t *con, 
   7.110 -                            binding_key_t *key)
   7.111 -{
   7.112 -    binding_ent_t **curs, *ent;
   7.113 -    
   7.114 -    if (!binding_has_colliding_hashes(con, key))
   7.115 -    {
   7.116 -    
   7.117 -        curs = &table[BINDING_HASH(key)];
   7.118 -
   7.119 -        while ((*curs != NULL) && ((*curs)->con != con))
   7.120 -           curs = &(*curs)->next;
   7.121 -
   7.122 -        if (*curs != NULL) {
   7.123 -           ent = *curs;
   7.124 -           *curs = (*curs)->next;
   7.125 -           free(ent);
   7.126 -        }
   7.127 -    }
   7.128 -    
   7.129 -    connection_remove_binding(con, key);
   7.130 -    
   7.131 -    return 0;    
   7.132 -}
   7.133 -
   7.134 -int xcs_bind(connection_t *con, int port, u16 type)
   7.135 -{
   7.136 -    binding_key_t  key;
   7.137 -    
   7.138 -    key.port = port;
   7.139 -    key.type = type;
   7.140 -    
   7.141 -    return table_add(binding_table, con, &key);  
   7.142 -}
   7.143 -
   7.144 -int xcs_unbind(connection_t *con, int port, u16 type)
   7.145 -{
   7.146 -    binding_key_t  key;
   7.147 -    
   7.148 -    key.port = port;
   7.149 -    key.type = type;
   7.150 -    
   7.151 -    return table_remove(binding_table, con, &key); 
   7.152 -}
   7.153 -
   7.154 -
   7.155 -static void for_each_binding(binding_ent_t *list, binding_key_t *key, 
   7.156 -                void (*f)(connection_t *, void *), void *arg)
   7.157 -{
   7.158 -    while (list != NULL) 
   7.159 -    {
   7.160 -        if (connection_has_binding(list->con, key))
   7.161 -            f(list->con, arg);
   7.162 -        list = list->next;
   7.163 -    }  
   7.164 -}
   7.165 -
   7.166 -void xcs_lookup(int port, u16 type, void (*f)(connection_t *, void *), 
   7.167 -                void *arg)
   7.168 -{
   7.169 -    binding_key_t  key;
   7.170 -            
   7.171 -    key.port  = port; key.type = type;
   7.172 -    for_each_binding(binding_table[BINDING_HASH(&key)], &key, f, arg);
   7.173 -            
   7.174 -    key.port  = port; key.type = TYPE_WILDCARD;
   7.175 -    for_each_binding(binding_table[BINDING_HASH(&key)], &key, f, arg);
   7.176 -            
   7.177 -    key.port  = PORT_WILDCARD; key.type = type;
   7.178 -    for_each_binding(binding_table[BINDING_HASH(&key)], &key, f, arg);
   7.179 -            
   7.180 -    key.port  = PORT_WILDCARD; key.type = TYPE_WILDCARD;
   7.181 -    for_each_binding(binding_table[BINDING_HASH(&key)], &key, f, arg);
   7.182 -}
     8.1 --- a/tools/xcs/connection.c	Wed Sep 07 18:37:55 2005 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,157 +0,0 @@
     8.4 -/*
     8.5 - * connection.c
     8.6 - *
     8.7 - * State associated with a client connection to xcs.
     8.8 - *
     8.9 - * Copyright (c) 2004, Andrew Warfield
    8.10 - */
    8.11 -
    8.12 -#include <stdio.h>
    8.13 -#include <stdlib.h>
    8.14 -#include <string.h>
    8.15 -#include "xcs.h"
    8.16 -
    8.17 -connection_t *connection_list = NULL;
    8.18 -
    8.19 -#define CONNECTED(_c) (((_c)->ctrl_fd != -1) || ((_c)->data_fd != -1))
    8.20 -
    8.21 -connection_t *get_con_by_session(unsigned long session_id)
    8.22 -{
    8.23 -    connection_t **c, *ent = NULL;
    8.24 -    
    8.25 -    c = &connection_list;
    8.26 -    
    8.27 -    DPRINTF("looking for id: %lu : %lu\n", session_id, (*c)->id);
    8.28 -    
    8.29 -    while (*c != NULL) 
    8.30 -    {
    8.31 -        if ((*c)->id == session_id) 
    8.32 -            return (*c);
    8.33 -        c = &(*c)->next;
    8.34 -    }
    8.35 -    
    8.36 -    return ent;
    8.37 -}
    8.38 -
    8.39 -connection_t *connection_new()
    8.40 -{
    8.41 -    connection_t *con;
    8.42 -    
    8.43 -    con = (connection_t *)malloc(sizeof(connection_t));
    8.44 -    if (con == NULL)
    8.45 -    {
    8.46 -        DPRINTF("couldn't allocate a new connection\n");
    8.47 -        return NULL;
    8.48 -    }
    8.49 -    
    8.50 -    con->bindings = NULL;
    8.51 -    con->data_fd = -1;
    8.52 -    con->ctrl_fd = -1;
    8.53 -    
    8.54 -    /* connections need a unique session id. 
    8.55 -     * - this approach probably gets fixed later, but for the moment
    8.56 -     * is unique, and clearly identifies a connection.
    8.57 -     */
    8.58 -    con->id = (unsigned long)con;
    8.59 -    
    8.60 -    /* add it to the connection list */
    8.61 -    con->next = connection_list;
    8.62 -    connection_list = con;
    8.63 -    
    8.64 -    return (con);
    8.65 -}
    8.66 -
    8.67 -void connection_free(connection_t *con)
    8.68 -{
    8.69 -    /* first free all subscribed bindings: */
    8.70 -    
    8.71 -    while (con->bindings != NULL)
    8.72 -        xcs_unbind(con, con->bindings->key.port, con->bindings->key.type);
    8.73 -    
    8.74 -    /* now free the connection. */
    8.75 -    free(con);
    8.76 -}
    8.77 -    
    8.78 -int connection_add_binding(connection_t *con, binding_key_t *key)
    8.79 -{
    8.80 -    binding_key_ent_t *key_ent;
    8.81 -    
    8.82 -    key_ent = (binding_key_ent_t *)malloc(sizeof(binding_key_ent_t));
    8.83 -    if (key_ent == NULL)
    8.84 -    {
    8.85 -        DPRINTF("couldn't alloc key in connection_add_binding\n");
    8.86 -        return -1;    
    8.87 -    }
    8.88 -    
    8.89 -    key_ent->key = *key;
    8.90 -    key_ent->next = con->bindings;
    8.91 -    con->bindings = key_ent;
    8.92 -    
    8.93 -    return 0;
    8.94 -}
    8.95 -
    8.96 -int connection_remove_binding(connection_t *con, binding_key_t *key)
    8.97 -{
    8.98 -    binding_key_ent_t *key_ent;
    8.99 -    binding_key_ent_t **curs = &con->bindings;
   8.100 -    
   8.101 -    while ((*curs != NULL) && (!BINDING_KEYS_EQUAL(&(*curs)->key, key)))
   8.102 -        curs = &(*curs)->next;
   8.103 -    
   8.104 -    if (*curs != NULL) {
   8.105 -        key_ent = *curs;
   8.106 -        *curs = (*curs)->next;
   8.107 -        free(key_ent);
   8.108 -    }
   8.109 -    
   8.110 -    return 0;   
   8.111 -}
   8.112 -
   8.113 -
   8.114 -int connection_has_binding(connection_t *con, binding_key_t *key)
   8.115 -{
   8.116 -    binding_key_ent_t *ent;
   8.117 -    int ret = 0;
   8.118 -    
   8.119 -    ent = con->bindings;
   8.120 -    
   8.121 -    while (ent != NULL) 
   8.122 -    {
   8.123 -        if (BINDING_KEYS_EQUAL(key, &ent->key))
   8.124 -        {
   8.125 -            ret = 1;
   8.126 -            break;
   8.127 -        }
   8.128 -        ent = ent->next;
   8.129 -    }
   8.130 -    
   8.131 -    return ret;
   8.132 -}
   8.133 -
   8.134 -
   8.135 -void gc_connection_list(void)
   8.136 -{
   8.137 -    connection_t **c, *ent = NULL;
   8.138 -    struct timeval now, delta;
   8.139 -
   8.140 -    c = &connection_list;
   8.141 -    gettimeofday(&now, NULL);
   8.142 -
   8.143 -    while ( *c != NULL )
   8.144 -    {
   8.145 -        if ( !CONNECTED(*c) )
   8.146 -        {
   8.147 -            timersub(&now, &(*c)->disconnect_time, &delta);
   8.148 -            if ( delta.tv_sec >= XCS_SESSION_TIMEOUT )
   8.149 -            {
   8.150 -                DPRINTF("        : Freeing connection %lu after %lds\n", 
   8.151 -                     (*c)->id, delta.tv_sec);
   8.152 -                ent = *c;
   8.153 -                *c = (*c)->next;
   8.154 -                connection_free(ent);
   8.155 -                continue;
   8.156 -            }
   8.157 -        }
   8.158 -        c = &(*c)->next;
   8.159 -    }
   8.160 -}
     9.1 --- a/tools/xcs/ctrl_interface.c	Wed Sep 07 18:37:55 2005 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,258 +0,0 @@
     9.4 -/* control_interface.c
     9.5 - *
     9.6 - * Interfaces to control message rings to VMs.
     9.7 - *
     9.8 - * Most of this is directly based on the original xu interface to python 
     9.9 - * written by Keir Fraser.
    9.10 - *
    9.11 - * (c) 2004, Andrew Warfield
    9.12 - *
    9.13 - */
    9.14 -
    9.15 -#include <stdio.h>
    9.16 -#include <stdlib.h>
    9.17 -#include <string.h>
    9.18 -#include <sys/ioctl.h>
    9.19 -#include <sys/mman.h>
    9.20 -#include <errno.h>
    9.21 -#include "xcs.h"
    9.22 -
    9.23 -static int xc_handle = -1;
    9.24 -
    9.25 -/* Called at start-of-day when using the control channel interface. */
    9.26 -int ctrl_chan_init(void)
    9.27 -{
    9.28 -    if ( (xc_handle = xc_interface_open()) == -1 )
    9.29 -    {
    9.30 -        DPRINTF("Could not open Xen control interface");
    9.31 -        return -1;
    9.32 -    }
    9.33 -    
    9.34 -    return 0;
    9.35 -}
    9.36 -
    9.37 -static control_if_t *map_control_interface(int fd, unsigned long pfn,
    9.38 -					   u32 dom)
    9.39 -{
    9.40 -    char *vaddr = xc_map_foreign_range( fd, dom, PAGE_SIZE,
    9.41 -					PROT_READ|PROT_WRITE, pfn );
    9.42 -    if ( vaddr == NULL )
    9.43 -        return NULL;
    9.44 -    return (control_if_t *)(vaddr + 2048);
    9.45 -}
    9.46 -
    9.47 -static void unmap_control_interface(int fd, control_if_t *c)
    9.48 -{
    9.49 -    char *vaddr = (char *)c - 2048;
    9.50 -    (void)munmap(vaddr, PAGE_SIZE);
    9.51 -}
    9.52 -
    9.53 -int ctrl_chan_notify(control_channel_t *cc)
    9.54 -{
    9.55 -    return xc_evtchn_send(xc_handle, cc->local_port);
    9.56 -}
    9.57 -
    9.58 -int ctrl_chan_read_request(control_channel_t *cc, xcs_control_msg_t *dmsg)
    9.59 -{
    9.60 -    control_msg_t     *smsg;
    9.61 -    RING_IDX          c = cc->tx_ring.req_cons;
    9.62 -
    9.63 -    if ( !RING_HAS_UNCONSUMED_REQUESTS(&cc->tx_ring) )
    9.64 -    {
    9.65 -        DPRINTF("no request to read\n");
    9.66 -        return -1;
    9.67 -    }
    9.68 -    
    9.69 -    rmb(); /* make sure we see the data associated with the request */
    9.70 -    smsg = RING_GET_REQUEST(&cc->tx_ring, c);
    9.71 -    memcpy(&dmsg->msg, smsg, sizeof(*smsg));
    9.72 -    if ( dmsg->msg.length > sizeof(dmsg->msg.msg) )
    9.73 -        dmsg->msg.length = sizeof(dmsg->msg.msg);
    9.74 -    cc->tx_ring.req_cons++;
    9.75 -    return 0;
    9.76 -}
    9.77 -
    9.78 -int ctrl_chan_write_request(control_channel_t *cc, 
    9.79 -                            xcs_control_msg_t *smsg)
    9.80 -{
    9.81 -    control_msg_t *dmsg;
    9.82 -    RING_IDX       p = cc->rx_ring.req_prod_pvt;
    9.83 -    
    9.84 -    if ( RING_FULL(&cc->rx_ring) )
    9.85 -    {
    9.86 -        DPRINTF("no space to write request");
    9.87 -        return -ENOSPC;
    9.88 -    }
    9.89 -
    9.90 -    dmsg = RING_GET_REQUEST(&cc->rx_ring, p);
    9.91 -    memcpy(dmsg, &smsg->msg, sizeof(*dmsg));
    9.92 -
    9.93 -    wmb();
    9.94 -    cc->rx_ring.req_prod_pvt++;
    9.95 -    RING_PUSH_REQUESTS(&cc->rx_ring);
    9.96 -    
    9.97 -    return 0;
    9.98 -}
    9.99 -
   9.100 -int ctrl_chan_read_response(control_channel_t *cc, xcs_control_msg_t *dmsg)
   9.101 -{
   9.102 -    control_msg_t     *smsg;
   9.103 -    RING_IDX          c = cc->rx_ring.rsp_cons;
   9.104 -    
   9.105 -    if ( !RING_HAS_UNCONSUMED_RESPONSES(&cc->rx_ring) )
   9.106 -    {
   9.107 -        DPRINTF("no response to read");
   9.108 -        return -1;
   9.109 -    }
   9.110 -
   9.111 -    rmb(); /* make sure we see the data associated with the request */
   9.112 -    smsg = RING_GET_RESPONSE(&cc->rx_ring, c);
   9.113 -    memcpy(&dmsg->msg, smsg, sizeof(*smsg));
   9.114 -    if ( dmsg->msg.length > sizeof(dmsg->msg.msg) )
   9.115 -        dmsg->msg.length = sizeof(dmsg->msg.msg);
   9.116 -    cc->rx_ring.rsp_cons++;
   9.117 -    return 0;
   9.118 -}
   9.119 -
   9.120 -int ctrl_chan_write_response(control_channel_t *cc, 
   9.121 -                             xcs_control_msg_t *smsg)
   9.122 -{
   9.123 -    control_msg_t  *dmsg;
   9.124 -    RING_IDX        p = cc->tx_ring.rsp_prod_pvt;
   9.125 -
   9.126 -    /* akw: if the ring is synchronous, you should never need this test! */
   9.127 -    /* (but it was in the original code... )                             */
   9.128 -    if ( cc->tx_ring.req_cons == cc->tx_ring.rsp_prod_pvt )
   9.129 -    {
   9.130 -        DPRINTF("no space to write response");
   9.131 -        return -ENOSPC;
   9.132 -    }
   9.133 -
   9.134 -    dmsg = RING_GET_RESPONSE(&cc->tx_ring, p);
   9.135 -    memcpy(dmsg, &smsg->msg, sizeof(*dmsg));
   9.136 -
   9.137 -    wmb();
   9.138 -    cc->tx_ring.rsp_prod_pvt++;
   9.139 -    RING_PUSH_RESPONSES(&cc->tx_ring);
   9.140 -    
   9.141 -    return 0;
   9.142 -}
   9.143 -
   9.144 -int ctrl_chan_request_to_read(control_channel_t *cc)
   9.145 -{
   9.146 -    return (RING_HAS_UNCONSUMED_REQUESTS(&cc->tx_ring));
   9.147 -}
   9.148 -
   9.149 -int ctrl_chan_space_to_write_request(control_channel_t *cc)
   9.150 -{
   9.151 -    return (!(RING_FULL(&cc->rx_ring)));
   9.152 -}
   9.153 -
   9.154 -int ctrl_chan_response_to_read(control_channel_t *cc)
   9.155 -{
   9.156 -    return (RING_HAS_UNCONSUMED_RESPONSES(&cc->rx_ring));
   9.157 -}
   9.158 -
   9.159 -int ctrl_chan_space_to_write_response(control_channel_t *cc)
   9.160 -{
   9.161 -    /* again, there is something fishy here. */
   9.162 -    return ( cc->tx_ring.req_cons != cc->tx_ring.rsp_prod_pvt );
   9.163 -}
   9.164 -
   9.165 -int ctrl_chan_connect(control_channel_t *cc)
   9.166 -{
   9.167 -    xc_dominfo_t info;
   9.168 -
   9.169 -    if ( cc->connected )
   9.170 -    {
   9.171 -	return 0;
   9.172 -    }
   9.173 -
   9.174 -    if ( (xc_domain_getinfo(xc_handle, cc->remote_dom, 1, &info) != 1) ||
   9.175 -         (info.domid != cc->remote_dom) )
   9.176 -    {
   9.177 -        DPRINTF("Failed to obtain domain status");
   9.178 -        return -1;
   9.179 -    }
   9.180 -
   9.181 -    cc->interface = 
   9.182 -        map_control_interface(xc_handle, info.shared_info_frame,
   9.183 -			      cc->remote_dom);
   9.184 -
   9.185 -    if ( cc->interface == NULL )
   9.186 -    {
   9.187 -        DPRINTF("Failed to map domain control interface");
   9.188 -        return -1;
   9.189 -    }
   9.190 -
   9.191 -    /* Synchronise ring indexes. */
   9.192 -    BACK_RING_ATTACH(&cc->tx_ring, &cc->interface->tx_ring, CONTROL_RING_MEM);
   9.193 -    FRONT_RING_ATTACH(&cc->rx_ring, &cc->interface->rx_ring, CONTROL_RING_MEM);
   9.194 -
   9.195 -    cc->connected = 1;
   9.196 -
   9.197 -    return 0;
   9.198 -}
   9.199 -
   9.200 -void ctrl_chan_disconnect(control_channel_t *cc)
   9.201 -{
   9.202 -    if ( cc->connected )
   9.203 -	unmap_control_interface(xc_handle, cc->interface);
   9.204 -    cc->connected = 0;
   9.205 -}
   9.206 -
   9.207 -
   9.208 -control_channel_t *ctrl_chan_new(u32 dom, int local_port, int remote_port)
   9.209 -{
   9.210 -    control_channel_t *cc;
   9.211 -   
   9.212 -    cc = (control_channel_t *)malloc(sizeof(control_channel_t));
   9.213 -    if ( cc == NULL ) return NULL;
   9.214 -    
   9.215 -    cc->connected  = 0;
   9.216 -    cc->remote_dom = dom;
   9.217 -
   9.218 -    if ( dom == 0 )
   9.219 -    {
   9.220 -	goto fail;
   9.221 -    }
   9.222 -    else if ( xc_evtchn_bind_interdomain(xc_handle, 
   9.223 -                                         DOMID_SELF, dom, 
   9.224 -                                         &local_port, &remote_port) != 0 )
   9.225 -    {
   9.226 -        DPRINTF("Could not open channel to domain");
   9.227 -        goto fail;
   9.228 -    }
   9.229 -
   9.230 -    cc->local_port  = local_port;
   9.231 -    cc->remote_port = remote_port;
   9.232 -
   9.233 -    if ( ctrl_chan_connect(cc) != 0 )
   9.234 -        goto fail;
   9.235 -
   9.236 -    return cc;
   9.237 -    
   9.238 - fail:
   9.239 -    if ( dom != 0 )
   9.240 -        (void)xc_evtchn_close(xc_handle, DOMID_SELF, local_port);
   9.241 - 
   9.242 -    free(cc);
   9.243 -    
   9.244 -    return NULL;        
   9.245 -}
   9.246 -
   9.247 -void ctrl_chan_free(control_channel_t *cc)
   9.248 -{
   9.249 -    ctrl_chan_disconnect(cc);
   9.250 -    if ( cc->remote_dom != 0 )
   9.251 -        (void)xc_evtchn_close(xc_handle, DOMID_SELF, cc->local_port);
   9.252 -    free(cc);
   9.253 -}
   9.254 -
   9.255 -
   9.256 -/* other libxc commands: */
   9.257 -
   9.258 -int ctrl_chan_bind_virq(int virq, int *port)
   9.259 -{
   9.260 -    return xc_evtchn_bind_virq(xc_handle, virq, port);
   9.261 -}
    10.1 --- a/tools/xcs/dump.c	Wed Sep 07 18:37:55 2005 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,506 +0,0 @@
    10.4 -/*\
    10.5 - *  Copyright (C) International Business Machines  Corp., 2005
    10.6 - *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    10.7 - *
    10.8 - *  This program is free software; you can redistribute it and/or modify
    10.9 - *  it under the terms of the GNU General Public License as published by
   10.10 - *  the Free Software Foundation; under version 2 of the License.
   10.11 - * 
   10.12 - *  This program is distributed in the hope that it will be useful,
   10.13 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 - *  GNU General Public License for more details.
   10.16 - * 
   10.17 - *  You should have received a copy of the GNU General Public License
   10.18 - *  along with this program; if not, write to the Free Software
   10.19 - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.20 -\*/
   10.21 -
   10.22 -#include <stdio.h>
   10.23 -#include <stdarg.h>
   10.24 -
   10.25 -#include "dump.h"
   10.26 -
   10.27 -#define str(a) # a
   10.28 -#define error(a, ...) do { \
   10.29 - _error("%s:%s():L%d: " a, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);\
   10.30 -  exit(1); \
   10.31 -} while (0)
   10.32 -#define warn(a, ...) do { \
   10.33 - _error("%s:%s():L%d: " a, __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__);\
   10.34 -} while (0)
   10.35 -#define debug(a, ...) do { \
   10.36 - _error(a, ## __VA_ARGS__);\
   10.37 -} while (0)
   10.38 -
   10.39 -void _error(const char *fmt, ...);
   10.40 -
   10.41 -#define debug_begin(a, b) debug("CMSG_" a "_" b " {")
   10.42 -#define debug_end(a, b) debug("}")
   10.43 -#define debug_field(a, b, c) debug("\t." str(b) " = " c, a->b)
   10.44 -#define debug_field_mac(a, b) \
   10.45 -  debug("\t." str(b) " = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x", \
   10.46 -        a->b[0], a->b[1], a->b[2], a->b[3], a->b[4], a->b[5])
   10.47 -
   10.48 -#define debug_dump(a, b, c) debug_hex("\t." str(b) " = ", a->b, a->c)
   10.49 -
   10.50 -#include <stdint.h>
   10.51 -#include <string.h>
   10.52 -#include <stdio.h>
   10.53 -#include <ctype.h>
   10.54 -
   10.55 -static int strcount(const char *str, char ch)
   10.56 -{
   10.57 -	int i;
   10.58 -	int count = 0;
   10.59 -
   10.60 -	for (i = 0; str[i]; i++) {
   10.61 -		if (str[i] == ch) {
   10.62 -			count++;
   10.63 -		}
   10.64 -	}
   10.65 -
   10.66 -	return count;
   10.67 -}
   10.68 -
   10.69 -void debug_hex(const char *info, const uint8_t *data, size_t length)
   10.70 -{
   10.71 -	int indent = strlen(info) + (strcount(info, '\t') * 8 - 1);
   10.72 -	int words_per_row = (2 * (80 - indent - 2) / 7) & ~1;
   10.73 -	size_t i;
   10.74 -
   10.75 -	for (i = 0; i < length; i += words_per_row) {
   10.76 -		size_t ind;
   10.77 -
   10.78 -		if (i == 0) {
   10.79 -			fprintf(stderr, "%s", info);
   10.80 -		} else {
   10.81 -			int j;
   10.82 -			for (j = 0; j < indent; j++) {
   10.83 -				fprintf(stderr, " ");
   10.84 -			}
   10.85 -		}
   10.86 -
   10.87 -		for (ind = 0; ind < words_per_row; ind++) {
   10.88 -			if (ind % 2 == 0) {
   10.89 -				fprintf(stderr, " ");
   10.90 -			}
   10.91 -
   10.92 -			if (i + ind < length) {
   10.93 -				fprintf(stderr, "%.2X", data[i + ind]);
   10.94 -			} else {
   10.95 -				fprintf(stderr, "  ");
   10.96 -			}
   10.97 -		}
   10.98 -
   10.99 -		fprintf(stderr, " ");
  10.100 -
  10.101 -		for (ind = 0; ind < words_per_row; ind++) {
  10.102 -			if (i + ind < length) {
  10.103 -				if (isprint(data[i + ind])) {
  10.104 -					fprintf(stderr, "%c", data[i + ind]);
  10.105 -				} else {
  10.106 -					fprintf(stderr, ".");
  10.107 -				}
  10.108 -			} else {
  10.109 -				fprintf(stderr, " ");
  10.110 -			}
  10.111 -		}
  10.112 -		fprintf(stderr, "\n");
  10.113 -	}
  10.114 -}
  10.115 -
  10.116 -void dump_msg(const control_msg_t *msg, uint64_t flags)
  10.117 -{
  10.118 -	if ((flags & (1 << msg->type)) == 0) {
  10.119 -		return;
  10.120 -	}
  10.121 -
  10.122 -	switch (msg->type) {
  10.123 -	case CMSG_CONSOLE:
  10.124 -		if (msg->subtype == CMSG_CONSOLE_DATA) {
  10.125 -			debug_begin("CONSOLE", "DATA");
  10.126 -			debug_field(msg, length, "%u");
  10.127 -			debug_dump(msg, msg, length);
  10.128 -			debug_end("CONSOLE", "DATA");
  10.129 -		} else {
  10.130 -			debug_begin("CONSOLE", "UNKNOWN");
  10.131 -			debug_field(msg, subtype, "%u");
  10.132 -			debug_field(msg, length, "%u");
  10.133 -			debug_dump(msg, msg, length);
  10.134 -			debug_end("CONSOLE", "UNKNOWN");
  10.135 -		}
  10.136 -		break;
  10.137 -	case CMSG_BLKIF_BE:
  10.138 -		if (msg->subtype == CMSG_BLKIF_BE_CREATE) {
  10.139 -			blkif_be_create_t *load;
  10.140 -			load = (blkif_be_create_t *)msg->msg;
  10.141 -			debug_begin("BLKIF_BE", "CREATE");
  10.142 -			debug_field(load, domid, "%u");
  10.143 -			debug_field(load, blkif_handle, "%u");
  10.144 -			debug_field(load, status, "%u");
  10.145 -			debug_end("BLKIF_BE", "CREATE");
  10.146 -		} else if (msg->subtype == CMSG_BLKIF_BE_DESTROY) {
  10.147 -			blkif_be_destroy_t *load;
  10.148 -			load = (blkif_be_destroy_t *)msg->msg;
  10.149 -			debug_begin("BLKIF_BE", "DESTROY");
  10.150 -			debug_field(load, domid, "%u");
  10.151 -			debug_field(load, blkif_handle, "%u");
  10.152 -			debug_field(load, status, "%u");
  10.153 -			debug_end("BLKIF_BE", "DESTROY");
  10.154 -		} else if (msg->subtype == CMSG_BLKIF_BE_CONNECT) {
  10.155 -			blkif_be_connect_t *load;
  10.156 -			load = (blkif_be_connect_t *)msg->msg;
  10.157 -			debug_begin("BLKIF_BE", "CONNECT");
  10.158 -			debug_field(load, domid, "%u");
  10.159 -			debug_field(load, blkif_handle, "%u");
  10.160 -			debug_field(load, shmem_frame, "%lu");
  10.161 -			debug_field(load, evtchn, "%u");
  10.162 -			debug_field(load, status, "%u");
  10.163 -			debug_end("BLKIF_BE", "CONNECT");
  10.164 -		} else if (msg->subtype == CMSG_BLKIF_BE_DISCONNECT) {
  10.165 -			blkif_be_disconnect_t *load;
  10.166 -			load = (blkif_be_disconnect_t *)msg->msg;
  10.167 -			debug_begin("BLKIF_BE", "DISCONNECT");
  10.168 -			debug_field(load, domid, "%u");
  10.169 -			debug_field(load, blkif_handle, "%u");
  10.170 -			debug_field(load, status, "%u");
  10.171 -			debug_end("BLKIF_BE", "DISCONNECT");
  10.172 -		} else if (msg->subtype == CMSG_BLKIF_BE_VBD_CREATE) {
  10.173 -			blkif_be_vbd_create_t *load;
  10.174 -			load = (blkif_be_vbd_create_t *)msg->msg;
  10.175 -			debug_begin("BLKIF_BE", "VBD_CREATE");
  10.176 -			debug_field(load, domid, "%u");
  10.177 -			debug_field(load, blkif_handle, "%u");
  10.178 -			debug_field(load, pdevice, "%u");
  10.179 -			debug_field(load, vdevice, "%u");
  10.180 -			debug_field(load, readonly, "%u");
  10.181 -			debug_field(load, status, "%u");
  10.182 -			debug_end("BLKIF_BE", "VBD_CREATE");
  10.183 -		} else if (msg->subtype == CMSG_BLKIF_BE_VBD_DESTROY) {
  10.184 -			blkif_be_vbd_destroy_t *load;
  10.185 -			load = (blkif_be_vbd_destroy_t *)msg->msg;
  10.186 -			debug_begin("BLKIF_BE", "VBD_DESTROY");
  10.187 -			debug_field(load, domid, "%u");
  10.188 -			debug_field(load, blkif_handle, "%u");
  10.189 -			debug_field(load, vdevice, "%u");
  10.190 -			debug_field(load, status, "%u");
  10.191 -			debug_end("BLKIF_BE", "VBD_DESTROY");
  10.192 -		} else if (msg->subtype == CMSG_BLKIF_BE_DRIVER_STATUS) {
  10.193 -			blkif_be_driver_status_t *load;
  10.194 -			load = (blkif_be_driver_status_t *)msg->msg;
  10.195 -			debug_begin("BLKIF_BE", "DRIVER_STATUS");
  10.196 -			debug_field(load, status, "%u");
  10.197 -			debug_end("BLKIF_BE", "DRIVER_STATUS");
  10.198 -		} else {
  10.199 -			debug_begin("BLKIF_BE", "UNKNOWN");
  10.200 -			debug_field(msg, subtype, "%u");
  10.201 -			debug_field(msg, length, "%u");
  10.202 -			debug_dump(msg, msg, length);
  10.203 -			debug_end("BLKIF_BE", "UNKNOWN");
  10.204 -		}
  10.205 -		break;
  10.206 -	case CMSG_BLKIF_FE:
  10.207 -		if (msg->subtype == CMSG_BLKIF_FE_INTERFACE_STATUS) {
  10.208 -			blkif_fe_interface_status_t *load;
  10.209 -			load = (blkif_fe_interface_status_t *)msg->msg;
  10.210 -			debug_begin("BLKIF_FE", "INTERFACE_STATUS");
  10.211 -			debug_field(load, handle, "%u");
  10.212 -			debug_field(load, status, "%u");
  10.213 -			debug_field(load, evtchn, "%u");
  10.214 -			debug_field(load, domid, "%u");
  10.215 -			debug_end("BLKIF_FE", "INTERFACE_STATUS");
  10.216 -		} else if (msg->subtype == CMSG_BLKIF_FE_DRIVER_STATUS) {
  10.217 -			blkif_fe_driver_status_t *load;
  10.218 -			load = (blkif_fe_driver_status_t *)msg->msg;
  10.219 -			debug_begin("BLKIF_FE", "DRIVER_STATUS");
  10.220 -			debug_field(load, status, "%u");
  10.221 -			debug_field(load, max_handle, "%u");
  10.222 -			debug_end("BLKIF_FE", "DRIVER_STATUS");
  10.223 -		} else if (msg->subtype == CMSG_BLKIF_FE_INTERFACE_CONNECT) {
  10.224 -			blkif_fe_interface_connect_t *load;
  10.225 -			load = (blkif_fe_interface_connect_t *)msg->msg;
  10.226 -			debug_begin("BLKIF_FE", "INTERFACE_CONNECT");
  10.227 -			debug_field(load, handle, "%u");
  10.228 -			debug_field(load, shmem_frame, "%lu");
  10.229 -			debug_end("BLKIF_FE", "INTERFACE_CONNECT");
  10.230 -		} else if (msg->subtype == CMSG_BLKIF_FE_INTERFACE_DISCONNECT) {
  10.231 -			blkif_fe_interface_disconnect_t *load;
  10.232 -			load = (blkif_fe_interface_disconnect_t *)msg->msg;
  10.233 -			debug_begin("BLKIF_FE", "INTERFACE_DISCONNECT");
  10.234 -			debug_field(load, handle, "%u");
  10.235 -			debug_end("BLKIF_FE", "INTERFACE_DISCONNECT");
  10.236 -		} else if (msg->subtype == CMSG_BLKIF_FE_INTERFACE_QUERY) {
  10.237 -			blkif_fe_interface_query_t *load;
  10.238 -			load = (blkif_fe_interface_query_t *)msg->msg;
  10.239 -			debug_begin("BLKIF_FE", "INTERFACE_QUERY");
  10.240 -			debug_field(load, handle, "%u");
  10.241 -			debug_field(load, status, "%u");
  10.242 -			debug_field(load, evtchn, "%u");
  10.243 -			debug_field(load, domid, "%u");
  10.244 -			debug_end("BLKIF_FE", "INTERFACE_QUERY");
  10.245 -		} else {
  10.246 -			debug_begin("BLKIF_FE", "UNKNOWN");
  10.247 -			debug_field(msg, subtype, "%u");
  10.248 -			debug_field(msg, length, "%u");
  10.249 -			debug_dump(msg, msg, length);
  10.250 -			debug_end("BLKIF_FE", "UNKNOWN");
  10.251 -		}
  10.252 -		break;
  10.253 -	case CMSG_NETIF_BE:
  10.254 -		if (msg->subtype == CMSG_NETIF_BE_CREATE) {
  10.255 -			netif_be_create_t *load;
  10.256 -			load = (netif_be_create_t *)msg->msg;
  10.257 -			debug_begin("NETIF_BE", "CREATE");
  10.258 -			debug_field(load, domid, "%u");
  10.259 -			debug_field(load, netif_handle, "%u");
  10.260 -			debug_field_mac(load, mac);
  10.261 -			debug_field_mac(load, be_mac);
  10.262 -			debug_field(load, status, "%u");
  10.263 -			debug_end("NETIF_BE", "CREATE");
  10.264 -		} else if (msg->subtype == CMSG_NETIF_BE_DESTROY) {
  10.265 -			netif_be_destroy_t *load;
  10.266 -			load = (netif_be_destroy_t *)msg->msg;
  10.267 -			debug_begin("NETIF_BE", "DESTROY");
  10.268 -			debug_field(load, domid, "%u");
  10.269 -			debug_field(load, netif_handle, "%u");
  10.270 -			debug_field(load, status, "%u");
  10.271 -			debug_end("NETIF_BE", "DESTROY");
  10.272 -		} else if (msg->subtype == CMSG_NETIF_BE_CONNECT) {
  10.273 -			netif_be_connect_t *load;
  10.274 -			load = (netif_be_connect_t *)msg->msg;
  10.275 -			debug_begin("NETIF_BE", "CONNECT");
  10.276 -			debug_field(load, domid, "%u");
  10.277 -			debug_field(load, netif_handle, "%u");
  10.278 -			debug_field(load, tx_shmem_frame, "%lu");
  10.279 -			debug_field(load, rx_shmem_frame, "%lu");
  10.280 -			debug_field(load, evtchn, "%u");
  10.281 -			debug_field(load, status, "%u");
  10.282 -			debug_end("NETIF_BE", "CONNECT");
  10.283 -		} else if (msg->subtype == CMSG_NETIF_BE_DISCONNECT) {
  10.284 -			netif_be_disconnect_t *load;
  10.285 -			load = (netif_be_disconnect_t *)msg->msg;
  10.286 -			debug_begin("NETIF_BE", "DISCONNECT");
  10.287 -			debug_field(load, domid, "%u");
  10.288 -			debug_field(load, netif_handle, "%u");
  10.289 -			debug_field(load, status, "%u");
  10.290 -			debug_end("NETIF_BE", "DISCONNECT");
  10.291 -		} else if (msg->subtype == CMSG_NETIF_BE_DRIVER_STATUS) {
  10.292 -			netif_be_driver_status_t *load;
  10.293 -			load = (netif_be_driver_status_t *)msg->msg;
  10.294 -			debug_begin("NETIF_BE", "DRIVER_STATUS");
  10.295 -			debug_field(load, status, "%u");
  10.296 -			debug_end("NETIF_BE", "DRIVER_STATUS");
  10.297 -		} else {
  10.298 -			debug_begin("NETIF_BE", "UNKNOWN");
  10.299 -			debug_field(msg, subtype, "%u");
  10.300 -			debug_field(msg, length, "%u");
  10.301 -			debug_dump(msg, msg, length);
  10.302 -			debug_end("NETIF_BE", "UNKNOWN");
  10.303 -		}
  10.304 -		break;
  10.305 -	case CMSG_NETIF_FE:
  10.306 -		if (msg->subtype == CMSG_NETIF_FE_INTERFACE_STATUS) {
  10.307 -			netif_fe_interface_status_t *load;
  10.308 -			load = (netif_fe_interface_status_t *)msg->msg;
  10.309 -			debug_begin("NETIF_FE", "INTERFACE_STATUS");
  10.310 -			debug_field(load, handle, "%u");
  10.311 -			debug_field(load, status, "%u");
  10.312 -			debug_field(load, evtchn, "%u");
  10.313 -			debug_field_mac(load, mac);
  10.314 -			debug_field(load, domid, "%u");
  10.315 -			debug_end("NETIF_FE", "INTERFACE_STATUS");
  10.316 -		} else if (msg->subtype == CMSG_NETIF_FE_DRIVER_STATUS) {
  10.317 -			netif_fe_driver_status_t *load;
  10.318 -			load = (netif_fe_driver_status_t *)msg->msg;
  10.319 -			debug_begin("NETIF_FE", "DRIVER_STATUS");
  10.320 -			debug_field(load, status, "%u");
  10.321 -			debug_field(load, max_handle, "%u");
  10.322 -			debug_end("NETIF_FE", "DRIVER_STATUS");
  10.323 -		} else if (msg->subtype == CMSG_NETIF_FE_INTERFACE_CONNECT) {
  10.324 -			netif_fe_interface_connect_t *load;
  10.325 -			load = (netif_fe_interface_connect_t *)msg->msg;
  10.326 -			debug_begin("NETIF_FE", "INTERFACE_CONNECT");
  10.327 -			debug_field(load, handle, "%u");
  10.328 -			debug_field(load, tx_shmem_frame, "%lu");
  10.329 -			debug_field(load, rx_shmem_frame, "%lu");
  10.330 -			debug_end("NETIF_FE", "INTERFACE_CONNECT");
  10.331 -		} else if (msg->subtype == CMSG_NETIF_FE_INTERFACE_DISCONNECT) {
  10.332 -			netif_fe_interface_disconnect_t *load;
  10.333 -			load = (netif_fe_interface_disconnect_t *)msg->msg;
  10.334 -			debug_begin("NETIF_FE", "INTERFACE_DISCONNECT");
  10.335 -			debug_field(load, handle, "%u");
  10.336 -			debug_end("NETIF_FE", "INTERFACE_DISCONNECT");
  10.337 -		} else if (msg->subtype == CMSG_NETIF_FE_INTERFACE_QUERY) {
  10.338 -			netif_fe_interface_query_t *load;
  10.339 -			load = (netif_fe_interface_query_t *)msg->msg;
  10.340 -			debug_begin("NETIF_FE", "INTERFACE_QUERY");
  10.341 -			debug_field(load, handle, "%u");
  10.342 -			debug_field(load, status, "%u");
  10.343 -			debug_field(load, evtchn, "%u");
  10.344 -			debug_field_mac(load, mac);
  10.345 -			debug_field(load, domid, "%u");
  10.346 -			debug_end("NETIF_FE", "INTERFACE_QUERY");
  10.347 -		} else {
  10.348 -			debug_begin("NETIF_FE", "UNKNOWN");
  10.349 -			debug_field(msg, subtype, "%u");
  10.350 -			debug_field(msg, length, "%u");
  10.351 -			debug_dump(msg, msg, length);
  10.352 -			debug_end("NETIF_FE", "UNKNOWN");
  10.353 -		}
  10.354 -		break;
  10.355 -	case CMSG_SHUTDOWN:
  10.356 -		if (msg->subtype == CMSG_SHUTDOWN_POWEROFF) {
  10.357 -			debug_begin("SHUTDOWN", "POWEROFF");
  10.358 -			debug_end("SHUTDOWN", "POWEROFF");
  10.359 -		} else if (msg->subtype == CMSG_SHUTDOWN_REBOOT) {
  10.360 -			debug_begin("SHUTDOWN", "REBOOT");
  10.361 -			debug_end("SHUTDOWN", "REBOOT");
  10.362 -		} else if (msg->subtype == CMSG_SHUTDOWN_SUSPEND) {
  10.363 -			debug_begin("SHUTDOWN", "SUSPEND");
  10.364 -			debug_end("SHUTDOWN", "SUSPEND");
  10.365 -		} else if (msg->subtype == CMSG_SHUTDOWN_SYSRQ) {
  10.366 -			debug_begin("SHUTDOWN", "SYSRQ");
  10.367 -			debug_end("SHUTDOWN", "SYSRQ");
  10.368 -		} else {
  10.369 -			debug_begin("SHUTDOWN", "UNKNOWN");
  10.370 -			debug_field(msg, subtype, "%u");
  10.371 -			debug_field(msg, length, "%u");
  10.372 -			debug_dump(msg, msg, length);
  10.373 -			debug_end("SHUTDOWN", "UNKNOWN");
  10.374 -		}		
  10.375 -		break;
  10.376 -	case CMSG_MEM_REQUEST:
  10.377 -		if (msg->subtype == CMSG_MEM_REQUEST_SET) {
  10.378 -			mem_request_t *load;
  10.379 -			load = (mem_request_t *)msg->msg;
  10.380 -			debug_begin("MEM_REQUEST", "SET");
  10.381 -			debug_field(load, target, "%u");
  10.382 -			debug_field(load, status, "%u");
  10.383 -			debug_end("MEM_REQUEST", "SET");
  10.384 -		} else {
  10.385 -			debug_begin("MEM_REQUEST", "UNKNOWN");
  10.386 -			debug_field(msg, subtype, "%u");
  10.387 -			debug_field(msg, length, "%u");
  10.388 -			debug_dump(msg, msg, length);
  10.389 -			debug_end("MEM_REQUEST", "UNKNOWN");
  10.390 -		}		
  10.391 -		break;
  10.392 -	case CMSG_USBIF_BE:
  10.393 -		if (msg->subtype == CMSG_USBIF_BE_CREATE) {
  10.394 -			usbif_be_create_t *load;
  10.395 -			load = (usbif_be_create_t *)msg->msg;
  10.396 -			debug_begin("USBIF_BE", "CREATE");
  10.397 -			debug_field(load, domid, "%u");
  10.398 -			debug_field(load, status, "%u");
  10.399 -			debug_end("USBIF_BE", "CREATE");
  10.400 -		} else if (msg->subtype == CMSG_USBIF_BE_DESTROY) {
  10.401 -			usbif_be_destroy_t *load;
  10.402 -			load = (usbif_be_destroy_t *)msg->msg;
  10.403 -			debug_begin("USBIF_BE", "DESTROY");
  10.404 -			debug_field(load, domid, "%u");
  10.405 -			debug_field(load, status, "%u");
  10.406 -			debug_end("USBIF_BE", "DESTROY");
  10.407 -		} else if (msg->subtype == CMSG_USBIF_BE_CONNECT) {
  10.408 -			usbif_be_connect_t *load;
  10.409 -			load = (usbif_be_connect_t *)msg->msg;
  10.410 -			debug_begin("USBIF_BE", "CONNECT");
  10.411 -			debug_field(load, domid, "%u");
  10.412 -			debug_field(load, shmem_frame, "%lu");
  10.413 -			debug_field(load, evtchn, "%u");
  10.414 -			debug_field(load, bandwidth, "%u");
  10.415 -			debug_field(load, status, "%u");
  10.416 -			debug_end("USBIF_BE", "CONNECT");
  10.417 -		} else if (msg->subtype == CMSG_USBIF_BE_DISCONNECT) {
  10.418 -			usbif_be_disconnect_t *load;
  10.419 -			load = (usbif_be_disconnect_t *)msg->msg;
  10.420 -			debug_begin("USBIF_BE", "DISCONNECT");
  10.421 -			debug_field(load, domid, "%u");
  10.422 -			debug_field(load, status, "%u");
  10.423 -			debug_end("USBIF_BE", "DISCONNECT");
  10.424 -		} else if (msg->subtype == CMSG_USBIF_BE_CLAIM_PORT) {
  10.425 -			usbif_be_claim_port_t *load;
  10.426 -			load = (usbif_be_claim_port_t *)msg->msg;
  10.427 -			debug_begin("USBIF_BE", "CLAIM_PORT");
  10.428 -			debug_field(load, domid, "%u");
  10.429 -			debug_field(load, usbif_port, "%u");
  10.430 -			debug_field(load, status, "%u");
  10.431 -			debug_field(load, path, "%s");
  10.432 -			debug_end("USBIF_BE", "CLAIM_PORT");
  10.433 -		} else if (msg->subtype == CMSG_USBIF_BE_RELEASE_PORT) {
  10.434 -			usbif_be_release_port_t *load;
  10.435 -			load = (usbif_be_release_port_t *)msg->msg;
  10.436 -			debug_begin("USBIF_BE", "RELEASE_PORT");
  10.437 -			debug_field(load, path, "%s");
  10.438 -			debug_end("USBIF_BE", "RELEASE_PORT");
  10.439 -		} else if (msg->subtype == CMSG_USBIF_BE_DRIVER_STATUS_CHANGED) {
  10.440 -			usbif_be_driver_status_changed_t *load;
  10.441 -			load = (usbif_be_driver_status_changed_t *)msg->msg;
  10.442 -			debug_begin("USBIF_BE", "DRIVER_STATUS_CHANGED");
  10.443 -			debug_field(load, status, "%u");
  10.444 -			debug_end("USBIF_BE", "DRIVER_STATUS_CHANGED");
  10.445 -		} else {
  10.446 -			debug_begin("USBIF_BE", "UNKNOWN");
  10.447 -			debug_field(msg, subtype, "%u");
  10.448 -			debug_field(msg, length, "%u");
  10.449 -			debug_dump(msg, msg, length);
  10.450 -			debug_end("USBIF_BE", "UNKNOWN");
  10.451 -		}
  10.452 -		break;
  10.453 -	case CMSG_USBIF_FE:
  10.454 -		if (msg->subtype == CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED) {
  10.455 -			usbif_fe_interface_status_changed_t *load;
  10.456 -			load = (usbif_fe_interface_status_changed_t *)msg->msg;
  10.457 -			debug_begin("USBIF_FE", "INTERFACE_STATUS_CHANGED");
  10.458 -			debug_field(load, status, "%u");
  10.459 -			debug_field(load, evtchn, "%u");
  10.460 -			debug_field(load, domid, "%u");
  10.461 -			debug_field(load, bandwidth, "%u");
  10.462 -			debug_field(load, num_ports, "%u");
  10.463 -			debug_end("USBIF_FE", "INTERFACE_STATUS_CHANGED");
  10.464 -		} else if (msg->subtype == CMSG_USBIF_FE_DRIVER_STATUS_CHANGED) {
  10.465 -			usbif_fe_driver_status_changed_t *load;
  10.466 -			load = (usbif_fe_driver_status_changed_t *)msg->msg;
  10.467 -			debug_begin("USBIF_FE", "DRIVER_STATUS_CHANGED");
  10.468 -			debug_field(load, status, "%u");
  10.469 -			debug_end("USBIF_FE", "DRIVER_STATUS_CHANGED");
  10.470 -		} else if (msg->subtype == CMSG_USBIF_FE_INTERFACE_CONNECT) {
  10.471 -			usbif_fe_interface_connect_t *load;
  10.472 -			load = (usbif_fe_interface_connect_t *)msg->msg;
  10.473 -			debug_begin("USBIF_FE", "INTERFACE_CONNECT");
  10.474 -			debug_field(load, shmem_frame, "%lu");
  10.475 -			debug_end("USBIF_FE", "INTERFACE_CONNECT");
  10.476 -		} else if (msg->subtype == CMSG_USBIF_FE_INTERFACE_DISCONNECT) {
  10.477 -			debug_begin("USBIF_FE", "INTERFACE_DISCONNECT");
  10.478 -			debug_end("USBIF_FE", "INTERFACE_DISCONNECT");
  10.479 -		} else {
  10.480 -			debug_begin("USBIF_FE", "UNKNOWN");
  10.481 -			debug_field(msg, subtype, "%u");
  10.482 -			debug_field(msg, length, "%u");
  10.483 -			debug_dump(msg, msg, length);
  10.484 -			debug_end("USBIF_FE", "UNKNOWN");
  10.485 -		}
  10.486 -		break;
  10.487 -	default:
  10.488 -		debug_begin("UNKNOWN", "UNKNOWN");
  10.489 -		debug_field(msg, type, "%u");
  10.490 -		debug_field(msg, subtype, "%u");
  10.491 -		debug_field(msg, length, "%u");
  10.492 -		debug_dump(msg, msg, length);
  10.493 -		debug_end("UNKNOWN", "UNKNOWN");
  10.494 -		break;
  10.495 -	}
  10.496 -}
  10.497 -
  10.498 -void _error(const char *fmt, ...)
  10.499 -{
  10.500 -	va_list ap;
  10.501 -	char buffer[4096];
  10.502 -
  10.503 -	va_start(ap, fmt);
  10.504 -	vsnprintf(buffer, sizeof(buffer), fmt, ap);
  10.505 -	va_end(ap);
  10.506 -
  10.507 -	fprintf(stderr, "%s\n", buffer);
  10.508 -}
  10.509 -
    11.1 --- a/tools/xcs/dump.h	Wed Sep 07 18:37:55 2005 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,28 +0,0 @@
    11.4 -/*\
    11.5 - *  Copyright (C) International Business Machines  Corp., 2005
    11.6 - *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    11.7 - *
    11.8 - *  This program is free software; you can redistribute it and/or modify
    11.9 - *  it under the terms of the GNU General Public License as published by
   11.10 - *  the Free Software Foundation; under version 2 of the License.
   11.11 - * 
   11.12 - *  This program is distributed in the hope that it will be useful,
   11.13 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 - *  GNU General Public License for more details.
   11.16 - * 
   11.17 - *  You should have received a copy of the GNU General Public License
   11.18 - *  along with this program; if not, write to the Free Software
   11.19 - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.20 -\*/
   11.21 -
   11.22 -#ifndef XENCTLD_ERROR_H
   11.23 -#define XENCTLD_ERROR_H
   11.24 -
   11.25 -#include <stdint.h>
   11.26 -#include <xenctrl.h>
   11.27 -#include <xen/io/domain_controller.h>
   11.28 -
   11.29 -void dump_msg(const control_msg_t *msg, uint64_t flags);
   11.30 -
   11.31 -#endif
    12.1 --- a/tools/xcs/evtchn.c	Wed Sep 07 18:37:55 2005 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,106 +0,0 @@
    12.4 -/* evtchn.c
    12.5 - *
    12.6 - * Interfaces to event channel driver.
    12.7 - *
    12.8 - * Most of this is directly based on the original xu interface to python 
    12.9 - * written by Keir Fraser.
   12.10 - *
   12.11 - * (c) 2004, Andrew Warfield
   12.12 - *
   12.13 - */
   12.14 - 
   12.15 -#include <stdio.h>
   12.16 -#include <stdlib.h>
   12.17 -#include <sys/ioctl.h>
   12.18 -#include <sys/stat.h>
   12.19 -#include <sys/sysmacros.h> /* XOPEN drops makedev, this gets it back. */
   12.20 -#include <fcntl.h>
   12.21 -#include <unistd.h>
   12.22 -#include <errno.h>
   12.23 -#include "xcs.h"
   12.24 -
   12.25 -static int evtchn_fd = -1;
   12.26 -
   12.27 -/* NB. The following should be kept in sync with the kernel's evtchn driver. */
   12.28 -#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
   12.29 -#define EVTCHN_DEV_MAJOR 10
   12.30 -#define EVTCHN_DEV_MINOR 201
   12.31 -/* /dev/xen/evtchn ioctls: */
   12.32 -/* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
   12.33 -#define EVTCHN_RESET  _IO('E', 1)
   12.34 -/* EVTCHN_BIND: Bind to teh specified event-channel port. */
   12.35 -#define EVTCHN_BIND   _IO('E', 2)
   12.36 -/* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
   12.37 -#define EVTCHN_UNBIND _IO('E', 3)
   12.38 -
   12.39 -int evtchn_read()
   12.40 -{
   12.41 -    u16 v;
   12.42 -    int bytes;
   12.43 -
   12.44 -    while ( (bytes = read(evtchn_fd, &v, sizeof(v))) == -1 )
   12.45 -    {
   12.46 -        if ( errno == EINTR )
   12.47 -            continue;
   12.48 -        /* EAGAIN was cased to return 'None' in the python version... */
   12.49 -        return -errno;
   12.50 -    }
   12.51 -    
   12.52 -    if ( bytes == sizeof(v) )
   12.53 -        return v;
   12.54 -    
   12.55 -    /* bad return */
   12.56 -    return -1;
   12.57 -}
   12.58 -
   12.59 -void evtchn_unmask(u16 idx)
   12.60 -{
   12.61 -    (void)write(evtchn_fd, &idx, sizeof(idx));
   12.62 -}
   12.63 -
   12.64 -int evtchn_bind(int idx)
   12.65 -{
   12.66 -    if ( ioctl(evtchn_fd, EVTCHN_BIND, idx) != 0 )
   12.67 -        return -errno;
   12.68 -    
   12.69 -    return 0;
   12.70 -}
   12.71 -
   12.72 -int evtchn_unbind(int idx)
   12.73 -{
   12.74 -    if ( ioctl(evtchn_fd, EVTCHN_UNBIND, idx) != 0 )
   12.75 -        return -errno;
   12.76 -
   12.77 -    return 0;
   12.78 -}
   12.79 -
   12.80 -int evtchn_open(void)
   12.81 -{
   12.82 -    struct stat st;
   12.83 -    
   12.84 -    /* Make sure any existing device file links to correct device. */
   12.85 -    if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) ||
   12.86 -         !S_ISCHR(st.st_mode) ||
   12.87 -         (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) )
   12.88 -        (void)unlink(EVTCHN_DEV_NAME);
   12.89 -
   12.90 - reopen:
   12.91 -    evtchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR); 
   12.92 -    if ( evtchn_fd == -1 )
   12.93 -    {
   12.94 -        if ( (errno == ENOENT) &&
   12.95 -             ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
   12.96 -             (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, 
   12.97 -                    makedev(EVTCHN_DEV_MAJOR,EVTCHN_DEV_MINOR)) == 0) )
   12.98 -            goto reopen;
   12.99 -        return -errno;
  12.100 -    }
  12.101 -    return evtchn_fd;
  12.102 -}
  12.103 -
  12.104 -void evtchn_close()
  12.105 -{
  12.106 -    (void)close(evtchn_fd);
  12.107 -    evtchn_fd = -1;
  12.108 -}
  12.109 -
    13.1 --- a/tools/xcs/xcs.c	Wed Sep 07 18:37:55 2005 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,973 +0,0 @@
    13.4 -/* xcs.c 
    13.5 - *
    13.6 - * xcs - Xen Control Switch
    13.7 - *
    13.8 - * Copyright (c) 2004, Andrew Warfield
    13.9 - */
   13.10 - 
   13.11 -/*
   13.12 -
   13.13 -  Things we need to select on in xcs:
   13.14 -  
   13.15 -  1. Events arriving on /dev/evtchn
   13.16 -  
   13.17 -    These will kick a function to read everything off the fd, and scan the
   13.18 -    associated control message rings, resulting in notifications sent on
   13.19 -    data channels to connected clients.
   13.20 -    
   13.21 -  2. New TCP connections on XCS_PORT.
   13.22 -  
   13.23 -    These will either be control (intially) or associated data connections.
   13.24 -    
   13.25 -    Control connections will instantiate or rebind to an existing connnection
   13.26 -    struct.  The control channel is used to configure what events will be 
   13.27 -    received on an associated data channel.  These two channels are split
   13.28 -    out because the control channel is synchronous, all messages will return
   13.29 -    a result from XCS.  The data channel is effectively asynchronous, events
   13.30 -    may arrive in the middle of a control message exchange.  Additionally, 
   13.31 -    Having two TCP connections allows the client side to have a blocking
   13.32 -    listen loop for data messages, while independently interacting on the 
   13.33 -    control channel at other places in the code.
   13.34 -    
   13.35 -    Data connections attach to an existing control struct, using a session
   13.36 -    id that is passed during the control connect.  There is currently a 
   13.37 -    one-to-one relationship between data and control channels, but there
   13.38 -    could just as easily be many data channels, if there were a set of 
   13.39 -    clients with identical interests, or if you wanted to trace an existing
   13.40 -    client's data traffic.
   13.41 -    
   13.42 - 3. Messages arriving on open TCP connections.
   13.43 -    There are three types of open connections:
   13.44 -     
   13.45 -    3a. Messages arriving on open control channel file descriptors.
   13.46 - 
   13.47 -        [description of the control protocol here]
   13.48 - 
   13.49 -    3b. Messages arriving on open data channel file descriptors.
   13.50 - 
   13.51 -        [description of the data protocol here]
   13.52 -        
   13.53 -    3c. Messages arriving on (new) unbound connections.
   13.54 -    
   13.55 -        A connection must issue a XCS_CONNECT message to specify what
   13.56 -        it is, after which the connection is moved into one of the above 
   13.57 -        two groups.
   13.58 - 
   13.59 - Additionally, we need a periodic timer to do housekeeping.
   13.60 - 
   13.61 - 4. Every XCS_GC_INTERVAL seconds, we need to clean up outstanding state. 
   13.62 -    Specifically, we garbage collect any sessions (connection_t structs)
   13.63 -    that have been unconnected for a period of time (XCS_SESSION_TIMEOUT), 
   13.64 -    and close any connections that have been openned, but not connected
   13.65 -    as a control or data connection (XCS_UFD_TIMEOUT).
   13.66 -
   13.67 -*/
   13.68 -
   13.69 -#include <stdlib.h>
   13.70 -#include <stdio.h>
   13.71 -#include <unistd.h>
   13.72 -#include <sys/time.h>
   13.73 -#include <sys/types.h>
   13.74 -#include <string.h>
   13.75 -#include <signal.h>
   13.76 -#include <sys/socket.h>
   13.77 -#include <sys/un.h>
   13.78 -#include <errno.h>
   13.79 -#include <malloc.h>
   13.80 -#include <fcntl.h>
   13.81 -#include <ctype.h>
   13.82 -#include "xcs.h"
   13.83 -
   13.84 -#undef fd_max
   13.85 -#define fd_max(x,y) ((x) > (y) ? (x) : (y))
   13.86 -
   13.87 -/* ------[ Control channel interfaces ]------------------------------------*/
   13.88 -
   13.89 -static control_channel_t *cc_list[NR_EVENT_CHANNELS];
   13.90 -static int *dom_port_map = 0;
   13.91 -static int dom_port_map_size = 0;
   13.92 -
   13.93 -static void map_dom_to_port(u32 dom, int port)
   13.94 -{
   13.95 -    if (dom >= dom_port_map_size) {
   13.96 -        dom_port_map = (int *)realloc(dom_port_map,
   13.97 -                                      (dom + 256) * sizeof(dom_port_map[0]));
   13.98 -
   13.99 -        if (dom_port_map == NULL) {
  13.100 -            perror("realloc(dom_port_map)");
  13.101 -            exit(1);
  13.102 -        }
  13.103 -
  13.104 -        for (; dom_port_map_size < dom + 256; dom_port_map_size++) {
  13.105 -            dom_port_map[dom_port_map_size] = -1;
  13.106 -        }
  13.107 -    }
  13.108 -
  13.109 -    dom_port_map[dom] = port;
  13.110 -}
  13.111 -
  13.112 -static int dom_to_port(u32 dom) 
  13.113 -{
  13.114 -    if (dom >= dom_port_map_size) return -1;
  13.115 -
  13.116 -    return dom_port_map[dom];
  13.117 -}
  13.118 -
  13.119 -static void init_interfaces(void)
  13.120 -{
  13.121 -    memset(cc_list, 0, sizeof cc_list);
  13.122 -}
  13.123 -
  13.124 -static control_channel_t *add_interface(u32 dom, int local_port, 
  13.125 -                                        int remote_port)
  13.126 -{
  13.127 -    control_channel_t *cc=NULL, *oldcc;
  13.128 -    int ret;
  13.129 -    
  13.130 -    if ((dom_to_port(dom) >= 0) && (cc_list[dom_to_port(dom)] != NULL))
  13.131 -    {
  13.132 -        return(cc_list[dom_to_port(dom)]);
  13.133 -    }
  13.134 -    
  13.135 -    if (cc_list[local_port] == NULL) 
  13.136 -    {
  13.137 -        cc = ctrl_chan_new(dom, local_port, remote_port);
  13.138 -    }
  13.139 -    
  13.140 -    if (cc == NULL)
  13.141 -        return NULL;
  13.142 -    
  13.143 -    DPRINTF("added a new interface: dom: %u (l:%d,r:%d): %p\n",
  13.144 -            dom, local_port, remote_port, cc);
  13.145 -    DPRINTF("added a new interface: dom: %u (l:%d,r:%d): %p\n",
  13.146 -            dom, cc->local_port, cc->remote_port, cc);
  13.147 -    
  13.148 -    if ((ret = evtchn_bind(cc->local_port)) != 0)
  13.149 -    {
  13.150 -        DPRINTF("Got control interface, but couldn't bind evtchan!(%d)\n", ret);
  13.151 -        ctrl_chan_free(cc);
  13.152 -        return NULL;
  13.153 -    }
  13.154 -    
  13.155 -    if ( cc_list[cc->local_port] != NULL )
  13.156 -    {
  13.157 -        oldcc = cc_list[cc->local_port];
  13.158 -        
  13.159 -        if ((oldcc->remote_dom != cc->remote_dom) ||
  13.160 -            (oldcc->remote_port != cc->remote_port))
  13.161 -        {
  13.162 -            DPRINTF("CC conflict! (port: %d, old dom: %u, new dom: %u, "
  13.163 -                    "old ref_count: %d)\n",
  13.164 -                    cc->local_port, oldcc->remote_dom, cc->remote_dom, 
  13.165 -                    oldcc->ref_count);
  13.166 -            map_dom_to_port(oldcc->remote_dom, -1);
  13.167 -            ctrl_chan_free(cc_list[cc->local_port]);
  13.168 -            cc_list[cc->local_port] = NULL;
  13.169 -        }
  13.170 -    }
  13.171 -     
  13.172 -    cc_list[cc->local_port] = cc;
  13.173 -    map_dom_to_port(cc->remote_dom, cc->local_port);
  13.174 -    cc->type = CC_TYPE_INTERDOMAIN;
  13.175 -    cc->ref_count = 0;
  13.176 -    return cc;
  13.177 -}
  13.178 -
  13.179 -control_channel_t *add_virq(int virq)
  13.180 -{
  13.181 -    control_channel_t *cc;
  13.182 -    int virq_port;
  13.183 -    
  13.184 -    if (ctrl_chan_bind_virq(virq, &virq_port) == -1)
  13.185 -        return NULL;
  13.186 -    
  13.187 -    if ((cc_list[virq_port]       != NULL) && 
  13.188 -        (cc_list[virq_port]->type != CC_TYPE_VIRQ))
  13.189 -        return NULL; 
  13.190 -    
  13.191 -    if ((cc_list[virq_port]       != NULL) && 
  13.192 -        (cc_list[virq_port]->type == CC_TYPE_VIRQ))
  13.193 -        return cc_list[virq_port]; 
  13.194 -    
  13.195 -    cc = (control_channel_t *)malloc(sizeof(control_channel_t));
  13.196 -    if ( cc == NULL ) return NULL;
  13.197 -
  13.198 -    memset(cc, 0, sizeof(control_channel_t));
  13.199 -    cc->type       = CC_TYPE_VIRQ;
  13.200 -    cc->local_port = virq_port;
  13.201 -    cc->virq       = virq;
  13.202 -    cc->ref_count  = 1;
  13.203 -    
  13.204 -    if (evtchn_bind(cc->local_port) != 0)
  13.205 -    {
  13.206 -        DPRINTF("Got control interface, but couldn't bind evtchan!\n");
  13.207 -        free(cc);
  13.208 -        return NULL;
  13.209 -    }
  13.210 -
  13.211 -    cc_list[cc->local_port] = cc;
  13.212 -
  13.213 -    return cc;
  13.214 -}
  13.215 -
  13.216 -void get_interface(control_channel_t *cc)
  13.217 -{
  13.218 -    if (cc != NULL)
  13.219 -        cc->ref_count++;
  13.220 -}
  13.221 -    
  13.222 -void put_interface(control_channel_t *cc)
  13.223 -{
  13.224 -    if (cc != NULL)
  13.225 -    {
  13.226 -        cc->ref_count--;
  13.227 -        if (cc->ref_count <= 0)
  13.228 -        {
  13.229 -            DPRINTF("Freeing cc on port %d.\n", cc->local_port);
  13.230 -            (void)evtchn_unbind(cc->local_port);
  13.231 -            cc_list[cc->local_port] = NULL;
  13.232 -            map_dom_to_port(cc->remote_dom, -1);
  13.233 -            ctrl_chan_free(cc);
  13.234 -        }
  13.235 -    }
  13.236 -}
  13.237 -
  13.238 -/* ------[ Simple helpers ]------------------------------------------------*/
  13.239 -
  13.240 -/* listen_socket() is straight from paul sheer's useful select_tut manpage. */
  13.241 -static int listen_socket (char *listen_path) 
  13.242 -{
  13.243 -    struct sockaddr_un a;
  13.244 -    int s;
  13.245 -    int yes;
  13.246 -
  13.247 -    if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) 
  13.248 -    {
  13.249 -        perror ("socket");
  13.250 -        return -1;
  13.251 -    }
  13.252 -    
  13.253 -    yes = 1;
  13.254 -
  13.255 -    memset (&a, 0, sizeof (a));
  13.256 -    a.sun_family = AF_UNIX;
  13.257 -    strcpy(a.sun_path, listen_path);
  13.258 -
  13.259 -    /* remove an old socket if it exists. */
  13.260 -    unlink(listen_path);
  13.261 -
  13.262 -    if (bind(s, (struct sockaddr *) &a, sizeof (a)) < 0) 
  13.263 -    {
  13.264 -        fprintf (stderr, "bind('%s'): %s\n", listen_path, strerror(errno));
  13.265 -        close (s);
  13.266 -        return -1;
  13.267 -    }
  13.268 -    DPRINTF ("accepting connections on path %s\n", listen_path);
  13.269 -    listen (s, 10);
  13.270 -    return s;
  13.271 -}
  13.272 -
  13.273 -/* ------[ Message handlers ]----------------------------------------------*/
  13.274 -
  13.275 -#define NO_CHANGE     0
  13.276 -#define CONNECTED     1
  13.277 -#define DISCONNECTED  2
  13.278 -int handle_connect_msg( xcs_msg_t *msg, int fd )
  13.279 -{
  13.280 -    xcs_connect_msg_t *cmsg = &msg->u.connect;
  13.281 -    connection_t *con;
  13.282 -    int ret = NO_CHANGE;
  13.283 -    
  13.284 -    switch (msg->type)
  13.285 -    {
  13.286 -        case XCS_CONNECT_CTRL:
  13.287 -        {
  13.288 -            if ( cmsg->session_id == 0 )
  13.289 -            {
  13.290 -                con = connection_new();
  13.291 -                if ( con == NULL)
  13.292 -                {
  13.293 -                    msg->result = XCS_RSLT_FAILED;
  13.294 -                    break;
  13.295 -                }
  13.296 -                msg->result      = XCS_RSLT_OK;
  13.297 -                cmsg->session_id = con->id;
  13.298 -                con->ctrl_fd     = fd;
  13.299 -                ret = CONNECTED;
  13.300 -                DPRINTF("New control connection\n");
  13.301 -                break;
  13.302 -            }
  13.303 -
  13.304 -            con = get_con_by_session(cmsg->session_id);
  13.305 -            if ( con == NULL )
  13.306 -            {
  13.307 -                msg->result = XCS_RSLT_BADSESSION;
  13.308 -                break;
  13.309 -            }
  13.310 -            if ( con->ctrl_fd != -1 )
  13.311 -            {
  13.312 -                msg->result = XCS_RSLT_CONINUSE;
  13.313 -                break;
  13.314 -            }
  13.315 -            con->ctrl_fd   = fd;
  13.316 -            msg->result   = XCS_RSLT_OK;
  13.317 -            ret = CONNECTED;
  13.318 -            DPRINTF("Rebound to control connection\n");
  13.319 -            break;
  13.320 -        }
  13.321 -        case XCS_CONNECT_DATA:
  13.322 -        {
  13.323 -            con = get_con_by_session(cmsg->session_id);
  13.324 -            if ( con == NULL )
  13.325 -            {
  13.326 -                msg->result = XCS_RSLT_BADSESSION;
  13.327 -                break;
  13.328 -            }
  13.329 -            if ( con->data_fd != -1 )
  13.330 -            {
  13.331 -                msg->result = XCS_RSLT_CONINUSE;
  13.332 -                break;
  13.333 -            }
  13.334 -            con->data_fd   = fd;
  13.335 -            msg->result   = XCS_RSLT_OK;
  13.336 -            ret = CONNECTED;
  13.337 -            DPRINTF("Attached data connection\n");
  13.338 -            break;
  13.339 -
  13.340 -        }
  13.341 -        case XCS_CONNECT_BYE:
  13.342 -        {
  13.343 -            close ( fd );
  13.344 -            ret = DISCONNECTED;
  13.345 -            break;
  13.346 -        }
  13.347 -    }   
  13.348 -    
  13.349 -    return ret;
  13.350 -}
  13.351 -
  13.352 -int handle_control_message( connection_t *con, xcs_msg_t *msg )
  13.353 -{
  13.354 -    int ret;
  13.355 -    int reply_needed = 1;
  13.356 -            
  13.357 -    DPRINTF("Got message, type %u.\n", msg->type);
  13.358 -
  13.359 -    switch (msg->type)
  13.360 -    {
  13.361 -        case XCS_MSG_BIND:
  13.362 -        {
  13.363 -            xcs_bind_msg_t *bmsg = &msg->u.bind;
  13.364 -
  13.365 -            if ( ! BIND_MSG_VALID(bmsg) )
  13.366 -            {
  13.367 -                msg->result = XCS_RSLT_BADREQUEST;
  13.368 -                break;
  13.369 -            }
  13.370 -            
  13.371 -            ret = xcs_bind(con, bmsg->port, bmsg->type);
  13.372 -            if (ret == 0) {
  13.373 -                msg->result = XCS_RSLT_OK;
  13.374 -            } else {
  13.375 -                msg->result = XCS_RSLT_FAILED;
  13.376 -            }
  13.377 -            break;
  13.378 -        }
  13.379 -        case XCS_MSG_UNBIND:
  13.380 -        {
  13.381 -            xcs_bind_msg_t *bmsg = &msg->u.bind;
  13.382 -
  13.383 -            if ( ! BIND_MSG_VALID(bmsg) )
  13.384 -            {
  13.385 -                msg->result = XCS_RSLT_BADREQUEST;
  13.386 -                break;
  13.387 -            }
  13.388 -            
  13.389 -            ret = xcs_unbind(con, bmsg->port, bmsg->type);
  13.390 -            if (ret == 0) {
  13.391 -                msg->result = XCS_RSLT_OK;
  13.392 -            } else {
  13.393 -                msg->result = XCS_RSLT_FAILED;
  13.394 -            }
  13.395 -            break;
  13.396 -        }    
  13.397 -        case XCS_VIRQ_BIND:
  13.398 -        {
  13.399 -            control_channel_t *cc;
  13.400 -            xcs_virq_msg_t *vmsg = &msg->u.virq;
  13.401 -            if ( ! VIRQ_MSG_VALID(vmsg) )
  13.402 -            {
  13.403 -                msg->result = XCS_RSLT_BADREQUEST;
  13.404 -                break;
  13.405 -            }
  13.406 -
  13.407 -            cc = add_virq(vmsg->virq);
  13.408 -            if (cc == NULL)
  13.409 -            {
  13.410 -                msg->result = XCS_RSLT_FAILED;
  13.411 -                break;
  13.412 -            }
  13.413 -            ret = xcs_bind(con, cc->local_port, TYPE_VIRQ);
  13.414 -            if (ret == 0) {
  13.415 -                vmsg->port   = cc->local_port;
  13.416 -                msg->result  = XCS_RSLT_OK;
  13.417 -            } else {
  13.418 -                msg->result = XCS_RSLT_FAILED;
  13.419 -            }
  13.420 -            break;
  13.421 -        }
  13.422 -
  13.423 -        case XCS_CIF_NEW_CC:
  13.424 -        {
  13.425 -            control_channel_t *cc;
  13.426 -            xcs_interface_msg_t *imsg = &msg->u.interface;
  13.427 -
  13.428 -            if ( ! INTERFACE_MSG_VALID(imsg) )
  13.429 -            {
  13.430 -                msg->result = XCS_RSLT_BADREQUEST;
  13.431 -                break;
  13.432 -            }
  13.433 -
  13.434 -            cc = add_interface(imsg->dom, imsg->local_port, imsg->remote_port);
  13.435 -            if (cc != NULL) {
  13.436 -                get_interface(cc);
  13.437 -                msg->result       = XCS_RSLT_OK;
  13.438 -                imsg->local_port  = cc->local_port;
  13.439 -                imsg->remote_port = cc->remote_port;
  13.440 -            } else {
  13.441 -                msg->result = XCS_RSLT_FAILED;
  13.442 -            }
  13.443 -            break;
  13.444 -        }
  13.445 -
  13.446 -        case XCS_CIF_FREE_CC:
  13.447 -        {
  13.448 -            control_channel_t *cc;
  13.449 -            xcs_interface_msg_t *imsg = &msg->u.interface;
  13.450 -
  13.451 -            if ( ! INTERFACE_MSG_VALID(imsg) )
  13.452 -            {
  13.453 -                msg->result = XCS_RSLT_BADREQUEST;
  13.454 -                break;
  13.455 -            }
  13.456 -
  13.457 -            cc = add_interface(imsg->dom, imsg->local_port, imsg->remote_port);
  13.458 -            if (cc != NULL) {
  13.459 -                put_interface(cc);
  13.460 -            } 
  13.461 -            msg->result       = XCS_RSLT_OK;
  13.462 -            break;
  13.463 -        }
  13.464 -    }
  13.465 -    return reply_needed;
  13.466 -}
  13.467 -
  13.468 -void handle_data_message( connection_t *con, xcs_msg_t *msg )
  13.469 -{
  13.470 -    control_channel_t *cc;
  13.471 -    xcs_control_msg_t *cmsg = &msg->u.control;
  13.472 -    int port;
  13.473 -    
  13.474 -    switch (msg->type)
  13.475 -    {
  13.476 -    case XCS_REQUEST:
  13.477 -        if ( cmsg->remote_dom > MAX_DOMS )
  13.478 -            break;
  13.479 -        
  13.480 -        port = dom_to_port(cmsg->remote_dom);
  13.481 -        if (port == -1) break;
  13.482 -        cc = cc_list[port];
  13.483 -        if ((cc != NULL) && ( cc->type == CC_TYPE_INTERDOMAIN ))
  13.484 -        {
  13.485 -            DPRINTF("DN:REQ: dom:%d port: %d type: %d\n", 
  13.486 -                    cc->remote_dom, cc->local_port, 
  13.487 -                    cmsg->msg.type);
  13.488 -            ctrl_chan_write_request(cc, cmsg);
  13.489 -            ctrl_chan_notify(cc);
  13.490 -        } else {
  13.491 -            DPRINTF("tried to send a REQ to a null cc\n.");
  13.492 -        }
  13.493 -        break;
  13.494 -
  13.495 -    case XCS_RESPONSE:
  13.496 -        if ( cmsg->remote_dom > MAX_DOMS )
  13.497 -            break;
  13.498 -        
  13.499 -        port = dom_to_port(cmsg->remote_dom);
  13.500 -        if (port == -1) break;
  13.501 -        cc = cc_list[port];
  13.502 -        if ((cc != NULL) && ( cc->type == CC_TYPE_INTERDOMAIN ))
  13.503 -        {
  13.504 -            DPRINTF("DN:RSP: dom:%d port: %d type: %d\n", 
  13.505 -                    cc->remote_dom, cc->local_port, 
  13.506 -                    cmsg->msg.type);
  13.507 -            ctrl_chan_write_response(cc, cmsg);
  13.508 -            ctrl_chan_notify(cc);
  13.509 -        }
  13.510 -        break;
  13.511 -
  13.512 -    case XCS_VIRQ:
  13.513 -        if ( !(PORT_VALID(cmsg->local_port)) )
  13.514 -            break;
  13.515 -            
  13.516 -        cc = cc_list[cmsg->local_port];
  13.517 -        
  13.518 -        if ((cc != NULL) && ( cc->type == CC_TYPE_VIRQ ))
  13.519 -        {
  13.520 -            DPRINTF("DN:VIRQ:  virq: %d port: %d\n", 
  13.521 -                    cc->virq, cc->local_port);
  13.522 -            ctrl_chan_notify(cc);
  13.523 -        }
  13.524 -        break;
  13.525 -    }
  13.526 -}
  13.527 -    
  13.528 -/* ------[ Control interface handler ]-------------------------------------*/
  13.529 -
  13.530 -/* passed as a function pointer to the lookup. */
  13.531 -void send_kmsg(connection_t *c, void *arg)
  13.532 -{
  13.533 -    xcs_msg_t *msg = (xcs_msg_t *)arg;
  13.534 -
  13.535 -    DPRINTF("       -> CONNECTION %d\n", c->data_fd);
  13.536 -    if (c->data_fd > 0)
  13.537 -    {
  13.538 -      send(c->data_fd, msg, sizeof(xcs_msg_t), 0);
  13.539 -    }
  13.540 -}
  13.541 -
  13.542 -int handle_ctrl_if(void)
  13.543 -{
  13.544 -    control_channel_t *cc;
  13.545 -    control_msg_t     *msg;
  13.546 -    xcs_msg_t          kmsg;
  13.547 -    int                chan, ret;
  13.548 -    
  13.549 -    DPRINTF("Event thread kicked!\n");
  13.550 -again:
  13.551 -    while ((chan = evtchn_read()) > 0)
  13.552 -    {
  13.553 -        evtchn_unmask(chan);
  13.554 -        cc = cc_list[chan];
  13.555 -        if (cc_list[chan] == NULL) {
  13.556 -            DPRINTF("event from unknown channel (%d)\n", chan);
  13.557 -            continue;
  13.558 -        }
  13.559 -
  13.560 -        if ( cc_list[chan]->type == CC_TYPE_VIRQ )
  13.561 -        {
  13.562 -            DPRINTF("UP:VIRQ: virq:%d port: %d\n",
  13.563 -                    cc->virq, cc->local_port);
  13.564 -            kmsg.type = XCS_VIRQ;
  13.565 -            kmsg.u.control.local_port = cc->local_port;
  13.566 -            xcs_lookup(cc->local_port, TYPE_VIRQ, send_kmsg, &kmsg);
  13.567 -            continue;
  13.568 -        }
  13.569 -
  13.570 -        while (ctrl_chan_request_to_read(cc))
  13.571 -        {
  13.572 -            msg = &kmsg.u.control.msg;
  13.573 -            kmsg.type = XCS_REQUEST;
  13.574 -            kmsg.u.control.remote_dom = cc->remote_dom;
  13.575 -            kmsg.u.control.local_port = cc->local_port;
  13.576 -            ret = ctrl_chan_read_request(cc, &kmsg.u.control);
  13.577 -            DPRINTF("UP:REQ: dom:%d port: %d type: %d len: %d\n", 
  13.578 -                    cc->remote_dom, cc->local_port, 
  13.579 -                    msg->type, msg->length);
  13.580 -            if (ret == 0)
  13.581 -                xcs_lookup(cc->local_port, msg->type, send_kmsg, &kmsg);
  13.582 -        }
  13.583 -
  13.584 -        while (ctrl_chan_response_to_read(cc))
  13.585 -        {
  13.586 -            msg = &kmsg.u.control.msg;
  13.587 -            kmsg.type = XCS_RESPONSE;
  13.588 -            kmsg.u.control.remote_dom = cc->remote_dom;
  13.589 -            kmsg.u.control.local_port = cc->local_port;
  13.590 -            ret = ctrl_chan_read_response(cc, &kmsg.u.control);
  13.591 -            DPRINTF("UP:RSP: dom:%d port: %d type: %d len: %d\n", 
  13.592 -                    cc->remote_dom, cc->local_port, 
  13.593 -                    msg->type, msg->length);
  13.594 -            if (ret == 0)
  13.595 -                xcs_lookup(cc->local_port, msg->type, send_kmsg, &kmsg);
  13.596 -        }
  13.597 -    }
  13.598 -    
  13.599 -    if (chan == -EINTR)
  13.600 -        goto again;
  13.601 -    
  13.602 -    return chan;
  13.603 -}
  13.604 -
  13.605 -  
  13.606 -/* ------[ Main xcs code / big select loop ]-------------------------------*/
  13.607 -
  13.608 -                
  13.609 -typedef struct unbound_fd_st {
  13.610 -    int                   fd;
  13.611 -    struct timeval        born;
  13.612 -    struct unbound_fd_st *next;
  13.613 -} unbound_fd_t;
  13.614 -
  13.615 -/* This makes ufd point to the next entry in the list, so need to   *
  13.616 - * break/continue if called while iterating.                        */
  13.617 -void delete_ufd(unbound_fd_t **ufd)
  13.618 -{
  13.619 -    unbound_fd_t *del_ufd;
  13.620 -    
  13.621 -    del_ufd = *ufd;
  13.622 -    *ufd    = (*ufd)->next;
  13.623 -    free( del_ufd );
  13.624 -}
  13.625 -
  13.626 -void gc_ufd_list( unbound_fd_t **ufd )
  13.627 -{
  13.628 -    struct timeval now, delta;
  13.629 -    
  13.630 -    gettimeofday(&now, NULL);
  13.631 -    
  13.632 -    while ( *ufd != NULL )
  13.633 -    {
  13.634 -        timersub(&now, &(*ufd)->born, &delta);
  13.635 -        if (delta.tv_sec > XCS_UFD_TIMEOUT)
  13.636 -        {
  13.637 -            DPRINTF("GC-UFD: closing fd: %d\n", (*ufd)->fd);
  13.638 -            close((*ufd)->fd);
  13.639 -            delete_ufd(ufd);
  13.640 -            continue;
  13.641 -        }
  13.642 -        ufd = &(*ufd)->next;
  13.643 -    }
  13.644 -}
  13.645 -
  13.646 -void daemonize_xcs(void)
  13.647 -{
  13.648 -    
  13.649 -    /* detach from our controlling tty so that a shell does hang waiting for
  13.650 -       stopped jobs. */
  13.651 -    
  13.652 -    pid_t pid = fork();
  13.653 -    int fd;
  13.654 -
  13.655 -    if (pid == -1) {
  13.656 -	    perror("fork()");
  13.657 -    } else if (pid) {
  13.658 -	    exit(0);
  13.659 -    }
  13.660 -
  13.661 -    fd = open("/var/log/xcs.log", O_WRONLY | O_APPEND | O_CREAT);
  13.662 -    if ( fd == -1 ) {
  13.663 -        fprintf(stderr, "xcs couldn't open logfile.  Directing all output to "
  13.664 -                "/dev/null instead.\n");
  13.665 -        fd = open("/dev/null", O_WRONLY);
  13.666 -    }
  13.667 -    
  13.668 -    setsid();
  13.669 -    close(2);
  13.670 -    close(1);
  13.671 -    close(0);
  13.672 -    dup(fd);
  13.673 -    dup(fd);
  13.674 -}
  13.675 -
  13.676 -
  13.677 -static char *pidfilename = NULL;
  13.678 -void cleanup(int sig)
  13.679 -{
  13.680 -    /* throw away our pidfile if we created one. */
  13.681 -    if ( pidfilename != NULL ) 
  13.682 -        unlink(pidfilename);
  13.683 -    exit(0);
  13.684 -}
  13.685 -
  13.686 -int main (int argc, char *argv[])
  13.687 -{
  13.688 -    int listen_fd, evtchn_fd;
  13.689 -    unbound_fd_t *unbound_fd_list = NULL, **ufd;
  13.690 -    struct timeval timeout = { XCS_GC_INTERVAL, 0 };
  13.691 -    connection_t **con;
  13.692 -    int c, daemonize;
  13.693 -    FILE *pidfile;
  13.694 -    struct stat s;
  13.695 -    
  13.696 -    daemonize = 1;
  13.697 -    pidfile = NULL;
  13.698 -
  13.699 -    signal(SIGHUP, cleanup);
  13.700 -    signal(SIGTERM, cleanup);
  13.701 -    signal(SIGINT, cleanup);
  13.702 -    
  13.703 -    /* Do a bunch of stuff before potentially daemonizing so we can 
  13.704 -     * print error messages sanely before redirecting output. */
  13.705 -    
  13.706 -    /* Initialize xc and event connections. */
  13.707 -    if (ctrl_chan_init() != 0)
  13.708 -    {
  13.709 -        printf("Couldn't open conneciton to libxc.\n");
  13.710 -        exit(-1);
  13.711 -    }
  13.712 -    
  13.713 -    if ((evtchn_fd = evtchn_open()) < 0)
  13.714 -    {
  13.715 -        printf("Couldn't open event channel driver interface.\n");
  13.716 -        exit(-1);
  13.717 -    }
  13.718 -   
  13.719 -    /* Bind listen_fd to the client socket. */
  13.720 -    listen_fd = listen_socket(XCS_SUN_PATH);
  13.721 -     
  13.722 -    while ((c = getopt (argc, argv, "ip:")) != -1)
  13.723 -    {
  13.724 -        switch (c)
  13.725 -        {
  13.726 -        case 'i': /* interactive */
  13.727 -            daemonize = 0;
  13.728 -            break;
  13.729 -        case 'p': /* pid file */
  13.730 -            pidfilename = optarg;
  13.731 -            break;          
  13.732 -        case '?':
  13.733 -            if (isprint (optopt))
  13.734 -                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
  13.735 -            else
  13.736 -                fprintf (stderr,
  13.737 -                    "Bad option character `\\x%x'.\n", optopt);
  13.738 -            break;
  13.739 -        }    
  13.740 -    }
  13.741 -    
  13.742 -    if ( pidfilename != NULL )
  13.743 -    {
  13.744 -        if ( stat(pidfilename, &s) == 0 )
  13.745 -        {
  13.746 -            fprintf(stderr, "Thre specified pid file (%s) already exists.\n"
  13.747 -                    "Is another instance of xcs running?\n", pidfilename);
  13.748 -            exit(-1);
  13.749 -        }
  13.750 -
  13.751 -        pidfile = fopen(pidfilename, "w");
  13.752 -        if (pidfile == NULL)
  13.753 -        {
  13.754 -            fprintf(stderr, "Error openning pidfile (%s).\n", pidfilename);
  13.755 -            exit(-1);
  13.756 -        }
  13.757 -    }
  13.758 -        
  13.759 -    if (daemonize == 1) 
  13.760 -        daemonize_xcs();
  13.761 -    
  13.762 -    if (pidfile != NULL)
  13.763 -    {
  13.764 -        fprintf(pidfile, "%d", getpid());
  13.765 -        fclose(pidfile); 
  13.766 -    }
  13.767 -    
  13.768 -    
  13.769 -    /* Initialize control interfaces, bindings. */
  13.770 -    init_interfaces();
  13.771 -    init_bindings();
  13.772 -    
  13.773 -   
  13.774 -    for (;;)
  13.775 -    {
  13.776 -        int n = 0, ret;
  13.777 -        fd_set rd, wr, er;
  13.778 -        FD_ZERO ( &rd );
  13.779 -        FD_ZERO ( &wr );
  13.780 -        FD_ZERO ( &er );
  13.781 -        
  13.782 -        /* TCP listen fd: */
  13.783 -        FD_SET ( listen_fd, &rd );
  13.784 -        n = fd_max ( n, listen_fd );
  13.785 -        
  13.786 -        /* Evtchn fd: */
  13.787 -        FD_SET ( evtchn_fd, &rd );
  13.788 -        n = fd_max ( n, evtchn_fd );
  13.789 -        
  13.790 -        /* unbound connection fds: */
  13.791 -        ufd = &unbound_fd_list;
  13.792 -        while ((*ufd) != NULL) 
  13.793 -        {
  13.794 -            FD_SET ( (*ufd)->fd, &rd );
  13.795 -            n = fd_max ( n, (*ufd)->fd );
  13.796 -            ufd = &(*ufd)->next;
  13.797 -        }
  13.798 -        
  13.799 -        /* control and data fds: */
  13.800 -        con = &connection_list;
  13.801 -        while ((*con) != NULL)
  13.802 -        {
  13.803 -            if ((*con)->ctrl_fd > 0)
  13.804 -            {
  13.805 -                FD_SET ( (*con)->ctrl_fd, &rd );
  13.806 -                n = fd_max ( n, (*con)->ctrl_fd );
  13.807 -            }
  13.808 -            if ((*con)->data_fd > 0)
  13.809 -            {
  13.810 -                FD_SET ( (*con)->data_fd, &rd );
  13.811 -                n = fd_max ( n, (*con)->data_fd );
  13.812 -            }
  13.813 -            con = &(*con)->next;
  13.814 -        }
  13.815 -        
  13.816 -        ret = select ( n + 1, &rd, &wr, &er, &timeout );
  13.817 -        
  13.818 -        if ( (timeout.tv_sec == 0) && (timeout.tv_usec == 0) )
  13.819 -        {
  13.820 -            gc_ufd_list(&unbound_fd_list);
  13.821 -            gc_connection_list();
  13.822 -            timeout.tv_sec = XCS_GC_INTERVAL;
  13.823 -        }
  13.824 -        
  13.825 -        if ( (ret == -1) && (errno == EINTR) )
  13.826 -            continue;
  13.827 -        if ( ret < 0 )
  13.828 -        {
  13.829 -            perror ("select()");
  13.830 -            exit(-1);
  13.831 -        }
  13.832 -        
  13.833 -        /* CASE 1: Events arriving on /dev/evtchn. */
  13.834 -        
  13.835 -        if ( FD_ISSET (evtchn_fd, &rd ))
  13.836 -            handle_ctrl_if();
  13.837 -        
  13.838 -        /* CASE 2: New connection on the listen port. */
  13.839 -        if ( FD_ISSET ( listen_fd, &rd ))
  13.840 -        {
  13.841 -            struct sockaddr_un remote_addr;
  13.842 -            int size;
  13.843 -            memset (&remote_addr, 0, sizeof (remote_addr));
  13.844 -            size = sizeof remote_addr;
  13.845 -            ret = accept(listen_fd, (struct sockaddr *)&remote_addr, (socklen_t *)&size);
  13.846 -            if ( ret < 0 )
  13.847 -            {
  13.848 -                perror("accept()");
  13.849 -            } else {
  13.850 -                unbound_fd_t *new_ufd;
  13.851 -                
  13.852 -                new_ufd = (unbound_fd_t *)malloc(sizeof(*new_ufd));
  13.853 -                
  13.854 -                if (new_ufd != NULL)
  13.855 -                {
  13.856 -                    gettimeofday(&new_ufd->born, NULL);
  13.857 -                    new_ufd->fd     = ret;
  13.858 -                    new_ufd->next   = unbound_fd_list;
  13.859 -                    unbound_fd_list = new_ufd; 
  13.860 -                } else {
  13.861 -                    perror("malloc unbound connection");
  13.862 -                    close(ret);
  13.863 -                }
  13.864 -            }
  13.865 -        }
  13.866 -        
  13.867 -        /* CASE 3a: Handle messages on control connections. */
  13.868 -        
  13.869 -        con = &connection_list;
  13.870 -        while ( *con != NULL )
  13.871 -        {
  13.872 -            if ( ((*con)->ctrl_fd > 0) && (FD_ISSET((*con)->ctrl_fd, &rd)) )
  13.873 -            {
  13.874 -                xcs_msg_t msg;
  13.875 -                memset (&msg, 0, sizeof(msg));
  13.876 -                ret = read( (*con)->ctrl_fd, &msg, sizeof(msg) );
  13.877 -                
  13.878 -                if ( ret < 0 )
  13.879 -                {
  13.880 -                    perror("reading ctrl fd.");
  13.881 -                } else if ( ret == 0 )
  13.882 -                {
  13.883 -                    DPRINTF("Control connection dropped.\n");
  13.884 -                    close ( (*con)->ctrl_fd );
  13.885 -                    (*con)->ctrl_fd = -1;
  13.886 -                    gettimeofday(&(*con)->disconnect_time, NULL);
  13.887 -                } else 
  13.888 -                {
  13.889 -                    if ( ret != sizeof(msg) )
  13.890 -                    {
  13.891 -                        DPRINTF("Unexpected frame size!\n");
  13.892 -                        continue;
  13.893 -                    }
  13.894 -                    
  13.895 -                    ret = handle_control_message( *con, &msg );
  13.896 -                    
  13.897 -                    if ( ret == 1 )
  13.898 -                        send( (*con)->ctrl_fd, &msg, sizeof(msg), 0 );
  13.899 -                }
  13.900 -            }
  13.901 -            con = &(*con)->next;
  13.902 -        }
  13.903 -        
  13.904 -        /* CASE 3b: Handle messages on data connections. */
  13.905 -        
  13.906 -        con = &connection_list;
  13.907 -        while ( *con != NULL )
  13.908 -        {
  13.909 -            if ( ((*con)->data_fd > 0) && (FD_ISSET((*con)->data_fd, &rd)) )
  13.910 -            {
  13.911 -                xcs_msg_t msg;
  13.912 -                memset (&msg, 0, sizeof(msg));
  13.913 -                ret = read( (*con)->data_fd, &msg, sizeof(msg) );
  13.914 -                
  13.915 -                if ( ret < 0 )
  13.916 -                {
  13.917 -                    perror("reading data fd.");
  13.918 -                } else if ( ret == 0 )
  13.919 -                {
  13.920 -                    DPRINTF("Data connection dropped.\n");
  13.921 -                    close ( (*con)->data_fd );
  13.922 -                    (*con)->data_fd = -1;
  13.923 -                    gettimeofday(&(*con)->disconnect_time, NULL);
  13.924 -                } else 
  13.925 -                {
  13.926 -                    if ( ret != sizeof(msg) )
  13.927 -                    {
  13.928 -                        DPRINTF("Unexpected frame size!\n");
  13.929 -                        continue;
  13.930 -                    }
  13.931 -                    
  13.932 -                    handle_data_message( *con, &msg );
  13.933 -                }
  13.934 -            }
  13.935 -            con = &(*con)->next;
  13.936 -        }
  13.937 -        
  13.938 -        /* CASE 3c: Handle messages arriving on unbound connections. */
  13.939 -        ufd = &unbound_fd_list;
  13.940 -        while ((*ufd) != NULL)
  13.941 -        {
  13.942 -            if ( FD_ISSET( (*ufd)->fd, &rd ) )
  13.943 -            {
  13.944 -                xcs_msg_t msg;
  13.945 -                memset (&msg, 0, sizeof(msg));
  13.946 -                ret = read( (*ufd)->fd, &msg, sizeof(msg) );
  13.947 -                
  13.948 -                if ( ret == 0 )
  13.949 -                {
  13.950 -                    close ( (*ufd)->fd );
  13.951 -                    delete_ufd(ufd);
  13.952 -                    continue; /* we just advanced ufd */
  13.953 -                } else {
  13.954 -                    if ( ret != sizeof(msg) )
  13.955 -                    {
  13.956 -                        DPRINTF("Unexpected frame size!\n");
  13.957 -                        continue;
  13.958 -                    }
  13.959 -                    
  13.960 -                    ret = handle_connect_msg( &msg, (*ufd)->fd );
  13.961 -                    
  13.962 -                    if ( (ret == CONNECTED) || (ret == NO_CHANGE) )
  13.963 -                        send( (*ufd)->fd, &msg, sizeof(msg), 0 );
  13.964 -                    
  13.965 -                    if ( (ret = CONNECTED) || (ret = DISCONNECTED) )
  13.966 -                    {
  13.967 -                        delete_ufd( ufd );
  13.968 -                        continue;
  13.969 -                    }
  13.970 -                }
  13.971 -            }
  13.972 -            ufd = &(*ufd)->next;
  13.973 -        }
  13.974 -    }
  13.975 -}
  13.976 -
    14.1 --- a/tools/xcs/xcs.h	Wed Sep 07 18:37:55 2005 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,148 +0,0 @@
    14.4 -/* xcs.h
    14.5 - *
    14.6 - * public interfaces for the control interface switch (xcs).
    14.7 - *
    14.8 - * (c) 2004, Andrew Warfield
    14.9 - *
   14.10 - */
   14.11 -
   14.12 -
   14.13 -#ifndef __XCS_H__
   14.14 -#define __XCS_H__
   14.15 -
   14.16 -#include <pthread.h>
   14.17 -#include <xenctrl.h>
   14.18 -#include <xen/xen.h>
   14.19 -#include <xen/io/domain_controller.h>
   14.20 -#include <xen/linux/privcmd.h>
   14.21 -#include <sys/time.h>
   14.22 -#include "xcs_proto.h"
   14.23 -
   14.24 -/* ------[ Debug macros ]--------------------------------------------------*/
   14.25 -
   14.26 -#if 0
   14.27 -#define DPRINTF(_f, _a...) printf ( _f , ## _a )
   14.28 -#else
   14.29 -#define DPRINTF(_f, _a...) ((void)0)
   14.30 -#endif
   14.31 -
   14.32 -/* ------[ XCS-specific defines and types ]--------------------------------*/
   14.33 -
   14.34 -#define MAX_DOMS            1024
   14.35 -#define XCS_SESSION_TIMEOUT   10 /* (secs) disconnected session gc timeout */
   14.36 -#define XCS_UFD_TIMEOUT        5 /* how long can connections be unbound?   */
   14.37 -#define XCS_GC_INTERVAL        5 /* How often to run gc handlers.          */
   14.38 -
   14.39 -
   14.40 -/* ------[ Other required defines ]----------------------------------------*/
   14.41 -
   14.42 -/* Size of a machine page frame. */
   14.43 -#define PAGE_SIZE XC_PAGE_SIZE
   14.44 -
   14.45 -#ifndef timersub /* XOPEN and __BSD don't cooperate well... */
   14.46 -#define timersub(a, b, result)                                                \
   14.47 -  do {                                                                        \
   14.48 -    (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
   14.49 -    (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
   14.50 -    if ((result)->tv_usec < 0) {                                              \
   14.51 -      --(result)->tv_sec;                                                     \
   14.52 -      (result)->tv_usec += 1000000;                                           \
   14.53 -    }                                                                         \
   14.54 -  } while (0)
   14.55 -#endif /*timersub*/
   14.56 -
   14.57 -/* ------[ Bindings Interface ]--------------------------------------------*/
   14.58 -
   14.59 -/*forward declare connection_t */
   14.60 -typedef struct connection_st connection_t;
   14.61 -
   14.62 -typedef struct {
   14.63 -    int    port;
   14.64 -    u16    type;
   14.65 -} binding_key_t;
   14.66 -
   14.67 -typedef struct binding_key_ent_st {
   14.68 -    binding_key_t              key;
   14.69 -    struct binding_key_ent_st *next;
   14.70 -} binding_key_ent_t;
   14.71 -
   14.72 -#define BINDING_KEYS_EQUAL(_k1, _k2) \
   14.73 -    (((_k1)->port == (_k2)->port) && ((_k1)->type == (_k2)->type))
   14.74 -
   14.75 -int  xcs_bind(connection_t *con, int port, u16 type);
   14.76 -int  xcs_unbind(connection_t *con, int port, u16 type);
   14.77 -void xcs_lookup(int port, u16 type, void (*f)(connection_t *, void *), 
   14.78 -        void *arg);
   14.79 -void init_bindings(void);
   14.80 -
   14.81 -/* ------[ Connection Interface ]------------------------------------------*/
   14.82 -
   14.83 -struct connection_st {
   14.84 -    unsigned long      id;              /* Unique session id             */
   14.85 -    int                ctrl_fd;         /* TCP descriptors               */
   14.86 -    int                data_fd;         /*                               */
   14.87 -    binding_key_ent_t *bindings;        /* List of bindings              */
   14.88 -    connection_t      *next;            /* Linked list of connections    */
   14.89 -    struct timeval     disconnect_time; /*  "            "               */
   14.90 -}; /* previously typedefed as connection_t */
   14.91 -
   14.92 -
   14.93 -extern connection_t *connection_list;
   14.94 -
   14.95 -connection_t *get_con_by_session(unsigned long session_id);
   14.96 -connection_t *connection_new();
   14.97 -void connection_free(connection_t *con);
   14.98 -int  connection_add_binding(connection_t *con, binding_key_t *key);
   14.99 -int  connection_remove_binding(connection_t *con, binding_key_t *key);
  14.100 -int  connection_has_binding(connection_t *con, binding_key_t *key);
  14.101 -void gc_connection_list(void);
  14.102 -
  14.103 -/* ------[ Control Channel Interfaces ]------------------------------------*/
  14.104 - 
  14.105 -typedef struct {
  14.106 -    int               connected;
  14.107 -    int               ref_count;
  14.108 -    int               type;
  14.109 -    u32               remote_dom;
  14.110 -    int               local_port;
  14.111 -    int               remote_port;
  14.112 -    control_if_t     *interface;
  14.113 -    ctrl_back_ring_t  tx_ring;
  14.114 -    ctrl_front_ring_t rx_ring;
  14.115 -    int               virq;
  14.116 -} control_channel_t;
  14.117 -
  14.118 -/* cc types that we care about */
  14.119 -#define CC_TYPE_INTERDOMAIN  0
  14.120 -#define CC_TYPE_VIRQ         1
  14.121 -
  14.122 -control_channel_t 
  14.123 -     *ctrl_chan_new(u32 dom, int local_port, int remote_port);
  14.124 -void  ctrl_chan_free(control_channel_t *cc);
  14.125 -int   ctrl_chan_init(void);
  14.126 -int   ctrl_chan_notify(control_channel_t *cc);
  14.127 -int   ctrl_chan_read_request(control_channel_t *cc, xcs_control_msg_t *);
  14.128 -int   ctrl_chan_write_request(control_channel_t *cc, 
  14.129 -                            xcs_control_msg_t *smsg);
  14.130 -int   ctrl_chan_read_response(control_channel_t *cc, xcs_control_msg_t *);
  14.131 -int   ctrl_chan_write_response(control_channel_t *cc, 
  14.132 -                             xcs_control_msg_t *smsg);
  14.133 -int   ctrl_chan_request_to_read(control_channel_t *cc);
  14.134 -int   ctrl_chan_space_to_write_request(control_channel_t *cc);
  14.135 -int   ctrl_chan_response_to_read(control_channel_t *cc);
  14.136 -int   ctrl_chan_space_to_write_response(control_channel_t *cc);
  14.137 -int   ctrl_chan_connect(control_channel_t *cc);
  14.138 -void  ctrl_chan_disconnect(control_channel_t *cc);
  14.139 -int   ctrl_chan_bind_virq(int virq, int *port);
  14.140 -
  14.141 -/* ------[ Event notification interfaces ]---------------------------------*/
  14.142 -
  14.143 -
  14.144 -int   evtchn_open(void);
  14.145 -void  evtchn_close();
  14.146 -int   evtchn_bind(int idx);
  14.147 -int   evtchn_unbind(int idx);
  14.148 -void  evtchn_unmask(u16 idx);
  14.149 -int   evtchn_read();
  14.150 -
  14.151 -#endif /* __XCS_H__ */
    15.1 --- a/tools/xcs/xcs_proto.h	Wed Sep 07 18:37:55 2005 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,101 +0,0 @@
    15.4 -/* xcs_proto.h
    15.5 - *
    15.6 - * protocol interfaces for the control interface switch (xcs).
    15.7 - *
    15.8 - * (c) 2004, Andrew Warfield
    15.9 - *
   15.10 - */
   15.11 -
   15.12 -#ifndef  __XCS_PROTO_H__
   15.13 -#define  __XCS_PROTO_H__
   15.14 -
   15.15 -#define XCS_SUN_PATH     "/var/lib/xen/xcs_socket"
   15.16 -
   15.17 -/* xcs message types: */
   15.18 -#define XCS_CONNECT_CTRL       0 /* This is a control connection.     */
   15.19 -#define XCS_CONNECT_DATA       1 /* This is a data connection.        */
   15.20 -#define XCS_CONNECT_BYE        2 /* Terminate a session.              */
   15.21 -#define XCS_MSG_BIND           3 /* Register for a message type.      */
   15.22 -#define XCS_MSG_UNBIND         4 /* Unregister for a message type.    */
   15.23 -#define XCS_VIRQ_BIND          5 /* Register for a virq.              */
   15.24 -#define XCS_MSG_WRITELOCK      6 /* Writelock a (dom,type) pair.      */
   15.25 -#define XCS_CIF_NEW_CC         7 /* Create a new control channel.     */
   15.26 -#define XCS_CIF_FREE_CC        8 /* Create a new control channel.     */
   15.27 -#define XCS_REQUEST            9 /* This is a request message.        */
   15.28 -#define XCS_RESPONSE          10 /* this is a response Message.       */
   15.29 -#define XCS_VIRQ              11 /* this is a virq notification.      */
   15.30 -
   15.31 -/* xcs result values: */
   15.32 -#define XCS_RSLT_OK            0
   15.33 -#define XCS_RSLT_FAILED        1 /* something bad happened.           */
   15.34 -#define XCS_RSLT_ARECONNECTED  2 /* attempt to over connect.          */
   15.35 -#define XCS_RSLT_BADSESSION    3 /* request for unknown session id.   */
   15.36 -#define XCS_RSLT_NOSESSION     4 /* tried to do something before NEW. */
   15.37 -#define XCS_RSLT_CONINUSE      5 /* Requested connection is taken.    */
   15.38 -#define XCS_RSLT_BADREQUEST    6 /* Request message didn't validate.  */
   15.39 -
   15.40 -/* Binding wildcards */
   15.41 -#define PORT_WILDCARD  0xefffffff
   15.42 -#define TYPE_WILDCARD  0xffff
   15.43 -#define TYPE_VIRQ      0xfffe
   15.44 -
   15.45 -typedef struct {
   15.46 -    unsigned long  session_id;
   15.47 -} xcs_connect_msg_t;
   15.48 -
   15.49 -typedef struct {
   15.50 -    int port;
   15.51 -    u16 type;  
   15.52 -} xcs_bind_msg_t;
   15.53 -
   15.54 -typedef struct {
   15.55 -    int port;
   15.56 -    u16 virq;  
   15.57 -} xcs_virq_msg_t;
   15.58 -
   15.59 -typedef struct {
   15.60 -    u32 dom;
   15.61 -    int local_port;
   15.62 -    int remote_port;
   15.63 -} xcs_interface_msg_t;
   15.64 -
   15.65 -typedef struct {
   15.66 -    u32           remote_dom;
   15.67 -    int           local_port;
   15.68 -    control_msg_t msg;
   15.69 -} xcs_control_msg_t;
   15.70 -
   15.71 -typedef struct {
   15.72 -    u32 type;
   15.73 -    u32 result;
   15.74 -    union {
   15.75 -        xcs_connect_msg_t   connect;   /* These are xcs ctrl message types */
   15.76 -        xcs_bind_msg_t      bind;
   15.77 -        xcs_virq_msg_t      virq;
   15.78 -        xcs_interface_msg_t interface;
   15.79 -        
   15.80 -        xcs_control_msg_t   control;   /* These are xcs data message types */
   15.81 -    } u;
   15.82 -} xcs_msg_t;
   15.83 -
   15.84 -/* message validation macros. */
   15.85 -#define PORT_VALID(_p)                                                 \
   15.86 -    ( (((_p) >= 0) && ((_p) < NR_EVENT_CHANNELS))                      \
   15.87 -    || ((_p) == PORT_WILDCARD) )
   15.88 -
   15.89 -#define TYPE_VALID(_t)                                                 \
   15.90 -    (  ((_t) < 256)                                                    \
   15.91 -    || ((_t) == TYPE_VIRQ)                                             \
   15.92 -    || ((_t) == TYPE_WILDCARD) )
   15.93 -
   15.94 -#define BIND_MSG_VALID(_b)                                             \
   15.95 -    ( PORT_VALID((_b)->port) && TYPE_VALID((_b)->type) )
   15.96 -    
   15.97 -/* Port is overwritten, and we don't currently validate the requested virq. */
   15.98 -#define VIRQ_MSG_VALID(_v) ( 1 )
   15.99 -    
  15.100 -/* Interfaces may return with ports of -1, but may not be requested as such */
  15.101 -#define INTERFACE_MSG_VALID(_i)                                        \
  15.102 -    ( PORT_VALID((_i)->local_port) && PORT_VALID((_i)->remote_port) )
  15.103 -
  15.104 -#endif /* __XCS_PROTO_H__ */
    16.1 --- a/tools/xcs/xcsdump.c	Wed Sep 07 18:37:55 2005 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,206 +0,0 @@
    16.4 -/* xcsdump.c
    16.5 - *
    16.6 - * little tool to sniff control messages.
    16.7 - *
    16.8 - * Copyright (c) 2004, Andrew Warfield
    16.9 - *
   16.10 - * Modifications by Anthony Liguori <aliguori@us.ibm.com> are:
   16.11 - *   Copyright (C) 2005, International Business Machines, Corp.
   16.12 - */
   16.13 -
   16.14 -#include <stdio.h>
   16.15 -#include <stdlib.h>
   16.16 -#include <string.h>
   16.17 -#include <unistd.h>
   16.18 -#include <sys/types.h>
   16.19 -#include <sys/socket.h>
   16.20 -#include <sys/un.h>
   16.21 -#include <ctype.h>
   16.22 -#include <xenctrl.h>
   16.23 -#include <xen/xen.h>
   16.24 -#include <xen/io/domain_controller.h>
   16.25 -#include <getopt.h>
   16.26 -#include "xcs_proto.h"
   16.27 -#include "xcs.h"
   16.28 -
   16.29 -#include "dump.h"
   16.30 -
   16.31 -static int xcs_ctrl_fd = -1; /* connection to the xcs server. */
   16.32 -static int xcs_data_fd = -1; /* connection to the xcs server. */
   16.33 -
   16.34 -int sock_connect(char *path)
   16.35 -{
   16.36 -    struct sockaddr_un addr;
   16.37 -    int ret, len, fd;
   16.38 -
   16.39 -    fd = socket(AF_UNIX, SOCK_STREAM, 0);
   16.40 -    if (fd < 0)
   16.41 -    {
   16.42 -        printf("error creating xcs socket!\n");
   16.43 -        return -1;
   16.44 -    }
   16.45 -
   16.46 -    addr.sun_family = AF_UNIX;
   16.47 -    strcpy(addr.sun_path, path);
   16.48 -    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
   16.49 -
   16.50 -    ret = connect(fd, (struct sockaddr *)&addr, len);
   16.51 -    if (ret < 0) 
   16.52 -    {
   16.53 -        printf("error connecting to xcs!\n");
   16.54 -        return -1;
   16.55 -    }
   16.56 -    
   16.57 -    return fd;
   16.58 -}
   16.59 -
   16.60 -void sock_disconnect(int *fd)
   16.61 -{
   16.62 -    close(*fd);
   16.63 -    *fd = -1;
   16.64 -}
   16.65 -
   16.66 -void xcs_read(int fd, xcs_msg_t *msg)
   16.67 -{
   16.68 -    int ret;
   16.69 -    
   16.70 -    ret = read(fd, msg, sizeof(xcs_msg_t));
   16.71 -    if (ret != sizeof(xcs_msg_t)) {
   16.72 -        printf("read error\n");
   16.73 -        exit(-1);
   16.74 -    }
   16.75 -}
   16.76 -
   16.77 -void xcs_send(int fd, xcs_msg_t *msg)
   16.78 -{
   16.79 -    int ret;
   16.80 -    
   16.81 -    ret = send(fd, msg, sizeof(xcs_msg_t), 0);
   16.82 -    if (ret != sizeof(xcs_msg_t) )
   16.83 -    {
   16.84 -        printf("send error\n");
   16.85 -        exit(-1);
   16.86 -    }
   16.87 -}
   16.88 -              
   16.89 -
   16.90 -int main(int argc, char* argv[])
   16.91 -{
   16.92 -    int ret;
   16.93 -    xcs_msg_t msg;
   16.94 -    control_msg_t *cmsg;
   16.95 -    int verbose = 0;
   16.96 -    int ch;
   16.97 -
   16.98 -    while ((ch = getopt(argc, argv, "hv:")) != -1)
   16.99 -    {
  16.100 -        switch (ch)
  16.101 -        {
  16.102 -        case 'v':
  16.103 -            verbose = atoi(optarg);
  16.104 -            break;
  16.105 -        case 'h':
  16.106 -  	    printf("Usage: %s [-v FLAGS]\n"
  16.107 -"Displays XCS control message traffic.\n"
  16.108 -"\n"
  16.109 -"FLAGS is a bitmask where each bit (numbering starts from LSB) represents\n"
  16.110 -"whether to display a particular message type.\n"
  16.111 -"\n"
  16.112 -"For example, -v 1022 will display all messages except for console messages.\n"
  16.113 -		   , argv[0]);
  16.114 -	    exit(0);
  16.115 -	    break;
  16.116 -        }
  16.117 -    }
  16.118 -    
  16.119 -    ret = sock_connect(XCS_SUN_PATH);
  16.120 -    if (ret < 0) 
  16.121 -    {
  16.122 -        printf("connect failed!\n"); 
  16.123 -        exit(-1);
  16.124 -    }
  16.125 -    xcs_ctrl_fd = ret;
  16.126 -    
  16.127 -    memset(&msg, 0, sizeof(msg));
  16.128 -    msg.type = XCS_CONNECT_CTRL;
  16.129 -    xcs_send(xcs_ctrl_fd, &msg);
  16.130 -    xcs_read(xcs_ctrl_fd, &msg);
  16.131 -    if (msg.result != XCS_RSLT_OK)
  16.132 -    {
  16.133 -        printf("Error connecting control channel\n");
  16.134 -        exit(-1);
  16.135 -    }
  16.136 -    
  16.137 -    ret = sock_connect(XCS_SUN_PATH);
  16.138 -    if (ret < 0) 
  16.139 -    {
  16.140 -        printf("connect failed!\n"); 
  16.141 -        exit(-1);
  16.142 -    }
  16.143 -    xcs_data_fd = ret;
  16.144 -    
  16.145 -    msg.type = XCS_CONNECT_DATA;
  16.146 -    /* session id is set from before... */
  16.147 -    xcs_send(xcs_data_fd, &msg);
  16.148 -    xcs_read(xcs_data_fd, &msg);
  16.149 -    if (msg.result != XCS_RSLT_OK)
  16.150 -    {
  16.151 -        printf("Error connecting data channel\n");
  16.152 -        exit(-1);
  16.153 -    }
  16.154 -    
  16.155 -    msg.type = XCS_MSG_BIND;
  16.156 -    msg.u.bind.port = PORT_WILDCARD;
  16.157 -    msg.u.bind.type = TYPE_WILDCARD;
  16.158 -    xcs_send(xcs_ctrl_fd, &msg);
  16.159 -    xcs_read(xcs_ctrl_fd, &msg);
  16.160 -    if (msg.result != XCS_RSLT_OK)
  16.161 -    {
  16.162 -        printf("Error binding.\n");
  16.163 -        exit(-1);
  16.164 -    }
  16.165 -    
  16.166 -    
  16.167 -    while (1)
  16.168 -    {
  16.169 -        xcs_read(xcs_data_fd, &msg);
  16.170 -        cmsg = &msg.u.control.msg;
  16.171 -        
  16.172 -        switch (msg.type)
  16.173 -        {
  16.174 -        case XCS_REQUEST:
  16.175 -  	    if (!verbose || verbose & (1 << msg.u.control.msg.type))
  16.176 -            {
  16.177 -	        printf("[REQUEST ] : (dom:%u port:%d) (type:(%d,%d) len %d)\n",
  16.178 -		       msg.u.control.remote_dom,
  16.179 -		       msg.u.control.local_port,
  16.180 -		       msg.u.control.msg.type, 
  16.181 -		       msg.u.control.msg.subtype, 
  16.182 -		       msg.u.control.msg.length);
  16.183 -
  16.184 -		dump_msg(cmsg, verbose);
  16.185 -	    }
  16.186 -	    break; 
  16.187 -        case XCS_RESPONSE:
  16.188 -  	    if (!verbose || verbose & (1 << msg.u.control.msg.type))
  16.189 -            {
  16.190 -	        printf("[RESPONSE] : (dom:%u port:%d) (type:(%d,%d) len %d)\n",
  16.191 -		       msg.u.control.remote_dom,
  16.192 -		       msg.u.control.local_port,
  16.193 -		       msg.u.control.msg.type, 
  16.194 -		       msg.u.control.msg.subtype, 
  16.195 -		       msg.u.control.msg.length);
  16.196 -
  16.197 -		dump_msg(cmsg, verbose);
  16.198 -	    }
  16.199 -	    break;
  16.200 -        case XCS_VIRQ:
  16.201 -            printf("[VIRQ    ] : %d\n", msg.u.control.local_port);
  16.202 -	    break;
  16.203 -        default:
  16.204 -            printf("[UNKNOWN ] : %d\n", msg.type);
  16.205 -        }
  16.206 -    }
  16.207 -    
  16.208 -    return(0);
  16.209 -}
    17.1 --- a/tools/xenstore/Makefile	Wed Sep 07 18:37:55 2005 +0000
    17.2 +++ b/tools/xenstore/Makefile	Wed Sep 07 19:01:05 2005 +0000
    17.3 @@ -15,7 +15,6 @@ PROG_DEP = .*.d
    17.4  BASECFLAGS+= -O3 $(PROFILE)
    17.5  #BASECFLAGS+= -I$(XEN_ROOT)/tools
    17.6  BASECFLAGS+= -I$(XEN_ROOT)/tools/libxc
    17.7 -BASECFLAGS+= -I$(XEN_ROOT)/tools/xcs
    17.8  BASECFLAGS+= -I$(XEN_ROOT)/xen/include/public
    17.9  BASECFLAGS+= -I.
   17.10  BASECFLAGS+= -I$(XEN_ROOT)/linux-2.6-xen-sparse/include/asm-xen/linux-public