aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2020-07-22 02:15:21 +0000
committerXin LI <delphij@FreeBSD.org>2020-07-22 02:15:21 +0000
commitfcf69f3dbce6b3b6187ff584031e690fbe2479d2 (patch)
treeffeb8b9fcb72de1f688fe880b1a8e468add897aa
parent0ab851aac3a028d0771e6d32054b8b768a2bec3b (diff)
downloadsrc-fcf69f3dbce6b3b6187ff584031e690fbe2479d2.tar.gz
src-fcf69f3dbce6b3b6187ff584031e690fbe2479d2.zip
Consistently use gctl_get_provider instead of home-grown variants.
Reviewed by: cem, imp MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D25739
Notes
Notes: svn path=/head/; revision=363411
-rw-r--r--sys/geom/cache/g_cache.c14
-rw-r--r--sys/geom/concat/g_concat.c28
-rw-r--r--sys/geom/eli/g_eli_ctl.c29
-rw-r--r--sys/geom/label/g_label.c14
-rw-r--r--sys/geom/mirror/g_mirror_ctl.c56
-rw-r--r--sys/geom/mountver/g_mountver.c15
-rw-r--r--sys/geom/nop/g_nop.c48
-rw-r--r--sys/geom/raid3/g_raid3_ctl.c15
-rw-r--r--sys/geom/stripe/g_stripe.c26
-rw-r--r--sys/geom/virstor/g_virstor.c19
10 files changed, 62 insertions, 202 deletions
diff --git a/sys/geom/cache/g_cache.c b/sys/geom/cache/g_cache.c
index f20ee9d4368a..337879a3f52c 100644
--- a/sys/geom/cache/g_cache.c
+++ b/sys/geom/cache/g_cache.c
@@ -757,19 +757,9 @@ g_cache_ctl_create(struct gctl_req *req, struct g_class *mp)
/* This field is not important here. */
md.md_provsize = 0;
- name = gctl_get_asciiparam(req, "arg1");
- if (name == NULL) {
- gctl_error(req, "No 'arg1' argument");
- return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_CACHE_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
+ pp = gctl_get_provider(req, "arg1");
+ if (pp == NULL)
return;
- }
gp = g_cache_create(mp, pp, &md, G_CACHE_TYPE_MANUAL);
if (gp == NULL) {
gctl_error(req, "Can't create %s.", md.md_name);
diff --git a/sys/geom/concat/g_concat.c b/sys/geom/concat/g_concat.c
index 63f3cbee82b7..adb92567aba5 100644
--- a/sys/geom/concat/g_concat.c
+++ b/sys/geom/concat/g_concat.c
@@ -840,19 +840,9 @@ g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
/* Check all providers are valid */
for (no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", no);
- return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_CONCAT_DEBUG(1, "Disk %s is invalid.", name);
- gctl_error(req, "Disk %s is invalid.", name);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
}
gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL);
@@ -866,15 +856,13 @@ g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
for (attached = 0, no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument.", no);
- return;
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL) {
+ name = gctl_get_asciiparam(req, param);
+ MPASS(name != NULL);
+ sbuf_printf(sb, " %s", name);
+ continue;
}
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- KASSERT(pp != NULL, ("Provider %s disappear?!", name));
if (g_concat_add_disk(sc, pp, no - 1) != 0) {
G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.",
no, pp->name, gp->name);
diff --git a/sys/geom/eli/g_eli_ctl.c b/sys/geom/eli/g_eli_ctl.c
index ccfdb3aa5119..abff51747709 100644
--- a/sys/geom/eli/g_eli_ctl.c
+++ b/sys/geom/eli/g_eli_ctl.c
@@ -58,7 +58,6 @@ g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp)
{
struct g_eli_metadata md;
struct g_provider *pp;
- const char *name;
u_char *key, mkey[G_ELI_DATAIVKEYLEN];
int *nargs, *detach, *readonly, *dryrunp;
int keysize, error, nkey, dryrun, dummy;
@@ -115,22 +114,13 @@ g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp)
return;
}
- name = gctl_get_asciiparam(req, "arg0");
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 0);
+ pp = gctl_get_provider(req, "arg0");
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- gctl_error(req, "Provider %s is invalid.", name);
- return;
- }
error = g_eli_read_metadata(mp, pp, &md);
if (error != 0) {
gctl_error(req, "Cannot read metadata from %s (error=%d).",
- name, error);
+ pp->name, error);
return;
}
if (md.md_keys == 0x00) {
@@ -368,18 +358,9 @@ g_eli_ctl_onetime(struct gctl_req *req, struct g_class *mp)
/* Not important here. */
bzero(md.md_hash, sizeof(md.md_hash));
- name = gctl_get_asciiparam(req, "arg0");
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 0);
+ pp = gctl_get_provider(req, "arg0");
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- gctl_error(req, "Provider %s is invalid.", name);
- return;
- }
sectorsize = gctl_get_paraml(req, "sectorsize", sizeof(*sectorsize));
if (sectorsize == NULL) {
diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c
index b418451b82c1..1052865b6a4e 100644
--- a/sys/geom/label/g_label.c
+++ b/sys/geom/label/g_label.c
@@ -437,19 +437,9 @@ g_label_ctl_create(struct gctl_req *req, struct g_class *mp)
/*
* arg1 is the name of provider.
*/
- name = gctl_get_asciiparam(req, "arg1");
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", 1);
- return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_LABEL_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
+ pp = gctl_get_provider(req, "arg1");
+ if (pp == NULL)
return;
- }
/*
* arg0 is the label.
*/
diff --git a/sys/geom/mirror/g_mirror_ctl.c b/sys/geom/mirror/g_mirror_ctl.c
index 60e46d8c903e..a1594dd18177 100644
--- a/sys/geom/mirror/g_mirror_ctl.c
+++ b/sys/geom/mirror/g_mirror_ctl.c
@@ -441,34 +441,25 @@ g_mirror_ctl_create(struct gctl_req *req, struct g_class *mp)
cp = g_new_consumer(gp);
for (no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", no);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL) {
err:
g_destroy_consumer(cp);
g_destroy_geom(gp);
g_topology_unlock();
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);
if (g_access(cp, 1, 0, 0) != 0) {
- G_MIRROR_DEBUG(1, "Can't open disk %s.", name);
- gctl_error(req, "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.", pp->name);
err2:
g_detach(cp);
goto err;
}
if (pp->mediasize == 0 || pp->sectorsize == 0) {
- G_MIRROR_DEBUG(1, "Disk %s has no media.", name);
- gctl_error(req, "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.", pp->name);
g_access(cp, -1, 0, 0);
goto err2;
}
@@ -500,12 +491,10 @@ err2:
sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
for (attached = 0, no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
+ pp = gctl_get_provider(req, param);
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);
continue;
}
@@ -677,30 +666,21 @@ g_mirror_ctl_insert(struct gctl_req *req, struct g_class *mp)
g_topology_lock();
for (i = 1, n = 0; i < (u_int)*nargs; i++) {
snprintf(param, sizeof(param), "arg%u", i);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", i);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
continue;
- }
- if (g_mirror_find_disk(sc, name) != NULL) {
- gctl_error(req, "Provider %s already inserted.", name);
- 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);
+ if (g_mirror_find_disk(sc, pp->name) != NULL) {
+ gctl_error(req, "Provider %s already inserted.", pp->name);
continue;
}
cp = g_new_consumer(sc->sc_geom);
if (g_attach(cp, pp) != 0) {
g_destroy_consumer(cp);
- gctl_error(req, "Cannot attach to provider %s.", name);
+ gctl_error(req, "Cannot attach to provider %s.", pp->name);
continue;
}
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:
g_detach(cp);
g_destroy_consumer(cp);
@@ -709,14 +689,14 @@ err:
mdsize = (sc->sc_type == G_MIRROR_TYPE_AUTOMATIC) ?
pp->sectorsize : 0;
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:
g_access(cp, 0, -1, -1);
goto err;
}
if ((sc->sc_provider->sectorsize % pp->sectorsize) != 0) {
gctl_error(req, "Invalid sectorsize of provider %s.",
- name);
+ pp->name);
goto err2;
}
if (sc->sc_type != G_MIRROR_TYPE_AUTOMATIC) {
@@ -731,7 +711,7 @@ err2:
md.md_dflags |= G_MIRROR_DISK_FLAG_INACTIVE;
if (g_mirror_add_disk(sc, pp, &md) != 0) {
sc->sc_ndisks--;
- gctl_error(req, "Disk %s not inserted.", name);
+ gctl_error(req, "Disk %s not inserted.", pp->name);
}
g_topology_lock();
continue;
diff --git a/sys/geom/mountver/g_mountver.c b/sys/geom/mountver/g_mountver.c
index c1ca84aa451a..4d48e6bfdb78 100644
--- a/sys/geom/mountver/g_mountver.c
+++ b/sys/geom/mountver/g_mountver.c
@@ -404,7 +404,6 @@ static void
g_mountver_ctl_create(struct gctl_req *req, struct g_class *mp)
{
struct g_provider *pp;
- const char *name;
char param[16];
int i, *nargs;
@@ -421,19 +420,9 @@ g_mountver_ctl_create(struct gctl_req *req, struct g_class *mp)
}
for (i = 0; i < *nargs; i++) {
snprintf(param, sizeof(param), "arg%d", i);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", i);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_MOUNTVER_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
- return;
- }
if (g_mountver_create(req, mp, pp) != 0)
return;
}
diff --git a/sys/geom/nop/g_nop.c b/sys/geom/nop/g_nop.c
index e0dd92ef20a1..75d4f44f2627 100644
--- a/sys/geom/nop/g_nop.c
+++ b/sys/geom/nop/g_nop.c
@@ -544,7 +544,7 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
intmax_t *val, error, rfailprob, wfailprob, count_until_fail, offset,
secsize, size, stripesize, stripeoffset, delaymsec,
rdelayprob, wdelayprob;
- const char *name, *physpath, *gnopname;
+ const char *physpath, *gnopname;
char param[16];
int i, *nargs;
@@ -671,19 +671,9 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
for (i = 0; i < *nargs; i++) {
snprintf(param, sizeof(param), "arg%d", i);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", i);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_NOP_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
- return;
- }
if (g_nop_create(req, mp, pp,
gnopname,
error == -1 ? EIO : (int)error,
@@ -708,7 +698,6 @@ g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp)
struct g_provider *pp;
intmax_t *val, delaymsec, error, rdelayprob, rfailprob, wdelayprob,
wfailprob, count_until_fail;
- const char *name;
char param[16];
int i, *nargs;
@@ -782,17 +771,12 @@ g_nop_ctl_configure(struct gctl_req *req, struct g_class *mp)
for (i = 0; i < *nargs; i++) {
snprintf(param, sizeof(param), "arg%d", i);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", i);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL || pp->geom->class != mp) {
- G_NOP_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
+ if (pp->geom->class != mp) {
+ G_NOP_DEBUG(1, "Provider %s is invalid.", pp->name);
+ gctl_error(req, "Provider %s is invalid.", pp->name);
return;
}
sc = pp->geom->softc;
@@ -879,7 +863,6 @@ g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp)
{
struct g_nop_softc *sc;
struct g_provider *pp;
- const char *name;
char param[16];
int i, *nargs;
@@ -897,17 +880,12 @@ g_nop_ctl_reset(struct gctl_req *req, struct g_class *mp)
for (i = 0; i < *nargs; i++) {
snprintf(param, sizeof(param), "arg%d", i);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", i);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL || pp->geom->class != mp) {
- G_NOP_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
+ if (pp->geom->class != mp) {
+ G_NOP_DEBUG(1, "Provider %s is invalid.", pp->name);
+ gctl_error(req, "Provider %s is invalid.", pp->name);
return;
}
sc = pp->geom->softc;
diff --git a/sys/geom/raid3/g_raid3_ctl.c b/sys/geom/raid3/g_raid3_ctl.c
index 9794f176470b..1fb81501e87d 100644
--- a/sys/geom/raid3/g_raid3_ctl.c
+++ b/sys/geom/raid3/g_raid3_ctl.c
@@ -422,24 +422,13 @@ g_raid3_ctl_insert(struct gctl_req *req, struct g_class *mp)
gctl_error(req, "No '%s' argument.", "hardcode");
return;
}
- name = gctl_get_asciiparam(req, "arg1");
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 1);
+ pp = gctl_get_provider(req, "arg1");
+ if (pp == NULL)
return;
- }
if (gctl_get_param(req, "number", NULL) != NULL)
no = gctl_get_paraml(req, "number", sizeof(*no));
else
no = NULL;
- if (strncmp(name, _PATH_DEV, 5) == 0)
- name += 5;
- g_topology_lock();
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- g_topology_unlock();
- gctl_error(req, "Invalid provider.");
- return;
- }
gp = g_new_geomf(mp, "raid3:insert");
gp->orphan = g_raid3_ctl_insert_orphan;
cp = g_new_consumer(gp);
diff --git a/sys/geom/stripe/g_stripe.c b/sys/geom/stripe/g_stripe.c
index af764ee7453a..a1b9835499ee 100644
--- a/sys/geom/stripe/g_stripe.c
+++ b/sys/geom/stripe/g_stripe.c
@@ -1091,19 +1091,9 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_class *mp)
/* Check all providers are valid */
for (no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", no);
- return;
- }
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- if (pp == NULL) {
- G_STRIPE_DEBUG(1, "Disk %s is invalid.", name);
- gctl_error(req, "Disk %s is invalid.", name);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL)
return;
- }
}
gp = g_stripe_create(mp, &md, G_STRIPE_TYPE_MANUAL);
@@ -1117,15 +1107,13 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_class *mp)
sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
for (attached = 0, no = 1; no < *nargs; no++) {
snprintf(param, sizeof(param), "arg%u", no);
- name = gctl_get_asciiparam(req, param);
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", no);
+ pp = gctl_get_provider(req, param);
+ if (pp == NULL) {
+ name = gctl_get_asciiparam(req, param);
+ MPASS(name != NULL);
+ sbuf_printf(sb, " %s", name);
continue;
}
- if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
- name += strlen(_PATH_DEV);
- pp = g_provider_by_name(name);
- KASSERT(pp != NULL, ("Provider %s disappear?!", name));
if (g_stripe_add_disk(sc, pp, no - 1) != 0) {
G_STRIPE_DEBUG(1, "Disk %u (%s) not attached to %s.",
no, pp->name, gp->name);
diff --git a/sys/geom/virstor/g_virstor.c b/sys/geom/virstor/g_virstor.c
index be6446e1f8d1..7cc09b32c9c7 100644
--- a/sys/geom/virstor/g_virstor.c
+++ b/sys/geom/virstor/g_virstor.c
@@ -313,32 +313,19 @@ virstor_ctl_add(struct gctl_req *req, struct g_class *cp)
for (i = 1; i < *nargs; i++) {
struct g_virstor_metadata md;
char aname[8];
- const char *prov_name;
struct g_provider *pp;
struct g_consumer *cp;
u_int nc;
u_int j;
snprintf(aname, sizeof aname, "arg%d", i);
- prov_name = gctl_get_asciiparam(req, aname);
- if (prov_name == NULL) {
- gctl_error(req, "Error fetching argument '%s'", aname);
- g_topology_unlock();
- return;
- }
- if (strncmp(prov_name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
- prov_name += sizeof(_PATH_DEV) - 1;
-
- pp = g_provider_by_name(prov_name);
+ pp = gctl_get_provider(req, aname);
if (pp == NULL) {
/* This is the most common error so be verbose about it */
if (added != 0) {
- gctl_error(req, "Invalid provider: '%s' (added"
- " %u components)", prov_name, added);
+ gctl_error(req, "Invalid provider. (added"
+ " %u components)", added);
update_metadata(sc);
- } else {
- gctl_error(req, "Invalid provider: '%s'",
- prov_name);
}
g_topology_unlock();
return;