mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
bitkeeper revision 1.198 (3eb067ccnZGiSrE___bi3AnWpeUuIw)
allow creation of vbd directly from disk partition error checking to ensure that /proc/partitions is from a xeno machine
This commit is contained in:
1 parent
788185b57d
commit
12e2968e45
4 files changed
+92
-9
No files matched your search
@@ -252,6 +252,45 @@ Parser
|
||||
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 =
|
||||
@@ -269,6 +308,7 @@ Parser
|
||||
commands[4]);
|
||||
}
|
||||
|
||||
/* display commandline to user */
|
||||
{
|
||||
vd = vdm.get_virtual_disk_key(commands[1]);
|
||||
System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
|
||||
@@ -280,7 +320,7 @@ Parser
|
||||
{
|
||||
if (commands.length < 3)
|
||||
{
|
||||
System.out.println ("vbdcreate <domain number> <vbd number>");
|
||||
System.out.println ("vbddelete <domain number> <vbd number>");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ package uk.ac.cam.cl.xeno.vdmanager;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class
|
||||
PartitionManager
|
||||
@@ -14,6 +15,9 @@ 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
|
||||
@@ -32,6 +36,14 @@ PartitionManager
|
||||
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();
|
||||
@@ -58,6 +70,21 @@ PartitionManager
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -133,6 +133,22 @@ VirtualDisk
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -14,14 +14,14 @@ import java.io.PrintWriter;
|
||||
public class
|
||||
VirtualDiskManager
|
||||
{
|
||||
VirtualDisk free;
|
||||
VirtualDisk free_disk;
|
||||
Vector virtual_disks;
|
||||
Hashtable virtual_block_devices;
|
||||
Hashtable key_hash;
|
||||
|
||||
VirtualDiskManager ()
|
||||
{
|
||||
free = new VirtualDisk("free");
|
||||
free_disk = new VirtualDisk("free");
|
||||
|
||||
virtual_disks = new Vector(10,5);
|
||||
flush_virtual_block_devices();
|
||||
@@ -37,7 +37,7 @@ VirtualDiskManager
|
||||
public void
|
||||
add_xeno_partition (Partition partition, long size)
|
||||
{
|
||||
free.add_new_partition (partition, size);
|
||||
free_disk.add_new_partition (partition, size);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ VirtualDiskManager
|
||||
{
|
||||
Extent e;
|
||||
|
||||
e = free.remove_extent();
|
||||
e = free_disk.remove_extent();
|
||||
if (e == null)
|
||||
{
|
||||
return null;
|
||||
@@ -88,7 +88,7 @@ VirtualDiskManager
|
||||
e = vd.remove_extent();
|
||||
while (e != null)
|
||||
{
|
||||
free.add_extent(e);
|
||||
free_disk.add_extent(e);
|
||||
e = vd.remove_extent();
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ VirtualDiskManager
|
||||
public void
|
||||
add_free (VirtualDisk vd)
|
||||
{
|
||||
free = vd;
|
||||
free_disk = vd;
|
||||
}
|
||||
|
||||
public String
|
||||
@@ -218,7 +218,7 @@ VirtualDiskManager
|
||||
public String
|
||||
dump_free()
|
||||
{
|
||||
return(free.dump(true, false));
|
||||
return(free_disk.dump(true, false));
|
||||
}
|
||||
|
||||
public String
|
||||
@@ -265,7 +265,7 @@ VirtualDiskManager
|
||||
dump_xml(PrintWriter out)
|
||||
{
|
||||
out.println("<free>");
|
||||
free.dump_xml(out);
|
||||
free_disk.dump_xml(out);
|
||||
out.println("</free>");
|
||||
out.println("<virtual_disks>");
|
||||
for (int i = 0; i < virtual_disks.size(); i++)
|
||||
|
||||