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:22:20 +0000 (10:22 -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

15 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/clear/test_kernel
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/tracker/test_event_tracker
tests/regression/tools/wildcard/test_event_wildcard
tests/utils/utils.sh

index dcb102ff4ae2eafc109092566170141ff8488cd7..fed3426c9674a813c1cf7df87ddcb2fec17c9559 100755 (executable)
@@ -205,7 +205,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 7ed6d33b9f73b410be6c24c91cf667de6217e02e..550c0e9a3dc3840f9b68ae85011caebed9c1f55e 100644 (file)
@@ -123,7 +123,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 741e782a3842956ba9fe474ba192bc6c7f3bdb4a..4b185db89f7e4ef9808575b44cc237c7f7e16cc4 100755 (executable)
@@ -40,7 +40,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
 }
 
@@ -82,7 +82,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")"
@@ -130,7 +130,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.
@@ -148,10 +148,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 538d09b01157ee5a236723fe377c9718cb81f7ae..722468f5757aeb73f26b899ec2ee1582049ce09d 100755 (executable)
@@ -29,7 +29,7 @@ source $TESTDIR/utils/utils.sh
 function signal_cleanup()
 {
        diag "*** Exiting ***"
-       modprobe -r lttng-test
+       modprobe --remove lttng-test
        full_cleanup
 }
 
@@ -96,7 +96,7 @@ function test_rotation_destroy_flush_single()
 
        rm -rf $TRACE_PATH
 
-       modprobe -r lttng-test
+       modprobe --remove lttng-test
        stop_lttng_sessiond
 }
 
index 051f3de24ec890756bc8dba13302af9145a754c4..01065748b898e192e0225be8b1477c602f067179 100755 (executable)
@@ -20,7 +20,7 @@ source $TESTDIR/utils/utils.sh
 function signal_cleanup ()
 {
        stop_lttng_sessiond
-       modprobe -r lttng-test
+       modprobe --remove lttng-test
        full_cleanup
 }
 
@@ -620,7 +620,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 6d1009a48eeaa881f11a02e186726a4b4238826c..8f3e5f4fefa8c1e4a54a44bfddf9bc4be9ea2d1d 100755 (executable)
@@ -1465,7 +1465,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 503bd13de57742701ffe44935c8e9e02aeb9eecb..82faf43b9509ffe9230a63ed792e74f5da494977 100755 (executable)
@@ -119,7 +119,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 1eb0d106749f6b682742e03cc5fb60458f1c46c1..4caa976b2ee6c6cf2e37e05dc763aadff107e6c3 100755 (executable)
@@ -90,7 +90,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 dae482ce3e5d19b4605d4d84fbbd9b9f05d0bd9d..9468d0a0db19c8aeb66486cc2a3352a850eb3c8a 100755 (executable)
@@ -325,7 +325,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 ()
@@ -360,7 +360,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 0f879e6360b3c500720b6f302d264c3974f5b0ca..8c31d488e373557912fa85674a0199ac73f99ecd 100755 (executable)
@@ -102,7 +102,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 92f584bbd25d354fb6b90ce80ce6b22cb9dac475..00c7d76cead58ffb9b83f6b0ef450fac363de2ca 100755 (executable)
@@ -59,6 +59,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 f4019b46176d17bb476b0d9f0fd43aebefbca31f..7cd51bc03f0c029e22e36e1fb3c01bed05eef86d 100755 (executable)
@@ -105,7 +105,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 fe4114ab4a7d6a647800a4419355afc13f4a318f..711690af6400daabc4627dc87c77e4730da5d541 100755 (executable)
@@ -537,7 +537,7 @@ skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KE
        test_event_tracker kernel 1 "${EVENT_NAME}" "--pid --all"
        test_event_pid_tracker kernel 1 "${EVENT_NAME}"
 
-       rmmod lttng-test
+       modprobe --remove lttng-test
        ok $? "Unloading lttng-test module"
 }
 
index 0bf2d2c2c1bf56aae11db4add11891ff2e3979c9..36d56cd3e596571cd4115d0e00ea085f0ec5d56f 100755 (executable)
@@ -167,7 +167,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 1a6ea3c424016e4ecca9fa76f1726a168d39839d..574495704a83baa5f2ba30f273131495eef0f3f2 100644 (file)
@@ -700,7 +700,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.039516 seconds and 4 git commands to generate.