Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/mirror/g_mirror_ctl.c
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static struct g_mirror_disk * | static struct g_mirror_disk * | ||||
g_mirror_find_disk(struct g_mirror_softc *sc, const char *name) | g_mirror_find_disk(struct g_mirror_softc *sc, const char *name) | ||||
{ | { | ||||
struct g_mirror_disk *disk; | struct g_mirror_disk *disk; | ||||
sx_assert(&sc->sc_lock, SX_XLOCKED); | sx_assert(&sc->sc_lock, SX_XLOCKED); | ||||
if (strncmp(name, "/dev/", 5) == 0) | if (strncmp(name, _PATH_DEV, 5) == 0) | ||||
name += 5; | name += 5; | ||||
LIST_FOREACH(disk, &sc->sc_disks, d_next) { | LIST_FOREACH(disk, &sc->sc_disks, d_next) { | ||||
if (disk->d_consumer == NULL) | if (disk->d_consumer == NULL) | ||||
continue; | continue; | ||||
if (disk->d_consumer->provider == NULL) | if (disk->d_consumer->provider == NULL) | ||||
continue; | continue; | ||||
if (strcmp(disk->d_consumer->provider->name, name) == 0) | if (strcmp(disk->d_consumer->provider->name, name) == 0) | ||||
return (disk); | return (disk); | ||||
▲ Show 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | for (no = 1; no < *nargs; no++) { | ||||
if (name == NULL) { | if (name == NULL) { | ||||
gctl_error(req, "No 'arg%u' argument.", no); | 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, "/dev/", strlen("/dev/")) == 0) | if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | ||||
name += strlen("/dev/"); | name += strlen(_PATH_DEV); | ||||
pp = g_provider_by_name(name); | pp = g_provider_by_name(name); | ||||
if (pp == NULL) { | if (pp == NULL) { | ||||
G_MIRROR_DEBUG(1, "Disk %s is invalid.", name); | G_MIRROR_DEBUG(1, "Disk %s is invalid.", name); | ||||
gctl_error(req, "Disk %s is invalid.", name); | gctl_error(req, "Disk %s is invalid.", name); | ||||
goto err; | 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) { | ||||
Show All 33 Lines | err2: | ||||
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); | name = gctl_get_asciiparam(req, param); | ||||
if (strncmp(name, "/dev/", strlen("/dev/")) == 0) | if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | ||||
name += strlen("/dev/"); | name += strlen(_PATH_DEV); | ||||
pp = g_provider_by_name(name); | pp = g_provider_by_name(name); | ||||
if (pp == NULL) { | if (pp == NULL) { | ||||
G_MIRROR_DEBUG(1, "Provider %s disappear?!", name); | G_MIRROR_DEBUG(1, "Provider %s disappear?!", name); | ||||
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; | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | for (i = 1, n = 0; i < (u_int)*nargs; i++) { | ||||
if (name == NULL) { | if (name == NULL) { | ||||
gctl_error(req, "No 'arg%u' argument.", i); | gctl_error(req, "No 'arg%u' argument.", i); | ||||
continue; | continue; | ||||
} | } | ||||
if (g_mirror_find_disk(sc, name) != NULL) { | if (g_mirror_find_disk(sc, name) != NULL) { | ||||
gctl_error(req, "Provider %s already inserted.", name); | gctl_error(req, "Provider %s already inserted.", name); | ||||
continue; | continue; | ||||
} | } | ||||
if (strncmp(name, "/dev/", 5) == 0) | if (strncmp(name, _PATH_DEV, 5) == 0) | ||||
name += 5; | name += 5; | ||||
pp = g_provider_by_name(name); | pp = g_provider_by_name(name); | ||||
if (pp == NULL) { | if (pp == NULL) { | ||||
gctl_error(req, "Unknown provider %s.", name); | gctl_error(req, "Unknown provider %s.", name); | ||||
continue; | 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) { | ||||
▲ Show 20 Lines • Show All 451 Lines • Show Last 20 Lines |