Subject: bug#36634: Virtual Machine Manager (virt-manager)

From: Miguel Arruga Vivas <[email-masked]>
Date: Sun, 27 Oct 2019 10:37:19 +0100

Hello again,

The two patches attached create the cgroup directory needed and remove
the warning for the ip binary missing.  Still the following errors
are emitted to the log. 

--------------------8<-------------------
error : virConnectGetCPUModelNames:1109 : this function is not supported by the connection driver: virConnectGetCPUModelNames
error : virConnectGetAllDomainStats:11705 : this function is not supported by the connection driver: virConnectGetAllDomainStats
error : virCgroupSetValueRaw:473 : Unable to write to '/sys/fs/cgroup/unified/machine/qemu-1-Guix.libvirt-qemu/tasks': No such file or directory
error : virCgroupRemoveRecursively:2383 : Unable to remove /sys/fs/cgroup/unified/machine/qemu-1-Guix.libvirt-qemu/ (16) 
-------------------->8-------------------

The last two may indicate there may be lurking another bug in the
cgroups configuration, but at least the machines can be created and
started/stopped seamlessly.  What do you think?

Happy hacking!
Miguel
>From a5dd055ea0fc20420cca6df2d38302596d397c49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <[email-masked]>
Date: Sun, 27 Oct 2019 03:56:17 +0100
Subject: [PATCH 1/2] services: libvirtd: Create required control groups.

* gnu/services/virtualization.scm (libvirt-shepherd-service)
[libvirtd-activation]: New shepherd service.
[libvirtd]: Add a requirement of the new service.
---
 gnu/services/virtualization.scm | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index bc8ac9b40a..2f26945efd 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -428,8 +428,19 @@ potential infinite waits blocking libvirt."))
   (let* ((config-file (libvirt-conf-file config))
          (libvirt (libvirt-configuration-libvirt config)))
     (list (shepherd-service
+           ;; See https://libvirt.org/cgroups.html#currentLayoutGeneric
+           (documentation "Create the cgroup hierarchy required by libvirt.")
+           (provision '(libvirtd-activation))
+           (requirement '(file-system-/sys/fs/cgroup))
+           (one-shot? #t)
+           (start #~(lambda args
+                      (let ((path "/sys/fs/cgroup/unified/machine"))
+                        (or (access? path F_OK) (mkdir path)))))
+           (stop #~(lambda args #t)))
+          (shepherd-service
            (documentation "Run the libvirt daemon.")
            (provision '(libvirtd))
+           (requirement '(libvirtd-activation))
            (start #~(make-forkexec-constructor
                      (list (string-append #$libvirt "/sbin/libvirtd")
                            "-f" #$config-file)
-- 
2.23.0

>From 24f7c06a47562f410ceb982a3b2a0d44980de392 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <[email-masked]>
Date: Sun, 27 Oct 2019 03:59:23 +0100
Subject: [PATCH 2/2] services: libvirtd: Provide ip binary at runtime.

* gnu/services/virtualization.scm (libvirt-shepherd-service): Add sbin to
the PATH variable, as ip binary is installed there.
---
 gnu/services/virtualization.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index 2f26945efd..488cd63041 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -444,9 +444,11 @@ potential infinite waits blocking libvirt."))
            (start #~(make-forkexec-constructor
                      (list (string-append #$libvirt "/sbin/libvirtd")
                            "-f" #$config-file)
+                     ;; For finding qemu and ip binaries.
                      #:environment-variables
-                     ;; For finding qemu binaries.
-                     '("PATH=/run/current-system/profile/bin")))
+                     (list (string-append
+                            "PATH=/run/current-system/profile/bin:"
+                            "/run/current-system/profile/sbin"))))
            (stop #~(make-kill-destructor))))))
 
 (define libvirt-service-type
-- 
2.23.0