2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2016 Joyent, Inc.
20 .Nm id_space_destroy ,
23 .Nm id_alloc_nosleep ,
25 .Nm id_allocff_nosleep ,
26 .Nm id_alloc_specific_nosleep ,
28 .Nd create, destroy, and use identifier spaces
33 .Fa "const char *name"
39 .Fa "id_space_t *idspace"
48 .Fa "id_space_t *idspace"
52 .Fa "id_space_t *idspace"
56 .Fa "id_space_t *idspace"
59 .Fo id_allocff_nosleep
60 .Fa "id_space_t *idspace"
63 .Fo id_allocff_specific_nosleep
64 .Fa "id_space_t *idspace"
69 .Fa "id_space_t *idspace"
72 .Sh INTERFACE STABILITY
79 structure allocated with the
83 An identifier, a signed 32-bit integer.
85 An ASCII character string to call the identifier space.
87 The lower end of an identifier space. This value is included in the
90 The upper end of an identifier space. This value is excluded from the
96 suite of functions is used to create and manage identifier spaces. An
97 identifier space allows the system to manage a range of identifiers. It
98 tracks what values have been used and which values have not been used
99 and has different ways of allocating values from the identifier space.
101 Identifier spaces are often used by device drivers to manage ranges of
102 numeric identifiers that may be disjoint. A common use case for
103 identifier spaces is to manage the set of allocated minor numbers for a
105 .Ss Creating, Expanding and Destroying Identifier Spaces
106 To create an identifier space, the
108 function should be used. A name for the id space must be passed in the
110 argument. It should be unique. For device drivers, often combining the
111 name of the driver and the instance from the
112 .Xr ddi_get_instance 9F
113 function results in a unique name.
119 describe the range of the identifier space. The range is inclusive on
120 the low end and exclusive on the high end. Mathematically, this would be
127 function has been successfully called, the returned identifier space can
128 be used to allocate and manage identifiers.
130 Once an identifier space has been created, additional ranges of
131 identifiers can be added. This process allows for disjoint ranges of
132 values to be added to a single identifier space. The
134 function is used to do this, and it adds the range
138 to the identifier space. The range follows the same rules as with the
146 Finally, when an identifier space is no longer being used and all of its
147 identifiers have been freed, the caller should call the
149 function to destroy the id space
152 All three of these functions,
153 .Fn id_space_create ,
154 .Fn id_space_extend ,
157 may block. They should only be called from a context where it's safe for
158 it to block. This is equivalent to performing a blocking memory allocation.
159 .Ss Allocating Identifiers
160 Once an id space has been created with the
162 function, identifiers can be allocated from the space. There are three
163 different strategies for allocating an identifier:
166 Allocating an identifier using the standard algorithm that attempts to
167 use the next identifier first.
169 Allocating an identifier using a first fit algorithm. These are
172 in the name. Using this will tend to keep the allocated id space more
175 Allocating a specific id.
178 In addition, identifiers can be allocated in both a blocking and
179 non-blocking fashion. When functions with the
181 prefix are used, they are non-blocking. If no identifier is available,
182 they will return an error.
186 function will allocate the next identifier. The
188 function uses the same algorithm as
190 but will fail rather than block.
194 function will allocate the first available identifier. The
195 .Fn id_allocff_nosleep
196 function uses the same algorithm as
198 but will fail rather than block.
201 .Fn id_alloc_specific_nosleep
202 function attempts to allocate the specific identifier
204 from the specified identifier space. If
206 has already been allocated, then the function will fail.
207 .Ss Freeing Identifiers
208 Every allocated identifier must eventually be freed and returned to the
209 identifier space. To free an identifier, use the
211 function, specifying the identifier in
213 and the identifier space it came from in
215 It is a programmer error to call the
217 function on an identifier that has not been allocated.
219 All of these functions may be called in
224 .Fn id_alloc_nosleep ,
225 .Fn id_allocff_nosleep ,
227 .Fn id_alloc_specific_nosleep
228 functions may be called in
232 Upon successful completion, the
234 function returns a pointer to an identifier space. Otherwise,
236 is returned to indicate that the identifier space could not be created.
242 functions always return an identifier that's in the range of the
243 specified identifier space.
245 Upon successful completion, the
246 .Fn id_alloc_nosleep ,
247 .Fn id_allocff_nosleep ,
249 .Fn id_alloc_specific_nosleep
250 functions will return an identifier that's in the range of the specified
251 identifier space. Otherwise,
253 is returned to indicate that no identifier was available, or in the case
255 .Fn id_alloc_specific_nosleep
256 function, that the specified identifier was not available.