Skip to content

Commit

Permalink
[xfs,filesys,ext] Get list of devices by lsblk -lpo NAME,FSTYPE.
Browse files Browse the repository at this point in the history
It can happen the FS of interest is not actually mounted and then
we have no info about it. This is revorks of how we should get
list of devices. It adds a new __init__.py fuction to decrease
code duplication get_dev_by_fstype(self,fstype). It is using lsblk
instead of /proc/mounts. Last change is separation of Ext2/3/4
info into separate module from filesys.

Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
  • Loading branch information
lherbolt committed Feb 2, 2024
1 parent 097a1ae commit 18383f6
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 25 deletions.
13 changes: 13 additions & 0 deletions sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,19 @@ def get_tags_for_file(self, fname):
tags.extend(val)
return tags

def get_devices_by_fstype(self, fstype):
"""Get list of devices based on fstype and returns empty array in case
of failure.
"""
dev = []
all_devs = self.exec_cmd("lsblk -rpo NAME,FSTYPE")
if (all_devs['status'] == 0 and not all_devs['truncated']):
if all_devs['status'] == 0:
for line in all_devs['output'].splitlines():
if (fstype in line) and (line.split()[0] not in dev):
dev.append(line.split()[0])
return dev

def generate_copyspec_tags(self):
"""After file collections have completed, retroactively generate
manifest entries to apply tags to files copied by generic copyspecs
Expand Down
57 changes: 57 additions & 0 deletions sos/report/plugins/ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, IndependentPlugin, PluginOpt


class Ext(Plugin, IndependentPlugin):
"""This plugin collects information on mounted Ext2/3/4 filessystems on
the local system.
Users should expect `dumpe2fs -h` or `dumpe2fs` collections by this
plugin for each Ext2/3/4 filesystem that is recognized by lsblk.
"""

short_desc = 'Ext2/3/4 filesystem'

plugin_name = 'ext'
profiles = ('storage',)
files = ('/sys/fs/ext4/', '/proc/fs/ext4/', '/proc/fs/jbd2/')

option_list = [
PluginOpt('dumpe2fs', default=False, desc='dump filesystem info'),
PluginOpt('frag', default=False,
desc='collect filesystem fragmentation status')
]

def setup(self):
dumpe2fs_opts = '-h'
if self.get_option('dumpe2fs'):
dumpe2fs_opts = ''
allfs = self.get_devices_by_fstype('ext')
if allfs:
for fs in allfs:
self.add_cmd_output(f"dumpe2fs {dumpe2fs_opts} {fs}",
tags="dumpe2fs_h")

if self.get_option('frag'):
self.add_cmd_output(f"e2freefrag {fs}", priority=100)

else:
mounts = '/proc/mounts'
ext_fs_regex = r"^(/dev/\S+).+ext[234]\s+"
for dev in self.do_regex_find_all(ext_fs_regex, mounts):
self.add_cmd_output(f"dumpe2fs {dumpe2fs_opts} {fs}",
tags="dumpe2fs_h")

if self.get_option('frag'):
self.add_cmd_output(f"e2freefrag {fs}", priority=100)

self.add_copy_spec(self.files)

# vim: set et ts=4 sw=4 :
33 changes: 24 additions & 9 deletions sos/report/plugins/filesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class Filesys(Plugin, DebianPlugin, UbuntuPlugin, CosPlugin):
option_list = [
PluginOpt('lsof', default=False,
desc='collect information on all open files'),
PluginOpt('dumpe2fs', default=False, desc='dump filesystem info'),
PluginOpt('frag', default=False,
desc='collect filesystem fragmentation status')
]

def setup(self):
Expand Down Expand Up @@ -75,18 +72,36 @@ def setup(self):
if self.get_option('lsof'):
self.add_cmd_output("lsof -b +M -n -l -P", root_symlink="lsof",
priority=50)
option_list = [
PluginOpt('dumpe2fs', default=False, desc='dump filesystem info'),
PluginOpt('frag', default=False,
desc='collect filesystem fragmentation status')
]

def setup(self):

This comment has been minimized.

Copy link
@jcastill

jcastill Feb 2, 2024

Member

extra setup here?
Perhaps remove this one, and move these option_list to the one above?

dumpe2fs_opts = '-h'
if self.get_option('dumpe2fs'):
dumpe2fs_opts = ''
mounts = '/proc/mounts'
ext_fs_regex = r"^(/dev/\S+).+ext[234]\s+"
for dev in self.do_regex_find_all(ext_fs_regex, mounts):
self.add_cmd_output("dumpe2fs %s %s" % (dumpe2fs_opts, dev),
tags="dumpe2fs_h")
allfs = self.get_devices_by_fstype('ext')
if allfs:
for fs in allfs:
self.add_cmd_output(f"dumpe2fs {dumpe2fs_opts} {fs}",
tags="dumpe2fs_h")

if self.get_option('frag'):
self.add_cmd_output(f"e2freefrag {fs}", priority=100)

else:
mounts = '/proc/mounts'
ext_fs_regex = r"^(/dev/\S+).+ext[234]\s+"
for dev in self.do_regex_find_all(ext_fs_regex, mounts):
self.add_cmd_output(f"dumpe2fs {dumpe2fs_opts} {fs}",
tags="dumpe2fs_h")

if self.get_option('frag'):
self.add_cmd_output("e2freefrag %s" % (dev), priority=100)
self.add_cmd_output(f"e2freefrag {fs}", priority=100)

self.add_copy_spec(self.files)

def postproc(self):
self.do_file_sub(
Expand Down
37 changes: 21 additions & 16 deletions sos/report/plugins/xfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@


class Xfs(Plugin, IndependentPlugin):
"""This plugin collects information on mounted XFS filessystems on the
local system.
"""This plugin collects information on mounted XFS filessystems on
the local system.
Users should expect `xfs_info` and `xfs_admin` collections by this plugin
for each XFS filesystem that is locally mounted.
Users should expect `xfs_info` and `xfs_admin` collections by this
plugin for each XFS filesystem that is recognized by lsblk.
"""

short_desc = 'XFS filesystem'
Expand All @@ -25,18 +25,23 @@ class Xfs(Plugin, IndependentPlugin):
kernel_mods = ('xfs',)

def setup(self):
mounts = '/proc/mounts'
ext_fs_regex = r"^(/dev/.+).+xfs\s+"
for dev in zip(self.do_regex_find_all(ext_fs_regex, mounts)):
for e in dev:
parts = e.split(' ')
self.add_cmd_output("xfs_info %s" % (parts[1]),
allfs = self.get_devices_by_fstype('xfs')
if allfs:
for fs in allfs:
self.add_cmd_output(f"xfs_info {fs}",
tags="xfs_info")
self.add_cmd_output("xfs_admin -l -u %s" % (parts[0]))

self.add_copy_spec([
'/proc/fs/xfs',
'/sys/fs/xfs'
])
self.add_cmd_output(f"xfs_admin -l -u {fs}")

else:
mounts = '/proc/mounts'
ext_fs_regex = r"^(/dev/.+).+xfs\s+"
for dev in zip(self.do_regex_find_all(ext_fs_regex, mounts)):
for e in dev:
parts = e.split()
self.add_cmd_output(f"xfs_info {parts[1]}",
tags="xfs_info")
self.add_cmd_output(f"xfs_admin -l -u {parts[0]}")

self.add_copy_spec(self.files)

# vim: set et ts=4 sw=4 :

0 comments on commit 18383f6

Please sign in to comment.