ia64/xen-unstable

changeset 3939:d8cf61e99a52

bitkeeper revision 1.1236.1.29 (421facf0U_Bl4zERFH7SO_Vg0H8Ebg)

Move xcs to unix domain sockets.

signed-off-by: akw27@cl.cam.ac.uk
author akw27@arcadians.cl.cam.ac.uk
date Fri Feb 25 22:55:44 2005 +0000 (2005-02-25)
parents da55822ba1b5
children 6a7bbb8b60f4
files tools/misc/xend tools/python/xen/lowlevel/xu/xu.c tools/xcs/xcs.c tools/xcs/xcs_proto.h tools/xcs/xcsdump.c
line diff
     1.1 --- a/tools/misc/xend	Fri Feb 25 20:56:40 2005 +0000
     1.2 +++ b/tools/misc/xend	Fri Feb 25 22:55:44 2005 +0000
     1.3 @@ -24,7 +24,7 @@ import sys
     1.4  import socket
     1.5  import time
     1.6  
     1.7 -XCS_PORT = 1633
     1.8 +XCS_PATH = "/var/xen/xcs_socket"
     1.9  XCS_EXEC = "/usr/sbin/xcs"
    1.10  XCS_LOGFILE = "/var/log/xcs.log"
    1.11  
    1.12 @@ -100,9 +100,9 @@ def xcs_running():
    1.13      """ See if the control switch is running.
    1.14      """
    1.15      ret = 1
    1.16 -    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    1.17 +    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    1.18      try:
    1.19 -        s.connect( ("127.0.0.1", XCS_PORT) )
    1.20 +        s.connect( (XCS_PATH) )
    1.21      except:
    1.22          ret = 0
    1.23      s.close()
    1.24 @@ -118,7 +118,7 @@ def main():
    1.25      
    1.26      if (not xcs_running()):
    1.27          if os.fork():
    1.28 -            time.sleep(1) # let xcs start
    1.29 +            time.usleep(500) # let xcs start
    1.30          else:
    1.31              try:
    1.32                  logfile = os.open(XCS_LOGFILE, 
     2.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Fri Feb 25 20:56:40 2005 +0000
     2.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Fri Feb 25 22:55:44 2005 +0000
     2.3 @@ -13,10 +13,10 @@
     2.4  #include <sys/wait.h>
     2.5  #include <sys/stat.h>
     2.6  #include <sys/socket.h>
     2.7 +#include <sys/un.h>
     2.8  #include <sys/mman.h>
     2.9  #include <sys/poll.h>
    2.10  #include <sys/sysmacros.h>
    2.11 -#include <netinet/in.h>
    2.12  #include <fcntl.h>
    2.13  #include <unistd.h>
    2.14  #include <errno.h>
    2.15 @@ -87,36 +87,34 @@ static int xcs_ctrl_read(xcs_msg_t *msg)
    2.16  static int xcs_data_send(xcs_msg_t *msg);
    2.17  static int xcs_data_read(xcs_msg_t *msg);
    2.18  
    2.19 -static int xcs_connect(char *ip, short port)
    2.20 +static int xcs_connect(char *path)
    2.21  {
    2.22 -    struct sockaddr_in addr;
    2.23 -    int ret, flags;
    2.24 +    struct sockaddr_un addr;
    2.25 +    int ret, len, flags;
    2.26      xcs_msg_t msg;
    2.27  
    2.28      if (xcs_data_fd != -1) /* already connected */
    2.29          return 0;
    2.30      
    2.31 -    xcs_ctrl_fd = socket(AF_INET, SOCK_STREAM, 0);
    2.32 +    xcs_ctrl_fd = socket(AF_UNIX, SOCK_STREAM, 0);
    2.33      if (xcs_ctrl_fd < 0)
    2.34      {
    2.35          printf("error creating xcs socket!\n");
    2.36          goto fail;
    2.37      }
    2.38      
    2.39 -    addr.sin_family = AF_INET;
    2.40 -    addr.sin_port = htons(port);
    2.41 -    addr.sin_addr.s_addr = inet_addr(ip);
    2.42 -    memset(&(addr.sin_zero), '\0', 8);
    2.43 +    addr.sun_family = AF_UNIX;
    2.44 +    strcpy(addr.sun_path, path);
    2.45 +    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
    2.46  
    2.47 -    ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, 
    2.48 -            sizeof(struct sockaddr));
    2.49 +    ret = connect(xcs_ctrl_fd, (struct sockaddr *)&addr, len);
    2.50      if (ret < 0) 
    2.51      {
    2.52          printf("error connecting to xcs(ctrl)! (%d)\n", errno);
    2.53          goto ctrl_fd_fail;
    2.54      }
    2.55  
    2.56 -    //set_cloexec(xcs_ctrl_fd);
    2.57 +    /*set_cloexec(xcs_ctrl_fd);*/
    2.58              
    2.59      msg.type = XCS_CONNECT_CTRL;
    2.60      msg.u.connect.session_id = xcs_session_id;
    2.61 @@ -131,20 +129,18 @@ static int xcs_connect(char *ip, short p
    2.62      xcs_session_id = msg.u.connect.session_id;
    2.63      
    2.64      /* now the data connection. */
    2.65 -    xcs_data_fd = socket(AF_INET, SOCK_STREAM, 0);
    2.66 +    xcs_data_fd = socket(AF_UNIX, SOCK_STREAM, 0);
    2.67      if (xcs_data_fd < 0)
    2.68      {
    2.69          printf("error creating xcs data socket!\n");
    2.70          goto ctrl_fd_fail;
    2.71      }
    2.72      
    2.73 -    addr.sin_family = AF_INET;
    2.74 -    addr.sin_port = htons(port);
    2.75 -    addr.sin_addr.s_addr = inet_addr(ip);
    2.76 -    memset(&(addr.sin_zero), '\0', 8);
    2.77 +    addr.sun_family = AF_UNIX;
    2.78 +    strcpy(addr.sun_path, path);
    2.79 +    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
    2.80      
    2.81 -    ret = connect(xcs_data_fd, (struct sockaddr *)&addr, 
    2.82 -            sizeof(struct sockaddr));
    2.83 +    ret = connect(xcs_data_fd, (struct sockaddr *)&addr, len);
    2.84      if (ret < 0) 
    2.85      {
    2.86          printf("error connecting to xcs(data)! (%d)\n", errno);
    2.87 @@ -447,7 +443,7 @@ static PyObject *xu_notifier_new(PyObjec
    2.88      for (i = 0; i < XCS_RING_SIZE; i++) 
    2.89          REQ_RING_ENT(i) = RSP_RING_ENT(i) = NULL;
    2.90      
    2.91 -    (void)xcs_connect("127.0.0.1", XCS_TCP_PORT);
    2.92 +    (void)xcs_connect(XCS_SUN_PATH);
    2.93      
    2.94  
    2.95      return (PyObject *)xun;
     3.1 --- a/tools/xcs/xcs.c	Fri Feb 25 20:56:40 2005 +0000
     3.2 +++ b/tools/xcs/xcs.c	Fri Feb 25 22:55:44 2005 +0000
     3.3 @@ -71,8 +71,7 @@
     3.4  #include <string.h>
     3.5  #include <signal.h>
     3.6  #include <sys/socket.h>
     3.7 -#include <netinet/in.h>
     3.8 -#include <arpa/inet.h>
     3.9 +#include <sys/un.h>
    3.10  #include <errno.h>
    3.11  #include <malloc.h>
    3.12  #include <fcntl.h>
    3.13 @@ -89,27 +88,28 @@ static int dom_port_map_size = 0;
    3.14  
    3.15  static void map_dom_to_port(u32 dom, int port)
    3.16  {
    3.17 -	if (dom >= dom_port_map_size) {
    3.18 -		dom_port_map = (int *)realloc(dom_port_map,
    3.19 -					      (dom + 10) * sizeof(dom_port_map[0]));
    3.20 +    if (dom >= dom_port_map_size) {
    3.21 +        dom_port_map = (int *)realloc(dom_port_map,
    3.22 +                                      (dom + 256) * sizeof(dom_port_map[0]));
    3.23  
    3.24 -		if (dom_port_map == NULL) {
    3.25 -			perror("realloc(dom_port_map)");
    3.26 -			exit(1);
    3.27 -		}
    3.28 +        if (dom_port_map == NULL) {
    3.29 +            perror("realloc(dom_port_map)");
    3.30 +            exit(1);
    3.31 +        }
    3.32  
    3.33 -		for (; dom_port_map_size < dom + 10; dom_port_map_size++) {
    3.34 -			dom_port_map[dom_port_map_size] = -1;
    3.35 -		}
    3.36 -	}
    3.37 +        for (; dom_port_map_size < dom + 10; dom_port_map_size++) {
    3.38 +            dom_port_map[dom_port_map_size] = -1;
    3.39 +        }
    3.40 +    }
    3.41  
    3.42 -	dom_port_map[dom] = port;
    3.43 +    dom_port_map[dom] = port;
    3.44  }
    3.45  
    3.46 -static int dom_to_port(u32 dom) {
    3.47 -	if (dom >= dom_port_map_size) return -1;
    3.48 +static int dom_to_port(u32 dom) 
    3.49 +{
    3.50 +    if (dom >= dom_port_map_size) return -1;
    3.51  
    3.52 -	return dom_port_map[dom];
    3.53 +    return dom_port_map[dom];
    3.54  }
    3.55  
    3.56  static void init_interfaces(void)
    3.57 @@ -218,37 +218,34 @@ void put_interface(control_channel_t *cc
    3.58  /* ------[ Simple helpers ]------------------------------------------------*/
    3.59  
    3.60  /* listen_socket() is straight from paul sheer's useful select_tut manpage. */
    3.61 -static int listen_socket (int listen_port) 
    3.62 +static int listen_socket (char *listen_path) 
    3.63  {
    3.64 -    struct sockaddr_in a;
    3.65 +    struct sockaddr_un a;
    3.66      int s;
    3.67      int yes;
    3.68  
    3.69 -    if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 
    3.70 +    if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) 
    3.71      {
    3.72          perror ("socket");
    3.73          return -1;
    3.74      }
    3.75      
    3.76      yes = 1;
    3.77 -    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
    3.78 -        (char *) &yes, sizeof (yes)) < 0) 
    3.79 -    {
    3.80 -        perror ("setsockopt");
    3.81 -        close (s);
    3.82 -        return -1;
    3.83 -    }
    3.84  
    3.85      memset (&a, 0, sizeof (a));
    3.86 -    a.sin_port = htons (listen_port);
    3.87 -    a.sin_family = AF_INET;
    3.88 +    a.sun_family = AF_UNIX;
    3.89 +    strcpy(a.sun_path, listen_path);
    3.90 +
    3.91 +    /* remove an old socket if it exists. */
    3.92 +    unlink(listen_path);
    3.93 +
    3.94      if (bind(s, (struct sockaddr *) &a, sizeof (a)) < 0) 
    3.95      {
    3.96          perror ("bind");
    3.97          close (s);
    3.98          return -1;
    3.99      }
   3.100 -    printf ("accepting connections on port %d\n", (int) listen_port);
   3.101 +    printf ("accepting connections on path %s\n", listen_path);
   3.102      listen (s, 10);
   3.103      return s;
   3.104  }
   3.105 @@ -626,13 +623,13 @@ void gc_ufd_list( unbound_fd_t **ufd )
   3.106      }
   3.107  }
   3.108  
   3.109 -int main (int argc, char*argv[])
   3.110 +int main (int argc, char *argv[])
   3.111  {
   3.112      int listen_fd, evtchn_fd;
   3.113      unbound_fd_t *unbound_fd_list = NULL, **ufd;
   3.114      struct timeval timeout = { XCS_GC_INTERVAL, 0 };
   3.115      connection_t **con;
   3.116 -    
   3.117 +
   3.118      /* Initialize xc and event connections. */
   3.119      if (ctrl_chan_init() != 0)
   3.120      {
   3.121 @@ -650,7 +647,7 @@ int main (int argc, char*argv[])
   3.122      init_interfaces();
   3.123      init_bindings();
   3.124      
   3.125 -    listen_fd = listen_socket(XCS_TCP_PORT);
   3.126 +    listen_fd = listen_socket(XCS_SUN_PATH);
   3.127     
   3.128      /* detach from our controlling tty so that a shell does hang waiting for
   3.129         stopped jobs. */
   3.130 @@ -742,7 +739,7 @@ int main (int argc, char*argv[])
   3.131          /* CASE 2: New connection on the listen port. */
   3.132          if ( FD_ISSET ( listen_fd, &rd ))
   3.133          {
   3.134 -            struct sockaddr_in remote_addr;
   3.135 +            struct sockaddr_un remote_addr;
   3.136              int size;
   3.137              memset (&remote_addr, 0, sizeof (remote_addr));
   3.138              size = sizeof remote_addr;
     4.1 --- a/tools/xcs/xcs_proto.h	Fri Feb 25 20:56:40 2005 +0000
     4.2 +++ b/tools/xcs/xcs_proto.h	Fri Feb 25 22:55:44 2005 +0000
     4.3 @@ -9,7 +9,7 @@
     4.4  #ifndef  __XCS_PROTO_H__
     4.5  #define  __XCS_PROTO_H__
     4.6  
     4.7 -#define XCS_TCP_PORT     1633
     4.8 +#define XCS_SUN_PATH     "/var/xen/xcs_socket"
     4.9  
    4.10  /* xcs message types: */
    4.11  #define XCS_CONNECT_CTRL       0 /* This is a control connection.     */
     5.1 --- a/tools/xcs/xcsdump.c	Fri Feb 25 20:56:40 2005 +0000
     5.2 +++ b/tools/xcs/xcsdump.c	Fri Feb 25 22:55:44 2005 +0000
     5.3 @@ -11,8 +11,7 @@
     5.4  #include <unistd.h>
     5.5  #include <sys/types.h>
     5.6  #include <sys/socket.h>
     5.7 -#include <netinet/in.h>
     5.8 -#include <arpa/inet.h>
     5.9 +#include <sys/un.h>
    5.10  #include <ctype.h>
    5.11  #include <xc.h>
    5.12  #include <xen/xen.h>
    5.13 @@ -23,24 +22,23 @@
    5.14  static int xcs_ctrl_fd = -1; /* connection to the xcs server. */
    5.15  static int xcs_data_fd = -1; /* connection to the xcs server. */
    5.16  
    5.17 -int tcp_connect(char *ip, short port)
    5.18 +int sock_connect(char *path)
    5.19  {
    5.20 -    struct sockaddr_in addr;
    5.21 -    int ret, fd;
    5.22 +    struct sockaddr_un addr;
    5.23 +    int ret, len, fd;
    5.24  
    5.25 -    fd = socket(AF_INET, SOCK_STREAM, 0);
    5.26 +    fd = socket(AF_UNIX, SOCK_STREAM, 0);
    5.27      if (fd < 0)
    5.28      {
    5.29          printf("error creating xcs socket!\n");
    5.30          return -1;
    5.31      }
    5.32  
    5.33 -    addr.sin_family = AF_INET;
    5.34 -    addr.sin_port = htons(port);
    5.35 -    addr.sin_addr.s_addr = inet_addr(ip);
    5.36 -    memset(&(addr.sin_zero), '\0', 8);
    5.37 +    addr.sun_family = AF_UNIX;
    5.38 +    strcpy(addr.sun_path, path);
    5.39 +    len = sizeof(addr.sun_family) + strlen(addr.sun_path) + 1;
    5.40  
    5.41 -    ret = connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr));
    5.42 +    ret = connect(fd, (struct sockaddr *)&addr, len);
    5.43      if (ret < 0) 
    5.44      {
    5.45          printf("error connecting to xcs!\n");
    5.46 @@ -50,7 +48,7 @@ int tcp_connect(char *ip, short port)
    5.47      return fd;
    5.48  }
    5.49  
    5.50 -void tcp_disconnect(int *fd)
    5.51 +void sock_disconnect(int *fd)
    5.52  {
    5.53      close(*fd);
    5.54      *fd = -1;
    5.55 @@ -91,7 +89,7 @@ int main(int argc, char* argv[])
    5.56          if ((strlen(argv[1]) >=2) && (strncmp(argv[1], "-v", 2) == 0))
    5.57              verbose = 1;
    5.58      
    5.59 -    ret = tcp_connect("127.0.0.1", XCS_TCP_PORT);
    5.60 +    ret = sock_connect(XCS_SUN_PATH);
    5.61      if (ret < 0) 
    5.62      {
    5.63          printf("connect failed!\n"); 
    5.64 @@ -109,7 +107,7 @@ int main(int argc, char* argv[])
    5.65          exit(-1);
    5.66      }
    5.67      
    5.68 -    ret = tcp_connect("127.0.0.1", XCS_TCP_PORT);
    5.69 +    ret = sock_connect(XCS_SUN_PATH);
    5.70      if (ret < 0) 
    5.71      {
    5.72          printf("connect failed!\n");