[libvirt] libvirt-java storage support and refactoring

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

 



Hello!

This patch contains the following:

- The complete storage handling API
- Fixing memory leaks in the VirConnect JNI implementation

I've written the new classes using a new approach.

I've found that libvirt for the most part has a very perdicitble and repetitive API (great design!), and as a result I've found myself copying the same code over and over again. I've decided to make generic JNI functions, that can handle multiple libvirt functions with function pointers. The generic functions are in generic.c and they are used extensively in the new Storage JNI implementation.

I'd like to have your input on this architecture, my current plan is to refactor all trivial JNI functions to use these generics, unless there are objections.

The positive aspects of the new architecture:

- No code duplication, one generic function fix affects all similar functions
- Less code

The negative aspects:

- Ugly syntax (but JNI is ugly enough already)
- Easier to make errors in JNI code due to function type casts.

I think that the benefits outweigh the negatives, esepecialy when we start cleaning up memory allocation, 64/32 bit cleannes stuff, threading, it will have to be done in one function, instead of 3 or 30 cut'n'pasted ones, scattered in 5 files.

best regards
István

Index: src/org/libvirt/Connect.java
===================================================================
RCS file: /data/cvs/libvirt-java/src/org/libvirt/Connect.java,v
retrieving revision 1.1
diff -u -r1.1 Connect.java
--- src/org/libvirt/Connect.java	18 Jul 2008 14:37:21 -0000	1.1
+++ src/org/libvirt/Connect.java	2 Aug 2008 15:21:11 -0000
@@ -1,5 +1,9 @@
 package org.libvirt;
 
+import org.libvirt.LibvirtException;
+import org.libvirt.StoragePool;
+import org.libvirt.StorageVol;
+
 /**
  * The Connect object represents a connection to a local or remote hypervisor/driver.
  *
@@ -541,4 +545,157 @@
 
 	private native int _setDom0Memory(long memory) throws LibvirtException;
 
+	/**
+	 * Provides the number of inactive storage pools
+	 * 
+	 * @return the number of pools found
+	 * @throws LibvirtException
+	 */
+	public int numOfDefinedStoragePools() throws LibvirtException {
+		return _numOfDefinedStoragePools(VCP);
+	}
+
+	private native int _numOfDefinedStoragePools(long VCP) throws LibvirtException;
+
+	/**
+	 * Provides the number of active storage pools
+	 * 
+	 * @return the number of pools found
+	 * @throws LibvirtException
+	 */
+	public int numOfStoragePools() throws LibvirtException {
+		return _numOfStoragePools(VCP);
+	}
+
+	private native int _numOfStoragePools(long VCP) throws LibvirtException;
+
+	/**
+	 * Provides the list of names of inactive storage pools.
+	 *
+	 * @return an Array of Strings that contains the names of the defined storage pools
+	 * @throws LibvirtException
+	 */
+	public String[] listDefinedStoragePools() throws LibvirtException {
+		return _listDefinedStoragePools(VCP);
+	}
+
+	private native String[] _listDefinedStoragePools(long VCP)
+	throws LibvirtException;
+
+	/**
+	 * Provides the list of names of active storage pools.
+	 *
+	 * @return an Array of Strings that contains the names of the defined storage pools
+	 * @throws LibvirtException
+	 */
+	public String[] listStoragePools() throws LibvirtException {
+		return _listStoragePools(VCP);
+	}
+
+	private native String[] _listStoragePools(long VCP)
+	throws LibvirtException;
+	
+	/**
+	 * Create a new storage based on its XML description. 
+	 * The pool is not persistent, so its definition will disappear when it is destroyed, or if the host is restarted
+	 * 
+	 * @param xmlDesc XML description for new pool
+	 * @param flags future flags, use 0 for now
+	 * @return StoragePool object
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolCreateXML(String xmlDesc, int flags)
+	throws LibvirtException {
+		return new StoragePool(this, _virStoragePoolCreateXML(VCP, xmlDesc, flags));
+	}
+
+	private native long _virStoragePoolCreateXML(long VCP, String xmlDesc, int flags)
+	throws LibvirtException;
+	
+	/**
+	 * Define a new inactive storage pool based on its XML description. 
+	 * The pool is persistent, until explicitly undefined.
+	 * 
+	 * @param xmlDesc XML description for new pool
+	 * @param flags flags future flags, use 0 for now
+	 * @return StoragePool object
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolDefineXML(String xml, int flags)
+	throws LibvirtException {
+		return new StoragePool(this, _virStoragePoolDefineXML(VCP, xml, flags));
+	}
+
+	private native long _virStoragePoolDefineXML(long VCP, String xml, int flags)
+	throws LibvirtException;
+
+	/**
+	 * Fetch a storage pool based on its unique name
+	 * 
+	 * @param name name of pool to fetch
+	 * @return StoragePool object
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolLookupByName(String name)
+	throws LibvirtException {
+		return new StoragePool(this, _virStoragePoolLookupByName(VCP, name));
+	}
+
+	private native long _virStoragePoolLookupByName(long VCP, String name)
+	throws LibvirtException;
+
+	/**
+	 * Fetch a storage pool based on its globally unique id
+	 * 
+	 * @param UUID globally unique id of pool to fetch
+	 * @return a new network object
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolLookupByUUID(int[] UUID)
+	throws LibvirtException {
+		return new StoragePool(this, _virStoragePoolLookupByUUID(VCP, UUID));
+	}
+
+	private native long _virStoragePoolLookupByUUID(long VCP, int[] UUID);
+	
+	/**
+	 * Fetch a storage pool based on its globally unique id
+	 * 
+	 * @param UUID globally unique id of pool to fetch
+	 * @return VirStoragePool object
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolLookupByUUIDString(String UUID)
+	throws LibvirtException {
+		return new StoragePool(this, _virStoragePoolLookupByUUIDString(VCP, UUID));
+	}
+
+	private native long _virStoragePoolLookupByUUIDString(long VCP, String UUID)
+	throws LibvirtException;
+	
+	/**
+	 * Fetch a a storage volume based on its globally unique key
+	 * 
+	 * @param key globally unique key
+	 * @return a storage volume
+	 */
+	public StorageVol storageVolLookupByKey(String key){
+		return new StorageVol(this, _virStorageVolLookupByKey(VCP, key));
+	}
+	
+	private native long _virStorageVolLookupByKey(long VCP, String key);
+	
+	/**
+	 * Fetch a storage volume based on its locally (host) unique path
+	 * 
+	 * @param path locally unique path
+	 * @return 	a storage volume
+	 */
+	public StorageVol storageVolLookupByPath(String path){
+		return new StorageVol(this, _virStorageVolLookupByPath(VCP, path));
+	}
+	
+	private native long _virStorageVolLookupByPath(long VCP, String path);
+
+
 }
Index: src/jni/org_libvirt_Connect.c
===================================================================
RCS file: /data/cvs/libvirt-java/src/jni/org_libvirt_Connect.c,v
retrieving revision 1.2
diff -u -r1.2 org_libvirt_Connect.c
--- src/jni/org_libvirt_Connect.c	22 Jul 2008 08:27:42 -0000	1.2
+++ src/jni/org_libvirt_Connect.c	2 Aug 2008 15:21:11 -0000
@@ -6,7 +6,8 @@
 
 #include <assert.h>
 
