diff --git a/tools/libxutil/Makefile b/tools/libxutil/Makefile index 8ba9eb3454..8be24daa92 100644 --- a/tools/libxutil/Makefile +++ b/tools/libxutil/Makefile @@ -8,7 +8,7 @@ LIB_SRCS += allocate.c LIB_SRCS += file_stream.c LIB_SRCS += gzip_stream.c LIB_SRCS += iostream.c -LIB_SRCS += sys_net.c +#LIB_SRCS += sys_net.c LIB_SRCS += sys_string.c LIB_OBJS := $(LIB_SRCS:.c=.o) diff --git a/tools/libxutil/allocate.h b/tools/libxutil/allocate.h index 08bc67b910..391b7be2bd 100644 --- a/tools/libxutil/allocate.h +++ b/tools/libxutil/allocate.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XEN_LIB_ALLOCATE_H_ -#define _XEN_LIB_ALLOCATE_H_ +#ifndef _XUTIL_ALLOCATE_H_ +#define _XUTIL_ALLOCATE_H_ /** Allocate memory for a given type, and cast. */ #define ALLOCATE(ctype) (ctype *)allocate(sizeof(ctype)) @@ -33,7 +33,7 @@ extern void memzero(void *p, int size); typedef void AllocateFailedFn(int size, int type); extern AllocateFailedFn *allocate_failed_fn; -#endif /* _XEN_LIB_ALLOCATE_H_ */ +#endif /* _XUTIL_ALLOCATE_H_ */ diff --git a/tools/libxutil/file_stream.h b/tools/libxutil/file_stream.h index 36a0f928b2..f717656c24 100644 --- a/tools/libxutil/file_stream.h +++ b/tools/libxutil/file_stream.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XEN_LIB_FILE_STREAM_H_ -#define _XEN_LIB_FILE_STREAM_H_ +#ifndef _XUTIL_FILE_STREAM_H_ +#define _XUTIL_FILE_STREAM_H_ #ifndef __KERNEL__ #include "iostream.h" @@ -32,4 +32,4 @@ extern IOStream get_stream_stdin(void); extern int file_stream_setvbuf(IOStream *io, char *buf, int mode, size_t size); #endif -#endif /* !_XEN_LIB_FILE_STREAM_H_ */ +#endif /* !_XUTIL_FILE_STREAM_H_ */ diff --git a/tools/libxutil/gzip_stream.c b/tools/libxutil/gzip_stream.c index af46023f9d..a933c5ff73 100644 --- a/tools/libxutil/gzip_stream.c +++ b/tools/libxutil/gzip_stream.c @@ -1,4 +1,3 @@ -/* $Id: gzip_stream.c,v 1.4 2003/09/30 15:22:53 mjw Exp $ */ /* * Copyright (C) 2003 Hewlett-Packard Company. * diff --git a/tools/libxutil/gzip_stream.h b/tools/libxutil/gzip_stream.h index cf76d25275..fd28e39575 100644 --- a/tools/libxutil/gzip_stream.h +++ b/tools/libxutil/gzip_stream.h @@ -1,4 +1,3 @@ -#/* $Id: gzip_stream.h,v 1.3 2003/09/30 15:22:53 mjw Exp $ */ /* * Copyright (C) 2003 Hewlett-Packard Company. * @@ -17,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _SP_GZIP_STREAM_H_ -#define _SP_GZIP_STREAM_H_ +#ifndef _XUTIL_GZIP_STREAM_H_ +#define _XUTIL_GZIP_STREAM_H_ #ifndef __KERNEL__ #include "iostream.h" @@ -28,4 +27,4 @@ extern IOStream *gzip_stream_new(gzFile *f); extern IOStream *gzip_stream_fopen(const char *file, const char *flags); extern IOStream *gzip_stream_fdopen(int fd, const char *flags); #endif -#endif /* !_SP_FILE_STREAM_H_ */ +#endif /* !_XUTIL_GZIP_STREAM_H_ */ diff --git a/tools/libxutil/kernel_stream.h b/tools/libxutil/kernel_stream.h index be370f2a45..0f18058d59 100644 --- a/tools/libxutil/kernel_stream.h +++ b/tools/libxutil/kernel_stream.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XEN_LIB_KERNEL_STREAM_H_ -#define _XEN_LIB_KERNEL_STREAM_H_ +#ifndef _XUTIL_KERNEL_STREAM_H_ +#define _XUTIL_KERNEL_STREAM_H_ #ifdef __KERNEL__ #include "iostream.h" @@ -26,4 +26,4 @@ extern IOStream get_stream_kernel(void); #define get_stream_stdout get_stream_kernel #endif /* __KERNEL__ */ -#endif /* !_XEN_LIB_KERNEL_STREAM_H_ */ +#endif /* !_XUTIL_KERNEL_STREAM_H_ */ diff --git a/tools/libxutil/string_stream.h b/tools/libxutil/string_stream.h index 36d764b265..b6cbc0f3df 100644 --- a/tools/libxutil/string_stream.h +++ b/tools/libxutil/string_stream.h @@ -1,4 +1,3 @@ -/* $Id: string_stream.h,v 1.1 2003/08/22 14:25:48 mjw Exp $ */ /* * Copyright (C) 2001, 2002 Hewlett-Packard Company. * @@ -17,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _SP_STRING_STREAM_H_ -#define _SP_STRING_STREAM_H_ +#ifndef _XUTIL_STRING_STREAM_H_ +#define _XUTIL_STRING_STREAM_H_ #include "iostream.h" @@ -43,4 +42,4 @@ extern IOMethods *string_stream_get_methods(void); extern IOStream *string_stream_new(char *s, int n); extern void string_stream_init(IOStream *stream, StringData *data, char *s, int n); -#endif /* !_SP_STRING_STREAM_H_ */ +#endif /* !_XUTIL_STRING_STREAM_H_ */ diff --git a/tools/libxutil/sys_net.h b/tools/libxutil/sys_net.h index da6c1e8fd5..61754940f2 100644 --- a/tools/libxutil/sys_net.h +++ b/tools/libxutil/sys_net.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XEN_LIB_SYS_NET_H_ -#define _XEN_LIB_SYS_NET_H_ +#ifndef _XUTIL_SYS_NET_H_ +#define _XUTIL_SYS_NET_H_ /** @file * * Replacement for standard network includes. @@ -72,7 +72,7 @@ extern int inet_aton(const char *address, struct in_addr *inp); extern char *mac_ntoa(const unsigned char *macaddr); extern int mac_aton(const char *addr, unsigned char *macaddr); -#endif /* !_SP_SYS_NET_H_ */ +#endif /* !_XUTIL_SYS_NET_H_ */ diff --git a/tools/libxutil/sys_string.h b/tools/libxutil/sys_string.h index f39935f669..ea60401168 100644 --- a/tools/libxutil/sys_string.h +++ b/tools/libxutil/sys_string.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _XEN_LIB_SYS_STRING_H_ -#define _XEN_LIB_SYS_STRING_H_ +#ifndef _XUTIL_SYS_STRING_H_ +#define _XUTIL_SYS_STRING_H_ /** @file * Replacement for standard string includes. * Works in user or kernel code. @@ -88,4 +88,4 @@ static inline size_t strnlen(const char *s, size_t n){ extern int convert_atoul(const char *s, unsigned long *v); extern int path_concat(char *s, char *t, char **val); -#endif /* !_XEN_LIB_SYS_STRING_H_ */ +#endif /* !_XUTIL_SYS_STRING_H_ */ diff --git a/tools/python/xen/xend/server/blkif.py b/tools/python/xen/xend/server/blkif.py index 7310494377..d265ae382e 100755 --- a/tools/python/xen/xend/server/blkif.py +++ b/tools/python/xen/xend/server/blkif.py @@ -210,9 +210,6 @@ class BlkifController(controller.Controller): self.evtchn['port2']]) return val - def lostChannel(self): - controller.Controller.lostChannel(self) - def getDevices(self): return self.devices.values() diff --git a/tools/python/xen/xend/server/channel.py b/tools/python/xen/xend/server/channel.py index 0c9d316dec..caaa66e28c 100755 --- a/tools/python/xen/xend/server/channel.py +++ b/tools/python/xen/xend/server/channel.py @@ -174,9 +174,9 @@ class VirqChannel(BaseChannel): """Close the channel. Calls lostChannel(self) on all its clients and channelClosed() on the factory. """ - for c in self.clients: + for c in self.clients[:]: c.lostChannel(self) - del self.clients + self.clients = [] BaseChannel.close(self) def registerClient(self, client): @@ -238,7 +238,7 @@ class Channel(BaseChannel): """ if self.closed: return self.closed = 1 - for d in self.devs: + for d in self.devs[:]: d.lostChannel() self.factory.channelClosed(self) self.devs = [] diff --git a/tools/python/xen/xend/server/console.py b/tools/python/xen/xend/server/console.py index 336ccacca0..77f6343c3d 100755 --- a/tools/python/xen/xend/server/console.py +++ b/tools/python/xen/xend/server/console.py @@ -93,10 +93,15 @@ class ConsoleController(controller.Controller): output and the connected TCP sockets to post console input. """ + STATUS_NEW = 'new' + STATUS_CLOSED = 'closed' + STATUS_CONNECTED = 'connected' + STATUS_LISTENING = 'listening' + def __init__(self, factory, dom, console_port): controller.Controller.__init__(self, factory, dom) self.majorTypes = [ CMSG_CONSOLE ] - self.status = "new" + self.status = self.STATUS_NEW self.addr = None self.conn = None self.rbuf = xu.buffer() @@ -123,28 +128,31 @@ class ConsoleController(controller.Controller): return not (self.closed() or self.rbuf.empty()) def closed(self): - return self.status == 'closed' + return self.status == self.STATUS_CLOSED def connected(self): - return self.status == 'connected' + return self.status == self.STATUS_CONNECTED def close(self): - try: - self.status = "closed" - if self.conn: - self.conn.loseConnection() - self.listener.stopListening() - self.deregisterChannel() - self.lostChannel() - except Exception, ex: - print 'ConsoleController>close>', ex - raise + """Close the console controller. + """ + self.lostChannel() + + def lostChannel(self): + """The channel to the domain has been lost. + Cleanup: disconnect TCP connections and listeners, notify the controller. + """ + self.status = self.STATUS_CLOSED + if self.conn: + self.conn.loseConnection() + self.listener.stopListening() + controller.Controller.lostChannel(self) def listen(self): """Listen for TCP connections to the console port.. """ if self.closed(): return - self.status = "listening" + self.status = self.STATUS_LISTENING if self.listener: #self.listener.startListening() pass @@ -153,15 +161,25 @@ class ConsoleController(controller.Controller): self.listener = reactor.listenTCP(self.console_port, f) def connect(self, addr, conn): + """Connect a TCP connection to the console. + Fails if closed or already connected. + + addr peer address + conn connection + + returns 0 if ok, negative otherwise + """ if self.closed(): return -1 if self.connected(): return -1 self.addr = addr self.conn = conn - self.status = "connected" + self.status = self.STATUS_CONNECTED self.handleOutput() return 0 def disconnect(self): + """Disconnect the TCP connection to the console. + """ if self.conn: self.conn.loseConnection() self.addr = None @@ -169,15 +187,29 @@ class ConsoleController(controller.Controller): self.listen() def requestReceived(self, msg, type, subtype): + """Receive console data from the console channel. + + msg console message + type major message type + subtype minor message typ + """ self.rbuf.write(msg.get_payload()) self.handleOutput() def responseReceived(self, msg, type, subtype): - # Just ignore responses. + """Handle a response to a request written to the console channel. + Just ignore it because the return values are not interesting. + + msg console message + type major message type + subtype minor message typ + """ pass def produceRequests(self): - # Send as much pending console data as there is room for. + """Write pending console data to the console channel. + Writes as much to the channel as it can. + """ work = 0 while not self.wbuf.empty() and self.channel.writeReady(): msg = xu.message(CMSG_CONSOLE, 0, 0) @@ -187,7 +219,12 @@ class ConsoleController(controller.Controller): def handleInput(self, conn, data): """Handle some external input aimed at the console. - Called from a TCP connection (conn). + Called from a TCP connection (conn). Ignores the input + if the calling connection (conn) is not the one connected + to the console (self.conn). + + conn connection + data input data """ if self.closed(): return -1 if conn != self.conn: return 0 diff --git a/tools/python/xen/xend/server/controller.py b/tools/python/xen/xend/server/controller.py index 299bd621f6..49d6e26ea8 100755 --- a/tools/python/xen/xend/server/controller.py +++ b/tools/python/xen/xend/server/controller.py @@ -205,12 +205,12 @@ class Controller(CtrlMsgRcvr): def close(self): """Close the controller. """ - self.deregisterChannel() self.lostChannel() def lostChannel(self): """The controller channel has been lost. """ + self.deregisterChannel() self.factory.instanceClosed(self) class Dev: diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py index 5760552e8b..0096511b7c 100755 --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -198,8 +198,9 @@ class NetifController(controller.Controller): def randomMAC(self): """Generate a random MAC address. - The OUI (Organisation Unique Identifier) used is AA:00:00, which - is a currently unassigned one that used to belong to DEC. + Uses OUI (Organizationally Unique Identifier) AA:00:00, an + unassigned one that used to belong to DEC. The OUI list is + available at 'standards.ieee.org'. The remaining 3 fields are random, with the first bit of the first random field set 0.