2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2017 Oracle. All Rights Reserved.
5 # Routines for messing around with loadable kernel modules
7 # Return the module name for this fs.
13 # Reload a particular module. This module MUST NOT be the module that
14 # underlies the filesystem.
19 modprobe -r "${module}" || _fail "${module} unload failed"
20 modprobe "${module}" || _fail "${module} load failed"
23 # Reload the filesystem module.
28 # Unload test fs, try to reload module, remount
30 local had_scratchfs=""
31 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
32 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
33 test -n "${had_testfs}" && _test_unmount
34 test -n "${had_scratchfs}" && _scratch_unmount
35 _reload_module "${module}"
36 test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
37 test -n "${had_testfs}" && _test_mount 2> /dev/null
40 # Check that we have a module that can be loaded. This module MUST NOT
41 # be the module that underlies the filesystem.
42 _require_loadable_module()
46 modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."
47 modprobe -r "${module}" || _notrun "Require ${module} to be unloadable"
48 modprobe "${module}" || _notrun "${module} load failed"
51 # Check that the module for FSTYP can be loaded.
52 _require_loadable_fs_module()
56 modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."
58 # Unload test fs, try to reload module, remount
60 local had_scratchfs=""
61 _check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
62 _check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
63 test -n "${had_testfs}" && _test_unmount
64 test -n "${had_scratchfs}" && _scratch_unmount
67 modprobe -r "${module}" || unload_ok=0
68 modprobe "${module}" || load_ok=0
69 test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
70 test -n "${had_testfs}" && _test_mount 2> /dev/null
71 test -z "${unload_ok}" || _notrun "Require module ${module} to be unloadable"
72 test -z "${load_ok}" || _notrun "${module} load failed"
75 # Print the value of a filesystem module parameter
76 # at /sys/module/$FSTYP/parameters/$PARAM
78 # Usage example (FSTYP=overlay):
79 # _get_fs_module_param index
80 _get_fs_module_param()
82 cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null