Lines Matching +full:- +full:gp
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
63 static int g_mountver_destroy(struct g_geom *gp, boolean_t force);
66 struct g_geom *gp);
70 struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp);
90 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) in g_mountver_detach()
91 g_access(cp, -cp->acr, -cp->acw, -cp->ace); in g_mountver_detach()
99 struct g_geom *gp; in g_mountver_done() local
103 cp = bp->bio_from; in g_mountver_done()
104 gp = cp->geom; in g_mountver_done()
105 if (bp->bio_error != ENXIO) { in g_mountver_done()
116 pbp = bp->bio_parent; in g_mountver_done()
117 KASSERT(pbp->bio_to == LIST_FIRST(&gp->provider), in g_mountver_done()
120 pbp->bio_inbed++; in g_mountver_done()
124 sc = gp->softc; in g_mountver_done()
125 mtx_lock(&sc->sc_mtx); in g_mountver_done()
126 if (--cp->index == 0 && sc->sc_orphaned) in g_mountver_done()
128 mtx_unlock(&sc->sc_mtx); in g_mountver_done()
136 g_mountver_send(struct g_geom *gp, struct bio *bp) in g_mountver_send() argument
138 struct g_mountver_softc *sc = gp->softc; in g_mountver_send()
142 mtx_assert(&sc->sc_mtx, MA_OWNED); in g_mountver_send()
145 mtx_unlock(&sc->sc_mtx); in g_mountver_send()
149 cp = LIST_FIRST(&gp->consumer); in g_mountver_send()
150 cp->index++; in g_mountver_send()
151 mtx_unlock(&sc->sc_mtx); in g_mountver_send()
153 cbp->bio_done = g_mountver_done; in g_mountver_send()
161 struct g_geom *gp; in g_mountver_queue() local
163 gp = bp->bio_to->geom; in g_mountver_queue()
164 sc = gp->softc; in g_mountver_queue()
166 mtx_lock(&sc->sc_mtx); in g_mountver_queue()
167 TAILQ_INSERT_TAIL(&sc->sc_queue, bp, bio_queue); in g_mountver_queue()
168 mtx_unlock(&sc->sc_mtx); in g_mountver_queue()
172 g_mountver_send_queued(struct g_geom *gp) in g_mountver_send_queued() argument
177 sc = gp->softc; in g_mountver_send_queued()
179 mtx_lock(&sc->sc_mtx); in g_mountver_send_queued()
180 while ((bp = TAILQ_FIRST(&sc->sc_queue)) != NULL && !sc->sc_orphaned) { in g_mountver_send_queued()
181 TAILQ_REMOVE(&sc->sc_queue, bp, bio_queue); in g_mountver_send_queued()
184 g_mountver_send(gp, bp); in g_mountver_send_queued()
185 mtx_lock(&sc->sc_mtx); in g_mountver_send_queued()
187 mtx_unlock(&sc->sc_mtx); in g_mountver_send_queued()
191 g_mountver_discard_queued(struct g_geom *gp) in g_mountver_discard_queued() argument
196 sc = gp->softc; in g_mountver_discard_queued()
198 mtx_lock(&sc->sc_mtx); in g_mountver_discard_queued()
199 while ((bp = TAILQ_FIRST(&sc->sc_queue)) != NULL) { in g_mountver_discard_queued()
200 TAILQ_REMOVE(&sc->sc_queue, bp, bio_queue); in g_mountver_discard_queued()
201 mtx_unlock(&sc->sc_mtx); in g_mountver_discard_queued()
204 mtx_lock(&sc->sc_mtx); in g_mountver_discard_queued()
206 mtx_unlock(&sc->sc_mtx); in g_mountver_discard_queued()
213 struct g_geom *gp; in g_mountver_start() local
215 gp = bp->bio_to->geom; in g_mountver_start()
216 sc = gp->softc; in g_mountver_start()
224 mtx_lock(&sc->sc_mtx); in g_mountver_start()
225 if (sc->sc_orphaned || !TAILQ_EMPTY(&sc->sc_queue)) { in g_mountver_start()
226 mtx_unlock(&sc->sc_mtx); in g_mountver_start()
227 if (sc->sc_shutting_down) { in g_mountver_start()
234 if (!sc->sc_orphaned) in g_mountver_start()
235 g_mountver_send_queued(gp); in g_mountver_start()
239 g_mountver_send(gp, bp); in g_mountver_start()
247 struct g_geom *gp; in g_mountver_access() local
252 gp = pp->geom; in g_mountver_access()
253 cp = LIST_FIRST(&gp->consumer); in g_mountver_access()
254 sc = gp->softc; in g_mountver_access()
257 KASSERT(sc != NULL, ("Trying to access withered provider \"%s\".", pp->name)); in g_mountver_access()
259 sc->sc_access_r += dr; in g_mountver_access()
260 sc->sc_access_w += dw; in g_mountver_access()
261 sc->sc_access_e += de; in g_mountver_access()
263 if (sc->sc_orphaned) in g_mountver_access()
273 struct g_geom *gp; in g_mountver_create() local
283 gp = NULL; in g_mountver_create()
287 snprintf(name, sizeof(name), "%s%s", pp->name, G_MOUNTVER_SUFFIX); in g_mountver_create()
288 LIST_FOREACH(gp, &mp->geom, geom) { in g_mountver_create()
289 if (strcmp(gp->name, name) == 0) { in g_mountver_create()
294 gp = g_new_geom(mp, name); in g_mountver_create()
296 mtx_init(&sc->sc_mtx, "gmountver", NULL, MTX_DEF | MTX_RECURSE); in g_mountver_create()
297 TAILQ_INIT(&sc->sc_queue); in g_mountver_create()
298 sc->sc_provider_name = strdup(pp->name, M_GEOM); in g_mountver_create()
299 gp->softc = sc; in g_mountver_create()
300 gp->start = g_mountver_start; in g_mountver_create()
301 gp->orphan = g_mountver_orphan; in g_mountver_create()
302 gp->resize = g_mountver_resize; in g_mountver_create()
303 gp->access = g_mountver_access; in g_mountver_create()
304 gp->dumpconf = g_mountver_dumpconf; in g_mountver_create()
306 newpp = g_new_providerf(gp, "%s", gp->name); in g_mountver_create()
307 newpp->mediasize = pp->mediasize; in g_mountver_create()
308 newpp->sectorsize = pp->sectorsize; in g_mountver_create()
309 newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE; in g_mountver_create()
310 LIST_FOREACH(gap, &pp->aliases, ga_next) in g_mountver_create()
311 g_provider_add_alias(newpp, "%s%s", gap->ga_alias, G_MOUNTVER_SUFFIX); in g_mountver_create()
313 if ((pp->flags & G_PF_ACCEPT_UNMAPPED) != 0) { in g_mountver_create()
314 G_MOUNTVER_DEBUG(0, "Unmapped supported for %s.", gp->name); in g_mountver_create()
315 newpp->flags |= G_PF_ACCEPT_UNMAPPED; in g_mountver_create()
317 G_MOUNTVER_DEBUG(0, "Unmapped unsupported for %s.", gp->name); in g_mountver_create()
318 newpp->flags &= ~G_PF_ACCEPT_UNMAPPED; in g_mountver_create()
321 cp = g_new_consumer(gp); in g_mountver_create()
322 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; in g_mountver_create()
325 gctl_error(req, "Cannot attach to provider %s.", pp->name); in g_mountver_create()
330 gctl_error(req, "Cannot access provider %s.", pp->name); in g_mountver_create()
333 error = g_io_getattr("GEOM::ident", cp, &identsize, sc->sc_ident); in g_mountver_create()
334 g_access(cp, -1, 0, 0); in g_mountver_create()
337 gctl_error(req, "Cannot get disk ident from %s; error = %d.", pp->name, error); in g_mountver_create()
341 G_MOUNTVER_DEBUG(0, "Cannot get disk ident from %s; error = %d.", pp->name, error); in g_mountver_create()
342 sc->sc_ident[0] = '\0'; in g_mountver_create()
346 G_MOUNTVER_DEBUG(0, "Device %s created.", gp->name); in g_mountver_create()
349 g_free(sc->sc_provider_name); in g_mountver_create()
350 if (cp->provider != NULL) in g_mountver_create()
354 g_free(gp->softc); in g_mountver_create()
355 g_destroy_geom(gp); in g_mountver_create()
360 g_mountver_destroy(struct g_geom *gp, boolean_t force) in g_mountver_destroy() argument
366 if (gp->softc == NULL) in g_mountver_destroy()
368 sc = gp->softc; in g_mountver_destroy()
369 pp = LIST_FIRST(&gp->provider); in g_mountver_destroy()
370 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) { in g_mountver_destroy()
373 "can't be definitely removed.", pp->name); in g_mountver_destroy()
376 pp->name, pp->acr, pp->acw, pp->ace); in g_mountver_destroy()
380 G_MOUNTVER_DEBUG(0, "Device %s removed.", gp->name); in g_mountver_destroy()
384 g_mountver_discard_queued(gp); in g_mountver_destroy()
385 g_free(sc->sc_provider_name); in g_mountver_destroy()
386 g_free(gp->softc); in g_mountver_destroy()
387 gp->softc = NULL; in g_mountver_destroy()
388 g_wither_geom(gp, ENXIO); in g_mountver_destroy()
394 g_mountver_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp) in g_mountver_destroy_geom() argument
397 return (g_mountver_destroy(gp, 0)); in g_mountver_destroy_geom()
431 struct g_geom *gp; in g_mountver_find_geom() local
433 LIST_FOREACH(gp, &mp->geom, geom) { in g_mountver_find_geom()
434 if (strcmp(gp->name, name) == 0) in g_mountver_find_geom()
435 return (gp); in g_mountver_find_geom()
444 struct g_geom *gp; in g_mountver_ctl_destroy() local
474 gp = g_mountver_find_geom(mp, name); in g_mountver_ctl_destroy()
475 if (gp == NULL) { in g_mountver_ctl_destroy()
480 error = g_mountver_destroy(gp, *force); in g_mountver_ctl_destroy()
483 gp->name, error); in g_mountver_ctl_destroy()
497 sc = cp->geom->softc; in g_mountver_orphan()
498 mtx_lock(&sc->sc_mtx); in g_mountver_orphan()
499 sc->sc_orphaned = 1; in g_mountver_orphan()
500 done = (cp->index == 0); in g_mountver_orphan()
501 mtx_unlock(&sc->sc_mtx); in g_mountver_orphan()
504 G_MOUNTVER_DEBUG(0, "%s is offline. Mount verification in progress.", sc->sc_provider_name); in g_mountver_orphan()
510 struct g_geom *gp; in g_mountver_resize() local
513 gp = cp->geom; in g_mountver_resize()
515 LIST_FOREACH(pp, &gp->provider, provider) in g_mountver_resize()
516 g_resize_provider(pp, cp->provider->mediasize); in g_mountver_resize()
520 g_mountver_ident_matches(struct g_geom *gp) in g_mountver_ident_matches() argument
527 sc = gp->softc; in g_mountver_ident_matches()
528 cp = LIST_FIRST(&gp->consumer); in g_mountver_ident_matches()
536 "not attaching; error = %d.", gp->name, error); in g_mountver_ident_matches()
540 g_access(cp, -1, 0, 0); in g_mountver_ident_matches()
543 "not attaching; error = %d.", gp->name, error); in g_mountver_ident_matches()
546 if (strcmp(ident, sc->sc_ident) != 0) { in g_mountver_ident_matches()
548 "from expected \"%s\", not attaching.", gp->name, ident, in g_mountver_ident_matches()
549 sc->sc_ident); in g_mountver_ident_matches()
561 struct g_geom *gp; in g_mountver_taste() local
565 g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name); in g_mountver_taste()
566 G_MOUNTVER_DEBUG(2, "Tasting %s.", pp->name); in g_mountver_taste()
571 LIST_FOREACH(gp, &mp->geom, geom) { in g_mountver_taste()
572 sc = gp->softc; in g_mountver_taste()
577 if (pp == LIST_FIRST(&gp->provider)) in g_mountver_taste()
580 if (sc->sc_orphaned && strcmp(pp->name, sc->sc_provider_name) == 0) in g_mountver_taste()
583 if (gp == NULL) in g_mountver_taste()
586 cp = LIST_FIRST(&gp->consumer); in g_mountver_taste()
589 G_MOUNTVER_DEBUG(0, "Cannot attach to %s; error = %d.", pp->name, error); in g_mountver_taste()
593 error = g_mountver_ident_matches(gp); in g_mountver_taste()
598 if (sc->sc_access_r > 0 || sc->sc_access_w > 0 || sc->sc_access_e > 0) { in g_mountver_taste()
599 error = g_access(cp, sc->sc_access_r, sc->sc_access_w, sc->sc_access_e); in g_mountver_taste()
601 G_MOUNTVER_DEBUG(0, "Cannot access %s; error = %d.", pp->name, error); in g_mountver_taste()
606 sc->sc_orphaned = 0; in g_mountver_taste()
607 g_mountver_send_queued(gp); in g_mountver_taste()
608 G_MOUNTVER_DEBUG(0, "%s has completed mount verification.", sc->sc_provider_name); in g_mountver_taste()
610 return (gp); in g_mountver_taste()
642 g_mountver_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, in g_mountver_dumpconf() argument
650 sc = gp->softc; in g_mountver_dumpconf()
652 sc->sc_orphaned ? "OFFLINE" : "ONLINE"); in g_mountver_dumpconf()
653 sbuf_printf(sb, "%s<Provider-Name>%s</Provider-Name>\n", indent, sc->sc_provider_name); in g_mountver_dumpconf()
654 sbuf_printf(sb, "%s<Disk-Ident>%s</Disk-Ident>\n", indent, sc->sc_ident); in g_mountver_dumpconf()
662 struct g_geom *gp, *gp2; in g_mountver_shutdown_pre_sync() local
666 LIST_FOREACH_SAFE(gp, &mp->geom, geom, gp2) { in g_mountver_shutdown_pre_sync()
667 if (gp->softc == NULL) in g_mountver_shutdown_pre_sync()
669 sc = gp->softc; in g_mountver_shutdown_pre_sync()
670 sc->sc_shutting_down = 1; in g_mountver_shutdown_pre_sync()
671 if (sc->sc_orphaned) in g_mountver_shutdown_pre_sync()
672 g_mountver_destroy(gp, 1); in g_mountver_shutdown_pre_sync()