diff options
-rw-r--r-- | sysutils/xentools12/DESCR | 5 | ||||
-rw-r--r-- | sysutils/xentools12/Makefile | 39 | ||||
-rw-r--r-- | sysutils/xentools12/PLIST | 18 | ||||
-rw-r--r-- | sysutils/xentools12/distinfo | 19 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-aa | 14 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ab | 16 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ac | 28 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ad | 13 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ae | 33 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-af | 23 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ag | 27 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ah | 26 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ai | 13 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-aj | 26 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-ak | 29 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-al | 34 | ||||
-rw-r--r-- | sysutils/xentools12/patches/patch-am | 214 |
17 files changed, 577 insertions, 0 deletions
diff --git a/sysutils/xentools12/DESCR b/sysutils/xentools12/DESCR new file mode 100644 index 00000000000..38e79fc0d1c --- /dev/null +++ b/sysutils/xentools12/DESCR @@ -0,0 +1,5 @@ +The Xen virtual machine monitor allows running several virtual machines +on a single physical machine. The xentools12 package contains the +tools to create, destroy and control the virtual machines. + +The xentools12 package contains the tools for Xen v1.2. diff --git a/sysutils/xentools12/Makefile b/sysutils/xentools12/Makefile new file mode 100644 index 00000000000..780b4b59fd3 --- /dev/null +++ b/sysutils/xentools12/Makefile @@ -0,0 +1,39 @@ +# $NetBSD: Makefile,v 1.1 2004/05/08 18:24:00 cl Exp $ +# + +PKGNAME= xentools12 +DISTNAME= xeno-1.2-src-040418 +DISTFILES= ${DISTNAME}${EXTRACT_SUFX} +DISTFILES+= netbsd-xen-kernel-headers-040508.tar.gz +CATEGORIES= local +MASTER_SITES= ftp://ftp.NetBSD.org/pub/NetBSD/arch/xen/misc/ +EXTRACT_SUFX= .tgz + +MAINTAINER= cl@NetBSD.org +HOMEPAGE= http://www.netbsd.org/Ports/xen/ +COMMENT= Userland Tools for Xen + +ONLY_FOR_PLATFORM= *-*-i386 + +WRKSRC= ${WRKDIR}/xeno-1.2/tools + +PKG_SYSCONFSUBDIR?= xc12 +USE_PKGINSTALL= yes +EGDIR= ${PREFIX}/share/examples/${PKGNAME_NOREV} +CONF_FILES= ${EGDIR}/defaults ${PKG_SYSCONFDIR}/defaults +CONF_FILES+= ${EGDIR}/democd ${PKG_SYSCONFDIR}/democd +CONF_FILES+= ${EGDIR}/netbsd ${PKG_SYSCONFDIR}/netbsd + +USE_GNU_TOOLS+= make +MAKE_ENV+= EGDIR="${EGDIR}" +MAKE_ENV+= MV="${MV}" PYTHON="${PYTHONBIN}" SED="${SED}" +PYTHON_VERSIONS_ACCEPTED= 22 22pth 23 23pth +PY_PATCHPLIST= yes +PYTHON_PATCH_SCRIPTS= examples/xc_dom_control.py examples/xc_dom_create.py +PYTHON_PATCH_SCRIPTS+= examples/xc_vd_tool.py +USE_BUILDLINK3= yes + +.include "../../lang/python/application.mk" +.include "../../lang/python/extension.mk" + +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/xentools12/PLIST b/sysutils/xentools12/PLIST new file mode 100644 index 00000000000..955d9c70011 --- /dev/null +++ b/sysutils/xentools12/PLIST @@ -0,0 +1,18 @@ +@comment $NetBSD: PLIST,v 1.1 2004/05/08 18:24:00 cl Exp $ +bin/balloon +bin/xc_dom_control.py +bin/xc_dom_create.py +bin/xc_vd_tool.py +bin/xen_cpuperf +bin/xen_read_console +include/xc.h +lib/libxc.so +lib/libxc.so.1.2 +lib/libxc.so.1.2.0 +${PYSITELIB}/Xc.so +${PYSITELIB}/XenoUtil.py +${PYSITELIB}/XenoUtil.pyc +share/examples/${PKGNAME}/defaults +share/examples/${PKGNAME}/democd +share/examples/${PKGNAME}/netbsd +@dirrm share/examples/${PKGNAME} diff --git a/sysutils/xentools12/distinfo b/sysutils/xentools12/distinfo new file mode 100644 index 00000000000..4f66a25e8b6 --- /dev/null +++ b/sysutils/xentools12/distinfo @@ -0,0 +1,19 @@ +$NetBSD: distinfo,v 1.1 2004/05/08 18:24:00 cl Exp $ + +SHA1 (xeno-1.2-src-040418.tgz) = d19f627dc40416f369f6728fcd86e4364e1713ee +Size (xeno-1.2-src-040418.tgz) = 2960238 bytes +SHA1 (netbsd-xen-kernel-headers-040508.tar.gz) = 4e452e48b9896528a9fed580b46a072be28b807d +Size (netbsd-xen-kernel-headers-040508.tar.gz) = 1140 bytes +SHA1 (patch-aa) = 6c43d7b592f316f5e0bf2d2ee88a2edba03cb635 +SHA1 (patch-ab) = 130cba1d87a72a75789809561e6ab5094e843abe +SHA1 (patch-ac) = 53bfeaddecf8e9b583e7764845acab1827587348 +SHA1 (patch-ad) = 20b20b9b7e0755de90c9d126bce030d5a267fb44 +SHA1 (patch-ae) = d0b46925a02c14f551cb7612747e1f7a237ad68c +SHA1 (patch-af) = d7ca50cd38a499b6703ccae55572095165f4bc77 +SHA1 (patch-ag) = 2811168875b4c3b0af194fe0b6a95ac9be123260 +SHA1 (patch-ah) = a1523d6df5220a2915cd7ff152c3011042d7de71 +SHA1 (patch-ai) = 936a9c198f15a3e6f78a1639c70bea19338ef1d1 +SHA1 (patch-aj) = 3d567c5497b09e1b5980fe75d2bb38a23e39621d +SHA1 (patch-ak) = d4e0d09f232f9d37ab4ab93fc389b07de4d9a5da +SHA1 (patch-al) = 3ab650d2608455c603046afe46375ff3fa219703 +SHA1 (patch-am) = 90e31b894191b2a8df23344bc6997fa874f555e9 diff --git a/sysutils/xentools12/patches/patch-aa b/sysutils/xentools12/patches/patch-aa new file mode 100644 index 00000000000..c05a1739861 --- /dev/null +++ b/sysutils/xentools12/patches/patch-aa @@ -0,0 +1,14 @@ +$NetBSD: patch-aa,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- balloon/Makefile.orig 2004-04-18 04:29:14.000000000 +0200 ++++ balloon/Makefile +@@ -5,8 +5,7 @@ $(TARGET): balloon.c + $(CC) -O2 -Wall -o $(TARGET) balloon.c + + install: $(TARGET) +- mkdir -p $(prefix)/usr/bin +- cp -a $(TARGET) $(prefix)/usr/bin ++ ${BSD_INSTALL_PROGRAM} $(TARGET) ${PREFIX}/bin + + dist: $(TARGET) + mkdir -p ../../../install/bin diff --git a/sysutils/xentools12/patches/patch-ab b/sysutils/xentools12/patches/patch-ab new file mode 100644 index 00000000000..96402d73eee --- /dev/null +++ b/sysutils/xentools12/patches/patch-ab @@ -0,0 +1,16 @@ +$NetBSD: patch-ab,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- balloon/balloon.c.orig 2004-04-18 04:29:13.000000000 +0200 ++++ balloon/balloon.c +@@ -31,7 +31,11 @@ typedef struct user_balloon_op { + + static int open_balloon_proc() + { ++#if defined(__linux__) + return open("/proc/xeno/balloon", O_RDWR); ++#elif defined(__NetBSD__) ++ return open("/kern/xen/balloon", O_RDWR); ++#endif + } + + /* inflate balloon function signals to kernel it should relinquish memory */ diff --git a/sysutils/xentools12/patches/patch-ac b/sysutils/xentools12/patches/patch-ac new file mode 100644 index 00000000000..5bba5215666 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ac @@ -0,0 +1,28 @@ +$NetBSD: patch-ac,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- examples/Makefile.orig 2004-04-18 04:29:14.000000000 +0200 ++++ examples/Makefile +@@ -12,15 +12,16 @@ ETC = defaults democd netbsd + INITD = xendomains + + all: ++ [ -f xc_dom_create.py-pre ] || ${MV} xc_dom_create.py xc_dom_create.py-pre ++ ${SED} -e 's|@PKG_SYSCONFDIR@|${PKG_SYSCONFDIR}|g' \ ++ xc_dom_create.py-pre > xc_dom_create.py + + install: all +- mkdir -p $(prefix)/usr/bin +- cp -a $(INSTALL) $(prefix)/usr/bin +- #chmod 755 $(INSTALL) +- mkdir -p $(prefix)/etc/xc +- for i in $(ETC) ; do [ ! -e $(prefix)/etc/xc/$$i ] && echo Install $$i && cp $$i $(prefix)/etc/xc/ ; done || true +- mkdir -p $(prefix)/etc/xc/auto +- for i in $(INITD) ; do [ -e $(prefix)/etc/init.d/ ] && [ ! -e $(prefix)/etc/init.d/$$i ] && cp $$i $(prefix)/etc/init.d/ ; done || true ++ ${BSD_INSTALL_SCRIPT} $(INSTALL) ${PREFIX}/bin ++ ${BSD_INSTALL_DATA_DIR} ${EGDIR} ++ ${BSD_INSTALL_DATA} $(ETC) ${EGDIR} ++ #mkdir -p $(prefix)/etc/xc/auto ++ #for i in $(INITD) ; do [ -e $(prefix)/etc/init.d/ ] && [ ! -e $(prefix)/etc/init.d/$$i ] && cp $$i $(prefix)/etc/init.d/ ; done || true + + dist: all + mkdir -p ../../../install/bin diff --git a/sysutils/xentools12/patches/patch-ad b/sysutils/xentools12/patches/patch-ad new file mode 100644 index 00000000000..6102f862ef4 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ad @@ -0,0 +1,13 @@ +$NetBSD: patch-ad,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- examples/xc_dom_create.py.orig 2004-04-18 04:29:16.000000000 +0200 ++++ examples/xc_dom_create.py +@@ -2,7 +2,7 @@ + + import Xc, XenoUtil, string, sys, os, time, socket, getopt, signal, syslog + +-config_dir = '/etc/xc/' ++config_dir = '@PKG_SYSCONFDIR@/' + config_file = xc_config_file = config_dir + 'defaults' + + def main_usage (): diff --git a/sysutils/xentools12/patches/patch-ae b/sysutils/xentools12/patches/patch-ae new file mode 100644 index 00000000000..1d346ce70c5 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ae @@ -0,0 +1,33 @@ +$NetBSD: patch-ae,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- misc/Makefile.orig 2004-04-18 04:29:10.000000000 +0200 ++++ misc/Makefile +@@ -2,6 +2,7 @@ + CC = gcc + CFLAGS = -Wall -O3 + EXTRA_INC = -I../../xen/include -I../../xenolinux-sparse/include -I../xc/lib ++EXTRA_INC += -I../../../netbsd-xen-kernel-headers + + HDRS = $(wildcard *.h) + SRCS = $(wildcard *.c) +@@ -9,18 +10,12 @@ OBJS = $(patsubst %.c,%.o,$(SRCS)) + + TARGETS = xen_read_console xen_cpuperf + +-INSTALL = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone ++INSTALL = $(TARGETS) # xen-mkdevnodes xen_nat_enable xen-clone + + all: $(TARGETS) +- $(MAKE) -C miniterm + + install: all +- mkdir -p $(prefix)/usr/bin +- cp -a $(INSTALL) $(prefix)/usr/bin +- chmod 755 $(prefix)/usr/bin/xen-mkdevnodes +- chmod 755 $(prefix)/usr/bin/xen_nat_enable +- chmod 755 $(prefix)/usr/bin/xen-clone +- $(MAKE) -C miniterm install ++ ${BSD_INSTALL_PROGRAM} $(INSTALL) ${PREFIX}/bin + + dist: all + mkdir -p ../../../install/bin diff --git a/sysutils/xentools12/patches/patch-af b/sysutils/xentools12/patches/patch-af new file mode 100644 index 00000000000..f675467a69c --- /dev/null +++ b/sysutils/xentools12/patches/patch-af @@ -0,0 +1,23 @@ +$NetBSD: patch-af,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- misc/xen_cpuperf.c.orig 2004-04-18 04:29:11.000000000 +0200 ++++ misc/xen_cpuperf.c +@@ -9,7 +9,9 @@ + + #include <sys/types.h> + #include <sched.h> ++#if defined(__linux__) + #include <error.h> ++#endif + #include <stdio.h> + #include <unistd.h> + #include <stdlib.h> +@@ -217,7 +219,7 @@ int main(int argc, char **argv) + } + } + +- if ( (privfd = open("/proc/xeno/privcmd", O_RDWR)) == -1 ) ++ if ( (privfd = open(PRIVCMD_PATH, O_RDWR)) == -1 ) + { + fprintf(stderr, "Could not open privileged Xen control interface.\n"); + exit(1); diff --git a/sysutils/xentools12/patches/patch-ag b/sysutils/xentools12/patches/patch-ag new file mode 100644 index 00000000000..1bf47932317 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ag @@ -0,0 +1,27 @@ +$NetBSD: patch-ag,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/Makefile.orig 2004-04-18 04:29:11.000000000 +0200 ++++ xc/lib/Makefile +@@ -6,6 +6,7 @@ SONAME = libxc.so.$(MAJOR) + CC = gcc + CFLAGS = -c -Wall -O3 + CFLAGS += -I../../../xen/include -I../../../xenolinux-sparse/include ++CFLAGS += -I../../../../netbsd-xen-kernel-headers + + HDRS = $(wildcard *.h) + OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) +@@ -23,12 +24,8 @@ check-for-zlib: + fi + + install: all +- mkdir -p $(prefix)/usr/lib +- mkdir -p $(prefix)/usr/include +- cp -a $(LIB) $(prefix)/usr/lib +- chmod 755 $(prefix)/usr/lib/$(LIB) +- cp xc.h $(prefix)/usr/include +- chmod 644 $(prefix)/usr/include/xc.h ++ ${BSD_INSTALL_PROGRAM} $(LIB) ${PREFIX}/lib ++ ${BSD_INSTALL_DATA} xc.h ${PREFIX}/include + + dist: all + mkdir -p ../../../../install/lib diff --git a/sysutils/xentools12/patches/patch-ah b/sysutils/xentools12/patches/patch-ah new file mode 100644 index 00000000000..244eff6ee1f --- /dev/null +++ b/sysutils/xentools12/patches/patch-ah @@ -0,0 +1,26 @@ +$NetBSD: patch-ah,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/xc_linux_build.c.orig 2004-04-18 04:29:15.000000000 +0200 ++++ xc/lib/xc_linux_build.c +@@ -222,6 +222,10 @@ static int setup_guestos(int xc_handle, + if ( (vl2tab = map_pfn(pm_handle, l2tab >> PAGE_SHIFT)) == NULL ) + goto error_out; + memset(vl2tab, 0, PAGE_SIZE); ++ unmap_pfn(pm_handle, vl2tab); ++ if ( (vl2tab = map_pfn_ro(pm_handle, l2tab >> PAGE_SHIFT)) == NULL ) ++ goto error_out; ++ mlock(vl2tab, PAGE_SIZE); + vl2e = vl2tab + l2_table_offset(virt_load_addr); + for ( count = 0; count < tot_pages; count++ ) + { +@@ -231,6 +235,10 @@ static int setup_guestos(int xc_handle, + if ( (vl1tab = map_pfn(pm_handle, l1tab >> PAGE_SHIFT)) == NULL ) + goto error_out; + memset(vl1tab, 0, PAGE_SIZE); ++ unmap_pfn(pm_handle, vl1tab); ++ if ( (vl1tab = map_pfn_ro(pm_handle, l1tab >> PAGE_SHIFT)) == NULL ) ++ goto error_out; ++ mlock(vl1tab, PAGE_SIZE); + alloc_index--; + + vl1e = vl1tab + l1_table_offset(virt_load_addr + diff --git a/sysutils/xentools12/patches/patch-ai b/sysutils/xentools12/patches/patch-ai new file mode 100644 index 00000000000..69d8093da97 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ai @@ -0,0 +1,13 @@ +$NetBSD: patch-ai,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/xc_misc.c.orig 2004-04-18 04:29:12.000000000 +0200 ++++ xc/lib/xc_misc.c +@@ -8,7 +8,7 @@ + + int xc_interface_open(void) + { +- int fd = open("/proc/xeno/privcmd", O_RDWR); ++ int fd = open(PRIVCMD_PATH, O_RDWR); + if ( fd == -1 ) + PERROR("Could not obtain handle on privileged command interface"); + return fd; diff --git a/sysutils/xentools12/patches/patch-aj b/sysutils/xentools12/patches/patch-aj new file mode 100644 index 00000000000..514e8d5d4c7 --- /dev/null +++ b/sysutils/xentools12/patches/patch-aj @@ -0,0 +1,26 @@ +$NetBSD: patch-aj,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/xc_netbsd_build.c.orig 2004-04-18 04:29:16.000000000 +0200 ++++ xc/lib/xc_netbsd_build.c +@@ -157,6 +157,10 @@ static int setup_guestos(int xc_handle, + if ( (vl2tab = map_pfn(pm_handle, l2tab >> PAGE_SHIFT)) == NULL ) + goto error_out; + memset(vl2tab, 0, PAGE_SIZE); ++ unmap_pfn(pm_handle, vl2tab); ++ if ( (vl2tab = map_pfn_ro(pm_handle, l2tab >> PAGE_SHIFT)) == NULL ) ++ goto error_out; ++ mlock(vl2tab, PAGE_SIZE); + vl2e = vl2tab + l2_table_offset(*virt_load_addr); + for ( count = 0; count < tot_pages; count++ ) + { +@@ -166,6 +170,10 @@ static int setup_guestos(int xc_handle, + if ( (vl1tab = map_pfn(pm_handle, l1tab >> PAGE_SHIFT)) == NULL ) + goto error_out; + memset(vl1tab, 0, PAGE_SIZE); ++ unmap_pfn(pm_handle, vl1tab); ++ if ( (vl1tab = map_pfn_ro(pm_handle, l1tab >> PAGE_SHIFT)) == NULL ) ++ goto error_out; ++ mlock(vl1tab, PAGE_SIZE); + alloc_index--; + + vl1e = vl1tab + l1_table_offset(*virt_load_addr + diff --git a/sysutils/xentools12/patches/patch-ak b/sysutils/xentools12/patches/patch-ak new file mode 100644 index 00000000000..9191870df24 --- /dev/null +++ b/sysutils/xentools12/patches/patch-ak @@ -0,0 +1,29 @@ +$NetBSD: patch-ak,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/xc_private.c.orig 2004-04-18 04:29:09.000000000 +0200 ++++ xc/lib/xc_private.c +@@ -8,7 +8,7 @@ + + int init_pfn_mapper(void) + { +- return open("/dev/mem", O_RDWR); ++ return open("/kern/xen/machmem", O_RDWR); + } + + int close_pfn_mapper(int pm_handle) +@@ -25,6 +25,15 @@ void *map_pfn(int pm_handle, unsigned lo + return vaddr; + } + ++void *map_pfn_ro(int pm_handle, unsigned long pfn) ++{ ++ void *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ, ++ MAP_SHARED, pm_handle, pfn << PAGE_SHIFT); ++ if ( vaddr == MAP_FAILED ) ++ return NULL; ++ return vaddr; ++} ++ + void unmap_pfn(int pm_handle, void *vaddr) + { + (void)munmap(vaddr, PAGE_SIZE); diff --git a/sysutils/xentools12/patches/patch-al b/sysutils/xentools12/patches/patch-al new file mode 100644 index 00000000000..2af708a7f0c --- /dev/null +++ b/sysutils/xentools12/patches/patch-al @@ -0,0 +1,34 @@ +$NetBSD: patch-al,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/lib/xc_private.h.orig 2004-04-18 04:29:14.000000000 +0200 ++++ xc/lib/xc_private.h +@@ -16,11 +16,21 @@ + + #include "xc.h" + ++#if defined(__linux__) + #include <asm-xeno/proc_cmd.h> ++#elif defined(__NetBSD__) ++#include <sys/xenio.h> ++#endif + #include <hypervisor-ifs/hypervisor-if.h> + #include <hypervisor-ifs/dom0_ops.h> + #include <hypervisor-ifs/vbd.h> + ++#if defined(__linux__) ++#define PRIVCMD_PATH "/proc/xeno/privcmd" ++#elif defined(__NetBSD__) ++#define PRIVCMD_PATH "/kern/xen/privcmd" ++#endif ++ + #define _PAGE_PRESENT 0x001 + #define _PAGE_RW 0x002 + #define _PAGE_USER 0x004 +@@ -149,6 +159,7 @@ static inline int do_block_io_op(int xc_ + int init_pfn_mapper(void); + int close_pfn_mapper(int pm_handle); + void *map_pfn(int pm_handle, unsigned long pfn); ++void *map_pfn_ro(int pm_handle, unsigned long pfn); + void unmap_pfn(int pm_handle, void *vaddr); + + #endif /* __XC_PRIVATE_H__ */ diff --git a/sysutils/xentools12/patches/patch-am b/sysutils/xentools12/patches/patch-am new file mode 100644 index 00000000000..42e6ff0cfad --- /dev/null +++ b/sysutils/xentools12/patches/patch-am @@ -0,0 +1,214 @@ +$NetBSD: patch-am,v 1.1 2004/05/08 18:24:00 cl Exp $ + +--- xc/py/XenoUtil.py.orig 2004-04-18 04:29:13.000000000 +0200 ++++ xc/py/XenoUtil.py +@@ -25,26 +25,40 @@ except ImportError: + # on failure, just catch the error, don't do anything + pass + ++os_ifs = {'Linux' : 'eth0', 'NetBSD' : 'xennet0'} ++default_if = os_ifs[os.uname()[0]] ++ ++os_vfr_paths = {'Linux' : '/proc/xeno/vfr', 'NetBSD' : '/kern/xen/vfr'} ++vfr_path = os_vfr_paths[os.uname()[0]] ++ ++os_ipgw_cmds = {'Linux' : '/sbin/route -n', ++ 'NetBSD' : '/sbin/route -n get default'} ++ipgw_cmd = os_ipgw_cmds[os.uname()[0]] ++ ++os_ipgw_res = {'Linux' : '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' + ++ '\s+\S+\s+\S*G.*%s.*', ++ 'NetBSD' : 'gateway:\s([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)(?:%s)?'} ++ipgw_re = os_ipgw_res[os.uname()[0]] + + ##### Networking-related functions + +-def get_current_ipaddr(dev='eth0'): ++def get_current_ipaddr(dev=default_if): + """Return a string containing the primary IP address for the given +- network interface (default 'eth0'). +- """ ++ network interface (default '%s'). ++ """ % default_if + fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) + lines = fd.readlines() + for line in lines: +- m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', ++ m = re.search( '^\s+inet (?:addr:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', + line ) + if m: + return m.group(1) + return None + +-def get_current_ipmask(dev='eth0'): ++def get_current_ipmask(dev=default_if): + """Return a string containing the primary IP netmask for the given +- network interface (default 'eth0'). +- """ ++ network interface (default '%s'). ++ """ % default_if + fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) + lines = fd.readlines() + for line in lines: +@@ -52,17 +66,22 @@ def get_current_ipmask(dev='eth0'): + line ) + if m: + return m.group(1) ++ m = re.search( '^.+netmask (0x[0-9a-f]+)\s', ++ line ) ++ if m: ++ a = int(m.group(1), 16) ++ return '%d.%d.%d.%d' % ( ((a>>24)&0xff), ((a>>16)&0xff), ++ ((a>>8)&0xff), (a&0xff) ) + return None + +-def get_current_ipgw(dev='eth0'): ++def get_current_ipgw(dev=default_if): + """Return a string containing the IP gateway for the given +- network interface (default 'eth0'). +- """ +- fd = os.popen( '/sbin/route -n' ) ++ network interface (default '%s'). ++ """ % default_if ++ fd = os.popen( ipgw_cmd ) + lines = fd.readlines() + for line in lines: +- m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' + +- '\s+\S+\s+\S*G.*' + dev + '.*', line ) ++ m = re.search( ipgw_re % dev, line ) + if m: + return m.group(1) + return None +@@ -72,7 +91,7 @@ def setup_vfr_rules_for_vif(dom,vif,addr + is expressed as a textual dotted quad, and set up appropriate routing + rules in Xen. No return value. + """ +- fd = os.open( '/proc/xeno/vfr', os.O_WRONLY ) ++ fd = os.open( vfr_path, os.O_WRONLY ) + if ( re.search( '169\.254', addr) ): + os.write( fd, 'ADD ACCEPT srcaddr=' + addr + + ' srcaddrmask=255.255.255.255' + +@@ -117,14 +136,42 @@ def check_subnet( ip, network, netmask ) + + ##### VBD-related Functions + ++# ls -l /dev/hd[a-z] /dev/sd[a-z] /dev/scd* | sed -e 's#/dev/##' -e 's#,##' ++# | awk -v ORS=" " '{print "'\''" $10 "'\'':" $5 * 256 + $6 "," }'; ++blkdev_name_to_number_dict = { ++ 'hda':768, 'hdb':832, 'hdc':5632, 'hdd':5696, 'hde':8448, ++ 'hdf':8512, 'hdg':8704, 'hdh':8768, 'hdi':14336, 'hdj':14400, ++ 'hdk':14592, 'hdl':14656, ++ 'sda':2048, 'sdb':2064, 'sdc':2080, 'sdd':2096, ++ 'sde':2112, 'sdf':2128, 'sdg':2144, 'sdh':2160, ++ 'scd0':2816, 'scd1':2817, 'scd10':2826, 'scd11':2827, ++ 'scd12':2828, 'scd13':2829, 'scd14':2830, 'scd15':2831, ++ 'scd16':2832, 'scd2':2818, 'scd3':2819, 'scd4':2820, ++ 'scd5':2821, 'scd6':2822, 'scd7':2823, 'scd8':2824, ++ 'scd9':2825 ++ } ++ + def blkdev_name_to_number(name): + """Take the given textual block-device name (e.g., '/dev/sda1', +- 'hda') and return the device number used by the OS. """ ++ 'hda') and return the device number used by Xen. """ + +- if not re.match( '/dev/', name ): +- name = '/dev/' + name +- +- return os.stat(name).st_rdev ++ m = re.search( '/dev/(.+)', name ) ++ if m: ++ name = m.group(1) ++ ++ try: ++ return blkdev_name_to_number_dict[name] ++ except KeyError: ++ pass ++ ++ m = re.search( '^(...)([0-9]+)', name ) ++ if not m: ++ return None ++ ++ try: ++ return blkdev_name_to_number_dict[m.group(1)] + int( m.group(2) ) ++ except KeyError: ++ return None + + # lookup_blkdev_partn_info( '/dev/sda3' ) + def lookup_raw_partn(partition): +@@ -137,6 +184,11 @@ def lookup_raw_partn(partition): + type: 'Disk' or identifying name for partition type + """ + ++ os_lookup = { 'Linux' : lookup_raw_partn_linux, ++ 'NetBSD' : lookup_raw_partn_netbsd } ++ return os_lookup[os.uname()[0]](partition) ++ ++def lookup_raw_partn_linux(partition): + if not re.match( '/dev/', partition ): + partition = '/dev/' + partition + +@@ -168,6 +220,37 @@ def lookup_raw_partn(partition): + + return None + ++def lookup_raw_partn_netbsd(partition): ++ m = re.search( '^(?:/dev/)?([a-z]+[0-9]+)([a-z]*)', partition ) ++ if not m: ++ return None ++ ++ drive = m.group(1) ++ partition = m.group(2) ++ ++ fd = os.popen( '/sbin/sysctl -n ' + ++ 'machdep.domain0.diskcookie.%s' % drive ) ++ try: ++ cookie = int(fd.readline()) ++ except ValueError: ++ cookie = -1 ++ fd.close() ++ ++ fd = os.popen( '/sbin/disklabel %s' % drive ) ++ lines = fd.readlines() ++ for line in lines: ++ # # size offset fstype [fsize bsize cpg/sgs] ++ # a: 80555328 9514512 4.2BSD 2048 16384 28624 ++ m = re.search( '^\s+%s:\s*([0-9]+)\s+([0-9]+)\s+' % partition, ++ line ) ++ if m: ++ return [ { 'device' : int(cookie), ++ 'start_sector' : long(m.group(2)), ++ 'nr_sectors' : long(m.group(1)), ++ 'type' : '0' } ] ++ ++ return None ++ + def lookup_disk_uname( uname ): + """Lookup a list of segments for either a physical or a virtual device. + uname [string]: name of the device in the format \'vd:id\' for a virtual +@@ -905,11 +988,12 @@ def vd_extents_validate(new_extents,new_ + vbd_ext['writeable'] = vbd['writeable'] + old_extents.append(vbd_ext) + +- ##### Now scan /proc/mounts for compile a list of extents corresponding to ++ ##### Now scan /bin/mount for compile a list of extents corresponding to + ##### any devices mounted in DOM0. This list is added on to old_extents + +- regexp = re.compile("/dev/(\S*) \S* \S* (..).*") +- fd = open('/proc/mounts', "r") ++ mount_cmd = { 'Linux' : '/bin/mount', 'NetBSD' : '/sbin/mount' } ++ regexp = re.compile("/dev/(\S*) on \S* type \S* \(([^\),]*)") ++ fd = os.popen(mount_cmd[os.uname()[0]]) + + while True: + line = fd.readline() +@@ -932,7 +1016,8 @@ def vd_extents_validate(new_extents,new_ + + # set a writeable flag as appropriate + for ext in ext_list: +- ext['writeable'] = m.group(2) == 'rw' ++ ext['writeable'] = (m.group(2) != 'ro' and ++ m.group(2) != 'read-only') + + # now we've got here, the contents of ext_list are in a + # suitable format to be added onto the old_extents list, ready |