FreeBSD/sys/geom/virstor/g_virstor.c
/*
 * Add provider to a GEOM class instance
 */
Add provider to a GEOM class instance
Add provider to a GEOM class instance
static int
add_provider_to_geom(struct g_virstor_softc *sc, struct g_provider *pp,
    struct g_virstor_metadata *md)
{
	struct g_virstor_component *component;
	struct g_consumer *cp, *fcp;
	struct g_geom *gp;
	int error;
	if (md->no >= sc->n_components)
		return (EINVAL);
	component = &(sc->components[md->no]);
	if (component->gcons != NULL)
		return (EEXIST);
	gp = sc->geom;
	fcp = LIST_FIRST(&gp->consumer);
	cp = g_new_consumer(gp);
	error = g_attach(cp, pp);
	if (error != 0) {
		g_destroy_consumer(cp);
		return (error);
	}
	if (fcp != NULL) {
		if (fcp->provider->sectorsize != pp->sectorsize) {
			LOG_MSG(LVL_ERROR, "Provider %s of %s has invalid "
			    "sector size (%d)", pp->name, sc->geom->name,
			    pp->sectorsize);
			return (EINVAL);
		}
		if (fcp->acr > 0 || fcp->acw || fcp->ace > 0) {
			error = g_access(cp, fcp->acr, fcp->acw, fcp->ace);
			if (error != 0) {
				g_detach(cp);
				g_destroy_consumer(cp);
				return (error);
			}
		}
	}
	cp->private = component;
	component->gcons = cp;
	component->sc = sc;
	component->index = md->no;
	component->chunk_count = md->chunk_count;
	component->chunk_next = md->chunk_next;
	component->chunk_reserved = md->chunk_reserved;
	component->flags = md->flags;
	LOG_MSG(LVL_DEBUG, "%s attached to %s", pp->name, sc->geom->name);
	virstor_check_and_run(sc);
	return (0);
}
static int add_provider_to_geom ( struct g_virstor_softc * sc , struct g_provider * pp , struct g_virstor_metadata * md ) { struct g_virstor_component * component ; struct g_consumer * cp , * fcp ; struct g_geom * gp ; int error ; if ( md -> no >= sc -> n_components ) return ( EINVAL ) ; component = & ( sc -> components [ md -> no ] ) ; if ( component -> gcons != NULL ) return ( EEXIST ) ; gp = sc -> geom ; fcp = LIST_FIRST ( & gp -> consumer ) ; cp = g_new_consumer ( gp ) ; error = g_attach ( cp , pp ) ; if ( error != 0 ) { g_destroy_consumer ( cp ) ; return ( error ) ; } if ( fcp != NULL ) { if ( fcp -> provider -> sectorsize != pp -> sectorsize ) { LOG_MSG ( LVL_ERROR , " " " " , pp -> name , sc -> geom -> name , pp -> sectorsize ) ; return ( EINVAL ) ; } if ( fcp -> acr > 0 || fcp -> acw || fcp -> ace > 0 ) { error = g_access ( cp , fcp -> acr , fcp -> acw , fcp -> ace ) ; if ( error != 0 ) { g_detach ( cp ) ; g_destroy_consumer ( cp ) ; return ( error ) ; } } } cp -> private = component ; component -> gcons = cp ; component -> sc = sc ; component -> index = md -> no ; component -> chunk_count = md -> chunk_count ; component -> chunk_next = md -> chunk_next ; component -> chunk_reserved = md -> chunk_reserved ; component -> flags = md -> flags ; LOG_MSG ( LVL_DEBUG , " " , pp -> name , sc -> geom -> name ) ; virstor_check_and_run ( sc ) ; return ( 0 ) ; }
Add provider to a GEOM class instance
Add provider to a GEOM class instance
/* "Current" compontent */ /* TODO: this can be made to work */ /* Replicate access permissions from first "live" consumer
			 * to the new one */ /* Bring up a new component */