On 06/22/2017 09:14 PM, Dawid Zamirski wrote:
---
src/libvirt-php.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
src/libvirt-php.h | 7 +++++++
2 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 7784450..535d321 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -54,6 +54,7 @@ int le_libvirt_network;
int le_libvirt_nodedev;
int le_libvirt_stream;
int le_libvirt_snapshot;
+int le_libvirt_nwfilter;
ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect, 0, 0, 0)
ZEND_ARG_INFO(0, url)
@@ -823,6 +824,8 @@ translate_counter_type(int type)
return "storage volume";
case INT_RESOURCE_SNAPSHOT:
return "snapshot";
+ case INT_RESOURCE_NWFILTER:
+ return "nwfilter";
}
return "unknown";
@@ -1226,6 +1229,17 @@ void free_resource(int type, void *mem TSRMLS_DC)
resource_change_counter(INT_RESOURCE_SNAPSHOT, NULL,
(virDomainSnapshotPtr)mem, 0 TSRMLS_CC);
}
}
+
+ if (type == INT_RESOURCE_NWFILTER) {
+ rv = virNWFilterFree((virNWFilterPtr) mem);
+ if (rv != 0) {
+ DPRINTF("%s: virNWFilterFree(%p) returned %d (%s)\n",
__FUNCTION__, (virNWFilterPtr) mem, rv, LIBVIRT_G(last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "virDomainSnapshotFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+ } else {
+ DPRINTF("%s: virNWFilterFree(%p) completed successfully\n",
__FUNCTION__, (virNWFilterPtr) mem);
+ resource_change_counter(INT_RESOURCE_NWFILTER, NULL, (virNWFilterPtr) mem, 0
TSRMLS_CC);
+ }
+ }
}
/*
@@ -1570,7 +1584,7 @@ static void php_libvirt_snapshot_dtor(virt_resource *rsrc
TSRMLS_DC)
rv = virDomainSnapshotFree(snapshot->snapshot);
if (rv != 0) {
DPRINTF("%s: virDomainSnapshotFree(%p) returned %d\n",
__FUNCTION__, snapshot->snapshot, rv);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "virDomainSnapshotFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
} else {
DPRINTF("%s: virDomainSnapshotFree(%p) completed
successfully\n", __FUNCTION__, snapshot->snapshot);
resource_change_counter(INT_RESOURCE_SNAPSHOT,
snapshot->domain->conn->conn, snapshot->snapshot, 0 TSRMLS_CC);
@@ -1581,6 +1595,34 @@ static void php_libvirt_snapshot_dtor(virt_resource *rsrc
TSRMLS_DC)
}
}
+/* Destructor for nwfilter resource */
+static void php_libvirt_nwfilter_dtor(virt_resource *rsrc)
Missing TSRMLS_DC after @rsrc. I'll fix this before pushing.
+{
+ php_libvirt_nwfilter *nwfilter = (php_libvirt_nwfilter *) rsrc->ptr;
+ int rv = 0;
+
+ if (nwfilter != NULL) {
+ if (nwfilter->nwfilter != NULL) {
+ if (!check_resource_allocation(NULL, INT_RESOURCE_NWFILTER,
nwfilter->nwfilter TSRMLS_CC)) {
+ nwfilter->nwfilter = NULL;
+ efree(nwfilter);
+
+ return;
+ }
+ rv = virNWFilterFree(nwfilter->nwfilter);
+ if (rv != 0) {
+ DPRINTF("%s: virNWFilterFree(%p) returned %d\n", __FUNCTION__,
nwfilter->nwfilter, rv);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "virNWFilterFree failed
with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+ } else {
+ DPRINTF("%s: virNWFilterFee(%p) completed successfully\n",
__FUNCTION__, nwfilter->nwfilter);
+ resource_change_counter(INT_RESOURCE_NWFILTER,
nwfilter->conn->conn, nwfilter->nwfilter, 0 TSRMLS_CC);
+ }
+ nwfilter->nwfilter = NULL;
+ }
+ efree(nwfilter);
+ }
+}
+
Michal