-//TODO We are leaking UTFChars all over the place. We need to strcpy, then release every string we get from JAVA, and not use them directly!
+//TODO We are leaking UTFChars all over the place. We need to release every string we get from JAVA with ReleaseStringUTFChars! (Done)
+//TODO The same for *ArrayElements
 
 JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1virInitialize
   (JNIEnv *env, jclass cls){
@@ -47,8 +48,11 @@
 }
 
 JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1getMaxVcpus
-  (JNIEnv *env, jobject obj, jlong VCP, jstring type){
-	return virConnectGetMaxVcpus((virConnectPtr)VCP , (*env)->GetStringUTFChars(env, type, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_type){
+	const char *type = (*env)->GetStringUTFChars(env, j_type, NULL);
+	int retval = (jlong)virConnectGetMaxVcpus((virConnectPtr)VCP, type);
+	(*env)->ReleaseStringUTFChars(env, j_type, type);
+	return retval;
 };
 
 JNIEXPORT jstring JNICALL Java_org_libvirt_Connect__1getType
@@ -76,7 +80,7 @@
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1getVersion
   (JNIEnv *env, jobject obj, jlong VCP){
 	unsigned long hvVer=0;
-	int retval = virConnectGetVersion((virConnectPtr)VCP, &hvVer);
+	long retval = virConnectGetVersion((virConnectPtr)VCP, &hvVer);
 	return (jlong)(hvVer);
 };
 
@@ -146,31 +150,35 @@
 
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1open
-  (JNIEnv *env, jobject obj, jstring uri){
+  (JNIEnv *env, jobject obj, jstring j_uri){
 
 	virConnectPtr vc;
+	const char *uri=(*env)->GetStringUTFChars(env, j_uri, NULL);
 
 	//Initialize the libvirt VirtConn Object
-	vc=virConnectOpen((*env)->GetStringUTFChars(env, uri, NULL));
+	vc=virConnectOpen(uri);
+	(*env)->ReleaseStringUTFChars(env, j_uri, uri);
 	if(vc==NULL){
 		//We have a pending java exception, let's return
 		assert((*env)->ExceptionOccurred(env));
 		return (jlong)NULL;
 	}
 
-	//Initialized the error handler for this connection
+	//Initialize the error handler for this connection
 	virConnSetErrorFunc(vc, env, virErrorHandler);
 
 	return (jlong)vc;
 };
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1openReadOnly
-  (JNIEnv *env, jobject obj, jstring uri){
+  (JNIEnv *env, jobject obj, jstring j_uri){
 
 	virConnectPtr vc;
-
+	const char *uri=(*env)->GetStringUTFChars(env, j_uri, NULL);
+	
 	//Initialize the libvirt VirtConn Object
-	vc=virConnectOpenReadOnly((*env)->GetStringUTFChars(env, uri, NULL));
+	vc=virConnectOpenReadOnly(uri);
+	(*env)->ReleaseStringUTFChars(env, j_uri, uri);
 	if(vc==NULL){
 		//We have a pending java exception, let's return
 		assert((*env)->ExceptionOccurred(env));
@@ -184,10 +192,10 @@
 };
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1openAuth
-  (JNIEnv *env, jobject obj, jstring uri, jobject j_auth, jint flags){
+  (JNIEnv *env, jobject obj, jstring j_uri, jobject j_auth, jint flags){
 
 	virConnectPtr vc;
-	virError error;
+	const char *uri=(*env)->GetStringUTFChars(env, j_uri, NULL);
 
 	virConnectAuth *auth = malloc(sizeof(virConnectAuth));
 
@@ -222,8 +230,9 @@
 	cb_wrapper->env = env;
 	cb_wrapper->auth = j_auth;
 	auth->cbdata=cb_wrapper;
-
-	vc=virConnectOpenAuth((*env)->GetStringUTFChars(env, uri, NULL), auth, flags);
+	
+	vc=virConnectOpenAuth(uri, auth, flags);
+	(*env)->ReleaseStringUTFChars(env, j_uri, uri);
 	if (vc==NULL){
 		//We have a pending java exception, let's return
 		assert((*env)->ExceptionOccurred(env));
@@ -237,18 +246,27 @@
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virNetworkCreateXML
-  (JNIEnv *env, jobject obj, jlong VCP, jstring xmlDesc){
-	return (jlong)virNetworkCreateXML((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, xmlDesc, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virNetworkCreateXML((virConnectPtr)VCP, xmlDesc);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virNetworkDefineXML
-(JNIEnv *env, jobject obj, jlong VCP, jstring xmlDesc){
-	return (jlong)virNetworkDefineXML((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, xmlDesc, NULL));
+(JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virNetworkDefineXML((virConnectPtr)VCP, xmlDesc);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virNetworkLookupByName
-  (JNIEnv *env, jobject obj, jlong VCP, jstring name){
-	return (jlong)virNetworkLookupByName((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, name, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_name){
+	const char *name=(*env)->GetStringUTFChars(env, j_name, NULL);
+	jlong retval = (jlong)virNetworkLookupByName((virConnectPtr)VCP, name);
+	(*env)->ReleaseStringUTFChars(env, j_name, name);
+	return retval;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virNetworkLookupByUUID
@@ -264,8 +282,11 @@
 
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virNetworkLookupByUUIDString
-  (JNIEnv *env, jobject obj, jlong VCP, jstring UUID){
-	return (jlong)virNetworkLookupByUUIDString((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, UUID, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_UUID){
+	const char *uuid=(*env)->GetStringUTFChars(env, j_UUID, NULL);
+	jlong retval =  (jlong)virNetworkLookupByUUIDString((virConnectPtr)VCP, uuid);
+	(*env)->ReleaseStringUTFChars(env, j_UUID, uuid);
+	return retval;
 }
 
 JNIEXPORT jobject JNICALL Java_org_libvirt_Connect__1virNodeInfo
@@ -342,8 +363,11 @@
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virDomainLookupByName
-  (JNIEnv *env, jobject obj, jlong VCP, jstring name){
-		return (jlong)virDomainLookupByName((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, name, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_name){
+	const char *name=(*env)->GetStringUTFChars(env, j_name, NULL);
+	jlong retval =  (jlong)virDomainLookupByName((virConnectPtr)VCP, name);
+	(*env)->ReleaseStringUTFChars(env, j_name, name);
+	return retval;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virDomainLookupByUUID
@@ -358,8 +382,11 @@
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virDomainLookupByUUIDString
-  (JNIEnv *env, jobject obj, jlong VCP, jstring UUID){
-	return (jlong)virDomainLookupByUUIDString((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, UUID, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_UUID){
+	const char *UUID=(*env)->GetStringUTFChars(env, j_UUID, NULL);
+	jlong retval = (jlong)virDomainLookupByUUIDString((virConnectPtr)VCP, UUID);
+	(*env)->ReleaseStringUTFChars(env, j_UUID, UUID);
+	return retval;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virGetLibVirVersion
@@ -376,26 +403,115 @@
 	type = (*env)->GetStringUTFChars(env, j_type, NULL);
 
 	virGetVersion(&libVer, type, &typeVer);
+	(*env)->ReleaseStringUTFChars(env, j_type, type);
 
 	return libVer;
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virDomainCreateLinux
-  (JNIEnv *env, jobject obj, jlong VCP, jstring xmlDesc, jint flags){
-	return(jlong)virDomainCreateLinux((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, xmlDesc, NULL), flags);
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc, jint flags){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virDomainCreateLinux((virConnectPtr)VCP, xmlDesc, flags);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;	
 }
 
 JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virDomainDefineXML
-  (JNIEnv *env, jobject obj, jlong VCP, jstring xmlDesc){
-	return(jlong)virDomainDefineXML((virConnectPtr)VCP, (*env)->GetStringUTFChars(env, xmlDesc, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virDomainDefineXML((virConnectPtr)VCP, xmlDesc);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;	
 }
 
 JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1virDomainRestore
-  (JNIEnv *env, jobject obj, jlong VCP, jstring from){
-	return virDomainRestore((virConnectPtr)VCP, (char*)(*env)->GetStringUTFChars(env, from, NULL));
+  (JNIEnv *env, jobject obj, jlong VCP, jstring j_from){
+	const char *from=(*env)->GetStringUTFChars(env, j_from, NULL);
+	jint retval = (jint)virDomainRestore((virConnectPtr)VCP, from);
+	(*env)->ReleaseStringUTFChars(env, j_from, from);
+	return retval;	
 }
 
 JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1setDom0Memory
   (JNIEnv *env, jobject obj, jlong memory){
 	return virDomainSetMemory(NULL, memory);
 }
+
+JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1numOfDefinedStoragePools
+  (JNIEnv *env, jobject obj, jlong VCP){
+	return virConnectNumOfDefinedStoragePools((virConnectPtr)VCP);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_Connect__1numOfStoragePools
+  (JNIEnv *env, jobject obj, jlong VCP){
+	return virConnectNumOfStoragePools((virConnectPtr)VCP);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_libvirt_Connect__1listDefinedStoragePools
+(JNIEnv *env, jobject obj, jlong VCP){
+	int maxnames;
+	char **names;
+	int c;
+	jobjectArray j_names=NULL;
+	if((maxnames = virConnectNumOfDefinedStoragePools((virConnectPtr)VCP))<0)
+		return NULL;
+	names= (char**)calloc(maxnames, sizeof(char*));
+	if(virConnectListDefinedStoragePools((virConnectPtr)VCP, names, maxnames)>=0){
+		j_names= (jobjectArray)(*env)->NewObjectArray(env, maxnames,
+			(*env)->FindClass(env,"java/lang/String"),
+			(*env)->NewStringUTF(env,""));
+		for(c=0; c<maxnames; c++){
+			(*env)->SetObjectArrayElement(env, j_names, c, (*env)->NewStringUTF(env, names[c]));
+		}
+	}
+	free(names);
+
+	return j_names;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_libvirt_Connect__1listStoragePools
+(JNIEnv *env, jobject obj, jlong VCP){
+	int maxnames;
+	char **names;
+	int c;
+	jobjectArray j_names=NULL;
+	if((maxnames = virConnectNumOfStoragePools((virConnectPtr)VCP))<0)
+		return NULL;
+	names= (char**)calloc(maxnames, sizeof(char*));
+	if(virConnectListStoragePools((virConnectPtr)VCP, names, maxnames)>=0){
+		j_names= (jobjectArray)(*env)->NewObjectArray(env, maxnames,
+			(*env)->FindClass(env,"java/lang/String"),
+			(*env)->NewStringUTF(env,""));
+		for(c=0; c<maxnames; c++){
+			(*env)->SetObjectArrayElement(env, j_names, c, (*env)->NewStringUTF(env, names[c]));
+		}
+	}
+	free(names);
+
+	return j_names;
+}
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virStoragePoolCreateXML
+(JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc, jint flags){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virStoragePoolCreateXML((virConnectPtr)VCP, xmlDesc, flags);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
+}
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virStoragePoolDefineXML
+(JNIEnv *env, jobject obj, jlong VCP, jstring j_xmlDesc, jint flags){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virStoragePoolDefineXML((virConnectPtr)VCP, xmlDesc, flags);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
+}
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_Connect__1virStoragePoolLookupByName
+(JNIEnv *env, jobject obj, jlong VCP, jstring j_name){
+	const char *name=(*env)->GetStringUTFChars(env, j_name, NULL);
+	jlong retval = (jlong)virStoragePoolLookupByName((virConnectPtr)VCP, name);
+	(*env)->ReleaseStringUTFChars(env, j_name, name);
+	return retval;	
+}
+
Index: src/jni/Makefile.am
===================================================================
RCS file: /data/cvs/libvirt-java/src/jni/Makefile.am,v
retrieving revision 1.5
diff -u -r1.5 Makefile.am
--- src/jni/Makefile.am	18 Jul 2008 14:37:21 -0000	1.5
+++ src/jni/Makefile.am	2 Aug 2008 15:21:11 -0000
@@ -4,7 +4,13 @@
   org_libvirt_Domain.h \
   org_libvirt_Domain_CreateFlags.h \
   org_libvirt_Domain_MigrateFlags.h \
-  org_libvirt_Domain_XMLFlags.h
+  org_libvirt_Domain_XMLFlags.h \
+  org_libvirt_StoragePool_BuildFlags.h \
+  org_libvirt_StoragePool_DeleteFlags.h \
+  org_libvirt_StoragePool.h \
+  org_libvirt_StorageVol_Type.h \
+  org_libvirt_StorageVol_DeleteFlags.h \
+  org_libvirt_StorageVol.h
 
 BUILT_SOURCES = $(GENERATED)
 
@@ -18,12 +24,22 @@
 
 org_libvirt_Domain.h org_libvirt_Domain_CreateFlags.h org_libvirt_Domain_MigrateFlags.h org_libvirt_Domain_XMLFlags.h : $(JAVA_CLASS_ROOT)/org/libvirt/Domain.class
 	$(JAVAH) -classpath $(JAVA_CLASS_ROOT) org.libvirt.Domain
+	
+org_libvirt_StoragePool.h org_libvirt_StoragePool_BuildFlags.h org_libvirt_StoragePool_DeleteFlags.h : $(JAVA_CLASS_ROOT)/org/libvirt/StoragePool.class
+	$(JAVAH) -classpath $(JAVA_CLASS_ROOT) org.libvirt.StoragePool
+	
+org_libvirt_StorageVol.h org_libvirt_StorageVol_Type.h org_libvirt_StorageVol_DeleteFlags.h : $(JAVA_CLASS_ROOT)/org/libvirt/StorageVol.class
+	$(JAVAH) -classpath $(JAVA_CLASS_ROOT) org.libvirt.StorageVol
 
 lib_LTLIBRARIES = libvirt_jni.la
 libvirt_jni_la_SOURCES = \
   org_libvirt_Network.c \
   org_libvirt_Connect.c \
   org_libvirt_Domain.c \
+  org_libvirt_StoragePool.c \
+  org_libvirt_StorageVol.c \
+  generic.c \
+  generic.h \
   ErrorHandler.c \
   ErrorHandler.h \
   ConnectAuthCallbackBridge.c \
Index: libvirt-java.spec.in
===================================================================
RCS file: /data/cvs/libvirt-java/libvirt-java.spec.in,v
retrieving revision 1.9
diff -u -r1.9 libvirt-java.spec.in
--- libvirt-java.spec.in	18 Jul 2008 14:37:21 -0000	1.9
+++ libvirt-java.spec.in	2 Aug 2008 15:21:10 -0000
@@ -1,7 +1,7 @@
 Summary:	Java bindings for the libvirt virtualization API
 Name:		libvirt-java
 Version:	@VERSION@
-Release:	1%{?dist}
+Release:	2%{?dist}
 License:	LGPLv2+
 Group:		Development/Libraries
 Source:		http://libvirt.org/sources/java/libvirt-java-%{version}.tar.gz
Index: src/jni/generic.c
===================================================================
RCS file: src/jni/generic.c
diff -N src/jni/generic.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/jni/generic.c	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,128 @@
+#include "generic.h"
+#include <jni.h>
+#include <stdlib.h>
+
+jint generic__virObj__int
+(JNIEnv *env, jobject obj, jlong virObj1, int (*virFunc1)(void*) ){
+	return (jint)virFunc1((void*)virObj1);
+}
+
+jint generic__virObj_int__int
+  (JNIEnv *env, jobject obj, jlong virObj1, jint arg1, int (*virFunc1)(void*, int)){
+	return (jint)virFunc1((void*)virObj1, arg1);
+}
+
+jstring generic__virObj__conststring
+  (JNIEnv *env, jobject obj, jlong virObj1, const char* (*virFunc1)(void*)){
+	jstring j_retstring=NULL;
+	const char *retstring;
+	if((retstring = virFunc1((void*)virObj1))){
+		j_retstring = (*env)->NewStringUTF(env, retstring);
+	} 
+	return j_retstring;
+}
+
+jstring generic__virObj__string
+  (JNIEnv *env, jobject obj, jlong virObj1, char* (*virFunc1)(void*)){
+	jstring j_retstring=NULL;
+	char *retstring;
+	if((retstring = virFunc1((void*)virObj1))){
+		j_retstring = (*env)->NewStringUTF(env, retstring);
+		free(retstring);
+	} 
+	return j_retstring;
+}
+
+jstring generic__virObj_int__string
+  (JNIEnv *env, jobject obj, jlong virObj, jint arg1, char* (*virFunc1)(void*, int)){
+	jstring j_retstring;
+	char* retstring = NULL;
+	if((retstring = virFunc1((void*)virObj, arg1))){
+		j_retstring = (*env)->NewStringUTF(env, retstring);
+		free(retstring);
+	}
+	return j_retstring;
+}
+
+jboolean generic_getAutostart
+  (JNIEnv *env, jobject obj, jlong virObj, int (*VirFunc1)(void*, int*)){
+	int autostart=0;
+	VirFunc1((virStoragePoolPtr)virObj, &autostart);
+	return (jboolean)autostart;
+}
+
+jintArray generic_getUUID
+  (JNIEnv *env, jobject obj, jlong virObj1, int	(*virFunc1)(void*, unsigned char*)){
+	unsigned char uuid[VIR_UUID_BUFLEN];
+	jintArray j_uuid;
+	int c;
+	int uuidbyte;
+
+	if(virFunc1((void*)virObj1, uuid)<0)
+		return NULL;
+	//unpack UUID
+	j_uuid=(*env)->NewIntArray(env, VIR_UUID_BUFLEN);
+	for(c=0; c<VIR_UUID_BUFLEN; c++){
+			uuidbyte=uuid[c];
+			(*env)->SetIntArrayRegion(env, j_uuid, c, 1, &uuidbyte);
+	}
+	return j_uuid;
+}
+
+jstring generic_getUUIDString
+  (JNIEnv *env, jobject obj, jlong virObj, int (*virFunc1)(void*, char*)){
+	char uuidString[VIR_UUID_STRING_BUFLEN];
+	virFunc1((void*)virObj, uuidString);
+	return (*env)->NewStringUTF(env, uuidString);
+}
+
+JNIEXPORT jobjectArray JNICALL generic_list_stringarray
+  (JNIEnv *env, jobject obj, jlong virObj, int (*virFunc1)(void*, char ** const, int), int (*virFunc2)(void*)){
+	int maxnames;
+	char **names;
+	int c;
+	jobjectArray j_names=NULL;
+	if((maxnames = virFunc2((void*)virObj))<0)
+		return NULL;
+	names= (char**)calloc(maxnames, sizeof(char*));
+	if(virFunc1((void*)virObj, names, maxnames)>=0){
+		j_names= (jobjectArray)(*env)->NewObjectArray(env, maxnames,
+			(*env)->FindClass(env,"java/lang/String"),
+			(*env)->NewStringUTF(env,""));
+		for(c=0; c<maxnames; c++){
+			(*env)->SetObjectArrayElement(env, j_names, c, (*env)->NewStringUTF(env, names[c]));
+		}
+	}
+	free(names);
+
+	return j_names;
+}
+
+JNIEXPORT jlong JNICALL generic_lookupBy_string
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_stringid, void* (*virFunc1)(void*, const char *)){
+	const char *stringid=(*env)->GetStringUTFChars(env, j_stringid, NULL);
+	jlong retval = (jlong)virFunc1((void*)virObj, stringid);
+	(*env)->ReleaseStringUTFChars(env, j_stringid, stringid);
+	return retval;
+}
+
+JNIEXPORT jlong JNICALL generic_lookupBy_none
+  (JNIEnv *env, jobject obj, jlong virObj, void* (*virFunc1)(void*)){
+	return (jlong)virFunc1((void*)virObj);
+}
+
+JNIEXPORT jlong JNICALL generic_CreateDefineXML
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_xmlDesc, void*	(*virFunc1)	(void*, const char *)){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virFunc1((void*)virObj, xmlDesc);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
+}
+
+JNIEXPORT jlong JNICALL generic_CreateDefineXML_with_flags
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_xmlDesc, jint flags, void*	(*virFunc1)	(void*, const char *, unsigned int)){
+	const char *xmlDesc=(*env)->GetStringUTFChars(env, j_xmlDesc, NULL);
+	jlong retval = (jlong)virFunc1((void*)virObj, xmlDesc, flags);
+	(*env)->ReleaseStringUTFChars(env, j_xmlDesc, xmlDesc);
+	return retval;
+}
Index: src/jni/org_libvirt_StoragePool.c
===================================================================
RCS file: src/jni/org_libvirt_StoragePool.c
diff -N src/jni/org_libvirt_StoragePool.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/jni/org_libvirt_StoragePool.c	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,117 @@
+#include <libvirt/libvirt.h>
+#include "org_libvirt_StoragePool.h"
+#include "generic.h"
+
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1build
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	return generic__virObj_int__int(env, obj, VSPP, flags, (int (*)(void*, int))&virStoragePoolBuild);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1create
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	return generic__virObj_int__int(env, obj, VSPP, flags, (int (*)(void*, int))&virStoragePoolCreate);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1delete
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	return generic__virObj_int__int(env, obj, VSPP, flags, (int (*)(void*, int))&virStoragePoolDelete);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1destroy
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic__virObj__int(env, obj, VSPP, (int (*)(void*))&virStoragePoolDelete);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1free
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic__virObj__int(env, obj, VSPP, (int (*)(void*))&virStoragePoolFree);
+}
+
+JNIEXPORT jboolean JNICALL Java_org_libvirt_StoragePool__1getAutostart
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic_getAutostart(env, obj, VSPP, (int (*)(void*, int*))&virStoragePoolGetAutostart);
+}
+
+JNIEXPORT jobject JNICALL Java_org_libvirt_StoragePool__1getInfo
+  (JNIEnv *env, jobject obj, jlong VSPP){
+
+	virStoragePoolInfo storagePoolInfo;
+
+	jobject j_info;
+
+	//Get the data
+	if(virStoragePoolGetInfo((virStoragePoolPtr)VSPP, &storagePoolInfo)<0)
+		return NULL;
+
+	//get the field Ids of info
+	jclass j_storagePoolInfo_cls = (*env)->FindClass(env,"org/libvirt/StoragePoolInfo");
+	jmethodID j_storagePoolInfo_constructor = (*env)->GetMethodID(env, j_storagePoolInfo_cls, "<init>", "(IJJJ)V");
+	
+	//Long live encapsulation
+	j_info=(*env)->NewObject(env,
+					j_storagePoolInfo_cls,
+					j_storagePoolInfo_constructor,
+					storagePoolInfo.state,
+					storagePoolInfo.capacity,
+					storagePoolInfo.allocation,
+					storagePoolInfo.available);	
+
+	return j_info;
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StoragePool__1getName
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic__virObj__conststring(env, obj, VSPP, (const char* (*)(void*))&virStoragePoolGetName);
+}
+
+JNIEXPORT jintArray JNICALL Java_org_libvirt_StoragePool__1getUUID
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic_getUUID(env, obj, VSPP, (int (*)(void*, unsigned char*))&virStoragePoolGetUUID);
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StoragePool__1getUUIDString
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic_getUUIDString(env, obj, VSPP, (int (*)(void*, char*))&virStoragePoolGetUUIDString);
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StoragePool__1getXMLDesc
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	return generic__virObj_int__string(env, obj, VSPP, flags, (char* (*)(void*, int))&virStoragePoolGetXMLDesc);
+}
+
+JNIEXPORT jobjectArray JNICALL Java_org_libvirt_StoragePool__1listVolumes
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic_list_stringarray(env, obj, VSPP, (int (*)(void*, char ** const, int))&virStoragePoolListVolumes, (int (*)(void*))&virStoragePoolNumOfVolumes);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StoragePool__1numOfVolumes
+  (JNIEnv *env, jobject obj, jlong VSPP){
+	return generic__virObj__int(env, obj, VSPP, (int (*)(void*))&virStoragePoolNumOfVolumes);
+}
+
+JNIEXPORT void JNICALL Java_org_libvirt_StoragePool__1refresh
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	generic__virObj_int__int(env, obj, VSPP, flags, (int (*)(void*, int))&virStoragePoolRefresh);
+}
+
+JNIEXPORT void JNICALL Java_org_libvirt_StoragePool__1setAutostart
+  (JNIEnv *env, jobject obj, jlong VSPP, jint flags){
+	generic__virObj_int__int(env, obj, VSPP, flags, (int (*)(void*, int))&virStoragePoolSetAutostart);
+}
+
+JNIEXPORT void JNICALL Java_org_libvirt_StoragePool__1undefine
+(JNIEnv *env, jobject obj, jlong VSPP){
+	generic__virObj__int(env, obj, VSPP, (int (*)(void*))&virStoragePoolUndefine);
+}
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_StoragePool__1storageVolLookupByName
+  (JNIEnv *env, jobject obj, jlong VSPP, jstring name){
+	return generic_lookupBy_string(env, obj, VSPP, name, (void* (*)(void*, const char *))&virStorageVolLookupByName);
+}
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_StoragePool__1storageVolCreateXML
+  (JNIEnv *env, jobject obj, jlong VSPP, jstring xmlDesc, jint flags){
+	return generic_CreateDefineXML_with_flags(env, obj, VSPP, xmlDesc, flags, (void* (*)(void*, const char *, unsigned int))&virStorageVolCreateXML);
+}
+
Index: src/org/libvirt/StorageVolInfo.java
===================================================================
RCS file: src/org/libvirt/StorageVolInfo.java
diff -N src/org/libvirt/StorageVolInfo.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/libvirt/StorageVolInfo.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,53 @@
+package org.libvirt;
+
+public class StorageVolInfo {
+	
+	/**
+	 * The type of the Volume
+	 */
+	public VirStorageVolType type;
+	/**
+	 * Logical size bytes
+	 */
+	public long	capacity;
+	/**
+	 * Current allocation bytes
+	 */
+	public long	allocation;
+	
+	public static enum VirStorageVolType{
+		/**
+		 * Regular file based volumes
+		 */
+		VIR_STORAGE_VOL_FILE, 
+		/**
+		 * Block based volumes
+		 */
+		VIR_STORAGE_VOL_BLOCK, 
+	}
+	
+	/**
+	 * This is meant to be called from the JNI side, as a convenience constructor
+	 * 
+	 * @param type the type, as defined by libvirt
+	 * @param capacity
+	 * @param allocation
+	 */
+	StorageVolInfo(int type, long capacity, long allocation){
+		switch(type){
+			case 0: this.type=VirStorageVolType.VIR_STORAGE_VOL_FILE; break;
+			case 1: this.type=VirStorageVolType.VIR_STORAGE_VOL_BLOCK; break;
+			default: assert(false);
+		}
+		this.capacity = capacity;
+		this.allocation = allocation;
+	}	
+	
+	public String toString(){
+		StringBuffer result = new StringBuffer("");
+		result.append("type:" + type + "\n");
+		result.append("capacity:" + capacity + "\n");
+		result.append("allocation:" + allocation + "\n");
+		return result.toString();
+	}
+}
Index: src/org/libvirt/StorageVol.java
===================================================================
RCS file: src/org/libvirt/StorageVol.java
diff -N src/org/libvirt/StorageVol.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/libvirt/StorageVol.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,158 @@
+package org.libvirt;
+
+public class StorageVol {
+	
+	static final class DeleteFlags{
+		/**
+		 * Delete metadata only (fast)
+		 */
+		static final int VIR_STORAGE_POOL_DELETE_NORMAL	 = 	0;
+		/**
+		 * Clear all data to zeros (slow)
+		 */
+		static final int VIR_STORAGE_POOL_DELETE_ZEROED	= 	1;
+	}
+	
+	public static enum Type {
+		/**
+		 * Regular file based volumes
+		 */
+		VIR_STORAGE_VOL_FILE,
+		/**
+		 * Block based volumes
+		 */
+		VIR_STORAGE_VOL_BLOCK
+	}
+
+	/**
+	 * the native virStorageVolPtr.
+	 */
+	private long  VSVP;
+	
+	/**
+	 * The VirConnect Object that represents the Hypervisor of this Domain
+	 */
+	private Connect virConnect;
+	
+	
+	/**
+	 * Constructs a VirStorageVol object from a known native virStoragePoolPtr, and a VirConnect object.
+	 * For use when native libvirt returns a virStorageVolPtr, i.e. error handling.
+	 * 
+	 * @param virConnect the Domain's hypervisor
+	 * @param VSVP the native virStorageVolPtr
+	 */
+	StorageVol(Connect virConnect, long VSVP){
+		this.virConnect = virConnect;
+		this.VSVP = VSVP;
+	}
+	
+	/**
+	 * Fetch a storage pool which contains this volume
+	 * 
+	 * @return StoragePool object, 
+	 * @throws LibvirtException
+	 */
+	public StoragePool storagePoolLookupByVolume()
+	throws LibvirtException {
+		return new StoragePool(virConnect, _storagePoolLookupByVolume(VSVP));
+	}
+
+	private native long _storagePoolLookupByVolume(long VSVP)
+	throws LibvirtException;
+
+	/**
+	 * Delete the storage volume from the pool
+	 * 
+	 * @param flags future flags, use 0 for now
+	 * @throws LibvirtException
+	 */
+	public void delete(int flags) throws LibvirtException{
+		_delete(VSVP, flags);
+	}
+	
+	private native int _delete(long VSVP, int flags) throws LibvirtException;
+	
+	/**
+	 * Release the storage volume handle. The underlying storage volume contains to exist
+	 * 
+	 * @throws LibvirtException
+	 */
+	public void free() throws LibvirtException{
+		_free(VSVP);
+	}
+	
+	private native int _free(long VSVP) throws LibvirtException;
+	
+	/**
+	 * Provides the connection object associated with a storage volume. The reference counter on the connection is not increased by this call.
+	 * 
+	 * @return the Connect object
+	 */
+	public Connect getConnect(){
+		return virConnect;
+	}
+	
+	/**
+	 * Fetches volatile information about the storage volume such as its current allocation
+	 * 
+	 * @return StorageVolInfo object
+	 * @throws LibvirtException
+	 */
+	public StorageVolInfo getInfo() throws LibvirtException{
+		return _getInfo(VSVP);
+	}
+
+	private native StorageVolInfo _getInfo(long VSVP) throws LibvirtException;
+
+	/**
+	 * Fetch the storage volume key. This is globally unique, so the same volume will have the same key no matter what host it is accessed from
+	 * 
+	 * @return the key
+	 * @throws LibvirtException
+	 */
+	public String getKey() throws LibvirtException{
+		return _getKey(VSVP);
+	}
+
+	private native String _getKey(long VSVP) throws LibvirtException;
+	
+	/**
+	 * Fetch the storage volume name. This is unique within the scope of a pool
+	 * 
+	 * @return the name
+	 * @throws LibvirtException
+	 */
+	public String getName() throws LibvirtException{
+		return _getName(VSVP);
+	}
+
+	private native String _getName(long VSVP) throws LibvirtException;
+	
+	/**
+	 * Fetch the storage volume path. 
+	 * Depending on the pool configuration this is either persistent across hosts, or dynamically assigned at pool startup. 
+	 * Consult pool documentation for information on getting the persistent naming
+	 * 
+	 * @return 
+	 * @throws LibvirtException
+	 */
+	public String getPath() throws LibvirtException{
+		return _getPath(VSVP);
+	}
+
+	private native String _getPath(long VSVP) throws LibvirtException;
+	
+	/**
+	 * Fetch an XML document describing all aspects of this storage volume
+	 * 
+	 * @param flags flags for XML generation (unused, pass 0)
+	 * @return the XML document
+	 * @throws LibvirtException
+	 */
+	public String getXMLDesc(int flags) throws LibvirtException{
+		return _getXMLDesc(VSVP, flags);
+	}
+	
+	private native String _getXMLDesc(long VSVP, int flags) throws LibvirtException;
+}
Index: src/org/libvirt/StoragePoolInfo.java
===================================================================
RCS file: src/org/libvirt/StoragePoolInfo.java
diff -N src/org/libvirt/StoragePoolInfo.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/libvirt/StoragePoolInfo.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,73 @@
+package org.libvirt;
+
+public class StoragePoolInfo {
+	
+	/**
+	 * the running state
+	 */
+	public StoragePoolState state;
+	
+	/**
+	 * Logical size bytes
+	 */
+	public long capacity;
+	
+	/**
+	 * Current allocation bytes
+	 */
+	public long allocation;
+	
+	/**
+	 * Remaining free space bytes
+	 */
+	public long available;
+	
+	public static enum StoragePoolState {
+		/**
+		 * Not running
+		 */
+		VIR_STORAGE_POOL_INACTIVE, 
+		/**
+		 * Initializing pool, not available
+		 */
+		VIR_STORAGE_POOL_BUILDING, 
+		/**
+		 * Running normally
+		 */
+		VIR_STORAGE_POOL_RUNNING, 
+		/**
+		 * Running degraded
+		 */
+		VIR_STORAGE_POOL_DEGRADED, 
+	}
+	
+	/**
+	 * This is meant to be called from the JNI side, as a convenience constructor
+	 * 
+	 * @param state the state, as defined by libvirt
+	 * @param capacity 
+	 * @param allocation
+	 * @param available
+	 */
+	StoragePoolInfo(int state, long capacity, long allocation, long available){
+		switch(state){
+			case 0: this.state=StoragePoolState.VIR_STORAGE_POOL_INACTIVE; break;
+			case 1: this.state=StoragePoolState.VIR_STORAGE_POOL_BUILDING; break;
+			case 2: this.state=StoragePoolState.VIR_STORAGE_POOL_RUNNING; break;
+			case 3: this.state=StoragePoolState.VIR_STORAGE_POOL_DEGRADED; break;
+			default: assert(false);
+		}
+		this.capacity = capacity;
+		this.allocation = allocation;
+		this.available = available;
+	}
+	
+	public String toString(){
+		StringBuffer result = new StringBuffer("");
+		result.append("state:" + state + "\n");
+		result.append("capacity:" + capacity + "\n");
+		result.append("allocation:" + allocation + "\n");
+		result.append("available:" + available + "\n");
+		return result.toString();
+	}
+}
Index: src/org/libvirt/StoragePool.java
===================================================================
RCS file: src/org/libvirt/StoragePool.java
diff -N src/org/libvirt/StoragePool.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/libvirt/StoragePool.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,286 @@
+package org.libvirt;
+
+public class StoragePool {
+
+	static final class BuildFlags{
+		/**
+		 * Regular build from scratch
+		 */
+		static final int VIR_STORAGE_POOL_BUILD_NEW	 = 	0;
+		/**
+		 * Repair / reinitialize
+		 */
+		static final int VIR_STORAGE_POOL_BUILD_REPAIR	= 	1; 
+		/**
+		 * Extend existing pool
+		 */
+		static final int VIR_STORAGE_POOL_BUILD_RESIZE	= 	2;
+	}
+	
+	static final class DeleteFlags{
+		/**
+		 * Delete metadata only (fast)
+		 */
+		static final int VIR_STORAGE_POOL_DELETE_NORMAL	 = 	0;
+		/**
+		 * Clear all data to zeros (slow)
+		 */
+		static final int VIR_STORAGE_POOL_DELETE_ZEROED	= 	1;
+	}
+	
+	/**
+	 * the native virStoragePoolPtr.
+	 */
+	private long  VSPP;
+	
+	/**
+	 * The VirConnect Object that represents the Hypervisor of this Domain
+	 */
+	private Connect virConnect;
+	
+	
+	/**
+	 * Constructs a VirStoragePool object from a known native virStoragePoolPtr, and a VirConnect object.
+	 * For use when native libvirt returns a virStoragePoolPtr, i.e. error handling.
+	 * 
+	 * @param virConnect the Domain's hypervisor
+	 * @param VSPP the native virStoragePoolPtr
+	 */
+	StoragePool(Connect virConnect, long VSPP){
+		this.virConnect = virConnect;
+		this.VSPP = VSPP;
+	}
+	
+	/**
+	 * Build the underlying storage pool
+	 * 
+	 * @param flags future flags, use 0 for now
+	 */
+	public void build(int flags) throws LibvirtException{
+		_build(VSPP, flags);
+	}
+	
+	private native int _build(long VSPP, int flags) throws LibvirtException;
+	
+	/**
+	 * Starts this inactive storage pool
+	 * 
+	 * @param flags future flags, use 0 for now
+	 */
+	public void create(int flags) throws LibvirtException{
+		_create(VSPP, flags);
+	}
+	
+	private native int _create(long VSPP, int flags) throws LibvirtException;
+	
+	/**
+	 * Delete the underlying pool resources. This is a non-recoverable operation. 
+	 * The virStoragePool object itself is not free'd.
+	 * 
+	 * @param flags flags for obliteration process
+	 */
+	public void delete(int flags) throws LibvirtException{
+		_delete(VSPP, flags);
+	}
+	
+	private native int _delete(long VSPP, int flags) throws LibvirtException;
+	
+	/**
+	 * Destroy an active storage pool. 
+	 * This will deactivate the pool on the host, but keep any persistent config associated with it. 
+	 * If it has a persistent config it can later be restarted with virStoragePoolCreate(). 
+	 * This does not free the associated virStoragePoolPtr object.
+	 */
+	public void destroy() throws LibvirtException{
+		_destroy(VSPP);
+	}
+	
+	private native int _destroy(long VSPP) throws LibvirtException;
+	
+	/**
+	 * Free a storage pool object, releasing all memory associated with it. 
+	 * Does not change the state of the pool on the host.
+	 */
+	public void free() throws LibvirtException{
+		_free(VSPP);
+	}
+	
+	private native int _free(long VSPP) throws LibvirtException;
+	
+	
+	/**
+	 * Fetches the value of the autostart flag, which determines whether the pool is automatically started at boot time
+	 *
+	 * @return the result
+	 * @throws LibvirtException
+	 */
+	public boolean getAutostart() throws LibvirtException{
+		return _getAutostart(VSPP);
+	}
+
+	private native boolean _getAutostart(long VSPP) throws LibvirtException;
+	
+	/**
+	 * Provides the connection pointer associated with a storage pool.
+	 *
+	 * @return the Connect object
+	 */
+	public Connect getConnect(){
+		return virConnect;
+	}
+	/**
+	 * Get volatile information about the storage pool such as free space / usage summary
+	 *
+	 * @return a StoragePoolInfo object describing this storage pool
+	 * @throws LibvirtException
+	 */
+	public StoragePoolInfo getInfo() throws LibvirtException{
+		return _getInfo(VSPP);
+	}
+
+	private native StoragePoolInfo _getInfo(long VSPP) throws LibvirtException;
+
+	/**
+	 * Fetch the locally unique name of the storage pool
+	 *
+	 * @return the name
+	 * @throws LibvirtException
+	 */
+	public String getName() throws LibvirtException{
+		return _getName(VSPP);
+	}
+
+	private native String _getName(long VSPP) throws LibvirtException;
+	
+	/**
+	 * Fetch the globally unique ID of this storage pool
+	 * 
+	 * @return the UUID as an unpacked int array
+	 * @throws LibvirtException
+	 */
+	public int[] getUUID() throws LibvirtException{
+		return _getUUID(VSPP);
+	}
+	
+	private native int[] _getUUID(long VSPP) throws LibvirtException;
+	
+
+	/**
+	 * Fetch the globally unique ID of the storage pool as a string
+	 * 
+	 * @return the UUID in canonical String format
+	 * @throws LibvirtException
+	 */
+	public String getUUIDString() throws LibvirtException{
+		return _getUUIDString(VSPP);
+	}
+
+	private native String _getUUIDString(long VSPP) throws LibvirtException;
+	
+	/**
+	 * Fetch an XML document describing all aspects of the storage pool. 
+	 * This is suitable for later feeding back into the virStoragePoolCreateXML method.
+	 * 
+	 * @param flags flags for XML format options (set of virDomainXMLFlags)
+	 * @return a XML document
+	 *-java @throws LibvirtException
+	 */
+	public String getXMLDesc(int flags) throws LibvirtException{
+		return _getXMLDesc(VSPP, flags);
+	}
+	
+	private native String _getXMLDesc(long VSPP, int flags) throws LibvirtException;
+	
+	/**
+	 * Fetch list of storage volume names
+	 *
+	 * @return an Array of Strings that contains the names of the storage volumes
+	 * @throws LibvirtException
+	 */
+	public String[] listVolumes() throws LibvirtException {
+		return _listVolumes(VSPP);
+	}
+
+	private native String[] _listVolumes(long VSPP)
+	throws LibvirtException;
+
+	/**
+	 * Fetch the number of storage volumes within a pool
+	 *
+	 * @return the number of storage pools
+	 * @throws LibvirtException
+	 */
+	public int numOfVolumes() throws LibvirtException {
+		return _numOfVolumes(VSPP);
+	}
+
+	private native int _numOfVolumes(long VSPP) throws LibvirtException;
+
+	/**
+	 * Request that the pool refresh its list of volumes. 
+	 * This may involve communicating with a remote server, and/or initializing new devices at the OS layer
+	 *
+	 * @param flags flags to control refresh behaviour (currently unused, use 0)
+	 * @throws LibvirtException
+	 */
+	public void refresh(int flags) throws LibvirtException {
+		_refresh(VSPP, flags);
+	}
+
+	private native void _refresh(long VSPP, int flags) throws LibvirtException;
+
+	/**
+	 * Sets the autostart flag
+	 *
+	 * @param autostart	new flag setting
+	 * @throws LibvirtException
+	 */
+	public void setAutostart(int autostart) throws LibvirtException {
+		_setAutostart(VSPP, autostart);
+	}
+
+	private native void _setAutostart(long VSPP, int autostart) throws LibvirtException;
+
+	/**
+	 * Undefine an inactive storage pool
+	 *
+	 * @throws LibvirtException
+	 */
+	public void undefine() throws LibvirtException {
+		_undefine(VSPP);
+	}
+
+	private native void _undefine(long VSPP) throws LibvirtException;
+
+	/**
+	 * Fetch an object representing to a storage volume based on its name within a pool
+	 *
+	 * @param name name of storage volume
+	 * @return The StorageVol object found
+	 * @throws LibvirtException
+	 */
+	public StorageVol storageVolLookupByName(String name)
+	throws LibvirtException {
+		return new StorageVol(virConnect, _storageVolLookupByName(VSPP, name));
+	}
+
+	private native long _storageVolLookupByName(long VSPP, String name)
+	throws LibvirtException;
+
+	/**
+	 * Create a storage volume within a pool based on an XML description. Not all pools support creation of volumes
+	 * 
+	 * @param xmlDesc description of volume to create
+	 * @param flags flags for creation (unused, pass 0)
+	 * @return the storage volume
+	 * @throws LibvirtException
+	 */
+	public StorageVol storageVolCreateXML(String xmlDesc, int flags)
+	throws LibvirtException {
+		return new StorageVol(virConnect, _storageVolCreateXML(VSPP, xmlDesc, flags));
+	}
+
+	private native long _storageVolCreateXML(long VSPP, String xmlDesc, int flags)
+	throws LibvirtException;
+
+}
Index: src/jni/org_libvirt_StorageVol.c
===================================================================
RCS file: src/jni/org_libvirt_StorageVol.c
diff -N src/jni/org_libvirt_StorageVol.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/jni/org_libvirt_StorageVol.c	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,65 @@
+#include "org_libvirt_StorageVol.h"
+#include "generic.h"
+#include <libvirt/libvirt.h>
+
+JNIEXPORT jlong JNICALL Java_org_libvirt_StorageVol__1storagePoolLookupByVolume
+  (JNIEnv *env, jobject obj, jlong VSVP){
+	return generic_lookupBy_none(env, obj, VSVP, (void* (*)(void*))&virStoragePoolLookupByVolume);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StorageVol__1delete
+  (JNIEnv *env, jobject obj, jlong VSVP, jint flags){
+	return generic__virObj_int__int(env, obj, VSVP, flags, (int (*)(void*, int))&virStorageVolDelete);
+}
+
+JNIEXPORT jint JNICALL Java_org_libvirt_StorageVol__1free
+  (JNIEnv *env, jobject obj, jlong VSVP){
+	return generic__virObj__int(env, obj, VSVP, (int (*)(void*))&virStorageVolFree);
+}
+
+JNIEXPORT jobject JNICALL Java_org_libvirt_StorageVol__1getInfo
+(JNIEnv *env, jobject obj, jlong VSVP){
+
+	virStorageVolInfo storageVolInfo;
+
+	jobject j_info;
+
+	//Get the data
+	if(virStorageVolGetInfo((virStorageVolPtr)VSVP, &storageVolInfo)<0)
+		return NULL;
+
+	//get the field Ids of info
+	jclass j_storageVolInfo_cls = (*env)->FindClass(env,"org/libvirt/StorageVolInfo");
+	jmethodID j_storageVolInfo_constructor = (*env)->GetMethodID(env, j_storageVolInfo_cls, "<init>", "(IJJ)V");
+	
+	//Long live encapsulation
+	j_info=(*env)->NewObject(env,
+					j_storageVolInfo_cls,
+					j_storageVolInfo_constructor,
+					storageVolInfo.type,
+					storageVolInfo.capacity,
+					storageVolInfo.allocation);	
+
+	return j_info;
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StorageVol__1getKey
+  (JNIEnv *env, jobject obj, jlong VSVP){
+	return generic__virObj__conststring(env, obj, VSVP, (const char* (*)(void*))&virStorageVolGetKey);
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StorageVol__1getName
+  (JNIEnv *env, jobject obj, jlong VSVP){
+	return generic__virObj__conststring(env, obj, VSVP, (const char* (*)(void*))&virStorageVolGetName);
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StorageVol__1getPath
+  (JNIEnv *env, jobject obj, jlong VSVP){
+	return generic__virObj__string(env, obj, VSVP, (char* (*)(void*))&virStorageVolGetPath);
+}
+
+JNIEXPORT jstring JNICALL Java_org_libvirt_StorageVol__1getXMLDesc
+  (JNIEnv *env, jobject obj, jlong VSVP, jint flags){
+	return generic__virObj_int__string(env, obj, VSVP, flags, (char* (*)(void*, int))&virStorageVolGetXMLDesc);
+}
+
Index: src/jni/generic.h
===================================================================
RCS file: src/jni/generic.h
diff -N src/jni/generic.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/jni/generic.h	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,88 @@
+#ifndef GENERIC_H_
+#define GENERIC_H_
+#include <jni.h>
+#include <libvirt/libvirt.h>
+
+/*
+ * Generic wrapper with a virObj argument returning an int
+ * (for functions like virDomainFree)
+ */
+jint generic__virObj__int
+  (JNIEnv *env, jobject obj, jlong virObj1, int (*virFunc1)(void*));
+
+/*
+ * Generic wrapper with a virObj and an int arguments returning an int
+ * (for functions like virStorageVolDelete)
+ */
+jint generic__virObj_int__int
+  (JNIEnv *env, jobject obj, jlong virObj1, jint arg1, int (*virFunc1)(void*, int));
+
+/*
+ * Generic wrapper with a virObj arguments returning a constant String
+ * (for functions like virNetworkGetBridgeName	)
+ */
+jstring generic__virObj__conststring
+  (JNIEnv *env, jobject obj, jlong virObj1, const char* (*virFunc1)(void*));
+
+/*
+ * Generic wrapper with a virObj arguments returning a String to be freed by the caller
+ * (for functions like virNetworkGetName)
+ */
+jstring generic__virObj__string
+  (JNIEnv *env, jobject obj, jlong virObj1, char* (*virFunc1)(void*));
+
+/*
+ * Generic wrapper with a virObj and an int argument returning a String to be freed by the caller
+ * (for functions like virStoragePoolGetXMLDesc)
+ */
+jstring generic__virObj_int__string
+  (JNIEnv *env, jobject obj, jlong virObj, jint arg1, char* (*virFunc1)(void*, int));
+
+/*
+ * Generic wrapper for the *getAutoStart functions
+ */
+jboolean generic_getAutostart
+  (JNIEnv *env, jobject obj, jlong virObj, int (*VirFunc1)(void*, int*));
+
+/*
+ * Generic wrapper for the *getUUID functions
+ */
+jintArray generic_getUUID
+  (JNIEnv *env, jobject obj, jlong virObj1, int	(*virFunc1)(void*, unsigned char*));
+
+/*
+ * Generic wrapper for the *getUUIDString functions
+ */
+jstring generic_getUUIDString
+  (JNIEnv *env, jobject obj, jlong virObj, int (*virFunc1)(void*, char*));
+
+/*
+ * Generic wrapper for the *List* functions that return an array of strings
+ * virFunc1 is the *List* function
+ * virFunc2 is the corresponding *NumOf* function
+ */
+JNIEXPORT jobjectArray JNICALL generic_list_stringarray
+  (JNIEnv *env, jobject obj, jlong virObj, int (*virFunc1)(void*, char ** const, int), int (*virFunc2)(void*));
+
+/*
+ * Generic wrapper for the *LookupBy* functions that take a string and return a VirObject
+ */
+JNIEXPORT jlong JNICALL generic_lookupBy_string
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_stringid, void* (*virFunc1)(void*, const char *));
+
+/*
+ * Generic wrapper for the *LookupBy* functions that take no argument and return a VirObject
+ */
+JNIEXPORT jlong JNICALL generic_lookupBy_none
+  (JNIEnv *env, jobject obj, jlong virObj, void* (*virFunc1)(void*));
+
+/*
+ * Generic wrapper for the *CreateXML* and *DefineXML* functions that take no flags and return VirObject
+ */
+JNIEXPORT jlong JNICALL generic_CreateDefineXML
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_xmlDesc, void*	(*virFunc1)	(void*, const char *));
+
+JNIEXPORT jlong JNICALL generic_CreateDefineXML_with_flags
+  (JNIEnv *env, jobject obj, jlong virObj, jstring j_xmlDesc, jint flags, void*	(*virFunc1)	(void*, const char *, unsigned int));
+
+#endif /*GENERIC_H_*/

--
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]