[libvirt-php PATCH v2 07/11] Split up the bindings for libvirt storage API

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

 



---
 src/Makefile.am       |    3 +-
 src/libvirt-php.c     | 1188 +------------------------------------------------
 src/libvirt-php.h     |   49 --
 src/libvirt-storage.c | 1130 ++++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt-storage.h |  137 ++++++
 5 files changed, 1271 insertions(+), 1236 deletions(-)
 create mode 100644 src/libvirt-storage.c
 create mode 100644 src/libvirt-storage.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 4ae01db..32b23cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,7 +26,8 @@ libvirt_php_la_SOURCES = \
 	libvirt-node.c libvirt-node.h \
 	libvirt-stream.c libvirt-stream.h \
 	libvirt-domain.c libvirt-domain.h \
-	libvirt-network.c libvirt-network.h 
+	libvirt-network.c libvirt-network.h \
+	libvirt-storage.c libvirt-storage.h
 libvirt_php_la_CFLAGS = \
 	$(AM_CFLAGS) \
 	-DCOMPILE_DL_LIBVIRT=1
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index e3e5554..a4108a6 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -24,6 +24,7 @@
 #include "libvirt-stream.h"
 #include "libvirt-domain.h"
 #include "libvirt-network.h"
+#include "libvirt-storage.h"
 
 DEBUG_INIT("core");
 
@@ -37,8 +38,6 @@ const char *features_binaries[] = { NULL };
 #endif
 
 /* ZEND thread safe per request globals definition */
-int le_libvirt_storagepool;
-int le_libvirt_volume;
 int le_libvirt_nodedev;
 int le_libvirt_snapshot;
 int le_libvirt_nwfilter;
@@ -484,38 +483,7 @@ static zend_function_entry libvirt_functions[] = {
     PHP_FE(libvirt_domain_snapshot_revert,       arginfo_libvirt_conn_optflags)
     PHP_FE(libvirt_domain_snapshot_delete,       arginfo_libvirt_conn_optflags)
     PHP_FE(libvirt_domain_snapshot_lookup_by_name, arginfo_libvirt_domain_snapshot_lookup_by_name)
-    /* Storagepool functions */
-    PHP_FE(libvirt_storagepool_lookup_by_name,   arginfo_libvirt_conn_name)
-    PHP_FE(libvirt_storagepool_lookup_by_volume, arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_get_info,         arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagevolume_lookup_by_name, arginfo_libvirt_conn_name)
-    PHP_FE(libvirt_storagevolume_lookup_by_path, arginfo_libvirt_storagevolume_lookup_by_path)
-    PHP_FE(libvirt_storagevolume_get_name,       arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagevolume_get_path,       arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagevolume_get_info,       arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagevolume_get_xml_desc,   arginfo_libvirt_storagevolume_get_xml_desc)
-    PHP_FE(libvirt_storagevolume_create_xml,     arginfo_libvirt_conn_xml)
-    PHP_FE(libvirt_storagevolume_create_xml_from,arginfo_libvirt_storagevolume_create_xml_from)
-    PHP_FE(libvirt_storagevolume_delete,         arginfo_libvirt_conn_optflags)
-    PHP_FE(libvirt_storagevolume_download,       arginfo_libvirt_storagevolume_download)
-    PHP_FE(libvirt_storagevolume_upload,         arginfo_libvirt_storagevolume_download)
-    PHP_FE(libvirt_storagevolume_resize,         arginfo_libvirt_storagevolume_resize)
-    PHP_FE(libvirt_storagepool_get_uuid_string,  arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_get_name,         arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_lookup_by_uuid_string, arginfo_libvirt_conn_uuid)
-    PHP_FE(libvirt_storagepool_get_xml_desc,     arginfo_libvirt_conn_xpath)
-    PHP_FE(libvirt_storagepool_define_xml,       arginfo_libvirt_storagepool_define_xml)
-    PHP_FE(libvirt_storagepool_undefine,         arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_create,           arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_destroy,          arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_is_active,        arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_get_volume_count, arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_refresh,          arginfo_libvirt_conn_optflags)
-    PHP_FE(libvirt_storagepool_set_autostart,    arginfo_libvirt_conn_flags)
-    PHP_FE(libvirt_storagepool_get_autostart,    arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_build,            arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_delete,           arginfo_libvirt_conn)
-    /* Network functions */
+    PHP_FE_LIBVIRT_STORAGE
     PHP_FE_LIBVIRT_NETWORK
     PHP_FE_LIBVIRT_NODE
     /* Nodedev functions */
@@ -536,10 +504,6 @@ static zend_function_entry libvirt_functions[] = {
     /* List functions */
     PHP_FE(libvirt_list_domain_snapshots,        arginfo_libvirt_conn_optflags)
     PHP_FE(libvirt_list_nodedevs,                arginfo_libvirt_conn_optcap)
-    PHP_FE(libvirt_list_storagepools,            arginfo_libvirt_conn)
-    PHP_FE(libvirt_list_active_storagepools,     arginfo_libvirt_conn)
-    PHP_FE(libvirt_list_inactive_storagepools,   arginfo_libvirt_conn)
-    PHP_FE(libvirt_storagepool_list_volumes,     arginfo_libvirt_conn)
     PHP_FE(libvirt_list_all_nwfilters,           arginfo_libvirt_conn)
     PHP_FE(libvirt_list_nwfilters,               arginfo_libvirt_conn)
     /* Version information and common function */
@@ -577,7 +541,6 @@ zend_module_entry libvirt_module_entry = {
 ZEND_GET_MODULE(libvirt)
 #endif
 
-
 /* PHP init options */
 PHP_INI_BEGIN()
 STD_PHP_INI_ENTRY("libvirt.longlong_to_string", "1", PHP_INI_ALL, OnUpdateBool, longlong_to_string_ini, zend_libvirt_globals, libvirt_globals)
@@ -1222,60 +1185,6 @@ int is_local_connection(virConnectPtr conn)
 #endif
 }
 
-/* Destructor for storagepool resource */
-static void php_libvirt_storagepool_dtor(virt_resource *rsrc TSRMLS_DC)
-{
-    php_libvirt_storagepool *pool = (php_libvirt_storagepool *)rsrc->ptr;
-    int rv = 0;
-
-    if (pool != NULL) {
-        if (pool->pool != NULL) {
-            if (!check_resource_allocation(NULL, INT_RESOURCE_STORAGEPOOL, pool->pool TSRMLS_CC)) {
-                pool->pool = NULL;
-                efree(pool);
-                return;
-            }
-            rv = virStoragePoolFree(pool->pool);
-            if (rv != 0) {
-                DPRINTF("%s: virStoragePoolFree(%p) returned %d (%s)\n", __FUNCTION__, pool->pool, rv, LIBVIRT_G(last_error));
-                php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStoragePoolFree failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
-            } else {
-                DPRINTF("%s: virStoragePoolFree(%p) completed successfully\n", __FUNCTION__, pool->pool);
-                resource_change_counter(INT_RESOURCE_STORAGEPOOL, NULL, pool->pool, 0 TSRMLS_CC);
-            }
-            pool->pool = NULL;
-        }
-        efree(pool);
-    }
-}
-
-/* Destructor for volume resource */
-static void php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC)
-{
-    php_libvirt_volume *volume = (php_libvirt_volume *)rsrc->ptr;
-    int rv = 0;
-
-    if (volume != NULL) {
-        if (volume->volume != NULL) {
-            if (!check_resource_allocation(NULL, INT_RESOURCE_VOLUME, volume->volume TSRMLS_CC)) {
-                volume->volume = NULL;
-                efree(volume);
-                return;
-            }
-            rv = virStorageVolFree(volume->volume);
-            if (rv != 0) {
-                DPRINTF("%s: virStorageVolFree(%p) returned %d (%s)\n", __FUNCTION__, volume->volume, rv, LIBVIRT_G(last_error));
-                php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
-            } else {
-                DPRINTF("%s: virStorageVolFree(%p) completed successfully\n", __FUNCTION__, volume->volume);
-                resource_change_counter(INT_RESOURCE_VOLUME, NULL, volume->volume, 0 TSRMLS_CC);
-            }
-            volume->volume = NULL;
-        }
-        efree(volume);
-    }
-}
-
 /* Destructor for nodedev resource */
 static void php_libvirt_nodedev_dtor(virt_resource *rsrc TSRMLS_DC)
 {
@@ -1696,32 +1605,6 @@ PHP_MSHUTDOWN_FUNCTION(libvirt)
             RETURN_FALSE;                                                                       \
     } while (0)
 
-#define GET_STORAGEPOOL_FROM_ARGS(args, ...)                                                    \
-    do {                                                                                        \
-        reset_error(TSRMLS_C);                                                                  \
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILURE) {   \
-            set_error("Invalid arguments" TSRMLS_CC);                                           \
-            RETURN_FALSE;                                                                       \
-        }                                                                                       \
-                                                                                                \
-        VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);\
-        if ((pool == NULL) || (pool->pool == NULL))                                             \
-            RETURN_FALSE;                                                                       \
-    } while (0)                                                                                 \
-
-#define GET_VOLUME_FROM_ARGS(args, ...)                                                         \
-    do {                                                                                        \
-        reset_error(TSRMLS_C);                                                                  \
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILURE) {   \
-            set_error("Invalid arguments" TSRMLS_CC);                                           \
-            RETURN_FALSE;                                                                       \
-        }                                                                                       \
-                                                                                                \
-        VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);\
-        if ((volume == NULL) || (volume->volume == NULL))                                       \
-            RETURN_FALSE;                                                                       \
-    } while (0)                                                                                 \
-
 #define GET_SNAPSHOT_FROM_ARGS(args, ...)                                                       \
     do {                                                                                        \
         reset_error(TSRMLS_C);                                                                  \
@@ -2928,1075 +2811,8 @@ PHP_FUNCTION(libvirt_list_domain_snapshots)
     efree(names);
 }
 
