ia64/xen-unstable

changeset 443:67bf82322cc1

bitkeeper revision 1.224 (3ebe2eafd96cvR2TVTUptkPgSEFFkQ)

CommandNew.java:
Allow .gz initrd and image, decompressed to /tmp and deleted after building the domain
author tlh20@labyrinth.cl.cam.ac.uk
date Sun May 11 11:06:23 2003 +0000 (2003-05-11)
parents 3b7be708d378
children 5c7227b5427c
files BitKeeper/etc/logging_ok tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java
line diff
     1.1 --- a/BitKeeper/etc/logging_ok	Fri May 09 08:48:32 2003 +0000
     1.2 +++ b/BitKeeper/etc/logging_ok	Sun May 11 11:06:23 2003 +0000
     1.3 @@ -20,3 +20,4 @@ rn@wyvis.research.intel-research.net
     1.4  smh22@boulderdash.cl.cam.ac.uk
     1.5  smh22@uridium.cl.cam.ac.uk
     1.6  tlh20@elite.cl.cam.ac.uk
     1.7 +tlh20@labyrinth.cl.cam.ac.uk
     2.1 --- a/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java	Fri May 09 08:48:32 2003 +0000
     2.2 +++ b/tools/domctl/src/uk/ac/cam/cl/xeno/domctl/CommandNew.java	Sun May 11 11:06:23 2003 +0000
     2.3 @@ -1,6 +1,7 @@
     2.4  package uk.ac.cam.cl.xeno.domctl;
     2.5  
     2.6  import java.io.*;
     2.7 +import java.util.zip.*;
     2.8  import java.net.*;
     2.9  
    2.10  public class CommandNew extends Command
    2.11 @@ -27,129 +28,147 @@ public class CommandNew extends Command
    2.12      DataInputStream dis;
    2.13      int idx;
    2.14      int i;
    2.15 +    File image_tmp = null;
    2.16 +    File initrd_tmp = null;
    2.17  
    2.18      d.describe ();
    2.19  
    2.20      try
    2.21        {
    2.22 -	/* Some initial sanity checks */
    2.23 -	if (root_dev.equals ("/dev/nfs") && (vifs == 0)) {
    2.24 -	  return reportError ("Cannot use NFS root without VIFs configured");
    2.25 -	}
    2.26 -
    2.27 -	/* Create a new empty domain */
    2.28 -	Process create_p;
    2.29 -	String create_cmdarray[] = new String[3];
    2.30 -	int create_rc;
    2.31 -	create_cmdarray[0] = d.XIToolsDir + "xi_create";
    2.32 -	create_cmdarray[1] = "" + size;
    2.33 -	create_cmdarray[2] = name;
    2.34 -	if (Settings.TEST) {
    2.35 -	  reportCommand (create_cmdarray);
    2.36 -	  domain_id=1;
    2.37 -	  create_rc=0;
    2.38 -	} else {
    2.39 -	  create_p = r.exec (create_cmdarray);
    2.40 -	  dis = new DataInputStream (new BufferedInputStream (create_p.getInputStream ()));
    2.41 -	  domain_id = Integer.parseInt (dis.readLine ());
    2.42 -	  create_rc = create_p.waitFor ();
    2.43 -	}
    2.44 -
    2.45 -	if (create_rc != 0) {
    2.46 -	  return reportXIError ("Failed to create domain", create_cmdarray);
    2.47 -	} else if (domain_id > d.MaxDomainNumber) {
    2.48 -	  return reportError ("Cannot configure more than " + 
    2.49 -			      d.MaxDomainNumber + " domains");
    2.50 -	}
    2.51 -
    2.52 -	/* Set up boot parameters to pass to xi_build. */
    2.53 -	if (root_dev.equals ("/dev/nfs")) {
    2.54 -	  if (vifs == 0) {
    2.55 -	    return reportError ("Cannot use NFS root without VIFs configured");
    2.56 -	  }
    2.57 -	  if (nfs_root_path == null) {
    2.58 -	    return reportError ("No NFS root specified");
    2.59 -	  }
    2.60 -	  if (nw_nfs_server == null) {
    2.61 -	    return reportError ("No NFS server specified");
    2.62 -	  }
    2.63 -	  bargs = (bargs + 
    2.64 -		   "root=/dev/nfs " +
    2.65 -		   "nfsroot=" + StringPattern.parse(nfs_root_path).resolve(domain_id) +
    2.66 -		   " ");
    2.67 -	} else {
    2.68 -	  bargs = (bargs + 
    2.69 -		   "root=" + StringPattern.parse(root_dev).resolve(domain_id) +
    2.70 -		   " ");
    2.71 -
    2.72 -	}
    2.73 -	
    2.74 -	if (vifs > 0) {
    2.75 -	  domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
    2.76 -	  if (nw_host == null) {
    2.77 -	    try {
    2.78 -	      nw_host = InetAddress.getByName(domain_ip).getHostName();
    2.79 -	    } catch (UnknownHostException uhe) {
    2.80 -	      nw_host = "" + nw_ip;
    2.81 +	try
    2.82 +	  {
    2.83 +	    /* Some initial sanity checks */
    2.84 +	    if (root_dev.equals ("/dev/nfs") && (vifs == 0)) {
    2.85 +	      return reportError ("Cannot use NFS root without VIFs configured");
    2.86  	    }
    2.87  	    
    2.88 +	    /* Uncompress the image and initrd */
    2.89 +	    if (image.endsWith (".gz")) {
    2.90 +	      image_tmp = getUncompressed ("xen-image-", image);
    2.91 +	      image = image_tmp.getPath ();
    2.92 +	    }
    2.93 +	    
    2.94 +	    if (initrd != null && initrd.endsWith (".gz")) {
    2.95 +	      initrd_tmp = getUncompressed ("xen-initrd-", initrd);
    2.96 +	      initrd = initrd_tmp.getPath ();
    2.97 +	    }
    2.98 +	    
    2.99 +	    /* Create a new empty domain */
   2.100 +	    Process create_p;
   2.101 +	    String create_cmdarray[] = new String[3];
   2.102 +	    int create_rc;
   2.103 +	    create_cmdarray[0] = d.XIToolsDir + "xi_create";
   2.104 +	    create_cmdarray[1] = "" + size;
   2.105 +	    create_cmdarray[2] = name;
   2.106 +	    if (Settings.TEST) {
   2.107 +	      reportCommand (create_cmdarray);
   2.108 +	      domain_id=1;
   2.109 +	      create_rc=0;
   2.110 +	    } else {
   2.111 +	      create_p = r.exec (create_cmdarray);
   2.112 +	      dis = new DataInputStream (new BufferedInputStream (create_p.getInputStream ()));
   2.113 +	      domain_id = Integer.parseInt (dis.readLine ());
   2.114 +	      create_rc = create_p.waitFor ();
   2.115 +	    }
   2.116 +	    
   2.117 +	    if (create_rc != 0) {
   2.118 +	      return reportXIError ("Failed to create domain", create_cmdarray);
   2.119 +	    } else if (domain_id > d.MaxDomainNumber) {
   2.120 +	      return reportError ("Cannot configure more than " + 
   2.121 +				  d.MaxDomainNumber + " domains");
   2.122 +	    }
   2.123 +	    
   2.124 +	    /* Set up boot parameters to pass to xi_build. */
   2.125 +	    if (root_dev.equals ("/dev/nfs")) {
   2.126 +	      if (vifs == 0) {
   2.127 +		return reportError ("Cannot use NFS root without VIFs configured");
   2.128 +	      }
   2.129 +	      if (nfs_root_path == null) {
   2.130 +		return reportError ("No NFS root specified");
   2.131 +	      }
   2.132 +	      if (nw_nfs_server == null) {
   2.133 +		return reportError ("No NFS server specified");
   2.134 +	      }
   2.135 +	      bargs = (bargs + 
   2.136 +		       "root=/dev/nfs " +
   2.137 +		       "nfsroot=" + StringPattern.parse(nfs_root_path).resolve(domain_id) +
   2.138 +		       " ");
   2.139 +	    } else {
   2.140 +	      bargs = (bargs + 
   2.141 +		       "root=" + StringPattern.parse(root_dev).resolve(domain_id) +
   2.142 +		       " ");
   2.143 +	      
   2.144 +	    }
   2.145 +	    
   2.146 +	    if (vifs > 0) {
   2.147 +	      domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
   2.148 +	      if (nw_host == null) {
   2.149 +		try {
   2.150 +		  nw_host = InetAddress.getByName(domain_ip).getHostName();
   2.151 +		} catch (UnknownHostException uhe) {
   2.152 +		  nw_host = "" + nw_ip;
   2.153 +		}
   2.154 +		
   2.155 +	      }
   2.156 +	      bargs = ("ip=" + domain_ip +
   2.157 +		       ":" + ((nw_nfs_server == null) ? "" : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id))) +
   2.158 +		       ":" + ((nw_gw == null) ? "" : (InetAddressPattern.parse(nw_gw).resolve(domain_id))) + 
   2.159 +		       ":" + ((nw_mask == null) ? "" : InetAddressPattern.parse(nw_mask).resolve(domain_id)) +
   2.160 +		       ":" + ((nw_host == null) ? "" : nw_host) + 
   2.161 +		       ":eth0:off " + bargs);
   2.162 +	    }
   2.163 +	    
   2.164 +	    /* Build the domain */
   2.165 +	    Process build_p;
   2.166 +	    String build_cmdarray[] = new String[6];
   2.167 +	    int build_rc;
   2.168 +	    idx = 0;
   2.169 +	    for (i = 0; i < build_cmdarray.length; i ++) 
   2.170 +	      build_cmdarray[i] = "";
   2.171 +	    build_cmdarray[idx ++] = d.XIToolsDir + "xi_build";
   2.172 +	    build_cmdarray[idx ++] = "" + domain_id;
   2.173 +	    build_cmdarray[idx ++] = "" + image;
   2.174 +	    build_cmdarray[idx ++] = "" + vifs;
   2.175 +	    if (initrd != null) build_cmdarray[idx ++] = "initrd=" + initrd;
   2.176 +	    build_cmdarray[idx ++] = "" + bargs;
   2.177 +	    System.out.println ("Build args: " + bargs);
   2.178 +	    if (Settings.TEST) {
   2.179 +	      reportCommand (build_cmdarray);
   2.180 +	      build_rc = 0;
   2.181 +	    } else {
   2.182 +	      build_p = r.exec (build_cmdarray);
   2.183 +	      build_rc = build_p.waitFor ();
   2.184 +	    }
   2.185 +	    
   2.186 +	    if (build_rc != 0) {
   2.187 +	      return reportXIError ("Failed to build domain", build_cmdarray);
   2.188 +	    }
   2.189 +	    
   2.190 +	    /* Set up the first VIF if necessary */
   2.191 +	    if (vifs > 0) {
   2.192 +	      Process vifinit_p;
   2.193 +	      String vifinit_cmdarray[] = new String[4];
   2.194 +	      int vifinit_rc;
   2.195 +	      vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
   2.196 +	      vifinit_cmdarray[1] = "" + domain_id;
   2.197 +	      vifinit_cmdarray[2] = "0";
   2.198 +	      vifinit_cmdarray[3] = domain_ip;
   2.199 +	      if (Settings.TEST) {
   2.200 +		reportCommand (vifinit_cmdarray);
   2.201 +		vifinit_rc = 0;
   2.202 +	      } else {
   2.203 +		vifinit_p = r.exec (vifinit_cmdarray);
   2.204 +		vifinit_rc = vifinit_p.waitFor ();
   2.205 +	      }
   2.206 +	      
   2.207 +	      if (vifinit_rc != 0) {
   2.208 +		return reportXIError ("Failed to initialise VIF 0", vifinit_cmdarray);
   2.209 +	      }
   2.210 +	    }
   2.211 +	  } finally {
   2.212 +	    if (image_tmp != null) image_tmp.delete();
   2.213 +	    if (initrd_tmp != null) initrd_tmp.delete ();
   2.214  	  }
   2.215 -	  bargs = ("ip=" + domain_ip +
   2.216 -		   ":" + ((nw_nfs_server == null) ? "" : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id))) +
   2.217 -		   ":" + ((nw_gw == null) ? "" : (InetAddressPattern.parse(nw_gw).resolve(domain_id))) + 
   2.218 -		   ":" + ((nw_mask == null) ? "" : InetAddressPattern.parse(nw_mask).resolve(domain_id)) +
   2.219 -		   ":" + ((nw_host == null) ? "" : nw_host) + 
   2.220 -		   ":eth0:off " + bargs);
   2.221 -	}
   2.222 -	
   2.223 -	/* Build the domain */
   2.224 -	Process build_p;
   2.225 -	String build_cmdarray[] = new String[6];
   2.226 -	int build_rc;
   2.227 -	idx = 0;
   2.228 -	for (i = 0; i < build_cmdarray.length; i ++) 
   2.229 -	  build_cmdarray[i] = "";
   2.230 -	build_cmdarray[idx ++] = d.XIToolsDir + "xi_build";
   2.231 -	build_cmdarray[idx ++] = "" + domain_id;
   2.232 -	build_cmdarray[idx ++] = "" + image;
   2.233 -	build_cmdarray[idx ++] = "" + vifs;
   2.234 -	if (initrd != null) build_cmdarray[idx ++] = "initrd=" + initrd;
   2.235 -	build_cmdarray[idx ++] = "" + bargs;
   2.236 -	System.out.println ("Build args: " + bargs);
   2.237 -	if (Settings.TEST) {
   2.238 -	  reportCommand (build_cmdarray);
   2.239 -	  build_rc = 0;
   2.240 -	} else {
   2.241 -	  build_p = r.exec (build_cmdarray);
   2.242 -	  build_rc = build_p.waitFor ();
   2.243 -	}
   2.244 -
   2.245 -	if (build_rc != 0) {
   2.246 -	  return reportXIError ("Failed to build domain", build_cmdarray);
   2.247 -	}
   2.248 -
   2.249 -
   2.250 -	/* Set up the first VIF if necessary */
   2.251 -	if (vifs > 0) {
   2.252 -	  Process vifinit_p;
   2.253 -	  String vifinit_cmdarray[] = new String[4];
   2.254 -	  int vifinit_rc;
   2.255 -	  vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
   2.256 -	  vifinit_cmdarray[1] = "" + domain_id;
   2.257 -	  vifinit_cmdarray[2] = "0";
   2.258 -	  vifinit_cmdarray[3] = domain_ip;
   2.259 -	  if (Settings.TEST) {
   2.260 -	    reportCommand (vifinit_cmdarray);
   2.261 -	    vifinit_rc = 0;
   2.262 -	  } else {
   2.263 -	    vifinit_p = r.exec (vifinit_cmdarray);
   2.264 -	    vifinit_rc = vifinit_p.waitFor ();
   2.265 -	  }
   2.266 -	  
   2.267 -	  if (vifinit_rc != 0) {
   2.268 -	    return reportXIError ("Failed to initialise VIF 0", vifinit_cmdarray);
   2.269 -	  }
   2.270 -	}
   2.271        }
   2.272      catch (Exception e) 
   2.273        {
   2.274 @@ -165,6 +184,29 @@ public class CommandNew extends Command
   2.275      return rc;
   2.276    }
   2.277  
   2.278 +  File getUncompressed (String prefix, String original) throws IOException {
   2.279 +    FileOutputStream fos;
   2.280 +    GZIPInputStream gis;
   2.281 +    File result;
   2.282 +    byte buffer[] = new byte[1024];
   2.283 +    int l;
   2.284 +    
   2.285 +    result = File.createTempFile (prefix, null);
   2.286 +    
   2.287 +    try {
   2.288 +      fos = new FileOutputStream (result);
   2.289 +      gis = new GZIPInputStream (new FileInputStream (original));
   2.290 +      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
   2.291 +	fos.write (buffer, 0, l);
   2.292 +      }	  
   2.293 +    } catch (IOException ioe) {
   2.294 +      result.delete ();
   2.295 +      throw ioe;
   2.296 +    }
   2.297 +
   2.298 +    return result;
   2.299 +  }
   2.300 +
   2.301    public String getName()
   2.302    {
   2.303      return "new";