summaryrefslogtreecommitdiff
path: root/common/module
blob: 39e4e7931c24f2bdb583ec3a12e054ed659dd5fb (plain)
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
77
78
79
80
81
82
83
##/bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2017 Oracle.  All Rights Reserved.
#
# Routines for messing around with loadable kernel modules

# Return the module name for this fs.
_module_for_fs()
{
	echo "${FSTYP}"
}

# Reload a particular module.  This module MUST NOT be the module that
# underlies the filesystem.
_reload_module()
{
	local module="$1"

	modprobe -r "${module}" || _fail "${module} unload failed"
	modprobe "${module}" || _fail "${module} load failed"
}

# Reload the filesystem module.
_reload_fs_module()
{
	local module="$1"

	# Unload test fs, try to reload module, remount
	local had_testfs=""
	local had_scratchfs=""
	_check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
	_check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
	test -n "${had_testfs}" && _test_unmount
	test -n "${had_scratchfs}" && _scratch_unmount
	_reload_module "${module}"
	test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
	test -n "${had_testfs}" && _test_mount 2> /dev/null
}

# Check that we have a module that can be loaded.  This module MUST NOT
# be the module that underlies the filesystem.
_require_loadable_module()
{
	local module="$1"

	modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."
	modprobe -r "${module}" || _notrun "Require ${module} to be unloadable"
	modprobe "${module}" || _notrun "${module} load failed"
}

# Check that the module for FSTYP can be loaded.
_require_loadable_fs_module()
{
	local module="$1"

	modinfo "${module}" > /dev/null 2>&1 || _notrun "${module}: must be a module."

	# Unload test fs, try to reload module, remount
	local had_testfs=""
	local had_scratchfs=""
	_check_mounted_on TEST_DEV $TEST_DEV TEST_DIR $TEST_DIR && had_testfs="true"
	_check_mounted_on SCRATCH_DEV $SCRATCH_DEV SCRATCH_MNT $SCRATCH_MNT && had_scratchfs="true"
	test -n "${had_testfs}" && _test_unmount
	test -n "${had_scratchfs}" && _scratch_unmount
	local unload_ok=""
	local load_ok=""
	modprobe -r "${module}" || unload_ok=0
	modprobe "${module}" || load_ok=0
	test -n "${had_scratchfs}" && _scratch_mount 2> /dev/null
	test -n "${had_testfs}" && _test_mount 2> /dev/null
	test -z "${unload_ok}" || _notrun "Require module ${module} to be unloadable"
	test -z "${load_ok}" || _notrun "${module} load failed"
}

# Print the value of a filesystem module parameter
# at /sys/module/$FSTYP/parameters/$PARAM
#
# Usage example (FSTYP=overlay):
#   _get_fs_module_param index
_get_fs_module_param()
{
	cat /sys/module/${FSTYP}/parameters/${1} 2>/dev/null
}