[libvirt-php] Add lookup function for pool & volume

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

 



---
 src/libvirt-php.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt-php.h |    2 +
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 3179271..5737163 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -102,8 +102,10 @@ static function_entry libvirt_functions[] = {
 	PHP_FE(libvirt_domain_snapshot_lookup_by_name, NULL)
 	/* Storagepool functions */
 	PHP_FE(libvirt_storagepool_lookup_by_name,NULL)
+	PHP_FE(libvirt_storagepool_lookup_by_volume,NULL)
 	PHP_FE(libvirt_storagepool_get_info,NULL)
 	PHP_FE(libvirt_storagevolume_lookup_by_name,NULL)
+	PHP_FE(libvirt_storagevolume_lookup_by_path,NULL)
 	PHP_FE(libvirt_storagevolume_get_name,NULL)
 	PHP_FE(libvirt_storagevolume_get_path,NULL)
 	PHP_FE(libvirt_storagevolume_get_info,NULL)
@@ -2600,6 +2602,37 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_name)
 	ZEND_REGISTER_RESOURCE(return_value, res_pool, le_libvirt_storagepool);
 }
 
+/* Storagepool functions */
+
+/*
+	Function name:	libvirt_storagepool_lookup_by_volume
+	Since version:	0.4.1(-1)
+	Description:	Function is used to lookup for storage pool by a volume
+	Arguments:		@res [volume]: volume resource of storage pool
+	Returns:		libvirt storagepool resource
+*/
+PHP_FUNCTION(libvirt_storagepool_lookup_by_volume)
+{
+	php_libvirt_volume *volume;
+	zval *zvolume;
+	virStoragePoolPtr pool=NULL;
+	php_libvirt_storagepool *res_pool;
+
+	GET_VOLUME_FROM_ARGS ("r", &zvolume);
+
+	pool = virStoragePoolLookupByVolume (volume->volume);
+	if (pool == NULL)
+	{
+		set_error ("Cannot find storage pool" TSRMLS_CC);
+		RETURN_FALSE;
+	}
+
+	res_pool = emalloc(sizeof(php_libvirt_storagepool));
+	res_pool->pool = pool;
+
+	ZEND_REGISTER_RESOURCE(return_value, res_pool, le_libvirt_storagepool);
+}
+
 /*
 	Function name:	libvirt_storagepool_list_volumes
 	Since version:	0.4.1(-1)
@@ -2693,6 +2726,39 @@ PHP_FUNCTION(libvirt_storagevolume_lookup_by_name)
 }
 
 /*
+	Function name:	libvirt_storagevolume_lookup_by_path
+	Since version:	0.4.1(-2)
+	Description:	Function is used to lookup for storage volume by it's path
+	Arguments:		@res [resource]: libvirt connection resource
+					@path [string]: path of the storage volume to look for
+	Returns:		libvirt storagevolume resource
+*/
+PHP_FUNCTION(libvirt_storagevolume_lookup_by_path)
+{
+	php_libvirt_connection *conn=NULL;
+	php_libvirt_volume *res_volume;
+	zval *zconn;
+	int name_len;
+	char *name=NULL;
+	virStorageVolPtr volume=NULL;
+
+	GET_CONNECTION_FROM_ARGS("rs",&zconn,&name,&name_len);
+	if ( (name == NULL) || (name_len<1)) RETURN_FALSE;
+
+	volume=virStorageVolLookupByPath (conn->conn,name);
+	if (volume==NULL)
+	{
+		set_error ("Cannot find volume");
+		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_storagevolume_get_name
 	Since version:	0.4.1(-2)
 	Description:	Function is used to get the storage volume name
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index b49355f..4646c64 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -165,9 +165,11 @@ PHP_FUNCTION(libvirt_domain_snapshot_revert);
 PHP_FUNCTION(libvirt_domain_snapshot_delete);
 /* Storagepool functions */
 PHP_FUNCTION(libvirt_storagepool_lookup_by_name);
+PHP_FUNCTION(libvirt_storagepool_lookup_by_volume);
 PHP_FUNCTION(libvirt_storagepool_list_volumes);
 PHP_FUNCTION(libvirt_storagepool_get_info);
 PHP_FUNCTION(libvirt_storagevolume_lookup_by_name);
+PHP_FUNCTION(libvirt_storagevolume_lookup_by_path);
 PHP_FUNCTION(libvirt_storagevolume_get_name);
 PHP_FUNCTION(libvirt_storagevolume_get_path);
 PHP_FUNCTION(libvirt_storagevolume_get_info);
-- 
1.7.3.4
o

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


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