]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove src/nodeinfo
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 7 Mar 2017 09:40:15 +0000 (10:40 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 27 Mar 2017 11:13:29 +0000 (13:13 +0200)
There is no "node driver" as there was before, drivers have to do
their own ACL checking anyway, so they all specify their functions and
nodeinfo is basically just extending conf/capablities.  Hence moving
the code to src/conf/ is the right way to go.

Also that way we can de-duplicate some code that is in virsysfs and/or
virhostcpu that got duplicated during the virhostcpu.c split.  And
Some cleanup is done throughout the changes, like adding the vir*
prefix etc.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
26 files changed:
po/POTFILES.in
src/Makefile.am
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_driver.c
src/conf/capabilities.c
src/conf/capabilities.h
src/cpu/cpu.c
src/libvirt_private.syms
src/lxc/lxc_conf.c
src/lxc/lxc_driver.c
src/nodeinfo.c [deleted file]
src/nodeinfo.h [deleted file]
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_capabilities.c
src/qemu/qemu_conf.c
src/qemu/qemu_driver.c
src/uml/uml_conf.c
src/uml/uml_driver.c
src/vbox/vbox_common.c
src/vmware/vmware_conf.c
src/vz/vz_driver.c
src/vz/vz_sdk.c
src/xen/xen_driver.c
tests/commandtest.c

index 2002e6889413083789a997a7b043ce04e2225ee7..4cffb535066bdd7a2b14b678d1a8df6a9e7e7ddb 100644 (file)
@@ -117,7 +117,6 @@ src/network/leaseshelper.c
 src/node_device/node_device_driver.c
 src/node_device/node_device_hal.c
 src/node_device/node_device_udev.c
-src/nodeinfo.c
 src/nwfilter/nwfilter_dhcpsnoop.c
 src/nwfilter/nwfilter_driver.c
 src/nwfilter/nwfilter_ebiptables_driver.c
index efaa7241394ba12f5f1fa52ce1e8ff35a8a8e916..23fc2120df8daf6cef025e63960962e3c4de7aed 100644 (file)
@@ -204,7 +204,6 @@ util/virkeymaps.h: $(srcdir)/util/keymaps.csv       \
          <$(srcdir)/util/keymaps.csv >util/virkeymaps.h
 
 # Internal generic driver infrastructure
-NODE_INFO_SOURCES = nodeinfo.h nodeinfo.c
 DATATYPES_SOURCES = datatypes.h datatypes.c
 DRIVER_SOURCES =                                                       \
                driver.c driver.h                                       \
@@ -219,7 +218,6 @@ DRIVER_SOURCES =                                                    \
                driver-stream.h                                         \
                internal.h                                              \
                $(DATATYPES_SOURCES)                                    \
-               $(NODE_INFO_SOURCES)                                    \
                libvirt.c libvirt_internal.h                            \
                libvirt-domain.c                                        \
                libvirt-domain-snapshot.c                               \
@@ -3168,7 +3166,6 @@ libexec_PROGRAMS += libvirt_lxc
 
 libvirt_lxc_SOURCES =                                          \
                $(LXC_CONTROLLER_SOURCES)                       \
-               $(NODE_INFO_SOURCES)                            \
                $(DATATYPES_SOURCES)
 libvirt_lxc_LDFLAGS = \
                $(AM_LDFLAGS) \
index 875ee4ad5d2708e657af7f3cdd764f88d4f944b7..381cc0de37d5f4fa050ef2ff20e45caa1ac067de 100644 (file)
@@ -31,7 +31,6 @@
 #include "virlog.h"
 #include "virstring.h"
 #include "cpu/cpu.h"
-#include "nodeinfo.h"
 #include "domain_conf.h"
 #include "vircommand.h"
 #include "bhyve_capabilities.h"
index 380af39b0b2a44e1fb8479e8482af135f7958269..74cc5ab219cc073bcbba9808ed372f79e1854070 100644 (file)
@@ -50,7 +50,6 @@
 #include "virstring.h"
 #include "cpu/cpu.h"
 #include "viraccessapicheck.h"
-#include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "conf/domain_capabilities.h"
@@ -1207,12 +1206,12 @@ bhyveNodeGetMemoryStats(virConnectPtr conn,
 
 static int
 bhyveNodeGetInfo(virConnectPtr conn,
-                      virNodeInfoPtr nodeinfo)
+                 virNodeInfoPtr nodeinfo)
 {
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 static int
index 87e274c06675c12fa6c467fa82b43af23ae2617e..d798d5364cc21b03bc8daaa965bb2f4e94a85a1d 100644 (file)
 
 #include <config.h>
 
+#include <stdio.h>
+#include <string.h>
 #include <strings.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
 
 #include "capabilities.h"
-#include "virbuffer.h"
-#include "viralloc.h"
-#include "viruuid.h"
+#include "count-one-bits.h"
 #include "cpu_conf.h"
+#include "domain_conf.h"
+#include "physmem.h"
+#include "viralloc.h"
+#include "virarch.h"
+#include "virbuffer.h"
 #include "virerror.h"
+#include "virfile.h"
+#include "virhostcpu.h"
+#include "virhostmem.h"
+#include "virlog.h"
+#include "virnuma.h"
 #include "virstring.h"
-#include "domain_conf.h"
+#include "virsysfs.h"
+#include "virtypedparam.h"
+#include "viruuid.h"
 
 #define VIR_FROM_THIS VIR_FROM_CAPABILITIES
 
+VIR_LOG_INIT("conf.capabilities")
+
 VIR_ENUM_DECL(virCapsHostPMTarget)
 VIR_ENUM_IMPL(virCapsHostPMTarget, VIR_NODE_SUSPEND_TARGET_LAST,
               "suspend_mem", "suspend_disk", "suspend_hybrid");
@@ -1128,3 +1145,271 @@ virCapabilitiesGetCpusForNodemask(virCapsPtr caps,
 
     return ret;
 }
+
+
+int
+virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo)
+{
+    virArch hostarch = virArchFromHost();
+    unsigned long long memorybytes;
+
+    memset(nodeinfo, 0, sizeof(*nodeinfo));
+
+    if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
+        return -1;
+
+    if (virHostMemGetInfo(&memorybytes, NULL) < 0)
+        return -1;
+    nodeinfo->memory = memorybytes / 1024;
+
+    if (virHostCPUGetInfo(hostarch,
+                          &nodeinfo->cpus, &nodeinfo->mhz,
+                          &nodeinfo->nodes, &nodeinfo->sockets,
+                          &nodeinfo->cores, &nodeinfo->threads) < 0)
+        return -1;
+
+    return 0;
+}
+
+/* returns 1 on success, 0 if the detection failed and -1 on hard error */
+static int
+virCapabilitiesFillCPUInfo(int cpu_id ATTRIBUTE_UNUSED,
+                           virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
+{
+#ifdef __linux__
+    cpu->id = cpu_id;
+
+    if (virHostCPUGetSocket(cpu_id, &cpu->socket_id) < 0 ||
+        virHostCPUGetCore(cpu_id, &cpu->core_id) < 0)
+        return -1;
+
+    if (!(cpu->siblings = virHostCPUGetSiblingsList(cpu_id)))
+        return -1;
+
+    return 0;
+#else
+    virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                   _("node cpu info not implemented on this platform"));
+    return -1;
+#endif
+}
+
+static int
+virCapabilitiesGetNUMASiblingInfo(int node,
+                                  virCapsHostNUMACellSiblingInfoPtr *siblings,
+                                  int *nsiblings)
+{
+    virCapsHostNUMACellSiblingInfoPtr tmp = NULL;
+    int tmp_size = 0;
+    int ret = -1;
+    int *distances = NULL;
+    int ndistances = 0;
+    size_t i;
+
+    if (virNumaGetDistances(node, &distances, &ndistances) < 0)
+        goto cleanup;
+
+    if (!distances) {
+        *siblings = NULL;
+        *nsiblings = 0;
+        return 0;
+    }
+
+    if (VIR_ALLOC_N(tmp, ndistances) < 0)
+        goto cleanup;
+
+    for (i = 0; i < ndistances; i++) {
+        if (!distances[i])
+            continue;
+
+        tmp[tmp_size].node = i;
+        tmp[tmp_size].distance = distances[i];
+        tmp_size++;
+    }
+
+    if (VIR_REALLOC_N(tmp, tmp_size) < 0)
+        goto cleanup;
+
+    *siblings = tmp;
+    *nsiblings = tmp_size;
+    tmp = NULL;
+    tmp_size = 0;
+    ret = 0;
+ cleanup:
+    VIR_FREE(distances);
+    VIR_FREE(tmp);
+    return ret;
+}
+
+static int
+virCapabilitiesGetNUMAPagesInfo(int node,
+                                virCapsHostNUMACellPageInfoPtr *pageinfo,
+                                int *npageinfo)
+{
+    int ret = -1;
+    unsigned int *pages_size = NULL, *pages_avail = NULL;
+    size_t npages, i;
+
+    if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(*pageinfo, npages) < 0)
+        goto cleanup;
+    *npageinfo = npages;
+
+    for (i = 0; i < npages; i++) {
+        (*pageinfo)[i].size = pages_size[i];
+        (*pageinfo)[i].avail = pages_avail[i];
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(pages_avail);
+    VIR_FREE(pages_size);
+    return ret;
+}
+
+
+static int
+virCapabilitiesInitNUMAFake(virCapsPtr caps)
+{
+    virNodeInfo nodeinfo;
+    virCapsHostNUMACellCPUPtr cpus;
+    int ncpus;
+    int s, c, t;
+    int id, cid;
+    int onlinecpus ATTRIBUTE_UNUSED;
+    bool tmp;
+
+    if (virCapabilitiesGetNodeInfo(&nodeinfo) < 0)
+        return -1;
+
+    ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
+    onlinecpus = nodeinfo.cpus;
+
+    if (VIR_ALLOC_N(cpus, ncpus) < 0)
+        return -1;
+
+    id = cid = 0;
+    for (s = 0; s < nodeinfo.sockets; s++) {
+        for (c = 0; c < nodeinfo.cores; c++) {
+            for (t = 0; t < nodeinfo.threads; t++) {
+                if (virHostCPUGetOnline(id, &tmp) < 0)
+                    goto error;
+                if (tmp) {
+                    cpus[cid].id = id;
+                    cpus[cid].socket_id = s;
+                    cpus[cid].core_id = c;
+                    if (!(cpus[cid].siblings = virBitmapNew(ncpus)))
+                        goto error;
+                    ignore_value(virBitmapSetBit(cpus[cid].siblings, id));
+                    cid++;
+                }
+
+                id++;
+            }
+        }
+    }
+
+    if (virCapabilitiesAddHostNUMACell(caps, 0,
+                                       nodeinfo.memory,
+#ifdef __linux__
+                                       onlinecpus, cpus,
+#else
+                                       ncpus, cpus,
+#endif
+                                       0, NULL,
+                                       0, NULL) < 0)
+        goto error;
+
+    return 0;
+
+ error:
+    for (; id >= 0; id--)
+        virBitmapFree(cpus[id].siblings);
+    VIR_FREE(cpus);
+    return -1;
+}
+
+int
+virCapabilitiesInitNUMA(virCapsPtr caps)
+{
+    int n;
+    unsigned long long memory;
+    virCapsHostNUMACellCPUPtr cpus = NULL;
+    virBitmapPtr cpumap = NULL;
+    virCapsHostNUMACellSiblingInfoPtr siblings = NULL;
+    int nsiblings = 0;
+    virCapsHostNUMACellPageInfoPtr pageinfo = NULL;
+    int npageinfo;
+    int ret = -1;
+    int ncpus = 0;
+    int cpu;
+    bool topology_failed = false;
+    int max_node;
+
+    if (!virNumaIsAvailable())
+        return virCapabilitiesInitNUMAFake(caps);
+
+    if ((max_node = virNumaGetMaxNode()) < 0)
+        goto cleanup;
+
+    for (n = 0; n <= max_node; n++) {
+        size_t i;
+
+        if ((ncpus = virNumaGetNodeCPUs(n, &cpumap)) < 0) {
+            if (ncpus == -2)
+                continue;
+
+            goto cleanup;
+        }
+
+        if (VIR_ALLOC_N(cpus, ncpus) < 0)
+            goto cleanup;
+        cpu = 0;
+
+        for (i = 0; i < virBitmapSize(cpumap); i++) {
+            if (virBitmapIsBitSet(cpumap, i)) {
+                if (virCapabilitiesFillCPUInfo(i, cpus + cpu++) < 0) {
+                    topology_failed = true;
+                    virResetLastError();
+                }
+            }
+        }
+
+        if (virCapabilitiesGetNUMASiblingInfo(n, &siblings, &nsiblings) < 0)
+            goto cleanup;
+
+        if (virCapabilitiesGetNUMAPagesInfo(n, &pageinfo, &npageinfo) < 0)
+            goto cleanup;
+
+        /* Detect the amount of memory in the numa cell in KiB */
+        virNumaGetNodeMemory(n, &memory, NULL);
+        memory >>= 10;
+
+        if (virCapabilitiesAddHostNUMACell(caps, n, memory,
+                                           ncpus, cpus,
+                                           nsiblings, siblings,
+                                           npageinfo, pageinfo) < 0)
+            goto cleanup;
+
+        cpus = NULL;
+        siblings = NULL;
+        pageinfo = NULL;
+        virBitmapFree(cpumap);
+        cpumap = NULL;
+    }
+
+    ret = 0;
+
+ cleanup:
+    if ((topology_failed || ret < 0) && cpus)
+        virCapabilitiesClearHostNUMACellCPUTopology(cpus, ncpus);
+
+    virBitmapFree(cpumap);
+    VIR_FREE(cpus);
+    VIR_FREE(siblings);
+    VIR_FREE(pageinfo);
+    return ret;
+}
index 8634fda144582ea4c22d2d09d23c4eccd42d5c5d..3cb305b50b4a04c587f0be9efb8f0652ebedb86c 100644 (file)
@@ -297,4 +297,8 @@ virCapabilitiesFormatXML(virCapsPtr caps);
 virBitmapPtr virCapabilitiesGetCpusForNodemask(virCapsPtr caps,
                                                virBitmapPtr nodemask);
 
+int virCapabilitiesGetNodeInfo(virNodeInfoPtr nodeinfo);
+
+int virCapabilitiesInitNUMA(virCapsPtr caps);
+
 #endif /* __VIR_CAPABILITIES_H */
index 484f5fceb090ee15c90b5b4a3e512bcce6b36f64..b88f9955f3580381e03ac659f7557f365c2e36e0 100644 (file)
 #include "virlog.h"
 #include "viralloc.h"
 #include "virxml.h"
-#include "nodeinfo.h"
 #include "cpu.h"
 #include "cpu_map.h"
 #include "cpu_x86.h"
 #include "cpu_ppc64.h"
 #include "cpu_s390.h"
 #include "cpu_arm.h"
+#include "capabilities.h"
 #include "virstring.h"
 
 
@@ -468,7 +468,7 @@ virCPUProbeHost(virArch arch)
 {
     virNodeInfo nodeinfo;
 
-    if (nodeGetInfo(&nodeinfo))
+    if (virCapabilitiesGetNodeInfo(&nodeinfo))
         return NULL;
 
     return virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo, NULL, 0);
index ec6deb8a5dfd11dddc30b7f9719f06c4a37cfeab..0365b6251976559dfd68a962c033743c6b9ba7f7 100644 (file)
@@ -57,7 +57,9 @@ virCapabilitiesFreeGuest;
 virCapabilitiesFreeMachines;
 virCapabilitiesFreeNUMAInfo;
 virCapabilitiesGetCpusForNodemask;
+virCapabilitiesGetNodeInfo;
 virCapabilitiesHostSecModelAddBaseLabel;
+virCapabilitiesInitNUMA;
 virCapabilitiesNew;
 virCapabilitiesSetHostCPU;
 virCapabilitiesSetNetPrefix;
@@ -1133,11 +1135,6 @@ virLogManagerFree;
 virLogManagerNew;
 
 
-# nodeinfo.h
-nodeCapsInitNUMA;
-nodeGetInfo;
-
-
 # secret/secret_util.h
 virSecretGetSecretString;
 
index 538bbbe87d3f4ca9c0ef9e18f8078700f39d1dc1..e47b667f582a30c591bf08dda0aadb7510a7690a 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "lxc_conf.h"
 #include "lxc_domain.h"
-#include "nodeinfo.h"
 #include "virerror.h"
 #include "virconf.h"
 #include "viralloc.h"
@@ -77,7 +76,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
      * unexpected failures. We don't want to break the lxc
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(caps) < 0) {
+    if (virCapabilitiesInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 5dbd5a6c242c4cb48d356c58919900c66e737ac9..ecd5fbdd4de16f6ce27d5720400349b436e9f4c9 100644 (file)
@@ -57,7 +57,6 @@
 #include "virnetdevbridge.h"
 #include "virnetdevveth.h"
 #include "virnetdevopenvswitch.h"
-#include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "viruuid.h"
@@ -5171,7 +5170,7 @@ lxcNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
deleted file mode 100644 (file)
index f2ded02..0000000
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * nodeinfo.c: Helper routines for OS specific node information
- *
- * Copyright (C) 2006-2008, 2010-2015 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Author: Daniel P. Berrange <berrange@redhat.com>
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <errno.h>
-#include <sys/utsname.h>
-#include "conf/domain_conf.h"
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-
-#include "viralloc.h"
-#include "nodeinfo.h"
-#include "virhostcpu.h"
-#include "virhostmem.h"
-#include "physmem.h"
-#include "virerror.h"
-#include "count-one-bits.h"
-#include "intprops.h"
-#include "virarch.h"
-#include "virfile.h"
-#include "virtypedparam.h"
-#include "virstring.h"
-#include "virnuma.h"
-#include "virlog.h"
-
-#define VIR_FROM_THIS VIR_FROM_NONE
-
-VIR_LOG_INIT("nodeinfo");
-
-
-
-#ifdef __linux__
-# define SYSFS_SYSTEM_PATH "/sys/devices/system"
-# define SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX 8192
-
-
-/* Return the positive decimal contents of the given
- * DIR/cpu%u/FILE, or -1 on error.  If DEFAULT_VALUE is non-negative
- * and the file could not be found, return that instead of an error;
- * this is useful for machines that cannot hot-unplug cpu0, or where
- * hot-unplugging is disabled, or where the kernel is too old
- * to support NUMA cells, etc.  */
-static int
-virNodeGetCpuValue(const char *dir, unsigned int cpu, const char *file,
-                   int default_value)
-{
-    char *path;
-    FILE *pathfp;
-    int value = -1;
-    char value_str[INT_BUFSIZE_BOUND(value)];
-    char *tmp;
-
-    if (virAsprintf(&path, "%s/cpu%u/%s", dir, cpu, file) < 0)
-        return -1;
-
-    pathfp = fopen(path, "r");
-    if (pathfp == NULL) {
-        if (default_value >= 0 && errno == ENOENT)
-            value = default_value;
-        else
-            virReportSystemError(errno, _("cannot open %s"), path);
-        goto cleanup;
-    }
-
-    if (fgets(value_str, sizeof(value_str), pathfp) == NULL) {
-        virReportSystemError(errno, _("cannot read from %s"), path);
-        goto cleanup;
-    }
-    if (virStrToLong_i(value_str, &tmp, 10, &value) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("could not convert '%s' to an integer"),
-                       value_str);
-        goto cleanup;
-    }
-
- cleanup:
-    VIR_FORCE_FCLOSE(pathfp);
-    VIR_FREE(path);
-
-    return value;
-}
-
-
-static virBitmapPtr
-virNodeGetSiblingsListLinux(const char *dir, int cpu_id)
-{
-    char *path = NULL;
-    char *buf = NULL;
-    virBitmapPtr ret = NULL;
-
-    if (virAsprintf(&path, "%s/cpu%u/topology/thread_siblings_list",
-                    dir, cpu_id) < 0)
-        goto cleanup;
-
-    if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &buf) < 0)
-        goto cleanup;
-
-    if (virBitmapParse(buf, &ret, virNumaGetMaxCPUs()) < 0)
-        goto cleanup;
-
- cleanup:
-    VIR_FREE(buf);
-    VIR_FREE(path);
-    return ret;
-}
-#else
-# define SYSFS_SYSTEM_PATH "fake"
-#endif
-
-
-int
-nodeGetInfo(virNodeInfoPtr nodeinfo)
-{
-    virArch hostarch = virArchFromHost();
-    unsigned long long memorybytes;
-
-    memset(nodeinfo, 0, sizeof(*nodeinfo));
-
-    if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
-        return -1;
-
-    if (virHostMemGetInfo(&memorybytes, NULL) < 0)
-        return -1;
-    nodeinfo->memory = memorybytes / 1024;
-
-    if (virHostCPUGetInfo(hostarch,
-                          &nodeinfo->cpus, &nodeinfo->mhz,
-                          &nodeinfo->nodes, &nodeinfo->sockets,
-                          &nodeinfo->cores, &nodeinfo->threads) < 0)
-        return -1;
-
-    return 0;
-}
-
-
-static int
-nodeCapsInitNUMAFake(const char *cpupath ATTRIBUTE_UNUSED,
-                     virCapsPtr caps ATTRIBUTE_UNUSED)
-{
-    virNodeInfo nodeinfo;
-    virCapsHostNUMACellCPUPtr cpus;
-    int ncpus;
-    int s, c, t;
-    int id, cid;
-    int onlinecpus ATTRIBUTE_UNUSED;
-
-    if (nodeGetInfo(&nodeinfo) < 0)
-        return -1;
-
-    ncpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
-    onlinecpus = nodeinfo.cpus;
-
-    if (VIR_ALLOC_N(cpus, ncpus) < 0)
-        return -1;
-
-    id = cid = 0;
-    for (s = 0; s < nodeinfo.sockets; s++) {
-        for (c = 0; c < nodeinfo.cores; c++) {
-            for (t = 0; t < nodeinfo.threads; t++) {
-#ifdef __linux__
-                if (virNodeGetCpuValue(cpupath, id, "online", 1)) {
-#endif
-                    cpus[cid].id = id;
-                    cpus[cid].socket_id = s;
-                    cpus[cid].core_id = c;
-                    if (!(cpus[cid].siblings = virBitmapNew(ncpus)))
-                        goto error;
-                    ignore_value(virBitmapSetBit(cpus[cid].siblings, id));
-                    cid++;
-#ifdef __linux__
-                }
-#endif
-
-                id++;
-            }
-        }
-    }
-
-    if (virCapabilitiesAddHostNUMACell(caps, 0,
-                                       nodeinfo.memory,
-#ifdef __linux__
-                                       onlinecpus, cpus,
-#else
-                                       ncpus, cpus,
-#endif
-                                       0, NULL,
-                                       0, NULL) < 0)
-        goto error;
-
-    return 0;
-
- error:
-    for (; id >= 0; id--)
-        virBitmapFree(cpus[id].siblings);
-    VIR_FREE(cpus);
-    return -1;
-}
-
-
-/* returns 1 on success, 0 if the detection failed and -1 on hard error */
-static int
-virNodeCapsFillCPUInfo(const char *cpupath ATTRIBUTE_UNUSED,
-                       int cpu_id ATTRIBUTE_UNUSED,
-                       virCapsHostNUMACellCPUPtr cpu ATTRIBUTE_UNUSED)
-{
-#ifdef __linux__
-    int tmp;
-    cpu->id = cpu_id;
-
-    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
-                                  "topology/physical_package_id", -1)) < 0)
-        return 0;
-
-    cpu->socket_id = tmp;
-
-    if ((tmp = virNodeGetCpuValue(cpupath, cpu_id,
-                                  "topology/core_id", -1)) < 0)
-        return 0;
-
-    cpu->core_id = tmp;
-
-    if (!(cpu->siblings = virNodeGetSiblingsListLinux(cpupath, cpu_id)))
-        return -1;
-
-    return 0;
-#else
-    virReportError(VIR_ERR_NO_SUPPORT, "%s",
-                   _("node cpu info not implemented on this platform"));
-    return -1;
-#endif
-}
-
-static int
-virNodeCapsGetSiblingInfo(int node,
-                          virCapsHostNUMACellSiblingInfoPtr *siblings,
-                          int *nsiblings)
-{
-    virCapsHostNUMACellSiblingInfoPtr tmp = NULL;
-    int tmp_size = 0;
-    int ret = -1;
-    int *distances = NULL;
-    int ndistances = 0;
-    size_t i;
-
-    if (virNumaGetDistances(node, &distances, &ndistances) < 0)
-        goto cleanup;
-
-    if (!distances) {
-        *siblings = NULL;
-        *nsiblings = 0;
-        return 0;
-    }
-
-    if (VIR_ALLOC_N(tmp, ndistances) < 0)
-        goto cleanup;
-
-    for (i = 0; i < ndistances; i++) {
-        if (!distances[i])
-            continue;
-
-        tmp[tmp_size].node = i;
-        tmp[tmp_size].distance = distances[i];
-        tmp_size++;
-    }
-
-    if (VIR_REALLOC_N(tmp, tmp_size) < 0)
-        goto cleanup;
-
-    *siblings = tmp;
-    *nsiblings = tmp_size;
-    tmp = NULL;
-    tmp_size = 0;
-    ret = 0;
- cleanup:
-    VIR_FREE(distances);
-    VIR_FREE(tmp);
-    return ret;
-}
-
-static int
-virNodeCapsGetPagesInfo(int node,
-                        virCapsHostNUMACellPageInfoPtr *pageinfo,
-                        int *npageinfo)
-{
-    int ret = -1;
-    unsigned int *pages_size = NULL, *pages_avail = NULL;
-    size_t npages, i;
-
-    if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < 0)
-        goto cleanup;
-
-    if (VIR_ALLOC_N(*pageinfo, npages) < 0)
-        goto cleanup;
-    *npageinfo = npages;
-
-    for (i = 0; i < npages; i++) {
-        (*pageinfo)[i].size = pages_size[i];
-        (*pageinfo)[i].avail = pages_avail[i];
-    }
-
-    ret = 0;
-
- cleanup:
-    VIR_FREE(pages_avail);
-    VIR_FREE(pages_size);
-    return ret;
-}
-
-int
-nodeCapsInitNUMA(virCapsPtr caps)
-{
-    int n;
-    unsigned long long memory;
-    virCapsHostNUMACellCPUPtr cpus = NULL;
-    virBitmapPtr cpumap = NULL;
-    virCapsHostNUMACellSiblingInfoPtr siblings = NULL;
-    int nsiblings = 0;
-    virCapsHostNUMACellPageInfoPtr pageinfo = NULL;
-    int npageinfo;
-    int ret = -1;
-    int ncpus = 0;
-    int cpu;
-    bool topology_failed = false;
-    int max_node;
-
-    if (!virNumaIsAvailable()) {
-        ret = nodeCapsInitNUMAFake(SYSFS_SYSTEM_PATH "/cpu", caps);
-        goto cleanup;
-    }
-
-    if ((max_node = virNumaGetMaxNode()) < 0)
-        goto cleanup;
-
-    for (n = 0; n <= max_node; n++) {
-        size_t i;
-
-        if ((ncpus = virNumaGetNodeCPUs(n, &cpumap)) < 0) {
-            if (ncpus == -2)
-                continue;
-
-            goto cleanup;
-        }
-
-        if (VIR_ALLOC_N(cpus, ncpus) < 0)
-            goto cleanup;
-        cpu = 0;
-
-        for (i = 0; i < virBitmapSize(cpumap); i++) {
-            if (virBitmapIsBitSet(cpumap, i)) {
-                if (virNodeCapsFillCPUInfo(SYSFS_SYSTEM_PATH "/cpu",
-                                           i, cpus + cpu++) < 0) {
-                    topology_failed = true;
-                    virResetLastError();
-                }
-            }
-        }
-
-        if (virNodeCapsGetSiblingInfo(n, &siblings, &nsiblings) < 0)
-            goto cleanup;
-
-        if (virNodeCapsGetPagesInfo(n, &pageinfo, &npageinfo) < 0)
-            goto cleanup;
-
-        /* Detect the amount of memory in the numa cell in KiB */
-        virNumaGetNodeMemory(n, &memory, NULL);
-        memory >>= 10;
-
-        if (virCapabilitiesAddHostNUMACell(caps, n, memory,
-                                           ncpus, cpus,
-                                           nsiblings, siblings,
-                                           npageinfo, pageinfo) < 0)
-            goto cleanup;
-
-        cpus = NULL;
-        siblings = NULL;
-        pageinfo = NULL;
-        virBitmapFree(cpumap);
-        cpumap = NULL;
-    }
-
-    ret = 0;
-
- cleanup:
-    if ((topology_failed || ret < 0) && cpus)
-        virCapabilitiesClearHostNUMACellCPUTopology(cpus, ncpus);
-
-    virBitmapFree(cpumap);
-    VIR_FREE(cpus);
-    VIR_FREE(siblings);
-    VIR_FREE(pageinfo);
-    return ret;
-}
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
deleted file mode 100644 (file)
index 3c4dc46..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * nodeinfo.h: Helper routines for OS specific node information
- *
- * Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Author: Daniel P. Berrange <berrange@redhat.com>
- */
-
-#ifndef __VIR_NODEINFO_H__
-# define __VIR_NODEINFO_H__
-
-# include "capabilities.h"
-
-int nodeGetInfo(virNodeInfoPtr nodeinfo);
-int nodeCapsInitNUMA(virCapsPtr caps);
-
-#endif /* __VIR_NODEINFO_H__*/
index e4d7634d2eff45e9341b0449bddc52962523b580..196fefb8de19d1280c74de12373cc3d87cf3492a 100644 (file)
@@ -47,7 +47,6 @@
 #include "viruuid.h"
 #include "virbuffer.h"
 #include "viralloc.h"
