svn commit: r363411 - in head/sys/geom: cache concat eli label mirror mountver nop raid3 stripe virstor
Xin LI
delphij at FreeBSD.org
Wed Jul 22 02:15:23 UTC 2020
Author: delphij
Date: Wed Jul 22 02:15:21 2020
New Revision: 363411
URL: https://svnweb.freebsd.org/changeset/base/363411
Log:
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
Modified:
head/sys/geom/cache/g_cache.c
head/sys/geom/concat/g_concat.c
head/sys/geom/eli/g_eli_ctl.c
head/sys/geom/label/g_label.c
head/sys/geom/mirror/g_mirror_ctl.c
head/sys/geom/mountver/g_mountver.c
head/sys/geom/nop/g_nop.c
head/sys/geom/raid3/g_raid3_ctl.c
head/sys/geom/stripe/g_stripe.c
head/sys/geom/virstor/g_virstor.c
Modified: head/sys/geom/cache/g_cache.c
==============================================================================
--- head/sys/geom/cache/g_cache.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/cache/g_cache.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -757,19 +757,9 @@ g_cache_ctl_create(struct gctl_req *req, struct g_clas
/* 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");
+ pp = gctl_get_provider(req, "arg1");
+ 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_CACHE_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
- 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);
Modified: head/sys/geom/concat/g_concat.c
==============================================================================
--- head/sys/geom/concat/g_concat.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/concat/g_concat.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -840,19 +840,9 @@ g_concat_ctl_create(struct gctl_req *req, struct g_cla
/* 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);
+ 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_CONCAT_DEBUG(1, "Disk %s is invalid.", name);
- gctl_error(req, "Disk %s is invalid.", name);
- 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_cla
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);
Modified: head/sys/geom/eli/g_eli_ctl.c
==============================================================================
--- head/sys/geom/eli/g_eli_ctl.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/eli/g_eli_ctl.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -58,7 +58,6 @@ g_eli_ctl_attach(struct gctl_req *req, struct g_class
{
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
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
/* 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) {
Modified: head/sys/geom/label/g_label.c
==============================================================================
--- head/sys/geom/label/g_label.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/label/g_label.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -437,19 +437,9 @@ g_label_ctl_create(struct gctl_req *req, struct g_clas
/*
* arg1 is the name of provider.
*/
- name = gctl_get_asciiparam(req, "arg1");
- if (name == NULL) {
- gctl_error(req, "No 'arg%d' argument", 1);
+ pp = gctl_get_provider(req, "arg1");
+ 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_LABEL_DEBUG(1, "Provider %s is invalid.", name);
- gctl_error(req, "Provider %s is invalid.", name);
- return;
- }
/*
* arg0 is the label.
*/
Modified: head/sys/geom/mirror/g_mirror_ctl.c
==============================================================================
--- head/sys/geom/mirror/g_mirror_ctl.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/mirror/g_mirror_ctl.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -441,34 +441,25 @@ g_mirror_ctl_create(struct gctl_req *req, struct g_cla
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_cla
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);
+ if (g_mirror_find_disk(sc, pp->name) != NULL) {
+ gctl_error(req, "Provider %s already inserted.", pp->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);
- 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;
Modified: head/sys/geom/mountver/g_mountver.c
==============================================================================
--- head/sys/geom/mountver/g_mountver.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/mountver/g_mountver.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -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_c
}
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;
}
Modified: head/sys/geom/nop/g_nop.c
==============================================================================
--- head/sys/geom/nop/g_nop.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/nop/g_nop.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -544,7 +544,7 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class
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
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_cla
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_cla
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 *
{
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 *
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;
Modified: head/sys/geom/raid3/g_raid3_ctl.c
==============================================================================
--- head/sys/geom/raid3/g_raid3_ctl.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/raid3/g_raid3_ctl.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -422,24 +422,13 @@ g_raid3_ctl_insert(struct gctl_req *req, struct g_clas
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);
Modified: head/sys/geom/stripe/g_stripe.c
==============================================================================
--- head/sys/geom/stripe/g_stripe.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/stripe/g_stripe.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -1091,19 +1091,9 @@ g_stripe_ctl_create(struct gctl_req *req, struct g_cla
/* 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);
+ 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_STRIPE_DEBUG(1, "Disk %s is invalid.", name);
- gctl_error(req, "Disk %s is invalid.", name);
- 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_cla
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);
Modified: head/sys/geom/virstor/g_virstor.c
==============================================================================
--- head/sys/geom/virstor/g_virstor.c Wed Jul 22 02:14:27 2020 (r363410)
+++ head/sys/geom/virstor/g_virstor.c Wed Jul 22 02:15:21 2020 (r363411)
@@ -313,32 +313,19 @@ virstor_ctl_add(struct gctl_req *req, struct g_class *
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;
More information about the svn-src-all
mailing list