diff options
Diffstat (limited to 'sys/geom/bde')
-rw-r--r-- | sys/geom/bde/g_bde.c | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/sys/geom/bde/g_bde.c b/sys/geom/bde/g_bde.c index 850cf1e..4d27d80 100644 --- a/sys/geom/bde/g_bde.c +++ b/sys/geom/bde/g_bde.c @@ -275,161 +275,8 @@ g_bde_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp) return (0); } -static int -g_bde_config(struct g_configargs *ga) -{ - struct g_geom *gp; - struct g_consumer *cp; - struct g_provider *pp; - struct g_bde_key *kp; - int error; - u_int sectorsize; - off_t mediasize; - struct g_bde_softc *sc; - - g_trace(G_T_TOPOLOGY, "g_bde_config(%d)", ga->flag); - g_topology_assert(); - gp = NULL; - if (ga->flag == GCFG_DISMANTLE) { - /* - * Orderly detachment. - */ - if (ga->geom != NULL) { - gp = ga->geom; - } else if (ga->provider != NULL) { - if (ga->provider->geom->class == ga->class) { - gp = ga->provider->geom; - } else { - LIST_FOREACH(cp, &ga->provider->consumers, - consumers) { - if (cp->geom->class == ga->class) { - gp = cp->geom; - break; - } - } - } - if (gp == NULL) - return (EINVAL); - } else { - return (EINVAL); - } - KASSERT(gp != NULL, ("NULL geom")); - pp = LIST_FIRST(&gp->provider); - KASSERT(pp != NULL, ("NULL provider")); - if (pp->acr > 0 || pp->acw > 0 || pp->ace > 0) - return (EBUSY); - g_orphan_provider(pp, ENXIO); - sc = gp->softc; - cp = LIST_FIRST(&gp->consumer); - KASSERT(cp != NULL, ("NULL consumer")); - sc->dead = 1; - wakeup(sc); - error = g_access_rel(cp, -1, -1, -1); - KASSERT(error == 0, ("error on close")); - g_detach(cp); - g_destroy_consumer(cp); - g_topology_unlock(); - while (sc->dead != 2 && !LIST_EMPTY(&pp->consumers)) - tsleep(sc, PRIBIO, "g_bdedie", hz); - g_waitidle(); - g_topology_lock(); - g_destroy_provider(pp); - mtx_destroy(&sc->worklist_mutex); - bzero(&sc->key, sizeof sc->key); - g_free(sc); - g_destroy_geom(gp); - return (0); - } - - if (ga->flag != GCFG_CREATE) - return (EOPNOTSUPP); - - if (ga->provider == NULL) - return (EINVAL); - /* - * Attach - */ - gp = g_new_geomf(ga->class, "%s.bde", ga->provider->name); - gp->start = g_bde_start; - gp->orphan = g_bde_orphan; - gp->access = g_bde_access; - gp->spoiled = g_std_spoiled; - cp = g_new_consumer(gp); - g_attach(cp, ga->provider); - error = g_access_rel(cp, 1, 1, 1); - if (error) { - g_detach(cp); - g_destroy_consumer(cp); - g_destroy_geom(gp); - return (error); - } - g_topology_unlock(); - g_waitidle(); - while (1) { - sectorsize = cp->provider->sectorsize; - mediasize = cp->provider->mediasize; - sc = g_malloc(sizeof(struct g_bde_softc), M_WAITOK | M_ZERO); - gp->softc = sc; - sc->geom = gp; - sc->consumer = cp; - - error = g_bde_decrypt_lock(sc, ga->ptr, - (u_char *)ga->ptr + (sizeof sc->sha2), - mediasize, sectorsize, NULL); - bzero(sc->sha2, sizeof sc->sha2); - if (error) - break; - kp = &sc->key; - - /* Initialize helper-fields */ - kp->keys_per_sector = kp->sectorsize / G_BDE_SKEYLEN; - kp->zone_cont = kp->keys_per_sector * kp->sectorsize; - kp->zone_width = kp->zone_cont + kp->sectorsize; - kp->media_width = kp->sectorN - kp->sector0 - - G_BDE_MAXKEYS * kp->sectorsize; - - /* Our external parameters */ - sc->zone_cont = kp->zone_cont; - sc->mediasize = g_bde_max_sector(kp); - sc->sectorsize = kp->sectorsize; - - TAILQ_INIT(&sc->freelist); - TAILQ_INIT(&sc->worklist); - mtx_init(&sc->worklist_mutex, "g_bde_worklist", NULL, MTX_DEF); - mtx_lock(&Giant); - /* XXX: error check */ - kthread_create(g_bde_worker, gp, &sc->thread, 0, 0, - "g_bde %s", gp->name); - mtx_unlock(&Giant); - g_topology_lock(); - pp = g_new_providerf(gp, gp->name); - pp->flags |= G_PF_CANDELETE; - pp->stripesize = kp->zone_cont; - pp->stripeoffset = 0; - pp->mediasize = sc->mediasize; - pp->sectorsize = sc->sectorsize; - g_error_provider(pp, 0); - g_topology_unlock(); - break; - } - g_topology_lock(); - if (error == 0) { - ga->geom = gp; - return (0); - } else { - g_access_rel(cp, -1, -1, -1); - } - g_detach(cp); - g_destroy_consumer(cp); - if (gp->softc != NULL) - g_free(gp->softc); - g_destroy_geom(gp); - return (error); -} - static struct g_class g_bde_class = { .name = BDE_CLASS_NAME, - .config = g_bde_config, .create_geom = g_bde_create_geom, .destroy_geom = g_bde_destroy_geom, G_CLASS_INITIALIZER |