Skip to contentSkip to conversation

scripts/kvm/kvm_stat: Fix tracefs access checking

PATCH New Janosch Frank 1 participant 1 message Feb 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scripts/kvm/kvm_stat: Fix tracefs access checking

On kernels build without CONFIG_TRACING kvm_stat will bail out even when traces are not used. This is not very helpful, especially if the user can't install a new kernel. Instead, we should warn the user and fall back to debugfs statistics.

These changes check if trace statistics were selected without kernel support and warn the user. If they were not selected explicitly, we wait five seconds to let the user read the warning and then set the debugfs statistics to True and the tracefs ones to False. Otherwise we exit.

Fixes 7aa4ee5 ('scripts/kvm/kvm_stat: Improve debugfs access checking')

---
v1 to v2:
Exit if -t is set explicitly

 scripts/kvm/kvm_stat | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
scripts/kvm/kvm_stat +18 -5
index d43e8f3..4756eee 100755
@@ -22,6 +22,7 @@ import resource
 import struct
 import re
 from collections import defaultdict
+from time import sleep
 
 VMX_EXIT_REASONS = {
     'EXCEPTION_NMI':        0,
@@ -778,7 +779,7 @@ def get_providers(options):
 
     return providers
 
-def check_access():
+def check_access(options):
     if not os.path.exists('/sys/kernel/debug'):
         sys.stderr.write('Please enable CONFIG_DEBUG_FS in your kernel.')
         sys.exit(1)
@@ -790,14 +791,26 @@ def check_access():
                          "Also ensure, that the kvm modules are loaded.\n")
         sys.exit(1)
 
-    if not os.path.exists(PATH_DEBUGFS_TRACING):
-        sys.stderr.write("Please make {0} readable by the current user.\n"
+    if not os.path.exists(PATH_DEBUGFS_TRACING) and (options.tracepoints
+                                                     or not options.debugfs):
+        sys.stderr.write("Please enable CONFIG_TRACING in your kernel "
+                         "when using the option -t (default).\n"
+                         "If it is enabled, make {0} readable by the "
+                         "current user.\n"
                          .format(PATH_DEBUGFS_TRACING))
-        sys.exit(1)
+
+        if options.tracepoints:
+            sys.exit(1)
+
+        sys.stderr.write("Falling back to debugfs statistics!\n")
+        options.debugfs = True
+        sleep(5)
+
+    return options
 
 def main():
-    check_access()
     options = get_options()
+    options = check_access(options)
     providers = get_providers(options)
     stats = Stats(providers, fields=options.fields)
 
Signature · 1 line
2.3.0