Lines Matching +full:- +full:gp
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2002 Poul-Henning Kamp
8 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
10 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
62 gsp->softc = g_malloc(scsize, M_WAITOK | M_ZERO); in g_slice_alloc()
64 gsp->softc = NULL; in g_slice_alloc()
65 gsp->slices = g_malloc(nslice * sizeof(struct g_slice), in g_slice_alloc()
67 gsp->nslice = nslice; in g_slice_alloc()
72 g_slice_free(struct g_geom *gp) in g_slice_free() argument
76 gsp = gp->softc; in g_slice_free()
77 gp->softc = NULL; in g_slice_free()
80 * We can get multiple spoiled events before wither-washer in g_slice_free()
86 g_free(gsp->slices); in g_slice_free()
87 g_free(gsp->hotspot); in g_slice_free()
88 g_free(gsp->softc); in g_slice_free()
97 struct g_geom *gp; in g_slice_access() local
103 gp = pp->geom; in g_slice_access()
104 cp = LIST_FIRST(&gp->consumer); in g_slice_access()
106 gsp = gp->softc; in g_slice_access()
108 gsl = &gsp->slices[pp->index]; in g_slice_access()
109 for (u = 0; u < gsp->nslice; u++) { in g_slice_access()
110 gsl2 = &gsp->slices[u]; in g_slice_access()
111 if (gsl2->length == 0) in g_slice_access()
113 if (u == pp->index) in g_slice_access()
115 if (gsl->offset + gsl->length <= gsl2->offset) in g_slice_access()
117 if (gsl2->offset + gsl2->length <= gsl->offset) in g_slice_access()
120 pp2 = gsl2->provider; in g_slice_access()
121 if ((pp->acw + dw) > 0 && pp2->ace > 0) in g_slice_access()
123 if ((pp->ace + de) > 0 && pp2->acw > 0) in g_slice_access()
128 if (cp->acr == 0 && cp->acw == 0 && cp->ace == 0) in g_slice_access()
131 if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1) in g_slice_access()
132 de--; in g_slice_access()
139 if (error == 0 && (gp->flags & G_GEOM_WITHER) != 0 && in g_slice_access()
140 (cp->acr + cp->acw + cp->ace) == 0) in g_slice_access()
141 g_slice_free(gp); in g_slice_access()
148 * XXX: bio, or only the non-hot bits. This would get messy if there were
157 struct g_geom *gp; in g_slice_finish_hot() local
163 KASSERT(bp->bio_to != NULL, in g_slice_finish_hot()
165 KASSERT(bp->bio_from != NULL, in g_slice_finish_hot()
167 gp = bp->bio_to->geom; in g_slice_finish_hot()
168 gsp = gp->softc; in g_slice_finish_hot()
169 cp = LIST_FIRST(&gp->consumer); in g_slice_finish_hot()
171 idx = bp->bio_to->index; in g_slice_finish_hot()
172 gsl = &gsp->slices[idx]; in g_slice_finish_hot()
179 if (bp2->bio_offset + bp2->bio_length > gsl->length) in g_slice_finish_hot()
180 bp2->bio_length = gsl->length - bp2->bio_offset; in g_slice_finish_hot()
181 bp2->bio_done = g_std_done; in g_slice_finish_hot()
182 bp2->bio_offset += gsl->offset; in g_slice_finish_hot()
191 KASSERT(bp->bio_cmd == BIO_GETATTR && in g_slice_done()
192 strcmp(bp->bio_attribute, "GEOM::ident") == 0, in g_slice_done()
193 ("bio_cmd=0x%x bio_attribute=%s", bp->bio_cmd, bp->bio_attribute)); in g_slice_done()
195 if (bp->bio_error == 0 && bp->bio_data[0] != '\0') { in g_slice_done()
200 bp->bio_parent->bio_to->index); in g_slice_done()
201 if (strlcat(bp->bio_data, idx, bp->bio_length) >= in g_slice_done()
202 bp->bio_length) { in g_slice_done()
203 bp->bio_error = EFAULT; in g_slice_done()
214 struct g_geom *gp; in g_slice_start() local
223 pp = bp->bio_to; in g_slice_start()
224 gp = pp->geom; in g_slice_start()
225 gsp = gp->softc; in g_slice_start()
226 cp = LIST_FIRST(&gp->consumer); in g_slice_start()
227 idx = pp->index; in g_slice_start()
228 gsl = &gsp->slices[idx]; in g_slice_start()
229 switch(bp->bio_cmd) { in g_slice_start()
233 if (bp->bio_offset > gsl->length) { in g_slice_start()
241 t = bp->bio_offset + gsl->offset; in g_slice_start()
242 for (m_index = 0; m_index < gsp->nhotspot; m_index++) { in g_slice_start()
243 ghp = &gsp->hotspot[m_index]; in g_slice_start()
244 if (t >= ghp->offset + ghp->length) in g_slice_start()
246 if (t + bp->bio_length <= ghp->offset) in g_slice_start()
248 switch(bp->bio_cmd) { in g_slice_start()
249 case BIO_READ: idx = ghp->ract; break; in g_slice_start()
250 case BIO_WRITE: idx = ghp->wact; break; in g_slice_start()
251 case BIO_DELETE: idx = ghp->dact; break; in g_slice_start()
261 error = gsp->start(bp); in g_slice_start()
266 error = g_post_event(gsp->hot, bp, M_NOWAIT, in g_slice_start()
267 gp, NULL); in g_slice_start()
279 if (bp2->bio_offset + bp2->bio_length > gsl->length) in g_slice_start()
280 bp2->bio_length = gsl->length - bp2->bio_offset; in g_slice_start()
281 bp2->bio_done = g_std_done; in g_slice_start()
282 bp2->bio_offset += gsl->offset; in g_slice_start()
287 if (gsp->start != NULL && gsp->start(bp)) in g_slice_start()
289 if (!strcmp("GEOM::ident", bp->bio_attribute)) { in g_slice_start()
295 bp2->bio_done = g_slice_done; in g_slice_start()
299 if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) { in g_slice_start()
302 gkd = (struct g_kerneldump *)bp->bio_data; in g_slice_start()
303 gkd->offset += gsp->slices[idx].offset; in g_slice_start()
304 if (gkd->length > gsp->slices[idx].length) in g_slice_start()
305 gkd->length = gsp->slices[idx].length; in g_slice_start()
316 bp2->bio_done = g_std_done; in g_slice_start()
326 g_slice_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, str… in g_slice_dumpconf() argument
330 gsp = gp->softc; in g_slice_dumpconf()
332 sbuf_printf(sb, " i %u", pp->index); in g_slice_dumpconf()
334 (uintmax_t)gsp->slices[pp->index].offset); in g_slice_dumpconf()
338 sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index); in g_slice_dumpconf()
340 indent, (uintmax_t)gsp->slices[pp->index].length); in g_slice_dumpconf()
342 (uintmax_t)gsp->slices[pp->index].length / 512); in g_slice_dumpconf()
344 (uintmax_t)gsp->slices[pp->index].offset); in g_slice_dumpconf()
346 (uintmax_t)gsp->slices[pp->index].offset / 512); in g_slice_dumpconf()
351 g_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length, u_int sectorsize,… in g_slice_config() argument
361 gp->name, idx, how); in g_slice_config()
363 gsp = gp->softc; in g_slice_config()
364 if (idx >= gsp->nslice) in g_slice_config()
366 gsl = &gsp->slices[idx]; in g_slice_config()
367 pp = gsl->provider; in g_slice_config()
369 acc = pp->acr + pp->acw + pp->ace; in g_slice_config()
373 if (length < gsl->length) in g_slice_config()
375 if (offset != gsl->offset) in g_slice_config()
381 gsl->length = length; in g_slice_config()
382 gsl->offset = offset; in g_slice_config()
383 gsl->sectorsize = sectorsize; in g_slice_config()
388 printf("GEOM: Deconfigure %s\n", pp->name); in g_slice_config()
390 gsl->provider = NULL; in g_slice_config()
391 gsp->nprovider--; in g_slice_config()
397 pp->name, (intmax_t)offset, (intmax_t)length, in g_slice_config()
398 (intmax_t)(offset + length - 1)); in g_slice_config()
399 g_resize_provider(pp, gsl->length); in g_slice_config()
407 pp = g_new_providerf(gp, "%s", sbuf_data(sb)); in g_slice_config()
408 pp2 = LIST_FIRST(&gp->consumer)->provider; in g_slice_config()
409 pp->stripesize = pp2->stripesize; in g_slice_config()
410 pp->stripeoffset = pp2->stripeoffset + offset; in g_slice_config()
411 if (pp->stripesize > 0) in g_slice_config()
412 pp->stripeoffset %= pp->stripesize; in g_slice_config()
413 if (gsp->nhotspot == 0) { in g_slice_config()
414 pp->flags |= pp2->flags & G_PF_ACCEPT_UNMAPPED; in g_slice_config()
415 pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE; in g_slice_config()
419 pp->name, (intmax_t)offset, (intmax_t)length, in g_slice_config()
420 (intmax_t)(offset + length - 1)); in g_slice_config()
421 pp->index = idx; in g_slice_config()
422 pp->mediasize = gsl->length; in g_slice_config()
423 pp->sectorsize = gsl->sectorsize; in g_slice_config()
424 gsl->provider = pp; in g_slice_config()
425 gsp->nprovider++; in g_slice_config()
434 * it contains meta-data used to configure the slicer.
445 g_slice_conf_hot(struct g_geom *gp, u_int idx, off_t offset, off_t length, int ract, int dact, int … in g_slice_conf_hot() argument
453 gp->name, idx, (intmax_t)offset, (intmax_t)length); in g_slice_conf_hot()
455 gsp = gp->softc; in g_slice_conf_hot()
457 if (gsp->nhotspot == 0) { in g_slice_conf_hot()
458 LIST_FOREACH(pp, &gp->provider, provider) in g_slice_conf_hot()
459 pp->flags &= ~(G_PF_ACCEPT_UNMAPPED | in g_slice_conf_hot()
461 LIST_FOREACH(cp, &gp->consumer, consumer) in g_slice_conf_hot()
462 cp->flags &= ~(G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE); in g_slice_conf_hot()
464 gsl = gsp->hotspot; in g_slice_conf_hot()
465 if(idx >= gsp->nhotspot) { in g_slice_conf_hot()
467 if (gsp->hotspot != NULL) in g_slice_conf_hot()
468 bcopy(gsp->hotspot, gsl2, gsp->nhotspot * sizeof(*gsl2)); in g_slice_conf_hot()
469 gsp->hotspot = gsl2; in g_slice_conf_hot()
470 if (gsp->hotspot != NULL) in g_slice_conf_hot()
473 gsp->nhotspot = idx + 1; in g_slice_conf_hot()
478 || gsp->start != NULL, ("G_SLICE_HOT_START but no slice->start")); in g_slice_conf_hot()
489 struct g_geom *gp; in g_slice_orphan() local
492 gp = cp->geom; in g_slice_orphan()
493 g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, gp->name); in g_slice_orphan()
494 g_wither_geom(gp, ENXIO); in g_slice_orphan()
500 if ((cp->acr + cp->acw + cp->ace) == 0) in g_slice_orphan()
501 g_slice_free(gp); in g_slice_orphan()
508 g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, cp->geom->name); in g_slice_spoiled()
509 cp->flags |= G_CF_ORPHAN; in g_slice_spoiled()
514 g_slice_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp) in g_slice_destroy_geom() argument
517 g_slice_spoiled(LIST_FIRST(&gp->consumer)); in g_slice_destroy_geom()
524 struct g_geom *gp; in g_slice_new() local
532 gp = g_new_geom(mp, pp->name); in g_slice_new()
534 gsp->start = start; in g_slice_new()
535 gp->softc = gsp; in g_slice_new()
536 gp->start = g_slice_start; in g_slice_new()
537 gp->access = g_slice_access; in g_slice_new()
538 gp->orphan = g_slice_orphan; in g_slice_new()
539 gp->spoiled = g_slice_spoiled; in g_slice_new()
540 if (gp->dumpconf == NULL) in g_slice_new()
541 gp->dumpconf = g_slice_dumpconf; in g_slice_new()
542 if (gp->class->destroy_geom == NULL) in g_slice_new()
543 gp->class->destroy_geom = g_slice_destroy_geom; in g_slice_new()
544 cp = g_new_consumer(gp); in g_slice_new()
545 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; in g_slice_new()
550 g_wither_geom(gp, ENXIO); in g_slice_new()
554 *vp = gsp->softc; in g_slice_new()
556 return (gp); in g_slice_new()