debuggers.hg

changeset 603:7e70ba4347e3

bitkeeper revision 1.304.1.7 (3f0bf195LrxhtbvmW2HyL5qXkoR63g)

Undo silly design decision by me; namely, to do any checking of values in the Parse classes.
Instead, it should be done in the Command classes, so that the web interface need not duplicate code.
author rac61@labyrinth.cl.cam.ac.uk
date Wed Jul 09 10:42:29 2003 +0000 (2003-07-09)
parents 05473a4cb01e
children f11254826a31
files tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java tools/control/src/org/xenoserver/control/CommandPartitionAdd.java tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java tools/control/src/org/xenoserver/control/CommandVbdCreate.java tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java tools/control/src/org/xenoserver/control/CommandVdCreate.java tools/control/src/org/xenoserver/control/CommandVdDelete.java tools/control/src/org/xenoserver/control/Partition.java tools/control/src/org/xenoserver/control/VirtualDisk.java tools/control/src/org/xenoserver/control/VirtualDiskManager.java
line diff
     1.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java	Wed Jul 09 10:21:08 2003 +0000
     1.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java	Wed Jul 09 10:42:29 2003 +0000
     1.3 @@ -6,55 +6,38 @@ import org.xenoserver.control.CommandFai
     1.4  import org.xenoserver.control.CommandPartitionAdd;
     1.5  import org.xenoserver.control.Defaults;
     1.6  import org.xenoserver.control.Library;
     1.7 -import org.xenoserver.control.Partition;
     1.8 -import org.xenoserver.control.PartitionManager;
     1.9 -import org.xenoserver.control.Settings;
    1.10  
    1.11  public class ParsePartitionsAdd extends CommandParser {
    1.12 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    1.13 -    boolean force = getFlagParameter(args, 'f');
    1.14 -    String partition_name = getStringParameter(args, 'p', "");
    1.15 -    String size = getStringParameter(args, 'c', "128M");
    1.16 -    
    1.17 -    if (partition_name.equals("")) {
    1.18 -      throw new ParseFailedException("Expected -p<partition_name>");
    1.19 -    }
    1.20 -      
    1.21 -    long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE;
    1.22 -    if ( chunksize <= 0 ) {
    1.23 -      throw new CommandFailedException("Chunk size " + size + " is smaller than sector size.");
    1.24 -    }
    1.25 -    
    1.26 -    // Initialise the partition manager and look up the partition
    1.27 -    loadState();
    1.28 -    Partition p = PartitionManager.IT.getPartition(partition_name);
    1.29 -    
    1.30 -    if ( p == null ) {
    1.31 -      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    1.32 +    public void parse(Defaults d, LinkedList args)
    1.33 +        throws ParseFailedException, CommandFailedException {
    1.34 +        boolean force = getFlagParameter(args, 'f');
    1.35 +        String partition_name = getStringParameter(args, 'p', "");
    1.36 +        String size = getStringParameter(args, 'c', "128M");
    1.37 +
    1.38 +        if (partition_name.equals("")) {
    1.39 +            throw new ParseFailedException("Expected -p<partition_name>");
    1.40 +        }
    1.41 +
    1.42 +        loadState();
    1.43 +        String output =
    1.44 +            new CommandPartitionAdd(partition_name, Library.parseSize(size),force)
    1.45 +                .execute();
    1.46 +        if (output != null) {
    1.47 +            System.out.println(output);
    1.48 +        }
    1.49 +        saveState();
    1.50      }
    1.51 -    
    1.52 -    // Check if this partition belongs to the VDM
    1.53 -    if (p.isXeno() && !force) {
    1.54 -      throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
    1.55 +
    1.56 +    public String getName() {
    1.57 +        return "add";
    1.58      }
    1.59 -    
    1.60 -    String output = new CommandPartitionAdd( p, chunksize ).execute();
    1.61 -    if ( output != null ) {
    1.62 -      System.out.println( output );
    1.63 -    }
    1.64 -    saveState();
    1.65 -  }
    1.66  
    1.67 -  public String getName() {
    1.68 -    return "add";
    1.69 -  }
    1.70 +    public String getUsage() {
    1.71 +        return "-p<partition_name> [-f] [-c<chunk_size>]";
    1.72 +    }
    1.73  
    1.74 -  public String getUsage() {
    1.75 -    return "-p<partition_name> [-f] [-c<chunk_size>]";
    1.76 -  }
    1.77 -
    1.78 -  public String getHelpText() {
    1.79 -    return "Add the specified partition to the virtual disk manager's free\n" +
    1.80 -           "space. -c changes the default chunk size. -f forces add.";
    1.81 -  }
    1.82 +    public String getHelpText() {
    1.83 +        return "Add the specified partition to the virtual disk manager's free\n"
    1.84 +            + "space. -c changes the default chunk size. -f forces add.";
    1.85 +    }
    1.86  }
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java	Wed Jul 09 10:21:08 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java	Wed Jul 09 10:42:29 2003 +0000
     2.3 @@ -6,60 +6,50 @@ import org.xenoserver.control.CommandFai
     2.4  import org.xenoserver.control.CommandPhysicalGrant;
     2.5  import org.xenoserver.control.Defaults;
     2.6  import org.xenoserver.control.Mode;
     2.7 -import org.xenoserver.control.Partition;
     2.8 -import org.xenoserver.control.PartitionManager;
     2.9  
    2.10  public class ParsePhysicalGrant extends CommandParser {
    2.11 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    2.12 -    int domain_id = getIntParameter(args, 'n', 0);
    2.13 -    boolean force = getFlagParameter(args, 'f');
    2.14 -    String partition_name = getStringParameter(args, 'p', "");
    2.15 -    boolean write = getFlagParameter(args, 'w');
    2.16 -    
    2.17 -    if (domain_id == 0) {
    2.18 -      throw new ParseFailedException("Expected -n<domain_id>");
    2.19 -    }
    2.20 -    if (partition_name.equals("")) {
    2.21 -      throw new ParseFailedException("Expected -p<partition_name>");
    2.22 -    }
    2.23 -      
    2.24 -    Mode mode;
    2.25 -    if (write) {
    2.26 -      mode = Mode.READ_WRITE;
    2.27 -    } else {
    2.28 -      mode = Mode.READ_ONLY;
    2.29 +    public void parse(Defaults d, LinkedList args)
    2.30 +        throws ParseFailedException, CommandFailedException {
    2.31 +        int domain_id = getIntParameter(args, 'n', 0);
    2.32 +        boolean force = getFlagParameter(args, 'f');
    2.33 +        String partition_name = getStringParameter(args, 'p', "");
    2.34 +        boolean write = getFlagParameter(args, 'w');
    2.35 +
    2.36 +        if (domain_id == 0) {
    2.37 +            throw new ParseFailedException("Expected -n<domain_id>");
    2.38 +        }
    2.39 +        if (partition_name.equals("")) {
    2.40 +            throw new ParseFailedException("Expected -p<partition_name>");
    2.41 +        }
    2.42 +
    2.43 +        Mode mode;
    2.44 +        if (write) {
    2.45 +            mode = Mode.READ_WRITE;
    2.46 +        } else {
    2.47 +            mode = Mode.READ_ONLY;
    2.48 +        }
    2.49 +
    2.50 +        // Initialise the partition manager and look up the partition
    2.51 +        loadState();
    2.52 +        String output =
    2.53 +            new CommandPhysicalGrant(d, domain_id, partition_name, mode, force)
    2.54 +                .execute();
    2.55 +        if (output != null) {
    2.56 +            System.out.println(output);
    2.57 +        }
    2.58      }
    2.59 -      
    2.60 -    // Initialise the partition manager and look up the partition
    2.61 -    loadState();
    2.62 -    Partition p = PartitionManager.IT.getPartition(partition_name);
    2.63 -    
    2.64 -    if ( p == null ) {
    2.65 -      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    2.66 -    }
    2.67 -    
    2.68 -    // Check if this partition belongs to the VDM
    2.69 -    if (p.isXeno() && !force) {
    2.70 -      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.");
    2.71 +
    2.72 +    public String getName() {
    2.73 +        return "grant";
    2.74      }
    2.75 -         
    2.76 -    String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute();
    2.77 -    if ( output != null ) {
    2.78 -      System.out.println( output );
    2.79 +
    2.80 +    public String getUsage() {
    2.81 +        return "-n<domain_id> -p<partition_name> [-f] [-w]";
    2.82      }
    2.83 -  }
    2.84  
    2.85 -  public String getName() {
    2.86 -    return "grant";
    2.87 -  }
    2.88 -
    2.89 -  public String getUsage() {
    2.90 -    return "-n<domain_id> -p<partition_name> [-f] [-w]";
    2.91 -  }
    2.92 -
    2.93 -  public String getHelpText() {
    2.94 -    return "Grant the specified domain access to the given partition.  -w grants" +
    2.95 -           " read-write instead of read-only.  -f forcibly grants access.";
    2.96 -  }
    2.97 +    public String getHelpText() {
    2.98 +        return "Grant the specified domain access to the given partition.  -w grants"
    2.99 +            + " read-write instead of read-only.  -f forcibly grants access.";
   2.100 +    }
   2.101  
   2.102  }
     3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java	Wed Jul 09 10:21:08 2003 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java	Wed Jul 09 10:42:29 2003 +0000
     3.3 @@ -5,8 +5,6 @@ import java.util.LinkedList;
     3.4  import org.xenoserver.control.CommandFailedException;
     3.5  import org.xenoserver.control.CommandPhysicalRevoke;
     3.6  import org.xenoserver.control.Defaults;
     3.7 -import org.xenoserver.control.Partition;
     3.8 -import org.xenoserver.control.PartitionManager;
     3.9  
    3.10  public class ParsePhysicalRevoke extends CommandParser {
    3.11      public void parse(Defaults d, LinkedList args)
    3.12 @@ -23,14 +21,7 @@ public class ParsePhysicalRevoke extends
    3.13  
    3.14          // Initialise the partition manager and look up the partition
    3.15          loadState();
    3.16 -        Partition p = PartitionManager.IT.getPartition(partition_name);
    3.17 -
    3.18 -        if (p == null) {
    3.19 -            throw new CommandFailedException(
    3.20 -                "Partition " + partition_name + " does not exist.");
    3.21 -        }
    3.22 -
    3.23 -        String output = new CommandPhysicalRevoke(d, domain_id, p).execute();
    3.24 +        String output = new CommandPhysicalRevoke(d, domain_id, partition_name).execute();
    3.25          if (output != null) {
    3.26              System.out.println(output);
    3.27          }
     4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java	Wed Jul 09 10:21:08 2003 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java	Wed Jul 09 10:42:29 2003 +0000
     4.3 @@ -7,10 +7,6 @@ import org.xenoserver.control.CommandVbd
     4.4  import org.xenoserver.control.CommandVbdCreatePhysical;
     4.5  import org.xenoserver.control.Defaults;
     4.6  import org.xenoserver.control.Mode;
     4.7 -import org.xenoserver.control.Partition;
     4.8 -import org.xenoserver.control.PartitionManager;
     4.9 -import org.xenoserver.control.VirtualDisk;
    4.10 -import org.xenoserver.control.VirtualDiskManager;
    4.11  
    4.12  public class ParseVbdCreate extends CommandParser {
    4.13      public void parse(Defaults d, LinkedList args)
    4.14 @@ -41,21 +37,10 @@ public class ParseVbdCreate extends Comm
    4.15          loadState();
    4.16          String output;
    4.17          if (vd_key.equals("")) {
    4.18 -            Partition p = PartitionManager.IT.getPartition(partition_name);
    4.19 -            if ( p == null ) {
    4.20 -                throw new CommandFailedException("No partition " + partition_name + " exists" );
    4.21 -            }
    4.22 -            
    4.23 -            output = new CommandVbdCreatePhysical( p, domain_id, vbd_num, mode ).execute();
    4.24 +            output = new CommandVbdCreatePhysical( partition_name, domain_id, vbd_num, mode ).execute();
    4.25          } else {
    4.26 -            VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(vd_key);
    4.27 -            if (vd == null) {
    4.28 -                throw new CommandFailedException(
    4.29 -                    "No virtual disk with key " + vd_key);
    4.30 -            }
    4.31 -
    4.32              output =
    4.33 -                new CommandVbdCreate(vd, domain_id, vbd_num, mode).execute();
    4.34 +                new CommandVbdCreate(vd_key, domain_id, vbd_num, mode).execute();
    4.35          }
    4.36          if (output != null) {
    4.37              System.out.println(output);
     5.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java	Wed Jul 09 10:21:08 2003 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java	Wed Jul 09 10:42:29 2003 +0000
     5.3 @@ -9,7 +9,6 @@ import org.xenoserver.control.CommandFai
     5.4  import org.xenoserver.control.CommandVdCreate;
     5.5  import org.xenoserver.control.Defaults;
     5.6  import org.xenoserver.control.Library;
     5.7 -import org.xenoserver.control.Settings;
     5.8  
     5.9  public class ParseVdCreate extends CommandParser {
    5.10      public void parse(Defaults d, LinkedList args)
    5.11 @@ -39,9 +38,7 @@ public class ParseVdCreate extends Comma
    5.12          long size = Library.parseSize(size_s);
    5.13  
    5.14          loadState();
    5.15 -        String output =
    5.16 -            new CommandVdCreate(name, size / Settings.SECTOR_SIZE, expiry)
    5.17 -                .execute();
    5.18 +        String output = new CommandVdCreate(name, size, expiry).execute();
    5.19          if (output != null) {
    5.20              System.out.println(output);
    5.21          }
     6.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java	Wed Jul 09 10:21:08 2003 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java	Wed Jul 09 10:42:29 2003 +0000
     6.3 @@ -5,7 +5,6 @@ import java.util.LinkedList;
     6.4  import org.xenoserver.control.CommandFailedException;
     6.5  import org.xenoserver.control.CommandVdDelete;
     6.6  import org.xenoserver.control.Defaults;
     6.7 -import org.xenoserver.control.VirtualDiskManager;
     6.8  
     6.9  public class ParseVdDelete extends CommandParser {
    6.10      public void parse(Defaults d, LinkedList args)
    6.11 @@ -17,11 +16,6 @@ public class ParseVdDelete extends Comma
    6.12          }
    6.13  
    6.14          loadState();
    6.15 -        if (VirtualDiskManager.IT.getVirtualDisk(vd_key) == null) {
    6.16 -            throw new CommandFailedException(
    6.17 -                "Virtual disk " + vd_key + " does not exist");
    6.18 -        }
    6.19 -
    6.20          String output = new CommandVdDelete(vd_key).execute();
    6.21          if (output != null) {
    6.22              System.out.println(output);
     7.1 --- a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java	Wed Jul 09 10:21:08 2003 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java	Wed Jul 09 10:42:29 2003 +0000
     7.3 @@ -4,27 +4,46 @@ package org.xenoserver.control;
     7.4   * Add a disk partition to the VirtualDiskManager as a XenoPartition.
     7.5   */
     7.6  public class CommandPartitionAdd extends Command {
     7.7 +    /** True to force creation. */
     7.8 +    private boolean force;
     7.9      /** Partition to add as a XenoPartition. */
    7.10 -    private Partition partition;
    7.11 -    /** Chunk size to split partition into (in sectors). */
    7.12 +    private String partition_name;
    7.13 +    /** Chunk size to split partition into (in bytes). */
    7.14      private long chunksize;
    7.15  
    7.16      /**
    7.17       * Constructor for CommandPartitionAdd.
    7.18 -     * @param partition Partition to add.
    7.19 -     * @param chunksize Chunk size to split partition into (in sectors).
    7.20 +     * @param partition_name Partition to add.
    7.21 +     * @param chunksize Chunk size to split partition into (in bytes).
    7.22 +     * @param force True to force creation.
    7.23       */
    7.24 -    public CommandPartitionAdd(Partition partition, long chunksize) {
    7.25 -        this.partition = partition;
    7.26 +    public CommandPartitionAdd(String partition_name, long chunksize, boolean force) {
    7.27 +        this.partition_name = partition_name;
    7.28          this.chunksize = chunksize;
    7.29 +        this.force = force;
    7.30      }
    7.31  
    7.32      /**
    7.33       * @see org.xenoserver.control.Command#execute()
    7.34       */
    7.35      public String execute() throws CommandFailedException {
    7.36 -        VirtualDiskManager.IT.addPartition(partition, chunksize);
    7.37 -        PartitionManager.IT.addXenoPartition(partition);
    7.38 -        return "Added partition " + partition.getName();
    7.39 +        Partition p = PartitionManager.IT.getPartition(partition_name);
    7.40 +        if (p == null) {
    7.41 +            throw new CommandFailedException(
    7.42 +                "Partition " + partition_name + " does not exist.");
    7.43 +        }
    7.44 +        // Check if this partition belongs to the VDM
    7.45 +        if (p.isXeno() && !force) {
    7.46 +          throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
    7.47 +        }
    7.48 +        
    7.49 +        long size = chunksize / Settings.SECTOR_SIZE;
    7.50 +        if ( chunksize <= 0 ) {
    7.51 +          throw new CommandFailedException("Chunk size is smaller than sector size.");
    7.52 +        }
    7.53 +    
    7.54 +        VirtualDiskManager.IT.addPartition(p, size);
    7.55 +        PartitionManager.IT.addXenoPartition(p);
    7.56 +        return "Added partition " + p.getName();
    7.57      }
    7.58  }
     8.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java	Wed Jul 09 10:21:08 2003 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java	Wed Jul 09 10:42:29 2003 +0000
     8.3 @@ -9,9 +9,11 @@ public class CommandPhysicalGrant extend
     8.4      /** Domain ID to grant access for */ 
     8.5      private int domain_id;
     8.6      /** Partition to grant access to */
     8.7 -    private Partition partition;
     8.8 +    private String partition_name;
     8.9      /** Access mode to grant */
    8.10      private Mode mode;
    8.11 +    /** True to force grant */
    8.12 +    private boolean force;
    8.13  
    8.14      /**
    8.15       * Constructor for CommandPhysicalGrant.
    8.16 @@ -19,16 +21,19 @@ public class CommandPhysicalGrant extend
    8.17       * @param domain_id Domain to grant access for.
    8.18       * @param partition Partition to grant access to.
    8.19       * @param mode Access mode to grant.
    8.20 +     * @param force True to force grant
    8.21       */
    8.22      public CommandPhysicalGrant(
    8.23          Defaults d,
    8.24          int domain_id,
    8.25 -        Partition partition,
    8.26 -        Mode mode) {
    8.27 +        String partition,
    8.28 +        Mode mode,
    8.29 +        boolean force) {
    8.30          this.d = d;
    8.31          this.domain_id = domain_id;
    8.32 -        this.partition = partition;
    8.33 +        this.partition_name = partition;
    8.34          this.mode = mode;
    8.35 +        this.force = force;
    8.36      }
    8.37  
    8.38      /**
    8.39 @@ -38,6 +43,17 @@ public class CommandPhysicalGrant extend
    8.40          Runtime r = Runtime.getRuntime();
    8.41          String output = null;
    8.42  
    8.43 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
    8.44 +    
    8.45 +        if ( partition == null ) {
    8.46 +          throw new CommandFailedException("Partition " + partition_name + " does not exist.");
    8.47 +        }
    8.48 +    
    8.49 +        // Check if this partition belongs to the VDM
    8.50 +        if (partition.isXeno() && !force) {
    8.51 +          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.");
    8.52 +        }
    8.53 +         
    8.54          try {
    8.55              Process start_p;
    8.56              String start_cmdarray[] = new String[7];
     9.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java	Wed Jul 09 10:21:08 2003 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java	Wed Jul 09 10:42:29 2003 +0000
     9.3 @@ -9,7 +9,7 @@ public class CommandPhysicalRevoke exten
     9.4      /** Domain to revoke access from */
     9.5      private int domain_id;
     9.6      /** Partition to revoke access to */
     9.7 -    private Partition partition;
     9.8 +    private String partition_name;
     9.9  
    9.10      /**
    9.11       * Constructor for CommandPhysicalRevoke.
    9.12 @@ -17,10 +17,10 @@ public class CommandPhysicalRevoke exten
    9.13       * @param domain_id Domain to revoke access from.
    9.14       * @param partition Partition to revoke access to.
    9.15       */
    9.16 -    public CommandPhysicalRevoke(Defaults d, int domain_id, Partition partition) {
    9.17 +    public CommandPhysicalRevoke(Defaults d, int domain_id, String partition) {
    9.18          this.d = d;
    9.19          this.domain_id = domain_id;
    9.20 -        this.partition = partition;
    9.21 +        this.partition_name = partition;
    9.22      }
    9.23  
    9.24      /**
    9.25 @@ -30,6 +30,13 @@ public class CommandPhysicalRevoke exten
    9.26          Runtime r = Runtime.getRuntime();
    9.27          String output = null;
    9.28  
    9.29 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
    9.30 +
    9.31 +        if (partition == null) {
    9.32 +            throw new CommandFailedException(
    9.33 +                "Partition " + partition_name + " does not exist.");
    9.34 +        }
    9.35 +
    9.36          try {
    9.37              Process start_p;
    9.38              String start_cmdarray[] = new String[5];
    10.1 --- a/tools/control/src/org/xenoserver/control/CommandVbdCreate.java	Wed Jul 09 10:21:08 2003 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdCreate.java	Wed Jul 09 10:42:29 2003 +0000
    10.3 @@ -8,7 +8,7 @@ import java.io.IOException;
    10.4   */
    10.5  public class CommandVbdCreate extends Command {
    10.6      /** Virtual disk to map to. */
    10.7 -    private VirtualDisk vd;
    10.8 +    private String vd_key;
    10.9      /** Domain to create VBD for. */
   10.10      private int domain_id;
   10.11      /** VBD number to use. */
   10.12 @@ -24,11 +24,11 @@ public class CommandVbdCreate extends Co
   10.13       * @param mode Access mode to grant.
   10.14       */
   10.15      public CommandVbdCreate(
   10.16 -        VirtualDisk vd,
   10.17 +        String vd,
   10.18          int domain_id,
   10.19          int vbd_num,
   10.20          Mode mode) {
   10.21 -        this.vd = vd;
   10.22 +        this.vd_key = vd;
   10.23          this.domain_id = domain_id;
   10.24          this.vbd_num = vbd_num;
   10.25          this.mode = mode;
   10.26 @@ -38,9 +38,13 @@ public class CommandVbdCreate extends Co
   10.27       * @see org.xenoserver.control.Command#execute()
   10.28       */
   10.29      public String execute() throws CommandFailedException {
   10.30 -        VirtualBlockDevice vbd;
   10.31 +        VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(vd_key);
   10.32 +        if (vd == null) {
   10.33 +            throw new CommandFailedException(
   10.34 +                "No virtual disk with key " + vd_key);
   10.35 +        }
   10.36  
   10.37 -        vbd =
   10.38 +        VirtualBlockDevice vbd =
   10.39              VirtualDiskManager.IT.createVirtualBlockDevice(
   10.40                  vd,
   10.41                  domain_id,
    11.1 --- a/tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java	Wed Jul 09 10:21:08 2003 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java	Wed Jul 09 10:42:29 2003 +0000
    11.3 @@ -8,7 +8,7 @@ import java.io.IOException;
    11.4   */
    11.5  public class CommandVbdCreatePhysical extends Command {
    11.6      /** Virtual disk to map to. */
    11.7 -    private Partition partition;
    11.8 +    private String partition_name;
    11.9      /** Domain to create VBD for. */
   11.10      private int domain_id;
   11.11      /** VBD number to use. */
   11.12 @@ -24,11 +24,11 @@ public class CommandVbdCreatePhysical ex
   11.13       * @param mode Access mode to grant.
   11.14       */
   11.15      public CommandVbdCreatePhysical(
   11.16 -        Partition partition,
   11.17 +        String partition,
   11.18          int domain_id,
   11.19          int vbd_num,
   11.20          Mode mode) {
   11.21 -        this.partition = partition;
   11.22 +        this.partition_name = partition;
   11.23          this.domain_id = domain_id;
   11.24          this.vbd_num = vbd_num;
   11.25          this.mode = mode;
   11.26 @@ -38,14 +38,17 @@ public class CommandVbdCreatePhysical ex
   11.27       * @see org.xenoserver.control.Command#execute()
   11.28       */
   11.29      public String execute() throws CommandFailedException {
   11.30 -        VirtualDisk vd = new VirtualDisk("vbd:"+partition.getName());
   11.31 -        vd.addPartition(partition,partition.getNumSects());
   11.32 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
   11.33 +        if (partition == null) {
   11.34 +            throw new CommandFailedException(
   11.35 +                "No partition " + partition_name + " exists");
   11.36 +        }
   11.37  
   11.38 -        VirtualBlockDevice vbd = new VirtualBlockDevice(
   11.39 -                vd,
   11.40 -                domain_id,
   11.41 -                vbd_num,
   11.42 -                mode);
   11.43 +        VirtualDisk vd = new VirtualDisk("vbd:" + partition.getName());
   11.44 +        vd.addPartition(partition, partition.getNumSects());
   11.45 +
   11.46 +        VirtualBlockDevice vbd =
   11.47 +            new VirtualBlockDevice(vd, domain_id, vbd_num, mode);
   11.48  
   11.49          String command = vd.dumpForXen(vbd);
   11.50  
   11.51 @@ -55,7 +58,9 @@ public class CommandVbdCreatePhysical ex
   11.52              fw.flush();
   11.53              fw.close();
   11.54          } catch (IOException e) {
   11.55 -            throw new CommandFailedException("Could not write VBD details to /proc/xeno/dom0/vhd", e);
   11.56 +            throw new CommandFailedException(
   11.57 +                "Could not write VBD details to /proc/xeno/dom0/vhd",
   11.58 +                e);
   11.59          }
   11.60  
   11.61          return "Created virtual block device "
    12.1 --- a/tools/control/src/org/xenoserver/control/CommandVdCreate.java	Wed Jul 09 10:21:08 2003 +0000
    12.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java	Wed Jul 09 10:42:29 2003 +0000
    12.3 @@ -8,7 +8,7 @@ import java.util.Date;
    12.4  public class CommandVdCreate extends Command {
    12.5      /** Name of new disk. */
    12.6      private String name;
    12.7 -    /** Size of new disk in sectors. */
    12.8 +    /** Size of new disk in bytes. */
    12.9      private long size;
   12.10      /** Expiry date of new disk. */
   12.11      private Date expiry;
   12.12 @@ -16,7 +16,7 @@ public class CommandVdCreate extends Com
   12.13      /**
   12.14       * Constructor for CommandVdCreate.
   12.15       * @param name Name of new virtual disk.
   12.16 -     * @param size Size in sectors.
   12.17 +     * @param size Size in bytes.
   12.18       * @param expiry Expiry time, or null for never.
   12.19       */
   12.20      public CommandVdCreate(String name, long size, Date expiry) {
   12.21 @@ -30,7 +30,10 @@ public class CommandVdCreate extends Com
   12.22       */
   12.23      public String execute() throws CommandFailedException {
   12.24          VirtualDisk vd =
   12.25 -            VirtualDiskManager.IT.createVirtualDisk(name, size, expiry);
   12.26 +            VirtualDiskManager.IT.createVirtualDisk(
   12.27 +                name,
   12.28 +                size / Settings.SECTOR_SIZE,
   12.29 +                expiry);
   12.30          if (vd == null) {
   12.31              throw new CommandFailedException("Not enough free space to create disk");
   12.32          }
    13.1 --- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java	Wed Jul 09 10:21:08 2003 +0000
    13.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java	Wed Jul 09 10:42:29 2003 +0000
    13.3 @@ -19,6 +19,11 @@ public class CommandVdDelete extends Com
    13.4       * @see org.xenoserver.control.Command#execute()
    13.5       */
    13.6      public String execute() throws CommandFailedException {
    13.7 +        if (VirtualDiskManager.IT.getVirtualDisk(key) == null) {
    13.8 +            throw new CommandFailedException(
    13.9 +                "Virtual disk " + key + " does not exist");
   13.10 +        }
   13.11 +
   13.12          VirtualDiskManager.IT.deleteVirtualDisk(key);
   13.13          return "Deleted virtual disk " + key;
   13.14      }
    14.1 --- a/tools/control/src/org/xenoserver/control/Partition.java	Wed Jul 09 10:21:08 2003 +0000
    14.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java	Wed Jul 09 10:42:29 2003 +0000
    14.3 @@ -142,7 +142,7 @@ public class Partition {
    14.4       * @param other Other partition to compare to.
    14.5       * @return True if they are identical.
    14.6       */
    14.7 -    public boolean identical(Partition other) {
    14.8 +    boolean identical(Partition other) {
    14.9          return this.major == other.major
   14.10              && this.minor == other.minor
   14.11              && this.blocks == other.blocks
   14.12 @@ -154,7 +154,7 @@ public class Partition {
   14.13      /**
   14.14       * @return An Extent covering this partiton.
   14.15       */
   14.16 -    public Extent toExtent() {
   14.17 +    Extent toExtent() {
   14.18          return new Extent(getDisk(),start_sect,nr_sects);
   14.19      }
   14.20  
   14.21 @@ -162,7 +162,7 @@ public class Partition {
   14.22       * @param e Extent to compare this partition to.
   14.23       * @return True if this partition covers the same disk area as the given extent.
   14.24       */
   14.25 -    public boolean matchesExtent(Extent e) {
   14.26 +    boolean matchesExtent(Extent e) {
   14.27          return e.getDisk() == getDisk()
   14.28              && e.getOffset() == start_sect
   14.29              && e.getSize() == nr_sects;
    15.1 --- a/tools/control/src/org/xenoserver/control/VirtualDisk.java	Wed Jul 09 10:21:08 2003 +0000
    15.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDisk.java	Wed Jul 09 10:42:29 2003 +0000
    15.3 @@ -227,7 +227,7 @@ public class VirtualDisk {
    15.4       * Reset the expiry time for this virtual disk.
    15.5       * @param expiry The new expiry time, or null for never.
    15.6       */
    15.7 -    public void refreshExpiry(Date expiry) {
    15.8 +    void refreshExpiry(Date expiry) {
    15.9          this.expiry = expiry;
   15.10      }
   15.11  }
    16.1 --- a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 10:21:08 2003 +0000
    16.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 10:42:29 2003 +0000
    16.3 @@ -45,7 +45,7 @@ public class VirtualDiskManager {
    16.4       * @param partition The partition to add.
    16.5       * @param chunkSize The chunk size to split the partition into, in sectors. 
    16.6       */
    16.7 -    public void addPartition(Partition partition, long chunkSize) {
    16.8 +    void addPartition(Partition partition, long chunkSize) {
    16.9          freeDisk.addPartition(partition, chunkSize);
   16.10      }
   16.11  
   16.12 @@ -56,7 +56,7 @@ public class VirtualDiskManager {
   16.13       * @param expiry The expiry time, or null for never.
   16.14       * @return null if not enough space is available
   16.15       */
   16.16 -    public VirtualDisk createVirtualDisk(String name, long size, Date expiry) {
   16.17 +    VirtualDisk createVirtualDisk(String name, long size, Date expiry) {
   16.18          if (freeDisk.getSize() < size) {
   16.19              return null;
   16.20          }
   16.21 @@ -83,7 +83,7 @@ public class VirtualDiskManager {
   16.22       * Delete a virtual disk, and put its extents back into the free pool.
   16.23       * @param key The key of the disk to delete.
   16.24       */
   16.25 -    public void deleteVirtualDisk(String key) {
   16.26 +    void deleteVirtualDisk(String key) {
   16.27          VirtualDisk vd;
   16.28  
   16.29          vd = (VirtualDisk) virtualDisks.get(key);
   16.30 @@ -108,7 +108,7 @@ public class VirtualDiskManager {
   16.31       * @param mode The mode to create the device with.
   16.32       * @return The newly created virtual block device.
   16.33       */
   16.34 -    public VirtualBlockDevice createVirtualBlockDevice(
   16.35 +    VirtualBlockDevice createVirtualBlockDevice(
   16.36          VirtualDisk vd,
   16.37          int domain,
   16.38          int vbdNum,
   16.39 @@ -126,7 +126,7 @@ public class VirtualDiskManager {
   16.40       * @param domain Domain owning the device.
   16.41       * @param vbdNum The vbd number within the domain.
   16.42       */
   16.43 -    public void deleteVirtualBlockDevice(int domain, int vbdNum) {
   16.44 +    void deleteVirtualBlockDevice(int domain, int vbdNum) {
   16.45          Object hash = hashVBD(domain, vbdNum);
   16.46          virtualBlockDevices.remove(hash);
   16.47      }
   16.48 @@ -134,7 +134,7 @@ public class VirtualDiskManager {
   16.49      /**
   16.50       * Flush all virtual block devices.
   16.51       */
   16.52 -    public void flushVirtualBlockDevices() {
   16.53 +    void flushVirtualBlockDevices() {
   16.54          /* isn't automatic garbage collection wonderful? */
   16.55          virtualBlockDevices = new LinkedHashMap(100);
   16.56      }