[libvirt] [libvirt-php] Add volume clone support

Lyre liyong at skybility.com
Sat Mar 26 06:35:39 UTC 2011


New API: libvirt_storagevolume_create_xml_from ()
---
 src/libvirt-php.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/libvirt-php.h |    1 +
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 890b447..3179271 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -109,6 +109,7 @@ static function_entry libvirt_functions[] = {
 	PHP_FE(libvirt_storagevolume_get_info,NULL)
 	PHP_FE(libvirt_storagevolume_get_xml_desc,NULL)
 	PHP_FE(libvirt_storagevolume_create_xml,NULL)
+	PHP_FE(libvirt_storagevolume_create_xml_from,NULL)
 	PHP_FE(libvirt_storagepool_get_uuid_string, NULL)
 	PHP_FE(libvirt_storagepool_get_name, NULL)
 	PHP_FE(libvirt_storagepool_lookup_by_uuid_string, NULL)
@@ -1904,7 +1905,16 @@ PHP_FUNCTION(libvirt_domain_memory_stats)
 	int retval;
 	long flags=0;
 	int i;
-	struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR];
+
+	struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR] =
+	{
+		{VIR_DOMAIN_MEMORY_STAT_SWAP_IN, 0},
+		{VIR_DOMAIN_MEMORY_STAT_SWAP_OUT, 0},
+		{VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT, 0},
+		{VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT, 0},
+		{VIR_DOMAIN_MEMORY_STAT_UNUSED, 0},
+		{VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 0},
+	};
 
 	GET_DOMAIN_FROM_ARGS("r|l",&zdomain,&flags);
 
@@ -2804,6 +2814,51 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml)
 }
 
 /*
+	Function name:	libvirt_storagevolume_create_xml_from
+	Since version:	0.4.1(-2)
+	Description:	Function is used to clone the new storage volume into pool from the orignial volume
+	Arguments:		@pool [resource]: libvirt storagepool resource
+					@xml [string]: XML string to create the storage volume in the storage pool
+					@original_volume [resource]: libvirt storagevolume resource
+	Returns:		libvirt storagevolume resource
+*/
+PHP_FUNCTION(libvirt_storagevolume_create_xml_from)
+{
+	php_libvirt_volume *res_volume=NULL;
+	php_libvirt_storagepool *pool=NULL;
+	zval *zpool;
+
+	php_libvirt_volume *pl_volume=NULL;
+	zval *zvolume;
+
+	virStorageVolPtr volume=NULL;
+	char *xml;
+	int xml_len;
+
+	if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &xml, &xml_len, &zvolume) == FAILURE)
+	{
+		RETURN_FALSE;
+	}
+
+	ZEND_FETCH_RESOURCE (pool, php_libvirt_storagepool*, &zpool, -1, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);
+	if ((pool==NULL)||(pool->pool==NULL))RETURN_FALSE;
+	ZEND_FETCH_RESOURCE (pl_volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+	if ((pl_volume==NULL)||(pl_volume->volume==NULL))RETURN_FALSE;
+
+	volume=virStorageVolCreateXMLFrom(pool->pool,xml, pl_volume->volume, 0);
+	if (volume==NULL)
+	{
+		set_error ("Cannot create new volume" TSRMLS_CC);
+		RETURN_FALSE;
+	}
+
+	res_volume= emalloc(sizeof(php_libvirt_volume));
+	res_volume->volume = volume;
+
+	ZEND_REGISTER_RESOURCE(return_value, res_volume, le_libvirt_volume);
+}
+
+/*
 	Function name:	libvirt_storagepool_get_uuid_string
 	Since version:	0.4.1(-1)
 	Description:	Function is used to get storage pool by UUID string
@@ -3058,7 +3113,7 @@ PHP_FUNCTION(libvirt_storagepool_refresh)
 	zval *zpool;
 	unsigned long flags = 0;
 
-	GET_STORAGEPOOL_FROM_ARGS ("rl", &zpool, &flags);
+	GET_STORAGEPOOL_FROM_ARGS ("r|l", &zpool, &flags);
 
 	if (virStoragePoolRefresh (pool->pool, flags) < 0)
 	{
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index 816175d..b49355f 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -173,6 +173,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_path);
 PHP_FUNCTION(libvirt_storagevolume_get_info);
 PHP_FUNCTION(libvirt_storagevolume_get_xml_desc);
 PHP_FUNCTION(libvirt_storagevolume_create_xml);
+PHP_FUNCTION(libvirt_storagevolume_create_xml_from);
 PHP_FUNCTION(libvirt_storagepool_get_uuid_string);
 PHP_FUNCTION(libvirt_storagepool_get_name);
 PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string);
-- 
1.7.3.4
m




More information about the libvir-list mailing list