geom_event.c (18e88d825ca7d2e4ed0d52be1821871c47d6ac94) geom_event.c (3d1d5bc3c36007d92f05fc5b1d08998598722a0b)
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

--- 45 unchanged lines hidden (view full) ---

54#include <geom/geom_int.h>
55
56TAILQ_HEAD(event_tailq_head, g_event);
57
58static struct event_tailq_head g_events = TAILQ_HEAD_INITIALIZER(g_events);
59static u_int g_pending_events;
60static TAILQ_HEAD(,g_provider) g_doorstep = TAILQ_HEAD_INITIALIZER(g_doorstep);
61static struct mtx g_eventlock;
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

--- 45 unchanged lines hidden (view full) ---

54#include <geom/geom_int.h>
55
56TAILQ_HEAD(event_tailq_head, g_event);
57
58static struct event_tailq_head g_events = TAILQ_HEAD_INITIALIZER(g_events);
59static u_int g_pending_events;
60static TAILQ_HEAD(,g_provider) g_doorstep = TAILQ_HEAD_INITIALIZER(g_doorstep);
61static struct mtx g_eventlock;
62static struct sx g_eventstall;
63
64#define G_N_EVENTREFS 20
65
66struct g_event {
67 TAILQ_ENTRY(g_event) events;
68 g_event_t *func;
69 void *arg;
70 int flag;

--- 8 unchanged lines hidden (view full) ---

79g_waitidle(void)
80{
81
82 while (g_pending_events)
83 tsleep(&g_pending_events, PPAUSE, "g_waitidle", hz/5);
84}
85
86void
62
63#define G_N_EVENTREFS 20
64
65struct g_event {
66 TAILQ_ENTRY(g_event) events;
67 g_event_t *func;
68 void *arg;
69 int flag;

--- 8 unchanged lines hidden (view full) ---

78g_waitidle(void)
79{
80
81 while (g_pending_events)
82 tsleep(&g_pending_events, PPAUSE, "g_waitidle", hz/5);
83}
84
85void
87g_stall_events(void)
88{
89
90 sx_xlock(&g_eventstall);
91}
92
93void
94g_release_events(void)
95{
96
97 sx_xunlock(&g_eventstall);
98}
99
100void
101g_orphan_provider(struct g_provider *pp, int error)
102{
103
86g_orphan_provider(struct g_provider *pp, int error)
87{
88
89 /* G_VALID_PROVIDER(pp) We likely lack topology lock */
104 g_trace(G_T_TOPOLOGY, "g_orphan_provider(%p(%s), %d)",
105 pp, pp->name, error);
106 KASSERT(error != 0,
107 ("g_orphan_provider(%p(%s), 0) error must be non-zero\n",
108 pp, pp->name));
109
110 pp->error = error;
111 mtx_lock(&g_eventlock);

--- 11 unchanged lines hidden (view full) ---

123 */
124
125static void
126g_orphan_register(struct g_provider *pp)
127{
128 struct g_consumer *cp, *cp2;
129 int wf;
130
90 g_trace(G_T_TOPOLOGY, "g_orphan_provider(%p(%s), %d)",
91 pp, pp->name, error);
92 KASSERT(error != 0,
93 ("g_orphan_provider(%p(%s), 0) error must be non-zero\n",
94 pp, pp->name));
95
96 pp->error = error;
97 mtx_lock(&g_eventlock);

--- 11 unchanged lines hidden (view full) ---

109 */
110
111static void
112g_orphan_register(struct g_provider *pp)
113{
114 struct g_consumer *cp, *cp2;
115 int wf;
116
131 g_trace(G_T_TOPOLOGY, "g_orphan_register(%s)", pp->name);
132 g_topology_assert();
117 g_topology_assert();
118 G_VALID_PROVIDER(pp);
119 g_trace(G_T_TOPOLOGY, "g_orphan_register(%s)", pp->name);
133
134 wf = pp->flags & G_PF_WITHER;
135 pp->flags &= ~G_PF_WITHER;
136
137 /*
138 * Tell all consumers the bad news.
139 * Don't be surprised if they self-destruct.
140 */

--- 20 unchanged lines hidden (view full) ---

161}
162
163static int
164one_event(void)
165{
166 struct g_event *ep;
167 struct g_provider *pp;
168
120
121 wf = pp->flags & G_PF_WITHER;
122 pp->flags &= ~G_PF_WITHER;
123
124 /*
125 * Tell all consumers the bad news.
126 * Don't be surprised if they self-destruct.
127 */

--- 20 unchanged lines hidden (view full) ---

148}
149
150static int
151one_event(void)
152{
153 struct g_event *ep;
154 struct g_provider *pp;
155
169 sx_xlock(&g_eventstall);
170 g_topology_lock();
171 for (;;) {
172 mtx_lock(&g_eventlock);
173 pp = TAILQ_FIRST(&g_doorstep);
156 g_topology_lock();
157 for (;;) {
158 mtx_lock(&g_eventlock);
159 pp = TAILQ_FIRST(&g_doorstep);
174 if (pp != NULL)
160 if (pp != NULL) {
161 G_VALID_PROVIDER(pp);
175 TAILQ_REMOVE(&g_doorstep, pp, orphan);
162 TAILQ_REMOVE(&g_doorstep, pp, orphan);
163 }
176 mtx_unlock(&g_eventlock);
177 if (pp == NULL)
178 break;
179 g_orphan_register(pp);
180 }
181 mtx_lock(&g_eventlock);
182 ep = TAILQ_FIRST(&g_events);
183 if (ep == NULL) {
184 mtx_unlock(&g_eventlock);
185 g_topology_unlock();
164 mtx_unlock(&g_eventlock);
165 if (pp == NULL)
166 break;
167 g_orphan_register(pp);
168 }
169 mtx_lock(&g_eventlock);
170 ep = TAILQ_FIRST(&g_events);
171 if (ep == NULL) {
172 mtx_unlock(&g_eventlock);
173 g_topology_unlock();
186 sx_xunlock(&g_eventstall);
187 return (0);
188 }
189 TAILQ_REMOVE(&g_events, ep, events);
190 mtx_unlock(&g_eventlock);
191 g_topology_assert();
192 ep->func(ep->arg, 0);
193 g_topology_assert();
194 if (ep->flag & EV_WAKEUP) {
195 ep->flag |= EV_DONE;
196 wakeup(ep);
197 } else {
198 g_free(ep);
199 }
200 g_pending_events--;
201 if (g_pending_events == 0)
202 wakeup(&g_pending_events);
203 g_topology_unlock();
174 return (0);
175 }
176 TAILQ_REMOVE(&g_events, ep, events);
177 mtx_unlock(&g_eventlock);
178 g_topology_assert();
179 ep->func(ep->arg, 0);
180 g_topology_assert();
181 if (ep->flag & EV_WAKEUP) {
182 ep->flag |= EV_DONE;
183 wakeup(ep);
184 } else {
185 g_free(ep);
186 }
187 g_pending_events--;
188 if (g_pending_events == 0)
189 wakeup(&g_pending_events);
190 g_topology_unlock();
204 sx_xunlock(&g_eventstall);
205 return (1);
206}
207
208void
209g_run_events()
210{
211
212 while (one_event())

--- 119 unchanged lines hidden (view full) ---

332 return (error);
333}
334
335void
336g_event_init()
337{
338
339 mtx_init(&g_eventlock, "GEOM orphanage", NULL, MTX_DEF);
191 return (1);
192}
193
194void
195g_run_events()
196{
197
198 while (one_event())

--- 119 unchanged lines hidden (view full) ---

318 return (error);
319}
320
321void
322g_event_init()
323{
324
325 mtx_init(&g_eventlock, "GEOM orphanage", NULL, MTX_DEF);
340 sx_init(&g_eventstall, "GEOM event stalling");
341}
326}