Revise use of the vinum_conf variables drives_used, subdisks_used,

plexes_used and volumes_used.  Now these fields are only informative,
and the <object>_allocated count is used for searches, etc.  This also
required checking the object state before doing things with the
presumed object.

Problems-reported-by: Kiril Mitev <kiril@ideaglobal.com>
This commit is contained in:
Greg Lehey 1999-03-30 04:59:32 +00:00
parent 696ff94de7
commit 8c1e93bf98
2 changed files with 28 additions and 24 deletions

View File

@ -154,8 +154,9 @@ vinum_inactive(int confopen)
if (confopen && (vinum_conf.flags & VF_OPEN)) /* open by vinum(8)? */
return 0; /* can't do it while we're open */
lock_config();
for (i = 0; i < vinum_conf.volumes_used; i++) {
if ((VOL[i].flags & VF_OPEN)) { /* volume is open */
for (i = 0; i < vinum_conf.volumes_allocated; i++) {
if ((VOL[i].state > volume_down)
&& (VOL[i].flags & VF_OPEN)) { /* volume is open */
can_do = 0;
break;
}
@ -175,14 +176,14 @@ void
free_vinum(int cleardrive)
{
int i;
int drives_used = vinum_conf.drives_used;
int drives_allocated = vinum_conf.drives_allocated;
if (DRIVE != NULL) {
if (cleardrive) { /* remove the vinum config */
for (i = 0; i < drives_used; i++)
for (i = 0; i < drives_allocated; i++)
remove_drive(i); /* remove the drive */
} else { /* keep the config */
for (i = 0; i < drives_used; i++)
for (i = 0; i < drives_allocated; i++)
free_drive(&DRIVE[i]); /* close files and things */
}
Free(DRIVE);
@ -198,7 +199,7 @@ free_vinum(int cleardrive)
if (SD != NULL)
Free(SD);
if (PLEX != NULL) {
for (i = 0; i < vinum_conf.plexes_used; i++) {
for (i = 0; i < vinum_conf.plexes_allocated; i++) {
struct plex *plex = &vinum_conf.plex[i];
if (plex->state != plex_unallocated) { /* we have real data there */
@ -268,7 +269,7 @@ vinumopen(dev_t dev,
switch (device->type) {
case VINUM_VOLUME_TYPE:
index = Volno(dev);
if (index >= vinum_conf.volumes_used)
if (index >= vinum_conf.volumes_allocated)
return ENXIO; /* no such device */
vol = &VOL[index];
@ -289,14 +290,15 @@ vinumopen(dev_t dev,
}
case VINUM_PLEX_TYPE:
if (Volno(dev) >= vinum_conf.volumes_used)
if (Volno(dev) >= vinum_conf.volumes_allocated)
return ENXIO;
index = Plexno(dev); /* get plex index in vinum_conf */
if (index >= vinum_conf.plexes_used)
if (index >= vinum_conf.plexes_allocated)
return ENXIO; /* no such device */
plex = &PLEX[index];
switch (plex->state) {
case plex_referenced:
case plex_unallocated:
return EINVAL;
@ -306,11 +308,12 @@ vinumopen(dev_t dev,
}
case VINUM_SD_TYPE:
if ((Volno(dev) >= vinum_conf.volumes_used) || /* no such volume */
(Plexno(dev) >= vinum_conf.plexes_used)) /* or no such plex */
if ((Volno(dev) >= vinum_conf.volumes_allocated) /* no such volume */
||(Plexno(dev) >= vinum_conf.plexes_allocated)) /* or no such plex */
return ENXIO; /* no such device */
index = Sdno(dev); /* get the subdisk number */
if (index >= vinum_conf.subdisks_used)
if ((index >= vinum_conf.subdisks_allocated) /* not a valid SD entry */
||(SD[index].state < sd_obsolete)) /* or SD is not real */
return ENXIO; /* no such device */
sd = &SD[index];
@ -364,7 +367,7 @@ vinumclose(dev_t dev,
/* First, decide what we're looking at */
switch (device->type) {
case VINUM_VOLUME_TYPE:
if (index >= vinum_conf.volumes_used)
if (index >= vinum_conf.volumes_allocated)
return ENXIO; /* no such device */
vol = &VOL[index];
@ -385,20 +388,20 @@ vinumclose(dev_t dev,
}
case VINUM_PLEX_TYPE:
if (Volno(dev) >= vinum_conf.volumes_used)
if (Volno(dev) >= vinum_conf.volumes_allocated)
return ENXIO;
index = Plexno(dev); /* get plex index in vinum_conf */
if (index >= vinum_conf.plexes_used)
if (index >= vinum_conf.plexes_allocated)
return ENXIO; /* no such device */
PLEX[index].flags &= ~VF_OPEN; /* reset our flags */
return 0;
case VINUM_SD_TYPE:
if ((Volno(dev) >= vinum_conf.volumes_used) || /* no such volume */
(Plexno(dev) >= vinum_conf.plexes_used)) /* or no such plex */
if ((Volno(dev) >= vinum_conf.volumes_allocated) || /* no such volume */
(Plexno(dev) >= vinum_conf.plexes_allocated)) /* or no such plex */
return ENXIO; /* no such device */
index = Sdno(dev); /* get the subdisk number */
if (index >= vinum_conf.subdisks_used)
if (index >= vinum_conf.subdisks_allocated)
return ENXIO; /* no such device */
SD[index].flags &= ~VF_OPEN; /* reset our flags */
return 0;

View File

@ -68,8 +68,9 @@ set_drive_state(int driveno, enum drivestate newstate, enum setstateflags flags)
&& (drive->vp == NULL)) /* should be open, but we're not */
init_drive(drive, 1); /* which changes the state again */
if (newstate != oldstate) { /* state has changed */
for (sdno = 0; sdno < vinum_conf.subdisks_used; sdno++) { /* find this drive's subdisks */
if (SD[sdno].driveno == driveno) /* belongs to this drive */
for (sdno = 0; sdno < vinum_conf.subdisks_allocated; sdno++) { /* find this drive's subdisks */
if ((SD[sdno].state >= sd_referenced)
&& (SD[sdno].driveno == driveno)) /* belongs to this drive */
update_sd_state(sdno); /* update the state */
}
}
@ -891,8 +892,8 @@ setstate(struct vinum_ioctl_msg *msg)
switch (msg->type) {
case sd_object:
sd = &SD[msg->index];
if ((msg->index >= vinum_conf.subdisks_used)
|| (sd->state == sd_unallocated)) {
if ((msg->index >= vinum_conf.subdisks_allocated)
|| (sd->state <= sd_referenced)) {
sprintf(ioctl_reply->msg, "Invalid subdisk %d", msg->index);
ioctl_reply->error = EFAULT;
return;
@ -907,8 +908,8 @@ setstate(struct vinum_ioctl_msg *msg)
case plex_object:
plex = &PLEX[msg->index];
if ((msg->index >= vinum_conf.plexes_used)
|| (plex->state == plex_unallocated)) {
if ((msg->index >= vinum_conf.plexes_allocated)
|| (plex->state <= plex_unallocated)) {
sprintf(ioctl_reply->msg, "Invalid plex %d", msg->index);
ioctl_reply->error = EFAULT;
return;