From nobody Fri May 16 04:09:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501785488280638.9726045934866; Thu, 3 Aug 2017 11:38:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C72185542; Thu, 3 Aug 2017 18:38:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42AA9792B0; Thu, 3 Aug 2017 18:38:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C3A721803B24; Thu, 3 Aug 2017 18:38:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v73IZR3g026090 for ; Thu, 3 Aug 2017 14:35:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25FB079297; Thu, 3 Aug 2017 18:35:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B5C15C891 for ; Thu, 3 Aug 2017 18:35:27 +0000 (UTC) Received: from mail-qt0-f172.google.com (mail-qt0-f172.google.com [209.85.216.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 593F3356D7 for ; Thu, 3 Aug 2017 18:35:19 +0000 (UTC) Received: by mail-qt0-f172.google.com with SMTP id a18so12779310qta.0 for ; Thu, 03 Aug 2017 11:35:19 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id b142sm23906990qka.37.2017.08.03.11.35.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2017 11:35:16 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C72185542 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7C72185542 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kwErVTlS" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 593F3356D7 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzrudy@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 593F3356D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=9lYgPvTGpWxjE2dtiTNzszRJCle+06wAaf1Xho6nKsY=; b=kwErVTlS0iyTKoNtEsy7VxVSyt6zhTykt2OqqiXSjKuF7cq6BxLnWuI/JLoZ0W8+Mt VLM9v5acNDuoVBDznNYfGYfT3tj74gMfCVeiXX6RIFpS8w3yMsj3njpbfP4xX7zIZZK/ m/VKsDsY6+HOXi1X0VF/GoNrUSYmhT21LXOW4ERc2nLPgpFga3kO7nkWamCU3oME/0BI FVT8PpHEo9gHSeMIq9h4NxtgPs8uxmfTpydERx9JFXa5Bm02/Ik5QTVMNwGeezFsuqxr v3qB5HZS0G5KNmM8vlgVCrLYw6D/Kf4hA+qyn8FNToagUUL5TSd1ZKR+VAVEwYBkcJaH VcUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=9lYgPvTGpWxjE2dtiTNzszRJCle+06wAaf1Xho6nKsY=; b=ug162fnt3BDaJLBFd2c8GjCwo9Ko/mZPNBAPe0ut2aVJXEGmliGb7iMLFdeNr42ZMk eTAtUDdPlqol38R0NWtYaPqS9jO1QK+St9KozweMR36Md9iEY3/+tU3fN6zhhHN+rjST qcpBa42aVizXHGl7srT4iNazchiNQE4mgWZ9AnMtdee2qH9ewJ1TG/DW9/xJw69EQdkN hiCfP+xWWeq4R2+2TVb08UluiYSu4+u0uzRF2AzNzKr7q1HlW0MUd8+Aw3FU2wG5LCzA t7cyiEZsmR/SHqreW35NmY+MOfhf7jBQVGj/zowpC/icJGn/2xJnSWss0jwLxgUCHmNF I4kw== X-Gm-Message-State: AHYfb5hJ5I0qXRcR0Qg1SSN0DCONNTC3rVN+oCqK2TyhVTfLgWj4iixB u8IXK24/qY0YmIf0/GQ= X-Received: by 10.237.37.107 with SMTP id w40mr3388059qtc.14.1501785317142; Thu, 03 Aug 2017 11:35:17 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Thu, 3 Aug 2017 14:35:05 -0400 Message-Id: <20170803183509.1250-8-dzrudy@gmail.com> In-Reply-To: <20170803183509.1250-1-dzrudy@gmail.com> References: <20170803183509.1250-1-dzrudy@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 03 Aug 2017 18:35:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 03 Aug 2017 18:35:19 +0000 (UTC) for IP:'209.85.216.172' DOMAIN:'mail-qt0-f172.google.com' HELO:'mail-qt0-f172.google.com' FROM:'dzrudy@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.43 (DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.172 mail-qt0-f172.google.com 209.85.216.172 mail-qt0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-php PATCH v2 07/11] Split up the bindings for libvirt storage API X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 03 Aug 2017 18:38:06 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- 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 =3D \ libvirt-node.c libvirt-node.h \ libvirt-stream.c libvirt-stream.h \ libvirt-domain.c libvirt-domain.h \ - libvirt-network.c libvirt-network.h=20 + libvirt-network.c libvirt-network.h \ + libvirt-storage.c libvirt-storage.h libvirt_php_la_CFLAGS =3D \ $(AM_CFLAGS) \ -DCOMPILE_DL_LIBVIRT=3D1 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" =20 DEBUG_INIT("core"); =20 @@ -37,8 +38,6 @@ const char *features_binaries[] =3D { NULL }; #endif =20 /* 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[] =3D { PHP_FE(libvirt_domain_snapshot_revert, arginfo_libvirt_conn_optf= lags) PHP_FE(libvirt_domain_snapshot_delete, arginfo_libvirt_conn_optf= lags) 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_storagevo= lume_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_storagevo= lume_get_xml_desc) - PHP_FE(libvirt_storagevolume_create_xml, arginfo_libvirt_conn_xml) - PHP_FE(libvirt_storagevolume_create_xml_from,arginfo_libvirt_storagevo= lume_create_xml_from) - PHP_FE(libvirt_storagevolume_delete, arginfo_libvirt_conn_optf= lags) - PHP_FE(libvirt_storagevolume_download, arginfo_libvirt_storagevo= lume_download) - PHP_FE(libvirt_storagevolume_upload, arginfo_libvirt_storagevo= lume_download) - PHP_FE(libvirt_storagevolume_resize, arginfo_libvirt_storagevo= lume_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_xpat= h) - PHP_FE(libvirt_storagepool_define_xml, arginfo_libvirt_storagepo= ol_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_optf= lags) - PHP_FE(libvirt_storagepool_set_autostart, arginfo_libvirt_conn_flag= s) - 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[] =3D { /* List functions */ PHP_FE(libvirt_list_domain_snapshots, arginfo_libvirt_conn_optf= lags) PHP_FE(libvirt_list_nodedevs, arginfo_libvirt_conn_optc= ap) - 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 =3D { ZEND_GET_MODULE(libvirt) #endif =20 - /* PHP init options */ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("libvirt.longlong_to_string", "1", PHP_INI_ALL, OnUpdate= Bool, longlong_to_string_ini, zend_libvirt_globals, libvirt_globals) @@ -1222,60 +1185,6 @@ int is_local_connection(virConnectPtr conn) #endif } =20 -/* Destructor for storagepool resource */ -static void php_libvirt_storagepool_dtor(virt_resource *rsrc TSRMLS_DC) -{ - php_libvirt_storagepool *pool =3D (php_libvirt_storagepool *)rsrc->ptr; - int rv =3D 0; - - if (pool !=3D NULL) { - if (pool->pool !=3D NULL) { - if (!check_resource_allocation(NULL, INT_RESOURCE_STORAGEPOOL,= pool->pool TSRMLS_CC)) { - pool->pool =3D NULL; - efree(pool); - return; - } - rv =3D virStoragePoolFree(pool->pool); - if (rv !=3D 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, "virStoragePoo= lFree 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, po= ol->pool, 0 TSRMLS_CC); - } - pool->pool =3D NULL; - } - efree(pool); - } -} - -/* Destructor for volume resource */ -static void php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC) -{ - php_libvirt_volume *volume =3D (php_libvirt_volume *)rsrc->ptr; - int rv =3D 0; - - if (volume !=3D NULL) { - if (volume->volume !=3D NULL) { - if (!check_resource_allocation(NULL, INT_RESOURCE_VOLUME, volu= me->volume TSRMLS_CC)) { - volume->volume =3D NULL; - efree(volume); - return; - } - rv =3D virStorageVolFree(volume->volume); - if (rv !=3D 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, "virStorageVol= Free 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 =3D 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) =20 -#define GET_STORAGEPOOL_FROM_ARGS(args, ...) = \ - do { = \ - reset_error(TSRMLS_C); = \ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_AR= GS__) =3D=3D FAILURE) { \ - set_error("Invalid arguments" TSRMLS_CC); = \ - RETURN_FALSE; = \ - } = \ - = \ - VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LI= BVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);\ - if ((pool =3D=3D NULL) || (pool->pool =3D=3D 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_AR= GS__) =3D=3D FAILURE) { \ - set_error("Invalid arguments" TSRMLS_CC); = \ - RETURN_FALSE; = \ - } = \ - = \ - VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIB= VIRT_VOLUME_RES_NAME, le_libvirt_volume);\ - if ((volume =3D=3D NULL) || (volume->volume =3D=3D 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); } =20 -/* 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 na= me - * 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 =3D NULL; - zval *zconn; - strsize_t name_len; - char *name =3D NULL; - virStoragePoolPtr pool =3D NULL; - php_libvirt_storagepool *res_pool; - - GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len); - - if ((name =3D=3D NULL) || (name_len < 1)) - RETURN_FALSE; - pool =3D virStoragePoolLookupByName(conn->conn, name); - DPRINTF("%s: virStoragePoolLookupByName(%p, %s) returned %p\n", PHPFUN= C, conn->conn, name, pool); - if (pool =3D=3D NULL) - RETURN_FALSE; - - res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); - res_pool->pool =3D pool; - res_pool->conn =3D 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 =3D NULL; - php_libvirt_storagepool *res_pool; - - GET_VOLUME_FROM_ARGS("r", &zvolume); - - pool =3D virStoragePoolLookupByVolume(volume->volume); - DPRINTF("%s: virStoragePoolLookupByVolume(%p) returned %p\n", PHPFUNC,= volume->volume, pool); - if (pool =3D=3D NULL) - RETURN_FALSE; - - res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); - res_pool->pool =3D pool; - res_pool->conn =3D 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 stor= age 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 =3D NULL; - zval *zpool; - char **names =3D NULL; - int expectedcount =3D -1; - int i; - int count =3D -1; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - if ((expectedcount =3D virStoragePoolNumOfVolumes(pool->pool)) < 0) - RETURN_FALSE; - - DPRINTF("%s: virStoragePoolNumOfVolumes(%p) returned %d\n", PHPFUNC, p= ool->pool, expectedcount); - names =3D (char **)emalloc(expectedcount*sizeof(char *)); - - count =3D virStoragePoolListVolumes(pool->pool, names, expectedcount); - DPRINTF("%s: virStoragePoolListVolumes(%p, %p, %d) returned %d\n", PHP= FUNC, pool->pool, names, expectedcount, count); - array_init(return_value); - - if ((count !=3D expectedcount) || (count < 0)) - RETURN_FALSE; - for (i =3D 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, all= ocation and available space - */ -PHP_FUNCTION(libvirt_storagepool_get_info) -{ - php_libvirt_storagepool *pool =3D NULL; - zval *zpool; - virStoragePoolInfo poolInfo; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolGetInfo(pool->pool, &poolInfo); - DPRINTF("%s: virStoragePoolGetInfo(%p, ) returned %d\n", PHPFUNC= , pool->pool, retval); - if (retval !=3D 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 =3D NULL; - php_libvirt_volume *res_volume; - zval *zpool; - strsize_t name_len; - char *name =3D NULL; - virStorageVolPtr volume =3D NULL; - - GET_STORAGEPOOL_FROM_ARGS("rs", &zpool, &name, &name_len); - if ((name =3D=3D NULL) || (name_len < 1)) - RETURN_FALSE; - - volume =3D virStorageVolLookupByName(pool->pool, name); - DPRINTF("%s: virStorageVolLookupByName(%p, %s) returned %p\n", PHPFUNC= , pool->pool, name, volume); - if (volume =3D=3D NULL) - RETURN_FALSE; - - res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); - res_volume->volume =3D volume; - res_volume->conn =3D pool->conn; - - DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); - resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 =3D NULL; - php_libvirt_volume *res_volume; - zval *zconn; - strsize_t name_len; - char *name =3D NULL; - virStorageVolPtr volume =3D NULL; - - GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len); - if ((name =3D=3D NULL) || (name_len < 1)) - RETURN_FALSE; - - volume =3D virStorageVolLookupByPath(conn->conn, name); - DPRINTF("%s: virStorageVolLookupByPath(%p, %s) returned %p\n", PHPFUNC= , conn->conn, name, volume); - if (volume =3D=3D NULL) { - set_error_if_unset("Cannot find storage volume on requested path" = TSRMLS_CC); - RETURN_FALSE; - } - - res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); - res_volume->volume =3D volume; - res_volume->conn =3D conn; - - DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); - resource_change_counter(INT_RESOURCE_VOLUME, conn->conn, res_volume->v= olume, 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 =3D NULL; - zval *zvolume; - const char *retval; - - GET_VOLUME_FROM_ARGS("r", &zvolume); - - retval =3D virStorageVolGetName(volume->volume); - DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume-= >volume, retval); - if (retval =3D=3D 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 =3D NULL; - zval *zvolume; - char *retval; - - GET_VOLUME_FROM_ARGS("r", &zvolume); - - retval =3D virStorageVolGetPath(volume->volume); - DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume-= >volume, retval); - if (retval =3D=3D 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 a= nd capacity - */ -PHP_FUNCTION(libvirt_storagevolume_get_info) -{ - php_libvirt_volume *volume =3D NULL; - zval *zvolume; - virStorageVolInfo volumeInfo; - int retval; - - GET_VOLUME_FROM_ARGS("r", &zvolume); - - retval =3D virStorageVolGetInfo(volume->volume, &volumeInfo); - DPRINTF("%s: virStorageVolGetInfo(%p, ) returned %d\n", PHPFUNC,= volume->volume, retval); - if (retval !=3D 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 descrip= tion - * Arguments: @res [resource]: libvirt storagevolume resource - * @xpath [string]: optional xPath expression string to g= et just this entry, can be NULL - * @flags [int]: optional flags - * Returns: storagevolume XML description or result of xPath expre= ssion - */ -PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) -{ - php_libvirt_volume *volume =3D NULL; - zval *zvolume; - char *tmp =3D NULL; - char *xml; - char *xpath =3D NULL; - strsize_t xpath_len; - zend_long flags =3D 0; - int retval =3D -1; - - GET_VOLUME_FROM_ARGS("rs|l", &zvolume, &xpath, &xpath_len, &flags); - if (xpath_len < 1) - xpath =3D NULL; - - DPRINTF("%s: volume =3D %p, xpath =3D %s, flags =3D %ld\n", PHPFUNC, v= olume->volume, xpath, flags); - - xml =3D virStorageVolGetXMLDesc(volume->volume, flags); - if (xml =3D=3D NULL) { - set_error_if_unset("Cannot get the XML description" TSRMLS_CC); - RETURN_FALSE; - } - - tmp =3D get_string_from_xpath(xml, xpath, NULL, &retval); - if ((tmp =3D=3D 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 re= turn 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 =3D NULL; - php_libvirt_storagepool *pool =3D NULL; - zval *zpool; - virStorageVolPtr volume =3D NULL; - char *xml; - zend_long flags =3D 0; - strsize_t xml_len; - - GET_STORAGEPOOL_FROM_ARGS("rs|l", &zpool, &xml, &xml_len, &flags); - - volume =3D virStorageVolCreateXML(pool->pool, xml, flags); - DPRINTF("%s: virStorageVolCreateXML(%p, , 0) returned %p\n", PHPF= UNC, pool->pool, volume); - if (volume =3D=3D NULL) - RETURN_FALSE; - - res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); - res_volume->volume =3D volume; - res_volume->conn =3D pool->conn; - - DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); - resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 res= ource - * Returns: libvirt storagevolume resource - */ -PHP_FUNCTION(libvirt_storagevolume_create_xml_from) -{ - php_libvirt_volume *res_volume =3D NULL; - php_libvirt_storagepool *pool =3D NULL; - zval *zpool; - - php_libvirt_volume *pl_volume =3D NULL; - zval *zvolume; - - virStorageVolPtr volume =3D NULL; - char *xml; - strsize_t xml_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &x= ml, &xml_len, &zvolume) =3D=3D FAILURE) { - set_error("Invalid pool resource, XML or volume resouce" TSRMLS_CC= ); - RETURN_FALSE; - } - - VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIR= T_STORAGEPOOL_RES_NAME, le_libvirt_storagepool); - if ((pool =3D=3D NULL) || (pool->pool =3D=3D NULL)) - RETURN_FALSE; - VIRT_FETCH_RESOURCE(pl_volume, php_libvirt_volume*, &zvolume, PHP_LIBV= IRT_VOLUME_RES_NAME, le_libvirt_volume); - if ((pl_volume =3D=3D NULL) || (pl_volume->volume =3D=3D NULL)) - RETURN_FALSE; - resource_change_counter(INT_RESOURCE_VOLUME, NULL, pl_volume->volume, = 1 TSRMLS_CC); - - volume =3D virStorageVolCreateXMLFrom(pool->pool, xml, pl_volume->volu= me, 0); - DPRINTF("%s: virStorageVolCreateXMLFrom(%p, , %p, 0) returned %p\= n", PHPFUNC, pool->pool, pl_volume->volume, volume); - if (volume =3D=3D NULL) - RETURN_FALSE; - - res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); - res_volume->volume =3D volume; - res_volume->conn =3D pool->conn; - - DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); - resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 de= letion for virStorageVolDelete() - * Returns: TRUE for success, FALSE on error - */ -PHP_FUNCTION(libvirt_storagevolume_delete) -{ - php_libvirt_volume *volume =3D NULL; - zval *zvolume; - zend_long flags =3D 0; - int retval =3D 0; - - GET_VOLUME_FROM_ARGS("r|l", &zvolume, &flags); - - retval =3D virStorageVolDelete(volume->volume, flags); - DPRINTF("%s: virStorageVolDelete(%p, %d) returned %d\n", PHPFUNC, volu= me->volume, (int) flags, retval); - if (retval !=3D 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 r= esource - * Arguments: @res [resource]: libvirt storagevolume resource - * @capacity [int]: capacity for the storage volume - * @flags [int]: optional flags for the storage volume re= size for virStorageVolResize() - * Returns: int - */ -PHP_FUNCTION(libvirt_storagevolume_resize) -{ - php_libvirt_volume *volume =3D NULL; - zval *zvolume; - zend_long flags =3D 0; - zend_long capacity =3D 0; - int retval =3D -1; - - GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags); - - retval =3D virStorageVolResize(volume->volume, capacity, flags); - DPRINTF("%s: virStorageVolResize(%p, %d, %d) returned %d\n", PHPFUNC, = volume->volume, (int) capacity, (int) flags, retval); - if (retval !=3D 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 do= wnload for virStorageVolDownload() - * Returns: int - */ -PHP_FUNCTION(libvirt_storagevolume_download) -{ - php_libvirt_volume *volume =3D NULL; - php_libvirt_stream *stream =3D NULL; - zval *zvolume; - zval *zstream; - zend_long flags =3D 0; - zend_long offset =3D 0; - zend_long length =3D 0; - int retval =3D -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvol= ume, &zstream, &offset, &length, &flags) =3D=3D FAILURE) - RETURN_LONG(retval); - VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT= _VOLUME_RES_NAME, le_libvirt_volume); - if ((volume =3D=3D NULL) || (volume->volume =3D=3D NULL)) - RETURN_LONG(retval); - VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT= _STREAM_RES_NAME, le_libvirt_stream); - if ((stream =3D=3D NULL) || (stream->stream =3D=3D NULL)) - RETURN_LONG(retval); - - retval =3D virStorageVolDownload(volume->volume, stream->stream, offse= t, 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 =3D=3D -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 r= esource - * 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 up= load for virStorageVolUpload() - * Returns: int - */ -PHP_FUNCTION(libvirt_storagevolume_upload) -{ - php_libvirt_volume *volume =3D NULL; - php_libvirt_stream *stream =3D NULL; - zval *zvolume; - zval *zstream; - zend_long flags =3D 0; - zend_long offset =3D 0; - zend_long length =3D 0; - int retval =3D -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvol= ume, &zstream, &offset, &length, &flags) =3D=3D FAILURE) - RETURN_LONG(retval); - VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT= _VOLUME_RES_NAME, le_libvirt_volume); - if ((volume =3D=3D NULL) || (volume->volume =3D=3D NULL)) - RETURN_LONG(retval); - VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT= _STREAM_RES_NAME, le_libvirt_stream); - if ((stream =3D=3D NULL) || (stream->stream =3D=3D NULL)) - RETURN_LONG(retval); - - retval =3D virStorageVolUpload(volume->volume, stream->stream, offset,= length, flags); - DPRINTF("%s: virStorageVolUpload(%p, %p, %d, %d, %d) returned %d\n", P= HPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) f= lags, retval); - - if (retval =3D=3D -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 =3D NULL; - zval *zpool; - char *uuid; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - uuid =3D (char *)emalloc(VIR_UUID_STRING_BUFLEN); - retval =3D virStoragePoolGetUUIDString(pool->pool, uuid); - DPRINTF("%s: virStoragePoolGetUUIDString(%p, %p) returned %d (%s)\n", = PHPFUNC, pool->pool, uuid, retval, uuid); - if (retval !=3D 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 sto= rage pool resource - * Arguments: @res [resource]: libvirt storagepool resource - * Returns: storagepool name string - */ -PHP_FUNCTION(libvirt_storagepool_get_name) -{ - php_libvirt_storagepool *pool =3D NULL; - zval *zpool; - const char *name =3D NULL; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - name =3D virStoragePoolGetName(pool->pool); - DPRINTF("%s: virStoragePoolGetName(%p) returned %s\n", PHPFUNC, pool->= pool, name); - if (name =3D=3D 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 =3D NULL; - zval *zconn; - char *uuid =3D NULL; - strsize_t uuid_len; - virStoragePoolPtr storage =3D NULL; - php_libvirt_storagepool *res_pool; - - GET_CONNECTION_FROM_ARGS("rs", &zconn, &uuid, &uuid_len); - - if ((uuid =3D=3D NULL) || (uuid_len < 1)) - RETURN_FALSE; - - storage =3D virStoragePoolLookupByUUIDString(conn->conn, uuid); - DPRINTF("%s: virStoragePoolLookupByUUIDString(%p, %s) returned %p\n", = PHPFUNC, conn->conn, uuid, storage); - if (storage =3D=3D NULL) - RETURN_FALSE; - - res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); - res_pool->pool =3D storage; - res_pool->conn =3D 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 st= orage pool identified by res - * Arguments: @res [resource]: libvirt storagepool resource - * @xpath [string]: optional xPath expression string to g= et 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 =3D NULL; - zval *zpool; - char *xml; - char *xpath =3D NULL; - char *tmp =3D NULL; - zend_long flags =3D 0; - strsize_t xpath_len; - int retval =3D -1; - - GET_STORAGEPOOL_FROM_ARGS("r|s", &zpool, &xpath, &xpath_len, &flags); - if (xpath_len < 1) - xpath =3D NULL; - - DPRINTF("%s: pool =3D %p, flags =3D %ld, xpath =3D %s\n", PHPFUNC, poo= l->pool, flags, xpath); - - xml =3D virStoragePoolGetXMLDesc(pool->pool, flags); - if (xml =3D=3D NULL) { - set_error_if_unset("Cannot get the XML description" TSRMLS_CC); - RETURN_FALSE; - } - - tmp =3D get_string_from_xpath(xml, xpath, NULL, &retval); - if ((tmp =3D=3D 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 s= tring 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 =3D NULL; - php_libvirt_connection *conn =3D NULL; - zval *zconn; - virStoragePoolPtr pool =3D NULL; - char *xml; - strsize_t xml_len; - zend_long flags =3D 0; - - - GET_CONNECTION_FROM_ARGS("rs|l", &zconn, &xml, &xml_len, &flags); - - pool =3D virStoragePoolDefineXML(conn->conn, xml, (unsigned int)flags); - DPRINTF("%s: virStoragePoolDefineXML(%p, ) returned %p\n", PHPFUN= C, conn->conn, pool); - if (pool =3D=3D NULL) - RETURN_FALSE; - - res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); - res_pool->pool =3D pool; - res_pool->conn =3D 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 identifi= ed 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 =3D NULL; - zval *zpool; - int retval =3D 0; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolUndefine(pool->pool); - DPRINTF("%s: virStoragePoolUndefine(%p) returned %d\n", PHPFUNC, pool-= >pool, retval); - if (retval !=3D 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 =3D NULL; - zval *zpool; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolCreate(pool->pool, 0); - DPRINTF("%s: virStoragePoolCreate(%p, 0) returned %d\n", PHPFUNC, pool= ->pool, retval); - if (retval !=3D 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 =3D NULL; - zval *zpool; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolDestroy(pool->pool); - DPRINTF("%s: virStoragePoolDestroy(%p) returned %d\n", PHPFUNC, pool->= pool, retval); - if (retval !=3D 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 po= ol is active or not - * Arguments: @res [resource]: libvirt storagepool resource - * Returns: result of virStoragePoolIsActive - */ -PHP_FUNCTION(libvirt_storagepool_is_active) -{ - php_libvirt_storagepool *pool =3D 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 st= orage 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 =3D 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 informati= on - * 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 =3D NULL; - zval *zpool; - zend_long flags =3D 0; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r|l", &zpool, &flags); - - retval =3D virStoragePoolRefresh(pool->pool, flags); - DPRINTF("%s: virStoragePoolRefresh(%p, %ld) returned %d\n", PHPFUNC, p= ool->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 =3D NULL; - zval *zpool; - zend_bool flags =3D 0; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("rb", &zpool, &flags); - - retval =3D virStoragePoolSetAutostart(pool->pool, flags); - DPRINTF("%s: virStoragePoolSetAutostart(%p, %d) returned %d\n", PHPFUN= C, pool->pool, flags, retval); - if (retval !=3D 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 disabl= ed, FALSE with last_error set for error - */ -PHP_FUNCTION(libvirt_storagepool_get_autostart) -{ - php_libvirt_storagepool *pool =3D NULL; - zval *zpool; - int autostart; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - if (virStoragePoolGetAutostart(pool->pool, &autostart) =3D=3D 0 && - autostart !=3D 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 =3D NULL; - zval *zpool; - int flags =3D 0; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolBuild(pool->pool, flags); - DPRINTF("%s: virStoragePoolBuild(%p, %d) returned %d\n", PHPFUNC, pool= ->pool, flags, retval); - if (retval =3D=3D 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 =3D NULL; - zval *zpool; - int flags =3D 0; - int retval; - - GET_STORAGEPOOL_FROM_ARGS("r", &zpool); - - retval =3D virStoragePoolDelete(pool->pool, flags); - DPRINTF("%s: virStoragePoolDelete(%p, %d) returned %d\n", PHPFUNC, poo= l->pool, flags, retval); - if (retval =3D=3D 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 connecti= on - * Arguments: @res [resource]: libvirt connection resource - * Returns: libvirt storagepool names array for the connection - */ -PHP_FUNCTION(libvirt_list_storagepools) -{ - php_libvirt_connection *conn =3D NULL; - zval *zconn; - int count =3D -1; - int expectedcount =3D -1; - char **names; - int i; - - GET_CONNECTION_FROM_ARGS("r", &zconn); - - if ((expectedcount =3D virConnectNumOfStoragePools(conn->conn)) < 0) - RETURN_FALSE; - - names =3D (char **)emalloc(expectedcount*sizeof(char *)); - count =3D virConnectListStoragePools(conn->conn, names, expectedcount); - - if ((count !=3D expectedcount) || (count < 0)) { - efree(names); - RETURN_FALSE; - } - - array_init(return_value); - for (i =3D 0; i < count; i++) { - VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]); - free(names[i]); - } - efree(names); - - - if ((expectedcount =3D virConnectNumOfDefinedStoragePools(conn->conn))= < 0) - RETURN_FALSE; - names =3D (char **)emalloc(expectedcount * sizeof(char *)); - count =3D virConnectListDefinedStoragePools(conn->conn, names, expecte= dcount); - if ((count !=3D expectedcount) || (count < 0)) { - efree(names); - RETURN_FALSE; - } - - for (i =3D 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 c= onnection - * Arguments: @res [resource]: libvirt connection resource - * Returns: libvirt storagepool names array for the connection - */ -PHP_FUNCTION(libvirt_list_active_storagepools) -{ - php_libvirt_connection *conn =3D NULL; - zval *zconn; - int count =3D -1; - int expectedcount =3D -1; - char **names; - int i; - - GET_CONNECTION_FROM_ARGS("r", &zconn); - - if ((expectedcount =3D virConnectNumOfStoragePools(conn->conn)) < 0) - RETURN_FALSE; - - names =3D (char **)emalloc(expectedcount*sizeof(char *)); - count =3D virConnectListStoragePools(conn->conn, names, expectedcount); - - if ((count !=3D expectedcount) || (count < 0)) { - efree(names); - RETURN_FALSE; - } - array_init(return_value); - for (i =3D 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 =3D NULL; - zval *zconn; - int count =3D -1; - int expectedcount =3D -1; - char **names; - int i; - - GET_CONNECTION_FROM_ARGS("r", &zconn); - - if ((expectedcount =3D virConnectNumOfDefinedStoragePools(conn->conn))= < 0) - RETURN_FALSE; - - names =3D (char **)emalloc(expectedcount * sizeof(char *)); - count =3D virConnectListDefinedStoragePools(conn->conn, names, expecte= dcount); - if ((count !=3D expectedcount) || (count < 0)) { - efree(names); - RETURN_FALSE; - } - - array_init(return_value); - for (i =3D 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; =20 /* 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 =20 @@ -156,16 +154,6 @@ typedef struct _php_libvirt_nodedev { php_libvirt_connection* conn; } php_libvirt_nodedev; =20 -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); =20 -#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 + +#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 =3D (php_libvirt_storagepool *)rsrc->ptr; + int rv =3D 0; + + if (pool !=3D NULL) { + if (pool->pool !=3D NULL) { + if (!check_resource_allocation(NULL, INT_RESOURCE_STORAGEPOOL,= pool->pool TSRMLS_CC)) { + pool->pool =3D NULL; + efree(pool); + return; + } + rv =3D virStoragePoolFree(pool->pool); + if (rv !=3D 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, "virStoragePoo= lFree 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, po= ol->pool, 0 TSRMLS_CC); + } + pool->pool =3D NULL; + } + efree(pool); + } +} + +void +php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC) +{ + php_libvirt_volume *volume =3D (php_libvirt_volume *)rsrc->ptr; + int rv =3D 0; + + if (volume !=3D NULL) { + if (volume->volume !=3D NULL) { + if (!check_resource_allocation(NULL, INT_RESOURCE_VOLUME, volu= me->volume TSRMLS_CC)) { + volume->volume =3D NULL; + efree(volume); + return; + } + rv =3D virStorageVolFree(volume->volume); + if (rv !=3D 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, "virStorageVol= Free 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 =3D 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 na= me + * 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 =3D NULL; + zval *zconn; + strsize_t name_len; + char *name =3D NULL; + virStoragePoolPtr pool =3D NULL; + php_libvirt_storagepool *res_pool; + + GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len); + + if ((name =3D=3D NULL) || (name_len < 1)) + RETURN_FALSE; + pool =3D virStoragePoolLookupByName(conn->conn, name); + DPRINTF("%s: virStoragePoolLookupByName(%p, %s) returned %p\n", PHPFUN= C, conn->conn, name, pool); + if (pool =3D=3D NULL) + RETURN_FALSE; + + res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); + res_pool->pool =3D pool; + res_pool->conn =3D 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 =3D NULL; + php_libvirt_storagepool *res_pool; + + GET_VOLUME_FROM_ARGS("r", &zvolume); + + pool =3D virStoragePoolLookupByVolume(volume->volume); + DPRINTF("%s: virStoragePoolLookupByVolume(%p) returned %p\n", PHPFUNC,= volume->volume, pool); + if (pool =3D=3D NULL) + RETURN_FALSE; + + res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); + res_pool->pool =3D pool; + res_pool->conn =3D 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 stor= age 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 =3D NULL; + zval *zpool; + char **names =3D NULL; + int expectedcount =3D -1; + int i; + int count =3D -1; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + if ((expectedcount =3D virStoragePoolNumOfVolumes(pool->pool)) < 0) + RETURN_FALSE; + + DPRINTF("%s: virStoragePoolNumOfVolumes(%p) returned %d\n", PHPFUNC, p= ool->pool, expectedcount); + names =3D (char **)emalloc(expectedcount*sizeof(char *)); + + count =3D virStoragePoolListVolumes(pool->pool, names, expectedcount); + DPRINTF("%s: virStoragePoolListVolumes(%p, %p, %d) returned %d\n", PHP= FUNC, pool->pool, names, expectedcount, count); + array_init(return_value); + + if ((count !=3D expectedcount) || (count < 0)) + RETURN_FALSE; + for (i =3D 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, all= ocation and available space + */ +PHP_FUNCTION(libvirt_storagepool_get_info) +{ + php_libvirt_storagepool *pool =3D NULL; + zval *zpool; + virStoragePoolInfo poolInfo; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolGetInfo(pool->pool, &poolInfo); + DPRINTF("%s: virStoragePoolGetInfo(%p, ) returned %d\n", PHPFUNC= , pool->pool, retval); + if (retval !=3D 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 =3D NULL; + zval *zpool; + char *uuid; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + uuid =3D (char *)emalloc(VIR_UUID_STRING_BUFLEN); + retval =3D virStoragePoolGetUUIDString(pool->pool, uuid); + DPRINTF("%s: virStoragePoolGetUUIDString(%p, %p) returned %d (%s)\n", = PHPFUNC, pool->pool, uuid, retval, uuid); + if (retval !=3D 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 sto= rage pool resource + * Arguments: @res [resource]: libvirt storagepool resource + * Returns: storagepool name string + */ +PHP_FUNCTION(libvirt_storagepool_get_name) +{ + php_libvirt_storagepool *pool =3D NULL; + zval *zpool; + const char *name =3D NULL; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + name =3D virStoragePoolGetName(pool->pool); + DPRINTF("%s: virStoragePoolGetName(%p) returned %s\n", PHPFUNC, pool->= pool, name); + if (name =3D=3D 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 =3D NULL; + zval *zconn; + char *uuid =3D NULL; + strsize_t uuid_len; + virStoragePoolPtr storage =3D NULL; + php_libvirt_storagepool *res_pool; + + GET_CONNECTION_FROM_ARGS("rs", &zconn, &uuid, &uuid_len); + + if ((uuid =3D=3D NULL) || (uuid_len < 1)) + RETURN_FALSE; + + storage =3D virStoragePoolLookupByUUIDString(conn->conn, uuid); + DPRINTF("%s: virStoragePoolLookupByUUIDString(%p, %s) returned %p\n", = PHPFUNC, conn->conn, uuid, storage); + if (storage =3D=3D NULL) + RETURN_FALSE; + + res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); + res_pool->pool =3D storage; + res_pool->conn =3D 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 st= orage pool identified by res + * Arguments: @res [resource]: libvirt storagepool resource + * @xpath [string]: optional xPath expression string to g= et 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 =3D NULL; + zval *zpool; + char *xml; + char *xpath =3D NULL; + char *tmp =3D NULL; + zend_long flags =3D 0; + strsize_t xpath_len; + int retval =3D -1; + + GET_STORAGEPOOL_FROM_ARGS("r|s", &zpool, &xpath, &xpath_len, &flags); + if (xpath_len < 1) + xpath =3D NULL; + + DPRINTF("%s: pool =3D %p, flags =3D %ld, xpath =3D %s\n", PHPFUNC, poo= l->pool, flags, xpath); + + xml =3D virStoragePoolGetXMLDesc(pool->pool, flags); + if (xml =3D=3D NULL) { + set_error_if_unset("Cannot get the XML description" TSRMLS_CC); + RETURN_FALSE; + } + + tmp =3D get_string_from_xpath(xml, xpath, NULL, &retval); + if ((tmp =3D=3D 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 s= tring 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 =3D NULL; + php_libvirt_connection *conn =3D NULL; + zval *zconn; + virStoragePoolPtr pool =3D NULL; + char *xml; + strsize_t xml_len; + zend_long flags =3D 0; + + + GET_CONNECTION_FROM_ARGS("rs|l", &zconn, &xml, &xml_len, &flags); + + pool =3D virStoragePoolDefineXML(conn->conn, xml, (unsigned int)flags); + DPRINTF("%s: virStoragePoolDefineXML(%p, ) returned %p\n", PHPFUN= C, conn->conn, pool); + if (pool =3D=3D NULL) + RETURN_FALSE; + + res_pool =3D (php_libvirt_storagepool *)emalloc(sizeof(php_libvirt_sto= ragepool)); + res_pool->pool =3D pool; + res_pool->conn =3D 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 identifi= ed 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 =3D NULL; + zval *zpool; + int retval =3D 0; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolUndefine(pool->pool); + DPRINTF("%s: virStoragePoolUndefine(%p) returned %d\n", PHPFUNC, pool-= >pool, retval); + if (retval !=3D 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 =3D NULL; + zval *zpool; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolCreate(pool->pool, 0); + DPRINTF("%s: virStoragePoolCreate(%p, 0) returned %d\n", PHPFUNC, pool= ->pool, retval); + if (retval !=3D 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 =3D NULL; + zval *zpool; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolDestroy(pool->pool); + DPRINTF("%s: virStoragePoolDestroy(%p) returned %d\n", PHPFUNC, pool->= pool, retval); + if (retval !=3D 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 po= ol is active or not + * Arguments: @res [resource]: libvirt storagepool resource + * Returns: result of virStoragePoolIsActive + */ +PHP_FUNCTION(libvirt_storagepool_is_active) +{ + php_libvirt_storagepool *pool =3D 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 st= orage 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 =3D 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 informati= on + * 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 =3D NULL; + zval *zpool; + zend_long flags =3D 0; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r|l", &zpool, &flags); + + retval =3D virStoragePoolRefresh(pool->pool, flags); + DPRINTF("%s: virStoragePoolRefresh(%p, %ld) returned %d\n", PHPFUNC, p= ool->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 =3D NULL; + zval *zpool; + zend_bool flags =3D 0; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("rb", &zpool, &flags); + + retval =3D virStoragePoolSetAutostart(pool->pool, flags); + DPRINTF("%s: virStoragePoolSetAutostart(%p, %d) returned %d\n", PHPFUN= C, pool->pool, flags, retval); + if (retval !=3D 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 disabl= ed, FALSE with last_error set for error + */ +PHP_FUNCTION(libvirt_storagepool_get_autostart) +{ + php_libvirt_storagepool *pool =3D NULL; + zval *zpool; + int autostart; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + if (virStoragePoolGetAutostart(pool->pool, &autostart) =3D=3D 0 && + autostart !=3D 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 =3D NULL; + zval *zpool; + int flags =3D 0; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolBuild(pool->pool, flags); + DPRINTF("%s: virStoragePoolBuild(%p, %d) returned %d\n", PHPFUNC, pool= ->pool, flags, retval); + if (retval =3D=3D 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 =3D NULL; + zval *zpool; + int flags =3D 0; + int retval; + + GET_STORAGEPOOL_FROM_ARGS("r", &zpool); + + retval =3D virStoragePoolDelete(pool->pool, flags); + DPRINTF("%s: virStoragePoolDelete(%p, %d) returned %d\n", PHPFUNC, poo= l->pool, flags, retval); + if (retval =3D=3D 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 =3D NULL; + php_libvirt_volume *res_volume; + zval *zpool; + strsize_t name_len; + char *name =3D NULL; + virStorageVolPtr volume =3D NULL; + + GET_STORAGEPOOL_FROM_ARGS("rs", &zpool, &name, &name_len); + if ((name =3D=3D NULL) || (name_len < 1)) + RETURN_FALSE; + + volume =3D virStorageVolLookupByName(pool->pool, name); + DPRINTF("%s: virStorageVolLookupByName(%p, %s) returned %p\n", PHPFUNC= , pool->pool, name, volume); + if (volume =3D=3D NULL) + RETURN_FALSE; + + res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); + res_volume->volume =3D volume; + res_volume->conn =3D pool->conn; + + DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); + resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 =3D NULL; + php_libvirt_volume *res_volume; + zval *zconn; + strsize_t name_len; + char *name =3D NULL; + virStorageVolPtr volume =3D NULL; + + GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len); + if ((name =3D=3D NULL) || (name_len < 1)) + RETURN_FALSE; + + volume =3D virStorageVolLookupByPath(conn->conn, name); + DPRINTF("%s: virStorageVolLookupByPath(%p, %s) returned %p\n", PHPFUNC= , conn->conn, name, volume); + if (volume =3D=3D NULL) { + set_error_if_unset("Cannot find storage volume on requested path" = TSRMLS_CC); + RETURN_FALSE; + } + + res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); + res_volume->volume =3D volume; + res_volume->conn =3D conn; + + DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); + resource_change_counter(INT_RESOURCE_VOLUME, conn->conn, res_volume->v= olume, 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 =3D NULL; + zval *zvolume; + const char *retval; + + GET_VOLUME_FROM_ARGS("r", &zvolume); + + retval =3D virStorageVolGetName(volume->volume); + DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume-= >volume, retval); + if (retval =3D=3D 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 =3D NULL; + zval *zvolume; + char *retval; + + GET_VOLUME_FROM_ARGS("r", &zvolume); + + retval =3D virStorageVolGetPath(volume->volume); + DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume-= >volume, retval); + if (retval =3D=3D 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 a= nd capacity + */ +PHP_FUNCTION(libvirt_storagevolume_get_info) +{ + php_libvirt_volume *volume =3D NULL; + zval *zvolume; + virStorageVolInfo volumeInfo; + int retval; + + GET_VOLUME_FROM_ARGS("r", &zvolume); + + retval =3D virStorageVolGetInfo(volume->volume, &volumeInfo); + DPRINTF("%s: virStorageVolGetInfo(%p, ) returned %d\n", PHPFUNC,= volume->volume, retval); + if (retval !=3D 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 descrip= tion + * Arguments: @res [resource]: libvirt storagevolume resource + * @xpath [string]: optional xPath expression string to g= et just this entry, can be NULL + * @flags [int]: optional flags + * Returns: storagevolume XML description or result of xPath expre= ssion + */ +PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) +{ + php_libvirt_volume *volume =3D NULL; + zval *zvolume; + char *tmp =3D NULL; + char *xml; + char *xpath =3D NULL; + strsize_t xpath_len; + zend_long flags =3D 0; + int retval =3D -1; + + GET_VOLUME_FROM_ARGS("rs|l", &zvolume, &xpath, &xpath_len, &flags); + if (xpath_len < 1) + xpath =3D NULL; + + DPRINTF("%s: volume =3D %p, xpath =3D %s, flags =3D %ld\n", PHPFUNC, v= olume->volume, xpath, flags); + + xml =3D virStorageVolGetXMLDesc(volume->volume, flags); + if (xml =3D=3D NULL) { + set_error_if_unset("Cannot get the XML description" TSRMLS_CC); + RETURN_FALSE; + } + + tmp =3D get_string_from_xpath(xml, xpath, NULL, &retval); + if ((tmp =3D=3D 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 re= turn 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 =3D NULL; + php_libvirt_storagepool *pool =3D NULL; + zval *zpool; + virStorageVolPtr volume =3D NULL; + char *xml; + zend_long flags =3D 0; + strsize_t xml_len; + + GET_STORAGEPOOL_FROM_ARGS("rs|l", &zpool, &xml, &xml_len, &flags); + + volume =3D virStorageVolCreateXML(pool->pool, xml, flags); + DPRINTF("%s: virStorageVolCreateXML(%p, , 0) returned %p\n", PHPF= UNC, pool->pool, volume); + if (volume =3D=3D NULL) + RETURN_FALSE; + + res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); + res_volume->volume =3D volume; + res_volume->conn =3D pool->conn; + + DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); + resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 res= ource + * Returns: libvirt storagevolume resource + */ +PHP_FUNCTION(libvirt_storagevolume_create_xml_from) +{ + php_libvirt_volume *res_volume =3D NULL; + php_libvirt_storagepool *pool =3D NULL; + zval *zpool; + + php_libvirt_volume *pl_volume =3D NULL; + zval *zvolume; + + virStorageVolPtr volume =3D NULL; + char *xml; + strsize_t xml_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &x= ml, &xml_len, &zvolume) =3D=3D FAILURE) { + set_error("Invalid pool resource, XML or volume resouce" TSRMLS_CC= ); + RETURN_FALSE; + } + + VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIR= T_STORAGEPOOL_RES_NAME, le_libvirt_storagepool); + if ((pool =3D=3D NULL) || (pool->pool =3D=3D NULL)) + RETURN_FALSE; + VIRT_FETCH_RESOURCE(pl_volume, php_libvirt_volume*, &zvolume, PHP_LIBV= IRT_VOLUME_RES_NAME, le_libvirt_volume); + if ((pl_volume =3D=3D NULL) || (pl_volume->volume =3D=3D NULL)) + RETURN_FALSE; + resource_change_counter(INT_RESOURCE_VOLUME, NULL, pl_volume->volume, = 1 TSRMLS_CC); + + volume =3D virStorageVolCreateXMLFrom(pool->pool, xml, pl_volume->volu= me, 0); + DPRINTF("%s: virStorageVolCreateXMLFrom(%p, , %p, 0) returned %p\= n", PHPFUNC, pool->pool, pl_volume->volume, volume); + if (volume =3D=3D NULL) + RETURN_FALSE; + + res_volume =3D (php_libvirt_volume *)emalloc(sizeof(php_libvirt_volume= )); + res_volume->volume =3D volume; + res_volume->conn =3D pool->conn; + + DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); + resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_vol= ume->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 de= letion for virStorageVolDelete() + * Returns: TRUE for success, FALSE on error + */ +PHP_FUNCTION(libvirt_storagevolume_delete) +{ + php_libvirt_volume *volume =3D NULL; + zval *zvolume; + zend_long flags =3D 0; + int retval =3D 0; + + GET_VOLUME_FROM_ARGS("r|l", &zvolume, &flags); + + retval =3D virStorageVolDelete(volume->volume, flags); + DPRINTF("%s: virStorageVolDelete(%p, %d) returned %d\n", PHPFUNC, volu= me->volume, (int) flags, retval); + if (retval !=3D 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 do= wnload for virStorageVolDownload() + * Returns: int + */ +PHP_FUNCTION(libvirt_storagevolume_download) +{ + php_libvirt_volume *volume =3D NULL; + php_libvirt_stream *stream =3D NULL; + zval *zvolume; + zval *zstream; + zend_long flags =3D 0; + zend_long offset =3D 0; + zend_long length =3D 0; + int retval =3D -1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvol= ume, &zstream, &offset, &length, &flags) =3D=3D FAILURE) + RETURN_LONG(retval); + VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT= _VOLUME_RES_NAME, le_libvirt_volume); + if ((volume =3D=3D NULL) || (volume->volume =3D=3D NULL)) + RETURN_LONG(retval); + VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT= _STREAM_RES_NAME, le_libvirt_stream); + if ((stream =3D=3D NULL) || (stream->stream =3D=3D NULL)) + RETURN_LONG(retval); + + retval =3D virStorageVolDownload(volume->volume, stream->stream, offse= t, 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 =3D=3D -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 r= esource + * 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 up= load for virStorageVolUpload() + * Returns: int + */ +PHP_FUNCTION(libvirt_storagevolume_upload) +{ + php_libvirt_volume *volume =3D NULL; + php_libvirt_stream *stream =3D NULL; + zval *zvolume; + zval *zstream; + zend_long flags =3D 0; + zend_long offset =3D 0; + zend_long length =3D 0; + int retval =3D -1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvol= ume, &zstream, &offset, &length, &flags) =3D=3D FAILURE) + RETURN_LONG(retval); + VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT= _VOLUME_RES_NAME, le_libvirt_volume); + if ((volume =3D=3D NULL) || (volume->volume =3D=3D NULL)) + RETURN_LONG(retval); + VIRT_FETCH_RESOURCE(stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT= _STREAM_RES_NAME, le_libvirt_stream); + if ((stream =3D=3D NULL) || (stream->stream =3D=3D NULL)) + RETURN_LONG(retval); + + retval =3D virStorageVolUpload(volume->volume, stream->stream, offset,= length, flags); + DPRINTF("%s: virStorageVolUpload(%p, %p, %d, %d, %d) returned %d\n", P= HPFUNC, volume->volume, stream->stream, (int) offset, (int) length, (int) f= lags, retval); + + if (retval =3D=3D -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 r= esource + * Arguments: @res [resource]: libvirt storagevolume resource + * @capacity [int]: capacity for the storage volume + * @flags [int]: optional flags for the storage volume re= size for virStorageVolResize() + * Returns: int + */ +PHP_FUNCTION(libvirt_storagevolume_resize) +{ + php_libvirt_volume *volume =3D NULL; + zval *zvolume; + zend_long flags =3D 0; + zend_long capacity =3D 0; + int retval =3D -1; + + GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags); + + retval =3D virStorageVolResize(volume->volume, capacity, flags); + DPRINTF("%s: virStorageVolResize(%p, %d, %d) returned %d\n", PHPFUNC, = volume->volume, (int) capacity, (int) flags, retval); + if (retval !=3D 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 connecti= on + * Arguments: @res [resource]: libvirt connection resource + * Returns: libvirt storagepool names array for the connection + */ +PHP_FUNCTION(libvirt_list_storagepools) +{ + php_libvirt_connection *conn =3D NULL; + zval *zconn; + int count =3D -1; + int expectedcount =3D -1; + char **names; + int i; + + GET_CONNECTION_FROM_ARGS("r", &zconn); + + if ((expectedcount =3D virConnectNumOfStoragePools(conn->conn)) < 0) + RETURN_FALSE; + + names =3D (char **)emalloc(expectedcount*sizeof(char *)); + count =3D virConnectListStoragePools(conn->conn, names, expectedcount); + + if ((count !=3D expectedcount) || (count < 0)) { + efree(names); + RETURN_FALSE; + } + + array_init(return_value); + for (i =3D 0; i < count; i++) { + VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]); + free(names[i]); + } + efree(names); + + + if ((expectedcount =3D virConnectNumOfDefinedStoragePools(conn->conn))= < 0) + RETURN_FALSE; + names =3D (char **)emalloc(expectedcount * sizeof(char *)); + count =3D virConnectListDefinedStoragePools(conn->conn, names, expecte= dcount); + if ((count !=3D expectedcount) || (count < 0)) { + efree(names); + RETURN_FALSE; + } + + for (i =3D 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 c= onnection + * Arguments: @res [resource]: libvirt connection resource + * Returns: libvirt storagepool names array for the connection + */ +PHP_FUNCTION(libvirt_list_active_storagepools) +{ + php_libvirt_connection *conn =3D NULL; + zval *zconn; + int count =3D -1; + int expectedcount =3D -1; + char **names; + int i; + + GET_CONNECTION_FROM_ARGS("r", &zconn); + + if ((expectedcount =3D virConnectNumOfStoragePools(conn->conn)) < 0) + RETURN_FALSE; + + names =3D (char **)emalloc(expectedcount*sizeof(char *)); + count =3D virConnectListStoragePools(conn->conn, names, expectedcount); + + if ((count !=3D expectedcount) || (count < 0)) { + efree(names); + RETURN_FALSE; + } + array_init(return_value); + for (i =3D 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 =3D NULL; + zval *zconn; + int count =3D -1; + int expectedcount =3D -1; + char **names; + int i; + + GET_CONNECTION_FROM_ARGS("r", &zconn); + + if ((expectedcount =3D virConnectNumOfDefinedStoragePools(conn->conn))= < 0) + RETURN_FALSE; + + names =3D (char **)emalloc(expectedcount * sizeof(char *)); + count =3D virConnectListDefinedStoragePools(conn->conn, names, expecte= dcount); + if ((count !=3D expectedcount) || (count < 0)) { + efree(names); + RETURN_FALSE; + } + + array_init(return_value); + for (i =3D 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_stor= agepool_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_stor= agevolume_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_stor= agevolume_get_xml_desc) \ + PHP_FE(libvirt_storagevolume_create_xml, arginfo_libvirt_conn= _xml) \ + PHP_FE(libvirt_storagevolume_create_xml_from, arginfo_libvirt_stor= agevolume_create_xml_from) \ + PHP_FE(libvirt_storagevolume_delete, arginfo_libvirt_conn= _optflags) \ + PHP_FE(libvirt_storagevolume_download, arginfo_libvirt_stor= agevolume_download) \ + PHP_FE(libvirt_storagevolume_upload, arginfo_libvirt_stor= agevolume_download) \ + PHP_FE(libvirt_storagevolume_resize, arginfo_libvirt_stor= agevolume_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__) =3D=3D 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 =3D=3D NULL) || (pool->pool =3D=3D 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__) =3D=3D 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 =3D=3D NULL) || (volume->volume =3D=3D 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 --=20 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list