From 115e984cb1a8de13910124ec68fce38497963f1e Mon Sep 17 00:00:00 2001 From: "rac61@labyrinth.cl.cam.ac.uk" Date: Tue, 8 Jul 2003 13:02:26 +0000 Subject: bitkeeper revision 1.289.1.4 (3f0ac0e2RKTYkaGxMaS0yvsU2le2uA) Finish converting to support correct way of getting partition/disk numbers Code cleanups --- .../src/org/xenoserver/cmdline/CommandParser.java | 186 ++++--- .../src/org/xenoserver/cmdline/ParseDomainNew.java | 12 +- .../org/xenoserver/cmdline/ParsePhysicalGrant.java | 7 +- .../xenoserver/cmdline/ParsePhysicalRevoke.java | 6 +- .../src/org/xenoserver/control/Command.java | 38 +- .../xenoserver/control/CommandDomainDestroy.java | 98 ++-- .../org/xenoserver/control/CommandDomainList.java | 173 +++--- .../org/xenoserver/control/CommandDomainNew.java | 578 +++++++++++---------- .../org/xenoserver/control/CommandDomainStart.java | 83 +-- .../org/xenoserver/control/CommandDomainStop.java | 83 +-- .../xenoserver/control/CommandFailedException.java | 53 +- .../xenoserver/control/CommandPartitionAdd.java | 42 +- .../xenoserver/control/CommandPhysicalGrant.java | 133 ++--- .../xenoserver/control/CommandPhysicalList.java | 23 +- .../xenoserver/control/CommandPhysicalRevoke.java | 101 ++-- .../org/xenoserver/control/CommandVdCreate.java | 51 +- .../org/xenoserver/control/CommandVdDelete.java | 33 +- .../org/xenoserver/control/CommandVdRefresh.java | 47 +- .../src/org/xenoserver/control/Defaults.java | 377 +++++++------- .../control/src/org/xenoserver/control/Domain.java | 57 +- .../src/org/xenoserver/control/Partition.java | 15 + 21 files changed, 1227 insertions(+), 969 deletions(-) (limited to 'tools') diff --git a/tools/control/src/org/xenoserver/cmdline/CommandParser.java b/tools/control/src/org/xenoserver/cmdline/CommandParser.java index 35b7c236be..1f558c3605 100644 --- a/tools/control/src/org/xenoserver/cmdline/CommandParser.java +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java @@ -16,83 +16,127 @@ import org.xenoserver.control.XML; * and execute it, displaying any output. */ public abstract class CommandParser { - /** - * Subclasses should implement this method such that it outputs any successful - * output to the screen, or throws an exception if required arguments - * are missing or malformed. It also may propagate exceptions from the - * command execution. - * - * @param d The defaults object to use. - * @param args The arguments to parse. - * @throws ParseFailedException if the arguments are not suitable. - * @throws CommandFailedException if the command did not execute successfully. - */ - public abstract void parse(Defaults d, LinkedList args) - throws ParseFailedException, CommandFailedException; + /** + * Subclasses should implement this method such that it outputs any successful + * output to the screen, or throws an exception if required arguments + * are missing or malformed. It also may propagate exceptions from the + * command execution. + * + * @param d The defaults object to use. + * @param args The arguments to parse. + * @throws ParseFailedException if the arguments are not suitable. + * @throws CommandFailedException if the command did not execute successfully. + */ + public abstract void parse(Defaults d, LinkedList args) + throws ParseFailedException, CommandFailedException; - /** Return the command name which will be matched on the command line. */ - public abstract String getName(); - /** Return a usage string for this command. */ - public abstract String getUsage(); - /** Return the help text for this command. */ - public abstract String getHelpText(); - - /** Print a usage string for this command. */ - public void printUsage(String prefix) - { - String name = getName(); - if ( prefix != null ) - name = prefix + " " + name; - String usage = getUsage(); - while (name.length() < 16) - name = name + " "; - System.out.println(" " + name + usage); - } - - /** Prints the help text for this command. */ - public void printHelpText(LinkedList args) - { - System.out.println(getName() + " " + getUsage()); - System.out.println(); - System.out.println(getHelpText()); - } + /** @return The command name which will be matched on the command line. */ + public abstract String getName(); + /** @return A usage string for this command. */ + public abstract String getUsage(); + /** @return The help text for this command. */ + public abstract String getHelpText(); - public String getStringParameter(List args, char key, String def) { - String r = getParameter(args, key); - return (r == null) ? def : r; - } + /** + * Print a usage string for this command. + * @param prefix The command prefix for this command + */ + public void printUsage(String prefix) { + String name = getName(); + if (prefix != null) { + name = prefix + " " + name; + } + String usage = getUsage(); + while (name.length() < 16) { + name = name + " "; + } + System.out.println(" " + name + usage); + } + + /** + * Prints the help text for this command. + * @param args Command arguments, ignored for normal commands. + */ + public void printHelpText(LinkedList args) { + System.out.println(getName() + " " + getUsage()); + System.out.println(); + System.out.println(getHelpText()); + } + + /** + * Get a string parameter + * @param args Argument list to search + * @param key Argument key + * @param def Default value + * @return parameter, or default if none found + */ + public String getStringParameter(List args, char key, String def) { + String r = getParameter(args, key); + return (r == null) ? def : r; + } - public int getIntParameter(List args, char key, int def) { - String r = getParameter(args, key); - return (r == null) ? def : (Integer.parseInt(r)); - } + /** + * Get an int parameter + * @param args Argument list to search + * @param key Argument key + * @param def Default value + * @return parameter, or default if none found + */ + public int getIntParameter(List args, char key, int def) { + String r = getParameter(args, key); + return (r == null) ? def : (Integer.parseInt(r)); + } - public boolean getFlagParameter(List args, char key) { - String r = getParameter(args, key); - return (r == null) ? false : true; - } + /** + * Get a boolean parameter + * @param args Argument list to search + * @param key Argument key + * @return parameter, or false if none found + */ + public boolean getFlagParameter(List args, char key) { + String r = getParameter(args, key); + return (r == null) ? false : true; + } - protected String getParameter(List args, char key) { - String result = null; - Iterator i = args.iterator(); - while ( i.hasNext() ) { - String arg = (String) i.next(); - if (arg.startsWith("-" + key)) { - if (arg.length() > 2) { - result = arg.substring(2); - } else { - result = ""; + /** + * Get a parameter + * @param args Argument list to search + * @param key Key to look for + * @return Value, or "" if no value, or null if no such argument + */ + protected String getParameter(List args, char key) { + String result = null; + Iterator i = args.iterator(); + while (i.hasNext()) { + String arg = (String) i.next(); + if (arg.startsWith("-" + key)) { + if (arg.length() > 2) { + result = arg.substring(2); + } else { + result = ""; + } + } } - } + return result; } - return result; - } - protected void loadState() { - XML.loadState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_INPUT_FILE ); - } - - protected void saveState() { - XML.saveState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_OUTPUT_FILE ); - } + /** + * Load the partition and disk manager state + */ + protected void loadState() { + XML.loadState( + PartitionManager.IT, + VirtualDiskManager.IT, + Settings.STATE_INPUT_FILE); + } + + /** + * Save the partition and disk manager state + */ + protected void saveState() { + XML.saveState( + PartitionManager.IT, + VirtualDiskManager.IT, + Settings.STATE_OUTPUT_FILE); + } } diff --git a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java index 66f7ac763f..069d439b16 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java @@ -16,12 +16,12 @@ public class ParseDomainNew extends CommandParser { int vifs = getIntParameter(args, 'v', d.domainVIFs); String bargs = getStringParameter (args, 'a', d.args) + " "; String root_dev = getStringParameter (args, 'd', d.rootDevice); - String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot); - String nw_ip = getStringParameter (args, '4', d.NWIP); - String nw_gw = getStringParameter (args, 'g', d.NWGW); - String nw_mask = getStringParameter (args, 'm', d.NWMask); - String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer); - String nw_host = getStringParameter (args, 'h', d.NWHost); + String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot); + String nw_ip = getStringParameter (args, '4', d.nwIP); + String nw_gw = getStringParameter (args, 'g', d.nwGateway); + String nw_mask = getStringParameter (args, 'm', d.nwMask); + String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer); + String nw_host = getStringParameter (args, 'h', d.nwHost); d.describe(); diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java index af3c7a6b47..629d2cb3bf 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java @@ -5,7 +5,6 @@ import java.util.LinkedList; import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.CommandPhysicalGrant; import org.xenoserver.control.Defaults; -import org.xenoserver.control.Extent; import org.xenoserver.control.Mode; import org.xenoserver.control.Partition; import org.xenoserver.control.PartitionManager; @@ -39,11 +38,7 @@ public class ParsePhysicalGrant extends CommandParser { if (p.isXeno() && !force) 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."); - // Convert the partition into a physical extent - Extent e = p.toExtent(); - int partition_no = p.getMinor() & 0x1F; - - String output = new CommandPhysicalGrant( d, domain_id, e, mode, partition_no ).execute(); + String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute(); if ( output != null ) System.out.println( output ); } diff --git a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java index 5c0e80201f..a5c90a720d 100644 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java @@ -5,7 +5,6 @@ import java.util.LinkedList; import org.xenoserver.control.CommandFailedException; import org.xenoserver.control.CommandPhysicalRevoke; import org.xenoserver.control.Defaults; -import org.xenoserver.control.Extent; import org.xenoserver.control.Partition; import org.xenoserver.control.PartitionManager; @@ -26,10 +25,7 @@ public class ParsePhysicalRevoke extends CommandParser { if ( p == null ) throw new CommandFailedException("Partition " + partition_name + " does not exist."); - // Convert the partition into a physical extent - Extent e = p.toExtent(); - - String output = new CommandPhysicalRevoke( d, domain_id, e ).execute(); + String output = new CommandPhysicalRevoke( d, domain_id, p ).execute(); if ( output != null ) System.out.println( output ); } diff --git a/tools/control/src/org/xenoserver/control/Command.java b/tools/control/src/org/xenoserver/control/Command.java index a327f29973..c2759b0ea9 100644 --- a/tools/control/src/org/xenoserver/control/Command.java +++ b/tools/control/src/org/xenoserver/control/Command.java @@ -5,23 +5,27 @@ package org.xenoserver.control; * and virtual disk settings. */ public abstract class Command { - /** - * Subclasses should define an execute method which will apply the - * relevant change, if possible. - * - * @return The results of executing the command, if successful, or null if - * the command does not need to return results. - * @throws CommandFailedException if the command could not be completed. - */ - public abstract String execute() throws CommandFailedException; + /** + * Subclasses should define an execute method which will apply the + * relevant change, if possible. + * + * @return The results of executing the command, if successful, or null if + * the command does not need to return results. + * @throws CommandFailedException if the command could not be completed. + */ + public abstract String execute() throws CommandFailedException; - protected String reportCommand (String cmd_array[]) - { - StringBuffer sb = new StringBuffer(); - int i; - for (i = 0; i < cmd_array.length; i ++) { - sb.append (cmd_array[i] + " "); + /** + * Construct a string to report the execution of a command. + * @param cmd_array The array of command parameters. + * @return The report string. + */ + protected String reportCommand(String[] cmd_array) { + StringBuffer sb = new StringBuffer(); + int i; + for (i = 0; i < cmd_array.length; i++) { + sb.append(cmd_array[i] + " "); + } + return sb.toString(); } - return sb.toString(); - } } diff --git a/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java b/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java index 6bb66167ae..7d9f0a8cd3 100644 --- a/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java +++ b/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java @@ -4,55 +4,65 @@ package org.xenoserver.control; * Destroys a domain. */ public class CommandDomainDestroy extends Command { - private Defaults d; - private int domain_id; - private boolean force; + /** Defaults instance in use. */ + private Defaults d; + /** Domain ID to destroy. */ + private int domain_id; + /** Force destruction? */ + private boolean force; - /** - * Constructor for CommandDomainDestroy. - * - * @param d Defaults object to use. - * @param domain_id Domain ID number to destroy. - * @param force Force destruction. - */ - public CommandDomainDestroy(Defaults d, int domain_id, boolean force) { - this.d = d; - this.domain_id = domain_id; - this.force = force; - } + /** + * Constructor for CommandDomainDestroy. + * + * @param d Defaults object to use. + * @param domain_id Domain ID number to destroy. + * @param force Force destruction. + */ + public CommandDomainDestroy(Defaults d, int domain_id, boolean force) { + this.d = d; + this.domain_id = domain_id; + this.force = force; + } - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - String output = null; + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + String output = null; - try { - Process destroy_p; - String destroy_cmdarray[] = force ? new String[3] : new String[2]; - int destroy_rc; - int idx = 0; - destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy"; - if (force) { - destroy_cmdarray[idx++] = "-f"; - } - destroy_cmdarray[idx++] = "" + domain_id; + try { + Process destroy_p; + String destroy_cmdarray[] = force ? new String[3] : new String[2]; + int destroy_rc; + int idx = 0; + destroy_cmdarray[idx++] = d.xiToolsDir + "xi_destroy"; + if (force) { + destroy_cmdarray[idx++] = "-f"; + } + destroy_cmdarray[idx++] = "" + domain_id; - if (Settings.TEST) { - output = reportCommand(destroy_cmdarray); - } else { - destroy_p = r.exec(destroy_cmdarray); - destroy_rc = destroy_p.waitFor(); + if (Settings.TEST) { + output = reportCommand(destroy_cmdarray); + } else { + destroy_p = r.exec(destroy_cmdarray); + destroy_rc = destroy_p.waitFor(); - if (destroy_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray); + if (destroy_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not destroy domain", + destroy_cmdarray); + } + output = "Destroyed domain " + domain_id; + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not destroy domain (" + e + ")", + e); } - output = "Destroyed domain " + domain_id; - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not destroy domain (" + e + ")", e); - } - return output; - } + return output; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandDomainList.java b/tools/control/src/org/xenoserver/control/CommandDomainList.java index 69b2ca04a9..4defb1b922 100644 --- a/tools/control/src/org/xenoserver/control/CommandDomainList.java +++ b/tools/control/src/org/xenoserver/control/CommandDomainList.java @@ -10,98 +10,109 @@ import java.util.Vector; * domains() to get the array of domains. */ public class CommandDomainList extends Command { - private Defaults d; - private Domain[] array; + /** Defaults instance in use. */ + private Defaults d; + /** Array of domains returned. */ + private Domain[] array; + + /** + * Constructor for CommandDomainList. + * @param d Defaults object to use. + */ + public CommandDomainList(Defaults d) { + this.d = d; + } - /** - * Constructor for CommandDomainList. - * @param d Defaults object to use. - */ - public CommandDomainList(Defaults d) { - this.d = d; - } + /** + * Retrieves the list of domains. + * @return null, call domains() to get the list. + * @throws CommandFailedException if the list could not be retrieved. + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + Vector v = new Vector(); + String outline; + BufferedReader in; + String output = null; - /** - * Retrieves the list of domains. - * @return null, call domains() to get the list. - */ - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - Vector v = new Vector(); - String outline; - BufferedReader in; - String output = null; + try { + Process start_p; + String start_cmdarray[] = new String[1]; + int start_rc; + start_cmdarray[0] = d.xiToolsDir + "xi_list"; - try { - Process start_p; - String start_cmdarray[] = new String[1]; - int start_rc; - start_cmdarray[0] = d.XIToolsDir + "xi_list"; + if (Settings.TEST) { + output = reportCommand(start_cmdarray); + } else { + start_p = r.exec(start_cmdarray); + start_rc = start_p.waitFor(); + if (start_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not get domain list", + start_cmdarray); + } - if (Settings.TEST) { - output = reportCommand(start_cmdarray); - } else { - start_p = r.exec(start_cmdarray); - start_rc = start_p.waitFor(); - if (start_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray); - } + in = + new BufferedReader( + new InputStreamReader(start_p.getInputStream())); - in = - new BufferedReader(new InputStreamReader(start_p.getInputStream())); + outline = in.readLine(); + while (outline != null) { + Domain domain = new Domain(); - outline = in.readLine(); - while (outline != null) { - Domain domain = new Domain(); + StringTokenizer st = new StringTokenizer(outline); + if (st.hasMoreTokens()) { + domain.id = Integer.parseInt(st.nextToken()); + } + if (st.hasMoreTokens()) { + domain.processor = Integer.parseInt(st.nextToken()); + } + if (st.hasMoreTokens()) { + if (st.nextToken().equals("1")) { + domain.cpu = true; + } else { + domain.cpu = false; + } + } + if (st.hasMoreTokens()) { + domain.nstate = Integer.parseInt(st.nextToken()); + } + if (st.hasMoreTokens()) { + domain.state = st.nextToken().toLowerCase(); + } + if (st.hasMoreTokens()) { + domain.mcu = Integer.parseInt(st.nextToken()); + } + if (st.hasMoreTokens()) { + domain.pages = Integer.parseInt(st.nextToken()); + } + if (st.hasMoreTokens()) { + domain.name = st.nextToken(); + } - StringTokenizer st = new StringTokenizer(outline); - if (st.hasMoreTokens()) { - domain.id = Integer.parseInt(st.nextToken()); - } - if (st.hasMoreTokens()) { - domain.processor = Integer.parseInt(st.nextToken()); - } - if (st.hasMoreTokens()) { - if (st.nextToken().equals("1")) { - domain.cpu = true; - } else { - domain.cpu = false; - } - } - if (st.hasMoreTokens()) { - domain.nstate = Integer.parseInt(st.nextToken()); - } - if (st.hasMoreTokens()) { - domain.state = st.nextToken().toLowerCase(); - } - if (st.hasMoreTokens()) { - domain.mcu = Integer.parseInt(st.nextToken()); - } - if (st.hasMoreTokens()) { - domain.pages = Integer.parseInt(st.nextToken()); - } - if (st.hasMoreTokens()) { - domain.name = st.nextToken(); - } + v.add(domain); - v.add(domain); + outline = in.readLine(); + } - outline = in.readLine(); + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not get domain list(" + e + ")", + e); } - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not get domain list(" + e + ")", e); + array = new Domain[v.size()]; + v.toArray(array); + return output; } - array = new Domain[v.size()]; - v.toArray(array); - return output; - } - - public Domain[] domains() { - return array; - } + /** + * @return Array of domains. + */ + public Domain[] domains() { + return array; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandDomainNew.java b/tools/control/src/org/xenoserver/control/CommandDomainNew.java index 50fa6da5dc..4729cab55a 100644 --- a/tools/control/src/org/xenoserver/control/CommandDomainNew.java +++ b/tools/control/src/org/xenoserver/control/CommandDomainNew.java @@ -15,287 +15,339 @@ import java.util.zip.GZIPInputStream; * call output() to get an array of strings. */ public class CommandDomainNew extends Command { - private Defaults d; - private String name; - private int size; - private String image; - private String initrd; - private int vifs; - private String bargs; - private String root_dev; - private String nfs_root_path; - private String nw_ip; - private String nw_gw; - private String nw_mask; - private String nw_nfs_server; - private String nw_host; - private String[] output; - - public String[] output() { - return output; - } - - /** - * Constructor for CommandDomainNew. - * @param d Defaults object to use. - * @param name Name for the domain. - * @param size Memory size for the domain. - * @param image Image to boot domain from. - * @param initrd Initrd to boot domain with. - * @param vifs Number of virtual interfaces for the domain. - * @param bargs Boot arguments for the domain. - * @param root_dev Root device for the domain. - * @param nfs_root_path NFS root to be used by the domain. - * @param nw_ip IP address pattern to use for the domain's interfaces. - * @param nw_gw Gateway to configure the domain for. - * @param nw_mask Network mask to configure the domain for. - * @param nw_nfs_server NFS server to be used by the domain. - * @param nw_host Hostname to be used by the domain. - */ - public CommandDomainNew( - Defaults d, - String name, - int size, - String image, - String initrd, - int vifs, - String bargs, - String root_dev, - String nfs_root_path, - String nw_ip, - String nw_gw, - String nw_mask, - String nw_nfs_server, - String nw_host) { - this.d = d; - this.name = name; - this.size = size; - this.image = image; - this.initrd = initrd; - this.vifs = vifs; - this.bargs = bargs; - this.root_dev = root_dev; - this.nfs_root_path = nfs_root_path; - this.nw_ip = nw_ip; - this.nw_gw = nw_gw; - this.nw_mask = nw_mask; - this.nw_nfs_server = nw_nfs_server; - this.nw_host = nw_host; - } + /** Defaults instance in use. */ + private Defaults d; + /** Name of new domain. */ + private String name; + /** Memory size for new domain. */ + private int size; + /** Kernel image */ + private String image; + /** Initial ramdisk */ + private String initrd; + /** Num of virtual interfaces */ + private int vifs; + /** Boot arguments */ + private String bargs; + /** Root device */ + private String root_dev; + /** NFS root path */ + private String nfs_root_path; + /** IP address */ + private String nw_ip; + /** Gateway */ + private String nw_gw; + /** netmask */ + private String nw_mask; + /** NFS server */ + private String nw_nfs_server; + /** Hostname */ + private String nw_host; + /** Output from domain creation */ + private String[] output; - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - int domain_id = -1; - BufferedReader br; - int idx; - int i; - File image_tmp = null; - File initrd_tmp = null; - String domain_ip = ""; - - String create_cmdarray[] = new String[3]; - String build_cmdarray[] = new String[6]; - String vifinit_cmdarray[] = new String[4]; + /** + * @return Output from domain creation. + */ + public String[] output() { + return output; + } - try { - try { - /* Some initial sanity checks */ - if (root_dev.equals("/dev/nfs") && (vifs == 0)) { - throw new CommandFailedException("Cannot use NFS root without VIFs configured"); - } + /** + * Constructor for CommandDomainNew. + * @param d Defaults object to use. + * @param name Name for the domain. + * @param size Memory size for the domain. + * @param image Image to boot domain from. + * @param initrd Initrd to boot domain with. + * @param vifs Number of virtual interfaces for the domain. + * @param bargs Boot arguments for the domain. + * @param root_dev Root device for the domain. + * @param nfs_root_path NFS root to be used by the domain. + * @param nw_ip IP address pattern to use for the domain's interfaces. + * @param nw_gw Gateway to configure the domain for. + * @param nw_mask Network mask to configure the domain for. + * @param nw_nfs_server NFS server to be used by the domain. + * @param nw_host Hostname to be used by the domain. + */ + public CommandDomainNew( + Defaults d, + String name, + int size, + String image, + String initrd, + int vifs, + String bargs, + String root_dev, + String nfs_root_path, + String nw_ip, + String nw_gw, + String nw_mask, + String nw_nfs_server, + String nw_host) { + this.d = d; + this.name = name; + this.size = size; + this.image = image; + this.initrd = initrd; + this.vifs = vifs; + this.bargs = bargs; + this.root_dev = root_dev; + this.nfs_root_path = nfs_root_path; + this.nw_ip = nw_ip; + this.nw_gw = nw_gw; + this.nw_mask = nw_mask; + this.nw_nfs_server = nw_nfs_server; + this.nw_host = nw_host; + } - /* Uncompress the image and initrd */ - if (image.endsWith(".gz")) { - image_tmp = getUncompressed("xen-image-", image); - image = image_tmp.getPath(); - } + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + int domain_id = -1; + BufferedReader br; + int idx; + int i; + File image_tmp = null; + File initrd_tmp = null; + String domain_ip = ""; - if (initrd != null && initrd.endsWith(".gz")) { - initrd_tmp = getUncompressed("xen-initrd-", initrd); - initrd = initrd_tmp.getPath(); - } + String create_cmdarray[] = new String[3]; + String build_cmdarray[] = new String[6]; + String vifinit_cmdarray[] = new String[4]; - /* Create a new empty domain */ - Process create_p; - int create_rc; - create_cmdarray[0] = d.XIToolsDir + "xi_create"; - create_cmdarray[1] = "" + size; - create_cmdarray[2] = name; - if (Settings.TEST) { - reportCommand(create_cmdarray); - domain_id = 1; - create_rc = 0; - } else { - create_p = r.exec(create_cmdarray); - br = - new BufferedReader( - new InputStreamReader(create_p.getInputStream())); - domain_id = Integer.parseInt(br.readLine()); - create_rc = create_p.waitFor(); - } + try { + try { + /* Some initial sanity checks */ + if (root_dev.equals("/dev/nfs") && (vifs == 0)) { + throw new CommandFailedException("Cannot use NFS root without VIFs configured"); + } - if (create_rc != 0) { - throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray); - } else if (domain_id > d.MaxDomainNumber) { - throw new CommandFailedException( - "Cannot configure more than " + d.MaxDomainNumber + " domains"); - } + /* Uncompress the image and initrd */ + if (image.endsWith(".gz")) { + image_tmp = getUncompressed("xen-image-", image); + image = image_tmp.getPath(); + } - /* Set up boot parameters to pass to xi_build. */ - if (root_dev.equals("/dev/nfs")) { - if (vifs == 0) { - throw new CommandFailedException("Cannot use NFS root without VIFs configured"); - } - if (nfs_root_path == null) { - throw new CommandFailedException("No NFS root specified"); - } - if (nw_nfs_server == null) { - throw new CommandFailedException("No NFS server specified"); - } - bargs = - (bargs - + " root=/dev/nfs " - + "nfsroot=" - + StringPattern.parse(nfs_root_path).resolve(domain_id) - + " "); - } else { - bargs = - (bargs - + " root=" - + StringPattern.parse(root_dev).resolve(domain_id) - + " "); + if (initrd != null && initrd.endsWith(".gz")) { + initrd_tmp = getUncompressed("xen-initrd-", initrd); + initrd = initrd_tmp.getPath(); + } - } + /* Create a new empty domain */ + Process create_p; + int create_rc; + create_cmdarray[0] = d.xiToolsDir + "xi_create"; + create_cmdarray[1] = "" + size; + create_cmdarray[2] = name; + if (Settings.TEST) { + reportCommand(create_cmdarray); + domain_id = 1; + create_rc = 0; + } else { + create_p = r.exec(create_cmdarray); + br = + new BufferedReader( + new InputStreamReader(create_p.getInputStream())); + domain_id = Integer.parseInt(br.readLine()); + create_rc = create_p.waitFor(); + } - if (vifs > 0) { - domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id); - if (nw_host == null) { - try { - nw_host = InetAddress.getByName(domain_ip).getHostName(); - } catch (UnknownHostException uhe) { - nw_host = "" + nw_ip; - } + if (create_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Failed to create domain", + create_cmdarray); + } else if (domain_id > d.maxDomainNumber) { + throw new CommandFailedException( + "Cannot configure more than " + + d.maxDomainNumber + + " domains"); + } - } - bargs = - ("ip=" - + domain_ip - + ":" - + ((nw_nfs_server == null) - ? "" - : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id))) - + ":" - + ((nw_gw == null) - ? "" - : (InetAddressPattern.parse(nw_gw).resolve(domain_id))) - + ":" - + ((nw_mask == null) - ? "" - : InetAddressPattern.parse(nw_mask).resolve(domain_id)) - + ":" - + ((nw_host == null) ? "" : nw_host) - + ":eth0:off " - + bargs); - } + /* Set up boot parameters to pass to xi_build. */ + if (root_dev.equals("/dev/nfs")) { + if (vifs == 0) { + throw new CommandFailedException("Cannot use NFS root without VIFs configured"); + } + if (nfs_root_path == null) { + throw new CommandFailedException("No NFS root specified"); + } + if (nw_nfs_server == null) { + throw new CommandFailedException("No NFS server specified"); + } + bargs = + (bargs + + " root=/dev/nfs " + + "nfsroot=" + + StringPattern.parse(nfs_root_path).resolve( + domain_id) + + " "); + } else { + bargs = + (bargs + + " root=" + + StringPattern.parse(root_dev).resolve(domain_id) + + " "); - /* Build the domain */ - Process build_p; - int build_rc; - idx = 0; - for (i = 0; i < build_cmdarray.length; i++) - build_cmdarray[i] = ""; - build_cmdarray[idx++] = d.XIToolsDir + "xi_build"; - build_cmdarray[idx++] = "" + domain_id; - build_cmdarray[idx++] = "" + image; - build_cmdarray[idx++] = "" + vifs; - if (initrd != null) - build_cmdarray[idx++] = "initrd=" + initrd; - build_cmdarray[idx++] = "" + bargs; - if (Settings.TEST) { - reportCommand(build_cmdarray); - build_rc = 0; - } else { - build_p = r.exec(build_cmdarray); - build_rc = build_p.waitFor(); - } + } + + if (vifs > 0) { + domain_ip = + InetAddressPattern.parse(nw_ip).resolve(domain_id); + if (nw_host == null) { + try { + nw_host = + InetAddress.getByName(domain_ip).getHostName(); + } catch (UnknownHostException uhe) { + nw_host = "" + nw_ip; + } + + } + bargs = + ("ip=" + + domain_ip + + ":" + + ((nw_nfs_server == null) + ? "" + : (InetAddressPattern + .parse(nw_nfs_server) + .resolve(domain_id))) + + ":" + + ((nw_gw == null) + ? "" + : (InetAddressPattern + .parse(nw_gw) + .resolve(domain_id))) + + ":" + + ((nw_mask == null) + ? "" + : InetAddressPattern.parse(nw_mask).resolve( + domain_id)) + + ":" + + ((nw_host == null) ? "" : nw_host) + + ":eth0:off " + + bargs); + } - if (build_rc != 0) { - throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray); + /* Build the domain */ + Process build_p; + int build_rc; + idx = 0; + for (i = 0; i < build_cmdarray.length; i++) { + build_cmdarray[i] = ""; + } + build_cmdarray[idx++] = d.xiToolsDir + "xi_build"; + build_cmdarray[idx++] = "" + domain_id; + build_cmdarray[idx++] = "" + image; + build_cmdarray[idx++] = "" + vifs; + if (initrd != null) { + build_cmdarray[idx++] = "initrd=" + initrd; + } + build_cmdarray[idx++] = "" + bargs; + if (Settings.TEST) { + reportCommand(build_cmdarray); + build_rc = 0; + } else { + build_p = r.exec(build_cmdarray); + build_rc = build_p.waitFor(); + } + + if (build_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Failed to build domain", + build_cmdarray); + } + + /* Set up the first VIF if necessary */ + if (vifs > 0) { + Process vifinit_p; + int vifinit_rc; + vifinit_cmdarray[0] = d.xiToolsDir + "xi_vifinit"; + vifinit_cmdarray[1] = "" + domain_id; + vifinit_cmdarray[2] = "0"; + vifinit_cmdarray[3] = domain_ip; + if (Settings.TEST) { + reportCommand(vifinit_cmdarray); + vifinit_rc = 0; + } else { + vifinit_p = r.exec(vifinit_cmdarray); + vifinit_rc = vifinit_p.waitFor(); + } + + if (vifinit_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Failed to initialise VIF 0", + vifinit_cmdarray); + } + } + } finally { + if (image_tmp != null) { + image_tmp.delete(); + } + if (initrd_tmp != null) { + initrd_tmp.delete(); + } + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not create new domain (" + e + ")", + e); } - /* Set up the first VIF if necessary */ + output = new String[vifs > 0 ? 6 : 4]; + output[0] = "Domain created with arguments:"; + output[1] = ""; + for (i = 0; i < create_cmdarray.length; i++) { + output[1] += create_cmdarray[i] + " "; + } + output[2] = "Domain built with arguments:"; + output[3] = ""; + for (i = 0; i < build_cmdarray.length; i++) { + output[3] += build_cmdarray[i] + " "; + } if (vifs > 0) { - Process vifinit_p; - int vifinit_rc; - vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit"; - vifinit_cmdarray[1] = "" + domain_id; - vifinit_cmdarray[2] = "0"; - vifinit_cmdarray[3] = domain_ip; - if (Settings.TEST) { - reportCommand(vifinit_cmdarray); - vifinit_rc = 0; - } else { - vifinit_p = r.exec(vifinit_cmdarray); - vifinit_rc = vifinit_p.waitFor(); - } - - if (vifinit_rc != 0) { - throw CommandFailedException.XICommandFailed( - "Failed to initialise VIF 0", - vifinit_cmdarray); - } + output[4] = "VIF 0 initialized with arguments:"; + output[5] = ""; + for (i = 0; i < vifinit_cmdarray.length; i++) { + output[5] += vifinit_cmdarray[i] + " "; + } } - } finally { - if (image_tmp != null) - image_tmp.delete(); - if (initrd_tmp != null) - initrd_tmp.delete(); - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not create new domain (" + e + ")", e); - } - output = new String[ vifs > 0 ? 6 : 4 ]; - output[0] = "Domain created with arguments:"; - output[1] = ""; - for (i = 0; i < create_cmdarray.length; i++) - output[1] += create_cmdarray[i] + " "; - output[2] = "Domain built with arguments:"; - output[3] = ""; - for (i = 0; i < build_cmdarray.length; i++) - output[3] += build_cmdarray[i] + " "; - if ( vifs > 0 ) { - output[4] = "VIF 0 initialized with arguments:"; - output[5] = ""; - for (i = 0; i < vifinit_cmdarray.length; i++) - output[5] += vifinit_cmdarray[i] + " "; + return null; } - return null; - } - - private File getUncompressed (String prefix, String original) throws IOException { - FileOutputStream fos; - GZIPInputStream gis; - File result; - byte buffer[] = new byte[1024]; - int l; - - result = File.createTempFile (prefix, null); - - try { - fos = new FileOutputStream (result); - gis = new GZIPInputStream (new FileInputStream (original)); - while ((l = gis.read(buffer, 0, buffer.length)) != -1) { - fos.write (buffer, 0, l); - } - } catch (IOException ioe) { - result.delete (); - throw ioe; - } + /** + * Get uncompressed version of file. + * @param prefix Temp file prefix. + * @param original Original filename. + * @return Uncompressed file. + * @throws IOException if decompression failed. + */ + private File getUncompressed(String prefix, String original) + throws IOException { + FileOutputStream fos; + GZIPInputStream gis; + File result; + byte buffer[] = new byte[1024]; + int l; - return result; - } + result = File.createTempFile(prefix, null); + + try { + fos = new FileOutputStream(result); + gis = new GZIPInputStream(new FileInputStream(original)); + while ((l = gis.read(buffer, 0, buffer.length)) != -1) { + fos.write(buffer, 0, l); + } + } catch (IOException ioe) { + result.delete(); + throw ioe; + } + + return result; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandDomainStart.java b/tools/control/src/org/xenoserver/control/CommandDomainStart.java index 1719da233e..71ba043043 100644 --- a/tools/control/src/org/xenoserver/control/CommandDomainStart.java +++ b/tools/control/src/org/xenoserver/control/CommandDomainStart.java @@ -4,46 +4,55 @@ package org.xenoserver.control; * Starts a domain. */ public class CommandDomainStart extends Command { - private Defaults d; - private int domain_id; - - /** - * Constructor for CommandDomainStart. - * @param d Defaults object to use. - * @param domain_id Domain to start. - */ - public CommandDomainStart(Defaults d, int domain_id) { - this.d = d; - this.domain_id = domain_id; - } + /** Defaults instance in use. */ + private Defaults d; + /** Domain ID to start */ + private int domain_id; + + /** + * Constructor for CommandDomainStart. + * @param d Defaults object to use. + * @param domain_id Domain to start. + */ + public CommandDomainStart(Defaults d, int domain_id) { + this.d = d; + this.domain_id = domain_id; + } - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - String output = null; + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + String output = null; - try { - Process start_p; - String start_cmdarray[] = new String[2]; - int start_rc; - start_cmdarray[0] = d.XIToolsDir + "xi_start"; - start_cmdarray[1] = "" + domain_id; + try { + Process start_p; + String start_cmdarray[] = new String[2]; + int start_rc; + start_cmdarray[0] = d.xiToolsDir + "xi_start"; + start_cmdarray[1] = "" + domain_id; - if (Settings.TEST) { - output = reportCommand(start_cmdarray); - } else { - start_p = r.exec(start_cmdarray); - start_rc = start_p.waitFor(); - if (start_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray); + if (Settings.TEST) { + output = reportCommand(start_cmdarray); + } else { + start_p = r.exec(start_cmdarray); + start_rc = start_p.waitFor(); + if (start_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not start domain", + start_cmdarray); + } + output = "Started domain " + domain_id; + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not start new domain (" + e + ")", + e); } - output = "Started domain " + domain_id; - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not start new domain (" + e + ")", e); - } - return output; - } + return output; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandDomainStop.java b/tools/control/src/org/xenoserver/control/CommandDomainStop.java index b66fae6ee1..27e111f5dd 100644 --- a/tools/control/src/org/xenoserver/control/CommandDomainStop.java +++ b/tools/control/src/org/xenoserver/control/CommandDomainStop.java @@ -4,47 +4,56 @@ package org.xenoserver.control; * Stops a domain. */ public class CommandDomainStop extends Command { - private Defaults d; - private int domain_id; - - /** - * Constructor for CommandDomainStop. - * @param d The defaults object to use. - * @param domain_id The domain to stop. - */ - public CommandDomainStop(Defaults d, int domain_id) { - this.d = d; - this.domain_id = domain_id; - } + /** Defaults instance in use */ + private Defaults d; + /** Domain ID to stop */ + private int domain_id; - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - String output = null; + /** + * Constructor for CommandDomainStop. + * @param d The defaults object to use. + * @param domain_id The domain to stop. + */ + public CommandDomainStop(Defaults d, int domain_id) { + this.d = d; + this.domain_id = domain_id; + } + + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + String output = null; - try { - Process stop_p; - String stop_cmdarray[] = new String[2]; - int stop_rc; - stop_cmdarray[0] = d.XIToolsDir + "xi_stop"; - stop_cmdarray[1] = "" + domain_id; + try { + Process stop_p; + String stop_cmdarray[] = new String[2]; + int stop_rc; + stop_cmdarray[0] = d.xiToolsDir + "xi_stop"; + stop_cmdarray[1] = "" + domain_id; - if (Settings.TEST) { - output = reportCommand(stop_cmdarray); - } else { - stop_p = r.exec(stop_cmdarray); - stop_rc = stop_p.waitFor(); + if (Settings.TEST) { + output = reportCommand(stop_cmdarray); + } else { + stop_p = r.exec(stop_cmdarray); + stop_rc = stop_p.waitFor(); - if (stop_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray); + if (stop_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not stop domain", + stop_cmdarray); + } + output = "Stopped domain " + domain_id; + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not stop new domain (" + e + ")", + e); } - output = "Stopped domain " + domain_id; - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not stop new domain (" + e + ")", e); - } - return output; - } + return output; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandFailedException.java b/tools/control/src/org/xenoserver/control/CommandFailedException.java index f8571c33e2..e097114da7 100644 --- a/tools/control/src/org/xenoserver/control/CommandFailedException.java +++ b/tools/control/src/org/xenoserver/control/CommandFailedException.java @@ -4,29 +4,38 @@ package org.xenoserver.control; * Thrown to indicate that a command failed to execute. */ public class CommandFailedException extends Exception { - public CommandFailedException() { - super(); - } - - public CommandFailedException(String message) { - super(message); - } + /** + * Construct an exception with a message. + * @param message Message to use. + */ + public CommandFailedException(String message) { + super(message); + } - public CommandFailedException(String message, Throwable cause) { - super(message, cause); - } + /** + * Construct an exception with a message and cause. + * @param message Message to use. + * @param cause Throwable cause. + */ + public CommandFailedException(String message, Throwable cause) { + super(message, cause); + } - public CommandFailedException(Throwable cause) { - super(cause); - } - - public static CommandFailedException XICommandFailed(String message, String cmd_array[]) { - StringBuffer sb = new StringBuffer(); - int i; - sb.append (message + " using: "); - for (i = 0; i < cmd_array.length; i ++) { - sb.append (cmd_array[i] + " "); + /** + * Construct an exception for an XI command failure. + * @param message Message to use + * @param cmd_array Command array used to invoke xi command + * @return Suitable exception. + */ + public static CommandFailedException xiCommandFailed( + String message, + String cmd_array[]) { + StringBuffer sb = new StringBuffer(); + int i; + sb.append(message + " using: "); + for (i = 0; i < cmd_array.length; i++) { + sb.append(cmd_array[i] + " "); + } + return new CommandFailedException(sb.toString()); } - return new CommandFailedException( sb.toString() ); - } } diff --git a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java index 9dc8c19b85..72d1bb631b 100644 --- a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java @@ -1,22 +1,30 @@ package org.xenoserver.control; +/** + * Add a disk partition to the VirtualDiskManager as a XenoPartition. + */ public class CommandPartitionAdd extends Command { - private Partition partition; - private long chunksize; - - /** - * Constructor for CommandPartitionAdd. - * @param partition Partition to add. - * @param chunksize Chunk size to split partition into (in sectors). - */ - public CommandPartitionAdd(Partition partition, long chunksize) { - this.partition = partition; - this.chunksize = chunksize; - } + /** Partition to add as a XenoPartition. */ + private Partition partition; + /** Chunk size to split partition into (in sectors). */ + private long chunksize; - public String execute() throws CommandFailedException { - VirtualDiskManager.IT.addPartition(partition,chunksize); - PartitionManager.IT.addXenoPartition(partition); - return "Added partition " + partition.getName(); - } + /** + * Constructor for CommandPartitionAdd. + * @param partition Partition to add. + * @param chunksize Chunk size to split partition into (in sectors). + */ + public CommandPartitionAdd(Partition partition, long chunksize) { + this.partition = partition; + this.chunksize = chunksize; + } + + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + VirtualDiskManager.IT.addPartition(partition, chunksize); + PartitionManager.IT.addXenoPartition(partition); + return "Added partition " + partition.getName(); + } } diff --git a/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java index 03323d75f6..ab56ad65e1 100644 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java @@ -1,71 +1,84 @@ package org.xenoserver.control; +/** + * Grant physical access to a partition for a given domain. + */ public class CommandPhysicalGrant extends Command { - private Defaults d; - private int domain_id; - private Extent extent; - private Mode mode; - private int partition_no; + /** Defaults instance to use */ + private Defaults d; + /** Domain ID to grant access for */ + private int domain_id; + /** Partition to grant access to */ + private Partition partition; + /** Access mode to grant */ + private Mode mode; - /** - * Constructor for CommandPhysicalGrant. - * @param d Defaults object to use. - * @param domain_id Domain to grant access for. - * @param extent Extent to grant access to. - * @param mode Access mode to grant. - * @param partition_no Partition number to use (or zero for none). - */ - public CommandPhysicalGrant( - Defaults d, - int domain_id, - Extent extent, - Mode mode, - int partition_no) { - this.d = d; - this.domain_id = domain_id; - this.extent = extent; - this.mode = mode; - this.partition_no = partition_no; - } + /** + * Constructor for CommandPhysicalGrant. + * @param d Defaults object to use. + * @param domain_id Domain to grant access for. + * @param partition Partition to grant access to. + * @param mode Access mode to grant. + */ + public CommandPhysicalGrant( + Defaults d, + int domain_id, + Partition partition, + Mode mode) { + this.d = d; + this.domain_id = domain_id; + this.partition = partition; + this.mode = mode; + } - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - String output = null; + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + String output = null; - try { - Process start_p; - String start_cmdarray[] = new String[7]; - int start_rc; - start_cmdarray[0] = d.XIToolsDir + "xi_phys_grant"; - if ( mode == Mode.READ_WRITE ) - start_cmdarray[1] = "rw"; - else if ( mode == Mode.READ_ONLY ) - start_cmdarray[1] = "ro"; - else - throw new CommandFailedException( "Unknown access mode '" + mode + "'" ); - start_cmdarray[2] = Integer.toString( domain_id ); - start_cmdarray[3] = Integer.toString( extent.getDisk() ); - start_cmdarray[4] = Long.toString( extent.getOffset() ); - start_cmdarray[5] = Long.toString( extent.getSize() ); - start_cmdarray[6] = Integer.toString( partition_no ); + try { + Process start_p; + String start_cmdarray[] = new String[7]; + int start_rc; + start_cmdarray[0] = d.xiToolsDir + "xi_phys_grant"; + if (mode == Mode.READ_WRITE) { + start_cmdarray[1] = "rw"; + } else if (mode == Mode.READ_ONLY) { + start_cmdarray[1] = "ro"; + } else { + throw new CommandFailedException( + "Unknown access mode '" + mode + "'"); + } + start_cmdarray[2] = Integer.toString(domain_id); + Extent e = partition.toExtent(); + start_cmdarray[3] = Integer.toString(e.getDisk()); + start_cmdarray[4] = Long.toString(e.getOffset()); + start_cmdarray[5] = Long.toString(e.getSize()); + start_cmdarray[6] = Integer.toString(partition.getPartitionIndex()); - if (Settings.TEST) { - output = reportCommand(start_cmdarray); - } else { - start_p = r.exec(start_cmdarray); - start_rc = start_p.waitFor(); - if (start_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not grant physical access", start_cmdarray); + if (Settings.TEST) { + output = reportCommand(start_cmdarray); + } else { + start_p = r.exec(start_cmdarray); + start_rc = start_p.waitFor(); + if (start_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not grant physical access", + start_cmdarray); + } + output = "Granted physical access to domain " + domain_id; + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not grant physical access (" + e + ")", + e); } - output = "Granted physical access to domain " + domain_id; - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not grant physical access (" + e + ")", e); - } - return output; - } + return output; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java index 234a0880d6..14c9288db4 100644 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java @@ -12,13 +12,17 @@ import java.util.StringTokenizer; * to modes. */ public class CommandPhysicalList extends Command { + /** Domain to list details for */ private int domain_id; + /** Defaults instance to use. */ private Defaults d; + /** Map of extents to access modes */ private Map map = new HashMap(); /** * Constructor for CommandDomainList. * @param d Defaults object to use. + * @param domain_id Domain ID to query for */ public CommandPhysicalList(Defaults d, int domain_id) { this.d = d; @@ -28,6 +32,7 @@ public class CommandPhysicalList extends Command { /** * Retrieves the list of extents. * @return null, call extents() to get the list. + * @throws CommandFailedException if the list could not be retrieved. */ public String execute() throws CommandFailedException { Runtime r = Runtime.getRuntime(); @@ -39,7 +44,7 @@ public class CommandPhysicalList extends Command { Process start_p; String start_cmdarray[] = new String[2]; int start_rc; - start_cmdarray[0] = d.XIToolsDir + "xi_phys_probe"; + start_cmdarray[0] = d.xiToolsDir + "xi_phys_probe"; start_cmdarray[1] = Integer.toString(domain_id); if (Settings.TEST) { @@ -48,7 +53,7 @@ public class CommandPhysicalList extends Command { start_p = r.exec(start_cmdarray); start_rc = start_p.waitFor(); if (start_rc != 0) { - throw CommandFailedException.XICommandFailed( + throw CommandFailedException.xiCommandFailed( "Could not get extent list", start_cmdarray); } @@ -62,7 +67,7 @@ public class CommandPhysicalList extends Command { int disk = -1; long offset = -1; long size = -1; - + StringTokenizer st = new StringTokenizer(outline); if (st.hasMoreTokens()) { disk = Short.parseShort(st.nextToken(), 16); @@ -75,14 +80,15 @@ public class CommandPhysicalList extends Command { } if (st.hasMoreTokens()) { String mode = st.nextToken(); - Extent extent = new Extent(disk,offset,size); - if (mode.equals("rw")) + Extent extent = new Extent(disk, offset, size); + if (mode.equals("rw")) { map.put(extent, Mode.READ_WRITE); - else if (mode.equals("r")) + } else if (mode.equals("r")) { map.put(extent, Mode.READ_ONLY); - else + } else { throw new CommandFailedException( "Could not parse access mode " + mode); + } } outline = in.readLine(); @@ -100,6 +106,9 @@ public class CommandPhysicalList extends Command { return output; } + /** + * @return Map of extents to access modes. + */ public Map extents() { return map; } diff --git a/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java index 290af9ffe3..22473c5beb 100644 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java @@ -1,56 +1,67 @@ package org.xenoserver.control; +/** + * Revoke physical access to a partition from a domain. + */ public class CommandPhysicalRevoke extends Command { - private Defaults d; - private int domain_id; - private Extent extent; + /** Defaults instance to use. */ + private Defaults d; + /** Domain to revoke access from */ + private int domain_id; + /** Partition to revoke access to */ + private Partition partition; - /** - * Constructor for CommandPhysicalRevoke. - * @param d Defaults object to use. - * @param domain_id Domain to revoke access from. - * @param extent Extent to revoke access from. - */ - public CommandPhysicalRevoke( - Defaults d, - int domain_id, - Extent extent) { - this.d = d; - this.domain_id = domain_id; - this.extent = extent; - } + /** + * Constructor for CommandPhysicalRevoke. + * @param d Defaults object to use. + * @param domain_id Domain to revoke access from. + * @param partition Partition to revoke access to. + */ + public CommandPhysicalRevoke(Defaults d, int domain_id, Partition partition) { + this.d = d; + this.domain_id = domain_id; + this.partition = partition; + } - public String execute() throws CommandFailedException { - Runtime r = Runtime.getRuntime(); - String output = null; + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + Runtime r = Runtime.getRuntime(); + String output = null; - try { - Process start_p; - String start_cmdarray[] = new String[5]; - int start_rc; - start_cmdarray[0] = d.XIToolsDir + "xi_phys_revoke"; - start_cmdarray[1] = Integer.toString( domain_id ); - start_cmdarray[2] = Integer.toString( extent.getDisk() ); - start_cmdarray[3] = Long.toString( extent.getOffset() ); - start_cmdarray[4] = Long.toString( extent.getSize() ); + try { + Process start_p; + String start_cmdarray[] = new String[5]; + int start_rc; + start_cmdarray[0] = d.xiToolsDir + "xi_phys_revoke"; + start_cmdarray[1] = Integer.toString(domain_id); + Extent e = partition.toExtent(); + start_cmdarray[2] = Integer.toString(e.getDisk()); + start_cmdarray[3] = Long.toString(e.getOffset()); + start_cmdarray[4] = Long.toString(e.getSize()); - if (Settings.TEST) { - output = reportCommand(start_cmdarray); - } else { - start_p = r.exec(start_cmdarray); - start_rc = start_p.waitFor(); - if (start_rc != 0) { - throw CommandFailedException.XICommandFailed("Could not revoke physical access", start_cmdarray); + if (Settings.TEST) { + output = reportCommand(start_cmdarray); + } else { + start_p = r.exec(start_cmdarray); + start_rc = start_p.waitFor(); + if (start_rc != 0) { + throw CommandFailedException.xiCommandFailed( + "Could not revoke physical access", + start_cmdarray); + } + output = "Revoked physical access from domain " + domain_id; + } + } catch (CommandFailedException e) { + throw e; + } catch (Exception e) { + throw new CommandFailedException( + "Could not revoke physical access (" + e + ")", + e); } - output = "Revoked physical access from domain " + domain_id; - } - } catch (CommandFailedException e) { - throw e; - } catch (Exception e) { - throw new CommandFailedException("Could not revoke physical access (" + e + ")", e); - } - return output; - } + return output; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandVdCreate.java b/tools/control/src/org/xenoserver/control/CommandVdCreate.java index bdc3c774eb..4187b49890 100644 --- a/tools/control/src/org/xenoserver/control/CommandVdCreate.java +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java @@ -2,27 +2,38 @@ package org.xenoserver.control; import java.util.Date; +/** + * Create a virtual disk. + */ public class CommandVdCreate extends Command { - private String name; - private long size; - private Date expiry; + /** Name of new disk. */ + private String name; + /** Size of new disk in sectors. */ + private long size; + /** Expiry date of new disk. */ + private Date expiry; - /** - * Constructor for CommandVdCreate. - * @param name Name of new virtual disk. - * @param size Size in sectors. - * @param expiry Expiry time, or null for never. - */ - public CommandVdCreate(String name, long size, Date expiry) { - this.name = name; - this.size = size; - this.expiry = expiry; - } + /** + * Constructor for CommandVdCreate. + * @param name Name of new virtual disk. + * @param size Size in sectors. + * @param expiry Expiry time, or null for never. + */ + public CommandVdCreate(String name, long size, Date expiry) { + this.name = name; + this.size = size; + this.expiry = expiry; + } - public String execute() throws CommandFailedException { - VirtualDisk vd = VirtualDiskManager.IT.createVirtualDisk(name,size,expiry); - if ( vd == null ) - throw new CommandFailedException( "Not enough free space to create disk" ); - return "Virtual Disk created with key: " + vd.getKey(); - } + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + VirtualDisk vd = + VirtualDiskManager.IT.createVirtualDisk(name, size, expiry); + if (vd == null) { + throw new CommandFailedException("Not enough free space to create disk"); + } + return "Virtual Disk created with key: " + vd.getKey(); + } } diff --git a/tools/control/src/org/xenoserver/control/CommandVdDelete.java b/tools/control/src/org/xenoserver/control/CommandVdDelete.java index f09561dfd2..5243cae566 100644 --- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java +++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java @@ -1,18 +1,25 @@ package org.xenoserver.control; +/** + * Delete virtual disk. + */ public class CommandVdDelete extends Command { - private String key; - - /** - * Constructor for CommandVdDelete. - * @param key The key of the disk to delete. - */ - public CommandVdDelete(String key) { - this.key = key; - } + /** Key of disk to delete. */ + private String key; - public String execute() throws CommandFailedException { - VirtualDiskManager.IT.deleteVirtualDisk(key); - return "Deleted virtual disk " + key; - } + /** + * Constructor for CommandVdDelete. + * @param key The key of the disk to delete. + */ + public CommandVdDelete(String key) { + this.key = key; + } + + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + VirtualDiskManager.IT.deleteVirtualDisk(key); + return "Deleted virtual disk " + key; + } } diff --git a/tools/control/src/org/xenoserver/control/CommandVdRefresh.java b/tools/control/src/org/xenoserver/control/CommandVdRefresh.java index 291e709446..2331209ea5 100644 --- a/tools/control/src/org/xenoserver/control/CommandVdRefresh.java +++ b/tools/control/src/org/xenoserver/control/CommandVdRefresh.java @@ -2,25 +2,34 @@ package org.xenoserver.control; import java.util.Date; +/** + * Refresh the expiry time on a virtual disk. + */ public class CommandVdRefresh extends Command { - private String key; - private Date expiry; - - /** - * Constructor for CommandVdRefresh. - * @param key Key to refresh. - * @param expiry New expiry (null for no expiry). - */ - public CommandVdRefresh(String key, Date expiry) { - this.key = key; - this.expiry = expiry; - } + /** Key of disk to refresh */ + private String key; + /** New expiry */ + private Date expiry; - public String execute() throws CommandFailedException { - VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); - if ( vd == null ) - throw new CommandFailedException( "No such virtual disk " + key ); - vd.refreshExpiry(expiry); - return "Refreshed virtual disk " + key; - } + /** + * Constructor for CommandVdRefresh. + * @param key Key to refresh. + * @param expiry New expiry (null for no expiry). + */ + public CommandVdRefresh(String key, Date expiry) { + this.key = key; + this.expiry = expiry; + } + + /** + * @see org.xenoserver.control.Command#execute() + */ + public String execute() throws CommandFailedException { + VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); + if (vd == null) { + throw new CommandFailedException("No such virtual disk " + key); + } + vd.refreshExpiry(expiry); + return "Refreshed virtual disk " + key; + } } diff --git a/tools/control/src/org/xenoserver/control/Defaults.java b/tools/control/src/org/xenoserver/control/Defaults.java index 61fd47f1ef..1fba5baeac 100644 --- a/tools/control/src/org/xenoserver/control/Defaults.java +++ b/tools/control/src/org/xenoserver/control/Defaults.java @@ -16,190 +16,217 @@ import org.xml.sax.helpers.DefaultHandler; * management utilities. On construction it parses the defaults file * located through the Settings class. */ -public class Defaults -{ - public String domainName; +public class Defaults { + /** Default domain name. */ + public String domainName; + /** Default domain memory size in KB. */ + public int domainSizeKB; + /** Default domain kernel image. */ + public String domainImage; + /** Default domain initrd. */ + public String domainInitRD; + /** Default number of virtual interfaces. */ + public int domainVIFs; + /** Default root device. */ + public String rootDevice; + /** Default IP address pattern. */ + public String nwIP; + /** Default gateway pattern. */ + public String nwGateway; + /** Default netmask patterh. */ + public String nwMask; + /** Default hostname pattern. */ + public String nwHost; + /** Default NFS server pattern. */ + public String nwNFSServer; + /** Default NFS root pattern. */ + public String nwNFSRoot; + /** Maximum domain number. */ + public int maxDomainNumber = Integer.MAX_VALUE; + /** Default boot arguments. */ + public String args = ""; + /** Directory to find XI tools. */ + public String xiToolsDir = ""; - public int domainSizeKB; - public String domainImage; - public String domainInitRD; - public int domainVIFs; - - public String rootDevice; - - public String NWIP; - public String NWGW; - public String NWMask; - public String NWHost; - - public String NWNFSServer; - public String NWNFSRoot; - - public int MaxDomainNumber = Integer.MAX_VALUE; - public String args = ""; - - public String XIToolsDir = ""; - - /***********************************************************************/ - - public Defaults () - { - File f = Settings.getDefaultsFile (); - - if (f == null) - { - return; + + /** + * Create defaults instance and parse the defaults file. + */ + public Defaults() { + File f = Settings.getDefaultsFile(); + + if (f == null) { + return; + } + + try { + XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl(); + Handler handler = new Handler(); + xr.setContentHandler(handler); + xr.setErrorHandler(handler); + xr.parse(new InputSource(new FileReader(f))); + } catch (Exception e) { + System.err.println( + "Could not read defaults file " + f + "\nException: " + e); + e.printStackTrace(); + return; + } } - try - { - XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl(); - Handler handler = new Handler (); - xr.setContentHandler (handler); - xr.setErrorHandler (handler); - xr.parse (new InputSource(new FileReader (f))); - } - catch (Exception e) - { - System.err.println ("Could not read defaults file " + f + - "\nException: " + e); - e.printStackTrace(); - return; - } - } - - public void describe () { - System.out.println ("Domain defaults:"); - System.out.println (" name " + domainName); - System.out.println (" size " + domainSizeKB); - System.out.println (" vifs " + domainVIFs); - System.out.println (" domainImage " + domainImage); - System.out.println (" domainInitRD " + domainInitRD); - System.out.println (" rootDevice " + rootDevice); - System.out.println (" NWIP " + NWIP); - System.out.println (" NWGW " + NWGW); - System.out.println (" NWMask " + NWMask); - System.out.println (" MaxDomainNumber " + MaxDomainNumber); - System.out.println (" NWNFSServer " + NWNFSServer); - System.out.println (" NWNFSRoot " + NWNFSRoot); - System.out.println (" XIToolsDir " + XIToolsDir); - System.out.println (" args " + args); - } - - /***********************************************************************/ - - class Handler extends DefaultHandler - { - boolean inDomctlDefaults; - String lastName; - - public void startDocument () - { + /** + * Describe the defaults to System.out + */ + public void describe() { + System.out.println("Domain defaults:"); + System.out.println(" name " + domainName); + System.out.println(" size " + domainSizeKB); + System.out.println(" vifs " + domainVIFs); + System.out.println(" domainImage " + domainImage); + System.out.println(" domainInitRD " + domainInitRD); + System.out.println(" rootDevice " + rootDevice); + System.out.println(" NWIP " + nwIP); + System.out.println(" NWGW " + nwGateway); + System.out.println(" NWMask " + nwMask); + System.out.println(" MaxDomainNumber " + maxDomainNumber); + System.out.println(" NWNFSServer " + nwNFSServer); + System.out.println(" NWNFSRoot " + nwNFSRoot); + System.out.println(" XIToolsDir " + xiToolsDir); + System.out.println(" args " + args); } - public void endDocument () - { + /** + * SAX event handler. + */ + private class Handler extends DefaultHandler { + /** Are we inside the defaults node. */ + boolean inDomctlDefaults; + /** Last element name read. */ + String lastName; + + /** + * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) + */ + public void startElement( + String uri, + String name, + String qname, + Attributes atts) { + if (qname.equals("domctl_defaults")) { + inDomctlDefaults = true; + } else { + lastName = qname; + } + } + + /** + * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) + */ + public void endElement(String uri, String name, String qname) { + lastName = ""; + if (qname.equals("domctl_defaults")) { + inDomctlDefaults = false; + } + } + + /** + * @see org.xml.sax.ContentHandler#characters(char[], int, int) + */ + public void characters(char ch[], int start, int length) { + String s = new String(ch, start, length); + if (lastName != null) { + if (lastName.equals("domain_size_kb")) { + domainSizeKB = Integer.parseInt(s); + } else if (lastName.equals("domain_image")) { + domainImage = s; + } else if (lastName.equals("domain_name")) { + domainName = s; + } else if (lastName.equals("domain_init_rd")) { + domainInitRD = s; + } else if (lastName.equals("domain_vifs")) { + domainVIFs = Integer.parseInt(s); + } else if (lastName.equals("root_device")) { + rootDevice = s; + } else if (lastName.equals("nw_ip")) { + nwIP = + expandDefault( + s, + runCommand(xiToolsDir + Settings.XI_HELPER + " ip") + .trim()); + } else if (lastName.equals("nw_gw")) { + nwGateway = + expandDefault( + s, + runCommand( + xiToolsDir + Settings.XI_HELPER + " route") + .trim()); + } else if (lastName.equals("nw_mask")) { + nwMask = + expandDefault( + s, + runCommand( + xiToolsDir + Settings.XI_HELPER + " mask") + .trim()); + } else if (lastName.equals("nw_host")) { + nwHost = s; + } else if (lastName.equals("nw_nfs_server")) { + nwNFSServer = s; + } else if (lastName.equals("nw_nfs_root")) { + nwNFSRoot = s; + } else if (lastName.equals("args")) { + args = s; + } else if (lastName.equals("max_domain_number")) { + maxDomainNumber = Integer.parseInt(s); + } else if (lastName.equals("xi_tools_dir")) { + xiToolsDir = s; + } + } + } } - public void startElement (String uri, String name, - String qname, Attributes atts) - { - if (qname.equals ("domctl_defaults")) { - inDomctlDefaults = true; - } else { - lastName = qname; - } + /** + * Expand a defaults pattern. + * @param supplied Supplied pattern. + * @param self Own value for variable. + * @return Appropriate value. + */ + private String expandDefault(String supplied, String self) { + if (supplied.startsWith("=")) { + if (supplied.length() > 1) { + return self + supplied.substring(1, supplied.length()); + } else { + return self; + } + } else { + return supplied; + } } - public void endElement (String uri, String name, String qname) - { - lastName = ""; - if (qname.equals ("domctl_defaults")) { - inDomctlDefaults = false; - } - } - - public void characters (char ch[], int start, int length) - { - String s = new String (ch, start, length); - if (lastName != null) - { - if (lastName.equals ("domain_size_kb")) { - domainSizeKB = Integer.parseInt (s); - } else if (lastName.equals ("domain_image")) { - domainImage = s; - } else if (lastName.equals ("domain_name")) { - domainName = s; - } else if (lastName.equals ("domain_init_rd")) { - domainInitRD = s; - } else if (lastName.equals ("domain_vifs")) { - domainVIFs = Integer.parseInt (s); - } else if (lastName.equals ("root_device")) { - rootDevice = s; - } else if (lastName.equals ("nw_ip")) { - NWIP = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" ip").trim()); - } else if (lastName.equals ("nw_gw")) { - NWGW = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" route").trim()); - } else if (lastName.equals ("nw_mask")) { - NWMask = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" mask").trim()); - } else if (lastName.equals ("nw_host")) { - NWHost = s; - } else if (lastName.equals ("nw_nfs_server")) { - NWNFSServer = s; - } else if (lastName.equals ("nw_nfs_root")) { - NWNFSRoot = s; - } else if (lastName.equals ("args")) { - args = s; - } else if (lastName.equals ("max_domain_number")) { - MaxDomainNumber = Integer.parseInt(s); - } else if (lastName.equals ("xi_tools_dir")) { - XIToolsDir = s; - } - } - } - } - - public String expandDefault (String supplied, String self) - { - if (supplied.startsWith ("=")) { - if (supplied.length() > 1) { - return self + supplied.substring (1, supplied.length()); - } else { - return self; - } - } else { - return supplied; + /** + * Run a command for the Defaults object. + * @param command Command string to run. + * @return Command's output. + */ + private String runCommand(String command) { + Runtime runtime = Runtime.getRuntime(); + String outline; + StringBuffer output = new StringBuffer(); + + try { + Process process = runtime.exec(command); + BufferedReader in = + new BufferedReader( + new InputStreamReader(process.getInputStream())); + + outline = in.readLine(); + while (outline != null) { + output.append("\n" + outline); + outline = in.readLine(); + } + } catch (IOException e) { + return e.toString(); + } + + return output.toString(); } - } - - - public String - runCommand (String command) - { - Runtime runtime = Runtime.getRuntime(); - String outline; - StringBuffer output = new StringBuffer(); - - try - { - Process process = runtime.exec(command); - BufferedReader in = new BufferedReader( - new InputStreamReader(process.getInputStream())); - - outline = in.readLine(); - while (outline != null) - { - output.append("\n" + outline); - outline = in.readLine(); - } - } - catch (IOException e) - { - return e.toString(); - } - - return output.toString(); - } - } diff --git a/tools/control/src/org/xenoserver/control/Domain.java b/tools/control/src/org/xenoserver/control/Domain.java index 27f9ec9e39..c84cf8cffb 100644 --- a/tools/control/src/org/xenoserver/control/Domain.java +++ b/tools/control/src/org/xenoserver/control/Domain.java @@ -2,30 +2,39 @@ package org.xenoserver.control; /** * A Domain object holds the details of one domain suitable for returning - * from methods enquiring about domain status. + * from methods enquiring about domain status. As it's only used to pass + * return values back from DomainList, the fields are left public for + * convenience. */ -public class -Domain -{ - public int id; /* domain id */ - public int processor; /* processor */ - public boolean cpu; /* has cpu */ - public int nstate; /* state */ - public String state; /* running, interruptable, uninterruptable, - wait, suspended, dying */ - public int mcu; /* mcu advances */ - public int pages; /* total pages */ - public String name; /* name */ +public class Domain { + /** Domain ID. */ + public int id; + /** Processor index. */ + public int processor; + /** Has the CPU at the moment? */ + public boolean cpu; + /** State index. */ + public int nstate; + /** State string. */ + public String state; + /** MCU advances. */ + public int mcu; + /** Total pages. */ + public int pages; + /** Name. */ + public String name; - Domain() - { - id = 0; - processor = 0; - cpu = false; - nstate = 0; - state = ""; - mcu = 0; - pages = 0; - name = "none"; - } + /** + * Domain constructor, with default values. + */ + Domain() { + id = 0; + processor = 0; + cpu = false; + nstate = 0; + state = ""; + mcu = 0; + pages = 0; + name = "none"; + } } diff --git a/tools/control/src/org/xenoserver/control/Partition.java b/tools/control/src/org/xenoserver/control/Partition.java index 510e266813..7cfc918f29 100644 --- a/tools/control/src/org/xenoserver/control/Partition.java +++ b/tools/control/src/org/xenoserver/control/Partition.java @@ -182,4 +182,19 @@ public class Partition { throw new IllegalArgumentException("Don't know how to convert " + name + "into a disk number"); } } + + /** + * @return Partition index on disk for this partition. + */ + public int getPartitionIndex() { + if ( name.startsWith("hd") ) { + // low 6 bits of minor are partition no + return minor & 0x3F; + } else if ( name.startsWith("sd") ) { + // low 4 bits of minor are partition no + return minor & 0x0F; + } else { + throw new IllegalArgumentException("Don't know how to convert " + name + "into a partition number"); + } + } } -- cgit v1.2.3