FreeBSD/sys/geom/virstor/g_virstor.c
/*
 * Creates a new instance of this GEOM class, initialise softc
 */
Creates a new instance of this GEOM class, initialise softc
Creates a new instance of this GEOM class initialise softc
static struct g_geom *
create_virstor_geom(struct g_class *mp, struct g_virstor_metadata *md)
{
	struct g_geom *gp;
	struct g_virstor_softc *sc;
	LOG_MSG(LVL_DEBUG, "Creating geom instance for %s (id=%u)",
	    md->md_name, md->md_id);
	if (md->md_count < 1 || md->md_chunk_size < 1 ||
	    md->md_virsize < md->md_chunk_size) {
		LOG_MSG(LVL_ERROR, "Nonsensical metadata information for %s",
		    md->md_name);
		return (NULL);
	}
	LIST_FOREACH(gp, &mp->geom, geom) {
		sc = gp->softc;
		if (sc != NULL && strcmp(sc->geom->name, md->md_name) == 0) {
			LOG_MSG(LVL_WARNING, "Geom %s already exists",
			    md->md_name);
			if (sc->id != md->md_id) {
				LOG_MSG(LVL_ERROR,
				    "Some stale or invalid components "
				    "exist for virstor device named %s. "
				    "You will need to <CLEAR> all stale "
				    "components and maybe reconfigure "
				    "the virstor device. Tune "
				    "kern.geom.virstor.debug sysctl up "
				    "for more information.",
				    sc->geom->name);
			}
			return (NULL);
		}
	}
	gp = g_new_geomf(mp, "%s", md->md_name);
	gp->softc = NULL; 
	gp->start = g_virstor_start;
	gp->spoiled = g_virstor_orphan;
	gp->orphan = g_virstor_orphan;
	gp->access = g_virstor_access;
	gp->dumpconf = g_virstor_dumpconf;
	sc = malloc(sizeof(*sc), M_GVIRSTOR, M_WAITOK | M_ZERO);
	sc->id = md->md_id;
	sc->n_components = md->md_count;
	sc->components = malloc(sizeof(struct g_virstor_component) * md->md_count,
	    M_GVIRSTOR, M_WAITOK | M_ZERO);
	sc->chunk_size = md->md_chunk_size;
	sc->virsize = md->md_virsize;
	STAILQ_INIT(&sc->delayed_bio_q);
	mtx_init(&sc->delayed_bio_q_mtx, "gvirstor_delayed_bio_q_mtx",
	    "gvirstor", MTX_DEF | MTX_RECURSE);
	sc->geom = gp;
	sc->provider = NULL; 
	gp->softc = sc;
	LOG_MSG(LVL_ANNOUNCE, "Device %s created", sc->geom->name);
	return (gp);
}
static struct g_geom * create_virstor_geom ( struct g_class * mp , struct g_virstor_metadata * md ) { struct g_geom * gp ; struct g_virstor_softc * sc ; LOG_MSG ( LVL_DEBUG , " " , md -> md_name , md -> md_id ) ; if ( md -> md_count < 1 || md -> md_chunk_size < 1 || md -> md_virsize < md -> md_chunk_size ) { LOG_MSG ( LVL_ERROR , " " , md -> md_name ) ; return ( NULL ) ; } LIST_FOREACH ( gp , & mp -> geom , geom ) { sc = gp -> softc ; if ( sc != NULL && strcmp ( sc -> geom -> name , md -> md_name ) == 0 ) { LOG_MSG ( LVL_WARNING , " " , md -> md_name ) ; if ( sc -> id != md -> md_id ) { LOG_MSG ( LVL_ERROR , " " " " " " " " " " " " " " , sc -> geom -> name ) ; } return ( NULL ) ; } } gp = g_new_geomf ( mp , " " , md -> md_name ) ; gp -> softc = NULL ; gp -> start = g_virstor_start ; gp -> spoiled = g_virstor_orphan ; gp -> orphan = g_virstor_orphan ; gp -> access = g_virstor_access ; gp -> dumpconf = g_virstor_dumpconf ; sc = malloc ( sizeof ( * sc ) , M_GVIRSTOR , M_WAITOK | M_ZERO ) ; sc -> id = md -> md_id ; sc -> n_components = md -> md_count ; sc -> components = malloc ( sizeof ( struct g_virstor_component ) * md -> md_count , M_GVIRSTOR , M_WAITOK | M_ZERO ) ; sc -> chunk_size = md -> md_chunk_size ; sc -> virsize = md -> md_virsize ; STAILQ_INIT ( & sc -> delayed_bio_q ) ; mtx_init ( & sc -> delayed_bio_q_mtx , " " , " " , MTX_DEF | MTX_RECURSE ) ; sc -> geom = gp ; sc -> provider = NULL ; gp -> softc = sc ; LOG_MSG ( LVL_ANNOUNCE , " " , sc -> geom -> name ) ; return ( gp ) ; }
Creates a new instance of this GEOM class, initialise softc
Creates a new instance of this GEOM class initialise softc
/* This is bogus configuration, and probably means data is
		 * somehow corrupted. Panic, maybe? */ /* Check if it's already created */ /* to circumevent races that test softc */ /* virstor_check_and_run will create it */