Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/mirror/g_mirror_ctl.c
Show First 20 Lines • Show All 435 Lines • ▼ Show 20 Lines | g_mirror_ctl_create(struct gctl_req *req, struct g_class *mp) | ||||
g_topology_lock(); | g_topology_lock(); | ||||
mediasize = OFF_MAX; | mediasize = OFF_MAX; | ||||
sectorsize = 0; | sectorsize = 0; | ||||
gp = g_new_geomf(mp, "%s", md.md_name); | gp = g_new_geomf(mp, "%s", md.md_name); | ||||
gp->orphan = g_mirror_create_orphan; | gp->orphan = g_mirror_create_orphan; | ||||
cp = g_new_consumer(gp); | cp = g_new_consumer(gp); | ||||
for (no = 1; no < *nargs; no++) { | for (no = 1; no < *nargs; no++) { | ||||
snprintf(param, sizeof(param), "arg%u", no); | snprintf(param, sizeof(param), "arg%u", no); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (name == NULL) { | if (pp == NULL) { | ||||
gctl_error(req, "No 'arg%u' argument.", no); | |||||
err: | err: | ||||
g_destroy_consumer(cp); | g_destroy_consumer(cp); | ||||
g_destroy_geom(gp); | g_destroy_geom(gp); | ||||
g_topology_unlock(); | g_topology_unlock(); | ||||
return; | return; | ||||
} | } | ||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | |||||
name += strlen(_PATH_DEV); | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | |||||
G_MIRROR_DEBUG(1, "Disk %s is invalid.", name); | |||||
gctl_error(req, "Disk %s is invalid.", name); | |||||
goto err; | |||||
} | |||||
g_attach(cp, pp); | g_attach(cp, pp); | ||||
if (g_access(cp, 1, 0, 0) != 0) { | if (g_access(cp, 1, 0, 0) != 0) { | ||||
G_MIRROR_DEBUG(1, "Can't open disk %s.", name); | G_MIRROR_DEBUG(1, "Can't open disk %s.", pp->name); | ||||
gctl_error(req, "Can't open disk %s.", name); | gctl_error(req, "Can't open disk %s.", pp->name); | ||||
err2: | err2: | ||||
g_detach(cp); | g_detach(cp); | ||||
goto err; | goto err; | ||||
} | } | ||||
if (pp->mediasize == 0 || pp->sectorsize == 0) { | if (pp->mediasize == 0 || pp->sectorsize == 0) { | ||||
G_MIRROR_DEBUG(1, "Disk %s has no media.", name); | G_MIRROR_DEBUG(1, "Disk %s has no media.", pp->name); | ||||
gctl_error(req, "Disk %s has no media.", name); | gctl_error(req, "Disk %s has no media.", pp->name); | ||||
g_access(cp, -1, 0, 0); | g_access(cp, -1, 0, 0); | ||||
goto err2; | goto err2; | ||||
} | } | ||||
if (pp->mediasize < mediasize) | if (pp->mediasize < mediasize) | ||||
mediasize = pp->mediasize; | mediasize = pp->mediasize; | ||||
if (pp->sectorsize > sectorsize) | if (pp->sectorsize > sectorsize) | ||||
sectorsize = pp->sectorsize; | sectorsize = pp->sectorsize; | ||||
g_access(cp, -1, 0, 0); | g_access(cp, -1, 0, 0); | ||||
Show All 15 Lines | err2: | ||||
sc = gp->softc; | sc = gp->softc; | ||||
g_topology_unlock(); | g_topology_unlock(); | ||||
sx_xlock(&sc->sc_lock); | sx_xlock(&sc->sc_lock); | ||||
sc->sc_flags |= G_MIRROR_DEVICE_FLAG_TASTING; | sc->sc_flags |= G_MIRROR_DEVICE_FLAG_TASTING; | ||||
sb = sbuf_new_auto(); | sb = sbuf_new_auto(); | ||||
sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name); | sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name); | ||||
for (attached = 0, no = 1; no < *nargs; no++) { | for (attached = 0, no = 1; no < *nargs; no++) { | ||||
snprintf(param, sizeof(param), "arg%u", no); | snprintf(param, sizeof(param), "arg%u", no); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | |||||
name += strlen(_PATH_DEV); | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | if (pp == NULL) { | ||||
G_MIRROR_DEBUG(1, "Provider %s disappear?!", name); | name = gctl_get_asciiparam(req, param); | ||||
MPASS(name != NULL); | |||||
sbuf_printf(sb, " %s", name); | sbuf_printf(sb, " %s", name); | ||||
continue; | continue; | ||||
} | } | ||||
md.md_did = arc4random(); | md.md_did = arc4random(); | ||||
md.md_priority = no - 1; | md.md_priority = no - 1; | ||||
if (g_mirror_add_disk(sc, pp, &md) != 0) { | if (g_mirror_add_disk(sc, pp, &md) != 0) { | ||||
G_MIRROR_DEBUG(1, "Disk %u (%s) not attached to %s.", | G_MIRROR_DEBUG(1, "Disk %u (%s) not attached to %s.", | ||||
no, pp->name, gp->name); | no, pp->name, gp->name); | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | if (g_mirror_ndisks(sc, -1) < sc->sc_ndisks) { | ||||
sx_xunlock(&sc->sc_lock); | sx_xunlock(&sc->sc_lock); | ||||
return; | return; | ||||
} | } | ||||
disks = g_malloc(sizeof(*disks) * (*nargs), M_WAITOK | M_ZERO); | disks = g_malloc(sizeof(*disks) * (*nargs), M_WAITOK | M_ZERO); | ||||
g_topology_lock(); | g_topology_lock(); | ||||
for (i = 1, n = 0; i < (u_int)*nargs; i++) { | for (i = 1, n = 0; i < (u_int)*nargs; i++) { | ||||
snprintf(param, sizeof(param), "arg%u", i); | snprintf(param, sizeof(param), "arg%u", i); | ||||
name = gctl_get_asciiparam(req, param); | pp = gctl_get_provider(req, param); | ||||
if (name == NULL) { | if (pp == NULL) | ||||
gctl_error(req, "No 'arg%u' argument.", i); | |||||
continue; | continue; | ||||
} | if (g_mirror_find_disk(sc, pp->name) != NULL) { | ||||
if (g_mirror_find_disk(sc, name) != NULL) { | gctl_error(req, "Provider %s already inserted.", pp->name); | ||||
gctl_error(req, "Provider %s already inserted.", name); | |||||
continue; | continue; | ||||
} | } | ||||
if (strncmp(name, _PATH_DEV, 5) == 0) | |||||
name += 5; | |||||
pp = g_provider_by_name(name); | |||||
if (pp == NULL) { | |||||
gctl_error(req, "Unknown provider %s.", name); | |||||
continue; | |||||
} | |||||
cp = g_new_consumer(sc->sc_geom); | cp = g_new_consumer(sc->sc_geom); | ||||
if (g_attach(cp, pp) != 0) { | if (g_attach(cp, pp) != 0) { | ||||
g_destroy_consumer(cp); | g_destroy_consumer(cp); | ||||
gctl_error(req, "Cannot attach to provider %s.", name); | gctl_error(req, "Cannot attach to provider %s.", pp->name); | ||||
continue; | continue; | ||||
} | } | ||||
if (g_access(cp, 0, 1, 1) != 0) { | if (g_access(cp, 0, 1, 1) != 0) { | ||||
gctl_error(req, "Cannot access provider %s.", name); | gctl_error(req, "Cannot access provider %s.", pp->name); | ||||
err: | err: | ||||
g_detach(cp); | g_detach(cp); | ||||
g_destroy_consumer(cp); | g_destroy_consumer(cp); | ||||
continue; | continue; | ||||
} | } | ||||
mdsize = (sc->sc_type == G_MIRROR_TYPE_AUTOMATIC) ? | mdsize = (sc->sc_type == G_MIRROR_TYPE_AUTOMATIC) ? | ||||
pp->sectorsize : 0; | pp->sectorsize : 0; | ||||
if (sc->sc_provider->mediasize > pp->mediasize - mdsize) { | if (sc->sc_provider->mediasize > pp->mediasize - mdsize) { | ||||
gctl_error(req, "Provider %s too small.", name); | gctl_error(req, "Provider %s too small.", pp->name); | ||||
err2: | err2: | ||||
g_access(cp, 0, -1, -1); | g_access(cp, 0, -1, -1); | ||||
goto err; | goto err; | ||||
} | } | ||||
if ((sc->sc_provider->sectorsize % pp->sectorsize) != 0) { | if ((sc->sc_provider->sectorsize % pp->sectorsize) != 0) { | ||||
gctl_error(req, "Invalid sectorsize of provider %s.", | gctl_error(req, "Invalid sectorsize of provider %s.", | ||||
name); | pp->name); | ||||
goto err2; | goto err2; | ||||
} | } | ||||
if (sc->sc_type != G_MIRROR_TYPE_AUTOMATIC) { | if (sc->sc_type != G_MIRROR_TYPE_AUTOMATIC) { | ||||
g_access(cp, 0, -1, -1); | g_access(cp, 0, -1, -1); | ||||
g_detach(cp); | g_detach(cp); | ||||
g_destroy_consumer(cp); | g_destroy_consumer(cp); | ||||
g_topology_unlock(); | g_topology_unlock(); | ||||
sc->sc_ndisks++; | sc->sc_ndisks++; | ||||
g_mirror_fill_metadata(sc, NULL, &md); | g_mirror_fill_metadata(sc, NULL, &md); | ||||
md.md_priority = *priority; | md.md_priority = *priority; | ||||
if (*inactive) | if (*inactive) | ||||
md.md_dflags |= G_MIRROR_DISK_FLAG_INACTIVE; | md.md_dflags |= G_MIRROR_DISK_FLAG_INACTIVE; | ||||
if (g_mirror_add_disk(sc, pp, &md) != 0) { | if (g_mirror_add_disk(sc, pp, &md) != 0) { | ||||
sc->sc_ndisks--; | sc->sc_ndisks--; | ||||
gctl_error(req, "Disk %s not inserted.", name); | gctl_error(req, "Disk %s not inserted.", pp->name); | ||||
} | } | ||||
g_topology_lock(); | g_topology_lock(); | ||||
continue; | continue; | ||||
} | } | ||||
disks[n].provider = pp; | disks[n].provider = pp; | ||||
disks[n].consumer = cp; | disks[n].consumer = cp; | ||||
n++; | n++; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 406 Lines • Show Last 20 Lines |