Skip to content
Pierre Vignéras edited this page Dec 9, 2011 · 15 revisions

Rulesets

.. sectnums::

This page is dedicated to user rulesets. If you want to contribute your own rulesets, create a directory in the wiki under rulesets/ containing:

  • your ruleset file which is normally in <confdir>/<rulesetname>.rs;
  • your depsfinders scripts along with their dependencies if required;
  • your action scripts if any;
  • your guesser if relevant.

Then describe how to use those files in a separate section on this page.

Find in rulesets/pings-example/ the files relevant to the pings ruleset of the tutorial.

How to use it:

  • download the guesser and save it somewhere (say: ~/.local/dev/)
  • download the depsfinder and save it somewhere (say: ~/.local/bin/)
  • download the ping ruleset and save it in ~/.sequencer/

Edit the configuration file ~/.sequencer/config and change it so the new guesser is taken into account. Change the line:

guesser.module.name = sequencer.guesser

by:

guesser.module.name = myguesser

Change your PATH and PYTHONPATH according to the location of your files:

$ export PATH=~/.local/bin:$PATH
$ export PYTHONPATH=~/.local/dev/

Check the ruleset checksum:

$ sequencer dbchecksum ping
ruleset |  name |                                                                                                                         checksum |
-----------------------------------------------------------------------------------------------------------------------------------------------------
   ping |   cmd | cd67d6932094a13c4ecc9f473b9df0ede7c2b3089b26c10abe4af8c10bc808039ca849e08c8640e4ffd1c0d00de7634a14c1cc33cb2b4c0e078aee877a98f9a5 |
   ping | group | b5d275f3cced7f572b6627133152f967cf953c490c00ecce7a4db1f2853487715d9ff5e8479ebb2a519dd7921bd0fdbbca1639e634b7f2f64e99a9b29e10aee3 |
   ping | ----- | b6d03aa304d85393390dad43592c520731334f33208abafbadc06e3534f0228247a6c24dbcf4fa769028cdecee40dc54ebb97b798d9384345682f317eb1328a8 |

$

Note that the ruleset has been renamed into ``ping`` instead of ``pings``. In the tutorial we want to distinguish between the action name (``ping``) and the ruleset name (``pings``) in order to prevent confusion. At this stage, this is no more required.

Execute:

$ sequencer ping <host> <group>

For example:

$ sequencer ping 10.0.0.[1-254]

Output aggregation should be done with clubak (from ClusterShell) as in:

$ sequencer ping rack[1-50]|clubak -c

Currently under Linux, at least on my distribution (Gentoo), a vast number of modules are loaded by default. Most of them are not used (at a given moment). For example, loading the module driver for your ethernet device is useless if your are using your wifi device to access the net. In such a situation, the ethernet driver can be unloaded. Doing so might seem an easy task: just do:

$ sudo modprobe -r <module_name>

Unfortunately, this will only remove the said module (and all its dependencies) if it is currently unused and if it is a leaf in the graph of modules dependencies. In such a situation I am tired removing each module one after the other before reaching a point where the original module can be removed. This is a situation where the sequencer can be used: you have a graph of dependencies between components (here: loadable kernel module alias lkm) and you want to execute an action (rmmod) on each such module in a given order.

Let's start by loading all possible modules into the current kernel so we will have a big set of module to unload (this is not required though):

$ for i in $(find /lib/modules/$(uname -r)/ -name '*ko');do sudo modprobe $(basename $i|sed 's/.ko//');done

Dont't worry, you will see lots of error messages: most of them just say that you do not have the device related to the module your are loading.

The current list of loaded modules is:

$ lsmod |wc -l
1692
$

We will now configure the sequencer so we can specify any module and it will do whatever is required to remove it if possible. We will also allow the removal of a group of modules such as:

$ sequencer rmmod drivers.net#group@lkm

For that purpose we need:

Download both files and copy them into ~/.sequencer/depsfinder

