Mdstat - file /proc/mdstat

class insights.parsers.mdstat.Mdstat(context, extra_bad_lines=None)[source]

Bases: CommandParser

Represents the information in the /proc/mdstat file. Several examples of possible data containe in the file can be found on the MDstat kernel.org wiki page.

In particular, the discussion here will focus on initial extraction of information form lines such as:

Personalities : [raid1] [raid6] [raid5] [raid4]
md1 : active raid1 sdb2[1] sda2[0]
      136448 blocks [2/2] [UU]

md2 : active raid1 sdb3[1] sda3[0]
      129596288 blocks [2/2] [UU]

md3 : active raid5 sdl1[9] sdk1[8] sdj1[7] sdi1[6] sdh1[5] sdg1[4] sdf1[3] sde1[2] sdd1[1] sdc1[0]
      1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUUUUUUUUU]

unused devices: <none>

The data contained in mdstat is represented with three top level members - personalities, components and mds.

personalities

A list of RAID levels the kernel currently supports.

Type:

list

components

A list containing a dict of md component device information. Each of these dicts contains the following keys

  • device_name : string - name of the array device

  • active : boolean - True if the array is active, False if it is inactive.

  • component_name : string - name of the component device

  • raid : string - with the raid level, e.g., “raid1” for “md1”

  • role : int - raid role number

  • device_flag : str - device component status flag. Known values include ‘F’ (failed device), ‘S’, and ‘W’

  • up : boolean - True if the component device is up

  • auto_read_only : boolean - True if the array device is “auto-read-only”

  • blocks : the number of blocks in the device

  • level : the current RAID level, if found in the status line

  • chunk : the device chunk size, if found in the status line

  • algorithm : the current conflict resolution algorithm, if found in the status line

Type:

list

mds

A dictionary keyed on the MD device name. Each dict contains the following keys

  • name: Name of the MD device

  • active: Whether the MD device is active

  • raid: The RAID type string

  • devices: a list of the devices in this

  • blocks, level, chunk and algorithm - the same information given above per component device (if found)

Type:

dict

Examples

>>> type(mdstat)
<class 'insights.parsers.mdstat.Mdstat'>
>>> mdstat.personalities
['raid1', 'raid6', 'raid5', 'raid4']
>>> len(mdstat.components)
14
>>> mdstat.components[0]['device_name']
'md1'
>>> sdb2 = mdstat.components[0]
>>> sdb2['component_name']
'sdb2'
>>> sdb2['active']
True
>>> sdb2['raid']
'raid1'
>>> sdb2['role']
1
>>> sdb2['up']
True
>>> sorted(mdstat.mds.keys())
['md1', 'md2', 'md3']
>>> mdstat.mds['md1']['active']
True
>>> len(mdstat.mds['md1']['devices'])
2
>>> mdstat.mds['md1']['devices'][0]['component_name']
'sdb2'
parse_content(content)[source]

This method must be implemented by classes based on this class.

insights.parsers.mdstat.apply_upstring(upstring, component_list)[source]

Update the dictionaries resulting from parse_array_start with the “up” key based on the upstring returned from parse_upstring.

The function assumes that the upstring and component_list parameters passed in are from the same device array stanza of a /proc/mdstat file.

The function modifies component_list in place, adding or updating the value of the “up” key to True if there is a corresponding U in the upstring string, or to False if there is a corresponding _.

If there the number of rows in component_list does not match the number of characters in upstring, an AssertionError is raised.

Parameters:
  • upstring (str) -- String sequence of U``s and ``_``s as determined by the ``parse_upstring method.

  • component_list (list) -- List of dictionaries output from the parse_array_start method.

insights.parsers.mdstat.parse_array_start(md_line)[source]

Parse the initial line of a device array stanza in /proc/mdstat.

Sample of md_line:

md2 : active raid1 sdb3[1] sda3[0]
Parameters:

md_line (str) -- A single line from the start of a device array stanza.

Returns:

A list of dictionaries, one dictionary for each component

device making up the array.

Return type:

list

Raises:

ParseException -- If the format isn’t like the sample above.

insights.parsers.mdstat.parse_array_status(line, components)[source]

Parse the array status line, e.g.:

1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUUUUUUUUU]

This retrieves the following pieces of information:

  • blocks - (int) number of blocks in the whole MD device (always present)

  • level - (int) if found, the present RAID level

  • chunksize - (str) if found, the size of the data chunk in kilobytes

  • algorithm - (int) if found, the current algorithm in use.

Because of the way data is stored per-component and not per-array, this then puts the above keys into each of the component dictionaries in the list we’ve been given.

Sample data:

1250241792 blocks super 1.2 level 5, 64k chunk, algorithm 2 [5/5] [UUUUUU]
1465151808 blocks level 5, 64k chunk, algorithm 2 [4/3] [UUU_]
136448 blocks [2/2] [UU]
6306 blocks super external:imsm<Paste>
Parameters:
  • line (str) -- The array status line to parse.

  • components (list) -- A list of component dicts.

insights.parsers.mdstat.parse_personalities(personalities_line)[source]

Parse the “personalities” line of /proc/mdstat.

Sample of personalities_line:

Personalities : [linear] [raid0] [raid1] [raid5] [raid4] [raid6]
Parameters:
  • personalities_line (str) -- A single “Personalities” line from an

  • files. (/proc/mdstat)

Returns:

A list of raid “personalities” listed on the line.

Return type:

list

Raises:

ParseException -- If the format isn’t like the sample above.

insights.parsers.mdstat.parse_upstring(line)[source]

Parse the subsequent lines of a device array stanza in /proc/mdstat for the “up” indicator string. The up indicator is “U” and down indicator is “_”.

Samples of line:

129596288 blocks [2/2] [UU]
1318680576 blocks level 5, 1024k chunk, algorithm 2 [10/10] [UUU_UUUUUU]
Parameters

line (str): A single line from a device array stanza.

Returns:

The string containing a series of U and _ characters if found in the string, and None if the up string is not found.

Return type:

str