]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Accept TIDs for virProcess{Get,Set}Affinity() on BSD
authorAndrea Bolognani <abologna@redhat.com>
Fri, 23 Feb 2024 00:29:28 +0000 (01:29 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 19 Mar 2024 17:34:25 +0000 (18:34 +0100)
Depending on the situation, the IDs that we pass to these
functions can be either referring to processes or threads.

Linux doesn't have separate interfaces for one or the other,
but FreeBSD does and we're explicitly telling it that the ID
refers to a process. When it refers to a thread instead, the
call will fail, and the VM will not be able to start.

Luckily, another possible choice is CPU_WHICH_TIDPID, which
makes things behave the same as Linux.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virprocess.c

index 047b0aa0cdfd202081b7260962691514484c9aad..8384bd1378ed0ec96170991455f27c55c77a1c59 100644 (file)
@@ -551,7 +551,7 @@ int virProcessSetAffinity(pid_t pid,
             CPU_SET(i, &mask);
     }
 
-    if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid,
+    if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
                            sizeof(mask), &mask) != 0) {
         if (quiet) {
             VIR_DEBUG("cannot set CPU affinity on process %d: %s",
@@ -574,7 +574,7 @@ virProcessGetAffinity(pid_t pid)
     virBitmap *ret = NULL;
 
     CPU_ZERO(&mask);
-    if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid,
+    if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid,
                            sizeof(mask), &mask) != 0) {
         virReportSystemError(errno,
                              _("cannot get CPU affinity of process %1$d"), pid);