-#include "nodeinfo.h"
 #include "virfile.h"
 #include "vircommand.h"
 #include "virstring.h"
@@ -166,7 +165,7 @@ virCapsPtr openvzCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (virCapabilitiesInitNUMA(caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
index 01ad7628455af80de18c6fc62cd02a629a8c7bfc..647c8522ddb58ad392386a7935f46ef86ada7627 100644 (file)
@@ -48,7 +48,6 @@
 #include "openvz_util.h"
 #include "virbuffer.h"
 #include "openvz_conf.h"
-#include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "viralloc.h"
@@ -2162,7 +2161,7 @@ static int
 openvzNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
                   virNodeInfoPtr nodeinfo)
 {
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 
index 39fa0264ccf8fc14791ebacb6d32b189a6f19cf9..1803aa53b74497ed6598eaef2125b506e3d4d12b 100644 (file)
@@ -53,7 +53,6 @@
 #include "viruuid.h"
 #include "domain_conf.h"
 #include "storage_conf.h"
-#include "nodeinfo.h"
 #include "virfile.h"
 #include "interface_conf.h"
 #include "phyp_driver.h"
@@ -335,7 +334,7 @@ phypCapsInit(void)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(caps) < 0) {
+    if (virCapabilitiesInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN
             ("Failed to query host NUMA topology, disabling NUMA capabilities");
index 3d00debc52c8941993ea782316d3ade8066f1fe9..60d2bbcb2305eb8023bf744cdc5029309cf246ac 100644 (file)
@@ -31,7 +31,6 @@
 #include "virfile.h"
 #include "virpidfile.h"
 #include "virprocess.h"
-#include "nodeinfo.h"
 #include "cpu/cpu.h"
 #include "cpu/cpu_x86.h"
 #include "domain_conf.h"
@@ -1124,7 +1123,7 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(caps) < 0) {
+    if (virCapabilitiesInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 35869d441c9d7a648e5296fb901debdb58884c8f..3b33e37bb36073d89f3a37cd6cef30843d09dc6a 100644 (file)
@@ -45,7 +45,6 @@
 #include "viralloc.h"
 #include "datatypes.h"
 #include "virxml.h"
-#include "nodeinfo.h"
 #include "virlog.h"
 #include "cpu/cpu.h"
 #include "domain_nwfilter.h"
index 68044d8c4dc93326ea1a96365d0baef1231583f6..824b9a569e600d8ba7461cb32a6726f0ab826de1 100644 (file)
@@ -64,7 +64,6 @@
 #include "virlog.h"
 #include "datatypes.h"
 #include "virbuffer.h"
-#include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "virnetdevtap.h"
@@ -18293,7 +18292,7 @@ qemuNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 
index 4663c7dee83aded318c27492a88cd29890cc2d66..871653c5a64c9d8f793c55f07d055a62a242b8d9 100644 (file)
@@ -39,7 +39,6 @@
 #include "virbuffer.h"
 #include "virconf.h"
 #include "viralloc.h"
-#include "nodeinfo.h"
 #include "virlog.h"
 #include "domain_nwfilter.h"
 #include "virfile.h"
@@ -65,7 +64,7 @@ virCapsPtr umlCapsInit(void)
      * unexpected failures. We don't want to break the QEMU
      * driver in this scenario, so log errors & carry on
      */
-    if (nodeCapsInitNUMA(caps) < 0) {
+    if (virCapabilitiesInitNUMA(caps) < 0) {
         virCapabilitiesFreeNUMAInfo(caps);
         VIR_WARN("Failed to query host NUMA topology, disabling NUMA capabilities");
     }
index 18e62663ca861826a623ea956ba66b1824c7b23a..f03fdbf68fd62049fbc8f6e504ecdf78a67ab1e2 100644 (file)
@@ -45,7 +45,6 @@
 #include "uml_driver.h"
 #include "uml_conf.h"
 #include "virbuffer.h"
-#include "nodeinfo.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "capabilities.h"
@@ -2770,7 +2769,7 @@ umlNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 
index a64d2e89a9bd66e5c9eb6aa61ddb41daf3cbcb5d..b71506ae5dc31f032412b9a29af13363d6452817 100644 (file)
@@ -29,7 +29,6 @@
 #include "domain_event.h"
 #include "virlog.h"
 #include "viralloc.h"
-#include "nodeinfo.h"
 #include "virhostmem.h"
 #include "virstring.h"
 #include "virfile.h"
@@ -77,7 +76,7 @@ vboxCapsInit(void)
                                    false, false)) == NULL)
         goto no_memory;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (virCapabilitiesInitNUMA(caps) < 0)
         goto no_memory;
 
     if ((guest = virCapabilitiesAddGuest(caps,
@@ -7438,7 +7437,7 @@ static int
 vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
                 virNodeInfoPtr nodeinfo)
 {
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 static int
index 3ced61028e97f9b468a4232bc9eae980812f7ff6..bf4597c4748a7050a5b4c4e8d7ea9618eca245ef 100644 (file)
@@ -27,7 +27,6 @@
 #include "cpu/cpu.h"
 #include "dirname.h"
 #include "viralloc.h"
-#include "nodeinfo.h"
 #include "virfile.h"
 #include "viruuid.h"
 #include "virerror.h"
@@ -66,7 +65,7 @@ vmwareCapsInit(void)
                                    false, false)) == NULL)
         goto error;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (virCapabilitiesInitNUMA(caps) < 0)
         goto error;
 
     /* i686 guests are always supported */
index 3536491c399432c6b703d05619600cf7e383f028..88f1960eb178933aedc95541a7bf5d75f22b55db 100644 (file)
@@ -47,7 +47,6 @@
 #include "configmake.h"
 #include "virfile.h"
 #include "virstoragefile.h"
-#include "nodeinfo.h"
 #include "virstring.h"
 #include "cpu/cpu.h"
 #include "virtypedparam.h"
@@ -116,7 +115,7 @@ vzBuildCapabilities(void)
                                    false, false)) == NULL)
         return NULL;
 
