ia64/xen-unstable

changeset 638:9b6e7829eb39

bitkeeper revision 1.356 (3f13f2c2PyTtgUQ-EMLCir5OE3cd1g)

Add support for usr= argument to xenctl domain new
Add better argument construction (ro if root is a disk)
Add automatic physical disk access grant if root/usr are disks
author rac61@labyrinth.cl.cam.ac.uk
date Tue Jul 15 12:25:38 2003 +0000 (2003-07-15)
parents 9e2f11b00e2f
children 178a4dbaac17
files tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java tools/control/src/org/xenoserver/control/CommandDomainNew.java tools/control/src/org/xenoserver/control/Defaults.java tools/control/src/org/xenoserver/control/StringPattern.java
line diff
     1.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java	Tue Jul 15 10:42:54 2003 +0000
     1.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java	Tue Jul 15 12:25:38 2003 +0000
     1.3 @@ -4,7 +4,10 @@ import java.util.LinkedList;
     1.4  
     1.5  import org.xenoserver.control.CommandDomainNew;
     1.6  import org.xenoserver.control.CommandFailedException;
     1.7 +import org.xenoserver.control.CommandPhysicalGrant;
     1.8  import org.xenoserver.control.Defaults;
     1.9 +import org.xenoserver.control.Mode;
    1.10 +import org.xenoserver.control.StringPattern;
    1.11  
    1.12  public class ParseDomainNew extends CommandParser {
    1.13      public void parse(Defaults d, LinkedList args)
    1.14 @@ -16,6 +19,7 @@ public class ParseDomainNew extends Comm
    1.15          int vifs = getIntParameter(args, 'v', d.domainVIFs);
    1.16          String bargs = getStringParameter(args, 'a', d.args) + " ";
    1.17          String root_dev = getStringParameter(args, 'd', d.rootDevice);
    1.18 +        String usr_dev = getStringParameter(args, 'u', d.usrDevice);
    1.19          String nfs_root_path = getStringParameter(args, 'f', d.nwNFSRoot);
    1.20          String nw_ip = getStringParameter(args, '4', d.nwIP);
    1.21          String nw_gw = getStringParameter(args, 'g', d.nwGateway);
    1.22 @@ -40,12 +44,33 @@ public class ParseDomainNew extends Comm
    1.23                  nw_gw,
    1.24                  nw_mask,
    1.25                  nw_nfs_server,
    1.26 -                nw_host);
    1.27 +                nw_host,
    1.28 +                usr_dev);
    1.29          c.execute();
    1.30          String[] output = c.output();
    1.31          for (int i = 0; i < output.length; i++) {
    1.32              System.out.println(output[i]);
    1.33          }
    1.34 +        
    1.35 +        if (root_dev.startsWith("/dev/sda") || root_dev.startsWith("/dev/hda")) {
    1.36 +            String real_root = StringPattern.parse(root_dev).resolve(c.domain_id());
    1.37 +            String device = real_root.substring(real_root.indexOf('/',1)+1);
    1.38 +            CommandPhysicalGrant cg = new CommandPhysicalGrant(d,c.domain_id(),device,Mode.READ_WRITE,false);
    1.39 +            String output2 = cg.execute();
    1.40 +            if ( output2 != null ) {
    1.41 +                System.out.println(output2);
    1.42 +            }
    1.43 +        }
    1.44 +        
    1.45 +        if (usr_dev != null && (usr_dev.startsWith("/dev/sda")) || usr_dev.startsWith("/dev/hda")) {
    1.46 +            String real_usr = StringPattern.parse(usr_dev).resolve(c.domain_id());
    1.47 +            String device = real_usr.substring(real_usr.indexOf('/',1)+1);
    1.48 +            CommandPhysicalGrant cg = new CommandPhysicalGrant(d,c.domain_id(),device,Mode.READ_ONLY,false);
    1.49 +            String output2 = cg.execute();
    1.50 +            if ( output2 != null ) {
    1.51 +                System.out.println(output2);
    1.52 +            }
    1.53 +        }
    1.54      }
    1.55  
    1.56      public String getName() {
    1.57 @@ -53,7 +78,7 @@ public class ParseDomainNew extends Comm
    1.58      }
    1.59  
    1.60      public String getUsage() {
    1.61 -        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>]";
    1.62 +        return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-u<usr_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
    1.63      }
    1.64  
    1.65      public String getHelpText() {
    1.66 @@ -68,7 +93,8 @@ public class ParseDomainNew extends Comm
    1.67              + "  -v  Number of VIFs                           domain_vifs\n"
    1.68              + "  -r  InitRD (if required)                     domain_init_rd\n"
    1.69              + "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n"
    1.70 -            + "  -a  Additional boot parameters\n"
    1.71 +            + "  -u  Usr dev/path (e.g /dev/hda3, server:path)usr_device\n"
    1.72 +            + "  -a  Additional boot parameters               args\n"
    1.73              + "\n"
    1.74              + "Networking options:\n"
    1.75              + "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n"
     2.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainNew.java	Tue Jul 15 10:42:54 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainNew.java	Tue Jul 15 12:25:38 2003 +0000
     2.3 @@ -31,6 +31,8 @@ public class CommandDomainNew extends Co
     2.4      private String bargs;
     2.5      /** Root device */
     2.6      private String root_dev;
     2.7 +    /** Usr device */
     2.8 +    private String usr_dev;
     2.9      /** NFS root path */
    2.10      private String nfs_root_path;
    2.11      /** IP address */
    2.12 @@ -45,6 +47,8 @@ public class CommandDomainNew extends Co
    2.13      private String nw_host;
    2.14      /** Output from domain creation */
    2.15      private String[] output;
    2.16 +    /** Domain ID created. */
    2.17 +    private int domain_id;
    2.18  
    2.19      /**
    2.20       * @return Output from domain creation.
    2.21 @@ -52,6 +56,13 @@ public class CommandDomainNew extends Co
    2.22      public String[] output() {
    2.23          return output;
    2.24      }
    2.25 +    
    2.26 +    /**
    2.27 +     * @return The domain id this command created.
    2.28 +     */
    2.29 +    public int domain_id() {
    2.30 +        return domain_id;
    2.31 +    }
    2.32  
    2.33      /**
    2.34       * Constructor for CommandDomainNew.
    2.35 @@ -85,20 +96,40 @@ public class CommandDomainNew extends Co
    2.36          String nw_mask,
    2.37          String nw_nfs_server,
    2.38          String nw_host) {
    2.39 -        this.d = d;
    2.40 -        this.name = name;
    2.41 -        this.size = size;
    2.42 -        this.image = image;
    2.43 -        this.initrd = initrd;
    2.44 -        this.vifs = vifs;
    2.45 -        this.bargs = bargs;
    2.46 -        this.root_dev = root_dev;
    2.47 -        this.nfs_root_path = nfs_root_path;
    2.48 -        this.nw_ip = nw_ip;
    2.49 -        this.nw_gw = nw_gw;
    2.50 -        this.nw_mask = nw_mask;
    2.51 -        this.nw_nfs_server = nw_nfs_server;
    2.52 -        this.nw_host = nw_host;
    2.53 +        this(d,name,size,image,initrd,vifs,bargs,root_dev,nfs_root_path,nw_ip,nw_gw,nw_mask,nw_nfs_server,nw_host,null);
    2.54 +    }
    2.55 +    
    2.56 +    public CommandDomainNew(
    2.57 +        Defaults d,
    2.58 +        String name,
    2.59 +        int size,
    2.60 +        String image,
    2.61 +        String initrd,
    2.62 +        int vifs,
    2.63 +        String bargs,
    2.64 +        String root_dev,
    2.65 +        String nfs_root_path,
    2.66 +        String nw_ip,
    2.67 +        String nw_gw,
    2.68 +        String nw_mask,
    2.69 +        String nw_nfs_server,
    2.70 +        String nw_host,
    2.71 +        String usr_dev) {
    2.72 +            this.d = d;
    2.73 +            this.name = name;
    2.74 +            this.size = size;
    2.75 +            this.image = image;
    2.76 +            this.initrd = initrd;
    2.77 +            this.vifs = vifs;
    2.78 +            this.bargs = bargs;
    2.79 +            this.root_dev = root_dev;
    2.80 +            this.nfs_root_path = nfs_root_path;
    2.81 +            this.nw_ip = nw_ip;
    2.82 +            this.nw_gw = nw_gw;
    2.83 +            this.nw_mask = nw_mask;
    2.84 +            this.nw_nfs_server = nw_nfs_server;
    2.85 +            this.nw_host = nw_host;
    2.86 +            this.usr_dev = usr_dev;
    2.87      }
    2.88  
    2.89      /**
    2.90 @@ -189,9 +220,13 @@ public class CommandDomainNew extends Co
    2.91                          (bargs
    2.92                              + " root="
    2.93                              + StringPattern.parse(root_dev).resolve(domain_id)
    2.94 -                            + " ");
    2.95 +                            + " ro ");
    2.96  
    2.97                  }
    2.98 +                
    2.99 +                if (usr_dev != null && !usr_dev.equals("")) {
   2.100 +                    bargs = bargs + " usr=" + StringPattern.parse(usr_dev).resolve(domain_id) + " ";
   2.101 +                }
   2.102  
   2.103                  if (vifs > 0) {
   2.104                      domain_ip =
   2.105 @@ -316,6 +351,8 @@ public class CommandDomainNew extends Co
   2.106                  output[5] += vifinit_cmdarray[i] + " ";
   2.107              }
   2.108          }
   2.109 +        
   2.110 +        this.domain_id = domain_id;
   2.111  
   2.112          return null;
   2.113      }
     3.1 --- a/tools/control/src/org/xenoserver/control/Defaults.java	Tue Jul 15 10:42:54 2003 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/control/Defaults.java	Tue Jul 15 12:25:38 2003 +0000
     3.3 @@ -29,6 +29,8 @@ public class Defaults {
     3.4      public int domainVIFs;
     3.5      /** Default root device. */
     3.6      public String rootDevice;
     3.7 +    /** Default usr device. */
     3.8 +    public String usrDevice;
     3.9      /** Default IP address pattern. */
    3.10      public String nwIP;
    3.11      /** Default gateway pattern. */
    3.12 @@ -84,6 +86,7 @@ public class Defaults {
    3.13          System.out.println("   domainImage     " + domainImage);
    3.14          System.out.println("   domainInitRD    " + domainInitRD);
    3.15          System.out.println("   rootDevice      " + rootDevice);
    3.16 +        System.out.println("   usrDevice       " + usrDevice);
    3.17          System.out.println("   NWIP            " + nwIP);
    3.18          System.out.println("   NWGW            " + nwGateway);
    3.19          System.out.println("   NWMask          " + nwMask);
    3.20 @@ -146,6 +149,8 @@ public class Defaults {
    3.21                      domainVIFs = Integer.parseInt(s);
    3.22                  } else if (lastName.equals("root_device")) {
    3.23                      rootDevice = s;
    3.24 +                } else if (lastName.equals("usr_device")) {
    3.25 +                    usrDevice = s;
    3.26                  } else if (lastName.equals("nw_ip")) {
    3.27                      nwIP =
    3.28                          expandDefault(
     4.1 --- a/tools/control/src/org/xenoserver/control/StringPattern.java	Tue Jul 15 10:42:54 2003 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/control/StringPattern.java	Tue Jul 15 12:25:38 2003 +0000
     4.3 @@ -18,7 +18,7 @@ public class StringPattern {
     4.4       * @param t The pattern string to parse.
     4.5       * @return A usable pattern object.
     4.6       */
     4.7 -    static StringPattern parse(String t) {
     4.8 +    public static StringPattern parse(String t) {
     4.9          StringPattern result = new StringPattern();
    4.10          char[] ca = t.toCharArray();
    4.11          int idx = 0;
    4.12 @@ -53,7 +53,7 @@ public class StringPattern {
    4.13       * @param domain The domain number to use.
    4.14       * @return The expanded pattern for the given domain.
    4.15       */
    4.16 -    String resolve(int domain) {
    4.17 +    public String resolve(int domain) {
    4.18          if (addDom) {
    4.19              return base + (bn + domain);
    4.20          } else if (appendDom) {