|
Packit |
7cfc04 |
.\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH DELETE_MODULE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
delete_module \- unload a kernel module
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
.BI "int delete_module(const char *" name ", int " flags );
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.IR Note :
|
|
Packit |
7cfc04 |
No declaration of this system call is provided in glibc headers; see NOTES.
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR delete_module ()
|
|
Packit |
7cfc04 |
system call attempts to remove the unused loadable module entry
|
|
Packit |
7cfc04 |
identified by
|
|
Packit |
7cfc04 |
.IR name .
|
|
Packit |
7cfc04 |
If the module has an
|
|
Packit |
7cfc04 |
.I exit
|
|
Packit |
7cfc04 |
function, then that function is executed before unloading the module.
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR flags
|
|
Packit |
7cfc04 |
argument is used to modify the behavior of the system call,
|
|
Packit |
7cfc04 |
as described below.
|
|
Packit |
7cfc04 |
This system call requires privilege.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Module removal is attempted according to the following rules:
|
|
Packit |
7cfc04 |
.IP 1. 4
|
|
Packit |
7cfc04 |
If there are other loaded modules that depend on
|
|
Packit |
7cfc04 |
(i.e., refer to symbols defined in) this module,
|
|
Packit |
7cfc04 |
then the call fails.
|
|
Packit |
7cfc04 |
.IP 2.
|
|
Packit |
7cfc04 |
Otherwise, if the reference count for the module
|
|
Packit |
7cfc04 |
(i.e., the number of processes currently using the module)
|
|
Packit |
7cfc04 |
is zero, then the module is immediately unloaded.
|
|
Packit |
7cfc04 |
.IP 3.
|
|
Packit |
7cfc04 |
If a module has a nonzero reference count,
|
|
Packit |
7cfc04 |
then the behavior depends on the bits set in
|
|
Packit |
7cfc04 |
.IR flags .
|
|
Packit |
7cfc04 |
In normal usage (see NOTES), the
|
|
Packit |
7cfc04 |
.BR O_NONBLOCK
|
|
Packit |
7cfc04 |
flag is always specified, and the
|
|
Packit |
7cfc04 |
.BR O_TRUNC
|
|
Packit |
7cfc04 |
flag may additionally be specified.
|
|
Packit |
7cfc04 |
.\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
|
|
Packit |
7cfc04 |
.\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
|
|
Packit |
7cfc04 |
.IP
|
|
Packit |
7cfc04 |
The various combinations for
|
|
Packit |
7cfc04 |
.I flags
|
|
Packit |
7cfc04 |
have the following effect:
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B flags == O_NONBLOCK
|
|
Packit |
7cfc04 |
The call returns immediately, with an error.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B flags == (O_NONBLOCK | O_TRUNC)
|
|
Packit |
7cfc04 |
The module is unloaded immediately,
|
|
Packit |
7cfc04 |
regardless of whether it has a nonzero reference count.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B (flags & O_NONBLOCK) == 0
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
.I flags
|
|
Packit |
7cfc04 |
does not specify
|
|
Packit |
7cfc04 |
.BR O_NONBLOCK ,
|
|
Packit |
7cfc04 |
the following steps occur:
|
|
Packit |
7cfc04 |
.RS
|
|
Packit |
7cfc04 |
.IP * 3
|
|
Packit |
7cfc04 |
The module is marked so that no new references are permitted.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
If the module's reference count is nonzero,
|
|
Packit |
7cfc04 |
the caller is placed in an uninterruptible sleep state
|
|
Packit |
7cfc04 |
.RB ( TASK_UNINTERRUPTIBLE )
|
|
Packit |
7cfc04 |
until the reference count is zero, at which point the call unblocks.
|
|
Packit |
7cfc04 |
.IP *
|
|
Packit |
7cfc04 |
The module is unloaded in the usual way.
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.B O_TRUNC
|
|
Packit |
7cfc04 |
flag has one further effect on the rules described above.
|
|
Packit |
7cfc04 |
By default, if a module has an
|
|
Packit |
7cfc04 |
.I init
|
|
Packit |
7cfc04 |
function but no
|
|
Packit |
7cfc04 |
.I exit
|
|
Packit |
7cfc04 |
function, then an attempt to remove the module fails.
|
|
Packit |
7cfc04 |
However, if
|
|
Packit |
7cfc04 |
.BR O_TRUNC
|
|
Packit |
7cfc04 |
was specified, this requirement is bypassed.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Using the
|
|
Packit |
7cfc04 |
.B O_TRUNC
|
|
Packit |
7cfc04 |
flag is dangerous!
|
|
Packit |
7cfc04 |
If the kernel was not built with
|
|
Packit |
7cfc04 |
.BR CONFIG_MODULE_FORCE_UNLOAD ,
|
|
Packit |
7cfc04 |
this flag is silently ignored.
|
|
Packit |
7cfc04 |
(Normally,
|
|
Packit |
7cfc04 |
.BR CONFIG_MODULE_FORCE_UNLOAD
|
|
Packit |
7cfc04 |
is enabled.)
|
|
Packit |
7cfc04 |
Using this flag taints the kernel (TAINT_FORCED_RMMOD).
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
On success, zero is returned.
|
|
Packit |
7cfc04 |
On error, \-1 is returned and
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is set appropriately.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EBUSY
|
|
Packit |
7cfc04 |
The module is not "live"
|
|
Packit |
7cfc04 |
(i.e., it is still being initialized or is already marked for removal);
|
|
Packit |
7cfc04 |
or, the module has
|
|
Packit |
7cfc04 |
an
|
|
Packit |
7cfc04 |
.I init
|
|
Packit |
7cfc04 |
function but has no
|
|
Packit |
7cfc04 |
.I exit
|
|
Packit |
7cfc04 |
function, and
|
|
Packit |
7cfc04 |
.B O_TRUNC
|
|
Packit |
7cfc04 |
was not specified in
|
|
Packit |
7cfc04 |
.IR flags .
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EFAULT
|
|
Packit |
7cfc04 |
.I name
|
|
Packit |
7cfc04 |
refers to a location outside the process's accessible address space.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B ENOENT
|
|
Packit |
7cfc04 |
No module by that name exists.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EPERM
|
|
Packit |
7cfc04 |
The caller was not privileged
|
|
Packit |
7cfc04 |
(did not have the
|
|
Packit |
7cfc04 |
.B CAP_SYS_MODULE
|
|
Packit |
7cfc04 |
capability),
|
|
Packit |
7cfc04 |
or module unloading is disabled
|
|
Packit |
7cfc04 |
(see
|
|
Packit |
7cfc04 |
.IR /proc/sys/kernel/modules_disabled
|
|
Packit |
7cfc04 |
in
|
|
Packit |
7cfc04 |
.BR proc (5)).
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B EWOULDBLOCK
|
|
Packit |
7cfc04 |
Other modules depend on this module;
|
|
Packit |
7cfc04 |
or,
|
|
Packit |
7cfc04 |
.BR O_NONBLOCK
|
|
Packit |
7cfc04 |
was specified in
|
|
Packit |
7cfc04 |
.IR flags ,
|
|
Packit |
7cfc04 |
but the reference count of this module is nonzero and
|
|
Packit |
7cfc04 |
.B O_TRUNC
|
|
Packit |
7cfc04 |
was not specified in
|
|
Packit |
7cfc04 |
.IR flags .
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
.BR delete_module ()
|
|
Packit |
7cfc04 |
is Linux-specific.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR delete_module ()
|
|
Packit |
7cfc04 |
system call is not supported by glibc.
|
|
Packit |
7cfc04 |
No declaration is provided in glibc headers, but, through a quirk of history,
|
|
Packit |
7cfc04 |
glibc versions before 2.23 did export an ABI for this system call.
|
|
Packit |
7cfc04 |
Therefore, in order to employ this system call,
|
|
Packit |
7cfc04 |
it is (before glibc 2.23) sufficient to
|
|
Packit |
7cfc04 |
manually declare the interface in your code;
|
|
Packit |
7cfc04 |
alternatively, you can invoke the system call using
|
|
Packit |
7cfc04 |
.BR syscall (2).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The uninterruptible sleep that may occur if
|
|
Packit |
7cfc04 |
.BR O_NONBLOCK
|
|
Packit |
7cfc04 |
is omitted from
|
|
Packit |
7cfc04 |
.IR flags
|
|
Packit |
7cfc04 |
is considered undesirable, because the sleeping process is left
|
|
Packit |
7cfc04 |
in an unkillable state.
|
|
Packit |
7cfc04 |
As at Linux 3.7, specifying
|
|
Packit |
7cfc04 |
.BR O_NONBLOCK
|
|
Packit |
7cfc04 |
is optional, but in future kernels it is likely to become mandatory.
|
|
Packit |
7cfc04 |
.SS Linux 2.4 and earlier
|
|
Packit |
7cfc04 |
In Linux 2.4 and earlier, the system call took only one argument:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI " int delete_module(const char *" name );
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
If
|
|
Packit |
7cfc04 |
.I name
|
|
Packit |
7cfc04 |
is NULL, all unused modules marked auto-clean are removed.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Some further details of differences in the behavior of
|
|
Packit |
7cfc04 |
.BR delete_module ()
|
|
Packit |
7cfc04 |
in Linux 2.4 and earlier are
|
|
Packit |
7cfc04 |
.I not
|
|
Packit |
7cfc04 |
currently explained in this manual page.
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR create_module (2),
|
|
Packit |
7cfc04 |
.BR init_module (2),
|
|
Packit |
7cfc04 |
.BR query_module (2),
|
|
Packit |
7cfc04 |
.BR lsmod (8),
|
|
Packit |
7cfc04 |
.BR modprobe (8),
|
|
Packit |
7cfc04 |
.BR rmmod (8)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|