ia64/xen-unstable
changeset 531:61f612c81ec5
bitkeeper revision 1.289.1.2 (3f0aa5f5RZ04FODq-SZaRpQyRs03AA)
Refactoring partially complete, code reformatting, cleanups, documentation
Fix disk number handling so that it masks the correct number of bits.
Refactoring partially complete, code reformatting, cleanups, documentation
Fix disk number handling so that it masks the correct number of bits.
line diff
1.1 --- a/tools/control/src/org/xenoserver/cmdline/CommandParser.java Mon Jul 07 15:21:46 2003 +0000 1.2 +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java Tue Jul 08 11:07:33 2003 +0000 1.3 @@ -89,10 +89,10 @@ public abstract class CommandParser { 1.4 } 1.5 1.6 protected void loadState() { 1.7 - XML.load_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_INPUT_FILE ); 1.8 + XML.loadState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_INPUT_FILE ); 1.9 } 1.10 1.11 protected void saveState() { 1.12 - XML.dump_state( PartitionManager.it, VirtualDiskManager.it, Settings.STATE_OUTPUT_FILE ); 1.13 + XML.saveState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_OUTPUT_FILE ); 1.14 } 1.15 }
2.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java Mon Jul 07 15:21:46 2003 +0000 2.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsAdd.java Tue Jul 08 11:07:33 2003 +0000 2.3 @@ -19,19 +19,19 @@ public class ParsePartitionsAdd extends 2.4 if (partition_name.equals("")) 2.5 throw new ParseFailedException("Expected -p<partition_name>"); 2.6 2.7 - long chunksize = Library.parse_size( size ) / Settings.SECTOR_SIZE; 2.8 + long chunksize = Library.parseSize( size ) / Settings.SECTOR_SIZE; 2.9 if ( chunksize <= 0 ) 2.10 throw new CommandFailedException("Chunk size " + size + " is smaller than sector size."); 2.11 2.12 // Initialise the partition manager and look up the partition 2.13 loadState(); 2.14 - Partition p = PartitionManager.it.get_partition(partition_name); 2.15 + Partition p = PartitionManager.IT.getPartition(partition_name); 2.16 2.17 if ( p == null ) 2.18 throw new CommandFailedException("Partition " + partition_name + " does not exist."); 2.19 2.20 // Check if this partition belongs to the VDM 2.21 - if (p.getIsXeno() && !force) 2.22 + if (p.isXeno() && !force) 2.23 throw new CommandFailedException("Refusing to add partition as it is already allocated to the virtual disk manager. Use -f if you are sure."); 2.24 2.25 String output = new CommandPartitionAdd( p, chunksize ).execute();
3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java Mon Jul 07 15:21:46 2003 +0000 3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePartitionsList.java Tue Jul 08 11:07:33 2003 +0000 3.3 @@ -12,26 +12,26 @@ import org.xenoserver.control.PartitionM 3.4 public class ParsePartitionsList extends CommandParser { 3.5 public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { 3.6 loadState(); 3.7 - Iterator i = PartitionManager.it.iterator(); 3.8 + Iterator i = PartitionManager.IT.iterator(); 3.9 int idx = 1; 3.10 System.out.println( " maj:min " + " blocks " + "start sect " + 3.11 " num sects " + "name" ); 3.12 while (i.hasNext()) { 3.13 Partition p = (Partition) i.next(); 3.14 3.15 - if (p.getIsXeno()) { 3.16 + if (p.isXeno()) { 3.17 System.out.print("[ "); 3.18 } else { 3.19 System.out.print(" "); 3.20 } 3.21 - System.out.print(Library.format(idx++, 2, 0) + " "); 3.22 - System.out.print(Library.format(p.getMajor(),3,0) + ":" + 3.23 - Library.format(p.getMinor(),3,1) + " " + 3.24 - Library.format(p.getBlocks(),10,0) + " " + 3.25 - Library.format(p.getStartSect(),10,0) + " " + 3.26 - Library.format(p.getNumSects(),10,0) + " " + 3.27 - Library.format(p.getName(),7,1)); 3.28 - if (p.getIsXeno()) { 3.29 + System.out.print(Library.format(idx++, 2, false) + " "); 3.30 + System.out.print(Library.format(p.getMajor(),3,false) + ":" + 3.31 + Library.format(p.getMinor(),3,true) + " " + 3.32 + Library.format(p.getBlocks(),10,false) + " " + 3.33 + Library.format(p.getStartSect(),10,false) + " " + 3.34 + Library.format(p.getNumSects(),10,false) + " " + 3.35 + Library.format(p.getName(),7,true)); 3.36 + if (p.isXeno()) { 3.37 System.out.println("]"); 3.38 } else { 3.39 System.out.println();
4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Mon Jul 07 15:21:46 2003 +0000 4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Tue Jul 08 11:07:33 2003 +0000 4.3 @@ -30,13 +30,13 @@ public class ParsePhysicalGrant extends 4.4 4.5 // Initialise the partition manager and look up the partition 4.6 loadState(); 4.7 - Partition p = PartitionManager.it.get_partition(partition_name); 4.8 + Partition p = PartitionManager.IT.getPartition(partition_name); 4.9 4.10 if ( p == null ) 4.11 throw new CommandFailedException("Partition " + partition_name + " does not exist."); 4.12 4.13 // Check if this partition belongs to the VDM 4.14 - if (p.getIsXeno() && !force) 4.15 + if (p.isXeno() && !force) 4.16 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."); 4.17 4.18 // Convert the partition into a physical extent
5.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java Mon Jul 07 15:21:46 2003 +0000 5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java Tue Jul 08 11:07:33 2003 +0000 5.3 @@ -35,23 +35,23 @@ public class ParsePhysicalList extends C 5.4 Entry entry = (Entry) i.next(); 5.5 Extent e = (Extent) entry.getKey(); 5.6 String mode = entry.getValue().toString(); 5.7 - Partition p = PartitionManager.it.get_partition( e ); 5.8 + Partition p = PartitionManager.IT.getPartition( e ); 5.9 if ( p != null ) { 5.10 - System.out.println(Library.format(p.getMajor(),3,0) + ":" + 5.11 - Library.format(p.getMinor(),3,1) + " " + 5.12 - Library.format(p.getBlocks(),10,0) + " " + 5.13 - Library.format(p.getStartSect(),10,0) + " " + 5.14 - Library.format(p.getNumSects(),10,0) + " " + 5.15 - Library.format(p.getName(),7,1) + " " + 5.16 - Library.format(mode,2,1)); 5.17 + System.out.println(Library.format(p.getMajor(),3,false) + ":" + 5.18 + Library.format(p.getMinor(),3,true) + " " + 5.19 + Library.format(p.getBlocks(),10,false) + " " + 5.20 + Library.format(p.getStartSect(),10,false) + " " + 5.21 + Library.format(p.getNumSects(),10,false) + " " + 5.22 + Library.format(p.getName(),7,true) + " " + 5.23 + Library.format(mode,2,true)); 5.24 } else { 5.25 - System.out.println(Library.format(e.getMajor(),3,0) + ":" + 5.26 - Library.format(e.getMinor(),3,1) + " " + 5.27 + System.out.println(Library.format(e.getMajor(),3,false) + ":" + 5.28 + Library.format(e.getMinor(),3,true) + " " + 5.29 " " + " " + 5.30 - Library.format(e.getOffset(),10,0) + " " + 5.31 - Library.format(e.getSize(),10,0) + " " + 5.32 + Library.format(e.getOffset(),10,false) + " " + 5.33 + Library.format(e.getSize(),10,false) + " " + 5.34 " " + " " + 5.35 - Library.format(mode,2,1)); 5.36 + Library.format(mode,2,true)); 5.37 } 5.38 } 5.39 }
6.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Mon Jul 07 15:21:46 2003 +0000 6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Tue Jul 08 11:07:33 2003 +0000 6.3 @@ -21,7 +21,7 @@ public class ParsePhysicalRevoke extends 6.4 6.5 // Initialise the partition manager and look up the partition 6.6 loadState(); 6.7 - Partition p = PartitionManager.it.get_partition(partition_name); 6.8 + Partition p = PartitionManager.IT.getPartition(partition_name); 6.9 6.10 if ( p == null ) 6.11 throw new CommandFailedException("Partition " + partition_name + " does not exist.");
7.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java Mon Jul 07 15:21:46 2003 +0000 7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java Tue Jul 08 11:07:33 2003 +0000 7.3 @@ -25,7 +25,7 @@ public class ParseVdCreate extends Comma 7.4 else 7.5 expiry = new Date(Date.parse(expiry_s)); 7.6 7.7 - long size = Library.parse_size(size_s); 7.8 + long size = Library.parseSize(size_s); 7.9 7.10 loadState(); 7.11 String output = new CommandVdCreate(name,size/Settings.SECTOR_SIZE,expiry).execute();
8.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java Mon Jul 07 15:21:46 2003 +0000 8.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java Tue Jul 08 11:07:33 2003 +0000 8.3 @@ -15,7 +15,7 @@ public class ParseVdDelete extends Comma 8.4 throw new ParseFailedException("Expected -k<key>"); 8.5 8.6 loadState(); 8.7 - if ( VirtualDiskManager.it.get_virtual_disk_key(vd_key) == null ) 8.8 + if ( VirtualDiskManager.IT.getVirtualDisk(vd_key) == null ) 8.9 throw new CommandFailedException("Virtual disk " + vd_key + " does not exist"); 8.10 8.11 String output = new CommandVdDelete(vd_key).execute();
9.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java Mon Jul 07 15:21:46 2003 +0000 9.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdFree.java Tue Jul 08 11:07:33 2003 +0000 9.3 @@ -16,17 +16,17 @@ public class ParseVdFree extends Command 9.4 boolean verbose = getFlagParameter(args, 'v'); 9.5 9.6 loadState(); 9.7 - VirtualDisk free = VirtualDiskManager.it.getFreeVirtualDisk(); 9.8 + VirtualDisk free = VirtualDiskManager.IT.getFreeDisk(); 9.9 System.out.println( "Free disk has " + free.getExtentCount() + " extents totalling " 9.10 - + Library.format_size(free.getSize()*Settings.SECTOR_SIZE,8,1) ); 9.11 + + Library.formatSize(free.getSize()*Settings.SECTOR_SIZE,8,true) ); 9.12 if ( verbose ) { 9.13 - Iterator i = free.iterator(); 9.14 + Iterator i = free.extents(); 9.15 System.out.println(" disk offset size"); 9.16 while (i.hasNext()) { 9.17 Extent e = (Extent) i.next(); 9.18 - System.out.println( Library.format(e.getDisk(), 6, 0) + " " 9.19 - + Library.format(e.getOffset(), 12, 0) + " " 9.20 - + Library.format(e.getSize(), 12, 0) ); 9.21 + System.out.println( Library.format(e.getDisk(), 6, false) + " " 9.22 + + Library.format(e.getOffset(), 12, false) + " " 9.23 + + Library.format(e.getSize(), 12, false) ); 9.24 } 9.25 } 9.26 }
10.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java Mon Jul 07 15:21:46 2003 +0000 10.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVdShow.java Tue Jul 08 11:07:33 2003 +0000 10.3 @@ -13,41 +13,42 @@ import org.xenoserver.control.VirtualDis 10.4 10.5 public class ParseVdShow extends CommandParser { 10.6 public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException { 10.7 - int vd_num = getIntParameter(args,'n',-1); 10.8 + String key = getStringParameter(args,'k',""); 10.9 10.10 loadState(); 10.11 10.12 - if ( vd_num < 0 ) { 10.13 - System.out.println("num key expiry name size"); 10.14 - for (int i=0;i<VirtualDiskManager.it.getVirtualDiskCount();i++) { 10.15 - VirtualDisk vd = VirtualDiskManager.it.getVirtualDisk(i); 10.16 - System.out.print( Library.format(i,3,0) + " " + vd.getKey() + " " ); 10.17 + if ( key.equals("") ) { 10.18 + System.out.println("key expiry name size"); 10.19 + Iterator i = VirtualDiskManager.IT.getVirtualDisks(); 10.20 + while ( i.hasNext() ) { 10.21 + VirtualDisk vd = (VirtualDisk) i.next(); 10.22 + System.out.print( vd.getKey() + " " ); 10.23 if ( vd.getExpiry() != null ) 10.24 System.out.print( vd.getExpiry().toString() ); 10.25 else 10.26 System.out.print( " " ); 10.27 - System.out.println( " " + Library.format(vd.getName(),16,1) + " " 10.28 - + Library.format_size(vd.getSize()*Settings.SECTOR_SIZE,8,0) ); 10.29 + System.out.println( " " + Library.format(vd.getName(),16,true) + " " 10.30 + + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) ); 10.31 } 10.32 } else { 10.33 - VirtualDisk vd = VirtualDiskManager.it.getVirtualDisk(vd_num); 10.34 + VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); 10.35 if ( vd == null ) 10.36 - throw new CommandFailedException("There is no virtual disk " + vd_num ); 10.37 + throw new CommandFailedException("There is no virtual disk " + key ); 10.38 10.39 System.out.println(" name: " + vd.getName()); 10.40 System.out.println(" key: " + vd.getKey()); 10.41 - System.out.println(" size: " + Library.format_size(vd.getSize()*Settings.SECTOR_SIZE,8,1)); 10.42 + System.out.println(" size: " + Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,true)); 10.43 if ( vd.getExpiry() != null ) 10.44 System.out.println("expiry: " + vd.getExpiry()); 10.45 System.out.println(); 10.46 10.47 - Iterator i = vd.iterator(); 10.48 + Iterator i = vd.extents(); 10.49 System.out.println(" disk offset size"); 10.50 while (i.hasNext()) { 10.51 Extent e = (Extent) i.next(); 10.52 - System.out.println( Library.format(e.getDisk(), 6, 0) + " " 10.53 - + Library.format(e.getOffset(), 12, 0) + " " 10.54 - + Library.format(e.getSize(), 12, 0) ); 10.55 + System.out.println( Library.format(e.getDisk(), 6, false) + " " 10.56 + + Library.format(e.getOffset(), 12, false) + " " 10.57 + + Library.format(e.getSize(), 12, false) ); 10.58 } 10.59 } 10.60 }
11.1 --- a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java Mon Jul 07 15:21:46 2003 +0000 11.2 +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java Tue Jul 08 11:07:33 2003 +0000 11.3 @@ -15,8 +15,8 @@ public class CommandPartitionAdd extends 11.4 } 11.5 11.6 public String execute() throws CommandFailedException { 11.7 - VirtualDiskManager.it.add_xeno_partition(partition,chunksize); 11.8 - PartitionManager.it.add_xeno_partition(partition); 11.9 + VirtualDiskManager.IT.addPartition(partition,chunksize); 11.10 + PartitionManager.IT.addXenoPartition(partition); 11.11 return "Added partition " + partition.getName(); 11.12 } 11.13 }
12.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Mon Jul 07 15:21:46 2003 +0000 12.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Tue Jul 08 11:07:33 2003 +0000 12.3 @@ -12,86 +12,95 @@ import java.util.StringTokenizer; 12.4 * to modes. 12.5 */ 12.6 public class CommandPhysicalList extends Command { 12.7 - private int domain_id; 12.8 - private Defaults d; 12.9 - private Map map = new HashMap(); 12.10 + private int domain_id; 12.11 + private Defaults d; 12.12 + private Map map = new HashMap(); 12.13 + 12.14 + /** 12.15 + * Constructor for CommandDomainList. 12.16 + * @param d Defaults object to use. 12.17 + */ 12.18 + public CommandPhysicalList(Defaults d, int domain_id) { 12.19 + this.d = d; 12.20 + this.domain_id = domain_id; 12.21 + } 12.22 12.23 - /** 12.24 - * Constructor for CommandDomainList. 12.25 - * @param d Defaults object to use. 12.26 - */ 12.27 - public CommandPhysicalList(Defaults d, int domain_id) { 12.28 - this.d = d; 12.29 - this.domain_id = domain_id; 12.30 - } 12.31 + /** 12.32 + * Retrieves the list of extents. 12.33 + * @return null, call extents() to get the list. 12.34 + */ 12.35 + public String execute() throws CommandFailedException { 12.36 + Runtime r = Runtime.getRuntime(); 12.37 + String outline; 12.38 + BufferedReader in; 12.39 + String output = null; 12.40 + 12.41 + try { 12.42 + Process start_p; 12.43 + String start_cmdarray[] = new String[2]; 12.44 + int start_rc; 12.45 + start_cmdarray[0] = d.XIToolsDir + "xi_phys_probe"; 12.46 + start_cmdarray[1] = Integer.toString(domain_id); 12.47 + 12.48 + if (Settings.TEST) { 12.49 + output = reportCommand(start_cmdarray); 12.50 + } else { 12.51 + start_p = r.exec(start_cmdarray); 12.52 + start_rc = start_p.waitFor(); 12.53 + if (start_rc != 0) { 12.54 + throw CommandFailedException.XICommandFailed( 12.55 + "Could not get extent list", 12.56 + start_cmdarray); 12.57 + } 12.58 12.59 - /** 12.60 - * Retrieves the list of extents. 12.61 - * @return null, call extents() to get the list. 12.62 - */ 12.63 - public String execute() throws CommandFailedException { 12.64 - Runtime r = Runtime.getRuntime(); 12.65 - String outline; 12.66 - BufferedReader in; 12.67 - String output = null; 12.68 + in = 12.69 + new BufferedReader( 12.70 + new InputStreamReader(start_p.getInputStream())); 12.71 12.72 - try { 12.73 - Process start_p; 12.74 - String start_cmdarray[] = new String[2]; 12.75 - int start_rc; 12.76 - start_cmdarray[0] = d.XIToolsDir + "xi_phys_probe"; 12.77 - start_cmdarray[1] = Integer.toString( domain_id ); 12.78 + outline = in.readLine(); 12.79 + while (outline != null) { 12.80 + int disk = -1; 12.81 + long offset = -1; 12.82 + long size = -1; 12.83 + 12.84 + StringTokenizer st = new StringTokenizer(outline); 12.85 + if (st.hasMoreTokens()) { 12.86 + disk = Short.parseShort(st.nextToken(), 16); 12.87 + } 12.88 + if (st.hasMoreTokens()) { 12.89 + offset = Long.parseLong(st.nextToken(), 16); 12.90 + } 12.91 + if (st.hasMoreTokens()) { 12.92 + size = Long.parseLong(st.nextToken(), 16); 12.93 + } 12.94 + if (st.hasMoreTokens()) { 12.95 + String mode = st.nextToken(); 12.96 + Extent extent = new Extent(disk,offset,size); 12.97 + if (mode.equals("rw")) 12.98 + map.put(extent, Mode.READ_WRITE); 12.99 + else if (mode.equals("r")) 12.100 + map.put(extent, Mode.READ_ONLY); 12.101 + else 12.102 + throw new CommandFailedException( 12.103 + "Could not parse access mode " + mode); 12.104 + } 12.105 12.106 - if (Settings.TEST) { 12.107 - output = reportCommand(start_cmdarray); 12.108 - } else { 12.109 - start_p = r.exec(start_cmdarray); 12.110 - start_rc = start_p.waitFor(); 12.111 - if (start_rc != 0) { 12.112 - throw CommandFailedException.XICommandFailed("Could not get extent list", start_cmdarray); 12.113 + outline = in.readLine(); 12.114 + } 12.115 + 12.116 + } 12.117 + } catch (CommandFailedException e) { 12.118 + throw e; 12.119 + } catch (Exception e) { 12.120 + throw new CommandFailedException( 12.121 + "Could not get extent list(" + e + ")", 12.122 + e); 12.123 } 12.124 12.125 - in = 12.126 - new BufferedReader(new InputStreamReader(start_p.getInputStream())); 12.127 - 12.128 - outline = in.readLine(); 12.129 - while (outline != null) { 12.130 - Extent extent = new Extent(); 12.131 - 12.132 - StringTokenizer st = new StringTokenizer(outline); 12.133 - if (st.hasMoreTokens()) { 12.134 - extent.disk = Short.parseShort(st.nextToken(),16); 12.135 - } 12.136 - if (st.hasMoreTokens()) { 12.137 - extent.offset = Long.parseLong(st.nextToken(),16); 12.138 - } 12.139 - if (st.hasMoreTokens()) { 12.140 - extent.size = Long.parseLong(st.nextToken(),16); 12.141 - } 12.142 - if (st.hasMoreTokens()) { 12.143 - String mode = st.nextToken(); 12.144 - if ( mode.equals( "rw" ) ) 12.145 - map.put( extent, Mode.READ_WRITE ); 12.146 - else if ( mode.equals ( "r" ) ) 12.147 - map.put( extent, Mode.READ_ONLY ); 12.148 - else 12.149 - throw new CommandFailedException("Could not parse access mode " + mode); 12.150 - } 12.151 - 12.152 - outline = in.readLine(); 12.153 - } 12.154 - 12.155 - } 12.156 - } catch (CommandFailedException e) { 12.157 - throw e; 12.158 - } catch (Exception e) { 12.159 - throw new CommandFailedException("Could not get extent list(" + e + ")", e); 12.160 + return output; 12.161 } 12.162 12.163 - return output; 12.164 - } 12.165 - 12.166 - public Map extents() { 12.167 - return map; 12.168 - } 12.169 + public Map extents() { 12.170 + return map; 12.171 + } 12.172 }
13.1 --- a/tools/control/src/org/xenoserver/control/CommandVdCreate.java Mon Jul 07 15:21:46 2003 +0000 13.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java Tue Jul 08 11:07:33 2003 +0000 13.3 @@ -20,7 +20,7 @@ public class CommandVdCreate extends Com 13.4 } 13.5 13.6 public String execute() throws CommandFailedException { 13.7 - VirtualDisk vd = VirtualDiskManager.it.create_virtual_disk(name,size,expiry); 13.8 + VirtualDisk vd = VirtualDiskManager.IT.createVirtualDisk(name,size,expiry); 13.9 if ( vd == null ) 13.10 throw new CommandFailedException( "Not enough free space to create disk" ); 13.11 return "Virtual Disk created with key: " + vd.getKey();
14.1 --- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java Mon Jul 07 15:21:46 2003 +0000 14.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java Tue Jul 08 11:07:33 2003 +0000 14.3 @@ -12,7 +12,7 @@ public class CommandVdDelete extends Com 14.4 } 14.5 14.6 public String execute() throws CommandFailedException { 14.7 - VirtualDiskManager.it.delete_virtual_disk(key); 14.8 + VirtualDiskManager.IT.deleteVirtualDisk(key); 14.9 return "Deleted virtual disk " + key; 14.10 } 14.11 }
15.1 --- a/tools/control/src/org/xenoserver/control/CommandVdRefresh.java Mon Jul 07 15:21:46 2003 +0000 15.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdRefresh.java Tue Jul 08 11:07:33 2003 +0000 15.3 @@ -9,7 +9,7 @@ public class CommandVdRefresh extends Co 15.4 /** 15.5 * Constructor for CommandVdRefresh. 15.6 * @param key Key to refresh. 15.7 - * @param expiry New expiry. 15.8 + * @param expiry New expiry (null for no expiry). 15.9 */ 15.10 public CommandVdRefresh(String key, Date expiry) { 15.11 this.key = key; 15.12 @@ -17,7 +17,10 @@ public class CommandVdRefresh extends Co 15.13 } 15.14 15.15 public String execute() throws CommandFailedException { 15.16 - VirtualDiskManager.it.refresh_virtual_disk(key,expiry); 15.17 + VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); 15.18 + if ( vd == null ) 15.19 + throw new CommandFailedException( "No such virtual disk " + key ); 15.20 + vd.refreshExpiry(expiry); 15.21 return "Refreshed virtual disk " + key; 15.22 } 15.23 }
16.1 --- a/tools/control/src/org/xenoserver/control/Extent.java Mon Jul 07 15:21:46 2003 +0000 16.2 +++ b/tools/control/src/org/xenoserver/control/Extent.java Tue Jul 08 11:07:33 2003 +0000 16.3 @@ -5,83 +5,61 @@ 16.4 16.5 package org.xenoserver.control; 16.6 16.7 -public class 16.8 -Extent 16.9 -{ 16.10 - int disk; 16.11 - long offset; /* offset into disk */ 16.12 - long size; /* size of this extent in 512 byte sectors */ 16.13 - 16.14 - public int 16.15 - getDisk() 16.16 - { 16.17 - return disk; 16.18 - } 16.19 - 16.20 - public long 16.21 - getOffset() 16.22 - { 16.23 - return offset; 16.24 - } 16.25 +/** 16.26 + * Represents an extent on physical disk. 16.27 + */ 16.28 +public class Extent { 16.29 + /** Disk number; 16-bit major:minor pair with no partition number. */ 16.30 + private int disk; 16.31 + /** Offset into disk in sectors. */ 16.32 + private long offset; 16.33 + /** Size of extent in sectors. */ 16.34 + private long size; 16.35 16.36 - public long 16.37 - getSize() 16.38 - { 16.39 - return size; 16.40 - } 16.41 - 16.42 - public int 16.43 - getMajor() 16.44 - { 16.45 - return disk >> 8; 16.46 - } 16.47 - 16.48 - public int 16.49 - getMinor() 16.50 - { 16.51 - return disk & 0xFF; 16.52 - } 16.53 - 16.54 - public int hashCode() { 16.55 - final int PRIME = 1000003; 16.56 - int result = 0; 16.57 - result = PRIME * result + disk; 16.58 - result = PRIME * result + (int) (offset >>> 32); 16.59 - result = PRIME * result + (int) (offset & 0xFFFFFFFF); 16.60 - result = PRIME * result + (int) (size >>> 32); 16.61 - result = PRIME * result + (int) (size & 0xFFFFFFFF); 16.62 - 16.63 - return result; 16.64 - } 16.65 - 16.66 - public boolean equals(Object oth) { 16.67 - if (this == oth) { 16.68 - return true; 16.69 + /** 16.70 + * Constructor for Extent. 16.71 + * @param disk Disk number. 16.72 + * @param offset Offset into disk. 16.73 + * @param size Size of extent. 16.74 + */ 16.75 + Extent(int disk, long offset, long size) { 16.76 + this.disk = disk; 16.77 + this.offset = offset; 16.78 + this.size = size; 16.79 } 16.80 16.81 - if (oth == null) { 16.82 - return false; 16.83 + /** 16.84 + * @return Disk number. 16.85 + */ 16.86 + public int getDisk() { 16.87 + return disk; 16.88 } 16.89 16.90 - if (oth.getClass() != getClass()) { 16.91 - return false; 16.92 + /** 16.93 + * @return Offset into disk. 16.94 + */ 16.95 + public long getOffset() { 16.96 + return offset; 16.97 } 16.98 16.99 - Extent other = (Extent) oth; 16.100 - 16.101 - if (this.disk != other.disk) { 16.102 - return false; 16.103 + /** 16.104 + * @return Size of extent. 16.105 + */ 16.106 + public long getSize() { 16.107 + return size; 16.108 } 16.109 16.110 - if (this.offset != other.offset) { 16.111 - return false; 16.112 + /** 16.113 + * @return Major number of disk. 16.114 + */ 16.115 + public int getMajor() { 16.116 + return disk >> 8; 16.117 } 16.118 16.119 - if (this.size != other.size) { 16.120 - return false; 16.121 + /** 16.122 + * @return Minor number of disk, not including partition. 16.123 + */ 16.124 + public int getMinor() { 16.125 + return disk & 0xFF; 16.126 } 16.127 - 16.128 - return true; 16.129 - } 16.130 - 16.131 }
17.1 --- a/tools/control/src/org/xenoserver/control/InetAddressPattern.java Mon Jul 07 15:21:46 2003 +0000 17.2 +++ b/tools/control/src/org/xenoserver/control/InetAddressPattern.java Tue Jul 08 11:07:33 2003 +0000 17.3 @@ -3,58 +3,77 @@ package org.xenoserver.control; 17.4 import java.net.InetAddress; 17.5 import java.net.UnknownHostException; 17.6 17.7 -public class InetAddressPattern 17.8 -{ 17.9 - InetAddress base; 17.10 - boolean addDom; 17.11 - 17.12 - static InetAddressPattern parse (String t) 17.13 - { 17.14 - InetAddressPattern result = new InetAddressPattern (); 17.15 - char[] ca = t.toCharArray (); 17.16 - int len = ca.length; 17.17 +/** 17.18 + * This utility class expands configuration file patterns. 17.19 + */ 17.20 +public class InetAddressPattern { 17.21 + /** The base InetAddress for this pattern. */ 17.22 + private InetAddress base; 17.23 + /** If true, add the domain number to the base address. */ 17.24 + private boolean addDom; 17.25 17.26 - try { 17.27 - if (len == 0) { 17.28 - result.base = null; 17.29 - result.addDom = false; 17.30 - } else if (ca[len - 1] == '+') { 17.31 - result.base = InetAddress.getByName(t.substring(0, len - 1)); 17.32 - result.addDom = true; 17.33 - } else { 17.34 - result.base = InetAddress.getByName(t); 17.35 - result.addDom = false; 17.36 - } 17.37 - } catch (UnknownHostException uhe) { 17.38 - result.base = null; 17.39 - result.addDom = false; 17.40 + /** 17.41 + * Parse a pattern string into an InetAddressPattern. 17.42 + * @param t The pattern string. 17.43 + * @return The parsed pattern object. 17.44 + */ 17.45 + static InetAddressPattern parse(String t) { 17.46 + InetAddressPattern result = new InetAddressPattern(); 17.47 + char[] ca = t.toCharArray(); 17.48 + int len = ca.length; 17.49 + 17.50 + try { 17.51 + if (len == 0) { 17.52 + result.base = null; 17.53 + result.addDom = false; 17.54 + } else if (ca[len - 1] == '+') { 17.55 + result.base = InetAddress.getByName(t.substring(0, len - 1)); 17.56 + result.addDom = true; 17.57 + } else { 17.58 + result.base = InetAddress.getByName(t); 17.59 + result.addDom = false; 17.60 + } 17.61 + } catch (UnknownHostException uhe) { 17.62 + result.base = null; 17.63 + result.addDom = false; 17.64 + } 17.65 + 17.66 + return result; 17.67 } 17.68 17.69 - return result; 17.70 - } 17.71 + /** 17.72 + * Resolve the pattern for the given domain. 17.73 + * @param domain_id The domain ID. 17.74 + * @return The resolved string. 17.75 + */ 17.76 + String resolve(int domain_id) { 17.77 + byte[] b = base.getAddress(); 17.78 + if (addDom) { 17.79 + if (((int) b[3]) + domain_id > 255) { 17.80 + if (((int) b[2]) + domain_id > 255) { 17.81 + if (((int) b[1]) + domain_id > 255) { 17.82 + b[0]++; 17.83 + } 17.84 + b[1]++; 17.85 + } 17.86 + b[2]++; 17.87 + } 17.88 + b[3] += domain_id; 17.89 + } 17.90 + return "" 17.91 + + (b[0] + (b[0] < 0 ? 256 : 0)) 17.92 + + "." 17.93 + + (b[1] + (b[1] < 0 ? 256 : 0)) 17.94 + + "." 17.95 + + (b[2] + (b[2] < 0 ? 256 : 0)) 17.96 + + "." 17.97 + + (b[3] + (b[3] < 0 ? 256 : 0)); 17.98 + } 17.99 17.100 - public String resolve (int domain_id) { 17.101 - byte b[] = base.getAddress (); 17.102 - if (addDom) { 17.103 - if (((int)b[3]) + domain_id > 255) { 17.104 - if (((int)b[2]) + domain_id > 255) { 17.105 - if (((int)b[1]) + domain_id > 255) { 17.106 - b[0] ++; 17.107 - } 17.108 - b[1] ++; 17.109 - } 17.110 - b[2] ++; 17.111 - } 17.112 - b[3] += domain_id; 17.113 + /** 17.114 + * @see java.lang.Object#toString() 17.115 + */ 17.116 + public String toString() { 17.117 + return "[" + base + (addDom ? "+dom_id" : "") + "]"; 17.118 } 17.119 - return "" + 17.120 - (b[0] + (b[0] < 0 ? 256 : 0)) + "." + 17.121 - (b[1] + (b[1] < 0 ? 256 : 0)) + "." + 17.122 - (b[2] + (b[2] < 0 ? 256 : 0)) + "." + 17.123 - (b[3] + (b[3] < 0 ? 256 : 0)); 17.124 - } 17.125 - 17.126 - public String toString () { 17.127 - return "[" + base + (addDom ? "+dom_id" : "") + "]"; 17.128 - } 17.129 }
18.1 --- a/tools/control/src/org/xenoserver/control/Library.java Mon Jul 07 15:21:46 2003 +0000 18.2 +++ b/tools/control/src/org/xenoserver/control/Library.java Tue Jul 08 11:07:33 2003 +0000 18.3 @@ -5,162 +5,144 @@ 18.4 18.5 package org.xenoserver.control; 18.6 18.7 -public class 18.8 -Library 18.9 -{ 18.10 - /* 18.11 - * convert a number to a fixed width string 18.12 - */ 18.13 - public static String 18.14 - format (long input, int width, int prefix) 18.15 - { 18.16 - String sss = Long.toString(input); 18.17 - String space = " "; 18.18 +/** 18.19 + * Library functions. 18.20 + */ 18.21 +public class Library { 18.22 + /** 18.23 + * Convert a number to a fixed width string. 18.24 + * @param input The number to convert. 18.25 + * @param width The width desired. 18.26 + * @param leftAlign True to left-align the number. 18.27 + * @return The formatted string. 18.28 + */ 18.29 + public static String format(long input, int width, boolean leftAlign) { 18.30 + String sss = Long.toString(input); 18.31 + String space = " "; 18.32 18.33 - if (width < sss.length()) 18.34 - { 18.35 - width = sss.length(); 18.36 + if (width < sss.length()) { 18.37 + width = sss.length(); 18.38 + } 18.39 + 18.40 + if (leftAlign) { 18.41 + return sss + space.substring(0, width - sss.length()); 18.42 + } else { 18.43 + return space.substring(0, width - sss.length()) + sss; 18.44 + } 18.45 } 18.46 18.47 - if (prefix == 0) 18.48 - { 18.49 - return space.substring(0, width - sss.length()) + sss; 18.50 - } 18.51 - else 18.52 - { 18.53 - return sss + space.substring(0, width - sss.length()); 18.54 - } 18.55 - } 18.56 - 18.57 - /* 18.58 - * convert a string to a fixed width string 18.59 - */ 18.60 - public static String 18.61 - format (String input, int width, int prefix) 18.62 - { 18.63 - String space = " "; 18.64 - 18.65 - if (width < input.length()) 18.66 - { 18.67 - width = input.length(); 18.68 - } 18.69 + /** 18.70 + * Convert a string to a fixed-width string. 18.71 + * @param input Input string. 18.72 + * @param width Width desired. 18.73 + * @param leftAlign True to left-align the string. 18.74 + * @return The formatted string. 18.75 + */ 18.76 + public static String format(String input, int width, boolean leftAlign) { 18.77 + String space = " "; 18.78 18.79 - if (prefix == 0) 18.80 - { 18.81 - return space.substring(0, width - input.length()) + input; 18.82 - } 18.83 - else 18.84 - { 18.85 - return input + space.substring(0, width - input.length()); 18.86 - } 18.87 - } 18.88 + if (width < input.length()) { 18.89 + width = input.length(); 18.90 + } 18.91 18.92 - /* 18.93 - * convert a number (string format) into 18.94 - * the corresponding integer value. 18.95 - */ 18.96 - public static long 18.97 - parse_size(String size) 18.98 - { 18.99 - String substring = size; 18.100 - int suffix = 1; 18.101 - long value = 0; 18.102 - 18.103 - if (size == null) 18.104 - { 18.105 - return 0; 18.106 + if (leftAlign) { 18.107 + return input + space.substring(0, width - input.length()); 18.108 + } else { 18.109 + return space.substring(0, width - input.length()) + input; 18.110 + } 18.111 } 18.112 18.113 - if ((substring = check(size, 'm')) != null) 18.114 - { 18.115 - suffix = 1024 * 1024; 18.116 - } 18.117 - else if ((substring = check(size, 'M')) != null) 18.118 - { 18.119 - suffix = 1024 * 1024; 18.120 - } 18.121 - else if ((substring = check(size, 'k')) != null) 18.122 - { 18.123 - suffix = 1024; 18.124 - } 18.125 - else if ((substring = check(size, 'K')) != null) 18.126 - { 18.127 - suffix = 1024; 18.128 - } 18.129 - else if ((substring = check(size, 'g')) != null) 18.130 - { 18.131 - suffix = 1024 * 1024 * 1024; 18.132 - } 18.133 - else if ((substring = check(size, 'G')) != null) 18.134 - { 18.135 - suffix = 1024 * 1024 * 1024; 18.136 - } 18.137 - else 18.138 - { 18.139 - substring = size; 18.140 - } 18.141 + /** 18.142 + * Parse a size which may have a k/m/g suffix into a number. 18.143 + * @param size The size string to parse. 18.144 + * @return The equivalent number. 18.145 + */ 18.146 + public static long parseSize(String size) { 18.147 + String substring = size; 18.148 + int suffix = 1; 18.149 + long value = 0; 18.150 + 18.151 + if (size == null) { 18.152 + return 0; 18.153 + } 18.154 18.155 - try 18.156 - { 18.157 - value = Long.decode(substring).longValue() * suffix; 18.158 - } 18.159 - catch (NumberFormatException e) 18.160 - { 18.161 - value = 0; 18.162 + if ((substring = check(size, 'm')) != null) { 18.163 + suffix = 1024 * 1024; 18.164 + } else if ((substring = check(size, 'M')) != null) { 18.165 + suffix = 1024 * 1024; 18.166 + } else if ((substring = check(size, 'k')) != null) { 18.167 + suffix = 1024; 18.168 + } else if ((substring = check(size, 'K')) != null) { 18.169 + suffix = 1024; 18.170 + } else if ((substring = check(size, 'g')) != null) { 18.171 + suffix = 1024 * 1024 * 1024; 18.172 + } else if ((substring = check(size, 'G')) != null) { 18.173 + suffix = 1024 * 1024 * 1024; 18.174 + } else { 18.175 + substring = size; 18.176 + } 18.177 + 18.178 + try { 18.179 + value = Long.decode(substring).longValue() * suffix; 18.180 + } catch (NumberFormatException e) { 18.181 + value = 0; 18.182 + } 18.183 + 18.184 + return value; 18.185 } 18.186 18.187 - return value; 18.188 - } 18.189 - 18.190 - public static String 18.191 - check(String size, char suffix) 18.192 - { 18.193 - int index = size.indexOf(suffix); 18.194 + /** 18.195 + * Check if the given size has the specified suffix. 18.196 + * @param size Size string. 18.197 + * @param suffix Test suffix. 18.198 + * @return Number part of string, or null if suffix does not match. 18.199 + */ 18.200 + private static String check(String size, char suffix) { 18.201 + int index = size.indexOf(suffix); 18.202 18.203 - if (index != -1) 18.204 - { 18.205 - return size.substring(0, index); 18.206 - } 18.207 - else 18.208 - { 18.209 - return null; 18.210 + if (index != -1) { 18.211 + return size.substring(0, index); 18.212 + } else { 18.213 + return null; 18.214 + } 18.215 } 18.216 - } 18.217 - 18.218 - /** 18.219 - * Formats a number of bytes in whichever way makes most sense based 18.220 - * on magnitude and width. 18.221 - * 18.222 - * @param size Number of bytes. 18.223 - * @param width Width of field - at least 5, plz. 18.224 - * @param prefix Set to 1 for left justify 18.225 - * @return The formatted string. 18.226 - */ 18.227 - public static String format_size(long size,int width,int prefix) { 18.228 - char[] suffixes = { ' ', 'k', 'M', 'G' }; 18.229 - int suffix = 0; 18.230 - long before = size; 18.231 - float after = 0; 18.232 - 18.233 - while ( before > 10000 ) { 18.234 - after = ((float)(before % 1024)) / 1024; 18.235 - before /= 1024; 18.236 - suffix++; 18.237 + 18.238 + /** 18.239 + * Formats a number of bytes in whichever way makes most sense based 18.240 + * on magnitude and width. 18.241 + * 18.242 + * @param size Number of bytes. 18.243 + * @param width Width of field - at least 5, plz. 18.244 + * @param leftAlign True for left-align. 18.245 + * @return The formatted string. 18.246 + */ 18.247 + public static String formatSize(long size, int width, boolean leftAlign) { 18.248 + char[] suffixes = { ' ', 'k', 'M', 'G' }; 18.249 + int suffix = 0; 18.250 + long before = size; 18.251 + float after = 0; 18.252 + 18.253 + while (before > 10000) { 18.254 + after = ((float) (before % 1024)) / 1024; 18.255 + before /= 1024; 18.256 + suffix++; 18.257 + } 18.258 + 18.259 + StringBuffer num = new StringBuffer(width); 18.260 + num.append(Long.toString(before)); 18.261 + if (after != 0) { 18.262 + int space = width - num.length() - 2; 18.263 + if (space > 0) { 18.264 + num.append('.'); 18.265 + if (space > 3) { 18.266 + space = 3; 18.267 + } 18.268 + num.append( 18.269 + Integer.toString((int) (after * Math.pow(10, space)))); 18.270 + } 18.271 + } 18.272 + num.append(suffixes[suffix]); 18.273 + 18.274 + return format(num.toString(), width, leftAlign); 18.275 } 18.276 - 18.277 - StringBuffer num = new StringBuffer(width); 18.278 - num.append( Long.toString( before ) ); 18.279 - if ( after != 0 ) { 18.280 - int space = width - num.length() - 2; 18.281 - if ( space > 0 ) { 18.282 - num.append( '.' ); 18.283 - if ( space > 3 ) 18.284 - space = 3; 18.285 - num.append( Integer.toString( (int) (after * Math.pow(10,space)))); 18.286 - } 18.287 - } 18.288 - num.append( suffixes[suffix] ); 18.289 - 18.290 - return format(num.toString(),width,prefix); 18.291 - } 18.292 }
19.1 --- a/tools/control/src/org/xenoserver/control/Mode.java Mon Jul 07 15:21:46 2003 +0000 19.2 +++ b/tools/control/src/org/xenoserver/control/Mode.java Tue Jul 08 11:07:33 2003 +0000 19.3 @@ -7,16 +7,30 @@ 19.4 19.5 package org.xenoserver.control; 19.6 19.7 -public class 19.8 -Mode 19.9 -{ 19.10 - private final String name; 19.11 - 19.12 - private Mode(String name) { this.name = name; } 19.13 +/** 19.14 + * Enumeration to represent an access mode. 19.15 + */ 19.16 +public class Mode { 19.17 + /** name of this mode */ 19.18 + private final String name; 19.19 19.20 - public String toString() { return name; } 19.21 + /** 19.22 + * Construct a mode 19.23 + * @param name Name to use. 19.24 + */ 19.25 + private Mode(String name) { 19.26 + this.name = name; 19.27 + } 19.28 19.29 - public static final Mode READ_ONLY = new Mode("ro"); 19.30 - public static final Mode READ_WRITE = new Mode("rw"); 19.31 + /** 19.32 + * @see java.lang.Object#toString() 19.33 + */ 19.34 + public String toString() { 19.35 + return name; 19.36 + } 19.37 + 19.38 + /** Single read-only mode instance. */ 19.39 + public static final Mode READ_ONLY = new Mode("ro"); 19.40 + /** Single read-write mode instance. */ 19.41 + public static final Mode READ_WRITE = new Mode("rw"); 19.42 } 19.43 -
20.1 --- a/tools/control/src/org/xenoserver/control/Partition.java Mon Jul 07 15:21:46 2003 +0000 20.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java Tue Jul 08 11:07:33 2003 +0000 20.3 @@ -7,184 +7,179 @@ package org.xenoserver.control; 20.4 20.5 import java.io.PrintWriter; 20.6 20.7 -public class 20.8 -Partition 20.9 -{ 20.10 - int major; 20.11 - int minor; 20.12 - long blocks; 20.13 - long start_sect; 20.14 - long nr_sects; 20.15 - String name; 20.16 - boolean xeno; 20.17 - 20.18 - Partition 20.19 - duplicate () 20.20 - { 20.21 - Partition p = new Partition(); 20.22 +/** 20.23 + * Represents a single real partition. 20.24 + */ 20.25 +public class Partition { 20.26 + /** Major device number as seen by Linux. */ 20.27 + private int major; 20.28 + /** Minor device number as seen by Linux. */ 20.29 + private int minor; 20.30 + /** Number of blocks in the partition. */ 20.31 + private long blocks; 20.32 + /** Start sector of the partition. */ 20.33 + private long start_sect; 20.34 + /** Number of sectors in the partition. */ 20.35 + private long nr_sects; 20.36 + /** Name of the partition. */ 20.37 + private String name; 20.38 + /** True if this partition is a XenoPartition. */ 20.39 + private boolean xeno; 20.40 20.41 - p.major = major; 20.42 - p.minor = minor; 20.43 - p.blocks = blocks; 20.44 - p.start_sect = start_sect; 20.45 - p.nr_sects = nr_sects; 20.46 - p.name = name; 20.47 - p.xeno = xeno; 20.48 - 20.49 - return p; 20.50 - } 20.51 - 20.52 - void 20.53 - dump_xml(PrintWriter out) 20.54 - { 20.55 - out.println (" <partition>\n" + 20.56 - " <major>" + major + "</major>\n" + 20.57 - " <minor>" + minor + "</minor>\n" + 20.58 - " <blocks>" + blocks + "</blocks>\n" + 20.59 - " <start_sect>" + start_sect + "</start_sect>\n" + 20.60 - " <nr_sects>" + nr_sects + "</nr_sects>\n" + 20.61 - " <name>" + name + "</name>\n" + 20.62 - " </partition>"); 20.63 - } 20.64 - 20.65 - public int 20.66 - getMajor() 20.67 - { 20.68 - return major; 20.69 - } 20.70 + /** 20.71 + * Mark this partition as a XenoPartition. 20.72 + */ 20.73 + void makeXeno() { 20.74 + xeno = true; 20.75 + } 20.76 20.77 - public int 20.78 - getMinor() 20.79 - { 20.80 - return minor; 20.81 - } 20.82 - 20.83 - public long 20.84 - getBlocks() 20.85 - { 20.86 - return blocks; 20.87 - } 20.88 - 20.89 - public long 20.90 - getStartSect() 20.91 - { 20.92 - return start_sect; 20.93 - } 20.94 + /** 20.95 + * Constructor for Partition. 20.96 + * @param major Major number 20.97 + * @param minor Minor number 20.98 + * @param blocks Size in blocks 20.99 + * @param start_sect Start sector 20.100 + * @param nr_sects Number of sectors 20.101 + * @param name Name of partition 20.102 + * @param xeno True if XenoPartition 20.103 + */ 20.104 + Partition( 20.105 + int major, 20.106 + int minor, 20.107 + long blocks, 20.108 + long start_sect, 20.109 + long nr_sects, 20.110 + String name, 20.111 + boolean xeno) { 20.112 + this.major = major; 20.113 + this.minor = minor; 20.114 + this.blocks = blocks; 20.115 + this.start_sect = start_sect; 20.116 + this.nr_sects = nr_sects; 20.117 + this.name = name; 20.118 + this.xeno = xeno; 20.119 + } 20.120 20.121 - public long 20.122 - getNumSects() 20.123 - { 20.124 - return nr_sects; 20.125 - } 20.126 - 20.127 - public String 20.128 - getName() 20.129 - { 20.130 - return name; 20.131 - } 20.132 + /** 20.133 + * Dump this partition as XML. 20.134 + * @param out The writer to dump to. 20.135 + */ 20.136 + void dumpAsXML(PrintWriter out) { 20.137 + out.println( 20.138 + " <partition>\n" 20.139 + + " <major>" 20.140 + + major 20.141 + + "</major>\n" 20.142 + + " <minor>" 20.143 + + minor 20.144 + + "</minor>\n" 20.145 + + " <blocks>" 20.146 + + blocks 20.147 + + "</blocks>\n" 20.148 + + " <start_sect>" 20.149 + + start_sect 20.150 + + "</start_sect>\n" 20.151 + + " <nr_sects>" 20.152 + + nr_sects 20.153 + + "</nr_sects>\n" 20.154 + + " <name>" 20.155 + + name 20.156 + + "</name>\n" 20.157 + + " </partition>"); 20.158 + } 20.159 20.160 - public boolean 20.161 - getIsXeno() 20.162 - { 20.163 - return xeno; 20.164 - } 20.165 - 20.166 - public int hashCode() { 20.167 - final int PRIME = 1000003; 20.168 - int result = 0; 20.169 - result = PRIME * result + major; 20.170 - result = PRIME * result + minor; 20.171 - result = PRIME * result + (int) (blocks >>> 32); 20.172 - result = PRIME * result + (int) (blocks & 0xFFFFFFFF); 20.173 - result = PRIME * result + (int) (start_sect >>> 32); 20.174 - result = PRIME * result + (int) (start_sect & 0xFFFFFFFF); 20.175 - result = PRIME * result + (int) (nr_sects >>> 32); 20.176 - result = PRIME * result + (int) (nr_sects & 0xFFFFFFFF); 20.177 - if (name != null) { 20.178 - result = PRIME * result + name.hashCode(); 20.179 + /** 20.180 + * @return Major device number. 20.181 + */ 20.182 + public int getMajor() { 20.183 + return major; 20.184 } 20.185 20.186 - return result; 20.187 - } 20.188 - 20.189 - public boolean equals(Object oth) { 20.190 - if (this == oth) { 20.191 - return true; 20.192 + /** 20.193 + * @return Minor device number. 20.194 + */ 20.195 + public int getMinor() { 20.196 + return minor; 20.197 } 20.198 20.199 - if (oth == null) { 20.200 - return false; 20.201 - } 20.202 - 20.203 - if (oth.getClass() != getClass()) { 20.204 - return false; 20.205 + /** 20.206 + * @return Number of blocks. 20.207 + */ 20.208 + public long getBlocks() { 20.209 + return blocks; 20.210 } 20.211 20.212 - Partition other = (Partition) oth; 20.213 - 20.214 - if (this.major != other.major) { 20.215 - return false; 20.216 + /** 20.217 + * @return Starting sector. 20.218 + */ 20.219 + public long getStartSect() { 20.220 + return start_sect; 20.221 } 20.222 20.223 - if (this.minor != other.minor) { 20.224 - return false; 20.225 + /** 20.226 + * @return Number of sectors. 20.227 + */ 20.228 + public long getNumSects() { 20.229 + return nr_sects; 20.230 } 20.231 20.232 - if (this.blocks != other.blocks) { 20.233 - return false; 20.234 + /** 20.235 + * @return Name of partition. 20.236 + */ 20.237 + public String getName() { 20.238 + return name; 20.239 } 20.240 20.241 - if (this.start_sect != other.start_sect) { 20.242 - return false; 20.243 + /** 20.244 + * @return True if this is a XenoPartition. 20.245 + */ 20.246 + public boolean isXeno() { 20.247 + return xeno; 20.248 } 20.249 20.250 - if (this.nr_sects != other.nr_sects) { 20.251 - return false; 20.252 + /** 20.253 + * Is this partition identical to the other? 20.254 + * @param other Other partition to compare to. 20.255 + * @return True if they are identical. 20.256 + */ 20.257 + public boolean identical(Partition other) { 20.258 + return this.major == other.major 20.259 + && this.minor == other.minor 20.260 + && this.blocks == other.blocks 20.261 + && this.start_sect == other.start_sect 20.262 + && this.nr_sects == other.nr_sects 20.263 + && this.name.equals(other.name); 20.264 } 20.265 - if (this.name == null) { 20.266 - if (other.name != null) { 20.267 - return false; 20.268 - } 20.269 - } else { 20.270 - if (!this.name.equals(other.name)) { 20.271 - return false; 20.272 - } 20.273 + 20.274 + /** 20.275 + * @return An Extent covering this partiton. 20.276 + */ 20.277 + public Extent toExtent() { 20.278 + return new Extent(getDisk(),start_sect,nr_sects); 20.279 } 20.280 20.281 - return true; 20.282 - } 20.283 - 20.284 - /** 20.285 - * @return An Extent covering this partiton. 20.286 - */ 20.287 - public Extent toExtent() 20.288 - { 20.289 - Extent e = new Extent(); 20.290 - // Build 16-bit disk number.. high 8 bits are the major 20.291 - e.disk = major << 8; 20.292 - // Low 8 bits are the minor, but bottom 5 need to be cleared 20.293 - // as they are the partition number, not the disk number 20.294 - e.disk |= ( minor & 0xE0 ); 20.295 - e.offset = start_sect; 20.296 - e.size = nr_sects; 20.297 - return e; 20.298 - } 20.299 - 20.300 - /** 20.301 - * @param e Extent to compare this partition to. 20.302 - * @return True if this partition covers the same disk area as the given extent. 20.303 - */ 20.304 - public boolean matchesExtent( Extent e ) 20.305 - { 20.306 - if ( e.getMajor() != major ) 20.307 - return false; 20.308 - if ( e.getMinor() != minor ) 20.309 - return false; 20.310 - if ( e.offset != start_sect ) 20.311 - return false; 20.312 - if ( e.size != nr_sects ) 20.313 - return false; 20.314 - 20.315 - return true; 20.316 - } 20.317 + /** 20.318 + * @param e Extent to compare this partition to. 20.319 + * @return True if this partition covers the same disk area as the given extent. 20.320 + */ 20.321 + public boolean matchesExtent(Extent e) { 20.322 + return e.getDisk() == getDisk() 20.323 + && e.getOffset() == start_sect 20.324 + && e.getSize() == nr_sects; 20.325 + } 20.326 + 20.327 + /** 20.328 + * @return Disk number for this partition. 20.329 + */ 20.330 + public int getDisk() { 20.331 + if ( name.startsWith("hd") ) { 20.332 + // High 8 bits are major, low 8 bits are minor, with bottom 6 clear 20.333 + return (major << 8) | (minor & 0xC0); 20.334 + } else if ( name.startsWith("sd") ) { 20.335 + // High 8 bits are major, low 8 bits are minor, with bottom 4 clear 20.336 + return (major << 8) | (minor & 0xF0); 20.337 + } else { 20.338 + throw new IllegalArgumentException("Don't know how to convert " + name + "into a disk number"); 20.339 + } 20.340 + } 20.341 }
21.1 --- a/tools/control/src/org/xenoserver/control/PartitionManager.java Mon Jul 07 15:21:46 2003 +0000 21.2 +++ b/tools/control/src/org/xenoserver/control/PartitionManager.java Tue Jul 08 11:07:33 2003 +0000 21.3 @@ -17,170 +17,155 @@ import java.util.Vector; 21.4 * PartitionManager manages the partitions on the machine. It is a Singleton 21.5 * which automatically initialises itself on first class reference. 21.6 */ 21.7 -public class 21.8 -PartitionManager 21.9 -{ 21.10 - static final String proc_template = 21.11 - "major minor #blocks start_sect nr_sects name"; 21.12 - 21.13 - public static final PartitionManager it = new PartitionManager(Settings.PARTITIONS_FILE); 21.14 - 21.15 - Vector partition_map; 21.16 +public class PartitionManager { 21.17 + /** The proc header string, used to check that this is a suitable proc file. */ 21.18 + private static final String PROC_TEMPLATE = 21.19 + "major minor #blocks start_sect nr_sects name"; 21.20 21.21 - /* 21.22 - * Initialize partition manager with source file. 21.23 - * Normally we read from /proc/partitions, but we can 21.24 - * specify an alternative file for debugging 21.25 - */ 21.26 - private PartitionManager (String filename) 21.27 - { 21.28 - String str; 21.29 - BufferedReader in; 21.30 + /** The single PartitionManager reference. */ 21.31 + public static final PartitionManager IT = 21.32 + new PartitionManager(Settings.PARTITIONS_FILE); 21.33 21.34 - partition_map = new Vector(100,10); 21.35 - 21.36 - try 21.37 - { 21.38 - in = new BufferedReader(new FileReader(filename)); 21.39 + /** The list of partitions. */ 21.40 + private Vector partition_map; 21.41 21.42 - str = in.readLine(); /* skip headings */ 21.43 - if (str.length() < proc_template.length() || 21.44 - !str.substring(0, proc_template.length()).equals(proc_template)) 21.45 - { 21.46 - System.err.println ("Error: Incorrect /proc/partitions."); 21.47 - System.err.println (" Is this Xeno?"); 21.48 - System.exit (1); 21.49 - } 21.50 - 21.51 - str = in.readLine(); /* skip blank line */ 21.52 - 21.53 - str = in.readLine(); 21.54 - while (str != null) 21.55 - { 21.56 - Partition partition = new Partition(); 21.57 + /** 21.58 + * Initialize partition manager with source file. 21.59 + * Normally we read from /proc/partitions, but we can 21.60 + * specify an alternative file for debugging. 21.61 + * @param filename The file to read partition data from. 21.62 + */ 21.63 + private PartitionManager(String filename) { 21.64 + String str; 21.65 + BufferedReader in; 21.66 21.67 - partition.major = Integer.parseInt(str.substring(0,5).trim()); 21.68 - partition.minor = Integer.parseInt(str.substring(5,10).trim()); 21.69 - partition.blocks = Integer.parseInt(str.substring(10,21).trim()); 21.70 - partition.start_sect = Integer.parseInt(str.substring(21,32).trim()); 21.71 - partition.nr_sects = Integer.parseInt(str.substring(32,43).trim()); 21.72 - partition.name = str.substring(43).trim(); 21.73 - partition.xeno = false; 21.74 + partition_map = new Vector(100, 10); 21.75 21.76 - partition_map.add(partition); 21.77 - str = in.readLine(); 21.78 - } 21.79 - } 21.80 - catch (IOException io) 21.81 - { 21.82 - System.err.println ("PartitionManager: error reading partition file [" 21.83 - + filename + "]"); 21.84 - System.err.println (io); 21.85 - } 21.86 - } 21.87 + try { 21.88 + in = new BufferedReader(new FileReader(filename)); 21.89 21.90 - public Partition 21.91 - get_partition (String name) 21.92 - { 21.93 - Partition partition = null; 21.94 - for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 21.95 - { 21.96 - partition = (Partition) e.nextElement(); 21.97 - if (partition.name.equals(name)) 21.98 - { 21.99 - return partition; 21.100 - } 21.101 - } 21.102 - return null; 21.103 - } 21.104 + str = in.readLine(); /* skip headings */ 21.105 + if (str.length() < PROC_TEMPLATE.length() 21.106 + || !str.substring(0, PROC_TEMPLATE.length()).equals( 21.107 + PROC_TEMPLATE)) { 21.108 + System.err.println("Error: Incorrect /proc/partitions."); 21.109 + System.err.println(" Is this Xeno?"); 21.110 + System.exit(1); 21.111 + } 21.112 + 21.113 + str = in.readLine(); /* skip blank line */ 21.114 21.115 - /** 21.116 - * Finds the partition that matches the given extent, if any. 21.117 - * @param extent The extent to compare to. 21.118 - * @return The first matching partition, or null if none. 21.119 - */ 21.120 - public Partition 21.121 - get_partition (Extent extent) 21.122 - { 21.123 - Partition partition = null; 21.124 - for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 21.125 - { 21.126 - partition = (Partition) e.nextElement(); 21.127 - if (partition.matchesExtent(extent)) 21.128 - { 21.129 - return partition; 21.130 - } 21.131 - } 21.132 - return null; 21.133 - } 21.134 - 21.135 - Partition 21.136 - get_partition (int index) 21.137 - { 21.138 - return (Partition) partition_map.get(index); 21.139 - } 21.140 + str = in.readLine(); 21.141 + while (str != null) { 21.142 + Partition partition = 21.143 + new Partition( 21.144 + Integer.parseInt(str.substring(0, 5).trim()), 21.145 + Integer.parseInt(str.substring(5, 10).trim()), 21.146 + Integer.parseInt(str.substring(10, 21).trim()), 21.147 + Integer.parseInt(str.substring(21, 32).trim()), 21.148 + Integer.parseInt(str.substring(32, 43).trim()), 21.149 + str.substring(43).trim(), 21.150 + false); 21.151 21.152 - void 21.153 - add_xeno_partition (Partition p) 21.154 - { 21.155 - for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 21.156 - { 21.157 - Partition partition = (Partition) e.nextElement(); 21.158 - if (partition.equals(p)) 21.159 - { 21.160 - partition.xeno = true; 21.161 - } 21.162 - } 21.163 - } 21.164 - 21.165 - /* 21.166 - * dump the xeno partition list as xml 21.167 - */ 21.168 - void 21.169 - dump_xml (PrintWriter out) 21.170 - { 21.171 - out.println("<partitions>"); 21.172 - for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 21.173 - { 21.174 - Partition partition = (Partition) e.nextElement(); 21.175 - if (partition.xeno == true) 21.176 - { 21.177 - partition.dump_xml(out); 21.178 - } 21.179 + partition_map.add(partition); 21.180 + str = in.readLine(); 21.181 + } 21.182 + } catch (IOException io) { 21.183 + System.err.println( 21.184 + "PartitionManager: error reading partition file [" 21.185 + + filename 21.186 + + "]"); 21.187 + System.err.println(io); 21.188 + } 21.189 } 21.190 21.191 - out.println("</partitions>"); 21.192 - 21.193 - return; 21.194 - } 21.195 + /** 21.196 + * Find a partition with the specified name. 21.197 + * @param name The name to search for. 21.198 + * @return The partition found, or null if no such partition. 21.199 + */ 21.200 + public Partition getPartition(String name) { 21.201 + Partition partition = null; 21.202 + for (Enumeration e = partition_map.elements(); e.hasMoreElements();) { 21.203 + partition = (Partition) e.nextElement(); 21.204 + if (partition.getName().equals(name)) { 21.205 + return partition; 21.206 + } 21.207 + } 21.208 + return null; 21.209 + } 21.210 21.211 - /** 21.212 - * get the number of partitions 21.213 - */ 21.214 - 21.215 - int 21.216 - getPartitionCount () 21.217 - { 21.218 - return partition_map.size(); 21.219 - } 21.220 + /** 21.221 + * Finds the partition that matches the given extent, if any. 21.222 + * @param extent The extent to compare to. 21.223 + * @return The first matching partition, or null if none. 21.224 + */ 21.225 + public Partition getPartition(Extent extent) { 21.226 + Partition partition = null; 21.227 + for (Enumeration e = partition_map.elements(); e.hasMoreElements();) { 21.228 + partition = (Partition) e.nextElement(); 21.229 + if (partition.matchesExtent(extent)) { 21.230 + return partition; 21.231 + } 21.232 + } 21.233 + return null; 21.234 + } 21.235 + 21.236 + /** 21.237 + * Find the ith partition in the partition list. 21.238 + * @param i Index number. 21.239 + * @return The partition, or null if out of range. 21.240 + */ 21.241 + public Partition getPartition(int i) { 21.242 + if ( i >= partition_map.size() ) { 21.243 + return null; 21.244 + } 21.245 + return (Partition) partition_map.elementAt( i ); 21.246 + } 21.247 21.248 - /** 21.249 - * get the details about a particular partition 21.250 - * 21.251 - */ 21.252 - Partition 21.253 - getPartition (int index) 21.254 - { 21.255 - Partition partition = (Partition) partition_map.get(index); 21.256 - return partition; 21.257 - } 21.258 - 21.259 - /** 21.260 - * Get an iterator over all the partitions. 21.261 - * @return An iterator over Partition objects. 21.262 - */ 21.263 - public Iterator iterator() 21.264 - { 21.265 - return partition_map.iterator(); 21.266 - } 21.267 + /** 21.268 + * Adds the given partition as a XenoPartition. 21.269 + * @param p The partition to add. 21.270 + */ 21.271 + void addXenoPartition(Partition p) { 21.272 + for (Enumeration e = partition_map.elements(); e.hasMoreElements();) { 21.273 + Partition partition = (Partition) e.nextElement(); 21.274 + if (partition.identical(p)) { 21.275 + partition.makeXeno(); 21.276 + } 21.277 + } 21.278 + } 21.279 + 21.280 + /** 21.281 + * Dump the XenoPartition list as XML. 21.282 + * @param out Writer to dump to. 21.283 + */ 21.284 + void dumpAsXML(PrintWriter out) { 21.285 + out.println("<partitions>"); 21.286 + for (Enumeration e = partition_map.elements(); e.hasMoreElements();) { 21.287 + Partition partition = (Partition) e.nextElement(); 21.288 + if (partition.isXeno()) { 21.289 + partition.dumpAsXML(out); 21.290 + } 21.291 + } 21.292 + 21.293 + out.println("</partitions>"); 21.294 + 21.295 + return; 21.296 + } 21.297 + 21.298 + /** 21.299 + * @return The number of partitions. 21.300 + */ 21.301 + public int getPartitionCount() { 21.302 + return partition_map.size(); 21.303 + } 21.304 + 21.305 + /** 21.306 + * Get an iterator over all the partitions. 21.307 + * @return An iterator over Partition objects. 21.308 + */ 21.309 + public Iterator iterator() { 21.310 + return partition_map.iterator(); 21.311 + } 21.312 }
22.1 --- a/tools/control/src/org/xenoserver/control/Settings.java Mon Jul 07 15:21:46 2003 +0000 22.2 +++ b/tools/control/src/org/xenoserver/control/Settings.java Tue Jul 08 11:07:33 2003 +0000 22.3 @@ -7,38 +7,63 @@ import java.util.StringTokenizer; 22.4 * The Settings class is a repository for global settings such as the IP of 22.5 * the machine and the location of the defaults file. 22.6 */ 22.7 -public final class Settings 22.8 -{ 22.9 - public static final String DEFAULTS_FILE = System.getProperty ("DEFAULTS_FILE", "domctl.xml"); 22.10 - public static final String DEFAULTS_PATH = System.getProperty ("DEFAULTS_PATH", ".:/etc:/var/lib/xen"); 22.11 - public static final String LOCAL_IP = System.getProperty ("LOCAL_IP"); 22.12 - public static final String LOCAL_MASK = System.getProperty ("LOCAL_MASK"); 22.13 - public static final String LOCAL_GW = System.getProperty ("LOCAL_ROUTE"); 22.14 - public static final boolean TEST = (System.getProperty ("TEST") != null); 22.15 - public static final String XI_HELPER = System.getProperty ("XI_HELPER", "xi_helper"); 22.16 - public static final String PARTITIONS_FILE = System.getProperty("PARTITIONS_FILE", "/proc/partitions"); 22.17 - public static final String STATE_INPUT_FILE = System.getProperty("STATE_INPUT_FILE", "/var/lib/xen/vdstate.xml"); 22.18 - public static final String STATE_OUTPUT_FILE = System.getProperty("STATE_OUTPUT_FILE", "/var/lib/xen/vdstate.xml"); 22.19 - public static final int SECTOR_SIZE = Integer.parseInt( System.getProperty("SECTOR_SIZE", "512") ); 22.20 +public final class Settings { 22.21 + /** Filename for the defaults file. */ 22.22 + public static final String DEFAULTS_FILE = 22.23 + System.getProperty("DEFAULTS_FILE", "domctl.xml"); 22.24 + /** Path to search for the defaults file. */ 22.25 + public static final String DEFAULTS_PATH = 22.26 + System.getProperty("DEFAULTS_PATH", ".:/etc:/var/lib/xen"); 22.27 + /** IP address of domain 0. */ 22.28 + public static final String LOCAL_IP = System.getProperty("LOCAL_IP"); 22.29 + /** Network mask of domain 0. */ 22.30 + public static final String LOCAL_MASK = System.getProperty("LOCAL_MASK"); 22.31 + /** Gateway of domain 0. */ 22.32 + public static final String LOCAL_GW = System.getProperty("LOCAL_ROUTE"); 22.33 + /** If set, do not call any xi_ commands, just print their command lines. */ 22.34 + public static final boolean TEST = (System.getProperty("TEST") != null); 22.35 + /** Name of xi_helper utility. */ 22.36 + public static final String XI_HELPER = 22.37 + System.getProperty("XI_HELPER", "xi_helper"); 22.38 + /** File to parse to get partition info. */ 22.39 + public static final String PARTITIONS_FILE = 22.40 + System.getProperty("PARTITIONS_FILE", "/proc/partitions"); 22.41 + /** File to load virtual disk state from. */ 22.42 + public static final String STATE_INPUT_FILE = 22.43 + System.getProperty("STATE_INPUT_FILE", "/var/lib/xen/vdstate.xml"); 22.44 + /** File to save virtual disk state to. */ 22.45 + public static final String STATE_OUTPUT_FILE = 22.46 + System.getProperty("STATE_OUTPUT_FILE", "/var/lib/xen/vdstate.xml"); 22.47 + /** Size of a sector in bytes. */ 22.48 + public static final int SECTOR_SIZE = 22.49 + Integer.parseInt(System.getProperty("SECTOR_SIZE", "512")); 22.50 22.51 - public static File getDefaultsFile() { 22.52 - StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":"); 22.53 - File result = null; 22.54 - File probe; 22.55 + /** 22.56 + * Search for the defaults file in the path configured in DEFAULTS_PATH. 22.57 + * @return Reference to the defaults file. 22.58 + */ 22.59 + public static File getDefaultsFile() { 22.60 + StringTokenizer tok = new StringTokenizer(DEFAULTS_PATH, ":"); 22.61 + File result = null; 22.62 + File probe; 22.63 22.64 - while (tok.hasMoreTokens ()) { 22.65 - String probe_dir = tok.nextToken (); 22.66 - probe = new File (probe_dir, DEFAULTS_FILE); 22.67 - if (probe.exists ()) { 22.68 - result = probe; 22.69 - break; 22.70 - } 22.71 + while (tok.hasMoreTokens()) { 22.72 + String probe_dir = tok.nextToken(); 22.73 + probe = new File(probe_dir, DEFAULTS_FILE); 22.74 + if (probe.exists()) { 22.75 + result = probe; 22.76 + break; 22.77 + } 22.78 + } 22.79 + 22.80 + if (result == null) { 22.81 + System.err.println( 22.82 + "Could not find " 22.83 + + DEFAULTS_FILE 22.84 + + " in path " 22.85 + + DEFAULTS_PATH); 22.86 + } 22.87 + 22.88 + return result; 22.89 } 22.90 - 22.91 - if (result == null) { 22.92 - System.err.println ("Could not find " + DEFAULTS_FILE + " in path " + DEFAULTS_PATH); 22.93 - } 22.94 - 22.95 - return result; 22.96 - } 22.97 }
23.1 --- a/tools/control/src/org/xenoserver/control/StringPattern.java Mon Jul 07 15:21:46 2003 +0000 23.2 +++ b/tools/control/src/org/xenoserver/control/StringPattern.java Tue Jul 08 11:07:33 2003 +0000 23.3 @@ -1,59 +1,78 @@ 23.4 package org.xenoserver.control; 23.5 23.6 -public class StringPattern 23.7 -{ 23.8 - String base; 23.9 - int bn; 23.10 - boolean addDom; 23.11 - boolean appendDom; 23.12 - 23.13 - static StringPattern parse (String t) 23.14 - { 23.15 - StringPattern result = new StringPattern (); 23.16 - char[] ca = t.toCharArray (); 23.17 - int idx = 0; 23.18 - int len = ca.length; 23.19 +/** 23.20 + * This utility class expands configuration file patterns. 23.21 + */ 23.22 +public class StringPattern { 23.23 + /** The base string for this pattern. */ 23.24 + private String base; 23.25 + /** The base number for this pattern. */ 23.26 + private int bn; 23.27 + /** If true, add the domain number to the base number and append. */ 23.28 + private boolean addDom; 23.29 + /** If true, append the domain number to the base string. */ 23.30 + private boolean appendDom; 23.31 23.32 - if (len == 0) { 23.33 - result.base = ""; 23.34 - result.bn = 0; 23.35 - result.addDom = false; 23.36 - } else if (ca[len - 1] == '+') { 23.37 - idx = len - 2; 23.38 - if ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) { 23.39 - while ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) { 23.40 - idx --; 23.41 - } 23.42 - result.base = t.substring(0, idx + 1); 23.43 - result.bn = Integer.parseInt (t.substring (idx + 1, len - 1)); 23.44 - result.addDom = true; 23.45 - } else { 23.46 - result.base = t.substring(0, len - 1); 23.47 - result.appendDom = true; 23.48 - } 23.49 - } else { 23.50 - result.base = t; 23.51 + /** 23.52 + * Parse a string into a pattern. 23.53 + * @param t The pattern string to parse. 23.54 + * @return A usable pattern object. 23.55 + */ 23.56 + static StringPattern parse(String t) { 23.57 + StringPattern result = new StringPattern(); 23.58 + char[] ca = t.toCharArray(); 23.59 + int idx = 0; 23.60 + int len = ca.length; 23.61 + 23.62 + if (len == 0) { 23.63 + result.base = ""; 23.64 + result.bn = 0; 23.65 + result.addDom = false; 23.66 + } else if (ca[len - 1] == '+') { 23.67 + idx = len - 2; 23.68 + if ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) { 23.69 + while ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) { 23.70 + idx--; 23.71 + } 23.72 + result.base = t.substring(0, idx + 1); 23.73 + result.bn = Integer.parseInt(t.substring(idx + 1, len - 1)); 23.74 + result.addDom = true; 23.75 + } else { 23.76 + result.base = t.substring(0, len - 1); 23.77 + result.appendDom = true; 23.78 + } 23.79 + } else { 23.80 + result.base = t; 23.81 + } 23.82 + 23.83 + return result; 23.84 } 23.85 23.86 - return result; 23.87 - } 23.88 + /** 23.89 + * Resolve the pattern for the given domain number. 23.90 + * @param domain The domain number to use. 23.91 + * @return The expanded pattern for the given domain. 23.92 + */ 23.93 + String resolve(int domain) { 23.94 + if (addDom) { 23.95 + return base + (bn + domain); 23.96 + } else if (appendDom) { 23.97 + return base + domain; 23.98 + } else { 23.99 + return base; 23.100 + } 23.101 + } 23.102 23.103 - public String resolve (int domain_id) { 23.104 - if (addDom) { 23.105 - return base + (bn + domain_id); 23.106 - } else if (appendDom) { 23.107 - return base + domain_id; 23.108 - } else { 23.109 - return base; 23.110 + /** 23.111 + * @see java.lang.Object#toString() 23.112 + */ 23.113 + public String toString() { 23.114 + return ( 23.115 + "[" 23.116 + + base 23.117 + + (addDom ? "+" + bn : "") 23.118 + + ((addDom || appendDom) ? "+ID" : "") 23.119 + + "]"); 23.120 } 23.121 - } 23.122 - 23.123 - public String toString () { 23.124 - return ("[" + 23.125 - base + 23.126 - (addDom ? "+" + bn : "") + 23.127 - ((addDom || appendDom) ? "+ID" : "") + 23.128 - "]"); 23.129 - } 23.130 23.131 }
24.1 --- a/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java Mon Jul 07 15:21:46 2003 +0000 24.2 +++ b/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java Tue Jul 08 11:07:33 2003 +0000 24.3 @@ -7,55 +7,98 @@ package org.xenoserver.control; 24.4 24.5 import java.io.PrintWriter; 24.6 24.7 +/** 24.8 + * A virtual block device; a mapping from a domain-specific number to a virtual 24.9 + * disk with associated access mode. 24.10 + */ 24.11 public class VirtualBlockDevice { 24.12 - String key; 24.13 - int domain; 24.14 - int vbdnum; 24.15 - Mode mode; /* rw or ro */ 24.16 - 24.17 - String dump(boolean title) { 24.18 - StringBuffer sb = new StringBuffer(); 24.19 + /** The virtual disk which this block device maps onto. */ 24.20 + private VirtualDisk vd; 24.21 + /** The domain in which this block device exists. */ 24.22 + private int domain; 24.23 + /** The block device number in that domain. */ 24.24 + private int vbdNum; 24.25 + /** The access mode within that domain. */ 24.26 + private Mode mode; 24.27 24.28 - if (title) { 24.29 - sb.append(" key dom vbd mode\n"); 24.30 - } else { 24.31 - sb.append( 24.32 - " " 24.33 - + key 24.34 - + " " 24.35 - + Library.format(domain, 3, 0) 24.36 - + " " 24.37 - + Library.format(vbdnum, 3, 0) 24.38 - + " " 24.39 - + mode.toString() 24.40 - + "\n"); 24.41 + /** 24.42 + * Constructor for VirtualBlockDevice. 24.43 + * @param vd The virtual disk to map to. 24.44 + * @param domain The domain to create the device in. 24.45 + * @param vbdNum The number for the device. 24.46 + * @param mode The access mode. 24.47 + */ 24.48 + VirtualBlockDevice( 24.49 + VirtualDisk vd, 24.50 + int domain, 24.51 + int vbdNum, 24.52 + Mode mode) { 24.53 + this.vd = vd; 24.54 + this.domain = domain; 24.55 + this.vbdNum = vbdNum; 24.56 + this.mode = mode; 24.57 } 24.58 24.59 - return sb.toString(); 24.60 - } 24.61 + // TODO: get rid of this method 24.62 + String dump(boolean title) { 24.63 + StringBuffer sb = new StringBuffer(); 24.64 24.65 - void dump_xml(PrintWriter out) { 24.66 - out.println(" <virtual_block_device>"); 24.67 - out.println(" <key>" + key + "</key>"); 24.68 - out.println(" <domain>" + domain + "</domain>"); 24.69 - out.println(" <vbdnum>" + vbdnum + "</vbdnum>"); 24.70 - out.println(" <mode>" + mode + "</mode>"); 24.71 - out.println(" </virtual_block_device>"); 24.72 - } 24.73 + if (title) { 24.74 + sb.append(" key dom vbd mode\n"); 24.75 + } else { 24.76 + sb.append( 24.77 + " " 24.78 + + vd.getKey() 24.79 + + " " 24.80 + + Library.format(domain, 3, false) 24.81 + + " " 24.82 + + Library.format(vbdNum, 3, false) 24.83 + + " " 24.84 + + mode.toString() 24.85 + + "\n"); 24.86 + } 24.87 + 24.88 + return sb.toString(); 24.89 + } 24.90 24.91 - public String getKey() { 24.92 - return key; 24.93 - } 24.94 + /** 24.95 + * Dump the virtual block device as XML. 24.96 + * @param out The writer to dump to. 24.97 + */ 24.98 + void dumpAsXML(PrintWriter out) { 24.99 + out.println(" <virtual_block_device>"); 24.100 + out.println(" <key>" + vd.getKey() + "</key>"); 24.101 + out.println(" <domain>" + domain + "</domain>"); 24.102 + out.println(" <vbdnum>" + vbdNum + "</vbdnum>"); 24.103 + out.println(" <mode>" + mode + "</mode>"); 24.104 + out.println(" </virtual_block_device>"); 24.105 + } 24.106 24.107 - public int getDomain() { 24.108 - return domain; 24.109 - } 24.110 + /** 24.111 + * @return This device's virtual disk. 24.112 + */ 24.113 + public VirtualDisk getVirtualDisk() { 24.114 + return vd; 24.115 + } 24.116 24.117 - public int getVBDNum() { 24.118 - return vbdnum; 24.119 - } 24.120 + /** 24.121 + * @return The domain this device exists in. 24.122 + */ 24.123 + public int getDomain() { 24.124 + return domain; 24.125 + } 24.126 24.127 - public Mode getMode() { 24.128 - return mode; 24.129 - } 24.130 + /** 24.131 + * @return The device number within its domain. 24.132 + */ 24.133 + public int getVbdNum() { 24.134 + return vbdNum; 24.135 + } 24.136 + 24.137 + /** 24.138 + * @return This device's access mode. 24.139 + */ 24.140 + public Mode getMode() { 24.141 + return mode; 24.142 + } 24.143 }
25.1 --- a/tools/control/src/org/xenoserver/control/VirtualDisk.java Mon Jul 07 15:21:46 2003 +0000 25.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDisk.java Tue Jul 08 11:07:33 2003 +0000 25.3 @@ -10,172 +10,224 @@ import java.util.Date; 25.4 import java.util.Iterator; 25.5 import java.util.Vector; 25.6 25.7 +/** 25.8 + * A single virtual disk. This may be used by multiple virtual block devices. 25.9 + */ 25.10 public class VirtualDisk { 25.11 - String name; 25.12 - String key; 25.13 - Date expiry; 25.14 - Vector extents; 25.15 + /** The name of this virtual disk. */ 25.16 + private String name; 25.17 + /** The key of this virtual disk (unique). */ 25.18 + private String key; 25.19 + /** The expiry time of this virtual disk, or null for never. */ 25.20 + private Date expiry; 25.21 + /** The extent list for this virtual disk. */ 25.22 + private Vector extents; 25.23 25.24 - VirtualDisk(String name, Date expiry, String key) { 25.25 - this.name = name; 25.26 - if ( key == null ) 25.27 - this.key = generate_key(); 25.28 - else 25.29 - this.key = key; 25.30 - this.expiry = expiry; 25.31 - extents = new Vector(); 25.32 - } 25.33 + /** 25.34 + * Construct a new virtual disk, specifying all parameters. 25.35 + * @param name Name of the new disk. 25.36 + * @param expiry Expiry time, or null for never. 25.37 + * @param key Key for the new disk, or null to autogenerate. 25.38 + */ 25.39 + VirtualDisk(String name, Date expiry, String key) { 25.40 + this.name = name; 25.41 + if (key == null) { 25.42 + this.key = generateKey(); 25.43 + } else { 25.44 + this.key = key; 25.45 + } 25.46 + this.expiry = expiry; 25.47 + extents = new Vector(); 25.48 + } 25.49 25.50 - VirtualDisk(String name) { 25.51 - this(name, null, null); 25.52 - } 25.53 - 25.54 - VirtualDisk(String name, Date expiry) { 25.55 - this(name, expiry, null); 25.56 - } 25.57 + /** 25.58 + * Construct a new virtual disk, with automatically generated key and no expiry. 25.59 + * @param name Name of the new disk. 25.60 + */ 25.61 + VirtualDisk(String name) { 25.62 + this(name, null, null); 25.63 + } 25.64 25.65 - /* 25.66 - * generate a unique key for this virtual disk. 25.67 - * for now, just generate a 10 digit number 25.68 - */ 25.69 - String generate_key() { 25.70 - return Long.toString(1000000000l + (long) (Math.random() * 8999999999l)); 25.71 - } 25.72 + /** 25.73 + * Construct a new virtual disk, with automatically generated key. 25.74 + * @param name Name of the new disk. 25.75 + * @param expiry Expiry time, or null for never. 25.76 + */ 25.77 + VirtualDisk(String name, Date expiry) { 25.78 + this(name, expiry, null); 25.79 + } 25.80 25.81 - void set_expiry(Date expiry) { 25.82 - this.expiry = expiry; 25.83 - } 25.84 + /** 25.85 + * Generate a unique key for this virtual disk. 25.86 + * For now, just generate a 10 digit number. 25.87 + * @return A unique key. 25.88 + */ 25.89 + private static String generateKey() { 25.90 + return Long.toString( 25.91 + 1000000000L + (long) (Math.random() * 8999999999L)); 25.92 + } 25.93 25.94 - public void add_extent(Extent extent) { 25.95 - extents.add(extent); 25.96 - } 25.97 + /** 25.98 + * Add an extent to this disk. 25.99 + * @param extent The extent to add. 25.100 + */ 25.101 + void addExtent(Extent extent) { 25.102 + extents.add(extent); 25.103 + } 25.104 25.105 - public Extent remove_extent() { 25.106 - Extent e; 25.107 + /** 25.108 + * Remove the first extent from this disk. 25.109 + * @return The extent removed, or null if there are no extents. 25.110 + */ 25.111 + Extent removeExtent() { 25.112 + Extent e; 25.113 25.114 - if (extents.size() > 0) { 25.115 - e = (Extent) extents.remove(0); 25.116 - } else { 25.117 - e = null; 25.118 + if (extents.size() > 0) { 25.119 + e = (Extent) extents.remove(0); 25.120 + } else { 25.121 + e = null; 25.122 + } 25.123 + 25.124 + return e; 25.125 } 25.126 25.127 - return e; 25.128 - } 25.129 - 25.130 - String dump_xen(VirtualBlockDevice vbd) { 25.131 - StringBuffer sb = new StringBuffer(); 25.132 - 25.133 - sb.append( 25.134 - "domain:" 25.135 - + vbd.domain 25.136 - + " " 25.137 - + vbd.mode.toString() 25.138 - + " " 25.139 - + "segment:" 25.140 - + vbd.vbdnum 25.141 - + " " 25.142 - + "extents:" 25.143 - + extents.size() 25.144 - + " "); 25.145 - for (int loop = 0; loop < extents.size(); loop++) { 25.146 - Extent e = (Extent) extents.get(loop); 25.147 - sb.append( 25.148 - "(disk:" 25.149 - + e.disk 25.150 - + " " 25.151 - + "offset:" 25.152 - + e.offset 25.153 - + " " 25.154 - + "size:" 25.155 - + e.size 25.156 - + ")"); 25.157 - } 25.158 - return sb.toString(); 25.159 - } 25.160 + /** 25.161 + * Form a string suitable for passing into the XenoLinux proc interface mapping 25.162 + * the given VBD to this virtual disk. 25.163 + * @param vbd The virtual block device to map. 25.164 + * @return A XenoLinux /proc string. 25.165 + */ 25.166 + String dumpForXen(VirtualBlockDevice vbd) { 25.167 + StringBuffer sb = new StringBuffer(); 25.168 25.169 - void dump_xml(PrintWriter out) { 25.170 - out.println(" <virtual_disk>"); 25.171 - out.println(" <name>" + name + "</name>"); 25.172 - out.println(" <key>" + key + "</key>"); 25.173 - if (expiry == null) { 25.174 - out.println(" <expiry>0</expiry>"); 25.175 - } else { 25.176 - out.println(" <expiry>" + expiry.getTime() + "</expiry>"); 25.177 + sb.append( 25.178 + "domain:" 25.179 + + vbd.getDomain() 25.180 + + " " 25.181 + + vbd.getMode().toString() 25.182 + + " " 25.183 + + "segment:" 25.184 + + vbd.getVbdNum() 25.185 + + " " 25.186 + + "extents:" 25.187 + + extents.size() 25.188 + + " "); 25.189 + for (int loop = 0; loop < extents.size(); loop++) { 25.190 + Extent e = (Extent) extents.get(loop); 25.191 + sb.append( 25.192 + "(disk:" 25.193 + + e.getDisk() 25.194 + + " " 25.195 + + "offset:" 25.196 + + e.getOffset() 25.197 + + " " 25.198 + + "size:" 25.199 + + e.getSize() 25.200 + + ")"); 25.201 + } 25.202 + return sb.toString(); 25.203 } 25.204 - out.println(" <extents>"); 25.205 - for (int loop = 0; loop < extents.size(); loop++) { 25.206 - Extent e = (Extent) extents.get(loop); 25.207 - out.println(" <extent>"); 25.208 - out.println(" <disk>" + e.disk + "</disk>"); 25.209 - out.println(" <size>" + e.size + "</size>"); 25.210 - out.println(" <offset>" + e.offset + "</offset>"); 25.211 - out.println(" </extent>"); 25.212 - } 25.213 - out.println(" </extents>"); 25.214 - out.println(" </virtual_disk>"); 25.215 25.216 - return; 25.217 - } 25.218 - 25.219 - /* 25.220 - * Add a partition as a XenoPartition. 25.221 - * Chop the partition in to extents and of size "size" sectors 25.222 - * and add them to the virtual disk. 25.223 - */ 25.224 + /** 25.225 + * Dump the virtual disk as XML. 25.226 + * @param out The writer to dump to. 25.227 + */ 25.228 + void dumpAsXML(PrintWriter out) { 25.229 + out.println(" <virtual_disk>"); 25.230 + out.println(" <name>" + name + "</name>"); 25.231 + out.println(" <key>" + key + "</key>"); 25.232 + if (expiry == null) { 25.233 + out.println(" <expiry>0</expiry>"); 25.234 + } else { 25.235 + out.println(" <expiry>" + expiry.getTime() + "</expiry>"); 25.236 + } 25.237 + out.println(" <extents>"); 25.238 + for (int loop = 0; loop < extents.size(); loop++) { 25.239 + Extent e = (Extent) extents.get(loop); 25.240 + out.println(" <extent>"); 25.241 + out.println(" <disk>" + e.getDisk() + "</disk>"); 25.242 + out.println(" <size>" + e.getSize() + "</size>"); 25.243 + out.println(" <offset>" + e.getOffset() + "</offset>"); 25.244 + out.println(" </extent>"); 25.245 + } 25.246 + out.println(" </extents>"); 25.247 + out.println(" </virtual_disk>"); 25.248 25.249 - void add_new_partition(Partition partition, long size) { 25.250 - int loop; 25.251 - 25.252 - for (loop = 0; loop < partition.nr_sects / size; loop++) { 25.253 - Extent extent = new Extent(); 25.254 - 25.255 - extent.disk = partition.major << 8; 25.256 - extent.disk = extent.disk | (partition.minor >> 5) << 5; 25.257 - extent.size = size; 25.258 - extent.offset = partition.start_sect + (size * loop); 25.259 - 25.260 - add_extent(extent); 25.261 + return; 25.262 } 25.263 25.264 - return; 25.265 - } 25.266 + /** 25.267 + * Add a partition as a XenoPartition. 25.268 + * Chop the partition in to extents and add them to this virtual disk. 25.269 + * @param partition The partition to add. 25.270 + * @param extentSize The number of sectors to use for each extent. 25.271 + */ 25.272 + void addPartition(Partition partition, long extentSize) { 25.273 + int loop; 25.274 25.275 - public String getName() { 25.276 - return name; 25.277 - } 25.278 + for (loop = 0; loop < partition.getNumSects() / extentSize; loop++) { 25.279 + Extent extent = 25.280 + new Extent( 25.281 + partition.getDisk(), 25.282 + extentSize, 25.283 + partition.getStartSect() + (extentSize * loop)); 25.284 25.285 - public String getKey() { 25.286 - return key; 25.287 - } 25.288 + addExtent(extent); 25.289 + } 25.290 + } 25.291 25.292 - public Date getExpiry() { 25.293 - return expiry; 25.294 - } 25.295 + /** 25.296 + * @return The name of this virtual disk. 25.297 + */ 25.298 + public String getName() { 25.299 + return name; 25.300 + } 25.301 25.302 - public int getExtentCount() { 25.303 - return extents.size(); 25.304 - } 25.305 + /** 25.306 + * @return The key of this virtual disk. 25.307 + */ 25.308 + public String getKey() { 25.309 + return key; 25.310 + } 25.311 25.312 - public Extent getExtent(int index) { 25.313 - return (Extent) extents.get(index); 25.314 - } 25.315 + /** 25.316 + * @return The expiry time of this virtual disk. 25.317 + */ 25.318 + public Date getExpiry() { 25.319 + return expiry; 25.320 + } 25.321 + 25.322 + /** 25.323 + * @return The number of extents in this virtual disk. 25.324 + */ 25.325 + public int getExtentCount() { 25.326 + return extents.size(); 25.327 + } 25.328 25.329 - /** 25.330 - * @return Total size of this virtual disk in sectors. 25.331 - */ 25.332 - public long getSize() { 25.333 - long size = 0; 25.334 - Iterator i = extents.iterator(); 25.335 - while ( i.hasNext() ) { 25.336 - size += ((Extent) i.next()).getSize(); 25.337 + /** 25.338 + * @return Total size of this virtual disk in sectors. 25.339 + */ 25.340 + public long getSize() { 25.341 + long size = 0; 25.342 + Iterator i = extents.iterator(); 25.343 + while (i.hasNext()) { 25.344 + size += ((Extent) i.next()).getSize(); 25.345 + } 25.346 + return size; 25.347 } 25.348 - return size; 25.349 - } 25.350 - 25.351 - /** 25.352 - * @return An iterator over all extents in the disk. 25.353 - */ 25.354 - public Iterator iterator() { 25.355 - return extents.iterator(); 25.356 - } 25.357 + 25.358 + /** 25.359 + * @return An iterator over all extents in the disk. 25.360 + */ 25.361 + public Iterator extents() { 25.362 + return extents.iterator(); 25.363 + } 25.364 + 25.365 + /** 25.366 + * Reset the expiry time for this virtual disk. 25.367 + * @param expiry The new expiry time, or null for never. 25.368 + */ 25.369 + public void refreshExpiry(Date expiry) { 25.370 + this.expiry = expiry; 25.371 + } 25.372 }
26.1 --- a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java Mon Jul 07 15:21:46 2003 +0000 26.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java Tue Jul 08 11:07:33 2003 +0000 26.3 @@ -7,230 +7,216 @@ package org.xenoserver.control; 26.4 26.5 import java.io.PrintWriter; 26.6 import java.util.Date; 26.7 -import java.util.Enumeration; 26.8 -import java.util.Hashtable; 26.9 -import java.util.Vector; 26.10 +import java.util.Iterator; 26.11 +import java.util.LinkedHashMap; 26.12 26.13 /** 26.14 * VirtualDiskManager manages the list of virtual disks on the machine. It is 26.15 * a Singleton which automatically initialises itself on first class reference. 26.16 */ 26.17 public class VirtualDiskManager { 26.18 - public static final VirtualDiskManager it = new VirtualDiskManager(); 26.19 - VirtualDisk free_disk; 26.20 - Vector virtual_disks; 26.21 - Hashtable virtual_block_devices; 26.22 - Hashtable key_hash; 26.23 - 26.24 - private VirtualDiskManager() { 26.25 - free_disk = new VirtualDisk("free"); 26.26 + /** The single VDM reference. */ 26.27 + public static final VirtualDiskManager IT = new VirtualDiskManager(); 26.28 + /** The free-space disk. */ 26.29 + private VirtualDisk freeDisk; 26.30 + /** The map of keys to virtual disks. */ 26.31 + private LinkedHashMap virtualDisks = new LinkedHashMap(100); 26.32 + /** The map of (domain,vbdnum) to virtual block devices. */ 26.33 + private LinkedHashMap virtualBlockDevices = new LinkedHashMap(100); 26.34 26.35 - virtual_disks = new Vector(10, 5); 26.36 - flush_virtual_block_devices(); 26.37 - key_hash = new Hashtable(100); 26.38 - } 26.39 - 26.40 - public VirtualDisk get_virtual_disk_key(String key) { 26.41 - return ((VirtualDisk) key_hash.get(key)); 26.42 - } 26.43 + /** 26.44 + * VDM constructor, private as it's a singleton. 26.45 + */ 26.46 + private VirtualDiskManager() { 26.47 + freeDisk = new VirtualDisk("free"); 26.48 + } 26.49 26.50 - public void add_xeno_partition(Partition partition, long size) { 26.51 - free_disk.add_new_partition(partition, size); 26.52 - return; 26.53 - } 26.54 - 26.55 - /* 26.56 - * create a new virtual disk 26.57 - */ 26.58 - 26.59 - public VirtualDisk create_virtual_disk(String name, long size, Date expiry) { 26.60 - VirtualDisk vd = new VirtualDisk(name, expiry); 26.61 + /** 26.62 + * Get the virtual disk with the specified key. 26.63 + * @param key The key to look for. 26.64 + * @return The virtual disk, or null if not found. 26.65 + */ 26.66 + public VirtualDisk getVirtualDisk(String key) { 26.67 + return ((VirtualDisk) virtualDisks.get(key)); 26.68 + } 26.69 26.70 - if ( free_disk.getSize() < size ) 26.71 - return null; 26.72 - 26.73 - while (size > 0) { 26.74 - Extent e; 26.75 - 26.76 - e = free_disk.remove_extent(); 26.77 - if (e == null) { 26.78 - return null; 26.79 - } 26.80 - size -= e.size; 26.81 - vd.add_extent(e); 26.82 + /** 26.83 + * Add a new partition to the free space list in the disk manager. 26.84 + * @param partition The partition to add. 26.85 + * @param chunkSize The chunk size to split the partition into, in sectors. 26.86 + */ 26.87 + public void addPartition(Partition partition, long chunkSize) { 26.88 + freeDisk.addPartition(partition, chunkSize); 26.89 } 26.90 26.91 - add_virtual_disk(vd); 26.92 - 26.93 - return vd; 26.94 - } 26.95 + /** 26.96 + * Create a new virtual disk. 26.97 + * @param name The disk name to use. 26.98 + * @param size The number of sectors to allocate. 26.99 + * @param expiry The expiry time, or null for never. 26.100 + * @return null if not enough space is available 26.101 + */ 26.102 + public VirtualDisk createVirtualDisk(String name, long size, Date expiry) { 26.103 + if (freeDisk.getSize() < size) { 26.104 + return null; 26.105 + } 26.106 26.107 - /* 26.108 - * delete a new virtual disk. extents go back into the free pool 26.109 - */ 26.110 - 26.111 - public void delete_virtual_disk(String key) { 26.112 - VirtualDisk vd; 26.113 + VirtualDisk vd = new VirtualDisk(name, expiry); 26.114 26.115 - vd = (VirtualDisk) key_hash.get(key); 26.116 - if (vd != null) { 26.117 - Extent e; 26.118 + while (size > 0) { 26.119 + Extent e; 26.120 26.121 - key_hash.remove(key); 26.122 - virtual_disks.remove(vd); 26.123 + e = freeDisk.removeExtent(); 26.124 + if (e == null) { 26.125 + return null; 26.126 + } 26.127 + size -= e.getSize(); 26.128 + vd.addExtent(e); 26.129 + } 26.130 26.131 - e = vd.remove_extent(); 26.132 - while (e != null) { 26.133 - free_disk.add_extent(e); 26.134 - e = vd.remove_extent(); 26.135 - } 26.136 + insertVirtualDisk(vd); 26.137 + 26.138 + return vd; 26.139 } 26.140 - return; 26.141 - } 26.142 26.143 - /* 26.144 - * reset the expiry time for a virtual disk 26.145 - */ 26.146 - 26.147 - public void refresh_virtual_disk(String key, Date expiry) { 26.148 - VirtualDisk vd = (VirtualDisk) key_hash.get(key); 26.149 - if (vd != null) { 26.150 - vd.set_expiry(expiry); 26.151 - } 26.152 - } 26.153 + /** 26.154 + * Delete a virtual disk, and put its extents back into the free pool. 26.155 + * @param key The key of the disk to delete. 26.156 + */ 26.157 + public void deleteVirtualDisk(String key) { 26.158 + VirtualDisk vd; 26.159 26.160 - /* 26.161 - * create a new virtual block device 26.162 - */ 26.163 - public VirtualBlockDevice create_virtual_block_device( 26.164 - String key, 26.165 - int domain, 26.166 - int vbd_num, 26.167 - String mode) { 26.168 - VirtualBlockDevice vbd = new VirtualBlockDevice(); 26.169 - VirtualDisk vd = get_virtual_disk_key(key); 26.170 + vd = (VirtualDisk) virtualDisks.get(key); 26.171 + if (vd != null) { 26.172 + Extent e; 26.173 + 26.174 + virtualDisks.remove(key); 26.175 26.176 - if (vd == null) { 26.177 - System.err.println( 26.178 - "create virtual block device error: unknown key " + "[" + key + "]"); 26.179 - return null; 26.180 + e = vd.removeExtent(); 26.181 + while (e != null) { 26.182 + freeDisk.addExtent(e); 26.183 + e = vd.removeExtent(); 26.184 + } 26.185 + } 26.186 } 26.187 26.188 - vbd.key = key; 26.189 - vbd.domain = domain; 26.190 - vbd.vbdnum = vbd_num; 26.191 + /** 26.192 + * Create a new virtual block device. 26.193 + * @param vd The virtual disk to expose. 26.194 + * @param domain The domain to create the device for. 26.195 + * @param vbdNum The block device number to use. 26.196 + * @param mode The mode to create the device with. 26.197 + * @return The newly created virtual block device. 26.198 + */ 26.199 + public VirtualBlockDevice createVirtualBlockDevice( 26.200 + VirtualDisk vd, 26.201 + int domain, 26.202 + int vbdNum, 26.203 + Mode mode) { 26.204 + VirtualBlockDevice vbd = 26.205 + new VirtualBlockDevice(vd, domain, vbdNum, mode); 26.206 + 26.207 + insertVirtualBlockDevice(vbd); 26.208 + 26.209 + return vbd; 26.210 + } 26.211 26.212 - if (mode.equals(Mode.READ_ONLY.toString()) 26.213 - || mode.equals("RO") 26.214 - || mode.equals("ro")) { 26.215 - vbd.mode = Mode.READ_ONLY; 26.216 - } else if ( 26.217 - mode.equals(Mode.READ_WRITE.toString()) 26.218 - || mode.equals("RW") 26.219 - || mode.equals("rw")) { 26.220 - vbd.mode = Mode.READ_WRITE; 26.221 - } else { 26.222 - System.err.println( 26.223 - "create virtual block device error: unknown mode " + "[" + mode + "]"); 26.224 - return null; 26.225 + /** 26.226 + * Delete a virtual block device. 26.227 + * @param domain Domain owning the device. 26.228 + * @param vbdNum The vbd number within the domain. 26.229 + */ 26.230 + public void deleteVirtualBlockDevice(int domain, int vbdNum) { 26.231 + Object hash = hashVBD(domain, vbdNum); 26.232 + virtualBlockDevices.remove(hash); 26.233 + } 26.234 + 26.235 + /** 26.236 + * Flush all virtual block devices. 26.237 + */ 26.238 + public void flushVirtualBlockDevices() { 26.239 + /* isn't automatic garbage collection wonderful? */ 26.240 + virtualBlockDevices = new LinkedHashMap(100); 26.241 + } 26.242 + 26.243 + /** 26.244 + * Insert a new virtual disk into the map. 26.245 + * @param vd The disk to insert. 26.246 + */ 26.247 + void insertVirtualDisk(VirtualDisk vd) { 26.248 + virtualDisks.put(vd.getKey(), vd); 26.249 + } 26.250 + 26.251 + /** 26.252 + * Insert a new virtual block device into the map. 26.253 + * @param vbd The device to insert. 26.254 + */ 26.255 + void insertVirtualBlockDevice(VirtualBlockDevice vbd) { 26.256 + Object hash = hashVBD(vbd.getDomain(), vbd.getVbdNum()); 26.257 + virtualBlockDevices.put(hash, vbd); 26.258 } 26.259 26.260 - add_virtual_block_device(vbd); 26.261 - 26.262 - return vbd; 26.263 - } 26.264 - 26.265 - /* 26.266 - * delete a virtual block device 26.267 - */ 26.268 - public void delete_virtual_block_device(int domain, int vbd_num) { 26.269 - Object hash = get_vbd_hash(domain, vbd_num); 26.270 - virtual_block_devices.remove(hash); 26.271 - } 26.272 - 26.273 - /* 26.274 - * flush all virtual block devices 26.275 - */ 26.276 - public void flush_virtual_block_devices() { 26.277 - /* isn't automatic garbage collection wonderful? */ 26.278 - virtual_block_devices = new Hashtable(100); 26.279 - } 26.280 - 26.281 - public void add_virtual_disk(VirtualDisk vd) { 26.282 - virtual_disks.add(vd); 26.283 - key_hash.put(vd.getKey(), vd); 26.284 - } 26.285 + /** 26.286 + * Hash a virtual block device. 26.287 + * @param domain The VBD's domain. 26.288 + * @param vbdNum The VBD's number within the domain. 26.289 + * @return A suitable hash key. 26.290 + */ 26.291 + Object hashVBD(int domain, int vbdNum) { 26.292 + return new Integer(domain * 16 + vbdNum); 26.293 + } 26.294 26.295 - public void add_virtual_block_device(VirtualBlockDevice vbd) { 26.296 - Object hash = get_vbd_hash(vbd.domain, vbd.vbdnum); 26.297 - virtual_block_devices.put(hash, vbd); 26.298 - } 26.299 - 26.300 - Object get_vbd_hash(int domain, int vbd_num) { 26.301 - return new Integer(domain * 16 + vbd_num); 26.302 - } 26.303 - 26.304 - public void add_free(VirtualDisk vd) { 26.305 - free_disk = vd; 26.306 - } 26.307 - 26.308 - public String dump_virtualblockdevices() { 26.309 - StringBuffer sb = new StringBuffer(); 26.310 - boolean first = true; 26.311 - 26.312 - for (Enumeration enumeration = virtual_block_devices.elements(); 26.313 - enumeration.hasMoreElements(); 26.314 - ) { 26.315 - VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement(); 26.316 - if (first) { 26.317 - sb.append(vbd.dump(true)); 26.318 - first = false; 26.319 - } 26.320 - 26.321 - sb.append(vbd.dump(false)); 26.322 + /** 26.323 + * Set a new free disk. 26.324 + * @param vd The free disk to set. 26.325 + */ 26.326 + void setFreeDisk(VirtualDisk vd) { 26.327 + freeDisk = vd; 26.328 } 26.329 26.330 - return sb.toString(); 26.331 - } 26.332 + /** 26.333 + * Dump the data in the VirtualDiskManager in XML form. 26.334 + * @param out The output writer to dump to. 26.335 + */ 26.336 + void dumpAsXML(PrintWriter out) { 26.337 + out.println("<free>"); 26.338 + freeDisk.dumpAsXML(out); 26.339 + out.println("</free>"); 26.340 + out.println("<virtual_disks>"); 26.341 + Iterator i = virtualDisks.values().iterator(); 26.342 + while (i.hasNext()) { 26.343 + VirtualDisk vd = (VirtualDisk) i.next(); 26.344 + vd.dumpAsXML(out); 26.345 + } 26.346 + out.println("</virtual_disks>"); 26.347 + out.println("<virtual_block_devices>"); 26.348 + i = virtualBlockDevices.values().iterator(); 26.349 + while (i.hasNext()) { 26.350 + VirtualBlockDevice vbd = (VirtualBlockDevice) i.next(); 26.351 + vbd.dumpAsXML(out); 26.352 + } 26.353 26.354 - public void dump_xml(PrintWriter out) { 26.355 - out.println("<free>"); 26.356 - free_disk.dump_xml(out); 26.357 - out.println("</free>"); 26.358 - out.println("<virtual_disks>"); 26.359 - for (int i = 0; i < virtual_disks.size(); i++) { 26.360 - VirtualDisk vd = (VirtualDisk) virtual_disks.get(i); 26.361 - vd.dump_xml(out); 26.362 - } 26.363 - out.println("</virtual_disks>"); 26.364 - out.println("<virtual_block_devices>"); 26.365 - for (Enumeration enumeration = virtual_block_devices.elements(); 26.366 - enumeration.hasMoreElements(); 26.367 - ) { 26.368 - VirtualBlockDevice vbd = (VirtualBlockDevice) enumeration.nextElement(); 26.369 - vbd.dump_xml(out); 26.370 + out.println("</virtual_block_devices>"); 26.371 } 26.372 26.373 - out.println("</virtual_block_devices>"); 26.374 - 26.375 - return; 26.376 - } 26.377 - 26.378 - /*************************************************************************/ 26.379 - 26.380 - public int getVirtualDiskCount() { 26.381 - return virtual_disks.size(); 26.382 - } 26.383 + /** 26.384 + * @return The free disk. 26.385 + */ 26.386 + public VirtualDisk getFreeDisk() { 26.387 + return freeDisk; 26.388 + } 26.389 26.390 - public VirtualDisk getVirtualDisk(int index) { 26.391 - return (VirtualDisk) virtual_disks.get(index); 26.392 - } 26.393 + /** 26.394 + * @return An iterator over the virtual block devices. 26.395 + */ 26.396 + public Iterator getVirtualBlockDevices() { 26.397 + return virtualBlockDevices.values().iterator(); 26.398 + } 26.399 26.400 - public VirtualDisk getFreeVirtualDisk() { 26.401 - return free_disk; 26.402 - } 26.403 - 26.404 - public Enumeration getVirtualBlockDevices() { 26.405 - return virtual_block_devices.elements(); 26.406 - } 26.407 + /** 26.408 + * @return An iterator over the virtual disks. 26.409 + */ 26.410 + public Iterator getVirtualDisks() { 26.411 + return virtualDisks.values().iterator(); 26.412 + } 26.413 }
27.1 --- a/tools/control/src/org/xenoserver/control/XML.java Mon Jul 07 15:21:46 2003 +0000 27.2 +++ b/tools/control/src/org/xenoserver/control/XML.java Tue Jul 08 11:07:33 2003 +0000 27.3 @@ -19,107 +19,102 @@ import javax.xml.parsers.ParserConfigura 27.4 import org.w3c.dom.Document; 27.5 import org.xml.sax.SAXException; 27.6 import org.xml.sax.SAXParseException; 27.7 - 27.8 -public class 27.9 -XML 27.10 -{ 27.11 - static Document document = null; 27.12 27.13 - /* 27.14 - * dump partition manager and virtual disk manager state to filename 27.15 - */ 27.16 - 27.17 - public static void 27.18 - dump_state (PartitionManager pm, VirtualDiskManager vdm, String filename) 27.19 - { 27.20 - PrintWriter out; 27.21 +/** 27.22 + * Utility class for loading and saving state through XML files. 27.23 + */ 27.24 +public class XML { 27.25 + /** The document we are reading/writing. */ 27.26 + private static Document document = null; 27.27 27.28 - try 27.29 - { 27.30 - out = new PrintWriter(new BufferedWriter(new FileWriter(filename))); 27.31 - } 27.32 - catch (IOException e) 27.33 - { 27.34 - System.err.println ("XML.dump_state error [" + filename + "]"); 27.35 - System.err.println (e); 27.36 - return; 27.37 - } 27.38 + /** 27.39 + * Save the state of the managers to the configuration file given. 27.40 + * @param pm The PartitionManager to save. 27.41 + * @param vdm The VirtualDiskManager to save. 27.42 + * @param filename The configuration filename to save to. 27.43 + */ 27.44 + public static void saveState( 27.45 + PartitionManager pm, 27.46 + VirtualDiskManager vdm, 27.47 + String filename) { 27.48 + PrintWriter out; 27.49 27.50 - out.println("<?xml version=\"1.0\"?>"); 27.51 - out.println("<vdmanager>"); 27.52 - pm.dump_xml(out); 27.53 - vdm.dump_xml(out); 27.54 - out.println("</vdmanager>"); 27.55 - 27.56 - out.close(); 27.57 - return; 27.58 - } 27.59 + try { 27.60 + out = new PrintWriter(new BufferedWriter(new FileWriter(filename))); 27.61 + } catch (IOException e) { 27.62 + System.err.println("XML.dump_state error [" + filename + "]"); 27.63 + System.err.println(e); 27.64 + return; 27.65 + } 27.66 27.67 - /* 27.68 - * load partition manager and virtual disk manager state from filename 27.69 - */ 27.70 - public static void 27.71 - load_state (PartitionManager pm, VirtualDiskManager vdm, String filename) 27.72 - { 27.73 - if (document == null) 27.74 - { 27.75 - load_file (filename); 27.76 + out.println("<?xml version=\"1.0\"?>"); 27.77 + out.println("<vdmanager>"); 27.78 + pm.dumpAsXML(out); 27.79 + vdm.dumpAsXML(out); 27.80 + out.println("</vdmanager>"); 27.81 + 27.82 + out.close(); 27.83 + return; 27.84 } 27.85 27.86 - XMLHelper.parse(pm, vdm, document); 27.87 - } 27.88 - 27.89 - /* 27.90 - * load XML from disk 27.91 - */ 27.92 - static void 27.93 - load_file (String filename) 27.94 - { 27.95 - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 27.96 - // factory.setNamespaceAware(true); 27.97 - // factory.setValidating(true); 27.98 + /** 27.99 + * Load the state of the managers from the given configuration file. 27.100 + * @param pm The PartitionManager to load. 27.101 + * @param vdm The VirtualDomainManager to load. 27.102 + * @param filename The filename to read the configuration from. 27.103 + */ 27.104 + public static void loadState( 27.105 + PartitionManager pm, 27.106 + VirtualDiskManager vdm, 27.107 + String filename) { 27.108 + if (document == null) { 27.109 + loadFile(filename); 27.110 + } 27.111 27.112 - try 27.113 - { 27.114 - File file = new File(filename); 27.115 - 27.116 - DocumentBuilder builder = factory.newDocumentBuilder(); 27.117 - document = builder.parse(file); 27.118 + XMLHelper.parse(pm, vdm, document); 27.119 } 27.120 - catch (SAXParseException spe) /* error generated by parser */ 27.121 - { 27.122 - System.err.println ("xml parser exception on line " + 27.123 - spe.getLineNumber() + 27.124 - " for uri " + spe.getSystemId()); 27.125 - System.err.println (spe.getMessage()); 27.126 + 27.127 + /** 27.128 + * Load an XML file and parse it into a Document. 27.129 + * @param filename The file to load. 27.130 + */ 27.131 + private static void loadFile(String filename) { 27.132 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 27.133 + 27.134 + try { 27.135 + File file = new File(filename); 27.136 27.137 - Exception x = spe; 27.138 - if (spe.getException() != null) 27.139 - x = spe.getException(); 27.140 - x.printStackTrace(); 27.141 - System.exit(1); 27.142 - } 27.143 - catch (SAXException sxe) 27.144 - { 27.145 - Exception e = sxe; 27.146 - if (sxe.getException() != null) 27.147 - e = sxe.getException(); 27.148 - e.printStackTrace(); 27.149 - System.exit(1); 27.150 + DocumentBuilder builder = factory.newDocumentBuilder(); 27.151 + document = builder.parse(file); 27.152 + } catch (SAXParseException spe) /* error generated by parser */ { 27.153 + System.err.println( 27.154 + "xml parser exception on line " 27.155 + + spe.getLineNumber() 27.156 + + " for uri " 27.157 + + spe.getSystemId()); 27.158 + System.err.println(spe.getMessage()); 27.159 + 27.160 + Exception x = spe; 27.161 + if (spe.getException() != null) { 27.162 + x = spe.getException(); 27.163 + } 27.164 + x.printStackTrace(); 27.165 + System.exit(1); 27.166 + } catch (SAXException sxe) { 27.167 + Exception e = sxe; 27.168 + if (sxe.getException() != null) { 27.169 + e = sxe.getException(); 27.170 + } 27.171 + e.printStackTrace(); 27.172 + System.exit(1); 27.173 + } catch (ParserConfigurationException pce) { 27.174 + pce.printStackTrace(); 27.175 + } catch (FileNotFoundException fnfe) { 27.176 + System.err.println( 27.177 + "warning: state file not found [" + filename + "]"); 27.178 + } catch (IOException ioe) { 27.179 + ioe.printStackTrace(); 27.180 + } 27.181 + return; 27.182 } 27.183 - catch (ParserConfigurationException pce) 27.184 - { 27.185 - pce.printStackTrace(); 27.186 - } 27.187 - catch (FileNotFoundException fnfe) 27.188 - { 27.189 - System.err.println ("warning: state file not found [" + 27.190 - filename + "]"); 27.191 - } 27.192 - catch (IOException ioe) 27.193 - { 27.194 - ioe.printStackTrace(); 27.195 - } 27.196 - return; 27.197 - } 27.198 }
28.1 --- a/tools/control/src/org/xenoserver/control/XMLHelper.java Mon Jul 07 15:21:46 2003 +0000 28.2 +++ b/tools/control/src/org/xenoserver/control/XMLHelper.java Tue Jul 08 11:07:33 2003 +0000 28.3 @@ -8,201 +8,216 @@ package org.xenoserver.control; 28.4 import java.util.Date; 28.5 28.6 import org.w3c.dom.Document; 28.7 -import org.w3c.dom.Element; 28.8 import org.w3c.dom.Node; 28.9 import org.w3c.dom.NodeList; 28.10 28.11 -public class 28.12 -XMLHelper 28.13 -{ 28.14 - static void 28.15 - dump_document (Document document) 28.16 - { 28.17 - dump_element(document.getDocumentElement(), 0); 28.18 - } 28.19 +/** 28.20 + * XMLHelper contains helper methods used to parse the XML state files. 28.21 + */ 28.22 +class XMLHelper { 28.23 + /** 28.24 + * Find a subnode with the specified name. 28.25 + * @param name Name to look for. 28.26 + * @param node Node from which to start search. 28.27 + * @return The first subnode found, or null if none. 28.28 + */ 28.29 + private static Node getSubNode(String name, Node node) { 28.30 + if (node.getNodeType() != Node.ELEMENT_NODE) { 28.31 + System.err.println("Error: Search node not of element type"); 28.32 + return null; 28.33 + } 28.34 + 28.35 + if (!node.hasChildNodes()) { 28.36 + return null; 28.37 + } 28.38 28.39 - static void 28.40 - dump_element (Element element, int indent) 28.41 - { 28.42 - NodeList nl = element.getChildNodes(); 28.43 + NodeList list = node.getChildNodes(); 28.44 + for (int i = 0; i < list.getLength(); i++) { 28.45 + Node subnode = list.item(i); 28.46 + if (subnode.getNodeType() == Node.ELEMENT_NODE) { 28.47 + if (subnode.getNodeName() == name) { 28.48 + return subnode; 28.49 + } 28.50 + } 28.51 + } 28.52 + return null; 28.53 + } 28.54 28.55 - System.out.println ("<" + element.getTagName() + ">"); 28.56 - dump_nodelist(nl, indent + 1); 28.57 - System.out.println("</" + element.getTagName() + ">"); 28.58 - } 28.59 + /** 28.60 + * Get all the text of a given node. 28.61 + * @param node The node to examine. 28.62 + * @return The node's text. 28.63 + */ 28.64 + private static String getText(Node node) { 28.65 + StringBuffer result = new StringBuffer(); 28.66 + if (node == null || !node.hasChildNodes()) { 28.67 + return ""; 28.68 + } 28.69 28.70 - static void 28.71 - dump_nodelist (NodeList nl, int indent) 28.72 - { 28.73 - for (int loop = 0; loop < nl.getLength(); loop++) 28.74 - { 28.75 - Node node = nl.item(loop); 28.76 - switch (node.getNodeType()) 28.77 - { 28.78 - case Node.ELEMENT_NODE : 28.79 - { 28.80 - dump_element((Element)node, indent); 28.81 - break; 28.82 - } 28.83 - case Node.TEXT_NODE : 28.84 - { 28.85 - System.out.println("TEXT: " + node.getNodeValue()); 28.86 - break; 28.87 - } 28.88 - default : 28.89 - { 28.90 - System.out.println("NODE: " + node.getNodeType()); 28.91 - } 28.92 - } 28.93 + NodeList list = node.getChildNodes(); 28.94 + for (int i = 0; i < list.getLength(); i++) { 28.95 + Node subnode = list.item(i); 28.96 + if (subnode.getNodeType() == Node.TEXT_NODE) { 28.97 + result.append(subnode.getNodeValue()); 28.98 + } 28.99 + } 28.100 + return result.toString(); 28.101 } 28.102 - } 28.103 + 28.104 + /** 28.105 + * Parse the given configuration document and configure the managers. 28.106 + * @param pm PartitionManager instance to configure. 28.107 + * @param vdm VirtualDomainManager instance to configure. 28.108 + * @param document Document to parse. 28.109 + */ 28.110 + static void parse( 28.111 + PartitionManager pm, 28.112 + VirtualDiskManager vdm, 28.113 + Document document) { 28.114 + if (document == null) { 28.115 + return; 28.116 + } 28.117 + 28.118 + /* parse partitions */ 28.119 + parsePartitions(pm, document.getElementsByTagName("partition")); 28.120 28.121 - static Node 28.122 - get_subnode (String name, Node node) 28.123 - { 28.124 - if (node.getNodeType() != Node.ELEMENT_NODE) 28.125 - { 28.126 - System.err.println("Error: Search node not of element type"); 28.127 - return null; 28.128 + /* parse virtual disks */ 28.129 + NodeList list = document.getElementsByTagName("virtual_disk"); 28.130 + for (int i = 0; i < list.getLength(); i++) { 28.131 + Node subnode = list.item(i); 28.132 + String parent = subnode.getParentNode().getNodeName(); 28.133 + VirtualDisk vd = parseVirtualDisk(subnode); 28.134 + 28.135 + if (parent.equals("free")) { 28.136 + vdm.setFreeDisk(vd); 28.137 + } else if (parent.equals("virtual_disks")) { 28.138 + vdm.insertVirtualDisk(vd); 28.139 + } else { 28.140 + System.out.println( 28.141 + "XML parse error: unknown parent for virtual_disk " 28.142 + + "[" 28.143 + + parent 28.144 + + "]"); 28.145 + } 28.146 + } 28.147 + 28.148 + /* parse virtual block devices */ 28.149 + parseVirtualBlockDevices( 28.150 + vdm, 28.151 + document.getElementsByTagName("virtual_block_device")); 28.152 + 28.153 + return; 28.154 } 28.155 28.156 - if (!node.hasChildNodes()) return null; 28.157 - 28.158 - NodeList list = node.getChildNodes(); 28.159 - for (int i=0; i < list.getLength(); i++) 28.160 - { 28.161 - Node subnode = list.item(i); 28.162 - if (subnode.getNodeType() == Node.ELEMENT_NODE) 28.163 - { 28.164 - if (subnode.getNodeName() == name) return subnode; 28.165 - } 28.166 - } 28.167 - return null; 28.168 - } 28.169 - 28.170 - static String 28.171 - get_text (Node node) 28.172 - { 28.173 - StringBuffer result = new StringBuffer(); 28.174 - if (node==null || !node.hasChildNodes()) return ""; 28.175 + /** 28.176 + * Parse a node representing a virtual disk. 28.177 + * @param node The node to parse. 28.178 + * @return The VirtualDisk this node represents. 28.179 + */ 28.180 + private static VirtualDisk parseVirtualDisk(Node node) { 28.181 + VirtualDisk vd; 28.182 + Date date = new Date(); 28.183 + NodeList list; 28.184 28.185 - NodeList list = node.getChildNodes(); 28.186 - for (int i=0; i < list.getLength(); i++) 28.187 - { 28.188 - Node subnode = list.item(i); 28.189 - if (subnode.getNodeType() == Node.TEXT_NODE) 28.190 - { 28.191 - result.append(subnode.getNodeValue()); 28.192 - } 28.193 - } 28.194 - return result.toString(); 28.195 - } 28.196 + long timestamp = 28.197 + Long.parseLong( 28.198 + XMLHelper.getText(XMLHelper.getSubNode("expiry", node))); 28.199 + if (timestamp == 0) { 28.200 + date = null; 28.201 + } else { 28.202 + date.setTime(timestamp); 28.203 + } 28.204 + vd = 28.205 + new VirtualDisk( 28.206 + XMLHelper.getText(XMLHelper.getSubNode("name", node)), 28.207 + date, 28.208 + XMLHelper.getText(XMLHelper.getSubNode("key", node))); 28.209 28.210 - static void 28.211 - parse (PartitionManager pm, VirtualDiskManager vdm, Document document) 28.212 - { 28.213 - if (document == null) return; 28.214 - 28.215 - /* parse partitions */ 28.216 - parse_partitions(pm, document.getElementsByTagName("partition")); 28.217 + list = XMLHelper.getSubNode("extents", node).getChildNodes(); 28.218 + for (int i = 0; i < list.getLength(); i++) { 28.219 + Node enode = list.item(i); 28.220 28.221 - /* parse virtual disks */ 28.222 - NodeList list = document.getElementsByTagName("virtual_disk"); 28.223 - for (int i = 0; i < list.getLength(); i++) 28.224 - { 28.225 - Node subnode = list.item(i); 28.226 - String parent = subnode.getParentNode().getNodeName(); 28.227 - VirtualDisk vd = parse_virtual_disk(subnode); 28.228 + if (enode.getNodeType() == Node.ELEMENT_NODE 28.229 + && enode.getNodeName().equals("extent")) { 28.230 + Extent extent = 28.231 + new Extent( 28.232 + Integer.parseInt( 28.233 + XMLHelper.getText( 28.234 + XMLHelper.getSubNode("disk", enode))), 28.235 + Long.parseLong( 28.236 + XMLHelper.getText( 28.237 + XMLHelper.getSubNode("size", enode))), 28.238 + Long.parseLong( 28.239 + XMLHelper.getText( 28.240 + XMLHelper.getSubNode("offset", enode)))); 28.241 + vd.addExtent(extent); 28.242 + } 28.243 + } 28.244 28.245 - if (parent.equals("free")) 28.246 - { 28.247 - vdm.add_free(vd); 28.248 - } 28.249 - else if (parent.equals("virtual_disks")) 28.250 - { 28.251 - vdm.add_virtual_disk(vd); 28.252 - } 28.253 - else 28.254 - { 28.255 - System.out.println ("XML parse error: unknown parent for virtual_disk " 28.256 - + "[" + parent + "]"); 28.257 - } 28.258 + return vd; 28.259 } 28.260 28.261 - /* parse virtual block devices */ 28.262 - parse_virtual_block_devices(vdm, document.getElementsByTagName("virtual_block_device")); 28.263 - 28.264 - return; 28.265 - } 28.266 + /** 28.267 + * Parse a list of partition nodes. 28.268 + * @param pm The partition manager to configure. 28.269 + * @param nl The list of partition nodes. 28.270 + */ 28.271 + private static void parsePartitions(PartitionManager pm, NodeList nl) { 28.272 + Partition partition; 28.273 28.274 - static VirtualDisk 28.275 - parse_virtual_disk(Node node) 28.276 - { 28.277 - VirtualDisk vd; 28.278 - Date date = new Date(); 28.279 - NodeList list; 28.280 + for (int loop = 0; loop < nl.getLength(); loop++) { 28.281 + Node node = nl.item(loop); 28.282 28.283 - long timestamp = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("expiry", node))); 28.284 - if ( timestamp == 0 ) 28.285 - date = null; 28.286 - else 28.287 - date.setTime( timestamp ); 28.288 - vd = new VirtualDisk(XMLHelper.get_text(XMLHelper.get_subnode("name", node)), 28.289 - date, 28.290 - XMLHelper.get_text(XMLHelper.get_subnode("key", node))); 28.291 + partition = 28.292 + new Partition( 28.293 + Integer.parseInt( 28.294 + XMLHelper.getText(XMLHelper.getSubNode("major", node))), 28.295 + Integer.parseInt( 28.296 + XMLHelper.getText(XMLHelper.getSubNode("minor", node))), 28.297 + Integer.parseInt( 28.298 + XMLHelper.getText( 28.299 + XMLHelper.getSubNode("blocks", node))), 28.300 + Integer.parseInt( 28.301 + XMLHelper.getText( 28.302 + XMLHelper.getSubNode("start_sect", node))), 28.303 + Integer.parseInt( 28.304 + XMLHelper.getText( 28.305 + XMLHelper.getSubNode("nr_sects", node))), 28.306 + XMLHelper.getText(XMLHelper.getSubNode("name", node)), 28.307 + true); 28.308 28.309 - list = XMLHelper.get_subnode("extents", node).getChildNodes(); 28.310 - for (int i = 0; i < list.getLength(); i++) 28.311 - { 28.312 - Node enode = list.item(i); 28.313 - 28.314 - if (enode.getNodeType() == Node.ELEMENT_NODE && 28.315 - enode.getNodeName().equals("extent")) 28.316 - { 28.317 - Extent extent = new Extent(); 28.318 - 28.319 - extent.disk = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("disk", enode))); 28.320 - extent.size = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("size", enode))); 28.321 - extent.offset = Long.parseLong(XMLHelper.get_text(XMLHelper.get_subnode("offset", enode))); 28.322 - vd.add_extent(extent); 28.323 - } 28.324 + pm.addXenoPartition(partition); 28.325 + } 28.326 } 28.327 28.328 - return vd; 28.329 - } 28.330 - 28.331 - static void 28.332 - parse_partitions (PartitionManager pm, NodeList nl) 28.333 - { 28.334 - Partition partition; 28.335 - 28.336 - for (int loop = 0; loop < nl.getLength(); loop++) 28.337 - { 28.338 - Node node = nl.item(loop); 28.339 + /** 28.340 + * Parse a list of virtual block device nodes. 28.341 + * @param vdm The VirtualDiskManager to configure. 28.342 + * @param nl The node list. 28.343 + */ 28.344 + private static void parseVirtualBlockDevices( 28.345 + VirtualDiskManager vdm, 28.346 + NodeList nl) { 28.347 + for (int loop = 0; loop < nl.getLength(); loop++) { 28.348 + Node node = nl.item(loop); 28.349 + Mode mode; 28.350 28.351 - partition = new Partition(); 28.352 - partition.major = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("major", node))); 28.353 - partition.minor = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("minor", node))); 28.354 - partition.blocks = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("blocks", node))); 28.355 - partition.start_sect = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("start_sect", node))); 28.356 - partition.nr_sects = Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("nr_sects", node))); 28.357 - partition.name = XMLHelper.get_text(XMLHelper.get_subnode("name", node)); 28.358 - 28.359 - pm.add_xeno_partition(partition); 28.360 - } 28.361 - } 28.362 + if (XMLHelper 28.363 + .getText(XMLHelper.getSubNode("mode", node)) 28.364 + .equals("rw")) { 28.365 + mode = Mode.READ_WRITE; 28.366 + } else { 28.367 + mode = Mode.READ_ONLY; 28.368 + } 28.369 28.370 - static void 28.371 - parse_virtual_block_devices (VirtualDiskManager vdm, NodeList nl) 28.372 - { 28.373 - for (int loop = 0; loop < nl.getLength(); loop++) 28.374 - { 28.375 - Node node = nl.item(loop); 28.376 - 28.377 - vdm.create_virtual_block_device(XMLHelper.get_text(XMLHelper.get_subnode("key", node)), 28.378 - Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("domain", node))), 28.379 - Integer.parseInt(XMLHelper.get_text(XMLHelper.get_subnode("vbdnum", node))), 28.380 - XMLHelper.get_text(XMLHelper.get_subnode("mode", node))); 28.381 + vdm.createVirtualBlockDevice( 28.382 + vdm.getVirtualDisk( 28.383 + XMLHelper.getText(XMLHelper.getSubNode("key", node))), 28.384 + Integer.parseInt( 28.385 + XMLHelper.getText(XMLHelper.getSubNode("domain", node))), 28.386 + Integer.parseInt( 28.387 + XMLHelper.getText(XMLHelper.getSubNode("vbdnum", node))), 28.388 + mode); 28.389 + } 28.390 } 28.391 - } 28.392 }