diff options
author | Ryan Moeller <[email protected]> | 2020-02-27 20:15:06 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-27 17:15:06 -0800 |
commit | 2ce90dca91a991592da48c52332326ae4bb25b69 (patch) | |
tree | 71a970f07967e52f5b79aca669631a4e1f700e4e /cmd/arc_summary | |
parent | 276410387ef40e2c9659729ad6813a2dea3b3aae (diff) |
arc_summary: Make get_descriptions per platform
Linux uses modinfo to get tunables descriptions, FreeBSD has to use
sysctl.
Move the existing function definition so it is defined that way on
Linux, and add a definition in terms of sysctl for FreeBSD.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #10062
Diffstat (limited to 'cmd/arc_summary')
-rwxr-xr-x | cmd/arc_summary/arc_summary3 | 129 |
1 files changed, 76 insertions, 53 deletions
diff --git a/cmd/arc_summary/arc_summary3 b/cmd/arc_summary/arc_summary3 index 54c7babd5..1b11b2c22 100755 --- a/cmd/arc_summary/arc_summary3 +++ b/cmd/arc_summary/arc_summary3 @@ -111,6 +111,28 @@ if sys.platform.startswith('freebsd'): version = sysctl.filter(mib)[0].value return '{} version {}'.format(name, version) + def get_descriptions(_request): + # py-sysctl doesn't give descriptions, so we have to shell out. + command = ['sysctl', '-d', 'vfs.zfs'] + + # The recommended way to do this is with subprocess.run(). However, + # some installed versions of Python are < 3.5, so we offer them + # the option of doing it the old way (for now) + if 'run' in dir(subprocess): + info = subprocess.run(command, stdout=subprocess.PIPE, + universal_newlines=True) + lines = info.stdout.split('\n') + else: + info = subprocess.check_output(command, universal_newlines=True) + lines = info.split('\n') + + def fmt(line): + name, desc = line.split(':', 1) + return (name.strip(), desc.strip()) + + return dict([fmt(line) for line in lines if len(line) > 0]) + + elif sys.platform.startswith('linux'): KSTAT_PATH = '/proc/spl/kstat/zfs' SPL_PATH = '/sys/module/spl/parameters' @@ -165,6 +187,60 @@ elif sys.platform.startswith('linux'): return version + def get_descriptions(request): + """Get the descriptions of the Solaris Porting Layer (SPL) or the + tunables, return with minimal formatting. + """ + + if request not in ('spl', 'zfs'): + print('ERROR: description of "{0}" requested)'.format(request)) + sys.exit(1) + + descs = {} + target_prefix = 'parm:' + + # We would prefer to do this with /sys/modules -- see the discussion at + # get_version() -- but there isn't a way to get the descriptions from + # there, so we fall back on modinfo + command = ["/sbin/modinfo", request, "-0"] + + # The recommended way to do this is with subprocess.run(). However, + # some installed versions of Python are < 3.5, so we offer them + # the option of doing it the old way (for now) + info = '' + + try: + + if 'run' in dir(subprocess): + info = subprocess.run(command, stdout=subprocess.PIPE, + universal_newlines=True) + raw_output = info.stdout.split('\0') + else: + info = subprocess.check_output(command, + universal_newlines=True) + raw_output = info.split('\0') + + except subprocess.CalledProcessError: + print("Error: Descriptions not available", + "(can't access kernel module)") + sys.exit(1) + + for line in raw_output: + + if not line.startswith(target_prefix): + continue + + line = line[len(target_prefix):].strip() + name, raw_desc = line.split(':', 1) + desc = raw_desc.rsplit('(', 1)[0] + + if desc == '': + desc = '(No description found)' + + descs[name.strip()] = desc.strip() + + return descs + def cleanup_line(single_line): """Format a raw line of data from /proc and isolate the name value @@ -343,59 +419,6 @@ def get_kstats(): return result -def get_descriptions(request): - """Get the descriptions of the Solaris Porting Layer (SPL) or the - tunables, return with minimal formatting. - """ - - if request not in ('spl', 'zfs'): - print('ERROR: description of "{0}" requested)'.format(request)) - sys.exit(1) - - descs = {} - target_prefix = 'parm:' - - # We would prefer to do this with /sys/modules -- see the discussion at - # get_version() -- but there isn't a way to get the descriptions from - # there, so we fall back on modinfo - command = ["/sbin/modinfo", request, "-0"] - - # The recommended way to do this is with subprocess.run(). However, - # some installed versions of Python are < 3.5, so we offer them - # the option of doing it the old way (for now) - info = '' - - try: - - if 'run' in dir(subprocess): - info = subprocess.run(command, stdout=subprocess.PIPE, - universal_newlines=True) - raw_output = info.stdout.split('\0') - else: - info = subprocess.check_output(command, universal_newlines=True) - raw_output = info.split('\0') - - except subprocess.CalledProcessError: - print("Error: Descriptions not available (can't access kernel module)") - sys.exit(1) - - for line in raw_output: - - if not line.startswith(target_prefix): - continue - - line = line[len(target_prefix):].strip() - name, raw_desc = line.split(':', 1) - desc = raw_desc.rsplit('(', 1)[0] - - if desc == '': - desc = '(No description found)' - - descs[name.strip()] = desc.strip() - - return descs - - def get_version(request): """Get the version number of ZFS or SPL on this machine for header. Returns an error string, but does not raise an error, if we can't |