Skip to content

Commit

Permalink
Fix module unloading
Browse files Browse the repository at this point in the history
On Ubuntu, "modprobe nvidia" does not work if there is no such alias.
Previously this code ran "rmmod nvidia", but that broke since the
introduction of nvidia-uvm.

This patch attempts to map "nvidia" to "nvidia-304" by querying the
configuration and is not foolproof (e.g. when nouveau is configured
instead). As a workaround, you can create a modprobe.conf file
containing:

    alias nvidia nvidia-304
  • Loading branch information
Lekensteyn committed Jul 29, 2015
1 parent 524ded1 commit edd81b0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <unistd.h>
#include "module.h"
#include "bblogger.h"
#include "bbconfig.h"
#include "bbrun.h"

/**
Expand Down Expand Up @@ -84,6 +85,17 @@ int module_load(char *module_name, char *driver) {
return 1;
}

/**
* Maps a driver name (such as nvidia) to the module name (such as
* nvidia-current).
*/
static char *module_from_driver(char *driver) {
if (!strcmp(driver, bb_config.driver)) {
return bb_config.module_name;
}
return driver;
}

/**
* Attempts to unload a module if loaded, for ten seconds before
* giving up
Expand All @@ -92,13 +104,14 @@ int module_load(char *module_name, char *driver) {
* @return 1 if the driver is succesfully unloaded, 0 otherwise
*/
int module_unload(char *driver) {
char *module_name = module_from_driver(driver);
if (module_is_loaded(driver) == 1) {
int retries = 30;
bb_log(LOG_INFO, "Unloading %s driver\n", driver);
char *mod_argv[] = {
"modprobe",
"-r",
driver,
module_name,
NULL
};
bb_run_fork_wait(mod_argv, 10);
Expand Down

2 comments on commit edd81b0

@ArchangeGabriel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want this to be merged or prefer the shipping of modprobe rules?

@ArchangeGabriel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll drop this branch in favor of #762.

Please sign in to comment.