FreeBSD/sys/geom/sched/g_sched.c
/*
 * Helper function for the children classes, which takes
 * a geom and a bio and returns the private descriptor
 * associated to the request.  This involves fetching
 * the classification field and [al]locating the
 * corresponding entry in the hash table.
 */
Helper function for the children classes, which takes
a geom and a bio and returns the private descriptor
associated to the request.  This involves fetching
the classification field and [al]locating the
corresponding entry in the hash table.
Helper function for the children classes which takes a geom and a bio and returns the private descriptor associated to the request . This involves fetching the classification field and [ al ] locating the corresponding entry in the hash table .
void *
g_sched_get_class(struct g_geom *gp, struct bio *bp)
{
	struct g_sched_softc *sc;
	struct g_sched_class *gsc;
	struct g_gsched *gsp;
	struct g_hash *bucket;
	u_long key;
	sc = gp->softc;
	key = g_sched_classify(bp);
	bucket = g_sched_hash(sc, key);
	LIST_FOREACH(gsc, bucket, gsc_clist) {
		if (key == gsc->gsc_key) {
			gsc->gsc_refs++;
			return (gsc->gsc_priv);
		}
	}
	gsp = sc->sc_gsched;
	gsc = malloc(sizeof(*gsc) + gsp->gs_priv_size,
	    M_GEOM_SCHED, M_NOWAIT | M_ZERO);
	if (!gsc)
		return (NULL);
	if (gsp->gs_init_class(sc->sc_data, gsc->gsc_priv)) {
		free(gsc, M_GEOM_SCHED);
		return (NULL);
	}
	gsc->gsc_refs = 2;	
	gsc->gsc_key = key;
	LIST_INSERT_HEAD(bucket, gsc, gsc_clist);
	gsc->gsc_expire = ticks + me.gs_expire_secs * hz;
	return (gsc->gsc_priv);
}
void * g_sched_get_class ( struct g_geom * gp , struct bio * bp ) { struct g_sched_softc * sc ; struct g_sched_class * gsc ; struct g_gsched * gsp ; struct g_hash * bucket ; u_long key ; sc = gp -> softc ; key = g_sched_classify ( bp ) ; bucket = g_sched_hash ( sc , key ) ; LIST_FOREACH ( gsc , bucket , gsc_clist ) { if ( key == gsc -> gsc_key ) { gsc -> gsc_refs ++ ; return ( gsc -> gsc_priv ) ; } } gsp = sc -> sc_gsched ; gsc = malloc ( sizeof ( * gsc ) + gsp -> gs_priv_size , M_GEOM_SCHED , M_NOWAIT | M_ZERO ) ; if ( ! gsc ) return ( NULL ) ; if ( gsp -> gs_init_class ( sc -> sc_data , gsc -> gsc_priv ) ) { free ( gsc , M_GEOM_SCHED ) ; return ( NULL ) ; } gsc -> gsc_refs = 2 ; gsc -> gsc_key = key ; LIST_INSERT_HEAD ( bucket , gsc , gsc_clist ) ; gsc -> gsc_expire = ticks + me . gs_expire_secs * hz ; return ( gsc -> gsc_priv ) ; }
Helper function for the children classes, which takes
 a geom and a bio and returns the private descriptor
 associated to the request.
Helper function for the children classes which takes a geom and a bio and returns the private descriptor associated to the request .
/* 1 for the hash table, 1 for the caller. */