1 .\" Copyright (c) 2018 Conrad Meyer <cem@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Nd safely access device methods
39 .Fn dev_refthread "struct cdev *dev" "int *ref"
41 .Fn devvn_refthread "struct vnode *vp" "struct cdev **devp" "int *ref"
43 .Fn dev_relthread "struct cdev *dev" "int ref"
51 routines provide a safe way to access
53 devices that may be concurrently destroyed by
55 (e.g., removable media).
61 acquire a "thread reference" to the associated
63 and return a non-NULL pointer to the cdev's
66 For the duration of that reference, the cdev's associated private data and
67 method table object are valid.
68 Destruction of the cdev sleeps until the thread reference is released.
70 A reference cannot prevent media removal.
71 It is an implementation detail of individual drivers how method calls from
74 references are handled when the device is
76 A common behavior for disk devices is to return the
78 status, but that is not required by this KPI.
89 automatically before performing the same actions as
91 Additionally, a pointer to the
93 is returned to the caller via
96 correctly handles possible parallel reclamation of the vnode.
99 is used to release a reference to a
103 only be invoked when the associated invocation of
108 .Vt "struct cdevsw *" .
111 objects have two reference counts,
117 .Fn devvn_refthread ,
120 functions manipulate the
124 reference guarantees the liveness of the
129 reference provides only the weaker guarantee that the memory backing the
137 are unsuccessful, they return
140 If these routines are unsuccessful, they do not increment the
143 and do not initialize the value pointed to by the
145 parameter in any way.
153 unless the matching refthread routine succeeded!