ia64/xen-unstable

changeset 569:a4f6a72f64e0

bitkeeper revision 1.313 (3f0bf8a0YsfImKNTNOOIKMEz2NKZoA)

Add VBD delete and flush commands.
Yay, xenctl-cmdline should now be the union of domctl/xenctl-web/vdmanager's functionality.
author rac61@labyrinth.cl.cam.ac.uk
date Wed Jul 09 11:12:32 2003 +0000 (2003-07-09)
parents 7a7e8d7da0dc
children 6b2bf4c01047
files .rootkeys tools/control/src/org/xenoserver/cmdline/Main.java tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java tools/control/src/org/xenoserver/control/CommandVbdDelete.java tools/control/src/org/xenoserver/control/CommandVbdFlush.java tools/control/src/org/xenoserver/control/VirtualDiskManager.java
line diff
     1.1 --- a/.rootkeys	Wed Jul 09 11:03:26 2003 +0000
     1.2 +++ b/.rootkeys	Wed Jul 09 11:12:32 2003 +0000
     1.3 @@ -31,6 +31,8 @@ 3f05631dswxJX_TpcuG6tBstyHSetg tools/con
     1.4  3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
     1.5  3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
     1.6  3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
     1.7 +3f0bf89f_DkClyexDd4EDwinZJG83A tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
     1.8 +3f0bf89fvzPQqcHBq1xA0XlFiO8tLA tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
     1.9  3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
    1.10  3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
    1.11  3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
    1.12 @@ -50,6 +52,8 @@ 3f05631e_G6wzHhEnpihX0pIkEsbMw tools/con
    1.13  3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
    1.14  3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
    1.15  3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
    1.16 +3f0bf89fcVy1cFU18hPVXkFMMLHLug tools/control/src/org/xenoserver/control/CommandVbdDelete.java
    1.17 +3f0bf8a0aRDXkIGy3liS1oKXIQpeyA tools/control/src/org/xenoserver/control/CommandVbdFlush.java
    1.18  3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
    1.19  3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
    1.20  3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/Main.java	Wed Jul 09 11:03:26 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Wed Jul 09 11:12:32 2003 +0000
     2.3 @@ -36,6 +36,8 @@ public class Main {
     2.4      };
     2.5    private static final CommandParser vbdcommands[] =
     2.6      { new ParseVbdCreate(),
     2.7 +      new ParseVbdDelete(),
     2.8 +      new ParseVbdFlush(),
     2.9        new ParseVbdShow()
    2.10      };
    2.11    private static final CommandParser commands[] =
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java	Wed Jul 09 11:12:32 2003 +0000
     3.3 @@ -0,0 +1,41 @@
     3.4 +package org.xenoserver.cmdline;
     3.5 +
     3.6 +import java.util.LinkedList;
     3.7 +
     3.8 +import org.xenoserver.control.CommandFailedException;
     3.9 +import org.xenoserver.control.CommandVbdDelete;
    3.10 +import org.xenoserver.control.Defaults;
    3.11 +
    3.12 +public class ParseVbdDelete extends CommandParser {
    3.13 +    public void parse(Defaults d, LinkedList args)
    3.14 +        throws ParseFailedException, CommandFailedException {
    3.15 +        int domain_id = getIntParameter(args, 'n', 0);
    3.16 +        int vbd_num = getIntParameter(args, 'v', -1);
    3.17 +
    3.18 +        if (domain_id == 0) {
    3.19 +            throw new ParseFailedException("Expected -n<domain_id>");
    3.20 +        }
    3.21 +        if (vbd_num == -1) {
    3.22 +            throw new ParseFailedException("Expected -v<vbd_num>");
    3.23 +        }
    3.24 +        loadState();
    3.25 +        String output = new CommandVbdDelete(domain_id, vbd_num).execute();
    3.26 +        if (output != null) {
    3.27 +            System.out.println(output);
    3.28 +        }
    3.29 +        saveState();
    3.30 +    }
    3.31 +
    3.32 +    public String getName() {
    3.33 +        return "delete";
    3.34 +    }
    3.35 +
    3.36 +    public String getUsage() {
    3.37 +        return "-n<domain> -v<vbd>";
    3.38 +    }
    3.39 +
    3.40 +    public String getHelpText() {
    3.41 +        return "Deletes the specified virtual block device from the specified domain.";
    3.42 +    }
    3.43 +
    3.44 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java	Wed Jul 09 11:12:32 2003 +0000
     4.3 @@ -0,0 +1,31 @@
     4.4 +package org.xenoserver.cmdline;
     4.5 +
     4.6 +import java.util.LinkedList;
     4.7 +
     4.8 +import org.xenoserver.control.CommandFailedException;
     4.9 +import org.xenoserver.control.CommandVbdFlush;
    4.10 +import org.xenoserver.control.Defaults;
    4.11 +
    4.12 +public class ParseVbdFlush extends CommandParser {
    4.13 +    public void parse(Defaults d, LinkedList args)
    4.14 +        throws ParseFailedException, CommandFailedException {
    4.15 +        loadState();
    4.16 +        String output = new CommandVbdFlush().execute();
    4.17 +        if (output != null) {
    4.18 +            System.out.println(output);
    4.19 +        }
    4.20 +        saveState();
    4.21 +    }
    4.22 +
    4.23 +    public String getName() {
    4.24 +        return "flush";
    4.25 +    }
    4.26 +
    4.27 +    public String getUsage() {
    4.28 +        return "";
    4.29 +    }
    4.30 +
    4.31 +    public String getHelpText() {
    4.32 +        return "Delete all virtual block devices";
    4.33 +    }
    4.34 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdDelete.java	Wed Jul 09 11:12:32 2003 +0000
     5.3 @@ -0,0 +1,43 @@
     5.4 +package org.xenoserver.control;
     5.5 +
     5.6 +/**
     5.7 + * Delete a virtual block device. Note that this does not update anything inside
     5.8 + * Xen, and therefore should only be done if you are certain that the domain has
     5.9 + * either not been started, or has been destroyed, or you are sure it will not
    5.10 + * try to access the VBD again. Since the mapping is not removed in Xen, any
    5.11 + * subsequent changes to the underlying virtual disk will affect the domain,
    5.12 + * probably adversely.
    5.13 + */
    5.14 +public class CommandVbdDelete extends Command {
    5.15 +    /** Domain id to delete from */
    5.16 +    private int domain_id;
    5.17 +    /** VBD number to delete */
    5.18 +    private int vbd_num;
    5.19 +
    5.20 +    /**
    5.21 +     * Constructor for CommandVbdDelete.
    5.22 +     * @param domain_id Domain ID to delete from
    5.23 +     * @param vbd_num VBD number to delete
    5.24 +     */
    5.25 +    public CommandVbdDelete(int domain_id, int vbd_num) {
    5.26 +        this.domain_id = domain_id;
    5.27 +        this.vbd_num = vbd_num;
    5.28 +    }
    5.29 +
    5.30 +    /**
    5.31 +     * @see org.xenoserver.control.Command#execute()
    5.32 +     */
    5.33 +    public String execute() throws CommandFailedException {
    5.34 +        if (VirtualDiskManager
    5.35 +            .IT
    5.36 +            .deleteVirtualBlockDevice(domain_id, vbd_num)) {
    5.37 +            return "Deleted VBD " + vbd_num + " from domain " + domain_id;
    5.38 +        } else {
    5.39 +            throw new CommandFailedException(
    5.40 +                "No such virtual block device "
    5.41 +                    + vbd_num
    5.42 +                    + " in domain "
    5.43 +                    + domain_id);
    5.44 +        }
    5.45 +    }
    5.46 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/control/CommandVbdFlush.java	Wed Jul 09 11:12:32 2003 +0000
     6.3 @@ -0,0 +1,14 @@
     6.4 +package org.xenoserver.control;
     6.5 +
     6.6 +/**
     6.7 + * Flush (delete) all virtual block devices.
     6.8 + */
     6.9 +public class CommandVbdFlush extends Command {
    6.10 +    /**
    6.11 +     * @see org.xenoserver.control.Command#execute()
    6.12 +     */
    6.13 +    public String execute() throws CommandFailedException {
    6.14 +        VirtualDiskManager.IT.flushVirtualBlockDevices();
    6.15 +        return "Flushed virtual block devices";
    6.16 +    }
    6.17 +}
     7.1 --- a/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 11:03:26 2003 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/control/VirtualDiskManager.java	Wed Jul 09 11:12:32 2003 +0000
     7.3 @@ -125,10 +125,11 @@ public class VirtualDiskManager {
     7.4       * Delete a virtual block device.
     7.5       * @param domain Domain owning the device.
     7.6       * @param vbdNum The vbd number within the domain.
     7.7 +     * @return true if the VBD was deleted, false if it does not exist.
     7.8       */
     7.9 -    void deleteVirtualBlockDevice(int domain, int vbdNum) {
    7.10 +    boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
    7.11          Object hash = hashVBD(domain, vbdNum);
    7.12 -        virtualBlockDevices.remove(hash);
    7.13 +        return virtualBlockDevices.remove(hash) != null;
    7.14      }
    7.15  
    7.16      /**