[libvirt-php PATCH v2 03/11] Split up the bindings for libvirt node API

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

 



---
 src/Makefile.am          |   3 +-
 src/libvirt-connection.c |   1 +
 src/libvirt-connection.h |   2 -
 src/libvirt-node.c       | 305 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt-node.h       |  23 ++++
 src/libvirt-php.c        | 322 +----------------------------------------------
 src/libvirt-php.h        |   6 -
 src/util.h               |  25 ++++
 8 files changed, 358 insertions(+), 329 deletions(-)
 create mode 100644 src/libvirt-node.c
 create mode 100644 src/libvirt-node.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 0819dc6..ba2be62 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,7 +22,8 @@ libvirt_php_la_SOURCES = \
 	vncfunc.c vncfunc.h	\
 	sockets.c sockets.h \
 	libvirt-php.c libvirt-php.h \
-	libvirt-connection.c libvirt-connection.h
+	libvirt-connection.c libvirt-connection.h \
+	libvirt-node.c libvirt-node.h
 libvirt_php_la_CFLAGS = \
 	$(AM_CFLAGS) \
 	-DCOMPILE_DL_LIBVIRT=1
diff --git a/src/libvirt-connection.c b/src/libvirt-connection.c
index bcebd44..7e72333 100644
--- a/src/libvirt-connection.c
+++ b/src/libvirt-connection.c
@@ -6,6 +6,7 @@
 
 #include <libvirt/libvirt.h>
 
+#include "libvirt-php.h"
 #include "libvirt-connection.h"
 
 DEBUG_INIT("connection");
diff --git a/src/libvirt-connection.h b/src/libvirt-connection.h
index 2c50ec9..0cae5ec 100644
--- a/src/libvirt-connection.h
+++ b/src/libvirt-connection.h
@@ -7,8 +7,6 @@
 #ifndef __LIBVIRT_CONNECTION_H__
 # define __LIBVIRT_CONNECTION_H__
 
-# include "util.h"
-
 # define PHP_LIBVIRT_CONNECTION_RES_NAME "Libvirt connection"
 # define INT_RESOURCE_CONNECTION 0x01
 # define CONNECT_FLAG_SOUNDHW_GET_NAMES  0x01
