[SIGAR-44] Add 64-bit vmware support
This commit is contained in:
parent
280181adee
commit
ba91081747
|
@ -65,11 +65,29 @@ static void vmware_throw_last_error(JNIEnv *env, void *ptr, int type)
|
||||||
#define vmware_throw_last_server_error() \
|
#define vmware_throw_last_server_error() \
|
||||||
vmware_throw_last_error(env, server, VMWARE_EX_SERVER)
|
vmware_throw_last_error(env, server, VMWARE_EX_SERVER)
|
||||||
|
|
||||||
static jint vmware_get_pointer(JNIEnv *env, jobject obj)
|
static void *vmware_get_pointer(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
jclass cls = JENV->GetObjectClass(env, obj);
|
jclass cls = JENV->GetObjectClass(env, obj);
|
||||||
|
#ifdef __LP64__
|
||||||
|
jfieldID field = JENV->GetFieldID(env, cls, "ptr64", "J");
|
||||||
|
return (void *)JENV->GetLongField(env, obj, field);
|
||||||
|
#else
|
||||||
jfieldID field = JENV->GetFieldID(env, cls, "ptr", "I");
|
jfieldID field = JENV->GetFieldID(env, cls, "ptr", "I");
|
||||||
return JENV->GetIntField(env, obj, field);
|
return (void *)JENV->GetIntField(env, obj, field);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vmware_set_pointer(JNIEnv *env, jobject obj, const void *ptr) {
|
||||||
|
jfieldID pointer_field;
|
||||||
|
jclass cls = JENV->GetObjectClass(env, obj);
|
||||||
|
|
||||||
|
#ifdef __LP64__
|
||||||
|
pointer_field = JENV->GetFieldID(env, cls, "ptr64", "J");
|
||||||
|
JENV->SetLongField(env, obj, pointer_field, (jlong)ptr);
|
||||||
|
#else
|
||||||
|
pointer_field = JENV->GetFieldID(env, cls, "ptr", "I");
|
||||||
|
JENV->SetIntField(env, obj, pointer_field, (int)ptr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define dVM(obj) \
|
#define dVM(obj) \
|
||||||
|
@ -110,11 +128,11 @@ JNIEXPORT jboolean VMWARE_JNI(VMwareObject_init)
|
||||||
return VMControl_Init() && VMControl_VMInit();
|
return VMControl_Init() && VMControl_VMInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
|
JNIEXPORT void VMWARE_JNI(ConnectParams_create)
|
||||||
(JNIEnv *env, jclass classinstance,
|
(JNIEnv *env, jobject obj,
|
||||||
jstring jhost, jint port, jstring juser, jstring jpass)
|
jstring jhost, jint port, jstring juser, jstring jpass)
|
||||||
{
|
{
|
||||||
jint ptr;
|
VMControlConnectParams *params;
|
||||||
const char *host=NULL;
|
const char *host=NULL;
|
||||||
const char *user=NULL;
|
const char *user=NULL;
|
||||||
const char *pass=NULL;
|
const char *pass=NULL;
|
||||||
|
@ -129,7 +147,7 @@ JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
|
||||||
pass = JENV->GetStringUTFChars(env, jpass, NULL);
|
pass = JENV->GetStringUTFChars(env, jpass, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = (jint)VMControl_ConnectParamsNew(host, port, user, pass);
|
params = VMControl_ConnectParamsNew(host, port, user, pass);
|
||||||
|
|
||||||
if (host) {
|
if (host) {
|
||||||
JENV->ReleaseStringUTFChars(env, jhost, host);
|
JENV->ReleaseStringUTFChars(env, jhost, host);
|
||||||
|
@ -141,7 +159,7 @@ JNIEXPORT jint VMWARE_JNI(ConnectParams_create)
|
||||||
JENV->ReleaseStringUTFChars(env, jpass, pass);
|
JENV->ReleaseStringUTFChars(env, jpass, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
vmware_set_pointer(env, obj, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void VMWARE_JNI(ConnectParams_destroy)
|
JNIEXPORT void VMWARE_JNI(ConnectParams_destroy)
|
||||||
|
@ -151,10 +169,10 @@ JNIEXPORT void VMWARE_JNI(ConnectParams_destroy)
|
||||||
VMControl_ConnectParamsDestroy(params);
|
VMControl_ConnectParamsDestroy(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint VMWARE_JNI(VMwareServer_create)
|
JNIEXPORT void VMWARE_JNI(VMwareServer_create)
|
||||||
(JNIEnv *env, jclass classinstance)
|
(JNIEnv *env, jobject obj)
|
||||||
{
|
{
|
||||||
return (jint)VMControl_ServerNewEx();
|
vmware_set_pointer(env, obj, VMControl_ServerNewEx());
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void VMWARE_JNI(VMwareServer_destroy)
|
JNIEXPORT void VMWARE_JNI(VMwareServer_destroy)
|
||||||
|
@ -287,10 +305,10 @@ JNIEXPORT jstring VMWARE_JNI(VMwareServer_exec)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint VMWARE_JNI(VM_create)
|
JNIEXPORT void VMWARE_JNI(VM_create)
|
||||||
(JNIEnv *env, jclass classinstance)
|
(JNIEnv *env, jclass obj)
|
||||||
{
|
{
|
||||||
return (jint)VMControl_VMNewEx();
|
vmware_set_pointer(env, obj, VMControl_VMNewEx());
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void VMWARE_JNI(VM_destroy)
|
JNIEXPORT void VMWARE_JNI(VM_destroy)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#ifndef VMCONTROL_WRAPPER_H
|
#ifndef VMCONTROL_WRAPPER_H
|
||||||
#define VMCONTROL_WRAPPER_H
|
#define VMCONTROL_WRAPPER_H
|
||||||
|
|
||||||
#if defined(WIN32) || defined(__linux__) && !defined(__LP64__)
|
#if defined(WIN32) || defined(__linux__)
|
||||||
|
|
||||||
#define VMCONTROL_WRAPPER_SUPPORTED
|
#define VMCONTROL_WRAPPER_SUPPORTED
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.hyperic.sigar.vmware;
|
||||||
|
|
||||||
public class ConnectParams extends VMwareObject {
|
public class ConnectParams extends VMwareObject {
|
||||||
|
|
||||||
private static native int create(String host, int port,
|
private native void create(String host, int port,
|
||||||
String user, String pass);
|
String user, String pass);
|
||||||
|
|
||||||
native void destroy();
|
native void destroy();
|
||||||
|
@ -32,6 +32,6 @@ public class ConnectParams extends VMwareObject {
|
||||||
public ConnectParams(String host, int port,
|
public ConnectParams(String host, int port,
|
||||||
String user, String pass)
|
String user, String pass)
|
||||||
{
|
{
|
||||||
this.ptr = create(host, port, user, pass);
|
create(host, port, user, pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class VM extends VMwareObject {
|
||||||
|
|
||||||
native void destroy();
|
native void destroy();
|
||||||
|
|
||||||
private static native int create();
|
private static native void create();
|
||||||
|
|
||||||
private native void connect(ConnectParams params, String config, int mks)
|
private native void connect(ConnectParams params, String config, int mks)
|
||||||
throws VMwareException;
|
throws VMwareException;
|
||||||
|
@ -329,6 +329,6 @@ public class VM extends VMwareObject {
|
||||||
throws VMwareException;
|
throws VMwareException;
|
||||||
|
|
||||||
public VM() {
|
public VM() {
|
||||||
this.ptr = create();
|
create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,14 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hyperic.jni.ArchName;
|
||||||
import org.hyperic.sigar.SigarLoader;
|
import org.hyperic.sigar.SigarLoader;
|
||||||
import org.hyperic.sigar.win32.RegistryKey;
|
import org.hyperic.sigar.win32.RegistryKey;
|
||||||
import org.hyperic.sigar.win32.Win32Exception;
|
import org.hyperic.sigar.win32.Win32Exception;
|
||||||
|
|
||||||
public class VMControlLibrary {
|
public class VMControlLibrary {
|
||||||
|
private static final boolean IS64 = ArchName.is64();
|
||||||
|
|
||||||
public static final String REGISTRY_ROOT =
|
public static final String REGISTRY_ROOT =
|
||||||
"SOFTWARE\\VMware, Inc.";
|
"SOFTWARE\\VMware, Inc.";
|
||||||
|
|
||||||
|
@ -42,7 +45,8 @@ public class VMControlLibrary {
|
||||||
private static final String VMCONTROL_TAR =
|
private static final String VMCONTROL_TAR =
|
||||||
getProperty("control.tar", VMWARE_LIB + "/perl/control.tar");
|
getProperty("control.tar", VMWARE_LIB + "/perl/control.tar");
|
||||||
|
|
||||||
private static final String VMCONTROL = "vmcontrol";
|
private static final String VMCONTROL =
|
||||||
|
"vmcontrol" + (IS64 ? "64" : "");
|
||||||
|
|
||||||
private static final String VMCONTROL_DLL =
|
private static final String VMCONTROL_DLL =
|
||||||
VMCONTROL + "lib.dll";
|
VMCONTROL + "lib.dll";
|
||||||
|
@ -230,13 +234,6 @@ public class VMControlLibrary {
|
||||||
throw new IOException("Cannot write to: " + dir);
|
throw new IOException("Cannot write to: " + dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
File libssl = getLibSSL();
|
|
||||||
File libcrypto = getLibCrypto();
|
|
||||||
|
|
||||||
if (!libssl.exists()) {
|
|
||||||
throw new FileNotFoundException(libssl.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
File obj = new File(dir, VMCONTROL_OBJ);
|
File obj = new File(dir, VMCONTROL_OBJ);
|
||||||
if (!obj.exists()) {
|
if (!obj.exists()) {
|
||||||
//extract vmcontrol.o
|
//extract vmcontrol.o
|
||||||
|
@ -260,6 +257,18 @@ public class VMControlLibrary {
|
||||||
link_args.add(out.getPath());
|
link_args.add(out.getPath());
|
||||||
link_args.add(obj.getPath());
|
link_args.add(obj.getPath());
|
||||||
|
|
||||||
|
if (IS64) {
|
||||||
|
link_args.add("-lcrypto");
|
||||||
|
link_args.add("-lssl");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
File libssl = getLibSSL();
|
||||||
|
File libcrypto = getLibCrypto();
|
||||||
|
|
||||||
|
if (!libssl.exists()) {
|
||||||
|
throw new FileNotFoundException(libssl.toString());
|
||||||
|
}
|
||||||
|
|
||||||
//Skip rpath for ESX 3.x
|
//Skip rpath for ESX 3.x
|
||||||
if (!new File(libssl.getParent(), "libc.so.6").exists()) {
|
if (!new File(libssl.getParent(), "libc.so.6").exists()) {
|
||||||
final String rpath = "-Wl,-rpath";
|
final String rpath = "-Wl,-rpath";
|
||||||
|
@ -276,6 +285,7 @@ public class VMControlLibrary {
|
||||||
|
|
||||||
link_args.add(libssl.getPath());
|
link_args.add(libssl.getPath());
|
||||||
link_args.add(libcrypto.getPath());
|
link_args.add(libcrypto.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
exec((String[])link_args.toArray(new String[0]));
|
exec((String[])link_args.toArray(new String[0]));
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ import org.hyperic.sigar.SigarLoader;
|
||||||
abstract class VMwareObject {
|
abstract class VMwareObject {
|
||||||
public static final boolean LOADED;
|
public static final boolean LOADED;
|
||||||
|
|
||||||
protected int ptr = 0;
|
int ptr = 0;
|
||||||
|
long ptr64 = 0;
|
||||||
|
|
||||||
private static native boolean init(String lib);
|
private static native boolean init(String lib);
|
||||||
|
|
||||||
|
@ -81,9 +82,10 @@ abstract class VMwareObject {
|
||||||
abstract void destroy();
|
abstract void destroy();
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (this.ptr != 0) {
|
if ((this.ptr != 0) || (this.ptr64 != 0)) {
|
||||||
destroy();
|
destroy();
|
||||||
this.ptr = 0;
|
this.ptr = 0;
|
||||||
|
this.ptr64 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||||
public class VMwareServer extends VMwareObject {
|
public class VMwareServer extends VMwareObject {
|
||||||
native void destroy();
|
native void destroy();
|
||||||
|
|
||||||
private static native int create();
|
private native int create();
|
||||||
|
|
||||||
public native boolean connect(ConnectParams params)
|
public native boolean connect(ConnectParams params)
|
||||||
throws VMwareException;
|
throws VMwareException;
|
||||||
|
@ -45,6 +45,6 @@ public class VMwareServer extends VMwareObject {
|
||||||
throws VMwareException;
|
throws VMwareException;
|
||||||
|
|
||||||
public VMwareServer() {
|
public VMwareServer() {
|
||||||
this.ptr = create();
|
create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue