ia64/xen-unstable

changeset 498:4b8ce663794b

bitkeeper revision 1.269 (3f05631fUbZceaMD9jXHZuX-gUlgYw)

Start refactoring VD stuff into new package structure
Implemented physical disk access stuff for sos22's shiny new interface for same
author rac61@labyrinth.cl.cam.ac.uk
date Fri Jul 04 11:21:03 2003 +0000 (2003-07-04)
parents 11b14ed1bf78
children f18ad5c14d58 dc332ee77380
files .rootkeys tools/control/src/org/xenoserver/cmdline/Main.java tools/control/src/org/xenoserver/cmdline/ParseGroup.java tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java tools/control/src/org/xenoserver/control/CommandPhysicalList.java tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java tools/control/src/org/xenoserver/control/Extent.java tools/control/src/org/xenoserver/control/Library.java tools/control/src/org/xenoserver/control/Mode.java tools/control/src/org/xenoserver/control/Partition.java tools/control/src/org/xenoserver/control/PartitionManager.java tools/control/src/org/xenoserver/control/Settings.java tools/control/src/org/xenoserver/control/XML.java tools/control/src/org/xenoserver/control/XMLHelper.java
line diff
     1.1 --- a/.rootkeys	Fri Jul 04 10:39:53 2003 +0000
     1.2 +++ b/.rootkeys	Fri Jul 04 11:21:03 2003 +0000
     1.3 @@ -25,6 +25,10 @@ 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 +3f05631djnPcaqmzMFSa8RLmGCZ-0Q tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java
     1.8 +3f05631dswxJX_TpcuG6tBstyHSetg tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
     1.9 +3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
    1.10 +3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
    1.11  3f042c35V-Bf3dlIe1r5mZs8ZTPSvA tools/control/src/org/xenoserver/control/Command.java
    1.12  3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDomainDestroy.java
    1.13  3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandDomainList.java
    1.14 @@ -32,11 +36,21 @@ 3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/con
    1.15  3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandDomainStart.java
    1.16  3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandDomainStop.java
    1.17  3f042c35hdwL__Airzyz4HutOgGRqQ tools/control/src/org/xenoserver/control/CommandFailedException.java
    1.18 +3f05631ev3UK5FRi5vgR08zDp3OZYw tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java
    1.19 +3f05631e_G6wzHhEnpihX0pIkEsbMw tools/control/src/org/xenoserver/control/CommandPhysicalList.java
    1.20 +3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
    1.21  3eb781fdBRXfSlWzK6GXlIQIlHFoaQ tools/control/src/org/xenoserver/control/Defaults.java
    1.22  3ec41f7cQ7Ug739JBDrsVH-7KJ5MvQ tools/control/src/org/xenoserver/control/Domain.java
    1.23 +3ec41f7cAzdBu0lkuTTQx92rqSM9Qw tools/control/src/org/xenoserver/control/Extent.java
    1.24  3eb781fdDeZEopemXIVg_ARCGKSmBw tools/control/src/org/xenoserver/control/InetAddressPattern.java
    1.25 +3ec41f7cqN_uVR_7TqjgypDfFdGyrg tools/control/src/org/xenoserver/control/Library.java
    1.26 +3ec41f7dsb1R8BvBNzjYufMrx6ONdA tools/control/src/org/xenoserver/control/Mode.java
    1.27 +3ec41f7dbqJLTy1msByMzQhy3jHHyQ tools/control/src/org/xenoserver/control/Partition.java
    1.28 +3ec41f7djIGkw6M9meq8-YZ1WDATcw tools/control/src/org/xenoserver/control/PartitionManager.java
    1.29  3eb781fdmMkFbyb2SAGR0vsuFtl9Lw tools/control/src/org/xenoserver/control/Settings.java
    1.30  3eb781fdpgi83RpUvQWVccWjsDJK7w tools/control/src/org/xenoserver/control/StringPattern.java
    1.31 +3ec41f7dUPpYTwYL5QVpRBv6PLKPrg tools/control/src/org/xenoserver/control/XML.java
    1.32 +3ec41f7d7Try-2zmfnpaALwJjY0GCA tools/control/src/org/xenoserver/control/XMLHelper.java
    1.33  3ec41f7csVaMDEEUMZBotpSftCy0rg tools/control/src/uk/ac/cam/cl/xeno/xenctl/Extent.java
    1.34  3ec41f7cO5uUI4qZmJ29jsammoZP4Q tools/control/src/uk/ac/cam/cl/xeno/xenctl/Library.java
    1.35  3ec41f7civcv4mQiYK0DeX9Zvsxhrw tools/control/src/uk/ac/cam/cl/xeno/xenctl/Main.java.orig
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/Main.java	Fri Jul 04 10:39:53 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Fri Jul 04 11:21:03 2003 +0000
     2.3 @@ -17,9 +17,19 @@ public class Main {
     2.4        new ParseDomainDestroy(),
     2.5        new ParseDomainList()
     2.6      };
     2.7 +  static final CommandParser partitioncommands[] =
     2.8 +    { new ParsePartitionsList()
     2.9 +    };
    2.10 +  static final CommandParser physicalcommands[] =
    2.11 +    { new ParsePhysicalGrant(),
    2.12 +      new ParsePhysicalRevoke(),
    2.13 +      new ParsePhysicalList()
    2.14 +    };
    2.15    static final CommandParser commands[] =
    2.16      { help,
    2.17 -      new ParseGroup( "domain", domaincommands )
    2.18 +      new ParseGroup( "domain", domaincommands ),
    2.19 +      new ParseGroup( "partitions", partitioncommands ),
    2.20 +      new ParseGroup( "physical", physicalcommands )
    2.21      };
    2.22    static final CommandParser parser = new ParseGroup( null, commands );
    2.23  
     3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseGroup.java	Fri Jul 04 10:39:53 2003 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseGroup.java	Fri Jul 04 11:21:03 2003 +0000
     3.3 @@ -26,7 +26,7 @@ public class ParseGroup extends CommandP
     3.4      String c = (String) args.removeFirst();
     3.5      for (i = 0; i < commands.length; i++) {
     3.6        if (commands[i].getName().equals(c)) {
     3.7 -        if (getFlagParameter(args, '?')) {
     3.8 +        if (!args.isEmpty() && args.getFirst().equals("-?")) {
     3.9            commands[i].printHelpText(null);
    3.10          } else {
    3.11            commands[i].parse(d, args);
    3.12 @@ -44,12 +44,10 @@ public class ParseGroup extends CommandP
    3.13    }
    3.14  
    3.15    public String getUsage() {
    3.16 -    // TODO Auto-generated method stub
    3.17      return null;
    3.18    }
    3.19  
    3.20    public String getHelpText() {
    3.21 -    // TODO Auto-generated method stub
    3.22      return null;
    3.23    }
    3.24  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java	Fri Jul 04 11:21:03 2003 +0000
     4.3 @@ -0,0 +1,57 @@
     4.4 +package org.xenoserver.cmdline;
     4.5 +
     4.6 +import java.util.Iterator;
     4.7 +import java.util.LinkedList;
     4.8 +
     4.9 +import org.xenoserver.control.CommandFailedException;
    4.10 +import org.xenoserver.control.Defaults;
    4.11 +import org.xenoserver.control.Library;
    4.12 +import org.xenoserver.control.Partition;
    4.13 +import org.xenoserver.control.PartitionManager;
    4.14 +import org.xenoserver.control.Settings;
    4.15 +import org.xenoserver.control.XML;
    4.16 +
    4.17 +public class ParsePartitionsList extends CommandParser {
    4.18 +
    4.19 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    4.20 +    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    4.21 +    Iterator i = PartitionManager.it.iterator();
    4.22 +    int idx = 1;
    4.23 +    System.out.println( "     maj:min " + "    blocks " + "start sect " +
    4.24 +                        " num sects " + "name" );
    4.25 +    while (i.hasNext()) {
    4.26 +      Partition p = (Partition) i.next();
    4.27 +
    4.28 +      if (p.getIsXeno()) {
    4.29 +        System.out.print("[ ");
    4.30 +      } else {
    4.31 +        System.out.print("  ");
    4.32 +      }
    4.33 +      System.out.print(Library.format(idx++, 2, 0) + " ");
    4.34 +      System.out.print(Library.format(p.getMajor(),3,0) + ":" + 
    4.35 +          Library.format(p.getMinor(),3,1) + " " +
    4.36 +          Library.format(p.getBlocks(),10,0) + " " +
    4.37 +          Library.format(p.getStartSect(),10,0) + " " +
    4.38 +          Library.format(p.getNumSects(),10,0) + " " +
    4.39 +          Library.format(p.getName(),7,1));   
    4.40 +      if (p.getIsXeno()) {
    4.41 +        System.out.println("]");
    4.42 +      } else {
    4.43 +        System.out.println();
    4.44 +      }
    4.45 +    }
    4.46 +  }
    4.47 +
    4.48 +  public String getName() {
    4.49 +    return "list";
    4.50 +  }
    4.51 +
    4.52 +  public String getUsage() {
    4.53 +    return "";
    4.54 +  }
    4.55 +
    4.56 +  public String getHelpText() {
    4.57 +    return "List real partition information";
    4.58 +  }
    4.59 +
    4.60 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java	Fri Jul 04 11:21:03 2003 +0000
     5.3 @@ -0,0 +1,65 @@
     5.4 +package org.xenoserver.cmdline;
     5.5 +
     5.6 +import java.util.LinkedList;
     5.7 +
     5.8 +import org.xenoserver.control.CommandFailedException;
     5.9 +import org.xenoserver.control.CommandPhysicalGrant;
    5.10 +import org.xenoserver.control.Defaults;
    5.11 +import org.xenoserver.control.Extent;
    5.12 +import org.xenoserver.control.Mode;
    5.13 +import org.xenoserver.control.Partition;
    5.14 +import org.xenoserver.control.PartitionManager;
    5.15 +import org.xenoserver.control.Settings;
    5.16 +import org.xenoserver.control.XML;
    5.17 +
    5.18 +public class ParsePhysicalGrant extends CommandParser {
    5.19 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    5.20 +    int domain_id = getIntParameter(args, 'n', 0);
    5.21 +    boolean force = getFlagParameter(args, 'f');
    5.22 +    String partition_name = getStringParameter(args, 'p', "");
    5.23 +    boolean write = getFlagParameter(args, 'w');
    5.24 +    
    5.25 +    if (domain_id == 0)
    5.26 +      throw new ParseFailedException("Expected -n<domain_id>");
    5.27 +    if (partition_name.equals(""))
    5.28 +      throw new ParseFailedException("Expected -p<partition_name>");
    5.29 +      
    5.30 +    Mode mode;
    5.31 +    if (write)
    5.32 +      mode = Mode.READ_WRITE;
    5.33 +    else
    5.34 +      mode = Mode.READ_ONLY;
    5.35 +      
    5.36 +    // Initialise the partition manager and look up the partition
    5.37 +    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    5.38 +    Partition p = PartitionManager.it.get_partition(partition_name);
    5.39 +    
    5.40 +    if ( p == null )
    5.41 +      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    5.42 +    
    5.43 +    // Check if this partition belongs to the VDM
    5.44 +    if (p.getIsXeno() && !force)
    5.45 +      throw new CommandFailedException("Refusing to grant physical access as the given partition is allocated to the virtual disk manager. Use -f if you are sure.");
    5.46 +     
    5.47 +    // Convert the partition into a physical extent
    5.48 +    Extent e = p.toExtent();
    5.49 +    
    5.50 +    String output = new CommandPhysicalGrant( d, domain_id, e, mode ).execute();
    5.51 +    if ( output != null )
    5.52 +      System.out.println( output );
    5.53 +  }
    5.54 +
    5.55 +  public String getName() {
    5.56 +    return "grant";
    5.57 +  }
    5.58 +
    5.59 +  public String getUsage() {
    5.60 +    return "[-f] [-w] [-n<domain_id>] [-p<partition_name>]";
    5.61 +  }
    5.62 +
    5.63 +  public String getHelpText() {
    5.64 +    return "Grant the specified domain access to the given partition.  -w grants" +
    5.65 +           " read-write instead of read-only.  -f forcibly grants access.";
    5.66 +  }
    5.67 +
    5.68 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java	Fri Jul 04 11:21:03 2003 +0000
     6.3 @@ -0,0 +1,74 @@
     6.4 +package org.xenoserver.cmdline;
     6.5 +
     6.6 +import java.util.Iterator;
     6.7 +import java.util.LinkedList;
     6.8 +import java.util.Map.Entry;
     6.9 +
    6.10 +import org.xenoserver.control.CommandFailedException;
    6.11 +import org.xenoserver.control.CommandPhysicalList;
    6.12 +import org.xenoserver.control.Defaults;
    6.13 +import org.xenoserver.control.Extent;
    6.14 +import org.xenoserver.control.Library;
    6.15 +import org.xenoserver.control.Mode;
    6.16 +import org.xenoserver.control.Partition;
    6.17 +import org.xenoserver.control.PartitionManager;
    6.18 +import org.xenoserver.control.Settings;
    6.19 +import org.xenoserver.control.XML;
    6.20 +
    6.21 +public class ParsePhysicalList extends CommandParser {
    6.22 +
    6.23 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    6.24 +    int domain_id = getIntParameter(args, 'n', 0);
    6.25 +    if (domain_id == 0)
    6.26 +      throw new ParseFailedException("Expected -n<domain_id>");
    6.27 +
    6.28 +    // Initialise the partition manager
    6.29 +    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    6.30 +    
    6.31 +    CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
    6.32 +    String output = list.execute();
    6.33 +    if ( output != null )
    6.34 +      System.out.println( output );
    6.35 +      
    6.36 +    System.out.println( "maj:min " + "    blocks " + "start sect " +
    6.37 +                        " num sects " + "name    " + "access" );
    6.38 +    Iterator i = list.extents().entrySet().iterator();
    6.39 +    while ( i.hasNext() )
    6.40 +    {
    6.41 +      Entry entry = (Entry) i.next(); 
    6.42 +      Extent e = (Extent) entry.getKey();
    6.43 +      String mode = entry.getValue().toString();
    6.44 +      Partition p = PartitionManager.it.get_partition( e );
    6.45 +      if ( p != null ) {
    6.46 +        System.out.println(Library.format(p.getMajor(),3,0) + ":" + 
    6.47 +          Library.format(p.getMinor(),3,1) + " " +
    6.48 +          Library.format(p.getBlocks(),10,0) + " " +
    6.49 +          Library.format(p.getStartSect(),10,0) + " " +
    6.50 +          Library.format(p.getNumSects(),10,0) + " " +
    6.51 +          Library.format(p.getName(),7,1) + " " +
    6.52 +          Library.format(mode,2,1));   
    6.53 +      } else {
    6.54 +        System.out.println(Library.format(e.getMajor(),3,0) + ":" +
    6.55 +          Library.format(e.getMinor(),3,1) + " " +
    6.56 +          "          " + " " +
    6.57 +          Library.format(e.getOffset(),10,0) + " " +
    6.58 +          Library.format(e.getSize(),10,0) + " " +
    6.59 +          "       " + " " +
    6.60 +          Library.format(mode,2,1));
    6.61 +      }
    6.62 +    }
    6.63 +  }
    6.64 +
    6.65 +  public String getName() {
    6.66 +    return "list";
    6.67 +  }
    6.68 +
    6.69 +  public String getUsage() {
    6.70 +    return "[-n<domain_id>]";
    6.71 +  }
    6.72 +
    6.73 +  public String getHelpText() {
    6.74 +    return "List all physical access which the given domain has been granted.";
    6.75 +  }
    6.76 +
    6.77 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java	Fri Jul 04 11:21:03 2003 +0000
     7.3 @@ -0,0 +1,51 @@
     7.4 +package org.xenoserver.cmdline;
     7.5 +
     7.6 +import java.util.LinkedList;
     7.7 +
     7.8 +import org.xenoserver.control.CommandFailedException;
     7.9 +import org.xenoserver.control.CommandPhysicalRevoke;
    7.10 +import org.xenoserver.control.Defaults;
    7.11 +import org.xenoserver.control.Extent;
    7.12 +import org.xenoserver.control.Partition;
    7.13 +import org.xenoserver.control.PartitionManager;
    7.14 +import org.xenoserver.control.Settings;
    7.15 +import org.xenoserver.control.XML;
    7.16 +
    7.17 +public class ParsePhysicalRevoke extends CommandParser {
    7.18 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    7.19 +    int domain_id = getIntParameter(args, 'n', 0);
    7.20 +    String partition_name = getStringParameter(args, 'p', "");
    7.21 +    
    7.22 +    if (domain_id == 0)
    7.23 +      throw new ParseFailedException("Expected -n<domain_id>");
    7.24 +    if (partition_name.equals(""))
    7.25 +      throw new ParseFailedException("Expected -p<partition_name>");
    7.26 +      
    7.27 +    // Initialise the partition manager and look up the partition
    7.28 +    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    7.29 +    Partition p = PartitionManager.it.get_partition(partition_name);
    7.30 +    
    7.31 +    if ( p == null )
    7.32 +      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    7.33 +
    7.34 +    // Convert the partition into a physical extent
    7.35 +    Extent e = p.toExtent();
    7.36 +    
    7.37 +    String output = new CommandPhysicalRevoke( d, domain_id, e ).execute();
    7.38 +    if ( output != null )
    7.39 +      System.out.println( output );
    7.40 +  }
    7.41 +
    7.42 +  public String getName() {
    7.43 +    return "revoke";
    7.44 +  }
    7.45 +
    7.46 +  public String getUsage() {
    7.47 +    return "[-n<domain_id>] [-p<partition_name>]";
    7.48 +  }
    7.49 +
    7.50 +  public String getHelpText() {
    7.51 +    return "Revoke access to the given partition from the specified domain.";
    7.52 +  }
    7.53 +
    7.54 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java	Fri Jul 04 11:21:03 2003 +0000
     8.3 @@ -0,0 +1,66 @@
     8.4 +package org.xenoserver.control;
     8.5 +
     8.6 +public class CommandPhysicalGrant extends Command {
     8.7 +  private Defaults d;
     8.8 +  private int domain_id;
     8.9 +  private Extent extent;
    8.10 +  private Mode mode;
    8.11 +
    8.12 +  /**
    8.13 +   * Constructor for CommandPhysicalGrant.
    8.14 +   * @param d Defaults object to use.
    8.15 +   * @param domain_id Domain to grant access for.
    8.16 +   * @param extent Extent to grant access to.
    8.17 +   * @param mode Access mode to grant.
    8.18 +   */
    8.19 +  public CommandPhysicalGrant(
    8.20 +    Defaults d,
    8.21 +    int domain_id,
    8.22 +    Extent extent,
    8.23 +    Mode mode) {
    8.24 +    this.d = d;
    8.25 +    this.domain_id = domain_id;
    8.26 +    this.extent = extent;
    8.27 +    this.mode = mode;
    8.28 +  }
    8.29 +
    8.30 +  public String execute() throws CommandFailedException {
    8.31 +    Runtime r = Runtime.getRuntime();
    8.32 +    String output = null;
    8.33 +
    8.34 +    try {
    8.35 +      Process start_p;
    8.36 +      String start_cmdarray[] = new String[6];
    8.37 +      int start_rc;
    8.38 +      start_cmdarray[0] = d.XIToolsDir + "xi_phys_grant";
    8.39 +      if ( mode == Mode.READ_WRITE )
    8.40 +        start_cmdarray[1] = "rw";
    8.41 +      else if ( mode == Mode.READ_ONLY )
    8.42 +        start_cmdarray[1] = "ro";
    8.43 +      else
    8.44 +        throw new CommandFailedException( "Unknown access mode '" + mode + "'" );
    8.45 +      start_cmdarray[2] = Integer.toString( domain_id );
    8.46 +      start_cmdarray[3] = Short.toString( extent.getDisk() );
    8.47 +      start_cmdarray[4] = Long.toString( extent.getOffset() );
    8.48 +      start_cmdarray[5] = Long.toString( extent.getSize() );
    8.49 +
    8.50 +      if (Settings.TEST) {
    8.51 +        output = reportCommand(start_cmdarray);
    8.52 +      } else {
    8.53 +        start_p = r.exec(start_cmdarray);
    8.54 +        start_rc = start_p.waitFor();
    8.55 +        if (start_rc != 0) {
    8.56 +          throw CommandFailedException.XICommandFailed("Could not grant physical access", start_cmdarray);
    8.57 +        }
    8.58 +        output = "Granted physical access to domain " + domain_id;
    8.59 +      }
    8.60 +    } catch (CommandFailedException e) {
    8.61 +      throw e;
    8.62 +    } catch (Exception e) {
    8.63 +      throw new CommandFailedException("Could not grant physical access (" + e + ")", e);
    8.64 +    }
    8.65 +
    8.66 +    return output;
    8.67 +  }
    8.68 +
    8.69 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java	Fri Jul 04 11:21:03 2003 +0000
     9.3 @@ -0,0 +1,98 @@
     9.4 +package org.xenoserver.control;
     9.5 +
     9.6 +import java.io.BufferedReader;
     9.7 +import java.io.InputStreamReader;
     9.8 +import java.util.HashMap;
     9.9 +import java.util.Map;
    9.10 +import java.util.StringTokenizer;
    9.11 +
    9.12 +/**
    9.13 + * Lists details of all extents the given domain has access to.
    9.14 + * After execute() has been called, call extents() to get the map of extents
    9.15 + * to modes.
    9.16 + */
    9.17 +public class CommandPhysicalList extends Command {
    9.18 +  private int domain_id;
    9.19 +  private Defaults d;
    9.20 +  private Map map = new HashMap();
    9.21 +
    9.22 +  /**
    9.23 +   * Constructor for CommandDomainList.
    9.24 +   * @param d Defaults object to use.
    9.25 +   */
    9.26 +  public CommandPhysicalList(Defaults d, int domain_id) {
    9.27 +    this.d = d;
    9.28 +    this.domain_id = domain_id;
    9.29 +  }
    9.30 +
    9.31 +  /**
    9.32 +   * Retrieves the list of extents.
    9.33 +   * @return null, call extents() to get the list.
    9.34 +   */
    9.35 +  public String execute() throws CommandFailedException {
    9.36 +    Runtime r = Runtime.getRuntime();
    9.37 +    int rc = 0;
    9.38 +    String outline;
    9.39 +    BufferedReader in;
    9.40 +    String output = null;
    9.41 +
    9.42 +    try {
    9.43 +      Process start_p;
    9.44 +      String start_cmdarray[] = new String[2];
    9.45 +      int start_rc;
    9.46 +      start_cmdarray[0] = d.XIToolsDir + "xi_phys_probe";
    9.47 +      start_cmdarray[1] = Integer.toString( domain_id );
    9.48 +
    9.49 +      if (Settings.TEST) {
    9.50 +        output = reportCommand(start_cmdarray);
    9.51 +      } else {
    9.52 +        start_p = r.exec(start_cmdarray);
    9.53 +        start_rc = start_p.waitFor();
    9.54 +        if (start_rc != 0) {
    9.55 +          throw CommandFailedException.XICommandFailed("Could not get extent list", start_cmdarray);
    9.56 +        }
    9.57 +
    9.58 +        in =
    9.59 +          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
    9.60 +
    9.61 +        outline = in.readLine();
    9.62 +        while (outline != null) {
    9.63 +          Extent extent = new Extent();
    9.64 +
    9.65 +          StringTokenizer st = new StringTokenizer(outline);
    9.66 +          if (st.hasMoreTokens()) {
    9.67 +            extent.disk = Short.parseShort(st.nextToken(),16);
    9.68 +          }
    9.69 +          if (st.hasMoreTokens()) {
    9.70 +            extent.offset = Long.parseLong(st.nextToken(),16);
    9.71 +          }
    9.72 +          if (st.hasMoreTokens()) {
    9.73 +            extent.size = Long.parseLong(st.nextToken(),16);
    9.74 +          }
    9.75 +          if (st.hasMoreTokens()) {
    9.76 +            String mode = st.nextToken();
    9.77 +            if ( mode.equals( "rw" ) )
    9.78 +              map.put( extent, Mode.READ_WRITE );
    9.79 +            else if ( mode.equals ( "r" ) )
    9.80 +              map.put( extent, Mode.READ_ONLY );
    9.81 +            else
    9.82 +              throw new CommandFailedException("Could not parse access mode " + mode);
    9.83 +          }
    9.84 +
    9.85 +          outline = in.readLine();
    9.86 +        }
    9.87 +
    9.88 +      }
    9.89 +    } catch (CommandFailedException e) {
    9.90 +      throw e;
    9.91 +    } catch (Exception e) {
    9.92 +      throw new CommandFailedException("Could not get extent list(" + e + ")", e);
    9.93 +    }
    9.94 +
    9.95 +    return output;
    9.96 +  }
    9.97 +  
    9.98 +  public Map extents() {
    9.99 +    return map;
   9.100 +  }
   9.101 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java	Fri Jul 04 11:21:03 2003 +0000
    10.3 @@ -0,0 +1,56 @@
    10.4 +package org.xenoserver.control;
    10.5 +
    10.6 +public class CommandPhysicalRevoke extends Command {
    10.7 +  private Defaults d;
    10.8 +  private int domain_id;
    10.9 +  private Extent extent;
   10.10 +
   10.11 +  /**
   10.12 +   * Constructor for CommandPhysicalRevoke.
   10.13 +   * @param d Defaults object to use.
   10.14 +   * @param domain_id Domain to revoke access from.
   10.15 +   * @param extent Extent to revoke access from.
   10.16 +   */
   10.17 +  public CommandPhysicalRevoke(
   10.18 +    Defaults d,
   10.19 +    int domain_id,
   10.20 +    Extent extent) {
   10.21 +    this.d = d;
   10.22 +    this.domain_id = domain_id;
   10.23 +    this.extent = extent;
   10.24 +  }
   10.25 +
   10.26 +  public String execute() throws CommandFailedException {
   10.27 +    Runtime r = Runtime.getRuntime();
   10.28 +    String output = null;
   10.29 +
   10.30 +    try {
   10.31 +      Process start_p;
   10.32 +      String start_cmdarray[] = new String[5];
   10.33 +      int start_rc;
   10.34 +      start_cmdarray[0] = d.XIToolsDir + "xi_phys_revoke";
   10.35 +      start_cmdarray[1] = Integer.toString( domain_id );
   10.36 +      start_cmdarray[2] = Short.toString( extent.getDisk() );
   10.37 +      start_cmdarray[3] = Long.toString( extent.getOffset() );
   10.38 +      start_cmdarray[4] = Long.toString( extent.getSize() );
   10.39 +
   10.40 +      if (Settings.TEST) {
   10.41 +        output = reportCommand(start_cmdarray);
   10.42 +      } else {
   10.43 +        start_p = r.exec(start_cmdarray);
   10.44 +        start_rc = start_p.waitFor();
   10.45 +        if (start_rc != 0) {
   10.46 +          throw CommandFailedException.XICommandFailed("Could not revoke physical access", start_cmdarray);
   10.47 +        }
   10.48 +        output = "Revoked physical access from domain " + domain_id;
   10.49 +      }
   10.50 +    } catch (CommandFailedException e) {
   10.51 +      throw e;
   10.52 +    } catch (Exception e) {
   10.53 +      throw new CommandFailedException("Could not revoke physical access (" + e + ")", e);
   10.54 +    }
   10.55 +
   10.56 +    return output;
   10.57 +  }
   10.58 +
   10.59 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/control/Extent.java	Fri Jul 04 11:21:03 2003 +0000
    11.3 @@ -0,0 +1,87 @@
    11.4 +/*
    11.5 + * Extent.java
    11.6 + * 03.03.26 aho creation
    11.7 + */
    11.8 +
    11.9 +package org.xenoserver.control;
   11.10 +
   11.11 +public class
   11.12 +Extent
   11.13 +{
   11.14 +  short disk;
   11.15 +  long offset;                                           /* offset into disk */
   11.16 +  long size;                      /* size of this extent in 512 byte sectors */
   11.17 +
   11.18 +  public short
   11.19 +  getDisk()
   11.20 +  {
   11.21 +    return disk;
   11.22 +  }
   11.23 +
   11.24 +  public long
   11.25 +  getOffset()
   11.26 +  {
   11.27 +    return offset;
   11.28 +  }
   11.29 +
   11.30 +  public long
   11.31 +  getSize()
   11.32 +  {
   11.33 +    return size;
   11.34 +  }
   11.35 +  
   11.36 +  public int
   11.37 +  getMajor()
   11.38 +  {
   11.39 +    return disk >> 8;
   11.40 +  }
   11.41 +  
   11.42 +  public int
   11.43 +  getMinor()
   11.44 +  {
   11.45 +    return disk & 0xFF;
   11.46 +  }
   11.47 +  
   11.48 +  public int hashCode() {
   11.49 +    final int PRIME = 1000003;
   11.50 +    int result = 0;
   11.51 +    result = PRIME * result + disk;
   11.52 +    result = PRIME * result + (int) (offset >>> 32);
   11.53 +    result = PRIME * result + (int) (offset & 0xFFFFFFFF);
   11.54 +    result = PRIME * result + (int) (size >>> 32);
   11.55 +    result = PRIME * result + (int) (size & 0xFFFFFFFF);
   11.56 +
   11.57 +    return result;
   11.58 +  }
   11.59 +
   11.60 +  public boolean equals(Object oth) {
   11.61 +    if (this == oth) {
   11.62 +      return true;
   11.63 +    }
   11.64 +
   11.65 +    if (oth == null) {
   11.66 +      return false;
   11.67 +    }
   11.68 +
   11.69 +    if (oth.getClass() != getClass()) {
   11.70 +      return false;
   11.71 +    }
   11.72 +
   11.73 +    Extent other = (Extent) oth;
   11.74 +
   11.75 +    if (this.disk != other.disk) {
   11.76 +      return false;
   11.77 +    }
   11.78 +
   11.79 +    if (this.offset != other.offset) {
   11.80 +      return false;
   11.81 +    }
   11.82 +
   11.83 +    if (this.size != other.size) {
   11.84 +      return false;
   11.85 +    }
   11.86 +
   11.87 +    return true;
   11.88 +  }
   11.89 +
   11.90 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/control/src/org/xenoserver/control/Library.java	Fri Jul 04 11:21:03 2003 +0000
    12.3 @@ -0,0 +1,129 @@
    12.4 +/*
    12.5 + * Library.java
    12.6 + * 03.03.28 aho creation
    12.7 + */
    12.8 +
    12.9 +package org.xenoserver.control;
   12.10 +
   12.11 +public class
   12.12 +Library
   12.13 +{
   12.14 +  /*
   12.15 +   * convert a number to a fixed width string
   12.16 +   */
   12.17 +  public static String
   12.18 +  format (long input, int width, int prefix)
   12.19 +  {
   12.20 +    String sss = Long.toString(input);
   12.21 +    String space = "                                ";
   12.22 +
   12.23 +    if (width < sss.length())
   12.24 +    {
   12.25 +      width = sss.length();
   12.26 +    }
   12.27 +
   12.28 +    if (prefix == 0)
   12.29 +    {
   12.30 +      return space.substring(0, width - sss.length()) + sss;
   12.31 +    }
   12.32 +    else
   12.33 +    {
   12.34 +      return sss + space.substring(0, width - sss.length());
   12.35 +    }
   12.36 +  }
   12.37 +
   12.38 +  /*
   12.39 +   * convert a string to a fixed width string
   12.40 +   */
   12.41 +  public static String
   12.42 +  format (String input, int width, int prefix)
   12.43 +  {
   12.44 +    String space = "                                ";
   12.45 +
   12.46 +    if (width < input.length())
   12.47 +    {
   12.48 +      width = input.length();
   12.49 +    }
   12.50 +
   12.51 +    if (prefix == 0)
   12.52 +    {
   12.53 +      return space.substring(0, width - input.length()) + input;
   12.54 +    }
   12.55 +    else
   12.56 +    {
   12.57 +      return input + space.substring(0, width - input.length());
   12.58 +    }
   12.59 +  }
   12.60 +
   12.61 +  /*
   12.62 +   * convert a number (string format) into 
   12.63 +   * the corresponding integer value.
   12.64 +   */
   12.65 +  public static long
   12.66 +  parse_size(String size)
   12.67 +  {
   12.68 +    String substring = size;
   12.69 +    int    suffix = 1;
   12.70 +    long   value = 0;
   12.71 +
   12.72 +    if (size == null)
   12.73 +    {
   12.74 +      return 0;
   12.75 +    }
   12.76 +
   12.77 +    if ((substring = check(size, 'm')) != null)
   12.78 +    {
   12.79 +      suffix = 1024 * 1024;
   12.80 +    }
   12.81 +    else if ((substring = check(size, 'M')) != null)
   12.82 +    {
   12.83 +      suffix = 1024 * 1024;
   12.84 +    }
   12.85 +    else if ((substring = check(size, 'k')) != null)
   12.86 +    {
   12.87 +      suffix = 1024;
   12.88 +    }
   12.89 +    else if ((substring = check(size, 'K')) != null)
   12.90 +    {
   12.91 +      suffix = 1024;
   12.92 +    }
   12.93 +    else if ((substring = check(size, 'g')) != null)
   12.94 +    {
   12.95 +      suffix = 1024 * 1024 * 1024;
   12.96 +    }
   12.97 +    else if ((substring = check(size, 'G')) != null)
   12.98 +    {
   12.99 +      suffix = 1024 * 1024 * 1024;
  12.100 +    }
  12.101 +    else
  12.102 +    {
  12.103 +      substring = size;
  12.104 +    }
  12.105 +
  12.106 +    try
  12.107 +    {
  12.108 +      value = Long.decode(substring).longValue() * suffix;
  12.109 +    }
  12.110 +    catch (NumberFormatException e)
  12.111 +    {
  12.112 +      value = 0;
  12.113 +    }
  12.114 +
  12.115 +    return value;
  12.116 +  }
  12.117 +
  12.118 +  public static String
  12.119 +  check(String size, char suffix)
  12.120 +  {
  12.121 +    int index = size.indexOf(suffix);
  12.122 +
  12.123 +    if (index != -1)
  12.124 +    {
  12.125 +      return size.substring(0, index);
  12.126 +    }
  12.127 +    else
  12.128 +    {
  12.129 +      return null;
  12.130 +    }
  12.131 +  }
  12.132 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/control/src/org/xenoserver/control/Mode.java	Fri Jul 04 11:21:03 2003 +0000
    13.3 @@ -0,0 +1,22 @@
    13.4 +/*
    13.5 + * Mode.java
    13.6 + * 03.03.27 aho creation
    13.7 + *
    13.8 + * until we have jdk1.5, we're left with this mess...
    13.9 + */
   13.10 +
   13.11 +package org.xenoserver.control;
   13.12 +
   13.13 +public class 
   13.14 +Mode 
   13.15 +{
   13.16 +  private final String name;
   13.17 +
   13.18 +  private Mode(String name) { this.name = name; }
   13.19 +
   13.20 +  public String toString()  { return name; }
   13.21 +
   13.22 +  public static final Mode READ_ONLY  = new Mode("ro");
   13.23 +  public static final Mode READ_WRITE = new Mode("rw");
   13.24 +}
   13.25 +
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java	Fri Jul 04 11:21:03 2003 +0000
    14.3 @@ -0,0 +1,191 @@
    14.4 +/*
    14.5 + * Partition.java
    14.6 + * 03.03.26 aho creation
    14.7 + */
    14.8 +
    14.9 +package org.xenoserver.control;
   14.10 +
   14.11 +import java.io.*;
   14.12 +
   14.13 +public class
   14.14 +Partition
   14.15 +{
   14.16 +  int major;
   14.17 +  int minor;
   14.18 +  long blocks;
   14.19 +  long start_sect;
   14.20 +  long nr_sects;
   14.21 +  String name;
   14.22 +  boolean xeno;
   14.23 +
   14.24 +  Partition
   14.25 +  duplicate ()
   14.26 +  {
   14.27 +    Partition p = new Partition();
   14.28 +
   14.29 +    p.major = major;
   14.30 +    p.minor = minor;
   14.31 +    p.blocks = blocks;
   14.32 +    p.start_sect = start_sect;
   14.33 +    p.nr_sects = nr_sects;
   14.34 +    p.name = name;
   14.35 +    p.xeno = xeno;
   14.36 +
   14.37 +    return p;
   14.38 +  }
   14.39 +
   14.40 +  void
   14.41 +  dump_xml(PrintWriter out)
   14.42 +  {
   14.43 +    out.println ("  <partition>\n" +
   14.44 +		 "    <major>" + major + "</major>\n" +
   14.45 +		 "    <minor>" + minor + "</minor>\n" +
   14.46 +		 "    <blocks>" + blocks + "</blocks>\n" +
   14.47 +		 "    <start_sect>" + start_sect + "</start_sect>\n" +
   14.48 +		 "    <nr_sects>" + nr_sects + "</nr_sects>\n" +
   14.49 +		 "    <name>" + name + "</name>\n" +
   14.50 +		 "  </partition>");
   14.51 +  }
   14.52 +
   14.53 +  public int
   14.54 +  getMajor()
   14.55 +  {
   14.56 +    return major;
   14.57 +  }
   14.58 +
   14.59 +  public int
   14.60 +  getMinor()
   14.61 +  {
   14.62 +    return minor;
   14.63 +  }
   14.64 +
   14.65 +  public long
   14.66 +  getBlocks()
   14.67 +  {
   14.68 +    return blocks;
   14.69 +  }
   14.70 +  
   14.71 +  public long
   14.72 +  getStartSect()
   14.73 +  {
   14.74 +    return start_sect;
   14.75 +  }
   14.76 +
   14.77 +  public long
   14.78 +  getNumSects()
   14.79 +  {
   14.80 +    return nr_sects;
   14.81 +  }
   14.82 +  
   14.83 +  public String
   14.84 +  getName()
   14.85 +  {
   14.86 +    return name;
   14.87 +  }
   14.88 +
   14.89 +  public boolean
   14.90 +  getIsXeno()
   14.91 +  {
   14.92 +    return xeno;
   14.93 +  }
   14.94 +
   14.95 +  public int hashCode() {
   14.96 +    final int PRIME = 1000003;
   14.97 +    int result = 0;
   14.98 +    result = PRIME * result + major;
   14.99 +    result = PRIME * result + minor;
  14.100 +    result = PRIME * result + (int) (blocks >>> 32);
  14.101 +    result = PRIME * result + (int) (blocks & 0xFFFFFFFF);
  14.102 +    result = PRIME * result + (int) (start_sect >>> 32);
  14.103 +    result = PRIME * result + (int) (start_sect & 0xFFFFFFFF);
  14.104 +    result = PRIME * result + (int) (nr_sects >>> 32);
  14.105 +    result = PRIME * result + (int) (nr_sects & 0xFFFFFFFF);
  14.106 +    if (name != null) {
  14.107 +      result = PRIME * result + name.hashCode();
  14.108 +    }
  14.109 +
  14.110 +    return result;
  14.111 +  }
  14.112 +
  14.113 +  public boolean equals(Object oth) {
  14.114 +    if (this == oth) {
  14.115 +      return true;
  14.116 +    }
  14.117 +
  14.118 +    if (oth == null) {
  14.119 +      return false;
  14.120 +    }
  14.121 +
  14.122 +    if (oth.getClass() != getClass()) {
  14.123 +      return false;
  14.124 +    }
  14.125 +
  14.126 +    Partition other = (Partition) oth;
  14.127 +
  14.128 +    if (this.major != other.major) {
  14.129 +      return false;
  14.130 +    }
  14.131 +
  14.132 +    if (this.minor != other.minor) {
  14.133 +      return false;
  14.134 +    }
  14.135 +
  14.136 +    if (this.blocks != other.blocks) {
  14.137 +      return false;
  14.138 +    }
  14.139 +
  14.140 +    if (this.start_sect != other.start_sect) {
  14.141 +      return false;
  14.142 +    }
  14.143 +
  14.144 +    if (this.nr_sects != other.nr_sects) {
  14.145 +      return false;
  14.146 +    }
  14.147 +    if (this.name == null) {
  14.148 +      if (other.name != null) {
  14.149 +        return false;
  14.150 +      }
  14.151 +    } else {
  14.152 +      if (!this.name.equals(other.name)) {
  14.153 +        return false;
  14.154 +      }
  14.155 +    }
  14.156 +
  14.157 +    return true;
  14.158 +  }
  14.159 +
  14.160 +  /**
  14.161 +   * @return An Extent covering this partiton.
  14.162 +   */
  14.163 +  public Extent toExtent()
  14.164 +  {
  14.165 +    Extent e = new Extent();
  14.166 +    // Build 16-bit disk number.. high 8 bits are the major
  14.167 +    int disknum = major << 8;
  14.168 +    // Low 8 bits are the minor, but bottom 5 need to be cleared
  14.169 +    // as they are the partition number, not the disk number
  14.170 +    disknum |= ( minor & 0xE0 );
  14.171 +    e.disk = (short) disknum;
  14.172 +    e.offset = start_sect;
  14.173 +    e.size = nr_sects;
  14.174 +    return e;
  14.175 +  }
  14.176 +  
  14.177 +  /**
  14.178 +   * @param e Extent to compare this partition to.
  14.179 +   * @return True if this partition covers the same disk area as the given extent.
  14.180 +   */
  14.181 +  public boolean matchesExtent( Extent e )
  14.182 +  {
  14.183 +    if ( e.getMajor() != major )
  14.184 +      return false;
  14.185 +    if ( e.getMinor() != (minor & 0xE0) )
  14.186 +      return false;
  14.187 +    if ( e.offset != start_sect )
  14.188 +      return false;
  14.189 +    if ( e.size != nr_sects )
  14.190 +      return false;
  14.191 +      
  14.192 +    return true;
  14.193 +  }
  14.194 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/control/src/org/xenoserver/control/PartitionManager.java	Fri Jul 04 11:21:03 2003 +0000
    15.3 @@ -0,0 +1,185 @@
    15.4 +/*
    15.5 + * PartitionManager.java
    15.6 + * 03.03.26 aho creation
    15.7 + */
    15.8 +
    15.9 +package org.xenoserver.control;
   15.10 +
   15.11 +import java.io.*;
   15.12 +import java.util.Iterator;
   15.13 +import java.util.Vector;
   15.14 +import java.util.Enumeration;
   15.15 +
   15.16 +/**
   15.17 + * PartitionManager manages the partitions on the machine. It is a Singleton
   15.18 + * which automatically initialises itself on first class reference.
   15.19 + */
   15.20 +public class
   15.21 +PartitionManager
   15.22 +{
   15.23 +  static final String proc_template =
   15.24 +    "major minor  #blocks  start_sect   nr_sects name";
   15.25 +    
   15.26 +  public static final PartitionManager it = new PartitionManager(Settings.PARTITIONS_FILE);
   15.27 +    
   15.28 +  Vector partition_map;
   15.29 +
   15.30 +  /*
   15.31 +   * Initialize partition manager with source file.
   15.32 +   * Normally we read from /proc/partitions, but we can
   15.33 +   * specify an alternative file for debugging
   15.34 +   */
   15.35 +  private PartitionManager (String filename)
   15.36 +  {
   15.37 +    String str;
   15.38 +    BufferedReader in;
   15.39 +
   15.40 +    partition_map = new Vector(100,10);
   15.41 +
   15.42 +    try
   15.43 +    {
   15.44 +      in = new BufferedReader(new FileReader(filename));
   15.45 +
   15.46 +      str = in.readLine();                                  /* skip headings */
   15.47 +      if (str.length() < proc_template.length() ||
   15.48 +	  !str.substring(0, proc_template.length()).equals(proc_template))
   15.49 +      {
   15.50 +	System.err.println ("Error: Incorrect /proc/partitions.");
   15.51 +	System.err.println ("       Is this Xeno?");
   15.52 +	System.exit (1);
   15.53 +      }
   15.54 +
   15.55 +      str = in.readLine();                                /* skip blank line */
   15.56 +
   15.57 +      str = in.readLine();
   15.58 +      while (str != null)
   15.59 +      {
   15.60 +	Partition partition = new Partition();
   15.61 +
   15.62 +	partition.major = Integer.parseInt(str.substring(0,5).trim());
   15.63 +	partition.minor = Integer.parseInt(str.substring(5,10).trim());
   15.64 +	partition.blocks = Integer.parseInt(str.substring(10,21).trim());
   15.65 +	partition.start_sect = Integer.parseInt(str.substring(21,32).trim());
   15.66 +	partition.nr_sects = Integer.parseInt(str.substring(32,43).trim());
   15.67 +	partition.name = str.substring(43).trim();
   15.68 +	partition.xeno = false;
   15.69 +
   15.70 +	partition_map.add(partition);
   15.71 +	str = in.readLine();
   15.72 +      }
   15.73 +    }
   15.74 +    catch (IOException io)
   15.75 +    {
   15.76 +      System.err.println ("PartitionManager: error reading partition file [" 
   15.77 +			  + filename + "]");
   15.78 +      System.err.println (io);
   15.79 +    }
   15.80 +  }
   15.81 +
   15.82 +  public Partition
   15.83 +  get_partition (String name)
   15.84 +  {
   15.85 +    Partition partition = null;
   15.86 +    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
   15.87 +    {
   15.88 +      partition = (Partition) e.nextElement();
   15.89 +      if (partition.name.equals(name))
   15.90 +      {
   15.91 +  return partition;
   15.92 +      }
   15.93 +    }
   15.94 +    return null;
   15.95 +  }
   15.96 +
   15.97 +  /**
   15.98 +   * Finds the partition that matches the given extent, if any.
   15.99 +   * @param extent The extent to compare to.
  15.100 +   * @return The first matching partition, or null if none.
  15.101 +   */
  15.102 +  public Partition
  15.103 +  get_partition (Extent extent)
  15.104 +  {
  15.105 +    Partition partition = null;
  15.106 +    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
  15.107 +    {
  15.108 +      partition = (Partition) e.nextElement();
  15.109 +      if (partition.matchesExtent(extent))
  15.110 +      {
  15.111 +  return partition;
  15.112 +      }
  15.113 +    }
  15.114 +    return null;
  15.115 +  }
  15.116 +
  15.117 +  Partition
  15.118 +  get_partition (int index)
  15.119 +  {
  15.120 +    return (Partition) partition_map.get(index);
  15.121 +  }
  15.122 +
  15.123 +  void
  15.124 +  add_xeno_partition (Partition p)
  15.125 +  {
  15.126 +    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
  15.127 +    {
  15.128 +      Partition partition = (Partition) e.nextElement();
  15.129 +      if (partition.equals(p))
  15.130 +      {
  15.131 +	partition.xeno = true;
  15.132 +      }
  15.133 +    }
  15.134 +  }
  15.135 +
  15.136 +  /*
  15.137 +   * dump the xeno partition list as xml
  15.138 +   */
  15.139 +  void
  15.140 +  dump_xml (PrintWriter out)
  15.141 +  {
  15.142 +    int loop;
  15.143 +
  15.144 +    out.println("<partitions>");
  15.145 +    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
  15.146 +    {
  15.147 +      Partition partition = (Partition) e.nextElement();
  15.148 +      if (partition.xeno == true)
  15.149 +      {
  15.150 +	partition.dump_xml(out);
  15.151 +      }
  15.152 +    }
  15.153 +
  15.154 +    out.println("</partitions>");
  15.155 +
  15.156 +    return;
  15.157 +  }
  15.158 +
  15.159 +  /**
  15.160 +   * get the number of partitions 
  15.161 +   */
  15.162 +
  15.163 +  int
  15.164 +  getPartitionCount ()
  15.165 +  {
  15.166 +    return partition_map.size();
  15.167 +  }
  15.168 +
  15.169 +  /**
  15.170 +   * get the details about a particular partition
  15.171 +   *
  15.172 +   */
  15.173 +  Partition
  15.174 +  getPartition (int index)
  15.175 +  {
  15.176 +    Partition partition = (Partition) partition_map.get(index);
  15.177 +    return partition;
  15.178 +  }
  15.179 + 
  15.180 +  /**
  15.181 +   * Get an iterator over all the partitions.
  15.182 +   * @return An iterator over Partition objects.
  15.183 +   */
  15.184 +  public Iterator iterator()
  15.185 +  {
  15.186 +    return partition_map.iterator();
  15.187 +  }
  15.188 +}
    16.1 --- a/tools/control/src/org/xenoserver/control/Settings.java	Fri Jul 04 10:39:53 2003 +0000
    16.2 +++ b/tools/control/src/org/xenoserver/control/Settings.java	Fri Jul 04 11:21:03 2003 +0000
    16.3 @@ -16,7 +16,9 @@ public final class Settings
    16.4    public static final String LOCAL_GW = System.getProperty ("LOCAL_ROUTE");
    16.5    public static final boolean TEST = (System.getProperty ("TEST") != null);
    16.6    public static final String XI_HELPER = System.getProperty ("XI_HELPER", "xi_helper");
    16.7 -
    16.8 +  public static final String PARTITIONS_FILE = System.getProperty("PARTITIONS_FILE", "/proc/partitions");
    16.9 +  public static final String STATE_INPUT_FILE = System.getProperty("STATE_INPUT_FILE", "/var/lib/xen/vdstate.xml");
   16.10 +  public static final String STATE_OUTPUT_FILE = System.getProperty("STATE_OUTPUT_FILE", "/var/lib/xen/vdstate.xml");
   16.11  
   16.12    public static File getDefaultsFile() {
   16.13      StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":");
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/control/src/org/xenoserver/control/XML.java	Fri Jul 04 11:21:03 2003 +0000
    17.3 @@ -0,0 +1,125 @@
    17.4 +/*
    17.5 + * XML.java
    17.6 + * 03.03.26 aho creation
    17.7 + */
    17.8 +
    17.9 +package org.xenoserver.control;
   17.10 +
   17.11 +import java.io.BufferedWriter;
   17.12 +import java.io.File;
   17.13 +import java.io.FileNotFoundException;
   17.14 +import java.io.FileWriter;
   17.15 +import java.io.IOException;
   17.16 +import java.io.PrintWriter;
   17.17 +
   17.18 +import javax.xml.parsers.DocumentBuilder;
   17.19 +import javax.xml.parsers.DocumentBuilderFactory;
   17.20 +import javax.xml.parsers.ParserConfigurationException;
   17.21 +
   17.22 +import org.w3c.dom.Document;
   17.23 +import org.xml.sax.SAXException;
   17.24 +import org.xml.sax.SAXParseException;
   17.25 + 
   17.26 +public class
   17.27 +XML
   17.28 +{
   17.29 +  static Document document = null;
   17.30 +
   17.31 +  /*
   17.32 +   * dump partition manager and virtual disk manager state to filename
   17.33 +   */
   17.34 +
   17.35 +  public static void
   17.36 +  dump_state (PartitionManager pm,/* VirtualDiskManager vdm,*/ String filename)
   17.37 +  {
   17.38 +    PrintWriter out;
   17.39 +
   17.40 +    try
   17.41 +    {
   17.42 +      out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
   17.43 +    }
   17.44 +    catch (IOException e)
   17.45 +    {
   17.46 +      System.err.println ("XML.dump_state error [" + filename + "]");
   17.47 +      System.err.println (e);
   17.48 +      return;
   17.49 +    }
   17.50 +
   17.51 +    out.println("<?xml version=\"1.0\"?>");
   17.52 +    out.println("<vdmanager>");
   17.53 +    pm.dump_xml(out);
   17.54 +    //vdm.dump_xml(out);
   17.55 +    out.println("</vdmanager>");
   17.56 +
   17.57 +    out.close();
   17.58 +    return;
   17.59 +  }
   17.60 +
   17.61 +  /*
   17.62 +   * load partition manager and virtual disk manager state from filename
   17.63 +   */
   17.64 +  public static void
   17.65 +  load_state (PartitionManager pm, /*VirtualDiskManager vdm,*/ String filename)
   17.66 +  {
   17.67 +    if (document == null)
   17.68 +    {
   17.69 +      load_file (filename);
   17.70 +    }
   17.71 +
   17.72 +    XMLHelper.parse(pm, /*vdm,*/ document);
   17.73 +  }
   17.74 +
   17.75 +  /*
   17.76 +   * load XML from disk
   17.77 +   */
   17.78 +  static void
   17.79 +  load_file (String filename)
   17.80 +  {
   17.81 +    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   17.82 +    // factory.setNamespaceAware(true);
   17.83 +    // factory.setValidating(true);
   17.84 +
   17.85 +    try
   17.86 +    {
   17.87 +      File file = new File(filename);
   17.88 +
   17.89 +      DocumentBuilder builder = factory.newDocumentBuilder();
   17.90 +      document = builder.parse(file);
   17.91 +    }
   17.92 +    catch (SAXParseException spe)               /* error generated by parser */
   17.93 +    {
   17.94 +      System.err.println ("xml parser exception on line " + 
   17.95 +			  spe.getLineNumber() + 
   17.96 +			  " for uri " + spe.getSystemId());
   17.97 +      System.err.println (spe.getMessage());
   17.98 +
   17.99 +      Exception x = spe;
  17.100 +      if (spe.getException() != null)
  17.101 +	x = spe.getException();
  17.102 +      x.printStackTrace();
  17.103 +      System.exit(1);
  17.104 +    }
  17.105 +    catch (SAXException sxe)
  17.106 +    {
  17.107 +      Exception e = sxe;
  17.108 +      if (sxe.getException() != null)
  17.109 +	e = sxe.getException();
  17.110 +      e.printStackTrace();
  17.111 +      System.exit(1);
  17.112 +    }
  17.113 +    catch (ParserConfigurationException pce)
  17.114 +    {
  17.115 +      pce.printStackTrace();
  17.116 +    }
  17.117 +    catch (FileNotFoundException fnfe)
  17.118 +    {
  17.119 +      System.err.println ("warning: state file not found [" +
  17.120 +			  filename + "]");
  17.121 +    }
  17.122 +    catch (IOException ioe)
  17.123 +    {
  17.124 +      ioe.printStackTrace();
  17.125 +    }
  17.126 +    return;
  17.127 +  }
  17.128 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/control/src/org/xenoserver/control/XMLHelper.java	Fri Jul 04 11:21:03 2003 +0000
    18.3 @@ -0,0 +1,205 @@
    18.4 +/*
    18.5 + * XMLHelper.java
    18.6 + * 03.03.27 aho creation
    18.7 + */
    18.8 +
    18.9 +package org.xenoserver.control;
   18.10 +
   18.11 +import java.util.Date;
   18.12 +import org.w3c.dom.Document;
   18.13 +import org.w3c.dom.Element;
   18.14 +import org.w3c.dom.Node;
   18.15 +import org.w3c.dom.NodeList;
   18.16 +
   18.17 +public class
   18.18 +XMLHelper
   18.19 +{
   18.20 +  static void
   18.21 +  dump_document (Document document)
   18.22 +  {
   18.23 +    dump_element(document.getDocumentElement(), 0);
   18.24 +  }
   18.25 +
   18.26 +  static void
   18.27 +  dump_element (Element element, int indent)
   18.28 +  {
   18.29 +    NodeList nl = element.getChildNodes();
   18.30 +
   18.31 +    System.out.println ("<" + element.getTagName() + ">");
   18.32 +    dump_nodelist(nl, indent + 1);
   18.33 +    System.out.println("</" + element.getTagName() + ">");
   18.34 +  }
   18.35 +
   18.36 +  static void
   18.37 +  dump_nodelist (NodeList nl, int indent)
   18.38 +  {
   18.39 +    for (int loop = 0; loop < nl.getLength(); loop++)
   18.40 +    {
   18.41 +      Node node = nl.item(loop);
   18.42 +      switch (node.getNodeType())
   18.43 +      {
   18.44 +	case Node.ELEMENT_NODE : 
   18.45 +	{
   18.46 +	  dump_element((Element)node, indent);
   18.47 +	  break;
   18.48 +	}
   18.49 +	case Node.TEXT_NODE :
   18.50 +	{
   18.51 +	  System.out.println("TEXT: " + node.getNodeValue());
   18.52 +	  break;
   18.53 +	}
   18.54 +	default :
   18.55 +	{
   18.56 +	  System.out.println("NODE: " + node.getNodeType());
   18.57 +	}
   18.58 +      }
   18.59 +    }
   18.60 +  }
   18.61 +
   18.62 +  static Node 
   18.63 +  get_subnode (String name, Node node) 
   18.64 +  {
   18.65 +    if (node.getNodeType() != Node.ELEMENT_NODE) 
   18.66 +    {
   18.67 +      System.err.println("Error: Search node not of element type");
   18.68 +      return null;
   18.69 +    }
   18.70 +
   18.71 +    if (!node.hasChildNodes()) return null;
   18.72 +
   18.73 +    NodeList list = node.getChildNodes();
   18.74 +    for (int i=0; i < list.getLength(); i++) 
   18.75 +    {
   18.76 +      Node subnode = list.item(i);
   18.77 +      if (subnode.getNodeType() == Node.ELEMENT_NODE) 
   18.78 +      {
   18.79 +	if (subnode.getNodeName() == name) return subnode;
   18.80 +      }
   18.81 +    }
   18.82 +    return null;
   18.83 +  }
   18.84 +
   18.85 +  static String 
   18.86 +  get_text (Node node) 
   18.87 +  {
   18.88 +    StringBuffer result = new StringBuffer();
   18.89 +    if (node==null || !node.hasChildNodes()) return "";
   18.90 +
   18.91 +    NodeList list = node.getChildNodes();
   18.92 +    for (int i=0; i < list.getLength(); i++) 
   18.93 +    {
   18.94 +      Node subnode = list.item(i);
   18.95 +      if (subnode.getNodeType() == Node.TEXT_NODE) 
   18.96 +      {
   18.97 +	result.append(subnode.getNodeValue());
   18.98 +      }
   18.99 +    }
  18.100 +    return result.toString();
  18.101 +  }
  18.102 +
  18.103 +  static void
  18.104 +  parse (PartitionManager pm, /*VirtualDiskManager vdm,*/ Document document)
  18.105 +  {
  18.106 +    if (document == null) return;
  18.107 +
  18.108 +    /* parse partitions */
  18.109 +    parse_partitions(pm, document.getElementsByTagName("partition"));
  18.110 +/*
  18.111 +    / parse virtual disks /
  18.112 +    NodeList list = document.getElementsByTagName("virtual_disk");
  18.113 +    for (int i = 0; i < list.getLength(); i++)
  18.114 +    {
  18.115 +      Node subnode = list.item(i);
  18.116 +      String parent = subnode.getParentNode().getNodeName();
  18.117 +      VirtualDisk vd =  parse_virtual_disk(subnode);
  18.118 +
  18.119 +      if (parent.equals("free"))
  18.120 +      {
  18.121 +	vdm.add_free(vd);
  18.122 +      }
  18.123 +      else if (parent.equals("virtual_disks"))
  18.124 +      {
  18.125 +	vdm.add_virtual_disk(vd);
  18.126 +      }
  18.127 +      else
  18.128 +      {
  18.129 +	System.out.println ("XML parse error: unknown parent for virtual_disk "
  18.130 +			    + "[" + parent + "]");
  18.131 +      }
  18.132 +    }
  18.133 +
  18.134 +    / parse virtual block devices /
  18.135 +    parse_virtual_block_devices(vdm, document.getElementsByTagName("virtual_block_device"));
  18.136 +*/
  18.137 +    return;
  18.138 +  }
  18.139 +
  18.140 + /* static VirtualDisk
  18.141 +  parse_virtual_disk(Node node)
  18.142 +  {
  18.143 +    VirtualDisk vd;
  18.144 +    Date date = new Date();
  18.145 +    NodeList list;
  18.146 +
  18.147 +    date.setTime(Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("expiry", node))));
  18.148 +    vd = new VirtualDisk(XMLHelper.get_text(XMLHelper.get_subnode("name", node)),
  18.149 +			 date,
  18.150 +			 XMLHelper.get_text(XMLHelper.get_subnode("key", node)));
  18.151 +
  18.152 +    list = XMLHelper.get_subnode("extents", node).getChildNodes();
  18.153 +    for (int i = 0; i < list.getLength(); i++)
  18.154 +    {
  18.155 +      Node enode = list.item(i);
  18.156 +
  18.157 +      if (enode.getNodeType() == Node.ELEMENT_NODE &&
  18.158 +	  enode.getNodeName().equals("extent"))
  18.159 +      {
  18.160 +	Extent extent = new Extent();
  18.161 +
  18.162 +	extent.disk = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("disk", enode)));
  18.163 +	extent.size = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("size", enode)));
  18.164 +	extent.offset = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("offset", enode)));
  18.165 +	vd.add_extent(extent);
  18.166 +      }
  18.167 +    }
  18.168 +
  18.169 +    return vd;
  18.170 +  }*/
  18.171 +
  18.172 +  static void
  18.173 +  parse_partitions (PartitionManager pm, NodeList nl)
  18.174 +  {
  18.175 +    Partition partition;
  18.176 +
  18.177 +    for (int loop = 0; loop < nl.getLength(); loop++)
  18.178 +    {
  18.179 +      Node node = nl.item(loop);
  18.180 +
  18.181 +      partition = new Partition();
  18.182 +      partition.major = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("major", node)));
  18.183 +      partition.minor = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("minor", node)));
  18.184 +      partition.blocks = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("blocks", node)));
  18.185 +      partition.start_sect = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("start_sect", node)));
  18.186 +      partition.nr_sects = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("nr_sects", node)));
  18.187 +      partition.name = XMLHelper.get_text(XMLHelper.get_subnode("name", node));
  18.188 +
  18.189 +      pm.add_xeno_partition(partition);
  18.190 +    }
  18.191 +  }
  18.192 +/*
  18.193 +  static void
  18.194 +  parse_virtual_block_devices (VirtualDiskManager vdm, NodeList nl)
  18.195 +  {
  18.196 +    VirtualBlockDevice vbd;
  18.197 +
  18.198 +    for (int loop = 0; loop < nl.getLength(); loop++)
  18.199 +    {
  18.200 +      Node node = nl.item(loop);
  18.201 +
  18.202 +      vdm.create_virtual_block_device(XMLHelper.get_text(XMLHelper.get_subnode("key", node)),
  18.203 +				      Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("domain", node))),
  18.204 +				      Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("vbdnum", node))),
  18.205 +				      XMLHelper.get_text(XMLHelper.get_subnode("mode", node)));
  18.206 +    }
  18.207 +  }*/
  18.208 +}