Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/eli/g_eli_key_cache.c
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | g_eli_key_allocate(struct g_eli_softc *sc, uint64_t keyno) | ||||
mtx_lock(&sc->sc_ekeys_lock); | mtx_lock(&sc->sc_ekeys_lock); | ||||
/* | /* | ||||
* Recheck if the key wasn't added while we weren't holding the lock. | * Recheck if the key wasn't added while we weren't holding the lock. | ||||
*/ | */ | ||||
keysearch.gek_keyno = keyno; | keysearch.gek_keyno = keyno; | ||||
ekey = RB_FIND(g_eli_key_tree, &sc->sc_ekeys_tree, &keysearch); | ekey = RB_FIND(g_eli_key_tree, &sc->sc_ekeys_tree, &keysearch); | ||||
if (ekey != NULL) { | if (ekey != NULL) { | ||||
explicit_bzero(key, sizeof(*key)); | zfree(key, M_ELI); | ||||
free(key, M_ELI); | |||||
key = ekey; | key = ekey; | ||||
TAILQ_REMOVE(&sc->sc_ekeys_queue, key, gek_next); | TAILQ_REMOVE(&sc->sc_ekeys_queue, key, gek_next); | ||||
} else { | } else { | ||||
RB_INSERT(g_eli_key_tree, &sc->sc_ekeys_tree, key); | RB_INSERT(g_eli_key_tree, &sc->sc_ekeys_tree, key); | ||||
sc->sc_ekeys_allocated++; | sc->sc_ekeys_allocated++; | ||||
} | } | ||||
TAILQ_INSERT_TAIL(&sc->sc_ekeys_queue, key, gek_next); | TAILQ_INSERT_TAIL(&sc->sc_ekeys_queue, key, gek_next); | ||||
Show All 39 Lines | g_eli_key_remove(struct g_eli_softc *sc, struct g_eli_key *key) | ||||
mtx_assert(&sc->sc_ekeys_lock, MA_OWNED); | mtx_assert(&sc->sc_ekeys_lock, MA_OWNED); | ||||
KASSERT(key->gek_magic == G_ELI_KEY_MAGIC, ("Invalid magic.")); | KASSERT(key->gek_magic == G_ELI_KEY_MAGIC, ("Invalid magic.")); | ||||
KASSERT(key->gek_count == 0, ("gek_count=%d", key->gek_count)); | KASSERT(key->gek_count == 0, ("gek_count=%d", key->gek_count)); | ||||
RB_REMOVE(g_eli_key_tree, &sc->sc_ekeys_tree, key); | RB_REMOVE(g_eli_key_tree, &sc->sc_ekeys_tree, key); | ||||
TAILQ_REMOVE(&sc->sc_ekeys_queue, key, gek_next); | TAILQ_REMOVE(&sc->sc_ekeys_queue, key, gek_next); | ||||
sc->sc_ekeys_allocated--; | sc->sc_ekeys_allocated--; | ||||
explicit_bzero(key, sizeof(*key)); | zfree(key, M_ELI); | ||||
free(key, M_ELI); | |||||
} | } | ||||
void | void | ||||
g_eli_key_init(struct g_eli_softc *sc) | g_eli_key_init(struct g_eli_softc *sc) | ||||
{ | { | ||||
uint8_t *mkey; | uint8_t *mkey; | ||||
mtx_lock(&sc->sc_ekeys_lock); | mtx_lock(&sc->sc_ekeys_lock); | ||||
▲ Show 20 Lines • Show All 202 Lines • Show Last 20 Lines |