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