]> xenbits.xensource.com Git - libvirt.git/commitdiff
Merge processinfo.{c,h} into virprocess.{c,h}
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 13 Dec 2012 14:58:41 +0000 (14:58 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Dec 2012 11:19:45 +0000 (11:19 +0000)
po/POTFILES.in
src/Makefile.am
src/libvirt_private.syms
src/lxc/lxc_controller.c
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/util/processinfo.c [deleted file]
src/util/processinfo.h [deleted file]
src/util/virprocess.c
src/util/virprocess.h

index 5eab6a8e2a687456f934e79557c69aa9305be887..2dc72f6c3c752b799c8eec542e90c491b622f351 100644 (file)
@@ -139,7 +139,6 @@ src/test/test_driver.c
 src/uml/uml_conf.c
 src/uml/uml_driver.c
 src/util/iohelper.c
-src/util/processinfo.c
 src/util/sexpr.c
 src/util/stats_linux.c
 src/util/storage_file.c
index fbcb208e8f82ea08eca76be0185aaf3b9f19d03e..cbdfc45bc8c58e61c784a5a0967e60fb588a1352 100644 (file)
@@ -53,7 +53,6 @@ augeastest_DATA =
 # These files are not related to driver APIs. Simply generic
 # helper APIs for various purposes
 UTIL_SOURCES =                                                 \
-               util/processinfo.c util/processinfo.h           \
                util/sexpr.c util/sexpr.h                       \
                util/stats_linux.c util/stats_linux.h           \
                util/storage_file.c util/storage_file.h         \
index bf7f65b6024a9767299dc82d74e9cc205341f349..497d5d3a795ddfaafa3cc6c2a6376dfba64c0dc0 100644 (file)
@@ -1028,11 +1028,6 @@ pciResetDevice;
 pciWaitForDeviceCleanup;
 
 
-# processinfo.h
-virProcessInfoGetAffinity;
-virProcessInfoSetAffinity;
-
-
 # secret_conf.h
 virSecretDefFormat;
 virSecretDefFree;
@@ -1794,8 +1789,10 @@ virPidFileWritePath;
 
 # virprocess.h
 virProcessAbort;
+virProcessGetAffinity;
 virProcessKill;
 virProcessKillPainfully;
+virProcessSetAffinity;
 virProcessTranslateStatus;
 virProcessWait;
 
index 4520a5f0d9d26e70aea6d94bf6c0a5214d586fa8..8283c8ff72c5ab1dd1875c54c261236f7807021b 100644 (file)
@@ -67,7 +67,6 @@
 #include "virfile.h"
 #include "virpidfile.h"
 #include "vircommand.h"
-#include "processinfo.h"
 #include "nodeinfo.h"
 #include "virrandom.h"
 #include "virprocess.h"
@@ -541,7 +540,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
      * so use '0' to indicate our own process ID. No threads are
      * running at this point
      */
-    if (virProcessInfoSetAffinity(0 /* Self */, cpumapToSet) < 0) {
+    if (virProcessSetAffinity(0 /* Self */, cpumapToSet) < 0) {
         virBitmapFree(cpumap);
         return -1;
     }
index 677352de3a47b240e71e3330fd40e7b7ed9cfc3a..02dd77b69717b38bc6480ba239f861a31fc4aca1 100644 (file)
@@ -73,7 +73,7 @@
 #include "node_device_conf.h"
 #include "virpci.h"
 #include "virusb.h"
-#include "processinfo.h"
+#include "virprocess.h"
 #include "libvirt_internal.h"
 #include "xml.h"
 #include "cpu/cpu.h"
@@ -3880,8 +3880,8 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
                         goto cleanup;
                     }
                 } else {
-                    if (virProcessInfoSetAffinity(cpupids[i],
-                                                  vcpupin->cpumask) < 0) {
+                    if (virProcessSetAffinity(cpupids[i],
+                                              vcpupin->cpumask) < 0) {
                         virReportError(VIR_ERR_SYSTEM_ERROR,
                                        _("failed to set cpu affinity for vcpu %d"),
                                        i);
@@ -4154,7 +4154,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
                 goto cleanup;
             }
         } else {
-            if (virProcessInfoSetAffinity(priv->vcpupids[vcpu], pcpumap) < 0) {
+            if (virProcessSetAffinity(priv->vcpupids[vcpu], pcpumap) < 0) {
                 virReportError(VIR_ERR_SYSTEM_ERROR,
                                _("failed to set cpu affinity for vcpu %d"),
                                vcpu);
@@ -4422,7 +4422,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
                     }
                 }
             } else {
-                if (virProcessInfoSetAffinity(pid, pcpumap) < 0) {
+                if (virProcessSetAffinity(pid, pcpumap) < 0) {
                     virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
                                    _("failed to set cpu affinity for "
                                      "emulator threads"));
@@ -4640,8 +4640,8 @@ qemuDomainGetVcpus(virDomainPtr dom,
                     unsigned char *tmpmap = NULL;
                     int tmpmapLen = 0;
 
-                    if (virProcessInfoGetAffinity(priv->vcpupids[v],
-                                                  &map, maxcpu) < 0)
+                    if (virProcessGetAffinity(priv->vcpupids[v],
+                                              &map, maxcpu) < 0)
                         goto cleanup;
                     virBitmapToData(map, &tmpmap, &tmpmapLen);
                     if (tmpmapLen > maplen)
index c43c968e7611d0f1cdc61366842b7f6fccd6044c..0e823bddfb96d0c7f14d086b7428465570a6efc4 100644 (file)
@@ -60,7 +60,6 @@
 #include "util.h"
 #include "c-ctype.h"
 #include "nodeinfo.h"
-#include "processinfo.h"
 #include "domain_audit.h"
 #include "domain_nwfilter.h"
 #include "locking/domain_lock.h"
@@ -1980,7 +1979,7 @@ qemuProcessInitCpuAffinity(virQEMUDriverPtr driver,
      * so use '0' to indicate our own process ID. No threads are
      * running at this point
      */
-    if (virProcessInfoSetAffinity(0 /* Self */, cpumapToSet) < 0)
+    if (virProcessSetAffinity(0 /* Self */, cpumapToSet) < 0)
         goto cleanup;
 
     ret = 0;
@@ -2045,8 +2044,8 @@ qemuProcessSetVcpuAffinities(virConnectPtr conn ATTRIBUTE_UNUSED,
     for (n = 0; n < def->cputune.nvcpupin; n++) {
         vcpu = def->cputune.vcpupin[n]->vcpuid;
 
-        if (virProcessInfoSetAffinity(priv->vcpupids[vcpu],
-                                      def->cputune.vcpupin[n]->cpumask) < 0) {
+        if (virProcessSetAffinity(priv->vcpupids[vcpu],
+                                  def->cputune.vcpupin[n]->cpumask) < 0) {
             goto cleanup;
         }
     }
@@ -2072,7 +2071,7 @@ qemuProcessSetEmulatorAffinities(virConnectPtr conn ATTRIBUTE_UNUSED,
     else
         return 0;
 
-    ret = virProcessInfoSetAffinity(vm->pid, cpumask);
+    ret = virProcessSetAffinity(vm->pid, cpumask);
     return ret;
 }
 
diff --git a/src/util/processinfo.c b/src/util/processinfo.c
deleted file mode 100644 (file)
index 6cca426..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (C) 2009-2010, 2012 Red Hat, Inc.
- *
- * 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/>.
- *
- * Authors:
- *     Daniel P. Berrange <berrange@redhat.com>
- */
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <sched.h>
-
-#include "processinfo.h"
-#include "virterror_internal.h"
-
-#define VIR_FROM_THIS VIR_FROM_NONE
-
-#if HAVE_SCHED_GETAFFINITY
-
-int virProcessInfoSetAffinity(pid_t pid, virBitmapPtr map)
-{
-    int i;
-    bool set = false;
-# ifdef CPU_ALLOC
-    /* New method dynamically allocates cpu mask, allowing unlimted cpus */
-    int numcpus = 1024;
-    size_t masklen;
-    cpu_set_t *mask;
-
-    /* Not only may the statically allocated cpu_set_t be too small,
-     * but there is no way to ask the kernel what size is large enough.
-     * So you have no option but to pick a size, try, catch EINVAL,
-     * enlarge, and re-try.
-     *
-     * http://lkml.org/lkml/2009/7/28/620
-     */
-realloc:
-    masklen = CPU_ALLOC_SIZE(numcpus);
-    mask = CPU_ALLOC(numcpus);
-
-    if (!mask) {
-        virReportOOMError();
-        return -1;
-    }
-
-    CPU_ZERO_S(masklen, mask);
-    for (i = 0 ; i < virBitmapSize(map); i++) {
-        if (virBitmapGetBit(map, i, &set) < 0)
-            return -1;
-        if (set)
-            CPU_SET_S(i, masklen, mask);
-    }
-
-    if (sched_setaffinity(pid, masklen, mask) < 0) {
-        CPU_FREE(mask);
-        if (errno == EINVAL &&
-            numcpus < (1024 << 8)) { /* 262144 cpus ought to be enough for anyone */
-            numcpus = numcpus << 2;
-            goto realloc;
-        }
-        virReportSystemError(errno,
-                             _("cannot set CPU affinity on process %d"), pid);
-        return -1;
-    }
-    CPU_FREE(mask);
-# else
-    /* Legacy method uses a fixed size cpu mask, only allows up to 1024 cpus */
-    cpu_set_t mask;
-
-    CPU_ZERO(&mask);
-    for (i = 0 ; i < virBitmapSize(map); i++) {
-        if (virBitmapGetBit(map, i, &set) < 0)
-            return -1;
-        if (set)
-            CPU_SET(i, &mask);
-    }
-
-    if (sched_setaffinity(pid, sizeof(mask), &mask) < 0) {
-        virReportSystemError(errno,
-                             _("cannot set CPU affinity on process %d"), pid);
-        return -1;
-    }
-# endif
-
-    return 0;
-}
-
-int virProcessInfoGetAffinity(pid_t pid,
-                              virBitmapPtr *map,
-                              int maxcpu)
-{
-    int i;
-# ifdef CPU_ALLOC
-    /* New method dynamically allocates cpu mask, allowing unlimted cpus */
-    int numcpus = 1024;
-    size_t masklen;
-    cpu_set_t *mask;
-
-    /* Not only may the statically allocated cpu_set_t be too small,
-     * but there is no way to ask the kernel what size is large enough.
-     * So you have no option but to pick a size, try, catch EINVAL,
-     * enlarge, and re-try.
-     *
-     * http://lkml.org/lkml/2009/7/28/620
-     */
-realloc:
-    masklen = CPU_ALLOC_SIZE(numcpus);
-    mask = CPU_ALLOC(numcpus);
-
-    if (!mask) {
-        virReportOOMError();
-        return -1;
-    }
-
-    CPU_ZERO_S(masklen, mask);
-    if (sched_getaffinity(pid, masklen, mask) < 0) {
-        CPU_FREE(mask);
-        if (errno == EINVAL &&
-            numcpus < (1024 << 8)) { /* 262144 cpus ought to be enough for anyone */
-            numcpus = numcpus << 2;
-            goto realloc;
-        }
-        virReportSystemError(errno,
-                             _("cannot get CPU affinity of process %d"), pid);
-        return -1;
-    }
-
-    *map = virBitmapNew(maxcpu);
-    if (!*map) {
-        virReportOOMError();
-        return -1;
-    }
-
-    for (i = 0 ; i < maxcpu ; i++)
-        if (CPU_ISSET_S(i, masklen, mask))
-            ignore_value(virBitmapSetBit(*map, i));
-    CPU_FREE(mask);
-# else
-    /* Legacy method uses a fixed size cpu mask, only allows up to 1024 cpus */
-    cpu_set_t mask;
-
-    CPU_ZERO(&mask);
-    if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) {
-        virReportSystemError(errno,
-                             _("cannot get CPU affinity of process %d"), pid);
-        return -1;
-    }
-
-    for (i = 0 ; i < maxcpu ; i++)
-        if (CPU_ISSET(i, &mask))
-            ignore_value(virBitmapSetBit(*map, i));
-# endif
-
-    return 0;
-}
-
-#elif defined(__FreeBSD__)
-
-int virProcessInfoSetAffinity(pid_t pid ATTRIBUTE_UNUSED,
-                              virBitmapPtr map)
-{
-    if (!virBitmapIsAllSet(map)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("setting process affinity isn't supported "
-                         "on FreeBSD yet"));
-        return -1;
-    }
-
-    return 0;
-}
-
-int virProcessInfoGetAffinity(pid_t pid ATTRIBUTE_UNUSED,
-                              virBitmapPtr *map,
-                              int maxcpu)
-{
-    if (!(*map = virBitmapNew(maxcpu))) {
-        virReportOOMError();
-        return -1;
-    }
-    virBitmapSetAll(*map);
-
-    return 0;
-}
-
-#else /* HAVE_SCHED_GETAFFINITY */
-
-int virProcessInfoSetAffinity(pid_t pid ATTRIBUTE_UNUSED,
-                              virBitmapPtr map ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Process CPU affinity is not supported on this platform"));
-    return -1;
-}
-
-int virProcessInfoGetAffinity(pid_t pid ATTRIBUTE_UNUSED,
-                              virBitmapPtr *map ATTRIBUTE_UNUSED,
-                              int maxcpu ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Process CPU affinity is not supported on this platform"));
-    return -1;
-}
-#endif /* HAVE_SCHED_GETAFFINITY */
diff --git a/src/util/processinfo.h b/src/util/processinfo.h
deleted file mode 100644 (file)
index 0ae23c6..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 Red Hat, Inc.
- *
- * 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/>.
- *
- * Authors:
- *     Daniel P. Berrange <berrange@redhat.com>
- */
-
-#ifndef __VIR_PROCESSINFO_H__
-# define __VIR_PROCESSINFO_H__
-
-# include "internal.h"
-# include "virbitmap.h"
-
-int virProcessInfoSetAffinity(pid_t pid, virBitmapPtr map);
-
-int virProcessInfoGetAffinity(pid_t pid,
-                              virBitmapPtr *map,
-                              int maxcpu);
-
-#endif /* __VIR_PROCESSINFO_H__ */
index 8070b8bff0b72467e1105fd14acc5e357c18dd85..3959ae19b1cd3332c56969577ea758f84ad40bda 100644 (file)
@@ -25,6 +25,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <sys/wait.h>
+#include <sched.h>
 
 #include "virprocess.h"
 #include "virterror_internal.h"
@@ -300,3 +301,191 @@ virProcessKillPainfully(pid_t pid, bool force)
 cleanup:
     return ret;
 }
+
+
+#if HAVE_SCHED_GETAFFINITY
+
+int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
+{
+    int i;
+    bool set = false;
+# ifdef CPU_ALLOC
+    /* New method dynamically allocates cpu mask, allowing unlimted cpus */
+    int numcpus = 1024;
+    size_t masklen;
+    cpu_set_t *mask;
+
+    /* Not only may the statically allocated cpu_set_t be too small,
+     * but there is no way to ask the kernel what size is large enough.
+     * So you have no option but to pick a size, try, catch EINVAL,
+     * enlarge, and re-try.
+     *
+     * http://lkml.org/lkml/2009/7/28/620
+     */
+realloc:
+    masklen = CPU_ALLOC_SIZE(numcpus);
+    mask = CPU_ALLOC(numcpus);
+
+    if (!mask) {
+        virReportOOMError();
+        return -1;
+    }
+
+    CPU_ZERO_S(masklen, mask);
+    for (i = 0 ; i < virBitmapSize(map); i++) {
+        if (virBitmapGetBit(map, i, &set) < 0)
+            return -1;
+        if (set)
+            CPU_SET_S(i, masklen, mask);
+    }
+
+    if (sched_setaffinity(pid, masklen, mask) < 0) {
+        CPU_FREE(mask);
+        if (errno == EINVAL &&
+            numcpus < (1024 << 8)) { /* 262144 cpus ought to be enough for anyone */
+            numcpus = numcpus << 2;
+            goto realloc;
+        }
+        virReportSystemError(errno,
+                             _("cannot set CPU affinity on process %d"), pid);
+        return -1;
+    }
+    CPU_FREE(mask);
+# else
+    /* Legacy method uses a fixed size cpu mask, only allows up to 1024 cpus */
+    cpu_set_t mask;
+
+    CPU_ZERO(&mask);
+    for (i = 0 ; i < virBitmapSize(map); i++) {
+        if (virBitmapGetBit(map, i, &set) < 0)
+            return -1;
+        if (set)
+            CPU_SET(i, &mask);
+    }
+
+    if (sched_setaffinity(pid, sizeof(mask), &mask) < 0) {
+        virReportSystemError(errno,
+                             _("cannot set CPU affinity on process %d"), pid);
+        return -1;
+    }
+# endif
+
+    return 0;
+}
+
+int virProcessGetAffinity(pid_t pid,
+                          virBitmapPtr *map,
+                          int maxcpu)
+{
+    int i;
+# ifdef CPU_ALLOC
+    /* New method dynamically allocates cpu mask, allowing unlimted cpus */
+    int numcpus = 1024;
+    size_t masklen;
+    cpu_set_t *mask;
+
+    /* Not only may the statically allocated cpu_set_t be too small,
+     * but there is no way to ask the kernel what size is large enough.
+     * So you have no option but to pick a size, try, catch EINVAL,
+     * enlarge, and re-try.
+     *
+     * http://lkml.org/lkml/2009/7/28/620
+     */
+realloc:
+    masklen = CPU_ALLOC_SIZE(numcpus);
+    mask = CPU_ALLOC(numcpus);
+
+    if (!mask) {
+        virReportOOMError();
+        return -1;
+    }
+
+    CPU_ZERO_S(masklen, mask);
+    if (sched_getaffinity(pid, masklen, mask) < 0) {
+        CPU_FREE(mask);
+        if (errno == EINVAL &&
+            numcpus < (1024 << 8)) { /* 262144 cpus ought to be enough for anyone */
+            numcpus = numcpus << 2;
+            goto realloc;
+        }
+        virReportSystemError(errno,
+                             _("cannot get CPU affinity of process %d"), pid);
+        return -1;
+    }
+
+    *map = virBitmapNew(maxcpu);
+    if (!*map) {
+        virReportOOMError();
+        return -1;
+    }
+
+    for (i = 0 ; i < maxcpu ; i++)
+        if (CPU_ISSET_S(i, masklen, mask))
+            ignore_value(virBitmapSetBit(*map, i));
+    CPU_FREE(mask);
+# else
+    /* Legacy method uses a fixed size cpu mask, only allows up to 1024 cpus */
+    cpu_set_t mask;
+
+    CPU_ZERO(&mask);
+    if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) {
+        virReportSystemError(errno,
+                             _("cannot get CPU affinity of process %d"), pid);
+        return -1;
+    }
+
+    for (i = 0 ; i < maxcpu ; i++)
+        if (CPU_ISSET(i, &mask))
+            ignore_value(virBitmapSetBit(*map, i));
+# endif
+
+    return 0;
+}
+
+#elif defined(__FreeBSD__)
+
+int virProcessSetAffinity(pid_t pid ATTRIBUTE_UNUSED,
+                          virBitmapPtr map)
+{
+    if (!virBitmapIsAllSet(map)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("setting process affinity isn't supported "
+                         "on FreeBSD yet"));
+        return -1;
+    }
+
+    return 0;
+}
+
+int virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED,
+                          virBitmapPtr *map,
+                          int maxcpu)
+{
+    if (!(*map = virBitmapNew(maxcpu))) {
+        virReportOOMError();
+        return -1;
+    }
+    virBitmapSetAll(*map);
+
+    return 0;
+}
+
+#else /* HAVE_SCHED_GETAFFINITY */
+
+int virProcessSetAffinity(pid_t pid ATTRIBUTE_UNUSED,
+                          virBitmapPtr map ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Process CPU affinity is not supported on this platform"));
+    return -1;
+}
+
+int virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED,
+                          virBitmapPtr *map ATTRIBUTE_UNUSED,
+                          int maxcpu ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Process CPU affinity is not supported on this platform"));
+    return -1;
+}
+#endif /* HAVE_SCHED_GETAFFINITY */
index d537d92be5f667ade0243a75b1e8822a1c8b9331..8724f649f283e41cb018f7054b55f22ad5fc3978 100644 (file)
@@ -25,6 +25,7 @@
 # include <sys/types.h>
 
 # include "internal.h"
+# include "virbitmap.h"
 
 char *
 virProcessTranslateStatus(int status);
@@ -40,5 +41,10 @@ int virProcessKill(pid_t pid, int sig);
 
 int virProcessKillPainfully(pid_t pid, bool force);
 
+int virProcessSetAffinity(pid_t pid, virBitmapPtr map);
+
+int virProcessGetAffinity(pid_t pid,
+                          virBitmapPtr *map,
+                          int maxcpu);
 
 #endif /* __VIR_PROCESS_H__ */