Cleanup: use `modprobe --remove` rather than `rmmod`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 15 Sep 2020 16:10:18 +0000 (12:10 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 27 Nov 2020 15:23:29 +0000 (10:23 -0500)
Background
==========
According to the rmmod(8) man page:
  rmmod is a trivial program to remove a module (when module unloading
  support is provided) from the kernel. Most users will want to use
  modprobe(8) with the -r option instead.

`rmmod` simply unloads the provided module and decrements the refcount
of the modules it depended on but doesn't unload those dependencies if
their refcount is zero.

Issue
=====
With the following scenario we can end up if modules with a zero
refcount still loaded in the kernel:
  modprobe lttng-test
  lttng-sessiond
  ... (test case) ...
  ctrl+c sessiond
  rmmod lttng-test

When we teardown the lttng-sessiond, some modules are kept in the kernel
because the `lttng-test` module depends on them. So unloading
`lttng-test` using `rmmod` keeps those dependencies in the kernel.

Solution
========
Use `modprobe --remove` to unload modules and their now unused
dependencies.

From the modprobe(8) man page:
  -r, --remove
     This option causes modprobe to remove rather than insert a module.
     If the modules it depends on are also unused, modprobe will try to
     remove them too. Unlike insertion, more than one module can be
     specified on the command line

Note
====
This commit also replaces existing uses of `modprobe -r` to `modprobe
--remove` for consistency.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7be83a645097e1eddd478cfbb717906b971f04ea

13 files changed:
tests/destructive/metadata-regeneration
tests/perf/test_perf_raw.in
tests/regression/kernel/test_clock_override
tests/regression/kernel/test_rotation_destroy_flush
tests/regression/tools/filtering/test_valid_filter
tests/regression/tools/metadata/test_kernel
tests/regression/tools/notification/test_notification_kernel
tests/regression/tools/notification/test_notification_multi_app
tests/regression/tools/regen-metadata/test_kernel
tests/regression/tools/regen-statedump/test_kernel
tests/regression/tools/rotation/test_kernel
tests/regression/tools/wildcard/test_event_wildcard
tests/utils/utils.sh

index 729634f87d2b974f25760eb84d79cebe966beb7e..ce96bcd1a4ff9b68eb887bca9de3aea32437dca6 100755 (executable)
@@ -211,7 +211,7 @@ skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
        modprobe lttng-test
        test_kernel_local
        test_kernel_streaming
-       rmmod lttng-test
+       modprobe --remove lttng-test
 
        test_ust_local
        test_ust_streaming
index 9fab2cd796f97393444b41be720015ccff26d5e6..d2e8de5df269d1be02b1dfa46cc4f4da42f652a1 100644 (file)
@@ -133,7 +133,7 @@ skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
 {
        modprobe lttng-test
        test_kernel_raw
-       rmmod lttng-test
+       modprobe --remove lttng-test
 }
 
 stop_lttng_sessiond
index 1fbba7717884ce60252a7bc770a6876268d1082f..bf1a21f2752900c28cc1f96249412af6be57d1a2 100755 (executable)
@@ -50,7 +50,7 @@ function signal_cleanup()
 {
        diag "*** Exiting ***"
        stop_lttng_sessiond
-       modprobe -r lttng-test lttng-clock-plugin-test lttng-clock
+       modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock
        full_cleanup
 }
 
@@ -92,7 +92,7 @@ function test_clock_override_metadata()
        destroy_lttng_session_ok $SESSION_NAME
 
        stop_lttng_sessiond
-       modprobe -r lttng-test lttng-clock-plugin-test lttng-clock
+       modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock
 
        local TRACE_METADATA_FILE_PATH="$(find "$TRACE_PATH" -name metadata -type f)"
        local TRACE_METADATA_DIR="$(dirname "$TRACE_METADATA_FILE_PATH")"
@@ -140,7 +140,7 @@ function test_clock_override_timestamp()
                cut -d, -f1 | uniq | wc -l)
        test $unique_timestamps_count -gt 1
        ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
-       rmmod lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
 
        # Test with clock override plugin.
@@ -158,10 +158,8 @@ function test_clock_override_timestamp()
        stop_lttng_tracing_ok $SESSION_NAME
        destroy_lttng_session_ok $SESSION_NAME
 
