Make graid command line a bit more friendly by allowing volume name or

provider name to be specified instead of geom name (first argument in all
subcommands except label).  In most cases there is only one array used
any way, so it is not really useful to make user type ugly geom names like
Intel-f0bdf223 or SiI-732c2b9448cf.  Though they can be used in some cases.

Sponsored by:	iXsystems, Inc.
MFC after:	1 month
This commit is contained in:
Alexander Motin 2012-10-07 19:30:16 +00:00
parent 312188ac4a
commit 6871a543f9
4 changed files with 83 additions and 12 deletions

View File

@ -51,7 +51,10 @@ g_raid_find_node(struct g_class *mp, const char *name)
{
struct g_raid_softc *sc;
struct g_geom *gp;
struct g_provider *pp;
struct g_raid_volume *vol;
/* Look for geom with specified name. */
LIST_FOREACH(gp, &mp->geom, geom) {
sc = gp->softc;
if (sc == NULL)
@ -61,6 +64,35 @@ g_raid_find_node(struct g_class *mp, const char *name)
if (strcasecmp(sc->sc_name, name) == 0)
return (sc);
}
/* Look for provider with specified name. */
LIST_FOREACH(gp, &mp->geom, geom) {
sc = gp->softc;
if (sc == NULL)
continue;
if (sc->sc_stopping != 0)
continue;
LIST_FOREACH(pp, &gp->provider, provider) {
if (strcmp(pp->name, name) == 0)
return (sc);
if (strncmp(pp->name, "raid/", 5) == 0 &&
strcmp(pp->name + 5, name) == 0)
return (sc);
}
}
/* Look for volume with specified name. */
LIST_FOREACH(gp, &mp->geom, geom) {
sc = gp->softc;
if (sc == NULL)
continue;
if (sc->sc_stopping != 0)
continue;
TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
if (strcmp(vol->v_name, name) == 0)
return (sc);
}
}
return (NULL);
}

View File

@ -2231,7 +2231,7 @@ g_raid_md_ctl_ddf(struct g_raid_md_object *md,
struct g_consumer *cp;
struct g_provider *pp;
char arg[16];
const char *verb, *volname, *levelname, *diskname;
const char *nodename, *verb, *volname, *levelname, *diskname;
char *tmp;
int *nargs, *force;
off_t size, sectorsize, strip, offs[DDF_MAX_DISKS_HARD], esize;
@ -2502,8 +2502,12 @@ g_raid_md_ctl_ddf(struct g_raid_md_object *md,
}
if (strcmp(verb, "delete") == 0) {
nodename = gctl_get_asciiparam(req, "arg0");
if (nodename != NULL && strcasecmp(sc->sc_name, nodename) != 0)
nodename = NULL;
/* Full node destruction. */
if (*nargs == 1) {
if (*nargs == 1 && nodename != NULL) {
/* Check if some volume is still open. */
force = gctl_get_paraml(req, "force", sizeof(*force));
if (force != NULL && *force == 0 &&
@ -2521,11 +2525,12 @@ g_raid_md_ctl_ddf(struct g_raid_md_object *md,
}
/* Destroy specified volume. If it was last - all node. */
if (*nargs != 2) {
if (*nargs > 2) {
gctl_error(req, "Invalid number of arguments.");
return (-1);
}
volname = gctl_get_asciiparam(req, "arg1");
volname = gctl_get_asciiparam(req,
nodename != NULL ? "arg1" : "arg0");
if (volname == NULL) {
gctl_error(req, "No volume name.");
return (-2);
@ -2535,6 +2540,14 @@ g_raid_md_ctl_ddf(struct g_raid_md_object *md,
TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
if (strcmp(vol->v_name, volname) == 0)
break;
pp = vol->v_provider;
if (pp == NULL)
continue;
if (strcmp(pp->name, volname) == 0)
break;
if (strncmp(pp->name, "raid/", 5) == 0 &&
strcmp(pp->name + 5, volname) == 0)
break;
}
if (vol == NULL) {
i = strtol(volname, &tmp, 10);

View File

@ -1461,7 +1461,7 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
struct g_consumer *cp;
struct g_provider *pp;
char arg[16], serial[INTEL_SERIAL_LEN];
const char *verb, *volname, *levelname, *diskname;
const char *nodename, *verb, *volname, *levelname, *diskname;
char *tmp;
int *nargs, *force;
off_t off, size, sectorsize, strip, disk_sectors;
@ -1876,8 +1876,12 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
}
if (strcmp(verb, "delete") == 0) {
nodename = gctl_get_asciiparam(req, "arg0");
if (nodename != NULL && strcasecmp(sc->sc_name, nodename) != 0)
nodename = NULL;
/* Full node destruction. */
if (*nargs == 1) {
if (*nargs == 1 && nodename != NULL) {
/* Check if some volume is still open. */
force = gctl_get_paraml(req, "force", sizeof(*force));
if (force != NULL && *force == 0 &&
@ -1895,11 +1899,12 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
}
/* Destroy specified volume. If it was last - all node. */
if (*nargs != 2) {
if (*nargs > 2) {
gctl_error(req, "Invalid number of arguments.");
return (-1);
}
volname = gctl_get_asciiparam(req, "arg1");
volname = gctl_get_asciiparam(req,
nodename != NULL ? "arg1" : "arg0");
if (volname == NULL) {
gctl_error(req, "No volume name.");
return (-2);
@ -1909,6 +1914,14 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
if (strcmp(vol->v_name, volname) == 0)
break;
pp = vol->v_provider;
if (pp == NULL)
continue;
if (strcmp(pp->name, volname) == 0)
break;
if (strncmp(pp->name, "raid/", 5) == 0 &&
strcmp(pp->name + 5, volname) == 0)
break;
}
if (vol == NULL) {
i = strtol(volname, &tmp, 10);

View File

@ -1217,7 +1217,7 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
struct g_consumer *cp;
struct g_provider *pp;
char arg[16];
const char *verb, *volname, *levelname, *diskname;
const char *nodename, *verb, *volname, *levelname, *diskname;
char *tmp;
int *nargs, *force;
off_t size, sectorsize, strip;
@ -1478,8 +1478,12 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
}
if (strcmp(verb, "delete") == 0) {
nodename = gctl_get_asciiparam(req, "arg0");
if (nodename != NULL && strcasecmp(sc->sc_name, nodename) != 0)
nodename = NULL;
/* Full node destruction. */
if (*nargs == 1) {
if (*nargs == 1 && nodename != NULL) {
/* Check if some volume is still open. */
force = gctl_get_paraml(req, "force", sizeof(*force));
if (force != NULL && *force == 0 &&
@ -1497,11 +1501,12 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
}
/* Destroy specified volume. If it was last - all node. */
if (*nargs != 2) {
if (*nargs > 2) {
gctl_error(req, "Invalid number of arguments.");
return (-1);
}
volname = gctl_get_asciiparam(req, "arg1");
volname = gctl_get_asciiparam(req,
nodename != NULL ? "arg1" : "arg0");
if (volname == NULL) {
gctl_error(req, "No volume name.");
return (-2);
@ -1511,6 +1516,14 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
TAILQ_FOREACH(vol, &sc->sc_volumes, v_next) {
if (strcmp(vol->v_name, volname) == 0)
break;
pp = vol->v_provider;
if (pp == NULL)
continue;
if (strcmp(pp->name, volname) == 0)
break;
if (strncmp(pp->name, "raid/", 5) == 0 &&
strcmp(pp->name + 5, volname) == 0)
break;
}
if (vol == NULL) {
i = strtol(volname, &tmp, 10);