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
# 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 \
pciWaitForDeviceCleanup;
-# processinfo.h
-virProcessInfoGetAffinity;
-virProcessInfoSetAffinity;
-
-
# secret_conf.h
virSecretDefFormat;
virSecretDefFree;
# virprocess.h
virProcessAbort;
+virProcessGetAffinity;
virProcessKill;
virProcessKillPainfully;
+virProcessSetAffinity;
virProcessTranslateStatus;
virProcessWait;
#include "virfile.h"
#include "virpidfile.h"
#include "vircommand.h"
-#include "processinfo.h"
#include "nodeinfo.h"
#include "virrandom.h"
#include "virprocess.h"
* 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;
}
#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"
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);
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);
}
}
} 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"));
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)
#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"
* 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;
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;
}
}
else
return 0;
- ret = virProcessInfoSetAffinity(vm->pid, cpumask);
+ ret = virProcessSetAffinity(vm->pid, cpumask);
return ret;
}
+++ /dev/null
-/*
- * 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 */
+++ /dev/null
-/*
- * 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__ */
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
+#include <sched.h>
#include "virprocess.h"
#include "virterror_internal.h"
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 */
# include <sys/types.h>
# include "internal.h"
+# include "virbitmap.h"
char *
virProcessTranslateStatus(int status);
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__ */