[libvirt-java] [PATCH 52/65] Implement Domain.memoryPeek

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This wraps the virDomainMemoryPeek libvirt function, available since
version 0.4.5.

Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx>
---
 src/main/java/org/libvirt/Domain.java            |   40 ++++++++++++++++++++++
 src/main/java/org/libvirt/MemoryAddressMode.java |   19 ++++++++++
 src/main/java/org/libvirt/jna/Libvirt.java       |    5 +--
 3 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100644 src/main/java/org/libvirt/MemoryAddressMode.java

diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java
index f57460f..5f0d1d0 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -826,6 +826,46 @@ public class Domain {
     }
 
     /**
+     * Read the contents of a domain's memory.
+     * <p>
+     * If mode is MemoryAddressMode.VIRTUAL the 'start' parameter is
+     * interpreted as virtual memory address for whichever task
+     * happens to be running on the domain at the moment. Although
+     * this sounds haphazard it is in fact what you want in order to
+     * read Linux kernel state, because it ensures that pointers in
+     * the kernel image can be interpreted coherently.
+     * <p>
+     * This method always reads the number of bytes remaining in the
+     * buffer, that is, {@code buffer.remaining()} at the moment this
+     * method is invoked. Upon return the buffer's position will be
+     * equal to the limit, the limit itself will not have changed.
+     *
+     * @param start  the start address of the memory to peek
+     * @param mode   the mode which determines whether the given addresses
+     *               are interpreted as virtual or physical addresses
+     */
+    public void memoryPeek(long start, ByteBuffer buffer, MemoryAddressMode mode) throws LibvirtException
+    {
+        SizeT size = new SizeT();
+
+        // older libvirt has a limitation on the size of data
+        // transferred per request in the remote driver. So, split
+        // larger requests into 64K blocks.
+
+        do {
+            final int req = Math.min(65536, buffer.remaining());
+
+            size.setValue(req);
+
+            processError(libvirt.virDomainMemoryPeek(this.VDP, start, size, buffer, mode.getValue()));
+
+            buffer.position(buffer.position() + req);
+        } while (buffer.hasRemaining());
+
+        assert buffer.position() == buffer.limit();
+    }
+
+    /**
      * This function provides memory statistics for the domain.
      *
      * @param number
diff --git a/src/main/java/org/libvirt/MemoryAddressMode.java b/src/main/java/org/libvirt/MemoryAddressMode.java
new file mode 100644
index 0000000..c16edea
--- /dev/null
+++ b/src/main/java/org/libvirt/MemoryAddressMode.java
@@ -0,0 +1,19 @@
+package org.libvirt;
+
+public enum MemoryAddressMode {
+    /** addresses are virtual addresses */
+    VIRTUAL(1),
+
+    /** addresses are physical addresses */
+    PHYSICAL(2);
+
+    private final int value;
+
+    MemoryAddressMode(int v) {
+        this.value = v;
+    }
+
+    int getValue() {
+        return value;
+    }
+}
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java
index 0452246..28fbff1 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -22,10 +22,6 @@ import com.sun.jna.ptr.PointerByReference;
  * virConnCopyLastError
  * virFreeError
  *
- * LIBVIRT_0.4.2
- * virDomainBlockPeek
- * virDomainMemoryPeek
- *
  * LIBVIRT_0_5.0
  * virEventRegisterImpl
  * virConnectDomainEventRegister
@@ -286,6 +282,7 @@ public interface Libvirt extends Library {
     DomainPointer virDomainLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr);
     int virDomainManagedSave(DomainPointer virDomainPtr, int flags);
     int virDomainManagedSaveRemove(DomainPointer virDomainPtr, int flags);
+    int virDomainMemoryPeek(DomainPointer virDomainPtr, long start, SizeT size, ByteBuffer buffer, int flags);
     DomainPointer virDomainMigrate(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr,
             NativeLong flags, String dname, String uri, NativeLong bandwidth);
     DomainPointer virDomainMigrate2(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr,
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]