FreeBSD/sys/geom/virstor/g_virstor.c
/*
 * Allocate a chunk from a physical provider. Returns physical component,
 * chunk index relative to the component and the component's index.
 */
Allocate a chunk from a physical provider. Returns physical component,
chunk index relative to the component and the component's index.
Allocate a chunk from a physical provider . Returns physical component chunk index relative to the component and the component ' s index .
static int
allocate_chunk(struct g_virstor_softc *sc, struct g_virstor_component **comp,
    u_int *comp_no_p, u_int *chunk)
{
	u_int comp_no;
	KASSERT(sc->curr_component < sc->n_components,
	    ("%s: Invalid curr_component: %u",  __func__, sc->curr_component));
	comp_no = sc->curr_component;
	*comp = &sc->components[comp_no];
	dump_component(*comp);
	if ((*comp)->chunk_next >= (*comp)->chunk_count) {
		if (comp_no >= sc->n_components-1) {
			LOG_MSG(LVL_ERROR, "All physical space allocated for %s",
			    sc->geom->name);
			return (-1);
		}
		(*comp)->flags &= ~VIRSTOR_PROVIDER_CURRENT;
		sc->curr_component = ++comp_no;
		*comp = &sc->components[comp_no];
		if (comp_no >= sc->n_components - g_virstor_component_watermark-1)
			LOG_MSG(LVL_WARNING, "Device %s running out of components "
			    "(switching to %u/%u: %s)", sc->geom->name,
			    comp_no+1, sc->n_components,
			    (*comp)->gcons->provider->name);
		if ( (*comp)->chunk_reserved > 0 &&
		    (*comp)->chunk_next < (*comp)->chunk_reserved)
			(*comp)->chunk_next = (*comp)->chunk_reserved;
		(*comp)->flags |=
		    VIRSTOR_PROVIDER_ALLOCATED | VIRSTOR_PROVIDER_CURRENT;
		dump_component(*comp);
		*comp_no_p = comp_no;
		*chunk = (*comp)->chunk_next++;
	} else {
		*comp_no_p = comp_no;
		*chunk = (*comp)->chunk_next++;
	}
	return (0);
}
static int allocate_chunk ( struct g_virstor_softc * sc , struct g_virstor_component * * comp , u_int * comp_no_p , u_int * chunk ) { u_int comp_no ; KASSERT ( sc -> curr_component < sc -> n_components , ( " " , __func__ , sc -> curr_component ) ) ; comp_no = sc -> curr_component ; * comp = & sc -> components [ comp_no ] ; dump_component ( * comp ) ; if ( ( * comp ) -> chunk_next >= ( * comp ) -> chunk_count ) { if ( comp_no >= sc -> n_components - 1 ) { LOG_MSG ( LVL_ERROR , " " , sc -> geom -> name ) ; return ( -1 ) ; } ( * comp ) -> flags &= ~ VIRSTOR_PROVIDER_CURRENT ; sc -> curr_component = ++ comp_no ; * comp = & sc -> components [ comp_no ] ; if ( comp_no >= sc -> n_components - g_virstor_component_watermark - 1 ) LOG_MSG ( LVL_WARNING , " " " " , sc -> geom -> name , comp_no + 1 , sc -> n_components , ( * comp ) -> gcons -> provider -> name ) ; if ( ( * comp ) -> chunk_reserved > 0 && ( * comp ) -> chunk_next < ( * comp ) -> chunk_reserved ) ( * comp ) -> chunk_next = ( * comp ) -> chunk_reserved ; ( * comp ) -> flags |= VIRSTOR_PROVIDER_ALLOCATED | VIRSTOR_PROVIDER_CURRENT ; dump_component ( * comp ) ; * comp_no_p = comp_no ; * chunk = ( * comp ) -> chunk_next ++ ; } else { * comp_no_p = comp_no ; * chunk = ( * comp ) -> chunk_next ++ ; } return ( 0 ) ; }
Allocate a chunk from a physical provider.
Allocate a chunk from a physical provider .
/* This component is full. Allocate next component */ /* Take care not to overwrite reserved chunks */