-    if (nodeCapsInitNUMA(caps) < 0)
+    if (virCapabilitiesInitNUMA(caps) < 0)
         goto error;
 
 
@@ -129,7 +128,7 @@ vzBuildCapabilities(void)
                                          emulators[k], virt_types[k]) < 0)
                     goto error;
 
-    if (nodeGetInfo(&nodeinfo))
+    if (virCapabilitiesGetNodeInfo(&nodeinfo))
         goto error;
 
     if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
@@ -925,7 +924,7 @@ vzNodeGetInfo(virConnectPtr conn,
     if (virNodeGetInfoEnsureACL(conn) < 0)
         return -1;
 
-    return nodeGetInfo(nodeinfo);
+    return virCapabilitiesGetNodeInfo(nodeinfo);
 }
 
 static int vzConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
index 3fd17dbee44aabcbac82fef7d147764fb97e3047..c1a50fdc68c5bde607650118b58bc32063739b11 100644 (file)
@@ -26,7 +26,6 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virstring.h"
-#include "nodeinfo.h"
 #include "virlog.h"
 #include "datatypes.h"
 #include "domain_conf.h"
index c88e7ea00751fc35909dc1ca6badac8c5af2f12a..5a94ad79e64c94ca40abef686f6bd85b7ea411c7 100644 (file)
@@ -64,7 +64,6 @@
 #include "viruri.h"
 #include "vircommand.h"
 #include "virnodesuspend.h"
-#include "nodeinfo.h"
 #include "virhostmem.h"
 #include "configmake.h"
 #include "virstring.h"
index 7bf5447ad26981cfef1b4d1d2c273fc7738f8f0d..bfbf6a42f611e04743d6d1e06c9ba36aeec3d367 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "testutils.h"
 #include "internal.h"
-#include "nodeinfo.h"
 #include "viralloc.h"
 #include "vircommand.h"
 #include "virfile.h"