ia64/xen-unstable

changeset 567:f11254826a31

bitkeeper revision 1.311 (3f0bf55e-uz44DyPEK5RW-cYqe5jeQ)

Merge labyrinth.cl.cam.ac.uk:/auto/groups/xeno/users/rac61/xeno.bk
into labyrinth.cl.cam.ac.uk:/auto/groups/xeno/users/sos22/xeno.bk
author sos22@labyrinth.cl.cam.ac.uk
date Wed Jul 09 10:58:38 2003 +0000 (2003-07-09)
parents c013c04b116d 7e70ba4347e3
children 7a7e8d7da0dc
files .rootkeys tools/control/src/org/xenoserver/cmdline/Main.java tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java tools/control/src/org/xenoserver/cmdline/ParseDomainList.java tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java tools/control/src/org/xenoserver/cmdline/ParseFailedException.java tools/control/src/org/xenoserver/cmdline/ParseGroup.java tools/control/src/org/xenoserver/cmdline/ParseHelp.java tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.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/cmdline/ParseVbdCreate.java tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java tools/control/src/org/xenoserver/cmdline/ParseVdFree.java tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java tools/control/src/org/xenoserver/cmdline/ParseVdShow.java tools/control/src/org/xenoserver/control/CommandPartitionAdd.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/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/Extent.java tools/control/src/org/xenoserver/control/Partition.java tools/control/src/org/xenoserver/control/VirtualBlockDevice.java tools/control/src/org/xenoserver/control/VirtualDisk.java tools/control/src/org/xenoserver/control/VirtualDiskManager.java tools/control/src/org/xenoserver/control/XMLHelper.java tools/control/src/uk/ac/cam/cl/xeno/xenctl/Main.java.orig tools/control/src/uk/ac/cam/cl/xeno/xenctl/Parser.java
line diff
     1.1 --- a/.rootkeys	Wed Jul 09 10:58:27 2003 +0000
     1.2 +++ b/.rootkeys	Wed Jul 09 10:58:38 2003 +0000
     1.3 @@ -30,6 +30,8 @@ 3f05631djnPcaqmzMFSa8RLmGCZ-0Q tools/con
     1.4  3f05631dswxJX_TpcuG6tBstyHSetg tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
     1.5  3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
     1.6  3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
     1.7 +3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
     1.8 +3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
     1.9  3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
    1.10  3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
    1.11  3f098761zh9WTV6LpRqcet3gqlXdtg tools/control/src/org/xenoserver/cmdline/ParseVdFree.java
    1.12 @@ -46,6 +48,8 @@ 3f0987611uZwg-o64yi0p_2aXCYEug tools/con
    1.13  3f05631ev3UK5FRi5vgR08zDp3OZYw tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java
    1.14  3f05631e_G6wzHhEnpihX0pIkEsbMw tools/control/src/org/xenoserver/control/CommandPhysicalList.java
    1.15  3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
    1.16 +3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
    1.17 +3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
    1.18  3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
    1.19  3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
    1.20  3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
    1.21 @@ -64,8 +68,6 @@ 3ec41f7dVFBlviwXPQ06BlU3UybziA tools/con
    1.22  3ec41f7dKX9YpwrfH7BZ7BogyWqqLA tools/control/src/org/xenoserver/control/VirtualDiskManager.java
    1.23  3ec41f7dUPpYTwYL5QVpRBv6PLKPrg tools/control/src/org/xenoserver/control/XML.java
    1.24  3ec41f7d7Try-2zmfnpaALwJjY0GCA tools/control/src/org/xenoserver/control/XMLHelper.java
    1.25 -3ec41f7civcv4mQiYK0DeX9Zvsxhrw tools/control/src/uk/ac/cam/cl/xeno/xenctl/Main.java.orig
    1.26 -3ec41f7d3-xTeoVJBJqWqxVfU-ANoQ tools/control/src/uk/ac/cam/cl/xeno/xenctl/Parser.java
    1.27  3ec41f7dOVZgjP4sQS6vjuBnExdlMQ tools/control/src/uk/ac/cam/cl/xeno/xenctl/RootBean.java
    1.28  3ec41f7dvPdszb0frNEkMnEdJUBVjA tools/control/src/uk/ac/cam/cl/xeno/xenctl/SystemConfigurationBean.java
    1.29  3ec41f7dO6IuKGGLG4VRUhMDmkTn5g tools/control/web/WEB-INF/web.xml
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/Main.java	Wed Jul 09 10:58:27 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Wed Jul 09 10:58:38 2003 +0000
     2.3 @@ -1,58 +1,71 @@
     2.4  package org.xenoserver.cmdline;
     2.5  
     2.6  import java.util.LinkedList;
     2.7 +import java.util.NoSuchElementException;
     2.8  
     2.9  import org.xenoserver.control.CommandFailedException;
    2.10  import org.xenoserver.control.Defaults;
    2.11  
    2.12 +/**
    2.13 + * Main class for the command-line xenctl interface.
    2.14 + */
    2.15  public class Main {
    2.16    static final ParseHelp help = new ParseHelp();
    2.17 -  static final CommandParser domaincommands[] =
    2.18 +  private static final CommandParser domaincommands[] =
    2.19      { new ParseDomainNew(),
    2.20        new ParseDomainStart(),
    2.21        new ParseDomainStop(),
    2.22        new ParseDomainDestroy(),
    2.23        new ParseDomainList()
    2.24      };
    2.25 -  static final CommandParser partitioncommands[] =
    2.26 +  private static final CommandParser partitioncommands[] =
    2.27      { new ParsePartitionsAdd(),
    2.28        new ParsePartitionsList()
    2.29      };
    2.30 -  static final CommandParser physicalcommands[] =
    2.31 +  private static final CommandParser physicalcommands[] =
    2.32      { new ParsePhysicalGrant(),
    2.33        new ParsePhysicalRevoke(),
    2.34        new ParsePhysicalList()
    2.35      };
    2.36 -  static final CommandParser vdcommands[] =
    2.37 +  private static final CommandParser vdcommands[] =
    2.38      { new ParseVdCreate(),
    2.39        new ParseVdDelete(),
    2.40        new ParseVdRefresh(),
    2.41        new ParseVdShow(),
    2.42        new ParseVdFree()
    2.43      };
    2.44 -  static final CommandParser commands[] =
    2.45 +  private static final CommandParser vbdcommands[] =
    2.46 +    { new ParseVbdCreate(),
    2.47 +      new ParseVbdShow()
    2.48 +    };
    2.49 +  private static final CommandParser commands[] =
    2.50      { help,
    2.51        new ParseGroup( "domain", domaincommands ),
    2.52        new ParseGroup( "partitions", partitioncommands ),
    2.53        new ParseGroup( "physical", physicalcommands ),
    2.54 -      new ParseGroup( "vd", vdcommands )
    2.55 +      new ParseGroup( "vd", vdcommands ),
    2.56 +      new ParseGroup( "vbd", vbdcommands )
    2.57      };
    2.58 +  /** The top-level parser. */
    2.59    static final CommandParser parser = new ParseGroup( null, commands );
    2.60  
    2.61    public static void main(String[] args) {
    2.62      Defaults d = new Defaults();
    2.63      int ec = -1;
    2.64      LinkedList arglist = new LinkedList();
    2.65 -    for ( int i=0; i<args.length; i++ )
    2.66 +    for ( int i=0; i<args.length; i++ ) {
    2.67        arglist.add( args[i] );
    2.68 +    }
    2.69  
    2.70      if (args.length == 0) {
    2.71 -      help.parse(d, arglist);
    2.72 +      help.parse(null, null);
    2.73      } else {
    2.74        try
    2.75        {
    2.76          parser.parse(d, arglist);
    2.77          ec = 0;
    2.78 +      } catch (NoSuchElementException e) {
    2.79 +          help.parse(null, null);
    2.80        } catch (ParseFailedException e) {
    2.81          System.err.println( e.getMessage() );
    2.82        } catch (CommandFailedException e) {
     3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java	Wed Jul 09 10:58:27 2003 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java	Wed Jul 09 10:58:38 2003 +0000
     3.3 @@ -7,32 +7,30 @@ import org.xenoserver.control.CommandFai
     3.4  import org.xenoserver.control.Defaults;
     3.5  
     3.6  public class ParseDomainDestroy extends CommandParser {
     3.7 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
     3.8 -    int domain_id = getIntParameter(args, 'n', 0);
     3.9 -    boolean force = getFlagParameter(args, 'f');
    3.10 +    public void parse(Defaults d, LinkedList args)
    3.11 +        throws ParseFailedException, CommandFailedException {
    3.12 +        int domain_id = getIntParameter(args, 'n', 0);
    3.13 +        boolean force = getFlagParameter(args, 'f');
    3.14  
    3.15 -    if (domain_id == 0) {
    3.16 -      throw new ParseFailedException("Expected -n<domain_id>");
    3.17 +        if (domain_id == 0) {
    3.18 +            throw new ParseFailedException("Expected -n<domain_id>");
    3.19 +        }
    3.20 +
    3.21 +        String output = new CommandDomainDestroy(d, domain_id, force).execute();
    3.22 +        if (output != null) {
    3.23 +            System.out.println(output);
    3.24 +        }
    3.25      }
    3.26  
    3.27 -    String output = new CommandDomainDestroy(d, domain_id, force).execute();
    3.28 -    if ( output != null )
    3.29 -      System.out.println( output );
    3.30 -  }
    3.31 -  
    3.32 -  public String getName()
    3.33 -  {
    3.34 -    return "destroy";
    3.35 -  }
    3.36 +    public String getName() {
    3.37 +        return "destroy";
    3.38 +    }
    3.39  
    3.40 -  public String getUsage()
    3.41 -  {
    3.42 -    return "[-f] [-n<domain_id>]";
    3.43 -  }
    3.44 +    public String getUsage() {
    3.45 +        return "-n<domain_id> [-f]";
    3.46 +    }
    3.47  
    3.48 -  public String getHelpText()
    3.49 -  {
    3.50 -    return
    3.51 -      "Destory the specified domain.  -f forcibly destroys it.";
    3.52 -  }
    3.53 +    public String getHelpText() {
    3.54 +        return "Destroy the specified domain.  -f forcibly destroys it.";
    3.55 +    }
    3.56  }
     4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java	Wed Jul 09 10:58:27 2003 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java	Wed Jul 09 10:58:38 2003 +0000
     4.3 @@ -8,40 +8,37 @@ import org.xenoserver.control.Defaults;
     4.4  import org.xenoserver.control.Domain;
     4.5  
     4.6  public class ParseDomainList extends CommandParser {
     4.7 +    public void parse(Defaults d, LinkedList args)
     4.8 +        throws ParseFailedException, CommandFailedException {
     4.9 +        CommandDomainList list = new CommandDomainList(d);
    4.10 +        String output = list.execute();
    4.11 +        if (output != null) {
    4.12 +            System.out.println(output);
    4.13 +        }
    4.14  
    4.15 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    4.16 -    CommandDomainList list = new CommandDomainList(d);
    4.17 -    String output = list.execute();
    4.18 -    if ( output != null )
    4.19 -      System.out.println( output );
    4.20 -    Domain[] domains = list.domains();
    4.21 +        Domain[] domains = list.domains();
    4.22  
    4.23 -    for (int loop = 0; loop < domains.length; loop++)
    4.24 -    {
    4.25 -      System.out.println ("id: " + domains[loop].id + 
    4.26 -        " (" + domains[loop].name+ ")");
    4.27 -      System.out.println ("  processor: " + domains[loop].processor);
    4.28 -      System.out.println ("  has cpu: " + domains[loop].cpu);
    4.29 -      System.out.println ("  state: " + domains[loop].nstate + " " +
    4.30 -        domains[loop].state);
    4.31 -      System.out.println ("  mcu advance: " + domains[loop].mcu);
    4.32 -      System.out.println ("  total pages: " + domains[loop].pages);
    4.33 +        for (int loop = 0; loop < domains.length; loop++) {
    4.34 +            System.out.println(
    4.35 +                "id: " + domains[loop].id + " (" + domains[loop].name + ")");
    4.36 +            System.out.println("  processor: " + domains[loop].processor);
    4.37 +            System.out.println("  has cpu: " + domains[loop].cpu);
    4.38 +            System.out.println(
    4.39 +                "  state: " + domains[loop].nstate + " " + domains[loop].state);
    4.40 +            System.out.println("  mcu advance: " + domains[loop].mcu);
    4.41 +            System.out.println("  total pages: " + domains[loop].pages);
    4.42 +        }
    4.43      }
    4.44 -  }
    4.45  
    4.46 -  public String getName()
    4.47 -  {
    4.48 -    return "list";
    4.49 -  }
    4.50 +    public String getName() {
    4.51 +        return "list";
    4.52 +    }
    4.53  
    4.54 -  public String getUsage()
    4.55 -  {
    4.56 -    return "";
    4.57 -  }
    4.58 +    public String getUsage() {
    4.59 +        return "";
    4.60 +    }
    4.61  
    4.62 -  public String getHelpText()
    4.63 -  {
    4.64 -    return
    4.65 -      "List domain information";
    4.66 -  }
    4.67 +    public String getHelpText() {
    4.68 +        return "List domain information and status.";
    4.69 +    }
    4.70  }
     5.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java	Wed Jul 09 10:58:27 2003 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java	Wed Jul 09 10:58:38 2003 +0000
     5.3 @@ -7,76 +7,86 @@ import org.xenoserver.control.CommandFai
     5.4  import org.xenoserver.control.Defaults;
     5.5  
     5.6  public class ParseDomainNew extends CommandParser {
     5.7 +    public void parse(Defaults d, LinkedList args)
     5.8 +        throws ParseFailedException, CommandFailedException {
     5.9 +        String name = getStringParameter(args, 'n', d.domainName);
    5.10 +        int size = getIntParameter(args, 'k', d.domainSizeKB);
    5.11 +        String image = getStringParameter(args, 'i', d.domainImage);
    5.12 +        String initrd = getStringParameter(args, 'r', d.domainInitRD);
    5.13 +        int vifs = getIntParameter(args, 'v', d.domainVIFs);
    5.14 +        String bargs = getStringParameter(args, 'a', d.args) + " ";
    5.15 +        String root_dev = getStringParameter(args, 'd', d.rootDevice);
    5.16 +        String nfs_root_path = getStringParameter(args, 'f', d.nwNFSRoot);
    5.17 +        String nw_ip = getStringParameter(args, '4', d.nwIP);
    5.18 +        String nw_gw = getStringParameter(args, 'g', d.nwGateway);
    5.19 +        String nw_mask = getStringParameter(args, 'm', d.nwMask);
    5.20 +        String nw_nfs_server = getStringParameter(args, 's', d.nwNFSServer);
    5.21 +        String nw_host = getStringParameter(args, 'h', d.nwHost);
    5.22  
    5.23 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    5.24 -    String name = getStringParameter(args, 'n', d.domainName);
    5.25 -    int size = getIntParameter(args, 'k', d.domainSizeKB);
    5.26 -    String image = getStringParameter(args, 'i', d.domainImage);
    5.27 -    String initrd = getStringParameter (args, 'r', d.domainInitRD);
    5.28 -    int vifs = getIntParameter(args, 'v', d.domainVIFs);
    5.29 -    String bargs = getStringParameter (args, 'a', d.args) + " ";
    5.30 -    String root_dev = getStringParameter (args, 'd', d.rootDevice);
    5.31 -    String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot);
    5.32 -    String nw_ip = getStringParameter (args, '4', d.nwIP);
    5.33 -    String nw_gw = getStringParameter (args, 'g', d.nwGateway);
    5.34 -    String nw_mask = getStringParameter (args, 'm', d.nwMask);
    5.35 -    String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer);
    5.36 -    String nw_host = getStringParameter (args, 'h', d.nwHost);
    5.37 -
    5.38 -    d.describe();
    5.39 +        d.describe();
    5.40  
    5.41 -    CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs,
    5.42 -                                  bargs, root_dev, nfs_root_path,
    5.43 -                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
    5.44 -    c.execute();
    5.45 -    String[] output = c.output();
    5.46 -    for ( int i = 0; i < output.length; i++ )
    5.47 -      System.out.println( output[i] ); 
    5.48 -  }
    5.49 -
    5.50 -  public String getName()
    5.51 -  {
    5.52 -    return "new";
    5.53 -  }
    5.54 -
    5.55 -  public String getUsage()
    5.56 -  {
    5.57 -    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
    5.58 -  }
    5.59 +        CommandDomainNew c =
    5.60 +            new CommandDomainNew(
    5.61 +                d,
    5.62 +                name,
    5.63 +                size,
    5.64 +                image,
    5.65 +                initrd,
    5.66 +                vifs,
    5.67 +                bargs,
    5.68 +                root_dev,
    5.69 +                nfs_root_path,
    5.70 +                nw_ip,
    5.71 +                nw_gw,
    5.72 +                nw_mask,
    5.73 +                nw_nfs_server,
    5.74 +                nw_host);
    5.75 +        c.execute();
    5.76 +        String[] output = c.output();
    5.77 +        for (int i = 0; i < output.length; i++) {
    5.78 +            System.out.println(output[i]);
    5.79 +        }
    5.80 +    }
    5.81  
    5.82 -  public String getHelpText()
    5.83 -  {
    5.84 -    return
    5.85 -      "Create a new domain.  Note that most of the parameters will assume\n" +
    5.86 -      "default values: it should not be necessary to specify them all. See\n" +
    5.87 -      "domctl.xml for the current default settings.\n" +
    5.88 -      "\n" +
    5.89 -      "General command line options:\n" +
    5.90 -      "  -n  Domain name                              domain_name\n" +
    5.91 -      "  -k  Domain size (kb)                         domain_size_kb\n" +
    5.92 -      "  -i  Domain image name                        domain_image\n" +
    5.93 -      "  -v  Number of VIFs                           domain_vifs\n" +
    5.94 -      "  -r  InitRD (if required)                     domain_init_rd\n" +
    5.95 -      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
    5.96 -      "  -a  Additional boot parameters\n" +
    5.97 -      "\n" +
    5.98 -      "Networking options:\n" +
    5.99 -      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
   5.100 -      "  -s  NFS server                               nw_nfs_server\n" +
   5.101 -      "  -4  Domain IPv4 address                      nw_ip\n" +
   5.102 -      "  -g  Domain gateway                           nw_gw\n" +
   5.103 -      "  -m  Domain net mask                          nw_mask\n" +
   5.104 -      "  -h  Domain hostname                          nw_host\n" +
   5.105 -      "\n" +
   5.106 -      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
   5.107 -      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
   5.108 -      "domain 1 patterns would expand as follows:\n" +
   5.109 -      "\n" +
   5.110 -      "  /dev/hda+       /dev/hda1\n" +
   5.111 -      "  /dev/hda7+      /dev/hda8\n" +
   5.112 -      "  128.232.8.50+   128.232.8.51\n" +
   5.113 -      "\n" +
   5.114 -      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
   5.115 -      "expanded to the corresponding setting from the calling domain.\n";
   5.116 -  }
   5.117 +    public String getName() {
   5.118 +        return "new";
   5.119 +    }
   5.120 +
   5.121 +    public String getUsage() {
   5.122 +        return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
   5.123 +    }
   5.124 +
   5.125 +    public String getHelpText() {
   5.126 +        return "Create a new domain.  Note that most of the parameters will assume\n"
   5.127 +            + "default values: it should not be necessary to specify them all. See\n"
   5.128 +            + "domctl.xml for the current default settings.\n"
   5.129 +            + "\n"
   5.130 +            + "General command line options:\n"
   5.131 +            + "  -n  Domain name                              domain_name\n"
   5.132 +            + "  -k  Domain size (kb)                         domain_size_kb\n"
   5.133 +            + "  -i  Domain image name                        domain_image\n"
   5.134 +            + "  -v  Number of VIFs                           domain_vifs\n"
   5.135 +            + "  -r  InitRD (if required)                     domain_init_rd\n"
   5.136 +            + "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n"
   5.137 +            + "  -a  Additional boot parameters\n"
   5.138 +            + "\n"
   5.139 +            + "Networking options:\n"
   5.140 +            + "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n"
   5.141 +            + "  -s  NFS server                               nw_nfs_server\n"
   5.142 +            + "  -4  Domain IPv4 address                      nw_ip\n"
   5.143 +            + "  -g  Domain gateway                           nw_gw\n"
   5.144 +            + "  -m  Domain net mask                          nw_mask\n"
   5.145 +            + "  -h  Domain hostname                          nw_host\n"
   5.146 +            + "\n"
   5.147 +            + "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n"
   5.148 +            + "which the allocated domain ID will be incorporated.  e.g.  for\n"
   5.149 +            + "domain 1 patterns would expand as follows:\n"
   5.150 +            + "\n"
   5.151 +            + "  /dev/hda+       /dev/hda1\n"
   5.152 +            + "  /dev/hda7+      /dev/hda8\n"
   5.153 +            + "  128.232.8.50+   128.232.8.51\n"
   5.154 +            + "\n"
   5.155 +            + "Additionally, patterns for -4 -g -m can include an = which is\n"
   5.156 +            + "expanded to the corresponding setting from the calling domain.\n";
   5.157 +    }
   5.158  }
     6.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java	Wed Jul 09 10:58:27 2003 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java	Wed Jul 09 10:58:38 2003 +0000
     6.3 @@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFai
     6.4  import org.xenoserver.control.Defaults;
     6.5  
     6.6  public class ParseDomainStart extends CommandParser {
     6.7 +    public void parse(Defaults d, LinkedList args)
     6.8 +        throws ParseFailedException, CommandFailedException {
     6.9 +        int domain_id = getIntParameter(args, 'n', 0);
    6.10  
    6.11 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    6.12 -    int domain_id = getIntParameter(args, 'n', 0);
    6.13 -    
    6.14 -    if (domain_id == 0) {
    6.15 -      throw new ParseFailedException("Expected -n<domain_id>");
    6.16 +        if (domain_id == 0) {
    6.17 +            throw new ParseFailedException("Expected -n<domain_id>");
    6.18 +        }
    6.19 +
    6.20 +        String output = new CommandDomainStart(d, domain_id).execute();
    6.21 +        if (output != null)
    6.22 +            System.out.println(output);
    6.23      }
    6.24  
    6.25 -    String output = new CommandDomainStart(d, domain_id).execute();
    6.26 -    if ( output != null )
    6.27 -      System.out.println( output );
    6.28 -  }
    6.29 -
    6.30 -  public String getName()
    6.31 -  {
    6.32 -    return "start";
    6.33 -  }
    6.34 +    public String getName() {
    6.35 +        return "start";
    6.36 +    }
    6.37  
    6.38 -  public String getUsage()
    6.39 -  {
    6.40 -    return "[-n<domain_id>]";
    6.41 -  }
    6.42 +    public String getUsage() {
    6.43 +        return "-n<domain_id>";
    6.44 +    }
    6.45  
    6.46 -  public String getHelpText()
    6.47 -  {
    6.48 -    return
    6.49 -      "Start the specified domain.";
    6.50 -  }
    6.51 +    public String getHelpText() {
    6.52 +        return "Start the specified domain.";
    6.53 +    }
    6.54  }
     7.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java	Wed Jul 09 10:58:27 2003 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java	Wed Jul 09 10:58:38 2003 +0000
     7.3 @@ -7,32 +7,28 @@ import org.xenoserver.control.CommandFai
     7.4  import org.xenoserver.control.Defaults;
     7.5  
     7.6  public class ParseDomainStop extends CommandParser {
     7.7 +    public void parse(Defaults d, LinkedList args)
     7.8 +        throws ParseFailedException, CommandFailedException {
     7.9 +        int domain_id = getIntParameter(args, 'n', 0);
    7.10  
    7.11 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    7.12 -    int domain_id = getIntParameter(args, 'n', 0);
    7.13 -    
    7.14 -    if (domain_id == 0) {
    7.15 -      throw new ParseFailedException("Expected -n<domain_id>");
    7.16 +        if (domain_id == 0) {
    7.17 +            throw new ParseFailedException("Expected -n<domain_id>");
    7.18 +        }
    7.19 +
    7.20 +        String output = new CommandDomainStop(d, domain_id).execute();
    7.21 +        if (output != null)
    7.22 +            System.out.println(output);
    7.23      }
    7.24  
    7.25 -    String output = new CommandDomainStop(d, domain_id).execute();
    7.26 -    if ( output != null )
    7.27 -      System.out.println( output );
    7.28 -  }
    7.29 -
    7.30 -  public String getName()
    7.31 -  {
    7.32 -    return "stop";
    7.33 -  }
    7.34 +    public String getName() {
    7.35 +        return "stop";
    7.36 +    }
    7.37  
    7.38 -  public String getUsage()
    7.39 -  {
    7.40 -    return "[-n<domain_id>]";
    7.41 -  }
    7.42 +    public String getUsage() {
    7.43 +        return "-n<domain_id>";
    7.44 +    }
    7.45  
    7.46 -  public String getHelpText()
    7.47 -  {
    7.48 -    return
    7.49 -      "Stop the specified domain.";
    7.50 -  }
    7.51 +    public String getHelpText() {
    7.52 +        return "Stop the specified domain.";
    7.53 +    }
    7.54  }
     8.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java	Wed Jul 09 10:58:27 2003 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java	Wed Jul 09 10:58:38 2003 +0000
     8.3 @@ -4,19 +4,11 @@ package org.xenoserver.cmdline;
     8.4   * Thrown when a command line could not be parsed.
     8.5   */
     8.6  public class ParseFailedException extends Exception {
     8.7 -  public ParseFailedException() {
     8.8 -    super();
     8.9 -  }
    8.10 -
    8.11 -  public ParseFailedException(String message) {
    8.12 -    super(message);
    8.13 -  }
    8.14 +    public ParseFailedException(String message) {
    8.15 +        super(message);
    8.16 +    }
    8.17  
    8.18 -  public ParseFailedException(String message, Throwable cause) {
    8.19 -    super(message, cause);
    8.20 -  }
    8.21 -
    8.22 -  public ParseFailedException(Throwable cause) {
    8.23 -    super(cause);
    8.24 -  }
    8.25 +    public ParseFailedException(String message, Throwable cause) {
    8.26 +        super(message, cause);
    8.27 +    }
    8.28  }
     9.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseGroup.java	Wed Jul 09 10:58:27 2003 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseGroup.java	Wed Jul 09 10:58:38 2003 +0000
     9.3 @@ -5,69 +5,90 @@ import java.util.LinkedList;
     9.4  import org.xenoserver.control.CommandFailedException;
     9.5  import org.xenoserver.control.Defaults;
     9.6  
     9.7 +/**
     9.8 + * Parses a group of commands; taking the first argument, it searches its
     9.9 + * array of commands until it finds a match, and then, removing the matched
    9.10 + * argument from the command line, invokes it. This allows hierarchical
    9.11 + * parsing.
    9.12 + */
    9.13  public class ParseGroup extends CommandParser {
    9.14 -  private final String name;
    9.15 -  private final CommandParser[] commands;
    9.16 -  
    9.17 -  /**
    9.18 -   * Constructor for ParseGroup.
    9.19 -   * @param name Name of this group of commands
    9.20 -   * @param commands Array of commands to include
    9.21 -   */
    9.22 -  public ParseGroup(String name, CommandParser[] commands) {
    9.23 -    this.name = name;
    9.24 -    this.commands = commands;
    9.25 -  }
    9.26 +    /** Name of this group, i.e. the prefix to the command line */
    9.27 +    private final String name;
    9.28 +    /** The commands this group will attempt to match its arguments against. */
    9.29 +    private final CommandParser[] commands;
    9.30  
    9.31 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    9.32 -    int i;
    9.33 -    String c = (String) args.removeFirst();
    9.34 -    for (i = 0; i < commands.length; i++) {
    9.35 -      if (commands[i].getName().equals(c)) {
    9.36 -        if (!args.isEmpty() && args.getFirst().equals("-?")) {
    9.37 -          commands[i].printHelpText(null);
    9.38 -        } else {
    9.39 -          commands[i].parse(d, args);
    9.40 -        }
    9.41 -        break;
    9.42 -      }
    9.43 +    /**
    9.44 +     * Constructor for ParseGroup.
    9.45 +     * @param name Name of this group of commands
    9.46 +     * @param commands Array of commands to include
    9.47 +     */
    9.48 +    public ParseGroup(String name, CommandParser[] commands) {
    9.49 +        this.name = name;
    9.50 +        this.commands = commands;
    9.51      }
    9.52 -    if (i == commands.length) {
    9.53 -      throw new ParseFailedException("Unknown command " + c);
    9.54 -    }
    9.55 -  }
    9.56  
    9.57 -  public String getName() {
    9.58 -    return name;
    9.59 -  }
    9.60 +    public void parse(Defaults d, LinkedList args)
    9.61 +        throws ParseFailedException, CommandFailedException {
    9.62 +        if (args.isEmpty()) {
    9.63 +            Main.help.parse(null,null);
    9.64 +            return;
    9.65 +        }
    9.66 +        
    9.67 +        int i;
    9.68 +        String c = (String) args.removeFirst();
    9.69 +        for (i = 0; i < commands.length; i++) {
    9.70 +            if (commands[i].getName().equals(c)) {
    9.71 +                if (!args.isEmpty() && args.getFirst().equals("-?")) {
    9.72 +                    commands[i].printHelpText(null);
    9.73 +                } else {
    9.74 +                    commands[i].parse(d, args);
    9.75 +                }
    9.76 +                break;
    9.77 +            }
    9.78 +        }
    9.79 +        if (i == commands.length) {
    9.80 +            throw new ParseFailedException("Unknown command " + c);
    9.81 +        }
    9.82 +    }
    9.83  
    9.84 -  public String getUsage() {
    9.85 -    return null;
    9.86 -  }
    9.87 +    public String getName() {
    9.88 +        return name;
    9.89 +    }
    9.90  
    9.91 -  public String getHelpText() {
    9.92 -    return null;
    9.93 -  }
    9.94 +    public String getUsage() {
    9.95 +        return null;
    9.96 +    }
    9.97  
    9.98 -  public void printUsage(String prefix) {
    9.99 -    if ( prefix == null )
   9.100 -      prefix = name;
   9.101 -    else
   9.102 -      prefix += " " + name;
   9.103 -    for ( int i=0; i<commands.length; i++ )
   9.104 -      commands[i].printUsage(prefix);
   9.105 -  }
   9.106 +    public String getHelpText() {
   9.107 +        return null;
   9.108 +    }
   9.109 +
   9.110 +    public void printUsage(String prefix) {
   9.111 +        if (prefix == null) {
   9.112 +            prefix = name;
   9.113 +        } else {
   9.114 +            prefix += " " + name;
   9.115 +        }
   9.116 +        for (int i = 0; i < commands.length; i++) {
   9.117 +            commands[i].printUsage(prefix);
   9.118 +        }
   9.119 +    }
   9.120  
   9.121 -  public void printHelpText(LinkedList args) {
   9.122 -    if ( name != null )
   9.123 -      System.out.print( name + " " );
   9.124 -    int i;
   9.125 -    String c = (String) args.removeFirst();
   9.126 -    for (i = 0; i < commands.length; i++) {
   9.127 -      if (commands[i].getName().equals(c)) {
   9.128 -        commands[i].printHelpText(args);
   9.129 -        break;
   9.130 -      }
   9.131 +    public void printHelpText(LinkedList args) {
   9.132 +        if (args == null) {
   9.133 +            Main.help.parse(null,null);
   9.134 +            return;            
   9.135 +        }
   9.136 +        if (name != null) {
   9.137 +            System.out.print(name + " ");
   9.138 +        }
   9.139 +        int i;
   9.140 +        String c = (String) args.removeFirst();
   9.141 +        for (i = 0; i < commands.length; i++) {
   9.142 +            if (commands[i].getName().equals(c)) {
   9.143 +                commands[i].printHelpText(args);
   9.144 +                break;
   9.145 +            }
   9.146 +        }
   9.147      }
   9.148 -  }
   9.149  }
    10.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseHelp.java	Wed Jul 09 10:58:27 2003 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java	Wed Jul 09 10:58:38 2003 +0000
    10.3 @@ -5,31 +5,27 @@ import java.util.LinkedList;
    10.4  import org.xenoserver.control.Defaults;
    10.5  
    10.6  public class ParseHelp extends CommandParser {
    10.7 +    public void parse(Defaults d, LinkedList args) {
    10.8 +        if (args == null || args.isEmpty()) {
    10.9 +            System.out.println("Usage:");
   10.10 +            Main.parser.printUsage(null);
   10.11 +        } else {
   10.12 +            System.out.print("xenctl ");
   10.13 +            Main.parser.printHelpText(args);
   10.14 +        }
   10.15  
   10.16 -  public void parse(Defaults d, LinkedList args) {
   10.17 -    if (args.size() == 0) {
   10.18 -      System.out.println("Usage:");
   10.19 -      Main.parser.printUsage(null);
   10.20 -    } else {
   10.21 -      System.out.print("xenctl ");
   10.22 -      Main.parser.printHelpText(args);
   10.23 +        System.out.println("");
   10.24      }
   10.25  
   10.26 -    System.out.println("");
   10.27 -  }
   10.28 -  
   10.29 -  public String getName()
   10.30 -  {
   10.31 -    return "help";
   10.32 -  }
   10.33 +    public String getName() {
   10.34 +        return "help";
   10.35 +    }
   10.36  
   10.37 -  public String getUsage()
   10.38 -  {
   10.39 -    return "";
   10.40 -  }
   10.41 +    public String getUsage() {
   10.42 +        return "[<any command>]";
   10.43 +    }
   10.44  
   10.45 -  public String getHelpText()
   10.46 -  {
   10.47 -    return "This message";
   10.48 -  }  
   10.49 +    public String getHelpText() {
   10.50 +        return "This message, or if a command is specified, help for that command.";
   10.51 +    }
   10.52  }
    11.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java	Wed Jul 09 10:58:27 2003 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java	Wed Jul 09 10:58:38 2003 +0000
    11.3 @@ -6,51 +6,38 @@ import org.xenoserver.control.CommandFai
    11.4  import org.xenoserver.control.CommandPartitionAdd;
    11.5  import org.xenoserver.control.Defaults;
    11.6  import org.xenoserver.control.Library;
    11.7 -import org.xenoserver.control.Partition;
    11.8 -import org.xenoserver.control.PartitionManager;
    11.9 -import org.xenoserver.control.Settings;
   11.10  
   11.11  public class ParsePartitionsAdd extends CommandParser {
   11.12 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   11.13 -    boolean force = getFlagParameter(args, 'f');
   11.14 -    String partition_name = getStringParameter(args, 'p', "");
   11.15 -    String size = getStringParameter(args, 'c', "100M");
   11.16 -    
   11.17 -    if (partition_name.equals(""))
   11.18 -      throw new ParseFailedException("Expected -p<partition_name>");
   11.19 -      
   11.20 -    long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE;
   11.21 -    if ( chunksize <= 0 )
   11.22 -      throw new CommandFailedException("Chunk size " + size + " is smaller than sector size.");
   11.23 -    
   11.24 -    // Initialise the partition manager and look up the partition
   11.25 -    loadState();
   11.26 -    Partition p = PartitionManager.IT.getPartition(partition_name);
   11.27 -    
   11.28 -    if ( p == null )
   11.29 -      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
   11.30 -    
   11.31 -    // Check if this partition belongs to the VDM
   11.32 -    if (p.isXeno() && !force)
   11.33 -      throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
   11.34 -    
   11.35 -    String output = new CommandPartitionAdd( p, chunksize ).execute();
   11.36 -    if ( output != null )
   11.37 -      System.out.println( output );
   11.38 -      
   11.39 -    saveState();
   11.40 -  }
   11.41 +    public void parse(Defaults d, LinkedList args)
   11.42 +        throws ParseFailedException, CommandFailedException {
   11.43 +        boolean force = getFlagParameter(args, 'f');
   11.44 +        String partition_name = getStringParameter(args, 'p', "");
   11.45 +        String size = getStringParameter(args, 'c', "128M");
   11.46 +
   11.47 +        if (partition_name.equals("")) {
   11.48 +            throw new ParseFailedException("Expected -p<partition_name>");
   11.49 +        }
   11.50  
   11.51 -  public String getName() {
   11.52 -    return "add";
   11.53 -  }
   11.54 +        loadState();
   11.55 +        String output =
   11.56 +            new CommandPartitionAdd(partition_name, Library.parseSize(size),force)
   11.57 +                .execute();
   11.58 +        if (output != null) {
   11.59 +            System.out.println(output);
   11.60 +        }
   11.61 +        saveState();
   11.62 +    }
   11.63  
   11.64 -  public String getUsage() {
   11.65 -    return "[-f] [-p<partition_name>] [-c<chunk_size>]";
   11.66 -  }
   11.67 +    public String getName() {
   11.68 +        return "add";
   11.69 +    }
   11.70  
   11.71 -  public String getHelpText() {
   11.72 -    return "Add the specified partition to the virtual disk manager's free\n" +
   11.73 -           "space. -c changes the default chunk size. -f forces add.";
   11.74 -  }
   11.75 +    public String getUsage() {
   11.76 +        return "-p<partition_name> [-f] [-c<chunk_size>]";
   11.77 +    }
   11.78 +
   11.79 +    public String getHelpText() {
   11.80 +        return "Add the specified partition to the virtual disk manager's free\n"
   11.81 +            + "space. -c changes the default chunk size. -f forces add.";
   11.82 +    }
   11.83  }
    12.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java	Wed Jul 09 10:58:27 2003 +0000
    12.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java	Wed Jul 09 10:58:38 2003 +0000
    12.3 @@ -10,45 +10,56 @@ import org.xenoserver.control.Partition;
    12.4  import org.xenoserver.control.PartitionManager;
    12.5  
    12.6  public class ParsePartitionsList extends CommandParser {
    12.7 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    12.8 -    loadState();
    12.9 -    Iterator i = PartitionManager.IT.iterator();
   12.10 -    int idx = 1;
   12.11 -    System.out.println( "     maj:min " + "    blocks " + "start sect " +
   12.12 -                        " num sects " + "name" );
   12.13 -    while (i.hasNext()) {
   12.14 -      Partition p = (Partition) i.next();
   12.15 +    public void parse(Defaults d, LinkedList args)
   12.16 +        throws ParseFailedException, CommandFailedException {
   12.17 +        loadState();
   12.18 +        Iterator i = PartitionManager.IT.iterator();
   12.19 +        int idx = 1;
   12.20 +        System.out.println(
   12.21 +            "     maj:min "
   12.22 +                + "    blocks "
   12.23 +                + "start sect "
   12.24 +                + " num sects "
   12.25 +                + "name");
   12.26 +        while (i.hasNext()) {
   12.27 +            Partition p = (Partition) i.next();
   12.28  
   12.29 -      if (p.isXeno()) {
   12.30 -        System.out.print("[ ");
   12.31 -      } else {
   12.32 -        System.out.print("  ");
   12.33 -      }
   12.34 -      System.out.print(Library.format(idx++, 2, false) + " ");
   12.35 -      System.out.print(Library.format(p.getMajor(),3,false) + ":" + 
   12.36 -          Library.format(p.getMinor(),3,true) + " " +
   12.37 -          Library.format(p.getBlocks(),10,false) + " " +
   12.38 -          Library.format(p.getStartSect(),10,false) + " " +
   12.39 -          Library.format(p.getNumSects(),10,false) + " " +
   12.40 -          Library.format(p.getName(),7,true));   
   12.41 -      if (p.isXeno()) {
   12.42 -        System.out.println("]");
   12.43 -      } else {
   12.44 -        System.out.println();
   12.45 -      }
   12.46 +            if (p.isXeno()) {
   12.47 +                System.out.print("[ ");
   12.48 +            } else {
   12.49 +                System.out.print("  ");
   12.50 +            }
   12.51 +            System.out.print(Library.format(idx++, 2, false) + " ");
   12.52 +            System.out.print(
   12.53 +                Library.format(p.getMajor(), 3, false)
   12.54 +                    + ":"
   12.55 +                    + Library.format(p.getMinor(), 3, true)
   12.56 +                    + " "
   12.57 +                    + Library.format(p.getBlocks(), 10, false)
   12.58 +                    + " "
   12.59 +                    + Library.format(p.getStartSect(), 10, false)
   12.60 +                    + " "
   12.61 +                    + Library.format(p.getNumSects(), 10, false)
   12.62 +                    + " "
   12.63 +                    + Library.format(p.getName(), 7, true));
   12.64 +            if (p.isXeno()) {
   12.65 +                System.out.println("]");
   12.66 +            } else {
   12.67 +                System.out.println();
   12.68 +            }
   12.69 +        }
   12.70      }
   12.71 -  }
   12.72  
   12.73 -  public String getName() {
   12.74 -    return "list";
   12.75 -  }
   12.76 +    public String getName() {
   12.77 +        return "list";
   12.78 +    }
   12.79  
   12.80 -  public String getUsage() {
   12.81 -    return "";
   12.82 -  }
   12.83 +    public String getUsage() {
   12.84 +        return "";
   12.85 +    }
   12.86  
   12.87 -  public String getHelpText() {
   12.88 -    return "List real partition information";
   12.89 -  }
   12.90 +    public String getHelpText() {
   12.91 +        return "List physical partition information. Partitions surrounded by [] are XenoPartitions.";
   12.92 +    }
   12.93  
   12.94  }
    13.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java	Wed Jul 09 10:58:27 2003 +0000
    13.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java	Wed Jul 09 10:58:38 2003 +0000
    13.3 @@ -6,54 +6,50 @@ import org.xenoserver.control.CommandFai
    13.4  import org.xenoserver.control.CommandPhysicalGrant;
    13.5  import org.xenoserver.control.Defaults;
    13.6  import org.xenoserver.control.Mode;
    13.7 -import org.xenoserver.control.Partition;
    13.8 -import org.xenoserver.control.PartitionManager;
    13.9  
   13.10  public class ParsePhysicalGrant extends CommandParser {
   13.11 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   13.12 -    int domain_id = getIntParameter(args, 'n', 0);
   13.13 -    boolean force = getFlagParameter(args, 'f');
   13.14 -    String partition_name = getStringParameter(args, 'p', "");
   13.15 -    boolean write = getFlagParameter(args, 'w');
   13.16 -    
   13.17 -    if (domain_id == 0)
   13.18 -      throw new ParseFailedException("Expected -n<domain_id>");
   13.19 -    if (partition_name.equals(""))
   13.20 -      throw new ParseFailedException("Expected -p<partition_name>");
   13.21 -      
   13.22 -    Mode mode;
   13.23 -    if (write)
   13.24 -      mode = Mode.READ_WRITE;
   13.25 -    else
   13.26 -      mode = Mode.READ_ONLY;
   13.27 -      
   13.28 -    // Initialise the partition manager and look up the partition
   13.29 -    loadState();
   13.30 -    Partition p = PartitionManager.IT.getPartition(partition_name);
   13.31 -    
   13.32 -    if ( p == null )
   13.33 -      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
   13.34 -    
   13.35 -    // Check if this partition belongs to the VDM
   13.36 -    if (p.isXeno() && !force)
   13.37 -      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.");
   13.38 -     
   13.39 -    String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute();
   13.40 -    if ( output != null )
   13.41 -      System.out.println( output );
   13.42 -  }
   13.43 +    public void parse(Defaults d, LinkedList args)
   13.44 +        throws ParseFailedException, CommandFailedException {
   13.45 +        int domain_id = getIntParameter(args, 'n', 0);
   13.46 +        boolean force = getFlagParameter(args, 'f');
   13.47 +        String partition_name = getStringParameter(args, 'p', "");
   13.48 +        boolean write = getFlagParameter(args, 'w');
   13.49 +
   13.50 +        if (domain_id == 0) {
   13.51 +            throw new ParseFailedException("Expected -n<domain_id>");
   13.52 +        }
   13.53 +        if (partition_name.equals("")) {
   13.54 +            throw new ParseFailedException("Expected -p<partition_name>");
   13.55 +        }
   13.56 +
   13.57 +        Mode mode;
   13.58 +        if (write) {
   13.59 +            mode = Mode.READ_WRITE;
   13.60 +        } else {
   13.61 +            mode = Mode.READ_ONLY;
   13.62 +        }
   13.63  
   13.64 -  public String getName() {
   13.65 -    return "grant";
   13.66 -  }
   13.67 +        // Initialise the partition manager and look up the partition
   13.68 +        loadState();
   13.69 +        String output =
   13.70 +            new CommandPhysicalGrant(d, domain_id, partition_name, mode, force)
   13.71 +                .execute();
   13.72 +        if (output != null) {
   13.73 +            System.out.println(output);
   13.74 +        }
   13.75 +    }
   13.76  
   13.77 -  public String getUsage() {
   13.78 -    return "[-f] [-w] [-n<domain_id>] [-p<partition_name>]";
   13.79 -  }
   13.80 +    public String getName() {
   13.81 +        return "grant";
   13.82 +    }
   13.83  
   13.84 -  public String getHelpText() {
   13.85 -    return "Grant the specified domain access to the given partition.  -w grants" +
   13.86 -           " read-write instead of read-only.  -f forcibly grants access.";
   13.87 -  }
   13.88 +    public String getUsage() {
   13.89 +        return "-n<domain_id> -p<partition_name> [-f] [-w]";
   13.90 +    }
   13.91 +
   13.92 +    public String getHelpText() {
   13.93 +        return "Grant the specified domain access to the given partition.  -w grants"
   13.94 +            + " read-write instead of read-only.  -f forcibly grants access.";
   13.95 +    }
   13.96  
   13.97  }
    14.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java	Wed Jul 09 10:58:27 2003 +0000
    14.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java	Wed Jul 09 10:58:38 2003 +0000
    14.3 @@ -13,59 +13,82 @@ import org.xenoserver.control.Partition;
    14.4  import org.xenoserver.control.PartitionManager;
    14.5  
    14.6  public class ParsePhysicalList extends CommandParser {
    14.7 +    public void parse(Defaults d, LinkedList args)
    14.8 +        throws ParseFailedException, CommandFailedException {
    14.9 +        int domain_id = getIntParameter(args, 'n', 0);
   14.10 +        if (domain_id == 0) {
   14.11 +            throw new ParseFailedException("Expected -n<domain_id>");
   14.12 +        }
   14.13  
   14.14 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   14.15 -    int domain_id = getIntParameter(args, 'n', 0);
   14.16 -    if (domain_id == 0)
   14.17 -      throw new ParseFailedException("Expected -n<domain_id>");
   14.18 +        // Initialise the partition manager
   14.19 +        loadState();
   14.20 +
   14.21 +        CommandPhysicalList list = new CommandPhysicalList(d, domain_id);
   14.22 +        String output = list.execute();
   14.23 +        if (output != null) {
   14.24 +            System.out.println(output);
   14.25 +        }
   14.26  
   14.27 -    // Initialise the partition manager
   14.28 -    loadState();
   14.29 -    
   14.30 -    CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
   14.31 -    String output = list.execute();
   14.32 -    if ( output != null )
   14.33 -      System.out.println( output );
   14.34 -      
   14.35 -    System.out.println( "maj:min " + "    blocks " + "start sect " +
   14.36 -                        " num sects " + "name    " + "access" );
   14.37 -    Iterator i = list.extents().entrySet().iterator();
   14.38 -    while ( i.hasNext() )
   14.39 -    {
   14.40 -      Entry entry = (Entry) i.next(); 
   14.41 -      Extent e = (Extent) entry.getKey();
   14.42 -      String mode = entry.getValue().toString();
   14.43 -      Partition p = PartitionManager.IT.getPartition( e );
   14.44 -      if ( p != null ) {
   14.45 -        System.out.println(Library.format(p.getMajor(),3,false) + ":" + 
   14.46 -          Library.format(p.getMinor(),3,true) + " " +
   14.47 -          Library.format(p.getBlocks(),10,false) + " " +
   14.48 -          Library.format(p.getStartSect(),10,false) + " " +
   14.49 -          Library.format(p.getNumSects(),10,false) + " " +
   14.50 -          Library.format(p.getName(),7,true) + " " +
   14.51 -          Library.format(mode,2,true));   
   14.52 -      } else {
   14.53 -        System.out.println(Library.format(e.getMajor(),3,false) + ":" +
   14.54 -          Library.format(e.getMinor(),3,true) + " " +
   14.55 -          "          " + " " +
   14.56 -          Library.format(e.getOffset(),10,false) + " " +
   14.57 -          Library.format(e.getSize(),10,false) + " " +
   14.58 -          "       " + " " +
   14.59 -          Library.format(mode,2,true));
   14.60 -      }
   14.61 +        System.out.println(
   14.62 +            "maj:min "
   14.63 +                + "    blocks "
   14.64 +                + "start sect "
   14.65 +                + " num sects "
   14.66 +                + "name    "
   14.67 +                + "access");
   14.68 +        Iterator i = list.extents().entrySet().iterator();
   14.69 +        while (i.hasNext()) {
   14.70 +            Entry entry = (Entry) i.next();
   14.71 +            Extent e = (Extent) entry.getKey();
   14.72 +            String mode = entry.getValue().toString();
   14.73 +            Partition p = PartitionManager.IT.getPartition(e);
   14.74 +            if (p != null) {
   14.75 +                System.out.println(
   14.76 +                    Library.format(p.getMajor(), 3, false)
   14.77 +                        + ":"
   14.78 +                        + Library.format(p.getMinor(), 3, true)
   14.79 +                        + " "
   14.80 +                        + Library.format(p.getBlocks(), 10, false)
   14.81 +                        + " "
   14.82 +                        + Library.format(p.getStartSect(), 10, false)
   14.83 +                        + " "
   14.84 +                        + Library.format(p.getNumSects(), 10, false)
   14.85 +                        + " "
   14.86 +                        + Library.format(p.getName(), 7, true)
   14.87 +                        + " "
   14.88 +                        + Library.format(mode, 2, true));
   14.89 +            } else {
   14.90 +                System.out.println(
   14.91 +                    Library.format(e.getMajor(), 3, false)
   14.92 +                        + ":"
   14.93 +                        + Library.format(
   14.94 +                            e.getMinor() | e.getPartitionNo(),
   14.95 +                            3,
   14.96 +                            true)
   14.97 +                        + " "
   14.98 +                        + "          "
   14.99 +                        + " "
  14.100 +                        + Library.format(e.getOffset(), 10, false)
  14.101 +                        + " "
  14.102 +                        + Library.format(e.getSize(), 10, false)
  14.103 +                        + " "
  14.104 +                        + "       "
  14.105 +                        + " "
  14.106 +                        + Library.format(mode, 2, true));
  14.107 +            }
  14.108 +        }
  14.109      }
  14.110 -  }
  14.111  
  14.112 -  public String getName() {
  14.113 -    return "list";
  14.114 -  }
  14.115 +    public String getName() {
  14.116 +        return "list";
  14.117 +    }
  14.118  
  14.119 -  public String getUsage() {
  14.120 -    return "[-n<domain_id>]";
  14.121 -  }
  14.122 +    public String getUsage() {
  14.123 +        return "-n<domain_id>";
  14.124 +    }
  14.125  
  14.126 -  public String getHelpText() {
  14.127 -    return "List all physical access which the given domain has been granted.";
  14.128 -  }
  14.129 +    public String getHelpText() {
  14.130 +        return "List all physical access which the given domain has been granted.";
  14.131 +    }
  14.132  
  14.133  }
    15.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java	Wed Jul 09 10:58:27 2003 +0000
    15.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java	Wed Jul 09 10:58:38 2003 +0000
    15.3 @@ -5,41 +5,38 @@ import java.util.LinkedList;
    15.4  import org.xenoserver.control.CommandFailedException;
    15.5  import org.xenoserver.control.CommandPhysicalRevoke;
    15.6  import org.xenoserver.control.Defaults;
    15.7 -import org.xenoserver.control.Partition;
    15.8 -import org.xenoserver.control.PartitionManager;
    15.9  
   15.10  public class ParsePhysicalRevoke extends CommandParser {
   15.11 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   15.12 -    int domain_id = getIntParameter(args, 'n', 0);
   15.13 -    String partition_name = getStringParameter(args, 'p', "");
   15.14 -    
   15.15 -    if (domain_id == 0)
   15.16 -      throw new ParseFailedException("Expected -n<domain_id>");
   15.17 -    if (partition_name.equals(""))
   15.18 -      throw new ParseFailedException("Expected -p<partition_name>");
   15.19 -      
   15.20 -    // Initialise the partition manager and look up the partition
   15.21 -    loadState();
   15.22 -    Partition p = PartitionManager.IT.getPartition(partition_name);
   15.23 -    
   15.24 -    if ( p == null )
   15.25 -      throw new CommandFailedException("Partition " + partition_name + " does not exist.");
   15.26 +    public void parse(Defaults d, LinkedList args)
   15.27 +        throws ParseFailedException, CommandFailedException {
   15.28 +        int domain_id = getIntParameter(args, 'n', 0);
   15.29 +        String partition_name = getStringParameter(args, 'p', "");
   15.30 +
   15.31 +        if (domain_id == 0) {
   15.32 +            throw new ParseFailedException("Expected -n<domain_id>");
   15.33 +        }
   15.34 +        if (partition_name.equals("")) {
   15.35 +            throw new ParseFailedException("Expected -p<partition_name>");
   15.36 +        }
   15.37  
   15.38 -    String output = new CommandPhysicalRevoke( d, domain_id, p ).execute();
   15.39 -    if ( output != null )
   15.40 -      System.out.println( output );
   15.41 -  }
   15.42 +        // Initialise the partition manager and look up the partition
   15.43 +        loadState();
   15.44 +        String output = new CommandPhysicalRevoke(d, domain_id, partition_name).execute();
   15.45 +        if (output != null) {
   15.46 +            System.out.println(output);
   15.47 +        }
   15.48 +    }
   15.49  
   15.50 -  public String getName() {
   15.51 -    return "revoke";
   15.52 -  }
   15.53 +    public String getName() {
   15.54 +        return "revoke";
   15.55 +    }
   15.56  
   15.57 -  public String getUsage() {
   15.58 -    return "[-n<domain_id>] [-p<partition_name>]";
   15.59 -  }
   15.60 +    public String getUsage() {
   15.61 +        return "-n<domain_id> -p<partition_name>";
   15.62 +    }
   15.63  
   15.64 -  public String getHelpText() {
   15.65 -    return "Revoke access to the given partition from the specified domain.";
   15.66 -  }
   15.67 +    public String getHelpText() {
   15.68 +        return "Revoke access to the given partition from the specified domain.";
   15.69 +    }
   15.70  
   15.71  }
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java	Wed Jul 09 10:58:38 2003 +0000
    16.3 @@ -0,0 +1,65 @@
    16.4 +package org.xenoserver.cmdline;
    16.5 +
    16.6 +import java.util.LinkedList;
    16.7 +
    16.8 +import org.xenoserver.control.CommandFailedException;
    16.9 +import org.xenoserver.control.CommandVbdCreate;
   16.10 +import org.xenoserver.control.CommandVbdCreatePhysical;
   16.11 +import org.xenoserver.control.Defaults;
   16.12 +import org.xenoserver.control.Mode;
   16.13 +
   16.14 +public class ParseVbdCreate extends CommandParser {
   16.15 +    public void parse(Defaults d, LinkedList args)
   16.16 +        throws ParseFailedException, CommandFailedException {
   16.17 +        String vd_key = getStringParameter(args, 'k', "");
   16.18 +        String partition_name = getStringParameter(args, 'p', "");
   16.19 +        int domain_id = getIntParameter(args, 'n', 0);
   16.20 +        int vbd_num = getIntParameter(args, 'v', -1);
   16.21 +        boolean write = getFlagParameter(args, 'w');
   16.22 +
   16.23 +        if (vd_key.equals("") && partition_name.equals("")) {
   16.24 +            throw new ParseFailedException("Expected -k<key> or -p<partition>");
   16.25 +        }
   16.26 +        if (domain_id == 0) {
   16.27 +            throw new ParseFailedException("Expected -n<domain_id>");
   16.28 +        }
   16.29 +        if (vbd_num == -1) {
   16.30 +            throw new ParseFailedException("Expected -v<vbd_num>");
   16.31 +        }
   16.32 +
   16.33 +        Mode mode;
   16.34 +        if (write) {
   16.35 +            mode = Mode.READ_WRITE;
   16.36 +        } else {
   16.37 +            mode = Mode.READ_ONLY;
   16.38 +        }
   16.39 +
   16.40 +        loadState();
   16.41 +        String output;
   16.42 +        if (vd_key.equals("")) {
   16.43 +            output = new CommandVbdCreatePhysical( partition_name, domain_id, vbd_num, mode ).execute();
   16.44 +        } else {
   16.45 +            output =
   16.46 +                new CommandVbdCreate(vd_key, domain_id, vbd_num, mode).execute();
   16.47 +        }
   16.48 +        if (output != null) {
   16.49 +            System.out.println(output);
   16.50 +        }
   16.51 +        saveState();
   16.52 +    }
   16.53 +
   16.54 +    public String getName() {
   16.55 +        return "create";
   16.56 +    }
   16.57 +
   16.58 +    public String getUsage() {
   16.59 +        return "-n<domain_id> {-k<key>|-p<partition} -v<vbd_num> [-w]";
   16.60 +    }
   16.61 +
   16.62 +    public String getHelpText() {
   16.63 +        return "Create a new virtual block device binding the virtual disk with\n"
   16.64 +            + "the specified key to the domain and VBD number given. Add -w to\n"
   16.65 +            + "allow read-write access.";
   16.66 +    }
   16.67 +
   16.68 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java	Wed Jul 09 10:58:38 2003 +0000
    17.3 @@ -0,0 +1,41 @@
    17.4 +package org.xenoserver.cmdline;
    17.5 +
    17.6 +import java.util.Iterator;
    17.7 +import java.util.LinkedList;
    17.8 +
    17.9 +import org.xenoserver.control.CommandFailedException;
   17.10 +import org.xenoserver.control.Defaults;
   17.11 +import org.xenoserver.control.Library;
   17.12 +import org.xenoserver.control.VirtualBlockDevice;
   17.13 +import org.xenoserver.control.VirtualDiskManager;
   17.14 +
   17.15 +public class ParseVbdShow extends CommandParser {
   17.16 +    public void parse(Defaults d, LinkedList args)
   17.17 +        throws ParseFailedException, CommandFailedException {
   17.18 +        loadState();
   17.19 +        Iterator i = VirtualDiskManager.IT.getVirtualBlockDevices();
   17.20 +        System.out.println("key         dom vbd mode");
   17.21 +        while (i.hasNext()) {
   17.22 +            VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
   17.23 +            System.out.println( vbd.getVirtualDisk().getKey()
   17.24 +                    + "  "
   17.25 +                    + Library.format(vbd.getDomain(), 3, false)
   17.26 +                    + " "
   17.27 +                    + Library.format(vbd.getVbdNum(), 3, false)
   17.28 +                    + " "
   17.29 +                    + vbd.getMode().toString());
   17.30 +        }
   17.31 +    }
   17.32 +
   17.33 +    public String getName() {
   17.34 +        return "show";
   17.35 +    }
   17.36 +
   17.37 +    public String getUsage() {
   17.38 +        return "";
   17.39 +    }
   17.40 +
   17.41 +    public String getHelpText() {
   17.42 +        return "Show details of all mapped virtual block devices.";
   17.43 +    }
   17.44 +}
    18.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java	Wed Jul 09 10:58:27 2003 +0000
    18.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java	Wed Jul 09 10:58:38 2003 +0000
    18.3 @@ -1,5 +1,7 @@
    18.4  package org.xenoserver.cmdline;
    18.5  
    18.6 +import java.text.DateFormat;
    18.7 +import java.text.ParseException;
    18.8  import java.util.Date;
    18.9  import java.util.LinkedList;
   18.10  
   18.11 @@ -7,43 +9,52 @@ import org.xenoserver.control.CommandFai
   18.12  import org.xenoserver.control.CommandVdCreate;
   18.13  import org.xenoserver.control.Defaults;
   18.14  import org.xenoserver.control.Library;
   18.15 -import org.xenoserver.control.Settings;
   18.16  
   18.17  public class ParseVdCreate extends CommandParser {
   18.18 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   18.19 -    String name = getStringParameter(args,'n',"");
   18.20 -    String size_s = getStringParameter(args,'s',"");
   18.21 -    String expiry_s = getStringParameter(args,'e',"");
   18.22 -    Date expiry;
   18.23 -    
   18.24 -    if ( name.equals("") )
   18.25 -      throw new ParseFailedException("Expected -n<name>");
   18.26 -    if ( size_s.equals("") )
   18.27 -      throw new ParseFailedException("Expected -s<size>");
   18.28 -    if ( expiry_s.equals("") )
   18.29 -      expiry = null;
   18.30 -    else
   18.31 -      expiry = new Date(Date.parse(expiry_s));
   18.32 -      
   18.33 -    long size = Library.parseSize(size_s);
   18.34 -    
   18.35 -    loadState();
   18.36 -    String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute();
   18.37 -    if ( output != null )
   18.38 -      System.out.println( output );
   18.39 -    saveState();
   18.40 -  }
   18.41 +    public void parse(Defaults d, LinkedList args)
   18.42 +        throws ParseFailedException, CommandFailedException {
   18.43 +        String name = getStringParameter(args, 'n', "");
   18.44 +        String size_s = getStringParameter(args, 's', "");
   18.45 +        String expiry_s = getStringParameter(args, 'e', "");
   18.46 +        Date expiry;
   18.47  
   18.48 -  public String getName() {
   18.49 -    return "create";
   18.50 -  }
   18.51 +        if (name.equals("")) {
   18.52 +            throw new ParseFailedException("Expected -n<name>");
   18.53 +        }
   18.54 +        if (size_s.equals("")) {
   18.55 +            throw new ParseFailedException("Expected -s<size>");
   18.56 +        }
   18.57 +        if (expiry_s.equals("")) {
   18.58 +            expiry = null;
   18.59 +        } else {
   18.60 +            DateFormat format = DateFormat.getDateTimeInstance();
   18.61 +            try {
   18.62 +                expiry = format.parse(expiry_s);
   18.63 +            } catch (ParseException e) {
   18.64 +                throw new ParseFailedException("Could not parse date");
   18.65 +            }
   18.66 +        }
   18.67 +
   18.68 +        long size = Library.parseSize(size_s);
   18.69  
   18.70 -  public String getUsage() {
   18.71 -    return "[-n<name>] [-s<size>] [-e<expiry>]";
   18.72 -  }
   18.73 +        loadState();
   18.74 +        String output = new CommandVdCreate(name, size, expiry).execute();
   18.75 +        if (output != null) {
   18.76 +            System.out.println(output);
   18.77 +        }
   18.78 +        saveState();
   18.79 +    }
   18.80  
   18.81 -  public String getHelpText() {
   18.82 -    return "Create a new virtual disk with the specified parameters";
   18.83 -  }
   18.84 +    public String getName() {
   18.85 +        return "create";
   18.86 +    }
   18.87 +
   18.88 +    public String getUsage() {
   18.89 +        return "-n<name> -s<size> [-e<expiry>]";
   18.90 +    }
   18.91 +
   18.92 +    public String getHelpText() {
   18.93 +        return "Create a new virtual disk with the specified parameters";
   18.94 +    }
   18.95  
   18.96  }
    19.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java	Wed Jul 09 10:58:27 2003 +0000
    19.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java	Wed Jul 09 10:58:38 2003 +0000
    19.3 @@ -5,36 +5,35 @@ import java.util.LinkedList;
    19.4  import org.xenoserver.control.CommandFailedException;
    19.5  import org.xenoserver.control.CommandVdDelete;
    19.6  import org.xenoserver.control.Defaults;
    19.7 -import org.xenoserver.control.VirtualDiskManager;
    19.8  
    19.9  public class ParseVdDelete extends CommandParser {
   19.10 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   19.11 -    String vd_key = getStringParameter(args,'k',"");
   19.12 -    
   19.13 -    if ( vd_key.equals("") )
   19.14 -      throw new ParseFailedException("Expected -k<key>");
   19.15 -    
   19.16 -    loadState();
   19.17 -    if ( VirtualDiskManager.IT.getVirtualDisk(vd_key) == null )
   19.18 -      throw new CommandFailedException("Virtual disk " + vd_key + " does not exist");
   19.19 -      
   19.20 -    String output = new CommandVdDelete(vd_key).execute();
   19.21 -    if ( output != null )
   19.22 -      System.out.println( output );
   19.23 -      
   19.24 -    saveState();
   19.25 -  }
   19.26 +    public void parse(Defaults d, LinkedList args)
   19.27 +        throws ParseFailedException, CommandFailedException {
   19.28 +        String vd_key = getStringParameter(args, 'k', "");
   19.29 +
   19.30 +        if (vd_key.equals("")) {
   19.31 +            throw new ParseFailedException("Expected -k<key>");
   19.32 +        }
   19.33 +
   19.34 +        loadState();
   19.35 +        String output = new CommandVdDelete(vd_key).execute();
   19.36 +        if (output != null) {
   19.37 +            System.out.println(output);
   19.38 +        }
   19.39  
   19.40 -  public String getName() {
   19.41 -    return "delete";
   19.42 -  }
   19.43 +        saveState();
   19.44 +    }
   19.45 +
   19.46 +    public String getName() {
   19.47 +        return "delete";
   19.48 +    }
   19.49  
   19.50 -  public String getUsage() {
   19.51 -    return "[-k<key>]";
   19.52 -  }
   19.53 +    public String getUsage() {
   19.54 +        return "-k<key>";
   19.55 +    }
   19.56  
   19.57 -  public String getHelpText() {
   19.58 -    return "Deletes the virtual disk with the specified key.";
   19.59 -  }
   19.60 +    public String getHelpText() {
   19.61 +        return "Deletes the virtual disk with the specified key.";
   19.62 +    }
   19.63  
   19.64  }
    20.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java	Wed Jul 09 10:58:27 2003 +0000
    20.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java	Wed Jul 09 10:58:38 2003 +0000
    20.3 @@ -12,34 +12,44 @@ import org.xenoserver.control.VirtualDis
    20.4  import org.xenoserver.control.VirtualDiskManager;
    20.5  
    20.6  public class ParseVdFree extends CommandParser {
    20.7 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    20.8 -    boolean verbose = getFlagParameter(args, 'v');
    20.9 -    
   20.10 -    loadState();
   20.11 -    VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
   20.12 -    System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling "
   20.13 -                      + Library.formatSize(free.getSize()*Settings.SECTOR_SIZE,8,true) );
   20.14 -    if ( verbose ) {
   20.15 -      Iterator i = free.extents();
   20.16 -      System.out.println("  disk       offset         size");
   20.17 -      while (i.hasNext()) {
   20.18 -        Extent e = (Extent) i.next();
   20.19 -        System.out.println( Library.format(e.getDisk(), 6, false) + " "
   20.20 -                          + Library.format(e.getOffset(), 12, false) + " "
   20.21 -                          + Library.format(e.getSize(), 12, false) );
   20.22 -      }
   20.23 +    public void parse(Defaults d, LinkedList args)
   20.24 +        throws ParseFailedException, CommandFailedException {
   20.25 +        boolean verbose = getFlagParameter(args, 'v');
   20.26 +
   20.27 +        loadState();
   20.28 +        VirtualDisk free = VirtualDiskManager.IT.getFreeDisk();
   20.29 +        System.out.println(
   20.30 +            "Free disk has "
   20.31 +                + free.getExtentCount()
   20.32 +                + " extents totalling "
   20.33 +                + Library.formatSize(
   20.34 +                    free.getSize() * Settings.SECTOR_SIZE,
   20.35 +                    8,
   20.36 +                    true));
   20.37 +        if (verbose) {
   20.38 +            Iterator i = free.extents();
   20.39 +            System.out.println("  disk       offset         size");
   20.40 +            while (i.hasNext()) {
   20.41 +                Extent e = (Extent) i.next();
   20.42 +                System.out.println(
   20.43 +                    Library.format(e.getDisk(), 6, false)
   20.44 +                        + " "
   20.45 +                        + Library.format(e.getOffset(), 12, false)
   20.46 +                        + " "
   20.47 +                        + Library.format(e.getSize(), 12, false));
   20.48 +            }
   20.49 +        }
   20.50      }
   20.51 -  }
   20.52  
   20.53 -  public String getName() {
   20.54 -    return "free";
   20.55 -  }
   20.56 +    public String getName() {
   20.57 +        return "free";
   20.58 +    }
   20.59  
   20.60 -  public String getUsage() {
   20.61 -    return "[-v]";
   20.62 -  }
   20.63 +    public String getUsage() {
   20.64 +        return "[-v]";
   20.65 +    }
   20.66  
   20.67 -  public String getHelpText() {
   20.68 -    return "Show free space allocated to virtual disk manager. -v enables verbose output.";
   20.69 -  }
   20.70 +    public String getHelpText() {
   20.71 +        return "Show free space allocated to virtual disk manager. -v enables verbose output.";
   20.72 +    }
   20.73  }
    21.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java	Wed Jul 09 10:58:27 2003 +0000
    21.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdRefresh.java	Wed Jul 09 10:58:38 2003 +0000
    21.3 @@ -1,5 +1,7 @@
    21.4  package org.xenoserver.cmdline;
    21.5  
    21.6 +import java.text.DateFormat;
    21.7 +import java.text.ParseException;
    21.8  import java.util.Date;
    21.9  import java.util.LinkedList;
   21.10  
   21.11 @@ -8,35 +10,44 @@ import org.xenoserver.control.CommandVdR
   21.12  import org.xenoserver.control.Defaults;
   21.13  
   21.14  public class ParseVdRefresh extends CommandParser {
   21.15 -  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   21.16 -    String vd_key = getStringParameter(args,'k',"");
   21.17 -    String expiry_s = getStringParameter(args,'e',"");
   21.18 -    Date expiry;
   21.19 -    
   21.20 -    if ( vd_key.equals("") )
   21.21 -      throw new ParseFailedException("Expected -k<key>");
   21.22 -    if ( expiry_s.equals("") )
   21.23 -      expiry = null;
   21.24 -    else
   21.25 -      expiry = new Date(Date.parse(expiry_s));
   21.26 -      
   21.27 -    loadState();
   21.28 -    String output = new CommandVdRefresh(vd_key,expiry).execute();
   21.29 -    if ( output != null )
   21.30 -      System.out.println(output);
   21.31 -    saveState();
   21.32 -  }
   21.33 +    public void parse(Defaults d, LinkedList args)
   21.34 +        throws ParseFailedException, CommandFailedException {
   21.35 +        String vd_key = getStringParameter(args, 'k', "");
   21.36 +        String expiry_s = getStringParameter(args, 'e', "");
   21.37 +        Date expiry;
   21.38 +
   21.39 +        if (vd_key.equals("")) {
   21.40 +            throw new ParseFailedException("Expected -k<key>");
   21.41 +        }
   21.42 +        if (expiry_s.equals("")) {
   21.43 +            expiry = null;
   21.44 +        } else {
   21.45 +            DateFormat format = DateFormat.getDateTimeInstance();
   21.46 +            try {
   21.47 +                expiry = format.parse(expiry_s);
   21.48 +            } catch (ParseException e) {
   21.49 +                throw new ParseFailedException("Could not parse date");
   21.50 +            }
   21.51 +        }
   21.52  
   21.53 -  public String getName() {
   21.54 -    return "refresh";
   21.55 -  }
   21.56 +        loadState();
   21.57 +        String output = new CommandVdRefresh(vd_key, expiry).execute();
   21.58 +        if (output != null) {
   21.59 +            System.out.println(output);
   21.60 +        }
   21.61 +        saveState();
   21.62 +    }
   21.63  
   21.64 -  public String getUsage() {
   21.65 -    return "-k<key> [-e<expiry>]";
   21.66 -  }
   21.67 +    public String getName() {
   21.68 +        return "refresh";
   21.69 +    }
   21.70  
   21.71 -  public String getHelpText() {
   21.72 -    return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
   21.73 -  }
   21.74 +    public String getUsage() {
   21.75 +        return "-k<key> [-e<expiry>]";
   21.76 +    }
   21.77 +
   21.78 +    public String getHelpText() {
   21.79 +        return "Refresh the expiry for the specified virtual disk. Omitting -e will cause the disk to never expire.";
   21.80 +    }
   21.81  
   21.82  }
    22.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java	Wed Jul 09 10:58:27 2003 +0000
    22.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java	Wed Jul 09 10:58:38 2003 +0000
    22.3 @@ -23,23 +23,26 @@ public class ParseVdShow extends Command
    22.4        while ( i.hasNext() ) {
    22.5          VirtualDisk vd = (VirtualDisk) i.next();
    22.6          System.out.print( vd.getKey() + " " );
    22.7 -        if ( vd.getExpiry() != null )
    22.8 +        if ( vd.getExpiry() != null ) {
    22.9            System.out.print( vd.getExpiry().toString() );
   22.10 -        else
   22.11 +        } else {
   22.12            System.out.print( "                            " );
   22.13 +        }
   22.14          System.out.println( " " + Library.format(vd.getName(),16,true) + " "
   22.15                            + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) );
   22.16        }
   22.17      } else {
   22.18        VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
   22.19 -      if ( vd == null )
   22.20 +      if ( vd == null ) {
   22.21          throw new CommandFailedException("There is no virtual disk " + key );
   22.22 +      }
   22.23          
   22.24        System.out.println("  name: " + vd.getName());
   22.25        System.out.println("   key: " + vd.getKey());
   22.26        System.out.println("  size: " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,true));
   22.27 -      if ( vd.getExpiry() != null )
   22.28 +      if ( vd.getExpiry() != null ) {
   22.29          System.out.println("expiry: " + vd.getExpiry());
   22.30 +      }
   22.31        System.out.println();
   22.32   
   22.33        Iterator i = vd.extents();
   22.34 @@ -58,10 +61,10 @@ public class ParseVdShow extends Command
   22.35    }
   22.36  
   22.37    public String getUsage() {
   22.38 -    return "[-n<diskno>]";
   22.39 +    return "[-k<key>]";
   22.40    }
   22.41  
   22.42    public String getHelpText() {
   22.43 -    return "Show a summary of all virtual disks, or details of one disk if -n is given";
   22.44 +    return "Show a summary of all virtual disks, or details of one disk if -k is given";
   22.45    }
   22.46  }
    23.1 --- a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java	Wed Jul 09 10:58:27 2003 +0000
    23.2 +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java	Wed Jul 09 10:58:38 2003 +0000
    23.3 @@ -4,27 +4,46 @@ package org.xenoserver.control;
    23.4   * Add a disk partition to the VirtualDiskManager as a XenoPartition.
    23.5   */
    23.6  public class CommandPartitionAdd extends Command {
    23.7 +    /** True to force creation. */
    23.8 +    private boolean force;
    23.9      /** Partition to add as a XenoPartition. */
   23.10 -    private Partition partition;
   23.11 -    /** Chunk size to split partition into (in sectors). */
   23.12 +    private String partition_name;
   23.13 +    /** Chunk size to split partition into (in bytes). */
   23.14      private long chunksize;
   23.15  
   23.16      /**
   23.17       * Constructor for CommandPartitionAdd.
   23.18 -     * @param partition Partition to add.
   23.19 -     * @param chunksize Chunk size to split partition into (in sectors).
   23.20 +     * @param partition_name Partition to add.
   23.21 +     * @param chunksize Chunk size to split partition into (in bytes).
   23.22 +     * @param force True to force creation.
   23.23       */
   23.24 -    public CommandPartitionAdd(Partition partition, long chunksize) {
   23.25 -        this.partition = partition;
   23.26 +    public CommandPartitionAdd(String partition_name, long chunksize, boolean force) {
   23.27 +        this.partition_name = partition_name;
   23.28          this.chunksize = chunksize;
   23.29 +        this.force = force;
   23.30      }
   23.31  
   23.32      /**
   23.33       * @see org.xenoserver.control.Command#execute()
   23.34       */
   23.35      public String execute() throws CommandFailedException {
   23.36 -        VirtualDiskManager.IT.addPartition(partition, chunksize);
   23.37 -        PartitionManager.IT.addXenoPartition(partition);
   23.38 -        return "Added partition " + partition.getName();
   23.39 +        Partition p = PartitionManager.IT.getPartition(partition_name);
   23.40 +        if (p == null) {
   23.41 +            throw new CommandFailedException(
   23.42 +                "Partition " + partition_name + " does not exist.");
   23.43 +        }
   23.44 +        // Check if this partition belongs to the VDM
   23.45 +        if (p.isXeno() && !force) {
   23.46 +          throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure.");
   23.47 +        }
   23.48 +        
   23.49 +        long size = chunksize / Settings.SECTOR_SIZE;
   23.50 +        if ( chunksize <= 0 ) {
   23.51 +          throw new CommandFailedException("Chunk size is smaller than sector size.");
   23.52 +        }
   23.53 +    
   23.54 +        VirtualDiskManager.IT.addPartition(p, size);
   23.55 +        PartitionManager.IT.addXenoPartition(p);
   23.56 +        return "Added partition " + p.getName();
   23.57      }
   23.58  }
    24.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java	Wed Jul 09 10:58:27 2003 +0000
    24.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java	Wed Jul 09 10:58:38 2003 +0000
    24.3 @@ -9,9 +9,11 @@ public class CommandPhysicalGrant extend
    24.4      /** Domain ID to grant access for */ 
    24.5      private int domain_id;
    24.6      /** Partition to grant access to */
    24.7 -    private Partition partition;
    24.8 +    private String partition_name;
    24.9      /** Access mode to grant */
   24.10      private Mode mode;
   24.11 +    /** True to force grant */
   24.12 +    private boolean force;
   24.13  
   24.14      /**
   24.15       * Constructor for CommandPhysicalGrant.
   24.16 @@ -19,16 +21,19 @@ public class CommandPhysicalGrant extend
   24.17       * @param domain_id Domain to grant access for.
   24.18       * @param partition Partition to grant access to.
   24.19       * @param mode Access mode to grant.
   24.20 +     * @param force True to force grant
   24.21       */
   24.22      public CommandPhysicalGrant(
   24.23          Defaults d,
   24.24          int domain_id,
   24.25 -        Partition partition,
   24.26 -        Mode mode) {
   24.27 +        String partition,
   24.28 +        Mode mode,
   24.29 +        boolean force) {
   24.30          this.d = d;
   24.31          this.domain_id = domain_id;
   24.32 -        this.partition = partition;
   24.33 +        this.partition_name = partition;
   24.34          this.mode = mode;
   24.35 +        this.force = force;
   24.36      }
   24.37  
   24.38      /**
   24.39 @@ -38,6 +43,17 @@ public class CommandPhysicalGrant extend
   24.40          Runtime r = Runtime.getRuntime();
   24.41          String output = null;
   24.42  
   24.43 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
   24.44 +    
   24.45 +        if ( partition == null ) {
   24.46 +          throw new CommandFailedException("Partition " + partition_name + " does not exist.");
   24.47 +        }
   24.48 +    
   24.49 +        // Check if this partition belongs to the VDM
   24.50 +        if (partition.isXeno() && !force) {
   24.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.");
   24.52 +        }
   24.53 +         
   24.54          try {
   24.55              Process start_p;
   24.56              String start_cmdarray[] = new String[7];
    25.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java	Wed Jul 09 10:58:27 2003 +0000
    25.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java	Wed Jul 09 10:58:38 2003 +0000
    25.3 @@ -65,12 +65,16 @@ public class CommandPhysicalList extends
    25.4                  outline = in.readLine();
    25.5                  while (outline != null) {
    25.6                      int disk = -1;
    25.7 +                    int partition_no = -1;
    25.8                      long offset = -1;
    25.9                      long size = -1;
   25.10  
   25.11                      StringTokenizer st = new StringTokenizer(outline);
   25.12                      if (st.hasMoreTokens()) {
   25.13 -                        disk = Short.parseShort(st.nextToken(), 16);
   25.14 +                        disk = Integer.parseInt(st.nextToken(), 16);
   25.15 +                    }
   25.16 +                    if (st.hasMoreTokens()) {
   25.17 +                        partition_no = Integer.parseInt(st.nextToken(), 16);
   25.18                      }
   25.19                      if (st.hasMoreTokens()) {
   25.20                          offset = Long.parseLong(st.nextToken(), 16);
   25.21 @@ -80,7 +84,7 @@ public class CommandPhysicalList extends
   25.22                      }
   25.23                      if (st.hasMoreTokens()) {
   25.24                          String mode = st.nextToken();
   25.25 -                        Extent extent = new Extent(disk, offset, size);
   25.26 +                        Extent extent = new Extent(disk, offset, size, partition_no);
   25.27                          if (mode.equals("rw")) {
   25.28                              map.put(extent, Mode.READ_WRITE);
   25.29                          } else if (mode.equals("r")) {
    26.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java	Wed Jul 09 10:58:27 2003 +0000
    26.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java	Wed Jul 09 10:58:38 2003 +0000
    26.3 @@ -9,7 +9,7 @@ public class CommandPhysicalRevoke exten
    26.4      /** Domain to revoke access from */
    26.5      private int domain_id;
    26.6      /** Partition to revoke access to */
    26.7 -    private Partition partition;
    26.8 +    private String partition_name;
    26.9  
   26.10      /**
   26.11       * Constructor for CommandPhysicalRevoke.
   26.12 @@ -17,10 +17,10 @@ public class CommandPhysicalRevoke exten
   26.13       * @param domain_id Domain to revoke access from.
   26.14       * @param partition Partition to revoke access to.
   26.15       */
   26.16 -    public CommandPhysicalRevoke(Defaults d, int domain_id, Partition partition) {
   26.17 +    public CommandPhysicalRevoke(Defaults d, int domain_id, String partition) {
   26.18          this.d = d;
   26.19          this.domain_id = domain_id;
   26.20 -        this.partition = partition;
   26.21 +        this.partition_name = partition;
   26.22      }
   26.23  
   26.24      /**
   26.25 @@ -30,6 +30,13 @@ public class CommandPhysicalRevoke exten
   26.26          Runtime r = Runtime.getRuntime();
   26.27          String output = null;
   26.28  
   26.29 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
   26.30 +
   26.31 +        if (partition == null) {
   26.32 +            throw new CommandFailedException(
   26.33 +                "Partition " + partition_name + " does not exist.");
   26.34 +        }
   26.35 +
   26.36          try {
   26.37              Process start_p;
   26.38              String start_cmdarray[] = new String[5];
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdCreate.java	Wed Jul 09 10:58:38 2003 +0000
    27.3 @@ -0,0 +1,69 @@
    27.4 +package org.xenoserver.control;
    27.5 +
    27.6 +import java.io.FileWriter;
    27.7 +import java.io.IOException;
    27.8 +
    27.9 +/**
   27.10 + * Create a virtual block device.
   27.11 + */
   27.12 +public class CommandVbdCreate extends Command {
   27.13 +    /** Virtual disk to map to. */
   27.14 +    private String vd_key;
   27.15 +    /** Domain to create VBD for. */
   27.16 +    private int domain_id;
   27.17 +    /** VBD number to use. */
   27.18 +    private int vbd_num;
   27.19 +    /** Access mode to grant. */
   27.20 +    private Mode mode;
   27.21 +
   27.22 +    /**
   27.23 +     * Constructor for CommandVbdCreate.
   27.24 +     * @param vd VirtualDisk to map to.
   27.25 +     * @param domain_id Domain to map for.
   27.26 +     * @param vbd_num VBD number within domain.
   27.27 +     * @param mode Access mode to grant.
   27.28 +     */
   27.29 +    public CommandVbdCreate(
   27.30 +        String vd,
   27.31 +        int domain_id,
   27.32 +        int vbd_num,
   27.33 +        Mode mode) {
   27.34 +        this.vd_key = vd;
   27.35 +        this.domain_id = domain_id;
   27.36 +        this.vbd_num = vbd_num;
   27.37 +        this.mode = mode;
   27.38 +    }
   27.39 +
   27.40 +    /**
   27.41 +     * @see org.xenoserver.control.Command#execute()
   27.42 +     */
   27.43 +    public String execute() throws CommandFailedException {
   27.44 +        VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(vd_key);
   27.45 +        if (vd == null) {
   27.46 +            throw new CommandFailedException(
   27.47 +                "No virtual disk with key " + vd_key);
   27.48 +        }
   27.49 +
   27.50 +        VirtualBlockDevice vbd =
   27.51 +            VirtualDiskManager.IT.createVirtualBlockDevice(
   27.52 +                vd,
   27.53 +                domain_id,
   27.54 +                vbd_num,
   27.55 +                mode);
   27.56 +        String command = vd.dumpForXen(vbd);
   27.57 +
   27.58 +        try {
   27.59 +            FileWriter fw = new FileWriter("/proc/xeno/dom0/vhd");
   27.60 +            fw.write(command);
   27.61 +            fw.flush();
   27.62 +            fw.close();
   27.63 +        } catch (IOException e) {
   27.64 +            throw new CommandFailedException("Could not write VBD details to /proc/xeno/dom0/vhd", e);
   27.65 +        }
   27.66 +
   27.67 +        return "Created virtual block device "
   27.68 +            + vbd_num
   27.69 +            + " for domain "
   27.70 +            + domain_id;
   27.71 +    }
   27.72 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java	Wed Jul 09 10:58:38 2003 +0000
    28.3 @@ -0,0 +1,71 @@
    28.4 +package org.xenoserver.control;
    28.5 +
    28.6 +import java.io.FileWriter;
    28.7 +import java.io.IOException;
    28.8 +
    28.9 +/**
   28.10 + * Create a virtual block device.
   28.11 + */
   28.12 +public class CommandVbdCreatePhysical extends Command {
   28.13 +    /** Virtual disk to map to. */
   28.14 +    private String partition_name;
   28.15 +    /** Domain to create VBD for. */
   28.16 +    private int domain_id;
   28.17 +    /** VBD number to use. */
   28.18 +    private int vbd_num;
   28.19 +    /** Access mode to grant. */
   28.20 +    private Mode mode;
   28.21 +
   28.22 +    /**
   28.23 +     * Constructor for CommandVbdCreate.
   28.24 +     * @param partition Partition to map to.
   28.25 +     * @param domain_id Domain to map for.
   28.26 +     * @param vbd_num VBD number within domain.
   28.27 +     * @param mode Access mode to grant.
   28.28 +     */
   28.29 +    public CommandVbdCreatePhysical(
   28.30 +        String partition,
   28.31 +        int domain_id,
   28.32 +        int vbd_num,
   28.33 +        Mode mode) {
   28.34 +        this.partition_name = partition;
   28.35 +        this.domain_id = domain_id;
   28.36 +        this.vbd_num = vbd_num;
   28.37 +        this.mode = mode;
   28.38 +    }
   28.39 +
   28.40 +    /**
   28.41 +     * @see org.xenoserver.control.Command#execute()
   28.42 +     */
   28.43 +    public String execute() throws CommandFailedException {
   28.44 +        Partition partition = PartitionManager.IT.getPartition(partition_name);
   28.45 +        if (partition == null) {
   28.46 +            throw new CommandFailedException(
   28.47 +                "No partition " + partition_name + " exists");
   28.48 +        }
   28.49 +
   28.50 +        VirtualDisk vd = new VirtualDisk("vbd:" + partition.getName());
   28.51 +        vd.addPartition(partition, partition.getNumSects());
   28.52 +
   28.53 +        VirtualBlockDevice vbd =
   28.54 +            new VirtualBlockDevice(vd, domain_id, vbd_num, mode);
   28.55 +
   28.56 +        String command = vd.dumpForXen(vbd);
   28.57 +
   28.58 +        try {
   28.59 +            FileWriter fw = new FileWriter("/proc/xeno/dom0/vhd");
   28.60 +            fw.write(command);
   28.61 +            fw.flush();
   28.62 +            fw.close();
   28.63 +        } catch (IOException e) {
   28.64 +            throw new CommandFailedException(
   28.65 +                "Could not write VBD details to /proc/xeno/dom0/vhd",
   28.66 +                e);
   28.67 +        }
   28.68 +
   28.69 +        return "Created virtual block device "
   28.70 +            + vbd_num
   28.71 +            + " for domain "
   28.72 +            + domain_id;
   28.73 +    }
   28.74 +}
    29.1 --- a/tools/control/src/org/xenoserver/control/CommandVdCreate.java	Wed Jul 09 10:58:27 2003 +0000
    29.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java	Wed Jul 09 10:58:38 2003 +0000
    29.3 @@ -8,7 +8,7 @@ import java.util.Date;
    29.4  public class CommandVdCreate extends Command {
    29.5      /** Name of new disk. */
    29.6      private String name;
    29.7 -    /** Size of new disk in sectors. */
    29.8 +    /** Size of new disk in bytes. */
    29.9      private long size;
   29.10      /** Expiry date of new disk. */
   29.11      private Date expiry;
   29.12 @@ -16,7 +16,7 @@ public class CommandVdCreate extends Com
   29.13      /**
   29.14       * Constructor for CommandVdCreate.
   29.15       * @param name Name of new virtual disk.
   29.16 -     * @param size Size in sectors.
   29.17 +     * @param size Size in bytes.
   29.18       * @param expiry Expiry time, or null for never.
   29.19       */
   29.20      public CommandVdCreate(String name, long size, Date expiry) {
   29.21 @@ -30,7 +30,10 @@ public class CommandVdCreate extends Com
   29.22       */
   29.23      public String execute() throws CommandFailedException {
   29.24          VirtualDisk vd =
   29.25 -            VirtualDiskManager.IT.createVirtualDisk(name, size, expiry);
   29.26 +            VirtualDiskManager.IT.createVirtualDisk(
   29.27 +                name,
   29.28 +                size / Settings.SECTOR_SIZE,
   29.29 +                expiry);
   29.30          if (vd == null) {
   29.31              throw new CommandFailedException("Not enough free space to create disk");
   29.32          }
    30.1 --- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java	Wed Jul 09 10:58:27 2003 +0000
    30.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java	Wed Jul 09 10:58:38 2003 +0000
    30.3 @@ -19,6 +19,11 @@ public class CommandVdDelete extends Com
    30.4       * @see org.xenoserver.control.Command#execute()
    30.5       */
    30.6      public String execute() throws CommandFailedException {
    30.7 +        if (VirtualDiskManager.IT.getVirtualDisk(key) == null) {
    30.8 +            throw new CommandFailedException(
    30.9 +                "Virtual disk " + key + " does not exist");
   30.10 +        }
   30.11 +
   30.12          VirtualDiskManager.IT.deleteVirtualDisk(key);
   30.13          return "Deleted virtual disk " + key;
   30.14      }
    31.1 --- a/tools/control/src/org/xenoserver/control/Extent.java	Wed Jul 09 10:58:27 2003 +0000
    31.2 +++ b/tools/control/src/org/xenoserver/control/Extent.java	Wed Jul 09 10:58:38 2003 +0000
    31.3 @@ -15,6 +15,8 @@ public class Extent {
    31.4      private long offset;
    31.5      /** Size of extent in sectors. */
    31.6      private long size;
    31.7 +    /** Partition number, if one is allocated. */
    31.8 +    private int partition_no;
    31.9  
   31.10      /**
   31.11       * Constructor for Extent.
   31.12 @@ -27,6 +29,20 @@ public class Extent {
   31.13          this.offset = offset;
   31.14          this.size = size;
   31.15      }
   31.16 +    
   31.17 +    /**
   31.18 +     * Constructor for Extent.
   31.19 +     * @param disk Disk number.
   31.20 +     * @param offset Offset into disk.
   31.21 +     * @param size Size of extent.
   31.22 +     * @param partition_no Partition number.
   31.23 +     */
   31.24 +    Extent(int disk, long offset, long size,int partition_no) {
   31.25 +        this.disk = disk;
   31.26 +        this.offset = offset;
   31.27 +        this.size = size;
   31.28 +        this.partition_no = partition_no;
   31.29 +    }
   31.30  
   31.31      /**
   31.32       * @return Disk number.
   31.33 @@ -62,4 +78,11 @@ public class Extent {
   31.34      public int getMinor() {
   31.35          return disk & 0xFF;
   31.36      }
   31.37 +    
   31.38 +    /**
   31.39 +     * @return Partition number of this extent.
   31.40 +     */
   31.41 +    public int getPartitionNo() {
   31.42 +        return partition_no;
   31.43 +    }
   31.44  }
    32.1 --- a/tools/control/src/org/xenoserver/control/Partition.java	Wed Jul 09 10:58:27 2003 +0000
    32.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java	Wed Jul 09 10:58:38 2003 +0000
    32.3 @@ -142,7 +142,7 @@ public class Partition {
    32.4       * @param other Other partition to compare to.
    32.5       * @return True if they are identical.
    32.6       */
    32.7 -    public boolean identical(Partition other) {
    32.8 +    boolean identical(Partition other) {
    32.9          return this.major == other.major
   32.10              && this.minor == other.minor
   32.11              && this.blocks == other.blocks
   32.12 @@ -154,7 +154,7 @@ public class Partition {
   32.13      /**
   32.14       * @return An Extent covering this partiton.
   32.15       */
   32.16 -    public Extent toExtent() {
   32.17 +    Extent toExtent() {
   32.18          return new Extent(getDisk(),start_sect,nr_sects);
   32.19      }
   32.20  
   32.21 @@ -162,7 +162,7 @@ public class Partition {
   32.22       * @param e Extent to compare this partition to.
   32.23       * @return True if this partition covers the same disk area as the given extent.
   32.24       */
   32.25 -    public boolean matchesExtent(Extent e) {
   32.26 +    boolean matchesExtent(Extent e) {
   32.27          return e.getDisk() == getDisk()
   32.28              && e.getOffset() == start_sect
   32.29              && e.getSize() == nr_sects;
    33.1 --- a/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java	Wed Jul 09 10:58:27 2003 +0000
    33.2 +++ b/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java	Wed Jul 09 10:58:38 2003 +0000
    33.3 @@ -39,28 +39,6 @@ public class VirtualBlockDevice {
    33.4          this.mode = mode;
    33.5      }
    33.6  
    33.7 -    // TODO: get rid of this method
    33.8 -    String dump(boolean title) {
    33.9 -        StringBuffer sb = new StringBuffer();
   33.10 -
   33.11 -        if (title) {
   33.12 -            sb.append("  key         dom vbd mode\n");
   33.13 -        } else {
   33.14 -            sb.append(
   33.15 -                "  "
   33.16 -                    + vd.getKey()
   33.17 -                    + "  "
   33.18 -                    + Library.format(domain, 3, false)
   33.19 -                    + " "
   33.20 -                    + Library.format(vbdNum, 3, false)
   33.21 -                    + " "
   33.22 -                    + mode.toString()
   33.23 -                    + "\n");
   33.24 -        }
   33.25 -
   33.26 -        return sb.toString();
   33.27 -    }
   33.28 -
   33.29      /**
   33.30       * Dump the virtual block device as XML.
   33.31       * @param out The writer to dump to.
    34.1 --- a/tools/control/src/org/xenoserver/control/VirtualDisk.java	Wed Jul 09 10:58:27 2003 +0000
    34.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDisk.java	Wed Jul 09 10:58:38 2003 +0000
    34.3 @@ -169,8 +169,8 @@ public class VirtualDisk {
    34.4              Extent extent =
    34.5                  new Extent(
    34.6                      partition.getDisk(),
    34.7 -                    extentSize,
    34.8 -                    partition.getStartSect() + (extentSize * loop));
    34.9 +                    partition.getStartSect() + (extentSize * loop),
   34.10 +                    extentSize);
   34.11  
   34.12              addExtent(extent);
   34.13          }
   34.14 @@ -227,7 +227,7 @@ public class VirtualDisk {
   34.15       * Reset the expiry time for this virtual disk.
   34.16       * @param expiry The new expiry time, or null for never.
   34.17       */
   34.18 -    public void refreshExpiry(Date expiry) {
   34.19 +    void refreshExpiry(Date expiry) {
   34.20          this.expiry = expiry;
   34.21      }
   34.22  }
    35.1 --- a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 10:58:27 2003 +0000
    35.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 10:58:38 2003 +0000
    35.3 @@ -45,7 +45,7 @@ public class VirtualDiskManager {
    35.4       * @param partition The partition to add.
    35.5       * @param chunkSize The chunk size to split the partition into, in sectors. 
    35.6       */
    35.7 -    public void addPartition(Partition partition, long chunkSize) {
    35.8 +    void addPartition(Partition partition, long chunkSize) {
    35.9          freeDisk.addPartition(partition, chunkSize);
   35.10      }
   35.11  
   35.12 @@ -56,7 +56,7 @@ public class VirtualDiskManager {
   35.13       * @param expiry The expiry time, or null for never.
   35.14       * @return null if not enough space is available
   35.15       */
   35.16 -    public VirtualDisk createVirtualDisk(String name, long size, Date expiry) {
   35.17 +    VirtualDisk createVirtualDisk(String name, long size, Date expiry) {
   35.18          if (freeDisk.getSize() < size) {
   35.19              return null;
   35.20          }
   35.21 @@ -83,7 +83,7 @@ public class VirtualDiskManager {
   35.22       * Delete a virtual disk, and put its extents back into the free pool.
   35.23       * @param key The key of the disk to delete.
   35.24       */
   35.25 -    public void deleteVirtualDisk(String key) {
   35.26 +    void deleteVirtualDisk(String key) {
   35.27          VirtualDisk vd;
   35.28  
   35.29          vd = (VirtualDisk) virtualDisks.get(key);
   35.30 @@ -108,7 +108,7 @@ public class VirtualDiskManager {
   35.31       * @param mode The mode to create the device with.
   35.32       * @return The newly created virtual block device.
   35.33       */
   35.34 -    public VirtualBlockDevice createVirtualBlockDevice(
   35.35 +    VirtualBlockDevice createVirtualBlockDevice(
   35.36          VirtualDisk vd,
   35.37          int domain,
   35.38          int vbdNum,
   35.39 @@ -126,7 +126,7 @@ public class VirtualDiskManager {
   35.40       * @param domain Domain owning the device.
   35.41       * @param vbdNum The vbd number within the domain.
   35.42       */
   35.43 -    public void deleteVirtualBlockDevice(int domain, int vbdNum) {
   35.44 +    void deleteVirtualBlockDevice(int domain, int vbdNum) {
   35.45          Object hash = hashVBD(domain, vbdNum);
   35.46          virtualBlockDevices.remove(hash);
   35.47      }
   35.48 @@ -134,7 +134,7 @@ public class VirtualDiskManager {
   35.49      /**
   35.50       * Flush all virtual block devices.
   35.51       */
   35.52 -    public void flushVirtualBlockDevices() {
   35.53 +    void flushVirtualBlockDevices() {
   35.54          /* isn't automatic garbage collection wonderful? */
   35.55          virtualBlockDevices = new LinkedHashMap(100);
   35.56      }
    36.1 --- a/tools/control/src/org/xenoserver/control/XMLHelper.java	Wed Jul 09 10:58:27 2003 +0000
    36.2 +++ b/tools/control/src/org/xenoserver/control/XMLHelper.java	Wed Jul 09 10:58:38 2003 +0000
    36.3 @@ -146,10 +146,11 @@ class XMLHelper {
    36.4                                  XMLHelper.getSubNode("disk", enode))),
    36.5                          Long.parseLong(
    36.6                              XMLHelper.getText(
    36.7 -                                XMLHelper.getSubNode("size", enode))),
    36.8 -                        Long.parseLong(
    36.9 -                            XMLHelper.getText(
   36.10 -                                XMLHelper.getSubNode("offset", enode))));
   36.11 +                                XMLHelper.getSubNode("offset", enode))),
   36.12 +                    Long.parseLong(
   36.13 +                        XMLHelper.getText(
   36.14 +                            XMLHelper.getSubNode("size", enode))));
   36.15 +
   36.16                  vd.addExtent(extent);
   36.17              }
   36.18          }
    37.1 --- a/tools/control/src/uk/ac/cam/cl/xeno/xenctl/Main.java.orig	Wed Jul 09 10:58:27 2003 +0000
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,35 +0,0 @@
    37.4 -/*
    37.5 - * Main.java
    37.6 - * 03.03.26 aho creation
    37.7 - */
    37.8 -
    37.9 -package uk.ac.cam.cl.xeno.vdmanager;
   37.10 -
   37.11 -import java.util.Date;
   37.12 -
   37.13 -public class
   37.14 -Main
   37.15 -{
   37.16 -  static String state_filename_in  = "/var/lib/xen/vdstate.xml";
   37.17 -  static String state_filename_out = "/var/lib/xen/vdstate.xml";
   37.18 -  static String partition_filename = "/proc/partitions";
   37.19 -
   37.20 -  void
   37.21 -  go (String[] argv)
   37.22 -  {
   37.23 -    PartitionManager pm = new PartitionManager(partition_filename);
   37.24 -    VirtualDiskManager vdm = new VirtualDiskManager();;
   37.25 -    Parser parser = new Parser(pm, vdm);
   37.26 -
   37.27 -    XML.load_state(pm, vdm, state_filename_in);
   37.28 -    parser.parse_main(argv);
   37.29 -    XML.dump_state(pm, vdm, state_filename_out);
   37.30 -  }
   37.31 -
   37.32 -  public static void
   37.33 -  main (String[] argv)
   37.34 -  {
   37.35 -    Main foo = new Main();
   37.36 -    foo.go(argv);
   37.37 -  }
   37.38 -}
    38.1 --- a/tools/control/src/uk/ac/cam/cl/xeno/xenctl/Parser.java	Wed Jul 09 10:58:27 2003 +0000
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,446 +0,0 @@
    38.4 -/*
    38.5 - * Parser.java
    38.6 - * 03.03.27 aho creation
    38.7 - */
    38.8 -
    38.9 -package uk.ac.cam.cl.xeno.xenctl;
   38.10 -
   38.11 -import java.io.BufferedReader;
   38.12 -import java.io.FileReader;
   38.13 -import java.io.InputStreamReader;
   38.14 -import java.io.FileNotFoundException;
   38.15 -import java.io.IOException;
   38.16 -import java.util.StringTokenizer;
   38.17 -import java.util.Vector;
   38.18 -import java.util.Date;
   38.19 -
   38.20 -public class
   38.21 -Parser
   38.22 -{
   38.23 -  static String prompt = "vdmanager> ";
   38.24 -  static String default_addpartition_chunksize = "104857600";        /* 100M */
   38.25 -  static int    default_sector_size = 512;
   38.26 -
   38.27 -  PartitionManager pm;
   38.28 -  VirtualDiskManager vdm;
   38.29 -
   38.30 -  Parser (PartitionManager pm, VirtualDiskManager vdm)
   38.31 -  {
   38.32 -    this.pm = pm;
   38.33 -    this.vdm = vdm;
   38.34 -  }
   38.35 -
   38.36 -  void
   38.37 -  parse_main (String[] argv)
   38.38 -  {
   38.39 -    if (argv.length == 0)
   38.40 -    {
   38.41 -      parse_input(null);
   38.42 -    }
   38.43 -    else
   38.44 -    {
   38.45 -      parse_commandline(argv);
   38.46 -    }
   38.47 -  }
   38.48 -
   38.49 -  void
   38.50 -  parse_input (String filename)
   38.51 -  {
   38.52 -    String line;
   38.53 -    BufferedReader in;
   38.54 -
   38.55 -    if (filename != null)
   38.56 -    {
   38.57 -      try
   38.58 -      {
   38.59 -	in = new BufferedReader(new FileReader(filename));
   38.60 -      }
   38.61 -      catch (FileNotFoundException fnfe)
   38.62 -      {
   38.63 -	System.err.println (fnfe);
   38.64 -	return;
   38.65 -      }
   38.66 -    }
   38.67 -    else
   38.68 -    {
   38.69 -      in = new BufferedReader(new InputStreamReader(System.in));
   38.70 -    }
   38.71 -
   38.72 -    try
   38.73 -    {
   38.74 -      if (filename == null)
   38.75 -      {
   38.76 -	System.out.print (prompt);
   38.77 -      }
   38.78 -      line = in.readLine();
   38.79 -      while (line != null)
   38.80 -      {
   38.81 -	StringTokenizer st = new StringTokenizer(line);
   38.82 -	Vector v = new Vector();
   38.83 -
   38.84 -	while (st.hasMoreTokens()) 
   38.85 -	{
   38.86 -	  v.add(st.nextToken());
   38.87 -	}
   38.88 -
   38.89 -	if (parse_commandline((String[]) v.toArray(new String[v.size()])))
   38.90 -	{
   38.91 -	  return;
   38.92 -	}
   38.93 -	
   38.94 -	if (filename == null)
   38.95 -	{
   38.96 -	  System.out.print (prompt);
   38.97 -	}
   38.98 -	line = in.readLine();
   38.99 -      }
  38.100 -    }
  38.101 -    catch (IOException ioe)
  38.102 -    {
  38.103 -      System.err.println(ioe);
  38.104 -    }
  38.105 -
  38.106 -    if (filename == null)
  38.107 -    {
  38.108 -      System.out.println ("");
  38.109 -    }
  38.110 -    return;
  38.111 -  }
  38.112 -
  38.113 -  boolean
  38.114 -  parse_commandline (String[] commands)
  38.115 -  {
  38.116 -    if (commands.length == 0)
  38.117 -    {
  38.118 -      return false;
  38.119 -    }
  38.120 -
  38.121 -    String keyword = commands[0].toLowerCase();
  38.122 -    if (keyword.equals("file"))
  38.123 -    {
  38.124 -      if (commands.length < 2)
  38.125 -      {
  38.126 -	System.out.println ("file [filename]");
  38.127 -	return false;
  38.128 -      }
  38.129 -      for (int i = 1; i < commands.length; i++)
  38.130 -      {
  38.131 -	System.out.println ("file " + commands[i]);
  38.132 -	parse_input(commands[i]);
  38.133 -      }
  38.134 -    }
  38.135 -    else if (keyword.equals("show"))
  38.136 -    {
  38.137 -      parse_show(commands);
  38.138 -    }
  38.139 -    else if (keyword.equals("addpartition"))
  38.140 -    {
  38.141 -      parse_addpartition(commands);
  38.142 -    }
  38.143 -    else if (keyword.equals("vdcreate"))
  38.144 -    {
  38.145 -      parse_vdcreate(commands);
  38.146 -    }
  38.147 -    else if (keyword.equals("vddelete"))
  38.148 -    {
  38.149 -      parse_vddelete(commands);
  38.150 -    }
  38.151 -    else if (keyword.equals("vdrefresh"))
  38.152 -    {
  38.153 -      parse_vdrefresh(commands);
  38.154 -    }
  38.155 -    else if (keyword.equals("vbdcreate"))
  38.156 -    {
  38.157 -      parse_vbdcreate(commands);
  38.158 -    }
  38.159 -    else if (keyword.equals("vbddelete"))
  38.160 -    {
  38.161 -      parse_vbddelete(commands);
  38.162 -    }
  38.163 -    else if (keyword.equals("vbdflush"))
  38.164 -    {
  38.165 -      vdm.flush_virtual_block_devices();
  38.166 -    }
  38.167 -    else if (keyword.equals("load"))
  38.168 -    {
  38.169 -      if (commands.length < 2)
  38.170 -      {
  38.171 -	System.out.println ("load <filename>");
  38.172 -	return false;
  38.173 -      }
  38.174 -      XML.load_state (pm, vdm, commands[1]);
  38.175 -    }
  38.176 -    else if (keyword.equals("save"))
  38.177 -    {
  38.178 -      if (commands.length < 2)
  38.179 -      {
  38.180 -	System.out.println ("save <filename>");
  38.181 -	return false;
  38.182 -      }
  38.183 -      XML.dump_state (pm, vdm, commands[1]);
  38.184 -    }
  38.185 -    else if (keyword.equals("help") ||
  38.186 -	     keyword.equals("?"))
  38.187 -    {
  38.188 -      parse_help();
  38.189 -    }
  38.190 -    else if (keyword.equals("exit") ||
  38.191 -	     keyword.equals("quit"))
  38.192 -    {
  38.193 -      return true;
  38.194 -    }
  38.195 -    else
  38.196 -    {
  38.197 -      System.out.println ("unknown command [" + commands[0] + "]. " +
  38.198 -			  "try \"help\"");
  38.199 -    }
  38.200 -    return false;
  38.201 -  }
  38.202 -
  38.203 -  void
  38.204 -  parse_vdcreate (String[] commands)
  38.205 -  {
  38.206 -    VirtualDisk vd;
  38.207 -
  38.208 -    if (commands.length < 4)
  38.209 -    {
  38.210 -      System.out.println ("vdcreate name size expiry");
  38.211 -      return;
  38.212 -    }
  38.213 -
  38.214 -    vd = vdm.create_virtual_disk(commands[1],
  38.215 -		     Library.parse_size(commands[2]) / default_sector_size,
  38.216 -				 new Date());
  38.217 -
  38.218 -    System.out.println ("Virtual Disk created with key: " + vd.get_key());
  38.219 -  }
  38.220 -
  38.221 -  void
  38.222 -  parse_vddelete (String[] commands)
  38.223 -  {
  38.224 -    if (commands.length < 2)
  38.225 -    {
  38.226 -      System.out.println ("vddelete key");
  38.227 -      return;
  38.228 -    }
  38.229 -
  38.230 -    vdm.delete_virtual_disk(commands[1]);
  38.231 -  }
  38.232 -
  38.233 -  void
  38.234 -  parse_vdrefresh (String[] commands)
  38.235 -  {
  38.236 -    if (commands.length < 3)
  38.237 -    {
  38.238 -      System.out.println ("vdrefresh key expiry");
  38.239 -      return;
  38.240 -    }
  38.241 -
  38.242 -    vdm.refresh_virtual_disk(commands[1],
  38.243 -			     new Date());
  38.244 -  }
  38.245 -
  38.246 -  void
  38.247 -  parse_vbdcreate (String[] commands)
  38.248 -  {
  38.249 -    VirtualDisk vd;
  38.250 -    VirtualBlockDevice vbd;
  38.251 -
  38.252 -    if (commands.length < 4)
  38.253 -    {
  38.254 -      System.out.println ("vbdcreate <key> <domain number> <vbd number>");
  38.255 -      return;
  38.256 -    }
  38.257 -
  38.258 -    if (commands[1].startsWith("sd") ||
  38.259 -	commands[1].startsWith("hd"))
  38.260 -    {
  38.261 -      /*
  38.262 -       * this is a gross hack to allow you to create a virtual block
  38.263 -       * device that maps directly to a physical partition
  38.264 -       */
  38.265 -
  38.266 -      /* find the appropriate partition */
  38.267 -      Partition partition = pm.get_partition(commands[1]);
  38.268 -      if (partition == null)
  38.269 -      {
  38.270 -	System.out.println ("vbdcreate error: couldn't find partition \"" +
  38.271 -			    commands[1] + "\"");
  38.272 -	return;
  38.273 -      }
  38.274 -
  38.275 -      /* create a virtual disk */
  38.276 -      vd = new VirtualDisk("vbd:" + commands[1]);
  38.277 -      vd.add_new_partition(partition, partition.nr_sects);
  38.278 -
  38.279 -
  38.280 -      /* display result */
  38.281 -      System.out.print("domain:" + commands[2] + " ");
  38.282 -      if (commands.length == 4)
  38.283 -      {
  38.284 -	System.out.print ("rw ");
  38.285 -      }
  38.286 -      else
  38.287 -      {
  38.288 -	System.out.print(commands[4] + " ");
  38.289 -      }
  38.290 -      System.out.print("segment:" + commands[3] + " ");
  38.291 -      System.out.print(vd.dump_xen());
  38.292 -      System.out.println("");
  38.293 -
  38.294 -      return;
  38.295 -    } 
  38.296 -
  38.297 -    if (commands.length == 4)
  38.298 -    {
  38.299 -      vbd =
  38.300 -      vdm.create_virtual_block_device(commands[1],
  38.301 -				      Integer.decode(commands[2]).intValue(),
  38.302 -				      Integer.decode(commands[3]).intValue(),
  38.303 -				      "rw");
  38.304 -    }
  38.305 -    else
  38.306 -    {
  38.307 -      vbd =
  38.308 -      vdm.create_virtual_block_device(commands[1],
  38.309 -				      Integer.decode(commands[2]).intValue(),
  38.310 -				      Integer.decode(commands[3]).intValue(),
  38.311 -				      commands[4]);
  38.312 -    }
  38.313 -
  38.314 -    /* display commandline to user */
  38.315 -    {
  38.316 -      vd = vdm.get_virtual_disk_key(commands[1]);
  38.317 -      System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
  38.318 -    }
  38.319 -  }
  38.320 -
  38.321 -  void
  38.322 -  parse_vbddelete (String[] commands)
  38.323 -  {
  38.324 -    if (commands.length < 3)
  38.325 -    {
  38.326 -      System.out.println ("vbddelete <domain number> <vbd number>");
  38.327 -      return;
  38.328 -    }
  38.329 -
  38.330 -    vdm.delete_virtual_block_device(Integer.decode(commands[1]).intValue(),
  38.331 -				    Integer.decode(commands[2]).intValue());
  38.332 -  }
  38.333 -
  38.334 -  static String show_helptxt = "show <partitions | free | vd [vd number] | vbd>";
  38.335 -  void
  38.336 -  parse_show (String[] commands)
  38.337 -  {
  38.338 -    String subword;
  38.339 -      
  38.340 -    if (commands.length < 2)
  38.341 -    {
  38.342 -      System.out.println (show_helptxt);
  38.343 -      return;
  38.344 -    }
  38.345 -
  38.346 -    subword = commands[1].toLowerCase();
  38.347 -    if (subword.equals("partition") ||
  38.348 -	subword.equals("partitions"))
  38.349 -    {
  38.350 -      System.out.println(pm.dump(true));
  38.351 -    }
  38.352 -    else if (subword.equals("vd"))
  38.353 -    {
  38.354 -      String text;
  38.355 -
  38.356 -      if (commands.length < 3)
  38.357 -      {
  38.358 -	System.out.println(vdm.dump_virtualdisks());
  38.359 -	return;
  38.360 -      }
  38.361 -      text = vdm.dump_virtualdisk(Integer.decode(commands[2]).intValue());
  38.362 -      if (text == null)
  38.363 -      {
  38.364 -	System.out.println("show vd error: invalid virtual disk number");
  38.365 -      }
  38.366 -      else
  38.367 -      {
  38.368 -	System.out.println(text);
  38.369 -      }
  38.370 -    }
  38.371 -    else if (subword.equals("vbd"))
  38.372 -    {
  38.373 -      System.out.println(vdm.dump_virtualblockdevices());
  38.374 -    }
  38.375 -    else if (subword.equals("free"))
  38.376 -    {
  38.377 -      System.out.println(vdm.dump_free());
  38.378 -    }
  38.379 -    else
  38.380 -    {
  38.381 -      System.out.println (show_helptxt);
  38.382 -      return;
  38.383 -    }
  38.384 -  }
  38.385 -
  38.386 -  void
  38.387 -  parse_addpartition(String[] commands)
  38.388 -  {
  38.389 -    String chunksize = default_addpartition_chunksize;
  38.390 -
  38.391 -    if (commands.length > 3 || commands.length < 2)
  38.392 -    {
  38.393 -      System.out.println ("addpartition <partition number> [chunksize]");
  38.394 -      return;
  38.395 -    }
  38.396 -    if (commands.length == 3)
  38.397 -    {
  38.398 -      chunksize = commands[2];
  38.399 -    }
  38.400 -
  38.401 -    System.out.println ("add partition " + commands[1] + " " + chunksize);
  38.402 -
  38.403 -    vdm.add_xeno_partition(pm.get_partition(Integer.parseInt(commands[1])), 
  38.404 -			   Library.parse_size(chunksize)/default_sector_size);
  38.405 -    pm.add_xeno_partition(pm.get_partition(Integer.parseInt(commands[1])));
  38.406 -  }
  38.407 -
  38.408 -  void
  38.409 -  parse_help()
  38.410 -  {
  38.411 -    System.out.println ("file <filename>     " +
  38.412 -			"read the contents of a file as input to vdmanager");
  38.413 -    System.out.println ("addpartition <partition number> [chunksize]");
  38.414 -    System.out.println ("                    " +
  38.415 -			"add a partition as a xeno partition");
  38.416 -    System.out.println ("vdcreate <name> <size> <expiry>");
  38.417 -    System.out.println ("                    " +
  38.418 -			"create a new virtual disk");
  38.419 -    System.out.println ("vddelete <key>      " +
  38.420 -			"delete a virtual disk");
  38.421 -    System.out.println ("vdrefresh <key> <expiry>");
  38.422 -    System.out.println ("                    " +
  38.423 -			"reset virtual disk expiry");
  38.424 -    System.out.println ("vbdcreate <key> <domain number> <vbd number> [rw|ro]");
  38.425 -    System.out.println ("                    " +
  38.426 -			"create a new virtual block device");
  38.427 -    System.out.println ("vbddelete <domain number> <vbd number>");
  38.428 -    System.out.println ("                    " +
  38.429 -			"delete a new virtual block device");
  38.430 -    System.out.println ("vbdflush            " +
  38.431 -			"remove all virtual block devices");
  38.432 -    System.out.println ("show partitions     " +
  38.433 -			"display a complete list of disk partitions");
  38.434 -    System.out.println ("show vd <vd number> " +
  38.435 -			"display virtual disk information");
  38.436 -    System.out.println ("show vbd            " +
  38.437 -			"display virtual virtual block device list");
  38.438 -    System.out.println ("show free           " +
  38.439 -			"display details about unallocated space");
  38.440 -    System.out.println ("load <filename>     " +
  38.441 -			"load new state from file");
  38.442 -    System.out.println ("save <filename>     " +
  38.443 -			"save state to file");
  38.444 -    System.out.println ("help                " +
  38.445 -			"display this help message");
  38.446 -    System.out.println ("quit                " +
  38.447 -			"exit");
  38.448 -  }
  38.449 -}