-       rmmod lttng-test
        stop_lttng_sessiond
-       rmmod lttng-clock-plugin-test
-       rmmod lttng-clock
+       modprobe --remove lttng-clock-plugin-test lttng-clock lttng-test
 
        # Use Babeltrace with "-n all" to give a comma separated list for
        # easy extraction of timestamps.
index 03933a3af18e4079f8b1a6bfa9e28cc921a04376..7120864dcfe7dafa37982662119a1cc8e451a26c 100755 (executable)
@@ -39,7 +39,7 @@ source $TESTDIR/utils/utils.sh
 function signal_cleanup()
 {
        diag "*** Exiting ***"
-       modprobe -r lttng-test
+       modprobe --remove lttng-test
        full_cleanup
 }
 
@@ -106,7 +106,7 @@ function test_rotation_destroy_flush_single()
 
        rm -rf $TRACE_PATH
 
-       modprobe -r lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
 }
 
index 2c146fe7b026538856d5b5e5ea936940dc6eb55f..cae41b23cd9659d2ec390a576fd3c8026ab716fe 100755 (executable)
@@ -1475,7 +1475,7 @@ skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $N
                i=$(( i + 2 ))
        done
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 }
 
 stop_lttng_sessiond
index c0a039289b326be649fadac458992dd8d01eb8fe..a7249298ec54c32cbab23174cae95e34b4dcbe99 100755 (executable)
@@ -129,7 +129,7 @@ skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_T
                ${fct_test}
        done
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 
        stop_lttng_sessiond
        unset LTTNG_HOME
index a1795169c11136b2c27dcc35dd9c8a5439ee10c1..cece15f2608e1a8290366768e192f9e76df18fc8 100755 (executable)
@@ -102,7 +102,7 @@ function kernel_test
        wait $APP_PID 2> /dev/null
 
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 
        rm -rf ${consumerd_pipe[@]} 2> /dev/null
 }
index 0c578d223f75ad564629dc2e8bb1731da20eff0a..693471feb393ff2f0eefac4027c3f530fde058fc 100755 (executable)
@@ -336,7 +336,7 @@ function test_multi_app_kernel ()
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 }
 
 function test_on_register_evaluation_ust ()
@@ -371,7 +371,7 @@ function test_on_register_evaluation_kernel()
        wait $generator_pid 2> /dev/null
        rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 }
 
 function test_on_register_evaluation ()
index 84249a8fc8056c6fc65ecb428c04260bbb4b4571..b0143819a523c8d86066bf35a91f68e5251790aa 100755 (executable)
@@ -112,7 +112,7 @@ skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_
                ${fct_test}
        done
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
        stop_lttng_relayd
 }
index be65472bae05212c6117a79245cb94a9dfe217a2..e9932122ceea16c27b31d37e462766b5ec7ad7ad 100755 (executable)
@@ -69,6 +69,6 @@ skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_
                ${fct_test}
        done
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
 }
index ba084bc44588d23e85cae0c4c75847ef6f2795f9..8ed95534f31d6d6fb02fa1e5fffdcf56fdfca9fd 100755 (executable)
@@ -115,7 +115,7 @@ skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_
                clean_path $TRACE_PATH
        done
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
        stop_lttng_relayd
 }
index 61ea67a72b3eb8b27ff600d773cd554e188c6fb2..14c6568eeb531c866163d2319a9707a737a446fc 100755 (executable)
@@ -177,7 +177,7 @@ skip $isroot "Root access is needed. Skipping all kernel wildcard tests." $NUM_K
        test_event_wildcard kernel 1 'lttng*test*filter*event'
        test_event_wildcard kernel 1 '*lttng*test*filter*event*'
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
 }
 
 stop_lttng_sessiond
index d03825e66f562f93ee100652c27b100add4c46b2..b29fa5f2d8b65e78a9b2c2d466680786e4dc036b 100644 (file)
@@ -664,7 +664,7 @@ function stop_lttng_sessiond_opt()
 
                        if [ -n "$modules" ]; then
                                diag "Unloading all LTTng modules"
-                               modprobe -r "$modules"
+                               modprobe --remove "$modules"
                        fi
                fi
        fi
This page took 0.031111 seconds and 4 git commands to generate.