aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>2003-07-10 11:13:53 +0000
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>2003-07-10 11:13:53 +0000
commit005477225b0845d60d14178287168b0e4e49ee5f (patch)
treefef7c9be73928b5bbd90985338c861bababa9313 /tools
parent19786bd474eb68aae77716ec7717c3d189ec59cb (diff)
downloadxen-005477225b0845d60d14178287168b0e4e49ee5f.tar.gz
xen-005477225b0845d60d14178287168b0e4e49ee5f.tar.bz2
xen-005477225b0845d60d14178287168b0e4e49ee5f.zip
bitkeeper revision 1.332 (3f0d4a71ScYIvhpYjrv_aLLacdn4Ig)
Remove on-disk storage of virtual block devices Implement retrieving VBD info from /proc remove VBD delete and flush commands as VBDs go away by themselves when their domains are destroyed
Diffstat (limited to 'tools')
-rw-r--r--tools/control/src/org/xenoserver/cmdline/Main.java2
-rw-r--r--tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java41
-rw-r--r--tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java31
-rw-r--r--tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java18
-rw-r--r--tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java7
-rw-r--r--tools/control/src/org/xenoserver/control/CommandVbdCreate.java2
-rw-r--r--tools/control/src/org/xenoserver/control/CommandVbdDelete.java43
-rw-r--r--tools/control/src/org/xenoserver/control/CommandVbdFlush.java14
-rw-r--r--tools/control/src/org/xenoserver/control/CommandVbdList.java66
-rw-r--r--tools/control/src/org/xenoserver/control/CommandVdDelete.java15
-rw-r--r--tools/control/src/org/xenoserver/control/VirtualBlockDevice.java15
-rw-r--r--tools/control/src/org/xenoserver/control/VirtualDiskManager.java66
-rw-r--r--tools/control/src/org/xenoserver/control/XMLHelper.java38
13 files changed, 94 insertions, 264 deletions
diff --git a/tools/control/src/org/xenoserver/cmdline/Main.java b/tools/control/src/org/xenoserver/cmdline/Main.java
index caf3451437..3b8cc554b7 100644
--- a/tools/control/src/org/xenoserver/cmdline/Main.java
+++ b/tools/control/src/org/xenoserver/cmdline/Main.java
@@ -36,8 +36,6 @@ public class Main {
};
private static final CommandParser vbdcommands[] =
{ new ParseVbdCreate(),
- new ParseVbdDelete(),
- new ParseVbdFlush(),
new ParseVbdShow()
};
private static final CommandParser commands[] =
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
deleted file mode 100644
index f0a9786b3e..0000000000
--- a/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdDelete;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdDelete extends CommandParser {
- public void parse(Defaults d, LinkedList args)
- throws ParseFailedException, CommandFailedException {
- int domain_id = getIntParameter(args, 'n', 0);
- int vbd_num = getIntParameter(args, 'v', -1);
-
- if (domain_id == 0) {
- throw new ParseFailedException("Expected -n<domain_id>");
- }
- if (vbd_num == -1) {
- throw new ParseFailedException("Expected -v<vbd_num>");
- }
- loadState();
- String output = new CommandVbdDelete(domain_id, vbd_num).execute();
- if (output != null) {
- System.out.println(output);
- }
- saveState();
- }
-
- public String getName() {
- return "delete";
- }
-
- public String getUsage() {
- return "-n<domain> -v<vbd>";
- }
-
- public String getHelpText() {
- return "Deletes the specified virtual block device from the specified domain.";
- }
-
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
deleted file mode 100644
index 30439000e4..0000000000
--- a/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package org.xenoserver.cmdline;
-
-import java.util.LinkedList;
-
-import org.xenoserver.control.CommandFailedException;
-import org.xenoserver.control.CommandVbdFlush;
-import org.xenoserver.control.Defaults;
-
-public class ParseVbdFlush extends CommandParser {
- public void parse(Defaults d, LinkedList args)
- throws ParseFailedException, CommandFailedException {
- loadState();
- String output = new CommandVbdFlush().execute();
- if (output != null) {
- System.out.println(output);
- }
- saveState();
- }
-
- public String getName() {
- return "flush";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getHelpText() {
- return "Delete all virtual block devices";
- }
-}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
index b89105d592..b35c9e068d 100644
--- a/tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
+++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
@@ -1,29 +1,29 @@
package org.xenoserver.cmdline;
-import java.util.Iterator;
import java.util.LinkedList;
import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdList;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.Library;
import org.xenoserver.control.VirtualBlockDevice;
-import org.xenoserver.control.VirtualDiskManager;
public class ParseVbdShow extends CommandParser {
public void parse(Defaults d, LinkedList args)
throws ParseFailedException, CommandFailedException {
loadState();
- Iterator i = VirtualDiskManager.IT.getVirtualBlockDevices();
+ CommandVbdList list = new CommandVbdList();
+ list.execute();
+ VirtualBlockDevice[] vbds = list.vbds();
System.out.println("key dom vbd mode");
- while (i.hasNext()) {
- VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
- System.out.println( vbd.getVirtualDisk().getKey()
+ for (int i=0; i<vbds.length; i++) {
+ System.out.println( vbds[i].getVirtualDisk().getKey()
+ " "
- + Library.format(vbd.getDomain(), 3, false)
+ + Library.format(vbds[i].getDomain(), 3, false)
+ " "
- + Library.format(vbd.getVbdNum(), 3, false)
+ + Library.format(vbds[i].getVbdNum(), 3, false)
+ " "
- + vbd.getMode().toString());
+ + vbds[i].getMode().toString());
}
}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
index cfbce4a423..842f977871 100644
--- a/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
+++ b/tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
@@ -10,13 +10,14 @@ public class ParseVdDelete extends CommandParser {
public void parse(Defaults d, LinkedList args)
throws ParseFailedException, CommandFailedException {
String vd_key = getStringParameter(args, 'k', "");
+ boolean force = getFlagParameter(args,'f');
if (vd_key.equals("")) {
throw new ParseFailedException("Expected -k<key>");
}
loadState();
- String output = new CommandVdDelete(vd_key).execute();
+ String output = new CommandVdDelete(vd_key,force).execute();
if (output != null) {
System.out.println(output);
}
@@ -29,11 +30,11 @@ public class ParseVdDelete extends CommandParser {
}
public String getUsage() {
- return "-k<key>";
+ return "-k<key> [-f]";
}
public String getHelpText() {
- return "Deletes the virtual disk with the specified key.";
+ return "Deletes the virtual disk with the specified key. -f forces deletion even if the disk is in use.";
}
}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdCreate.java b/tools/control/src/org/xenoserver/control/CommandVbdCreate.java
index 8ac0883264..3c1c21aa6c 100644
--- a/tools/control/src/org/xenoserver/control/CommandVbdCreate.java
+++ b/tools/control/src/org/xenoserver/control/CommandVbdCreate.java
@@ -45,7 +45,7 @@ public class CommandVbdCreate extends Command {
}
VirtualBlockDevice vbd =
- VirtualDiskManager.IT.createVirtualBlockDevice(
+ new VirtualBlockDevice(
vd,
domain_id,
vbd_num,
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdDelete.java b/tools/control/src/org/xenoserver/control/CommandVbdDelete.java
deleted file mode 100644
index ca1cd1edcb..0000000000
--- a/tools/control/src/org/xenoserver/control/CommandVbdDelete.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Delete a virtual block device. Note that this does not update anything inside
- * Xen, and therefore should only be done if you are certain that the domain has
- * either not been started, or has been destroyed, or you are sure it will not
- * try to access the VBD again. Since the mapping is not removed in Xen, any
- * subsequent changes to the underlying virtual disk will affect the domain,
- * probably adversely.
- */
-public class CommandVbdDelete extends Command {
- /** Domain id to delete from */
- private int domain_id;
- /** VBD number to delete */
- private int vbd_num;
-
- /**
- * Constructor for CommandVbdDelete.
- * @param domain_id Domain ID to delete from
- * @param vbd_num VBD number to delete
- */
- public CommandVbdDelete(int domain_id, int vbd_num) {
- this.domain_id = domain_id;
- this.vbd_num = vbd_num;
- }
-
- /**
- * @see org.xenoserver.control.Command#execute()
- */
- public String execute() throws CommandFailedException {
- if (VirtualDiskManager
- .IT
- .deleteVirtualBlockDevice(domain_id, vbd_num)) {
- return "Deleted VBD " + vbd_num + " from domain " + domain_id;
- } else {
- throw new CommandFailedException(
- "No such virtual block device "
- + vbd_num
- + " in domain "
- + domain_id);
- }
- }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdFlush.java b/tools/control/src/org/xenoserver/control/CommandVbdFlush.java
deleted file mode 100644
index fdb5b122b7..0000000000
--- a/tools/control/src/org/xenoserver/control/CommandVbdFlush.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.xenoserver.control;
-
-/**
- * Flush (delete) all virtual block devices.
- */
-public class CommandVbdFlush extends Command {
- /**
- * @see org.xenoserver.control.Command#execute()
- */
- public String execute() throws CommandFailedException {
- VirtualDiskManager.IT.flushVirtualBlockDevices();
- return "Flushed virtual block devices";
- }
-}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdList.java b/tools/control/src/org/xenoserver/control/CommandVbdList.java
new file mode 100644
index 0000000000..e525ee485f
--- /dev/null
+++ b/tools/control/src/org/xenoserver/control/CommandVbdList.java
@@ -0,0 +1,66 @@
+package org.xenoserver.control;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class CommandVbdList extends Command {
+ /** Array of virtual block devices returned */
+ private VirtualBlockDevice[] array;
+
+ public String execute() throws CommandFailedException {
+ Vector v = new Vector();
+ BufferedReader in;
+ String line;
+
+ try {
+ in = new BufferedReader(new FileReader("/proc/xeno/dom0/vhd"));
+ line = in.readLine();
+ while (line != null) {
+ int domain = -1;
+ int vbdnum = -1;
+ String key = "";
+ Mode mode = Mode.READ_ONLY;
+
+ StringTokenizer st = new StringTokenizer(line);
+ if (st.hasMoreTokens()) {
+ domain = Integer.parseInt(st.nextToken());
+ }
+ if (st.hasMoreTokens()) {
+ vbdnum = Integer.parseInt(st.nextToken());
+ }
+ if (st.hasMoreTokens()) {
+ key = st.nextToken();
+ }
+ if (st.hasMoreTokens()) {
+ if (Integer.parseInt(st.nextToken()) == 2) {
+ mode = Mode.READ_WRITE;
+ }
+ }
+
+ VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key);
+ if (vd == null) {
+ throw new CommandFailedException(
+ "Key " + key + " has no matching virtual disk");
+ }
+ VirtualBlockDevice vbd =
+ new VirtualBlockDevice(vd, domain, vbdnum, mode);
+ v.add(vbd);
+
+ line = in.readLine();
+ }
+ } catch (IOException e) {
+ throw new CommandFailedException("Could not read VBD file", e);
+ }
+
+ array = new VirtualBlockDevice[v.size()];
+ v.toArray(array);
+ return null;
+ }
+
+ public VirtualBlockDevice[] vbds() {
+ return array;
+ }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandVdDelete.java b/tools/control/src/org/xenoserver/control/CommandVdDelete.java
index 6fadde859c..2873cd2beb 100644
--- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java
+++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java
@@ -6,13 +6,16 @@ package org.xenoserver.control;
public class CommandVdDelete extends Command {
/** Key of disk to delete. */
private String key;
+ /** Force deletion? */
+ private boolean force;
/**
* Constructor for CommandVdDelete.
* @param key The key of the disk to delete.
*/
- public CommandVdDelete(String key) {
+ public CommandVdDelete(String key,boolean force) {
this.key = key;
+ this.force = force;
}
/**
@@ -23,6 +26,16 @@ public class CommandVdDelete extends Command {
throw new CommandFailedException(
"Virtual disk " + key + " does not exist");
}
+ if ( !force ) {
+ CommandVbdList list = new CommandVbdList();
+ list.execute();
+ VirtualBlockDevice[] vbds = list.vbds();
+ for (int i=0;i<vbds.length;i++) {
+ if (vbds[i].getVirtualDisk().getKey().equals(key)) {
+ throw new CommandFailedException("Virtual disk " + key + " is in use.");
+ }
+ }
+ }
VirtualDiskManager.IT.deleteVirtualDisk(key);
return "Deleted virtual disk " + key;
diff --git a/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java b/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java
index 6e7c64480a..2b1a5ceb21 100644
--- a/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java
+++ b/tools/control/src/org/xenoserver/control/VirtualBlockDevice.java
@@ -5,8 +5,6 @@
package org.xenoserver.control;
-import java.io.PrintWriter;
-
/**
* A virtual block device; a mapping from a domain-specific number to a virtual
* disk with associated access mode.
@@ -40,19 +38,6 @@ public class VirtualBlockDevice {
}
/**
- * Dump the virtual block device as XML.
- * @param out The writer to dump to.
- */
- void dumpAsXML(PrintWriter out) {
- out.println(" <virtual_block_device>");
- out.println(" <key>" + vd.getKey() + "</key>");
- out.println(" <domain>" + domain + "</domain>");
- out.println(" <vbdnum>" + vbdNum + "</vbdnum>");
- out.println(" <mode>" + mode + "</mode>");
- out.println(" </virtual_block_device>");
- }
-
- /**
* @return This device's virtual disk.
*/
public VirtualDisk getVirtualDisk() {
diff --git a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java
index 179ee079a4..8ff9041e8c 100644
--- a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java
+++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java
@@ -21,8 +21,6 @@ public class VirtualDiskManager {
private VirtualDisk freeDisk;
/** The map of keys to virtual disks. */
private LinkedHashMap virtualDisks = new LinkedHashMap(100);
- /** The map of (domain,vbdnum) to virtual block devices. */
- private LinkedHashMap virtualBlockDevices = new LinkedHashMap(100);
/**
* VDM constructor, private as it's a singleton.
@@ -101,46 +99,6 @@ public class VirtualDiskManager {
}
/**
- * Create a new virtual block device.
- * @param vd The virtual disk to expose.
- * @param domain The domain to create the device for.
- * @param vbdNum The block device number to use.
- * @param mode The mode to create the device with.
- * @return The newly created virtual block device.
- */
- VirtualBlockDevice createVirtualBlockDevice(
- VirtualDisk vd,
- int domain,
- int vbdNum,
- Mode mode) {
- VirtualBlockDevice vbd =
- new VirtualBlockDevice(vd, domain, vbdNum, mode);
-
- insertVirtualBlockDevice(vbd);
-
- return vbd;
- }
-
- /**
- * Delete a virtual block device.
- * @param domain Domain owning the device.
- * @param vbdNum The vbd number within the domain.
- * @return true if the VBD was deleted, false if it does not exist.
- */
- boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
- Object hash = hashVBD(domain, vbdNum);
- return virtualBlockDevices.remove(hash) != null;
- }
-
- /**
- * Flush all virtual block devices.
- */
- void flushVirtualBlockDevices() {
- /* isn't automatic garbage collection wonderful? */
- virtualBlockDevices = new LinkedHashMap(100);
- }
-
- /**
* Insert a new virtual disk into the map.
* @param vd The disk to insert.
*/
@@ -149,15 +107,6 @@ public class VirtualDiskManager {
}
/**
- * Insert a new virtual block device into the map.
- * @param vbd The device to insert.
- */
- void insertVirtualBlockDevice(VirtualBlockDevice vbd) {
- Object hash = hashVBD(vbd.getDomain(), vbd.getVbdNum());
- virtualBlockDevices.put(hash, vbd);
- }
-
- /**
* Hash a virtual block device.
* @param domain The VBD's domain.
* @param vbdNum The VBD's number within the domain.
@@ -190,14 +139,6 @@ public class VirtualDiskManager {
vd.dumpAsXML(out);
}
out.println("</virtual_disks>");
- out.println("<virtual_block_devices>");
- i = virtualBlockDevices.values().iterator();
- while (i.hasNext()) {
- VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
- vbd.dumpAsXML(out);
- }
-
- out.println("</virtual_block_devices>");
}
/**
@@ -208,13 +149,6 @@ public class VirtualDiskManager {
}
/**
- * @return An iterator over the virtual block devices.
- */
- public Iterator getVirtualBlockDevices() {
- return virtualBlockDevices.values().iterator();
- }
-
- /**
* @return An iterator over the virtual disks.
*/
public Iterator getVirtualDisks() {
diff --git a/tools/control/src/org/xenoserver/control/XMLHelper.java b/tools/control/src/org/xenoserver/control/XMLHelper.java
index 1f93844dd2..abdfe924ca 100644
--- a/tools/control/src/org/xenoserver/control/XMLHelper.java
+++ b/tools/control/src/org/xenoserver/control/XMLHelper.java
@@ -100,13 +100,6 @@ class XMLHelper {
+ "]");
}
}
-
- /* parse virtual block devices */
- parseVirtualBlockDevices(
- vdm,
- document.getElementsByTagName("virtual_block_device"));
-
- return;
}
/**
@@ -190,35 +183,4 @@ class XMLHelper {
pm.addXenoPartition(partition);
}
}
-
- /**
- * Parse a list of virtual block device nodes.
- * @param vdm The VirtualDiskManager to configure.
- * @param nl The node list.
- */
- private static void parseVirtualBlockDevices(
- VirtualDiskManager vdm,
- NodeList nl) {
- for (int loop = 0; loop < nl.getLength(); loop++) {
- Node node = nl.item(loop);
- Mode mode;
-
- if (XMLHelper
- .getText(XMLHelper.getSubNode("mode", node))
- .equals("rw")) {
- mode = Mode.READ_WRITE;
- } else {
- mode = Mode.READ_ONLY;
- }
-
- vdm.createVirtualBlockDevice(
- vdm.getVirtualDisk(
- XMLHelper.getText(XMLHelper.getSubNode("key", node))),
- Integer.parseInt(
- XMLHelper.getText(XMLHelper.getSubNode("domain", node))),
- Integer.parseInt(
- XMLHelper.getText(XMLHelper.getSubNode("vbdnum", node))),
- mode);
- }
- }
}