Suggested-by: Ján Tomko <jtomko(a)redhat.com>
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/lxc/lxc_controller.c | 2 +-
src/qemu/qemu_driver.c | 7 ++++---
src/qemu/qemu_process.c | 10 +++++-----
src/util/virprocess.c | 32 +++++++++++++++++++++++---------
src/util/virprocess.h | 2 +-
5 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 0a496fb7886c..37a28ac2f3c1 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -775,7 +775,7 @@ static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
* so use '0' to indicate our own process ID. No threads are
* running at this point
*/
- if (virProcessSetAffinity(0 /* Self */, cpumapToSet) < 0) {
+ if (virProcessSetAffinity(0 /* Self */, cpumapToSet, false) < 0) {
virBitmapFree(cpumap);
return -1;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ce72e1021d16..a792a1283253 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4529,7 +4529,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
goto cleanup;
}
- if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), cpumap) < 0)
+ if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu),
+ cpumap, false) < 0)
goto cleanup;
}
@@ -4747,7 +4748,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
}
}
- if (virProcessSetAffinity(vm->pid, pcpumap) < 0)
+ if (virProcessSetAffinity(vm->pid, pcpumap, false) < 0)
goto endjob;
virBitmapFree(def->cputune.emulatorpin);
@@ -5222,7 +5223,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
}
}
- if (virProcessSetAffinity(iothrid->thread_id, pcpumap) < 0)
+ if (virProcessSetAffinity(iothrid->thread_id, pcpumap, false) < 0)
goto endjob;
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 17d083d192a5..423c60c7c85b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2573,7 +2573,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
}
if (cpumapToSet &&
- virProcessSetAffinity(vm->pid, cpumapToSet) < 0) {
+ virProcessSetAffinity(vm->pid, cpumapToSet, false) < 0) {
/*
* We only want to error out if we failed to set the affinity to
* user-requested mapping. If we are just trying to reset the affinity
@@ -2743,7 +2743,8 @@ qemuProcessSetupPid(virDomainObjPtr vm,
affinity_cpumask = use_cpumask;
/* Setup legacy affinity. */
- if (affinity_cpumask && virProcessSetAffinity(pid, affinity_cpumask) < 0)
{
+ if (affinity_cpumask &&
+ virProcessSetAffinity(pid, affinity_cpumask, false) < 0) {
/*
* We only want to error out if we failed to set the affinity to
* user-requested mapping. If we are just trying to reset the affinity
@@ -2751,9 +2752,8 @@ qemuProcessSetupPid(virDomainObjPtr vm,
* 1) libvirtd does not have CAP_SYS_NICE
* 2) libvirtd does not run on all CPUs
*
- * However since this scenario is very improbable, we rather skip
- * reporting the error because it helps running libvirtd in a a scenario
- * where pinning is handled by someone else.
+ * This scenario can easily occurr when libvirtd is run inside a
+ * container with restrictive permissions and CPU pinning.
*
* See also:
https://bugzilla.redhat.com/1819801#c2
*/
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9de356505104..e9df56389621 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -441,7 +441,7 @@ int virProcessKillPainfully(pid_t pid, bool force)
#if WITH_SCHED_GETAFFINITY
-int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
+int virProcessSetAffinity(pid_t pid, virBitmapPtr map, bool quiet)
{
size_t i;
int numcpus = 1024;
@@ -479,9 +479,14 @@ int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
numcpus = numcpus << 2;
goto realloc;
}
- virReportSystemError(errno,
- _("cannot set CPU affinity on process %d"), pid);
- return -1;
+ if (quiet) {
+ VIR_DEBUG("cannot set CPU affinity on process %d: %s",
+ pid, g_strerror(errno));
+ } else {
+ virReportSystemError(errno,
+ _("cannot set CPU affinity on process %d"),
pid);
+ return -1;
+ }
}
CPU_FREE(mask);
@@ -533,7 +538,8 @@ virProcessGetAffinity(pid_t pid)
#elif defined(WITH_BSD_CPU_AFFINITY)
int virProcessSetAffinity(pid_t pid,
- virBitmapPtr map)
+ virBitmapPtr map,
+ bool quiet)
{
size_t i;
cpuset_t mask;
@@ -546,9 +552,14 @@ int virProcessSetAffinity(pid_t pid,
if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid,
sizeof(mask), &mask) != 0) {
- virReportSystemError(errno,
- _("cannot set CPU affinity on process %d"), pid);
- return -1;
+ if (quiet) {
+ VIR_DEBUG("cannot set CPU affinity on process %d: %s",
+ pid, g_strerror(errno));
+ } else {
+ virReportSystemError(errno,
+ _("cannot set CPU affinity on process %d"),
pid);
+ return -1;
+ }
}
return 0;
@@ -582,8 +593,11 @@ virProcessGetAffinity(pid_t pid)
#else /* WITH_SCHED_GETAFFINITY */
int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED,
- virBitmapPtr map G_GNUC_UNUSED)
+ virBitmapPtr map G_GNUC_UNUSED,
+ bool quiet G_GNUC_UNUSED)
{
+ /* The @quiet parameter is ignored here, it is used only for silencing
+ * actual failures. */
virReportSystemError(ENOSYS, "%s",
_("Process CPU affinity is not supported on this
platform"));
return -1;
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 437deb18305b..34210d6c9d62 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -58,7 +58,7 @@ int virProcessKillPainfullyDelay(pid_t pid,
bool force,
unsigned int extradelay);
-int virProcessSetAffinity(pid_t pid, virBitmapPtr map);
+int virProcessSetAffinity(pid_t pid, virBitmapPtr map, bool quiet);
virBitmapPtr virProcessGetAffinity(pid_t pid);
--
2.28.0