summaryrefslogtreecommitdiff
path: root/static/freebsd/man9/g_consumer.9 3.html
blob: dbd9d284227977b828dad99eb694f1a4d450284c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<table class="head">
  <tr>
    <td class="head-ltitle">G_CONSUMER(9)</td>
    <td class="head-vol">Kernel Developer's Manual</td>
    <td class="head-rtitle">G_CONSUMER(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">g_new_consumer</code>,
    <code class="Nm">g_destroy_consumer</code> &#x2014; <span class="Nd">GEOM
    consumers management</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
    &lt;<a class="In">geom/geom.h</a>&gt;</code></p>
<p class="Pp"><var class="Ft">struct g_consumer *</var>
  <br/>
  <code class="Fn">g_new_consumer</code>(<var class="Fa" style="white-space: nowrap;">struct
    g_geom *gp</var>);</p>
<p class="Pp"><var class="Ft">void</var>
  <br/>
  <code class="Fn">g_destroy_consumer</code>(<var class="Fa" style="white-space: nowrap;">struct
    g_consumer *cp</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">A GEOM consumer is the backdoor through which a geom connects to
    another GEOM provider and through which I/O requests are sent.</p>
<p class="Pp" id="g_new_consumer">The
    <a class="permalink" href="#g_new_consumer"><code class="Fn">g_new_consumer</code></a>()
    function creates a new consumer on geom <var class="Fa">gp</var>. Before
    using the new consumer, it has to be attached to a provider with
    <a class="Xr">g_attach(9)</a> and opened with
  <a class="Xr">g_access(9)</a>.</p>
<p class="Pp" id="g_destroy_consumer">The
    <a class="permalink" href="#g_destroy_consumer"><code class="Fn">g_destroy_consumer</code></a>()
    function destroys the given consumer and cancels all related pending events.
    This function is the last stage of killing an unwanted consumer.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="RESTRICTIONS/CONDITIONS"><a class="permalink" href="#RESTRICTIONS/CONDITIONS">RESTRICTIONS/CONDITIONS</a></h1>
<p class="Pp"><code class="Fn">g_new_consumer</code>():</p>
<ul class="Bl-item Bd-indent">
  <li>The geom <var class="Fa">gp</var> has to have an
      <var class="Va">orphan</var> method defined.</li>
  <li>The topology lock has to be held.</li>
</ul>
<p class="Pp" id="g_destroy_consumer~2"><a class="permalink" href="#g_destroy_consumer~2"><code class="Fn">g_destroy_consumer</code></a>():</p>
<ul class="Bl-item Bd-indent">
  <li>The consumer must not be attached to a provider.</li>
  <li>The access count has to be 0.</li>
  <li>The topology lock has to be held.</li>
</ul>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
  VALUES</a></h1>
<p class="Pp">The <code class="Fn">g_new_consumer</code>() function returns a
    pointer to the newly created consumer.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="EXAMPLES"><a class="permalink" href="#EXAMPLES">EXAMPLES</a></h1>
<p class="Pp">Create consumer, attach it to given provider, gain read access and
    clean up.</p>
<div class="Bd Pp Bd-indent Li">
<pre>void
some_function(struct g_geom *mygeom, struct g_provider *pp)
{
	struct g_consumer *cp;

	g_topology_assert();

	/* Create new consumer on 'mygeom' geom. */
	cp = g_new_consumer(mygeom);
	/* Attach newly created consumer to given provider. */
	if (g_attach(cp, pp) != 0) {
		g_destroy_consumer(cp);
		return;
	}
	/* Open provider for reading through our consumer. */
	if (g_access(cp, 1, 0, 0) != 0) {
		g_detach(cp);
		g_destroy_consumer(cp);
		return;
	}

	g_topology_unlock();
	/*
	 * Read data from provider.
	 */
	g_topology_lock();

	/* Disconnect from provider (release access count). */
	g_access(cp, -1, 0, 0);
	/* Detach from provider. */
	g_detach(cp);
	/* Destroy consumer. */
	g_destroy_consumer(cp);
}</pre>
</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">geom(4)</a>,
    <a class="Xr">DECLARE_GEOM_CLASS(9)</a>, <a class="Xr">g_access(9)</a>,
    <a class="Xr">g_attach(9)</a>, <a class="Xr">g_bio(9)</a>,
    <a class="Xr">g_data(9)</a>, <a class="Xr">g_event(9)</a>,
    <a class="Xr">g_geom(9)</a>, <a class="Xr">g_provider(9)</a>,
    <a class="Xr">g_provider_by_name(9)</a>,
  <a class="Xr">g_wither_geom(9)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">This manual page was written by <span class="An">Pawel Jakub
    Dawidek</span>
    &lt;<a class="Mt" href="mailto:pjd@FreeBSD.org">pjd@FreeBSD.org</a>&gt;.</p>
</section>
</div>
<table class="foot">
  <tr>
    <td class="foot-date">January 16, 2004</td>
    <td class="foot-os">FreeBSD 15.0</td>
  </tr>
</table>