debuggers.hg
changeset 557:8f3e358c9972
bitkeeper revision 1.286 (3f0982812_NP4IcqTvtRwEbA4TDhUQ)
Code cleanups
Save/load state factored out
Code cleanups
Save/load state factored out
line diff
1.1 --- a/tools/control/src/org/xenoserver/cmdline/CommandParser.java Mon Jul 07 10:09:50 2003 +0000 1.2 +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java Mon Jul 07 14:24:01 2003 +0000 1.3 @@ -4,9 +4,12 @@ import java.util.Iterator; 1.4 import java.util.LinkedList; 1.5 import java.util.List; 1.6 1.7 -import org.xenoserver.control.Command; 1.8 import org.xenoserver.control.CommandFailedException; 1.9 import org.xenoserver.control.Defaults; 1.10 +import org.xenoserver.control.PartitionManager; 1.11 +import org.xenoserver.control.Settings; 1.12 +import org.xenoserver.control.VirtualDiskManager; 1.13 +import org.xenoserver.control.XML; 1.14 1.15 /** 1.16 * Subclasses of Parser know how to parse arguments for a given command 1.17 @@ -84,4 +87,12 @@ public abstract class CommandParser { 1.18 } 1.19 return result; 1.20 } 1.21 + 1.22 + protected void loadState() { 1.23 + XML.load_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_INPUT_FILE ); 1.24 + } 1.25 + 1.26 + protected void saveState() { 1.27 + XML.dump_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_OUTPUT_FILE ); 1.28 + } 1.29 }
2.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java Mon Jul 07 10:09:50 2003 +0000 2.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java Mon Jul 07 14:24:01 2003 +0000 2.3 @@ -1,9 +1,7 @@ 2.4 package org.xenoserver.cmdline; 2.5 2.6 import java.util.LinkedList; 2.7 -import java.util.List; 2.8 2.9 -import org.xenoserver.control.Command; 2.10 import org.xenoserver.control.CommandDomainDestroy; 2.11 import org.xenoserver.control.CommandFailedException; 2.12 import org.xenoserver.control.Defaults;
3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java Mon Jul 07 10:09:50 2003 +0000 3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java Mon Jul 07 14:24:01 2003 +0000 3.3 @@ -1,11 +1,9 @@ 3.4 package org.xenoserver.cmdline; 3.5 3.6 import java.util.LinkedList; 3.7 -import java.util.List; 3.8 3.9 -import org.xenoserver.control.Command; 3.10 +import org.xenoserver.control.CommandDomainList; 3.11 import org.xenoserver.control.CommandFailedException; 3.12 -import org.xenoserver.control.CommandDomainList; 3.13 import org.xenoserver.control.Defaults; 3.14 import org.xenoserver.control.Domain; 3.15
4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java Mon Jul 07 10:09:50 2003 +0000 4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java Mon Jul 07 14:24:01 2003 +0000 4.3 @@ -1,11 +1,9 @@ 4.4 package org.xenoserver.cmdline; 4.5 4.6 import java.util.LinkedList; 4.7 -import java.util.List; 4.8 4.9 -import org.xenoserver.control.Command; 4.10 +import org.xenoserver.control.CommandDomainNew; 4.11 import org.xenoserver.control.CommandFailedException; 4.12 -import org.xenoserver.control.CommandDomainNew; 4.13 import org.xenoserver.control.Defaults; 4.14 4.15 public class ParseDomainNew extends CommandParser {
5.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java Mon Jul 07 10:09:50 2003 +0000 5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java Mon Jul 07 14:24:01 2003 +0000 5.3 @@ -1,11 +1,9 @@ 5.4 package org.xenoserver.cmdline; 5.5 5.6 import java.util.LinkedList; 5.7 -import java.util.List; 5.8 5.9 -import org.xenoserver.control.Command; 5.10 +import org.xenoserver.control.CommandDomainStart; 5.11 import org.xenoserver.control.CommandFailedException; 5.12 -import org.xenoserver.control.CommandDomainStart; 5.13 import org.xenoserver.control.Defaults; 5.14 5.15 public class ParseDomainStart extends CommandParser {
6.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java Mon Jul 07 10:09:50 2003 +0000 6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java Mon Jul 07 14:24:01 2003 +0000 6.3 @@ -1,11 +1,9 @@ 6.4 package org.xenoserver.cmdline; 6.5 6.6 import java.util.LinkedList; 6.7 -import java.util.List; 6.8 6.9 -import org.xenoserver.control.Command; 6.10 +import org.xenoserver.control.CommandDomainStop; 6.11 import org.xenoserver.control.CommandFailedException; 6.12 -import org.xenoserver.control.CommandDomainStop; 6.13 import org.xenoserver.control.Defaults; 6.14 6.15 public class ParseDomainStop extends CommandParser {
7.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseGroup.java Mon Jul 07 10:09:50 2003 +0000 7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseGroup.java Mon Jul 07 14:24:01 2003 +0000 7.3 @@ -1,8 +1,6 @@ 7.4 package org.xenoserver.cmdline; 7.5 7.6 -import java.util.Arrays; 7.7 import java.util.LinkedList; 7.8 -import java.util.List; 7.9 7.10 import org.xenoserver.control.CommandFailedException; 7.11 import org.xenoserver.control.Defaults;
8.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseHelp.java Mon Jul 07 10:09:50 2003 +0000 8.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java Mon Jul 07 14:24:01 2003 +0000 8.3 @@ -1,9 +1,7 @@ 8.4 package org.xenoserver.cmdline; 8.5 8.6 import java.util.LinkedList; 8.7 -import java.util.List; 8.8 8.9 -import org.xenoserver.control.Command; 8.10 import org.xenoserver.control.Defaults; 8.11 8.12 public class ParseHelp extends CommandParser {
9.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Mon Jul 07 10:09:50 2003 +0000 9.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Mon Jul 07 14:24:01 2003 +0000 9.3 @@ -9,8 +9,6 @@ import org.xenoserver.control.Extent; 9.4 import org.xenoserver.control.Mode; 9.5 import org.xenoserver.control.Partition; 9.6 import org.xenoserver.control.PartitionManager; 9.7 -import org.xenoserver.control.Settings; 9.8 -import org.xenoserver.control.XML; 9.9 9.10 public class ParsePhysicalGrant extends CommandParser { 9.11 public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { 9.12 @@ -31,7 +29,7 @@ public class ParsePhysicalGrant extends 9.13 mode = Mode.READ_ONLY; 9.14 9.15 // Initialise the partition manager and look up the partition 9.16 - XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE ); 9.17 + loadState(); 9.18 Partition p = PartitionManager.it.get_partition(partition_name); 9.19 9.20 if ( p == null )
10.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java Mon Jul 07 10:09:50 2003 +0000 10.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java Mon Jul 07 14:24:01 2003 +0000 10.3 @@ -9,11 +9,8 @@ import org.xenoserver.control.CommandPhy 10.4 import org.xenoserver.control.Defaults; 10.5 import org.xenoserver.control.Extent; 10.6 import org.xenoserver.control.Library; 10.7 -import org.xenoserver.control.Mode; 10.8 import org.xenoserver.control.Partition; 10.9 import org.xenoserver.control.PartitionManager; 10.10 -import org.xenoserver.control.Settings; 10.11 -import org.xenoserver.control.XML; 10.12 10.13 public class ParsePhysicalList extends CommandParser { 10.14 10.15 @@ -23,7 +20,7 @@ public class ParsePhysicalList extends C 10.16 throw new ParseFailedException("Expected -n<domain_id>"); 10.17 10.18 // Initialise the partition manager 10.19 - XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE ); 10.20 + loadState(); 10.21 10.22 CommandPhysicalList list = new CommandPhysicalList( d, domain_id ); 10.23 String output = list.execute();
11.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Mon Jul 07 10:09:50 2003 +0000 11.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Mon Jul 07 14:24:01 2003 +0000 11.3 @@ -8,8 +8,6 @@ import org.xenoserver.control.Defaults; 11.4 import org.xenoserver.control.Extent; 11.5 import org.xenoserver.control.Partition; 11.6 import org.xenoserver.control.PartitionManager; 11.7 -import org.xenoserver.control.Settings; 11.8 -import org.xenoserver.control.XML; 11.9 11.10 public class ParsePhysicalRevoke extends CommandParser { 11.11 public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { 11.12 @@ -22,7 +20,7 @@ public class ParsePhysicalRevoke extends 11.13 throw new ParseFailedException("Expected -p<partition_name>"); 11.14 11.15 // Initialise the partition manager and look up the partition 11.16 - XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE ); 11.17 + loadState(); 11.18 Partition p = PartitionManager.it.get_partition(partition_name); 11.19 11.20 if ( p == null )
12.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainList.java Mon Jul 07 10:09:50 2003 +0000 12.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainList.java Mon Jul 07 14:24:01 2003 +0000 12.3 @@ -27,7 +27,6 @@ public class CommandDomainList extends C 12.4 */ 12.5 public String execute() throws CommandFailedException { 12.6 Runtime r = Runtime.getRuntime(); 12.7 - int rc = 0; 12.8 Vector v = new Vector(); 12.9 String outline; 12.10 BufferedReader in;
13.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Mon Jul 07 10:09:50 2003 +0000 13.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Mon Jul 07 14:24:01 2003 +0000 13.3 @@ -31,7 +31,6 @@ public class CommandPhysicalList extends 13.4 */ 13.5 public String execute() throws CommandFailedException { 13.6 Runtime r = Runtime.getRuntime(); 13.7 - int rc = 0; 13.8 String outline; 13.9 BufferedReader in; 13.10 String output = null;
14.1 --- a/tools/control/src/org/xenoserver/control/InetAddressPattern.java Mon Jul 07 10:09:50 2003 +0000 14.2 +++ b/tools/control/src/org/xenoserver/control/InetAddressPattern.java Mon Jul 07 14:24:01 2003 +0000 14.3 @@ -1,6 +1,7 @@ 14.4 package org.xenoserver.control; 14.5 14.6 -import java.net.*; 14.7 +import java.net.InetAddress; 14.8 +import java.net.UnknownHostException; 14.9 14.10 public class InetAddressPattern 14.11 { 14.12 @@ -11,7 +12,6 @@ public class InetAddressPattern 14.13 { 14.14 InetAddressPattern result = new InetAddressPattern (); 14.15 char[] ca = t.toCharArray (); 14.16 - int idx = 0; 14.17 int len = ca.length; 14.18 14.19 try {
15.1 --- a/tools/control/src/org/xenoserver/control/Library.java Mon Jul 07 10:09:50 2003 +0000 15.2 +++ b/tools/control/src/org/xenoserver/control/Library.java Mon Jul 07 14:24:01 2003 +0000 15.3 @@ -126,4 +126,41 @@ Library 15.4 return null; 15.5 } 15.6 } 15.7 + 15.8 + /** 15.9 + * Formats a number of bytes in whichever way makes most sense based 15.10 + * on magnitude and width. 15.11 + * 15.12 + * @param size Number of bytes. 15.13 + * @param width Width of field - at least 5, plz. 15.14 + * @param prefix Set to 1 for left justify 15.15 + * @return The formatted string. 15.16 + */ 15.17 + public static String format_size(long size,int width,int prefix) { 15.18 + char[] suffixes = { ' ', 'k', 'M', 'G' }; 15.19 + int suffix = 0; 15.20 + long before = size; 15.21 + float after = 0; 15.22 + 15.23 + while ( before > 10000 ) { 15.24 + after = ((float)(before % 1024)) / 1024; 15.25 + before /= 1024; 15.26 + suffix++; 15.27 + } 15.28 + 15.29 + StringBuffer num = new StringBuffer(width); 15.30 + num.append( Long.toString( before ) ); 15.31 + if ( after != 0 ) { 15.32 + int space = width - num.length() - 2; 15.33 + if ( space > 0 ) { 15.34 + num.append( '.' ); 15.35 + if ( space > 3 ) 15.36 + space = 3; 15.37 + num.append( Integer.toString( (int) (after * Math.pow(10,space)))); 15.38 + } 15.39 + } 15.40 + num.append( suffixes[suffix] ); 15.41 + 15.42 + return format(num.toString(),width,prefix); 15.43 + } 15.44 }
16.1 --- a/tools/control/src/org/xenoserver/control/Partition.java Mon Jul 07 10:09:50 2003 +0000 16.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java Mon Jul 07 14:24:01 2003 +0000 16.3 @@ -5,7 +5,7 @@ 16.4 16.5 package org.xenoserver.control; 16.6 16.7 -import java.io.*; 16.8 +import java.io.PrintWriter; 16.9 16.10 public class 16.11 Partition
17.1 --- a/tools/control/src/org/xenoserver/control/PartitionManager.java Mon Jul 07 10:09:50 2003 +0000 17.2 +++ b/tools/control/src/org/xenoserver/control/PartitionManager.java Mon Jul 07 14:24:01 2003 +0000 17.3 @@ -5,10 +5,13 @@ 17.4 17.5 package org.xenoserver.control; 17.6 17.7 -import java.io.*; 17.8 +import java.io.BufferedReader; 17.9 +import java.io.FileReader; 17.10 +import java.io.IOException; 17.11 +import java.io.PrintWriter; 17.12 +import java.util.Enumeration; 17.13 import java.util.Iterator; 17.14 import java.util.Vector; 17.15 -import java.util.Enumeration; 17.16 17.17 /** 17.18 * PartitionManager manages the partitions on the machine. It is a Singleton 17.19 @@ -136,8 +139,6 @@ PartitionManager 17.20 void 17.21 dump_xml (PrintWriter out) 17.22 { 17.23 - int loop; 17.24 - 17.25 out.println("<partitions>"); 17.26 for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 17.27 {
18.1 --- a/tools/control/src/org/xenoserver/control/Settings.java Mon Jul 07 10:09:50 2003 +0000 18.2 +++ b/tools/control/src/org/xenoserver/control/Settings.java Mon Jul 07 14:24:01 2003 +0000 18.3 @@ -19,6 +19,7 @@ public final class Settings 18.4 public static final String PARTITIONS_FILE = System.getProperty("PARTITIONS_FILE", "/proc/partitions"); 18.5 public static final String STATE_INPUT_FILE = System.getProperty("STATE_INPUT_FILE", "/var/lib/xen/vdstate.xml"); 18.6 public static final String STATE_OUTPUT_FILE = System.getProperty("STATE_OUTPUT_FILE", "/var/lib/xen/vdstate.xml"); 18.7 + public static final int SECTOR_SIZE = Integer.parseInt( System.getProperty("SECTOR_SIZE", "512") ); 18.8 18.9 public static File getDefaultsFile() { 18.10 StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":");