-/* Storagepool functions */
-
-/*
- * Function name:   libvirt_storagepool_lookup_by_name
- * Since version:   0.4.1(-1)
- * Description:     Function is used to lookup for storage pool by it's name
- * Arguments:       @res [resource]: libvirt connection resource
- *                  @name [string]: storage pool name
- * Returns:         libvirt storagepool resource
- */
-PHP_FUNCTION(libvirt_storagepool_lookup_by_name)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    strsize_t name_len;
-    char *name = NULL;
-    virStoragePoolPtr pool = NULL;
-    php_libvirt_storagepool *res_pool;
-
-    GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
-
-    if ((name == NULL) || (name_len < 1))
-        RETURN_FALSE;
-    pool = virStoragePoolLookupByName(conn->conn, name);
-    DPRINTF("%s: virStoragePoolLookupByName(%p, %s) returned %p\n", PHPFUNC, conn->conn, name, pool);
-    if (pool == NULL)
-        RETURN_FALSE;
-
-    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
-    res_pool->pool = pool;
-    res_pool->conn = conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
-    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(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);
-    DPRINTF("%s: virStoragePoolLookupByVolume(%p) returned %p\n", PHPFUNC, volume->volume, pool);
-    if (pool == NULL)
-        RETURN_FALSE;
-
-    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
-    res_pool->pool = pool;
-    res_pool->conn = volume->conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
-    resource_change_counter(INT_RESOURCE_STORAGEPOOL, res_pool->conn->conn, res_pool->pool, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
-}
-
-/*
- * Function name:   libvirt_storagepool_list_volumes
- * Since version:   0.4.1(-1)
- * Description:     Function is used to list volumes in the specified storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         list of storage volume names in the storage pool in an array using default keys (indexes)
- */
-PHP_FUNCTION(libvirt_storagepool_list_volumes)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    char **names = NULL;
-    int expectedcount = -1;
-    int i;
-    int count = -1;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    if ((expectedcount = virStoragePoolNumOfVolumes(pool->pool)) < 0)
-        RETURN_FALSE;
-
-    DPRINTF("%s: virStoragePoolNumOfVolumes(%p) returned %d\n", PHPFUNC, pool->pool, expectedcount);
-    names = (char **)emalloc(expectedcount*sizeof(char *));
-
-    count = virStoragePoolListVolumes(pool->pool, names, expectedcount);
-    DPRINTF("%s: virStoragePoolListVolumes(%p, %p, %d) returned %d\n", PHPFUNC, pool->pool, names, expectedcount, count);
-    array_init(return_value);
-
-    if ((count != expectedcount) || (count < 0))
-        RETURN_FALSE;
-    for (i = 0; i < count; i++) {
-        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
-        free(names[i]);
-    }
-
-    efree(names);
-}
-
-/*
- * Function name:   libvirt_storagepool_get_info
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get information about the storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         storage pool information array of state, capacity, allocation and available space
- */
-PHP_FUNCTION(libvirt_storagepool_get_info)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    virStoragePoolInfo poolInfo;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolGetInfo(pool->pool, &poolInfo);
-    DPRINTF("%s: virStoragePoolGetInfo(%p, <info>) returned %d\n", PHPFUNC, pool->pool, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-
-    array_init(return_value);
-
-    // @todo: fix the long long returns
-    LONGLONG_INIT;
-    add_assoc_long(return_value, "state", (long)poolInfo.state);
-    LONGLONG_ASSOC(return_value, "capacity", poolInfo.capacity);
-    LONGLONG_ASSOC(return_value, "allocation", poolInfo.allocation);
-    LONGLONG_ASSOC(return_value, "available", poolInfo.available);
-}
-
-/*
- * Function name:   libvirt_storagevolume_lookup_by_name
- * Since version:   0.4.1(-1)
- * Description:     Function is used to lookup for storage volume by it's name
- * Arguments:       @res [resource]: libvirt storagepool resource
- *                  @name [string]: name of the storage volume to look for
- * Returns:         libvirt storagevolume resource
- */
-PHP_FUNCTION(libvirt_storagevolume_lookup_by_name)
-{
-    php_libvirt_storagepool *pool = NULL;
-    php_libvirt_volume *res_volume;
-    zval *zpool;
-    strsize_t name_len;
-    char *name = NULL;
-    virStorageVolPtr volume = NULL;
-
-    GET_STORAGEPOOL_FROM_ARGS("rs", &zpool, &name, &name_len);
-    if ((name == NULL) || (name_len < 1))
-        RETURN_FALSE;
-
-    volume = virStorageVolLookupByName(pool->pool, name);
-    DPRINTF("%s: virStorageVolLookupByName(%p, %s) returned %p\n", PHPFUNC, pool->pool, name, volume);
-    if (volume == NULL)
-        RETURN_FALSE;
-
-    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
-    res_volume->volume = volume;
-    res_volume->conn   = pool->conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
-    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
-}
-
-/*
- * 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;
-    strsize_t 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);
-    DPRINTF("%s: virStorageVolLookupByPath(%p, %s) returned %p\n", PHPFUNC, conn->conn, name, volume);
-    if (volume == NULL) {
-        set_error_if_unset("Cannot find storage volume on requested path" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
-    res_volume->volume = volume;
-    res_volume->conn   = conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
-    resource_change_counter(INT_RESOURCE_VOLUME, conn->conn, res_volume->volume, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(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
- * Arguments:       @res [resource]: libvirt storagevolume resource
- * Returns:         storagevolume name
- */
-PHP_FUNCTION(libvirt_storagevolume_get_name)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    const char *retval;
-
-    GET_VOLUME_FROM_ARGS("r", &zvolume);
-
-    retval = virStorageVolGetName(volume->volume);
-    DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval);
-    if (retval == NULL)
-        RETURN_FALSE;
-
-    VIRT_RETURN_STRING(retval);
-}
-
-/*
- * 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
- * Returns:         storagevolume path
- */
-PHP_FUNCTION(libvirt_storagevolume_get_path)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    char *retval;
-
-    GET_VOLUME_FROM_ARGS("r", &zvolume);
-
-    retval = virStorageVolGetPath(volume->volume);
-    DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval);
-    if (retval == NULL)
-        RETURN_FALSE;
-
-    VIRT_RETVAL_STRING(retval);
-    free(retval);
-}
-
-/*
- * Function name:   libvirt_storagevolume_get_info
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get the storage volume information
- * Arguments:       @res [resource]: libvirt storagevolume resource
- * Returns:         storage volume information array of type, allocation and capacity
- */
-PHP_FUNCTION(libvirt_storagevolume_get_info)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    virStorageVolInfo volumeInfo;
-    int retval;
-
-    GET_VOLUME_FROM_ARGS("r", &zvolume);
-
-    retval = virStorageVolGetInfo(volume->volume, &volumeInfo);
-    DPRINTF("%s: virStorageVolGetInfo(%p, <info>) returned %d\n", PHPFUNC, volume->volume, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-
-    array_init(return_value);
-    LONGLONG_INIT;
-    add_assoc_long(return_value, "type", (long)volumeInfo.type);
-    LONGLONG_ASSOC(return_value, "capacity", volumeInfo.capacity);
-    LONGLONG_ASSOC(return_value, "allocation", volumeInfo.allocation);
-}
-
-/*
- * Function name:   libvirt_storagevolume_get_xml_desc
- * Since version:   0.4.1(-1), changed 0.4.2
- * Description:     Function is used to get the storage volume XML description
- * Arguments:       @res [resource]: libvirt storagevolume resource
- *                  @xpath [string]: optional xPath expression string to get just this entry, can be NULL
- *                  @flags [int]: optional flags
- * Returns:         storagevolume XML description or result of xPath expression
- */
-PHP_FUNCTION(libvirt_storagevolume_get_xml_desc)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    char *tmp = NULL;
-    char *xml;
-    char *xpath = NULL;
-    strsize_t xpath_len;
-    zend_long flags = 0;
-    int retval = -1;
-
-    GET_VOLUME_FROM_ARGS("rs|l", &zvolume, &xpath, &xpath_len, &flags);
-    if (xpath_len < 1)
-        xpath = NULL;
-
-    DPRINTF("%s: volume = %p, xpath = %s, flags = %ld\n", PHPFUNC, volume->volume, xpath, flags);
-
-    xml = virStorageVolGetXMLDesc(volume->volume, flags);
-    if (xml == NULL) {
-        set_error_if_unset("Cannot get the XML description" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
-    if ((tmp == NULL) || (retval < 0)) {
-        VIRT_RETVAL_STRING(xml);
-    } else {
-        VIRT_RETVAL_STRING(tmp);
-    }
-
-    free(xml);
-    free(tmp);
-}
-
-/*
- * Function name:   libvirt_storagevolume_create_xml
- * Since version:   0.4.1(-1)
- * Description:     Function is used to create the new storage pool and return the handle to new storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- *                  @xml [string]: XML string to create the storage volume in the storage pool
- *                  @flags [int]: virStorageVolCreateXML flags
- * Returns:         libvirt storagevolume resource
- */
-PHP_FUNCTION(libvirt_storagevolume_create_xml)
-{
-    php_libvirt_volume *res_volume = NULL;
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    virStorageVolPtr volume = NULL;
-    char *xml;
-    zend_long flags = 0;
-    strsize_t xml_len;
-
-    GET_STORAGEPOOL_FROM_ARGS("rs|l", &zpool, &xml, &xml_len, &flags);
-
-    volume = virStorageVolCreateXML(pool->pool, xml, flags);
-    DPRINTF("%s: virStorageVolCreateXML(%p, <xml>, 0) returned %p\n", PHPFUNC, pool->pool, volume);
-    if (volume == NULL)
-        RETURN_FALSE;
-
-    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
-    res_volume->volume = volume;
-    res_volume->conn   = pool->conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
-    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
-}
-
-/*
- * 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;
-    strsize_t xml_len;
-
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &xml, &xml_len, &zvolume) == FAILURE) {
-        set_error("Invalid pool resource, XML or volume resouce" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);
-    if ((pool == NULL) || (pool->pool == NULL))
-        RETURN_FALSE;
-    VIRT_FETCH_RESOURCE(pl_volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
-    if ((pl_volume == NULL) || (pl_volume->volume == NULL))
-        RETURN_FALSE;
-    resource_change_counter(INT_RESOURCE_VOLUME, NULL, pl_volume->volume, 1 TSRMLS_CC);
-
-    volume = virStorageVolCreateXMLFrom(pool->pool, xml, pl_volume->volume, 0);
-    DPRINTF("%s: virStorageVolCreateXMLFrom(%p, <xml>, %p, 0) returned %p\n", PHPFUNC, pool->pool, pl_volume->volume, volume);
-    if (volume == NULL)
-        RETURN_FALSE;
-
-    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
-    res_volume->volume = volume;
-    res_volume->conn   = pool->conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
-    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
-}
-
-/*
- * Function name:   libvirt_storagevolume_delete
- * Since version:   0.4.2
- * Description:     Function is used to delete to volume identified by it's resource
- * Arguments:       @res [resource]: libvirt storagevolume resource
- *                  @flags [int]: optional flags for the storage volume deletion for virStorageVolDelete()
- * Returns:         TRUE for success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagevolume_delete)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    zend_long flags = 0;
-    int retval = 0;
-
-    GET_VOLUME_FROM_ARGS("r|l", &zvolume, &flags);
-
-    retval = virStorageVolDelete(volume->volume, flags);
-    DPRINTF("%s: virStorageVolDelete(%p, %d) returned %d\n", PHPFUNC, volume->volume, (int) flags, retval);
-    if (retval != 0) {
-        set_error_if_unset("Cannot delete storage volume" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagevolume_resize
- * Since version:   0.5.0
- * Description:     Function is used to resize volume identified by it's resource
- * Arguments:       @res [resource]: libvirt storagevolume resource
- *                  @capacity [int]: capacity for the storage volume
- *                  @flags [int]: optional flags for the storage volume resize for virStorageVolResize()
- * Returns:         int
- */
-PHP_FUNCTION(libvirt_storagevolume_resize)
-{
-    php_libvirt_volume *volume = NULL;
-    zval *zvolume;
-    zend_long flags = 0;
-    zend_long capacity = 0;
-    int retval = -1;
-
-    GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags);
-
-    retval = virStorageVolResize(volume->volume, capacity, flags);
-    DPRINTF("%s: virStorageVolResize(%p, %d, %d) returned %d\n", PHPFUNC, volume->volume, (int) capacity, (int) flags, retval);
-    if (retval != 0) {
-        set_error_if_unset("Cannot resize storage volume" TSRMLS_CC);
-        RETURN_LONG(retval);
-    }
-
-    RETURN_LONG(retval);
-}
-
-/*
- * Function name:   libvirt_storagevolume_download
- * Since version:   0.5.0
- * Description:     Function is used to download volume identified by it's resource
- * Arguments:       @res [resource]: libvirt storagevolume resource
- *                  @stream [resource]: stream to use as output
- *                  @offset [int]: position to start reading from
- *                  @length [int] : limit on amount of data to download
- *                  @flags [int]: optional flags for the storage volume download for virStorageVolDownload()
- * Returns:         int
- */
-PHP_FUNCTION(libvirt_storagevolume_download)
-{
-    php_libvirt_volume *volume = NULL;
-    php_libvirt_stream *stream = NULL;
-    zval *zvolume;
-    zval *zstream;
-    zend_long flags = 0;
-    zend_long offset = 0;
-    zend_long length = 0;
-    int retval = -1;
-
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE)
-        RETURN_LONG(retval);
-    VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
-    if ((volume == NULL) || (volume->volume == NULL))
-        RETURN_LONG(retval);
-    VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
-    if ((stream == NULL) || (stream->stream == NULL))
-        RETURN_LONG(retval);
-
-    retval = virStorageVolDownload(volume->volume, stream->stream, offset, length, flags);
-    DPRINTF("%s: virStorageVolDownload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
-
-    if (retval == -1) {
-        set_error("Cannot download from stream" TSRMLS_CC);
-        RETURN_LONG(retval);
-    }
-
-    RETURN_LONG(retval);
-}
-
-/*
- * Function name:   libvirt_storagevolume_upload
- * Since version:   0.5.0
- * Description:     Function is used to upload volume identified by it's resource
- * Arguments:       @res [resource]: libvirt storagevolume resource
- *                  @stream [resource]: stream to use as input
- *                  @offset [int]: position to start writing to
- *                  @length [int] : limit on amount of data to upload
- *                  @flags [int]: optional flags for the storage volume upload for virStorageVolUpload()
- * Returns:         int
- */
-PHP_FUNCTION(libvirt_storagevolume_upload)
-{
-    php_libvirt_volume *volume = NULL;
-    php_libvirt_stream *stream = NULL;
-    zval *zvolume;
-    zval *zstream;
-    zend_long flags = 0;
-    zend_long offset = 0;
-    zend_long length = 0;
-    int retval = -1;
-
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE)
-        RETURN_LONG(retval);
-    VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
-    if ((volume == NULL) || (volume->volume == NULL))
-        RETURN_LONG(retval);
-    VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
-    if ((stream == NULL) || (stream->stream == NULL))
-        RETURN_LONG(retval);
-
-    retval = virStorageVolUpload(volume->volume, stream->stream, offset, length, flags);
-    DPRINTF("%s: virStorageVolUpload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
-
-    if (retval == -1) {
-        set_error_if_unset("Cannot upload storage volume" TSRMLS_CC);
-        RETURN_LONG(retval);
-    }
-
-    RETURN_LONG(retval);
-}
-
-/*
- * Function name:   libvirt_storagepool_get_uuid_string
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get storage pool by UUID string
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         storagepool UUID string
- */
-PHP_FUNCTION(libvirt_storagepool_get_uuid_string)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    char *uuid;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    uuid = (char *)emalloc(VIR_UUID_STRING_BUFLEN);
-    retval = virStoragePoolGetUUIDString(pool->pool, uuid);
-    DPRINTF("%s: virStoragePoolGetUUIDString(%p, %p) returned %d (%s)\n", PHPFUNC, pool->pool, uuid, retval, uuid);
-    if (retval != 0)
-        RETURN_FALSE;
-
-    VIRT_RETVAL_STRING(uuid);
-    efree(uuid);
-}
-
-/*
- * Function name:   libvirt_storagepool_get_name
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get storage pool name from the storage pool resource
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         storagepool name string
- */
-PHP_FUNCTION(libvirt_storagepool_get_name)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    const char *name = NULL;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    name = virStoragePoolGetName(pool->pool);
-    DPRINTF("%s: virStoragePoolGetName(%p) returned %s\n", PHPFUNC, pool->pool, name);
-    if (name == NULL)
-        RETURN_FALSE;
-
-    VIRT_RETURN_STRING(name);
-}
-
-/*
- * Function name:   libvirt_storagepool_lookup_by_uuid_string
- * Since version:   0.4.1(-1)
- * Description:     Function is used to lookup for storage pool identified by UUID string
- * Arguments:       @res [resource]: libvirt connection resource
- *                  @uuid [string]: UUID string to look for storagepool
- * Returns:         libvirt storagepool resource
- */
-PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    char *uuid = NULL;
-    strsize_t uuid_len;
-    virStoragePoolPtr storage = NULL;
-    php_libvirt_storagepool *res_pool;
-
-    GET_CONNECTION_FROM_ARGS("rs", &zconn, &uuid, &uuid_len);
-
-    if ((uuid == NULL) || (uuid_len < 1))
-        RETURN_FALSE;
-
-    storage = virStoragePoolLookupByUUIDString(conn->conn, uuid);
-    DPRINTF("%s: virStoragePoolLookupByUUIDString(%p, %s) returned %p\n", PHPFUNC, conn->conn, uuid, storage);
-    if (storage == NULL)
-        RETURN_FALSE;
-
-    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
-    res_pool->pool = storage;
-    res_pool->conn = conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
-    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
-}
-
-/*
- * Function name:   libvirt_storagepool_get_xml_desc
- * Since version:   0.4.1(-1), changed 0.4.2
- * Description:     Function is used to get the XML description for the storage pool identified by res
- * Arguments:       @res [resource]: libvirt storagepool resource
- *                  @xpath [string]: optional xPath expression string to get just this entry, can be NULL
- * Returns:         storagepool XML description string or result of xPath expression
- */
-PHP_FUNCTION(libvirt_storagepool_get_xml_desc)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    char *xml;
-    char *xpath = NULL;
-    char *tmp = NULL;
-    zend_long flags = 0;
-    strsize_t xpath_len;
-    int retval = -1;
-
-    GET_STORAGEPOOL_FROM_ARGS("r|s", &zpool, &xpath, &xpath_len, &flags);
-    if (xpath_len < 1)
-        xpath = NULL;
-
-    DPRINTF("%s: pool = %p, flags = %ld, xpath = %s\n", PHPFUNC, pool->pool, flags, xpath);
-
-    xml = virStoragePoolGetXMLDesc(pool->pool, flags);
-    if (xml == NULL) {
-        set_error_if_unset("Cannot get the XML description" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
-    if ((tmp == NULL) || (retval < 0)) {
-        VIRT_RETVAL_STRING(xml);
-    } else {
-        VIRT_RETVAL_STRING(tmp);
-    }
-
-    free(xml);
-    free(tmp);
-}
-
-/*
- * Function name:   libvirt_storagepool_define_xml
- * Since version:   0.4.1(-1)
- * Description:     Function is used to define the storage pool from XML string and return it's resource
- * Arguments:       @res [resource]: libvirt connection resource
- *                  @xml [string]: XML string definition of storagepool
- *                  @flags [int]: flags to define XML
- * Returns:         libvirt storagepool resource
- */
-PHP_FUNCTION(libvirt_storagepool_define_xml)
-{
-    php_libvirt_storagepool *res_pool = NULL;
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    virStoragePoolPtr pool = NULL;
-    char *xml;
-    strsize_t xml_len;
-    zend_long flags = 0;
-
-
-    GET_CONNECTION_FROM_ARGS("rs|l", &zconn, &xml, &xml_len, &flags);
-
-    pool = virStoragePoolDefineXML(conn->conn, xml, (unsigned int)flags);
-    DPRINTF("%s: virStoragePoolDefineXML(%p, <xml>) returned %p\n", PHPFUNC, conn->conn, pool);
-    if (pool == NULL)
-        RETURN_FALSE;
-
-    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
-    res_pool->pool = pool;
-    res_pool->conn = conn;
-
-    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
-    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
-
-    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
-}
-
-/*
- * Function name:   libvirt_storagepool_undefine
- * Since version:   0.4.1(-1)
- * Description:     Function is used to undefine the storage pool identified by it's resource
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_undefine)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int retval = 0;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolUndefine(pool->pool);
-    DPRINTF("%s: virStoragePoolUndefine(%p) returned %d\n", PHPFUNC, pool->pool, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagepool_create
- * Since version:   0.4.1(-1)
- * Description:     Function is used to create/start the storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_create)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolCreate(pool->pool, 0);
-    DPRINTF("%s: virStoragePoolCreate(%p, 0) returned %d\n", PHPFUNC, pool->pool, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagepool_destroy
- * Since version:   0.4.1(-1)
- * Description:     Function is used to destory the storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_destroy)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolDestroy(pool->pool);
-    DPRINTF("%s: virStoragePoolDestroy(%p) returned %d\n", PHPFUNC, pool->pool, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagepool_is_active
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get information whether storage pool is active or not
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         result of virStoragePoolIsActive
- */
-PHP_FUNCTION(libvirt_storagepool_is_active)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    RETURN_LONG(virStoragePoolIsActive(pool->pool));
-}
-
-/*
- * Function name:   libvirt_storagepool_get_volume_count
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get storage volume count in the storage pool
- * Arguments:           @res [resource]: libvirt storagepool resource
- * Returns:             number of volumes in the pool
- */
-PHP_FUNCTION(libvirt_storagepool_get_volume_count)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    RETURN_LONG(virStoragePoolNumOfVolumes(pool->pool));
-}
-
-/*
- * Function name:   libvirt_storagepool_refresh
- * Since version:   0.4.1(-1)
- * Description:     Function is used to refresh the storage pool information
- * Arguments:       @res [resource]: libvirt storagepool resource
- *                  @flags [int]: refresh flags
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_refresh)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    zend_long flags = 0;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r|l", &zpool, &flags);
-
-    retval = virStoragePoolRefresh(pool->pool, flags);
-    DPRINTF("%s: virStoragePoolRefresh(%p, %ld) returned %d\n", PHPFUNC, pool->pool, flags, retval);
-    if (retval < 0)
-        RETURN_FALSE;
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagepool_set_autostart
- * Since version:   0.4.1(-1)
- * Description:     Function is used to set autostart of the storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- *                  @flags [int]: flags to set autostart
- * Returns:         result on setting storagepool autostart value
- */
-PHP_FUNCTION(libvirt_storagepool_set_autostart)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    zend_bool flags = 0;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("rb", &zpool, &flags);
-
-    retval = virStoragePoolSetAutostart(pool->pool, flags);
-    DPRINTF("%s: virStoragePoolSetAutostart(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
-    if (retval != 0)
-        RETURN_FALSE;
-    RETURN_TRUE;
-}
-
-/*
- * Function name:   libvirt_storagepool_get_autostart
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get autostart of the storage pool
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE for autostart enabled, FALSE for autostart disabled, FALSE with last_error set for error
- */
-PHP_FUNCTION(libvirt_storagepool_get_autostart)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int autostart;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    if (virStoragePoolGetAutostart(pool->pool, &autostart) == 0 &&
-        autostart != 0)
-        RETURN_TRUE;
-
-    RETURN_FALSE;
-}
-
-/*
- * Function name:   libvirt_storagepool_build
- * Since version:   0.4.2
- * Description:     Function is used to Build the underlying storage pool, e.g. create the destination directory for NFS
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_build)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int flags = 0;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolBuild(pool->pool, flags);
-    DPRINTF("%s: virStoragePoolBuild(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
-    if (retval == 0)
-        RETURN_TRUE;
-
-    RETURN_FALSE;
-}
-
-/*
- * Function name:   libvirt_storagepool_delete
- * Since version:   0.4.6
- * Description:     Function is used to Delete the underlying storage pool, e.g. remove the destination directory for NFS
- * Arguments:       @res [resource]: libvirt storagepool resource
- * Returns:         TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_storagepool_delete)
-{
-    php_libvirt_storagepool *pool = NULL;
-    zval *zpool;
-    int flags = 0;
-    int retval;
-
-    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
-
-    retval = virStoragePoolDelete(pool->pool, flags);
-    DPRINTF("%s: virStoragePoolDelete(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
-    if (retval == 0)
-        RETURN_TRUE;
-
-    RETURN_FALSE;
-}
-
 /* Listing functions */
 /*
- * Function name:   libvirt_list_storagepools
- * Since version:   0.4.1(-1)
- * Description:     Function is used to list storage pools on the connection
- * Arguments:       @res [resource]: libvirt connection resource
- * Returns:         libvirt storagepool names array for the connection
- */
-PHP_FUNCTION(libvirt_list_storagepools)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int count = -1;
-    int expectedcount = -1;
-    char **names;
-    int i;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    if ((expectedcount = virConnectNumOfStoragePools(conn->conn)) < 0)
-        RETURN_FALSE;
-
-    names = (char **)emalloc(expectedcount*sizeof(char *));
-    count = virConnectListStoragePools(conn->conn, names, expectedcount);
-
-    if ((count != expectedcount) || (count < 0)) {
-        efree(names);
-        RETURN_FALSE;
-    }
-
-    array_init(return_value);
-    for (i = 0; i < count; i++) {
-        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
-        free(names[i]);
-    }
-    efree(names);
-
-
-    if ((expectedcount = virConnectNumOfDefinedStoragePools(conn->conn)) < 0)
-        RETURN_FALSE;
-    names = (char **)emalloc(expectedcount * sizeof(char *));
-    count = virConnectListDefinedStoragePools(conn->conn, names, expectedcount);
-    if ((count != expectedcount) || (count < 0)) {
-        efree(names);
-        RETURN_FALSE;
-    }
-
-    for (i = 0; i < count; i++) {
-        VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
-        free(names[i]);
-    }
-    efree(names);
-}
-
-/*
- * Function name:   libvirt_list_active_storagepools
- * Since version:   0.4.1(-1)
- * Description:     Function is used to list active storage pools on the connection
- * Arguments:       @res [resource]: libvirt connection resource
- * Returns:         libvirt storagepool names array for the connection
- */
-PHP_FUNCTION(libvirt_list_active_storagepools)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int count = -1;
-    int expectedcount = -1;
-    char **names;
-    int i;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    if ((expectedcount = virConnectNumOfStoragePools(conn->conn)) < 0)
-        RETURN_FALSE;
-
-    names = (char **)emalloc(expectedcount*sizeof(char *));
-    count = virConnectListStoragePools(conn->conn, names, expectedcount);
-
-    if ((count != expectedcount) || (count < 0)) {
-        efree(names);
-        RETURN_FALSE;
-    }
-    array_init(return_value);
-    for (i = 0; i < count; i++) {
-        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
-        free(names[i]);
-    }
-    efree(names);
-}
-
-/*
- * Function name:   libvirt_list_inactive_storagepools
- * Since version:   0.4.1(-1)
- * Description:     Function is used to list inactive storage pools on the connection
- * Arguments:       @res [resource]: libvirt connection resource
- * Returns:         libvirt storagepool names array for the connection
- */
-PHP_FUNCTION(libvirt_list_inactive_storagepools)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int count = -1;
-    int expectedcount = -1;
-    char **names;
-    int i;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    if ((expectedcount = virConnectNumOfDefinedStoragePools(conn->conn)) < 0)
-        RETURN_FALSE;
-
-    names = (char **)emalloc(expectedcount * sizeof(char *));
-    count = virConnectListDefinedStoragePools(conn->conn, names, expectedcount);
-    if ((count != expectedcount) || (count < 0)) {
-        efree(names);
-        RETURN_FALSE;
-    }
-
-    array_init(return_value);
-    for (i = 0; i < count; i++) {
-        VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
-        free(names[i]);
-    }
-    efree(names);
-}
-
-/*
  * Function name:   libvirt_list_nodedevs
  * Since version:   0.4.1(-1)
  * Description:     Function is used to list node devices on the connection
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index 8b6e9e4..6e1fd0c 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -109,8 +109,6 @@ typedef uint64_t arch_uint;
 
 /* Internal resource identifier objects */
 #define INT_RESOURCE_NODEDEV        0x08
