[libvirt] [PATCH] qemu: Start domain on a node without cpu affinity

libvirt affinity wrappers don't support macOS Thread Affinity API: https://developer.apple.com/library/archive/releasenotes/Performance/RN-Affi... virProcessSetAffinity stub prevents libvirt from starting a qemu domain on macOS: $ virsh start vm error: Failed to start domain vm error: Process CPU affinity is not supported on this platform: Function not implemented With the patch a VM can be started on macOS but some affinity-related commands will return errors: $ virsh vcpuinfo vm error: Requested operation is not valid: cpu affinity is not supported $ virsh vcpupin vm VCPU: CPU Affinity ---------------------------------- 0: 0-7 $ virsh vcpupin vm --live --vcpu 0 --cpulist 7 error: operation failed: Virt type 'qemu' does not support vCPU pinning $ virsh emulatorpin vm emulator: CPU Affinity ---------------------------------- *: 0-7 $ virsh emulatorpin vm --live --cpulist 7 error: Requested operation is not valid: cpu affinity is not supported The patch also fixes virmacmaptest on macOS Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- src/qemu/qemu_driver.c | 6 ++++++ src/util/virprocess.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 21e9e87ddd..2e225b1ede 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5245,6 +5245,12 @@ qemuDomainPinEmulator(virDomainPtr dom, if (virDomainPinEmulatorEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; + if (!qemuDomainHasVcpuPids(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + goto cleanup; + } + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 3988f5546c..7eaafd29f2 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -598,7 +598,7 @@ int virProcessSetAffinity(pid_t pid ATTRIBUTE_UNUSED, { virReportSystemError(ENOSYS, "%s", _("Process CPU affinity is not supported on this platform")); - return -1; + return 0; } virBitmapPtr -- 2.15.2 (Apple Git-101.1)

On Wed, Aug 22, 2018 at 00:31:29 +0300, Roman Bolshakov wrote:
libvirt affinity wrappers don't support macOS Thread Affinity API: https://developer.apple.com/library/archive/releasenotes/Performance/RN-Affi...
virProcessSetAffinity stub prevents libvirt from starting a qemu domain on macOS:
$ virsh start vm error: Failed to start domain vm error: Process CPU affinity is not supported on this platform: Function not implemented
With the patch a VM can be started on macOS but some affinity-related commands will return errors:
$ virsh vcpuinfo vm error: Requested operation is not valid: cpu affinity is not supported
$ virsh vcpupin vm VCPU: CPU Affinity ---------------------------------- 0: 0-7
$ virsh vcpupin vm --live --vcpu 0 --cpulist 7 error: operation failed: Virt type 'qemu' does not support vCPU pinning
$ virsh emulatorpin vm emulator: CPU Affinity ---------------------------------- *: 0-7
$ virsh emulatorpin vm --live --cpulist 7 error: Requested operation is not valid: cpu affinity is not supported
The patch also fixes virmacmaptest on macOS
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- src/qemu/qemu_driver.c | 6 ++++++ src/util/virprocess.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 21e9e87ddd..2e225b1ede 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5245,6 +5245,12 @@ qemuDomainPinEmulator(virDomainPtr dom, if (virDomainPinEmulatorEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup;
+ if (!qemuDomainHasVcpuPids(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + goto cleanup; + } + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 3988f5546c..7eaafd29f2 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -598,7 +598,7 @@ int virProcessSetAffinity(pid_t pid ATTRIBUTE_UNUSED, { virReportSystemError(ENOSYS, "%s", _("Process CPU affinity is not supported on this platform")); - return -1; + return 0;
This is not a good idea. The caller should make sure that it does not call this function if we need to support such a code path. If you blindly return 0 here other callers might get confused. Also setting an error and returning success is generally wrong.

On Wed, Aug 22, 2018 at 09:48:10AM +0200, Peter Krempa wrote:
On Wed, Aug 22, 2018 at 00:31:29 +0300, Roman Bolshakov wrote:
libvirt affinity wrappers don't support macOS Thread Affinity API: https://developer.apple.com/library/archive/releasenotes/Performance/RN-Affi...
virProcessSetAffinity stub prevents libvirt from starting a qemu domain on macOS:
$ virsh start vm error: Failed to start domain vm error: Process CPU affinity is not supported on this platform: Function not implemented
With the patch a VM can be started on macOS but some affinity-related commands will return errors:
$ virsh vcpuinfo vm error: Requested operation is not valid: cpu affinity is not supported
$ virsh vcpupin vm VCPU: CPU Affinity ---------------------------------- 0: 0-7
$ virsh vcpupin vm --live --vcpu 0 --cpulist 7 error: operation failed: Virt type 'qemu' does not support vCPU pinning
$ virsh emulatorpin vm emulator: CPU Affinity ---------------------------------- *: 0-7
$ virsh emulatorpin vm --live --cpulist 7 error: Requested operation is not valid: cpu affinity is not supported
The patch also fixes virmacmaptest on macOS
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- src/qemu/qemu_driver.c | 6 ++++++ src/util/virprocess.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 21e9e87ddd..2e225b1ede 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5245,6 +5245,12 @@ qemuDomainPinEmulator(virDomainPtr dom, if (virDomainPinEmulatorEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup;
+ if (!qemuDomainHasVcpuPids(vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + goto cleanup; + } + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 3988f5546c..7eaafd29f2 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -598,7 +598,7 @@ int virProcessSetAffinity(pid_t pid ATTRIBUTE_UNUSED, { virReportSystemError(ENOSYS, "%s", _("Process CPU affinity is not supported on this platform")); - return -1; + return 0;
This is not a good idea. The caller should make sure that it does not call this function if we need to support such a code path.
Specifically I think you just need to turn qemuProcessInitCpuAffinity into a no-op on macOS builds. Of course if its possible to actually implement virProcessSetAffinity on macOS that's an option too :-) Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (3)
-
Daniel P. Berrangé
-
Peter Krempa
-
Roman Bolshakov