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.
88 This value is included in the range.
90 The upper end of an identifier space.
91 This value is excluded from the range.
96 suite of functions is used to create and manage identifier spaces.
97 An identifier space allows the system to manage a range of identifiers.
98 It 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.
103 A common use case for identifier spaces is to manage the set of allocated minor
104 numbers for a device driver.
105 .Ss Creating, Expanding and Destroying Identifier Spaces
106 To create an identifier space, the
108 function should be used.
109 A name for the id space must be passed in the
113 For device drivers, often combining the name of the driver and the instance from
115 .Xr ddi_get_instance 9F
116 function results in a unique name.
122 describe the range of the identifier space.
123 The range is inclusive on the low end and exclusive on the high end.
124 Mathematically, this would be represented as
130 function has been successfully called, the returned identifier space can
131 be used to allocate and manage identifiers.
133 Once an identifier space has been created, additional ranges of
134 identifiers can be added.
135 This process allows for disjoint ranges of values to be added to a single
139 function is used to do this, and it adds the range
143 to the identifier space.
144 The range follows the same rules as with the
152 Finally, when an identifier space is no longer being used and all of its
153 identifiers have been freed, the caller should call the
155 function to destroy the id space
158 All three of these functions,
159 .Fn id_space_create ,
160 .Fn id_space_extend ,
164 They should only be called from a context where it's safe for it to block.
165 This is equivalent to performing a blocking memory allocation.
166 .Ss Allocating Identifiers
167 Once an id space has been created with the
169 function, identifiers can be allocated from the space.
170 There are three different strategies for allocating an identifier:
173 Allocating an identifier using the standard algorithm that attempts to
174 use the next identifier first.
176 Allocating an identifier using a first fit algorithm.
177 These are functions with
180 Using this will tend to keep the allocated id space more compressed.
182 Allocating a specific id.
185 In addition, identifiers can be allocated in both a blocking and
186 non-blocking fashion.
187 When functions with the
189 prefix are used, they are non-blocking.
190 If no identifier is available, they will return an error.
194 function will allocate the next identifier.
197 function uses the same algorithm as
199 but will fail rather than block.
203 function will allocate the first available identifier.
205 .Fn id_allocff_nosleep
206 function uses the same algorithm as
208 but will fail rather than block.
211 .Fn id_alloc_specific_nosleep
212 function attempts to allocate the specific identifier
214 from the specified identifier space.
217 has already been allocated, then the function will fail.
218 .Ss Freeing Identifiers
219 Every allocated identifier must eventually be freed and returned to the
221 To free an identifier, use the
223 function, specifying the identifier in
225 and the identifier space it came from in
227 It is a programmer error to call the
229 function on an identifier that has not been allocated.
231 All of these functions may be called in
237 .Fn id_alloc_nosleep ,
238 .Fn id_allocff_nosleep ,
240 .Fn id_alloc_specific_nosleep
241 functions may be called in
245 Upon successful completion, the
247 function returns a pointer to an identifier space.
250 is returned to indicate that the identifier space could not be created.
256 functions always return an identifier that's in the range of the
257 specified identifier space.
259 Upon successful completion, the
260 .Fn id_alloc_nosleep ,
261 .Fn id_allocff_nosleep ,
263 .Fn id_alloc_specific_nosleep
264 functions will return an identifier that's in the range of the specified
268 is returned to indicate that no identifier was available, or in the case
270 .Fn id_alloc_specific_nosleep
271 function, that the specified identifier was not available.