xref: /freebsd/share/man/man9/osd.9 (revision c85d716664f4df3cf9496d3a471f9f3bf408efa6)
14a2b56ebSLawrence Stewart.\"
24a2b56ebSLawrence Stewart.\" Copyright (c) 2010 Lawrence Stewart <lstewart@FreeBSD.org>
34a2b56ebSLawrence Stewart.\" All rights reserved.
44a2b56ebSLawrence Stewart.\"
54a2b56ebSLawrence Stewart.\" Redistribution and use in source and binary forms, with or without
64a2b56ebSLawrence Stewart.\" modification, are permitted provided that the following conditions
74a2b56ebSLawrence Stewart.\" are met:
84a2b56ebSLawrence Stewart.\" 1. Redistributions of source code must retain the above copyright
94a2b56ebSLawrence Stewart.\"    notice, this list of conditions, and the following disclaimer,
104a2b56ebSLawrence Stewart.\"    without modification, immediately at the beginning of the file.
114a2b56ebSLawrence Stewart.\" 2. The name of the author may not be used to endorse or promote products
124a2b56ebSLawrence Stewart.\"    derived from this software without specific prior written permission.
134a2b56ebSLawrence Stewart.\"
144a2b56ebSLawrence Stewart.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154a2b56ebSLawrence Stewart.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164a2b56ebSLawrence Stewart.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174a2b56ebSLawrence Stewart.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
184a2b56ebSLawrence Stewart.\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194a2b56ebSLawrence Stewart.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204a2b56ebSLawrence Stewart.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214a2b56ebSLawrence Stewart.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224a2b56ebSLawrence Stewart.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234a2b56ebSLawrence Stewart.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244a2b56ebSLawrence Stewart.\" SUCH DAMAGE.
254a2b56ebSLawrence Stewart.\"
264a2b56ebSLawrence Stewart.\" $FreeBSD$
274a2b56ebSLawrence Stewart.\"
28aa90aec2SConrad Meyer.Dd April 26, 2016
294a2b56ebSLawrence Stewart.Dt OSD 9
304a2b56ebSLawrence Stewart.Os
314a2b56ebSLawrence Stewart.Sh NAME
324a2b56ebSLawrence Stewart.Nm osd ,
334a2b56ebSLawrence Stewart.Nm osd_register ,
344a2b56ebSLawrence Stewart.Nm osd_deregister ,
354a2b56ebSLawrence Stewart.Nm osd_set ,
36320d8421SJamie Gritton.Nm osd_reserve ,
37320d8421SJamie Gritton.Nm osd_set_reserved ,
38320d8421SJamie Gritton.Nm osd_free_reserved ,
394a2b56ebSLawrence Stewart.Nm osd_get ,
404a2b56ebSLawrence Stewart.Nm osd_del ,
414a2b56ebSLawrence Stewart.Nm osd_call ,
424a2b56ebSLawrence Stewart.Nm osd_exit
434a2b56ebSLawrence Stewart.Nd Object Specific Data
444a2b56ebSLawrence Stewart.Sh SYNOPSIS
454a2b56ebSLawrence Stewart.In sys/osd.h
464a2b56ebSLawrence Stewart.Ft typedef void
474a2b56ebSLawrence Stewart.Fn "\*(lp*osd_destructor_t\*(rp" "void *value"
484a2b56ebSLawrence Stewart.Ft typedef int
494a2b56ebSLawrence Stewart.Fn "\*(lp*osd_method_t\*(rp" "void *obj" "void *data"
504a2b56ebSLawrence Stewart.Ft int
514a2b56ebSLawrence Stewart.Fo osd_register
524a2b56ebSLawrence Stewart.Fa "u_int type"
534a2b56ebSLawrence Stewart.Fa "osd_destructor_t destructor"
544a2b56ebSLawrence Stewart.Fa "osd_method_t *methods"
554a2b56ebSLawrence Stewart.Fc
564a2b56ebSLawrence Stewart.Ft void
574a2b56ebSLawrence Stewart.Fo osd_deregister
584a2b56ebSLawrence Stewart.Fa "u_int type"
594a2b56ebSLawrence Stewart.Fa "u_int slot"
604a2b56ebSLawrence Stewart.Fc
614a2b56ebSLawrence Stewart.Ft int
624a2b56ebSLawrence Stewart.Fo osd_set
634a2b56ebSLawrence Stewart.Fa "u_int type"
644a2b56ebSLawrence Stewart.Fa "struct osd *osd"
654a2b56ebSLawrence Stewart.Fa "u_int slot"
664a2b56ebSLawrence Stewart.Fa "void *value"
674a2b56ebSLawrence Stewart.Fc
68aa90aec2SConrad Meyer.Ft void **
69320d8421SJamie Gritton.Fo osd_reserve
70320d8421SJamie Gritton.Fa "u_int slot"
71320d8421SJamie Gritton.Fc
72320d8421SJamie Gritton.Ft int
73320d8421SJamie Gritton.Fo osd_set_reserved
74320d8421SJamie Gritton.Fa "u_int type"
75320d8421SJamie Gritton.Fa "struct osd *osd"
76320d8421SJamie Gritton.Fa "u_int slot"
77aa90aec2SConrad Meyer.Fa "void **rsv"
78320d8421SJamie Gritton.Fa "void *value"
79320d8421SJamie Gritton.Fc
80320d8421SJamie Gritton.Ft void
81320d8421SJamie Gritton.Fo osd_free_reserved
82aa90aec2SConrad Meyer.Fa "void **rsv"
83320d8421SJamie Gritton.Fc
84320d8421SJamie Gritton.Ft void *
854a2b56ebSLawrence Stewart.Fo osd_get
864a2b56ebSLawrence Stewart.Fa "u_int type"
874a2b56ebSLawrence Stewart.Fa "struct osd *osd"
884a2b56ebSLawrence Stewart.Fa "u_int slot"
894a2b56ebSLawrence Stewart.Fc
904a2b56ebSLawrence Stewart.Ft void
914a2b56ebSLawrence Stewart.Fo osd_del
924a2b56ebSLawrence Stewart.Fa "u_int type"
934a2b56ebSLawrence Stewart.Fa "struct osd *osd"
944a2b56ebSLawrence Stewart.Fa "u_int slot"
954a2b56ebSLawrence Stewart.Fc
964a2b56ebSLawrence Stewart.Ft int
974a2b56ebSLawrence Stewart.Fo osd_call
984a2b56ebSLawrence Stewart.Fa "u_int type"
994a2b56ebSLawrence Stewart.Fa "u_int method"
1004a2b56ebSLawrence Stewart.Fa "void *obj"
1014a2b56ebSLawrence Stewart.Fa "void *data"
1024a2b56ebSLawrence Stewart.Fc
1034a2b56ebSLawrence Stewart.Ft void
1044a2b56ebSLawrence Stewart.Fo osd_exit
1054a2b56ebSLawrence Stewart.Fa "u_int type"
1064a2b56ebSLawrence Stewart.Fa "struct osd *osd"
1074a2b56ebSLawrence Stewart.Fc
1084a2b56ebSLawrence Stewart.Sh DESCRIPTION
1094a2b56ebSLawrence StewartThe
1104a2b56ebSLawrence Stewart.Nm
1114a2b56ebSLawrence Stewartframework provides a mechanism to dynamically associate arbitrary data at
1124a2b56ebSLawrence Stewartrun-time with any kernel data structure which has been suitably modified for use
1134a2b56ebSLawrence Stewartwith
1144a2b56ebSLawrence Stewart.Nm .
1154a2b56ebSLawrence StewartThe one-off modification required involves embedding a
1164a2b56ebSLawrence Stewart.Vt "struct osd"
1174a2b56ebSLawrence Stewartinside the kernel data structure.
1184a2b56ebSLawrence Stewart.Pp
1194a2b56ebSLawrence StewartAn additional benefit is that after the initial change to a structure is made,
1204a2b56ebSLawrence Stewartall subsequent use of
1214a2b56ebSLawrence Stewart.Nm
1224a2b56ebSLawrence Stewartwith the structure involves no changes to the structure's layout.
1234a2b56ebSLawrence StewartBy extension, if the data structure is part of the ABI,
1244a2b56ebSLawrence Stewart.Nm
1254a2b56ebSLawrence Stewartprovides a way of extending the structure in an ABI preserving manner.
1264a2b56ebSLawrence Stewart.Pp
1274a2b56ebSLawrence StewartThe details of the embedded
1284a2b56ebSLawrence Stewart.Vt "struct osd"
1294a2b56ebSLawrence Stewartare not relevant to consumers of the
1304a2b56ebSLawrence Stewart.Nm
1314a2b56ebSLawrence Stewartframework and should not be manipulated directly.
1324a2b56ebSLawrence Stewart.Pp
1334a2b56ebSLawrence StewartData associated with a structure is referenced by the
1344a2b56ebSLawrence Stewart.Nm
1354a2b56ebSLawrence Stewartframework using a type/slot identifier pair.
1364a2b56ebSLawrence StewartTypes are statically defined in
1374a2b56ebSLawrence Stewart.In sys/osd.h
1384a2b56ebSLawrence Stewartand provide a high-level grouping for slots to be registered under.
1394a2b56ebSLawrence StewartSlot identifiers are dynamically assigned by the framework when a data type is
1404a2b56ebSLawrence Stewartregistered using
1414a2b56ebSLawrence Stewart.Fn osd_register
1424a2b56ebSLawrence Stewartand remains valid until a corresponding call to
1434a2b56ebSLawrence Stewart.Fn osd_deregister .
1444a2b56ebSLawrence Stewart.Ss Functions
1454a2b56ebSLawrence StewartThe
1464a2b56ebSLawrence Stewart.Fn osd_register
1474a2b56ebSLawrence Stewartfunction registers a type/slot identifier pair with the
1484a2b56ebSLawrence Stewart.Nm
1494a2b56ebSLawrence Stewartframework for use with a new data type.
1504a2b56ebSLawrence StewartThe function may sleep and therefore cannot be called from a non-sleepable
1514a2b56ebSLawrence Stewartcontext.
1524a2b56ebSLawrence StewartThe
1534a2b56ebSLawrence Stewart.Fa type
1544a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
1554a2b56ebSLawrence Stewart.In sys/osd.h
1564a2b56ebSLawrence Stewartthe slot identifier should be allocated under.
1574a2b56ebSLawrence StewartThe
1584a2b56ebSLawrence Stewart.Fa destructor
1594a2b56ebSLawrence Stewartargument specifies an optional osd_destructor_t function pointer that will be
1604a2b56ebSLawrence Stewartcalled for objects of the type being registered which are later destroyed by the
1614a2b56ebSLawrence Stewart.Fn osd_del
1624a2b56ebSLawrence Stewartfunction.
1634a2b56ebSLawrence StewartNULL may be passed if no destructor is required.
1644a2b56ebSLawrence StewartThe
1654a2b56ebSLawrence Stewart.Fa methods
1664a2b56ebSLawrence Stewartargument specifies an optional array of osd_method_t function pointers which
1674a2b56ebSLawrence Stewartcan be later invoked by the
1684a2b56ebSLawrence Stewart.Fn osd_call
1694a2b56ebSLawrence Stewartfunction.
1704a2b56ebSLawrence StewartNULL may be passed if no methods are required.
1714a2b56ebSLawrence StewartThe
1724a2b56ebSLawrence Stewart.Fa methods
1734a2b56ebSLawrence Stewartargument is currently only useful with the OSD_JAIL type identifier.
1744a2b56ebSLawrence Stewart.Pp
1754a2b56ebSLawrence StewartThe
1764a2b56ebSLawrence Stewart.Fn osd_deregister
1774a2b56ebSLawrence Stewartfunction deregisters a previously registered type/slot identifier pair.
1784a2b56ebSLawrence StewartThe function may sleep and therefore cannot be called from a non-sleepable
1794a2b56ebSLawrence Stewartcontext.
1804a2b56ebSLawrence StewartThe
1814a2b56ebSLawrence Stewart.Fa type
1824a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
1834a2b56ebSLawrence Stewart.In sys/osd.h
1844a2b56ebSLawrence Stewartthe slot identifier is allocated under.
1854a2b56ebSLawrence StewartThe
1864a2b56ebSLawrence Stewart.Fa slot
1874a2b56ebSLawrence Stewartargument specifies the slot identifier which is being deregistered and should be
1884a2b56ebSLawrence Stewartthe value that was returned by
1894a2b56ebSLawrence Stewart.Fn osd_register
1904a2b56ebSLawrence Stewartwhen the data type was registered.
1914a2b56ebSLawrence Stewart.Pp
1924a2b56ebSLawrence StewartThe
1934a2b56ebSLawrence Stewart.Fn osd_set
1944a2b56ebSLawrence Stewartfunction associates a data object pointer with a kernel data structure's
1954a2b56ebSLawrence Stewart.Vt struct osd
1964a2b56ebSLawrence Stewartmember.
1974a2b56ebSLawrence StewartThe
1984a2b56ebSLawrence Stewart.Fa type
1994a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
2004a2b56ebSLawrence Stewart.In sys/osd.h
2014a2b56ebSLawrence Stewartthe slot identifier is allocated under.
2024a2b56ebSLawrence StewartThe
2034a2b56ebSLawrence Stewart.Fa osd
2044a2b56ebSLawrence Stewartargument is a pointer to the kernel data structure's
2054a2b56ebSLawrence Stewart.Vt struct osd
2064a2b56ebSLawrence Stewartwhich will have the
2074a2b56ebSLawrence Stewart.Fa value
2084a2b56ebSLawrence Stewartpointer associated with it.
2094a2b56ebSLawrence StewartThe
2104a2b56ebSLawrence Stewart.Fa slot
2114a2b56ebSLawrence Stewartargument specifies the slot identifier to assign the
2124a2b56ebSLawrence Stewart.Fa value
2134a2b56ebSLawrence Stewartpointer to.
2144a2b56ebSLawrence StewartThe
2154a2b56ebSLawrence Stewart.Fa value
2164a2b56ebSLawrence Stewartargument points to a data object to associate with
2174a2b56ebSLawrence Stewart.Fa osd .
2184a2b56ebSLawrence Stewart.Pp
2194a2b56ebSLawrence StewartThe
220320d8421SJamie Gritton.Fn osd_set_reserved
221320d8421SJamie Grittonfunction does the same as
222320d8421SJamie Gritton.Fn osd_set ,
223320d8421SJamie Grittonbut with an extra argument
224320d8421SJamie Gritton.Fa rsv
225320d8421SJamie Grittonthat is internal-use memory previously allocated via
226320d8421SJamie Gritton.Fn osd_reserve .
227320d8421SJamie Gritton.Pp
228320d8421SJamie GrittonThe
2294a2b56ebSLawrence Stewart.Fn osd_get
2304a2b56ebSLawrence Stewartfunction returns the data pointer associated with a kernel data structure's
2314a2b56ebSLawrence Stewart.Vt struct osd
2324a2b56ebSLawrence Stewartmember from the specified type/slot identifier pair.
2334a2b56ebSLawrence StewartThe
2344a2b56ebSLawrence Stewart.Fa type
2354a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
2364a2b56ebSLawrence Stewart.In sys/osd.h
2374a2b56ebSLawrence Stewartthe slot identifier is allocated under.
2384a2b56ebSLawrence StewartThe
2394a2b56ebSLawrence Stewart.Fa osd
2404a2b56ebSLawrence Stewartargument is a pointer to the kernel data structure's
2414a2b56ebSLawrence Stewart.Vt struct osd
2424a2b56ebSLawrence Stewartto retrieve the data pointer from.
2434a2b56ebSLawrence StewartThe
2444a2b56ebSLawrence Stewart.Fa slot
2454a2b56ebSLawrence Stewartargument specifies the slot identifier to retrieve the data pointer from.
2464a2b56ebSLawrence Stewart.Pp
2474a2b56ebSLawrence StewartThe
2484a2b56ebSLawrence Stewart.Fn osd_del
2494a2b56ebSLawrence Stewartfunction removes the data pointer associated with a kernel data structure's
2504a2b56ebSLawrence Stewart.Vt struct osd
2514a2b56ebSLawrence Stewartmember from the specified type/slot identifier pair.
2524a2b56ebSLawrence StewartThe
2534a2b56ebSLawrence Stewart.Fa type
2544a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
2554a2b56ebSLawrence Stewart.In sys/osd.h
2564a2b56ebSLawrence Stewartthe slot identifier is allocated under.
2574a2b56ebSLawrence StewartThe
2584a2b56ebSLawrence Stewart.Fa osd
2594a2b56ebSLawrence Stewartargument is a pointer to the kernel data structure's
2604a2b56ebSLawrence Stewart.Vt struct osd
2614a2b56ebSLawrence Stewartto remove the data pointer from.
2624a2b56ebSLawrence StewartThe
2634a2b56ebSLawrence Stewart.Fa slot
2644a2b56ebSLawrence Stewartargument specifies the slot identifier to remove the data pointer from.
2654a2b56ebSLawrence StewartIf an osd_destructor_t function pointer was specified at registration time, the
2664a2b56ebSLawrence Stewartdestructor function will be called and passed the data pointer for the type/slot
2674a2b56ebSLawrence Stewartidentifier pair which is being deleted.
2684a2b56ebSLawrence Stewart.Pp
2694a2b56ebSLawrence StewartThe
2704a2b56ebSLawrence Stewart.Fn osd_call
2714a2b56ebSLawrence Stewartfunction calls the specified osd_method_t function pointer for all
2724a2b56ebSLawrence Stewartcurrently registered slots of a given type on the specified
2734a2b56ebSLawrence Stewart.Fa obj
2744a2b56ebSLawrence Stewartand
2754a2b56ebSLawrence Stewart.Fa data
2764a2b56ebSLawrence Stewartpointers.
2774a2b56ebSLawrence StewartThe function may sleep and therefore cannot be called from a non-sleepable
2784a2b56ebSLawrence Stewartcontext.
2794a2b56ebSLawrence StewartThe
2804a2b56ebSLawrence Stewart.Fa type
2814a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
2824a2b56ebSLawrence Stewart.In sys/osd.h
2834a2b56ebSLawrence Stewartto call the method for.
2844a2b56ebSLawrence StewartThe
2854a2b56ebSLawrence Stewart.Fa method
2864a2b56ebSLawrence Stewartargument specifies the index into the osd_method_t array that was passed to
2874a2b56ebSLawrence Stewart.Fn osd_register .
2884a2b56ebSLawrence StewartThe
2894a2b56ebSLawrence Stewart.Fa obj
2904a2b56ebSLawrence Stewartand
2914a2b56ebSLawrence Stewart.Fa data
2924a2b56ebSLawrence Stewartarguments are passed to the method function pointer of each slot.
2934a2b56ebSLawrence Stewart.Pp
2944a2b56ebSLawrence StewartThe
2954a2b56ebSLawrence Stewart.Fn osd_exit
2964a2b56ebSLawrence Stewartfunction removes all data object pointers from all currently registered slots
2974a2b56ebSLawrence Stewartfor a given type for the specified kernel data structure's
2984a2b56ebSLawrence Stewart.Vt struct osd
2994a2b56ebSLawrence Stewartmember.
3004a2b56ebSLawrence StewartThe
3014a2b56ebSLawrence Stewart.Fa type
3024a2b56ebSLawrence Stewartargument specifies which high-level type grouping from
3034a2b56ebSLawrence Stewart.In sys/osd.h
3044a2b56ebSLawrence Stewartto remove data pointers from.
3054a2b56ebSLawrence StewartThe
3064a2b56ebSLawrence Stewart.Fa osd
3074a2b56ebSLawrence Stewartargument is a pointer to the kernel data structure's
3084a2b56ebSLawrence Stewart.Vt struct osd
3094a2b56ebSLawrence Stewartto remove all data object pointers for all currently registered slots from.
3104a2b56ebSLawrence Stewart.Sh IMPLEMENTATION NOTES
3114a2b56ebSLawrence Stewart.Nm
3124a2b56ebSLawrence Stewartuses a two dimensional matrix (array of arrays) as the data structure to manage
3134a2b56ebSLawrence Stewartthe external data associated with a kernel data structure's
3144a2b56ebSLawrence Stewart.Vt struct osd
3154a2b56ebSLawrence Stewartmember.
3164a2b56ebSLawrence StewartThe type identifier is used as the index into the outer array, and the slot
317aa90aec2SConrad Meyeridentifier is used as the index into the inner array.
318aa90aec2SConrad MeyerTo set or retrieve a data pointer for a given type/slot identifier pair,
3194a2b56ebSLawrence Stewart.Fn osd_set
3204a2b56ebSLawrence Stewartand
3214a2b56ebSLawrence Stewart.Fn osd_get
3224a2b56ebSLawrence Stewartperform the equivalent of array[type][slot], which is both constant time and
3234a2b56ebSLawrence Stewartfast.
3244a2b56ebSLawrence Stewart.Pp
3254a2b56ebSLawrence StewartIf
3264a2b56ebSLawrence Stewart.Fn osd_set
3274a2b56ebSLawrence Stewartis called on a
3284a2b56ebSLawrence Stewart.Vt struct osd
3294a2b56ebSLawrence Stewartfor the first time, the array for storing data pointers is dynamically allocated
3304a2b56ebSLawrence Stewartusing
3314a2b56ebSLawrence Stewart.Xr malloc 9
3324a2b56ebSLawrence Stewartwith M_NOWAIT to a size appropriate for the slot identifier being set.
3334a2b56ebSLawrence StewartIf a subsequent call to
3344a2b56ebSLawrence Stewart.Fn osd_set
3354a2b56ebSLawrence Stewartattempts to set a slot identifier which is numerically larger than the slot used
3364a2b56ebSLawrence Stewartin the previous
3374a2b56ebSLawrence Stewart.Fn osd_set
3384a2b56ebSLawrence Stewartcall,
3394a2b56ebSLawrence Stewart.Xr realloc 9
3404a2b56ebSLawrence Stewartis used to grow the array to the appropriate size such that the slot identifier
3414a2b56ebSLawrence Stewartcan be used.
3424a2b56ebSLawrence StewartTo maximise the efficiency of any code which calls
3434a2b56ebSLawrence Stewart.Fn osd_set
344aa90aec2SConrad Meyersequentially on a number of different slot identifiers (e.g., during an
3454a2b56ebSLawrence Stewartinitialisation phase) one should loop through the slot identifiers in descending
3464a2b56ebSLawrence Stewartorder from highest to lowest.
3474a2b56ebSLawrence StewartThis will result in only a single
3484a2b56ebSLawrence Stewart.Xr malloc 9
3494a2b56ebSLawrence Stewartcall to create an array of the largest slot size and all subsequent calls to
3504a2b56ebSLawrence Stewart.Fn osd_set
3514a2b56ebSLawrence Stewartwill proceed without any
3524a2b56ebSLawrence Stewart.Xr realloc 9
3534a2b56ebSLawrence Stewartcalls.
3544a2b56ebSLawrence Stewart.Pp
355320d8421SJamie GrittonIt is possible for
356320d8421SJamie Gritton.Fn osd_set
357aa90aec2SConrad Meyerto fail to allocate this array.
358aa90aec2SConrad MeyerTo ensure that such allocation succeeds,
359320d8421SJamie Gritton.Fn osd_reserve
360320d8421SJamie Grittonmay be called (in a non-blocking context), and it will pre-allocate the
361320d8421SJamie Grittonmemory via
362320d8421SJamie Gritton.Xr malloc 9
363320d8421SJamie Grittonwith M_WAITOK.
364320d8421SJamie GrittonThen this pre-allocated memory is passed to
365320d8421SJamie Gritton.Fn osd_set_reserved ,
366320d8421SJamie Grittonwhich will use it if necessary or otherwise discard it.
367320d8421SJamie GrittonThe memory may also be explicitly discarded by calling
368320d8421SJamie Gritton.Fn osd_free_reserved .
369320d8421SJamie GrittonAs this method always allocates memory whether or not it is ultimately needed,
370320d8421SJamie Grittonit should be used only rarely, such as in the unlikely event that
371320d8421SJamie Gritton.Fn osd_set
372320d8421SJamie Grittonfails.
373320d8421SJamie Gritton.Pp
3744a2b56ebSLawrence StewartThe
3754a2b56ebSLawrence Stewart.Nm
3764a2b56ebSLawrence StewartAPI is geared towards slot identifiers storing pointers to the same underlying
3774a2b56ebSLawrence Stewartdata structure type for a given
3784a2b56ebSLawrence Stewart.Nm
3794a2b56ebSLawrence Stewarttype identifier.
3804a2b56ebSLawrence StewartThis is not a requirement, and
3814a2b56ebSLawrence Stewart.Xr khelp 9
3824a2b56ebSLawrence Stewartfor example stores completely different data types in slots under the OSD_KHELP
3834a2b56ebSLawrence Stewarttype identifier.
3844a2b56ebSLawrence Stewart.Ss Locking
3854a2b56ebSLawrence Stewart.Nm
3864a2b56ebSLawrence Stewartinternally uses a mix of
3874a2b56ebSLawrence Stewart.Xr mutex 9 ,
3884a2b56ebSLawrence Stewart.Xr rmlock 9
3894a2b56ebSLawrence Stewartand
3904a2b56ebSLawrence Stewart.Xr sx 9
3914a2b56ebSLawrence Stewartlocks to protect its internal data structures and state.
3924a2b56ebSLawrence Stewart.Pp
3934a2b56ebSLawrence StewartResponsibility for synchronising access to a kernel data structure's
3944a2b56ebSLawrence Stewart.Vt struct osd
3954a2b56ebSLawrence Stewartmember is left to the subsystem that uses the data structure and calls the
3964a2b56ebSLawrence Stewart.Nm
3974a2b56ebSLawrence StewartAPI.
3984a2b56ebSLawrence Stewart.Pp
3994a2b56ebSLawrence Stewart.Fn osd_get
4004a2b56ebSLawrence Stewartonly acquires an
4014a2b56ebSLawrence Stewart.Xr rmlock
4024a2b56ebSLawrence Stewartin read mode, therefore making it safe to use in the majority of contexts within
4034a2b56ebSLawrence Stewartthe kernel including most fast paths.
4044a2b56ebSLawrence Stewart.Sh RETURN VALUES
4054a2b56ebSLawrence Stewart.Fn osd_register
4064a2b56ebSLawrence Stewartreturns the slot identifier for the newly registered data type.
4074a2b56ebSLawrence Stewart.Pp
4084a2b56ebSLawrence Stewart.Fn osd_set
409320d8421SJamie Grittonand
410320d8421SJamie Gritton.Fn osd_set_reserved
411320d8421SJamie Grittonreturn zero on success or ENOMEM if the specified type/slot identifier pair
4124a2b56ebSLawrence Stewarttriggered an internal
4134a2b56ebSLawrence Stewart.Xr realloc 9
414320d8421SJamie Grittonwhich failed
415*c85d7166SChristian Brueffer.Ns (
416*c85d7166SChristian Brueffer.Fn osd_set_reserved
417320d8421SJamie Grittonwill always succeed when
418320d8421SJamie Gritton.Fa rsv
419320d8421SJamie Grittonis non-NULL).
4204a2b56ebSLawrence Stewart.Pp
4214a2b56ebSLawrence Stewart.Fn osd_get
4224a2b56ebSLawrence Stewartreturns the data pointer for the specified type/slot identifier pair, or NULL if
4234a2b56ebSLawrence Stewartthe slot has not been initialised yet.
4244a2b56ebSLawrence Stewart.Pp
425320d8421SJamie Gritton.Fn osd_reserve
426320d8421SJamie Grittonreturns a pointer suitable for passing to
427320d8421SJamie Gritton.Fn osd_set_reserved
428320d8421SJamie Grittonor
429320d8421SJamie Gritton.Fn osd_free_reserved .
430320d8421SJamie Gritton.Pp
4314a2b56ebSLawrence Stewart.Fn osd_call
4324a2b56ebSLawrence Stewartreturns zero if no method is run or the method for each slot runs successfully.
4334a2b56ebSLawrence StewartIf a method for a slot returns non-zero,
4344a2b56ebSLawrence Stewart.Fn osd_call
4354a2b56ebSLawrence Stewartterminates prematurely and returns the method's error to the caller.
4364a2b56ebSLawrence Stewart.Sh SEE ALSO
4374a2b56ebSLawrence Stewart.Xr khelp 9
4384a2b56ebSLawrence Stewart.Sh HISTORY
4394a2b56ebSLawrence StewartThe
4404a2b56ebSLawrence StewartObject Specific Data (OSD) facility first appeared in
4414a2b56ebSLawrence Stewart.Fx 8.0 .
4424a2b56ebSLawrence Stewart.Sh AUTHORS
4434a2b56ebSLawrence Stewart.An -nosplit
4444a2b56ebSLawrence StewartThe
4454a2b56ebSLawrence Stewart.Nm
4464a2b56ebSLawrence Stewartfacility was written by
4478a7314fcSBaptiste Daroussin.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org .
4484a2b56ebSLawrence Stewart.Pp
4494a2b56ebSLawrence StewartThis manual page was written by
4508a7314fcSBaptiste Daroussin.An Lawrence Stewart Aq Mt lstewart@FreeBSD.org .
451