ia64/xen-unstable

changeset 423:67a66de6d9a0

bitkeeper revision 1.206 (3eb7820fjxOimwW6NMSeo6KyAdqZUQ)

Many files:
new file
domctl, xi_ tools, updated domain builder, /proc/xeno/domains
author tlh20@elite.cl.cam.ac.uk
date Tue May 06 09:36:15 2003 +0000 (2003-05-06)
parents 5d0fd4216f8f
children 8b178f8d401d
files .bk-to-hg .hg-to-bk .rootkeys BitKeeper/etc/logging_ok tools/domain_builder/dom_builder.c tools/domain_builder/dom_kill.c tools/domctl/Makefile tools/domctl/build.xml tools/domctl/domctl tools/domctl/domctl.xml tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Command.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandDestroy.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandHelp.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStart.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStop.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Defaults.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/InetAddressPattern.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Main.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Settings.java tools/domctl/src/uk/ac/cam/cl/xeno/domctl/StringPattern.java tools/internal/Makefile tools/internal/dom0_defs.h tools/internal/hypervisor_defs.h tools/internal/mem_defs.h tools/internal/xi_build.c tools/internal/xi_create.c tools/internal/xi_destroy.c tools/internal/xi_start.c tools/internal/xi_stop.c tools/internal/xi_vifinit xen/common/dom0_ops.c xen/common/domain.c xen/common/schedule.c xen/include/xeno/dom0_ops.h xen/include/xeno/sched.h xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h
line diff
     1.1 --- a/.bk-to-hg	Sat May 03 13:47:58 2003 +0000
     1.2 +++ b/.bk-to-hg	Tue May 06 09:36:15 2003 +0000
     1.3 @@ -2,5 +2,7 @@
     1.4  set -e
     1.5  test -L tools/domain_builder/dom0_ops.h
     1.6  rm      tools/domain_builder/dom0_ops.h
     1.7 +test -L tools/internal/dom0_ops.h
     1.8 +rm      tools/internal/dom0_ops.h
     1.9  (find -depth -type d -print | xargs -r rmdir 2>/dev/null) || true
    1.10  exit 0
     2.1 --- a/.hg-to-bk	Sat May 03 13:47:58 2003 +0000
     2.2 +++ b/.hg-to-bk	Tue May 06 09:36:15 2003 +0000
     2.3 @@ -3,5 +3,7 @@ set -e
     2.4  mkdir -p tools
     2.5  mkdir -p tools/domain_builder
     2.6  ln -s ../../xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h tools/domain_builder/dom0_ops.h
     2.7 +mkdir -p tools/internal
     2.8 +ln -s ../../xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h tools/internal/dom0_ops.h
     2.9  (find -depth -type d -print | xargs -r rmdir 2>/dev/null) || true
    2.10  exit 0
     3.1 --- a/.rootkeys	Sat May 03 13:47:58 2003 +0000
     3.2 +++ b/.rootkeys	Tue May 06 09:36:15 2003 +0000
     3.3 @@ -15,6 +15,32 @@ 3e4d00468aE86IfyjfrJwYoxzM7pAw tools/dom
     3.4  3e71afadoAI0VvAGKebLpToVQxUKfQ tools/domain_builder/mynewdom
     3.5  3e4d0046VHhXwFuG5FK34AVxqd5A_A tools/domain_builder/newdom
     3.6  3e4d0046IBzDIeaMbQB-e2QB2ahbig tools/domain_builder/vifinit
     3.7 +3eb781edFwm_pW9FwnQACIe68viLOw tools/domctl/Makefile
     3.8 +3eb781fcTp_LPQwaot3SSSehkaf4eg tools/domctl/build.xml
     3.9 +3eb781fcXf-WczEdAhnTpWfbR55jqA tools/domctl/domctl
    3.10 +3eb781fcabCKRogwxJA3-jJKstw9Vg tools/domctl/domctl.xml
    3.11 +3eb781fcffCXkrcWLBxUTOfQFa3Saw tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Command.java
    3.12 +3eb781fcOLcVAcqnZOAikur6sAP0rA tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandDestroy.java
    3.13 +3eb781fcQuQVSKxKtp4fBgPOwx7DDw tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandHelp.java
    3.14 +3eb781fcRYdxK1HbjBX7r7VlO5PS0w tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java
    3.15 +3eb781fcbp9IAHTl40CoMavY1FNd_g tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStart.java
    3.16 +3eb781fdRXSsyEre7LxCmPJMpB5BaQ tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStop.java
    3.17 +3eb781fdX_thm9iHSxQ8vqQ0fL7Ncg tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Defaults.java
    3.18 +3eb781fdTWJr8RPdfuG20IC0CzYL2A tools/domctl/src/uk/ac/cam/cl/xeno/domctl/InetAddressPattern.java
    3.19 +3eb781fdA8LFQEYE2fXg1JDB9OceYA tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Main.java
    3.20 +3eb781fd_CgRvlaIBkJjxUSnuvCuHQ tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Settings.java
    3.21 +3eb781fdFDS4lap1-3ZVDtbKZfpVZA tools/domctl/src/uk/ac/cam/cl/xeno/domctl/StringPattern.java
    3.22 +3eb781fdl4lXWYZzmqDDUAYhAThRqQ tools/internal/Makefile
    3.23 +3eb781fdc539MQQm47rYRCCR3N5i-Q tools/internal/dom0_defs.h
    3.24 +3eb781fdEYILyFg60YVBsWNqxWFf1g tools/internal/dom0_ops.h
    3.25 +3eb781fddjylXbsepjppUyIXa5lcaQ tools/internal/hypervisor_defs.h
    3.26 +3eb781fdKiQbgozBsgs_zzJQ9ubehw tools/internal/mem_defs.h
    3.27 +3eb781fdgbSkh2O6JQS-65Dz4n0ItQ tools/internal/xi_build.c
    3.28 +3eb781fdW1SAyiaC4mTsXq_9fRHh-A tools/internal/xi_create.c
    3.29 +3eb781fdcJ0fF7rWfzAOArW-x4-gwA tools/internal/xi_destroy.c
    3.30 +3eb781fd8oRfPgH7qTh7xvgmwD6NgA tools/internal/xi_start.c
    3.31 +3eb781fd0Eo9K1jEFCSAVzO51i_ngg tools/internal/xi_stop.c
    3.32 +3eb781fd7211MZsLxJSiuy7W4KnJXg tools/internal/xi_vifinit
    3.33  3ea53c6dz47kAOwpk54f8_zOAQ5ngw tools/vdmanager/build.xml
    3.34  3eaff785PwN0C3-xhCf_zMCL27JIgQ tools/vdmanager/notes.xml
    3.35  3ea53c6dE-azH1i1VJmJMp9SHnETkQ tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Extent.java
     4.1 --- a/BitKeeper/etc/logging_ok	Sat May 03 13:47:58 2003 +0000
     4.2 +++ b/BitKeeper/etc/logging_ok	Tue May 06 09:36:15 2003 +0000
     4.3 @@ -18,3 +18,4 @@ rn@wyvis.camb.intel-research.net
     4.4  rn@wyvis.research.intel-research.net
     4.5  smh22@boulderdash.cl.cam.ac.uk
     4.6  smh22@uridium.cl.cam.ac.uk
     4.7 +tlh20@elite.cl.cam.ac.uk
     5.1 --- a/tools/domain_builder/dom_builder.c	Sat May 03 13:47:58 2003 +0000
     5.2 +++ b/tools/domain_builder/dom_builder.c	Tue May 06 09:36:15 2003 +0000
     5.3 @@ -49,7 +49,7 @@ static int do_kill_domain(int dom_id, in
     5.4      dom0_op_t dop;
     5.5      int cmd_fd;
     5.6  
     5.7 -    dop.cmd = DOM0_KILLDOMAIN;
     5.8 +    dop.cmd = DOM0_DESTROYDOMAIN;
     5.9      dop.u.killdomain.domain = dom_id;
    5.10      dop.u.killdomain.force  = force;
    5.11  
    5.12 @@ -178,8 +178,9 @@ static dom0_newdomain_t * create_new_dom
    5.13          return 0;
    5.14      }
    5.15  
    5.16 -    dop.cmd = DOM0_NEWDOMAIN;
    5.17 +    dop.cmd = DOM0_CREATEDOMAIN;
    5.18      dop.u.newdomain.memory_kb = req_mem;
    5.19 +    dop.u.newdomain.name[0] = 0;
    5.20  
    5.21      write(cmd_fd, &dop, sizeof(dom0_op_t));
    5.22      close(cmd_fd);
    5.23 @@ -435,7 +436,11 @@ static int launch_domain(dom_meminfo_t  
    5.24          return -1;
    5.25      }
    5.26  
    5.27 -    dop.cmd = DOM0_STARTDOM;
    5.28 +    dop.cmd = DOM0_BUILDDOMAIN;
    5.29 +    memcpy(&dop.u.meminfo, meminfo, sizeof(dom_meminfo_t));
    5.30 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
    5.31 +
    5.32 +    dop.cmd = DOM0_STARTDOMAIN;
    5.33      memcpy(&dop.u.meminfo, meminfo, sizeof(dom_meminfo_t));
    5.34      write(cmd_fd, &dop, sizeof(dom0_op_t));
    5.35  
     6.1 --- a/tools/domain_builder/dom_kill.c	Sat May 03 13:47:58 2003 +0000
     6.2 +++ b/tools/domain_builder/dom_kill.c	Tue May 06 09:36:15 2003 +0000
     6.3 @@ -21,7 +21,7 @@ static int do_kill_domain(int dom_id, in
     6.4      dom0_op_t dop;
     6.5      int cmd_fd;
     6.6  
     6.7 -    dop.cmd = DOM0_KILLDOMAIN;
     6.8 +    dop.cmd = DOM0_DESTROYDOMAIN;
     6.9      dop.u.killdomain.domain = dom_id;
    6.10      dop.u.killdomain.force  = force;
    6.11  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/domctl/Makefile	Tue May 06 09:36:15 2003 +0000
     7.3 @@ -0,0 +1,5 @@
     7.4 +default:
     7.5 +	ant dist
     7.6 +
     7.7 +clean:
     7.8 +	ant clean
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/domctl/build.xml	Tue May 06 09:36:15 2003 +0000
     8.3 @@ -0,0 +1,45 @@
     8.4 +<project name="domctl project" default="compile">
     8.5 +  <property name="src" location="src"/>
     8.6 +  <property name="build" location="build"/>
     8.7 +  <property name="dist" location="dist"/>
     8.8 +  <property name="lib" location="lib"/>
     8.9 +
    8.10 +  <target name="init">
    8.11 +    <tstamp/>
    8.12 +    <mkdir dir="${build}"/>     
    8.13 +  </target>
    8.14 +
    8.15 +  <target name="compile" depends="init">
    8.16 +    <javac srcdir="${src}" destdir="${build}" debug="on"/>
    8.17 +  </target>
    8.18 +
    8.19 +  <target name="dist" depends="compile">
    8.20 +    <jar jarfile="domctl.jar"
    8.21 +         excludes="*~"
    8.22 +	 basedir="${build}">
    8.23 +      <fileset dir="${src}" />
    8.24 +      <fileset dir=".">
    8.25 +        <include name="build.xml"/>
    8.26 +        <include name="domctl"/>
    8.27 +      </fileset>
    8.28 +      <manifest>
    8.29 +        <attribute name="Built-By" value="${user.name}"/>
    8.30 +	<attribute name="Main-Class" value="uk.ac.cam.cl.xeno.domctl.Main"/>
    8.31 +	<attribute name="Sealed" value="true"/>
    8.32 +      </manifest>
    8.33 +    </jar>
    8.34 +  </target>
    8.35 +
    8.36 +  <target name="test" depends="compile">
    8.37 +    <java fork="true" classname="uk.ac.cam.cl.xeno.domctl.Main">
    8.38 +      <classpath>
    8.39 +        <pathelement path="${build}"/>
    8.40 +      </classpath>
    8.41 +    </java>
    8.42 +  </target>
    8.43 +
    8.44 +  <target name="clean">
    8.45 +    <delete dir="${build}"/>
    8.46 +    <delete dir="${lib}"/>
    8.47 +  </target>
    8.48 +</project>
    8.49 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/domctl/domctl	Tue May 06 09:36:15 2003 +0000
     9.3 @@ -0,0 +1,31 @@
     9.4 +#!/bin/bash -x
     9.5 +
     9.6 +if [ -z "$DEFAULTS_FILE" ] ; then DEFAULTS_FILE=domctl.xml ; fi
     9.7 +if [ -z "$DEFAULTS_PATH" ] ; then DEFAULTS_PATH=.:/etc ; fi
     9.8 +if [ -z "$QUERY_DEV" ] ; then QUERY_DEV=eth0 ; fi
     9.9 +if [ -z "$IFCONFIG" ] ; then IFCONFIG=/sbin/ifconfig ; fi
    9.10 +if [ -z "$ROUTE" ] ; then ROUTE=/sbin/route ; fi
    9.11 +if [ -z "$JAVA" ] ; then JAVA=java ; fi
    9.12 +
    9.13 +if [ ! -x "$IFCONFIG" ]; then
    9.14 +  echo Could not find executable $IFCONFIG
    9.15 +  exit 1
    9.16 +fi
    9.17 +
    9.18 +if [ ! -x "$ROUTE" ]; then
    9.19 +  echo Could not find executable $ROUTE
    9.20 +  exit 1
    9.21 +fi
    9.22 +
    9.23 +# Try to determine dom0 network settings to avoid hard-coding
    9.24 +# particular machines in the defaults file
    9.25 +LOCAL_IP=$(/sbin/ifconfig $QUERY_DEV | grep 'inet addr' | tr ':' '\t' | awk '{print $3}')
    9.26 +LOCAL_MASK=$(/sbin/ifconfig $QUERY_DEV | grep 'Mask' | tr ':' '\t' | awk '{print $7}')
    9.27 +LOCAL_ROUTE=$(/sbin/route -n | grep $QUERY_DEV | grep 'G' | awk '{print $2}')
    9.28 +
    9.29 +
    9.30 +#ARGS="-DTEST -DDEFAULTS_FILE=$DEFAULTS_FILE -DDEFAULTS_PATH=$DEFAULTS_PATH -DLOCAL_IP=$LOCAL_IP -DLOCAL_MASK=$LOCAL_MASK -DLOCAL_ROUTE=$LOCAL_ROUTE"
    9.31 +ARGS="-DDEFAULTS_FILE=$DEFAULTS_FILE -DDEFAULTS_PATH=$DEFAULTS_PATH -DLOCAL_IP=$LOCAL_IP -DLOCAL_MASK=$LOCAL_MASK -DLOCAL_ROUTE=$LOCAL_ROUTE"
    9.32 +
    9.33 +
    9.34 +$JAVA $ARGS -jar domctl.jar $*
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/domctl/domctl.xml	Tue May 06 09:36:15 2003 +0000
    10.3 @@ -0,0 +1,15 @@
    10.4 +<?xml version="1.0"?>
    10.5 +<domctl_defaults>
    10.6 +<domain_name>XenoLinux</domain_name>
    10.7 +<domain_size_kb>16000</domain_size_kb>
    10.8 +<domain_image>./image</domain_image>
    10.9 +<domain_vifs>1</domain_vifs>
   10.10 +<root_device>/dev/nfs</root_device>
   10.11 +<nw_ip>=+</nw_ip>
   10.12 +<nw_gw>=</nw_gw>
   10.13 +<nw_mask>=</nw_mask>
   10.14 +<nw_nfs_server>128.232.32.20</nw_nfs_server>
   10.15 +<nw_nfs_root>/usr/groups/srgboot/moonraider/roots/root+</nw_nfs_root>
   10.16 +<max_domain_number>2</max_domain_number>
   10.17 +<xi_tools_dir>/tools/internal/</xi_tools_dir>
   10.18 +</domctl_defaults>
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Command.java	Tue May 06 09:36:15 2003 +0000
    11.3 @@ -0,0 +1,74 @@
    11.4 +package uk.ac.cam.cl.xeno.domctl;
    11.5 +
    11.6 +public abstract class Command
    11.7 +{
    11.8 +  public abstract int doCommand(Defaults d, String args[]);
    11.9 +  public abstract String getName();			
   11.10 +  public abstract String getUsage();
   11.11 +  public abstract String getHelpText();
   11.12 +
   11.13 +  public String getStringParameter(String args[], char key, String def)
   11.14 +  {
   11.15 +    String r = getParameter (args, key);
   11.16 +    return (r == null) ? def : r;
   11.17 +  }
   11.18 +
   11.19 +  public int getIntParameter(String args[], char key, int def)
   11.20 +  {
   11.21 +    String r = getParameter (args, key);
   11.22 +    return (r == null) ? def : (Integer.parseInt (r));
   11.23 +  }
   11.24 +
   11.25 +  public boolean getFlagParameter(String args[], char key)
   11.26 +  {
   11.27 +    String r = getParameter (args, key);
   11.28 +    return (r == null) ? false : true;
   11.29 +  }
   11.30 +
   11.31 +  public String getParameter (String args[], char key)
   11.32 +  {
   11.33 +    int i;
   11.34 +    String result = null;
   11.35 +    for (i = 0; i < args.length; i ++)
   11.36 +      {
   11.37 +	if (args[i].startsWith("-" + key)) 
   11.38 +	  {
   11.39 +	    if (args[i].length() > 2)
   11.40 +	      {
   11.41 +		result = args[i].substring(2, args[i].length());
   11.42 +	      }
   11.43 +	    else
   11.44 +	      {
   11.45 +		result = "";
   11.46 +	      }
   11.47 +	  }
   11.48 +      }
   11.49 +    return result;
   11.50 +  }
   11.51 +
   11.52 +  public int reportXIError (String message, String cmd_array[])
   11.53 +  {
   11.54 +    int i;
   11.55 +    System.err.print (message + " using: ");
   11.56 +    for (i = 0; i < cmd_array.length; i ++) {
   11.57 +      System.err.print (cmd_array[i] + " ");
   11.58 +    }
   11.59 +    System.err.println();
   11.60 +    return -1;
   11.61 +  }
   11.62 +
   11.63 +  public int reportError (String message)
   11.64 +  {
   11.65 +    System.err.println (message);
   11.66 +    return -1;
   11.67 +  }
   11.68 +
   11.69 +  public void reportCommand (String cmd_array[])
   11.70 +  {
   11.71 +    int i;
   11.72 +    for (i = 0; i < cmd_array.length; i ++) {
   11.73 +      System.out.print (cmd_array[i] + " ");
   11.74 +    }
   11.75 +    System.out.println();
   11.76 +  }
   11.77 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandDestroy.java	Tue May 06 09:36:15 2003 +0000
    12.3 @@ -0,0 +1,69 @@
    12.4 +package uk.ac.cam.cl.xeno.domctl;
    12.5 +
    12.6 +import java.io.*;
    12.7 +import java.net.*;
    12.8 +
    12.9 +public class CommandDestroy extends Command
   12.10 +{
   12.11 +  public int doCommand(Defaults d, String args[])
   12.12 +  {
   12.13 +    Runtime r = Runtime.getRuntime ();
   12.14 +    int domain_id = getIntParameter(args, 'n', 0);
   12.15 +    boolean force = getFlagParameter(args, 'f');
   12.16 +    int rc = 0;
   12.17 +
   12.18 +    if (domain_id == 0) {
   12.19 +      System.err.println ("Expected -n<domain_id>");
   12.20 +      rc = -1;
   12.21 +      return rc;
   12.22 +    }
   12.23 +
   12.24 +    try
   12.25 +      {
   12.26 +	Process destroy_p;
   12.27 +	String destroy_cmdarray[] = force ? new String[3] : new String[2];
   12.28 +	int destroy_rc;
   12.29 +	int idx = 0;
   12.30 +	destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
   12.31 +	if (force) {
   12.32 +	  destroy_cmdarray[idx++] = "-f";
   12.33 +	}
   12.34 +	destroy_cmdarray[idx++] = "" + domain_id;
   12.35 +
   12.36 +	if (Settings.TEST) {
   12.37 +	  reportCommand (destroy_cmdarray);
   12.38 +	} else {
   12.39 +	  destroy_p = r.exec (destroy_cmdarray);
   12.40 +	  destroy_rc = destroy_p.waitFor ();
   12.41 +	  
   12.42 +	  if (destroy_rc != 0) {
   12.43 +	    return reportXIError ("Could not destroy domain", destroy_cmdarray);
   12.44 +	  }
   12.45 +	}
   12.46 +      }
   12.47 +    catch (Exception e) 
   12.48 +      {
   12.49 +	System.err.println ("Could not destroy domain (" + e + ")");
   12.50 +	e.printStackTrace ();
   12.51 +	rc = -1;
   12.52 +      }
   12.53 +
   12.54 +    return rc;
   12.55 +  }
   12.56 +
   12.57 +  public String getName()
   12.58 +  {
   12.59 +    return "destroy";
   12.60 +  }
   12.61 +
   12.62 +  public String getUsage()
   12.63 +  {
   12.64 +    return "[-f] [-n<domain_id>]";
   12.65 +  }
   12.66 +
   12.67 +  public String getHelpText()
   12.68 +  {
   12.69 +    return
   12.70 +      "Destory the specified domain.  -f forcibly destroys it.";
   12.71 +  }
   12.72 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandHelp.java	Tue May 06 09:36:15 2003 +0000
    13.3 @@ -0,0 +1,58 @@
    13.4 +package uk.ac.cam.cl.xeno.domctl;
    13.5 +
    13.6 +public class CommandHelp extends Command
    13.7 +{
    13.8 +  public int doCommand(Defaults d, String args[])
    13.9 +  {
   13.10 +    if (args.length <= 1)
   13.11 +      {
   13.12 +	System.out.println ("Usage:");
   13.13 +	for (int i = 0; i < Main.commands.length; i ++) 
   13.14 +	  {
   13.15 +	    String name = Main.commands[i].getName ();
   13.16 +	    String usage = Main.commands[i].getUsage ();
   13.17 +	    while (name.length() < 12) name = name + " ";
   13.18 +	    System.out.println ("   " + name + usage);
   13.19 +	  }
   13.20 +      }
   13.21 +    else 
   13.22 +      {
   13.23 +	for (int i = 0; i < Main.commands.length; i ++) 
   13.24 +	  {
   13.25 +	    String name = Main.commands[i].getName ();
   13.26 +	    String usage = Main.commands[i].getUsage ();
   13.27 +	    if (name.equals (args[1]))
   13.28 +	      {
   13.29 +		doHelpFor (Main.commands[i]);
   13.30 +		break;
   13.31 +	      }
   13.32 +	  }
   13.33 +      }
   13.34 +
   13.35 +    System.out.println ("");
   13.36 +    return 0;
   13.37 +  }
   13.38 +
   13.39 +  public int doHelpFor (Command c)
   13.40 +  {
   13.41 +    System.out.println ("domctl " + c.getName() + " " + c.getUsage());
   13.42 +    System.out.println ();
   13.43 +    System.out.println (c.getHelpText ());
   13.44 +    return 0;
   13.45 +  }
   13.46 +
   13.47 +  public String getName()
   13.48 +  {
   13.49 +    return "help";
   13.50 +  }
   13.51 +
   13.52 +  public String getUsage()
   13.53 +  {
   13.54 +    return "";
   13.55 +  }
   13.56 +
   13.57 +  public String getHelpText()
   13.58 +  {
   13.59 +    return "This message";
   13.60 +  }  
   13.61 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java	Tue May 06 09:36:15 2003 +0000
    14.3 @@ -0,0 +1,203 @@
    14.4 +package uk.ac.cam.cl.xeno.domctl;
    14.5 +
    14.6 +import java.io.*;
    14.7 +import java.net.*;
    14.8 +
    14.9 +public class CommandNew extends Command
   14.10 +{
   14.11 +  public int doCommand(Defaults d, String args[])
   14.12 +  {
   14.13 +    Runtime r = Runtime.getRuntime ();
   14.14 +    String name = getStringParameter(args, 'n', d.domainName);
   14.15 +    int size = getIntParameter(args, 'k', d.domainSizeKB);
   14.16 +    String image = getStringParameter(args, 'i', d.domainImage);
   14.17 +    String initrd = getStringParameter (args, 'r', d.domainInitRD);
   14.18 +    int vifs = getIntParameter(args, 'v', d.domainVIFs);
   14.19 +    String bargs = getStringParameter (args, 'a', "");
   14.20 +    String root_dev = getStringParameter (args, 'd', d.rootDevice);
   14.21 +    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
   14.22 +    String nw_ip = getStringParameter (args, '4', d.NWIP);
   14.23 +    String nw_gw = getStringParameter (args, 'g', d.NWGW);
   14.24 +    String nw_mask = getStringParameter (args, 'm', d.NWMask);
   14.25 +    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
   14.26 +    String nw_host = getStringParameter (args, 'h', d.NWHost);
   14.27 +    String domain_ip = "";
   14.28 +    int rc = 0;
   14.29 +    int domain_id;
   14.30 +    DataInputStream dis;
   14.31 +    int idx;
   14.32 +    int i;
   14.33 +
   14.34 +
   14.35 +    try
   14.36 +      {
   14.37 +	/* Some initial sanity checks */
   14.38 +	if (root_dev.equals ("/dev/nfs") && (vifs == 0)) {
   14.39 +	  return reportError ("Cannot use NFS root without VIFs configured");
   14.40 +	}
   14.41 +
   14.42 +	/* Create a new empty domain */
   14.43 +	Process create_p;
   14.44 +	String create_cmdarray[] = new String[3];
   14.45 +	int create_rc;
   14.46 +	create_cmdarray[0] = d.XIToolsDir + "xi_create";
   14.47 +	create_cmdarray[1] = "" + size;
   14.48 +	create_cmdarray[2] = name;
   14.49 +	if (Settings.TEST) {
   14.50 +	  reportCommand (create_cmdarray);
   14.51 +	  domain_id=1;
   14.52 +	  create_rc=0;
   14.53 +	} else {
   14.54 +	  create_p = r.exec (create_cmdarray);
   14.55 +	  dis = new DataInputStream (new BufferedInputStream (create_p.getInputStream ()));
   14.56 +	  domain_id = Integer.parseInt (dis.readLine ());
   14.57 +	  create_rc = create_p.waitFor ();
   14.58 +	}
   14.59 +
   14.60 +	if (create_rc != 0) {
   14.61 +	  return reportXIError ("Failed to create domain", create_cmdarray);
   14.62 +	} else if (domain_id > d.MaxDomainNumber) {
   14.63 +	  return reportError ("Cannot configure more than " + 
   14.64 +			      d.MaxDomainNumber + " domains");
   14.65 +	}
   14.66 +	
   14.67 +	/* Set up boot parameters to pass to xi_build. */
   14.68 +	bargs = "";
   14.69 +
   14.70 +	if (root_dev.equals ("/dev/nfs")) {
   14.71 +	  if (vifs == 0) {
   14.72 +	    return reportError ("Cannot use NFS root without VIFs configured");
   14.73 +	  }
   14.74 +	  bargs = (bargs + 
   14.75 +		   "root=/dev/nfs " +
   14.76 +		   "nfsroot=" + StringPattern.parse(nfs_root_path).resolve(domain_id) +
   14.77 +		   " ");
   14.78 +	} else {
   14.79 +	  bargs = ("root=" + StringPattern.parse(root_dev).resolve(domain_id) +
   14.80 +		   " ");
   14.81 +
   14.82 +	}
   14.83 +	
   14.84 +	if (vifs > 0) {
   14.85 +	  domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
   14.86 +	  if (nw_host == null) {
   14.87 +	    try {
   14.88 +	      nw_host = InetAddress.getByName(domain_ip).getHostName();
   14.89 +	    } catch (UnknownHostException uhe) {
   14.90 +	      nw_host = "" + nw_ip;
   14.91 +	    }
   14.92 +	    
   14.93 +	  }
   14.94 +	  bargs = ("ip=" + domain_ip +
   14.95 +		   ":" + InetAddressPattern.parse(nw_nfs_server).resolve(domain_id) +
   14.96 +		   ":" + InetAddressPattern.parse(nw_gw).resolve(domain_id) + 
   14.97 +		   ":" + InetAddressPattern.parse(nw_mask).resolve(domain_id) +
   14.98 +		   ":" + nw_host + 
   14.99 +		   ":eth0:off " + bargs);
  14.100 +	}
  14.101 +	
  14.102 +	/* Build the domain */
  14.103 +	Process build_p;
  14.104 +	String build_cmdarray[] = new String[6];
  14.105 +	int build_rc;
  14.106 +	idx = 0;
  14.107 +	for (i = 0; i < build_cmdarray.length; i ++) 
  14.108 +	  build_cmdarray[i] = "";
  14.109 +	build_cmdarray[idx ++] = d.XIToolsDir + "xi_build";
  14.110 +	build_cmdarray[idx ++] = "" + domain_id;
  14.111 +	build_cmdarray[idx ++] = "" + image;
  14.112 +	build_cmdarray[idx ++] = "" + vifs;
  14.113 +	if (initrd != null) build_cmdarray[idx ++] = "initrd=" + initrd;
  14.114 +	build_cmdarray[idx ++] = "" + bargs;
  14.115 +	System.out.println ("Build args: " + bargs);
  14.116 +	if (Settings.TEST) {
  14.117 +	  reportCommand (build_cmdarray);
  14.118 +	  build_rc = 0;
  14.119 +	} else {
  14.120 +	  build_p = r.exec (build_cmdarray);
  14.121 +	  build_rc = build_p.waitFor ();
  14.122 +	}
  14.123 +
  14.124 +	if (build_rc != 0) {
  14.125 +	  return reportXIError ("Failed to build domain", build_cmdarray);
  14.126 +	}
  14.127 +
  14.128 +
  14.129 +	/* Set up the first VIF if necessary */
  14.130 +	if (vifs > 0) {
  14.131 +	  Process vifinit_p;
  14.132 +	  String vifinit_cmdarray[] = new String[4];
  14.133 +	  int vifinit_rc;
  14.134 +	  vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
  14.135 +	  vifinit_cmdarray[1] = "" + domain_id;
  14.136 +	  vifinit_cmdarray[2] = "0";
  14.137 +	  vifinit_cmdarray[3] = domain_ip;
  14.138 +	  if (Settings.TEST) {
  14.139 +	    reportCommand (vifinit_cmdarray);
  14.140 +	    vifinit_rc = 0;
  14.141 +	  } else {
  14.142 +	    vifinit_p = r.exec (vifinit_cmdarray);
  14.143 +	    vifinit_rc = vifinit_p.waitFor ();
  14.144 +	  }
  14.145 +	  
  14.146 +	  if (vifinit_rc != 0) {
  14.147 +	    return reportXIError ("Failed to initialise VIF 0", vifinit_cmdarray);
  14.148 +	  }
  14.149 +	}
  14.150 +      }
  14.151 +    catch (Exception e) 
  14.152 +      {
  14.153 +	System.err.println ("Could not create new domain (" + e + ")");
  14.154 +	e.printStackTrace ();
  14.155 +	rc = -1;
  14.156 +      }
  14.157 +
  14.158 +    return rc;
  14.159 +  }
  14.160 +
  14.161 +  public String getName()
  14.162 +  {
  14.163 +    return "new";
  14.164 +  }
  14.165 +
  14.166 +  public String getUsage()
  14.167 +  {
  14.168 +    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
  14.169 +  }
  14.170 +
  14.171 +  public String getHelpText()
  14.172 +  {
  14.173 +    return
  14.174 +      "Create a new domain.  Note that most of the parameters will assume\n" +
  14.175 +      "default values: it should not be necessary to specify them all. See\n" +
  14.176 +      "domctl.xml for the current default settings.\n" +
  14.177 +      "\n" +
  14.178 +      "General command line options:\n" +
  14.179 +      "  -n  Domain name                              domain_name\n" +
  14.180 +      "  -k  Domain size (kb)                         domain_size_kb\n" +
  14.181 +      "  -i  Domain image name                        domain_image\n" +
  14.182 +      "  -v  Number of VIFs                           domain_vifs\n" +
  14.183 +      "  -r  InitRD (if required)                     domain_init_rd\n" +
  14.184 +      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
  14.185 +      "  -a  Additional boot parameters\n" +
  14.186 +      "\n" +
  14.187 +      "Networking options:\n" +
  14.188 +      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
  14.189 +      "  -s  NFS server                               nw_nfs_server\n" +
  14.190 +      "  -4  Domain IPv4 address                      nw_ip\n" +
  14.191 +      "  -g  Domain gateway                           nw_gw\n" +
  14.192 +      "  -m  Domain net mask                          nw_mask\n" +
  14.193 +      "  -h  Domain hostname                          nw_host\n" +
  14.194 +      "\n" +
  14.195 +      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
  14.196 +      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
  14.197 +      "domain 1 patterns would expand as follows:\n" +
  14.198 +      "\n" +
  14.199 +      "  /dev/hda+       /dev/hda1\n" +
  14.200 +      "  /dev/hda7+      /dev/hda8\n" +
  14.201 +      "  128.232.8.50+   128.232.8.51\n" +
  14.202 +      "\n" +
  14.203 +      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
  14.204 +      "expanded to the corresponding setting from the calling domain.\n";
  14.205 +  }
  14.206 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStart.java	Tue May 06 09:36:15 2003 +0000
    15.3 @@ -0,0 +1,63 @@
    15.4 +package uk.ac.cam.cl.xeno.domctl;
    15.5 +
    15.6 +import java.io.*;
    15.7 +import java.net.*;
    15.8 +
    15.9 +public class CommandStart extends Command
   15.10 +{
   15.11 +  public int doCommand(Defaults d, String args[])
   15.12 +  {
   15.13 +    Runtime r = Runtime.getRuntime ();
   15.14 +    int domain_id = getIntParameter(args, 'n', 0);
   15.15 +    int rc = 0;
   15.16 +
   15.17 +    if (domain_id == 0) {
   15.18 +      System.err.println ("Expected -n<domain_id>");
   15.19 +      rc = -1;
   15.20 +      return rc;
   15.21 +    }
   15.22 +
   15.23 +    try
   15.24 +      {
   15.25 +	Process start_p;
   15.26 +	String start_cmdarray[] = new String[2];
   15.27 +	int start_rc;
   15.28 +	start_cmdarray[0] = d.XIToolsDir + "xi_start";
   15.29 +	start_cmdarray[1] = "" + domain_id;
   15.30 +
   15.31 +	if (Settings.TEST) {
   15.32 +	  reportCommand (start_cmdarray);
   15.33 +	} else {
   15.34 +	  start_p = r.exec (start_cmdarray);
   15.35 +	  start_rc = start_p.waitFor ();
   15.36 +	  if (start_rc != 0) {
   15.37 +	    return reportXIError ("Could not start domain", start_cmdarray);
   15.38 +	  }
   15.39 +	}
   15.40 +      }
   15.41 +    catch (Exception e) 
   15.42 +      {
   15.43 +	System.err.println ("Could not start new domain (" + e + ")");
   15.44 +	e.printStackTrace ();
   15.45 +	rc = -1;
   15.46 +      }
   15.47 +
   15.48 +    return rc;
   15.49 +  }
   15.50 +
   15.51 +  public String getName()
   15.52 +  {
   15.53 +    return "start";
   15.54 +  }
   15.55 +
   15.56 +  public String getUsage()
   15.57 +  {
   15.58 +    return "[-n<domain_id>]";
   15.59 +  }
   15.60 +
   15.61 +  public String getHelpText()
   15.62 +  {
   15.63 +    return
   15.64 +      "Start the specified domain.";
   15.65 +  }
   15.66 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandStop.java	Tue May 06 09:36:15 2003 +0000
    16.3 @@ -0,0 +1,64 @@
    16.4 +package uk.ac.cam.cl.xeno.domctl;
    16.5 +
    16.6 +import java.io.*;
    16.7 +import java.net.*;
    16.8 +
    16.9 +public class CommandStop extends Command
   16.10 +{
   16.11 +  public int doCommand(Defaults d, String args[])
   16.12 +  {
   16.13 +    Runtime r = Runtime.getRuntime ();
   16.14 +    int domain_id = getIntParameter(args, 'n', 0);
   16.15 +    int rc = 0;
   16.16 +
   16.17 +    if (domain_id == 0) {
   16.18 +      System.err.println ("Expected -n<domain_id>");
   16.19 +      rc = -1;
   16.20 +      return rc;
   16.21 +    }
   16.22 +
   16.23 +    try
   16.24 +      {
   16.25 +	Process stop_p;
   16.26 +	String stop_cmdarray[] = new String[2];
   16.27 +	int stop_rc;
   16.28 +	stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
   16.29 +	stop_cmdarray[1] = "" + domain_id;
   16.30 +
   16.31 +	if (Settings.TEST) {
   16.32 +	  reportCommand (stop_cmdarray);
   16.33 +	} else {
   16.34 +	  stop_p = r.exec (stop_cmdarray);
   16.35 +	  stop_rc = stop_p.waitFor ();
   16.36 +	  
   16.37 +	  if (stop_rc != 0) {
   16.38 +	    return reportXIError ("Could not stop domain", stop_cmdarray);
   16.39 +	  }
   16.40 +	}
   16.41 +      }
   16.42 +    catch (Exception e) 
   16.43 +      {
   16.44 +	System.err.println ("Could not stop new domain (" + e + ")");
   16.45 +	e.printStackTrace ();
   16.46 +	rc = -1;
   16.47 +      }
   16.48 +
   16.49 +    return rc;
   16.50 +  }
   16.51 +
   16.52 +  public String getName()
   16.53 +  {
   16.54 +    return "stop";
   16.55 +  }
   16.56 +
   16.57 +  public String getUsage()
   16.58 +  {
   16.59 +    return "[-n<domain_id>]";
   16.60 +  }
   16.61 +
   16.62 +  public String getHelpText()
   16.63 +  {
   16.64 +    return
   16.65 +      "Stop the specified domain.";
   16.66 +  }
   16.67 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Defaults.java	Tue May 06 09:36:15 2003 +0000
    17.3 @@ -0,0 +1,153 @@
    17.4 +package uk.ac.cam.cl.xeno.domctl;
    17.5 +
    17.6 +import java.net.InetAddress;
    17.7 +import java.io.*;
    17.8 +import org.xml.sax.*;
    17.9 +import org.xml.sax.helpers.*;
   17.10 +
   17.11 +public class Defaults
   17.12 +{
   17.13 +  String domainName;
   17.14 +
   17.15 +  int domainSizeKB;
   17.16 +  String domainImage;
   17.17 +  String domainInitRD;
   17.18 +  int domainVIFs;
   17.19 +
   17.20 +  String rootDevice;
   17.21 +
   17.22 +  String NWIP;
   17.23 +  String NWGW;
   17.24 +  String NWMask;
   17.25 +  String NWHost;
   17.26 +
   17.27 +  String NWNFSServer;
   17.28 +  String NWNFSRoot;
   17.29 +
   17.30 +  int MaxDomainNumber;
   17.31 +
   17.32 +  String XIToolsDir;
   17.33 +
   17.34 +  /***********************************************************************/
   17.35 +
   17.36 +  public Defaults ()
   17.37 +  {
   17.38 +    File f = Settings.getDefaultsFile ();
   17.39 +    System.out.println ("f=" + f);
   17.40 +
   17.41 +    try
   17.42 +      {
   17.43 +	XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl();
   17.44 +	Handler handler = new Handler ();
   17.45 +	xr.setContentHandler (handler);
   17.46 +	xr.setErrorHandler (handler);
   17.47 +	xr.parse (new InputSource(new FileReader (f)));
   17.48 +      }
   17.49 +    catch (Exception e) 
   17.50 +      {
   17.51 +	System.err.println ("Could not read defaults file " + f +
   17.52 +			    "\nException: " + e);
   17.53 +	e.printStackTrace();
   17.54 +	System.exit(1);
   17.55 +      }
   17.56 +
   17.57 +    System.out.println ("Domain defaults:");
   17.58 +    System.out.println ("   name        " + domainName);
   17.59 +    System.out.println ("   size        " + domainSizeKB);
   17.60 +    System.out.println ("   vifs        " + domainVIFs);
   17.61 +    System.out.println ("   domainImage " + domainImage);
   17.62 +    System.out.println ("   domainInitRD " + domainInitRD);
   17.63 +    System.out.println ("   rootDevice " + rootDevice);
   17.64 +    System.out.println ("   NWIP " + NWIP);
   17.65 +    System.out.println ("   NWGW " + NWGW);
   17.66 +    System.out.println ("   NWMask " + NWMask);
   17.67 +    System.out.println ("   MaxDomainNumber " + MaxDomainNumber);
   17.68 +    System.out.println ("   NWNFSServer " + NWNFSServer);
   17.69 +    System.out.println ("   NWNFSRoot " + NWNFSRoot);
   17.70 +    System.out.println ("   XIToolsDir " + XIToolsDir);
   17.71 +  }
   17.72 +
   17.73 +  /***********************************************************************/
   17.74 +
   17.75 +  class Handler extends DefaultHandler
   17.76 +  {
   17.77 +    boolean inDomctlDefaults;
   17.78 +    String lastName;
   17.79 +
   17.80 +    public void startDocument ()
   17.81 +    {
   17.82 +    }
   17.83 +
   17.84 +    public void endDocument ()
   17.85 +    {
   17.86 +    }
   17.87 +
   17.88 +    public void startElement (String uri, String name,
   17.89 +			      String qname, Attributes atts)
   17.90 +    {
   17.91 +      if (qname.equals ("domctl_defaults")) {
   17.92 +	inDomctlDefaults = true;
   17.93 +      } else {
   17.94 +	lastName = qname;
   17.95 +      }
   17.96 +    }
   17.97 +
   17.98 +    public void endElement (String uri, String name, String qname)
   17.99 +    {
  17.100 +      lastName = "";
  17.101 +      if (qname.equals ("domctl_defaults")) {
  17.102 +	inDomctlDefaults = false;
  17.103 +      }
  17.104 +    }
  17.105 +    
  17.106 +    public void characters (char ch[], int start, int length)
  17.107 +    {
  17.108 +      String s = new String (ch, start, length);
  17.109 +      if (lastName != null)
  17.110 +	{
  17.111 +	  if (lastName.equals ("domain_size_kb")) {
  17.112 +	    domainSizeKB = Integer.parseInt (s);
  17.113 +	  } else if (lastName.equals ("domain_image")) {
  17.114 +	    domainImage = s;
  17.115 +	  } else if (lastName.equals ("domain_name")) {
  17.116 +	    domainName = s;
  17.117 +	  } else if (lastName.equals ("domain_init_rd")) {
  17.118 +	    domainInitRD = s;
  17.119 +	  } else if (lastName.equals ("domain_vifs")) {
  17.120 +	    domainVIFs = Integer.parseInt (s);
  17.121 +	  } else if (lastName.equals ("root_device")) {
  17.122 +	    rootDevice = s;
  17.123 +	  } else if (lastName.equals ("nw_ip")) {
  17.124 +	    NWIP = expandDefault (s, Settings.LOCAL_IP);
  17.125 +	  } else if (lastName.equals ("nw_gw")) {
  17.126 +	    NWGW = expandDefault (s, Settings.LOCAL_GW);
  17.127 +	  } else if (lastName.equals ("nw_mask")) {
  17.128 +	    NWMask = expandDefault (s, Settings.LOCAL_MASK);
  17.129 +	  } else if (lastName.equals ("nw_host")) {
  17.130 +	    NWHost = s;
  17.131 +	  } else if (lastName.equals ("nw_nfs_server")) {
  17.132 +	    NWNFSServer = s;
  17.133 +	  } else if (lastName.equals ("nw_nfs_root")) {
  17.134 +	    NWNFSRoot = s;
  17.135 +	  } else if (lastName.equals ("max_domain_number")) {
  17.136 +	    MaxDomainNumber = Integer.parseInt(s);
  17.137 +	  } else if (lastName.equals ("xi_tools_dir")) {
  17.138 +	    XIToolsDir = s;
  17.139 +	  }
  17.140 +	}
  17.141 +    }
  17.142 +  }
  17.143 +
  17.144 +  public String expandDefault (String supplied, String self)
  17.145 +  {
  17.146 +    if (supplied.startsWith ("=")) {
  17.147 +      if (supplied.length() > 1) {
  17.148 +	return self + supplied.substring (1, supplied.length());
  17.149 +      } else {
  17.150 +	return self;
  17.151 +      }
  17.152 +    } else {
  17.153 +      return supplied;
  17.154 +    }
  17.155 +  }
  17.156 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/InetAddressPattern.java	Tue May 06 09:36:15 2003 +0000
    18.3 @@ -0,0 +1,60 @@
    18.4 +package uk.ac.cam.cl.xeno.domctl;
    18.5 +
    18.6 +import java.net.*;
    18.7 +
    18.8 +public class InetAddressPattern
    18.9 +{
   18.10 +  InetAddress base;
   18.11 +  boolean addDom;
   18.12 +
   18.13 +  static InetAddressPattern parse (String t)
   18.14 +  {
   18.15 +    InetAddressPattern result = new InetAddressPattern ();
   18.16 +    char[] ca = t.toCharArray ();
   18.17 +    int idx = 0;
   18.18 +    int len = ca.length;
   18.19 +
   18.20 +    try {
   18.21 +      if (len == 0) {
   18.22 +	result.base = null;
   18.23 +	result.addDom = false;
   18.24 +      } else if (ca[len - 1] == '+') {
   18.25 +	result.base = InetAddress.getByName(t.substring(0, len - 1));
   18.26 +	result.addDom = true;
   18.27 +      } else {
   18.28 +	result.base = InetAddress.getByName(t);
   18.29 +	result.addDom = false;
   18.30 +      }
   18.31 +    } catch (UnknownHostException uhe) {
   18.32 +      result.base = null;
   18.33 +      result.addDom = false;
   18.34 +    }
   18.35 +
   18.36 +    return result;
   18.37 +  }
   18.38 +
   18.39 +  public String resolve (int domain_id) {
   18.40 +    byte b[] = base.getAddress ();
   18.41 +    if (addDom) {
   18.42 +      if (((int)b[3]) + domain_id > 255) {
   18.43 +	if (((int)b[2]) + domain_id > 255) {
   18.44 +	  if (((int)b[1]) + domain_id > 255) {
   18.45 +	    b[0] ++;
   18.46 +	  }
   18.47 +	  b[1] ++;
   18.48 +	}
   18.49 +	b[2] ++;
   18.50 +      }
   18.51 +      b[3] += domain_id;
   18.52 +    }
   18.53 +    return "" + 
   18.54 +      (b[0] + (b[0] < 0 ? 256 : 0)) + "." + 
   18.55 +      (b[1] + (b[1] < 0 ? 256 : 0)) + "." + 
   18.56 +      (b[2] + (b[2] < 0 ? 256 : 0)) + "." + 
   18.57 +      (b[3] + (b[3] < 0 ? 256 : 0));
   18.58 +  }
   18.59 +
   18.60 +  public String toString () {
   18.61 +    return "[" + base + (addDom ? "+dom_id" : "") + "]";
   18.62 +  }
   18.63 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Main.java	Tue May 06 09:36:15 2003 +0000
    19.3 @@ -0,0 +1,39 @@
    19.4 +package uk.ac.cam.cl.xeno.domctl;
    19.5 +
    19.6 +public class Main 
    19.7 +{
    19.8 +  static CommandHelp help = new CommandHelp ();
    19.9 +  static CommandNew newdom = new CommandNew ();
   19.10 +  static CommandStart start = new CommandStart ();
   19.11 +  static CommandStop stop = new CommandStop ();
   19.12 +  static CommandDestroy destroy = new CommandDestroy ();
   19.13 +  static Command commands[] = { help, newdom, start, stop, destroy };
   19.14 +
   19.15 +  public static void main (String[] args)
   19.16 +  {
   19.17 +    Defaults d = new Defaults ();
   19.18 +    int ec = -1;
   19.19 +
   19.20 +    if (args.length == 0) {
   19.21 +      ec = help.doCommand (d, args);
   19.22 +    } else {
   19.23 +      String c = args[0];
   19.24 +      int i;
   19.25 +      for (i = 0; i < commands.length; i ++) {
   19.26 +	if (commands[i].getName().equals(c)) {
   19.27 +	  if (commands[i].getFlagParameter (args, '?')) {
   19.28 +	    ec = help.doHelpFor (commands[i]);
   19.29 +	  } else {
   19.30 +	    ec = commands[i].doCommand (d, args);
   19.31 +	  }
   19.32 +	  break;
   19.33 +	}
   19.34 +      }
   19.35 +      if (i == commands.length) {
   19.36 +	System.out.println ("Unknown command " + c);
   19.37 +      }
   19.38 +    }
   19.39 +
   19.40 +    System.exit (ec);
   19.41 +  }
   19.42 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/Settings.java	Tue May 06 09:36:15 2003 +0000
    20.3 @@ -0,0 +1,38 @@
    20.4 +package uk.ac.cam.cl.xeno.domctl;
    20.5 +
    20.6 +import java.util.*;
    20.7 +import java.io.*;
    20.8 +import org.xml.sax.*;
    20.9 +
   20.10 +public final class Settings
   20.11 +{
   20.12 +  public static final String DEFAULTS_FILE = System.getProperty ("DEFAULTS_FILE");
   20.13 +  public static final String DEFAULTS_PATH = System.getProperty ("DEFAULTS_PATH");
   20.14 +  public static final String LOCAL_IP = System.getProperty ("LOCAL_IP");
   20.15 +  public static final String LOCAL_MASK = System.getProperty ("LOCAL_MASK");
   20.16 +  public static final String LOCAL_GW = System.getProperty ("LOCAL_ROUTE");
   20.17 +  public static final boolean TEST = (System.getProperty ("TEST") != null);
   20.18 +
   20.19 +
   20.20 +  public static File getDefaultsFile() {
   20.21 +    StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":");
   20.22 +    File result = null;
   20.23 +    File probe;
   20.24 +
   20.25 +    while (tok.hasMoreTokens ()) {
   20.26 +      String probe_dir = tok.nextToken ();
   20.27 +      probe = new File (probe_dir, DEFAULTS_FILE);
   20.28 +      if (probe.exists ()) {
   20.29 +	result = probe;
   20.30 +	break;
   20.31 +      }
   20.32 +    }
   20.33 +
   20.34 +    if (result == null) {
   20.35 +      System.err.println ("Could not find " + DEFAULTS_FILE + " in path " + DEFAULTS_PATH);
   20.36 +      System.exit (1);
   20.37 +    }
   20.38 +
   20.39 +    return result;
   20.40 +  }
   20.41 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/StringPattern.java	Tue May 06 09:36:15 2003 +0000
    21.3 @@ -0,0 +1,59 @@
    21.4 +package uk.ac.cam.cl.xeno.domctl;
    21.5 +
    21.6 +public class StringPattern
    21.7 +{
    21.8 +  String base;
    21.9 +  int bn;
   21.10 +  boolean addDom;
   21.11 +  boolean appendDom;
   21.12 +
   21.13 +  static StringPattern parse (String t)
   21.14 +  {
   21.15 +    StringPattern result = new StringPattern ();
   21.16 +    char[] ca = t.toCharArray ();
   21.17 +    int idx = 0;
   21.18 +    int len = ca.length;
   21.19 +
   21.20 +    if (len == 0) {
   21.21 +      result.base = "";
   21.22 +      result.bn = 0;
   21.23 +      result.addDom = false;
   21.24 +    } else if (ca[len - 1] == '+') {
   21.25 +      idx = len - 2;
   21.26 +      if ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
   21.27 +	while ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
   21.28 +	  idx --;
   21.29 +	}
   21.30 +	result.base = t.substring(0, idx + 1);
   21.31 +	result.bn = Integer.parseInt (t.substring (idx + 1, len - 1));
   21.32 +	result.addDom = true;
   21.33 +      } else {
   21.34 +	result.base = t.substring(0, len - 1);
   21.35 +	result.appendDom = true;
   21.36 +      }
   21.37 +    } else {
   21.38 +      result.base = t;
   21.39 +    }
   21.40 +
   21.41 +    return result;
   21.42 +  }
   21.43 +
   21.44 +  public String resolve (int domain_id) {
   21.45 +    if (addDom) {
   21.46 +      return base + (bn + domain_id);
   21.47 +    } else if (appendDom) {
   21.48 +      return base + domain_id;
   21.49 +    } else {
   21.50 +      return base;
   21.51 +    }
   21.52 +  }
   21.53 +
   21.54 +  public String toString () {
   21.55 +    return ("[" + 
   21.56 +	    base + 
   21.57 +	    (addDom ? "+" + bn : "") + 
   21.58 +	    ((addDom || appendDom) ? "+ID" : "") + 
   21.59 +	    "]");
   21.60 +  }
   21.61 +
   21.62 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/internal/Makefile	Tue May 06 09:36:15 2003 +0000
    22.3 @@ -0,0 +1,32 @@
    22.4 +CC = gcc
    22.5 +XI_CREATE = xi_create
    22.6 +XI_START = xi_start
    22.7 +XI_STOP = xi_stop
    22.8 +XI_DESTROY = xi_destroy
    22.9 +XI_BUILD = xi_build
   22.10 +
   22.11 +all: $(XI_CREATE).o $(XI_START).o $(XI_STOP).o $(XI_DESTROY).o $(XI_BUILD).o
   22.12 +	$(CC) -o $(XI_CREATE) $(XI_CREATE).o
   22.13 +	$(CC) -o $(XI_BUILD) $(XI_BUILD).o
   22.14 +	$(CC) -o $(XI_START) $(XI_START).o
   22.15 +	$(CC) -o $(XI_STOP) $(XI_STOP).o
   22.16 +	$(CC) -o $(XI_DESTROY) $(XI_DESTROY).o
   22.17 +
   22.18 +$(XI_CREATE).o: $(XI_CREATE).c dom0_defs.h dom0_ops.h hypervisor_defs.h mem_defs.h
   22.19 +	$(CC) -c $(XI_CREATE).c 
   22.20 +
   22.21 +internal_domain_build.o: internal_domain_build.c dom0_defs.h dom0_ops.h hypervisor_defs.h mem_defs.h
   22.22 +	$(CC) -c internal_domain_build.c 
   22.23 +
   22.24 +$(XI_START).o: $(XI_START).c dom0_defs.h dom0_ops.h hypervisor_defs.h mem_defs.h
   22.25 +	$(CC) -c $(XI_START).c 
   22.26 +
   22.27 +$(XI_STOP).o: $(XI_STOP).c dom0_defs.h dom0_ops.h hypervisor_defs.h mem_defs.h
   22.28 +	$(CC) -c $(XI_STOP).c 
   22.29 +
   22.30 +$(XI_DESTROY).o: $(XI_DESTROY).c dom0_ops.h dom0_defs.h
   22.31 +	$(CC) -c $(XI_DESTROY).c 
   22.32 +
   22.33 +clean:
   22.34 +	$(RM) *.o $(XI_CREATE) $(XI_START) $(XI_STOP) $(XI_DESTROY) $(XI_BUILD)
   22.35 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tools/internal/dom0_defs.h	Tue May 06 09:36:15 2003 +0000
    23.3 @@ -0,0 +1,9 @@
    23.4 +#define PROC_XENO_ROOT  "xeno"
    23.5 +#define PROC_CMD        "dom0_cmd"
    23.6 +#define PROC_DOM_PREFIX "dom"
    23.7 +#define PROC_DOM_MEM    "mem"
    23.8 +#define PROC_DOM_DATA   "new_dom_data"
    23.9 +#define PROC_DOMAINS    "domains"
   23.10 +
   23.11 +#define MAX_PATH        256
   23.12 +
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/tools/internal/hypervisor_defs.h	Tue May 06 09:36:15 2003 +0000
    24.3 @@ -0,0 +1,36 @@
    24.4 +/******************************************************************************
    24.5 + * hypervisor_defs.h
    24.6 + * 
    24.7 + * This needs to be kept in sync with Xen's pagetable update interface!
    24.8 + * 
    24.9 + * Copyright (c) 2002-2003, Keir Fraser & Boris Dragovic 
   24.10 + */
   24.11 +
   24.12 +/* taken from include/hypervisor-ifs/hypervisor-if.h */
   24.13 +typedef struct
   24.14 +{
   24.15 +/*
   24.16 + * PGREQ_XXX: specified in least-significant bits of 'ptr' field. All requests 
   24.17 + * specify relevent PTE or PT address in 'ptr'. Normal requests specify update 
   24.18 + * value in 'value'. Extended requests specify command in least 8 bits of 
   24.19 + * 'value'.
   24.20 + */
   24.21 +    unsigned long ptr, val; /* *ptr = val */
   24.22 +} page_update_request_t;
   24.23 +
   24.24 +/* A normal page-table update request. */
   24.25 +#define PGREQ_NORMAL           0
   24.26 +#define PGREQ_MPT_UPDATE 1
   24.27 +/* An extended command. */
   24.28 +#define PGREQ_EXTENDED_COMMAND 2
   24.29 +/* Announce a new top-level page table. */
   24.30 +#define PGEXT_PIN_L1_TABLE      0
   24.31 +#define PGEXT_PIN_L2_TABLE      1
   24.32 +#define PGEXT_PIN_L3_TABLE      2
   24.33 +#define PGEXT_PIN_L4_TABLE      3
   24.34 +#define PGEXT_UNPIN_TABLE       4
   24.35 +#define PGEXT_NEW_BASEPTR       5
   24.36 +#define PGEXT_TLB_FLUSH         6
   24.37 +#define PGEXT_INVLPG            7
   24.38 +#define PGEXT_CMD_MASK        255
   24.39 +#define PGEXT_CMD_SHIFT         8
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/tools/internal/mem_defs.h	Tue May 06 09:36:15 2003 +0000
    25.3 @@ -0,0 +1,45 @@
    25.4 +/*
    25.5 + * memory related definitions needed for userspace domain builder dom0 application. these _need_ to
    25.6 + * be kept in sync with the kernel .h files they were copied over from or something horrible will
    25.7 + * happen. remmember: god kills a kitten every time you forget to keep these in sync.
    25.8 + * 
    25.9 + * KAF: Boris, these constants are all fixed by x86 hardware. So the kittens are safe for now :-)
   25.10 + * 
   25.11 + * Copyright 2002 by B Dragovic
   25.12 + */
   25.13 +
   25.14 +/* copied over from hypervisor: include/asm-i386/page.h */
   25.15 +
   25.16 +#define _PAGE_PRESENT   0x001
   25.17 +#define _PAGE_RW    0x002
   25.18 +#define _PAGE_USER  0x004
   25.19 +#define _PAGE_PWT   0x008
   25.20 +#define _PAGE_PCD   0x010
   25.21 +#define _PAGE_ACCESSED  0x020
   25.22 +#define _PAGE_DIRTY 0x040
   25.23 +#define _PAGE_PAT       0x080
   25.24 +#define _PAGE_PSE   0x080
   25.25 +#define _PAGE_GLOBAL    0x100
   25.26 +
   25.27 +
   25.28 +#define L1_PAGETABLE_SHIFT       12
   25.29 +#define L2_PAGETABLE_SHIFT       22
   25.30 + 
   25.31 +#define ENTRIES_PER_L1_PAGETABLE 1024
   25.32 +#define ENTRIES_PER_L2_PAGETABLE 1024
   25.33 + 
   25.34 +#define PAGE_SHIFT              L1_PAGETABLE_SHIFT
   25.35 +#define PAGE_SIZE               (1UL << PAGE_SHIFT)
   25.36 +#define PAGE_MASK               (~(PAGE_SIZE-1))
   25.37 +
   25.38 +typedef struct { unsigned long l1_lo; } l1_pgentry_t;
   25.39 +typedef struct { unsigned long l2_lo; } l2_pgentry_t;
   25.40 +
   25.41 +#define l1_table_offset(_a) \
   25.42 +          (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
   25.43 +#define l2_table_offset(_a) \
   25.44 +          ((_a) >> L2_PAGETABLE_SHIFT)
   25.45 +
   25.46 +/* local definitions */
   25.47 +
   25.48 +#define nr_2_page(x) (x << PAGE_SHIFT)
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/internal/xi_build.c	Tue May 06 09:36:15 2003 +0000
    26.3 @@ -0,0 +1,524 @@
    26.4 +/* 
    26.5 + * XenoDomainBuilder, copyright (c) Boris Dragovic, bd240@cl.cam.ac.uk
    26.6 + * This code is released under terms and conditions of GNU GPL :).
    26.7 + * Usage: <executable> <mem_kb> <os image> <num_vifs> 
    26.8 + */
    26.9 +
   26.10 +#include <unistd.h>
   26.11 +#include <stdio.h>
   26.12 +#include <errno.h>
   26.13 +#include <fcntl.h>
   26.14 +#include <sys/mman.h>
   26.15 +#include <sys/types.h>
   26.16 +#include <sys/stat.h>
   26.17 +#include <stdlib.h>
   26.18 +
   26.19 +#include "hypervisor_defs.h"
   26.20 +#include "dom0_ops.h"
   26.21 +#include "dom0_defs.h"
   26.22 +#include "mem_defs.h"
   26.23 +
   26.24 +#define PERR_STRING "Xeno Domain Builder"
   26.25 +
   26.26 +#define GUEST_SIG   "XenoGues"
   26.27 +#define SIG_LEN    8
   26.28 +
   26.29 +/*
   26.30 + * NB. No ring-3 access in initial guestOS pagetables. Note that we allow
   26.31 + * ring-3 privileges in the page directories, so that the guestOS may later
   26.32 + * decide to share a 4MB region with applications.
   26.33 + */
   26.34 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
   26.35 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   26.36 +
   26.37 +/* standardized error reporting function */
   26.38 +static void dberr(char *msg)
   26.39 +{
   26.40 +    printf("%s: %s\n", PERR_STRING, msg);
   26.41 +}
   26.42 +
   26.43 +/* status reporting function */
   26.44 +static void dbstatus(char * msg)
   26.45 +{
   26.46 +    printf("Domain Builder: %s\n", msg);
   26.47 +}
   26.48 +
   26.49 +
   26.50 +/* clean up domain's memory allocations */
   26.51 +static void dom_mem_cleanup(dom_mem_t * dom_mem)
   26.52 +{
   26.53 +    char mem_path[MAX_PATH];
   26.54 +    int mem_fd;
   26.55 +
   26.56 +    /* open the domain's /proc mem interface */
   26.57 +    sprintf(mem_path, "%s%s%s%s%d%s%s", "/proc/", PROC_XENO_ROOT, "/", 
   26.58 +        PROC_DOM_PREFIX, dom_mem->domain, "/", PROC_DOM_MEM);
   26.59 +
   26.60 +    mem_fd = open(mem_path, O_WRONLY);
   26.61 +    if(mem_fd < 0){
   26.62 +        perror(PERR_STRING);
   26.63 +    }
   26.64 +    
   26.65 +    if(write(mem_fd, (dom_mem_t *)dom_mem, sizeof(dom_mem_t)) < 0){
   26.66 +	dbstatus("Error unmapping domain's memory.\n");
   26.67 +    }
   26.68 +
   26.69 +    close(mem_fd);
   26.70 +}
   26.71 +
   26.72 +/* ask dom0 to export domains memory through /proc */
   26.73 +static int setup_dom_memmap(unsigned long pfn, int pages, int dom)
   26.74 +{
   26.75 +    char cmd_path[MAX_PATH];
   26.76 +    dom0_op_t dop;
   26.77 +    int cmd_fd;
   26.78 +
   26.79 +    dop.cmd = MAP_DOM_MEM;
   26.80 +    dop.u.dommem.start_pfn = pfn;
   26.81 +    dop.u.dommem.tot_pages = pages;
   26.82 +    dop.u.dommem.domain = dom;
   26.83 +
   26.84 +    /* open the /proc command interface */
   26.85 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   26.86 +    cmd_fd = open(cmd_path, O_WRONLY);
   26.87 +    if(cmd_fd < 0){
   26.88 +        perror(PERR_STRING);
   26.89 +        return -1;
   26.90 +    }
   26.91 +
   26.92 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
   26.93 +    close(cmd_fd);
   26.94 +
   26.95 +    return 0;
   26.96 +}
   26.97 +      
   26.98 +/* request the actual mapping from dom0 */
   26.99 +static unsigned long get_vaddr(unsigned int dom)
  26.100 +{
  26.101 +    char mem_path[MAX_PATH];
  26.102 +	unsigned long addr;
  26.103 +    int mem_fd;
  26.104 +
  26.105 +    /* open the domain's /proc mem interface */
  26.106 +    sprintf(mem_path, "%s%s%s%s%d%s%s", "/proc/", PROC_XENO_ROOT, "/", 
  26.107 +                    PROC_DOM_PREFIX, dom, "/", PROC_DOM_MEM);
  26.108 +
  26.109 +    mem_fd = open(mem_path, O_RDONLY);
  26.110 +    if(mem_fd < 0){
  26.111 +        perror(PERR_STRING);
  26.112 +        return 0;
  26.113 +    }
  26.114 +
  26.115 +    /* get virtual address of mapped region */
  26.116 +	read(mem_fd, &addr, sizeof(addr));
  26.117 +	
  26.118 +    close(mem_fd);
  26.119 +
  26.120 +    return addr;
  26.121 +}
  26.122 +
  26.123 +static int map_dom_mem(unsigned long pfn, int pages, int dom, 
  26.124 +    dom_mem_t * dom_mem)
  26.125 +{
  26.126 +
  26.127 +    if(setup_dom_memmap(pfn, pages, dom)){
  26.128 +        perror(PERR_STRING);
  26.129 +        return -1;
  26.130 +    }
  26.131 +
  26.132 +    dom_mem->domain = dom;
  26.133 +    dom_mem->start_pfn = pfn;
  26.134 +    dom_mem->tot_pages = pages;
  26.135 +    if((dom_mem->vaddr = get_vaddr(dom)) == 0){
  26.136 +        dberr("Error mapping dom memory.");
  26.137 +        return -1;
  26.138 +    }
  26.139 +    
  26.140 +    return 0;
  26.141 +}
  26.142 +
  26.143 +/* open kernel image and do some sanity checks */
  26.144 +static int do_kernel_chcks(char *image, long dom_size, 
  26.145 +    unsigned long * load_addr, size_t * ksize)
  26.146 +{
  26.147 +    char signature[8];
  26.148 +    char status[MAX_PATH];
  26.149 +    struct stat stat;
  26.150 +    int fd;
  26.151 +    int ret; 
  26.152 +    
  26.153 +    fd = open(image, O_RDONLY);
  26.154 +    if(fd < 0){
  26.155 +        perror(PERR_STRING);
  26.156 +        ret = -1;    
  26.157 +        goto out;
  26.158 +    }
  26.159 +
  26.160 +    if(fstat(fd, &stat) < 0){
  26.161 +        perror(PERR_STRING);
  26.162 +        ret = -1;
  26.163 +		close(fd);
  26.164 +        goto out;
  26.165 +    }
  26.166 +
  26.167 +    if(stat.st_size > (dom_size << 10)){
  26.168 +        sprintf(status, "Kernel image size %ld larger than requested "
  26.169 +            "domain size %ld\n Terminated.\n", stat.st_size, dom_size);
  26.170 +        dberr(status);
  26.171 +        ret = -1;
  26.172 +		close(fd);
  26.173 +        goto out;
  26.174 +    }
  26.175 +    
  26.176 +    read(fd, signature, SIG_LEN);
  26.177 +    if(strncmp(signature, GUEST_SIG, SIG_LEN)){
  26.178 +        dberr("Kernel image does not contain required signature. "
  26.179 +		"Terminating.\n");
  26.180 +        ret = -1;
  26.181 +		close(fd);
  26.182 +        goto out;
  26.183 +    }
  26.184 +
  26.185 +    read(fd, load_addr, sizeof(unsigned long));
  26.186 +
  26.187 +    *ksize = stat.st_size - SIG_LEN - sizeof(unsigned long);
  26.188 +
  26.189 +    ret = fd;
  26.190 +
  26.191 +out:    
  26.192 +    return ret;
  26.193 +}
  26.194 +
  26.195 +/* this is the main guestos setup function,
  26.196 + * returnes domain descriptor structure to be used when launching
  26.197 + * the domain by hypervisor to do some last minute initialization.
  26.198 + * page table initialization is done by making a list of page table
  26.199 + * requests that are handeled by the hypervisor in the ordinary
  26.200 + * manner. this way, many potentially messy things are avoided...
  26.201 + */ 
  26.202 +#define PAGE_TO_VADDR(_pfn) ((void *)(dom_mem->vaddr + ((_pfn) * PAGE_SIZE)))
  26.203 +static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, int initrd_fd,
  26.204 +    unsigned long virt_load_addr, size_t ksize, dom_mem_t *dom_mem)
  26.205 +{
  26.206 +    dom_meminfo_t *meminfo;
  26.207 +    unsigned long *page_array;
  26.208 +    page_update_request_t *pgt_updates;
  26.209 +    dom_mem_t mem_map;
  26.210 +    dom_meminfo_t *ret = NULL;
  26.211 +    int alloc_index, num_pt_pages;
  26.212 +    unsigned long l2tab;
  26.213 +    unsigned long l1tab = 0;
  26.214 +    unsigned long num_pgt_updates = 0;
  26.215 +    unsigned long count, pt_start;
  26.216 +    dom0_op_t pgupdate_req;
  26.217 +    char cmd_path[MAX_PATH];
  26.218 +    int cmd_fd;
  26.219 +
  26.220 +    meminfo     = (dom_meminfo_t *)malloc(sizeof(dom_meminfo_t));
  26.221 +    page_array  = malloc(dom_mem->tot_pages * 4);
  26.222 +    pgt_updates = (page_update_request_t *)dom_mem->vaddr;
  26.223 +    alloc_index = dom_mem->tot_pages - 1;
  26.224 +
  26.225 +    memset(meminfo, 0, sizeof(meminfo));
  26.226 +
  26.227 +    memcpy(page_array, (void *)dom_mem->vaddr, dom_mem->tot_pages * 4);
  26.228 +
  26.229 +    /* Count bottom-level PTs, rounding up. Include one PTE for shared info. */
  26.230 +    num_pt_pages = 
  26.231 +        (l1_table_offset(virt_load_addr) + dom_mem->tot_pages + 1024) / 1024;
  26.232 +
  26.233 +    /* We must also count the page directory. */
  26.234 +    num_pt_pages++;
  26.235 +
  26.236 +    /* Index of first PT page. */
  26.237 +    pt_start = dom_mem->tot_pages - num_pt_pages;
  26.238 +
  26.239 +    /* first allocate page for page dir. allocation goes backwards from the
  26.240 +     * end of the allocated physical address space.
  26.241 +     */
  26.242 +    l2tab = *(page_array + alloc_index) << PAGE_SHIFT; 
  26.243 +    memset(PAGE_TO_VADDR(alloc_index), 0, PAGE_SIZE);
  26.244 +    alloc_index--;
  26.245 +    meminfo->l2_pgt_addr = l2tab;
  26.246 +    meminfo->virt_shinfo_addr = virt_load_addr + nr_2_page(dom_mem->tot_pages);
  26.247 +
  26.248 +    /* pin down l2tab addr as page dir page - causes hypervisor to provide
  26.249 +     * correct protection for the page
  26.250 +     */ 
  26.251 +    pgt_updates->ptr = l2tab | PGREQ_EXTENDED_COMMAND;
  26.252 +    pgt_updates->val = PGEXT_PIN_L2_TABLE;
  26.253 +    pgt_updates++;
  26.254 +    num_pgt_updates++;
  26.255 +
  26.256 +    /*
  26.257 +     * Initialise the page tables. The final iteration is for the shared_info
  26.258 +     * PTE -- we break out before filling in the entry, as that is done by
  26.259 +     * Xen during final setup.
  26.260 +     */
  26.261 +    l2tab += l2_table_offset(virt_load_addr) * sizeof(l2_pgentry_t);
  26.262 +    for ( count = 0; count < (dom_mem->tot_pages + 1); count++ )
  26.263 +    {    
  26.264 +        if ( !((unsigned long)l1tab & (PAGE_SIZE-1)) ) 
  26.265 +        {
  26.266 +            l1tab = *(page_array + alloc_index) << PAGE_SHIFT;
  26.267 +            memset(PAGE_TO_VADDR(alloc_index), 0, PAGE_SIZE);
  26.268 +            alloc_index--;
  26.269 +			
  26.270 +            l1tab += l1_table_offset(virt_load_addr + nr_2_page(count)) 
  26.271 +                * sizeof(l1_pgentry_t);
  26.272 +
  26.273 +            /* make apropriate entry in the page directory */
  26.274 +            pgt_updates->ptr = l2tab;
  26.275 +            pgt_updates->val = l1tab | L2_PROT;
  26.276 +            pgt_updates++;
  26.277 +            num_pgt_updates++;
  26.278 +            l2tab += sizeof(l2_pgentry_t);
  26.279 +        }
  26.280 +
  26.281 +        /* The last PTE we consider is filled in later by Xen. */
  26.282 +        if ( count == dom_mem->tot_pages ) break;
  26.283 +		
  26.284 +        if ( count < pt_start )
  26.285 +        {
  26.286 +            pgt_updates->ptr = l1tab;
  26.287 +            pgt_updates->val = (*(page_array + count) << PAGE_SHIFT) | L1_PROT;
  26.288 +            pgt_updates++;
  26.289 +            num_pgt_updates++;
  26.290 +            l1tab += sizeof(l1_pgentry_t);
  26.291 +        }
  26.292 +        else
  26.293 +        {
  26.294 +            pgt_updates->ptr = l1tab;
  26.295 +            pgt_updates->val = 
  26.296 +		((*(page_array + count) << PAGE_SHIFT) | L1_PROT) & ~_PAGE_RW;
  26.297 +            pgt_updates++;
  26.298 +            num_pgt_updates++;
  26.299 +            l1tab += sizeof(l1_pgentry_t);
  26.300 +        }
  26.301 +
  26.302 +        pgt_updates->ptr = 
  26.303 +	    (*(page_array + count) << PAGE_SHIFT) | PGREQ_MPT_UPDATE;
  26.304 +        pgt_updates->val = count;
  26.305 +        pgt_updates++;
  26.306 +        num_pgt_updates++;
  26.307 +    }
  26.308 +
  26.309 +    meminfo->virt_startinfo_addr = virt_load_addr + nr_2_page(alloc_index - 1);
  26.310 +    meminfo->domain = dom;
  26.311 +
  26.312 +    /*
  26.313 +     * Send the page update requests down to the hypervisor.
  26.314 +     * NB. We must do this before loading the guest OS image!
  26.315 +     */
  26.316 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
  26.317 +    if ( (cmd_fd = open(cmd_path, O_WRONLY)) < 0 ) goto out;
  26.318 +    pgupdate_req.cmd = DO_PGUPDATES;
  26.319 +    pgupdate_req.u.pgupdate.pgt_update_arr  = (unsigned long)dom_mem->vaddr;
  26.320 +    pgupdate_req.u.pgupdate.num_pgt_updates = num_pgt_updates;
  26.321 +    write(cmd_fd, &pgupdate_req, sizeof(dom0_op_t));
  26.322 +    close(cmd_fd);
  26.323 +
  26.324 +    /* Load the guest OS image. */
  26.325 +    if( read(kernel_fd, (char *)dom_mem->vaddr, ksize) != ksize )
  26.326 +    {
  26.327 +        dberr("Error reading kernel image, could not"
  26.328 +              " read the whole image. Terminating.\n");
  26.329 +        goto out;
  26.330 +    }
  26.331 +
  26.332 +    if( initrd_fd )
  26.333 +      {
  26.334 +	struct stat stat;
  26.335 +	unsigned long isize;
  26.336 +
  26.337 +	if(fstat(initrd_fd, &stat) < 0){
  26.338 +	  perror(PERR_STRING);
  26.339 +	  close(initrd_fd);
  26.340 +	  goto out;
  26.341 +	}
  26.342 +	isize = stat.st_size;
  26.343 +
  26.344 +	if( read(initrd_fd, ((char *)dom_mem->vaddr)+ksize, isize) != isize )
  26.345 +	  {
  26.346 +	    dberr("Error reading initrd image, could not"
  26.347 +		  " read the whole image. Terminating.\n");
  26.348 +	    goto out;
  26.349 +	  }
  26.350 +
  26.351 +	meminfo->virt_mod_addr = virt_load_addr + ksize;
  26.352 +	meminfo->virt_mod_len  = isize;
  26.353 +
  26.354 +      }
  26.355 +
  26.356 +
  26.357 +    ret = meminfo;
  26.358 +out:
  26.359 +
  26.360 +    return ret;
  26.361 +}
  26.362 +
  26.363 +static int launch_domain(dom_meminfo_t  * meminfo)
  26.364 +{
  26.365 +    char cmd_path[MAX_PATH];
  26.366 +    dom0_op_t dop;
  26.367 +    int cmd_fd;
  26.368 +
  26.369 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
  26.370 +    cmd_fd = open(cmd_path, O_WRONLY);
  26.371 +    if(cmd_fd < 0){
  26.372 +        perror(PERR_STRING);
  26.373 +        return -1;
  26.374 +    }
  26.375 +
  26.376 +    dop.cmd = DOM0_BUILDDOMAIN;
  26.377 +    memcpy(&dop.u.meminfo, meminfo, sizeof(dom_meminfo_t));
  26.378 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
  26.379 +    close(cmd_fd);
  26.380 +
  26.381 +    return 0;
  26.382 +}
  26.383 +
  26.384 +static int get_domain_info (int domain_id,
  26.385 +                            int *pg_head,
  26.386 +                            int *tot_pages)
  26.387 +{
  26.388 +  FILE *f; 
  26.389 +  char domains_path[MAX_PATH];
  26.390 +  char domains_line[256];
  26.391 +  int rc = -1;
  26.392 +  int read_id;
  26.393 +
  26.394 +  sprintf (domains_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_DOMAINS
  26.395 +);
  26.396 +
  26.397 +  f = fopen (domains_path, "r");
  26.398 +  if (f == NULL) goto out;
  26.399 +
  26.400 +  read_id = -1;
  26.401 +  while (fgets (domains_line, 256, f) != 0)
  26.402 +    { 
  26.403 +      int trans;
  26.404 +      trans = sscanf (domains_line, "%d %*d %*d %*d %*d %*d %x %d %*s", &read_id
  26.405 +, pg_head, tot_pages);
  26.406 +      if (trans == 3) {
  26.407 +        if (read_id == domain_id) {
  26.408 +          rc = 0;
  26.409 +          break;
  26.410 +        }
  26.411 +      }
  26.412 +    }
  26.413 +
  26.414 +  if (read_id == -1) {
  26.415 +    errno = ESRCH;
  26.416 +  }
  26.417 +
  26.418 +  fclose (f);
  26.419 +
  26.420 + out:
  26.421 +  return rc;
  26.422 +}
  26.423 +
  26.424 +
  26.425 +int main(int argc, char **argv)
  26.426 +{
  26.427 +
  26.428 +    dom_mem_t dom_os_image;
  26.429 +    dom_mem_t dom_pgt; 
  26.430 +    dom_meminfo_t * meminfo;
  26.431 +    size_t ksize;
  26.432 +    unsigned long load_addr;
  26.433 +    char status[1024];
  26.434 +    int kernel_fd, initrd_fd = 0;
  26.435 +    int count;
  26.436 +    int cmd_len;
  26.437 +    int rc = -1;
  26.438 +    int args_start = 4;
  26.439 +    char initrd_name[1024];
  26.440 +    int domain_id;
  26.441 +    int pg_head;
  26.442 +    int tot_pages;
  26.443 +
  26.444 +    unsigned long addr;
  26.445 +
  26.446 +    /**** this argument parsing code is really _gross_. rewrite me! ****/
  26.447 +
  26.448 +    if(argc < 4) {
  26.449 +        dberr("Usage: dom_builder <domain_id> <image> <num_vifs> "
  26.450 +	      "[<initrd=initrd_name>] <boot_params>\n");
  26.451 +        return -1;
  26.452 +    }
  26.453 +
  26.454 +    /* Look up information about the domain */
  26.455 +    domain_id = atol(argv[1]);
  26.456 +    if (get_domain_info (domain_id, &pg_head, &tot_pages) != 0) {
  26.457 +      perror ("Could not find domain information");
  26.458 +      rc = -1;
  26.459 +      goto out;
  26.460 +    }
  26.461 +	     
  26.462 +    kernel_fd = do_kernel_chcks(argv[2], tot_pages << (PAGE_SHIFT - 10), &load_addr, &ksize);
  26.463 +    if(kernel_fd < 0)
  26.464 +	return -1;
  26.465 +    
  26.466 +
  26.467 +    /* map domain's memory */
  26.468 +    if(map_dom_mem(pg_head, tot_pages,
  26.469 +		   domain_id, &dom_os_image))
  26.470 +        goto out;
  26.471 +
  26.472 +    if( strncmp("initrd=", argv[args_start], 7) == 0 )
  26.473 +      {
  26.474 +	strncpy( initrd_name, argv[args_start]+7, sizeof(initrd_name) );
  26.475 +	initrd_name[sizeof(initrd_name)-1] = 0;
  26.476 +	printf("initrd present, name = %s\n", initrd_name );
  26.477 +	args_start++;
  26.478 +
  26.479 +	initrd_fd = open(initrd_name, O_RDONLY);
  26.480 +	if(initrd_fd < 0){
  26.481 +	  perror(PERR_STRING);
  26.482 +	  goto out;
  26.483 +	}
  26.484 +      }
  26.485 +
  26.486 +    /* the following code does the actual domain building */
  26.487 +    meminfo = setup_guestos(domain_id, kernel_fd, initrd_fd, load_addr, 
  26.488 +			    ksize, &dom_os_image); 
  26.489 +    
  26.490 +    /* and unmap the new domain's memory image since we no longer need it */
  26.491 +    dom_mem_cleanup(&dom_os_image);
  26.492 +
  26.493 +    if(!meminfo) { 
  26.494 +	printf("Domain Builder: debug: meminfo NULL\n");
  26.495 +        goto out;
  26.496 +    }
  26.497 +
  26.498 +    meminfo->virt_load_addr = load_addr;
  26.499 +    meminfo->num_vifs = atoi(argv[3]);
  26.500 +    meminfo->cmd_line[0] = '\0';
  26.501 +    cmd_len = 0;
  26.502 +    for(count = args_start; count < argc; count++){
  26.503 +        if(cmd_len + strlen(argv[count]) > MAX_CMD_LEN - 1){
  26.504 +            dberr("Size of image boot params too big!\n");
  26.505 +            break;
  26.506 +        }
  26.507 +        strcat(meminfo->cmd_line, argv[count]);
  26.508 +        strcat(meminfo->cmd_line, " ");
  26.509 +        cmd_len += strlen(argv[count] + 1);
  26.510 +    }
  26.511 +
  26.512 +    /*    sprintf(status, 
  26.513 +	    "About to launch new domain %d with folowing parameters:\n"
  26.514 +	    " * page table base: %lx \n * load address: %lx \n"
  26.515 +	    " * shared info address: %lx \n * start info address: %lx \n"
  26.516 +	    " * number of vifs: %d \n * cmd line: %s \n", meminfo->domain, 
  26.517 +	    meminfo->l2_pgt_addr, meminfo->virt_load_addr, 
  26.518 +	    meminfo->virt_shinfo_addr, meminfo->virt_startinfo_addr, 
  26.519 +	    meminfo->num_vifs, meminfo->cmd_line);
  26.520 +	    dbstatus(status);*/
  26.521 +    
  26.522 +    /* and launch the domain */
  26.523 +    rc = launch_domain(meminfo); 
  26.524 +    
  26.525 +out:
  26.526 +    return rc;
  26.527 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/tools/internal/xi_create.c	Tue May 06 09:36:15 2003 +0000
    27.3 @@ -0,0 +1,98 @@
    27.4 +/* 
    27.5 + * XenoDomainBuilder, copyright (c) Boris Dragovic, bd240@cl.cam.ac.uk
    27.6 + * This code is released under terms and conditions of GNU GPL :).
    27.7 + * Usage: <executable> <mem_kb> <os image> <num_vifs> 
    27.8 + */
    27.9 +
   27.10 +#include <unistd.h>
   27.11 +#include <stdio.h>
   27.12 +#include <errno.h>
   27.13 +#include <fcntl.h>
   27.14 +#include <sys/mman.h>
   27.15 +#include <sys/types.h>
   27.16 +#include <sys/stat.h>
   27.17 +#include <stdlib.h>
   27.18 +
   27.19 +#include "hypervisor_defs.h"
   27.20 +#include "dom0_ops.h"
   27.21 +#include "dom0_defs.h"
   27.22 +#include "mem_defs.h"
   27.23 +
   27.24 +/***********************************************************************/
   27.25 +
   27.26 +static char *argv0 = "internal_domain_create";
   27.27 +
   27.28 +static void ERROR (char *message)
   27.29 +{
   27.30 +  fprintf (stderr, "%s: %s\n", argv0, message);
   27.31 +  exit (-1);
   27.32 +}
   27.33 +
   27.34 +static void PERROR (char *message)
   27.35 +{
   27.36 +  fprintf (stderr, "%s: %s (%s)\n", argv0, message, sys_errlist[errno]);
   27.37 +  exit (-1);
   27.38 +}
   27.39 +
   27.40 +/***********************************************************************/
   27.41 +
   27.42 +static dom0_newdomain_t * create_new_domain(long req_mem, char *name)
   27.43 +{
   27.44 +    dom0_newdomain_t * dom_data;
   27.45 +    char cmd_path[MAX_PATH];
   27.46 +    char dom_id_path[MAX_PATH];
   27.47 +    dom0_op_t dop;
   27.48 +    int cmd_fd;
   27.49 +    int id_fd;
   27.50 +
   27.51 +    /* open the /proc command interface */
   27.52 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   27.53 +    cmd_fd = open(cmd_path, O_WRONLY);
   27.54 +    if(cmd_fd < 0){
   27.55 +        PERROR ("Could not open PROC_CMD interface");
   27.56 +        return 0;
   27.57 +    }
   27.58 +
   27.59 +    dop.cmd = DOM0_CREATEDOMAIN;
   27.60 +    dop.u.newdomain.memory_kb = req_mem;
   27.61 +    strncpy (dop.u.newdomain.name, name, MAX_DOMAIN_NAME - 1);
   27.62 +    dop.u.newdomain.name[MAX_DOMAIN_NAME - 1] = 0;
   27.63 +
   27.64 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
   27.65 +    close(cmd_fd);
   27.66 +
   27.67 +    sprintf(dom_id_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", 
   27.68 +        PROC_DOM_DATA);
   27.69 +    while((id_fd = open(dom_id_path, O_RDONLY)) < 0) continue;
   27.70 +    dom_data = (dom0_newdomain_t *)malloc(sizeof(dom0_newdomain_t));
   27.71 +    read(id_fd, dom_data, sizeof(dom0_newdomain_t));
   27.72 +    close(id_fd);
   27.73 +    
   27.74 +    return dom_data;
   27.75 +}    
   27.76 +
   27.77 +/***********************************************************************/
   27.78 +
   27.79 +int main(int argc, char **argv)
   27.80 +{
   27.81 +  dom0_newdomain_t * dom_data;
   27.82 +
   27.83 +  if (argv[0] != NULL) 
   27.84 +    {
   27.85 +      argv0 = argv[0];
   27.86 +    }
   27.87 +
   27.88 +  if(argc != 3) 
   27.89 +    {
   27.90 +      fprintf (stderr, "Usage: %s <kbytes-mem> <domain-name>\n", argv0);
   27.91 +      return -1;
   27.92 +    }
   27.93 +
   27.94 +  if(!(dom_data = create_new_domain(atol(argv[1]), argv[2]))) 
   27.95 +    {
   27.96 +      return -1;
   27.97 +    }
   27.98 +
   27.99 +  fprintf (stdout, "%d\n", dom_data -> domain);
  27.100 +  return 0;
  27.101 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/tools/internal/xi_destroy.c	Tue May 06 09:36:15 2003 +0000
    28.3 @@ -0,0 +1,81 @@
    28.4 +/* 
    28.5 + * A very(!) simple program to kill a domain. (c) Boris Dragovic
    28.6 + * Usage: <executable> <mem_kb> <os image> <num_vifs> 
    28.7 + */
    28.8 +
    28.9 +#include <unistd.h>
   28.10 +#include <stdio.h>
   28.11 +#include <errno.h>
   28.12 +#include <fcntl.h>
   28.13 +#include <sys/stat.h>
   28.14 +#include <sys/types.h>
   28.15 +
   28.16 +#include "dom0_ops.h"
   28.17 +#include "dom0_defs.h"
   28.18 +
   28.19 +/***********************************************************************/
   28.20 +
   28.21 +static char *argv0 = "internal_domain_stop";
   28.22 +
   28.23 +static void ERROR (char *message)
   28.24 +{
   28.25 +  fprintf (stderr, "%s: %s\n", argv0, message);
   28.26 +  exit (-1);
   28.27 +}
   28.28 +
   28.29 +static void PERROR (char *message)
   28.30 +{
   28.31 +  fprintf (stderr, "%s: %s (%s)\n", argv0, message, sys_errlist[errno]);
   28.32 +  exit (-1);
   28.33 +}
   28.34 +
   28.35 +/***********************************************************************/
   28.36 +
   28.37 +static int do_kill_domain(int dom_id, int force)
   28.38 +{
   28.39 +    char cmd_path[MAX_PATH];
   28.40 +    dom0_op_t dop;
   28.41 +    int cmd_fd;
   28.42 +
   28.43 +    dop.cmd = DOM0_DESTROYDOMAIN;
   28.44 +    dop.u.killdomain.domain = dom_id;
   28.45 +    dop.u.killdomain.force  = force;
   28.46 +
   28.47 +    /* open the /proc command interface */
   28.48 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   28.49 +    cmd_fd = open(cmd_path, O_WRONLY);
   28.50 +    if(cmd_fd < 0){
   28.51 +        PERROR ("Count not open PROC_CMD interface");
   28.52 +    }
   28.53 +
   28.54 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
   28.55 +    close(cmd_fd);
   28.56 +
   28.57 +    return 0;
   28.58 +}
   28.59 +
   28.60 +int main(int argc, char **argv)
   28.61 +{
   28.62 +  int ret;
   28.63 +
   28.64 +  if (argv[0] != NULL) 
   28.65 +    {
   28.66 +      argv0 = argv[0];
   28.67 +    }
   28.68 +
   28.69 +  if ( (argc < 2) || (argc > 3) )
   28.70 +    {
   28.71 +    usage:
   28.72 +        fprintf(stderr, "Usage: %s [-f] <domain_id>\n", argv0);
   28.73 +        fprintf(stderr, " -f: Forces immediate destruction of specified domain\n");
   28.74 +        ret = -1;
   28.75 +        goto out;
   28.76 +    }
   28.77 +
   28.78 +    if ( (argc == 3) && strcmp("-f", argv[1]) ) goto usage;
   28.79 +
   28.80 +    ret = do_kill_domain(atoi(argv[argc-1]), argc == 3);
   28.81 +
   28.82 +out:
   28.83 +    return ret;
   28.84 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/tools/internal/xi_start.c	Tue May 06 09:36:15 2003 +0000
    29.3 @@ -0,0 +1,80 @@
    29.4 +#include <unistd.h>
    29.5 +#include <stdio.h>
    29.6 +#include <errno.h>
    29.7 +#include <fcntl.h>
    29.8 +#include <sys/mman.h>
    29.9 +#include <sys/types.h>
   29.10 +#include <sys/stat.h>
   29.11 +#include <stdlib.h>
   29.12 +
   29.13 +#include "hypervisor_defs.h"
   29.14 +#include "dom0_ops.h"
   29.15 +#include "dom0_defs.h"
   29.16 +#include "mem_defs.h"
   29.17 +
   29.18 +/***********************************************************************/
   29.19 +
   29.20 +static char *argv0 = "internal_domain_start";
   29.21 +
   29.22 +static void ERROR (char *message)
   29.23 +{
   29.24 +  fprintf (stderr, "%s: %s\n", argv0, message);
   29.25 +  exit (-1);
   29.26 +}
   29.27 +
   29.28 +static void PERROR (char *message)
   29.29 +{
   29.30 +  fprintf (stderr, "%s: %s (%s)\n", argv0, message, sys_errlist[errno]);
   29.31 +  exit (-1);
   29.32 +}
   29.33 +
   29.34 +/***********************************************************************/
   29.35 +
   29.36 +static int start_domain(int id)
   29.37 +{
   29.38 +    dom0_newdomain_t * dom_data;
   29.39 +    char cmd_path[MAX_PATH];
   29.40 +    char dom_id_path[MAX_PATH];
   29.41 +    dom0_op_t dop;
   29.42 +    int cmd_fd;
   29.43 +    int id_fd;
   29.44 +
   29.45 +    /* Set up the DOM0_STARTDOMAIN command */
   29.46 +    dop.cmd = DOM0_STARTDOMAIN;
   29.47 +    dop.u.meminfo.domain = id;
   29.48 +
   29.49 +    /* open the /proc command interface */
   29.50 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   29.51 +    cmd_fd = open(cmd_path, O_WRONLY);
   29.52 +    if(cmd_fd < 0){
   29.53 +        PERROR ("Count not open PROC_CMD interface");
   29.54 +    }
   29.55 +
   29.56 +    /* Issue the command */
   29.57 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
   29.58 +    close(cmd_fd);
   29.59 +
   29.60 +    return 0;
   29.61 +}    
   29.62 +
   29.63 +/***********************************************************************/
   29.64 +
   29.65 +int main(int argc, char **argv)
   29.66 +{
   29.67 +  int rc;
   29.68 +
   29.69 +  if (argv[0] != NULL) 
   29.70 +    {
   29.71 +      argv0 = argv[0];
   29.72 +    }
   29.73 +
   29.74 +  if(argc != 2) 
   29.75 +    {
   29.76 +      fprintf (stderr, "Usage: %s <domain-id>\n", argv0);
   29.77 +      return -1;
   29.78 +    }
   29.79 +
   29.80 +  rc = start_domain(atol(argv[1]));
   29.81 +
   29.82 +  return rc;
   29.83 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/tools/internal/xi_stop.c	Tue May 06 09:36:15 2003 +0000
    30.3 @@ -0,0 +1,80 @@
    30.4 +#include <unistd.h>
    30.5 +#include <stdio.h>
    30.6 +#include <errno.h>
    30.7 +#include <fcntl.h>
    30.8 +#include <sys/mman.h>
    30.9 +#include <sys/types.h>
   30.10 +#include <sys/stat.h>
   30.11 +#include <stdlib.h>
   30.12 +
   30.13 +#include "hypervisor_defs.h"
   30.14 +#include "dom0_ops.h"
   30.15 +#include "dom0_defs.h"
   30.16 +#include "mem_defs.h"
   30.17 +
   30.18 +/***********************************************************************/
   30.19 +
   30.20 +static char *argv0 = "internal_domain_stop";
   30.21 +
   30.22 +static void ERROR (char *message)
   30.23 +{
   30.24 +  fprintf (stderr, "%s: %s\n", argv0, message);
   30.25 +  exit (-1);
   30.26 +}
   30.27 +
   30.28 +static void PERROR (char *message)
   30.29 +{
   30.30 +  fprintf (stderr, "%s: %s (%s)\n", argv0, message, sys_errlist[errno]);
   30.31 +  exit (-1);
   30.32 +}
   30.33 +
   30.34 +/***********************************************************************/
   30.35 +
   30.36 +static int stop_domain(int id)
   30.37 +{
   30.38 +    dom0_newdomain_t * dom_data;
   30.39 +    char cmd_path[MAX_PATH];
   30.40 +    char dom_id_path[MAX_PATH];
   30.41 +    dom0_op_t dop;
   30.42 +    int cmd_fd;
   30.43 +    int id_fd;
   30.44 +
   30.45 +    /* Set up the DOM0_STOPDOMAIN command */
   30.46 +    dop.cmd = DOM0_STOPDOMAIN;
   30.47 +    dop.u.meminfo.domain = id;
   30.48 +
   30.49 +    /* open the /proc command interface */
   30.50 +    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   30.51 +    cmd_fd = open(cmd_path, O_WRONLY);
   30.52 +    if(cmd_fd < 0){
   30.53 +        PERROR ("Count not open PROC_CMD interface");
   30.54 +    }
   30.55 +
   30.56 +    /* Issue the command */
   30.57 +    write(cmd_fd, &dop, sizeof(dom0_op_t));
   30.58 +    close(cmd_fd);
   30.59 +
   30.60 +    return 0;
   30.61 +}    
   30.62 +
   30.63 +/***********************************************************************/
   30.64 +
   30.65 +int main(int argc, char **argv)
   30.66 +{
   30.67 +  int rc;
   30.68 +
   30.69 +  if (argv[0] != NULL) 
   30.70 +    {
   30.71 +      argv0 = argv[0];
   30.72 +    }
   30.73 +
   30.74 +  if(argc != 2) 
   30.75 +    {
   30.76 +      fprintf (stderr, "Usage: %s <domain-id>\n", argv0);
   30.77 +      return -1;
   30.78 +    }
   30.79 +
   30.80 +  rc = stop_domain(atol(argv[1]));
   30.81 +
   30.82 +  return rc;
   30.83 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/tools/internal/xi_vifinit	Tue May 06 09:36:15 2003 +0000
    31.3 @@ -0,0 +1,25 @@
    31.4 +#!/bin/bash
    31.5 +#
    31.6 +# vifinit 
    31.7 +#
    31.8 +# This is a silly little script to dump a couple of simple rules down to 
    31.9 +# the hypervisor to assign a full static IP to a given virtual interface.
   31.10 +# 
   31.11 +# Usage is:
   31.12 +#
   31.13 +#   vifinit [vif dom] [vif idx] [dotted decimal ip address]
   31.14 +#
   31.15 +if [ $# -ne 3 ] ; 
   31.16 +then
   31.17 +        echo "usage: $0 <domain_id> <vid_ifx> <dotted_decimal_ip_address>"
   31.18 +        exit
   31.19 +fi
   31.20 +
   31.21 +#outbound rule:
   31.22 +echo "ADD ACCEPT srcaddr=$3 srcaddrmask=255.255.255.255 srcdom=$1 srcidx=$2 dst=PHYS proto=any" > /proc/vfr
   31.23 +
   31.24 +#inbound rule:
   31.25 +echo "ADD ACCEPT dstaddr=$3 dstaddrmask=255.255.255.255 src=ANY dstdom=$1 dstidx=$2 proto=any" > /proc/vfr
   31.26 +
   31.27 +#----] done.
   31.28 +
    32.1 --- a/xen/common/dom0_ops.c	Sat May 03 13:47:58 2003 +0000
    32.2 +++ b/xen/common/dom0_ops.c	Tue May 06 09:36:15 2003 +0000
    32.3 @@ -62,11 +62,19 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    32.4      switch ( op.cmd )
    32.5      {
    32.6  
    32.7 -    case DOM0_STARTDOM:
    32.8 +    case DOM0_BUILDDOMAIN:
    32.9      {
   32.10          struct task_struct * p = find_domain_by_id(op.u.meminfo.domain);
   32.11          if ( (ret = final_setup_guestos(p, &op.u.meminfo)) != 0 )
   32.12              break;
   32.13 +        ret = p->domain;
   32.14 +        free_task_struct(p);
   32.15 +    }
   32.16 +    break;
   32.17 +
   32.18 +    case DOM0_STARTDOMAIN:
   32.19 +    {
   32.20 +        struct task_struct * p = find_domain_by_id(op.u.meminfo.domain);
   32.21          wake_up(p);
   32.22          reschedule(p);
   32.23          ret = p->domain;
   32.24 @@ -74,7 +82,13 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   32.25      }
   32.26      break;
   32.27  
   32.28 -    case DOM0_NEWDOMAIN:
   32.29 +    case DOM0_STOPDOMAIN:
   32.30 +    {
   32.31 +      ret = stop_other_domain (op.u.meminfo.domain);
   32.32 +    }
   32.33 +    break;
   32.34 +
   32.35 +    case DOM0_CREATEDOMAIN:
   32.36      {
   32.37          struct task_struct *p;
   32.38          static unsigned int pro = 0;
   32.39 @@ -89,6 +103,11 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   32.40          if ( p == NULL ) 
   32.41              break;
   32.42  
   32.43 +	if (op.u.newdomain.name[0]) {
   32.44 +	  strncpy (p -> name, op.u.newdomain.name, MAX_DOMAIN_NAME);
   32.45 +	  p -> name[MAX_DOMAIN_NAME - 1] = 0;
   32.46 +	}
   32.47 +
   32.48          ret = alloc_new_dom_mem(p, op.u.newdomain.memory_kb);
   32.49          if ( ret != 0 ) 
   32.50          {
   32.51 @@ -108,7 +127,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   32.52      }
   32.53      break;
   32.54  
   32.55 -    case DOM0_KILLDOMAIN:
   32.56 +    case DOM0_DESTROYDOMAIN:
   32.57      {
   32.58          unsigned int dom = op.u.killdomain.domain;
   32.59          int force = op.u.killdomain.force;
   32.60 @@ -168,6 +187,38 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
   32.61      }
   32.62      break;
   32.63  
   32.64 +    case DOM0_GETDOMAININFO:
   32.65 +    { 
   32.66 +      struct task_struct *p;
   32.67 +      u_long flags;
   32.68 +
   32.69 +      p = idle0_task.next_task;
   32.70 +      read_lock_irqsave (&tasklist_lock, flags);
   32.71 +      do {
   32.72 +        if ((!is_idle_task (p)) && (p -> domain >= op.u.getdominfo.domain)) {
   32.73 +          break;
   32.74 +        }
   32.75 +      } while ((p = p -> next_task) != &idle0_task);
   32.76 +
   32.77 +      if (p == &idle0_task) {
   32.78 +        ret = -ESRCH;
   32.79 +      } else {
   32.80 +        op.u.getdominfo.domain = p -> domain;
   32.81 +        strcpy (op.u.getdominfo.name, p -> name);
   32.82 +        op.u.getdominfo.processor = p -> processor;
   32.83 +        op.u.getdominfo.has_cpu = p -> has_cpu;
   32.84 +        op.u.getdominfo.state = p -> state;
   32.85 +        op.u.getdominfo.hyp_events = p -> hyp_events;
   32.86 +        op.u.getdominfo.mcu_advance = p -> mcu_advance;
   32.87 +        op.u.getdominfo.pg_head = list_entry(p->pg_head.next,
   32.88 +                                             struct pfn_info, list) - frame_table;
   32.89 +        op.u.getdominfo.tot_pages = p -> tot_pages;
   32.90 +      }
   32.91 +      read_unlock_irqrestore (&tasklist_lock, flags);
   32.92 +      copy_to_user(u_dom0_op, &op, sizeof(op));
   32.93 +      break;
   32.94 +    }
   32.95 +
   32.96      default:
   32.97          ret = -ENOSYS;
   32.98  
    33.1 --- a/xen/common/domain.c	Sat May 03 13:47:58 2003 +0000
    33.2 +++ b/xen/common/domain.c	Tue May 06 09:36:15 2003 +0000
    33.3 @@ -175,6 +175,29 @@ long kill_other_domain(unsigned int dom,
    33.4      return 0;
    33.5  }
    33.6  
    33.7 +void stop_domain(void)
    33.8 +{
    33.9 +  current -> state = TASK_SUSPENDED;
   33.10 +  clear_bit(_HYP_EVENT_STOP, &(current->hyp_events));
   33.11 +  schedule ();
   33.12 +}
   33.13 +
   33.14 +long stop_other_domain(unsigned int dom)
   33.15 +{
   33.16 +  unsigned long cpu_mask;
   33.17 +  struct task_struct *p;
   33.18 +
   33.19 +  p = find_domain_by_id (dom);
   33.20 +  if ( p == NULL) return -ESRCH;
   33.21 +
   33.22 +  if ( p -> state != TASK_SUSPENDED )
   33.23 +    {
   33.24 +      cpu_mask = mark_hyp_event(p, _HYP_EVENT_STOP);
   33.25 +      hyp_event_notify(cpu_mask);
   33.26 +    }
   33.27 +
   33.28 +  return 0;
   33.29 +}
   33.30  
   33.31  unsigned int alloc_new_dom_mem(struct task_struct *p, unsigned int kbytes)
   33.32  {
    34.1 --- a/xen/common/schedule.c	Sat May 03 13:47:58 2003 +0000
    34.2 +++ b/xen/common/schedule.c	Tue May 06 09:36:15 2003 +0000
    34.3 @@ -349,6 +349,7 @@ asmlinkage void schedule(void)
    34.4      case TASK_UNINTERRUPTIBLE:
    34.5      case TASK_WAIT:
    34.6      case TASK_DYING:
    34.7 +    case TASK_SUSPENDED:
    34.8      default:
    34.9          /* done if not running. Else, continue */
   34.10          goto deschedule_done;
    35.1 --- a/xen/include/xeno/dom0_ops.h	Sat May 03 13:47:58 2003 +0000
    35.2 +++ b/xen/include/xeno/dom0_ops.h	Tue May 06 09:36:15 2003 +0000
    35.3 @@ -12,14 +12,18 @@
    35.4  #ifndef __DOM0_OPS_H__
    35.5  #define __DOM0_OPS_H__
    35.6  
    35.7 -#define DOM0_NEWDOMAIN   0
    35.8 -#define DOM0_KILLDOMAIN  1
    35.9 -#define DOM0_GETMEMLIST  2
   35.10 -#define DOM0_STARTDOM    4
   35.11 -#define DOM0_BVTCTL      6
   35.12 -#define DOM0_ADJUSTDOM   7
   35.13 +#define DOM0_GETMEMLIST     2
   35.14 +#define DOM0_BVTCTL         6
   35.15 +#define DOM0_ADJUSTDOM      7
   35.16 +#define DOM0_CREATEDOMAIN   8
   35.17 +#define DOM0_DESTROYDOMAIN  9
   35.18 +#define DOM0_STARTDOMAIN   10
   35.19 +#define DOM0_STOPDOMAIN    11
   35.20 +#define DOM0_GETDOMAININFO 12
   35.21 +#define DOM0_BUILDDOMAIN   13
   35.22  
   35.23  #define MAX_CMD_LEN    256
   35.24 +#define MAX_DOMAIN_NAME 16
   35.25  
   35.26  typedef struct dom0_newdomain_st 
   35.27  {
   35.28 @@ -27,6 +31,7 @@ typedef struct dom0_newdomain_st
   35.29      unsigned int memory_kb; 
   35.30      unsigned int num_vifs;  // temporary
   35.31      unsigned long pg_head;  // return parameter
   35.32 +    char name[MAX_DOMAIN_NAME];
   35.33  } dom0_newdomain_t;
   35.34  
   35.35  typedef struct dom0_killdomain_st
   35.36 @@ -69,6 +74,20 @@ typedef struct dom0_adjustdom_st
   35.37  	unsigned long warpu;    /* unwarp time requirement */
   35.38  } dom0_adjustdom_t;
   35.39  
   35.40 +typedef struct dom0_getdominfo_st
   35.41 +{
   35.42 +  unsigned int domain;          /* All returns except domain */
   35.43 +  char name[MAX_DOMAIN_NAME];
   35.44 +  int processor;
   35.45 +  int has_cpu;
   35.46 +  int state;
   35.47 +  int hyp_events;
   35.48 +  unsigned long mcu_advance;
   35.49 +  unsigned long pg_head;
   35.50 +  unsigned int tot_pages;
   35.51 +} dom0_getdominfo_t;
   35.52 +
   35.53 +
   35.54  typedef struct dom0_op_st
   35.55  {
   35.56      unsigned long cmd;
   35.57 @@ -80,7 +99,8 @@ typedef struct dom0_op_st
   35.58  		dom0_bvtctl_t bvtctl;
   35.59  		dom0_adjustdom_t adjustdom;
   35.60          dom_meminfo_t meminfo;
   35.61 -    }
   35.62 +        dom0_getdominfo_t getdominfo;
   35.63 +   }
   35.64      u;
   35.65  } dom0_op_t;
   35.66  
    36.1 --- a/xen/include/xeno/sched.h	Sat May 03 13:47:58 2003 +0000
    36.2 +++ b/xen/include/xeno/sched.h	Tue May 06 09:36:15 2003 +0000
    36.3 @@ -16,6 +16,8 @@
    36.4  #include <xeno/time.h>
    36.5  #include <xeno/ac_timer.h>
    36.6  
    36.7 +#define MAX_DOMAIN_NAME 16
    36.8 +
    36.9  extern unsigned long volatile jiffies;
   36.10  extern rwlock_t tasklist_lock;
   36.11  
   36.12 @@ -51,6 +53,7 @@ extern struct mm_struct init_mm;
   36.13  
   36.14  #define _HYP_EVENT_NEED_RESCHED 0
   36.15  #define _HYP_EVENT_DIE          1
   36.16 +#define _HYP_EVENT_STOP         2
   36.17  
   36.18  #define PF_DONEFPUINIT  0x1  /* Has the FPU been initialised for this task? */
   36.19  #define PF_USEDFPU      0x2  /* Has this task used the FPU since last save? */
   36.20 @@ -141,6 +144,8 @@ struct task_struct
   36.21                                         0-0xFFFFFFFF for kernel-thread
   36.22                                       */
   36.23  
   36.24 +    char name[MAX_DOMAIN_NAME];
   36.25 +
   36.26      /*
   36.27       * active_mm stays for now. It's entangled in the tricky TLB flushing
   36.28       * stuff which I haven't addressed yet. It stays until I'm man enough
   36.29 @@ -223,6 +228,8 @@ extern void __kill_domain(struct task_st
   36.30  extern void kill_domain(void);
   36.31  extern void kill_domain_with_errmsg(const char *err);
   36.32  extern long kill_other_domain(unsigned int dom, int force);
   36.33 +extern void stop_domain(void);
   36.34 +extern long stop_other_domain(unsigned int dom);
   36.35  
   36.36  /* arch/process.c */
   36.37  void new_thread(struct task_struct *p,
    37.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Sat May 03 13:47:58 2003 +0000
    37.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Tue May 06 09:36:15 2003 +0000
    37.3 @@ -23,6 +23,7 @@
    37.4  #include <linux/iobuf.h>
    37.5  #include <linux/highmem.h>
    37.6  #include <linux/pagemap.h>
    37.7 +#include <linux/seq_file.h>
    37.8  
    37.9  #include <asm/pgalloc.h>
   37.10  #include <asm/pgtable.h>
   37.11 @@ -31,6 +32,9 @@
   37.12  
   37.13  #include "dom0_ops.h"
   37.14  
   37.15 +#define TRUE  1
   37.16 +#define FALSE 0
   37.17 +
   37.18  /* Private proc-file data structures. */
   37.19  typedef struct proc_data {
   37.20      unsigned int domain;
   37.21 @@ -45,6 +49,7 @@ typedef struct proc_mem_data {
   37.22  #define XENO_BASE       "xeno"
   37.23  #define DOM0_CMD_INTF   "dom0_cmd"
   37.24  #define DOM0_NEWDOM     "new_dom_data"
   37.25 +#define DOM_LIST_INTF   "domains"
   37.26  
   37.27  #define MAX_LEN         16
   37.28  #define DOM_DIR         "dom"
   37.29 @@ -56,6 +61,7 @@ typedef struct proc_mem_data {
   37.30  struct proc_dir_entry *xeno_base;
   37.31  static struct proc_dir_entry *dom0_cmd_intf;
   37.32  static struct proc_dir_entry *proc_ft;
   37.33 +static struct proc_dir_entry *dom_list_intf;
   37.34  
   37.35  unsigned long direct_mmap(unsigned long, unsigned long, pgprot_t, int, int);
   37.36  int direct_unmap(unsigned long, unsigned long);
   37.37 @@ -266,7 +272,7 @@ static int cmd_write_proc(struct file *f
   37.38          ret = HYPERVISOR_dom0_op(&op);
   37.39  
   37.40          /* if new domain created, create proc entries */
   37.41 -        if(op.cmd == DOM0_NEWDOMAIN){
   37.42 +        if(op.cmd == DOM0_CREATEDOMAIN) {
   37.43              create_proc_dom_entries(ret);
   37.44  
   37.45              params = (dom0_newdomain_t *)kmalloc(sizeof(dom0_newdomain_t),
   37.46 @@ -295,6 +301,94 @@ out:
   37.47      
   37.48  }
   37.49  
   37.50 +/***********************************************************************
   37.51 + *
   37.52 + * Implementation of /proc/xeno/domains
   37.53 + */
   37.54 +
   37.55 +static dom0_op_t proc_domains_op;
   37.56 +static int proc_domains_finished;
   37.57 +static rwlock_t proc_xeno_domains_lock = RW_LOCK_UNLOCKED;
   37.58 +
   37.59 +static void *xeno_domains_next(struct seq_file *s, void *v, loff_t *pos)
   37.60 +{
   37.61 +  int ret;
   37.62 +
   37.63 +  if (pos != NULL) { ++ (*pos); }
   37.64 +  if (!proc_domains_finished) {
   37.65 +    proc_domains_op.u.getdominfo.domain ++;
   37.66 +    ret = HYPERVISOR_dom0_op(&proc_domains_op);
   37.67 +    if (ret < 0) proc_domains_finished = TRUE;
   37.68 +  }
   37.69 +  
   37.70 +  return (proc_domains_finished) ? NULL : &proc_domains_op;
   37.71 +}
   37.72 +
   37.73 +static void *xeno_domains_start(struct seq_file *s, loff_t *ppos)
   37.74 +{ 
   37.75 +  loff_t pos = *ppos;
   37.76 +  
   37.77 +  write_lock (&proc_xeno_domains_lock);
   37.78 +  proc_domains_op.cmd = DOM0_GETDOMAININFO;
   37.79 +  proc_domains_op.u.getdominfo.domain = 0;
   37.80 +  (void)HYPERVISOR_dom0_op(&proc_domains_op);
   37.81 +  proc_domains_finished = FALSE;
   37.82 +  
   37.83 +  while (pos > 0) {
   37.84 +    pos --;
   37.85 +    xeno_domains_next (s, NULL, NULL);
   37.86 +  }
   37.87 +  
   37.88 +  return (proc_domains_finished) ? NULL : &proc_domains_op;
   37.89 +}
   37.90 +
   37.91 +static void xeno_domains_stop(struct seq_file *s, void *v)
   37.92 +{ 
   37.93 +  write_unlock (&proc_xeno_domains_lock);
   37.94 +}
   37.95 +
   37.96 +static int xeno_domains_show(struct seq_file *s, void *v)
   37.97 +{ 
   37.98 +  dom0_op_t *di = v;
   37.99 +  
  37.100 +  seq_printf (s, 
  37.101 +              "%8d %2d %1d %2d %8d %8ld %p %8d %s\n",
  37.102 +              di -> u.getdominfo.domain, 
  37.103 +              di -> u.getdominfo.processor,
  37.104 +              di -> u.getdominfo.has_cpu,
  37.105 +              di -> u.getdominfo.state,
  37.106 +              di -> u.getdominfo.hyp_events,
  37.107 +              di -> u.getdominfo.mcu_advance,
  37.108 +              di -> u.getdominfo.pg_head,
  37.109 +              di -> u.getdominfo.tot_pages,
  37.110 +              di -> u.getdominfo.name);
  37.111 +
  37.112 +  return 0;
  37.113 +}
  37.114 +
  37.115 +struct seq_operations xeno_domains_op = {
  37.116 +        .start          = xeno_domains_start,
  37.117 +        .next           = xeno_domains_next,
  37.118 +        .stop           = xeno_domains_stop,
  37.119 +        .show           = xeno_domains_show,
  37.120 +};
  37.121 +
  37.122 +static int xeno_domains_open(struct inode *inode, struct file *file)
  37.123 +{
  37.124 +        return seq_open(file, &xeno_domains_op);
  37.125 +}
  37.126 +
  37.127 +static struct file_operations proc_xeno_domains_operations = {
  37.128 +        open:           xeno_domains_open,
  37.129 +        read:           seq_read,
  37.130 +        llseek:         seq_lseek,
  37.131 +        release:        seq_release,
  37.132 +};
  37.133 +
  37.134 +/***********************************************************************/
  37.135 +
  37.136 +
  37.137 +
  37.138  static int __init init_module(void)
  37.139  {
  37.140      /* xeno proc root setup */
  37.141 @@ -311,6 +405,15 @@ static int __init init_module(void)
  37.142          dom0_cmd_intf->write_proc = cmd_write_proc;
  37.143      }
  37.144  
  37.145 +    /* domain list interface */
  37.146 +    dom_list_intf = create_proc_entry (DOM_LIST_INTF, 0400, xeno_base);
  37.147 +    if ( dom_list_intf != NULL )
  37.148 +      {
  37.149 +        dom_list_intf -> owner = THIS_MODULE;
  37.150 +        dom_list_intf -> nlink = 1;
  37.151 +        dom_list_intf -> proc_fops = &proc_xeno_domains_operations;
  37.152 +      }
  37.153 +
  37.154      /* set up /proc entries for dom 0 */
  37.155      create_proc_dom_entries(0);
  37.156  
    38.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h	Sat May 03 13:47:58 2003 +0000
    38.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_ops.h	Tue May 06 09:36:15 2003 +0000
    38.3 @@ -9,17 +9,21 @@
    38.4   * MUST BE KEPT IN SYNC WITH tools/domain_builder/dom0_ops.h
    38.5   */
    38.6  
    38.7 -#define DOM0_NEWDOMAIN   0
    38.8 -#define DOM0_KILLDOMAIN  1
    38.9 -#define DOM0_GETMEMLIST  2
   38.10 -#define DOM0_STARTDOM    4
   38.11 -#define DOM0_BVTCTL      6
   38.12 -#define DOM0_ADJUSTDOM   7
   38.13 -#define MAP_DOM_MEM      8 /* Not passed down to Xen */
   38.14 -#define DO_PGUPDATES     9 /* Not passed down to Xen */
   38.15 -#define MAX_CMD         10
   38.16 +#define DOM0_GETMEMLIST     2
   38.17 +#define DOM0_BVTCTL         6
   38.18 +#define DOM0_ADJUSTDOM      7
   38.19 +#define DOM0_CREATEDOMAIN   8
   38.20 +#define DOM0_DESTROYDOMAIN  9
   38.21 +#define DOM0_STARTDOMAIN   10
   38.22 +#define DOM0_STOPDOMAIN    11
   38.23 +#define DOM0_GETDOMAININFO 12
   38.24 +#define DOM0_BUILDDOMAIN   13
   38.25 +#define MAP_DOM_MEM        14 /* Not passed down to Xen */
   38.26 +#define DO_PGUPDATES       15 /* Not passed down to Xen */
   38.27 +#define MAX_CMD            16
   38.28  
   38.29  #define MAX_CMD_LEN     256
   38.30 +#define MAX_DOMAIN_NAME 16
   38.31  
   38.32  typedef struct dom0_newdomain_st
   38.33  {
   38.34 @@ -27,6 +31,7 @@ typedef struct dom0_newdomain_st
   38.35      unsigned int memory_kb;
   38.36      unsigned int num_vifs;  /* temporary */
   38.37      unsigned long pg_head;  /* return parameter */
   38.38 +    char name[MAX_DOMAIN_NAME];
   38.39  } dom0_newdomain_t;
   38.40  
   38.41  typedef struct dom0_killdomain_st
   38.42 @@ -86,6 +91,19 @@ typedef struct domain_launch
   38.43  } dom_meminfo_t;
   38.44  
   38.45  
   38.46 +typedef struct dom0_getdominfo_st
   38.47 +{
   38.48 +  unsigned int domain;          /* All returns except domain */
   38.49 +  char name[MAX_DOMAIN_NAME];
   38.50 +  int processor;
   38.51 +  int has_cpu;
   38.52 +  int state;
   38.53 +  int hyp_events;
   38.54 +  unsigned long mcu_advance;
   38.55 +  unsigned long pg_head;
   38.56 +  unsigned int tot_pages;
   38.57 +} dom0_getdominfo_t;
   38.58 +
   38.59  
   38.60  typedef struct dom0_op_st
   38.61  {
   38.62 @@ -100,7 +118,8 @@ typedef struct dom0_op_st
   38.63          dom_mem_t dommem;
   38.64          dom_pgupdate_t pgupdate;
   38.65          dom_meminfo_t meminfo;
   38.66 -    }
   38.67 +        dom0_getdominfo_t getdominfo;
   38.68 +   }
   38.69      u;
   38.70  } dom0_op_t;
   38.71