---
src/Makefile.am | 3 +-
src/libvirt-nodedev.c | 339 ++++++++++++++++++++++++++++++++++++++++++++++++
src/libvirt-nodedev.h | 54 ++++++++
src/libvirt-php.c | 353 +-------------------------------------------------
src/libvirt-php.h | 13 --
5 files changed, 398 insertions(+), 364 deletions(-)
create mode 100644 src/libvirt-nodedev.c
create mode 100644 src/libvirt-nodedev.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 1b78011..30bebad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,8 +27,9 @@ libvirt_php_la_SOURCES = \
libvirt-stream.c libvirt-stream.h \
libvirt-domain.c libvirt-domain.h \
libvirt-snapshot.c libvirt-snapshot.h \
+ libvirt-storage.c libvirt-storage.h \
libvirt-network.c libvirt-network.h \
- libvirt-storage.c libvirt-storage.h
+ libvirt-nodedev.c libvirt-nodedev.h
libvirt_php_la_CFLAGS = \
$(AM_CFLAGS) \
-DCOMPILE_DL_LIBVIRT=1
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
new file mode 100644
index 0000000..06a420d
--- /dev/null
+++ b/src/libvirt-nodedev.c
@@ -0,0 +1,339 @@
+/*
+ * libvirt-nodedev.c: The PHP bindings to libvirt nodedev API
+ *
+ * See COPYING for the license of this software
+ */
+
+#include <libvirt/libvirt.h>
+
+#include "libvirt-nodedev.h"
+
+DEBUG_INIT("nodedev");
+
+void
+php_libvirt_nodedev_dtor(virt_resource *rsrc TSRMLS_DC)
+{
+ php_libvirt_nodedev *nodedev = (php_libvirt_nodedev *)rsrc->ptr;
+ int rv = 0;
+
+ if (nodedev != NULL) {
+ if (nodedev->device != NULL) {
+ if (!check_resource_allocation(nodedev->conn->conn,
INT_RESOURCE_NODEDEV, nodedev->device TSRMLS_CC)) {
+ nodedev->device = NULL;
+ efree(nodedev);
+ return;
+ }
+ rv = virNodeDeviceFree(nodedev->device);
+ if (rv != 0) {
+ DPRINTF("%s: virNodeDeviceFree(%p) returned %d (%s)\n",
__FUNCTION__, nodedev->device, rv, LIBVIRT_G(last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+ } else {
+ DPRINTF("%s: virNodeDeviceFree(%p) completed successfully\n",
__FUNCTION__, nodedev->device);
+ resource_change_counter(INT_RESOURCE_NODEDEV, nodedev->conn->conn,
nodedev->device, 0 TSRMLS_CC);
+ }
+ nodedev->device = NULL;
+ }
+ efree(nodedev);
+ }
+}
+
+/*
+ * Function name: libvirt_nodedev_get
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the node device by it's name
+ * Arguments: @res [resource]: libvirt connection resource
+ * @name [string]: name of the nodedev to get resource
+ * Returns: libvirt nodedev resource
+ */
+PHP_FUNCTION(libvirt_nodedev_get)
+{
+ php_libvirt_connection *conn = NULL;
+ php_libvirt_nodedev *res_dev = NULL;
+ virNodeDevice *dev;
+ zval *zconn;
+ char *name;
+ strsize_t name_len;
+
+ GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
+
+ if ((dev = virNodeDeviceLookupByName(conn->conn, name)) == NULL) {
+ set_error("Cannot get find requested node device" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ res_dev = (php_libvirt_nodedev *)emalloc(sizeof(php_libvirt_nodedev));
+ res_dev->device = dev;
+ res_dev->conn = conn;
+
+ DPRINTF("%s: returning %p\n", PHPFUNC, res_dev->device);
+ resource_change_counter(INT_RESOURCE_NODEDEV, conn->conn, res_dev->device, 1
TSRMLS_CC);
+
+ VIRT_REGISTER_RESOURCE(res_dev, le_libvirt_nodedev);
+}
+
+/*
+ * Function name: libvirt_nodedev_capabilities
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to list node devices by capabilities
+ * Arguments: @res [resource]: libvirt nodedev resource
+ * Returns: nodedev capabilities array
+ */
+PHP_FUNCTION(libvirt_nodedev_capabilities)
+{
+ php_libvirt_nodedev *nodedev = NULL;
+ zval *znodedev;
+ int count = -1;
+ int expectedcount = -1;
+ char **names;
+ int i;
+
+ GET_NODEDEV_FROM_ARGS("r", &znodedev);
+
+ if ((expectedcount = virNodeDeviceNumOfCaps(nodedev->device)) < 0)
+ RETURN_FALSE;
+ names = (char **)emalloc(expectedcount*sizeof(char *));
+ count = virNodeDeviceListCaps(nodedev->device, names, expectedcount);
+ if ((count != expectedcount) || (count < 0))
+ RETURN_FALSE;
+
+ array_init(return_value);
+ for (i = 0; i < count; i++) {
+ VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+ free(names[i]);
+ }
+
+ efree(names);
+}
+
+/*
+ * Function name: libvirt_nodedev_get_xml_desc
+ * Since version: 0.4.1(-1), changed 0.4.2
+ * Description: Function is used to get the node device's XML description
+ * Arguments: @res [resource]: libvirt nodedev resource
+ * @xpath [string]: optional xPath expression string to get just this
entry, can be NULL
+ * Returns: nodedev XML description string or result of xPath expression
+ */
+PHP_FUNCTION(libvirt_nodedev_get_xml_desc)
+{
+ php_libvirt_nodedev *nodedev = NULL;
+ zval *znodedev;
+ char *tmp = NULL;
+ char *xml = NULL;
+ char *xpath = NULL;
+ strsize_t xpath_len;
+ int retval = -1;
+
+ GET_NODEDEV_FROM_ARGS("r|s", &znodedev, &xpath, &xpath_len);
+ if (xpath_len < 1)
+ xpath = NULL;
+
+ xml = virNodeDeviceGetXMLDesc(nodedev->device, 0);
+ if (!xml) {
+ set_error("Cannot get the device XML information" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
+ if ((tmp == NULL) || (retval < 0))
+ VIRT_RETVAL_STRING(xml);
+ else
+ VIRT_RETVAL_STRING(tmp);
+
+ free(xml);
+ free(tmp);
+}
+
+/*
+ * Function name: libvirt_nodedev_get_information
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the node device's information
+ * Arguments: @res [resource]: libvirt nodedev resource
+ * Returns: nodedev information array
+ */
+PHP_FUNCTION(libvirt_nodedev_get_information)
+{
+ php_libvirt_nodedev *nodedev = NULL;
+ zval *znodedev;
+ int retval = -1;
+ char *xml = NULL;
+ char *tmp = NULL;
+ char *cap = NULL;
+
+ GET_NODEDEV_FROM_ARGS("r", &znodedev);
+
+ xml = virNodeDeviceGetXMLDesc(nodedev->device, 0);
+ if (!xml) {
+ set_error("Cannot get the device XML information" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ /* Get name */
+ tmp = get_string_from_xpath(xml, "//device/name", NULL, &retval);
+ if (tmp == NULL) {
+ set_error("Invalid XPath node for device name" TSRMLS_CC);
+ goto error;
+ }
+
+ if (retval < 0) {
+ set_error("Cannot get XPath expression result for device name"
TSRMLS_CC);
+ goto error;
+ }
+
+ VIRT_ADD_ASSOC_STRING(return_value, "name", tmp);
+
+ /* Get parent name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "parent", tmp);
+
+ /* Get capability */
+ cap = get_string_from_xpath(xml, "//device/capability/@type", NULL,
&retval);
+ if ((cap != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "capability", cap);
+
+ /* System capability is having hardware and firmware sub-blocks */
+ if (strcmp(cap, "system") == 0) {
+ /* Get hardware vendor */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor",
NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "hardware_vendor", tmp);
+
+ /* Get hardware version */
+ free(tmp);
+ tmp = get_string_from_xpath(xml,
"//device/capability/hardware/version", NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "hardware_version", tmp);
+
+ /* Get hardware serial */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial",
NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "hardware_serial", tmp);
+
+ /* Get hardware UUID */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid",
NULL, &retval);
+ if (tmp != NULL)
+ VIRT_ADD_ASSOC_STRING(return_value, "hardware_uuid", tmp);
+
+ /* Get firmware vendor */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor",
NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "firmware_vendor", tmp);
+
+ /* Get firmware version */
+ free(tmp);
+ tmp = get_string_from_xpath(xml,
"//device/capability/firmware/version", NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "firmware_version", tmp);
+
+ /* Get firmware release date */
+ free(tmp);
+ tmp = get_string_from_xpath(xml,
"//device/capability/firmware/release_date", NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "firmware_release_date", tmp);
+ }
+
+ /* Get product_id */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "product_id", tmp);
+
+ /* Get product_name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/product", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "product_name", tmp);
+
+ /* Get vendor_id */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "vendor_id", tmp);
+
+ /* Get vendor_name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "vendor_name", tmp);
+
+ /* Get driver name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/driver/name", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "driver_name", tmp);
+
+ /* Get driver name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "interface_name", tmp);
+
+ /* Get driver name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/address", NULL,
&retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "address", tmp);
+
+ /* Get driver name */
+ free(tmp);
+ tmp = get_string_from_xpath(xml, "//device/capability/capability/@type",
NULL, &retval);
+ if ((tmp != NULL) && (retval > 0))
+ VIRT_ADD_ASSOC_STRING(return_value, "capabilities", tmp);
+
+ free(cap);
+ free(tmp);
+ free(xml);
+ return;
+
+ error:
+ free(cap);
+ free(tmp);
+ free(xml);
+ RETURN_FALSE;
+}
+
+/*
+ * Function name: libvirt_list_nodedevs
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to list node devices on the connection
+ * Arguments: @res [resource]: libvirt connection resource
+ * @cap [string]: optional capability string
+ * Returns: libvirt nodedev names array for the connection
+ */
+PHP_FUNCTION(libvirt_list_nodedevs)
+{
+ php_libvirt_connection *conn = NULL;
+ zval *zconn;
+ int count = -1;
+ int expectedcount = -1;
+ char *cap = NULL;
+ char **names;
+ int i;
+ strsize_t cap_len;
+
+ GET_CONNECTION_FROM_ARGS("r|s", &zconn, &cap, &cap_len);
+
+ if ((expectedcount = virNodeNumOfDevices(conn->conn, cap, 0)) < 0)
+ RETURN_FALSE;
+ names = (char **)emalloc(expectedcount*sizeof(char *));
+ count = virNodeListDevices(conn->conn, cap, names, expectedcount, 0);
+ if ((count != expectedcount) || (count < 0)) {
+ efree(names);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ for (i = 0; i < count; i++) {
+ VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+ free(names[i]);
+ }
+
+ efree(names);
+}
diff --git a/src/libvirt-nodedev.h b/src/libvirt-nodedev.h
new file mode 100644
index 0000000..350b213
--- /dev/null
+++ b/src/libvirt-nodedev.h
@@ -0,0 +1,54 @@
+/*
+ * libvirt-nodedev.h: The PHP bindings to libvirt nodedev API
+ *
+ * See COPYING for the license of this software
+ */
+
+#ifndef __LIBVIRT_NODEDEV_H__
+# define __LIBVIRT_NODEDEV_H__
+
+# include "libvirt-connection.h"
+
+# define PHP_LIBVIRT_NODEDEV_RES_NAME "Libvirt node device"
+# define INT_RESOURCE_NODEDEV 0x08
+
+# define PHP_FE_LIBVIRT_NODEDEV \
+ PHP_FE(libvirt_nodedev_get, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_nodedev_capabilities, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_nodedev_get_xml_desc, arginfo_libvirt_conn_xpath) \
+ PHP_FE(libvirt_nodedev_get_information, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_list_nodedevs, arginfo_libvirt_conn_optcap)
+
+# define GET_NODEDEV_FROM_ARGS(args, ...) \
+ do { \
+ reset_error(TSRMLS_C); \
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \
+ args, \
+ __VA_ARGS__) == FAILURE) { \
+ set_error("Invalid arguments" TSRMLS_CC);
\
+ RETURN_FALSE; \
+ } \
+ \
+ VIRT_FETCH_RESOURCE(nodedev, php_libvirt_nodedev*, &znodedev, \
+ PHP_LIBVIRT_NODEDEV_RES_NAME, le_libvirt_nodedev); \
+ if (nodedev == NULL || nodedev->device == NULL) \
+ RETURN_FALSE; \
+ } while (0)
+
+int le_libvirt_nodedev;
+
+typedef struct _php_libvirt_nodedev {
+ virNodeDevicePtr device;
+ php_libvirt_connection* conn;
+} php_libvirt_nodedev;
+
+
+void php_libvirt_nodedev_dtor(virt_resource *rsrc TSRMLS_DC);
+
+PHP_FUNCTION(libvirt_nodedev_get);
+PHP_FUNCTION(libvirt_nodedev_capabilities);
+PHP_FUNCTION(libvirt_nodedev_get_xml_desc);
+PHP_FUNCTION(libvirt_nodedev_get_information);
+PHP_FUNCTION(libvirt_list_nodedevs);
+
+#endif
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 8814e54..b62bcac 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -25,8 +25,9 @@
#include "libvirt-stream.h"
#include "libvirt-domain.h"
#include "libvirt-snapshot.h"
-#include "libvirt-network.h"
#include "libvirt-storage.h"
+#include "libvirt-network.h"
+#include "libvirt-nodedev.h"
DEBUG_INIT("core");
@@ -40,7 +41,6 @@ const char *features_binaries[] = { NULL };
#endif
/* ZEND thread safe per request globals definition */
-int le_libvirt_nodedev;
int le_libvirt_nwfilter;
ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect, 0, 0, 0)
@@ -481,11 +481,7 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE_LIBVIRT_STORAGE
PHP_FE_LIBVIRT_NETWORK
PHP_FE_LIBVIRT_NODE
- /* Nodedev functions */
- PHP_FE(libvirt_nodedev_get, arginfo_libvirt_conn)
- PHP_FE(libvirt_nodedev_capabilities, arginfo_libvirt_conn)
- PHP_FE(libvirt_nodedev_get_xml_desc, arginfo_libvirt_conn_xpath)
- PHP_FE(libvirt_nodedev_get_information, arginfo_libvirt_conn)
+ PHP_FE_LIBVIRT_NODEDEV
/* NWFilter functions */
PHP_FE(libvirt_nwfilter_define_xml, arginfo_libvirt_conn_xml)
PHP_FE(libvirt_nwfilter_undefine, arginfo_libvirt_conn)
@@ -497,7 +493,6 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_nwfilter_lookup_by_uuid_string, arginfo_libvirt_conn_uuid)
PHP_FE(libvirt_nwfilter_lookup_by_uuid, arginfo_libvirt_conn_uuid)
/* List functions */
- PHP_FE(libvirt_list_nodedevs, arginfo_libvirt_conn_optcap)
PHP_FE(libvirt_list_all_nwfilters, arginfo_libvirt_conn)
PHP_FE(libvirt_list_nwfilters, arginfo_libvirt_conn)
/* Version information and common function */
@@ -1179,33 +1174,6 @@ int is_local_connection(virConnectPtr conn)
#endif
}
-/* Destructor for nodedev resource */
-static void php_libvirt_nodedev_dtor(virt_resource *rsrc TSRMLS_DC)
-{
- php_libvirt_nodedev *nodedev = (php_libvirt_nodedev *)rsrc->ptr;
- int rv = 0;
-
- if (nodedev != NULL) {
- if (nodedev->device != NULL) {
- if (!check_resource_allocation(nodedev->conn->conn,
INT_RESOURCE_NODEDEV, nodedev->device TSRMLS_CC)) {
- nodedev->device = NULL;
- efree(nodedev);
- return;
- }
- rv = virNodeDeviceFree(nodedev->device);
- if (rv != 0) {
- DPRINTF("%s: virNodeDeviceFree(%p) returned %d (%s)\n",
__FUNCTION__, nodedev->device, rv, LIBVIRT_G(last_error));
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
- } else {
- DPRINTF("%s: virNodeDeviceFree(%p) completed successfully\n",
__FUNCTION__, nodedev->device);
- resource_change_counter(INT_RESOURCE_NODEDEV, nodedev->conn->conn,
nodedev->device, 0 TSRMLS_CC);
- }
- nodedev->device = NULL;
- }
- efree(nodedev);
- }
-}
-
/* Destructor for nwfilter resource */
static void php_libvirt_nwfilter_dtor(virt_resource *rsrc TSRMLS_DC)
{
@@ -1559,19 +1527,6 @@ PHP_MSHUTDOWN_FUNCTION(libvirt)
}
/* Macros for obtaining resources from arguments */
-#define GET_NODEDEV_FROM_ARGS(args, ...)
\
- do {
\
- reset_error(TSRMLS_C);
\
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) ==
FAILURE) { \
- set_error("Invalid arguments" TSRMLS_CC);
\
- RETURN_FALSE;
\
- }
\
-
\
- VIRT_FETCH_RESOURCE(nodedev, php_libvirt_nodedev*, &znodedev,
PHP_LIBVIRT_NODEDEV_RES_NAME, le_libvirt_nodedev);\
- if ((nodedev == NULL) || (nodedev->device == NULL))
\
- RETURN_FALSE;
\
- } while (0)
-
#define GET_NWFILTER_FROM_ARGS(args, ...)
\
do {
\
reset_error(TSRMLS_C);
\
@@ -2560,45 +2515,6 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network)
}
/* Listing functions */
-/*
- * Function name: libvirt_list_nodedevs
- * Since version: 0.4.1(-1)
- * Description: Function is used to list node devices on the connection
- * Arguments: @res [resource]: libvirt connection resource
- * @cap [string]: optional capability string
- * Returns: libvirt nodedev names array for the connection
- */
-PHP_FUNCTION(libvirt_list_nodedevs)
-{
- php_libvirt_connection *conn = NULL;
- zval *zconn;
- int count = -1;
- int expectedcount = -1;
- char *cap = NULL;
- char **names;
- int i;
- strsize_t cap_len;
-
- GET_CONNECTION_FROM_ARGS("r|s", &zconn, &cap, &cap_len);
-
- if ((expectedcount = virNodeNumOfDevices(conn->conn, cap, 0)) < 0)
- RETURN_FALSE;
- names = (char **)emalloc(expectedcount*sizeof(char *));
- count = virNodeListDevices(conn->conn, cap, names, expectedcount, 0);
- if ((count != expectedcount) || (count < 0)) {
- efree(names);
- RETURN_FALSE;
- }
-
- array_init(return_value);
- for (i = 0; i < count; i++) {
- VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
- free(names[i]);
- }
-
- efree(names);
-}
-
/*
* Function name: libvirt_list_all_nwfilters
@@ -2684,269 +2600,6 @@ PHP_FUNCTION(libvirt_list_nwfilters)
if (!done)
RETURN_FALSE;
}
-/* Nodedev functions */
-
-/*
- * Function name: libvirt_nodedev_get
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the node device by it's name
- * Arguments: @res [resource]: libvirt connection resource
- * @name [string]: name of the nodedev to get resource
- * Returns: libvirt nodedev resource
- */
-PHP_FUNCTION(libvirt_nodedev_get)
-{
- php_libvirt_connection *conn = NULL;
- php_libvirt_nodedev *res_dev = NULL;
- virNodeDevice *dev;
- zval *zconn;
- char *name;
- strsize_t name_len;
-
- GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
-
- if ((dev = virNodeDeviceLookupByName(conn->conn, name)) == NULL) {
- set_error("Cannot get find requested node device" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- res_dev = (php_libvirt_nodedev *)emalloc(sizeof(php_libvirt_nodedev));
- res_dev->device = dev;
- res_dev->conn = conn;
-
- DPRINTF("%s: returning %p\n", PHPFUNC, res_dev->device);
- resource_change_counter(INT_RESOURCE_NODEDEV, conn->conn, res_dev->device, 1
TSRMLS_CC);
-
- VIRT_REGISTER_RESOURCE(res_dev, le_libvirt_nodedev);
-}
-
-/*
- * Function name: libvirt_nodedev_capabilities
- * Since version: 0.4.1(-1)
- * Description: Function is used to list node devices by capabilities
- * Arguments: @res [resource]: libvirt nodedev resource
- * Returns: nodedev capabilities array
- */
-PHP_FUNCTION(libvirt_nodedev_capabilities)
-{
- php_libvirt_nodedev *nodedev = NULL;
- zval *znodedev;
- int count = -1;
- int expectedcount = -1;
- char **names;
- int i;
-
- GET_NODEDEV_FROM_ARGS("r", &znodedev);
-
- if ((expectedcount = virNodeDeviceNumOfCaps(nodedev->device)) < 0)
- RETURN_FALSE;
- names = (char **)emalloc(expectedcount*sizeof(char *));
- count = virNodeDeviceListCaps(nodedev->device, names, expectedcount);
- if ((count != expectedcount) || (count < 0))
- RETURN_FALSE;
-
- array_init(return_value);
- for (i = 0; i < count; i++) {
- VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
- free(names[i]);
- }
-
- efree(names);
-}
-
-/*
- * Function name: libvirt_nodedev_get_xml_desc
- * Since version: 0.4.1(-1), changed 0.4.2
- * Description: Function is used to get the node device's XML description
- * Arguments: @res [resource]: libvirt nodedev resource
- * @xpath [string]: optional xPath expression string to get just this
entry, can be NULL
- * Returns: nodedev XML description string or result of xPath expression
- */
-PHP_FUNCTION(libvirt_nodedev_get_xml_desc)
-{
- php_libvirt_nodedev *nodedev = NULL;
- zval *znodedev;
- char *tmp = NULL;
- char *xml = NULL;
- char *xpath = NULL;
- strsize_t xpath_len;
- int retval = -1;
-
- GET_NODEDEV_FROM_ARGS("r|s", &znodedev, &xpath, &xpath_len);
- if (xpath_len < 1)
- xpath = NULL;
-
- xml = virNodeDeviceGetXMLDesc(nodedev->device, 0);
- if (!xml) {
- set_error("Cannot get the device XML information" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
- if ((tmp == NULL) || (retval < 0))
- VIRT_RETVAL_STRING(xml);
- else
- VIRT_RETVAL_STRING(tmp);
-
- free(xml);
- free(tmp);
-}
-
-/*
- * Function name: libvirt_nodedev_get_information
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the node device's information
- * Arguments: @res [resource]: libvirt nodedev resource
- * Returns: nodedev information array
- */
-PHP_FUNCTION(libvirt_nodedev_get_information)
-{
- php_libvirt_nodedev *nodedev = NULL;
- zval *znodedev;
- int retval = -1;
- char *xml = NULL;
- char *tmp = NULL;
- char *cap = NULL;
-
- GET_NODEDEV_FROM_ARGS("r", &znodedev);
-
- xml = virNodeDeviceGetXMLDesc(nodedev->device, 0);
- if (!xml) {
- set_error("Cannot get the device XML information" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- array_init(return_value);
-
- /* Get name */
- tmp = get_string_from_xpath(xml, "//device/name", NULL, &retval);
- if (tmp == NULL) {
- set_error("Invalid XPath node for device name" TSRMLS_CC);
- goto error;
- }
-
- if (retval < 0) {
- set_error("Cannot get XPath expression result for device name"
TSRMLS_CC);
- goto error;
- }
-
- VIRT_ADD_ASSOC_STRING(return_value, "name", tmp);
-
- /* Get parent name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "parent", tmp);
-
- /* Get capability */
- cap = get_string_from_xpath(xml, "//device/capability/@type", NULL,
&retval);
- if ((cap != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "capability", cap);
-
- /* System capability is having hardware and firmware sub-blocks */
- if (strcmp(cap, "system") == 0) {
- /* Get hardware vendor */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor",
NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "hardware_vendor", tmp);
-
- /* Get hardware version */
- free(tmp);
- tmp = get_string_from_xpath(xml,
"//device/capability/hardware/version", NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "hardware_version", tmp);
-
- /* Get hardware serial */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial",
NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "hardware_serial", tmp);
-
- /* Get hardware UUID */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid",
NULL, &retval);
- if (tmp != NULL)
- VIRT_ADD_ASSOC_STRING(return_value, "hardware_uuid", tmp);
-
- /* Get firmware vendor */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor",
NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "firmware_vendor", tmp);
-
- /* Get firmware version */
- free(tmp);
- tmp = get_string_from_xpath(xml,
"//device/capability/firmware/version", NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "firmware_version", tmp);
-
- /* Get firmware release date */
- free(tmp);
- tmp = get_string_from_xpath(xml,
"//device/capability/firmware/release_date", NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "firmware_release_date", tmp);
- }
-
- /* Get product_id */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "product_id", tmp);
-
- /* Get product_name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/product", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "product_name", tmp);
-
- /* Get vendor_id */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "vendor_id", tmp);
-
- /* Get vendor_name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "vendor_name", tmp);
-
- /* Get driver name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/driver/name", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "driver_name", tmp);
-
- /* Get driver name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "interface_name", tmp);
-
- /* Get driver name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/address", NULL,
&retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "address", tmp);
-
- /* Get driver name */
- free(tmp);
- tmp = get_string_from_xpath(xml, "//device/capability/capability/@type",
NULL, &retval);
- if ((tmp != NULL) && (retval > 0))
- VIRT_ADD_ASSOC_STRING(return_value, "capabilities", tmp);
-
- free(cap);
- free(tmp);
- free(xml);
- return;
-
- error:
- free(cap);
- free(tmp);
- free(xml);
- RETURN_FALSE;
-}
/* NWFilter functions */
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index ca10d23..676b29e 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -128,7 +128,6 @@ typedef uint64_t arch_uint;
#define PHP_LIBVIRT_WORLD_EXTNAME "libvirt"
/* Internal resource identifier objects */
-#define INT_RESOURCE_NODEDEV 0x08
#define INT_RESOURCE_NWFILTER 0x60
typedef struct tTokenizer {
@@ -162,11 +161,6 @@ typedef struct tVMNetwork {
typedef struct _php_libvirt_connection php_libvirt_connection;
/* Libvirt-php types */
-typedef struct _php_libvirt_nodedev {
- virNodeDevicePtr device;
- php_libvirt_connection* conn;
-} php_libvirt_nodedev;
-
typedef struct _php_libvirt_nwfilter {
virNWFilterPtr nwfilter;
php_libvirt_connection* conn;
@@ -224,7 +218,6 @@ const char *get_feature_binary(const char *name);
long get_next_free_numeric_value(virDomainPtr domain, char *xpath);
int get_subnet_bits(char *ip);
-#define PHP_LIBVIRT_NODEDEV_RES_NAME "Libvirt node device"
#define PHP_LIBVIRT_NWFILTER_RES_NAME "Libvirt nwfilter"
PHP_MINIT_FUNCTION(libvirt);
@@ -235,11 +228,6 @@ PHP_MINFO_FUNCTION(libvirt);
/* Common functions */
PHP_FUNCTION(libvirt_get_last_error);
-/* Nodedev functions */
-PHP_FUNCTION(libvirt_nodedev_get);
-PHP_FUNCTION(libvirt_nodedev_capabilities);
-PHP_FUNCTION(libvirt_nodedev_get_xml_desc);
-PHP_FUNCTION(libvirt_nodedev_get_information);
/* NWFilter functions */
PHP_FUNCTION(libvirt_nwfilter_define_xml);
PHP_FUNCTION(libvirt_nwfilter_undefine);
@@ -251,7 +239,6 @@ PHP_FUNCTION(libvirt_nwfilter_lookup_by_name);
PHP_FUNCTION(libvirt_nwfilter_lookup_by_uuid_string);
PHP_FUNCTION(libvirt_nwfilter_lookup_by_uuid);
/* Listing functions */
-PHP_FUNCTION(libvirt_list_nodedevs);
PHP_FUNCTION(libvirt_list_all_nwfilters);
PHP_FUNCTION(libvirt_list_nwfilters);
/* Common functions */
--
2.13.3