diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:55:43 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:55:43 -0400 |
| commit | ac5e55f5f2af5b92794c2aded46c6bae85b5f5ed (patch) | |
| tree | 9367490586c84cba28652e443e3166d66c33b0d9 /static/freebsd/man9/dev_refthread.9 3.html | |
| parent | 253e67c8b3a72b3a4757fdbc5845297628db0a4a (diff) | |
docs: Added All FreeBSD Manuals
Diffstat (limited to 'static/freebsd/man9/dev_refthread.9 3.html')
| -rw-r--r-- | static/freebsd/man9/dev_refthread.9 3.html | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/static/freebsd/man9/dev_refthread.9 3.html b/static/freebsd/man9/dev_refthread.9 3.html new file mode 100644 index 00000000..9ca70fac --- /dev/null +++ b/static/freebsd/man9/dev_refthread.9 3.html @@ -0,0 +1,125 @@ +<table class="head"> + <tr> + <td class="head-ltitle">DEV_REFTHREAD(9)</td> + <td class="head-vol">Kernel Developer's Manual</td> + <td class="head-rtitle">DEV_REFTHREAD(9)</td> + </tr> +</table> +<div class="manual-text"> +<section class="Sh"> +<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1> +<p class="Pp"><code class="Nm">dev_refthread</code>, + <code class="Nm">devvn_refthread</code>, + <code class="Nm">dev_relthread</code> — <span class="Nd">safely + access device methods</span></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1> +<p class="Pp"><code class="In">#include + <<a class="In">sys/param.h</a>></code> + <br/> + <code class="In">#include <<a class="In">sys/conf.h</a>></code></p> +<p class="Pp"><var class="Ft">struct cdevsw *</var> + <br/> + <code class="Fn">dev_refthread</code>(<var class="Fa" style="white-space: nowrap;">struct + cdev *dev</var>, <var class="Fa" style="white-space: nowrap;">int + *ref</var>);</p> +<p class="Pp"><var class="Ft">struct cdevsw *</var> + <br/> + <code class="Fn">devvn_refthread</code>(<var class="Fa" style="white-space: nowrap;">struct + vnode *vp</var>, <var class="Fa" style="white-space: nowrap;">struct cdev + **devp</var>, <var class="Fa" style="white-space: nowrap;">int + *ref</var>);</p> +<p class="Pp"><var class="Ft">void</var> + <br/> + <code class="Fn">dev_relthread</code>(<var class="Fa" style="white-space: nowrap;">struct + cdev *dev</var>, <var class="Fa" style="white-space: nowrap;">int + ref</var>);</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1> +<p class="Pp">The + <a class="permalink" href="#dev_refthread"><code class="Fn" id="dev_refthread">dev_refthread</code></a>() + (or <code class="Fn">devvn_refthread</code>()) and + <code class="Fn">dev_relthread</code>() routines provide a safe way to + access <a class="Xr">devfs(4)</a> devices that may be concurrently destroyed + by + <a class="permalink" href="#destroy_dev"><code class="Fn" id="destroy_dev">destroy_dev</code></a>() + (e.g., removable media).</p> +<p class="Pp" id="dev_refthread~2">If successful, + <a class="permalink" href="#dev_refthread~2"><code class="Fn">dev_refthread</code></a>() + and <code class="Fn">devvn_refthread</code>() acquire a "thread + reference" to the associated <var class="Vt">struct cdev</var> and + return a non-NULL pointer to the cdev's <var class="Vt">struct cdevsw</var> + method table. For the duration of that reference, the cdev's associated + private data and method table object are valid. Destruction of the cdev + sleeps until the thread reference is released.</p> +<p class="Pp" id="dev_refthread~3">A reference cannot prevent media removal. It + is an implementation detail of individual drivers how method calls from + callers with + <a class="permalink" href="#dev_refthread~3"><code class="Fn">dev_refthread</code></a>() + references are handled when the device is pending destruction. A common + behavior for disk devices is to return the <code class="Er">ENXIO</code> + status, but that is not required by this KPI.</p> +<p class="Pp" id="devvn_refthread">The + <a class="permalink" href="#devvn_refthread"><code class="Fn">devvn_refthread</code></a>() + variant of <code class="Fn">dev_refthread</code>() extracts the + <var class="Vt">struct cdev</var> pointer out of the + <code class="Dv">VCHR</code> <a class="Xr">vnode(9)</a> automatically before + performing the same actions as <code class="Fn">dev_refthread</code>(). + Additionally, a pointer to the <var class="Vt">struct cdev</var> is returned + to the caller via <var class="Fa">*devp</var>. + <code class="Fn">devvn_refthread</code>() correctly handles possible + parallel reclamation of the vnode.</p> +<p class="Pp" id="dev_relthread"><a class="permalink" href="#dev_relthread"><code class="Fn">dev_relthread</code></a>() + is used to release a reference to a <var class="Vt">struct cdev</var>. + <code class="Fn">dev_relthread</code>() + <a class="permalink" href="#must"><b class="Sy" id="must">must</b></a> only + be invoked when the associated invocation of + <code class="Fn">dev_refthread</code>() or + <code class="Fn">devvn_refthread</code>() returned a non-NULL + <var class="Vt">struct cdevsw *</var>.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="CONTEXT"><a class="permalink" href="#CONTEXT">CONTEXT</a></h1> +<p class="Pp"><var class="Vt">struct cdev</var> objects have two reference + counts, <var class="Va">si_refcount</var> and + <var class="Va">si_threadcount</var>. The + <code class="Fn">dev_refthread</code>(), + <code class="Fn">devvn_refthread</code>(), and + <code class="Fn">dev_relthread</code>() functions manipulate the + <var class="Va">si_threadcount</var>. The + <var class="Va">si_threadcount</var> reference guarantees the liveness of + the <var class="Vt">struct cdev</var> object. The other + <var class="Va">si_refcount</var> reference provides only the weaker + guarantee that the memory backing the <var class="Vt">struct cdev</var> has + not been freed.</p> +</section> +<section class="Sh"> +<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN + VALUES</a></h1> +<p class="Pp">If <code class="Fn">dev_refthread</code>() or + <code class="Fn">devvn_refthread</code>() are unsuccessful, they return + <code class="Dv">NULL</code>.</p> +<div class="Bf Em">If these routines are unsuccessful, they do not increment the + <var class="Vt">struct cdev</var> <var class="Va">si_threadcount</var> and do + not initialize the value pointed to by the <var class="Fa">*ref</var> + parameter in any way.</div> +</section> +<section class="Sh"> +<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE + ALSO</a></h1> +<p class="Pp"><a class="Xr">devfs(4)</a>, <a class="Xr">destroy_dev(9)</a></p> +</section> +<section class="Sh"> +<h1 class="Sh" id="CAVEATS"><a class="permalink" href="#CAVEATS">CAVEATS</a></h1> +<p class="Pp">Do not invoke <code class="Fn">dev_relthread</code>() unless the + matching refthread routine succeeded!</p> +</section> +</div> +<table class="foot"> + <tr> + <td class="foot-date">August 29, 2018</td> + <td class="foot-os">FreeBSD 15.0</td> + </tr> +</table> |
