aboutsummaryrefslogtreecommitdiffstats
path: root/sos/plugins/filesys.py
blob: ee36bd1de76d6a39e7b756eebbf9e9df9d8e0cdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
### This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin
import os
import re
from itertools import *

class filesys(Plugin, RedHatPlugin, UbuntuPlugin):
    """information on filesystems
    """
    optionList = [("lsof", 'gathers information on all open files', 'slow', False)]
    optionList = [("dumpe2fs", 'dump filesystem information', 'slow', False)]

    def setup(self):
        self.addCopySpecs([
            "/proc/filesystems",
            "/etc/fstab",
            "/proc/self/mounts",
            "/proc/mounts",
            "/proc/mdstat",
            "/etc/raidtab",
            "/etc/mdadm.conf"])
        mounts = self.getCmdOutputNow("/bin/mount -l", root_symlink = "mount")

        self.addCmdOutput("/bin/findmnt")
        self.addCmdOutput("/bin/df -al", root_symlink = "df")
        self.addCmdOutput("/bin/df -ali")
        if self.getOption('lsof'):
            self.addCmdOutput("/usr/sbin/lsof -b +M -n -l -P", root_symlink = "lsof")
        self.addCmdOutput("/sbin/blkid -c /dev/null")
        self.addCmdOutput("/usr/bin/lsblk")

        part_titlep = re.compile("^major")
        blankp = re.compile("^$")
        partlist = []
        devlist = []
        try:
            for line in open('/proc/partitions'):
                if((bool(part_titlep.match(line))) | (bool(blankp.match(line)))):
                    continue
                partlist.append('/dev/' + line.split()[-1])
        except IOError:
            exit(1)
        if os.path.exists("/sbin/hdparm"):
            for dev in partlist:
                ret, hdparm, time = self.callExtProg('/sbin/hdparm -g %s' %(dev))
                if(ret == 0):
                    start_geo = hdparm.strip().split("\n")[-1].strip().split()[-1]
                    if(start_geo == "0"):
      	                devlist.append(dev)
        else:
            # Cheaper heuristic as RHEL* does not ship hdparm for S390(x)
            # Skips least dm-.* correctly
            part_in_disk = re.compile("^/dev/[a-z]+$")
            for dev in partlist:
                if bool(part_in_disk.match(dev)):
                    devlist.append(dev)

        for i in devlist:
            self.addCmdOutput("/sbin/parted -s %s print" % (i))

        if self.getOption('dumpe2fs'):
            for extfs in izip(self.doRegexFindAll(r"^(/dev/.+) on .+ type ext.\s+", mounts)):
                self.addCmdOutput("/sbin/dumpe2fs %s" % (extfs))