]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/delete_module.2
random.4: spfix
[thirdparty/man-pages.git] / man2 / delete_module.2
CommitLineData
f4008050 1.\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
c4d4162c 2.\"
f4008050
MK
3.\" Permission is granted to make and distribute verbatim copies of this
4.\" manual provided the copyright notice and this permission notice are
5.\" preserved on all copies.
6.\"
7.\" Permission is granted to copy and distribute modified versions of this
8.\" manual under the conditions for verbatim copying, provided that the
9.\" entire resulting derived work is distributed under the terms of a
10.\" permission notice identical to this one.
11.\"
12.\" Since the Linux kernel and libraries are constantly changing, this
13.\" manual page may be incorrect or out-of-date. The author(s) assume no
14.\" responsibility for errors or omissions, or for damages resulting from
15.\" the use of the information contained herein. The author(s) may not
16.\" have taken the same level of care in the production of this manual,
17.\" which is licensed free of charge, as they might when working
18.\" professionally.
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
c4d4162c 22.\"
35f69680 23.TH DELETE_MODULE 2 2012-11-08 "Linux" "Linux Programmer's Manual"
c4d4162c 24.SH NAME
460240ca 25delete_module \- unload a kernel module
c4d4162c
MK
26.SH SYNOPSIS
27.nf
460240ca 28.BI "int delete_module(const char *" name ", int " flags );
c4d4162c 29.fi
460240ca
MK
30
31.IR Note :
32There is no glibc wrapper for this system call; see NOTES.
c4d4162c 33.SH DESCRIPTION
b4f49502 34The
c4d4162c 35.BR delete_module ()
b4f49502 36system call attempts to remove the unused loadable module entry
460240ca
MK
37identified by
38.IR name .
b4f49502
MK
39If the module has an
40.I exit
41function, then that function is executed before unloading the module.
42The
43.IR flags
44argument is used to modify the behavior of the system call,
45as described below.
c4d4162c 46This system call requires privilege.
460240ca 47
b4f49502
MK
48Module removal is attempted according to the following rules:
49.IP 1. 4
460240ca
MK
50If there are other loaded modules that depend on
51(i.e., refer to symbols defined in) this module,
52then the call fails.
b4f49502
MK
53.IP 2.
54Otherwise, if the reference count for the module
55(i.e., the number of processes currently using the module)
56is zero, then the module is immediately unloaded.
57.IP 3.
58If a module has a nonzero reference count,
59then the behavior depends on the bits set in
60.IR flags .
61In normal usage (see NOTES), the
62.BR O_NONBLOCK
63flag is always specified, and the
64.BR O_TRUNC
65flag may additionally be specified.
66.\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
67.\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
0cb430a1 68
b4f49502
MK
69The various combinations for
70.I flags
71have the following effect:
72.RS 4
460240ca 73.TP
b4f49502
MK
74.B flags == O_NONBLOCK
75The call returns immediately, with an error.
76.TP
77.B flags == (O_NONBLOCK | O_TRUNC)
78The module is unloaded immediately,
79regardless of whether it has a nonzero reference count.
80.TP
0cb430a1 81.B (flags & O_NONBLOCK) == 0
b4f49502
MK
82If
83.I flags
84does not specify
85.BR O_NONBLOCK ,
86the following steps occur:
460240ca
MK
87.RS
88.IP * 3
b4f49502 89The module is marked so that no new references are permitted.
460240ca 90.IP *
b4f49502
MK
91If the module's reference count is nonzero,
92the caller is placed in an uninterruptible sleep state
93.RB ( TASK_UNINTERRUPTIBLE )
94until the reference count is zero, at which point the call unblocks.
95.IP *
96The module is unloaded in the usual way.
460240ca 97.RE
b4f49502
MK
98.RE
99.PP
100The
101.B O_TRUNC
102flag has one further effect on the rules described above.
35f69680 103By default, if a module has an
b4f49502
MK
104.I init
105function but no
fa1d2749 106.I exit
35f69680 107function, then an attempt to remove the module will fail.
b4f49502
MK
108However, if
109.BR O_TRUNC
110was specified, this requirement is bypassed.
111.PP
fa1d2749 112Using the
b4f49502
MK
113.B O_TRUNC
114flag is dangerous!
460240ca
MK
115If the kernel was not built with
116.BR CONFIG_MODULE_FORCE_UNLOAD ,
117this flag is silently ignored.
e64bdfcf 118(Normally,
b4f49502
MK
119.BR CONFIG_MODULE_FORCE_UNLOAD
120is enabled.)
121Using this flag taints the kernel (TAINT_FORCED_RMMOD).
c4d4162c 122.SH "RETURN VALUE"
c13182ef
MK
123On success, zero is returned.
124On error, \-1 is returned and
c4d4162c
MK
125.I errno
126is set appropriately.
127.SH ERRORS
128.TP
129.B EBUSY
460240ca
MK
130The module is not "live"
131(i.e., it is still being initialized or is already marked for removal);
b4f49502
MK
132or, the module has
133an
134.I init
135function but has no
460240ca 136.I exit
b4f49502 137function, and
460240ca
MK
138.B O_TRUNC
139was not specified in
140.IR flags .
c4d4162c
MK
141.TP
142.B EFAULT
143.I name
b4f49502 144refers to a location outside the process's accessible address space.
c4d4162c
MK
145.TP
146.B ENOENT
147No module by that name exists.
148.TP
149.B EPERM
150The caller was not privileged
151(did not have the
152.B CAP_SYS_MODULE
460240ca
MK
153capability),
154or module unloading is disabled
155(see
156.IR /proc/sys/kernel/modules_disabled
157in
158.BR proc (5)).
159.TP
160.B EWOULDBLOCK
161Other modules depend on this module;
162or,
163.BR O_NONBLOCK
164was specified in
165.IR flags ,
fa1d2749 166but the reference count of this module is nonzero and
460240ca
MK
167.B O_TRUNC
168was not specified in
169.IR flags .
c4d4162c
MK
170.SH "CONFORMING TO"
171.BR delete_module ()
8382f16d 172is Linux-specific.
460240ca
MK
173.SH NOTES
174Glibc does not provide a wrapper for this system call; call it using
175.BR syscall (2).
176
b2fc8e9f 177The uninterruptible sleep that may occur if
b4f49502
MK
178.BR O_NONBLOCK
179is omitted from
180.IR flags
181is considered undesirable, because the sleeping process is left
182in an unkillable state.
183As at Linux 3.7, specifying
184.BR O_NONBLOCK
185is optional, but in future kernels it is likely to become mandatory.
460240ca
MK
186.SS Linux 2.4 and earlier
187In Linux 2.4 and earlier, the system call took only one argument:
188
189.BI " int delete_module(const char *" name );
190
191If
192.I name
193is NULL, all unused modules marked auto-clean are removed.
194
195Some further details of differences in the behavior of
196.BR delete_module ()
197in Linux 2.4 and earlier are
198.I not
199currently explained in this manual page.
c4d4162c
MK
200.SH "SEE ALSO"
201.BR create_module (2),
202.BR init_module (2),
98038e98 203.BR query_module (2),
b4f49502 204.BR lsmod (8),
eceb82f7 205.BR modprobe (8),
98038e98 206.BR rmmod (8)