debuggers.hg
changeset 6699:acde14d25398
Make xenstored bind to domain exception virq directly, instead of via xcs.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Wed Sep 07 15:53:04 2005 +0000 (2005-09-07) |
parents | 652bd7876153 |
children | 4309a1fd8447 |
files | tools/xenstore/xenstored_core.c tools/xenstore/xenstored_domain.c |
line diff
1.1 --- a/tools/xenstore/xenstored_core.c Wed Sep 07 14:19:05 2005 +0000 1.2 +++ b/tools/xenstore/xenstored_core.c Wed Sep 07 15:53:04 2005 +0000 1.3 @@ -51,7 +51,6 @@ 1.4 #include "xenstored_domain.h" 1.5 #include "xenctrl.h" 1.6 #include "xen/io/domain_controller.h" 1.7 -#include "xcs_proto.h" 1.8 1.9 static bool verbose; 1.10 LIST_HEAD(connections); 1.11 @@ -325,7 +324,7 @@ static int destroy_conn(void *_conn) 1.12 } 1.13 1.14 static int initialize_set(fd_set *inset, fd_set *outset, int sock, int ro_sock, 1.15 - int event_fd, int xcs_fd) 1.16 + int event_fd) 1.17 { 1.18 struct connection *i; 1.19 int max; 1.20 @@ -340,9 +339,6 @@ static int initialize_set(fd_set *inset, 1.21 FD_SET(event_fd, inset); 1.22 if (event_fd > max) 1.23 max = event_fd; 1.24 - FD_SET(xcs_fd, inset); 1.25 - if (xcs_fd > max) 1.26 - max = xcs_fd; 1.27 list_for_each_entry(i, &connections, list) { 1.28 if (i->domain) 1.29 continue; 1.30 @@ -1650,125 +1646,6 @@ static void daemonize(void) 1.31 umask(0); 1.32 } 1.33 1.34 -static int open_domain_socket(const char *path) 1.35 -{ 1.36 - struct sockaddr_un addr; 1.37 - int sock; 1.38 - size_t addr_len; 1.39 - 1.40 - if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { 1.41 - goto out; 1.42 - } 1.43 - 1.44 - addr.sun_family = AF_UNIX; 1.45 - strcpy(addr.sun_path, path); 1.46 - addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1; 1.47 - 1.48 - if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) { 1.49 - goto out_close_sock; 1.50 - } 1.51 - 1.52 - return sock; 1.53 - 1.54 - out_close_sock: 1.55 - close(sock); 1.56 - out: 1.57 - return -1; 1.58 -} 1.59 - 1.60 -bool _read_write_sync(int fd, void *data, size_t size, bool do_read) 1.61 -{ 1.62 - size_t offset = 0; 1.63 - ssize_t len; 1.64 - 1.65 - while (offset < size) { 1.66 - if (do_read) { 1.67 - len = read(fd, data + offset, size - offset); 1.68 - } else { 1.69 - len = write(fd, data + offset, size - offset); 1.70 - } 1.71 - 1.72 - if (len < 1) { 1.73 - if (len == -1 && (errno == EAGAIN || errno == EINTR)) { 1.74 - continue; 1.75 - } else { 1.76 - return false; 1.77 - } 1.78 - } else { 1.79 - offset += len; 1.80 - } 1.81 - } 1.82 - 1.83 - return true; 1.84 -} 1.85 - 1.86 -#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true) 1.87 -#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false) 1.88 - 1.89 -/* synchronized send/recv strictly for setting up xcs */ 1.90 -/* always use asychronize callbacks any other time */ 1.91 -static bool xcs_send_recv(int fd, xcs_msg_t *msg) 1.92 -{ 1.93 - bool ret = false; 1.94 - 1.95 - if (!write_sync(fd, msg, sizeof(*msg))) { 1.96 - eprintf("Write failed at %s:%s():L%d? Possible bug.", 1.97 - __FILE__, __FUNCTION__, __LINE__); 1.98 - goto out; 1.99 - } 1.100 - 1.101 - if (!read_sync(fd, msg, sizeof(*msg))) { 1.102 - eprintf("Read failed at %s:%s():L%d? Possible bug.", 1.103 - __FILE__, __FUNCTION__, __LINE__); 1.104 - goto out; 1.105 - } 1.106 - 1.107 - ret = true; 1.108 - 1.109 - out: 1.110 - return ret; 1.111 -} 1.112 - 1.113 -static void handle_xcs(int xcs_fd) 1.114 -{ 1.115 - xcs_msg_t msg; 1.116 - 1.117 - if (!read_sync(xcs_fd, &msg, sizeof(msg))) 1.118 - barf_perror("read from xcs failed!"); 1.119 - 1.120 - domain_cleanup(); 1.121 -} 1.122 - 1.123 -static int xcs_init(void) 1.124 -{ 1.125 - int ctrl_fd, data_fd; 1.126 - xcs_msg_t msg; 1.127 - 1.128 - ctrl_fd = open_domain_socket(XCS_SUN_PATH); 1.129 - if (ctrl_fd == -1) 1.130 - barf_perror("Failed to contact xcs. Is it running?"); 1.131 - 1.132 - data_fd = open_domain_socket(XCS_SUN_PATH); 1.133 - if (data_fd == -1) 1.134 - barf_perror("Failed to contact xcs. Is it running?"); 1.135 - 1.136 - memset(&msg, 0, sizeof(msg)); 1.137 - msg.type = XCS_CONNECT_CTRL; 1.138 - if (!xcs_send_recv(ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) 1.139 - barf_perror("xcs control connect failed."); 1.140 - 1.141 - msg.type = XCS_CONNECT_DATA; 1.142 - if (!xcs_send_recv(data_fd, &msg) || msg.result != XCS_RSLT_OK) 1.143 - barf_perror("xcs data connect failed."); 1.144 - 1.145 - msg.type = XCS_VIRQ_BIND; 1.146 - msg.u.virq.virq = VIRQ_DOM_EXC; 1.147 - if (!xcs_send_recv(ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) 1.148 - barf_perror("xcs virq bind failed."); 1.149 - 1.150 - return data_fd; 1.151 -} 1.152 - 1.153 1.154 static struct option options[] = { 1.155 { "pid-file", 1, NULL, 'F' }, 1.156 @@ -1780,7 +1657,7 @@ static struct option options[] = { 1.157 1.158 int main(int argc, char *argv[]) 1.159 { 1.160 - int opt, *sock, *ro_sock, event_fd, xcs_fd, max; 1.161 + int opt, *sock, *ro_sock, event_fd, max; 1.162 struct sockaddr_un addr; 1.163 fd_set inset, outset; 1.164 bool dofork = true; 1.165 @@ -1864,9 +1741,6 @@ int main(int argc, char *argv[]) 1.166 /* Listen to hypervisor. */ 1.167 event_fd = domain_init(); 1.168 1.169 - /* Listen to hypervisor - more. */ 1.170 - xcs_fd = xcs_init(); 1.171 - 1.172 /* Restore existing connections. */ 1.173 restore_existing_connections(); 1.174 1.175 @@ -1887,8 +1761,7 @@ int main(int argc, char *argv[]) 1.176 #endif 1.177 1.178 /* Get ready to listen to the tools. */ 1.179 - max = initialize_set(&inset, &outset, *sock, *ro_sock, event_fd, 1.180 - xcs_fd); 1.181 + max = initialize_set(&inset, &outset, *sock, *ro_sock, event_fd); 1.182 1.183 /* Main loop. */ 1.184 /* FIXME: Rewrite so noone can starve. */ 1.185 @@ -1919,9 +1792,6 @@ int main(int argc, char *argv[]) 1.186 if (FD_ISSET(event_fd, &inset)) 1.187 handle_event(event_fd); 1.188 1.189 - if (FD_ISSET(xcs_fd, &inset)) 1.190 - handle_xcs(xcs_fd); 1.191 - 1.192 list_for_each_entry(i, &connections, list) { 1.193 if (i->domain) 1.194 continue; 1.195 @@ -1965,6 +1835,6 @@ int main(int argc, char *argv[]) 1.196 unblock_connections(); 1.197 1.198 max = initialize_set(&inset, &outset, *sock, *ro_sock, 1.199 - event_fd, xcs_fd); 1.200 + event_fd); 1.201 } 1.202 }
2.1 --- a/tools/xenstore/xenstored_domain.c Wed Sep 07 14:19:05 2005 +0000 2.2 +++ b/tools/xenstore/xenstored_domain.c Wed Sep 07 15:53:04 2005 +0000 2.3 @@ -38,6 +38,7 @@ 2.4 2.5 static int *xc_handle; 2.6 static int eventchn_fd; 2.7 +static int virq_port; 2.8 static unsigned int ringbuf_datasize; 2.9 2.10 struct domain 2.11 @@ -224,6 +225,10 @@ void handle_event(int event_fd) 2.12 2.13 if (read(event_fd, &port, sizeof(port)) != sizeof(port)) 2.14 barf_perror("Failed to read from event fd"); 2.15 + 2.16 + if (port == virq_port) 2.17 + domain_cleanup(); 2.18 + 2.19 #ifndef TESTING 2.20 if (write(event_fd, &port, sizeof(port)) != sizeof(port)) 2.21 barf_perror("Failed to write to event fd"); 2.22 @@ -449,5 +454,12 @@ int domain_init(void) 2.23 #endif 2.24 if (eventchn_fd < 0) 2.25 barf_perror("Failed to open connection to hypervisor"); 2.26 + 2.27 + if (xc_evtchn_bind_virq(*xc_handle, VIRQ_DOM_EXC, &virq_port)) 2.28 + barf_perror("Failed to bind to domain exception virq"); 2.29 + 2.30 + if (ioctl(eventchn_fd, EVENTCHN_BIND, virq_port) != 0) 2.31 + barf_perror("Failed to bind to domain exception virq port"); 2.32 + 2.33 return eventchn_fd; 2.34 }