Skip to content

Commit 1fd6a70

Browse files
Stefan-Rasplbonzini
authored andcommitted
tools/kvm_stat: fix debugfs handling
Te checks for debugfs assumed that debugfs is always mounted at /sys/kernel/debug - which is likely, but not guaranteed. This is addressed by checking /proc/mounts for the actual location. Furthermore, when debugfs was mounted, but the kvm module not loaded, a misleading error pointing towards debugfs not present was given. To reproduce, (a) run kvm_stat with debugfs mounted at a place different from /sys/kernel/debug (b) run kvm_stat with debugfs mounted but kvm module not loaded Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 1cd8bfb commit 1fd6a70

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

‎tools/kvm/kvm_stat/kvm_stat‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ class perf_event_attr(ctypes.Structure):
331331
PERF_TYPE_TRACEPOINT = 2
332332
PERF_FORMAT_GROUP = 1 << 3
333333

334-
PATH_DEBUGFS_TRACING = '/sys/kernel/debug/tracing'
335-
PATH_DEBUGFS_KVM = '/sys/kernel/debug/kvm'
336-
337334

338335
class Group(object):
339336
"""Represents a perf event group."""
@@ -1544,17 +1541,6 @@ Press any other key to refresh statistics immediately.
15441541

15451542
def check_access(options):
15461543
"""Exits if the current user can't access all needed directories."""
1547-
if not os.path.exists('/sys/kernel/debug'):
1548-
sys.stderr.write('Please enable CONFIG_DEBUG_FS in your kernel.')
1549-
sys.exit(1)
1550-
1551-
if not os.path.exists(PATH_DEBUGFS_KVM):
1552-
sys.stderr.write("Please make sure, that debugfs is mounted and "
1553-
"readable by the current user:\n"
1554-
"('mount -t debugfs debugfs /sys/kernel/debug')\n"
1555-
"Also ensure, that the kvm modules are loaded.\n")
1556-
sys.exit(1)
1557-
15581544
if not os.path.exists(PATH_DEBUGFS_TRACING) and (options.tracepoints or
15591545
not options.debugfs):
15601546
sys.stderr.write("Please enable CONFIG_TRACING in your kernel "
@@ -1572,7 +1558,33 @@ def check_access(options):
15721558
return options
15731559

15741560

1561+
def assign_globals():
1562+
global PATH_DEBUGFS_KVM
1563+
global PATH_DEBUGFS_TRACING
1564+
1565+
debugfs = ''
1566+
for line in file('/proc/mounts'):
1567+
if line.split(' ')[0] == 'debugfs':
1568+
debugfs = line.split(' ')[1]
1569+
break
1570+
if debugfs == '':
1571+
sys.stderr.write("Please make sure that CONFIG_DEBUG_FS is enabled in "
1572+
"your kernel, mounted and\nreadable by the current "
1573+
"user:\n"
1574+
"('mount -t debugfs debugfs /sys/kernel/debug')\n")
1575+
sys.exit(1)
1576+
1577+
PATH_DEBUGFS_KVM = os.path.join(debugfs, 'kvm')
1578+
PATH_DEBUGFS_TRACING = os.path.join(debugfs, 'tracing')
1579+
1580+
if not os.path.exists(PATH_DEBUGFS_KVM):
1581+
sys.stderr.write("Please make sure that CONFIG_KVM is enabled in "
1582+
"your kernel and that the modules are loaded.\n")
1583+
sys.exit(1)
1584+
1585+
15751586
def main():
1587+
assign_globals()
15761588
options = get_options()
15771589
options = check_access(options)
15781590

0 commit comments

Comments
 (0)