[libvirt] [libvirt-php PATCH v2 0/4] new API for storage

Hi all: Those patches fixed some minor mistakes, and added 3 functions for storage. Lyre (4): Comment: fix typo Storagepool: make flag for pool refresh optional Volume: add "clone" support Storage: add lookup functions src/libvirt-php.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/libvirt-php.h | 3 + 2 files changed, 111 insertions(+), 2 deletions(-) -- 1.7.3.4

--- src/libvirt-php.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 890b447..b43da7a 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2704,7 +2704,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_name) } /* - Function name: libvirt_storagevolume_path + Function name: libvirt_storagevolume_get_path Since version: 0.4.1(-2) Description: Function is used to get the storage volume path Arguments: @res [resource]: libvirt storagevolume resource -- 1.7.3.4 P

--- src/libvirt-php.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index b43da7a..4835e59 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -3058,7 +3058,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) { -- 1.7.3.4 S

New API: libvirt_storagevolume_create_xml_from() It may need some asynchronous mechanism to use this fuction, since it may taks a long long time. --- src/libvirt-php.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt-php.h | 1 + 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 4835e59..6e8dea8 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) @@ -2804,6 +2805,47 @@ 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)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 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

--- src/libvirt-php.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/libvirt-php.h | 2 + 2 files changed, 66 insertions(+), 0 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 6e8dea8..6ca7c50 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) @@ -2591,6 +2593,36 @@ 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) + { + 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) @@ -2684,6 +2716,38 @@ 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) + { + 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 g

On 03/28/2011 01:06 PM, Lyre wrote:
Hi all:
Those patches fixed some minor mistakes, and added 3 functions for storage.
Lyre (4): Comment: fix typo Storagepool: make flag for pool refresh optional Volume: add "clone" support Storage: add lookup functions
src/libvirt-php.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/libvirt-php.h | 3 + 2 files changed, 111 insertions(+), 2 deletions(-)
Looks good. I've pushed all of them now, i.e. ACKed and pushed the whole series. Also, thanks for posting this as a patch series with cover letter (part 0/4). Much appreciated :) Thanks a lot! Michal -- Michal Novotny <minovotn@redhat.com>, RHCE Virtualization Team (xen userspace), Red Hat
participants (2)
-
Lyre
-
Michal Novotny