3 # Routines for messing around with loadable kernel modules
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2017 Oracle. All Rights Reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #-----------------------------------------------------------------------
23 # Return the module name for this fs.
29 # Reload a particular module. This module MUST NOT be the module that
30 # underlies the filesystem.
35 modprobe -r "${module}" || _fail "${module} unload failed"
36 modprobe "${module}" || _fail "${module} load failed"
39 # Reload the filesystem module.
44 # Unload test fs, try to reload module, remount
46 local had_scratchfs=""
47 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
48 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
49 test -n "${had_testfs}" && _test_unmount
50 test -n "${had_scratchfs}" && _scratch_unmount
51 _reload_module "${module}"
52 test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
53 test -n "${had_testfs}" && _test_mount 2> /dev/null
56 # Check that we have a module that can be loaded. This module MUST NOT
57 # be the module that underlies the filesystem.
58 _require_loadable_module()
62 modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."
63 modprobe -r "${module}" || _notrun "Require ${module} to be unloadable"
64 modprobe "${module}" || _notrun "${module} load failed"
67 # Check that the module for FSTYP can be loaded.
68 _require_loadable_fs_module()
72 modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."
74 # Unload test fs, try to reload module, remount
76 local had_scratchfs=""
77 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
78 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
79 test -n "${had_testfs}" && _test_unmount
80 test -n "${had_scratchfs}" && _scratch_unmount
83 modprobe -r "${module}" || unload_ok=0
84 modprobe "${module}" || load_ok=0
85 test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
86 test -n "${had_testfs}" && _test_mount 2> /dev/null
87 test -z "${unload_ok}" || _notrun "Require module ${module} to be unloadable"
88 test -z "${load_ok}" || _notrun "${module} load failed"
91 # Print the value of a filesystem module parameter
92 # at /sys/module/$FSTYP/parameters/$PARAM
94 # Usage example (FSTYP=overlay):
95 # _get_fs_module_param index
96 _get_fs_module_param()
98 cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null