Commit da39ba5e1d65e997a98f6eb93ba6e6eb505f6e3c

Authored by Rusty Russell
1 parent 93ded9b8fd

module: don't use stop_machine for waiting rmmod

rmmod has a little-used "-w" option, meaning that instead of failing if the
module is in use, it should block until the module becomes unused.

In this case, we don't need to use stop_machine: Max Krasnyansky
indicated that would be useful for SystemTap which loads/unloads new
modules frequently.

Cc: Max Krasnyansky <maxk@qualcomm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Showing 1 changed file with 11 additions and 4 deletions Side-by-side Diff

... ... @@ -639,8 +639,8 @@
639 639 {
640 640 struct stopref *sref = _sref;
641 641  
642   - /* If it's not unused, quit unless we are told to block. */
643   - if ((sref->flags & O_NONBLOCK) && module_refcount(sref->mod) != 0) {
  642 + /* If it's not unused, quit unless we're forcing. */
  643 + if (module_refcount(sref->mod) != 0) {
644 644 if (!(*sref->forced = try_force_unload(sref->flags)))
645 645 return -EWOULDBLOCK;
646 646 }
647 647  
... ... @@ -652,9 +652,16 @@
652 652  
653 653 static int try_stop_module(struct module *mod, int flags, int *forced)
654 654 {
655   - struct stopref sref = { mod, flags, forced };
  655 + if (flags & O_NONBLOCK) {
  656 + struct stopref sref = { mod, flags, forced };
656 657  
657   - return stop_machine_run(__try_stop_module, &sref, NR_CPUS);
  658 + return stop_machine_run(__try_stop_module, &sref, NR_CPUS);
  659 + } else {
  660 + /* We don't need to stop the machine for this. */
  661 + mod->state = MODULE_STATE_GOING;
  662 + synchronize_sched();
  663 + return 0;
  664 + }
658 665 }
659 666  
660 667 unsigned int module_refcount(struct module *mod)