- Style fixes.

- Prefer strlcpy() over strncpy().
This commit is contained in:
Pawel Jakub Dawidek 2010-02-18 22:29:35 +00:00
parent f24bf7522d
commit 12f35a615a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=204071

View File

@ -95,9 +95,8 @@ g_mpd(void *arg, int flags __unused)
g_topology_assert(); g_topology_assert();
cp = arg; cp = arg;
if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) { if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
g_access(cp, -cp->acr, -cp->acw, -cp->ace); g_access(cp, -cp->acr, -cp->acw, -cp->ace);
}
if (cp->provider) { if (cp->provider) {
printf("GEOM_MULTIPATH: %s removed from %s\n", printf("GEOM_MULTIPATH: %s removed from %s\n",
cp->provider->name, cp->geom->name); cp->provider->name, cp->geom->name);
@ -222,15 +221,16 @@ g_multipath_done_error(struct bio *bp)
static void static void
g_multipath_kt(void *arg) g_multipath_kt(void *arg)
{ {
g_multipath_kt_state = GKT_RUN; g_multipath_kt_state = GKT_RUN;
mtx_lock(&gmtbq_mtx); mtx_lock(&gmtbq_mtx);
while (g_multipath_kt_state == GKT_RUN) { while (g_multipath_kt_state == GKT_RUN) {
for (;;) { for (;;) {
struct bio *bp; struct bio *bp;
bp = bioq_takefirst(&gmtbq); bp = bioq_takefirst(&gmtbq);
if (bp == NULL) { if (bp == NULL)
break; break;
}
mtx_unlock(&gmtbq_mtx); mtx_unlock(&gmtbq_mtx);
g_multipath_done_error(bp); g_multipath_done_error(bp);
mtx_lock(&gmtbq_mtx); mtx_lock(&gmtbq_mtx);
@ -264,9 +264,8 @@ g_multipath_access(struct g_provider *pp, int dr, int dw, int de)
fail: fail:
LIST_FOREACH(cp, &gp->consumer, consumer) { LIST_FOREACH(cp, &gp->consumer, consumer) {
if (cp == badcp) { if (cp == badcp)
break; break;
}
(void) g_access(cp, -dr, -dw, -de); (void) g_access(cp, -dr, -dw, -de);
} }
return (error); return (error);
@ -290,9 +289,8 @@ g_multipath_create(struct g_class *mp, struct g_multipath_metadata *md)
} }
gp = g_new_geomf(mp, md->md_name); gp = g_new_geomf(mp, md->md_name);
if (gp == NULL) { if (gp == NULL)
goto fail; goto fail;
}
sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO); sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
gp->softc = sc; gp->softc = sc;
@ -303,9 +301,8 @@ g_multipath_create(struct g_class *mp, struct g_multipath_metadata *md)
memcpy(sc->sc_name, md->md_name, sizeof (sc->sc_name)); memcpy(sc->sc_name, md->md_name, sizeof (sc->sc_name));
pp = g_new_providerf(gp, "multipath/%s", md->md_name); pp = g_new_providerf(gp, "multipath/%s", md->md_name);
if (pp == NULL) { if (pp == NULL)
goto fail; goto fail;
}
/* limit the provider to not have it stomp on metadata */ /* limit the provider to not have it stomp on metadata */
pp->mediasize = md->md_size - md->md_sectorsize; pp->mediasize = md->md_size - md->md_sectorsize;
pp->sectorsize = md->md_sectorsize; pp->sectorsize = md->md_sectorsize;
@ -314,9 +311,8 @@ g_multipath_create(struct g_class *mp, struct g_multipath_metadata *md)
return (gp); return (gp);
fail: fail:
if (gp != NULL) { if (gp != NULL) {
if (gp->softc != NULL) { if (gp->softc != NULL)
g_free(gp->softc); g_free(gp->softc);
}
g_destroy_geom(gp); g_destroy_geom(gp);
} }
return (NULL); return (NULL);
@ -338,9 +334,8 @@ g_multipath_add_disk(struct g_geom *gp, struct g_provider *pp)
* Make sure that the passed provider isn't already attached * Make sure that the passed provider isn't already attached
*/ */
LIST_FOREACH(cp, &gp->consumer, consumer) { LIST_FOREACH(cp, &gp->consumer, consumer) {
if (cp->provider == pp) { if (cp->provider == pp)
break; break;
}
} }
if (cp) { if (cp) {
printf("GEOM_MULTIPATH: provider %s already attached to %s\n", printf("GEOM_MULTIPATH: provider %s already attached to %s\n",
@ -349,9 +344,8 @@ g_multipath_add_disk(struct g_geom *gp, struct g_provider *pp)
} }
nxtcp = LIST_FIRST(&gp->consumer); nxtcp = LIST_FIRST(&gp->consumer);
cp = g_new_consumer(gp); cp = g_new_consumer(gp);
if (cp == NULL) { if (cp == NULL)
return (ENOMEM); return (ENOMEM);
}
error = g_attach(cp, pp); error = g_attach(cp, pp);
if (error != 0) { if (error != 0) {
printf("GEOM_MULTIPATH: cannot attach %s to %s", printf("GEOM_MULTIPATH: cannot attach %s to %s",
@ -392,13 +386,11 @@ g_multipath_destroy(struct g_geom *gp)
struct g_provider *pp; struct g_provider *pp;
g_topology_assert(); g_topology_assert();
if (gp->softc == NULL) { if (gp->softc == NULL)
return (ENXIO); return (ENXIO);
}
pp = LIST_FIRST(&gp->provider); pp = LIST_FIRST(&gp->provider);
if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) { if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0))
return (EBUSY); return (EBUSY);
}
printf("GEOM_MULTIPATH: destroying %s\n", gp->name); printf("GEOM_MULTIPATH: destroying %s\n", gp->name);
g_free(gp->softc); g_free(gp->softc);
gp->softc = NULL; gp->softc = NULL;
@ -410,6 +402,7 @@ static int
g_multipath_destroy_geom(struct gctl_req *req, struct g_class *mp, g_multipath_destroy_geom(struct gctl_req *req, struct g_class *mp,
struct g_geom *gp) struct g_geom *gp)
{ {
return (g_multipath_destroy(gp)); return (g_multipath_destroy(gp));
} }
@ -418,9 +411,8 @@ g_multipath_init(struct g_class *mp)
{ {
bioq_init(&gmtbq); bioq_init(&gmtbq);
mtx_init(&gmtbq_mtx, "gmtbq", NULL, MTX_DEF); mtx_init(&gmtbq_mtx, "gmtbq", NULL, MTX_DEF);
if (kproc_create(g_multipath_kt, mp, NULL, 0, 0, "g_mp_kt") == 0) { if (kproc_create(g_multipath_kt, mp, NULL, 0, 0, "g_mp_kt") == 0)
g_multipath_kt_state = GKT_RUN; g_multipath_kt_state = GKT_RUN;
}
} }
static void static void
@ -446,18 +438,16 @@ g_multipath_read_metadata(struct g_consumer *cp,
g_topology_assert(); g_topology_assert();
error = g_access(cp, 1, 0, 0); error = g_access(cp, 1, 0, 0);
if (error != 0) { if (error != 0)
return (error); return (error);
}
pp = cp->provider; pp = cp->provider;
g_topology_unlock(); g_topology_unlock();
buf = g_read_data(cp, pp->mediasize - pp->sectorsize, buf = g_read_data(cp, pp->mediasize - pp->sectorsize,
pp->sectorsize, &error); pp->sectorsize, &error);
g_topology_lock(); g_topology_lock();
g_access(cp, -1, 0, 0); g_access(cp, -1, 0, 0);
if (buf == NULL) { if (buf == NULL)
return (error); return (error);
}
multipath_metadata_decode(buf, md); multipath_metadata_decode(buf, md);
g_free(buf); g_free(buf);
return (0); return (0);
@ -484,15 +474,13 @@ g_multipath_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
g_detach(cp); g_detach(cp);
g_destroy_consumer(cp); g_destroy_consumer(cp);
g_destroy_geom(gp); g_destroy_geom(gp);
if (error != 0) { if (error != 0)
return (NULL); return (NULL);
}
gp = NULL; gp = NULL;
if (strcmp(md.md_magic, G_MULTIPATH_MAGIC) != 0) { if (strcmp(md.md_magic, G_MULTIPATH_MAGIC) != 0) {
if (g_multipath_debug) { if (g_multipath_debug)
printf("%s is not MULTIPATH\n", pp->name); printf("%s is not MULTIPATH\n", pp->name);
}
return (NULL); return (NULL);
} }
if (md.md_version != G_MULTIPATH_VERSION) { if (md.md_version != G_MULTIPATH_VERSION) {
@ -501,9 +489,8 @@ g_multipath_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
G_MULTIPATH_VERSION); G_MULTIPATH_VERSION);
return (NULL); return (NULL);
} }
if (g_multipath_debug) { if (g_multipath_debug)
printf("MULTIPATH: %s/%s\n", md.md_name, md.md_uuid); printf("MULTIPATH: %s/%s\n", md.md_name, md.md_uuid);
}
/* /*
* Let's check if such a device already is present. We check against * Let's check if such a device already is present. We check against
@ -519,25 +506,20 @@ g_multipath_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
sc = NULL; sc = NULL;
LIST_FOREACH(gp, &mp->geom, geom) { LIST_FOREACH(gp, &mp->geom, geom) {
sc = gp->softc; sc = gp->softc;
if (sc == NULL) { if (sc == NULL)
continue; continue;
} if (strncmp(md.md_uuid, sc->sc_uuid, sizeof(md.md_uuid)) == 0)
if (strncmp(md.md_uuid, sc->sc_uuid, sizeof(md.md_uuid)) == 0) {
break; break;
}
} }
LIST_FOREACH(gp1, &mp->geom, geom) { LIST_FOREACH(gp1, &mp->geom, geom) {
if (gp1 == gp) { if (gp1 == gp)
continue; continue;
}
sc = gp1->softc; sc = gp1->softc;
if (sc == NULL) { if (sc == NULL)
continue; continue;
} if (strncmp(md.md_name, sc->sc_name, sizeof(md.md_name)) == 0)
if (strncmp(md.md_name, sc->sc_name, sizeof(md.md_name)) == 0) {
break; break;
}
} }
/* /*
@ -564,9 +546,9 @@ g_multipath_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
sc->sc_name, sc->sc_uuid); sc->sc_name, sc->sc_uuid);
printf("GEOM_MULTIPATH: %s will be (temporarily) %s\n", printf("GEOM_MULTIPATH: %s will be (temporarily) %s\n",
md.md_uuid, buf); md.md_uuid, buf);
strlcpy(md.md_name, buf, sizeof (md.md_name)); strlcpy(md.md_name, buf, sizeof(md.md_name));
} else { } else {
strlcpy(md.md_name, sc->sc_name, sizeof (md.md_name)); strlcpy(md.md_name, sc->sc_name, sizeof(md.md_name));
} }
} }
@ -586,9 +568,8 @@ g_multipath_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
KASSERT(sc != NULL, ("sc is NULL")); KASSERT(sc != NULL, ("sc is NULL"));
error = g_multipath_add_disk(gp, pp); error = g_multipath_add_disk(gp, pp);
if (error != 0) { if (error != 0) {
if (isnew) { if (isnew)
g_multipath_destroy(gp); g_multipath_destroy(gp);
}
return (NULL); return (NULL);
} }
return (gp); return (gp);
@ -627,9 +608,8 @@ g_multipath_ctl_create(struct gctl_req *req, struct g_class *mp)
gctl_error(req, "No 'arg1' argument"); gctl_error(req, "No 'arg1' argument");
return; return;
} }
if (strncmp(name, devpf, 5) == 0) { if (strncmp(name, devpf, 5) == 0)
name += 5; name += 5;
}
pp0 = g_provider_by_name(name); pp0 = g_provider_by_name(name);
if (pp0 == NULL) { if (pp0 == NULL) {
gctl_error(req, "Provider %s is invalid", name); gctl_error(req, "Provider %s is invalid", name);
@ -641,9 +621,8 @@ g_multipath_ctl_create(struct gctl_req *req, struct g_class *mp)
gctl_error(req, "No 'arg2' argument"); gctl_error(req, "No 'arg2' argument");
return; return;
} }
if (strncmp(name, devpf, 5) == 0) { if (strncmp(name, devpf, 5) == 0)
name += 5; name += 5;
}
pp1 = g_provider_by_name(name); pp1 = g_provider_by_name(name);
if (pp1 == NULL) { if (pp1 == NULL) {
gctl_error(req, "Provider %s is invalid", name); gctl_error(req, "Provider %s is invalid", name);
@ -687,13 +666,12 @@ g_multipath_ctl_create(struct gctl_req *req, struct g_class *mp)
memset(&md, 0, sizeof(md)); memset(&md, 0, sizeof(md));
md.md_size = pp0->mediasize; md.md_size = pp0->mediasize;
md.md_sectorsize = pp0->sectorsize; md.md_sectorsize = pp0->sectorsize;
strncpy(md.md_name, mpname, sizeof (md.md_name)); strlcpy(md.md_name, mpname, sizeof(md.md_name));
strncpy(md.md_uuid, uuid, sizeof (md.md_uuid)); strlcpy(md.md_uuid, uuid, sizeof(md.md_uuid));
gp = g_multipath_create(mp, &md); gp = g_multipath_create(mp, &md);
if (gp == NULL) { if (gp == NULL)
return; return;
}
error = g_multipath_add_disk(gp, pp0); error = g_multipath_add_disk(gp, pp0);
if (error) { if (error) {
g_multipath_destroy(gp); g_multipath_destroy(gp);