Bunch of small bugfixes and cleanups.
Found with: Clang Static Analyzer
This commit is contained in:
parent
636076752a
commit
14e2cd0a00
@ -1608,7 +1608,7 @@ g_raid_access(struct g_provider *pp, int acr, int acw, int ace)
|
||||
{
|
||||
struct g_raid_volume *vol;
|
||||
struct g_raid_softc *sc;
|
||||
int dcr, dcw, dce, opens, error = 0;
|
||||
int dcw, opens, error = 0;
|
||||
|
||||
g_topology_assert();
|
||||
sc = pp->geom->softc;
|
||||
@ -1618,10 +1618,7 @@ g_raid_access(struct g_provider *pp, int acr, int acw, int ace)
|
||||
|
||||
G_RAID_DEBUG1(2, sc, "Access request for %s: r%dw%de%d.", pp->name,
|
||||
acr, acw, ace);
|
||||
|
||||
dcr = pp->acr + acr;
|
||||
dcw = pp->acw + acw;
|
||||
dce = pp->ace + ace;
|
||||
|
||||
g_topology_unlock();
|
||||
sx_xlock(&sc->sc_lock);
|
||||
|
@ -1153,7 +1153,6 @@ g_raid_md_taste_intel(struct g_raid_md_object *md, struct g_class *mp,
|
||||
|
||||
/* Read metadata from device. */
|
||||
meta = NULL;
|
||||
spare = 0;
|
||||
vendor = 0xffff;
|
||||
disk_pos = 0;
|
||||
if (g_access(cp, 1, 0, 0) != 0)
|
||||
@ -1431,7 +1430,7 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
|
||||
gctl_error(req, "Can't open disk '%s'.",
|
||||
diskname);
|
||||
g_topology_unlock();
|
||||
error = -4;
|
||||
error = -7;
|
||||
break;
|
||||
}
|
||||
pp = cp->provider;
|
||||
@ -1481,6 +1480,11 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (sectorsize <= 0) {
|
||||
gctl_error(req, "Can't get sector size.");
|
||||
return (-8);
|
||||
}
|
||||
|
||||
/* Reserve some space for metadata. */
|
||||
size -= ((4096 + sectorsize - 1) / sectorsize) * sectorsize;
|
||||
|
||||
@ -1953,7 +1957,6 @@ g_raid_md_ctl_intel(struct g_raid_md_object *md,
|
||||
|
||||
disk = g_raid_create_disk(sc);
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_md_data = (void *)pd;
|
||||
cp->private = disk;
|
||||
|
||||
|
@ -579,14 +579,12 @@ g_raid_md_jmicron_refill(struct g_raid_softc *sc)
|
||||
{
|
||||
struct g_raid_md_object *md;
|
||||
struct g_raid_md_jmicron_object *mdi;
|
||||
struct jmicron_raid_conf *meta;
|
||||
struct g_raid_disk *disk;
|
||||
struct task *task;
|
||||
int update, na;
|
||||
|
||||
md = sc->sc_md;
|
||||
mdi = (struct g_raid_md_jmicron_object *)md;
|
||||
meta = mdi->mdio_meta;
|
||||
update = 0;
|
||||
do {
|
||||
/* Make sure we miss anything. */
|
||||
@ -620,10 +618,8 @@ g_raid_md_jmicron_refill(struct g_raid_softc *sc)
|
||||
} while (disk != NULL);
|
||||
|
||||
/* Write new metadata if we changed something. */
|
||||
if (update) {
|
||||
if (update)
|
||||
g_raid_md_write_jmicron(md, NULL, NULL, NULL);
|
||||
meta = mdi->mdio_meta;
|
||||
}
|
||||
|
||||
/* Update status of our need for spare. */
|
||||
mdi->mdio_incomplete = (g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE) <
|
||||
@ -835,9 +831,7 @@ g_raid_md_taste_jmicron(struct g_raid_md_object *md, struct g_class *mp,
|
||||
|
||||
/* Read metadata from device. */
|
||||
meta = NULL;
|
||||
spare = 0;
|
||||
vendor = 0xffff;
|
||||
disk_pos = 0;
|
||||
if (g_access(cp, 1, 0, 0) != 0)
|
||||
return (G_RAID_MD_TASTE_FAIL);
|
||||
g_topology_unlock();
|
||||
@ -1133,6 +1127,11 @@ g_raid_md_ctl_jmicron(struct g_raid_md_object *md,
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (sectorsize <= 0) {
|
||||
gctl_error(req, "Can't get sector size.");
|
||||
return (-8);
|
||||
}
|
||||
|
||||
/* Reserve space for metadata. */
|
||||
size -= sectorsize;
|
||||
|
||||
@ -1364,7 +1363,6 @@ g_raid_md_ctl_jmicron(struct g_raid_md_object *md,
|
||||
|
||||
disk = g_raid_create_disk(sc);
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_md_data = (void *)pd;
|
||||
cp->private = disk;
|
||||
g_topology_unlock();
|
||||
@ -1470,7 +1468,6 @@ g_raid_md_write_jmicron(struct g_raid_md_object *md, struct g_raid_volume *tvol,
|
||||
if (mdi->mdio_meta != NULL)
|
||||
free(mdi->mdio_meta, M_MD_JMICRON);
|
||||
mdi->mdio_meta = meta;
|
||||
i = 0;
|
||||
TAILQ_FOREACH(disk, &sc->sc_disks, d_next) {
|
||||
pd = (struct g_raid_md_jmicron_perdisk *)disk->d_md_data;
|
||||
if (disk->d_state != G_RAID_DISK_S_ACTIVE &&
|
||||
@ -1507,12 +1504,10 @@ g_raid_md_fail_disk_jmicron(struct g_raid_md_object *md,
|
||||
struct g_raid_subdisk *tsd, struct g_raid_disk *tdisk)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_md_jmicron_object *mdi;
|
||||
struct g_raid_md_jmicron_perdisk *pd;
|
||||
struct g_raid_subdisk *sd;
|
||||
|
||||
sc = md->mdo_softc;
|
||||
mdi = (struct g_raid_md_jmicron_object *)md;
|
||||
pd = (struct g_raid_md_jmicron_perdisk *)tdisk->d_md_data;
|
||||
|
||||
/* We can't fail disk that is not a part of array now. */
|
||||
|
@ -584,14 +584,12 @@ g_raid_md_nvidia_refill(struct g_raid_softc *sc)
|
||||
{
|
||||
struct g_raid_md_object *md;
|
||||
struct g_raid_md_nvidia_object *mdi;
|
||||
struct nvidia_raid_conf *meta;
|
||||
struct g_raid_disk *disk;
|
||||
struct task *task;
|
||||
int update, na;
|
||||
|
||||
md = sc->sc_md;
|
||||
mdi = (struct g_raid_md_nvidia_object *)md;
|
||||
meta = mdi->mdio_meta;
|
||||
update = 0;
|
||||
do {
|
||||
/* Make sure we miss anything. */
|
||||
@ -625,10 +623,8 @@ g_raid_md_nvidia_refill(struct g_raid_softc *sc)
|
||||
} while (disk != NULL);
|
||||
|
||||
/* Write new metadata if we changed something. */
|
||||
if (update) {
|
||||
if (update)
|
||||
g_raid_md_write_nvidia(md, NULL, NULL, NULL);
|
||||
meta = mdi->mdio_meta;
|
||||
}
|
||||
|
||||
/* Update status of our need for spare. */
|
||||
mdi->mdio_incomplete = (g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE) <
|
||||
@ -828,7 +824,7 @@ g_raid_md_taste_nvidia(struct g_raid_md_object *md, struct g_class *mp,
|
||||
struct nvidia_raid_conf *meta;
|
||||
struct g_raid_md_nvidia_perdisk *pd;
|
||||
struct g_geom *geom;
|
||||
int error, disk_pos, result, spare, len;
|
||||
int error, result, spare, len;
|
||||
char name[32];
|
||||
uint16_t vendor;
|
||||
|
||||
@ -838,9 +834,7 @@ g_raid_md_taste_nvidia(struct g_raid_md_object *md, struct g_class *mp,
|
||||
|
||||
/* Read metadata from device. */
|
||||
meta = NULL;
|
||||
spare = 0;
|
||||
vendor = 0xffff;
|
||||
disk_pos = 0;
|
||||
if (g_access(cp, 1, 0, 0) != 0)
|
||||
return (G_RAID_MD_TASTE_FAIL);
|
||||
g_topology_unlock();
|
||||
@ -866,16 +860,9 @@ g_raid_md_taste_nvidia(struct g_raid_md_object *md, struct g_class *mp,
|
||||
return (G_RAID_MD_TASTE_FAIL);
|
||||
}
|
||||
|
||||
/* Check this disk position in obtained metadata. */
|
||||
disk_pos = meta->disk_number;
|
||||
if (disk_pos == -1) {
|
||||
G_RAID_DEBUG(1, "NVIDIA disk position not found");
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
/* Metadata valid. Print it. */
|
||||
g_raid_md_nvidia_print(meta);
|
||||
G_RAID_DEBUG(1, "NVIDIA disk position %d", disk_pos);
|
||||
G_RAID_DEBUG(1, "NVIDIA disk position %d", meta->disk_number);
|
||||
spare = 0;//(meta->type == NVIDIA_T_SPARE) ? 1 : 0;
|
||||
|
||||
search:
|
||||
@ -1141,6 +1128,11 @@ g_raid_md_ctl_nvidia(struct g_raid_md_object *md,
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (sectorsize <= 0) {
|
||||
gctl_error(req, "Can't get sector size.");
|
||||
return (-8);
|
||||
}
|
||||
|
||||
/* Reserve space for metadata. */
|
||||
size -= 2 * sectorsize;
|
||||
|
||||
@ -1371,7 +1363,6 @@ g_raid_md_ctl_nvidia(struct g_raid_md_object *md,
|
||||
|
||||
disk = g_raid_create_disk(sc);
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_md_data = (void *)pd;
|
||||
cp->private = disk;
|
||||
g_topology_unlock();
|
||||
@ -1528,12 +1519,10 @@ g_raid_md_fail_disk_nvidia(struct g_raid_md_object *md,
|
||||
struct g_raid_subdisk *tsd, struct g_raid_disk *tdisk)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_md_nvidia_object *mdi;
|
||||
struct g_raid_md_nvidia_perdisk *pd;
|
||||
struct g_raid_subdisk *sd;
|
||||
|
||||
sc = md->mdo_softc;
|
||||
mdi = (struct g_raid_md_nvidia_object *)md;
|
||||
pd = (struct g_raid_md_nvidia_perdisk *)tdisk->d_md_data;
|
||||
|
||||
/* We can't fail disk that is not a part of array now. */
|
||||
|
@ -1154,12 +1154,10 @@ g_raid_md_event_promise(struct g_raid_md_object *md,
|
||||
struct g_raid_disk *disk, u_int event)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_md_promise_perdisk *pd;
|
||||
|
||||
sc = md->mdo_softc;
|
||||
if (disk == NULL)
|
||||
return (-1);
|
||||
pd = (struct g_raid_md_promise_perdisk *)disk->d_md_data;
|
||||
switch (event) {
|
||||
case G_RAID_DISK_E_DISCONNECTED:
|
||||
/* Delete disk. */
|
||||
@ -1184,10 +1182,8 @@ static int
|
||||
g_raid_md_volume_event_promise(struct g_raid_md_object *md,
|
||||
struct g_raid_volume *vol, u_int event)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_md_promise_pervolume *pv;
|
||||
|
||||
sc = md->mdo_softc;
|
||||
pv = (struct g_raid_md_promise_pervolume *)vol->v_md_data;
|
||||
switch (event) {
|
||||
case G_RAID_VOLUME_E_STARTMD:
|
||||
@ -1345,6 +1341,11 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
|
||||
return (error);
|
||||
}
|
||||
|
||||
if (sectorsize <= 0) {
|
||||
gctl_error(req, "Can't get sector size.");
|
||||
return (-8);
|
||||
}
|
||||
|
||||
/* Handle size argument. */
|
||||
len = sizeof(*sizearg);
|
||||
sizearg = gctl_get_param(req, "size", &len);
|
||||
@ -1567,8 +1568,6 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
|
||||
continue;
|
||||
}
|
||||
|
||||
pd = (struct g_raid_md_promise_perdisk *)disk->d_md_data;
|
||||
|
||||
/* Erase metadata on deleting disk and destroy it. */
|
||||
promise_meta_erase(disk->d_consumer);
|
||||
g_raid_destroy_disk(disk);
|
||||
@ -1610,14 +1609,12 @@ g_raid_md_ctl_promise(struct g_raid_md_object *md,
|
||||
error = -4;
|
||||
break;
|
||||
}
|
||||
pp = cp->provider;
|
||||
g_topology_unlock();
|
||||
|
||||
pd = malloc(sizeof(*pd), M_MD_PROMISE, M_WAITOK | M_ZERO);
|
||||
|
||||
disk = g_raid_create_disk(sc);
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_md_data = (void *)pd;
|
||||
cp->private = disk;
|
||||
|
||||
|
@ -641,14 +641,12 @@ g_raid_md_sii_refill(struct g_raid_softc *sc)
|
||||
{
|
||||
struct g_raid_md_object *md;
|
||||
struct g_raid_md_sii_object *mdi;
|
||||
struct sii_raid_conf *meta;
|
||||
struct g_raid_disk *disk;
|
||||
struct task *task;
|
||||
int update, na;
|
||||
|
||||
md = sc->sc_md;
|
||||
mdi = (struct g_raid_md_sii_object *)md;
|
||||
meta = mdi->mdio_meta;
|
||||
update = 0;
|
||||
do {
|
||||
/* Make sure we miss anything. */
|
||||
@ -682,10 +680,8 @@ g_raid_md_sii_refill(struct g_raid_softc *sc)
|
||||
} while (disk != NULL);
|
||||
|
||||
/* Write new metadata if we changed something. */
|
||||
if (update) {
|
||||
if (update)
|
||||
g_raid_md_write_sii(md, NULL, NULL, NULL);
|
||||
meta = mdi->mdio_meta;
|
||||
}
|
||||
|
||||
/* Update status of our need for spare. */
|
||||
mdi->mdio_incomplete = (g_raid_ndisks(sc, G_RAID_DISK_S_ACTIVE) <
|
||||
@ -921,9 +917,7 @@ g_raid_md_taste_sii(struct g_raid_md_object *md, struct g_class *mp,
|
||||
|
||||
/* Read metadata from device. */
|
||||
meta = NULL;
|
||||
spare = 0;
|
||||
vendor = 0xffff;
|
||||
disk_pos = 0;
|
||||
if (g_access(cp, 1, 0, 0) != 0)
|
||||
return (G_RAID_MD_TASTE_FAIL);
|
||||
g_topology_unlock();
|
||||
@ -1219,6 +1213,11 @@ g_raid_md_ctl_sii(struct g_raid_md_object *md,
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (sectorsize <= 0) {
|
||||
gctl_error(req, "Can't get sector size.");
|
||||
return (-8);
|
||||
}
|
||||
|
||||
/* Reserve space for metadata. */
|
||||
size -= 0x800 * sectorsize;
|
||||
|
||||
@ -1449,7 +1448,6 @@ g_raid_md_ctl_sii(struct g_raid_md_object *md,
|
||||
|
||||
disk = g_raid_create_disk(sc);
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_md_data = (void *)pd;
|
||||
cp->private = disk;
|
||||
g_topology_unlock();
|
||||
@ -1559,7 +1557,6 @@ g_raid_md_write_sii(struct g_raid_md_object *md, struct g_raid_volume *tvol,
|
||||
if (mdi->mdio_meta != NULL)
|
||||
free(mdi->mdio_meta, M_MD_SII);
|
||||
mdi->mdio_meta = meta;
|
||||
i = 0;
|
||||
TAILQ_FOREACH(disk, &sc->sc_disks, d_next) {
|
||||
pd = (struct g_raid_md_sii_perdisk *)disk->d_md_data;
|
||||
if (disk->d_state != G_RAID_DISK_S_ACTIVE)
|
||||
@ -1605,12 +1602,10 @@ g_raid_md_fail_disk_sii(struct g_raid_md_object *md,
|
||||
struct g_raid_subdisk *tsd, struct g_raid_disk *tdisk)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_md_sii_object *mdi;
|
||||
struct g_raid_md_sii_perdisk *pd;
|
||||
struct g_raid_subdisk *sd;
|
||||
|
||||
sc = md->mdo_softc;
|
||||
mdi = (struct g_raid_md_sii_object *)md;
|
||||
pd = (struct g_raid_md_sii_perdisk *)tdisk->d_md_data;
|
||||
|
||||
/* We can't fail disk that is not a part of array now. */
|
||||
|
@ -549,7 +549,6 @@ g_raid_tr_iostart_raid1_read(struct g_raid_tr_object *tr, struct bio *bp)
|
||||
static void
|
||||
g_raid_tr_iostart_raid1_write(struct g_raid_tr_object *tr, struct bio *bp)
|
||||
{
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_volume *vol;
|
||||
struct g_raid_subdisk *sd;
|
||||
struct bio_queue_head queue;
|
||||
@ -557,7 +556,6 @@ g_raid_tr_iostart_raid1_write(struct g_raid_tr_object *tr, struct bio *bp)
|
||||
int i;
|
||||
|
||||
vol = tr->tro_volume;
|
||||
sc = vol->v_softc;
|
||||
|
||||
/*
|
||||
* Allocate all bios before sending any request, so we can return
|
||||
|
@ -196,13 +196,11 @@ g_raid_tr_taste_raid1e(struct g_raid_tr_object *tr, struct g_raid_volume *vol)
|
||||
static int
|
||||
g_raid_tr_update_state_raid1e_even(struct g_raid_volume *vol)
|
||||
{
|
||||
struct g_raid_tr_raid1e_object *trs;
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_subdisk *sd, *bestsd, *worstsd;
|
||||
int i, j, state, sstate;
|
||||
|
||||
sc = vol->v_softc;
|
||||
trs = (struct g_raid_tr_raid1e_object *)vol->v_tr;
|
||||
state = G_RAID_VOLUME_S_OPTIMAL;
|
||||
for (i = 0; i < vol->v_disks_count / N; i++) {
|
||||
bestsd = &vol->v_subdisks[i * N];
|
||||
@ -251,13 +249,11 @@ g_raid_tr_update_state_raid1e_even(struct g_raid_volume *vol)
|
||||
static int
|
||||
g_raid_tr_update_state_raid1e_odd(struct g_raid_volume *vol)
|
||||
{
|
||||
struct g_raid_tr_raid1e_object *trs;
|
||||
struct g_raid_softc *sc;
|
||||
struct g_raid_subdisk *sd, *bestsd, *worstsd;
|
||||
int i, j, state, sstate;
|
||||
|
||||
sc = vol->v_softc;
|
||||
trs = (struct g_raid_tr_raid1e_object *)vol->v_tr;
|
||||
if (g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_ACTIVE) ==
|
||||
vol->v_disks_count)
|
||||
return (G_RAID_VOLUME_S_OPTIMAL);
|
||||
|
Loading…
Reference in New Issue
Block a user