Devel
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
August 2008
- 70 participants
- 162 discussions
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_*/
8
10
05 Aug '08
"make distcheck" is failing because two generated source files
are left behind. It requires that all generated files be removed.
This fixes it:
>From a7f4c47140ed0e585f1135e0f7917bc32f145997 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 4 Aug 2008 16:10:03 +0200
Subject: [PATCH] make distclean: remove generated source files
* src/Makefile.am (DISTCLEANFILES): Define to $(BUILT_SOURCES)
so "make distcheck" passes.
---
src/Makefile.am | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 556ad0a..5d238cd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -189,3 +189,4 @@ install-exec-local:
$(MKDIR_P) $(DESTDIR)$(localstatedir)/cache/libvirt
CLEANFILES = *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda
+DISTCLEANFILES = $(BUILT_SOURCES)
--
1.6.0.rc1.36.g5ff70
3
3
Hi,
This patch fixes syntax error(found TAB(s))
http://builder.virt-manager.org/module-libvirt--devel.html
Thanks
Atsushi SAKAI
3
2
Hi all.
I have the question about the option of dnsmasq that libvirt sets as a default virtual network.
Why does dnsmasq listen to all NICs as specified "--except-interface lo"?
And, at the following conditions, the message is output to /var/log/messages.
Do you know why it is output?
Conditions:
1) Dnsmasq is started by libvirt. And...
# ps -ef | grep dnsmasq
nobody 5877 5754 0 Jul30 ? 00:00:00 /usr/sbin/dnsmasq --keep-in-foreground --strict-order
--bind-interfaces --pid-file --conf-file --listen-address 192.168.122.1 --except-interface lo
--dhcp-leasefile=/var/lib/libvirt/dhcp-default.leases --dhcp-range 192.168.122.2,192.168.122.254
2) chenge the network address to '0.0.0.0'. And...
# ifconfig eth3 0 up
3) Dnsmasq recieves DHCPINFORM message from other DHCP servers.
Message:
dnsmasq[5877]: no address range available for DHCP request via eth3
Thank you
Nobuhiro Itou
2
2
At what time are volumes currently detected on NetFS? I see there is
some sort of storage now going on, since deleting files from NFS doesn't
delete them from vol-list directly. (If this is fixed in a recent
version... I'm sorry to bother)
Stefan
3
2
Hi,
I am running XEN on an debian etch. For clustering purposes I wanted to
boot fedora as virtual machine.
That works (except for nfs mounts) fine using the paravortualization
features.
But fully virtulalized guests do not even boot, I do not get any
sensefull error message, my config file looks like:
<domain type='xen'>
<name>werewolf</name>
<os>
<type>hvm</type>
<loader>/usr/lib/xen-3.0.3-1/boot/hvmloader</loader>
<kernel>/data/virtual/kernel/kvm1/vmlinuz-2.6.18-6-amd64</kernel>
<initrd>/data/virtual/kernel/kvm1/initrd.img-2.6.18-6-amd64</initrd>
<cmdline>root=/dev/hda1</cmdline>
</os>
<memory>524M</memory>
<vcpu>1</vcpu>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file'>
<source file='/tmp/werewolf.img.plb13810'/>
<target dev='hda1' bus='xen'/>
</disk>
<interface type='bridge'>
<source bridge='virbr1'/>
</interface>
</devices>
<features>
<acpi/>
</features>
</domain>
<domain type='xen'>
<name>werewolf</name>
<os>
<type>hvm</type>
<loader>/usr/lib/xen-3.0.3-1/boot/hvmloader</loader>
<kernel>/data/virtual/kernel/kvm1/vmlinuz-2.6.18-6-amd64</kernel>
<initrd>/data/virtual/kernel/kvm1/initrd.img-2.6.18-6-amd64</initrd>
<cmdline>root=/dev/hda1</cmdline>
</os>
<memory>524M</memory>
<vcpu>1</vcpu>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file'>
<source file='/tmp/werewolf.img.plb13810'/>
<target dev='hda1' bus='xen'/>
</disk>
<interface type='bridge'>
<source bridge='virbr1'/>
</interface>
</devices>
<features>
<acpi/>
</features>
</domain>
all I get when tryin virsh create is:
xend_post: error from xen daemon: (xend.err "Error creating domain: (0,
'Error')")
Whats wrong?
2
2
I wrote this months ago and forgot about it:
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 880a279..1e6e875 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -2171,7 +2171,7 @@ error:
*/
static virDomainDefPtr
xenDaemonParseSxpr(virConnectPtr conn,
- struct sexpr *root,
+ const struct sexpr *root,
int xendConfigVersion,
const char *cpus)
{
When you pull the thread (i.e., eliminate all resulting
warnings that arise from the above change), you end up with
the following additional const-adding changes:
(I'll squash the two into a single change set before committing)
>From 1d0fd10b999ab65c555d8cb5bcfc03bc5cad9e6e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 1 Aug 2008 15:36:31 +0200
Subject: [PATCH] xend_internal.c, sexpr.c: const-correctness
---
src/sexpr.c | 2 +-
src/sexpr.h | 2 +-
src/xend_internal.c | 19 ++++++++++---------
3 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/src/sexpr.c b/src/sexpr.c
index 90c549c..b607e41 100644
--- a/src/sexpr.c
+++ b/src/sexpr.c
@@ -519,7 +519,7 @@ sexpr_lookup(const struct sexpr *sexpr, const char *node)
* Returns true if the key was found, false otherwise
*/
int
-sexpr_has(struct sexpr *sexpr, const char *node)
+sexpr_has(const struct sexpr *sexpr, const char *node)
{
struct sexpr *s = sexpr_lookup_key(sexpr, node);
diff --git a/src/sexpr.h b/src/sexpr.h
index 0559a27..c3d038e 100644
--- a/src/sexpr.h
+++ b/src/sexpr.h
@@ -51,5 +51,5 @@ int sexpr_node_copy(const struct sexpr *sexpr, const char *node, char **dst);
const char *sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf,2,3);
struct sexpr *sexpr_lookup(const struct sexpr *sexpr, const char *node);
-int sexpr_has(struct sexpr *sexpr, const char *node);
+int sexpr_has(const struct sexpr *sexpr, const char *node);
#endif
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 1e6e875..e29702a 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -1180,7 +1180,8 @@ xend_detect_config_version(virConnectPtr conn) {
* Returns 0 in case of success and -1 in case of error
*/
static int
-xenDaemonParseSxprOS(virConnectPtr xend, struct sexpr *node,
+xenDaemonParseSxprOS(virConnectPtr xend,
+ const struct sexpr *node,
virDomainDefPtr def,
int hvm)
{
@@ -1640,11 +1641,11 @@ error:
static int
xenDaemonParseSxprDisks(virConnectPtr conn,
virDomainDefPtr def,
- struct sexpr *root,
+ const struct sexpr *root,
int hvm,
int xendConfigVersion)
{
- struct sexpr *cur, *node;
+ const struct sexpr *cur, *node;
virDomainDiskDefPtr disk = NULL, prev = def->disks;
for (cur = root; cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) {
@@ -1803,10 +1804,10 @@ error:
static int
xenDaemonParseSxprNets(virConnectPtr conn,
virDomainDefPtr def,
- struct sexpr *root)
+ const struct sexpr *root)
{
virDomainNetDefPtr net = NULL, prev = def->nets;
- struct sexpr *cur, *node;
+ const struct sexpr *cur, *node;
const char *tmp;
int vif_index = 0;
@@ -1964,7 +1965,7 @@ error:
static int
xenDaemonParseSxprUSB(virConnectPtr conn,
virDomainDefPtr def,
- struct sexpr *root)
+ const struct sexpr *root)
{
virDomainInputDefPtr prev = def->inputs;
struct sexpr *cur, *node;
@@ -2007,7 +2008,7 @@ no_memory:
static int
xenDaemonParseSxprGraphicsOld(virConnectPtr conn,
virDomainDefPtr def,
- struct sexpr *root,
+ const struct sexpr *root,
int hvm,
int xendConfigVersion)
{
@@ -2085,10 +2086,10 @@ no_memory:
static int
xenDaemonParseSxprGraphicsNew(virConnectPtr conn,
virDomainDefPtr def,
- struct sexpr *root)
+ const struct sexpr *root)
{
virDomainGraphicsDefPtr graphics = NULL;
- struct sexpr *cur, *node;
+ const struct sexpr *cur, *node;
const char *tmp;
/* append network devices and framebuffer */
--
1.6.0.rc1.29.gf08e3
2
2
01 Aug '08
This implements 'virsh edit', 'virsh net-edit' and 'virsh pool-edit'
commands.
Previous discussion of this patch was in this thread:
https://www.redhat.com/archives/libvir-list/2008-July/thread.html#00434
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
2
6
One good turn deserves another ;-)
This also normalizes spacing around the "*" in declarations
of vshControl and vshCmd pointers.
Of course, this compiles with no warnings and passes "make syntax-check".
>From e0db0c0eb4a62eafe1f5790de6d7f9a9d5cb84a0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 1 Aug 2008 14:00:20 +0200
Subject: [PATCH] virsh.c: more const-correctness
---
src/virsh.c | 266 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 133 insertions(+), 133 deletions(-)
diff --git a/src/virsh.c b/src/virsh.c
index 620f103..d636301 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -182,7 +182,7 @@ typedef struct vshCmdOpt {
*/
typedef struct {
const char *name;
- int (*handler) (vshControl *, vshCmd *); /* command handler */
+ int (*handler) (vshControl *, const vshCmd *); /* command handler */
vshCmdOptDef *opts; /* definition of command options */
vshCmdInfo *info; /* details about command */
} vshCmdDef;
@@ -218,35 +218,35 @@ typedef struct __vshControl {
static vshCmdDef commands[];
-static void vshError(vshControl * ctl, int doexit, const char *format, ...)
+static void vshError(vshControl *ctl, int doexit, const char *format, ...)
ATTRIBUTE_FORMAT(printf, 3, 4);
-static int vshInit(vshControl * ctl);
-static int vshDeinit(vshControl * ctl);
-static void vshUsage(vshControl * ctl, const char *cmdname);
+static int vshInit(vshControl *ctl);
+static int vshDeinit(vshControl *ctl);
+static void vshUsage(vshControl *ctl, const char *cmdname);
static void vshOpenLogFile(vshControl *ctl);
static void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap);
static void vshCloseLogFile(vshControl *ctl);
-static int vshParseArgv(vshControl * ctl, int argc, char **argv);
+static int vshParseArgv(vshControl *ctl, int argc, char **argv);
static const char *vshCmddefGetInfo(vshCmdDef * cmd, const char *info);
static vshCmdDef *vshCmddefSearch(const char *cmdname);
-static int vshCmddefHelp(vshControl * ctl, const char *name, int withprog);
+static int vshCmddefHelp(vshControl *ctl, const char *name, int withprog);
-static vshCmdOpt *vshCommandOpt(vshCmd * cmd, const char *name);
-static int vshCommandOptInt(vshCmd * cmd, const char *name, int *found);
-static char *vshCommandOptString(vshCmd * cmd, const char *name,
+static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
+static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
+static char *vshCommandOptString(const vshCmd *cmd, const char *name,
int *found);
#if 0
-static int vshCommandOptStringList(vshCmd * cmd, const char *name, char ***data);
+static int vshCommandOptStringList(const vshCmd *cmd, const char *name, char ***data);
#endif
-static int vshCommandOptBool(vshCmd * cmd, const char *name);
+static int vshCommandOptBool(const vshCmd *cmd, const char *name);
#define VSH_BYID (1 << 1)
#define VSH_BYUUID (1 << 2)
#define VSH_BYNAME (1 << 3)
-static virDomainPtr vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd,
+static virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
const char *optname, char **name, int flag);
/* default is lookup by Id, Name and UUID */
@@ -254,7 +254,7 @@ static virDomainPtr vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd,
vshCommandOptDomainBy(_ctl, _cmd, _optname, _name, \
VSH_BYID|VSH_BYUUID|VSH_BYNAME)
-static virNetworkPtr vshCommandOptNetworkBy(vshControl * ctl, vshCmd * cmd,
+static virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
const char *optname, char **name, int flag);
/* default is lookup by Name and UUID */
@@ -262,7 +262,7 @@ static virNetworkPtr vshCommandOptNetworkBy(vshControl * ctl, vshCmd * cmd,
vshCommandOptNetworkBy(_ctl, _cmd, _optname, _name, \
VSH_BYUUID|VSH_BYNAME)
-static virStoragePoolPtr vshCommandOptPoolBy(vshControl * ctl, vshCmd * cmd,
+static virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd,
const char *optname, char **name, int flag);
/* default is lookup by Name and UUID */
@@ -270,7 +270,7 @@ static virStoragePoolPtr vshCommandOptPoolBy(vshControl * ctl, vshCmd * cmd,
vshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \
VSH_BYUUID|VSH_BYNAME)
-static virStorageVolPtr vshCommandOptVolBy(vshControl * ctl, vshCmd * cmd,
+static virStorageVolPtr vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
const char *optname,
const char *pooloptname,
char **name, int flag);
@@ -280,9 +280,9 @@ static virStorageVolPtr vshCommandOptVolBy(vshControl * ctl, vshCmd * cmd,
vshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \
VSH_BYUUID|VSH_BYNAME)
-static void vshPrintExtra(vshControl * ctl, const char *format, ...)
+static void vshPrintExtra(vshControl *ctl, const char *format, ...)
ATTRIBUTE_FORMAT(printf, 2, 3);
-static void vshDebug(vshControl * ctl, int level, const char *format, ...)
+static void vshDebug(vshControl *ctl, int level, const char *format, ...)
ATTRIBUTE_FORMAT(printf, 3, 4);
/* XXX: add batch support */
@@ -290,19 +290,19 @@ static void vshDebug(vshControl * ctl, int level, const char *format, ...)
static const char *vshDomainStateToString(int state);
static const char *vshDomainVcpuStateToString(int state);
-static int vshConnectionUsability(vshControl * ctl, virConnectPtr conn,
+static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn,
int showerror);
-static void *_vshMalloc(vshControl * ctl, size_t sz, const char *filename, int line);
+static void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
#define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
-static void *_vshCalloc(vshControl * ctl, size_t nmemb, size_t sz, const char *filename, int line);
+static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *filename, int line);
#define vshCalloc(_ctl, _nmemb, _sz) _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
-static void *_vshRealloc(vshControl * ctl, void *ptr, size_t sz, const char *filename, int line);
+static void *_vshRealloc(vshControl *ctl, void *ptr, size_t sz, const char *filename, int line);
#define vshRealloc(_ctl, _ptr, _sz) _vshRealloc(_ctl, _ptr, _sz, __FILE__, __LINE__)
-static char *_vshStrdup(vshControl * ctl, const char *s, const char *filename, int line);
+static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line);
#define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
@@ -346,7 +346,7 @@ static vshCmdOptDef opts_help[] = {
};
static int
-cmdHelp(vshControl * ctl, vshCmd * cmd)
+cmdHelp(vshControl *ctl, const vshCmd *cmd)
{
const char *cmdname = vshCommandOptString(cmd, "command", NULL);
@@ -380,7 +380,7 @@ static vshCmdOptDef opts_autostart[] = {
};
static int
-cmdAutostart(vshControl * ctl, vshCmd * cmd)
+cmdAutostart(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name;
@@ -432,7 +432,7 @@ static vshCmdOptDef opts_connect[] = {
};
static int
-cmdConnect(vshControl * ctl, vshCmd * cmd)
+cmdConnect(vshControl *ctl, const vshCmd *cmd)
{
int ro = vshCommandOptBool(cmd, "readonly");
@@ -481,7 +481,7 @@ static vshCmdOptDef opts_console[] = {
#ifndef __MINGW32__
static int
-cmdConsole(vshControl * ctl, vshCmd * cmd)
+cmdConsole(vshControl *ctl, const vshCmd *cmd)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj = NULL;
@@ -531,7 +531,7 @@ cmdConsole(vshControl * ctl, vshCmd * cmd)
#else /* __MINGW32__ */
static int
-cmdConsole(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdConsole(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
vshError (ctl, FALSE, "%s", _("console not implemented on this platform"));
return FALSE;
@@ -557,7 +557,7 @@ static vshCmdOptDef opts_list[] = {
static int
-cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
int inactive = vshCommandOptBool(cmd, "inactive");
int all = vshCommandOptBool(cmd, "all");
@@ -673,7 +673,7 @@ static vshCmdOptDef opts_domstate[] = {
};
static int
-cmdDomstate(vshControl * ctl, vshCmd * cmd)
+cmdDomstate(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
@@ -711,7 +711,7 @@ static vshCmdOptDef opts_domblkstat[] = {
};
static int
-cmdDomblkstat (vshControl *ctl, vshCmd *cmd)
+cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name, *device;
@@ -768,7 +768,7 @@ static vshCmdOptDef opts_domifstat[] = {
};
static int
-cmdDomIfstat (vshControl *ctl, vshCmd *cmd)
+cmdDomIfstat (vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name, *device;
@@ -834,7 +834,7 @@ static vshCmdOptDef opts_suspend[] = {
};
static int
-cmdSuspend(vshControl * ctl, vshCmd * cmd)
+cmdSuspend(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name;
@@ -873,7 +873,7 @@ static vshCmdOptDef opts_create[] = {
};
static int
-cmdCreate(vshControl * ctl, vshCmd * cmd)
+cmdCreate(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *from;
@@ -921,7 +921,7 @@ static vshCmdOptDef opts_define[] = {
};
static int
-cmdDefine(vshControl * ctl, vshCmd * cmd)
+cmdDefine(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *from;
@@ -969,7 +969,7 @@ static vshCmdOptDef opts_undefine[] = {
};
static int
-cmdUndefine(vshControl * ctl, vshCmd * cmd)
+cmdUndefine(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1024,7 +1024,7 @@ static vshCmdOptDef opts_start[] = {
};
static int
-cmdStart(vshControl * ctl, vshCmd * cmd)
+cmdStart(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1070,7 +1070,7 @@ static vshCmdOptDef opts_save[] = {
};
static int
-cmdSave(vshControl * ctl, vshCmd * cmd)
+cmdSave(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name;
@@ -1115,7 +1115,7 @@ static vshCmdOptDef opts_schedinfo[] = {
};
static int
-cmdSchedinfo(vshControl * ctl, vshCmd * cmd)
+cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
{
char *schedulertype;
virDomainPtr dom;
@@ -1264,7 +1264,7 @@ static vshCmdOptDef opts_restore[] = {
};
static int
-cmdRestore(vshControl * ctl, vshCmd * cmd)
+cmdRestore(vshControl *ctl, const vshCmd *cmd)
{
char *from;
int found;
@@ -1303,7 +1303,7 @@ static vshCmdOptDef opts_dump[] = {
};
static int
-cmdDump(vshControl * ctl, vshCmd * cmd)
+cmdDump(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *name;
@@ -1347,7 +1347,7 @@ static vshCmdOptDef opts_resume[] = {
};
static int
-cmdResume(vshControl * ctl, vshCmd * cmd)
+cmdResume(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1386,7 +1386,7 @@ static vshCmdOptDef opts_shutdown[] = {
};
static int
-cmdShutdown(vshControl * ctl, vshCmd * cmd)
+cmdShutdown(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1425,7 +1425,7 @@ static vshCmdOptDef opts_reboot[] = {
};
static int
-cmdReboot(vshControl * ctl, vshCmd * cmd)
+cmdReboot(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1464,7 +1464,7 @@ static vshCmdOptDef opts_destroy[] = {
};
static int
-cmdDestroy(vshControl * ctl, vshCmd * cmd)
+cmdDestroy(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -1503,7 +1503,7 @@ static vshCmdOptDef opts_dominfo[] = {
};
static int
-cmdDominfo(vshControl * ctl, vshCmd * cmd)
+cmdDominfo(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
@@ -1585,7 +1585,7 @@ static vshCmdOptDef opts_freecell[] = {
};
static int
-cmdFreecell(vshControl * ctl, vshCmd * cmd)
+cmdFreecell(vshControl *ctl, const vshCmd *cmd)
{
int ret;
int cell, cell_given;
@@ -1627,7 +1627,7 @@ static vshCmdOptDef opts_vcpuinfo[] = {
};
static int
-cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
+cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
@@ -1716,7 +1716,7 @@ static vshCmdOptDef opts_vcpupin[] = {
};
static int
-cmdVcpupin(vshControl * ctl, vshCmd * cmd)
+cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
@@ -1849,7 +1849,7 @@ static vshCmdOptDef opts_setvcpus[] = {
};
static int
-cmdSetvcpus(vshControl * ctl, vshCmd * cmd)
+cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int count;
@@ -1906,7 +1906,7 @@ static vshCmdOptDef opts_setmem[] = {
};
static int
-cmdSetmem(vshControl * ctl, vshCmd * cmd)
+cmdSetmem(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
virDomainInfo info;
@@ -1963,7 +1963,7 @@ static vshCmdOptDef opts_setmaxmem[] = {
};
static int
-cmdSetmaxmem(vshControl * ctl, vshCmd * cmd)
+cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
virDomainInfo info;
@@ -2017,7 +2017,7 @@ static vshCmdInfo info_nodeinfo[] = {
};
static int
-cmdNodeinfo(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
virNodeInfo info;
@@ -2051,7 +2051,7 @@ static vshCmdInfo info_capabilities[] = {
};
static int
-cmdCapabilities (vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdCapabilities (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *caps;
@@ -2084,7 +2084,7 @@ static vshCmdOptDef opts_dumpxml[] = {
};
static int
-cmdDumpXML(vshControl * ctl, vshCmd * cmd)
+cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
int ret = TRUE;
@@ -2123,7 +2123,7 @@ static vshCmdOptDef opts_domname[] = {
};
static int
-cmdDomname(vshControl * ctl, vshCmd * cmd)
+cmdDomname(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
@@ -2153,7 +2153,7 @@ static vshCmdOptDef opts_domid[] = {
};
static int
-cmdDomid(vshControl * ctl, vshCmd * cmd)
+cmdDomid(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
unsigned int id;
@@ -2188,7 +2188,7 @@ static vshCmdOptDef opts_domuuid[] = {
};
static int
-cmdDomuuid(vshControl * ctl, vshCmd * cmd)
+cmdDomuuid(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char uuid[VIR_UUID_STRING_BUFLEN];
@@ -2227,7 +2227,7 @@ static vshCmdOptDef opts_migrate[] = {
};
static int
-cmdMigrate (vshControl *ctl, vshCmd *cmd)
+cmdMigrate (vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
const char *desturi;
@@ -2289,7 +2289,7 @@ static vshCmdOptDef opts_network_autostart[] = {
};
static int
-cmdNetworkAutostart(vshControl * ctl, vshCmd * cmd)
+cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
char *name;
@@ -2338,7 +2338,7 @@ static vshCmdOptDef opts_network_create[] = {
};
static int
-cmdNetworkCreate(vshControl * ctl, vshCmd * cmd)
+cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
char *from;
@@ -2386,7 +2386,7 @@ static vshCmdOptDef opts_network_define[] = {
};
static int
-cmdNetworkDefine(vshControl * ctl, vshCmd * cmd)
+cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
char *from;
@@ -2434,7 +2434,7 @@ static vshCmdOptDef opts_network_destroy[] = {
};
static int
-cmdNetworkDestroy(vshControl * ctl, vshCmd * cmd)
+cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
int ret = TRUE;
@@ -2474,7 +2474,7 @@ static vshCmdOptDef opts_network_dumpxml[] = {
};
static int
-cmdNetworkDumpXML(vshControl * ctl, vshCmd * cmd)
+cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
int ret = TRUE;
@@ -2516,7 +2516,7 @@ static vshCmdOptDef opts_network_list[] = {
};
static int
-cmdNetworkList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
int inactive = vshCommandOptBool(cmd, "inactive");
int all = vshCommandOptBool(cmd, "all");
@@ -2638,7 +2638,7 @@ static vshCmdOptDef opts_network_name[] = {
};
static int
-cmdNetworkName(vshControl * ctl, vshCmd * cmd)
+cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
@@ -2670,7 +2670,7 @@ static vshCmdOptDef opts_network_start[] = {
};
static int
-cmdNetworkStart(vshControl * ctl, vshCmd * cmd)
+cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
int ret = TRUE;
@@ -2709,7 +2709,7 @@ static vshCmdOptDef opts_network_undefine[] = {
};
static int
-cmdNetworkUndefine(vshControl * ctl, vshCmd * cmd)
+cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
int ret = TRUE;
@@ -2747,7 +2747,7 @@ static vshCmdOptDef opts_network_uuid[] = {
};
static int
-cmdNetworkUuid(vshControl * ctl, vshCmd * cmd)
+cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
char uuid[VIR_UUID_STRING_BUFLEN];
@@ -2797,7 +2797,7 @@ static vshCmdOptDef opts_pool_autostart[] = {
};
static int
-cmdPoolAutostart(vshControl * ctl, vshCmd * cmd)
+cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
char *name;
@@ -2846,7 +2846,7 @@ static vshCmdOptDef opts_pool_create[] = {
};
static int
-cmdPoolCreate(vshControl * ctl, vshCmd * cmd)
+cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
char *from;
@@ -2899,7 +2899,7 @@ static vshCmdOptDef opts_pool_create_as[] = {
static int
-cmdPoolCreateAs(vshControl * ctl, vshCmd * cmd)
+cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int found;
@@ -2984,7 +2984,7 @@ static vshCmdOptDef opts_pool_define[] = {
};
static int
-cmdPoolDefine(vshControl * ctl, vshCmd * cmd)
+cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
char *from;
@@ -3038,7 +3038,7 @@ static vshCmdOptDef opts_pool_define_as[] = {
static int
-cmdPoolDefineAs(vshControl * ctl, vshCmd * cmd)
+cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int found;
@@ -3122,7 +3122,7 @@ static vshCmdOptDef opts_pool_build[] = {
};
static int
-cmdPoolBuild(vshControl * ctl, vshCmd * cmd)
+cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3162,7 +3162,7 @@ static vshCmdOptDef opts_pool_destroy[] = {
};
static int
-cmdPoolDestroy(vshControl * ctl, vshCmd * cmd)
+cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3202,7 +3202,7 @@ static vshCmdOptDef opts_pool_delete[] = {
};
static int
-cmdPoolDelete(vshControl * ctl, vshCmd * cmd)
+cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3242,7 +3242,7 @@ static vshCmdOptDef opts_pool_refresh[] = {
};
static int
-cmdPoolRefresh(vshControl * ctl, vshCmd * cmd)
+cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3282,7 +3282,7 @@ static vshCmdOptDef opts_pool_dumpxml[] = {
};
static int
-cmdPoolDumpXML(vshControl * ctl, vshCmd * cmd)
+cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3324,7 +3324,7 @@ static vshCmdOptDef opts_pool_list[] = {
};
static int
-cmdPoolList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
int inactive = vshCommandOptBool(cmd, "inactive");
int all = vshCommandOptBool(cmd, "all");
@@ -3467,7 +3467,7 @@ static vshCmdOptDef opts_pool_info[] = {
};
static int
-cmdPoolInfo(vshControl * ctl, vshCmd * cmd)
+cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolInfo info;
virStoragePoolPtr pool;
@@ -3542,7 +3542,7 @@ static vshCmdOptDef opts_pool_name[] = {
};
static int
-cmdPoolName(vshControl * ctl, vshCmd * cmd)
+cmdPoolName(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
@@ -3574,7 +3574,7 @@ static vshCmdOptDef opts_pool_start[] = {
};
static int
-cmdPoolStart(vshControl * ctl, vshCmd * cmd)
+cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3645,7 +3645,7 @@ static int cmdVolSize(const char *data, unsigned long long *val)
}
static int
-cmdVolCreateAs(vshControl * ctl, vshCmd * cmd)
+cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
virStorageVolPtr vol;
@@ -3735,7 +3735,7 @@ static vshCmdOptDef opts_pool_undefine[] = {
};
static int
-cmdPoolUndefine(vshControl * ctl, vshCmd * cmd)
+cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
int ret = TRUE;
@@ -3773,7 +3773,7 @@ static vshCmdOptDef opts_pool_uuid[] = {
};
static int
-cmdPoolUuid(vshControl * ctl, vshCmd * cmd)
+cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
char uuid[VIR_UUID_STRING_BUFLEN];
@@ -3813,7 +3813,7 @@ static vshCmdOptDef opts_vol_create[] = {
};
static int
-cmdVolCreate(vshControl * ctl, vshCmd * cmd)
+cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
virStorageVolPtr vol;
@@ -3872,7 +3872,7 @@ static vshCmdOptDef opts_vol_delete[] = {
};
static int
-cmdVolDelete(vshControl * ctl, vshCmd * cmd)
+cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
int ret = TRUE;
@@ -3914,7 +3914,7 @@ static vshCmdOptDef opts_vol_info[] = {
};
static int
-cmdVolInfo(vshControl * ctl, vshCmd * cmd)
+cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolInfo info;
virStorageVolPtr vol;
@@ -3966,7 +3966,7 @@ static vshCmdOptDef opts_vol_dumpxml[] = {
};
static int
-cmdVolDumpXML(vshControl * ctl, vshCmd * cmd)
+cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
int ret = TRUE;
@@ -4007,7 +4007,7 @@ static vshCmdOptDef opts_vol_list[] = {
};
static int
-cmdVolList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
virStoragePoolPtr pool;
int maxactive = 0, i;
@@ -4085,7 +4085,7 @@ static vshCmdOptDef opts_vol_name[] = {
};
static int
-cmdVolName(vshControl * ctl, vshCmd * cmd)
+cmdVolName(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
@@ -4118,7 +4118,7 @@ static vshCmdOptDef opts_vol_key[] = {
};
static int
-cmdVolKey(vshControl * ctl, vshCmd * cmd)
+cmdVolKey(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
@@ -4152,7 +4152,7 @@ static vshCmdOptDef opts_vol_path[] = {
};
static int
-cmdVolPath(vshControl * ctl, vshCmd * cmd)
+cmdVolPath(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
@@ -4185,7 +4185,7 @@ static vshCmdInfo info_version[] = {
static int
-cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
unsigned long hvVersion;
const char *hvType;
@@ -4263,7 +4263,7 @@ static vshCmdInfo info_hostname[] = {
};
static int
-cmdHostname (vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED)
+cmdHostname (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *hostname;
@@ -4292,7 +4292,7 @@ static vshCmdInfo info_uri[] = {
};
static int
-cmdURI (vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED)
+cmdURI (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *uri;
@@ -4327,7 +4327,7 @@ static vshCmdOptDef opts_vncdisplay[] = {
};
static int
-cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
+cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj = NULL;
@@ -4403,7 +4403,7 @@ static vshCmdOptDef opts_ttyconsole[] = {
};
static int
-cmdTTYConsole(vshControl * ctl, vshCmd * cmd)
+cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj = NULL;
@@ -4465,7 +4465,7 @@ static vshCmdOptDef opts_attach_device[] = {
};
static int
-cmdAttachDevice(vshControl * ctl, vshCmd * cmd)
+cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *from;
@@ -4522,7 +4522,7 @@ static vshCmdOptDef opts_detach_device[] = {
};
static int
-cmdDetachDevice(vshControl * ctl, vshCmd * cmd)
+cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
char *from;
@@ -4583,7 +4583,7 @@ static vshCmdOptDef opts_attach_interface[] = {
};
static int
-cmdAttachInterface(vshControl * ctl, vshCmd * cmd)
+cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
char *mac, *target, *script, *type, *source;
@@ -4694,7 +4694,7 @@ static vshCmdOptDef opts_detach_interface[] = {
};
static int
-cmdDetachInterface(vshControl * ctl, vshCmd * cmd)
+cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
xmlDocPtr xml = NULL;
@@ -4817,7 +4817,7 @@ static vshCmdOptDef opts_attach_disk[] = {
};
static int
-cmdAttachDisk(vshControl * ctl, vshCmd * cmd)
+cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
char *source, *target, *driver, *subdriver, *type, *mode;
@@ -4975,7 +4975,7 @@ static vshCmdOptDef opts_detach_disk[] = {
};
static int
-cmdDetachDisk(vshControl * ctl, vshCmd * cmd)
+cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj=NULL;
@@ -5079,7 +5079,7 @@ static vshCmdInfo info_quit[] = {
};
static int
-cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
+cmdQuit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
ctl->imode = FALSE;
return TRUE;
@@ -5226,7 +5226,7 @@ vshCmddefGetData(vshCmdDef * cmd, int data_ct)
* Checks for required options
*/
static int
-vshCommandCheckOpts(vshControl * ctl, vshCmd * cmd)
+vshCommandCheckOpts(vshControl *ctl, vshCmd *cmd)
{
vshCmdDef *def = cmd->def;
vshCmdOptDef *d;
@@ -5268,7 +5268,7 @@ vshCmddefSearch(const char *cmdname)
}
static int
-vshCmddefHelp(vshControl * ctl, const char *cmdname, int withprog)
+vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog)
{
vshCmdDef *def = vshCmddefSearch(cmdname);
@@ -5337,7 +5337,7 @@ vshCommandOptFree(vshCmdOpt * arg)
}
static void
-vshCommandFree(vshCmd * cmd)
+vshCommandFree(vshCmd *cmd)
{
vshCmd *c = cmd;
@@ -5356,7 +5356,7 @@ vshCommandFree(vshCmd * cmd)
* Returns option by name
*/
static vshCmdOpt *
-vshCommandOpt(vshCmd * cmd, const char *name)
+vshCommandOpt(const vshCmd *cmd, const char *name)
{
vshCmdOpt *opt = cmd->opts;
@@ -5372,7 +5372,7 @@ vshCommandOpt(vshCmd * cmd, const char *name)
* Returns option as INT
*/
static int
-vshCommandOptInt(vshCmd * cmd, const char *name, int *found)
+vshCommandOptInt(const vshCmd *cmd, const char *name, int *found)
{
vshCmdOpt *arg = vshCommandOpt(cmd, name);
int res = 0, num_found = FALSE;
@@ -5394,7 +5394,7 @@ vshCommandOptInt(vshCmd * cmd, const char *name, int *found)
* Returns option as STRING
*/
static char *
-vshCommandOptString(vshCmd * cmd, const char *name, int *found)
+vshCommandOptString(const vshCmd *cmd, const char *name, int *found)
{
vshCmdOpt *arg = vshCommandOpt(cmd, name);
@@ -5406,7 +5406,7 @@ vshCommandOptString(vshCmd * cmd, const char *name, int *found)
#if 0
static int
-vshCommandOptStringList(vshCmd * cmd, const char *name, char ***data)
+vshCommandOptStringList(const vshCmd *cmd, const char *name, char ***data)
{
vshCmdOpt *arg = cmd->opts;
char **val = NULL;
@@ -5434,14 +5434,14 @@ vshCommandOptStringList(vshCmd * cmd, const char *name, char ***data)
* Returns TRUE/FALSE if the option exists
*/
static int
-vshCommandOptBool(vshCmd * cmd, const char *name)
+vshCommandOptBool(const vshCmd *cmd, const char *name)
{
return vshCommandOpt(cmd, name) ? TRUE : FALSE;
}
static virDomainPtr
-vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname,
+vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
char **name, int flag)
{
virDomainPtr dom = NULL;
@@ -5487,7 +5487,7 @@ vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname,
}
static virNetworkPtr
-vshCommandOptNetworkBy(vshControl * ctl, vshCmd * cmd, const char *optname,
+vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
char **name, int flag)
{
virNetworkPtr network = NULL;
@@ -5524,7 +5524,7 @@ vshCommandOptNetworkBy(vshControl * ctl, vshCmd * cmd, const char *optname,
}
static virStoragePoolPtr
-vshCommandOptPoolBy(vshControl * ctl, vshCmd * cmd, const char *optname,
+vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
char **name, int flag)
{
virStoragePoolPtr pool = NULL;
@@ -5561,7 +5561,7 @@ vshCommandOptPoolBy(vshControl * ctl, vshCmd * cmd, const char *optname,
}
static virStorageVolPtr
-vshCommandOptVolBy(vshControl * ctl, vshCmd * cmd,
+vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
const char *optname,
const char *pooloptname,
char **name, int flag)
@@ -5620,7 +5620,7 @@ vshCommandOptVolBy(vshControl * ctl, vshCmd * cmd,
* Executes command(s) and returns return code from last command
*/
static int
-vshCommandRun(vshControl * ctl, vshCmd * cmd)
+vshCommandRun(vshControl *ctl, const vshCmd *cmd)
{
int ret = TRUE;
@@ -5659,7 +5659,7 @@ vshCommandRun(vshControl * ctl, vshCmd * cmd)
#define VSH_TK_END 3
static int
-vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
+vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res)
{
int tk = VSH_TK_NONE;
int quote = FALSE;
@@ -5730,7 +5730,7 @@ vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
}
static int
-vshCommandParse(vshControl * ctl, char *cmdstr)
+vshCommandParse(vshControl *ctl, char *cmdstr)
{
char *str;
char *tkdata = NULL;
@@ -5915,7 +5915,7 @@ vshDomainVcpuStateToString(int state)
}
static int
-vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
+vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror)
{
/* TODO: use something like virConnectionState() to
* check usability of the connection
@@ -5929,7 +5929,7 @@ vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
}
static void
-vshDebug(vshControl * ctl, int level, const char *format, ...)
+vshDebug(vshControl *ctl, int level, const char *format, ...)
{
va_list ap;
@@ -5946,7 +5946,7 @@ vshDebug(vshControl * ctl, int level, const char *format, ...)
}
static void
-vshPrintExtra(vshControl * ctl, const char *format, ...)
+vshPrintExtra(vshControl *ctl, const char *format, ...)
{
va_list ap;
@@ -5960,7 +5960,7 @@ vshPrintExtra(vshControl * ctl, const char *format, ...)
static void
-vshError(vshControl * ctl, int doexit, const char *format, ...)
+vshError(vshControl *ctl, int doexit, const char *format, ...)
{
va_list ap;
@@ -5987,7 +5987,7 @@ vshError(vshControl * ctl, int doexit, const char *format, ...)
}
static void *
-_vshMalloc(vshControl * ctl, size_t size, const char *filename, int line)
+_vshMalloc(vshControl *ctl, size_t size, const char *filename, int line)
{
void *x;
@@ -5999,7 +5999,7 @@ _vshMalloc(vshControl * ctl, size_t size, const char *filename, int line)
}
static void *
-_vshCalloc(vshControl * ctl, size_t nmemb, size_t size, const char *filename, int line)
+_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, int line)
{
void *x;
@@ -6011,7 +6011,7 @@ _vshCalloc(vshControl * ctl, size_t nmemb, size_t size, const char *filename, in
}
static void *
-_vshRealloc(vshControl * ctl, void *ptr, size_t size, const char *filename, int line)
+_vshRealloc(vshControl *ctl, void *ptr, size_t size, const char *filename, int line)
{
void *x;
@@ -6024,7 +6024,7 @@ _vshRealloc(vshControl * ctl, void *ptr, size_t size, const char *filename, int
}
static char *
-_vshStrdup(vshControl * ctl, const char *s, const char *filename, int line)
+_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line)
{
char *x;
@@ -6041,7 +6041,7 @@ _vshStrdup(vshControl * ctl, const char *s, const char *filename, int line)
* Initialize connection.
*/
static int
-vshInit(vshControl * ctl)
+vshInit(vshControl *ctl)
{
if (ctl->conn)
return FALSE;
@@ -6357,7 +6357,7 @@ vshReadline (vshControl *ctl, const char *prompt)
* Deinitialize virsh
*/
static int
-vshDeinit(vshControl * ctl)
+vshDeinit(vshControl *ctl)
{
vshCloseLogFile(ctl);
free(ctl->name);
@@ -6377,7 +6377,7 @@ vshDeinit(vshControl * ctl)
* Print usage
*/
static void
-vshUsage(vshControl * ctl, const char *cmdname)
+vshUsage(vshControl *ctl, const char *cmdname)
{
vshCmdDef *cmd;
@@ -6413,7 +6413,7 @@ vshUsage(vshControl * ctl, const char *cmdname)
*
*/
static int
-vshParseArgv(vshControl * ctl, int argc, char **argv)
+vshParseArgv(vshControl *ctl, int argc, char **argv)
{
char *last = NULL;
int i, end = 0, help = 0;
--
1.6.0.rc1.29.gf08e3
2
2
This is something I previously submitted as part of one of the LXC
patches, but I figure it makes sense on its own, since OpenVZ needs
this now too.
This adds two new XML elements to the domain XML format:
- An <init> block within <os> allowing specification of the path for
a binary to run when starting the container - aka 'init' by any other
name. First we also specify that all containers will use an OS
type of 'exe' - as in executable - the container equivalent of 'hvm'
<os>
<type>exe</type>
<init>/sbin/init</init>
</os>
- An <filesystem> element for specifying how the container's filesystem
is to be provided. This can actually be useful for full-machine virt
too such as KVM which have host filesystem pass-through. There are
various ways to configure it:
eg to use '/some/directory' as the root filesystem for a container
<filesystem type='mount'>
<source dir='/some/directory'/>
<target dir='/'/>
</filesystem>
eg to use a template called 'fedora9web' as the root filesystem for
a container
<filesystem type='template'>
<source name='fedora9web'/>
<target dir='/'/>
</filesystem>
eg to use a file containing a filesystem as the root filesystem
<filesystem type='file'>
<source file='/some/file.img'/>
<target dir='/'/>
</filesystem>
eg to use a disk partition or other block device (eg LVM) containing
a filesystem as the root filesystem
<filesystem type='block'>
<source dev='/dev/VolGroup00/Fedora9Web'/>
<target dir='/'/>
</filesystem>
If setting the root filesystem, the target path will be '/', some
container based virt allows the host OS root filesystem to be
used in the guest, and merely specify additive mounts at specific
locations,
eg to override just /home within a container
<filesystem type='mount'>
<source dir='/some/directory'/>
<target dir='/home'/>
</filesystem>
I believe this should satisfy all the OpenVZ, LXC and Linux-VServer
drivers' requirements around filesystems
Daniel
diff -r 5614da5fe9ef src/domain_conf.c
--- a/src/domain_conf.c Fri Jul 25 15:38:46 2008 +0100
+++ b/src/domain_conf.c Tue Jul 29 16:03:38 2008 +0100
@@ -86,6 +86,12 @@
"virtio",
"xen")
+VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
+ "mount",
+ "block",
+ "file",
+ "template")
+
VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST,
"user",
"ethernet",
@@ -234,6 +240,18 @@
VIR_FREE(def->driverType);
virDomainDiskDefFree(def->next);
+ VIR_FREE(def);
+}
+
+void virDomainFSDefFree(virDomainFSDefPtr def)
+{
+ if (!def)
+ return;
+
+ VIR_FREE(def->src);
+ VIR_FREE(def->dst);
+
+ virDomainFSDefFree(def->next);
VIR_FREE(def);
}
@@ -345,6 +363,7 @@
virDomainGraphicsDefFree(def->graphics);
virDomainInputDefFree(def->inputs);
virDomainDiskDefFree(def->disks);
+ virDomainFSDefFree(def->fss);
virDomainNetDefFree(def->nets);
virDomainChrDefFree(def->serials);
virDomainChrDefFree(def->parallels);
@@ -355,6 +374,7 @@
VIR_FREE(def->os.type);
VIR_FREE(def->os.arch);
VIR_FREE(def->os.machine);
+ VIR_FREE(def->os.init);
VIR_FREE(def->os.kernel);
VIR_FREE(def->os.initrd);
VIR_FREE(def->os.cmdline);
@@ -620,6 +640,89 @@
error:
virDomainDiskDefFree(def);
+ def = NULL;
+ goto cleanup;
+}
+
+
+/* Parse the XML definition for a disk
+ * @param node XML nodeset to parse for disk definition
+ */
+static virDomainFSDefPtr
+virDomainFSDefParseXML(virConnectPtr conn,
+ xmlNodePtr node) {
+ virDomainFSDefPtr def;
+ xmlNodePtr cur;
+ char *type = NULL;
+ char *source = NULL;
+ char *target = NULL;
+
+ if (VIR_ALLOC(def) < 0) {
+ virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
+ return NULL;
+ }
+
+ type = virXMLPropString(node, "type");
+ if (type) {
+ if ((def->type = virDomainFSTypeFromString(type)) < 0) {
+ virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("unknown filesystem type '%s'"), type);
+ goto error;
+ }
+ } else {
+ def->type = VIR_DOMAIN_FS_TYPE_MOUNT;
+ }
+
+ cur = node->children;
+ while (cur != NULL) {
+ if (cur->type == XML_ELEMENT_NODE) {
+ if ((source == NULL) &&
+ (xmlStrEqual(cur->name, BAD_CAST "source"))) {
+
+ if (def->type == VIR_DOMAIN_FS_TYPE_MOUNT)
+ source = virXMLPropString(cur, "dir");
+ else if (def->type == VIR_DOMAIN_FS_TYPE_FILE)
+ source = virXMLPropString(cur, "file");
+ else if (def->type == VIR_DOMAIN_FS_TYPE_BLOCK)
+ source = virXMLPropString(cur, "dev");
+ else if (def->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
+ source = virXMLPropString(cur, "name");
+ } else if ((target == NULL) &&
+ (xmlStrEqual(cur->name, BAD_CAST "target"))) {
+ target = virXMLPropString(cur, "dir");
+ } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
+ def->readonly = 1;
+ }
+ }
+ cur = cur->next;
+ }
+
+ if (source == NULL) {
+ virDomainReportError(conn, VIR_ERR_NO_SOURCE,
+ target ? "%s" : NULL, target);
+ goto error;
+ }
+
+ if (target == NULL) {
+ virDomainReportError(conn, VIR_ERR_NO_TARGET,
+ source ? "%s" : NULL, source);
+ goto error;
+ }
+
+ def->src = source;
+ source = NULL;
+ def->dst = target;
+ target = NULL;
+
+cleanup:
+ VIR_FREE(type);
+ VIR_FREE(target);
+ VIR_FREE(source);
+
+ return def;
+
+ error:
+ virDomainFSDefFree(def);
def = NULL;
goto cleanup;
}
@@ -1351,6 +1454,10 @@
dev->type = VIR_DOMAIN_DEVICE_DISK;
if (!(dev->data.disk = virDomainDiskDefParseXML(conn, node)))
goto error;
+ } else if (xmlStrEqual(node->name, BAD_CAST "filesystem")) {
+ dev->type = VIR_DOMAIN_DEVICE_FS;
+ if (!(dev->data.fs = virDomainFSDefParseXML(conn, node)))
+ goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "interface")) {
dev->type = VIR_DOMAIN_DEVICE_NET;
if (!(dev->data.net = virDomainNetDefParseXML(conn, node)))
@@ -1560,7 +1667,21 @@
}
}
- if (!def->os.bootloader) {
+ /*
+ * Booting options for different OS types....
+ *
+ * - A bootloader (and optional kernel+initrd) (xen)
+ * - A kernel + initrd (xen)
+ * - A boot device (and optional kernel+initrd) (hvm)
+ * - An init script (exe)
+ */
+
+ if (STREQ(def->os.type, "exe")) {
+ def->os.init = virXPathString(conn, "string(./os/init[1])", ctxt);
+ }
+
+ if (STREQ(def->os.type, "xen") ||
+ STREQ(def->os.type, "hvm")) {
def->os.kernel = virXPathString(conn, "string(./os/kernel[1])", ctxt);
def->os.initrd = virXPathString(conn, "string(./os/initrd[1])", ctxt);
def->os.cmdline = virXPathString(conn, "string(./os/cmdline[1])", ctxt);
@@ -1610,12 +1731,9 @@
def->os.type,
def->os.arch,
type);
- if (!emulator) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- "%s", _("unsupported guest type"));
- goto error;
- }
- if (!(def->emulator = strdup(emulator))) {
+
+ if (emulator &&
+ !(def->emulator = strdup(emulator))) {
virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto error;
}
@@ -1648,6 +1766,23 @@
ptr = ptr->next;
}
}
+ }
+ VIR_FREE(nodes);
+
+ /* analysis of the filesystems */
+ if ((n = virXPathNodeSet(conn, "./devices/filesystem", ctxt, &nodes)) < 0) {
+ virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("cannot extract filesystem devices"));
+ goto error;
+ }
+ for (i = n - 1 ; i >= 0 ; i--) {
+ virDomainFSDefPtr fs = virDomainFSDefParseXML(conn,
+ nodes[i]);
+ if (!fs)
+ goto error;
+
+ fs->next = def->fss;
+ def->fss = fs;
}
VIR_FREE(nodes);
@@ -2202,6 +2337,57 @@
}
static int
+virDomainFSDefFormat(virConnectPtr conn,
+ virBufferPtr buf,
+ virDomainFSDefPtr def)
+{
+ const char *type = virDomainFSTypeToString(def->type);
+
+ if (!type) {
+ virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("unexpected filesystem type %d"), def->type);
+ return -1;
+ }
+
+ virBufferVSprintf(buf,
+ " <filesystem type='%s'>\n",
+ type);
+
+ if (def->src) {
+ switch (def->type) {
+ case VIR_DOMAIN_FS_TYPE_MOUNT:
+ virBufferEscapeString(buf, " <source dir='%s'/>\n",
+ def->src);
+ break;
+
+ case VIR_DOMAIN_FS_TYPE_BLOCK:
+ virBufferEscapeString(buf, " <source dev='%s'/>\n",
+ def->src);
+ break;
+
+ case VIR_DOMAIN_FS_TYPE_FILE:
+ virBufferEscapeString(buf, " <source file='%s'/>\n",
+ def->src);
+ break;
+
+ case VIR_DOMAIN_FS_TYPE_TEMPLATE:
+ virBufferEscapeString(buf, " <source name='%s'/>\n",
+ def->src);
+ }
+ }
+
+ virBufferVSprintf(buf, " <target dir='%s'/>\n",
+ def->dst);
+
+ if (def->readonly)
+ virBufferAddLit(buf, " <readonly/>\n");
+
+ virBufferAddLit(buf, " </filesystem>\n");
+
+ return 0;
+}
+
+static int
virDomainNetDefFormat(virConnectPtr conn,
virBufferPtr buf,
virDomainNetDefPtr def)
@@ -2479,6 +2665,7 @@
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainDiskDefPtr disk;
+ virDomainFSDefPtr fs;
virDomainNetDefPtr net;
virDomainSoundDefPtr sound;
virDomainInputDefPtr input;
@@ -2548,6 +2735,9 @@
else
virBufferVSprintf(&buf, ">%s</type>\n", def->os.type);
+ if (def->os.init)
+ virBufferEscapeString(&buf, " <init>%s</init>\n",
+ def->os.init);
if (def->os.loader)
virBufferEscapeString(&buf, " <loader>%s</loader>\n",
def->os.loader);
@@ -2621,6 +2811,13 @@
if (virDomainDiskDefFormat(conn, &buf, disk) < 0)
goto cleanup;
disk = disk->next;
+ }
+
+ fs = def->fss;
+ while (fs) {
+ if (virDomainFSDefFormat(conn, &buf, fs) < 0)
+ goto cleanup;
+ fs = fs->next;
}
net = def->nets;
diff -r 5614da5fe9ef src/domain_conf.h
--- a/src/domain_conf.h Fri Jul 25 15:38:46 2008 +0100
+++ b/src/domain_conf.h Tue Jul 29 16:03:38 2008 +0100
@@ -91,6 +91,28 @@
unsigned int shared : 1;
virDomainDiskDefPtr next;
+};
+
+
+/* Two types of disk backends */
+enum virDomainFSType {
+ VIR_DOMAIN_FS_TYPE_MOUNT, /* Better named 'bind' */
+ VIR_DOMAIN_FS_TYPE_BLOCK,
+ VIR_DOMAIN_FS_TYPE_FILE,
+ VIR_DOMAIN_FS_TYPE_TEMPLATE,
+
+ VIR_DOMAIN_FS_TYPE_LAST
+};
+
+typedef struct _virDomainFSDef virDomainFSDef;
+typedef virDomainFSDef *virDomainFSDefPtr;
+struct _virDomainFSDef {
+ int type;
+ char *src;
+ char *dst;
+ unsigned int readonly : 1;
+
+ virDomainFSDefPtr next;
};
@@ -262,6 +284,7 @@
/* Flags for the 'type' field in next struct */
enum virDomainDeviceType {
VIR_DOMAIN_DEVICE_DISK,
+ VIR_DOMAIN_DEVICE_FS,
VIR_DOMAIN_DEVICE_NET,
VIR_DOMAIN_DEVICE_INPUT,
VIR_DOMAIN_DEVICE_SOUND,
@@ -273,6 +296,7 @@
int type;
union {
virDomainDiskDefPtr disk;
+ virDomainFSDefPtr fs;
virDomainNetDefPtr net;
virDomainInputDefPtr input;
virDomainSoundDefPtr sound;
@@ -318,6 +342,7 @@
char *machine;
int nBootDevs;
int bootDevs[VIR_DOMAIN_BOOT_LAST];
+ char *init;
char *kernel;
char *initrd;
char *cmdline;
@@ -357,6 +382,7 @@
virDomainGraphicsDefPtr graphics;
virDomainDiskDefPtr disks;
+ virDomainFSDefPtr fss;
virDomainNetDefPtr nets;
virDomainInputDefPtr inputs;
virDomainSoundDefPtr sounds;
@@ -411,6 +437,7 @@
void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def);
void virDomainInputDefFree(virDomainInputDefPtr def);
void virDomainDiskDefFree(virDomainDiskDefPtr def);
+void virDomainFSDefFree(virDomainFSDefPtr def);
void virDomainNetDefFree(virDomainNetDefPtr def);
void virDomainChrDefFree(virDomainChrDefPtr def);
void virDomainSoundDefFree(virDomainSoundDefPtr def);
@@ -481,6 +508,7 @@
VIR_ENUM_DECL(virDomainDisk)
VIR_ENUM_DECL(virDomainDiskDevice)
VIR_ENUM_DECL(virDomainDiskBus)
+VIR_ENUM_DECL(virDomainFS)
VIR_ENUM_DECL(virDomainNet)
VIR_ENUM_DECL(virDomainChr)
VIR_ENUM_DECL(virDomainSoundModel)
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
4
10