Bug 1934063

Summary: Service for kvm_stat logging not available
Product: [Fedora] Fedora Reporter: Thomas Huth <thuth>
Component: kernelAssignee: Kernel Maintainer List <kernel-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: acaringi, adscvr, airlied, alciregi, bfu, bskeggs, bugproxy, cohuck, dhorak, hdegoede, jarodwilson, jbenc, jeremy, jglisse, jinzhao, jonathan, josef, juzhang, kernel-maint, knoel, lgoncalv, linville, masami256, mchehab, ngu, pbonzini, ptalbert, qzhang, ribarry, smitterl, steved, thuth, virt-qe-z, yiwei
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1934042 Environment:
Last Closed: 2021-07-01 07:47:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1919930, 1934042    
Bug Blocks: 467765, 1071880    

Description Thomas Huth 2021-03-02 12:25:20 UTC
+++ This bug was initially created as a clone of Bug #1934042 +++

Description of problem:
/usr/lib/systemd/system/kvm_stat.service could not added with kernel-tools, need to add manually, 

Version-Release number of selected component (if applicable):
host kernel:5.11.0-0.rc7.151.el9.s390x
qemu:qemu-kvm-5.2.0-7.el9.s390x
guest kernel:5.11.0-0.rc7.151.el9.s390x

How reproducible:
100%

Steps to Reproduce:
1.Install kernel-tools package
2.Try to start kvm_stat logging via 'systemctl start kvm_stat.service

Actual results:
[root@l42 ~]# systemctl start kvm_stat
Failed to start kvm_stat.service: Unit kvm_stat.service not found.

Expected results:
[root@l42 bfu]# systemctl status kvm_stat
● kvm_stat.service - Service that logs KVM kernel module trace events
     Loaded: loaded (/usr/lib/systemd/system/kvm_stat.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-03-02 04:19:38 EST; 2s ago
   Main PID: 647939 (kvm_stat)
      Tasks: 1 (limit: 28846)
     Memory: 10.7M
        CPU: 110ms
     CGroup: /system.slice/kvm_stat.service
             └─647939 /usr/bin/python3 -s /usr/bin/kvm_stat -dtcz -s 0.1 -L /var/log/kvm_stat.csv

Comment 1 Thomas Huth 2021-03-02 12:32:50 UTC
Beside the missing kvm_stat.service file (which can be found in the tools/kvm/kvm_stat/ folder of the kernel sources), we'd also need a matching logrotate config file like this:

/var/log/kvm_stat.csv {
        size 10M
        missingok
        compress
        maxage 30
        rotate 5
        nodateext
        postrotate
                /usr/bin/systemctl try-restart kvm_stat.service
        endscript
}

Comment 2 Thomas Huth 2021-03-02 15:23:06 UTC
FWIW, this were the changes that I did for the RHEL8 kernel spec file (for BZ 1919930):

diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index 32dac629b11c..78922902c1f3 100644
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -540,6 +540,7 @@ Source400: mod-kvm.list
 # Sources for kernel-tools
 Source2000: cpupower.service
 Source2001: cpupower.config
+Source2002: kvm_stat.logrotate
 
 ## Patches needed for building this package
 
@@ -2086,9 +2087,11 @@ popd
 pushd tools/gpio
 %{tools_make} DESTDIR=%{buildroot} install
 popd
+install -m644 -D %{SOURCE2002} %{buildroot}%{_sysconfdir}/logrotate.d/kvm_stat
 pushd tools/kvm/kvm_stat
 make INSTALL_ROOT=%{buildroot} install-tools
 make INSTALL_ROOT=%{buildroot} install-man
+install -m644 -D kvm_stat.service %{buildroot}%{_unitdir}/kvm_stat.service
 popd
 # install VM tools
 pushd tools/vm/
@@ -2448,6 +2451,8 @@ fi
 %{_bindir}/gpio-event-mon
 %{_mandir}/man1/kvm_stat*
 %{_bindir}/kvm_stat
+%{_unitdir}/kvm_stat.service
+%config(noreplace) %{_sysconfdir}/logrotate.d/kvm_stat
 %{_bindir}/page_owner_sort
 %{_bindir}/slabinfo
 
diff --git a/redhat/kvm_stat.logrotate b/redhat/kvm_stat.logrotate
new file mode 100644
index 000000000000..105e15e651f0
--- /dev/null
+++ b/redhat/kvm_stat.logrotate
@@ -0,0 +1,11 @@
+/var/log/kvm_stat.csv {
+       size 10M
+       missingok
+       compress
+       maxage 30
+       rotate 5
+       nodateext
+       postrotate
+               /usr/bin/systemctl try-restart kvm_stat.service
+       endscript
+}

... I assume the spec file for the Fedora kernel could be adjusted in a similar way?

Comment 3 Thomas Huth 2021-07-01 07:47:21 UTC
Seems like this has been fixed in commit 4f81869d2aa7 by Jiri Benc - Thank you very much, Jiri!