ia64/xen-unstable

changeset 411:040b2a93aca3

bitkeeper revision 1.198 (3eb067ccnZGiSrE___bi3AnWpeUuIw)

allow creation of vbd directly from disk partition
error checking to ensure that /proc/partitions is from a xeno machine
author ach61@labyrinth.cl.cam.ac.uk
date Thu May 01 00:18:20 2003 +0000 (2003-05-01)
parents 0afe9ac81deb
children eaaeabbe61cb
files tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Parser.java tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/PartitionManager.java tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDisk.java tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDiskManager.java
line diff
     1.1 --- a/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Parser.java	Wed Apr 30 16:22:46 2003 +0000
     1.2 +++ b/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Parser.java	Thu May 01 00:18:20 2003 +0000
     1.3 @@ -252,6 +252,45 @@ Parser
     1.4        return;
     1.5      }
     1.6  
     1.7 +    if (commands[1].startsWith("sd") ||
     1.8 +	commands[1].startsWith("hd"))
     1.9 +    {
    1.10 +      /*
    1.11 +       * this is a gross hack to allow you to create a virtual block
    1.12 +       * device that maps directly to a physical partition
    1.13 +       */
    1.14 +
    1.15 +      /* find the appropriate partition */
    1.16 +      Partition partition = pm.get_partition(commands[1]);
    1.17 +      if (partition == null)
    1.18 +      {
    1.19 +	System.out.println ("vbdcreate error: couldn't find partition \"" +
    1.20 +			    commands[1] + "\"");
    1.21 +	return;
    1.22 +      }
    1.23 +
    1.24 +      /* create a virtual disk */
    1.25 +      vd = new VirtualDisk("vbd:" + commands[1]);
    1.26 +      vd.add_new_partition(partition, partition.nr_sects);
    1.27 +
    1.28 +
    1.29 +      /* display result */
    1.30 +      System.out.print("domain:" + commands[2] + " ");
    1.31 +      if (commands.length == 4)
    1.32 +      {
    1.33 +	System.out.print ("rw ");
    1.34 +      }
    1.35 +      else
    1.36 +      {
    1.37 +	System.out.print(commands[4] + " ");
    1.38 +      }
    1.39 +      System.out.print("segment:" + commands[3] + " ");
    1.40 +      System.out.print(vd.dump_xen());
    1.41 +      System.out.println("");
    1.42 +
    1.43 +      return;
    1.44 +    } 
    1.45 +
    1.46      if (commands.length == 4)
    1.47      {
    1.48        vbd =
    1.49 @@ -269,6 +308,7 @@ Parser
    1.50  				      commands[4]);
    1.51      }
    1.52  
    1.53 +    /* display commandline to user */
    1.54      {
    1.55        vd = vdm.get_virtual_disk_key(commands[1]);
    1.56        System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
    1.57 @@ -280,7 +320,7 @@ Parser
    1.58    {
    1.59      if (commands.length < 3)
    1.60      {
    1.61 -      System.out.println ("vbdcreate <domain number> <vbd number>");
    1.62 +      System.out.println ("vbddelete <domain number> <vbd number>");
    1.63        return;
    1.64      }
    1.65  
     2.1 --- a/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/PartitionManager.java	Wed Apr 30 16:22:46 2003 +0000
     2.2 +++ b/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/PartitionManager.java	Thu May 01 00:18:20 2003 +0000
     2.3 @@ -7,6 +7,7 @@ package uk.ac.cam.cl.xeno.vdmanager;
     2.4  
     2.5  import java.io.*;
     2.6  import java.util.Vector;
     2.7 +import java.util.Enumeration;
     2.8  
     2.9  public class
    2.10  PartitionManager
    2.11 @@ -14,6 +15,9 @@ PartitionManager
    2.12    Vector partition_map;
    2.13    Vector xeno_partition_list;
    2.14  
    2.15 +  static String proc_template =
    2.16 +    "major minor  #blocks  start_sect   nr_sects name";
    2.17 +
    2.18    /*
    2.19     * Initialize partition manager with source file.
    2.20     * Normally we read from /proc/partitions, but we can
    2.21 @@ -32,6 +36,14 @@ PartitionManager
    2.22        in = new BufferedReader(new FileReader(filename));
    2.23  
    2.24        str = in.readLine();                                  /* skip headings */
    2.25 +      if (str.length() < proc_template.length() ||
    2.26 +	  !str.substring(0, proc_template.length()).equals(proc_template))
    2.27 +      {
    2.28 +	System.err.println ("Error: Incorrect /proc/partitions.");
    2.29 +	System.err.println ("       Is this Xeno?");
    2.30 +	System.exit (1);
    2.31 +      }
    2.32 +
    2.33        str = in.readLine();                                /* skip blank line */
    2.34  
    2.35        str = in.readLine();
    2.36 @@ -59,6 +71,21 @@ PartitionManager
    2.37    }
    2.38  
    2.39    Partition
    2.40 +  get_partition (String name)
    2.41 +  {
    2.42 +    Partition partition = null;
    2.43 +    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
    2.44 +    {
    2.45 +      partition = (Partition) e.nextElement();
    2.46 +      if (partition.name.equals(name))
    2.47 +      {
    2.48 +	return partition;
    2.49 +      }
    2.50 +    }
    2.51 +    return null;
    2.52 +  }
    2.53 +
    2.54 +  Partition
    2.55    get_partition (int index)
    2.56    {
    2.57      return (Partition) partition_map.get(index);
     3.1 --- a/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDisk.java	Wed Apr 30 16:22:46 2003 +0000
     3.2 +++ b/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDisk.java	Thu May 01 00:18:20 2003 +0000
     3.3 @@ -134,6 +134,22 @@ VirtualDisk
     3.4    }
     3.5  
     3.6    String
     3.7 +  dump_xen ()
     3.8 +  {
     3.9 +    StringBuffer sb = new StringBuffer();
    3.10 +
    3.11 +    sb.append("extents:" + extents.size() + " ");
    3.12 +    for (int loop = 0; loop < extents.size(); loop++)
    3.13 +    {
    3.14 +      Extent e = (Extent) extents.get(loop);
    3.15 +      sb.append("(disk:" + e.disk + " " +
    3.16 +		"offset:" + e.offset + " " +
    3.17 +		"size:" + e.size + ")");
    3.18 +    }
    3.19 +    return sb.toString();
    3.20 +  }
    3.21 +
    3.22 +  String
    3.23    dump_xen (VirtualBlockDevice vbd)
    3.24    {
    3.25      StringBuffer sb = new StringBuffer();
     4.1 --- a/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDiskManager.java	Wed Apr 30 16:22:46 2003 +0000
     4.2 +++ b/tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDiskManager.java	Thu May 01 00:18:20 2003 +0000
     4.3 @@ -14,14 +14,14 @@ import java.io.PrintWriter;
     4.4  public class
     4.5  VirtualDiskManager
     4.6  {
     4.7 -  VirtualDisk free;
     4.8 +  VirtualDisk free_disk;
     4.9    Vector virtual_disks;
    4.10    Hashtable virtual_block_devices;
    4.11    Hashtable key_hash;
    4.12  
    4.13    VirtualDiskManager ()
    4.14    {
    4.15 -    free = new VirtualDisk("free");
    4.16 +    free_disk = new VirtualDisk("free");
    4.17  
    4.18      virtual_disks = new Vector(10,5);
    4.19      flush_virtual_block_devices();
    4.20 @@ -37,7 +37,7 @@ VirtualDiskManager
    4.21    public void
    4.22    add_xeno_partition (Partition partition, long size)
    4.23    {
    4.24 -    free.add_new_partition (partition, size);
    4.25 +    free_disk.add_new_partition (partition, size);
    4.26      return;
    4.27    }
    4.28  
    4.29 @@ -54,7 +54,7 @@ VirtualDiskManager
    4.30      {
    4.31        Extent e;
    4.32  
    4.33 -      e = free.remove_extent();
    4.34 +      e = free_disk.remove_extent();
    4.35        if (e == null)
    4.36        {
    4.37  	return null;
    4.38 @@ -88,7 +88,7 @@ VirtualDiskManager
    4.39        e = vd.remove_extent();
    4.40        while (e != null)
    4.41        {
    4.42 -	free.add_extent(e);
    4.43 +	free_disk.add_extent(e);
    4.44  	e = vd.remove_extent();
    4.45        }
    4.46      }
    4.47 @@ -198,7 +198,7 @@ VirtualDiskManager
    4.48    public void
    4.49    add_free (VirtualDisk vd)
    4.50    {
    4.51 -    free = vd;
    4.52 +    free_disk = vd;
    4.53    }
    4.54  
    4.55    public String
    4.56 @@ -218,7 +218,7 @@ VirtualDiskManager
    4.57    public String
    4.58    dump_free()
    4.59    {
    4.60 -    return(free.dump(true, false));
    4.61 +    return(free_disk.dump(true, false));
    4.62    }
    4.63  
    4.64    public String
    4.65 @@ -265,7 +265,7 @@ VirtualDiskManager
    4.66    dump_xml(PrintWriter out)
    4.67    {
    4.68      out.println("<free>");
    4.69 -    free.dump_xml(out);
    4.70 +    free_disk.dump_xml(out);
    4.71      out.println("</free>");
    4.72      out.println("<virtual_disks>");
    4.73      for (int i = 0; i < virtual_disks.size(); i++)