mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
bitkeeper revision 1.286 (3f0982812_NP4IcqTvtRwEbA4TDhUQ)
Code cleanups Save/load state factored out
This commit is contained in:
1 parent
e4c9dea98d
commit
e08b759edc
18 files changed
+65
-38
No files matched your search
@@ -4,9 +4,12 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
import org.xenoserver.control.PartitionManager;
|
||||
import org.xenoserver.control.Settings;
|
||||
import org.xenoserver.control.VirtualDiskManager;
|
||||
import org.xenoserver.control.XML;
|
||||
|
||||
/**
|
||||
* Subclasses of Parser know how to parse arguments for a given command
|
||||
@@ -84,4 +87,12 @@ public abstract class CommandParser {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void loadState() {
|
||||
XML.load_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_INPUT_FILE );
|
||||
}
|
||||
|
||||
protected void saveState() {
|
||||
XML.dump_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_OUTPUT_FILE );
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandDomainDestroy;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.CommandDomainList;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
import org.xenoserver.control.Domain;
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.CommandDomainNew;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
public class ParseDomainNew extends CommandParser {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.CommandDomainStart;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
public class ParseDomainStart extends CommandParser {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.CommandDomainStop;
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
public class ParseDomainStop extends CommandParser {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.CommandFailedException;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.xenoserver.cmdline;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.xenoserver.control.Command;
|
||||
import org.xenoserver.control.Defaults;
|
||||
|
||||
public class ParseHelp extends CommandParser {
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.xenoserver.control.Extent;
|
||||
import org.xenoserver.control.Mode;
|
||||
import org.xenoserver.control.Partition;
|
||||
import org.xenoserver.control.PartitionManager;
|
||||
import org.xenoserver.control.Settings;
|
||||
import org.xenoserver.control.XML;
|
||||
|
||||
public class ParsePhysicalGrant extends CommandParser {
|
||||
public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
|
||||
@@ -31,7 +29,7 @@ public class ParsePhysicalGrant extends CommandParser {
|
||||
mode = Mode.READ_ONLY;
|
||||
|
||||
// Initialise the partition manager and look up the partition
|
||||
XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
|
||||
loadState();
|
||||
Partition p = PartitionManager.it.get_partition(partition_name);
|
||||
|
||||
if ( p == null )
|
||||
|
||||
@@ -9,11 +9,8 @@ import org.xenoserver.control.CommandPhysicalList;
|
||||
import org.xenoserver.control.Defaults;
|
||||
import org.xenoserver.control.Extent;
|
||||
import org.xenoserver.control.Library;
|
||||
import org.xenoserver.control.Mode;
|
||||
import org.xenoserver.control.Partition;
|
||||
import org.xenoserver.control.PartitionManager;
|
||||
import org.xenoserver.control.Settings;
|
||||
import org.xenoserver.control.XML;
|
||||
|
||||
public class ParsePhysicalList extends CommandParser {
|
||||
|
||||
@@ -23,7 +20,7 @@ public class ParsePhysicalList extends CommandParser {
|
||||
throw new ParseFailedException("Expected -n<domain_id>");
|
||||
|
||||
// Initialise the partition manager
|
||||
XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
|
||||
loadState();
|
||||
|
||||
CommandPhysicalList list = new CommandPhysicalList( d, domain_id );
|
||||
String output = list.execute();
|
||||
|
||||
@@ -8,8 +8,6 @@ import org.xenoserver.control.Defaults;
|
||||
import org.xenoserver.control.Extent;
|
||||
import org.xenoserver.control.Partition;
|
||||
import org.xenoserver.control.PartitionManager;
|
||||
import org.xenoserver.control.Settings;
|
||||
import org.xenoserver.control.XML;
|
||||
|
||||
public class ParsePhysicalRevoke extends CommandParser {
|
||||
public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
|
||||
@@ -22,7 +20,7 @@ public class ParsePhysicalRevoke extends CommandParser {
|
||||
throw new ParseFailedException("Expected -p<partition_name>");
|
||||
|
||||
// Initialise the partition manager and look up the partition
|
||||
XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
|
||||
loadState();
|
||||
Partition p = PartitionManager.it.get_partition(partition_name);
|
||||
|
||||
if ( p == null )
|
||||
|
||||
@@ -27,7 +27,6 @@ public class CommandDomainList extends Command {
|
||||
*/
|
||||
public String execute() throws CommandFailedException {
|
||||
Runtime r = Runtime.getRuntime();
|
||||
int rc = 0;
|
||||
Vector v = new Vector();
|
||||
String outline;
|
||||
BufferedReader in;
|
||||
|
||||
@@ -31,7 +31,6 @@ public class CommandPhysicalList extends Command {
|
||||
*/
|
||||
public String execute() throws CommandFailedException {
|
||||
Runtime r = Runtime.getRuntime();
|
||||
int rc = 0;
|
||||
String outline;
|
||||
BufferedReader in;
|
||||
String output = null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.xenoserver.control;
|
||||
|
||||
import java.net.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class InetAddressPattern
|
||||
{
|
||||
@@ -11,7 +12,6 @@ public class InetAddressPattern
|
||||
{
|
||||
InetAddressPattern result = new InetAddressPattern ();
|
||||
char[] ca = t.toCharArray ();
|
||||
int idx = 0;
|
||||
int len = ca.length;
|
||||
|
||||
try {
|
||||
|
||||
@@ -126,4 +126,41 @@ Library
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number of bytes in whichever way makes most sense based
|
||||
* on magnitude and width.
|
||||
*
|
||||
* @param size Number of bytes.
|
||||
* @param width Width of field - at least 5, plz.
|
||||
* @param prefix Set to 1 for left justify
|
||||
* @return The formatted string.
|
||||
*/
|
||||
public static String format_size(long size,int width,int prefix) {
|
||||
char[] suffixes = { ' ', 'k', 'M', 'G' };
|
||||
int suffix = 0;
|
||||
long before = size;
|
||||
float after = 0;
|
||||
|
||||
while ( before > 10000 ) {
|
||||
after = ((float)(before % 1024)) / 1024;
|
||||
before /= 1024;
|
||||
suffix++;
|
||||
}
|
||||
|
||||
StringBuffer num = new StringBuffer(width);
|
||||
num.append( Long.toString( before ) );
|
||||
if ( after != 0 ) {
|
||||
int space = width - num.length() - 2;
|
||||
if ( space > 0 ) {
|
||||
num.append( '.' );
|
||||
if ( space > 3 )
|
||||
space = 3;
|
||||
num.append( Integer.toString( (int) (after * Math.pow(10,space))));
|
||||
}
|
||||
}
|
||||
num.append( suffixes[suffix] );
|
||||
|
||||
return format(num.toString(),width,prefix);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.xenoserver.control;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class
|
||||
Partition
|
||||
|
||||
@@ -5,10 +5,13 @@
|
||||
|
||||
package org.xenoserver.control;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* PartitionManager manages the partitions on the machine. It is a Singleton
|
||||
@@ -136,8 +139,6 @@ PartitionManager
|
||||
void
|
||||
dump_xml (PrintWriter out)
|
||||
{
|
||||
int loop;
|
||||
|
||||
out.println("<partitions>");
|
||||
for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ public final class Settings
|
||||
public static final String PARTITIONS_FILE = System.getProperty("PARTITIONS_FILE", "/proc/partitions");
|
||||
public static final String STATE_INPUT_FILE = System.getProperty("STATE_INPUT_FILE", "/var/lib/xen/vdstate.xml");
|
||||
public static final String STATE_OUTPUT_FILE = System.getProperty("STATE_OUTPUT_FILE", "/var/lib/xen/vdstate.xml");
|
||||
public static final int SECTOR_SIZE = Integer.parseInt( System.getProperty("SECTOR_SIZE", "512") );
|
||||
|
||||
public static File getDefaultsFile() {
|
||||
StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":");
|
||||
|
||||