ia64/xen-unstable

changeset 521:209c95700af8

bitkeeper revision 1.288 (3f098762sqCvcfeLanWC1bkr_aEKGA)

Add virtual disk manager to xenctl
Implement partial virtual disk functionality
Code cleanups
author rac61@labyrinth.cl.cam.ac.uk
date Mon Jul 07 14:44:50 2003 +0000 (2003-07-07)
parents f15a7e78b8cb
children 07cb518caf2f
files .rootkeys tools/control/src/org/xenoserver/cmdline/Main.java tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java tools/control/src/org/xenoserver/cmdline/ParseVdFree.java tools/control/src/org/xenoserver/cmdline/ParseVdShow.java tools/control/src/org/xenoserver/control/CommandPartitionAdd.java tools/control/src/org/xenoserver/control/CommandVdCreate.java tools/control/src/org/xenoserver/control/VirtualBlockDevice.java tools/control/src/org/xenoserver/control/VirtualDisk.java tools/control/src/org/xenoserver/control/VirtualDiskManager.java tools/control/src/org/xenoserver/control/XML.java tools/control/src/org/xenoserver/control/XMLHelper.java
line diff
     1.1 --- a/.rootkeys	Mon Jul 07 14:41:17 2003 +0000
     1.2 +++ b/.rootkeys	Mon Jul 07 14:44:50 2003 +0000
     1.3 @@ -25,10 +25,14 @@ 3f042c35Lc-JegNavF6Bj6coM486Ig tools/con
     1.4  3f042c35UhRkvblwKSx0KW2QHUn3Fw tools/control/src/org/xenoserver/cmdline/ParseFailedException.java
     1.5  3f0445524oTSyogDGmCAyKMM665Rxg tools/control/src/org/xenoserver/cmdline/ParseGroup.java
     1.6  3f042c35Inw0LzkOzXo9ncbEHZzUHA tools/control/src/org/xenoserver/cmdline/ParseHelp.java
     1.7 +3f098761jTSCT4f7lCWFePC3TJN_nw tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java
     1.8  3f05631djnPcaqmzMFSa8RLmGCZ-0Q tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java
     1.9  3f05631dswxJX_TpcuG6tBstyHSetg tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
    1.10  3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
    1.11  3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
    1.12 +3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
    1.13 +3f098761zh9WTV6LpRqcet3gqlXdtg tools/control/src/org/xenoserver/cmdline/ParseVdFree.java
    1.14 +3f098761vY4hzt_QKskmvMcibN0zYQ tools/control/src/org/xenoserver/cmdline/ParseVdShow.java
    1.15  3f042c35V-Bf3dlIe1r5mZs8ZTPSvA tools/control/src/org/xenoserver/control/Command.java
    1.16  3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDomainDestroy.java
    1.17  3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandDomainList.java
    1.18 @@ -36,9 +40,11 @@ 3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/con
    1.19  3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandDomainStart.java
    1.20  3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandDomainStop.java
    1.21  3f042c35hdwL__Airzyz4HutOgGRqQ tools/control/src/org/xenoserver/control/CommandFailedException.java
    1.22 +3f0987611uZwg-o64yi0p_2aXCYEug tools/control/src/org/xenoserver/control/CommandPartitionAdd.java
    1.23  3f05631ev3UK5FRi5vgR08zDp3OZYw tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java
    1.24  3f05631e_G6wzHhEnpihX0pIkEsbMw tools/control/src/org/xenoserver/control/CommandPhysicalList.java
    1.25  3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
    1.26 +3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
    1.27  3eb781fdBRXfSlWzK6GXlIQIlHFoaQ tools/control/src/org/xenoserver/control/Defaults.java
    1.28  3ec41f7cQ7Ug739JBDrsVH-7KJ5MvQ tools/control/src/org/xenoserver/control/Domain.java
    1.29  3ec41f7cAzdBu0lkuTTQx92rqSM9Qw tools/control/src/org/xenoserver/control/Extent.java
    1.30 @@ -49,6 +55,9 @@ 3ec41f7dbqJLTy1msByMzQhy3jHHyQ tools/con
    1.31  3ec41f7djIGkw6M9meq8-YZ1WDATcw tools/control/src/org/xenoserver/control/PartitionManager.java
    1.32  3eb781fdmMkFbyb2SAGR0vsuFtl9Lw tools/control/src/org/xenoserver/control/Settings.java
    1.33  3eb781fdpgi83RpUvQWVccWjsDJK7w tools/control/src/org/xenoserver/control/StringPattern.java
    1.34 +3ec41f7dNJZ1YkLD8X5CsqqYmP601g tools/control/src/org/xenoserver/control/VirtualBlockDevice.java
    1.35 +3ec41f7dVFBlviwXPQ06BlU3UybziA tools/control/src/org/xenoserver/control/VirtualDisk.java
    1.36 +3ec41f7dKX9YpwrfH7BZ7BogyWqqLA tools/control/src/org/xenoserver/control/VirtualDiskManager.java
    1.37  3ec41f7dUPpYTwYL5QVpRBv6PLKPrg tools/control/src/org/xenoserver/control/XML.java
    1.38  3ec41f7d7Try-2zmfnpaALwJjY0GCA tools/control/src/org/xenoserver/control/XMLHelper.java
    1.39  3ec41f7civcv4mQiYK0DeX9Zvsxhrw tools/control/src/uk/ac/cam/cl/xeno/xenctl/Main.java.orig
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/Main.java	Mon Jul 07 14:41:17 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Mon Jul 07 14:44:50 2003 +0000
     2.3 @@ -1,9 +1,6 @@
     2.4  package org.xenoserver.cmdline;
     2.5  
     2.6 -import java.util.Arrays;
     2.7 -import java.util.Collections;
     2.8  import java.util.LinkedList;
     2.9 -import java.util.List;
    2.10  
    2.11  import org.xenoserver.control.CommandFailedException;
    2.12  import org.xenoserver.control.Defaults;
    2.13 @@ -18,18 +15,25 @@ public class Main {
    2.14        new ParseDomainList()
    2.15      };
    2.16    static final CommandParser partitioncommands[] =
    2.17 -    { new ParsePartitionsList()
    2.18 +    { new ParsePartitionsAdd(),
    2.19 +      new ParsePartitionsList()
    2.20      };
    2.21    static final CommandParser physicalcommands[] =
    2.22      { new ParsePhysicalGrant(),
    2.23        new ParsePhysicalRevoke(),
    2.24        new ParsePhysicalList()
    2.25      };
    2.26 +  static final CommandParser vdcommands[] =
    2.27 +    { new ParseVdCreate(),
    2.28 +      new ParseVdShow(),
    2.29 +      new ParseVdFree()
    2.30 +    };
    2.31    static final CommandParser commands[] =
    2.32      { help,
    2.33        new ParseGroup( "domain", domaincommands ),
    2.34        new ParseGroup( "partitions", partitioncommands ),
    2.35 -      new ParseGroup( "physical", physicalcommands )
    2.36 +      new ParseGroup( "physical", physicalcommands ),
    2.37 +      new ParseGroup( "vd", vdcommands )
    2.38      };
    2.39    static final CommandParser parser = new ParseGroup( null, commands );
    2.40  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java	Mon Jul 07 14:44:50 2003 +0000
     3.3 @@ -0,0 +1,56 @@
     3.4 +package org.xenoserver.cmdline;
     3.5 +
     3.6 +import java.util.LinkedList;
     3.7 +
     3.8 +import org.xenoserver.control.CommandFailedException;
     3.9 +import org.xenoserver.control.CommandPartitionAdd;
    3.10 +import org.xenoserver.control.Defaults;
    3.11 +import org.xenoserver.control.Library;
    3.12 +import org.xenoserver.control.Partition;
    3.13 +import org.xenoserver.control.PartitionManager;
    3.14 +import org.xenoserver.control.Settings;
    3.15 +
    3.16 +public class ParsePartitionsAdd extends CommandParser {
    3.17 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    3.18 +    boolean force = getFlagParameter(args, 'f');
    3.19 +    String partition_name = getStringParameter(args, 'p', "");
    3.20 +    String size = getStringParameter(args, 'c', "100M");
    3.21 +    
    3.22 +    if (partition_name.equals(""))
    3.23 +      throw new ParseFailedException("Expected -p<partition_name>");
    3.24 +      
    3.25 +    long chunksize = Library.parse_size( size ) / Settings.SECTOR_SIZE;
    3.26 +    if ( chunksize <= 0 )
    3.27 +      throw new CommandFailedException("Chunk size " + size + " is smaller than sector size.");
    3.28 +    
    3.29 +    // Initialise the partition manager and look up the partition
    3.30 +    loadState();
    3.31 +    Partition p = PartitionManager.it.get_partition(partition_name);
    3.32 +    
    3.33 +    if ( p == null )
    3.34 +      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    3.35 +    
    3.36 +    // Check if this partition belongs to the VDM
    3.37 +    if (p.getIsXeno() && !force)
    3.38 +      throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
    3.39 +    
    3.40 +    String output = new CommandPartitionAdd( p, chunksize ).execute();
    3.41 +    if ( output != null )
    3.42 +      System.out.println( output );
    3.43 +      
    3.44 +    saveState();
    3.45 +  }
    3.46 +
    3.47 +  public String getName() {
    3.48 +    return "add";
    3.49 +  }
    3.50 +
    3.51 +  public String getUsage() {
    3.52 +    return "[-f] [-p<partition_name>] [-c<chunk_size>]";
    3.53 +  }
    3.54 +
    3.55 +  public String getHelpText() {
    3.56 +    return "Add the specified partition to the virtual disk manager's free\n" +
    3.57 +           "space. -c changes the default chunk size. -f forces add.";
    3.58 +  }
    3.59 +}
     4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java	Mon Jul 07 14:41:17 2003 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java	Mon Jul 07 14:44:50 2003 +0000
     4.3 @@ -8,13 +8,10 @@ import org.xenoserver.control.Defaults;
     4.4  import org.xenoserver.control.Library;
     4.5  import org.xenoserver.control.Partition;
     4.6  import org.xenoserver.control.PartitionManager;
     4.7 -import org.xenoserver.control.Settings;
     4.8 -import org.xenoserver.control.XML;
     4.9  
    4.10  public class ParsePartitionsList extends CommandParser {
    4.11 -
    4.12    public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    4.13 -    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    4.14 +    loadState();
    4.15      Iterator i = PartitionManager.it.iterator();
    4.16      int idx = 1;
    4.17      System.out.println( "     maj:min " + "    blocks " + "start sect " +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java	Mon Jul 07 14:44:50 2003 +0000
     5.3 @@ -0,0 +1,49 @@
     5.4 +package org.xenoserver.cmdline;
     5.5 +
     5.6 +import java.util.Date;
     5.7 +import java.util.LinkedList;
     5.8 +
     5.9 +import org.xenoserver.control.CommandFailedException;
    5.10 +import org.xenoserver.control.CommandVdCreate;
    5.11 +import org.xenoserver.control.Defaults;
    5.12 +import org.xenoserver.control.Library;
    5.13 +import org.xenoserver.control.Settings;
    5.14 +
    5.15 +public class ParseVdCreate extends CommandParser {
    5.16 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    5.17 +    String name = getStringParameter(args,'n',"");
    5.18 +    String size_s = getStringParameter(args,'s',"");
    5.19 +    String expiry_s = getStringParameter(args,'e',"");
    5.20 +    Date expiry;
    5.21 +    
    5.22 +    if ( name.equals("") )
    5.23 +      throw new ParseFailedException("Expected -n<name>");
    5.24 +    if ( size_s.equals("") )
    5.25 +      throw new ParseFailedException("Expected -s<size>");
    5.26 +    if ( expiry_s.equals("") )
    5.27 +      expiry = null;
    5.28 +    else
    5.29 +      expiry = new Date(Date.parse(expiry_s));
    5.30 +      
    5.31 +    long size = Library.parse_size(size_s);
    5.32 +    
    5.33 +    loadState();
    5.34 +    String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute();
    5.35 +    if ( output != null )
    5.36 +      System.out.println( output );
    5.37 +    saveState();
    5.38 +  }
    5.39 +
    5.40 +  public String getName() {
    5.41 +    return "create";
    5.42 +  }
    5.43 +
    5.44 +  public String getUsage() {
    5.45 +    return "[-n<name>] [-s<size>] [-e<expiry>]";
    5.46 +  }
    5.47 +
    5.48 +  public String getHelpText() {
    5.49 +    return "Create a new virtual disk with the specified parameters";
    5.50 +  }
    5.51 +
    5.52 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java	Mon Jul 07 14:44:50 2003 +0000
     6.3 @@ -0,0 +1,45 @@
     6.4 +package org.xenoserver.cmdline;
     6.5 +
     6.6 +import java.util.Iterator;
     6.7 +import java.util.LinkedList;
     6.8 +
     6.9 +import org.xenoserver.control.CommandFailedException;
    6.10 +import org.xenoserver.control.Defaults;
    6.11 +import org.xenoserver.control.Extent;
    6.12 +import org.xenoserver.control.Library;
    6.13 +import org.xenoserver.control.Settings;
    6.14 +import org.xenoserver.control.VirtualDisk;
    6.15 +import org.xenoserver.control.VirtualDiskManager;
    6.16 +
    6.17 +public class ParseVdFree extends CommandParser {
    6.18 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    6.19 +    boolean verbose = getFlagParameter(args, 'v');
    6.20 +    
    6.21 +    loadState();
    6.22 +    VirtualDisk free = VirtualDiskManager.it.getFreeVirtualDisk();
    6.23 +    System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling "
    6.24 +                      + Library.format_size(free.getSize()*Settings.SECTOR_SIZE,8,1) );
    6.25 +    if ( verbose ) {
    6.26 +      Iterator i = free.iterator();
    6.27 +      System.out.println("  disk       offset         size");
    6.28 +      while (i.hasNext()) {
    6.29 +        Extent e = (Extent) i.next();
    6.30 +        System.out.println( Library.format(e.getDisk(), 6, 0) + " "
    6.31 +                          + Library.format(e.getOffset(), 12, 0) + " "
    6.32 +                          + Library.format(e.getSize(), 12, 0) );
    6.33 +      }
    6.34 +    }
    6.35 +  }
    6.36 +
    6.37 +  public String getName() {
    6.38 +    return "free";
    6.39 +  }
    6.40 +
    6.41 +  public String getUsage() {
    6.42 +    return "[-v]";
    6.43 +  }
    6.44 +
    6.45 +  public String getHelpText() {
    6.46 +    return "Show free space allocated to virtual disk manager. -v enables verbose output.";
    6.47 +  }
    6.48 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java	Mon Jul 07 14:44:50 2003 +0000
     7.3 @@ -0,0 +1,66 @@
     7.4 +package org.xenoserver.cmdline;
     7.5 +
     7.6 +import java.util.Iterator;
     7.7 +import java.util.LinkedList;
     7.8 +
     7.9 +import org.xenoserver.control.CommandFailedException;
    7.10 +import org.xenoserver.control.Defaults;
    7.11 +import org.xenoserver.control.Extent;
    7.12 +import org.xenoserver.control.Library;
    7.13 +import org.xenoserver.control.Settings;
    7.14 +import org.xenoserver.control.VirtualDisk;
    7.15 +import org.xenoserver.control.VirtualDiskManager;
    7.16 +
    7.17 +public class ParseVdShow extends CommandParser {
    7.18 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    7.19 +    int vd_num = getIntParameter(args,'n',-1);
    7.20 +    
    7.21 +    loadState();
    7.22 +    
    7.23 +    if ( vd_num < 0 ) {
    7.24 +      System.out.println("num key        expiry                       name                 size");
    7.25 +      for (int i=0;i<VirtualDiskManager.it.getVirtualDiskCount();i++) {
    7.26 +        VirtualDisk vd = VirtualDiskManager.it.getVirtualDisk(i);
    7.27 +        System.out.print( Library.format(i,3,0) + " " + vd.getKey() + " " );
    7.28 +        if ( vd.getExpiry() != null )
    7.29 +          System.out.print( vd.getExpiry().toString() );
    7.30 +        else
    7.31 +          System.out.print( "                            " );
    7.32 +        System.out.println( " " + Library.format(vd.getName(),16,1) + " "
    7.33 +                          + Library.format_size(vd.getSize()*Settings.SECTOR_SIZE,8,0) );
    7.34 +      }
    7.35 +    } else {
    7.36 +      VirtualDisk vd = VirtualDiskManager.it.getVirtualDisk(vd_num);
    7.37 +      if ( vd == null )
    7.38 +        throw new CommandFailedException("There is no virtual disk " + vd_num );
    7.39 +        
    7.40 +      System.out.println("  name: " + vd.getName());
    7.41 +      System.out.println("   key: " + vd.getKey());
    7.42 +      System.out.println("  size: " + Library.format_size(vd.getSize()*Settings.SECTOR_SIZE,8,1));
    7.43 +      if ( vd.getExpiry() != null )
    7.44 +        System.out.println("expiry: " + vd.getExpiry());
    7.45 +      System.out.println();
    7.46 + 
    7.47 +      Iterator i = vd.iterator();
    7.48 +      System.out.println("  disk       offset         size");
    7.49 +      while (i.hasNext()) {
    7.50 +        Extent e = (Extent) i.next();
    7.51 +        System.out.println( Library.format(e.getDisk(), 6, 0) + " "
    7.52 +                          + Library.format(e.getOffset(), 12, 0) + " "
    7.53 +                          + Library.format(e.getSize(), 12, 0) );
    7.54 +      }
    7.55 +    }
    7.56 +  }
    7.57 +
    7.58 +  public String getName() {
    7.59 +    return "show";
    7.60 +  }
    7.61 +
    7.62 +  public String getUsage() {
    7.63 +    return "[-n<diskno>]";
    7.64 +  }
    7.65 +
    7.66 +  public String getHelpText() {
    7.67 +    return "Show a summary of all virtual disks, or details of one disk if -n is given";
    7.68 +  }
    7.69 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java	Mon Jul 07 14:44:50 2003 +0000
     8.3 @@ -0,0 +1,22 @@
     8.4 +package org.xenoserver.control;
     8.5 +
     8.6 +public class CommandPartitionAdd extends Command {
     8.7 +  private Partition partition;
     8.8 +  private long chunksize;
     8.9 +  
    8.10 +  /**
    8.11 +   * Constructor for CommandPartitionAdd.
    8.12 +   * @param partition Partition to add.
    8.13 +   * @param chunksize Chunk size to split partition into (in sectors).
    8.14 +   */
    8.15 +  public CommandPartitionAdd(Partition partition, long chunksize) {
    8.16 +    this.partition = partition;
    8.17 +    this.chunksize = chunksize;
    8.18 +  }
    8.19 +
    8.20 +  public String execute() throws CommandFailedException {
    8.21 +    VirtualDiskManager.it.add_xeno_partition(partition,chunksize);
    8.22 +    PartitionManager.it.add_xeno_partition(partition);
    8.23 +    return "Added partition " + partition.getName();
    8.24 +  }
    8.25 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java	Mon Jul 07 14:44:50 2003 +0000
     9.3 @@ -0,0 +1,28 @@
     9.4 +package org.xenoserver.control;
     9.5 +
     9.6 +import java.util.Date;
     9.7 +
     9.8 +public class CommandVdCreate extends Command {
     9.9 +  private String name;
    9.10 +  private long size;
    9.11 +  private Date expiry;
    9.12 +
    9.13 +  /**
    9.14 +   * Constructor for CommandVdCreate.
    9.15 +   * @param name Name of new virtual disk.
    9.16 +   * @param size Size in sectors.
    9.17 +   * @param expiry Expiry time, or null for never.
    9.18 +   */
    9.19 +  public CommandVdCreate(String name, long size, Date expiry) {
    9.20 +    this.name = name;
    9.21 +    this.size = size;
    9.22 +    this.expiry = expiry;
    9.23 +  }
    9.24 +
    9.25 +  public String execute() throws CommandFailedException {
    9.26 +    VirtualDisk vd = VirtualDiskManager.it.create_virtual_disk(name,size,expiry);
    9.27 +    if ( vd == null )
    9.28 +      throw new CommandFailedException( "Not enough free space to create disk" );
    9.29 +    return "Virtual Disk created with key: " + vd.getKey();
    9.30 +  }
    9.31 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java	Mon Jul 07 14:44:50 2003 +0000
    10.3 @@ -0,0 +1,61 @@
    10.4 +/*
    10.5 + * VirtualBlockDevice.java
    10.6 + * 03.03.27 aho creation
    10.7 + */
    10.8 +
    10.9 +package org.xenoserver.control;
   10.10 +
   10.11 +import java.io.PrintWriter;
   10.12 +
   10.13 +public class VirtualBlockDevice {
   10.14 +  String key;
   10.15 +  int domain;
   10.16 +  int vbdnum;
   10.17 +  Mode mode; /* rw or ro */
   10.18 +
   10.19 +  String dump(boolean title) {
   10.20 +    StringBuffer sb = new StringBuffer();
   10.21 +
   10.22 +    if (title) {
   10.23 +      sb.append("  key         dom vbd mode\n");
   10.24 +    } else {
   10.25 +      sb.append(
   10.26 +        "  "
   10.27 +          + key
   10.28 +          + "  "
   10.29 +          + Library.format(domain, 3, 0)
   10.30 +          + " "
   10.31 +          + Library.format(vbdnum, 3, 0)
   10.32 +          + " "
   10.33 +          + mode.toString()
   10.34 +          + "\n");
   10.35 +    }
   10.36 +
   10.37 +    return sb.toString();
   10.38 +  }
   10.39 +
   10.40 +  void dump_xml(PrintWriter out) {
   10.41 +    out.println("  <virtual_block_device>");
   10.42 +    out.println("    <key>" + key + "</key>");
   10.43 +    out.println("    <domain>" + domain + "</domain>");
   10.44 +    out.println("    <vbdnum>" + vbdnum + "</vbdnum>");
   10.45 +    out.println("    <mode>" + mode + "</mode>");
   10.46 +    out.println("  </virtual_block_device>");
   10.47 +  }
   10.48 +
   10.49 +  public String getKey() {
   10.50 +    return key;
   10.51 +  }
   10.52 +
   10.53 +  public int getDomain() {
   10.54 +    return domain;
   10.55 +  }
   10.56 +
   10.57 +  public int getVBDNum() {
   10.58 +    return vbdnum;
   10.59 +  }
   10.60 +
   10.61 +  public Mode getMode() {
   10.62 +    return mode;
   10.63 +  }
   10.64 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDisk.java	Mon Jul 07 14:44:50 2003 +0000
    11.3 @@ -0,0 +1,181 @@
    11.4 +/*
    11.5 + * VirtualDisk.java
    11.6 + * 03.03.26 aho creation
    11.7 + */
    11.8 +
    11.9 +package org.xenoserver.control;
   11.10 +
   11.11 +import java.io.PrintWriter;
   11.12 +import java.util.Date;
   11.13 +import java.util.Iterator;
   11.14 +import java.util.Vector;
   11.15 +
   11.16 +public class VirtualDisk {
   11.17 +  String name;
   11.18 +  String key;
   11.19 +  Date expiry;
   11.20 +  Vector extents;
   11.21 +
   11.22 +  VirtualDisk(String name, Date expiry, String key) {
   11.23 +    this.name = name;
   11.24 +    if ( key == null )
   11.25 +      this.key = generate_key();
   11.26 +    else
   11.27 +      this.key = key;
   11.28 +    this.expiry = expiry;
   11.29 +    extents = new Vector();
   11.30 +  }
   11.31 +
   11.32 +  VirtualDisk(String name) {
   11.33 +    this(name, null, null);
   11.34 +  }
   11.35 +
   11.36 +  VirtualDisk(String name, Date expiry) {
   11.37 +    this(name, expiry, null);
   11.38 +  }
   11.39 +
   11.40 +  /*
   11.41 +   * generate a unique key for this virtual disk.
   11.42 +   * for now, just generate a 10 digit number
   11.43 +   */
   11.44 +  String generate_key() {
   11.45 +    return Long.toString(1000000000l + (long) (Math.random() * 8999999999l));
   11.46 +  }
   11.47 +
   11.48 +  void set_expiry(Date expiry) {
   11.49 +    this.expiry = expiry;
   11.50 +  }
   11.51 +
   11.52 +  public void add_extent(Extent extent) {
   11.53 +    extents.add(extent);
   11.54 +  }
   11.55 +
   11.56 +  public Extent remove_extent() {
   11.57 +    Extent e;
   11.58 +
   11.59 +    if (extents.size() > 0) {
   11.60 +      e = (Extent) extents.remove(0);
   11.61 +    } else {
   11.62 +      e = null;
   11.63 +    }
   11.64 +
   11.65 +    return e;
   11.66 +  }
   11.67 +
   11.68 +  String dump_xen(VirtualBlockDevice vbd) {
   11.69 +    StringBuffer sb = new StringBuffer();
   11.70 +
   11.71 +    sb.append(
   11.72 +      "domain:"
   11.73 +        + vbd.domain
   11.74 +        + " "
   11.75 +        + vbd.mode.toString()
   11.76 +        + " "
   11.77 +        + "segment:"
   11.78 +        + vbd.vbdnum
   11.79 +        + " "
   11.80 +        + "extents:"
   11.81 +        + extents.size()
   11.82 +        + " ");
   11.83 +    for (int loop = 0; loop < extents.size(); loop++) {
   11.84 +      Extent e = (Extent) extents.get(loop);
   11.85 +      sb.append(
   11.86 +        "(disk:"
   11.87 +          + e.disk
   11.88 +          + " "
   11.89 +          + "offset:"
   11.90 +          + e.offset
   11.91 +          + " "
   11.92 +          + "size:"
   11.93 +          + e.size
   11.94 +          + ")");
   11.95 +    }
   11.96 +    return sb.toString();
   11.97 +  }
   11.98 +
   11.99 +  void dump_xml(PrintWriter out) {
  11.100 +    out.println("  <virtual_disk>");
  11.101 +    out.println("    <name>" + name + "</name>");
  11.102 +    out.println("    <key>" + key + "</key>");
  11.103 +    if (expiry == null) {
  11.104 +      out.println("    <expiry>0</expiry>");
  11.105 +    } else {
  11.106 +      out.println("    <expiry>" + expiry.getTime() + "</expiry>");
  11.107 +    }
  11.108 +    out.println("    <extents>");
  11.109 +    for (int loop = 0; loop < extents.size(); loop++) {
  11.110 +      Extent e = (Extent) extents.get(loop);
  11.111 +      out.println("      <extent>");
  11.112 +      out.println("        <disk>" + e.disk + "</disk>");
  11.113 +      out.println("        <size>" + e.size + "</size>");
  11.114 +      out.println("        <offset>" + e.offset + "</offset>");
  11.115 +      out.println("      </extent>");
  11.116 +    }
  11.117 +    out.println("    </extents>");
  11.118 +    out.println("  </virtual_disk>");
  11.119 +
  11.120 +    return;
  11.121 +  }
  11.122 +
  11.123 +  /*
  11.124 +   * Add a partition as a XenoPartition.
  11.125 +   * Chop the partition in to extents and of size "size" sectors
  11.126 +   * and add them to the virtual disk.
  11.127 +   */
  11.128 +
  11.129 +  void add_new_partition(Partition partition, long size) {
  11.130 +    int loop;
  11.131 +
  11.132 +    for (loop = 0; loop < partition.nr_sects / size; loop++) {
  11.133 +      Extent extent = new Extent();
  11.134 +
  11.135 +      extent.disk = partition.major << 8;
  11.136 +      extent.disk = extent.disk | (partition.minor >> 5) << 5;
  11.137 +      extent.size = size;
  11.138 +      extent.offset = partition.start_sect + (size * loop);
  11.139 +
  11.140 +      add_extent(extent);
  11.141 +    }
  11.142 +
  11.143 +    return;
  11.144 +  }
  11.145 +
  11.146 +  public String getName() {
  11.147 +    return name;
  11.148 +  }
  11.149 +
  11.150 +  public String getKey() {
  11.151 +    return key;
  11.152 +  }
  11.153 +
  11.154 +  public Date getExpiry() {
  11.155 +    return expiry;
  11.156 +  }
  11.157 +
  11.158 +  public int getExtentCount() {
  11.159 +    return extents.size();
  11.160 +  }
  11.161 +
  11.162 +  public Extent getExtent(int index) {
  11.163 +    return (Extent) extents.get(index);
  11.164 +  }
  11.165 +
  11.166 +  /**
  11.167 +   * @return Total size of this virtual disk in sectors.
  11.168 +   */
  11.169 +  public long getSize() {
  11.170 +    long size = 0;
  11.171 +    Iterator i = extents.iterator();
  11.172 +    while ( i.hasNext() ) {
  11.173 +      size += ((Extent) i.next()).getSize();
  11.174 +    }
  11.175 +    return size;
  11.176 +  }
  11.177 +  
  11.178 +  /**
  11.179 +   * @return An iterator over all extents in the disk.
  11.180 +   */
  11.181 +  public Iterator iterator() {
  11.182 +    return extents.iterator();
  11.183 +  }
  11.184 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Mon Jul 07 14:44:50 2003 +0000
    12.3 @@ -0,0 +1,236 @@
    12.4 +/*
    12.5 + * VirtualDiskManager.java
    12.6 + * 03.03.26 aho creation
    12.7 + */
    12.8 +
    12.9 +package org.xenoserver.control;
   12.10 +
   12.11 +import java.io.PrintWriter;
   12.12 +import java.util.Date;
   12.13 +import java.util.Enumeration;
   12.14 +import java.util.Hashtable;
   12.15 +import java.util.Vector;
   12.16 +
   12.17 +/**
   12.18 + * VirtualDiskManager manages the list of virtual disks on the machine. It is
   12.19 + * a Singleton which automatically initialises itself on first class reference.
   12.20 + */
   12.21 +public class VirtualDiskManager {
   12.22 +  public static final VirtualDiskManager it = new VirtualDiskManager();
   12.23 +  VirtualDisk free_disk;
   12.24 +  Vector virtual_disks;
   12.25 +  Hashtable virtual_block_devices;
   12.26 +  Hashtable key_hash;
   12.27 +
   12.28 +  private VirtualDiskManager() {
   12.29 +    free_disk = new VirtualDisk("free");
   12.30 +
   12.31 +    virtual_disks = new Vector(10, 5);
   12.32 +    flush_virtual_block_devices();
   12.33 +    key_hash = new Hashtable(100);
   12.34 +  }
   12.35 +
   12.36 +  public VirtualDisk get_virtual_disk_key(String key) {
   12.37 +    return ((VirtualDisk) key_hash.get(key));
   12.38 +  }
   12.39 +
   12.40 +  public void add_xeno_partition(Partition partition, long size) {
   12.41 +    free_disk.add_new_partition(partition, size);
   12.42 +    return;
   12.43 +  }
   12.44 +
   12.45 +  /*
   12.46 +   * create a new virtual disk
   12.47 +   */
   12.48 +
   12.49 +  public VirtualDisk create_virtual_disk(String name, long size, Date expiry) {
   12.50 +    VirtualDisk vd = new VirtualDisk(name, expiry);
   12.51 +
   12.52 +    if ( free_disk.getSize() < size )
   12.53 +      return null;
   12.54 +    
   12.55 +    while (size > 0) {
   12.56 +      Extent e;
   12.57 +
   12.58 +      e = free_disk.remove_extent();
   12.59 +      if (e == null) {
   12.60 +        return null;
   12.61 +      }
   12.62 +      size -= e.size;
   12.63 +      vd.add_extent(e);
   12.64 +    }
   12.65 +
   12.66 +    add_virtual_disk(vd);
   12.67 +
   12.68 +    return vd;
   12.69 +  }
   12.70 +
   12.71 +  /*
   12.72 +   * delete a new virtual disk.  extents go back into the free pool
   12.73 +   */
   12.74 +
   12.75 +  public void delete_virtual_disk(String key) {
   12.76 +    VirtualDisk vd;
   12.77 +
   12.78 +    vd = (VirtualDisk) key_hash.get(key);
   12.79 +    if (vd != null) {
   12.80 +      Extent e;
   12.81 +
   12.82 +      key_hash.remove(key);
   12.83 +      virtual_disks.remove(vd);
   12.84 +
   12.85 +      e = vd.remove_extent();
   12.86 +      while (e != null) {
   12.87 +        free_disk.add_extent(e);
   12.88 +        e = vd.remove_extent();
   12.89 +      }
   12.90 +    }
   12.91 +    return;
   12.92 +  }
   12.93 +
   12.94 +  /*
   12.95 +   * reset the expiry time for a virtual disk
   12.96 +   */
   12.97 +
   12.98 +  public void refresh_virtual_disk(String key, Date expiry) {
   12.99 +    VirtualDisk vd = (VirtualDisk) key_hash.get(key);
  12.100 +    if (vd != null) {
  12.101 +      vd.set_expiry(expiry);
  12.102 +    }
  12.103 +  }
  12.104 +
  12.105 +  /*
  12.106 +   * create a new virtual block device
  12.107 +   */
  12.108 +  public VirtualBlockDevice create_virtual_block_device(
  12.109 +    String key,
  12.110 +    int domain,
  12.111 +    int vbd_num,
  12.112 +    String mode) {
  12.113 +    VirtualBlockDevice vbd = new VirtualBlockDevice();
  12.114 +    VirtualDisk vd = get_virtual_disk_key(key);
  12.115 +
  12.116 +    if (vd == null) {
  12.117 +      System.err.println(
  12.118 +        "create virtual block device error: unknown key " + "[" + key + "]");
  12.119 +      return null;
  12.120 +    }
  12.121 +
  12.122 +    vbd.key = key;
  12.123 +    vbd.domain = domain;
  12.124 +    vbd.vbdnum = vbd_num;
  12.125 +
  12.126 +    if (mode.equals(Mode.READ_ONLY.toString())
  12.127 +      || mode.equals("RO")
  12.128 +      || mode.equals("ro")) {
  12.129 +      vbd.mode = Mode.READ_ONLY;
  12.130 +    } else if (
  12.131 +      mode.equals(Mode.READ_WRITE.toString())
  12.132 +        || mode.equals("RW")
  12.133 +        || mode.equals("rw")) {
  12.134 +      vbd.mode = Mode.READ_WRITE;
  12.135 +    } else {
  12.136 +      System.err.println(
  12.137 +        "create virtual block device error: unknown mode " + "[" + mode + "]");
  12.138 +      return null;
  12.139 +    }
  12.140 +
  12.141 +    add_virtual_block_device(vbd);
  12.142 +
  12.143 +    return vbd;
  12.144 +  }
  12.145 +
  12.146 +  /*
  12.147 +   * delete a virtual block device 
  12.148 +   */
  12.149 +  public void delete_virtual_block_device(int domain, int vbd_num) {
  12.150 +    Object hash = get_vbd_hash(domain, vbd_num);
  12.151 +    virtual_block_devices.remove(hash);
  12.152 +  }
  12.153 +
  12.154 +  /*
  12.155 +   * flush all virtual block devices
  12.156 +   */
  12.157 +  public void flush_virtual_block_devices() {
  12.158 +    /* isn't automatic garbage collection wonderful? */
  12.159 +    virtual_block_devices = new Hashtable(100);
  12.160 +  }
  12.161 +
  12.162 +  public void add_virtual_disk(VirtualDisk vd) {
  12.163 +    virtual_disks.add(vd);
  12.164 +    key_hash.put(vd.getKey(), vd);
  12.165 +  }
  12.166 +
  12.167 +  public void add_virtual_block_device(VirtualBlockDevice vbd) {
  12.168 +    Object hash = get_vbd_hash(vbd.domain, vbd.vbdnum);
  12.169 +    virtual_block_devices.put(hash, vbd);
  12.170 +  }
  12.171 +
  12.172 +  Object get_vbd_hash(int domain, int vbd_num) {
  12.173 +    return new Integer(domain * 16 + vbd_num);
  12.174 +  }
  12.175 +
  12.176 +  public void add_free(VirtualDisk vd) {
  12.177 +    free_disk = vd;
  12.178 +  }
  12.179 +
  12.180 +  public String dump_virtualblockdevices() {
  12.181 +    StringBuffer sb = new StringBuffer();
  12.182 +    boolean first = true;
  12.183 +
  12.184 +    for (Enumeration enumeration = virtual_block_devices.elements();
  12.185 +      enumeration.hasMoreElements();
  12.186 +      ) {
  12.187 +      VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement();
  12.188 +      if (first) {
  12.189 +        sb.append(vbd.dump(true));
  12.190 +        first = false;
  12.191 +      }
  12.192 +
  12.193 +      sb.append(vbd.dump(false));
  12.194 +    }
  12.195 +
  12.196 +    return sb.toString();
  12.197 +  }
  12.198 +
  12.199 +  public void dump_xml(PrintWriter out) {
  12.200 +    out.println("<free>");
  12.201 +    free_disk.dump_xml(out);
  12.202 +    out.println("</free>");
  12.203 +    out.println("<virtual_disks>");
  12.204 +    for (int i = 0; i < virtual_disks.size(); i++) {
  12.205 +      VirtualDisk vd = (VirtualDisk) virtual_disks.get(i);
  12.206 +      vd.dump_xml(out);
  12.207 +    }
  12.208 +    out.println("</virtual_disks>");
  12.209 +    out.println("<virtual_block_devices>");
  12.210 +    for (Enumeration enumeration = virtual_block_devices.elements();
  12.211 +      enumeration.hasMoreElements();
  12.212 +      ) {
  12.213 +      VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement();
  12.214 +      vbd.dump_xml(out);
  12.215 +    }
  12.216 +
  12.217 +    out.println("</virtual_block_devices>");
  12.218 +
  12.219 +    return;
  12.220 +  }
  12.221 +
  12.222 +  /*************************************************************************/
  12.223 +
  12.224 +  public int getVirtualDiskCount() {
  12.225 +    return virtual_disks.size();
  12.226 +  }
  12.227 +
  12.228 +  public VirtualDisk getVirtualDisk(int index) {
  12.229 +    return (VirtualDisk) virtual_disks.get(index);
  12.230 +  }
  12.231 +
  12.232 +  public VirtualDisk getFreeVirtualDisk() {
  12.233 +    return free_disk;
  12.234 +  }
  12.235 +
  12.236 +  public Enumeration getVirtualBlockDevices() {
  12.237 +    return virtual_block_devices.elements();
  12.238 +  }
  12.239 +}
    13.1 --- a/tools/control/src/org/xenoserver/control/XML.java	Mon Jul 07 14:41:17 2003 +0000
    13.2 +++ b/tools/control/src/org/xenoserver/control/XML.java	Mon Jul 07 14:44:50 2003 +0000
    13.3 @@ -30,7 +30,7 @@ XML
    13.4     */
    13.5  
    13.6    public static void
    13.7 -  dump_state (PartitionManager pm,/* VirtualDiskManager vdm,*/ String filename)
    13.8 +  dump_state (PartitionManager pm, VirtualDiskManager vdm, String filename)
    13.9    {
   13.10      PrintWriter out;
   13.11  
   13.12 @@ -48,7 +48,7 @@ XML
   13.13      out.println("<?xml version=\"1.0\"?>");
   13.14      out.println("<vdmanager>");
   13.15      pm.dump_xml(out);
   13.16 -    //vdm.dump_xml(out);
   13.17 +    vdm.dump_xml(out);
   13.18      out.println("</vdmanager>");
   13.19  
   13.20      out.close();
   13.21 @@ -59,14 +59,14 @@ XML
   13.22     * load partition manager and virtual disk manager state from filename
   13.23     */
   13.24    public static void
   13.25 -  load_state (PartitionManager pm, /*VirtualDiskManager vdm,*/ String filename)
   13.26 +  load_state (PartitionManager pm, VirtualDiskManager vdm, String filename)
   13.27    {
   13.28      if (document == null)
   13.29      {
   13.30        load_file (filename);
   13.31      }
   13.32  
   13.33 -    XMLHelper.parse(pm, /*vdm,*/ document);
   13.34 +    XMLHelper.parse(pm, vdm, document);
   13.35    }
   13.36  
   13.37    /*
    14.1 --- a/tools/control/src/org/xenoserver/control/XMLHelper.java	Mon Jul 07 14:41:17 2003 +0000
    14.2 +++ b/tools/control/src/org/xenoserver/control/XMLHelper.java	Mon Jul 07 14:44:50 2003 +0000
    14.3 @@ -6,6 +6,7 @@
    14.4  package org.xenoserver.control;
    14.5  
    14.6  import java.util.Date;
    14.7 +
    14.8  import org.w3c.dom.Document;
    14.9  import org.w3c.dom.Element;
   14.10  import org.w3c.dom.Node;
   14.11 @@ -98,14 +99,14 @@ XMLHelper
   14.12    }
   14.13  
   14.14    static void
   14.15 -  parse (PartitionManager pm, /*VirtualDiskManager vdm,*/ Document document)
   14.16 +  parse (PartitionManager pm, VirtualDiskManager vdm, Document document)
   14.17    {
   14.18      if (document == null) return;
   14.19  
   14.20      /* parse partitions */
   14.21      parse_partitions(pm, document.getElementsByTagName("partition"));
   14.22 -/*
   14.23 -    / parse virtual disks /
   14.24 +
   14.25 +    /* parse virtual disks */
   14.26      NodeList list = document.getElementsByTagName("virtual_disk");
   14.27      for (int i = 0; i < list.getLength(); i++)
   14.28      {
   14.29 @@ -128,20 +129,24 @@ XMLHelper
   14.30        }
   14.31      }
   14.32  
   14.33 -    / parse virtual block devices /
   14.34 +    /* parse virtual block devices */
   14.35      parse_virtual_block_devices(vdm, document.getElementsByTagName("virtual_block_device"));
   14.36 -*/
   14.37 +
   14.38      return;
   14.39    }
   14.40  
   14.41 - /* static VirtualDisk
   14.42 +  static VirtualDisk
   14.43    parse_virtual_disk(Node node)
   14.44    {
   14.45      VirtualDisk vd;
   14.46      Date date = new Date();
   14.47      NodeList list;
   14.48  
   14.49 -    date.setTime(Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("expiry", node))));
   14.50 +    long timestamp = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("expiry", node)));
   14.51 +    if ( timestamp == 0 )
   14.52 +      date = null;
   14.53 +    else
   14.54 +      date.setTime( timestamp );
   14.55      vd = new VirtualDisk(XMLHelper.get_text(XMLHelper.get_subnode("name", node)),
   14.56  			 date,
   14.57  			 XMLHelper.get_text(XMLHelper.get_subnode("key", node)));
   14.58 @@ -164,7 +169,7 @@ XMLHelper
   14.59      }
   14.60  
   14.61      return vd;
   14.62 -  }*/
   14.63 +  }
   14.64  
   14.65    static void
   14.66    parse_partitions (PartitionManager pm, NodeList nl)
   14.67 @@ -186,12 +191,10 @@ XMLHelper
   14.68        pm.add_xeno_partition(partition);
   14.69      }
   14.70    }
   14.71 -/*
   14.72 +
   14.73    static void
   14.74    parse_virtual_block_devices (VirtualDiskManager vdm, NodeList nl)
   14.75    {
   14.76 -    VirtualBlockDevice vbd;
   14.77 -
   14.78      for (int loop = 0; loop < nl.getLength(); loop++)
   14.79      {
   14.80        Node node = nl.item(loop);
   14.81 @@ -201,5 +204,5 @@ XMLHelper
   14.82  				      Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("vbdnum", node))),
   14.83  				      XMLHelper.get_text(XMLHelper.get_subnode("mode", node)));
   14.84      }
   14.85 -  }*/
   14.86 +  }
   14.87  }