-#define INT_RESOURCE_STORAGEPOOL    0x10
-#define INT_RESOURCE_VOLUME         0x20
 #define INT_RESOURCE_SNAPSHOT       0x40
 #define INT_RESOURCE_NWFILTER       0x60
 
@@ -156,16 +154,6 @@ typedef struct _php_libvirt_nodedev {
     php_libvirt_connection* conn;
 } php_libvirt_nodedev;
 
-typedef struct _php_libvirt_storagepool {
-    virStoragePoolPtr pool;
-    php_libvirt_connection* conn;
-} php_libvirt_storagepool;
-
-typedef struct _php_libvirt_volume {
-    virStorageVolPtr volume;
-    php_libvirt_connection* conn;
-} php_libvirt_volume;
-
 typedef struct _php_libvirt_nwfilter {
     virNWFilterPtr nwfilter;
     php_libvirt_connection* conn;
@@ -223,8 +211,6 @@ const char *get_feature_binary(const char *name);
 long get_next_free_numeric_value(virDomainPtr domain, char *xpath);
 int get_subnet_bits(char *ip);
 
-#define PHP_LIBVIRT_STORAGEPOOL_RES_NAME "Libvirt storagepool"
-#define PHP_LIBVIRT_VOLUME_RES_NAME "Libvirt volume"
 #define PHP_LIBVIRT_NODEDEV_RES_NAME "Libvirt node device"
 #define PHP_LIBVIRT_SNAPSHOT_RES_NAME "Libvirt domain snapshot"
 #define PHP_LIBVIRT_NWFILTER_RES_NAME "Libvirt nwfilter"
@@ -244,38 +230,6 @@ PHP_FUNCTION(libvirt_domain_snapshot_lookup_by_name);
 PHP_FUNCTION(libvirt_domain_snapshot_get_xml);
 PHP_FUNCTION(libvirt_domain_snapshot_revert);
 PHP_FUNCTION(libvirt_domain_snapshot_delete);
-/* Storage pool and storage volume 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);
-PHP_FUNCTION(libvirt_storagevolume_get_xml_desc);
-PHP_FUNCTION(libvirt_storagevolume_create_xml);
-PHP_FUNCTION(libvirt_storagevolume_create_xml_from);
-PHP_FUNCTION(libvirt_storagevolume_delete);
-PHP_FUNCTION(libvirt_storagevolume_download);
-PHP_FUNCTION(libvirt_storagevolume_upload);
-PHP_FUNCTION(libvirt_storagevolume_resize);
-PHP_FUNCTION(libvirt_storagepool_get_uuid_string);
-PHP_FUNCTION(libvirt_storagepool_get_name);
-PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string);
-PHP_FUNCTION(libvirt_storagepool_get_xml_desc);
-PHP_FUNCTION(libvirt_storagepool_define_xml);
-PHP_FUNCTION(libvirt_storagepool_undefine);
-PHP_FUNCTION(libvirt_storagepool_create);
-PHP_FUNCTION(libvirt_storagepool_destroy);
-PHP_FUNCTION(libvirt_storagepool_is_active);
-PHP_FUNCTION(libvirt_storagepool_get_volume_count);
-PHP_FUNCTION(libvirt_storagepool_refresh);
-PHP_FUNCTION(libvirt_storagepool_set_autostart);
-PHP_FUNCTION(libvirt_storagepool_get_autostart);
-PHP_FUNCTION(libvirt_storagepool_build);
-PHP_FUNCTION(libvirt_storagepool_delete);
 /* Nodedev functions */
 PHP_FUNCTION(libvirt_nodedev_get);
 PHP_FUNCTION(libvirt_nodedev_capabilities);
@@ -296,9 +250,6 @@ PHP_FUNCTION(libvirt_list_nodedevs);
 PHP_FUNCTION(libvirt_list_all_nwfilters);
 PHP_FUNCTION(libvirt_list_nwfilters);
 PHP_FUNCTION(libvirt_list_domain_snapshots);
-PHP_FUNCTION(libvirt_list_storagepools);
-PHP_FUNCTION(libvirt_list_active_storagepools);
-PHP_FUNCTION(libvirt_list_inactive_storagepools);
 /* Common functions */
 PHP_FUNCTION(libvirt_version);
 PHP_FUNCTION(libvirt_check_version);
diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c
new file mode 100644
index 0000000..191f60a
--- /dev/null
+++ b/src/libvirt-storage.c
@@ -0,0 +1,1130 @@
+/*
+ * libvirt-storage.c: The PHP bindings to libvirt storage API
+ *
+ * See COPYING for the license of this software
+ */
+
+#include <libvirt/libvirt.h>
+
+#include "libvirt-php.h"
+#include "libvirt-stream.h"
+#include "libvirt-storage.h"
+
+DEBUG_INIT("storage");
+
+void
+php_libvirt_storagepool_dtor(virt_resource *rsrc TSRMLS_DC)
+{
+    php_libvirt_storagepool *pool = (php_libvirt_storagepool *)rsrc->ptr;
+    int rv = 0;
+
+    if (pool != NULL) {
+        if (pool->pool != NULL) {
+            if (!check_resource_allocation(NULL, INT_RESOURCE_STORAGEPOOL, pool->pool TSRMLS_CC)) {
+                pool->pool = NULL;
+                efree(pool);
+                return;
+            }
+            rv = virStoragePoolFree(pool->pool);
+            if (rv != 0) {
+                DPRINTF("%s: virStoragePoolFree(%p) returned %d (%s)\n", __FUNCTION__, pool->pool, rv, LIBVIRT_G(last_error));
+                php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStoragePoolFree failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+            } else {
+                DPRINTF("%s: virStoragePoolFree(%p) completed successfully\n", __FUNCTION__, pool->pool);
+                resource_change_counter(INT_RESOURCE_STORAGEPOOL, NULL, pool->pool, 0 TSRMLS_CC);
+            }
+            pool->pool = NULL;
+        }
+        efree(pool);
+    }
+}
+
+void
+php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC)
+{
+    php_libvirt_volume *volume = (php_libvirt_volume *)rsrc->ptr;
+    int rv = 0;
+
+    if (volume != NULL) {
+        if (volume->volume != NULL) {
+            if (!check_resource_allocation(NULL, INT_RESOURCE_VOLUME, volume->volume TSRMLS_CC)) {
+                volume->volume = NULL;
+                efree(volume);
+                return;
+            }
+            rv = virStorageVolFree(volume->volume);
+            if (rv != 0) {
+                DPRINTF("%s: virStorageVolFree(%p) returned %d (%s)\n", __FUNCTION__, volume->volume, rv, LIBVIRT_G(last_error));
+                php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+            } else {
+                DPRINTF("%s: virStorageVolFree(%p) completed successfully\n", __FUNCTION__, volume->volume);
+                resource_change_counter(INT_RESOURCE_VOLUME, NULL, volume->volume, 0 TSRMLS_CC);
+            }
+            volume->volume = NULL;
+        }
+        efree(volume);
+    }
+}
+
+/*
+ * Function name:   libvirt_storagepool_lookup_by_name
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to lookup for storage pool by it's name
+ * Arguments:       @res [resource]: libvirt connection resource
+ *                  @name [string]: storage pool name
+ * Returns:         libvirt storagepool resource
+ */
+PHP_FUNCTION(libvirt_storagepool_lookup_by_name)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    strsize_t name_len;
+    char *name = NULL;
+    virStoragePoolPtr pool = NULL;
+    php_libvirt_storagepool *res_pool;
+
+    GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
+
+    if ((name == NULL) || (name_len < 1))
+        RETURN_FALSE;
+    pool = virStoragePoolLookupByName(conn->conn, name);
+    DPRINTF("%s: virStoragePoolLookupByName(%p, %s) returned %p\n", PHPFUNC, conn->conn, name, pool);
+    if (pool == NULL)
+        RETURN_FALSE;
+
+    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
+    res_pool->pool = pool;
+    res_pool->conn = conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
+    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
+}
+
+/*
+ * 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);
+    DPRINTF("%s: virStoragePoolLookupByVolume(%p) returned %p\n", PHPFUNC, volume->volume, pool);
+    if (pool == NULL)
+        RETURN_FALSE;
+
+    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
+    res_pool->pool = pool;
+    res_pool->conn = volume->conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
+    resource_change_counter(INT_RESOURCE_STORAGEPOOL, res_pool->conn->conn, res_pool->pool, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
+}
+
+/*
+ * Function name:   libvirt_storagepool_list_volumes
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to list volumes in the specified storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         list of storage volume names in the storage pool in an array using default keys (indexes)
+ */
+PHP_FUNCTION(libvirt_storagepool_list_volumes)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    char **names = NULL;
+    int expectedcount = -1;
+    int i;
+    int count = -1;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    if ((expectedcount = virStoragePoolNumOfVolumes(pool->pool)) < 0)
+        RETURN_FALSE;
+
+    DPRINTF("%s: virStoragePoolNumOfVolumes(%p) returned %d\n", PHPFUNC, pool->pool, expectedcount);
+    names = (char **)emalloc(expectedcount*sizeof(char *));
+
+    count = virStoragePoolListVolumes(pool->pool, names, expectedcount);
+    DPRINTF("%s: virStoragePoolListVolumes(%p, %p, %d) returned %d\n", PHPFUNC, pool->pool, names, expectedcount, count);
+    array_init(return_value);
+
+    if ((count != expectedcount) || (count < 0))
+        RETURN_FALSE;
+    for (i = 0; i < count; i++) {
+        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
+        free(names[i]);
+    }
+
+    efree(names);
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_info
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get information about the storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         storage pool information array of state, capacity, allocation and available space
+ */
+PHP_FUNCTION(libvirt_storagepool_get_info)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    virStoragePoolInfo poolInfo;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolGetInfo(pool->pool, &poolInfo);
+    DPRINTF("%s: virStoragePoolGetInfo(%p, <info>) returned %d\n", PHPFUNC, pool->pool, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+
+    array_init(return_value);
+
+    // @todo: fix the long long returns
+    LONGLONG_INIT;
+    add_assoc_long(return_value, "state", (long)poolInfo.state);
+    LONGLONG_ASSOC(return_value, "capacity", poolInfo.capacity);
+    LONGLONG_ASSOC(return_value, "allocation", poolInfo.allocation);
+    LONGLONG_ASSOC(return_value, "available", poolInfo.available);
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_uuid_string
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get storage pool by UUID string
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         storagepool UUID string
+ */
+PHP_FUNCTION(libvirt_storagepool_get_uuid_string)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    char *uuid;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    uuid = (char *)emalloc(VIR_UUID_STRING_BUFLEN);
+    retval = virStoragePoolGetUUIDString(pool->pool, uuid);
+    DPRINTF("%s: virStoragePoolGetUUIDString(%p, %p) returned %d (%s)\n", PHPFUNC, pool->pool, uuid, retval, uuid);
+    if (retval != 0)
+        RETURN_FALSE;
+
+    VIRT_RETVAL_STRING(uuid);
+    efree(uuid);
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_name
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get storage pool name from the storage pool resource
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         storagepool name string
+ */
+PHP_FUNCTION(libvirt_storagepool_get_name)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    const char *name = NULL;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    name = virStoragePoolGetName(pool->pool);
+    DPRINTF("%s: virStoragePoolGetName(%p) returned %s\n", PHPFUNC, pool->pool, name);
+    if (name == NULL)
+        RETURN_FALSE;
+
+    VIRT_RETURN_STRING(name);
+}
+
+/*
+ * Function name:   libvirt_storagepool_lookup_by_uuid_string
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to lookup for storage pool identified by UUID string
+ * Arguments:       @res [resource]: libvirt connection resource
+ *                  @uuid [string]: UUID string to look for storagepool
+ * Returns:         libvirt storagepool resource
+ */
+PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    char *uuid = NULL;
+    strsize_t uuid_len;
+    virStoragePoolPtr storage = NULL;
+    php_libvirt_storagepool *res_pool;
+
+    GET_CONNECTION_FROM_ARGS("rs", &zconn, &uuid, &uuid_len);
+
+    if ((uuid == NULL) || (uuid_len < 1))
+        RETURN_FALSE;
+
+    storage = virStoragePoolLookupByUUIDString(conn->conn, uuid);
+    DPRINTF("%s: virStoragePoolLookupByUUIDString(%p, %s) returned %p\n", PHPFUNC, conn->conn, uuid, storage);
+    if (storage == NULL)
+        RETURN_FALSE;
+
+    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
+    res_pool->pool = storage;
+    res_pool->conn = conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
+    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_xml_desc
+ * Since version:   0.4.1(-1), changed 0.4.2
+ * Description:     Function is used to get the XML description for the storage pool identified by res
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ *                  @xpath [string]: optional xPath expression string to get just this entry, can be NULL
+ * Returns:         storagepool XML description string or result of xPath expression
+ */
+PHP_FUNCTION(libvirt_storagepool_get_xml_desc)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    char *xml;
+    char *xpath = NULL;
+    char *tmp = NULL;
+    zend_long flags = 0;
+    strsize_t xpath_len;
+    int retval = -1;
+
+    GET_STORAGEPOOL_FROM_ARGS("r|s", &zpool, &xpath, &xpath_len, &flags);
+    if (xpath_len < 1)
+        xpath = NULL;
+
+    DPRINTF("%s: pool = %p, flags = %ld, xpath = %s\n", PHPFUNC, pool->pool, flags, xpath);
+
+    xml = virStoragePoolGetXMLDesc(pool->pool, flags);
+    if (xml == NULL) {
+        set_error_if_unset("Cannot get the XML description" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
+    if ((tmp == NULL) || (retval < 0)) {
+        VIRT_RETVAL_STRING(xml);
+    } else {
+        VIRT_RETVAL_STRING(tmp);
+    }
+
+    free(xml);
+    free(tmp);
+}
+
+/*
+ * Function name:   libvirt_storagepool_define_xml
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to define the storage pool from XML string and return it's resource
+ * Arguments:       @res [resource]: libvirt connection resource
+ *                  @xml [string]: XML string definition of storagepool
+ *                  @flags [int]: flags to define XML
+ * Returns:         libvirt storagepool resource
+ */
+PHP_FUNCTION(libvirt_storagepool_define_xml)
+{
+    php_libvirt_storagepool *res_pool = NULL;
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    virStoragePoolPtr pool = NULL;
+    char *xml;
+    strsize_t xml_len;
+    zend_long flags = 0;
+
+
+    GET_CONNECTION_FROM_ARGS("rs|l", &zconn, &xml, &xml_len, &flags);
+
+    pool = virStoragePoolDefineXML(conn->conn, xml, (unsigned int)flags);
+    DPRINTF("%s: virStoragePoolDefineXML(%p, <xml>) returned %p\n", PHPFUNC, conn->conn, pool);
+    if (pool == NULL)
+        RETURN_FALSE;
+
+    res_pool = (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_storagepool));
+    res_pool->pool = pool;
+    res_pool->conn = conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool);
+    resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_pool, le_libvirt_storagepool);
+}
+
+/*
+ * Function name:   libvirt_storagepool_undefine
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to undefine the storage pool identified by it's resource
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_undefine)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int retval = 0;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolUndefine(pool->pool);
+    DPRINTF("%s: virStoragePoolUndefine(%p) returned %d\n", PHPFUNC, pool->pool, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_create
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to create/start the storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_create)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolCreate(pool->pool, 0);
+    DPRINTF("%s: virStoragePoolCreate(%p, 0) returned %d\n", PHPFUNC, pool->pool, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_destroy
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to destory the storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_destroy)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolDestroy(pool->pool);
+    DPRINTF("%s: virStoragePoolDestroy(%p) returned %d\n", PHPFUNC, pool->pool, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_is_active
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get information whether storage pool is active or not
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         result of virStoragePoolIsActive
+ */
+PHP_FUNCTION(libvirt_storagepool_is_active)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    RETURN_LONG(virStoragePoolIsActive(pool->pool));
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_volume_count
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get storage volume count in the storage pool
+ * Arguments:           @res [resource]: libvirt storagepool resource
+ * Returns:             number of volumes in the pool
+ */
+PHP_FUNCTION(libvirt_storagepool_get_volume_count)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    RETURN_LONG(virStoragePoolNumOfVolumes(pool->pool));
+}
+
+/*
+ * Function name:   libvirt_storagepool_refresh
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to refresh the storage pool information
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ *                  @flags [int]: refresh flags
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_refresh)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    zend_long flags = 0;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r|l", &zpool, &flags);
+
+    retval = virStoragePoolRefresh(pool->pool, flags);
+    DPRINTF("%s: virStoragePoolRefresh(%p, %ld) returned %d\n", PHPFUNC, pool->pool, flags, retval);
+    if (retval < 0)
+        RETURN_FALSE;
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_set_autostart
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to set autostart of the storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ *                  @flags [int]: flags to set autostart
+ * Returns:         result on setting storagepool autostart value
+ */
+PHP_FUNCTION(libvirt_storagepool_set_autostart)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    zend_bool flags = 0;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("rb", &zpool, &flags);
+
+    retval = virStoragePoolSetAutostart(pool->pool, flags);
+    DPRINTF("%s: virStoragePoolSetAutostart(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_get_autostart
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get autostart of the storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE for autostart enabled, FALSE for autostart disabled, FALSE with last_error set for error
+ */
+PHP_FUNCTION(libvirt_storagepool_get_autostart)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int autostart;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    if (virStoragePoolGetAutostart(pool->pool, &autostart) == 0 &&
+        autostart != 0)
+        RETURN_TRUE;
+
+    RETURN_FALSE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_build
+ * Since version:   0.4.2
+ * Description:     Function is used to Build the underlying storage pool, e.g. create the destination directory for NFS
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_build)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int flags = 0;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolBuild(pool->pool, flags);
+    DPRINTF("%s: virStoragePoolBuild(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
+    if (retval == 0)
+        RETURN_TRUE;
+
+    RETURN_FALSE;
+}
+
+/*
+ * Function name:   libvirt_storagepool_delete
+ * Since version:   0.4.6
+ * Description:     Function is used to Delete the underlying storage pool, e.g. remove the destination directory for NFS
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ * Returns:         TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagepool_delete)
+{
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    int flags = 0;
+    int retval;
+
+    GET_STORAGEPOOL_FROM_ARGS("r", &zpool);
+
+    retval = virStoragePoolDelete(pool->pool, flags);
+    DPRINTF("%s: virStoragePoolDelete(%p, %d) returned %d\n", PHPFUNC, pool->pool, flags, retval);
+    if (retval == 0)
+        RETURN_TRUE;
+
+    RETURN_FALSE;
+}
+
+/*
+ * Function name:   libvirt_storagevolume_lookup_by_name
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to lookup for storage volume by it's name
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ *                  @name [string]: name of the storage volume to look for
+ * Returns:         libvirt storagevolume resource
+ */
+PHP_FUNCTION(libvirt_storagevolume_lookup_by_name)
+{
+    php_libvirt_storagepool *pool = NULL;
+    php_libvirt_volume *res_volume;
+    zval *zpool;
+    strsize_t name_len;
+    char *name = NULL;
+    virStorageVolPtr volume = NULL;
+
+    GET_STORAGEPOOL_FROM_ARGS("rs", &zpool, &name, &name_len);
+    if ((name == NULL) || (name_len < 1))
+        RETURN_FALSE;
+
+    volume = virStorageVolLookupByName(pool->pool, name);
+    DPRINTF("%s: virStorageVolLookupByName(%p, %s) returned %p\n", PHPFUNC, pool->pool, name, volume);
+    if (volume == NULL)
+        RETURN_FALSE;
+
+    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
+    res_volume->volume = volume;
+    res_volume->conn   = pool->conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
+    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
+}
+
+/*
+ * 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;
+    strsize_t 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);
+    DPRINTF("%s: virStorageVolLookupByPath(%p, %s) returned %p\n", PHPFUNC, conn->conn, name, volume);
+    if (volume == NULL) {
+        set_error_if_unset("Cannot find storage volume on requested path" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
+    res_volume->volume = volume;
+    res_volume->conn   = conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
+    resource_change_counter(INT_RESOURCE_VOLUME, conn->conn, res_volume->volume, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(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
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ * Returns:         storagevolume name
+ */
+PHP_FUNCTION(libvirt_storagevolume_get_name)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    const char *retval;
+
+    GET_VOLUME_FROM_ARGS("r", &zvolume);
+
+    retval = virStorageVolGetName(volume->volume);
+    DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval);
+    if (retval == NULL)
+        RETURN_FALSE;
+
+    VIRT_RETURN_STRING(retval);
+}
+
+/*
+ * 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
+ * Returns:         storagevolume path
+ */
+PHP_FUNCTION(libvirt_storagevolume_get_path)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    char *retval;
+
+    GET_VOLUME_FROM_ARGS("r", &zvolume);
+
+    retval = virStorageVolGetPath(volume->volume);
+    DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval);
+    if (retval == NULL)
+        RETURN_FALSE;
+
+    VIRT_RETVAL_STRING(retval);
+    free(retval);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_get_info
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get the storage volume information
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ * Returns:         storage volume information array of type, allocation and capacity
+ */
+PHP_FUNCTION(libvirt_storagevolume_get_info)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    virStorageVolInfo volumeInfo;
+    int retval;
+
+    GET_VOLUME_FROM_ARGS("r", &zvolume);
+
+    retval = virStorageVolGetInfo(volume->volume, &volumeInfo);
+    DPRINTF("%s: virStorageVolGetInfo(%p, <info>) returned %d\n", PHPFUNC, volume->volume, retval);
+    if (retval != 0)
+        RETURN_FALSE;
+
+    array_init(return_value);
+    LONGLONG_INIT;
+    add_assoc_long(return_value, "type", (long)volumeInfo.type);
+    LONGLONG_ASSOC(return_value, "capacity", volumeInfo.capacity);
+    LONGLONG_ASSOC(return_value, "allocation", volumeInfo.allocation);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_get_xml_desc
+ * Since version:   0.4.1(-1), changed 0.4.2
+ * Description:     Function is used to get the storage volume XML description
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ *                  @xpath [string]: optional xPath expression string to get just this entry, can be NULL
+ *                  @flags [int]: optional flags
+ * Returns:         storagevolume XML description or result of xPath expression
+ */
+PHP_FUNCTION(libvirt_storagevolume_get_xml_desc)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    char *tmp = NULL;
+    char *xml;
+    char *xpath = NULL;
+    strsize_t xpath_len;
+    zend_long flags = 0;
+    int retval = -1;
+
+    GET_VOLUME_FROM_ARGS("rs|l", &zvolume, &xpath, &xpath_len, &flags);
+    if (xpath_len < 1)
+        xpath = NULL;
+
+    DPRINTF("%s: volume = %p, xpath = %s, flags = %ld\n", PHPFUNC, volume->volume, xpath, flags);
+
+    xml = virStorageVolGetXMLDesc(volume->volume, flags);
+    if (xml == NULL) {
+        set_error_if_unset("Cannot get the XML description" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
+    if ((tmp == NULL) || (retval < 0)) {
+        VIRT_RETVAL_STRING(xml);
+    } else {
+        VIRT_RETVAL_STRING(tmp);
+    }
+
+    free(xml);
+    free(tmp);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_create_xml
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to create the new storage pool and return the handle to new storage pool
+ * Arguments:       @res [resource]: libvirt storagepool resource
+ *                  @xml [string]: XML string to create the storage volume in the storage pool
+ *                  @flags [int]: virStorageVolCreateXML flags
+ * Returns:         libvirt storagevolume resource
+ */
+PHP_FUNCTION(libvirt_storagevolume_create_xml)
+{
+    php_libvirt_volume *res_volume = NULL;
+    php_libvirt_storagepool *pool = NULL;
+    zval *zpool;
+    virStorageVolPtr volume = NULL;
+    char *xml;
+    zend_long flags = 0;
+    strsize_t xml_len;
+
+    GET_STORAGEPOOL_FROM_ARGS("rs|l", &zpool, &xml, &xml_len, &flags);
+
+    volume = virStorageVolCreateXML(pool->pool, xml, flags);
+    DPRINTF("%s: virStorageVolCreateXML(%p, <xml>, 0) returned %p\n", PHPFUNC, pool->pool, volume);
+    if (volume == NULL)
+        RETURN_FALSE;
+
+    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
+    res_volume->volume = volume;
+    res_volume->conn   = pool->conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
+    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
+}
+
+/*
+ * 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;
+    strsize_t xml_len;
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &xml, &xml_len, &zvolume) == FAILURE) {
+        set_error("Invalid pool resource, XML or volume resouce" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);
+    if ((pool == NULL) || (pool->pool == NULL))
+        RETURN_FALSE;
+    VIRT_FETCH_RESOURCE(pl_volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+    if ((pl_volume == NULL) || (pl_volume->volume == NULL))
+        RETURN_FALSE;
+    resource_change_counter(INT_RESOURCE_VOLUME, NULL, pl_volume->volume, 1 TSRMLS_CC);
+
+    volume = virStorageVolCreateXMLFrom(pool->pool, xml, pl_volume->volume, 0);
+    DPRINTF("%s: virStorageVolCreateXMLFrom(%p, <xml>, %p, 0) returned %p\n", PHPFUNC, pool->pool, pl_volume->volume, volume);
+    if (volume == NULL)
+        RETURN_FALSE;
+
+    res_volume = (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume));
+    res_volume->volume = volume;
+    res_volume->conn   = pool->conn;
+
+    DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume);
+    resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC);
+
+    VIRT_REGISTER_RESOURCE(res_volume, le_libvirt_volume);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_delete
+ * Since version:   0.4.2
+ * Description:     Function is used to delete to volume identified by it's resource
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ *                  @flags [int]: optional flags for the storage volume deletion for virStorageVolDelete()
+ * Returns:         TRUE for success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_storagevolume_delete)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    zend_long flags = 0;
+    int retval = 0;
+
+    GET_VOLUME_FROM_ARGS("r|l", &zvolume, &flags);
+
+    retval = virStorageVolDelete(volume->volume, flags);
+    DPRINTF("%s: virStorageVolDelete(%p, %d) returned %d\n", PHPFUNC, volume->volume, (int) flags, retval);
+    if (retval != 0) {
+        set_error_if_unset("Cannot delete storage volume" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    RETURN_TRUE;
+}
+
+/*
+ * Function name:   libvirt_storagevolume_download
+ * Since version:   0.5.0
+ * Description:     Function is used to download volume identified by it's resource
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ *                  @stream [resource]: stream to use as output
+ *                  @offset [int]: position to start reading from
+ *                  @length [int] : limit on amount of data to download
+ *                  @flags [int]: optional flags for the storage volume download for virStorageVolDownload()
+ * Returns:         int
+ */
+PHP_FUNCTION(libvirt_storagevolume_download)
+{
+    php_libvirt_volume *volume = NULL;
+    php_libvirt_stream *stream = NULL;
+    zval *zvolume;
+    zval *zstream;
+    zend_long flags = 0;
+    zend_long offset = 0;
+    zend_long length = 0;
+    int retval = -1;
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE)
+        RETURN_LONG(retval);
+    VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+    if ((volume == NULL) || (volume->volume == NULL))
+        RETURN_LONG(retval);
+    VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+    if ((stream == NULL) || (stream->stream == NULL))
+        RETURN_LONG(retval);
+
+    retval = virStorageVolDownload(volume->volume, stream->stream, offset, length, flags);
+    DPRINTF("%s: virStorageVolDownload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
+
+    if (retval == -1) {
+        set_error("Cannot download from stream" TSRMLS_CC);
+        RETURN_LONG(retval);
+    }
+
+    RETURN_LONG(retval);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_upload
+ * Since version:   0.5.0
+ * Description:     Function is used to upload volume identified by it's resource
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ *                  @stream [resource]: stream to use as input
+ *                  @offset [int]: position to start writing to
+ *                  @length [int] : limit on amount of data to upload
+ *                  @flags [int]: optional flags for the storage volume upload for virStorageVolUpload()
+ * Returns:         int
+ */
+PHP_FUNCTION(libvirt_storagevolume_upload)
+{
+    php_libvirt_volume *volume = NULL;
+    php_libvirt_stream *stream = NULL;
+    zval *zvolume;
+    zval *zstream;
+    zend_long flags = 0;
+    zend_long offset = 0;
+    zend_long length = 0;
+    int retval = -1;
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE)
+        RETURN_LONG(retval);
+    VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);
+    if ((volume == NULL) || (volume->volume == NULL))
+        RETURN_LONG(retval);
+    VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream);
+    if ((stream == NULL) || (stream->stream == NULL))
+        RETURN_LONG(retval);
+
+    retval = virStorageVolUpload(volume->volume, stream->stream, offset, length, flags);
+    DPRINTF("%s: virStorageVolUpload(%p, %p, %d, %d, %d) returned %d\n", PHPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) flags, retval);
+
+    if (retval == -1) {
+        set_error_if_unset("Cannot upload storage volume" TSRMLS_CC);
+        RETURN_LONG(retval);
+    }
+
+    RETURN_LONG(retval);
+}
+
+/*
+ * Function name:   libvirt_storagevolume_resize
+ * Since version:   0.5.0
+ * Description:     Function is used to resize volume identified by it's resource
+ * Arguments:       @res [resource]: libvirt storagevolume resource
+ *                  @capacity [int]: capacity for the storage volume
+ *                  @flags [int]: optional flags for the storage volume resize for virStorageVolResize()
+ * Returns:         int
+ */
+PHP_FUNCTION(libvirt_storagevolume_resize)
+{
+    php_libvirt_volume *volume = NULL;
+    zval *zvolume;
+    zend_long flags = 0;
+    zend_long capacity = 0;
+    int retval = -1;
+
+    GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags);
+
+    retval = virStorageVolResize(volume->volume, capacity, flags);
+    DPRINTF("%s: virStorageVolResize(%p, %d, %d) returned %d\n", PHPFUNC, volume->volume, (int) capacity, (int) flags, retval);
+    if (retval != 0) {
+        set_error_if_unset("Cannot resize storage volume" TSRMLS_CC);
+        RETURN_LONG(retval);
+    }
+
+    RETURN_LONG(retval);
+}
+
+/*
+ * Function name:   libvirt_list_storagepools
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to list storage pools on the connection
+ * Arguments:       @res [resource]: libvirt connection resource
+ * Returns:         libvirt storagepool names array for the connection
+ */
+PHP_FUNCTION(libvirt_list_storagepools)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int count = -1;
+    int expectedcount = -1;
+    char **names;
+    int i;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    if ((expectedcount = virConnectNumOfStoragePools(conn->conn)) < 0)
+        RETURN_FALSE;
+
+    names = (char **)emalloc(expectedcount*sizeof(char *));
+    count = virConnectListStoragePools(conn->conn, names, expectedcount);
+
+    if ((count != expectedcount) || (count < 0)) {
+        efree(names);
+        RETURN_FALSE;
+    }
+
+    array_init(return_value);
+    for (i = 0; i < count; i++) {
+        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
+        free(names[i]);
+    }
+    efree(names);
+
+
+    if ((expectedcount = virConnectNumOfDefinedStoragePools(conn->conn)) < 0)
+        RETURN_FALSE;
+    names = (char **)emalloc(expectedcount * sizeof(char *));
+    count = virConnectListDefinedStoragePools(conn->conn, names, expectedcount);
+    if ((count != expectedcount) || (count < 0)) {
+        efree(names);
+        RETURN_FALSE;
+    }
+
+    for (i = 0; i < count; i++) {
+        VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+        free(names[i]);
+    }
+    efree(names);
+}
+
+/*
+ * Function name:   libvirt_list_active_storagepools
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to list active storage pools on the connection
+ * Arguments:       @res [resource]: libvirt connection resource
+ * Returns:         libvirt storagepool names array for the connection
+ */
+PHP_FUNCTION(libvirt_list_active_storagepools)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int count = -1;
+    int expectedcount = -1;
+    char **names;
+    int i;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    if ((expectedcount = virConnectNumOfStoragePools(conn->conn)) < 0)
+        RETURN_FALSE;
+
+    names = (char **)emalloc(expectedcount*sizeof(char *));
+    count = virConnectListStoragePools(conn->conn, names, expectedcount);
+
+    if ((count != expectedcount) || (count < 0)) {
+        efree(names);
+        RETURN_FALSE;
+    }
+    array_init(return_value);
+    for (i = 0; i < count; i++) {
+        VIRT_ADD_NEXT_INDEX_STRING(return_value,  names[i]);
+        free(names[i]);
+    }
+    efree(names);
+}
+
+/*
+ * Function name:   libvirt_list_inactive_storagepools
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to list inactive storage pools on the connection
+ * Arguments:       @res [resource]: libvirt connection resource
+ * Returns:         libvirt storagepool names array for the connection
+ */
+PHP_FUNCTION(libvirt_list_inactive_storagepools)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int count = -1;
+    int expectedcount = -1;
+    char **names;
+    int i;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    if ((expectedcount = virConnectNumOfDefinedStoragePools(conn->conn)) < 0)
+        RETURN_FALSE;
+
+    names = (char **)emalloc(expectedcount * sizeof(char *));
+    count = virConnectListDefinedStoragePools(conn->conn, names, expectedcount);
+    if ((count != expectedcount) || (count < 0)) {
+        efree(names);
+        RETURN_FALSE;
+    }
+
+    array_init(return_value);
+    for (i = 0; i < count; i++) {
+        VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+        free(names[i]);
+    }
+    efree(names);
+}
diff --git a/src/libvirt-storage.h b/src/libvirt-storage.h
new file mode 100644
index 0000000..de972f7
--- /dev/null
+++ b/src/libvirt-storage.h
@@ -0,0 +1,137 @@
+/*
+ * libvirt-storage.h: The PHP bindings to libvirt storage API
+ *
+ * See COPYING for the license of this software
+ */
+
+#ifndef __LIBVIRT_STORAGE_H__
+# define __LIBVIRT_STORAGE_H__
+
+# include "libvirt-connection.h"
+
+# define PHP_LIBVIRT_STORAGEPOOL_RES_NAME "Libvirt storagepool"
+# define PHP_LIBVIRT_VOLUME_RES_NAME "Libvirt volume"
+# define INT_RESOURCE_STORAGEPOOL 0x10
+# define INT_RESOURCE_VOLUME 0x20
+
+# define PHP_FE_LIBVIRT_STORAGE                                                                      \
+    PHP_FE(libvirt_storagepool_lookup_by_name,        arginfo_libvirt_conn_name)                     \
+    PHP_FE(libvirt_storagepool_lookup_by_volume,      arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_list_volumes,          arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_get_info,              arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_get_uuid_string,       arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_get_name,              arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_lookup_by_uuid_string, arginfo_libvirt_conn_uuid)                     \
+    PHP_FE(libvirt_storagepool_get_xml_desc,          arginfo_libvirt_conn_xpath)                    \
+    PHP_FE(libvirt_storagepool_define_xml,            arginfo_libvirt_storagepool_define_xml)        \
+    PHP_FE(libvirt_storagepool_undefine,              arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_create,                arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_destroy,               arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_is_active,             arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_get_volume_count,      arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_refresh,               arginfo_libvirt_conn_optflags)                 \
+    PHP_FE(libvirt_storagepool_set_autostart,         arginfo_libvirt_conn_flags)                    \
+    PHP_FE(libvirt_storagepool_get_autostart,         arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_build,                 arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagepool_delete,                arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagevolume_lookup_by_name,      arginfo_libvirt_conn_name)                     \
+    PHP_FE(libvirt_storagevolume_lookup_by_path,      arginfo_libvirt_storagevolume_lookup_by_path)  \
+    PHP_FE(libvirt_storagevolume_get_name,            arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagevolume_get_path,            arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagevolume_get_info,            arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_storagevolume_get_xml_desc,        arginfo_libvirt_storagevolume_get_xml_desc)    \
+    PHP_FE(libvirt_storagevolume_create_xml,          arginfo_libvirt_conn_xml)                      \
+    PHP_FE(libvirt_storagevolume_create_xml_from,     arginfo_libvirt_storagevolume_create_xml_from) \
+    PHP_FE(libvirt_storagevolume_delete,              arginfo_libvirt_conn_optflags)                 \
+    PHP_FE(libvirt_storagevolume_download,            arginfo_libvirt_storagevolume_download)        \
+    PHP_FE(libvirt_storagevolume_upload,              arginfo_libvirt_storagevolume_download)        \
+    PHP_FE(libvirt_storagevolume_resize,              arginfo_libvirt_storagevolume_resize)          \
+    PHP_FE(libvirt_list_storagepools,                 arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_list_active_storagepools,          arginfo_libvirt_conn)                          \
+    PHP_FE(libvirt_list_inactive_storagepools,        arginfo_libvirt_conn)
+
+# define GET_STORAGEPOOL_FROM_ARGS(args, ...)                                  \
+    do {                                                                       \
+        reset_error(TSRMLS_C);                                                 \
+        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,                   \
+                                  args,                                        \
+                                  __VA_ARGS__) == FAILURE) {                   \
+            set_error("Invalid arguments" TSRMLS_CC);                          \
+            RETURN_FALSE;                                                      \
+        }                                                                      \
+                                                                               \
+        VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool,            \
+                            PHP_LIBVIRT_STORAGEPOOL_RES_NAME,                  \
+                            le_libvirt_storagepool);                           \
+        if ((pool == NULL) || (pool->pool == NULL))                            \
+            RETURN_FALSE;                                                      \
+    } while (0)                                                                \
+
+# define GET_VOLUME_FROM_ARGS(args, ...)                                       \
+    do {                                                                       \
+        reset_error(TSRMLS_C);                                                 \
+        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,                   \
+                                  args,                                        \
+                                  __VA_ARGS__) == FAILURE) {                   \
+            set_error("Invalid arguments" TSRMLS_CC);                          \
+            RETURN_FALSE;                                                      \
+        }                                                                      \
+                                                                               \
+        VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume,             \
+                            PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);   \
+        if ((volume == NULL) || (volume->volume == NULL))                      \
+            RETURN_FALSE;                                                      \
+    } while (0)                                                                \
+
+int le_libvirt_storagepool;
+int le_libvirt_volume;
+
+typedef struct _php_libvirt_storagepool {
+    virStoragePoolPtr pool;
+    php_libvirt_connection* conn;
+} php_libvirt_storagepool;
+
+typedef struct _php_libvirt_volume {
+    virStorageVolPtr volume;
+    php_libvirt_connection* conn;
+} php_libvirt_volume;
+
+void php_libvirt_storagepool_dtor(virt_resource *rsrc TSRMLS_DC);
+void php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC);
+
+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_storagepool_get_uuid_string);
+PHP_FUNCTION(libvirt_storagepool_get_name);
+PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string);
+PHP_FUNCTION(libvirt_storagepool_get_xml_desc);
+PHP_FUNCTION(libvirt_storagepool_define_xml);
+PHP_FUNCTION(libvirt_storagepool_undefine);
+PHP_FUNCTION(libvirt_storagepool_create);
+PHP_FUNCTION(libvirt_storagepool_destroy);
+PHP_FUNCTION(libvirt_storagepool_is_active);
+PHP_FUNCTION(libvirt_storagepool_get_volume_count);
+PHP_FUNCTION(libvirt_storagepool_refresh);
+PHP_FUNCTION(libvirt_storagepool_set_autostart);
+PHP_FUNCTION(libvirt_storagepool_get_autostart);
+PHP_FUNCTION(libvirt_storagepool_build);
+PHP_FUNCTION(libvirt_storagepool_delete);
+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);
+PHP_FUNCTION(libvirt_storagevolume_get_xml_desc);
+PHP_FUNCTION(libvirt_storagevolume_create_xml);
+PHP_FUNCTION(libvirt_storagevolume_create_xml_from);
+PHP_FUNCTION(libvirt_storagevolume_delete);
+PHP_FUNCTION(libvirt_storagevolume_download);
+PHP_FUNCTION(libvirt_storagevolume_upload);
+PHP_FUNCTION(libvirt_storagevolume_resize);
+PHP_FUNCTION(libvirt_list_storagepools);
+PHP_FUNCTION(libvirt_list_active_storagepools);
+PHP_FUNCTION(libvirt_list_inactive_storagepools);
+
+#endif
-- 
2.13.3

--
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]
  Powered by Linux