Adapt the sequencer [[configuration file|Advanced#wiki-configuration-file]] accordingly if required:

  • Change the depsfinder_path entry so it points towards the directory you copied depsfinder files into:

depsfinder_path = /home/pierre/.sequencer/depsfinder

Currently it is not possible (to my knowledge) to get what is using a given module. The output of the lsmod command is useless here: it shows which other module is using a given module, not what program, or device needs it. As an example, on my laptop, I have:

$ lsmod |grep '^battery'
battery                 7360  0
$

But, while the Used by column is empty, still various programs are using that module to fetch various information on my battery status:

$ acpi
Battery 0: Charging, 64%, rate information unavailable
$ sudo rmmod battery
$ acpi
$

So you see, now, the battery information is no more available. Therefore, it is hard to know which module is actually used by something. Unless we have a better option, we will specify by hand the modules that we do not want to remove into the file: ~/.sequencer/filter/used_modules. The filtering feature of the sequencer will then be used to prevent those modules from being removed. This file can be initialized by the following instruction:

$ /usr/sbin/lspci -k|awk '/Kernel modules: / {print $3}' >> ~/.sequencer/filter/used_modules

Add in that file other modules you consider as 'not-to-be-removed':

$ echo -e 'battery\nprocessor\nthermal' >> ~/.sequencer/filter/used_modules

Finally, create the rules:

$ sequencer dbadd rmmod all group@lkm '%id =~ ^.*#group@lkm$' NONE 'find_loaded_lkms %name'  single 'Remove group of modules'
$ sequencer dbadd rmmod single ko@lkm "bash -c \"! grep %name $HOME/.sequencer/filter/used_modules\"" 'sudo /sbin/rmmod %name' 'find_lkm_using %name' single 'Remove a module after all its dependencies'

Note that we use sudo /sbin/rmmod to remove individual modules.

So dbshow should give:

$ sequencer dbshow rmmod
ruleset |   name |     types |                                                             filter |                 action |             depsfinder | dependson |                                   comments |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  rmmod |    all | group@lkm |                                              %id =~ ^.*#group@lkm$ |                   NONE | find_loaded_lkms %name |    single |                    Remove group of modules |
  rmmod | single |    ko@lkm | bash -c "! grep %name /home/pierre/.sequencer/filter/used_modules" | sudo /sbin/rmmod %name |   find_lkm_using %name |    single | Remove a module after all its dependencies |

Checksumming cannot be used here because the filter actually depends on your home directory... We might have used a script file for grepping instead of hardcoding here how we filter out components.

So now, check first on a small group of devices such as 'sound':

$ sequencer  rmmod sound#group@lkm --report model --doexec=no --actionsgraphto=/tmp/rmmod-sound.dot

Use dot command to viusalize the dependency graph:

$ dot -T x11 -K circo /tmp/rmmod-sound.dot

You should see something like this:

[[rmmod-sound.jpg|alt=Actions graph DOT representation of the rmmod ruleset with the sound#group@lkm]]

Executing should be as simple as:

$ sequencer  rmmod sound#group@lkm

Finally, compare the number of modules before and after the execution of the rmmod ruleset on the all#group@lkm component:

$ lsmod |wc -l
1583
$ sequencer  rmmod all#group@lkm
WARNING - video#ko@lkm/single: ERROR: Module video is in use by i915
WARNING - crc32c#ko@lkm/single: ERROR: Module crc32c is in use
ERROR - video#ko@lkm/single: [rc=1] ERROR: Module video is in use by i915
ERROR - crc32c#ko@lkm/single: [rc=1] ERROR: Module crc32c is in use
WARNING - fuse#ko@lkm/single: ERROR: Module fuse is in use
ERROR - fuse#ko@lkm/single: [rc=1] ERROR: Module fuse is in use
WARNING - sctp#ko@lkm/single: ERROR: Module sctp is in use
WARNING - rtl8192c_common#ko@lkm/single: ERROR: Module rtl8192c_common is in use by rtl8192ce
ERROR - sctp#ko@lkm/single: [rc=1] ERROR: Module sctp is in use
ERROR - rtl8192c_common#ko@lkm/single: [rc=1] ERROR: Module rtl8192c_common is in use by rtl8192ce
WARNING - ts_kmp#ko@lkm/single: ERROR: Module ts_kmp is in use
ERROR - ts_kmp#ko@lkm/single: [rc=1] ERROR: Module ts_kmp is in use
WARNING - mperf#ko@lkm/single: ERROR: Module mperf is in use by acpi_cpufreq
WARNING - intel_agp#ko@lkm/single: ERROR: Module intel_agp is in use by i915
WARNING - arc4#ko@lkm/single: ERROR: Module arc4 is in use
ERROR - mperf#ko@lkm/single: [rc=1] ERROR: Module mperf is in use by acpi_cpufreq
ERROR - intel_agp#ko@lkm/single: [rc=1] ERROR: Module intel_agp is in use by i915
ERROR - arc4#ko@lkm/single: [rc=1] ERROR: Module arc4 is in use
WARNING - rtlwifi#ko@lkm/single: ERROR: Module rtlwifi is in use by rtl8192ce
ERROR - rtlwifi#ko@lkm/single: [rc=1] ERROR: Module rtlwifi is in use by rtl8192ce
WARNING - mii#ko@lkm/single: ERROR: Module mii is in use by jme
ERROR - mii#ko@lkm/single: [rc=1] ERROR: Module mii is in use by jme
WARNING - libahci#ko@lkm/single: ERROR: Module libahci is in use by ahci
ERROR - libahci#ko@lkm/single: [rc=1] ERROR: Module libahci is in use by ahci
WARNING - dccp_ipv4#ko@lkm/single: ERROR: Module dccp_ipv4 is in use
ERROR - dccp_ipv4#ko@lkm/single: [rc=1] ERROR: Module dccp_ipv4 is in use
WARNING - drm_kms_helper#ko@lkm/single: ERROR: Module drm_kms_helper is in use by i915
ERROR - drm_kms_helper#ko@lkm/single: [rc=1] ERROR: Module drm_kms_helper is in use by i915
WARNING - libphy#ko@lkm/single: ERROR: Module libphy is in use by realtek
ERROR - libphy#ko@lkm/single: [rc=1] ERROR: Module libphy is in use by realtek
WARNING - ar7part#ko@lkm/single: ERROR: Removing 'ar7part': Device or resource busy
ERROR - ar7part#ko@lkm/single: [rc=1] ERROR: Removing 'ar7part': Device or resource busy
WARNING - dm_mod#ko@lkm/single: ERROR: Module dm_mod is in use
ERROR - dm_mod#ko@lkm/single: [rc=1] ERROR: Module dm_mod is in use
WARNING - i2c_algo_bit#ko@lkm/single: ERROR: Module i2c_algo_bit is in use by i915
ERROR - i2c_algo_bit#ko@lkm/single: [rc=1] ERROR: Module i2c_algo_bit is in use by i915
WARNING - snd_hwdep#ko@lkm/single: ERROR: Module snd_hwdep is in use by snd_hda_codec
ERROR - snd_hwdep#ko@lkm/single: [rc=1] ERROR: Module snd_hwdep is in use by snd_hda_codec
WARNING - firmware_class#ko@lkm/single: ERROR: Module firmware_class is in use by rtl8192ce
WARNING - snd_pcm#ko@lkm/single: ERROR: Module snd_pcm is in use by snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
ERROR - firmware_class#ko@lkm/single: [rc=1] ERROR: Module firmware_class is in use by rtl8192ce
ERROR - snd_pcm#ko@lkm/single: [rc=1] ERROR: Module snd_pcm is in use by snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
$ lsmod |wc -l
55
$

All those errors are fine and taking into account by the sequencer. If you are curious, execute with the --report=all option.

Clone this wiki locally