mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
bitkeeper revision 1.287 (3f09868dbEGgx_VclUxqKkhY0if9xA)
Delete vdmanager as any useful code it contained has been moved into the old xenctl web src
This commit is contained in:
1 parent
e08b759edc
commit
928d168337
17 files changed
-1930
No files matched your search
@@ -57,7 +57,6 @@
|
||||
3ec41f7dvPdszb0frNEkMnEdJUBVjA tools/control/src/uk/ac/cam/cl/xeno/xenctl/SystemConfigurationBean.java
|
||||
3ec41f7dlW5Buk3MO18HHtBax1Jz9g tools/control/src/uk/ac/cam/cl/xeno/xenctl/VirtualBlockDevice.java
|
||||
3ec41f7dP3VglJUTuP45rwvSAoW_pg tools/control/src/uk/ac/cam/cl/xeno/xenctl/VirtualDisk.java
|
||||
3ec41f7d8_ZsS9JjYQq861OFAZS9GA tools/control/src/uk/ac/cam/cl/xeno/xenctl/VirtualDiskManager.java
|
||||
3ec41f7dO6IuKGGLG4VRUhMDmkTn5g tools/control/web/WEB-INF/web.xml
|
||||
3ec41f7dRAPXBA0jQUd1k6MB3xVidg tools/control/web/img/cambridge.gif
|
||||
3ec41f7dvxVe1Vb3kVOLZcN5Jra2tQ tools/control/web/img/help.gif
|
||||
@@ -123,22 +122,7 @@
|
||||
3eb781fd8oRfPgH7qTh7xvgmwD6NgA tools/internal/xi_start.c
|
||||
3eb781fd0Eo9K1jEFCSAVzO51i_ngg tools/internal/xi_stop.c
|
||||
3eb781fd7211MZsLxJSiuy7W4KnJXg tools/internal/xi_vifinit
|
||||
3eb788dbUz7cB-Gj-Y2mcQUzxWN3NQ tools/vdmanager/Makefile
|
||||
3ea53c6dz47kAOwpk54f8_zOAQ5ngw tools/vdmanager/build.xml
|
||||
3eaff785PwN0C3-xhCf_zMCL27JIgQ tools/vdmanager/notes.xml
|
||||
3ea53c6dE-azH1i1VJmJMp9SHnETkQ tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Extent.java
|
||||
3ea53c6dtqvqC3gxeAjzmSwkYsowIw tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Library.java
|
||||
3ea53c6dVva2nmEP3TNM37RmshYJ1g tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Main.java
|
||||
3ea53c6dF_CltZw3zVG3-R76tMlhMA tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Mode.java
|
||||
3ea53c6dpDHzX93WBQXulAmm85Njzw tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Parser.java
|
||||
3ea53c6d5Rgb_r3sSpgpgP-LEn423Q tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Partition.java
|
||||
3ea53c6d2dbw9PQT8bGwFUIFIeVhGA tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/PartitionManager.java
|
||||
3ea53c6dSKVeFlBS7VwTO38BCueHBQ tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualBlockDevice.java
|
||||
3ea53c6dCSPB23LMsHvf44Pp6WL2Pg tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDisk.java
|
||||
3ea53c6d48QGVkviHh0jBB_h_ZqZDw tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDiskManager.java
|
||||
3ea53c6efdL6CPTu_z5b_MxlxTdX_Q tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/XML.java
|
||||
3ea53c6ek5CbDZbBF3513sZKa5W3cQ tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/XMLHelper.java
|
||||
3ea53c6eKECrbeZtdlbaR1zcBwn94A tools/vdmanager/vdmanager
|
||||
3ddb79bcbOVHh38VJzc97-JEGD4dJQ xen/Makefile
|
||||
3ddb79bcCa2VbsMp7mWKlhgwLQUQGA xen/README
|
||||
3ddb79bcWnTwYsQRWl_PaneJfa6p0w xen/Rules.mk
|
||||
|
||||
@@ -1,315 +0,0 @@
|
||||
/*
|
||||
* VirtualDiskManager.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.xenctl;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Date;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class
|
||||
VirtualDiskManager
|
||||
{
|
||||
VirtualDisk free_disk;
|
||||
Vector virtual_disks;
|
||||
Hashtable virtual_block_devices;
|
||||
Hashtable key_hash;
|
||||
|
||||
VirtualDiskManager ()
|
||||
{
|
||||
free_disk = new VirtualDisk("free");
|
||||
|
||||
virtual_disks = new Vector(10,5);
|
||||
flush_virtual_block_devices();
|
||||
key_hash = new Hashtable(100);
|
||||
}
|
||||
|
||||
public VirtualDisk
|
||||
get_virtual_disk_key (String key)
|
||||
{
|
||||
return ((VirtualDisk) key_hash.get(key));
|
||||
}
|
||||
|
||||
public void
|
||||
add_xeno_partition (Partition partition, long size)
|
||||
{
|
||||
free_disk.add_new_partition (partition, size);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* create a new virtual disk
|
||||
*/
|
||||
|
||||
public VirtualDisk
|
||||
create_virtual_disk(String name, long size, Date expiry)
|
||||
{
|
||||
VirtualDisk vd = new VirtualDisk (name, expiry);
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
Extent e;
|
||||
|
||||
e = free_disk.remove_extent();
|
||||
if (e == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
size -= e.size;
|
||||
vd.add_extent(e);
|
||||
}
|
||||
|
||||
add_virtual_disk(vd);
|
||||
|
||||
return vd;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete a new virtual disk. extents go back into the free pool
|
||||
*/
|
||||
|
||||
public void
|
||||
delete_virtual_disk (String key)
|
||||
{
|
||||
VirtualDisk vd;
|
||||
|
||||
vd = (VirtualDisk) key_hash.get(key);
|
||||
if (vd != null)
|
||||
{
|
||||
Extent e;
|
||||
|
||||
key_hash.remove(key);
|
||||
virtual_disks.remove(vd);
|
||||
|
||||
e = vd.remove_extent();
|
||||
while (e != null)
|
||||
{
|
||||
free_disk.add_extent(e);
|
||||
e = vd.remove_extent();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* reset the expiry time for a virtual disk
|
||||
*/
|
||||
|
||||
public void
|
||||
refresh_virtual_disk (String key, Date expiry)
|
||||
{
|
||||
VirtualDisk vd = (VirtualDisk) key_hash.get(key);
|
||||
if (vd != null)
|
||||
{
|
||||
vd.set_expiry(expiry);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* create a new virtual block device
|
||||
*/
|
||||
public VirtualBlockDevice
|
||||
create_virtual_block_device (String key, int domain, int vbd_num,
|
||||
String mode)
|
||||
{
|
||||
VirtualBlockDevice vbd = new VirtualBlockDevice();
|
||||
VirtualDisk vd = get_virtual_disk_key(key);
|
||||
|
||||
if (vd == null)
|
||||
{
|
||||
System.err.println("create virtual block device error: unknown key " +
|
||||
"[" + key + "]");
|
||||
return null;
|
||||
}
|
||||
|
||||
vbd.key = key;
|
||||
vbd.domain = domain;
|
||||
vbd.vbdnum = vbd_num;
|
||||
|
||||
if (mode.equals(Mode.READ_ONLY.toString()) ||
|
||||
mode.equals("RO") ||
|
||||
mode.equals("ro"))
|
||||
{
|
||||
vbd.mode = Mode.READ_ONLY;
|
||||
}
|
||||
else if (mode.equals(Mode.READ_WRITE.toString()) ||
|
||||
mode.equals("RW") ||
|
||||
mode.equals("rw"))
|
||||
{
|
||||
vbd.mode = Mode.READ_WRITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("create virtual block device error: unknown mode " +
|
||||
"[" + mode + "]");
|
||||
return null;
|
||||
}
|
||||
|
||||
add_virtual_block_device(vbd);
|
||||
|
||||
return vbd;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete a virtual block device
|
||||
*/
|
||||
public void
|
||||
delete_virtual_block_device (int domain, int vbd_num)
|
||||
{
|
||||
Object hash = get_vbd_hash(domain, vbd_num);
|
||||
VirtualBlockDevice vbd = (VirtualBlockDevice)virtual_block_devices.remove(hash);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* flush all virtual block devices
|
||||
*/
|
||||
public void
|
||||
flush_virtual_block_devices ()
|
||||
{
|
||||
/* isn't automatic garbage collection wonderful? */
|
||||
virtual_block_devices = new Hashtable(100);
|
||||
}
|
||||
|
||||
public void
|
||||
add_virtual_disk (VirtualDisk vd)
|
||||
{
|
||||
virtual_disks.add(vd);
|
||||
key_hash.put(vd.get_key(), vd);
|
||||
}
|
||||
|
||||
public void
|
||||
add_virtual_block_device (VirtualBlockDevice vbd)
|
||||
{
|
||||
Object hash = get_vbd_hash(vbd.domain, vbd.vbdnum);
|
||||
virtual_block_devices.put(hash, vbd);
|
||||
}
|
||||
|
||||
Object
|
||||
get_vbd_hash (int domain, int vbd_num)
|
||||
{
|
||||
return new Integer(domain * 16 + vbd_num);
|
||||
}
|
||||
|
||||
public void
|
||||
add_free (VirtualDisk vd)
|
||||
{
|
||||
free_disk = vd;
|
||||
}
|
||||
|
||||
public String
|
||||
dump_virtualdisk (int segment)
|
||||
{
|
||||
if (segment < 0 || segment >= virtual_disks.size())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
VirtualDisk vd = (VirtualDisk) virtual_disks.get(segment);
|
||||
return (vd.dump(true, true));
|
||||
}
|
||||
}
|
||||
|
||||
public String
|
||||
dump_free()
|
||||
{
|
||||
return(free_disk.dump(true, false));
|
||||
}
|
||||
|
||||
public String
|
||||
dump_virtualdisks()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (int i = 0; i < virtual_disks.size(); i++)
|
||||
{
|
||||
VirtualDisk vd = (VirtualDisk) virtual_disks.get(i);
|
||||
if (i == 0)
|
||||
{
|
||||
sb.append(vd.dump(false, true));
|
||||
}
|
||||
sb.append(vd.dump(false, false));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String
|
||||
dump_virtualblockdevices()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
boolean first = true;
|
||||
|
||||
for (Enumeration enumeration = virtual_block_devices.elements() ;
|
||||
enumeration.hasMoreElements() ;)
|
||||
{
|
||||
VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement();
|
||||
if (first)
|
||||
{
|
||||
sb.append(vbd.dump(true));
|
||||
first = false;
|
||||
}
|
||||
|
||||
sb.append(vbd.dump(false));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void
|
||||
dump_xml(PrintWriter out)
|
||||
{
|
||||
out.println("<free>");
|
||||
free_disk.dump_xml(out);
|
||||
out.println("</free>");
|
||||
out.println("<virtual_disks>");
|
||||
for (int i = 0; i < virtual_disks.size(); i++)
|
||||
{
|
||||
VirtualDisk vd = (VirtualDisk) virtual_disks.get(i);
|
||||
vd.dump_xml(out);
|
||||
}
|
||||
out.println("</virtual_disks>");
|
||||
out.println("<virtual_block_devices>");
|
||||
for (Enumeration enumeration = virtual_block_devices.elements() ;
|
||||
enumeration.hasMoreElements() ;)
|
||||
{
|
||||
VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement();
|
||||
vbd.dump_xml(out);
|
||||
}
|
||||
|
||||
out.println("</virtual_block_devices>");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
public int
|
||||
getVirtualDiskCount ()
|
||||
{
|
||||
return virtual_disks.size();
|
||||
}
|
||||
|
||||
public VirtualDisk
|
||||
getVirtualDisk (int index)
|
||||
{
|
||||
return (VirtualDisk) virtual_disks.get(index);
|
||||
}
|
||||
|
||||
public VirtualDisk
|
||||
getFreeVirtualDisk ()
|
||||
{
|
||||
return free_disk;
|
||||
}
|
||||
|
||||
public Enumeration
|
||||
getVirtualBlockDevices ()
|
||||
{
|
||||
return virtual_block_devices.elements();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
default:
|
||||
ant dist
|
||||
|
||||
install: default
|
||||
cp -a vdmanager vdmanager.jar ../../../install/bin
|
||||
chmod 755 ../../../install/bin/vdmanager
|
||||
clean:
|
||||
ant clean
|
||||
rm -f vdmanager.jar
|
||||
@@ -1,45 +0,0 @@
|
||||
<project name="vdmanager project" default="compile">
|
||||
<property name="src" location="src"/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<property name="lib" location="lib"/>
|
||||
|
||||
<target name="init">
|
||||
<tstamp/>
|
||||
<mkdir dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="${src}" destdir="${build}" debug="on"/>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="compile">
|
||||
<jar jarfile="vdmanager.jar"
|
||||
excludes="*~"
|
||||
basedir="${build}">
|
||||
<fileset dir="${src}" />
|
||||
<fileset dir=".">
|
||||
<include name="build.xml"/>
|
||||
<include name="vdmanager"/>
|
||||
</fileset>
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${user.name}"/>
|
||||
<attribute name="Main-Class" value="uk.ac.cam.cl.xeno.vdmanager.Main"/>
|
||||
<attribute name="Sealed" value="true"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="test" depends="compile">
|
||||
<java fork="true" classname="uk.ac.cam.cl.xeno.vdmanager.Main">
|
||||
<classpath>
|
||||
<pathelement path="${build}"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build}"/>
|
||||
<delete dir="${lib}"/>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE vdmanager.dtd [
|
||||
<!ELEMENT vdmanager (partitions|free|virtual_disks|virtual_block_devices)*>
|
||||
|
||||
<!ELEMENT partitions (partition)*>
|
||||
<!ELEMENT partition (major, minor, blocks, star_sect, nr_sects, name)>
|
||||
<!ELEMENT major (#PCDATA)>
|
||||
<!ELEMENT minor (#PCDATA)>
|
||||
<!ELEMENT blocks (#PCDATA)>
|
||||
<!ELEMENT start_sect (#PCDATA)>
|
||||
<!ELEMENT nr_sects (#PCDATA)>
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
|
||||
<!ELEMENT free (virtual_disk)?>
|
||||
<!ELEMENT virtual_disks (virtual_disk)*>
|
||||
<!ELEMENT virtual_disk (name, key, expiry, extents)>
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
<!ELEMENT key (#PCDATA)>
|
||||
<!ELEMENT expiry (#PCDATA)>
|
||||
<!ELEMENT extents (extent)*>
|
||||
<!ELEMENT extent (disk, size, offset)>
|
||||
<!ELEMENT disk (#PCDATA)>
|
||||
<!ELEMENT size (#PCDATA)>
|
||||
<!ELEMENT offset (#PCDATA)>
|
||||
|
||||
<!ELEMENT virtual_block_devices (virtual_block_device)*>
|
||||
<!ELEMENT virtual_block_device (key, domain, vbdnum, mode)>
|
||||
<!ELEMENT key (#PCDATA)>
|
||||
<!ELEMENT domain (#PCDATA)>
|
||||
<!ELEMENT vbdnum (#PCDATA)>
|
||||
<!ELEMENT mode (#PCDATA)>
|
||||
]>
|
||||
|
||||
<vdmanager>
|
||||
</vdmanager>
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Extent.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
public class
|
||||
Extent
|
||||
{
|
||||
int disk;
|
||||
long offset; /* offset into disk */
|
||||
long size; /* size of this extent in 512 byte sectors */
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Library.java
|
||||
* 03.03.28 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
public class
|
||||
Library
|
||||
{
|
||||
/*
|
||||
* convert a number to a fixed width string
|
||||
*/
|
||||
static String
|
||||
format (long input, int width, int prefix)
|
||||
{
|
||||
String sss = Long.toString(input);
|
||||
String space = " ";
|
||||
|
||||
if (width < sss.length())
|
||||
{
|
||||
width = sss.length();
|
||||
}
|
||||
|
||||
if (prefix == 0)
|
||||
{
|
||||
return space.substring(0, width - sss.length()) + sss;
|
||||
}
|
||||
else
|
||||
{
|
||||
return sss + space.substring(0, width - sss.length());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* convert a string to a fixed width string
|
||||
*/
|
||||
static String
|
||||
format (String input, int width, int prefix)
|
||||
{
|
||||
String space = " ";
|
||||
|
||||
if (width < input.length())
|
||||
{
|
||||
width = input.length();
|
||||
}
|
||||
|
||||
if (prefix == 0)
|
||||
{
|
||||
return space.substring(0, width - input.length()) + input;
|
||||
}
|
||||
else
|
||||
{
|
||||
return input + space.substring(0, width - input.length());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* convert a number (string format) into
|
||||
* the corresponding integer value.
|
||||
*/
|
||||
static long
|
||||
parse_size(String size)
|
||||
{
|
||||
String substring = size;
|
||||
int suffix = 1;
|
||||
|
||||
if ((substring = check(size, 'm')) != null)
|
||||
{
|
||||
suffix = 1024 * 1024;
|
||||
}
|
||||
else if ((substring = check(size, 'M')) != null)
|
||||
{
|
||||
suffix = 1024 * 1024;
|
||||
}
|
||||
else if ((substring = check(size, 'k')) != null)
|
||||
{
|
||||
suffix = 1024;
|
||||
}
|
||||
else if ((substring = check(size, 'K')) != null)
|
||||
{
|
||||
suffix = 1024;
|
||||
}
|
||||
else if ((substring = check(size, 'g')) != null)
|
||||
{
|
||||
suffix = 1024 * 1024 * 1024;
|
||||
}
|
||||
else if ((substring = check(size, 'G')) != null)
|
||||
{
|
||||
suffix = 1024 * 1024 * 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
substring = size;
|
||||
}
|
||||
|
||||
return Long.decode(substring).longValue() * suffix;
|
||||
}
|
||||
|
||||
static String
|
||||
check(String size, char suffix)
|
||||
{
|
||||
int index = size.indexOf(suffix);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
return size.substring(0, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Main.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class
|
||||
Main
|
||||
{
|
||||
static String state_filename_in = "/var/lib/xen/vdstate.xml";
|
||||
static String state_filename_out = "/var/lib/xen/vdstate.xml";
|
||||
static String partition_filename = "/proc/partitions";
|
||||
|
||||
void
|
||||
go (String[] argv)
|
||||
{
|
||||
PartitionManager pm = new PartitionManager(partition_filename);
|
||||
VirtualDiskManager vdm = new VirtualDiskManager();;
|
||||
Parser parser = new Parser(pm, vdm);
|
||||
|
||||
XML.load_state(pm, vdm, state_filename_in);
|
||||
parser.parse_main(argv);
|
||||
XML.dump_state(pm, vdm, state_filename_out);
|
||||
}
|
||||
|
||||
public static void
|
||||
main (String[] argv)
|
||||
{
|
||||
Main foo = new Main();
|
||||
foo.go(argv);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Mode.java
|
||||
* 03.03.27 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
public class
|
||||
Mode
|
||||
{
|
||||
private final String name;
|
||||
|
||||
private Mode(String name) { this.name = name; }
|
||||
|
||||
public String toString() { return name; }
|
||||
|
||||
public static final Mode READ_ONLY = new Mode("ro");
|
||||
public static final Mode READ_WRITE = new Mode("rw");
|
||||
}
|
||||
|
||||
@@ -1,446 +0,0 @@
|
||||
/*
|
||||
* Parser.java
|
||||
* 03.03.27 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
import java.util.Date;
|
||||
|
||||
public class
|
||||
Parser
|
||||
{
|
||||
static String prompt = "vdmanager> ";
|
||||
static String default_addpartition_chunksize = "104857600"; /* 100M */
|
||||
static int default_sector_size = 512;
|
||||
|
||||
PartitionManager pm;
|
||||
VirtualDiskManager vdm;
|
||||
|
||||
Parser (PartitionManager pm, VirtualDiskManager vdm)
|
||||
{
|
||||
this.pm = pm;
|
||||
this.vdm = vdm;
|
||||
}
|
||||
|
||||
void
|
||||
parse_main (String[] argv)
|
||||
{
|
||||
if (argv.length == 0)
|
||||
{
|
||||
parse_input(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
parse_commandline(argv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_input (String filename)
|
||||
{
|
||||
String line;
|
||||
BufferedReader in;
|
||||
|
||||
if (filename != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in = new BufferedReader(new FileReader(filename));
|
||||
}
|
||||
catch (FileNotFoundException fnfe)
|
||||
{
|
||||
System.err.println (fnfe);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
in = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (filename == null)
|
||||
{
|
||||
System.out.print (prompt);
|
||||
}
|
||||
line = in.readLine();
|
||||
while (line != null)
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(line);
|
||||
Vector v = new Vector();
|
||||
|
||||
while (st.hasMoreTokens())
|
||||
{
|
||||
v.add(st.nextToken());
|
||||
}
|
||||
|
||||
if (parse_commandline((String[]) v.toArray(new String[v.size()])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (filename == null)
|
||||
{
|
||||
System.out.print (prompt);
|
||||
}
|
||||
line = in.readLine();
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
System.err.println(ioe);
|
||||
}
|
||||
|
||||
if (filename == null)
|
||||
{
|
||||
System.out.println ("");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean
|
||||
parse_commandline (String[] commands)
|
||||
{
|
||||
if (commands.length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String keyword = commands[0].toLowerCase();
|
||||
if (keyword.equals("file"))
|
||||
{
|
||||
if (commands.length < 2)
|
||||
{
|
||||
System.out.println ("file [filename]");
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < commands.length; i++)
|
||||
{
|
||||
System.out.println ("file " + commands[i]);
|
||||
parse_input(commands[i]);
|
||||
}
|
||||
}
|
||||
else if (keyword.equals("show"))
|
||||
{
|
||||
parse_show(commands);
|
||||
}
|
||||
else if (keyword.equals("addpartition"))
|
||||
{
|
||||
parse_addpartition(commands);
|
||||
}
|
||||
else if (keyword.equals("vdcreate"))
|
||||
{
|
||||
parse_vdcreate(commands);
|
||||
}
|
||||
else if (keyword.equals("vddelete"))
|
||||
{
|
||||
parse_vddelete(commands);
|
||||
}
|
||||
else if (keyword.equals("vdrefresh"))
|
||||
{
|
||||
parse_vdrefresh(commands);
|
||||
}
|
||||
else if (keyword.equals("vbdcreate"))
|
||||
{
|
||||
parse_vbdcreate(commands);
|
||||
}
|
||||
else if (keyword.equals("vbddelete"))
|
||||
{
|
||||
parse_vbddelete(commands);
|
||||
}
|
||||
else if (keyword.equals("vbdflush"))
|
||||
{
|
||||
vdm.flush_virtual_block_devices();
|
||||
}
|
||||
else if (keyword.equals("load"))
|
||||
{
|
||||
if (commands.length < 2)
|
||||
{
|
||||
System.out.println ("load <filename>");
|
||||
return false;
|
||||
}
|
||||
XML.load_state (pm, vdm, commands[1]);
|
||||
}
|
||||
else if (keyword.equals("save"))
|
||||
{
|
||||
if (commands.length < 2)
|
||||
{
|
||||
System.out.println ("save <filename>");
|
||||
return false;
|
||||
}
|
||||
XML.dump_state (pm, vdm, commands[1]);
|
||||
}
|
||||
else if (keyword.equals("help") ||
|
||||
keyword.equals("?"))
|
||||
{
|
||||
parse_help();
|
||||
}
|
||||
else if (keyword.equals("exit") ||
|
||||
keyword.equals("quit"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println ("unknown command [" + commands[0] + "]. " +
|
||||
"try \"help\"");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
parse_vdcreate (String[] commands)
|
||||
{
|
||||
VirtualDisk vd;
|
||||
|
||||
if (commands.length < 4)
|
||||
{
|
||||
System.out.println ("vdcreate name size expiry");
|
||||
return;
|
||||
}
|
||||
|
||||
vd = vdm.create_virtual_disk(commands[1],
|
||||
Library.parse_size(commands[2]) / default_sector_size,
|
||||
new Date());
|
||||
|
||||
System.out.println ("Virtual Disk created with key: " + vd.get_key());
|
||||
}
|
||||
|
||||
void
|
||||
parse_vddelete (String[] commands)
|
||||
{
|
||||
if (commands.length < 2)
|
||||
{
|
||||
System.out.println ("vddelete key");
|
||||
return;
|
||||
}
|
||||
|
||||
vdm.delete_virtual_disk(commands[1]);
|
||||
}
|
||||
|
||||
void
|
||||
parse_vdrefresh (String[] commands)
|
||||
{
|
||||
if (commands.length < 3)
|
||||
{
|
||||
System.out.println ("vdrefresh key expiry");
|
||||
return;
|
||||
}
|
||||
|
||||
vdm.refresh_virtual_disk(commands[1],
|
||||
new Date());
|
||||
}
|
||||
|
||||
void
|
||||
parse_vbdcreate (String[] commands)
|
||||
{
|
||||
VirtualDisk vd;
|
||||
VirtualBlockDevice vbd;
|
||||
|
||||
if (commands.length < 4)
|
||||
{
|
||||
System.out.println ("vbdcreate <key> <domain number> <vbd number>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (commands[1].startsWith("sd") ||
|
||||
commands[1].startsWith("hd"))
|
||||
{
|
||||
/*
|
||||
* this is a gross hack to allow you to create a virtual block
|
||||
* device that maps directly to a physical partition
|
||||
*/
|
||||
|
||||
/* find the appropriate partition */
|
||||
Partition partition = pm.get_partition(commands[1]);
|
||||
if (partition == null)
|
||||
{
|
||||
System.out.println ("vbdcreate error: couldn't find partition \"" +
|
||||
commands[1] + "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
/* create a virtual disk */
|
||||
vd = new VirtualDisk("vbd:" + commands[1]);
|
||||
vd.add_new_partition(partition, partition.nr_sects);
|
||||
|
||||
|
||||
/* display result */
|
||||
System.out.print("domain:" + commands[2] + " ");
|
||||
if (commands.length == 4)
|
||||
{
|
||||
System.out.print ("rw ");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.print(commands[4] + " ");
|
||||
}
|
||||
System.out.print("segment:" + commands[3] + " ");
|
||||
System.out.print(vd.dump_xen());
|
||||
System.out.println("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (commands.length == 4)
|
||||
{
|
||||
vbd =
|
||||
vdm.create_virtual_block_device(commands[1],
|
||||
Integer.decode(commands[2]).intValue(),
|
||||
Integer.decode(commands[3]).intValue(),
|
||||
"rw");
|
||||
}
|
||||
else
|
||||
{
|
||||
vbd =
|
||||
vdm.create_virtual_block_device(commands[1],
|
||||
Integer.decode(commands[2]).intValue(),
|
||||
Integer.decode(commands[3]).intValue(),
|
||||
commands[4]);
|
||||
}
|
||||
|
||||
/* display commandline to user */
|
||||
{
|
||||
vd = vdm.get_virtual_disk_key(commands[1]);
|
||||
System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_vbddelete (String[] commands)
|
||||
{
|
||||
if (commands.length < 3)
|
||||
{
|
||||
System.out.println ("vbddelete <domain number> <vbd number>");
|
||||
return;
|
||||
}
|
||||
|
||||
vdm.delete_virtual_block_device(Integer.decode(commands[1]).intValue(),
|
||||
Integer.decode(commands[2]).intValue());
|
||||
}
|
||||
|
||||
static String show_helptxt = "show <partitions | free | vd [vd number] | vbd>";
|
||||
void
|
||||
parse_show (String[] commands)
|
||||
{
|
||||
String subword;
|
||||
|
||||
if (commands.length < 2)
|
||||
{
|
||||
System.out.println (show_helptxt);
|
||||
return;
|
||||
}
|
||||
|
||||
subword = commands[1].toLowerCase();
|
||||
if (subword.equals("partition") ||
|
||||
subword.equals("partitions"))
|
||||
{
|
||||
System.out.println(pm.dump(true));
|
||||
}
|
||||
else if (subword.equals("vd"))
|
||||
{
|
||||
String text;
|
||||
|
||||
if (commands.length < 3)
|
||||
{
|
||||
System.out.println(vdm.dump_virtualdisks());
|
||||
return;
|
||||
}
|
||||
text = vdm.dump_virtualdisk(Integer.decode(commands[2]).intValue());
|
||||
if (text == null)
|
||||
{
|
||||
System.out.println("show vd error: invalid virtual disk number");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(text);
|
||||
}
|
||||
}
|
||||
else if (subword.equals("vbd"))
|
||||
{
|
||||
System.out.println(vdm.dump_virtualblockdevices());
|
||||
}
|
||||
else if (subword.equals("free"))
|
||||
{
|
||||
System.out.println(vdm.dump_free());
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println (show_helptxt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_addpartition(String[] commands)
|
||||
{
|
||||
String chunksize = default_addpartition_chunksize;
|
||||
|
||||
if (commands.length > 3 || commands.length < 2)
|
||||
{
|
||||
System.out.println ("addpartition <partition number> [chunksize]");
|
||||
return;
|
||||
}
|
||||
if (commands.length == 3)
|
||||
{
|
||||
chunksize = commands[2];
|
||||
}
|
||||
|
||||
System.out.println ("add partition " + commands[1] + " " + chunksize);
|
||||
|
||||
vdm.add_xeno_partition(pm.get_partition(Integer.parseInt(commands[1])),
|
||||
Library.parse_size(chunksize)/default_sector_size);
|
||||
pm.add_xeno_partition(pm.get_partition(Integer.parseInt(commands[1])));
|
||||
}
|
||||
|
||||
void
|
||||
parse_help()
|
||||
{
|
||||
System.out.println ("file <filename> " +
|
||||
"read the contents of a file as input to vdmanager");
|
||||
System.out.println ("addpartition <partition number> [chunksize]");
|
||||
System.out.println (" " +
|
||||
"add a partition as a xeno partition");
|
||||
System.out.println ("vdcreate <name> <size> <expiry>");
|
||||
System.out.println (" " +
|
||||
"create a new virtual disk");
|
||||
System.out.println ("vddelete <key> " +
|
||||
"delete a virtual disk");
|
||||
System.out.println ("vdrefresh <key> <expiry>");
|
||||
System.out.println (" " +
|
||||
"reset virtual disk expiry");
|
||||
System.out.println ("vbdcreate <key> <domain number> <vbd number> [rw|ro]");
|
||||
System.out.println (" " +
|
||||
"create a new virtual block device");
|
||||
System.out.println ("vbddelete <domain number> <vbd number>");
|
||||
System.out.println (" " +
|
||||
"delete a new virtual block device");
|
||||
System.out.println ("vbdflush " +
|
||||
"remove all virtual block devices");
|
||||
System.out.println ("show partitions " +
|
||||
"display a complete list of disk partitions");
|
||||
System.out.println ("show vd <vd number> " +
|
||||
"display virtual disk information");
|
||||
System.out.println ("show vbd " +
|
||||
"display virtual virtual block device list");
|
||||
System.out.println ("show free " +
|
||||
"display details about unallocated space");
|
||||
System.out.println ("load <filename> " +
|
||||
"load new state from file");
|
||||
System.out.println ("save <filename> " +
|
||||
"save state to file");
|
||||
System.out.println ("help " +
|
||||
"display this help message");
|
||||
System.out.println ("quit " +
|
||||
"exit");
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* PartitionManager.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class
|
||||
Partition
|
||||
{
|
||||
int major;
|
||||
int minor;
|
||||
long blocks;
|
||||
long start_sect;
|
||||
long nr_sects;
|
||||
String name;
|
||||
|
||||
boolean
|
||||
identical (Partition p)
|
||||
{
|
||||
return (major == p.major &&
|
||||
minor == p.minor &&
|
||||
blocks == p.blocks &&
|
||||
start_sect == p.start_sect &&
|
||||
nr_sects == p.nr_sects &&
|
||||
name.equals(p.name));
|
||||
}
|
||||
|
||||
Partition
|
||||
duplicate ()
|
||||
{
|
||||
Partition p = new Partition();
|
||||
|
||||
p.major = major;
|
||||
p.minor = minor;
|
||||
p.blocks = blocks;
|
||||
p.start_sect = start_sect;
|
||||
p.nr_sects = nr_sects;
|
||||
p.name = name;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
String
|
||||
dump (boolean title)
|
||||
{
|
||||
if (title)
|
||||
{
|
||||
return ("maj:min " +
|
||||
" blocks " +
|
||||
"start sect " +
|
||||
" num sects " +
|
||||
"name");
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Library.format(major,3,0) + ":" +
|
||||
Library.format(minor,3,1) + " " +
|
||||
Library.format(blocks,10,0) + " " +
|
||||
Library.format(start_sect,10,0) + " " +
|
||||
Library.format(nr_sects,10,0) + " " +
|
||||
Library.format(name,7,1));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dump_xml(PrintWriter out)
|
||||
{
|
||||
out.println (" <partition>\n" +
|
||||
" <major>" + major + "</major>\n" +
|
||||
" <minor>" + minor + "</minor>\n" +
|
||||
" <blocks>" + blocks + "</blocks>\n" +
|
||||
" <start_sect>" + start_sect + "</start_sect>\n" +
|
||||
" <nr_sects>" + nr_sects + "</nr_sects>\n" +
|
||||
" <name>" + name + "</name>\n" +
|
||||
" </partition>");
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* PartitionManager.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class
|
||||
PartitionManager
|
||||
{
|
||||
Vector partition_map;
|
||||
Vector xeno_partition_list;
|
||||
|
||||
static String proc_template =
|
||||
"major minor #blocks start_sect nr_sects name";
|
||||
|
||||
/*
|
||||
* Initialize partition manager with source file.
|
||||
* Normally we read from /proc/partitions, but we can
|
||||
* specify an alternative file for debugging
|
||||
*/
|
||||
PartitionManager (String filename)
|
||||
{
|
||||
String str;
|
||||
BufferedReader in;
|
||||
|
||||
partition_map = new Vector(100,10);
|
||||
xeno_partition_list = new Vector(10,5);
|
||||
|
||||
try
|
||||
{
|
||||
in = new BufferedReader(new FileReader(filename));
|
||||
|
||||
str = in.readLine(); /* skip headings */
|
||||
if (str.length() < proc_template.length() ||
|
||||
!str.substring(0, proc_template.length()).equals(proc_template))
|
||||
{
|
||||
System.err.println ("Error: Incorrect /proc/partitions.");
|
||||
System.err.println (" Is this Xeno?");
|
||||
System.exit (1);
|
||||
}
|
||||
|
||||
str = in.readLine(); /* skip blank line */
|
||||
|
||||
str = in.readLine();
|
||||
while (str != null)
|
||||
{
|
||||
Partition partition = new Partition();
|
||||
|
||||
partition.major = Integer.parseInt(str.substring(0,5).trim());
|
||||
partition.minor = Integer.parseInt(str.substring(5,10).trim());
|
||||
partition.blocks = Integer.parseInt(str.substring(10,21).trim());
|
||||
partition.start_sect = Integer.parseInt(str.substring(21,32).trim());
|
||||
partition.nr_sects = Integer.parseInt(str.substring(32,43).trim());
|
||||
partition.name = str.substring(43).trim();
|
||||
|
||||
partition_map.add(partition);
|
||||
str = in.readLine();
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
System.err.println ("PartitionManager: error reading partition file ["
|
||||
+ filename + "]");
|
||||
System.err.println (io);
|
||||
}
|
||||
}
|
||||
|
||||
Partition
|
||||
get_partition (String name)
|
||||
{
|
||||
Partition partition = null;
|
||||
for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;)
|
||||
{
|
||||
partition = (Partition) e.nextElement();
|
||||
if (partition.name.equals(name))
|
||||
{
|
||||
return partition;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Partition
|
||||
get_partition (int index)
|
||||
{
|
||||
return (Partition) partition_map.get(index);
|
||||
}
|
||||
|
||||
void
|
||||
add_xeno_partition (Partition partition)
|
||||
{
|
||||
Partition xeno_partition = (Partition) partition.duplicate();
|
||||
|
||||
xeno_partition_list.add(xeno_partition);
|
||||
}
|
||||
|
||||
/*
|
||||
* dump the xeno partition list as xml
|
||||
*/
|
||||
void
|
||||
dump_xml (PrintWriter out)
|
||||
{
|
||||
int loop;
|
||||
|
||||
out.println("<partitions>");
|
||||
for (loop = 0; loop < xeno_partition_list.size(); loop++)
|
||||
{
|
||||
Partition partition = (Partition) xeno_partition_list.get(loop);
|
||||
partition.dump_xml(out);
|
||||
}
|
||||
out.println("</partitions>");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* dump the partition map as a string
|
||||
* mark: mark the current xeno partitions in the partition map
|
||||
*/
|
||||
String
|
||||
dump (boolean mark)
|
||||
{
|
||||
int loop, idx;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Partition partition;
|
||||
|
||||
for (idx = 0; idx < partition_map.size(); idx++)
|
||||
{
|
||||
boolean xeno_partition = false;
|
||||
|
||||
partition = (Partition) partition_map.get(idx);
|
||||
|
||||
/* is this a xeno partition */
|
||||
if (mark)
|
||||
{
|
||||
for (loop = 0; loop < xeno_partition_list.size(); loop++)
|
||||
{
|
||||
if (partition.identical((Partition)xeno_partition_list.get(loop)))
|
||||
{
|
||||
xeno_partition = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == 0)
|
||||
{
|
||||
sb.append(" idx " + partition.dump(true) + "\n");
|
||||
}
|
||||
if (xeno_partition)
|
||||
{
|
||||
sb.append("[ ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(Library.format(idx,2,0) + " " + partition.dump(false));
|
||||
if (xeno_partition)
|
||||
{
|
||||
sb.append("]\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* VirtualBlockDevice.java
|
||||
* 03.03.27 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class
|
||||
VirtualBlockDevice
|
||||
{
|
||||
String key;
|
||||
int domain;
|
||||
int vbdnum;
|
||||
Mode mode; /* rw or ro */
|
||||
|
||||
String
|
||||
dump (boolean title)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int loop;
|
||||
|
||||
if (title)
|
||||
{
|
||||
sb.append(" key dom vbd mode\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(" " + key + " " +
|
||||
Library.format(domain,3,0) + " " +
|
||||
Library.format(vbdnum,3,0) + " " +
|
||||
mode.toString() + "\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void
|
||||
dump_xml (PrintWriter out)
|
||||
{
|
||||
out.println(" <virtual_block_device>");
|
||||
out.println(" <key>" + key + "</key>");
|
||||
out.println(" <domain>" + domain + "</domain>");
|
||||
out.println(" <vbdnum>" + vbdnum + "</vbdnum>");
|
||||
out.println(" <mode>" + mode + "</mode>");
|
||||
out.println(" </virtual_block_device>");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* VirtualDisk.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
import java.lang.Math;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class
|
||||
VirtualDisk
|
||||
{
|
||||
String name;
|
||||
String key;
|
||||
Date expiry;
|
||||
Vector extents;
|
||||
|
||||
VirtualDisk (String name, Date expiry, String key)
|
||||
{
|
||||
this.name = name;
|
||||
this.key = key;
|
||||
this.expiry = expiry;
|
||||
extents = new Vector();
|
||||
}
|
||||
|
||||
VirtualDisk (String name)
|
||||
{
|
||||
this (name, null, null);
|
||||
this.key = generate_key();
|
||||
extents = new Vector();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualDisk (String name, Date expiry)
|
||||
{
|
||||
this(name, expiry, null);
|
||||
this.key = generate_key();
|
||||
}
|
||||
|
||||
/*
|
||||
* generate a unique key for this virtual disk.
|
||||
* for now, just generate a 10 digit number
|
||||
*/
|
||||
String
|
||||
generate_key ()
|
||||
{
|
||||
return Long.toString(1000000000l + (long)(Math.random() * 8999999999l));
|
||||
}
|
||||
|
||||
String
|
||||
get_key ()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
Date
|
||||
get_expiry ()
|
||||
{
|
||||
return expiry;
|
||||
}
|
||||
|
||||
void
|
||||
set_expiry (Date expiry)
|
||||
{
|
||||
this.expiry = expiry;
|
||||
}
|
||||
|
||||
public void
|
||||
add_extent (Extent extent)
|
||||
{
|
||||
extents.add(extent);
|
||||
}
|
||||
|
||||
public Extent
|
||||
remove_extent ()
|
||||
{
|
||||
Extent e;
|
||||
|
||||
if (extents.size() > 0)
|
||||
{
|
||||
e = (Extent) extents.remove(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
e = null;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
String
|
||||
dump (boolean details, boolean title)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int loop;
|
||||
|
||||
if (details)
|
||||
{
|
||||
if (title)
|
||||
{
|
||||
sb.append(" name: " + name + "\n");
|
||||
sb.append(" key: " + key + "\n");
|
||||
sb.append("expiry: " + expiry + "\n");
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(" idx disk offset size \n");
|
||||
for (loop = 0; loop < extents.size(); loop++)
|
||||
{
|
||||
Extent e = (Extent) extents.get(loop);
|
||||
sb.append(" " +
|
||||
Library.format(loop,3,0) + " " +
|
||||
Library.format(e.disk,6,0) +
|
||||
Library.format(e.offset,10,0) +
|
||||
Library.format(e.size,10,0) + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (title)
|
||||
{
|
||||
sb.append(" key expiry name\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append(" " + key + " " + expiry.toString() + " " + name + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String
|
||||
dump_xen ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append("extents:" + extents.size() + " ");
|
||||
for (int loop = 0; loop < extents.size(); loop++)
|
||||
{
|
||||
Extent e = (Extent) extents.get(loop);
|
||||
sb.append("(disk:" + e.disk + " " +
|
||||
"offset:" + e.offset + " " +
|
||||
"size:" + e.size + ")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
String
|
||||
dump_xen (VirtualBlockDevice vbd)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append("domain:" + vbd.domain + " " +
|
||||
vbd.mode.toString() + " " +
|
||||
"segment:" + vbd.vbdnum + " " +
|
||||
"extents:" + extents.size() + " ");
|
||||
for (int loop = 0; loop < extents.size(); loop++)
|
||||
{
|
||||
Extent e = (Extent) extents.get(loop);
|
||||
sb.append("(disk:" + e.disk + " " +
|
||||
"offset:" + e.offset + " " +
|
||||
"size:" + e.size + ")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void
|
||||
dump_xml (PrintWriter out)
|
||||
{
|
||||
out.println(" <virtual_disk>");
|
||||
out.println(" <name>" + name + "</name>");
|
||||
out.println(" <key>" + key + "</key>");
|
||||
if (expiry == null)
|
||||
{
|
||||
out.println(" <expiry>0</expiry>");
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println(" <expiry>" + expiry.getTime() + "</expiry>");
|
||||
}
|
||||
out.println(" <extents>");
|
||||
for (int loop = 0; loop < extents.size(); loop++)
|
||||
{
|
||||
Extent e = (Extent) extents.get(loop);
|
||||
out.println(" <extent>");
|
||||
out.println(" <disk>" + e.disk + "</disk>");
|
||||
out.println(" <size>" + e.size + "</size>");
|
||||
out.println(" <offset>" + e.offset + "</offset>");
|
||||
out.println(" </extent>");
|
||||
}
|
||||
out.println(" </extents>");
|
||||
out.println(" </virtual_disk>");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a partition as a XenoPartition.
|
||||
* Chop the partition in to extents and of size "size" sectors
|
||||
* and add them to the virtual disk.
|
||||
*/
|
||||
|
||||
void
|
||||
add_new_partition (Partition partition, long size)
|
||||
{
|
||||
int loop;
|
||||
|
||||
for (loop = 0; loop < partition.nr_sects / size; loop++)
|
||||
{
|
||||
Extent extent = new Extent();
|
||||
|
||||
extent.disk = partition.major << 8;
|
||||
extent.disk = extent.disk | (partition.minor >> 5) << 5;
|
||||
extent.size = size;
|
||||
extent.offset = partition.start_sect + (size * loop);
|
||||
|
||||
add_extent(extent);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* XML.java
|
||||
* 03.03.26 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
public class
|
||||
XML
|
||||
{
|
||||
static Document document = null;
|
||||
|
||||
/*
|
||||
* dump partition manager and virtual disk manager state to filename
|
||||
*/
|
||||
|
||||
static void
|
||||
dump_state (PartitionManager pm, VirtualDiskManager vdm, String filename)
|
||||
{
|
||||
PrintWriter out;
|
||||
|
||||
try
|
||||
{
|
||||
out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.err.println ("XML.dump_state error [" + filename + "]");
|
||||
System.err.println (e);
|
||||
return;
|
||||
}
|
||||
|
||||
out.println("<?xml version=\"1.0\"?>");
|
||||
out.println("<vdmanager>");
|
||||
pm.dump_xml(out);
|
||||
vdm.dump_xml(out);
|
||||
out.println("</vdmanager>");
|
||||
|
||||
out.close();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* load partition manager and virtual disk manager state from filename
|
||||
*/
|
||||
static void
|
||||
load_state (PartitionManager pm, VirtualDiskManager vdm, String filename)
|
||||
{
|
||||
if (document == null)
|
||||
{
|
||||
load_file (filename);
|
||||
}
|
||||
|
||||
XMLHelper.parse(pm, vdm, document);
|
||||
}
|
||||
|
||||
/*
|
||||
* load XML from disk
|
||||
*/
|
||||
static void
|
||||
load_file (String filename)
|
||||
{
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
// factory.setNamespaceAware(true);
|
||||
// factory.setValidating(true);
|
||||
|
||||
try
|
||||
{
|
||||
File file = new File(filename);
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
document = builder.parse(file);
|
||||
}
|
||||
catch (SAXParseException spe) /* error generated by parser */
|
||||
{
|
||||
System.err.println ("xml parser exception on line " +
|
||||
spe.getLineNumber() +
|
||||
" for uri " + spe.getSystemId());
|
||||
System.err.println (spe.getMessage());
|
||||
|
||||
Exception x = spe;
|
||||
if (spe.getException() != null)
|
||||
x = spe.getException();
|
||||
x.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
catch (SAXException sxe)
|
||||
{
|
||||
Exception e = sxe;
|
||||
if (sxe.getException() != null)
|
||||
e = sxe.getException();
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
catch (ParserConfigurationException pce)
|
||||
{
|
||||
pce.printStackTrace();
|
||||
}
|
||||
catch (FileNotFoundException fnfe)
|
||||
{
|
||||
System.err.println ("warning: state file not found [" +
|
||||
filename + "]");
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* XMLHelper.java
|
||||
* 03.03.27 aho creation
|
||||
*/
|
||||
|
||||
package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.util.Date;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class
|
||||
XMLHelper
|
||||
{
|
||||
static void
|
||||
dump_document (Document document)
|
||||
{
|
||||
dump_element(document.getDocumentElement(), 0);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_element (Element element, int indent)
|
||||
{
|
||||
NodeList nl = element.getChildNodes();
|
||||
|
||||
System.out.println ("<" + element.getTagName() + ">");
|
||||
dump_nodelist(nl, indent + 1);
|
||||
System.out.println("</" + element.getTagName() + ">");
|
||||
}
|
||||
|
||||
static void
|
||||
dump_nodelist (NodeList nl, int indent)
|
||||
{
|
||||
for (int loop = 0; loop < nl.getLength(); loop++)
|
||||
{
|
||||
Node node = nl.item(loop);
|
||||
switch (node.getNodeType())
|
||||
{
|
||||
case Node.ELEMENT_NODE :
|
||||
{
|
||||
dump_element((Element)node, indent);
|
||||
break;
|
||||
}
|
||||
case Node.TEXT_NODE :
|
||||
{
|
||||
System.out.println("TEXT: " + node.getNodeValue());
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
System.out.println("NODE: " + node.getNodeType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Node
|
||||
get_subnode (String name, Node node)
|
||||
{
|
||||
if (node.getNodeType() != Node.ELEMENT_NODE)
|
||||
{
|
||||
System.err.println("Error: Search node not of element type");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!node.hasChildNodes()) return null;
|
||||
|
||||
NodeList list = node.getChildNodes();
|
||||
for (int i=0; i < list.getLength(); i++)
|
||||
{
|
||||
Node subnode = list.item(i);
|
||||
if (subnode.getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if (subnode.getNodeName() == name) return subnode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String
|
||||
get_text (Node node)
|
||||
{
|
||||
StringBuffer result = new StringBuffer();
|
||||
if (node==null || !node.hasChildNodes()) return "";
|
||||
|
||||
NodeList list = node.getChildNodes();
|
||||
for (int i=0; i < list.getLength(); i++)
|
||||
{
|
||||
Node subnode = list.item(i);
|
||||
if (subnode.getNodeType() == Node.TEXT_NODE)
|
||||
{
|
||||
result.append(subnode.getNodeValue());
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static void
|
||||
parse (PartitionManager pm, VirtualDiskManager vdm, Document document)
|
||||
{
|
||||
if (document == null) return;
|
||||
|
||||
/* parse partitions */
|
||||
parse_partitions(pm, document.getElementsByTagName("partition"));
|
||||
|
||||
/* parse virtual disks */
|
||||
NodeList list = document.getElementsByTagName("virtual_disk");
|
||||
for (int i = 0; i < list.getLength(); i++)
|
||||
{
|
||||
Node subnode = list.item(i);
|
||||
String parent = subnode.getParentNode().getNodeName();
|
||||
VirtualDisk vd = parse_virtual_disk(subnode);
|
||||
|
||||
if (parent.equals("free"))
|
||||
{
|
||||
vdm.add_free(vd);
|
||||
}
|
||||
else if (parent.equals("virtual_disks"))
|
||||
{
|
||||
vdm.add_virtual_disk(vd);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println ("XML parse error: unknown parent for virtual_disk "
|
||||
+ "[" + parent + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/* parse virtual block devices */
|
||||
parse_virtual_block_devices(vdm, document.getElementsByTagName("virtual_block_device"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static VirtualDisk
|
||||
parse_virtual_disk(Node node)
|
||||
{
|
||||
VirtualDisk vd;
|
||||
Date date = new Date();
|
||||
NodeList list;
|
||||
|
||||
date.setTime(Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("expiry", node))));
|
||||
vd = new VirtualDisk(XMLHelper.get_text(XMLHelper.get_subnode("name", node)),
|
||||
date,
|
||||
XMLHelper.get_text(XMLHelper.get_subnode("key", node)));
|
||||
|
||||
list = XMLHelper.get_subnode("extents", node).getChildNodes();
|
||||
for (int i = 0; i < list.getLength(); i++)
|
||||
{
|
||||
Node enode = list.item(i);
|
||||
|
||||
if (enode.getNodeType() == Node.ELEMENT_NODE &&
|
||||
enode.getNodeName().equals("extent"))
|
||||
{
|
||||
Extent extent = new Extent();
|
||||
|
||||
extent.disk = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("disk", enode)));
|
||||
extent.size = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("size", enode)));
|
||||
extent.offset = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("offset", enode)));
|
||||
vd.add_extent(extent);
|
||||
}
|
||||
}
|
||||
|
||||
return vd;
|
||||
}
|
||||
|
||||
static void
|
||||
parse_partitions (PartitionManager pm, NodeList nl)
|
||||
{
|
||||
Partition partition;
|
||||
|
||||
for (int loop = 0; loop < nl.getLength(); loop++)
|
||||
{
|
||||
Node node = nl.item(loop);
|
||||
|
||||
partition = new Partition();
|
||||
partition.major = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("major", node)));
|
||||
partition.minor = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("minor", node)));
|
||||
partition.blocks = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("blocks", node)));
|
||||
partition.start_sect = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("start_sect", node)));
|
||||
partition.nr_sects = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("nr_sects", node)));
|
||||
partition.name = XMLHelper.get_text(XMLHelper.get_subnode("name", node));
|
||||
|
||||
pm.add_xeno_partition(partition);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
parse_virtual_block_devices (VirtualDiskManager vdm, NodeList nl)
|
||||
{
|
||||
VirtualBlockDevice vbd;
|
||||
|
||||
for (int loop = 0; loop < nl.getLength(); loop++)
|
||||
{
|
||||
Node node = nl.item(loop);
|
||||
|
||||
vdm.create_virtual_block_device(XMLHelper.get_text(XMLHelper.get_subnode("key", node)),
|
||||
Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("domain", node))),
|
||||
Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("vbdnum", node))),
|
||||
XMLHelper.get_text(XMLHelper.get_subnode("mode", node)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# development only
|
||||
export ANT_HOME=/anfs/scratch/boulderdash/ach61/jakarta-ant-1.5.1
|
||||
export JAVA_HOME=/anfs/scratch/labyrinth/ach61/java-1.4.1
|
||||
export PATH=${ANT_HOME}/bin:${JAVA_HOME}/bin:${PATH}
|
||||
|
||||
# runtime
|
||||
export JAVA_HOME=../jre-1.4.1
|
||||
export PATH=${JAVA_HOME}/bin:${PATH}
|
||||
if [ -f /var/lib/xen/vdstate.xml ]
|
||||
then
|
||||
cp /var/lib/xen/vdstate.xml /var/lib/xen/vdstate.old.xml
|
||||
fi
|
||||
|
||||
java -jar vdmanager.jar $*
|
||||