man-pages/man2/delete_module.2.html
2021-03-31 01:06:50 +01:00

330 lines
7.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of DELETE_MODULE</TITLE>
</HEAD><BODY>
<H1>DELETE_MODULE</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
delete_module - unload a kernel module
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>int delete_module(const char *</B><I>name</I><B>, int </B><I>flags</I><B>);</B>
</PRE>
<P>
<I>Note</I>:
No declaration of this system call is provided in glibc headers; see NOTES.
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>delete_module</B>()
system call attempts to remove the unused loadable module entry
identified by
<I>name</I>.
If the module has an
<I>exit</I>
function, then that function is executed before unloading the module.
The
<I>flags</I>
argument is used to modify the behavior of the system call,
as described below.
This system call requires privilege.
<P>
Module removal is attempted according to the following rules:
<DL COMPACT>
<DT id="1">1.<DD>
If there are other loaded modules that depend on
(i.e., refer to symbols defined in) this module,
then the call fails.
<DT id="2">2.<DD>
Otherwise, if the reference count for the module
(i.e., the number of processes currently using the module)
is zero, then the module is immediately unloaded.
<DT id="3">3.<DD>
If a module has a nonzero reference count,
then the behavior depends on the bits set in
<I>flags</I>.
In normal usage (see NOTES), the
<B>O_NONBLOCK</B>
flag is always specified, and the
<B>O_TRUNC</B>
flag may additionally be specified.
<DT id="4"><DD>
The various combinations for
<I>flags</I>
have the following effect:
<DL COMPACT><DT id="5"><DD>
<DL COMPACT>
<DT id="6"><B>flags == O_NONBLOCK</B>
<DD>
The call returns immediately, with an error.
<DT id="7"><B>flags == (O_NONBLOCK | O_TRUNC)</B>
<DD>
The module is unloaded immediately,
regardless of whether it has a nonzero reference count.
<DT id="8"><B>(flags &amp; O_NONBLOCK) == 0</B>
<DD>
If
<I>flags</I>
does not specify
<B>O_NONBLOCK</B>,
the following steps occur:
<DL COMPACT><DT id="9"><DD>
<DL COMPACT>
<DT id="10">*<DD>
The module is marked so that no new references are permitted.
<DT id="11">*<DD>
If the module's reference count is nonzero,
the caller is placed in an uninterruptible sleep state
(<B>TASK_UNINTERRUPTIBLE</B>)
until the reference count is zero, at which point the call unblocks.
<DT id="12">*<DD>
The module is unloaded in the usual way.
</DL>
</DL>
</DL>
</DL>
</DL>
<P>
The
<B>O_TRUNC</B>
flag has one further effect on the rules described above.
By default, if a module has an
<I>init</I>
function but no
<I>exit</I>
function, then an attempt to remove the module fails.
However, if
<B>O_TRUNC</B>
was specified, this requirement is bypassed.
<P>
Using the
<B>O_TRUNC</B>
flag is dangerous!
If the kernel was not built with
<B>CONFIG_MODULE_FORCE_UNLOAD</B>,
this flag is silently ignored.
(Normally,
<B>CONFIG_MODULE_FORCE_UNLOAD</B>
is enabled.)
Using this flag taints the kernel (TAINT_FORCED_RMMOD).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="13"><B>EBUSY</B>
<DD>
The module is not &quot;live&quot;
(i.e., it is still being initialized or is already marked for removal);
or, the module has
an
<I>init</I>
function but has no
<I>exit</I>
function, and
<B>O_TRUNC</B>
was not specified in
<I>flags</I>.
<DT id="14"><B>EFAULT</B>
<DD>
<I>name</I>
refers to a location outside the process's accessible address space.
<DT id="15"><B>ENOENT</B>
<DD>
No module by that name exists.
<DT id="16"><B>EPERM</B>
<DD>
The caller was not privileged
(did not have the
<B>CAP_SYS_MODULE</B>
capability),
or module unloading is disabled
(see
<I>/proc/sys/kernel/modules_disabled</I>
in
<B><A HREF="/cgi-bin/man/man2html?5+proc">proc</A></B>(5)).
<DT id="17"><B>EWOULDBLOCK</B>
<DD>
Other modules depend on this module;
or,
<B>O_NONBLOCK</B>
was specified in
<I>flags</I>,
but the reference count of this module is nonzero and
<B>O_TRUNC</B>
was not specified in
<I>flags</I>.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>delete_module</B>()
is Linux-specific.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
The
<B>delete_module</B>()
system call is not supported by glibc.
No declaration is provided in glibc headers, but, through a quirk of history,
glibc versions before 2.23 did export an ABI for this system call.
Therefore, in order to employ this system call,
it is (before glibc 2.23) sufficient to
manually declare the interface in your code;
alternatively, you can invoke the system call using
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
<P>
The uninterruptible sleep that may occur if
<B>O_NONBLOCK</B>
is omitted from
<I>flags</I>
is considered undesirable, because the sleeping process is left
in an unkillable state.
As at Linux 3.7, specifying
<B>O_NONBLOCK</B>
is optional, but in future kernels it is likely to become mandatory.
<A NAME="lbAI">&nbsp;</A>
<H3>Linux 2.4 and earlier</H3>
In Linux 2.4 and earlier, the system call took only one argument:
<P>
<B> int delete_module(const char *</B><I>name</I><B>);</B>
<P>
If
<I>name</I>
is NULL, all unused modules marked auto-clean are removed.
<P>
Some further details of differences in the behavior of
<B>delete_module</B>()
in Linux 2.4 and earlier are
<I>not</I>
currently explained in this manual page.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+create_module">create_module</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+init_module">init_module</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+query_module">query_module</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?8+lsmod">lsmod</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+modprobe">modprobe</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+rmmod">rmmod</A></B>(8)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="18"><A HREF="#lbAB">NAME</A><DD>
<DT id="19"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="20"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="21"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="22"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="23"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="24"><A HREF="#lbAH">NOTES</A><DD>
<DL>
<DT id="25"><A HREF="#lbAI">Linux 2.4 and earlier</A><DD>
</DL>
<DT id="26"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="27"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:32 GMT, March 31, 2021
</BODY>
</HTML>