diff --git a/src/libvirt-node.c b/src/libvirt-node.c
new file mode 100644
index 0000000..e578802
--- /dev/null
+++ b/src/libvirt-node.c
@@ -0,0 +1,305 @@
+/*
+ * libvirt-node.c: The PHP bindings to libvirt connection API
+ *
+ * See COPYING for the license of this software
+ */
+
+#include <libvirt/libvirt.h>
+
+#include "libvirt-php.h"
+#include "libvirt-connection.h"
+#include "libvirt-node.h"
+
+DEBUG_INIT("node");
+
+/*
+ * Function name:   libvirt_node_get_info
+ * Since version:   0.4.1(-1)
+ * Description:     Function is used to get the information about host node, mainly total memory installed, total CPUs installed and model information are useful
+ * Arguments:       @conn [resource]: resource for connection
+ * Returns:         array of node information or FALSE for error
+ */
+PHP_FUNCTION(libvirt_node_get_info)
+{
+    virNodeInfo info;
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int retval;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    retval = virNodeGetInfo   (conn->conn, &info);
+    DPRINTF("%s: virNodeGetInfo returned %d\n", PHPFUNC, retval);
+    if (retval == -1)
+        RETURN_FALSE;
+
+    array_init(return_value);
+    VIRT_ADD_ASSOC_STRING(return_value, "model", info.model);
+    add_assoc_long(return_value, "memory", (long)info.memory);
+    add_assoc_long(return_value, "cpus", (long)info.cpus);
+    add_assoc_long(return_value, "nodes", (long)info.nodes);
+    add_assoc_long(return_value, "sockets", (long)info.sockets);
+    add_assoc_long(return_value, "cores", (long)info.cores);
+    add_assoc_long(return_value, "threads", (long)info.threads);
+    add_assoc_long(return_value, "mhz", (long)info.mhz);
+}
+
+/*
+ * Function name:   libvirt_node_get_cpu_stats
+ * Since version:   0.4.6
+ * Description:     Function is used to get the CPU stats per nodes
+ * Arguments:       @conn [resource]: resource for connection
+ *                  @cpunr [int]: CPU number to get information about, defaults to VIR_NODE_CPU_STATS_ALL_CPUS to get information about all CPUs
+ * Returns:         array of node CPU statistics including time (in seconds since UNIX epoch), cpu number and total number of CPUs on node or FALSE for error
+ */
+PHP_FUNCTION(libvirt_node_get_cpu_stats)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS;
+    virNodeCPUStatsPtr params;
+    virNodeInfo info;
+    zend_long cpunr = -1;
+    int nparams = 0;
+    int i, j, numCpus;
+
+    GET_CONNECTION_FROM_ARGS("r|l", &zconn, &cpunr);
+
+    if (virNodeGetInfo(conn->conn, &info) != 0) {
+        set_error("Cannot get number of CPUs" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    numCpus = info.cpus;
+    if (cpunr > numCpus - 1) {
+        char tmp[256] = { 0 };
+        snprintf(tmp, sizeof(tmp), "Invalid CPU number, valid numbers in range 0 to %d or VIR_NODE_CPU_STATS_ALL_CPUS",
+                 numCpus - 1);
+        set_error(tmp TSRMLS_CC);
+
+        RETURN_FALSE;
+    }
+
+    cpuNum = (int)cpunr;
+
+    if (virNodeGetCPUStats(conn->conn, cpuNum, NULL, &nparams, 0) != 0) {
+        set_error("Cannot get number of CPU stats" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    if (nparams == 0)
+        RETURN_TRUE;
+
+    DPRINTF("%s: Number of parameters got from virNodeGetCPUStats is %d\n", __FUNCTION__, nparams);
+
+    params = (virNodeCPUStatsPtr)calloc(nparams, nparams * sizeof(*params));
+
+    array_init(return_value);
+    for (i = 0; i < 2; i++) {
+        zval *arr;
+
+        if (i > 0)
+#ifdef EXTWIN
+            Sleep(1000);
+#else
+        sleep(1);
+#endif
+
+        if (virNodeGetCPUStats(conn->conn, cpuNum, params, &nparams, 0) != 0) {
+            set_error("Unable to get node cpu stats" TSRMLS_CC);
+            RETURN_FALSE;
+        }
+
+        VIRT_ARRAY_INIT(arr);
+
+        for (j = 0; j < nparams; j++) {
+            DPRINTF("%s: Field %s has value of %llu\n", __FUNCTION__, params[j].field, params[j].value);
+
+            add_assoc_long(arr, params[j].field, params[j].value);
+        }
+
+        add_assoc_long(arr, "time", time(NULL));
+
+        add_index_zval(return_value, i, arr);
+    }
+
+    add_assoc_long(return_value, "cpus", numCpus);
+    if (cpuNum >= 0) {
+        add_assoc_long(return_value, "cpu", cpunr);
+    } else {
+        if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS)
+            VIRT_ADD_ASSOC_STRING(return_value, "cpu", "all");
+        else
+            VIRT_ADD_ASSOC_STRING(return_value, "cpu", "unknown");
+    }
+
+    free(params);
+    params = NULL;
+}
+
+/*
+ * Function name:   libvirt_node_get_cpu_stats_for_each_cpu
+ * Since version:   0.4.6
+ * Description:     Function is used to get the CPU stats for each CPU on the host node
+ * Arguments:       @conn [resource]: resource for connection
+ *                  @time [int]: time in seconds to get the information about, without aggregation for further processing
+ * Returns:         array of node CPU statistics for each CPU including time (in seconds since UNIX epoch), cpu number and total number of CPUs on node or FALSE for error
+ */
+PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    virNodeCPUStatsPtr params;
+    virNodeInfo info;
+    int nparams = 0;
+    zend_long avg = 0, iter = 0;
+    int done = 0;
+    int i, j, numCpus;
+    time_t startTime = 0;
+    zval *time_array;
+
+    GET_CONNECTION_FROM_ARGS("r|l", &zconn, &avg);
+
+    if (virNodeGetInfo(conn->conn, &info) != 0) {
+        set_error("Cannot get number of CPUs" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    if (virNodeGetCPUStats(conn->conn, VIR_NODE_CPU_STATS_ALL_CPUS, NULL, &nparams, 0) != 0) {
+        set_error("Cannot get number of CPU stats" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    if (nparams == 0)
+        RETURN_TRUE;
+
+    DPRINTF("%s: Number of parameters got from virNodeGetCPUStats is %d\n", __FUNCTION__, nparams);
+
+    params = (virNodeCPUStatsPtr)calloc(nparams, nparams * sizeof(*params));
+
+    numCpus = info.cpus;
+    array_init(return_value);
+
+    startTime = time(NULL);
+
+    iter = 0;
+    done = 0;
+    while (!done) {
+        zval *arr;
+        VIRT_ARRAY_INIT(arr);
+
+        for (i = 0; i < numCpus; i++) {
+            zval *arr2;
+
+            if (virNodeGetCPUStats(conn->conn, i, params, &nparams, 0) != 0) {
+                set_error("Unable to get node cpu stats" TSRMLS_CC);
+                RETURN_FALSE;
+            }
+
+            VIRT_ARRAY_INIT(arr2);
+
+            for (j = 0; j < nparams; j++)
+                add_assoc_long(arr2, params[j].field, params[j].value);
+
+            add_assoc_long(arr, "time", time(NULL));
+            add_index_zval(arr, i, arr2);
+        }
+
+        add_index_zval(return_value, iter, arr);
+
+        if ((avg <= 0) || (iter == avg - 1)) {
+            done = 1;
+            break;
+        }
+
+#ifndef EXTWIN
+        sleep(1);
+#else
+        Sleep(1000);
+#endif
+        iter++;
+    }
+
+    VIRT_ARRAY_INIT(time_array);
+    add_assoc_long(time_array, "start", startTime);
+    add_assoc_long(time_array, "finish", time(NULL));
+    add_assoc_long(time_array, "duration", time(NULL) - startTime);
+
+    add_assoc_zval(return_value, "times", time_array);
+
+    free(params);
+    params = NULL;
+}
+
+/*
+ * Function name:   libvirt_node_get_mem_stats
+ * Since version:   0.4.6
+ * Description:     Function is used to get the memory stats per node
+ * Arguments:       @conn [resource]: resource for connection
+ * Returns:         array of node memory statistics including time (in seconds since UNIX epoch) or FALSE for error
+ */
+PHP_FUNCTION(libvirt_node_get_mem_stats)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    int memNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
+    virNodeMemoryStatsPtr params;
+    int nparams = 0;
+    int j;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    if (virNodeGetMemoryStats(conn->conn, memNum, NULL, &nparams, 0) != 0) {
+        set_error("Cannot get number of memory stats" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    if (nparams == 0)
+        RETURN_TRUE;
+
+    DPRINTF("%s: Number of parameters got from virNodeGetMemoryStats is %d\n", __FUNCTION__, nparams);
+
+    params = (virNodeMemoryStatsPtr)calloc(nparams, nparams * sizeof(*params));
+
+    array_init(return_value);
+    if (virNodeGetMemoryStats(conn->conn, memNum, params, &nparams, 0) != 0) {
+        set_error("Unable to get node memory stats" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+
+    for (j = 0; j < nparams; j++) {
+        DPRINTF("%s: Field %s has value of %llu\n", __FUNCTION__, params[j].field, params[j].value);
+
+        add_assoc_long(return_value, params[j].field, params[j].value);
+    }
+
+    add_assoc_long(return_value, "time", time(NULL));
+
+    free(params);
+    params = NULL;
+}
+
+/*
+ * Function name:   libvirt_node_get_free_memory
+ * Since version:   0.5.3
+ * Description:     Function is used to get free memory available on the node.
+ * Arguments:       @conn [resource]: resource for connection.
+ * Returns:         The available free memery in bytes as string or FALSE for error.
+ */
+PHP_FUNCTION(libvirt_node_get_free_memory)
+{
+    php_libvirt_connection *conn = NULL;
+    zval *zconn;
+    unsigned long long ret;
+    LONGLONG_INIT;
+
+    GET_CONNECTION_FROM_ARGS("r", &zconn);
+
+    if ((ret = virNodeGetFreeMemory(conn->conn)) != 0) {
+        LONGLONG_RETURN_AS_STRING(ret);
+    } else {
+        set_error("Cannot get the free memory for the node" TSRMLS_CC);
+        RETURN_FALSE;
+    }
+}
+
diff --git a/src/libvirt-node.h b/src/libvirt-node.h
new file mode 100644
index 0000000..650283e
--- /dev/null
+++ b/src/libvirt-node.h
@@ -0,0 +1,23 @@
+/*
+ * libvirt-node.h: The PHP bindings to libvirt node API
+ *
+ * See COPYING for the license of this software
+ */
+
+#ifndef __LIBVIRT_NODE_H__
+# define __LIBVIRT_NODE_H__
+
+# define PHP_FE_LIBVIRT_NODE                                                       \
+    PHP_FE(libvirt_node_get_info,                   arginfo_libvirt_conn)          \
+    PHP_FE(libvirt_node_get_cpu_stats,              arginfo_libvirt_conn_optcpunr) \
+    PHP_FE(libvirt_node_get_cpu_stats_for_each_cpu, arginfo_libvirt_conn_opttime)  \
+    PHP_FE(libvirt_node_get_mem_stats,              arginfo_libvirt_conn)          \
+    PHP_FE(libvirt_node_get_free_memory,            arginfo_libvirt_conn)
+
+PHP_FUNCTION(libvirt_node_get_info);
+PHP_FUNCTION(libvirt_node_get_cpu_stats);
+PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu);
+PHP_FUNCTION(libvirt_node_get_mem_stats);
+PHP_FUNCTION(libvirt_node_get_free_memory);
+
+#endif
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index c439e24..6315ec4 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -20,6 +20,7 @@
 #include "vncfunc.h"
 #include "sockets.h"
 #include "libvirt-connection.h"
+#include "libvirt-node.h"
 
 DEBUG_INIT("core");
 
@@ -609,11 +610,7 @@ static zend_function_entry libvirt_functions[] = {
     PHP_FE(libvirt_network_get_autostart,        arginfo_libvirt_conn)
     PHP_FE(libvirt_network_set_autostart,        arginfo_libvirt_conn_flags)
     /* Node functions */
-    PHP_FE(libvirt_node_get_info,                arginfo_libvirt_conn)
-    PHP_FE(libvirt_node_get_cpu_stats,           arginfo_libvirt_conn_optcpunr)
-    PHP_FE(libvirt_node_get_cpu_stats_for_each_cpu, arginfo_libvirt_conn_opttime)
-    PHP_FE(libvirt_node_get_mem_stats,           arginfo_libvirt_conn)
-    PHP_FE(libvirt_node_get_free_memory,         arginfo_libvirt_conn)
+    PHP_FE_LIBVIRT_NODE
     /* Nodedev functions */
     PHP_FE(libvirt_nodedev_get,                  arginfo_libvirt_conn)
     PHP_FE(libvirt_nodedev_capabilities,         arginfo_libvirt_conn)
@@ -1967,30 +1964,6 @@ PHP_MSHUTDOWN_FUNCTION(libvirt)
             RETURN_FALSE;                                                                       \
     } while (0)                                                                                 \
 
-#define LONGLONG_INIT \
-    char tmpnumber[64]
-
-#define LONGLONG_ASSOC(out, key, in)                        \
-    if (LIBVIRT_G(longlong_to_string_ini)) {                \
-        snprintf(tmpnumber, 63, "%llu", in);                \
-        VIRT_ADD_ASSOC_STRING(out, key, tmpnumber);         \
-    } else {                                                \
-        add_assoc_long(out, key, in);                       \
-    }
-
-#define LONGLONG_INDEX(out, key, in)                        \
-    if (LIBVIRT_G(longlong_to_string_ini)) {                \
-        snprintf(tmpnumber, 63, "%llu", in);                \
-        VIRT_ADD_INDEX_STRING(out, key, tmpnumber);         \
-    } else {                                                \
-        add_index_long(out, key, in);                       \
-    }
-
-#define LONGLONG_RETURN_AS_STRING(in)                       \
-    do {                                                    \
-        snprintf(tmpnumber, 63, "%llu", in);                \
-        VIRT_RETURN_STRING(tmpnumber);                      \
-    } while (0)
 
 /* Common functions */
 
@@ -2008,297 +1981,6 @@ PHP_FUNCTION(libvirt_get_last_error)
 }
 
 /*
- * Function name:   libvirt_node_get_info
- * Since version:   0.4.1(-1)
- * Description:     Function is used to get the information about host node, mainly total memory installed, total CPUs installed and model information are useful
- * Arguments:       @conn [resource]: resource for connection
- * Returns:         array of node information or FALSE for error
- */
-PHP_FUNCTION(libvirt_node_get_info)
-{
-    virNodeInfo info;
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int retval;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    retval = virNodeGetInfo   (conn->conn, &info);
-    DPRINTF("%s: virNodeGetInfo returned %d\n", PHPFUNC, retval);
-    if (retval == -1)
-        RETURN_FALSE;
-
-    array_init(return_value);
-    VIRT_ADD_ASSOC_STRING(return_value, "model", info.model);
-    add_assoc_long(return_value, "memory", (long)info.memory);
-    add_assoc_long(return_value, "cpus", (long)info.cpus);
-    add_assoc_long(return_value, "nodes", (long)info.nodes);
-    add_assoc_long(return_value, "sockets", (long)info.sockets);
-    add_assoc_long(return_value, "cores", (long)info.cores);
-    add_assoc_long(return_value, "threads", (long)info.threads);
-    add_assoc_long(return_value, "mhz", (long)info.mhz);
-}
-
-/*
- * Function name:   libvirt_node_get_cpu_stats
- * Since version:   0.4.6
- * Description:     Function is used to get the CPU stats per nodes
- * Arguments:       @conn [resource]: resource for connection
- *                  @cpunr [int]: CPU number to get information about, defaults to VIR_NODE_CPU_STATS_ALL_CPUS to get information about all CPUs
- * Returns:         array of node CPU statistics including time (in seconds since UNIX epoch), cpu number and total number of CPUs on node or FALSE for error
- */
-PHP_FUNCTION(libvirt_node_get_cpu_stats)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS;
-    virNodeCPUStatsPtr params;
-    virNodeInfo info;
-    zend_long cpunr = -1;
-    int nparams = 0;
-    int i, j, numCpus;
-
-    GET_CONNECTION_FROM_ARGS("r|l", &zconn, &cpunr);
-
-    if (virNodeGetInfo(conn->conn, &info) != 0) {
-        set_error("Cannot get number of CPUs" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    numCpus = info.cpus;
-    if (cpunr > numCpus - 1) {
-        char tmp[256] = { 0 };
-        snprintf(tmp, sizeof(tmp), "Invalid CPU number, valid numbers in range 0 to %d or VIR_NODE_CPU_STATS_ALL_CPUS",
-                 numCpus - 1);
-        set_error(tmp TSRMLS_CC);
-
-        RETURN_FALSE;
-    }
-
-    cpuNum = (int)cpunr;
-
-    if (virNodeGetCPUStats(conn->conn, cpuNum, NULL, &nparams, 0) != 0) {
-        set_error("Cannot get number of CPU stats" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    if (nparams == 0)
-        RETURN_TRUE;
-
-    DPRINTF("%s: Number of parameters got from virNodeGetCPUStats is %d\n", __FUNCTION__, nparams);
-
-    params = (virNodeCPUStatsPtr)calloc(nparams, nparams * sizeof(*params));
-
-    array_init(return_value);
-    for (i = 0; i < 2; i++) {
-        zval *arr;
-
-        if (i > 0)
-#ifdef EXTWIN
-            Sleep(1000);
-#else
-        sleep(1);
-#endif
-
-        if (virNodeGetCPUStats(conn->conn, cpuNum, params, &nparams, 0) != 0) {
-            set_error("Unable to get node cpu stats" TSRMLS_CC);
-            RETURN_FALSE;
-        }
-
-        VIRT_ARRAY_INIT(arr);
-
-        for (j = 0; j < nparams; j++) {
-            DPRINTF("%s: Field %s has value of %llu\n", __FUNCTION__, params[j].field, params[j].value);
-
-            add_assoc_long(arr, params[j].field, params[j].value);
-        }
-
-        add_assoc_long(arr, "time", time(NULL));
-
-        add_index_zval(return_value, i, arr);
-    }
-
-    add_assoc_long(return_value, "cpus", numCpus);
-    if (cpuNum >= 0) {
-        add_assoc_long(return_value, "cpu", cpunr);
-    } else {
-        if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS)
-            VIRT_ADD_ASSOC_STRING(return_value, "cpu", "all");
-        else
-            VIRT_ADD_ASSOC_STRING(return_value, "cpu", "unknown");
-    }
-
-    free(params);
-    params = NULL;
-}
-
-/*
- * Function name:   libvirt_node_get_cpu_stats_for_each_cpu
- * Since version:   0.4.6
- * Description:     Function is used to get the CPU stats for each CPU on the host node
- * Arguments:       @conn [resource]: resource for connection
- *                  @time [int]: time in seconds to get the information about, without aggregation for further processing
- * Returns:         array of node CPU statistics for each CPU including time (in seconds since UNIX epoch), cpu number and total number of CPUs on node or FALSE for error
- */
-PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    virNodeCPUStatsPtr params;
-    virNodeInfo info;
-    int nparams = 0;
-    zend_long avg = 0, iter = 0;
-    int done = 0;
-    int i, j, numCpus;
-    time_t startTime = 0;
-    zval *time_array;
-
-    GET_CONNECTION_FROM_ARGS("r|l", &zconn, &avg);
-
-    if (virNodeGetInfo(conn->conn, &info) != 0) {
-        set_error("Cannot get number of CPUs" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    if (virNodeGetCPUStats(conn->conn, VIR_NODE_CPU_STATS_ALL_CPUS, NULL, &nparams, 0) != 0) {
-        set_error("Cannot get number of CPU stats" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    if (nparams == 0)
-        RETURN_TRUE;
-
-    DPRINTF("%s: Number of parameters got from virNodeGetCPUStats is %d\n", __FUNCTION__, nparams);
-
-    params = (virNodeCPUStatsPtr)calloc(nparams, nparams * sizeof(*params));
-
-    numCpus = info.cpus;
-    array_init(return_value);
-
-    startTime = time(NULL);
-
-    iter = 0;
-    done = 0;
-    while (!done) {
-        zval *arr;
-        VIRT_ARRAY_INIT(arr);
-
-        for (i = 0; i < numCpus; i++) {
-            zval *arr2;
-
-            if (virNodeGetCPUStats(conn->conn, i, params, &nparams, 0) != 0) {
-                set_error("Unable to get node cpu stats" TSRMLS_CC);
-                RETURN_FALSE;
-            }
-
-            VIRT_ARRAY_INIT(arr2);
-
-            for (j = 0; j < nparams; j++)
-                add_assoc_long(arr2, params[j].field, params[j].value);
-
-            add_assoc_long(arr, "time", time(NULL));
-            add_index_zval(arr, i, arr2);
-        }
-
-        add_index_zval(return_value, iter, arr);
-
-        if ((avg <= 0) || (iter == avg - 1)) {
-            done = 1;
-            break;
-        }
-
-#ifndef EXTWIN
-        sleep(1);
-#else
-        Sleep(1000);
-#endif
-        iter++;
-    }
-
-    VIRT_ARRAY_INIT(time_array);
-    add_assoc_long(time_array, "start", startTime);
-    add_assoc_long(time_array, "finish", time(NULL));
-    add_assoc_long(time_array, "duration", time(NULL) - startTime);
-
-    add_assoc_zval(return_value, "times", time_array);
-
-    free(params);
-    params = NULL;
-}
-
-/*
- * Function name:   libvirt_node_get_mem_stats
- * Since version:   0.4.6
- * Description:     Function is used to get the memory stats per node
- * Arguments:       @conn [resource]: resource for connection
- * Returns:         array of node memory statistics including time (in seconds since UNIX epoch) or FALSE for error
- */
-PHP_FUNCTION(libvirt_node_get_mem_stats)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    int memNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
-    virNodeMemoryStatsPtr params;
-    int nparams = 0;
-    int j;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    if (virNodeGetMemoryStats(conn->conn, memNum, NULL, &nparams, 0) != 0) {
-        set_error("Cannot get number of memory stats" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    if (nparams == 0)
-        RETURN_TRUE;
-
-    DPRINTF("%s: Number of parameters got from virNodeGetMemoryStats is %d\n", __FUNCTION__, nparams);
-
-    params = (virNodeMemoryStatsPtr)calloc(nparams, nparams * sizeof(*params));
-
-    array_init(return_value);
-    if (virNodeGetMemoryStats(conn->conn, memNum, params, &nparams, 0) != 0) {
-        set_error("Unable to get node memory stats" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-
-    for (j = 0; j < nparams; j++) {
-        DPRINTF("%s: Field %s has value of %llu\n", __FUNCTION__, params[j].field, params[j].value);
-
-        add_assoc_long(return_value, params[j].field, params[j].value);
-    }
-
-    add_assoc_long(return_value, "time", time(NULL));
-
-    free(params);
-    params = NULL;
-}
-
-/*
- * Function name:   libvirt_node_get_free_memory
- * Since version:   0.5.3
- * Description:     Function is used to get free memory available on the node.
- * Arguments:       @conn [resource]: resource for connection.
- * Returns:         The available free memery in bytes as string or FALSE for error.
- */
-PHP_FUNCTION(libvirt_node_get_free_memory)
-{
-    php_libvirt_connection *conn = NULL;
-    zval *zconn;
-    unsigned long long ret;
-    LONGLONG_INIT;
-
-    GET_CONNECTION_FROM_ARGS("r", &zconn);
-
-    if ((ret = virNodeGetFreeMemory(conn->conn)) != 0) {
-        LONGLONG_RETURN_AS_STRING(ret);
-    } else {
-        set_error("Cannot get the free memory for the node" TSRMLS_CC);
-        RETURN_FALSE;
-    }
-}
-
-/*
  * Function name:   libvirt_image_create
  * Since version:   0.4.2
  * Description:     Function is used to create the image of desired name, size and format. The image will be created in the image path (libvirt.image_path INI variable). Works only o
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index 85fdae2..a701235 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -254,12 +254,6 @@ PHP_MINFO_FUNCTION(libvirt);
 
 /* Common functions */
 PHP_FUNCTION(libvirt_get_last_error);
-/* Node functions */
-PHP_FUNCTION(libvirt_node_get_info);
-PHP_FUNCTION(libvirt_node_get_cpu_stats);
-PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu);
-PHP_FUNCTION(libvirt_node_get_mem_stats);
-PHP_FUNCTION(libvirt_node_get_free_memory);
 /* Stream functions */
 PHP_FUNCTION(libvirt_stream_create);
 PHP_FUNCTION(libvirt_stream_close);
diff --git a/src/util.h b/src/util.h
index 17846a1..e664e26 100644
--- a/src/util.h
+++ b/src/util.h
@@ -225,6 +225,31 @@
 
 # endif /* PHP_MAJOR_VERSION < 7 */
 
+# define LONGLONG_INIT                                                         \
+    char tmpnumber[64]
+
+# define LONGLONG_ASSOC(out, key, in)                                          \
+    if (LIBVIRT_G(longlong_to_string_ini)) {                                   \
+        snprintf(tmpnumber, 63, "%llu", in);                                   \
+        VIRT_ADD_ASSOC_STRING(out, key, tmpnumber);                            \
+    } else {                                                                   \
+        add_assoc_long(out, key, in);                                          \
+    }
+
+# define LONGLONG_INDEX(out, key, in)                                          \
+    if (LIBVIRT_G(longlong_to_string_ini)) {                                   \
+        snprintf(tmpnumber, 63, "%llu", in);                                   \
+        VIRT_ADD_INDEX_STRING(out, key, tmpnumber);                            \
+    } else {                                                                   \
+        add_index_long(out, key, in);                                          \
+    }
+
+# define LONGLONG_RETURN_AS_STRING(in)                                         \
+    do {                                                                       \
+        snprintf(tmpnumber, 63, "%llu", in);                                   \
+        VIRT_RETURN_STRING(tmpnumber);                                         \
+    } while (0)
+
 # ifndef PHP_FE_END
 #  define PHP_FE_END {NULL, NULL, NULL}
 # endif
-- 
2.13.3

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



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