[libvirt] [libvirt-java] Add various block, snapshot and migrate methods

Hi, I've sent a series of patches like these about two weeks ago and got some great feedback from Claudio on those! The feedback from Claudio has been used for writing this series of patches. Backwards compatibility has been preserved by still using virDomainMigrate and virtDomainMigrateToUri for the exisiting methods, just to be sure. Thank you, Wido

This adds the blockResize() method to the Domain class Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 17 +++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 18 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 1c86bd4..3da6f56 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -188,6 +188,23 @@ public class Domain { } /** + * Resize a block device of domain while the domain is running. + * + * @param disk + * path to the block image, or shorthand (like vda) + * @param size + * the new size of the block devices + * @param flags + * when set to 1, units of size is in bytes instead of KiloBytes + * @throws LibvirtException + */ + public void blockResize(String disk, long size, int flags) throws LibvirtException { + int returnValue = libvirt.virDomainBlockResize(VDP, disk, size, flags); + processError(); + } + + + /** * Dumps the core of this domain on a given file for analysis. Note that for * remote Xen Daemon the file path will be interpreted in the remote host. * diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 87979cd..e64cb9d 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -181,6 +181,7 @@ public interface Libvirt extends Library { int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML); int virDomainAttachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int flags); int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats stats, int size); + int virDomainBlockResize(DomainPointer virDomainPtr, String disk, long size, int flags); int virDomainCoreDump(DomainPointer virDomainPtr, String to, int flags); int virDomainCreate(DomainPointer virDomainPtr); int virDomainCreateWithFlags(DomainPointer virDomainPtr, int flags); -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:23 +0100, Wido den Hollander wrote:
This adds the blockResize() method to the Domain class
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 17 +++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 18 insertions(+)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 1c86bd4..3da6f56 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -188,6 +188,23 @@ public class Domain { }
/** + * Resize a block device of domain while the domain is running. + * + * @param disk + * path to the block image, or shorthand (like vda) + * @param size + * the new size of the block devices + * @param flags + * when set to 1, units of size is in bytes instead of KiloBytes
Um, I don't like using magic numbers. Apparently Domain.BlockResizeFlags is missing. ACK with this squashed in: --- >8 ---- diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 3da6f56..aada6a9 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -24,6 +24,13 @@ import com.sun.jna.ptr.PointerByReference; */ public class Domain { + public static final class BlockResizeFlags { + /** + * size is in bytes instead of KiB + */ + public static final int BYTES = 1; + } + static final class CreateFlags { static final int VIR_DOMAIN_NONE = 0; static final int VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = (1 << 0); /* Restore or alter @@ -195,7 +202,7 @@ public class Domain { * @param size * the new size of the block devices * @param flags - * when set to 1, units of size is in bytes instead of KiloBytes + * bitwise OR'ed values of {@link BlockResizeFlags} * @throws LibvirtException */ public void blockResize(String disk, long size, int flags) throws LibvirtException { -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

This allows us to resize storage pool volumes. Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/StorageVol.java | 36 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 37 insertions(+) diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 4b9db80..bc0c01f 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -22,6 +22,23 @@ public class StorageVol { static final int VIR_STORAGE_POOL_DELETE_ZEROED = 1; } + static final class ResizeFlags { + /** + * force allocation of new size + */ + static final int ALLOCATE = 1; + + /** + * size is relative to current + */ + static final int DELTA = 2; + + /** + * allow decrease in capacity + */ + static final int SHRINK = 4; + } + public static enum Type { /** * Regular file based volumes @@ -33,6 +50,8 @@ public class StorageVol { VIR_STORAGE_VOL_BLOCK } + + /** * the native virStorageVolPtr. */ @@ -203,4 +222,21 @@ public class StorageVol { processError(); return returnValue; } + + /** + * Resize a volume + * + * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolResize">Libvirt Documentation</a> + * @param capacity + * new capacity for volume + * @param flags + * flags for resizing, see libvirt API for exact flags + * @return 0 on success, or -1 on error + * @throws LibvirtException + */ + public int resize(long capacity, int flags) throws LibvirtException { + int returnValue = libvirt.virStorageVolResize(VSVP, capacity, flags); + processError(); + return returnValue; + } } diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index e64cb9d..8262cb9 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -325,6 +325,7 @@ public interface Libvirt extends Library { StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name); StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String path); int virStorageVolWipe(StorageVolPointer storageVolPtr, int flags); + int virStorageVolResize(StorageVolPointer storageVolPtr, long capacity, int flags); // Interface Methods int virInterfaceCreate(InterfacePointer virDevicePointer); -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:24 +0100, Wido den Hollander wrote:
This allows us to resize storage pool volumes.
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/StorageVol.java | 36 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 37 insertions(+)
diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 4b9db80..bc0c01f 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -22,6 +22,23 @@ public class StorageVol { static final int VIR_STORAGE_POOL_DELETE_ZEROED = 1; }
+ static final class ResizeFlags {
This class and its members are not public and hence cannot be used from client code. This makes me wonder, did you actually use those flags in your code? That would only be possible if you author your code in the org.libvirt package... which shouldn't be done in the first place. There are other pre-existing flags following this pattern, which has been a thorn in my side for quite some time. I'll create a follow up patch.
@@ -33,6 +50,8 @@ public class StorageVol { VIR_STORAGE_VOL_BLOCK }
+ +
Spurious white space addition. ACK with this squashed in: --- >8 ----- diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index bc0c01f..39776b2 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -22,21 +22,21 @@ public class StorageVol { static final int VIR_STORAGE_POOL_DELETE_ZEROED = 1; } - static final class ResizeFlags { + public static final class ResizeFlags { /** * force allocation of new size */ - static final int ALLOCATE = 1; + public static final int ALLOCATE = 1; /** * size is relative to current */ - static final int DELTA = 2; + public static final int DELTA = 2; /** * allow decrease in capacity */ - static final int SHRINK = 4; + public static final int SHRINK = 4; } public static enum Type { @@ -50,8 +50,6 @@ public class StorageVol { VIR_STORAGE_VOL_BLOCK } - - /** * the native virStorageVolPtr. */ -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

We divert from the one-on-one mapping rule here by not adding the undefineFlags() method Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 24 ++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 3da6f56..8f4d9da 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -76,6 +76,17 @@ public class Domain { static final int VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2); /* update guest CPU requirements according to host CPU */ } + static final class UndefineFlags { + /** + * Also remove any managed save + */ + static final int MANAGED_SAVE = (1 << 0); + /** + * If last use of domain, then also remove any snapshot metadata + */ + static final int SNAPSHOTS_METADATA = (1 << 1); + } + /** * the native virDomainPtr. */ @@ -1118,6 +1129,19 @@ public class Domain { } /** + * Undefines this domain but does not stop if it it is running. With option for passing flags + * + * @see <a href="http://libvirt.org/html/libvirt-libvirt.html#virDomainUndefineFlags">Libvirt Documentation</a> + * @param flags + * flags for undefining the domain. See virDomainUndefineFlagsValues for more information + * @throws LibvirtException + */ + public void undefine(int flags) throws LibvirtException { + libvirt.virDomainUndefineFlags(VDP, flags); + processError(); + } + + /** * Change a virtual device on a domain * * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainUpdateDeviceFlags">Libvirt Documentation</a> diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 8262cb9..b814cab 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -240,6 +240,7 @@ public interface Libvirt extends Library { int virDomainSuspend(DomainPointer virDomainPtr); int virDomainUpdateDeviceFlags(DomainPointer virDomainPtr, String xml, int flags); int virDomainUndefine(DomainPointer virDomainPtr); + int virDomainUndefineFlags(DomainPointer virDomainPtr, int flags); // Network functions int virNetworkCreate(NetworkPointer virConnectPtr); -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:25 +0100, Wido den Hollander wrote:
We divert from the one-on-one mapping rule here by not adding the undefineFlags() method
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 24 ++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 1 + 2 files changed, 25 insertions(+)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 3da6f56..8f4d9da 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -76,6 +76,17 @@ public class Domain { static final int VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2); /* update guest CPU requirements according to host CPU */ }
+ static final class UndefineFlags {
Again, this class and its members should be public. ACK with this squashed in: ---- >8 ------ diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index decf6ec..0dcf9f3 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -83,15 +83,15 @@ public class Domain { static final int VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2); /* update guest CPU requirements according to host CPU */ } - static final class UndefineFlags { + public static final class UndefineFlags { /** * Also remove any managed save */ - static final int MANAGED_SAVE = (1 << 0); + public static final int MANAGED_SAVE = (1 << 0); /** * If last use of domain, then also remove any snapshot metadata */ - static final int SNAPSHOTS_METADATA = (1 << 1); + public static final int SNAPSHOTS_METADATA = (1 << 1); } /** -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

This commit also adds virDomainSnapshotListFlags which is used by various snapshot related methods. Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 54 +++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 8f4d9da..da03c27 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -87,6 +87,40 @@ public class Domain { static final int SNAPSHOTS_METADATA = (1 << 1); } + static final class SnapshotListFlags { + /** + * Filter by snapshots with no parents, when listing a domain + */ + static final int ROOTS = (1 << 0); + + /** + * List all descendants, not just children, when listing a snapshot + */ + static final int DESCENDANTS = (1 << 0); + + /** For historical reasons, groups do not use contiguous bits. */ + + /** + * Filter by snapshots with no children + */ + static final int LEAVES = (1 << 2); + + /** + * Filter by snapshots that have children + */ + static final int NO_LEAVES = (1 << 3); + + /** + * Filter by snapshots which have metadata + */ + static final int METADATA = (1 << 1); + + /** + * Filter by snapshots with no metadata + */ + static final int NO_METADATA = (1 << 4); + } + /** * the native virDomainPtr. */ @@ -1050,7 +1084,7 @@ public class Domain { } /** - * Collect the list of domain snapshots for the given domain. + * Collect the list of domain snapshots for the given domain. With the option to pass flags * * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames">Libvirt @@ -1058,13 +1092,13 @@ public class Domain { * @return The list of names, or null if an error * @throws LibvirtException */ - public String[] snapshotListNames() throws LibvirtException { + public String[] snapshotListNames(int flags) throws LibvirtException { String[] returnValue = null; int num = snapshotNum(); if (num >= 0) { returnValue = new String[num]; if (num > 0) { - libvirt.virDomainSnapshotListNames(VDP, returnValue, num, 0); + libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags); processError(); } } @@ -1072,6 +1106,20 @@ public class Domain { } /** + * Collect the list of domain snapshots for the given domain. + * This method is here for backwards compatibility. + * + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames">Libvirt + * Documentation</a> + * @return The list of names, or null if an error + * @throws LibvirtException + */ + public String[] snapshotListNames() throws LibvirtException { + return snapshotListNames(0); + } + + /** * Retrieve a snapshot by name * * @see <a -- 1.7.9.5

You're using tabs in the subject line. Is this intentional? In the subject: s/addition/additional/ At Sun, 13 Jan 2013 19:09:26 +0100, Wido den Hollander wrote:
This commit also adds virDomainSnapshotListFlags which is used by various snapshot related methods.
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 54 +++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 8f4d9da..da03c27 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -87,6 +87,40 @@ public class Domain { static final int SNAPSHOTS_METADATA = (1 << 1); }
+ static final class SnapshotListFlags { + /** + * Filter by snapshots with no parents, when listing a domain + */ + static final int ROOTS = (1 << 0);
Again, this should be public.
@@ -1072,6 +1106,20 @@ public class Domain { }
/** + * Collect the list of domain snapshots for the given domain. + * This method is here for backwards compatibility.
Yes and no. It's a convenience method one can use when not intending to specify flags. Talking about backwards compatibility in that comment suggests that this method is deprecated and/or should not be used. ACK with the typo fixed and this squashed in: ---- >8 ---- diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 8ff4910..9a2d968 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -94,38 +94,38 @@ public class Domain { public static final int SNAPSHOTS_METADATA = (1 << 1); } - static final class SnapshotListFlags { + public static final class SnapshotListFlags { /** * Filter by snapshots with no parents, when listing a domain */ - static final int ROOTS = (1 << 0); + public static final int ROOTS = (1 << 0); /** * List all descendants, not just children, when listing a snapshot */ - static final int DESCENDANTS = (1 << 0); + public static final int DESCENDANTS = (1 << 0); /** For historical reasons, groups do not use contiguous bits. */ /** * Filter by snapshots with no children */ - static final int LEAVES = (1 << 2); + public static final int LEAVES = (1 << 2); /** * Filter by snapshots that have children */ - static final int NO_LEAVES = (1 << 3); + public static final int NO_LEAVES = (1 << 3); /** * Filter by snapshots which have metadata */ - static final int METADATA = (1 << 1); + public static final int METADATA = (1 << 1); /** * Filter by snapshots with no metadata */ - static final int NO_METADATA = (1 << 4); + public static final int NO_METADATA = (1 << 4); } /** @@ -1114,11 +1114,14 @@ public class Domain { /** * Collect the list of domain snapshots for the given domain. - * This method is here for backwards compatibility. + * <p> + * This is just a convenience method, it has the same effect + * as calling {@code snapshotListNames(0);}. * + * @see #snapshotListNames(int) * @see <a - * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames">Libvirt - * Documentation</a> + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames"> + * virDomainSnapshotListNames</a> * @return The list of names, or null if an error * @throws LibvirtException */ -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

The original implementation doesn't have a argument for passing flags. It is however still there for backwards compatibility. Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index da03c27..6bdc1df 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1051,11 +1051,13 @@ public class Domain { * Documentation</a> * @param xmlDesc * string containing an XML description of the domain + * @param flags + * flags for creating the snapshot, see the virDomainSnapshotCreateFlags for the flag options * @return the snapshot, or null on Error * @throws LibvirtException */ - public DomainSnapshot snapshotCreateXML(String xmlDesc) throws LibvirtException { - DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, 0); + public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws LibvirtException { + DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, flags); processError(); DomainSnapshot returnValue = null; if (ptr != null) { @@ -1065,6 +1067,24 @@ public class Domain { } /** + * Creates a new snapshot of a domain based on the snapshot xml contained in + * xmlDesc. + * + * This method is still here for backwards compatibility since the C version + * has an additional argument with flags, which is set to 0 here. + * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotCreateXML">Libvirt + * Documentation</a> + * @param xmlDesc + * string containing an XML description of the domain + * @return the snapshot, or null on Error + * @throws LibvirtException + */ + public DomainSnapshot snapshotCreateXML(String xmlDesc) throws LibvirtException { + return snapshotCreateXML(xmlDesc, 0); + } + + /** * Get the current snapshot for a domain, if any. * * @see <a -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:27 +0100, Wido den Hollander wrote:
The original implementation doesn't have a argument for passing flags. It is however still there for backwards compatibility.
s/a argument/an argument/ in this sentence and in the subject.
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index da03c27..6bdc1df 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1051,11 +1051,13 @@ public class Domain { * Documentation</a> * @param xmlDesc * string containing an XML description of the domain + * @param flags + * flags for creating the snapshot, see the virDomainSnapshotCreateFlags for the flag options * @return the snapshot, or null on Error * @throws LibvirtException */ - public DomainSnapshot snapshotCreateXML(String xmlDesc) throws LibvirtException { - DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, 0); + public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws LibvirtException { + DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc, flags); processError(); DomainSnapshot returnValue = null; if (ptr != null) { @@ -1065,6 +1067,24 @@ public class Domain { }
/** + * Creates a new snapshot of a domain based on the snapshot xml contained in + * xmlDesc. + * + * This method is still here for backwards compatibility since the C version + * has an additional argument with flags, which is set to 0 here.
IMO, talking about backwards compatibility and C implementation details here has no value to the average libvirt-java user. See my comment for 4/7, also. ACK with the typo fixed and this squashed in: --- >8 ---- diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index f80e0e7..52aafb3 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -1076,9 +1076,11 @@ public class Domain { /** * Creates a new snapshot of a domain based on the snapshot xml contained in * xmlDesc. + * <p> + * This is just a convenience method, it has the same effect + * as calling {@code snapshotCreateXML(xmlDesc, 0);}. * - * This method is still here for backwards compatibility since the C version - * has an additional argument with flags, which is set to 0 here. + * @see #snapshotCreateXML(int) * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotCreateXML">Libvirt * Documentation</a> -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

virDomainMigrate2 adds the dxml argument which makes it possible to alter host-specific portions of the domain XML that will be used on the destination host. The original migrate method still uses virDomainMigrate for backwards compatibility reasons. Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 58 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 + 2 files changed, 60 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 6bdc1df..2758747 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -778,6 +778,64 @@ public class Domain { /** * Migrate this domain object from its current host to the destination host + * given by dconn (a connection to the destination host). + * Flags may be one of more of the following: + * Domain.VIR_MIGRATE_LIVE Attempt a live migration. + * If a hypervisor supports renaming domains during migration, then you may + * set the dname parameter to the new name (otherwise it keeps the same name). + * If this is not supported by the hypervisor, dname must be NULL or else you + * will get an error. + * Since typically the two hypervisors connect directly to each other in order + * to perform the migration, you may need to specify a path from the source + * to the destination. This is the purpose of the uri parameter. + * If uri is NULL, then libvirt will try tofind the best method. + * Uri may specify the hostname or IP address of the destination host as seen + * from the source, or uri may be a URI giving transport, hostname, user, + * port, etc. in the usual form. + * Uri should only be specified if you want to migrate over a specific interface + * on the remote host. + * For Qemu/KVM, the uri should be of the form "tcp://hostname[:port]". + * This does not require TCP auth to be setup between the connections, since + * migrate uses a straight TCP connection (unless using the PEER2PEER flag, + * in which case URI should be a full fledged libvirt URI). + * Refer also to driver documentation for the particular URIs supported. + * If set to 0, libvirt will choose a suitable default. + * Some hypervisors do not support this feature and will return an + * error if bandwidth is not 0. To see which features are supported by the + * current hypervisor, see Connect.getCapabilities, /capabilities/host/migration_features. + * There are many limitations on migration imposed by the underlying technology + * for example it may not be possible to migrate between different processors + * even with the same architecture, or between different types of hypervisor. + * + * If the hypervisor supports it, @dxml can be used to alter + * host-specific portions of the domain XML that will be used on + * the destination. + * + * @param dconn + * destination host (a Connect object) + * @param dxml + * (optional) XML config for launching guest on target + * @param flags + * flags + * @param dname + * (optional) rename domain to this at destination + * @param uri + * (optional) dest hostname/URI as seen from the source host + * @param bandwidth + * optional) specify migration bandwidth limit in Mbps + * @return the new domain object if the migration was successful, or NULL in + * case of error. Note that the new domain object exists in the + * scope of the destination connection (dconn). + * @throws LibvirtException + */ + public Domain migrate(Connect dconn, long flags, String dxml, String dname, String uri, long bandwidth) throws LibvirtException { + DomainPointer newPtr = libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new NativeLong(flags), dname, uri, new NativeLong(bandwidth)); + processError(); + return new Domain(dconn, newPtr); + } + + /** + * Migrate this domain object from its current host to the destination host * given by dconn (a connection to the destination host). Flags may be one * of more of the following: Domain.VIR_MIGRATE_LIVE Attempt a live * migration. If a hypervisor supports renaming domains during migration, diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index b814cab..4a8bdf3 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -221,6 +221,8 @@ public interface Libvirt extends Library { int virDomainManagedSaveRemove(DomainPointer virDomainPtr, int flags); DomainPointer virDomainMigrate(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, NativeLong flags, String dname, String uri, NativeLong bandwidth); + DomainPointer virDomainMigrate2(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, + String dxml, NativeLong flags, String dname, String uri, NativeLong bandwidth); int virDomainMigrateSetMaxDowntime(DomainPointer virDomainPtr, long downtime, int flags); int virDomainMigrateToURI(DomainPointer virDomainPtr, String duri, NativeLong flags, String dname, NativeLong bandwidth); -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:28 +0100, Wido den Hollander wrote:
virDomainMigrate2 adds the dxml argument which makes it possible to alter host-specific portions of the domain XML that will be used on the destination host.
The original migrate method still uses virDomainMigrate for backwards compatibility reasons.
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 58 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 + 2 files changed, 60 insertions(+)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 6bdc1df..2758747 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -778,6 +778,64 @@ public class Domain {
/** * Migrate this domain object from its current host to the destination host + * given by dconn (a connection to the destination host). + * Flags may be one of more of the following:
s/one of/one or/
+ * Domain.VIR_MIGRATE_LIVE Attempt a live migration.
Huh? Only one possible flag? Better not duplicate this information here, this is hard to keep in sync.
+ * If a hypervisor supports renaming domains during migration, then you may + * set the dname parameter to the new name (otherwise it keeps the same name). + * If this is not supported by the hypervisor, dname must be NULL or else you
"NULL" should be "null" in Java.
+ * will get an error. + * Since typically the two hypervisors connect directly to each other in order + * to perform the migration, you may need to specify a path from the source + * to the destination. This is the purpose of the uri parameter. + * If uri is NULL, then libvirt will try tofind the best method. + * Uri may specify the hostname or IP address of the destination host as seen + * from the source, or uri may be a URI giving transport, hostname, user, + * port, etc. in the usual form. + * Uri should only be specified if you want to migrate over a specific interface + * on the remote host. + * For Qemu/KVM, the uri should be of the form "tcp://hostname[:port]". + * This does not require TCP auth to be setup between the connections, since + * migrate uses a straight TCP connection (unless using the PEER2PEER flag, + * in which case URI should be a full fledged libvirt URI). + * Refer also to driver documentation for the particular URIs supported. + * If set to 0, libvirt will choose a suitable default.
This sentence makes no sense. To what parameter is it referring to? There's some part of text missing before.
+ * Some hypervisors do not support this feature and will return an + * error if bandwidth is not 0. To see which features are supported by the + * current hypervisor, see Connect.getCapabilities, /capabilities/host/migration_features. + * There are many limitations on migration imposed by the underlying technology + * for example it may not be possible to migrate between different processors + * even with the same architecture, or between different types of hypervisor. + * + * If the hypervisor supports it, @dxml can be used to alter
Don't use @dxml in order to refer to arguments. That's a libvirt doc thing.
+ * host-specific portions of the domain XML that will be used on + * the destination.
Phew. That's a long comment without paragraphs. Insert a few <p>'s.
+ * @param dconn + * destination host (a Connect object) + * @param dxml + * (optional) XML config for launching guest on target + * @param flags + * flags + * @param dname + * (optional) rename domain to this at destination + * @param uri + * (optional) dest hostname/URI as seen from the source host + * @param bandwidth + * optional) specify migration bandwidth limit in Mbps
Missing opening paren.
+ * @return the new domain object if the migration was successful, or NULL in + * case of error.
It never return NULL nor null because it will throw an exception on error. But I can see where this is coming from. ACK with this squashed in: ---- >8 ----- diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 2575d7b..3d779d6 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -786,35 +786,51 @@ public class Domain { /** * Migrate this domain object from its current host to the destination host * given by dconn (a connection to the destination host). - * Flags may be one of more of the following: - * Domain.VIR_MIGRATE_LIVE Attempt a live migration. + * <p> + * Flags may be bitwise OR'ed values of + * {@link org.libvirt.Domain.MigrateFlags MigrateFlags}. + * <p> * If a hypervisor supports renaming domains during migration, then you may * set the dname parameter to the new name (otherwise it keeps the same name). - * If this is not supported by the hypervisor, dname must be NULL or else you - * will get an error. + * <p> + * If this is not supported by the hypervisor, dname must be {@code null} or + * else you will get an exception. + * <p> * Since typically the two hypervisors connect directly to each other in order * to perform the migration, you may need to specify a path from the source * to the destination. This is the purpose of the uri parameter. - * If uri is NULL, then libvirt will try tofind the best method. + * <p> + * If uri is {@code null}, then libvirt will try to find the best method. + * <p> * Uri may specify the hostname or IP address of the destination host as seen * from the source, or uri may be a URI giving transport, hostname, user, * port, etc. in the usual form. + * <p> * Uri should only be specified if you want to migrate over a specific interface * on the remote host. - * For Qemu/KVM, the uri should be of the form "tcp://hostname[:port]". + * <p> + * For Qemu/KVM, the URI should be of the form {@code "tcp://hostname[:port]"}. + * <p> * This does not require TCP auth to be setup between the connections, since * migrate uses a straight TCP connection (unless using the PEER2PEER flag, * in which case URI should be a full fledged libvirt URI). + * <p> * Refer also to driver documentation for the particular URIs supported. - * If set to 0, libvirt will choose a suitable default. + * <p> + * The maximum bandwidth (in Mbps) that will be used to do + * migration can be specified with the bandwidth parameter. If + * set to 0, libvirt will choose a suitable default. + * <p> * Some hypervisors do not support this feature and will return an - * error if bandwidth is not 0. To see which features are supported by the - * current hypervisor, see Connect.getCapabilities, /capabilities/host/migration_features. + * error if bandwidth is not 0. To see which features are + * supported by the current hypervisor, see + * Connect.getCapabilities, /capabilities/host/migration_features. + * <p> * There are many limitations on migration imposed by the underlying technology * for example it may not be possible to migrate between different processors * even with the same architecture, or between different types of hypervisor. - * - * If the hypervisor supports it, @dxml can be used to alter + * <p> + * If the hypervisor supports it, dxml can be used to alter * host-specific portions of the domain XML that will be used on * the destination. * @@ -829,11 +845,11 @@ public class Domain { * @param uri * (optional) dest hostname/URI as seen from the source host * @param bandwidth - * optional) specify migration bandwidth limit in Mbps - * @return the new domain object if the migration was successful, or NULL in - * case of error. Note that the new domain object exists in the - * scope of the destination connection (dconn). - * @throws LibvirtException + * (optional) specify migration bandwidth limit in Mbps + * @return the new domain object if the migration was + * successful. Note that the new domain object exists in + * the scope of the destination connection (dconn). + * @throws LibvirtException if the migration fails */ public Domain migrate(Connect dconn, long flags, String dxml, String dname, String uri, long bandwidth) throws LibvirtException { DomainPointer newPtr = libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new NativeLong(flags), dname, uri, new NativeLong(bandwidth)); -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

The new migrateToUri method has the dxml argument which has been added in virDomainMigrateToUri2. The original migrateToUri method still uses virDomainMigrateToUri to be sure we don't break backwards compatibility. Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 29 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 2 files changed, 31 insertions(+) diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 2758747..c903bac 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -907,6 +907,35 @@ public class Domain { * given by duri. * * @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI"> + * virDomainMigrateToURI</a> + * + * @param dconnuri + * (optional) URI for target libvirtd if @flags includes VIR_MIGRATE_PEER2PEER + * @param miguri + * (optional) URI for invoking the migration, not if @flags includs VIR_MIGRATE_TUNNELLED + * @param dxml + * (optional) XML config for launching guest on target + * @param flags + * Controls the migrate + * @param dname + * The name at the destnation + * @param bandwidth + * Specify the migration bandwidth + * @return 0 if successful + * @throws LibvirtException + */ + public int migrateToURI(String dconnuri, String miguri, String dxml, long flags, String dname, long bandwidth) throws LibvirtException { + int returnValue = libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri, dxml, new NativeLong(flags), dname, new NativeLong(bandwidth)); + processError(); + return returnValue; + } + + /** + * Migrate the domain object from its current host to the destination host + * given by duri. + * + * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI"> * virDomainMigrateToURI</a> * diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 4a8bdf3..8c7d6ef 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -226,6 +226,8 @@ public interface Libvirt extends Library { int virDomainMigrateSetMaxDowntime(DomainPointer virDomainPtr, long downtime, int flags); int virDomainMigrateToURI(DomainPointer virDomainPtr, String duri, NativeLong flags, String dname, NativeLong bandwidth); + int virDomainMigrateToURI2(DomainPointer virDomainPtr, String dconnuri, String miguri, + String dxml, NativeLong flags, String dname, NativeLong bandwidth); int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats, int nr_stats, int flags); int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen); int virDomainReboot(DomainPointer virDomainPtr, int flags); -- 1.7.9.5

At Sun, 13 Jan 2013 19:09:29 +0100, Wido den Hollander wrote:
The new migrateToUri method has the dxml argument which has been added in virDomainMigrateToUri2.
The original migrateToUri method still uses virDomainMigrateToUri to be sure we don't break backwards compatibility.
Signed-off-by: Wido den Hollander <wido@widodh.nl> --- src/main/java/org/libvirt/Domain.java | 29 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 2 ++ 2 files changed, 31 insertions(+)
diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 2758747..c903bac 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -907,6 +907,35 @@ public class Domain { * given by duri.
There is no duri parameter for your new method. I see, you just copied the comment from the old function. But even worse, I found the same mistake in libvirt's documentation. It wasn't easy to figure this out.
* @see <a + * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI"> + * virDomainMigrateToURI</a> + * + * @param dconnuri + * (optional) URI for target libvirtd if @flags includes VIR_MIGRATE_PEER2PEER + * @param miguri + * (optional) URI for invoking the migration, not if @flags includs VIR_MIGRATE_TUNNELLED + * @param dxml + * (optional) XML config for launching guest on target + * @param flags + * Controls the migrate + * @param dname + * The name at the destnation + * @param bandwidth + * Specify the migration bandwidth + * @return 0 if successful + * @throws LibvirtException + */ + public int migrateToURI(String dconnuri, String miguri, String dxml, long flags, String dname, long bandwidth) throws LibvirtException {
ACK with this squashed in --- >8 ---- diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index d68edbb..a72e8c6 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -926,8 +926,15 @@ public class Domain { } /** - * Migrate the domain object from its current host to the destination host - * given by duri. + * Migrate the domain object from its current host to the destination + * denoted by a given URI. + * <p> + * The destination is given either in dconnuri (if the + * {@link MigrateFlags#VIR_MIGRATE_PEER2PEER PEER2PEER} + * is flag set), or in miguri (if neither the + * {@link MigrateFlags#VIR_MIGRATE_PEER2PEER PEER2PEER} nor the + * {@link MigrateFlags#VIR_MIGRATE_TUNNELLED TUNNELLED} migration + * flag is set in flags). * * @see <a * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI"> -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

Hello Wido, At Sun, 13 Jan 2013 19:09:22 +0100, Wido den Hollander wrote:
Hi,
I've sent a series of patches like these about two weeks ago and got some great feedback from Claudio on those!
The feedback from Claudio has been used for writing this series of patches.
Backwards compatibility has been preserved by still using virDomainMigrate and virtDomainMigrateToUri for the exisiting methods, just to be sure.
I have reviewed your changeset and basically it's OK with a few nits fixed. If you or somebody else doesn't have any objections I'd push the whole series. Claudio -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

Hello Claudio, On 01/23/2013 04:13 PM, Claudio Bley wrote:
Hello Wido,
At Sun, 13 Jan 2013 19:09:22 +0100, Wido den Hollander wrote:
Hi,
I've sent a series of patches like these about two weeks ago and got some great feedback from Claudio on those!
The feedback from Claudio has been used for writing this series of patches.
Backwards compatibility has been preserved by still using virDomainMigrate and virtDomainMigrateToUri for the exisiting methods, just to be sure.
I have reviewed your changeset and basically it's OK with a few nits fixed.
If you or somebody else doesn't have any objections I'd push the whole series.
Thank you! I just saw your comments coming in. Since I don't know what the convention is for libvirt-java I followed most of the existing code with the implementation. Your feedback sounds good, so no objections from my side. Wido
Claudio

At Wed, 23 Jan 2013 16:19:43 +0100, Wido den Hollander wrote:
Hello Claudio,
On 01/23/2013 04:13 PM, Claudio Bley wrote:
Hello Wido,
At Sun, 13 Jan 2013 19:09:22 +0100, Wido den Hollander wrote:
Hi,
I've sent a series of patches like these about two weeks ago and got some great feedback from Claudio on those!
The feedback from Claudio has been used for writing this series of patches.
Backwards compatibility has been preserved by still using virDomainMigrate and virtDomainMigrateToUri for the exisiting methods, just to be sure.
I have reviewed your changeset and basically it's OK with a few nits fixed.
If you or somebody else doesn't have any objections I'd push the whole series.
Thank you! I just saw your comments coming in.
Since I don't know what the convention is for libvirt-java I followed most of the existing code with the implementation.
Your feedback sounds good, so no objections from my side.
OK, pushed now. Thanks for your submission! Claudio -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:<http://www.av-test.org> Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern
participants (2)
-
Claudio Bley
-
Wido den Hollander